summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAndreas Aardal Hanssen <andreas.aardal.hanssen@nokia.com>2009-04-06 11:31:02 (GMT)
committerJason McDonald <jason.mcdonald@nokia.com>2009-04-15 10:24:21 (GMT)
commit66fe4167b123c644874216af4f1c1a2fb3c478b2 (patch)
tree3d16684d3db3cd9c8e2d84c1b7d513fc0660a353 /tests
parentfdff47ac6baebf0611f98e7e25c90d54413fbe06 (diff)
downloadQt-66fe4167b123c644874216af4f1c1a2fb3c478b2.zip
Qt-66fe4167b123c644874216af4f1c1a2fb3c478b2.tar.gz
Qt-66fe4167b123c644874216af4f1c1a2fb3c478b2.tar.bz2
Fixup update rect regression by adjusting expose rectangles.
This change shows a limitation in Graphics View caused by QPen's default width being 0 (cosmetic), while Graphics View actually does not support cosmetic pens at all. Because items are at risk of drawing lines that poke 1 pixel outside their bounding rect, QGraphicsView must look for items that are up to one pixel larger than their bounding rect mapped to viewport coordinates. Furthermore, mapToScene(QRect) forces us to adjust the input rectangle by (0, 0, 1, 1), because it uses QRect::bottomRight() (etc) when mapping the rectangle to a polygon (which is _wrong_). Since this behavior has been there since 4.2, we don't want to fix it in a 4.5 patch release... The only _proper_ fix to this problem is for the view to know the item's "adjust" in device coordinates, allowing items to use cosmetic pens freely. Fex, we could introduce QGraphicsItem::viewportMargins() or so. Added an autotest to ensure this doesn't break again. Reviewed-by: bnilsen (cherry picked from commit cc18633fe45d599bfeac2a8b2737d155f1dd5564)
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qgraphicsview/tst_qgraphicsview.cpp61
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/auto/qgraphicsview/tst_qgraphicsview.cpp b/tests/auto/qgraphicsview/tst_qgraphicsview.cpp
index e046514..535730a 100644
--- a/tests/auto/qgraphicsview/tst_qgraphicsview.cpp
+++ b/tests/auto/qgraphicsview/tst_qgraphicsview.cpp
@@ -155,6 +155,8 @@ private slots:
void fitInView();
void itemsAtPoint();
void itemsInRect();
+ void itemsInRect_cosmeticAdjust_data();
+ void itemsInRect_cosmeticAdjust();
void itemsInPoly();
void itemsInPath();
void itemAt();
@@ -1310,6 +1312,65 @@ void tst_QGraphicsView::itemsInRect()
QCOMPARE(items.takeFirst()->zValue(), qreal(3));
}
+class CountPaintItem : public QGraphicsRectItem
+{
+public:
+ int numPaints;
+
+ CountPaintItem(const QRectF &rect)
+ : QGraphicsRectItem(rect), numPaints(0)
+ { }
+
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0)
+ {
+ ++numPaints;
+ QGraphicsRectItem::paint(painter, option, widget);
+ }
+};
+
+void tst_QGraphicsView::itemsInRect_cosmeticAdjust_data()
+{
+ QTest::addColumn<QRect>("updateRect");
+ QTest::addColumn<int>("numPaints");
+
+ QTest::newRow("nil") << QRect() << 1;
+ QTest::newRow("0, 0, 300, 100") << QRect(0, 0, 300, 100) << 1;
+ QTest::newRow("0, 0, 100, 300") << QRect(0, 0, 100, 300) << 1;
+ QTest::newRow("200, 0, 100, 300") << QRect(200, 0, 100, 300) << 1;
+ QTest::newRow("0, 200, 300, 100") << QRect(0, 200, 300, 100) << 1;
+ QTest::newRow("0, 0, 300, 99") << QRect(0, 0, 300, 99) << 0;
+ QTest::newRow("0, 0, 99, 300") << QRect(0, 0, 99, 300) << 0;
+ QTest::newRow("201, 0, 99, 300") << QRect(201, 0, 99, 300) << 0;
+ QTest::newRow("0, 201, 300, 99") << QRect(0, 201, 300, 99) << 0;
+}
+
+void tst_QGraphicsView::itemsInRect_cosmeticAdjust()
+{
+ QFETCH(QRect, updateRect);
+ QFETCH(int, numPaints);
+
+ QGraphicsScene scene(-100, -100, 200, 200);
+ CountPaintItem *rect = new CountPaintItem(QRectF(-50, -50, 100, 100));
+ scene.addItem(rect);
+
+ QGraphicsView view(&scene);
+ view.setFrameStyle(0);
+ view.resize(300, 300);
+ view.show();
+#ifdef Q_WS_X11
+ qt_x11_wait_for_window_manager(&view);
+#endif
+ QTest::qWait(125);
+
+ rect->numPaints = 0;
+ if (updateRect.isNull())
+ view.viewport()->update();
+ else
+ view.viewport()->update(updateRect);
+ qApp->processEvents();
+ QCOMPARE(rect->numPaints, numPaints);
+}
+
void tst_QGraphicsView::itemsInPoly()
{
QGraphicsScene scene;