| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/io/qsettings.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||||||||||||||||||||||||||
| 2 | ** | - | ||||||||||||||||||||||||||||||||||||
| 3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||||||||||||||||||||||||||
| 4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||||||||||||||||||||
| 5 | ** | - | ||||||||||||||||||||||||||||||||||||
| 6 | ** This file is part of the QtCore module of the Qt Toolkit. | - | ||||||||||||||||||||||||||||||||||||
| 7 | ** | - | ||||||||||||||||||||||||||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||||||||||||||||||||
| 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 http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||||||||||||||||||||
| 15 | ** information use the contact form at http://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 2.1 or version 3 as published by the Free | - | ||||||||||||||||||||||||||||||||||||
| 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||||||||||||||||||||
| 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||||||||||||||||||||
| 22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||||||||||||||||||||
| 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||||||||||||||||||||
| 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||||||||||||||||||||
| 25 | ** | - | ||||||||||||||||||||||||||||||||||||
| 26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||||||||||||||||||||
| 27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||||||||||||||||||||
| 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||||||||||||||||||||
| 29 | ** | - | ||||||||||||||||||||||||||||||||||||
| 30 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||||||||||||||||||||
| 31 | ** | - | ||||||||||||||||||||||||||||||||||||
| 32 | ****************************************************************************/ | - | ||||||||||||||||||||||||||||||||||||
| 33 | - | |||||||||||||||||||||||||||||||||||||
| 34 | #include <qdebug.h> | - | ||||||||||||||||||||||||||||||||||||
| 35 | #include "qplatformdefs.h" | - | ||||||||||||||||||||||||||||||||||||
| 36 | #include "qsettings.h" | - | ||||||||||||||||||||||||||||||||||||
| 37 | - | |||||||||||||||||||||||||||||||||||||
| 38 | #ifndef QT_NO_SETTINGS | - | ||||||||||||||||||||||||||||||||||||
| 39 | - | |||||||||||||||||||||||||||||||||||||
| 40 | #include "qsettings_p.h" | - | ||||||||||||||||||||||||||||||||||||
| 41 | #include "qcache.h" | - | ||||||||||||||||||||||||||||||||||||
| 42 | #include "qfile.h" | - | ||||||||||||||||||||||||||||||||||||
| 43 | #include "qdir.h" | - | ||||||||||||||||||||||||||||||||||||
| 44 | #include "qfileinfo.h" | - | ||||||||||||||||||||||||||||||||||||
| 45 | #include "qmutex.h" | - | ||||||||||||||||||||||||||||||||||||
| 46 | #include "qlibraryinfo.h" | - | ||||||||||||||||||||||||||||||||||||
| 47 | #include "qtemporaryfile.h" | - | ||||||||||||||||||||||||||||||||||||
| 48 | #include "qstandardpaths.h" | - | ||||||||||||||||||||||||||||||||||||
| 49 | #include <qdatastream.h> | - | ||||||||||||||||||||||||||||||||||||
| 50 | - | |||||||||||||||||||||||||||||||||||||
| 51 | #ifndef QT_NO_TEXTCODEC | - | ||||||||||||||||||||||||||||||||||||
| 52 | # include "qtextcodec.h" | - | ||||||||||||||||||||||||||||||||||||
| 53 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 54 | - | |||||||||||||||||||||||||||||||||||||
| 55 | #ifndef QT_NO_GEOM_VARIANT | - | ||||||||||||||||||||||||||||||||||||
| 56 | #include "qsize.h" | - | ||||||||||||||||||||||||||||||||||||
| 57 | #include "qpoint.h" | - | ||||||||||||||||||||||||||||||||||||
| 58 | #include "qrect.h" | - | ||||||||||||||||||||||||||||||||||||
| 59 | #endif // !QT_NO_GEOM_VARIANT | - | ||||||||||||||||||||||||||||||||||||
| 60 | - | |||||||||||||||||||||||||||||||||||||
| 61 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||||||||||||||||||||
| 62 | #include "qcoreapplication.h" | - | ||||||||||||||||||||||||||||||||||||
| 63 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 64 | - | |||||||||||||||||||||||||||||||||||||
| 65 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||||||||||||||
| 66 | #include "qsavefile.h" | - | ||||||||||||||||||||||||||||||||||||
| 67 | #include "qlockfile.h" | - | ||||||||||||||||||||||||||||||||||||
| 68 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 69 | - | |||||||||||||||||||||||||||||||||||||
| 70 | #ifdef Q_OS_VXWORKS | - | ||||||||||||||||||||||||||||||||||||
| 71 | # include <ioLib.h> | - | ||||||||||||||||||||||||||||||||||||
| 72 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 73 | - | |||||||||||||||||||||||||||||||||||||
| 74 | #include <algorithm> | - | ||||||||||||||||||||||||||||||||||||
| 75 | #include <stdlib.h> | - | ||||||||||||||||||||||||||||||||||||
| 76 | - | |||||||||||||||||||||||||||||||||||||
| 77 | #ifdef Q_OS_WIN // for homedirpath reading from registry | - | ||||||||||||||||||||||||||||||||||||
| 78 | # include <private/qsystemlibrary_p.h> | - | ||||||||||||||||||||||||||||||||||||
| 79 | # include <qt_windows.h> | - | ||||||||||||||||||||||||||||||||||||
| 80 | # ifndef Q_OS_WINRT | - | ||||||||||||||||||||||||||||||||||||
| 81 | # include <shlobj.h> | - | ||||||||||||||||||||||||||||||||||||
| 82 | # endif | - | ||||||||||||||||||||||||||||||||||||
| 83 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 84 | - | |||||||||||||||||||||||||||||||||||||
| 85 | #ifdef Q_OS_WINRT | - | ||||||||||||||||||||||||||||||||||||
| 86 | #include <wrl.h> | - | ||||||||||||||||||||||||||||||||||||
| 87 | #include <windows.foundation.h> | - | ||||||||||||||||||||||||||||||||||||
| 88 | #include <windows.storage.h> | - | ||||||||||||||||||||||||||||||||||||
| 89 | using namespace Microsoft::WRL; | - | ||||||||||||||||||||||||||||||||||||
| 90 | using namespace Microsoft::WRL::Wrappers; | - | ||||||||||||||||||||||||||||||||||||
| 91 | using namespace ABI::Windows::Foundation; | - | ||||||||||||||||||||||||||||||||||||
| 92 | using namespace ABI::Windows::Storage; | - | ||||||||||||||||||||||||||||||||||||
| 93 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 94 | - | |||||||||||||||||||||||||||||||||||||
| 95 | #ifndef CSIDL_COMMON_APPDATA | - | ||||||||||||||||||||||||||||||||||||
| 96 | #define CSIDL_COMMON_APPDATA 0x0023 // All Users\Application Data | - | ||||||||||||||||||||||||||||||||||||
| 97 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 98 | - | |||||||||||||||||||||||||||||||||||||
| 99 | #ifndef CSIDL_APPDATA | - | ||||||||||||||||||||||||||||||||||||
| 100 | #define CSIDL_APPDATA 0x001a // <username>\Application Data | - | ||||||||||||||||||||||||||||||||||||
| 101 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 102 | - | |||||||||||||||||||||||||||||||||||||
| 103 | #if defined(Q_OS_UNIX) && !defined(Q_OS_MAC) && !defined(Q_OS_BLACKBERRY) && !defined(Q_OS_ANDROID) | - | ||||||||||||||||||||||||||||||||||||
| 104 | #define Q_XDG_PLATFORM | - | ||||||||||||||||||||||||||||||||||||
| 105 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 106 | - | |||||||||||||||||||||||||||||||||||||
| 107 | #if !defined(QT_NO_STANDARDPATHS) && (defined(Q_XDG_PLATFORM) || defined(Q_OS_IOS)) | - | ||||||||||||||||||||||||||||||||||||
| 108 | #define QSETTINGS_USE_QSTANDARDPATHS | - | ||||||||||||||||||||||||||||||||||||
| 109 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 110 | - | |||||||||||||||||||||||||||||||||||||
| 111 | // ************************************************************************ | - | ||||||||||||||||||||||||||||||||||||
| 112 | // QConfFile | - | ||||||||||||||||||||||||||||||||||||
| 113 | - | |||||||||||||||||||||||||||||||||||||
| 114 | /* | - | ||||||||||||||||||||||||||||||||||||
| 115 | QConfFile objects are explicitly shared within the application. | - | ||||||||||||||||||||||||||||||||||||
| 116 | This ensures that modification to the settings done through one | - | ||||||||||||||||||||||||||||||||||||
| 117 | QSettings object are immediately reflected in other setting | - | ||||||||||||||||||||||||||||||||||||
| 118 | objects of the same application. | - | ||||||||||||||||||||||||||||||||||||
| 119 | */ | - | ||||||||||||||||||||||||||||||||||||
| 120 | - | |||||||||||||||||||||||||||||||||||||
| 121 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||||||||||||||||||||
| 122 | - | |||||||||||||||||||||||||||||||||||||
| 123 | struct QConfFileCustomFormat | - | ||||||||||||||||||||||||||||||||||||
| 124 | { | - | ||||||||||||||||||||||||||||||||||||
| 125 | QString extension; | - | ||||||||||||||||||||||||||||||||||||
| 126 | QSettings::ReadFunc readFunc; | - | ||||||||||||||||||||||||||||||||||||
| 127 | QSettings::WriteFunc writeFunc; | - | ||||||||||||||||||||||||||||||||||||
| 128 | Qt::CaseSensitivity caseSensitivity; | - | ||||||||||||||||||||||||||||||||||||
| 129 | }; | - | ||||||||||||||||||||||||||||||||||||
| 130 | Q_DECLARE_TYPEINFO(QConfFileCustomFormat, Q_MOVABLE_TYPE); | - | ||||||||||||||||||||||||||||||||||||
| 131 | - | |||||||||||||||||||||||||||||||||||||
| 132 | typedef QHash<QString, QConfFile *> ConfFileHash; | - | ||||||||||||||||||||||||||||||||||||
| 133 | typedef QCache<QString, QConfFile> ConfFileCache; | - | ||||||||||||||||||||||||||||||||||||
| 134 | typedef QHash<int, QString> PathHash; | - | ||||||||||||||||||||||||||||||||||||
| 135 | typedef QVector<QConfFileCustomFormat> CustomFormatVector; | - | ||||||||||||||||||||||||||||||||||||
| 136 | - | |||||||||||||||||||||||||||||||||||||
| 137 | Q_GLOBAL_STATIC(ConfFileHash, usedHashFunc) executed 50 times by 30 tests: end of blockExecuted by:
executed 50 times by 30 tests: guard.store(QtGlobalStatic::Destroyed);Executed by:
executed 12517 times by 35 tests: return &holder.value;Executed by:
| 0-12517 | ||||||||||||||||||||||||||||||||||||
| 138 | Q_GLOBAL_STATIC(ConfFileCache, unusedCacheFunc) executed 50 times by 30 tests: end of blockExecuted by:
executed 50 times by 30 tests: guard.store(QtGlobalStatic::Destroyed);Executed by:
executed 5076 times by 30 tests: return &holder.value;Executed by:
| 0-5076 | ||||||||||||||||||||||||||||||||||||
| 139 | Q_GLOBAL_STATIC(PathHash, pathHashFunc) executed 7 times by 7 tests: end of blockExecuted by:
executed 7 times by 7 tests: guard.store(QtGlobalStatic::Destroyed);Executed by:
executed 3308 times by 7 tests: return &holder.value;Executed by:
| 0-3308 | ||||||||||||||||||||||||||||||||||||
| 140 | Q_GLOBAL_STATIC(CustomFormatVector, customFormatVectorFunc) executed 1 time by 1 test: end of blockExecuted by:
executed 1 time by 1 test: guard.store(QtGlobalStatic::Destroyed);Executed by:
executed 179 times by 1 test: return &holder.value;Executed by:
| 0-179 | ||||||||||||||||||||||||||||||||||||
| 141 | - | |||||||||||||||||||||||||||||||||||||
| 142 | static QBasicMutex settingsGlobalMutex; | - | ||||||||||||||||||||||||||||||||||||
| 143 | - | |||||||||||||||||||||||||||||||||||||
| 144 | static QSettings::Format globalDefaultFormat = QSettings::NativeFormat; | - | ||||||||||||||||||||||||||||||||||||
| 145 | - | |||||||||||||||||||||||||||||||||||||
| 146 | QConfFile::QConfFile(const QString &fileName, bool _userPerms) | - | ||||||||||||||||||||||||||||||||||||
| 147 | : name(fileName), size(0), ref(1), userPerms(_userPerms) | - | ||||||||||||||||||||||||||||||||||||
| 148 | { | - | ||||||||||||||||||||||||||||||||||||
| 149 | usedHashFunc()->insert(name, this); | - | ||||||||||||||||||||||||||||||||||||
| 150 | } executed 2522 times by 30 tests: end of blockExecuted by:
| 2522 | ||||||||||||||||||||||||||||||||||||
| 151 | - | |||||||||||||||||||||||||||||||||||||
| 152 | QConfFile::~QConfFile() | - | ||||||||||||||||||||||||||||||||||||
| 153 | { | - | ||||||||||||||||||||||||||||||||||||
| 154 | if (usedHashFunc())
| 0-2522 | ||||||||||||||||||||||||||||||||||||
| 155 | usedHashFunc()->remove(name); executed 2522 times by 35 tests: usedHashFunc()->remove(name);Executed by:
| 2522 | ||||||||||||||||||||||||||||||||||||
| 156 | } executed 2522 times by 35 tests: end of blockExecuted by:
| 2522 | ||||||||||||||||||||||||||||||||||||
| 157 | - | |||||||||||||||||||||||||||||||||||||
| 158 | ParsedSettingsMap QConfFile::mergedKeyMap() const | - | ||||||||||||||||||||||||||||||||||||
| 159 | { | - | ||||||||||||||||||||||||||||||||||||
| 160 | ParsedSettingsMap result = originalKeys; | - | ||||||||||||||||||||||||||||||||||||
| 161 | ParsedSettingsMap::const_iterator i; | - | ||||||||||||||||||||||||||||||||||||
| 162 | - | |||||||||||||||||||||||||||||||||||||
| 163 | for (i = removedKeys.begin(); i != removedKeys.end(); ++i)
| 563-795 | ||||||||||||||||||||||||||||||||||||
| 164 | result.remove(i.key()); executed 795 times by 3 tests: result.remove(i.key());Executed by:
| 795 | ||||||||||||||||||||||||||||||||||||
| 165 | for (i = addedKeys.begin(); i != addedKeys.end(); ++i)
| 563-2360 | ||||||||||||||||||||||||||||||||||||
| 166 | result.insert(i.key(), i.value()); executed 2360 times by 6 tests: result.insert(i.key(), i.value());Executed by:
| 2360 | ||||||||||||||||||||||||||||||||||||
| 167 | return result; executed 563 times by 6 tests: return result;Executed by:
| 563 | ||||||||||||||||||||||||||||||||||||
| 168 | } | - | ||||||||||||||||||||||||||||||||||||
| 169 | - | |||||||||||||||||||||||||||||||||||||
| 170 | bool QConfFile::isWritable() const | - | ||||||||||||||||||||||||||||||||||||
| 171 | { | - | ||||||||||||||||||||||||||||||||||||
| 172 | QFileInfo fileInfo(name); | - | ||||||||||||||||||||||||||||||||||||
| 173 | - | |||||||||||||||||||||||||||||||||||||
| 174 | #ifndef QT_NO_TEMPORARYFILE | - | ||||||||||||||||||||||||||||||||||||
| 175 | if (fileInfo.exists()) {
| 123-462 | ||||||||||||||||||||||||||||||||||||
| 176 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 177 | QFile file(name); | - | ||||||||||||||||||||||||||||||||||||
| 178 | return file.open(QFile::ReadWrite); executed 462 times by 6 tests: return file.open(QFile::ReadWrite);Executed by:
| 462 | ||||||||||||||||||||||||||||||||||||
| 179 | #ifndef QT_NO_TEMPORARYFILE | - | ||||||||||||||||||||||||||||||||||||
| 180 | } else { | - | ||||||||||||||||||||||||||||||||||||
| 181 | // Create the directories to the file. | - | ||||||||||||||||||||||||||||||||||||
| 182 | QDir dir(fileInfo.absolutePath()); | - | ||||||||||||||||||||||||||||||||||||
| 183 | if (!dir.exists()) {
| 22-101 | ||||||||||||||||||||||||||||||||||||
| 184 | if (!dir.mkpath(dir.absolutePath()))
| 0-101 | ||||||||||||||||||||||||||||||||||||
| 185 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||||||||||||||
| 186 | } executed 101 times by 1 test: end of blockExecuted by:
| 101 | ||||||||||||||||||||||||||||||||||||
| 187 | - | |||||||||||||||||||||||||||||||||||||
| 188 | // we use a temporary file to avoid race conditions | - | ||||||||||||||||||||||||||||||||||||
| 189 | QTemporaryFile file(name); | - | ||||||||||||||||||||||||||||||||||||
| 190 | return file.open(); executed 123 times by 1 test: return file.open();Executed by:
| 123 | ||||||||||||||||||||||||||||||||||||
| 191 | } | - | ||||||||||||||||||||||||||||||||||||
| 192 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 193 | } | - | ||||||||||||||||||||||||||||||||||||
| 194 | - | |||||||||||||||||||||||||||||||||||||
| 195 | QConfFile *QConfFile::fromName(const QString &fileName, bool _userPerms) | - | ||||||||||||||||||||||||||||||||||||
| 196 | { | - | ||||||||||||||||||||||||||||||||||||
| 197 | QString absPath = QFileInfo(fileName).absoluteFilePath(); | - | ||||||||||||||||||||||||||||||||||||
| 198 | - | |||||||||||||||||||||||||||||||||||||
| 199 | ConfFileHash *usedHash = usedHashFunc(); | - | ||||||||||||||||||||||||||||||||||||
| 200 | ConfFileCache *unusedCache = unusedCacheFunc(); | - | ||||||||||||||||||||||||||||||||||||
| 201 | - | |||||||||||||||||||||||||||||||||||||
| 202 | QConfFile *confFile = 0; | - | ||||||||||||||||||||||||||||||||||||
| 203 | QMutexLocker locker(&settingsGlobalMutex); | - | ||||||||||||||||||||||||||||||||||||
| 204 | - | |||||||||||||||||||||||||||||||||||||
| 205 | if (!(confFile = usedHash->value(absPath))) {
| 215-3195 | ||||||||||||||||||||||||||||||||||||
| 206 | if ((confFile = unusedCache->take(absPath)))
| 673-2522 | ||||||||||||||||||||||||||||||||||||
| 207 | usedHash->insert(absPath, confFile); executed 673 times by 7 tests: usedHash->insert(absPath, confFile);Executed by:
| 673 | ||||||||||||||||||||||||||||||||||||
| 208 | } executed 3195 times by 30 tests: end of blockExecuted by:
| 3195 | ||||||||||||||||||||||||||||||||||||
| 209 | if (confFile) {
| 888-2522 | ||||||||||||||||||||||||||||||||||||
| 210 | confFile->ref.ref(); | - | ||||||||||||||||||||||||||||||||||||
| 211 | return confFile; executed 888 times by 7 tests: return confFile;Executed by:
| 888 | ||||||||||||||||||||||||||||||||||||
| 212 | } | - | ||||||||||||||||||||||||||||||||||||
| 213 | return new QConfFile(absPath, _userPerms); executed 2522 times by 30 tests: return new QConfFile(absPath, _userPerms);Executed by:
| 2522 | ||||||||||||||||||||||||||||||||||||
| 214 | } | - | ||||||||||||||||||||||||||||||||||||
| 215 | - | |||||||||||||||||||||||||||||||||||||
| 216 | void QConfFile::clearCache() | - | ||||||||||||||||||||||||||||||||||||
| 217 | { | - | ||||||||||||||||||||||||||||||||||||
| 218 | QMutexLocker locker(&settingsGlobalMutex); | - | ||||||||||||||||||||||||||||||||||||
| 219 | unusedCacheFunc()->clear(); | - | ||||||||||||||||||||||||||||||||||||
| 220 | } executed 125 times by 1 test: end of blockExecuted by:
| 125 | ||||||||||||||||||||||||||||||||||||
| 221 | - | |||||||||||||||||||||||||||||||||||||
| 222 | // ************************************************************************ | - | ||||||||||||||||||||||||||||||||||||
| 223 | // QSettingsPrivate | - | ||||||||||||||||||||||||||||||||||||
| 224 | - | |||||||||||||||||||||||||||||||||||||
| 225 | QSettingsPrivate::QSettingsPrivate(QSettings::Format format) | - | ||||||||||||||||||||||||||||||||||||
| 226 | : format(format), scope(QSettings::UserScope /* nothing better to put */), iniCodec(0), spec(0), fallbacks(true), | - | ||||||||||||||||||||||||||||||||||||
| 227 | pendingChanges(false), status(QSettings::NoError) | - | ||||||||||||||||||||||||||||||||||||
| 228 | { | - | ||||||||||||||||||||||||||||||||||||
| 229 | } executed 119 times by 28 tests: end of blockExecuted by:
| 119 | ||||||||||||||||||||||||||||||||||||
| 230 | - | |||||||||||||||||||||||||||||||||||||
| 231 | QSettingsPrivate::QSettingsPrivate(QSettings::Format format, QSettings::Scope scope, | - | ||||||||||||||||||||||||||||||||||||
| 232 | const QString &organization, const QString &application) | - | ||||||||||||||||||||||||||||||||||||
| 233 | : format(format), scope(scope), organizationName(organization), applicationName(application), | - | ||||||||||||||||||||||||||||||||||||
| 234 | iniCodec(0), spec(0), fallbacks(true), pendingChanges(false), status(QSettings::NoError) | - | ||||||||||||||||||||||||||||||||||||
| 235 | { | - | ||||||||||||||||||||||||||||||||||||
| 236 | } executed 1422 times by 7 tests: end of blockExecuted by:
| 1422 | ||||||||||||||||||||||||||||||||||||
| 237 | - | |||||||||||||||||||||||||||||||||||||
| 238 | QSettingsPrivate::~QSettingsPrivate() | - | ||||||||||||||||||||||||||||||||||||
| 239 | { | - | ||||||||||||||||||||||||||||||||||||
| 240 | } | - | ||||||||||||||||||||||||||||||||||||
| 241 | - | |||||||||||||||||||||||||||||||||||||
| 242 | QString QSettingsPrivate::actualKey(const QString &key) const | - | ||||||||||||||||||||||||||||||||||||
| 243 | { | - | ||||||||||||||||||||||||||||||||||||
| 244 | QString n = normalizedKey(key); | - | ||||||||||||||||||||||||||||||||||||
| 245 | Q_ASSERT_X(!n.isEmpty(), "QSettings", "empty key"); | - | ||||||||||||||||||||||||||||||||||||
| 246 | n.prepend(groupPrefix); | - | ||||||||||||||||||||||||||||||||||||
| 247 | return n; executed 48868 times by 30 tests: return n;Executed by:
| 48868 | ||||||||||||||||||||||||||||||||||||
| 248 | } | - | ||||||||||||||||||||||||||||||||||||
| 249 | - | |||||||||||||||||||||||||||||||||||||
| 250 | /* | - | ||||||||||||||||||||||||||||||||||||
| 251 | Returns a string that never starts nor ends with a slash (or an | - | ||||||||||||||||||||||||||||||||||||
| 252 | empty string). Examples: | - | ||||||||||||||||||||||||||||||||||||
| 253 | - | |||||||||||||||||||||||||||||||||||||
| 254 | "foo" becomes "foo" | - | ||||||||||||||||||||||||||||||||||||
| 255 | "/foo//bar///" becomes "foo/bar" | - | ||||||||||||||||||||||||||||||||||||
| 256 | "///" becomes "" | - | ||||||||||||||||||||||||||||||||||||
| 257 | - | |||||||||||||||||||||||||||||||||||||
| 258 | This function is optimized to avoid a QString deep copy in the | - | ||||||||||||||||||||||||||||||||||||
| 259 | common case where the key is already normalized. | - | ||||||||||||||||||||||||||||||||||||
| 260 | */ | - | ||||||||||||||||||||||||||||||||||||
| 261 | QString QSettingsPrivate::normalizedKey(const QString &key) | - | ||||||||||||||||||||||||||||||||||||
| 262 | { | - | ||||||||||||||||||||||||||||||||||||
| 263 | QString result = key; | - | ||||||||||||||||||||||||||||||||||||
| 264 | - | |||||||||||||||||||||||||||||||||||||
| 265 | int i = 0; | - | ||||||||||||||||||||||||||||||||||||
| 266 | while (i < result.size()) {
| 125-160110 | ||||||||||||||||||||||||||||||||||||
| 267 | while (result.at(i) == QLatin1Char('/')) {
| 544-160019 | ||||||||||||||||||||||||||||||||||||
| 268 | result.remove(i, 1); | - | ||||||||||||||||||||||||||||||||||||
| 269 | if (i == result.size())
| 91-453 | ||||||||||||||||||||||||||||||||||||
| 270 | goto after_loop; executed 91 times by 1 test: goto after_loop;Executed by:
| 91 | ||||||||||||||||||||||||||||||||||||
| 271 | } executed 453 times by 1 test: end of blockExecuted by:
| 453 | ||||||||||||||||||||||||||||||||||||
| 272 | while (result.at(i) != QLatin1Char('/')) {
| 109757-947162 | ||||||||||||||||||||||||||||||||||||
| 273 | ++i; | - | ||||||||||||||||||||||||||||||||||||
| 274 | if (i == result.size())
| 50262-896900 | ||||||||||||||||||||||||||||||||||||
| 275 | return result; executed 50262 times by 30 tests: return result;Executed by:
| 50262 | ||||||||||||||||||||||||||||||||||||
| 276 | } executed 896900 times by 30 tests: end of blockExecuted by:
| 896900 | ||||||||||||||||||||||||||||||||||||
| 277 | ++i; // leave the slash alone | - | ||||||||||||||||||||||||||||||||||||
| 278 | } executed 109757 times by 28 tests: end of blockExecuted by:
| 109757 | ||||||||||||||||||||||||||||||||||||
| 279 | - | |||||||||||||||||||||||||||||||||||||
| 280 | after_loop: code before this statement executed 125 times by 3 tests: after_loop:Executed by:
| 125 | ||||||||||||||||||||||||||||||||||||
| 281 | if (!result.isEmpty())
| 58-158 | ||||||||||||||||||||||||||||||||||||
| 282 | result.truncate(i - 1); // remove the trailing slash executed 58 times by 1 test: result.truncate(i - 1);Executed by:
| 58 | ||||||||||||||||||||||||||||||||||||
| 283 | return result; executed 216 times by 3 tests: return result;Executed by:
| 216 | ||||||||||||||||||||||||||||||||||||
| 284 | } | - | ||||||||||||||||||||||||||||||||||||
| 285 | - | |||||||||||||||||||||||||||||||||||||
| 286 | // see also qsettings_win.cpp, qsettings_winrt.cpp and qsettings_mac.cpp | - | ||||||||||||||||||||||||||||||||||||
| 287 | - | |||||||||||||||||||||||||||||||||||||
| 288 | #if !defined(Q_OS_WIN) && !defined(Q_OS_MAC) | - | ||||||||||||||||||||||||||||||||||||
| 289 | QSettingsPrivate *QSettingsPrivate::create(QSettings::Format format, QSettings::Scope scope, | - | ||||||||||||||||||||||||||||||||||||
| 290 | const QString &organization, const QString &application) | - | ||||||||||||||||||||||||||||||||||||
| 291 | { | - | ||||||||||||||||||||||||||||||||||||
| 292 | return new QConfFileSettingsPrivate(format, scope, organization, application); executed 1422 times by 7 tests: return new QConfFileSettingsPrivate(format, scope, organization, application);Executed by:
| 1422 | ||||||||||||||||||||||||||||||||||||
| 293 | } | - | ||||||||||||||||||||||||||||||||||||
| 294 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 295 | - | |||||||||||||||||||||||||||||||||||||
| 296 | #if !defined(Q_OS_WIN) | - | ||||||||||||||||||||||||||||||||||||
| 297 | QSettingsPrivate *QSettingsPrivate::create(const QString &fileName, QSettings::Format format) | - | ||||||||||||||||||||||||||||||||||||
| 298 | { | - | ||||||||||||||||||||||||||||||||||||
| 299 | return new QConfFileSettingsPrivate(fileName, format); executed 119 times by 28 tests: return new QConfFileSettingsPrivate(fileName, format);Executed by:
| 119 | ||||||||||||||||||||||||||||||||||||
| 300 | } | - | ||||||||||||||||||||||||||||||||||||
| 301 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 302 | - | |||||||||||||||||||||||||||||||||||||
| 303 | void QSettingsPrivate::processChild(QStringRef key, ChildSpec spec, QStringList &result) | - | ||||||||||||||||||||||||||||||||||||
| 304 | { | - | ||||||||||||||||||||||||||||||||||||
| 305 | if (spec != AllKeys) {
| 2860-30653 | ||||||||||||||||||||||||||||||||||||
| 306 | int slashPos = key.indexOf(QLatin1Char('/')); | - | ||||||||||||||||||||||||||||||||||||
| 307 | if (slashPos == -1) {
| 304-2556 | ||||||||||||||||||||||||||||||||||||
| 308 | if (spec != ChildKeys)
| 152 | ||||||||||||||||||||||||||||||||||||
| 309 | return; executed 152 times by 1 test: return;Executed by:
| 152 | ||||||||||||||||||||||||||||||||||||
| 310 | } else { executed 152 times by 1 test: end of blockExecuted by:
| 152 | ||||||||||||||||||||||||||||||||||||
| 311 | if (spec != ChildGroups)
| 328-2228 | ||||||||||||||||||||||||||||||||||||
| 312 | return; executed 328 times by 1 test: return;Executed by:
| 328 | ||||||||||||||||||||||||||||||||||||
| 313 | key.truncate(slashPos); | - | ||||||||||||||||||||||||||||||||||||
| 314 | } executed 2228 times by 5 tests: end of blockExecuted by:
| 2228 | ||||||||||||||||||||||||||||||||||||
| 315 | } | - | ||||||||||||||||||||||||||||||||||||
| 316 | result.append(key.toString()); | - | ||||||||||||||||||||||||||||||||||||
| 317 | } executed 33033 times by 27 tests: end of blockExecuted by:
| 33033 | ||||||||||||||||||||||||||||||||||||
| 318 | - | |||||||||||||||||||||||||||||||||||||
| 319 | void QSettingsPrivate::beginGroupOrArray(const QSettingsGroup &group) | - | ||||||||||||||||||||||||||||||||||||
| 320 | { | - | ||||||||||||||||||||||||||||||||||||
| 321 | groupStack.push(group); | - | ||||||||||||||||||||||||||||||||||||
| 322 | if (!group.name().isEmpty()) {
| 43-1284 | ||||||||||||||||||||||||||||||||||||
| 323 | groupPrefix += group.name(); | - | ||||||||||||||||||||||||||||||||||||
| 324 | groupPrefix += QLatin1Char('/'); | - | ||||||||||||||||||||||||||||||||||||
| 325 | } executed 1284 times by 6 tests: end of blockExecuted by:
| 1284 | ||||||||||||||||||||||||||||||||||||
| 326 | } executed 1327 times by 6 tests: end of blockExecuted by:
| 1327 | ||||||||||||||||||||||||||||||||||||
| 327 | - | |||||||||||||||||||||||||||||||||||||
| 328 | /* | - | ||||||||||||||||||||||||||||||||||||
| 329 | We only set an error if there isn't one set already. This way the user always gets the | - | ||||||||||||||||||||||||||||||||||||
| 330 | first error that occurred. We always allow clearing errors. | - | ||||||||||||||||||||||||||||||||||||
| 331 | */ | - | ||||||||||||||||||||||||||||||||||||
| 332 | - | |||||||||||||||||||||||||||||||||||||
| 333 | void QSettingsPrivate::setStatus(QSettings::Status status) const | - | ||||||||||||||||||||||||||||||||||||
| 334 | { | - | ||||||||||||||||||||||||||||||||||||
| 335 | if (status == QSettings::NoError || this->status == QSettings::NoError)
| 0-40 | ||||||||||||||||||||||||||||||||||||
| 336 | this->status = status; executed 37 times by 3 tests: this->status = status;Executed by:
| 37 | ||||||||||||||||||||||||||||||||||||
| 337 | } executed 40 times by 3 tests: end of blockExecuted by:
| 40 | ||||||||||||||||||||||||||||||||||||
| 338 | - | |||||||||||||||||||||||||||||||||||||
| 339 | void QSettingsPrivate::update() | - | ||||||||||||||||||||||||||||||||||||
| 340 | { | - | ||||||||||||||||||||||||||||||||||||
| 341 | flush(); | - | ||||||||||||||||||||||||||||||||||||
| 342 | pendingChanges = false; | - | ||||||||||||||||||||||||||||||||||||
| 343 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||||||||||||||||||||
| 344 | - | |||||||||||||||||||||||||||||||||||||
| 345 | void QSettingsPrivate::requestUpdate() | - | ||||||||||||||||||||||||||||||||||||
| 346 | { | - | ||||||||||||||||||||||||||||||||||||
| 347 | if (!pendingChanges) {
| 565-2149 | ||||||||||||||||||||||||||||||||||||
| 348 | pendingChanges = true; | - | ||||||||||||||||||||||||||||||||||||
| 349 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||||||||||||||||||||
| 350 | Q_Q(QSettings); | - | ||||||||||||||||||||||||||||||||||||
| 351 | QCoreApplication::postEvent(q, new QEvent(QEvent::UpdateRequest)); | - | ||||||||||||||||||||||||||||||||||||
| 352 | #else | - | ||||||||||||||||||||||||||||||||||||
| 353 | update(); | - | ||||||||||||||||||||||||||||||||||||
| 354 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 355 | } executed 565 times by 6 tests: end of blockExecuted by:
| 565 | ||||||||||||||||||||||||||||||||||||
| 356 | } executed 2714 times by 6 tests: end of blockExecuted by:
| 2714 | ||||||||||||||||||||||||||||||||||||
| 357 | - | |||||||||||||||||||||||||||||||||||||
| 358 | QStringList QSettingsPrivate::variantListToStringList(const QVariantList &l) | - | ||||||||||||||||||||||||||||||||||||
| 359 | { | - | ||||||||||||||||||||||||||||||||||||
| 360 | QStringList result; | - | ||||||||||||||||||||||||||||||||||||
| 361 | result.reserve(l.count()); | - | ||||||||||||||||||||||||||||||||||||
| 362 | QVariantList::const_iterator it = l.constBegin(); | - | ||||||||||||||||||||||||||||||||||||
| 363 | for (; it != l.constEnd(); ++it)
| 522-1079 | ||||||||||||||||||||||||||||||||||||
| 364 | result.append(variantToString(*it)); executed 1079 times by 6 tests: result.append(variantToString(*it));Executed by:
| 1079 | ||||||||||||||||||||||||||||||||||||
| 365 | return result; executed 522 times by 6 tests: return result;Executed by:
| 522 | ||||||||||||||||||||||||||||||||||||
| 366 | } | - | ||||||||||||||||||||||||||||||||||||
| 367 | - | |||||||||||||||||||||||||||||||||||||
| 368 | QVariant QSettingsPrivate::stringListToVariantList(const QStringList &l) | - | ||||||||||||||||||||||||||||||||||||
| 369 | { | - | ||||||||||||||||||||||||||||||||||||
| 370 | QStringList outStringList = l; | - | ||||||||||||||||||||||||||||||||||||
| 371 | for (int i = 0; i < outStringList.count(); ++i) {
| 47-8740 | ||||||||||||||||||||||||||||||||||||
| 372 | const QString &str = outStringList.at(i); | - | ||||||||||||||||||||||||||||||||||||
| 373 | - | |||||||||||||||||||||||||||||||||||||
| 374 | if (str.startsWith(QLatin1Char('@'))) {
| 34-8706 | ||||||||||||||||||||||||||||||||||||
| 375 | if (str.length() >= 2 && str.at(1) == QLatin1Char('@')) {
| 0-34 | ||||||||||||||||||||||||||||||||||||
| 376 | outStringList[i].remove(0, 1); | - | ||||||||||||||||||||||||||||||||||||
| 377 | } else { executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||||||||||||||||||||
| 378 | QVariantList variantList; | - | ||||||||||||||||||||||||||||||||||||
| 379 | const int stringCount = l.count(); | - | ||||||||||||||||||||||||||||||||||||
| 380 | variantList.reserve(stringCount); | - | ||||||||||||||||||||||||||||||||||||
| 381 | for (int j = 0; j < stringCount; ++j)
| 30-258 | ||||||||||||||||||||||||||||||||||||
| 382 | variantList.append(stringToVariant(l.at(j))); executed 258 times by 1 test: variantList.append(stringToVariant(l.at(j)));Executed by:
| 258 | ||||||||||||||||||||||||||||||||||||
| 383 | return variantList; executed 30 times by 1 test: return variantList;Executed by:
| 30 | ||||||||||||||||||||||||||||||||||||
| 384 | } | - | ||||||||||||||||||||||||||||||||||||
| 385 | } | - | ||||||||||||||||||||||||||||||||||||
| 386 | } executed 8710 times by 28 tests: end of blockExecuted by:
| 8710 | ||||||||||||||||||||||||||||||||||||
| 387 | return outStringList; executed 47 times by 28 tests: return outStringList;Executed by:
| 47 | ||||||||||||||||||||||||||||||||||||
| 388 | } | - | ||||||||||||||||||||||||||||||||||||
| 389 | - | |||||||||||||||||||||||||||||||||||||
| 390 | QString QSettingsPrivate::variantToString(const QVariant &v) | - | ||||||||||||||||||||||||||||||||||||
| 391 | { | - | ||||||||||||||||||||||||||||||||||||
| 392 | QString result; | - | ||||||||||||||||||||||||||||||||||||
| 393 | - | |||||||||||||||||||||||||||||||||||||
| 394 | switch (v.type()) { | - | ||||||||||||||||||||||||||||||||||||
| 395 | case QVariant::Invalid: never executed: case QVariant::Invalid: | 0 | ||||||||||||||||||||||||||||||||||||
| 396 | result = QLatin1String("@Invalid()"); | - | ||||||||||||||||||||||||||||||||||||
| 397 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||
| 398 | - | |||||||||||||||||||||||||||||||||||||
| 399 | case QVariant::ByteArray: { executed 252 times by 6 tests: case QVariant::ByteArray:Executed by:
| 252 | ||||||||||||||||||||||||||||||||||||
| 400 | QByteArray a = v.toByteArray(); | - | ||||||||||||||||||||||||||||||||||||
| 401 | result = QLatin1String("@ByteArray("); | - | ||||||||||||||||||||||||||||||||||||
| 402 | result += QString::fromLatin1(a.constData(), a.size()); | - | ||||||||||||||||||||||||||||||||||||
| 403 | result += QLatin1Char(')'); | - | ||||||||||||||||||||||||||||||||||||
| 404 | break; executed 252 times by 6 tests: break;Executed by:
| 252 | ||||||||||||||||||||||||||||||||||||
| 405 | } | - | ||||||||||||||||||||||||||||||||||||
| 406 | - | |||||||||||||||||||||||||||||||||||||
| 407 | case QVariant::String: executed 1861 times by 6 tests: case QVariant::String:Executed by:
| 1861 | ||||||||||||||||||||||||||||||||||||
| 408 | case QVariant::LongLong: never executed: case QVariant::LongLong: | 0 | ||||||||||||||||||||||||||||||||||||
| 409 | case QVariant::ULongLong: never executed: case QVariant::ULongLong: | 0 | ||||||||||||||||||||||||||||||||||||
| 410 | case QVariant::Int: executed 630 times by 5 tests: case QVariant::Int:Executed by:
| 630 | ||||||||||||||||||||||||||||||||||||
| 411 | case QVariant::UInt: executed 96 times by 2 tests: case QVariant::UInt:Executed by:
| 96 | ||||||||||||||||||||||||||||||||||||
| 412 | case QVariant::Bool: executed 4 times by 1 test: case QVariant::Bool:Executed by:
| 4 | ||||||||||||||||||||||||||||||||||||
| 413 | case QVariant::Double: never executed: case QVariant::Double: | 0 | ||||||||||||||||||||||||||||||||||||
| 414 | case QVariant::KeySequence: { executed 2 times by 1 test: case QVariant::KeySequence:Executed by:
| 2 | ||||||||||||||||||||||||||||||||||||
| 415 | result = v.toString(); | - | ||||||||||||||||||||||||||||||||||||
| 416 | if (result.contains(QChar::Null))
| 2-2591 | ||||||||||||||||||||||||||||||||||||
| 417 | result = QLatin1String("@String(") + result + QLatin1Char(')'); executed 2 times by 1 test: result = QLatin1String("@String(") + result + QLatin1Char(')');Executed by:
| 2 | ||||||||||||||||||||||||||||||||||||
| 418 | else if (result.startsWith(QLatin1Char('@')))
| 7-2584 | ||||||||||||||||||||||||||||||||||||
| 419 | result.prepend(QLatin1Char('@')); executed 7 times by 1 test: result.prepend(QLatin1Char('@'));Executed by:
| 7 | ||||||||||||||||||||||||||||||||||||
| 420 | break; executed 2593 times by 6 tests: break;Executed by:
| 2593 | ||||||||||||||||||||||||||||||||||||
| 421 | } | - | ||||||||||||||||||||||||||||||||||||
| 422 | #ifndef QT_NO_GEOM_VARIANT | - | ||||||||||||||||||||||||||||||||||||
| 423 | case QVariant::Rect: { executed 43 times by 1 test: case QVariant::Rect:Executed by:
| 43 | ||||||||||||||||||||||||||||||||||||
| 424 | QRect r = qvariant_cast<QRect>(v); | - | ||||||||||||||||||||||||||||||||||||
| 425 | result += QLatin1String("@Rect("); | - | ||||||||||||||||||||||||||||||||||||
| 426 | result += QString::number(r.x()); | - | ||||||||||||||||||||||||||||||||||||
| 427 | result += QLatin1Char(' '); | - | ||||||||||||||||||||||||||||||||||||
| 428 | result += QString::number(r.y()); | - | ||||||||||||||||||||||||||||||||||||
| 429 | result += QLatin1Char(' '); | - | ||||||||||||||||||||||||||||||||||||
| 430 | result += QString::number(r.width()); | - | ||||||||||||||||||||||||||||||||||||
| 431 | result += QLatin1Char(' '); | - | ||||||||||||||||||||||||||||||||||||
| 432 | result += QString::number(r.height()); | - | ||||||||||||||||||||||||||||||||||||
| 433 | result += QLatin1Char(')'); | - | ||||||||||||||||||||||||||||||||||||
| 434 | break; executed 43 times by 1 test: break;Executed by:
| 43 | ||||||||||||||||||||||||||||||||||||
| 435 | } | - | ||||||||||||||||||||||||||||||||||||
| 436 | case QVariant::Size: { executed 41 times by 1 test: case QVariant::Size:Executed by:
| 41 | ||||||||||||||||||||||||||||||||||||
| 437 | QSize s = qvariant_cast<QSize>(v); | - | ||||||||||||||||||||||||||||||||||||
| 438 | result += QLatin1String("@Size("); | - | ||||||||||||||||||||||||||||||||||||
| 439 | result += QString::number(s.width()); | - | ||||||||||||||||||||||||||||||||||||
| 440 | result += QLatin1Char(' '); | - | ||||||||||||||||||||||||||||||||||||
| 441 | result += QString::number(s.height()); | - | ||||||||||||||||||||||||||||||||||||
| 442 | result += QLatin1Char(')'); | - | ||||||||||||||||||||||||||||||||||||
| 443 | break; executed 41 times by 1 test: break;Executed by:
| 41 | ||||||||||||||||||||||||||||||||||||
| 444 | } | - | ||||||||||||||||||||||||||||||||||||
| 445 | case QVariant::Point: { executed 39 times by 1 test: case QVariant::Point:Executed by:
| 39 | ||||||||||||||||||||||||||||||||||||
| 446 | QPoint p = qvariant_cast<QPoint>(v); | - | ||||||||||||||||||||||||||||||||||||
| 447 | result += QLatin1String("@Point("); | - | ||||||||||||||||||||||||||||||||||||
| 448 | result += QString::number(p.x()); | - | ||||||||||||||||||||||||||||||||||||
| 449 | result += QLatin1Char(' '); | - | ||||||||||||||||||||||||||||||||||||
| 450 | result += QString::number(p.y()); | - | ||||||||||||||||||||||||||||||||||||
| 451 | result += QLatin1Char(')'); | - | ||||||||||||||||||||||||||||||||||||
| 452 | break; executed 39 times by 1 test: break;Executed by:
| 39 | ||||||||||||||||||||||||||||||||||||
| 453 | } | - | ||||||||||||||||||||||||||||||||||||
| 454 | #endif // !QT_NO_GEOM_VARIANT | - | ||||||||||||||||||||||||||||||||||||
| 455 | - | |||||||||||||||||||||||||||||||||||||
| 456 | default: { executed 176 times by 1 test: default:Executed by:
| 176 | ||||||||||||||||||||||||||||||||||||
| 457 | #ifndef QT_NO_DATASTREAM | - | ||||||||||||||||||||||||||||||||||||
| 458 | QDataStream::Version version; | - | ||||||||||||||||||||||||||||||||||||
| 459 | const char *typeSpec; | - | ||||||||||||||||||||||||||||||||||||
| 460 | if (v.type() == QVariant::DateTime) {
| 4-172 | ||||||||||||||||||||||||||||||||||||
| 461 | version = QDataStream::Qt_5_6; | - | ||||||||||||||||||||||||||||||||||||
| 462 | typeSpec = "@DateTime("; | - | ||||||||||||||||||||||||||||||||||||
| 463 | } else { executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||||||||||||||||||||
| 464 | version = QDataStream::Qt_4_0; | - | ||||||||||||||||||||||||||||||||||||
| 465 | typeSpec = "@Variant("; | - | ||||||||||||||||||||||||||||||||||||
| 466 | } executed 172 times by 1 test: end of blockExecuted by:
| 172 | ||||||||||||||||||||||||||||||||||||
| 467 | QByteArray a; | - | ||||||||||||||||||||||||||||||||||||
| 468 | { | - | ||||||||||||||||||||||||||||||||||||
| 469 | QDataStream s(&a, QIODevice::WriteOnly); | - | ||||||||||||||||||||||||||||||||||||
| 470 | s.setVersion(version); | - | ||||||||||||||||||||||||||||||||||||
| 471 | s << v; | - | ||||||||||||||||||||||||||||||||||||
| 472 | } | - | ||||||||||||||||||||||||||||||||||||
| 473 | - | |||||||||||||||||||||||||||||||||||||
| 474 | result = QLatin1String(typeSpec); | - | ||||||||||||||||||||||||||||||||||||
| 475 | result += QString::fromLatin1(a.constData(), a.size()); | - | ||||||||||||||||||||||||||||||||||||
| 476 | result += QLatin1Char(')'); | - | ||||||||||||||||||||||||||||||||||||
| 477 | #else | - | ||||||||||||||||||||||||||||||||||||
| 478 | Q_ASSERT(!"QSettings: Cannot save custom types without QDataStream support"); | - | ||||||||||||||||||||||||||||||||||||
| 479 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 480 | break; executed 176 times by 1 test: break;Executed by:
| 176 | ||||||||||||||||||||||||||||||||||||
| 481 | } | - | ||||||||||||||||||||||||||||||||||||
| 482 | } | - | ||||||||||||||||||||||||||||||||||||
| 483 | - | |||||||||||||||||||||||||||||||||||||
| 484 | return result; executed 3144 times by 6 tests: return result;Executed by:
| 3144 | ||||||||||||||||||||||||||||||||||||
| 485 | } | - | ||||||||||||||||||||||||||||||||||||
| 486 | - | |||||||||||||||||||||||||||||||||||||
| 487 | - | |||||||||||||||||||||||||||||||||||||
| 488 | QVariant QSettingsPrivate::stringToVariant(const QString &s) | - | ||||||||||||||||||||||||||||||||||||
| 489 | { | - | ||||||||||||||||||||||||||||||||||||
| 490 | if (s.startsWith(QLatin1Char('@'))) {
| 314-29937 | ||||||||||||||||||||||||||||||||||||
| 491 | if (s.endsWith(QLatin1Char(')'))) {
| 7-307 | ||||||||||||||||||||||||||||||||||||
| 492 | if (s.startsWith(QLatin1String("@ByteArray("))) {
| 13-294 | ||||||||||||||||||||||||||||||||||||
| 493 | return QVariant(s.midRef(11, s.size() - 12).toLatin1()); executed 13 times by 4 tests: return QVariant(s.midRef(11, s.size() - 12).toLatin1());Executed by:
| 13 | ||||||||||||||||||||||||||||||||||||
| 494 | } else if (s.startsWith(QLatin1String("@String("))) {
| 0-294 | ||||||||||||||||||||||||||||||||||||
| 495 | return QVariant(s.midRef(8, s.size() - 9).toString()); never executed: return QVariant(s.midRef(8, s.size() - 9).toString()); | 0 | ||||||||||||||||||||||||||||||||||||
| 496 | } else if (s.startsWith(QLatin1String("@Variant("))
| 131-163 | ||||||||||||||||||||||||||||||||||||
| 497 | || s.startsWith(QLatin1String("@DateTime("))) {
| 4-127 | ||||||||||||||||||||||||||||||||||||
| 498 | #ifndef QT_NO_DATASTREAM | - | ||||||||||||||||||||||||||||||||||||
| 499 | QDataStream::Version version; | - | ||||||||||||||||||||||||||||||||||||
| 500 | int offset; | - | ||||||||||||||||||||||||||||||||||||
| 501 | if (s.at(1) == QLatin1Char('D')) {
| 4-163 | ||||||||||||||||||||||||||||||||||||
| 502 | version = QDataStream::Qt_5_6; | - | ||||||||||||||||||||||||||||||||||||
| 503 | offset = 10; | - | ||||||||||||||||||||||||||||||||||||
| 504 | } else { executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||||||||||||||||||||
| 505 | version = QDataStream::Qt_4_0; | - | ||||||||||||||||||||||||||||||||||||
| 506 | offset = 9; | - | ||||||||||||||||||||||||||||||||||||
| 507 | } executed 163 times by 1 test: end of blockExecuted by:
| 163 | ||||||||||||||||||||||||||||||||||||
| 508 | QByteArray a = s.midRef(offset).toLatin1(); | - | ||||||||||||||||||||||||||||||||||||
| 509 | QDataStream stream(&a, QIODevice::ReadOnly); | - | ||||||||||||||||||||||||||||||||||||
| 510 | stream.setVersion(version); | - | ||||||||||||||||||||||||||||||||||||
| 511 | QVariant result; | - | ||||||||||||||||||||||||||||||||||||
| 512 | stream >> result; | - | ||||||||||||||||||||||||||||||||||||
| 513 | return result; executed 167 times by 1 test: return result;Executed by:
| 167 | ||||||||||||||||||||||||||||||||||||
| 514 | #else | - | ||||||||||||||||||||||||||||||||||||
| 515 | Q_ASSERT(!"QSettings: Cannot load custom types without QDataStream support"); | - | ||||||||||||||||||||||||||||||||||||
| 516 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 517 | #ifndef QT_NO_GEOM_VARIANT | - | ||||||||||||||||||||||||||||||||||||
| 518 | } else if (s.startsWith(QLatin1String("@Rect("))) {
| 45-82 | ||||||||||||||||||||||||||||||||||||
| 519 | QStringList args = QSettingsPrivate::splitArgs(s, 5); | - | ||||||||||||||||||||||||||||||||||||
| 520 | if (args.size() == 4)
| 2-43 | ||||||||||||||||||||||||||||||||||||
| 521 | return QVariant(QRect(args[0].toInt(), args[1].toInt(), args[2].toInt(), args[3].toInt())); executed 43 times by 1 test: return QVariant(QRect(args[0].toInt(), args[1].toInt(), args[2].toInt(), args[3].toInt()));Executed by:
| 43 | ||||||||||||||||||||||||||||||||||||
| 522 | } else if (s.startsWith(QLatin1String("@Size("))) { executed 2 times by 1 test: end of blockExecuted by:
| 2-41 | ||||||||||||||||||||||||||||||||||||
| 523 | QStringList args = QSettingsPrivate::splitArgs(s, 5); | - | ||||||||||||||||||||||||||||||||||||
| 524 | if (args.size() == 2)
| 0-41 | ||||||||||||||||||||||||||||||||||||
| 525 | return QVariant(QSize(args[0].toInt(), args[1].toInt())); executed 41 times by 1 test: return QVariant(QSize(args[0].toInt(), args[1].toInt()));Executed by:
| 41 | ||||||||||||||||||||||||||||||||||||
| 526 | } else if (s.startsWith(QLatin1String("@Point("))) { never executed: end of block
| 0-39 | ||||||||||||||||||||||||||||||||||||
| 527 | QStringList args = QSettingsPrivate::splitArgs(s, 6); | - | ||||||||||||||||||||||||||||||||||||
| 528 | if (args.size() == 2)
| 0-39 | ||||||||||||||||||||||||||||||||||||
| 529 | return QVariant(QPoint(args[0].toInt(), args[1].toInt())); executed 39 times by 1 test: return QVariant(QPoint(args[0].toInt(), args[1].toInt()));Executed by:
| 39 | ||||||||||||||||||||||||||||||||||||
| 530 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 531 | } else if (s == QLatin1String("@Invalid()")) { never executed: end of block
| 0-2 | ||||||||||||||||||||||||||||||||||||
| 532 | return QVariant(); never executed: return QVariant(); | 0 | ||||||||||||||||||||||||||||||||||||
| 533 | } | - | ||||||||||||||||||||||||||||||||||||
| 534 | - | |||||||||||||||||||||||||||||||||||||
| 535 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||||||||||||||||||||
| 536 | if (s.startsWith(QLatin1String("@@")))
| 5-6 | ||||||||||||||||||||||||||||||||||||
| 537 | return QVariant(s.mid(1)); executed 5 times by 1 test: return QVariant(s.mid(1));Executed by:
| 5 | ||||||||||||||||||||||||||||||||||||
| 538 | } executed 6 times by 1 test: end of blockExecuted by:
| 6 | ||||||||||||||||||||||||||||||||||||
| 539 | - | |||||||||||||||||||||||||||||||||||||
| 540 | return QVariant(s); executed 29943 times by 28 tests: return QVariant(s);Executed by:
| 29943 | ||||||||||||||||||||||||||||||||||||
| 541 | } | - | ||||||||||||||||||||||||||||||||||||
| 542 | - | |||||||||||||||||||||||||||||||||||||
| 543 | static const char hexDigits[] = "0123456789ABCDEF"; | - | ||||||||||||||||||||||||||||||||||||
| 544 | - | |||||||||||||||||||||||||||||||||||||
| 545 | void QSettingsPrivate::iniEscapedKey(const QString &key, QByteArray &result) | - | ||||||||||||||||||||||||||||||||||||
| 546 | { | - | ||||||||||||||||||||||||||||||||||||
| 547 | result.reserve(result.length() + key.length() * 3 / 2); | - | ||||||||||||||||||||||||||||||||||||
| 548 | for (int i = 0; i < key.size(); ++i) {
| 3010-25953 | ||||||||||||||||||||||||||||||||||||
| 549 | uint ch = key.at(i).unicode(); | - | ||||||||||||||||||||||||||||||||||||
| 550 | - | |||||||||||||||||||||||||||||||||||||
| 551 | if (ch == '/') {
| 448-25505 | ||||||||||||||||||||||||||||||||||||
| 552 | result += '\\'; | - | ||||||||||||||||||||||||||||||||||||
| 553 | } else if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9') executed 448 times by 4 tests: end of blockExecuted by:
| 13-22317 | ||||||||||||||||||||||||||||||||||||
| 554 | || ch == '_' || ch == '-' || ch == '.') {
| 1-131 | ||||||||||||||||||||||||||||||||||||
| 555 | result += (char)ch; | - | ||||||||||||||||||||||||||||||||||||
| 556 | } else if (ch <= 0xFF) { executed 25378 times by 6 tests: end of blockExecuted by:
| 5-25378 | ||||||||||||||||||||||||||||||||||||
| 557 | result += '%'; | - | ||||||||||||||||||||||||||||||||||||
| 558 | result += hexDigits[ch / 16]; | - | ||||||||||||||||||||||||||||||||||||
| 559 | result += hexDigits[ch % 16]; | - | ||||||||||||||||||||||||||||||||||||
| 560 | } else { executed 122 times by 1 test: end of blockExecuted by:
| 122 | ||||||||||||||||||||||||||||||||||||
| 561 | result += "%U"; | - | ||||||||||||||||||||||||||||||||||||
| 562 | QByteArray hexCode; | - | ||||||||||||||||||||||||||||||||||||
| 563 | for (int i = 0; i < 4; ++i) {
| 5-20 | ||||||||||||||||||||||||||||||||||||
| 564 | hexCode.prepend(hexDigits[ch % 16]); | - | ||||||||||||||||||||||||||||||||||||
| 565 | ch >>= 4; | - | ||||||||||||||||||||||||||||||||||||
| 566 | } executed 20 times by 1 test: end of blockExecuted by:
| 20 | ||||||||||||||||||||||||||||||||||||
| 567 | result += hexCode; | - | ||||||||||||||||||||||||||||||||||||
| 568 | } executed 5 times by 1 test: end of blockExecuted by:
| 5 | ||||||||||||||||||||||||||||||||||||
| 569 | } | - | ||||||||||||||||||||||||||||||||||||
| 570 | } executed 3010 times by 6 tests: end of blockExecuted by:
| 3010 | ||||||||||||||||||||||||||||||||||||
| 571 | - | |||||||||||||||||||||||||||||||||||||
| 572 | bool QSettingsPrivate::iniUnescapedKey(const QByteArray &key, int from, int to, QString &result) | - | ||||||||||||||||||||||||||||||||||||
| 573 | { | - | ||||||||||||||||||||||||||||||||||||
| 574 | bool lowercaseOnly = true; | - | ||||||||||||||||||||||||||||||||||||
| 575 | int i = from; | - | ||||||||||||||||||||||||||||||||||||
| 576 | result.reserve(result.length() + (to - from)); | - | ||||||||||||||||||||||||||||||||||||
| 577 | while (i < to) {
| 38766-293991 | ||||||||||||||||||||||||||||||||||||
| 578 | int ch = (uchar)key.at(i); | - | ||||||||||||||||||||||||||||||||||||
| 579 | - | |||||||||||||||||||||||||||||||||||||
| 580 | if (ch == '\\') {
| 227-293764 | ||||||||||||||||||||||||||||||||||||
| 581 | result += QLatin1Char('/'); | - | ||||||||||||||||||||||||||||||||||||
| 582 | ++i; | - | ||||||||||||||||||||||||||||||||||||
| 583 | continue; executed 227 times by 4 tests: continue;Executed by:
| 227 | ||||||||||||||||||||||||||||||||||||
| 584 | } | - | ||||||||||||||||||||||||||||||||||||
| 585 | - | |||||||||||||||||||||||||||||||||||||
| 586 | if (ch != '%' || i == to - 1) {
| 2-293695 | ||||||||||||||||||||||||||||||||||||
| 587 | if (uint(ch - 'A') <= 'Z' - 'A') // only for ASCII
| 33340-260357 | ||||||||||||||||||||||||||||||||||||
| 588 | lowercaseOnly = false; executed 33340 times by 28 tests: lowercaseOnly = false;Executed by:
| 33340 | ||||||||||||||||||||||||||||||||||||
| 589 | result += QLatin1Char(ch); | - | ||||||||||||||||||||||||||||||||||||
| 590 | ++i; | - | ||||||||||||||||||||||||||||||||||||
| 591 | continue; executed 293697 times by 28 tests: continue;Executed by:
| 293697 | ||||||||||||||||||||||||||||||||||||
| 592 | } | - | ||||||||||||||||||||||||||||||||||||
| 593 | - | |||||||||||||||||||||||||||||||||||||
| 594 | int numDigits = 2; | - | ||||||||||||||||||||||||||||||||||||
| 595 | int firstDigitPos = i + 1; | - | ||||||||||||||||||||||||||||||||||||
| 596 | - | |||||||||||||||||||||||||||||||||||||
| 597 | ch = key.at(i + 1); | - | ||||||||||||||||||||||||||||||||||||
| 598 | if (ch == 'U') {
| 9-58 | ||||||||||||||||||||||||||||||||||||
| 599 | ++firstDigitPos; | - | ||||||||||||||||||||||||||||||||||||
| 600 | numDigits = 4; | - | ||||||||||||||||||||||||||||||||||||
| 601 | } executed 9 times by 1 test: end of blockExecuted by:
| 9 | ||||||||||||||||||||||||||||||||||||
| 602 | - | |||||||||||||||||||||||||||||||||||||
| 603 | if (firstDigitPos + numDigits > to) {
| 0-67 | ||||||||||||||||||||||||||||||||||||
| 604 | result += QLatin1Char('%'); | - | ||||||||||||||||||||||||||||||||||||
| 605 | // ### missing U | - | ||||||||||||||||||||||||||||||||||||
| 606 | ++i; | - | ||||||||||||||||||||||||||||||||||||
| 607 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||||||||||||||
| 608 | } | - | ||||||||||||||||||||||||||||||||||||
| 609 | - | |||||||||||||||||||||||||||||||||||||
| 610 | bool ok; | - | ||||||||||||||||||||||||||||||||||||
| 611 | ch = key.mid(firstDigitPos, numDigits).toInt(&ok, 16); | - | ||||||||||||||||||||||||||||||||||||
| 612 | if (!ok) {
| 10-57 | ||||||||||||||||||||||||||||||||||||
| 613 | result += QLatin1Char('%'); | - | ||||||||||||||||||||||||||||||||||||
| 614 | // ### missing U | - | ||||||||||||||||||||||||||||||||||||
| 615 | ++i; | - | ||||||||||||||||||||||||||||||||||||
| 616 | continue; executed 10 times by 1 test: continue;Executed by:
| 10 | ||||||||||||||||||||||||||||||||||||
| 617 | } | - | ||||||||||||||||||||||||||||||||||||
| 618 | - | |||||||||||||||||||||||||||||||||||||
| 619 | QChar qch(ch); | - | ||||||||||||||||||||||||||||||||||||
| 620 | if (qch.isUpper())
| 3-54 | ||||||||||||||||||||||||||||||||||||
| 621 | lowercaseOnly = false; executed 3 times by 1 test: lowercaseOnly = false;Executed by:
| 3 | ||||||||||||||||||||||||||||||||||||
| 622 | result += qch; | - | ||||||||||||||||||||||||||||||||||||
| 623 | i = firstDigitPos + numDigits; | - | ||||||||||||||||||||||||||||||||||||
| 624 | } executed 57 times by 1 test: end of blockExecuted by:
| 57 | ||||||||||||||||||||||||||||||||||||
| 625 | return lowercaseOnly; executed 38766 times by 28 tests: return lowercaseOnly;Executed by:
| 38766 | ||||||||||||||||||||||||||||||||||||
| 626 | } | - | ||||||||||||||||||||||||||||||||||||
| 627 | - | |||||||||||||||||||||||||||||||||||||
| 628 | void QSettingsPrivate::iniEscapedString(const QString &str, QByteArray &result, QTextCodec *codec) | - | ||||||||||||||||||||||||||||||||||||
| 629 | { | - | ||||||||||||||||||||||||||||||||||||
| 630 | bool needsQuotes = false; | - | ||||||||||||||||||||||||||||||||||||
| 631 | bool escapeNextIfDigit = false; | - | ||||||||||||||||||||||||||||||||||||
| 632 | bool useCodec = codec && !str.startsWith(QLatin1String("@ByteArray("))
| 1-3167 | ||||||||||||||||||||||||||||||||||||
| 633 | && !str.startsWith(QLatin1String("@Variant("));
| 0-2 | ||||||||||||||||||||||||||||||||||||
| 634 | - | |||||||||||||||||||||||||||||||||||||
| 635 | int i; | - | ||||||||||||||||||||||||||||||||||||
| 636 | int startPos = result.size(); | - | ||||||||||||||||||||||||||||||||||||
| 637 | - | |||||||||||||||||||||||||||||||||||||
| 638 | result.reserve(startPos + str.size() * 3 / 2); | - | ||||||||||||||||||||||||||||||||||||
| 639 | const QChar *unicode = str.unicode(); | - | ||||||||||||||||||||||||||||||||||||
| 640 | for (i = 0; i < str.size(); ++i) {
| 3170-88383 | ||||||||||||||||||||||||||||||||||||
| 641 | uint ch = unicode[i].unicode(); | - | ||||||||||||||||||||||||||||||||||||
| 642 | if (ch == ';' || ch == ',' || ch == '=')
| 3-88380 | ||||||||||||||||||||||||||||||||||||
| 643 | needsQuotes = true; executed 11 times by 1 test: needsQuotes = true;Executed by:
| 11 | ||||||||||||||||||||||||||||||||||||
| 644 | - | |||||||||||||||||||||||||||||||||||||
| 645 | if (escapeNextIfDigit
| 36158-52225 | ||||||||||||||||||||||||||||||||||||
| 646 | && ((ch >= '0' && ch <= '9')
| 16-31663 | ||||||||||||||||||||||||||||||||||||
| 647 | || (ch >= 'a' && ch <= 'f')
| 823-32246 | ||||||||||||||||||||||||||||||||||||
| 648 | || (ch >= 'A' && ch <= 'F'))) {
| 525-31664 | ||||||||||||||||||||||||||||||||||||
| 649 | result += "\\x"; | - | ||||||||||||||||||||||||||||||||||||
| 650 | result += QByteArray::number(ch, 16); | - | ||||||||||||||||||||||||||||||||||||
| 651 | continue; executed 1364 times by 6 tests: continue;Executed by:
| 1364 | ||||||||||||||||||||||||||||||||||||
| 652 | } | - | ||||||||||||||||||||||||||||||||||||
| 653 | - | |||||||||||||||||||||||||||||||||||||
| 654 | escapeNextIfDigit = false; | - | ||||||||||||||||||||||||||||||||||||
| 655 | - | |||||||||||||||||||||||||||||||||||||
| 656 | switch (ch) { | - | ||||||||||||||||||||||||||||||||||||
| 657 | case '\0': executed 28664 times by 6 tests: case '\0':Executed by:
| 28664 | ||||||||||||||||||||||||||||||||||||
| 658 | result += "\\0"; | - | ||||||||||||||||||||||||||||||||||||
| 659 | escapeNextIfDigit = true; | - | ||||||||||||||||||||||||||||||||||||
| 660 | break; executed 28664 times by 6 tests: break;Executed by:
| 28664 | ||||||||||||||||||||||||||||||||||||
| 661 | case '\a': executed 3 times by 1 test: case '\a':Executed by:
| 3 | ||||||||||||||||||||||||||||||||||||
| 662 | result += "\\a"; | - | ||||||||||||||||||||||||||||||||||||
| 663 | break; executed 3 times by 1 test: break;Executed by:
| 3 | ||||||||||||||||||||||||||||||||||||
| 664 | case '\b': executed 125 times by 1 test: case '\b':Executed by:
| 125 | ||||||||||||||||||||||||||||||||||||
| 665 | result += "\\b"; | - | ||||||||||||||||||||||||||||||||||||
| 666 | break; executed 125 times by 1 test: break;Executed by:
| 125 | ||||||||||||||||||||||||||||||||||||
| 667 | case '\f': executed 4 times by 1 test: case '\f':Executed by:
| 4 | ||||||||||||||||||||||||||||||||||||
| 668 | result += "\\f"; | - | ||||||||||||||||||||||||||||||||||||
| 669 | break; executed 4 times by 1 test: break;Executed by:
| 4 | ||||||||||||||||||||||||||||||||||||
| 670 | case '\n': executed 229 times by 1 test: case '\n':Executed by:
| 229 | ||||||||||||||||||||||||||||||||||||
| 671 | result += "\\n"; | - | ||||||||||||||||||||||||||||||||||||
| 672 | break; executed 229 times by 1 test: break;Executed by:
| 229 | ||||||||||||||||||||||||||||||||||||
| 673 | case '\r': executed 4 times by 1 test: case '\r':Executed by:
| 4 | ||||||||||||||||||||||||||||||||||||
| 674 | result += "\\r"; | - | ||||||||||||||||||||||||||||||||||||
| 675 | break; executed 4 times by 1 test: break;Executed by:
| 4 | ||||||||||||||||||||||||||||||||||||
| 676 | case '\t': executed 28 times by 1 test: case '\t':Executed by:
| 28 | ||||||||||||||||||||||||||||||||||||
| 677 | result += "\\t"; | - | ||||||||||||||||||||||||||||||||||||
| 678 | break; executed 28 times by 1 test: break;Executed by:
| 28 | ||||||||||||||||||||||||||||||||||||
| 679 | case '\v': executed 8 times by 1 test: case '\v':Executed by:
| 8 | ||||||||||||||||||||||||||||||||||||
| 680 | result += "\\v"; | - | ||||||||||||||||||||||||||||||||||||
| 681 | break; executed 8 times by 1 test: break;Executed by:
| 8 | ||||||||||||||||||||||||||||||||||||
| 682 | case '"': executed 3 times by 1 test: case '"':Executed by:
| 3 | ||||||||||||||||||||||||||||||||||||
| 683 | case '\\': executed 4 times by 1 test: case '\\':Executed by:
| 4 | ||||||||||||||||||||||||||||||||||||
| 684 | result += '\\'; | - | ||||||||||||||||||||||||||||||||||||
| 685 | result += (char)ch; | - | ||||||||||||||||||||||||||||||||||||
| 686 | break; executed 7 times by 1 test: break;Executed by:
| 7 | ||||||||||||||||||||||||||||||||||||
| 687 | default: executed 57947 times by 6 tests: default:Executed by:
| 57947 | ||||||||||||||||||||||||||||||||||||
| 688 | if (ch <= 0x1F || (ch >= 0x7F && !useCodec)) {
| 4-54330 | ||||||||||||||||||||||||||||||||||||
| 689 | result += "\\x"; | - | ||||||||||||||||||||||||||||||||||||
| 690 | result += QByteArray::number(ch, 16); | - | ||||||||||||||||||||||||||||||||||||
| 691 | escapeNextIfDigit = true; | - | ||||||||||||||||||||||||||||||||||||
| 692 | #ifndef QT_NO_TEXTCODEC | - | ||||||||||||||||||||||||||||||||||||
| 693 | } else if (useCodec) { executed 6134 times by 6 tests: end of blockExecuted by:
| 26-51787 | ||||||||||||||||||||||||||||||||||||
| 694 | // slow | - | ||||||||||||||||||||||||||||||||||||
| 695 | result += codec->fromUnicode(&unicode[i], 1); | - | ||||||||||||||||||||||||||||||||||||
| 696 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 697 | } else { executed 26 times by 1 test: end of blockExecuted by:
| 26 | ||||||||||||||||||||||||||||||||||||
| 698 | result += (char)ch; | - | ||||||||||||||||||||||||||||||||||||
| 699 | } executed 51787 times by 6 tests: end of blockExecuted by:
| 51787 | ||||||||||||||||||||||||||||||||||||
| 700 | } | - | ||||||||||||||||||||||||||||||||||||
| 701 | } | - | ||||||||||||||||||||||||||||||||||||
| 702 | - | |||||||||||||||||||||||||||||||||||||
| 703 | if (needsQuotes
| 8-3162 | ||||||||||||||||||||||||||||||||||||
| 704 | || (startPos < result.size() && (result.at(startPos) == ' '
| 3-3126 | ||||||||||||||||||||||||||||||||||||
| 705 | || result.at(result.size() - 1) == ' '))) {
| 3-3120 | ||||||||||||||||||||||||||||||||||||
| 706 | result.insert(startPos, '"'); | - | ||||||||||||||||||||||||||||||||||||
| 707 | result += '"'; | - | ||||||||||||||||||||||||||||||||||||
| 708 | } executed 14 times by 1 test: end of blockExecuted by:
| 14 | ||||||||||||||||||||||||||||||||||||
| 709 | } executed 3170 times by 6 tests: end of blockExecuted by:
| 3170 | ||||||||||||||||||||||||||||||||||||
| 710 | - | |||||||||||||||||||||||||||||||||||||
| 711 | inline static void iniChopTrailingSpaces(QString &str, int limit) | - | ||||||||||||||||||||||||||||||||||||
| 712 | { | - | ||||||||||||||||||||||||||||||||||||
| 713 | int n = str.size() - 1; | - | ||||||||||||||||||||||||||||||||||||
| 714 | QChar ch; | - | ||||||||||||||||||||||||||||||||||||
| 715 | while (n >= limit && ((ch = str.at(n)) == QLatin1Char(' ') || ch == QLatin1Char('\t')))
| 0-38903 | ||||||||||||||||||||||||||||||||||||
| 716 | str.truncate(n--); executed 12 times by 1 test: str.truncate(n--);Executed by:
| 12 | ||||||||||||||||||||||||||||||||||||
| 717 | } executed 38919 times by 28 tests: end of blockExecuted by:
| 38919 | ||||||||||||||||||||||||||||||||||||
| 718 | - | |||||||||||||||||||||||||||||||||||||
| 719 | void QSettingsPrivate::iniEscapedStringList(const QStringList &strs, QByteArray &result, QTextCodec *codec) | - | ||||||||||||||||||||||||||||||||||||
| 720 | { | - | ||||||||||||||||||||||||||||||||||||
| 721 | if (strs.isEmpty()) {
| 4-539 | ||||||||||||||||||||||||||||||||||||
| 722 | /* | - | ||||||||||||||||||||||||||||||||||||
| 723 | We need to distinguish between empty lists and one-item | - | ||||||||||||||||||||||||||||||||||||
| 724 | lists that contain an empty string. Ideally, we'd have a | - | ||||||||||||||||||||||||||||||||||||
| 725 | @EmptyList() symbol but that would break compatibility | - | ||||||||||||||||||||||||||||||||||||
| 726 | with Qt 4.0. @Invalid() stands for QVariant(), and | - | ||||||||||||||||||||||||||||||||||||
| 727 | QVariant().toStringList() returns an empty QStringList, | - | ||||||||||||||||||||||||||||||||||||
| 728 | so we're in good shape. | - | ||||||||||||||||||||||||||||||||||||
| 729 | */ | - | ||||||||||||||||||||||||||||||||||||
| 730 | result += "@Invalid()"; | - | ||||||||||||||||||||||||||||||||||||
| 731 | } else { executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||||||||||||||||||||
| 732 | for (int i = 0; i < strs.size(); ++i) {
| 539-1116 | ||||||||||||||||||||||||||||||||||||
| 733 | if (i != 0)
| 539-577 | ||||||||||||||||||||||||||||||||||||
| 734 | result += ", "; executed 577 times by 6 tests: result += ", ";Executed by:
| 577 | ||||||||||||||||||||||||||||||||||||
| 735 | iniEscapedString(strs.at(i), result, codec); | - | ||||||||||||||||||||||||||||||||||||
| 736 | } executed 1116 times by 6 tests: end of blockExecuted by:
| 1116 | ||||||||||||||||||||||||||||||||||||
| 737 | } executed 539 times by 6 tests: end of blockExecuted by:
| 539 | ||||||||||||||||||||||||||||||||||||
| 738 | } | - | ||||||||||||||||||||||||||||||||||||
| 739 | - | |||||||||||||||||||||||||||||||||||||
| 740 | bool QSettingsPrivate::iniUnescapedStringList(const QByteArray &str, int from, int to, | - | ||||||||||||||||||||||||||||||||||||
| 741 | QString &stringResult, QStringList &stringListResult, | - | ||||||||||||||||||||||||||||||||||||
| 742 | QTextCodec *codec) | - | ||||||||||||||||||||||||||||||||||||
| 743 | { | - | ||||||||||||||||||||||||||||||||||||
| 744 | static const char escapeCodes[][2] = | - | ||||||||||||||||||||||||||||||||||||
| 745 | { | - | ||||||||||||||||||||||||||||||||||||
| 746 | { 'a', '\a' }, | - | ||||||||||||||||||||||||||||||||||||
| 747 | { 'b', '\b' }, | - | ||||||||||||||||||||||||||||||||||||
| 748 | { 'f', '\f' }, | - | ||||||||||||||||||||||||||||||||||||
| 749 | { 'n', '\n' }, | - | ||||||||||||||||||||||||||||||||||||
| 750 | { 'r', '\r' }, | - | ||||||||||||||||||||||||||||||||||||
| 751 | { 't', '\t' }, | - | ||||||||||||||||||||||||||||||||||||
| 752 | { 'v', '\v' }, | - | ||||||||||||||||||||||||||||||||||||
| 753 | { '"', '"' }, | - | ||||||||||||||||||||||||||||||||||||
| 754 | { '?', '?' }, | - | ||||||||||||||||||||||||||||||||||||
| 755 | { '\'', '\'' }, | - | ||||||||||||||||||||||||||||||||||||
| 756 | { '\\', '\\' } | - | ||||||||||||||||||||||||||||||||||||
| 757 | }; | - | ||||||||||||||||||||||||||||||||||||
| 758 | static const int numEscapeCodes = sizeof(escapeCodes) / sizeof(escapeCodes[0]); | - | ||||||||||||||||||||||||||||||||||||
| 759 | - | |||||||||||||||||||||||||||||||||||||
| 760 | bool isStringList = false; | - | ||||||||||||||||||||||||||||||||||||
| 761 | bool inQuotedString = false; | - | ||||||||||||||||||||||||||||||||||||
| 762 | bool currentValueIsQuoted = false; | - | ||||||||||||||||||||||||||||||||||||
| 763 | int escapeVal = 0; | - | ||||||||||||||||||||||||||||||||||||
| 764 | int i = from; | - | ||||||||||||||||||||||||||||||||||||
| 765 | char ch; | - | ||||||||||||||||||||||||||||||||||||
| 766 | - | |||||||||||||||||||||||||||||||||||||
| 767 | StSkipSpaces: code before this statement executed 30077 times by 28 tests: StSkipSpaces:Executed by:
| 30077 | ||||||||||||||||||||||||||||||||||||
| 768 | while (i < to && ((ch = str.at(i)) == ' ' || ch == '\t'))
| 2-39234 | ||||||||||||||||||||||||||||||||||||
| 769 | ++i; executed 285 times by 5 tests: ++i;Executed by:
| 285 | ||||||||||||||||||||||||||||||||||||
| 770 | // fallthrough | - | ||||||||||||||||||||||||||||||||||||
| 771 | - | |||||||||||||||||||||||||||||||||||||
| 772 | StNormal: code before this statement executed 38969 times by 28 tests: StNormal:Executed by:
| 38969 | ||||||||||||||||||||||||||||||||||||
| 773 | int chopLimit = stringResult.length(); | - | ||||||||||||||||||||||||||||||||||||
| 774 | while (i < to) {
| 30071-54069 | ||||||||||||||||||||||||||||||||||||
| 775 | switch (str.at(i)) { | - | ||||||||||||||||||||||||||||||||||||
| 776 | case '\\': executed 5551 times by 4 tests: case '\\':Executed by:
| 5551 | ||||||||||||||||||||||||||||||||||||
| 777 | ++i; | - | ||||||||||||||||||||||||||||||||||||
| 778 | if (i >= to)
| 3-5548 | ||||||||||||||||||||||||||||||||||||
| 779 | goto end; executed 3 times by 1 test: goto end;Executed by:
| 3 | ||||||||||||||||||||||||||||||||||||
| 780 | - | |||||||||||||||||||||||||||||||||||||
| 781 | ch = str.at(i++); | - | ||||||||||||||||||||||||||||||||||||
| 782 | for (int j = 0; j < numEscapeCodes; ++j) {
| 5198-58414 | ||||||||||||||||||||||||||||||||||||
| 783 | if (ch == escapeCodes[j][0]) {
| 350-58064 | ||||||||||||||||||||||||||||||||||||
| 784 | stringResult += QLatin1Char(escapeCodes[j][1]); | - | ||||||||||||||||||||||||||||||||||||
| 785 | goto StNormal; executed 350 times by 1 test: goto StNormal;Executed by:
| 350 | ||||||||||||||||||||||||||||||||||||
| 786 | } | - | ||||||||||||||||||||||||||||||||||||
| 787 | } executed 58064 times by 4 tests: end of blockExecuted by:
| 58064 | ||||||||||||||||||||||||||||||||||||
| 788 | - | |||||||||||||||||||||||||||||||||||||
| 789 | if (ch == 'x') {
| 1612-3586 | ||||||||||||||||||||||||||||||||||||
| 790 | escapeVal = 0; | - | ||||||||||||||||||||||||||||||||||||
| 791 | - | |||||||||||||||||||||||||||||||||||||
| 792 | if (i >= to)
| 0-1612 | ||||||||||||||||||||||||||||||||||||
| 793 | goto end; never executed: goto end; | 0 | ||||||||||||||||||||||||||||||||||||
| 794 | - | |||||||||||||||||||||||||||||||||||||
| 795 | ch = str.at(i); | - | ||||||||||||||||||||||||||||||||||||
| 796 | if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'F') || (ch >= 'a' && ch <= 'f'))
| 0-1612 | ||||||||||||||||||||||||||||||||||||
| 797 | goto StHexEscape; executed 1611 times by 4 tests: goto StHexEscape;Executed by:
| 1611 | ||||||||||||||||||||||||||||||||||||
| 798 | } else if (ch >= '0' && ch <= '7') { executed 1 time by 1 test: end of blockExecuted by:
| 1-3571 | ||||||||||||||||||||||||||||||||||||
| 799 | escapeVal = ch - '0'; | - | ||||||||||||||||||||||||||||||||||||
| 800 | goto StOctEscape; executed 3567 times by 4 tests: goto StOctEscape;Executed by:
| 3567 | ||||||||||||||||||||||||||||||||||||
| 801 | } else if (ch == '\n' || ch == '\r') {
| 6-13 | ||||||||||||||||||||||||||||||||||||
| 802 | if (i < to) {
| 5-7 | ||||||||||||||||||||||||||||||||||||
| 803 | char ch2 = str.at(i); | - | ||||||||||||||||||||||||||||||||||||
| 804 | // \n, \r, \r\n, and \n\r are legitimate line terminators in INI files | - | ||||||||||||||||||||||||||||||||||||
| 805 | if ((ch2 == '\n' || ch2 == '\r') && ch2 != ch)
| 0-5 | ||||||||||||||||||||||||||||||||||||
| 806 | ++i; executed 5 times by 1 test: ++i;Executed by:
| 5 | ||||||||||||||||||||||||||||||||||||
| 807 | } executed 7 times by 1 test: end of blockExecuted by:
| 7 | ||||||||||||||||||||||||||||||||||||
| 808 | } else { executed 12 times by 1 test: end of blockExecuted by:
| 12 | ||||||||||||||||||||||||||||||||||||
| 809 | // the character is skipped | - | ||||||||||||||||||||||||||||||||||||
| 810 | } executed 7 times by 1 test: end of blockExecuted by:
| 7 | ||||||||||||||||||||||||||||||||||||
| 811 | chopLimit = stringResult.length(); | - | ||||||||||||||||||||||||||||||||||||
| 812 | break; executed 20 times by 1 test: break;Executed by:
| 20 | ||||||||||||||||||||||||||||||||||||
| 813 | case '"': executed 44 times by 1 test: case '"':Executed by:
| 44 | ||||||||||||||||||||||||||||||||||||
| 814 | ++i; | - | ||||||||||||||||||||||||||||||||||||
| 815 | currentValueIsQuoted = true; | - | ||||||||||||||||||||||||||||||||||||
| 816 | inQuotedString = !inQuotedString; | - | ||||||||||||||||||||||||||||||||||||
| 817 | if (!inQuotedString)
| 20-24 | ||||||||||||||||||||||||||||||||||||
| 818 | goto StSkipSpaces; executed 20 times by 1 test: goto StSkipSpaces;Executed by:
| 20 | ||||||||||||||||||||||||||||||||||||
| 819 | break; executed 24 times by 1 test: break;Executed by:
| 24 | ||||||||||||||||||||||||||||||||||||
| 820 | case ',': executed 8876 times by 28 tests: case ',':Executed by:
| 8876 | ||||||||||||||||||||||||||||||||||||
| 821 | if (!inQuotedString) {
| 4-8872 | ||||||||||||||||||||||||||||||||||||
| 822 | if (!currentValueIsQuoted)
| 9-8863 | ||||||||||||||||||||||||||||||||||||
| 823 | iniChopTrailingSpaces(stringResult, chopLimit); executed 8863 times by 28 tests: iniChopTrailingSpaces(stringResult, chopLimit);Executed by:
| 8863 | ||||||||||||||||||||||||||||||||||||
| 824 | if (!isStringList) {
| 82-8790 | ||||||||||||||||||||||||||||||||||||
| 825 | isStringList = true; | - | ||||||||||||||||||||||||||||||||||||
| 826 | stringListResult.clear(); | - | ||||||||||||||||||||||||||||||||||||
| 827 | stringResult.squeeze(); | - | ||||||||||||||||||||||||||||||||||||
| 828 | } executed 82 times by 28 tests: end of blockExecuted by:
| 82 | ||||||||||||||||||||||||||||||||||||
| 829 | stringListResult.append(stringResult); | - | ||||||||||||||||||||||||||||||||||||
| 830 | stringResult.clear(); | - | ||||||||||||||||||||||||||||||||||||
| 831 | currentValueIsQuoted = false; | - | ||||||||||||||||||||||||||||||||||||
| 832 | ++i; | - | ||||||||||||||||||||||||||||||||||||
| 833 | goto StSkipSpaces; executed 8872 times by 28 tests: goto StSkipSpaces;Executed by:
| 8872 | ||||||||||||||||||||||||||||||||||||
| 834 | } | - | ||||||||||||||||||||||||||||||||||||
| 835 | // fallthrough | - | ||||||||||||||||||||||||||||||||||||
| 836 | default: { code before this statement executed 4 times by 1 test: default:Executed by:
executed 39602 times by 28 tests: default:Executed by:
| 4-39602 | ||||||||||||||||||||||||||||||||||||
| 837 | int j = i + 1; | - | ||||||||||||||||||||||||||||||||||||
| 838 | while (j < to) {
| 30040-273956 | ||||||||||||||||||||||||||||||||||||
| 839 | ch = str.at(j); | - | ||||||||||||||||||||||||||||||||||||
| 840 | if (ch == '\\' || ch == '"' || ch == ',')
| 17-273268 | ||||||||||||||||||||||||||||||||||||
| 841 | break; executed 9562 times by 28 tests: break;Executed by:
| 9562 | ||||||||||||||||||||||||||||||||||||
| 842 | ++j; | - | ||||||||||||||||||||||||||||||||||||
| 843 | } executed 264394 times by 28 tests: end of blockExecuted by:
| 264394 | ||||||||||||||||||||||||||||||||||||
| 844 | - | |||||||||||||||||||||||||||||||||||||
| 845 | #ifdef QT_NO_TEXTCODEC | - | ||||||||||||||||||||||||||||||||||||
| 846 | Q_UNUSED(codec) | - | ||||||||||||||||||||||||||||||||||||
| 847 | #else | - | ||||||||||||||||||||||||||||||||||||
| 848 | if (codec) {
| 4-39598 | ||||||||||||||||||||||||||||||||||||
| 849 | stringResult += codec->toUnicode(str.constData() + i, j - i); | - | ||||||||||||||||||||||||||||||||||||
| 850 | } else executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||||||||||||||||||||
| 851 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 852 | { | - | ||||||||||||||||||||||||||||||||||||
| 853 | int n = stringResult.size(); | - | ||||||||||||||||||||||||||||||||||||
| 854 | stringResult.resize(n + (j - i)); | - | ||||||||||||||||||||||||||||||||||||
| 855 | QChar *resultData = stringResult.data() + n; | - | ||||||||||||||||||||||||||||||||||||
| 856 | for (int k = i; k < j; ++k)
| 39598-303960 | ||||||||||||||||||||||||||||||||||||
| 857 | *resultData++ = QLatin1Char(str.at(k)); executed 303960 times by 28 tests: *resultData++ = QLatin1Char(str.at(k));Executed by:
| 303960 | ||||||||||||||||||||||||||||||||||||
| 858 | } executed 39598 times by 28 tests: end of blockExecuted by:
| 39598 | ||||||||||||||||||||||||||||||||||||
| 859 | i = j; | - | ||||||||||||||||||||||||||||||||||||
| 860 | } | - | ||||||||||||||||||||||||||||||||||||
| 861 | } executed 39602 times by 28 tests: end of blockExecuted by:
| 39602 | ||||||||||||||||||||||||||||||||||||
| 862 | } | - | ||||||||||||||||||||||||||||||||||||
| 863 | if (!currentValueIsQuoted)
| 15-30056 | ||||||||||||||||||||||||||||||||||||
| 864 | iniChopTrailingSpaces(stringResult, chopLimit); executed 30056 times by 28 tests: iniChopTrailingSpaces(stringResult, chopLimit);Executed by:
| 30056 | ||||||||||||||||||||||||||||||||||||
| 865 | goto end; executed 30071 times by 28 tests: goto end;Executed by:
| 30071 | ||||||||||||||||||||||||||||||||||||
| 866 | - | |||||||||||||||||||||||||||||||||||||
| 867 | StHexEscape: | - | ||||||||||||||||||||||||||||||||||||
| 868 | if (i >= to) {
| 3-4168 | ||||||||||||||||||||||||||||||||||||
| 869 | stringResult += QChar(escapeVal); | - | ||||||||||||||||||||||||||||||||||||
| 870 | goto end; executed 3 times by 1 test: goto end;Executed by:
| 3 | ||||||||||||||||||||||||||||||||||||
| 871 | } | - | ||||||||||||||||||||||||||||||||||||
| 872 | - | |||||||||||||||||||||||||||||||||||||
| 873 | ch = str.at(i); | - | ||||||||||||||||||||||||||||||||||||
| 874 | if (ch >= 'a')
| 495-3673 | ||||||||||||||||||||||||||||||||||||
| 875 | ch -= 'a' - 'A'; executed 495 times by 4 tests: ch -= 'a' - 'A';Executed by:
| 495 | ||||||||||||||||||||||||||||||||||||
| 876 | if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'F')) {
| 123-4045 | ||||||||||||||||||||||||||||||||||||
| 877 | escapeVal <<= 4; | - | ||||||||||||||||||||||||||||||||||||
| 878 | escapeVal += strchr(hexDigits, ch) - hexDigits; | - | ||||||||||||||||||||||||||||||||||||
| 879 | ++i; | - | ||||||||||||||||||||||||||||||||||||
| 880 | goto StHexEscape; executed 2560 times by 4 tests: goto StHexEscape;Executed by:
| 2560 | ||||||||||||||||||||||||||||||||||||
| 881 | } else { | - | ||||||||||||||||||||||||||||||||||||
| 882 | stringResult += QChar(escapeVal); | - | ||||||||||||||||||||||||||||||||||||
| 883 | goto StNormal; executed 1608 times by 4 tests: goto StNormal;Executed by:
| 1608 | ||||||||||||||||||||||||||||||||||||
| 884 | } | - | ||||||||||||||||||||||||||||||||||||
| 885 | - | |||||||||||||||||||||||||||||||||||||
| 886 | StOctEscape: | - | ||||||||||||||||||||||||||||||||||||
| 887 | if (i >= to) {
| 0-3582 | ||||||||||||||||||||||||||||||||||||
| 888 | stringResult += QChar(escapeVal); | - | ||||||||||||||||||||||||||||||||||||
| 889 | goto end; never executed: goto end; | 0 | ||||||||||||||||||||||||||||||||||||
| 890 | } | - | ||||||||||||||||||||||||||||||||||||
| 891 | - | |||||||||||||||||||||||||||||||||||||
| 892 | ch = str.at(i); | - | ||||||||||||||||||||||||||||||||||||
| 893 | if (ch >= '0' && ch <= '7') {
| 15-3489 | ||||||||||||||||||||||||||||||||||||
| 894 | escapeVal <<= 3; | - | ||||||||||||||||||||||||||||||||||||
| 895 | escapeVal += ch - '0'; | - | ||||||||||||||||||||||||||||||||||||
| 896 | ++i; | - | ||||||||||||||||||||||||||||||||||||
| 897 | goto StOctEscape; executed 15 times by 1 test: goto StOctEscape;Executed by:
| 15 | ||||||||||||||||||||||||||||||||||||
| 898 | } else { | - | ||||||||||||||||||||||||||||||||||||
| 899 | stringResult += QChar(escapeVal); | - | ||||||||||||||||||||||||||||||||||||
| 900 | goto StNormal; executed 3567 times by 4 tests: goto StNormal;Executed by:
| 3567 | ||||||||||||||||||||||||||||||||||||
| 901 | } | - | ||||||||||||||||||||||||||||||||||||
| 902 | - | |||||||||||||||||||||||||||||||||||||
| 903 | end: | - | ||||||||||||||||||||||||||||||||||||
| 904 | if (isStringList)
| 82-29995 | ||||||||||||||||||||||||||||||||||||
| 905 | stringListResult.append(stringResult); executed 82 times by 28 tests: stringListResult.append(stringResult);Executed by:
| 82 | ||||||||||||||||||||||||||||||||||||
| 906 | return isStringList; executed 30077 times by 28 tests: return isStringList;Executed by:
| 30077 | ||||||||||||||||||||||||||||||||||||
| 907 | } | - | ||||||||||||||||||||||||||||||||||||
| 908 | - | |||||||||||||||||||||||||||||||||||||
| 909 | QStringList QSettingsPrivate::splitArgs(const QString &s, int idx) | - | ||||||||||||||||||||||||||||||||||||
| 910 | { | - | ||||||||||||||||||||||||||||||||||||
| 911 | int l = s.length(); | - | ||||||||||||||||||||||||||||||||||||
| 912 | Q_ASSERT(l > 0); | - | ||||||||||||||||||||||||||||||||||||
| 913 | Q_ASSERT(s.at(idx) == QLatin1Char('(')); | - | ||||||||||||||||||||||||||||||||||||
| 914 | Q_ASSERT(s.at(l - 1) == QLatin1Char(')')); | - | ||||||||||||||||||||||||||||||||||||
| 915 | - | |||||||||||||||||||||||||||||||||||||
| 916 | QStringList result; | - | ||||||||||||||||||||||||||||||||||||
| 917 | QString item; | - | ||||||||||||||||||||||||||||||||||||
| 918 | - | |||||||||||||||||||||||||||||||||||||
| 919 | for (++idx; idx < l; ++idx) {
| 125-711 | ||||||||||||||||||||||||||||||||||||
| 920 | QChar c = s.at(idx); | - | ||||||||||||||||||||||||||||||||||||
| 921 | if (c == QLatin1Char(')')) {
| 125-586 | ||||||||||||||||||||||||||||||||||||
| 922 | Q_ASSERT(idx == l - 1); | - | ||||||||||||||||||||||||||||||||||||
| 923 | result.append(item); | - | ||||||||||||||||||||||||||||||||||||
| 924 | } else if (c == QLatin1Char(' ')) { executed 125 times by 1 test: end of blockExecuted by:
| 125-375 | ||||||||||||||||||||||||||||||||||||
| 925 | result.append(item); | - | ||||||||||||||||||||||||||||||||||||
| 926 | item.clear(); | - | ||||||||||||||||||||||||||||||||||||
| 927 | } else { executed 211 times by 1 test: end of blockExecuted by:
| 211 | ||||||||||||||||||||||||||||||||||||
| 928 | item.append(c); | - | ||||||||||||||||||||||||||||||||||||
| 929 | } executed 375 times by 1 test: end of blockExecuted by:
| 375 | ||||||||||||||||||||||||||||||||||||
| 930 | } | - | ||||||||||||||||||||||||||||||||||||
| 931 | - | |||||||||||||||||||||||||||||||||||||
| 932 | return result; executed 125 times by 1 test: return result;Executed by:
| 125 | ||||||||||||||||||||||||||||||||||||
| 933 | } | - | ||||||||||||||||||||||||||||||||||||
| 934 | - | |||||||||||||||||||||||||||||||||||||
| 935 | // ************************************************************************ | - | ||||||||||||||||||||||||||||||||||||
| 936 | // QConfFileSettingsPrivate | - | ||||||||||||||||||||||||||||||||||||
| 937 | - | |||||||||||||||||||||||||||||||||||||
| 938 | void QConfFileSettingsPrivate::initFormat() | - | ||||||||||||||||||||||||||||||||||||
| 939 | { | - | ||||||||||||||||||||||||||||||||||||
| 940 | extension = (format == QSettings::NativeFormat) ? QLatin1String(".conf") : QLatin1String(".ini");
| 368-1173 | ||||||||||||||||||||||||||||||||||||
| 941 | readFunc = 0; | - | ||||||||||||||||||||||||||||||||||||
| 942 | writeFunc = 0; | - | ||||||||||||||||||||||||||||||||||||
| 943 | #if defined(Q_OS_MAC) | - | ||||||||||||||||||||||||||||||||||||
| 944 | caseSensitivity = (format == QSettings::NativeFormat) ? Qt::CaseSensitive : IniCaseSensitivity; | - | ||||||||||||||||||||||||||||||||||||
| 945 | #else | - | ||||||||||||||||||||||||||||||||||||
| 946 | caseSensitivity = IniCaseSensitivity; | - | ||||||||||||||||||||||||||||||||||||
| 947 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 948 | - | |||||||||||||||||||||||||||||||||||||
| 949 | if (format > QSettings::IniFormat) {
| 176-1365 | ||||||||||||||||||||||||||||||||||||
| 950 | QMutexLocker locker(&settingsGlobalMutex); | - | ||||||||||||||||||||||||||||||||||||
| 951 | const CustomFormatVector *customFormatVector = customFormatVectorFunc(); | - | ||||||||||||||||||||||||||||||||||||
| 952 | - | |||||||||||||||||||||||||||||||||||||
| 953 | int i = (int)format - (int)QSettings::CustomFormat1; | - | ||||||||||||||||||||||||||||||||||||
| 954 | if (i >= 0 && i < customFormatVector->size()) {
| 0-176 | ||||||||||||||||||||||||||||||||||||
| 955 | QConfFileCustomFormat info = customFormatVector->at(i); | - | ||||||||||||||||||||||||||||||||||||
| 956 | extension = info.extension; | - | ||||||||||||||||||||||||||||||||||||
| 957 | readFunc = info.readFunc; | - | ||||||||||||||||||||||||||||||||||||
| 958 | writeFunc = info.writeFunc; | - | ||||||||||||||||||||||||||||||||||||
| 959 | caseSensitivity = info.caseSensitivity; | - | ||||||||||||||||||||||||||||||||||||
| 960 | } executed 175 times by 1 test: end of blockExecuted by:
| 175 | ||||||||||||||||||||||||||||||||||||
| 961 | } executed 176 times by 1 test: end of blockExecuted by:
| 176 | ||||||||||||||||||||||||||||||||||||
| 962 | } executed 1541 times by 30 tests: end of blockExecuted by:
| 1541 | ||||||||||||||||||||||||||||||||||||
| 963 | - | |||||||||||||||||||||||||||||||||||||
| 964 | void QConfFileSettingsPrivate::initAccess() | - | ||||||||||||||||||||||||||||||||||||
| 965 | { | - | ||||||||||||||||||||||||||||||||||||
| 966 | if (confFiles[spec]) {
| 0-1541 | ||||||||||||||||||||||||||||||||||||
| 967 | if (format > QSettings::IniFormat) {
| 176-1365 | ||||||||||||||||||||||||||||||||||||
| 968 | if (!readFunc)
| 1-175 | ||||||||||||||||||||||||||||||||||||
| 969 | setStatus(QSettings::AccessError); executed 1 time by 1 test: setStatus(QSettings::AccessError);Executed by:
| 1 | ||||||||||||||||||||||||||||||||||||
| 970 | } executed 176 times by 1 test: end of blockExecuted by:
| 176 | ||||||||||||||||||||||||||||||||||||
| 971 | } executed 1541 times by 30 tests: end of blockExecuted by:
| 1541 | ||||||||||||||||||||||||||||||||||||
| 972 | - | |||||||||||||||||||||||||||||||||||||
| 973 | sync(); // loads the files the first time | - | ||||||||||||||||||||||||||||||||||||
| 974 | } executed 1541 times by 30 tests: end of blockExecuted by:
| 1541 | ||||||||||||||||||||||||||||||||||||
| 975 | - | |||||||||||||||||||||||||||||||||||||
| 976 | #if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) | - | ||||||||||||||||||||||||||||||||||||
| 977 | static QString windowsConfigPath(int type) | - | ||||||||||||||||||||||||||||||||||||
| 978 | { | - | ||||||||||||||||||||||||||||||||||||
| 979 | QString result; | - | ||||||||||||||||||||||||||||||||||||
| 980 | - | |||||||||||||||||||||||||||||||||||||
| 981 | wchar_t path[MAX_PATH]; | - | ||||||||||||||||||||||||||||||||||||
| 982 | if (SHGetSpecialFolderPath(0, path, type, false)) | - | ||||||||||||||||||||||||||||||||||||
| 983 | result = QString::fromWCharArray(path); | - | ||||||||||||||||||||||||||||||||||||
| 984 | - | |||||||||||||||||||||||||||||||||||||
| 985 | if (result.isEmpty()) { | - | ||||||||||||||||||||||||||||||||||||
| 986 | switch (type) { | - | ||||||||||||||||||||||||||||||||||||
| 987 | #ifndef Q_OS_WINCE | - | ||||||||||||||||||||||||||||||||||||
| 988 | case CSIDL_COMMON_APPDATA: | - | ||||||||||||||||||||||||||||||||||||
| 989 | result = QLatin1String("C:\\temp\\qt-common"); | - | ||||||||||||||||||||||||||||||||||||
| 990 | break; | - | ||||||||||||||||||||||||||||||||||||
| 991 | case CSIDL_APPDATA: | - | ||||||||||||||||||||||||||||||||||||
| 992 | result = QLatin1String("C:\\temp\\qt-user"); | - | ||||||||||||||||||||||||||||||||||||
| 993 | break; | - | ||||||||||||||||||||||||||||||||||||
| 994 | #else | - | ||||||||||||||||||||||||||||||||||||
| 995 | case CSIDL_COMMON_APPDATA: | - | ||||||||||||||||||||||||||||||||||||
| 996 | result = QLatin1String("\\Temp\\qt-common"); | - | ||||||||||||||||||||||||||||||||||||
| 997 | break; | - | ||||||||||||||||||||||||||||||||||||
| 998 | case CSIDL_APPDATA: | - | ||||||||||||||||||||||||||||||||||||
| 999 | result = QLatin1String("\\Temp\\qt-user"); | - | ||||||||||||||||||||||||||||||||||||
| 1000 | break; | - | ||||||||||||||||||||||||||||||||||||
| 1001 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 1002 | default: | - | ||||||||||||||||||||||||||||||||||||
| 1003 | ; | - | ||||||||||||||||||||||||||||||||||||
| 1004 | } | - | ||||||||||||||||||||||||||||||||||||
| 1005 | } | - | ||||||||||||||||||||||||||||||||||||
| 1006 | - | |||||||||||||||||||||||||||||||||||||
| 1007 | return result; | - | ||||||||||||||||||||||||||||||||||||
| 1008 | } | - | ||||||||||||||||||||||||||||||||||||
| 1009 | #elif defined(Q_OS_WINRT) // Q_OS_WIN && !Q_OS_WINRT | - | ||||||||||||||||||||||||||||||||||||
| 1010 | static QString windowsConfigPath(int type) | - | ||||||||||||||||||||||||||||||||||||
| 1011 | { | - | ||||||||||||||||||||||||||||||||||||
| 1012 | static QString result; | - | ||||||||||||||||||||||||||||||||||||
| 1013 | while (result.isEmpty()) { | - | ||||||||||||||||||||||||||||||||||||
| 1014 | ComPtr<IApplicationDataStatics> applicationDataStatics; | - | ||||||||||||||||||||||||||||||||||||
| 1015 | if (FAILED(GetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Storage_ApplicationData).Get(), &applicationDataStatics))) | - | ||||||||||||||||||||||||||||||||||||
| 1016 | return result; | - | ||||||||||||||||||||||||||||||||||||
| 1017 | ComPtr<IApplicationData> applicationData; | - | ||||||||||||||||||||||||||||||||||||
| 1018 | if (FAILED(applicationDataStatics->get_Current(&applicationData))) | - | ||||||||||||||||||||||||||||||||||||
| 1019 | return result; | - | ||||||||||||||||||||||||||||||||||||
| 1020 | ComPtr<IStorageFolder> localFolder; | - | ||||||||||||||||||||||||||||||||||||
| 1021 | if (FAILED(applicationData->get_LocalFolder(&localFolder))) | - | ||||||||||||||||||||||||||||||||||||
| 1022 | return result; | - | ||||||||||||||||||||||||||||||||||||
| 1023 | ComPtr<IStorageItem> localFolderItem; | - | ||||||||||||||||||||||||||||||||||||
| 1024 | if (FAILED(localFolder.As(&localFolderItem))) | - | ||||||||||||||||||||||||||||||||||||
| 1025 | return result; | - | ||||||||||||||||||||||||||||||||||||
| 1026 | HString path; | - | ||||||||||||||||||||||||||||||||||||
| 1027 | if (FAILED(localFolderItem->get_Path(path.GetAddressOf()))) | - | ||||||||||||||||||||||||||||||||||||
| 1028 | return result; | - | ||||||||||||||||||||||||||||||||||||
| 1029 | result = QString::fromWCharArray(path.GetRawBuffer(nullptr)); | - | ||||||||||||||||||||||||||||||||||||
| 1030 | } | - | ||||||||||||||||||||||||||||||||||||
| 1031 | - | |||||||||||||||||||||||||||||||||||||
| 1032 | switch (type) { | - | ||||||||||||||||||||||||||||||||||||
| 1033 | case CSIDL_COMMON_APPDATA: | - | ||||||||||||||||||||||||||||||||||||
| 1034 | return result + QLatin1String("\\qt-common"); | - | ||||||||||||||||||||||||||||||||||||
| 1035 | case CSIDL_APPDATA: | - | ||||||||||||||||||||||||||||||||||||
| 1036 | return result + QLatin1String("\\qt-user"); | - | ||||||||||||||||||||||||||||||||||||
| 1037 | default: | - | ||||||||||||||||||||||||||||||||||||
| 1038 | break; | - | ||||||||||||||||||||||||||||||||||||
| 1039 | } | - | ||||||||||||||||||||||||||||||||||||
| 1040 | return result; | - | ||||||||||||||||||||||||||||||||||||
| 1041 | } | - | ||||||||||||||||||||||||||||||||||||
| 1042 | #endif // Q_OS_WINRT | - | ||||||||||||||||||||||||||||||||||||
| 1043 | - | |||||||||||||||||||||||||||||||||||||
| 1044 | static inline int pathHashKey(QSettings::Format format, QSettings::Scope scope) | - | ||||||||||||||||||||||||||||||||||||
| 1045 | { | - | ||||||||||||||||||||||||||||||||||||
| 1046 | return int((uint(format) << 1) | uint(scope == QSettings::SystemScope)); executed 3437 times by 7 tests: return int((uint(format) << 1) | uint(scope == QSettings::SystemScope));Executed by:
| 3437 | ||||||||||||||||||||||||||||||||||||
| 1047 | } | - | ||||||||||||||||||||||||||||||||||||
| 1048 | - | |||||||||||||||||||||||||||||||||||||
| 1049 | static void initDefaultPaths(QMutexLocker *locker) | - | ||||||||||||||||||||||||||||||||||||
| 1050 | { | - | ||||||||||||||||||||||||||||||||||||
| 1051 | PathHash *pathHash = pathHashFunc(); | - | ||||||||||||||||||||||||||||||||||||
| 1052 | QString systemPath; | - | ||||||||||||||||||||||||||||||||||||
| 1053 | - | |||||||||||||||||||||||||||||||||||||
| 1054 | locker->unlock(); | - | ||||||||||||||||||||||||||||||||||||
| 1055 | - | |||||||||||||||||||||||||||||||||||||
| 1056 | /* | - | ||||||||||||||||||||||||||||||||||||
| 1057 | QLibraryInfo::location() uses QSettings, so in order to | - | ||||||||||||||||||||||||||||||||||||
| 1058 | avoid a dead-lock, we can't hold the global mutex while | - | ||||||||||||||||||||||||||||||||||||
| 1059 | calling it. | - | ||||||||||||||||||||||||||||||||||||
| 1060 | */ | - | ||||||||||||||||||||||||||||||||||||
| 1061 | systemPath = QLibraryInfo::location(QLibraryInfo::SettingsPath); | - | ||||||||||||||||||||||||||||||||||||
| 1062 | systemPath += QLatin1Char('/'); | - | ||||||||||||||||||||||||||||||||||||
| 1063 | - | |||||||||||||||||||||||||||||||||||||
| 1064 | locker->relock(); | - | ||||||||||||||||||||||||||||||||||||
| 1065 | if (pathHash->isEmpty()) {
| 0-7 | ||||||||||||||||||||||||||||||||||||
| 1066 | /* | - | ||||||||||||||||||||||||||||||||||||
| 1067 | Lazy initialization of pathHash. We initialize the | - | ||||||||||||||||||||||||||||||||||||
| 1068 | IniFormat paths and (on Unix) the NativeFormat paths. | - | ||||||||||||||||||||||||||||||||||||
| 1069 | (The NativeFormat paths are not configurable for the | - | ||||||||||||||||||||||||||||||||||||
| 1070 | Windows registry and the Mac CFPreferences.) | - | ||||||||||||||||||||||||||||||||||||
| 1071 | */ | - | ||||||||||||||||||||||||||||||||||||
| 1072 | #ifdef Q_OS_WIN | - | ||||||||||||||||||||||||||||||||||||
| 1073 | pathHash->insert(pathHashKey(QSettings::IniFormat, QSettings::UserScope), | - | ||||||||||||||||||||||||||||||||||||
| 1074 | windowsConfigPath(CSIDL_APPDATA) + QDir::separator()); | - | ||||||||||||||||||||||||||||||||||||
| 1075 | pathHash->insert(pathHashKey(QSettings::IniFormat, QSettings::SystemScope), | - | ||||||||||||||||||||||||||||||||||||
| 1076 | windowsConfigPath(CSIDL_COMMON_APPDATA) + QDir::separator()); | - | ||||||||||||||||||||||||||||||||||||
| 1077 | #else | - | ||||||||||||||||||||||||||||||||||||
| 1078 | - | |||||||||||||||||||||||||||||||||||||
| 1079 | #ifndef QSETTINGS_USE_QSTANDARDPATHS | - | ||||||||||||||||||||||||||||||||||||
| 1080 | // Non XDG platforms (OS X, iOS, Blackberry, Android...) have used this code path erroneously | - | ||||||||||||||||||||||||||||||||||||
| 1081 | // for some time now. Moving away from that would require migrating existing settings. | - | ||||||||||||||||||||||||||||||||||||
| 1082 | QString userPath; | - | ||||||||||||||||||||||||||||||||||||
| 1083 | QByteArray env = qgetenv("XDG_CONFIG_HOME"); | - | ||||||||||||||||||||||||||||||||||||
| 1084 | if (env.isEmpty()) { | - | ||||||||||||||||||||||||||||||||||||
| 1085 | userPath = QDir::homePath(); | - | ||||||||||||||||||||||||||||||||||||
| 1086 | userPath += QLatin1Char('/'); | - | ||||||||||||||||||||||||||||||||||||
| 1087 | userPath += QLatin1String(".config"); | - | ||||||||||||||||||||||||||||||||||||
| 1088 | } else if (env.startsWith('/')) { | - | ||||||||||||||||||||||||||||||||||||
| 1089 | userPath = QFile::decodeName(env); | - | ||||||||||||||||||||||||||||||||||||
| 1090 | } else { | - | ||||||||||||||||||||||||||||||||||||
| 1091 | userPath = QDir::homePath(); | - | ||||||||||||||||||||||||||||||||||||
| 1092 | userPath += QLatin1Char('/'); | - | ||||||||||||||||||||||||||||||||||||
| 1093 | userPath += QFile::decodeName(env); | - | ||||||||||||||||||||||||||||||||||||
| 1094 | } | - | ||||||||||||||||||||||||||||||||||||
| 1095 | #else | - | ||||||||||||||||||||||||||||||||||||
| 1096 | // When using a proper XDG platform, use QStandardPaths rather than the above hand-written code; | - | ||||||||||||||||||||||||||||||||||||
| 1097 | // it makes the use of test mode from unit tests possible. | - | ||||||||||||||||||||||||||||||||||||
| 1098 | // Ideally all platforms should use this, but see above for the migration issue. | - | ||||||||||||||||||||||||||||||||||||
| 1099 | QString userPath = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation); | - | ||||||||||||||||||||||||||||||||||||
| 1100 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 1101 | userPath += QLatin1Char('/'); | - | ||||||||||||||||||||||||||||||||||||
| 1102 | - | |||||||||||||||||||||||||||||||||||||
| 1103 | pathHash->insert(pathHashKey(QSettings::IniFormat, QSettings::UserScope), userPath); | - | ||||||||||||||||||||||||||||||||||||
| 1104 | pathHash->insert(pathHashKey(QSettings::IniFormat, QSettings::SystemScope), systemPath); | - | ||||||||||||||||||||||||||||||||||||
| 1105 | #ifndef Q_OS_MAC | - | ||||||||||||||||||||||||||||||||||||
| 1106 | pathHash->insert(pathHashKey(QSettings::NativeFormat, QSettings::UserScope), userPath); | - | ||||||||||||||||||||||||||||||||||||
| 1107 | pathHash->insert(pathHashKey(QSettings::NativeFormat, QSettings::SystemScope), systemPath); | - | ||||||||||||||||||||||||||||||||||||
| 1108 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 1109 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 1110 | } executed 7 times by 7 tests: end of blockExecuted by:
| 7 | ||||||||||||||||||||||||||||||||||||
| 1111 | } executed 7 times by 7 tests: end of blockExecuted by:
| 7 | ||||||||||||||||||||||||||||||||||||
| 1112 | - | |||||||||||||||||||||||||||||||||||||
| 1113 | static QString getPath(QSettings::Format format, QSettings::Scope scope) | - | ||||||||||||||||||||||||||||||||||||
| 1114 | { | - | ||||||||||||||||||||||||||||||||||||
| 1115 | Q_ASSERT((int)QSettings::NativeFormat == 0); | - | ||||||||||||||||||||||||||||||||||||
| 1116 | Q_ASSERT((int)QSettings::IniFormat == 1); | - | ||||||||||||||||||||||||||||||||||||
| 1117 | - | |||||||||||||||||||||||||||||||||||||
| 1118 | QMutexLocker locker(&settingsGlobalMutex); | - | ||||||||||||||||||||||||||||||||||||
| 1119 | PathHash *pathHash = pathHashFunc(); | - | ||||||||||||||||||||||||||||||||||||
| 1120 | if (pathHash->isEmpty())
| 6-2731 | ||||||||||||||||||||||||||||||||||||
| 1121 | initDefaultPaths(&locker); executed 6 times by 6 tests: initDefaultPaths(&locker);Executed by:
| 6 | ||||||||||||||||||||||||||||||||||||
| 1122 | - | |||||||||||||||||||||||||||||||||||||
| 1123 | QString result = pathHash->value(pathHashKey(format, scope)); | - | ||||||||||||||||||||||||||||||||||||
| 1124 | if (!result.isEmpty())
| 108-2629 | ||||||||||||||||||||||||||||||||||||
| 1125 | return result; executed 2629 times by 7 tests: return result;Executed by:
| 2629 | ||||||||||||||||||||||||||||||||||||
| 1126 | - | |||||||||||||||||||||||||||||||||||||
| 1127 | // fall back on INI path | - | ||||||||||||||||||||||||||||||||||||
| 1128 | return pathHash->value(pathHashKey(QSettings::IniFormat, scope)); executed 108 times by 1 test: return pathHash->value(pathHashKey(QSettings::IniFormat, scope));Executed by:
| 108 | ||||||||||||||||||||||||||||||||||||
| 1129 | } | - | ||||||||||||||||||||||||||||||||||||
| 1130 | - | |||||||||||||||||||||||||||||||||||||
| 1131 | QConfFileSettingsPrivate::QConfFileSettingsPrivate(QSettings::Format format, | - | ||||||||||||||||||||||||||||||||||||
| 1132 | QSettings::Scope scope, | - | ||||||||||||||||||||||||||||||||||||
| 1133 | const QString &organization, | - | ||||||||||||||||||||||||||||||||||||
| 1134 | const QString &application) | - | ||||||||||||||||||||||||||||||||||||
| 1135 | : QSettingsPrivate(format, scope, organization, application), | - | ||||||||||||||||||||||||||||||||||||
| 1136 | nextPosition(0x40000000) // big positive number | - | ||||||||||||||||||||||||||||||||||||
| 1137 | { | - | ||||||||||||||||||||||||||||||||||||
| 1138 | int i; | - | ||||||||||||||||||||||||||||||||||||
| 1139 | initFormat(); | - | ||||||||||||||||||||||||||||||||||||
| 1140 | - | |||||||||||||||||||||||||||||||||||||
| 1141 | QString org = organization; | - | ||||||||||||||||||||||||||||||||||||
| 1142 | if (org.isEmpty()) {
| 8-1414 | ||||||||||||||||||||||||||||||||||||
| 1143 | setStatus(QSettings::AccessError); | - | ||||||||||||||||||||||||||||||||||||
| 1144 | org = QLatin1String("Unknown Organization"); | - | ||||||||||||||||||||||||||||||||||||
| 1145 | } executed 8 times by 1 test: end of blockExecuted by:
| 8 | ||||||||||||||||||||||||||||||||||||
| 1146 | - | |||||||||||||||||||||||||||||||||||||
| 1147 | #if !defined(Q_OS_BLACKBERRY) | - | ||||||||||||||||||||||||||||||||||||
| 1148 | QString appFile = org + QDir::separator() + application + extension; | - | ||||||||||||||||||||||||||||||||||||
| 1149 | QString orgFile = org + extension; | - | ||||||||||||||||||||||||||||||||||||
| 1150 | - | |||||||||||||||||||||||||||||||||||||
| 1151 | if (scope == QSettings::UserScope) {
| 107-1315 | ||||||||||||||||||||||||||||||||||||
| 1152 | QString userPath = getPath(format, QSettings::UserScope); | - | ||||||||||||||||||||||||||||||||||||
| 1153 | if (!application.isEmpty())
| 256-1059 | ||||||||||||||||||||||||||||||||||||
| 1154 | confFiles[F_User | F_Application].reset(QConfFile::fromName(userPath + appFile, true)); executed 256 times by 2 tests: confFiles[F_User | F_Application].reset(QConfFile::fromName(userPath + appFile, true));Executed by:
| 256 | ||||||||||||||||||||||||||||||||||||
| 1155 | confFiles[F_User | F_Organization].reset(QConfFile::fromName(userPath + orgFile, true)); | - | ||||||||||||||||||||||||||||||||||||
| 1156 | } executed 1315 times by 7 tests: end of blockExecuted by:
| 1315 | ||||||||||||||||||||||||||||||||||||
| 1157 | - | |||||||||||||||||||||||||||||||||||||
| 1158 | QString systemPath = getPath(format, QSettings::SystemScope); | - | ||||||||||||||||||||||||||||||||||||
| 1159 | if (!application.isEmpty())
| 298-1124 | ||||||||||||||||||||||||||||||||||||
| 1160 | confFiles[F_System | F_Application].reset(QConfFile::fromName(systemPath + appFile, false)); executed 298 times by 2 tests: confFiles[F_System | F_Application].reset(QConfFile::fromName(systemPath + appFile, false));Executed by:
| 298 | ||||||||||||||||||||||||||||||||||||
| 1161 | confFiles[F_System | F_Organization].reset(QConfFile::fromName(systemPath + orgFile, false)); | - | ||||||||||||||||||||||||||||||||||||
| 1162 | #else | - | ||||||||||||||||||||||||||||||||||||
| 1163 | QString confName = getPath(format, QSettings::UserScope) + org; | - | ||||||||||||||||||||||||||||||||||||
| 1164 | if (!application.isEmpty()) | - | ||||||||||||||||||||||||||||||||||||
| 1165 | confName += QDir::separator() + application; | - | ||||||||||||||||||||||||||||||||||||
| 1166 | confName += extension; | - | ||||||||||||||||||||||||||||||||||||
| 1167 | confFiles[SandboxConfFile].reset(QConfFile::fromName(confName, true)); | - | ||||||||||||||||||||||||||||||||||||
| 1168 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 1169 | - | |||||||||||||||||||||||||||||||||||||
| 1170 | for (i = 0; i < NumConfFiles; ++i) {
| 0-2760 | ||||||||||||||||||||||||||||||||||||
| 1171 | if (confFiles[i]) {
| 1338-1422 | ||||||||||||||||||||||||||||||||||||
| 1172 | spec = i; | - | ||||||||||||||||||||||||||||||||||||
| 1173 | break; executed 1422 times by 7 tests: break;Executed by:
| 1422 | ||||||||||||||||||||||||||||||||||||
| 1174 | } | - | ||||||||||||||||||||||||||||||||||||
| 1175 | } executed 1338 times by 6 tests: end of blockExecuted by:
| 1338 | ||||||||||||||||||||||||||||||||||||
| 1176 | - | |||||||||||||||||||||||||||||||||||||
| 1177 | initAccess(); | - | ||||||||||||||||||||||||||||||||||||
| 1178 | } executed 1422 times by 7 tests: end of blockExecuted by:
| 1422 | ||||||||||||||||||||||||||||||||||||
| 1179 | - | |||||||||||||||||||||||||||||||||||||
| 1180 | QConfFileSettingsPrivate::QConfFileSettingsPrivate(const QString &fileName, | - | ||||||||||||||||||||||||||||||||||||
| 1181 | QSettings::Format format) | - | ||||||||||||||||||||||||||||||||||||
| 1182 | : QSettingsPrivate(format), | - | ||||||||||||||||||||||||||||||||||||
| 1183 | nextPosition(0x40000000) // big positive number | - | ||||||||||||||||||||||||||||||||||||
| 1184 | { | - | ||||||||||||||||||||||||||||||||||||
| 1185 | initFormat(); | - | ||||||||||||||||||||||||||||||||||||
| 1186 | - | |||||||||||||||||||||||||||||||||||||
| 1187 | confFiles[0].reset(QConfFile::fromName(fileName, true)); | - | ||||||||||||||||||||||||||||||||||||
| 1188 | - | |||||||||||||||||||||||||||||||||||||
| 1189 | initAccess(); | - | ||||||||||||||||||||||||||||||||||||
| 1190 | } executed 119 times by 28 tests: end of blockExecuted by:
| 119 | ||||||||||||||||||||||||||||||||||||
| 1191 | - | |||||||||||||||||||||||||||||||||||||
| 1192 | QConfFileSettingsPrivate::~QConfFileSettingsPrivate() | - | ||||||||||||||||||||||||||||||||||||
| 1193 | { | - | ||||||||||||||||||||||||||||||||||||
| 1194 | QMutexLocker locker(&settingsGlobalMutex); | - | ||||||||||||||||||||||||||||||||||||
| 1195 | ConfFileHash *usedHash = usedHashFunc(); | - | ||||||||||||||||||||||||||||||||||||
| 1196 | ConfFileCache *unusedCache = unusedCacheFunc(); | - | ||||||||||||||||||||||||||||||||||||
| 1197 | - | |||||||||||||||||||||||||||||||||||||
| 1198 | for (int i = 0; i < NumConfFiles; ++i) {
| 1541-6164 | ||||||||||||||||||||||||||||||||||||
| 1199 | if (confFiles[i] && !confFiles[i]->ref.deref()) {
| 215-3195 | ||||||||||||||||||||||||||||||||||||
| 1200 | if (confFiles[i]->size == 0) {
| 924-2271 | ||||||||||||||||||||||||||||||||||||
| 1201 | delete confFiles[i].take(); | - | ||||||||||||||||||||||||||||||||||||
| 1202 | } else { executed 2271 times by 7 tests: end of blockExecuted by:
| 2271 | ||||||||||||||||||||||||||||||||||||
| 1203 | if (usedHash)
| 0-924 | ||||||||||||||||||||||||||||||||||||
| 1204 | usedHash->remove(confFiles[i]->name); executed 924 times by 29 tests: usedHash->remove(confFiles[i]->name);Executed by:
| 924 | ||||||||||||||||||||||||||||||||||||
| 1205 | if (unusedCache) {
| 0-924 | ||||||||||||||||||||||||||||||||||||
| 1206 | QT_TRY { | - | ||||||||||||||||||||||||||||||||||||
| 1207 | // compute a better size? | - | ||||||||||||||||||||||||||||||||||||
| 1208 | unusedCache->insert(confFiles[i]->name, confFiles[i].data(), | - | ||||||||||||||||||||||||||||||||||||
| 1209 | 10 + (confFiles[i]->originalKeys.size() / 4)); | - | ||||||||||||||||||||||||||||||||||||
| 1210 | confFiles[i].take(); | - | ||||||||||||||||||||||||||||||||||||
| 1211 | } QT_CATCH(...) { executed 924 times by 29 tests: end of blockExecuted by:
| 924 | ||||||||||||||||||||||||||||||||||||
| 1212 | // out of memory. Do not cache the file. | - | ||||||||||||||||||||||||||||||||||||
| 1213 | delete confFiles[i].take(); | - | ||||||||||||||||||||||||||||||||||||
| 1214 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1215 | } else { | - | ||||||||||||||||||||||||||||||||||||
| 1216 | // unusedCache is gone - delete the entry to prevent a memory leak | - | ||||||||||||||||||||||||||||||||||||
| 1217 | delete confFiles[i].take(); | - | ||||||||||||||||||||||||||||||||||||
| 1218 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1219 | } | - | ||||||||||||||||||||||||||||||||||||
| 1220 | } | - | ||||||||||||||||||||||||||||||||||||
| 1221 | // prevent the ScopedPointer to deref it again. | - | ||||||||||||||||||||||||||||||||||||
| 1222 | confFiles[i].take(); | - | ||||||||||||||||||||||||||||||||||||
| 1223 | } executed 6164 times by 30 tests: end of blockExecuted by:
| 6164 | ||||||||||||||||||||||||||||||||||||
| 1224 | } executed 1541 times by 30 tests: end of blockExecuted by:
| 1541 | ||||||||||||||||||||||||||||||||||||
| 1225 | - | |||||||||||||||||||||||||||||||||||||
| 1226 | void QConfFileSettingsPrivate::remove(const QString &key) | - | ||||||||||||||||||||||||||||||||||||
| 1227 | { | - | ||||||||||||||||||||||||||||||||||||
| 1228 | QConfFile *confFile = confFiles[spec].data(); | - | ||||||||||||||||||||||||||||||||||||
| 1229 | if (!confFile)
| 0-261 | ||||||||||||||||||||||||||||||||||||
| 1230 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||
| 1231 | - | |||||||||||||||||||||||||||||||||||||
| 1232 | QSettingsKey theKey(key, caseSensitivity); | - | ||||||||||||||||||||||||||||||||||||
| 1233 | QSettingsKey prefix(key + QLatin1Char('/'), caseSensitivity); | - | ||||||||||||||||||||||||||||||||||||
| 1234 | QMutexLocker locker(&confFile->mutex); | - | ||||||||||||||||||||||||||||||||||||
| 1235 | - | |||||||||||||||||||||||||||||||||||||
| 1236 | ensureSectionParsed(confFile, theKey); | - | ||||||||||||||||||||||||||||||||||||
| 1237 | ensureSectionParsed(confFile, prefix); | - | ||||||||||||||||||||||||||||||||||||
| 1238 | - | |||||||||||||||||||||||||||||||||||||
| 1239 | ParsedSettingsMap::iterator i = confFile->addedKeys.lowerBound(prefix); | - | ||||||||||||||||||||||||||||||||||||
| 1240 | while (i != confFile->addedKeys.end() && i.key().startsWith(prefix))
| 12-248 | ||||||||||||||||||||||||||||||||||||
| 1241 | i = confFile->addedKeys.erase(i); executed 12 times by 1 test: i = confFile->addedKeys.erase(i);Executed by:
| 12 | ||||||||||||||||||||||||||||||||||||
| 1242 | confFile->addedKeys.remove(theKey); | - | ||||||||||||||||||||||||||||||||||||
| 1243 | - | |||||||||||||||||||||||||||||||||||||
| 1244 | ParsedSettingsMap::const_iterator j = const_cast<const ParsedSettingsMap *>(&confFile->originalKeys)->lowerBound(prefix); | - | ||||||||||||||||||||||||||||||||||||
| 1245 | while (j != confFile->originalKeys.constEnd() && j.key().startsWith(prefix)) {
| 16-760 | ||||||||||||||||||||||||||||||||||||
| 1246 | confFile->removedKeys.insert(j.key(), QVariant()); | - | ||||||||||||||||||||||||||||||||||||
| 1247 | ++j; | - | ||||||||||||||||||||||||||||||||||||
| 1248 | } executed 744 times by 3 tests: end of blockExecuted by:
| 744 | ||||||||||||||||||||||||||||||||||||
| 1249 | if (confFile->originalKeys.contains(theKey))
| 5-256 | ||||||||||||||||||||||||||||||||||||
| 1250 | confFile->removedKeys.insert(theKey, QVariant()); executed 5 times by 1 test: confFile->removedKeys.insert(theKey, QVariant());Executed by:
| 5 | ||||||||||||||||||||||||||||||||||||
| 1251 | } executed 261 times by 3 tests: end of blockExecuted by:
| 261 | ||||||||||||||||||||||||||||||||||||
| 1252 | - | |||||||||||||||||||||||||||||||||||||
| 1253 | void QConfFileSettingsPrivate::set(const QString &key, const QVariant &value) | - | ||||||||||||||||||||||||||||||||||||
| 1254 | { | - | ||||||||||||||||||||||||||||||||||||
| 1255 | QConfFile *confFile = confFiles[spec].data(); | - | ||||||||||||||||||||||||||||||||||||
| 1256 | if (!confFile)
| 0-2437 | ||||||||||||||||||||||||||||||||||||
| 1257 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||
| 1258 | - | |||||||||||||||||||||||||||||||||||||
| 1259 | QSettingsKey theKey(key, caseSensitivity, nextPosition++); | - | ||||||||||||||||||||||||||||||||||||
| 1260 | QMutexLocker locker(&confFile->mutex); | - | ||||||||||||||||||||||||||||||||||||
| 1261 | confFile->removedKeys.remove(theKey); | - | ||||||||||||||||||||||||||||||||||||
| 1262 | confFile->addedKeys.insert(theKey, value); | - | ||||||||||||||||||||||||||||||||||||
| 1263 | } executed 2437 times by 6 tests: end of blockExecuted by:
| 2437 | ||||||||||||||||||||||||||||||||||||
| 1264 | - | |||||||||||||||||||||||||||||||||||||
| 1265 | bool QConfFileSettingsPrivate::get(const QString &key, QVariant *value) const | - | ||||||||||||||||||||||||||||||||||||
| 1266 | { | - | ||||||||||||||||||||||||||||||||||||
| 1267 | QSettingsKey theKey(key, caseSensitivity); | - | ||||||||||||||||||||||||||||||||||||
| 1268 | ParsedSettingsMap::const_iterator j; | - | ||||||||||||||||||||||||||||||||||||
| 1269 | bool found = false; | - | ||||||||||||||||||||||||||||||||||||
| 1270 | - | |||||||||||||||||||||||||||||||||||||
| 1271 | for (int i = 0; i < NumConfFiles; ++i) {
| 23003-117362 | ||||||||||||||||||||||||||||||||||||
| 1272 | if (QConfFile *confFile = confFiles[i].data()) {
| 47020-70342 | ||||||||||||||||||||||||||||||||||||
| 1273 | QMutexLocker locker(&confFile->mutex); | - | ||||||||||||||||||||||||||||||||||||
| 1274 | - | |||||||||||||||||||||||||||||||||||||
| 1275 | if (!confFile->addedKeys.isEmpty()) {
| 723-46297 | ||||||||||||||||||||||||||||||||||||
| 1276 | j = confFile->addedKeys.constFind(theKey); | - | ||||||||||||||||||||||||||||||||||||
| 1277 | found = (j != confFile->addedKeys.constEnd()); | - | ||||||||||||||||||||||||||||||||||||
| 1278 | } executed 723 times by 1 test: end of blockExecuted by:
| 723 | ||||||||||||||||||||||||||||||||||||
| 1279 | if (!found) {
| 601-46419 | ||||||||||||||||||||||||||||||||||||
| 1280 | ensureSectionParsed(confFile, theKey); | - | ||||||||||||||||||||||||||||||||||||
| 1281 | j = confFile->originalKeys.constFind(theKey); | - | ||||||||||||||||||||||||||||||||||||
| 1282 | found = (j != confFile->originalKeys.constEnd()
| 22808-23611 | ||||||||||||||||||||||||||||||||||||
| 1283 | && !confFile->removedKeys.contains(theKey));
| 5-22803 | ||||||||||||||||||||||||||||||||||||
| 1284 | } executed 46419 times by 30 tests: end of blockExecuted by:
| 46419 | ||||||||||||||||||||||||||||||||||||
| 1285 | - | |||||||||||||||||||||||||||||||||||||
| 1286 | if (found && value)
| 119-23616 | ||||||||||||||||||||||||||||||||||||
| 1287 | *value = *j; executed 23285 times by 28 tests: *value = *j;Executed by:
| 23285 | ||||||||||||||||||||||||||||||||||||
| 1288 | - | |||||||||||||||||||||||||||||||||||||
| 1289 | if (found)
| 23404-23616 | ||||||||||||||||||||||||||||||||||||
| 1290 | return true; executed 23404 times by 28 tests: return true;Executed by:
| 23404 | ||||||||||||||||||||||||||||||||||||
| 1291 | if (!fallbacks)
| 24-23592 | ||||||||||||||||||||||||||||||||||||
| 1292 | break; executed 24 times by 1 test: break;Executed by:
| 24 | ||||||||||||||||||||||||||||||||||||
| 1293 | } executed 23592 times by 29 tests: end of blockExecuted by:
| 23592 | ||||||||||||||||||||||||||||||||||||
| 1294 | } executed 93934 times by 30 tests: end of blockExecuted by:
| 93934 | ||||||||||||||||||||||||||||||||||||
| 1295 | return false; executed 23027 times by 29 tests: return false;Executed by:
| 23027 | ||||||||||||||||||||||||||||||||||||
| 1296 | } | - | ||||||||||||||||||||||||||||||||||||
| 1297 | - | |||||||||||||||||||||||||||||||||||||
| 1298 | QStringList QConfFileSettingsPrivate::children(const QString &prefix, ChildSpec spec) const | - | ||||||||||||||||||||||||||||||||||||
| 1299 | { | - | ||||||||||||||||||||||||||||||||||||
| 1300 | QStringList result; | - | ||||||||||||||||||||||||||||||||||||
| 1301 | ParsedSettingsMap::const_iterator j; | - | ||||||||||||||||||||||||||||||||||||
| 1302 | - | |||||||||||||||||||||||||||||||||||||
| 1303 | QSettingsKey thePrefix(prefix, caseSensitivity); | - | ||||||||||||||||||||||||||||||||||||
| 1304 | int startPos = prefix.size(); | - | ||||||||||||||||||||||||||||||||||||
| 1305 | - | |||||||||||||||||||||||||||||||||||||
| 1306 | for (int i = 0; i < NumConfFiles; ++i) {
| 633-3620 | ||||||||||||||||||||||||||||||||||||
| 1307 | if (QConfFile *confFile = confFiles[i].data()) {
| 1672-1948 | ||||||||||||||||||||||||||||||||||||
| 1308 | QMutexLocker locker(&confFile->mutex); | - | ||||||||||||||||||||||||||||||||||||
| 1309 | - | |||||||||||||||||||||||||||||||||||||
| 1310 | if (thePrefix.isEmpty()) {
| 484-1188 | ||||||||||||||||||||||||||||||||||||
| 1311 | ensureAllSectionsParsed(confFile); | - | ||||||||||||||||||||||||||||||||||||
| 1312 | } else { executed 1188 times by 28 tests: end of blockExecuted by:
| 1188 | ||||||||||||||||||||||||||||||||||||
| 1313 | ensureSectionParsed(confFile, thePrefix); | - | ||||||||||||||||||||||||||||||||||||
| 1314 | } executed 484 times by 1 test: end of blockExecuted by:
| 484 | ||||||||||||||||||||||||||||||||||||
| 1315 | - | |||||||||||||||||||||||||||||||||||||
| 1316 | j = const_cast<const ParsedSettingsMap *>( | - | ||||||||||||||||||||||||||||||||||||
| 1317 | &confFile->originalKeys)->lowerBound( thePrefix); | - | ||||||||||||||||||||||||||||||||||||
| 1318 | while (j != confFile->originalKeys.constEnd() && j.key().startsWith(thePrefix)) {
| 156-33308 | ||||||||||||||||||||||||||||||||||||
| 1319 | if (!confFile->removedKeys.contains(j.key()))
| 6-33146 | ||||||||||||||||||||||||||||||||||||
| 1320 | processChild(j.key().originalCaseKey().midRef(startPos), spec, result); executed 33146 times by 27 tests: processChild(j.key().originalCaseKey().midRef(startPos), spec, result);Executed by:
| 33146 | ||||||||||||||||||||||||||||||||||||
| 1321 | ++j; | - | ||||||||||||||||||||||||||||||||||||
| 1322 | } executed 33152 times by 27 tests: end of blockExecuted by:
| 33152 | ||||||||||||||||||||||||||||||||||||
| 1323 | - | |||||||||||||||||||||||||||||||||||||
| 1324 | j = const_cast<const ParsedSettingsMap *>( | - | ||||||||||||||||||||||||||||||||||||
| 1325 | &confFile->addedKeys)->lowerBound(thePrefix); | - | ||||||||||||||||||||||||||||||||||||
| 1326 | while (j != confFile->addedKeys.constEnd() && j.key().startsWith(thePrefix)) {
| 37-1635 | ||||||||||||||||||||||||||||||||||||
| 1327 | processChild(j.key().originalCaseKey().midRef(startPos), spec, result); | - | ||||||||||||||||||||||||||||||||||||
| 1328 | ++j; | - | ||||||||||||||||||||||||||||||||||||
| 1329 | } executed 367 times by 1 test: end of blockExecuted by:
| 367 | ||||||||||||||||||||||||||||||||||||
| 1330 | - | |||||||||||||||||||||||||||||||||||||
| 1331 | if (!fallbacks)
| 292-1380 | ||||||||||||||||||||||||||||||||||||
| 1332 | break; executed 292 times by 1 test: break;Executed by:
| 292 | ||||||||||||||||||||||||||||||||||||
| 1333 | } executed 1380 times by 28 tests: end of blockExecuted by:
| 1380 | ||||||||||||||||||||||||||||||||||||
| 1334 | } executed 3328 times by 28 tests: end of blockExecuted by:
| 3328 | ||||||||||||||||||||||||||||||||||||
| 1335 | std::sort(result.begin(), result.end()); | - | ||||||||||||||||||||||||||||||||||||
| 1336 | result.erase(std::unique(result.begin(), result.end()), | - | ||||||||||||||||||||||||||||||||||||
| 1337 | result.end()); | - | ||||||||||||||||||||||||||||||||||||
| 1338 | return result; executed 925 times by 28 tests: return result;Executed by:
| 925 | ||||||||||||||||||||||||||||||||||||
| 1339 | } | - | ||||||||||||||||||||||||||||||||||||
| 1340 | - | |||||||||||||||||||||||||||||||||||||
| 1341 | void QConfFileSettingsPrivate::clear() | - | ||||||||||||||||||||||||||||||||||||
| 1342 | { | - | ||||||||||||||||||||||||||||||||||||
| 1343 | QConfFile *confFile = confFiles[spec].data(); | - | ||||||||||||||||||||||||||||||||||||
| 1344 | if (!confFile)
| 0-16 | ||||||||||||||||||||||||||||||||||||
| 1345 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||
| 1346 | - | |||||||||||||||||||||||||||||||||||||
| 1347 | QMutexLocker locker(&confFile->mutex); | - | ||||||||||||||||||||||||||||||||||||
| 1348 | ensureAllSectionsParsed(confFile); | - | ||||||||||||||||||||||||||||||||||||
| 1349 | confFile->addedKeys.clear(); | - | ||||||||||||||||||||||||||||||||||||
| 1350 | confFile->removedKeys = confFile->originalKeys; | - | ||||||||||||||||||||||||||||||||||||
| 1351 | } executed 16 times by 1 test: end of blockExecuted by:
| 16 | ||||||||||||||||||||||||||||||||||||
| 1352 | - | |||||||||||||||||||||||||||||||||||||
| 1353 | void QConfFileSettingsPrivate::sync() | - | ||||||||||||||||||||||||||||||||||||
| 1354 | { | - | ||||||||||||||||||||||||||||||||||||
| 1355 | // people probably won't be checking the status a whole lot, so in case of | - | ||||||||||||||||||||||||||||||||||||
| 1356 | // error we just try to go on and make the best of it | - | ||||||||||||||||||||||||||||||||||||
| 1357 | - | |||||||||||||||||||||||||||||||||||||
| 1358 | for (int i = 0; i < NumConfFiles; ++i) {
| 2170-8680 | ||||||||||||||||||||||||||||||||||||
| 1359 | QConfFile *confFile = confFiles[i].data(); | - | ||||||||||||||||||||||||||||||||||||
| 1360 | if (confFile) {
| 3723-4957 | ||||||||||||||||||||||||||||||||||||
| 1361 | QMutexLocker locker(&confFile->mutex); | - | ||||||||||||||||||||||||||||||||||||
| 1362 | syncConfFile(i); | - | ||||||||||||||||||||||||||||||||||||
| 1363 | } executed 4957 times by 30 tests: end of blockExecuted by:
| 4957 | ||||||||||||||||||||||||||||||||||||
| 1364 | } executed 8680 times by 30 tests: end of blockExecuted by:
| 8680 | ||||||||||||||||||||||||||||||||||||
| 1365 | } executed 2170 times by 30 tests: end of blockExecuted by:
| 2170 | ||||||||||||||||||||||||||||||||||||
| 1366 | - | |||||||||||||||||||||||||||||||||||||
| 1367 | void QConfFileSettingsPrivate::flush() | - | ||||||||||||||||||||||||||||||||||||
| 1368 | { | - | ||||||||||||||||||||||||||||||||||||
| 1369 | sync(); | - | ||||||||||||||||||||||||||||||||||||
| 1370 | } executed 565 times by 6 tests: end of blockExecuted by:
| 565 | ||||||||||||||||||||||||||||||||||||
| 1371 | - | |||||||||||||||||||||||||||||||||||||
| 1372 | QString QConfFileSettingsPrivate::fileName() const | - | ||||||||||||||||||||||||||||||||||||
| 1373 | { | - | ||||||||||||||||||||||||||||||||||||
| 1374 | QConfFile *confFile = confFiles[spec].data(); | - | ||||||||||||||||||||||||||||||||||||
| 1375 | if (!confFile)
| 0-27 | ||||||||||||||||||||||||||||||||||||
| 1376 | return QString(); never executed: return QString(); | 0 | ||||||||||||||||||||||||||||||||||||
| 1377 | return confFile->name; executed 27 times by 1 test: return confFile->name;Executed by:
| 27 | ||||||||||||||||||||||||||||||||||||
| 1378 | } | - | ||||||||||||||||||||||||||||||||||||
| 1379 | - | |||||||||||||||||||||||||||||||||||||
| 1380 | bool QConfFileSettingsPrivate::isWritable() const | - | ||||||||||||||||||||||||||||||||||||
| 1381 | { | - | ||||||||||||||||||||||||||||||||||||
| 1382 | if (format > QSettings::IniFormat && !writeFunc)
| 1-12 | ||||||||||||||||||||||||||||||||||||
| 1383 | return false; executed 1 time by 1 test: return false;Executed by:
| 1 | ||||||||||||||||||||||||||||||||||||
| 1384 | - | |||||||||||||||||||||||||||||||||||||
| 1385 | QConfFile *confFile = confFiles[spec].data(); | - | ||||||||||||||||||||||||||||||||||||
| 1386 | if (!confFile)
| 0-20 | ||||||||||||||||||||||||||||||||||||
| 1387 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||||||||||||||
| 1388 | - | |||||||||||||||||||||||||||||||||||||
| 1389 | return confFile->isWritable(); executed 20 times by 1 test: return confFile->isWritable();Executed by:
| 20 | ||||||||||||||||||||||||||||||||||||
| 1390 | } | - | ||||||||||||||||||||||||||||||||||||
| 1391 | - | |||||||||||||||||||||||||||||||||||||
| 1392 | void QConfFileSettingsPrivate::syncConfFile(int confFileNo) | - | ||||||||||||||||||||||||||||||||||||
| 1393 | { | - | ||||||||||||||||||||||||||||||||||||
| 1394 | QConfFile *confFile = confFiles[confFileNo].data(); | - | ||||||||||||||||||||||||||||||||||||
| 1395 | bool readOnly = confFile->addedKeys.isEmpty() && confFile->removedKeys.isEmpty();
| 110-4502 | ||||||||||||||||||||||||||||||||||||
| 1396 | bool ok; | - | ||||||||||||||||||||||||||||||||||||
| 1397 | - | |||||||||||||||||||||||||||||||||||||
| 1398 | /* | - | ||||||||||||||||||||||||||||||||||||
| 1399 | We can often optimize the read-only case, if the file on disk | - | ||||||||||||||||||||||||||||||||||||
| 1400 | hasn't changed. | - | ||||||||||||||||||||||||||||||||||||
| 1401 | */ | - | ||||||||||||||||||||||||||||||||||||
| 1402 | if (readOnly && confFile->size > 0) {
| 565-4392 | ||||||||||||||||||||||||||||||||||||
| 1403 | QFileInfo fileInfo(confFile->name); | - | ||||||||||||||||||||||||||||||||||||
| 1404 | if (confFile->size == fileInfo.size() && confFile->timeStamp == fileInfo.lastModified())
| 0-778 | ||||||||||||||||||||||||||||||||||||
| 1405 | return; executed 778 times by 7 tests: return;Executed by:
| 778 | ||||||||||||||||||||||||||||||||||||
| 1406 | } executed 45 times by 1 test: end of blockExecuted by:
| 45 | ||||||||||||||||||||||||||||||||||||
| 1407 | - | |||||||||||||||||||||||||||||||||||||
| 1408 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||||||||||||||
| 1409 | /* | - | ||||||||||||||||||||||||||||||||||||
| 1410 | Use a lockfile in order to protect us against other QSettings instances | - | ||||||||||||||||||||||||||||||||||||
| 1411 | trying to write the same settings at the same time. | - | ||||||||||||||||||||||||||||||||||||
| 1412 | - | |||||||||||||||||||||||||||||||||||||
| 1413 | We only need to lock if we are actually writing as only concurrent writes are a problem. | - | ||||||||||||||||||||||||||||||||||||
| 1414 | Concurrent read and write are not a problem because the writing operation is atomic. | - | ||||||||||||||||||||||||||||||||||||
| 1415 | */ | - | ||||||||||||||||||||||||||||||||||||
| 1416 | QLockFile lockFile(confFile->name + QLatin1String(".lock")); | - | ||||||||||||||||||||||||||||||||||||
| 1417 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 1418 | if (!readOnly) {
| 565-3614 | ||||||||||||||||||||||||||||||||||||
| 1419 | if (!confFile->isWritable()
| 2-563 | ||||||||||||||||||||||||||||||||||||
| 1420 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||||||||||||||
| 1421 | || !lockFile.lock()
| 0-563 | ||||||||||||||||||||||||||||||||||||
| 1422 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 1423 | ) { | - | ||||||||||||||||||||||||||||||||||||
| 1424 | setStatus(QSettings::AccessError); | - | ||||||||||||||||||||||||||||||||||||
| 1425 | return; executed 2 times by 1 test: return;Executed by:
| 2 | ||||||||||||||||||||||||||||||||||||
| 1426 | } | - | ||||||||||||||||||||||||||||||||||||
| 1427 | } executed 563 times by 6 tests: end of blockExecuted by:
| 563 | ||||||||||||||||||||||||||||||||||||
| 1428 | - | |||||||||||||||||||||||||||||||||||||
| 1429 | /* | - | ||||||||||||||||||||||||||||||||||||
| 1430 | We hold the lock. Let's reread the file if it has changed | - | ||||||||||||||||||||||||||||||||||||
| 1431 | since last time we read it. | - | ||||||||||||||||||||||||||||||||||||
| 1432 | */ | - | ||||||||||||||||||||||||||||||||||||
| 1433 | QFileInfo fileInfo(confFile->name); | - | ||||||||||||||||||||||||||||||||||||
| 1434 | bool mustReadFile = true; | - | ||||||||||||||||||||||||||||||||||||
| 1435 | bool createFile = !fileInfo.exists(); | - | ||||||||||||||||||||||||||||||||||||
| 1436 | - | |||||||||||||||||||||||||||||||||||||
| 1437 | if (!readOnly)
| 563-3614 | ||||||||||||||||||||||||||||||||||||
| 1438 | mustReadFile = (confFile->size != fileInfo.size() executed 563 times by 6 tests: mustReadFile = (confFile->size != fileInfo.size() || (confFile->size != 0 && confFile->timeStamp != fileInfo.lastModified()));Executed by:
| 1-563 | ||||||||||||||||||||||||||||||||||||
| 1439 | || (confFile->size != 0 && confFile->timeStamp != fileInfo.lastModified())); executed 563 times by 6 tests: mustReadFile = (confFile->size != fileInfo.size() || (confFile->size != 0 && confFile->timeStamp != fileInfo.lastModified()));Executed by:
| 0-563 | ||||||||||||||||||||||||||||||||||||
| 1440 | - | |||||||||||||||||||||||||||||||||||||
| 1441 | if (mustReadFile) {
| 562-3615 | ||||||||||||||||||||||||||||||||||||
| 1442 | confFile->unparsedIniSections.clear(); | - | ||||||||||||||||||||||||||||||||||||
| 1443 | confFile->originalKeys.clear(); | - | ||||||||||||||||||||||||||||||||||||
| 1444 | - | |||||||||||||||||||||||||||||||||||||
| 1445 | QFile file(confFile->name); | - | ||||||||||||||||||||||||||||||||||||
| 1446 | if (!createFile && !file.open(QFile::ReadOnly)) {
| 0-2897 | ||||||||||||||||||||||||||||||||||||
| 1447 | setStatus(QSettings::AccessError); | - | ||||||||||||||||||||||||||||||||||||
| 1448 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||
| 1449 | } | - | ||||||||||||||||||||||||||||||||||||
| 1450 | - | |||||||||||||||||||||||||||||||||||||
| 1451 | /* | - | ||||||||||||||||||||||||||||||||||||
| 1452 | Files that we can't read (because of permissions or | - | ||||||||||||||||||||||||||||||||||||
| 1453 | because they don't exist) are treated as empty files. | - | ||||||||||||||||||||||||||||||||||||
| 1454 | */ | - | ||||||||||||||||||||||||||||||||||||
| 1455 | if (file.isReadable() && fileInfo.size() != 0) {
| 184-2897 | ||||||||||||||||||||||||||||||||||||
| 1456 | #ifdef Q_OS_MAC | - | ||||||||||||||||||||||||||||||||||||
| 1457 | if (format == QSettings::NativeFormat) { | - | ||||||||||||||||||||||||||||||||||||
| 1458 | ok = readPlistFile(confFile->name, &confFile->originalKeys); | - | ||||||||||||||||||||||||||||||||||||
| 1459 | } else | - | ||||||||||||||||||||||||||||||||||||
| 1460 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 1461 | { | - | ||||||||||||||||||||||||||||||||||||
| 1462 | if (format <= QSettings::IniFormat) {
| 51-133 | ||||||||||||||||||||||||||||||||||||
| 1463 | QByteArray data = file.readAll(); | - | ||||||||||||||||||||||||||||||||||||
| 1464 | ok = readIniFile(data, &confFile->unparsedIniSections); | - | ||||||||||||||||||||||||||||||||||||
| 1465 | } else { executed 133 times by 29 tests: end of blockExecuted by:
| 133 | ||||||||||||||||||||||||||||||||||||
| 1466 | if (readFunc) {
| 0-51 | ||||||||||||||||||||||||||||||||||||
| 1467 | QSettings::SettingsMap tempNewKeys; | - | ||||||||||||||||||||||||||||||||||||
| 1468 | ok = readFunc(file, tempNewKeys); | - | ||||||||||||||||||||||||||||||||||||
| 1469 | - | |||||||||||||||||||||||||||||||||||||
| 1470 | if (ok) {
| 1-50 | ||||||||||||||||||||||||||||||||||||
| 1471 | QSettings::SettingsMap::const_iterator i = tempNewKeys.constBegin(); | - | ||||||||||||||||||||||||||||||||||||
| 1472 | while (i != tempNewKeys.constEnd()) {
| 50-408 | ||||||||||||||||||||||||||||||||||||
| 1473 | confFile->originalKeys.insert(QSettingsKey(i.key(), | - | ||||||||||||||||||||||||||||||||||||
| 1474 | caseSensitivity), | - | ||||||||||||||||||||||||||||||||||||
| 1475 | i.value()); | - | ||||||||||||||||||||||||||||||||||||
| 1476 | ++i; | - | ||||||||||||||||||||||||||||||||||||
| 1477 | } executed 408 times by 1 test: end of blockExecuted by:
| 408 | ||||||||||||||||||||||||||||||||||||
| 1478 | } executed 50 times by 1 test: end of blockExecuted by:
| 50 | ||||||||||||||||||||||||||||||||||||
| 1479 | } else { executed 51 times by 1 test: end of blockExecuted by:
| 51 | ||||||||||||||||||||||||||||||||||||
| 1480 | ok = false; | - | ||||||||||||||||||||||||||||||||||||
| 1481 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1482 | } | - | ||||||||||||||||||||||||||||||||||||
| 1483 | } | - | ||||||||||||||||||||||||||||||||||||
| 1484 | - | |||||||||||||||||||||||||||||||||||||
| 1485 | if (!ok)
| 1-183 | ||||||||||||||||||||||||||||||||||||
| 1486 | setStatus(QSettings::FormatError); executed 1 time by 1 test: setStatus(QSettings::FormatError);Executed by:
| 1 | ||||||||||||||||||||||||||||||||||||
| 1487 | } executed 184 times by 29 tests: end of blockExecuted by:
| 184 | ||||||||||||||||||||||||||||||||||||
| 1488 | - | |||||||||||||||||||||||||||||||||||||
| 1489 | confFile->size = fileInfo.size(); | - | ||||||||||||||||||||||||||||||||||||
| 1490 | confFile->timeStamp = fileInfo.lastModified(); | - | ||||||||||||||||||||||||||||||||||||
| 1491 | } executed 3615 times by 30 tests: end of blockExecuted by:
| 3615 | ||||||||||||||||||||||||||||||||||||
| 1492 | - | |||||||||||||||||||||||||||||||||||||
| 1493 | /* | - | ||||||||||||||||||||||||||||||||||||
| 1494 | We also need to save the file. We still hold the file lock, | - | ||||||||||||||||||||||||||||||||||||
| 1495 | so everything is under control. | - | ||||||||||||||||||||||||||||||||||||
| 1496 | */ | - | ||||||||||||||||||||||||||||||||||||
| 1497 | if (!readOnly) {
| 563-3614 | ||||||||||||||||||||||||||||||||||||
| 1498 | ensureAllSectionsParsed(confFile); | - | ||||||||||||||||||||||||||||||||||||
| 1499 | ParsedSettingsMap mergedKeys = confFile->mergedKeyMap(); | - | ||||||||||||||||||||||||||||||||||||
| 1500 | - | |||||||||||||||||||||||||||||||||||||
| 1501 | #ifdef Q_OS_MAC | - | ||||||||||||||||||||||||||||||||||||
| 1502 | if (format == QSettings::NativeFormat) { | - | ||||||||||||||||||||||||||||||||||||
| 1503 | ok = writePlistFile(confFile->name, mergedKeys); | - | ||||||||||||||||||||||||||||||||||||
| 1504 | } else | - | ||||||||||||||||||||||||||||||||||||
| 1505 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 1506 | { | - | ||||||||||||||||||||||||||||||||||||
| 1507 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||||||||||||||
| 1508 | QSaveFile sf(confFile->name); | - | ||||||||||||||||||||||||||||||||||||
| 1509 | #else | - | ||||||||||||||||||||||||||||||||||||
| 1510 | QFile sf(confFile->name); | - | ||||||||||||||||||||||||||||||||||||
| 1511 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 1512 | if (!sf.open(QIODevice::WriteOnly)) {
| 0-563 | ||||||||||||||||||||||||||||||||||||
| 1513 | setStatus(QSettings::AccessError); | - | ||||||||||||||||||||||||||||||||||||
| 1514 | ok = false; | - | ||||||||||||||||||||||||||||||||||||
| 1515 | } else if (format <= QSettings::IniFormat) { never executed: end of block
| 0-483 | ||||||||||||||||||||||||||||||||||||
| 1516 | ok = writeIniFile(sf, mergedKeys); | - | ||||||||||||||||||||||||||||||||||||
| 1517 | } else { executed 483 times by 6 tests: end of blockExecuted by:
| 483 | ||||||||||||||||||||||||||||||||||||
| 1518 | if (writeFunc) {
| 1-79 | ||||||||||||||||||||||||||||||||||||
| 1519 | QSettings::SettingsMap tempOriginalKeys; | - | ||||||||||||||||||||||||||||||||||||
| 1520 | - | |||||||||||||||||||||||||||||||||||||
| 1521 | ParsedSettingsMap::const_iterator i = mergedKeys.constBegin(); | - | ||||||||||||||||||||||||||||||||||||
| 1522 | while (i != mergedKeys.constEnd()) {
| 79-418 | ||||||||||||||||||||||||||||||||||||
| 1523 | tempOriginalKeys.insert(i.key(), i.value()); | - | ||||||||||||||||||||||||||||||||||||
| 1524 | ++i; | - | ||||||||||||||||||||||||||||||||||||
| 1525 | } executed 418 times by 1 test: end of blockExecuted by:
| 418 | ||||||||||||||||||||||||||||||||||||
| 1526 | ok = writeFunc(sf, tempOriginalKeys); | - | ||||||||||||||||||||||||||||||||||||
| 1527 | } else { executed 79 times by 1 test: end of blockExecuted by:
| 79 | ||||||||||||||||||||||||||||||||||||
| 1528 | ok = false; | - | ||||||||||||||||||||||||||||||||||||
| 1529 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||||||||||||||||||||
| 1530 | } | - | ||||||||||||||||||||||||||||||||||||
| 1531 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||||||||||||||||||||
| 1532 | if (ok)
| 3-560 | ||||||||||||||||||||||||||||||||||||
| 1533 | ok = sf.commit(); executed 560 times by 6 tests: ok = sf.commit();Executed by:
| 560 | ||||||||||||||||||||||||||||||||||||
| 1534 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 1535 | } | - | ||||||||||||||||||||||||||||||||||||
| 1536 | - | |||||||||||||||||||||||||||||||||||||
| 1537 | if (ok) {
| 3-560 | ||||||||||||||||||||||||||||||||||||
| 1538 | confFile->unparsedIniSections.clear(); | - | ||||||||||||||||||||||||||||||||||||
| 1539 | confFile->originalKeys = mergedKeys; | - | ||||||||||||||||||||||||||||||||||||
| 1540 | confFile->addedKeys.clear(); | - | ||||||||||||||||||||||||||||||||||||
| 1541 | confFile->removedKeys.clear(); | - | ||||||||||||||||||||||||||||||||||||
| 1542 | - | |||||||||||||||||||||||||||||||||||||
| 1543 | QFileInfo fileInfo(confFile->name); | - | ||||||||||||||||||||||||||||||||||||
| 1544 | confFile->size = fileInfo.size(); | - | ||||||||||||||||||||||||||||||||||||
| 1545 | confFile->timeStamp = fileInfo.lastModified(); | - | ||||||||||||||||||||||||||||||||||||
| 1546 | - | |||||||||||||||||||||||||||||||||||||
| 1547 | // If we have created the file, apply the file perms | - | ||||||||||||||||||||||||||||||||||||
| 1548 | if (createFile) {
| 115-445 | ||||||||||||||||||||||||||||||||||||
| 1549 | QFile::Permissions perms = fileInfo.permissions() | QFile::ReadOwner | QFile::WriteOwner; | - | ||||||||||||||||||||||||||||||||||||
| 1550 | if (!confFile->userPerms)
| 32-83 | ||||||||||||||||||||||||||||||||||||
| 1551 | perms |= QFile::ReadGroup | QFile::ReadOther; executed 32 times by 1 test: perms |= QFile::ReadGroup | QFile::ReadOther;Executed by:
| 32 | ||||||||||||||||||||||||||||||||||||
| 1552 | QFile(confFile->name).setPermissions(perms); | - | ||||||||||||||||||||||||||||||||||||
| 1553 | } executed 115 times by 1 test: end of blockExecuted by:
| 115 | ||||||||||||||||||||||||||||||||||||
| 1554 | } else { executed 560 times by 6 tests: end of blockExecuted by:
| 560 | ||||||||||||||||||||||||||||||||||||
| 1555 | setStatus(QSettings::AccessError); | - | ||||||||||||||||||||||||||||||||||||
| 1556 | } executed 3 times by 1 test: end of blockExecuted by:
| 3 | ||||||||||||||||||||||||||||||||||||
| 1557 | } | - | ||||||||||||||||||||||||||||||||||||
| 1558 | } executed 4177 times by 30 tests: end of blockExecuted by:
| 4177 | ||||||||||||||||||||||||||||||||||||
| 1559 | - | |||||||||||||||||||||||||||||||||||||
| 1560 | enum { Space = 0x1, Special = 0x2 }; | - | ||||||||||||||||||||||||||||||||||||
| 1561 | - | |||||||||||||||||||||||||||||||||||||
| 1562 | static const char charTraits[256] = | - | ||||||||||||||||||||||||||||||||||||
| 1563 | { | - | ||||||||||||||||||||||||||||||||||||
| 1564 | // Space: '\t', '\n', '\r', ' ' | - | ||||||||||||||||||||||||||||||||||||
| 1565 | // Special: '\n', '\r', '"', ';', '=', '\\' | - | ||||||||||||||||||||||||||||||||||||
| 1566 | - | |||||||||||||||||||||||||||||||||||||
| 1567 | 0, 0, 0, 0, 0, 0, 0, 0, 0, Space, Space | Special, 0, 0, Space | Special, 0, 0, | - | ||||||||||||||||||||||||||||||||||||
| 1568 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | - | ||||||||||||||||||||||||||||||||||||
| 1569 | Space, 0, Special, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | - | ||||||||||||||||||||||||||||||||||||
| 1570 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, Special, 0, Special, 0, 0, | - | ||||||||||||||||||||||||||||||||||||
| 1571 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | - | ||||||||||||||||||||||||||||||||||||
| 1572 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, Special, 0, 0, 0, | - | ||||||||||||||||||||||||||||||||||||
| 1573 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | - | ||||||||||||||||||||||||||||||||||||
| 1574 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | - | ||||||||||||||||||||||||||||||||||||
| 1575 | - | |||||||||||||||||||||||||||||||||||||
| 1576 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | - | ||||||||||||||||||||||||||||||||||||
| 1577 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | - | ||||||||||||||||||||||||||||||||||||
| 1578 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | - | ||||||||||||||||||||||||||||||||||||
| 1579 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | - | ||||||||||||||||||||||||||||||||||||
| 1580 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | - | ||||||||||||||||||||||||||||||||||||
| 1581 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | - | ||||||||||||||||||||||||||||||||||||
| 1582 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | - | ||||||||||||||||||||||||||||||||||||
| 1583 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 | - | ||||||||||||||||||||||||||||||||||||
| 1584 | }; | - | ||||||||||||||||||||||||||||||||||||
| 1585 | - | |||||||||||||||||||||||||||||||||||||
| 1586 | bool QConfFileSettingsPrivate::readIniLine(const QByteArray &data, int &dataPos, | - | ||||||||||||||||||||||||||||||||||||
| 1587 | int &lineStart, int &lineLen, int &equalsPos) | - | ||||||||||||||||||||||||||||||||||||
| 1588 | { | - | ||||||||||||||||||||||||||||||||||||
| 1589 | int dataLen = data.length(); | - | ||||||||||||||||||||||||||||||||||||
| 1590 | bool inQuotes = false; | - | ||||||||||||||||||||||||||||||||||||
| 1591 | - | |||||||||||||||||||||||||||||||||||||
| 1592 | equalsPos = -1; | - | ||||||||||||||||||||||||||||||||||||
| 1593 | - | |||||||||||||||||||||||||||||||||||||
| 1594 | lineStart = dataPos; | - | ||||||||||||||||||||||||||||||||||||
| 1595 | while (lineStart < dataLen && (charTraits[uint(uchar(data.at(lineStart)))] & Space))
| 8954-164168 | ||||||||||||||||||||||||||||||||||||
| 1596 | ++lineStart; executed 95115 times by 29 tests: ++lineStart;Executed by:
| 95115 | ||||||||||||||||||||||||||||||||||||
| 1597 | - | |||||||||||||||||||||||||||||||||||||
| 1598 | int i = lineStart; | - | ||||||||||||||||||||||||||||||||||||
| 1599 | while (i < dataLen) {
| 8974-140693 | ||||||||||||||||||||||||||||||||||||
| 1600 | while (!(charTraits[uint(uchar(data.at(i)))] & Special)) {
| 140658-1108734 | ||||||||||||||||||||||||||||||||||||
| 1601 | if (++i == dataLen)
| 35-1108699 | ||||||||||||||||||||||||||||||||||||
| 1602 | goto break_out_of_outer_loop; executed 35 times by 1 test: goto break_out_of_outer_loop;Executed by:
| 35 | ||||||||||||||||||||||||||||||||||||
| 1603 | } executed 1108699 times by 29 tests: end of blockExecuted by:
| 1108699 | ||||||||||||||||||||||||||||||||||||
| 1604 | - | |||||||||||||||||||||||||||||||||||||
| 1605 | char ch = data.at(i++); | - | ||||||||||||||||||||||||||||||||||||
| 1606 | if (ch == '=') {
| 60126-80532 | ||||||||||||||||||||||||||||||||||||
| 1607 | if (!inQuotes && equalsPos == -1)
| 0-60124 | ||||||||||||||||||||||||||||||||||||
| 1608 | equalsPos = i - 1; executed 60124 times by 28 tests: equalsPos = i - 1;Executed by:
| 60124 | ||||||||||||||||||||||||||||||||||||
| 1609 | } else if (ch == '\n' || ch == '\r') { executed 60126 times by 28 tests: end of blockExecuted by:
| 2-69002 | ||||||||||||||||||||||||||||||||||||
| 1610 | if (i == lineStart + 1) {
| 6-68998 | ||||||||||||||||||||||||||||||||||||
| 1611 | ++lineStart; | - | ||||||||||||||||||||||||||||||||||||
| 1612 | } else if (!inQuotes) { executed 6 times by 1 test: end of blockExecuted by:
| 4-68994 | ||||||||||||||||||||||||||||||||||||
| 1613 | --i; | - | ||||||||||||||||||||||||||||||||||||
| 1614 | goto break_out_of_outer_loop; executed 68994 times by 29 tests: goto break_out_of_outer_loop;Executed by:
| 68994 | ||||||||||||||||||||||||||||||||||||
| 1615 | } | - | ||||||||||||||||||||||||||||||||||||
| 1616 | } else if (ch == '\\') { executed 10 times by 1 test: end of blockExecuted by:
| 10-11420 | ||||||||||||||||||||||||||||||||||||
| 1617 | if (i < dataLen) {
| 4-11416 | ||||||||||||||||||||||||||||||||||||
| 1618 | char ch = data.at(i++); | - | ||||||||||||||||||||||||||||||||||||
| 1619 | if (i < dataLen) {
| 4-11412 | ||||||||||||||||||||||||||||||||||||
| 1620 | char ch2 = data.at(i); | - | ||||||||||||||||||||||||||||||||||||
| 1621 | // \n, \r, \r\n, and \n\r are legitimate line terminators in INI files | - | ||||||||||||||||||||||||||||||||||||
| 1622 | if ((ch == '\n' && ch2 == '\r') || (ch == '\r' && ch2 == '\n'))
| 4-11402 | ||||||||||||||||||||||||||||||||||||
| 1623 | ++i; executed 10 times by 1 test: ++i;Executed by:
| 10 | ||||||||||||||||||||||||||||||||||||
| 1624 | } executed 11412 times by 4 tests: end of blockExecuted by:
| 11412 | ||||||||||||||||||||||||||||||||||||
| 1625 | } executed 11416 times by 4 tests: end of blockExecuted by:
| 11416 | ||||||||||||||||||||||||||||||||||||
| 1626 | } else if (ch == '"') { executed 11420 times by 4 tests: end of blockExecuted by:
| 12-11420 | ||||||||||||||||||||||||||||||||||||
| 1627 | inQuotes = !inQuotes; | - | ||||||||||||||||||||||||||||||||||||
| 1628 | } else { executed 96 times by 2 tests: end of blockExecuted by:
| 96 | ||||||||||||||||||||||||||||||||||||
| 1629 | Q_ASSERT(ch == ';'); | - | ||||||||||||||||||||||||||||||||||||
| 1630 | - | |||||||||||||||||||||||||||||||||||||
| 1631 | if (i == lineStart + 1) {
| 4-8 | ||||||||||||||||||||||||||||||||||||
| 1632 | char ch; | - | ||||||||||||||||||||||||||||||||||||
| 1633 | while (i < dataLen && (((ch = data.at(i)) != '\n') && ch != '\r'))
| 0-26 | ||||||||||||||||||||||||||||||||||||
| 1634 | ++i; executed 22 times by 1 test: ++i;Executed by:
| 22 | ||||||||||||||||||||||||||||||||||||
| 1635 | lineStart = i; | - | ||||||||||||||||||||||||||||||||||||
| 1636 | } else if (!inQuotes) { executed 8 times by 1 test: end of blockExecuted by:
| 0-8 | ||||||||||||||||||||||||||||||||||||
| 1637 | --i; | - | ||||||||||||||||||||||||||||||||||||
| 1638 | goto break_out_of_outer_loop; executed 4 times by 1 test: goto break_out_of_outer_loop;Executed by:
| 4 | ||||||||||||||||||||||||||||||||||||
| 1639 | } | - | ||||||||||||||||||||||||||||||||||||
| 1640 | } executed 8 times by 1 test: end of blockExecuted by:
| 8 | ||||||||||||||||||||||||||||||||||||
| 1641 | } | - | ||||||||||||||||||||||||||||||||||||
| 1642 | - | |||||||||||||||||||||||||||||||||||||
| 1643 | break_out_of_outer_loop: code before this statement executed 8974 times by 29 tests: break_out_of_outer_loop:Executed by:
| 8974 | ||||||||||||||||||||||||||||||||||||
| 1644 | dataPos = i; | - | ||||||||||||||||||||||||||||||||||||
| 1645 | lineLen = i - lineStart; | - | ||||||||||||||||||||||||||||||||||||
| 1646 | return lineLen > 0; executed 78007 times by 29 tests: return lineLen > 0;Executed by:
| 78007 | ||||||||||||||||||||||||||||||||||||
| 1647 | } | - | ||||||||||||||||||||||||||||||||||||
| 1648 | - | |||||||||||||||||||||||||||||||||||||
| 1649 | /* | - | ||||||||||||||||||||||||||||||||||||
| 1650 | Returns \c false on parse error. However, as many keys are read as | - | ||||||||||||||||||||||||||||||||||||
| 1651 | possible, so if the user doesn't check the status he will get the | - | ||||||||||||||||||||||||||||||||||||
| 1652 | most out of the file anyway. | - | ||||||||||||||||||||||||||||||||||||
| 1653 | */ | - | ||||||||||||||||||||||||||||||||||||
| 1654 | bool QConfFileSettingsPrivate::readIniFile(const QByteArray &data, | - | ||||||||||||||||||||||||||||||||||||
| 1655 | UnparsedSettingsMap *unparsedIniSections) | - | ||||||||||||||||||||||||||||||||||||
| 1656 | { | - | ||||||||||||||||||||||||||||||||||||
| 1657 | #define FLUSH_CURRENT_SECTION() \ | - | ||||||||||||||||||||||||||||||||||||
| 1658 | { \ | - | ||||||||||||||||||||||||||||||||||||
| 1659 | QByteArray §ionData = (*unparsedIniSections)[QSettingsKey(currentSection, \ | - | ||||||||||||||||||||||||||||||||||||
| 1660 | IniCaseSensitivity, \ | - | ||||||||||||||||||||||||||||||||||||
| 1661 | sectionPosition)]; \ | - | ||||||||||||||||||||||||||||||||||||
| 1662 | if (!sectionData.isEmpty()) \ | - | ||||||||||||||||||||||||||||||||||||
| 1663 | sectionData.append('\n'); \ | - | ||||||||||||||||||||||||||||||||||||
| 1664 | sectionData += data.mid(currentSectionStart, lineStart - currentSectionStart); \ | - | ||||||||||||||||||||||||||||||||||||
| 1665 | sectionPosition = ++position; \ | - | ||||||||||||||||||||||||||||||||||||
| 1666 | } | - | ||||||||||||||||||||||||||||||||||||
| 1667 | - | |||||||||||||||||||||||||||||||||||||
| 1668 | QString currentSection; | - | ||||||||||||||||||||||||||||||||||||
| 1669 | int currentSectionStart = 0; | - | ||||||||||||||||||||||||||||||||||||
| 1670 | int dataPos = 0; | - | ||||||||||||||||||||||||||||||||||||
| 1671 | int lineStart; | - | ||||||||||||||||||||||||||||||||||||
| 1672 | int lineLen; | - | ||||||||||||||||||||||||||||||||||||
| 1673 | int equalsPos; | - | ||||||||||||||||||||||||||||||||||||
| 1674 | int position = 0; | - | ||||||||||||||||||||||||||||||||||||
| 1675 | int sectionPosition = 0; | - | ||||||||||||||||||||||||||||||||||||
| 1676 | bool ok = true; | - | ||||||||||||||||||||||||||||||||||||
| 1677 | - | |||||||||||||||||||||||||||||||||||||
| 1678 | #ifndef QT_NO_TEXTCODEC | - | ||||||||||||||||||||||||||||||||||||
| 1679 | // detect utf8 BOM | - | ||||||||||||||||||||||||||||||||||||
| 1680 | const uchar *dd = (const uchar *)data.constData(); | - | ||||||||||||||||||||||||||||||||||||
| 1681 | if (data.size() >= 3 && dd[0] == 0xef && dd[1] == 0xbb && dd[2] == 0xbf) {
| 0-131 | ||||||||||||||||||||||||||||||||||||
| 1682 | iniCodec = QTextCodec::codecForName("UTF-8"); | - | ||||||||||||||||||||||||||||||||||||
| 1683 | dataPos = 3; | - | ||||||||||||||||||||||||||||||||||||
| 1684 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||||||||||||||||||||
| 1685 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 1686 | - | |||||||||||||||||||||||||||||||||||||
| 1687 | while (readIniLine(data, dataPos, lineStart, lineLen, equalsPos)) {
| 133-38911 | ||||||||||||||||||||||||||||||||||||
| 1688 | char ch = data.at(lineStart); | - | ||||||||||||||||||||||||||||||||||||
| 1689 | if (ch == '[') {
| 8746-30165 | ||||||||||||||||||||||||||||||||||||
| 1690 | FLUSH_CURRENT_SECTION(); never executed: sectionData.append('\n');
| 0-8746 | ||||||||||||||||||||||||||||||||||||
| 1691 | - | |||||||||||||||||||||||||||||||||||||
| 1692 | // this is a section | - | ||||||||||||||||||||||||||||||||||||
| 1693 | QByteArray iniSection; | - | ||||||||||||||||||||||||||||||||||||
| 1694 | int idx = data.indexOf(']', lineStart); | - | ||||||||||||||||||||||||||||||||||||
| 1695 | if (idx == -1 || idx >= lineStart + lineLen) {
| 0-8746 | ||||||||||||||||||||||||||||||||||||
| 1696 | ok = false; | - | ||||||||||||||||||||||||||||||||||||
| 1697 | iniSection = data.mid(lineStart + 1, lineLen - 1); | - | ||||||||||||||||||||||||||||||||||||
| 1698 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1699 | iniSection = data.mid(lineStart + 1, idx - lineStart - 1); | - | ||||||||||||||||||||||||||||||||||||
| 1700 | } executed 8746 times by 28 tests: end of blockExecuted by:
| 8746 | ||||||||||||||||||||||||||||||||||||
| 1701 | - | |||||||||||||||||||||||||||||||||||||
| 1702 | iniSection = iniSection.trimmed(); | - | ||||||||||||||||||||||||||||||||||||
| 1703 | - | |||||||||||||||||||||||||||||||||||||
| 1704 | if (qstricmp(iniSection.constData(), "general") == 0) {
| 48-8698 | ||||||||||||||||||||||||||||||||||||
| 1705 | currentSection.clear(); | - | ||||||||||||||||||||||||||||||||||||
| 1706 | } else { executed 48 times by 1 test: end of blockExecuted by:
| 48 | ||||||||||||||||||||||||||||||||||||
| 1707 | if (qstricmp(iniSection.constData(), "%general") == 0) {
| 0-8698 | ||||||||||||||||||||||||||||||||||||
| 1708 | currentSection = QLatin1String(iniSection.constData() + 1); | - | ||||||||||||||||||||||||||||||||||||
| 1709 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1710 | currentSection.clear(); | - | ||||||||||||||||||||||||||||||||||||
| 1711 | iniUnescapedKey(iniSection, 0, iniSection.size(), currentSection); | - | ||||||||||||||||||||||||||||||||||||
| 1712 | } executed 8698 times by 28 tests: end of blockExecuted by:
| 8698 | ||||||||||||||||||||||||||||||||||||
| 1713 | currentSection += QLatin1Char('/'); | - | ||||||||||||||||||||||||||||||||||||
| 1714 | } executed 8698 times by 28 tests: end of blockExecuted by:
| 8698 | ||||||||||||||||||||||||||||||||||||
| 1715 | currentSectionStart = dataPos; | - | ||||||||||||||||||||||||||||||||||||
| 1716 | } executed 8746 times by 28 tests: end of blockExecuted by:
| 8746 | ||||||||||||||||||||||||||||||||||||
| 1717 | ++position; | - | ||||||||||||||||||||||||||||||||||||
| 1718 | } executed 38911 times by 29 tests: end of blockExecuted by:
| 38911 | ||||||||||||||||||||||||||||||||||||
| 1719 | - | |||||||||||||||||||||||||||||||||||||
| 1720 | Q_ASSERT(lineStart == data.length()); | - | ||||||||||||||||||||||||||||||||||||
| 1721 | FLUSH_CURRENT_SECTION(); never executed: sectionData.append('\n');
| 0-133 | ||||||||||||||||||||||||||||||||||||
| 1722 | - | |||||||||||||||||||||||||||||||||||||
| 1723 | return ok; executed 133 times by 29 tests: return ok;Executed by:
| 133 | ||||||||||||||||||||||||||||||||||||
| 1724 | - | |||||||||||||||||||||||||||||||||||||
| 1725 | #undef FLUSH_CURRENT_SECTION | - | ||||||||||||||||||||||||||||||||||||
| 1726 | } | - | ||||||||||||||||||||||||||||||||||||
| 1727 | - | |||||||||||||||||||||||||||||||||||||
| 1728 | bool QConfFileSettingsPrivate::readIniSection(const QSettingsKey §ion, const QByteArray &data, | - | ||||||||||||||||||||||||||||||||||||
| 1729 | ParsedSettingsMap *settingsMap, QTextCodec *codec) | - | ||||||||||||||||||||||||||||||||||||
| 1730 | { | - | ||||||||||||||||||||||||||||||||||||
| 1731 | QStringList strListValue; | - | ||||||||||||||||||||||||||||||||||||
| 1732 | bool sectionIsLowercase = (section == section.originalCaseKey()); | - | ||||||||||||||||||||||||||||||||||||
| 1733 | int equalsPos; | - | ||||||||||||||||||||||||||||||||||||
| 1734 | - | |||||||||||||||||||||||||||||||||||||
| 1735 | bool ok = true; | - | ||||||||||||||||||||||||||||||||||||
| 1736 | int dataPos = 0; | - | ||||||||||||||||||||||||||||||||||||
| 1737 | int lineStart; | - | ||||||||||||||||||||||||||||||||||||
| 1738 | int lineLen; | - | ||||||||||||||||||||||||||||||||||||
| 1739 | int position = section.originalKeyPosition(); | - | ||||||||||||||||||||||||||||||||||||
| 1740 | - | |||||||||||||||||||||||||||||||||||||
| 1741 | while (readIniLine(data, dataPos, lineStart, lineLen, equalsPos)) {
| 8825-30138 | ||||||||||||||||||||||||||||||||||||
| 1742 | char ch = data.at(lineStart); | - | ||||||||||||||||||||||||||||||||||||
| 1743 | Q_ASSERT(ch != '['); | - | ||||||||||||||||||||||||||||||||||||
| 1744 | - | |||||||||||||||||||||||||||||||||||||
| 1745 | if (equalsPos == -1) {
| 90-30048 | ||||||||||||||||||||||||||||||||||||
| 1746 | if (ch != ';')
| 0-90 | ||||||||||||||||||||||||||||||||||||
| 1747 | ok = false; executed 90 times by 3 tests: ok = false;Executed by:
| 90 | ||||||||||||||||||||||||||||||||||||
| 1748 | continue; executed 90 times by 3 tests: continue;Executed by:
| 90 | ||||||||||||||||||||||||||||||||||||
| 1749 | } | - | ||||||||||||||||||||||||||||||||||||
| 1750 | - | |||||||||||||||||||||||||||||||||||||
| 1751 | int keyEnd = equalsPos; | - | ||||||||||||||||||||||||||||||||||||
| 1752 | while (keyEnd > lineStart && ((ch = data.at(keyEnd - 1)) == ' ' || ch == '\t'))
| 0-30052 | ||||||||||||||||||||||||||||||||||||
| 1753 | --keyEnd; executed 4 times by 1 test: --keyEnd;Executed by:
| 4 | ||||||||||||||||||||||||||||||||||||
| 1754 | int valueStart = equalsPos + 1; | - | ||||||||||||||||||||||||||||||||||||
| 1755 | - | |||||||||||||||||||||||||||||||||||||
| 1756 | QString key = section.originalCaseKey(); | - | ||||||||||||||||||||||||||||||||||||
| 1757 | bool keyIsLowercase = (iniUnescapedKey(data, lineStart, keyEnd, key) && sectionIsLowercase);
| 0-29586 | ||||||||||||||||||||||||||||||||||||
| 1758 | - | |||||||||||||||||||||||||||||||||||||
| 1759 | QString strValue; | - | ||||||||||||||||||||||||||||||||||||
| 1760 | strValue.reserve(lineLen - (valueStart - lineStart)); | - | ||||||||||||||||||||||||||||||||||||
| 1761 | bool isStringList = iniUnescapedStringList(data, valueStart, lineStart + lineLen, | - | ||||||||||||||||||||||||||||||||||||
| 1762 | strValue, strListValue, codec); | - | ||||||||||||||||||||||||||||||||||||
| 1763 | QVariant variant; | - | ||||||||||||||||||||||||||||||||||||
| 1764 | if (isStringList) {
| 77-29971 | ||||||||||||||||||||||||||||||||||||
| 1765 | variant = stringListToVariantList(strListValue); | - | ||||||||||||||||||||||||||||||||||||
| 1766 | } else { executed 77 times by 28 tests: end of blockExecuted by:
| 77 | ||||||||||||||||||||||||||||||||||||
| 1767 | variant = stringToVariant(strValue); | - | ||||||||||||||||||||||||||||||||||||
| 1768 | } executed 29971 times by 28 tests: end of blockExecuted by:
| 29971 | ||||||||||||||||||||||||||||||||||||
| 1769 | - | |||||||||||||||||||||||||||||||||||||
| 1770 | /* | - | ||||||||||||||||||||||||||||||||||||
| 1771 | We try to avoid the expensive toLower() call in | - | ||||||||||||||||||||||||||||||||||||
| 1772 | QSettingsKey by passing Qt::CaseSensitive when the | - | ||||||||||||||||||||||||||||||||||||
| 1773 | key is already in lowercase. | - | ||||||||||||||||||||||||||||||||||||
| 1774 | */ | - | ||||||||||||||||||||||||||||||||||||
| 1775 | settingsMap->insert(QSettingsKey(key, keyIsLowercase ? Qt::CaseSensitive | - | ||||||||||||||||||||||||||||||||||||
| 1776 | : IniCaseSensitivity, | - | ||||||||||||||||||||||||||||||||||||
| 1777 | position), | - | ||||||||||||||||||||||||||||||||||||
| 1778 | variant); | - | ||||||||||||||||||||||||||||||||||||
| 1779 | ++position; | - | ||||||||||||||||||||||||||||||||||||
| 1780 | } executed 30048 times by 28 tests: end of blockExecuted by:
| 30048 | ||||||||||||||||||||||||||||||||||||
| 1781 | - | |||||||||||||||||||||||||||||||||||||
| 1782 | return ok; executed 8825 times by 29 tests: return ok;Executed by:
| 8825 | ||||||||||||||||||||||||||||||||||||
| 1783 | } | - | ||||||||||||||||||||||||||||||||||||
| 1784 | - | |||||||||||||||||||||||||||||||||||||
| 1785 | class QSettingsIniKey : public QString | - | ||||||||||||||||||||||||||||||||||||
| 1786 | { | - | ||||||||||||||||||||||||||||||||||||
| 1787 | public: | - | ||||||||||||||||||||||||||||||||||||
| 1788 | inline QSettingsIniKey() : position(-1) {} never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1789 | inline QSettingsIniKey(const QString &str, int pos = -1) : QString(str), position(pos) {} executed 2997 times by 6 tests: end of blockExecuted by:
| 2997 | ||||||||||||||||||||||||||||||||||||
| 1790 | - | |||||||||||||||||||||||||||||||||||||
| 1791 | int position; | - | ||||||||||||||||||||||||||||||||||||
| 1792 | }; | - | ||||||||||||||||||||||||||||||||||||
| 1793 | Q_DECLARE_TYPEINFO(QSettingsIniKey, Q_MOVABLE_TYPE); | - | ||||||||||||||||||||||||||||||||||||
| 1794 | - | |||||||||||||||||||||||||||||||||||||
| 1795 | static bool operator<(const QSettingsIniKey &k1, const QSettingsIniKey &k2) | - | ||||||||||||||||||||||||||||||||||||
| 1796 | { | - | ||||||||||||||||||||||||||||||||||||
| 1797 | if (k1.position != k2.position)
| 0-11504 | ||||||||||||||||||||||||||||||||||||
| 1798 | return k1.position < k2.position; never executed: return k1.position < k2.position; | 0 | ||||||||||||||||||||||||||||||||||||
| 1799 | return static_cast<const QString &>(k1) < static_cast<const QString &>(k2); executed 11504 times by 6 tests: return static_cast<const QString &>(k1) < static_cast<const QString &>(k2);Executed by:
| 11504 | ||||||||||||||||||||||||||||||||||||
| 1800 | } | - | ||||||||||||||||||||||||||||||||||||
| 1801 | - | |||||||||||||||||||||||||||||||||||||
| 1802 | typedef QMap<QSettingsIniKey, QVariant> IniKeyMap; | - | ||||||||||||||||||||||||||||||||||||
| 1803 | - | |||||||||||||||||||||||||||||||||||||
| 1804 | struct QSettingsIniSection | - | ||||||||||||||||||||||||||||||||||||
| 1805 | { | - | ||||||||||||||||||||||||||||||||||||
| 1806 | int position; | - | ||||||||||||||||||||||||||||||||||||
| 1807 | IniKeyMap keyMap; | - | ||||||||||||||||||||||||||||||||||||
| 1808 | - | |||||||||||||||||||||||||||||||||||||
| 1809 | inline QSettingsIniSection() : position(-1) {} executed 421 times by 6 tests: end of blockExecuted by:
| 421 | ||||||||||||||||||||||||||||||||||||
| 1810 | }; | - | ||||||||||||||||||||||||||||||||||||
| 1811 | - | |||||||||||||||||||||||||||||||||||||
| 1812 | typedef QMap<QString, QSettingsIniSection> IniMap; | - | ||||||||||||||||||||||||||||||||||||
| 1813 | - | |||||||||||||||||||||||||||||||||||||
| 1814 | /* | - | ||||||||||||||||||||||||||||||||||||
| 1815 | This would be more straightforward if we didn't try to remember the original | - | ||||||||||||||||||||||||||||||||||||
| 1816 | key order in the .ini file, but we do. | - | ||||||||||||||||||||||||||||||||||||
| 1817 | */ | - | ||||||||||||||||||||||||||||||||||||
| 1818 | bool QConfFileSettingsPrivate::writeIniFile(QIODevice &device, const ParsedSettingsMap &map) | - | ||||||||||||||||||||||||||||||||||||
| 1819 | { | - | ||||||||||||||||||||||||||||||||||||
| 1820 | IniMap iniMap; | - | ||||||||||||||||||||||||||||||||||||
| 1821 | IniMap::const_iterator i; | - | ||||||||||||||||||||||||||||||||||||
| 1822 | - | |||||||||||||||||||||||||||||||||||||
| 1823 | #ifdef Q_OS_WIN | - | ||||||||||||||||||||||||||||||||||||
| 1824 | const char * const eol = "\r\n"; | - | ||||||||||||||||||||||||||||||||||||
| 1825 | #else | - | ||||||||||||||||||||||||||||||||||||
| 1826 | const char eol = '\n'; | - | ||||||||||||||||||||||||||||||||||||
| 1827 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 1828 | - | |||||||||||||||||||||||||||||||||||||
| 1829 | for (ParsedSettingsMap::const_iterator j = map.constBegin(); j != map.constEnd(); ++j) {
| 483-2576 | ||||||||||||||||||||||||||||||||||||
| 1830 | QString section; | - | ||||||||||||||||||||||||||||||||||||
| 1831 | QSettingsIniKey key(j.key().originalCaseKey(), j.key().originalKeyPosition()); | - | ||||||||||||||||||||||||||||||||||||
| 1832 | int slashPos; | - | ||||||||||||||||||||||||||||||||||||
| 1833 | - | |||||||||||||||||||||||||||||||||||||
| 1834 | if ((slashPos = key.indexOf(QLatin1Char('/'))) != -1) {
| 515-2061 | ||||||||||||||||||||||||||||||||||||
| 1835 | section = key.left(slashPos); | - | ||||||||||||||||||||||||||||||||||||
| 1836 | key.remove(0, slashPos + 1); | - | ||||||||||||||||||||||||||||||||||||
| 1837 | } executed 2061 times by 6 tests: end of blockExecuted by:
| 2061 | ||||||||||||||||||||||||||||||||||||
| 1838 | - | |||||||||||||||||||||||||||||||||||||
| 1839 | QSettingsIniSection &iniSection = iniMap[section]; | - | ||||||||||||||||||||||||||||||||||||
| 1840 | - | |||||||||||||||||||||||||||||||||||||
| 1841 | // -1 means infinity | - | ||||||||||||||||||||||||||||||||||||
| 1842 | if (uint(key.position) < uint(iniSection.position))
| 0-2576 | ||||||||||||||||||||||||||||||||||||
| 1843 | iniSection.position = key.position; never executed: iniSection.position = key.position; | 0 | ||||||||||||||||||||||||||||||||||||
| 1844 | iniSection.keyMap[key] = j.value(); | - | ||||||||||||||||||||||||||||||||||||
| 1845 | } executed 2576 times by 6 tests: end of blockExecuted by:
| 2576 | ||||||||||||||||||||||||||||||||||||
| 1846 | - | |||||||||||||||||||||||||||||||||||||
| 1847 | const int sectionCount = iniMap.size(); | - | ||||||||||||||||||||||||||||||||||||
| 1848 | QVector<QSettingsIniKey> sections; | - | ||||||||||||||||||||||||||||||||||||
| 1849 | sections.reserve(sectionCount); | - | ||||||||||||||||||||||||||||||||||||
| 1850 | for (i = iniMap.constBegin(); i != iniMap.constEnd(); ++i)
| 421-483 | ||||||||||||||||||||||||||||||||||||
| 1851 | sections.append(QSettingsIniKey(i.key(), i.value().position)); executed 421 times by 6 tests: sections.append(QSettingsIniKey(i.key(), i.value().position));Executed by:
| 421 | ||||||||||||||||||||||||||||||||||||
| 1852 | std::sort(sections.begin(), sections.end()); | - | ||||||||||||||||||||||||||||||||||||
| 1853 | - | |||||||||||||||||||||||||||||||||||||
| 1854 | bool writeError = false; | - | ||||||||||||||||||||||||||||||||||||
| 1855 | for (int j = 0; !writeError && j < sectionCount; ++j) {
| 0-904 | ||||||||||||||||||||||||||||||||||||
| 1856 | i = iniMap.constFind(sections.at(j)); | - | ||||||||||||||||||||||||||||||||||||
| 1857 | Q_ASSERT(i != iniMap.constEnd()); | - | ||||||||||||||||||||||||||||||||||||
| 1858 | - | |||||||||||||||||||||||||||||||||||||
| 1859 | QByteArray realSection; | - | ||||||||||||||||||||||||||||||||||||
| 1860 | - | |||||||||||||||||||||||||||||||||||||
| 1861 | iniEscapedKey(i.key(), realSection); | - | ||||||||||||||||||||||||||||||||||||
| 1862 | - | |||||||||||||||||||||||||||||||||||||
| 1863 | if (realSection.isEmpty()) {
| 99-322 | ||||||||||||||||||||||||||||||||||||
| 1864 | realSection = "[General]"; | - | ||||||||||||||||||||||||||||||||||||
| 1865 | } else if (qstricmp(realSection.constData(), "general") == 0) { executed 99 times by 1 test: end of blockExecuted by:
| 3-319 | ||||||||||||||||||||||||||||||||||||
| 1866 | realSection = "[%General]"; | - | ||||||||||||||||||||||||||||||||||||
| 1867 | } else { executed 3 times by 1 test: end of blockExecuted by:
| 3 | ||||||||||||||||||||||||||||||||||||
| 1868 | realSection.prepend('['); | - | ||||||||||||||||||||||||||||||||||||
| 1869 | realSection.append(']'); | - | ||||||||||||||||||||||||||||||||||||
| 1870 | } executed 319 times by 6 tests: end of blockExecuted by:
| 319 | ||||||||||||||||||||||||||||||||||||
| 1871 | - | |||||||||||||||||||||||||||||||||||||
| 1872 | if (j != 0)
| 47-374 | ||||||||||||||||||||||||||||||||||||
| 1873 | realSection.prepend(eol); executed 47 times by 4 tests: realSection.prepend(eol);Executed by:
| 47 | ||||||||||||||||||||||||||||||||||||
| 1874 | realSection += eol; | - | ||||||||||||||||||||||||||||||||||||
| 1875 | - | |||||||||||||||||||||||||||||||||||||
| 1876 | device.write(realSection); | - | ||||||||||||||||||||||||||||||||||||
| 1877 | - | |||||||||||||||||||||||||||||||||||||
| 1878 | const IniKeyMap &ents = i.value().keyMap; | - | ||||||||||||||||||||||||||||||||||||
| 1879 | for (IniKeyMap::const_iterator j = ents.constBegin(); j != ents.constEnd(); ++j) {
| 421-2576 | ||||||||||||||||||||||||||||||||||||
| 1880 | QByteArray block; | - | ||||||||||||||||||||||||||||||||||||
| 1881 | iniEscapedKey(j.key(), block); | - | ||||||||||||||||||||||||||||||||||||
| 1882 | block += '='; | - | ||||||||||||||||||||||||||||||||||||
| 1883 | - | |||||||||||||||||||||||||||||||||||||
| 1884 | const QVariant &value = j.value(); | - | ||||||||||||||||||||||||||||||||||||
| 1885 | - | |||||||||||||||||||||||||||||||||||||
| 1886 | /* | - | ||||||||||||||||||||||||||||||||||||
| 1887 | The size() != 1 trick is necessary because | - | ||||||||||||||||||||||||||||||||||||
| 1888 | QVariant(QString("foo")).toList() returns an empty | - | ||||||||||||||||||||||||||||||||||||
| 1889 | list, not a list containing "foo". | - | ||||||||||||||||||||||||||||||||||||
| 1890 | */ | - | ||||||||||||||||||||||||||||||||||||
| 1891 | if (value.type() == QVariant::StringList
| 487-2089 | ||||||||||||||||||||||||||||||||||||
| 1892 | || (value.type() == QVariant::List && value.toList().size() != 1)) {
| 4-2050 | ||||||||||||||||||||||||||||||||||||
| 1893 | iniEscapedStringList(variantListToStringList(value.toList()), block, iniCodec); | - | ||||||||||||||||||||||||||||||||||||
| 1894 | } else { executed 522 times by 6 tests: end of blockExecuted by:
| 522 | ||||||||||||||||||||||||||||||||||||
| 1895 | iniEscapedString(variantToString(value), block, iniCodec); | - | ||||||||||||||||||||||||||||||||||||
| 1896 | } executed 2054 times by 6 tests: end of blockExecuted by:
| 2054 | ||||||||||||||||||||||||||||||||||||
| 1897 | block += eol; | - | ||||||||||||||||||||||||||||||||||||
| 1898 | if (device.write(block) == -1) {
| 0-2576 | ||||||||||||||||||||||||||||||||||||
| 1899 | writeError = true; | - | ||||||||||||||||||||||||||||||||||||
| 1900 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||
| 1901 | } | - | ||||||||||||||||||||||||||||||||||||
| 1902 | } executed 2576 times by 6 tests: end of blockExecuted by:
| 2576 | ||||||||||||||||||||||||||||||||||||
| 1903 | } executed 421 times by 6 tests: end of blockExecuted by:
| 421 | ||||||||||||||||||||||||||||||||||||
| 1904 | return !writeError; executed 483 times by 6 tests: return !writeError;Executed by:
| 483 | ||||||||||||||||||||||||||||||||||||
| 1905 | } | - | ||||||||||||||||||||||||||||||||||||
| 1906 | - | |||||||||||||||||||||||||||||||||||||
| 1907 | void QConfFileSettingsPrivate::ensureAllSectionsParsed(QConfFile *confFile) const | - | ||||||||||||||||||||||||||||||||||||
| 1908 | { | - | ||||||||||||||||||||||||||||||||||||
| 1909 | UnparsedSettingsMap::const_iterator i = confFile->unparsedIniSections.constBegin(); | - | ||||||||||||||||||||||||||||||||||||
| 1910 | const UnparsedSettingsMap::const_iterator end = confFile->unparsedIniSections.constEnd(); | - | ||||||||||||||||||||||||||||||||||||
| 1911 | - | |||||||||||||||||||||||||||||||||||||
| 1912 | for (; i != end; ++i) {
| 1767-8702 | ||||||||||||||||||||||||||||||||||||
| 1913 | if (!QConfFileSettingsPrivate::readIniSection(i.key(), i.value(), &confFile->originalKeys, iniCodec))
| 24-8678 | ||||||||||||||||||||||||||||||||||||
| 1914 | setStatus(QSettings::FormatError); executed 24 times by 3 tests: setStatus(QSettings::FormatError);Executed by:
| 24 | ||||||||||||||||||||||||||||||||||||
| 1915 | } executed 8702 times by 29 tests: end of blockExecuted by:
| 8702 | ||||||||||||||||||||||||||||||||||||
| 1916 | confFile->unparsedIniSections.clear(); | - | ||||||||||||||||||||||||||||||||||||
| 1917 | } executed 1767 times by 29 tests: end of blockExecuted by:
| 1767 | ||||||||||||||||||||||||||||||||||||
| 1918 | - | |||||||||||||||||||||||||||||||||||||
| 1919 | void QConfFileSettingsPrivate::ensureSectionParsed(QConfFile *confFile, | - | ||||||||||||||||||||||||||||||||||||
| 1920 | const QSettingsKey &key) const | - | ||||||||||||||||||||||||||||||||||||
| 1921 | { | - | ||||||||||||||||||||||||||||||||||||
| 1922 | if (confFile->unparsedIniSections.isEmpty())
| 204-47221 | ||||||||||||||||||||||||||||||||||||
| 1923 | return; executed 47221 times by 29 tests: return;Executed by:
| 47221 | ||||||||||||||||||||||||||||||||||||
| 1924 | - | |||||||||||||||||||||||||||||||||||||
| 1925 | UnparsedSettingsMap::iterator i; | - | ||||||||||||||||||||||||||||||||||||
| 1926 | - | |||||||||||||||||||||||||||||||||||||
| 1927 | int indexOfSlash = key.indexOf(QLatin1Char('/')); | - | ||||||||||||||||||||||||||||||||||||
| 1928 | if (indexOfSlash != -1) {
| 64-140 | ||||||||||||||||||||||||||||||||||||
| 1929 | i = confFile->unparsedIniSections.upperBound(key); | - | ||||||||||||||||||||||||||||||||||||
| 1930 | if (i == confFile->unparsedIniSections.begin())
| 6-134 | ||||||||||||||||||||||||||||||||||||
| 1931 | return; executed 6 times by 1 test: return;Executed by:
| 6 | ||||||||||||||||||||||||||||||||||||
| 1932 | --i; | - | ||||||||||||||||||||||||||||||||||||
| 1933 | if (i.key().isEmpty() || !key.startsWith(i.key()))
| 21-113 | ||||||||||||||||||||||||||||||||||||
| 1934 | return; executed 75 times by 3 tests: return;Executed by:
| 75 | ||||||||||||||||||||||||||||||||||||
| 1935 | } else { executed 59 times by 3 tests: end of blockExecuted by:
| 59 | ||||||||||||||||||||||||||||||||||||
| 1936 | i = confFile->unparsedIniSections.begin(); | - | ||||||||||||||||||||||||||||||||||||
| 1937 | if (i == confFile->unparsedIniSections.end() || !i.key().isEmpty())
| 0-64 | ||||||||||||||||||||||||||||||||||||
| 1938 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||
| 1939 | } executed 64 times by 1 test: end of blockExecuted by:
| 64 | ||||||||||||||||||||||||||||||||||||
| 1940 | - | |||||||||||||||||||||||||||||||||||||
| 1941 | if (!QConfFileSettingsPrivate::readIniSection(i.key(), i.value(), &confFile->originalKeys, iniCodec))
| 1-122 | ||||||||||||||||||||||||||||||||||||
| 1942 | setStatus(QSettings::FormatError); executed 1 time by 1 test: setStatus(QSettings::FormatError);Executed by:
| 1 | ||||||||||||||||||||||||||||||||||||
| 1943 | confFile->unparsedIniSections.erase(i); | - | ||||||||||||||||||||||||||||||||||||
| 1944 | } executed 123 times by 3 tests: end of blockExecuted by:
| 123 | ||||||||||||||||||||||||||||||||||||
| 1945 | - | |||||||||||||||||||||||||||||||||||||
| 1946 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 1947 | \class QSettings | - | ||||||||||||||||||||||||||||||||||||
| 1948 | \inmodule QtCore | - | ||||||||||||||||||||||||||||||||||||
| 1949 | \brief The QSettings class provides persistent platform-independent application settings. | - | ||||||||||||||||||||||||||||||||||||
| 1950 | - | |||||||||||||||||||||||||||||||||||||
| 1951 | \ingroup io | - | ||||||||||||||||||||||||||||||||||||
| 1952 | - | |||||||||||||||||||||||||||||||||||||
| 1953 | \reentrant | - | ||||||||||||||||||||||||||||||||||||
| 1954 | - | |||||||||||||||||||||||||||||||||||||
| 1955 | Users normally expect an application to remember its settings | - | ||||||||||||||||||||||||||||||||||||
| 1956 | (window sizes and positions, options, etc.) across sessions. This | - | ||||||||||||||||||||||||||||||||||||
| 1957 | information is often stored in the system registry on Windows, | - | ||||||||||||||||||||||||||||||||||||
| 1958 | and in property list files on \macos and iOS. On Unix systems, in the | - | ||||||||||||||||||||||||||||||||||||
| 1959 | absence of a standard, many applications (including the KDE | - | ||||||||||||||||||||||||||||||||||||
| 1960 | applications) use INI text files. | - | ||||||||||||||||||||||||||||||||||||
| 1961 | - | |||||||||||||||||||||||||||||||||||||
| 1962 | QSettings is an abstraction around these technologies, enabling | - | ||||||||||||||||||||||||||||||||||||
| 1963 | you to save and restore application settings in a portable | - | ||||||||||||||||||||||||||||||||||||
| 1964 | manner. It also supports \l{registerFormat()}{custom storage | - | ||||||||||||||||||||||||||||||||||||
| 1965 | formats}. | - | ||||||||||||||||||||||||||||||||||||
| 1966 | - | |||||||||||||||||||||||||||||||||||||
| 1967 | QSettings's API is based on QVariant, allowing you to save | - | ||||||||||||||||||||||||||||||||||||
| 1968 | most value-based types, such as QString, QRect, and QImage, | - | ||||||||||||||||||||||||||||||||||||
| 1969 | with the minimum of effort. | - | ||||||||||||||||||||||||||||||||||||
| 1970 | - | |||||||||||||||||||||||||||||||||||||
| 1971 | If all you need is a non-persistent memory-based structure, | - | ||||||||||||||||||||||||||||||||||||
| 1972 | consider using QMap<QString, QVariant> instead. | - | ||||||||||||||||||||||||||||||||||||
| 1973 | - | |||||||||||||||||||||||||||||||||||||
| 1974 | \tableofcontents section1 | - | ||||||||||||||||||||||||||||||||||||
| 1975 | - | |||||||||||||||||||||||||||||||||||||
| 1976 | \section1 Basic Usage | - | ||||||||||||||||||||||||||||||||||||
| 1977 | - | |||||||||||||||||||||||||||||||||||||
| 1978 | When creating a QSettings object, you must pass the name of your | - | ||||||||||||||||||||||||||||||||||||
| 1979 | company or organization as well as the name of your application. | - | ||||||||||||||||||||||||||||||||||||
| 1980 | For example, if your product is called Star Runner and your | - | ||||||||||||||||||||||||||||||||||||
| 1981 | company is called MySoft, you would construct the QSettings | - | ||||||||||||||||||||||||||||||||||||
| 1982 | object as follows: | - | ||||||||||||||||||||||||||||||||||||
| 1983 | - | |||||||||||||||||||||||||||||||||||||
| 1984 | \snippet settings/settings.cpp 0 | - | ||||||||||||||||||||||||||||||||||||
| 1985 | - | |||||||||||||||||||||||||||||||||||||
| 1986 | QSettings objects can be created either on the stack or on | - | ||||||||||||||||||||||||||||||||||||
| 1987 | the heap (i.e. using \c new). Constructing and destroying a | - | ||||||||||||||||||||||||||||||||||||
| 1988 | QSettings object is very fast. | - | ||||||||||||||||||||||||||||||||||||
| 1989 | - | |||||||||||||||||||||||||||||||||||||
| 1990 | If you use QSettings from many places in your application, you | - | ||||||||||||||||||||||||||||||||||||
| 1991 | might want to specify the organization name and the application | - | ||||||||||||||||||||||||||||||||||||
| 1992 | name using QCoreApplication::setOrganizationName() and | - | ||||||||||||||||||||||||||||||||||||
| 1993 | QCoreApplication::setApplicationName(), and then use the default | - | ||||||||||||||||||||||||||||||||||||
| 1994 | QSettings constructor: | - | ||||||||||||||||||||||||||||||||||||
| 1995 | - | |||||||||||||||||||||||||||||||||||||
| 1996 | \snippet settings/settings.cpp 1 | - | ||||||||||||||||||||||||||||||||||||
| 1997 | \snippet settings/settings.cpp 2 | - | ||||||||||||||||||||||||||||||||||||
| 1998 | \snippet settings/settings.cpp 3 | - | ||||||||||||||||||||||||||||||||||||
| 1999 | \dots | - | ||||||||||||||||||||||||||||||||||||
| 2000 | \snippet settings/settings.cpp 4 | - | ||||||||||||||||||||||||||||||||||||
| 2001 | - | |||||||||||||||||||||||||||||||||||||
| 2002 | (Here, we also specify the organization's Internet domain. When | - | ||||||||||||||||||||||||||||||||||||
| 2003 | the Internet domain is set, it is used on \macos and iOS instead of the | - | ||||||||||||||||||||||||||||||||||||
| 2004 | organization name, since \macos and iOS applications conventionally use | - | ||||||||||||||||||||||||||||||||||||
| 2005 | Internet domains to identify themselves. If no domain is set, a | - | ||||||||||||||||||||||||||||||||||||
| 2006 | fake domain is derived from the organization name. See the | - | ||||||||||||||||||||||||||||||||||||
| 2007 | \l{Platform-Specific Notes} below for details.) | - | ||||||||||||||||||||||||||||||||||||
| 2008 | - | |||||||||||||||||||||||||||||||||||||
| 2009 | QSettings stores settings. Each setting consists of a QString | - | ||||||||||||||||||||||||||||||||||||
| 2010 | that specifies the setting's name (the \e key) and a QVariant | - | ||||||||||||||||||||||||||||||||||||
| 2011 | that stores the data associated with the key. To write a setting, | - | ||||||||||||||||||||||||||||||||||||
| 2012 | use setValue(). For example: | - | ||||||||||||||||||||||||||||||||||||
| 2013 | - | |||||||||||||||||||||||||||||||||||||
| 2014 | \snippet settings/settings.cpp 5 | - | ||||||||||||||||||||||||||||||||||||
| 2015 | - | |||||||||||||||||||||||||||||||||||||
| 2016 | If there already exists a setting with the same key, the existing | - | ||||||||||||||||||||||||||||||||||||
| 2017 | value is overwritten by the new value. For efficiency, the | - | ||||||||||||||||||||||||||||||||||||
| 2018 | changes may not be saved to permanent storage immediately. (You | - | ||||||||||||||||||||||||||||||||||||
| 2019 | can always call sync() to commit your changes.) | - | ||||||||||||||||||||||||||||||||||||
| 2020 | - | |||||||||||||||||||||||||||||||||||||
| 2021 | You can get a setting's value back using value(): | - | ||||||||||||||||||||||||||||||||||||
| 2022 | - | |||||||||||||||||||||||||||||||||||||
| 2023 | \snippet settings/settings.cpp 6 | - | ||||||||||||||||||||||||||||||||||||
| 2024 | - | |||||||||||||||||||||||||||||||||||||
| 2025 | If there is no setting with the specified name, QSettings | - | ||||||||||||||||||||||||||||||||||||
| 2026 | returns a null QVariant (which can be converted to the integer 0). | - | ||||||||||||||||||||||||||||||||||||
| 2027 | You can specify another default value by passing a second | - | ||||||||||||||||||||||||||||||||||||
| 2028 | argument to value(): | - | ||||||||||||||||||||||||||||||||||||
| 2029 | - | |||||||||||||||||||||||||||||||||||||
| 2030 | \snippet settings/settings.cpp 7 | - | ||||||||||||||||||||||||||||||||||||
| 2031 | - | |||||||||||||||||||||||||||||||||||||
| 2032 | To test whether a given key exists, call contains(). To remove | - | ||||||||||||||||||||||||||||||||||||
| 2033 | the setting associated with a key, call remove(). To obtain the | - | ||||||||||||||||||||||||||||||||||||
| 2034 | list of all keys, call allKeys(). To remove all keys, call | - | ||||||||||||||||||||||||||||||||||||
| 2035 | clear(). | - | ||||||||||||||||||||||||||||||||||||
| 2036 | - | |||||||||||||||||||||||||||||||||||||
| 2037 | \section1 QVariant and GUI Types | - | ||||||||||||||||||||||||||||||||||||
| 2038 | - | |||||||||||||||||||||||||||||||||||||
| 2039 | Because QVariant is part of the Qt Core module, it cannot provide | - | ||||||||||||||||||||||||||||||||||||
| 2040 | conversion functions to data types such as QColor, QImage, and | - | ||||||||||||||||||||||||||||||||||||
| 2041 | QPixmap, which are part of Qt GUI. In other words, there is no | - | ||||||||||||||||||||||||||||||||||||
| 2042 | \c toColor(), \c toImage(), or \c toPixmap() functions in QVariant. | - | ||||||||||||||||||||||||||||||||||||
| 2043 | - | |||||||||||||||||||||||||||||||||||||
| 2044 | Instead, you can use the QVariant::value() or the qVariantValue() | - | ||||||||||||||||||||||||||||||||||||
| 2045 | template function. For example: | - | ||||||||||||||||||||||||||||||||||||
| 2046 | - | |||||||||||||||||||||||||||||||||||||
| 2047 | \snippet code/src_corelib_io_qsettings.cpp 0 | - | ||||||||||||||||||||||||||||||||||||
| 2048 | - | |||||||||||||||||||||||||||||||||||||
| 2049 | The inverse conversion (e.g., from QColor to QVariant) is | - | ||||||||||||||||||||||||||||||||||||
| 2050 | automatic for all data types supported by QVariant, including | - | ||||||||||||||||||||||||||||||||||||
| 2051 | GUI-related types: | - | ||||||||||||||||||||||||||||||||||||
| 2052 | - | |||||||||||||||||||||||||||||||||||||
| 2053 | \snippet code/src_corelib_io_qsettings.cpp 1 | - | ||||||||||||||||||||||||||||||||||||
| 2054 | - | |||||||||||||||||||||||||||||||||||||
| 2055 | Custom types registered using qRegisterMetaType() and | - | ||||||||||||||||||||||||||||||||||||
| 2056 | qRegisterMetaTypeStreamOperators() can be stored using QSettings. | - | ||||||||||||||||||||||||||||||||||||
| 2057 | - | |||||||||||||||||||||||||||||||||||||
| 2058 | \section1 Section and Key Syntax | - | ||||||||||||||||||||||||||||||||||||
| 2059 | - | |||||||||||||||||||||||||||||||||||||
| 2060 | Setting keys can contain any Unicode characters. The Windows | - | ||||||||||||||||||||||||||||||||||||
| 2061 | registry and INI files use case-insensitive keys, whereas the | - | ||||||||||||||||||||||||||||||||||||
| 2062 | CFPreferences API on \macos and iOS uses case-sensitive keys. To | - | ||||||||||||||||||||||||||||||||||||
| 2063 | avoid portability problems, follow these simple rules: | - | ||||||||||||||||||||||||||||||||||||
| 2064 | - | |||||||||||||||||||||||||||||||||||||
| 2065 | \list 1 | - | ||||||||||||||||||||||||||||||||||||
| 2066 | \li Always refer to the same key using the same case. For example, | - | ||||||||||||||||||||||||||||||||||||
| 2067 | if you refer to a key as "text fonts" in one place in your | - | ||||||||||||||||||||||||||||||||||||
| 2068 | code, don't refer to it as "Text Fonts" somewhere else. | - | ||||||||||||||||||||||||||||||||||||
| 2069 | - | |||||||||||||||||||||||||||||||||||||
| 2070 | \li Avoid key names that are identical except for the case. For | - | ||||||||||||||||||||||||||||||||||||
| 2071 | example, if you have a key called "MainWindow", don't try to | - | ||||||||||||||||||||||||||||||||||||
| 2072 | save another key as "mainwindow". | - | ||||||||||||||||||||||||||||||||||||
| 2073 | - | |||||||||||||||||||||||||||||||||||||
| 2074 | \li Do not use slashes ('/' and '\\') in section or key names; the | - | ||||||||||||||||||||||||||||||||||||
| 2075 | backslash character is used to separate sub keys (see below). On | - | ||||||||||||||||||||||||||||||||||||
| 2076 | windows '\\' are converted by QSettings to '/', which makes | - | ||||||||||||||||||||||||||||||||||||
| 2077 | them identical. | - | ||||||||||||||||||||||||||||||||||||
| 2078 | \endlist | - | ||||||||||||||||||||||||||||||||||||
| 2079 | - | |||||||||||||||||||||||||||||||||||||
| 2080 | You can form hierarchical keys using the '/' character as a | - | ||||||||||||||||||||||||||||||||||||
| 2081 | separator, similar to Unix file paths. For example: | - | ||||||||||||||||||||||||||||||||||||
| 2082 | - | |||||||||||||||||||||||||||||||||||||
| 2083 | \snippet settings/settings.cpp 8 | - | ||||||||||||||||||||||||||||||||||||
| 2084 | \snippet settings/settings.cpp 9 | - | ||||||||||||||||||||||||||||||||||||
| 2085 | \snippet settings/settings.cpp 10 | - | ||||||||||||||||||||||||||||||||||||
| 2086 | - | |||||||||||||||||||||||||||||||||||||
| 2087 | If you want to save or restore many settings with the same | - | ||||||||||||||||||||||||||||||||||||
| 2088 | prefix, you can specify the prefix using beginGroup() and call | - | ||||||||||||||||||||||||||||||||||||
| 2089 | endGroup() at the end. Here's the same example again, but this | - | ||||||||||||||||||||||||||||||||||||
| 2090 | time using the group mechanism: | - | ||||||||||||||||||||||||||||||||||||
| 2091 | - | |||||||||||||||||||||||||||||||||||||
| 2092 | \snippet settings/settings.cpp 11 | - | ||||||||||||||||||||||||||||||||||||
| 2093 | \codeline | - | ||||||||||||||||||||||||||||||||||||
| 2094 | \snippet settings/settings.cpp 12 | - | ||||||||||||||||||||||||||||||||||||
| 2095 | - | |||||||||||||||||||||||||||||||||||||
| 2096 | If a group is set using beginGroup(), the behavior of most | - | ||||||||||||||||||||||||||||||||||||
| 2097 | functions changes consequently. Groups can be set recursively. | - | ||||||||||||||||||||||||||||||||||||
| 2098 | - | |||||||||||||||||||||||||||||||||||||
| 2099 | In addition to groups, QSettings also supports an "array" | - | ||||||||||||||||||||||||||||||||||||
| 2100 | concept. See beginReadArray() and beginWriteArray() for details. | - | ||||||||||||||||||||||||||||||||||||
| 2101 | - | |||||||||||||||||||||||||||||||||||||
| 2102 | \section1 Fallback Mechanism | - | ||||||||||||||||||||||||||||||||||||
| 2103 | - | |||||||||||||||||||||||||||||||||||||
| 2104 | Let's assume that you have created a QSettings object with the | - | ||||||||||||||||||||||||||||||||||||
| 2105 | organization name MySoft and the application name Star Runner. | - | ||||||||||||||||||||||||||||||||||||
| 2106 | When you look up a value, up to four locations are searched in | - | ||||||||||||||||||||||||||||||||||||
| 2107 | that order: | - | ||||||||||||||||||||||||||||||||||||
| 2108 | - | |||||||||||||||||||||||||||||||||||||
| 2109 | \list 1 | - | ||||||||||||||||||||||||||||||||||||
| 2110 | \li a user-specific location for the Star Runner application | - | ||||||||||||||||||||||||||||||||||||
| 2111 | \li a user-specific location for all applications by MySoft | - | ||||||||||||||||||||||||||||||||||||
| 2112 | \li a system-wide location for the Star Runner application | - | ||||||||||||||||||||||||||||||||||||
| 2113 | \li a system-wide location for all applications by MySoft | - | ||||||||||||||||||||||||||||||||||||
| 2114 | \endlist | - | ||||||||||||||||||||||||||||||||||||
| 2115 | - | |||||||||||||||||||||||||||||||||||||
| 2116 | (See \l{Platform-Specific Notes} below for information on what | - | ||||||||||||||||||||||||||||||||||||
| 2117 | these locations are on the different platforms supported by Qt.) | - | ||||||||||||||||||||||||||||||||||||
| 2118 | - | |||||||||||||||||||||||||||||||||||||
| 2119 | If a key cannot be found in the first location, the search goes | - | ||||||||||||||||||||||||||||||||||||
| 2120 | on in the second location, and so on. This enables you to store | - | ||||||||||||||||||||||||||||||||||||
| 2121 | system-wide or organization-wide settings and to override them on | - | ||||||||||||||||||||||||||||||||||||
| 2122 | a per-user or per-application basis. To turn off this mechanism, | - | ||||||||||||||||||||||||||||||||||||
| 2123 | call setFallbacksEnabled(false). | - | ||||||||||||||||||||||||||||||||||||
| 2124 | - | |||||||||||||||||||||||||||||||||||||
| 2125 | Although keys from all four locations are available for reading, | - | ||||||||||||||||||||||||||||||||||||
| 2126 | only the first file (the user-specific location for the | - | ||||||||||||||||||||||||||||||||||||
| 2127 | application at hand) is accessible for writing. To write to any | - | ||||||||||||||||||||||||||||||||||||
| 2128 | of the other files, omit the application name and/or specify | - | ||||||||||||||||||||||||||||||||||||
| 2129 | QSettings::SystemScope (as opposed to QSettings::UserScope, the | - | ||||||||||||||||||||||||||||||||||||
| 2130 | default). | - | ||||||||||||||||||||||||||||||||||||
| 2131 | - | |||||||||||||||||||||||||||||||||||||
| 2132 | Let's see with an example: | - | ||||||||||||||||||||||||||||||||||||
| 2133 | - | |||||||||||||||||||||||||||||||||||||
| 2134 | \snippet settings/settings.cpp 13 | - | ||||||||||||||||||||||||||||||||||||
| 2135 | \snippet settings/settings.cpp 14 | - | ||||||||||||||||||||||||||||||||||||
| 2136 | - | |||||||||||||||||||||||||||||||||||||
| 2137 | The table below summarizes which QSettings objects access | - | ||||||||||||||||||||||||||||||||||||
| 2138 | which location. "\b{X}" means that the location is the main | - | ||||||||||||||||||||||||||||||||||||
| 2139 | location associated to the QSettings object and is used both | - | ||||||||||||||||||||||||||||||||||||
| 2140 | for reading and for writing; "o" means that the location is used | - | ||||||||||||||||||||||||||||||||||||
| 2141 | as a fallback when reading. | - | ||||||||||||||||||||||||||||||||||||
| 2142 | - | |||||||||||||||||||||||||||||||||||||
| 2143 | \table | - | ||||||||||||||||||||||||||||||||||||
| 2144 | \header \li Locations \li \c{obj1} \li \c{obj2} \li \c{obj3} \li \c{obj4} | - | ||||||||||||||||||||||||||||||||||||
| 2145 | \row \li 1. User, Application \li \b{X} \li \li \li | - | ||||||||||||||||||||||||||||||||||||
| 2146 | \row \li 2. User, Organization \li o \li \b{X} \li \li | - | ||||||||||||||||||||||||||||||||||||
| 2147 | \row \li 3. System, Application \li o \li \li \b{X} \li | - | ||||||||||||||||||||||||||||||||||||
| 2148 | \row \li 4. System, Organization \li o \li o \li o \li \b{X} | - | ||||||||||||||||||||||||||||||||||||
| 2149 | \endtable | - | ||||||||||||||||||||||||||||||||||||
| 2150 | - | |||||||||||||||||||||||||||||||||||||
| 2151 | The beauty of this mechanism is that it works on all platforms | - | ||||||||||||||||||||||||||||||||||||
| 2152 | supported by Qt and that it still gives you a lot of flexibility, | - | ||||||||||||||||||||||||||||||||||||
| 2153 | without requiring you to specify any file names or registry | - | ||||||||||||||||||||||||||||||||||||
| 2154 | paths. | - | ||||||||||||||||||||||||||||||||||||
| 2155 | - | |||||||||||||||||||||||||||||||||||||
| 2156 | If you want to use INI files on all platforms instead of the | - | ||||||||||||||||||||||||||||||||||||
| 2157 | native API, you can pass QSettings::IniFormat as the first | - | ||||||||||||||||||||||||||||||||||||
| 2158 | argument to the QSettings constructor, followed by the scope, the | - | ||||||||||||||||||||||||||||||||||||
| 2159 | organization name, and the application name: | - | ||||||||||||||||||||||||||||||||||||
| 2160 | - | |||||||||||||||||||||||||||||||||||||
| 2161 | \snippet settings/settings.cpp 15 | - | ||||||||||||||||||||||||||||||||||||
| 2162 | - | |||||||||||||||||||||||||||||||||||||
| 2163 | The \l{tools/settingseditor}{Settings Editor} example lets you | - | ||||||||||||||||||||||||||||||||||||
| 2164 | experiment with different settings location and with fallbacks | - | ||||||||||||||||||||||||||||||||||||
| 2165 | turned on or off. | - | ||||||||||||||||||||||||||||||||||||
| 2166 | - | |||||||||||||||||||||||||||||||||||||
| 2167 | \section1 Restoring the State of a GUI Application | - | ||||||||||||||||||||||||||||||||||||
| 2168 | - | |||||||||||||||||||||||||||||||||||||
| 2169 | QSettings is often used to store the state of a GUI | - | ||||||||||||||||||||||||||||||||||||
| 2170 | application. The following example illustrates how to use QSettings | - | ||||||||||||||||||||||||||||||||||||
| 2171 | to save and restore the geometry of an application's main window. | - | ||||||||||||||||||||||||||||||||||||
| 2172 | - | |||||||||||||||||||||||||||||||||||||
| 2173 | \snippet settings/settings.cpp 16 | - | ||||||||||||||||||||||||||||||||||||
| 2174 | \codeline | - | ||||||||||||||||||||||||||||||||||||
| 2175 | \snippet settings/settings.cpp 17 | - | ||||||||||||||||||||||||||||||||||||
| 2176 | - | |||||||||||||||||||||||||||||||||||||
| 2177 | See \l{Window Geometry} for a discussion on why it is better to | - | ||||||||||||||||||||||||||||||||||||
| 2178 | call QWidget::resize() and QWidget::move() rather than QWidget::setGeometry() | - | ||||||||||||||||||||||||||||||||||||
| 2179 | to restore a window's geometry. | - | ||||||||||||||||||||||||||||||||||||
| 2180 | - | |||||||||||||||||||||||||||||||||||||
| 2181 | The \c readSettings() and \c writeSettings() functions must be | - | ||||||||||||||||||||||||||||||||||||
| 2182 | called from the main window's constructor and close event handler | - | ||||||||||||||||||||||||||||||||||||
| 2183 | as follows: | - | ||||||||||||||||||||||||||||||||||||
| 2184 | - | |||||||||||||||||||||||||||||||||||||
| 2185 | \snippet settings/settings.cpp 18 | - | ||||||||||||||||||||||||||||||||||||
| 2186 | \dots | - | ||||||||||||||||||||||||||||||||||||
| 2187 | \snippet settings/settings.cpp 19 | - | ||||||||||||||||||||||||||||||||||||
| 2188 | \snippet settings/settings.cpp 20 | - | ||||||||||||||||||||||||||||||||||||
| 2189 | \codeline | - | ||||||||||||||||||||||||||||||||||||
| 2190 | \snippet settings/settings.cpp 21 | - | ||||||||||||||||||||||||||||||||||||
| 2191 | - | |||||||||||||||||||||||||||||||||||||
| 2192 | See the \l{mainwindows/application}{Application} example for a | - | ||||||||||||||||||||||||||||||||||||
| 2193 | self-contained example that uses QSettings. | - | ||||||||||||||||||||||||||||||||||||
| 2194 | - | |||||||||||||||||||||||||||||||||||||
| 2195 | \section1 Accessing Settings from Multiple Threads or Processes Simultaneously | - | ||||||||||||||||||||||||||||||||||||
| 2196 | - | |||||||||||||||||||||||||||||||||||||
| 2197 | QSettings is \l{reentrant}. This means that you can use | - | ||||||||||||||||||||||||||||||||||||
| 2198 | distinct QSettings object in different threads | - | ||||||||||||||||||||||||||||||||||||
| 2199 | simultaneously. This guarantee stands even when the QSettings | - | ||||||||||||||||||||||||||||||||||||
| 2200 | objects refer to the same files on disk (or to the same entries | - | ||||||||||||||||||||||||||||||||||||
| 2201 | in the system registry). If a setting is modified through one | - | ||||||||||||||||||||||||||||||||||||
| 2202 | QSettings object, the change will immediately be visible in | - | ||||||||||||||||||||||||||||||||||||
| 2203 | any other QSettings objects that operate on the same location | - | ||||||||||||||||||||||||||||||||||||
| 2204 | and that live in the same process. | - | ||||||||||||||||||||||||||||||||||||
| 2205 | - | |||||||||||||||||||||||||||||||||||||
| 2206 | QSettings can safely be used from different processes (which can | - | ||||||||||||||||||||||||||||||||||||
| 2207 | be different instances of your application running at the same | - | ||||||||||||||||||||||||||||||||||||
| 2208 | time or different applications altogether) to read and write to | - | ||||||||||||||||||||||||||||||||||||
| 2209 | the same system locations. It uses advisory file locking and a | - | ||||||||||||||||||||||||||||||||||||
| 2210 | smart merging algorithm to ensure data integrity. Note that sync() | - | ||||||||||||||||||||||||||||||||||||
| 2211 | imports changes made by other processes (in addition to writing | - | ||||||||||||||||||||||||||||||||||||
| 2212 | the changes from this QSettings). | - | ||||||||||||||||||||||||||||||||||||
| 2213 | - | |||||||||||||||||||||||||||||||||||||
| 2214 | \section1 Platform-Specific Notes | - | ||||||||||||||||||||||||||||||||||||
| 2215 | - | |||||||||||||||||||||||||||||||||||||
| 2216 | \section2 Locations Where Application Settings Are Stored | - | ||||||||||||||||||||||||||||||||||||
| 2217 | - | |||||||||||||||||||||||||||||||||||||
| 2218 | As mentioned in the \l{Fallback Mechanism} section, QSettings | - | ||||||||||||||||||||||||||||||||||||
| 2219 | stores settings for an application in up to four locations, | - | ||||||||||||||||||||||||||||||||||||
| 2220 | depending on whether the settings are user-specific or | - | ||||||||||||||||||||||||||||||||||||
| 2221 | system-wide and whether the settings are application-specific | - | ||||||||||||||||||||||||||||||||||||
| 2222 | or organization-wide. For simplicity, we're assuming the | - | ||||||||||||||||||||||||||||||||||||
| 2223 | organization is called MySoft and the application is called Star | - | ||||||||||||||||||||||||||||||||||||
| 2224 | Runner. | - | ||||||||||||||||||||||||||||||||||||
| 2225 | - | |||||||||||||||||||||||||||||||||||||
| 2226 | On Unix systems, if the file format is NativeFormat, the | - | ||||||||||||||||||||||||||||||||||||
| 2227 | following files are used by default: | - | ||||||||||||||||||||||||||||||||||||
| 2228 | - | |||||||||||||||||||||||||||||||||||||
| 2229 | \list 1 | - | ||||||||||||||||||||||||||||||||||||
| 2230 | \li \c{$HOME/.config/MySoft/Star Runner.conf} (Qt for Embedded Linux: \c{$HOME/Settings/MySoft/Star Runner.conf}) | - | ||||||||||||||||||||||||||||||||||||
| 2231 | \li \c{$HOME/.config/MySoft.conf} (Qt for Embedded Linux: \c{$HOME/Settings/MySoft.conf}) | - | ||||||||||||||||||||||||||||||||||||
| 2232 | \li \c{/etc/xdg/MySoft/Star Runner.conf} | - | ||||||||||||||||||||||||||||||||||||
| 2233 | \li \c{/etc/xdg/MySoft.conf} | - | ||||||||||||||||||||||||||||||||||||
| 2234 | \endlist | - | ||||||||||||||||||||||||||||||||||||
| 2235 | - | |||||||||||||||||||||||||||||||||||||
| 2236 | On \macos versions 10.2 and 10.3, these files are used by | - | ||||||||||||||||||||||||||||||||||||
| 2237 | default: | - | ||||||||||||||||||||||||||||||||||||
| 2238 | - | |||||||||||||||||||||||||||||||||||||
| 2239 | \list 1 | - | ||||||||||||||||||||||||||||||||||||
| 2240 | \li \c{$HOME/Library/Preferences/com.MySoft.Star Runner.plist} | - | ||||||||||||||||||||||||||||||||||||
| 2241 | \li \c{$HOME/Library/Preferences/com.MySoft.plist} | - | ||||||||||||||||||||||||||||||||||||
| 2242 | \li \c{/Library/Preferences/com.MySoft.Star Runner.plist} | - | ||||||||||||||||||||||||||||||||||||
| 2243 | \li \c{/Library/Preferences/com.MySoft.plist} | - | ||||||||||||||||||||||||||||||||||||
| 2244 | \endlist | - | ||||||||||||||||||||||||||||||||||||
| 2245 | - | |||||||||||||||||||||||||||||||||||||
| 2246 | On Windows, NativeFormat settings are stored in the following | - | ||||||||||||||||||||||||||||||||||||
| 2247 | registry paths: | - | ||||||||||||||||||||||||||||||||||||
| 2248 | - | |||||||||||||||||||||||||||||||||||||
| 2249 | \list 1 | - | ||||||||||||||||||||||||||||||||||||
| 2250 | \li \c{HKEY_CURRENT_USER\Software\MySoft\Star Runner} | - | ||||||||||||||||||||||||||||||||||||
| 2251 | \li \c{HKEY_CURRENT_USER\Software\MySoft\OrganizationDefaults} | - | ||||||||||||||||||||||||||||||||||||
| 2252 | \li \c{HKEY_LOCAL_MACHINE\Software\MySoft\Star Runner} | - | ||||||||||||||||||||||||||||||||||||
| 2253 | \li \c{HKEY_LOCAL_MACHINE\Software\MySoft\OrganizationDefaults} | - | ||||||||||||||||||||||||||||||||||||
| 2254 | \endlist | - | ||||||||||||||||||||||||||||||||||||
| 2255 | - | |||||||||||||||||||||||||||||||||||||
| 2256 | \note On Windows, for 32-bit programs running in WOW64 mode, settings are | - | ||||||||||||||||||||||||||||||||||||
| 2257 | stored in the following registry path: | - | ||||||||||||||||||||||||||||||||||||
| 2258 | \c{HKEY_LOCAL_MACHINE\Software\WOW6432node}. | - | ||||||||||||||||||||||||||||||||||||
| 2259 | - | |||||||||||||||||||||||||||||||||||||
| 2260 | On BlackBerry only a single file is used (see \l{Platform Limitations}). | - | ||||||||||||||||||||||||||||||||||||
| 2261 | If the file format is NativeFormat, this is "Settings/MySoft/Star Runner.conf" | - | ||||||||||||||||||||||||||||||||||||
| 2262 | in the application's home directory. | - | ||||||||||||||||||||||||||||||||||||
| 2263 | - | |||||||||||||||||||||||||||||||||||||
| 2264 | If the file format is IniFormat, the following files are | - | ||||||||||||||||||||||||||||||||||||
| 2265 | used on Unix, \macos, and iOS: | - | ||||||||||||||||||||||||||||||||||||
| 2266 | - | |||||||||||||||||||||||||||||||||||||
| 2267 | \list 1 | - | ||||||||||||||||||||||||||||||||||||
| 2268 | \li \c{$HOME/.config/MySoft/Star Runner.ini} (Qt for Embedded Linux: \c{$HOME/Settings/MySoft/Star Runner.ini}) | - | ||||||||||||||||||||||||||||||||||||
| 2269 | \li \c{$HOME/.config/MySoft.ini} (Qt for Embedded Linux: \c{$HOME/Settings/MySoft.ini}) | - | ||||||||||||||||||||||||||||||||||||
| 2270 | \li \c{/etc/xdg/MySoft/Star Runner.ini} | - | ||||||||||||||||||||||||||||||||||||
| 2271 | \li \c{/etc/xdg/MySoft.ini} | - | ||||||||||||||||||||||||||||||||||||
| 2272 | \endlist | - | ||||||||||||||||||||||||||||||||||||
| 2273 | - | |||||||||||||||||||||||||||||||||||||
| 2274 | On Windows, the following files are used: | - | ||||||||||||||||||||||||||||||||||||
| 2275 | - | |||||||||||||||||||||||||||||||||||||
| 2276 | \list 1 | - | ||||||||||||||||||||||||||||||||||||
| 2277 | \li \c{CSIDL_APPDATA\MySoft\Star Runner.ini} | - | ||||||||||||||||||||||||||||||||||||
| 2278 | \li \c{CSIDL_APPDATA\MySoft.ini} | - | ||||||||||||||||||||||||||||||||||||
| 2279 | \li \c{CSIDL_COMMON_APPDATA\MySoft\Star Runner.ini} | - | ||||||||||||||||||||||||||||||||||||
| 2280 | \li \c{CSIDL_COMMON_APPDATA\MySoft.ini} | - | ||||||||||||||||||||||||||||||||||||
| 2281 | \endlist | - | ||||||||||||||||||||||||||||||||||||
| 2282 | - | |||||||||||||||||||||||||||||||||||||
| 2283 | The identifiers prefixed by \c{CSIDL_} are special item ID lists to be passed | - | ||||||||||||||||||||||||||||||||||||
| 2284 | to the Win32 API function \c{SHGetSpecialFolderPath()} to obtain the | - | ||||||||||||||||||||||||||||||||||||
| 2285 | corresponding path. | - | ||||||||||||||||||||||||||||||||||||
| 2286 | - | |||||||||||||||||||||||||||||||||||||
| 2287 | \c{CSIDL_APPDATA} usually points to \tt{C:\\Users\\\e{User Name}\\AppData\\Roaming}, | - | ||||||||||||||||||||||||||||||||||||
| 2288 | also shown by the environment variable \c{%APPDATA%}. | - | ||||||||||||||||||||||||||||||||||||
| 2289 | - | |||||||||||||||||||||||||||||||||||||
| 2290 | \c{CSIDL_COMMON_APPDATA} usually points to \tt{C:\\ProgramData}. | - | ||||||||||||||||||||||||||||||||||||
| 2291 | - | |||||||||||||||||||||||||||||||||||||
| 2292 | On BlackBerry only a single file is used (see \l{Platform Limitations}). | - | ||||||||||||||||||||||||||||||||||||
| 2293 | If the file format is IniFormat, this is "Settings/MySoft/Star Runner.ini" | - | ||||||||||||||||||||||||||||||||||||
| 2294 | in the application's home directory. | - | ||||||||||||||||||||||||||||||||||||
| 2295 | - | |||||||||||||||||||||||||||||||||||||
| 2296 | The paths for the \c .ini and \c .conf files can be changed using | - | ||||||||||||||||||||||||||||||||||||
| 2297 | setPath(). On Unix, \macos, and iOS the user can override them by | - | ||||||||||||||||||||||||||||||||||||
| 2298 | setting the \c XDG_CONFIG_HOME environment variable; see | - | ||||||||||||||||||||||||||||||||||||
| 2299 | setPath() for details. | - | ||||||||||||||||||||||||||||||||||||
| 2300 | - | |||||||||||||||||||||||||||||||||||||
| 2301 | \section2 Accessing INI and .plist Files Directly | - | ||||||||||||||||||||||||||||||||||||
| 2302 | - | |||||||||||||||||||||||||||||||||||||
| 2303 | Sometimes you do want to access settings stored in a specific | - | ||||||||||||||||||||||||||||||||||||
| 2304 | file or registry path. On all platforms, if you want to read an | - | ||||||||||||||||||||||||||||||||||||
| 2305 | INI file directly, you can use the QSettings constructor that | - | ||||||||||||||||||||||||||||||||||||
| 2306 | takes a file name as first argument and pass QSettings::IniFormat | - | ||||||||||||||||||||||||||||||||||||
| 2307 | as second argument. For example: | - | ||||||||||||||||||||||||||||||||||||
| 2308 | - | |||||||||||||||||||||||||||||||||||||
| 2309 | \snippet code/src_corelib_io_qsettings.cpp 2 | - | ||||||||||||||||||||||||||||||||||||
| 2310 | - | |||||||||||||||||||||||||||||||||||||
| 2311 | You can then use the QSettings object to read and write settings | - | ||||||||||||||||||||||||||||||||||||
| 2312 | in the file. | - | ||||||||||||||||||||||||||||||||||||
| 2313 | - | |||||||||||||||||||||||||||||||||||||
| 2314 | On \macos and iOS, you can access property list \c .plist files by passing | - | ||||||||||||||||||||||||||||||||||||
| 2315 | QSettings::NativeFormat as second argument. For example: | - | ||||||||||||||||||||||||||||||||||||
| 2316 | - | |||||||||||||||||||||||||||||||||||||
| 2317 | \snippet code/src_corelib_io_qsettings.cpp 3 | - | ||||||||||||||||||||||||||||||||||||
| 2318 | - | |||||||||||||||||||||||||||||||||||||
| 2319 | \section2 Accessing the Windows Registry Directly | - | ||||||||||||||||||||||||||||||||||||
| 2320 | - | |||||||||||||||||||||||||||||||||||||
| 2321 | On Windows, QSettings lets you access settings that have been | - | ||||||||||||||||||||||||||||||||||||
| 2322 | written with QSettings (or settings in a supported format, e.g., string | - | ||||||||||||||||||||||||||||||||||||
| 2323 | data) in the system registry. This is done by constructing a QSettings | - | ||||||||||||||||||||||||||||||||||||
| 2324 | object with a path in the registry and QSettings::NativeFormat. | - | ||||||||||||||||||||||||||||||||||||
| 2325 | - | |||||||||||||||||||||||||||||||||||||
| 2326 | For example: | - | ||||||||||||||||||||||||||||||||||||
| 2327 | - | |||||||||||||||||||||||||||||||||||||
| 2328 | \snippet code/src_corelib_io_qsettings.cpp 4 | - | ||||||||||||||||||||||||||||||||||||
| 2329 | - | |||||||||||||||||||||||||||||||||||||
| 2330 | All the registry entries that appear under the specified path can | - | ||||||||||||||||||||||||||||||||||||
| 2331 | be read or written through the QSettings object as usual (using | - | ||||||||||||||||||||||||||||||||||||
| 2332 | forward slashes instead of backslashes). For example: | - | ||||||||||||||||||||||||||||||||||||
| 2333 | - | |||||||||||||||||||||||||||||||||||||
| 2334 | \snippet code/src_corelib_io_qsettings.cpp 5 | - | ||||||||||||||||||||||||||||||||||||
| 2335 | - | |||||||||||||||||||||||||||||||||||||
| 2336 | Note that the backslash character is, as mentioned, used by | - | ||||||||||||||||||||||||||||||||||||
| 2337 | QSettings to separate subkeys. As a result, you cannot read or | - | ||||||||||||||||||||||||||||||||||||
| 2338 | write windows registry entries that contain slashes or | - | ||||||||||||||||||||||||||||||||||||
| 2339 | backslashes; you should use a native windows API if you need to do | - | ||||||||||||||||||||||||||||||||||||
| 2340 | so. | - | ||||||||||||||||||||||||||||||||||||
| 2341 | - | |||||||||||||||||||||||||||||||||||||
| 2342 | \section2 Accessing Common Registry Settings on Windows | - | ||||||||||||||||||||||||||||||||||||
| 2343 | - | |||||||||||||||||||||||||||||||||||||
| 2344 | On Windows, it is possible for a key to have both a value and subkeys. | - | ||||||||||||||||||||||||||||||||||||
| 2345 | Its default value is accessed by using "Default" or "." in | - | ||||||||||||||||||||||||||||||||||||
| 2346 | place of a subkey: | - | ||||||||||||||||||||||||||||||||||||
| 2347 | - | |||||||||||||||||||||||||||||||||||||
| 2348 | \snippet code/src_corelib_io_qsettings.cpp 6 | - | ||||||||||||||||||||||||||||||||||||
| 2349 | - | |||||||||||||||||||||||||||||||||||||
| 2350 | On other platforms than Windows, "Default" and "." would be | - | ||||||||||||||||||||||||||||||||||||
| 2351 | treated as regular subkeys. | - | ||||||||||||||||||||||||||||||||||||
| 2352 | - | |||||||||||||||||||||||||||||||||||||
| 2353 | \section2 Platform Limitations | - | ||||||||||||||||||||||||||||||||||||
| 2354 | - | |||||||||||||||||||||||||||||||||||||
| 2355 | While QSettings attempts to smooth over the differences between | - | ||||||||||||||||||||||||||||||||||||
| 2356 | the different supported platforms, there are still a few | - | ||||||||||||||||||||||||||||||||||||
| 2357 | differences that you should be aware of when porting your | - | ||||||||||||||||||||||||||||||||||||
| 2358 | application: | - | ||||||||||||||||||||||||||||||||||||
| 2359 | - | |||||||||||||||||||||||||||||||||||||
| 2360 | \list | - | ||||||||||||||||||||||||||||||||||||
| 2361 | \li The Windows system registry has the following limitations: A | - | ||||||||||||||||||||||||||||||||||||
| 2362 | subkey may not exceed 255 characters, an entry's value may | - | ||||||||||||||||||||||||||||||||||||
| 2363 | not exceed 16,383 characters, and all the values of a key may | - | ||||||||||||||||||||||||||||||||||||
| 2364 | not exceed 65,535 characters. One way to work around these | - | ||||||||||||||||||||||||||||||||||||
| 2365 | limitations is to store the settings using the IniFormat | - | ||||||||||||||||||||||||||||||||||||
| 2366 | instead of the NativeFormat. | - | ||||||||||||||||||||||||||||||||||||
| 2367 | - | |||||||||||||||||||||||||||||||||||||
| 2368 | \li On \macos and iOS, allKeys() will return some extra keys for global | - | ||||||||||||||||||||||||||||||||||||
| 2369 | settings that apply to all applications. These keys can be | - | ||||||||||||||||||||||||||||||||||||
| 2370 | read using value() but cannot be changed, only shadowed. | - | ||||||||||||||||||||||||||||||||||||
| 2371 | Calling setFallbacksEnabled(false) will hide these global | - | ||||||||||||||||||||||||||||||||||||
| 2372 | settings. | - | ||||||||||||||||||||||||||||||||||||
| 2373 | - | |||||||||||||||||||||||||||||||||||||
| 2374 | \li On \macos and iOS, the CFPreferences API used by QSettings expects | - | ||||||||||||||||||||||||||||||||||||
| 2375 | Internet domain names rather than organization names. To | - | ||||||||||||||||||||||||||||||||||||
| 2376 | provide a uniform API, QSettings derives a fake domain name | - | ||||||||||||||||||||||||||||||||||||
| 2377 | from the organization name (unless the organization name | - | ||||||||||||||||||||||||||||||||||||
| 2378 | already is a domain name, e.g. OpenOffice.org). The algorithm | - | ||||||||||||||||||||||||||||||||||||
| 2379 | appends ".com" to the company name and replaces spaces and | - | ||||||||||||||||||||||||||||||||||||
| 2380 | other illegal characters with hyphens. If you want to specify | - | ||||||||||||||||||||||||||||||||||||
| 2381 | a different domain name, call | - | ||||||||||||||||||||||||||||||||||||
| 2382 | QCoreApplication::setOrganizationDomain(), | - | ||||||||||||||||||||||||||||||||||||
| 2383 | QCoreApplication::setOrganizationName(), and | - | ||||||||||||||||||||||||||||||||||||
| 2384 | QCoreApplication::setApplicationName() in your \c main() | - | ||||||||||||||||||||||||||||||||||||
| 2385 | function and then use the default QSettings constructor. | - | ||||||||||||||||||||||||||||||||||||
| 2386 | Another solution is to use preprocessor directives, for | - | ||||||||||||||||||||||||||||||||||||
| 2387 | example: | - | ||||||||||||||||||||||||||||||||||||
| 2388 | - | |||||||||||||||||||||||||||||||||||||
| 2389 | \snippet code/src_corelib_io_qsettings.cpp 7 | - | ||||||||||||||||||||||||||||||||||||
| 2390 | - | |||||||||||||||||||||||||||||||||||||
| 2391 | \li On \macos, permissions to access settings not belonging to the | - | ||||||||||||||||||||||||||||||||||||
| 2392 | current user (i.e. SystemScope) have changed with 10.7 (Lion). Prior to | - | ||||||||||||||||||||||||||||||||||||
| 2393 | that version, users having admin rights could access these. For 10.7 and | - | ||||||||||||||||||||||||||||||||||||
| 2394 | 10.8 (Mountain Lion), only root can. However, 10.9 (Mavericks) changes | - | ||||||||||||||||||||||||||||||||||||
| 2395 | that rule again but only for the native format (plist files). | - | ||||||||||||||||||||||||||||||||||||
| 2396 | - | |||||||||||||||||||||||||||||||||||||
| 2397 | \li On the BlackBerry platform, applications run in a sandbox. They are not | - | ||||||||||||||||||||||||||||||||||||
| 2398 | allowed to read or write outside of this sandbox. This involves the | - | ||||||||||||||||||||||||||||||||||||
| 2399 | following limitations: | - | ||||||||||||||||||||||||||||||||||||
| 2400 | \list | - | ||||||||||||||||||||||||||||||||||||
| 2401 | \li As there is only a single scope the scope is simply ignored, | - | ||||||||||||||||||||||||||||||||||||
| 2402 | i.e. there is no difference between SystemScope and UserScope. | - | ||||||||||||||||||||||||||||||||||||
| 2403 | \li The \l{Fallback Mechanism} is not applied, i.e. only a single | - | ||||||||||||||||||||||||||||||||||||
| 2404 | location is considered. | - | ||||||||||||||||||||||||||||||||||||
| 2405 | \li It is advised against setting and using custom file paths. | - | ||||||||||||||||||||||||||||||||||||
| 2406 | \endlist | - | ||||||||||||||||||||||||||||||||||||
| 2407 | - | |||||||||||||||||||||||||||||||||||||
| 2408 | \endlist | - | ||||||||||||||||||||||||||||||||||||
| 2409 | - | |||||||||||||||||||||||||||||||||||||
| 2410 | \sa QVariant, QSessionManager, {Settings Editor Example}, {Application Example} | - | ||||||||||||||||||||||||||||||||||||
| 2411 | */ | - | ||||||||||||||||||||||||||||||||||||
| 2412 | - | |||||||||||||||||||||||||||||||||||||
| 2413 | /*! \enum QSettings::Status | - | ||||||||||||||||||||||||||||||||||||
| 2414 | - | |||||||||||||||||||||||||||||||||||||
| 2415 | The following status values are possible: | - | ||||||||||||||||||||||||||||||||||||
| 2416 | - | |||||||||||||||||||||||||||||||||||||
| 2417 | \value NoError No error occurred. | - | ||||||||||||||||||||||||||||||||||||
| 2418 | \value AccessError An access error occurred (e.g. trying to write to a read-only file). | - | ||||||||||||||||||||||||||||||||||||
| 2419 | \value FormatError A format error occurred (e.g. loading a malformed INI file). | - | ||||||||||||||||||||||||||||||||||||
| 2420 | - | |||||||||||||||||||||||||||||||||||||
| 2421 | \sa status() | - | ||||||||||||||||||||||||||||||||||||
| 2422 | */ | - | ||||||||||||||||||||||||||||||||||||
| 2423 | - | |||||||||||||||||||||||||||||||||||||
| 2424 | /*! \enum QSettings::Format | - | ||||||||||||||||||||||||||||||||||||
| 2425 | - | |||||||||||||||||||||||||||||||||||||
| 2426 | This enum type specifies the storage format used by QSettings. | - | ||||||||||||||||||||||||||||||||||||
| 2427 | - | |||||||||||||||||||||||||||||||||||||
| 2428 | \value NativeFormat Store the settings using the most | - | ||||||||||||||||||||||||||||||||||||
| 2429 | appropriate storage format for the platform. | - | ||||||||||||||||||||||||||||||||||||
| 2430 | On Windows, this means the system registry; | - | ||||||||||||||||||||||||||||||||||||
| 2431 | on \macos and iOS, this means the CFPreferences | - | ||||||||||||||||||||||||||||||||||||
| 2432 | API; on Unix, this means textual | - | ||||||||||||||||||||||||||||||||||||
| 2433 | configuration files in INI format. | - | ||||||||||||||||||||||||||||||||||||
| 2434 | \value IniFormat Store the settings in INI files. | - | ||||||||||||||||||||||||||||||||||||
| 2435 | \value InvalidFormat Special value returned by registerFormat(). | - | ||||||||||||||||||||||||||||||||||||
| 2436 | \omitvalue CustomFormat1 | - | ||||||||||||||||||||||||||||||||||||
| 2437 | \omitvalue CustomFormat2 | - | ||||||||||||||||||||||||||||||||||||
| 2438 | \omitvalue CustomFormat3 | - | ||||||||||||||||||||||||||||||||||||
| 2439 | \omitvalue CustomFormat4 | - | ||||||||||||||||||||||||||||||||||||
| 2440 | \omitvalue CustomFormat5 | - | ||||||||||||||||||||||||||||||||||||
| 2441 | \omitvalue CustomFormat6 | - | ||||||||||||||||||||||||||||||||||||
| 2442 | \omitvalue CustomFormat7 | - | ||||||||||||||||||||||||||||||||||||
| 2443 | \omitvalue CustomFormat8 | - | ||||||||||||||||||||||||||||||||||||
| 2444 | \omitvalue CustomFormat9 | - | ||||||||||||||||||||||||||||||||||||
| 2445 | \omitvalue CustomFormat10 | - | ||||||||||||||||||||||||||||||||||||
| 2446 | \omitvalue CustomFormat11 | - | ||||||||||||||||||||||||||||||||||||
| 2447 | \omitvalue CustomFormat12 | - | ||||||||||||||||||||||||||||||||||||
| 2448 | \omitvalue CustomFormat13 | - | ||||||||||||||||||||||||||||||||||||
| 2449 | \omitvalue CustomFormat14 | - | ||||||||||||||||||||||||||||||||||||
| 2450 | \omitvalue CustomFormat15 | - | ||||||||||||||||||||||||||||||||||||
| 2451 | \omitvalue CustomFormat16 | - | ||||||||||||||||||||||||||||||||||||
| 2452 | - | |||||||||||||||||||||||||||||||||||||
| 2453 | On Unix, NativeFormat and IniFormat mean the same thing, except | - | ||||||||||||||||||||||||||||||||||||
| 2454 | that the file extension is different (\c .conf for NativeFormat, | - | ||||||||||||||||||||||||||||||||||||
| 2455 | \c .ini for IniFormat). | - | ||||||||||||||||||||||||||||||||||||
| 2456 | - | |||||||||||||||||||||||||||||||||||||
| 2457 | The INI file format is a Windows file format that Qt supports on | - | ||||||||||||||||||||||||||||||||||||
| 2458 | all platforms. In the absence of an INI standard, we try to | - | ||||||||||||||||||||||||||||||||||||
| 2459 | follow what Microsoft does, with the following exceptions: | - | ||||||||||||||||||||||||||||||||||||
| 2460 | - | |||||||||||||||||||||||||||||||||||||
| 2461 | \list | - | ||||||||||||||||||||||||||||||||||||
| 2462 | \li If you store types that QVariant can't convert to QString | - | ||||||||||||||||||||||||||||||||||||
| 2463 | (e.g., QPoint, QRect, and QSize), Qt uses an \c{@}-based | - | ||||||||||||||||||||||||||||||||||||
| 2464 | syntax to encode the type. For example: | - | ||||||||||||||||||||||||||||||||||||
| 2465 | - | |||||||||||||||||||||||||||||||||||||
| 2466 | \snippet code/src_corelib_io_qsettings.cpp 8 | - | ||||||||||||||||||||||||||||||||||||
| 2467 | - | |||||||||||||||||||||||||||||||||||||
| 2468 | To minimize compatibility issues, any \c @ that doesn't | - | ||||||||||||||||||||||||||||||||||||
| 2469 | appear at the first position in the value or that isn't | - | ||||||||||||||||||||||||||||||||||||
| 2470 | followed by a Qt type (\c Point, \c Rect, \c Size, etc.) is | - | ||||||||||||||||||||||||||||||||||||
| 2471 | treated as a normal character. | - | ||||||||||||||||||||||||||||||||||||
| 2472 | - | |||||||||||||||||||||||||||||||||||||
| 2473 | \li Although backslash is a special character in INI files, most | - | ||||||||||||||||||||||||||||||||||||
| 2474 | Windows applications don't escape backslashes (\c{\}) in file | - | ||||||||||||||||||||||||||||||||||||
| 2475 | paths: | - | ||||||||||||||||||||||||||||||||||||
| 2476 | - | |||||||||||||||||||||||||||||||||||||
| 2477 | \snippet code/src_corelib_io_qsettings.cpp 9 | - | ||||||||||||||||||||||||||||||||||||
| 2478 | - | |||||||||||||||||||||||||||||||||||||
| 2479 | QSettings always treats backslash as a special character and | - | ||||||||||||||||||||||||||||||||||||
| 2480 | provides no API for reading or writing such entries. | - | ||||||||||||||||||||||||||||||||||||
| 2481 | - | |||||||||||||||||||||||||||||||||||||
| 2482 | \li The INI file format has severe restrictions on the syntax of | - | ||||||||||||||||||||||||||||||||||||
| 2483 | a key. Qt works around this by using \c % as an escape | - | ||||||||||||||||||||||||||||||||||||
| 2484 | character in keys. In addition, if you save a top-level | - | ||||||||||||||||||||||||||||||||||||
| 2485 | setting (a key with no slashes in it, e.g., "someKey"), it | - | ||||||||||||||||||||||||||||||||||||
| 2486 | will appear in the INI file's "General" section. To avoid | - | ||||||||||||||||||||||||||||||||||||
| 2487 | overwriting other keys, if you save something using a key | - | ||||||||||||||||||||||||||||||||||||
| 2488 | such as "General/someKey", the key will be located in the | - | ||||||||||||||||||||||||||||||||||||
| 2489 | "%General" section, \e not in the "General" section. | - | ||||||||||||||||||||||||||||||||||||
| 2490 | - | |||||||||||||||||||||||||||||||||||||
| 2491 | \li Following the philosophy that we should be liberal in what | - | ||||||||||||||||||||||||||||||||||||
| 2492 | we accept and conservative in what we generate, QSettings | - | ||||||||||||||||||||||||||||||||||||
| 2493 | will accept Latin-1 encoded INI files, but generate pure | - | ||||||||||||||||||||||||||||||||||||
| 2494 | ASCII files, where non-ASCII values are encoded using standard | - | ||||||||||||||||||||||||||||||||||||
| 2495 | INI escape sequences. To make the INI files more readable (but | - | ||||||||||||||||||||||||||||||||||||
| 2496 | potentially less compatible), call setIniCodec(). | - | ||||||||||||||||||||||||||||||||||||
| 2497 | \endlist | - | ||||||||||||||||||||||||||||||||||||
| 2498 | - | |||||||||||||||||||||||||||||||||||||
| 2499 | \sa registerFormat(), setPath() | - | ||||||||||||||||||||||||||||||||||||
| 2500 | */ | - | ||||||||||||||||||||||||||||||||||||
| 2501 | - | |||||||||||||||||||||||||||||||||||||
| 2502 | /*! \enum QSettings::Scope | - | ||||||||||||||||||||||||||||||||||||
| 2503 | - | |||||||||||||||||||||||||||||||||||||
| 2504 | This enum specifies whether settings are user-specific or shared | - | ||||||||||||||||||||||||||||||||||||
| 2505 | by all users of the same system. | - | ||||||||||||||||||||||||||||||||||||
| 2506 | - | |||||||||||||||||||||||||||||||||||||
| 2507 | \value UserScope Store settings in a location specific to the | - | ||||||||||||||||||||||||||||||||||||
| 2508 | current user (e.g., in the user's home | - | ||||||||||||||||||||||||||||||||||||
| 2509 | directory). | - | ||||||||||||||||||||||||||||||||||||
| 2510 | \value SystemScope Store settings in a global location, so that | - | ||||||||||||||||||||||||||||||||||||
| 2511 | all users on the same machine access the same | - | ||||||||||||||||||||||||||||||||||||
| 2512 | set of settings. | - | ||||||||||||||||||||||||||||||||||||
| 2513 | - | |||||||||||||||||||||||||||||||||||||
| 2514 | \sa setPath() | - | ||||||||||||||||||||||||||||||||||||
| 2515 | */ | - | ||||||||||||||||||||||||||||||||||||
| 2516 | - | |||||||||||||||||||||||||||||||||||||
| 2517 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||||||||||||||||||||
| 2518 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 2519 | Constructs a QSettings object for accessing settings of the | - | ||||||||||||||||||||||||||||||||||||
| 2520 | application called \a application from the organization called \a | - | ||||||||||||||||||||||||||||||||||||
| 2521 | organization, and with parent \a parent. | - | ||||||||||||||||||||||||||||||||||||
| 2522 | - | |||||||||||||||||||||||||||||||||||||
| 2523 | Example: | - | ||||||||||||||||||||||||||||||||||||
| 2524 | \snippet code/src_corelib_io_qsettings.cpp 10 | - | ||||||||||||||||||||||||||||||||||||
| 2525 | - | |||||||||||||||||||||||||||||||||||||
| 2526 | The scope is set to QSettings::UserScope, and the format is | - | ||||||||||||||||||||||||||||||||||||
| 2527 | set to QSettings::NativeFormat (i.e. calling setDefaultFormat() | - | ||||||||||||||||||||||||||||||||||||
| 2528 | before calling this constructor has no effect). | - | ||||||||||||||||||||||||||||||||||||
| 2529 | - | |||||||||||||||||||||||||||||||||||||
| 2530 | \sa setDefaultFormat(), {Fallback Mechanism} | - | ||||||||||||||||||||||||||||||||||||
| 2531 | */ | - | ||||||||||||||||||||||||||||||||||||
| 2532 | QSettings::QSettings(const QString &organization, const QString &application, QObject *parent) | - | ||||||||||||||||||||||||||||||||||||
| 2533 | : QObject(*QSettingsPrivate::create(NativeFormat, UserScope, organization, application), | - | ||||||||||||||||||||||||||||||||||||
| 2534 | parent) | - | ||||||||||||||||||||||||||||||||||||
| 2535 | { | - | ||||||||||||||||||||||||||||||||||||
| 2536 | } executed 50 times by 2 tests: end of blockExecuted by:
| 50 | ||||||||||||||||||||||||||||||||||||
| 2537 | - | |||||||||||||||||||||||||||||||||||||
| 2538 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 2539 | Constructs a QSettings object for accessing settings of the | - | ||||||||||||||||||||||||||||||||||||
| 2540 | application called \a application from the organization called \a | - | ||||||||||||||||||||||||||||||||||||
| 2541 | organization, and with parent \a parent. | - | ||||||||||||||||||||||||||||||||||||
| 2542 | - | |||||||||||||||||||||||||||||||||||||
| 2543 | If \a scope is QSettings::UserScope, the QSettings object searches | - | ||||||||||||||||||||||||||||||||||||
| 2544 | user-specific settings first, before it searches system-wide | - | ||||||||||||||||||||||||||||||||||||
| 2545 | settings as a fallback. If \a scope is QSettings::SystemScope, the | - | ||||||||||||||||||||||||||||||||||||
| 2546 | QSettings object ignores user-specific settings and provides | - | ||||||||||||||||||||||||||||||||||||
| 2547 | access to system-wide settings. | - | ||||||||||||||||||||||||||||||||||||
| 2548 | - | |||||||||||||||||||||||||||||||||||||
| 2549 | The storage format is set to QSettings::NativeFormat (i.e. calling | - | ||||||||||||||||||||||||||||||||||||
| 2550 | setDefaultFormat() before calling this constructor has no effect). | - | ||||||||||||||||||||||||||||||||||||
| 2551 | - | |||||||||||||||||||||||||||||||||||||
| 2552 | If no application name is given, the QSettings object will | - | ||||||||||||||||||||||||||||||||||||
| 2553 | only access the organization-wide \l{Fallback Mechanism}{locations}. | - | ||||||||||||||||||||||||||||||||||||
| 2554 | - | |||||||||||||||||||||||||||||||||||||
| 2555 | \sa setDefaultFormat() | - | ||||||||||||||||||||||||||||||||||||
| 2556 | */ | - | ||||||||||||||||||||||||||||||||||||
| 2557 | QSettings::QSettings(Scope scope, const QString &organization, const QString &application, | - | ||||||||||||||||||||||||||||||||||||
| 2558 | QObject *parent) | - | ||||||||||||||||||||||||||||||||||||
| 2559 | : QObject(*QSettingsPrivate::create(NativeFormat, scope, organization, application), parent) | - | ||||||||||||||||||||||||||||||||||||
| 2560 | { | - | ||||||||||||||||||||||||||||||||||||
| 2561 | } executed 1034 times by 6 tests: end of blockExecuted by:
| 1034 | ||||||||||||||||||||||||||||||||||||
| 2562 | - | |||||||||||||||||||||||||||||||||||||
| 2563 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 2564 | Constructs a QSettings object for accessing settings of the | - | ||||||||||||||||||||||||||||||||||||
| 2565 | application called \a application from the organization called | - | ||||||||||||||||||||||||||||||||||||
| 2566 | \a organization, and with parent \a parent. | - | ||||||||||||||||||||||||||||||||||||
| 2567 | - | |||||||||||||||||||||||||||||||||||||
| 2568 | If \a scope is QSettings::UserScope, the QSettings object searches | - | ||||||||||||||||||||||||||||||||||||
| 2569 | user-specific settings first, before it searches system-wide | - | ||||||||||||||||||||||||||||||||||||
| 2570 | settings as a fallback. If \a scope is | - | ||||||||||||||||||||||||||||||||||||
| 2571 | QSettings::SystemScope, the QSettings object ignores user-specific | - | ||||||||||||||||||||||||||||||||||||
| 2572 | settings and provides access to system-wide settings. | - | ||||||||||||||||||||||||||||||||||||
| 2573 | - | |||||||||||||||||||||||||||||||||||||
| 2574 | If \a format is QSettings::NativeFormat, the native API is used for | - | ||||||||||||||||||||||||||||||||||||
| 2575 | storing settings. If \a format is QSettings::IniFormat, the INI format | - | ||||||||||||||||||||||||||||||||||||
| 2576 | is used. | - | ||||||||||||||||||||||||||||||||||||
| 2577 | - | |||||||||||||||||||||||||||||||||||||
| 2578 | If no application name is given, the QSettings object will | - | ||||||||||||||||||||||||||||||||||||
| 2579 | only access the organization-wide \l{Fallback Mechanism}{locations}. | - | ||||||||||||||||||||||||||||||||||||
| 2580 | */ | - | ||||||||||||||||||||||||||||||||||||
| 2581 | QSettings::QSettings(Format format, Scope scope, const QString &organization, | - | ||||||||||||||||||||||||||||||||||||
| 2582 | const QString &application, QObject *parent) | - | ||||||||||||||||||||||||||||||||||||
| 2583 | : QObject(*QSettingsPrivate::create(format, scope, organization, application), parent) | - | ||||||||||||||||||||||||||||||||||||
| 2584 | { | - | ||||||||||||||||||||||||||||||||||||
| 2585 | } executed 333 times by 1 test: end of blockExecuted by:
| 333 | ||||||||||||||||||||||||||||||||||||
| 2586 | - | |||||||||||||||||||||||||||||||||||||
| 2587 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 2588 | Constructs a QSettings object for accessing the settings | - | ||||||||||||||||||||||||||||||||||||
| 2589 | stored in the file called \a fileName, with parent \a parent. If | - | ||||||||||||||||||||||||||||||||||||
| 2590 | the file doesn't already exist, it is created. | - | ||||||||||||||||||||||||||||||||||||
| 2591 | - | |||||||||||||||||||||||||||||||||||||
| 2592 | If \a format is QSettings::NativeFormat, the meaning of \a | - | ||||||||||||||||||||||||||||||||||||
| 2593 | fileName depends on the platform. On Unix, \a fileName is the | - | ||||||||||||||||||||||||||||||||||||
| 2594 | name of an INI file. On \macos and iOS, \a fileName is the name of a | - | ||||||||||||||||||||||||||||||||||||
| 2595 | \c .plist file. On Windows, \a fileName is a path in the system | - | ||||||||||||||||||||||||||||||||||||
| 2596 | registry. | - | ||||||||||||||||||||||||||||||||||||
| 2597 | - | |||||||||||||||||||||||||||||||||||||
| 2598 | If \a format is QSettings::IniFormat, \a fileName is the name of an INI | - | ||||||||||||||||||||||||||||||||||||
| 2599 | file. | - | ||||||||||||||||||||||||||||||||||||
| 2600 | - | |||||||||||||||||||||||||||||||||||||
| 2601 | \warning This function is provided for convenience. It works well for | - | ||||||||||||||||||||||||||||||||||||
| 2602 | accessing INI or \c .plist files generated by Qt, but might fail on some | - | ||||||||||||||||||||||||||||||||||||
| 2603 | syntaxes found in such files originated by other programs. In particular, | - | ||||||||||||||||||||||||||||||||||||
| 2604 | be aware of the following limitations: | - | ||||||||||||||||||||||||||||||||||||
| 2605 | - | |||||||||||||||||||||||||||||||||||||
| 2606 | \list | - | ||||||||||||||||||||||||||||||||||||
| 2607 | \li QSettings provides no way of reading INI "path" entries, i.e., entries | - | ||||||||||||||||||||||||||||||||||||
| 2608 | with unescaped slash characters. (This is because these entries are | - | ||||||||||||||||||||||||||||||||||||
| 2609 | ambiguous and cannot be resolved automatically.) | - | ||||||||||||||||||||||||||||||||||||
| 2610 | \li In INI files, QSettings uses the \c @ character as a metacharacter in some | - | ||||||||||||||||||||||||||||||||||||
| 2611 | contexts, to encode Qt-specific data types (e.g., \c @Rect), and might | - | ||||||||||||||||||||||||||||||||||||
| 2612 | therefore misinterpret it when it occurs in pure INI files. | - | ||||||||||||||||||||||||||||||||||||
| 2613 | \endlist | - | ||||||||||||||||||||||||||||||||||||
| 2614 | - | |||||||||||||||||||||||||||||||||||||
| 2615 | \sa fileName() | - | ||||||||||||||||||||||||||||||||||||
| 2616 | */ | - | ||||||||||||||||||||||||||||||||||||
| 2617 | QSettings::QSettings(const QString &fileName, Format format, QObject *parent) | - | ||||||||||||||||||||||||||||||||||||
| 2618 | : QObject(*QSettingsPrivate::create(fileName, format), parent) | - | ||||||||||||||||||||||||||||||||||||
| 2619 | { | - | ||||||||||||||||||||||||||||||||||||
| 2620 | } executed 119 times by 28 tests: end of blockExecuted by:
| 119 | ||||||||||||||||||||||||||||||||||||
| 2621 | - | |||||||||||||||||||||||||||||||||||||
| 2622 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 2623 | Constructs a QSettings object for accessing settings of the | - | ||||||||||||||||||||||||||||||||||||
| 2624 | application and organization set previously with a call to | - | ||||||||||||||||||||||||||||||||||||
| 2625 | QCoreApplication::setOrganizationName(), | - | ||||||||||||||||||||||||||||||||||||
| 2626 | QCoreApplication::setOrganizationDomain(), and | - | ||||||||||||||||||||||||||||||||||||
| 2627 | QCoreApplication::setApplicationName(). | - | ||||||||||||||||||||||||||||||||||||
| 2628 | - | |||||||||||||||||||||||||||||||||||||
| 2629 | The scope is QSettings::UserScope and the format is | - | ||||||||||||||||||||||||||||||||||||
| 2630 | defaultFormat() (QSettings::NativeFormat by default). | - | ||||||||||||||||||||||||||||||||||||
| 2631 | Use setDefaultFormat() before calling this constructor | - | ||||||||||||||||||||||||||||||||||||
| 2632 | to change the default format used by this constructor. | - | ||||||||||||||||||||||||||||||||||||
| 2633 | - | |||||||||||||||||||||||||||||||||||||
| 2634 | The code | - | ||||||||||||||||||||||||||||||||||||
| 2635 | - | |||||||||||||||||||||||||||||||||||||
| 2636 | \snippet code/src_corelib_io_qsettings.cpp 11 | - | ||||||||||||||||||||||||||||||||||||
| 2637 | - | |||||||||||||||||||||||||||||||||||||
| 2638 | is equivalent to | - | ||||||||||||||||||||||||||||||||||||
| 2639 | - | |||||||||||||||||||||||||||||||||||||
| 2640 | \snippet code/src_corelib_io_qsettings.cpp 12 | - | ||||||||||||||||||||||||||||||||||||
| 2641 | - | |||||||||||||||||||||||||||||||||||||
| 2642 | If QCoreApplication::setOrganizationName() and | - | ||||||||||||||||||||||||||||||||||||
| 2643 | QCoreApplication::setApplicationName() has not been previously | - | ||||||||||||||||||||||||||||||||||||
| 2644 | called, the QSettings object will not be able to read or write | - | ||||||||||||||||||||||||||||||||||||
| 2645 | any settings, and status() will return AccessError. | - | ||||||||||||||||||||||||||||||||||||
| 2646 | - | |||||||||||||||||||||||||||||||||||||
| 2647 | On \macos and iOS, if both a name and an Internet domain are specified | - | ||||||||||||||||||||||||||||||||||||
| 2648 | for the organization, the domain is preferred over the name. On | - | ||||||||||||||||||||||||||||||||||||
| 2649 | other platforms, the name is preferred over the domain. | - | ||||||||||||||||||||||||||||||||||||
| 2650 | - | |||||||||||||||||||||||||||||||||||||
| 2651 | \sa QCoreApplication::setOrganizationName(), | - | ||||||||||||||||||||||||||||||||||||
| 2652 | QCoreApplication::setOrganizationDomain(), | - | ||||||||||||||||||||||||||||||||||||
| 2653 | QCoreApplication::setApplicationName(), | - | ||||||||||||||||||||||||||||||||||||
| 2654 | setDefaultFormat() | - | ||||||||||||||||||||||||||||||||||||
| 2655 | */ | - | ||||||||||||||||||||||||||||||||||||
| 2656 | QSettings::QSettings(QObject *parent) | - | ||||||||||||||||||||||||||||||||||||
| 2657 | : QObject(*QSettingsPrivate::create(globalDefaultFormat, UserScope, | - | ||||||||||||||||||||||||||||||||||||
| 2658 | #ifdef Q_OS_MAC | - | ||||||||||||||||||||||||||||||||||||
| 2659 | QCoreApplication::organizationDomain().isEmpty() | - | ||||||||||||||||||||||||||||||||||||
| 2660 | ? QCoreApplication::organizationName() | - | ||||||||||||||||||||||||||||||||||||
| 2661 | : QCoreApplication::organizationDomain() | - | ||||||||||||||||||||||||||||||||||||
| 2662 | #else | - | ||||||||||||||||||||||||||||||||||||
| 2663 | QCoreApplication::organizationName().isEmpty() | - | ||||||||||||||||||||||||||||||||||||
| 2664 | ? QCoreApplication::organizationDomain() | - | ||||||||||||||||||||||||||||||||||||
| 2665 | : QCoreApplication::organizationName() | - | ||||||||||||||||||||||||||||||||||||
| 2666 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 2667 | , QCoreApplication::applicationName()), | - | ||||||||||||||||||||||||||||||||||||
| 2668 | parent) | - | ||||||||||||||||||||||||||||||||||||
| 2669 | { | - | ||||||||||||||||||||||||||||||||||||
| 2670 | } executed 5 times by 1 test: end of blockExecuted by:
| 5 | ||||||||||||||||||||||||||||||||||||
| 2671 | - | |||||||||||||||||||||||||||||||||||||
| 2672 | #else | - | ||||||||||||||||||||||||||||||||||||
| 2673 | QSettings::QSettings(const QString &organization, const QString &application) | - | ||||||||||||||||||||||||||||||||||||
| 2674 | : d_ptr(QSettingsPrivate::create(globalDefaultFormat, QSettings::UserScope, organization, application)) | - | ||||||||||||||||||||||||||||||||||||
| 2675 | { | - | ||||||||||||||||||||||||||||||||||||
| 2676 | d_ptr->q_ptr = this; | - | ||||||||||||||||||||||||||||||||||||
| 2677 | } | - | ||||||||||||||||||||||||||||||||||||
| 2678 | - | |||||||||||||||||||||||||||||||||||||
| 2679 | QSettings::QSettings(Scope scope, const QString &organization, const QString &application) | - | ||||||||||||||||||||||||||||||||||||
| 2680 | : d_ptr(QSettingsPrivate::create(globalDefaultFormat, scope, organization, application)) | - | ||||||||||||||||||||||||||||||||||||
| 2681 | { | - | ||||||||||||||||||||||||||||||||||||
| 2682 | d_ptr->q_ptr = this; | - | ||||||||||||||||||||||||||||||||||||
| 2683 | } | - | ||||||||||||||||||||||||||||||||||||
| 2684 | - | |||||||||||||||||||||||||||||||||||||
| 2685 | QSettings::QSettings(Format format, Scope scope, const QString &organization, | - | ||||||||||||||||||||||||||||||||||||
| 2686 | const QString &application) | - | ||||||||||||||||||||||||||||||||||||
| 2687 | : d_ptr(QSettingsPrivate::create(format, scope, organization, application)) | - | ||||||||||||||||||||||||||||||||||||
| 2688 | { | - | ||||||||||||||||||||||||||||||||||||
| 2689 | d_ptr->q_ptr = this; | - | ||||||||||||||||||||||||||||||||||||
| 2690 | } | - | ||||||||||||||||||||||||||||||||||||
| 2691 | - | |||||||||||||||||||||||||||||||||||||
| 2692 | QSettings::QSettings(const QString &fileName, Format format) | - | ||||||||||||||||||||||||||||||||||||
| 2693 | : d_ptr(QSettingsPrivate::create(fileName, format)) | - | ||||||||||||||||||||||||||||||||||||
| 2694 | { | - | ||||||||||||||||||||||||||||||||||||
| 2695 | d_ptr->q_ptr = this; | - | ||||||||||||||||||||||||||||||||||||
| 2696 | } | - | ||||||||||||||||||||||||||||||||||||
| 2697 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 2698 | - | |||||||||||||||||||||||||||||||||||||
| 2699 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 2700 | Destroys the QSettings object. | - | ||||||||||||||||||||||||||||||||||||
| 2701 | - | |||||||||||||||||||||||||||||||||||||
| 2702 | Any unsaved changes will eventually be written to permanent | - | ||||||||||||||||||||||||||||||||||||
| 2703 | storage. | - | ||||||||||||||||||||||||||||||||||||
| 2704 | - | |||||||||||||||||||||||||||||||||||||
| 2705 | \sa sync() | - | ||||||||||||||||||||||||||||||||||||
| 2706 | */ | - | ||||||||||||||||||||||||||||||||||||
| 2707 | QSettings::~QSettings() | - | ||||||||||||||||||||||||||||||||||||
| 2708 | { | - | ||||||||||||||||||||||||||||||||||||
| 2709 | Q_D(QSettings); | - | ||||||||||||||||||||||||||||||||||||
| 2710 | if (d->pendingChanges) {
| 561-980 | ||||||||||||||||||||||||||||||||||||
| 2711 | QT_TRY { | - | ||||||||||||||||||||||||||||||||||||
| 2712 | d->flush(); | - | ||||||||||||||||||||||||||||||||||||
| 2713 | } QT_CATCH(...) { executed 561 times by 6 tests: end of blockExecuted by:
| 561 | ||||||||||||||||||||||||||||||||||||
| 2714 | ; // ok. then don't flush but at least don't throw in the destructor | - | ||||||||||||||||||||||||||||||||||||
| 2715 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 2716 | } | - | ||||||||||||||||||||||||||||||||||||
| 2717 | } executed 1541 times by 30 tests: end of blockExecuted by:
| 1541 | ||||||||||||||||||||||||||||||||||||
| 2718 | - | |||||||||||||||||||||||||||||||||||||
| 2719 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 2720 | Removes all entries in the primary location associated to this | - | ||||||||||||||||||||||||||||||||||||
| 2721 | QSettings object. | - | ||||||||||||||||||||||||||||||||||||
| 2722 | - | |||||||||||||||||||||||||||||||||||||
| 2723 | Entries in fallback locations are not removed. | - | ||||||||||||||||||||||||||||||||||||
| 2724 | - | |||||||||||||||||||||||||||||||||||||
| 2725 | If you only want to remove the entries in the current group(), | - | ||||||||||||||||||||||||||||||||||||
| 2726 | use remove("") instead. | - | ||||||||||||||||||||||||||||||||||||
| 2727 | - | |||||||||||||||||||||||||||||||||||||
| 2728 | \sa remove(), setFallbacksEnabled() | - | ||||||||||||||||||||||||||||||||||||
| 2729 | */ | - | ||||||||||||||||||||||||||||||||||||
| 2730 | void QSettings::clear() | - | ||||||||||||||||||||||||||||||||||||
| 2731 | { | - | ||||||||||||||||||||||||||||||||||||
| 2732 | Q_D(QSettings); | - | ||||||||||||||||||||||||||||||||||||
| 2733 | d->clear(); | - | ||||||||||||||||||||||||||||||||||||
| 2734 | d->requestUpdate(); | - | ||||||||||||||||||||||||||||||||||||
| 2735 | } executed 15 times by 1 test: end of blockExecuted by:
| 15 | ||||||||||||||||||||||||||||||||||||
| 2736 | - | |||||||||||||||||||||||||||||||||||||
| 2737 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 2738 | Writes any unsaved changes to permanent storage, and reloads any | - | ||||||||||||||||||||||||||||||||||||
| 2739 | settings that have been changed in the meantime by another | - | ||||||||||||||||||||||||||||||||||||
| 2740 | application. | - | ||||||||||||||||||||||||||||||||||||
| 2741 | - | |||||||||||||||||||||||||||||||||||||
| 2742 | This function is called automatically from QSettings's destructor and | - | ||||||||||||||||||||||||||||||||||||
| 2743 | by the event loop at regular intervals, so you normally don't need to | - | ||||||||||||||||||||||||||||||||||||
| 2744 | call it yourself. | - | ||||||||||||||||||||||||||||||||||||
| 2745 | - | |||||||||||||||||||||||||||||||||||||
| 2746 | \sa status() | - | ||||||||||||||||||||||||||||||||||||
| 2747 | */ | - | ||||||||||||||||||||||||||||||||||||
| 2748 | void QSettings::sync() | - | ||||||||||||||||||||||||||||||||||||
| 2749 | { | - | ||||||||||||||||||||||||||||||||||||
| 2750 | Q_D(QSettings); | - | ||||||||||||||||||||||||||||||||||||
| 2751 | d->sync(); | - | ||||||||||||||||||||||||||||||||||||
| 2752 | } executed 64 times by 1 test: end of blockExecuted by:
| 64 | ||||||||||||||||||||||||||||||||||||
| 2753 | - | |||||||||||||||||||||||||||||||||||||
| 2754 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 2755 | Returns the path where settings written using this QSettings | - | ||||||||||||||||||||||||||||||||||||
| 2756 | object are stored. | - | ||||||||||||||||||||||||||||||||||||
| 2757 | - | |||||||||||||||||||||||||||||||||||||
| 2758 | On Windows, if the format is QSettings::NativeFormat, the return value | - | ||||||||||||||||||||||||||||||||||||
| 2759 | is a system registry path, not a file path. | - | ||||||||||||||||||||||||||||||||||||
| 2760 | - | |||||||||||||||||||||||||||||||||||||
| 2761 | \sa isWritable(), format() | - | ||||||||||||||||||||||||||||||||||||
| 2762 | */ | - | ||||||||||||||||||||||||||||||||||||
| 2763 | QString QSettings::fileName() const | - | ||||||||||||||||||||||||||||||||||||
| 2764 | { | - | ||||||||||||||||||||||||||||||||||||
| 2765 | Q_D(const QSettings); | - | ||||||||||||||||||||||||||||||||||||
| 2766 | return d->fileName(); executed 27 times by 1 test: return d->fileName();Executed by:
| 27 | ||||||||||||||||||||||||||||||||||||
| 2767 | } | - | ||||||||||||||||||||||||||||||||||||
| 2768 | - | |||||||||||||||||||||||||||||||||||||
| 2769 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 2770 | \since 4.4 | - | ||||||||||||||||||||||||||||||||||||
| 2771 | - | |||||||||||||||||||||||||||||||||||||
| 2772 | Returns the format used for storing the settings. | - | ||||||||||||||||||||||||||||||||||||
| 2773 | - | |||||||||||||||||||||||||||||||||||||
| 2774 | \sa defaultFormat(), fileName(), scope(), organizationName(), applicationName() | - | ||||||||||||||||||||||||||||||||||||
| 2775 | */ | - | ||||||||||||||||||||||||||||||||||||
| 2776 | QSettings::Format QSettings::format() const | - | ||||||||||||||||||||||||||||||||||||
| 2777 | { | - | ||||||||||||||||||||||||||||||||||||
| 2778 | Q_D(const QSettings); | - | ||||||||||||||||||||||||||||||||||||
| 2779 | return d->format; executed 30 times by 1 test: return d->format;Executed by:
| 30 | ||||||||||||||||||||||||||||||||||||
| 2780 | } | - | ||||||||||||||||||||||||||||||||||||
| 2781 | - | |||||||||||||||||||||||||||||||||||||
| 2782 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 2783 | \since 4.4 | - | ||||||||||||||||||||||||||||||||||||
| 2784 | - | |||||||||||||||||||||||||||||||||||||
| 2785 | Returns the scope used for storing the settings. | - | ||||||||||||||||||||||||||||||||||||
| 2786 | - | |||||||||||||||||||||||||||||||||||||
| 2787 | \sa format(), organizationName(), applicationName() | - | ||||||||||||||||||||||||||||||||||||
| 2788 | */ | - | ||||||||||||||||||||||||||||||||||||
| 2789 | QSettings::Scope QSettings::scope() const | - | ||||||||||||||||||||||||||||||||||||
| 2790 | { | - | ||||||||||||||||||||||||||||||||||||
| 2791 | Q_D(const QSettings); | - | ||||||||||||||||||||||||||||||||||||
| 2792 | return d->scope; executed 28 times by 1 test: return d->scope;Executed by:
| 28 | ||||||||||||||||||||||||||||||||||||
| 2793 | } | - | ||||||||||||||||||||||||||||||||||||
| 2794 | - | |||||||||||||||||||||||||||||||||||||
| 2795 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 2796 | \since 4.4 | - | ||||||||||||||||||||||||||||||||||||
| 2797 | - | |||||||||||||||||||||||||||||||||||||
| 2798 | Returns the organization name used for storing the settings. | - | ||||||||||||||||||||||||||||||||||||
| 2799 | - | |||||||||||||||||||||||||||||||||||||
| 2800 | \sa QCoreApplication::organizationName(), format(), scope(), applicationName() | - | ||||||||||||||||||||||||||||||||||||
| 2801 | */ | - | ||||||||||||||||||||||||||||||||||||
| 2802 | QString QSettings::organizationName() const | - | ||||||||||||||||||||||||||||||||||||
| 2803 | { | - | ||||||||||||||||||||||||||||||||||||
| 2804 | Q_D(const QSettings); | - | ||||||||||||||||||||||||||||||||||||
| 2805 | return d->organizationName; executed 32 times by 1 test: return d->organizationName;Executed by:
| 32 | ||||||||||||||||||||||||||||||||||||
| 2806 | } | - | ||||||||||||||||||||||||||||||||||||
| 2807 | - | |||||||||||||||||||||||||||||||||||||
| 2808 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 2809 | \since 4.4 | - | ||||||||||||||||||||||||||||||||||||
| 2810 | - | |||||||||||||||||||||||||||||||||||||
| 2811 | Returns the application name used for storing the settings. | - | ||||||||||||||||||||||||||||||||||||
| 2812 | - | |||||||||||||||||||||||||||||||||||||
| 2813 | \sa QCoreApplication::applicationName(), format(), scope(), organizationName() | - | ||||||||||||||||||||||||||||||||||||
| 2814 | */ | - | ||||||||||||||||||||||||||||||||||||
| 2815 | QString QSettings::applicationName() const | - | ||||||||||||||||||||||||||||||||||||
| 2816 | { | - | ||||||||||||||||||||||||||||||||||||
| 2817 | Q_D(const QSettings); | - | ||||||||||||||||||||||||||||||||||||
| 2818 | return d->applicationName; executed 24 times by 1 test: return d->applicationName;Executed by:
| 24 | ||||||||||||||||||||||||||||||||||||
| 2819 | } | - | ||||||||||||||||||||||||||||||||||||
| 2820 | - | |||||||||||||||||||||||||||||||||||||
| 2821 | #ifndef QT_NO_TEXTCODEC | - | ||||||||||||||||||||||||||||||||||||
| 2822 | - | |||||||||||||||||||||||||||||||||||||
| 2823 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 2824 | \since 4.5 | - | ||||||||||||||||||||||||||||||||||||
| 2825 | - | |||||||||||||||||||||||||||||||||||||
| 2826 | Sets the codec for accessing INI files (including \c .conf files on Unix) | - | ||||||||||||||||||||||||||||||||||||
| 2827 | to \a codec. The codec is used for decoding any data that is read from | - | ||||||||||||||||||||||||||||||||||||
| 2828 | the INI file, and for encoding any data that is written to the file. By | - | ||||||||||||||||||||||||||||||||||||
| 2829 | default, no codec is used, and non-ASCII characters are encoded using | - | ||||||||||||||||||||||||||||||||||||
| 2830 | standard INI escape sequences. | - | ||||||||||||||||||||||||||||||||||||
| 2831 | - | |||||||||||||||||||||||||||||||||||||
| 2832 | \warning The codec must be set immediately after creating the QSettings | - | ||||||||||||||||||||||||||||||||||||
| 2833 | object, before accessing any data. | - | ||||||||||||||||||||||||||||||||||||
| 2834 | - | |||||||||||||||||||||||||||||||||||||
| 2835 | \sa iniCodec() | - | ||||||||||||||||||||||||||||||||||||
| 2836 | */ | - | ||||||||||||||||||||||||||||||||||||
| 2837 | void QSettings::setIniCodec(QTextCodec *codec) | - | ||||||||||||||||||||||||||||||||||||
| 2838 | { | - | ||||||||||||||||||||||||||||||||||||
| 2839 | Q_D(QSettings); | - | ||||||||||||||||||||||||||||||||||||
| 2840 | d->iniCodec = codec; | - | ||||||||||||||||||||||||||||||||||||
| 2841 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 2842 | - | |||||||||||||||||||||||||||||||||||||
| 2843 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 2844 | \since 4.5 | - | ||||||||||||||||||||||||||||||||||||
| 2845 | \overload | - | ||||||||||||||||||||||||||||||||||||
| 2846 | - | |||||||||||||||||||||||||||||||||||||
| 2847 | Sets the codec for accessing INI files (including \c .conf files on Unix) | - | ||||||||||||||||||||||||||||||||||||
| 2848 | to the QTextCodec for the encoding specified by \a codecName. Common | - | ||||||||||||||||||||||||||||||||||||
| 2849 | values for \c codecName include "ISO 8859-1", "UTF-8", and "UTF-16". | - | ||||||||||||||||||||||||||||||||||||
| 2850 | If the encoding isn't recognized, nothing happens. | - | ||||||||||||||||||||||||||||||||||||
| 2851 | - | |||||||||||||||||||||||||||||||||||||
| 2852 | \sa QTextCodec::codecForName() | - | ||||||||||||||||||||||||||||||||||||
| 2853 | */ | - | ||||||||||||||||||||||||||||||||||||
| 2854 | void QSettings::setIniCodec(const char *codecName) | - | ||||||||||||||||||||||||||||||||||||
| 2855 | { | - | ||||||||||||||||||||||||||||||||||||
| 2856 | Q_D(QSettings); | - | ||||||||||||||||||||||||||||||||||||
| 2857 | if (QTextCodec *codec = QTextCodec::codecForName(codecName))
| 0-6 | ||||||||||||||||||||||||||||||||||||
| 2858 | d->iniCodec = codec; executed 6 times by 1 test: d->iniCodec = codec;Executed by:
| 6 | ||||||||||||||||||||||||||||||||||||
| 2859 | } executed 6 times by 1 test: end of blockExecuted by:
| 6 | ||||||||||||||||||||||||||||||||||||
| 2860 | - | |||||||||||||||||||||||||||||||||||||
| 2861 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 2862 | \since 4.5 | - | ||||||||||||||||||||||||||||||||||||
| 2863 | - | |||||||||||||||||||||||||||||||||||||
| 2864 | Returns the codec that is used for accessing INI files. By default, | - | ||||||||||||||||||||||||||||||||||||
| 2865 | no codec is used, so a null pointer is returned. | - | ||||||||||||||||||||||||||||||||||||
| 2866 | */ | - | ||||||||||||||||||||||||||||||||||||
| 2867 | - | |||||||||||||||||||||||||||||||||||||
| 2868 | QTextCodec *QSettings::iniCodec() const | - | ||||||||||||||||||||||||||||||||||||
| 2869 | { | - | ||||||||||||||||||||||||||||||||||||
| 2870 | Q_D(const QSettings); | - | ||||||||||||||||||||||||||||||||||||
| 2871 | return d->iniCodec; never executed: return d->iniCodec; | 0 | ||||||||||||||||||||||||||||||||||||
| 2872 | } | - | ||||||||||||||||||||||||||||||||||||
| 2873 | - | |||||||||||||||||||||||||||||||||||||
| 2874 | #endif // QT_NO_TEXTCODEC | - | ||||||||||||||||||||||||||||||||||||
| 2875 | - | |||||||||||||||||||||||||||||||||||||
| 2876 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 2877 | Returns a status code indicating the first error that was met by | - | ||||||||||||||||||||||||||||||||||||
| 2878 | QSettings, or QSettings::NoError if no error occurred. | - | ||||||||||||||||||||||||||||||||||||
| 2879 | - | |||||||||||||||||||||||||||||||||||||
| 2880 | Be aware that QSettings delays performing some operations. For this | - | ||||||||||||||||||||||||||||||||||||
| 2881 | reason, you might want to call sync() to ensure that the data stored | - | ||||||||||||||||||||||||||||||||||||
| 2882 | in QSettings is written to disk before calling status(). | - | ||||||||||||||||||||||||||||||||||||
| 2883 | - | |||||||||||||||||||||||||||||||||||||
| 2884 | \sa sync() | - | ||||||||||||||||||||||||||||||||||||
| 2885 | */ | - | ||||||||||||||||||||||||||||||||||||
| 2886 | QSettings::Status QSettings::status() const | - | ||||||||||||||||||||||||||||||||||||
| 2887 | { | - | ||||||||||||||||||||||||||||||||||||
| 2888 | Q_D(const QSettings); | - | ||||||||||||||||||||||||||||||||||||
| 2889 | return d->status; executed 99 times by 1 test: return d->status;Executed by:
| 99 | ||||||||||||||||||||||||||||||||||||
| 2890 | } | - | ||||||||||||||||||||||||||||||||||||
| 2891 | - | |||||||||||||||||||||||||||||||||||||
| 2892 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 2893 | Appends \a prefix to the current group. | - | ||||||||||||||||||||||||||||||||||||
| 2894 | - | |||||||||||||||||||||||||||||||||||||
| 2895 | The current group is automatically prepended to all keys | - | ||||||||||||||||||||||||||||||||||||
| 2896 | specified to QSettings. In addition, query functions such as | - | ||||||||||||||||||||||||||||||||||||
| 2897 | childGroups(), childKeys(), and allKeys() are based on the group. | - | ||||||||||||||||||||||||||||||||||||
| 2898 | By default, no group is set. | - | ||||||||||||||||||||||||||||||||||||
| 2899 | - | |||||||||||||||||||||||||||||||||||||
| 2900 | Groups are useful to avoid typing in the same setting paths over | - | ||||||||||||||||||||||||||||||||||||
| 2901 | and over. For example: | - | ||||||||||||||||||||||||||||||||||||
| 2902 | - | |||||||||||||||||||||||||||||||||||||
| 2903 | \snippet code/src_corelib_io_qsettings.cpp 13 | - | ||||||||||||||||||||||||||||||||||||
| 2904 | - | |||||||||||||||||||||||||||||||||||||
| 2905 | This will set the value of three settings: | - | ||||||||||||||||||||||||||||||||||||
| 2906 | - | |||||||||||||||||||||||||||||||||||||
| 2907 | \list | - | ||||||||||||||||||||||||||||||||||||
| 2908 | \li \c mainwindow/size | - | ||||||||||||||||||||||||||||||||||||
| 2909 | \li \c mainwindow/fullScreen | - | ||||||||||||||||||||||||||||||||||||
| 2910 | \li \c outputpanel/visible | - | ||||||||||||||||||||||||||||||||||||
| 2911 | \endlist | - | ||||||||||||||||||||||||||||||||||||
| 2912 | - | |||||||||||||||||||||||||||||||||||||
| 2913 | Call endGroup() to reset the current group to what it was before | - | ||||||||||||||||||||||||||||||||||||
| 2914 | the corresponding beginGroup() call. Groups can be nested. | - | ||||||||||||||||||||||||||||||||||||
| 2915 | - | |||||||||||||||||||||||||||||||||||||
| 2916 | \sa endGroup(), group() | - | ||||||||||||||||||||||||||||||||||||
| 2917 | */ | - | ||||||||||||||||||||||||||||||||||||
| 2918 | void QSettings::beginGroup(const QString &prefix) | - | ||||||||||||||||||||||||||||||||||||
| 2919 | { | - | ||||||||||||||||||||||||||||||||||||
| 2920 | Q_D(QSettings); | - | ||||||||||||||||||||||||||||||||||||
| 2921 | d->beginGroupOrArray(QSettingsGroup(d->normalizedKey(prefix))); | - | ||||||||||||||||||||||||||||||||||||
| 2922 | } executed 1287 times by 6 tests: end of blockExecuted by:
| 1287 | ||||||||||||||||||||||||||||||||||||
| 2923 | - | |||||||||||||||||||||||||||||||||||||
| 2924 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 2925 | Resets the group to what it was before the corresponding | - | ||||||||||||||||||||||||||||||||||||
| 2926 | beginGroup() call. | - | ||||||||||||||||||||||||||||||||||||
| 2927 | - | |||||||||||||||||||||||||||||||||||||
| 2928 | Example: | - | ||||||||||||||||||||||||||||||||||||
| 2929 | - | |||||||||||||||||||||||||||||||||||||
| 2930 | \snippet code/src_corelib_io_qsettings.cpp 14 | - | ||||||||||||||||||||||||||||||||||||
| 2931 | - | |||||||||||||||||||||||||||||||||||||
| 2932 | \sa beginGroup(), group() | - | ||||||||||||||||||||||||||||||||||||
| 2933 | */ | - | ||||||||||||||||||||||||||||||||||||
| 2934 | void QSettings::endGroup() | - | ||||||||||||||||||||||||||||||||||||
| 2935 | { | - | ||||||||||||||||||||||||||||||||||||
| 2936 | Q_D(QSettings); | - | ||||||||||||||||||||||||||||||||||||
| 2937 | if (d->groupStack.isEmpty()) {
| 14-790 | ||||||||||||||||||||||||||||||||||||
| 2938 | qWarning("QSettings::endGroup: No matching beginGroup()"); | - | ||||||||||||||||||||||||||||||||||||
| 2939 | return; executed 14 times by 1 test: return;Executed by:
| 14 | ||||||||||||||||||||||||||||||||||||
| 2940 | } | - | ||||||||||||||||||||||||||||||||||||
| 2941 | - | |||||||||||||||||||||||||||||||||||||
| 2942 | QSettingsGroup group = d->groupStack.pop(); | - | ||||||||||||||||||||||||||||||||||||
| 2943 | int len = group.toString().size(); | - | ||||||||||||||||||||||||||||||||||||
| 2944 | if (len > 0)
| 43-747 | ||||||||||||||||||||||||||||||||||||
| 2945 | d->groupPrefix.truncate(d->groupPrefix.size() - (len + 1)); executed 747 times by 4 tests: d->groupPrefix.truncate(d->groupPrefix.size() - (len + 1));Executed by:
| 747 | ||||||||||||||||||||||||||||||||||||
| 2946 | - | |||||||||||||||||||||||||||||||||||||
| 2947 | if (group.isArray())
| 4-786 | ||||||||||||||||||||||||||||||||||||
| 2948 | qWarning("QSettings::endGroup: Expected endArray() instead"); executed 4 times by 1 test: QMessageLogger(__FILE__, 2948, __PRETTY_FUNCTION__).warning("QSettings::endGroup: Expected endArray() instead");Executed by:
| 4 | ||||||||||||||||||||||||||||||||||||
| 2949 | } executed 790 times by 4 tests: end of blockExecuted by:
| 790 | ||||||||||||||||||||||||||||||||||||
| 2950 | - | |||||||||||||||||||||||||||||||||||||
| 2951 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 2952 | Returns the current group. | - | ||||||||||||||||||||||||||||||||||||
| 2953 | - | |||||||||||||||||||||||||||||||||||||
| 2954 | \sa beginGroup(), endGroup() | - | ||||||||||||||||||||||||||||||||||||
| 2955 | */ | - | ||||||||||||||||||||||||||||||||||||
| 2956 | QString QSettings::group() const | - | ||||||||||||||||||||||||||||||||||||
| 2957 | { | - | ||||||||||||||||||||||||||||||||||||
| 2958 | Q_D(const QSettings); | - | ||||||||||||||||||||||||||||||||||||
| 2959 | return d->groupPrefix.left(d->groupPrefix.size() - 1); executed 226 times by 3 tests: return d->groupPrefix.left(d->groupPrefix.size() - 1);Executed by:
| 226 | ||||||||||||||||||||||||||||||||||||
| 2960 | } | - | ||||||||||||||||||||||||||||||||||||
| 2961 | - | |||||||||||||||||||||||||||||||||||||
| 2962 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 2963 | Adds \a prefix to the current group and starts reading from an | - | ||||||||||||||||||||||||||||||||||||
| 2964 | array. Returns the size of the array. | - | ||||||||||||||||||||||||||||||||||||
| 2965 | - | |||||||||||||||||||||||||||||||||||||
| 2966 | Example: | - | ||||||||||||||||||||||||||||||||||||
| 2967 | - | |||||||||||||||||||||||||||||||||||||
| 2968 | \snippet code/src_corelib_io_qsettings.cpp 15 | - | ||||||||||||||||||||||||||||||||||||
| 2969 | - | |||||||||||||||||||||||||||||||||||||
| 2970 | Use beginWriteArray() to write the array in the first place. | - | ||||||||||||||||||||||||||||||||||||
| 2971 | - | |||||||||||||||||||||||||||||||||||||
| 2972 | \sa beginWriteArray(), endArray(), setArrayIndex() | - | ||||||||||||||||||||||||||||||||||||
| 2973 | */ | - | ||||||||||||||||||||||||||||||||||||
| 2974 | int QSettings::beginReadArray(const QString &prefix) | - | ||||||||||||||||||||||||||||||||||||
| 2975 | { | - | ||||||||||||||||||||||||||||||||||||
| 2976 | Q_D(QSettings); | - | ||||||||||||||||||||||||||||||||||||
| 2977 | d->beginGroupOrArray(QSettingsGroup(d->normalizedKey(prefix), false)); | - | ||||||||||||||||||||||||||||||||||||
| 2978 | return value(QLatin1String("size")).toInt(); executed 20 times by 1 test: return value(QLatin1String("size")).toInt();Executed by:
| 20 | ||||||||||||||||||||||||||||||||||||
| 2979 | } | - | ||||||||||||||||||||||||||||||||||||
| 2980 | - | |||||||||||||||||||||||||||||||||||||
| 2981 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 2982 | Adds \a prefix to the current group and starts writing an array | - | ||||||||||||||||||||||||||||||||||||
| 2983 | of size \a size. If \a size is -1 (the default), it is automatically | - | ||||||||||||||||||||||||||||||||||||
| 2984 | determined based on the indexes of the entries written. | - | ||||||||||||||||||||||||||||||||||||
| 2985 | - | |||||||||||||||||||||||||||||||||||||
| 2986 | If you have many occurrences of a certain set of keys, you can | - | ||||||||||||||||||||||||||||||||||||
| 2987 | use arrays to make your life easier. For example, let's suppose | - | ||||||||||||||||||||||||||||||||||||
| 2988 | that you want to save a variable-length list of user names and | - | ||||||||||||||||||||||||||||||||||||
| 2989 | passwords. You could then write: | - | ||||||||||||||||||||||||||||||||||||
| 2990 | - | |||||||||||||||||||||||||||||||||||||
| 2991 | \snippet code/src_corelib_io_qsettings.cpp 16 | - | ||||||||||||||||||||||||||||||||||||
| 2992 | - | |||||||||||||||||||||||||||||||||||||
| 2993 | The generated keys will have the form | - | ||||||||||||||||||||||||||||||||||||
| 2994 | - | |||||||||||||||||||||||||||||||||||||
| 2995 | \list | - | ||||||||||||||||||||||||||||||||||||
| 2996 | \li \c logins/size | - | ||||||||||||||||||||||||||||||||||||
| 2997 | \li \c logins/1/userName | - | ||||||||||||||||||||||||||||||||||||
| 2998 | \li \c logins/1/password | - | ||||||||||||||||||||||||||||||||||||
| 2999 | \li \c logins/2/userName | - | ||||||||||||||||||||||||||||||||||||
| 3000 | \li \c logins/2/password | - | ||||||||||||||||||||||||||||||||||||
| 3001 | \li \c logins/3/userName | - | ||||||||||||||||||||||||||||||||||||
| 3002 | \li \c logins/3/password | - | ||||||||||||||||||||||||||||||||||||
| 3003 | \li ... | - | ||||||||||||||||||||||||||||||||||||
| 3004 | \endlist | - | ||||||||||||||||||||||||||||||||||||
| 3005 | - | |||||||||||||||||||||||||||||||||||||
| 3006 | To read back an array, use beginReadArray(). | - | ||||||||||||||||||||||||||||||||||||
| 3007 | - | |||||||||||||||||||||||||||||||||||||
| 3008 | \sa beginReadArray(), endArray(), setArrayIndex() | - | ||||||||||||||||||||||||||||||||||||
| 3009 | */ | - | ||||||||||||||||||||||||||||||||||||
| 3010 | void QSettings::beginWriteArray(const QString &prefix, int size) | - | ||||||||||||||||||||||||||||||||||||
| 3011 | { | - | ||||||||||||||||||||||||||||||||||||
| 3012 | Q_D(QSettings); | - | ||||||||||||||||||||||||||||||||||||
| 3013 | d->beginGroupOrArray(QSettingsGroup(d->normalizedKey(prefix), size < 0)); | - | ||||||||||||||||||||||||||||||||||||
| 3014 | - | |||||||||||||||||||||||||||||||||||||
| 3015 | if (size < 0)
| 8-12 | ||||||||||||||||||||||||||||||||||||
| 3016 | remove(QLatin1String("size")); executed 12 times by 1 test: remove(QLatin1String("size"));Executed by:
| 12 | ||||||||||||||||||||||||||||||||||||
| 3017 | else | - | ||||||||||||||||||||||||||||||||||||
| 3018 | setValue(QLatin1String("size"), size); executed 8 times by 1 test: setValue(QLatin1String("size"), size);Executed by:
| 8 | ||||||||||||||||||||||||||||||||||||
| 3019 | } | - | ||||||||||||||||||||||||||||||||||||
| 3020 | - | |||||||||||||||||||||||||||||||||||||
| 3021 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 3022 | Closes the array that was started using beginReadArray() or | - | ||||||||||||||||||||||||||||||||||||
| 3023 | beginWriteArray(). | - | ||||||||||||||||||||||||||||||||||||
| 3024 | - | |||||||||||||||||||||||||||||||||||||
| 3025 | \sa beginReadArray(), beginWriteArray() | - | ||||||||||||||||||||||||||||||||||||
| 3026 | */ | - | ||||||||||||||||||||||||||||||||||||
| 3027 | void QSettings::endArray() | - | ||||||||||||||||||||||||||||||||||||
| 3028 | { | - | ||||||||||||||||||||||||||||||||||||
| 3029 | Q_D(QSettings); | - | ||||||||||||||||||||||||||||||||||||
| 3030 | if (d->groupStack.isEmpty()) {
| 0-44 | ||||||||||||||||||||||||||||||||||||
| 3031 | qWarning("QSettings::endArray: No matching beginArray()"); | - | ||||||||||||||||||||||||||||||||||||
| 3032 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||||||||
| 3033 | } | - | ||||||||||||||||||||||||||||||||||||
| 3034 | - | |||||||||||||||||||||||||||||||||||||
| 3035 | QSettingsGroup group = d->groupStack.top(); | - | ||||||||||||||||||||||||||||||||||||
| 3036 | int len = group.toString().size(); | - | ||||||||||||||||||||||||||||||||||||
| 3037 | d->groupStack.pop(); | - | ||||||||||||||||||||||||||||||||||||
| 3038 | if (len > 0)
| 0-44 | ||||||||||||||||||||||||||||||||||||
| 3039 | d->groupPrefix.truncate(d->groupPrefix.size() - (len + 1)); executed 44 times by 1 test: d->groupPrefix.truncate(d->groupPrefix.size() - (len + 1));Executed by:
| 44 | ||||||||||||||||||||||||||||||||||||
| 3040 | - | |||||||||||||||||||||||||||||||||||||
| 3041 | if (group.arraySizeGuess() != -1)
| 12-32 | ||||||||||||||||||||||||||||||||||||
| 3042 | setValue(group.name() + QLatin1String("/size"), group.arraySizeGuess()); executed 12 times by 1 test: setValue(group.name() + QLatin1String("/size"), group.arraySizeGuess());Executed by:
| 12 | ||||||||||||||||||||||||||||||||||||
| 3043 | - | |||||||||||||||||||||||||||||||||||||
| 3044 | if (!group.isArray())
| 8-36 | ||||||||||||||||||||||||||||||||||||
| 3045 | qWarning("QSettings::endArray: Expected endGroup() instead"); executed 8 times by 1 test: QMessageLogger(__FILE__, 3045, __PRETTY_FUNCTION__).warning("QSettings::endArray: Expected endGroup() instead");Executed by:
| 8 | ||||||||||||||||||||||||||||||||||||
| 3046 | } executed 44 times by 1 test: end of blockExecuted by:
| 44 | ||||||||||||||||||||||||||||||||||||
| 3047 | - | |||||||||||||||||||||||||||||||||||||
| 3048 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 3049 | Sets the current array index to \a i. Calls to functions such as | - | ||||||||||||||||||||||||||||||||||||
| 3050 | setValue(), value(), remove(), and contains() will operate on the | - | ||||||||||||||||||||||||||||||||||||
| 3051 | array entry at that index. | - | ||||||||||||||||||||||||||||||||||||
| 3052 | - | |||||||||||||||||||||||||||||||||||||
| 3053 | You must call beginReadArray() or beginWriteArray() before you | - | ||||||||||||||||||||||||||||||||||||
| 3054 | can call this function. | - | ||||||||||||||||||||||||||||||||||||
| 3055 | */ | - | ||||||||||||||||||||||||||||||||||||
| 3056 | void QSettings::setArrayIndex(int i) | - | ||||||||||||||||||||||||||||||||||||
| 3057 | { | - | ||||||||||||||||||||||||||||||||||||
| 3058 | Q_D(QSettings); | - | ||||||||||||||||||||||||||||||||||||
| 3059 | if (d->groupStack.isEmpty() || !d->groupStack.top().isArray()) {
| 0-148 | ||||||||||||||||||||||||||||||||||||
| 3060 | qWarning("QSettings::setArrayIndex: Missing beginArray()"); | - | ||||||||||||||||||||||||||||||||||||
| 3061 | return; executed 20 times by 1 test: return;Executed by:
| 20 | ||||||||||||||||||||||||||||||||||||
| 3062 | } | - | ||||||||||||||||||||||||||||||||||||
| 3063 | - | |||||||||||||||||||||||||||||||||||||
| 3064 | QSettingsGroup &top = d->groupStack.top(); | - | ||||||||||||||||||||||||||||||||||||
| 3065 | int len = top.toString().size(); | - | ||||||||||||||||||||||||||||||||||||
| 3066 | top.setArrayIndex(qMax(i, 0)); | - | ||||||||||||||||||||||||||||||||||||
| 3067 | d->groupPrefix.replace(d->groupPrefix.size() - len - 1, len, top.toString()); | - | ||||||||||||||||||||||||||||||||||||
| 3068 | } executed 128 times by 1 test: end of blockExecuted by:
| 128 | ||||||||||||||||||||||||||||||||||||
| 3069 | - | |||||||||||||||||||||||||||||||||||||
| 3070 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 3071 | Returns a list of all keys, including subkeys, that can be read | - | ||||||||||||||||||||||||||||||||||||
| 3072 | using the QSettings object. | - | ||||||||||||||||||||||||||||||||||||
| 3073 | - | |||||||||||||||||||||||||||||||||||||
| 3074 | Example: | - | ||||||||||||||||||||||||||||||||||||
| 3075 | - | |||||||||||||||||||||||||||||||||||||
| 3076 | \snippet code/src_corelib_io_qsettings.cpp 17 | - | ||||||||||||||||||||||||||||||||||||
| 3077 | - | |||||||||||||||||||||||||||||||||||||
| 3078 | If a group is set using beginGroup(), only the keys in the group | - | ||||||||||||||||||||||||||||||||||||
| 3079 | are returned, without the group prefix: | - | ||||||||||||||||||||||||||||||||||||
| 3080 | - | |||||||||||||||||||||||||||||||||||||
| 3081 | \snippet code/src_corelib_io_qsettings.cpp 18 | - | ||||||||||||||||||||||||||||||||||||
| 3082 | - | |||||||||||||||||||||||||||||||||||||
| 3083 | \sa childGroups(), childKeys() | - | ||||||||||||||||||||||||||||||||||||
| 3084 | */ | - | ||||||||||||||||||||||||||||||||||||
| 3085 | QStringList QSettings::allKeys() const | - | ||||||||||||||||||||||||||||||||||||
| 3086 | { | - | ||||||||||||||||||||||||||||||||||||
| 3087 | Q_D(const QSettings); | - | ||||||||||||||||||||||||||||||||||||
| 3088 | return d->children(d->groupPrefix, QSettingsPrivate::AllKeys); executed 228 times by 27 tests: return d->children(d->groupPrefix, QSettingsPrivate::AllKeys);Executed by:
| 228 | ||||||||||||||||||||||||||||||||||||
| 3089 | } | - | ||||||||||||||||||||||||||||||||||||
| 3090 | - | |||||||||||||||||||||||||||||||||||||
| 3091 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 3092 | Returns a list of all top-level keys that can be read using the | - | ||||||||||||||||||||||||||||||||||||
| 3093 | QSettings object. | - | ||||||||||||||||||||||||||||||||||||
| 3094 | - | |||||||||||||||||||||||||||||||||||||
| 3095 | Example: | - | ||||||||||||||||||||||||||||||||||||
| 3096 | - | |||||||||||||||||||||||||||||||||||||
| 3097 | \snippet code/src_corelib_io_qsettings.cpp 19 | - | ||||||||||||||||||||||||||||||||||||
| 3098 | - | |||||||||||||||||||||||||||||||||||||
| 3099 | If a group is set using beginGroup(), the top-level keys in that | - | ||||||||||||||||||||||||||||||||||||
| 3100 | group are returned, without the group prefix: | - | ||||||||||||||||||||||||||||||||||||
| 3101 | - | |||||||||||||||||||||||||||||||||||||
| 3102 | \snippet code/src_corelib_io_qsettings.cpp 20 | - | ||||||||||||||||||||||||||||||||||||
| 3103 | - | |||||||||||||||||||||||||||||||||||||
| 3104 | You can navigate through the entire setting hierarchy using | - | ||||||||||||||||||||||||||||||||||||
| 3105 | childKeys() and childGroups() recursively. | - | ||||||||||||||||||||||||||||||||||||
| 3106 | - | |||||||||||||||||||||||||||||||||||||
| 3107 | \sa childGroups(), allKeys() | - | ||||||||||||||||||||||||||||||||||||
| 3108 | */ | - | ||||||||||||||||||||||||||||||||||||
| 3109 | QStringList QSettings::childKeys() const | - | ||||||||||||||||||||||||||||||||||||
| 3110 | { | - | ||||||||||||||||||||||||||||||||||||
| 3111 | Q_D(const QSettings); | - | ||||||||||||||||||||||||||||||||||||
| 3112 | return d->children(d->groupPrefix, QSettingsPrivate::ChildKeys); executed 104 times by 1 test: return d->children(d->groupPrefix, QSettingsPrivate::ChildKeys);Executed by:
| 104 | ||||||||||||||||||||||||||||||||||||
| 3113 | } | - | ||||||||||||||||||||||||||||||||||||
| 3114 | - | |||||||||||||||||||||||||||||||||||||
| 3115 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 3116 | Returns a list of all key top-level groups that contain keys that | - | ||||||||||||||||||||||||||||||||||||
| 3117 | can be read using the QSettings object. | - | ||||||||||||||||||||||||||||||||||||
| 3118 | - | |||||||||||||||||||||||||||||||||||||
| 3119 | Example: | - | ||||||||||||||||||||||||||||||||||||
| 3120 | - | |||||||||||||||||||||||||||||||||||||
| 3121 | \snippet code/src_corelib_io_qsettings.cpp 21 | - | ||||||||||||||||||||||||||||||||||||
| 3122 | - | |||||||||||||||||||||||||||||||||||||
| 3123 | If a group is set using beginGroup(), the first-level keys in | - | ||||||||||||||||||||||||||||||||||||
| 3124 | that group are returned, without the group prefix. | - | ||||||||||||||||||||||||||||||||||||
| 3125 | - | |||||||||||||||||||||||||||||||||||||
| 3126 | \snippet code/src_corelib_io_qsettings.cpp 22 | - | ||||||||||||||||||||||||||||||||||||
| 3127 | - | |||||||||||||||||||||||||||||||||||||
| 3128 | You can navigate through the entire setting hierarchy using | - | ||||||||||||||||||||||||||||||||||||
| 3129 | childKeys() and childGroups() recursively. | - | ||||||||||||||||||||||||||||||||||||
| 3130 | - | |||||||||||||||||||||||||||||||||||||
| 3131 | \sa childKeys(), allKeys() | - | ||||||||||||||||||||||||||||||||||||
| 3132 | */ | - | ||||||||||||||||||||||||||||||||||||
| 3133 | QStringList QSettings::childGroups() const | - | ||||||||||||||||||||||||||||||||||||
| 3134 | { | - | ||||||||||||||||||||||||||||||||||||
| 3135 | Q_D(const QSettings); | - | ||||||||||||||||||||||||||||||||||||
| 3136 | return d->children(d->groupPrefix, QSettingsPrivate::ChildGroups); executed 593 times by 6 tests: return d->children(d->groupPrefix, QSettingsPrivate::ChildGroups);Executed by:
| 593 | ||||||||||||||||||||||||||||||||||||
| 3137 | } | - | ||||||||||||||||||||||||||||||||||||
| 3138 | - | |||||||||||||||||||||||||||||||||||||
| 3139 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 3140 | Returns \c true if settings can be written using this QSettings | - | ||||||||||||||||||||||||||||||||||||
| 3141 | object; returns \c false otherwise. | - | ||||||||||||||||||||||||||||||||||||
| 3142 | - | |||||||||||||||||||||||||||||||||||||
| 3143 | One reason why isWritable() might return false is if | - | ||||||||||||||||||||||||||||||||||||
| 3144 | QSettings operates on a read-only file. | - | ||||||||||||||||||||||||||||||||||||
| 3145 | - | |||||||||||||||||||||||||||||||||||||
| 3146 | \warning This function is not perfectly reliable, because the | - | ||||||||||||||||||||||||||||||||||||
| 3147 | file permissions can change at any time. | - | ||||||||||||||||||||||||||||||||||||
| 3148 | - | |||||||||||||||||||||||||||||||||||||
| 3149 | \sa fileName(), status(), sync() | - | ||||||||||||||||||||||||||||||||||||
| 3150 | */ | - | ||||||||||||||||||||||||||||||||||||
| 3151 | bool QSettings::isWritable() const | - | ||||||||||||||||||||||||||||||||||||
| 3152 | { | - | ||||||||||||||||||||||||||||||||||||
| 3153 | Q_D(const QSettings); | - | ||||||||||||||||||||||||||||||||||||
| 3154 | return d->isWritable(); executed 21 times by 1 test: return d->isWritable();Executed by:
| 21 | ||||||||||||||||||||||||||||||||||||
| 3155 | } | - | ||||||||||||||||||||||||||||||||||||
| 3156 | - | |||||||||||||||||||||||||||||||||||||
| 3157 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 3158 | - | |||||||||||||||||||||||||||||||||||||
| 3159 | Sets the value of setting \a key to \a value. If the \a key already | - | ||||||||||||||||||||||||||||||||||||
| 3160 | exists, the previous value is overwritten. | - | ||||||||||||||||||||||||||||||||||||
| 3161 | - | |||||||||||||||||||||||||||||||||||||
| 3162 | Note that the Windows registry and INI files use case-insensitive | - | ||||||||||||||||||||||||||||||||||||
| 3163 | keys, whereas the CFPreferences API on \macos and iOS uses | - | ||||||||||||||||||||||||||||||||||||
| 3164 | case-sensitive keys. To avoid portability problems, see the | - | ||||||||||||||||||||||||||||||||||||
| 3165 | \l{Section and Key Syntax} rules. | - | ||||||||||||||||||||||||||||||||||||
| 3166 | - | |||||||||||||||||||||||||||||||||||||
| 3167 | Example: | - | ||||||||||||||||||||||||||||||||||||
| 3168 | - | |||||||||||||||||||||||||||||||||||||
| 3169 | \snippet code/src_corelib_io_qsettings.cpp 23 | - | ||||||||||||||||||||||||||||||||||||
| 3170 | - | |||||||||||||||||||||||||||||||||||||
| 3171 | \sa value(), remove(), contains() | - | ||||||||||||||||||||||||||||||||||||
| 3172 | */ | - | ||||||||||||||||||||||||||||||||||||
| 3173 | void QSettings::setValue(const QString &key, const QVariant &value) | - | ||||||||||||||||||||||||||||||||||||
| 3174 | { | - | ||||||||||||||||||||||||||||||||||||
| 3175 | Q_D(QSettings); | - | ||||||||||||||||||||||||||||||||||||
| 3176 | if (key.isEmpty()) {
| 1-2437 | ||||||||||||||||||||||||||||||||||||
| 3177 | qWarning("QSettings::setValue: Empty key passed"); | - | ||||||||||||||||||||||||||||||||||||
| 3178 | return; executed 1 time by 1 test: return;Executed by:
| 1 | ||||||||||||||||||||||||||||||||||||
| 3179 | } | - | ||||||||||||||||||||||||||||||||||||
| 3180 | QString k = d->actualKey(key); | - | ||||||||||||||||||||||||||||||||||||
| 3181 | d->set(k, value); | - | ||||||||||||||||||||||||||||||||||||
| 3182 | d->requestUpdate(); | - | ||||||||||||||||||||||||||||||||||||
| 3183 | } executed 2437 times by 6 tests: end of blockExecuted by:
| 2437 | ||||||||||||||||||||||||||||||||||||
| 3184 | - | |||||||||||||||||||||||||||||||||||||
| 3185 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 3186 | Removes the setting \a key and any sub-settings of \a key. | - | ||||||||||||||||||||||||||||||||||||
| 3187 | - | |||||||||||||||||||||||||||||||||||||
| 3188 | Example: | - | ||||||||||||||||||||||||||||||||||||
| 3189 | - | |||||||||||||||||||||||||||||||||||||
| 3190 | \snippet code/src_corelib_io_qsettings.cpp 24 | - | ||||||||||||||||||||||||||||||||||||
| 3191 | - | |||||||||||||||||||||||||||||||||||||
| 3192 | Be aware that if one of the fallback locations contains a setting | - | ||||||||||||||||||||||||||||||||||||
| 3193 | with the same key, that setting will be visible after calling | - | ||||||||||||||||||||||||||||||||||||
| 3194 | remove(). | - | ||||||||||||||||||||||||||||||||||||
| 3195 | - | |||||||||||||||||||||||||||||||||||||
| 3196 | If \a key is an empty string, all keys in the current group() are | - | ||||||||||||||||||||||||||||||||||||
| 3197 | removed. For example: | - | ||||||||||||||||||||||||||||||||||||
| 3198 | - | |||||||||||||||||||||||||||||||||||||
| 3199 | \snippet code/src_corelib_io_qsettings.cpp 25 | - | ||||||||||||||||||||||||||||||||||||
| 3200 | - | |||||||||||||||||||||||||||||||||||||
| 3201 | Note that the Windows registry and INI files use case-insensitive | - | ||||||||||||||||||||||||||||||||||||
| 3202 | keys, whereas the CFPreferences API on \macos and iOS uses | - | ||||||||||||||||||||||||||||||||||||
| 3203 | case-sensitive keys. To avoid portability problems, see the | - | ||||||||||||||||||||||||||||||||||||
| 3204 | \l{Section and Key Syntax} rules. | - | ||||||||||||||||||||||||||||||||||||
| 3205 | - | |||||||||||||||||||||||||||||||||||||
| 3206 | \sa setValue(), value(), contains() | - | ||||||||||||||||||||||||||||||||||||
| 3207 | */ | - | ||||||||||||||||||||||||||||||||||||
| 3208 | void QSettings::remove(const QString &key) | - | ||||||||||||||||||||||||||||||||||||
| 3209 | { | - | ||||||||||||||||||||||||||||||||||||
| 3210 | Q_D(QSettings); | - | ||||||||||||||||||||||||||||||||||||
| 3211 | /* | - | ||||||||||||||||||||||||||||||||||||
| 3212 | We cannot use actualKey(), because remove() supports empty | - | ||||||||||||||||||||||||||||||||||||
| 3213 | keys. The code is also tricky because of slash handling. | - | ||||||||||||||||||||||||||||||||||||
| 3214 | */ | - | ||||||||||||||||||||||||||||||||||||
| 3215 | QString theKey = d->normalizedKey(key); | - | ||||||||||||||||||||||||||||||||||||
| 3216 | if (theKey.isEmpty())
| 111-151 | ||||||||||||||||||||||||||||||||||||
| 3217 | theKey = group(); executed 111 times by 3 tests: theKey = group();Executed by:
| 111 | ||||||||||||||||||||||||||||||||||||
| 3218 | else | - | ||||||||||||||||||||||||||||||||||||
| 3219 | theKey.prepend(d->groupPrefix); executed 151 times by 3 tests: theKey.prepend(d->groupPrefix);Executed by:
| 151 | ||||||||||||||||||||||||||||||||||||
| 3220 | - | |||||||||||||||||||||||||||||||||||||
| 3221 | if (theKey.isEmpty()) {
| 1-261 | ||||||||||||||||||||||||||||||||||||
| 3222 | d->clear(); | - | ||||||||||||||||||||||||||||||||||||
| 3223 | } else { executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||||||||||||||||||||
| 3224 | d->remove(theKey); | - | ||||||||||||||||||||||||||||||||||||
| 3225 | } executed 261 times by 3 tests: end of blockExecuted by:
| 261 | ||||||||||||||||||||||||||||||||||||
| 3226 | d->requestUpdate(); | - | ||||||||||||||||||||||||||||||||||||
| 3227 | } executed 262 times by 3 tests: end of blockExecuted by:
| 262 | ||||||||||||||||||||||||||||||||||||
| 3228 | - | |||||||||||||||||||||||||||||||||||||
| 3229 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 3230 | Returns \c true if there exists a setting called \a key; returns | - | ||||||||||||||||||||||||||||||||||||
| 3231 | false otherwise. | - | ||||||||||||||||||||||||||||||||||||
| 3232 | - | |||||||||||||||||||||||||||||||||||||
| 3233 | If a group is set using beginGroup(), \a key is taken to be | - | ||||||||||||||||||||||||||||||||||||
| 3234 | relative to that group. | - | ||||||||||||||||||||||||||||||||||||
| 3235 | - | |||||||||||||||||||||||||||||||||||||
| 3236 | Note that the Windows registry and INI files use case-insensitive | - | ||||||||||||||||||||||||||||||||||||
| 3237 | keys, whereas the CFPreferences API on \macos and iOS uses | - | ||||||||||||||||||||||||||||||||||||
| 3238 | case-sensitive keys. To avoid portability problems, see the | - | ||||||||||||||||||||||||||||||||||||
| 3239 | \l{Section and Key Syntax} rules. | - | ||||||||||||||||||||||||||||||||||||
| 3240 | - | |||||||||||||||||||||||||||||||||||||
| 3241 | \sa value(), setValue() | - | ||||||||||||||||||||||||||||||||||||
| 3242 | */ | - | ||||||||||||||||||||||||||||||||||||
| 3243 | bool QSettings::contains(const QString &key) const | - | ||||||||||||||||||||||||||||||||||||
| 3244 | { | - | ||||||||||||||||||||||||||||||||||||
| 3245 | Q_D(const QSettings); | - | ||||||||||||||||||||||||||||||||||||
| 3246 | QString k = d->actualKey(key); | - | ||||||||||||||||||||||||||||||||||||
| 3247 | return d->get(k, 0); executed 218 times by 1 test: return d->get(k, 0);Executed by:
| 218 | ||||||||||||||||||||||||||||||||||||
| 3248 | } | - | ||||||||||||||||||||||||||||||||||||
| 3249 | - | |||||||||||||||||||||||||||||||||||||
| 3250 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 3251 | Sets whether fallbacks are enabled to \a b. | - | ||||||||||||||||||||||||||||||||||||
| 3252 | - | |||||||||||||||||||||||||||||||||||||
| 3253 | By default, fallbacks are enabled. | - | ||||||||||||||||||||||||||||||||||||
| 3254 | - | |||||||||||||||||||||||||||||||||||||
| 3255 | \sa fallbacksEnabled() | - | ||||||||||||||||||||||||||||||||||||
| 3256 | */ | - | ||||||||||||||||||||||||||||||||||||
| 3257 | void QSettings::setFallbacksEnabled(bool b) | - | ||||||||||||||||||||||||||||||||||||
| 3258 | { | - | ||||||||||||||||||||||||||||||||||||
| 3259 | Q_D(QSettings); | - | ||||||||||||||||||||||||||||||||||||
| 3260 | d->fallbacks = !!b; | - | ||||||||||||||||||||||||||||||||||||
| 3261 | } executed 58 times by 1 test: end of blockExecuted by:
| 58 | ||||||||||||||||||||||||||||||||||||
| 3262 | - | |||||||||||||||||||||||||||||||||||||
| 3263 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 3264 | Returns \c true if fallbacks are enabled; returns \c false otherwise. | - | ||||||||||||||||||||||||||||||||||||
| 3265 | - | |||||||||||||||||||||||||||||||||||||
| 3266 | By default, fallbacks are enabled. | - | ||||||||||||||||||||||||||||||||||||
| 3267 | - | |||||||||||||||||||||||||||||||||||||
| 3268 | \sa setFallbacksEnabled() | - | ||||||||||||||||||||||||||||||||||||
| 3269 | */ | - | ||||||||||||||||||||||||||||||||||||
| 3270 | bool QSettings::fallbacksEnabled() const | - | ||||||||||||||||||||||||||||||||||||
| 3271 | { | - | ||||||||||||||||||||||||||||||||||||
| 3272 | Q_D(const QSettings); | - | ||||||||||||||||||||||||||||||||||||
| 3273 | return d->fallbacks; executed 34 times by 1 test: return d->fallbacks;Executed by:
| 34 | ||||||||||||||||||||||||||||||||||||
| 3274 | } | - | ||||||||||||||||||||||||||||||||||||
| 3275 | - | |||||||||||||||||||||||||||||||||||||
| 3276 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||||||||||||||||||||
| 3277 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 3278 | \reimp | - | ||||||||||||||||||||||||||||||||||||
| 3279 | */ | - | ||||||||||||||||||||||||||||||||||||
| 3280 | bool QSettings::event(QEvent *event) | - | ||||||||||||||||||||||||||||||||||||
| 3281 | { | - | ||||||||||||||||||||||||||||||||||||
| 3282 | Q_D(QSettings); | - | ||||||||||||||||||||||||||||||||||||
| 3283 | if (event->type() == QEvent::UpdateRequest) {
| 0-4 | ||||||||||||||||||||||||||||||||||||
| 3284 | d->update(); | - | ||||||||||||||||||||||||||||||||||||
| 3285 | return true; executed 4 times by 1 test: return true;Executed by:
| 4 | ||||||||||||||||||||||||||||||||||||
| 3286 | } | - | ||||||||||||||||||||||||||||||||||||
| 3287 | return QObject::event(event); never executed: return QObject::event(event); | 0 | ||||||||||||||||||||||||||||||||||||
| 3288 | } | - | ||||||||||||||||||||||||||||||||||||
| 3289 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 3290 | - | |||||||||||||||||||||||||||||||||||||
| 3291 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 3292 | Returns the value for setting \a key. If the setting doesn't | - | ||||||||||||||||||||||||||||||||||||
| 3293 | exist, returns \a defaultValue. | - | ||||||||||||||||||||||||||||||||||||
| 3294 | - | |||||||||||||||||||||||||||||||||||||
| 3295 | If no default value is specified, a default QVariant is | - | ||||||||||||||||||||||||||||||||||||
| 3296 | returned. | - | ||||||||||||||||||||||||||||||||||||
| 3297 | - | |||||||||||||||||||||||||||||||||||||
| 3298 | Note that the Windows registry and INI files use case-insensitive | - | ||||||||||||||||||||||||||||||||||||
| 3299 | keys, whereas the CFPreferences API on \macos and iOS uses | - | ||||||||||||||||||||||||||||||||||||
| 3300 | case-sensitive keys. To avoid portability problems, see the | - | ||||||||||||||||||||||||||||||||||||
| 3301 | \l{Section and Key Syntax} rules. | - | ||||||||||||||||||||||||||||||||||||
| 3302 | - | |||||||||||||||||||||||||||||||||||||
| 3303 | Example: | - | ||||||||||||||||||||||||||||||||||||
| 3304 | - | |||||||||||||||||||||||||||||||||||||
| 3305 | \snippet code/src_corelib_io_qsettings.cpp 26 | - | ||||||||||||||||||||||||||||||||||||
| 3306 | - | |||||||||||||||||||||||||||||||||||||
| 3307 | \sa setValue(), contains(), remove() | - | ||||||||||||||||||||||||||||||||||||
| 3308 | */ | - | ||||||||||||||||||||||||||||||||||||
| 3309 | QVariant QSettings::value(const QString &key, const QVariant &defaultValue) const | - | ||||||||||||||||||||||||||||||||||||
| 3310 | { | - | ||||||||||||||||||||||||||||||||||||
| 3311 | Q_D(const QSettings); | - | ||||||||||||||||||||||||||||||||||||
| 3312 | if (key.isEmpty()) {
| 1-46213 | ||||||||||||||||||||||||||||||||||||
| 3313 | qWarning("QSettings::value: Empty key passed"); | - | ||||||||||||||||||||||||||||||||||||
| 3314 | return QVariant(); executed 1 time by 1 test: return QVariant();Executed by:
| 1 | ||||||||||||||||||||||||||||||||||||
| 3315 | } | - | ||||||||||||||||||||||||||||||||||||
| 3316 | QVariant result = defaultValue; | - | ||||||||||||||||||||||||||||||||||||
| 3317 | QString k = d->actualKey(key); | - | ||||||||||||||||||||||||||||||||||||
| 3318 | d->get(k, &result); | - | ||||||||||||||||||||||||||||||||||||
| 3319 | return result; executed 46213 times by 30 tests: return result;Executed by:
| 46213 | ||||||||||||||||||||||||||||||||||||
| 3320 | } | - | ||||||||||||||||||||||||||||||||||||
| 3321 | - | |||||||||||||||||||||||||||||||||||||
| 3322 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 3323 | \since 4.4 | - | ||||||||||||||||||||||||||||||||||||
| 3324 | - | |||||||||||||||||||||||||||||||||||||
| 3325 | Sets the default file format to the given \a format, which is used | - | ||||||||||||||||||||||||||||||||||||
| 3326 | for storing settings for the QSettings(QObject *) constructor. | - | ||||||||||||||||||||||||||||||||||||
| 3327 | - | |||||||||||||||||||||||||||||||||||||
| 3328 | If no default format is set, QSettings::NativeFormat is used. See | - | ||||||||||||||||||||||||||||||||||||
| 3329 | the documentation for the QSettings constructor you are using to | - | ||||||||||||||||||||||||||||||||||||
| 3330 | see if that constructor will ignore this function. | - | ||||||||||||||||||||||||||||||||||||
| 3331 | - | |||||||||||||||||||||||||||||||||||||
| 3332 | \sa format() | - | ||||||||||||||||||||||||||||||||||||
| 3333 | */ | - | ||||||||||||||||||||||||||||||||||||
| 3334 | void QSettings::setDefaultFormat(Format format) | - | ||||||||||||||||||||||||||||||||||||
| 3335 | { | - | ||||||||||||||||||||||||||||||||||||
| 3336 | globalDefaultFormat = format; | - | ||||||||||||||||||||||||||||||||||||
| 3337 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||||||||||||||
| 3338 | - | |||||||||||||||||||||||||||||||||||||
| 3339 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 3340 | \since 4.4 | - | ||||||||||||||||||||||||||||||||||||
| 3341 | - | |||||||||||||||||||||||||||||||||||||
| 3342 | Returns default file format used for storing settings for the QSettings(QObject *) constructor. | - | ||||||||||||||||||||||||||||||||||||
| 3343 | If no default format is set, QSettings::NativeFormat is used. | - | ||||||||||||||||||||||||||||||||||||
| 3344 | - | |||||||||||||||||||||||||||||||||||||
| 3345 | \sa format() | - | ||||||||||||||||||||||||||||||||||||
| 3346 | */ | - | ||||||||||||||||||||||||||||||||||||
| 3347 | QSettings::Format QSettings::defaultFormat() | - | ||||||||||||||||||||||||||||||||||||
| 3348 | { | - | ||||||||||||||||||||||||||||||||||||
| 3349 | return globalDefaultFormat; executed 2 times by 1 test: return globalDefaultFormat;Executed by:
| 2 | ||||||||||||||||||||||||||||||||||||
| 3350 | } | - | ||||||||||||||||||||||||||||||||||||
| 3351 | - | |||||||||||||||||||||||||||||||||||||
| 3352 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 3353 | \obsolete | - | ||||||||||||||||||||||||||||||||||||
| 3354 | - | |||||||||||||||||||||||||||||||||||||
| 3355 | Use setPath() instead. | - | ||||||||||||||||||||||||||||||||||||
| 3356 | - | |||||||||||||||||||||||||||||||||||||
| 3357 | \oldcode | - | ||||||||||||||||||||||||||||||||||||
| 3358 | setSystemIniPath(path); | - | ||||||||||||||||||||||||||||||||||||
| 3359 | \newcode | - | ||||||||||||||||||||||||||||||||||||
| 3360 | setPath(QSettings::NativeFormat, QSettings::SystemScope, path); | - | ||||||||||||||||||||||||||||||||||||
| 3361 | setPath(QSettings::IniFormat, QSettings::SystemScope, path); | - | ||||||||||||||||||||||||||||||||||||
| 3362 | \endcode | - | ||||||||||||||||||||||||||||||||||||
| 3363 | */ | - | ||||||||||||||||||||||||||||||||||||
| 3364 | void QSettings::setSystemIniPath(const QString &dir) | - | ||||||||||||||||||||||||||||||||||||
| 3365 | { | - | ||||||||||||||||||||||||||||||||||||
| 3366 | setPath(IniFormat, SystemScope, dir); | - | ||||||||||||||||||||||||||||||||||||
| 3367 | #if !defined(Q_OS_WIN) && !defined(Q_OS_MAC) | - | ||||||||||||||||||||||||||||||||||||
| 3368 | setPath(NativeFormat, SystemScope, dir); | - | ||||||||||||||||||||||||||||||||||||
| 3369 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 3370 | } executed 139 times by 1 test: end of blockExecuted by:
| 139 | ||||||||||||||||||||||||||||||||||||
| 3371 | - | |||||||||||||||||||||||||||||||||||||
| 3372 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 3373 | \obsolete | - | ||||||||||||||||||||||||||||||||||||
| 3374 | - | |||||||||||||||||||||||||||||||||||||
| 3375 | Use setPath() instead. | - | ||||||||||||||||||||||||||||||||||||
| 3376 | */ | - | ||||||||||||||||||||||||||||||||||||
| 3377 | - | |||||||||||||||||||||||||||||||||||||
| 3378 | void QSettings::setUserIniPath(const QString &dir) | - | ||||||||||||||||||||||||||||||||||||
| 3379 | { | - | ||||||||||||||||||||||||||||||||||||
| 3380 | setPath(IniFormat, UserScope, dir); | - | ||||||||||||||||||||||||||||||||||||
| 3381 | #if !defined(Q_OS_WIN) && !defined(Q_OS_MAC) | - | ||||||||||||||||||||||||||||||||||||
| 3382 | setPath(NativeFormat, UserScope, dir); | - | ||||||||||||||||||||||||||||||||||||
| 3383 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 3384 | } executed 139 times by 1 test: end of blockExecuted by:
| 139 | ||||||||||||||||||||||||||||||||||||
| 3385 | - | |||||||||||||||||||||||||||||||||||||
| 3386 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 3387 | \since 4.1 | - | ||||||||||||||||||||||||||||||||||||
| 3388 | - | |||||||||||||||||||||||||||||||||||||
| 3389 | Sets the path used for storing settings for the given \a format | - | ||||||||||||||||||||||||||||||||||||
| 3390 | and \a scope, to \a path. The \a format can be a custom format. | - | ||||||||||||||||||||||||||||||||||||
| 3391 | - | |||||||||||||||||||||||||||||||||||||
| 3392 | The table below summarizes the default values: | - | ||||||||||||||||||||||||||||||||||||
| 3393 | - | |||||||||||||||||||||||||||||||||||||
| 3394 | \table | - | ||||||||||||||||||||||||||||||||||||
| 3395 | \header \li Platform \li Format \li Scope \li Path | - | ||||||||||||||||||||||||||||||||||||
| 3396 | \row \li{1,2} Windows \li{1,2} IniFormat \li UserScope \li \c CSIDL_APPDATA | - | ||||||||||||||||||||||||||||||||||||
| 3397 | \row \li SystemScope \li \c CSIDL_COMMON_APPDATA | - | ||||||||||||||||||||||||||||||||||||
| 3398 | \row \li{1,2} Unix \li{1,2} NativeFormat, IniFormat \li UserScope \li \c $HOME/.config | - | ||||||||||||||||||||||||||||||||||||
| 3399 | \row \li SystemScope \li \c /etc/xdg | - | ||||||||||||||||||||||||||||||||||||
| 3400 | \row \li{1,2} Qt for Embedded Linux \li{1,2} NativeFormat, IniFormat \li UserScope \li \c $HOME/Settings | - | ||||||||||||||||||||||||||||||||||||
| 3401 | \row \li SystemScope \li \c /etc/xdg | - | ||||||||||||||||||||||||||||||||||||
| 3402 | \row \li{1,2} \macos and iOS \li{1,2} IniFormat \li UserScope \li \c $HOME/.config | - | ||||||||||||||||||||||||||||||||||||
| 3403 | \row \li SystemScope \li \c /etc/xdg | - | ||||||||||||||||||||||||||||||||||||
| 3404 | \endtable | - | ||||||||||||||||||||||||||||||||||||
| 3405 | - | |||||||||||||||||||||||||||||||||||||
| 3406 | The default UserScope paths on Unix, \macos, and iOS (\c | - | ||||||||||||||||||||||||||||||||||||
| 3407 | $HOME/.config or $HOME/Settings) can be overridden by the user by setting the | - | ||||||||||||||||||||||||||||||||||||
| 3408 | \c XDG_CONFIG_HOME environment variable. The default SystemScope | - | ||||||||||||||||||||||||||||||||||||
| 3409 | paths on Unix, \macos, and iOS (\c /etc/xdg) can be overridden when | - | ||||||||||||||||||||||||||||||||||||
| 3410 | building the Qt library using the \c configure script's \c | - | ||||||||||||||||||||||||||||||||||||
| 3411 | -sysconfdir flag (see QLibraryInfo for details). | - | ||||||||||||||||||||||||||||||||||||
| 3412 | - | |||||||||||||||||||||||||||||||||||||
| 3413 | Setting the NativeFormat paths on Windows, \macos, and iOS has no | - | ||||||||||||||||||||||||||||||||||||
| 3414 | effect. | - | ||||||||||||||||||||||||||||||||||||
| 3415 | - | |||||||||||||||||||||||||||||||||||||
| 3416 | \warning This function doesn't affect existing QSettings objects. | - | ||||||||||||||||||||||||||||||||||||
| 3417 | - | |||||||||||||||||||||||||||||||||||||
| 3418 | \sa registerFormat() | - | ||||||||||||||||||||||||||||||||||||
| 3419 | */ | - | ||||||||||||||||||||||||||||||||||||
| 3420 | void QSettings::setPath(Format format, Scope scope, const QString &path) | - | ||||||||||||||||||||||||||||||||||||
| 3421 | { | - | ||||||||||||||||||||||||||||||||||||
| 3422 | QMutexLocker locker(&settingsGlobalMutex); | - | ||||||||||||||||||||||||||||||||||||
| 3423 | PathHash *pathHash = pathHashFunc(); | - | ||||||||||||||||||||||||||||||||||||
| 3424 | if (pathHash->isEmpty())
| 1-563 | ||||||||||||||||||||||||||||||||||||
| 3425 | initDefaultPaths(&locker); executed 1 time by 1 test: initDefaultPaths(&locker);Executed by:
| 1 | ||||||||||||||||||||||||||||||||||||
| 3426 | pathHash->insert(pathHashKey(format, scope), path + QDir::separator()); | - | ||||||||||||||||||||||||||||||||||||
| 3427 | } executed 564 times by 1 test: end of blockExecuted by:
| 564 | ||||||||||||||||||||||||||||||||||||
| 3428 | - | |||||||||||||||||||||||||||||||||||||
| 3429 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 3430 | \typedef QSettings::SettingsMap | - | ||||||||||||||||||||||||||||||||||||
| 3431 | - | |||||||||||||||||||||||||||||||||||||
| 3432 | Typedef for QMap<QString, QVariant>. | - | ||||||||||||||||||||||||||||||||||||
| 3433 | - | |||||||||||||||||||||||||||||||||||||
| 3434 | \sa registerFormat() | - | ||||||||||||||||||||||||||||||||||||
| 3435 | */ | - | ||||||||||||||||||||||||||||||||||||
| 3436 | - | |||||||||||||||||||||||||||||||||||||
| 3437 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 3438 | \typedef QSettings::ReadFunc | - | ||||||||||||||||||||||||||||||||||||
| 3439 | - | |||||||||||||||||||||||||||||||||||||
| 3440 | Typedef for a pointer to a function with the following signature: | - | ||||||||||||||||||||||||||||||||||||
| 3441 | - | |||||||||||||||||||||||||||||||||||||
| 3442 | \snippet code/src_corelib_io_qsettings.cpp 27 | - | ||||||||||||||||||||||||||||||||||||
| 3443 | - | |||||||||||||||||||||||||||||||||||||
| 3444 | \c ReadFunc is used in \c registerFormat() as a pointer to a function | - | ||||||||||||||||||||||||||||||||||||
| 3445 | that reads a set of key/value pairs. \c ReadFunc should read all the | - | ||||||||||||||||||||||||||||||||||||
| 3446 | options in one pass, and return all the settings in the \c SettingsMap | - | ||||||||||||||||||||||||||||||||||||
| 3447 | container, which is initially empty. | - | ||||||||||||||||||||||||||||||||||||
| 3448 | - | |||||||||||||||||||||||||||||||||||||
| 3449 | \sa WriteFunc, registerFormat() | - | ||||||||||||||||||||||||||||||||||||
| 3450 | */ | - | ||||||||||||||||||||||||||||||||||||
| 3451 | - | |||||||||||||||||||||||||||||||||||||
| 3452 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 3453 | \typedef QSettings::WriteFunc | - | ||||||||||||||||||||||||||||||||||||
| 3454 | - | |||||||||||||||||||||||||||||||||||||
| 3455 | Typedef for a pointer to a function with the following signature: | - | ||||||||||||||||||||||||||||||||||||
| 3456 | - | |||||||||||||||||||||||||||||||||||||
| 3457 | \snippet code/src_corelib_io_qsettings.cpp 28 | - | ||||||||||||||||||||||||||||||||||||
| 3458 | - | |||||||||||||||||||||||||||||||||||||
| 3459 | \c WriteFunc is used in \c registerFormat() as a pointer to a function | - | ||||||||||||||||||||||||||||||||||||
| 3460 | that writes a set of key/value pairs. \c WriteFunc is only called once, | - | ||||||||||||||||||||||||||||||||||||
| 3461 | so you need to output the settings in one go. | - | ||||||||||||||||||||||||||||||||||||
| 3462 | - | |||||||||||||||||||||||||||||||||||||
| 3463 | \sa ReadFunc, registerFormat() | - | ||||||||||||||||||||||||||||||||||||
| 3464 | */ | - | ||||||||||||||||||||||||||||||||||||
| 3465 | - | |||||||||||||||||||||||||||||||||||||
| 3466 | /*! | - | ||||||||||||||||||||||||||||||||||||
| 3467 | \since 4.1 | - | ||||||||||||||||||||||||||||||||||||
| 3468 | \threadsafe | - | ||||||||||||||||||||||||||||||||||||
| 3469 | - | |||||||||||||||||||||||||||||||||||||
| 3470 | Registers a custom storage format. On success, returns a special | - | ||||||||||||||||||||||||||||||||||||
| 3471 | Format value that can then be passed to the QSettings constructor. | - | ||||||||||||||||||||||||||||||||||||
| 3472 | On failure, returns InvalidFormat. | - | ||||||||||||||||||||||||||||||||||||
| 3473 | - | |||||||||||||||||||||||||||||||||||||
| 3474 | The \a extension is the file | - | ||||||||||||||||||||||||||||||||||||
| 3475 | extension associated to the format (without the '.'). | - | ||||||||||||||||||||||||||||||||||||
| 3476 | - | |||||||||||||||||||||||||||||||||||||
| 3477 | The \a readFunc and \a writeFunc parameters are pointers to | - | ||||||||||||||||||||||||||||||||||||
| 3478 | functions that read and write a set of key/value pairs. The | - | ||||||||||||||||||||||||||||||||||||
| 3479 | QIODevice parameter to the read and write functions is always | - | ||||||||||||||||||||||||||||||||||||
| 3480 | opened in binary mode (i.e., without the QIODevice::Text flag). | - | ||||||||||||||||||||||||||||||||||||
| 3481 | - | |||||||||||||||||||||||||||||||||||||
| 3482 | The \a caseSensitivity parameter specifies whether keys are case | - | ||||||||||||||||||||||||||||||||||||
| 3483 | sensitive or not. This makes a difference when looking up values | - | ||||||||||||||||||||||||||||||||||||
| 3484 | using QSettings. The default is case sensitive. | - | ||||||||||||||||||||||||||||||||||||
| 3485 | - | |||||||||||||||||||||||||||||||||||||
| 3486 | By default, if you use one of the constructors that work in terms | - | ||||||||||||||||||||||||||||||||||||
| 3487 | of an organization name and an application name, the file system | - | ||||||||||||||||||||||||||||||||||||
| 3488 | locations used are the same as for IniFormat. Use setPath() to | - | ||||||||||||||||||||||||||||||||||||
| 3489 | specify other locations. | - | ||||||||||||||||||||||||||||||||||||
| 3490 | - | |||||||||||||||||||||||||||||||||||||
| 3491 | Example: | - | ||||||||||||||||||||||||||||||||||||
| 3492 | - | |||||||||||||||||||||||||||||||||||||
| 3493 | \snippet code/src_corelib_io_qsettings.cpp 29 | - | ||||||||||||||||||||||||||||||||||||
| 3494 | - | |||||||||||||||||||||||||||||||||||||
| 3495 | \sa setPath() | - | ||||||||||||||||||||||||||||||||||||
| 3496 | */ | - | ||||||||||||||||||||||||||||||||||||
| 3497 | QSettings::Format QSettings::registerFormat(const QString &extension, ReadFunc readFunc, | - | ||||||||||||||||||||||||||||||||||||
| 3498 | WriteFunc writeFunc, | - | ||||||||||||||||||||||||||||||||||||
| 3499 | Qt::CaseSensitivity caseSensitivity) | - | ||||||||||||||||||||||||||||||||||||
| 3500 | { | - | ||||||||||||||||||||||||||||||||||||
| 3501 | #ifdef QT_QSETTINGS_ALWAYS_CASE_SENSITIVE_AND_FORGET_ORIGINAL_KEY_ORDER | - | ||||||||||||||||||||||||||||||||||||
| 3502 | Q_ASSERT(caseSensitivity == Qt::CaseSensitive); | - | ||||||||||||||||||||||||||||||||||||
| 3503 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 3504 | - | |||||||||||||||||||||||||||||||||||||
| 3505 | QMutexLocker locker(&settingsGlobalMutex); | - | ||||||||||||||||||||||||||||||||||||
| 3506 | CustomFormatVector *customFormatVector = customFormatVectorFunc(); | - | ||||||||||||||||||||||||||||||||||||
| 3507 | int index = customFormatVector->size(); | - | ||||||||||||||||||||||||||||||||||||
| 3508 | if (index == 16) // the QSettings::Format enum has room for 16 custom formats
| 0-3 | ||||||||||||||||||||||||||||||||||||
| 3509 | return QSettings::InvalidFormat; never executed: return QSettings::InvalidFormat; | 0 | ||||||||||||||||||||||||||||||||||||
| 3510 | - | |||||||||||||||||||||||||||||||||||||
| 3511 | QConfFileCustomFormat info; | - | ||||||||||||||||||||||||||||||||||||
| 3512 | info.extension = QLatin1Char('.'); | - | ||||||||||||||||||||||||||||||||||||
| 3513 | info.extension += extension; | - | ||||||||||||||||||||||||||||||||||||
| 3514 | info.readFunc = readFunc; | - | ||||||||||||||||||||||||||||||||||||
| 3515 | info.writeFunc = writeFunc; | - | ||||||||||||||||||||||||||||||||||||
| 3516 | info.caseSensitivity = caseSensitivity; | - | ||||||||||||||||||||||||||||||||||||
| 3517 | customFormatVector->append(info); | - | ||||||||||||||||||||||||||||||||||||
| 3518 | - | |||||||||||||||||||||||||||||||||||||
| 3519 | return QSettings::Format((int)QSettings::CustomFormat1 + index); executed 3 times by 1 test: return QSettings::Format((int)QSettings::CustomFormat1 + index);Executed by:
| 3 | ||||||||||||||||||||||||||||||||||||
| 3520 | } | - | ||||||||||||||||||||||||||||||||||||
| 3521 | - | |||||||||||||||||||||||||||||||||||||
| 3522 | QT_END_NAMESPACE | - | ||||||||||||||||||||||||||||||||||||
| 3523 | - | |||||||||||||||||||||||||||||||||||||
| 3524 | #endif // QT_NO_SETTINGS | - | ||||||||||||||||||||||||||||||||||||
| Source code | Switch to Preprocessed file |