|
|
@ -34,6 +34,7 @@ |
|
|
|
#include <QString> |
|
|
|
#include <QString> |
|
|
|
|
|
|
|
|
|
|
|
#include "settingsstorage.h" |
|
|
|
#include "settingsstorage.h" |
|
|
|
|
|
|
|
#include "utils/string.h" |
|
|
|
|
|
|
|
|
|
|
|
template <typename T> |
|
|
|
template <typename T> |
|
|
|
class CachedSettingValue |
|
|
|
class CachedSettingValue |
|
|
@ -94,20 +95,13 @@ private: |
|
|
|
template <typename U, typename std::enable_if<std::is_enum<U>::value, int>::type = 0> |
|
|
|
template <typename U, typename std::enable_if<std::is_enum<U>::value, int>::type = 0> |
|
|
|
U loadValue(const U &defaultValue) |
|
|
|
U loadValue(const U &defaultValue) |
|
|
|
{ |
|
|
|
{ |
|
|
|
static_assert(std::is_same<int, typename std::underlying_type<U>::type>::value, |
|
|
|
return Utils::String::parse(SettingsStorage::instance()->loadValue(m_keyName).toString(), defaultValue); |
|
|
|
"Enumeration underlying type has to be int"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool ok = false; |
|
|
|
|
|
|
|
const U res = static_cast<U>(QMetaEnum::fromType<U>().keyToValue( |
|
|
|
|
|
|
|
SettingsStorage::instance()->loadValue(m_keyName).toString().toLatin1().constData(), &ok)); |
|
|
|
|
|
|
|
return ok ? res : defaultValue; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
template <typename U, typename std::enable_if<std::is_enum<U>::value, int>::type = 0> |
|
|
|
template <typename U, typename std::enable_if<std::is_enum<U>::value, int>::type = 0> |
|
|
|
void storeValue(const U &value) |
|
|
|
void storeValue(const U &value) |
|
|
|
{ |
|
|
|
{ |
|
|
|
SettingsStorage::instance()->storeValue(m_keyName, |
|
|
|
SettingsStorage::instance()->storeValue(m_keyName, Utils::String::serialize(value)); |
|
|
|
QString::fromLatin1(QMetaEnum::fromType<U>().valueToKey(static_cast<int>(value)))); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const QString m_keyName; |
|
|
|
const QString m_keyName; |
|
|
|