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>
This commit is contained in:
Dirk Hohndel 2018-09-06 15:15:19 -07:00
parent d88f865793
commit e71b049498
7 changed files with 30 additions and 27 deletions

View file

@ -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, "");
}

View file

@ -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();
}

View file

@ -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)

View file

@ -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();
}

View file

@ -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;
if (value != defaultValue)
s.setValue(key, value);
else
s.remove(key);
}
QVariant qPrefPrivate::propValue(const QString &key, const QVariant &defaultValue)

View file

@ -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); \
} \
} \

View file

@ -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();
}