1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2020 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the QtCore module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | |
40 | #ifndef QSETTINGS_H |
41 | #define QSETTINGS_H |
42 | |
43 | #include <QtCore/qobject.h> |
44 | #include <QtCore/qvariant.h> |
45 | #include <QtCore/qstring.h> |
46 | #include <QtCore/qscopedpointer.h> |
47 | |
48 | QT_REQUIRE_CONFIG(settings); |
49 | |
50 | #include <ctype.h> |
51 | |
52 | QT_BEGIN_NAMESPACE |
53 | |
54 | #ifdef Status // we seem to pick up a macro Status --> int somewhere |
55 | #undef Status |
56 | #endif |
57 | |
58 | class QIODevice; |
59 | class QSettingsPrivate; |
60 | |
61 | #ifndef QT_NO_QOBJECT |
62 | class Q_CORE_EXPORT QSettings : public QObject |
63 | #else |
64 | class Q_CORE_EXPORT QSettings |
65 | #endif |
66 | { |
67 | #ifndef QT_NO_QOBJECT |
68 | Q_OBJECT |
69 | #else |
70 | QScopedPointer<QSettingsPrivate> d_ptr; |
71 | #endif |
72 | Q_DECLARE_PRIVATE(QSettings) |
73 | |
74 | public: |
75 | enum Status { |
76 | NoError = 0, |
77 | AccessError, |
78 | FormatError |
79 | }; |
80 | #ifndef QT_NO_QOBJECT |
81 | Q_ENUM(Status) |
82 | #endif |
83 | |
84 | enum Format { |
85 | NativeFormat, |
86 | IniFormat, |
87 | |
88 | #if defined(Q_OS_WIN) || defined(Q_CLANG_QDOC) |
89 | Registry32Format, |
90 | Registry64Format, |
91 | #endif |
92 | |
93 | InvalidFormat = 16, |
94 | CustomFormat1, |
95 | CustomFormat2, |
96 | CustomFormat3, |
97 | CustomFormat4, |
98 | CustomFormat5, |
99 | CustomFormat6, |
100 | CustomFormat7, |
101 | CustomFormat8, |
102 | CustomFormat9, |
103 | CustomFormat10, |
104 | CustomFormat11, |
105 | CustomFormat12, |
106 | CustomFormat13, |
107 | CustomFormat14, |
108 | CustomFormat15, |
109 | CustomFormat16 |
110 | }; |
111 | #ifndef QT_NO_QOBJECT |
112 | Q_ENUM(Format) |
113 | #endif |
114 | |
115 | enum Scope { |
116 | UserScope, |
117 | SystemScope |
118 | }; |
119 | #ifndef QT_NO_QOBJECT |
120 | Q_ENUM(Scope) |
121 | #endif |
122 | |
123 | #ifndef QT_NO_QOBJECT |
124 | explicit QSettings(const QString &organization, |
125 | const QString &application = QString(), QObject *parent = nullptr); |
126 | QSettings(Scope scope, const QString &organization, |
127 | const QString &application = QString(), QObject *parent = nullptr); |
128 | QSettings(Format format, Scope scope, const QString &organization, |
129 | const QString &application = QString(), QObject *parent = nullptr); |
130 | QSettings(const QString &fileName, Format format, QObject *parent = nullptr); |
131 | explicit QSettings(QObject *parent = nullptr); |
132 | explicit QSettings(Scope scope, QObject *parent = nullptr); |
133 | #else |
134 | explicit QSettings(const QString &organization, |
135 | const QString &application = QString()); |
136 | QSettings(Scope scope, const QString &organization, |
137 | const QString &application = QString()); |
138 | QSettings(Format format, Scope scope, const QString &organization, |
139 | const QString &application = QString()); |
140 | QSettings(const QString &fileName, Format format); |
141 | # ifndef QT_BUILD_QMAKE |
142 | explicit QSettings(Scope scope = UserScope); |
143 | # endif |
144 | #endif |
145 | ~QSettings(); |
146 | |
147 | void clear(); |
148 | void sync(); |
149 | Status status() const; |
150 | bool isAtomicSyncRequired() const; |
151 | void setAtomicSyncRequired(bool enable); |
152 | |
153 | void beginGroup(const QString &prefix); |
154 | void endGroup(); |
155 | QString group() const; |
156 | |
157 | int beginReadArray(const QString &prefix); |
158 | void beginWriteArray(const QString &prefix, int size = -1); |
159 | void endArray(); |
160 | void setArrayIndex(int i); |
161 | |
162 | QStringList allKeys() const; |
163 | QStringList childKeys() const; |
164 | QStringList childGroups() const; |
165 | bool isWritable() const; |
166 | |
167 | void setValue(const QString &key, const QVariant &value); |
168 | QVariant value(const QString &key, const QVariant &defaultValue = QVariant()) const; |
169 | |
170 | void remove(const QString &key); |
171 | bool contains(const QString &key) const; |
172 | |
173 | void setFallbacksEnabled(bool b); |
174 | bool fallbacksEnabled() const; |
175 | |
176 | QString fileName() const; |
177 | Format format() const; |
178 | Scope scope() const; |
179 | QString organizationName() const; |
180 | QString applicationName() const; |
181 | |
182 | static void setDefaultFormat(Format format); |
183 | static Format defaultFormat(); |
184 | static void setPath(Format format, Scope scope, const QString &path); |
185 | |
186 | typedef QMap<QString, QVariant> SettingsMap; |
187 | typedef bool (*ReadFunc)(QIODevice &device, SettingsMap &map); |
188 | typedef bool (*WriteFunc)(QIODevice &device, const SettingsMap &map); |
189 | |
190 | static Format registerFormat(const QString &extension, ReadFunc readFunc, WriteFunc writeFunc, |
191 | Qt::CaseSensitivity caseSensitivity = Qt::CaseSensitive); |
192 | |
193 | protected: |
194 | #ifndef QT_NO_QOBJECT |
195 | bool event(QEvent *event) override; |
196 | #endif |
197 | |
198 | private: |
199 | Q_DISABLE_COPY(QSettings) |
200 | }; |
201 | |
202 | QT_END_NAMESPACE |
203 | |
204 | #endif // QSETTINGS_H |
205 | |