mirror of
https://github.com/TES3MP/TES3MP.git
synced 2025-09-27 23:21:20 -04:00
more Operation enhancements in preparation for save operation
This commit is contained in:
parent
414e6abb95
commit
d71d282952
@ -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()
|
||||||
@ -69,8 +90,16 @@ void CSMDoc::Operation::executeStage()
|
|||||||
++mCurrentStage;
|
++mCurrentStage;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
mCurrentStage->first->perform (mCurrentStep++, messages);
|
mCurrentStage->first->perform (mCurrentStep++, messages);
|
||||||
|
}
|
||||||
|
catch (const std::exception&)
|
||||||
|
{
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
|
||||||
++mCurrentStepTotal;
|
++mCurrentStepTotal;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user