tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
branchRCL_3
changeset 5 d3bac044e0f0
parent 4 3b1da2848fc7
child 7 3f74d0d4af4c
equal deleted inserted replaced
4:3b1da2848fc7 5:d3bac044e0f0
   314     void sceneBoundingRect();
   314     void sceneBoundingRect();
   315     void childrenBoundingRect();
   315     void childrenBoundingRect();
   316     void childrenBoundingRectTransformed();
   316     void childrenBoundingRectTransformed();
   317     void childrenBoundingRect2();
   317     void childrenBoundingRect2();
   318     void childrenBoundingRect3();
   318     void childrenBoundingRect3();
       
   319     void childrenBoundingRect4();
   319     void group();
   320     void group();
   320     void setGroup();
   321     void setGroup();
   321     void setGroup2();
   322     void setGroup2();
   322     void nestedGroups();
   323     void nestedGroups();
   323     void warpChildrenIntoGroup();
   324     void warpChildrenIntoGroup();
   415     void task240400_clickOnTextItem();
   416     void task240400_clickOnTextItem();
   416     void task243707_addChildBeforeParent();
   417     void task243707_addChildBeforeParent();
   417     void task197802_childrenVisibility();
   418     void task197802_childrenVisibility();
   418     void QTBUG_4233_updateCachedWithSceneRect();
   419     void QTBUG_4233_updateCachedWithSceneRect();
   419     void QTBUG_5418_textItemSetDefaultColor();
   420     void QTBUG_5418_textItemSetDefaultColor();
       
   421     void QTBUG_6738_missingUpdateWithSetParent();
   420 
   422 
   421 private:
   423 private:
   422     QList<QGraphicsItem *> paintedItems;
   424     QList<QGraphicsItem *> paintedItems;
   423 };
   425 };
   424 
   426 
  3253     QRectF subTreeRect = rect->childrenBoundingRect();
  3255     QRectF subTreeRect = rect->childrenBoundingRect();
  3254     QCOMPARE(subTreeRect.left(), qreal(-206.0660171779821));
  3256     QCOMPARE(subTreeRect.left(), qreal(-206.0660171779821));
  3255     QCOMPARE(subTreeRect.top(), qreal(75.0));
  3257     QCOMPARE(subTreeRect.top(), qreal(75.0));
  3256     QCOMPARE(subTreeRect.width(), qreal(351.7766952966369));
  3258     QCOMPARE(subTreeRect.width(), qreal(351.7766952966369));
  3257     QCOMPARE(subTreeRect.height(), qreal(251.7766952966369));
  3259     QCOMPARE(subTreeRect.height(), qreal(251.7766952966369));
       
  3260 }
       
  3261 
       
  3262 void tst_QGraphicsItem::childrenBoundingRect4()
       
  3263 {
       
  3264     QGraphicsScene scene;
       
  3265 
       
  3266     QGraphicsRectItem *rect = scene.addRect(QRectF(0, 0, 10, 10));
       
  3267     QGraphicsRectItem *rect2 = scene.addRect(QRectF(0, 0, 20, 20));
       
  3268     QGraphicsRectItem *rect3 = scene.addRect(QRectF(0, 0, 30, 30));
       
  3269     rect2->setParentItem(rect);
       
  3270     rect3->setParentItem(rect);
       
  3271 
       
  3272     QGraphicsView view(&scene);
       
  3273     view.show();
       
  3274 
       
  3275     QTest::qWaitForWindowShown(&view);
       
  3276 
       
  3277     // Try to mess up the cached bounding rect.
       
  3278     rect->childrenBoundingRect();
       
  3279     rect2->childrenBoundingRect();
       
  3280 
       
  3281     rect3->setOpacity(0.0);
       
  3282     rect3->setParentItem(rect2);
       
  3283 
       
  3284     QCOMPARE(rect->childrenBoundingRect(), rect3->boundingRect());
       
  3285     QCOMPARE(rect2->childrenBoundingRect(), rect3->boundingRect());
  3258 }
  3286 }
  3259 
  3287 
  3260 void tst_QGraphicsItem::group()
  3288 void tst_QGraphicsItem::group()
  3261 {
  3289 {
  3262     QGraphicsScene scene;
  3290     QGraphicsScene scene;
  9867     i->setDefaultTextColor(col);
  9895     i->setDefaultTextColor(col);
  9868     QApplication::processEvents();
  9896     QApplication::processEvents();
  9869     QCOMPARE(i->painted, 0); //same color as before should not trigger an update (QTBUG-6242)
  9897     QCOMPARE(i->painted, 0); //same color as before should not trigger an update (QTBUG-6242)
  9870 }
  9898 }
  9871 
  9899 
       
  9900 void tst_QGraphicsItem::QTBUG_6738_missingUpdateWithSetParent()
       
  9901 {
       
  9902     // In all 3 test cases below the reparented item should disappear
       
  9903     EventTester *parent = new EventTester;
       
  9904     EventTester *child = new EventTester(parent);
       
  9905     EventTester *child2 = new EventTester(parent);
       
  9906     EventTester *child3 = new EventTester(parent);
       
  9907     EventTester *child4 = new EventTester(parent);
       
  9908 
       
  9909     child->setPos(10, 10);
       
  9910     child2->setPos(20, 20);
       
  9911     child3->setPos(30, 30);
       
  9912     child4->setPos(40, 40);
       
  9913 
       
  9914     QGraphicsScene scene;
       
  9915     scene.addItem(parent);
       
  9916 
       
  9917     class MyGraphicsView : public QGraphicsView
       
  9918     { public:
       
  9919         int repaints;
       
  9920         QRegion paintedRegion;
       
  9921         MyGraphicsView(QGraphicsScene *scene) : QGraphicsView(scene), repaints(0) {}
       
  9922         void paintEvent(QPaintEvent *e)
       
  9923         {
       
  9924             ++repaints;
       
  9925             paintedRegion += e->region();
       
  9926             QGraphicsView::paintEvent(e);
       
  9927         }
       
  9928         void reset() { repaints = 0; paintedRegion = QRegion(); }
       
  9929     };
       
  9930 
       
  9931     MyGraphicsView view(&scene);
       
  9932     view.show();
       
  9933     QTest::qWaitForWindowShown(&view);
       
  9934     QTRY_VERIFY(view.repaints > 0);
       
  9935 
       
  9936     // test case #1
       
  9937     view.reset();
       
  9938     child2->setVisible(false);
       
  9939     child2->setParentItem(child);
       
  9940 
       
  9941     QTRY_VERIFY(view.repaints == 1);
       
  9942 
       
  9943     // test case #2
       
  9944     view.reset();
       
  9945     child3->setOpacity(0.0);
       
  9946     child3->setParentItem(child);
       
  9947 
       
  9948     QTRY_VERIFY(view.repaints == 1);
       
  9949 
       
  9950     // test case #3
       
  9951     view.reset();
       
  9952     child4->setParentItem(child);
       
  9953     child4->setVisible(false);
       
  9954 
       
  9955     QTRY_VERIFY(view.repaints == 1);
       
  9956 }
       
  9957 
  9872 QTEST_MAIN(tst_QGraphicsItem)
  9958 QTEST_MAIN(tst_QGraphicsItem)
  9873 #include "tst_qgraphicsitem.moc"
  9959 #include "tst_qgraphicsitem.moc"