summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Ham <christopher.ham@nokia.com>2011-01-28 06:03:22 (GMT)
committerChristopher Ham <christopher.ham@nokia.com>2011-01-28 06:03:22 (GMT)
commit74329f77d567e0b7e8cd4cab2ff6ce3f2b8892ad (patch)
tree69780dc6664a9b1f25d4d9fe1b76f66ea05a4adf
parent281f449dfcb533448c0f2df955b4f5c059db7ba2 (diff)
downloadQt-74329f77d567e0b7e8cd4cab2ff6ce3f2b8892ad.zip
Qt-74329f77d567e0b7e8cd4cab2ff6ce3f2b8892ad.tar.gz
Qt-74329f77d567e0b7e8cd4cab2ff6ce3f2b8892ad.tar.bz2
Update Docs, Examples and Demos for new CreateObject overloadable
Dynamic object in Docs explains QScriptValue argument. SameGame and Dynamic scene now make use of overloadable. Task-number: QTBUG-13087 Reviewed-by: Bea Lam
-rw-r--r--demos/declarative/samegame/SamegameCore/BoomBlock.qml2
-rw-r--r--demos/declarative/samegame/SamegameCore/Button.qml2
-rw-r--r--demos/declarative/samegame/SamegameCore/Dialog.qml2
-rwxr-xr-xdemos/declarative/samegame/SamegameCore/samegame.js11
-rw-r--r--demos/declarative/samegame/samegame.qml2
-rw-r--r--doc/src/declarative/dynamicobjects.qdoc14
-rw-r--r--doc/src/snippets/declarative/componentCreation.js6
-rw-r--r--examples/declarative/toys/dynamicscene/qml/itemCreation.js7
8 files changed, 23 insertions, 23 deletions
diff --git a/demos/declarative/samegame/SamegameCore/BoomBlock.qml b/demos/declarative/samegame/SamegameCore/BoomBlock.qml
index da51230..009aeca 100644
--- a/demos/declarative/samegame/SamegameCore/BoomBlock.qml
+++ b/demos/declarative/samegame/SamegameCore/BoomBlock.qml
@@ -39,7 +39,7 @@
**
****************************************************************************/
-import QtQuick 1.0
+import QtQuick 1.1
import Qt.labs.particles 1.0
Item {
diff --git a/demos/declarative/samegame/SamegameCore/Button.qml b/demos/declarative/samegame/SamegameCore/Button.qml
index aea4e53..b2b232c 100644
--- a/demos/declarative/samegame/SamegameCore/Button.qml
+++ b/demos/declarative/samegame/SamegameCore/Button.qml
@@ -39,7 +39,7 @@
**
****************************************************************************/
-import QtQuick 1.0
+import QtQuick 1.1
Rectangle {
id: container
diff --git a/demos/declarative/samegame/SamegameCore/Dialog.qml b/demos/declarative/samegame/SamegameCore/Dialog.qml
index b11c65c..ecac475 100644
--- a/demos/declarative/samegame/SamegameCore/Dialog.qml
+++ b/demos/declarative/samegame/SamegameCore/Dialog.qml
@@ -39,7 +39,7 @@
**
****************************************************************************/
-import QtQuick 1.0
+import QtQuick 1.1
Rectangle {
id: page
diff --git a/demos/declarative/samegame/SamegameCore/samegame.js b/demos/declarative/samegame/SamegameCore/samegame.js
index 9266767..b838790 100755
--- a/demos/declarative/samegame/SamegameCore/samegame.js
+++ b/demos/declarative/samegame/SamegameCore/samegame.js
@@ -177,18 +177,19 @@ function createBlock(column,row){
// not be ready immediately. There is a statusChanged signal on the
// component you could use if you want to wait to load remote files.
if(component.status == Component.Ready){
- var dynamicObject = component.createObject(gameCanvas);
+ var dynamicObject = component.createObject(gameCanvas,
+ {"type": Math.floor(Math.random() * 3),
+ "x": column*gameCanvas.blockSize,
+ "width": gameCanvas.blockSize,
+ "height": gameCanvas.blockSize});
if(dynamicObject == null){
console.log("error creating block");
console.log(component.errorString());
return false;
}
- dynamicObject.type = Math.floor(Math.random() * 3);
- dynamicObject.x = column*gameCanvas.blockSize;
dynamicObject.y = row*gameCanvas.blockSize;
- dynamicObject.width = gameCanvas.blockSize;
- dynamicObject.height = gameCanvas.blockSize;
dynamicObject.spawned = true;
+
board[index(column,row)] = dynamicObject;
}else{
console.log("error loading block component");
diff --git a/demos/declarative/samegame/samegame.qml b/demos/declarative/samegame/samegame.qml
index ebb8e4a..ab64156 100644
--- a/demos/declarative/samegame/samegame.qml
+++ b/demos/declarative/samegame/samegame.qml
@@ -39,7 +39,7 @@
**
****************************************************************************/
-import QtQuick 1.0
+import QtQuick 1.1
import "SamegameCore"
import "SamegameCore/samegame.js" as Logic
diff --git a/doc/src/declarative/dynamicobjects.qdoc b/doc/src/declarative/dynamicobjects.qdoc
index 073e0c4..f186dca 100644
--- a/doc/src/declarative/dynamicobjects.qdoc
+++ b/doc/src/declarative/dynamicobjects.qdoc
@@ -62,10 +62,16 @@ To dynamically load a component defined in a QML file, call the
This function takes the URL of the QML file as its only argument and creates
a \l Component object from this URL.
-Once you have a \l Component, you can call its \l {Component::createObject()}{createObject()} method to create an instance of
-the component. This function takes exactly one argument, which is the parent for the new item. Since graphical items will
-not appear on the scene without a parent, it is recommended that you set the parent this way. However, if you wish to set
-the parent later you can safely pass \c null to this function.
+Once you have a \l Component, you can call its \l {Component::createObject()}{createObject()} method to create an instance of
+the component. This function can take one or two arguments:
+\list
+\o The first is the parent for the new item. Since graphical items will not appear on the scene without a parent, it is
+ recommended that you set the parent this way. However, if you wish to set the parent later you can safely pass \c null to
+ this function.
+\o The second is optional and is a script which assigns values to the item's properties during creation. This avoids warnings
+ when certain properties have been bound to before they have been set by the code. Additionally, there are small performance
+ benefits when instantiating objects in this way.
+\endlist
Here is an example. First there is \c Sprite.qml, which defines a simple QML component:
diff --git a/doc/src/snippets/declarative/componentCreation.js b/doc/src/snippets/declarative/componentCreation.js
index c29a1f9..cf59777 100644
--- a/doc/src/snippets/declarative/componentCreation.js
+++ b/doc/src/snippets/declarative/componentCreation.js
@@ -17,15 +17,11 @@ function createSpriteObjects() {
//![local]
component = Qt.createComponent("Sprite.qml");
- sprite = component.createObject(appWindow);
+ sprite = component.createObject(appWindow, {"x": 100, "y": 100});
if (sprite == null) {
// Error Handling
console.log("Error creating object");
- } else {
- sprite.x = 100;
- sprite.y = 100;
- // ...
}
//![local]
diff --git a/examples/declarative/toys/dynamicscene/qml/itemCreation.js b/examples/declarative/toys/dynamicscene/qml/itemCreation.js
index e74f7b0..4ee74c2 100644
--- a/examples/declarative/toys/dynamicscene/qml/itemCreation.js
+++ b/examples/declarative/toys/dynamicscene/qml/itemCreation.js
@@ -28,11 +28,8 @@ function loadComponent() {
function createItem() {
if (itemComponent.status == Component.Ready && draggedItem == null) {
- draggedItem = itemComponent.createObject(window);
- draggedItem.image = paletteItem.image;
- draggedItem.x = posnInWindow.x;
- draggedItem.y = posnInWindow.y;
- draggedItem.z = 3; // make sure created item is above the ground layer
+ draggedItem = itemComponent.createObject(window, {"image": paletteItem.image, "x": posnInWindow.x, "y": posnInWindow.y, "z": 3});
+ // make sure created item is above the ground layer
} else if (itemComponent.status == Component.Error) {
draggedItem = null;
console.log("error creating component");