43 #include <QtTest/QtTest> |
43 #include <QtTest/QtTest> |
44 #include <QtGui/qgraphicsscene.h> |
44 #include <QtGui/qgraphicsscene.h> |
45 #include <private/qgraphicsscenebsptreeindex_p.h> |
45 #include <private/qgraphicsscenebsptreeindex_p.h> |
46 #include <private/qgraphicssceneindex_p.h> |
46 #include <private/qgraphicssceneindex_p.h> |
47 #include <private/qgraphicsscenelinearindex_p.h> |
47 #include <private/qgraphicsscenelinearindex_p.h> |
|
48 #include "../../shared/util.h" |
|
49 |
48 |
50 |
49 //TESTED_CLASS= |
51 //TESTED_CLASS= |
50 //TESTED_FILES= |
52 //TESTED_FILES= |
51 |
53 |
52 class tst_QGraphicsSceneIndex : public QObject |
54 class tst_QGraphicsSceneIndex : public QObject |
264 QCOMPARE(scene.items().size(), 3); |
267 QCOMPARE(scene.items().size(), 3); |
265 |
268 |
266 // Move from unindexed items into untransformable items. |
269 // Move from unindexed items into untransformable items. |
267 QTest::qWait(50); |
270 QTest::qWait(50); |
268 QCOMPARE(scene.items().size(), 3); |
271 QCOMPARE(scene.items().size(), 3); |
|
272 } |
|
273 |
|
274 class RectWidget : public QGraphicsWidget |
|
275 { |
|
276 Q_OBJECT |
|
277 public: |
|
278 RectWidget(QGraphicsItem *parent = 0) : QGraphicsWidget(parent) |
|
279 { |
|
280 } |
|
281 |
|
282 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
283 { |
|
284 painter->setBrush(brush); |
|
285 painter->drawRect(boundingRect()); |
|
286 } |
|
287 public: |
|
288 QBrush brush; |
|
289 }; |
|
290 |
|
291 void tst_QGraphicsSceneIndex::removeItems() |
|
292 { |
|
293 QGraphicsScene scene; |
|
294 |
|
295 RectWidget *parent = new RectWidget; |
|
296 parent->brush = QBrush(QColor(Qt::magenta)); |
|
297 parent->setGeometry(250, 250, 400, 400); |
|
298 |
|
299 RectWidget *widget = new RectWidget(parent); |
|
300 widget->brush = QBrush(QColor(Qt::blue)); |
|
301 widget->setGeometry(10, 10, 200, 200); |
|
302 |
|
303 RectWidget *widgetChild1 = new RectWidget(widget); |
|
304 widgetChild1->brush = QBrush(QColor(Qt::green)); |
|
305 widgetChild1->setGeometry(20, 20, 100, 100); |
|
306 |
|
307 RectWidget *widgetChild2 = new RectWidget(widgetChild1); |
|
308 widgetChild2->brush = QBrush(QColor(Qt::yellow)); |
|
309 widgetChild2->setGeometry(25, 25, 50, 50); |
|
310 |
|
311 scene.addItem(parent); |
|
312 |
|
313 QGraphicsView view(&scene); |
|
314 view.resize(600, 600); |
|
315 view.show(); |
|
316 QApplication::setActiveWindow(&view); |
|
317 QTest::qWaitForWindowShown(&view); |
|
318 |
|
319 QApplication::processEvents(); |
|
320 |
|
321 scene.removeItem(widgetChild1); |
|
322 |
|
323 delete widgetChild1; |
|
324 |
|
325 //We move the parent |
|
326 scene.items(295, 295, 50, 50); |
|
327 |
|
328 //This should not crash |
269 } |
329 } |
270 |
330 |
271 void tst_QGraphicsSceneIndex::clear() |
331 void tst_QGraphicsSceneIndex::clear() |
272 { |
332 { |
273 class MyItem : public QGraphicsItem |
333 class MyItem : public QGraphicsItem |
296 // Make sure the index is re-generated after QGraphicsScene::clear(); |
356 // Make sure the index is re-generated after QGraphicsScene::clear(); |
297 // otherwise no items will be painted. |
357 // otherwise no items will be painted. |
298 MyItem *item = new MyItem; |
358 MyItem *item = new MyItem; |
299 scene.addItem(item); |
359 scene.addItem(item); |
300 qApp->processEvents(); |
360 qApp->processEvents(); |
301 QCOMPARE(item->numPaints, 1); |
361 QTRY_COMPARE(item->numPaints, 1); |
302 } |
362 } |
303 |
363 |
304 QTEST_MAIN(tst_QGraphicsSceneIndex) |
364 QTEST_MAIN(tst_QGraphicsSceneIndex) |
305 #include "tst_qgraphicssceneindex.moc" |
365 #include "tst_qgraphicssceneindex.moc" |