1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-20 14:23:53 +00:00
openmw/apps/opencs/model/prefs/state.hpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

114 lines
2.8 KiB
C++
Raw Normal View History

2016-02-16 18:17:04 +00:00
#ifndef CSM_PREFS_STATE_H
#define CSM_PREFS_STATE_H
2015-12-06 11:06:28 +00:00
#include <map>
#include <string>
2015-12-15 11:19:48 +00:00
#include <QMutex>
#include <QObject>
#ifndef Q_MOC_RUN
#include <components/files/configurationmanager.hpp>
#endif
2015-12-06 11:06:28 +00:00
#include "category.hpp"
2015-12-10 16:33:14 +00:00
#include "enumsetting.hpp"
#include "shortcutmanager.hpp"
2015-12-06 11:06:28 +00:00
2015-12-11 10:15:14 +00:00
class QColor;
namespace CSMPrefs
{
2015-12-08 16:21:58 +00:00
class IntSetting;
2015-12-10 09:58:38 +00:00
class DoubleSetting;
2015-12-10 12:28:48 +00:00
class BoolSetting;
2015-12-11 10:15:14 +00:00
class ColourSetting;
class ShortcutSetting;
2016-07-27 17:53:33 +00:00
class ModifierSetting;
2022-10-09 10:39:43 +00:00
class Setting;
class StringSetting;
2015-12-08 16:21:58 +00:00
2015-12-15 11:19:48 +00: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
2015-12-08 08:56:42 +00:00
static State* sThis;
2022-09-22 18:26:05 +00:00
public:
typedef std::map<std::string, Category> Collection;
typedef Collection::iterator Iterator;
private:
const std::string mConfigFile;
const std::string mDefaultConfigFile;
const Files::ConfigurationManager& mConfigurationManager;
ShortcutManager mShortcutManager;
2015-12-08 08:56:42 +00:00
Collection mCategories;
Iterator mCurrentCategory;
2015-12-15 11:19:48 +00:00
QMutex mMutex;
2015-12-08 08:56:42 +00:00
void declare();
2015-12-06 11:06:28 +00:00
2015-12-10 09:58:38 +00:00
void declareCategory(const std::string& key);
2015-12-08 16:21:58 +00:00
IntSetting& declareInt(const std::string& key, const QString& label, int default_);
DoubleSetting& declareDouble(const std::string& key, const QString& label, double default_);
2015-12-10 12:28:48 +00:00
BoolSetting& declareBool(const std::string& key, const QString& label, bool default_);
2015-12-10 16:33:14 +00:00
EnumSetting& declareEnum(const std::string& key, const QString& label, EnumValue default_);
2015-12-11 10:15:14 +00:00
ColourSetting& declareColour(const std::string& key, const QString& label, QColor default_);
ShortcutSetting& declareShortcut(const std::string& key, const QString& label, const QKeySequence& default_);
StringSetting& declareString(const std::string& key, const QString& label, std::string default_);
2016-07-27 17:53:33 +00:00
ModifierSetting& declareModifier(const std::string& key, const QString& label, int modifier_);
2015-12-11 10:32:55 +00:00
void declareSubcategory(const QString& label);
2015-12-08 16:21:58 +00:00
void setDefault(const std::string& key, const std::string& default_);
2022-09-22 18:26:05 +00:00
public:
State(const Files::ConfigurationManager& configurationManager);
State(const State&) = delete;
~State();
State& operator=(const State&) = delete;
void save();
2015-12-08 08:56:42 +00:00
Iterator begin();
Iterator end();
2015-12-06 11:06:28 +00:00
ShortcutManager& getShortcutManager();
2015-12-11 10:50:06 +00:00
Category& operator[](const std::string& key);
2015-12-08 11:04:45 +00:00
2015-12-08 16:21:58 +00:00
void update(const Setting& setting);
static State& get();
2015-12-08 16:21:58 +00:00
void resetCategory(const std::string& category);
void resetAll();
2015-12-08 16:21:58 +00:00
signals:
void settingChanged(const CSMPrefs::Setting* setting);
};
// convenience function
State& get();
}
#endif