diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 2a747e517..310ba6659 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -103,7 +103,6 @@ set(SUBSURFACE_CORE_LIB_SRCS # classes to manage struct preferences for QWidget and QML settings/qPref.cpp - settings/qPrefAnimations.cpp settings/qPrefCloudStorage.cpp settings/qPrefDisplay.cpp settings/qPrefDiveComputer.cpp diff --git a/core/pref.h b/core/pref.h index a27c7d6c4..895006f7e 100644 --- a/core/pref.h +++ b/core/pref.h @@ -109,7 +109,6 @@ struct preferences { const char *divelist_font; double font_size; bool show_developer; - const char *theme; // ********** Facebook ********** facebook_prefs_t facebook; diff --git a/core/settings/qPref.cpp b/core/settings/qPref.cpp index e5f662470..90aedd925 100644 --- a/core/settings/qPref.cpp +++ b/core/settings/qPref.cpp @@ -16,7 +16,6 @@ void qPref::loadSync(bool doSync) if (!doSync) uiLanguage(NULL); - qPrefAnimations::instance()->loadSync(doSync); qPrefCloudStorage::instance()->loadSync(doSync); qPrefDisplay::instance()->loadSync(doSync); qPrefDiveComputer::instance()->loadSync(doSync); diff --git a/core/settings/qPref.h b/core/settings/qPref.h index 36fd9d09a..036b3c6b2 100644 --- a/core/settings/qPref.h +++ b/core/settings/qPref.h @@ -6,7 +6,6 @@ #include -#include "qPrefAnimations.h" #include "qPrefCloudStorage.h" #include "qPrefDisplay.h" #include "qPrefDiveComputer.h" diff --git a/core/settings/qPrefAnimations.cpp b/core/settings/qPrefAnimations.cpp deleted file mode 100644 index ca1980210..000000000 --- a/core/settings/qPrefAnimations.cpp +++ /dev/null @@ -1,21 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -#include "qPrefAnimations.h" -#include "qPrefPrivate.h" - -static const QString group = QStringLiteral("Animations"); - -qPrefAnimations::qPrefAnimations(QObject *parent) : QObject(parent) -{ -} -qPrefAnimations *qPrefAnimations::instance() -{ - static qPrefAnimations *self = new qPrefAnimations; - return self; -} - -void qPrefAnimations::loadSync(bool doSync) -{ - disk_animation_speed(doSync); -} - -HANDLE_PREFERENCE_INT(Animations, "/animation_speed", animation_speed); diff --git a/core/settings/qPrefAnimations.h b/core/settings/qPrefAnimations.h deleted file mode 100644 index 450e854f9..000000000 --- a/core/settings/qPrefAnimations.h +++ /dev/null @@ -1,35 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -#ifndef QPREFANIMATIONS_H -#define QPREFANIMATIONS_H -#include "core/pref.h" - -#include - -class qPrefAnimations : public QObject { - Q_OBJECT - Q_PROPERTY(int animation_speed READ animation_speed WRITE set_animation_speed NOTIFY animation_speed_changed); - -public: - qPrefAnimations(QObject *parent = NULL); - static qPrefAnimations *instance(); - - // Load/Sync local settings (disk) and struct preference - static void loadSync(bool doSync); - static void load() { loadSync(false); } - static void sync() { loadSync(true); } - -public: - static int animation_speed() { return prefs.animation_speed; } - -public slots: - static void set_animation_speed(int value); - -signals: - void animation_speed_changed(int value); - -private: - // functions to load/sync variable with disk - static void disk_animation_speed(bool doSync); -}; - -#endif diff --git a/core/settings/qPrefDisplay.cpp b/core/settings/qPrefDisplay.cpp index a75d1f48b..680fdc923 100644 --- a/core/settings/qPrefDisplay.cpp +++ b/core/settings/qPrefDisplay.cpp @@ -8,6 +8,39 @@ static const QString group = QStringLiteral("Display"); +QPointF qPrefDisplay::st_tooltip_position; +static const QPointF st_tooltip_position_default = QPointF(0,0); + +QString qPrefDisplay::st_lastDir; +static const QString st_lastDir_default = ""; + +QString qPrefDisplay::st_theme; +static const QString st_theme_default = "Blue"; + +QString qPrefDisplay::st_UserSurvey; +static const QString st_UserSurvey_default = ""; + +QByteArray qPrefDisplay::st_mainSplitter; +static const QByteArray st_mainSplitter_default = ""; + +QByteArray qPrefDisplay::st_topSplitter; +static const QByteArray st_topSplitter_default = ""; + +QByteArray qPrefDisplay::st_bottomSplitter; +static const QByteArray st_bottomSplitter_default = ""; + +bool qPrefDisplay::st_maximized; +static bool st_maximized_default = false; + +QByteArray qPrefDisplay::st_geometry; +static const QByteArray st_geometry_default = 0; + +QByteArray qPrefDisplay::st_windowState; +static const QByteArray st_windowState_default = 0; + +int qPrefDisplay::st_lastState; +static int st_lastState_default = false; + qPrefDisplay::qPrefDisplay(QObject *parent) : QObject(parent) { } @@ -19,11 +52,16 @@ qPrefDisplay *qPrefDisplay::instance() void qPrefDisplay::loadSync(bool doSync) { + disk_animation_speed(doSync); disk_divelist_font(doSync); disk_font_size(doSync); disk_display_invalid_dives(doSync); disk_show_developer(doSync); - disk_theme(doSync); + if (!doSync) { + load_tooltip_position(); + load_theme(); + load_UserSurvey(); + } } void qPrefDisplay::set_divelist_font(const QString &value) @@ -69,13 +107,13 @@ void qPrefDisplay::disk_font_size(bool doSync) setCorrectFont(); } +//JAN static const QString group = QStringLiteral("Animations"); +HANDLE_PREFERENCE_INT(Display, "/animation_speed", animation_speed); + 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 @@ -102,3 +140,25 @@ void qPrefDisplay::setCorrectFont() prefs.display_invalid_dives = qPrefPrivate::propValue(group + "/displayinvalid", default_prefs.display_invalid_dives).toBool(); } + +HANDLE_PROP_QSTRING(Display, "FileDialog/LastDir", lastDir); + +HANDLE_PROP_QSTRING(Display, "Theme/currentTheme", theme); + +HANDLE_PROP_QPOINTF(Display, "ProfileMap/tooltip_position", tooltip_position); + +HANDLE_PROP_QSTRING(Display, "UserSurvey/SurveyDone", UserSurvey); + +HANDLE_PROP_QBYTEARRAY(Display, "MainWindow/mainSplitter", mainSplitter); + +HANDLE_PROP_QBYTEARRAY(Display, "MainWindow/topSplitter", topSplitter); + +HANDLE_PROP_QBYTEARRAY(Display, "MainWindow/bottomSplitter", bottomSplitter); + +HANDLE_PROP_BOOL(Display, "MainWindow/maximized", maximized); + +HANDLE_PROP_QBYTEARRAY(Display, "MainWindow/geometry", geometry); + +HANDLE_PROP_QBYTEARRAY(Display, "MainWindow/windowState", windowState); + +HANDLE_PROP_INT(Display, "MainWindow/lastState", lastState); diff --git a/core/settings/qPrefDisplay.h b/core/settings/qPrefDisplay.h index ba7be7200..5a7eb7aac 100644 --- a/core/settings/qPrefDisplay.h +++ b/core/settings/qPrefDisplay.h @@ -4,14 +4,26 @@ #include "core/pref.h" #include +#include class qPrefDisplay : public QObject { Q_OBJECT + Q_PROPERTY(int animation_speed READ animation_speed WRITE set_animation_speed NOTIFY animation_speed_changed); Q_PROPERTY(QString divelist_font READ divelist_font WRITE set_divelist_font NOTIFY divelist_font_changed); Q_PROPERTY(double font_size READ font_size WRITE set_font_size NOTIFY font_size_changed); Q_PROPERTY(bool display_invalid_dives READ display_invalid_dives WRITE set_display_invalid_dives NOTIFY display_invalid_dives_changed); + Q_PROPERTY(QString lastDir READ lastDir WRITE set_lastDir NOTIFY lastDir_changed); Q_PROPERTY(bool show_developer READ show_developer WRITE set_show_developer NOTIFY show_developer_changed); Q_PROPERTY(QString theme READ theme WRITE set_theme NOTIFY theme_changed); + Q_PROPERTY(QPointF tooltip_position READ tooltip_position WRITE set_tooltip_position NOTIFY tooltip_position_changed); + Q_PROPERTY(QString UserSurvey READ UserSurvey WRITE set_UserSurvey NOTIFY UserSurvey_changed); + Q_PROPERTY(QByteArray mainSplitter READ mainSplitter WRITE set_mainSplitter NOTIFY mainSplitter_changed); + Q_PROPERTY(QByteArray topSplitter READ topSplitter WRITE set_topSplitter NOTIFY topSplitter_changed); + Q_PROPERTY(QByteArray bottomSplitter READ bottomSplitter WRITE set_bottomSplitter NOTIFY bottomSplitter_changed); + Q_PROPERTY(bool maximized READ maximized WRITE set_maximized NOTIFY maximized_changed); + Q_PROPERTY(QByteArray geometry READ geometry WRITE set_geometry NOTIFY geometry_changed); + Q_PROPERTY(QByteArray windowState READ windowState WRITE set_windowState NOTIFY windowState_changed); + Q_PROPERTY(int lastState READ lastState WRITE set_lastState NOTIFY lastState_changed); public: qPrefDisplay(QObject *parent = NULL); @@ -23,35 +35,94 @@ public: static void sync() { loadSync(true); } public: + static int animation_speed() { return prefs.animation_speed; } static QString divelist_font() { return prefs.divelist_font; } static double font_size() { return prefs.font_size; } static bool display_invalid_dives() { return prefs.display_invalid_dives; } + static QString lastDir() { return st_lastDir; ; } static bool show_developer() { return prefs.show_developer; } - static QString theme() { return prefs.theme; } + static QString theme() { return st_theme; } + static QPointF tooltip_position() { return st_tooltip_position; } + static QString UserSurvey() { return st_UserSurvey; } + static QByteArray mainSplitter() { return st_mainSplitter; } + static QByteArray topSplitter() { return st_topSplitter; } + static QByteArray bottomSplitter() { return st_bottomSplitter; } + static bool maximized() { return st_maximized; } + static QByteArray geometry() { return st_geometry; } + static QByteArray windowState() { return st_windowState; } + static int lastState() { return st_lastState; } public slots: + static void set_animation_speed(int value); static void set_divelist_font(const QString &value); static void set_font_size(double value); static void set_display_invalid_dives(bool value); + static void set_lastDir(const QString &value); static void set_show_developer(bool value); static void set_theme(const QString &value); + static void set_tooltip_position(const QPointF &value); + static void set_UserSurvey(const QString &value); + static void set_mainSplitter(const QByteArray &value); + static void set_topSplitter(const QByteArray &value); + static void set_bottomSplitter(const QByteArray &value); + static void set_maximized(bool value); + static void set_geometry(const QByteArray& value); + static void set_windowState(const QByteArray& value); + static void set_lastState(int value); signals: + void animation_speed_changed(int value); void divelist_font_changed(const QString &value); void font_size_changed(double value); void display_invalid_dives_changed(bool value); + void lastDir_changed(const QString &value); void show_developer_changed(bool value); void theme_changed(const QString &value); + void tooltip_position_changed(const QPointF &value); + void UserSurvey_changed(const QString &value); + void mainSplitter_changed(const QByteArray &value); + void topSplitter_changed(const QByteArray &value); + void bottomSplitter_changed(const QByteArray &value); + void maximized_changed(bool value); + void geometry_changed(const QByteArray& value); + void windowState_changed(const QByteArray& value); + void lastState_changed(int value); private: // functions to load/sync variable with disk + static void disk_animation_speed(bool doSync); static void disk_divelist_font(bool doSync); static void disk_font_size(bool doSync); static void disk_display_invalid_dives(bool doSync); static void disk_show_developer(bool doSync); - static void disk_theme(bool doSync); + + // functions to handle class variables + static void load_lastDir(); + static void load_theme(); + static void load_tooltip_position(); + static void load_UserSurvey(); + static void load_mainSplitter(); + static void load_topSplitter(); + static void load_bottomSplitter(); + static void load_maximized(); + static void load_geometry(); + static void load_windowState(); + static void load_lastState(); // font helper function static void setCorrectFont(); + + // Class variables not present in structure preferences + static QString st_lastDir; + static QString st_theme; + static QPointF st_tooltip_position; + static QString st_UserSurvey; + static QByteArray st_mainSplitter; + static QByteArray st_topSplitter; + static QByteArray st_bottomSplitter; + static bool st_maximized; + static QByteArray st_geometry; + static QByteArray st_windowState; + static int st_lastState; }; #endif diff --git a/desktop-widgets/preferences/preferences_defaults.cpp b/desktop-widgets/preferences/preferences_defaults.cpp index cf7b03c9e..b8af84b91 100644 --- a/desktop-widgets/preferences/preferences_defaults.cpp +++ b/desktop-widgets/preferences/preferences_defaults.cpp @@ -74,7 +74,7 @@ void PreferencesDefaults::refreshSettings() ui->default_cylinder->setCurrentIndex(i); } ui->displayinvalid->setChecked(qPrefDisplay::display_invalid_dives()); - ui->velocitySlider->setValue(qPrefAnimations::animation_speed()); + ui->velocitySlider->setValue(qPrefDisplay::animation_speed()); ui->btnUseDefaultFile->setChecked(qPrefGeneral::use_default_file()); if (qPrefCloudStorage::cloud_verification_status() == qPref::CS_VERIFIED) { @@ -117,5 +117,5 @@ void PreferencesDefaults::syncSettings() qPrefDisplay::set_divelist_font(ui->font->currentFont().toString()); qPrefDisplay::set_font_size(ui->fontsize->value()); qPrefDisplay::set_display_invalid_dives(ui->displayinvalid->isChecked()); - qPrefAnimations::set_animation_speed(ui->velocitySlider->value()); + qPrefDisplay::set_animation_speed(ui->velocitySlider->value()); } diff --git a/desktop-widgets/printer.cpp b/desktop-widgets/printer.cpp index 6d3af39e9..780dce2ba 100644 --- a/desktop-widgets/printer.cpp +++ b/desktop-widgets/printer.cpp @@ -3,7 +3,7 @@ #include "templatelayout.h" #include "core/statistics.h" #include "core/qthelper.h" -#include "core/settings/qPrefAnimations.h" +#include "core/settings/qPrefDisplay.h" #include #include @@ -136,7 +136,7 @@ void Printer::render(int Pages = 0) // keep original preferences QPointer profile = MainWindow::instance()->graphics(); int profileFrameStyle = profile->frameStyle(); - int animationOriginal = qPrefAnimations::animation_speed(); + int animationOriginal = qPrefDisplay::animation_speed(); double fontScale = profile->getFontPrintScale(); double printFontScale = 1.0; @@ -144,7 +144,7 @@ void Printer::render(int Pages = 0) profile->setFrameStyle(QFrame::NoFrame); profile->setPrintMode(true, !printOptions->color_selected); profile->setToolTipVisibile(false); - qPrefAnimations::set_animation_speed(0); + qPrefDisplay::set_animation_speed(0); // render the Qwebview QPainter painter; @@ -202,7 +202,7 @@ void Printer::render(int Pages = 0) #else profile->resize(originalSize); #endif - qPrefAnimations::set_animation_speed(animationOriginal); + qPrefDisplay::set_animation_speed(animationOriginal); //replot the dive after returning the settings profile->plotDive(0, true, true); diff --git a/packaging/ios/Subsurface-mobile.pro b/packaging/ios/Subsurface-mobile.pro index f065fcd7f..7637480cb 100644 --- a/packaging/ios/Subsurface-mobile.pro +++ b/packaging/ios/Subsurface-mobile.pro @@ -78,7 +78,6 @@ SOURCES += ../../subsurface-mobile-main.cpp \ ../../core/connectionlistmodel.cpp \ ../../core/qt-ble.cpp \ ../../core/settings/qPref.cpp \ - ../../core/settings/qPrefAnimations.cpp \ ../../core/settings/qPrefCloudStorage.cpp \ ../../core/settings/qPrefDisplay.cpp \ ../../core/settings/qPrefDiveComputer.cpp \ @@ -200,7 +199,6 @@ HEADERS += \ ../../core/connectionlistmodel.h \ ../../core/qt-ble.h \ ../../core/settings/qPref.h \ - ../../core/settings/qPrefAnimations.h \ ../../core/settings/qPrefCloudStorage.h \ ../../core/settings/qPrefDisplay.h \ ../../core/settings/qPrefDiveComputer.h \ diff --git a/profile-widget/animationfunctions.cpp b/profile-widget/animationfunctions.cpp index 0b84fbcd5..89779e3a8 100644 --- a/profile-widget/animationfunctions.cpp +++ b/profile-widget/animationfunctions.cpp @@ -1,14 +1,14 @@ // SPDX-License-Identifier: GPL-2.0 #include "profile-widget/animationfunctions.h" #include "core/pref.h" -#include "core/settings/qPrefAnimations.h" +#include "core/settings/qPrefDisplay.h" #include namespace Animations { void hide(QObject *obj) { - if (qPrefAnimations::animation_speed() != 0) { + if (qPrefDisplay::animation_speed() != 0) { QPropertyAnimation *animation = new QPropertyAnimation(obj, "opacity"); animation->setStartValue(1); animation->setEndValue(0); @@ -20,7 +20,7 @@ namespace Animations { void show(QObject *obj) { - if (qPrefAnimations::animation_speed() != 0) { + if (qPrefDisplay::animation_speed() != 0) { QPropertyAnimation *animation = new QPropertyAnimation(obj, "opacity"); animation->setStartValue(0); animation->setEndValue(1); @@ -32,7 +32,7 @@ namespace Animations { void animDelete(QObject *obj) { - if (qPrefAnimations::animation_speed() != 0) { + if (qPrefDisplay::animation_speed() != 0) { QPropertyAnimation *animation = new QPropertyAnimation(obj, "opacity"); obj->connect(animation, &QPropertyAnimation::finished, &QObject::deleteLater); animation->setStartValue(1); @@ -45,7 +45,7 @@ namespace Animations { void moveTo(QObject *obj, qreal x, qreal y) { - if (qPrefAnimations::animation_speed() != 0) { + if (qPrefDisplay::animation_speed() != 0) { QPropertyAnimation *animation = new QPropertyAnimation(obj, "pos"); animation->setDuration(prefs.animation_speed); animation->setStartValue(obj->property("pos").toPointF()); @@ -58,7 +58,7 @@ namespace Animations { void scaleTo(QObject *obj, qreal scale) { - if (qPrefAnimations::animation_speed() != 0) { + if (qPrefDisplay::animation_speed() != 0) { QPropertyAnimation *animation = new QPropertyAnimation(obj, "scale"); animation->setDuration(prefs.animation_speed); animation->setStartValue(obj->property("scale").toReal()); diff --git a/profile-widget/divetooltipitem.cpp b/profile-widget/divetooltipitem.cpp index 21bf82c13..363382324 100644 --- a/profile-widget/divetooltipitem.cpp +++ b/profile-widget/divetooltipitem.cpp @@ -4,7 +4,7 @@ #include "core/profile.h" #include "core/membuffer.h" #include "core/metrics.h" -#include "core/settings/qPrefAnimations.h" +#include "core/settings/qPrefDisplay.h" #include #include #include @@ -62,7 +62,7 @@ void ToolTipItem::collapse() { int dim = defaultIconMetrics().sz_small; - if (qPrefAnimations::animation_speed()) { + if (qPrefDisplay::animation_speed()) { QPropertyAnimation *animation = new QPropertyAnimation(this, "rect"); animation->setDuration(100); animation->setStartValue(nextRectangle); @@ -120,7 +120,7 @@ void ToolTipItem::expand() nextRectangle.setHeight(height); if (nextRectangle != rect()) { - if (qPrefAnimations::animation_speed()) { + if (qPrefDisplay::animation_speed()) { QPropertyAnimation *animation = new QPropertyAnimation(this, "rect", this); animation->setDuration(prefs.animation_speed); animation->setStartValue(rect()); diff --git a/profile-widget/profilewidget2.cpp b/profile-widget/profilewidget2.cpp index a40908e5c..9155b7511 100644 --- a/profile-widget/profilewidget2.cpp +++ b/profile-widget/profilewidget2.cpp @@ -4,7 +4,7 @@ #include "core/subsurface-string.h" #include "core/qthelper.h" #include "core/profile.h" -#include "core/settings/qPrefAnimations.h" +#include "core/settings/qPrefDisplay.h" #include "core/settings/qPrefTechnicalDetails.h" #include "core/settings/qPrefPartialPressureGas.h" #include "profile-widget/diveeventitem.h" @@ -596,8 +596,8 @@ void ProfileWidget2::plotDive(struct dive *d, bool force, bool doClearPictures) // special handling for the first time we display things int animSpeedBackup = 0; if (firstCall && haveFilesOnCommandLine()) { - animSpeedBackup = qPrefAnimations::animation_speed(); - qPrefAnimations::set_animation_speed(0); + animSpeedBackup = qPrefDisplay::animation_speed(); + qPrefDisplay::set_animation_speed(0); firstCall = false; } @@ -806,7 +806,7 @@ void ProfileWidget2::plotDive(struct dive *d, bool force, bool doClearPictures) #endif diveComputerText->setText(dcText); if (haveFilesOnCommandLine() && animSpeedBackup != 0) { - qPrefAnimations::set_animation_speed(animSpeedBackup); + qPrefDisplay::set_animation_speed(animSpeedBackup); } #ifndef SUBSURFACE_MOBILE diff --git a/subsurface-helper.cpp b/subsurface-helper.cpp index 67cfcceb4..389d47cbf 100644 --- a/subsurface-helper.cpp +++ b/subsurface-helper.cpp @@ -156,7 +156,6 @@ void register_qml_types() { int rc; REGISTER_TYPE(qPref, "SsrfPrefs"); - REGISTER_TYPE(qPrefAnimations, "SsrfAnimationsPrefs"); REGISTER_TYPE(qPrefCloudStorage, "SsrfCloudStoragePrefs"); REGISTER_TYPE(qPrefDisplay, "SsrfDisplayPrefs"); REGISTER_TYPE(qPrefDiveComputer, "SsrfDiveComputerPrefs"); diff --git a/subsurface-mobile-main.cpp b/subsurface-mobile-main.cpp index 4f0bf1d7f..e700455f3 100644 --- a/subsurface-mobile-main.cpp +++ b/subsurface-mobile-main.cpp @@ -98,7 +98,7 @@ int main(int argc, char **argv) set_filename(NULL); // some hard coded settings - qPrefAnimations::set_animation_speed(0); // we render the profile to pixmap, no animations + qPrefDisplay::set_animation_speed(0); // we render the profile to pixmap, no animations // always show the divecomputer reported ceiling in red prefs.redceiling = 1; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index fd1be7ea6..4d59536bd 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -100,7 +100,6 @@ TEST(TestPicture testpicture.cpp) TEST(TestMerge testmerge.cpp) TEST(TestTagList testtaglist.cpp) -TEST(TestQPrefAnimations testqPrefAnimations.cpp) TEST(TestQPrefCloudStorage testqPrefCloudStorage.cpp) TEST(TestQPrefDisplay testqPrefDisplay.cpp) TEST(TestQPrefDiveComputer testqPrefDiveComputer.cpp) @@ -132,7 +131,6 @@ add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} TestMerge TestTagList - TestQPrefAnimations TestQPrefCloudStorage TestQPrefDisplay TestQPrefDiveComputer diff --git a/tests/testqPrefAnimations.cpp b/tests/testqPrefAnimations.cpp deleted file mode 100644 index 90292f28f..000000000 --- a/tests/testqPrefAnimations.cpp +++ /dev/null @@ -1,83 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -#include "testqPrefAnimations.h" - -#include "core/pref.h" -#include "core/qthelper.h" -#include "core/settings/qPref.h" - -#include -#include - -void TestQPrefAnimations::initTestCase() -{ - QCoreApplication::setOrganizationName("Subsurface"); - QCoreApplication::setOrganizationDomain("subsurface.hohndel.org"); - QCoreApplication::setApplicationName("SubsurfaceTestQPrefAnimations"); -} - -void TestQPrefAnimations::test_struct_get() -{ - // Test struct pref -> get func. - - auto tst = qPrefAnimations::instance(); - - prefs.animation_speed = 17; - - QCOMPARE(tst->animation_speed(), prefs.animation_speed); -} - -void TestQPrefAnimations::test_set_struct() -{ - // Test set func -> struct pref - - auto tst = qPrefAnimations::instance(); - - tst->set_animation_speed(27); - - QCOMPARE(prefs.animation_speed, 27); -} - -void TestQPrefAnimations::test_set_load_struct() -{ - // test set func -> load -> struct pref - - auto tst = qPrefAnimations::instance(); - - tst->set_animation_speed(33); - - prefs.animation_speed = 17; - - tst->load(); - QCOMPARE(prefs.animation_speed, 33); -} - -void TestQPrefAnimations::test_struct_disk() -{ - // test struct prefs -> disk - - auto tst = qPrefAnimations::instance(); - - prefs.animation_speed = 27; - - tst->sync(); - prefs.animation_speed = 35; - - tst->load(); - QCOMPARE(prefs.animation_speed, 27); -} - -void TestQPrefAnimations::test_multiple() -{ - // test multiple instances have the same information - - prefs.animation_speed = 37; - auto tst_direct = new qPrefAnimations; - - prefs.animation_speed = 25; - auto tst = qPrefAnimations::instance(); - - QCOMPARE(tst->animation_speed(), tst_direct->animation_speed()); - QCOMPARE(tst_direct->animation_speed(), 25); -} - -QTEST_MAIN(TestQPrefAnimations) diff --git a/tests/testqPrefAnimations.h b/tests/testqPrefAnimations.h deleted file mode 100644 index f0ed4a195..000000000 --- a/tests/testqPrefAnimations.h +++ /dev/null @@ -1,18 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -#ifndef TESTQPREFANIMATIONS_H -#define TESTQPREFANIMATIONS_H - -#include - -class TestQPrefAnimations : public QObject { - Q_OBJECT -private slots: - void initTestCase(); - void test_struct_get(); - void test_set_struct(); - void test_set_load_struct(); - void test_struct_disk(); - void test_multiple(); -}; - -#endif // TESTQPREFANIMATIONS_H diff --git a/tests/testqPrefDisplay.cpp b/tests/testqPrefDisplay.cpp index 0f534c0da..ce4d627ed 100644 --- a/tests/testqPrefDisplay.cpp +++ b/tests/testqPrefDisplay.cpp @@ -21,17 +21,17 @@ void TestQPrefDisplay::test_struct_get() auto display = qPrefDisplay::instance(); + prefs.animation_speed = 17; 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->animation_speed(), prefs.animation_speed); 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() @@ -40,17 +40,39 @@ void TestQPrefDisplay::test_set_struct() auto display = qPrefDisplay::instance(); + display->set_animation_speed(27); display->set_display_invalid_dives(true); display->set_divelist_font("doNotCareAtAll"); display->set_font_size(12.0); display->set_show_developer(false); display->set_theme("myTheme"); + display->set_lastDir("test1"); + display->set_tooltip_position(QPointF(512, 3)); + display->set_UserSurvey("my1"); + display->set_mainSplitter("main1"); + display->set_topSplitter("top1"); + display->set_bottomSplitter("bottom1"); + display->set_maximized(false); + display->set_geometry("geo1"); + display->set_windowState("win1"); + display->set_lastState(17); + QCOMPARE(prefs.animation_speed, 27); QCOMPARE(prefs.display_invalid_dives, true); QCOMPARE(prefs.divelist_font, "doNotCareAtAll"); QCOMPARE(prefs.font_size, 12.0); QCOMPARE(prefs.show_developer, false); - QCOMPARE(prefs.theme, "myTheme"); + QCOMPARE(display->theme(), QString("myTheme")); + QCOMPARE(display->lastDir(), QString("test1")); + QCOMPARE(display->tooltip_position(), QPointF(512, 3)); + QCOMPARE(display->UserSurvey(), QString("my1")); + QCOMPARE(display->mainSplitter(), QByteArray("main1")); + QCOMPARE(display->topSplitter(), QByteArray("top1")); + QCOMPARE(display->bottomSplitter(), QByteArray("bottom1")); + QCOMPARE(display->maximized(), false); + QCOMPARE(display->geometry(), QByteArray("geo1")); + QCOMPARE(display->windowState(), QByteArray("win1")); + QCOMPARE(display->lastState(), 17); } void TestQPrefDisplay::test_set_load_struct() @@ -59,24 +81,46 @@ void TestQPrefDisplay::test_set_load_struct() auto display = qPrefDisplay::instance(); + display->set_animation_speed(33); display->set_display_invalid_dives(false); display->set_divelist_font("doNotCareString"); display->set_font_size(15.0); display->set_show_developer(true); display->set_theme("myTheme2"); + display->set_lastDir("test2"); + display->set_tooltip_position(QPointF(612, 3)); + display->set_UserSurvey("my2"); + display->set_mainSplitter("main2"); + display->set_topSplitter("top2"); + display->set_bottomSplitter("bottom2"); + display->set_maximized(true); + display->set_geometry("geo2"); + display->set_windowState("win2"); + display->set_lastState(27); + prefs.animation_speed = 17; prefs.display_invalid_dives = true; prefs.divelist_font = copy_qstring("doNotCareAtAll"); prefs.font_size = 12.0; prefs.show_developer = false; - prefs.theme = copy_qstring("myTheme"); display->load(); + QCOMPARE(prefs.animation_speed, 33); QCOMPARE(prefs.display_invalid_dives, false); QCOMPARE(prefs.divelist_font, "doNotCareString"); QCOMPARE(prefs.font_size, 15.0); QCOMPARE(prefs.show_developer, true); - QCOMPARE(prefs.theme, "myTheme2"); + QCOMPARE(display->theme(), QString("myTheme2")); + QCOMPARE(display->lastDir(), QString("test2")); + QCOMPARE(display->tooltip_position(), QPointF(612, 3)); + QCOMPARE(display->UserSurvey(), QString("my2")); + QCOMPARE(display->mainSplitter(), QByteArray("main2")); + QCOMPARE(display->topSplitter(), QByteArray("top2")); + QCOMPARE(display->bottomSplitter(), QByteArray("bottom2")); + QCOMPARE(display->maximized(), true); + QCOMPARE(display->geometry(), QByteArray("geo2")); + QCOMPARE(display->windowState(), QByteArray("win2")); + QCOMPARE(display->lastState(), 27); } void TestQPrefDisplay::test_struct_disk() @@ -85,25 +129,25 @@ void TestQPrefDisplay::test_struct_disk() auto display = qPrefDisplay::instance(); + prefs.animation_speed = 27; prefs.display_invalid_dives = true; prefs.divelist_font = copy_qstring("doNotCareAtAll"); prefs.font_size = 17.0; prefs.show_developer = false; - prefs.theme = copy_qstring("myTheme3"); display->sync(); + prefs.animation_speed = 35; prefs.display_invalid_dives = false; prefs.divelist_font = copy_qstring("noString"); prefs.font_size = 11.0; prefs.show_developer = true; - prefs.theme = copy_qstring("myTheme"); display->load(); + QCOMPARE(prefs.animation_speed, 27); QCOMPARE(prefs.display_invalid_dives, true); QCOMPARE(prefs.divelist_font, "doNotCareAtAll"); QCOMPARE(prefs.font_size, 17.0); QCOMPARE(prefs.show_developer, false); - QCOMPARE(prefs.theme, "myTheme3"); } void TestQPrefDisplay::test_multiple() diff --git a/tests/tst_qPrefAnimations.qml b/tests/tst_qPrefAnimations.qml deleted file mode 100644 index 01e59fa42..000000000 --- a/tests/tst_qPrefAnimations.qml +++ /dev/null @@ -1,19 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -import QtQuick 2.6 -import QtTest 1.2 -import org.subsurfacedivelog.mobile 1.0 - -TestCase { - name: "qPrefAnimations" - - SsrfAnimationsPrefs { - id: tst - } - - function test_variables() { - var x1 = tst.animation_speed; - tst.animation_speed = 37 - compare(tst.animation_speed, 37) - } - -} diff --git a/tests/tst_qPrefDisplay.qml b/tests/tst_qPrefDisplay.qml index eb4e11e30..e25f17bf8 100644 --- a/tests/tst_qPrefDisplay.qml +++ b/tests/tst_qPrefDisplay.qml @@ -11,21 +11,68 @@ TestCase { } function test_variables() { + var x0 = display.animation_speed + display.animation_speed = 37 + compare(display.animation_speed, 37) + 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") - } +//TBD var x6 = display.tooltip_position +//TBD display.tooltip_position = ?? +//TBD compare(display.tooltip_position, ??) + + var x7 = display.lastDir + display.lastDir = "myDir" + compare(display.lastDir, "myDir") + + var x8 = display.UserSurvey + display.UserSurvey = "yes" + compare(display.UserSurvey, "yes") + +//TBD var x9 = display.mainSplitter +//TBD display.mainSplitter = ??? +//TBD compare(display.mainSplitter, ???) + +//TBD var x10 = display.topSplitter +//TBD display.topSplitter = ??? +//TBD compare(display.topSplitter, ???) + +//TBD var x11 = display.bottomSplitter +//TBD display.bottomSplitter = ??? +//TBD compare(display.bottomSplitter, ???) + + var x12 = display.maximized + display.maximized = true + compare(display.maximized, true) + +//TBD var x13 = display.geometry +//TBD display.geometry = ??? +//TBD compare(display.geometry, ???) + +//TBD var x14 = display.windowState +//TBD display.windowState = ??? +//TBD compare(display.windowState, ???) + + var x15 = display.lastState + display.lastState = 17 + compare(display.lastState, 17) + } }