summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjørn Erik Nilsen <bjorn.nilsen@nokia.com>2009-10-22 12:49:40 (GMT)
committerBjørn Erik Nilsen <bjorn.nilsen@nokia.com>2009-10-23 08:34:46 (GMT)
commitcc4d3fbc317bc9044c3ce23569f0225b29af4fd5 (patch)
treec76592219af2ddfc1d2a049d03ee98f8807a3639
parenta95883e90fadeddd2f49da6765fb2d79f7ce77bd (diff)
downloadQt-cc4d3fbc317bc9044c3ce23569f0225b29af4fd5.zip
Qt-cc4d3fbc317bc9044c3ce23569f0225b29af4fd5.tar.gz
Qt-cc4d3fbc317bc9044c3ce23569f0225b29af4fd5.tar.bz2
QGraphicsLineItem leave traces when moving around (reg. against 4.5)
The problem was that QGraphicsLineItem's bounding rect is an empty rect (either width is 0 or height is 0), and when updating the item's old occupied area, we explicitly checked whether the rect was empty() or not. In case of being empty (rect.isEmpty()) we did nothing, which was the root of the problem. We can safely remove the rect.isEmpty() check without any significant loss of performance since the common case is that the rect is non-empty. And in the case of being empty, we'll bail out from QGraphicsViewPrivate::updateRect's highly optimized rect intersection. Auto test included. Task: QTBUG-4877 Reviewed-by: alexis
-rw-r--r--src/gui/graphicsview/qgraphicsscene.cpp2
-rw-r--r--tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp34
2 files changed, 35 insertions, 1 deletions
diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp
index 03c8a97..9736c3e 100644
--- a/src/gui/graphicsview/qgraphicsscene.cpp
+++ b/src/gui/graphicsview/qgraphicsscene.cpp
@@ -4888,7 +4888,7 @@ void QGraphicsScenePrivate::processDirtyItemsRecursive(QGraphicsItem *item, bool
continue;
}
- if (item->d_ptr->paintedViewBoundingRectsNeedRepaint && !paintedViewBoundingRect.isEmpty()) {
+ if (item->d_ptr->paintedViewBoundingRectsNeedRepaint) {
paintedViewBoundingRect.translate(viewPrivate->dirtyScrollOffset);
if (!viewPrivate->updateRect(paintedViewBoundingRect))
paintedViewBoundingRect = QRect(-1, -1, -1, -1); // Outside viewport.
diff --git a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
index dcad8e1..4fae911 100644
--- a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
+++ b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
@@ -372,6 +372,7 @@ private slots:
void itemUsesExtendedStyleOption();
void itemSendsGeometryChanges();
void moveItem();
+ void moveLineItem();
void sorting_data();
void sorting();
void itemHasNoContents();
@@ -7438,6 +7439,39 @@ void tst_QGraphicsItem::moveItem()
COMPARE_REGIONS(view.paintedRegion, expectedParentRegion);
}
+void tst_QGraphicsItem::moveLineItem()
+{
+ QGraphicsScene scene;
+ scene.setSceneRect(0, 0, 200, 200);
+ QGraphicsLineItem *item = new QGraphicsLineItem(0, 0, 100, 0);
+ item->setPos(50, 50);
+ scene.addItem(item);
+
+ MyGraphicsView view(&scene);
+ view.show();
+#ifdef Q_WS_X11
+ qt_x11_wait_for_window_manager(&view);
+#endif
+ QTest::qWait(200);
+ view.reset();
+
+ const QRect itemDeviceBoundingRect = item->deviceTransform(view.viewportTransform())
+ .mapRect(item->boundingRect()).toRect();
+ QRegion expectedRegion = itemDeviceBoundingRect.adjusted(-2, -2, 2, 2); // antialiasing
+
+ // Make sure the calculated region is correct.
+ item->update();
+ QTest::qWait(10);
+ QCOMPARE(view.paintedRegion, expectedRegion);
+ view.reset();
+
+ // Old position: (50, 50)
+ item->setPos(50, 100);
+ expectedRegion += expectedRegion.translated(0, 50);
+ QTest::qWait(10);
+ QCOMPARE(view.paintedRegion, expectedRegion);
+}
+
void tst_QGraphicsItem::sorting_data()
{
QTest::addColumn<int>("index");