summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAndreas Aardal Hanssen <andreas.aardal.hanssen@nokia.com>2009-04-15 08:23:08 (GMT)
committerAndreas Aardal Hanssen <andreas.aardal.hanssen@nokia.com>2009-04-15 08:38:59 (GMT)
commit7a0f9ae94ca7a47dc285431d31f6839c07870194 (patch)
treeac46d83f38015a708237574db351db2c2af9380f /tests
parentb33ebce3de3efd98a45c8ca0a349f78aac09c875 (diff)
downloadQt-7a0f9ae94ca7a47dc285431d31f6839c07870194.zip
Qt-7a0f9ae94ca7a47dc285431d31f6839c07870194.tar.gz
Qt-7a0f9ae94ca7a47dc285431d31f6839c07870194.tar.bz2
BT: Fix a regression to 4.4 in Graphics View's handling of child clippers
Regression caused by optimizations in QGraphicsItem and QGraphicsScene. The changes in QGraphicsItem fix bugs in QGraphicsItem::mapToParent functions, which did the translation before applying the transformation, instead of the other way (transform, then translate). This bug caused almost all mapToParent and mapRectToParent functions to behave wrongly. Unfortunately the new helper functions in QGraphicsScene for discovering items made use of these functions, which introduced a regression. Fixing these functions also fixes item discovery. The other part of this change fixes a regression caused by c1909321, which luckily happened after 4.5.0 and never saw the light of day. The fix is to also invalidate the cached clip path even if there is no scene, which is necessary if you build your scene graph outside the scene, and finish off by adding the root item to the scene. Task-number: 250680 Reviewed-by: Alexis
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp83
-rw-r--r--tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp26
2 files changed, 109 insertions, 0 deletions
diff --git a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
index 5dd7e1e..2d1be37 100644
--- a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
+++ b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
@@ -162,6 +162,8 @@ private slots:
void mapFromToParent();
void mapFromToScene();
void mapFromToItem();
+ void mapRectFromToParent_data();
+ void mapRectFromToParent();
void isAncestorOf();
void commonAncestorItem();
void data();
@@ -2515,6 +2517,87 @@ void tst_QGraphicsItem::mapFromToItem()
delete item4;
}
+void tst_QGraphicsItem::mapRectFromToParent_data()
+{
+ QTest::addColumn<bool>("parent");
+ QTest::addColumn<QPointF>("parentPos");
+ QTest::addColumn<QTransform>("parentTransform");
+ QTest::addColumn<QPointF>("pos");
+ QTest::addColumn<QTransform>("transform");
+ QTest::addColumn<QRectF>("inputRect");
+ QTest::addColumn<QRectF>("outputRect");
+
+ QTest::newRow("nil") << false << QPointF() << QTransform() << QPointF() << QTransform() << QRectF() << QRectF();
+ QTest::newRow("simple") << false << QPointF() << QTransform() << QPointF() << QTransform()
+ << QRectF(0, 0, 10, 10) << QRectF(0, 0, 10, 10);
+ QTest::newRow("simple w/parent") << true
+ << QPointF() << QTransform()
+ << QPointF() << QTransform()
+ << QRectF(0, 0, 10, 10) << QRectF(0, 0, 10, 10);
+ QTest::newRow("simple w/parent parentPos") << true
+ << QPointF(50, 50) << QTransform()
+ << QPointF() << QTransform()
+ << QRectF(0, 0, 10, 10) << QRectF(0, 0, 10, 10);
+ QTest::newRow("simple w/parent parentPos parentRotation") << true
+ << QPointF(50, 50) << QTransform().rotate(45)
+ << QPointF() << QTransform()
+ << QRectF(0, 0, 10, 10) << QRectF(0, 0, 10, 10);
+ QTest::newRow("pos w/parent") << true
+ << QPointF() << QTransform()
+ << QPointF(50, 50) << QTransform()
+ << QRectF(0, 0, 10, 10) << QRectF(50, 50, 10, 10);
+ QTest::newRow("rotation w/parent") << true
+ << QPointF() << QTransform()
+ << QPointF() << QTransform().rotate(90)
+ << QRectF(0, 0, 10, 10) << QRectF(-10, 0, 10, 10);
+ QTest::newRow("pos rotation w/parent") << true
+ << QPointF() << QTransform()
+ << QPointF(50, 50) << QTransform().rotate(90)
+ << QRectF(0, 0, 10, 10) << QRectF(40, 50, 10, 10);
+ QTest::newRow("pos rotation w/parent parentPos parentRotation") << true
+ << QPointF(-170, -190) << QTransform().rotate(90)
+ << QPointF(50, 50) << QTransform().rotate(90)
+ << QRectF(0, 0, 10, 10) << QRectF(40, 50, 10, 10);
+}
+
+void tst_QGraphicsItem::mapRectFromToParent()
+{
+ QFETCH(bool, parent);
+ QFETCH(QPointF, parentPos);
+ QFETCH(QTransform, parentTransform);
+ QFETCH(QPointF, pos);
+ QFETCH(QTransform, transform);
+ QFETCH(QRectF, inputRect);
+ QFETCH(QRectF, outputRect);
+
+ QGraphicsRectItem *rect = new QGraphicsRectItem;
+ rect->setPos(pos);
+ rect->setTransform(transform);
+
+ if (parent) {
+ QGraphicsRectItem *rectParent = new QGraphicsRectItem;
+ rect->setParentItem(rectParent);
+ rectParent->setPos(parentPos);
+ rectParent->setTransform(parentTransform);
+ }
+
+ // Make sure we use non-destructive transform operations (e.g., 90 degree
+ // rotations).
+ QCOMPARE(rect->mapRectToParent(inputRect), outputRect);
+ QCOMPARE(rect->mapRectFromParent(outputRect), inputRect);
+ QCOMPARE(rect->itemTransform(rect->parentItem()).mapRect(inputRect), outputRect);
+ QCOMPARE(rect->mapToParent(inputRect).boundingRect(), outputRect);
+ QCOMPARE(rect->mapToParent(QPolygonF(inputRect)).boundingRect(), outputRect);
+ QCOMPARE(rect->mapFromParent(outputRect).boundingRect(), inputRect);
+ QCOMPARE(rect->mapFromParent(QPolygonF(outputRect)).boundingRect(), inputRect);
+ QPainterPath inputPath;
+ inputPath.addRect(inputRect);
+ QPainterPath outputPath;
+ outputPath.addRect(outputRect);
+ QCOMPARE(rect->mapToParent(inputPath).boundingRect(), outputPath.boundingRect());
+ QCOMPARE(rect->mapFromParent(outputPath).boundingRect(), inputPath.boundingRect());
+}
+
void tst_QGraphicsItem::isAncestorOf()
{
QGraphicsItem *grandPa = new QGraphicsRectItem;
diff --git a/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp b/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp
index 91ed851..354d81a 100644
--- a/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp
+++ b/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp
@@ -245,6 +245,7 @@ private slots:
void task139782_containsItemBoundingRect();
void task176178_itemIndexMethodBreaksSceneRect();
void task160653_selectionChanged();
+ void task250680_childClip();
};
void tst_QGraphicsScene::initTestCase()
@@ -3384,6 +3385,31 @@ void tst_QGraphicsScene::task160653_selectionChanged()
QCOMPARE(spy.count(), 1);
}
+void tst_QGraphicsScene::task250680_childClip()
+{
+ QGraphicsRectItem *clipper = new QGraphicsRectItem;
+ clipper->setFlag(QGraphicsItem::ItemClipsChildrenToShape);
+ clipper->setPen(QPen(Qt::green));
+ clipper->setRect(200, 200, 640, 480);
+
+ QGraphicsRectItem *rect = new QGraphicsRectItem(clipper);
+ rect->setPen(QPen(Qt::red));
+ rect->setBrush(QBrush(QColor(255, 0, 0, 75)));
+ rect->setPos(320, 240);
+ rect->setRect(-25, -25, 50, 50);
+
+ QGraphicsScene scene;
+ scene.addItem(clipper);
+
+ QPainterPath path;
+ path.addRect(-25, -25, 50, 50);
+ QCOMPARE(rect->clipPath(), path);
+
+ QCOMPARE(scene.items(QRectF(320, 240, 5, 5)).size(), 2);
+ rect->rotate(45);
+ QCOMPARE(scene.items(QRectF(320, 240, 5, 5)).size(), 2);
+}
+
void tst_QGraphicsScene::sorting_data()
{
QTest::addColumn<bool>("cache");