QuasarAppLib
settings.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2021-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
9#include "settings.h"
10#include <QSettings>
11#include <QCoreApplication>
12#include <QDebug>
13
14namespace QuasarAppUtils {
15
17 auto name = QCoreApplication::applicationName();
18 auto company = QCoreApplication::organizationName();
19 if (name.isEmpty()) {
20 name = "QuasarAppUtils";
21 }
22
23 if (company.isEmpty()) {
24 company = "QuasarApp";
25 }
26
27 _settings = new QSettings(QSettings::NativeFormat, QSettings::Scope::UserScope, company, name);
28}
29
31 return _settings->sync();
32}
33
35 if (isBool(key)) {
36 return _settings->value(key, def).toBool();
37 }
38
39 return _settings->value(key, def);
40}
41
43 return _settings->setValue(key, value);
44}
45
46bool Settings::ignoreToRest(const QString &) const {
47 return false;
48}
49
53
54bool Settings::isBool(const QString &) const {
55 return false;
56}
57
59{
60 return _boolOptions;
61}
62
67
69 return ISettings::initService(std::make_unique<Settings>());
70}
71
72}
static std::unique_ptr< ISettings > & initService()
initService This method initialize the Base object as a service.
Definition qaservice.h:81
bool ignoreToRest(const QString &) const override
ignoreToRest This method should be returns true if the key setting is not be reset on the resetToDefa...
Definition settings.cpp:46
const QSet< QString > & boolOptions() const
boolOptions returns current map with keys that has a bool type.
Definition settings.cpp:58
static bool initService()
initService This method initialize default object of the QuasarAppUtils::Settings type.
Definition settings.cpp:68
QVariant getValueImplementation(const QString &key, const QVariant &def) override
getValueImplementation This method will return the value of the settings.
Definition settings.cpp:34
virtual bool isBool(const QString &key) const
isBool This method should be return true if the key's type is bool. This is needed because QVariant w...
Definition settings.cpp:54
QHash< QString, QVariant > defaultSettings() override
Definition settings.cpp:50
void setBoolOptions(const QSet< QString > &newBoolOptions)
setBoolOptions This method sets new map of the boolean options.
Definition settings.cpp:63
void setValueImplementation(const QString key, const QVariant &value) override
setValueImplementation This slot will set a new value for the key parameter.
Definition settings.cpp:42
void syncImplementation() override
syncImplementation This method should save all configuration data to the hard drive;
Definition settings.cpp:30
The QuasaraAppUtils class This lib include base functions for the all applications of QuasarApp group...
Definition helpdata.cpp:18
void gen(int size, QByteArray &result)