diff options
author | Alexis Menard <alexis.menard@nokia.com> | 2009-04-21 13:25:51 (GMT) |
---|---|---|
committer | Jason McDonald <jason.mcdonald@nokia.com> | 2009-04-21 23:14:05 (GMT) |
commit | c585c0906e7ffe119231efb77f3681a25ffdba44 (patch) | |
tree | 513cee454430bf6c4d85989acd8c0f2c283d3c95 | |
parent | 727ca7a3b6a63b7b76ffe03c4eea72fe37ba2def (diff) | |
download | Qt-c585c0906e7ffe119231efb77f3681a25ffdba44.zip Qt-c585c0906e7ffe119231efb77f3681a25ffdba44.tar.gz Qt-c585c0906e7ffe119231efb77f3681a25ffdba44.tar.bz2 |
We don't need to call two times itemChange when an item is deleted.
Previously we were calling two times itemChange on the parent to give
QGraphicsItem::ItemChildAddedChange. We don't need that. One is enough.
BT : yes
Task-number: BT
Reviewed-by: Andreas
(cherry picked from commit 95b7c50e503dd4743e22c35f341aa31105ea7d73)
-rw-r--r-- | src/gui/graphicsview/qgraphicsscene.cpp | 6 | ||||
-rw-r--r-- | tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp | 35 |
2 files changed, 35 insertions, 6 deletions
diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp index e946f0f..5cd69b3 100644 --- a/src/gui/graphicsview/qgraphicsscene.cpp +++ b/src/gui/graphicsview/qgraphicsscene.cpp @@ -697,12 +697,6 @@ void QGraphicsScenePrivate::_q_removeItemLater(QGraphicsItem *item) { Q_Q(QGraphicsScene); - if (QGraphicsItem *parent = item->d_func()->parent) { - parent->itemChange(QGraphicsItem::ItemChildRemovedChange, - qVariantFromValue<QGraphicsItem *>(item)); - parent->d_func()->children.removeAll(item); - } - // Clear focus on the item to remove any reference in the focusWidget // chain. item->clearFocus(); diff --git a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp index ef84f50..2d221f9 100644 --- a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp @@ -3658,6 +3658,8 @@ void tst_QGraphicsItem::defaultItemTest_QGraphicsEllipseItem() class ItemChangeTester : public QGraphicsRectItem { public: + ItemChangeTester(){} + ItemChangeTester(QGraphicsItem *parent) : QGraphicsRectItem(parent) {} QVariant itemChangeReturnValue; QGraphicsScene *itemSceneChangeTargetScene; @@ -3932,6 +3934,39 @@ void tst_QGraphicsItem::itemChange() QCOMPARE(tester.changes.size(), ++changeCount); QCOMPARE(tester.changes.last(), QGraphicsItem::ItemChildRemovedChange); QCOMPARE(qVariantValue<QGraphicsItem *>(tester.values.last()), (QGraphicsItem *)&testerHelper); + + // ItemChildRemovedChange 1 + ItemChangeTester *test = new ItemChangeTester; + test->itemSceneChangeTargetScene = 0; + int count = 0; + QGraphicsScene *scene = new QGraphicsScene; + scene->addItem(test); + count = test->changes.size(); + //We test here the fact that when a child is deleted the parent receive only one ItemChildRemovedChange + QGraphicsRectItem *child = new QGraphicsRectItem(test); + //We received ItemChildAddedChange + QCOMPARE(test->changes.size(), ++count); + QCOMPARE(test->changes.last(), QGraphicsItem::ItemChildAddedChange); + delete child; + child = 0; + QCOMPARE(test->changes.size(), ++count); + QCOMPARE(test->changes.last(), QGraphicsItem::ItemChildRemovedChange); + + ItemChangeTester *childTester = new ItemChangeTester(test); + //Changes contains all sceneHasChanged and so on, we don't want to test that + int childCount = childTester->changes.size(); + //We received ItemChildAddedChange + QCOMPARE(test->changes.size(), ++count); + child = new QGraphicsRectItem(childTester); + //We received ItemChildAddedChange + QCOMPARE(childTester->changes.size(), ++childCount); + QCOMPARE(childTester->changes.last(), QGraphicsItem::ItemChildAddedChange); + //Delete the child of the top level with all its children + delete childTester; + //Only one removal + QCOMPARE(test->changes.size(), ++count); + QCOMPARE(test->changes.last(), QGraphicsItem::ItemChildRemovedChange); + delete scene; } { // ItemChildRemovedChange 2 |