Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions src/preferences/configobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,27 @@ template <class ValueType> class ConfigObject {
// returns QString().
QString getValueString(const ConfigKey& key) const;

template<typename E>
struct is_qflags : std::false_type {};
template<typename E>
struct is_qflags<QFlags<E>> : std::true_type {};

// Sets the value for key to ValueType(value), over-writing pre-existing
// values. ResultType is serialized to string on a per-type basis.
template <class ResultType>
template<class ResultType>
requires(!std::is_enum_v<ResultType> && !is_qflags<ResultType>::value)
void setValue(const ConfigKey& key, const ResultType& value);
template<class EnumType>
requires std::is_enum_v<EnumType>
requires(std::is_enum_v<EnumType> && !is_qflags<EnumType>::value)
// we need to take value as const ref otherwise the overload is ambiguous
void setValue(const ConfigKey& key, const EnumType& value) {
setValue<int>(key, static_cast<int>(value));
};
template<class QFlagsType>
requires(is_qflags<QFlagsType>::value)
void setValue(const ConfigKey& key, const QFlagsType& value) {
setValue<int>(key, value.toInt());
}

// Returns the value for key, converted to ResultType. If key is not present
// or the value cannot be converted to ResultType, returns ResultType().
Expand All @@ -177,15 +188,21 @@ template <class ValueType> class ConfigObject {

// Returns the value for key, converted to ResultType. If key is not present
// or the value cannot be converted to ResultType, returns default_value.
template <class ResultType>
template<typename ResultType>
requires(!std::is_enum_v<ResultType> && !is_qflags<ResultType>::value)
ResultType getValue(const ConfigKey& key, const ResultType& default_value) const;
QString getValue(const ConfigKey& key, const char* default_value) const;
template<typename EnumType>
requires std::is_enum_v<EnumType>
requires(std::is_enum_v<EnumType> && !is_qflags<EnumType>::value)
EnumType getValue(const ConfigKey& key, const EnumType& default_value) const {
// we need to take default_value as const ref otherwise the overload is ambiguous
return static_cast<EnumType>(getValue<int>(key, static_cast<int>(default_value)));
}
template<typename QFlagsType>
requires(is_qflags<QFlagsType>::value)
QFlagsType getValue(const ConfigKey& key, const QFlagsType& default_value) const {
return QFlagsType::fromInt(getValue<int>(key, default_value.toInt()));
}

QMultiHash<ValueType, ConfigKey> transpose() const;

Expand Down
Loading
Loading