forked from teamnwah/openmw-tes3coop
added interface for querying settings
This commit is contained in:
parent
31b105ad9e
commit
8245b9e439
7 changed files with 83 additions and 3 deletions
|
@ -1,6 +1,10 @@
|
||||||
|
|
||||||
#include "category.hpp"
|
#include "category.hpp"
|
||||||
|
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
#include "setting.hpp"
|
||||||
|
|
||||||
CSMPrefs::Category::Category (State *parent, const std::string& key)
|
CSMPrefs::Category::Category (State *parent, const std::string& key)
|
||||||
: mParent (parent), mKey (key)
|
: mParent (parent), mKey (key)
|
||||||
{}
|
{}
|
||||||
|
@ -29,3 +33,12 @@ CSMPrefs::Category::Iterator CSMPrefs::Category::end()
|
||||||
{
|
{
|
||||||
return mSettings.end();
|
return mSettings.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CSMPrefs::Setting& CSMPrefs::Category::operator[] (const std::string& key)
|
||||||
|
{
|
||||||
|
for (Iterator iter = mSettings.begin(); iter!=mSettings.end(); ++iter)
|
||||||
|
if ((*iter)->getKey()==key)
|
||||||
|
return **iter;
|
||||||
|
|
||||||
|
throw std::logic_error ("Invalid user setting: " + key);
|
||||||
|
}
|
||||||
|
|
|
@ -35,6 +35,8 @@ namespace CSMPrefs
|
||||||
Iterator begin();
|
Iterator begin();
|
||||||
|
|
||||||
Iterator end();
|
Iterator end();
|
||||||
|
|
||||||
|
Setting& operator[] (const std::string& key);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
|
|
||||||
#include "setting.hpp"
|
#include "setting.hpp"
|
||||||
|
|
||||||
|
#include <QColor>
|
||||||
|
|
||||||
#include "category.hpp"
|
#include "category.hpp"
|
||||||
#include "state.hpp"
|
#include "state.hpp"
|
||||||
|
|
||||||
|
@ -35,3 +37,49 @@ const std::string& CSMPrefs::Setting::getLabel() const
|
||||||
{
|
{
|
||||||
return mLabel;
|
return mLabel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int CSMPrefs::Setting::toInt() const
|
||||||
|
{
|
||||||
|
return mValues->getInt (mKey, mParent->getKey());
|
||||||
|
}
|
||||||
|
|
||||||
|
double CSMPrefs::Setting::toDouble() const
|
||||||
|
{
|
||||||
|
return mValues->getFloat (mKey, mParent->getKey());
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string CSMPrefs::Setting::toString() const
|
||||||
|
{
|
||||||
|
return mValues->getString (mKey, mParent->getKey());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CSMPrefs::Setting::isTrue() const
|
||||||
|
{
|
||||||
|
return mValues->getBool (mKey, mParent->getKey());
|
||||||
|
}
|
||||||
|
|
||||||
|
QColor CSMPrefs::Setting::toColor() const
|
||||||
|
{
|
||||||
|
return QColor (QString::fromUtf8 (toString().c_str()));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CSMPrefs::operator== (const Setting& setting, const std::string& key)
|
||||||
|
{
|
||||||
|
std::string fullKey = setting.getParent()->getKey() + "/" + setting.getKey();
|
||||||
|
return fullKey==key;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CSMPrefs::operator== (const std::string& key, const Setting& setting)
|
||||||
|
{
|
||||||
|
return setting==key;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CSMPrefs::operator!= (const Setting& setting, const std::string& key)
|
||||||
|
{
|
||||||
|
return !(setting==key);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CSMPrefs::operator!= (const std::string& key, const Setting& setting)
|
||||||
|
{
|
||||||
|
return !(key==setting);
|
||||||
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
class QWidget;
|
class QWidget;
|
||||||
|
class QColor;
|
||||||
|
|
||||||
namespace Settings
|
namespace Settings
|
||||||
{
|
{
|
||||||
|
@ -47,7 +48,23 @@ namespace CSMPrefs
|
||||||
const std::string& getKey() const;
|
const std::string& getKey() const;
|
||||||
|
|
||||||
const std::string& getLabel() const;
|
const std::string& getLabel() const;
|
||||||
|
|
||||||
|
int toInt() const;
|
||||||
|
|
||||||
|
double toDouble() const;
|
||||||
|
|
||||||
|
std::string toString() const;
|
||||||
|
|
||||||
|
bool isTrue() const;
|
||||||
|
|
||||||
|
QColor toColor() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// note: fullKeys have the format categoryKey/settingKey
|
||||||
|
bool operator== (const Setting& setting, const std::string& fullKey);
|
||||||
|
bool operator== (const std::string& fullKey, const Setting& setting);
|
||||||
|
bool operator!= (const Setting& setting, const std::string& fullKey);
|
||||||
|
bool operator!= (const std::string& fullKey, const Setting& setting);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -356,7 +356,7 @@ CSMPrefs::State::Iterator CSMPrefs::State::end()
|
||||||
return mCategories.end();
|
return mCategories.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
CSMPrefs::Category& CSMPrefs::State::getCategory (const std::string& key)
|
CSMPrefs::Category& CSMPrefs::State::operator[] (const std::string& key)
|
||||||
{
|
{
|
||||||
Iterator iter = mCategories.find (key);
|
Iterator iter = mCategories.find (key);
|
||||||
|
|
||||||
|
|
|
@ -81,7 +81,7 @@ namespace CSMPrefs
|
||||||
|
|
||||||
Iterator end();
|
Iterator end();
|
||||||
|
|
||||||
Category& getCategory (const std::string& key);
|
Category& operator[](const std::string& key);
|
||||||
|
|
||||||
void update (const Setting& setting);
|
void update (const Setting& setting);
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,7 @@ CSVPrefs::PageBase *CSVPrefs::Dialogue::makePage (const std::string& key)
|
||||||
{
|
{
|
||||||
// special case page code goes here
|
// special case page code goes here
|
||||||
|
|
||||||
return new Page (CSMPrefs::get().getCategory (key), mContent);
|
return new Page (CSMPrefs::get()[key], mContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
CSVPrefs::Dialogue::Dialogue()
|
CSVPrefs::Dialogue::Dialogue()
|
||||||
|
|
Loading…
Reference in a new issue