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

Last change on this file since 5452 was 5452, checked in by mervart, 9 years ago
File size: 3.2 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 QString fullKey = _groupName.isEmpty() ? key : _groupName + '/' + key;
76 if (_app->_settings.contains(fullKey)) {
77 return _app->_settings[fullKey];
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 QString fullKey = _groupName.isEmpty() ? key : _groupName + '/' + key;
89 _app->_settings[fullKey] = value;
90}
91
92//
93////////////////////////////////////////////////////////////////////////////
94void t_settings::remove(const QString& key ) {
95 QMutexLocker locker(&_mutex);
96 QString fullKey = _groupName.isEmpty() ? key : _groupName + '/' + key;
97 _app->_settings.remove(fullKey);
98}
99
100//
101////////////////////////////////////////////////////////////////////////////
102void t_settings::sync() {
103 QMutexLocker locker(&_mutex);
104 QSettings settings(_app->confFileName(), QSettings::IniFormat);
105 settings.clear();
106 QMapIterator<QString, QVariant> it(_app->_settings);
107 while (it.hasNext()) {
108 it.next();
109 settings.setValue(it.key(), it.value());
110 }
111 settings.sync();
112}
113
114//
115////////////////////////////////////////////////////////////////////////////
116void t_settings::beginGroup(const QString& groupName) {
117 QMutexLocker locker(&_mutex);
118 _groupName = groupName;
119}
120
121//
122////////////////////////////////////////////////////////////////////////////
123void t_settings::endGroup() {
124 QMutexLocker locker(&_mutex);
125 _groupName.clear();
126}
Note: See TracBrowser for help on using the repository browser.