diff options
author | Petr Mrázek <peterix@gmail.com> | 2013-07-16 00:30:32 +0200 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2013-07-16 00:30:32 +0200 |
commit | e2ee6d6d254285284f07b07cb60409fbda0bf7ad (patch) | |
tree | 30810ad496b34ae949aba3a72efb0a0363e8b718 /libsettings | |
parent | b5450042b5f9ddaad7585f644591b7d009aeb5cb (diff) | |
download | MultiMC-e2ee6d6d254285284f07b07cb60409fbda0bf7ad.tar MultiMC-e2ee6d6d254285284f07b07cb60409fbda0bf7ad.tar.gz MultiMC-e2ee6d6d254285284f07b07cb60409fbda0bf7ad.tar.lz MultiMC-e2ee6d6d254285284f07b07cb60409fbda0bf7ad.tar.xz MultiMC-e2ee6d6d254285284f07b07cb60409fbda0bf7ad.zip |
Finalize the instance settings dialog, add setting reset mechanism
Diffstat (limited to 'libsettings')
-rw-r--r-- | libsettings/include/inisettingsobject.h | 1 | ||||
-rw-r--r-- | libsettings/include/setting.h | 13 | ||||
-rw-r--r-- | libsettings/include/settingsobject.h | 22 | ||||
-rw-r--r-- | libsettings/src/inisettingsobject.cpp | 9 | ||||
-rw-r--r-- | libsettings/src/setting.cpp | 5 | ||||
-rw-r--r-- | libsettings/src/settingsobject.cpp | 18 |
6 files changed, 68 insertions, 0 deletions
diff --git a/libsettings/include/inisettingsobject.h b/libsettings/include/inisettingsobject.h index 36c8e4bd..03d6fe05 100644 --- a/libsettings/include/inisettingsobject.h +++ b/libsettings/include/inisettingsobject.h @@ -47,6 +47,7 @@ public: protected slots: virtual void changeSetting(const Setting &setting, QVariant value); + virtual void resetSetting ( const Setting& setting ); protected: virtual QVariant retrieveValue(const Setting &setting); diff --git a/libsettings/include/setting.h b/libsettings/include/setting.h index 36709729..a161ab50 100644 --- a/libsettings/include/setting.h +++ b/libsettings/include/setting.h @@ -84,6 +84,12 @@ signals: */ void settingChanged(const Setting &setting, QVariant value); + /*! + * \brief Signal emitted when this Setting object's value resets to default. + * \param setting A reference to the Setting that changed. + */ + void settingReset(const Setting &setting); + public slots: /*! * \brief Changes the setting's value. @@ -93,6 +99,13 @@ public slots: */ virtual void set(QVariant value); + /*! + * \brief Reset the setting to default + * This is done by emitting the settingReset() signal which will then be + * handled by the SettingsObject object and cause the setting to change. + * \param value The new value. + */ + virtual void reset(); protected: QString m_id; QVariant m_defVal; diff --git a/libsettings/include/settingsobject.h b/libsettings/include/settingsobject.h index 23f0d644..a2f03699 100644 --- a/libsettings/include/settingsobject.h +++ b/libsettings/include/settingsobject.h @@ -100,6 +100,11 @@ public: */ virtual bool set(const QString &id, QVariant value); + /*! + * \brief Reverts the setting with the given ID to default. + * \param id The ID of the setting to reset. + */ + virtual void reset(const QString &id) const; /*! * \brief Gets a QList with pointers to all of the registered settings. @@ -125,6 +130,14 @@ signals: */ void settingChanged(const Setting &setting, QVariant value); + /*! + * \brief Signal emitted when one of this SettingsObject object's settings resets. + * This is usually just connected directly to each Setting object's + * settingReset() signals. + * \param setting A reference to the Setting object that changed. + */ + void settingReset(const Setting &setting); + protected slots: /*! * \brief Changes a setting. @@ -136,6 +149,15 @@ protected slots: */ virtual void changeSetting(const Setting &setting, QVariant value) = 0; + /*! + * \brief Resets a setting. + * This slot is usually connected to each Setting object's + * settingReset() signal. The signal is emitted, causing this slot + * to update the setting's value in the config file. + * \param setting A reference to the Setting object that changed. + */ + virtual void resetSetting(const Setting &setting) = 0; + protected: /*! * \brief Connects the necessary signals to the given Setting. diff --git a/libsettings/src/inisettingsobject.cpp b/libsettings/src/inisettingsobject.cpp index 17b132a3..854421b6 100644 --- a/libsettings/src/inisettingsobject.cpp +++ b/libsettings/src/inisettingsobject.cpp @@ -40,6 +40,15 @@ void INISettingsObject::changeSetting(const Setting &setting, QVariant value) } } +void INISettingsObject::resetSetting ( const Setting& setting ) +{ + if (contains(setting.id())) + { + m_ini.remove(setting.configKey()); + m_ini.saveFile(m_filePath); + } +} + QVariant INISettingsObject::retrieveValue(const Setting &setting) { if (contains(setting.id())) diff --git a/libsettings/src/setting.cpp b/libsettings/src/setting.cpp index 1a4f9e13..8e60af06 100644 --- a/libsettings/src/setting.cpp +++ b/libsettings/src/setting.cpp @@ -47,3 +47,8 @@ void Setting::set(QVariant value) { emit settingChanged(*this, value); } + +void Setting::reset() +{ + emit settingReset(*this); +} diff --git a/libsettings/src/settingsobject.cpp b/libsettings/src/settingsobject.cpp index f94a6552..bf7b8825 100644 --- a/libsettings/src/settingsobject.cpp +++ b/libsettings/src/settingsobject.cpp @@ -98,6 +98,14 @@ bool SettingsObject::set(const QString &id, QVariant value) } } +void SettingsObject::reset(const QString &id) const +{ + Setting *setting = getSetting(id); + if(setting) + setting->reset(); +} + + QList<Setting *> SettingsObject::getSettings() { return m_settings.values(); @@ -115,6 +123,11 @@ void SettingsObject::connectSignals(const Setting &setting) SLOT(changeSetting(const Setting &, QVariant))); connect(&setting, SIGNAL(settingChanged(const Setting &, QVariant)), SIGNAL(settingChanged(const Setting &, QVariant))); + + connect(&setting, SIGNAL(settingReset(Setting)), + SLOT(resetSetting(const Setting &))); + connect(&setting, SIGNAL(settingReset(Setting)), + SIGNAL(settingReset(const Setting &))); } void SettingsObject::disconnectSignals(const Setting &setting) @@ -123,4 +136,9 @@ void SettingsObject::disconnectSignals(const Setting &setting) this, SLOT(changeSetting(const Setting &, QVariant))); setting.disconnect(SIGNAL(settingChanged(const Setting &, QVariant)), this, SIGNAL(settingChanged(const Setting &, QVariant))); + + setting.disconnect(SIGNAL(settingReset(const Setting &, QVariant)), + this, SLOT(resetSetting(const Setting &, QVariant))); + setting.disconnect(SIGNAL(settingReset(const Setting &, QVariant)), + this, SIGNAL(settingReset(const Setting &, QVariant))); } |