-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpreferences.cpp
43 lines (35 loc) · 891 Bytes
/
preferences.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
#include <QSettings>
#include <QString>
#include <QStringList>
#include "preferences.h"
static Preferences *inst;
Preferences::Preferences(): QObject() {
}
void Preferences::setValue(const QString &key, const QVariant &value) {
QSettings s;
s.setValue(QString("settings/") + key, value);
emit valueChanged(key);
}
QVariant Preferences::value(const QString &key, const QVariant &defaultValue) const {
QSettings s;
return s.value(QString("settings/") + key, defaultValue);
}
void Preferences::apply() {
QSettings s;
foreach (QString key, s.allKeys()) {
if (key.startsWith("settings/")) {
key = key.mid(9);
setValue(key, value(key));
}
}
}
Preferences *Preferences::instance() {
if (!inst) {
inst = new Preferences;
}
return inst;
}
void Preferences::close() {
delete inst;
inst = 0;
}