summaryrefslogtreecommitdiffstats
path: root/src/corelib/serialization/qjsonvalue.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/serialization/qjsonvalue.cpp')
-rw-r--r--src/corelib/serialization/qjsonvalue.cpp50
1 files changed, 29 insertions, 21 deletions
diff --git a/src/corelib/serialization/qjsonvalue.cpp b/src/corelib/serialization/qjsonvalue.cpp
index 1cc8e71d9b..6c2656d89f 100644
--- a/src/corelib/serialization/qjsonvalue.cpp
+++ b/src/corelib/serialization/qjsonvalue.cpp
@@ -59,6 +59,10 @@ static QJsonValue::Type convertFromCborType(QCborValue::Type type) noexcept
\brief The QJsonValue class encapsulates a value in JSON.
+ \compares equality
+ \compareswith equality QJsonValueConstRef QJsonValueRef
+ \endcompareswith
+
A value in JSON can be one of 6 basic types:
JSON is a format to store structured data. It has 6 basic data types:
@@ -96,7 +100,7 @@ static QJsonValue::Type convertFromCborType(QCborValue::Type type) noexcept
\li \l {QJsonObject}::operator[](const QString & key) const
\endlist
- \sa {JSON Support in Qt}, {JSON Save Game Example}
+ \sa {JSON Support in Qt}, {Saving and Loading a Game}
*/
/*!
@@ -345,6 +349,7 @@ void QJsonValue::swap(QJsonValue &other) noexcept
error cases as e.g. accessing a non existing key in a QJsonObject.
*/
+#ifndef QT_NO_VARIANT
/*!
Converts \a variant to a QJsonValue and returns it.
@@ -587,6 +592,7 @@ QVariant QJsonValue::toVariant() const
error condition, when trying to read an out of bounds value
in an array or a non existent key in an object.
*/
+#endif // !QT_NO_VARIANT
/*!
Returns the type of the value.
@@ -821,35 +827,37 @@ const QJsonValue QJsonValue::operator[](qsizetype i) const
}
/*!
- Returns \c true if the value is equal to \a other.
- */
-bool QJsonValue::operator==(const QJsonValue &other) const
+ \fn bool QJsonValue::operator==(const QJsonValue &lhs, const QJsonValue &rhs)
+
+ Returns \c true if the \a lhs value is equal to \a rhs value, \c false otherwise.
+*/
+bool comparesEqual(const QJsonValue &lhs, const QJsonValue &rhs) noexcept
{
- if (value.type() != other.value.type()) {
- if (isDouble() && other.isDouble()) {
+ if (lhs.value.type() != rhs.value.type()) {
+ if (lhs.isDouble() && rhs.isDouble()) {
// One value Cbor integer, one Cbor double, should interact as doubles.
- return toDouble() == other.toDouble();
+ return lhs.toDouble() == rhs.toDouble();
}
return false;
}
- switch (value.type()) {
+ switch (lhs.value.type()) {
case QCborValue::Undefined:
case QCborValue::Null:
case QCborValue::True:
case QCborValue::False:
break;
case QCborValue::Double:
- return toDouble() == other.toDouble();
+ return lhs.toDouble() == rhs.toDouble();
case QCborValue::Integer:
- return QJsonPrivate::Value::valueHelper(value)
- == QJsonPrivate::Value::valueHelper(other.value);
+ return QJsonPrivate::Value::valueHelper(lhs.value)
+ == QJsonPrivate::Value::valueHelper(rhs.value);
case QCborValue::String:
- return toString() == other.toString();
+ return lhs.toString() == rhs.toString();
case QCborValue::Array:
- return toArray() == other.toArray();
+ return lhs.toArray() == rhs.toArray();
case QCborValue::Map:
- return toObject() == other.toObject();
+ return lhs.toObject() == rhs.toObject();
default:
return false;
}
@@ -857,12 +865,10 @@ bool QJsonValue::operator==(const QJsonValue &other) const
}
/*!
- Returns \c true if the value is not equal to \a other.
- */
-bool QJsonValue::operator!=(const QJsonValue &other) const
-{
- return !(*this == other);
-}
+ \fn bool QJsonValue::operator!=(const QJsonValue &lhs, const QJsonValue &rhs)
+
+ Returns \c true if the \a lhs value is not equal to \a rhs value, \c false otherwise.
+*/
/*!
\class QJsonValueRef
@@ -936,10 +942,12 @@ QJsonValueRef &QJsonValueRef::operator =(const QJsonValueRef &ref)
return assignToRef(*this, d->valueAt(index), is_object);
}
+#ifndef QT_NO_VARIANT
QVariant QJsonValueConstRef::toVariant() const
{
return concrete(*this).toVariant();
}
+#endif // !QT_NO_VARIANT
QJsonArray QJsonValueConstRef::toArray() const
{
@@ -1011,7 +1019,7 @@ QJsonValue QJsonValueConstRef::concrete(QJsonValueConstRef self) noexcept
QString QJsonValueConstRef::objectKey(QJsonValueConstRef self)
{
Q_ASSERT(self.is_object);
- Q_ASSUME(self.is_object);
+ Q_ASSERT(self.is_object);
const QCborContainerPrivate *d = QJsonPrivate::Value::container(self);
qsizetype index = QJsonPrivate::Value::indexHelper(self);