mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 23:53:52 +00:00
framework for accessing user settings in operation stages
This commit is contained in:
parent
8aba52170f
commit
1ee1934053
5 changed files with 52 additions and 3 deletions
|
@ -7,6 +7,7 @@
|
|||
#include <QTimer>
|
||||
|
||||
#include "../world/universalid.hpp"
|
||||
#include "../settings/usersettings.hpp"
|
||||
|
||||
#include "state.hpp"
|
||||
#include "stage.hpp"
|
||||
|
@ -23,13 +24,16 @@ void CSMDoc::Operation::prepareStages()
|
|||
{
|
||||
iter->second = iter->first->setup();
|
||||
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)
|
||||
: mType (type), mStages(std::vector<std::pair<Stage *, int> >()), mCurrentStage(mStages.begin()),
|
||||
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);
|
||||
}
|
||||
|
@ -50,7 +54,7 @@ void CSMDoc::Operation::run()
|
|||
mConnected = true;
|
||||
}
|
||||
|
||||
prepareStages();
|
||||
mPrepared = false;
|
||||
|
||||
mTimer->start (0);
|
||||
}
|
||||
|
@ -60,6 +64,14 @@ void CSMDoc::Operation::appendStage (Stage *stage)
|
|||
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
|
||||
{
|
||||
return mError;
|
||||
|
@ -84,8 +96,22 @@ void CSMDoc::Operation::abort()
|
|||
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()
|
||||
{
|
||||
if (!mPrepared)
|
||||
{
|
||||
prepareStages();
|
||||
mPrepared = true;
|
||||
}
|
||||
|
||||
Messages messages;
|
||||
|
||||
while (mCurrentStage!=mStages.end())
|
||||
|
|
|
@ -2,9 +2,11 @@
|
|||
#define CSM_DOC_OPERATION_H
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#include <QObject>
|
||||
#include <QTimer>
|
||||
#include <QStringList>
|
||||
|
||||
namespace CSMWorld
|
||||
{
|
||||
|
@ -30,6 +32,8 @@ namespace CSMDoc
|
|||
bool mError;
|
||||
bool mConnected;
|
||||
QTimer *mTimer;
|
||||
std::map<QString, QStringList> mSettings;
|
||||
bool mPrepared;
|
||||
|
||||
void prepareStages();
|
||||
|
||||
|
@ -46,6 +50,11 @@ namespace CSMDoc
|
|||
///
|
||||
/// \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;
|
||||
|
||||
signals:
|
||||
|
@ -63,6 +72,8 @@ namespace CSMDoc
|
|||
|
||||
void run();
|
||||
|
||||
void updateUserSetting (const QString& name, const QStringList& value);
|
||||
|
||||
private slots:
|
||||
|
||||
void executeStage();
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
|
||||
#include "operationholder.hpp"
|
||||
|
||||
#include "../settings/usersettings.hpp"
|
||||
|
||||
#include "operation.hpp"
|
||||
|
||||
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 (&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
|
||||
|
|
|
@ -2,3 +2,5 @@
|
|||
#include "stage.hpp"
|
||||
|
||||
CSMDoc::Stage::~Stage() {}
|
||||
|
||||
void CSMDoc::Stage::updateUserSetting (const QString& name, const QStringList& value) {}
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
|
||||
#include "messages.hpp"
|
||||
|
||||
class QString;
|
||||
|
||||
namespace CSMDoc
|
||||
{
|
||||
class Stage
|
||||
|
@ -21,6 +23,9 @@ namespace CSMDoc
|
|||
|
||||
virtual void perform (int stage, Messages& messages) = 0;
|
||||
///< Messages resulting from this stage will be appended to \a messages.
|
||||
|
||||
/// Default-implementation: ignore
|
||||
virtual void updateUserSetting (const QString& name, const QStringList& value);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue