From 4b257e496ef5aee520425eaec9f14601cb0826d2 Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Mon, 11 Jul 2022 20:41:07 +0400 Subject: [PATCH] Use static settings map for launcher and editor - the Settings::Manager has a static data anyway --- apps/launcher/datafilespage.cpp | 1 + apps/launcher/maindialog.cpp | 6 +-- apps/launcher/maindialog.hpp | 2 - apps/opencs/editor.cpp | 2 + apps/opencs/model/prefs/boolsetting.cpp | 8 +-- apps/opencs/model/prefs/boolsetting.hpp | 2 +- apps/opencs/model/prefs/coloursetting.cpp | 8 +-- apps/opencs/model/prefs/coloursetting.hpp | 2 +- apps/opencs/model/prefs/doublesetting.cpp | 8 +-- apps/opencs/model/prefs/doublesetting.hpp | 2 +- apps/opencs/model/prefs/enumsetting.cpp | 8 +-- apps/opencs/model/prefs/enumsetting.hpp | 2 +- apps/opencs/model/prefs/intsetting.cpp | 8 +-- apps/opencs/model/prefs/intsetting.hpp | 2 +- apps/opencs/model/prefs/modifiersetting.cpp | 10 ++-- apps/opencs/model/prefs/modifiersetting.hpp | 3 +- apps/opencs/model/prefs/setting.cpp | 20 +++---- apps/opencs/model/prefs/setting.hpp | 10 +--- apps/opencs/model/prefs/shortcutsetting.cpp | 10 ++-- apps/opencs/model/prefs/shortcutsetting.hpp | 2 +- apps/opencs/model/prefs/state.cpp | 60 ++++++++++----------- apps/opencs/model/prefs/state.hpp | 5 -- apps/opencs/model/prefs/stringsetting.cpp | 8 +-- apps/opencs/model/prefs/stringsetting.hpp | 2 +- 24 files changed, 87 insertions(+), 104 deletions(-) diff --git a/apps/launcher/datafilespage.cpp b/apps/launcher/datafilespage.cpp index e16202a047..e1b34a8034 100644 --- a/apps/launcher/datafilespage.cpp +++ b/apps/launcher/datafilespage.cpp @@ -19,6 +19,7 @@ #include #include +#include #include #include #include diff --git a/apps/launcher/maindialog.cpp b/apps/launcher/maindialog.cpp index ab6a3e52a3..69259f8b27 100644 --- a/apps/launcher/maindialog.cpp +++ b/apps/launcher/maindialog.cpp @@ -423,14 +423,14 @@ bool Launcher::MainDialog::setupGameData() bool Launcher::MainDialog::setupGraphicsSettings() { - mEngineSettings.clear(); // Ensure to clear previous settings in case we had already loaded settings. + Settings::Manager::clear(); // Ensure to clear previous settings in case we had already loaded settings. try { boost::program_options::variables_map variables; boost::program_options::options_description desc; mCfgMgr.addCommonOptions(desc); mCfgMgr.readConfiguration(variables, desc, true); - mEngineSettings.load(mCfgMgr); + Settings::Manager::load(mCfgMgr); return true; } catch (std::exception& e) @@ -513,7 +513,7 @@ bool Launcher::MainDialog::writeSettings() // Graphics settings const std::string settingsPath = (mCfgMgr.getUserConfigPath() / "settings.cfg").string(); try { - mEngineSettings.saveUser(settingsPath); + Settings::Manager::saveUser(settingsPath); } catch (std::exception& e) { std::string msg = "
Error writing settings.cfg

" + diff --git a/apps/launcher/maindialog.hpp b/apps/launcher/maindialog.hpp index ee81185dd5..ca198cef54 100644 --- a/apps/launcher/maindialog.hpp +++ b/apps/launcher/maindialog.hpp @@ -10,7 +10,6 @@ #include #include -#include #endif #include "ui_mainwindow.h" @@ -95,7 +94,6 @@ namespace Launcher Files::ConfigurationManager mCfgMgr; Config::GameSettings mGameSettings; - Settings::Manager mEngineSettings; Config::LauncherSettings mLauncherSettings; }; diff --git a/apps/opencs/editor.cpp b/apps/opencs/editor.cpp index 5dfa3fbf4e..b70c9f9ca8 100644 --- a/apps/opencs/editor.cpp +++ b/apps/opencs/editor.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include "model/doc/document.hpp" #include "model/world/data.hpp" @@ -109,6 +110,7 @@ boost::program_options::variables_map CS::Editor::readConfiguration() boost::program_options::notify(variables); mCfgMgr.readConfiguration(variables, desc, false); + Settings::Manager::load(mCfgMgr, true); setupLogging(mCfgMgr.getLogPath().string(), "OpenMW-CS"); return variables; diff --git a/apps/opencs/model/prefs/boolsetting.cpp b/apps/opencs/model/prefs/boolsetting.cpp index c8a2c7c5e2..2ef141b0d3 100644 --- a/apps/opencs/model/prefs/boolsetting.cpp +++ b/apps/opencs/model/prefs/boolsetting.cpp @@ -8,9 +8,9 @@ #include "category.hpp" #include "state.hpp" -CSMPrefs::BoolSetting::BoolSetting (Category *parent, Settings::Manager *values, +CSMPrefs::BoolSetting::BoolSetting (Category *parent, QMutex *mutex, const std::string& key, const std::string& label, bool default_) -: Setting (parent, values, mutex, key, label), mDefault (default_), mWidget(nullptr) +: Setting (parent, mutex, key, label), mDefault (default_), mWidget(nullptr) {} CSMPrefs::BoolSetting& CSMPrefs::BoolSetting::setTooltip (const std::string& tooltip) @@ -39,7 +39,7 @@ void CSMPrefs::BoolSetting::updateWidget() { if (mWidget) { - mWidget->setCheckState(getValues().getBool(getKey(), getParent()->getKey()) + mWidget->setCheckState(Settings::Manager::getBool(getKey(), getParent()->getKey()) ? Qt::Checked : Qt::Unchecked); } @@ -49,7 +49,7 @@ void CSMPrefs::BoolSetting::valueChanged (int value) { { QMutexLocker lock (getMutex()); - getValues().setBool (getKey(), getParent()->getKey(), value); + Settings::Manager::setBool (getKey(), getParent()->getKey(), value); } getParent()->getState()->update (*this); diff --git a/apps/opencs/model/prefs/boolsetting.hpp b/apps/opencs/model/prefs/boolsetting.hpp index 941cb50372..4bfd7df47a 100644 --- a/apps/opencs/model/prefs/boolsetting.hpp +++ b/apps/opencs/model/prefs/boolsetting.hpp @@ -17,7 +17,7 @@ namespace CSMPrefs public: - BoolSetting (Category *parent, Settings::Manager *values, + BoolSetting (Category *parent, QMutex *mutex, const std::string& key, const std::string& label, bool default_); BoolSetting& setTooltip (const std::string& tooltip); diff --git a/apps/opencs/model/prefs/coloursetting.cpp b/apps/opencs/model/prefs/coloursetting.cpp index 24735a3bac..569a759632 100644 --- a/apps/opencs/model/prefs/coloursetting.cpp +++ b/apps/opencs/model/prefs/coloursetting.cpp @@ -11,9 +11,9 @@ #include "category.hpp" #include "state.hpp" -CSMPrefs::ColourSetting::ColourSetting (Category *parent, Settings::Manager *values, +CSMPrefs::ColourSetting::ColourSetting (Category *parent, QMutex *mutex, const std::string& key, const std::string& label, QColor default_) -: Setting (parent, values, mutex, key, label), mDefault (default_), mWidget(nullptr) +: Setting (parent, mutex, key, label), mDefault (default_), mWidget(nullptr) {} CSMPrefs::ColourSetting& CSMPrefs::ColourSetting::setTooltip (const std::string& tooltip) @@ -45,7 +45,7 @@ void CSMPrefs::ColourSetting::updateWidget() if (mWidget) { mWidget->setColor(QString::fromStdString - (getValues().getString(getKey(), getParent()->getKey()))); + (Settings::Manager::getString(getKey(), getParent()->getKey()))); } } @@ -54,7 +54,7 @@ void CSMPrefs::ColourSetting::valueChanged() CSVWidget::ColorEditor& widget = dynamic_cast (*sender()); { QMutexLocker lock (getMutex()); - getValues().setString (getKey(), getParent()->getKey(), widget.color().name().toUtf8().data()); + Settings::Manager::setString (getKey(), getParent()->getKey(), widget.color().name().toUtf8().data()); } getParent()->getState()->update (*this); diff --git a/apps/opencs/model/prefs/coloursetting.hpp b/apps/opencs/model/prefs/coloursetting.hpp index 4a814c0e2e..097eec4313 100644 --- a/apps/opencs/model/prefs/coloursetting.hpp +++ b/apps/opencs/model/prefs/coloursetting.hpp @@ -22,7 +22,7 @@ namespace CSMPrefs public: - ColourSetting (Category *parent, Settings::Manager *values, + ColourSetting (Category *parent, QMutex *mutex, const std::string& key, const std::string& label, QColor default_); diff --git a/apps/opencs/model/prefs/doublesetting.cpp b/apps/opencs/model/prefs/doublesetting.cpp index 757b67389a..d8253353b5 100644 --- a/apps/opencs/model/prefs/doublesetting.cpp +++ b/apps/opencs/model/prefs/doublesetting.cpp @@ -12,9 +12,9 @@ #include "category.hpp" #include "state.hpp" -CSMPrefs::DoubleSetting::DoubleSetting (Category *parent, Settings::Manager *values, +CSMPrefs::DoubleSetting::DoubleSetting (Category *parent, QMutex *mutex, const std::string& key, const std::string& label, double default_) -: Setting (parent, values, mutex, key, label), +: Setting (parent, mutex, key, label), mPrecision(2), mMin (0), mMax (std::numeric_limits::max()), mDefault (default_), mWidget(nullptr) {} @@ -75,7 +75,7 @@ void CSMPrefs::DoubleSetting::updateWidget() { if (mWidget) { - mWidget->setValue(getValues().getFloat(getKey(), getParent()->getKey())); + mWidget->setValue(Settings::Manager::getFloat(getKey(), getParent()->getKey())); } } @@ -83,7 +83,7 @@ void CSMPrefs::DoubleSetting::valueChanged (double value) { { QMutexLocker lock (getMutex()); - getValues().setFloat (getKey(), getParent()->getKey(), value); + Settings::Manager::setFloat (getKey(), getParent()->getKey(), value); } getParent()->getState()->update (*this); diff --git a/apps/opencs/model/prefs/doublesetting.hpp b/apps/opencs/model/prefs/doublesetting.hpp index 47886e446f..f65a776351 100644 --- a/apps/opencs/model/prefs/doublesetting.hpp +++ b/apps/opencs/model/prefs/doublesetting.hpp @@ -20,7 +20,7 @@ namespace CSMPrefs public: - DoubleSetting (Category *parent, Settings::Manager *values, + DoubleSetting (Category *parent, QMutex *mutex, const std::string& key, const std::string& label, double default_); diff --git a/apps/opencs/model/prefs/enumsetting.cpp b/apps/opencs/model/prefs/enumsetting.cpp index ec3fca328f..096c9aab38 100644 --- a/apps/opencs/model/prefs/enumsetting.cpp +++ b/apps/opencs/model/prefs/enumsetting.cpp @@ -40,9 +40,9 @@ CSMPrefs::EnumValues& CSMPrefs::EnumValues::add (const std::string& value, const } -CSMPrefs::EnumSetting::EnumSetting (Category *parent, Settings::Manager *values, +CSMPrefs::EnumSetting::EnumSetting (Category *parent, QMutex *mutex, const std::string& key, const std::string& label, const EnumValue& default_) -: Setting (parent, values, mutex, key, label), mDefault (default_), mWidget(nullptr) +: Setting (parent, mutex, key, label), mDefault (default_), mWidget(nullptr) {} CSMPrefs::EnumSetting& CSMPrefs::EnumSetting::setTooltip (const std::string& tooltip) @@ -107,7 +107,7 @@ void CSMPrefs::EnumSetting::updateWidget() if (mWidget) { int index = mWidget->findText(QString::fromStdString - (getValues().getString(getKey(), getParent()->getKey()))); + (Settings::Manager::getString(getKey(), getParent()->getKey()))); mWidget->setCurrentIndex(index); } @@ -117,7 +117,7 @@ void CSMPrefs::EnumSetting::valueChanged (int value) { { QMutexLocker lock (getMutex()); - getValues().setString (getKey(), getParent()->getKey(), mValues.mValues.at (value).mValue); + Settings::Manager::setString (getKey(), getParent()->getKey(), mValues.mValues.at (value).mValue); } getParent()->getState()->update (*this); diff --git a/apps/opencs/model/prefs/enumsetting.hpp b/apps/opencs/model/prefs/enumsetting.hpp index 235f6adc3a..d0467b0639 100644 --- a/apps/opencs/model/prefs/enumsetting.hpp +++ b/apps/opencs/model/prefs/enumsetting.hpp @@ -41,7 +41,7 @@ namespace CSMPrefs public: - EnumSetting (Category *parent, Settings::Manager *values, + EnumSetting (Category *parent, QMutex *mutex, const std::string& key, const std::string& label, const EnumValue& default_); diff --git a/apps/opencs/model/prefs/intsetting.cpp b/apps/opencs/model/prefs/intsetting.cpp index 407ed11f05..b3d4a66334 100644 --- a/apps/opencs/model/prefs/intsetting.cpp +++ b/apps/opencs/model/prefs/intsetting.cpp @@ -12,9 +12,9 @@ #include "category.hpp" #include "state.hpp" -CSMPrefs::IntSetting::IntSetting (Category *parent, Settings::Manager *values, +CSMPrefs::IntSetting::IntSetting (Category *parent, QMutex *mutex, const std::string& key, const std::string& label, int default_) -: Setting (parent, values, mutex, key, label), mMin (0), mMax (std::numeric_limits::max()), +: Setting (parent, mutex, key, label), mMin (0), mMax (std::numeric_limits::max()), mDefault (default_), mWidget(nullptr) {} @@ -67,7 +67,7 @@ void CSMPrefs::IntSetting::updateWidget() { if (mWidget) { - mWidget->setValue(getValues().getInt(getKey(), getParent()->getKey())); + mWidget->setValue(Settings::Manager::getInt(getKey(), getParent()->getKey())); } } @@ -75,7 +75,7 @@ void CSMPrefs::IntSetting::valueChanged (int value) { { QMutexLocker lock (getMutex()); - getValues().setInt (getKey(), getParent()->getKey(), value); + Settings::Manager::setInt (getKey(), getParent()->getKey(), value); } getParent()->getState()->update (*this); diff --git a/apps/opencs/model/prefs/intsetting.hpp b/apps/opencs/model/prefs/intsetting.hpp index f18213b77b..c03e010ad7 100644 --- a/apps/opencs/model/prefs/intsetting.hpp +++ b/apps/opencs/model/prefs/intsetting.hpp @@ -19,7 +19,7 @@ namespace CSMPrefs public: - IntSetting (Category *parent, Settings::Manager *values, + IntSetting (Category *parent, QMutex *mutex, const std::string& key, const std::string& label, int default_); // defaults to [0, std::numeric_limits::max()] diff --git a/apps/opencs/model/prefs/modifiersetting.cpp b/apps/opencs/model/prefs/modifiersetting.cpp index 288926d00b..606cece2bc 100644 --- a/apps/opencs/model/prefs/modifiersetting.cpp +++ b/apps/opencs/model/prefs/modifiersetting.cpp @@ -7,14 +7,16 @@ #include #include +#include + #include "state.hpp" #include "shortcutmanager.hpp" namespace CSMPrefs { - ModifierSetting::ModifierSetting(Category* parent, Settings::Manager* values, QMutex* mutex, const std::string& key, + ModifierSetting::ModifierSetting(Category* parent, QMutex* mutex, const std::string& key, const std::string& label) - : Setting(parent, values, mutex, key, label) + : Setting(parent, mutex, key, label) , mButton(nullptr) , mEditorActive(false) { @@ -47,7 +49,7 @@ namespace CSMPrefs { if (mButton) { - std::string shortcut = getValues().getString(getKey(), getParent()->getKey()); + std::string shortcut = Settings::Manager::getString(getKey(), getParent()->getKey()); int modifier; State::get().getShortcutManager().convertFromString(shortcut, modifier); @@ -135,7 +137,7 @@ namespace CSMPrefs { QMutexLocker lock(getMutex()); - getValues().setString(getKey(), getParent()->getKey(), value); + Settings::Manager::setString(getKey(), getParent()->getKey(), value); } getParent()->getState()->update(*this); diff --git a/apps/opencs/model/prefs/modifiersetting.hpp b/apps/opencs/model/prefs/modifiersetting.hpp index 977badb8df..d1af9d25c6 100644 --- a/apps/opencs/model/prefs/modifiersetting.hpp +++ b/apps/opencs/model/prefs/modifiersetting.hpp @@ -16,8 +16,7 @@ namespace CSMPrefs public: - ModifierSetting(Category* parent, Settings::Manager* values, QMutex* mutex, const std::string& key, - const std::string& label); + ModifierSetting(Category* parent, QMutex* mutex, const std::string& key, const std::string& label); std::pair makeWidgets(QWidget* parent) override; diff --git a/apps/opencs/model/prefs/setting.cpp b/apps/opencs/model/prefs/setting.cpp index 165062232a..524938bcc7 100644 --- a/apps/opencs/model/prefs/setting.cpp +++ b/apps/opencs/model/prefs/setting.cpp @@ -4,23 +4,19 @@ #include #include +#include + #include "category.hpp" #include "state.hpp" -Settings::Manager& CSMPrefs::Setting::getValues() -{ - return *mValues; -} - QMutex *CSMPrefs::Setting::getMutex() { return mMutex; } -CSMPrefs::Setting::Setting (Category *parent, Settings::Manager *values, QMutex *mutex, +CSMPrefs::Setting::Setting (Category *parent, QMutex *mutex, const std::string& key, const std::string& label) -: QObject (parent->getState()), mParent (parent), mValues (values), mMutex (mutex), mKey (key), - mLabel (label) +: QObject (parent->getState()), mParent (parent), mMutex (mutex), mKey (key), mLabel (label) {} CSMPrefs::Setting:: ~Setting() {} @@ -52,25 +48,25 @@ const std::string& CSMPrefs::Setting::getLabel() const int CSMPrefs::Setting::toInt() const { QMutexLocker lock (mMutex); - return mValues->getInt (mKey, mParent->getKey()); + return Settings::Manager::getInt (mKey, mParent->getKey()); } double CSMPrefs::Setting::toDouble() const { QMutexLocker lock (mMutex); - return mValues->getFloat (mKey, mParent->getKey()); + return Settings::Manager::getFloat (mKey, mParent->getKey()); } std::string CSMPrefs::Setting::toString() const { QMutexLocker lock (mMutex); - return mValues->getString (mKey, mParent->getKey()); + return Settings::Manager::getString (mKey, mParent->getKey()); } bool CSMPrefs::Setting::isTrue() const { QMutexLocker lock (mMutex); - return mValues->getBool (mKey, mParent->getKey()); + return Settings::Manager::getBool (mKey, mParent->getKey()); } QColor CSMPrefs::Setting::toColor() const diff --git a/apps/opencs/model/prefs/setting.hpp b/apps/opencs/model/prefs/setting.hpp index 7cb2d7acf6..fcf70c26cd 100644 --- a/apps/opencs/model/prefs/setting.hpp +++ b/apps/opencs/model/prefs/setting.hpp @@ -10,11 +10,6 @@ class QWidget; class QColor; class QMutex; -namespace Settings -{ - class Manager; -} - namespace CSMPrefs { class Category; @@ -24,20 +19,17 @@ namespace CSMPrefs Q_OBJECT Category *mParent; - Settings::Manager *mValues; QMutex *mMutex; std::string mKey; std::string mLabel; protected: - Settings::Manager& getValues(); - QMutex *getMutex(); public: - Setting (Category *parent, Settings::Manager *values, QMutex *mutex, const std::string& key, const std::string& label); + Setting (Category *parent, QMutex *mutex, const std::string& key, const std::string& label); virtual ~Setting(); diff --git a/apps/opencs/model/prefs/shortcutsetting.cpp b/apps/opencs/model/prefs/shortcutsetting.cpp index e0cd5bb07b..622c182dce 100644 --- a/apps/opencs/model/prefs/shortcutsetting.cpp +++ b/apps/opencs/model/prefs/shortcutsetting.cpp @@ -8,14 +8,16 @@ #include #include +#include + #include "state.hpp" #include "shortcutmanager.hpp" namespace CSMPrefs { - ShortcutSetting::ShortcutSetting(Category* parent, Settings::Manager* values, QMutex* mutex, const std::string& key, + ShortcutSetting::ShortcutSetting(Category* parent, QMutex* mutex, const std::string& key, const std::string& label) - : Setting(parent, values, mutex, key, label) + : Setting(parent, mutex, key, label) , mButton(nullptr) , mEditorActive(false) , mEditorPos(0) @@ -53,7 +55,7 @@ namespace CSMPrefs { if (mButton) { - std::string shortcut = getValues().getString(getKey(), getParent()->getKey()); + std::string shortcut = Settings::Manager::getString(getKey(), getParent()->getKey()); QKeySequence sequence; State::get().getShortcutManager().convertFromString(shortcut, sequence); @@ -179,7 +181,7 @@ namespace CSMPrefs { QMutexLocker lock(getMutex()); - getValues().setString(getKey(), getParent()->getKey(), value); + Settings::Manager::setString(getKey(), getParent()->getKey(), value); } getParent()->getState()->update(*this); diff --git a/apps/opencs/model/prefs/shortcutsetting.hpp b/apps/opencs/model/prefs/shortcutsetting.hpp index 52298232e7..cc1394b47e 100644 --- a/apps/opencs/model/prefs/shortcutsetting.hpp +++ b/apps/opencs/model/prefs/shortcutsetting.hpp @@ -16,7 +16,7 @@ namespace CSMPrefs public: - ShortcutSetting(Category* parent, Settings::Manager* values, QMutex* mutex, const std::string& key, + ShortcutSetting(Category* parent, QMutex* mutex, const std::string& key, const std::string& label); std::pair makeWidgets(QWidget* parent) override; diff --git a/apps/opencs/model/prefs/state.cpp b/apps/opencs/model/prefs/state.cpp index 0acd8680c8..a93684a9f2 100644 --- a/apps/opencs/model/prefs/state.cpp +++ b/apps/opencs/model/prefs/state.cpp @@ -5,6 +5,8 @@ #include #include +#include + #include "intsetting.hpp" #include "doublesetting.hpp" #include "boolsetting.hpp" @@ -14,11 +16,6 @@ CSMPrefs::State *CSMPrefs::State::sThis = nullptr; -void CSMPrefs::State::load() -{ - mSettings.load(mConfigurationManager, true); -} - void CSMPrefs::State::declare() { declareCategory ("Windows"); @@ -448,10 +445,10 @@ CSMPrefs::IntSetting& CSMPrefs::State::declareInt (const std::string& key, setDefault(key, std::to_string(default_)); - default_ = mSettings.getInt (key, mCurrentCategory->second.getKey()); + default_ = Settings::Manager::getInt (key, mCurrentCategory->second.getKey()); CSMPrefs::IntSetting *setting = - new CSMPrefs::IntSetting (&mCurrentCategory->second, &mSettings, &mMutex, key, label, + new CSMPrefs::IntSetting (&mCurrentCategory->second, &mMutex, key, label, default_); mCurrentCategory->second.addSetting (setting); @@ -469,10 +466,10 @@ CSMPrefs::DoubleSetting& CSMPrefs::State::declareDouble (const std::string& key, stream << default_; setDefault(key, stream.str()); - default_ = mSettings.getFloat (key, mCurrentCategory->second.getKey()); + default_ = Settings::Manager::getFloat (key, mCurrentCategory->second.getKey()); CSMPrefs::DoubleSetting *setting = - new CSMPrefs::DoubleSetting (&mCurrentCategory->second, &mSettings, &mMutex, + new CSMPrefs::DoubleSetting (&mCurrentCategory->second, &mMutex, key, label, default_); mCurrentCategory->second.addSetting (setting); @@ -488,10 +485,10 @@ CSMPrefs::BoolSetting& CSMPrefs::State::declareBool (const std::string& key, setDefault (key, default_ ? "true" : "false"); - default_ = mSettings.getBool (key, mCurrentCategory->second.getKey()); + default_ = Settings::Manager::getBool (key, mCurrentCategory->second.getKey()); CSMPrefs::BoolSetting *setting = - new CSMPrefs::BoolSetting (&mCurrentCategory->second, &mSettings, &mMutex, key, label, + new CSMPrefs::BoolSetting (&mCurrentCategory->second, &mMutex, key, label, default_); mCurrentCategory->second.addSetting (setting); @@ -507,10 +504,10 @@ CSMPrefs::EnumSetting& CSMPrefs::State::declareEnum (const std::string& key, setDefault (key, default_.mValue); - default_.mValue = mSettings.getString (key, mCurrentCategory->second.getKey()); + default_.mValue = Settings::Manager::getString (key, mCurrentCategory->second.getKey()); CSMPrefs::EnumSetting *setting = - new CSMPrefs::EnumSetting (&mCurrentCategory->second, &mSettings, &mMutex, key, label, + new CSMPrefs::EnumSetting (&mCurrentCategory->second, &mMutex, key, label, default_); mCurrentCategory->second.addSetting (setting); @@ -526,10 +523,10 @@ CSMPrefs::ColourSetting& CSMPrefs::State::declareColour (const std::string& key, setDefault (key, default_.name().toUtf8().data()); - default_.setNamedColor (QString::fromUtf8 (mSettings.getString (key, mCurrentCategory->second.getKey()).c_str())); + default_.setNamedColor (QString::fromUtf8 (Settings::Manager::getString (key, mCurrentCategory->second.getKey()).c_str())); CSMPrefs::ColourSetting *setting = - new CSMPrefs::ColourSetting (&mCurrentCategory->second, &mSettings, &mMutex, key, label, + new CSMPrefs::ColourSetting (&mCurrentCategory->second, &mMutex, key, label, default_); mCurrentCategory->second.addSetting (setting); @@ -549,10 +546,10 @@ CSMPrefs::ShortcutSetting& CSMPrefs::State::declareShortcut (const std::string& // Setup with actual data QKeySequence sequence; - getShortcutManager().convertFromString(mSettings.getString(key, mCurrentCategory->second.getKey()), sequence); + getShortcutManager().convertFromString(Settings::Manager::getString(key, mCurrentCategory->second.getKey()), sequence); getShortcutManager().setSequence(key, sequence); - CSMPrefs::ShortcutSetting *setting = new CSMPrefs::ShortcutSetting (&mCurrentCategory->second, &mSettings, &mMutex, + CSMPrefs::ShortcutSetting *setting = new CSMPrefs::ShortcutSetting (&mCurrentCategory->second, &mMutex, key, label); mCurrentCategory->second.addSetting (setting); @@ -566,10 +563,10 @@ CSMPrefs::StringSetting& CSMPrefs::State::declareString (const std::string& key, setDefault (key, default_); - default_ = mSettings.getString (key, mCurrentCategory->second.getKey()); + default_ = Settings::Manager::getString (key, mCurrentCategory->second.getKey()); CSMPrefs::StringSetting *setting = - new CSMPrefs::StringSetting (&mCurrentCategory->second, &mSettings, &mMutex, key, label, + new CSMPrefs::StringSetting (&mCurrentCategory->second, &mMutex, key, label, default_); mCurrentCategory->second.addSetting (setting); @@ -589,10 +586,10 @@ CSMPrefs::ModifierSetting& CSMPrefs::State::declareModifier(const std::string& k // Setup with actual data int modifier; - getShortcutManager().convertFromString(mSettings.getString(key, mCurrentCategory->second.getKey()), modifier); + getShortcutManager().convertFromString(Settings::Manager::getString(key, mCurrentCategory->second.getKey()), modifier); getShortcutManager().setModifier(key, modifier); - CSMPrefs::ModifierSetting *setting = new CSMPrefs::ModifierSetting (&mCurrentCategory->second, &mSettings, &mMutex, + CSMPrefs::ModifierSetting *setting = new CSMPrefs::ModifierSetting (&mCurrentCategory->second, &mMutex, key, label); mCurrentCategory->second.addSetting (setting); @@ -605,7 +602,7 @@ void CSMPrefs::State::declareSeparator() throw std::logic_error ("no category for setting"); CSMPrefs::Setting *setting = - new CSMPrefs::Setting (&mCurrentCategory->second, &mSettings, &mMutex, "", ""); + new CSMPrefs::Setting (&mCurrentCategory->second, &mMutex, "", ""); mCurrentCategory->second.addSetting (setting); } @@ -616,7 +613,7 @@ void CSMPrefs::State::declareSubcategory(const std::string& label) throw std::logic_error ("no category for setting"); CSMPrefs::Setting *setting = - new CSMPrefs::Setting (&mCurrentCategory->second, &mSettings, &mMutex, "", label); + new CSMPrefs::Setting (&mCurrentCategory->second, &mMutex, "", label); mCurrentCategory->second.addSetting (setting); } @@ -626,10 +623,10 @@ void CSMPrefs::State::setDefault (const std::string& key, const std::string& def Settings::CategorySetting fullKey (mCurrentCategory->second.getKey(), key); Settings::CategorySettingValueMap::iterator iter = - mSettings.mDefaultSettings.find (fullKey); + Settings::Manager::mDefaultSettings.find (fullKey); - if (iter==mSettings.mDefaultSettings.end()) - mSettings.mDefaultSettings.insert (std::make_pair (fullKey, default_)); + if (iter==Settings::Manager::mDefaultSettings.end()) + Settings::Manager::mDefaultSettings.insert (std::make_pair (fullKey, default_)); } CSMPrefs::State::State (const Files::ConfigurationManager& configurationManager) @@ -641,7 +638,6 @@ CSMPrefs::State::State (const Files::ConfigurationManager& configurationManager) sThis = this; - load(); declare(); } @@ -653,7 +649,7 @@ CSMPrefs::State::~State() void CSMPrefs::State::save() { boost::filesystem::path user = mConfigurationManager.getUserConfigPath() / mConfigFile; - mSettings.saveUser (user.string()); + Settings::Manager::saveUser (user.string()); } CSMPrefs::State::Iterator CSMPrefs::State::begin() @@ -696,16 +692,16 @@ CSMPrefs::State& CSMPrefs::State::get() void CSMPrefs::State::resetCategory(const std::string& category) { - for (Settings::CategorySettingValueMap::iterator i = mSettings.mUserSettings.begin(); - i != mSettings.mUserSettings.end(); ++i) + for (Settings::CategorySettingValueMap::iterator i = Settings::Manager::mUserSettings.begin(); + i != Settings::Manager::mUserSettings.end(); ++i) { // if the category matches if (i->first.first == category) { // mark the setting as changed - mSettings.mChangedSettings.insert(std::make_pair(i->first.first, i->first.second)); + Settings::Manager::mChangedSettings.insert(std::make_pair(i->first.first, i->first.second)); // reset the value to the default - i->second = mSettings.mDefaultSettings[i->first]; + i->second = Settings::Manager::mDefaultSettings[i->first]; } } diff --git a/apps/opencs/model/prefs/state.hpp b/apps/opencs/model/prefs/state.hpp index 7c9fcbecda..f464013644 100644 --- a/apps/opencs/model/prefs/state.hpp +++ b/apps/opencs/model/prefs/state.hpp @@ -11,8 +11,6 @@ #include #endif -#include - #include "category.hpp" #include "setting.hpp" #include "enumsetting.hpp" @@ -51,7 +49,6 @@ namespace CSMPrefs const std::string mDefaultConfigFile; const Files::ConfigurationManager& mConfigurationManager; ShortcutManager mShortcutManager; - Settings::Manager mSettings; Collection mCategories; Iterator mCurrentCategory; QMutex mMutex; @@ -62,8 +59,6 @@ namespace CSMPrefs private: - void load(); - void declare(); void declareCategory (const std::string& key); diff --git a/apps/opencs/model/prefs/stringsetting.cpp b/apps/opencs/model/prefs/stringsetting.cpp index 27290b6c72..c062e23465 100644 --- a/apps/opencs/model/prefs/stringsetting.cpp +++ b/apps/opencs/model/prefs/stringsetting.cpp @@ -9,9 +9,9 @@ #include "category.hpp" #include "state.hpp" -CSMPrefs::StringSetting::StringSetting (Category *parent, Settings::Manager *values, +CSMPrefs::StringSetting::StringSetting (Category *parent, QMutex *mutex, const std::string& key, const std::string& label, std::string default_) -: Setting (parent, values, mutex, key, label), mDefault (default_), mWidget(nullptr) +: Setting (parent, mutex, key, label), mDefault (default_), mWidget(nullptr) {} CSMPrefs::StringSetting& CSMPrefs::StringSetting::setTooltip (const std::string& tooltip) @@ -39,7 +39,7 @@ void CSMPrefs::StringSetting::updateWidget() { if (mWidget) { - mWidget->setText(QString::fromStdString(getValues().getString(getKey(), getParent()->getKey()))); + mWidget->setText(QString::fromStdString(Settings::Manager::getString(getKey(), getParent()->getKey()))); } } @@ -47,7 +47,7 @@ void CSMPrefs::StringSetting::textChanged (const QString& text) { { QMutexLocker lock (getMutex()); - getValues().setString (getKey(), getParent()->getKey(), text.toStdString()); + Settings::Manager::setString (getKey(), getParent()->getKey(), text.toStdString()); } getParent()->getState()->update (*this); diff --git a/apps/opencs/model/prefs/stringsetting.hpp b/apps/opencs/model/prefs/stringsetting.hpp index 36d020f296..d4203bce8f 100644 --- a/apps/opencs/model/prefs/stringsetting.hpp +++ b/apps/opencs/model/prefs/stringsetting.hpp @@ -17,7 +17,7 @@ namespace CSMPrefs public: - StringSetting (Category *parent, Settings::Manager *values, + StringSetting (Category *parent, QMutex *mutex, const std::string& key, const std::string& label, std::string default_); StringSetting& setTooltip (const std::string& tooltip);