-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.cpp
executable file
·59 lines (52 loc) · 1.25 KB
/
settings.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "settings.h"
Settings::Settings(bool inMemory)
{
this->isInMemory = inMemory;
if(this->isInMemory) {
return;
}
QDir settingsPath;
settingsPath.setPath(QCoreApplication::applicationDirPath());
settingsPath.mkdir(".cfg");
settingsPath.cd(".cfg");
this->settings = new QSettings(settingsPath.filePath(".config"), QSettings::IniFormat);
}
Settings::~Settings()
{
if(this->settings) {
delete this->settings;
}
}
QVariant Settings::get(QString key)
{
if(isInMemory) {
return this->inMemorySettings.value(key);
} else {
return this->settings->value(key, defaultSettings.value(key));
}
}
QVariant Settings::get(QString key, QVariant defVal)
{
if(isInMemory) {
return this->inMemorySettings.value(key, defVal);
} else {
return this->settings->value(key, defVal);
}
}
bool Settings::hasKey(QString key)
{
if(isInMemory) {
return this->inMemorySettings.contains(key);
} else {
return this->settings->contains(key);
}
}
void Settings::set(QString key, QVariant val)
{
if(isInMemory) {
this->inMemorySettings.insert(key, val);
} else {
this->settings->setValue(key, val);
this->settings->sync();
}
}