From 5838929371d37b2f4b8771d3c1a8fb17b3989b06 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Fri, 23 Nov 2012 00:36:01 +0100 Subject: [PATCH] implemented a dummy save function (does not actually save anything) --- apps/opencs/model/doc/document.cpp | 30 ++++++++++++++++++++++++++++ apps/opencs/model/doc/document.hpp | 15 +++++++++++++- apps/opencs/view/doc/view.cpp | 15 ++++++++++++++ apps/opencs/view/doc/view.hpp | 4 ++++ apps/opencs/view/doc/viewmanager.cpp | 2 +- 5 files changed, 64 insertions(+), 2 deletions(-) diff --git a/apps/opencs/model/doc/document.cpp b/apps/opencs/model/doc/document.cpp index 8770b3b90a..8788ecb9f8 100644 --- a/apps/opencs/model/doc/document.cpp +++ b/apps/opencs/model/doc/document.cpp @@ -4,6 +4,10 @@ CSMDoc::Document::Document() { connect (&mUndoStack, SIGNAL (cleanChanged (bool)), this, SLOT (modificationStateChanged (bool))); + + // dummy implementation -> remove when proper save is implemented. + mSaveCount = 0; + connect (&mSaveTimer, SIGNAL(timeout()), this, SLOT (saving())); } QUndoStack& CSMDoc::Document::getUndoStack() @@ -18,10 +22,36 @@ int CSMDoc::Document::getState() const if (!mUndoStack.isClean()) state |= State_Modified; + if (mSaveCount) + state |= State_Locked | State_Saving; + return state; } +void CSMDoc::Document::save() +{ + mSaveCount = 1; + mSaveTimer.start (500); +} + +void CSMDoc::Document::abortSave() +{ + mSaveTimer.stop(); +} + void CSMDoc::Document::modificationStateChanged (bool clean) { emit stateChanged (getState(), this); +} + +void CSMDoc::Document::saving() +{ + ++mSaveCount; + + if (mSaveCount>15) + { + mSaveCount = 0; + mSaveTimer.stop(); + mUndoStack.setClean(); + } } \ No newline at end of file diff --git a/apps/opencs/model/doc/document.hpp b/apps/opencs/model/doc/document.hpp index 0499aaf9fb..90589b09cd 100644 --- a/apps/opencs/model/doc/document.hpp +++ b/apps/opencs/model/doc/document.hpp @@ -3,6 +3,7 @@ #include #include +#include namespace CSMDoc { @@ -14,11 +15,16 @@ namespace CSMDoc enum State { - State_Modified = 1 + State_Modified = 1, + State_Locked = 2, + State_Saving = 4 }; QUndoStack mUndoStack; + int mSaveCount; ///< dummy implementation -> remove when proper save is implemented. + QTimer mSaveTimer; ///< dummy implementation -> remove when proper save is implemented. + // not implemented Document (const Document&); Document& operator= (const Document&); @@ -31,6 +37,10 @@ namespace CSMDoc int getState() const; + void save(); + + void abortSave(); + signals: void stateChanged (int state, CSMDoc::Document *document); @@ -38,6 +48,9 @@ namespace CSMDoc private slots: void modificationStateChanged (bool clean); + + void saving(); + ///< dummy implementation -> remove when proper save is implemented. }; } diff --git a/apps/opencs/view/doc/view.cpp b/apps/opencs/view/doc/view.cpp index be753e2161..59852bef0b 100644 --- a/apps/opencs/view/doc/view.cpp +++ b/apps/opencs/view/doc/view.cpp @@ -16,6 +16,15 @@ void CSVDoc::View::closeEvent (QCloseEvent *event) event->ignore(); } +void CSVDoc::View::setupFileMenu() +{ + QMenu *file = menuBar()->addMenu (tr ("&File")); + + QAction *save = new QAction (tr ("&Save"), this); + connect (save, SIGNAL (triggered()), this, SLOT (save())); + file->addAction (save); +} + void CSVDoc::View::setupEditMenu() { QMenu *edit = menuBar()->addMenu (tr ("&Edit")); @@ -45,6 +54,7 @@ void CSVDoc::View::setupViewMenu() void CSVDoc::View::setupUi() { + setupFileMenu(); setupEditMenu(); setupViewMenu(); } @@ -105,4 +115,9 @@ void CSVDoc::View::newView() void CSVDoc::View::test() { mDocument->getUndoStack().push (new QUndoCommand()); +} + +void CSVDoc::View::save() +{ + mDocument->save(); } \ No newline at end of file diff --git a/apps/opencs/view/doc/view.hpp b/apps/opencs/view/doc/view.hpp index 67eafe2d5c..be7d23fd07 100644 --- a/apps/opencs/view/doc/view.hpp +++ b/apps/opencs/view/doc/view.hpp @@ -31,6 +31,8 @@ namespace CSVDoc void closeEvent (QCloseEvent *event); + void setupFileMenu(); + void setupEditMenu(); void setupViewMenu(); @@ -57,6 +59,8 @@ namespace CSVDoc void newView(); void test(); + + void save(); }; } diff --git a/apps/opencs/view/doc/viewmanager.cpp b/apps/opencs/view/doc/viewmanager.cpp index ad391dabeb..c7f147660a 100644 --- a/apps/opencs/view/doc/viewmanager.cpp +++ b/apps/opencs/view/doc/viewmanager.cpp @@ -99,4 +99,4 @@ void CSVDoc::ViewManager::documentStateChanged (int state, CSMDoc::Document *doc for (std::vector::const_iterator iter (mViews.begin()); iter!=mViews.end(); ++iter) if ((*iter)->getDocument()==document) (*iter)->updateDocumentState(); -} \ No newline at end of file +}