diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/corelib/compat/removed_api.cpp | 12 | ||||
| -rw-r--r-- | src/corelib/serialization/qjsonarray.cpp | 42 | ||||
| -rw-r--r-- | src/corelib/serialization/qjsonarray.h | 11 |
3 files changed, 47 insertions, 18 deletions
diff --git a/src/corelib/compat/removed_api.cpp b/src/corelib/compat/removed_api.cpp index 5dbe213cc8b..9b0dd81b30d 100644 --- a/src/corelib/compat/removed_api.cpp +++ b/src/corelib/compat/removed_api.cpp @@ -959,6 +959,18 @@ bool QFileInfo::operator==(const QFileInfo &fileinfo) const return comparesEqual(*this, fileinfo); } +#include "qjsonarray.h" + +bool QJsonArray::operator==(const QJsonArray &other) const +{ + return comparesEqual(*this, other); +} + +bool QJsonArray::operator!=(const QJsonArray &other) const +{ + return !comparesEqual(*this, other); +} + #if QT_CONFIG(processenvironment) #include "qprocess.h" // inlined API diff --git a/src/corelib/serialization/qjsonarray.cpp b/src/corelib/serialization/qjsonarray.cpp index 2a660680b94..3ed91d4d0a1 100644 --- a/src/corelib/serialization/qjsonarray.cpp +++ b/src/corelib/serialization/qjsonarray.cpp @@ -28,6 +28,10 @@ QT_BEGIN_NAMESPACE \brief The QJsonArray class encapsulates a JSON array. + \compares equality + \compareswith equality QJsonValue + \endcompareswith + A JSON array is a list of values. The list can be manipulated by inserting and removing QJsonValue's from the array. @@ -471,36 +475,40 @@ QJsonValue QJsonArray::operator[](qsizetype i) const return at(i); } -/*! - Returns \c true if this array is equal to \a other. - */ -bool QJsonArray::operator==(const QJsonArray &other) const +bool comparesEqual(const QJsonArray &lhs, const QJsonArray &rhs) noexcept { - if (a == other.a) + if (lhs.a == rhs.a) return true; - if (!a) - return !other.a->elements.size(); - if (!other.a) - return !a->elements.size(); - if (a->elements.size() != other.a->elements.size()) + if (!lhs.a) + return !rhs.a->elements.size(); + if (!rhs.a) + return !lhs.a->elements.size(); + if (lhs.a->elements.size() != rhs.a->elements.size()) return false; - for (qsizetype i = 0; i < a->elements.size(); ++i) { - if (a->valueAt(i) != other.a->valueAt(i)) + for (qsizetype i = 0; i < lhs.a->elements.size(); ++i) { + if (lhs.a->valueAt(i) != rhs.a->valueAt(i)) return false; } return true; } -/*! - Returns \c true if this array is not equal to \a other. - */ -bool QJsonArray::operator!=(const QJsonArray &other) const +bool comparesEqual(const QJsonArray &lhs, const QJsonValue &rhs) noexcept { - return !(*this == other); + return lhs == rhs.toArray(); } +/*! \fn bool QJsonArray::operator==(const QJsonArray &lhs, const QJsonArray &rhs) + + Returns \c true if \a lhs array is equal to \a rhs, \c false otherwise. +*/ + +/*! \fn bool QJsonArray::operator!=(const QJsonArray &lhs, const QJsonArray &rhs) + + Returns \c true if \a lhs array is not equal to \a rhs, \c false otherwise. +*/ + /*! \fn QJsonArray::iterator QJsonArray::begin() Returns an \l{STL-style iterators}{STL-style iterator} pointing to the first item in diff --git a/src/corelib/serialization/qjsonarray.h b/src/corelib/serialization/qjsonarray.h index af4ac9fd37e..a2baa7738cc 100644 --- a/src/corelib/serialization/qjsonarray.h +++ b/src/corelib/serialization/qjsonarray.h @@ -60,9 +60,10 @@ public: QJsonValueRef operator[](qsizetype i); QJsonValue operator[](qsizetype i) const; +#if QT_CORE_REMOVED_SINCE(6, 8) bool operator==(const QJsonArray &other) const; bool operator!=(const QJsonArray &other) const; - +#endif void swap(QJsonArray &other) noexcept { a.swap(other.a); @@ -225,6 +226,14 @@ private: friend class QCborArray; friend Q_CORE_EXPORT QDebug operator<<(QDebug, const QJsonArray &); + friend Q_CORE_EXPORT bool comparesEqual(const QJsonArray &lhs, + const QJsonArray &rhs) noexcept; + + friend Q_CORE_EXPORT bool comparesEqual(const QJsonArray &lhs, + const QJsonValue &rhs) noexcept; + Q_DECLARE_EQUALITY_COMPARABLE(QJsonArray) + Q_DECLARE_EQUALITY_COMPARABLE(QJsonArray, QJsonValue) + QJsonArray(QCborContainerPrivate *array); bool detach(qsizetype reserve = 0); |
