summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Brasser <michael.brasser@nokia.com>2010-08-10 01:50:49 (GMT)
committerToby Tomkins <toby.tomkins@nokia.com>2010-08-11 05:08:46 (GMT)
commite0167ee787bd0d28a9de0278c3f70f30151e2be6 (patch)
tree7f6036cc44c50e113e898f3b12635f1a17849cfe
parente133941d76a2214708b5d7c6aa35eae44d6f5076 (diff)
downloadQt-e0167ee787bd0d28a9de0278c3f70f30151e2be6.zip
Qt-e0167ee787bd0d28a9de0278c3f70f30151e2be6.tar.gz
Qt-e0167ee787bd0d28a9de0278c3f70f30151e2be6.tar.bz2
Don't double-add item change listeners.
When a Repeater was used as the child of an Item binding to childrenRect, the item change listener was being added twice for the items created by the Repeater. Task-number: QTBUG-12722 (cherry picked from commit 6feb5b75ce96aeeefee189af003949db8c031519)
-rw-r--r--src/declarative/graphicsitems/qdeclarativeitem.cpp4
-rw-r--r--tests/auto/declarative/qdeclarativeitem/data/childrenRectBug3.qml15
-rw-r--r--tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp12
3 files changed, 29 insertions, 2 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp
index 06862f1..ccbdce8 100644
--- a/src/declarative/graphicsitems/qdeclarativeitem.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp
@@ -2740,12 +2740,12 @@ QVariant QDeclarativeItem::itemChange(GraphicsItemChange change,
}
break;
case ItemChildAddedChange:
- if (d->_contents)
+ if (d->_contents && d->componentComplete)
d->_contents->childAdded(qobject_cast<QDeclarativeItem*>(
value.value<QGraphicsItem*>()));
break;
case ItemChildRemovedChange:
- if (d->_contents)
+ if (d->_contents && d->componentComplete)
d->_contents->childRemoved(qobject_cast<QDeclarativeItem*>(
value.value<QGraphicsItem*>()));
break;
diff --git a/tests/auto/declarative/qdeclarativeitem/data/childrenRectBug3.qml b/tests/auto/declarative/qdeclarativeitem/data/childrenRectBug3.qml
new file mode 100644
index 0000000..f19ab4f
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeitem/data/childrenRectBug3.qml
@@ -0,0 +1,15 @@
+import Qt 4.7
+
+Rectangle {
+ width: 300
+ height: 300
+
+ Rectangle {
+ height: childrenRect.height
+
+ Repeater {
+ model: 1
+ Rectangle { }
+ }
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp b/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp
index d76d360..25ca157 100644
--- a/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp
+++ b/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp
@@ -75,6 +75,7 @@ private slots:
void childrenRect();
void childrenRectBug();
void childrenRectBug2();
+ void childrenRectBug3();
void childrenProperty();
void resourcesProperty();
@@ -780,6 +781,17 @@ void tst_QDeclarativeItem::childrenRectBug2()
delete canvas;
}
+// QTBUG-12722
+void tst_QDeclarativeItem::childrenRectBug3()
+{
+ QDeclarativeView *canvas = new QDeclarativeView(0);
+ canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/childrenRectBug3.qml"));
+ canvas->show();
+
+ //don't crash on delete
+ delete canvas;
+}
+
template<typename T>
T *tst_QDeclarativeItem::findItem(QGraphicsObject *parent, const QString &objectName)
{