mirror of
				https://github.com/subsurface/subsurface.git
				synced 2025-02-19 22:16:15 +00:00 
			
		
		
		
	core: add qPref.h_and qPrefprivate.h
add 2 header files and 1 cpp file (qPrefPrivate does not have an implementation) The rewrite/consoliadation of SettingsObjectWrapper, qmlmanager, qmlpref and planner needs a place to put common private parts (qPrefPrivate) and 1 common class (qPref). Signed-off-by: Jan Iversen <jani@apache.org>
This commit is contained in:
		
							parent
							
								
									6c9c2168e1
								
							
						
					
					
						commit
						d02a03983d
					
				
					 5 changed files with 121 additions and 0 deletions
				
			
		| 
						 | 
					@ -98,6 +98,9 @@ set(SUBSURFACE_CORE_LIB_SRCS
 | 
				
			||||||
	windowtitleupdate.cpp
 | 
						windowtitleupdate.cpp
 | 
				
			||||||
	worldmap-save.c
 | 
						worldmap-save.c
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						# classes to manage struct preferences for QWidget and QML
 | 
				
			||||||
 | 
						settings/qPref.cpp
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	#Subsurface Qt have the Subsurface structs QObjectified for easy access via QML.
 | 
						#Subsurface Qt have the Subsurface structs QObjectified for easy access via QML.
 | 
				
			||||||
	subsurface-qt/DiveObjectHelper.cpp
 | 
						subsurface-qt/DiveObjectHelper.cpp
 | 
				
			||||||
	subsurface-qt/CylinderObjectHelper.cpp
 | 
						subsurface-qt/CylinderObjectHelper.cpp
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										18
									
								
								core/settings/qPref.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								core/settings/qPref.cpp
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,18 @@
 | 
				
			||||||
 | 
					// SPDX-License-Identifier: GPL-2.0
 | 
				
			||||||
 | 
					#include "qPref_private.h"
 | 
				
			||||||
 | 
					#include "qPref.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					qPref *qPref::m_instance = NULL;
 | 
				
			||||||
 | 
					qPref *qPref::instance()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if (!m_instance)
 | 
				
			||||||
 | 
							m_instance = new qPref;
 | 
				
			||||||
 | 
						return m_instance;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void qPref::loadSync(bool doSync)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										25
									
								
								core/settings/qPref.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								core/settings/qPref.h
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,25 @@
 | 
				
			||||||
 | 
					// SPDX-License-Identifier: GPL-2.0
 | 
				
			||||||
 | 
					#ifndef QPREF_H
 | 
				
			||||||
 | 
					#define QPREF_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <QObject>
 | 
				
			||||||
 | 
					#include "core/pref.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class qPref : public QObject {
 | 
				
			||||||
 | 
						Q_OBJECT
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public:
 | 
				
			||||||
 | 
						qPref(QObject *parent = NULL) : QObject(parent) {};
 | 
				
			||||||
 | 
						~qPref() {};
 | 
				
			||||||
 | 
						static qPref *instance();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Load/Sync local settings (disk) and struct preference
 | 
				
			||||||
 | 
						void loadSync(bool doSync);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					private:
 | 
				
			||||||
 | 
						static qPref *m_instance;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
							
								
								
									
										72
									
								
								core/settings/qPref_private.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										72
									
								
								core/settings/qPref_private.h
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,72 @@
 | 
				
			||||||
 | 
					// SPDX-License-Identifier: GPL-2.0
 | 
				
			||||||
 | 
					#ifndef QPREFPRIVATE_H
 | 
				
			||||||
 | 
					#define QPREFPRIVATE_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Header used by all qPref<class> implementations to avoid duplicating code
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <QObject>
 | 
				
			||||||
 | 
					#include <QSettings>
 | 
				
			||||||
 | 
					#include <QVariant>
 | 
				
			||||||
 | 
					#include "core/qthelper.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define COPY_TXT(name, string) \
 | 
				
			||||||
 | 
					{ \
 | 
				
			||||||
 | 
						free((void *)prefs.name); \
 | 
				
			||||||
 | 
						prefs.name = copy_qstring(string); \
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define LOADSYNC_INT(name, field) \
 | 
				
			||||||
 | 
					{ \
 | 
				
			||||||
 | 
						QSettings s; \
 | 
				
			||||||
 | 
						if (doSync) \
 | 
				
			||||||
 | 
							s.setValue(group + name, prefs.field); \
 | 
				
			||||||
 | 
						else \
 | 
				
			||||||
 | 
							prefs.field = s.value(group + name, default_prefs.field).toInt(); \
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define LOADSYNC_INT_DEF(name, field, defval) \
 | 
				
			||||||
 | 
					{ \
 | 
				
			||||||
 | 
						QSettings s; \
 | 
				
			||||||
 | 
						if (doSync)	\
 | 
				
			||||||
 | 
							s.setValue(group + name, prefs.field); \
 | 
				
			||||||
 | 
						else \
 | 
				
			||||||
 | 
							prefs.field = s.value(group + name, defval).toInt(); \
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define LOADSYNC_ENUM(name, type, field) \
 | 
				
			||||||
 | 
					{ \
 | 
				
			||||||
 | 
						QSettings s; \
 | 
				
			||||||
 | 
						if (doSync)	\
 | 
				
			||||||
 | 
							s.setValue(group + name, prefs.field); \
 | 
				
			||||||
 | 
						else \
 | 
				
			||||||
 | 
							prefs.field = (enum type)s.value(group + name, default_prefs.field).toInt(); \
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define LOADSYNC_BOOL(name, field) \
 | 
				
			||||||
 | 
					{ \
 | 
				
			||||||
 | 
						QSettings s; \
 | 
				
			||||||
 | 
						if (doSync)	\
 | 
				
			||||||
 | 
							s.setValue(group + name, prefs.field); \
 | 
				
			||||||
 | 
						else \
 | 
				
			||||||
 | 
							prefs.field = s.value(group + name, default_prefs.field).toBool(); \
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define LOADSYNC_DOUBLE(name, field) \
 | 
				
			||||||
 | 
					{ \
 | 
				
			||||||
 | 
						QSettings s; \
 | 
				
			||||||
 | 
						if (doSync)	\
 | 
				
			||||||
 | 
							s.setValue(group + name, prefs.field); \
 | 
				
			||||||
 | 
						else \
 | 
				
			||||||
 | 
							prefs.field = s.value(group + name, default_prefs.field).toDouble(); \
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define LOADSYNC_TXT(name, field) \
 | 
				
			||||||
 | 
					{ \
 | 
				
			||||||
 | 
						QSettings s; \
 | 
				
			||||||
 | 
						if (doSync)	\
 | 
				
			||||||
 | 
							s.setValue(group + name, prefs.field); \
 | 
				
			||||||
 | 
						else \
 | 
				
			||||||
 | 
							prefs.field = copy_qstring(s.value(group + name, default_prefs.field).toString()); \
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
| 
						 | 
					@ -77,6 +77,7 @@ SOURCES += ../../subsurface-mobile-main.cpp \
 | 
				
			||||||
	../../core/btdiscovery.cpp \
 | 
						../../core/btdiscovery.cpp \
 | 
				
			||||||
	../../core/connectionlistmodel.cpp \
 | 
						../../core/connectionlistmodel.cpp \
 | 
				
			||||||
	../../core/qt-ble.cpp \
 | 
						../../core/qt-ble.cpp \
 | 
				
			||||||
 | 
						../../core/settings/qPref.cpp \
 | 
				
			||||||
	../../core/subsurface-qt/CylinderObjectHelper.cpp \
 | 
						../../core/subsurface-qt/CylinderObjectHelper.cpp \
 | 
				
			||||||
	../../core/subsurface-qt/DiveObjectHelper.cpp \
 | 
						../../core/subsurface-qt/DiveObjectHelper.cpp \
 | 
				
			||||||
	../../core/subsurface-qt/SettingsObjectWrapper.cpp \
 | 
						../../core/subsurface-qt/SettingsObjectWrapper.cpp \
 | 
				
			||||||
| 
						 | 
					@ -183,6 +184,8 @@ HEADERS += \
 | 
				
			||||||
	../../core/btdiscovery.h \
 | 
						../../core/btdiscovery.h \
 | 
				
			||||||
	../../core/connectionlistmodel.h \
 | 
						../../core/connectionlistmodel.h \
 | 
				
			||||||
	../../core/qt-ble.h \
 | 
						../../core/qt-ble.h \
 | 
				
			||||||
 | 
						../../core/settings/qPref.h \
 | 
				
			||||||
 | 
						../../core/settings/qPref_private.h \
 | 
				
			||||||
	../../core/subsurface-qt/CylinderObjectHelper.h \
 | 
						../../core/subsurface-qt/CylinderObjectHelper.h \
 | 
				
			||||||
	../../core/subsurface-qt/DiveObjectHelper.h \
 | 
						../../core/subsurface-qt/DiveObjectHelper.h \
 | 
				
			||||||
	../../core/subsurface-qt/SettingsObjectWrapper.h \
 | 
						../../core/subsurface-qt/SettingsObjectWrapper.h \
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue