mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
c0e9e978a1
commit
3c3729711c
9 changed files with 46 additions and 25 deletions
|
@ -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
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// SPDX-License-Identifier: GPL-2.0
|
||||
#include "qPref_private.h"
|
||||
#include "qPrefPrivate.h"
|
||||
#include "qPref.h"
|
||||
#include "ssrf-version.h"
|
||||
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
11
core/settings/qPrefPrivate.cpp
Normal file
11
core/settings/qPrefPrivate.cpp
Normal file
|
@ -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;
|
||||
}
|
|
@ -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
|
|
@ -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 \
|
||||
|
|
Loading…
Add table
Reference in a new issue