diff options
-rw-r--r-- | src/qml/compiler/qqmltypecompiler.cpp | 7 | ||||
-rw-r--r-- | tests/auto/qml/qqmllanguage/data/customParserProperties.qml | 7 | ||||
-rw-r--r-- | tests/auto/qml/qqmllanguage/testtypes.cpp | 16 | ||||
-rw-r--r-- | tests/auto/qml/qqmllanguage/testtypes.h | 27 | ||||
-rw-r--r-- | tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp | 15 |
5 files changed, 66 insertions, 6 deletions
diff --git a/src/qml/compiler/qqmltypecompiler.cpp b/src/qml/compiler/qqmltypecompiler.cpp index 9e2ab9e046..26f6e0b74f 100644 --- a/src/qml/compiler/qqmltypecompiler.cpp +++ b/src/qml/compiler/qqmltypecompiler.cpp @@ -1753,11 +1753,6 @@ bool QQmlPropertyValidator::validateObject(int objectIndex, const QV4::CompiledD customBindings << binding; customParserBindings.setBit(i); continue; - } else if (binding->type == QV4::CompiledData::Binding::Type_Object - || binding->type == QV4::CompiledData::Binding::Type_GroupProperty) { - customBindings << binding; - customParserBindings.setBit(i); - continue; } } @@ -1808,7 +1803,7 @@ bool QQmlPropertyValidator::validateObject(int objectIndex, const QV4::CompiledD bool seenSubObjectWithId = false; - if (binding->type >= QV4::CompiledData::Binding::Type_Object) { + if (binding->type >= QV4::CompiledData::Binding::Type_Object && !customParser) { qSwap(_seenObjectWithId, seenSubObjectWithId); const bool subObjectValid = validateObject(binding->value.objectIndex, binding, pd && QQmlValueTypeFactory::valueType(pd->propType)); qSwap(_seenObjectWithId, seenSubObjectWithId); diff --git a/tests/auto/qml/qqmllanguage/data/customParserProperties.qml b/tests/auto/qml/qqmllanguage/data/customParserProperties.qml new file mode 100644 index 0000000000..5d72edb8e5 --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/customParserProperties.qml @@ -0,0 +1,7 @@ +import Test 1.0 +import QtQml 2.0 +SimpleObjectWithCustomParser { + intProperty: 42 + property string qmlString: "Hello" + property var someObject: QtObject {} +} diff --git a/tests/auto/qml/qqmllanguage/testtypes.cpp b/tests/auto/qml/qqmllanguage/testtypes.cpp index c37845840b..6dd7fca77e 100644 --- a/tests/auto/qml/qqmllanguage/testtypes.cpp +++ b/tests/auto/qml/qqmllanguage/testtypes.cpp @@ -92,6 +92,7 @@ void registerTypes() qmlRegisterType<MyCreateableDerivedClass,1>("Test", 1, 1, "MyCreateableDerivedClass"); qmlRegisterCustomType<CustomBinding>("Test", 1, 0, "CustomBinding", new CustomBindingParser); + qmlRegisterCustomType<SimpleObjectWithCustomParser>("Test", 1, 0, "SimpleObjectWithCustomParser", new SimpleObjectCustomParser); qmlRegisterType<RootObjectInCreationTester>("Test", 1, 0, "RootObjectInCreationTester"); } @@ -191,3 +192,18 @@ QByteArray EnumSupportingCustomParser::compile(const QV4::CompiledData::QmlUnit return QByteArray(); } + + +QByteArray SimpleObjectCustomParser::compile(const QV4::CompiledData::QmlUnit *, int, const QList<const QV4::CompiledData::Binding *> &bindings) +{ + return QByteArray::number(bindings.count()); +} + +void SimpleObjectCustomParser::setCustomData(QObject *object, const QByteArray &data) +{ + SimpleObjectWithCustomParser *o = qobject_cast<SimpleObjectWithCustomParser*>(object); + Q_ASSERT(o); + bool ok = false; + o->setCustomBindingsCount(data.toInt(&ok)); + Q_ASSERT(ok); +} diff --git a/tests/auto/qml/qqmllanguage/testtypes.h b/tests/auto/qml/qqmllanguage/testtypes.h index 6ed363e363..a8605da651 100644 --- a/tests/auto/qml/qqmllanguage/testtypes.h +++ b/tests/auto/qml/qqmllanguage/testtypes.h @@ -1104,6 +1104,33 @@ class CustomBindingParser : public QQmlCustomParser virtual void setCustomData(QObject *object, const QByteArray &data); }; +class SimpleObjectWithCustomParser : public QObject +{ + Q_OBJECT + Q_PROPERTY(int intProperty READ intProperty WRITE setIntProperty) +public: + SimpleObjectWithCustomParser() + : m_intProperty(0) + , m_customBindingsCount(0) + {} + + int intProperty() const { return m_intProperty; } + void setIntProperty(int value) { m_intProperty = value; } + + void setCustomBindingsCount(int count) { m_customBindingsCount = count; } + int customBindingsCount() const { return m_customBindingsCount; } + +private: + int m_intProperty; + int m_customBindingsCount; +}; + +class SimpleObjectCustomParser : public QQmlCustomParser +{ + virtual QByteArray compile(const QV4::CompiledData::QmlUnit *, int, const QList<const QV4::CompiledData::Binding *> &bindings); + virtual void setCustomData(QObject *object, const QByteArray &data); +}; + class RootObjectInCreationTester : public QObject { Q_OBJECT diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp index e5c86e744d..619c7719f6 100644 --- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp +++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp @@ -229,6 +229,7 @@ private slots: void customParserBindingScopes(); void customParserEvaluateEnum(); + void customParserProperties(); void preservePropertyCacheOnGroupObjects(); void propertyCacheInSync(); @@ -3598,6 +3599,20 @@ void tst_qqmllanguage::customParserEvaluateEnum() QVERIFY(!o.isNull()); } +void tst_qqmllanguage::customParserProperties() +{ + QQmlComponent component(&engine, testFile("customParserProperties.qml")); + VERIFY_ERRORS(0); + QScopedPointer<QObject> o(component.create()); + QVERIFY(!o.isNull()); + SimpleObjectWithCustomParser *testObject = qobject_cast<SimpleObjectWithCustomParser*>(o.data()); + QVERIFY(testObject); + QCOMPARE(testObject->customBindingsCount(), 0); + QCOMPARE(testObject->intProperty(), 42); + QCOMPARE(testObject->property("qmlString").toString(), QStringLiteral("Hello")); + QVERIFY(!testObject->property("someObject").isNull()); +} + void tst_qqmllanguage::preservePropertyCacheOnGroupObjects() { QQmlComponent component(&engine, testFile("preservePropertyCacheOnGroupObjects.qml")); |