From 746d1af8262ed303a3b0934dde1a8b7e27108b83 Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Sun, 12 Apr 2026 00:00:56 +1000 Subject: [PATCH] feat: allow resetting options Also make options changed programmatically (from QML, etc) mark themselves as loaded --- plugin/src/Caelestia/Config/configobject.cpp | 18 ++++++++++++++++++ plugin/src/Caelestia/Config/configobject.hpp | 4 ++++ 2 files changed, 22 insertions(+) diff --git a/plugin/src/Caelestia/Config/configobject.cpp b/plugin/src/Caelestia/Config/configobject.cpp index fda9fba2..7a36f7b5 100644 --- a/plugin/src/Caelestia/Config/configobject.cpp +++ b/plugin/src/Caelestia/Config/configobject.cpp @@ -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; diff --git a/plugin/src/Caelestia/Config/configobject.hpp b/plugin/src/Caelestia/Config/configobject.hpp index a70cdd74..8ffe074c 100644 --- a/plugin/src/Caelestia/Config/configobject.hpp +++ b/plugin/src/Caelestia/Config/configobject.hpp @@ -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 static bool updateMember(T& member, const T& value) { @@ -86,6 +89,7 @@ signals: void propertiesChanged(const QMap& changed); protected: + void markPropertyLoaded(const QString& name); void notifyPropertyChanged(const QString& name, const QVariant& value); private: