From d71d2829527dc61ba19084b0e3c891c69ec81e86 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sun, 15 Sep 2013 12:03:36 +0200 Subject: [PATCH] more Operation enhancements in preparation for save operation --- apps/opencs/model/doc/operation.cpp | 35 ++++++++++++++++++++++++++--- apps/opencs/model/doc/operation.hpp | 9 ++++++-- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/apps/opencs/model/doc/operation.cpp b/apps/opencs/model/doc/operation.cpp index 7f47e8c706..8af5a2c0dc 100644 --- a/apps/opencs/model/doc/operation.cpp +++ b/apps/opencs/model/doc/operation.cpp @@ -15,6 +15,7 @@ void CSMDoc::Operation::prepareStages() mCurrentStep = 0; mCurrentStepTotal = 0; mTotalSteps = 0; + mError = false; for (std::vector >::iterator iter (mStages.begin()); iter!=mStages.end(); ++iter) { @@ -23,7 +24,8 @@ void CSMDoc::Operation::prepareStages() } } -CSMDoc::Operation::Operation (int type, bool ordered) : mType (type), mOrdered (ordered) +CSMDoc::Operation::Operation (int type, bool ordered, bool finalAlways) +: mType (type), mOrdered (ordered), mFinalAlways (finalAlways) { connect (this, SIGNAL (finished()), this, SLOT (operationDone())); } @@ -52,9 +54,28 @@ void CSMDoc::Operation::appendStage (Stage *stage) mStages.push_back (std::make_pair (stage, 0)); } +bool CSMDoc::Operation::hasError() const +{ + return mError; +} + void CSMDoc::Operation::abort() { - exit(); + if (!isRunning()) + return; + + mError = true; + + if (mFinalAlways) + { + if (mStages.begin()!=mStages.end() && mCurrentStage!=--mStages.end()) + { + mCurrentStep = 0; + mCurrentStage = --mStages.end(); + } + } + else + mCurrentStage = mStages.end(); } void CSMDoc::Operation::executeStage() @@ -70,7 +91,15 @@ void CSMDoc::Operation::executeStage() } else { - mCurrentStage->first->perform (mCurrentStep++, messages); + try + { + mCurrentStage->first->perform (mCurrentStep++, messages); + } + catch (const std::exception&) + { + abort(); + } + ++mCurrentStepTotal; break; } diff --git a/apps/opencs/model/doc/operation.hpp b/apps/opencs/model/doc/operation.hpp index 2fadbda556..316eda78fd 100644 --- a/apps/opencs/model/doc/operation.hpp +++ b/apps/opencs/model/doc/operation.hpp @@ -20,13 +20,16 @@ namespace CSMDoc int mCurrentStepTotal; int mTotalSteps; int mOrdered; + bool mFinalAlways; + bool mError; void prepareStages(); public: - Operation (int type, bool ordered); - ///< \param parallel Stages must be executed in the given order. + Operation (int type, bool ordered, bool finalAlways = false); + ///< \param ordered Stages must be executed in the given order. + /// \param finalAlways Execute last stage even if an error occurred during earlier stages. virtual ~Operation(); @@ -37,6 +40,8 @@ namespace CSMDoc /// /// \attention Do no call this function while this Operation is running. + bool hasError() const; + signals: void progress (int current, int max, int type);