From eaa58e0530c3624ee186f5f43ef02f63203354a3 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Fri, 23 Nov 2012 10:52:46 +0100 Subject: [PATCH] preparations for multiple parallel progress-type operations --- apps/opencs/model/doc/document.cpp | 6 +++--- apps/opencs/model/doc/document.hpp | 5 ++--- apps/opencs/view/doc/view.cpp | 11 ++++++----- apps/opencs/view/doc/view.hpp | 3 ++- apps/opencs/view/doc/viewmanager.cpp | 8 ++++---- apps/opencs/view/doc/viewmanager.hpp | 2 +- 6 files changed, 18 insertions(+), 17 deletions(-) diff --git a/apps/opencs/model/doc/document.cpp b/apps/opencs/model/doc/document.cpp index 3c2c5cd8a..c4f830531 100644 --- a/apps/opencs/model/doc/document.cpp +++ b/apps/opencs/model/doc/document.cpp @@ -23,7 +23,7 @@ int CSMDoc::Document::getState() const state |= State_Modified; if (mSaveCount) - state |= State_Locked | State_Saving | State_Progress; + state |= State_Locked | State_Saving; return state; } @@ -33,7 +33,7 @@ void CSMDoc::Document::save() mSaveCount = 1; mSaveTimer.start (500); emit stateChanged (getState(), this); - emit progress (1, 16, this); + emit progress (1, 16, State_Saving, this); } void CSMDoc::Document::abortSave() @@ -51,7 +51,7 @@ void CSMDoc::Document::saving() { ++mSaveCount; - emit progress (mSaveCount, 16, this); + emit progress (mSaveCount, 16, State_Saving, this); if (mSaveCount>15) { diff --git a/apps/opencs/model/doc/document.hpp b/apps/opencs/model/doc/document.hpp index b1c9ead86..8553427a1 100644 --- a/apps/opencs/model/doc/document.hpp +++ b/apps/opencs/model/doc/document.hpp @@ -17,8 +17,7 @@ namespace CSMDoc { State_Modified = 1, State_Locked = 2, - State_Saving = 4, - State_Progress = 8 + State_Saving = 4 }; QUndoStack mUndoStack; @@ -46,7 +45,7 @@ namespace CSMDoc void stateChanged (int state, CSMDoc::Document *document); - void progress (int current, int max, CSMDoc::Document *document); + void progress (int current, int max, int type, CSMDoc::Document *document); private slots: diff --git a/apps/opencs/view/doc/view.cpp b/apps/opencs/view/doc/view.cpp index 8f3efc673..3e9701669 100644 --- a/apps/opencs/view/doc/view.cpp +++ b/apps/opencs/view/doc/view.cpp @@ -20,10 +20,9 @@ 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); - mEditingActions.push_back (save); + mSave = new QAction (tr ("&Save"), this); + connect (mSave, SIGNAL (triggered()), this, SLOT (save())); + file->addAction (mSave); } void CSVDoc::View::setupEditMenu() @@ -85,6 +84,8 @@ void CSVDoc::View::updateActions() mUndo->setEnabled (editing & mDocument->getUndoStack().canUndo()); mRedo->setEnabled (editing & mDocument->getUndoStack().canRedo()); + + mSave->setEnabled (!(mDocument->getState() & CSMDoc::Document::State_Saving)); } CSVDoc::View::View (ViewManager& viewManager, CSMDoc::Document *document, int totalViews) @@ -121,7 +122,7 @@ void CSVDoc::View::updateDocumentState() updateActions(); } -void CSVDoc::View::updateProgress (int current, int max) +void CSVDoc::View::updateProgress (int current, int max, int type) { } diff --git a/apps/opencs/view/doc/view.hpp b/apps/opencs/view/doc/view.hpp index ab945188f..1836ced8b 100644 --- a/apps/opencs/view/doc/view.hpp +++ b/apps/opencs/view/doc/view.hpp @@ -26,6 +26,7 @@ namespace CSVDoc int mViewTotal; QAction *mUndo; QAction *mRedo; + QAction *mSave; std::vector mEditingActions; // not implemented @@ -61,7 +62,7 @@ namespace CSVDoc void updateDocumentState(); - void updateProgress (int current, int max); + void updateProgress (int current, int max, int type); private slots: diff --git a/apps/opencs/view/doc/viewmanager.cpp b/apps/opencs/view/doc/viewmanager.cpp index 7f94f52a2..ed31fdb75 100644 --- a/apps/opencs/view/doc/viewmanager.cpp +++ b/apps/opencs/view/doc/viewmanager.cpp @@ -46,8 +46,8 @@ CSVDoc::View *CSVDoc::ViewManager::addView (CSMDoc::Document *document) connect (document, SIGNAL (stateChanged (int, CSMDoc::Document *)), this, SLOT (documentStateChanged (int, CSMDoc::Document *))); - connect (document, SIGNAL (progress (int, int, CSMDoc::Document *)), - this, SLOT (progress (int, int, CSMDoc::Document *))); + connect (document, SIGNAL (progress (int, int, int, CSMDoc::Document *)), + this, SLOT (progress (int, int, int, CSMDoc::Document *))); } View *view = new View (*this, document, countViews (document)+1); @@ -102,9 +102,9 @@ void CSVDoc::ViewManager::documentStateChanged (int state, CSMDoc::Document *doc (*iter)->updateDocumentState(); } -void CSVDoc::ViewManager::progress (int current, int max, CSMDoc::Document *document) +void CSVDoc::ViewManager::progress (int current, int max, int type, CSMDoc::Document *document) { for (std::vector::const_iterator iter (mViews.begin()); iter!=mViews.end(); ++iter) if ((*iter)->getDocument()==document) - (*iter)->updateProgress (current, max); + (*iter)->updateProgress (current, max, type); } \ No newline at end of file diff --git a/apps/opencs/view/doc/viewmanager.hpp b/apps/opencs/view/doc/viewmanager.hpp index bcf6dc59e..eac490250 100644 --- a/apps/opencs/view/doc/viewmanager.hpp +++ b/apps/opencs/view/doc/viewmanager.hpp @@ -46,7 +46,7 @@ namespace CSVDoc void documentStateChanged (int state, CSMDoc::Document *document); - void progress (int current, int max, CSMDoc::Document *document); + void progress (int current, int max, int type, CSMDoc::Document *document); }; }