diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2018-07-14 08:15:23 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-07-14 08:16:14 -0700 |
commit | dc22747cb02caff55da809da234fd7ad1cf23f27 (patch) | |
tree | e9ac9a875c841974b10baa27fe58c41dfbbf1133 | |
parent | e834874a7a6f8e37fade28bf20640b8d0815373b (diff) | |
parent | f63217495d27c77b2f7f866caec568a19ee9543d (diff) | |
download | subsurface-dc22747cb02caff55da809da234fd7ad1cf23f27.tar.gz |
Merge branch 'qPrefAnimations' of https://github.com/janiversen/subsurface
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | core/CMakeLists.txt | 1 | ||||
-rw-r--r-- | core/settings/qPref.h | 3 | ||||
-rw-r--r-- | core/settings/qPrefAnimations.cpp | 20 | ||||
-rw-r--r-- | core/settings/qPrefAnimations.h | 38 | ||||
-rw-r--r-- | core/subsurface-qt/SettingsObjectWrapper.cpp | 23 | ||||
-rw-r--r-- | core/subsurface-qt/SettingsObjectWrapper.h | 21 | ||||
-rw-r--r-- | desktop-widgets/preferences/preferences_defaults.cpp | 4 | ||||
-rw-r--r-- | packaging/ios/Subsurface-mobile.pro | 2 | ||||
-rw-r--r-- | subsurface-helper.cpp | 5 | ||||
-rw-r--r-- | tests/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/testpreferences.cpp | 5 | ||||
-rw-r--r-- | tests/testqPrefAnimations.cpp | 81 | ||||
-rw-r--r-- | tests/testqPrefAnimations.h | 19 | ||||
-rw-r--r-- | tests/tst_qPrefAnimations.qml | 19 |
14 files changed, 191 insertions, 51 deletions
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.h b/core/settings/qPref.h index 70eef3cb3..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 { @@ -34,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/subsurface-qt/SettingsObjectWrapper.cpp b/core/subsurface-qt/SettingsObjectWrapper.cpp index c5a335a8e..e2fadd90c 100644 --- a/core/subsurface-qt/SettingsObjectWrapper.cpp +++ b/core/subsurface-qt/SettingsObjectWrapper.cpp @@ -2054,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) @@ -2127,7 +2106,7 @@ QObject(parent), general_settings(new GeneralSettingsObjectWrapper(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)) diff --git a/core/subsurface-qt/SettingsObjectWrapper.h b/core/subsurface-qt/SettingsObjectWrapper.h index a6a47a0a1..075227384 100644 --- a/core/subsurface-qt/SettingsObjectWrapper.h +++ b/core/subsurface-qt/SettingsObjectWrapper.h @@ -640,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) @@ -690,7 +673,7 @@ class SettingsObjectWrapper : public QObject { Q_PROPERTY(GeneralSettingsObjectWrapper* general MEMBER general_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) @@ -709,7 +692,7 @@ public: GeneralSettingsObjectWrapper *general_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 0df9ebde7..a7b5e4c1d 100644 --- a/desktop-widgets/preferences/preferences_defaults.cpp +++ b/desktop-widgets/preferences/preferences_defaults.cpp @@ -93,6 +93,6 @@ void PreferencesDefaults::syncSettings() 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 894c8a1b6..92409cb81 100644 --- a/subsurface-helper.cpp +++ b/subsurface-helper.cpp @@ -144,7 +144,10 @@ 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!!"; + 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!!"; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 771504794..0f30bfecb 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -98,6 +98,7 @@ 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) diff --git a/tests/testpreferences.cpp b/tests/testpreferences.cpp index 7a0fa64fd..d950c49f9 100644 --- a/tests/testpreferences.cpp +++ b/tests/testpreferences.cpp @@ -482,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/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) + } + +} |