summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Ham <christopher.ham@nokia.com>2011-01-28 05:57:12 (GMT)
committerChristopher Ham <christopher.ham@nokia.com>2011-01-28 06:01:20 (GMT)
commit281f449dfcb533448c0f2df955b4f5c059db7ba2 (patch)
tree6c199e8e6eae964e2f22bbcb402363effdbbebbc
parentfeabbd82912ff39b42d02ee669aefd93a81eed11 (diff)
downloadQt-281f449dfcb533448c0f2df955b4f5c059db7ba2.zip
Qt-281f449dfcb533448c0f2df955b4f5c059db7ba2.tar.gz
Qt-281f449dfcb533448c0f2df955b4f5c059db7ba2.tar.bz2
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
-rw-r--r--src/declarative/qml/qdeclarativecomponent.cpp6
-rw-r--r--tests/auto/declarative/qdeclarativecomponent/data/createObjectWithScript.qml2
-rw-r--r--tests/auto/declarative/qdeclarativecomponent/tst_qdeclarativecomponent.cpp2
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 <QtDeclarative/qdeclarativeengine.h>
#include <QtDeclarative/qdeclarativecomponent.h>
#include <QtDeclarative/qdeclarativeitem.h>
+#include <QtDeclarative/qdeclarativeproperty.h>
#include <qcolor.h>
#ifdef Q_OS_SYMBIAN
@@ -135,6 +136,7 @@ void tst_qdeclarativecomponent::qmlCreateObjectWithProperties()
QCOMPARE(testObject1->property("x").value<int>(), 17);
QCOMPARE(testObject1->property("y").value<int>(), 17);
QCOMPARE(testObject1->property("color").value<QColor>(), QColor(255,255,255));
+ QCOMPARE(QDeclarativeProperty::read(testObject1,"border.width").toInt(), 3);
delete testObject1;
QObject *testObject2 = object->property("declarativeitem").value<QObject*>();