Line | Source Code | Coverage |
---|
1 | /**************************************************************************** | - |
2 | ** | - |
3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). | - |
4 | ** Contact: http://www.qt-project.org/legal | - |
5 | ** | - |
6 | ** This file is part of the QtCore module of the Qt Toolkit. | - |
7 | ** | - |
8 | ** $QT_BEGIN_LICENSE:LGPL$ | - |
9 | ** Commercial License Usage | - |
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - |
11 | ** accordance with the commercial license agreement provided with the | - |
12 | ** Software or, alternatively, in accordance with the terms contained in | - |
13 | ** a written agreement between you and Digia. For licensing terms and | - |
14 | ** conditions see http://qt.digia.com/licensing. For further information | - |
15 | ** use the contact form at http://qt.digia.com/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 as published by the Free Software | - |
20 | ** Foundation and appearing in the file LICENSE.LGPL included in the | - |
21 | ** packaging of this file. Please review the following information to | - |
22 | ** ensure the GNU Lesser General Public License version 2.1 requirements | - |
23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - |
24 | ** | - |
25 | ** In addition, as a special exception, Digia gives you certain additional | - |
26 | ** rights. These rights are described in the Digia Qt LGPL Exception | - |
27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - |
28 | ** | - |
29 | ** GNU General Public License Usage | - |
30 | ** Alternatively, this file may be used under the terms of the GNU | - |
31 | ** General Public License version 3.0 as published by the Free Software | - |
32 | ** Foundation and appearing in the file LICENSE.GPL included in the | - |
33 | ** packaging of this file. Please review the following information to | - |
34 | ** ensure the GNU General Public License version 3.0 requirements will be | - |
35 | ** met: http://www.gnu.org/copyleft/gpl.html. | - |
36 | ** | - |
37 | ** | - |
38 | ** $QT_END_LICENSE$ | - |
39 | ** | - |
40 | ****************************************************************************/ | - |
41 | | - |
42 | #include <qdebug.h> | - |
43 | #include "qplatformdefs.h" | - |
44 | #include "qsettings.h" | - |
45 | | - |
46 | #ifndef QT_NO_SETTINGS | - |
47 | | - |
48 | #include "qsettings_p.h" | - |
49 | #include "qcache.h" | - |
50 | #include "qfile.h" | - |
51 | #include "qdir.h" | - |
52 | #include "qfileinfo.h" | - |
53 | #include "qmutex.h" | - |
54 | #include "qlibraryinfo.h" | - |
55 | #include "qtemporaryfile.h" | - |
56 | | - |
57 | #ifndef QT_NO_TEXTCODEC | - |
58 | # include "qtextcodec.h" | - |
59 | #endif | - |
60 | | - |
61 | #ifndef QT_NO_GEOM_VARIANT | - |
62 | #include "qsize.h" | - |
63 | #include "qpoint.h" | - |
64 | #include "qrect.h" | - |
65 | #endif // !QT_NO_GEOM_VARIANT | - |
66 | | - |
67 | #ifndef QT_NO_QOBJECT | - |
68 | #include "qcoreapplication.h" | - |
69 | #endif | - |
70 | | - |
71 | #ifdef Q_OS_VXWORKS | - |
72 | # include <ioLib.h> | - |
73 | #endif | - |
74 | | - |
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 | #endif | - |
81 | | - |
82 | #ifndef CSIDL_COMMON_APPDATA | - |
83 | #define CSIDL_COMMON_APPDATA 0x0023 // All Users\Application Data | - |
84 | #endif | - |
85 | | - |
86 | #ifndef CSIDL_APPDATA | - |
87 | #define CSIDL_APPDATA 0x001a // <username>\Application Data | - |
88 | #endif | - |
89 | | - |
90 | #ifdef Q_AUTOTEST_EXPORT | - |
91 | # define Q_AUTOTEST_EXPORT_HELPER Q_AUTOTEST_EXPORT | - |
92 | #else | - |
93 | # define Q_AUTOTEST_EXPORT_HELPER static | - |
94 | #endif | - |
95 | | - |
96 | // ************************************************************************ | - |
97 | // QConfFile | - |
98 | | - |
99 | /* | - |
100 | QConfFile objects are explicitly shared within the application. | - |
101 | This ensures that modification to the settings done through one | - |
102 | QSettings object are immediately reflected in other setting | - |
103 | objects of the same application. | - |
104 | */ | - |
105 | | - |
106 | QT_BEGIN_NAMESPACE | - |
107 | | - |
108 | struct QConfFileCustomFormat | - |
109 | { | - |
110 | QString extension; | - |
111 | QSettings::ReadFunc readFunc; | - |
112 | QSettings::WriteFunc writeFunc; | - |
113 | Qt::CaseSensitivity caseSensitivity; | - |
114 | }; | - |
115 | | - |
116 | typedef QHash<QString, QConfFile *> ConfFileHash; | - |
117 | typedef QCache<QString, QConfFile> ConfFileCache; | - |
118 | typedef QHash<int, QString> PathHash; | - |
119 | typedef QVector<QConfFileCustomFormat> CustomFormatVector; | - |
120 | | - |
121 | Q_GLOBAL_STATIC(ConfFileHash, usedHashFunc) never executed: delete x; executed: return thisGlobalStatic.pointer.load(); Execution Count:5404 partially evaluated: !thisGlobalStatic.pointer.testAndSetOrdered(0, x) no Evaluation Count:0 | yes Evaluation Count:6 |
evaluated: !thisGlobalStatic.pointer.load() yes Evaluation Count:6 | yes Evaluation Count:5398 |
partially evaluated: !thisGlobalStatic.destroyed yes Evaluation Count:6 | no Evaluation Count:0 |
| 0-5404 |
122 | Q_GLOBAL_STATIC(ConfFileCache, unusedCacheFunc) never executed: delete x; executed: return thisGlobalStatic.pointer.load(); Execution Count:2572 partially evaluated: !thisGlobalStatic.pointer.testAndSetOrdered(0, x) no Evaluation Count:0 | yes Evaluation Count:6 |
evaluated: !thisGlobalStatic.pointer.load() yes Evaluation Count:6 | yes Evaluation Count:2566 |
partially evaluated: !thisGlobalStatic.destroyed yes Evaluation Count:6 | no Evaluation Count:0 |
| 0-2572 |
123 | Q_GLOBAL_STATIC(PathHash, pathHashFunc) never executed: delete x; executed: return thisGlobalStatic.pointer.load(); Execution Count:1958 partially evaluated: !thisGlobalStatic.pointer.testAndSetOrdered(0, x) no Evaluation Count:0 | yes Evaluation Count:5 |
evaluated: !thisGlobalStatic.pointer.load() yes Evaluation Count:5 | yes Evaluation Count:1953 |
partially evaluated: !thisGlobalStatic.destroyed yes Evaluation Count:5 | no Evaluation Count:0 |
| 0-1958 |
124 | Q_GLOBAL_STATIC(CustomFormatVector, customFormatVectorFunc) never executed: delete x; executed: return thisGlobalStatic.pointer.load(); Execution Count:93 partially evaluated: !thisGlobalStatic.pointer.testAndSetOrdered(0, x) no Evaluation Count:0 | yes Evaluation Count:1 |
evaluated: !thisGlobalStatic.pointer.load() yes Evaluation Count:1 | yes Evaluation Count:92 |
partially evaluated: !thisGlobalStatic.destroyed yes Evaluation Count:1 | no Evaluation Count:0 |
| 0-93 |
125 | | - |
126 | static QBasicMutex settingsGlobalMutex; | - |
127 | | - |
128 | static QSettings::Format globalDefaultFormat = QSettings::NativeFormat; | - |
129 | | - |
130 | #ifndef Q_OS_WIN | - |
131 | inline bool qt_isEvilFsTypeName(const char *name) | - |
132 | { | - |
133 | return (qstrncmp(name, "nfs", 3) == 0 never executed: return (qstrncmp(name, "nfs", 3) == 0 || qstrncmp(name, "autofs", 6) == 0 || qstrncmp(name, "cachefs", 7) == 0); | 0 |
134 | || qstrncmp(name, "autofs", 6) == 0 never executed: return (qstrncmp(name, "nfs", 3) == 0 || qstrncmp(name, "autofs", 6) == 0 || qstrncmp(name, "cachefs", 7) == 0); | 0 |
135 | || qstrncmp(name, "cachefs", 7) == 0); never executed: return (qstrncmp(name, "nfs", 3) == 0 || qstrncmp(name, "autofs", 6) == 0 || qstrncmp(name, "cachefs", 7) == 0); | 0 |
136 | } | - |
137 | | - |
138 | #if defined(Q_OS_BSD4) && !defined(Q_OS_NETBSD) | - |
139 | QT_BEGIN_INCLUDE_NAMESPACE | - |
140 | # include <sys/param.h> | - |
141 | # include <sys/mount.h> | - |
142 | QT_END_INCLUDE_NAMESPACE | - |
143 | | - |
144 | Q_AUTOTEST_EXPORT_HELPER bool qIsLikelyToBeNfs(int handle) | - |
145 | { | - |
146 | struct statfs buf; | - |
147 | if (fstatfs(handle, &buf) != 0) | - |
148 | return false; | - |
149 | return qt_isEvilFsTypeName(buf.f_fstypename); | - |
150 | } | - |
151 | | - |
152 | #elif defined(Q_OS_LINUX) || defined(Q_OS_HURD) | - |
153 | QT_BEGIN_INCLUDE_NAMESPACE | - |
154 | # include <sys/vfs.h> | - |
155 | # ifdef QT_LINUXBASE | - |
156 | // LSB 3.2 has fstatfs in sys/statfs.h, sys/vfs.h is just an empty dummy header | - |
157 | # include <sys/statfs.h> | - |
158 | # endif | - |
159 | QT_END_INCLUDE_NAMESPACE | - |
160 | # ifndef NFS_SUPER_MAGIC | - |
161 | # define NFS_SUPER_MAGIC 0x00006969 | - |
162 | # endif | - |
163 | # ifndef AUTOFS_SUPER_MAGIC | - |
164 | # define AUTOFS_SUPER_MAGIC 0x00000187 | - |
165 | # endif | - |
166 | # ifndef AUTOFSNG_SUPER_MAGIC | - |
167 | # define AUTOFSNG_SUPER_MAGIC 0x7d92b1a0 | - |
168 | # endif | - |
169 | | - |
170 | Q_AUTOTEST_EXPORT_HELPER bool qIsLikelyToBeNfs(int handle) | - |
171 | { | - |
172 | struct statfs buf; executed (the execution status of this line is deduced): struct statfs buf; | - |
173 | if (fstatfs(handle, &buf) != 0) evaluated: fstatfs(handle, &buf) != 0 yes Evaluation Count:5 | yes Evaluation Count:944 |
| 5-944 |
174 | return false; executed: return false; Execution Count:5 | 5 |
175 | return buf.f_type == NFS_SUPER_MAGIC executed: return buf.f_type == 0x00006969 || buf.f_type == 0x00000187 || buf.f_type == 0x7d92b1a0; Execution Count:944 | 944 |
176 | || buf.f_type == AUTOFS_SUPER_MAGIC executed: return buf.f_type == 0x00006969 || buf.f_type == 0x00000187 || buf.f_type == 0x7d92b1a0; Execution Count:944 | 944 |
177 | || buf.f_type == AUTOFSNG_SUPER_MAGIC; executed: return buf.f_type == 0x00006969 || buf.f_type == 0x00000187 || buf.f_type == 0x7d92b1a0; Execution Count:944 | 944 |
178 | } | - |
179 | | - |
180 | #elif defined(Q_OS_SOLARIS) || defined(Q_OS_IRIX) || defined(Q_OS_AIX) || defined(Q_OS_HPUX) \ | - |
181 | || defined(Q_OS_OSF) || defined(Q_OS_QNX) || defined(Q_OS_SCO) \ | - |
182 | || defined(Q_OS_UNIXWARE) || defined(Q_OS_RELIANT) || defined(Q_OS_NETBSD) | - |
183 | QT_BEGIN_INCLUDE_NAMESPACE | - |
184 | # include <sys/statvfs.h> | - |
185 | QT_END_INCLUDE_NAMESPACE | - |
186 | | - |
187 | Q_AUTOTEST_EXPORT_HELPER bool qIsLikelyToBeNfs(int handle) | - |
188 | { | - |
189 | struct statvfs buf; | - |
190 | if (fstatvfs(handle, &buf) != 0) | - |
191 | return false; | - |
192 | #if defined(Q_OS_NETBSD) | - |
193 | return qt_isEvilFsTypeName(buf.f_fstypename); | - |
194 | #else | - |
195 | return qt_isEvilFsTypeName(buf.f_basetype); | - |
196 | #endif | - |
197 | } | - |
198 | #else | - |
199 | Q_AUTOTEST_EXPORT_HELPER inline bool qIsLikelyToBeNfs(int /* handle */) | - |
200 | { | - |
201 | return true; | - |
202 | } | - |
203 | #endif | - |
204 | | - |
205 | static bool unixLock(int handle, int lockType) | - |
206 | { | - |
207 | /* | - |
208 | NFS hangs on the fcntl() call below when statd or lockd isn't | - |
209 | running. There's no way to detect this. Our work-around for | - |
210 | now is to disable locking when we detect NFS (or AutoFS or | - |
211 | CacheFS, which are probably wrapping NFS). | - |
212 | */ | - |
213 | if (qIsLikelyToBeNfs(handle)) partially evaluated: qIsLikelyToBeNfs(handle) no Evaluation Count:0 | yes Evaluation Count:949 |
| 0-949 |
214 | return false; never executed: return false; | 0 |
215 | | - |
216 | struct flock fl; executed (the execution status of this line is deduced): struct flock fl; | - |
217 | fl.l_whence = SEEK_SET; executed (the execution status of this line is deduced): fl.l_whence = 0; | - |
218 | fl.l_start = 0; executed (the execution status of this line is deduced): fl.l_start = 0; | - |
219 | fl.l_len = 0; executed (the execution status of this line is deduced): fl.l_len = 0; | - |
220 | fl.l_type = lockType; executed (the execution status of this line is deduced): fl.l_type = lockType; | - |
221 | return fcntl(handle, F_SETLKW, &fl) == 0; executed: return fcntl(handle, 7, &fl) == 0; Execution Count:949 | 949 |
222 | } | - |
223 | #endif | - |
224 | | - |
225 | QConfFile::QConfFile(const QString &fileName, bool _userPerms) | - |
226 | : name(fileName), size(0), ref(1), userPerms(_userPerms) | - |
227 | { | - |
228 | usedHashFunc()->insert(name, this); executed (the execution status of this line is deduced): usedHashFunc()->insert(name, this); | - |
229 | } executed: } Execution Count:944 | 944 |
230 | | - |
231 | QConfFile::~QConfFile() | - |
232 | { | - |
233 | if (usedHashFunc()) partially evaluated: usedHashFunc() yes Evaluation Count:944 | no Evaluation Count:0 |
| 0-944 |
234 | usedHashFunc()->remove(name); executed: usedHashFunc()->remove(name); Execution Count:944 | 944 |
235 | } executed: } Execution Count:944 | 944 |
236 | | - |
237 | ParsedSettingsMap QConfFile::mergedKeyMap() const | - |
238 | { | - |
239 | ParsedSettingsMap result = originalKeys; executed (the execution status of this line is deduced): ParsedSettingsMap result = originalKeys; | - |
240 | ParsedSettingsMap::const_iterator i; executed (the execution status of this line is deduced): ParsedSettingsMap::const_iterator i; | - |
241 | | - |
242 | for (i = removedKeys.begin(); i != removedKeys.end(); ++i) evaluated: i != removedKeys.end() yes Evaluation Count:134 | yes Evaluation Count:495 |
| 134-495 |
243 | result.remove(i.key()); executed: result.remove(i.key()); Execution Count:134 | 134 |
244 | for (i = addedKeys.begin(); i != addedKeys.end(); ++i) evaluated: i != addedKeys.end() yes Evaluation Count:770 | yes Evaluation Count:495 |
| 495-770 |
245 | result.insert(i.key(), i.value()); executed: result.insert(i.key(), i.value()); Execution Count:770 | 770 |
246 | return result; executed: return result; Execution Count:495 | 495 |
247 | } | - |
248 | | - |
249 | bool QConfFile::isWritable() const | - |
250 | { | - |
251 | QFileInfo fileInfo(name); executed (the execution status of this line is deduced): QFileInfo fileInfo(name); | - |
252 | | - |
253 | #ifndef QT_NO_TEMPORARYFILE | - |
254 | if (fileInfo.exists()) { evaluated: fileInfo.exists() yes Evaluation Count:417 | yes Evaluation Count:98 |
| 98-417 |
255 | #endif | - |
256 | QFile file(name); executed (the execution status of this line is deduced): QFile file(name); | - |
257 | return file.open(QFile::ReadWrite); executed: return file.open(QFile::ReadWrite); Execution Count:417 | 417 |
258 | #ifndef QT_NO_TEMPORARYFILE | - |
259 | } else { | - |
260 | // Create the directories to the file. | - |
261 | QDir dir(fileInfo.absolutePath()); executed (the execution status of this line is deduced): QDir dir(fileInfo.absolutePath()); | - |
262 | if (!dir.exists()) { evaluated: !dir.exists() yes Evaluation Count:75 | yes Evaluation Count:23 |
| 23-75 |
263 | if (!dir.mkpath(dir.absolutePath())) partially evaluated: !dir.mkpath(dir.absolutePath()) no Evaluation Count:0 | yes Evaluation Count:75 |
| 0-75 |
264 | return false; never executed: return false; | 0 |
265 | } executed: } Execution Count:75 | 75 |
266 | | - |
267 | // we use a temporary file to avoid race conditions | - |
268 | QTemporaryFile file(name); executed (the execution status of this line is deduced): QTemporaryFile file(name); | - |
269 | return file.open(); executed: return file.open(); Execution Count:98 | 98 |
270 | } | - |
271 | #endif | - |
272 | } | - |
273 | | - |
274 | QConfFile *QConfFile::fromName(const QString &fileName, bool _userPerms) | - |
275 | { | - |
276 | QString absPath = QFileInfo(fileName).absoluteFilePath(); executed (the execution status of this line is deduced): QString absPath = QFileInfo(fileName).absoluteFilePath(); | - |
277 | | - |
278 | ConfFileHash *usedHash = usedHashFunc(); executed (the execution status of this line is deduced): ConfFileHash *usedHash = usedHashFunc(); | - |
279 | ConfFileCache *unusedCache = unusedCacheFunc(); executed (the execution status of this line is deduced): ConfFileCache *unusedCache = unusedCacheFunc(); | - |
280 | | - |
281 | QConfFile *confFile = 0; executed (the execution status of this line is deduced): QConfFile *confFile = 0; | - |
282 | QMutexLocker locker(&settingsGlobalMutex); executed (the execution status of this line is deduced): QMutexLocker locker(&settingsGlobalMutex); | - |
283 | | - |
284 | if (!(confFile = usedHash->value(absPath))) { evaluated: !(confFile = usedHash->value(absPath)) yes Evaluation Count:1220 | yes Evaluation Count:551 |
| 551-1220 |
285 | if ((confFile = unusedCache->take(absPath))) evaluated: (confFile = unusedCache->take(absPath)) yes Evaluation Count:276 | yes Evaluation Count:944 |
| 276-944 |
286 | usedHash->insert(absPath, confFile); executed: usedHash->insert(absPath, confFile); Execution Count:276 | 276 |
287 | } executed: } Execution Count:1220 | 1220 |
288 | if (confFile) { evaluated: confFile yes Evaluation Count:827 | yes Evaluation Count:944 |
| 827-944 |
289 | confFile->ref.ref(); executed (the execution status of this line is deduced): confFile->ref.ref(); | - |
290 | return confFile; executed: return confFile; Execution Count:827 | 827 |
291 | } | - |
292 | return new QConfFile(absPath, _userPerms); executed: return new QConfFile(absPath, _userPerms); Execution Count:944 | 944 |
293 | } | - |
294 | | - |
295 | void QConfFile::clearCache() | - |
296 | { | - |
297 | QMutexLocker locker(&settingsGlobalMutex); never executed (the execution status of this line is deduced): QMutexLocker locker(&settingsGlobalMutex); | - |
298 | unusedCacheFunc()->clear(); never executed (the execution status of this line is deduced): unusedCacheFunc()->clear(); | - |
299 | } | 0 |
300 | | - |
301 | // ************************************************************************ | - |
302 | // QSettingsPrivate | - |
303 | | - |
304 | QSettingsPrivate::QSettingsPrivate(QSettings::Format format) | - |
305 | : format(format), scope(QSettings::UserScope /* nothing better to put */), iniCodec(0), spec(0), fallbacks(true), | - |
306 | pendingChanges(false), status(QSettings::NoError) | - |
307 | { | - |
308 | } executed: } Execution Count:44 | 44 |
309 | | - |
310 | QSettingsPrivate::QSettingsPrivate(QSettings::Format format, QSettings::Scope scope, | - |
311 | const QString &organization, const QString &application) | - |
312 | : format(format), scope(scope), organizationName(organization), applicationName(application), | - |
313 | iniCodec(0), spec(0), fallbacks(true), pendingChanges(false), status(QSettings::NoError) | - |
314 | { | - |
315 | } executed: } Execution Count:758 | 758 |
316 | | - |
317 | QSettingsPrivate::~QSettingsPrivate() | - |
318 | { | - |
319 | } | - |
320 | | - |
321 | QString QSettingsPrivate::actualKey(const QString &key) const | - |
322 | { | - |
323 | QString n = normalizedKey(key); executed (the execution status of this line is deduced): QString n = normalizedKey(key); | - |
324 | Q_ASSERT_X(!n.isEmpty(), "QSettings", "empty key"); executed (the execution status of this line is deduced): qt_noop(); | - |
325 | n.prepend(groupPrefix); executed (the execution status of this line is deduced): n.prepend(groupPrefix); | - |
326 | return n; executed: return n; Execution Count:3566 | 3566 |
327 | } | - |
328 | | - |
329 | /* | - |
330 | Returns a string that never starts nor ends with a slash (or an | - |
331 | empty string). Examples: | - |
332 | | - |
333 | "foo" becomes "foo" | - |
334 | "/foo//bar///" becomes "foo/bar" | - |
335 | "///" becomes "" | - |
336 | | - |
337 | This function is optimized to avoid a QString deep copy in the | - |
338 | common case where the key is already normalized. | - |
339 | */ | - |
340 | QString QSettingsPrivate::normalizedKey(const QString &key) | - |
341 | { | - |
342 | QString result = key; executed (the execution status of this line is deduced): QString result = key; | - |
343 | | - |
344 | int i = 0; executed (the execution status of this line is deduced): int i = 0; | - |
345 | while (i < result.size()) { evaluated: i < result.size() yes Evaluation Count:8424 | yes Evaluation Count:10 |
| 10-8424 |
346 | while (result.at(i) == QLatin1Char('/')) { evaluated: result.at(i) == QLatin1Char('/') yes Evaluation Count:181 | yes Evaluation Count:8412 |
| 181-8412 |
347 | result.remove(i, 1); executed (the execution status of this line is deduced): result.remove(i, 1); | - |
348 | if (i == result.size()) evaluated: i == result.size() yes Evaluation Count:12 | yes Evaluation Count:169 |
| 12-169 |
349 | goto after_loop; executed: goto after_loop; Execution Count:12 | 12 |
350 | } executed: } Execution Count:169 | 169 |
351 | while (result.at(i) != QLatin1Char('/')) { evaluated: result.at(i) != QLatin1Char('/') yes Evaluation Count:48349 | yes Evaluation Count:4078 |
| 4078-48349 |
352 | ++i; executed (the execution status of this line is deduced): ++i; | - |
353 | if (i == result.size()) evaluated: i == result.size() yes Evaluation Count:4334 | yes Evaluation Count:44015 |
| 4334-44015 |
354 | return result; executed: return result; Execution Count:4334 | 4334 |
355 | } executed: } Execution Count:44015 | 44015 |
356 | ++i; // leave the slash alone executed (the execution status of this line is deduced): ++i; | - |
357 | } executed: } Execution Count:4078 | 4078 |
358 | | - |
359 | after_loop: code before this statement executed: after_loop: Execution Count:10 | 10 |
360 | if (!result.isEmpty()) evaluated: !result.isEmpty() yes Evaluation Count:12 | yes Evaluation Count:10 |
| 10-12 |
361 | result.truncate(i - 1); // remove the trailing slash executed: result.truncate(i - 1); Execution Count:12 | 12 |
362 | return result; executed: return result; Execution Count:22 | 22 |
363 | } | - |
364 | | - |
365 | // see also qsettings_win.cpp and qsettings_mac.cpp | - |
366 | | - |
367 | #if !defined(Q_OS_WIN) && !defined(Q_OS_MAC) | - |
368 | QSettingsPrivate *QSettingsPrivate::create(QSettings::Format format, QSettings::Scope scope, | - |
369 | const QString &organization, const QString &application) | - |
370 | { | - |
371 | return new QConfFileSettingsPrivate(format, scope, organization, application); executed: return new QConfFileSettingsPrivate(format, scope, organization, application); Execution Count:758 | 758 |
372 | } | - |
373 | #endif | - |
374 | | - |
375 | #if !defined(Q_OS_WIN) | - |
376 | QSettingsPrivate *QSettingsPrivate::create(const QString &fileName, QSettings::Format format) | - |
377 | { | - |
378 | return new QConfFileSettingsPrivate(fileName, format); executed: return new QConfFileSettingsPrivate(fileName, format); Execution Count:44 | 44 |
379 | } | - |
380 | #endif | - |
381 | | - |
382 | void QSettingsPrivate::processChild(QString key, ChildSpec spec, QMap<QString, QString> &result) | - |
383 | { | - |
384 | if (spec != AllKeys) { evaluated: spec != AllKeys yes Evaluation Count:208 | yes Evaluation Count:1349 |
| 208-1349 |
385 | int slashPos = key.indexOf(QLatin1Char('/')); executed (the execution status of this line is deduced): int slashPos = key.indexOf(QLatin1Char('/')); | - |
386 | if (slashPos == -1) { evaluated: slashPos == -1 yes Evaluation Count:40 | yes Evaluation Count:168 |
| 40-168 |
387 | if (spec != ChildKeys) evaluated: spec != ChildKeys yes Evaluation Count:20 | yes Evaluation Count:20 |
| 20 |
388 | return; executed: return; Execution Count:20 | 20 |
389 | } else { executed: } Execution Count:20 | 20 |
390 | if (spec != ChildGroups) evaluated: spec != ChildGroups yes Evaluation Count:64 | yes Evaluation Count:104 |
| 64-104 |
391 | return; executed: return; Execution Count:64 | 64 |
392 | key.truncate(slashPos); executed (the execution status of this line is deduced): key.truncate(slashPos); | - |
393 | } executed: } Execution Count:104 | 104 |
394 | } | - |
395 | result.insert(key, QString()); executed (the execution status of this line is deduced): result.insert(key, QString()); | - |
396 | } executed: } Execution Count:1473 | 1473 |
397 | | - |
398 | void QSettingsPrivate::beginGroupOrArray(const QSettingsGroup &group) | - |
399 | { | - |
400 | groupStack.push(group); executed (the execution status of this line is deduced): groupStack.push(group); | - |
401 | if (!group.name().isEmpty()) { evaluated: !group.name().isEmpty() yes Evaluation Count:657 | yes Evaluation Count:7 |
| 7-657 |
402 | groupPrefix += group.name(); executed (the execution status of this line is deduced): groupPrefix += group.name(); | - |
403 | groupPrefix += QLatin1Char('/'); executed (the execution status of this line is deduced): groupPrefix += QLatin1Char('/'); | - |
404 | } executed: } Execution Count:657 | 657 |
405 | } executed: } Execution Count:664 | 664 |
406 | | - |
407 | /* | - |
408 | We only set an error if there isn't one set already. This way the user always gets the | - |
409 | first error that occurred. We always allow clearing errors. | - |
410 | */ | - |
411 | | - |
412 | void QSettingsPrivate::setStatus(QSettings::Status status) const | - |
413 | { | - |
414 | if (status == QSettings::NoError || this->status == QSettings::NoError) partially evaluated: status == QSettings::NoError no Evaluation Count:0 | yes Evaluation Count:15 |
evaluated: this->status == QSettings::NoError yes Evaluation Count:13 | yes Evaluation Count:2 |
| 0-15 |
415 | this->status = status; executed: this->status = status; Execution Count:13 | 13 |
416 | } executed: } Execution Count:15 | 15 |
417 | | - |
418 | void QSettingsPrivate::update() | - |
419 | { | - |
420 | flush(); executed (the execution status of this line is deduced): flush(); | - |
421 | pendingChanges = false; executed (the execution status of this line is deduced): pendingChanges = false; | - |
422 | } executed: } Execution Count:4 | 4 |
423 | | - |
424 | void QSettingsPrivate::requestUpdate() | - |
425 | { | - |
426 | if (!pendingChanges) { evaluated: !pendingChanges yes Evaluation Count:495 | yes Evaluation Count:479 |
| 479-495 |
427 | pendingChanges = true; executed (the execution status of this line is deduced): pendingChanges = true; | - |
428 | #ifndef QT_NO_QOBJECT | - |
429 | Q_Q(QSettings); executed (the execution status of this line is deduced): QSettings * const q = q_func(); | - |
430 | QCoreApplication::postEvent(q, new QEvent(QEvent::UpdateRequest)); executed (the execution status of this line is deduced): QCoreApplication::postEvent(q, new QEvent(QEvent::UpdateRequest)); | - |
431 | #else | - |
432 | update(); | - |
433 | #endif | - |
434 | } executed: } Execution Count:495 | 495 |
435 | } executed: } Execution Count:974 | 974 |
436 | | - |
437 | QStringList QSettingsPrivate::variantListToStringList(const QVariantList &l) | - |
438 | { | - |
439 | QStringList result; executed (the execution status of this line is deduced): QStringList result; | - |
440 | QVariantList::const_iterator it = l.constBegin(); executed (the execution status of this line is deduced): QVariantList::const_iterator it = l.constBegin(); | - |
441 | for (; it != l.constEnd(); ++it) evaluated: it != l.constEnd() yes Evaluation Count:34 | yes Evaluation Count:16 |
| 16-34 |
442 | result.append(variantToString(*it)); executed: result.append(variantToString(*it)); Execution Count:34 | 34 |
443 | return result; executed: return result; Execution Count:16 | 16 |
444 | } | - |
445 | | - |
446 | QVariant QSettingsPrivate::stringListToVariantList(const QStringList &l) | - |
447 | { | - |
448 | QStringList outStringList = l; executed (the execution status of this line is deduced): QStringList outStringList = l; | - |
449 | for (int i = 0; i < outStringList.count(); ++i) { evaluated: i < outStringList.count() yes Evaluation Count:254 | yes Evaluation Count:21 |
| 21-254 |
450 | const QString &str = outStringList.at(i); executed (the execution status of this line is deduced): const QString &str = outStringList.at(i); | - |
451 | | - |
452 | if (str.startsWith(QLatin1Char('@'))) { partially evaluated: str.startsWith(QLatin1Char('@')) no Evaluation Count:0 | yes Evaluation Count:254 |
| 0-254 |
453 | if (str.length() >= 2 && str.at(1) == QLatin1Char('@')) { never evaluated: str.length() >= 2 never evaluated: str.at(1) == QLatin1Char('@') | 0 |
454 | outStringList[i].remove(0, 1); never executed (the execution status of this line is deduced): outStringList[i].remove(0, 1); | - |
455 | } else { | 0 |
456 | QVariantList variantList; never executed (the execution status of this line is deduced): QVariantList variantList; | - |
457 | for (int j = 0; j < l.count(); ++j) never evaluated: j < l.count() | 0 |
458 | variantList.append(stringToVariant(l.at(j))); never executed: variantList.append(stringToVariant(l.at(j))); | 0 |
459 | return variantList; never executed: return variantList; | 0 |
460 | } | - |
461 | } | - |
462 | } executed: } Execution Count:254 | 254 |
463 | return outStringList; executed: return outStringList; Execution Count:21 | 21 |
464 | } | - |
465 | | - |
466 | QString QSettingsPrivate::variantToString(const QVariant &v) | - |
467 | { | - |
468 | QString result; executed (the execution status of this line is deduced): QString result; | - |
469 | | - |
470 | switch (v.type()) { | - |
471 | case QVariant::Invalid: | - |
472 | result = QLatin1String("@Invalid()"); never executed (the execution status of this line is deduced): result = QLatin1String("@Invalid()"); | - |
473 | break; | 0 |
474 | | - |
475 | case QVariant::ByteArray: { | - |
476 | QByteArray a = v.toByteArray(); executed (the execution status of this line is deduced): QByteArray a = v.toByteArray(); | - |
477 | result = QLatin1String("@ByteArray("); executed (the execution status of this line is deduced): result = QLatin1String("@ByteArray("); | - |
478 | result += QString::fromLatin1(a.constData(), a.size()); executed (the execution status of this line is deduced): result += QString::fromLatin1(a.constData(), a.size()); | - |
479 | result += QLatin1Char(')'); executed (the execution status of this line is deduced): result += QLatin1Char(')'); | - |
480 | break; executed: break; Execution Count:279 | 279 |
481 | } | - |
482 | | - |
483 | case QVariant::String: | - |
484 | case QVariant::LongLong: | - |
485 | case QVariant::ULongLong: | - |
486 | case QVariant::Int: | - |
487 | case QVariant::UInt: | - |
488 | case QVariant::Bool: | - |
489 | case QVariant::Double: | - |
490 | case QVariant::KeySequence: { | - |
491 | result = v.toString(); executed (the execution status of this line is deduced): result = v.toString(); | - |
492 | if (result.startsWith(QLatin1Char('@'))) partially evaluated: result.startsWith(QLatin1Char('@')) no Evaluation Count:0 | yes Evaluation Count:6239 |
| 0-6239 |
493 | result.prepend(QLatin1Char('@')); never executed: result.prepend(QLatin1Char('@')); | 0 |
494 | break; executed: break; Execution Count:6239 | 6239 |
495 | } | - |
496 | #ifndef QT_NO_GEOM_VARIANT | - |
497 | case QVariant::Rect: { | - |
498 | QRect r = qvariant_cast<QRect>(v); never executed (the execution status of this line is deduced): QRect r = qvariant_cast<QRect>(v); | - |
499 | result += QLatin1String("@Rect("); never executed (the execution status of this line is deduced): result += QLatin1String("@Rect("); | - |
500 | result += QString::number(r.x()); never executed (the execution status of this line is deduced): result += QString::number(r.x()); | - |
501 | result += QLatin1Char(' '); never executed (the execution status of this line is deduced): result += QLatin1Char(' '); | - |
502 | result += QString::number(r.y()); never executed (the execution status of this line is deduced): result += QString::number(r.y()); | - |
503 | result += QLatin1Char(' '); never executed (the execution status of this line is deduced): result += QLatin1Char(' '); | - |
504 | result += QString::number(r.width()); never executed (the execution status of this line is deduced): result += QString::number(r.width()); | - |
505 | result += QLatin1Char(' '); never executed (the execution status of this line is deduced): result += QLatin1Char(' '); | - |
506 | result += QString::number(r.height()); never executed (the execution status of this line is deduced): result += QString::number(r.height()); | - |
507 | result += QLatin1Char(')'); never executed (the execution status of this line is deduced): result += QLatin1Char(')'); | - |
508 | break; | 0 |
509 | } | - |
510 | case QVariant::Size: { | - |
511 | QSize s = qvariant_cast<QSize>(v); never executed (the execution status of this line is deduced): QSize s = qvariant_cast<QSize>(v); | - |
512 | result += QLatin1String("@Size("); never executed (the execution status of this line is deduced): result += QLatin1String("@Size("); | - |
513 | result += QString::number(s.width()); never executed (the execution status of this line is deduced): result += QString::number(s.width()); | - |
514 | result += QLatin1Char(' '); never executed (the execution status of this line is deduced): result += QLatin1Char(' '); | - |
515 | result += QString::number(s.height()); never executed (the execution status of this line is deduced): result += QString::number(s.height()); | - |
516 | result += QLatin1Char(')'); never executed (the execution status of this line is deduced): result += QLatin1Char(')'); | - |
517 | break; | 0 |
518 | } | - |
519 | case QVariant::Point: { | - |
520 | QPoint p = qvariant_cast<QPoint>(v); never executed (the execution status of this line is deduced): QPoint p = qvariant_cast<QPoint>(v); | - |
521 | result += QLatin1String("@Point("); never executed (the execution status of this line is deduced): result += QLatin1String("@Point("); | - |
522 | result += QString::number(p.x()); never executed (the execution status of this line is deduced): result += QString::number(p.x()); | - |
523 | result += QLatin1Char(' '); never executed (the execution status of this line is deduced): result += QLatin1Char(' '); | - |
524 | result += QString::number(p.y()); never executed (the execution status of this line is deduced): result += QString::number(p.y()); | - |
525 | result += QLatin1Char(')'); never executed (the execution status of this line is deduced): result += QLatin1Char(')'); | - |
526 | break; | 0 |
527 | } | - |
528 | #endif // !QT_NO_GEOM_VARIANT | - |
529 | | - |
530 | default: { | - |
531 | #ifndef QT_NO_DATASTREAM | - |
532 | QByteArray a; executed (the execution status of this line is deduced): QByteArray a; | - |
533 | { | - |
534 | QDataStream s(&a, QIODevice::WriteOnly); executed (the execution status of this line is deduced): QDataStream s(&a, QIODevice::WriteOnly); | - |
535 | s.setVersion(QDataStream::Qt_4_0); executed (the execution status of this line is deduced): s.setVersion(QDataStream::Qt_4_0); | - |
536 | s << v; executed (the execution status of this line is deduced): s << v; | - |
537 | } | - |
538 | | - |
539 | result = QLatin1String("@Variant("); executed (the execution status of this line is deduced): result = QLatin1String("@Variant("); | - |
540 | result += QString::fromLatin1(a.constData(), a.size()); executed (the execution status of this line is deduced): result += QString::fromLatin1(a.constData(), a.size()); | - |
541 | result += QLatin1Char(')'); executed (the execution status of this line is deduced): result += QLatin1Char(')'); | - |
542 | #else | - |
543 | Q_ASSERT(!"QSettings: Cannot save custom types without QDataStream support"); | - |
544 | #endif | - |
545 | break; executed: break; Execution Count:9 | 9 |
546 | } | - |
547 | } | - |
548 | | - |
549 | return result; executed: return result; Execution Count:6527 | 6527 |
550 | } | - |
551 | | - |
552 | | - |
553 | QVariant QSettingsPrivate::stringToVariant(const QString &s) | - |
554 | { | - |
555 | if (s.startsWith(QLatin1Char('@'))) { evaluated: s.startsWith(QLatin1Char('@')) yes Evaluation Count:287 | yes Evaluation Count:6697 |
| 287-6697 |
556 | if (s.endsWith(QLatin1Char(')'))) { partially evaluated: s.endsWith(QLatin1Char(')')) yes Evaluation Count:287 | no Evaluation Count:0 |
| 0-287 |
557 | if (s.startsWith(QLatin1String("@ByteArray("))) { evaluated: s.startsWith(QLatin1String("@ByteArray(")) yes Evaluation Count:279 | yes Evaluation Count:8 |
| 8-279 |
558 | return QVariant(s.toLatin1().mid(11, s.size() - 12)); executed: return QVariant(s.toLatin1().mid(11, s.size() - 12)); Execution Count:279 | 279 |
559 | } else if (s.startsWith(QLatin1String("@Variant("))) { evaluated: s.startsWith(QLatin1String("@Variant(")) yes Evaluation Count:4 | yes Evaluation Count:4 |
| 4 |
560 | #ifndef QT_NO_DATASTREAM | - |
561 | QByteArray a(s.toLatin1().mid(9)); executed (the execution status of this line is deduced): QByteArray a(s.toLatin1().mid(9)); | - |
562 | QDataStream stream(&a, QIODevice::ReadOnly); executed (the execution status of this line is deduced): QDataStream stream(&a, QIODevice::ReadOnly); | - |
563 | stream.setVersion(QDataStream::Qt_4_0); executed (the execution status of this line is deduced): stream.setVersion(QDataStream::Qt_4_0); | - |
564 | QVariant result; executed (the execution status of this line is deduced): QVariant result; | - |
565 | stream >> result; executed (the execution status of this line is deduced): stream >> result; | - |
566 | return result; executed: return result; Execution Count:4 | 4 |
567 | #else | - |
568 | Q_ASSERT(!"QSettings: Cannot load custom types without QDataStream support"); | - |
569 | #endif | - |
570 | #ifndef QT_NO_GEOM_VARIANT | - |
571 | } else if (s.startsWith(QLatin1String("@Rect("))) { partially evaluated: s.startsWith(QLatin1String("@Rect(")) no Evaluation Count:0 | yes Evaluation Count:4 |
| 0-4 |
572 | QStringList args = QSettingsPrivate::splitArgs(s, 5); never executed (the execution status of this line is deduced): QStringList args = QSettingsPrivate::splitArgs(s, 5); | - |
573 | if (args.size() == 4) never evaluated: args.size() == 4 | 0 |
574 | return QVariant(QRect(args[0].toInt(), args[1].toInt(), args[2].toInt(), args[3].toInt())); never executed: return QVariant(QRect(args[0].toInt(), args[1].toInt(), args[2].toInt(), args[3].toInt())); | 0 |
575 | } else if (s.startsWith(QLatin1String("@Size("))) { never executed: } partially evaluated: s.startsWith(QLatin1String("@Size(")) no Evaluation Count:0 | yes Evaluation Count:4 |
| 0-4 |
576 | QStringList args = QSettingsPrivate::splitArgs(s, 5); never executed (the execution status of this line is deduced): QStringList args = QSettingsPrivate::splitArgs(s, 5); | - |
577 | if (args.size() == 2) never evaluated: args.size() == 2 | 0 |
578 | return QVariant(QSize(args[0].toInt(), args[1].toInt())); never executed: return QVariant(QSize(args[0].toInt(), args[1].toInt())); | 0 |
579 | } else if (s.startsWith(QLatin1String("@Point("))) { never executed: } partially evaluated: s.startsWith(QLatin1String("@Point(")) no Evaluation Count:0 | yes Evaluation Count:4 |
| 0-4 |
580 | QStringList args = QSettingsPrivate::splitArgs(s, 6); never executed (the execution status of this line is deduced): QStringList args = QSettingsPrivate::splitArgs(s, 6); | - |
581 | if (args.size() == 2) never evaluated: args.size() == 2 | 0 |
582 | return QVariant(QPoint(args[0].toInt(), args[1].toInt())); never executed: return QVariant(QPoint(args[0].toInt(), args[1].toInt())); | 0 |
583 | #endif | - |
584 | } else if (s == QLatin1String("@Invalid()")) { never executed: } partially evaluated: s == QLatin1String("@Invalid()") yes Evaluation Count:4 | no Evaluation Count:0 |
| 0-4 |
585 | return QVariant(); executed: return QVariant(); Execution Count:4 | 4 |
586 | } | - |
587 | | - |
588 | } | - |
589 | if (s.startsWith(QLatin1String("@@"))) never evaluated: s.startsWith(QLatin1String("@@")) | 0 |
590 | return QVariant(s.mid(1)); never executed: return QVariant(s.mid(1)); | 0 |
591 | } | 0 |
592 | | - |
593 | return QVariant(s); executed: return QVariant(s); Execution Count:6697 | 6697 |
594 | } | - |
595 | | - |
596 | static const char hexDigits[] = "0123456789ABCDEF"; | - |
597 | | - |
598 | void QSettingsPrivate::iniEscapedKey(const QString &key, QByteArray &result) | - |
599 | { | - |
600 | result.reserve(result.length() + key.length() * 3 / 2); executed (the execution status of this line is deduced): result.reserve(result.length() + key.length() * 3 / 2); | - |
601 | for (int i = 0; i < key.size(); ++i) { evaluated: i < key.size() yes Evaluation Count:89997 | yes Evaluation Count:6972 |
| 6972-89997 |
602 | uint ch = key.at(i).unicode(); executed (the execution status of this line is deduced): uint ch = key.at(i).unicode(); | - |
603 | | - |
604 | if (ch == '/') { evaluated: ch == '/' yes Evaluation Count:6027 | yes Evaluation Count:83970 |
| 6027-83970 |
605 | result += '\\'; executed (the execution status of this line is deduced): result += '\\'; | - |
606 | } else if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9') executed: } Execution Count:6027 evaluated: ch >= 'a' yes Evaluation Count:69357 | yes Evaluation Count:14613 |
partially evaluated: ch <= 'z' yes Evaluation Count:69357 | no Evaluation Count:0 |
evaluated: ch >= 'A' yes Evaluation Count:6201 | yes Evaluation Count:8412 |
partially evaluated: ch <= 'Z' yes Evaluation Count:6201 | no Evaluation Count:0 |
evaluated: ch >= '0' yes Evaluation Count:8338 | yes Evaluation Count:74 |
partially evaluated: ch <= '9' yes Evaluation Count:8338 | no Evaluation Count:0 |
| 0-69357 |
607 | || ch == '_' || ch == '-' || ch == '.') { partially evaluated: ch == '_' no Evaluation Count:0 | yes Evaluation Count:74 |
partially evaluated: ch == '-' no Evaluation Count:0 | yes Evaluation Count:74 |
evaluated: ch == '.' yes Evaluation Count:2 | yes Evaluation Count:72 |
| 0-74 |
608 | result += (char)ch; executed (the execution status of this line is deduced): result += (char)ch; | - |
609 | } else if (ch <= 0xFF) { executed: } Execution Count:83898 partially evaluated: ch <= 0xFF yes Evaluation Count:72 | no Evaluation Count:0 |
| 0-83898 |
610 | result += '%'; executed (the execution status of this line is deduced): result += '%'; | - |
611 | result += hexDigits[ch / 16]; executed (the execution status of this line is deduced): result += hexDigits[ch / 16]; | - |
612 | result += hexDigits[ch % 16]; executed (the execution status of this line is deduced): result += hexDigits[ch % 16]; | - |
613 | } else { executed: } Execution Count:72 | 72 |
614 | result += "%U"; never executed (the execution status of this line is deduced): result += "%U"; | - |
615 | QByteArray hexCode; never executed (the execution status of this line is deduced): QByteArray hexCode; | - |
616 | for (int i = 0; i < 4; ++i) { | 0 |
617 | hexCode.prepend(hexDigits[ch % 16]); never executed (the execution status of this line is deduced): hexCode.prepend(hexDigits[ch % 16]); | - |
618 | ch >>= 4; never executed (the execution status of this line is deduced): ch >>= 4; | - |
619 | } | 0 |
620 | result += hexCode; never executed (the execution status of this line is deduced): result += hexCode; | - |
621 | } | 0 |
622 | } | - |
623 | } executed: } Execution Count:6972 | 6972 |
624 | | - |
625 | bool QSettingsPrivate::iniUnescapedKey(const QByteArray &key, int from, int to, QString &result) | - |
626 | { | - |
627 | bool lowercaseOnly = true; executed (the execution status of this line is deduced): bool lowercaseOnly = true; | - |
628 | int i = from; executed (the execution status of this line is deduced): int i = from; | - |
629 | result.reserve(result.length() + (to - from)); executed (the execution status of this line is deduced): result.reserve(result.length() + (to - from)); | - |
630 | while (i < to) { evaluated: i < to yes Evaluation Count:94334 | yes Evaluation Count:7582 |
| 7582-94334 |
631 | int ch = (uchar)key.at(i); executed (the execution status of this line is deduced): int ch = (uchar)key.at(i); | - |
632 | | - |
633 | if (ch == '\\') { evaluated: ch == '\\' yes Evaluation Count:5894 | yes Evaluation Count:88440 |
| 5894-88440 |
634 | result += QLatin1Char('/'); executed (the execution status of this line is deduced): result += QLatin1Char('/'); | - |
635 | ++i; executed (the execution status of this line is deduced): ++i; | - |
636 | continue; executed: continue; Execution Count:5894 | 5894 |
637 | } | - |
638 | | - |
639 | if (ch != '%' || i == to - 1) { evaluated: ch != '%' yes Evaluation Count:88405 | yes Evaluation Count:35 |
partially evaluated: i == to - 1 no Evaluation Count:0 | yes Evaluation Count:35 |
| 0-88405 |
640 | if (uint(ch - 'A') <= 'Z' - 'A') // only for ASCII evaluated: uint(ch - 'A') <= 'Z' - 'A' yes Evaluation Count:6899 | yes Evaluation Count:81506 |
| 6899-81506 |
641 | lowercaseOnly = false; executed: lowercaseOnly = false; Execution Count:6899 | 6899 |
642 | result += QLatin1Char(ch); executed (the execution status of this line is deduced): result += QLatin1Char(ch); | - |
643 | ++i; executed (the execution status of this line is deduced): ++i; | - |
644 | continue; executed: continue; Execution Count:88405 | 88405 |
645 | } | - |
646 | | - |
647 | int numDigits = 2; executed (the execution status of this line is deduced): int numDigits = 2; | - |
648 | int firstDigitPos = i + 1; executed (the execution status of this line is deduced): int firstDigitPos = i + 1; | - |
649 | | - |
650 | ch = key.at(i + 1); executed (the execution status of this line is deduced): ch = key.at(i + 1); | - |
651 | if (ch == 'U') { partially evaluated: ch == 'U' no Evaluation Count:0 | yes Evaluation Count:35 |
| 0-35 |
652 | ++firstDigitPos; never executed (the execution status of this line is deduced): ++firstDigitPos; | - |
653 | numDigits = 4; never executed (the execution status of this line is deduced): numDigits = 4; | - |
654 | } | 0 |
655 | | - |
656 | if (firstDigitPos + numDigits > to) { partially evaluated: firstDigitPos + numDigits > to no Evaluation Count:0 | yes Evaluation Count:35 |
| 0-35 |
657 | result += QLatin1Char('%'); never executed (the execution status of this line is deduced): result += QLatin1Char('%'); | - |
658 | // ### missing U | - |
659 | ++i; never executed (the execution status of this line is deduced): ++i; | - |
660 | continue; never executed: continue; | 0 |
661 | } | - |
662 | | - |
663 | bool ok; executed (the execution status of this line is deduced): bool ok; | - |
664 | ch = key.mid(firstDigitPos, numDigits).toInt(&ok, 16); executed (the execution status of this line is deduced): ch = key.mid(firstDigitPos, numDigits).toInt(&ok, 16); | - |
665 | if (!ok) { partially evaluated: !ok no Evaluation Count:0 | yes Evaluation Count:35 |
| 0-35 |
666 | result += QLatin1Char('%'); never executed (the execution status of this line is deduced): result += QLatin1Char('%'); | - |
667 | // ### missing U | - |
668 | ++i; never executed (the execution status of this line is deduced): ++i; | - |
669 | continue; never executed: continue; | 0 |
670 | } | - |
671 | | - |
672 | QChar qch(ch); executed (the execution status of this line is deduced): QChar qch(ch); | - |
673 | if (qch.isUpper()) partially evaluated: qch.isUpper() no Evaluation Count:0 | yes Evaluation Count:35 |
| 0-35 |
674 | lowercaseOnly = false; never executed: lowercaseOnly = false; | 0 |
675 | result += qch; executed (the execution status of this line is deduced): result += qch; | - |
676 | i = firstDigitPos + numDigits; executed (the execution status of this line is deduced): i = firstDigitPos + numDigits; | - |
677 | } executed: } Execution Count:35 | 35 |
678 | return lowercaseOnly; executed: return lowercaseOnly; Execution Count:7582 | 7582 |
679 | } | - |
680 | | - |
681 | void QSettingsPrivate::iniEscapedString(const QString &str, QByteArray &result, QTextCodec *codec) | - |
682 | { | - |
683 | bool needsQuotes = false; executed (the execution status of this line is deduced): bool needsQuotes = false; | - |
684 | bool escapeNextIfDigit = false; executed (the execution status of this line is deduced): bool escapeNextIfDigit = false; | - |
685 | int i; executed (the execution status of this line is deduced): int i; | - |
686 | int startPos = result.size(); executed (the execution status of this line is deduced): int startPos = result.size(); | - |
687 | | - |
688 | result.reserve(startPos + str.size() * 3 / 2); executed (the execution status of this line is deduced): result.reserve(startPos + str.size() * 3 / 2); | - |
689 | for (i = 0; i < str.size(); ++i) { evaluated: i < str.size() yes Evaluation Count:182761 | yes Evaluation Count:6527 |
| 6527-182761 |
690 | uint ch = str.at(i).unicode(); executed (the execution status of this line is deduced): uint ch = str.at(i).unicode(); | - |
691 | if (ch == ';' || ch == ',' || ch == '=') partially evaluated: ch == ';' no Evaluation Count:0 | yes Evaluation Count:182761 |
partially evaluated: ch == ',' no Evaluation Count:0 | yes Evaluation Count:182761 |
evaluated: ch == '=' yes Evaluation Count:486 | yes Evaluation Count:182275 |
| 0-182761 |
692 | needsQuotes = true; executed: needsQuotes = true; Execution Count:486 | 486 |
693 | | - |
694 | if (escapeNextIfDigit evaluated: escapeNextIfDigit yes Evaluation Count:92087 | yes Evaluation Count:90674 |
| 90674-92087 |
695 | && ((ch >= '0' && ch <= '9') evaluated: ch >= '0' yes Evaluation Count:32117 | yes Evaluation Count:59970 |
evaluated: ch <= '9' yes Evaluation Count:699 | yes Evaluation Count:31418 |
| 699-59970 |
696 | || (ch >= 'a' && ch <= 'f') evaluated: ch >= 'a' yes Evaluation Count:30063 | yes Evaluation Count:61325 |
evaluated: ch <= 'f' yes Evaluation Count:8159 | yes Evaluation Count:21904 |
| 8159-61325 |
697 | || (ch >= 'A' && ch <= 'F'))) { evaluated: ch >= 'A' yes Evaluation Count:22496 | yes Evaluation Count:60733 |
evaluated: ch <= 'F' yes Evaluation Count:118 | yes Evaluation Count:22378 |
| 118-60733 |
698 | result += "\\x"; executed (the execution status of this line is deduced): result += "\\x"; | - |
699 | result += QByteArray::number(ch, 16); executed (the execution status of this line is deduced): result += QByteArray::number(ch, 16); | - |
700 | continue; executed: continue; Execution Count:8976 | 8976 |
701 | } | - |
702 | | - |
703 | escapeNextIfDigit = false; executed (the execution status of this line is deduced): escapeNextIfDigit = false; | - |
704 | | - |
705 | switch (ch) { | - |
706 | case '\0': | - |
707 | result += "\\0"; executed (the execution status of this line is deduced): result += "\\0"; | - |
708 | escapeNextIfDigit = true; executed (the execution status of this line is deduced): escapeNextIfDigit = true; | - |
709 | break; executed: break; Execution Count:71831 | 71831 |
710 | case '\a': | - |
711 | result += "\\a"; executed (the execution status of this line is deduced): result += "\\a"; | - |
712 | break; executed: break; Execution Count:1 | 1 |
713 | case '\b': | - |
714 | result += "\\b"; executed (the execution status of this line is deduced): result += "\\b"; | - |
715 | break; executed: break; Execution Count:134 | 134 |
716 | case '\f': | - |
717 | result += "\\f"; executed (the execution status of this line is deduced): result += "\\f"; | - |
718 | break; executed: break; Execution Count:1 | 1 |
719 | case '\n': | - |
720 | result += "\\n"; executed (the execution status of this line is deduced): result += "\\n"; | - |
721 | break; executed: break; Execution Count:27 | 27 |
722 | case '\r': | - |
723 | result += "\\r"; executed (the execution status of this line is deduced): result += "\\r"; | - |
724 | break; executed: break; Execution Count:2 | 2 |
725 | case '\t': | - |
726 | result += "\\t"; executed (the execution status of this line is deduced): result += "\\t"; | - |
727 | break; executed: break; Execution Count:17 | 17 |
728 | case '\v': | - |
729 | result += "\\v"; never executed (the execution status of this line is deduced): result += "\\v"; | - |
730 | break; | 0 |
731 | case '"': | - |
732 | case '\\': | - |
733 | result += '\\'; never executed (the execution status of this line is deduced): result += '\\'; | - |
734 | result += (char)ch; never executed (the execution status of this line is deduced): result += (char)ch; | - |
735 | break; | 0 |
736 | default: | - |
737 | if (ch <= 0x1F || (ch >= 0x7F && !codec)) { evaluated: ch <= 0x1F yes Evaluation Count:7046 | yes Evaluation Count:94726 |
evaluated: ch >= 0x7F yes Evaluation Count:4234 | yes Evaluation Count:90492 |
partially evaluated: !codec yes Evaluation Count:4234 | no Evaluation Count:0 |
| 0-94726 |
738 | result += "\\x"; executed (the execution status of this line is deduced): result += "\\x"; | - |
739 | result += QByteArray::number(ch, 16); executed (the execution status of this line is deduced): result += QByteArray::number(ch, 16); | - |
740 | escapeNextIfDigit = true; executed (the execution status of this line is deduced): escapeNextIfDigit = true; | - |
741 | #ifndef QT_NO_TEXTCODEC | - |
742 | } else if (codec) { executed: } Execution Count:11280 partially evaluated: codec no Evaluation Count:0 | yes Evaluation Count:90492 |
| 0-90492 |
743 | // slow | - |
744 | result += codec->fromUnicode(str.at(i)); never executed (the execution status of this line is deduced): result += codec->fromUnicode(str.at(i)); | - |
745 | #endif | - |
746 | } else { | 0 |
747 | result += (char)ch; executed (the execution status of this line is deduced): result += (char)ch; | - |
748 | } executed: } Execution Count:90492 | 90492 |
749 | } | - |
750 | } executed: } Execution Count:173785 | 173785 |
751 | | - |
752 | if (needsQuotes evaluated: needsQuotes yes Evaluation Count:276 | yes Evaluation Count:6251 |
| 276-6251 |
753 | || (startPos < result.size() && (result.at(startPos) == ' ' evaluated: startPos < result.size() yes Evaluation Count:6234 | yes Evaluation Count:17 |
partially evaluated: result.at(startPos) == ' ' no Evaluation Count:0 | yes Evaluation Count:6234 |
| 0-6234 |
754 | || result.at(result.size() - 1) == ' '))) { partially evaluated: result.at(result.size() - 1) == ' ' no Evaluation Count:0 | yes Evaluation Count:6234 |
| 0-6234 |
755 | result.insert(startPos, '"'); executed (the execution status of this line is deduced): result.insert(startPos, '"'); | - |
756 | result += '"'; executed (the execution status of this line is deduced): result += '"'; | - |
757 | } executed: } Execution Count:276 | 276 |
758 | } executed: } Execution Count:6527 | 6527 |
759 | | - |
760 | inline static void iniChopTrailingSpaces(QString &str) | - |
761 | { | - |
762 | int n = str.size() - 1; executed (the execution status of this line is deduced): int n = str.size() - 1; | - |
763 | QChar ch; executed (the execution status of this line is deduced): QChar ch; | - |
764 | while (n >= 0 && ((ch = str.at(n)) == QLatin1Char(' ') || ch == QLatin1Char('\t'))) evaluated: n >= 0 yes Evaluation Count:6948 | yes Evaluation Count:14 |
partially evaluated: (ch = str.at(n)) == QLatin1Char(' ') no Evaluation Count:0 | yes Evaluation Count:6948 |
partially evaluated: ch == QLatin1Char('\t') no Evaluation Count:0 | yes Evaluation Count:6948 |
| 0-6948 |
765 | str.truncate(n--); never executed: str.truncate(n--); | 0 |
766 | } executed: } Execution Count:6962 | 6962 |
767 | | - |
768 | void QSettingsPrivate::iniEscapedStringList(const QStringList &strs, QByteArray &result, QTextCodec *codec) | - |
769 | { | - |
770 | if (strs.isEmpty()) { evaluated: strs.isEmpty() yes Evaluation Count:4 | yes Evaluation Count:12 |
| 4-12 |
771 | /* | - |
772 | We need to distinguish between empty lists and one-item | - |
773 | lists that contain an empty string. Ideally, we'd have a | - |
774 | @EmptyList() symbol but that would break compatibility | - |
775 | with Qt 4.0. @Invalid() stands for QVariant(), and | - |
776 | QVariant().toStringList() returns an empty QStringList, | - |
777 | so we're in good shape. | - |
778 | */ | - |
779 | result += "@Invalid()"; executed (the execution status of this line is deduced): result += "@Invalid()"; | - |
780 | } else { executed: } Execution Count:4 | 4 |
781 | for (int i = 0; i < strs.size(); ++i) { evaluated: i < strs.size() yes Evaluation Count:34 | yes Evaluation Count:12 |
| 12-34 |
782 | if (i != 0) evaluated: i != 0 yes Evaluation Count:22 | yes Evaluation Count:12 |
| 12-22 |
783 | result += ", "; executed: result += ", "; Execution Count:22 | 22 |
784 | iniEscapedString(strs.at(i), result, codec); executed (the execution status of this line is deduced): iniEscapedString(strs.at(i), result, codec); | - |
785 | } executed: } Execution Count:34 | 34 |
786 | } executed: } Execution Count:12 | 12 |
787 | } | - |
788 | | - |
789 | bool QSettingsPrivate::iniUnescapedStringList(const QByteArray &str, int from, int to, | - |
790 | QString &stringResult, QStringList &stringListResult, | - |
791 | QTextCodec *codec) | - |
792 | { | - |
793 | static const char escapeCodes[][2] = | - |
794 | { | - |
795 | { 'a', '\a' }, | - |
796 | { 'b', '\b' }, | - |
797 | { 'f', '\f' }, | - |
798 | { 'n', '\n' }, | - |
799 | { 'r', '\r' }, | - |
800 | { 't', '\t' }, | - |
801 | { 'v', '\v' }, | - |
802 | { '"', '"' }, | - |
803 | { '?', '?' }, | - |
804 | { '\'', '\'' }, | - |
805 | { '\\', '\\' } | - |
806 | }; | - |
807 | static const int numEscapeCodes = sizeof(escapeCodes) / sizeof(escapeCodes[0]); | - |
808 | | - |
809 | bool isStringList = false; executed (the execution status of this line is deduced): bool isStringList = false; | - |
810 | bool inQuotedString = false; executed (the execution status of this line is deduced): bool inQuotedString = false; | - |
811 | bool currentValueIsQuoted = false; executed (the execution status of this line is deduced): bool currentValueIsQuoted = false; | - |
812 | int escapeVal = 0; executed (the execution status of this line is deduced): int escapeVal = 0; | - |
813 | int i = from; executed (the execution status of this line is deduced): int i = from; | - |
814 | char ch; executed (the execution status of this line is deduced): char ch; | - |
815 | | - |
816 | StSkipSpaces: code before this statement executed: StSkipSpaces: Execution Count:7005 | 7005 |
817 | while (i < to && ((ch = str.at(i)) == ' ' || ch == '\t')) evaluated: i < to yes Evaluation Count:7242 | yes Evaluation Count:286 |
evaluated: (ch = str.at(i)) == ' ' yes Evaluation Count:14 | yes Evaluation Count:7228 |
partially evaluated: ch == '\t' no Evaluation Count:0 | yes Evaluation Count:7228 |
| 0-7242 |
818 | ++i; executed: ++i; Execution Count:14 | 14 |
819 | // fallthrough | - |
820 | | - |
821 | StNormal: code before this statement executed: StNormal: Execution Count:7514 | 7514 |
822 | while (i < to) { evaluated: i < to yes Evaluation Count:122853 | yes Evaluation Count:7005 |
| 7005-122853 |
823 | switch (str.at(i)) { | - |
824 | case '\\': | - |
825 | ++i; executed (the execution status of this line is deduced): ++i; | - |
826 | if (i >= to) partially evaluated: i >= to no Evaluation Count:0 | yes Evaluation Count:91760 |
| 0-91760 |
827 | goto end; never executed: goto end; | 0 |
828 | | - |
829 | ch = str.at(i++); executed (the execution status of this line is deduced): ch = str.at(i++); | - |
830 | for (int j = 0; j < numEscapeCodes; ++j) { evaluated: j < numEscapeCodes yes Evaluation Count:1008120 | yes Evaluation Count:91619 |
| 91619-1008120 |
831 | if (ch == escapeCodes[j][0]) { evaluated: ch == escapeCodes[j][0] yes Evaluation Count:141 | yes Evaluation Count:1007979 |
| 141-1007979 |
832 | stringResult += QLatin1Char(escapeCodes[j][1]); executed (the execution status of this line is deduced): stringResult += QLatin1Char(escapeCodes[j][1]); | - |
833 | goto StNormal; executed: goto StNormal; Execution Count:141 | 141 |
834 | } | - |
835 | } executed: } Execution Count:1007979 | 1007979 |
836 | | - |
837 | if (ch == 'x') { evaluated: ch == 'x' yes Evaluation Count:20135 | yes Evaluation Count:71484 |
| 20135-71484 |
838 | escapeVal = 0; executed (the execution status of this line is deduced): escapeVal = 0; | - |
839 | | - |
840 | if (i >= to) partially evaluated: i >= to no Evaluation Count:0 | yes Evaluation Count:20135 |
| 0-20135 |
841 | goto end; never executed: goto end; | 0 |
842 | | - |
843 | ch = str.at(i); executed (the execution status of this line is deduced): ch = str.at(i); | - |
844 | if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'F') || (ch >= 'a' && ch <= 'f')) partially evaluated: ch >= '0' yes Evaluation Count:20135 | no Evaluation Count:0 |
evaluated: ch <= '9' yes Evaluation Count:16537 | yes Evaluation Count:3598 |
partially evaluated: ch >= 'A' yes Evaluation Count:3598 | no Evaluation Count:0 |
partially evaluated: ch <= 'F' no Evaluation Count:0 | yes Evaluation Count:3598 |
partially evaluated: ch >= 'a' yes Evaluation Count:3598 | no Evaluation Count:0 |
partially evaluated: ch <= 'f' yes Evaluation Count:3598 | no Evaluation Count:0 |
| 0-20135 |
845 | goto StHexEscape; executed: goto StHexEscape; Execution Count:20135 | 20135 |
846 | } else if (ch >= '0' && ch <= '7') { never executed: } partially evaluated: ch >= '0' yes Evaluation Count:71484 | no Evaluation Count:0 |
partially evaluated: ch <= '7' yes Evaluation Count:71484 | no Evaluation Count:0 |
| 0-71484 |
847 | escapeVal = ch - '0'; executed (the execution status of this line is deduced): escapeVal = ch - '0'; | - |
848 | goto StOctEscape; executed: goto StOctEscape; Execution Count:71484 | 71484 |
849 | } else if (ch == '\n' || ch == '\r') { never evaluated: ch == '\n' never evaluated: ch == '\r' | 0 |
850 | if (i < to) { | 0 |
851 | char ch2 = str.at(i); never executed (the execution status of this line is deduced): char ch2 = str.at(i); | - |
852 | // \n, \r, \r\n, and \n\r are legitimate line terminators in INI files | - |
853 | if ((ch2 == '\n' || ch2 == '\r') && ch2 != ch) never evaluated: ch2 == '\n' never evaluated: ch2 == '\r' never evaluated: ch2 != ch | 0 |
854 | ++i; | 0 |
855 | } | 0 |
856 | } else { | 0 |
857 | // the character is skipped | - |
858 | } | 0 |
859 | break; | 0 |
860 | case '"': | - |
861 | ++i; executed (the execution status of this line is deduced): ++i; | - |
862 | currentValueIsQuoted = true; executed (the execution status of this line is deduced): currentValueIsQuoted = true; | - |
863 | inQuotedString = !inQuotedString; executed (the execution status of this line is deduced): inQuotedString = !inQuotedString; | - |
864 | if (!inQuotedString) evaluated: !inQuotedString yes Evaluation Count:276 | yes Evaluation Count:276 |
| 276 |
865 | goto StSkipSpaces; executed: goto StSkipSpaces; Execution Count:276 | 276 |
866 | break; executed: break; Execution Count:276 | 276 |
867 | case ',': | - |
868 | if (!inQuotedString) { partially evaluated: !inQuotedString yes Evaluation Count:233 | no Evaluation Count:0 |
| 0-233 |
869 | if (!currentValueIsQuoted) partially evaluated: !currentValueIsQuoted yes Evaluation Count:233 | no Evaluation Count:0 |
| 0-233 |
870 | iniChopTrailingSpaces(stringResult); executed: iniChopTrailingSpaces(stringResult); Execution Count:233 | 233 |
871 | if (!isStringList) { evaluated: !isStringList yes Evaluation Count:21 | yes Evaluation Count:212 |
| 21-212 |
872 | isStringList = true; executed (the execution status of this line is deduced): isStringList = true; | - |
873 | stringListResult.clear(); executed (the execution status of this line is deduced): stringListResult.clear(); | - |
874 | stringResult.squeeze(); executed (the execution status of this line is deduced): stringResult.squeeze(); | - |
875 | } executed: } Execution Count:21 | 21 |
876 | stringListResult.append(stringResult); executed (the execution status of this line is deduced): stringListResult.append(stringResult); | - |
877 | stringResult.clear(); executed (the execution status of this line is deduced): stringResult.clear(); | - |
878 | currentValueIsQuoted = false; executed (the execution status of this line is deduced): currentValueIsQuoted = false; | - |
879 | ++i; executed (the execution status of this line is deduced): ++i; | - |
880 | goto StSkipSpaces; executed: goto StSkipSpaces; Execution Count:233 | 233 |
881 | } | - |
882 | // fallthrough | - |
883 | default: { code before this statement never executed: default: | 0 |
884 | int j = i + 1; executed (the execution status of this line is deduced): int j = i + 1; | - |
885 | while (j < to) { evaluated: j < to yes Evaluation Count:89384 | yes Evaluation Count:6719 |
| 6719-89384 |
886 | ch = str.at(j); executed (the execution status of this line is deduced): ch = str.at(j); | - |
887 | if (ch == '\\' || ch == '"' || ch == ',') evaluated: ch == '\\' yes Evaluation Count:23084 | yes Evaluation Count:66300 |
evaluated: ch == '"' yes Evaluation Count:276 | yes Evaluation Count:66024 |
evaluated: ch == ',' yes Evaluation Count:229 | yes Evaluation Count:65795 |
| 229-66300 |
888 | break; executed: break; Execution Count:23589 | 23589 |
889 | ++j; executed (the execution status of this line is deduced): ++j; | - |
890 | } executed: } Execution Count:65795 | 65795 |
891 | | - |
892 | #ifndef QT_NO_TEXTCODEC | - |
893 | if (codec) { partially evaluated: codec no Evaluation Count:0 | yes Evaluation Count:30308 |
| 0-30308 |
894 | stringResult += codec->toUnicode(str.constData() + i, j - i); never executed (the execution status of this line is deduced): stringResult += codec->toUnicode(str.constData() + i, j - i); | - |
895 | } else | 0 |
896 | #endif | - |
897 | { | - |
898 | int n = stringResult.size(); executed (the execution status of this line is deduced): int n = stringResult.size(); | - |
899 | stringResult.resize(n + (j - i)); executed (the execution status of this line is deduced): stringResult.resize(n + (j - i)); | - |
900 | QChar *resultData = stringResult.data() + n; executed (the execution status of this line is deduced): QChar *resultData = stringResult.data() + n; | - |
901 | for (int k = i; k < j; ++k) evaluated: k < j yes Evaluation Count:96103 | yes Evaluation Count:30308 |
| 30308-96103 |
902 | *resultData++ = QLatin1Char(str.at(k)); executed: *resultData++ = QLatin1Char(str.at(k)); Execution Count:96103 | 96103 |
903 | } executed: } Execution Count:30308 | 30308 |
904 | i = j; executed (the execution status of this line is deduced): i = j; | - |
905 | } | - |
906 | } executed: } Execution Count:30308 | 30308 |
907 | } executed: } Execution Count:30584 | 30584 |
908 | goto end; executed: goto end; Execution Count:7005 | 7005 |
909 | | - |
910 | StHexEscape: | - |
911 | if (i >= to) { partially evaluated: i >= to no Evaluation Count:0 | yes Evaluation Count:54021 |
| 0-54021 |
912 | stringResult += QChar(escapeVal); never executed (the execution status of this line is deduced): stringResult += QChar(escapeVal); | - |
913 | goto end; never executed: goto end; | 0 |
914 | } | - |
915 | | - |
916 | ch = str.at(i); executed (the execution status of this line is deduced): ch = str.at(i); | - |
917 | if (ch >= 'a') evaluated: ch >= 'a' yes Evaluation Count:7776 | yes Evaluation Count:46245 |
| 7776-46245 |
918 | ch -= 'a' - 'A'; executed: ch -= 'a' - 'A'; Execution Count:7776 | 7776 |
919 | if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'F')) { evaluated: ch >= '0' yes Evaluation Count:53747 | yes Evaluation Count:274 |
evaluated: ch <= '9' yes Evaluation Count:26662 | yes Evaluation Count:27085 |
evaluated: ch >= 'A' yes Evaluation Count:27085 | yes Evaluation Count:274 |
evaluated: ch <= 'F' yes Evaluation Count:7224 | yes Evaluation Count:19861 |
| 274-53747 |
920 | escapeVal <<= 4; executed (the execution status of this line is deduced): escapeVal <<= 4; | - |
921 | escapeVal += strchr(hexDigits, ch) - hexDigits; executed (the execution status of this line is deduced): escapeVal += strchr(hexDigits, ch) - hexDigits; | - |
922 | ++i; executed (the execution status of this line is deduced): ++i; | - |
923 | goto StHexEscape; executed: goto StHexEscape; Execution Count:33886 | 33886 |
924 | } else { | - |
925 | stringResult += QChar(escapeVal); executed (the execution status of this line is deduced): stringResult += QChar(escapeVal); | - |
926 | goto StNormal; executed: goto StNormal; Execution Count:20135 | 20135 |
927 | } | - |
928 | | - |
929 | StOctEscape: | - |
930 | if (i >= to) { partially evaluated: i >= to no Evaluation Count:0 | yes Evaluation Count:71484 |
| 0-71484 |
931 | stringResult += QChar(escapeVal); never executed (the execution status of this line is deduced): stringResult += QChar(escapeVal); | - |
932 | goto end; never executed: goto end; | 0 |
933 | } | - |
934 | | - |
935 | ch = str.at(i); executed (the execution status of this line is deduced): ch = str.at(i); | - |
936 | if (ch >= '0' && ch <= '7') { evaluated: ch >= '0' yes Evaluation Count:67573 | yes Evaluation Count:3911 |
partially evaluated: ch <= '7' no Evaluation Count:0 | yes Evaluation Count:67573 |
| 0-67573 |
937 | escapeVal <<= 3; never executed (the execution status of this line is deduced): escapeVal <<= 3; | - |
938 | escapeVal += ch - '0'; never executed (the execution status of this line is deduced): escapeVal += ch - '0'; | - |
939 | ++i; never executed (the execution status of this line is deduced): ++i; | - |
940 | goto StOctEscape; never executed: goto StOctEscape; | 0 |
941 | } else { | - |
942 | stringResult += QChar(escapeVal); executed (the execution status of this line is deduced): stringResult += QChar(escapeVal); | - |
943 | goto StNormal; executed: goto StNormal; Execution Count:71484 | 71484 |
944 | } | - |
945 | | - |
946 | end: | - |
947 | if (!currentValueIsQuoted) evaluated: !currentValueIsQuoted yes Evaluation Count:6729 | yes Evaluation Count:276 |
| 276-6729 |
948 | iniChopTrailingSpaces(stringResult); executed: iniChopTrailingSpaces(stringResult); Execution Count:6729 | 6729 |
949 | if (isStringList) evaluated: isStringList yes Evaluation Count:21 | yes Evaluation Count:6984 |
| 21-6984 |
950 | stringListResult.append(stringResult); executed: stringListResult.append(stringResult); Execution Count:21 | 21 |
951 | return isStringList; executed: return isStringList; Execution Count:7005 | 7005 |
952 | } | - |
953 | | - |
954 | QStringList QSettingsPrivate::splitArgs(const QString &s, int idx) | - |
955 | { | - |
956 | int l = s.length(); never executed (the execution status of this line is deduced): int l = s.length(); | - |
957 | Q_ASSERT(l > 0); never executed (the execution status of this line is deduced): qt_noop(); | - |
958 | Q_ASSERT(s.at(idx) == QLatin1Char('(')); never executed (the execution status of this line is deduced): qt_noop(); | - |
959 | Q_ASSERT(s.at(l - 1) == QLatin1Char(')')); never executed (the execution status of this line is deduced): qt_noop(); | - |
960 | | - |
961 | QStringList result; never executed (the execution status of this line is deduced): QStringList result; | - |
962 | QString item; never executed (the execution status of this line is deduced): QString item; | - |
963 | | - |
964 | for (++idx; idx < l; ++idx) { | 0 |
965 | QChar c = s.at(idx); never executed (the execution status of this line is deduced): QChar c = s.at(idx); | - |
966 | if (c == QLatin1Char(')')) { never evaluated: c == QLatin1Char(')') | 0 |
967 | Q_ASSERT(idx == l - 1); never executed (the execution status of this line is deduced): qt_noop(); | - |
968 | result.append(item); never executed (the execution status of this line is deduced): result.append(item); | - |
969 | } else if (c == QLatin1Char(' ')) { never executed: } never evaluated: c == QLatin1Char(' ') | 0 |
970 | result.append(item); never executed (the execution status of this line is deduced): result.append(item); | - |
971 | item.clear(); never executed (the execution status of this line is deduced): item.clear(); | - |
972 | } else { | 0 |
973 | item.append(c); never executed (the execution status of this line is deduced): item.append(c); | - |
974 | } | 0 |
975 | } | - |
976 | | - |
977 | return result; never executed: return result; | 0 |
978 | } | - |
979 | | - |
980 | // ************************************************************************ | - |
981 | // QConfFileSettingsPrivate | - |
982 | | - |
983 | void QConfFileSettingsPrivate::initFormat() | - |
984 | { | - |
985 | extension = (format == QSettings::NativeFormat) ? QLatin1String(".conf") : QLatin1String(".ini"); evaluated: (format == QSettings::NativeFormat) yes Evaluation Count:642 | yes Evaluation Count:160 |
| 160-642 |
986 | readFunc = 0; executed (the execution status of this line is deduced): readFunc = 0; | - |
987 | writeFunc = 0; executed (the execution status of this line is deduced): writeFunc = 0; | - |
988 | #if defined(Q_OS_MAC) | - |
989 | caseSensitivity = (format == QSettings::NativeFormat) ? Qt::CaseSensitive : IniCaseSensitivity; | - |
990 | #else | - |
991 | caseSensitivity = IniCaseSensitivity; executed (the execution status of this line is deduced): caseSensitivity = IniCaseSensitivity; | - |
992 | #endif | - |
993 | | - |
994 | if (format > QSettings::IniFormat) { evaluated: format > QSettings::IniFormat yes Evaluation Count:90 | yes Evaluation Count:712 |
| 90-712 |
995 | QMutexLocker locker(&settingsGlobalMutex); executed (the execution status of this line is deduced): QMutexLocker locker(&settingsGlobalMutex); | - |
996 | const CustomFormatVector *customFormatVector = customFormatVectorFunc(); executed (the execution status of this line is deduced): const CustomFormatVector *customFormatVector = customFormatVectorFunc(); | - |
997 | | - |
998 | int i = (int)format - (int)QSettings::CustomFormat1; executed (the execution status of this line is deduced): int i = (int)format - (int)QSettings::CustomFormat1; | - |
999 | if (i >= 0 && i < customFormatVector->size()) { partially evaluated: i >= 0 yes Evaluation Count:90 | no Evaluation Count:0 |
evaluated: i < customFormatVector->size() yes Evaluation Count:89 | yes Evaluation Count:1 |
| 0-90 |
1000 | QConfFileCustomFormat info = customFormatVector->at(i); executed (the execution status of this line is deduced): QConfFileCustomFormat info = customFormatVector->at(i); | - |
1001 | extension = info.extension; executed (the execution status of this line is deduced): extension = info.extension; | - |
1002 | readFunc = info.readFunc; executed (the execution status of this line is deduced): readFunc = info.readFunc; | - |
1003 | writeFunc = info.writeFunc; executed (the execution status of this line is deduced): writeFunc = info.writeFunc; | - |
1004 | caseSensitivity = info.caseSensitivity; executed (the execution status of this line is deduced): caseSensitivity = info.caseSensitivity; | - |
1005 | } executed: } Execution Count:89 | 89 |
1006 | } executed: } Execution Count:90 | 90 |
1007 | } executed: } Execution Count:802 | 802 |
1008 | | - |
1009 | void QConfFileSettingsPrivate::initAccess() | - |
1010 | { | - |
1011 | if (confFiles[spec]) { partially evaluated: confFiles[spec] yes Evaluation Count:802 | no Evaluation Count:0 |
| 0-802 |
1012 | if (format > QSettings::IniFormat) { evaluated: format > QSettings::IniFormat yes Evaluation Count:90 | yes Evaluation Count:712 |
| 90-712 |
1013 | if (!readFunc) evaluated: !readFunc yes Evaluation Count:1 | yes Evaluation Count:89 |
| 1-89 |
1014 | setStatus(QSettings::AccessError); executed: setStatus(QSettings::AccessError); Execution Count:1 | 1 |
1015 | } executed: } Execution Count:90 | 90 |
1016 | } executed: } Execution Count:802 | 802 |
1017 | | - |
1018 | sync(); // loads the files the first time executed (the execution status of this line is deduced): sync(); | - |
1019 | } executed: } Execution Count:802 | 802 |
1020 | | - |
1021 | #ifdef Q_OS_WIN | - |
1022 | static QString windowsConfigPath(int type) | - |
1023 | { | - |
1024 | QString result; | - |
1025 | | - |
1026 | #ifndef Q_OS_WINCE | - |
1027 | QSystemLibrary library(QLatin1String("shell32")); | - |
1028 | #else | - |
1029 | QSystemLibrary library(QLatin1String("coredll")); | - |
1030 | #endif // Q_OS_WINCE | - |
1031 | typedef BOOL (WINAPI*GetSpecialFolderPath)(HWND, LPWSTR, int, BOOL); | - |
1032 | GetSpecialFolderPath SHGetSpecialFolderPath = (GetSpecialFolderPath)library.resolve("SHGetSpecialFolderPathW"); | - |
1033 | if (SHGetSpecialFolderPath) { | - |
1034 | wchar_t path[MAX_PATH]; | - |
1035 | SHGetSpecialFolderPath(0, path, type, false); | - |
1036 | result = QString::fromWCharArray(path); | - |
1037 | } | - |
1038 | | - |
1039 | if (result.isEmpty()) { | - |
1040 | switch (type) { | - |
1041 | #ifndef Q_OS_WINCE | - |
1042 | case CSIDL_COMMON_APPDATA: | - |
1043 | result = QLatin1String("C:\\temp\\qt-common"); | - |
1044 | break; | - |
1045 | case CSIDL_APPDATA: | - |
1046 | result = QLatin1String("C:\\temp\\qt-user"); | - |
1047 | break; | - |
1048 | #else | - |
1049 | case CSIDL_COMMON_APPDATA: | - |
1050 | result = QLatin1String("\\Temp\\qt-common"); | - |
1051 | break; | - |
1052 | case CSIDL_APPDATA: | - |
1053 | result = QLatin1String("\\Temp\\qt-user"); | - |
1054 | break; | - |
1055 | #endif | - |
1056 | default: | - |
1057 | ; | - |
1058 | } | - |
1059 | } | - |
1060 | | - |
1061 | return result; | - |
1062 | } | - |
1063 | #endif // Q_OS_WIN | - |
1064 | | - |
1065 | static inline int pathHashKey(QSettings::Format format, QSettings::Scope scope) | - |
1066 | { | - |
1067 | return int((uint(format) << 1) | uint(scope == QSettings::SystemScope)); executed: return int((uint(format) << 1) | uint(scope == QSettings::SystemScope)); Execution Count:2081 | 2081 |
1068 | } | - |
1069 | | - |
1070 | static void initDefaultPaths(QMutexLocker *locker) | - |
1071 | { | - |
1072 | PathHash *pathHash = pathHashFunc(); executed (the execution status of this line is deduced): PathHash *pathHash = pathHashFunc(); | - |
1073 | QString homePath = QDir::homePath(); executed (the execution status of this line is deduced): QString homePath = QDir::homePath(); | - |
1074 | QString systemPath; executed (the execution status of this line is deduced): QString systemPath; | - |
1075 | | - |
1076 | locker->unlock(); executed (the execution status of this line is deduced): locker->unlock(); | - |
1077 | | - |
1078 | /* | - |
1079 | QLibraryInfo::location() uses QSettings, so in order to | - |
1080 | avoid a dead-lock, we can't hold the global mutex while | - |
1081 | calling it. | - |
1082 | */ | - |
1083 | systemPath = QLibraryInfo::location(QLibraryInfo::SettingsPath); executed (the execution status of this line is deduced): systemPath = QLibraryInfo::location(QLibraryInfo::SettingsPath); | - |
1084 | systemPath += QLatin1Char('/'); executed (the execution status of this line is deduced): systemPath += QLatin1Char('/'); | - |
1085 | | - |
1086 | locker->relock(); executed (the execution status of this line is deduced): locker->relock(); | - |
1087 | if (pathHash->isEmpty()) { partially evaluated: pathHash->isEmpty() yes Evaluation Count:5 | no Evaluation Count:0 |
| 0-5 |
1088 | /* | - |
1089 | Lazy initialization of pathHash. We initialize the | - |
1090 | IniFormat paths and (on Unix) the NativeFormat paths. | - |
1091 | (The NativeFormat paths are not configurable for the | - |
1092 | Windows registry and the Mac CFPreferences.) | - |
1093 | */ | - |
1094 | #ifdef Q_OS_WIN | - |
1095 | pathHash->insert(pathHashKey(QSettings::IniFormat, QSettings::UserScope), | - |
1096 | windowsConfigPath(CSIDL_APPDATA) + QDir::separator()); | - |
1097 | pathHash->insert(pathHashKey(QSettings::IniFormat, QSettings::SystemScope), | - |
1098 | windowsConfigPath(CSIDL_COMMON_APPDATA) + QDir::separator()); | - |
1099 | #else | - |
1100 | QString userPath; never executed (the execution status of this line is deduced): QString userPath; | - |
1101 | char *env = getenv("XDG_CONFIG_HOME"); never executed (the execution status of this line is deduced): char *env = getenv("XDG_CONFIG_HOME"); | - |
1102 | if (env == 0) { partially evaluated: env == 0 yes Evaluation Count:5 | no Evaluation Count:0 |
| 0-5 |
1103 | userPath = homePath; executed (the execution status of this line is deduced): userPath = homePath; | - |
1104 | userPath += QLatin1Char('/'); executed (the execution status of this line is deduced): userPath += QLatin1Char('/'); | - |
1105 | userPath += QLatin1String(".config"); executed (the execution status of this line is deduced): userPath += QLatin1String(".config"); | - |
1106 | } else if (*env == '/') { executed: } Execution Count:5 never evaluated: *env == '/' | 0-5 |
1107 | userPath = QFile::decodeName(env); never executed (the execution status of this line is deduced): userPath = QFile::decodeName(env); | - |
1108 | } else { | 0 |
1109 | userPath = homePath; never executed (the execution status of this line is deduced): userPath = homePath; | - |
1110 | userPath += QLatin1Char('/'); never executed (the execution status of this line is deduced): userPath += QLatin1Char('/'); | - |
1111 | userPath += QFile::decodeName(env); never executed (the execution status of this line is deduced): userPath += QFile::decodeName(env); | - |
1112 | } | 0 |
1113 | userPath += QLatin1Char('/'); executed (the execution status of this line is deduced): userPath += QLatin1Char('/'); | - |
1114 | | - |
1115 | pathHash->insert(pathHashKey(QSettings::IniFormat, QSettings::UserScope), userPath); executed (the execution status of this line is deduced): pathHash->insert(pathHashKey(QSettings::IniFormat, QSettings::UserScope), userPath); | - |
1116 | pathHash->insert(pathHashKey(QSettings::IniFormat, QSettings::SystemScope), systemPath); executed (the execution status of this line is deduced): pathHash->insert(pathHashKey(QSettings::IniFormat, QSettings::SystemScope), systemPath); | - |
1117 | #ifndef Q_OS_MAC | - |
1118 | pathHash->insert(pathHashKey(QSettings::NativeFormat, QSettings::UserScope), userPath); executed (the execution status of this line is deduced): pathHash->insert(pathHashKey(QSettings::NativeFormat, QSettings::UserScope), userPath); | - |
1119 | pathHash->insert(pathHashKey(QSettings::NativeFormat, QSettings::SystemScope), systemPath); executed (the execution status of this line is deduced): pathHash->insert(pathHashKey(QSettings::NativeFormat, QSettings::SystemScope), systemPath); | - |
1120 | #endif | - |
1121 | #endif | - |
1122 | } executed: } Execution Count:5 | 5 |
1123 | } executed: } Execution Count:5 | 5 |
1124 | | - |
1125 | static QString getPath(QSettings::Format format, QSettings::Scope scope) | - |
1126 | { | - |
1127 | Q_ASSERT((int)QSettings::NativeFormat == 0); executed (the execution status of this line is deduced): qt_noop(); | - |
1128 | Q_ASSERT((int)QSettings::IniFormat == 1); executed (the execution status of this line is deduced): qt_noop(); | - |
1129 | | - |
1130 | QMutexLocker locker(&settingsGlobalMutex); executed (the execution status of this line is deduced): QMutexLocker locker(&settingsGlobalMutex); | - |
1131 | PathHash *pathHash = pathHashFunc(); executed (the execution status of this line is deduced): PathHash *pathHash = pathHashFunc(); | - |
1132 | if (pathHash->isEmpty()) evaluated: pathHash->isEmpty() yes Evaluation Count:4 | yes Evaluation Count:1453 |
| 4-1453 |
1133 | initDefaultPaths(&locker); executed: initDefaultPaths(&locker); Execution Count:4 | 4 |
1134 | | - |
1135 | QString result = pathHash->value(pathHashKey(format, scope)); executed (the execution status of this line is deduced): QString result = pathHash->value(pathHashKey(format, scope)); | - |
1136 | if (!result.isEmpty()) evaluated: !result.isEmpty() yes Evaluation Count:1349 | yes Evaluation Count:108 |
| 108-1349 |
1137 | return result; executed: return result; Execution Count:1349 | 1349 |
1138 | | - |
1139 | // fall back on INI path | - |
1140 | return pathHash->value(pathHashKey(QSettings::IniFormat, scope)); executed: return pathHash->value(pathHashKey(QSettings::IniFormat, scope)); Execution Count:108 | 108 |
1141 | } | - |
1142 | | - |
1143 | QConfFileSettingsPrivate::QConfFileSettingsPrivate(QSettings::Format format, | - |
1144 | QSettings::Scope scope, | - |
1145 | const QString &organization, | - |
1146 | const QString &application) | - |
1147 | : QSettingsPrivate(format, scope, organization, application), | - |
1148 | nextPosition(0x40000000) // big positive number | - |
1149 | { | - |
1150 | int i; executed (the execution status of this line is deduced): int i; | - |
1151 | initFormat(); executed (the execution status of this line is deduced): initFormat(); | - |
1152 | | - |
1153 | QString org = organization; executed (the execution status of this line is deduced): QString org = organization; | - |
1154 | if (org.isEmpty()) { evaluated: org.isEmpty() yes Evaluation Count:7 | yes Evaluation Count:751 |
| 7-751 |
1155 | setStatus(QSettings::AccessError); executed (the execution status of this line is deduced): setStatus(QSettings::AccessError); | - |
1156 | org = QLatin1String("Unknown Organization"); executed (the execution status of this line is deduced): org = QLatin1String("Unknown Organization"); | - |
1157 | } executed: } Execution Count:7 | 7 |
1158 | | - |
1159 | #if !defined(Q_OS_BLACKBERRY) | - |
1160 | QString appFile = org + QDir::separator() + application + extension; executed (the execution status of this line is deduced): QString appFile = org + QDir::separator() + application + extension; | - |
1161 | QString orgFile = org + extension; executed (the execution status of this line is deduced): QString orgFile = org + extension; | - |
1162 | | - |
1163 | if (scope == QSettings::UserScope) { evaluated: scope == QSettings::UserScope yes Evaluation Count:699 | yes Evaluation Count:59 |
| 59-699 |
1164 | QString userPath = getPath(format, QSettings::UserScope); executed (the execution status of this line is deduced): QString userPath = getPath(format, QSettings::UserScope); | - |
1165 | if (!application.isEmpty()) evaluated: !application.isEmpty() yes Evaluation Count:114 | yes Evaluation Count:585 |
| 114-585 |
1166 | confFiles[F_User | F_Application].reset(QConfFile::fromName(userPath + appFile, true)); executed: confFiles[F_User | F_Application].reset(QConfFile::fromName(userPath + appFile, true)); Execution Count:114 | 114 |
1167 | confFiles[F_User | F_Organization].reset(QConfFile::fromName(userPath + orgFile, true)); executed (the execution status of this line is deduced): confFiles[F_User | F_Organization].reset(QConfFile::fromName(userPath + orgFile, true)); | - |
1168 | } executed: } Execution Count:699 | 699 |
1169 | | - |
1170 | QString systemPath = getPath(format, QSettings::SystemScope); executed (the execution status of this line is deduced): QString systemPath = getPath(format, QSettings::SystemScope); | - |
1171 | if (!application.isEmpty()) evaluated: !application.isEmpty() yes Evaluation Count:156 | yes Evaluation Count:602 |
| 156-602 |
1172 | confFiles[F_System | F_Application].reset(QConfFile::fromName(systemPath + appFile, false)); executed: confFiles[F_System | F_Application].reset(QConfFile::fromName(systemPath + appFile, false)); Execution Count:156 | 156 |
1173 | confFiles[F_System | F_Organization].reset(QConfFile::fromName(systemPath + orgFile, false)); executed (the execution status of this line is deduced): confFiles[F_System | F_Organization].reset(QConfFile::fromName(systemPath + orgFile, false)); | - |
1174 | #else | - |
1175 | QString confName = getPath(format, QSettings::UserScope) + org; | - |
1176 | if (!application.isEmpty()) | - |
1177 | confName += QDir::separator() + application; | - |
1178 | confName += extension; | - |
1179 | confFiles[SandboxConfFile].reset(QConfFile::fromName(confName, true)); | - |
1180 | #endif | - |
1181 | | - |
1182 | for (i = 0; i < NumConfFiles; ++i) { partially evaluated: i < NumConfFiles yes Evaluation Count:1478 | no Evaluation Count:0 |
| 0-1478 |
1183 | if (confFiles[i]) { evaluated: confFiles[i] yes Evaluation Count:758 | yes Evaluation Count:720 |
| 720-758 |
1184 | spec = i; executed (the execution status of this line is deduced): spec = i; | - |
1185 | break; executed: break; Execution Count:758 | 758 |
1186 | } | - |
1187 | } executed: } Execution Count:720 | 720 |
1188 | | - |
1189 | initAccess(); executed (the execution status of this line is deduced): initAccess(); | - |
1190 | } executed: } Execution Count:758 | 758 |
1191 | | - |
1192 | QConfFileSettingsPrivate::QConfFileSettingsPrivate(const QString &fileName, | - |
1193 | QSettings::Format format) | - |
1194 | : QSettingsPrivate(format), | - |
1195 | nextPosition(0x40000000) // big positive number | - |
1196 | { | - |
1197 | initFormat(); executed (the execution status of this line is deduced): initFormat(); | - |
1198 | | - |
1199 | confFiles[0].reset(QConfFile::fromName(fileName, true)); executed (the execution status of this line is deduced): confFiles[0].reset(QConfFile::fromName(fileName, true)); | - |
1200 | | - |
1201 | initAccess(); executed (the execution status of this line is deduced): initAccess(); | - |
1202 | } executed: } Execution Count:44 | 44 |
1203 | | - |
1204 | QConfFileSettingsPrivate::~QConfFileSettingsPrivate() | - |
1205 | { | - |
1206 | QMutexLocker locker(&settingsGlobalMutex); executed (the execution status of this line is deduced): QMutexLocker locker(&settingsGlobalMutex); | - |
1207 | ConfFileHash *usedHash = usedHashFunc(); executed (the execution status of this line is deduced): ConfFileHash *usedHash = usedHashFunc(); | - |
1208 | ConfFileCache *unusedCache = unusedCacheFunc(); executed (the execution status of this line is deduced): ConfFileCache *unusedCache = unusedCacheFunc(); | - |
1209 | | - |
1210 | for (int i = 0; i < NumConfFiles; ++i) { evaluated: i < NumConfFiles yes Evaluation Count:3208 | yes Evaluation Count:802 |
| 802-3208 |
1211 | if (confFiles[i] && !confFiles[i]->ref.deref()) { evaluated: confFiles[i] yes Evaluation Count:1771 | yes Evaluation Count:1437 |
evaluated: !confFiles[i]->ref.deref() yes Evaluation Count:1220 | yes Evaluation Count:551 |
| 551-1771 |
1212 | if (confFiles[i]->size == 0) { evaluated: confFiles[i]->size == 0 yes Evaluation Count:910 | yes Evaluation Count:310 |
| 310-910 |
1213 | delete confFiles[i].take(); executed (the execution status of this line is deduced): delete confFiles[i].take(); | - |
1214 | } else { executed: } Execution Count:910 | 910 |
1215 | if (usedHash) partially evaluated: usedHash yes Evaluation Count:310 | no Evaluation Count:0 |
| 0-310 |
1216 | usedHash->remove(confFiles[i]->name); executed: usedHash->remove(confFiles[i]->name); Execution Count:310 | 310 |
1217 | if (unusedCache) { partially evaluated: unusedCache yes Evaluation Count:310 | no Evaluation Count:0 |
| 0-310 |
1218 | QT_TRY { | - |
1219 | // compute a better size? | - |
1220 | unusedCache->insert(confFiles[i]->name, confFiles[i].data(), executed (the execution status of this line is deduced): unusedCache->insert(confFiles[i]->name, confFiles[i].data(), | - |
1221 | 10 + (confFiles[i]->originalKeys.size() / 4)); executed (the execution status of this line is deduced): 10 + (confFiles[i]->originalKeys.size() / 4)); | - |
1222 | confFiles[i].take(); executed (the execution status of this line is deduced): confFiles[i].take(); | - |
1223 | } QT_CATCH(...) { executed: } Execution Count:310 | 310 |
1224 | // out of memory. Do not cache the file. | - |
1225 | delete confFiles[i].take(); never executed (the execution status of this line is deduced): delete confFiles[i].take(); | - |
1226 | } | 0 |
1227 | } else { executed: } Execution Count:310 | 310 |
1228 | // unusedCache is gone - delete the entry to prevent a memory leak | - |
1229 | delete confFiles[i].take(); never executed (the execution status of this line is deduced): delete confFiles[i].take(); | - |
1230 | } | 0 |
1231 | } | - |
1232 | } | - |
1233 | // prevent the ScopedPointer to deref it again. | - |
1234 | confFiles[i].take(); executed (the execution status of this line is deduced): confFiles[i].take(); | - |
1235 | } executed: } Execution Count:3208 | 3208 |
1236 | } executed: } Execution Count:802 | 802 |
1237 | | - |
1238 | void QConfFileSettingsPrivate::remove(const QString &key) | - |
1239 | { | - |
1240 | QConfFile *confFile = confFiles[spec].data(); executed (the execution status of this line is deduced): QConfFile *confFile = confFiles[spec].data(); | - |
1241 | if (!confFile) partially evaluated: !confFile no Evaluation Count:0 | yes Evaluation Count:125 |
| 0-125 |
1242 | return; | 0 |
1243 | | - |
1244 | QSettingsKey theKey(key, caseSensitivity); executed (the execution status of this line is deduced): QSettingsKey theKey(key, caseSensitivity); | - |
1245 | QSettingsKey prefix(key + QLatin1Char('/'), caseSensitivity); executed (the execution status of this line is deduced): QSettingsKey prefix(key + QLatin1Char('/'), caseSensitivity); | - |
1246 | QMutexLocker locker(&confFile->mutex); executed (the execution status of this line is deduced): QMutexLocker locker(&confFile->mutex); | - |
1247 | | - |
1248 | ensureSectionParsed(confFile, theKey); executed (the execution status of this line is deduced): ensureSectionParsed(confFile, theKey); | - |
1249 | ensureSectionParsed(confFile, prefix); executed (the execution status of this line is deduced): ensureSectionParsed(confFile, prefix); | - |
1250 | | - |
1251 | ParsedSettingsMap::iterator i = confFile->addedKeys.lowerBound(prefix); executed (the execution status of this line is deduced): ParsedSettingsMap::iterator i = confFile->addedKeys.lowerBound(prefix); | - |
1252 | while (i != confFile->addedKeys.end() && i.key().startsWith(prefix)) evaluated: i != confFile->addedKeys.end() yes Evaluation Count:25 | yes Evaluation Count:112 |
evaluated: i.key().startsWith(prefix) yes Evaluation Count:12 | yes Evaluation Count:13 |
| 12-112 |
1253 | i = confFile->addedKeys.erase(i); executed: i = confFile->addedKeys.erase(i); Execution Count:12 | 12 |
1254 | confFile->addedKeys.remove(theKey); executed (the execution status of this line is deduced): confFile->addedKeys.remove(theKey); | - |
1255 | | - |
1256 | ParsedSettingsMap::const_iterator j = const_cast<const ParsedSettingsMap *>(&confFile->originalKeys)->lowerBound(prefix); executed (the execution status of this line is deduced): ParsedSettingsMap::const_iterator j = const_cast<const ParsedSettingsMap *>(&confFile->originalKeys)->lowerBound(prefix); | - |
1257 | while (j != confFile->originalKeys.constEnd() && j.key().startsWith(prefix)) { evaluated: j != confFile->originalKeys.constEnd() yes Evaluation Count:18 | yes Evaluation Count:109 |
evaluated: j.key().startsWith(prefix) yes Evaluation Count:2 | yes Evaluation Count:16 |
| 2-109 |
1258 | confFile->removedKeys.insert(j.key(), QVariant()); executed (the execution status of this line is deduced): confFile->removedKeys.insert(j.key(), QVariant()); | - |
1259 | ++j; executed (the execution status of this line is deduced): ++j; | - |
1260 | } executed: } Execution Count:2 | 2 |
1261 | if (confFile->originalKeys.contains(theKey)) evaluated: confFile->originalKeys.contains(theKey) yes Evaluation Count:89 | yes Evaluation Count:36 |
| 36-89 |
1262 | confFile->removedKeys.insert(theKey, QVariant()); executed: confFile->removedKeys.insert(theKey, QVariant()); Execution Count:89 | 89 |
1263 | } executed: } Execution Count:125 | 125 |
1264 | | - |
1265 | void QConfFileSettingsPrivate::set(const QString &key, const QVariant &value) | - |
1266 | { | - |
1267 | QConfFile *confFile = confFiles[spec].data(); executed (the execution status of this line is deduced): QConfFile *confFile = confFiles[spec].data(); | - |
1268 | if (!confFile) partially evaluated: !confFile no Evaluation Count:0 | yes Evaluation Count:834 |
| 0-834 |
1269 | return; | 0 |
1270 | | - |
1271 | QSettingsKey theKey(key, caseSensitivity, nextPosition++); executed (the execution status of this line is deduced): QSettingsKey theKey(key, caseSensitivity, nextPosition++); | - |
1272 | QMutexLocker locker(&confFile->mutex); executed (the execution status of this line is deduced): QMutexLocker locker(&confFile->mutex); | - |
1273 | confFile->removedKeys.remove(theKey); executed (the execution status of this line is deduced): confFile->removedKeys.remove(theKey); | - |
1274 | confFile->addedKeys.insert(theKey, value); executed (the execution status of this line is deduced): confFile->addedKeys.insert(theKey, value); | - |
1275 | } executed: } Execution Count:834 | 834 |
1276 | | - |
1277 | bool QConfFileSettingsPrivate::get(const QString &key, QVariant *value) const | - |
1278 | { | - |
1279 | QSettingsKey theKey(key, caseSensitivity); executed (the execution status of this line is deduced): QSettingsKey theKey(key, caseSensitivity); | - |
1280 | ParsedSettingsMap::const_iterator j; executed (the execution status of this line is deduced): ParsedSettingsMap::const_iterator j; | - |
1281 | bool found = false; executed (the execution status of this line is deduced): bool found = false; | - |
1282 | | - |
1283 | for (int i = 0; i < NumConfFiles; ++i) { evaluated: i < NumConfFiles yes Evaluation Count:6307 | yes Evaluation Count:939 |
| 939-6307 |
1284 | if (QConfFile *confFile = confFiles[i].data()) { evaluated: QConfFile *confFile = confFiles[i].data() yes Evaluation Count:3145 | yes Evaluation Count:3162 |
| 3145-3162 |
1285 | QMutexLocker locker(&confFile->mutex); executed (the execution status of this line is deduced): QMutexLocker locker(&confFile->mutex); | - |
1286 | | - |
1287 | if (!confFile->addedKeys.isEmpty()) { evaluated: !confFile->addedKeys.isEmpty() yes Evaluation Count:699 | yes Evaluation Count:2446 |
| 699-2446 |
1288 | j = confFile->addedKeys.constFind(theKey); executed (the execution status of this line is deduced): j = confFile->addedKeys.constFind(theKey); | - |
1289 | found = (j != confFile->addedKeys.constEnd()); executed (the execution status of this line is deduced): found = (j != confFile->addedKeys.constEnd()); | - |
1290 | } executed: } Execution Count:699 | 699 |
1291 | if (!found) { evaluated: !found yes Evaluation Count:2568 | yes Evaluation Count:577 |
| 577-2568 |
1292 | ensureSectionParsed(confFile, theKey); executed (the execution status of this line is deduced): ensureSectionParsed(confFile, theKey); | - |
1293 | j = confFile->originalKeys.constFind(theKey); executed (the execution status of this line is deduced): j = confFile->originalKeys.constFind(theKey); | - |
1294 | found = (j != confFile->originalKeys.constEnd() evaluated: j != confFile->originalKeys.constEnd() yes Evaluation Count:1197 | yes Evaluation Count:1371 |
| 1197-1371 |
1295 | && !confFile->removedKeys.contains(theKey)); evaluated: !confFile->removedKeys.contains(theKey) yes Evaluation Count:1192 | yes Evaluation Count:5 |
| 5-1192 |
1296 | } executed: } Execution Count:2568 | 2568 |
1297 | | - |
1298 | if (found && value) evaluated: found yes Evaluation Count:1769 | yes Evaluation Count:1376 |
evaluated: value yes Evaluation Count:1662 | yes Evaluation Count:107 |
| 107-1769 |
1299 | *value = *j; executed: *value = *j; Execution Count:1662 | 1662 |
1300 | | - |
1301 | if (found) evaluated: found yes Evaluation Count:1769 | yes Evaluation Count:1376 |
| 1376-1769 |
1302 | return true; executed: return true; Execution Count:1769 | 1769 |
1303 | if (!fallbacks) evaluated: !fallbacks yes Evaluation Count:24 | yes Evaluation Count:1352 |
| 24-1352 |
1304 | break; executed: break; Execution Count:24 | 24 |
1305 | } executed: } Execution Count:1352 | 1352 |
1306 | } executed: } Execution Count:4514 | 4514 |
1307 | return false; executed: return false; Execution Count:963 | 963 |
1308 | } | - |
1309 | | - |
1310 | QStringList QConfFileSettingsPrivate::children(const QString &prefix, ChildSpec spec) const | - |
1311 | { | - |
1312 | QMap<QString, QString> result; executed (the execution status of this line is deduced): QMap<QString, QString> result; | - |
1313 | ParsedSettingsMap::const_iterator j; executed (the execution status of this line is deduced): ParsedSettingsMap::const_iterator j; | - |
1314 | | - |
1315 | QSettingsKey thePrefix(prefix, caseSensitivity); executed (the execution status of this line is deduced): QSettingsKey thePrefix(prefix, caseSensitivity); | - |
1316 | int startPos = prefix.size(); executed (the execution status of this line is deduced): int startPos = prefix.size(); | - |
1317 | | - |
1318 | for (int i = 0; i < NumConfFiles; ++i) { evaluated: i < NumConfFiles yes Evaluation Count:544 | yes Evaluation Count:116 |
| 116-544 |
1319 | if (QConfFile *confFile = confFiles[i].data()) { evaluated: QConfFile *confFile = confFiles[i].data() yes Evaluation Count:421 | yes Evaluation Count:123 |
| 123-421 |
1320 | QMutexLocker locker(&confFile->mutex); executed (the execution status of this line is deduced): QMutexLocker locker(&confFile->mutex); | - |
1321 | | - |
1322 | if (thePrefix.isEmpty()) { evaluated: thePrefix.isEmpty() yes Evaluation Count:117 | yes Evaluation Count:304 |
| 117-304 |
1323 | ensureAllSectionsParsed(confFile); executed (the execution status of this line is deduced): ensureAllSectionsParsed(confFile); | - |
1324 | } else { executed: } Execution Count:117 | 117 |
1325 | ensureSectionParsed(confFile, thePrefix); executed (the execution status of this line is deduced): ensureSectionParsed(confFile, thePrefix); | - |
1326 | } executed: } Execution Count:304 | 304 |
1327 | | - |
1328 | j = const_cast<const ParsedSettingsMap *>( executed (the execution status of this line is deduced): j = const_cast<const ParsedSettingsMap *>( | - |
1329 | &confFile->originalKeys)->lowerBound( thePrefix); executed (the execution status of this line is deduced): &confFile->originalKeys)->lowerBound( thePrefix); | - |
1330 | while (j != confFile->originalKeys.constEnd() && j.key().startsWith(thePrefix)) { evaluated: j != confFile->originalKeys.constEnd() yes Evaluation Count:1208 | yes Evaluation Count:409 |
evaluated: j.key().startsWith(thePrefix) yes Evaluation Count:1196 | yes Evaluation Count:12 |
| 12-1208 |
1331 | if (!confFile->removedKeys.contains(j.key())) evaluated: !confFile->removedKeys.contains(j.key()) yes Evaluation Count:1190 | yes Evaluation Count:6 |
| 6-1190 |
1332 | processChild(j.key().originalCaseKey().mid(startPos), spec, result); executed: processChild(j.key().originalCaseKey().mid(startPos), spec, result); Execution Count:1190 | 1190 |
1333 | ++j; executed (the execution status of this line is deduced): ++j; | - |
1334 | } executed: } Execution Count:1196 | 1196 |
1335 | | - |
1336 | j = const_cast<const ParsedSettingsMap *>( executed (the execution status of this line is deduced): j = const_cast<const ParsedSettingsMap *>( | - |
1337 | &confFile->addedKeys)->lowerBound(thePrefix); executed (the execution status of this line is deduced): &confFile->addedKeys)->lowerBound(thePrefix); | - |
1338 | while (j != confFile->addedKeys.constEnd() && j.key().startsWith(thePrefix)) { evaluated: j != confFile->addedKeys.constEnd() yes Evaluation Count:404 | yes Evaluation Count:384 |
evaluated: j.key().startsWith(thePrefix) yes Evaluation Count:367 | yes Evaluation Count:37 |
| 37-404 |
1339 | processChild(j.key().originalCaseKey().mid(startPos), spec, result); executed (the execution status of this line is deduced): processChild(j.key().originalCaseKey().mid(startPos), spec, result); | - |
1340 | ++j; executed (the execution status of this line is deduced): ++j; | - |
1341 | } executed: } Execution Count:367 | 367 |
1342 | | - |
1343 | if (!fallbacks) evaluated: !fallbacks yes Evaluation Count:40 | yes Evaluation Count:381 |
| 40-381 |
1344 | break; executed: break; Execution Count:40 | 40 |
1345 | } executed: } Execution Count:381 | 381 |
1346 | } executed: } Execution Count:504 | 504 |
1347 | return result.keys(); executed: return result.keys(); Execution Count:156 | 156 |
1348 | } | - |
1349 | | - |
1350 | void QConfFileSettingsPrivate::clear() | - |
1351 | { | - |
1352 | QConfFile *confFile = confFiles[spec].data(); executed (the execution status of this line is deduced): QConfFile *confFile = confFiles[spec].data(); | - |
1353 | if (!confFile) partially evaluated: !confFile no Evaluation Count:0 | yes Evaluation Count:15 |
| 0-15 |
1354 | return; | 0 |
1355 | | - |
1356 | QMutexLocker locker(&confFile->mutex); executed (the execution status of this line is deduced): QMutexLocker locker(&confFile->mutex); | - |
1357 | ensureAllSectionsParsed(confFile); executed (the execution status of this line is deduced): ensureAllSectionsParsed(confFile); | - |
1358 | confFile->addedKeys.clear(); executed (the execution status of this line is deduced): confFile->addedKeys.clear(); | - |
1359 | confFile->removedKeys = confFile->originalKeys; executed (the execution status of this line is deduced): confFile->removedKeys = confFile->originalKeys; | - |
1360 | } executed: } Execution Count:15 | 15 |
1361 | | - |
1362 | void QConfFileSettingsPrivate::sync() | - |
1363 | { | - |
1364 | // people probably won't be checking the status a whole lot, so in case of | - |
1365 | // error we just try to go on and make the best of it | - |
1366 | | - |
1367 | for (int i = 0; i < NumConfFiles; ++i) { evaluated: i < NumConfFiles yes Evaluation Count:5435 | yes Evaluation Count:1359 |
| 1359-5435 |
1368 | QConfFile *confFile = confFiles[i].data(); executed (the execution status of this line is deduced): QConfFile *confFile = confFiles[i].data(); | - |
1369 | if (confFile) { evaluated: confFile yes Evaluation Count:3037 | yes Evaluation Count:2398 |
| 2398-3037 |
1370 | QMutexLocker locker(&confFile->mutex); executed (the execution status of this line is deduced): QMutexLocker locker(&confFile->mutex); | - |
1371 | syncConfFile(i); executed (the execution status of this line is deduced): syncConfFile(i); | - |
1372 | } executed: } Execution Count:3038 | 3038 |
1373 | } executed: } Execution Count:5436 | 5436 |
1374 | } executed: } Execution Count:1359 | 1359 |
1375 | | - |
1376 | void QConfFileSettingsPrivate::flush() | - |
1377 | { | - |
1378 | sync(); executed (the execution status of this line is deduced): sync(); | - |
1379 | } executed: } Execution Count:495 | 495 |
1380 | | - |
1381 | QString QConfFileSettingsPrivate::fileName() const | - |
1382 | { | - |
1383 | QConfFile *confFile = confFiles[spec].data(); executed (the execution status of this line is deduced): QConfFile *confFile = confFiles[spec].data(); | - |
1384 | if (!confFile) partially evaluated: !confFile no Evaluation Count:0 | yes Evaluation Count:25 |
| 0-25 |
1385 | return QString(); never executed: return QString(); | 0 |
1386 | return confFile->name; executed: return confFile->name; Execution Count:25 | 25 |
1387 | } | - |
1388 | | - |
1389 | bool QConfFileSettingsPrivate::isWritable() const | - |
1390 | { | - |
1391 | if (format > QSettings::IniFormat && !writeFunc) evaluated: format > QSettings::IniFormat yes Evaluation Count:12 | yes Evaluation Count:9 |
evaluated: !writeFunc yes Evaluation Count:1 | yes Evaluation Count:11 |
| 1-12 |
1392 | return false; executed: return false; Execution Count:1 | 1 |
1393 | | - |
1394 | QConfFile *confFile = confFiles[spec].data(); executed (the execution status of this line is deduced): QConfFile *confFile = confFiles[spec].data(); | - |
1395 | if (!confFile) partially evaluated: !confFile no Evaluation Count:0 | yes Evaluation Count:20 |
| 0-20 |
1396 | return false; never executed: return false; | 0 |
1397 | | - |
1398 | return confFile->isWritable(); executed: return confFile->isWritable(); Execution Count:20 | 20 |
1399 | } | - |
1400 | | - |
1401 | void QConfFileSettingsPrivate::syncConfFile(int confFileNo) | - |
1402 | { | - |
1403 | QConfFile *confFile = confFiles[confFileNo].data(); executed (the execution status of this line is deduced): QConfFile *confFile = confFiles[confFileNo].data(); | - |
1404 | bool readOnly = confFile->addedKeys.isEmpty() && confFile->removedKeys.isEmpty(); evaluated: confFile->addedKeys.isEmpty() yes Evaluation Count:2629 | yes Evaluation Count:408 |
evaluated: confFile->removedKeys.isEmpty() yes Evaluation Count:2542 | yes Evaluation Count:87 |
| 87-2629 |
1405 | bool ok; executed (the execution status of this line is deduced): bool ok; | - |
1406 | | - |
1407 | /* | - |
1408 | We can often optimize the read-only case, if the file on disk | - |
1409 | hasn't changed. | - |
1410 | */ | - |
1411 | if (readOnly && confFile->size > 0) { evaluated: readOnly yes Evaluation Count:2542 | yes Evaluation Count:495 |
evaluated: confFile->size > 0 yes Evaluation Count:356 | yes Evaluation Count:2186 |
| 356-2542 |
1412 | QFileInfo fileInfo(confFile->name); executed (the execution status of this line is deduced): QFileInfo fileInfo(confFile->name); | - |
1413 | if (confFile->size == fileInfo.size() && confFile->timeStamp == fileInfo.lastModified()) evaluated: confFile->size == fileInfo.size() yes Evaluation Count:324 | yes Evaluation Count:32 |
partially evaluated: confFile->timeStamp == fileInfo.lastModified() yes Evaluation Count:324 | no Evaluation Count:0 |
| 0-324 |
1414 | return; executed: return; Execution Count:324 | 324 |
1415 | } executed: } Execution Count:32 | 32 |
1416 | | - |
1417 | /* | - |
1418 | Open the configuration file and try to use it using a named | - |
1419 | semaphore on Windows and an advisory lock on Unix-based | - |
1420 | systems. This protect us against other QSettings instances | - |
1421 | trying to access the same file from other threads or | - |
1422 | processes. | - |
1423 | | - |
1424 | As it stands now, the locking mechanism doesn't work for | - |
1425 | .plist files. | - |
1426 | */ | - |
1427 | QFile file(confFile->name); executed (the execution status of this line is deduced): QFile file(confFile->name); | - |
1428 | bool createFile = !file.exists(); executed (the execution status of this line is deduced): bool createFile = !file.exists(); | - |
1429 | if (!readOnly && confFile->isWritable()) evaluated: !readOnly yes Evaluation Count:495 | yes Evaluation Count:2219 |
evaluated: confFile->isWritable() yes Evaluation Count:493 | yes Evaluation Count:2 |
| 2-2219 |
1430 | file.open(QFile::ReadWrite); executed: file.open(QFile::ReadWrite); Execution Count:493 | 493 |
1431 | if (!file.isOpen()) evaluated: !file.isOpen() yes Evaluation Count:2221 | yes Evaluation Count:493 |
| 493-2221 |
1432 | file.open(QFile::ReadOnly); executed: file.open(QFile::ReadOnly); Execution Count:2221 | 2221 |
1433 | | - |
1434 | if (!createFile && !file.isOpen()) evaluated: !createFile yes Evaluation Count:859 | yes Evaluation Count:1855 |
partially evaluated: !file.isOpen() no Evaluation Count:0 | yes Evaluation Count:859 |
| 0-1855 |
1435 | setStatus(QSettings::AccessError); never executed: setStatus(QSettings::AccessError); | 0 |
1436 | | - |
1437 | #ifdef Q_OS_WIN | - |
1438 | HANDLE readSemaphore = 0; | - |
1439 | HANDLE writeSemaphore = 0; | - |
1440 | static const int FileLockSemMax = 50; | - |
1441 | int numReadLocks = readOnly ? 1 : FileLockSemMax; | - |
1442 | | - |
1443 | if (file.isOpen()) { | - |
1444 | // Acquire the write lock if we will be writing | - |
1445 | if (!readOnly) { | - |
1446 | QString writeSemName = QLatin1String("QSettingsWriteSem "); | - |
1447 | writeSemName.append(file.fileName()); | - |
1448 | | - |
1449 | writeSemaphore = CreateSemaphore(0, 1, 1, reinterpret_cast<const wchar_t *>(writeSemName.utf16())); | - |
1450 | | - |
1451 | if (writeSemaphore) { | - |
1452 | WaitForSingleObject(writeSemaphore, INFINITE); | - |
1453 | } else { | - |
1454 | setStatus(QSettings::AccessError); | - |
1455 | return; | - |
1456 | } | - |
1457 | } | - |
1458 | | - |
1459 | // Acquire all the read locks if we will be writing, to make sure nobody | - |
1460 | // reads while we're writing. If we are only reading, acquire a single | - |
1461 | // read lock. | - |
1462 | QString readSemName(QLatin1String("QSettingsReadSem ")); | - |
1463 | readSemName.append(file.fileName()); | - |
1464 | | - |
1465 | readSemaphore = CreateSemaphore(0, FileLockSemMax, FileLockSemMax, reinterpret_cast<const wchar_t *>(readSemName.utf16())); | - |
1466 | | - |
1467 | if (readSemaphore) { | - |
1468 | for (int i = 0; i < numReadLocks; ++i) | - |
1469 | WaitForSingleObject(readSemaphore, INFINITE); | - |
1470 | } else { | - |
1471 | setStatus(QSettings::AccessError); | - |
1472 | if (writeSemaphore != 0) { | - |
1473 | ReleaseSemaphore(writeSemaphore, 1, 0); | - |
1474 | CloseHandle(writeSemaphore); | - |
1475 | } | - |
1476 | return; | - |
1477 | } | - |
1478 | } | - |
1479 | #else | - |
1480 | if (file.isOpen()) evaluated: file.isOpen() yes Evaluation Count:949 | yes Evaluation Count:1765 |
| 949-1765 |
1481 | unixLock(file.handle(), readOnly ? F_RDLCK : F_WRLCK); executed: unixLock(file.handle(), readOnly ? 0 : 1); Execution Count:949 | 949 |
1482 | #endif | - |
1483 | | - |
1484 | // If we have created the file, apply the file perms | - |
1485 | if (file.isOpen()) { evaluated: file.isOpen() yes Evaluation Count:949 | yes Evaluation Count:1765 |
| 949-1765 |
1486 | if (createFile) { evaluated: createFile yes Evaluation Count:90 | yes Evaluation Count:859 |
| 90-859 |
1487 | QFile::Permissions perms = file.permissions() | QFile::ReadOwner | QFile::WriteOwner; executed (the execution status of this line is deduced): QFile::Permissions perms = file.permissions() | QFile::ReadOwner | QFile::WriteOwner; | - |
1488 | if (!confFile->userPerms) evaluated: !confFile->userPerms yes Evaluation Count:20 | yes Evaluation Count:70 |
| 20-70 |
1489 | perms |= QFile::ReadGroup | QFile::ReadOther; executed: perms |= QFile::ReadGroup | QFile::ReadOther; Execution Count:20 | 20 |
1490 | file.setPermissions(perms); executed (the execution status of this line is deduced): file.setPermissions(perms); | - |
1491 | } executed: } Execution Count:90 | 90 |
1492 | } executed: } Execution Count:949 | 949 |
1493 | | - |
1494 | /* | - |
1495 | We hold the lock. Let's reread the file if it has changed | - |
1496 | since last time we read it. | - |
1497 | */ | - |
1498 | QFileInfo fileInfo(confFile->name); executed (the execution status of this line is deduced): QFileInfo fileInfo(confFile->name); | - |
1499 | bool mustReadFile = true; executed (the execution status of this line is deduced): bool mustReadFile = true; | - |
1500 | | - |
1501 | if (!readOnly) evaluated: !readOnly yes Evaluation Count:495 | yes Evaluation Count:2219 |
| 495-2219 |
1502 | mustReadFile = (confFile->size != fileInfo.size() executed: mustReadFile = (confFile->size != fileInfo.size() || (confFile->size != 0 && confFile->timeStamp != fileInfo.lastModified())); Execution Count:495 evaluated: confFile->size != fileInfo.size() yes Evaluation Count:14 | yes Evaluation Count:481 |
| 14-495 |
1503 | || (confFile->size != 0 && confFile->timeStamp != fileInfo.lastModified())); executed: mustReadFile = (confFile->size != fileInfo.size() || (confFile->size != 0 && confFile->timeStamp != fileInfo.lastModified())); Execution Count:495 evaluated: confFile->size != 0 yes Evaluation Count:390 | yes Evaluation Count:91 |
partially evaluated: confFile->timeStamp != fileInfo.lastModified() no Evaluation Count:0 | yes Evaluation Count:390 |
| 0-495 |
1504 | | - |
1505 | if (mustReadFile) { evaluated: mustReadFile yes Evaluation Count:2233 | yes Evaluation Count:481 |
| 481-2233 |
1506 | confFile->unparsedIniSections.clear(); executed (the execution status of this line is deduced): confFile->unparsedIniSections.clear(); | - |
1507 | confFile->originalKeys.clear(); executed (the execution status of this line is deduced): confFile->originalKeys.clear(); | - |
1508 | | - |
1509 | /* | - |
1510 | Files that we can't read (because of permissions or | - |
1511 | because they don't exist) are treated as empty files. | - |
1512 | */ | - |
1513 | if (file.isReadable() && fileInfo.size() != 0) { evaluated: file.isReadable() yes Evaluation Count:468 | yes Evaluation Count:1765 |
evaluated: fileInfo.size() != 0 yes Evaluation Count:466 | yes Evaluation Count:2 |
| 2-1765 |
1514 | #ifdef Q_OS_MAC | - |
1515 | if (format == QSettings::NativeFormat) { | - |
1516 | ok = readPlistFile(confFile->name, &confFile->originalKeys); | - |
1517 | } else | - |
1518 | #endif | - |
1519 | { | - |
1520 | if (format <= QSettings::IniFormat) { evaluated: format <= QSettings::IniFormat yes Evaluation Count:431 | yes Evaluation Count:35 |
| 35-431 |
1521 | QByteArray data = file.readAll(); executed (the execution status of this line is deduced): QByteArray data = file.readAll(); | - |
1522 | ok = readIniFile(data, &confFile->unparsedIniSections); executed (the execution status of this line is deduced): ok = readIniFile(data, &confFile->unparsedIniSections); | - |
1523 | } else { executed: } Execution Count:431 | 431 |
1524 | if (readFunc) { partially evaluated: readFunc yes Evaluation Count:35 | no Evaluation Count:0 |
| 0-35 |
1525 | QSettings::SettingsMap tempNewKeys; executed (the execution status of this line is deduced): QSettings::SettingsMap tempNewKeys; | - |
1526 | ok = readFunc(file, tempNewKeys); executed (the execution status of this line is deduced): ok = readFunc(file, tempNewKeys); | - |
1527 | | - |
1528 | if (ok) { evaluated: ok yes Evaluation Count:34 | yes Evaluation Count:1 |
| 1-34 |
1529 | QSettings::SettingsMap::const_iterator i = tempNewKeys.constBegin(); executed (the execution status of this line is deduced): QSettings::SettingsMap::const_iterator i = tempNewKeys.constBegin(); | - |
1530 | while (i != tempNewKeys.constEnd()) { evaluated: i != tempNewKeys.constEnd() yes Evaluation Count:118 | yes Evaluation Count:34 |
| 34-118 |
1531 | confFile->originalKeys.insert(QSettingsKey(i.key(), executed (the execution status of this line is deduced): confFile->originalKeys.insert(QSettingsKey(i.key(), | - |
1532 | caseSensitivity), executed (the execution status of this line is deduced): caseSensitivity), | - |
1533 | i.value()); executed (the execution status of this line is deduced): i.value()); | - |
1534 | ++i; executed (the execution status of this line is deduced): ++i; | - |
1535 | } executed: } Execution Count:118 | 118 |
1536 | } executed: } Execution Count:34 | 34 |
1537 | } else { executed: } Execution Count:35 | 35 |
1538 | ok = false; never executed (the execution status of this line is deduced): ok = false; | - |
1539 | } | 0 |
1540 | } | - |
1541 | } | - |
1542 | | - |
1543 | if (!ok) evaluated: !ok yes Evaluation Count:1 | yes Evaluation Count:465 |
| 1-465 |
1544 | setStatus(QSettings::FormatError); executed: setStatus(QSettings::FormatError); Execution Count:1 | 1 |
1545 | } executed: } Execution Count:466 | 466 |
1546 | | - |
1547 | confFile->size = fileInfo.size(); executed (the execution status of this line is deduced): confFile->size = fileInfo.size(); | - |
1548 | confFile->timeStamp = fileInfo.lastModified(); executed (the execution status of this line is deduced): confFile->timeStamp = fileInfo.lastModified(); | - |
1549 | } executed: } Execution Count:2233 | 2233 |
1550 | | - |
1551 | /* | - |
1552 | We also need to save the file. We still hold the file lock, | - |
1553 | so everything is under control. | - |
1554 | */ | - |
1555 | if (!readOnly) { evaluated: !readOnly yes Evaluation Count:495 | yes Evaluation Count:2219 |
| 495-2219 |
1556 | ensureAllSectionsParsed(confFile); executed (the execution status of this line is deduced): ensureAllSectionsParsed(confFile); | - |
1557 | ParsedSettingsMap mergedKeys = confFile->mergedKeyMap(); executed (the execution status of this line is deduced): ParsedSettingsMap mergedKeys = confFile->mergedKeyMap(); | - |
1558 | | - |
1559 | if (file.isWritable()) { evaluated: file.isWritable() yes Evaluation Count:493 | yes Evaluation Count:2 |
| 2-493 |
1560 | #ifdef Q_OS_MAC | - |
1561 | if (format == QSettings::NativeFormat) { | - |
1562 | ok = writePlistFile(confFile->name, mergedKeys); | - |
1563 | } else | - |
1564 | #endif | - |
1565 | { | - |
1566 | file.seek(0); executed (the execution status of this line is deduced): file.seek(0); | - |
1567 | file.resize(0); executed (the execution status of this line is deduced): file.resize(0); | - |
1568 | | - |
1569 | if (format <= QSettings::IniFormat) { evaluated: format <= QSettings::IniFormat yes Evaluation Count:450 | yes Evaluation Count:43 |
| 43-450 |
1570 | ok = writeIniFile(file, mergedKeys); executed (the execution status of this line is deduced): ok = writeIniFile(file, mergedKeys); | - |
1571 | if (!ok) { partially evaluated: !ok no Evaluation Count:0 | yes Evaluation Count:450 |
| 0-450 |
1572 | // try to restore old data; might work if the disk was full and the new data | - |
1573 | // was larger than the old data | - |
1574 | file.seek(0); never executed (the execution status of this line is deduced): file.seek(0); | - |
1575 | file.resize(0); never executed (the execution status of this line is deduced): file.resize(0); | - |
1576 | writeIniFile(file, confFile->originalKeys); never executed (the execution status of this line is deduced): writeIniFile(file, confFile->originalKeys); | - |
1577 | } | 0 |
1578 | } else { executed: } Execution Count:450 | 450 |
1579 | if (writeFunc) { partially evaluated: writeFunc yes Evaluation Count:43 | no Evaluation Count:0 |
| 0-43 |
1580 | QSettings::SettingsMap tempOriginalKeys; executed (the execution status of this line is deduced): QSettings::SettingsMap tempOriginalKeys; | - |
1581 | | - |
1582 | ParsedSettingsMap::const_iterator i = mergedKeys.constBegin(); executed (the execution status of this line is deduced): ParsedSettingsMap::const_iterator i = mergedKeys.constBegin(); | - |
1583 | while (i != mergedKeys.constEnd()) { evaluated: i != mergedKeys.constEnd() yes Evaluation Count:155 | yes Evaluation Count:43 |
| 43-155 |
1584 | tempOriginalKeys.insert(i.key(), i.value()); executed (the execution status of this line is deduced): tempOriginalKeys.insert(i.key(), i.value()); | - |
1585 | ++i; executed (the execution status of this line is deduced): ++i; | - |
1586 | } executed: } Execution Count:155 | 155 |
1587 | ok = writeFunc(file, tempOriginalKeys); executed (the execution status of this line is deduced): ok = writeFunc(file, tempOriginalKeys); | - |
1588 | } else { executed: } Execution Count:43 | 43 |
1589 | ok = false; never executed (the execution status of this line is deduced): ok = false; | - |
1590 | } | 0 |
1591 | } | - |
1592 | } | - |
1593 | } else { | - |
1594 | ok = false; executed (the execution status of this line is deduced): ok = false; | - |
1595 | } executed: } Execution Count:2 | 2 |
1596 | | - |
1597 | if (ok) { evaluated: ok yes Evaluation Count:491 | yes Evaluation Count:4 |
| 4-491 |
1598 | confFile->unparsedIniSections.clear(); executed (the execution status of this line is deduced): confFile->unparsedIniSections.clear(); | - |
1599 | confFile->originalKeys = mergedKeys; executed (the execution status of this line is deduced): confFile->originalKeys = mergedKeys; | - |
1600 | confFile->addedKeys.clear(); executed (the execution status of this line is deduced): confFile->addedKeys.clear(); | - |
1601 | confFile->removedKeys.clear(); executed (the execution status of this line is deduced): confFile->removedKeys.clear(); | - |
1602 | | - |
1603 | QFileInfo fileInfo(confFile->name); executed (the execution status of this line is deduced): QFileInfo fileInfo(confFile->name); | - |
1604 | confFile->size = fileInfo.size(); executed (the execution status of this line is deduced): confFile->size = fileInfo.size(); | - |
1605 | confFile->timeStamp = fileInfo.lastModified(); executed (the execution status of this line is deduced): confFile->timeStamp = fileInfo.lastModified(); | - |
1606 | } else { executed: } Execution Count:491 | 491 |
1607 | setStatus(QSettings::AccessError); executed (the execution status of this line is deduced): setStatus(QSettings::AccessError); | - |
1608 | } executed: } Execution Count:4 | 4 |
1609 | } | - |
1610 | | - |
1611 | /* | - |
1612 | Release the file lock. | - |
1613 | */ | - |
1614 | #ifdef Q_OS_WIN | - |
1615 | if (readSemaphore != 0) { | - |
1616 | ReleaseSemaphore(readSemaphore, numReadLocks, 0); | - |
1617 | CloseHandle(readSemaphore); | - |
1618 | } | - |
1619 | if (writeSemaphore != 0) { | - |
1620 | ReleaseSemaphore(writeSemaphore, 1, 0); | - |
1621 | CloseHandle(writeSemaphore); | - |
1622 | } | - |
1623 | #endif | - |
1624 | } executed: } Execution Count:2714 | 2714 |
1625 | | - |
1626 | enum { Space = 0x1, Special = 0x2 }; | - |
1627 | | - |
1628 | static const char charTraits[256] = | - |
1629 | { | - |
1630 | // Space: '\t', '\n', '\r', ' ' | - |
1631 | // Special: '\n', '\r', '"', ';', '=', '\\' | - |
1632 | | - |
1633 | 0, 0, 0, 0, 0, 0, 0, 0, 0, Space, Space | Special, 0, 0, Space | Special, 0, 0, | - |
1634 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | - |
1635 | Space, 0, Special, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | - |
1636 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, Special, 0, Special, 0, 0, | - |
1637 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | - |
1638 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, Special, 0, 0, 0, | - |
1639 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | - |
1640 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | - |
1641 | | - |
1642 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | - |
1643 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | - |
1644 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | - |
1645 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | - |
1646 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | - |
1647 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | - |
1648 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | - |
1649 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 | - |
1650 | }; | - |
1651 | | - |
1652 | bool QConfFileSettingsPrivate::readIniLine(const QByteArray &data, int &dataPos, | - |
1653 | int &lineStart, int &lineLen, int &equalsPos) | - |
1654 | { | - |
1655 | int dataLen = data.length(); executed (the execution status of this line is deduced): int dataLen = data.length(); | - |
1656 | bool inQuotes = false; executed (the execution status of this line is deduced): bool inQuotes = false; | - |
1657 | | - |
1658 | equalsPos = -1; executed (the execution status of this line is deduced): equalsPos = -1; | - |
1659 | | - |
1660 | lineStart = dataPos; executed (the execution status of this line is deduced): lineStart = dataPos; | - |
1661 | while (lineStart < dataLen && (charTraits[uint(uchar(data.at(lineStart)))] & Space)) evaluated: lineStart < dataLen yes Evaluation Count:30389 | yes Evaluation Count:1425 |
evaluated: (charTraits[uint(uchar(data.at(lineStart)))] & Space) yes Evaluation Count:15701 | yes Evaluation Count:14688 |
| 1425-30389 |
1662 | ++lineStart; executed: ++lineStart; Execution Count:15701 | 15701 |
1663 | | - |
1664 | int i = lineStart; executed (the execution status of this line is deduced): int i = lineStart; | - |
1665 | while (i < dataLen) { evaluated: i < dataLen yes Evaluation Count:226138 | yes Evaluation Count:1425 |
| 1425-226138 |
1666 | while (!(charTraits[uint(uchar(data.at(i)))] & Special)) { evaluated: !(charTraits[uint(uchar(data.at(i)))] & Special) yes Evaluation Count:423578 | yes Evaluation Count:226138 |
| 226138-423578 |
1667 | if (++i == dataLen) partially evaluated: ++i == dataLen no Evaluation Count:0 | yes Evaluation Count:423578 |
| 0-423578 |
1668 | goto break_out_of_outer_loop; never executed: goto break_out_of_outer_loop; | 0 |
1669 | } executed: } Execution Count:423578 | 423578 |
1670 | | - |
1671 | char ch = data.at(i++); executed (the execution status of this line is deduced): char ch = data.at(i++); | - |
1672 | if (ch == '=') { evaluated: ch == '=' yes Evaluation Count:15025 | yes Evaluation Count:211113 |
| 15025-211113 |
1673 | if (!inQuotes && equalsPos == -1) evaluated: !inQuotes yes Evaluation Count:14053 | yes Evaluation Count:972 |
partially evaluated: equalsPos == -1 yes Evaluation Count:14053 | no Evaluation Count:0 |
| 0-14053 |
1674 | equalsPos = i - 1; executed: equalsPos = i - 1; Execution Count:14053 | 14053 |
1675 | } else if (ch == '\n' || ch == '\r') { executed: } Execution Count:15025 evaluated: ch == '\n' yes Evaluation Count:14688 | yes Evaluation Count:196425 |
partially evaluated: ch == '\r' no Evaluation Count:0 | yes Evaluation Count:196425 |
| 0-196425 |
1676 | if (i == lineStart + 1) { partially evaluated: i == lineStart + 1 no Evaluation Count:0 | yes Evaluation Count:14688 |
| 0-14688 |
1677 | ++lineStart; never executed (the execution status of this line is deduced): ++lineStart; | - |
1678 | } else if (!inQuotes) { never executed: } partially evaluated: !inQuotes yes Evaluation Count:14688 | no Evaluation Count:0 |
| 0-14688 |
1679 | --i; executed (the execution status of this line is deduced): --i; | - |
1680 | goto break_out_of_outer_loop; executed: goto break_out_of_outer_loop; Execution Count:14688 | 14688 |
1681 | } | - |
1682 | } else if (ch == '\\') { evaluated: ch == '\\' yes Evaluation Count:195321 | yes Evaluation Count:1104 |
| 1104-195321 |
1683 | if (i < dataLen) { partially evaluated: i < dataLen yes Evaluation Count:195321 | no Evaluation Count:0 |
| 0-195321 |
1684 | char ch = data.at(i++); executed (the execution status of this line is deduced): char ch = data.at(i++); | - |
1685 | if (i < dataLen) { partially evaluated: i < dataLen yes Evaluation Count:195321 | no Evaluation Count:0 |
| 0-195321 |
1686 | char ch2 = data.at(i); executed (the execution status of this line is deduced): char ch2 = data.at(i); | - |
1687 | // \n, \r, \r\n, and \n\r are legitimate line terminators in INI files | - |
1688 | if ((ch == '\n' && ch2 == '\r') || (ch == '\r' && ch2 == '\n')) partially evaluated: ch == '\n' no Evaluation Count:0 | yes Evaluation Count:195321 |
never evaluated: ch2 == '\r' partially evaluated: ch == '\r' no Evaluation Count:0 | yes Evaluation Count:195321 |
never evaluated: ch2 == '\n' | 0-195321 |
1689 | ++i; | 0 |
1690 | } executed: } Execution Count:195321 | 195321 |
1691 | } executed: } Execution Count:195321 | 195321 |
1692 | } else if (ch == '"') { executed: } Execution Count:195321 partially evaluated: ch == '"' yes Evaluation Count:1104 | no Evaluation Count:0 |
| 0-195321 |
1693 | inQuotes = !inQuotes; executed (the execution status of this line is deduced): inQuotes = !inQuotes; | - |
1694 | } else { executed: } Execution Count:1104 | 1104 |
1695 | Q_ASSERT(ch == ';'); never executed (the execution status of this line is deduced): qt_noop(); | - |
1696 | | - |
1697 | if (i == lineStart + 1) { never evaluated: i == lineStart + 1 | 0 |
1698 | char ch; never executed (the execution status of this line is deduced): char ch; | - |
1699 | while (i < dataLen && ((ch = data.at(i) != '\n') && ch != '\r')) never evaluated: i < dataLen never evaluated: (ch = data.at(i) != '\n') never evaluated: ch != '\r' | 0 |
1700 | ++i; | 0 |
1701 | lineStart = i; never executed (the execution status of this line is deduced): lineStart = i; | - |
1702 | } else if (!inQuotes) { never executed: } never evaluated: !inQuotes | 0 |
1703 | --i; never executed (the execution status of this line is deduced): --i; | - |
1704 | goto break_out_of_outer_loop; never executed: goto break_out_of_outer_loop; | 0 |
1705 | } | - |
1706 | } | - |
1707 | } | - |
1708 | | - |
1709 | break_out_of_outer_loop: code before this statement executed: break_out_of_outer_loop: Execution Count:1425 | 1425 |
1710 | dataPos = i; executed (the execution status of this line is deduced): dataPos = i; | - |
1711 | lineLen = i - lineStart; executed (the execution status of this line is deduced): lineLen = i - lineStart; | - |
1712 | return lineLen > 0; executed: return lineLen > 0; Execution Count:16113 | 16113 |
1713 | } | - |
1714 | | - |
1715 | /* | - |
1716 | Returns false on parse error. However, as many keys are read as | - |
1717 | possible, so if the user doesn't check the status he will get the | - |
1718 | most out of the file anyway. | - |
1719 | */ | - |
1720 | bool QConfFileSettingsPrivate::readIniFile(const QByteArray &data, | - |
1721 | UnparsedSettingsMap *unparsedIniSections) | - |
1722 | { | - |
1723 | #define FLUSH_CURRENT_SECTION() \ | - |
1724 | { \ | - |
1725 | QByteArray §ionData = (*unparsedIniSections)[QSettingsKey(currentSection, \ | - |
1726 | IniCaseSensitivity, \ | - |
1727 | sectionPosition)]; \ | - |
1728 | if (!sectionData.isEmpty()) \ | - |
1729 | sectionData.append('\n'); \ | - |
1730 | sectionData += data.mid(currentSectionStart, lineStart - currentSectionStart); \ | - |
1731 | sectionPosition = ++position; \ | - |
1732 | } | - |
1733 | | - |
1734 | QString currentSection; executed (the execution status of this line is deduced): QString currentSection; | - |
1735 | int currentSectionStart = 0; executed (the execution status of this line is deduced): int currentSectionStart = 0; | - |
1736 | int dataPos = 0; executed (the execution status of this line is deduced): int dataPos = 0; | - |
1737 | int lineStart; executed (the execution status of this line is deduced): int lineStart; | - |
1738 | int lineLen; executed (the execution status of this line is deduced): int lineLen; | - |
1739 | int equalsPos; executed (the execution status of this line is deduced): int equalsPos; | - |
1740 | int position = 0; executed (the execution status of this line is deduced): int position = 0; | - |
1741 | int sectionPosition = 0; executed (the execution status of this line is deduced): int sectionPosition = 0; | - |
1742 | bool ok = true; executed (the execution status of this line is deduced): bool ok = true; | - |
1743 | | - |
1744 | while (readIniLine(data, dataPos, lineStart, lineLen, equalsPos)) { evaluated: readIniLine(data, dataPos, lineStart, lineLen, equalsPos) yes Evaluation Count:7679 | yes Evaluation Count:431 |
| 431-7679 |
1745 | char ch = data.at(lineStart); executed (the execution status of this line is deduced): char ch = data.at(lineStart); | - |
1746 | if (ch == '[') { evaluated: ch == '[' yes Evaluation Count:627 | yes Evaluation Count:7052 |
| 627-7052 |
1747 | FLUSH_CURRENT_SECTION(); never executed: sectionData.append('\n'); partially evaluated: !sectionData.isEmpty() no Evaluation Count:0 | yes Evaluation Count:627 |
| 0-627 |
1748 | | - |
1749 | // this is a section | - |
1750 | QByteArray iniSection; executed (the execution status of this line is deduced): QByteArray iniSection; | - |
1751 | int idx = data.indexOf(']', lineStart); executed (the execution status of this line is deduced): int idx = data.indexOf(']', lineStart); | - |
1752 | if (idx == -1 || idx >= lineStart + lineLen) { partially evaluated: idx == -1 no Evaluation Count:0 | yes Evaluation Count:627 |
partially evaluated: idx >= lineStart + lineLen no Evaluation Count:0 | yes Evaluation Count:627 |
| 0-627 |
1753 | ok = false; never executed (the execution status of this line is deduced): ok = false; | - |
1754 | iniSection = data.mid(lineStart + 1, lineLen - 1); never executed (the execution status of this line is deduced): iniSection = data.mid(lineStart + 1, lineLen - 1); | - |
1755 | } else { | 0 |
1756 | iniSection = data.mid(lineStart + 1, idx - lineStart - 1); executed (the execution status of this line is deduced): iniSection = data.mid(lineStart + 1, idx - lineStart - 1); | - |
1757 | } executed: } Execution Count:627 | 627 |
1758 | | - |
1759 | iniSection = iniSection.trimmed(); executed (the execution status of this line is deduced): iniSection = iniSection.trimmed(); | - |
1760 | | - |
1761 | if (qstricmp(iniSection.constData(), "general") == 0) { evaluated: qstricmp(iniSection.constData(), "general") == 0 yes Evaluation Count:48 | yes Evaluation Count:579 |
| 48-579 |
1762 | currentSection.clear(); executed (the execution status of this line is deduced): currentSection.clear(); | - |
1763 | } else { executed: } Execution Count:48 | 48 |
1764 | if (qstricmp(iniSection.constData(), "%general") == 0) { evaluated: qstricmp(iniSection.constData(), "%general") == 0 yes Evaluation Count:2 | yes Evaluation Count:577 |
| 2-577 |
1765 | currentSection = QLatin1String(iniSection.constData() + 1); executed (the execution status of this line is deduced): currentSection = QLatin1String(iniSection.constData() + 1); | - |
1766 | } else { executed: } Execution Count:2 | 2 |
1767 | currentSection.clear(); executed (the execution status of this line is deduced): currentSection.clear(); | - |
1768 | iniUnescapedKey(iniSection, 0, iniSection.size(), currentSection); executed (the execution status of this line is deduced): iniUnescapedKey(iniSection, 0, iniSection.size(), currentSection); | - |
1769 | } executed: } Execution Count:577 | 577 |
1770 | currentSection += QLatin1Char('/'); executed (the execution status of this line is deduced): currentSection += QLatin1Char('/'); | - |
1771 | } executed: } Execution Count:579 | 579 |
1772 | currentSectionStart = dataPos; executed (the execution status of this line is deduced): currentSectionStart = dataPos; | - |
1773 | } executed: } Execution Count:627 | 627 |
1774 | ++position; executed (the execution status of this line is deduced): ++position; | - |
1775 | } executed: } Execution Count:7679 | 7679 |
1776 | | - |
1777 | Q_ASSERT(lineStart == data.length()); executed (the execution status of this line is deduced): qt_noop(); | - |
1778 | FLUSH_CURRENT_SECTION(); never executed: sectionData.append('\n'); partially evaluated: !sectionData.isEmpty() no Evaluation Count:0 | yes Evaluation Count:431 |
| 0-431 |
1779 | | - |
1780 | return ok; executed: return ok; Execution Count:431 | 431 |
1781 | | - |
1782 | #undef FLUSH_CURRENT_SECTION | - |
1783 | } | - |
1784 | | - |
1785 | bool QConfFileSettingsPrivate::readIniSection(const QSettingsKey §ion, const QByteArray &data, | - |
1786 | ParsedSettingsMap *settingsMap, QTextCodec *codec) | - |
1787 | { | - |
1788 | QStringList strListValue; executed (the execution status of this line is deduced): QStringList strListValue; | - |
1789 | bool sectionIsLowercase = (section == section.originalCaseKey()); executed (the execution status of this line is deduced): bool sectionIsLowercase = (section == section.originalCaseKey()); | - |
1790 | int equalsPos; executed (the execution status of this line is deduced): int equalsPos; | - |
1791 | | - |
1792 | bool ok = true; executed (the execution status of this line is deduced): bool ok = true; | - |
1793 | int dataPos = 0; executed (the execution status of this line is deduced): int dataPos = 0; | - |
1794 | int lineStart; executed (the execution status of this line is deduced): int lineStart; | - |
1795 | int lineLen; executed (the execution status of this line is deduced): int lineLen; | - |
1796 | int position = section.originalKeyPosition(); executed (the execution status of this line is deduced): int position = section.originalKeyPosition(); | - |
1797 | | - |
1798 | while (readIniLine(data, dataPos, lineStart, lineLen, equalsPos)) { evaluated: readIniLine(data, dataPos, lineStart, lineLen, equalsPos) yes Evaluation Count:7009 | yes Evaluation Count:994 |
| 994-7009 |
1799 | char ch = data.at(lineStart); executed (the execution status of this line is deduced): char ch = data.at(lineStart); | - |
1800 | Q_ASSERT(ch != '['); executed (the execution status of this line is deduced): qt_noop(); | - |
1801 | | - |
1802 | if (equalsPos == -1) { evaluated: equalsPos == -1 yes Evaluation Count:4 | yes Evaluation Count:7005 |
| 4-7005 |
1803 | if (ch != ';') partially evaluated: ch != ';' yes Evaluation Count:4 | no Evaluation Count:0 |
| 0-4 |
1804 | ok = false; executed: ok = false; Execution Count:4 | 4 |
1805 | continue; executed: continue; Execution Count:4 | 4 |
1806 | } | - |
1807 | | - |
1808 | int keyEnd = equalsPos; executed (the execution status of this line is deduced): int keyEnd = equalsPos; | - |
1809 | while (keyEnd > lineStart && ((ch = data.at(keyEnd - 1)) == ' ' || ch == '\t')) partially evaluated: keyEnd > lineStart yes Evaluation Count:7005 | no Evaluation Count:0 |
partially evaluated: (ch = data.at(keyEnd - 1)) == ' ' no Evaluation Count:0 | yes Evaluation Count:7005 |
partially evaluated: ch == '\t' no Evaluation Count:0 | yes Evaluation Count:7005 |
| 0-7005 |
1810 | --keyEnd; never executed: --keyEnd; | 0 |
1811 | int valueStart = equalsPos + 1; executed (the execution status of this line is deduced): int valueStart = equalsPos + 1; | - |
1812 | | - |
1813 | QString key = section.originalCaseKey(); executed (the execution status of this line is deduced): QString key = section.originalCaseKey(); | - |
1814 | bool keyIsLowercase = (iniUnescapedKey(data, lineStart, keyEnd, key) && sectionIsLowercase); evaluated: iniUnescapedKey(data, lineStart, keyEnd, key) yes Evaluation Count:559 | yes Evaluation Count:6446 |
partially evaluated: sectionIsLowercase yes Evaluation Count:559 | no Evaluation Count:0 |
| 0-6446 |
1815 | | - |
1816 | QString strValue; executed (the execution status of this line is deduced): QString strValue; | - |
1817 | strValue.reserve(lineLen - (valueStart - lineStart)); executed (the execution status of this line is deduced): strValue.reserve(lineLen - (valueStart - lineStart)); | - |
1818 | bool isStringList = iniUnescapedStringList(data, valueStart, lineStart + lineLen, executed (the execution status of this line is deduced): bool isStringList = iniUnescapedStringList(data, valueStart, lineStart + lineLen, | - |
1819 | strValue, strListValue, codec); executed (the execution status of this line is deduced): strValue, strListValue, codec); | - |
1820 | QVariant variant; executed (the execution status of this line is deduced): QVariant variant; | - |
1821 | if (isStringList) { evaluated: isStringList yes Evaluation Count:21 | yes Evaluation Count:6984 |
| 21-6984 |
1822 | variant = stringListToVariantList(strListValue); executed (the execution status of this line is deduced): variant = stringListToVariantList(strListValue); | - |
1823 | } else { executed: } Execution Count:21 | 21 |
1824 | variant = stringToVariant(strValue); executed (the execution status of this line is deduced): variant = stringToVariant(strValue); | - |
1825 | } executed: } Execution Count:6984 | 6984 |
1826 | | - |
1827 | /* | - |
1828 | We try to avoid the expensive toLower() call in | - |
1829 | QSettingsKey by passing Qt::CaseSensitive when the | - |
1830 | key is already in lowercase. | - |
1831 | */ | - |
1832 | settingsMap->insert(QSettingsKey(key, keyIsLowercase ? Qt::CaseSensitive executed (the execution status of this line is deduced): settingsMap->insert(QSettingsKey(key, keyIsLowercase ? Qt::CaseSensitive | - |
1833 | : IniCaseSensitivity, executed (the execution status of this line is deduced): : IniCaseSensitivity, | - |
1834 | position), executed (the execution status of this line is deduced): position), | - |
1835 | variant); executed (the execution status of this line is deduced): variant); | - |
1836 | ++position; executed (the execution status of this line is deduced): ++position; | - |
1837 | } executed: } Execution Count:7005 | 7005 |
1838 | | - |
1839 | return ok; executed: return ok; Execution Count:994 | 994 |
1840 | } | - |
1841 | | - |
1842 | class QSettingsIniKey : public QString | - |
1843 | { | - |
1844 | public: | - |
1845 | inline QSettingsIniKey() : position(-1) {} | 0 |
1846 | inline QSettingsIniKey(const QString &str, int pos = -1) : QString(str), position(pos) {} executed: } Execution Count:6972 | 6972 |
1847 | | - |
1848 | int position; | - |
1849 | }; | - |
1850 | | - |
1851 | static bool operator<(const QSettingsIniKey &k1, const QSettingsIniKey &k2) | - |
1852 | { | - |
1853 | if (k1.position != k2.position) partially evaluated: k1.position != k2.position no Evaluation Count:0 | yes Evaluation Count:47855 |
| 0-47855 |
1854 | return k1.position < k2.position; never executed: return k1.position < k2.position; | 0 |
1855 | return static_cast<const QString &>(k1) < static_cast<const QString &>(k2); executed: return static_cast<const QString &>(k1) < static_cast<const QString &>(k2); Execution Count:47855 | 47855 |
1856 | } | - |
1857 | | - |
1858 | typedef QMap<QSettingsIniKey, QVariant> IniKeyMap; | - |
1859 | | - |
1860 | struct QSettingsIniSection | - |
1861 | { | - |
1862 | int position; | - |
1863 | IniKeyMap keyMap; | - |
1864 | | - |
1865 | inline QSettingsIniSection() : position(-1) {} executed: } Execution Count:463 | 463 |
1866 | }; | - |
1867 | | - |
1868 | typedef QMap<QString, QSettingsIniSection> IniMap; | - |
1869 | | - |
1870 | /* | - |
1871 | This would be more straightforward if we didn't try to remember the original | - |
1872 | key order in the .ini file, but we do. | - |
1873 | */ | - |
1874 | bool QConfFileSettingsPrivate::writeIniFile(QIODevice &device, const ParsedSettingsMap &map) | - |
1875 | { | - |
1876 | IniMap iniMap; executed (the execution status of this line is deduced): IniMap iniMap; | - |
1877 | IniMap::const_iterator i; executed (the execution status of this line is deduced): IniMap::const_iterator i; | - |
1878 | | - |
1879 | #ifdef Q_OS_WIN | - |
1880 | const char * const eol = "\r\n"; | - |
1881 | #else | - |
1882 | const char eol = '\n'; executed (the execution status of this line is deduced): const char eol = '\n'; | - |
1883 | #endif | - |
1884 | | - |
1885 | for (ParsedSettingsMap::const_iterator j = map.constBegin(); j != map.constEnd(); ++j) { evaluated: j != map.constEnd() yes Evaluation Count:6509 | yes Evaluation Count:450 |
| 450-6509 |
1886 | QString section; executed (the execution status of this line is deduced): QString section; | - |
1887 | QSettingsIniKey key(j.key().originalCaseKey(), j.key().originalKeyPosition()); executed (the execution status of this line is deduced): QSettingsIniKey key(j.key().originalCaseKey(), j.key().originalKeyPosition()); | - |
1888 | int slashPos; executed (the execution status of this line is deduced): int slashPos; | - |
1889 | | - |
1890 | if ((slashPos = key.indexOf(QLatin1Char('/'))) != -1) { evaluated: (slashPos = key.indexOf(QLatin1Char('/'))) != -1 yes Evaluation Count:6261 | yes Evaluation Count:248 |
| 248-6261 |
1891 | section = key.left(slashPos); executed (the execution status of this line is deduced): section = key.left(slashPos); | - |
1892 | key.remove(0, slashPos + 1); executed (the execution status of this line is deduced): key.remove(0, slashPos + 1); | - |
1893 | } executed: } Execution Count:6261 | 6261 |
1894 | | - |
1895 | QSettingsIniSection &iniSection = iniMap[section]; executed (the execution status of this line is deduced): QSettingsIniSection &iniSection = iniMap[section]; | - |
1896 | | - |
1897 | // -1 means infinity | - |
1898 | if (uint(key.position) < uint(iniSection.position)) partially evaluated: uint(key.position) < uint(iniSection.position) no Evaluation Count:0 | yes Evaluation Count:6509 |
| 0-6509 |
1899 | iniSection.position = key.position; never executed: iniSection.position = key.position; | 0 |
1900 | iniSection.keyMap[key] = j.value(); executed (the execution status of this line is deduced): iniSection.keyMap[key] = j.value(); | - |
1901 | } executed: } Execution Count:6509 | 6509 |
1902 | | - |
1903 | const int sectionCount = iniMap.size(); executed (the execution status of this line is deduced): const int sectionCount = iniMap.size(); | - |
1904 | QVector<QSettingsIniKey> sections; executed (the execution status of this line is deduced): QVector<QSettingsIniKey> sections; | - |
1905 | sections.reserve(sectionCount); executed (the execution status of this line is deduced): sections.reserve(sectionCount); | - |
1906 | for (i = iniMap.constBegin(); i != iniMap.constEnd(); ++i) evaluated: i != iniMap.constEnd() yes Evaluation Count:463 | yes Evaluation Count:450 |
| 450-463 |
1907 | sections.append(QSettingsIniKey(i.key(), i.value().position)); executed: sections.append(QSettingsIniKey(i.key(), i.value().position)); Execution Count:463 | 463 |
1908 | qSort(sections); executed (the execution status of this line is deduced): qSort(sections); | - |
1909 | | - |
1910 | bool writeError = false; executed (the execution status of this line is deduced): bool writeError = false; | - |
1911 | for (int j = 0; !writeError && j < sectionCount; ++j) { partially evaluated: !writeError yes Evaluation Count:913 | no Evaluation Count:0 |
evaluated: j < sectionCount yes Evaluation Count:463 | yes Evaluation Count:450 |
| 0-913 |
1912 | i = iniMap.constFind(sections.at(j)); executed (the execution status of this line is deduced): i = iniMap.constFind(sections.at(j)); | - |
1913 | Q_ASSERT(i != iniMap.constEnd()); executed (the execution status of this line is deduced): qt_noop(); | - |
1914 | | - |
1915 | QByteArray realSection; executed (the execution status of this line is deduced): QByteArray realSection; | - |
1916 | | - |
1917 | iniEscapedKey(i.key(), realSection); executed (the execution status of this line is deduced): iniEscapedKey(i.key(), realSection); | - |
1918 | | - |
1919 | if (realSection.isEmpty()) { evaluated: realSection.isEmpty() yes Evaluation Count:51 | yes Evaluation Count:412 |
| 51-412 |
1920 | realSection = "[General]"; executed (the execution status of this line is deduced): realSection = "[General]"; | - |
1921 | } else if (qstricmp(realSection.constData(), "general") == 0) { executed: } Execution Count:51 evaluated: qstricmp(realSection.constData(), "general") == 0 yes Evaluation Count:3 | yes Evaluation Count:409 |
| 3-409 |
1922 | realSection = "[%General]"; executed (the execution status of this line is deduced): realSection = "[%General]"; | - |
1923 | } else { executed: } Execution Count:3 | 3 |
1924 | realSection.prepend('['); executed (the execution status of this line is deduced): realSection.prepend('['); | - |
1925 | realSection.append(']'); executed (the execution status of this line is deduced): realSection.append(']'); | - |
1926 | } executed: } Execution Count:409 | 409 |
1927 | | - |
1928 | if (j != 0) evaluated: j != 0 yes Evaluation Count:15 | yes Evaluation Count:448 |
| 15-448 |
1929 | realSection.prepend(eol); executed: realSection.prepend(eol); Execution Count:15 | 15 |
1930 | realSection += eol; executed (the execution status of this line is deduced): realSection += eol; | - |
1931 | | - |
1932 | device.write(realSection); executed (the execution status of this line is deduced): device.write(realSection); | - |
1933 | | - |
1934 | const IniKeyMap &ents = i.value().keyMap; executed (the execution status of this line is deduced): const IniKeyMap &ents = i.value().keyMap; | - |
1935 | for (IniKeyMap::const_iterator j = ents.constBegin(); j != ents.constEnd(); ++j) { evaluated: j != ents.constEnd() yes Evaluation Count:6509 | yes Evaluation Count:463 |
| 463-6509 |
1936 | QByteArray block; executed (the execution status of this line is deduced): QByteArray block; | - |
1937 | iniEscapedKey(j.key(), block); executed (the execution status of this line is deduced): iniEscapedKey(j.key(), block); | - |
1938 | block += '='; executed (the execution status of this line is deduced): block += '='; | - |
1939 | | - |
1940 | const QVariant &value = j.value(); executed (the execution status of this line is deduced): const QVariant &value = j.value(); | - |
1941 | | - |
1942 | /* | - |
1943 | The size() != 1 trick is necessary because | - |
1944 | QVariant(QString("foo")).toList() returns an empty | - |
1945 | list, not a list containing "foo". | - |
1946 | */ | - |
1947 | if (value.type() == QVariant::StringList evaluated: value.type() == QVariant::StringList yes Evaluation Count:11 | yes Evaluation Count:6498 |
| 11-6498 |
1948 | || (value.type() == QVariant::List && value.toList().size() != 1)) { evaluated: value.type() == QVariant::List yes Evaluation Count:9 | yes Evaluation Count:6489 |
evaluated: value.toList().size() != 1 yes Evaluation Count:5 | yes Evaluation Count:4 |
| 4-6489 |
1949 | iniEscapedStringList(variantListToStringList(value.toList()), block, iniCodec); executed (the execution status of this line is deduced): iniEscapedStringList(variantListToStringList(value.toList()), block, iniCodec); | - |
1950 | } else { executed: } Execution Count:16 | 16 |
1951 | iniEscapedString(variantToString(value), block, iniCodec); executed (the execution status of this line is deduced): iniEscapedString(variantToString(value), block, iniCodec); | - |
1952 | } executed: } Execution Count:6493 | 6493 |
1953 | block += eol; executed (the execution status of this line is deduced): block += eol; | - |
1954 | if (device.write(block) == -1) { partially evaluated: device.write(block) == -1 no Evaluation Count:0 | yes Evaluation Count:6509 |
| 0-6509 |
1955 | writeError = true; never executed (the execution status of this line is deduced): writeError = true; | - |
1956 | break; | 0 |
1957 | } | - |
1958 | } executed: } Execution Count:6509 | 6509 |
1959 | } executed: } Execution Count:463 | 463 |
1960 | return !writeError; executed: return !writeError; Execution Count:450 | 450 |
1961 | } | - |
1962 | | - |
1963 | void QConfFileSettingsPrivate::ensureAllSectionsParsed(QConfFile *confFile) const | - |
1964 | { | - |
1965 | UnparsedSettingsMap::const_iterator i = confFile->unparsedIniSections.constBegin(); executed (the execution status of this line is deduced): UnparsedSettingsMap::const_iterator i = confFile->unparsedIniSections.constBegin(); | - |
1966 | const UnparsedSettingsMap::const_iterator end = confFile->unparsedIniSections.constEnd(); executed (the execution status of this line is deduced): const UnparsedSettingsMap::const_iterator end = confFile->unparsedIniSections.constEnd(); | - |
1967 | | - |
1968 | for (; i != end; ++i) { evaluated: i != end yes Evaluation Count:779 | yes Evaluation Count:627 |
| 627-779 |
1969 | if (!QConfFileSettingsPrivate::readIniSection(i.key(), i.value(), &confFile->originalKeys, iniCodec)) evaluated: !QConfFileSettingsPrivate::readIniSection(i.key(), i.value(), &confFile->originalKeys, iniCodec) yes Evaluation Count:2 | yes Evaluation Count:777 |
| 2-777 |
1970 | setStatus(QSettings::FormatError); executed: setStatus(QSettings::FormatError); Execution Count:2 | 2 |
1971 | } executed: } Execution Count:779 | 779 |
1972 | confFile->unparsedIniSections.clear(); executed (the execution status of this line is deduced): confFile->unparsedIniSections.clear(); | - |
1973 | } executed: } Execution Count:627 | 627 |
1974 | | - |
1975 | void QConfFileSettingsPrivate::ensureSectionParsed(QConfFile *confFile, | - |
1976 | const QSettingsKey &key) const | - |
1977 | { | - |
1978 | if (confFile->unparsedIniSections.isEmpty()) evaluated: confFile->unparsedIniSections.isEmpty() yes Evaluation Count:2615 | yes Evaluation Count:507 |
| 507-2615 |
1979 | return; executed: return; Execution Count:2615 | 2615 |
1980 | | - |
1981 | UnparsedSettingsMap::iterator i; executed (the execution status of this line is deduced): UnparsedSettingsMap::iterator i; | - |
1982 | | - |
1983 | int indexOfSlash = key.indexOf(QLatin1Char('/')); executed (the execution status of this line is deduced): int indexOfSlash = key.indexOf(QLatin1Char('/')); | - |
1984 | if (indexOfSlash != -1) { evaluated: indexOfSlash != -1 yes Evaluation Count:477 | yes Evaluation Count:30 |
| 30-477 |
1985 | i = confFile->unparsedIniSections.upperBound(key); executed (the execution status of this line is deduced): i = confFile->unparsedIniSections.upperBound(key); | - |
1986 | if (i == confFile->unparsedIniSections.begin()) partially evaluated: i == confFile->unparsedIniSections.begin() no Evaluation Count:0 | yes Evaluation Count:477 |
| 0-477 |
1987 | return; | 0 |
1988 | --i; executed (the execution status of this line is deduced): --i; | - |
1989 | if (i.key().isEmpty() || !key.startsWith(i.key())) evaluated: i.key().isEmpty() yes Evaluation Count:284 | yes Evaluation Count:193 |
partially evaluated: !key.startsWith(i.key()) no Evaluation Count:0 | yes Evaluation Count:193 |
| 0-284 |
1990 | return; executed: return; Execution Count:284 | 284 |
1991 | } else { executed: } Execution Count:193 | 193 |
1992 | i = confFile->unparsedIniSections.begin(); executed (the execution status of this line is deduced): i = confFile->unparsedIniSections.begin(); | - |
1993 | if (i == confFile->unparsedIniSections.end() || !i.key().isEmpty()) partially evaluated: i == confFile->unparsedIniSections.end() no Evaluation Count:0 | yes Evaluation Count:30 |
evaluated: !i.key().isEmpty() yes Evaluation Count:8 | yes Evaluation Count:22 |
| 0-30 |
1994 | return; executed: return; Execution Count:8 | 8 |
1995 | } executed: } Execution Count:22 | 22 |
1996 | | - |
1997 | if (!QConfFileSettingsPrivate::readIniSection(i.key(), i.value(), &confFile->originalKeys, iniCodec)) partially evaluated: !QConfFileSettingsPrivate::readIniSection(i.key(), i.value(), &confFile->originalKeys, iniCodec) no Evaluation Count:0 | yes Evaluation Count:215 |
| 0-215 |
1998 | setStatus(QSettings::FormatError); never executed: setStatus(QSettings::FormatError); | 0 |
1999 | confFile->unparsedIniSections.erase(i); executed (the execution status of this line is deduced): confFile->unparsedIniSections.erase(i); | - |
2000 | } executed: } Execution Count:215 | 215 |
2001 | | - |
2002 | /*! | - |
2003 | \class QSettings | - |
2004 | \inmodule QtCore | - |
2005 | \brief The QSettings class provides persistent platform-independent application settings. | - |
2006 | | - |
2007 | \ingroup io | - |
2008 | | - |
2009 | \reentrant | - |
2010 | | - |
2011 | Users normally expect an application to remember its settings | - |
2012 | (window sizes and positions, options, etc.) across sessions. This | - |
2013 | information is often stored in the system registry on Windows, | - |
2014 | and in XML preferences files on Mac OS X. On Unix systems, in the | - |
2015 | absence of a standard, many applications (including the KDE | - |
2016 | applications) use INI text files. | - |
2017 | | - |
2018 | QSettings is an abstraction around these technologies, enabling | - |
2019 | you to save and restore application settings in a portable | - |
2020 | manner. It also supports \l{registerFormat()}{custom storage | - |
2021 | formats}. | - |
2022 | | - |
2023 | QSettings's API is based on QVariant, allowing you to save | - |
2024 | most value-based types, such as QString, QRect, and QImage, | - |
2025 | with the minimum of effort. | - |
2026 | | - |
2027 | If all you need is a non-persistent memory-based structure, | - |
2028 | consider using QMap<QString, QVariant> instead. | - |
2029 | | - |
2030 | \tableofcontents section1 | - |
2031 | | - |
2032 | \section1 Basic Usage | - |
2033 | | - |
2034 | When creating a QSettings object, you must pass the name of your | - |
2035 | company or organization as well as the name of your application. | - |
2036 | For example, if your product is called Star Runner and your | - |
2037 | company is called MySoft, you would construct the QSettings | - |
2038 | object as follows: | - |
2039 | | - |
2040 | \snippet settings/settings.cpp 0 | - |
2041 | | - |
2042 | QSettings objects can be created either on the stack or on | - |
2043 | the heap (i.e. using \c new). Constructing and destroying a | - |
2044 | QSettings object is very fast. | - |
2045 | | - |
2046 | If you use QSettings from many places in your application, you | - |
2047 | might want to specify the organization name and the application | - |
2048 | name using QCoreApplication::setOrganizationName() and | - |
2049 | QCoreApplication::setApplicationName(), and then use the default | - |
2050 | QSettings constructor: | - |
2051 | | - |
2052 | \snippet settings/settings.cpp 1 | - |
2053 | \snippet settings/settings.cpp 2 | - |
2054 | \snippet settings/settings.cpp 3 | - |
2055 | \dots | - |
2056 | \snippet settings/settings.cpp 4 | - |
2057 | | - |
2058 | (Here, we also specify the organization's Internet domain. When | - |
2059 | the Internet domain is set, it is used on Mac OS X instead of the | - |
2060 | organization name, since Mac OS X applications conventionally use | - |
2061 | Internet domains to identify themselves. If no domain is set, a | - |
2062 | fake domain is derived from the organization name. See the | - |
2063 | \l{Platform-Specific Notes} below for details.) | - |
2064 | | - |
2065 | QSettings stores settings. Each setting consists of a QString | - |
2066 | that specifies the setting's name (the \e key) and a QVariant | - |
2067 | that stores the data associated with the key. To write a setting, | - |
2068 | use setValue(). For example: | - |
2069 | | - |
2070 | \snippet settings/settings.cpp 5 | - |
2071 | | - |
2072 | If there already exists a setting with the same key, the existing | - |
2073 | value is overwritten by the new value. For efficiency, the | - |
2074 | changes may not be saved to permanent storage immediately. (You | - |
2075 | can always call sync() to commit your changes.) | - |
2076 | | - |
2077 | You can get a setting's value back using value(): | - |
2078 | | - |
2079 | \snippet settings/settings.cpp 6 | - |
2080 | | - |
2081 | If there is no setting with the specified name, QSettings | - |
2082 | returns a null QVariant (which can be converted to the integer 0). | - |
2083 | You can specify another default value by passing a second | - |
2084 | argument to value(): | - |
2085 | | - |
2086 | \snippet settings/settings.cpp 7 | - |
2087 | | - |
2088 | To test whether a given key exists, call contains(). To remove | - |
2089 | the setting associated with a key, call remove(). To obtain the | - |
2090 | list of all keys, call allKeys(). To remove all keys, call | - |
2091 | clear(). | - |
2092 | | - |
2093 | \section1 QVariant and GUI Types | - |
2094 | | - |
2095 | Because QVariant is part of the Qt Core module, it cannot provide | - |
2096 | conversion functions to data types such as QColor, QImage, and | - |
2097 | QPixmap, which are part of Qt GUI. In other words, there is no | - |
2098 | \c toColor(), \c toImage(), or \c toPixmap() functions in QVariant. | - |
2099 | | - |
2100 | Instead, you can use the QVariant::value() or the qVariantValue() | - |
2101 | template function. For example: | - |
2102 | | - |
2103 | \snippet code/src_corelib_io_qsettings.cpp 0 | - |
2104 | | - |
2105 | The inverse conversion (e.g., from QColor to QVariant) is | - |
2106 | automatic for all data types supported by QVariant, including | - |
2107 | GUI-related types: | - |
2108 | | - |
2109 | \snippet code/src_corelib_io_qsettings.cpp 1 | - |
2110 | | - |
2111 | Custom types registered using qRegisterMetaType() and | - |
2112 | qRegisterMetaTypeStreamOperators() can be stored using QSettings. | - |
2113 | | - |
2114 | \section1 Section and Key Syntax | - |
2115 | | - |
2116 | Setting keys can contain any Unicode characters. The Windows | - |
2117 | registry and INI files use case-insensitive keys, whereas the | - |
2118 | Carbon Preferences API on Mac OS X uses case-sensitive keys. To | - |
2119 | avoid portability problems, follow these simple rules: | - |
2120 | | - |
2121 | \list 1 | - |
2122 | \li Always refer to the same key using the same case. For example, | - |
2123 | if you refer to a key as "text fonts" in one place in your | - |
2124 | code, don't refer to it as "Text Fonts" somewhere else. | - |
2125 | | - |
2126 | \li Avoid key names that are identical except for the case. For | - |
2127 | example, if you have a key called "MainWindow", don't try to | - |
2128 | save another key as "mainwindow". | - |
2129 | | - |
2130 | \li Do not use slashes ('/' and '\\') in section or key names; the | - |
2131 | backslash character is used to separate sub keys (see below). On | - |
2132 | windows '\\' are converted by QSettings to '/', which makes | - |
2133 | them identical. | - |
2134 | \endlist | - |
2135 | | - |
2136 | You can form hierarchical keys using the '/' character as a | - |
2137 | separator, similar to Unix file paths. For example: | - |
2138 | | - |
2139 | \snippet settings/settings.cpp 8 | - |
2140 | \snippet settings/settings.cpp 9 | - |
2141 | \snippet settings/settings.cpp 10 | - |
2142 | | - |
2143 | If you want to save or restore many settings with the same | - |
2144 | prefix, you can specify the prefix using beginGroup() and call | - |
2145 | endGroup() at the end. Here's the same example again, but this | - |
2146 | time using the group mechanism: | - |
2147 | | - |
2148 | \snippet settings/settings.cpp 11 | - |
2149 | \codeline | - |
2150 | \snippet settings/settings.cpp 12 | - |
2151 | | - |
2152 | If a group is set using beginGroup(), the behavior of most | - |
2153 | functions changes consequently. Groups can be set recursively. | - |
2154 | | - |
2155 | In addition to groups, QSettings also supports an "array" | - |
2156 | concept. See beginReadArray() and beginWriteArray() for details. | - |
2157 | | - |
2158 | \section1 Fallback Mechanism | - |
2159 | | - |
2160 | Let's assume that you have created a QSettings object with the | - |
2161 | organization name MySoft and the application name Star Runner. | - |
2162 | When you look up a value, up to four locations are searched in | - |
2163 | that order: | - |
2164 | | - |
2165 | \list 1 | - |
2166 | \li a user-specific location for the Star Runner application | - |
2167 | \li a user-specific location for all applications by MySoft | - |
2168 | \li a system-wide location for the Star Runner application | - |
2169 | \li a system-wide location for all applications by MySoft | - |
2170 | \endlist | - |
2171 | | - |
2172 | (See \l{Platform-Specific Notes} below for information on what | - |
2173 | these locations are on the different platforms supported by Qt.) | - |
2174 | | - |
2175 | If a key cannot be found in the first location, the search goes | - |
2176 | on in the second location, and so on. This enables you to store | - |
2177 | system-wide or organization-wide settings and to override them on | - |
2178 | a per-user or per-application basis. To turn off this mechanism, | - |
2179 | call setFallbacksEnabled(false). | - |
2180 | | - |
2181 | Although keys from all four locations are available for reading, | - |
2182 | only the first file (the user-specific location for the | - |
2183 | application at hand) is accessible for writing. To write to any | - |
2184 | of the other files, omit the application name and/or specify | - |
2185 | QSettings::SystemScope (as opposed to QSettings::UserScope, the | - |
2186 | default). | - |
2187 | | - |
2188 | Let's see with an example: | - |
2189 | | - |
2190 | \snippet settings/settings.cpp 13 | - |
2191 | \snippet settings/settings.cpp 14 | - |
2192 | | - |
2193 | The table below summarizes which QSettings objects access | - |
2194 | which location. "\b{X}" means that the location is the main | - |
2195 | location associated to the QSettings object and is used both | - |
2196 | for reading and for writing; "o" means that the location is used | - |
2197 | as a fallback when reading. | - |
2198 | | - |
2199 | \table | - |
2200 | \header \li Locations \li \c{obj1} \li \c{obj2} \li \c{obj3} \li \c{obj4} | - |
2201 | \row \li 1. User, Application \li \b{X} \li \li \li | - |
2202 | \row \li 2. User, Organization \li o \li \b{X} \li \li | - |
2203 | \row \li 3. System, Application \li o \li \li \b{X} \li | - |
2204 | \row \li 4. System, Organization \li o \li o \li o \li \b{X} | - |
2205 | \endtable | - |
2206 | | - |
2207 | The beauty of this mechanism is that it works on all platforms | - |
2208 | supported by Qt and that it still gives you a lot of flexibility, | - |
2209 | without requiring you to specify any file names or registry | - |
2210 | paths. | - |
2211 | | - |
2212 | If you want to use INI files on all platforms instead of the | - |
2213 | native API, you can pass QSettings::IniFormat as the first | - |
2214 | argument to the QSettings constructor, followed by the scope, the | - |
2215 | organization name, and the application name: | - |
2216 | | - |
2217 | \snippet settings/settings.cpp 15 | - |
2218 | | - |
2219 | The \l{tools/settingseditor}{Settings Editor} example lets you | - |
2220 | experiment with different settings location and with fallbacks | - |
2221 | turned on or off. | - |
2222 | | - |
2223 | \section1 Restoring the State of a GUI Application | - |
2224 | | - |
2225 | QSettings is often used to store the state of a GUI | - |
2226 | application. The following example illustrates how to use QSettings | - |
2227 | to save and restore the geometry of an application's main window. | - |
2228 | | - |
2229 | \snippet settings/settings.cpp 16 | - |
2230 | \codeline | - |
2231 | \snippet settings/settings.cpp 17 | - |
2232 | | - |
2233 | See \l{Window Geometry} for a discussion on why it is better to | - |
2234 | call QWidget::resize() and QWidget::move() rather than QWidget::setGeometry() | - |
2235 | to restore a window's geometry. | - |
2236 | | - |
2237 | The \c readSettings() and \c writeSettings() functions must be | - |
2238 | called from the main window's constructor and close event handler | - |
2239 | as follows: | - |
2240 | | - |
2241 | \snippet settings/settings.cpp 18 | - |
2242 | \dots | - |
2243 | \snippet settings/settings.cpp 19 | - |
2244 | \snippet settings/settings.cpp 20 | - |
2245 | \codeline | - |
2246 | \snippet settings/settings.cpp 21 | - |
2247 | | - |
2248 | See the \l{mainwindows/application}{Application} example for a | - |
2249 | self-contained example that uses QSettings. | - |
2250 | | - |
2251 | \section1 Accessing Settings from Multiple Threads or Processes Simultaneously | - |
2252 | | - |
2253 | QSettings is \l{reentrant}. This means that you can use | - |
2254 | distinct QSettings object in different threads | - |
2255 | simultaneously. This guarantee stands even when the QSettings | - |
2256 | objects refer to the same files on disk (or to the same entries | - |
2257 | in the system registry). If a setting is modified through one | - |
2258 | QSettings object, the change will immediately be visible in | - |
2259 | any other QSettings objects that operate on the same location | - |
2260 | and that live in the same process. | - |
2261 | | - |
2262 | QSettings can safely be used from different processes (which can | - |
2263 | be different instances of your application running at the same | - |
2264 | time or different applications altogether) to read and write to | - |
2265 | the same system locations. It uses advisory file locking and a | - |
2266 | smart merging algorithm to ensure data integrity. Note that sync() | - |
2267 | imports changes made by other processes (in addition to writing | - |
2268 | the changes from this QSettings). | - |
2269 | | - |
2270 | \section1 Platform-Specific Notes | - |
2271 | | - |
2272 | \section2 Locations Where Application Settings Are Stored | - |
2273 | | - |
2274 | As mentioned in the \l{Fallback Mechanism} section, QSettings | - |
2275 | stores settings for an application in up to four locations, | - |
2276 | depending on whether the settings are user-specific or | - |
2277 | system-wide and whether the settings are application-specific | - |
2278 | or organization-wide. For simplicity, we're assuming the | - |
2279 | organization is called MySoft and the application is called Star | - |
2280 | Runner. | - |
2281 | | - |
2282 | On Unix systems, if the file format is NativeFormat, the | - |
2283 | following files are used by default: | - |
2284 | | - |
2285 | \list 1 | - |
2286 | \li \c{$HOME/.config/MySoft/Star Runner.conf} (Qt for Embedded Linux: \c{$HOME/Settings/MySoft/Star Runner.conf}) | - |
2287 | \li \c{$HOME/.config/MySoft.conf} (Qt for Embedded Linux: \c{$HOME/Settings/MySoft.conf}) | - |
2288 | \li \c{/etc/xdg/MySoft/Star Runner.conf} | - |
2289 | \li \c{/etc/xdg/MySoft.conf} | - |
2290 | \endlist | - |
2291 | | - |
2292 | On Mac OS X versions 10.2 and 10.3, these files are used by | - |
2293 | default: | - |
2294 | | - |
2295 | \list 1 | - |
2296 | \li \c{$HOME/Library/Preferences/com.MySoft.Star Runner.plist} | - |
2297 | \li \c{$HOME/Library/Preferences/com.MySoft.plist} | - |
2298 | \li \c{/Library/Preferences/com.MySoft.Star Runner.plist} | - |
2299 | \li \c{/Library/Preferences/com.MySoft.plist} | - |
2300 | \endlist | - |
2301 | | - |
2302 | On Windows, NativeFormat settings are stored in the following | - |
2303 | registry paths: | - |
2304 | | - |
2305 | \list 1 | - |
2306 | \li \c{HKEY_CURRENT_USER\Software\MySoft\Star Runner} | - |
2307 | \li \c{HKEY_CURRENT_USER\Software\MySoft\OrganizationDefaults} | - |
2308 | \li \c{HKEY_LOCAL_MACHINE\Software\MySoft\Star Runner} | - |
2309 | \li \c{HKEY_LOCAL_MACHINE\Software\MySoft\OrganizationDefaults} | - |
2310 | \endlist | - |
2311 | | - |
2312 | \note On Windows, for 32-bit programs running in WOW64 mode, settings are | - |
2313 | stored in the following registry path: | - |
2314 | \c{HKEY_LOCAL_MACHINE\Software\WOW6432node}. | - |
2315 | | - |
2316 | If the file format is IniFormat, the following files are | - |
2317 | used on Unix and Mac OS X: | - |
2318 | | - |
2319 | \list 1 | - |
2320 | \li \c{$HOME/.config/MySoft/Star Runner.ini} (Qt for Embedded Linux: \c{$HOME/Settings/MySoft/Star Runner.ini}) | - |
2321 | \li \c{$HOME/.config/MySoft.ini} (Qt for Embedded Linux: \c{$HOME/Settings/MySoft.ini}) | - |
2322 | \li \c{/etc/xdg/MySoft/Star Runner.ini} | - |
2323 | \li \c{/etc/xdg/MySoft.ini} | - |
2324 | \endlist | - |
2325 | | - |
2326 | On Windows, the following files are used: | - |
2327 | | - |
2328 | \list 1 | - |
2329 | \li \c{%APPDATA%\MySoft\Star Runner.ini} | - |
2330 | \li \c{%APPDATA%\MySoft.ini} | - |
2331 | \li \c{%COMMON_APPDATA%\MySoft\Star Runner.ini} | - |
2332 | \li \c{%COMMON_APPDATA%\MySoft.ini} | - |
2333 | \endlist | - |
2334 | | - |
2335 | The \c %APPDATA% path is usually \tt{C:\\Documents and | - |
2336 | Settings\\\e{User Name}\\Application Data}; the \c | - |
2337 | %COMMON_APPDATA% path is usually \tt{C:\\Documents and | - |
2338 | Settings\\All Users\\Application Data}. | - |
2339 | | - |
2340 | The paths for the \c .ini and \c .conf files can be changed using | - |
2341 | setPath(). On Unix and Mac OS X, the user can override them by by | - |
2342 | setting the \c XDG_CONFIG_HOME environment variable; see | - |
2343 | setPath() for details. | - |
2344 | | - |
2345 | \section2 Accessing INI and .plist Files Directly | - |
2346 | | - |
2347 | Sometimes you do want to access settings stored in a specific | - |
2348 | file or registry path. On all platforms, if you want to read an | - |
2349 | INI file directly, you can use the QSettings constructor that | - |
2350 | takes a file name as first argument and pass QSettings::IniFormat | - |
2351 | as second argument. For example: | - |
2352 | | - |
2353 | \snippet code/src_corelib_io_qsettings.cpp 2 | - |
2354 | | - |
2355 | You can then use the QSettings object to read and write settings | - |
2356 | in the file. | - |
2357 | | - |
2358 | On Mac OS X, you can access XML-based \c .plist files by passing | - |
2359 | QSettings::NativeFormat as second argument. For example: | - |
2360 | | - |
2361 | \snippet code/src_corelib_io_qsettings.cpp 3 | - |
2362 | | - |
2363 | \section2 Accessing the Windows Registry Directly | - |
2364 | | - |
2365 | On Windows, QSettings lets you access settings that have been | - |
2366 | written with QSettings (or settings in a supported format, e.g., string | - |
2367 | data) in the system registry. This is done by constructing a QSettings | - |
2368 | object with a path in the registry and QSettings::NativeFormat. | - |
2369 | | - |
2370 | For example: | - |
2371 | | - |
2372 | \snippet code/src_corelib_io_qsettings.cpp 4 | - |
2373 | | - |
2374 | All the registry entries that appear under the specified path can | - |
2375 | be read or written through the QSettings object as usual (using | - |
2376 | forward slashes instead of backslashes). For example: | - |
2377 | | - |
2378 | \snippet code/src_corelib_io_qsettings.cpp 5 | - |
2379 | | - |
2380 | Note that the backslash character is, as mentioned, used by | - |
2381 | QSettings to separate subkeys. As a result, you cannot read or | - |
2382 | write windows registry entries that contain slashes or | - |
2383 | backslashes; you should use a native windows API if you need to do | - |
2384 | so. | - |
2385 | | - |
2386 | \section2 Accessing Common Registry Settings on Windows | - |
2387 | | - |
2388 | On Windows, it is possible for a key to have both a value and subkeys. | - |
2389 | Its default value is accessed by using "Default" or "." in | - |
2390 | place of a subkey: | - |
2391 | | - |
2392 | \snippet code/src_corelib_io_qsettings.cpp 6 | - |
2393 | | - |
2394 | On other platforms than Windows, "Default" and "." would be | - |
2395 | treated as regular subkeys. | - |
2396 | | - |
2397 | \section2 Platform Limitations | - |
2398 | | - |
2399 | While QSettings attempts to smooth over the differences between | - |
2400 | the different supported platforms, there are still a few | - |
2401 | differences that you should be aware of when porting your | - |
2402 | application: | - |
2403 | | - |
2404 | \list | - |
2405 | \li The Windows system registry has the following limitations: A | - |
2406 | subkey may not exceed 255 characters, an entry's value may | - |
2407 | not exceed 16,383 characters, and all the values of a key may | - |
2408 | not exceed 65,535 characters. One way to work around these | - |
2409 | limitations is to store the settings using the IniFormat | - |
2410 | instead of the NativeFormat. | - |
2411 | | - |
2412 | \li On Mac OS X, allKeys() will return some extra keys for global | - |
2413 | settings that apply to all applications. These keys can be | - |
2414 | read using value() but cannot be changed, only shadowed. | - |
2415 | Calling setFallbacksEnabled(false) will hide these global | - |
2416 | settings. | - |
2417 | | - |
2418 | \li On Mac OS X, the CFPreferences API used by QSettings expects | - |
2419 | Internet domain names rather than organization names. To | - |
2420 | provide a uniform API, QSettings derives a fake domain name | - |
2421 | from the organization name (unless the organization name | - |
2422 | already is a domain name, e.g. OpenOffice.org). The algorithm | - |
2423 | appends ".com" to the company name and replaces spaces and | - |
2424 | other illegal characters with hyphens. If you want to specify | - |
2425 | a different domain name, call | - |
2426 | QCoreApplication::setOrganizationDomain(), | - |
2427 | QCoreApplication::setOrganizationName(), and | - |
2428 | QCoreApplication::setApplicationName() in your \c main() | - |
2429 | function and then use the default QSettings constructor. | - |
2430 | Another solution is to use preprocessor directives, for | - |
2431 | example: | - |
2432 | | - |
2433 | \snippet code/src_corelib_io_qsettings.cpp 7 | - |
2434 | | - |
2435 | \li On Unix and Mac OS X systems, the advisory file locking is disabled | - |
2436 | if NFS (or AutoFS or CacheFS) is detected to work around a bug in the | - |
2437 | NFS fcntl() implementation, which hangs forever if statd or lockd aren't | - |
2438 | running. Also, the locking isn't performed when accessing \c .plist | - |
2439 | files. | - |
2440 | | - |
2441 | \li On the BlackBerry platform, applications run in a sandbox. They are not | - |
2442 | allowed to read or write outside of this sandbox. This involves the | - |
2443 | following limitations: | - |
2444 | \list | - |
2445 | \li As there is only a single scope the scope is simply ignored. | - |
2446 | \li The \l{Fallback Mechanism} is not applied, i.e. only a single | - |
2447 | location is considered. | - |
2448 | \li It is advised against setting and using custom file paths. | - |
2449 | \endlist | - |
2450 | | - |
2451 | \endlist | - |
2452 | | - |
2453 | \sa QVariant, QSessionManager, {Settings Editor Example}, {Application Example} | - |
2454 | */ | - |
2455 | | - |
2456 | /*! \enum QSettings::Status | - |
2457 | | - |
2458 | The following status values are possible: | - |
2459 | | - |
2460 | \value NoError No error occurred. | - |
2461 | \value AccessError An access error occurred (e.g. trying to write to a read-only file). | - |
2462 | \value FormatError A format error occurred (e.g. loading a malformed INI file). | - |
2463 | | - |
2464 | \sa status() | - |
2465 | */ | - |
2466 | | - |
2467 | /*! \enum QSettings::Format | - |
2468 | | - |
2469 | This enum type specifies the storage format used by QSettings. | - |
2470 | | - |
2471 | \value NativeFormat Store the settings using the most | - |
2472 | appropriate storage format for the platform. | - |
2473 | On Windows, this means the system registry; | - |
2474 | on Mac OS X, this means the CFPreferences | - |
2475 | API; on Unix, this means textual | - |
2476 | configuration files in INI format. | - |
2477 | \value IniFormat Store the settings in INI files. | - |
2478 | \value InvalidFormat Special value returned by registerFormat(). | - |
2479 | \omitvalue CustomFormat1 | - |
2480 | \omitvalue CustomFormat2 | - |
2481 | \omitvalue CustomFormat3 | - |
2482 | \omitvalue CustomFormat4 | - |
2483 | \omitvalue CustomFormat5 | - |
2484 | \omitvalue CustomFormat6 | - |
2485 | \omitvalue CustomFormat7 | - |
2486 | \omitvalue CustomFormat8 | - |
2487 | \omitvalue CustomFormat9 | - |
2488 | \omitvalue CustomFormat10 | - |
2489 | \omitvalue CustomFormat11 | - |
2490 | \omitvalue CustomFormat12 | - |
2491 | \omitvalue CustomFormat13 | - |
2492 | \omitvalue CustomFormat14 | - |
2493 | \omitvalue CustomFormat15 | - |
2494 | \omitvalue CustomFormat16 | - |
2495 | | - |
2496 | On Unix, NativeFormat and IniFormat mean the same thing, except | - |
2497 | that the file extension is different (\c .conf for NativeFormat, | - |
2498 | \c .ini for IniFormat). | - |
2499 | | - |
2500 | The INI file format is a Windows file format that Qt supports on | - |
2501 | all platforms. In the absence of an INI standard, we try to | - |
2502 | follow what Microsoft does, with the following exceptions: | - |
2503 | | - |
2504 | \list | - |
2505 | \li If you store types that QVariant can't convert to QString | - |
2506 | (e.g., QPoint, QRect, and QSize), Qt uses an \c{@}-based | - |
2507 | syntax to encode the type. For example: | - |
2508 | | - |
2509 | \snippet code/src_corelib_io_qsettings.cpp 8 | - |
2510 | | - |
2511 | To minimize compatibility issues, any \c @ that doesn't | - |
2512 | appear at the first position in the value or that isn't | - |
2513 | followed by a Qt type (\c Point, \c Rect, \c Size, etc.) is | - |
2514 | treated as a normal character. | - |
2515 | | - |
2516 | \li Although backslash is a special character in INI files, most | - |
2517 | Windows applications don't escape backslashes (\c{\}) in file | - |
2518 | paths: | - |
2519 | | - |
2520 | \snippet code/src_corelib_io_qsettings.cpp 9 | - |
2521 | | - |
2522 | QSettings always treats backslash as a special character and | - |
2523 | provides no API for reading or writing such entries. | - |
2524 | | - |
2525 | \li The INI file format has severe restrictions on the syntax of | - |
2526 | a key. Qt works around this by using \c % as an escape | - |
2527 | character in keys. In addition, if you save a top-level | - |
2528 | setting (a key with no slashes in it, e.g., "someKey"), it | - |
2529 | will appear in the INI file's "General" section. To avoid | - |
2530 | overwriting other keys, if you save something using the a key | - |
2531 | such as "General/someKey", the key will be located in the | - |
2532 | "%General" section, \e not in the "General" section. | - |
2533 | | - |
2534 | \li Following the philosophy that we should be liberal in what | - |
2535 | we accept and conservative in what we generate, QSettings | - |
2536 | will accept Latin-1 encoded INI files, but generate pure | - |
2537 | ASCII files, where non-ASCII values are encoded using standard | - |
2538 | INI escape sequences. To make the INI files more readable (but | - |
2539 | potentially less compatible), call setIniCodec(). | - |
2540 | \endlist | - |
2541 | | - |
2542 | \sa registerFormat(), setPath() | - |
2543 | */ | - |
2544 | | - |
2545 | /*! \enum QSettings::Scope | - |
2546 | | - |
2547 | This enum specifies whether settings are user-specific or shared | - |
2548 | by all users of the same system. | - |
2549 | | - |
2550 | \value UserScope Store settings in a location specific to the | - |
2551 | current user (e.g., in the user's home | - |
2552 | directory). | - |
2553 | \value SystemScope Store settings in a global location, so that | - |
2554 | all users on the same machine access the same | - |
2555 | set of settings. | - |
2556 | | - |
2557 | \sa setPath() | - |
2558 | */ | - |
2559 | | - |
2560 | #ifndef QT_NO_QOBJECT | - |
2561 | /*! | - |
2562 | Constructs a QSettings object for accessing settings of the | - |
2563 | application called \a application from the organization called \a | - |
2564 | organization, and with parent \a parent. | - |
2565 | | - |
2566 | Example: | - |
2567 | \snippet code/src_corelib_io_qsettings.cpp 10 | - |
2568 | | - |
2569 | The scope is set to QSettings::UserScope, and the format is | - |
2570 | set to QSettings::NativeFormat (i.e. calling setDefaultFormat() | - |
2571 | before calling this constructor has no effect). | - |
2572 | | - |
2573 | \sa setDefaultFormat(), {Fallback Mechanism} | - |
2574 | */ | - |
2575 | QSettings::QSettings(const QString &organization, const QString &application, QObject *parent) | - |
2576 | : QObject(*QSettingsPrivate::create(NativeFormat, UserScope, organization, application), | - |
2577 | parent) | - |
2578 | { | - |
2579 | } executed: } Execution Count:36 | 36 |
2580 | | - |
2581 | /*! | - |
2582 | Constructs a QSettings object for accessing settings of the | - |
2583 | application called \a application from the organization called \a | - |
2584 | organization, and with parent \a parent. | - |
2585 | | - |
2586 | If \a scope is QSettings::UserScope, the QSettings object searches | - |
2587 | user-specific settings first, before it searches system-wide | - |
2588 | settings as a fallback. If \a scope is QSettings::SystemScope, the | - |
2589 | QSettings object ignores user-specific settings and provides | - |
2590 | access to system-wide settings. | - |
2591 | | - |
2592 | The storage format is set to QSettings::NativeFormat (i.e. calling | - |
2593 | setDefaultFormat() before calling this constructor has no effect). | - |
2594 | | - |
2595 | If no application name is given, the QSettings object will | - |
2596 | only access the organization-wide \l{Fallback Mechanism}{locations}. | - |
2597 | | - |
2598 | \sa setDefaultFormat() | - |
2599 | */ | - |
2600 | QSettings::QSettings(Scope scope, const QString &organization, const QString &application, | - |
2601 | QObject *parent) | - |
2602 | : QObject(*QSettingsPrivate::create(NativeFormat, scope, organization, application), parent) | - |
2603 | { | - |
2604 | } executed: } Execution Count:561 | 561 |
2605 | | - |
2606 | /*! | - |
2607 | Constructs a QSettings object for accessing settings of the | - |
2608 | application called \a application from the organization called | - |
2609 | \a organization, and with parent \a parent. | - |
2610 | | - |
2611 | If \a scope is QSettings::UserScope, the QSettings object searches | - |
2612 | user-specific settings first, before it searches system-wide | - |
2613 | settings as a fallback. If \a scope is | - |
2614 | QSettings::SystemScope, the QSettings object ignores user-specific | - |
2615 | settings and provides access to system-wide settings. | - |
2616 | | - |
2617 | If \a format is QSettings::NativeFormat, the native API is used for | - |
2618 | storing settings. If \a format is QSettings::IniFormat, the INI format | - |
2619 | is used. | - |
2620 | | - |
2621 | If no application name is given, the QSettings object will | - |
2622 | only access the organization-wide \l{Fallback Mechanism}{locations}. | - |
2623 | */ | - |
2624 | QSettings::QSettings(Format format, Scope scope, const QString &organization, | - |
2625 | const QString &application, QObject *parent) | - |
2626 | : QObject(*QSettingsPrivate::create(format, scope, organization, application), parent) | - |
2627 | { | - |
2628 | } executed: } Execution Count:157 | 157 |
2629 | | - |
2630 | /*! | - |
2631 | Constructs a QSettings object for accessing the settings | - |
2632 | stored in the file called \a fileName, with parent \a parent. If | - |
2633 | the file doesn't already exist, it is created. | - |
2634 | | - |
2635 | If \a format is QSettings::NativeFormat, the meaning of \a | - |
2636 | fileName depends on the platform. On Unix, \a fileName is the | - |
2637 | name of an INI file. On Mac OS X, \a fileName is the name of a | - |
2638 | \c .plist file. On Windows, \a fileName is a path in the system | - |
2639 | registry. | - |
2640 | | - |
2641 | If \a format is QSettings::IniFormat, \a fileName is the name of an INI | - |
2642 | file. | - |
2643 | | - |
2644 | \warning This function is provided for convenience. It works well for | - |
2645 | accessing INI or \c .plist files generated by Qt, but might fail on some | - |
2646 | syntaxes found in such files originated by other programs. In particular, | - |
2647 | be aware of the following limitations: | - |
2648 | | - |
2649 | \list | - |
2650 | \li QSettings provides no way of reading INI "path" entries, i.e., entries | - |
2651 | with unescaped slash characters. (This is because these entries are | - |
2652 | ambiguous and cannot be resolved automatically.) | - |
2653 | \li In INI files, QSettings uses the \c @ character as a metacharacter in some | - |
2654 | contexts, to encode Qt-specific data types (e.g., \c @Rect), and might | - |
2655 | therefore misinterpret it when it occurs in pure INI files. | - |
2656 | \endlist | - |
2657 | | - |
2658 | \sa fileName() | - |
2659 | */ | - |
2660 | QSettings::QSettings(const QString &fileName, Format format, QObject *parent) | - |
2661 | : QObject(*QSettingsPrivate::create(fileName, format), parent) | - |
2662 | { | - |
2663 | } executed: } Execution Count:44 | 44 |
2664 | | - |
2665 | /*! | - |
2666 | Constructs a QSettings object for accessing settings of the | - |
2667 | application and organization set previously with a call to | - |
2668 | QCoreApplication::setOrganizationName(), | - |
2669 | QCoreApplication::setOrganizationDomain(), and | - |
2670 | QCoreApplication::setApplicationName(). | - |
2671 | | - |
2672 | The scope is QSettings::UserScope and the format is | - |
2673 | defaultFormat() (QSettings::NativeFormat by default). | - |
2674 | Use setDefaultFormat() before calling this constructor | - |
2675 | to change the default format used by this constructor. | - |
2676 | | - |
2677 | The code | - |
2678 | | - |
2679 | \snippet code/src_corelib_io_qsettings.cpp 11 | - |
2680 | | - |
2681 | is equivalent to | - |
2682 | | - |
2683 | \snippet code/src_corelib_io_qsettings.cpp 12 | - |
2684 | | - |
2685 | If QCoreApplication::setOrganizationName() and | - |
2686 | QCoreApplication::setApplicationName() has not been previously | - |
2687 | called, the QSettings object will not be able to read or write | - |
2688 | any settings, and status() will return AccessError. | - |
2689 | | - |
2690 | On Mac OS X, if both a name and an Internet domain are specified | - |
2691 | for the organization, the domain is preferred over the name. On | - |
2692 | other platforms, the name is preferred over the domain. | - |
2693 | | - |
2694 | \sa QCoreApplication::setOrganizationName(), | - |
2695 | QCoreApplication::setOrganizationDomain(), | - |
2696 | QCoreApplication::setApplicationName(), | - |
2697 | setDefaultFormat() | - |
2698 | */ | - |
2699 | QSettings::QSettings(QObject *parent) | - |
2700 | : QObject(*QSettingsPrivate::create(globalDefaultFormat, UserScope, | - |
2701 | #ifdef Q_OS_MAC | - |
2702 | QCoreApplication::organizationDomain().isEmpty() | - |
2703 | ? QCoreApplication::organizationName() | - |
2704 | : QCoreApplication::organizationDomain() | - |
2705 | #else | - |
2706 | QCoreApplication::organizationName().isEmpty() | - |
2707 | ? QCoreApplication::organizationDomain() | - |
2708 | : QCoreApplication::organizationName() | - |
2709 | #endif | - |
2710 | , QCoreApplication::applicationName()), | - |
2711 | parent) | - |
2712 | { | - |
2713 | } executed: } Execution Count:4 | 4 |
2714 | | - |
2715 | #else | - |
2716 | QSettings::QSettings(const QString &organization, const QString &application) | - |
2717 | : d_ptr(QSettingsPrivate::create(globalDefaultFormat, QSettings::UserScope, organization, application)) | - |
2718 | { | - |
2719 | d_ptr->q_ptr = this; | - |
2720 | } | - |
2721 | | - |
2722 | QSettings::QSettings(Scope scope, const QString &organization, const QString &application) | - |
2723 | : d_ptr(QSettingsPrivate::create(globalDefaultFormat, scope, organization, application)) | - |
2724 | { | - |
2725 | d_ptr->q_ptr = this; | - |
2726 | } | - |
2727 | | - |
2728 | QSettings::QSettings(Format format, Scope scope, const QString &organization, | - |
2729 | const QString &application) | - |
2730 | : d_ptr(QSettingsPrivate::create(format, scope, organization, application)) | - |
2731 | { | - |
2732 | d_ptr->q_ptr = this; | - |
2733 | } | - |
2734 | | - |
2735 | QSettings::QSettings(const QString &fileName, Format format) | - |
2736 | : d_ptr(QSettingsPrivate::create(fileName, format)) | - |
2737 | { | - |
2738 | d_ptr->q_ptr = this; | - |
2739 | } | - |
2740 | #endif | - |
2741 | | - |
2742 | /*! | - |
2743 | Destroys the QSettings object. | - |
2744 | | - |
2745 | Any unsaved changes will eventually be written to permanent | - |
2746 | storage. | - |
2747 | | - |
2748 | \sa sync() | - |
2749 | */ | - |
2750 | QSettings::~QSettings() | - |
2751 | { | - |
2752 | Q_D(QSettings); executed (the execution status of this line is deduced): QSettingsPrivate * const d = d_func(); | - |
2753 | if (d->pendingChanges) { evaluated: d->pendingChanges yes Evaluation Count:491 | yes Evaluation Count:311 |
| 311-491 |
2754 | QT_TRY { | - |
2755 | d->flush(); executed (the execution status of this line is deduced): d->flush(); | - |
2756 | } QT_CATCH(...) { executed: } Execution Count:491 | 491 |
2757 | ; // ok. then don't flush but at least don't throw in the destructor | - |
2758 | } | 0 |
2759 | } executed: } Execution Count:491 | 491 |
2760 | } executed: } Execution Count:802 | 802 |
2761 | | - |
2762 | /*! | - |
2763 | Removes all entries in the primary location associated to this | - |
2764 | QSettings object. | - |
2765 | | - |
2766 | Entries in fallback locations are not removed. | - |
2767 | | - |
2768 | If you only want to remove the entries in the current group(), | - |
2769 | use remove("") instead. | - |
2770 | | - |
2771 | \sa remove(), setFallbacksEnabled() | - |
2772 | */ | - |
2773 | void QSettings::clear() | - |
2774 | { | - |
2775 | Q_D(QSettings); executed (the execution status of this line is deduced): QSettingsPrivate * const d = d_func(); | - |
2776 | d->clear(); executed (the execution status of this line is deduced): d->clear(); | - |
2777 | d->requestUpdate(); executed (the execution status of this line is deduced): d->requestUpdate(); | - |
2778 | } executed: } Execution Count:14 | 14 |
2779 | | - |
2780 | /*! | - |
2781 | Writes any unsaved changes to permanent storage, and reloads any | - |
2782 | settings that have been changed in the meantime by another | - |
2783 | application. | - |
2784 | | - |
2785 | This function is called automatically from QSettings's destructor and | - |
2786 | by the event loop at regular intervals, so you normally don't need to | - |
2787 | call it yourself. | - |
2788 | | - |
2789 | \sa status() | - |
2790 | */ | - |
2791 | void QSettings::sync() | - |
2792 | { | - |
2793 | Q_D(QSettings); executed (the execution status of this line is deduced): QSettingsPrivate * const d = d_func(); | - |
2794 | d->sync(); executed (the execution status of this line is deduced): d->sync(); | - |
2795 | } executed: } Execution Count:62 | 62 |
2796 | | - |
2797 | /*! | - |
2798 | Returns the path where settings written using this QSettings | - |
2799 | object are stored. | - |
2800 | | - |
2801 | On Windows, if the format is QSettings::NativeFormat, the return value | - |
2802 | is a system registry path, not a file path. | - |
2803 | | - |
2804 | \sa isWritable(), format() | - |
2805 | */ | - |
2806 | QString QSettings::fileName() const | - |
2807 | { | - |
2808 | Q_D(const QSettings); executed (the execution status of this line is deduced): const QSettingsPrivate * const d = d_func(); | - |
2809 | return d->fileName(); executed: return d->fileName(); Execution Count:25 | 25 |
2810 | } | - |
2811 | | - |
2812 | /*! | - |
2813 | \since 4.4 | - |
2814 | | - |
2815 | Returns the format used for storing the settings. | - |
2816 | | - |
2817 | \sa defaultFormat(), fileName(), scope(), organizationName(), applicationName() | - |
2818 | */ | - |
2819 | QSettings::Format QSettings::format() const | - |
2820 | { | - |
2821 | Q_D(const QSettings); executed (the execution status of this line is deduced): const QSettingsPrivate * const d = d_func(); | - |
2822 | return d->format; executed: return d->format; Execution Count:30 | 30 |
2823 | } | - |
2824 | | - |
2825 | /*! | - |
2826 | \since 4.4 | - |
2827 | | - |
2828 | Returns the scope used for storing the settings. | - |
2829 | | - |
2830 | \sa format(), organizationName(), applicationName() | - |
2831 | */ | - |
2832 | QSettings::Scope QSettings::scope() const | - |
2833 | { | - |
2834 | Q_D(const QSettings); executed (the execution status of this line is deduced): const QSettingsPrivate * const d = d_func(); | - |
2835 | return d->scope; executed: return d->scope; Execution Count:28 | 28 |
2836 | } | - |
2837 | | - |
2838 | /*! | - |
2839 | \since 4.4 | - |
2840 | | - |
2841 | Returns the organization name used for storing the settings. | - |
2842 | | - |
2843 | \sa QCoreApplication::organizationName(), format(), scope(), applicationName() | - |
2844 | */ | - |
2845 | QString QSettings::organizationName() const | - |
2846 | { | - |
2847 | Q_D(const QSettings); executed (the execution status of this line is deduced): const QSettingsPrivate * const d = d_func(); | - |
2848 | return d->organizationName; executed: return d->organizationName; Execution Count:32 | 32 |
2849 | } | - |
2850 | | - |
2851 | /*! | - |
2852 | \since 4.4 | - |
2853 | | - |
2854 | Returns the application name used for storing the settings. | - |
2855 | | - |
2856 | \sa QCoreApplication::applicationName(), format(), scope(), organizationName() | - |
2857 | */ | - |
2858 | QString QSettings::applicationName() const | - |
2859 | { | - |
2860 | Q_D(const QSettings); executed (the execution status of this line is deduced): const QSettingsPrivate * const d = d_func(); | - |
2861 | return d->applicationName; executed: return d->applicationName; Execution Count:24 | 24 |
2862 | } | - |
2863 | | - |
2864 | #ifndef QT_NO_TEXTCODEC | - |
2865 | | - |
2866 | /*! | - |
2867 | \since 4.5 | - |
2868 | | - |
2869 | Sets the codec for accessing INI files (including \c .conf files on Unix) | - |
2870 | to \a codec. The codec is used for decoding any data that is read from | - |
2871 | the INI file, and for encoding any data that is written to the file. By | - |
2872 | default, no codec is used, and non-ASCII characters are encoded using | - |
2873 | standard INI escape sequences. | - |
2874 | | - |
2875 | \warning The codec must be set immediately after creating the QSettings | - |
2876 | object, before accessing any data. | - |
2877 | | - |
2878 | \sa iniCodec() | - |
2879 | */ | - |
2880 | void QSettings::setIniCodec(QTextCodec *codec) | - |
2881 | { | - |
2882 | Q_D(QSettings); never executed (the execution status of this line is deduced): QSettingsPrivate * const d = d_func(); | - |
2883 | d->iniCodec = codec; never executed (the execution status of this line is deduced): d->iniCodec = codec; | - |
2884 | } | 0 |
2885 | | - |
2886 | /*! | - |
2887 | \since 4.5 | - |
2888 | \overload | - |
2889 | | - |
2890 | Sets the codec for accessing INI files (including \c .conf files on Unix) | - |
2891 | to the QTextCodec for the encoding specified by \a codecName. Common | - |
2892 | values for \c codecName include "ISO 8859-1", "UTF-8", and "UTF-16". | - |
2893 | If the encoding isn't recognized, nothing happens. | - |
2894 | | - |
2895 | \sa QTextCodec::codecForName() | - |
2896 | */ | - |
2897 | void QSettings::setIniCodec(const char *codecName) | - |
2898 | { | - |
2899 | Q_D(QSettings); never executed (the execution status of this line is deduced): QSettingsPrivate * const d = d_func(); | - |
2900 | if (QTextCodec *codec = QTextCodec::codecForName(codecName)) never evaluated: QTextCodec *codec = QTextCodec::codecForName(codecName) | 0 |
2901 | d->iniCodec = codec; never executed: d->iniCodec = codec; | 0 |
2902 | } | 0 |
2903 | | - |
2904 | /*! | - |
2905 | \since 4.5 | - |
2906 | | - |
2907 | Returns the codec that is used for accessing INI files. By default, | - |
2908 | no codec is used, so a null pointer is returned. | - |
2909 | */ | - |
2910 | | - |
2911 | QTextCodec *QSettings::iniCodec() const | - |
2912 | { | - |
2913 | Q_D(const QSettings); never executed (the execution status of this line is deduced): const QSettingsPrivate * const d = d_func(); | - |
2914 | return d->iniCodec; never executed: return d->iniCodec; | 0 |
2915 | } | - |
2916 | | - |
2917 | #endif // QT_NO_TEXTCODEC | - |
2918 | | - |
2919 | /*! | - |
2920 | Returns a status code indicating the first error that was met by | - |
2921 | QSettings, or QSettings::NoError if no error occurred. | - |
2922 | | - |
2923 | Be aware that QSettings delays performing some operations. For this | - |
2924 | reason, you might want to call sync() to ensure that the data stored | - |
2925 | in QSettings is written to disk before calling status(). | - |
2926 | | - |
2927 | \sa sync() | - |
2928 | */ | - |
2929 | QSettings::Status QSettings::status() const | - |
2930 | { | - |
2931 | Q_D(const QSettings); executed (the execution status of this line is deduced): const QSettingsPrivate * const d = d_func(); | - |
2932 | return d->status; executed: return d->status; Execution Count:43 | 43 |
2933 | } | - |
2934 | | - |
2935 | /*! | - |
2936 | Appends \a prefix to the current group. | - |
2937 | | - |
2938 | The current group is automatically prepended to all keys | - |
2939 | specified to QSettings. In addition, query functions such as | - |
2940 | childGroups(), childKeys(), and allKeys() are based on the group. | - |
2941 | By default, no group is set. | - |
2942 | | - |
2943 | Groups are useful to avoid typing in the same setting paths over | - |
2944 | and over. For example: | - |
2945 | | - |
2946 | \snippet code/src_corelib_io_qsettings.cpp 13 | - |
2947 | | - |
2948 | This will set the value of three settings: | - |
2949 | | - |
2950 | \list | - |
2951 | \li \c mainwindow/size | - |
2952 | \li \c mainwindow/fullScreen | - |
2953 | \li \c outputpanel/visible | - |
2954 | \endlist | - |
2955 | | - |
2956 | Call endGroup() to reset the current group to what it was before | - |
2957 | the corresponding beginGroup() call. Groups can be nested. | - |
2958 | | - |
2959 | \sa endGroup(), group() | - |
2960 | */ | - |
2961 | void QSettings::beginGroup(const QString &prefix) | - |
2962 | { | - |
2963 | Q_D(QSettings); executed (the execution status of this line is deduced): QSettingsPrivate * const d = d_func(); | - |
2964 | d->beginGroupOrArray(QSettingsGroup(d->normalizedKey(prefix))); executed (the execution status of this line is deduced): d->beginGroupOrArray(QSettingsGroup(d->normalizedKey(prefix))); | - |
2965 | } executed: } Execution Count:624 | 624 |
2966 | | - |
2967 | /*! | - |
2968 | Resets the group to what it was before the corresponding | - |
2969 | beginGroup() call. | - |
2970 | | - |
2971 | Example: | - |
2972 | | - |
2973 | \snippet code/src_corelib_io_qsettings.cpp 14 | - |
2974 | | - |
2975 | \sa beginGroup(), group() | - |
2976 | */ | - |
2977 | void QSettings::endGroup() | - |
2978 | { | - |
2979 | Q_D(QSettings); executed (the execution status of this line is deduced): QSettingsPrivate * const d = d_func(); | - |
2980 | if (d->groupStack.isEmpty()) { evaluated: d->groupStack.isEmpty() yes Evaluation Count:14 | yes Evaluation Count:64 |
| 14-64 |
2981 | qWarning("QSettings::endGroup: No matching beginGroup()"); executed (the execution status of this line is deduced): QMessageLogger("io/qsettings.cpp", 2981, __PRETTY_FUNCTION__).warning("QSettings::endGroup: No matching beginGroup()"); | - |
2982 | return; executed: return; Execution Count:14 | 14 |
2983 | } | - |
2984 | | - |
2985 | QSettingsGroup group = d->groupStack.pop(); executed (the execution status of this line is deduced): QSettingsGroup group = d->groupStack.pop(); | - |
2986 | int len = group.toString().size(); executed (the execution status of this line is deduced): int len = group.toString().size(); | - |
2987 | if (len > 0) evaluated: len > 0 yes Evaluation Count:57 | yes Evaluation Count:7 |
| 7-57 |
2988 | d->groupPrefix.truncate(d->groupPrefix.size() - (len + 1)); executed: d->groupPrefix.truncate(d->groupPrefix.size() - (len + 1)); Execution Count:57 | 57 |
2989 | | - |
2990 | if (group.isArray()) evaluated: group.isArray() yes Evaluation Count:4 | yes Evaluation Count:60 |
| 4-60 |
2991 | qWarning("QSettings::endGroup: Expected endArray() instead"); executed: QMessageLogger("io/qsettings.cpp", 2991, __PRETTY_FUNCTION__).warning("QSettings::endGroup: Expected endArray() instead"); Execution Count:4 | 4 |
2992 | } executed: } Execution Count:64 | 64 |
2993 | | - |
2994 | /*! | - |
2995 | Returns the current group. | - |
2996 | | - |
2997 | \sa beginGroup(), endGroup() | - |
2998 | */ | - |
2999 | QString QSettings::group() const | - |
3000 | { | - |
3001 | Q_D(const QSettings); executed (the execution status of this line is deduced): const QSettingsPrivate * const d = d_func(); | - |
3002 | return d->groupPrefix.left(d->groupPrefix.size() - 1); executed: return d->groupPrefix.left(d->groupPrefix.size() - 1); Execution Count:118 | 118 |
3003 | } | - |
3004 | | - |
3005 | /*! | - |
3006 | Adds \a prefix to the current group and starts reading from an | - |
3007 | array. Returns the size of the array. | - |
3008 | | - |
3009 | Example: | - |
3010 | | - |
3011 | \snippet code/src_corelib_io_qsettings.cpp 15 | - |
3012 | | - |
3013 | Use beginWriteArray() to write the array in the first place. | - |
3014 | | - |
3015 | \sa beginWriteArray(), endArray(), setArrayIndex() | - |
3016 | */ | - |
3017 | int QSettings::beginReadArray(const QString &prefix) | - |
3018 | { | - |
3019 | Q_D(QSettings); executed (the execution status of this line is deduced): QSettingsPrivate * const d = d_func(); | - |
3020 | d->beginGroupOrArray(QSettingsGroup(d->normalizedKey(prefix), false)); executed (the execution status of this line is deduced): d->beginGroupOrArray(QSettingsGroup(d->normalizedKey(prefix), false)); | - |
3021 | return value(QLatin1String("size")).toInt(); executed: return value(QLatin1String("size")).toInt(); Execution Count:20 | 20 |
3022 | } | - |
3023 | | - |
3024 | /*! | - |
3025 | Adds \a prefix to the current group and starts writing an array | - |
3026 | of size \a size. If \a size is -1 (the default), it is automatically | - |
3027 | determined based on the indexes of the entries written. | - |
3028 | | - |
3029 | If you have many occurrences of a certain set of keys, you can | - |
3030 | use arrays to make your life easier. For example, let's suppose | - |
3031 | that you want to save a variable-length list of user names and | - |
3032 | passwords. You could then write: | - |
3033 | | - |
3034 | \snippet code/src_corelib_io_qsettings.cpp 16 | - |
3035 | | - |
3036 | The generated keys will have the form | - |
3037 | | - |
3038 | \list | - |
3039 | \li \c logins/size | - |
3040 | \li \c logins/1/userName | - |
3041 | \li \c logins/1/password | - |
3042 | \li \c logins/2/userName | - |
3043 | \li \c logins/2/password | - |
3044 | \li \c logins/3/userName | - |
3045 | \li \c logins/3/password | - |
3046 | \li ... | - |
3047 | \endlist | - |
3048 | | - |
3049 | To read back an array, use beginReadArray(). | - |
3050 | | - |
3051 | \sa beginReadArray(), endArray(), setArrayIndex() | - |
3052 | */ | - |
3053 | void QSettings::beginWriteArray(const QString &prefix, int size) | - |
3054 | { | - |
3055 | Q_D(QSettings); executed (the execution status of this line is deduced): QSettingsPrivate * const d = d_func(); | - |
3056 | d->beginGroupOrArray(QSettingsGroup(d->normalizedKey(prefix), size < 0)); executed (the execution status of this line is deduced): d->beginGroupOrArray(QSettingsGroup(d->normalizedKey(prefix), size < 0)); | - |
3057 | | - |
3058 | if (size < 0) evaluated: size < 0 yes Evaluation Count:12 | yes Evaluation Count:8 |
| 8-12 |
3059 | remove(QLatin1String("size")); executed: remove(QLatin1String("size")); Execution Count:12 | 12 |
3060 | else | - |
3061 | setValue(QLatin1String("size"), size); executed: setValue(QLatin1String("size"), size); Execution Count:8 | 8 |
3062 | } | - |
3063 | | - |
3064 | /*! | - |
3065 | Closes the array that was started using beginReadArray() or | - |
3066 | beginWriteArray(). | - |
3067 | | - |
3068 | \sa beginReadArray(), beginWriteArray() | - |
3069 | */ | - |
3070 | void QSettings::endArray() | - |
3071 | { | - |
3072 | Q_D(QSettings); executed (the execution status of this line is deduced): QSettingsPrivate * const d = d_func(); | - |
3073 | if (d->groupStack.isEmpty()) { partially evaluated: d->groupStack.isEmpty() no Evaluation Count:0 | yes Evaluation Count:44 |
| 0-44 |
3074 | qWarning("QSettings::endArray: No matching beginArray()"); never executed (the execution status of this line is deduced): QMessageLogger("io/qsettings.cpp", 3074, __PRETTY_FUNCTION__).warning("QSettings::endArray: No matching beginArray()"); | - |
3075 | return; | 0 |
3076 | } | - |
3077 | | - |
3078 | QSettingsGroup group = d->groupStack.top(); executed (the execution status of this line is deduced): QSettingsGroup group = d->groupStack.top(); | - |
3079 | int len = group.toString().size(); executed (the execution status of this line is deduced): int len = group.toString().size(); | - |
3080 | d->groupStack.pop(); executed (the execution status of this line is deduced): d->groupStack.pop(); | - |
3081 | if (len > 0) partially evaluated: len > 0 yes Evaluation Count:44 | no Evaluation Count:0 |
| 0-44 |
3082 | d->groupPrefix.truncate(d->groupPrefix.size() - (len + 1)); executed: d->groupPrefix.truncate(d->groupPrefix.size() - (len + 1)); Execution Count:44 | 44 |
3083 | | - |
3084 | if (group.arraySizeGuess() != -1) evaluated: group.arraySizeGuess() != -1 yes Evaluation Count:12 | yes Evaluation Count:32 |
| 12-32 |
3085 | setValue(group.name() + QLatin1String("/size"), group.arraySizeGuess()); executed: setValue(group.name() + QLatin1String("/size"), group.arraySizeGuess()); Execution Count:12 | 12 |
3086 | | - |
3087 | if (!group.isArray()) evaluated: !group.isArray() yes Evaluation Count:8 | yes Evaluation Count:36 |
| 8-36 |
3088 | qWarning("QSettings::endArray: Expected endGroup() instead"); executed: QMessageLogger("io/qsettings.cpp", 3088, __PRETTY_FUNCTION__).warning("QSettings::endArray: Expected endGroup() instead"); Execution Count:8 | 8 |
3089 | } executed: } Execution Count:44 | 44 |
3090 | | - |
3091 | /*! | - |
3092 | Sets the current array index to \a i. Calls to functions such as | - |
3093 | setValue(), value(), remove(), and contains() will operate on the | - |
3094 | array entry at that index. | - |
3095 | | - |
3096 | You must call beginReadArray() or beginWriteArray() before you | - |
3097 | can call this function. | - |
3098 | */ | - |
3099 | void QSettings::setArrayIndex(int i) | - |
3100 | { | - |
3101 | Q_D(QSettings); executed (the execution status of this line is deduced): QSettingsPrivate * const d = d_func(); | - |
3102 | if (d->groupStack.isEmpty() || !d->groupStack.top().isArray()) { partially evaluated: d->groupStack.isEmpty() no Evaluation Count:0 | yes Evaluation Count:148 |
evaluated: !d->groupStack.top().isArray() yes Evaluation Count:20 | yes Evaluation Count:128 |
| 0-148 |
3103 | qWarning("QSettings::setArrayIndex: Missing beginArray()"); executed (the execution status of this line is deduced): QMessageLogger("io/qsettings.cpp", 3103, __PRETTY_FUNCTION__).warning("QSettings::setArrayIndex: Missing beginArray()"); | - |
3104 | return; executed: return; Execution Count:20 | 20 |
3105 | } | - |
3106 | | - |
3107 | QSettingsGroup &top = d->groupStack.top(); executed (the execution status of this line is deduced): QSettingsGroup &top = d->groupStack.top(); | - |
3108 | int len = top.toString().size(); executed (the execution status of this line is deduced): int len = top.toString().size(); | - |
3109 | top.setArrayIndex(qMax(i, 0)); executed (the execution status of this line is deduced): top.setArrayIndex(qMax(i, 0)); | - |
3110 | d->groupPrefix.replace(d->groupPrefix.size() - len - 1, len, top.toString()); executed (the execution status of this line is deduced): d->groupPrefix.replace(d->groupPrefix.size() - len - 1, len, top.toString()); | - |
3111 | } executed: } Execution Count:128 | 128 |
3112 | | - |
3113 | /*! | - |
3114 | Returns a list of all keys, including subkeys, that can be read | - |
3115 | using the QSettings object. | - |
3116 | | - |
3117 | Example: | - |
3118 | | - |
3119 | \snippet code/src_corelib_io_qsettings.cpp 17 | - |
3120 | | - |
3121 | If a group is set using beginGroup(), only the keys in the group | - |
3122 | are returned, without the group prefix: | - |
3123 | | - |
3124 | \snippet code/src_corelib_io_qsettings.cpp 18 | - |
3125 | | - |
3126 | \sa childGroups(), childKeys() | - |
3127 | */ | - |
3128 | QStringList QSettings::allKeys() const | - |
3129 | { | - |
3130 | Q_D(const QSettings); executed (the execution status of this line is deduced): const QSettingsPrivate * const d = d_func(); | - |
3131 | return d->children(d->groupPrefix, QSettingsPrivate::AllKeys); executed: return d->children(d->groupPrefix, QSettingsPrivate::AllKeys); Execution Count:112 | 112 |
3132 | } | - |
3133 | | - |
3134 | /*! | - |
3135 | Returns a list of all top-level keys that can be read using the | - |
3136 | QSettings object. | - |
3137 | | - |
3138 | Example: | - |
3139 | | - |
3140 | \snippet code/src_corelib_io_qsettings.cpp 19 | - |
3141 | | - |
3142 | If a group is set using beginGroup(), the top-level keys in that | - |
3143 | group are returned, without the group prefix: | - |
3144 | | - |
3145 | \snippet code/src_corelib_io_qsettings.cpp 20 | - |
3146 | | - |
3147 | You can navigate through the entire setting hierarchy using | - |
3148 | childKeys() and childGroups() recursively. | - |
3149 | | - |
3150 | \sa childGroups(), allKeys() | - |
3151 | */ | - |
3152 | QStringList QSettings::childKeys() const | - |
3153 | { | - |
3154 | Q_D(const QSettings); executed (the execution status of this line is deduced): const QSettingsPrivate * const d = d_func(); | - |
3155 | return d->children(d->groupPrefix, QSettingsPrivate::ChildKeys); executed: return d->children(d->groupPrefix, QSettingsPrivate::ChildKeys); Execution Count:20 | 20 |
3156 | } | - |
3157 | | - |
3158 | /*! | - |
3159 | Returns a list of all key top-level groups that contain keys that | - |
3160 | can be read using the QSettings object. | - |
3161 | | - |
3162 | Example: | - |
3163 | | - |
3164 | \snippet code/src_corelib_io_qsettings.cpp 21 | - |
3165 | | - |
3166 | If a group is set using beginGroup(), the first-level keys in | - |
3167 | that group are returned, without the group prefix. | - |
3168 | | - |
3169 | \snippet code/src_corelib_io_qsettings.cpp 22 | - |
3170 | | - |
3171 | You can navigate through the entire setting hierarchy using | - |
3172 | childKeys() and childGroups() recursively. | - |
3173 | | - |
3174 | \sa childKeys(), allKeys() | - |
3175 | */ | - |
3176 | QStringList QSettings::childGroups() const | - |
3177 | { | - |
3178 | Q_D(const QSettings); executed (the execution status of this line is deduced): const QSettingsPrivate * const d = d_func(); | - |
3179 | return d->children(d->groupPrefix, QSettingsPrivate::ChildGroups); executed: return d->children(d->groupPrefix, QSettingsPrivate::ChildGroups); Execution Count:24 | 24 |
3180 | } | - |
3181 | | - |
3182 | /*! | - |
3183 | Returns true if settings can be written using this QSettings | - |
3184 | object; returns false otherwise. | - |
3185 | | - |
3186 | One reason why isWritable() might return false is if | - |
3187 | QSettings operates on a read-only file. | - |
3188 | | - |
3189 | \warning This function is not perfectly reliable, because the | - |
3190 | file permissions can change at any time. | - |
3191 | | - |
3192 | \sa fileName(), status(), sync() | - |
3193 | */ | - |
3194 | bool QSettings::isWritable() const | - |
3195 | { | - |
3196 | Q_D(const QSettings); executed (the execution status of this line is deduced): const QSettingsPrivate * const d = d_func(); | - |
3197 | return d->isWritable(); executed: return d->isWritable(); Execution Count:21 | 21 |
3198 | } | - |
3199 | | - |
3200 | /*! | - |
3201 | | - |
3202 | Sets the value of setting \a key to \a value. If the \a key already | - |
3203 | exists, the previous value is overwritten. | - |
3204 | | - |
3205 | Note that the Windows registry and INI files use case-insensitive | - |
3206 | keys, whereas the Carbon Preferences API on Mac OS X uses | - |
3207 | case-sensitive keys. To avoid portability problems, see the | - |
3208 | \l{Section and Key Syntax} rules. | - |
3209 | | - |
3210 | Example: | - |
3211 | | - |
3212 | \snippet code/src_corelib_io_qsettings.cpp 23 | - |
3213 | | - |
3214 | \sa value(), remove(), contains() | - |
3215 | */ | - |
3216 | void QSettings::setValue(const QString &key, const QVariant &value) | - |
3217 | { | - |
3218 | Q_D(QSettings); executed (the execution status of this line is deduced): QSettingsPrivate * const d = d_func(); | - |
3219 | QString k = d->actualKey(key); executed (the execution status of this line is deduced): QString k = d->actualKey(key); | - |
3220 | d->set(k, value); executed (the execution status of this line is deduced): d->set(k, value); | - |
3221 | d->requestUpdate(); executed (the execution status of this line is deduced): d->requestUpdate(); | - |
3222 | } executed: } Execution Count:834 | 834 |
3223 | | - |
3224 | /*! | - |
3225 | Removes the setting \a key and any sub-settings of \a key. | - |
3226 | | - |
3227 | Example: | - |
3228 | | - |
3229 | \snippet code/src_corelib_io_qsettings.cpp 24 | - |
3230 | | - |
3231 | Be aware that if one of the fallback locations contains a setting | - |
3232 | with the same key, that setting will be visible after calling | - |
3233 | remove(). | - |
3234 | | - |
3235 | If \a key is an empty string, all keys in the current group() are | - |
3236 | removed. For example: | - |
3237 | | - |
3238 | \snippet code/src_corelib_io_qsettings.cpp 25 | - |
3239 | | - |
3240 | Note that the Windows registry and INI files use case-insensitive | - |
3241 | keys, whereas the Carbon Preferences API on Mac OS X uses | - |
3242 | case-sensitive keys. To avoid portability problems, see the | - |
3243 | \l{Section and Key Syntax} rules. | - |
3244 | | - |
3245 | \sa setValue(), value(), contains() | - |
3246 | */ | - |
3247 | void QSettings::remove(const QString &key) | - |
3248 | { | - |
3249 | Q_D(QSettings); executed (the execution status of this line is deduced): QSettingsPrivate * const d = d_func(); | - |
3250 | /* | - |
3251 | We cannot use actualKey(), because remove() supports empty | - |
3252 | keys. The code is also tricky because of slash handling. | - |
3253 | */ | - |
3254 | QString theKey = d->normalizedKey(key); executed (the execution status of this line is deduced): QString theKey = d->normalizedKey(key); | - |
3255 | if (theKey.isEmpty()) evaluated: theKey.isEmpty() yes Evaluation Count:3 | yes Evaluation Count:123 |
| 3-123 |
3256 | theKey = group(); executed: theKey = group(); Execution Count:3 | 3 |
3257 | else | - |
3258 | theKey.prepend(d->groupPrefix); executed: theKey.prepend(d->groupPrefix); Execution Count:123 | 123 |
3259 | | - |
3260 | if (theKey.isEmpty()) { evaluated: theKey.isEmpty() yes Evaluation Count:1 | yes Evaluation Count:125 |
| 1-125 |
3261 | d->clear(); executed (the execution status of this line is deduced): d->clear(); | - |
3262 | } else { executed: } Execution Count:1 | 1 |
3263 | d->remove(theKey); executed (the execution status of this line is deduced): d->remove(theKey); | - |
3264 | } executed: } Execution Count:125 | 125 |
3265 | d->requestUpdate(); executed (the execution status of this line is deduced): d->requestUpdate(); | - |
3266 | } executed: } Execution Count:126 | 126 |
3267 | | - |
3268 | /*! | - |
3269 | Returns true if there exists a setting called \a key; returns | - |
3270 | false otherwise. | - |
3271 | | - |
3272 | If a group is set using beginGroup(), \a key is taken to be | - |
3273 | relative to that group. | - |
3274 | | - |
3275 | Note that the Windows registry and INI files use case-insensitive | - |
3276 | keys, whereas the Carbon Preferences API on Mac OS X uses | - |
3277 | case-sensitive keys. To avoid portability problems, see the | - |
3278 | \l{Section and Key Syntax} rules. | - |
3279 | | - |
3280 | \sa value(), setValue() | - |
3281 | */ | - |
3282 | bool QSettings::contains(const QString &key) const | - |
3283 | { | - |
3284 | Q_D(const QSettings); executed (the execution status of this line is deduced): const QSettingsPrivate * const d = d_func(); | - |
3285 | QString k = d->actualKey(key); executed (the execution status of this line is deduced): QString k = d->actualKey(key); | - |
3286 | return d->get(k, 0); executed: return d->get(k, 0); Execution Count:198 | 198 |
3287 | } | - |
3288 | | - |
3289 | /*! | - |
3290 | Sets whether fallbacks are enabled to \a b. | - |
3291 | | - |
3292 | By default, fallbacks are enabled. | - |
3293 | | - |
3294 | \sa fallbacksEnabled() | - |
3295 | */ | - |
3296 | void QSettings::setFallbacksEnabled(bool b) | - |
3297 | { | - |
3298 | Q_D(QSettings); executed (the execution status of this line is deduced): QSettingsPrivate * const d = d_func(); | - |
3299 | d->fallbacks = !!b; executed (the execution status of this line is deduced): d->fallbacks = !!b; | - |
3300 | } executed: } Execution Count:22 | 22 |
3301 | | - |
3302 | /*! | - |
3303 | Returns true if fallbacks are enabled; returns false otherwise. | - |
3304 | | - |
3305 | By default, fallbacks are enabled. | - |
3306 | | - |
3307 | \sa setFallbacksEnabled() | - |
3308 | */ | - |
3309 | bool QSettings::fallbacksEnabled() const | - |
3310 | { | - |
3311 | Q_D(const QSettings); executed (the execution status of this line is deduced): const QSettingsPrivate * const d = d_func(); | - |
3312 | return d->fallbacks; executed: return d->fallbacks; Execution Count:34 | 34 |
3313 | } | - |
3314 | | - |
3315 | #ifndef QT_NO_QOBJECT | - |
3316 | /*! | - |
3317 | \reimp | - |
3318 | */ | - |
3319 | bool QSettings::event(QEvent *event) | - |
3320 | { | - |
3321 | Q_D(QSettings); executed (the execution status of this line is deduced): QSettingsPrivate * const d = d_func(); | - |
3322 | if (event->type() == QEvent::UpdateRequest) { partially evaluated: event->type() == QEvent::UpdateRequest yes Evaluation Count:4 | no Evaluation Count:0 |
| 0-4 |
3323 | d->update(); executed (the execution status of this line is deduced): d->update(); | - |
3324 | return true; executed: return true; Execution Count:4 | 4 |
3325 | } | - |
3326 | return QObject::event(event); never executed: return QObject::event(event); | 0 |
3327 | } | - |
3328 | #endif | - |
3329 | | - |
3330 | /*! | - |
3331 | Returns the value for setting \a key. If the setting doesn't | - |
3332 | exist, returns \a defaultValue. | - |
3333 | | - |
3334 | If no default value is specified, a default QVariant is | - |
3335 | returned. | - |
3336 | | - |
3337 | Note that the Windows registry and INI files use case-insensitive | - |
3338 | keys, whereas the Carbon Preferences API on Mac OS X uses | - |
3339 | case-sensitive keys. To avoid portability problems, see the | - |
3340 | \l{Section and Key Syntax} rules. | - |
3341 | | - |
3342 | Example: | - |
3343 | | - |
3344 | \snippet code/src_corelib_io_qsettings.cpp 26 | - |
3345 | | - |
3346 | \sa setValue(), contains(), remove() | - |
3347 | */ | - |
3348 | QVariant QSettings::value(const QString &key, const QVariant &defaultValue) const | - |
3349 | { | - |
3350 | Q_D(const QSettings); executed (the execution status of this line is deduced): const QSettingsPrivate * const d = d_func(); | - |
3351 | QVariant result = defaultValue; executed (the execution status of this line is deduced): QVariant result = defaultValue; | - |
3352 | QString k = d->actualKey(key); executed (the execution status of this line is deduced): QString k = d->actualKey(key); | - |
3353 | d->get(k, &result); executed (the execution status of this line is deduced): d->get(k, &result); | - |
3354 | return result; executed: return result; Execution Count:2534 | 2534 |
3355 | } | - |
3356 | | - |
3357 | /*! | - |
3358 | \since 4.4 | - |
3359 | | - |
3360 | Sets the default file format to the given \a format, which is used | - |
3361 | for storing settings for the QSettings(QObject *) constructor. | - |
3362 | | - |
3363 | If no default format is set, QSettings::NativeFormat is used. See | - |
3364 | the documentation for the QSettings constructor you are using to | - |
3365 | see if that constructor will ignore this function. | - |
3366 | | - |
3367 | \sa format() | - |
3368 | */ | - |
3369 | void QSettings::setDefaultFormat(Format format) | - |
3370 | { | - |
3371 | globalDefaultFormat = format; executed (the execution status of this line is deduced): globalDefaultFormat = format; | - |
3372 | } executed: } Execution Count:2 | 2 |
3373 | | - |
3374 | /*! | - |
3375 | \since 4.4 | - |
3376 | | - |
3377 | Returns default file format used for storing settings for the QSettings(QObject *) constructor. | - |
3378 | If no default format is set, QSettings::NativeFormat is used. | - |
3379 | | - |
3380 | \sa format() | - |
3381 | */ | - |
3382 | QSettings::Format QSettings::defaultFormat() | - |
3383 | { | - |
3384 | return globalDefaultFormat; executed: return globalDefaultFormat; Execution Count:2 | 2 |
3385 | } | - |
3386 | | - |
3387 | /*! | - |
3388 | \obsolete | - |
3389 | | - |
3390 | Use setPath() instead. | - |
3391 | | - |
3392 | \oldcode | - |
3393 | setSystemIniPath(path); | - |
3394 | \newcode | - |
3395 | setPath(QSettings::NativeFormat, QSettings::SystemScope, path); | - |
3396 | setPath(QSettings::IniFormat, QSettings::SystemScope, path); | - |
3397 | \endcode | - |
3398 | */ | - |
3399 | void QSettings::setSystemIniPath(const QString &dir) | - |
3400 | { | - |
3401 | setPath(IniFormat, SystemScope, dir); executed (the execution status of this line is deduced): setPath(IniFormat, SystemScope, dir); | - |
3402 | #if !defined(Q_OS_WIN) && !defined(Q_OS_MAC) | - |
3403 | setPath(NativeFormat, SystemScope, dir); executed (the execution status of this line is deduced): setPath(NativeFormat, SystemScope, dir); | - |
3404 | #endif | - |
3405 | } executed: } Execution Count:122 | 122 |
3406 | | - |
3407 | /*! | - |
3408 | \obsolete | - |
3409 | | - |
3410 | Use setPath() instead. | - |
3411 | */ | - |
3412 | | - |
3413 | void QSettings::setUserIniPath(const QString &dir) | - |
3414 | { | - |
3415 | setPath(IniFormat, UserScope, dir); executed (the execution status of this line is deduced): setPath(IniFormat, UserScope, dir); | - |
3416 | #if !defined(Q_OS_WIN) && !defined(Q_OS_MAC) | - |
3417 | setPath(NativeFormat, UserScope, dir); executed (the execution status of this line is deduced): setPath(NativeFormat, UserScope, dir); | - |
3418 | #endif | - |
3419 | } executed: } Execution Count:122 | 122 |
3420 | | - |
3421 | /*! | - |
3422 | \since 4.1 | - |
3423 | | - |
3424 | Sets the path used for storing settings for the given \a format | - |
3425 | and \a scope, to \a path. The \a format can be a custom format. | - |
3426 | | - |
3427 | The table below summarizes the default values: | - |
3428 | | - |
3429 | \table | - |
3430 | \header \li Platform \li Format \li Scope \li Path | - |
3431 | \row \li{1,2} Windows \li{1,2} IniFormat \li UserScope \li \c %APPDATA% | - |
3432 | \row \li SystemScope \li \c %COMMON_APPDATA% | - |
3433 | \row \li{1,2} Unix \li{1,2} NativeFormat, IniFormat \li UserScope \li \c $HOME/.config | - |
3434 | \row \li SystemScope \li \c /etc/xdg | - |
3435 | \row \li{1,2} Qt for Embedded Linux \li{1,2} NativeFormat, IniFormat \li UserScope \li \c $HOME/Settings | - |
3436 | \row \li SystemScope \li \c /etc/xdg | - |
3437 | \row \li{1,2} Mac OS X \li{1,2} IniFormat \li UserScope \li \c $HOME/.config | - |
3438 | \row \li SystemScope \li \c /etc/xdg | - |
3439 | \endtable | - |
3440 | | - |
3441 | The default UserScope paths on Unix and Mac OS X (\c | - |
3442 | $HOME/.config or $HOME/Settings) can be overridden by the user by setting the | - |
3443 | \c XDG_CONFIG_HOME environment variable. The default SystemScope | - |
3444 | paths on Unix and Mac OS X (\c /etc/xdg) can be overridden when | - |
3445 | building the Qt library using the \c configure script's \c | - |
3446 | --sysconfdir flag (see QLibraryInfo for details). | - |
3447 | | - |
3448 | Setting the NativeFormat paths on Windows and Mac OS X has no | - |
3449 | effect. | - |
3450 | | - |
3451 | \warning This function doesn't affect existing QSettings objects. | - |
3452 | | - |
3453 | \sa registerFormat() | - |
3454 | */ | - |
3455 | void QSettings::setPath(Format format, Scope scope, const QString &path) | - |
3456 | { | - |
3457 | QMutexLocker locker(&settingsGlobalMutex); executed (the execution status of this line is deduced): QMutexLocker locker(&settingsGlobalMutex); | - |
3458 | PathHash *pathHash = pathHashFunc(); executed (the execution status of this line is deduced): PathHash *pathHash = pathHashFunc(); | - |
3459 | if (pathHash->isEmpty()) evaluated: pathHash->isEmpty() yes Evaluation Count:1 | yes Evaluation Count:495 |
| 1-495 |
3460 | initDefaultPaths(&locker); executed: initDefaultPaths(&locker); Execution Count:1 | 1 |
3461 | pathHash->insert(pathHashKey(format, scope), path + QDir::separator()); executed (the execution status of this line is deduced): pathHash->insert(pathHashKey(format, scope), path + QDir::separator()); | - |
3462 | } executed: } Execution Count:496 | 496 |
3463 | | - |
3464 | /*! | - |
3465 | \typedef QSettings::SettingsMap | - |
3466 | | - |
3467 | Typedef for QMap<QString, QVariant>. | - |
3468 | | - |
3469 | \sa registerFormat() | - |
3470 | */ | - |
3471 | | - |
3472 | /*! | - |
3473 | \typedef QSettings::ReadFunc | - |
3474 | | - |
3475 | Typedef for a pointer to a function with the following signature: | - |
3476 | | - |
3477 | \snippet code/src_corelib_io_qsettings.cpp 27 | - |
3478 | | - |
3479 | \c ReadFunc is used in \c registerFormat() as a pointer to a function | - |
3480 | that reads a set of key/value pairs. \c ReadFunc should read all the | - |
3481 | options in one pass, and return all the settings in the \c SettingsMap | - |
3482 | container, which is initially empty. | - |
3483 | | - |
3484 | \sa WriteFunc, registerFormat() | - |
3485 | */ | - |
3486 | | - |
3487 | /*! | - |
3488 | \typedef QSettings::WriteFunc | - |
3489 | | - |
3490 | Typedef for a pointer to a function with the following signature: | - |
3491 | | - |
3492 | \snippet code/src_corelib_io_qsettings.cpp 28 | - |
3493 | | - |
3494 | \c WriteFunc is used in \c registerFormat() as a pointer to a function | - |
3495 | that writes a set of key/value pairs. \c WriteFunc is only called once, | - |
3496 | so you need to output the settings in one go. | - |
3497 | | - |
3498 | \sa ReadFunc, registerFormat() | - |
3499 | */ | - |
3500 | | - |
3501 | /*! | - |
3502 | \since 4.1 | - |
3503 | \threadsafe | - |
3504 | | - |
3505 | Registers a custom storage format. On success, returns a special | - |
3506 | Format value that can then be passed to the QSettings constructor. | - |
3507 | On failure, returns InvalidFormat. | - |
3508 | | - |
3509 | The \a extension is the file | - |
3510 | extension associated to the format (without the '.'). | - |
3511 | | - |
3512 | The \a readFunc and \a writeFunc parameters are pointers to | - |
3513 | functions that read and write a set of key/value pairs. The | - |
3514 | QIODevice parameter to the read and write functions is always | - |
3515 | opened in binary mode (i.e., without the QIODevice::Text flag). | - |
3516 | | - |
3517 | The \a caseSensitivity parameter specifies whether keys are case | - |
3518 | sensitive or not. This makes a difference when looking up values | - |
3519 | using QSettings. The default is case sensitive. | - |
3520 | | - |
3521 | By default, if you use one of the constructors that work in terms | - |
3522 | of an organization name and an application name, the file system | - |
3523 | locations used are the same as for IniFormat. Use setPath() to | - |
3524 | specify other locations. | - |
3525 | | - |
3526 | Example: | - |
3527 | | - |
3528 | \snippet code/src_corelib_io_qsettings.cpp 29 | - |
3529 | | - |
3530 | \sa setPath() | - |
3531 | */ | - |
3532 | QSettings::Format QSettings::registerFormat(const QString &extension, ReadFunc readFunc, | - |
3533 | WriteFunc writeFunc, | - |
3534 | Qt::CaseSensitivity caseSensitivity) | - |
3535 | { | - |
3536 | #ifdef QT_QSETTINGS_ALWAYS_CASE_SENSITIVE_AND_FORGET_ORIGINAL_KEY_ORDER | - |
3537 | Q_ASSERT(caseSensitivity == Qt::CaseSensitive); executed (the execution status of this line is deduced): qt_noop(); | - |
3538 | #endif | - |
3539 | | - |
3540 | QMutexLocker locker(&settingsGlobalMutex); executed (the execution status of this line is deduced): QMutexLocker locker(&settingsGlobalMutex); | - |
3541 | CustomFormatVector *customFormatVector = customFormatVectorFunc(); executed (the execution status of this line is deduced): CustomFormatVector *customFormatVector = customFormatVectorFunc(); | - |
3542 | int index = customFormatVector->size(); executed (the execution status of this line is deduced): int index = customFormatVector->size(); | - |
3543 | if (index == 16) // the QSettings::Format enum has room for 16 custom formats partially evaluated: index == 16 no Evaluation Count:0 | yes Evaluation Count:3 |
| 0-3 |
3544 | return QSettings::InvalidFormat; never executed: return QSettings::InvalidFormat; | 0 |
3545 | | - |
3546 | QConfFileCustomFormat info; executed (the execution status of this line is deduced): QConfFileCustomFormat info; | - |
3547 | info.extension = QLatin1Char('.'); executed (the execution status of this line is deduced): info.extension = QLatin1Char('.'); | - |
3548 | info.extension += extension; executed (the execution status of this line is deduced): info.extension += extension; | - |
3549 | info.readFunc = readFunc; executed (the execution status of this line is deduced): info.readFunc = readFunc; | - |
3550 | info.writeFunc = writeFunc; executed (the execution status of this line is deduced): info.writeFunc = writeFunc; | - |
3551 | info.caseSensitivity = caseSensitivity; executed (the execution status of this line is deduced): info.caseSensitivity = caseSensitivity; | - |
3552 | customFormatVector->append(info); executed (the execution status of this line is deduced): customFormatVector->append(info); | - |
3553 | | - |
3554 | return QSettings::Format((int)QSettings::CustomFormat1 + index); executed: return QSettings::Format((int)QSettings::CustomFormat1 + index); Execution Count:3 | 3 |
3555 | } | - |
3556 | | - |
3557 | QT_END_NAMESPACE | - |
3558 | | - |
3559 | #endif // QT_NO_SETTINGS | - |
3560 | | - |
| | |