summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjørn Erik Nilsen <bjorn.nilsen@nokia.com>2010-02-23 14:56:28 (GMT)
committerBjørn Erik Nilsen <bjorn.nilsen@nokia.com>2010-02-23 16:27:26 (GMT)
commitf0076dfed6543c622418359b3c217c171249cfb3 (patch)
tree68b0029ed13346b422b10e7062b27bb4066595bf
parent510cb9e5b2c4702753685d59f10bb0464b7d9991 (diff)
downloadQt-f0076dfed6543c622418359b3c217c171249cfb3.zip
Qt-f0076dfed6543c622418359b3c217c171249cfb3.tar.gz
Qt-f0076dfed6543c622418359b3c217c171249cfb3.tar.bz2
Regression: QGraphicsScene::render fails to render the entire scene correctly.
This only happened with items that had either negative width or height (boundingRect().width()|height()). Problem was that in case of not having an exposed region (drawing items from QGraphicsScene::render), we simply checked whether the bounding rect was empty or not. This is fine, however we have to normalize the rect first. (Note that QRegion::intersects(rect) always normalizes the rect, so that's why this use case broke only when calling QGraphicsScene::render). Auto-test included. Task-number: QTBUG-7775 Reviewed-by: yoann
-rw-r--r--src/gui/graphicsview/qgraphicsscene.cpp3
-rw-r--r--tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp36
2 files changed, 38 insertions, 1 deletions
diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp
index 4472272..43fa24a 100644
--- a/src/gui/graphicsview/qgraphicsscene.cpp
+++ b/src/gui/graphicsview/qgraphicsscene.cpp
@@ -4678,7 +4678,8 @@ void QGraphicsScenePrivate::drawSubtreeRecursive(QGraphicsItem *item, QPainter *
if (widget)
item->d_ptr->paintedViewBoundingRects.insert(widget, viewBoundingRect);
viewBoundingRect.adjust(-1, -1, 1, 1);
- drawItem = exposedRegion ? exposedRegion->intersects(viewBoundingRect) : !viewBoundingRect.isEmpty();
+ drawItem = exposedRegion ? exposedRegion->intersects(viewBoundingRect)
+ : !viewBoundingRect.normalized().isEmpty();
if (!drawItem) {
if (!itemHasChildren)
return;
diff --git a/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp b/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp
index 469ded0..9d437d6 100644
--- a/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp
+++ b/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp
@@ -244,6 +244,7 @@ private slots:
#endif
void render_data();
void render();
+ void renderItemsWithNegativeWidthOrHeight();
void contextMenuEvent();
void contextMenuEvent_ItemIgnoresTransformations();
void update();
@@ -2750,6 +2751,41 @@ void tst_QGraphicsScene::render()
}
}
+void tst_QGraphicsScene::renderItemsWithNegativeWidthOrHeight()
+{
+ QGraphicsScene scene(0, 0, 150, 150);
+
+ // Add item with negative width.
+ QGraphicsRectItem *item1 = new QGraphicsRectItem(0, 0, -150, 50);
+ item1->setBrush(Qt::red);
+ item1->setPos(150, 50);
+ scene.addItem(item1);
+
+ // Add item with negative height.
+ QGraphicsRectItem *item2 = new QGraphicsRectItem(0, 0, 50, -150);
+ item2->setBrush(Qt::blue);
+ item2->setPos(50, 150);
+ scene.addItem(item2);
+
+ QGraphicsView view(&scene);
+ view.setFrameStyle(QFrame::NoFrame);
+ view.resize(150, 150);
+ view.show();
+ QCOMPARE(view.viewport()->size(), QSize(150, 150));
+
+ QImage expected(view.viewport()->size(), QImage::Format_RGB32);
+ view.viewport()->render(&expected);
+
+ // Make sure the scene background is the same as the viewport background.
+ scene.setBackgroundBrush(view.viewport()->palette().brush(view.viewport()->backgroundRole()));
+ QImage actual(150, 150, QImage::Format_RGB32);
+ QPainter painter(&actual);
+ scene.render(&painter);
+ painter.end();
+
+ QCOMPARE(actual, expected);
+}
+
void tst_QGraphicsScene::contextMenuEvent()
{
QGraphicsScene scene;