summaryrefslogtreecommitdiffstats
path: root/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
diff options
context:
space:
mode:
authorAlexis Menard <alexis.menard@nokia.com>2010-03-22 07:04:46 (GMT)
committerAlexis Menard <alexis.menard@nokia.com>2010-03-24 08:29:00 (GMT)
commitb6b1dee9460d6fdde0b8ad005301c0a315ad30bf (patch)
tree688822268433c0c37a7d8282a132a450b1150f03 /tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
parent67dd6de344710d1c0a21e9dbc803a1d0c95e05b7 (diff)
downloadQt-b6b1dee9460d6fdde0b8ad005301c0a315ad30bf.zip
Qt-b6b1dee9460d6fdde0b8ad005301c0a315ad30bf.tar.gz
Qt-b6b1dee9460d6fdde0b8ad005301c0a315ad30bf.tar.bz2
Fix a crash when reparenting an item in QGraphicsView.
Before calling addItem we need to invalidate the depth otherwise if someone call anything relating to sorting when itemChange is called (because of the scene change for instance) then qt_closestItemFirst for example can crash because of an invalid state. Task-number:QTBUG-6932 Reviewed-by:janarve
Diffstat (limited to 'tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp')
-rw-r--r--tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
index 4d9f23f..75fb337 100644
--- a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
+++ b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
@@ -439,6 +439,7 @@ private slots:
void QTBUG_7714_fullUpdateDiscardingOpacityUpdate2();
void QT_2653_fullUpdateDiscardingOpacityUpdate();
void QT_2649_focusScope();
+ void sortItemsWhileAdding();
private:
QList<QGraphicsItem *> paintedItems;
@@ -10070,5 +10071,38 @@ void tst_QGraphicsItem::QT_2649_focusScope()
delete scene;
}
+class MyGraphicsItemWithItemChange : public QGraphicsWidget
+{
+public:
+ MyGraphicsItemWithItemChange(QGraphicsItem *parent = 0) : QGraphicsWidget(parent)
+ {}
+
+ QVariant itemChange(GraphicsItemChange change, const QVariant &value)
+ {
+ if (change == QGraphicsItem::ItemSceneHasChanged) {
+ foreach (QGraphicsView *view, scene()->views()) {
+ //We trigger a sort of unindexed items in the BSP
+ view->sceneRect();
+ }
+ }
+ return QGraphicsWidget::itemChange(change, value);
+ }
+};
+
+void tst_QGraphicsItem::sortItemsWhileAdding()
+{
+ QGraphicsScene scene;
+ QGraphicsView view(&scene);
+ QGraphicsWidget grandGrandParent;
+ grandGrandParent.resize(200, 200);
+ scene.addItem(&grandGrandParent);
+ QGraphicsWidget grandParent;
+ grandParent.resize(200, 200);
+ QGraphicsWidget parent(&grandParent);
+ parent.resize(200, 200);
+ MyGraphicsItemWithItemChange item(&parent);
+ grandParent.setParentItem(&grandGrandParent);
+}
+
QTEST_MAIN(tst_QGraphicsItem)
#include "tst_qgraphicsitem.moc"