From e3767fdc43ca0008bcc5265ba18d067ff06685ec Mon Sep 17 00:00:00 2001 From: jan Iversen Date: Mon, 2 Jul 2018 09:25:20 +0200 Subject: [PATCH] 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_" 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 --- core/settings/qPref_private.h | 52 ++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) 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