File indexing completed on 2025-01-18 10:07:35
0001
0002
0003
0004 #ifndef QSETTINGS_H
0005 #define QSETTINGS_H
0006
0007 #include <QtCore/qobject.h>
0008 #include <QtCore/qvariant.h>
0009 #include <QtCore/qstring.h>
0010 #include <QtCore/qscopedpointer.h>
0011
0012 QT_REQUIRE_CONFIG(settings);
0013
0014 #include <ctype.h>
0015
0016 QT_BEGIN_NAMESPACE
0017
0018 #ifdef Status
0019 #undef Status
0020 #endif
0021
0022 class QIODevice;
0023 class QSettingsPrivate;
0024
0025 #ifndef QT_NO_QOBJECT
0026 class Q_CORE_EXPORT QSettings : public QObject
0027 #else
0028 class Q_CORE_EXPORT QSettings
0029 #endif
0030 {
0031 #ifndef QT_NO_QOBJECT
0032 Q_OBJECT
0033 #else
0034 QScopedPointer<QSettingsPrivate> d_ptr;
0035 #endif
0036 Q_DECLARE_PRIVATE(QSettings)
0037
0038 public:
0039 enum Status {
0040 NoError = 0,
0041 AccessError,
0042 FormatError
0043 };
0044 #ifndef QT_NO_QOBJECT
0045 Q_ENUM(Status)
0046 #endif
0047
0048 enum Format {
0049 NativeFormat = 0,
0050 IniFormat = 1,
0051
0052 #if defined(Q_OS_WIN) || defined(Q_QDOC)
0053 Registry32Format = 2,
0054 Registry64Format = 3,
0055 #endif
0056
0057 #if defined(Q_OS_WASM) || defined(Q_QDOC)
0058 WebLocalStorageFormat = 4,
0059 WebIndexedDBFormat = 5,
0060 #endif
0061
0062 InvalidFormat = 16,
0063 CustomFormat1,
0064 CustomFormat2,
0065 CustomFormat3,
0066 CustomFormat4,
0067 CustomFormat5,
0068 CustomFormat6,
0069 CustomFormat7,
0070 CustomFormat8,
0071 CustomFormat9,
0072 CustomFormat10,
0073 CustomFormat11,
0074 CustomFormat12,
0075 CustomFormat13,
0076 CustomFormat14,
0077 CustomFormat15,
0078 CustomFormat16
0079 };
0080 #ifndef QT_NO_QOBJECT
0081 Q_ENUM(Format)
0082 #endif
0083
0084 enum Scope {
0085 UserScope,
0086 SystemScope
0087 };
0088 #ifndef QT_NO_QOBJECT
0089 Q_ENUM(Scope)
0090 #endif
0091
0092 #ifndef QT_NO_QOBJECT
0093 explicit QSettings(const QString &organization,
0094 const QString &application = QString(), QObject *parent = nullptr);
0095 QSettings(Scope scope, const QString &organization,
0096 const QString &application = QString(), QObject *parent = nullptr);
0097 QSettings(Format format, Scope scope, const QString &organization,
0098 const QString &application = QString(), QObject *parent = nullptr);
0099 QSettings(const QString &fileName, Format format, QObject *parent = nullptr);
0100 explicit QSettings(QObject *parent = nullptr);
0101 explicit QSettings(Scope scope, QObject *parent = nullptr);
0102 #else
0103 explicit QSettings(const QString &organization,
0104 const QString &application = QString());
0105 QSettings(Scope scope, const QString &organization,
0106 const QString &application = QString());
0107 QSettings(Format format, Scope scope, const QString &organization,
0108 const QString &application = QString());
0109 QSettings(const QString &fileName, Format format);
0110 explicit QSettings(Scope scope = UserScope);
0111 #endif
0112 ~QSettings();
0113
0114 void clear();
0115 void sync();
0116 Status status() const;
0117 bool isAtomicSyncRequired() const;
0118 void setAtomicSyncRequired(bool enable);
0119
0120 #if QT_CORE_REMOVED_SINCE(6, 4)
0121 void beginGroup(const QString &prefix);
0122 #endif
0123 void beginGroup(QAnyStringView prefix);
0124 void endGroup();
0125 QString group() const;
0126
0127 #if QT_CORE_REMOVED_SINCE(6, 4)
0128 int beginReadArray(const QString &prefix);
0129 void beginWriteArray(const QString &prefix, int size = -1);
0130 #endif
0131 int beginReadArray(QAnyStringView prefix);
0132 void beginWriteArray(QAnyStringView prefix, int size = -1);
0133 void endArray();
0134 void setArrayIndex(int i);
0135
0136 QStringList allKeys() const;
0137 QStringList childKeys() const;
0138 QStringList childGroups() const;
0139 bool isWritable() const;
0140
0141 #if QT_CORE_REMOVED_SINCE(6, 4)
0142 void setValue(const QString &key, const QVariant &value);
0143 QVariant value(const QString &key, const QVariant &defaultValue) const;
0144 QVariant value(const QString &key) const;
0145 #endif
0146 void setValue(QAnyStringView key, const QVariant &value);
0147 QVariant value(QAnyStringView key, const QVariant &defaultValue) const;
0148 QVariant value(QAnyStringView key) const;
0149
0150 #if QT_CORE_REMOVED_SINCE(6, 4)
0151 void remove(const QString &key);
0152 bool contains(const QString &key) const;
0153 #endif
0154 void remove(QAnyStringView key);
0155 bool contains(QAnyStringView key) const;
0156
0157 void setFallbacksEnabled(bool b);
0158 bool fallbacksEnabled() const;
0159
0160 QString fileName() const;
0161 Format format() const;
0162 Scope scope() const;
0163 QString organizationName() const;
0164 QString applicationName() const;
0165
0166 static void setDefaultFormat(Format format);
0167 static Format defaultFormat();
0168 static void setPath(Format format, Scope scope, const QString &path);
0169
0170 typedef QMap<QString, QVariant> SettingsMap;
0171 typedef bool (*ReadFunc)(QIODevice &device, SettingsMap &map);
0172 typedef bool (*WriteFunc)(QIODevice &device, const SettingsMap &map);
0173
0174 static Format registerFormat(const QString &extension, ReadFunc readFunc, WriteFunc writeFunc,
0175 Qt::CaseSensitivity caseSensitivity = Qt::CaseSensitive);
0176
0177 protected:
0178 #ifndef QT_NO_QOBJECT
0179 bool event(QEvent *event) override;
0180 #endif
0181
0182 private:
0183 Q_DISABLE_COPY(QSettings)
0184 };
0185
0186 QT_END_NAMESPACE
0187
0188 #endif