Skip to content

Commit 0f31d85

Browse files
committed
Add overload setValue(const ConfigKey& key, QFlagsType& value)
1 parent 5e7366a commit 0f31d85

2 files changed

Lines changed: 22 additions & 6 deletions

File tree

src/preferences/configobject.h

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,16 +154,27 @@ template <class ValueType> class ConfigObject {
154154
// returns QString().
155155
QString getValueString(const ConfigKey& key) const;
156156

157+
template<typename E>
158+
struct is_qflags : std::false_type {};
159+
template<typename E>
160+
struct is_qflags<QFlags<E>> : std::true_type {};
161+
157162
// Sets the value for key to ValueType(value), over-writing pre-existing
158163
// values. ResultType is serialized to string on a per-type basis.
159-
template <class ResultType>
164+
template<class ResultType>
165+
requires(!std::is_enum_v<ResultType> && !is_qflags<ResultType>::value)
160166
void setValue(const ConfigKey& key, const ResultType& value);
161167
template<class EnumType>
162-
requires std::is_enum_v<EnumType>
168+
requires(std::is_enum_v<EnumType> && !is_qflags<EnumType>::value)
163169
// we need to take value as const ref otherwise the overload is ambiguous
164170
void setValue(const ConfigKey& key, const EnumType& value) {
165171
setValue<int>(key, static_cast<int>(value));
166172
};
173+
template<class QFlagsType>
174+
requires(is_qflags<QFlagsType>::value)
175+
void setValue(const ConfigKey& key, const QFlagsType& value) {
176+
setValue<int>(key, value.toInt());
177+
}
167178

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

178189
// Returns the value for key, converted to ResultType. If key is not present
179190
// or the value cannot be converted to ResultType, returns default_value.
180-
template<class ResultType>
181-
requires(!std::is_enum_v<ResultType>)
191+
template<typename ResultType>
192+
requires(!std::is_enum_v<ResultType> && !is_qflags<ResultType>::value)
182193
ResultType getValue(const ConfigKey& key, const ResultType& default_value) const;
183194
QString getValue(const ConfigKey& key, const char* default_value) const;
184195
template<typename EnumType>
185-
requires std::is_enum_v<EnumType>
196+
requires(std::is_enum_v<EnumType> && !is_qflags<EnumType>::value)
186197
EnumType getValue(const ConfigKey& key, const EnumType& default_value) const {
187198
// we need to take default_value as const ref otherwise the overload is ambiguous
188199
return static_cast<EnumType>(getValue<int>(key, static_cast<int>(default_value)));
189200
}
201+
template<typename QFlagsType>
202+
requires(is_qflags<QFlagsType>::value)
203+
QFlagsType getValue(const ConfigKey& key, const QFlagsType& default_value) const {
204+
return QFlagsType::fromInt(getValue<int>(key, default_value.toInt()));
205+
}
190206

191207
QMultiHash<ValueType, ConfigKey> transpose() const;
192208

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)