CustusX  2023.01.05-dev+develop.0da12
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 }
cxResource_EXPORT ProfilePtr profile()
Definition: cxProfile.cpp:160
bool contains(const QString &key) const
Definition: cxSettings.cpp:71
QString fileName() const
Definition: cxSettings.cpp:76
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
Definition: cxSettings.cpp:66
void setValueIfNotDefault(const QString &key, const QVariant &value, const QVariant &defaultValue)
Definition: cxSettings.cpp:51
void setValue(const QString &key, const QVariant &value)
Definition: cxSettings.cpp:58
Customized interface for setting values in QSettings.
Definition: cxSettings.h:37
void valueChangedFor(QString key)
void resetFile(QString filename)
internal use only: reset internal settings file.
Definition: cxSettings.cpp:34
Settings * settings()
Shortcut for accessing the settings instance.
Definition: cxSettings.cpp:21
virtual ~Settings()
Definition: cxSettings.cpp:30
Namespace for all CustusX production code.