summaryrefslogtreecommitdiffstats
path: root/core/settings/qPrefPrivate.h
diff options
context:
space:
mode:
authorGravatar jan Iversen <jani@apache.org>2018-07-22 15:30:07 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-07-25 08:35:04 -0700
commitead05c8e17d320e723b982584cbd94c3ffdd5662 (patch)
treed65d0b9e3d58295364015d4a96efd15787bda400 /core/settings/qPrefPrivate.h
parent92ade62260c30be55632047fa97332b2d2d97a8f (diff)
downloadsubsurface-ead05c8e17d320e723b982584cbd94c3ffdd5662.tar.gz
core: expand qPref macros to handle sub structure
Expand SET_, DISK_ and HANDLE_ macros with field for substructure Structure prefs contains e.g. prefs.dive_computer.vendor an extra field are added to the macros to allow this. Signed-off-by: Jan Iversen <jani@apache.org>
Diffstat (limited to 'core/settings/qPrefPrivate.h')
-rw-r--r--core/settings/qPrefPrivate.h118
1 files changed, 75 insertions, 43 deletions
diff --git a/core/settings/qPrefPrivate.h b/core/settings/qPrefPrivate.h
index 29cb9028c..804c6921b 100644
--- a/core/settings/qPrefPrivate.h
+++ b/core/settings/qPrefPrivate.h
@@ -32,130 +32,162 @@ private:
//******* Macros to generate disk function
-#define DISK_LOADSYNC_BOOL(usegroup, name, field) \
+#define DISK_LOADSYNC_BOOL_EXT(usegroup, name, field, usestruct) \
void qPref ## usegroup::disk_ ## field(bool doSync) \
{ \
if (doSync) \
- qPrefPrivate::instance()->setting.setValue(group + name, prefs.field); \
+ qPrefPrivate::instance()->setting.setValue(group + name, prefs.usestruct field); \
else \
- prefs.field = qPrefPrivate::instance()->setting.value(group + name, default_prefs.field).toBool(); \
+ prefs.usestruct field = qPrefPrivate::instance()->setting.value(group + name, default_prefs.usestruct field).toBool(); \
}
+#define DISK_LOADSYNC_BOOL(usegroup, name, field) \
+DISK_LOADSYNC_BOOL_EXT(usegroup, name, field, )
-#define DISK_LOADSYNC_DOUBLE(usegroup, name, field) \
+#define DISK_LOADSYNC_DOUBLE_EXT(usegroup, name, field, usestruct) \
void qPref ## usegroup::disk_ ## field(bool doSync) \
{ \
if (doSync) \
- qPrefPrivate::instance()->setting.setValue(group + name, prefs.field); \
+ qPrefPrivate::instance()->setting.setValue(group + name, prefs.usestruct field); \
else \
- prefs.field = qPrefPrivate::instance()->setting.value(group + name, default_prefs.field).toDouble(); \
+ prefs.usestruct field = qPrefPrivate::instance()->setting.value(group + name, default_prefs.usestruct field).toDouble(); \
}
+#define DISK_LOADSYNC_DOUBLE(usegroup, name, field) \
+DISK_LOADSYNC_DOUBLE_EXT(usegroup, name, field, )
-#define DISK_LOADSYNC_ENUM(usegroup, name, type, field) \
+#define DISK_LOADSYNC_ENUM_EXT(usegroup, name, type, field, usestruct) \
void qPref ## usegroup::disk_ ## field(bool doSync) \
{ \
if (doSync) \
- qPrefPrivate::instance()->setting.setValue(group + name, prefs.field); \
+ qPrefPrivate::instance()->setting.setValue(group + name, prefs.usestruct field); \
else \
- prefs.field = (enum type)qPrefPrivate::instance()->setting.value(group + name, default_prefs.field).toInt(); \
+ prefs.usestruct field = (enum type)qPrefPrivate::instance()->setting.value(group + name, default_prefs.usestruct field).toInt(); \
}
+#define DISK_LOADSYNC_ENUM(usegroup, name, type, field) \
+DISK_LOADSYNC_ENUM_EXT(usegroup, name, type, field, )
-#define DISK_LOADSYNC_INT(usegroup, name, field) \
+#define DISK_LOADSYNC_INT_EXT(usegroup, name, field, usestruct) \
void qPref ## usegroup::disk_ ## field(bool doSync) \
{ \
if (doSync) \
- qPrefPrivate::instance()->setting.setValue(group + name, prefs.field); \
+ qPrefPrivate::instance()->setting.setValue(group + name, prefs.usestruct field); \
else \
- prefs.field = qPrefPrivate::instance()->setting.value(group + name, default_prefs.field).toInt(); \
+ prefs.usestruct field = qPrefPrivate::instance()->setting.value(group + name, default_prefs.usestruct field).toInt(); \
}
+#define DISK_LOADSYNC_INT(usegroup, name, field) \
+DISK_LOADSYNC_INT(usegroup, name, field, )
-#define DISK_LOADSYNC_INT_DEF(usegroup, name, field, defval) \
+#define DISK_LOADSYNC_INT_DEF_EXT(usegroup, name, field, defval, usestruct) \
void qPref ## usegroup::disk_ ## field(bool doSync) \
{ \
if (doSync) \
- qPrefPrivate::instance()->setting.setValue(group + name, prefs.field); \
+ qPrefPrivate::instance()->setting.setValue(group + name, prefs.usestruct field); \
else \
- prefs.field = qPrefPrivate::instance()->setting.value(group + name, defval).toInt(); \
+ prefs.usestruct field = qPrefPrivate::instance()->setting.value(group + name, defval).toInt(); \
}
+#define DISK_LOADSYNC_INT_DEF(usegroup, name, field, defval) \
+DISK_LOADSYNC_INT_DEF_EXT(usegroup, name, field, defval, )
-#define DISK_LOADSYNC_TXT(usegroup, name, field) \
+#define DISK_LOADSYNC_TXT_EXT(usegroup, name, field, usestruct) \
void qPref ## usegroup::disk_ ## field(bool doSync) \
{ \
if (doSync) \
- qPrefPrivate::instance()->setting.setValue(group + name, prefs.field); \
+ qPrefPrivate::instance()->setting.setValue(group + name, prefs.usestruct field); \
else \
- prefs.field = copy_qstring(qPrefPrivate::instance()->setting.value(group + name, default_prefs.field).toString()); \
+ prefs.usestruct field = copy_qstring(qPrefPrivate::instance()->setting.value(group + name, default_prefs.usestruct field).toString()); \
}
+#define DISK_LOADSYNC_TXT(usegroup, name, field) \
+DISK_LOADSYNC_TXT_EXT(usegroup, name, field, )
//******* Macros to generate set function
-#define SET_PREFERENCE_BOOL(usegroup, field) \
+#define SET_PREFERENCE_BOOL_EXT(usegroup, field, usestruct) \
void qPref ## usegroup::set_ ## field (bool value) \
{ \
- if (value != prefs.field) { \
- prefs.field = value; \
+ if (value != prefs.usestruct field) { \
+ prefs.usestruct field = value; \
disk_ ## field(true); \
emit field ## _changed(value); \
} \
}
+#define SET_PREFERENCE_BOOL(usegroup, field) \
+SET_PREFERENCE_BOOL_EXT(usegroup, field, ) \
-#define SET_PREFERENCE_DOUBLE(usegroup, field) \
+#define SET_PREFERENCE_DOUBLE_EXT(usegroup, field, usestruct) \
void qPref ## usegroup::set_ ## field (double value) \
{ \
- if (value != prefs.field) { \
- prefs.field = value; \
+ if (value != prefs.usestruct field) { \
+ prefs.usestruct field = value; \
disk_ ## field(true); \
emit field ## _changed(value); \
} \
}
+#define SET_PREFERENCE_DOUBLE(usegroup, field) \
+SET_PREFERENCE_DOUBLE_EXT(usegroup, field, ) \
-#define SET_PREFERENCE_ENUM(usegroup, type, field) \
+#define SET_PREFERENCE_ENUM_EXT(usegroup, type, field, usestruct) \
void qPref ## usegroup::set_ ## field (type value) \
{ \
- if (value != prefs.field) { \
- prefs.field = value; \
+ if (value != prefs.usestruct field) { \
+ prefs.usestruct field = value; \
disk_ ## field(true); \
emit field ## _changed(value); \
} \
}
+#define SET_PREFERENCE_ENUM(usegroup, type, field) \
+SET_PREFERENCE_ENUM_EXT(usegroup, type, field, )
-#define SET_PREFERENCE_INT(usegroup, field) \
+#define SET_PREFERENCE_INT_EXT(usegroup, field, usestruct) \
void qPref ## usegroup::set_ ## field (int value) \
{ \
- if (value != prefs.field) { \
- prefs.field = value; \
+ if (value != prefs.usestruct field) { \
+ prefs.usestruct field = value; \
disk_ ## field(true); \
emit field ## _changed(value); \
} \
}
+#define SET_PREFERENCE_INT(usegroup, field) \
+SET_PREFERENCE_INT_EXT(usegroup, field, ) \
-#define SET_PREFERENCE_TXT(usegroup, field) \
+#define SET_PREFERENCE_TXT_EXT(usegroup, field, usestruct) \
void qPref ## usegroup::set_ ## field (const QString& value) \
{ \
- if (value != prefs.field) { \
- qPrefPrivate::instance()->copy_txt(&prefs.field, value); \
+ if (value != prefs.usestruct field) { \
+ qPrefPrivate::instance()->copy_txt(&prefs.usestruct field, value); \
disk_ ## field(true); \
emit field ## _changed(value); \
} \
}
+#define SET_PREFERENCE_TXT(usegroup, field) \
+SET_PREFERENCE_TXT_EXT(usegroup, field, ) \
//******* Macros to generate set/set/loadsync combined
+#define HANDLE_PREFERENCE_BOOL_EXT(usegroup, name, field, usestruct) \
+SET_PREFERENCE_BOOL_EXT(usegroup, field, usestruct); \
+DISK_LOADSYNC_BOOL_EXT(usegroup, name, field, usestruct);
#define HANDLE_PREFERENCE_BOOL(usegroup, name, field) \
-SET_PREFERENCE_BOOL(usegroup, field); \
-DISK_LOADSYNC_BOOL(usegroup, name, field);
+HANDLE_PREFERENCE_BOOL_EXT(usegroup, name, field, )
+#define HANDLE_PREFERENCE_DOUBLE_EXT(usegroup, name, field, usestruct) \
+SET_PREFERENCE_DOUBLE_EXT(usegroup, field, usestruct); \
+DISK_LOADSYNC_DOUBLE_EXT(usegroup, name, field, usestruct);
#define HANDLE_PREFERENCE_DOUBLE(usegroup, name, field) \
-SET_PREFERENCE_DOUBLE(usegroup, field); \
-DISK_LOADSYNC_DOUBLE(usegroup, name, field);
+HANDLE_PREFERENCE_DOUBLE_EXT(usegroup, name, field, )
+#define HANDLE_PREFERENCE_ENUM_EXT(usegroup, type, name, field, usestruct) \
+SET_PREFERENCE_ENUM_EXT(usegroup, type, field, usestruct); \
+DISK_LOADSYNC_ENUM_EXT(usegroup, name, type, field, usestruct);
#define HANDLE_PREFERENCE_ENUM(usegroup, type, name, field) \
-SET_PREFERENCE_ENUM(usegroup, type, field); \
-DISK_LOADSYNC_ENUM(usegroup, name, type, field);
+HANDLE_PREFERENCE_ENUM_EXT(usegroup, type, name, field, )
+#define HANDLE_PREFERENCE_INT_EXT(usegroup, name, field, usestruct) \
+SET_PREFERENCE_INT_EXT(usegroup, field, usestruct); \
+DISK_LOADSYNC_INT_EXT(usegroup, name, field, usestruct);
#define HANDLE_PREFERENCE_INT(usegroup, name, field) \
-SET_PREFERENCE_INT(usegroup, field); \
-DISK_LOADSYNC_INT(usegroup, name, field);
+HANDLE_PREFERENCE_INT_EXT(usegroup, name, field, )
+#define HANDLE_PREFERENCE_TXT_EXT(usegroup, name, field, usestruct) \
+SET_PREFERENCE_TXT_EXT(usegroup, field, usestruct); \
+DISK_LOADSYNC_TXT_EXT(usegroup, name, field, usestruct);
#define HANDLE_PREFERENCE_TXT(usegroup, name, field) \
-SET_PREFERENCE_TXT(usegroup, field); \
-DISK_LOADSYNC_TXT(usegroup, name, field);
+HANDLE_PREFERENCE_TXT_EXT(usegroup, name, field, )
#endif