From 11db0632758db443c3fb336dae23da83a358e73d Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Thu, 21 Jan 2010 13:40:03 +1000 Subject: Allow composite value sources --- src/declarative/qml/qmlcompiler.cpp | 6 ++--- .../qmllanguage/data/MyCompositeValueSource.qml | 6 +++++ .../qmllanguage/data/propertyValueSource.2.qml | 5 +++++ .../declarative/qmllanguage/tst_qmllanguage.cpp | 26 ++++++++++++++++++++-- 4 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 tests/auto/declarative/qmllanguage/data/MyCompositeValueSource.qml create mode 100644 tests/auto/declarative/qmllanguage/data/propertyValueSource.2.qml diff --git a/src/declarative/qml/qmlcompiler.cpp b/src/declarative/qml/qmlcompiler.cpp index 4ee59b3..fedc1ee 100644 --- a/src/declarative/qml/qmlcompiler.cpp +++ b/src/declarative/qml/qmlcompiler.cpp @@ -1610,7 +1610,7 @@ void QmlCompiler::genPropertyAssignment(QmlParser::Property *prop, store.assignValueSource.property = genPropertyData(prop); store.assignValueSource.owner = 0; } - QmlType *valueType = QmlMetaType::qmlType(v->object->metatype); + QmlType *valueType = toQmlType(v->object); store.assignValueSource.castValue = valueType->propertyValueSourceCast(); output->bytecode << store; @@ -1627,7 +1627,7 @@ void QmlCompiler::genPropertyAssignment(QmlParser::Property *prop, store.assignValueInterceptor.property = genPropertyData(prop); store.assignValueInterceptor.owner = 0; } - QmlType *valueType = QmlMetaType::qmlType(v->object->metatype); + QmlType *valueType = toQmlType(v->object); store.assignValueInterceptor.castValue = valueType->propertyValueInterceptorCast(); output->bytecode << store; @@ -1995,7 +1995,7 @@ bool QmlCompiler::buildPropertyObjectAssignment(QmlParser::Property *prop, bool isPropertyValue = false; // Will be true if the assigned type inherits QmlPropertyValueInterceptor bool isPropertyInterceptor = false; - if (QmlType *valueType = QmlMetaType::qmlType(v->object->metatype)) { + if (QmlType *valueType = toQmlType(v->object)) { isPropertyValue = valueType->propertyValueSourceCast() != -1; isPropertyInterceptor = valueType->propertyValueInterceptorCast() != -1; } diff --git a/tests/auto/declarative/qmllanguage/data/MyCompositeValueSource.qml b/tests/auto/declarative/qmllanguage/data/MyCompositeValueSource.qml new file mode 100644 index 0000000..e620e26 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/MyCompositeValueSource.qml @@ -0,0 +1,6 @@ +import Test 1.0 + +MyPropertyValueSource { + property int x +} + diff --git a/tests/auto/declarative/qmllanguage/data/propertyValueSource.2.qml b/tests/auto/declarative/qmllanguage/data/propertyValueSource.2.qml new file mode 100644 index 0000000..57a6070 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/propertyValueSource.2.qml @@ -0,0 +1,5 @@ +import Test 1.0 +MyTypeObject { + intProperty : MyCompositeValueSource {} +} + diff --git a/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp b/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp index 976dc76..0a636db 100644 --- a/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp +++ b/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp @@ -650,6 +650,7 @@ void tst_qmllanguage::autoComponentCreation() void tst_qmllanguage::propertyValueSource() { + { QmlComponent component(&engine, TEST_FILE("propertyValueSource.qml")); VERIFY_ERRORS(0); MyTypeObject *object = qobject_cast(component.create()); @@ -658,8 +659,7 @@ void tst_qmllanguage::propertyValueSource() QList valueSources; QObjectList allChildren = object->findChildren(); foreach (QObject *child, allChildren) { - QmlType *type = QmlMetaType::qmlType(child->metaObject()); - if (type && type->propertyValueSourceCast() != -1) + if (qobject_cast(child)) valueSources.append(child); } @@ -669,6 +669,28 @@ void tst_qmllanguage::propertyValueSource() QVERIFY(valueSource != 0); QCOMPARE(valueSource->prop.object(), object); QCOMPARE(valueSource->prop.name(), QString(QLatin1String("intProperty"))); + } + + { + QmlComponent component(&engine, TEST_FILE("propertyValueSource.2.qml")); + VERIFY_ERRORS(0); + MyTypeObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + + QList valueSources; + QObjectList allChildren = object->findChildren(); + foreach (QObject *child, allChildren) { + if (qobject_cast(child)) + valueSources.append(child); + } + + QCOMPARE(valueSources.count(), 1); + MyPropertyValueSource *valueSource = + qobject_cast(valueSources.at(0)); + QVERIFY(valueSource != 0); + QCOMPARE(valueSource->prop.object(), object); + QCOMPARE(valueSource->prop.name(), QString(QLatin1String("intProperty"))); + } } void tst_qmllanguage::attachedProperties() -- cgit v0.12