From fe1726fd7d33a5e1bda863ca6000bc3b9806b1aa Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Thu, 22 Jan 2015 10:38:34 +0100 Subject: Document and further test that QJsonObject::keys() is sorted. Change-Id: I6b145c1240cce85ad3fea6fb90ddbed629487f83 Reviewed-by: Lars Knoll --- src/corelib/json/qjsonobject.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/corelib/json') diff --git a/src/corelib/json/qjsonobject.cpp b/src/corelib/json/qjsonobject.cpp index bc74092f59..cd68db8dc6 100644 --- a/src/corelib/json/qjsonobject.cpp +++ b/src/corelib/json/qjsonobject.cpp @@ -223,6 +223,8 @@ QVariantMap QJsonObject::toVariantMap() const /*! Returns a list of all keys in this object. + + The list is sorted lexographically. */ QStringList QJsonObject::keys() const { -- cgit v1.2.3 From 0fa7374f1dc433b6b8955cb14dabb22c10f50854 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 23 Jan 2015 14:20:02 -0800 Subject: Ensure that the binary JSON objects are actually sorted QJsonObject requires that, since it does binary searches for the keys. Change-Id: I8a7a116f51864cecb52fffff13bc24660c1cc1ac Reviewed-by: Lars Knoll --- src/corelib/json/qjson.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/corelib/json') diff --git a/src/corelib/json/qjson.cpp b/src/corelib/json/qjson.cpp index 8fa172eae8..abba1f1b49 100644 --- a/src/corelib/json/qjson.cpp +++ b/src/corelib/json/qjson.cpp @@ -200,6 +200,7 @@ bool Object::isValid() const if (tableOffset + length*sizeof(offset) > size) return false; + QString lastKey; for (uint i = 0; i < length; ++i) { offset entryOffset = table()[i]; if (entryOffset + sizeof(Entry) >= tableOffset) @@ -208,8 +209,12 @@ bool Object::isValid() const int s = e->size(); if (table()[i] + s > tableOffset) return false; + QString key = e->key(); + if (key < lastKey) + return false; if (!e->value.isValid(this)) return false; + lastKey = key; } return true; } -- cgit v1.2.3 From 1afe110b8fe6da51ec23736fa3a105013255f904 Mon Sep 17 00:00:00 2001 From: Nico Vertriest Date: Wed, 21 Jan 2015 15:42:19 +0100 Subject: Doc: corrected link/autolink issues in corelib Task-number: QTBUG-43115 Change-Id: I31da92e3a7c4dd7b75ee283dbfecd77e284978ca Reviewed-by: Martin Smith --- src/corelib/json/qjsonarray.cpp | 13 +++++++------ src/corelib/json/qjsonvalue.cpp | 18 ++++++++++++++++-- 2 files changed, 23 insertions(+), 8 deletions(-) (limited to 'src/corelib/json') diff --git a/src/corelib/json/qjsonarray.cpp b/src/corelib/json/qjsonarray.cpp index acbd7dda8f..c3420b21b2 100644 --- a/src/corelib/json/qjsonarray.cpp +++ b/src/corelib/json/qjsonarray.cpp @@ -531,8 +531,8 @@ bool QJsonArray::contains(const QJsonValue &value) const \a i must be a valid index position in the array (i.e., \c{0 <= i < size()}). - The return value is of type QJsonValueRef, a helper class for QJsonArray - and QJsonObject. When you get an object of type QJsonValueRef, you can + The return value is of type \keyword QJsonValueRef, a helper class for QJsonArray + and QJsonObject. When you get an object of type \keyword QJsonValueRef, you can use it as if it were a reference to a QJsonValue. If you assign to it, the assignment will apply to the character in the QJsonArray of QJsonObject from which you got the reference. @@ -731,13 +731,14 @@ bool QJsonArray::operator!=(const QJsonArray &other) const /*! \fn QJsonValueRef QJsonArray::iterator::operator*() const + Returns a modifiable reference to the current item. You can change the value of an item by using operator*() on the left side of an assignment. - The return value is of type QJsonValueRef, a helper class for QJsonArray - and QJsonObject. When you get an object of type QJsonValueRef, you can + The return value is of type \keyword QJsonValueRef, a helper class for QJsonArray + and QJsonObject. When you get an object of type \keyword QJsonValueRef, you can use it as if it were a reference to a QJsonValue. If you assign to it, the assignment will apply to the character in the QJsonArray of QJsonObject from which you got the reference. @@ -756,8 +757,8 @@ bool QJsonArray::operator!=(const QJsonArray &other) const This function is provided to make QJsonArray iterators behave like C++ pointers. - The return value is of type QJsonValueRef, a helper class for QJsonArray - and QJsonObject. When you get an object of type QJsonValueRef, you can + The return value is of type \keyword QJsonValueRef, a helper class for QJsonArray + and QJsonObject. When you get an object of type \keyword QJsonValueRef, you can use it as if it were a reference to a QJsonValue. If you assign to it, the assignment will apply to the character in the QJsonArray of QJsonObject from which you got the reference. diff --git a/src/corelib/json/qjsonvalue.cpp b/src/corelib/json/qjsonvalue.cpp index ac4fcb89c1..6d0b3aa5d8 100644 --- a/src/corelib/json/qjsonvalue.cpp +++ b/src/corelib/json/qjsonvalue.cpp @@ -74,6 +74,20 @@ QT_BEGIN_NAMESPACE conversions. This implies that converting to a type that is not stored in the value will return a default constructed return value. + \section1 QJsonValueRef + + QJsonValueRef is a helper class for QJsonArray and QJsonObject. + When you get an object of type QJsonValueRef, you can + use it as if it were a reference to a QJsonValue. If you assign to it, + the assignment will apply to the element in the QJsonArray or QJsonObject + from which you got the reference. + + The following methods return QJsonValueRef: + \list + \li \l {QJsonArray}::operator[](int i) + \li \l {QJsonObject}::operator[](const QString & key) const + \endlist + \sa {JSON Support in Qt}, {JSON Save Game Example} */ @@ -416,13 +430,13 @@ QJsonValue QJsonValue::fromVariant(const QVariant &variant) The QJsonValue types will be converted as follows: - \value Null {QVariant::}{QVariant()} + \value Null \l {QVariant::}{QVariant()} \value Bool QMetaType::Bool \value Double QMetaType::Double \value String QString \value Array QVariantList \value Object QVariantMap - \value Undefined {QVariant::}{QVariant()} + \value Undefined \l {QVariant::}{QVariant()} \sa fromVariant() */ -- cgit v1.2.3