Add equality comparison between QJsonObject and QJsonValueConstRef

- amends 839cffd5212cc1437661e9c650eb2ff4b19fa4e8

Fixes: QTBUG-123927
Change-Id: I9174e747478937d4c9ed6522dd603fea50daf203
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
This commit is contained in:
Tatiana Borisova 2024-04-02 17:31:01 +02:00 committed by Ivan Solovev
parent f62a6ac874
commit faaee82129
3 changed files with 10 additions and 1 deletions

View File

@ -32,7 +32,7 @@ QT_BEGIN_NAMESPACE
\brief The QJsonObject class encapsulates a JSON object.
\compares equality
\compareswith equality QJsonValue
\compareswith equality QJsonValue QJsonValueConstRef
\endcompareswith
A JSON object is a list of key value pairs, where the keys are unique strings

View File

@ -244,8 +244,14 @@ private:
{
return comparesEqual(lhs, rhs.toObject());
}
friend bool comparesEqual(const QJsonObject &lhs,
const QJsonValueConstRef &rhs) noexcept
{
return comparesEqual(lhs, rhs.toObject());
}
Q_DECLARE_EQUALITY_COMPARABLE(QJsonObject)
Q_DECLARE_EQUALITY_COMPARABLE(QJsonObject, QJsonValue)
Q_DECLARE_EQUALITY_COMPARABLE(QJsonObject, QJsonValueConstRef)
friend class QJsonValue;
friend class QJsonDocument;
friend class QJsonPrivate::Value;

View File

@ -187,6 +187,8 @@ void tst_QtJson::compareCompiles()
QTestPrivate::testEqualityOperatorsCompile<QJsonValueRef>();
QTestPrivate::testEqualityOperatorsCompile<QJsonArray, QJsonValue>();
QTestPrivate::testEqualityOperatorsCompile<QJsonObject, QJsonValue>();
QTestPrivate::testEqualityOperatorsCompile<QJsonObject, QJsonValueConstRef>();
QTestPrivate::testEqualityOperatorsCompile<QJsonObject, QJsonValueRef>();
QTestPrivate::testEqualityOperatorsCompile<QJsonValueConstRef, QJsonValue>();
QTestPrivate::testEqualityOperatorsCompile<QJsonValueRef, QJsonValue>();
QTestPrivate::testEqualityOperatorsCompile<QJsonValueRef, QJsonValueConstRef>();
@ -670,6 +672,7 @@ void tst_QtJson::testObjectInsertCopies()
QCOMPARE(obj.size(), 2);
QCOMPARE(obj.value("value"), "TEST");
QCOMPARE(obj.value("prop2"), "TEST");
QT_TEST_EQUALITY_OPS(rv, obj["value"].toObject(), true);
}
{
QJsonObject obj;