diff options
Diffstat (limited to 'tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp')
-rw-r--r-- | tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp | 128 |
1 files changed, 59 insertions, 69 deletions
diff --git a/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp b/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp index fa72e25baf..515ba80bbe 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2021 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QtWidgets/QApplication> #include <QtWidgets/QDial> @@ -321,27 +321,27 @@ void tst_QGraphicsScene::sceneRect() QGraphicsScene scene; QSignalSpy sceneRectChanged(&scene, &QGraphicsScene::sceneRectChanged); QCOMPARE(scene.sceneRect(), QRectF()); - QCOMPARE(sceneRectChanged.count(), 0); + QCOMPARE(sceneRectChanged.size(), 0); QGraphicsRectItem *item = scene.addRect(QRectF(0, 0, 10, 10)); item->setPen(QPen(Qt::black, 0)); item->setPos(-5, -5); - QCOMPARE(sceneRectChanged.count(), 0); + QCOMPARE(sceneRectChanged.size(), 0); QCOMPARE(itemAt(scene, 0, 0), item); QVERIFY(scene.items(QPointF(10, 10)).isEmpty()); - QCOMPARE(sceneRectChanged.count(), 0); + QCOMPARE(sceneRectChanged.size(), 0); QCOMPARE(scene.sceneRect(), QRectF(-5, -5, 10, 10)); - QCOMPARE(sceneRectChanged.count(), 1); + QCOMPARE(sceneRectChanged.size(), 1); QCOMPARE(sceneRectChanged.last().at(0).toRectF(), scene.sceneRect()); item->setPos(0, 0); QCOMPARE(scene.sceneRect(), QRectF(-5, -5, 15, 15)); - QCOMPARE(sceneRectChanged.count(), 2); + QCOMPARE(sceneRectChanged.size(), 2); QCOMPARE(sceneRectChanged.last().at(0).toRectF(), scene.sceneRect()); scene.setSceneRect(-100, -100, 10, 10); - QCOMPARE(sceneRectChanged.count(), 3); + QCOMPARE(sceneRectChanged.size(), 3); QCOMPARE(sceneRectChanged.last().at(0).toRectF(), scene.sceneRect()); QCOMPARE(itemAt(scene, 0, 0), item); @@ -349,16 +349,16 @@ void tst_QGraphicsScene::sceneRect() QCOMPARE(scene.sceneRect(), QRectF(-100, -100, 10, 10)); item->setPos(10, 10); QCOMPARE(scene.sceneRect(), QRectF(-100, -100, 10, 10)); - QCOMPARE(sceneRectChanged.count(), 3); + QCOMPARE(sceneRectChanged.size(), 3); QCOMPARE(sceneRectChanged.last().at(0).toRectF(), scene.sceneRect()); scene.setSceneRect(QRectF()); QCOMPARE(itemAt(scene, 10, 10), item); QVERIFY(scene.items(QPointF(20, 20)).isEmpty()); - QCOMPARE(sceneRectChanged.count(), 4); + QCOMPARE(sceneRectChanged.size(), 4); QCOMPARE(scene.sceneRect(), QRectF(-5, -5, 25, 25)); - QCOMPARE(sceneRectChanged.count(), 5); + QCOMPARE(sceneRectChanged.size(), 5); QCOMPARE(sceneRectChanged.last().at(0).toRectF(), scene.sceneRect()); } @@ -534,7 +534,7 @@ void tst_QGraphicsScene::itemsBoundingRect() QGraphicsScene scene; - for (const auto &rect : qAsConst(rects)) { + for (const auto &rect : std::as_const(rects)) { QPainterPath path; path.addRect(rect); QGraphicsPathItem *item = scene.addPath(path); @@ -599,7 +599,7 @@ void tst_QGraphicsScene::items_QPointF() int n = 0; QList<QGraphicsItem *> addedItems; - for (const auto &rect : qAsConst(items)) { + for (const auto &rect : std::as_const(items)) { QPainterPath path; path.addRect(0, 0, rect.width(), rect.height()); @@ -946,32 +946,32 @@ void tst_QGraphicsScene::selectionChanged() { QGraphicsScene scene(0, 0, 1000, 1000); QSignalSpy spy(&scene, &QGraphicsScene::selectionChanged); - QCOMPARE(spy.count(), 0); + QCOMPARE(spy.size(), 0); QPainterPath path; path.addRect(scene.sceneRect()); QCOMPARE(scene.selectionArea(), QPainterPath()); scene.setSelectionArea(path); QCOMPARE(scene.selectionArea(), path); - QCOMPARE(spy.count(), 0); // selection didn't change + QCOMPARE(spy.size(), 0); // selection didn't change QVERIFY(scene.selectedItems().isEmpty()); QGraphicsItem *rect = scene.addRect(QRectF(0, 0, 100, 100)); - QCOMPARE(spy.count(), 0); // selection didn't change + QCOMPARE(spy.size(), 0); // selection didn't change rect->setSelected(true); QVERIFY(!rect->isSelected()); - QCOMPARE(spy.count(), 0); // selection didn't change, item isn't selectable + QCOMPARE(spy.size(), 0); // selection didn't change, item isn't selectable rect->setFlag(QGraphicsItem::ItemIsSelectable); rect->setSelected(true); QVERIFY(rect->isSelected()); - QCOMPARE(spy.count(), 1); // selection changed + QCOMPARE(spy.size(), 1); // selection changed QCOMPARE(scene.selectedItems(), {rect}); rect->setSelected(false); QVERIFY(!rect->isSelected()); - QCOMPARE(spy.count(), 2); // selection changed + QCOMPARE(spy.size(), 2); // selection changed QVERIFY(scene.selectedItems().isEmpty()); QGraphicsEllipseItem *parentItem = new QGraphicsEllipseItem(QRectF(0, 0, 100, 100)); @@ -983,33 +983,33 @@ void tst_QGraphicsScene::selectionChanged() grandChildItem->setSelected(true); scene.addItem(parentItem); - QCOMPARE(spy.count(), 3); // the grandchild was added, so the selection changed once + QCOMPARE(spy.size(), 3); // the grandchild was added, so the selection changed once scene.removeItem(parentItem); - QCOMPARE(spy.count(), 4); // the grandchild was removed, so the selection changed + QCOMPARE(spy.size(), 4); // the grandchild was removed, so the selection changed rect->setSelected(true); - QCOMPARE(spy.count(), 5); // the rect was reselected, so the selection changed + QCOMPARE(spy.size(), 5); // the rect was reselected, so the selection changed scene.clearSelection(); - QCOMPARE(spy.count(), 6); // the scene selection was cleared + QCOMPARE(spy.size(), 6); // the scene selection was cleared rect->setSelected(true); - QCOMPARE(spy.count(), 7); // the rect was reselected, so the selection changed + QCOMPARE(spy.size(), 7); // the rect was reselected, so the selection changed rect->setFlag(QGraphicsItem::ItemIsSelectable, false); - QCOMPARE(spy.count(), 8); // the rect was unselected, so the selection changed + QCOMPARE(spy.size(), 8); // the rect was unselected, so the selection changed rect->setSelected(true); - QCOMPARE(spy.count(), 8); // the rect is not longer selectable, so the selection does not change + QCOMPARE(spy.size(), 8); // the rect is not longer selectable, so the selection does not change rect->setFlag(QGraphicsItem::ItemIsSelectable, true); rect->setSelected(true); - QCOMPARE(spy.count(), 9); // the rect is again selectable, so the selection changed + QCOMPARE(spy.size(), 9); // the rect is again selectable, so the selection changed delete rect; - QCOMPARE(spy.count(), 10); // a selected item was deleted; selection changed + QCOMPARE(spy.size(), 10); // a selected item was deleted; selection changed } void tst_QGraphicsScene::selectionChanged2() @@ -1022,7 +1022,7 @@ void tst_QGraphicsScene::selectionChanged2() item1->setFlag(QGraphicsItem::ItemIsSelectable); item2->setFlag(QGraphicsItem::ItemIsSelectable); - QCOMPARE(spy.count(), 0); + QCOMPARE(spy.size(), 0); { QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMousePress); event.setScenePos(QPointF(50, 50)); @@ -1037,7 +1037,7 @@ void tst_QGraphicsScene::selectionChanged2() } QVERIFY(item1->isSelected()); QVERIFY(!item2->isSelected()); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); { QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMousePress); event.setScenePos(QPointF(150, 150)); @@ -1052,7 +1052,7 @@ void tst_QGraphicsScene::selectionChanged2() } QVERIFY(!item1->isSelected()); QVERIFY(item2->isSelected()); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); { QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMousePress); event.setScenePos(QPointF(50, 50)); @@ -1062,7 +1062,7 @@ void tst_QGraphicsScene::selectionChanged2() } QVERIFY(!item1->isSelected()); QVERIFY(item2->isSelected()); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); { QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseRelease); event.setScenePos(QPointF(50, 50)); @@ -1071,7 +1071,7 @@ void tst_QGraphicsScene::selectionChanged2() } QVERIFY(item1->isSelected()); QVERIFY(!item2->isSelected()); - QCOMPARE(spy.count(), 3); + QCOMPARE(spy.size(), 3); } void tst_QGraphicsScene::addItem() @@ -1294,7 +1294,6 @@ void tst_QGraphicsScene::removeItem() view.setWindowTitle(QTest::currentTestFunction()); view.setFixedSize(150, 150); view.show(); - QApplicationPrivate::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowActive(&view)); QTest::mouseMove(view.windowHandle(), view.mapFromScene(hoverItem->scenePos() + QPointF(20, 20))); QTRY_VERIFY(!hoverItem->isHovered); @@ -1602,7 +1601,6 @@ void tst_QGraphicsScene::hoverEvents_siblings() view.rotate(10); view.scale(1.7, 1.7); view.show(); - QApplicationPrivate::setActiveWindow(&view); view.activateWindow(); QVERIFY(QTest::qWaitForWindowActive(&view)); @@ -1672,7 +1670,6 @@ void tst_QGraphicsScene::hoverEvents_parentChild() view.rotate(10); view.scale(1.7, 1.7); view.show(); - QApplicationPrivate::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowActive(&view)); QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMouseMove); @@ -1734,7 +1731,7 @@ void tst_QGraphicsScene::createItemGroup() // All items in children1 are children of parent1 QGraphicsItem *parent1 = scene.addRect(QRectF(-10, -10, 20, 20)); - for (QGraphicsItem *item : qAsConst(children1)) + for (QGraphicsItem *item : std::as_const(children1)) item->setParentItem(parent1); QGraphicsItemGroup *group = scene.createItemGroup(children1); @@ -1750,7 +1747,7 @@ void tst_QGraphicsScene::createItemGroup() // All items in children2 are children of parent2 QGraphicsItem *parent2 = scene.addRect(QRectF(-10, -10, 20, 20)); - for (QGraphicsItem *item : qAsConst(children2)) + for (QGraphicsItem *item : std::as_const(children2)) item->setParentItem(parent2); // Now make parent2 a child of parent1, so all children2 are also children @@ -1774,7 +1771,7 @@ void tst_QGraphicsScene::createItemGroup() QCOMPARE(children2.first()->parentItem(), parent1); // Fixup the parent-child chain - for (QGraphicsItem *item : qAsConst(children2)) + for (QGraphicsItem *item : std::as_const(children2)) item->setParentItem(parent2); // These share no common parent @@ -1784,7 +1781,7 @@ void tst_QGraphicsScene::createItemGroup() // Make children3 children of parent3 QGraphicsItem *parent3 = scene.addRect(QRectF(-10, -10, 20, 20)); - for (QGraphicsItem *item : qAsConst(children3)) + for (QGraphicsItem *item : std::as_const(children3)) item->setParentItem(parent3); // These should have parent3 as a parent @@ -2680,6 +2677,9 @@ void tst_QGraphicsScene::renderItemsWithNegativeWidthOrHeight() #ifdef Q_OS_ANDROID QSKIP("Test only works on platforms with resizable windows"); #endif + if (QGuiApplication::platformName().startsWith(QLatin1String("eglfs"), Qt::CaseInsensitive)) + QSKIP("EGLFS does not allow resizing on top window"); + QGraphicsScene scene(0, 0, m_testSize.width(), m_testSize.height()); // Add item with negative width. @@ -2834,7 +2834,7 @@ void tst_QGraphicsScene::update() QCoreApplication::processEvents(); // Check that the update region is correct - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); QRectF region; const auto &rects = qvariant_cast<QList<QRectF> >(spy.at(0).at(0)); for (const auto &rectF : rects) @@ -2851,7 +2851,6 @@ void tst_QGraphicsScene::update2() view.resize(m_testSize); view.setScene(&scene); view.show(); - QApplicationPrivate::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowActive(&view)); QTRY_VERIFY(view.repaints >= 1); view.repaints = 0; @@ -3041,7 +3040,6 @@ void tst_QGraphicsScene::tabFocus_emptyScene() widget.setLayout(layout); widget.setWindowTitle(QTest::currentTestFunction()); widget.show(); - QApplicationPrivate::setActiveWindow(&widget); widget.activateWindow(); QVERIFY(QTest::qWaitForWindowActive(&widget)); @@ -3093,7 +3091,6 @@ void tst_QGraphicsScene::tabFocus_sceneWithFocusableItems() widget.setWindowTitle(QTest::currentTestFunction()); widget.setLayout(layout); widget.show(); - QApplicationPrivate::setActiveWindow(&widget); widget.activateWindow(); QVERIFY(QTest::qWaitForWindowActive(&widget)); @@ -3533,7 +3530,7 @@ void tst_QGraphicsScene::task160653_selectionChanged() QVERIFY(QTest::qWaitForWindowActive(&view)); QTest::mouseClick( view.viewport(), Qt::LeftButton, {}, view.mapFromScene(scene.items().first()->scenePos())); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); } void tst_QGraphicsScene::task250680_childClip() @@ -3822,7 +3819,6 @@ void tst_QGraphicsScene::inputMethod() view.resize(m_testSize); view.show(); view.setWindowTitle(QTest::currentTestFunction()); - QApplicationPrivate::setActiveWindow(&view); view.setFocus(); QVERIFY(QTest::qWaitForWindowActive(&view)); QCOMPARE(QApplication::activeWindow(), &view); @@ -4066,7 +4062,6 @@ void tst_QGraphicsScene::isActive() view1->setVisible(false); toplevel1.show(); - QApplicationPrivate::setActiveWindow(&toplevel1); QVERIFY(QTest::qWaitForWindowActive(&toplevel1)); QCOMPARE(QApplication::activeWindow(), &toplevel1); @@ -4243,7 +4238,6 @@ void tst_QGraphicsScene::isActive() toplevel3.show(); - QApplicationPrivate::setActiveWindow(&toplevel3); QVERIFY(QTest::qWaitForWindowActive(&toplevel3)); QCOMPARE(QApplication::activeWindow(), &toplevel3); @@ -4356,7 +4350,6 @@ void tst_QGraphicsScene::removeFullyTransparentItem() view.resize(m_testSize); view.setScene(&scene); view.show(); - QApplicationPrivate::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowActive(&view)); QCoreApplication::processEvents(); // Process all queued paint events @@ -4623,17 +4616,17 @@ void tst_QGraphicsScene::focusItemChangedSignal() QGraphicsScene scene; QSignalSpy spy(&scene, &QGraphicsScene::focusItemChanged); QVERIFY(spy.isValid()); - QCOMPARE(spy.count(), 0); + QCOMPARE(spy.size(), 0); scene.setFocus(); - QCOMPARE(spy.count(), 0); + QCOMPARE(spy.size(), 0); QEvent activateEvent(QEvent::WindowActivate); QCoreApplication::sendEvent(&scene, &activateEvent); - QCOMPARE(spy.count(), 0); + QCOMPARE(spy.size(), 0); QGraphicsRectItem *topLevelItem1 = new QGraphicsRectItem; topLevelItem1->setFlag(QGraphicsItem::ItemIsFocusable); scene.addItem(topLevelItem1); - QCOMPARE(spy.count(), 0); + QCOMPARE(spy.size(), 0); QVERIFY(!topLevelItem1->hasFocus()); QGraphicsRectItem *topLevelItem2 = new QGraphicsRectItem; @@ -4641,7 +4634,7 @@ void tst_QGraphicsScene::focusItemChangedSignal() topLevelItem2->setFocus(); QVERIFY(!topLevelItem2->hasFocus()); scene.addItem(topLevelItem2); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); QList<QVariant> arguments = spy.takeFirst(); QCOMPARE(arguments.size(), 3); QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(0)), topLevelItem2); @@ -4650,7 +4643,7 @@ void tst_QGraphicsScene::focusItemChangedSignal() QVERIFY(topLevelItem2->hasFocus()); scene.clearFocus(); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); arguments = spy.takeFirst(); QCOMPARE(arguments.size(), 3); QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(0)), nullptr); @@ -4658,7 +4651,7 @@ void tst_QGraphicsScene::focusItemChangedSignal() QCOMPARE(qvariant_cast<Qt::FocusReason>(arguments.at(2)), Qt::OtherFocusReason); scene.setFocus(Qt::MenuBarFocusReason); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); arguments = spy.takeFirst(); QCOMPARE(arguments.size(), 3); QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(0)), topLevelItem2); @@ -4687,16 +4680,16 @@ void tst_QGraphicsScene::focusItemChangedSignal() QEvent deactivateEvent(QEvent::WindowDeactivate); QCoreApplication::sendEvent(&scene, &deactivateEvent); QEXPECT_FAIL("", "QTBUG-28346", Continue); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); QCoreApplication::sendEvent(&scene, &activateEvent); QEXPECT_FAIL("", "QTBUG-28346", Continue); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); QGraphicsRectItem *panel1 = new QGraphicsRectItem; panel1->setFlags(QGraphicsItem::ItemIsPanel | QGraphicsItem::ItemIsFocusable); panel1->setFocus(); scene.addItem(panel1); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); arguments = spy.takeFirst(); QCOMPARE(arguments.size(), 3); QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(0)), panel1); @@ -4706,11 +4699,11 @@ void tst_QGraphicsScene::focusItemChangedSignal() QGraphicsRectItem *panel2 = new QGraphicsRectItem; panel2->setFlags(QGraphicsItem::ItemIsPanel | QGraphicsItem::ItemIsFocusable); scene.addItem(panel2); - QCOMPARE(spy.count(), 0); + QCOMPARE(spy.size(), 0); for (int i = 0; i < 3; ++i) { scene.setActivePanel(panel2); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); arguments = spy.takeFirst(); QCOMPARE(arguments.size(), 3); QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(0)), panel2); @@ -4718,7 +4711,7 @@ void tst_QGraphicsScene::focusItemChangedSignal() QCOMPARE(qvariant_cast<Qt::FocusReason>(arguments.at(2)), Qt::ActiveWindowFocusReason); scene.setActivePanel(panel1); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); arguments = spy.takeFirst(); QCOMPARE(arguments.size(), 3); QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(0)), panel1); @@ -4814,7 +4807,6 @@ void tst_QGraphicsScene::focusOnTouch() rect->setFlag(QGraphicsItem::ItemIsFocusable, true); view.show(); - QApplicationPrivate::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowActive(&view)); QVERIFY(!rect->hasFocus()); @@ -4865,23 +4857,23 @@ void tst_QGraphicsScene::clearSelection() scene.addItem(regularRect); scene.addItem(selectedRect); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); QCOMPARE(scene.selectedItems().size(), 2); scene.clearSelection(); QVERIFY(!regularRect->isSelected()); QVERIFY(selectedRect->isSelected()); QCOMPARE(scene.selectedItems().size(), 1); - QCOMPARE(spy.count(), 3); + QCOMPARE(spy.size(), 3); delete regularRect; - QCOMPARE(spy.count(), 3); + QCOMPARE(spy.size(), 3); scene.clearSelection(); - QCOMPARE(spy.count(), 3); + QCOMPARE(spy.size(), 3); delete selectedRect; - QCOMPARE(spy.count(), 4); + QCOMPARE(spy.size(), 4); } void tst_QGraphicsScene::taskQTBUG_15977_renderWithDeviceCoordinateCache() @@ -4915,7 +4907,6 @@ void tst_QGraphicsScene::taskQTBUG_16401_focusItem() rect->setFlag(QGraphicsItem::ItemIsFocusable); view.show(); - QApplicationPrivate::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowActive(&view)); QVERIFY(!scene.focusItem()); @@ -4957,7 +4948,6 @@ void tst_QGraphicsScene::taskQTBUG_42915_focusNextPrevChild() widget2->setFocusPolicy(Qt::NoFocus); view.show(); - QApplicationPrivate::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowActive(&view)); QTest::keyEvent(QTest::Click, &view, Qt::Key_Tab); |