1
0
mirror of https://github.com/d47081/qBittorrent.git synced 2025-01-11 15:27:54 +00:00

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.
This commit is contained in:
Chocobo1 2021-12-07 14:11:53 +08:00
parent 261f08b90e
commit 1c52fff1cc
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C

View File

@ -60,17 +60,18 @@ public:
{
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);
}
else if constexpr (std::is_same_v<T, QVariant>)
{
return loadValueImpl(key, defaultValue);
}
else if constexpr (IsQFlags<T>::value)
{
const QVariant value = loadValueImpl(key, static_cast<typename T::Int>(defaultValue));
return T {value.template value<typename T::Int>()};
const typename T::Int value = loadValue(key, static_cast<typename T::Int>(defaultValue));
return T {value};
}
else if constexpr (std::is_same_v<T, QVariant>)
{
// fast path for loading QVariant
return loadValueImpl(key, defaultValue);
}
else
{