QuasarAppLib
isettings.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2018-2025 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 {
25 Auto,
27 Manual
28};
29
45class QUASARAPPSHARED_EXPORT ISettings : public QObject, public Service<ISettings>
46{
47 Q_OBJECT
48
49public:
50 ~ISettings() override;
51
59 Q_INVOKABLE QVariant getValue(const QString &key, const QVariant& def = {});
60
69 Q_INVOKABLE QString getStrValue(const QString &key, const QString& def = {});
70
74 Q_INVOKABLE void resetToDefault();
75
82 virtual bool ignoreToRest(const QString& key) const;
83
87 void sync();
88
93 void forceReloadCache();
94
99 SettingsSaveMode getMode() const;
100
105 void setMode(const SettingsSaveMode &mode);
106
112 static ISettings* instance();
113
123 static bool initService(std::unique_ptr<ISettings> obj);
124
125public slots:
131 void setValue(const QString &key, const QVariant& value);
132
138 void setStrValue(const QString& key, const QString& value);
139
140
141signals:
147 void valueChanged(QString key, QVariant value);
148
154 void valueStrChanged(QString key, QString value);
155
156protected:
157
158 explicit ISettings(SettingsSaveMode mode = SettingsSaveMode::Auto);
159
181 virtual QHash<QString, QVariant> defaultSettings() = 0;
182
186 virtual void syncImplementation() = 0;
187
194 virtual QVariant getValueImplementation(const QString &key, const QVariant& def) = 0;
195
201 virtual void setValueImplementation(const QString key, const QVariant& value) = 0;
202
206 void clearCache();
207
214 QHash<QString, QVariant>& settingsMap();
215
216private:
217
218 SettingsSaveMode _mode = SettingsSaveMode::Auto;
219
220 QHash<QString, QVariant> _cache;
221 QHash<QString, QVariant> *_defaultConfig = nullptr;
222
223 friend class Service<ISettings>;
224};
225
226
227};
228
229
230#endif // ISETTINGS_H
The Settings class base interface for implementation settings backends. Available implementations: Se...
Definition isettings.h:46
void valueStrChanged(QString key, QString value)
valueStrChanged some as valueChanged(QString key, QVariant value) but value has ben converted to the ...
virtual void syncImplementation()=0
syncImplementation This method should save all configuration data to the hard drive;
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.
virtual QHash< QString, QVariant > defaultSettings()=0
The Service class is a template class for creating a singleton services objects. This is manual contr...
Definition qaservice.h:68
The QuasaraAppUtils class This lib include base functions for the all applications of QuasarApp group...
Definition helpdata.cpp:18
SettingsSaveMode
The SettingsSaveMode enum.
Definition isettings.h:23
@ Auto
a settings will be saved on hard disk when called the Settings::setValue method.
@ Manual
a settings will be saved on hard disk when called the Settings::Sync method.
#define QUASARAPPSHARED_EXPORT