QuasarAppLib/settings.cpp

55 lines
1.3 KiB
C++
Raw Normal View History

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>
#include <QCoreApplication>
2018-09-29 15:56:04 +03:00
using namespace QuasarAppUtils;
Settings::Settings() {
auto name = QCoreApplication::applicationName();
if (name.isEmpty()) {
name = "QuasarAppUtils";
}
_settings = new QSettings(name, QSettings::IniFormat);
2018-09-29 15:56:04 +03:00
}
Settings *Settings::initSettings() {
2018-09-29 15:56:04 +03:00
static Settings* res = new Settings();
return res;
}
Settings *Settings::get() {
return initSettings();
}
2018-09-29 15:56:04 +03:00
const Settings *Settings::getConst() {
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);
}