1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-25 06:35:30 +00:00

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;
mCurrentStepTotal = 0;
mTotalSteps = 0;
mError = false;
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()));
}
@ -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;
}

View File

@ -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);