|
|
@ -1,5 +1,6 @@ |
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Bittorrent Client using Qt and libtorrent. |
|
|
|
* Bittorrent Client using Qt and libtorrent. |
|
|
|
|
|
|
|
* Copyright (C) 2023 Mike Tzou (Chocobo1) |
|
|
|
* Copyright (C) 2016 Vladimir Golovnev <glassez@yandex.ru> |
|
|
|
* Copyright (C) 2016 Vladimir Golovnev <glassez@yandex.ru> |
|
|
|
* Copyright (C) 2014 sledgehammer999 <hammered999@gmail.com> |
|
|
|
* Copyright (C) 2014 sledgehammer999 <hammered999@gmail.com> |
|
|
|
* |
|
|
|
* |
|
|
@ -41,10 +42,7 @@ |
|
|
|
#include "utils/string.h" |
|
|
|
#include "utils/string.h" |
|
|
|
|
|
|
|
|
|
|
|
template <typename T> |
|
|
|
template <typename T> |
|
|
|
struct IsQFlags : std::false_type {}; |
|
|
|
concept IsQFlags = std::same_as<T, QFlags<typename T::enum_type>>; |
|
|
|
|
|
|
|
|
|
|
|
template <typename T> |
|
|
|
|
|
|
|
struct IsQFlags<QFlags<T>> : std::true_type {}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// There are 2 ways for class `T` provide serialization support into `SettingsStorage`:
|
|
|
|
// There are 2 ways for class `T` provide serialization support into `SettingsStorage`:
|
|
|
|
// 1. If the `T` state is intended for users to edit (via a text editor), then
|
|
|
|
// 1. If the `T` state is intended for users to edit (via a text editor), then
|
|
|
@ -76,7 +74,7 @@ public: |
|
|
|
const auto value = loadValue<QString>(key); |
|
|
|
const auto value = loadValue<QString>(key); |
|
|
|
return Utils::String::toEnum(value, defaultValue); |
|
|
|
return Utils::String::toEnum(value, defaultValue); |
|
|
|
} |
|
|
|
} |
|
|
|
else if constexpr (IsQFlags<T>::value) |
|
|
|
else if constexpr (IsQFlags<T>) |
|
|
|
{ |
|
|
|
{ |
|
|
|
const typename T::Int value = loadValue(key, static_cast<typename T::Int>(defaultValue)); |
|
|
|
const typename T::Int value = loadValue(key, static_cast<typename T::Int>(defaultValue)); |
|
|
|
return T {value}; |
|
|
|
return T {value}; |
|
|
@ -101,7 +99,7 @@ public: |
|
|
|
storeValueImpl(key, value.toString()); |
|
|
|
storeValueImpl(key, value.toString()); |
|
|
|
else if constexpr (std::is_enum_v<T>) |
|
|
|
else if constexpr (std::is_enum_v<T>) |
|
|
|
storeValueImpl(key, Utils::String::fromEnum(value)); |
|
|
|
storeValueImpl(key, Utils::String::fromEnum(value)); |
|
|
|
else if constexpr (IsQFlags<T>::value) |
|
|
|
else if constexpr (IsQFlags<T>) |
|
|
|
storeValueImpl(key, static_cast<typename T::Int>(value)); |
|
|
|
storeValueImpl(key, static_cast<typename T::Int>(value)); |
|
|
|
else |
|
|
|
else |
|
|
|
storeValueImpl(key, QVariant::fromValue(value)); |
|
|
|
storeValueImpl(key, QVariant::fromValue(value)); |
|
|
|