Avoid complex types as statics.
[dorian] / model / settings.cpp
1 #include <QSettings>
2
3 #include "settings.h"
4
5 static Settings *theInstance;
6
7 Settings::Settings(QObject *parent) :
8     QObject(parent)
9 {
10 }
11
12 Settings *Settings::instance()
13 {
14     if (!theInstance) {
15         theInstance = new Settings();
16     }
17     return theInstance;
18 }
19
20 void Settings::close()
21 {
22     delete theInstance;
23     theInstance = 0;
24 }
25
26 void Settings::setValue(const QString &key, const QVariant &value)
27 {
28     QSettings s;
29     s.setValue(QString("settings/") + key, value);
30     emit valueChanged(key);
31 }
32
33 QVariant Settings::value(const QString &key, const QVariant &defaultValue) const
34 {
35     QSettings s;
36     return s.value(QString("settings/") + key, defaultValue);
37 }