From ee6b5643b5581ec3fda3873543f9275235ae0598 Mon Sep 17 00:00:00 2001 From: jan Iversen Date: Fri, 7 Sep 2018 11:13:12 -0700 Subject: 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 Signed-off-by: Dirk Hohndel --- core/settings/qPrefPrivate.h | 84 +++++++++++++++++++++++++++++++++----------- 1 file changed, 63 insertions(+), 21 deletions(-) (limited to 'core') 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, ) -- cgit v1.2.3-70-g09d2