diff options
Diffstat (limited to 'src/corelib/serialization/qjsonobject.cpp')
-rw-r--r-- | src/corelib/serialization/qjsonobject.cpp | 321 |
1 files changed, 138 insertions, 183 deletions
diff --git a/src/corelib/serialization/qjsonobject.cpp b/src/corelib/serialization/qjsonobject.cpp index a06af5d02d..2f61de0824 100644 --- a/src/corelib/serialization/qjsonobject.cpp +++ b/src/corelib/serialization/qjsonobject.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include <qjsonobject.h> #include <qjsonvalue.h> @@ -45,6 +9,8 @@ #include <qdebug.h> #include <qvariant.h> #include <qcbormap.h> +#include <qmap.h> +#include <qhash.h> #include <private/qcborvalue_p.h> #include "qjsonwriter_p.h" @@ -59,11 +25,16 @@ QT_BEGIN_NAMESPACE \inmodule QtCore \ingroup json \ingroup shared + \ingroup qtserialization \reentrant \since 5.0 \brief The QJsonObject class encapsulates a JSON object. + \compares equality + \compareswith equality QJsonValue QJsonValueConstRef + \endcompareswith + A JSON object is a list of key value pairs, where the keys are unique strings and the values are represented by a QJsonValue. @@ -76,7 +47,7 @@ QT_BEGIN_NAMESPACE You can convert the object to and from text based JSON through QJsonDocument. - \sa {JSON Support in Qt}, {JSON Save Game Example} + \sa {JSON Support in Qt}, {Saving and Loading a Game} */ /*! @@ -118,7 +89,7 @@ QT_BEGIN_NAMESPACE QJsonObject::QJsonObject() = default; /*! - \fn QJsonObject::QJsonObject(std::initializer_list<QPair<QString, QJsonValue> > args) + \fn QJsonObject::QJsonObject(std::initializer_list<std::pair<QString, QJsonValue> > args) \since 5.4 Constructs a QJsonObject instance initialized from \a args initialization list. For example: @@ -137,7 +108,6 @@ QJsonObject::QJsonObject() = default; QJsonObject::QJsonObject(QCborContainerPrivate *object) : o(object) { - Q_ASSERT(o); } /*! @@ -145,7 +115,7 @@ QJsonObject::QJsonObject(QCborContainerPrivate *object) */ QJsonObject::~QJsonObject() = default; -QJsonObject::QJsonObject(std::initializer_list<QPair<QString, QJsonValue> > args) +QJsonObject::QJsonObject(std::initializer_list<std::pair<QString, QJsonValue> > args) { for (const auto &arg : args) insert(arg.first, arg.second); @@ -157,11 +127,13 @@ QJsonObject::QJsonObject(std::initializer_list<QPair<QString, QJsonValue> > args Since QJsonObject is implicitly shared, the copy is shallow as long as the object does not get modified. */ -QJsonObject::QJsonObject(const QJsonObject &other) -{ - o = other.o; -} +QJsonObject::QJsonObject(const QJsonObject &other) noexcept = default; + +/*! + \since 5.10 + Move-constructs a QJsonObject from \a other. +*/ QJsonObject::QJsonObject(QJsonObject &&other) noexcept : o(other.o) { @@ -171,18 +143,8 @@ QJsonObject::QJsonObject(QJsonObject &&other) noexcept /*! Assigns \a other to this object. */ -QJsonObject &QJsonObject::operator =(const QJsonObject &other) -{ - o = other.o; - return *this; -} +QJsonObject &QJsonObject::operator =(const QJsonObject &other) noexcept = default; -/*! - \fn QJsonObject::QJsonObject(QJsonObject &&other) - \since 5.10 - - Move-constructs a QJsonObject from \a other. -*/ /*! \fn QJsonObject &QJsonObject::operator =(QJsonObject &&other) @@ -198,7 +160,7 @@ QJsonObject &QJsonObject::operator =(const QJsonObject &other) Swaps the object \a other with this. This operation is very fast and never fails. */ - +#ifndef QT_NO_VARIANT /*! Converts the variant map \a map to a QJsonObject. @@ -261,18 +223,19 @@ QVariantHash QJsonObject::toVariantHash() const { return QCborMap::fromJsonObject(*this).toVariantHash(); } +#endif // !QT_NO_VARIANT /*! Returns a list of all keys in this object. - The list is sorted lexographically. + The list is sorted alphabetically. */ QStringList QJsonObject::keys() const { QStringList keys; if (o) { - keys.reserve(o->elements.length() / 2); - for (qsizetype i = 0, end = o->elements.length(); i < end; i += 2) + keys.reserve(o->elements.size() / 2); + for (qsizetype i = 0, end = o->elements.size(); i < end; i += 2) keys.append(o->stringAt(i)); } return keys; @@ -283,7 +246,7 @@ QStringList QJsonObject::keys() const */ qsizetype QJsonObject::size() const { - return o ? o->elements.length() / 2 : 0; + return o ? o->elements.size() / 2 : 0; } /*! @@ -306,14 +269,13 @@ static qsizetype indexOf(const QExplicitlySharedDataPointer<QCborContainerPrivat const auto it = std::lower_bound( begin, end, key, [&](const QJsonPrivate::ConstKeyIterator::value_type &e, const String &key) { - return o->stringCompareElement(e.key(), key) < 0; + return o->stringCompareElement(e.key(), key, QtCbor::Comparison::ForOrdering) < 0; }); *keyExists = (it != end) && o->stringEqualsElement((*it).key(), key); - return (it - begin) * 2; + return it.it - begin.it; } -#if QT_STRINGVIEW_LEVEL < 2 /*! Returns a QJsonValue representing the value for the key \a key. @@ -325,7 +287,6 @@ QJsonValue QJsonObject::value(const QString &key) const { return value(QStringView(key)); } -#endif /*! \overload @@ -340,7 +301,7 @@ QJsonValue QJsonObject::value(QStringView key) const \overload \since 5.7 */ -QJsonValue QJsonObject::value(QLatin1String key) const +QJsonValue QJsonObject::value(QLatin1StringView key) const { return valueImpl(key); } @@ -361,7 +322,6 @@ QJsonValue QJsonObject::valueImpl(T key) const return QJsonPrivate::Value::fromTrustedCbor(o->valueAt(i + 1)); } -#if QT_STRINGVIEW_LEVEL < 2 /*! Returns a QJsonValue representing the value for the key \a key. @@ -375,7 +335,6 @@ QJsonValue QJsonObject::operator [](const QString &key) const { return (*this)[QStringView(key)]; } -#endif /*! \fn QJsonValue QJsonObject::operator [](QStringView key) const @@ -385,13 +344,12 @@ QJsonValue QJsonObject::operator [](const QString &key) const */ /*! - \fn QJsonValue QJsonObject::operator [](QLatin1String key) const + \fn QJsonValue QJsonObject::operator [](QLatin1StringView key) const \overload \since 5.7 */ -#if QT_STRINGVIEW_LEVEL < 2 /*! Returns a reference to the value for \a key. If there is no value with key \a key in the object, one is created with a QJsonValue::Null value and then @@ -409,7 +367,6 @@ QJsonValueRef QJsonObject::operator [](const QString &key) { return (*this)[QStringView(key)]; } -#endif /*! \overload @@ -424,7 +381,7 @@ QJsonValueRef QJsonObject::operator [](QStringView key) \overload \since 5.7 */ -QJsonValueRef QJsonObject::operator [](QLatin1String key) +QJsonValueRef QJsonObject::operator [](QLatin1StringView key) { return atImpl(key); } @@ -441,7 +398,7 @@ QJsonValueRef QJsonObject::atImpl(T key) bool keyExists = false; auto index = indexOf(o, key, &keyExists); if (!keyExists) { - detach(o->elements.length() / 2 + 1); + detach(o->elements.size() / 2 + 1); o->insertAt(index, key); o->insertAt(index + 1, QCborValue::fromJsonValue(QJsonValue())); } @@ -449,7 +406,6 @@ QJsonValueRef QJsonObject::atImpl(T key) return QJsonValueRef(this, index / 2); } -#if QT_STRINGVIEW_LEVEL < 2 /*! Inserts a new item with the key \a key and a value of \a value. @@ -467,7 +423,6 @@ QJsonObject::iterator QJsonObject::insert(const QString &key, const QJsonValue & { return insert(QStringView(key), value); } -#endif /*! \overload @@ -482,7 +437,7 @@ QJsonObject::iterator QJsonObject::insert(QStringView key, const QJsonValue &val \overload \since 5.14 */ -QJsonObject::iterator QJsonObject::insert(QLatin1String key, const QJsonValue &value) +QJsonObject::iterator QJsonObject::insert(QLatin1StringView key, const QJsonValue &value) { return insertImpl(key, value); } @@ -509,7 +464,7 @@ template <typename T> QJsonObject::iterator QJsonObject::insertAt(qsizetype pos, T key, const QJsonValue &value, bool keyExists) { if (o) - detach(o->elements.length() / 2 + (keyExists ? 0 : 1)); + detach(o->elements.size() / 2 + (keyExists ? 0 : 1)); else o = new QCborContainerPrivate; @@ -522,7 +477,6 @@ QJsonObject::iterator QJsonObject::insertAt(qsizetype pos, T key, const QJsonVal return {this, pos / 2}; } -#if QT_STRINGVIEW_LEVEL < 2 /*! Removes \a key from the object. @@ -532,7 +486,6 @@ void QJsonObject::remove(const QString &key) { remove(QStringView(key)); } -#endif /*! \overload @@ -547,7 +500,7 @@ void QJsonObject::remove(QStringView key) \overload \since 5.14 */ -void QJsonObject::remove(QLatin1String key) +void QJsonObject::remove(QLatin1StringView key) { removeImpl(key); } @@ -566,10 +519,9 @@ void QJsonObject::removeImpl(T key) if (!keyExists) return; - removeAt(index / 2); + removeAt(index); } -#if QT_STRINGVIEW_LEVEL < 2 /*! Removes \a key from the object. @@ -583,7 +535,6 @@ QJsonValue QJsonObject::take(const QString &key) { return take(QStringView(key)); } -#endif /*! \overload @@ -598,7 +549,7 @@ QJsonValue QJsonObject::take(QStringView key) \overload \since 5.14 */ -QJsonValue QJsonObject::take(QLatin1String key) +QJsonValue QJsonObject::take(QLatin1StringView key) { return takeImpl(key); } @@ -619,11 +570,10 @@ QJsonValue QJsonObject::takeImpl(T key) detach(); const QJsonValue v = QJsonPrivate::Value::fromTrustedCbor(o->extractAt(index + 1)); - removeAt(index / 2); + removeAt(index); return v; } -#if QT_STRINGVIEW_LEVEL < 2 /*! Returns \c true if the object contains key \a key. @@ -633,7 +583,6 @@ bool QJsonObject::contains(const QString &key) const { return contains(QStringView(key)); } -#endif /*! \overload @@ -648,7 +597,7 @@ bool QJsonObject::contains(QStringView key) const \overload \since 5.7 */ -bool QJsonObject::contains(QLatin1String key) const +bool QJsonObject::contains(QLatin1StringView key) const { return containsImpl(key); } @@ -668,22 +617,24 @@ bool QJsonObject::containsImpl(T key) const } /*! - Returns \c true if \a other is equal to this object. - */ -bool QJsonObject::operator==(const QJsonObject &other) const + \fn bool QJsonObject::operator==(const QJsonObject &lhs, const QJsonObject &rhs) + + Returns \c true if \a lhs object is equal to \a rhs, \c false otherwise. +*/ +bool comparesEqual(const QJsonObject &lhs, const QJsonObject &rhs) noexcept { - if (o == other.o) + if (lhs.o == rhs.o) return true; - if (!o) - return !other.o->elements.length(); - if (!other.o) - return !o->elements.length(); - if (o->elements.length() != other.o->elements.length()) + if (!lhs.o) + return !rhs.o->elements.size(); + if (!rhs.o) + return !lhs.o->elements.size(); + if (lhs.o->elements.size() != rhs.o->elements.size()) return false; - for (qsizetype i = 0, end = o->elements.length(); i < end; ++i) { - if (o->valueAt(i) != other.o->valueAt(i)) + for (qsizetype i = 0, end = lhs.o->elements.size(); i < end; ++i) { + if (lhs.o->valueAt(i) != rhs.o->valueAt(i)) return false; } @@ -691,12 +642,10 @@ bool QJsonObject::operator==(const QJsonObject &other) const } /*! - Returns \c true if \a other is not equal to this object. - */ -bool QJsonObject::operator!=(const QJsonObject &other) const -{ - return !(*this == other); -} + \fn bool QJsonObject::operator!=(const QJsonObject &lhs, const QJsonObject &rhs) + + Returns \c true if \a lhs object is not equal to \a rhs, \c false otherwise. +*/ /*! Removes the (key, value) pair pointed to by the iterator \a it @@ -707,16 +656,14 @@ bool QJsonObject::operator!=(const QJsonObject &other) const */ QJsonObject::iterator QJsonObject::erase(QJsonObject::iterator it) { - if (it.item.o != this || qsizetype(it.item.index) >= o->elements.length()) - return {this, o->elements.length()}; - - removeAt(it.item.index); + removeAt(it.item.index * 2); - // iterator hasn't changed - return it; + // index hasn't changed; the container pointer shouldn't have changed + // because we shouldn't have detached (detaching happens on obtaining a + // non-const iterator). But just in case we did, reload the pointer. + return { this, qsizetype(it.item.index) }; } -#if QT_STRINGVIEW_LEVEL < 2 /*! Returns an iterator pointing to the item with key \a key in the map. @@ -728,7 +675,6 @@ QJsonObject::iterator QJsonObject::find(const QString &key) { return find(QStringView(key)); } -#endif /*! \overload @@ -743,7 +689,7 @@ QJsonObject::iterator QJsonObject::find(QStringView key) \overload \since 5.7 */ -QJsonObject::iterator QJsonObject::find(QLatin1String key) +QJsonObject::iterator QJsonObject::find(QLatin1StringView key) { return findImpl(key); } @@ -762,12 +708,10 @@ QJsonObject::iterator QJsonObject::findImpl(T key) return {this, index / 2}; } -#if QT_STRINGVIEW_LEVEL < 2 /*! \fn QJsonObject::const_iterator QJsonObject::find(const QString &key) const \overload */ -#endif /*! \fn QJsonObject::const_iterator QJsonObject::find(QStringView key) const @@ -775,13 +719,12 @@ QJsonObject::iterator QJsonObject::findImpl(T key) \since 5.14 */ -/*! \fn QJsonObject::const_iterator QJsonObject::find(QLatin1String key) const +/*! \fn QJsonObject::const_iterator QJsonObject::find(QLatin1StringView key) const \overload \since 5.7 */ -#if QT_STRINGVIEW_LEVEL < 2 /*! Returns a const iterator pointing to the item with key \a key in the map. @@ -793,7 +736,6 @@ QJsonObject::const_iterator QJsonObject::constFind(const QString &key) const { return constFind(QStringView(key)); } -#endif /*! \overload @@ -808,7 +750,7 @@ QJsonObject::const_iterator QJsonObject::constFind(QStringView key) const \overload \since 5.7 */ -QJsonObject::const_iterator QJsonObject::constFind(QLatin1String key) const +QJsonObject::const_iterator QJsonObject::constFind(QLatin1StringView key) const { return constFindImpl(key); } @@ -898,6 +840,10 @@ QJsonObject::const_iterator QJsonObject::constFindImpl(T key) const \brief The QJsonObject::iterator class provides an STL-style non-const iterator for QJsonObject. + \compares strong + \compareswith strong QJsonObject::const_iterator + \endcompareswith + QJsonObject::iterator allows you to iterate over a QJsonObject and to modify the value (but not the key) stored under a particular key. If you want to iterate over a const QJsonObject, you @@ -914,7 +860,7 @@ QJsonObject::const_iterator QJsonObject::constFindImpl(T key) const Multiple iterators can be used on the same object. Existing iterators will however become dangling once the object gets modified. - \sa QJsonObject::const_iterator, {JSON Support in Qt}, {JSON Save Game Example} + \sa QJsonObject::const_iterator, {JSON Support in Qt}, {Saving and Loading a Game} */ /*! \typedef QJsonObject::iterator::difference_type @@ -1003,12 +949,17 @@ QJsonObject::const_iterator QJsonObject::constFindImpl(T key) const \sa key() */ -/*! \fn QJsonValueRef *QJsonObject::iterator::operator->() const +/*! \fn QJsonValueRef *QJsonObject::iterator::operator->() Returns a pointer to a modifiable reference to the current item. */ -/*! \fn const QJsonValueRef QJsonObject::iterator::operator[](qsizetype j) +/*! \fn const QJsonValueConstRef *QJsonObject::iterator::operator->() const + + Returns a pointer to a constant reference to the current item. +*/ + +/*! \fn const QJsonValueRef QJsonObject::iterator::operator[](qsizetype j) const Returns a modifiable reference to the item at offset \a j from the item pointed to by this iterator (the item at position \c{*this + j}). @@ -1026,60 +977,60 @@ QJsonObject::const_iterator QJsonObject::constFindImpl(T key) const */ /*! - \fn bool QJsonObject::iterator::operator==(const iterator &other) const - \fn bool QJsonObject::iterator::operator==(const const_iterator &other) const + \fn bool QJsonObject::iterator::operator==(const iterator &lhs, const iterator &rhs) + \fn bool QJsonObject::iterator::operator==(const iterator &lhs, const const_iterator &rhs) - Returns \c true if \a other points to the same item as this + Returns \c true if \a lhs points to the same item as \a rhs iterator; otherwise returns \c false. \sa operator!=() */ /*! - \fn bool QJsonObject::iterator::operator!=(const iterator &other) const - \fn bool QJsonObject::iterator::operator!=(const const_iterator &other) const + \fn bool QJsonObject::iterator::operator!=(const iterator &lhs, const iterator &rhs) + \fn bool QJsonObject::iterator::operator!=(const iterator &lhs, const const_iterator &rhs) - Returns \c true if \a other points to a different item than this + Returns \c true if \a lhs points to a different item than \a rhs iterator; otherwise returns \c false. \sa operator==() */ /*! - \fn bool QJsonObject::iterator::operator<(const iterator& other) const - \fn bool QJsonObject::iterator::operator<(const const_iterator& other) const + \fn bool QJsonObject::iterator::operator<(const iterator &lhs, const iterator &rhs) + \fn bool QJsonObject::iterator::operator<(const iterator &lhs, const const_iterator &rhs) - Returns \c true if the item pointed to by this iterator is less than - the item pointed to by the \a other iterator. + Returns \c true if the item pointed to by \a lhs iterator is less than + the item pointed to by the \a rhs iterator. */ /*! - \fn bool QJsonObject::iterator::operator<=(const iterator& other) const - \fn bool QJsonObject::iterator::operator<=(const const_iterator& other) const + \fn bool QJsonObject::iterator::operator<=(const iterator &lhs, const iterator &rhs) + \fn bool QJsonObject::iterator::operator<=(const iterator &lhs, const const_iterator &rhs) - Returns \c true if the item pointed to by this iterator is less than - or equal to the item pointed to by the \a other iterator. + Returns \c true if the item pointed to by \a lhs iterator is less than + or equal to the item pointed to by the \a rhs iterator. */ /*! - \fn bool QJsonObject::iterator::operator>(const iterator& other) const - \fn bool QJsonObject::iterator::operator>(const const_iterator& other) const + \fn bool QJsonObject::iterator::operator>(const iterator &lhs, const iterator &rhs) + \fn bool QJsonObject::iterator::operator>(const iterator &lhs, const const_iterator &rhs) - Returns \c true if the item pointed to by this iterator is greater - than the item pointed to by the \a other iterator. + Returns \c true if the item pointed to by \a lhs iterator is greater + than the item pointed to by the \a rhs iterator. */ /*! - \fn bool QJsonObject::iterator::operator>=(const iterator& other) const - \fn bool QJsonObject::iterator::operator>=(const const_iterator& other) const + \fn bool QJsonObject::iterator::operator>=(const iterator &lhs, const iterator &rhs) + \fn bool QJsonObject::iterator::operator>=(const iterator &lhs, const const_iterator &rhs) - Returns \c true if the item pointed to by this iterator is greater - than or equal to the item pointed to by the \a other iterator. + Returns \c true if the item pointed to by \a lhs iterator is greater + than or equal to the item pointed to by the \a rhs iterator. */ /*! \fn QJsonObject::iterator QJsonObject::iterator::operator++() - The prefix ++ operator, \c{++i}, advances the iterator to the + The prefix \c{++} operator, \c{++i}, advances the iterator to the next item in the object and returns an iterator to the new current item. @@ -1092,14 +1043,14 @@ QJsonObject::const_iterator QJsonObject::constFindImpl(T key) const \overload - The postfix ++ operator, \c{i++}, advances the iterator to the + The postfix \c{++} operator, \c{i++}, advances the iterator to the next item in the object and returns an iterator to the previously current item. */ /*! \fn QJsonObject::iterator QJsonObject::iterator::operator--() - The prefix -- operator, \c{--i}, makes the preceding item + The prefix \c{--} operator, \c{--i}, makes the preceding item current and returns an iterator pointing to the new current item. Calling this function on QJsonObject::begin() leads to undefined @@ -1112,7 +1063,7 @@ QJsonObject::const_iterator QJsonObject::constFindImpl(T key) const \overload - The postfix -- operator, \c{i--}, makes the preceding item + The postfix \c{--} operator, \c{i--}, makes the preceding item current and returns an iterator pointing to the previously current item. */ @@ -1163,6 +1114,10 @@ QJsonObject::const_iterator QJsonObject::constFindImpl(T key) const \since 5.0 \brief The QJsonObject::const_iterator class provides an STL-style const iterator for QJsonObject. + \compares strong + \compareswith strong QJsonObject::iterator + \endcompareswith + QJsonObject::const_iterator allows you to iterate over a QJsonObject. If you want to modify the QJsonObject as you iterate over it, you must use QJsonObject::iterator instead. It is generally @@ -1179,7 +1134,7 @@ QJsonObject::const_iterator QJsonObject::constFindImpl(T key) const Multiple iterators can be used on the same object. Existing iterators will however become dangling if the object gets modified. - \sa QJsonObject::iterator, {JSON Support in Qt}, {JSON Save Game Example} + \sa QJsonObject::iterator, {JSON Support in Qt}, {Saving and Loading a Game} */ /*! \typedef QJsonObject::const_iterator::difference_type @@ -1238,14 +1193,14 @@ QJsonObject::const_iterator QJsonObject::constFindImpl(T key) const \sa value() */ -/*! \fn QJsonValueRef QJsonObject::const_iterator::value() const +/*! \fn QJsonValueConstRef QJsonObject::const_iterator::value() const Returns the current item's value. \sa key(), operator*() */ -/*! \fn const QJsonValueRef QJsonObject::const_iterator::operator*() const +/*! \fn const QJsonValueConstRef QJsonObject::const_iterator::operator*() const Returns the current item's value. @@ -1254,12 +1209,12 @@ QJsonObject::const_iterator QJsonObject::constFindImpl(T key) const \sa key() */ -/*! \fn const QJsonValueRef *QJsonObject::const_iterator::operator->() const +/*! \fn const QJsonValueConstRef *QJsonObject::const_iterator::operator->() const Returns a pointer to the current item. */ -/*! \fn const QJsonValue QJsonObject::const_iterator::operator[](qsizetype j) +/*! \fn const QJsonValueConstRef QJsonObject::const_iterator::operator[](qsizetype j) const Returns the item at offset \a j from the item pointed to by this iterator (the item at position \c{*this + j}). @@ -1271,55 +1226,53 @@ QJsonObject::const_iterator QJsonObject::constFindImpl(T key) const */ -/*! \fn bool QJsonObject::const_iterator::operator==(const const_iterator &other) const - \fn bool QJsonObject::const_iterator::operator==(const iterator &other) const +/*! \fn bool QJsonObject::const_iterator::operator==(const const_iterator &lhs, const const_iterator &rhs) - Returns \c true if \a other points to the same item as this + Returns \c true if \a lhs points to the same item as \a rhs iterator; otherwise returns \c false. \sa operator!=() */ -/*! \fn bool QJsonObject::const_iterator::operator!=(const const_iterator &other) const - \fn bool QJsonObject::const_iterator::operator!=(const iterator &other) const +/*! \fn bool QJsonObject::const_iterator::operator!=(const const_iterator &lhs, const const_iterator &rhs) - Returns \c true if \a other points to a different item than this + Returns \c true if \a lhs points to a different item than \a rhs iterator; otherwise returns \c false. \sa operator==() */ /*! - \fn bool QJsonObject::const_iterator::operator<(const const_iterator& other) const + \fn bool QJsonObject::const_iterator::operator<(const const_iterator &lhs, const const_iterator &rhs) - Returns \c true if the item pointed to by this iterator is less than - the item pointed to by the \a other iterator. + Returns \c true if the item pointed to by \a lhs iterator is less than + the item pointed to by the \a rhs iterator. */ /*! - \fn bool QJsonObject::const_iterator::operator<=(const const_iterator& other) const + \fn bool QJsonObject::const_iterator::operator<=(const const_iterator &lhs, const const_iterator &rhs) - Returns \c true if the item pointed to by this iterator is less than - or equal to the item pointed to by the \a other iterator. + Returns \c true if the item pointed to by \a lhs iterator is less than + or equal to the item pointed to by the \a rhs iterator. */ /*! - \fn bool QJsonObject::const_iterator::operator>(const const_iterator& other) const + \fn bool QJsonObject::const_iterator::operator>(const const_iterator &lhs, const const_iterator &rhs) - Returns \c true if the item pointed to by this iterator is greater - than the item pointed to by the \a other iterator. + Returns \c true if the item pointed to by \a lhs iterator is greater + than the item pointed to by the \a rhs iterator. */ /*! - \fn bool QJsonObject::const_iterator::operator>=(const const_iterator& other) const + \fn bool QJsonObject::const_iterator::operator>=(const const_iterator &lhs, const const_iterator &rhs) - Returns \c true if the item pointed to by this iterator is greater - than or equal to the item pointed to by the \a other iterator. + Returns \c true if the item pointed to by \a lhs iterator is greater + than or equal to the item pointed to by the \a rhs iterator. */ /*! \fn QJsonObject::const_iterator QJsonObject::const_iterator::operator++() - The prefix ++ operator, \c{++i}, advances the iterator to the + The prefix \c{++} operator, \c{++i}, advances the iterator to the next item in the object and returns an iterator to the new current item. @@ -1332,14 +1285,14 @@ QJsonObject::const_iterator QJsonObject::constFindImpl(T key) const \overload - The postfix ++ operator, \c{i++}, advances the iterator to the + The postfix \c{++} operator, \c{i++}, advances the iterator to the next item in the object and returns an iterator to the previously current item. */ /*! \fn QJsonObject::const_iterator &QJsonObject::const_iterator::operator--() - The prefix -- operator, \c{--i}, makes the preceding item + The prefix \c{--} operator, \c{--i}, makes the preceding item current and returns an iterator pointing to the new current item. Calling this function on QJsonObject::begin() leads to undefined @@ -1352,7 +1305,7 @@ QJsonObject::const_iterator QJsonObject::constFindImpl(T key) const \overload - The postfix -- operator, \c{i--}, makes the preceding item + The postfix \c{--} operator, \c{i--}, makes the preceding item current and returns an iterator pointing to the previously current item. */ @@ -1411,16 +1364,17 @@ bool QJsonObject::detach(qsizetype reserve) { if (!o) return true; - o = QCborContainerPrivate::detach(o.data(), reserve ? reserve * 2 : o->elements.length()); + o = QCborContainerPrivate::detach(o.data(), reserve ? reserve * 2 : o->elements.size()); return o; } +#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) && !defined(QT_BOOTSTRAPPED) /*! \internal */ QString QJsonObject::keyAt(qsizetype i) const { - Q_ASSERT(o && i >= 0 && i * 2 < o->elements.length()); + Q_ASSERT(o && i >= 0 && i * 2 < o->elements.size()); return o->stringAt(i * 2); } @@ -1429,7 +1383,7 @@ QString QJsonObject::keyAt(qsizetype i) const */ QJsonValue QJsonObject::valueAt(qsizetype i) const { - if (!o || i < 0 || 2 * i + 1 >= o->elements.length()) + if (!o || i < 0 || 2 * i + 1 >= o->elements.size()) return QJsonValue(QJsonValue::Undefined); return QJsonPrivate::Value::fromTrustedCbor(o->valueAt(2 * i + 1)); } @@ -1439,7 +1393,7 @@ QJsonValue QJsonObject::valueAt(qsizetype i) const */ void QJsonObject::setValueAt(qsizetype i, const QJsonValue &val) { - Q_ASSERT(o && i >= 0 && 2 * i + 1 < o->elements.length()); + Q_ASSERT(o && i >= 0 && 2 * i + 1 < o->elements.size()); detach(); if (val.isUndefined()) { o->removeAt(2 * i + 1); @@ -1448,6 +1402,7 @@ void QJsonObject::setValueAt(qsizetype i, const QJsonValue &val) o->replaceAt(2 * i + 1, QCborValue::fromJsonValue(val)); } } +#endif // Qt 7 /*! \internal @@ -1455,8 +1410,8 @@ void QJsonObject::setValueAt(qsizetype i, const QJsonValue &val) void QJsonObject::removeAt(qsizetype index) { detach(); - o->removeAt(2 * index + 1); - o->removeAt(2 * index); + o->removeAt(index + 1); + o->removeAt(index); } size_t qHash(const QJsonObject &object, size_t seed) |