qjsonobject.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/corelib/json/qjsonobject.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
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 <qstringlist.h>-
38#include <qdebug.h>-
39#include <qvariant.h>-
40#include "qjson_p.h"-
41#include "qjsonwriter_p.h"-
42-
43QT_BEGIN_NAMESPACE-
44-
45/*!-
46 \class QJsonObject-
47 \inmodule QtCore-
48 \ingroup json-
49 \ingroup shared-
50 \reentrant-
51 \since 5.0-
52-
53 \brief The QJsonObject class encapsulates a JSON object.-
54-
55 A JSON object is a list of key value pairs, where the keys are unique strings-
56 and the values are represented by a QJsonValue.-
57-
58 A QJsonObject can be converted to and from a QVariantMap. You can query the-
59 number of (key, value) pairs with size(), insert(), and remove() entries from it-
60 and iterate over its content using the standard C++ iterator pattern.-
61-
62 QJsonObject is an implicitly shared class, and shares the data with the document-
63 it has been created from as long as it is not being modified.-
64-
65 You can convert the object to and from text based JSON through QJsonDocument.-
66-
67 \sa {JSON Support in Qt}, {JSON Save Game Example}-
68*/-
69-
70/*!-
71 \typedef QJsonObject::Iterator-
72-
73 Qt-style synonym for QJsonObject::iterator.-
74*/-
75-
76/*!-
77 \typedef QJsonObject::ConstIterator-
78-
79 Qt-style synonym for QJsonObject::const_iterator.-
80*/-
81-
82/*!-
83 \typedef QJsonObject::key_type-
84-
85 Typedef for QString. Provided for STL compatibility.-
86*/-
87-
88/*!-
89 \typedef QJsonObject::mapped_type-
90-
91 Typedef for QJsonValue. Provided for STL compatibility.-
92*/-
93-
94/*!-
95 \typedef QJsonObject::size_type-
96-
97 Typedef for int. Provided for STL compatibility.-
98*/-
99-
100-
101/*!-
102 Constructs an empty JSON object.-
103-
104 \sa isEmpty()-
105 */-
106QJsonObject::QJsonObject()-
107 : d(0), o(0)-
108{-
109}
executed 43512 times by 142 tests: end of block
Executed by:
  • tst_Lancelot
  • tst_NetworkSelfTest
  • tst_PlatformSocketEngine
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractPrintDialog
  • tst_QAbstractScrollArea
  • tst_QAccessibility
  • tst_QApplication
  • tst_QBrush
  • tst_QButtonGroup
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QDataStream
  • tst_QDateTimeEdit
  • tst_QDialog
  • tst_QDnsLookup
  • tst_QDnsLookup_Appless
  • tst_QDoubleSpinBox
  • tst_QFactoryLoader
  • tst_QFileDialog2
  • ...
43512
110-
111/*!-
112 \fn QJsonObject::QJsonObject(std::initializer_list<QPair<QString, QJsonValue> > args)-
113 \since 5.4-
114 Constructs a QJsonObject instance initialized from \a args initialization list.-
115 For example:-
116 \code-
117 QJsonObject object-
118 {-
119 {"property1", 1},-
120 {"property2", 2}-
121 };-
122 \endcode-
123*/-
124-
125/*!-
126 \internal-
127 */-
128QJsonObject::QJsonObject(QJsonPrivate::Data *data, QJsonPrivate::Object *object)-
129 : d(data), o(object)-
130{-
131 Q_ASSERT(d);-
132 Q_ASSERT(o);-
133 d->ref.ref();-
134}
executed 42688 times by 116 tests: end of block
Executed by:
  • tst_NetworkSelfTest
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractPrintDialog
  • tst_QAbstractScrollArea
  • tst_QAccessibility
  • tst_QApplication
  • tst_QBrush
  • tst_QButtonGroup
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QDataStream
  • tst_QDateTimeEdit
  • tst_QDialog
  • tst_QDoubleSpinBox
  • tst_QFactoryLoader
  • tst_QFileDialog2
  • tst_QFileIconProvider
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QFocusEvent
  • ...
42688
135-
136/*!-
137 This method replaces part of the QJsonObject(std::initializer_list<QPair<QString, QJsonValue>> args) body.-
138 The constructor needs to be inline, but we do not want to leak implementation details-
139 of this class.-
140 \note this method is called for an uninitialized object-
141 \internal-
142 */-
143-
144void QJsonObject::initialize()-
145{-
146 d = 0;-
147 o = 0;-
148}
never executed: end of block
0
149-
150/*!-
151 Destroys the object.-
152 */-
153QJsonObject::~QJsonObject()-
154{-
155 if (d && !d->ref.deref())
dDescription
TRUEevaluated 86845 times by 359 tests
Evaluated by:
  • tst_NetworkSelfTest
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractPrintDialog
  • tst_QAbstractScrollArea
  • tst_QAccessibility
  • tst_QApplication
  • tst_QBrush
  • tst_QButtonGroup
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QDataStream
  • tst_QDateTimeEdit
  • tst_QDialog
  • tst_QDoubleSpinBox
  • tst_QFactoryLoader
  • tst_QFileDialog2
  • tst_QFileIconProvider
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QFocusEvent
  • ...
FALSEevaluated 42758 times by 119 tests
Evaluated by:
  • tst_NetworkSelfTest
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractPrintDialog
  • tst_QAbstractScrollArea
  • tst_QAccessibility
  • tst_QApplication
  • tst_QBrush
  • tst_QButtonGroup
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QDataStream
  • tst_QDateTimeEdit
  • tst_QDialog
  • tst_QDoubleSpinBox
  • tst_QFactoryLoader
  • tst_QFileDialog2
  • tst_QFileIconProvider
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QFocusEvent
  • ...
!d->ref.deref()Description
TRUEevaluated 3039 times by 249 tests
Evaluated by:
  • tst_QFactoryLoader
  • tst_QGuiApplication
  • tst_QMetaType
  • tst_QPluginLoader
  • tst_gestures - unknown status
  • tst_lancelot - unknown status
  • tst_languagechange - unknown status
  • tst_modeltest - unknown status
  • tst_networkselftest - unknown status
  • tst_qabstractbutton - unknown status
  • tst_qabstractitemview - unknown status
  • tst_qabstractnetworkcache - unknown status
  • tst_qabstractprintdialog - unknown status
  • tst_qabstractproxymodel - unknown status
  • tst_qabstractscrollarea - unknown status
  • tst_qabstractslider - unknown status
  • tst_qabstractspinbox - unknown status
  • tst_qabstracttextdocumentlayout - unknown status
  • tst_qaccessibility - unknown status
  • tst_qaction - unknown status
  • tst_qactiongroup - unknown status
  • tst_qapplication - unknown status
  • tst_qbackingstore - unknown status
  • tst_qboxlayout - unknown status
  • tst_qbrush - unknown status
  • ...
FALSEevaluated 83806 times by 117 tests
Evaluated by:
  • tst_NetworkSelfTest
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractPrintDialog
  • tst_QAbstractScrollArea
  • tst_QAccessibility
  • tst_QApplication
  • tst_QBrush
  • tst_QButtonGroup
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QDataStream
  • tst_QDateTimeEdit
  • tst_QDialog
  • tst_QDoubleSpinBox
  • tst_QFactoryLoader
  • tst_QFileDialog2
  • tst_QFileIconProvider
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QFocusEvent
  • ...
3039-86845
156 delete d;
executed 3039 times by 249 tests: delete d;
Executed by:
  • tst_QFactoryLoader
  • tst_QGuiApplication
  • tst_QMetaType
  • tst_QPluginLoader
  • tst_gestures - unknown status
  • tst_lancelot - unknown status
  • tst_languagechange - unknown status
  • tst_modeltest - unknown status
  • tst_networkselftest - unknown status
  • tst_qabstractbutton - unknown status
  • tst_qabstractitemview - unknown status
  • tst_qabstractnetworkcache - unknown status
  • tst_qabstractprintdialog - unknown status
  • tst_qabstractproxymodel - unknown status
  • tst_qabstractscrollarea - unknown status
  • tst_qabstractslider - unknown status
  • tst_qabstractspinbox - unknown status
  • tst_qabstracttextdocumentlayout - unknown status
  • tst_qaccessibility - unknown status
  • tst_qaction - unknown status
  • tst_qactiongroup - unknown status
  • tst_qapplication - unknown status
  • tst_qbackingstore - unknown status
  • tst_qboxlayout - unknown status
  • tst_qbrush - unknown status
  • ...
3039
157}
executed 129603 times by 362 tests: end of block
Executed by:
  • tst_NetworkSelfTest
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractPrintDialog
  • tst_QAbstractScrollArea
  • tst_QAccessibility
  • tst_QApplication
  • tst_QBrush
  • tst_QButtonGroup
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QDataStream
  • tst_QDateTimeEdit
  • tst_QDialog
  • tst_QDoubleSpinBox
  • tst_QFactoryLoader
  • tst_QFileDialog2
  • tst_QFileIconProvider
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QFocusEvent
  • ...
129603
158-
159/*!-
160 Creates a copy of \a other.-
161-
162 Since QJsonObject is implicitly shared, the copy is shallow-
163 as long as the object does not get modified.-
164 */-
165QJsonObject::QJsonObject(const QJsonObject &other)-
166{-
167 d = other.d;-
168 o = other.o;-
169 if (d)
dDescription
TRUEevaluated 41144 times by 111 tests
Evaluated by:
  • tst_NetworkSelfTest
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractPrintDialog
  • tst_QAbstractScrollArea
  • tst_QAccessibility
  • tst_QApplication
  • tst_QBrush
  • tst_QButtonGroup
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QDataStream
  • tst_QDateTimeEdit
  • tst_QDialog
  • tst_QDoubleSpinBox
  • tst_QFileDialog2
  • tst_QFileIconProvider
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QFocusEvent
  • tst_QFontComboBox
  • ...
FALSEevaluated 3 times by 1 test
Evaluated by:
  • tst_QVariant
3-41144
170 d->ref.ref();
executed 41144 times by 111 tests: d->ref.ref();
Executed by:
  • tst_NetworkSelfTest
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractPrintDialog
  • tst_QAbstractScrollArea
  • tst_QAccessibility
  • tst_QApplication
  • tst_QBrush
  • tst_QButtonGroup
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QDataStream
  • tst_QDateTimeEdit
  • tst_QDialog
  • tst_QDoubleSpinBox
  • tst_QFileDialog2
  • tst_QFileIconProvider
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QFocusEvent
  • tst_QFontComboBox
  • ...
41144
171}
executed 41147 times by 112 tests: end of block
Executed by:
  • tst_NetworkSelfTest
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractPrintDialog
  • tst_QAbstractScrollArea
  • tst_QAccessibility
  • tst_QApplication
  • tst_QBrush
  • tst_QButtonGroup
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QDataStream
  • tst_QDateTimeEdit
  • tst_QDialog
  • tst_QDoubleSpinBox
  • tst_QFileDialog2
  • tst_QFileIconProvider
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QFocusEvent
  • tst_QFontComboBox
  • ...
41147
172-
173/*!-
174 Assigns \a other to this object.-
175 */-
176QJsonObject &QJsonObject::operator =(const QJsonObject &other)-
177{-
178 if (d != other.d) {
d != other.dDescription
TRUEevaluated 653 times by 110 tests
Evaluated by:
  • tst_NetworkSelfTest
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractPrintDialog
  • tst_QAbstractScrollArea
  • tst_QAccessibility
  • tst_QApplication
  • tst_QBrush
  • tst_QButtonGroup
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QDataStream
  • tst_QDateTimeEdit
  • tst_QDialog
  • tst_QDoubleSpinBox
  • tst_QFactoryLoader
  • tst_QFileDialog2
  • tst_QFileIconProvider
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QFocusEvent
  • ...
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QVariant
1-653
179 if (d && !d->ref.deref())
dDescription
TRUEnever evaluated
FALSEevaluated 653 times by 110 tests
Evaluated by:
  • tst_NetworkSelfTest
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractPrintDialog
  • tst_QAbstractScrollArea
  • tst_QAccessibility
  • tst_QApplication
  • tst_QBrush
  • tst_QButtonGroup
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QDataStream
  • tst_QDateTimeEdit
  • tst_QDialog
  • tst_QDoubleSpinBox
  • tst_QFactoryLoader
  • tst_QFileDialog2
  • tst_QFileIconProvider
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QFocusEvent
  • ...
!d->ref.deref()Description
TRUEnever evaluated
FALSEnever evaluated
0-653
180 delete d;
never executed: delete d;
0
181 d = other.d;-
182 if (d)
dDescription
TRUEevaluated 653 times by 110 tests
Evaluated by:
  • tst_NetworkSelfTest
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractPrintDialog
  • tst_QAbstractScrollArea
  • tst_QAccessibility
  • tst_QApplication
  • tst_QBrush
  • tst_QButtonGroup
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QDataStream
  • tst_QDateTimeEdit
  • tst_QDialog
  • tst_QDoubleSpinBox
  • tst_QFactoryLoader
  • tst_QFileDialog2
  • tst_QFileIconProvider
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QFocusEvent
  • ...
FALSEnever evaluated
0-653
183 d->ref.ref();
executed 653 times by 110 tests: d->ref.ref();
Executed by:
  • tst_NetworkSelfTest
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractPrintDialog
  • tst_QAbstractScrollArea
  • tst_QAccessibility
  • tst_QApplication
  • tst_QBrush
  • tst_QButtonGroup
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QDataStream
  • tst_QDateTimeEdit
  • tst_QDialog
  • tst_QDoubleSpinBox
  • tst_QFactoryLoader
  • tst_QFileDialog2
  • tst_QFileIconProvider
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QFocusEvent
  • ...
653
184 }
executed 653 times by 110 tests: end of block
Executed by:
  • tst_NetworkSelfTest
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractPrintDialog
  • tst_QAbstractScrollArea
  • tst_QAccessibility
  • tst_QApplication
  • tst_QBrush
  • tst_QButtonGroup
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QDataStream
  • tst_QDateTimeEdit
  • tst_QDialog
  • tst_QDoubleSpinBox
  • tst_QFactoryLoader
  • tst_QFileDialog2
  • tst_QFileIconProvider
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QFocusEvent
  • ...
653
185 o = other.o;-
186-
187 return *this;
executed 654 times by 111 tests: return *this;
Executed by:
  • tst_NetworkSelfTest
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractPrintDialog
  • tst_QAbstractScrollArea
  • tst_QAccessibility
  • tst_QApplication
  • tst_QBrush
  • tst_QButtonGroup
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QDataStream
  • tst_QDateTimeEdit
  • tst_QDialog
  • tst_QDoubleSpinBox
  • tst_QFactoryLoader
  • tst_QFileDialog2
  • tst_QFileIconProvider
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QFocusEvent
  • ...
654
188}-
189-
190/*!-
191 Converts the variant map \a map to a QJsonObject.-
192-
193 The keys in \a map will be used as the keys in the JSON object,-
194 and the QVariant values will be converted to JSON values.-
195-
196 \sa fromVariantHash(), toVariantMap(), QJsonValue::fromVariant()-
197 */-
198QJsonObject QJsonObject::fromVariantMap(const QVariantMap &map)-
199{-
200 QJsonObject object;-
201 if (map.isEmpty())
map.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
202 return object;
never executed: return object;
0
203-
204 object.detach2(1024);-
205-
206 QVector<QJsonPrivate::offset> offsets;-
207 QJsonPrivate::offset currentOffset;-
208 currentOffset = sizeof(QJsonPrivate::Base);-
209-
210 // the map is already sorted, so we can simply append one entry after the other and-
211 // write the offset table at the end-
212 for (QVariantMap::const_iterator it = map.constBegin(); it != map.constEnd(); ++it) {
it != map.constEnd()Description
TRUEnever evaluated
FALSEnever evaluated
0
213 QString key = it.key();-
214 QJsonValue val = QJsonValue::fromVariant(it.value());-
215-
216 bool latinOrIntValue;-
217 int valueSize = QJsonPrivate::Value::requiredStorage(val, &latinOrIntValue);-
218-
219 bool latinKey = QJsonPrivate::useCompressed(key);-
220 int valueOffset = sizeof(QJsonPrivate::Entry) + QJsonPrivate::qStringSize(key, latinKey);-
221 int requiredSize = valueOffset + valueSize;-
222-
223 if (!object.detach2(requiredSize + sizeof(QJsonPrivate::offset))) // offset for the new index entry
!object.detach...vate::offset))Description
TRUEnever evaluated
FALSEnever evaluated
0
224 return QJsonObject();
never executed: return QJsonObject();
0
225-
226 QJsonPrivate::Entry *e = reinterpret_cast<QJsonPrivate::Entry *>(reinterpret_cast<char *>(object.o) + currentOffset);-
227 e->value.type = val.t;-
228 e->value.latinKey = latinKey;-
229 e->value.latinOrIntValue = latinOrIntValue;-
230 e->value.value = QJsonPrivate::Value::valueToStore(val, (char *)e - (char *)object.o + valueOffset);-
231 QJsonPrivate::copyString((char *)(e + 1), key, latinKey);-
232 if (valueSize)
valueSizeDescription
TRUEnever evaluated
FALSEnever evaluated
0
233 QJsonPrivate::Value::copyData(val, (char *)e + valueOffset, latinOrIntValue);
never executed: QJsonPrivate::Value::copyData(val, (char *)e + valueOffset, latinOrIntValue);
0
234-
235 offsets << currentOffset;-
236 currentOffset += requiredSize;-
237 object.o->size = currentOffset;-
238 }
never executed: end of block
0
239-
240 // write table-
241 object.o->tableOffset = currentOffset;-
242 if (!object.detach2(sizeof(QJsonPrivate::offset)*offsets.size()))
!object.detach...ffsets.size())Description
TRUEnever evaluated
FALSEnever evaluated
0
243 return QJsonObject();
never executed: return QJsonObject();
0
244 memcpy(object.o->table(), offsets.constData(), offsets.size()*sizeof(uint));-
245 object.o->length = offsets.size();-
246 object.o->size = currentOffset + sizeof(QJsonPrivate::offset)*offsets.size();-
247-
248 return object;
never executed: return object;
0
249}-
250-
251/*!-
252 Converts this object to a QVariantMap.-
253-
254 Returns the created map.-
255-
256 \sa toVariantHash()-
257 */-
258QVariantMap QJsonObject::toVariantMap() const-
259{-
260 QVariantMap map;-
261 if (o) {
oDescription
TRUEnever evaluated
FALSEnever evaluated
0
262 for (uint i = 0; i < o->length; ++i) {
i < o->lengthDescription
TRUEnever evaluated
FALSEnever evaluated
0
263 QJsonPrivate::Entry *e = o->entryAt(i);-
264 map.insert(e->key(), QJsonValue(d, o, e->value).toVariant());-
265 }
never executed: end of block
0
266 }
never executed: end of block
0
267 return map;
never executed: return map;
0
268}-
269-
270/*!-
271 Converts the variant hash \a hash to a QJsonObject.-
272 \since 5.5-
273-
274 The keys in \a hash will be used as the keys in the JSON object,-
275 and the QVariant values will be converted to JSON values.-
276-
277 \sa fromVariantMap(), toVariantHash(), QJsonValue::fromVariant()-
278 */-
279QJsonObject QJsonObject::fromVariantHash(const QVariantHash &hash)-
280{-
281 // ### this is implemented the trivial way, not the most efficient way-
282-
283 QJsonObject object;-
284 for (QVariantHash::const_iterator it = hash.constBegin(); it != hash.constEnd(); ++it)
it != hash.constEnd()Description
TRUEnever evaluated
FALSEnever evaluated
0
285 object.insert(it.key(), QJsonValue::fromVariant(it.value()));
never executed: object.insert(it.key(), QJsonValue::fromVariant(it.value()));
0
286 return object;
never executed: return object;
0
287}-
288-
289/*!-
290 Converts this object to a QVariantHash.-
291 \since 5.5-
292-
293 Returns the created hash.-
294-
295 \sa toVariantMap()-
296 */-
297QVariantHash QJsonObject::toVariantHash() const-
298{-
299 QVariantHash hash;-
300 if (o) {
oDescription
TRUEnever evaluated
FALSEnever evaluated
0
301 for (uint i = 0; i < o->length; ++i) {
i < o->lengthDescription
TRUEnever evaluated
FALSEnever evaluated
0
302 QJsonPrivate::Entry *e = o->entryAt(i);-
303 hash.insert(e->key(), QJsonValue(d, o, e->value).toVariant());-
304 }
never executed: end of block
0
305 }
never executed: end of block
0
306 return hash;
never executed: return hash;
0
307}-
308-
309/*!-
310 Returns a list of all keys in this object.-
311-
312 The list is sorted lexographically.-
313 */-
314QStringList QJsonObject::keys() const-
315{-
316 QStringList keys;-
317 if (o) {
oDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_qmakelib
FALSEnever evaluated
0-4
318 keys.reserve(o->length);-
319 for (uint i = 0; i < o->length; ++i) {
i < o->lengthDescription
TRUEevaluated 18 times by 1 test
Evaluated by:
  • tst_qmakelib
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_qmakelib
4-18
320 QJsonPrivate::Entry *e = o->entryAt(i);-
321 keys.append(e->key());-
322 }
executed 18 times by 1 test: end of block
Executed by:
  • tst_qmakelib
18
323 }
executed 4 times by 1 test: end of block
Executed by:
  • tst_qmakelib
4
324 return keys;
executed 4 times by 1 test: return keys;
Executed by:
  • tst_qmakelib
4
325}-
326-
327/*!-
328 Returns the number of (key, value) pairs stored in the object.-
329 */-
330int QJsonObject::size() const-
331{-
332 if (!d)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
333 return 0;
never executed: return 0;
0
334-
335 return o->length;
never executed: return o->length;
0
336}-
337-
338/*!-
339 Returns \c true if the object is empty. This is the same as size() == 0.-
340-
341 \sa size()-
342 */-
343bool QJsonObject::isEmpty() const-
344{-
345 if (!d)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
346 return true;
never executed: return true;
0
347-
348 return !o->length;
never executed: return !o->length;
0
349}-
350-
351/*!-
352 Returns a QJsonValue representing the value for the key \a key.-
353-
354 The returned QJsonValue is QJsonValue::Undefined if the key does not exist.-
355-
356 \sa QJsonValue, QJsonValue::isUndefined()-
357 */-
358QJsonValue QJsonObject::value(const QString &key) const-
359{-
360 if (!d)
!dDescription
TRUEnever evaluated
FALSEevaluated 87477 times by 116 tests
Evaluated by:
  • tst_NetworkSelfTest
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractPrintDialog
  • tst_QAbstractScrollArea
  • tst_QAccessibility
  • tst_QApplication
  • tst_QBrush
  • tst_QButtonGroup
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QDataStream
  • tst_QDateTimeEdit
  • tst_QDialog
  • tst_QDoubleSpinBox
  • tst_QFactoryLoader
  • tst_QFileDialog2
  • tst_QFileIconProvider
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QFocusEvent
  • ...
0-87477
361 return QJsonValue(QJsonValue::Undefined);
never executed: return QJsonValue(QJsonValue::Undefined);
0
362-
363 bool keyExists;-
364 int i = o->indexOf(key, &keyExists);-
365 if (!keyExists)
!keyExistsDescription
TRUEevaluated 302 times by 3 tests
Evaluated by:
  • tst_QFactoryLoader
  • tst_QNetworkCookieJar
  • tst_QOpenGlConfig
FALSEevaluated 87175 times by 116 tests
Evaluated by:
  • tst_NetworkSelfTest
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractPrintDialog
  • tst_QAbstractScrollArea
  • tst_QAccessibility
  • tst_QApplication
  • tst_QBrush
  • tst_QButtonGroup
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QDataStream
  • tst_QDateTimeEdit
  • tst_QDialog
  • tst_QDoubleSpinBox
  • tst_QFactoryLoader
  • tst_QFileDialog2
  • tst_QFileIconProvider
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QFocusEvent
  • ...
302-87175
366 return QJsonValue(QJsonValue::Undefined);
executed 302 times by 3 tests: return QJsonValue(QJsonValue::Undefined);
Executed by:
  • tst_QFactoryLoader
  • tst_QNetworkCookieJar
  • tst_QOpenGlConfig
302
367 return QJsonValue(d, o, o->entryAt(i)->value);
executed 87175 times by 116 tests: return QJsonValue(d, o, o->entryAt(i)->value);
Executed by:
  • tst_NetworkSelfTest
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractPrintDialog
  • tst_QAbstractScrollArea
  • tst_QAccessibility
  • tst_QApplication
  • tst_QBrush
  • tst_QButtonGroup
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QDataStream
  • tst_QDateTimeEdit
  • tst_QDialog
  • tst_QDoubleSpinBox
  • tst_QFactoryLoader
  • tst_QFileDialog2
  • tst_QFileIconProvider
  • tst_QFileSystemModel
  • tst_QFiledialog
  • tst_QFocusEvent
  • ...
87175
368}-
369-
370/*!-
371 Returns a QJsonValue representing the value for the key \a key.-
372-
373 This does the same as value().-
374-
375 The returned QJsonValue is QJsonValue::Undefined if the key does not exist.-
376-
377 \sa value(), QJsonValue, QJsonValue::isUndefined()-
378 */-
379QJsonValue QJsonObject::operator [](const QString &key) const-
380{-
381 return value(key);
never executed: return value(key);
0
382}-
383-
384/*!-
385 Returns a reference to the value for \a key.-
386-
387 The return value is of type QJsonValueRef, a helper class for QJsonArray-
388 and QJsonObject. When you get an object of type QJsonValueRef, you can-
389 use it as if it were a reference to a QJsonValue. If you assign to it,-
390 the assignment will apply to the element in the QJsonArray or QJsonObject-
391 from which you got the reference.-
392-
393 \sa value()-
394 */-
395QJsonValueRef QJsonObject::operator [](const QString &key)-
396{-
397 // ### somewhat inefficient, as we lookup the key twice if it doesn't yet exist-
398 bool keyExists = false;-
399 int index = o ? o->indexOf(key, &keyExists) : -1;
oDescription
TRUEnever evaluated
FALSEnever evaluated
0
400 if (!keyExists) {
!keyExistsDescription
TRUEnever evaluated
FALSEnever evaluated
0
401 iterator i = insert(key, QJsonValue());-
402 index = i.i;-
403 }
never executed: end of block
0
404 return QJsonValueRef(this, index);
never executed: return QJsonValueRef(this, index);
0
405}-
406-
407/*!-
408 Inserts a new item with the key \a key and a value of \a value.-
409-
410 If there is already an item with the key \a key, then that item's value-
411 is replaced with \a value.-
412-
413 Returns an iterator pointing to the inserted item.-
414-
415 If the value is QJsonValue::Undefined, it will cause the key to get removed-
416 from the object. The returned iterator will then point to end().-
417-
418 \sa remove(), take(), QJsonObject::iterator, end()-
419 */-
420QJsonObject::iterator QJsonObject::insert(const QString &key, const QJsonValue &value)-
421{-
422 if (value.t == QJsonValue::Undefined) {
value.t == QJs...lue::UndefinedDescription
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • tst_QMetaType
0-8
423 remove(key);-
424 return end();
never executed: return end();
0
425 }-
426 QJsonValue val = value;-
427-
428 bool latinOrIntValue;-
429 int valueSize = QJsonPrivate::Value::requiredStorage(val, &latinOrIntValue);-
430-
431 bool latinKey = QJsonPrivate::useCompressed(key);-
432 int valueOffset = sizeof(QJsonPrivate::Entry) + QJsonPrivate::qStringSize(key, latinKey);-
433 int requiredSize = valueOffset + valueSize;-
434-
435 if (!detach2(requiredSize + sizeof(QJsonPrivate::offset))) // offset for the new index entry
!detach2(requi...vate::offset))Description
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • tst_QMetaType
0-8
436 return iterator();
never executed: return iterator();
0
437-
438 if (!o->length)
!o->lengthDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QMetaType
FALSEevaluated 6 times by 1 test
Evaluated by:
  • tst_QMetaType
2-6
439 o->tableOffset = sizeof(QJsonPrivate::Object);
executed 2 times by 1 test: o->tableOffset = sizeof(QJsonPrivate::Object);
Executed by:
  • tst_QMetaType
2
440-
441 bool keyExists = false;-
442 int pos = o->indexOf(key, &keyExists);-
443 if (keyExists)
keyExistsDescription
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • tst_QMetaType
0-8
444 ++d->compactionCounter;
never executed: ++d->compactionCounter;
0
445-
446 uint off = o->reserveSpace(requiredSize, pos, 1, keyExists);-
447 if (!off)
!offDescription
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • tst_QMetaType
0-8
448 return end();
never executed: return end();
0
449-
450 QJsonPrivate::Entry *e = o->entryAt(pos);-
451 e->value.type = val.t;-
452 e->value.latinKey = latinKey;-
453 e->value.latinOrIntValue = latinOrIntValue;-
454 e->value.value = QJsonPrivate::Value::valueToStore(val, (char *)e - (char *)o + valueOffset);-
455 QJsonPrivate::copyString((char *)(e + 1), key, latinKey);-
456 if (valueSize)
valueSizeDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QMetaType
FALSEevaluated 6 times by 1 test
Evaluated by:
  • tst_QMetaType
2-6
457 QJsonPrivate::Value::copyData(val, (char *)e + valueOffset, latinOrIntValue);
executed 2 times by 1 test: QJsonPrivate::Value::copyData(val, (char *)e + valueOffset, latinOrIntValue);
Executed by:
  • tst_QMetaType
2
458-
459 if (d->compactionCounter > 32u && d->compactionCounter >= unsigned(o->length) / 2u)
d->compactionCounter > 32uDescription
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • tst_QMetaType
d->compactionC...->length) / 2uDescription
TRUEnever evaluated
FALSEnever evaluated
0-8
460 compact();
never executed: compact();
0
461-
462 return iterator(this, pos);
executed 8 times by 1 test: return iterator(this, pos);
Executed by:
  • tst_QMetaType
8
463}-
464-
465/*!-
466 Removes \a key from the object.-
467-
468 \sa insert(), take()-
469 */-
470void QJsonObject::remove(const QString &key)-
471{-
472 if (!d)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
473 return;
never executed: return;
0
474-
475 bool keyExists;-
476 int index = o->indexOf(key, &keyExists);-
477 if (!keyExists)
!keyExistsDescription
TRUEnever evaluated
FALSEnever evaluated
0
478 return;
never executed: return;
0
479-
480 detach2();-
481 o->removeItems(index, 1);-
482 ++d->compactionCounter;-
483 if (d->compactionCounter > 32u && d->compactionCounter >= unsigned(o->length) / 2u)
d->compactionCounter > 32uDescription
TRUEnever evaluated
FALSEnever evaluated
d->compactionC...->length) / 2uDescription
TRUEnever evaluated
FALSEnever evaluated
0
484 compact();
never executed: compact();
0
485}
never executed: end of block
0
486-
487/*!-
488 Removes \a key from the object.-
489-
490 Returns a QJsonValue containing the value referenced by \a key.-
491 If \a key was not contained in the object, the returned QJsonValue-
492 is QJsonValue::Undefined.-
493-
494 \sa insert(), remove(), QJsonValue-
495 */-
496QJsonValue QJsonObject::take(const QString &key)-
497{-
498 if (!o)
!oDescription
TRUEnever evaluated
FALSEnever evaluated
0
499 return QJsonValue(QJsonValue::Undefined);
never executed: return QJsonValue(QJsonValue::Undefined);
0
500-
501 bool keyExists;-
502 int index = o->indexOf(key, &keyExists);-
503 if (!keyExists)
!keyExistsDescription
TRUEnever evaluated
FALSEnever evaluated
0
504 return QJsonValue(QJsonValue::Undefined);
never executed: return QJsonValue(QJsonValue::Undefined);
0
505-
506 QJsonValue v(d, o, o->entryAt(index)->value);-
507 detach2();-
508 o->removeItems(index, 1);-
509 ++d->compactionCounter;-
510 if (d->compactionCounter > 32u && d->compactionCounter >= unsigned(o->length) / 2u)
d->compactionCounter > 32uDescription
TRUEnever evaluated
FALSEnever evaluated
d->compactionC...->length) / 2uDescription
TRUEnever evaluated
FALSEnever evaluated
0
511 compact();
never executed: compact();
0
512-
513 return v;
never executed: return v;
0
514}-
515-
516/*!-
517 Returns \c true if the object contains key \a key.-
518-
519 \sa insert(), remove(), take()-
520 */-
521bool QJsonObject::contains(const QString &key) const-
522{-
523 if (!o)
!oDescription
TRUEnever evaluated
FALSEevaluated 12 times by 1 test
Evaluated by:
  • tst_QOpenGlConfig
0-12
524 return false;
never executed: return false;
0
525-
526 bool keyExists;-
527 o->indexOf(key, &keyExists);-
528 return keyExists;
executed 12 times by 1 test: return keyExists;
Executed by:
  • tst_QOpenGlConfig
12
529}-
530-
531/*!-
532 Returns \c true if \a other is equal to this object.-
533 */-
534bool QJsonObject::operator==(const QJsonObject &other) const-
535{-
536 if (o == other.o)
o == other.oDescription
TRUEevaluated 8 times by 1 test
Evaluated by:
  • tst_QMetaType
FALSEnever evaluated
0-8
537 return true;
executed 8 times by 1 test: return true;
Executed by:
  • tst_QMetaType
8
538-
539 if (!o)
!oDescription
TRUEnever evaluated
FALSEnever evaluated
0
540 return !other.o->length;
never executed: return !other.o->length;
0
541 if (!other.o)
!other.oDescription
TRUEnever evaluated
FALSEnever evaluated
0
542 return !o->length;
never executed: return !o->length;
0
543 if (o->length != other.o->length)
o->length != other.o->lengthDescription
TRUEnever evaluated
FALSEnever evaluated
0
544 return false;
never executed: return false;
0
545-
546 for (uint i = 0; i < o->length; ++i) {
i < o->lengthDescription
TRUEnever evaluated
FALSEnever evaluated
0
547 QJsonPrivate::Entry *e = o->entryAt(i);-
548 QJsonValue v(d, o, e->value);-
549 if (other.value(e->key()) != v)
other.value(e->key()) != vDescription
TRUEnever evaluated
FALSEnever evaluated
0
550 return false;
never executed: return false;
0
551 }
never executed: end of block
0
552-
553 return true;
never executed: return true;
0
554}-
555-
556/*!-
557 Returns \c true if \a other is not equal to this object.-
558 */-
559bool QJsonObject::operator!=(const QJsonObject &other) const-
560{-
561 return !(*this == other);
never executed: return !(*this == other);
0
562}-
563-
564/*!-
565 Removes the (key, value) pair pointed to by the iterator \a it-
566 from the map, and returns an iterator to the next item in the-
567 map.-
568-
569 \sa remove()-
570 */-
571QJsonObject::iterator QJsonObject::erase(QJsonObject::iterator it)-
572{-
573 Q_ASSERT(d && d->ref.load() == 1);-
574 if (it.o != this || it.i < 0 || it.i >= (int)o->length)
it.o != thisDescription
TRUEnever evaluated
FALSEnever evaluated
it.i < 0Description
TRUEnever evaluated
FALSEnever evaluated
it.i >= (int)o->lengthDescription
TRUEnever evaluated
FALSEnever evaluated
0
575 return iterator(this, o->length);
never executed: return iterator(this, o->length);
0
576-
577 int index = it.i;-
578-
579 o->removeItems(index, 1);-
580 ++d->compactionCounter;-
581 if (d->compactionCounter > 32u && d->compactionCounter >= unsigned(o->length) / 2u)
d->compactionCounter > 32uDescription
TRUEnever evaluated
FALSEnever evaluated
d->compactionC...->length) / 2uDescription
TRUEnever evaluated
FALSEnever evaluated
0
582 compact();
never executed: compact();
0
583-
584 // iterator hasn't changed-
585 return it;
never executed: return it;
0
586}-
587-
588/*!-
589 Returns an iterator pointing to the item with key \a key in the-
590 map.-
591-
592 If the map contains no item with key \a key, the function-
593 returns end().-
594 */-
595QJsonObject::iterator QJsonObject::find(const QString &key)-
596{-
597 bool keyExists = false;-
598 int index = o ? o->indexOf(key, &keyExists) : 0;
oDescription
TRUEnever evaluated
FALSEnever evaluated
0
599 if (!keyExists)
!keyExistsDescription
TRUEnever evaluated
FALSEnever evaluated
0
600 return end();
never executed: return end();
0
601 detach2();-
602 return iterator(this, index);
never executed: return iterator(this, index);
0
603}-
604-
605/*! \fn QJsonObject::const_iterator QJsonObject::find(const QString &key) const-
606-
607 \overload-
608*/-
609-
610/*!-
611 Returns a const iterator pointing to the item with key \a key in the-
612 map.-
613-
614 If the map contains no item with key \a key, the function-
615 returns constEnd().-
616 */-
617QJsonObject::const_iterator QJsonObject::constFind(const QString &key) const-
618{-
619 bool keyExists = false;-
620 int index = o ? o->indexOf(key, &keyExists) : 0;
oDescription
TRUEnever evaluated
FALSEnever evaluated
0
621 if (!keyExists)
!keyExistsDescription
TRUEnever evaluated
FALSEnever evaluated
0
622 return end();
never executed: return end();
0
623 return const_iterator(this, index);
never executed: return const_iterator(this, index);
0
624}-
625-
626/*! \fn int QJsonObject::count() const-
627-
628 \overload-
629-
630 Same as size().-
631*/-
632-
633/*! \fn int QJsonObject::length() const-
634-
635 \overload-
636-
637 Same as size().-
638*/-
639-
640/*! \fn QJsonObject::iterator QJsonObject::begin()-
641-
642 Returns an \l{STL-style iterators}{STL-style iterator} pointing to the first item in-
643 the object.-
644-
645 \sa constBegin(), end()-
646*/-
647-
648/*! \fn QJsonObject::const_iterator QJsonObject::begin() const-
649-
650 \overload-
651*/-
652-
653/*! \fn QJsonObject::const_iterator QJsonObject::constBegin() const-
654-
655 Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first item-
656 in the object.-
657-
658 \sa begin(), constEnd()-
659*/-
660-
661/*! \fn QJsonObject::iterator QJsonObject::end()-
662-
663 Returns an \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item-
664 after the last item in the object.-
665-
666 \sa begin(), constEnd()-
667*/-
668-
669/*! \fn QJsonObject::const_iterator QJsonObject::end() const-
670-
671 \overload-
672*/-
673-
674/*! \fn QJsonObject::const_iterator QJsonObject::constEnd() const-
675-
676 Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary-
677 item after the last item in the object.-
678-
679 \sa constBegin(), end()-
680*/-
681-
682/*!-
683 \fn bool QJsonObject::empty() const-
684-
685 This function is provided for STL compatibility. It is equivalent-
686 to isEmpty(), returning \c true if the object is empty; otherwise-
687 returning \c false.-
688*/-
689-
690/*! \class QJsonObject::iterator-
691 \inmodule QtCore-
692 \ingroup json-
693 \reentrant-
694 \since 5.0-
695-
696 \brief The QJsonObject::iterator class provides an STL-style non-const iterator for QJsonObject.-
697-
698 QJsonObject::iterator allows you to iterate over a QJsonObject-
699 and to modify the value (but not the key) stored under-
700 a particular key. If you want to iterate over a const QJsonObject, you-
701 should use QJsonObject::const_iterator. It is generally good practice to-
702 use QJsonObject::const_iterator on a non-const QJsonObject as well, unless you-
703 need to change the QJsonObject through the iterator. Const iterators are-
704 slightly faster, and improve code readability.-
705-
706 The default QJsonObject::iterator constructor creates an uninitialized-
707 iterator. You must initialize it using a QJsonObject function like-
708 QJsonObject::begin(), QJsonObject::end(), or QJsonObject::find() before you can-
709 start iterating.-
710-
711 Multiple iterators can be used on the same object. Existing iterators will however-
712 become dangling once the object gets modified.-
713-
714 \sa QJsonObject::const_iterator, {JSON Support in Qt}, {JSON Save Game Example}-
715*/-
716-
717/*! \typedef QJsonObject::iterator::difference_type-
718-
719 \internal-
720*/-
721-
722/*! \typedef QJsonObject::iterator::iterator_category-
723-
724 A synonym for \e {std::random_access_iterator_tag} indicating-
725 this iterator is a random-access iterator.-
726-
727 \note In Qt versions before 5.6, this was set by mistake to-
728 \e {std::bidirectional_iterator_tag}.-
729*/-
730-
731/*! \typedef QJsonObject::iterator::reference-
732-
733 \internal-
734*/-
735-
736/*! \typedef QJsonObject::iterator::value_type-
737-
738 \internal-
739*/-
740-
741/*! \typedef QJsonObject::iterator::pointer-
742-
743 \internal-
744*/-
745-
746/*! \fn QJsonObject::iterator::iterator()-
747-
748 Constructs an uninitialized iterator.-
749-
750 Functions like key(), value(), and operator++() must not be-
751 called on an uninitialized iterator. Use operator=() to assign a-
752 value to it before using it.-
753-
754 \sa QJsonObject::begin(), QJsonObject::end()-
755*/-
756-
757/*! \fn QJsonObject::iterator::iterator(QJsonObject *obj, int index)-
758 \internal-
759*/-
760-
761/*! \fn QString QJsonObject::iterator::key() const-
762-
763 Returns the current item's key.-
764-
765 There is no direct way of changing an item's key through an-
766 iterator, although it can be done by calling QJsonObject::erase()-
767 followed by QJsonObject::insert().-
768-
769 \sa value()-
770*/-
771-
772/*! \fn QJsonValueRef QJsonObject::iterator::value() const-
773-
774 Returns a modifiable reference to the current item's value.-
775-
776 You can change the value of an item by using value() on-
777 the left side of an assignment.-
778-
779 The return value is of type QJsonValueRef, a helper class for QJsonArray-
780 and QJsonObject. When you get an object of type QJsonValueRef, you can-
781 use it as if it were a reference to a QJsonValue. If you assign to it,-
782 the assignment will apply to the element in the QJsonArray or QJsonObject-
783 from which you got the reference.-
784-
785 \sa key(), operator*()-
786*/-
787-
788/*! \fn QJsonValueRef QJsonObject::iterator::operator*() const-
789-
790 Returns a modifiable reference to the current item's value.-
791-
792 Same as value().-
793-
794 The return value is of type QJsonValueRef, a helper class for QJsonArray-
795 and QJsonObject. When you get an object of type QJsonValueRef, you can-
796 use it as if it were a reference to a QJsonValue. If you assign to it,-
797 the assignment will apply to the element in the QJsonArray or QJsonObject-
798 from which you got the reference.-
799-
800 \sa key()-
801*/-
802-
803/*! \fn QJsonValueRef *QJsonObject::iterator::operator->() const-
804-
805 Returns a pointer to a modifiable reference to the current item.-
806*/-
807-
808/*!-
809 \fn bool QJsonObject::iterator::operator==(const iterator &other) const-
810 \fn bool QJsonObject::iterator::operator==(const const_iterator &other) const-
811-
812 Returns \c true if \a other points to the same item as this-
813 iterator; otherwise returns \c false.-
814-
815 \sa operator!=()-
816*/-
817-
818/*!-
819 \fn bool QJsonObject::iterator::operator!=(const iterator &other) const-
820 \fn bool QJsonObject::iterator::operator!=(const const_iterator &other) const-
821-
822 Returns \c true if \a other points to a different item than this-
823 iterator; otherwise returns \c false.-
824-
825 \sa operator==()-
826*/-
827-
828/*! \fn QJsonObject::iterator QJsonObject::iterator::operator++()-
829-
830 The prefix ++ operator, \c{++i}, advances the iterator to the-
831 next item in the object and returns an iterator to the new current-
832 item.-
833-
834 Calling this function on QJsonObject::end() leads to undefined results.-
835-
836 \sa operator--()-
837*/-
838-
839/*! \fn QJsonObject::iterator QJsonObject::iterator::operator++(int)-
840-
841 \overload-
842-
843 The postfix ++ operator, \c{i++}, advances the iterator to the-
844 next item in the object and returns an iterator to the previously-
845 current item.-
846*/-
847-
848/*! \fn QJsonObject::iterator QJsonObject::iterator::operator--()-
849-
850 The prefix -- operator, \c{--i}, makes the preceding item-
851 current and returns an iterator pointing to the new current item.-
852-
853 Calling this function on QJsonObject::begin() leads to undefined-
854 results.-
855-
856 \sa operator++()-
857*/-
858-
859/*! \fn QJsonObject::iterator QJsonObject::iterator::operator--(int)-
860-
861 \overload-
862-
863 The postfix -- operator, \c{i--}, makes the preceding item-
864 current and returns an iterator pointing to the previously-
865 current item.-
866*/-
867-
868/*! \fn QJsonObject::iterator QJsonObject::iterator::operator+(int j) const-
869-
870 Returns an iterator to the item at \a j positions forward from-
871 this iterator. If \a j is negative, the iterator goes backward.-
872-
873 \sa operator-()-
874-
875*/-
876-
877/*! \fn QJsonObject::iterator QJsonObject::iterator::operator-(int j) const-
878-
879 Returns an iterator to the item at \a j positions backward from-
880 this iterator. If \a j is negative, the iterator goes forward.-
881-
882 \sa operator+()-
883*/-
884-
885/*! \fn QJsonObject::iterator &QJsonObject::iterator::operator+=(int j)-
886-
887 Advances the iterator by \a j items. If \a j is negative, the-
888 iterator goes backward.-
889-
890 \sa operator-=(), operator+()-
891*/-
892-
893/*! \fn QJsonObject::iterator &QJsonObject::iterator::operator-=(int j)-
894-
895 Makes the iterator go back by \a j items. If \a j is negative,-
896 the iterator goes forward.-
897-
898 \sa operator+=(), operator-()-
899*/-
900-
901/*!-
902 \class QJsonObject::const_iterator-
903 \inmodule QtCore-
904 \ingroup json-
905 \since 5.0-
906 \brief The QJsonObject::const_iterator class provides an STL-style const iterator for QJsonObject.-
907-
908 QJsonObject::const_iterator allows you to iterate over a QJsonObject.-
909 If you want to modify the QJsonObject as you iterate-
910 over it, you must use QJsonObject::iterator instead. It is generally-
911 good practice to use QJsonObject::const_iterator on a non-const QJsonObject as-
912 well, unless you need to change the QJsonObject through the iterator.-
913 Const iterators are slightly faster and improve code-
914 readability.-
915-
916 The default QJsonObject::const_iterator constructor creates an-
917 uninitialized iterator. You must initialize it using a QJsonObject-
918 function like QJsonObject::constBegin(), QJsonObject::constEnd(), or-
919 QJsonObject::find() before you can start iterating.-
920-
921 Multiple iterators can be used on the same object. Existing iterators-
922 will however become dangling if the object gets modified.-
923-
924 \sa QJsonObject::iterator, {JSON Support in Qt}, {JSON Save Game Example}-
925*/-
926-
927/*! \typedef QJsonObject::const_iterator::difference_type-
928-
929 \internal-
930*/-
931-
932/*! \typedef QJsonObject::const_iterator::iterator_category-
933-
934 A synonym for \e {std::random_access_iterator_tag} indicating-
935 this iterator is a random-access iterator.-
936-
937 \note In Qt versions before 5.6, this was set by mistake to-
938 \e {std::bidirectional_iterator_tag}.-
939*/-
940-
941/*! \typedef QJsonObject::const_iterator::reference-
942-
943 \internal-
944*/-
945-
946/*! \typedef QJsonObject::const_iterator::value_type-
947-
948 \internal-
949*/-
950-
951/*! \typedef QJsonObject::const_iterator::pointer-
952-
953 \internal-
954*/-
955-
956/*! \fn QJsonObject::const_iterator::const_iterator()-
957-
958 Constructs an uninitialized iterator.-
959-
960 Functions like key(), value(), and operator++() must not be-
961 called on an uninitialized iterator. Use operator=() to assign a-
962 value to it before using it.-
963-
964 \sa QJsonObject::constBegin(), QJsonObject::constEnd()-
965*/-
966-
967/*! \fn QJsonObject::const_iterator::const_iterator(const QJsonObject *obj, int index)-
968 \internal-
969*/-
970-
971/*! \fn QJsonObject::const_iterator::const_iterator(const iterator &other)-
972-
973 Constructs a copy of \a other.-
974*/-
975-
976/*! \fn QString QJsonObject::const_iterator::key() const-
977-
978 Returns the current item's key.-
979-
980 \sa value()-
981*/-
982-
983/*! \fn QJsonValue QJsonObject::const_iterator::value() const-
984-
985 Returns the current item's value.-
986-
987 \sa key(), operator*()-
988*/-
989-
990/*! \fn QJsonValue QJsonObject::const_iterator::operator*() const-
991-
992 Returns the current item's value.-
993-
994 Same as value().-
995-
996 \sa key()-
997*/-
998-
999/*! \fn QJsonValue *QJsonObject::const_iterator::operator->() const-
1000-
1001 Returns a pointer to the current item.-
1002*/-
1003-
1004/*! \fn bool QJsonObject::const_iterator::operator==(const const_iterator &other) const-
1005 \fn bool QJsonObject::const_iterator::operator==(const iterator &other) const-
1006-
1007 Returns \c true if \a other points to the same item as this-
1008 iterator; otherwise returns \c false.-
1009-
1010 \sa operator!=()-
1011*/-
1012-
1013/*! \fn bool QJsonObject::const_iterator::operator!=(const const_iterator &other) const-
1014 \fn bool QJsonObject::const_iterator::operator!=(const iterator &other) const-
1015-
1016 Returns \c true if \a other points to a different item than this-
1017 iterator; otherwise returns \c false.-
1018-
1019 \sa operator==()-
1020*/-
1021-
1022/*! \fn QJsonObject::const_iterator QJsonObject::const_iterator::operator++()-
1023-
1024 The prefix ++ operator, \c{++i}, advances the iterator to the-
1025 next item in the object and returns an iterator to the new current-
1026 item.-
1027-
1028 Calling this function on QJsonObject::end() leads to undefined results.-
1029-
1030 \sa operator--()-
1031*/-
1032-
1033/*! \fn QJsonObject::const_iterator QJsonObject::const_iterator::operator++(int)-
1034-
1035 \overload-
1036-
1037 The postfix ++ operator, \c{i++}, advances the iterator to the-
1038 next item in the object and returns an iterator to the previously-
1039 current item.-
1040*/-
1041-
1042/*! \fn QJsonObject::const_iterator &QJsonObject::const_iterator::operator--()-
1043-
1044 The prefix -- operator, \c{--i}, makes the preceding item-
1045 current and returns an iterator pointing to the new current item.-
1046-
1047 Calling this function on QJsonObject::begin() leads to undefined-
1048 results.-
1049-
1050 \sa operator++()-
1051*/-
1052-
1053/*! \fn QJsonObject::const_iterator QJsonObject::const_iterator::operator--(int)-
1054-
1055 \overload-
1056-
1057 The postfix -- operator, \c{i--}, makes the preceding item-
1058 current and returns an iterator pointing to the previously-
1059 current item.-
1060*/-
1061-
1062/*! \fn QJsonObject::const_iterator QJsonObject::const_iterator::operator+(int j) const-
1063-
1064 Returns an iterator to the item at \a j positions forward from-
1065 this iterator. If \a j is negative, the iterator goes backward.-
1066-
1067 This operation can be slow for large \a j values.-
1068-
1069 \sa operator-()-
1070*/-
1071-
1072/*! \fn QJsonObject::const_iterator QJsonObject::const_iterator::operator-(int j) const-
1073-
1074 Returns an iterator to the item at \a j positions backward from-
1075 this iterator. If \a j is negative, the iterator goes forward.-
1076-
1077 This operation can be slow for large \a j values.-
1078-
1079 \sa operator+()-
1080*/-
1081-
1082/*! \fn QJsonObject::const_iterator &QJsonObject::const_iterator::operator+=(int j)-
1083-
1084 Advances the iterator by \a j items. If \a j is negative, the-
1085 iterator goes backward.-
1086-
1087 This operation can be slow for large \a j values.-
1088-
1089 \sa operator-=(), operator+()-
1090*/-
1091-
1092/*! \fn QJsonObject::const_iterator &QJsonObject::const_iterator::operator-=(int j)-
1093-
1094 Makes the iterator go back by \a j items. If \a j is negative,-
1095 the iterator goes forward.-
1096-
1097 This operation can be slow for large \a j values.-
1098-
1099 \sa operator+=(), operator-()-
1100*/-
1101-
1102-
1103/*!-
1104 \internal-
1105 */-
1106void QJsonObject::detach(uint reserve)-
1107{-
1108 Q_UNUSED(reserve)-
1109 Q_ASSERT(!reserve);-
1110 detach2(reserve);-
1111}
never executed: end of block
0
1112-
1113bool QJsonObject::detach2(uint reserve)-
1114{-
1115 if (!d) {
!dDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QMetaType
FALSEevaluated 6 times by 1 test
Evaluated by:
  • tst_QMetaType
2-6
1116 if (reserve >= QJsonPrivate::Value::MaxSize) {
reserve >= QJs...Value::MaxSizeDescription
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_QMetaType
0-2
1117 qWarning("QJson: Document too large to store in data structure");-
1118 return false;
never executed: return false;
0
1119 }-
1120 d = new QJsonPrivate::Data(reserve, QJsonValue::Object);-
1121 o = static_cast<QJsonPrivate::Object *>(d->header->root());-
1122 d->ref.ref();-
1123 return true;
executed 2 times by 1 test: return true;
Executed by:
  • tst_QMetaType
2
1124 }-
1125 if (reserve == 0 && d->ref.load() == 1)
reserve == 0Description
TRUEnever evaluated
FALSEevaluated 6 times by 1 test
Evaluated by:
  • tst_QMetaType
d->ref.load() == 1Description
TRUEnever evaluated
FALSEnever evaluated
0-6
1126 return true;
never executed: return true;
0
1127-
1128 QJsonPrivate::Data *x = d->clone(o, reserve);-
1129 if (!x)
!xDescription
TRUEnever evaluated
FALSEevaluated 6 times by 1 test
Evaluated by:
  • tst_QMetaType
0-6
1130 return false;
never executed: return false;
0
1131 x->ref.ref();-
1132 if (!d->ref.deref())
!d->ref.deref()Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QMetaType
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_QMetaType
2-4
1133 delete d;
executed 2 times by 1 test: delete d;
Executed by:
  • tst_QMetaType
2
1134 d = x;-
1135 o = static_cast<QJsonPrivate::Object *>(d->header->root());-
1136 return true;
executed 6 times by 1 test: return true;
Executed by:
  • tst_QMetaType
6
1137}-
1138-
1139/*!-
1140 \internal-
1141 */-
1142void QJsonObject::compact()-
1143{-
1144 if (!d || !d->compactionCounter)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
!d->compactionCounterDescription
TRUEnever evaluated
FALSEnever evaluated
0
1145 return;
never executed: return;
0
1146-
1147 detach2();-
1148 d->compact();-
1149 o = static_cast<QJsonPrivate::Object *>(d->header->root());-
1150}
never executed: end of block
0
1151-
1152/*!-
1153 \internal-
1154 */-
1155QString QJsonObject::keyAt(int i) const-
1156{-
1157 Q_ASSERT(o && i >= 0 && i < (int)o->length);-
1158-
1159 QJsonPrivate::Entry *e = o->entryAt(i);-
1160 return e->key();
never executed: return e->key();
0
1161}-
1162-
1163/*!-
1164 \internal-
1165 */-
1166QJsonValue QJsonObject::valueAt(int i) const-
1167{-
1168 if (!o || i < 0 || i >= (int)o->length)
!oDescription
TRUEnever evaluated
FALSEnever evaluated
i < 0Description
TRUEnever evaluated
FALSEnever evaluated
i >= (int)o->lengthDescription
TRUEnever evaluated
FALSEnever evaluated
0
1169 return QJsonValue(QJsonValue::Undefined);
never executed: return QJsonValue(QJsonValue::Undefined);
0
1170-
1171 QJsonPrivate::Entry *e = o->entryAt(i);-
1172 return QJsonValue(d, o, e->value);
never executed: return QJsonValue(d, o, e->value);
0
1173}-
1174-
1175/*!-
1176 \internal-
1177 */-
1178void QJsonObject::setValueAt(int i, const QJsonValue &val)-
1179{-
1180 Q_ASSERT(o && i >= 0 && i < (int)o->length);-
1181-
1182 QJsonPrivate::Entry *e = o->entryAt(i);-
1183 insert(e->key(), val);-
1184}
never executed: end of block
0
1185-
1186#if !defined(QT_NO_DEBUG_STREAM) && !defined(QT_JSON_READONLY)-
1187QDebug operator<<(QDebug dbg, const QJsonObject &o)-
1188{-
1189 QDebugStateSaver saver(dbg);-
1190 if (!o.o) {
!o.oDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QVariant
FALSEnever evaluated
0-1
1191 dbg << "QJsonObject()";-
1192 return dbg;
executed 1 time by 1 test: return dbg;
Executed by:
  • tst_QVariant
1
1193 }-
1194 QByteArray json;-
1195 QJsonPrivate::Writer::objectToJson(o.o, json, 0, true);-
1196 dbg.nospace() << "QJsonObject("-
1197 << json.constData() // print as utf-8 string without extra quotation marks-
1198 << ")";-
1199 return dbg;
never executed: return dbg;
0
1200}-
1201#endif-
1202-
1203QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9