BuildmLearn Toolkit  2.0.4
BuildmLearn Toolkit is an easy-to-use program that helps users make mobile apps without any knowledge of application development.
 All Classes Functions Enumerations Groups Pages
settings.h
1 /*
2  Copyright (c) 2012, BuildmLearn Contributors listed at http://buildmlearn.org/people/
3  All rights reserved.
4 
5  Redistribution and use in source and binary forms, with or without
6  modification, are permitted provided that the following conditions are met:
7 
8  * Redistributions of source code must retain the above copyright notice, this
9  list of conditions and the following disclaimer.
10 
11  * Redistributions in binary form must reproduce the above copyright notice,
12  this list of conditions and the following disclaimer in the documentation
13  and/or other materials provided with the distribution.
14 
15  * Neither the name of the BuildmLearn nor the names of its
16  contributors may be used to endorse or promote products derived from
17  this software without specific prior written permission.
18 
19  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30 
31 #ifndef SETTINGS_H
32 #define SETTINGS_H
33 
34 #include <QSettings>
35 
36 #include <QPointer>
37 
38 
39 /// \brief Application-wide settings mechanism.
40 class Settings : public QSettings {
41  Q_OBJECT
42 
43  public:
44  /// \brief Describes possible types of loaded settings.
45  enum Type {
46  Portable,
47  NonPortable
48  };
49 
50  // Destructor.
51  virtual ~Settings();
52 
53  /// \brief Type of used settings.
54  /// \return Returns type of used settings.
55  inline Type type() const {
56  return m_initializationStatus;
57  }
58 
59  /// \brief Getter/setter for settings values.
60  /// \param section Section in the settings.
61  /// \param key Key of setting.
62  /// \param default_value Default value to be used if no value exists for given key.
63  /// \return Returns found value, default value or empty variant value.
64  inline QVariant value(const QString &section,
65  const QString &key,
66  const QVariant &default_value = QVariant()) {
67  return QSettings::value(QString("%1/%2").arg(section, key), default_value);
68  }
69 
70  /// \brief Sets new value into settings.
71  /// \param section Section in the settings.
72  /// \param key Key.
73  /// \param value New value.
74  inline void setValue(const QString &section,
75  const QString &key,
76  const QVariant &value) {
77  QSettings::setValue(QString("%1/%2").arg(section, key), value);
78  }
79 
80  /// \brief Synchronizes settings.
81  /// \return Returns state of settings.
82  QSettings::Status checkSettings();
83 
84  /// \brief Creates settings file in correct location.
85  /// \param parent Parent object.
86  /// \return Returns pointer to new settings.
87  static Settings *setupSettings(QObject *parent);
88 
89  private:
90  // Constructor.
91  Settings(const QString & file_name, Format format,
92  const Type &type, QObject * parent = 0);
93 
94  Type m_initializationStatus;
95 };
96 
97 #endif // SETTINGS_H
Type type() const
Type of used settings.
Definition: settings.h:55
void setValue(const QString &section, const QString &key, const QVariant &value)
Sets new value into settings.
Definition: settings.h:74
Type
Describes possible types of loaded settings.
Definition: settings.h:45
Application-wide settings mechanism.
Definition: settings.h:40
QVariant value(const QString &section, const QString &key, const QVariant &default_value=QVariant())
Getter/setter for settings values.
Definition: settings.h:64
QSettings::Status checkSettings()
Synchronizes settings.
Definition: settings.cpp:50
static Settings * setupSettings(QObject *parent)
Creates settings file in correct location.
Definition: settings.cpp:57