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