diff options
author | jan Iversen <jani@apache.org> | 2018-07-17 15:22:51 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-07-18 10:40:08 -0700 |
commit | 3c3729711c86a621b425370fd11d4271e4208f1b (patch) | |
tree | 6d689f6b3ce4e24997d1a79e63e3039eef8c7642 | |
parent | c0e9e978a1aa70713f9478391ebde353708a2f07 (diff) | |
download | subsurface-3c3729711c86a621b425370fd11d4271e4208f1b.tar.gz |
core: remove QSettings in qPref* and use a shared variable
Add qPrefPrivate class which contains one QSettings variable,
delete QSettings from qPref* class definitions
this secures there are only instance of QSettings
(QSettings needs to be in a QObject class to work)
Signed-off-by: Jan Iversen <jani@apache.org>
-rw-r--r-- | core/CMakeLists.txt | 1 | ||||
-rw-r--r-- | core/settings/qPref.cpp | 2 | ||||
-rw-r--r-- | core/settings/qPrefAnimations.cpp | 5 | ||||
-rw-r--r-- | core/settings/qPrefAnimations.h | 4 | ||||
-rw-r--r-- | core/settings/qPrefDisplay.cpp | 4 | ||||
-rw-r--r-- | core/settings/qPrefDisplay.h | 4 | ||||
-rw-r--r-- | core/settings/qPrefPrivate.cpp | 11 | ||||
-rw-r--r-- | core/settings/qPrefPrivate.h (renamed from core/settings/qPref_private.h) | 37 | ||||
-rw-r--r-- | packaging/ios/Subsurface-mobile.pro | 3 |
9 files changed, 46 insertions, 25 deletions
diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 5b476c779..9a7d108c5 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -102,6 +102,7 @@ set(SUBSURFACE_CORE_LIB_SRCS settings/qPref.cpp settings/qPrefAnimations.cpp settings/qPrefDisplay.cpp + settings/qPrefPrivate.cpp #Subsurface Qt have the Subsurface structs QObjectified for easy access via QML. subsurface-qt/DiveObjectHelper.cpp diff --git a/core/settings/qPref.cpp b/core/settings/qPref.cpp index 027d4af5a..1605e30df 100644 --- a/core/settings/qPref.cpp +++ b/core/settings/qPref.cpp @@ -1,5 +1,5 @@ // SPDX-License-Identifier: GPL-2.0 -#include "qPref_private.h" +#include "qPrefPrivate.h" #include "qPref.h" #include "ssrf-version.h" diff --git a/core/settings/qPrefAnimations.cpp b/core/settings/qPrefAnimations.cpp index a6ecc1d5b..9be8900c5 100644 --- a/core/settings/qPrefAnimations.cpp +++ b/core/settings/qPrefAnimations.cpp @@ -1,7 +1,8 @@ // SPDX-License-Identifier: GPL-2.0 #include "qPref.h" -#include "qPref_private.h" -#include "qPrefAnimations.h" +#include "qPrefPrivate.h" + +static const QString group = QStringLiteral("Animations"); qPrefAnimations::qPrefAnimations(QObject *parent) : QObject(parent) { diff --git a/core/settings/qPrefAnimations.h b/core/settings/qPrefAnimations.h index fb58b207e..4971aa06d 100644 --- a/core/settings/qPrefAnimations.h +++ b/core/settings/qPrefAnimations.h @@ -3,7 +3,6 @@ #define QPREFANIMATIONS_H #include <QObject> -#include <QSettings> class qPrefAnimations : public QObject { Q_OBJECT @@ -28,9 +27,6 @@ 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); }; diff --git a/core/settings/qPrefDisplay.cpp b/core/settings/qPrefDisplay.cpp index a248294d1..55a0129a9 100644 --- a/core/settings/qPrefDisplay.cpp +++ b/core/settings/qPrefDisplay.cpp @@ -1,11 +1,13 @@ // SPDX-License-Identifier: GPL-2.0 #include "qPref.h" -#include "qPref_private.h" +#include "qPrefPrivate.h" #include "core/subsurface-string.h" #include <QApplication> #include <QFont> +static const QString group = QStringLiteral("Display"); + qPrefDisplay::qPrefDisplay(QObject *parent) : QObject(parent) { } diff --git a/core/settings/qPrefDisplay.h b/core/settings/qPrefDisplay.h index 4a1c0ada5..cb6b872f9 100644 --- a/core/settings/qPrefDisplay.h +++ b/core/settings/qPrefDisplay.h @@ -3,7 +3,6 @@ #define QPREFDISPLAY_H #include <QObject> -#include <QSettings> class qPrefDisplay : public QObject { Q_OBJECT @@ -44,9 +43,6 @@ signals: void theme_changed(const QString& value); private: - const QString group = QStringLiteral("Display"); - QSettings setting; - // functions to load/sync variable with disk void disk_divelist_font(bool doSync); void disk_font_size(bool doSync); diff --git a/core/settings/qPrefPrivate.cpp b/core/settings/qPrefPrivate.cpp new file mode 100644 index 000000000..53b99c4e5 --- /dev/null +++ b/core/settings/qPrefPrivate.cpp @@ -0,0 +1,11 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "qPrefPrivate.h" + +qPrefPrivate::qPrefPrivate(QObject *parent) : QObject(parent) +{ +} +qPrefPrivate *qPrefPrivate::instance() +{ + static qPrefPrivate *self = new qPrefPrivate; + return self; +} diff --git a/core/settings/qPref_private.h b/core/settings/qPrefPrivate.h index de06029fa..e4131e9e4 100644 --- a/core/settings/qPref_private.h +++ b/core/settings/qPrefPrivate.h @@ -9,6 +9,19 @@ #include <QObject> #include "core/qthelper.h" +// implementation class of the interface classes +class qPrefPrivate : public QObject { + Q_OBJECT + +public: + static qPrefPrivate *instance(); + + QSettings setting; + +private: + qPrefPrivate(QObject *parent = NULL); +}; + //****** Macros to be used in the set functions ****** #define COPY_TXT(name, string) \ { \ @@ -20,49 +33,49 @@ #define LOADSYNC_BOOL(name, field) \ { \ if (doSync) \ - setting.setValue(group + name, prefs.field); \ + qPrefPrivate::instance()->setting.setValue(group + name, prefs.field); \ else \ - prefs.field = setting.value(group + name, default_prefs.field).toBool(); \ + prefs.field = qPrefPrivate::instance()->setting.value(group + name, default_prefs.field).toBool(); \ } #define LOADSYNC_DOUBLE(name, field) \ { \ if (doSync) \ - setting.setValue(group + name, prefs.field); \ + qPrefPrivate::instance()->setting.setValue(group + name, prefs.field); \ else \ - prefs.field = setting.value(group + name, default_prefs.field).toDouble(); \ + prefs.field = qPrefPrivate::instance()->setting.value(group + name, default_prefs.field).toDouble(); \ } #define LOADSYNC_ENUM(name, type, field) \ { \ if (doSync) \ - setting.setValue(group + name, prefs.field); \ + qPrefPrivate::instance()->setting.setValue(group + name, prefs.field); \ else \ - prefs.field = (enum type)setting.value(group + name, default_prefs.field).toInt(); \ + prefs.field = (enum type)qPrefPrivate::instance()->setting.value(group + name, default_prefs.field).toInt(); \ } #define LOADSYNC_INT(name, field) \ { \ if (doSync) \ - setting.setValue(group + name, prefs.field); \ + qPrefPrivate::instance()->setting.setValue(group + name, prefs.field); \ else \ - prefs.field = setting.value(group + name, default_prefs.field).toInt(); \ + prefs.field = qPrefPrivate::instance()->setting.value(group + name, default_prefs.field).toInt(); \ } #define LOADSYNC_INT_DEF(name, field, defval) \ { \ if (doSync) \ - setting.setValue(group + name, prefs.field); \ + qPrefPrivate::instance()->setting.setValue(group + name, prefs.field); \ else \ - prefs.field = setting.value(group + name, defval).toInt(); \ + prefs.field = qPrefPrivate::instance()->setting.value(group + name, defval).toInt(); \ } #define LOADSYNC_TXT(name, field) \ { \ if (doSync) \ - setting.setValue(group + name, prefs.field); \ + qPrefPrivate::instance()->setting.setValue(group + name, prefs.field); \ else \ - prefs.field = copy_qstring(setting.value(group + name, default_prefs.field).toString()); \ + prefs.field = copy_qstring(qPrefPrivate::instance()->setting.value(group + name, default_prefs.field).toString()); \ } //******* Macros to generate disk function diff --git a/packaging/ios/Subsurface-mobile.pro b/packaging/ios/Subsurface-mobile.pro index 1d0c473df..c4ce9e93e 100644 --- a/packaging/ios/Subsurface-mobile.pro +++ b/packaging/ios/Subsurface-mobile.pro @@ -80,6 +80,7 @@ SOURCES += ../../subsurface-mobile-main.cpp \ ../../core/settings/qPref.cpp \ ../../core/settings/qPrefAnimations.cpp \ ../../core/settings/qPrefDisplay.cpp \ + ../../core/settings/qPrefPrivate.cpp \ ../../core/subsurface-qt/CylinderObjectHelper.cpp \ ../../core/subsurface-qt/DiveObjectHelper.cpp \ ../../core/subsurface-qt/SettingsObjectWrapper.cpp \ @@ -189,7 +190,7 @@ HEADERS += \ ../../core/settings/qPref.h \ ../../core/settings/qPrefAnimations.h \ ../../core/settings/qPrefDisplay.h \ - ../../core/settings/qPref_private.h \ + ../../core/settings/qPrefPrivate.h \ ../../core/subsurface-qt/CylinderObjectHelper.h \ ../../core/subsurface-qt/DiveObjectHelper.h \ ../../core/subsurface-qt/SettingsObjectWrapper.h \ |