feat: allow resetting options
Also make options changed programmatically (from QML, etc) mark themselves as loaded
This commit is contained in:
parent
93b5fb5f4f
commit
746d1af826
2 changed files with 22 additions and 0 deletions
|
|
@ -168,6 +168,24 @@ void ConfigObject::syncFromGlobal(ConfigObject* global) {
|
|||
}
|
||||
}
|
||||
|
||||
void ConfigObject::markPropertyLoaded(const QString& name) {
|
||||
m_loadedKeys.insert(name);
|
||||
}
|
||||
|
||||
void ConfigObject::resetOption(const QString& name) {
|
||||
m_loadedKeys.remove(name);
|
||||
|
||||
// If synced from global, re-copy the global value
|
||||
if (m_global) {
|
||||
int idx = metaObject()->indexOfProperty(name.toUtf8().constData());
|
||||
if (idx >= 0) {
|
||||
auto prop = metaObject()->property(idx);
|
||||
if (prop.isWritable())
|
||||
prop.write(this, prop.read(m_global));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ConfigObject::resyncFromGlobal() {
|
||||
if (!m_global)
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ public:
|
|||
} \
|
||||
void set_##name(const Type& val) { \
|
||||
if (caelestia::config::ConfigObject::updateMember(m_##name, val)) { \
|
||||
markPropertyLoaded(QStringLiteral(#name)); \
|
||||
Q_EMIT name##Changed(); \
|
||||
notifyPropertyChanged(QStringLiteral(#name), QVariant::fromValue(m_##name)); \
|
||||
} \
|
||||
|
|
@ -68,6 +69,8 @@ public:
|
|||
|
||||
[[nodiscard]] bool isPropertyLoaded(const QString& name) const { return m_loadedKeys.contains(name); }
|
||||
|
||||
Q_INVOKABLE void resetOption(const QString& name);
|
||||
|
||||
[[nodiscard]] bool recentlySaved() const { return m_recentlySaved; }
|
||||
|
||||
template <typename T> static bool updateMember(T& member, const T& value) {
|
||||
|
|
@ -86,6 +89,7 @@ signals:
|
|||
void propertiesChanged(const QMap<QString, QVariant>& changed);
|
||||
|
||||
protected:
|
||||
void markPropertyLoaded(const QString& name);
|
||||
void notifyPropertyChanged(const QString& name, const QVariant& value);
|
||||
|
||||
private:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue