diff options
author | jan Iversen <jani@apache.org> | 2018-06-30 11:23:33 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-07-07 09:44:06 -0700 |
commit | ce358fdb68f00291abae28fc717506cd13a40f11 (patch) | |
tree | 1fb91641db5781397a4b372645aa684141e9683c /core/settings/qPref_private.h | |
parent | e5dace2233fd2007ce81d0d926d411641c519fb2 (diff) | |
download | subsurface-ce358fdb68f00291abae28fc717506cd13a40f11.tar.gz |
core: qPref private add macros to replace disk* functions
Use a private QSettings variable, instead of declaring it each time
Add macros to handle full disk* functions
Signed-off-by: Jan Iversen <jani@apache.org>
Diffstat (limited to 'core/settings/qPref_private.h')
-rw-r--r-- | core/settings/qPref_private.h | 82 |
1 files changed, 57 insertions, 25 deletions
diff --git a/core/settings/qPref_private.h b/core/settings/qPref_private.h index 96a3b1e5e..e2e8f350c 100644 --- a/core/settings/qPref_private.h +++ b/core/settings/qPref_private.h @@ -4,69 +4,101 @@ // Header used by all qPref<class> implementations to avoid duplicating code -#include <QObject> #include <QSettings> #include <QVariant> +#include <QObject> #include "core/qthelper.h" +//****** Macros to be used in the set functions ****** #define COPY_TXT(name, string) \ { \ free((void *)prefs.name); \ prefs.name = copy_qstring(string); \ } -#define LOADSYNC_INT(name, field) \ +//****** Macros to be used in the disk functions, which are special ****** +#define LOADSYNC_BOOL(name, field) \ { \ - QSettings s; \ - if (doSync) \ - s.setValue(group + name, prefs.field); \ + if (doSync) \ + setting.setValue(group + name, prefs.field); \ else \ - prefs.field = s.value(group + name, default_prefs.field).toInt(); \ + prefs.field = setting.value(group + name, default_prefs.field).toBool(); \ } -#define LOADSYNC_INT_DEF(name, field, defval) \ +#define LOADSYNC_DOUBLE(name, field) \ { \ - QSettings s; \ if (doSync) \ - s.setValue(group + name, prefs.field); \ + setting.setValue(group + name, prefs.field); \ else \ - prefs.field = s.value(group + name, defval).toInt(); \ + prefs.field = setting.value(group + name, default_prefs.field).toDouble(); \ } #define LOADSYNC_ENUM(name, type, field) \ { \ - QSettings s; \ if (doSync) \ - s.setValue(group + name, prefs.field); \ + setting.setValue(group + name, prefs.field); \ else \ - prefs.field = (enum type)s.value(group + name, default_prefs.field).toInt(); \ + prefs.field = (enum type)setting.value(group + name, default_prefs.field).toInt(); \ } -#define LOADSYNC_BOOL(name, field) \ +#define LOADSYNC_INT(name, field) \ { \ - QSettings s; \ - if (doSync) \ - s.setValue(group + name, prefs.field); \ + if (doSync) \ + setting.setValue(group + name, prefs.field); \ else \ - prefs.field = s.value(group + name, default_prefs.field).toBool(); \ + prefs.field = setting.value(group + name, default_prefs.field).toInt(); \ } -#define LOADSYNC_DOUBLE(name, field) \ +#define LOADSYNC_INT_DEF(name, field, defval) \ { \ - QSettings s; \ if (doSync) \ - s.setValue(group + name, prefs.field); \ + setting.setValue(group + name, prefs.field); \ else \ - prefs.field = s.value(group + name, default_prefs.field).toDouble(); \ + prefs.field = setting.value(group + name, defval).toInt(); \ } #define LOADSYNC_TXT(name, field) \ { \ - QSettings s; \ if (doSync) \ - s.setValue(group + name, prefs.field); \ + setting.setValue(group + name, prefs.field); \ else \ - prefs.field = copy_qstring(s.value(group + name, default_prefs.field).toString()); \ + prefs.field = copy_qstring(setting.value(group + name, default_prefs.field).toString()); \ } +//******* Macros to generate disk function +#define DISK_LOADSYNC_BOOL(class, name, field) \ +void qPref ## class::disk_ ## field(bool doSync) \ +{ \ + LOADSYNC_BOOL(name, field); \ +} + +#define DISK_LOADSYNC_DOUBLE(class, name, field) \ +void qPref ## class::disk_ ## field(bool doSync) \ +{ \ + LOADSYNC_DOUBLE(name, field); \ +} + +#define DISK_LOADSYNC_ENUM(class, name, type, field) \ +void qPref ## class::disk_ ## field(bool doSync) \ +{ \ + LOADSYNC_ENUM(name, type, field); \ +} + +#define DISK_LOADSYNC_INT(class, name, field) \ +void qPref ## class::disk_ ## field(bool doSync) \ +{ \ + LOADSYNC_DOUBLE(name, field); \ +} + +#define DISK_LOADSYNC_INT_DEF(class, name, field, defval) \ +void qPref ## class::disk_ ## field(bool doSync) \ +{ \ + LOADSYNC_INT_DEF(name, field, defval); \ +} + +#define DISK_LOADSYNC_TXT(class, name, field) \ +void qPref ## class::disk_ ## field(bool doSync) \ +{ \ + LOADSYNC_TXT(name, field); \ +} #endif |