summaryrefslogtreecommitdiffstats
path: root/examples/qt3d/bigmodel-qml
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2015-06-10 19:14:11 +0200
committerSean Harmer <sean.harmer@kdab.com>2015-06-11 19:28:11 +0000
commit75a7ab50a78cfd41b4624929395c46ce357bc971 (patch)
tree57202c8c4a723b86d12637e52488fd76329d26a6 /examples/qt3d/bigmodel-qml
parentdef3633a71324c95c309894159d9562860cd76a9 (diff)
Improve bigmodel example by using a QtQuick ListModel
When using a number as a model, when the model changes, a new model is recreated which induces all delegates to be cleared and recreated. Using a ListModel however, the model reference remains the same, only its content is updated which implies that already created delegates are kept which is much more efficient. This example could further be improved by making the delegate more lightweight by defining components in the scene root and referencing those as components in the delegate. However this would complexify this example which is there rather as a how to than a performance oriented one. Change-Id: I542889a25b65f5de4579288b00b56c9c52667764 Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'examples/qt3d/bigmodel-qml')
-rw-r--r--examples/qt3d/bigmodel-qml/main.qml10
1 files changed, 7 insertions, 3 deletions
diff --git a/examples/qt3d/bigmodel-qml/main.qml b/examples/qt3d/bigmodel-qml/main.qml
index 641ee860e..2831d3c02 100644
--- a/examples/qt3d/bigmodel-qml/main.qml
+++ b/examples/qt3d/bigmodel-qml/main.qml
@@ -59,6 +59,11 @@ Entity {
upVector: Qt.vector3d( 0.0, 1.0, 0.0 )
}
+ QQ2.ListModel {
+ id: entityModel
+ QQ2.ListElement { emptyRole: 0 }
+ }
+
NodeInstantiator {
id: collection
property int _count: 0
@@ -66,12 +71,11 @@ Entity {
property int cols: 8
property int _rows: count / cols
- model: _count
+ model: entityModel
delegate: MyEntity {
id: myEntity
property real _lightness: 0.2 + 0.7 / collection._rows * Math.floor(index / collection.cols)
property real _hue: (index % collection.cols) / collection.cols
-
x: collection.spacing * (index % collection.cols - 0.5 * (collection.cols - 1))
z: collection.spacing * (Math.floor(index / collection.cols) - 0.5 * collection._rows)
diffuse: Qt.hsla( _hue, 0.5, _lightness, 1.0 )
@@ -83,7 +87,7 @@ Entity {
repeat: true
running: true
onTriggered: {
- collection._count += 1
+ entityModel.append({});
}
}
}