summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukáš Lalinský <lalinsky@gmail.com>2008-12-11 13:50:23 +0100
committerLukáš Lalinský <lalinsky@gmail.com>2008-12-11 13:50:23 +0100
commitf86e334bf61cd03febbbe5fa0da3dc8b2267489f (patch)
treec648c24db1d723da814796a6641880a9ea04e00b
parenta44e7cfffe081640360232af9ca412c834f40459 (diff)
downloaddbmodel-f86e334bf61cd03febbbe5fa0da3dc8b2267489f.tar.gz
dbmodel-f86e334bf61cd03febbbe5fa0da3dc8b2267489f.tar.bz2
Get rid of the MainWindow-owner QUndoGroup
-rw-r--r--src/mainwindow.cpp46
-rw-r--r--src/mainwindow.h3
2 files changed, 27 insertions, 22 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index a5a7174..80cae48 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -30,6 +30,7 @@
#include <QMessageBox>
#include <QDebug>
#include <QDockWidget>
+#include <QUndoView>
#include <QStackedWidget>
#include "diagramitem.h"
#include "diagramitemfactory.h"
@@ -55,7 +56,6 @@ public:
MainWindow::MainWindow()
: QMainWindow(), d(new MainWindowPrivate), m_model(NULL)
{
- m_undoGroup = new QUndoGroup(this);
setupUi();
setupActions();
setupToolBar();
@@ -73,15 +73,10 @@ MainWindow::MainWindow()
connect(QApplication::clipboard(), SIGNAL(changed(QClipboard::Mode)), this, SLOT(updateClipboard(QClipboard::Mode)));
updateClipboard(QClipboard::Clipboard);
updateSelection();
-
- connect(m_undoGroup, SIGNAL(cleanChanged(bool)), SLOT(updateWindowTitle()));
}
MainWindow::~MainWindow()
{
- if (m_model) {
- m_undoGroup->removeStack(m_model->undoStack());
- }
delete d;
}
@@ -227,10 +222,10 @@ MainWindow::setupActions()
m_actionSwitchMode[2]->setIcon(QIcon(":/icons/16x16/item-relationship.png"));
m_actionSwitchMode[2]->setCheckable(true);
- m_actionUndo = m_undoGroup->createUndoAction(this, tr("&Undo"));
+ m_actionUndo = new QAction(tr("&Undo"), this);
m_actionUndo->setShortcut(QKeySequence(tr("Ctrl+Z")));
m_actionUndo->setIcon(IconProvider::findIcon(16, "edit-undo.png"));
- m_actionRedo = m_undoGroup->createRedoAction(this, tr("Re&do"));
+ m_actionRedo = new QAction(tr("Re&do"), this);
m_actionRedo->setShortcut(QKeySequence(tr("Ctrl+Shift+Z")));
m_actionRedo->setIcon(IconProvider::findIcon(16, "edit-redo.png"));
@@ -497,17 +492,33 @@ MainWindow::newModel(DiagramDocument *newModel)
}
m_view->setScene(newModel);
- if (m_model) {
- m_undoGroup->removeStack(m_model->undoStack());
- delete m_model;
+
+ if (m_model != 0) {
+ QUndoStack *undoStack = m_model->undoStack();
+ disconnect(undoStack, SIGNAL(cleanChanged(bool)), this, SLOT(updateWindowTitle()));
+ disconnect(undoStack, SIGNAL(canUndoChanged(bool)), m_actionUndo, SLOT(setEnabled(bool)));
+ disconnect(undoStack, SIGNAL(canRedoChanged(bool)), m_actionRedo, SLOT(setEnabled(bool)));
+ disconnect(m_actionUndo, SIGNAL(triggered(bool)), undoStack, SLOT(undo()));
+ disconnect(m_actionRedo, SIGNAL(triggered(bool)), undoStack, SLOT(redo()));
+ disconnect(m_model, 0, this, 0);
+ m_model->deleteLater();
}
+
m_model = newModel;
updateMode(m_model->mode());
- m_undoGroup->addStack(m_model->undoStack());
- m_undoGroup->setActiveStack(m_model->undoStack());
+ updateSelection();
m_actionShowGrid->setChecked(m_model->isGridVisible());
+ QUndoStack *undoStack = m_model->undoStack();
+ connect(undoStack, SIGNAL(cleanChanged(bool)), this, SLOT(updateWindowTitle()));
+ connect(undoStack, SIGNAL(canUndoChanged(bool)), m_actionUndo, SLOT(setEnabled(bool)));
+ connect(undoStack, SIGNAL(canRedoChanged(bool)), m_actionRedo, SLOT(setEnabled(bool)));
+ connect(m_actionUndo, SIGNAL(triggered(bool)), undoStack, SLOT(undo()));
+ connect(m_actionRedo, SIGNAL(triggered(bool)), undoStack, SLOT(redo()));
+ m_actionUndo->setEnabled(undoStack->canUndo());
+ m_actionRedo->setEnabled(undoStack->canRedo());
+
connect(m_model,
SIGNAL(modeChanged(DiagramDocument::Mode)),
SLOT(updateMode(DiagramDocument::Mode)));
@@ -519,6 +530,9 @@ MainWindow::newModel(DiagramDocument *newModel)
void
MainWindow::updateSelection()
{
+ if (m_model == 0)
+ return;
+
QList<DiagramItem *> items = m_model->selectedItems();
// Update the property editor
@@ -579,12 +593,6 @@ MainWindow::switchModeAddRelation()
m_model->setMode(DiagramDocument::AddRelation);
}
-QUndoStack *
-MainWindow::currentUndoStack()
-{
- return m_undoGroup->activeStack();
-}
-
void
MainWindow::openRecentFile()
{
diff --git a/src/mainwindow.h b/src/mainwindow.h
index d1d3e2a..eab0868 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -34,8 +34,6 @@ public:
MainWindow();
~MainWindow();
- QUndoStack *currentUndoStack();
-
public slots:
void newModel(DiagramDocument *newModel = 0);
@@ -90,7 +88,6 @@ private:
class MainWindowPrivate;
MainWindowPrivate *const d;
- QUndoGroup *m_undoGroup;
DiagramView *m_view;
DiagramDocument *m_model;