Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-23 08:32:54

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