Add undo stack

Add an instance of QUndoStack in the mainwindow, and add undo/redo
actions in the edit menu. The QUndoStack will have a collection
of QUndoCommands to process the undo and redo events.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Grace Karanja 2015-02-11 09:26:17 +03:00 committed by Dirk Hohndel
parent 013da6b0af
commit ef14798d6d
2 changed files with 13 additions and 0 deletions

View file

@ -36,6 +36,7 @@
#include "usermanual.h" #include "usermanual.h"
#endif #endif
#include <QNetworkProxy> #include <QNetworkProxy>
#include <QUndoStack>
MainWindow *MainWindow::m_Instance = NULL; MainWindow *MainWindow::m_Instance = NULL;
@ -180,6 +181,16 @@ MainWindow::MainWindow() : QMainWindow(),
toolBar->setContentsMargins(zeroMargins); toolBar->setContentsMargins(zeroMargins);
updateManager = new UpdateManager(this); updateManager = new UpdateManager(this);
undoStack = new QUndoStack(this);
QAction *undoAction = undoStack->createUndoAction(this, tr("&Undo"));
QAction *redoAction = undoStack->createRedoAction(this, tr("&Redo"));
undoAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Z));
redoAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Z));
QList<QAction*>undoRedoActions;
undoRedoActions.append(undoAction);
undoRedoActions.append(redoAction);
ui.menu_Edit->addActions(undoRedoActions);
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()

View file

@ -34,6 +34,7 @@ class DivePlannerWidget;
class ProfileWidget2; class ProfileWidget2;
class PlannerDetails; class PlannerDetails;
class PlannerSettingsWidget; class PlannerSettingsWidget;
class QUndoStack;
enum MainWindowTitleFormat { enum MainWindowTitleFormat {
MWTF_DEFAULT, MWTF_DEFAULT,
@ -88,6 +89,7 @@ public:
void printPlan(); void printPlan();
void checkSurvey(QSettings *s); void checkSurvey(QSettings *s);
void setApplicationState(const QByteArray& state); void setApplicationState(const QByteArray& state);
QUndoStack *undoStack;
private private
slots: slots:
/* file menu action */ /* file menu action */