diff options
author | Bjørn Erik Nilsen <bjorn.nilsen@nokia.com> | 2010-07-20 08:32:59 (GMT) |
---|---|---|
committer | Bjørn Erik Nilsen <bjorn.nilsen@nokia.com> | 2010-07-20 10:10:37 (GMT) |
commit | 4df9c96e2c213c39924e22e02621b0c61e83f8fe (patch) | |
tree | 3e95cfcf951ecbca57cfd01491586ab172e77cd1 /tests/auto/qgraphicsview/tst_qgraphicsview.cpp | |
parent | 7bdbf59e43bd5db584923402b8a2ce2f50d1ca4b (diff) | |
download | Qt-4df9c96e2c213c39924e22e02621b0c61e83f8fe.zip Qt-4df9c96e2c213c39924e22e02621b0c61e83f8fe.tar.gz Qt-4df9c96e2c213c39924e22e02621b0c61e83f8fe.tar.bz2 |
QGraphicsItem: Animation leaves drawing artifacts when clipping is used.
This only happens when the ItemHasNoContents and ItemClipsChildrenToShape
flags are set. Problem is that items with no content are threated as 'dummy'
items, which means they are never drawn or 'processed' otherwise, so the
cached bounding rect is not reliable/usable. This means that in case of
changing the geometry of such items, its children always have to take
care of invalidating the occupied areas and the update can not be
clipped to the item's bounding rect.
Regression after commit: c1c7dbf2
Auto test included.
Task-number: QTBUG-11504
Reviewed-by: yoann
Diffstat (limited to 'tests/auto/qgraphicsview/tst_qgraphicsview.cpp')
-rw-r--r-- | tests/auto/qgraphicsview/tst_qgraphicsview.cpp | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/tests/auto/qgraphicsview/tst_qgraphicsview.cpp b/tests/auto/qgraphicsview/tst_qgraphicsview.cpp index b8df7f6..1cce687 100644 --- a/tests/auto/qgraphicsview/tst_qgraphicsview.cpp +++ b/tests/auto/qgraphicsview/tst_qgraphicsview.cpp @@ -219,6 +219,7 @@ private slots: void update2_data(); void update2(); void update_ancestorClipsChildrenToShape(); + void update_ancestorClipsChildrenToShape2(); void inputMethodSensitivity(); void inputContextReset(); void indirectPainting(); @@ -3815,6 +3816,78 @@ void tst_QGraphicsView::update_ancestorClipsChildrenToShape() #endif } +void tst_QGraphicsView::update_ancestorClipsChildrenToShape2() +{ + QGraphicsScene scene(-150, -150, 300, 300); + + /* + Add two rects: + + +------------------+ + | child | + | +--------------+ | + | | parent | | + | | | | + | | | | + | | | | + | +--------------+ | + +------------------+ + + ... where the parent has no contents and clips the child to shape. + */ + QApplication::processEvents(); // Get rid of pending update. + + QGraphicsRectItem *parent = static_cast<QGraphicsRectItem *>(scene.addRect(-50, -50, 100, 100)); + parent->setBrush(QColor(0, 0, 255, 125)); + parent->setFlag(QGraphicsItem::ItemClipsChildrenToShape); + parent->setFlag(QGraphicsItem::ItemHasNoContents); + + QGraphicsRectItem *child = static_cast<QGraphicsRectItem *>(scene.addRect(-100, -100, 200, 200)); + child->setBrush(QColor(255, 0, 0, 125)); + child->setParentItem(parent); + + CustomView view(&scene); + view.show(); + QTest::qWaitForWindowShown(&view); + QTRY_VERIFY(view.painted); + + view.lastUpdateRegions.clear(); + view.painted = false; + + // Call child->update() and make sure the updated area is within its parent's clip. + QRectF expected = child->deviceTransform(view.viewportTransform()).mapRect(child->boundingRect()); + expected &= parent->deviceTransform(view.viewportTransform()).mapRect(parent->boundingRect()); + + child->update(); + QTRY_VERIFY(view.painted); + +#ifndef QT_MAC_USE_COCOA //cocoa doesn't support drawing regions + QTRY_VERIFY(view.painted); + QCOMPARE(view.lastUpdateRegions.size(), 1); + QCOMPARE(view.lastUpdateRegions.at(0), QRegion(expected.toAlignedRect())); +#endif + + QTest::qWait(50); + + view.lastUpdateRegions.clear(); + view.painted = false; + + // Invalidate the parent's geometry and trigger an update. + // The update area should be clipped to the parent's bounding rect for 'normal' items, + // but in this case the item has no contents (ItemHasNoContents) and its geometry + // is invalidated, which means we cannot clip the child update. So, the expected + // area is exactly the same as the child's bounding rect (adjusted for antialiasing). + parent->setRect(parent->rect().adjusted(-10, -10, -10, -10)); + expected = child->deviceTransform(view.viewportTransform()).mapRect(child->boundingRect()); + expected.adjust(-2, -2, 2, 2); // Antialiasing + +#ifndef QT_MAC_USE_COCOA //cocoa doesn't support drawing regions + QTRY_VERIFY(view.painted); + QCOMPARE(view.lastUpdateRegions.size(), 1); + QCOMPARE(view.lastUpdateRegions.at(0), QRegion(expected.toAlignedRect())); +#endif +} + class FocusItem : public QGraphicsRectItem { public: |