Added: #1450 Added multiple undo stacks per context.

This commit is contained in:
dnk-88 2012-03-13 02:20:26 +03:00
parent ad6dd9cf9a
commit 0b3c18894a
5 changed files with 37 additions and 4 deletions

View file

@ -78,6 +78,18 @@ Core::IContext *ContextManager::context(const QString &id) const
return 0;
}
void ContextManager::registerUndoStack(QUndoStack *stack)
{
nlassert(stack);
d->m_mainWindow->undoGroup()->addStack(stack);
}
void ContextManager::unregisterUndoStack(QUndoStack *stack)
{
nlassert(stack);
d->m_mainWindow->undoGroup()->removeStack(stack);
}
void ContextManager::activateContext(const QString &id)
{
const int index = indexOf(id);
@ -85,6 +97,11 @@ void ContextManager::activateContext(const QString &id)
d->m_tabWidget->setCurrentIndex(index);
}
void ContextManager::updateCurrentContext()
{
d->m_mainWindow->updateContext(currentContext());
}
void ContextManager::objectAdded(QObject *obj)
{
IContext *context = qobject_cast<IContext *>(obj);

View file

@ -26,6 +26,7 @@
QT_BEGIN_NAMESPACE
class QTabWidget;
class QUndoStack;
QT_END_NAMESPACE
namespace Core
@ -45,12 +46,17 @@ public:
Core::IContext *currentContext() const;
Core::IContext *context(const QString &id) const;
// temporary solution for multiple undo stacks per context
void registerUndoStack(QUndoStack *stack);
void unregisterUndoStack(QUndoStack *stack);
Q_SIGNALS:
// the default argument '=0' is important for connects without the oldContext argument.
void currentContextChanged(Core::IContext *context, Core::IContext *oldContext = 0);
public Q_SLOTS:
void activateContext(const QString &id);
void updateCurrentContext();
private Q_SLOTS:
void objectAdded(QObject *obj);

View file

@ -128,6 +128,11 @@ QSettings *MainWindow::settings() const
return m_settings;
}
QUndoGroup *MainWindow::undoGroup() const
{
return m_undoGroup;
}
ExtensionSystem::IPluginManager *MainWindow::pluginManager() const
{
return m_pluginManager;
@ -135,12 +140,16 @@ ExtensionSystem::IPluginManager *MainWindow::pluginManager() const
void MainWindow::addContextObject(IContext *context)
{
m_undoGroup->addStack(context->undoStack());
QUndoStack *stack = context->undoStack();
if (stack)
m_undoGroup->addStack(stack);
}
void MainWindow::removeContextObject(IContext *context)
{
m_undoGroup->removeStack(context->undoStack());
QUndoStack *stack = context->undoStack();
if (stack)
m_undoGroup->removeStack(stack);
}
void MainWindow::open()

View file

@ -52,6 +52,7 @@ public:
MenuManager *menuManager() const;
ContextManager *contextManager() const;
QSettings *settings() const;
QUndoGroup *undoGroup() const;
ExtensionSystem::IPluginManager *pluginManager() const;
@ -62,6 +63,7 @@ public Q_SLOTS:
bool showOptionsDialog(const QString &group = QString(),
const QString &page = QString(),
QWidget *parent = 0);
void updateContext(Core::IContext *context);
private Q_SLOTS:
void open();
@ -77,7 +79,6 @@ private Q_SLOTS:
void gotoPos();
void setFullScreen(bool enabled);
void about();
void updateContext(Core::IContext *context);
protected:
virtual void closeEvent(QCloseEvent *event);