diff options
author | Bjørn Erik Nilsen <bjorn.nilsen@nokia.com> | 2010-04-26 07:40:19 (GMT) |
---|---|---|
committer | Bjørn Erik Nilsen <bjorn.nilsen@nokia.com> | 2010-05-03 12:33:33 (GMT) |
commit | 666cacd03d57da6a9caab5936f14c68d1c486e7e (patch) | |
tree | 4665bafee6942c454b00e9e0ea93d30fca2d129e /tests/auto/qgraphicsitem | |
parent | 28659c21d12a267b10e5b441bf4c776e04d69bdc (diff) | |
download | Qt-666cacd03d57da6a9caab5936f14c68d1c486e7e.zip Qt-666cacd03d57da6a9caab5936f14c68d1c486e7e.tar.gz Qt-666cacd03d57da6a9caab5936f14c68d1c486e7e.tar.bz2 |
QGraphicsView drawing artifacts due to rounding errors.
Found during investigation of QTBUG-8820, and clearly visible in
examples/graphicsview/diagramscene when slowly moving an item out of the
viewport (left and top edge). Caused by two problems:
1) Using QRectF::toRect() instead of QRectF::toAlignedRect().
2) Didn't adjust the item's bounding rect properly in drawSubtree().
QRectF::toRect() is completely useless since all the coordinates are rounded
to the nearest integer. E.g. QRectF(-0.4, -0.4, 10.4, 10.4).toRect()
-> QRect(0, 0, 10, 10), whereas toAlignedRect() returns QRect(-1, -1, 11, 11).
Then when we have a proper aligned rect, we have to adjust it by 2
pixels in all directions (or 1 pixel in case of
QGraphicsView::DontAdjustForAntialiasing). At first glance this
adjustment seems too much, since one would assume adjusing the QRectF by
0.5 before using toAlignedRect() would be sufficient. That's sufficient
in an untransformed world with pens using BevelJoin. However, the story
is completely different as soon as the world is transformed or the pens
use a different join. It's basically complicated (in some cases
impossible) to calculate a pixel perfect aligned QRect, so instead we
adjust by the amount of pixels required in the worst case.
This commit also includes some optimizations for QRegion updates (since
I anyways had to change the code). There's no point in using QRegion
granularity if the viewport update mode is either FullViewportUpdate or
BoundingRectViewportUpdate.
Auto tests adjusted and new ones included.
Task-number: QTBUG-10338
Diffstat (limited to 'tests/auto/qgraphicsitem')
-rw-r--r-- | tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp index 055ae80..81097be 100644 --- a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp @@ -7293,7 +7293,7 @@ void tst_QGraphicsItem::update() QCOMPARE(item->repaints, 1); QCOMPARE(view.repaints, 1); QRect itemDeviceBoundingRect = item->deviceTransform(view.viewportTransform()) - .mapRect(item->boundingRect()).toRect(); + .mapRect(item->boundingRect()).toAlignedRect(); QRegion expectedRegion = itemDeviceBoundingRect.adjusted(-2, -2, 2, 2); // The entire item's bounding rect (adjusted for antialiasing) should have been painted. QCOMPARE(view.paintedRegion, expectedRegion); @@ -7372,7 +7372,7 @@ void tst_QGraphicsItem::update() scene.addItem(parent); QTest::qWait(50); itemDeviceBoundingRect = item->deviceTransform(view.viewportTransform()) - .mapRect(item->boundingRect()).toRect(); + .mapRect(item->boundingRect()).toAlignedRect(); expectedRegion = itemDeviceBoundingRect.adjusted(-2, -2, 2, 2); view.reset(); item->repaints = 0; @@ -7648,7 +7648,7 @@ void tst_QGraphicsItem::moveItem() // Item's boundingRect: (-10, -10, 20, 20). QRect parentDeviceBoundingRect = parent->deviceTransform(view.viewportTransform()) - .mapRect(parent->boundingRect()).toRect() + .mapRect(parent->boundingRect()).toAlignedRect() .adjusted(-2, -2, 2, 2); // Adjusted for antialiasing. parent->setPos(20, 20); @@ -7711,8 +7711,14 @@ void tst_QGraphicsItem::moveLineItem() QTest::qWait(200); view.reset(); + QRectF brect = item->boundingRect(); + // Do same adjustments as in qgraphicsscene.cpp + if (!brect.width()) + brect.adjust(qreal(-0.00001), 0, qreal(0.00001), 0); + if (!brect.height()) + brect.adjust(0, qreal(-0.00001), 0, qreal(0.00001)); const QRect itemDeviceBoundingRect = item->deviceTransform(view.viewportTransform()) - .mapRect(item->boundingRect()).toRect(); + .mapRect(brect).toAlignedRect(); QRegion expectedRegion = itemDeviceBoundingRect.adjusted(-2, -2, 2, 2); // antialiasing // Make sure the calculated region is correct. |