Fraxinus  2023.01.05-dev+develop.0da12
An IGT application
cxSettings.h
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 #ifndef CXSETTINGS_H_
12 #define CXSETTINGS_H_
13 
14 #include "cxResourceExport.h"
15 
16 #include "boost/shared_ptr.hpp"
17 #include <QObject>
18 #include <QSettings>
19 
20 namespace cx
21 {
22 
29 typedef boost::shared_ptr<class QSettings> QSettingsPtr;
30 
37 class cxResource_EXPORT Settings : public QObject
38 {
39  Q_OBJECT
40 
41 public:
42 
43  void setValueIfNotDefault(const QString& key, const QVariant& value, const QVariant& defaultValue);
44  //forwarding functions from QSettings
45  void setValue(const QString& key, const QVariant& value);
46  QVariant value(const QString& key, const QVariant& defaultValue = QVariant()) const;
47 
48  bool contains(const QString& key) const;
49  QString fileName() const;
50 
51  void sync();
52 
53  void resetFile(QString filename);
54  Settings();
55  virtual ~Settings();
56 
59  template<class T>
60  void fillDefault(QString name, T value)
61  {
62  if (!this->contains(name))
63  this->setValue(name, value);
64  }
65 
66 signals:
67  void valueChangedFor(QString key);
68 
69 private slots:
70 private:
71  QSettingsPtr mSettings;
72 
73 };
74 
76 cxResource_EXPORT Settings* settings();
77 
82 }
83 
84 #endif /* CXSETTINGS_H_ */
Customized interface for setting values in QSettings.
Definition: cxSettings.h:37
boost::shared_ptr< class QSettings > QSettingsPtr
Definition: cxProfile.h:24
Settings * settings()
Shortcut for accessing the settings instance.
Definition: cxSettings.cpp:21
void fillDefault(QString name, T value)
Definition: cxSettings.h:60
Namespace for all CustusX production code.