From ed3d8b8ca2a4cd5dea2870f5bbbcf3f7de6abb0c Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Thu, 22 Nov 2012 15:54:31 +0100 Subject: [PATCH] added undo stack and undo/redo actions --- apps/opencs/model/doc/document.cpp | 7 ++++++- apps/opencs/model/doc/document.hpp | 6 ++++++ apps/opencs/view/doc/view.cpp | 25 ++++++++++++++++++++++--- apps/opencs/view/doc/view.hpp | 4 ++++ 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/apps/opencs/model/doc/document.cpp b/apps/opencs/model/doc/document.cpp index 7154c484ba..448598a4e4 100644 --- a/apps/opencs/model/doc/document.cpp +++ b/apps/opencs/model/doc/document.cpp @@ -1,4 +1,9 @@ #include "document.hpp" -CSMDoc::Document::Document() {} \ No newline at end of file +CSMDoc::Document::Document() {} + +QUndoStack& CSMDoc::Document::getUndoStack() +{ + return mUndoStack; +} \ No newline at end of file diff --git a/apps/opencs/model/doc/document.hpp b/apps/opencs/model/doc/document.hpp index e440859629..1dea7afc28 100644 --- a/apps/opencs/model/doc/document.hpp +++ b/apps/opencs/model/doc/document.hpp @@ -1,10 +1,14 @@ #ifndef CSM_DOC_DOCUMENT_H #define CSM_DOC_DOCUMENT_H +#include + namespace CSMDoc { class Document { + QUndoStack mUndoStack; + // not implemented Document (const Document&); Document& operator= (const Document&); @@ -12,6 +16,8 @@ namespace CSMDoc public: Document(); + + QUndoStack& getUndoStack(); }; } diff --git a/apps/opencs/view/doc/view.cpp b/apps/opencs/view/doc/view.cpp index 406ce7dc74..7a2296fed2 100644 --- a/apps/opencs/view/doc/view.cpp +++ b/apps/opencs/view/doc/view.cpp @@ -6,6 +6,8 @@ #include #include +#include "../../model/doc/document.hpp" + #include "viewmanager.hpp" void CSVDoc::View::closeEvent (QCloseEvent *event) @@ -14,17 +16,34 @@ void CSVDoc::View::closeEvent (QCloseEvent *event) event->ignore(); } -void CSVDoc::View::setupUi() +void CSVDoc::View::setupEditMenu() +{ + QMenu *edit = menuBar()->addMenu (tr ("&Edit")); + + QAction *undo = mDocument->getUndoStack().createUndoAction (this, tr("&Undo")); + undo->setShortcuts (QKeySequence::Undo); + edit->addAction (undo); + + QAction *redo = mDocument->getUndoStack().createRedoAction (this, tr("&Redo")); + redo->setShortcuts (QKeySequence::Redo); + edit->addAction (redo); +} + +void CSVDoc::View::setupViewMenu() { - // view menu QMenu *view = menuBar()->addMenu (tr ("&View")); QAction *newWindow = new QAction (tr ("&New View"), this); connect (newWindow, SIGNAL (triggered()), this, SLOT (newView())); - view->addAction (newWindow); } +void CSVDoc::View::setupUi() +{ + setupEditMenu(); + setupViewMenu(); +} + void CSVDoc::View::updateTitle() { std::ostringstream stream; diff --git a/apps/opencs/view/doc/view.hpp b/apps/opencs/view/doc/view.hpp index 78ec45a5d1..457cc84fa6 100644 --- a/apps/opencs/view/doc/view.hpp +++ b/apps/opencs/view/doc/view.hpp @@ -31,6 +31,10 @@ namespace CSVDoc void closeEvent (QCloseEvent *event); + void setupEditMenu(); + + void setupViewMenu(); + void setupUi(); void updateTitle();