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

114 lines
2.8 KiB
C++
Raw Normal View History

2016-02-16 19:17:04 +01:00
#ifndef CSM_PREFS_STATE_H
#define CSM_PREFS_STATE_H
2015-12-06 12:06:28 +01:00
#include <map>
#include <string>
#include <QObject>
2015-12-15 12:19:48 +01:00
#include <QMutex>
#ifndef Q_MOC_RUN
#include <components/files/configurationmanager.hpp>
#endif
#include <components/settings/settings.hpp>
2015-12-06 12:06:28 +01:00
#include "category.hpp"
2015-12-08 17:21:58 +01:00
#include "setting.hpp"
2015-12-10 17:33:14 +01:00
#include "enumsetting.hpp"
#include "shortcutmanager.hpp"
2015-12-06 12:06:28 +01:00
2015-12-11 11:15:14 +01:00
class QColor;
namespace CSMPrefs
{
2015-12-08 17:21:58 +01:00
class IntSetting;
2015-12-10 10:58:38 +01:00
class DoubleSetting;
2015-12-10 13:28:48 +01:00
class BoolSetting;
2015-12-11 11:15:14 +01:00
class ColourSetting;
class ShortcutSetting;
2015-12-08 17:21:58 +01:00
2015-12-15 12:19:48 +01:00
/// \brief User settings state
///
/// \note Access to the user settings is thread-safe once all declarations and loading has
/// been completed.
class State : public QObject
{
Q_OBJECT
static State *sThis;
2015-12-08 09:56:42 +01:00
public:
typedef std::map<std::string, Category> Collection;
typedef Collection::iterator Iterator;
private:
const std::string mConfigFile;
const Files::ConfigurationManager& mConfigurationManager;
ShortcutManager mShortcutManager;
Settings::Manager mSettings;
2015-12-08 09:56:42 +01:00
Collection mCategories;
Iterator mCurrentCategory;
2015-12-15 12:19:48 +01:00
QMutex mMutex;
// not implemented
State (const State&);
State& operator= (const State&);
private:
void load();
void declare();
2015-12-08 09:56:42 +01:00
void declareCategory (const std::string& key);
2015-12-06 12:06:28 +01:00
2015-12-08 17:21:58 +01:00
IntSetting& declareInt (const std::string& key, const std::string& label, int default_);
2015-12-10 10:58:38 +01:00
DoubleSetting& declareDouble (const std::string& key, const std::string& label, double default_);
2015-12-08 17:21:58 +01:00
2015-12-10 13:28:48 +01:00
BoolSetting& declareBool (const std::string& key, const std::string& label, bool default_);
2015-12-10 17:33:14 +01:00
EnumSetting& declareEnum (const std::string& key, const std::string& label, EnumValue default_);
2015-12-11 11:15:14 +01:00
ColourSetting& declareColour (const std::string& key, const std::string& label, QColor default_);
ShortcutSetting& declareShortcut (const std::string& key, const std::string& label,
const QKeySequence& default_, int modifier=0);
2015-12-11 11:32:55 +01:00
void declareSeparator();
2015-12-08 17:21:58 +01:00
void setDefault (const std::string& key, const std::string& default_);
public:
State (const Files::ConfigurationManager& configurationManager);
~State();
void save();
2015-12-08 09:56:42 +01:00
Iterator begin();
Iterator end();
2015-12-06 12:06:28 +01:00
ShortcutManager& getShortcutManager();
2015-12-11 11:50:06 +01:00
Category& operator[](const std::string& key);
2015-12-08 12:04:45 +01:00
2015-12-08 17:21:58 +01:00
void update (const Setting& setting);
static State& get();
2015-12-08 17:21:58 +01:00
signals:
void settingChanged (const CSMPrefs::Setting *setting);
};
// convenience function
State& get();
}
#endif