Add QtJson types to meta-type system
Make QJsonValue, QJsonObject, QJsonArray and QJsonDocument first-class meta-types. This is an enabler for a lightweight integration with QML. Change-Id: I4725efdd2746cf97fd26d3632a99e8eee849f834 Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@nokia.com> Reviewed-by: Lars Knoll <lars.knoll@nokia.com>bb10
parent
8727db0dad
commit
83e055424a
|
|
@ -64,6 +64,10 @@
|
|||
# include "qvariant.h"
|
||||
# include "qabstractitemmodel.h"
|
||||
# include "qregularexpression.h"
|
||||
# include "qjsonvalue.h"
|
||||
# include "qjsonobject.h"
|
||||
# include "qjsonarray.h"
|
||||
# include "qjsondocument.h"
|
||||
#endif
|
||||
|
||||
#ifndef QT_NO_GEOM_VARIANT
|
||||
|
|
@ -111,6 +115,10 @@ template<> struct TypeDefinition<QBitArray> { static const bool IsAvailable = fa
|
|||
template<> struct TypeDefinition<QUrl> { static const bool IsAvailable = false; };
|
||||
template<> struct TypeDefinition<QEasingCurve> { static const bool IsAvailable = false; };
|
||||
template<> struct TypeDefinition<QModelIndex> { static const bool IsAvailable = false; };
|
||||
template<> struct TypeDefinition<QJsonValue> { static const bool IsAvailable = false; };
|
||||
template<> struct TypeDefinition<QJsonObject> { static const bool IsAvailable = false; };
|
||||
template<> struct TypeDefinition<QJsonArray> { static const bool IsAvailable = false; };
|
||||
template<> struct TypeDefinition<QJsonDocument> { static const bool IsAvailable = false; };
|
||||
#endif
|
||||
#ifdef QT_NO_REGEXP
|
||||
template<> struct TypeDefinition<QRegExp> { static const bool IsAvailable = false; };
|
||||
|
|
@ -245,6 +253,10 @@ template<> struct TypeDefinition<QRegularExpression> { static const bool IsAvail
|
|||
\value QVector4D QVector4D
|
||||
\value QQuaternion QQuaternion
|
||||
\value QEasingCurve QEasingCurve
|
||||
\value QJsonValue QJsonValue
|
||||
\value QJsonObject QJsonObject
|
||||
\value QJsonArray QJsonArray
|
||||
\value QJsonDocument QJsonDocument
|
||||
|
||||
\value User Base value for user types
|
||||
\value UnknownType This is an invalid type id. It is returned from QMetaType for types that are not registered
|
||||
|
|
@ -665,6 +677,10 @@ bool QMetaType::save(QDataStream &stream, int type, const void *data)
|
|||
case QMetaType::QObjectStar:
|
||||
case QMetaType::QWidgetStar:
|
||||
case QMetaType::QModelIndex:
|
||||
case QMetaType::QJsonValue:
|
||||
case QMetaType::QJsonObject:
|
||||
case QMetaType::QJsonArray:
|
||||
case QMetaType::QJsonDocument:
|
||||
return false;
|
||||
case QMetaType::Long:
|
||||
stream << qlonglong(*static_cast<const long *>(data));
|
||||
|
|
@ -876,6 +892,10 @@ bool QMetaType::load(QDataStream &stream, int type, void *data)
|
|||
case QMetaType::QObjectStar:
|
||||
case QMetaType::QWidgetStar:
|
||||
case QMetaType::QModelIndex:
|
||||
case QMetaType::QJsonValue:
|
||||
case QMetaType::QJsonObject:
|
||||
case QMetaType::QJsonArray:
|
||||
case QMetaType::QJsonDocument:
|
||||
return false;
|
||||
case QMetaType::Long: {
|
||||
qlonglong l;
|
||||
|
|
|
|||
|
|
@ -102,7 +102,11 @@ QT_BEGIN_NAMESPACE
|
|||
F(QUuid, 30, QUuid) \
|
||||
F(QVariant, 41, QVariant) \
|
||||
F(QModelIndex, 42, QModelIndex) \
|
||||
F(QRegularExpression, 44, QRegularExpression)
|
||||
F(QRegularExpression, 44, QRegularExpression) \
|
||||
F(QJsonValue, 45, QJsonValue) \
|
||||
F(QJsonObject, 46, QJsonObject) \
|
||||
F(QJsonArray, 47, QJsonArray) \
|
||||
F(QJsonDocument, 48, QJsonDocument) \
|
||||
|
||||
#define QT_FOR_EACH_STATIC_CORE_POINTER(F)\
|
||||
F(QObjectStar, 39, QObject*) \
|
||||
|
|
@ -196,7 +200,7 @@ public:
|
|||
QT_FOR_EACH_STATIC_TYPE(QT_DEFINE_METATYPE_ID)
|
||||
|
||||
FirstCoreType = Bool,
|
||||
LastCoreType = QRegularExpression,
|
||||
LastCoreType = QJsonDocument,
|
||||
FirstGuiType = QFont,
|
||||
LastGuiType = QPolygonF,
|
||||
FirstWidgetsType = QIcon,
|
||||
|
|
|
|||
|
|
@ -56,6 +56,10 @@
|
|||
#include "quuid.h"
|
||||
#ifndef QT_BOOTSTRAPPED
|
||||
#include "qabstractitemmodel.h"
|
||||
#include "qjsonvalue.h"
|
||||
#include "qjsonobject.h"
|
||||
#include "qjsonarray.h"
|
||||
#include "qjsondocument.h"
|
||||
#endif
|
||||
#include "private/qvariant_p.h"
|
||||
#include "qmetatype_p.h"
|
||||
|
|
@ -108,6 +112,10 @@ struct TypeDefinition {
|
|||
template<> struct TypeDefinition<QEasingCurve> { static const bool IsAvailable = false; };
|
||||
template<> struct TypeDefinition<QModelIndex> { static const bool IsAvailable = false; };
|
||||
template<> struct TypeDefinition<QRegularExpression> { static const bool IsAvailable = false; };
|
||||
template<> struct TypeDefinition<QJsonValue> { static const bool IsAvailable = false; };
|
||||
template<> struct TypeDefinition<QJsonObject> { static const bool IsAvailable = false; };
|
||||
template<> struct TypeDefinition<QJsonArray> { static const bool IsAvailable = false; };
|
||||
template<> struct TypeDefinition<QJsonDocument> { static const bool IsAvailable = false; };
|
||||
#endif
|
||||
#ifdef QT_NO_GEOM_VARIANT
|
||||
template<> struct TypeDefinition<QRect> { static const bool IsAvailable = false; };
|
||||
|
|
|
|||
|
|
@ -541,6 +541,36 @@ template<> struct TestValueFactory<QMetaType::QRegularExpression> {
|
|||
#endif
|
||||
}
|
||||
};
|
||||
template<> struct TestValueFactory<QMetaType::QJsonValue> {
|
||||
static QJsonValue *create() { return new QJsonValue(123.); }
|
||||
};
|
||||
template<> struct TestValueFactory<QMetaType::QJsonObject> {
|
||||
static QJsonObject *create() {
|
||||
QJsonObject *o = new QJsonObject();
|
||||
o->insert("a", 123.);
|
||||
o->insert("b", true);
|
||||
o->insert("c", QJsonValue::Null);
|
||||
o->insert("d", QLatin1String("ciao"));
|
||||
return o;
|
||||
}
|
||||
};
|
||||
template<> struct TestValueFactory<QMetaType::QJsonArray> {
|
||||
static QJsonArray *create() {
|
||||
QJsonArray *a = new QJsonArray();
|
||||
a->append(123.);
|
||||
a->append(true);
|
||||
a->append(QJsonValue::Null);
|
||||
a->append(QLatin1String("ciao"));
|
||||
return a;
|
||||
}
|
||||
};
|
||||
template<> struct TestValueFactory<QMetaType::QJsonDocument> {
|
||||
static QJsonDocument *create() {
|
||||
return new QJsonDocument(
|
||||
QJsonDocument::fromJson("{ 'foo': 123, 'bar': [true, null, 'ciao'] }")
|
||||
);
|
||||
}
|
||||
};
|
||||
template<> struct TestValueFactory<QMetaType::QVariant> {
|
||||
static QVariant *create() { return new QVariant(QStringList(QStringList() << "Q" << "t")); }
|
||||
};
|
||||
|
|
@ -1339,6 +1369,10 @@ struct StreamingTraits
|
|||
DECLARE_NONSTREAMABLE(void)
|
||||
DECLARE_NONSTREAMABLE(void*)
|
||||
DECLARE_NONSTREAMABLE(QModelIndex)
|
||||
DECLARE_NONSTREAMABLE(QJsonValue)
|
||||
DECLARE_NONSTREAMABLE(QJsonObject)
|
||||
DECLARE_NONSTREAMABLE(QJsonArray)
|
||||
DECLARE_NONSTREAMABLE(QJsonDocument)
|
||||
DECLARE_NONSTREAMABLE(QObject*)
|
||||
DECLARE_NONSTREAMABLE(QWidget*)
|
||||
|
||||
|
|
|
|||
|
|
@ -1643,8 +1643,8 @@ void tst_QVariant::writeToReadFromOldDataStream()
|
|||
|
||||
void tst_QVariant::checkDataStream()
|
||||
{
|
||||
QTest::ignoreMessage(QtWarningMsg, "Trying to construct an instance of an invalid type, type id: 46");
|
||||
const QByteArray settingsHex("0000002effffffffff");
|
||||
QTest::ignoreMessage(QtWarningMsg, "Trying to construct an instance of an invalid type, type id: 49");
|
||||
const QByteArray settingsHex("00000031ffffffffff");
|
||||
const QByteArray settings = QByteArray::fromHex(settingsHex);
|
||||
QDataStream in(settings);
|
||||
QVariant v;
|
||||
|
|
|
|||
Loading…
Reference in New Issue