From 73fa0f87c26a3f5bf17746ec91d05264f0020093 Mon Sep 17 00:00:00 2001
From: Chris Meyer <cmeyer1969@gmail.com>
Date: Mon, 4 Oct 2010 10:49:32 +0200
Subject: Fix QTBUG-13730. QGraphicsScene::render clipping bug. Includes test
 case.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Merge-request: 2480
Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
---
 src/gui/graphicsview/qgraphicsscene.cpp            |   2 +-
 .../render/all-all-untransformed-clip-ellipse.png  | Bin 0 -> 1819 bytes
 .../render/all-all-untransformed-clip-rect.png     | Bin 0 -> 1255 bytes
 tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp   |  65 ++++++++++++---------
 4 files changed, 40 insertions(+), 27 deletions(-)
 create mode 100644 tests/auto/qgraphicsscene/testData/render/all-all-untransformed-clip-ellipse.png
 create mode 100644 tests/auto/qgraphicsscene/testData/render/all-all-untransformed-clip-rect.png

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
new file mode 100644
index 0000000..9b401b4
Binary files /dev/null and b/tests/auto/qgraphicsscene/testData/render/all-all-untransformed-clip-ellipse.png differ
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
new file mode 100644
index 0000000..1c59698
Binary files /dev/null and b/tests/auto/qgraphicsscene/testData/render/all-all-untransformed-clip-rect.png differ
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();
 
-- 
cgit v0.12