NorMIT-nav  22.09
An IGT application
cxSettings.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 #include "cxSettings.h"
12 #include "cxTypeConversions.h"
13 #include <iostream>
14 //#include "cxDataLocations.h"
15 #include "cxProfile.h"
16 
17 namespace cx
18 {
19 
20 //Settings *Settings::mInstance = NULL;
22 {
23  return profile()->getSettings();
24 }
25 
27 {
28 }
29 
31 {
32 }
33 
34 void Settings::resetFile(QString filename)
35 {
36  QStringList keys;
37  if (mSettings)
38  keys << mSettings->allKeys();
39 
40  mSettings.reset(new QSettings(filename, QSettings::IniFormat));
41 
42  if (mSettings)
43  keys << mSettings->allKeys();
44 
45  keys.removeDuplicates();
46 
47  foreach (QString key, keys)
48  emit valueChangedFor(key);
49 }
50 
51 void Settings::setValueIfNotDefault(const QString& key, const QVariant& value, const QVariant& defaultValue)
52 {
53  if (value==defaultValue)
54  return;
55  this->setValue(key, value);
56 }
57 
58 void Settings::setValue(const QString& key, const QVariant& value)
59 {
60  mSettings->setValue(key, value);
61  this->sync();
62 
63  emit valueChangedFor(key);
64 }
65 
66 QVariant Settings::value(const QString& key, const QVariant& defaultValue) const
67 {
68  return mSettings->value(key, defaultValue);
69 }
70 
71 bool Settings::contains(const QString& key) const
72 {
73  return mSettings->contains(key);
74 }
75 
76 QString Settings::fileName() const
77 {
78  return mSettings->fileName();
79 }
80 
82 {
83  mSettings->sync();
84 }
85 }
cx::Settings::valueChangedFor
void valueChangedFor(QString key)
cx::Settings::sync
void sync()
Definition: cxSettings.cpp:81
cx::Settings::value
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
Definition: cxSettings.cpp:66
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::Settings::~Settings
virtual ~Settings()
Definition: cxSettings.cpp:30
cx::Settings::resetFile
void resetFile(QString filename)
internal use only: reset internal settings file.
Definition: cxSettings.cpp:34
cx::Settings::setValueIfNotDefault
void setValueIfNotDefault(const QString &key, const QVariant &value, const QVariant &defaultValue)
Definition: cxSettings.cpp:51
cx::Settings
Customized interface for setting values in QSettings.
Definition: cxSettings.h:37
cx::Settings::Settings
Settings()
Definition: cxSettings.cpp:26
cxProfile.h
cxTypeConversions.h
cxSettings.h
cx::Settings::contains
bool contains(const QString &key) const
Definition: cxSettings.cpp:71
cx::profile
cxResource_EXPORT ProfilePtr profile()
Definition: cxProfile.cpp:160
cx::Settings::setValue
void setValue(const QString &key, const QVariant &value)
Definition: cxSettings.cpp:58
cx::settings
Settings * settings()
Shortcut for accessing the settings instance.
Definition: cxSettings.cpp:21
cx::Settings::fileName
QString fileName() const
Definition: cxSettings.cpp:76