From da61c1714f24d42f5295bcd60d704e65f503b174 Mon Sep 17 00:00:00 2001 From: jan Iversen Date: Wed, 4 Jul 2018 21:45:48 +0200 Subject: core: activate qPrefDisplay in SettingsObjectWrapper add the prepared class qPrefDisplay to SettingsObjectWrapper and thereby making it active. As a consequence of the uniform naming standard desktop-widgets/preferences_defaults.cpp and tests/testpreferences.cpp have been updated. Signed-off-by: Jan Iversen --- core/subsurface-qt/SettingsObjectWrapper.cpp | 71 +--------------------------- 1 file changed, 1 insertion(+), 70 deletions(-) (limited to 'core/subsurface-qt/SettingsObjectWrapper.cpp') diff --git a/core/subsurface-qt/SettingsObjectWrapper.cpp b/core/subsurface-qt/SettingsObjectWrapper.cpp index 80b9df8ee..416c645b6 100644 --- a/core/subsurface-qt/SettingsObjectWrapper.cpp +++ b/core/subsurface-qt/SettingsObjectWrapper.cpp @@ -1913,75 +1913,6 @@ void GeneralSettingsObjectWrapper::setAutoRecalculateThumbnails(bool value) emit autoRecalculateThumbnailsChanged(value); } -DisplaySettingsObjectWrapper::DisplaySettingsObjectWrapper(QObject *parent) : - QObject(parent) -{ -} - -QString DisplaySettingsObjectWrapper::divelistFont() const -{ - return prefs.divelist_font; -} - -double DisplaySettingsObjectWrapper::fontSize() const -{ - return prefs.font_size; -} - -bool DisplaySettingsObjectWrapper::displayInvalidDives() const -{ - return prefs.display_invalid_dives; -} - -void DisplaySettingsObjectWrapper::setDivelistFont(const QString& value) -{ - - QString newValue = value; - if (value.contains(",")) - newValue = value.left(value.indexOf(",")); - - if (newValue == prefs.divelist_font) - return; - - QSettings s; - s.beginGroup(group); - s.setValue("divelist_font", value); - - if (!subsurface_ignore_font(qPrintable(newValue))) { - free((void *)prefs.divelist_font); - prefs.divelist_font = copy_qstring(newValue); - qApp->setFont(QFont(newValue)); - } - emit divelistFontChanged(newValue); -} - -void DisplaySettingsObjectWrapper::setFontSize(double value) -{ - if (value == prefs.font_size) - return; - - QSettings s; - s.beginGroup(group); - s.setValue("font_size", value); - prefs.font_size = value; - QFont defaultFont = qApp->font(); - defaultFont.setPointSizeF(prefs.font_size); - qApp->setFont(defaultFont); - emit fontSizeChanged(value); -} - -void DisplaySettingsObjectWrapper::setDisplayInvalidDives(bool value) -{ - if (value == prefs.display_invalid_dives) - return; - - QSettings s; - s.beginGroup(group); - s.setValue("displayinvalid", value); - prefs.display_invalid_dives = value; - emit displayInvalidDivesChanged(value); -} - LanguageSettingsObjectWrapper::LanguageSettingsObjectWrapper(QObject *parent) : QObject(parent) { @@ -2194,7 +2125,7 @@ QObject(parent), planner_settings(new DivePlannerSettings(this)), unit_settings(new UnitsSettings(this)), general_settings(new GeneralSettingsObjectWrapper(this)), - display_settings(new DisplaySettingsObjectWrapper(this)), + display_settings(new qPrefDisplay(this)), language_settings(new LanguageSettingsObjectWrapper(this)), animation_settings(new AnimationsSettingsObjectWrapper(this)), location_settings(new LocationServiceSettingsObjectWrapper(this)), -- cgit v1.2.3-70-g09d2 From 9732194bf8e018d93fc3b0244992b23d2cdd2859 Mon Sep 17 00:00:00 2001 From: jan Iversen Date: Wed, 4 Jul 2018 22:39:53 +0200 Subject: core: sync display variables from struct preferences when ssrf terminates Add qPrefDisplay sync to sync in SettingsObjectWrapper. If a program part change display variables in struct preferences, they would not be saved on disk. Signed-off-by: Jan Iversen --- core/subsurface-qt/SettingsObjectWrapper.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'core/subsurface-qt/SettingsObjectWrapper.cpp') diff --git a/core/subsurface-qt/SettingsObjectWrapper.cpp b/core/subsurface-qt/SettingsObjectWrapper.cpp index 416c645b6..57c3de8c7 100644 --- a/core/subsurface-qt/SettingsObjectWrapper.cpp +++ b/core/subsurface-qt/SettingsObjectWrapper.cpp @@ -2351,6 +2351,8 @@ void SettingsObjectWrapper::load() void SettingsObjectWrapper::sync() { + qPrefDisplay::instance()->sync(); + QSettings s; s.beginGroup("Planner"); s.setValue("last_stop", prefs.last_stop); -- cgit v1.2.3-70-g09d2 From 928fc1ee79a4391384f448cb75369ddb5e03ef28 Mon Sep 17 00:00:00 2001 From: jan Iversen Date: Wed, 4 Jul 2018 22:46:59 +0200 Subject: core: move load of display variables to qPrefDisplay from SettingsObjectWrapper ensure SettingsObjectWrapper load() loads all display variables. Copy font setting code from SettingsObjectWrapper to qPrefDisplay Signed-off-by: Jan Iversen --- core/settings/qPref.h | 4 ++-- core/settings/qPrefDisplay.cpp | 36 ++++++++++++++++++++++++++-- core/settings/qPrefDisplay.h | 7 ++++-- core/subsurface-qt/SettingsObjectWrapper.cpp | 24 +------------------ 4 files changed, 42 insertions(+), 29 deletions(-) (limited to 'core/subsurface-qt/SettingsObjectWrapper.cpp') diff --git a/core/settings/qPref.h b/core/settings/qPref.h index 425484726..70eef3cb3 100644 --- a/core/settings/qPref.h +++ b/core/settings/qPref.h @@ -20,8 +20,8 @@ public: // Load/Sync local settings (disk) and struct preference void loadSync(bool doSync); - void load() { loadSync(false); }; - void sync() { loadSync(true); }; + void load() { loadSync(false); } + void sync() { loadSync(true); } public: enum cloud_status { diff --git a/core/settings/qPrefDisplay.cpp b/core/settings/qPrefDisplay.cpp index cf0a4e54d..fee960f97 100644 --- a/core/settings/qPrefDisplay.cpp +++ b/core/settings/qPrefDisplay.cpp @@ -39,7 +39,12 @@ void qPrefDisplay::set_divelist_font(const QString& value) emit divelist_font_changed(value); } } -DISK_LOADSYNC_TXT(Display, "/divelist_font", divelist_font); +void qPrefDisplay::disk_divelist_font(bool doSync) +{ + LOADSYNC_TXT("/divelist_font", divelist_font); + if (!doSync) + setCorrectFont(); +} GET_PREFERENCE_DOUBLE(Display, font_size); void qPrefDisplay::set_font_size(double value) @@ -53,10 +58,37 @@ void qPrefDisplay::set_font_size(double value) emit font_size_changed(value); } } -DISK_LOADSYNC_DOUBLE(Display, "/font_size", font_size); +void qPrefDisplay::disk_font_size(bool doSync) +{ + LOADSYNC_DOUBLE("/font_size", font_size); + if (!doSync) + setCorrectFont(); +} HANDLE_PREFERENCE_BOOL(Display, "/displayinvalid", display_invalid_dives); HANDLE_PREFERENCE_BOOL(Display, "/show_developer", show_developer); HANDLE_PREFERENCE_TXT(Display, "/theme", theme); + + +void qPrefDisplay::setCorrectFont() +{ + // get the font from the settings or our defaults + // respect the system default font size if none is explicitly set + QFont defaultFont(prefs.divelist_font); + if (IS_FP_SAME(system_divelist_default_font_size, -1.0)) { + prefs.font_size = qApp->font().pointSizeF(); + system_divelist_default_font_size = prefs.font_size; // this way we don't save it on exit + } + // painful effort to ignore previous default fonts on Windows - ridiculous + QString fontName = defaultFont.toString(); + if (fontName.contains(",")) + fontName = fontName.left(fontName.indexOf(",")); + if (subsurface_ignore_font(qPrintable(fontName))) + defaultFont = QFont(prefs.divelist_font); + else + COPY_TXT(divelist_font, fontName); + defaultFont.setPointSizeF(prefs.font_size); + qApp->setFont(defaultFont); +} diff --git a/core/settings/qPrefDisplay.h b/core/settings/qPrefDisplay.h index 67930ae63..4a1c0ada5 100644 --- a/core/settings/qPrefDisplay.h +++ b/core/settings/qPrefDisplay.h @@ -19,8 +19,8 @@ public: // Load/Sync local settings (disk) and struct preference void loadSync(bool doSync); - void load() { loadSync(false); }; - void sync() { loadSync(true); }; + void load() { loadSync(false); } + void sync() { loadSync(true); } public: const QString divelist_font() const; @@ -53,5 +53,8 @@ private: void disk_display_invalid_dives(bool doSync); void disk_show_developer(bool doSync); void disk_theme(bool doSync); + + // font helper function + void setCorrectFont(); }; #endif diff --git a/core/subsurface-qt/SettingsObjectWrapper.cpp b/core/subsurface-qt/SettingsObjectWrapper.cpp index 57c3de8c7..c5a335a8e 100644 --- a/core/subsurface-qt/SettingsObjectWrapper.cpp +++ b/core/subsurface-qt/SettingsObjectWrapper.cpp @@ -2218,29 +2218,7 @@ void SettingsObjectWrapper::load() GET_BOOL("auto_recalculate_thumbnails", auto_recalculate_thumbnails); s.endGroup(); - s.beginGroup("Display"); - // get the font from the settings or our defaults - // respect the system default font size if none is explicitly set - QFont defaultFont = s.value("divelist_font", prefs.divelist_font).value(); - if (IS_FP_SAME(system_divelist_default_font_size, -1.0)) { - prefs.font_size = qApp->font().pointSizeF(); - system_divelist_default_font_size = prefs.font_size; // this way we don't save it on exit - } - prefs.font_size = s.value("font_size", prefs.font_size).toFloat(); - // painful effort to ignore previous default fonts on Windows - ridiculous - QString fontName = defaultFont.toString(); - if (fontName.contains(",")) - fontName = fontName.left(fontName.indexOf(",")); - if (subsurface_ignore_font(qPrintable(fontName))) { - defaultFont = QFont(prefs.divelist_font); - } else { - free((void *)prefs.divelist_font); - prefs.divelist_font = copy_qstring(fontName); - } - defaultFont.setPointSizeF(prefs.font_size); - qApp->setFont(defaultFont); - GET_BOOL("displayinvalid", display_invalid_dives); - s.endGroup(); + qPrefDisplay::instance()->load(); s.beginGroup("Animations"); GET_INT("animation_speed", animation_speed); -- cgit v1.2.3-70-g09d2