framework for accessing user settings in operation stages

c++11
Marc Zinnschlag 10 years ago
parent 8aba52170f
commit 1ee1934053

@ -7,6 +7,7 @@
#include <QTimer> #include <QTimer>
#include "../world/universalid.hpp" #include "../world/universalid.hpp"
#include "../settings/usersettings.hpp"
#include "state.hpp" #include "state.hpp"
#include "stage.hpp" #include "stage.hpp"
@ -23,13 +24,16 @@ void CSMDoc::Operation::prepareStages()
{ {
iter->second = iter->first->setup(); iter->second = iter->first->setup();
mTotalSteps += iter->second; mTotalSteps += iter->second;
for (std::map<QString, QStringList>::const_iterator iter2 (mSettings.begin()); iter2!=mSettings.end(); ++iter2)
iter->first->updateUserSetting (iter2->first, iter2->second);
} }
} }
CSMDoc::Operation::Operation (int type, bool ordered, bool finalAlways) CSMDoc::Operation::Operation (int type, bool ordered, bool finalAlways)
: mType (type), mStages(std::vector<std::pair<Stage *, int> >()), mCurrentStage(mStages.begin()), : mType (type), mStages(std::vector<std::pair<Stage *, int> >()), mCurrentStage(mStages.begin()),
mCurrentStep(0), mCurrentStepTotal(0), mTotalSteps(0), mOrdered (ordered), mCurrentStep(0), mCurrentStepTotal(0), mTotalSteps(0), mOrdered (ordered),
mFinalAlways (finalAlways), mError(false), mConnected (false) mFinalAlways (finalAlways), mError(false), mConnected (false), mPrepared (false)
{ {
mTimer = new QTimer (this); mTimer = new QTimer (this);
} }
@ -49,8 +53,8 @@ void CSMDoc::Operation::run()
connect (mTimer, SIGNAL (timeout()), this, SLOT (executeStage())); connect (mTimer, SIGNAL (timeout()), this, SLOT (executeStage()));
mConnected = true; mConnected = true;
} }
prepareStages(); mPrepared = false;
mTimer->start (0); mTimer->start (0);
} }
@ -60,6 +64,14 @@ void CSMDoc::Operation::appendStage (Stage *stage)
mStages.push_back (std::make_pair (stage, 0)); mStages.push_back (std::make_pair (stage, 0));
} }
void CSMDoc::Operation::configureSettings (const std::vector<QString>& settings)
{
for (std::vector<QString>::const_iterator iter (settings.begin()); iter!=settings.end(); ++iter)
{
mSettings.insert (std::make_pair (*iter, CSMSettings::UserSettings::instance().definitions (*iter)));
}
}
bool CSMDoc::Operation::hasError() const bool CSMDoc::Operation::hasError() const
{ {
return mError; return mError;
@ -84,8 +96,22 @@ void CSMDoc::Operation::abort()
mCurrentStage = mStages.end(); mCurrentStage = mStages.end();
} }
void CSMDoc::Operation::updateUserSetting (const QString& name, const QStringList& value)
{
std::map<QString, QStringList>::iterator iter = mSettings.find (name);
if (iter!=mSettings.end())
iter->second = value;
}
void CSMDoc::Operation::executeStage() void CSMDoc::Operation::executeStage()
{ {
if (!mPrepared)
{
prepareStages();
mPrepared = true;
}
Messages messages; Messages messages;
while (mCurrentStage!=mStages.end()) while (mCurrentStage!=mStages.end())

@ -2,9 +2,11 @@
#define CSM_DOC_OPERATION_H #define CSM_DOC_OPERATION_H
#include <vector> #include <vector>
#include <map>
#include <QObject> #include <QObject>
#include <QTimer> #include <QTimer>
#include <QStringList>
namespace CSMWorld namespace CSMWorld
{ {
@ -30,6 +32,8 @@ namespace CSMDoc
bool mError; bool mError;
bool mConnected; bool mConnected;
QTimer *mTimer; QTimer *mTimer;
std::map<QString, QStringList> mSettings;
bool mPrepared;
void prepareStages(); void prepareStages();
@ -46,6 +50,11 @@ namespace CSMDoc
/// ///
/// \attention Do no call this function while this Operation is running. /// \attention Do no call this function while this Operation is running.
/// Specify settings to be passed on to stages.
///
/// \attention Do no call this function while this Operation is running.
void configureSettings (const std::vector<QString>& settings);
bool hasError() const; bool hasError() const;
signals: signals:
@ -63,6 +72,8 @@ namespace CSMDoc
void run(); void run();
void updateUserSetting (const QString& name, const QStringList& value);
private slots: private slots:
void executeStage(); void executeStage();

@ -1,6 +1,8 @@
#include "operationholder.hpp" #include "operationholder.hpp"
#include "../settings/usersettings.hpp"
#include "operation.hpp" #include "operation.hpp"
CSMDoc::OperationHolder::OperationHolder (Operation *operation) : mRunning (false) CSMDoc::OperationHolder::OperationHolder (Operation *operation) : mRunning (false)
@ -29,6 +31,9 @@ void CSMDoc::OperationHolder::setOperation (Operation *operation)
connect (this, SIGNAL (abortSignal()), mOperation, SLOT (abort())); connect (this, SIGNAL (abortSignal()), mOperation, SLOT (abort()));
connect (&mThread, SIGNAL (started()), mOperation, SLOT (run())); connect (&mThread, SIGNAL (started()), mOperation, SLOT (run()));
connect (&CSMSettings::UserSettings::instance(), SIGNAL (userSettingUpdated (const QString&, const QStringList&)),
mOperation, SLOT (updateUserSetting (const QString&, const QStringList&)));
} }
bool CSMDoc::OperationHolder::isRunning() const bool CSMDoc::OperationHolder::isRunning() const

@ -2,3 +2,5 @@
#include "stage.hpp" #include "stage.hpp"
CSMDoc::Stage::~Stage() {} CSMDoc::Stage::~Stage() {}
void CSMDoc::Stage::updateUserSetting (const QString& name, const QStringList& value) {}

@ -8,6 +8,8 @@
#include "messages.hpp" #include "messages.hpp"
class QString;
namespace CSMDoc namespace CSMDoc
{ {
class Stage class Stage
@ -21,6 +23,9 @@ namespace CSMDoc
virtual void perform (int stage, Messages& messages) = 0; virtual void perform (int stage, Messages& messages) = 0;
///< Messages resulting from this stage will be appended to \a messages. ///< Messages resulting from this stage will be appended to \a messages.
/// Default-implementation: ignore
virtual void updateUserSetting (const QString& name, const QStringList& value);
}; };
} }

Loading…
Cancel
Save