1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QSETTINGS_H
5#define QSETTINGS_H
6
7#include <QtCore/qobject.h>
8#include <QtCore/qvariant.h>
9#include <QtCore/qstring.h>
10#include <QtCore/qscopedpointer.h>
11
12QT_REQUIRE_CONFIG(settings);
13
14#include <ctype.h>
15
16QT_BEGIN_NAMESPACE
17
18#ifdef Status // we seem to pick up a macro Status --> int somewhere
19#undef Status
20#endif
21
22class QIODevice;
23class QSettingsPrivate;
24
25#ifndef QT_NO_QOBJECT
26class Q_CORE_EXPORT QSettings : public QObject
27#else
28class Q_CORE_EXPORT QSettings
29#endif
30{
31#ifndef QT_NO_QOBJECT
32 Q_OBJECT
33#else
34 QScopedPointer<QSettingsPrivate> d_ptr;
35#endif
36 Q_DECLARE_PRIVATE(QSettings)
37
38public:
39 enum Status {
40 NoError = 0,
41 AccessError,
42 FormatError
43 };
44#ifndef QT_NO_QOBJECT
45 Q_ENUM(Status)
46#endif
47
48 enum Format {
49 NativeFormat,
50 IniFormat,
51
52#if defined(Q_OS_WIN) || defined(Q_QDOC)
53 Registry32Format,
54 Registry64Format,
55#endif
56
57#if defined(Q_OS_WASM)
58 // FIXME: add public API in next minor release.
59 // WebLocalStorageFormat (IniFormat + 1)
60 // WebIDBSFormat (IniFormat + 2)
61#endif
62
63 InvalidFormat = 16,
64 CustomFormat1,
65 CustomFormat2,
66 CustomFormat3,
67 CustomFormat4,
68 CustomFormat5,
69 CustomFormat6,
70 CustomFormat7,
71 CustomFormat8,
72 CustomFormat9,
73 CustomFormat10,
74 CustomFormat11,
75 CustomFormat12,
76 CustomFormat13,
77 CustomFormat14,
78 CustomFormat15,
79 CustomFormat16
80 };
81#ifndef QT_NO_QOBJECT
82 Q_ENUM(Format)
83#endif
84
85 enum Scope {
86 UserScope,
87 SystemScope
88 };
89#ifndef QT_NO_QOBJECT
90 Q_ENUM(Scope)
91#endif
92
93#ifndef QT_NO_QOBJECT
94 explicit QSettings(const QString &organization,
95 const QString &application = QString(), QObject *parent = nullptr);
96 QSettings(Scope scope, const QString &organization,
97 const QString &application = QString(), QObject *parent = nullptr);
98 QSettings(Format format, Scope scope, const QString &organization,
99 const QString &application = QString(), QObject *parent = nullptr);
100 QSettings(const QString &fileName, Format format, QObject *parent = nullptr);
101 explicit QSettings(QObject *parent = nullptr);
102 explicit QSettings(Scope scope, QObject *parent = nullptr);
103#else
104 explicit QSettings(const QString &organization,
105 const QString &application = QString());
106 QSettings(Scope scope, const QString &organization,
107 const QString &application = QString());
108 QSettings(Format format, Scope scope, const QString &organization,
109 const QString &application = QString());
110 QSettings(const QString &fileName, Format format);
111 explicit QSettings(Scope scope = UserScope);
112#endif
113 ~QSettings();
114
115 void clear();
116 void sync();
117 Status status() const;
118 bool isAtomicSyncRequired() const;
119 void setAtomicSyncRequired(bool enable);
120
121#if QT_CORE_REMOVED_SINCE(6, 4)
122 void beginGroup(const QString &prefix);
123#endif
124 void beginGroup(QAnyStringView prefix);
125 void endGroup();
126 QString group() const;
127
128#if QT_CORE_REMOVED_SINCE(6, 4)
129 int beginReadArray(const QString &prefix);
130 void beginWriteArray(const QString &prefix, int size = -1);
131#endif
132 int beginReadArray(QAnyStringView prefix);
133 void beginWriteArray(QAnyStringView prefix, int size = -1);
134 void endArray();
135 void setArrayIndex(int i);
136
137 QStringList allKeys() const;
138 QStringList childKeys() const;
139 QStringList childGroups() const;
140 bool isWritable() const;
141
142#if QT_CORE_REMOVED_SINCE(6, 4)
143 void setValue(const QString &key, const QVariant &value);
144 QVariant value(const QString &key, const QVariant &defaultValue) const;
145 QVariant value(const QString &key) const;
146#endif
147 void setValue(QAnyStringView key, const QVariant &value);
148 QVariant value(QAnyStringView key, const QVariant &defaultValue) const;
149 QVariant value(QAnyStringView key) const;
150
151#if QT_CORE_REMOVED_SINCE(6, 4)
152 void remove(const QString &key);
153 bool contains(const QString &key) const;
154#endif
155 void remove(QAnyStringView key);
156 bool contains(QAnyStringView key) const;
157
158 void setFallbacksEnabled(bool b);
159 bool fallbacksEnabled() const;
160
161 QString fileName() const;
162 Format format() const;
163 Scope scope() const;
164 QString organizationName() const;
165 QString applicationName() const;
166
167 static void setDefaultFormat(Format format);
168 static Format defaultFormat();
169 static void setPath(Format format, Scope scope, const QString &path);
170
171 typedef QMap<QString, QVariant> SettingsMap;
172 typedef bool (*ReadFunc)(QIODevice &device, SettingsMap &map);
173 typedef bool (*WriteFunc)(QIODevice &device, const SettingsMap &map);
174
175 static Format registerFormat(const QString &extension, ReadFunc readFunc, WriteFunc writeFunc,
176 Qt::CaseSensitivity caseSensitivity = Qt::CaseSensitive);
177
178protected:
179#ifndef QT_NO_QOBJECT
180 bool event(QEvent *event) override;
181#endif
182
183private:
184 Q_DISABLE_COPY(QSettings)
185};
186
187QT_END_NAMESPACE
188
189#endif // QSETTINGS_H
190

source code of qtbase/src/corelib/io/qsettings.h