Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/json/qjsonvalue.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||||||||
2 | ** | - | ||||||||||||||||||
3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||||||||
4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||
5 | ** | - | ||||||||||||||||||
6 | ** This file is part of the QtCore module of the Qt Toolkit. | - | ||||||||||||||||||
7 | ** | - | ||||||||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||
9 | ** Commercial License Usage | - | ||||||||||||||||||
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||
11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||
12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||
13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||
14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
15 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||||||||||||||
16 | ** | - | ||||||||||||||||||
17 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||
19 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||||||||||||||
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||
22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||
25 | ** | - | ||||||||||||||||||
26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||
27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||
29 | ** | - | ||||||||||||||||||
30 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
31 | ** | - | ||||||||||||||||||
32 | ****************************************************************************/ | - | ||||||||||||||||||
33 | - | |||||||||||||||||||
34 | #include <qjsonobject.h> | - | ||||||||||||||||||
35 | #include <qjsonvalue.h> | - | ||||||||||||||||||
36 | #include <qjsonarray.h> | - | ||||||||||||||||||
37 | #include <qvariant.h> | - | ||||||||||||||||||
38 | #include <qstringlist.h> | - | ||||||||||||||||||
39 | #include <qdebug.h> | - | ||||||||||||||||||
40 | - | |||||||||||||||||||
41 | #include "qjson_p.h" | - | ||||||||||||||||||
42 | - | |||||||||||||||||||
43 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
44 | - | |||||||||||||||||||
45 | /*! | - | ||||||||||||||||||
46 | \class QJsonValue | - | ||||||||||||||||||
47 | \inmodule QtCore | - | ||||||||||||||||||
48 | \ingroup json | - | ||||||||||||||||||
49 | \ingroup shared | - | ||||||||||||||||||
50 | \reentrant | - | ||||||||||||||||||
51 | \since 5.0 | - | ||||||||||||||||||
52 | - | |||||||||||||||||||
53 | \brief The QJsonValue class encapsulates a value in JSON. | - | ||||||||||||||||||
54 | - | |||||||||||||||||||
55 | A value in JSON can be one of 6 basic types: | - | ||||||||||||||||||
56 | - | |||||||||||||||||||
57 | JSON is a format to store structured data. It has 6 basic data types: | - | ||||||||||||||||||
58 | - | |||||||||||||||||||
59 | \list | - | ||||||||||||||||||
60 | \li bool QJsonValue::Bool | - | ||||||||||||||||||
61 | \li double QJsonValue::Double | - | ||||||||||||||||||
62 | \li string QJsonValue::String | - | ||||||||||||||||||
63 | \li array QJsonValue::Array | - | ||||||||||||||||||
64 | \li object QJsonValue::Object | - | ||||||||||||||||||
65 | \li null QJsonValue::Null | - | ||||||||||||||||||
66 | \endlist | - | ||||||||||||||||||
67 | - | |||||||||||||||||||
68 | A value can represent any of the above data types. In addition, QJsonValue has one special | - | ||||||||||||||||||
69 | flag to represent undefined values. This can be queried with isUndefined(). | - | ||||||||||||||||||
70 | - | |||||||||||||||||||
71 | The type of the value can be queried with type() or accessors like isBool(), isString(), and so on. | - | ||||||||||||||||||
72 | Likewise, the value can be converted to the type stored in it using the toBool(), toString() and so on. | - | ||||||||||||||||||
73 | - | |||||||||||||||||||
74 | Values are strictly typed internally and contrary to QVariant will not attempt to do any implicit type | - | ||||||||||||||||||
75 | conversions. This implies that converting to a type that is not stored in the value will return a default | - | ||||||||||||||||||
76 | constructed return value. | - | ||||||||||||||||||
77 | - | |||||||||||||||||||
78 | \section1 QJsonValueRef | - | ||||||||||||||||||
79 | - | |||||||||||||||||||
80 | QJsonValueRef is a helper class for QJsonArray and QJsonObject. | - | ||||||||||||||||||
81 | When you get an object of type QJsonValueRef, you can | - | ||||||||||||||||||
82 | use it as if it were a reference to a QJsonValue. If you assign to it, | - | ||||||||||||||||||
83 | the assignment will apply to the element in the QJsonArray or QJsonObject | - | ||||||||||||||||||
84 | from which you got the reference. | - | ||||||||||||||||||
85 | - | |||||||||||||||||||
86 | The following methods return QJsonValueRef: | - | ||||||||||||||||||
87 | \list | - | ||||||||||||||||||
88 | \li \l {QJsonArray}::operator[](int i) | - | ||||||||||||||||||
89 | \li \l {QJsonObject}::operator[](const QString & key) const | - | ||||||||||||||||||
90 | \endlist | - | ||||||||||||||||||
91 | - | |||||||||||||||||||
92 | \sa {JSON Support in Qt}, {JSON Save Game Example} | - | ||||||||||||||||||
93 | */ | - | ||||||||||||||||||
94 | - | |||||||||||||||||||
95 | /*! | - | ||||||||||||||||||
96 | Creates a QJsonValue of type \a type. | - | ||||||||||||||||||
97 | - | |||||||||||||||||||
98 | The default is to create a Null value. | - | ||||||||||||||||||
99 | */ | - | ||||||||||||||||||
100 | QJsonValue::QJsonValue(Type type) | - | ||||||||||||||||||
101 | : ui(0), d(0), t(type) | - | ||||||||||||||||||
102 | { | - | ||||||||||||||||||
103 | } executed 323 times by 7 tests: end of block Executed by:
| 323 | ||||||||||||||||||
104 | - | |||||||||||||||||||
105 | /*! | - | ||||||||||||||||||
106 | \internal | - | ||||||||||||||||||
107 | */ | - | ||||||||||||||||||
108 | QJsonValue::QJsonValue(QJsonPrivate::Data *data, QJsonPrivate::Base *base, const QJsonPrivate::Value &v) | - | ||||||||||||||||||
109 | : d(0) | - | ||||||||||||||||||
110 | { | - | ||||||||||||||||||
111 | t = (Type)(uint)v.type; | - | ||||||||||||||||||
112 | switch (t) { | - | ||||||||||||||||||
113 | case Undefined: never executed: case Undefined: | 0 | ||||||||||||||||||
114 | case Null: executed 1 time by 1 test: case Null: Executed by:
| 1 | ||||||||||||||||||
115 | dbl = 0; | - | ||||||||||||||||||
116 | break; executed 1 time by 1 test: break; Executed by:
| 1 | ||||||||||||||||||
117 | case Bool: executed 655 times by 111 tests: case Bool: Executed by:
| 655 | ||||||||||||||||||
118 | b = v.toBoolean(); | - | ||||||||||||||||||
119 | break; executed 655 times by 111 tests: break; Executed by:
| 655 | ||||||||||||||||||
120 | case Double: executed 1577 times by 113 tests: case Double: Executed by:
| 1577 | ||||||||||||||||||
121 | dbl = v.toDouble(base); | - | ||||||||||||||||||
122 | break; executed 1577 times by 113 tests: break; Executed by:
| 1577 | ||||||||||||||||||
123 | case String: { executed 69681 times by 114 tests: case String: Executed by:
| 69681 | ||||||||||||||||||
124 | QString s = v.toString(base); | - | ||||||||||||||||||
125 | stringData = s.data_ptr(); | - | ||||||||||||||||||
126 | stringData->ref.ref(); | - | ||||||||||||||||||
127 | break; executed 69681 times by 114 tests: break; Executed by:
| 69681 | ||||||||||||||||||
128 | } | - | ||||||||||||||||||
129 | case Array: executed 41984 times by 113 tests: case Array: Executed by:
| 41984 | ||||||||||||||||||
130 | case Object: executed 42053 times by 114 tests: case Object: Executed by:
| 42053 | ||||||||||||||||||
131 | d = data; | - | ||||||||||||||||||
132 | this->base = v.base(base); | - | ||||||||||||||||||
133 | break; executed 84037 times by 114 tests: break; Executed by:
| 84037 | ||||||||||||||||||
134 | } | - | ||||||||||||||||||
135 | if (d)
| 71914-84037 | ||||||||||||||||||
136 | d->ref.ref(); executed 84037 times by 114 tests: d->ref.ref(); Executed by:
| 84037 | ||||||||||||||||||
137 | } executed 155951 times by 116 tests: end of block Executed by:
| 155951 | ||||||||||||||||||
138 | - | |||||||||||||||||||
139 | /*! | - | ||||||||||||||||||
140 | Creates a value of type Bool, with value \a b. | - | ||||||||||||||||||
141 | */ | - | ||||||||||||||||||
142 | QJsonValue::QJsonValue(bool b) | - | ||||||||||||||||||
143 | : d(0), t(Bool) | - | ||||||||||||||||||
144 | { | - | ||||||||||||||||||
145 | this->b = b; | - | ||||||||||||||||||
146 | } executed 7 times by 2 tests: end of block Executed by:
| 7 | ||||||||||||||||||
147 | - | |||||||||||||||||||
148 | /*! | - | ||||||||||||||||||
149 | Creates a value of type Double, with value \a n. | - | ||||||||||||||||||
150 | */ | - | ||||||||||||||||||
151 | QJsonValue::QJsonValue(double n) | - | ||||||||||||||||||
152 | : d(0), t(Double) | - | ||||||||||||||||||
153 | { | - | ||||||||||||||||||
154 | this->dbl = n; | - | ||||||||||||||||||
155 | } executed 8 times by 2 tests: end of block Executed by:
| 8 | ||||||||||||||||||
156 | - | |||||||||||||||||||
157 | /*! | - | ||||||||||||||||||
158 | \overload | - | ||||||||||||||||||
159 | Creates a value of type Double, with value \a n. | - | ||||||||||||||||||
160 | */ | - | ||||||||||||||||||
161 | QJsonValue::QJsonValue(int n) | - | ||||||||||||||||||
162 | : d(0), t(Double) | - | ||||||||||||||||||
163 | { | - | ||||||||||||||||||
164 | this->dbl = n; | - | ||||||||||||||||||
165 | } executed 5 times by 1 test: end of block Executed by:
| 5 | ||||||||||||||||||
166 | - | |||||||||||||||||||
167 | /*! | - | ||||||||||||||||||
168 | \overload | - | ||||||||||||||||||
169 | Creates a value of type Double, with value \a n. | - | ||||||||||||||||||
170 | NOTE: the integer limits for IEEE 754 double precision data is 2^53 (-9007199254740992 to +9007199254740992). | - | ||||||||||||||||||
171 | If you pass in values outside this range expect a loss of precision to occur. | - | ||||||||||||||||||
172 | */ | - | ||||||||||||||||||
173 | QJsonValue::QJsonValue(qint64 n) | - | ||||||||||||||||||
174 | : d(0), t(Double) | - | ||||||||||||||||||
175 | { | - | ||||||||||||||||||
176 | this->dbl = double(n); | - | ||||||||||||||||||
177 | } never executed: end of block | 0 | ||||||||||||||||||
178 | - | |||||||||||||||||||
179 | /*! | - | ||||||||||||||||||
180 | Creates a value of type String, with value \a s. | - | ||||||||||||||||||
181 | */ | - | ||||||||||||||||||
182 | QJsonValue::QJsonValue(const QString &s) | - | ||||||||||||||||||
183 | : d(0), t(String) | - | ||||||||||||||||||
184 | { | - | ||||||||||||||||||
185 | stringDataFromQStringHelper(s); | - | ||||||||||||||||||
186 | } executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||||||||
187 | - | |||||||||||||||||||
188 | /*! | - | ||||||||||||||||||
189 | \fn QJsonValue::QJsonValue(const char *s) | - | ||||||||||||||||||
190 | - | |||||||||||||||||||
191 | Creates a value of type String with value \a s, assuming | - | ||||||||||||||||||
192 | UTF-8 encoding of the input. | - | ||||||||||||||||||
193 | - | |||||||||||||||||||
194 | You can disable this constructor by defining \c | - | ||||||||||||||||||
195 | QT_NO_CAST_FROM_ASCII when you compile your applications. | - | ||||||||||||||||||
196 | - | |||||||||||||||||||
197 | \since 5.3 | - | ||||||||||||||||||
198 | */ | - | ||||||||||||||||||
199 | - | |||||||||||||||||||
200 | void QJsonValue::stringDataFromQStringHelper(const QString &string) | - | ||||||||||||||||||
201 | { | - | ||||||||||||||||||
202 | stringData = *(QStringData **)(&string); | - | ||||||||||||||||||
203 | stringData->ref.ref(); | - | ||||||||||||||||||
204 | } executed 33 times by 3 tests: end of block Executed by:
| 33 | ||||||||||||||||||
205 | - | |||||||||||||||||||
206 | /*! | - | ||||||||||||||||||
207 | Creates a value of type String, with value \a s. | - | ||||||||||||||||||
208 | */ | - | ||||||||||||||||||
209 | QJsonValue::QJsonValue(QLatin1String s) | - | ||||||||||||||||||
210 | : d(0), t(String) | - | ||||||||||||||||||
211 | { | - | ||||||||||||||||||
212 | // ### FIXME: Avoid creating the temp QString below | - | ||||||||||||||||||
213 | QString str(s); | - | ||||||||||||||||||
214 | stringDataFromQStringHelper(str); | - | ||||||||||||||||||
215 | } executed 30 times by 2 tests: end of block Executed by:
| 30 | ||||||||||||||||||
216 | - | |||||||||||||||||||
217 | /*! | - | ||||||||||||||||||
218 | Creates a value of type Array, with value \a a. | - | ||||||||||||||||||
219 | */ | - | ||||||||||||||||||
220 | QJsonValue::QJsonValue(const QJsonArray &a) | - | ||||||||||||||||||
221 | : d(a.d), t(Array) | - | ||||||||||||||||||
222 | { | - | ||||||||||||||||||
223 | base = a.a; | - | ||||||||||||||||||
224 | if (d)
| 0 | ||||||||||||||||||
225 | d->ref.ref(); never executed: d->ref.ref(); | 0 | ||||||||||||||||||
226 | } never executed: end of block | 0 | ||||||||||||||||||
227 | - | |||||||||||||||||||
228 | /*! | - | ||||||||||||||||||
229 | Creates a value of type Object, with value \a o. | - | ||||||||||||||||||
230 | */ | - | ||||||||||||||||||
231 | QJsonValue::QJsonValue(const QJsonObject &o) | - | ||||||||||||||||||
232 | : d(o.d), t(Object) | - | ||||||||||||||||||
233 | { | - | ||||||||||||||||||
234 | base = o.o; | - | ||||||||||||||||||
235 | if (d)
| 0 | ||||||||||||||||||
236 | d->ref.ref(); never executed: d->ref.ref(); | 0 | ||||||||||||||||||
237 | } never executed: end of block | 0 | ||||||||||||||||||
238 | - | |||||||||||||||||||
239 | - | |||||||||||||||||||
240 | /*! | - | ||||||||||||||||||
241 | Destroys the value. | - | ||||||||||||||||||
242 | */ | - | ||||||||||||||||||
243 | QJsonValue::~QJsonValue() | - | ||||||||||||||||||
244 | { | - | ||||||||||||||||||
245 | if (t == String && stringData && !stringData->ref.deref())
| 0-86752 | ||||||||||||||||||
246 | free(stringData); executed 1901 times by 40 tests: free(stringData); Executed by:
| 1901 | ||||||||||||||||||
247 | - | |||||||||||||||||||
248 | if (d && !d->ref.deref())
| 0-84142 | ||||||||||||||||||
249 | delete d; never executed: delete d; | 0 | ||||||||||||||||||
250 | } executed 156483 times by 118 tests: end of block Executed by:
| 156483 | ||||||||||||||||||
251 | - | |||||||||||||||||||
252 | /*! | - | ||||||||||||||||||
253 | Creates a copy of \a other. | - | ||||||||||||||||||
254 | */ | - | ||||||||||||||||||
255 | QJsonValue::QJsonValue(const QJsonValue &other) | - | ||||||||||||||||||
256 | { | - | ||||||||||||||||||
257 | t = other.t; | - | ||||||||||||||||||
258 | d = other.d; | - | ||||||||||||||||||
259 | ui = other.ui; | - | ||||||||||||||||||
260 | if (d)
| 51-105 | ||||||||||||||||||
261 | d->ref.ref(); executed 105 times by 1 test: d->ref.ref(); Executed by:
| 105 | ||||||||||||||||||
262 | - | |||||||||||||||||||
263 | if (t == String && stringData)
| 0-139 | ||||||||||||||||||
264 | stringData->ref.ref(); executed 17 times by 3 tests: stringData->ref.ref(); Executed by:
| 17 | ||||||||||||||||||
265 | } executed 156 times by 3 tests: end of block Executed by:
| 156 | ||||||||||||||||||
266 | - | |||||||||||||||||||
267 | /*! | - | ||||||||||||||||||
268 | Assigns the value stored in \a other to this object. | - | ||||||||||||||||||
269 | */ | - | ||||||||||||||||||
270 | QJsonValue &QJsonValue::operator =(const QJsonValue &other) | - | ||||||||||||||||||
271 | { | - | ||||||||||||||||||
272 | QJsonValue copy(other); | - | ||||||||||||||||||
273 | // swap(copy); | - | ||||||||||||||||||
274 | qSwap(dbl, copy.dbl); | - | ||||||||||||||||||
275 | qSwap(d, copy.d); | - | ||||||||||||||||||
276 | qSwap(t, copy.t); | - | ||||||||||||||||||
277 | return *this; executed 1 time by 1 test: return *this; Executed by:
| 1 | ||||||||||||||||||
278 | } | - | ||||||||||||||||||
279 | - | |||||||||||||||||||
280 | /*! | - | ||||||||||||||||||
281 | \fn bool QJsonValue::isNull() const | - | ||||||||||||||||||
282 | - | |||||||||||||||||||
283 | Returns \c true if the value is null. | - | ||||||||||||||||||
284 | */ | - | ||||||||||||||||||
285 | - | |||||||||||||||||||
286 | /*! | - | ||||||||||||||||||
287 | \fn bool QJsonValue::isBool() const | - | ||||||||||||||||||
288 | - | |||||||||||||||||||
289 | Returns \c true if the value contains a boolean. | - | ||||||||||||||||||
290 | - | |||||||||||||||||||
291 | \sa toBool() | - | ||||||||||||||||||
292 | */ | - | ||||||||||||||||||
293 | - | |||||||||||||||||||
294 | /*! | - | ||||||||||||||||||
295 | \fn bool QJsonValue::isDouble() const | - | ||||||||||||||||||
296 | - | |||||||||||||||||||
297 | Returns \c true if the value contains a double. | - | ||||||||||||||||||
298 | - | |||||||||||||||||||
299 | \sa toDouble() | - | ||||||||||||||||||
300 | */ | - | ||||||||||||||||||
301 | - | |||||||||||||||||||
302 | /*! | - | ||||||||||||||||||
303 | \fn bool QJsonValue::isString() const | - | ||||||||||||||||||
304 | - | |||||||||||||||||||
305 | Returns \c true if the value contains a string. | - | ||||||||||||||||||
306 | - | |||||||||||||||||||
307 | \sa toString() | - | ||||||||||||||||||
308 | */ | - | ||||||||||||||||||
309 | - | |||||||||||||||||||
310 | /*! | - | ||||||||||||||||||
311 | \fn bool QJsonValue::isArray() const | - | ||||||||||||||||||
312 | - | |||||||||||||||||||
313 | Returns \c true if the value contains an array. | - | ||||||||||||||||||
314 | - | |||||||||||||||||||
315 | \sa toArray() | - | ||||||||||||||||||
316 | */ | - | ||||||||||||||||||
317 | - | |||||||||||||||||||
318 | /*! | - | ||||||||||||||||||
319 | \fn bool QJsonValue::isObject() const | - | ||||||||||||||||||
320 | - | |||||||||||||||||||
321 | Returns \c true if the value contains an object. | - | ||||||||||||||||||
322 | - | |||||||||||||||||||
323 | \sa toObject() | - | ||||||||||||||||||
324 | */ | - | ||||||||||||||||||
325 | - | |||||||||||||||||||
326 | /*! | - | ||||||||||||||||||
327 | \fn bool QJsonValue::isUndefined() const | - | ||||||||||||||||||
328 | - | |||||||||||||||||||
329 | Returns \c true if the value is undefined. This can happen in certain | - | ||||||||||||||||||
330 | error cases as e.g. accessing a non existing key in a QJsonObject. | - | ||||||||||||||||||
331 | */ | - | ||||||||||||||||||
332 | - | |||||||||||||||||||
333 | - | |||||||||||||||||||
334 | /*! | - | ||||||||||||||||||
335 | Converts \a variant to a QJsonValue and returns it. | - | ||||||||||||||||||
336 | - | |||||||||||||||||||
337 | The conversion will convert QVariant types as follows: | - | ||||||||||||||||||
338 | - | |||||||||||||||||||
339 | \table | - | ||||||||||||||||||
340 | \header | - | ||||||||||||||||||
341 | \li Source type | - | ||||||||||||||||||
342 | \li Destination type | - | ||||||||||||||||||
343 | \row | - | ||||||||||||||||||
344 | \li | - | ||||||||||||||||||
345 | \list | - | ||||||||||||||||||
346 | \li QMetaType::Bool | - | ||||||||||||||||||
347 | \endlist | - | ||||||||||||||||||
348 | \li QJsonValue::Bool | - | ||||||||||||||||||
349 | \row | - | ||||||||||||||||||
350 | \li | - | ||||||||||||||||||
351 | \list | - | ||||||||||||||||||
352 | \li QMetaType::Int | - | ||||||||||||||||||
353 | \li QMetaType::UInt | - | ||||||||||||||||||
354 | \li QMetaType::LongLong | - | ||||||||||||||||||
355 | \li QMetaType::ULongLong | - | ||||||||||||||||||
356 | \li QMetaType::Float | - | ||||||||||||||||||
357 | \li QMetaType::Double | - | ||||||||||||||||||
358 | \endlist | - | ||||||||||||||||||
359 | \li QJsonValue::Double | - | ||||||||||||||||||
360 | \row | - | ||||||||||||||||||
361 | \li | - | ||||||||||||||||||
362 | \list | - | ||||||||||||||||||
363 | \li QMetaType::QString | - | ||||||||||||||||||
364 | \endlist | - | ||||||||||||||||||
365 | \li QJsonValue::String | - | ||||||||||||||||||
366 | \row | - | ||||||||||||||||||
367 | \li | - | ||||||||||||||||||
368 | \list | - | ||||||||||||||||||
369 | \li QMetaType::QStringList | - | ||||||||||||||||||
370 | \li QMetaType::QVariantList | - | ||||||||||||||||||
371 | \endlist | - | ||||||||||||||||||
372 | \li QJsonValue::Array | - | ||||||||||||||||||
373 | \row | - | ||||||||||||||||||
374 | \li | - | ||||||||||||||||||
375 | \list | - | ||||||||||||||||||
376 | \li QMetaType::QVariantMap | - | ||||||||||||||||||
377 | \li QMetaType::QVariantHash | - | ||||||||||||||||||
378 | \endlist | - | ||||||||||||||||||
379 | \li QJsonValue::Object | - | ||||||||||||||||||
380 | \endtable | - | ||||||||||||||||||
381 | - | |||||||||||||||||||
382 | For all other QVariant types a conversion to a QString will be attempted. If the returned string | - | ||||||||||||||||||
383 | is empty, a Null QJsonValue will be stored, otherwise a String value using the returned QString. | - | ||||||||||||||||||
384 | - | |||||||||||||||||||
385 | \sa toVariant() | - | ||||||||||||||||||
386 | */ | - | ||||||||||||||||||
387 | QJsonValue QJsonValue::fromVariant(const QVariant &variant) | - | ||||||||||||||||||
388 | { | - | ||||||||||||||||||
389 | switch (variant.userType()) { | - | ||||||||||||||||||
390 | case QVariant::Bool: never executed: case QVariant::Bool: | 0 | ||||||||||||||||||
391 | return QJsonValue(variant.toBool()); never executed: return QJsonValue(variant.toBool()); | 0 | ||||||||||||||||||
392 | case QVariant::Int: never executed: case QVariant::Int: | 0 | ||||||||||||||||||
393 | case QMetaType::Float: never executed: case QMetaType::Float: | 0 | ||||||||||||||||||
394 | case QVariant::Double: never executed: case QVariant::Double: | 0 | ||||||||||||||||||
395 | case QVariant::LongLong: never executed: case QVariant::LongLong: | 0 | ||||||||||||||||||
396 | case QVariant::ULongLong: never executed: case QVariant::ULongLong: | 0 | ||||||||||||||||||
397 | case QVariant::UInt: never executed: case QVariant::UInt: | 0 | ||||||||||||||||||
398 | return QJsonValue(variant.toDouble()); never executed: return QJsonValue(variant.toDouble()); | 0 | ||||||||||||||||||
399 | case QVariant::String: never executed: case QVariant::String: | 0 | ||||||||||||||||||
400 | return QJsonValue(variant.toString()); never executed: return QJsonValue(variant.toString()); | 0 | ||||||||||||||||||
401 | case QVariant::StringList: never executed: case QVariant::StringList: | 0 | ||||||||||||||||||
402 | return QJsonValue(QJsonArray::fromStringList(variant.toStringList())); never executed: return QJsonValue(QJsonArray::fromStringList(variant.toStringList())); | 0 | ||||||||||||||||||
403 | case QVariant::List: never executed: case QVariant::List: | 0 | ||||||||||||||||||
404 | return QJsonValue(QJsonArray::fromVariantList(variant.toList())); never executed: return QJsonValue(QJsonArray::fromVariantList(variant.toList())); | 0 | ||||||||||||||||||
405 | case QVariant::Map: never executed: case QVariant::Map: | 0 | ||||||||||||||||||
406 | return QJsonValue(QJsonObject::fromVariantMap(variant.toMap())); never executed: return QJsonValue(QJsonObject::fromVariantMap(variant.toMap())); | 0 | ||||||||||||||||||
407 | case QVariant::Hash: never executed: case QVariant::Hash: | 0 | ||||||||||||||||||
408 | return QJsonValue(QJsonObject::fromVariantHash(variant.toHash())); never executed: return QJsonValue(QJsonObject::fromVariantHash(variant.toHash())); | 0 | ||||||||||||||||||
409 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||||||||
410 | case QMetaType::QJsonValue: never executed: case QMetaType::QJsonValue: | 0 | ||||||||||||||||||
411 | return variant.toJsonValue(); never executed: return variant.toJsonValue(); | 0 | ||||||||||||||||||
412 | case QMetaType::QJsonObject: never executed: case QMetaType::QJsonObject: | 0 | ||||||||||||||||||
413 | return variant.toJsonObject(); never executed: return variant.toJsonObject(); | 0 | ||||||||||||||||||
414 | case QMetaType::QJsonArray: never executed: case QMetaType::QJsonArray: | 0 | ||||||||||||||||||
415 | return variant.toJsonArray(); never executed: return variant.toJsonArray(); | 0 | ||||||||||||||||||
416 | case QMetaType::QJsonDocument: { never executed: case QMetaType::QJsonDocument: | 0 | ||||||||||||||||||
417 | QJsonDocument doc = variant.toJsonDocument(); | - | ||||||||||||||||||
418 | return doc.isArray() ? QJsonValue(doc.array()) : QJsonValue(doc.object()); never executed: return doc.isArray() ? QJsonValue(doc.array()) : QJsonValue(doc.object());
| 0 | ||||||||||||||||||
419 | } | - | ||||||||||||||||||
420 | #endif | - | ||||||||||||||||||
421 | default: never executed: default: | 0 | ||||||||||||||||||
422 | break; never executed: break; | 0 | ||||||||||||||||||
423 | } | - | ||||||||||||||||||
424 | QString string = variant.toString(); | - | ||||||||||||||||||
425 | if (string.isEmpty())
| 0 | ||||||||||||||||||
426 | return QJsonValue(); never executed: return QJsonValue(); | 0 | ||||||||||||||||||
427 | return QJsonValue(string); never executed: return QJsonValue(string); | 0 | ||||||||||||||||||
428 | } | - | ||||||||||||||||||
429 | - | |||||||||||||||||||
430 | /*! | - | ||||||||||||||||||
431 | Converts the value to a \l {QVariant::}{QVariant()}. | - | ||||||||||||||||||
432 | - | |||||||||||||||||||
433 | The QJsonValue types will be converted as follows: | - | ||||||||||||||||||
434 | - | |||||||||||||||||||
435 | \value Null \l {QVariant::}{QVariant()} | - | ||||||||||||||||||
436 | \value Bool QMetaType::Bool | - | ||||||||||||||||||
437 | \value Double QMetaType::Double | - | ||||||||||||||||||
438 | \value String QString | - | ||||||||||||||||||
439 | \value Array QVariantList | - | ||||||||||||||||||
440 | \value Object QVariantMap | - | ||||||||||||||||||
441 | \value Undefined \l {QVariant::}{QVariant()} | - | ||||||||||||||||||
442 | - | |||||||||||||||||||
443 | \sa fromVariant() | - | ||||||||||||||||||
444 | */ | - | ||||||||||||||||||
445 | QVariant QJsonValue::toVariant() const | - | ||||||||||||||||||
446 | { | - | ||||||||||||||||||
447 | switch (t) { | - | ||||||||||||||||||
448 | case Bool: never executed: case Bool: | 0 | ||||||||||||||||||
449 | return b; never executed: return b; | 0 | ||||||||||||||||||
450 | case Double: never executed: case Double: | 0 | ||||||||||||||||||
451 | return dbl; never executed: return dbl; | 0 | ||||||||||||||||||
452 | case String: never executed: case String: | 0 | ||||||||||||||||||
453 | return toString(); never executed: return toString(); | 0 | ||||||||||||||||||
454 | case Array: never executed: case Array: | 0 | ||||||||||||||||||
455 | return d ? never executed: return d ? QJsonArray(d, static_cast<QJsonPrivate::Array *>(base)).toVariantList() : QVariantList();
| 0 | ||||||||||||||||||
456 | QJsonArray(d, static_cast<QJsonPrivate::Array *>(base)).toVariantList() : never executed: return d ? QJsonArray(d, static_cast<QJsonPrivate::Array *>(base)).toVariantList() : QVariantList(); | 0 | ||||||||||||||||||
457 | QVariantList(); never executed: return d ? QJsonArray(d, static_cast<QJsonPrivate::Array *>(base)).toVariantList() : QVariantList(); | 0 | ||||||||||||||||||
458 | case Object: never executed: case Object: | 0 | ||||||||||||||||||
459 | return d ? never executed: return d ? QJsonObject(d, static_cast<QJsonPrivate::Object *>(base)).toVariantMap() : QVariantMap();
| 0 | ||||||||||||||||||
460 | QJsonObject(d, static_cast<QJsonPrivate::Object *>(base)).toVariantMap() : never executed: return d ? QJsonObject(d, static_cast<QJsonPrivate::Object *>(base)).toVariantMap() : QVariantMap(); | 0 | ||||||||||||||||||
461 | QVariantMap(); never executed: return d ? QJsonObject(d, static_cast<QJsonPrivate::Object *>(base)).toVariantMap() : QVariantMap(); | 0 | ||||||||||||||||||
462 | case Null: never executed: case Null: | 0 | ||||||||||||||||||
463 | case Undefined: never executed: case Undefined: | 0 | ||||||||||||||||||
464 | break; never executed: break; | 0 | ||||||||||||||||||
465 | } | - | ||||||||||||||||||
466 | return QVariant(); never executed: return QVariant(); | 0 | ||||||||||||||||||
467 | } | - | ||||||||||||||||||
468 | - | |||||||||||||||||||
469 | /*! | - | ||||||||||||||||||
470 | \enum QJsonValue::Type | - | ||||||||||||||||||
471 | - | |||||||||||||||||||
472 | This enum describes the type of the JSON value. | - | ||||||||||||||||||
473 | - | |||||||||||||||||||
474 | \value Null A Null value | - | ||||||||||||||||||
475 | \value Bool A boolean value. Use toBool() to convert to a bool. | - | ||||||||||||||||||
476 | \value Double A double. Use toDouble() to convert to a double. | - | ||||||||||||||||||
477 | \value String A string. Use toString() to convert to a QString. | - | ||||||||||||||||||
478 | \value Array An array. Use toArray() to convert to a QJsonArray. | - | ||||||||||||||||||
479 | \value Object An object. Use toObject() to convert to a QJsonObject. | - | ||||||||||||||||||
480 | \value Undefined The value is undefined. This is usually returned as an | - | ||||||||||||||||||
481 | error condition, when trying to read an out of bounds value | - | ||||||||||||||||||
482 | in an array or a non existent key in an object. | - | ||||||||||||||||||
483 | */ | - | ||||||||||||||||||
484 | - | |||||||||||||||||||
485 | /*! | - | ||||||||||||||||||
486 | Returns the type of the value. | - | ||||||||||||||||||
487 | - | |||||||||||||||||||
488 | \sa QJsonValue::Type | - | ||||||||||||||||||
489 | */ | - | ||||||||||||||||||
490 | QJsonValue::Type QJsonValue::type() const | - | ||||||||||||||||||
491 | { | - | ||||||||||||||||||
492 | return t; executed 272 times by 3 tests: return t; Executed by:
| 272 | ||||||||||||||||||
493 | } | - | ||||||||||||||||||
494 | - | |||||||||||||||||||
495 | /*! | - | ||||||||||||||||||
496 | Converts the value to a bool and returns it. | - | ||||||||||||||||||
497 | - | |||||||||||||||||||
498 | If type() is not bool, the \a defaultValue will be returned. | - | ||||||||||||||||||
499 | */ | - | ||||||||||||||||||
500 | bool QJsonValue::toBool(bool defaultValue) const | - | ||||||||||||||||||
501 | { | - | ||||||||||||||||||
502 | if (t != Bool)
| 0-657 | ||||||||||||||||||
503 | return defaultValue; never executed: return defaultValue; | 0 | ||||||||||||||||||
504 | return b; executed 657 times by 112 tests: return b; Executed by:
| 657 | ||||||||||||||||||
505 | } | - | ||||||||||||||||||
506 | - | |||||||||||||||||||
507 | /*! | - | ||||||||||||||||||
508 | Converts the value to an int and returns it. | - | ||||||||||||||||||
509 | - | |||||||||||||||||||
510 | If type() is not Double or the value is not a whole number, | - | ||||||||||||||||||
511 | the \a defaultValue will be returned. | - | ||||||||||||||||||
512 | */ | - | ||||||||||||||||||
513 | int QJsonValue::toInt(int defaultValue) const | - | ||||||||||||||||||
514 | { | - | ||||||||||||||||||
515 | if (t == Double && int(dbl) == dbl)
| 0 | ||||||||||||||||||
516 | return int(dbl); never executed: return int(dbl); | 0 | ||||||||||||||||||
517 | return defaultValue; never executed: return defaultValue; | 0 | ||||||||||||||||||
518 | } | - | ||||||||||||||||||
519 | - | |||||||||||||||||||
520 | /*! | - | ||||||||||||||||||
521 | Converts the value to a double and returns it. | - | ||||||||||||||||||
522 | - | |||||||||||||||||||
523 | If type() is not Double, the \a defaultValue will be returned. | - | ||||||||||||||||||
524 | */ | - | ||||||||||||||||||
525 | double QJsonValue::toDouble(double defaultValue) const | - | ||||||||||||||||||
526 | { | - | ||||||||||||||||||
527 | if (t != Double)
| 2-1583 | ||||||||||||||||||
528 | return defaultValue; executed 2 times by 1 test: return defaultValue; Executed by:
| 2 | ||||||||||||||||||
529 | return dbl; executed 1583 times by 114 tests: return dbl; Executed by:
| 1583 | ||||||||||||||||||
530 | } | - | ||||||||||||||||||
531 | - | |||||||||||||||||||
532 | /*! | - | ||||||||||||||||||
533 | Converts the value to a QString and returns it. | - | ||||||||||||||||||
534 | - | |||||||||||||||||||
535 | If type() is not String, the \a defaultValue will be returned. | - | ||||||||||||||||||
536 | */ | - | ||||||||||||||||||
537 | QString QJsonValue::toString(const QString &defaultValue) const | - | ||||||||||||||||||
538 | { | - | ||||||||||||||||||
539 | if (t != String)
| 157-69716 | ||||||||||||||||||
540 | return defaultValue; executed 157 times by 3 tests: return defaultValue; Executed by:
| 157 | ||||||||||||||||||
541 | stringData->ref.ref(); // the constructor below doesn't add a ref. | - | ||||||||||||||||||
542 | QStringDataPtr holder = { stringData }; | - | ||||||||||||||||||
543 | return QString(holder); executed 69716 times by 116 tests: return QString(holder); Executed by:
| 69716 | ||||||||||||||||||
544 | } | - | ||||||||||||||||||
545 | - | |||||||||||||||||||
546 | /*! | - | ||||||||||||||||||
547 | Converts the value to an array and returns it. | - | ||||||||||||||||||
548 | - | |||||||||||||||||||
549 | If type() is not Array, the \a defaultValue will be returned. | - | ||||||||||||||||||
550 | */ | - | ||||||||||||||||||
551 | QJsonArray QJsonValue::toArray(const QJsonArray &defaultValue) const | - | ||||||||||||||||||
552 | { | - | ||||||||||||||||||
553 | if (!d || t != Array)
| 0-41984 | ||||||||||||||||||
554 | return defaultValue; executed 42 times by 2 tests: return defaultValue; Executed by:
| 42 | ||||||||||||||||||
555 | - | |||||||||||||||||||
556 | return QJsonArray(d, static_cast<QJsonPrivate::Array *>(base)); executed 41984 times by 113 tests: return QJsonArray(d, static_cast<QJsonPrivate::Array *>(base)); Executed by:
| 41984 | ||||||||||||||||||
557 | } | - | ||||||||||||||||||
558 | - | |||||||||||||||||||
559 | /*! | - | ||||||||||||||||||
560 | \overload | - | ||||||||||||||||||
561 | - | |||||||||||||||||||
562 | Converts the value to an array and returns it. | - | ||||||||||||||||||
563 | - | |||||||||||||||||||
564 | If type() is not Array, a \l{QJsonArray::}{QJsonArray()} will be returned. | - | ||||||||||||||||||
565 | */ | - | ||||||||||||||||||
566 | QJsonArray QJsonValue::toArray() const | - | ||||||||||||||||||
567 | { | - | ||||||||||||||||||
568 | return toArray(QJsonArray()); executed 42026 times by 114 tests: return toArray(QJsonArray()); Executed by:
| 42026 | ||||||||||||||||||
569 | } | - | ||||||||||||||||||
570 | - | |||||||||||||||||||
571 | /*! | - | ||||||||||||||||||
572 | Converts the value to an object and returns it. | - | ||||||||||||||||||
573 | - | |||||||||||||||||||
574 | If type() is not Object, the \a defaultValue will be returned. | - | ||||||||||||||||||
575 | */ | - | ||||||||||||||||||
576 | QJsonObject QJsonValue::toObject(const QJsonObject &defaultValue) const | - | ||||||||||||||||||
577 | { | - | ||||||||||||||||||
578 | if (!d || t != Object)
| 0-42003 | ||||||||||||||||||
579 | return defaultValue; never executed: return defaultValue; | 0 | ||||||||||||||||||
580 | - | |||||||||||||||||||
581 | return QJsonObject(d, static_cast<QJsonPrivate::Object *>(base)); executed 42003 times by 114 tests: return QJsonObject(d, static_cast<QJsonPrivate::Object *>(base)); Executed by:
| 42003 | ||||||||||||||||||
582 | } | - | ||||||||||||||||||
583 | - | |||||||||||||||||||
584 | /*! | - | ||||||||||||||||||
585 | \overload | - | ||||||||||||||||||
586 | - | |||||||||||||||||||
587 | Converts the value to an object and returns it. | - | ||||||||||||||||||
588 | - | |||||||||||||||||||
589 | If type() is not Object, the \l {QJsonObject::}{QJsonObject()} will be returned. | - | ||||||||||||||||||
590 | */ | - | ||||||||||||||||||
591 | QJsonObject QJsonValue::toObject() const | - | ||||||||||||||||||
592 | { | - | ||||||||||||||||||
593 | return toObject(QJsonObject()); executed 42003 times by 114 tests: return toObject(QJsonObject()); Executed by:
| 42003 | ||||||||||||||||||
594 | } | - | ||||||||||||||||||
595 | - | |||||||||||||||||||
596 | /*! | - | ||||||||||||||||||
597 | Returns \c true if the value is equal to \a other. | - | ||||||||||||||||||
598 | */ | - | ||||||||||||||||||
599 | bool QJsonValue::operator==(const QJsonValue &other) const | - | ||||||||||||||||||
600 | { | - | ||||||||||||||||||
601 | if (t != other.t)
| 0-34 | ||||||||||||||||||
602 | return false; never executed: return false; | 0 | ||||||||||||||||||
603 | - | |||||||||||||||||||
604 | switch (t) { | - | ||||||||||||||||||
605 | case Undefined: never executed: case Undefined: | 0 | ||||||||||||||||||
606 | case Null: executed 4 times by 1 test: case Null: Executed by:
| 4 | ||||||||||||||||||
607 | break; executed 4 times by 1 test: break; Executed by:
| 4 | ||||||||||||||||||
608 | case Bool: never executed: case Bool: | 0 | ||||||||||||||||||
609 | return b == other.b; never executed: return b == other.b; | 0 | ||||||||||||||||||
610 | case Double: executed 4 times by 1 test: case Double: Executed by:
| 4 | ||||||||||||||||||
611 | return dbl == other.dbl; executed 4 times by 1 test: return dbl == other.dbl; Executed by:
| 4 | ||||||||||||||||||
612 | case String: executed 26 times by 1 test: case String: Executed by:
| 26 | ||||||||||||||||||
613 | return toString() == other.toString(); executed 26 times by 1 test: return toString() == other.toString(); Executed by:
| 26 | ||||||||||||||||||
614 | case Array: never executed: case Array: | 0 | ||||||||||||||||||
615 | if (base == other.base)
| 0 | ||||||||||||||||||
616 | return true; never executed: return true; | 0 | ||||||||||||||||||
617 | if (!base)
| 0 | ||||||||||||||||||
618 | return !other.base->length; never executed: return !other.base->length; | 0 | ||||||||||||||||||
619 | if (!other.base)
| 0 | ||||||||||||||||||
620 | return !base->length; never executed: return !base->length; | 0 | ||||||||||||||||||
621 | return QJsonArray(d, static_cast<QJsonPrivate::Array *>(base)) never executed: return QJsonArray(d, static_cast<QJsonPrivate::Array *>(base)) == QJsonArray(other.d, static_cast<QJsonPrivate::Array *>(other.base)); | 0 | ||||||||||||||||||
622 | == QJsonArray(other.d, static_cast<QJsonPrivate::Array *>(other.base)); never executed: return QJsonArray(d, static_cast<QJsonPrivate::Array *>(base)) == QJsonArray(other.d, static_cast<QJsonPrivate::Array *>(other.base)); | 0 | ||||||||||||||||||
623 | case Object: never executed: case Object: | 0 | ||||||||||||||||||
624 | if (base == other.base)
| 0 | ||||||||||||||||||
625 | return true; never executed: return true; | 0 | ||||||||||||||||||
626 | if (!base)
| 0 | ||||||||||||||||||
627 | return !other.base->length; never executed: return !other.base->length; | 0 | ||||||||||||||||||
628 | if (!other.base)
| 0 | ||||||||||||||||||
629 | return !base->length; never executed: return !base->length; | 0 | ||||||||||||||||||
630 | return QJsonObject(d, static_cast<QJsonPrivate::Object *>(base)) never executed: return QJsonObject(d, static_cast<QJsonPrivate::Object *>(base)) == QJsonObject(other.d, static_cast<QJsonPrivate::Object *>(other.base)); | 0 | ||||||||||||||||||
631 | == QJsonObject(other.d, static_cast<QJsonPrivate::Object *>(other.base)); never executed: return QJsonObject(d, static_cast<QJsonPrivate::Object *>(base)) == QJsonObject(other.d, static_cast<QJsonPrivate::Object *>(other.base)); | 0 | ||||||||||||||||||
632 | } | - | ||||||||||||||||||
633 | return true; executed 4 times by 1 test: return true; Executed by:
| 4 | ||||||||||||||||||
634 | } | - | ||||||||||||||||||
635 | - | |||||||||||||||||||
636 | /*! | - | ||||||||||||||||||
637 | Returns \c true if the value is not equal to \a other. | - | ||||||||||||||||||
638 | */ | - | ||||||||||||||||||
639 | bool QJsonValue::operator!=(const QJsonValue &other) const | - | ||||||||||||||||||
640 | { | - | ||||||||||||||||||
641 | return !(*this == other); executed 26 times by 1 test: return !(*this == other); Executed by:
| 26 | ||||||||||||||||||
642 | } | - | ||||||||||||||||||
643 | - | |||||||||||||||||||
644 | /*! | - | ||||||||||||||||||
645 | \internal | - | ||||||||||||||||||
646 | */ | - | ||||||||||||||||||
647 | void QJsonValue::detach() | - | ||||||||||||||||||
648 | { | - | ||||||||||||||||||
649 | if (!d)
| 0 | ||||||||||||||||||
650 | return; never executed: return; | 0 | ||||||||||||||||||
651 | - | |||||||||||||||||||
652 | QJsonPrivate::Data *x = d->clone(base); | - | ||||||||||||||||||
653 | x->ref.ref(); | - | ||||||||||||||||||
654 | if (!d->ref.deref())
| 0 | ||||||||||||||||||
655 | delete d; never executed: delete d; | 0 | ||||||||||||||||||
656 | d = x; | - | ||||||||||||||||||
657 | base = static_cast<QJsonPrivate::Object *>(d->header->root()); | - | ||||||||||||||||||
658 | } never executed: end of block | 0 | ||||||||||||||||||
659 | - | |||||||||||||||||||
660 | - | |||||||||||||||||||
661 | /*! | - | ||||||||||||||||||
662 | \class QJsonValueRef | - | ||||||||||||||||||
663 | \inmodule QtCore | - | ||||||||||||||||||
664 | \reentrant | - | ||||||||||||||||||
665 | \brief The QJsonValueRef class is a helper class for QJsonValue. | - | ||||||||||||||||||
666 | - | |||||||||||||||||||
667 | \internal | - | ||||||||||||||||||
668 | - | |||||||||||||||||||
669 | \ingroup json | - | ||||||||||||||||||
670 | - | |||||||||||||||||||
671 | When you get an object of type QJsonValueRef, if you can assign to it, | - | ||||||||||||||||||
672 | the assignment will apply to the character in the string from | - | ||||||||||||||||||
673 | which you got the reference. That is its whole purpose in life. | - | ||||||||||||||||||
674 | - | |||||||||||||||||||
675 | You can use it exactly in the same way as a reference to a QJsonValue. | - | ||||||||||||||||||
676 | - | |||||||||||||||||||
677 | The QJsonValueRef becomes invalid once modifications are made to the | - | ||||||||||||||||||
678 | string: if you want to keep the character, copy it into a QJsonValue. | - | ||||||||||||||||||
679 | - | |||||||||||||||||||
680 | Most of the QJsonValue member functions also exist in QJsonValueRef. | - | ||||||||||||||||||
681 | However, they are not explicitly documented here. | - | ||||||||||||||||||
682 | */ | - | ||||||||||||||||||
683 | - | |||||||||||||||||||
684 | - | |||||||||||||||||||
685 | QJsonValueRef &QJsonValueRef::operator =(const QJsonValue &val) | - | ||||||||||||||||||
686 | { | - | ||||||||||||||||||
687 | if (is_object)
| 0 | ||||||||||||||||||
688 | o->setValueAt(index, val); never executed: o->setValueAt(index, val); | 0 | ||||||||||||||||||
689 | else | - | ||||||||||||||||||
690 | a->replace(index, val); never executed: a->replace(index, val); | 0 | ||||||||||||||||||
691 | - | |||||||||||||||||||
692 | return *this; never executed: return *this; | 0 | ||||||||||||||||||
693 | } | - | ||||||||||||||||||
694 | - | |||||||||||||||||||
695 | QJsonValueRef &QJsonValueRef::operator =(const QJsonValueRef &ref) | - | ||||||||||||||||||
696 | { | - | ||||||||||||||||||
697 | if (is_object)
| 0 | ||||||||||||||||||
698 | o->setValueAt(index, ref); never executed: o->setValueAt(index, ref); | 0 | ||||||||||||||||||
699 | else | - | ||||||||||||||||||
700 | a->replace(index, ref); never executed: a->replace(index, ref); | 0 | ||||||||||||||||||
701 | - | |||||||||||||||||||
702 | return *this; never executed: return *this; | 0 | ||||||||||||||||||
703 | } | - | ||||||||||||||||||
704 | - | |||||||||||||||||||
705 | QVariant QJsonValueRef::toVariant() const | - | ||||||||||||||||||
706 | { | - | ||||||||||||||||||
707 | return toValue().toVariant(); never executed: return toValue().toVariant(); | 0 | ||||||||||||||||||
708 | } | - | ||||||||||||||||||
709 | - | |||||||||||||||||||
710 | QJsonArray QJsonValueRef::toArray() const | - | ||||||||||||||||||
711 | { | - | ||||||||||||||||||
712 | return toValue().toArray(); never executed: return toValue().toArray(); | 0 | ||||||||||||||||||
713 | } | - | ||||||||||||||||||
714 | - | |||||||||||||||||||
715 | QJsonObject QJsonValueRef::toObject() const | - | ||||||||||||||||||
716 | { | - | ||||||||||||||||||
717 | return toValue().toObject(); never executed: return toValue().toObject(); | 0 | ||||||||||||||||||
718 | } | - | ||||||||||||||||||
719 | - | |||||||||||||||||||
720 | QJsonValue QJsonValueRef::toValue() const | - | ||||||||||||||||||
721 | { | - | ||||||||||||||||||
722 | if (!is_object)
| 0 | ||||||||||||||||||
723 | return a->at(index); never executed: return a->at(index); | 0 | ||||||||||||||||||
724 | return o->valueAt(index); never executed: return o->valueAt(index); | 0 | ||||||||||||||||||
725 | } | - | ||||||||||||||||||
726 | - | |||||||||||||||||||
727 | #if !defined(QT_NO_DEBUG_STREAM) && !defined(QT_JSON_READONLY) | - | ||||||||||||||||||
728 | QDebug operator<<(QDebug dbg, const QJsonValue &o) | - | ||||||||||||||||||
729 | { | - | ||||||||||||||||||
730 | QDebugStateSaver saver(dbg); | - | ||||||||||||||||||
731 | switch (o.t) { | - | ||||||||||||||||||
732 | case QJsonValue::Undefined: never executed: case QJsonValue::Undefined: | 0 | ||||||||||||||||||
733 | dbg << "QJsonValue(undefined)"; | - | ||||||||||||||||||
734 | break; never executed: break; | 0 | ||||||||||||||||||
735 | case QJsonValue::Null: executed 1 time by 1 test: case QJsonValue::Null: Executed by:
| 1 | ||||||||||||||||||
736 | dbg << "QJsonValue(null)"; | - | ||||||||||||||||||
737 | break; executed 1 time by 1 test: break; Executed by:
| 1 | ||||||||||||||||||
738 | case QJsonValue::Bool: never executed: case QJsonValue::Bool: | 0 | ||||||||||||||||||
739 | dbg.nospace() << "QJsonValue(bool, " << o.toBool() << ')'; | - | ||||||||||||||||||
740 | break; never executed: break; | 0 | ||||||||||||||||||
741 | case QJsonValue::Double: never executed: case QJsonValue::Double: | 0 | ||||||||||||||||||
742 | dbg.nospace() << "QJsonValue(double, " << o.toDouble() << ')'; | - | ||||||||||||||||||
743 | break; never executed: break; | 0 | ||||||||||||||||||
744 | case QJsonValue::String: never executed: case QJsonValue::String: | 0 | ||||||||||||||||||
745 | dbg.nospace() << "QJsonValue(string, " << o.toString() << ')'; | - | ||||||||||||||||||
746 | break; never executed: break; | 0 | ||||||||||||||||||
747 | case QJsonValue::Array: never executed: case QJsonValue::Array: | 0 | ||||||||||||||||||
748 | dbg.nospace() << "QJsonValue(array, "; | - | ||||||||||||||||||
749 | dbg << o.toArray(); | - | ||||||||||||||||||
750 | dbg << ')'; | - | ||||||||||||||||||
751 | break; never executed: break; | 0 | ||||||||||||||||||
752 | case QJsonValue::Object: never executed: case QJsonValue::Object: | 0 | ||||||||||||||||||
753 | dbg.nospace() << "QJsonValue(object, "; | - | ||||||||||||||||||
754 | dbg << o.toObject(); | - | ||||||||||||||||||
755 | dbg << ')'; | - | ||||||||||||||||||
756 | break; never executed: break; | 0 | ||||||||||||||||||
757 | } | - | ||||||||||||||||||
758 | return dbg; executed 1 time by 1 test: return dbg; Executed by:
| 1 | ||||||||||||||||||
759 | } | - | ||||||||||||||||||
760 | #endif | - | ||||||||||||||||||
761 | - | |||||||||||||||||||
762 | QT_END_NAMESPACE | - | ||||||||||||||||||
Source code | Switch to Preprocessed file |