Browse Source

Unify value loading paths

The idea is to try load every intermediate value from the base case and
then convert them to their respective type.
adaptive-webui-19844
Chocobo1 3 years ago
parent
commit
1c52fff1cc
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 13
      src/base/settingsstorage.h

13
src/base/settingsstorage.h

@ -60,17 +60,18 @@ public:
{ {
if constexpr (std::is_enum_v<T>) if constexpr (std::is_enum_v<T>)
{ {
const auto value = loadValueImpl(key).toString(); const auto value = loadValue<QString>(key);
return Utils::String::toEnum(value, defaultValue); return Utils::String::toEnum(value, defaultValue);
} }
else if constexpr (std::is_same_v<T, QVariant>) else if constexpr (IsQFlags<T>::value)
{ {
return loadValueImpl(key, defaultValue); const typename T::Int value = loadValue(key, static_cast<typename T::Int>(defaultValue));
return T {value};
} }
else if constexpr (IsQFlags<T>::value) else if constexpr (std::is_same_v<T, QVariant>)
{ {
const QVariant value = loadValueImpl(key, static_cast<typename T::Int>(defaultValue)); // fast path for loading QVariant
return T {value.template value<typename T::Int>()}; return loadValueImpl(key, defaultValue);
} }
else else
{ {

Loading…
Cancel
Save