From cfd5a1fb4ed1c51c3dadab0c63820c625992069d Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Tue, 25 Mar 2014 16:24:03 +0100 Subject: Fix instantiation of QML list models with custom object properties When doing something like property Item blah: Item { ... } in a list model, we would erroneously pass "blah" to the custom parser of the list model, which is wrong as the binding to blah is on an existing property (not custom). For regular properties there's a code path in place to avoid passing this to the custom parser, but for sub-object bindings we'd unconditionally register it with the custom parser. This patch corrects that and also adds a unit test to verify that we don't pass any bindings to existing properties to the custom parser. Task-number: QTBUG-37795 Change-Id: I1a3091fb5fad4be08b577cf74a85f24c3ab62ef4 Reviewed-by: Lars Knoll --- tests/auto/qml/qqmllanguage/testtypes.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'tests/auto/qml/qqmllanguage/testtypes.cpp') 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("Test", 1, 1, "MyCreateableDerivedClass"); qmlRegisterCustomType("Test", 1, 0, "CustomBinding", new CustomBindingParser); + qmlRegisterCustomType("Test", 1, 0, "SimpleObjectWithCustomParser", new SimpleObjectCustomParser); qmlRegisterType("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 &bindings) +{ + return QByteArray::number(bindings.count()); +} + +void SimpleObjectCustomParser::setCustomData(QObject *object, const QByteArray &data) +{ + SimpleObjectWithCustomParser *o = qobject_cast(object); + Q_ASSERT(o); + bool ok = false; + o->setCustomBindingsCount(data.toInt(&ok)); + Q_ASSERT(ok); +} -- cgit v1.2.3