summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2010-07-20 00:14:38 (GMT)
committerMartin Jones <martin.jones@nokia.com>2010-07-20 00:14:38 (GMT)
commit17cc89e918a969d85d2b46631ee8743288c7586d (patch)
tree5157d7cd27194144440277aaca93167c12d67c4f
parentcc08942aa57877fd4b8e309088ffe9b28a7deeb8 (diff)
downloadQt-17cc89e918a969d85d2b46631ee8743288c7586d.zip
Qt-17cc89e918a969d85d2b46631ee8743288c7586d.tar.gz
Qt-17cc89e918a969d85d2b46631ee8743288c7586d.tar.bz2
Ensure released VisualItemModel items are removed from the scene.
Also parent them back to the VIM to ensure correct destruction. Task-number: QTBUG-12261
-rw-r--r--src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp8
-rw-r--r--tests/auto/declarative/qdeclarativerepeater/data/itemlist.qml29
-rw-r--r--tests/auto/declarative/qdeclarativerepeater/tst_qdeclarativerepeater.cpp9
3 files changed, 39 insertions, 7 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp
index cfa1c6d..7952b97 100644
--- a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp
+++ b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp
@@ -77,7 +77,7 @@ public:
QDeclarativeVisualItemModelPrivate() : QObjectPrivate() {}
static void children_append(QDeclarativeListProperty<QDeclarativeItem> *prop, QDeclarativeItem *item) {
- item->QObject::setParent(prop->object);
+ QDeclarative_setParent_noEvent(item, prop->object);
static_cast<QDeclarativeVisualItemModelPrivate *>(prop->data)->children.append(item);
static_cast<QDeclarativeVisualItemModelPrivate *>(prop->data)->itemAppended();
static_cast<QDeclarativeVisualItemModelPrivate *>(prop->data)->emitChildrenChanged();
@@ -185,9 +185,11 @@ QDeclarativeItem *QDeclarativeVisualItemModel::item(int index, bool)
return d->children.at(index);
}
-QDeclarativeVisualModel::ReleaseFlags QDeclarativeVisualItemModel::release(QDeclarativeItem *)
+QDeclarativeVisualModel::ReleaseFlags QDeclarativeVisualItemModel::release(QDeclarativeItem *item)
{
- // Nothing to do
+ if (item->scene())
+ item->scene()->removeItem(item);
+ QDeclarative_setParent_noEvent(item, this);
return 0;
}
diff --git a/tests/auto/declarative/qdeclarativerepeater/data/itemlist.qml b/tests/auto/declarative/qdeclarativerepeater/data/itemlist.qml
index e8dd8cc..4810736 100644
--- a/tests/auto/declarative/qdeclarativerepeater/data/itemlist.qml
+++ b/tests/auto/declarative/qdeclarativerepeater/data/itemlist.qml
@@ -4,21 +4,27 @@
import Qt 4.7
Rectangle {
+ id: root
color: "lightgray"
width: 240
height: 320
+ property variant itemModel: itemModel1
function checkProperties() {
testObject.error = false;
- if (testObject.useModel && view.model != itemModel) {
+ if (testObject.useModel && view.model != root.itemModel) {
console.log("model property incorrect");
testObject.error = true;
}
}
+ function switchModel() {
+ root.itemModel = itemModel2
+ }
+
VisualItemModel {
- id: itemModel
- objectName: "itemModel"
+ id: itemModel1
+ objectName: "itemModel1"
Rectangle {
objectName: "item1"
height: 50; width: 100; color: "#FFFEF0"
@@ -36,12 +42,27 @@ Rectangle {
}
}
+ VisualItemModel {
+ id: itemModel2
+ objectName: "itemModel2"
+ Rectangle {
+ objectName: "item4"
+ height: 50; width: 100; color: "#FFFEF0"
+ Text { objectName: "text4"; text: "index: " + parent.VisualItemModel.index; font.bold: true; anchors.centerIn: parent }
+ }
+ Rectangle {
+ objectName: "item5"
+ height: 50; width: 100; color: "#F0FFF7"
+ Text { objectName: "text5"; text: "index: " + parent.VisualItemModel.index; font.bold: true; anchors.centerIn: parent }
+ }
+ }
+
Column {
objectName: "container"
Repeater {
id: view
objectName: "repeater"
- model: testObject.useModel ? itemModel : 0
+ model: testObject.useModel ? root.itemModel : 0
}
}
}
diff --git a/tests/auto/declarative/qdeclarativerepeater/tst_qdeclarativerepeater.cpp b/tests/auto/declarative/qdeclarativerepeater/tst_qdeclarativerepeater.cpp
index 7299a43..623b3d7 100644
--- a/tests/auto/declarative/qdeclarativerepeater/tst_qdeclarativerepeater.cpp
+++ b/tests/auto/declarative/qdeclarativerepeater/tst_qdeclarativerepeater.cpp
@@ -361,6 +361,15 @@ void tst_QDeclarativeRepeater::itemModel()
QVERIFY(qobject_cast<QObject*>(container->childItems().at(2))->objectName() == "item3");
QVERIFY(container->childItems().at(3) == repeater);
+ QMetaObject::invokeMethod(canvas->rootObject(), "switchModel");
+ QCOMPARE(container->childItems().count(), 3);
+ QVERIFY(qobject_cast<QObject*>(container->childItems().at(0))->objectName() == "item4");
+ QVERIFY(qobject_cast<QObject*>(container->childItems().at(1))->objectName() == "item5");
+ QVERIFY(container->childItems().at(2) == repeater);
+
+ testObject->setUseModel(false);
+ QCOMPARE(container->childItems().count(), 1);
+
delete testObject;
delete canvas;
}