mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-03-27 05:37:25 +00:00
Use static settings map for launcher and editor - the Settings::Manager has a static data anyway
This commit is contained in:
parent
dfea7a6d01
commit
4b257e496e
apps
launcher
opencs
editor.cpp
model/prefs
boolsetting.cppboolsetting.hppcoloursetting.cppcoloursetting.hppdoublesetting.cppdoublesetting.hppenumsetting.cppenumsetting.hppintsetting.cppintsetting.hppmodifiersetting.cppmodifiersetting.hppsetting.cppsetting.hppshortcutsetting.cppshortcutsetting.hppstate.cppstate.hppstringsetting.cppstringsetting.hpp
@ -19,6 +19,7 @@
|
|||||||
#include <components/config/gamesettings.hpp>
|
#include <components/config/gamesettings.hpp>
|
||||||
#include <components/config/launchersettings.hpp>
|
#include <components/config/launchersettings.hpp>
|
||||||
|
|
||||||
|
#include <components/settings/settings.hpp>
|
||||||
#include <components/bsa/compressedbsafile.hpp>
|
#include <components/bsa/compressedbsafile.hpp>
|
||||||
#include <components/navmeshtool/protocol.hpp>
|
#include <components/navmeshtool/protocol.hpp>
|
||||||
#include <components/vfs/bsaarchive.hpp>
|
#include <components/vfs/bsaarchive.hpp>
|
||||||
|
@ -423,14 +423,14 @@ bool Launcher::MainDialog::setupGameData()
|
|||||||
|
|
||||||
bool Launcher::MainDialog::setupGraphicsSettings()
|
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
|
try
|
||||||
{
|
{
|
||||||
boost::program_options::variables_map variables;
|
boost::program_options::variables_map variables;
|
||||||
boost::program_options::options_description desc;
|
boost::program_options::options_description desc;
|
||||||
mCfgMgr.addCommonOptions(desc);
|
mCfgMgr.addCommonOptions(desc);
|
||||||
mCfgMgr.readConfiguration(variables, desc, true);
|
mCfgMgr.readConfiguration(variables, desc, true);
|
||||||
mEngineSettings.load(mCfgMgr);
|
Settings::Manager::load(mCfgMgr);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (std::exception& e)
|
catch (std::exception& e)
|
||||||
@ -513,7 +513,7 @@ bool Launcher::MainDialog::writeSettings()
|
|||||||
// Graphics settings
|
// Graphics settings
|
||||||
const std::string settingsPath = (mCfgMgr.getUserConfigPath() / "settings.cfg").string();
|
const std::string settingsPath = (mCfgMgr.getUserConfigPath() / "settings.cfg").string();
|
||||||
try {
|
try {
|
||||||
mEngineSettings.saveUser(settingsPath);
|
Settings::Manager::saveUser(settingsPath);
|
||||||
}
|
}
|
||||||
catch (std::exception& e) {
|
catch (std::exception& e) {
|
||||||
std::string msg = "<br><b>Error writing settings.cfg</b><br><br>" +
|
std::string msg = "<br><b>Error writing settings.cfg</b><br><br>" +
|
||||||
|
@ -10,7 +10,6 @@
|
|||||||
#include <components/config/gamesettings.hpp>
|
#include <components/config/gamesettings.hpp>
|
||||||
#include <components/config/launchersettings.hpp>
|
#include <components/config/launchersettings.hpp>
|
||||||
|
|
||||||
#include <components/settings/settings.hpp>
|
|
||||||
#endif
|
#endif
|
||||||
#include "ui_mainwindow.h"
|
#include "ui_mainwindow.h"
|
||||||
|
|
||||||
@ -95,7 +94,6 @@ namespace Launcher
|
|||||||
Files::ConfigurationManager mCfgMgr;
|
Files::ConfigurationManager mCfgMgr;
|
||||||
|
|
||||||
Config::GameSettings mGameSettings;
|
Config::GameSettings mGameSettings;
|
||||||
Settings::Manager mEngineSettings;
|
|
||||||
Config::LauncherSettings mLauncherSettings;
|
Config::LauncherSettings mLauncherSettings;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include <components/fallback/validate.hpp>
|
#include <components/fallback/validate.hpp>
|
||||||
#include <components/misc/rng.hpp>
|
#include <components/misc/rng.hpp>
|
||||||
#include <components/nifosg/nifloader.hpp>
|
#include <components/nifosg/nifloader.hpp>
|
||||||
|
#include <components/settings/settings.hpp>
|
||||||
|
|
||||||
#include "model/doc/document.hpp"
|
#include "model/doc/document.hpp"
|
||||||
#include "model/world/data.hpp"
|
#include "model/world/data.hpp"
|
||||||
@ -109,6 +110,7 @@ boost::program_options::variables_map CS::Editor::readConfiguration()
|
|||||||
boost::program_options::notify(variables);
|
boost::program_options::notify(variables);
|
||||||
|
|
||||||
mCfgMgr.readConfiguration(variables, desc, false);
|
mCfgMgr.readConfiguration(variables, desc, false);
|
||||||
|
Settings::Manager::load(mCfgMgr, true);
|
||||||
setupLogging(mCfgMgr.getLogPath().string(), "OpenMW-CS");
|
setupLogging(mCfgMgr.getLogPath().string(), "OpenMW-CS");
|
||||||
|
|
||||||
return variables;
|
return variables;
|
||||||
|
@ -8,9 +8,9 @@
|
|||||||
#include "category.hpp"
|
#include "category.hpp"
|
||||||
#include "state.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_)
|
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)
|
CSMPrefs::BoolSetting& CSMPrefs::BoolSetting::setTooltip (const std::string& tooltip)
|
||||||
@ -39,7 +39,7 @@ void CSMPrefs::BoolSetting::updateWidget()
|
|||||||
{
|
{
|
||||||
if (mWidget)
|
if (mWidget)
|
||||||
{
|
{
|
||||||
mWidget->setCheckState(getValues().getBool(getKey(), getParent()->getKey())
|
mWidget->setCheckState(Settings::Manager::getBool(getKey(), getParent()->getKey())
|
||||||
? Qt::Checked
|
? Qt::Checked
|
||||||
: Qt::Unchecked);
|
: Qt::Unchecked);
|
||||||
}
|
}
|
||||||
@ -49,7 +49,7 @@ void CSMPrefs::BoolSetting::valueChanged (int value)
|
|||||||
{
|
{
|
||||||
{
|
{
|
||||||
QMutexLocker lock (getMutex());
|
QMutexLocker lock (getMutex());
|
||||||
getValues().setBool (getKey(), getParent()->getKey(), value);
|
Settings::Manager::setBool (getKey(), getParent()->getKey(), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
getParent()->getState()->update (*this);
|
getParent()->getState()->update (*this);
|
||||||
|
@ -17,7 +17,7 @@ namespace CSMPrefs
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
BoolSetting (Category *parent, Settings::Manager *values,
|
BoolSetting (Category *parent,
|
||||||
QMutex *mutex, const std::string& key, const std::string& label, bool default_);
|
QMutex *mutex, const std::string& key, const std::string& label, bool default_);
|
||||||
|
|
||||||
BoolSetting& setTooltip (const std::string& tooltip);
|
BoolSetting& setTooltip (const std::string& tooltip);
|
||||||
|
@ -11,9 +11,9 @@
|
|||||||
#include "category.hpp"
|
#include "category.hpp"
|
||||||
#include "state.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_)
|
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)
|
CSMPrefs::ColourSetting& CSMPrefs::ColourSetting::setTooltip (const std::string& tooltip)
|
||||||
@ -45,7 +45,7 @@ void CSMPrefs::ColourSetting::updateWidget()
|
|||||||
if (mWidget)
|
if (mWidget)
|
||||||
{
|
{
|
||||||
mWidget->setColor(QString::fromStdString
|
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<CSVWidget::ColorEditor&> (*sender());
|
CSVWidget::ColorEditor& widget = dynamic_cast<CSVWidget::ColorEditor&> (*sender());
|
||||||
{
|
{
|
||||||
QMutexLocker lock (getMutex());
|
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);
|
getParent()->getState()->update (*this);
|
||||||
|
@ -22,7 +22,7 @@ namespace CSMPrefs
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
ColourSetting (Category *parent, Settings::Manager *values,
|
ColourSetting (Category *parent,
|
||||||
QMutex *mutex, const std::string& key, const std::string& label,
|
QMutex *mutex, const std::string& key, const std::string& label,
|
||||||
QColor default_);
|
QColor default_);
|
||||||
|
|
||||||
|
@ -12,9 +12,9 @@
|
|||||||
#include "category.hpp"
|
#include "category.hpp"
|
||||||
#include "state.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_)
|
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<double>::max()),
|
mPrecision(2), mMin (0), mMax (std::numeric_limits<double>::max()),
|
||||||
mDefault (default_), mWidget(nullptr)
|
mDefault (default_), mWidget(nullptr)
|
||||||
{}
|
{}
|
||||||
@ -75,7 +75,7 @@ void CSMPrefs::DoubleSetting::updateWidget()
|
|||||||
{
|
{
|
||||||
if (mWidget)
|
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());
|
QMutexLocker lock (getMutex());
|
||||||
getValues().setFloat (getKey(), getParent()->getKey(), value);
|
Settings::Manager::setFloat (getKey(), getParent()->getKey(), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
getParent()->getState()->update (*this);
|
getParent()->getState()->update (*this);
|
||||||
|
@ -20,7 +20,7 @@ namespace CSMPrefs
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
DoubleSetting (Category *parent, Settings::Manager *values,
|
DoubleSetting (Category *parent,
|
||||||
QMutex *mutex, const std::string& key, const std::string& label,
|
QMutex *mutex, const std::string& key, const std::string& label,
|
||||||
double default_);
|
double default_);
|
||||||
|
|
||||||
|
@ -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_)
|
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)
|
CSMPrefs::EnumSetting& CSMPrefs::EnumSetting::setTooltip (const std::string& tooltip)
|
||||||
@ -107,7 +107,7 @@ void CSMPrefs::EnumSetting::updateWidget()
|
|||||||
if (mWidget)
|
if (mWidget)
|
||||||
{
|
{
|
||||||
int index = mWidget->findText(QString::fromStdString
|
int index = mWidget->findText(QString::fromStdString
|
||||||
(getValues().getString(getKey(), getParent()->getKey())));
|
(Settings::Manager::getString(getKey(), getParent()->getKey())));
|
||||||
|
|
||||||
mWidget->setCurrentIndex(index);
|
mWidget->setCurrentIndex(index);
|
||||||
}
|
}
|
||||||
@ -117,7 +117,7 @@ void CSMPrefs::EnumSetting::valueChanged (int value)
|
|||||||
{
|
{
|
||||||
{
|
{
|
||||||
QMutexLocker lock (getMutex());
|
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);
|
getParent()->getState()->update (*this);
|
||||||
|
@ -41,7 +41,7 @@ namespace CSMPrefs
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
EnumSetting (Category *parent, Settings::Manager *values,
|
EnumSetting (Category *parent,
|
||||||
QMutex *mutex, const std::string& key, const std::string& label,
|
QMutex *mutex, const std::string& key, const std::string& label,
|
||||||
const EnumValue& default_);
|
const EnumValue& default_);
|
||||||
|
|
||||||
|
@ -12,9 +12,9 @@
|
|||||||
#include "category.hpp"
|
#include "category.hpp"
|
||||||
#include "state.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_)
|
QMutex *mutex, const std::string& key, const std::string& label, int default_)
|
||||||
: Setting (parent, values, mutex, key, label), mMin (0), mMax (std::numeric_limits<int>::max()),
|
: Setting (parent, mutex, key, label), mMin (0), mMax (std::numeric_limits<int>::max()),
|
||||||
mDefault (default_), mWidget(nullptr)
|
mDefault (default_), mWidget(nullptr)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ void CSMPrefs::IntSetting::updateWidget()
|
|||||||
{
|
{
|
||||||
if (mWidget)
|
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());
|
QMutexLocker lock (getMutex());
|
||||||
getValues().setInt (getKey(), getParent()->getKey(), value);
|
Settings::Manager::setInt (getKey(), getParent()->getKey(), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
getParent()->getState()->update (*this);
|
getParent()->getState()->update (*this);
|
||||||
|
@ -19,7 +19,7 @@ namespace CSMPrefs
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
IntSetting (Category *parent, Settings::Manager *values,
|
IntSetting (Category *parent,
|
||||||
QMutex *mutex, const std::string& key, const std::string& label, int default_);
|
QMutex *mutex, const std::string& key, const std::string& label, int default_);
|
||||||
|
|
||||||
// defaults to [0, std::numeric_limits<int>::max()]
|
// defaults to [0, std::numeric_limits<int>::max()]
|
||||||
|
@ -7,14 +7,16 @@
|
|||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
|
#include <components/settings/settings.hpp>
|
||||||
|
|
||||||
#include "state.hpp"
|
#include "state.hpp"
|
||||||
#include "shortcutmanager.hpp"
|
#include "shortcutmanager.hpp"
|
||||||
|
|
||||||
namespace CSMPrefs
|
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)
|
const std::string& label)
|
||||||
: Setting(parent, values, mutex, key, label)
|
: Setting(parent, mutex, key, label)
|
||||||
, mButton(nullptr)
|
, mButton(nullptr)
|
||||||
, mEditorActive(false)
|
, mEditorActive(false)
|
||||||
{
|
{
|
||||||
@ -47,7 +49,7 @@ namespace CSMPrefs
|
|||||||
{
|
{
|
||||||
if (mButton)
|
if (mButton)
|
||||||
{
|
{
|
||||||
std::string shortcut = getValues().getString(getKey(), getParent()->getKey());
|
std::string shortcut = Settings::Manager::getString(getKey(), getParent()->getKey());
|
||||||
|
|
||||||
int modifier;
|
int modifier;
|
||||||
State::get().getShortcutManager().convertFromString(shortcut, modifier);
|
State::get().getShortcutManager().convertFromString(shortcut, modifier);
|
||||||
@ -135,7 +137,7 @@ namespace CSMPrefs
|
|||||||
|
|
||||||
{
|
{
|
||||||
QMutexLocker lock(getMutex());
|
QMutexLocker lock(getMutex());
|
||||||
getValues().setString(getKey(), getParent()->getKey(), value);
|
Settings::Manager::setString(getKey(), getParent()->getKey(), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
getParent()->getState()->update(*this);
|
getParent()->getState()->update(*this);
|
||||||
|
@ -16,8 +16,7 @@ namespace CSMPrefs
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
ModifierSetting(Category* parent, Settings::Manager* values, QMutex* mutex, const std::string& key,
|
ModifierSetting(Category* parent, QMutex* mutex, const std::string& key, const std::string& label);
|
||||||
const std::string& label);
|
|
||||||
|
|
||||||
std::pair<QWidget*, QWidget*> makeWidgets(QWidget* parent) override;
|
std::pair<QWidget*, QWidget*> makeWidgets(QWidget* parent) override;
|
||||||
|
|
||||||
|
@ -4,23 +4,19 @@
|
|||||||
#include <QColor>
|
#include <QColor>
|
||||||
#include <QMutexLocker>
|
#include <QMutexLocker>
|
||||||
|
|
||||||
|
#include <components/settings/settings.hpp>
|
||||||
|
|
||||||
#include "category.hpp"
|
#include "category.hpp"
|
||||||
#include "state.hpp"
|
#include "state.hpp"
|
||||||
|
|
||||||
Settings::Manager& CSMPrefs::Setting::getValues()
|
|
||||||
{
|
|
||||||
return *mValues;
|
|
||||||
}
|
|
||||||
|
|
||||||
QMutex *CSMPrefs::Setting::getMutex()
|
QMutex *CSMPrefs::Setting::getMutex()
|
||||||
{
|
{
|
||||||
return mMutex;
|
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)
|
const std::string& key, const std::string& label)
|
||||||
: QObject (parent->getState()), mParent (parent), mValues (values), mMutex (mutex), mKey (key),
|
: QObject (parent->getState()), mParent (parent), mMutex (mutex), mKey (key), mLabel (label)
|
||||||
mLabel (label)
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
CSMPrefs::Setting:: ~Setting() {}
|
CSMPrefs::Setting:: ~Setting() {}
|
||||||
@ -52,25 +48,25 @@ const std::string& CSMPrefs::Setting::getLabel() const
|
|||||||
int CSMPrefs::Setting::toInt() const
|
int CSMPrefs::Setting::toInt() const
|
||||||
{
|
{
|
||||||
QMutexLocker lock (mMutex);
|
QMutexLocker lock (mMutex);
|
||||||
return mValues->getInt (mKey, mParent->getKey());
|
return Settings::Manager::getInt (mKey, mParent->getKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
double CSMPrefs::Setting::toDouble() const
|
double CSMPrefs::Setting::toDouble() const
|
||||||
{
|
{
|
||||||
QMutexLocker lock (mMutex);
|
QMutexLocker lock (mMutex);
|
||||||
return mValues->getFloat (mKey, mParent->getKey());
|
return Settings::Manager::getFloat (mKey, mParent->getKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string CSMPrefs::Setting::toString() const
|
std::string CSMPrefs::Setting::toString() const
|
||||||
{
|
{
|
||||||
QMutexLocker lock (mMutex);
|
QMutexLocker lock (mMutex);
|
||||||
return mValues->getString (mKey, mParent->getKey());
|
return Settings::Manager::getString (mKey, mParent->getKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CSMPrefs::Setting::isTrue() const
|
bool CSMPrefs::Setting::isTrue() const
|
||||||
{
|
{
|
||||||
QMutexLocker lock (mMutex);
|
QMutexLocker lock (mMutex);
|
||||||
return mValues->getBool (mKey, mParent->getKey());
|
return Settings::Manager::getBool (mKey, mParent->getKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
QColor CSMPrefs::Setting::toColor() const
|
QColor CSMPrefs::Setting::toColor() const
|
||||||
|
@ -10,11 +10,6 @@ class QWidget;
|
|||||||
class QColor;
|
class QColor;
|
||||||
class QMutex;
|
class QMutex;
|
||||||
|
|
||||||
namespace Settings
|
|
||||||
{
|
|
||||||
class Manager;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace CSMPrefs
|
namespace CSMPrefs
|
||||||
{
|
{
|
||||||
class Category;
|
class Category;
|
||||||
@ -24,20 +19,17 @@ namespace CSMPrefs
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
Category *mParent;
|
Category *mParent;
|
||||||
Settings::Manager *mValues;
|
|
||||||
QMutex *mMutex;
|
QMutex *mMutex;
|
||||||
std::string mKey;
|
std::string mKey;
|
||||||
std::string mLabel;
|
std::string mLabel;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
Settings::Manager& getValues();
|
|
||||||
|
|
||||||
QMutex *getMutex();
|
QMutex *getMutex();
|
||||||
|
|
||||||
public:
|
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();
|
virtual ~Setting();
|
||||||
|
|
||||||
|
@ -8,14 +8,16 @@
|
|||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
|
#include <components/settings/settings.hpp>
|
||||||
|
|
||||||
#include "state.hpp"
|
#include "state.hpp"
|
||||||
#include "shortcutmanager.hpp"
|
#include "shortcutmanager.hpp"
|
||||||
|
|
||||||
namespace CSMPrefs
|
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)
|
const std::string& label)
|
||||||
: Setting(parent, values, mutex, key, label)
|
: Setting(parent, mutex, key, label)
|
||||||
, mButton(nullptr)
|
, mButton(nullptr)
|
||||||
, mEditorActive(false)
|
, mEditorActive(false)
|
||||||
, mEditorPos(0)
|
, mEditorPos(0)
|
||||||
@ -53,7 +55,7 @@ namespace CSMPrefs
|
|||||||
{
|
{
|
||||||
if (mButton)
|
if (mButton)
|
||||||
{
|
{
|
||||||
std::string shortcut = getValues().getString(getKey(), getParent()->getKey());
|
std::string shortcut = Settings::Manager::getString(getKey(), getParent()->getKey());
|
||||||
|
|
||||||
QKeySequence sequence;
|
QKeySequence sequence;
|
||||||
State::get().getShortcutManager().convertFromString(shortcut, sequence);
|
State::get().getShortcutManager().convertFromString(shortcut, sequence);
|
||||||
@ -179,7 +181,7 @@ namespace CSMPrefs
|
|||||||
|
|
||||||
{
|
{
|
||||||
QMutexLocker lock(getMutex());
|
QMutexLocker lock(getMutex());
|
||||||
getValues().setString(getKey(), getParent()->getKey(), value);
|
Settings::Manager::setString(getKey(), getParent()->getKey(), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
getParent()->getState()->update(*this);
|
getParent()->getState()->update(*this);
|
||||||
|
@ -16,7 +16,7 @@ namespace CSMPrefs
|
|||||||
|
|
||||||
public:
|
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);
|
const std::string& label);
|
||||||
|
|
||||||
std::pair<QWidget*, QWidget*> makeWidgets(QWidget* parent) override;
|
std::pair<QWidget*, QWidget*> makeWidgets(QWidget* parent) override;
|
||||||
|
@ -5,6 +5,8 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
#include <components/settings/settings.hpp>
|
||||||
|
|
||||||
#include "intsetting.hpp"
|
#include "intsetting.hpp"
|
||||||
#include "doublesetting.hpp"
|
#include "doublesetting.hpp"
|
||||||
#include "boolsetting.hpp"
|
#include "boolsetting.hpp"
|
||||||
@ -14,11 +16,6 @@
|
|||||||
|
|
||||||
CSMPrefs::State *CSMPrefs::State::sThis = nullptr;
|
CSMPrefs::State *CSMPrefs::State::sThis = nullptr;
|
||||||
|
|
||||||
void CSMPrefs::State::load()
|
|
||||||
{
|
|
||||||
mSettings.load(mConfigurationManager, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CSMPrefs::State::declare()
|
void CSMPrefs::State::declare()
|
||||||
{
|
{
|
||||||
declareCategory ("Windows");
|
declareCategory ("Windows");
|
||||||
@ -448,10 +445,10 @@ CSMPrefs::IntSetting& CSMPrefs::State::declareInt (const std::string& key,
|
|||||||
|
|
||||||
setDefault(key, std::to_string(default_));
|
setDefault(key, std::to_string(default_));
|
||||||
|
|
||||||
default_ = mSettings.getInt (key, mCurrentCategory->second.getKey());
|
default_ = Settings::Manager::getInt (key, mCurrentCategory->second.getKey());
|
||||||
|
|
||||||
CSMPrefs::IntSetting *setting =
|
CSMPrefs::IntSetting *setting =
|
||||||
new CSMPrefs::IntSetting (&mCurrentCategory->second, &mSettings, &mMutex, key, label,
|
new CSMPrefs::IntSetting (&mCurrentCategory->second, &mMutex, key, label,
|
||||||
default_);
|
default_);
|
||||||
|
|
||||||
mCurrentCategory->second.addSetting (setting);
|
mCurrentCategory->second.addSetting (setting);
|
||||||
@ -469,10 +466,10 @@ CSMPrefs::DoubleSetting& CSMPrefs::State::declareDouble (const std::string& key,
|
|||||||
stream << default_;
|
stream << default_;
|
||||||
setDefault(key, stream.str());
|
setDefault(key, stream.str());
|
||||||
|
|
||||||
default_ = mSettings.getFloat (key, mCurrentCategory->second.getKey());
|
default_ = Settings::Manager::getFloat (key, mCurrentCategory->second.getKey());
|
||||||
|
|
||||||
CSMPrefs::DoubleSetting *setting =
|
CSMPrefs::DoubleSetting *setting =
|
||||||
new CSMPrefs::DoubleSetting (&mCurrentCategory->second, &mSettings, &mMutex,
|
new CSMPrefs::DoubleSetting (&mCurrentCategory->second, &mMutex,
|
||||||
key, label, default_);
|
key, label, default_);
|
||||||
|
|
||||||
mCurrentCategory->second.addSetting (setting);
|
mCurrentCategory->second.addSetting (setting);
|
||||||
@ -488,10 +485,10 @@ CSMPrefs::BoolSetting& CSMPrefs::State::declareBool (const std::string& key,
|
|||||||
|
|
||||||
setDefault (key, default_ ? "true" : "false");
|
setDefault (key, default_ ? "true" : "false");
|
||||||
|
|
||||||
default_ = mSettings.getBool (key, mCurrentCategory->second.getKey());
|
default_ = Settings::Manager::getBool (key, mCurrentCategory->second.getKey());
|
||||||
|
|
||||||
CSMPrefs::BoolSetting *setting =
|
CSMPrefs::BoolSetting *setting =
|
||||||
new CSMPrefs::BoolSetting (&mCurrentCategory->second, &mSettings, &mMutex, key, label,
|
new CSMPrefs::BoolSetting (&mCurrentCategory->second, &mMutex, key, label,
|
||||||
default_);
|
default_);
|
||||||
|
|
||||||
mCurrentCategory->second.addSetting (setting);
|
mCurrentCategory->second.addSetting (setting);
|
||||||
@ -507,10 +504,10 @@ CSMPrefs::EnumSetting& CSMPrefs::State::declareEnum (const std::string& key,
|
|||||||
|
|
||||||
setDefault (key, default_.mValue);
|
setDefault (key, default_.mValue);
|
||||||
|
|
||||||
default_.mValue = mSettings.getString (key, mCurrentCategory->second.getKey());
|
default_.mValue = Settings::Manager::getString (key, mCurrentCategory->second.getKey());
|
||||||
|
|
||||||
CSMPrefs::EnumSetting *setting =
|
CSMPrefs::EnumSetting *setting =
|
||||||
new CSMPrefs::EnumSetting (&mCurrentCategory->second, &mSettings, &mMutex, key, label,
|
new CSMPrefs::EnumSetting (&mCurrentCategory->second, &mMutex, key, label,
|
||||||
default_);
|
default_);
|
||||||
|
|
||||||
mCurrentCategory->second.addSetting (setting);
|
mCurrentCategory->second.addSetting (setting);
|
||||||
@ -526,10 +523,10 @@ CSMPrefs::ColourSetting& CSMPrefs::State::declareColour (const std::string& key,
|
|||||||
|
|
||||||
setDefault (key, default_.name().toUtf8().data());
|
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 =
|
CSMPrefs::ColourSetting *setting =
|
||||||
new CSMPrefs::ColourSetting (&mCurrentCategory->second, &mSettings, &mMutex, key, label,
|
new CSMPrefs::ColourSetting (&mCurrentCategory->second, &mMutex, key, label,
|
||||||
default_);
|
default_);
|
||||||
|
|
||||||
mCurrentCategory->second.addSetting (setting);
|
mCurrentCategory->second.addSetting (setting);
|
||||||
@ -549,10 +546,10 @@ CSMPrefs::ShortcutSetting& CSMPrefs::State::declareShortcut (const std::string&
|
|||||||
// Setup with actual data
|
// Setup with actual data
|
||||||
QKeySequence sequence;
|
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);
|
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);
|
key, label);
|
||||||
mCurrentCategory->second.addSetting (setting);
|
mCurrentCategory->second.addSetting (setting);
|
||||||
|
|
||||||
@ -566,10 +563,10 @@ CSMPrefs::StringSetting& CSMPrefs::State::declareString (const std::string& key,
|
|||||||
|
|
||||||
setDefault (key, default_);
|
setDefault (key, default_);
|
||||||
|
|
||||||
default_ = mSettings.getString (key, mCurrentCategory->second.getKey());
|
default_ = Settings::Manager::getString (key, mCurrentCategory->second.getKey());
|
||||||
|
|
||||||
CSMPrefs::StringSetting *setting =
|
CSMPrefs::StringSetting *setting =
|
||||||
new CSMPrefs::StringSetting (&mCurrentCategory->second, &mSettings, &mMutex, key, label,
|
new CSMPrefs::StringSetting (&mCurrentCategory->second, &mMutex, key, label,
|
||||||
default_);
|
default_);
|
||||||
|
|
||||||
mCurrentCategory->second.addSetting (setting);
|
mCurrentCategory->second.addSetting (setting);
|
||||||
@ -589,10 +586,10 @@ CSMPrefs::ModifierSetting& CSMPrefs::State::declareModifier(const std::string& k
|
|||||||
// Setup with actual data
|
// Setup with actual data
|
||||||
int modifier;
|
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);
|
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);
|
key, label);
|
||||||
mCurrentCategory->second.addSetting (setting);
|
mCurrentCategory->second.addSetting (setting);
|
||||||
|
|
||||||
@ -605,7 +602,7 @@ void CSMPrefs::State::declareSeparator()
|
|||||||
throw std::logic_error ("no category for setting");
|
throw std::logic_error ("no category for setting");
|
||||||
|
|
||||||
CSMPrefs::Setting *setting =
|
CSMPrefs::Setting *setting =
|
||||||
new CSMPrefs::Setting (&mCurrentCategory->second, &mSettings, &mMutex, "", "");
|
new CSMPrefs::Setting (&mCurrentCategory->second, &mMutex, "", "");
|
||||||
|
|
||||||
mCurrentCategory->second.addSetting (setting);
|
mCurrentCategory->second.addSetting (setting);
|
||||||
}
|
}
|
||||||
@ -616,7 +613,7 @@ void CSMPrefs::State::declareSubcategory(const std::string& label)
|
|||||||
throw std::logic_error ("no category for setting");
|
throw std::logic_error ("no category for setting");
|
||||||
|
|
||||||
CSMPrefs::Setting *setting =
|
CSMPrefs::Setting *setting =
|
||||||
new CSMPrefs::Setting (&mCurrentCategory->second, &mSettings, &mMutex, "", label);
|
new CSMPrefs::Setting (&mCurrentCategory->second, &mMutex, "", label);
|
||||||
|
|
||||||
mCurrentCategory->second.addSetting (setting);
|
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::CategorySetting fullKey (mCurrentCategory->second.getKey(), key);
|
||||||
|
|
||||||
Settings::CategorySettingValueMap::iterator iter =
|
Settings::CategorySettingValueMap::iterator iter =
|
||||||
mSettings.mDefaultSettings.find (fullKey);
|
Settings::Manager::mDefaultSettings.find (fullKey);
|
||||||
|
|
||||||
if (iter==mSettings.mDefaultSettings.end())
|
if (iter==Settings::Manager::mDefaultSettings.end())
|
||||||
mSettings.mDefaultSettings.insert (std::make_pair (fullKey, default_));
|
Settings::Manager::mDefaultSettings.insert (std::make_pair (fullKey, default_));
|
||||||
}
|
}
|
||||||
|
|
||||||
CSMPrefs::State::State (const Files::ConfigurationManager& configurationManager)
|
CSMPrefs::State::State (const Files::ConfigurationManager& configurationManager)
|
||||||
@ -641,7 +638,6 @@ CSMPrefs::State::State (const Files::ConfigurationManager& configurationManager)
|
|||||||
|
|
||||||
sThis = this;
|
sThis = this;
|
||||||
|
|
||||||
load();
|
|
||||||
declare();
|
declare();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -653,7 +649,7 @@ CSMPrefs::State::~State()
|
|||||||
void CSMPrefs::State::save()
|
void CSMPrefs::State::save()
|
||||||
{
|
{
|
||||||
boost::filesystem::path user = mConfigurationManager.getUserConfigPath() / mConfigFile;
|
boost::filesystem::path user = mConfigurationManager.getUserConfigPath() / mConfigFile;
|
||||||
mSettings.saveUser (user.string());
|
Settings::Manager::saveUser (user.string());
|
||||||
}
|
}
|
||||||
|
|
||||||
CSMPrefs::State::Iterator CSMPrefs::State::begin()
|
CSMPrefs::State::Iterator CSMPrefs::State::begin()
|
||||||
@ -696,16 +692,16 @@ CSMPrefs::State& CSMPrefs::State::get()
|
|||||||
|
|
||||||
void CSMPrefs::State::resetCategory(const std::string& category)
|
void CSMPrefs::State::resetCategory(const std::string& category)
|
||||||
{
|
{
|
||||||
for (Settings::CategorySettingValueMap::iterator i = mSettings.mUserSettings.begin();
|
for (Settings::CategorySettingValueMap::iterator i = Settings::Manager::mUserSettings.begin();
|
||||||
i != mSettings.mUserSettings.end(); ++i)
|
i != Settings::Manager::mUserSettings.end(); ++i)
|
||||||
{
|
{
|
||||||
// if the category matches
|
// if the category matches
|
||||||
if (i->first.first == category)
|
if (i->first.first == category)
|
||||||
{
|
{
|
||||||
// mark the setting as changed
|
// 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
|
// reset the value to the default
|
||||||
i->second = mSettings.mDefaultSettings[i->first];
|
i->second = Settings::Manager::mDefaultSettings[i->first];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,8 +11,6 @@
|
|||||||
#include <components/files/configurationmanager.hpp>
|
#include <components/files/configurationmanager.hpp>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <components/settings/settings.hpp>
|
|
||||||
|
|
||||||
#include "category.hpp"
|
#include "category.hpp"
|
||||||
#include "setting.hpp"
|
#include "setting.hpp"
|
||||||
#include "enumsetting.hpp"
|
#include "enumsetting.hpp"
|
||||||
@ -51,7 +49,6 @@ namespace CSMPrefs
|
|||||||
const std::string mDefaultConfigFile;
|
const std::string mDefaultConfigFile;
|
||||||
const Files::ConfigurationManager& mConfigurationManager;
|
const Files::ConfigurationManager& mConfigurationManager;
|
||||||
ShortcutManager mShortcutManager;
|
ShortcutManager mShortcutManager;
|
||||||
Settings::Manager mSettings;
|
|
||||||
Collection mCategories;
|
Collection mCategories;
|
||||||
Iterator mCurrentCategory;
|
Iterator mCurrentCategory;
|
||||||
QMutex mMutex;
|
QMutex mMutex;
|
||||||
@ -62,8 +59,6 @@ namespace CSMPrefs
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void load();
|
|
||||||
|
|
||||||
void declare();
|
void declare();
|
||||||
|
|
||||||
void declareCategory (const std::string& key);
|
void declareCategory (const std::string& key);
|
||||||
|
@ -9,9 +9,9 @@
|
|||||||
#include "category.hpp"
|
#include "category.hpp"
|
||||||
#include "state.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_)
|
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)
|
CSMPrefs::StringSetting& CSMPrefs::StringSetting::setTooltip (const std::string& tooltip)
|
||||||
@ -39,7 +39,7 @@ void CSMPrefs::StringSetting::updateWidget()
|
|||||||
{
|
{
|
||||||
if (mWidget)
|
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());
|
QMutexLocker lock (getMutex());
|
||||||
getValues().setString (getKey(), getParent()->getKey(), text.toStdString());
|
Settings::Manager::setString (getKey(), getParent()->getKey(), text.toStdString());
|
||||||
}
|
}
|
||||||
|
|
||||||
getParent()->getState()->update (*this);
|
getParent()->getState()->update (*this);
|
||||||
|
@ -17,7 +17,7 @@ namespace CSMPrefs
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
StringSetting (Category *parent, Settings::Manager *values,
|
StringSetting (Category *parent,
|
||||||
QMutex *mutex, const std::string& key, const std::string& label, std::string default_);
|
QMutex *mutex, const std::string& key, const std::string& label, std::string default_);
|
||||||
|
|
||||||
StringSetting& setTooltip (const std::string& tooltip);
|
StringSetting& setTooltip (const std::string& tooltip);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user