QuasarAppLib 1.0.530.c9fba11
isettings.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2018-2026 QuasarApp.
3 * Distributed under the lgplv3 software license, see the accompanying
4 * Everyone is permitted to copy and distribute verbatim copies
5 * of this license document, but changing it is not allowed.
6*/
7
8#ifndef ISETTINGS_H
9#define ISETTINGS_H
10
11#include "qaservice.h"
12#include "quasarapp_global.h"
13#include <QObject>
14#include <QVariant>
15
16class QSettings;
17
18namespace QuasarAppUtils {
19
23enum class SettingsSaveMode: quint64 {
28};
29
45class QUASARAPPSHARED_EXPORT ISettings : public QObject, public Service<ISettings>
46{
47 Q_OBJECT
48
49public:
54 ~ISettings() override;
55
63 Q_INVOKABLE QVariant getValue(const QString &key, const QVariant& def = {});
64
73 Q_INVOKABLE QString getStrValue(const QString &key, const QString& def = {});
74
78 Q_INVOKABLE void resetToDefault();
79
86 virtual bool ignoreToRest(const QString& key) const;
87
91 void sync();
92
97 void forceReloadCache();
98
104
109 void setMode(const SettingsSaveMode &mode);
110
116 static ISettings* instance();
117
127 static bool initService(std::unique_ptr<ISettings> obj);
128
129public slots:
135 void setValue(const QString &key, const QVariant& value);
136
142 void setStrValue(const QString& key, const QString& value);
143
144
145signals:
151 void valueChanged(QString key, QVariant value);
152
158 void valueStrChanged(QString key, QString value);
159
160protected:
161
163
185 virtual QHash<QString, QVariant> defaultSettings() = 0;
186
190 virtual void syncImplementation() = 0;
191
198 virtual QVariant getValueImplementation(const QString &key, const QVariant& def) = 0;
199
205 virtual void setValueImplementation(const QString key, const QVariant& value) = 0;
206
210 void clearCache();
211
218 QHash<QString, QVariant>& settingsMap();
219
220private:
221
223
224 QHash<QString, QVariant> _cache;
225 QHash<QString, QVariant> *_defaultConfig = nullptr;
226
227 friend class Service<ISettings>;
228};
229
230
231};
232
233
234#endif // ISETTINGS_H
virtual bool ignoreToRest(const QString &key) const
ignoreToRest This method should be returns true if the key setting is not be reset on the resetToDefa...
Definition isettings.cpp:85
static bool initService(std::unique_ptr< ISettings > obj)
initService This method initialize the global settings object.
Definition isettings.cpp:47
void sync()
sync This method save all settings data on a hard disk;
Definition isettings.cpp:89
void valueStrChanged(QString key, QString value)
valueStrChanged some as valueChanged(QString key, QVariant value) but value has ben converted to the ...
QHash< QString, QVariant > & settingsMap()
settingsMap This method returns initialized settings map. Settings map contains pairs with settings k...
Definition isettings.cpp:28
static ISettings * instance()
instance This method returns pointer to current settings object.
Definition isettings.cpp:43
virtual void syncImplementation()=0
syncImplementation This method should save all configuration data to the hard drive;
void setValue(const QString &key, const QVariant &value)
setValue This slot sets new value for a key setting
void valueChanged(QString key, QVariant value)
valueChanged This signal when value of the key settings changed
virtual QVariant getValueImplementation(const QString &key, const QVariant &def)=0
getValueImplementation This method will return the value of the settings.
virtual void setValueImplementation(const QString key, const QVariant &value)=0
setValueImplementation This slot will set a new value for the key parameter.
Q_INVOKABLE QString getStrValue(const QString &key, const QString &def={})
getStrValue some as getValue but convert result object to QString type.
Definition isettings.cpp:67
void clearCache()
clearCache This method clear all data from cache.
Definition isettings.cpp:24
ISettings(SettingsSaveMode mode=SettingsSaveMode::Auto)
Definition isettings.cpp:15
Q_INVOKABLE void resetToDefault()
resetToDefault This method reset all settings to default values.
Definition isettings.cpp:76
void forceReloadCache()
forceReloadCache This method force reload settings data from disk.
Definition isettings.cpp:97
void setMode(const SettingsSaveMode &mode)
setMode This method sets a new value of the settings mode.
Definition isettings.cpp:39
Q_INVOKABLE QVariant getValue(const QString &key, const QVariant &def={})
getValue This method return the value of the settings.
Definition isettings.cpp:51
SettingsSaveMode getMode() const
getMode This method return the current mode of the settings.
Definition isettings.cpp:35
virtual QHash< QString, QVariant > defaultSettings()=0
defaultSettings This method must be return default map of the settings and them values....
void setStrValue(const QString &key, const QString &value)
setStrValue This is some as setValue but working with the QString type.
The QuasarAppUtils namespace contains the base functions for all applications of the QuasarApp group....
SettingsSaveMode
The SettingsSaveMode enum.
Definition isettings.h:23
@ Auto
a settings will be saved on hard disk when called the Settings::setValue method.
Definition isettings.h:25
@ Manual
a settings will be saved on hard disk when called the Settings::Sync method.
Definition isettings.h:27
#define QUASARAPPSHARED_EXPORT