mirror of
				https://github.com/subsurface/subsurface.git
				synced 2025-02-19 22:16:15 +00:00 
			
		
		
		
	Merge branch 'qPrefAnimations' of https://github.com/janiversen/subsurface
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
		
						commit
						dc22747cb0
					
				
					 14 changed files with 191 additions and 51 deletions
				
			
		|  | @ -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. | ||||
|  |  | |||
|  | @ -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 | ||||
|  |  | |||
							
								
								
									
										20
									
								
								core/settings/qPrefAnimations.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								core/settings/qPrefAnimations.cpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -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); | ||||
							
								
								
									
										38
									
								
								core/settings/qPrefAnimations.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								core/settings/qPrefAnimations.h
									
										
									
									
									
										Normal file
									
								
							|  | @ -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 | ||||
|  | @ -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)) | ||||
|  |  | |||
|  | @ -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; | ||||
|  |  | |||
|  | @ -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()); | ||||
| } | ||||
|  |  | |||
|  | @ -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 \ | ||||
|  |  | |||
|  | @ -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!!"; | ||||
|  |  | |||
|  | @ -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) | ||||
|  |  | |||
|  | @ -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); | ||||
|  |  | |||
							
								
								
									
										81
									
								
								tests/testqPrefAnimations.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										81
									
								
								tests/testqPrefAnimations.cpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -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) | ||||
							
								
								
									
										19
									
								
								tests/testqPrefAnimations.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								tests/testqPrefAnimations.h
									
										
									
									
									
										Normal file
									
								
							|  | @ -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
 | ||||
							
								
								
									
										19
									
								
								tests/tst_qPrefAnimations.qml
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								tests/tst_qPrefAnimations.qml
									
										
									
									
									
										Normal file
									
								
							|  | @ -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) | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue