diff options
author | jan Iversen <jani@apache.org> | 2018-07-15 18:15:40 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-07-25 08:35:04 -0700 |
commit | 0002cd2d202c45d520f115280f98ba94c0028815 (patch) | |
tree | 8c32db430f9d1f6433c2da4a5bc394f262288478 /core | |
parent | 69c7ed676a7c7806f4132a899f98650fa2ad3dfb (diff) | |
download | subsurface-0002cd2d202c45d520f115280f98ba94c0028815.tar.gz |
core: create qPrefDiveComputer from SettingsObjectWrapper
Update set/get functions to follow common name scheme:
- get function have same name as in struct diveComputer
- set function have set_<name>
- signal function have <name>_changed
one class one .h/.cpp is the C++ idiom. Having load/sync of each
variable in 1 functions (in contrast to the distributed way
SettingsObjectWrapper handles it) secures the same storage name
is used. Having the set/get/load/sync functions grouped together
makes it easier to get an overview.
REMARK: this commit only defines the class, it is not active in production
Signed-off-by: Jan Iversen <jani@apache.org>
Diffstat (limited to 'core')
-rw-r--r-- | core/CMakeLists.txt | 1 | ||||
-rw-r--r-- | core/settings/qPref.h | 1 | ||||
-rw-r--r-- | core/settings/qPrefDiveComputer.cpp | 34 | ||||
-rw-r--r-- | core/settings/qPrefDiveComputer.h | 55 | ||||
-rw-r--r-- | core/settings/qPrefPrivate.h | 1 |
5 files changed, 92 insertions, 0 deletions
diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 577c496c9..c14ad1aa6 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -103,6 +103,7 @@ set(SUBSURFACE_CORE_LIB_SRCS settings/qPrefAnimations.cpp settings/qPrefCloudStorage.cpp settings/qPrefDisplay.cpp + settings/qPrefDiveComputer.cpp settings/qPrefPrivate.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 571fa2698..6afd1a87a 100644 --- a/core/settings/qPref.h +++ b/core/settings/qPref.h @@ -8,6 +8,7 @@ #include "qPrefAnimations.h" #include "qPrefCloudStorage.h" #include "qPrefDisplay.h" +#include "qPrefDiveComputer.h" class qPref : public QObject { Q_OBJECT diff --git a/core/settings/qPrefDiveComputer.cpp b/core/settings/qPrefDiveComputer.cpp new file mode 100644 index 000000000..04928dbfb --- /dev/null +++ b/core/settings/qPrefDiveComputer.cpp @@ -0,0 +1,34 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "qPref.h" +#include "qPrefPrivate.h" + +static const QString group = QStringLiteral("DiveComputer"); + +qPrefDiveComputer::qPrefDiveComputer(QObject *parent) : QObject(parent) +{ +} +qPrefDiveComputer *qPrefDiveComputer::instance() +{ + static qPrefDiveComputer *self = new qPrefDiveComputer; + return self; +} + + +void qPrefDiveComputer::loadSync(bool doSync) +{ + disk_device(doSync); + disk_device_name(doSync); + disk_download_mode(doSync); + disk_product(doSync); + disk_vendor(doSync); +} + +HANDLE_PREFERENCE_TXT_EXT(DiveComputer, "/dive_computer_device", device, dive_computer.); + +HANDLE_PREFERENCE_TXT_EXT(DiveComputer, "/dive_computer_device_name", device_name, dive_computer.); + +HANDLE_PREFERENCE_INT_EXT(DiveComputer, "/dive_computer_download_mode", download_mode, dive_computer.); + +HANDLE_PREFERENCE_TXT_EXT(DiveComputer, "/dive_computer_product", product, dive_computer.); + +HANDLE_PREFERENCE_TXT_EXT(DiveComputer, "/dive_computer_vendor", vendor, dive_computer.); diff --git a/core/settings/qPrefDiveComputer.h b/core/settings/qPrefDiveComputer.h new file mode 100644 index 000000000..8a80ee3ca --- /dev/null +++ b/core/settings/qPrefDiveComputer.h @@ -0,0 +1,55 @@ +// SPDX-License-Identifier: GPL-2.0 +#ifndef QPREFSDIVECOMPUTER_H +#define QPREFSDIVECOMPUTER_H +#include "core/pref.h" + +#include <QObject> + +class qPrefDiveComputer : public QObject { + Q_OBJECT + Q_PROPERTY(QString device READ device WRITE set_device NOTIFY device_changed); + Q_PROPERTY(QString device_name READ device_name WRITE set_device_name NOTIFY device_name_changed); + Q_PROPERTY(int download_mode READ download_mode WRITE set_download_mode NOTIFY download_mode_changed); + Q_PROPERTY(QString product READ product WRITE set_product NOTIFY product_changed); + Q_PROPERTY(QString vendor READ vendor WRITE set_vendor NOTIFY vendor_changed); + +public: + qPrefDiveComputer(QObject *parent = NULL); + static qPrefDiveComputer *instance(); + + // Load/Sync local settings (disk) and struct preference + void loadSync(bool doSync); + void inline load() {loadSync(false); } + void inline sync() {loadSync(true); } + +public: + static inline const QString& device() {return prefs.dive_computer.device; }; + static inline const QString& device_name() {return prefs.dive_computer.device_name; }; + static inline int download_mode() {return prefs.dive_computer.download_mode; }; + static inline const QString& product() {return prefs.dive_computer.product; }; + static inline const QString& vendor() {return prefs.dive_computer.vendor; }; + +public slots: + void set_device(const QString& device); + void set_device_name(const QString& device_name); + void set_download_mode(int mode); + void set_product(const QString& product); + void set_vendor(const QString& vendor); + +signals: + void device_changed(const QString& device); + void device_name_changed(const QString& device_name); + void download_mode_changed(int mode); + void product_changed(const QString& product); + void vendor_changed(const QString& vendor); + +private: + // functions to load/sync variable with disk + void disk_device(bool doSync); + void disk_device_name(bool doSync); + void disk_download_mode(bool doSync); + void disk_product(bool doSync); + void disk_vendor(bool doSync); +}; + +#endif diff --git a/core/settings/qPrefPrivate.h b/core/settings/qPrefPrivate.h index 804c6921b..da80f6a4b 100644 --- a/core/settings/qPrefPrivate.h +++ b/core/settings/qPrefPrivate.h @@ -17,6 +17,7 @@ public: friend class qPrefAnimations; friend class qPrefCloudStorage; friend class qPrefDisplay; + friend class qPrefDiveComputer; private: static qPrefPrivate *instance(); |