7#include "settingbase.h"
12#include <qfilesystemwatcher.h>
19#include <qstringliteral.h>
21#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
22#include <qtmetamacros.h>
24#include <qobjectdefs.h>
41class Setting final :
public SettingBase
45 virtual ~Setting()
override;
50 void setValue(
const T &newValue);
55 Setting(
const Setting &) =
delete;
56 Setting &operator=(
const Setting &) =
delete;
59 static constexpr bool m_isEnum = std::is_enum_v<T>;
67 void updateFromQSettings();
70 friend class TestSetting;
101Setting<T>::Setting(
const QString &key, Settings *settings,
QObject *parent)
102 : SettingBase(key, settings, parent)
104 if constexpr (m_isEnum) {
106 std::is_same_v<std::underlying_type_t<T>,
int>,
108 "If 'typename T' is an enum, its underlying type must be 'int'.");
113 qRegisterMetaType<T>();
114#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
116 qRegisterMetaTypeStreamOperators<T>();
119 if constexpr (m_isEnum) {
124 updateFromQSettings();
128 &Settings::updatedAfterFileChange,
130 &PerceptualColor::Setting<T>::updateFromQSettings
136Setting<T>::~Setting()
146void Setting<T>::updateFromQSettings()
159 const QVariant newValueVariant = underlyingQSettings()->
value(m_key);
161 if constexpr (m_isEnum) {
163 const int enumInteger = m_qMetaEnum.keysToValue(byteArray.
constData());
164 newValue =
static_cast<T
>(enumInteger);
166 newValue = newValueVariant.
value<T>();
170 if (newValue != m_value) {
172 Q_EMIT valueChanged();
179T Setting<T>::value()
const
188void Setting<T>::setValue(
const T &newValue)
190 if (newValue != m_value) {
192 if constexpr (m_isEnum) {
193 const auto newValueUnderlying =
194 static_cast<int>(newValue);
196 m_qMetaEnum.valueToKeys(newValueUnderlying));
197 underlyingQSettings()->setValue(m_key,
string);
200 underlyingQSettings()->setValue(m_key, newVariant);
202 Q_EMIT valueChanged();
The namespace of this library.
const char * constData() const const
QObject * parent() const const
QString fromUtf8(QByteArrayView str)
QByteArray toUtf8() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
QVariant fromValue(T &&value)
QString toString() const const