diff options
Diffstat (limited to 'tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp')
-rw-r--r-- | tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp | 73 |
1 files changed, 43 insertions, 30 deletions
diff --git a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp index e848fa627d..35356adcfc 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 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 <QTest> @@ -40,6 +40,8 @@ #include <QtGui/private/qeventpoint_p.h> +#include <QtWidgets/private/qapplication_p.h> + using AbstractGraphicsShapeItemPtr = QSharedPointer<QAbstractGraphicsShapeItem>; using GraphicsItems = QList<QGraphicsItem *>; using GraphicsItemsList = QList<QGraphicsItem *>; @@ -991,7 +993,6 @@ void tst_QGraphicsItem::inputMethodHints() scene.addItem(item); scene.addItem(item2); QGraphicsView view(&scene); - QApplication::setActiveWindow(&view); view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); @@ -1048,7 +1049,6 @@ void tst_QGraphicsItem::toolTip() view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.setFixedSize(200, 200); view.show(); - QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowExposed(&view)); QVERIFY(QTest::qWaitForWindowActive(&view)); { @@ -2206,7 +2206,7 @@ void tst_QGraphicsItem::setTransform() scene.update(scene.sceneRect()); QCoreApplication::processEvents(); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); item.setTransform(QTransform().rotate(qreal(12.34))); QRectF rotatedRect = scene.sceneRect(); @@ -2214,14 +2214,14 @@ void tst_QGraphicsItem::setTransform() scene.update(scene.sceneRect()); QCoreApplication::processEvents(); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); item.setTransform(QTransform()); scene.update(scene.sceneRect()); QCoreApplication::processEvents(); - QCOMPARE(spy.count(), 3); + QCOMPARE(spy.size(), 3); QList<QRectF> rlist = qvariant_cast<QList<QRectF> >(spy.last().at(0)); QCOMPARE(rlist.size(), 2); @@ -3374,7 +3374,7 @@ void tst_QGraphicsItem::childrenBoundingRect() childChild->setPos(500, 500); child->setTransform(QTransform().rotate(90), true); - scene.addPolygon(parent->mapToScene(parent->boundingRect() | parent->childrenBoundingRect()))->setPen(QPen(Qt::red));; + scene.addPolygon(parent->mapToScene(parent->boundingRect() | parent->childrenBoundingRect()))->setPen(QPen(Qt::red)); QGraphicsView view(&scene); view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); @@ -3601,7 +3601,7 @@ void tst_QGraphicsItem::group() view.fitInView(scene.itemsBoundingRect()); - for (QGraphicsItem *item : qAsConst(newItems)) { + for (QGraphicsItem *item : std::as_const(newItems)) { group->addToGroup(item); QCOMPARE(item->group(), group); } @@ -4944,7 +4944,6 @@ void tst_QGraphicsItem::sceneEventFilter() QGraphicsView view(&scene); view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); - QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowExposed(&view)); QVERIFY(QTest::qWaitForWindowActive(&view)); @@ -5565,7 +5564,6 @@ void tst_QGraphicsItem::itemClipsChildrenToShape4() scene.addEllipse( 100, 100, 100, 50 ); // <-- this is important to trigger the right codepath* //now the label is shown outerWidget->setFlag(QGraphicsItem::ItemClipsChildrenToShape, false ); - QApplication::setActiveWindow(&view); view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); QTRY_COMPARE(QApplication::activeWindow(), &view); @@ -5681,7 +5679,7 @@ void tst_QGraphicsItem::itemClipsChildrenToShape5() } const QList<QGraphicsItem *> children = parent->childItems(); - const int childrenCount = children.count(); + const int childrenCount = children.size(); for (int i = 0; i < 5; ++i) { QString clipString; @@ -6909,8 +6907,10 @@ void tst_QGraphicsItem::opacityZeroUpdates() view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); - if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) { + view.window()->activateWindow(); QVERIFY(QTest::qWaitForWindowActive(&view)); + } QCoreApplication::processEvents(); // Process all queued paint events QTRY_VERIFY(view.repaints > 0); @@ -7266,6 +7266,7 @@ void tst_QGraphicsItem::tabChangesFocus() widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); widget.setLayout(layout); widget.show(); + view->window()->activateWindow(); QVERIFY(QTest::qWaitForWindowActive(&widget)); QTRY_VERIFY(scene.isActive()); @@ -7300,7 +7301,7 @@ void tst_QGraphicsItem::cacheMode() view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.resize(150, 150); view.show(); - QApplication::setActiveWindow(&view); + view.window()->activateWindow(); QVERIFY(QTest::qWaitForWindowExposed(&view)); QVERIFY(QTest::qWaitForWindowActive(&view)); QCoreApplication::processEvents(); // Process all queued paint events @@ -7484,7 +7485,7 @@ void tst_QGraphicsItem::cacheMode2() view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.resize(150, 150); view.show(); - QApplication::setActiveWindow(&view); + view.window()->activateWindow(); QVERIFY(QTest::qWaitForWindowExposed(&view)); QVERIFY(QTest::qWaitForWindowActive(&view)); QCoreApplication::processEvents(); // Process all queued paint events @@ -8145,9 +8146,11 @@ void tst_QGraphicsItem::moveLineItem() MyGraphicsView view(&scene); view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); - QVERIFY(QTest::qWaitForWindowExposed(&view)); - if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) { + view.window()->activateWindow(); QVERIFY(QTest::qWaitForWindowActive(&view)); + } + QVERIFY(QTest::qWaitForWindowExposed(&view)); QCoreApplication::processEvents(); // Process all queued paint events view.reset(); @@ -8217,11 +8220,11 @@ void tst_QGraphicsItem::sorting() view.setFrameStyle(0); view.show(); if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) { - qApp->setActiveWindow(&view); + view.window()->activateWindow(); QVERIFY(QTest::qWaitForWindowActive(&view)); } QVERIFY(QTest::qWaitForWindowExposed(&view)); - QTRY_VERIFY(_paintedItems.count() > 0); + QTRY_VERIFY(_paintedItems.size() > 0); _paintedItems.clear(); @@ -8251,7 +8254,7 @@ void tst_QGraphicsItem::itemHasNoContents() view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) { - qApp->setActiveWindow(&view); + view.window()->activateWindow(); QVERIFY(QTest::qWaitForWindowActive(&view)); } QVERIFY(QTest::qWaitForWindowExposed(&view)); @@ -9271,7 +9274,7 @@ void tst_QGraphicsItem::ensureDirtySceneTransform() view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) { - QApplication::setActiveWindow(&view); + view.window()->activateWindow(); QVERIFY(QTest::qWaitForWindowActive(&view)); QCOMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&view)); } @@ -9669,7 +9672,7 @@ void tst_QGraphicsItem::QTBUG_4233_updateCachedWithSceneRect() QGraphicsView view(&scene); view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); - QApplication::setActiveWindow(&view); + view.window()->activateWindow(); QVERIFY(QTest::qWaitForWindowExposed(&view)); QVERIFY(QTest::qWaitForWindowActive(&view)); QCOMPARE(QApplication::activeWindow(), &view); @@ -10749,6 +10752,10 @@ void tst_QGraphicsItem::textItem_shortcuts() item->setFlag(QGraphicsItem::ItemIsFocusable); item->setTextInteractionFlags(Qt::TextEditorInteraction); w.show(); + if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) { + view.window()->activateWindow(); + QVERIFY(QTest::qWaitForWindowActive(&view)); + } QVERIFY(QTest::qWaitForWindowExposed(&w)); item->setFocus(); @@ -10803,8 +10810,10 @@ void tst_QGraphicsItem::scroll() view.setFrameStyle(0); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); - if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) { + view.window()->activateWindow(); QVERIFY(QTest::qWaitForWindowActive(&view)); + } QTRY_VERIFY(view.repaints > 0); view.reset(); @@ -10918,7 +10927,6 @@ void tst_QGraphicsItem::focusHandling() view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); - QApplication::setActiveWindow(&view); QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&view)); QVERIFY(itemWithFocus->hasFocus()); @@ -11323,7 +11331,7 @@ void tst_QGraphicsItem::QTBUG_6738_missingUpdateWithSetParent() view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) { - qApp->setActiveWindow(&view); + view.window()->activateWindow(); QVERIFY(QTest::qWaitForWindowActive(&view)); } QVERIFY(QTest::qWaitForWindowExposed(&view)); @@ -11377,8 +11385,10 @@ void tst_QGraphicsItem::QT_2653_fullUpdateDiscardingOpacityUpdate() view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); - if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) { + view.window()->activateWindow(); QVERIFY(QTest::qWaitForWindowActive(&view)); + } QCoreApplication::processEvents(); // Process all queued paint events view.reset(); @@ -11413,8 +11423,10 @@ void tst_QGraphicsItem::QTBUG_7714_fullUpdateDiscardingOpacityUpdate2() scene.addItem(parentGreen); origView.show(); - if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) { + view.window()->activateWindow(); QVERIFY(QTest::qWaitForWindowActive(&origView)); + } QVERIFY(QTest::qWaitForWindowExposed(&origView)); QCoreApplication::processEvents(); // Process all queued paint events @@ -11430,7 +11442,7 @@ void tst_QGraphicsItem::QTBUG_7714_fullUpdateDiscardingOpacityUpdate2() view.show(); if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) { - qApp->setActiveWindow(&view); + QApplicationPrivate::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowActive(&view)); } QVERIFY(QTest::qWaitForWindowExposed(&view)); @@ -11571,6 +11583,7 @@ void tst_QGraphicsItem::doNotMarkFullUpdateIfNotInScene() item2->setParentItem(item); scene.addItem(item); view.show(); + view.window()->activateWindow(); QVERIFY(QTest::qWaitForWindowExposed(view.windowHandle())); QVERIFY(QTest::qWaitForWindowActive(view.windowHandle())); QCoreApplication::processEvents(); // Process all queued paint events @@ -11605,7 +11618,7 @@ void tst_QGraphicsItem::itemDiesDuringDraggingOperation() scene.addItem(item); view.show(); if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) { - QApplication::setActiveWindow(&view); + view.window()->activateWindow(); QVERIFY(QTest::qWaitForWindowActive(&view)); QCOMPARE(QApplication::activeWindow(), &view); } @@ -11636,7 +11649,7 @@ void tst_QGraphicsItem::QTBUG_12112_focusItem() view.show(); if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) { - QApplication::setActiveWindow(&view); + view.window()->activateWindow(); QVERIFY(QTest::qWaitForWindowActive(&view)); QCOMPARE(QApplication::activeWindow(), &view); } @@ -11686,7 +11699,7 @@ public: QLatin1String wiseWords("AZ BUKI VEDI"); QString sentence(wiseWords); QStringList words = sentence.split(QLatin1Char(' '), Qt::SkipEmptyParts); - for (int i = 0; i < words.count(); ++i) { + for (int i = 0; i < words.size(); ++i) { QGraphicsProxyWidget *proxy = new QGraphicsProxyWidget(this); QLabel *label = new QLabel(words.at(i)); proxy->setWidget(label); |