more Operation enhancements in preparation for save operation

This commit is contained in:
Marc Zinnschlag 2013-09-15 12:03:36 +02:00
parent 414e6abb95
commit d71d282952
2 changed files with 39 additions and 5 deletions

View File

@ -15,6 +15,7 @@ void CSMDoc::Operation::prepareStages()
mCurrentStep = 0; mCurrentStep = 0;
mCurrentStepTotal = 0; mCurrentStepTotal = 0;
mTotalSteps = 0; mTotalSteps = 0;
mError = false;
for (std::vector<std::pair<Stage *, int> >::iterator iter (mStages.begin()); iter!=mStages.end(); ++iter) for (std::vector<std::pair<Stage *, int> >::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())); 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)); mStages.push_back (std::make_pair (stage, 0));
} }
bool CSMDoc::Operation::hasError() const
{
return mError;
}
void CSMDoc::Operation::abort() 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() void CSMDoc::Operation::executeStage()
@ -70,7 +91,15 @@ void CSMDoc::Operation::executeStage()
} }
else else
{ {
mCurrentStage->first->perform (mCurrentStep++, messages); try
{
mCurrentStage->first->perform (mCurrentStep++, messages);
}
catch (const std::exception&)
{
abort();
}
++mCurrentStepTotal; ++mCurrentStepTotal;
break; break;
} }

View File

@ -20,13 +20,16 @@ namespace CSMDoc
int mCurrentStepTotal; int mCurrentStepTotal;
int mTotalSteps; int mTotalSteps;
int mOrdered; int mOrdered;
bool mFinalAlways;
bool mError;
void prepareStages(); void prepareStages();
public: public:
Operation (int type, bool ordered); Operation (int type, bool ordered, bool finalAlways = false);
///< \param parallel Stages must be executed in the given order. ///< \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(); virtual ~Operation();
@ -37,6 +40,8 @@ namespace CSMDoc
/// ///
/// \attention Do no call this function while this Operation is running. /// \attention Do no call this function while this Operation is running.
bool hasError() const;
signals: signals:
void progress (int current, int max, int type); void progress (int current, int max, int type);