summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/gui/graphicsview/qgraphicsscene.cpp4
-rw-r--r--tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp23
2 files changed, 25 insertions, 2 deletions
diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp
index a0015dc..726e6d7 100644
--- a/src/gui/graphicsview/qgraphicsscene.cpp
+++ b/src/gui/graphicsview/qgraphicsscene.cpp
@@ -4583,13 +4583,13 @@ void QGraphicsScenePrivate::drawItemHelper(QGraphicsItem *item, QPainter *painte
itemCache->exposed.clear();
deviceData->cacheIndent = QPoint();
pix = QPixmap();
- } else {
+ } else if (!viewRect.isNull()) {
allowPartialCacheExposure = deviceData->cacheIndent != QPoint();
}
// Allow partial cache exposure if the device rect isn't fully contained and
// deviceRect is 20% taller or wider than the viewRect.
- if (!allowPartialCacheExposure && !viewRect.contains(deviceRect)) {
+ if (!allowPartialCacheExposure && !viewRect.isNull() && !viewRect.contains(deviceRect)) {
allowPartialCacheExposure = (viewRect.width() * 1.2 < deviceRect.width())
|| (viewRect.height() * 1.2 < deviceRect.height());
}
diff --git a/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp b/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp
index 6a2f849..588c476 100644
--- a/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp
+++ b/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp
@@ -288,6 +288,7 @@ private slots:
void taskQT657_paintIntoCacheWithTransparentParts();
void taskQTBUG_7863_paintIntoCacheWithTransparentParts();
void taskQT_3674_doNotCrash();
+ void taskQTBUG_15977_renderWithDeviceCoordinateCache();
};
void tst_QGraphicsScene::initTestCase()
@@ -4629,5 +4630,27 @@ void tst_QGraphicsScene::zeroScale()
QTRY_COMPARE(cl.changes.count(), 2);
}
+void tst_QGraphicsScene::taskQTBUG_15977_renderWithDeviceCoordinateCache()
+{
+ QGraphicsScene scene;
+ scene.setSceneRect(0, 0, 100, 100);
+ QGraphicsRectItem *rect = scene.addRect(0, 0, 100, 100);
+ rect->setPen(Qt::NoPen);
+ rect->setBrush(Qt::red);
+ rect->setCacheMode(QGraphicsItem::DeviceCoordinateCache);
+
+ QImage image(100, 100, QImage::Format_RGB32);
+ QPainter p(&image);
+ scene.render(&p);
+ p.end();
+
+ QImage expected(100, 100, QImage::Format_RGB32);
+ p.begin(&expected);
+ p.fillRect(expected.rect(), Qt::red);
+ p.end();
+
+ QCOMPARE(image, expected);
+}
+
QTEST_MAIN(tst_QGraphicsScene)
#include "tst_qgraphicsscene.moc"