diff options
author | Chris Meyer <cmeyer1969@gmail.com> | 2010-10-04 08:49:32 (GMT) |
---|---|---|
committer | Samuel Rødal <samuel.rodal@nokia.com> | 2010-10-04 08:49:32 (GMT) |
commit | 73fa0f87c26a3f5bf17746ec91d05264f0020093 (patch) | |
tree | c06e6f972cdae0c2f084d8bcd5b464b06134b52e | |
parent | ea8dd9d2dbd3345fbf76625c441d9832f758bf70 (diff) | |
download | Qt-73fa0f87c26a3f5bf17746ec91d05264f0020093.zip Qt-73fa0f87c26a3f5bf17746ec91d05264f0020093.tar.gz Qt-73fa0f87c26a3f5bf17746ec91d05264f0020093.tar.bz2 |
Fix QTBUG-13730. QGraphicsScene::render clipping bug. Includes test case.
Merge-request: 2480
Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
-rw-r--r-- | src/gui/graphicsview/qgraphicsscene.cpp | 2 | ||||
-rw-r--r-- | tests/auto/qgraphicsscene/testData/render/all-all-untransformed-clip-ellipse.png | bin | 0 -> 1819 bytes | |||
-rw-r--r-- | tests/auto/qgraphicsscene/testData/render/all-all-untransformed-clip-rect.png | bin | 0 -> 1255 bytes | |||
-rw-r--r-- | tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp | 65 |
4 files changed, 40 insertions, 27 deletions
diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp index 8dc15bf..e58b93c 100644 --- a/src/gui/graphicsview/qgraphicsscene.cpp +++ b/src/gui/graphicsview/qgraphicsscene.cpp @@ -1759,7 +1759,7 @@ void QGraphicsScene::render(QPainter *painter, const QRectF &target, const QRect painter->save(); // Transform the painter. - painter->setClipRect(targetRect); + painter->setClipRect(targetRect, Qt::IntersectClip); QTransform painterTransform; painterTransform *= QTransform() .translate(targetRect.left(), targetRect.top()) diff --git a/tests/auto/qgraphicsscene/testData/render/all-all-untransformed-clip-ellipse.png b/tests/auto/qgraphicsscene/testData/render/all-all-untransformed-clip-ellipse.png Binary files differnew file mode 100644 index 0000000..9b401b4 --- /dev/null +++ b/tests/auto/qgraphicsscene/testData/render/all-all-untransformed-clip-ellipse.png diff --git a/tests/auto/qgraphicsscene/testData/render/all-all-untransformed-clip-rect.png b/tests/auto/qgraphicsscene/testData/render/all-all-untransformed-clip-rect.png Binary files differnew file mode 100644 index 0000000..1c59698 --- /dev/null +++ b/tests/auto/qgraphicsscene/testData/render/all-all-untransformed-clip-rect.png diff --git a/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp b/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp index b8e729e..09cf4e2 100644 --- a/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp +++ b/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp @@ -2617,59 +2617,70 @@ void tst_QGraphicsScene::render_data() QTest::addColumn<QRectF>("sourceRect"); QTest::addColumn<Qt::AspectRatioMode>("aspectRatioMode"); QTest::addColumn<QMatrix>("matrix"); + QTest::addColumn<QPainterPath>("clip"); + + QPainterPath clip_rect; + clip_rect.addRect(50, 100, 200, 150); + + QPainterPath clip_ellipse; + clip_ellipse.addEllipse(100,50,150,200); QTest::newRow("all-all-untransformed") << QRectF() << QRectF() - << Qt::IgnoreAspectRatio << QMatrix(); + << Qt::IgnoreAspectRatio << QMatrix() << QPainterPath(); QTest::newRow("all-topleft-untransformed") << QRectF(0, 0, 150, 150) - << QRectF() << Qt::IgnoreAspectRatio << QMatrix(); + << QRectF() << Qt::IgnoreAspectRatio << QMatrix() << QPainterPath(); QTest::newRow("all-topright-untransformed") << QRectF(150, 0, 150, 150) - << QRectF() << Qt::IgnoreAspectRatio << QMatrix(); + << QRectF() << Qt::IgnoreAspectRatio << QMatrix() << QPainterPath(); QTest::newRow("all-bottomleft-untransformed") << QRectF(0, 150, 150, 150) - << QRectF() << Qt::IgnoreAspectRatio << QMatrix(); + << QRectF() << Qt::IgnoreAspectRatio << QMatrix() << QPainterPath(); QTest::newRow("all-bottomright-untransformed") << QRectF(150, 150, 150, 150) - << QRectF() << Qt::IgnoreAspectRatio << QMatrix(); + << QRectF() << Qt::IgnoreAspectRatio << QMatrix() << QPainterPath(); QTest::newRow("topleft-all-untransformed") << QRectF() << QRectF(-10, -10, 10, 10) - << Qt::IgnoreAspectRatio << QMatrix(); + << Qt::IgnoreAspectRatio << QMatrix() << QPainterPath(); QTest::newRow("topright-all-untransformed") << QRectF() << QRectF(0, -10, 10, 10) - << Qt::IgnoreAspectRatio << QMatrix(); + << Qt::IgnoreAspectRatio << QMatrix() << QPainterPath(); QTest::newRow("bottomleft-all-untransformed") << QRectF() << QRectF(-10, 0, 10, 10) - << Qt::IgnoreAspectRatio << QMatrix(); + << Qt::IgnoreAspectRatio << QMatrix() << QPainterPath(); QTest::newRow("bottomright-all-untransformed") << QRectF() << QRectF(0, 0, 10, 10) - << Qt::IgnoreAspectRatio << QMatrix(); + << Qt::IgnoreAspectRatio << QMatrix() << QPainterPath(); QTest::newRow("topleft-topleft-untransformed") << QRectF(0, 0, 150, 150) << QRectF(-10, -10, 10, 10) - << Qt::IgnoreAspectRatio << QMatrix(); + << Qt::IgnoreAspectRatio << QMatrix() << QPainterPath(); QTest::newRow("topright-topleft-untransformed") << QRectF(150, 0, 150, 150) << QRectF(-10, -10, 10, 10) - << Qt::IgnoreAspectRatio << QMatrix(); + << Qt::IgnoreAspectRatio << QMatrix() << QPainterPath(); QTest::newRow("bottomleft-topleft-untransformed") << QRectF(0, 150, 150, 150) << QRectF(-10, -10, 10, 10) - << Qt::IgnoreAspectRatio << QMatrix(); + << Qt::IgnoreAspectRatio << QMatrix() << QPainterPath(); QTest::newRow("bottomright-topleft-untransformed") << QRectF(150, 150, 150, 150) << QRectF(-10, -10, 10, 10) - << Qt::IgnoreAspectRatio << QMatrix(); + << Qt::IgnoreAspectRatio << QMatrix() << QPainterPath(); QTest::newRow("top-topleft-untransformed") << QRectF(0, 0, 300, 150) << QRectF(-10, -10, 10, 10) - << Qt::IgnoreAspectRatio << QMatrix(); + << Qt::IgnoreAspectRatio << QMatrix() << QPainterPath(); QTest::newRow("bottom-topleft-untransformed") << QRectF(0, 150, 300, 150) << QRectF(-10, -10, 10, 10) - << Qt::IgnoreAspectRatio << QMatrix(); + << Qt::IgnoreAspectRatio << QMatrix() << QPainterPath(); QTest::newRow("left-topleft-untransformed") << QRectF(0, 0, 150, 300) << QRectF(-10, -10, 10, 10) - << Qt::IgnoreAspectRatio << QMatrix(); + << Qt::IgnoreAspectRatio << QMatrix() << QPainterPath(); QTest::newRow("right-topleft-untransformed") << QRectF(150, 0, 150, 300) << QRectF(-10, -10, 10, 10) - << Qt::IgnoreAspectRatio << QMatrix(); + << Qt::IgnoreAspectRatio << QMatrix() << QPainterPath(); QTest::newRow("top-bottomright-untransformed") << QRectF(0, 0, 300, 150) << QRectF(0, 0, 10, 10) - << Qt::IgnoreAspectRatio << QMatrix(); + << Qt::IgnoreAspectRatio << QMatrix() << QPainterPath(); QTest::newRow("bottom-bottomright-untransformed") << QRectF(0, 150, 300, 150) << QRectF(0, 0, 10, 10) - << Qt::IgnoreAspectRatio << QMatrix(); + << Qt::IgnoreAspectRatio << QMatrix() << QPainterPath(); QTest::newRow("left-bottomright-untransformed") << QRectF(0, 0, 150, 300) << QRectF(0, 0, 10, 10) - << Qt::IgnoreAspectRatio << QMatrix(); + << Qt::IgnoreAspectRatio << QMatrix() << QPainterPath(); QTest::newRow("right-bottomright-untransformed") << QRectF(150, 0, 150, 300) << QRectF(0, 0, 10, 10) - << Qt::IgnoreAspectRatio << QMatrix(); + << Qt::IgnoreAspectRatio << QMatrix() << QPainterPath(); QTest::newRow("all-all-45-deg-right") << QRectF() << QRectF() - << Qt::IgnoreAspectRatio << QMatrix().rotate(-45); + << Qt::IgnoreAspectRatio << QMatrix().rotate(-45) << QPainterPath(); QTest::newRow("all-all-45-deg-left") << QRectF() << QRectF() - << Qt::IgnoreAspectRatio << QMatrix().rotate(45); + << Qt::IgnoreAspectRatio << QMatrix().rotate(45) << QPainterPath(); QTest::newRow("all-all-scale-2x") << QRectF() << QRectF() - << Qt::IgnoreAspectRatio << QMatrix().scale(2, 2); + << Qt::IgnoreAspectRatio << QMatrix().scale(2, 2) << QPainterPath(); QTest::newRow("all-all-translate-50-0") << QRectF() << QRectF() - << Qt::IgnoreAspectRatio << QMatrix().translate(50, 0); + << Qt::IgnoreAspectRatio << QMatrix().translate(50, 0) << QPainterPath(); QTest::newRow("all-all-translate-0-50") << QRectF() << QRectF() - << Qt::IgnoreAspectRatio << QMatrix().translate(0, 50); + << Qt::IgnoreAspectRatio << QMatrix().translate(0, 50) << QPainterPath(); + QTest::newRow("all-all-untransformed-clip-rect") << QRectF() << QRectF() + << Qt::IgnoreAspectRatio << QMatrix() << clip_rect; + QTest::newRow("all-all-untransformed-clip-ellipse") << QRectF() << QRectF() + << Qt::IgnoreAspectRatio << QMatrix() << clip_ellipse; } void tst_QGraphicsScene::render() @@ -2678,6 +2689,7 @@ void tst_QGraphicsScene::render() QFETCH(QRectF, sourceRect); QFETCH(Qt::AspectRatioMode, aspectRatioMode); QFETCH(QMatrix, matrix); + QFETCH(QPainterPath, clip); QPixmap pix(30, 30); pix.fill(Qt::blue); @@ -2703,6 +2715,7 @@ void tst_QGraphicsScene::render() painter.drawLine(0, 150, 300, 150); painter.drawLine(150, 0, 150, 300); painter.setMatrix(matrix); + if (!clip.isEmpty()) painter.setClipPath(clip); scene.render(&painter, targetRect, sourceRect, aspectRatioMode); painter.end(); |