From 281f449dfcb533448c0f2df955b4f5c059db7ba2 Mon Sep 17 00:00:00 2001 From: Christopher Ham Date: Fri, 28 Jan 2011 15:57:12 +1000 Subject: Adding support for group properties in Component::CreateObject() The QScriptValue overload for Component::CreateObject() should be able to set group properties. This change also allows for property binding from Javascript to continue to function. Task-number: QTBUG-13087 Reviewed-by: Bea Lam --- src/declarative/qml/qdeclarativecomponent.cpp | 6 +++++- .../qdeclarativecomponent/data/createObjectWithScript.qml | 2 +- .../declarative/qdeclarativecomponent/tst_qdeclarativecomponent.cpp | 2 ++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/declarative/qml/qdeclarativecomponent.cpp b/src/declarative/qml/qdeclarativecomponent.cpp index b634a7a..06bf3fd 100644 --- a/src/declarative/qml/qdeclarativecomponent.cpp +++ b/src/declarative/qml/qdeclarativecomponent.cpp @@ -715,7 +715,11 @@ QScriptValue QDeclarativeComponentPrivate::createObject(QObject *publicParent, c QScriptValueIterator it(valuemap); while (it.hasNext()) { it.next(); - newObject.setProperty(it.name(), it.value(), QScriptValue::KeepExistingFlags); + if (it.value().isFunction()) { // To allow property binding from javascript to work + newObject.setProperty(it.name(), it.value()); + } else { + QDeclarativeProperty::write(ret,it.name(),it.value().toVariant()); + } } } diff --git a/tests/auto/declarative/qdeclarativecomponent/data/createObjectWithScript.qml b/tests/auto/declarative/qdeclarativecomponent/data/createObjectWithScript.qml index 6f9ddc1..2ce76ed 100644 --- a/tests/auto/declarative/qdeclarativecomponent/data/createObjectWithScript.qml +++ b/tests/auto/declarative/qdeclarativecomponent/data/createObjectWithScript.qml @@ -29,7 +29,7 @@ Item{ } Component.onCompleted: { - root.declarativerectangle = a.createObject(root, {"x":17,"y":17, "color":"white"}); + root.declarativerectangle = a.createObject(root, {"x":17,"y":17, "color":"white", "border.width":3}); root.declarativeitem = b.createObject(root, {"x":17,"y":17,"testBool":true,"testInt":17,"testObject":root}); root.bindingTestObject = c.createObject(root, {'testValue': (function(){return width * 3}) }) // use root.width diff --git a/tests/auto/declarative/qdeclarativecomponent/tst_qdeclarativecomponent.cpp b/tests/auto/declarative/qdeclarativecomponent/tst_qdeclarativecomponent.cpp index 62c6bb5..7b7b392 100644 --- a/tests/auto/declarative/qdeclarativecomponent/tst_qdeclarativecomponent.cpp +++ b/tests/auto/declarative/qdeclarativecomponent/tst_qdeclarativecomponent.cpp @@ -45,6 +45,7 @@ #include #include #include +#include #include #ifdef Q_OS_SYMBIAN @@ -135,6 +136,7 @@ void tst_qdeclarativecomponent::qmlCreateObjectWithProperties() QCOMPARE(testObject1->property("x").value(), 17); QCOMPARE(testObject1->property("y").value(), 17); QCOMPARE(testObject1->property("color").value(), QColor(255,255,255)); + QCOMPARE(QDeclarativeProperty::read(testObject1,"border.width").toInt(), 3); delete testObject1; QObject *testObject2 = object->property("declarativeitem").value(); -- cgit v0.12