Skip to content

Commit 8414ddc

Browse files
committed
Add overload setValue(const ConfigKey& key, const QFlags<EnumType>& value)
1 parent 5e7366a commit 8414ddc

2 files changed

Lines changed: 19 additions & 4 deletions

File tree

src/preferences/configobject.h

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,11 @@ template <class ValueType> class ConfigObject {
164164
void setValue(const ConfigKey& key, const EnumType& value) {
165165
setValue<int>(key, static_cast<int>(value));
166166
};
167+
template<class EnumType>
168+
requires std::is_enum_v<EnumType>
169+
void setValue(const ConfigKey& key, const QFlags<EnumType>& value) {
170+
setValue<int>(key, value.toInt());
171+
}
167172

168173
// Returns the value for key, converted to ResultType. If key is not present
169174
// or the value cannot be converted to ResultType, returns ResultType().
@@ -175,18 +180,28 @@ template <class ValueType> class ConfigObject {
175180
return getValueString(key);
176181
}
177182

183+
template<typename E>
184+
struct is_qflags : std::false_type {};
185+
template<typename E>
186+
struct is_qflags<QFlags<E>> : std::true_type {};
187+
178188
// Returns the value for key, converted to ResultType. If key is not present
179189
// or the value cannot be converted to ResultType, returns default_value.
180-
template<class ResultType>
181-
requires(!std::is_enum_v<ResultType>)
190+
template<typename ResultType>
191+
requires(!std::is_enum_v<ResultType> && !is_qflags<ResultType>::value)
182192
ResultType getValue(const ConfigKey& key, const ResultType& default_value) const;
183193
QString getValue(const ConfigKey& key, const char* default_value) const;
184194
template<typename EnumType>
185-
requires std::is_enum_v<EnumType>
195+
requires(std::is_enum_v<EnumType> && !is_qflags<EnumType>::value)
186196
EnumType getValue(const ConfigKey& key, const EnumType& default_value) const {
187197
// we need to take default_value as const ref otherwise the overload is ambiguous
188198
return static_cast<EnumType>(getValue<int>(key, static_cast<int>(default_value)));
189199
}
200+
template<typename QFlagsType>
201+
requires(is_qflags<QFlagsType>::value)
202+
QFlagsType getValue(const ConfigKey& key, const QFlagsType& default_value) const {
203+
return QFlagsType::fromInt(getValue<int>(key, default_value.toInt()));
204+
}
190205

191206
QMultiHash<ValueType, ConfigKey> transpose() const;
192207

src/waveform/waveformwidgetfactory.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1421,7 +1421,7 @@ void WaveformWidgetFactory::setWaveformOption(
14211421
currentOptions.setFlag(option, enabled);
14221422
// clear unsupported options
14231423
currentOptions &= supportedOptions;
1424-
m_config->setValue<int>(kWaveformOptionsKey, currentOptions);
1424+
m_config->setValue(kWaveformOptionsKey, currentOptions);
14251425
}
14261426

14271427
void WaveformWidgetFactory::resetWaveformOptions() {

0 commit comments

Comments
 (0)