summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md2
-rw-r--r--CMakeLists.txt4
-rw-r--r--core/CMakeLists.txt1
-rw-r--r--core/settings/qPref.cpp1
-rw-r--r--core/settings/qPref.h5
-rw-r--r--core/settings/qPrefAnimations.cpp20
-rw-r--r--core/settings/qPrefAnimations.h38
-rw-r--r--core/settings/qPrefDisplay.cpp36
-rw-r--r--core/settings/qPrefDisplay.h5
-rw-r--r--core/subsurface-qt/SettingsObjectWrapper.cpp120
-rw-r--r--core/subsurface-qt/SettingsObjectWrapper.h48
-rw-r--r--desktop-widgets/preferences/preferences_defaults.cpp12
-rw-r--r--packaging/ios/Subsurface-mobile.pro2
-rw-r--r--subsurface-helper.cpp95
-rw-r--r--tests/.gitignore1
-rw-r--r--tests/CMakeLists.txt17
-rw-r--r--tests/testpreferences.cpp22
-rw-r--r--tests/testqPrefAnimations.cpp81
-rw-r--r--tests/testqPrefAnimations.h19
-rw-r--r--tests/testqPrefDisplay.cpp133
-rw-r--r--tests/testqPrefDisplay.h19
-rw-r--r--tests/testqml.cpp48
-rw-r--r--tests/tst_qPref.qml17
-rw-r--r--tests/tst_qPrefAnimations.qml19
-rw-r--r--tests/tst_qPrefDisplay.qml31
25 files changed, 560 insertions, 236 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 132286276..a47c6218f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,5 @@
+- mobile: show developer menu is now saved on disk and remebered between start of Subsurface
+- tests: add qml test harness
- Dive media: experimental support for metadata extraction from AVI and WMV files
- Dive media: sort thumbnails by timestamp
- Dive media: don't recalculate all pictures on drag & drop
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ce8571c8a..986e5632c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -224,9 +224,9 @@ if(BTSUPPORT)
list(APPEND QT_EXTRA_LIBRARIES Qt5::Bluetooth)
endif()
-find_package(Qt5 REQUIRED COMPONENTS Core Concurrent Widgets Network Svg Test LinguistTools Positioning Quick Location ${QT_EXTRA_COMPONENTS})
+find_package(Qt5 REQUIRED COMPONENTS Core Concurrent Widgets Network Svg Test QuickTest LinguistTools Positioning Quick Location ${QT_EXTRA_COMPONENTS})
set(QT_LIBRARIES Qt5::Core Qt5::Concurrent Qt5::Widgets Qt5::Network Qt5::Svg Qt5::Positioning Qt5::Quick Qt5::Location ${QT_EXTRA_LIBRARIES})
-set(QT_TEST_LIBRARIES ${QT_LIBRARIES} Qt5::Test)
+set(QT_TEST_LIBRARIES ${QT_LIBRARIES} Qt5::Test Qt5::QuickTest)
#disable bluetooth if Qt version is ancient.
if (BTSUPPORT AND Qt5Widgets_VERSION VERSION_LESS 5.4.0)
diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt
index 67f0623a7..5b476c779 100644
--- a/core/CMakeLists.txt
+++ b/core/CMakeLists.txt
@@ -100,6 +100,7 @@ set(SUBSURFACE_CORE_LIB_SRCS
# classes to manage struct preferences for QWidget and QML
settings/qPref.cpp
+ settings/qPrefAnimations.cpp
settings/qPrefDisplay.cpp
#Subsurface Qt have the Subsurface structs QObjectified for easy access via QML.
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..758b159d7 100644
--- a/core/settings/qPref.h
+++ b/core/settings/qPref.h
@@ -6,6 +6,7 @@
#include <QSettings>
#include "core/pref.h"
+#include "qPrefAnimations.h"
#include "qPrefDisplay.h"
class qPref : public QObject {
@@ -20,6 +21,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 {
@@ -32,8 +35,6 @@ public:
const QString canonical_version() const;
const QString mobile_version() const;
-
-private:
};
#endif
diff --git a/core/settings/qPrefAnimations.cpp b/core/settings/qPrefAnimations.cpp
new file mode 100644
index 000000000..a6ecc1d5b
--- /dev/null
+++ b/core/settings/qPrefAnimations.cpp
@@ -0,0 +1,20 @@
+// SPDX-License-Identifier: GPL-2.0
+#include "qPref.h"
+#include "qPref_private.h"
+#include "qPrefAnimations.h"
+
+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
new file mode 100644
index 000000000..fb58b207e
--- /dev/null
+++ b/core/settings/qPrefAnimations.h
@@ -0,0 +1,38 @@
+// SPDX-License-Identifier: GPL-2.0
+#ifndef QPREFANIMATIONS_H
+#define QPREFANIMATIONS_H
+
+#include <QObject>
+#include <QSettings>
+
+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
+ void loadSync(bool doSync);
+ void load() { loadSync(false); }
+ void sync() { loadSync(true); }
+
+public:
+ int animation_speed() const;
+
+public slots:
+ void set_animation_speed(int value);
+
+signals:
+ void animation_speed_changed(int value);
+
+private:
+ const QString group = QStringLiteral("Animations");
+ QSettings setting;
+
+ // functions to load/sync variable with disk
+ void disk_animation_speed(bool doSync);
+};
+
+#endif
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 6448e0115..4a1c0ada5 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;
@@ -51,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 80b9df8ee..e2fadd90c 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)
{
@@ -2123,27 +2054,6 @@ void LanguageSettingsObjectWrapper::setDateFormatOverride(bool value)
emit dateFormatOverrideChanged(value);
}
-AnimationsSettingsObjectWrapper::AnimationsSettingsObjectWrapper(QObject* parent):
- QObject(parent)
-{
-}
-
-int AnimationsSettingsObjectWrapper::animationSpeed() const
-{
- return prefs.animation_speed;
-}
-
-void AnimationsSettingsObjectWrapper::setAnimationSpeed(int value)
-{
- if (value == prefs.animation_speed)
- return;
-
- QSettings s;
- s.beginGroup(group);
- s.setValue("animation_speed", value);
- prefs.animation_speed = value;
- emit animationSpeedChanged(value);
-}
LocationServiceSettingsObjectWrapper::LocationServiceSettingsObjectWrapper(QObject* parent):
QObject(parent)
@@ -2194,9 +2104,9 @@ 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)),
+ animation_settings(new qPrefAnimations(this)),
location_settings(new LocationServiceSettingsObjectWrapper(this)),
update_manager_settings(new UpdateManagerSettings(this)),
dive_computer_settings(new DiveComputerSettings(this))
@@ -2287,29 +2197,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<QFont>();
- 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);
@@ -2420,6 +2308,8 @@ void SettingsObjectWrapper::load()
void SettingsObjectWrapper::sync()
{
+ qPrefDisplay::instance()->sync();
+
QSettings s;
s.beginGroup("Planner");
s.setValue("last_stop", prefs.last_stop);
diff --git a/core/subsurface-qt/SettingsObjectWrapper.h b/core/subsurface-qt/SettingsObjectWrapper.h
index 64f0621b2..075227384 100644
--- a/core/subsurface-qt/SettingsObjectWrapper.h
+++ b/core/subsurface-qt/SettingsObjectWrapper.h
@@ -6,6 +6,7 @@
#include <QDate>
#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)
@@ -661,23 +640,6 @@ private:
const QString group = QStringLiteral("Language");
};
-class AnimationsSettingsObjectWrapper : public QObject {
- Q_OBJECT
- Q_PROPERTY(int animation_speed READ animationSpeed WRITE setAnimationSpeed NOTIFY animationSpeedChanged)
-public:
- AnimationsSettingsObjectWrapper(QObject *parent);
- int animationSpeed() const;
-
-public slots:
- void setAnimationSpeed(int value);
-
-signals:
- void animationSpeedChanged(int value);
-
-private:
- const QString group = QStringLiteral("Animations");
-};
-
class LocationServiceSettingsObjectWrapper : public QObject {
Q_OBJECT
Q_PROPERTY(int time_threshold READ timeThreshold WRITE setTimeThreshold NOTIFY timeThresholdChanged)
@@ -709,9 +671,9 @@ 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(qPrefAnimations* animation MEMBER animation_settings CONSTANT)
Q_PROPERTY(LocationServiceSettingsObjectWrapper* Location MEMBER location_settings CONSTANT)
Q_PROPERTY(UpdateManagerSettings* update MEMBER update_manager_settings CONSTANT)
@@ -728,9 +690,9 @@ public:
DivePlannerSettings *planner_settings;
UnitsSettings *unit_settings;
GeneralSettingsObjectWrapper *general_settings;
- DisplaySettingsObjectWrapper *display_settings;
+ qPrefDisplay *display_settings;
LanguageSettingsObjectWrapper *language_settings;
- AnimationsSettingsObjectWrapper *animation_settings;
+ qPrefAnimations *animation_settings;
LocationServiceSettingsObjectWrapper *location_settings;
UpdateManagerSettings *update_manager_settings;
DiveComputerSettings *dive_computer_settings;
diff --git a/desktop-widgets/preferences/preferences_defaults.cpp b/desktop-widgets/preferences/preferences_defaults.cpp
index e93848f17..a7b5e4c1d 100644
--- a/desktop-widgets/preferences/preferences_defaults.cpp
+++ b/desktop-widgets/preferences/preferences_defaults.cpp
@@ -88,11 +88,11 @@ 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());
+ auto animation = qPrefAnimations::instance();
+ animation->set_animation_speed(ui->velocitySlider->value());
}
diff --git a/packaging/ios/Subsurface-mobile.pro b/packaging/ios/Subsurface-mobile.pro
index cea7fdb28..1d0c473df 100644
--- a/packaging/ios/Subsurface-mobile.pro
+++ b/packaging/ios/Subsurface-mobile.pro
@@ -78,6 +78,7 @@ SOURCES += ../../subsurface-mobile-main.cpp \
../../core/connectionlistmodel.cpp \
../../core/qt-ble.cpp \
../../core/settings/qPref.cpp \
+ ../../core/settings/qPrefAnimations.cpp \
../../core/settings/qPrefDisplay.cpp \
../../core/subsurface-qt/CylinderObjectHelper.cpp \
../../core/subsurface-qt/DiveObjectHelper.cpp \
@@ -186,6 +187,7 @@ HEADERS += \
../../core/connectionlistmodel.h \
../../core/qt-ble.h \
../../core/settings/qPref.h \
+ ../../core/settings/qPrefAnimations.h \
../../core/settings/qPrefDisplay.h \
../../core/settings/qPref_private.h \
../../core/subsurface-qt/CylinderObjectHelper.h \
diff --git a/subsurface-helper.cpp b/subsurface-helper.cpp
index b533e7e91..92409cb81 100644
--- a/subsurface-helper.cpp
+++ b/subsurface-helper.cpp
@@ -28,6 +28,7 @@
#include "core/pluginmanager.h"
#endif
+#ifndef SUBSURFACE_TEST_DATA
QObject *qqWindowObject = NULL;
void init_ui()
@@ -39,14 +40,14 @@ void init_ui()
MainWindow *window = new MainWindow();
window->setTitle();
-#endif
+#endif // SUBSURFACE_MOBILE
}
void exit_ui()
{
#ifndef SUBSURFACE_MOBILE
delete MainWindow::instance();
-#endif
+#endif // SUBSURFACE_MOBILE
delete qApp;
free((void *)existing_filename);
}
@@ -57,45 +58,6 @@ double get_screen_dpi()
return mydesk->physicalDpiX();
}
-void register_qml_types()
-{
- int rc;
- rc = qmlRegisterType<qPref>("org.subsurfacedivelog.mobile", 1, 0, "SsrfPrefs");
- if (rc < 0)
- qDebug() << "ERROR: Cannot register Prefs (class qPref), QML will not work!!";
- rc = qmlRegisterType<qPrefDisplay>("org.subsurfacedivelog.mobile", 1, 0, "SsrfDisplayPrefs");
- if (rc < 0)
- qDebug() << "ERROR: Cannot register DisplayPrefs (class qPrefDisplay), QML will not work!!";
-
-#ifdef SUBSURFACE_MOBILE
- rc = qmlRegisterType<QMLManager>("org.subsurfacedivelog.mobile", 1, 0, "QMLManager");
- if (rc < 0)
- qDebug() << "ERROR: Cannot register QMLManager, QML will not work!!";
- rc = qmlRegisterType<QMLPrefs>("org.subsurfacedivelog.mobile", 1, 0, "QMLPrefs");
- if (rc < 0)
- qDebug() << "ERROR: Cannot register QMLPrefs, QML will not work!!";
- rc = qmlRegisterType<QMLProfile>("org.subsurfacedivelog.mobile", 1, 0, "QMLProfile");
- if (rc < 0)
- qDebug() << "ERROR: Cannot register QMLProfile, QML will not work!!";
- rc = qmlRegisterType<DownloadThread>("org.subsurfacedivelog.mobile", 1, 0, "DCDownloadThread");
- if (rc < 0)
- qDebug() << "ERROR: Cannot register DCDownloadThread, QML will not work!!";
- rc = qmlRegisterType<DiveImportedModel>("org.subsurfacedivelog.mobile", 1, 0, "DCImportModel");
- if (rc < 0)
- qDebug() << "ERROR: Cannot register DCImportModel, QML will not work!!";
-#endif
-
- rc = qmlRegisterType<MapWidgetHelper>("org.subsurfacedivelog.mobile", 1, 0, "MapWidgetHelper");
- if (rc < 0)
- qDebug() << "ERROR: Cannot register MapWidgetHelper, QML will not work!!";
- rc = qmlRegisterType<MapLocationModel>("org.subsurfacedivelog.mobile", 1, 0, "MapLocationModel");
- if (rc < 0)
- qDebug() << "ERROR: Cannot register MapLocationModel, QML will not work!!";
- rc = qmlRegisterType<MapLocation>("org.subsurfacedivelog.mobile", 1, 0, "MapLocation");
- if (rc < 0)
- qDebug() << "ERROR: Cannot register MapLocation, QML will not work!!";
-}
-
void run_ui()
{
@@ -115,7 +77,7 @@ void run_ui()
engine.addImportPath(importPath.replace("MacOS", "Frameworks"));
}
qDebug() << "QML import path" << engine.importPathList();
-#endif
+#endif // __APPLE__ not Q_OS_IOS
engine.addImportPath("qrc://imports");
DiveListModel diveListModel;
LOG_STP("run_ui diveListModel started");
@@ -167,11 +129,56 @@ void run_ui()
#if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS)
qml_window->setHeight(1200);
qml_window->setWidth(800);
-#endif
+#endif // not Q_OS_ANDROID and not Q_OS_IOS
qml_window->show();
LOG_STP("run_ui running exec");
#else
MainWindow::instance()->show();
-#endif
+#endif // SUBSURFACE_MOBILE
qApp->exec();
}
+#endif // not SUBSURFACE_TEST_DATA
+
+void register_qml_types()
+{
+ int rc;
+ rc = qmlRegisterType<qPref>("org.subsurfacedivelog.mobile", 1, 0, "SsrfPrefs");
+ if (rc < 0)
+ qDebug() << "ERROR: Cannot register SsrfPrefs (class qPref), QML will not work!!";
+ rc = qmlRegisterType<qPrefAnimations>("org.subsurfacedivelog.mobile", 1, 0, "SsrfAnimationsPrefs");
+ if (rc < 0)
+ qDebug() << "ERROR: Cannot register SsrfAnimationsPrefs (class qPrefAnimations), QML will not work!!";
+ rc = qmlRegisterType<qPrefDisplay>("org.subsurfacedivelog.mobile", 1, 0, "SsrfDisplayPrefs");
+ if (rc < 0)
+ qDebug() << "ERROR: Cannot register DisplayPrefs (class qPrefDisplay), QML will not work!!";
+
+#ifndef SUBSURFACE_TEST_DATA
+#ifdef SUBSURFACE_MOBILE
+ rc = qmlRegisterType<QMLManager>("org.subsurfacedivelog.mobile", 1, 0, "QMLManager");
+ if (rc < 0)
+ qDebug() << "ERROR: Cannot register QMLManager, QML will not work!!";
+ rc = qmlRegisterType<QMLPrefs>("org.subsurfacedivelog.mobile", 1, 0, "QMLPrefs");
+ if (rc < 0)
+ qDebug() << "ERROR: Cannot register QMLPrefs, QML will not work!!";
+ rc = qmlRegisterType<QMLProfile>("org.subsurfacedivelog.mobile", 1, 0, "QMLProfile");
+ if (rc < 0)
+ qDebug() << "ERROR: Cannot register QMLProfile, QML will not work!!";
+ rc = qmlRegisterType<DownloadThread>("org.subsurfacedivelog.mobile", 1, 0, "DCDownloadThread");
+ if (rc < 0)
+ qDebug() << "ERROR: Cannot register DCDownloadThread, QML will not work!!";
+ rc = qmlRegisterType<DiveImportedModel>("org.subsurfacedivelog.mobile", 1, 0, "DCImportModel");
+ if (rc < 0)
+ qDebug() << "ERROR: Cannot register DCImportModel, QML will not work!!";
+#endif // not SUBSURFACE_MOBILE
+
+ rc = qmlRegisterType<MapWidgetHelper>("org.subsurfacedivelog.mobile", 1, 0, "MapWidgetHelper");
+ if (rc < 0)
+ qDebug() << "ERROR: Cannot register MapWidgetHelper, QML will not work!!";
+ rc = qmlRegisterType<MapLocationModel>("org.subsurfacedivelog.mobile", 1, 0, "MapLocationModel");
+ if (rc < 0)
+ qDebug() << "ERROR: Cannot register MapLocationModel, QML will not work!!";
+ rc = qmlRegisterType<MapLocation>("org.subsurfacedivelog.mobile", 1, 0, "MapLocation");
+ if (rc < 0)
+ qDebug() << "ERROR: Cannot register MapLocation, QML will not work!!";
+#endif // not SUBSURFACE_TEST_DATA
+}
diff --git a/tests/.gitignore b/tests/.gitignore
new file mode 100644
index 000000000..86950b3e9
--- /dev/null
+++ b/tests/.gitignore
@@ -0,0 +1 @@
+*.qmlc
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index a9c65bd09..0f30bfecb 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -76,6 +76,18 @@ enable_testing()
add_definitions(-g)
add_definitions(-DSUBSURFACE_TEST_DATA="${SUBSURFACE_TEST_DATA}")
+# Build QML test runner
+# add_executable demands relative path, therefore ../
+add_executable(TestQML testqml.cpp ../subsurface-helper.cpp )
+target_link_libraries(
+ TestQML
+ subsurface_corelib
+ RESOURCE_LIBRARY
+ ${QT_TEST_LIBRARIES}
+ ${SUBSURFACE_LINK_LIBRARIES}
+)
+
+# SSRF test cases (TBD, convert to standard qTest setup)
TEST(TestUnitConversion testunitconversion.cpp)
TEST(TestProfile testprofile.cpp)
TEST(TestGpsCoords testgpscoords.cpp)
@@ -85,9 +97,12 @@ TEST(TestDiveSiteDuplication testdivesiteduplication.cpp)
TEST(TestRenumber testrenumber.cpp)
TEST(TestGitStorage testgitstorage.cpp)
TEST(TestPreferences testpreferences.cpp)
+TEST(TestQPrefDisplay testqPrefDisplay.cpp)
+TEST(TestQPrefAnimations testqPrefAnimations.cpp)
TEST(TestPicture testpicture.cpp)
TEST(TestMerge testmerge.cpp)
TEST(TestTagList testtaglist.cpp)
+add_test(NAME TestQML COMMAND $<TARGET_FILE:TestQML> ${SUBSURFACE_SOURCE}/tests)
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND}
@@ -99,11 +114,13 @@ add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND}
TestGitStorage
TestPlan
TestDiveSiteDuplication
+ TestQPrefDisplay
TestPreferences
TestRenumber
TestPicture
TestMerge
TestTagList
+ TestQML
)
# useful for debugging CMake issues
diff --git a/tests/testpreferences.cpp b/tests/testpreferences.cpp
index 585044fd0..d950c49f9 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 = 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 language = pref->language_settings;
language->setLangLocale ("en_US");
language->setLanguage ("en");
@@ -499,11 +482,6 @@ void TestPreferences::testPreferences()
TEST(language->dateFormatOverride(),true);
TEST(language->useSystemLanguage(), true);
- pref->animation_settings->setAnimationSpeed(20);
- TEST(pref->animation_settings->animationSpeed(), 20);
- pref->animation_settings->setAnimationSpeed(30);
- TEST(pref->animation_settings->animationSpeed(), 30);
-
auto location = pref->location_settings;
location->setTimeThreshold(10);
location->setDistanceThreshold(20);
diff --git a/tests/testqPrefAnimations.cpp b/tests/testqPrefAnimations.cpp
new file mode 100644
index 000000000..db0e31218
--- /dev/null
+++ b/tests/testqPrefAnimations.cpp
@@ -0,0 +1,81 @@
+// SPDX-License-Identifier: GPL-2.0
+#include "testqPrefAnimations.h"
+
+#include "core/settings/qPrefAnimations.h"
+#include "core/pref.h"
+#include "core/qthelper.h"
+
+#include <QDate>
+
+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());
+}
+
+QTEST_MAIN(TestQPrefAnimations)
diff --git a/tests/testqPrefAnimations.h b/tests/testqPrefAnimations.h
new file mode 100644
index 000000000..162baf8fd
--- /dev/null
+++ b/tests/testqPrefAnimations.h
@@ -0,0 +1,19 @@
+// SPDX-License-Identifier: GPL-2.0
+#ifndef TESTQPREFANIMATIONS_H
+#define TESTQPREFANIMATIONS_H
+
+#include <QtTest>
+
+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
new file mode 100644
index 000000000..5d510fe21
--- /dev/null
+++ b/tests/testqPrefDisplay.cpp
@@ -0,0 +1,133 @@
+// SPDX-License-Identifier: GPL-2.0
+#include "testqPrefDisplay.h"
+
+#include "core/settings/qPrefDisplay.h"
+#include "core/pref.h"
+#include "core/qthelper.h"
+
+#include <QDate>
+
+void TestQPrefDisplay::initTestCase()
+{
+ QCoreApplication::setOrganizationName("Subsurface");
+ QCoreApplication::setOrganizationDomain("subsurface.hohndel.org");
+ QCoreApplication::setApplicationName("SubsurfaceTestQPrefDisplay");
+}
+
+void TestQPrefDisplay::test_struct_get()
+{
+ // Test struct pref -> get func.
+
+ auto display = qPrefDisplay::instance();
+
+ 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
+
+ auto display = qPrefDisplay::instance();
+
+ 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();
+
+ 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
new file mode 100644
index 000000000..6af2d2be5
--- /dev/null
+++ b/tests/testqPrefDisplay.h
@@ -0,0 +1,19 @@
+// SPDX-License-Identifier: GPL-2.0
+#ifndef TESTQPREFDISPLAY_H
+#define TESTQPREFDISPLAY_H
+
+#include <QtTest>
+
+class TestQPrefDisplay : 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 // TESTQPREFDISPLAY_H
diff --git a/tests/testqml.cpp b/tests/testqml.cpp
new file mode 100644
index 000000000..0b75d8d48
--- /dev/null
+++ b/tests/testqml.cpp
@@ -0,0 +1,48 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <QQmlEngine>
+#include <QtQuickTest>
+#include <QtTest>
+#include <QQmlEngine>
+#include <QQmlContext>
+#include <QApplication>
+
+#include "core/settings/qPref.h"
+#include "core/qt-gui.h"
+
+// this is the content of QUICK_TEST_MAIN amended with
+// registration of ssrf classes
+int main(int argc, char **argv)
+{
+ // QML testing is not supported in the oldest Qt versions we support
+ // if running with Qt version less than 5.10 then skip test
+#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
+ QTEST_ADD_GPU_BLACKLIST_SUPPORT
+ QTEST_SET_MAIN_SOURCE_PATH
+
+ // 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) {
+ qDebug() << "ERROR: missing tst_* directory";
+ return -1;
+ }
+ // save tst_dir and pass rest to Qt
+ const char *tst_dir = argv[1];
+ for (int i = 1; i < argc; i++)
+ argv[i] = argv[i+1];
+ argc--;
+
+ // Register types
+ register_qml_types();
+
+ // Run all tst_*.qml files
+ return quick_test_main(argc, argv, "TestQML", tst_dir);
+#else
+ return 0;
+#endif
+}
diff --git a/tests/tst_qPref.qml b/tests/tst_qPref.qml
new file mode 100644
index 000000000..99b798423
--- /dev/null
+++ b/tests/tst_qPref.qml
@@ -0,0 +1,17 @@
+// SPDX-License-Identifier: GPL-2.0
+import QtQuick 2.6
+import QtTest 1.2
+import org.subsurfacedivelog.mobile 1.0
+
+TestCase {
+ name: "qPref"
+
+ SsrfPrefs {
+ id: prefs
+ }
+
+ function test_register() {
+ var x = prefs.mobile_version
+ compare(x, prefs.mobile_version)
+ }
+}
diff --git a/tests/tst_qPrefAnimations.qml b/tests/tst_qPrefAnimations.qml
new file mode 100644
index 000000000..01e59fa42
--- /dev/null
+++ b/tests/tst_qPrefAnimations.qml
@@ -0,0 +1,19 @@
+// 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
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")
+ }
+
+}