aboutsummaryrefslogtreecommitdiffstats
path: root/core/settings/qPrefPrivate.h
diff options
context:
space:
mode:
authorGravatar jan Iversen <jani@apache.org>2018-09-07 11:13:12 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-09-07 14:37:18 -0700
commitee6b5643b5581ec3fda3873543f9275235ae0598 (patch)
treed4f0329cc6e7bf3f851cac14b44a41ace2680c0c /core/settings/qPrefPrivate.h
parent2ecbea3d24529b9776acb620c82af04a076b817f (diff)
downloadsubsurface-ee6b5643b5581ec3fda3873543f9275235ae0598.tar.gz
core/settings: only sync values that are actually changed
Add a variable reflecting the current_state to all DISK_* macros, in order to check if the original variable in struct preferences is changed. Only save to disk if actually changed [Dirk Hohndel: merged Jan's commit and renamed the variable and adjusted the commit message... but fundamentally the commit is still what Jan wrote, so he should get the credit] Signed-off-by: Jan Iversen <jani@apache.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'core/settings/qPrefPrivate.h')
-rw-r--r--core/settings/qPrefPrivate.h84
1 files changed, 63 insertions, 21 deletions
diff --git a/core/settings/qPrefPrivate.h b/core/settings/qPrefPrivate.h
index d11e389d3..d4f60542c 100644
--- a/core/settings/qPrefPrivate.h
+++ b/core/settings/qPrefPrivate.h
@@ -29,10 +29,16 @@ extern QString keyFromGroupAndName(QString group, QString name);
#define DISK_LOADSYNC_BOOL_EXT(usegroup, name, field, usestruct) \
void qPref##usegroup::disk_##field(bool doSync) \
{ \
- if (doSync) \
- qPrefPrivate::propSetValue(keyFromGroupAndName(group, name), prefs.usestruct field, default_prefs.usestruct field); \
- else \
+ static bool current_state; \
+ if (doSync) { \
+ if (current_state != prefs.usestruct field) { \
+ current_state = prefs.usestruct field; \
+ qPrefPrivate::propSetValue(keyFromGroupAndName(group, name), prefs.usestruct field, default_prefs.usestruct field); \
+ } \
+ } else { \
prefs.usestruct field = qPrefPrivate::propValue(keyFromGroupAndName(group, name), default_prefs.usestruct field).toBool(); \
+ current_state = prefs.usestruct field; \
+ } \
}
#define DISK_LOADSYNC_BOOL(usegroup, name, field) \
DISK_LOADSYNC_BOOL_EXT(usegroup, name, field, )
@@ -40,10 +46,16 @@ extern QString keyFromGroupAndName(QString group, QString name);
#define DISK_LOADSYNC_DOUBLE_EXT(usegroup, name, field, usestruct) \
void qPref##usegroup::disk_##field(bool doSync) \
{ \
- if (doSync) \
- qPrefPrivate::propSetValue(keyFromGroupAndName(group, name), prefs.usestruct field, default_prefs.usestruct field); \
- else \
+ static double current_state; \
+ if (doSync) { \
+ if (current_state != prefs.usestruct field) { \
+ current_state = prefs.usestruct field; \
+ qPrefPrivate::propSetValue(keyFromGroupAndName(group, name), prefs.usestruct field, default_prefs.usestruct field); \
+ } \
+ } else { \
prefs.usestruct field = qPrefPrivate::propValue(keyFromGroupAndName(group, name), default_prefs.usestruct field).toDouble(); \
+ current_state = prefs.usestruct field; \
+ } \
}
#define DISK_LOADSYNC_DOUBLE(usegroup, name, field) \
DISK_LOADSYNC_DOUBLE_EXT(usegroup, name, field, )
@@ -51,10 +63,16 @@ extern QString keyFromGroupAndName(QString group, QString name);
#define DISK_LOADSYNC_ENUM_EXT(usegroup, name, type, field, usestruct) \
void qPref##usegroup::disk_##field(bool doSync) \
{ \
- if (doSync) \
- qPrefPrivate::propSetValue(keyFromGroupAndName(group, name), prefs.usestruct field, default_prefs.usestruct field); \
- else \
+ static enum type current_state; \
+ if (doSync) { \
+ if (current_state != prefs.usestruct field) { \
+ current_state = prefs.usestruct field; \
+ qPrefPrivate::propSetValue(keyFromGroupAndName(group, name), prefs.usestruct field, default_prefs.usestruct field); \
+ } \
+ } else { \
prefs.usestruct field = (enum type)qPrefPrivate::propValue(keyFromGroupAndName(group, name), default_prefs.usestruct field).toInt(); \
+ current_state = prefs.usestruct field; \
+ } \
}
#define DISK_LOADSYNC_ENUM(usegroup, name, type, field) \
DISK_LOADSYNC_ENUM_EXT(usegroup, name, type, field, )
@@ -62,10 +80,16 @@ extern QString keyFromGroupAndName(QString group, QString name);
#define DISK_LOADSYNC_INT_EXT(usegroup, name, field, usestruct) \
void qPref##usegroup::disk_##field(bool doSync) \
{ \
- if (doSync) \
- qPrefPrivate::propSetValue(keyFromGroupAndName(group, name), prefs.usestruct field, default_prefs.usestruct field); \
- else \
+ static int current_state; \
+ if (doSync) { \
+ if (current_state != prefs.usestruct field) { \
+ current_state = prefs.usestruct field; \
+ qPrefPrivate::propSetValue(keyFromGroupAndName(group, name), prefs.usestruct field, default_prefs.usestruct field); \
+ } \
+ } else { \
prefs.usestruct field = qPrefPrivate::propValue(keyFromGroupAndName(group, name), default_prefs.usestruct field).toInt(); \
+ current_state = prefs.usestruct field; \
+ } \
}
#define DISK_LOADSYNC_INT(usegroup, name, field) \
DISK_LOADSYNC_INT_EXT(usegroup, name, field, )
@@ -73,10 +97,16 @@ extern QString keyFromGroupAndName(QString group, QString name);
#define DISK_LOADSYNC_INT_DEF_EXT(usegroup, name, field, defval, usestruct) \
void qPref##usegroup::disk_##field(bool doSync) \
{ \
- if (doSync) \
- qPrefPrivate::propSetValue(keyFromGroupAndName(group, name), prefs.usestruct field, default_prefs.usestruct field); \
- else \
+ static int current_state; \
+ if (doSync) { \
+ if (current_state != prefs.usestruct field) { \
+ current_state = prefs.usestruct field; \
+ qPrefPrivate::propSetValue(keyFromGroupAndName(group, name), prefs.usestruct field, default_prefs.usestruct field); \
+ } \
+ } else { \
prefs.usestruct field = qPrefPrivate::propValue(keyFromGroupAndName(group, name), defval).toInt(); \
+ current_state = prefs.usestruct field; \
+ } \
}
#define DISK_LOADSYNC_INT_DEF(usegroup, name, field, defval) \
DISK_LOADSYNC_INT_DEF_EXT(usegroup, name, field, defval, )
@@ -84,10 +114,16 @@ extern QString keyFromGroupAndName(QString group, QString name);
#define DISK_LOADSYNC_STRUCT_EXT(usegroup, name, field, var, usestruct) \
void qPref##usegroup::disk_##field(bool doSync) \
{ \
- if (doSync) \
- qPrefPrivate::propSetValue(keyFromGroupAndName(group, name), prefs.usestruct field . var, default_prefs.usestruct field . var); \
- else \
+ static int current_state; \
+ if (doSync) { \
+ if (current_state != prefs.usestruct field . var) { \
+ current_state = prefs.usestruct field . var; \
+ qPrefPrivate::propSetValue(keyFromGroupAndName(group, name), prefs.usestruct field . var, default_prefs.usestruct field . var); \
+ } \
+ } else { \
prefs.usestruct field . var = qPrefPrivate::propValue(keyFromGroupAndName(group, name), default_prefs.usestruct field . var).toInt(); \
+ current_state = prefs.usestruct field . var; \
+ } \
}
#define DISK_LOADSYNC_STRUCT(usegroup, name, field, var) \
DISK_LOADSYNC_STRUCT_EXT(usegroup, name, field, var, )
@@ -95,10 +131,16 @@ extern QString keyFromGroupAndName(QString group, QString name);
#define DISK_LOADSYNC_TXT_EXT(usegroup, name, field, usestruct) \
void qPref##usegroup::disk_##field(bool doSync) \
{ \
- if (doSync) \
- qPrefPrivate::propSetValue(keyFromGroupAndName(group, name), prefs.usestruct field, default_prefs.usestruct field); \
- else \
+ static QString current_state; \
+ if (doSync) { \
+ if (current_state != QString(prefs.usestruct field)) { \
+ current_state = QString(prefs.usestruct field); \
+ qPrefPrivate::propSetValue(keyFromGroupAndName(group, name), prefs.usestruct field, default_prefs.usestruct field); \
+ } \
+ } else { \
prefs.usestruct field = copy_qstring(qPrefPrivate::propValue(keyFromGroupAndName(group, name), default_prefs.usestruct field).toString()); \
+ current_state = QString(prefs.usestruct field); \
+ } \
}
#define DISK_LOADSYNC_TXT(usegroup, name, field) \
DISK_LOADSYNC_TXT_EXT(usegroup, name, field, )