2020-12-27 19:43:35 +00:00
|
|
|
#include "configuration.h"
|
|
|
|
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
QString getKey(const std::string & section, const std::string & key)
|
|
|
|
{
|
|
|
|
const QString qkey = QString::fromStdString(section) + "/" + QString::fromStdString(key);
|
|
|
|
return qkey;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-03 15:49:51 +00:00
|
|
|
QVariant Configuration::getVariant(const std::string & section, const std::string & key) const
|
2020-12-27 19:43:35 +00:00
|
|
|
{
|
|
|
|
const QString qkey = getKey(section, key);
|
|
|
|
const QVariant value = mySettings.value(qkey);
|
2021-11-03 15:49:51 +00:00
|
|
|
if (value.isNull())
|
|
|
|
{
|
|
|
|
throw std::runtime_error("Missing " + qkey.toStdString());
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string Configuration::getString(const std::string & section, const std::string & key) const
|
|
|
|
{
|
|
|
|
const QVariant value = getVariant(section, key);
|
|
|
|
const std::string res = value.toString().toStdString();
|
|
|
|
return res;
|
2020-12-27 19:43:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DWORD Configuration::getDWord(const std::string & section, const std::string & key) const
|
|
|
|
{
|
2021-11-03 15:49:51 +00:00
|
|
|
const QVariant value = getVariant(section, key);
|
|
|
|
const uint res = value.toUInt();
|
|
|
|
return res;
|
2020-12-27 19:43:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Configuration::getBool(const std::string & section, const std::string & key) const
|
|
|
|
{
|
2021-11-03 15:49:51 +00:00
|
|
|
const QVariant value = getVariant(section, key);
|
|
|
|
const bool res = value.toBool();
|
|
|
|
return res;
|
2020-12-27 19:43:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Configuration::putString(const std::string & section, const std::string & key, const std::string & value)
|
|
|
|
{
|
|
|
|
const QString s = QString::fromStdString(value);
|
|
|
|
mySettings.setValue(getKey(section, key), QVariant::fromValue(s));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Configuration::putDWord(const std::string & section, const std::string & key, const DWORD value)
|
|
|
|
{
|
|
|
|
mySettings.setValue(getKey(section, key), QVariant::fromValue(value));
|
|
|
|
}
|
2021-04-04 14:31:57 +01:00
|
|
|
|
|
|
|
std::map<std::string, std::map<std::string, std::string>> Configuration::getAllValues() const
|
|
|
|
{
|
|
|
|
throw std::runtime_error("Configuration::getAllValues not implemented.");
|
|
|
|
}
|