source: ntrip/trunk/GnssCenter/src/settings.cpp@ 5001

Last change on this file since 5001 was 5001, checked in by mervart, 11 years ago
File size: 2.8 KB
RevLine 
[4814]1/* -------------------------------------------------------------------------
2 * RTNet GUI
3 * -------------------------------------------------------------------------
4 *
[4861]5 * Class: t_settings
[4814]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
[4861]19#include "settings.h"
20#include "app.h"
[4814]21
[5001]22using namespace GnssCenter;
[4814]23
[4861]24QMutex t_settings::_mutex; // static mutex
25
[4814]26// Constructor
27////////////////////////////////////////////////////////////////////////////
[4861]28t_settings::t_settings() {
[4814]29 QMutexLocker locker(&_mutex);
30
[4861]31 _app = static_cast<t_app*>(qApp);
[4814]32
33 // First fill the options
34 // ----------------------
[4861]35 if (_app->_settings.size() == 0) {
[4814]36 reRead();
37 }
38}
39
40// Destructor
41////////////////////////////////////////////////////////////////////////////
[4861]42t_settings::~t_settings() {
[4814]43}
44
45// (Re-)read the Options from File or Set the Defaults
46////////////////////////////////////////////////////////////////////////////
[4861]47void t_settings::reRead() {
[4814]48
[4861]49 _app->_settings.clear();
[4814]50
[4861]51 QSettings settings(_app->confFileName(), QSettings::IniFormat);
[4814]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();
[4861]59 _app->_settings[key] = settings.value(key);
[4814]60 }
61 }
62
63 // Set Defaults
64 // ------------
65 else {
66
67 }
68}
69
70//
71////////////////////////////////////////////////////////////////////////////
[4861]72QVariant t_settings::value(const QString& key,
[4814]73 const QVariant& defaultValue) const {
74 QMutexLocker locker(&_mutex);
75
[4861]76 if (_app->_settings.contains(key)) {
77 return _app->_settings[key];
[4814]78 }
79 else {
80 return defaultValue;
81 }
82}
83
84//
85////////////////////////////////////////////////////////////////////////////
[4861]86void t_settings::setValue(const QString &key, const QVariant& value) {
[4814]87 QMutexLocker locker(&_mutex);
88 setValue_p(key, value);
89}
90
91//
92////////////////////////////////////////////////////////////////////////////
[4861]93void t_settings::setValue_p(const QString &key, const QVariant& value) {
94 _app->_settings[key] = value;
[4814]95}
96
97//
98////////////////////////////////////////////////////////////////////////////
[4861]99void t_settings::remove(const QString& key ) {
[4814]100 QMutexLocker locker(&_mutex);
[4861]101 _app->_settings.remove(key);
[4814]102}
103
104//
105////////////////////////////////////////////////////////////////////////////
[4861]106void t_settings::sync() {
[4814]107 QMutexLocker locker(&_mutex);
[4861]108 QSettings settings(_app->confFileName(), QSettings::IniFormat);
[4814]109 settings.clear();
[4861]110 QMapIterator<QString, QVariant> it(_app->_settings);
[4814]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.