From 4d3a64c5e65a781acb4acf4ba641456da28bd1e4 Mon Sep 17 00:00:00 2001 From: Alan Alpert <416365416c@gmail.com> Date: Sun, 16 Dec 2012 21:24:14 -0800 Subject: Add Composite Types to QQmlType When a composite type is loaded from a QML file, it now generates a QQmlType entry in QQmlMetaTypeData. Change-Id: I9b127dff7955456aacb25138fa6ea8efb7bb9221 Reviewed-by: Christopher Adams Reviewed-by: Alan Alpert --- .../auto/qml/qqmllanguage/data/CompositeType5.qml | 2 + .../auto/qml/qqmllanguage/data/CompositeType6.qml | 2 + .../qqmllanguage/data/assignCompositeToType.qml | 8 +++ tests/auto/qml/qqmlmetatype/data/CompositeType.qml | 5 ++ tests/auto/qml/qqmlmetatype/data/ImplicitType.qml | 5 ++ .../qqmlmetatype/data/testImplicitComposite.qml | 3 ++ tests/auto/qml/qqmlmetatype/qqmlmetatype.pro | 3 ++ tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp | 62 +++++++++++++++++++++- 8 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 tests/auto/qml/qqmllanguage/data/CompositeType5.qml create mode 100644 tests/auto/qml/qqmllanguage/data/CompositeType6.qml create mode 100644 tests/auto/qml/qqmlmetatype/data/CompositeType.qml create mode 100644 tests/auto/qml/qqmlmetatype/data/ImplicitType.qml create mode 100644 tests/auto/qml/qqmlmetatype/data/testImplicitComposite.qml (limited to 'tests/auto/qml') diff --git a/tests/auto/qml/qqmllanguage/data/CompositeType5.qml b/tests/auto/qml/qqmllanguage/data/CompositeType5.qml new file mode 100644 index 0000000000..564468ce90 --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/CompositeType5.qml @@ -0,0 +1,2 @@ +CompositeType { +} diff --git a/tests/auto/qml/qqmllanguage/data/CompositeType6.qml b/tests/auto/qml/qqmllanguage/data/CompositeType6.qml new file mode 100644 index 0000000000..a8a2af9318 --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/CompositeType6.qml @@ -0,0 +1,2 @@ +CompositeType2 { +} diff --git a/tests/auto/qml/qqmllanguage/data/assignCompositeToType.qml b/tests/auto/qml/qqmllanguage/data/assignCompositeToType.qml index 717cd84536..4034849df8 100644 --- a/tests/auto/qml/qqmllanguage/data/assignCompositeToType.qml +++ b/tests/auto/qml/qqmllanguage/data/assignCompositeToType.qml @@ -8,6 +8,10 @@ QtObject { property QtObject myProperty4 property MyQmlObject myProperty5 property MyQmlObject myProperty6 + property CompositeType myProperty7 + property CompositeType myProperty8 + property CompositeType2 myProperty9 + property CompositeType2 myPropertyA myProperty: CompositeType {} myProperty2: CompositeType2 {} @@ -15,4 +19,8 @@ QtObject { myProperty4: CompositeType4 {} myProperty5: CompositeType2 {} myProperty6: CompositeType4 {} + myProperty7: CompositeType {} + myProperty8: CompositeType5 {} + myProperty9: CompositeType2 {} + myPropertyA: CompositeType6 {} } diff --git a/tests/auto/qml/qqmlmetatype/data/CompositeType.qml b/tests/auto/qml/qqmlmetatype/data/CompositeType.qml new file mode 100644 index 0000000000..bc2abca42b --- /dev/null +++ b/tests/auto/qml/qqmlmetatype/data/CompositeType.qml @@ -0,0 +1,5 @@ +import QtQml 2.0 + +QtObject { + property int foo +} diff --git a/tests/auto/qml/qqmlmetatype/data/ImplicitType.qml b/tests/auto/qml/qqmlmetatype/data/ImplicitType.qml new file mode 100644 index 0000000000..ca2bcef5bf --- /dev/null +++ b/tests/auto/qml/qqmlmetatype/data/ImplicitType.qml @@ -0,0 +1,5 @@ +import QtQml 2.0 + +QtObject { + property int bar +} diff --git a/tests/auto/qml/qqmlmetatype/data/testImplicitComposite.qml b/tests/auto/qml/qqmlmetatype/data/testImplicitComposite.qml new file mode 100644 index 0000000000..f838c6995f --- /dev/null +++ b/tests/auto/qml/qqmlmetatype/data/testImplicitComposite.qml @@ -0,0 +1,3 @@ +import "." + +ImplicitType{} diff --git a/tests/auto/qml/qqmlmetatype/qqmlmetatype.pro b/tests/auto/qml/qqmlmetatype/qqmlmetatype.pro index b24f006bad..a9a6a32a2b 100644 --- a/tests/auto/qml/qqmlmetatype/qqmlmetatype.pro +++ b/tests/auto/qml/qqmlmetatype/qqmlmetatype.pro @@ -3,6 +3,9 @@ TARGET = tst_qqmlmetatype SOURCES += tst_qqmlmetatype.cpp macx:CONFIG -= app_bundle +TESTDATA = data/* +include (../../shared/util.pri) + CONFIG += parallel_test QT += core-private gui-private qml-private testlib v8-private DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 diff --git a/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp b/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp index d5dd364e25..03d2f0beb0 100644 --- a/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp +++ b/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp @@ -41,12 +41,16 @@ #include #include +#include +#include +#include #include #include #include +#include "../../shared/util.h" -class tst_qqmlmetatype : public QObject +class tst_qqmlmetatype : public QQmlDataTest { Q_OBJECT public: @@ -60,6 +64,8 @@ private slots: void qmlPropertyValueInterceptorCast(); void qmlType(); void invalidQmlTypeName(); + void registrationType(); + void compositeType(); void isList(); @@ -77,6 +83,13 @@ public: }; QML_DECLARE_TYPE(TestType); +QObject *testTypeProvider(QQmlEngine *engine, QJSEngine *scriptEngine) +{ + Q_UNUSED(engine); + Q_UNUSED(scriptEngine); + return new TestType(); +} + class ParserStatusTestType : public QObject, public QQmlParserStatus { Q_OBJECT @@ -108,10 +121,19 @@ QML_DECLARE_TYPE(ValueInterceptorTestType); void tst_qqmlmetatype::initTestCase() { + QQmlDataTest::initTestCase(); qmlRegisterType("Test", 1, 0, "TestType"); + qmlRegisterSingletonType("Test", 1, 0, "TestTypeSingleton", testTypeProvider); qmlRegisterType("Test", 1, 0, "ParserStatusTestType"); qmlRegisterType("Test", 1, 0, "ValueSourceTestType"); qmlRegisterType("Test", 1, 0, "ValueInterceptorTestType"); + + QUrl testTypeUrl(testFileUrl("CompositeType.qml")); + //TODO: Replace this with public API version when added + QQmlPrivate::RegisterCompositeType regStruct = { + testTypeUrl,"Test", 1, 0, "TestTypeComposite" + }; + QQmlPrivate::qmlregister(QQmlPrivate::CompositeRegistration, ®Struct); } void tst_qqmlmetatype::qmlParserStatusCast() @@ -228,6 +250,44 @@ void tst_qqmlmetatype::defaultObject() QCOMPARE(QString(QQmlMetaType::defaultProperty(&t).name()), QString("foo")); } +void tst_qqmlmetatype::registrationType() +{ + QQmlType *type = QQmlMetaType::qmlType(QString("TestType"), QString("Test"), 1, 0); + QVERIFY(type); + QVERIFY(!type->isInterface()); + QVERIFY(!type->isSingleton()); + QVERIFY(!type->isComposite()); + + type = QQmlMetaType::qmlType(QString("TestTypeSingleton"), QString("Test"), 1, 0); + QVERIFY(type); + QVERIFY(!type->isInterface()); + QVERIFY(type->isSingleton()); + QVERIFY(!type->isComposite()); + + type = QQmlMetaType::qmlType(QString("TestTypeComposite"), QString("Test"), 1, 0); + QVERIFY(type); + QVERIFY(!type->isInterface()); + QVERIFY(!type->isSingleton()); + QVERIFY(type->isComposite()); +} + +void tst_qqmlmetatype::compositeType() +{ + QQmlEngine engine; + + //Loading the test file also loads all composite types it imports + QQmlComponent c(&engine, testFileUrl("testImplicitComposite.qml")); + QObject* obj = c.create(); + QVERIFY(obj); + + QQmlType *type = QQmlMetaType::qmlType(QString("ImplicitType"), QString(""), 1, 0); + QVERIFY(type); + QVERIFY(type->module() == QLatin1String("")); + QVERIFY(type->elementName() == QLatin1String("ImplicitType")); + QCOMPARE(type->qmlTypeName(), QLatin1String("ImplicitType")); + QCOMPARE(type->sourceUrl(), testFileUrl("ImplicitType.qml")); +} + QTEST_MAIN(tst_qqmlmetatype) #include "tst_qqmlmetatype.moc" -- cgit v1.2.3