diff options
Diffstat (limited to 'tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp')
-rw-r--r-- | tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp | 268 |
1 files changed, 138 insertions, 130 deletions
diff --git a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp index 4a5a66dd05..60dc7a7288 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp @@ -1,31 +1,26 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. ** -** $QT_BEGIN_LICENSE:LGPL21$ +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. ** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** As a special exception, The Qt Company gives you certain additional -** rights. These rights are described in The Qt Company LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. ** ** $QT_END_LICENSE$ ** @@ -310,7 +305,7 @@ private slots: void selected_textItem(); void selected_multi(); void acceptedMouseButtons(); - void acceptsHoverEvents(); + void acceptHoverEvents(); void childAcceptsHoverEvents(); void hasFocus(); void pos(); @@ -385,7 +380,9 @@ private slots: void itemContainsChildrenInShape2(); void ancestorFlags(); void untransformable(); +#ifndef QT_NO_CONTEXTMENU void contextMenuEventPropagation(); +#endif // QT_NO_CONTEXTMENU void itemIsMovable(); void boundingRegion_data(); void boundingRegion(); @@ -564,9 +561,9 @@ void tst_QGraphicsItem::construction() QVERIFY(!item->isSelected()); QCOMPARE(item->acceptedMouseButtons(), Qt::MouseButtons(0x1f)); if (item->type() == QGraphicsTextItem::Type) - QVERIFY(item->acceptsHoverEvents()); + QVERIFY(item->acceptHoverEvents()); else - QVERIFY(!item->acceptsHoverEvents()); + QVERIFY(!item->acceptHoverEvents()); QVERIFY(!item->hasFocus()); QCOMPARE(item->pos(), QPointF()); QCOMPARE(item->matrix(), QMatrix()); @@ -1125,11 +1122,11 @@ void tst_QGraphicsItem::visible() scene.addItem(item); QVERIFY(item->isVisible()); - QCOMPARE(scene.itemAt(0, 0), item); + QCOMPARE(scene.items(QPointF(0, 0)).value(0, Q_NULLPTR), item); item->setVisible(false); - QCOMPARE(scene.itemAt(0, 0), (QGraphicsItem *)0); + QVERIFY(scene.items(QPointF(0, 0)).isEmpty()); item->setVisible(true); - QCOMPARE(scene.itemAt(0, 0), item); + QCOMPARE(scene.items(QPointF(0, 0)).value(0, Q_NULLPTR), item); QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMousePress); event.setButton(Qt::LeftButton); @@ -1930,7 +1927,7 @@ protected: { ++hoverOutCount; } }; -void tst_QGraphicsItem::acceptsHoverEvents() +void tst_QGraphicsItem::acceptHoverEvents() { QGraphicsScene scene; HoverItem *item1 = new HoverItem(QRectF(-10, -10, 20, 20)); @@ -1939,10 +1936,10 @@ void tst_QGraphicsItem::acceptsHoverEvents() scene.addItem(item2); item2->setZValue(1); - QVERIFY(!item1->acceptsHoverEvents()); - QVERIFY(!item2->acceptsHoverEvents()); - item1->setAcceptsHoverEvents(true); - item2->setAcceptsHoverEvents(true); + QVERIFY(!item1->acceptHoverEvents()); + QVERIFY(!item2->acceptHoverEvents()); + item1->setAcceptHoverEvents(true); + item2->setAcceptHoverEvents(true); QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseMove); event.setScenePos(QPointF(-100, -100)); @@ -1953,8 +1950,8 @@ void tst_QGraphicsItem::acceptsHoverEvents() QCOMPARE(item1->hoverInCount, 0); QCOMPARE(item2->hoverInCount, 1); - item1->setAcceptsHoverEvents(false); - item2->setAcceptsHoverEvents(false); + item1->setAcceptHoverEvents(false); + item2->setAcceptHoverEvents(false); event.setScenePos(QPointF(-100, -100)); QApplication::sendEvent(&scene, &event); @@ -1964,8 +1961,8 @@ void tst_QGraphicsItem::acceptsHoverEvents() QCOMPARE(item1->hoverInCount, 0); QCOMPARE(item2->hoverInCount, 1); - item1->setAcceptsHoverEvents(true); - item2->setAcceptsHoverEvents(false); + item1->setAcceptHoverEvents(true); + item2->setAcceptHoverEvents(false); event.setScenePos(QPointF(-100, -100)); QApplication::sendEvent(&scene, &event); @@ -2168,27 +2165,27 @@ void tst_QGraphicsItem::matrix() line.resetMatrix(); QCOMPARE(line.matrix(), QMatrix()); - line.rotate(90); + line.setTransform(QTransform().rotate(90), true); QCOMPARE(line.matrix(), QMatrix().rotate(90)); - line.rotate(90); + line.setTransform(QTransform().rotate(90), true); QCOMPARE(line.matrix(), QMatrix().rotate(90).rotate(90)); line.resetMatrix(); - line.scale(2, 4); + line.setTransform(QTransform::fromScale(2, 4), true); QCOMPARE(line.matrix(), QMatrix().scale(2, 4)); - line.scale(2, 4); + line.setTransform(QTransform::fromScale(2, 4), true); QCOMPARE(line.matrix(), QMatrix().scale(2, 4).scale(2, 4)); line.resetMatrix(); - line.shear(2, 4); + line.setTransform(QTransform().shear(2, 4), true); QCOMPARE(line.matrix(), QMatrix().shear(2, 4)); - line.shear(2, 4); + line.setTransform(QTransform().shear(2, 4), true); QCOMPARE(line.matrix(), QMatrix().shear(2, 4).shear(2, 4)); line.resetMatrix(); - line.translate(10, 10); + line.setTransform(QTransform::fromTranslate(10, 10), true); QCOMPARE(line.matrix(), QMatrix().translate(10, 10)); - line.translate(10, 10); + line.setTransform(QTransform::fromTranslate(10, 10), true); QCOMPARE(line.matrix(), QMatrix().translate(10, 10).translate(10, 10)); line.resetMatrix(); } @@ -2201,15 +2198,15 @@ void tst_QGraphicsItem::sceneMatrix() QCOMPARE(parent->sceneMatrix(), QMatrix()); QCOMPARE(child->sceneMatrix(), QMatrix()); - parent->translate(10, 10); + parent->setTransform(QTransform::fromTranslate(10, 10), true); QCOMPARE(parent->sceneMatrix(), QMatrix().translate(10, 10)); QCOMPARE(child->sceneMatrix(), QMatrix().translate(10, 10)); - child->translate(10, 10); + child->setTransform(QTransform::fromTranslate(10, 10), true); QCOMPARE(parent->sceneMatrix(), QMatrix().translate(10, 10)); QCOMPARE(child->sceneMatrix(), QMatrix().translate(20, 20)); - parent->rotate(90); + parent->setTransform(QTransform().rotate(90), true); QCOMPARE(parent->sceneMatrix(), QMatrix().translate(10, 10).rotate(90)); QCOMPARE(child->sceneMatrix(), QMatrix().translate(10, 10).rotate(90).translate(10, 10)); @@ -2645,7 +2642,7 @@ void tst_QGraphicsItem::isObscuredBy() MyItem myitem1, myitem2; myitem1.setRect(QRectF(50, 50, 40, 200)); - myitem1.rotate(67); + myitem1.setTransform(QTransform().rotate(67), true); myitem2.setRect(QRectF(25, 25, 20, 20)); myitem2.setZValue(-1.0); @@ -3272,7 +3269,7 @@ void tst_QGraphicsItem::hoverEventsGenerateRepaints() EventTester *tester = new EventTester; scene.addItem(tester); - tester->setAcceptsHoverEvents(true); + tester->setAcceptHoverEvents(true); QTRY_COMPARE(tester->repaints, 1); @@ -3364,7 +3361,7 @@ void tst_QGraphicsItem::sceneBoundingRect() QCOMPARE(item->boundingRect(), QRectF(0, 0, 100, 100)); QCOMPARE(item->sceneBoundingRect(), QRectF(100, 100, 100, 100)); - item->rotate(90); + item->setTransform(QTransform().rotate(90), true); QCOMPARE(item->boundingRect(), QRectF(0, 0, 100, 100)); QCOMPARE(item->sceneBoundingRect(), QRectF(0, 100, 100, 100)); @@ -3392,7 +3389,7 @@ void tst_QGraphicsItem::childrenBoundingRect() QGraphicsRectItem *childChild = scene.addRect(QRectF(0, 0, 100, 100), QPen(Qt::black, 0)); childChild->setParentItem(child); childChild->setPos(500, 500); - child->rotate(90); + child->setTransform(QTransform().rotate(90), true); scene.addPolygon(parent->mapToScene(parent->boundingRect() | parent->childrenBoundingRect()))->setPen(QPen(Qt::red));; @@ -3440,11 +3437,11 @@ void tst_QGraphicsItem::childrenBoundingRectTransformed() QCOMPARE(subTreeRect.width(), qreal(351.7766952966369)); QCOMPARE(subTreeRect.height(), qreal(251.7766952966369)); - rect->rotate(45); - rect2->rotate(-45); - rect3->rotate(45); - rect4->rotate(-45); - rect5->rotate(45); + rect->setTransform(QTransform().rotate(45), true); + rect2->setTransform(QTransform().rotate(-45), true); + rect3->setTransform(QTransform().rotate(45), true); + rect4->setTransform(QTransform().rotate(-45), true); + rect5->setTransform(QTransform().rotate(45), true); subTreeRect = rect->childrenBoundingRect(); QCOMPARE(rect->childrenBoundingRect(), QRectF(-100, 75, 275, 250)); @@ -3566,7 +3563,7 @@ void tst_QGraphicsItem::group() QGraphicsRectItem *child = scene.addRect(QRectF(0, 0, 50, 50), QPen(Qt::black, 0), QBrush(Qt::blue)); QGraphicsRectItem *parent2 = scene.addRect(QRectF(0, 0, 50, 50), QPen(Qt::black, 0), QBrush(Qt::red)); parent2->setPos(-50, 50); - child->rotate(45); + child->setTransform(QTransform().rotate(45), true); child->setParentItem(parent); parent->setPos(25, 25); child->setPos(25, 25); @@ -3615,7 +3612,7 @@ void tst_QGraphicsItem::group() newItems << item; item->setPos(-1000 + rand() % 2000, -1000 + rand() % 2000); - item->rotate(rand() % 90); + item->setTransform(QTransform().rotate(rand() % 90), true); } view.fitInView(scene.itemsBoundingRect()); @@ -3658,8 +3655,8 @@ void tst_QGraphicsItem::setGroup2() rect->setTransformOriginPoint(50,50); rect->setRotation(45); rect->setScale(1.5); - rect->translate(20,20); - group.translate(-30,-40); + rect->setTransform(QTransform::fromTranslate(20,20), true); + group.setTransform(QTransform::fromTranslate(-30, -40), true); group.setRotation(180); group.setScale(0.5); @@ -3712,7 +3709,7 @@ void tst_QGraphicsItem::warpChildrenIntoGroup() QGraphicsScene scene; QGraphicsRectItem *parentRectItem = scene.addRect(QRectF(0, 0, 100, 100)); QGraphicsRectItem *childRectItem = scene.addRect(QRectF(0, 0, 100, 100)); - parentRectItem->rotate(90); + parentRectItem->setTransform(QTransform().rotate(90), true); childRectItem->setPos(-50, -25); childRectItem->setParentItem(parentRectItem); @@ -3721,7 +3718,7 @@ void tst_QGraphicsItem::warpChildrenIntoGroup() QGraphicsRectItem *parentOfGroup = scene.addRect(QRectF(0, 0, 100, 100)); parentOfGroup->setPos(-200, -200); - parentOfGroup->scale(2, 2); + parentOfGroup->setTransform(QTransform::fromScale(2, 2), true); QGraphicsItemGroup *group = new QGraphicsItemGroup; group->setPos(50, 50); @@ -4129,9 +4126,9 @@ public: font.setPointSize(4); painter->setFont(font); for (int x = -100; x < 100; x += 25) { - for (int y = -100; y < 100; y += 25) { - painter->drawText(QRectF(x, y, 25, 25), Qt::AlignCenter, QString("%1x%2").arg(x).arg(y)); - } + const QString prefix = QString::number(x) + QLatin1Char('x'); + for (int y = -100; y < 100; y += 25) + painter->drawText(QRectF(x, y, 25, 25), Qt::AlignCenter, prefix + QString::number(y)); } } }; @@ -4634,7 +4631,7 @@ void tst_QGraphicsItem::itemChange() // ItemTransformChange / ItemTransformHasChanged tester.itemChangeReturnValue.setValue<QTransform>(QTransform().rotate(90)); - tester.translate(50, 0); + tester.setTransform(QTransform::fromTranslate(50, 0), true); ++changeCount; // notification sent too ++changeCount; QCOMPARE(tester.changes.size(), changeCount); @@ -5197,6 +5194,7 @@ public: } protected: +#ifndef QT_NO_CONTEXTMENU void contextMenuEvent(QGraphicsSceneContextMenuEvent *) { if (harakiri == 3) { @@ -5204,6 +5202,7 @@ protected: delete this; } } +#endif // QT_NO_CONTEXTMENU void dragEnterEvent(QGraphicsSceneDragDropEvent *event) { @@ -5366,7 +5365,7 @@ void tst_QGraphicsItem::deleteItemInEventHandlers() for (int i = 0; i < 17; ++i) { QGraphicsScene scene; HarakiriItem *item = new HarakiriItem(i); - item->setAcceptsHoverEvents(true); + item->setAcceptHoverEvents(true); item->setFlag(QGraphicsItem::ItemIsFocusable); scene.addItem(item); @@ -5382,11 +5381,13 @@ void tst_QGraphicsItem::deleteItemInEventHandlers() if (!item->dead) scene.advance(); +#ifndef QT_NO_CONTEXTMENU if (!item->dead) { QContextMenuEvent event(QContextMenuEvent::Other, view.mapFromScene(item->scenePos())); QCoreApplication::sendEvent(view.viewport(), &event); } +#endif // QT_NO_CONTEXTMENU if (!item->dead) QTest::mouseMove(view.viewport(), view.mapFromScene(item->scenePos())); if (!item->dead) @@ -5518,16 +5519,16 @@ void tst_QGraphicsItem::itemClipsChildrenToShape2() QGraphicsScene scene; scene.addItem(parent); - QCOMPARE(scene.itemAt(5, 5), (QGraphicsItem *)parent); - QCOMPARE(scene.itemAt(15, 5), (QGraphicsItem *)0); - QCOMPARE(scene.itemAt(5, 15), (QGraphicsItem *)0); - QCOMPARE(scene.itemAt(60, 60), (QGraphicsItem *)0); - QCOMPARE(scene.itemAt(140, 60), (QGraphicsItem *)0); - QCOMPARE(scene.itemAt(60, 140), (QGraphicsItem *)0); - QCOMPARE(scene.itemAt(140, 140), (QGraphicsItem *)0); - QCOMPARE(scene.itemAt(75, 75), (QGraphicsItem *)child2); - QCOMPARE(scene.itemAt(75, 100), (QGraphicsItem *)child1); - QCOMPARE(scene.itemAt(100, 75), (QGraphicsItem *)child1); + QCOMPARE(scene.items(QPointF(5, 5)).value(0, Q_NULLPTR), (QGraphicsItem *)parent); + QVERIFY(scene.items(QPointF(15, 5)).isEmpty()); + QVERIFY(scene.items(QPointF(5, 15)).isEmpty()); + QVERIFY(scene.items(QPointF(60, 60)).isEmpty()); + QVERIFY(scene.items(QPointF(140, 60)).isEmpty()); + QVERIFY(scene.items(QPointF(60, 140)).isEmpty()); + QVERIFY(scene.items(QPointF(140, 140)).isEmpty()); + QCOMPARE(scene.items(QPointF(75, 75)).value(0, Q_NULLPTR), (QGraphicsItem *)child2); + QCOMPARE(scene.items(QPointF(75, 100)).value(0, Q_NULLPTR), (QGraphicsItem *)child1); + QCOMPARE(scene.items(QPointF(100, 75)).value(0, Q_NULLPTR), (QGraphicsItem *)child1); QImage image(100, 100, QImage::Format_ARGB32_Premultiplied); image.fill(0); @@ -5562,20 +5563,20 @@ void tst_QGraphicsItem::itemClipsChildrenToShape3() grandchild->setPos( 50, 50 ); parent->setFlag(QGraphicsItem::ItemClipsChildrenToShape); - QCOMPARE(scene.itemAt(25,25), (QGraphicsItem *)parent); - QCOMPARE(scene.itemAt(75,75), (QGraphicsItem *)child); - QCOMPARE(scene.itemAt(125,125), (QGraphicsItem *)grandchild); - QCOMPARE(scene.itemAt(175,175), (QGraphicsItem *)0); + QCOMPARE(scene.items(QPointF(25, 25)).value(0, Q_NULLPTR), (QGraphicsItem *)parent); + QCOMPARE(scene.items(QPointF(75, 75)).value(0, Q_NULLPTR), (QGraphicsItem *)child); + QCOMPARE(scene.items(QPointF(125, 125)).value(0, Q_NULLPTR), (QGraphicsItem *)grandchild); + QVERIFY(scene.items(QPointF(175, 175)).isEmpty()); // Move child to fully overlap the parent. The grandchild should // now occupy two-thirds of the scene child->prepareGeometryChange(); child->setPos( 0, 0 ); - QCOMPARE(scene.itemAt(25,25), (QGraphicsItem *)child); - QCOMPARE(scene.itemAt(75,75), (QGraphicsItem *)grandchild); - QCOMPARE(scene.itemAt(125,125), (QGraphicsItem *)grandchild); - QCOMPARE(scene.itemAt(175,175), (QGraphicsItem *)0); + QCOMPARE(scene.items(QPointF(25, 25)).value(0, Q_NULLPTR), (QGraphicsItem *)child); + QCOMPARE(scene.items(QPointF(75, 75)).value(0, Q_NULLPTR), (QGraphicsItem *)grandchild); + QCOMPARE(scene.items(QPointF(125, 125)).value(0, Q_NULLPTR), (QGraphicsItem *)grandchild); + QVERIFY(scene.items(QPointF(175, 175)).isEmpty()); } class MyProxyWidget : public QGraphicsProxyWidget @@ -5847,17 +5848,17 @@ void tst_QGraphicsItem::itemClippingDiscovery() rightRectItem->setParentItem(clipItem); // The rects item are both visible at these points. - QCOMPARE(scene.itemAt(10, 10), (QGraphicsItem *)leftRectItem); - QCOMPARE(scene.itemAt(90, 90), (QGraphicsItem *)rightRectItem); + QCOMPARE(scene.items(QPointF(10, 10)).value(0, Q_NULLPTR), (QGraphicsItem *)leftRectItem); + QCOMPARE(scene.items(QPointF(90, 90)).value(0, Q_NULLPTR), (QGraphicsItem *)rightRectItem); // The ellipse clips the rects now. clipItem->setFlag(QGraphicsItem::ItemClipsChildrenToShape); // The rect items are no longer visible at these points. - QCOMPARE(scene.itemAt(10, 10), (QGraphicsItem *)0); + QVERIFY(scene.items(QPointF(10, 10)).isEmpty()); if (sizeof(qreal) != sizeof(double)) QSKIP("This fails due to internal rounding errors"); - QCOMPARE(scene.itemAt(90, 90), (QGraphicsItem *)0); + QVERIFY(scene.items(QPointF(90, 90)).isEmpty()); } class ItemCountsBoundingRectCalls : public QGraphicsRectItem @@ -5888,7 +5889,7 @@ void tst_QGraphicsItem::itemContainsChildrenInShape() int oldChildBoundingRectCalls = childOutsideShape->boundingRectCalls; // First test that both items are searched if no optimization flags are set - QGraphicsItem* item = scene.itemAt(25,5); + QGraphicsItem* item = scene.items(QPointF(25, 5)).value(0, Q_NULLPTR); QCOMPARE(item, childOutsideShape); QVERIFY(parent->boundingRectCalls > oldParentBoundingRectCalls); @@ -5899,7 +5900,7 @@ void tst_QGraphicsItem::itemContainsChildrenInShape() oldChildBoundingRectCalls = childOutsideShape->boundingRectCalls; // Repeat the test to make sure that no caching/indexing is in effect - item = scene.itemAt(25,5); + item = scene.items(QPointF(25, 5)).value(0, Q_NULLPTR); QCOMPARE(item, childOutsideShape); QVERIFY(parent->boundingRectCalls > oldParentBoundingRectCalls); @@ -5912,7 +5913,7 @@ void tst_QGraphicsItem::itemContainsChildrenInShape() // Set the optimization flag and make sure that the child is not returned // and that the child's boundingRect() method is never called. parent->setFlag(QGraphicsItem::ItemContainsChildrenInShape); - item = scene.itemAt(25,5); + item = scene.items(QPointF(25, 5)).value(0, Q_NULLPTR); QVERIFY(!(item)); QVERIFY(parent->boundingRectCalls > oldParentBoundingRectCalls); @@ -6220,12 +6221,12 @@ void tst_QGraphicsItem::untransformable() QGraphicsItem *item1 = new QGraphicsEllipseItem(QRectF(-50, -50, 100, 100)); item1->setZValue(1); item1->setFlag(QGraphicsItem::ItemIgnoresTransformations); - item1->rotate(45); + item1->setTransform(QTransform().rotate(45), true); ((QGraphicsEllipseItem *)item1)->setBrush(Qt::red); QGraphicsItem *item2 = new QGraphicsEllipseItem(QRectF(-50, -50, 100, 100)); item2->setParentItem(item1); - item2->rotate(45); + item2->setTransform(QTransform().rotate(45), true); item2->setPos(100, 0); ((QGraphicsEllipseItem *)item2)->setBrush(Qt::green); @@ -6280,6 +6281,7 @@ void tst_QGraphicsItem::untransformable() } } +#ifndef QT_NO_CONTEXTMENU class ContextMenuItem : public QGraphicsRectItem { public: @@ -6343,6 +6345,7 @@ void tst_QGraphicsItem::contextMenuEventPropagation() QCOMPARE(bottomItem->gotEvent, false); QCOMPARE(topItem->eventWasAccepted, true); } +#endif // QT_NO_CONTEXTMENU void tst_QGraphicsItem::itemIsMovable() { @@ -6464,10 +6467,11 @@ void tst_QGraphicsItem::task177918_lineItemUndetected() QGraphicsLineItem *line = scene.addLine(10, 10, 10, 10); QCOMPARE(line->boundingRect(), QRectF(10, 10, 0, 0)); - QVERIFY(!scene.items(9, 9, 2, 2, Qt::IntersectsItemShape).isEmpty()); - QVERIFY(!scene.items(9, 9, 2, 2, Qt::ContainsItemShape).isEmpty()); - QVERIFY(!scene.items(9, 9, 2, 2, Qt::IntersectsItemBoundingRect).isEmpty()); - QVERIFY(!scene.items(9, 9, 2, 2, Qt::ContainsItemBoundingRect).isEmpty()); + const QRectF rect(9, 9, 2, 2); + QVERIFY(!scene.items(rect, Qt::IntersectsItemShape).isEmpty()); + QVERIFY(!scene.items(rect, Qt::ContainsItemShape).isEmpty()); + QVERIFY(!scene.items(rect, Qt::IntersectsItemBoundingRect).isEmpty()); + QVERIFY(!scene.items(rect, Qt::ContainsItemBoundingRect).isEmpty()); } void tst_QGraphicsItem::task240400_clickOnTextItem_data() @@ -6703,8 +6707,8 @@ void tst_QGraphicsItem::itemTransform_parentChild() QGraphicsItem *child = scene.addRect(0, 0, 100, 100); child->setParentItem(parent); child->setPos(10, 10); - child->scale(2, 2); - child->rotate(90); + child->setTransform(QTransform::fromScale(2, 2), true); + child->setTransform(QTransform().rotate(90), true); QCOMPARE(child->itemTransform(parent).map(QPointF(10, 10)), QPointF(-10, 30)); QCOMPARE(parent->itemTransform(child).map(QPointF(-10, 30)), QPointF(10, 10)); @@ -6716,19 +6720,19 @@ void tst_QGraphicsItem::itemTransform_siblings() QGraphicsItem *parent = scene.addRect(0, 0, 100, 100); QGraphicsItem *brother = scene.addRect(0, 0, 100, 100); QGraphicsItem *sister = scene.addRect(0, 0, 100, 100); - parent->scale(10, 5); - parent->rotate(-180); - parent->shear(2, 3); + parent->setTransform(QTransform::fromScale(10, 5), true); + parent->setTransform(QTransform().rotate(-180), true); + parent->setTransform(QTransform().shear(2, 3), true); brother->setParentItem(parent); sister->setParentItem(parent); brother->setPos(10, 10); - brother->scale(2, 2); - brother->rotate(90); + brother->setTransform(QTransform::fromScale(2, 2), true); + brother->setTransform(QTransform().rotate(90), true); sister->setPos(10, 10); - sister->scale(2, 2); - sister->rotate(90); + sister->setTransform(QTransform::fromScale(2, 2), true); + sister->setTransform(QTransform().rotate(90), true); QCOMPARE(brother->itemTransform(sister).map(QPointF(10, 10)), QPointF(10, 10)); QCOMPARE(sister->itemTransform(brother).map(QPointF(10, 10)), QPointF(10, 10)); @@ -6740,11 +6744,11 @@ void tst_QGraphicsItem::itemTransform_unrelated() QGraphicsItem *stranger1 = scene.addRect(0, 0, 100, 100); QGraphicsItem *stranger2 = scene.addRect(0, 0, 100, 100); stranger1->setPos(10, 10); - stranger1->scale(2, 2); - stranger1->rotate(90); + stranger1->setTransform(QTransform::fromScale(2, 2), true); + stranger1->setTransform(QTransform().rotate(90), true); stranger2->setPos(10, 10); - stranger2->scale(2, 2); - stranger2->rotate(90); + stranger2->setTransform(QTransform::fromScale(2, 2), true); + stranger2->setTransform(QTransform().rotate(90), true); QCOMPARE(stranger1->itemTransform(stranger2).map(QPointF(10, 10)), QPointF(10, 10)); QCOMPARE(stranger2->itemTransform(stranger1).map(QPointF(10, 10)), QPointF(10, 10)); @@ -7026,7 +7030,8 @@ void tst_QGraphicsItem::itemStacksBehindParent() paintedItems.clear(); view.viewport()->update(); QApplication::processEvents(); - QTRY_COMPARE(scene.items(0, 0, 100, 100), (QList<QGraphicsItem *>() + QRectF rect(0, 0, 100, 100); + QTRY_COMPARE(scene.items(rect), (QList<QGraphicsItem *>() << grandChild111 << child11 << grandChild121 << child12 << parent1 << grandChild211 << child21 @@ -7042,7 +7047,7 @@ void tst_QGraphicsItem::itemStacksBehindParent() paintedItems.clear(); QApplication::processEvents(); - QTRY_COMPARE(scene.items(0, 0, 100, 100), (QList<QGraphicsItem *>() + QTRY_COMPARE(scene.items(rect), (QList<QGraphicsItem *>() << grandChild121 << child12 << parent1 << grandChild111 << child11 << grandChild211 << child21 @@ -7058,7 +7063,7 @@ void tst_QGraphicsItem::itemStacksBehindParent() scene.update(); QApplication::processEvents(); - QTRY_COMPARE(scene.items(0, 0, 100, 100), (QList<QGraphicsItem *>() + QTRY_COMPARE(scene.items(rect), (QList<QGraphicsItem *>() << parent1 << grandChild111 << child11 << grandChild121 << child12 << grandChild211 << child21 @@ -7226,12 +7231,12 @@ void tst_QGraphicsItem::sceneTransformCache() QGraphicsRectItem *rect2 = scene.addRect(0, 0, 100, 100); rect2->setPen(QPen(Qt::black, 0)); rect2->setParentItem(rect.data()); - rect2->rotate(90); - rect->translate(0, 50); + rect2->setTransform(QTransform().rotate(90), true); + rect->setTransform(QTransform::fromTranslate(0, 50), true); QGraphicsView view(&scene); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); - rect->translate(0, 100); + rect->setTransform(QTransform::fromTranslate(0, 100), true); QTransform x; x.translate(0, 150); x.rotate(90); @@ -7395,14 +7400,14 @@ void tst_QGraphicsItem::cacheMode() QCOMPARE(testerChild2->repaints, 2); // Translating does not result in a repaint. - tester->translate(10, 10); + tester->setTransform(QTransform::fromTranslate(10, 10), true); QTest::qWait(25); QTRY_COMPARE(tester->repaints, 2); QCOMPARE(testerChild->repaints, 2); QCOMPARE(testerChild2->repaints, 2); // Rotating results in a repaint. - tester->rotate(45); + tester->setTransform(QTransform().rotate(45), true); QTest::qWait(25); QTRY_COMPARE(tester->repaints, 3); QCOMPARE(testerChild->repaints, 3); @@ -7418,9 +7423,9 @@ void tst_QGraphicsItem::cacheMode() QCOMPARE(testerChild2->repaints, 3); // Rotating items with ItemCoordinateCache doesn't cause a repaint. - tester->rotate(22); - testerChild->rotate(22); - testerChild2->rotate(22); + tester->setTransform(QTransform().rotate(22), true); + testerChild->setTransform(QTransform().rotate(22), true); + testerChild2->setTransform(QTransform().rotate(22), true); QTest::qWait(25); QTRY_COMPARE(tester->repaints, 4); QTRY_COMPARE(testerChild->repaints, 4); @@ -7653,7 +7658,9 @@ public: void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) { QGraphicsRectItem::paint(painter, option, widget); - painter->drawText(boundingRect(), Qt::AlignCenter, QString("%1x%2\n%3x%4").arg(p.x()).arg(p.y()).arg(sp.x()).arg(sp.y())); + const QString text = QString::number(p.x()) + QLatin1Char('x') + QString::number(p.y()) + + QLatin1Char('\n') + QString::number(sp.x()) + QLatin1Char('x') + QString::number(sp.y()); + painter->drawText(boundingRect(), Qt::AlignCenter, text); } protected: @@ -7733,9 +7740,9 @@ void tst_QGraphicsItem::deviceTransform() rect1->setPos(100, 100); rect2->setPos(100, 100); rect3->setPos(100, 100); - rect1->rotate(rotation1); - rect2->rotate(rotation2); - rect3->rotate(rotation3); + rect1->setTransform(QTransform().rotate(rotation1), true); + rect2->setTransform(QTransform().rotate(rotation2), true); + rect3->setTransform(QTransform().rotate(rotation3), true); rect1->setFlag(QGraphicsItem::ItemIgnoresTransformations, untransformable1); rect2->setFlag(QGraphicsItem::ItemIgnoresTransformations, untransformable2); rect3->setFlag(QGraphicsItem::ItemIgnoresTransformations, untransformable3); @@ -7868,14 +7875,14 @@ void tst_QGraphicsItem::update() expectedRegion = itemDeviceBoundingRect.adjusted(-2, -2, 2, 2); view.reset(); item->repaints = 0; - parent->translate(-400, 0); + parent->setTransform(QTransform::fromTranslate(-400, 0), true); qApp->processEvents(); QCOMPARE(item->repaints, 0); QCOMPARE(view.repaints, 1); QCOMPARE(view.paintedRegion, expectedRegion); view.reset(); item->repaints = 0; - parent->translate(400, 0); + parent->setTransform(QTransform::fromTranslate(400, 0), true); qApp->processEvents(); QCOMPARE(item->repaints, 1); QCOMPARE(view.repaints, 1); @@ -8175,7 +8182,7 @@ void tst_QGraphicsItem::moveItem() RESET_COUNTERS - parent->translate(20, 20); + parent->setTransform(QTransform::fromTranslate(20, 20), true); qApp->processEvents(); QCOMPARE(parent->repaints, 1); QCOMPARE(child->repaints, 1); @@ -8241,10 +8248,11 @@ void tst_QGraphicsItem::sorting() QGraphicsScene scene; QGraphicsItem *grid[100][100]; for (int x = 0; x < 100; ++x) { + const QString prefix = QString::number(x) + QLatin1Char('x'); for (int y = 0; y < 100; ++y) { PainterItem *item = new PainterItem; item->setPos(x * 25, y * 25); - item->setData(0, QString("%1x%2").arg(x).arg(y)); + item->setData(0, prefix + QString::number(y)); grid[x][y] = item; scene.addItem(item); } @@ -11646,12 +11654,12 @@ void tst_QGraphicsItem::QTBUG_21618_untransformable_sceneTransform() QGraphicsItem *item1 = scene.addRect(0, 0, 100, 100, QPen(), Qt::red); item1->setPos(50, 50); - item1->translate(50, 50); - item1->rotate(90); + item1->setTransform(QTransform::fromTranslate(50, 50), true); + item1->setTransform(QTransform().rotate(90), true); QGraphicsItem *item2 = scene.addRect(0, 0, 100, 100, QPen(), Qt::green); item2->setPos(50, 50); - item2->translate(50, 50); - item2->rotate(90); + item2->setTransform(QTransform::fromTranslate(50, 50), true); + item2->setTransform(QTransform().rotate(90), true); item2->setFlags(QGraphicsItem::ItemIgnoresTransformations); QGraphicsRectItem *item1_topleft = new QGraphicsRectItem(QRectF(-2, -2, 4, 4)); |