1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-24 14:23:54 +00:00
openmw/apps/opencs/model/prefs/setting.cpp

100 lines
2.1 KiB
C++
Raw Normal View History

2015-12-08 16:21:58 +00:00
#include "setting.hpp"
2015-12-11 10:50:06 +00:00
#include <QColor>
2015-12-15 11:19:48 +00:00
#include <QMutexLocker>
2015-12-11 10:50:06 +00:00
#include <components/settings/settings.hpp>
2015-12-08 16:21:58 +00:00
#include "category.hpp"
#include "state.hpp"
2022-09-22 18:26:05 +00:00
QMutex* CSMPrefs::Setting::getMutex()
2015-12-15 11:19:48 +00:00
{
return mMutex;
}
2022-09-22 18:26:05 +00:00
CSMPrefs::Setting::Setting(Category* parent, QMutex* mutex, const std::string& key, const std::string& label)
: QObject(parent->getState())
, mParent(parent)
, mMutex(mutex)
, mKey(key)
, mLabel(label)
2015-12-11 10:22:15 +00:00
{
}
2022-09-22 18:26:05 +00:00
CSMPrefs::Setting::~Setting() {}
std::pair<QWidget*, QWidget*> CSMPrefs::Setting::makeWidgets(QWidget* parent)
{
2022-09-22 18:26:05 +00:00
return std::pair<QWidget*, QWidget*>(0, 0);
}
2022-09-22 18:26:05 +00:00
void CSMPrefs::Setting::updateWidget() {}
const CSMPrefs::Category* CSMPrefs::Setting::getParent() const
2015-12-08 16:21:58 +00:00
{
return mParent;
}
const std::string& CSMPrefs::Setting::getKey() const
{
return mKey;
}
const std::string& CSMPrefs::Setting::getLabel() const
{
return mLabel;
}
2015-12-11 10:50:06 +00:00
int CSMPrefs::Setting::toInt() const
{
2022-09-22 18:26:05 +00:00
QMutexLocker lock(mMutex);
return Settings::Manager::getInt(mKey, mParent->getKey());
2015-12-11 10:50:06 +00:00
}
double CSMPrefs::Setting::toDouble() const
{
2022-09-22 18:26:05 +00:00
QMutexLocker lock(mMutex);
return Settings::Manager::getFloat(mKey, mParent->getKey());
2015-12-11 10:50:06 +00:00
}
std::string CSMPrefs::Setting::toString() const
{
2022-09-22 18:26:05 +00:00
QMutexLocker lock(mMutex);
return Settings::Manager::getString(mKey, mParent->getKey());
2015-12-11 10:50:06 +00:00
}
bool CSMPrefs::Setting::isTrue() const
{
2022-09-22 18:26:05 +00:00
QMutexLocker lock(mMutex);
return Settings::Manager::getBool(mKey, mParent->getKey());
2015-12-11 10:50:06 +00:00
}
QColor CSMPrefs::Setting::toColor() const
{
2015-12-15 18:32:42 +00:00
// toString() handles lock
2022-09-22 18:26:05 +00:00
return QColor(QString::fromUtf8(toString().c_str()));
2015-12-11 10:50:06 +00:00
}
2022-09-22 18:26:05 +00:00
bool CSMPrefs::operator==(const Setting& setting, const std::string& key)
2015-12-11 10:50:06 +00:00
{
std::string fullKey = setting.getParent()->getKey() + "/" + setting.getKey();
2022-09-22 18:26:05 +00:00
return fullKey == key;
2015-12-11 10:50:06 +00:00
}
2022-09-22 18:26:05 +00:00
bool CSMPrefs::operator==(const std::string& key, const Setting& setting)
2015-12-11 10:50:06 +00:00
{
2022-09-22 18:26:05 +00:00
return setting == key;
2015-12-11 10:50:06 +00:00
}
2022-09-22 18:26:05 +00:00
bool CSMPrefs::operator!=(const Setting& setting, const std::string& key)
2015-12-11 10:50:06 +00:00
{
2022-09-22 18:26:05 +00:00
return !(setting == key);
2015-12-11 10:50:06 +00:00
}
2022-09-22 18:26:05 +00:00
bool CSMPrefs::operator!=(const std::string& key, const Setting& setting)
2015-12-11 10:50:06 +00:00
{
2022-09-22 18:26:05 +00:00
return !(key == setting);
2015-12-11 10:50:06 +00:00
}