summaryrefslogtreecommitdiffstats
path: root/core/settings
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2018-09-06 15:15:19 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-09-06 16:13:44 -0700
commite71b049498eaae05f7686445be320e90ca2f630e (patch)
tree335174bac350b3f1aaf18db58addcab619bba992 /core/settings
parentd88f86579372d356a7fd33e9fadb38a76b44c757 (diff)
downloadsubsurface-e71b049498eaae05f7686445be320e90ca2f630e.tar.gz
qPref: only save settings that aren't the default
This brings us back to the previous behavior. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'core/settings')
-rw-r--r--core/settings/qPrefCloudStorage.cpp8
-rw-r--r--core/settings/qPrefDisplay.cpp4
-rw-r--r--core/settings/qPrefGeneral.cpp2
-rw-r--r--core/settings/qPrefGeocoding.cpp6
-rw-r--r--core/settings/qPrefPrivate.cpp7
-rw-r--r--core/settings/qPrefPrivate.h28
-rw-r--r--core/settings/qPrefUpdateManager.cpp2
7 files changed, 30 insertions, 27 deletions
diff --git a/core/settings/qPrefCloudStorage.cpp b/core/settings/qPrefCloudStorage.cpp
index 9392a24c0..dc12ad633 100644
--- a/core/settings/qPrefCloudStorage.cpp
+++ b/core/settings/qPrefCloudStorage.cpp
@@ -45,7 +45,7 @@ void qPrefCloudStorage::set_cloud_base_url(const QString &value)
void qPrefCloudStorage::disk_cloud_base_url(bool doSync)
{
if (doSync) {
- qPrefPrivate::propSetValue(group + "/cloud_base_url", prefs.cloud_base_url);
+ qPrefPrivate::propSetValue(group + "/cloud_base_url", prefs.cloud_base_url, default_prefs.cloud_base_url);
} else {
prefs.cloud_base_url = copy_qstring(qPrefPrivate::propValue(group + "/cloud_base_url", default_prefs.cloud_base_url).toString());
qPrefPrivate::copy_txt(&prefs.cloud_git_url, QString(prefs.cloud_base_url) + "/git");
@@ -79,7 +79,7 @@ void qPrefCloudStorage::disk_cloud_storage_password(bool doSync)
{
if (doSync) {
if (prefs.save_password_local)
- qPrefPrivate::propSetValue(group + "/password", prefs.cloud_storage_password);
+ qPrefPrivate::propSetValue(group + "/password", prefs.cloud_storage_password, default_prefs.cloud_storage_password);
} else {
prefs.cloud_storage_password = copy_qstring(qPrefPrivate::propValue(group + "/password", default_prefs.cloud_storage_password).toString());
}
@@ -102,7 +102,7 @@ void qPrefCloudStorage::disk_userid(bool doSync)
{
if (doSync) {
// always save in new position (part of cloud storage group)
- qPrefPrivate::propSetValue(group + "subsurface_webservice_uid", prefs.userid);
+ qPrefPrivate::propSetValue(group + "subsurface_webservice_uid", prefs.userid, default_prefs.userid);
} else {
//WARNING: UserId was stored outside of any group.
// try to read from new location, if it fails read from old location
@@ -120,5 +120,5 @@ bool qPrefCloudStorage::loadFromCloud(const QString& email)
}
void qPrefCloudStorage::set_loadFromCloud(const QString& email, bool done)
{
- qPrefPrivate::propSetValue(QString("loadFromCloud") + email, done);
+ qPrefPrivate::propSetValue(QString("loadFromCloud") + email, done, "");
}
diff --git a/core/settings/qPrefDisplay.cpp b/core/settings/qPrefDisplay.cpp
index ecfd5e70b..ef4d8e1b8 100644
--- a/core/settings/qPrefDisplay.cpp
+++ b/core/settings/qPrefDisplay.cpp
@@ -90,7 +90,7 @@ void qPrefDisplay::set_divelist_font(const QString &value)
void qPrefDisplay::disk_divelist_font(bool doSync)
{
if (doSync)
- qPrefPrivate::propSetValue(group + "/divelist_font", prefs.divelist_font);
+ qPrefPrivate::propSetValue(group + "/divelist_font", prefs.divelist_font, default_prefs.divelist_font);
else
setCorrectFont();
}
@@ -110,7 +110,7 @@ void qPrefDisplay::set_font_size(double value)
void qPrefDisplay::disk_font_size(bool doSync)
{
if (doSync)
- qPrefPrivate::propSetValue(group + "/font_size", prefs.font_size);
+ qPrefPrivate::propSetValue(group + "/font_size", prefs.font_size, default_prefs.font_size);
else
setCorrectFont();
}
diff --git a/core/settings/qPrefGeneral.cpp b/core/settings/qPrefGeneral.cpp
index 8dfe67668..67df7b3fb 100644
--- a/core/settings/qPrefGeneral.cpp
+++ b/core/settings/qPrefGeneral.cpp
@@ -67,7 +67,7 @@ void qPrefGeneral::set_default_file_behavior(enum def_file_behavior value)
void qPrefGeneral::disk_default_file_behavior(bool doSync)
{
if (doSync) {
- qPrefPrivate::propSetValue(group + "/default_file_behavior", prefs.default_file_behavior);
+ qPrefPrivate::propSetValue(group + "/default_file_behavior", prefs.default_file_behavior, default_prefs.default_file_behavior);
} else {
prefs.default_file_behavior = (enum def_file_behavior)qPrefPrivate::propValue(group + "/default_file_behavior", default_prefs.default_file_behavior).toInt();
if (prefs.default_file_behavior == UNDEFINED_DEFAULT_FILE)
diff --git a/core/settings/qPrefGeocoding.cpp b/core/settings/qPrefGeocoding.cpp
index 7bb043e0f..02b8b154a 100644
--- a/core/settings/qPrefGeocoding.cpp
+++ b/core/settings/qPrefGeocoding.cpp
@@ -32,7 +32,7 @@ void qPrefGeocoding::set_first_taxonomy_category(taxonomy_category value)
void qPrefGeocoding::disk_first_taxonomy_category(bool doSync)
{
if (doSync)
- qPrefPrivate::propSetValue(group + "/cat0", prefs.geocoding.category[0]);
+ qPrefPrivate::propSetValue(group + "/cat0", prefs.geocoding.category[0], default_prefs.geocoding.category[0]);
else
prefs.geocoding.category[0] = (enum taxonomy_category)qPrefPrivate::propValue(group + "/cat0", default_prefs.geocoding.category[0]).toInt();
}
@@ -49,7 +49,7 @@ void qPrefGeocoding::set_second_taxonomy_category(taxonomy_category value)
void qPrefGeocoding::disk_second_taxonomy_category(bool doSync)
{
if (doSync)
- qPrefPrivate::propSetValue(group + "/cat1", prefs.geocoding.category[1]);
+ qPrefPrivate::propSetValue(group + "/cat1", prefs.geocoding.category[1], default_prefs.geocoding.category[1]);
else
prefs.geocoding.category[1] = (enum taxonomy_category)qPrefPrivate::propValue(group + "/cat1", default_prefs.geocoding.category[1]).toInt();
}
@@ -66,7 +66,7 @@ void qPrefGeocoding::set_third_taxonomy_category(taxonomy_category value)
void qPrefGeocoding::disk_third_taxonomy_category(bool doSync)
{
if (doSync)
- qPrefPrivate::propSetValue(group + "/cat2", prefs.geocoding.category[2]);
+ qPrefPrivate::propSetValue(group + "/cat2", prefs.geocoding.category[2], default_prefs.geocoding.category[2]);
else
prefs.geocoding.category[2] = (enum taxonomy_category)qPrefPrivate::propValue(group + "/cat2", default_prefs.geocoding.category[2]).toInt();
}
diff --git a/core/settings/qPrefPrivate.cpp b/core/settings/qPrefPrivate.cpp
index ff335a94f..6e835b92f 100644
--- a/core/settings/qPrefPrivate.cpp
+++ b/core/settings/qPrefPrivate.cpp
@@ -9,14 +9,17 @@ void qPrefPrivate::copy_txt(const char **name, const QString &string)
*name = copy_qstring(string);
}
-void qPrefPrivate::propSetValue(const QString &key, const QVariant &value)
+void qPrefPrivate::propSetValue(const QString &key, const QVariant &value, const QVariant &defaultValue)
{
// REMARK: making s static (which would be logical) does NOT work
// because it gets initialized too early.
// Having it as a local variable is light weight, because it is an
// interface class.
QSettings s;
- s.setValue(key, value);
+ if (value != defaultValue)
+ s.setValue(key, value);
+ else
+ s.remove(key);
}
QVariant qPrefPrivate::propValue(const QString &key, const QVariant &defaultValue)
diff --git a/core/settings/qPrefPrivate.h b/core/settings/qPrefPrivate.h
index e3376a3a2..a4622e29e 100644
--- a/core/settings/qPrefPrivate.h
+++ b/core/settings/qPrefPrivate.h
@@ -15,7 +15,7 @@ public:
// Helper functions
static void copy_txt(const char **name, const QString &string);
- static void propSetValue(const QString &key, const QVariant &value);
+ static void propSetValue(const QString &key, const QVariant &value, const QVariant &defaultValue);
static QVariant propValue(const QString &key, const QVariant &defaultValue);
private:
@@ -28,7 +28,7 @@ private:
void qPref##usegroup::disk_##field(bool doSync) \
{ \
if (doSync) \
- qPrefPrivate::propSetValue(group + name, prefs.usestruct field); \
+ qPrefPrivate::propSetValue(group + name, prefs.usestruct field, default_prefs.usestruct field); \
else \
prefs.usestruct field = qPrefPrivate::propValue(group + name, default_prefs.usestruct field).toBool(); \
}
@@ -39,7 +39,7 @@ private:
void qPref##usegroup::disk_##field(bool doSync) \
{ \
if (doSync) \
- qPrefPrivate::propSetValue(group + name, prefs.usestruct field); \
+ qPrefPrivate::propSetValue(group + name, prefs.usestruct field, default_prefs.usestruct field); \
else \
prefs.usestruct field = qPrefPrivate::propValue(group + name, default_prefs.usestruct field).toDouble(); \
}
@@ -50,7 +50,7 @@ private:
void qPref##usegroup::disk_##field(bool doSync) \
{ \
if (doSync) \
- qPrefPrivate::propSetValue(group + name, prefs.usestruct field); \
+ qPrefPrivate::propSetValue(group + name, prefs.usestruct field, default_prefs.usestruct field); \
else \
prefs.usestruct field = (enum type)qPrefPrivate::propValue(group + name, default_prefs.usestruct field).toInt(); \
}
@@ -61,7 +61,7 @@ private:
void qPref##usegroup::disk_##field(bool doSync) \
{ \
if (doSync) \
- qPrefPrivate::propSetValue(group + name, prefs.usestruct field); \
+ qPrefPrivate::propSetValue(group + name, prefs.usestruct field, default_prefs.usestruct field); \
else \
prefs.usestruct field = qPrefPrivate::propValue(group + name, default_prefs.usestruct field).toInt(); \
}
@@ -72,7 +72,7 @@ private:
void qPref##usegroup::disk_##field(bool doSync) \
{ \
if (doSync) \
- qPrefPrivate::propSetValue(group + name, prefs.usestruct field); \
+ qPrefPrivate::propSetValue(group + name, prefs.usestruct field, default_prefs.usestruct field); \
else \
prefs.usestruct field = qPrefPrivate::propValue(group + name, defval).toInt(); \
}
@@ -83,7 +83,7 @@ private:
void qPref##usegroup::disk_##field(bool doSync) \
{ \
if (doSync) \
- qPrefPrivate::propSetValue(group + name, prefs.usestruct field . var); \
+ qPrefPrivate::propSetValue(group + name, prefs.usestruct field . var, default_prefs.usestruct field . var); \
else \
prefs.usestruct field . var = qPrefPrivate::propValue(group + name, default_prefs.usestruct field . var).toInt(); \
}
@@ -94,7 +94,7 @@ private:
void qPref##usegroup::disk_##field(bool doSync) \
{ \
if (doSync) \
- qPrefPrivate::propSetValue(group + name, prefs.usestruct field); \
+ qPrefPrivate::propSetValue(group + name, prefs.usestruct field, default_prefs.usestruct field); \
else \
prefs.usestruct field = copy_qstring(qPrefPrivate::propValue(group + name, default_prefs.usestruct field).toString()); \
}
@@ -222,7 +222,7 @@ private:
{ \
if (value != st_##field) { \
st_##field = value; \
- qPrefPrivate::propSetValue(name, st_##field); \
+ qPrefPrivate::propSetValue(name, st_##field, QPointF()); \
emit qPref##useclass::instance()->field##_changed(value); \
} \
} \
@@ -236,7 +236,7 @@ private:
{ \
if (value != st_##field) { \
st_##field = value; \
- qPrefPrivate::propSetValue(name, st_##field); \
+ qPrefPrivate::propSetValue(name, st_##field, ""); \
emit qPref##useclass::instance()->field##_changed(value); \
} \
} \
@@ -250,7 +250,7 @@ private:
{ \
if (value != st_##field) { \
st_##field = value; \
- qPrefPrivate::propSetValue(name, st_##field); \
+ qPrefPrivate::propSetValue(name, st_##field, false); \
emit qPref##useclass::instance()->field##_changed(value); \
} \
} \
@@ -264,7 +264,7 @@ private:
{ \
if (value != st_##field) { \
st_##field = value; \
- qPrefPrivate::propSetValue(name, st_##field); \
+ qPrefPrivate::propSetValue(name, st_##field, 0.0); \
emit qPref##useclass::instance()->field##_changed(value); \
} \
} \
@@ -278,7 +278,7 @@ private:
{ \
if (value != st_##field) { \
st_##field = value; \
- qPrefPrivate::propSetValue(name, st_##field); \
+ qPrefPrivate::propSetValue(name, st_##field, 0); \
emit qPref##useclass::instance()->field##_changed(value); \
} \
} \
@@ -292,7 +292,7 @@ private:
{ \
if (value != st_##field) { \
st_##field = value; \
- qPrefPrivate::propSetValue(name, st_##field); \
+ qPrefPrivate::propSetValue(name, st_##field, QByteArray()); \
emit qPref##useclass::instance()->field##_changed(value); \
} \
} \
diff --git a/core/settings/qPrefUpdateManager.cpp b/core/settings/qPrefUpdateManager.cpp
index 4623c8a52..15ede6c5d 100644
--- a/core/settings/qPrefUpdateManager.cpp
+++ b/core/settings/qPrefUpdateManager.cpp
@@ -57,7 +57,7 @@ void qPrefUpdateManager::set_next_check(const QDate& value)
void qPrefUpdateManager::disk_next_check(bool doSync)
{
if (doSync)
- qPrefPrivate::propSetValue(group + "/NextCheck", prefs.update_manager.next_check);
+ qPrefPrivate::propSetValue(group + "/NextCheck", prefs.update_manager.next_check, default_prefs.update_manager.next_check);
else
prefs.update_manager.next_check = qPrefPrivate::propValue(group + "/NextCheck", 0).toInt();
}