2018-09-29 15:56:04 +03:00
|
|
|
/*
|
2019-01-26 07:51:58 +03:00
|
|
|
* Copyright (C) 2018-2019 QuasarApp.
|
2018-09-29 15:56:04 +03:00
|
|
|
* Distributed under the lgplv3 software license, see the accompanying
|
|
|
|
* Everyone is permitted to copy and distribute verbatim copies
|
|
|
|
* of this license document, but changing it is not allowed.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "settings.h"
|
|
|
|
#include <QSettings>
|
2019-09-23 18:36:29 +03:00
|
|
|
#include <QCoreApplication>
|
2018-09-29 15:56:04 +03:00
|
|
|
|
|
|
|
using namespace QuasarAppUtils;
|
|
|
|
|
|
|
|
Settings::Settings() {
|
2019-09-23 18:36:29 +03:00
|
|
|
auto name = QCoreApplication::applicationName();
|
|
|
|
if (name.isEmpty()) {
|
|
|
|
name = "QuasarAppUtils";
|
|
|
|
}
|
|
|
|
|
|
|
|
_settings = new QSettings(name, QSettings::IniFormat);
|
2018-09-29 15:56:04 +03:00
|
|
|
}
|
|
|
|
|
2019-09-23 18:36:29 +03:00
|
|
|
Settings *Settings::initSettings() {
|
2018-09-29 15:56:04 +03:00
|
|
|
static Settings* res = new Settings();
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2019-09-23 18:36:29 +03:00
|
|
|
Settings *Settings::get() {
|
|
|
|
return initSettings();
|
|
|
|
}
|
|
|
|
|
2018-09-29 15:56:04 +03:00
|
|
|
const Settings *Settings::getConst() {
|
2019-09-23 18:36:29 +03:00
|
|
|
return initSettings();
|
2018-09-29 15:56:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
QVariant Settings::getValue(const QString &key, const QVariant &def) {
|
|
|
|
return _settings->value(key, def);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Settings::getStrValue(const QString &key, const QString &def) {
|
|
|
|
return getValue(key, QVariant(def)).toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Settings::setValue(const QString key, const QVariant &value) {
|
|
|
|
_settings->setValue(key, value);
|
|
|
|
|
|
|
|
emit valueChanged(key, value);
|
|
|
|
emit valueStrChanged(key, value.toString());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void Settings::setStrValue(const QString &key, const QString &value) {
|
|
|
|
setValue(key, value);
|
|
|
|
}
|