source: ntrip/trunk/GnssCenter/main/settings.cpp@ 5035

Last change on this file since 5035 was 5001, checked in by mervart, 11 years ago
File size: 2.8 KB
Line 
1/* -------------------------------------------------------------------------
2 * RTNet GUI
3 * -------------------------------------------------------------------------
4 *
5 * Class: t_settings
6 *
7 * Purpose: Subclasses the QSettings
8 *
9 * Author: L. Mervart
10 *
11 * Created: 05-Jan-2013
12 *
13 * Changes:
14 *
15 * -----------------------------------------------------------------------*/
16
17#include <QSettings>
18
19#include "settings.h"
20#include "app.h"
21
22using namespace GnssCenter;
23
24QMutex t_settings::_mutex; // static mutex
25
26// Constructor
27////////////////////////////////////////////////////////////////////////////
28t_settings::t_settings() {
29 QMutexLocker locker(&_mutex);
30
31 _app = static_cast<t_app*>(qApp);
32
33 // First fill the options
34 // ----------------------
35 if (_app->_settings.size() == 0) {
36 reRead();
37 }
38}
39
40// Destructor
41////////////////////////////////////////////////////////////////////////////
42t_settings::~t_settings() {
43}
44
45// (Re-)read the Options from File or Set the Defaults
46////////////////////////////////////////////////////////////////////////////
47void t_settings::reRead() {
48
49 _app->_settings.clear();
50
51 QSettings settings(_app->confFileName(), QSettings::IniFormat);
52
53 // Read from File
54 // --------------
55 if (settings.allKeys().size() > 0) {
56 QStringListIterator it(settings.allKeys());
57 while (it.hasNext()) {
58 QString key = it.next();
59 _app->_settings[key] = settings.value(key);
60 }
61 }
62
63 // Set Defaults
64 // ------------
65 else {
66
67 }
68}
69
70//
71////////////////////////////////////////////////////////////////////////////
72QVariant t_settings::value(const QString& key,
73 const QVariant& defaultValue) const {
74 QMutexLocker locker(&_mutex);
75
76 if (_app->_settings.contains(key)) {
77 return _app->_settings[key];
78 }
79 else {
80 return defaultValue;
81 }
82}
83
84//
85////////////////////////////////////////////////////////////////////////////
86void t_settings::setValue(const QString &key, const QVariant& value) {
87 QMutexLocker locker(&_mutex);
88 setValue_p(key, value);
89}
90
91//
92////////////////////////////////////////////////////////////////////////////
93void t_settings::setValue_p(const QString &key, const QVariant& value) {
94 _app->_settings[key] = value;
95}
96
97//
98////////////////////////////////////////////////////////////////////////////
99void t_settings::remove(const QString& key ) {
100 QMutexLocker locker(&_mutex);
101 _app->_settings.remove(key);
102}
103
104//
105////////////////////////////////////////////////////////////////////////////
106void t_settings::sync() {
107 QMutexLocker locker(&_mutex);
108 QSettings settings(_app->confFileName(), QSettings::IniFormat);
109 settings.clear();
110 QMapIterator<QString, QVariant> it(_app->_settings);
111 while (it.hasNext()) {
112 it.next();
113 settings.setValue(it.key(), it.value());
114 }
115 settings.sync();
116}
Note: See TracBrowser for help on using the repository browser.