diff options
author | jan Iversen <jani@apache.org> | 2018-07-02 09:25:20 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-07-07 09:44:06 -0700 |
commit | e3767fdc43ca0008bcc5265ba18d067ff06685ec (patch) | |
tree | bef5dc43ce0bab56dc0bd33a552a93549dbfd654 | |
parent | 7ee1aab7286d529d5ae8e32ef0c43bef1cab912a (diff) | |
download | subsurface-e3767fdc43ca0008bcc5265ba18d067ff06685ec.tar.gz |
core: add macros to handle setter functions
Add macros to handle full function set functions in qPref
Remark: the function name is fixed to be "set_<name>" where name is
identical to the variable in struct preferences
This is not our standard naming, but is consistent with struct
preferences (that also use different name schemes).
Signed-off-by: Jan Iversen <jani@apache.org>
-rw-r--r-- | core/settings/qPref_private.h | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/core/settings/qPref_private.h b/core/settings/qPref_private.h index ebe266581..67ed08a43 100644 --- a/core/settings/qPref_private.h +++ b/core/settings/qPref_private.h @@ -102,7 +102,6 @@ void qPref ## class::disk_ ## field(bool doSync) \ LOADSYNC_TXT(name, field); \ } - //******* Macros to generate get function #define GET_PREFERENCE_BOOL(class, field) \ bool qPref ## class::field () const \ @@ -133,4 +132,55 @@ const QString qPref ## class::field () const \ { \ return prefs.field; \ } + +//******* Macros to generate set function +#define SET_PREFERENCE_BOOL(class, field) \ +void qPref ## class::set_ ## field (bool value) \ +{ \ + if (value != prefs.field) { \ + prefs.field = value; \ + disk_ ## field(true); \ + emit field ## _changed(value); \ + } \ +} + +#define SET_PREFERENCE_DOUBLE(class, field) \ +void qPref ## class::set_ ## field (double value) \ +{ \ + if (value != prefs.field) { \ + prefs.field = value; \ + disk_ ## field(true); \ + emit field ## _changed(value); \ + } \ +} + +#define SET_PREFERENCE_ENUM(class, type, field) \ +void qPref ## class::set_ ## field (type value) \ +{ \ + if (value != prefs.field) { \ + prefs.field = value; \ + disk_ ## field(true); \ + emit field ## _changed(value); \ + } \ +} + +#define SET_PREFERENCE_INT(class, field) \ +void qPref ## class::set_ ## field (int value) \ +{ \ + if (value != prefs.field) { \ + prefs.field = value; \ + disk_ ## field(true); \ + emit field ## _changed(value); \ + } \ +} + +#define SET_PREFERENCE_TXT(class, field) \ +void qPref ## class::set_ ## field (const QString& value) \ +{ \ + if (value != prefs.field) { \ + COPY_TXT(field, value); \ + disk_ ## field(true); \ + emit field ## _changed(value); \ + } \ +} #endif |