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>
This commit is contained in:
jan Iversen 2018-07-02 09:25:20 +02:00 committed by Dirk Hohndel
parent 7ee1aab728
commit e3767fdc43

View file

@ -102,7 +102,6 @@ void qPref ## class::disk_ ## field(bool doSync) \
LOADSYNC_TXT(name, field); \ LOADSYNC_TXT(name, field); \
} }
//******* Macros to generate get function //******* Macros to generate get function
#define GET_PREFERENCE_BOOL(class, field) \ #define GET_PREFERENCE_BOOL(class, field) \
bool qPref ## class::field () const \ bool qPref ## class::field () const \
@ -133,4 +132,55 @@ const QString qPref ## class::field () const \
{ \ { \
return prefs.field; \ 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 #endif