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/settings/qPref.cpp | 1 + core/settings/qPref.h | 2 + core/settings/qPrefDisplay.h | 2 + core/subsurface-qt/SettingsObjectWrapper.cpp | 71 +--------------------- core/subsurface-qt/SettingsObjectWrapper.h | 27 +------- .../preferences/preferences_defaults.cpp | 8 +-- tests/testpreferences.cpp | 32 +++++----- 7 files changed, 29 insertions(+), 114 deletions(-) diff --git a/core/settings/qPref.cpp b/core/settings/qPref.cpp index 189fad499..027d4af5a 100644 --- a/core/settings/qPref.cpp +++ b/core/settings/qPref.cpp @@ -15,6 +15,7 @@ static qPref *self = new qPref; void qPref::loadSync(bool doSync) { + qPrefDisplay::instance()->loadSync(doSync); } const QString qPref::canonical_version() const diff --git a/core/settings/qPref.h b/core/settings/qPref.h index e0e21ad6e..425484726 100644 --- a/core/settings/qPref.h +++ b/core/settings/qPref.h @@ -20,6 +20,8 @@ public: // Load/Sync local settings (disk) and struct preference void loadSync(bool doSync); + void load() { loadSync(false); }; + void sync() { loadSync(true); }; public: enum cloud_status { diff --git a/core/settings/qPrefDisplay.h b/core/settings/qPrefDisplay.h index 6448e0115..67930ae63 100644 --- a/core/settings/qPrefDisplay.h +++ b/core/settings/qPrefDisplay.h @@ -19,6 +19,8 @@ public: // Load/Sync local settings (disk) and struct preference void loadSync(bool doSync); + void load() { loadSync(false); }; + void sync() { loadSync(true); }; public: const QString divelist_font() const; 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)), diff --git a/core/subsurface-qt/SettingsObjectWrapper.h b/core/subsurface-qt/SettingsObjectWrapper.h index 64f0621b2..a6a47a0a1 100644 --- a/core/subsurface-qt/SettingsObjectWrapper.h +++ b/core/subsurface-qt/SettingsObjectWrapper.h @@ -6,6 +6,7 @@ #include #include "core/pref.h" +#include "core/settings/qPref.h" /* Wrapper class for the Settings. This will allow * seamlessy integration of the settings with the QML @@ -594,28 +595,6 @@ private: const QString group = QStringLiteral("GeneralSettings"); }; -class DisplaySettingsObjectWrapper : public QObject { - Q_OBJECT - Q_PROPERTY(QString divelist_font READ divelistFont WRITE setDivelistFont NOTIFY divelistFontChanged) - Q_PROPERTY(double font_size READ fontSize WRITE setFontSize NOTIFY fontSizeChanged) - Q_PROPERTY(bool display_invalid_dives READ displayInvalidDives WRITE setDisplayInvalidDives NOTIFY displayInvalidDivesChanged) -public: - DisplaySettingsObjectWrapper(QObject *parent); - QString divelistFont() const; - double fontSize() const; - bool displayInvalidDives() const; -public slots: - void setDivelistFont(const QString& value); - void setFontSize(double value); - void setDisplayInvalidDives(bool value); -signals: - void divelistFontChanged(const QString& value); - void fontSizeChanged(double value); - void displayInvalidDivesChanged(bool value); -private: - const QString group = QStringLiteral("Display"); -}; - class LanguageSettingsObjectWrapper : public QObject { Q_OBJECT Q_PROPERTY(QString language READ language WRITE setLanguage NOTIFY languageChanged) @@ -709,7 +688,7 @@ class SettingsObjectWrapper : public QObject { Q_PROPERTY(UnitsSettings* units MEMBER unit_settings CONSTANT) Q_PROPERTY(GeneralSettingsObjectWrapper* general MEMBER general_settings CONSTANT) - Q_PROPERTY(DisplaySettingsObjectWrapper* display MEMBER display_settings CONSTANT) + Q_PROPERTY(qPrefDisplay* display MEMBER display_settings CONSTANT) Q_PROPERTY(LanguageSettingsObjectWrapper* language MEMBER language_settings CONSTANT) Q_PROPERTY(AnimationsSettingsObjectWrapper* animation MEMBER animation_settings CONSTANT) Q_PROPERTY(LocationServiceSettingsObjectWrapper* Location MEMBER location_settings CONSTANT) @@ -728,7 +707,7 @@ public: DivePlannerSettings *planner_settings; UnitsSettings *unit_settings; GeneralSettingsObjectWrapper *general_settings; - DisplaySettingsObjectWrapper *display_settings; + qPrefDisplay *display_settings; LanguageSettingsObjectWrapper *language_settings; AnimationsSettingsObjectWrapper *animation_settings; LocationServiceSettingsObjectWrapper *location_settings; diff --git a/desktop-widgets/preferences/preferences_defaults.cpp b/desktop-widgets/preferences/preferences_defaults.cpp index e93848f17..0df9ebde7 100644 --- a/desktop-widgets/preferences/preferences_defaults.cpp +++ b/desktop-widgets/preferences/preferences_defaults.cpp @@ -88,10 +88,10 @@ void PreferencesDefaults::syncSettings() else if (ui->cloudDefaultFile->isChecked()) general->setDefaultFileBehavior(CLOUD_DEFAULT_FILE); - auto display = SettingsObjectWrapper::instance()->display_settings; - display->setDivelistFont(ui->font->currentFont().toString()); - display->setFontSize(ui->fontsize->value()); - display->setDisplayInvalidDives(ui->displayinvalid->isChecked()); + auto display = qPrefDisplay::instance(); + display->set_divelist_font(ui->font->currentFont().toString()); + display->set_font_size(ui->fontsize->value()); + display->set_display_invalid_dives(ui->displayinvalid->isChecked()); auto animation = SettingsObjectWrapper::instance()->animation_settings; animation->setAnimationSpeed(ui->velocitySlider->value()); diff --git a/tests/testpreferences.cpp b/tests/testpreferences.cpp index 585044fd0..38c132ee5 100644 --- a/tests/testpreferences.cpp +++ b/tests/testpreferences.cpp @@ -445,22 +445,22 @@ void TestPreferences::testPreferences() TEST(general->pscrRatio(), 1); TEST(general->useDefaultFile(), false); - auto display = pref->display_settings; - display->setDivelistFont("comic"); - display->setFontSize(10.0); - display->setDisplayInvalidDives(true); - - TEST(display->divelistFont(),QStringLiteral("comic")); - TEST(display->fontSize(), 10.0); - TEST(display->displayInvalidDives(), true); - - display->setDivelistFont("helvetica"); - display->setFontSize(14.0); - display->setDisplayInvalidDives(false); - - TEST(display->divelistFont(),QStringLiteral("helvetica")); - TEST(display->fontSize(), 14.0); - TEST(display->displayInvalidDives(), false); + auto display = qPrefDisplay::instance(); + display->set_divelist_font("comic"); + display->set_font_size(10.0); + display->set_display_invalid_dives(true); + + TEST(display->divelist_font(),QStringLiteral("comic")); + TEST(display->font_size(), 10.0); + TEST(display->display_invalid_dives(), true); + + display->set_divelist_font("helvetica"); + display->set_font_size(14.0); + display->set_display_invalid_dives(false); + + TEST(display->divelist_font(),QStringLiteral("helvetica")); + TEST(display->font_size(), 14.0); + TEST(display->display_invalid_dives(), false); auto language = pref->language_settings; language->setLangLocale ("en_US"); -- 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(+) 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(-) 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 From 8f7f1cacd60f150f5d2520d3c9c47d31322fd4c1 Mon Sep 17 00:00:00 2001 From: jan Iversen Date: Thu, 5 Jul 2018 22:34:04 +0200 Subject: tests: make qprefdisplay test file Remove display tests from testpreferences and make a new file Signed-off-by: Jan Iversen --- tests/CMakeLists.txt | 2 ++ tests/testpreferences.cpp | 17 ----------------- tests/testqPrefDisplay.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ tests/testqPrefDisplay.h | 16 ++++++++++++++++ tests/testqml.cpp | 9 +++++++-- 5 files changed, 67 insertions(+), 19 deletions(-) create mode 100644 tests/testqPrefDisplay.cpp create mode 100644 tests/testqPrefDisplay.h diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 863e9dd8e..771504794 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -97,6 +97,7 @@ TEST(TestDiveSiteDuplication testdivesiteduplication.cpp) TEST(TestRenumber testrenumber.cpp) TEST(TestGitStorage testgitstorage.cpp) TEST(TestPreferences testpreferences.cpp) +TEST(TestQPrefDisplay testqPrefDisplay.cpp) TEST(TestPicture testpicture.cpp) TEST(TestMerge testmerge.cpp) TEST(TestTagList testtaglist.cpp) @@ -112,6 +113,7 @@ add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} TestGitStorage TestPlan TestDiveSiteDuplication + TestQPrefDisplay TestPreferences TestRenumber TestPicture diff --git a/tests/testpreferences.cpp b/tests/testpreferences.cpp index 38c132ee5..7a0fa64fd 100644 --- a/tests/testpreferences.cpp +++ b/tests/testpreferences.cpp @@ -445,23 +445,6 @@ void TestPreferences::testPreferences() TEST(general->pscrRatio(), 1); TEST(general->useDefaultFile(), false); - auto display = qPrefDisplay::instance(); - display->set_divelist_font("comic"); - display->set_font_size(10.0); - display->set_display_invalid_dives(true); - - TEST(display->divelist_font(),QStringLiteral("comic")); - TEST(display->font_size(), 10.0); - TEST(display->display_invalid_dives(), true); - - display->set_divelist_font("helvetica"); - display->set_font_size(14.0); - display->set_display_invalid_dives(false); - - TEST(display->divelist_font(),QStringLiteral("helvetica")); - TEST(display->font_size(), 14.0); - TEST(display->display_invalid_dives(), false); - auto language = pref->language_settings; language->setLangLocale ("en_US"); language->setLanguage ("en"); diff --git a/tests/testqPrefDisplay.cpp b/tests/testqPrefDisplay.cpp new file mode 100644 index 000000000..bfd5b5eae --- /dev/null +++ b/tests/testqPrefDisplay.cpp @@ -0,0 +1,42 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "testqPrefDisplay.h" + +#include "core/settings/qPrefDisplay.h" + +#include +#include + +#define TEST(METHOD, VALUE) \ +QCOMPARE(METHOD, VALUE); \ +display->sync(); \ +display->load(); \ +QCOMPARE(METHOD, VALUE); + +void TestQPrefDisplay::initTestCase() +{ + QCoreApplication::setOrganizationName("Subsurface"); + QCoreApplication::setOrganizationDomain("subsurface.hohndel.org"); + QCoreApplication::setApplicationName("SubsurfaceTestQPrefDisplay"); +} + +void TestQPrefDisplay::test1() +{ + auto display = qPrefDisplay::instance(); + display->set_divelist_font("comic"); + display->set_font_size(10.0); + display->set_display_invalid_dives(true); + + TEST(display->divelist_font(),QStringLiteral("comic")); + TEST(display->font_size(), 10.0); + TEST(display->display_invalid_dives(), true); + + display->set_divelist_font("helvetica"); + display->set_font_size(14.0); + display->set_display_invalid_dives(false); + + TEST(display->divelist_font(),QStringLiteral("helvetica")); + TEST(display->font_size(), 14.0); + TEST(display->display_invalid_dives(), false); +} + +QTEST_MAIN(TestQPrefDisplay) diff --git a/tests/testqPrefDisplay.h b/tests/testqPrefDisplay.h new file mode 100644 index 000000000..1885e8686 --- /dev/null +++ b/tests/testqPrefDisplay.h @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: GPL-2.0 +#ifndef TESTQPREFDISPLAY_H +#define TESTQPREFDISPLAY_H + +#include +#include + +class TestQPrefDisplay : public QObject +{ + Q_OBJECT +private slots: + void initTestCase(); + void test1(); +}; + +#endif // TESTQPREFDISPLAY_H diff --git a/tests/testqml.cpp b/tests/testqml.cpp index 8ba04da90..0b75d8d48 100644 --- a/tests/testqml.cpp +++ b/tests/testqml.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "core/settings/qPref.h" #include "core/qt-gui.h" @@ -18,8 +19,12 @@ int main(int argc, char **argv) QTEST_ADD_GPU_BLACKLIST_SUPPORT QTEST_SET_MAIN_SOURCE_PATH - // check that qPref exists - new qPref; + // check that qPref classes exists + qPref::instance(); + qPrefDisplay::instance(); + + // prepare Qt application + new QApplication(argc, argv); // check that we have a directory if (argc < 2) { -- cgit v1.2.3-70-g09d2 From 1ef3f61cc9ce312e6a8649d7946e1b06b4febc9e Mon Sep 17 00:00:00 2001 From: jan Iversen Date: Fri, 6 Jul 2018 15:10:22 +0200 Subject: tests: add qPrefDisplay testcases remove test macro, split in functions and add test cases the existing test macro does not work because sync() does not save these variables to disk (set* does) Signed-off-by: Jan Iversen --- tests/testqPrefDisplay.cpp | 127 ++++++++++++++++++++++++++++++++++++++------- tests/testqPrefDisplay.h | 9 ++-- 2 files changed, 115 insertions(+), 21 deletions(-) diff --git a/tests/testqPrefDisplay.cpp b/tests/testqPrefDisplay.cpp index bfd5b5eae..5d510fe21 100644 --- a/tests/testqPrefDisplay.cpp +++ b/tests/testqPrefDisplay.cpp @@ -2,16 +2,11 @@ #include "testqPrefDisplay.h" #include "core/settings/qPrefDisplay.h" +#include "core/pref.h" +#include "core/qthelper.h" -#include #include -#define TEST(METHOD, VALUE) \ -QCOMPARE(METHOD, VALUE); \ -display->sync(); \ -display->load(); \ -QCOMPARE(METHOD, VALUE); - void TestQPrefDisplay::initTestCase() { QCoreApplication::setOrganizationName("Subsurface"); @@ -19,24 +14,120 @@ void TestQPrefDisplay::initTestCase() QCoreApplication::setApplicationName("SubsurfaceTestQPrefDisplay"); } -void TestQPrefDisplay::test1() +void TestQPrefDisplay::test_struct_get() { + // Test struct pref -> get func. + auto display = qPrefDisplay::instance(); - display->set_divelist_font("comic"); - display->set_font_size(10.0); + + prefs.display_invalid_dives = true; + prefs.divelist_font = copy_qstring("comic"); + prefs.font_size = 12.0; + prefs.show_developer = false; + prefs.theme = copy_qstring("myTheme"); + + QCOMPARE(display->display_invalid_dives(), prefs.display_invalid_dives); + QCOMPARE(display->divelist_font(), QString(prefs.divelist_font)); + QCOMPARE(display->font_size(), prefs.font_size); + QCOMPARE(display->show_developer(), prefs.show_developer); + QCOMPARE(display->theme(), QString(prefs.theme)); +} + +void TestQPrefDisplay::test_set_struct() +{ + // Test set func -> struct pref + + auto display = qPrefDisplay::instance(); + display->set_display_invalid_dives(true); + display->set_divelist_font("comic"); + display->set_font_size(12.0); + display->set_show_developer(false); + display->set_theme("myTheme"); + + QCOMPARE(prefs.display_invalid_dives, true); + QCOMPARE(prefs.divelist_font, "comic"); + QCOMPARE(prefs.font_size, 12.0); + QCOMPARE(prefs.show_developer, false); + QCOMPARE(prefs.theme, "myTheme"); +} + +void TestQPrefDisplay::test_set_load_struct() +{ + // test set func -> load -> struct pref - TEST(display->divelist_font(),QStringLiteral("comic")); - TEST(display->font_size(), 10.0); - TEST(display->display_invalid_dives(), true); + auto display = qPrefDisplay::instance(); - display->set_divelist_font("helvetica"); - display->set_font_size(14.0); display->set_display_invalid_dives(false); + display->set_divelist_font("helvitica"); + display->set_font_size(15.0); + display->set_show_developer(true); + display->set_theme("myTheme2"); + + prefs.display_invalid_dives = true; + prefs.divelist_font = copy_qstring("comic"); + prefs.font_size = 12.0; + prefs.show_developer = false; + prefs.theme = copy_qstring("myTheme"); + + display->load(); + QCOMPARE(prefs.display_invalid_dives, false); + QCOMPARE(prefs.divelist_font, "helvitica"); + QCOMPARE(prefs.font_size, 15.0); + QCOMPARE(prefs.show_developer, true); + QCOMPARE(prefs.theme, "myTheme2"); +} + +void TestQPrefDisplay::test_struct_disk() +{ + // test struct prefs -> disk + + auto display = qPrefDisplay::instance(); + + prefs.display_invalid_dives = true; + prefs.divelist_font = copy_qstring("helvitica"); + prefs.font_size = 17.0; + prefs.show_developer = false; + prefs.theme = copy_qstring("myTheme3"); + + display->sync(); + prefs.display_invalid_dives = false; + prefs.divelist_font = copy_qstring("comic"); + prefs.font_size = 11.0; + prefs.show_developer = true; + prefs.theme = copy_qstring("myTheme"); + + display->load(); + QCOMPARE(prefs.display_invalid_dives, true); + QCOMPARE(prefs.divelist_font, "helvitica"); + QCOMPARE(prefs.font_size, 17.0); + QCOMPARE(prefs.show_developer, false); + QCOMPARE(prefs.theme, "myTheme3"); +} + +void TestQPrefDisplay::test_multiple() +{ + // test multiple instances have the same information + + prefs.display_invalid_dives = false; + prefs.divelist_font = copy_qstring("comic"); + prefs.font_size = 11.0; + prefs.show_developer = true; + prefs.theme = copy_qstring("myTheme"); + auto display_direct = new qPrefDisplay; + + prefs.display_invalid_dives = true; + prefs.divelist_font = copy_qstring("helvetica"); + prefs.font_size = 15.0; + prefs.show_developer = false; + prefs.theme = copy_qstring("myTheme8"); + auto display = qPrefDisplay::instance(); - TEST(display->divelist_font(),QStringLiteral("helvetica")); - TEST(display->font_size(), 14.0); - TEST(display->display_invalid_dives(), false); + QCOMPARE(display->display_invalid_dives(), display_direct->display_invalid_dives()); + QCOMPARE(display->divelist_font(), display_direct->divelist_font()); + QCOMPARE(display->font_size(), display_direct->font_size()); + QCOMPARE(display->show_developer(), display_direct->show_developer()); + QCOMPARE(display->theme(), display_direct->theme()); } QTEST_MAIN(TestQPrefDisplay) diff --git a/tests/testqPrefDisplay.h b/tests/testqPrefDisplay.h index 1885e8686..6af2d2be5 100644 --- a/tests/testqPrefDisplay.h +++ b/tests/testqPrefDisplay.h @@ -2,15 +2,18 @@ #ifndef TESTQPREFDISPLAY_H #define TESTQPREFDISPLAY_H -#include -#include +#include class TestQPrefDisplay : public QObject { Q_OBJECT private slots: void initTestCase(); - void test1(); + void test_struct_get(); + void test_set_struct(); + void test_set_load_struct(); + void test_struct_disk(); + void test_multiple(); }; #endif // TESTQPREFDISPLAY_H -- cgit v1.2.3-70-g09d2 From b41fa07efadab526bd7df3a6637ed7e35c5ac62f Mon Sep 17 00:00:00 2001 From: jan Iversen Date: Wed, 11 Jul 2018 09:25:52 +0200 Subject: tests: add qPrefDisplay qml testcases add test of qml C++ interface Signed-off-by: Jan Iversen --- tests/tst_qPrefDisplay.qml | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 tests/tst_qPrefDisplay.qml diff --git a/tests/tst_qPrefDisplay.qml b/tests/tst_qPrefDisplay.qml new file mode 100644 index 000000000..eafcadee1 --- /dev/null +++ b/tests/tst_qPrefDisplay.qml @@ -0,0 +1,31 @@ +// SPDX-License-Identifier: GPL-2.0 +import QtQuick 2.6 +import QtTest 1.2 +import org.subsurfacedivelog.mobile 1.0 + +TestCase { + name: "qPref" + + SsrfDisplayPrefs { + id: display + } + + function test_variables() { + var x1 = display.divelist_font + display.divelist_font = "helvitica" + compare(display.divelist_font, "helvitica") + var x2 = display.font_size + display.font_size = 12.0 + compare(display.font_size, 12.0) + var x3 = display.display_invalid_dives + display.display_invalid_dives = !x3 + compare(display.display_invalid_dives, !x3) + var x4 = display.show_developer + display.show_developer = !x4 + compare(display.show_developer, !x4) + var x5 = display.theme + display.theme = "myColor" + compare(display.theme, "myColor") + } + +} -- cgit v1.2.3-70-g09d2 From aa0a918082dced90eb608ba44f39028bfe9ad0c1 Mon Sep 17 00:00:00 2001 From: jan Iversen Date: Thu, 12 Jul 2018 09:33:22 +0200 Subject: core: qPrefDisplay update CHANGELOG.md added note about "show developer" menu being stored on disk Signed-off-by: Jan Iversen --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ef39d73bf..f5965d77b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ +- mobile: show developer menu is now saved on disk and remebered between start of Subsurface - tests: add qml test harness - Cloud storage: fix potential issue with credentials on Linux [#1346] - Mobile/iOS: fix missing translations -- cgit v1.2.3-70-g09d2