From 997386d8736b036bdb3dd1a7a38e904d4793a755 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Fri, 23 Nov 2012 13:15:45 +0100 Subject: [PATCH] implemented world verify function (doesn't do anything yet; mostly meant as a test for multi-operation interface) --- apps/opencs/model/doc/document.cpp | 34 ++++++++++++++++++++++++++++++ apps/opencs/model/doc/document.hpp | 11 +++++++++- apps/opencs/view/doc/operation.cpp | 3 +++ apps/opencs/view/doc/view.cpp | 18 +++++++++++++++- apps/opencs/view/doc/view.hpp | 5 +++++ 5 files changed, 69 insertions(+), 2 deletions(-) diff --git a/apps/opencs/model/doc/document.cpp b/apps/opencs/model/doc/document.cpp index 473d72375..5c39e16c0 100644 --- a/apps/opencs/model/doc/document.cpp +++ b/apps/opencs/model/doc/document.cpp @@ -8,6 +8,10 @@ CSMDoc::Document::Document() // dummy implementation -> remove when proper save is implemented. mSaveCount = 0; connect (&mSaveTimer, SIGNAL(timeout()), this, SLOT (saving())); + + // dummy implementation -> remove when proper verify is implemented. + mVerifyCount = 0; + connect (&mVerifyTimer, SIGNAL(timeout()), this, SLOT (verifying())); } QUndoStack& CSMDoc::Document::getUndoStack() @@ -25,6 +29,9 @@ int CSMDoc::Document::getState() const if (mSaveCount) state |= State_Locked | State_Saving; + if (mVerifyCount) + state |= State_Locked | State_Verifying; + return state; } @@ -36,6 +43,14 @@ void CSMDoc::Document::save() emit progress (1, 16, State_Saving, 1, this); } +void CSMDoc::Document::verify() +{ + mVerifyCount = 1; + mVerifyTimer.start (500); + emit stateChanged (getState(), this); + emit progress (1, 20, State_Verifying, 1, this); +} + void CSMDoc::Document::abortOperation (int type) { if (type==State_Saving) @@ -43,6 +58,11 @@ void CSMDoc::Document::abortOperation (int type) mSaveTimer.stop(); emit stateChanged (getState(), this); } + else if (type==State_Verifying) + { + mVerifyTimer.stop(); + emit stateChanged (getState(), this); + } } void CSMDoc::Document::modificationStateChanged (bool clean) @@ -63,4 +83,18 @@ void CSMDoc::Document::saving() mUndoStack.setClean(); emit stateChanged (getState(), this); } +} + +void CSMDoc::Document::verifying() +{ + ++mVerifyCount; + + emit progress (mVerifyCount, 20, State_Verifying, 1, this); + + if (mVerifyCount>19) + { + mVerifyCount = 0; + mVerifyTimer.stop(); + emit stateChanged (getState(), this); + } } \ No newline at end of file diff --git a/apps/opencs/model/doc/document.hpp b/apps/opencs/model/doc/document.hpp index 3bed0151d..e691bb38f 100644 --- a/apps/opencs/model/doc/document.hpp +++ b/apps/opencs/model/doc/document.hpp @@ -17,7 +17,8 @@ namespace CSMDoc { State_Modified = 1, State_Locked = 2, - State_Saving = 4 + State_Saving = 4, + State_Verifying = 8 }; QUndoStack mUndoStack; @@ -25,6 +26,9 @@ namespace CSMDoc int mSaveCount; ///< dummy implementation -> remove when proper save is implemented. QTimer mSaveTimer; ///< dummy implementation -> remove when proper save is implemented. + int mVerifyCount; ///< dummy implementation -> remove when proper verify is implemented. + QTimer mVerifyTimer; ///< dummy implementation -> remove when proper verify is implemented. + // not implemented Document (const Document&); Document& operator= (const Document&); @@ -39,6 +43,8 @@ namespace CSMDoc void save(); + void verify(); + void abortOperation (int type); signals: @@ -53,6 +59,9 @@ namespace CSMDoc void saving(); ///< dummy implementation -> remove when proper save is implemented. + + void verifying(); + ///< dummy implementation -> remove when proper verify is implemented. }; } diff --git a/apps/opencs/view/doc/operation.cpp b/apps/opencs/view/doc/operation.cpp index cd9477557..02a93f9c5 100644 --- a/apps/opencs/view/doc/operation.cpp +++ b/apps/opencs/view/doc/operation.cpp @@ -14,6 +14,7 @@ void CSVDoc::Operation::updateLabel (int threads) switch (mType) { case CSMDoc::Document::State_Saving: name = "saving"; break; + case CSMDoc::Document::State_Verifying: name = "verifying"; break; } std::ostringstream stream; @@ -34,6 +35,8 @@ void CSVDoc::Operation::updateLabel (int threads) CSVDoc::Operation::Operation (int type) : mType (type), mStalling (false) { updateLabel(); + + /// \todo assign different progress bar colours to allow the user to distinguish easily between operation types } void CSVDoc::Operation::setProgress (int current, int max, int threads) diff --git a/apps/opencs/view/doc/view.cpp b/apps/opencs/view/doc/view.cpp index fe018ab3b..8ed1f83b8 100644 --- a/apps/opencs/view/doc/view.cpp +++ b/apps/opencs/view/doc/view.cpp @@ -54,11 +54,21 @@ void CSVDoc::View::setupViewMenu() view->addAction (newWindow); } +void CSVDoc::View::setupWorldMenu() +{ + QMenu *world = menuBar()->addMenu (tr ("&World")); + + mVerify = new QAction (tr ("&Verify"), this); + connect (mVerify, SIGNAL (triggered()), this, SLOT (verify())); + world->addAction (mVerify); +} + void CSVDoc::View::setupUi() { setupFileMenu(); setupEditMenu(); setupViewMenu(); + setupWorldMenu(); } void CSVDoc::View::updateTitle() @@ -87,6 +97,7 @@ void CSVDoc::View::updateActions() mRedo->setEnabled (editing & mDocument->getUndoStack().canRedo()); mSave->setEnabled (!(mDocument->getState() & CSMDoc::Document::State_Saving)); + mVerify->setEnabled (!(mDocument->getState() & CSMDoc::Document::State_Verifying)); } CSVDoc::View::View (ViewManager& viewManager, CSMDoc::Document *document, int totalViews) @@ -127,7 +138,7 @@ void CSVDoc::View::updateDocumentState() static const int operations[] = { - CSMDoc::Document::State_Saving, + CSMDoc::Document::State_Saving, CSMDoc::Document::State_Verifying, -1 // end marker }; @@ -156,4 +167,9 @@ void CSVDoc::View::test() void CSVDoc::View::save() { mDocument->save(); +} + +void CSVDoc::View::verify() +{ + mDocument->verify(); } \ No newline at end of file diff --git a/apps/opencs/view/doc/view.hpp b/apps/opencs/view/doc/view.hpp index 191af36b5..15394a7d8 100644 --- a/apps/opencs/view/doc/view.hpp +++ b/apps/opencs/view/doc/view.hpp @@ -28,6 +28,7 @@ namespace CSVDoc QAction *mUndo; QAction *mRedo; QAction *mSave; + QAction *mVerify; std::vector mEditingActions; Operations *mOperations; @@ -45,6 +46,8 @@ namespace CSVDoc void setupViewMenu(); + void setupWorldMenu(); + void setupUi(); void updateTitle(); @@ -73,6 +76,8 @@ namespace CSVDoc void test(); void save(); + + void verify(); }; }