diff options
Diffstat (limited to 'tests/auto/widgets/graphicsview')
45 files changed, 735 insertions, 459 deletions
diff --git a/tests/auto/widgets/graphicsview/CMakeLists.txt b/tests/auto/widgets/graphicsview/CMakeLists.txt index b480a04a8c..b0ea73b65e 100644 --- a/tests/auto/widgets/graphicsview/CMakeLists.txt +++ b/tests/auto/widgets/graphicsview/CMakeLists.txt @@ -1,4 +1,5 @@ -# Generated from graphicsview.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause if(QT_FEATURE_private_tests) add_subdirectory(qgraphicsanchorlayout) diff --git a/tests/auto/widgets/graphicsview/qgraphicsanchorlayout/BLACKLIST b/tests/auto/widgets/graphicsview/qgraphicsanchorlayout/BLACKLIST index ce0e42b3c7..fde971443d 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsanchorlayout/BLACKLIST +++ b/tests/auto/widgets/graphicsview/qgraphicsanchorlayout/BLACKLIST @@ -1,2 +1,2 @@ [layoutDirection] -ubuntu-20.04 +ubuntu-22.04 diff --git a/tests/auto/widgets/graphicsview/qgraphicsanchorlayout/CMakeLists.txt b/tests/auto/widgets/graphicsview/qgraphicsanchorlayout/CMakeLists.txt index 1d1e576299..2b530d39f3 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsanchorlayout/CMakeLists.txt +++ b/tests/auto/widgets/graphicsview/qgraphicsanchorlayout/CMakeLists.txt @@ -1,13 +1,20 @@ -# Generated from qgraphicsanchorlayout.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qgraphicsanchorlayout Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qgraphicsanchorlayout LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qgraphicsanchorlayout SOURCES tst_qgraphicsanchorlayout.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::Gui Qt::GuiPrivate diff --git a/tests/auto/widgets/graphicsview/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp b/tests/auto/widgets/graphicsview/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp index d8fa17280a..cf37aa5639 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.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> #include <QtWidgets/qgraphicsanchorlayout.h> diff --git a/tests/auto/widgets/graphicsview/qgraphicsanchorlayout1/CMakeLists.txt b/tests/auto/widgets/graphicsview/qgraphicsanchorlayout1/CMakeLists.txt index 11d2767c9e..62235c8d1b 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsanchorlayout1/CMakeLists.txt +++ b/tests/auto/widgets/graphicsview/qgraphicsanchorlayout1/CMakeLists.txt @@ -1,13 +1,20 @@ -# Generated from qgraphicsanchorlayout1.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qgraphicsanchorlayout1 Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qgraphicsanchorlayout1 LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qgraphicsanchorlayout1 SOURCES tst_qgraphicsanchorlayout1.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::Gui Qt::GuiPrivate diff --git a/tests/auto/widgets/graphicsview/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp b/tests/auto/widgets/graphicsview/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp index 8b4d8b0b68..9a047b876d 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.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 <QtGui> #include <QTest> @@ -1663,7 +1663,7 @@ void tst_QGraphicsAnchorLayout1::testBasicLayout() // Determine amount of widgets to add. int widgetCount = -1; - for (int i = 0; i < data.count(); ++i) { + for (int i = 0; i < data.size(); ++i) { const BasicLayoutTestData item = data[i]; widgetCount = qMax(widgetCount, item.firstIndex); widgetCount = qMax(widgetCount, item.secondIndex); @@ -1678,7 +1678,7 @@ void tst_QGraphicsAnchorLayout1::testBasicLayout() // Setup anchor layout TheAnchorLayout *layout = new TheAnchorLayout; - for (int i = 0; i < data.count(); ++i) { + for (int i = 0; i < data.size(); ++i) { const BasicLayoutTestData item = data[i]; layout->setAnchor( getItem(item.firstIndex, widgets, layout), @@ -1695,7 +1695,7 @@ void tst_QGraphicsAnchorLayout1::testBasicLayout() QCOMPARE(widget->size(), size); // Validate - for (int i = 0; i < result.count(); ++i) { + for (int i = 0; i < result.size(); ++i) { const BasicLayoutTestResult item = result[i]; QRectF expected = item.rect; QRectF actual = widgets[item.index]->geometry(); @@ -1707,7 +1707,7 @@ void tst_QGraphicsAnchorLayout1::testBasicLayout() widget->setLayoutDirection(Qt::RightToLeft); layout->activate(); // Validate - for (int j = 0; j < result.count(); ++j) { + for (int j = 0; j < result.size(); ++j) { const BasicLayoutTestResult item = result[j]; QRectF mirroredRect(item.rect); // only valid cases are mirrored @@ -2168,7 +2168,7 @@ void tst_QGraphicsAnchorLayout1::testRemoveCenterAnchor() // Determine amount of widgets to add. int widgetCount = -1; - for (int i = 0; i < data.count(); ++i) { + for (int i = 0; i < data.size(); ++i) { const BasicLayoutTestData item = data[i]; widgetCount = qMax(widgetCount, item.firstIndex); widgetCount = qMax(widgetCount, item.secondIndex); @@ -2185,7 +2185,7 @@ void tst_QGraphicsAnchorLayout1::testRemoveCenterAnchor() // Setup anchor layout TheAnchorLayout *layout = new TheAnchorLayout; - for (int i = 0; i < data.count(); ++i) { + for (int i = 0; i < data.size(); ++i) { const BasicLayoutTestData item = data[i]; layout->setAnchor( getItem(item.firstIndex, widgets, layout), @@ -2195,7 +2195,7 @@ void tst_QGraphicsAnchorLayout1::testRemoveCenterAnchor() item.spacing ); } - for (int i = 0; i < removeData.count(); ++i) { + for (int i = 0; i < removeData.size(); ++i) { const BasicLayoutTestData item = removeData[i]; layout->removeAnchor( getItem(item.firstIndex, widgets, layout), @@ -2211,7 +2211,7 @@ void tst_QGraphicsAnchorLayout1::testRemoveCenterAnchor() QCOMPARE(widget->size(), size); // Validate - for (int i = 0; i < result.count(); ++i) { + for (int i = 0; i < result.size(); ++i) { const BasicLayoutTestResult item = result[i]; QCOMPARE(widgets[item.index]->geometry(), item.rect); @@ -2999,7 +2999,7 @@ void tst_QGraphicsAnchorLayout1::testComplexCases() // Determine amount of widgets to add. int widgetCount = -1; - for (int i = 0; i < data.count(); ++i) { + for (int i = 0; i < data.size(); ++i) { const BasicLayoutTestData item = data[i]; widgetCount = qMax(widgetCount, item.firstIndex); widgetCount = qMax(widgetCount, item.secondIndex); @@ -3025,7 +3025,7 @@ void tst_QGraphicsAnchorLayout1::testComplexCases() // Setup anchor layout TheAnchorLayout *layout = new TheAnchorLayout; - for (int i = 0; i < data.count(); ++i) { + for (int i = 0; i < data.size(); ++i) { const BasicLayoutTestData item = data[i]; layout->setAnchor( getItem(item.firstIndex, widgets, layout), @@ -3042,7 +3042,7 @@ void tst_QGraphicsAnchorLayout1::testComplexCases() QCOMPARE(widget->size(), size); // Validate - for (int i = 0; i < result.count(); ++i) { + for (int i = 0; i < result.size(); ++i) { const BasicLayoutTestResult item = result[i]; QCOMPARE(widgets[item.index]->geometry(), item.rect); } @@ -3051,7 +3051,7 @@ void tst_QGraphicsAnchorLayout1::testComplexCases() widget->setLayoutDirection(Qt::RightToLeft); layout->activate(); // Validate - for (int j = 0; j < result.count(); ++j) { + for (int j = 0; j < result.size(); ++j) { const BasicLayoutTestResult item = result[j]; QRectF mirroredRect(item.rect); // only valid cases are mirrored diff --git a/tests/auto/widgets/graphicsview/qgraphicseffectsource/CMakeLists.txt b/tests/auto/widgets/graphicsview/qgraphicseffectsource/CMakeLists.txt index 5a4fda8234..1e198d7baa 100644 --- a/tests/auto/widgets/graphicsview/qgraphicseffectsource/CMakeLists.txt +++ b/tests/auto/widgets/graphicsview/qgraphicseffectsource/CMakeLists.txt @@ -1,13 +1,20 @@ -# Generated from qgraphicseffectsource.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qgraphicseffectsource Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qgraphicseffectsource LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qgraphicseffectsource SOURCES tst_qgraphicseffectsource.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::Gui Qt::GuiPrivate diff --git a/tests/auto/widgets/graphicsview/qgraphicseffectsource/tst_qgraphicseffectsource.cpp b/tests/auto/widgets/graphicsview/qgraphicseffectsource/tst_qgraphicseffectsource.cpp index 10c550efc0..28c439dbcd 100644 --- a/tests/auto/widgets/graphicsview/qgraphicseffectsource/tst_qgraphicseffectsource.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicseffectsource/tst_qgraphicseffectsource.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> #include <QtWidgets/qgraphicseffect.h> @@ -154,11 +154,11 @@ void tst_QGraphicsEffectSource::init() QVERIFY(effect); QVERIFY(item); QVERIFY(effect->source()); - effect->reset(); effect->storeDeviceDependentStuff = false; effect->doNothingInDraw = false; - item->reset(); QCoreApplication::processEvents(); // Process all queued paint events + effect->reset(); + item->reset(); } void tst_QGraphicsEffectSource::graphicsItem() diff --git a/tests/auto/widgets/graphicsview/qgraphicsgridlayout/CMakeLists.txt b/tests/auto/widgets/graphicsview/qgraphicsgridlayout/CMakeLists.txt index 0554d62807..c4ffe216f5 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsgridlayout/CMakeLists.txt +++ b/tests/auto/widgets/graphicsview/qgraphicsgridlayout/CMakeLists.txt @@ -1,13 +1,20 @@ -# Generated from qgraphicsgridlayout.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qgraphicsgridlayout Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qgraphicsgridlayout LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qgraphicsgridlayout SOURCES tst_qgraphicsgridlayout.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui Qt::Widgets ) diff --git a/tests/auto/widgets/graphicsview/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp b/tests/auto/widgets/graphicsview/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp index 04d1d0da59..fad75ec045 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsgridlayout/tst_qgraphicsgridlayout.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> @@ -1658,7 +1658,7 @@ void tst_QGraphicsGridLayout::sizeHint() widget->setContentsMargins(0, 0, 0, 0); int i; - for (i = 0; i < itemDescriptions.count(); ++i) { + for (i = 0; i < itemDescriptions.size(); ++i) { ItemDesc desc = itemDescriptions.at(i); RectWidget *item = new RectWidget(widget); desc.apply(layout, item); @@ -2159,7 +2159,7 @@ void tst_QGraphicsGridLayout::defaultStretchFactors() widget->setContentsMargins(0, 0, 0, 0); int i; - for (i = 0; i < itemDescriptions.count(); ++i) { + for (i = 0; i < itemDescriptions.size(); ++i) { ItemDesc desc = itemDescriptions.at(i); RectWidget *item = new RectWidget(widget); desc.apply(layout, item); @@ -2174,7 +2174,7 @@ void tst_QGraphicsGridLayout::defaultStretchFactors() widget->resize(newSize); QApplication::sendPostedEvents(0, 0); - for (i = 0; i < expectedSizes.count(); ++i) { + for (i = 0; i < expectedSizes.size(); ++i) { QSizeF itemSize = layout->itemAt(i)->geometry().size(); QCOMPARE(itemSize, expectedSizes.at(i)); } @@ -2318,7 +2318,7 @@ void tst_QGraphicsGridLayout::alignment2() widget->setContentsMargins(0, 0, 0, 0); int i; - for (i = 0; i < itemDescriptions.count(); ++i) { + for (i = 0; i < itemDescriptions.size(); ++i) { ItemDesc desc = itemDescriptions.at(i); RectWidget *item = new RectWidget(widget); desc.apply(layout, item); @@ -2333,7 +2333,7 @@ void tst_QGraphicsGridLayout::alignment2() widget->resize(newSize); QApplication::sendPostedEvents(0, 0); - for (i = 0; i < expectedGeometries.count(); ++i) { + for (i = 0; i < expectedGeometries.size(); ++i) { QRectF itemRect = layout->itemAt(i)->geometry(); QCOMPARE(itemRect, expectedGeometries.at(i)); } @@ -2896,7 +2896,7 @@ void tst_QGraphicsGridLayout::geometries() widget->setContentsMargins(0, 0, 0, 0); int i; - for (i = 0; i < itemDescriptions.count(); ++i) { + for (i = 0; i < itemDescriptions.size(); ++i) { ItemDesc desc = itemDescriptions.at(i); RectWidget *item = new RectWidget(widget); desc.apply(layout, item); @@ -2911,7 +2911,7 @@ void tst_QGraphicsGridLayout::geometries() widget->resize(newSize); QApplication::processEvents(); - for (i = 0; i < expectedGeometries.count(); ++i) { + for (i = 0; i < expectedGeometries.size(); ++i) { QRectF itemRect = layout->itemAt(i)->geometry(); QCOMPARE(itemRect, expectedGeometries.at(i)); } @@ -2976,11 +2976,6 @@ static QSizeF wfh(Qt::SizeHint /*which*/, const QSizeF &constraint) return result; } -bool qFuzzyCompare(const QSizeF &a, const QSizeF &b) -{ - return qFuzzyCompare(a.width(), b.width()) && qFuzzyCompare(a.height(), b.height()); -} - void tst_QGraphicsGridLayout::heightForWidth() { QGraphicsWidget *widget = new QGraphicsWidget; @@ -3156,7 +3151,6 @@ void tst_QGraphicsGridLayout::heightForWidthWithSpanning() QCOMPARE(layout->effectiveSizeHint(Qt::MaximumSize, QSizeF(200, -1)), QSizeF(200, 100)); } -Q_DECLARE_METATYPE(QSizePolicy::Policy) void tst_QGraphicsGridLayout::spanningItem2x2_data() { QTest::addColumn<QSizePolicy::Policy>("sizePolicy"); diff --git a/tests/auto/widgets/graphicsview/qgraphicsitem/BLACKLIST b/tests/auto/widgets/graphicsview/qgraphicsitem/BLACKLIST index 31dbb38a5d..c3de568a24 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsitem/BLACKLIST +++ b/tests/auto/widgets/graphicsview/qgraphicsitem/BLACKLIST @@ -1,4 +1,6 @@ # QTBUG-74760 [sorting] -opensuse-42.3 osx +# QTBUG-115293 +[itemUsesExtendedStyleOption] +wayland diff --git a/tests/auto/widgets/graphicsview/qgraphicsitem/CMakeLists.txt b/tests/auto/widgets/graphicsview/qgraphicsitem/CMakeLists.txt index 02a667eb9c..3ee507cd46 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsitem/CMakeLists.txt +++ b/tests/auto/widgets/graphicsview/qgraphicsitem/CMakeLists.txt @@ -1,15 +1,22 @@ -# Generated from qgraphicsitem.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qgraphicsitem Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qgraphicsitem LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qgraphicsitem SOURCES tst_qgraphicsitem.cpp DEFINES QT_NO_CAST_TO_ASCII - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::Gui Qt::GuiPrivate @@ -22,6 +29,6 @@ qt_internal_add_test(tst_qgraphicsitem ##################################################################### qt_internal_extend_target(tst_qgraphicsitem CONDITION WIN32 - PUBLIC_LIBRARIES + LIBRARIES user32 ) 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); diff --git a/tests/auto/widgets/graphicsview/qgraphicsitemanimation/CMakeLists.txt b/tests/auto/widgets/graphicsview/qgraphicsitemanimation/CMakeLists.txt index 48bb84d1bb..04bfb3f54a 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsitemanimation/CMakeLists.txt +++ b/tests/auto/widgets/graphicsview/qgraphicsitemanimation/CMakeLists.txt @@ -1,15 +1,22 @@ -# Generated from qgraphicsitemanimation.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qgraphicsitemanimation Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qgraphicsitemanimation LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qgraphicsitemanimation SOURCES tst_qgraphicsitemanimation.cpp DEFINES QT_NO_CAST_TO_ASCII - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui Qt::Widgets ) diff --git a/tests/auto/widgets/graphicsview/qgraphicsitemanimation/tst_qgraphicsitemanimation.cpp b/tests/auto/widgets/graphicsview/qgraphicsitemanimation/tst_qgraphicsitemanimation.cpp index 5f86ee4149..9cf74c23fe 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsitemanimation/tst_qgraphicsitemanimation.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsitemanimation/tst_qgraphicsitemanimation.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> diff --git a/tests/auto/widgets/graphicsview/qgraphicslayout/CMakeLists.txt b/tests/auto/widgets/graphicsview/qgraphicslayout/CMakeLists.txt index 768898549e..4951558423 100644 --- a/tests/auto/widgets/graphicsview/qgraphicslayout/CMakeLists.txt +++ b/tests/auto/widgets/graphicsview/qgraphicslayout/CMakeLists.txt @@ -1,15 +1,22 @@ -# Generated from qgraphicslayout.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qgraphicslayout Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qgraphicslayout LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qgraphicslayout SOURCES tst_qgraphicslayout.cpp DEFINES QT_USE_USING_NAMESPACE - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui Qt::Widgets ) diff --git a/tests/auto/widgets/graphicsview/qgraphicslayout/tst_qgraphicslayout.cpp b/tests/auto/widgets/graphicsview/qgraphicslayout/tst_qgraphicslayout.cpp index b5ba1d8787..268195d7d3 100644 --- a/tests/auto/widgets/graphicsview/qgraphicslayout/tst_qgraphicslayout.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicslayout/tst_qgraphicslayout.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> @@ -670,7 +670,7 @@ public: private slots: void valueChanged(qreal value) { - for (int i = 0; i < fromGeoms.count(); ++i) { + for (int i = 0; i < fromGeoms.size(); ++i) { QGraphicsLayoutItem *li = itemAt(i); QRectF from = fromGeoms.at(i); QRectF to = toGeoms.at(i); @@ -825,7 +825,7 @@ CustomLayout(QGraphicsLayoutItem *parent) int count() const override { - return items.count(); + return items.size(); } QGraphicsLayoutItem* itemAt(int index) const override @@ -841,12 +841,12 @@ void removeAt(int index) override void addItem(QGraphicsLayoutItem *item) { - insertItem(items.count(), item); + insertItem(items.size(), item); } void insertItem(int index, QGraphicsLayoutItem *item) { - index = qBound(0, index, items.count()); + index = qBound(0, index, items.size()); item->setParentLayoutItem(this); @@ -854,7 +854,7 @@ void insertItem(int index, QGraphicsLayoutItem *item) updateParentWidget(widget); - if (index == items.count()) { + if (index == items.size()) { items.append(item); } else { items.insert(index, item); @@ -922,7 +922,7 @@ void tst_QGraphicsLayout::ownership() destructedSet.clear(); window->setLayout(0); - QCOMPARE(destructedSet.count(), 0); + QCOMPARE(destructedSet.size(), 0); delete window; } diff --git a/tests/auto/widgets/graphicsview/qgraphicslayoutitem/CMakeLists.txt b/tests/auto/widgets/graphicsview/qgraphicslayoutitem/CMakeLists.txt index d927ec59aa..7bd25cecf2 100644 --- a/tests/auto/widgets/graphicsview/qgraphicslayoutitem/CMakeLists.txt +++ b/tests/auto/widgets/graphicsview/qgraphicslayoutitem/CMakeLists.txt @@ -1,13 +1,20 @@ -# Generated from qgraphicslayoutitem.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qgraphicslayoutitem Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qgraphicslayoutitem LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qgraphicslayoutitem SOURCES tst_qgraphicslayoutitem.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui Qt::Widgets ) diff --git a/tests/auto/widgets/graphicsview/qgraphicslayoutitem/tst_qgraphicslayoutitem.cpp b/tests/auto/widgets/graphicsview/qgraphicslayoutitem/tst_qgraphicslayoutitem.cpp index 2389d7668b..87b703a286 100644 --- a/tests/auto/widgets/graphicsview/qgraphicslayoutitem/tst_qgraphicslayoutitem.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicslayoutitem/tst_qgraphicslayoutitem.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> diff --git a/tests/auto/widgets/graphicsview/qgraphicslinearlayout/CMakeLists.txt b/tests/auto/widgets/graphicsview/qgraphicslinearlayout/CMakeLists.txt index 6c2e734348..b63bbb6f33 100644 --- a/tests/auto/widgets/graphicsview/qgraphicslinearlayout/CMakeLists.txt +++ b/tests/auto/widgets/graphicsview/qgraphicslinearlayout/CMakeLists.txt @@ -1,13 +1,20 @@ -# Generated from qgraphicslinearlayout.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qgraphicslinearlayout Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qgraphicslinearlayout LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qgraphicslinearlayout SOURCES tst_qgraphicslinearlayout.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui Qt::Widgets ) diff --git a/tests/auto/widgets/graphicsview/qgraphicslinearlayout/tst_qgraphicslinearlayout.cpp b/tests/auto/widgets/graphicsview/qgraphicslinearlayout/tst_qgraphicslinearlayout.cpp index ff625dbc00..65212e94cc 100644 --- a/tests/auto/widgets/graphicsview/qgraphicslinearlayout/tst_qgraphicslinearlayout.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicslinearlayout/tst_qgraphicslinearlayout.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> @@ -723,7 +723,7 @@ void tst_QGraphicsLinearLayout::orientation() // important to resize to preferredsize when orientation is switched widget->resize(widget->effectiveSizeHint(Qt::PreferredSize)); qApp->processEvents(); - for (i = 0; i < positions.count(); ++i) { + for (i = 0; i < positions.size(); ++i) { QGraphicsWidget *item = static_cast<QGraphicsWidget*>(layout.itemAt(i)); if (initialOrientation == Qt::Horizontal) QCOMPARE(item->pos().y(), positions.at(i)); @@ -1121,7 +1121,7 @@ void tst_QGraphicsLinearLayout::setStretchFactor() int i; - for (i = 0; i < stretches.count(); ++i) { + for (i = 0; i < stretches.size(); ++i) { QGraphicsWidget *item = new RectWidget(widget); item->setMinimumSize(5,5); item->setPreferredSize(10,5); @@ -1139,7 +1139,7 @@ void tst_QGraphicsLinearLayout::setStretchFactor() qreal firstStretch = -1; qreal firstExtent = -1.; qreal sumExtent = 0; - for (i = 0; i < stretches.count(); ++i) { + for (i = 0; i < stretches.size(); ++i) { QGraphicsWidget *item = static_cast<QGraphicsWidget*>(layout.itemAt(i)); qreal extent = item->size().width(); qreal stretch = (qreal)stretches.at(i); @@ -1297,7 +1297,7 @@ void tst_QGraphicsLinearLayout::defaultStretchFactors() QSizeF itemSize = layout->itemAt(i)->geometry().size(); if (orientation == Qt::Vertical) itemSize.transpose(); - if (i < expectedSizes.count()) + if (i < expectedSizes.size()) QCOMPARE(itemSize.width(), qreal(expectedSizes.at(i))); } diff --git a/tests/auto/widgets/graphicsview/qgraphicsobject/CMakeLists.txt b/tests/auto/widgets/graphicsview/qgraphicsobject/CMakeLists.txt index 9b7bf4c63c..0c21d9febc 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsobject/CMakeLists.txt +++ b/tests/auto/widgets/graphicsview/qgraphicsobject/CMakeLists.txt @@ -1,13 +1,20 @@ -# Generated from qgraphicsobject.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qgraphicsobject Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qgraphicsobject LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qgraphicsobject SOURCES tst_qgraphicsobject.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::Gui Qt::Widgets diff --git a/tests/auto/widgets/graphicsview/qgraphicsobject/tst_qgraphicsobject.cpp b/tests/auto/widgets/graphicsview/qgraphicsobject/tst_qgraphicsobject.cpp index 849ac19d25..674a7f73d5 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsobject/tst_qgraphicsobject.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsobject/tst_qgraphicsobject.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> @@ -41,28 +41,28 @@ void tst_QGraphicsObject::pos() QSignalSpy ySpy(&object, SIGNAL(yChanged())); QVERIFY(object.pos() == QPointF(0, 0)); object.setPos(10, 10); - QCOMPARE(xSpy.count(), 1); - QCOMPARE(ySpy.count(), 1); + QCOMPARE(xSpy.size(), 1); + QCOMPARE(ySpy.size(), 1); QCOMPARE(object.pos(), QPointF(10,10)); object.setPos(10, 10); - QCOMPARE(xSpy.count(), 1); - QCOMPARE(ySpy.count(), 1); + QCOMPARE(xSpy.size(), 1); + QCOMPARE(ySpy.size(), 1); object.setProperty("pos", QPointF(0, 0)); - QCOMPARE(xSpy.count(), 2); - QCOMPARE(ySpy.count(), 2); + QCOMPARE(xSpy.size(), 2); + QCOMPARE(ySpy.size(), 2); QCOMPARE(object.property("pos").toPointF(), QPointF(0,0)); object.setProperty("pos", QPointF(10, 0)); - QCOMPARE(xSpy.count(), 3); - QCOMPARE(ySpy.count(), 2); + QCOMPARE(xSpy.size(), 3); + QCOMPARE(ySpy.size(), 2); QCOMPARE(object.property("pos").toPointF(), QPointF(10,0)); object.setProperty("pos", QPointF(10, 10)); - QCOMPARE(xSpy.count(), 3); - QCOMPARE(ySpy.count(), 3); + QCOMPARE(xSpy.size(), 3); + QCOMPARE(ySpy.size(), 3); QVERIFY(object.property("pos") == QPointF(10, 10)); } @@ -73,19 +73,19 @@ void tst_QGraphicsObject::x() QSignalSpy ySpy(&object, SIGNAL(yChanged())); QVERIFY(object.pos() == QPointF(0, 0)); object.setX(10); - QCOMPARE(xSpy.count(), 1); - QCOMPARE(ySpy.count(), 0); + QCOMPARE(xSpy.size(), 1); + QCOMPARE(ySpy.size(), 0); QVERIFY(object.pos() == QPointF(10, 0)); QCOMPARE(object.x(), qreal(10)); object.setX(10); - QCOMPARE(xSpy.count(), 1); - QCOMPARE(ySpy.count(), 0); + QCOMPARE(xSpy.size(), 1); + QCOMPARE(ySpy.size(), 0); object.setProperty("x", 0); - QCOMPARE(xSpy.count(), 2); - QCOMPARE(ySpy.count(), 0); + QCOMPARE(xSpy.size(), 2); + QCOMPARE(ySpy.size(), 0); QCOMPARE(object.property("x").toDouble(), double(0)); } @@ -96,19 +96,19 @@ void tst_QGraphicsObject::y() QSignalSpy ySpy(&object, SIGNAL(yChanged())); QVERIFY(object.pos() == QPointF(0, 0)); object.setY(10); - QCOMPARE(xSpy.count(), 0); - QCOMPARE(ySpy.count(), 1); + QCOMPARE(xSpy.size(), 0); + QCOMPARE(ySpy.size(), 1); QVERIFY(object.pos() == QPointF(0, 10)); QCOMPARE(object.y(), qreal(10)); object.setY(10); - QCOMPARE(xSpy.count(), 0); - QCOMPARE(ySpy.count(), 1); + QCOMPARE(xSpy.size(), 0); + QCOMPARE(ySpy.size(), 1); object.setProperty("y", 0); - QCOMPARE(xSpy.count(), 0); - QCOMPARE(ySpy.count(), 2); + QCOMPARE(xSpy.size(), 0); + QCOMPARE(ySpy.size(), 2); QCOMPARE(object.property("y").toDouble(), qreal(0)); } @@ -118,15 +118,15 @@ void tst_QGraphicsObject::z() QSignalSpy zSpy(&object, SIGNAL(zChanged())); QCOMPARE(object.zValue(), qreal(0)); object.setZValue(10); - QCOMPARE(zSpy.count(), 1); + QCOMPARE(zSpy.size(), 1); QCOMPARE(object.zValue(), qreal(10)); object.setZValue(10); - QCOMPARE(zSpy.count(), 1); + QCOMPARE(zSpy.size(), 1); object.setProperty("z", 0); - QCOMPARE(zSpy.count(), 2); + QCOMPARE(zSpy.size(), 2); QCOMPARE(object.property("z").toDouble(), double(0)); } @@ -136,15 +136,15 @@ void tst_QGraphicsObject::opacity() QSignalSpy spy(&object, SIGNAL(opacityChanged())); QCOMPARE(object.opacity(), 1.); object.setOpacity(0); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); QCOMPARE(object.opacity(), 0.); object.setOpacity(0); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); object.setProperty("opacity", .5); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); QCOMPARE(object.property("opacity").toDouble(), .5); } @@ -154,15 +154,15 @@ void tst_QGraphicsObject::enabled() QSignalSpy spy(&object, SIGNAL(enabledChanged())); QVERIFY(object.isEnabled()); object.setEnabled(false); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); QVERIFY(!object.isEnabled()); object.setEnabled(false); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); object.setProperty("enabled", true); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); QVERIFY(object.property("enabled").toBool()); } @@ -172,15 +172,15 @@ void tst_QGraphicsObject::visible() QSignalSpy spy(&object, SIGNAL(visibleChanged())); QVERIFY(object.isVisible()); object.setVisible(false); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); QVERIFY(!object.isVisible()); object.setVisible(false); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); object.setProperty("visible", true); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); QVERIFY(object.property("visible").toBool()); } diff --git a/tests/auto/widgets/graphicsview/qgraphicspixmapitem/CMakeLists.txt b/tests/auto/widgets/graphicsview/qgraphicspixmapitem/CMakeLists.txt index a848a8dd77..b60958f4f1 100644 --- a/tests/auto/widgets/graphicsview/qgraphicspixmapitem/CMakeLists.txt +++ b/tests/auto/widgets/graphicsview/qgraphicspixmapitem/CMakeLists.txt @@ -1,13 +1,20 @@ -# Generated from qgraphicspixmapitem.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qgraphicspixmapitem Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qgraphicspixmapitem LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qgraphicspixmapitem SOURCES tst_qgraphicspixmapitem.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui Qt::Widgets ) diff --git a/tests/auto/widgets/graphicsview/qgraphicspixmapitem/tst_qgraphicspixmapitem.cpp b/tests/auto/widgets/graphicsview/qgraphicspixmapitem/tst_qgraphicspixmapitem.cpp index 44d38f0172..fd8f8bd37d 100644 --- a/tests/auto/widgets/graphicsview/qgraphicspixmapitem/tst_qgraphicspixmapitem.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicspixmapitem/tst_qgraphicspixmapitem.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> diff --git a/tests/auto/widgets/graphicsview/qgraphicspolygonitem/CMakeLists.txt b/tests/auto/widgets/graphicsview/qgraphicspolygonitem/CMakeLists.txt index 8a3c88a8a2..116378decb 100644 --- a/tests/auto/widgets/graphicsview/qgraphicspolygonitem/CMakeLists.txt +++ b/tests/auto/widgets/graphicsview/qgraphicspolygonitem/CMakeLists.txt @@ -1,13 +1,20 @@ -# Generated from qgraphicspolygonitem.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qgraphicspolygonitem Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qgraphicspolygonitem LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qgraphicspolygonitem SOURCES tst_qgraphicspolygonitem.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui Qt::Widgets ) diff --git a/tests/auto/widgets/graphicsview/qgraphicspolygonitem/tst_qgraphicspolygonitem.cpp b/tests/auto/widgets/graphicsview/qgraphicspolygonitem/tst_qgraphicspolygonitem.cpp index 5360249186..9412fab0ee 100644 --- a/tests/auto/widgets/graphicsview/qgraphicspolygonitem/tst_qgraphicspolygonitem.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicspolygonitem/tst_qgraphicspolygonitem.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> diff --git a/tests/auto/widgets/graphicsview/qgraphicsproxywidget/BLACKLIST b/tests/auto/widgets/graphicsview/qgraphicsproxywidget/BLACKLIST index 20977b26bb..731b3ae253 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsproxywidget/BLACKLIST +++ b/tests/auto/widgets/graphicsview/qgraphicsproxywidget/BLACKLIST @@ -1,8 +1,6 @@ [scrollUpdate] android b2qt -[hoverEnterLeaveEvent] -macos ci [windowOpacity] macos ci [wheelEventPropagation] diff --git a/tests/auto/widgets/graphicsview/qgraphicsproxywidget/CMakeLists.txt b/tests/auto/widgets/graphicsview/qgraphicsproxywidget/CMakeLists.txt index a1bf1270c2..f28ff74cfa 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsproxywidget/CMakeLists.txt +++ b/tests/auto/widgets/graphicsview/qgraphicsproxywidget/CMakeLists.txt @@ -1,15 +1,22 @@ -# Generated from qgraphicsproxywidget.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qgraphicsproxywidget Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qgraphicsproxywidget LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qgraphicsproxywidget SOURCES tst_qgraphicsproxywidget.cpp DEFINES QTEST_QPA_MOUSE_HANDLING - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::Gui Qt::GuiPrivate diff --git a/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp b/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp index 43522e325a..ee1a8c530a 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.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> @@ -9,6 +9,8 @@ #include <private/qgraphicsproxywidget_p.h> #include <private/qlayoutengine_p.h> // qSmartMin functions... +#include <QtWidgets/private/qapplication_p.h> + Q_LOGGING_CATEGORY(lcTests, "qt.widgets.tests") /* @@ -333,7 +335,7 @@ void tst_QGraphicsProxyWidget::setWidget() widget->setStyle(style.data()); widget->setFont(QFont("Times")); widget->setVisible(true); - QApplication::setActiveWindow(widget); + QApplicationPrivate::setActiveWindow(widget); widget->activateWindow(); widget->setEnabled(true); widget->resize(325, 241); @@ -707,7 +709,6 @@ void tst_QGraphicsProxyWidget::focusNextPrevChild() QGraphicsScene scene; QGraphicsView view(&scene); view.show(); - QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowActive(&view)); if (hasScene) { scene.addItem(proxyGuard.release()); @@ -749,7 +750,6 @@ void tst_QGraphicsProxyWidget::focusOutEvent() SubQGraphicsProxyWidget *proxy = new SubQGraphicsProxyWidget; scene.addItem(proxy); view.show(); - QApplication::setActiveWindow(&view); view.activateWindow(); view.setFocus(); QVERIFY(QTest::qWaitForWindowActive(&view)); @@ -782,6 +782,9 @@ void tst_QGraphicsProxyWidget::focusOutEvent() void tst_QGraphicsProxyWidget::focusProxy_QTBUG_51856() { +#ifdef ANDROID + QSKIP("This test leads to failures on subsequent test cases, QTBUG-119574"); +#endif // QSpinBox has an internal QLineEdit; this QLineEdit has the spinbox // as its focus proxy. struct FocusedSpinBox : QSpinBox @@ -804,6 +807,9 @@ void tst_QGraphicsProxyWidget::focusProxy_QTBUG_51856() } }; + if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + QSKIP("QWindow::requestActivate() is not supported."); + QGraphicsScene scene; QGraphicsView view(&scene); SubQGraphicsProxyWidget *proxy = new SubQGraphicsProxyWidget; @@ -925,7 +931,6 @@ void tst_QGraphicsProxyWidget::hoverEnterLeaveEvent() QGraphicsScene scene; QGraphicsView view(&scene); view.show(); - QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowActive(&view)); SubQGraphicsProxyWidget *proxy = new SubQGraphicsProxyWidget; @@ -940,7 +945,7 @@ void tst_QGraphicsProxyWidget::hoverEnterLeaveEvent() proxy->setPos(50, 0); QSignalSpy sceneChangedSpy(&scene, &QGraphicsScene::changed); scene.addItem(proxy); - QTRY_VERIFY(sceneChangedSpy.count() > 0); + QTRY_VERIFY(sceneChangedSpy.size() > 0); // outside graphics item QTest::mouseMove(&view, QPoint(10, 10)); @@ -979,7 +984,6 @@ void tst_QGraphicsProxyWidget::keyPressEvent() QGraphicsView view(&scene); view.show(); view.viewport()->setFocus(); - QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowActive(&view)); QCOMPARE(QApplication::activeWindow(), (QWidget*)&view); @@ -1018,7 +1022,6 @@ void tst_QGraphicsProxyWidget::keyReleaseEvent() QGraphicsScene scene; QGraphicsView view(&scene); view.show(); - QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowActive(&view)); QCOMPARE(QApplication::activeWindow(), (QWidget*)&view); @@ -1038,9 +1041,9 @@ void tst_QGraphicsProxyWidget::keyReleaseEvent() proxy->setFocus(); QTest::keyPress(view.viewport(), Qt::Key_Space); - QTRY_COMPARE(spy.count(), 0); + QTRY_COMPARE(spy.size(), 0); QTest::keyRelease(view.viewport(), Qt::Key_Space); - QTRY_COMPARE(spy.count(), hasWidget ? 1 : 0); + QTRY_COMPARE(spy.size(), hasWidget ? 1 : 0); } // protected void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event) @@ -1064,11 +1067,10 @@ void tst_QGraphicsProxyWidget::mouseDoubleClickEvent() view.resize(100, 100); view.show(); - QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowActive(&view)); QCOMPARE(QApplication::activeWindow(), (QWidget*)&view); // wait for scene to be updated before doing any coordinate mappings on it - QTRY_VERIFY(sceneChangedSpy.count() > 0); + QTRY_VERIFY(sceneChangedSpy.size() > 0); QPoint pointInLineEdit = view.mapFromScene(proxy->mapToScene(15, proxy->boundingRect().center().y())); QTest::mousePress(view.viewport(), Qt::LeftButton, {}, pointInLineEdit); @@ -1109,13 +1111,13 @@ void tst_QGraphicsProxyWidget::mousePressReleaseEvent() proxy->setFocus(); // wait for scene to be updated before doing any coordinate mappings on it - QTRY_VERIFY(sceneChangedSpy.count() > 0); + QTRY_VERIFY(sceneChangedSpy.size() > 0); QPoint buttonCenter = view.mapFromScene(proxy->mapToScene(proxy->boundingRect().center())); QTest::mousePress(view.viewport(), Qt::LeftButton, {}, buttonCenter); - QTRY_COMPARE(spy.count(), 0); + QTRY_COMPARE(spy.size(), 0); QTest::mouseRelease(view.viewport(), Qt::LeftButton, {}, buttonCenter); - QTRY_COMPARE(spy.count(), hasWidget ? 1 : 0); + QTRY_COMPARE(spy.size(), hasWidget ? 1 : 0); } void tst_QGraphicsProxyWidget::resizeEvent_data() @@ -1150,7 +1152,6 @@ void tst_QGraphicsProxyWidget::paintEvent() QGraphicsScene scene; QGraphicsView view(&scene); view.show(); - QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowActive(&view)); QVERIFY(view.isActiveWindow()); @@ -1166,7 +1167,7 @@ void tst_QGraphicsProxyWidget::paintEvent() QSignalSpy sceneChangedSpy(&scene, &QGraphicsScene::changed); scene.addItem(&proxy); - QTRY_VERIFY(sceneChangedSpy.count() > 0); // make sure the scene is ready + QTRY_VERIFY(sceneChangedSpy.size() > 0); // make sure the scene is ready proxy.paintCount = 0; w->update(); @@ -1321,6 +1322,9 @@ static QList<QRect> rects(const QRegion ®ion) void tst_QGraphicsProxyWidget::scrollUpdate() { + if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + QSKIP("QWindow::requestActivate() is not supported."); + ScrollWidget *widget = new ScrollWidget; QGraphicsScene scene; @@ -1534,7 +1538,6 @@ void tst_QGraphicsProxyWidget::tabFocus_simpleWidget() window.setLayout(layout); window.show(); - QApplication::setActiveWindow(&window); window.activateWindow(); QVERIFY(QTest::qWaitForWindowActive(&window)); @@ -1618,7 +1621,6 @@ void tst_QGraphicsProxyWidget::tabFocus_simpleTwoWidgets() window.setLayout(layout); window.show(); - QApplication::setActiveWindow(&window); window.activateWindow(); QVERIFY(QTest::qWaitForWindowActive(&window)); @@ -1751,7 +1753,6 @@ void tst_QGraphicsProxyWidget::tabFocus_complexWidget() window.setLayout(layout); window.show(); - QApplication::setActiveWindow(&window); window.activateWindow(); QVERIFY(QTest::qWaitForWindowActive(&window)); @@ -1888,7 +1889,6 @@ void tst_QGraphicsProxyWidget::tabFocus_complexTwoWidgets() window.setLayout(layout); window.show(); - QApplication::setActiveWindow(&window); window.activateWindow(); QVERIFY(QTest::qWaitForWindowActive(&window)); @@ -2062,7 +2062,6 @@ void tst_QGraphicsProxyWidget::setFocus_simpleWidget() window.setLayout(layout); window.show(); - QApplication::setActiveWindow(&window); window.activateWindow(); QVERIFY(QTest::qWaitForWindowActive(&window)); QCOMPARE(QApplication::activeWindow(), &window); @@ -2134,7 +2133,6 @@ void tst_QGraphicsProxyWidget::setFocus_simpleTwoWidgets() window.setLayout(layout); window.show(); - QApplication::setActiveWindow(&window); window.activateWindow(); QVERIFY(QTest::qWaitForWindowActive(&window)); QCOMPARE(QApplication::activeWindow(), &window); @@ -2213,7 +2211,6 @@ void tst_QGraphicsProxyWidget::setFocus_complexTwoWidgets() window.setLayout(layout); window.show(); - QApplication::setActiveWindow(&window); window.activateWindow(); QVERIFY(QTest::qWaitForWindowActive(&window)); QCOMPARE(QApplication::activeWindow(), &window); @@ -2305,7 +2302,7 @@ void tst_QGraphicsProxyWidget::popup_basic() box->setGeometry(0, 0, 320, 40); box->addItems(QStringList() << "monday" << "tuesday" << "wednesday" << "thursday" << "saturday" << "sunday"); - QCOMPARE(proxy->childItems().count(), 0); + QCOMPARE(proxy->childItems().size(), 0); proxy->setWidget(boxGuard.release()); proxy->show(); scene.addItem(proxy); @@ -2322,7 +2319,7 @@ void tst_QGraphicsProxyWidget::popup_basic() QTRY_COMPARE(box->pos(), QPoint()); - QCOMPARE(proxy->childItems().count(), 1); + QCOMPARE(proxy->childItems().size(), 1); QGraphicsProxyWidget *child = (QGraphicsProxyWidget*)(proxy->childItems())[0]; QVERIFY(child->isWidget()); QVERIFY(child->widget()); @@ -2402,7 +2399,7 @@ void tst_QGraphicsProxyWidget::changingCursor_basic() proxy->setWidget(widget); QSignalSpy sceneChangedSpy(&scene, &QGraphicsScene::changed); scene.addItem(proxy); - QTRY_VERIFY(sceneChangedSpy.count() > 0); // make sure the scene is ready + QTRY_VERIFY(sceneChangedSpy.size() > 0); // make sure the scene is ready // in QTest::mouseMove(view.viewport(), view.mapFromScene(proxy->mapToScene(proxy->boundingRect().center()))); @@ -2458,7 +2455,6 @@ void tst_QGraphicsProxyWidget::tooltip_basic() QGraphicsView view(&scene); view.setFixedSize(200, 200); view.show(); - QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowActive(&view)); { QHelpEvent helpEvent(QEvent::ToolTip, view.viewport()->rect().topLeft(), @@ -2468,7 +2464,8 @@ void tst_QGraphicsProxyWidget::tooltip_basic() bool foundView = false; bool foundTipLabel = false; - foreach (QWidget *widget, QApplication::topLevelWidgets()) { + const auto widgets = QApplication::topLevelWidgets(); + for (QWidget *widget : widgets) { if (widget == &view) foundView = true; if (widget->inherits("QTipLabel")) @@ -2595,7 +2592,7 @@ void tst_QGraphicsProxyWidget::windowOpacity() QGraphicsProxyWidget *proxy = scene.addWidget(widget); proxy->setCacheMode(QGraphicsItem::ItemCoordinateCache); - QApplication::setActiveWindow(&view); + QApplicationPrivate::setActiveWindow(&view); view.show(); QVERIFY(QTest::qWaitForWindowActive(&view)); QVERIFY(view.isActiveWindow()); @@ -2620,7 +2617,7 @@ void tst_QGraphicsProxyWidget::windowOpacity() QTRY_COMPARE(eventSpy.counts[QEvent::UpdateRequest], 0); QTRY_COMPARE(eventSpy.counts[QEvent::Paint], paints); - QTRY_COMPARE(signalSpy.count(), 1); + QTRY_COMPARE(signalSpy.size(), 1); const QList<QVariant> arguments = signalSpy.takeFirst(); const QList<QRectF> updateRects = qvariant_cast<QList<QRectF> >(arguments.at(0)); QCOMPARE(updateRects.size(), 1); @@ -2895,10 +2892,10 @@ void tst_QGraphicsProxyWidget::createProxyForChildWidget() QTest::mousePress(view.viewport(), Qt::LeftButton, {}, view.mapFromScene(checkboxProxy->mapToScene(QPointF(8,8)))); - QTRY_COMPARE(spy.count(), 0); + QTRY_COMPARE(spy.size(), 0); QTest::mouseRelease(view.viewport(), Qt::LeftButton, {}, view.mapFromScene(checkboxProxy->mapToScene(QPointF(8,8)))); - QTRY_COMPARE(spy.count(), 1); + QTRY_COMPARE(spy.size(), 1); @@ -2993,7 +2990,6 @@ void tst_QGraphicsProxyWidget::actionsContextMenu() view.resize(200, 200); view.move(QGuiApplication::primaryScreen()->geometry().center() - QPoint(100, 100)); view.show(); - QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowActive(&view)); view.setFocus(); QTRY_VERIFY(view.hasFocus()); @@ -3063,6 +3059,9 @@ void tst_QGraphicsProxyWidget::bypassGraphicsProxyWidget_data() void tst_QGraphicsProxyWidget::bypassGraphicsProxyWidget() { + if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + QSKIP("QWindow::requestActivate() is not supported."); + QFETCH(bool, bypass); std::unique_ptr<QWidget> widgetGuard(new QWidget); @@ -3072,7 +3071,6 @@ void tst_QGraphicsProxyWidget::bypassGraphicsProxyWidget() QGraphicsScene scene; QGraphicsView view(&scene); view.show(); - QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowActive(&view)); QGraphicsProxyWidget *proxy = scene.addWidget(widgetGuard.release()); @@ -3276,6 +3274,9 @@ public: void tst_QGraphicsProxyWidget::inputMethod() { + if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + QSKIP("QWindow::requestActivate() is not supported."); + QGraphicsScene scene; // check that the proxy is initialized with the correct input method sensitivity @@ -3335,7 +3336,6 @@ void tst_QGraphicsProxyWidget::clickFocus() view.setFrameStyle(0); view.resize(300, 300); view.show(); - QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowActive(&view)); QVERIFY(!proxy->hasFocus()); @@ -3479,7 +3479,6 @@ void tst_QGraphicsProxyWidget::QTBUG_6986_sendMouseEventToAlienWidget() QGraphicsView view(&scene); view.resize(600, 600); - QApplication::setActiveWindow(&view); view.show(); QVERIFY(QTest::qWaitForWindowActive(&view)); @@ -3523,7 +3522,6 @@ void tst_QGraphicsProxyWidget::mapToGlobal() // QTBUG-41135 childWidget->resize(embeddedWidget->size() / 2); childWidget->move(embeddedWidget->width() / 4, embeddedWidget->height() / 4); // center in embeddedWidget scene.addWidget(embeddedWidget); - QApplication::setActiveWindow(&view); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); const QPoint embeddedCenter = embeddedWidget->rect().center(); @@ -3531,8 +3529,9 @@ void tst_QGraphicsProxyWidget::mapToGlobal() // QTBUG-41135 QCOMPARE(embeddedWidget->mapFromGlobal(embeddedCenterGlobal), embeddedCenter); // This should be equivalent to the view center give or take rounding // errors due to odd window margins + const int Tolerance = qCeil(4 * view.devicePixelRatio()); const QPoint viewCenter = view.geometry().center(); - QVERIFY2((viewCenter - embeddedCenterGlobal).manhattanLength() <= 3, + QVERIFY2((viewCenter - embeddedCenterGlobal).manhattanLength() <= Tolerance, msgPointMismatch(embeddedCenterGlobal, viewCenter).constData()); // Same test with child centered on embeddedWidget. Also make sure @@ -3542,7 +3541,7 @@ void tst_QGraphicsProxyWidget::mapToGlobal() // QTBUG-41135 const QPoint childCenter = childWidget->rect().center(); const QPoint childCenterGlobal = childWidget->mapToGlobal(childCenter); QCOMPARE(childWidget->mapFromGlobal(childCenterGlobal), childCenter); - QVERIFY2((viewCenter - childCenterGlobal).manhattanLength() <= 4, + QVERIFY2((viewCenter - childCenterGlobal).manhattanLength() <= Tolerance, msgPointMismatch(childCenterGlobal, viewCenter).constData()); } @@ -3687,27 +3686,27 @@ void tst_QGraphicsProxyWidget::wheelEventPropagation() // accepted by the embedded widget QCOMPARE(view.itemAt(wheelPosition), nullptr); wheelUp(Qt::NoScrollPhase); - QCOMPARE(scrollSpy.count(), ++scrollCount); + QCOMPARE(scrollSpy.size(), ++scrollCount); // wheeling on the label, which ignores the event, should scroll the view QCOMPARE(view.itemAt(wheelPosition), labelProxy); wheelUp(Qt::NoScrollPhase); - QCOMPARE(scrollSpy.count(), ++scrollCount); + QCOMPARE(scrollSpy.size(), ++scrollCount); QCOMPARE(view.itemAt(wheelPosition), labelProxy); wheelUp(Qt::NoScrollPhase); - QCOMPARE(scrollSpy.count(), ++scrollCount); + QCOMPARE(scrollSpy.size(), ++scrollCount); // left the widget QCOMPARE(view.itemAt(wheelPosition), nullptr); wheelUp(Qt::NoScrollPhase); - QCOMPARE(scrollSpy.count(), ++scrollCount); + QCOMPARE(scrollSpy.size(), ++scrollCount); // reached the nested widget, which accepts the wheel event, so no more scrolling QCOMPARE(view.itemAt(wheelPosition), nestedProxy); // remember this position for later const int scrollBarValueOnNestedProxy = view.verticalScrollBar()->value(); wheelUp(Qt::NoScrollPhase); - QCOMPARE(scrollSpy.count(), scrollCount); + QCOMPARE(scrollSpy.size(), scrollCount); QCOMPARE(nestedWidget->wheelEventCount, 1); // reset, try with kinetic events @@ -3718,41 +3717,41 @@ void tst_QGraphicsProxyWidget::wheelEventPropagation() // no matter if the widget accepts wheel events - the view has the grab QCOMPARE(view.itemAt(wheelPosition), nullptr); wheelUp(Qt::ScrollBegin); - QCOMPARE(scrollSpy.count(), ++scrollCount); + QCOMPARE(scrollSpy.size(), ++scrollCount); for (int i = 0; i < 5; ++i) { wheelUp(Qt::ScrollUpdate); - QCOMPARE(scrollSpy.count(), ++scrollCount); + QCOMPARE(scrollSpy.size(), ++scrollCount); } wheelUp(Qt::ScrollEnd); - QCOMPARE(scrollSpy.count(), ++scrollCount); + QCOMPARE(scrollSpy.size(), ++scrollCount); // reset view.verticalScrollBar()->setValue(0); - scrollCount = scrollSpy.count(); + scrollCount = scrollSpy.size(); // starting a scroll on a widget that doesn't accept wheel events // should also scroll the view, which still gets the grab wheelUp(Qt::NoScrollPhase); - scrollCount = scrollSpy.count(); + scrollCount = scrollSpy.size(); QCOMPARE(view.itemAt(wheelPosition), labelProxy); wheelUp(Qt::ScrollBegin); - QCOMPARE(scrollSpy.count(), ++scrollCount); + QCOMPARE(scrollSpy.size(), ++scrollCount); for (int i = 0; i < 5; ++i) { wheelUp(Qt::ScrollUpdate); - QCOMPARE(scrollSpy.count(), ++scrollCount); + QCOMPARE(scrollSpy.size(), ++scrollCount); } wheelUp(Qt::ScrollEnd); - QCOMPARE(scrollSpy.count(), ++scrollCount); + QCOMPARE(scrollSpy.size(), ++scrollCount); // starting a scroll on a widget that does accept wheel events // should not scroll the view view.verticalScrollBar()->setValue(scrollBarValueOnNestedProxy); - scrollCount = scrollSpy.count(); + scrollCount = scrollSpy.size(); QCOMPARE(view.itemAt(wheelPosition), nestedProxy); wheelUp(Qt::ScrollBegin); - QCOMPARE(scrollSpy.count(), scrollCount); + QCOMPARE(scrollSpy.size(), scrollCount); } #endif // QT_CONFIG(wheelevent) @@ -3850,7 +3849,7 @@ void tst_QGraphicsProxyWidget::touchEventPropagation() QHash<int, QList<TouchRecord>> records; QWidget *mousePressReceiver = nullptr; - int count(int id = 0) const { return records.value(id).count(); } + int count(int id = 0) const { return records.value(id).size(); } TouchRecord at(int i, int id = 0) const { return records.value(id).at(i); } void clear() { @@ -3954,7 +3953,7 @@ void tst_QGraphicsProxyWidget::touchEventPropagation() QCOMPARE(record.receiver, view.windowHandle()); QCOMPARE(record.eventType, QEvent::TouchEnd); QCOMPARE(eventSpy.mousePressReceiver, pushButton1); - QCOMPARE(clickedSpy.count(), 1); + QCOMPARE(clickedSpy.size(), 1); eventSpy.clear(); clickedSpy.clear(); @@ -4022,7 +4021,7 @@ void tst_QGraphicsProxyWidget::touchEventPropagation() QCOMPARE(eventSpy.at(0, 3).receiver, touchWidget2); QCOMPARE(eventSpy.at(1, 3).receiver, touchWidget2); QCOMPARE(eventSpy.at(2, 3).receiver, touchWidget2); - QCOMPARE(clickedSpy.count(), 0); // multi-touch event does not synthesize a mouse event + QCOMPARE(clickedSpy.size(), 0); // multi-touch event does not synthesize a mouse event } QTEST_MAIN(tst_QGraphicsProxyWidget) diff --git a/tests/auto/widgets/graphicsview/qgraphicsscene/BLACKLIST b/tests/auto/widgets/graphicsview/qgraphicsscene/BLACKLIST deleted file mode 100644 index c3797c9d57..0000000000 --- a/tests/auto/widgets/graphicsview/qgraphicsscene/BLACKLIST +++ /dev/null @@ -1,5 +0,0 @@ -[isActive] -opensuse-42.3 ci -[tabFocus_sceneWithNestedFocusWidgets] -opensuse-42.3 - diff --git a/tests/auto/widgets/graphicsview/qgraphicsscene/CMakeLists.txt b/tests/auto/widgets/graphicsview/qgraphicsscene/CMakeLists.txt index ce4d6de7cd..c0dd8995b8 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsscene/CMakeLists.txt +++ b/tests/auto/widgets/graphicsview/qgraphicsscene/CMakeLists.txt @@ -1,9 +1,16 @@ -# Generated from qgraphicsscene.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qgraphicsscene Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qgraphicsscene LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + # Resources: set(testdata_resource_files @@ -39,12 +46,12 @@ set(testdata_resource_files ) qt_internal_add_test(tst_qgraphicsscene - LOWDPI # special case + LOWDPI SOURCES tst_qgraphicsscene.cpp DEFINES QT_NO_CAST_TO_ASCII - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::Gui Qt::GuiPrivate @@ -58,6 +65,6 @@ qt_internal_add_test(tst_qgraphicsscene ##################################################################### qt_internal_extend_target(tst_qgraphicsscene CONDITION WIN32 - PUBLIC_LIBRARIES + LIBRARIES user32 ) diff --git a/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp b/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp index cc92f3b65b..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> @@ -31,6 +31,8 @@ #include "../../../shared/platforminputcontext.h" #include <private/qinputmethod_p.h> +#include <QtWidgets/private/qapplication_p.h> + #if defined(Q_OS_WIN) #include <QtCore/qt_windows.h> #define Q_CHECK_PAINTEVENTS \ @@ -253,6 +255,7 @@ private slots: void focusItemChangedSignal(); void minimumRenderSize(); void focusOnTouch(); + void clearSelection(); // task specific tests below me void task139710_bspTreeCrash(); @@ -318,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); @@ -346,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()); } @@ -531,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); @@ -596,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()); @@ -943,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)); @@ -980,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() @@ -1019,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)); @@ -1034,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)); @@ -1049,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)); @@ -1059,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)); @@ -1068,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() @@ -1291,7 +1294,6 @@ void tst_QGraphicsScene::removeItem() view.setWindowTitle(QTest::currentTestFunction()); view.setFixedSize(150, 150); view.show(); - QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowActive(&view)); QTest::mouseMove(view.windowHandle(), view.mapFromScene(hoverItem->scenePos() + QPointF(20, 20))); QTRY_VERIFY(!hoverItem->isHovered); @@ -1599,7 +1601,6 @@ void tst_QGraphicsScene::hoverEvents_siblings() view.rotate(10); view.scale(1.7, 1.7); view.show(); - QApplication::setActiveWindow(&view); view.activateWindow(); QVERIFY(QTest::qWaitForWindowActive(&view)); @@ -1669,7 +1670,6 @@ void tst_QGraphicsScene::hoverEvents_parentChild() view.rotate(10); view.scale(1.7, 1.7); view.show(); - QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowActive(&view)); QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMouseMove); @@ -1731,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); @@ -1747,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 @@ -1771,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 @@ -1781,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 @@ -2677,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. @@ -2831,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) @@ -2848,7 +2851,6 @@ void tst_QGraphicsScene::update2() view.resize(m_testSize); view.setScene(&scene); view.show(); - QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowActive(&view)); QTRY_VERIFY(view.repaints >= 1); view.repaints = 0; @@ -3038,7 +3040,6 @@ void tst_QGraphicsScene::tabFocus_emptyScene() widget.setLayout(layout); widget.setWindowTitle(QTest::currentTestFunction()); widget.show(); - QApplication::setActiveWindow(&widget); widget.activateWindow(); QVERIFY(QTest::qWaitForWindowActive(&widget)); @@ -3090,7 +3091,6 @@ void tst_QGraphicsScene::tabFocus_sceneWithFocusableItems() widget.setWindowTitle(QTest::currentTestFunction()); widget.setLayout(layout); widget.show(); - QApplication::setActiveWindow(&widget); widget.activateWindow(); QVERIFY(QTest::qWaitForWindowActive(&widget)); @@ -3144,7 +3144,7 @@ void tst_QGraphicsScene::tabFocus_sceneWithFocusableItems() // Check that the correct item regains focus. widget.show(); - QApplication::setActiveWindow(&widget); + QApplicationPrivate::setActiveWindow(&widget); widget.activateWindow(); QVERIFY(QTest::qWaitForWindowActive(&widget)); QVERIFY(view->hasFocus()); @@ -3228,7 +3228,7 @@ void tst_QGraphicsScene::tabFocus_sceneWithFocusWidgets() widget.setWindowTitle(QTest::currentTestFunction()); widget.setLayout(layout); widget.show(); - QApplication::setActiveWindow(&widget); + QApplicationPrivate::setActiveWindow(&widget); widget.activateWindow(); QVERIFY(QTest::qWaitForWindowActive(&widget)); @@ -3267,7 +3267,7 @@ void tst_QGraphicsScene::tabFocus_sceneWithFocusWidgets() widget.hide(); QTest::qWait(15); widget.show(); - QApplication::setActiveWindow(&widget); + QApplicationPrivate::setActiveWindow(&widget); widget.activateWindow(); QVERIFY(QTest::qWaitForWindowActive(&widget)); QTRY_VERIFY(widget1->hasFocus()); @@ -3316,7 +3316,7 @@ void tst_QGraphicsScene::tabFocus_sceneWithNestedFocusWidgets() widget.setWindowTitle(QTest::currentTestFunction()); widget.setLayout(layout); widget.show(); - QApplication::setActiveWindow(&widget); + QApplicationPrivate::setActiveWindow(&widget); widget.activateWindow(); QVERIFY(QTest::qWaitForWindowActive(&widget)); @@ -3401,7 +3401,7 @@ void tst_QGraphicsScene::tabFocus_sceneWithNestedFocusWidgets() widget.hide(); QTest::qWait(12); widget.show(); - QApplication::setActiveWindow(&widget); + QApplicationPrivate::setActiveWindow(&widget); widget.activateWindow(); QVERIFY(QTest::qWaitForWindowActive(&widget)); QTRY_VERIFY(widget1->hasFocus()); @@ -3530,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() @@ -3661,8 +3661,8 @@ void tst_QGraphicsScene::insertionOrder() { QList<QGraphicsItem*> itemList = scene.items(); - QCOMPARE(itemList.count(), numItems); - for (int i = 0; i < itemList.count(); ++i) { + QCOMPARE(itemList.size(), numItems); + for (int i = 0; i < itemList.size(); ++i) { QCOMPARE(numItems-1-i, itemList.at(i)->data(0).toInt()); } } @@ -3675,8 +3675,8 @@ void tst_QGraphicsScene::insertionOrder() { QList<QGraphicsItem*> itemList = scene.items(); - QCOMPARE(itemList.count(), numItems); - for (int i = 0; i < itemList.count(); ++i) { + QCOMPARE(itemList.size(), numItems); + for (int i = 0; i < itemList.size(); ++i) { QCOMPARE(numItems-1-i, itemList.at(i)->data(0).toInt()); } } @@ -3819,7 +3819,6 @@ void tst_QGraphicsScene::inputMethod() view.resize(m_testSize); view.show(); view.setWindowTitle(QTest::currentTestFunction()); - QApplication::setActiveWindow(&view); view.setFocus(); QVERIFY(QTest::qWaitForWindowActive(&view)); QCOMPARE(QApplication::activeWindow(), &view); @@ -4024,7 +4023,7 @@ void tst_QGraphicsScene::polishItems2() // added 10 new children. These should be polished in the next // event loop iteration. const QList<QGraphicsItem *> children = item->childItems(); - QCOMPARE(children.count(), 10); + QCOMPARE(children.size(), 10); for (QGraphicsItem *child : children) QVERIFY(!static_cast<PolishItem *>(child)->polished); @@ -4063,7 +4062,6 @@ void tst_QGraphicsScene::isActive() view1->setVisible(false); toplevel1.show(); - QApplication::setActiveWindow(&toplevel1); QVERIFY(QTest::qWaitForWindowActive(&toplevel1)); QCOMPARE(QApplication::activeWindow(), &toplevel1); @@ -4092,7 +4090,7 @@ void tst_QGraphicsScene::isActive() QVERIFY(!scene2.hasFocus()); toplevel1.show(); - QApplication::setActiveWindow(&toplevel1); + QApplicationPrivate::setActiveWindow(&toplevel1); QVERIFY(QTest::qWaitForWindowActive(&toplevel1)); QCOMPARE(QApplication::activeWindow(), &toplevel1); @@ -4132,7 +4130,7 @@ void tst_QGraphicsScene::isActive() toplevel2.move(m_availableGeometry.topLeft() + QPoint(50, 50)); toplevel2.show(); - QApplication::setActiveWindow(&toplevel2); + QApplicationPrivate::setActiveWindow(&toplevel2); QVERIFY(QTest::qWaitForWindowActive(&toplevel2)); QCOMPARE(QApplication::activeWindow(), &toplevel2); @@ -4182,7 +4180,7 @@ void tst_QGraphicsScene::isActive() topLevelView.move(toplevel2.geometry().topRight() + QPoint(100, 50)); topLevelView.resize(m_testSize); topLevelView.show(); - QApplication::setActiveWindow(&topLevelView); + QApplicationPrivate::setActiveWindow(&topLevelView); topLevelView.setFocus(); QVERIFY(QTest::qWaitForWindowActive(&topLevelView)); QCOMPARE(QApplication::activeWindow(), &topLevelView); @@ -4210,7 +4208,7 @@ void tst_QGraphicsScene::isActive() QVERIFY(scene1.hasFocus()); QVERIFY(!scene2.hasFocus()); - QApplication::setActiveWindow(&toplevel2); + QApplicationPrivate::setActiveWindow(&toplevel2); QVERIFY(QTest::qWaitForWindowActive(&toplevel2)); QVERIFY(!scene1.isActive()); @@ -4240,7 +4238,6 @@ void tst_QGraphicsScene::isActive() toplevel3.show(); - QApplication::setActiveWindow(&toplevel3); QVERIFY(QTest::qWaitForWindowActive(&toplevel3)); QCOMPARE(QApplication::activeWindow(), &toplevel3); @@ -4353,7 +4350,6 @@ void tst_QGraphicsScene::removeFullyTransparentItem() view.resize(m_testSize); view.setScene(&scene); view.show(); - QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowActive(&view)); QCoreApplication::processEvents(); // Process all queued paint events @@ -4603,13 +4599,13 @@ void tst_QGraphicsScene::zeroScale() rect1->setScale(0.00000001); QApplication::processEvents(); - QTRY_COMPARE(cl.changes.count(), 1); + QTRY_COMPARE(cl.changes.size(), 1); QGraphicsRectItem *rect2 = new QGraphicsRectItem(-0.0000001, -0.0000001, 0.0000001, 0.0000001); rect2->setScale(0.00000001); scene.addItem(rect2); rect1->setPos(20,20); QApplication::processEvents(); - QTRY_COMPARE(cl.changes.count(), 2); + QTRY_COMPARE(cl.changes.size(), 2); } void tst_QGraphicsScene::focusItemChangedSignal() @@ -4620,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; @@ -4638,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); @@ -4647,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); @@ -4655,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); @@ -4684,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); @@ -4703,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); @@ -4715,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); @@ -4811,7 +4807,6 @@ void tst_QGraphicsScene::focusOnTouch() rect->setFlag(QGraphicsItem::ItemIsFocusable, true); view.show(); - QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowActive(&view)); QVERIFY(!rect->hasFocus()); @@ -4834,6 +4829,53 @@ void tst_QGraphicsScene::focusOnTouch() QVERIFY(rect->hasFocus()); } +void tst_QGraphicsScene::clearSelection() +{ + class AlwaysSelectedItem : public QGraphicsRectItem + { + public: + using QGraphicsRectItem::QGraphicsRectItem; + protected: + QVariant itemChange(GraphicsItemChange change, const QVariant& value) override + { + if (change == ItemSelectedChange) + return true; + return QGraphicsRectItem::itemChange(change, value); + } + }; + QGraphicsScene scene; + QSignalSpy spy(&scene, &QGraphicsScene::selectionChanged); + + QGraphicsRectItem *regularRect = new QGraphicsRectItem; + regularRect->setFlag(QGraphicsItem::ItemIsSelectable); + regularRect->setRect(0, 0, 50, 50); + regularRect->setSelected(true); + AlwaysSelectedItem *selectedRect = new AlwaysSelectedItem; + selectedRect->setFlag(QGraphicsItem::ItemIsSelectable); + selectedRect->setRect(50, 50, 50, 50); + selectedRect->setSelected(true); + scene.addItem(regularRect); + scene.addItem(selectedRect); + + QCOMPARE(spy.size(), 2); + + QCOMPARE(scene.selectedItems().size(), 2); + scene.clearSelection(); + QVERIFY(!regularRect->isSelected()); + QVERIFY(selectedRect->isSelected()); + QCOMPARE(scene.selectedItems().size(), 1); + QCOMPARE(spy.size(), 3); + + delete regularRect; + QCOMPARE(spy.size(), 3); + + scene.clearSelection(); + QCOMPARE(spy.size(), 3); + + delete selectedRect; + QCOMPARE(spy.size(), 4); +} + void tst_QGraphicsScene::taskQTBUG_15977_renderWithDeviceCoordinateCache() { QGraphicsScene scene; @@ -4865,7 +4907,6 @@ void tst_QGraphicsScene::taskQTBUG_16401_focusItem() rect->setFlag(QGraphicsItem::ItemIsFocusable); view.show(); - QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowActive(&view)); QVERIFY(!scene.focusItem()); @@ -4907,7 +4948,6 @@ void tst_QGraphicsScene::taskQTBUG_42915_focusNextPrevChild() widget2->setFocusPolicy(Qt::NoFocus); view.show(); - QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowActive(&view)); QTest::keyEvent(QTest::Click, &view, Qt::Key_Tab); diff --git a/tests/auto/widgets/graphicsview/qgraphicssceneindex/CMakeLists.txt b/tests/auto/widgets/graphicsview/qgraphicssceneindex/CMakeLists.txt index f95e618a16..867831d898 100644 --- a/tests/auto/widgets/graphicsview/qgraphicssceneindex/CMakeLists.txt +++ b/tests/auto/widgets/graphicsview/qgraphicssceneindex/CMakeLists.txt @@ -1,4 +1,11 @@ -# Generated from qgraphicssceneindex.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qgraphicssceneindex LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() if(NOT QT_FEATURE_private_tests) return() @@ -11,13 +18,10 @@ endif() qt_internal_add_test(tst_qgraphicssceneindex SOURCES tst_qgraphicssceneindex.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::Gui Qt::GuiPrivate Qt::Widgets Qt::WidgetsPrivate ) - -#### Keys ignored in scope 1:.:.:qgraphicssceneindex.pro:<TRUE>: -# _REQUIREMENTS = "qtConfig(private_tests)" diff --git a/tests/auto/widgets/graphicsview/qgraphicssceneindex/tst_qgraphicssceneindex.cpp b/tests/auto/widgets/graphicsview/qgraphicssceneindex/tst_qgraphicssceneindex.cpp index 4cad9906bb..b6d48b52d5 100644 --- a/tests/auto/widgets/graphicsview/qgraphicssceneindex/tst_qgraphicssceneindex.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicssceneindex/tst_qgraphicssceneindex.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> @@ -8,6 +8,7 @@ #include <private/qgraphicsscenebsptreeindex_p.h> #include <private/qgraphicssceneindex_p.h> #include <private/qgraphicsscenelinearindex_p.h> +#include <QtWidgets/private/qapplication_p.h> class tst_QGraphicsSceneIndex : public QObject { @@ -74,13 +75,13 @@ void tst_QGraphicsSceneIndex::scatteredItems() for (int i = 0; i < 10; ++i) scene.addRect(i*50, i*50, 40, 35); - QCOMPARE(scene.items(QPointF(5, 5)).count(), 1); - QCOMPARE(scene.items(QPointF(55, 55)).count(), 1); - QCOMPARE(scene.items(QPointF(-100, -100)).count(), 0); + QCOMPARE(scene.items(QPointF(5, 5)).size(), 1); + QCOMPARE(scene.items(QPointF(55, 55)).size(), 1); + QCOMPARE(scene.items(QPointF(-100, -100)).size(), 0); - QCOMPARE(scene.items(QRectF(0, 0, 10, 10)).count(), 1); - QCOMPARE(scene.items(QRectF(0, 0, 1000, 1000)).count(), 10); - QCOMPARE(scene.items(QRectF(-100, -1000, 0, 0)).count(), 0); + QCOMPARE(scene.items(QRectF(0, 0, 10, 10)).size(), 1); + QCOMPARE(scene.items(QRectF(0, 0, 1000, 1000)).size(), 10); + QCOMPARE(scene.items(QRectF(-100, -1000, 0, 0)).size(), 0); } void tst_QGraphicsSceneIndex::overlappedItems_data() @@ -99,17 +100,17 @@ void tst_QGraphicsSceneIndex::overlappedItems() for (int j = 0; j < 10; ++j) scene.addRect(i*50, j*50, 200, 200)->setPen(QPen(Qt::black, 0)); - QCOMPARE(scene.items(QPointF(5, 5)).count(), 1); - QCOMPARE(scene.items(QPointF(55, 55)).count(), 4); - QCOMPARE(scene.items(QPointF(105, 105)).count(), 9); - QCOMPARE(scene.items(QPointF(-100, -100)).count(), 0); - - QCOMPARE(scene.items(QRectF(0, 0, 1000, 1000)).count(), 100); - QCOMPARE(scene.items(QRectF(-100, -1000, 0, 0)).count(), 0); - QCOMPARE(scene.items(QRectF(0, 0, 200, 200)).count(), 16); - QCOMPARE(scene.items(QRectF(0, 0, 100, 100)).count(), 4); - QCOMPARE(scene.items(QRectF(0, 0, 1, 100)).count(), 2); - QCOMPARE(scene.items(QRectF(0, 0, 1, 1000)).count(), 10); + QCOMPARE(scene.items(QPointF(5, 5)).size(), 1); + QCOMPARE(scene.items(QPointF(55, 55)).size(), 4); + QCOMPARE(scene.items(QPointF(105, 105)).size(), 9); + QCOMPARE(scene.items(QPointF(-100, -100)).size(), 0); + + QCOMPARE(scene.items(QRectF(0, 0, 1000, 1000)).size(), 100); + QCOMPARE(scene.items(QRectF(-100, -1000, 0, 0)).size(), 0); + QCOMPARE(scene.items(QRectF(0, 0, 200, 200)).size(), 16); + QCOMPARE(scene.items(QRectF(0, 0, 100, 100)).size(), 4); + QCOMPARE(scene.items(QRectF(0, 0, 1, 100)).size(), 2); + QCOMPARE(scene.items(QRectF(0, 0, 1, 1000)).size(), 10); } void tst_QGraphicsSceneIndex::movingItems_data() @@ -128,20 +129,20 @@ void tst_QGraphicsSceneIndex::movingItems() scene.addRect(i*50, i*50, 40, 35); QGraphicsRectItem *box = scene.addRect(0, 0, 10, 10); - QCOMPARE(scene.items(QPointF(5, 5)).count(), 2); - QCOMPARE(scene.items(QPointF(-1, -1)).count(), 0); - QCOMPARE(scene.items(QRectF(0, 0, 5, 5)).count(), 2); + QCOMPARE(scene.items(QPointF(5, 5)).size(), 2); + QCOMPARE(scene.items(QPointF(-1, -1)).size(), 0); + QCOMPARE(scene.items(QRectF(0, 0, 5, 5)).size(), 2); box->setPos(10, 10); - QCOMPARE(scene.items(QPointF(9, 9)).count(), 1); - QCOMPARE(scene.items(QPointF(15, 15)).count(), 2); - QCOMPARE(scene.items(QRectF(0, 0, 1, 1)).count(), 1); + QCOMPARE(scene.items(QPointF(9, 9)).size(), 1); + QCOMPARE(scene.items(QPointF(15, 15)).size(), 2); + QCOMPARE(scene.items(QRectF(0, 0, 1, 1)).size(), 1); box->setPos(-5, -5); - QCOMPARE(scene.items(QPointF(-1, -1)).count(), 1); - QCOMPARE(scene.items(QRectF(0, 0, 1, 1)).count(), 2); + QCOMPARE(scene.items(QPointF(-1, -1)).size(), 1); + QCOMPARE(scene.items(QRectF(0, 0, 1, 1)).size(), 2); - QCOMPARE(scene.items(QRectF(0, 0, 1000, 1000)).count(), 11); + QCOMPARE(scene.items(QRectF(0, 0, 1000, 1000)).size(), 11); } void tst_QGraphicsSceneIndex::connectedToSceneRectChanged() @@ -290,7 +291,6 @@ void tst_QGraphicsSceneIndex::removeItems() QGraphicsView view(&scene); view.resize(600, 600); view.show(); - QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowActive(&view)); scene.removeItem(widgetChild1); @@ -322,7 +322,6 @@ void tst_QGraphicsSceneIndex::clear() QGraphicsView view(&scene); view.show(); - qApp->setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowActive(&view)); scene.clear(); diff --git a/tests/auto/widgets/graphicsview/qgraphicstransform/CMakeLists.txt b/tests/auto/widgets/graphicsview/qgraphicstransform/CMakeLists.txt index 12ba7dd834..a11036b30f 100644 --- a/tests/auto/widgets/graphicsview/qgraphicstransform/CMakeLists.txt +++ b/tests/auto/widgets/graphicsview/qgraphicstransform/CMakeLists.txt @@ -1,13 +1,20 @@ -# Generated from qgraphicstransform.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qgraphicstransform Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qgraphicstransform LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qgraphicstransform SOURCES tst_qgraphicstransform.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui Qt::Widgets ) diff --git a/tests/auto/widgets/graphicsview/qgraphicstransform/tst_qgraphicstransform.cpp b/tests/auto/widgets/graphicsview/qgraphicstransform/tst_qgraphicstransform.cpp index 114444ebb9..3ee63d288b 100644 --- a/tests/auto/widgets/graphicsview/qgraphicstransform/tst_qgraphicstransform.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicstransform/tst_qgraphicstransform.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> diff --git a/tests/auto/widgets/graphicsview/qgraphicsview/BLACKLIST b/tests/auto/widgets/graphicsview/qgraphicsview/BLACKLIST index 5ca22dfbda..ae5cbf7d6a 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsview/BLACKLIST +++ b/tests/auto/widgets/graphicsview/qgraphicsview/BLACKLIST @@ -1,23 +1,7 @@ -[task255529_transformationAnchorMouseAndViewportMargins] -opensuse-leap -[cursor] -opensuse-leap [cursor2] -ubuntu-16.04 -[sendEvent] -ubuntu-16.04 -opensuse-42.3 -[resizeAnchor] -opensuse-leap -rhel-7.6 -ubuntu -[update2] -opensuse-42.3 -[itemsInRect_cosmeticAdjust] -# QTBUG-66815 -ubuntu-16.04 -[fitInView] osx +[resizeAnchor] +rhel # QTBUG-87397 [itemsAtPoint] android diff --git a/tests/auto/widgets/graphicsview/qgraphicsview/CMakeLists.txt b/tests/auto/widgets/graphicsview/qgraphicsview/CMakeLists.txt index be9c4a3bc4..cf33de0b33 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsview/CMakeLists.txt +++ b/tests/auto/widgets/graphicsview/qgraphicsview/CMakeLists.txt @@ -1,16 +1,23 @@ -# Generated from qgraphicsview.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qgraphicsview Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qgraphicsview LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qgraphicsview SOURCES tst_qgraphicsview.cpp tst_qgraphicsview.h tst_qgraphicsview_2.cpp DEFINES QT_NO_CAST_TO_ASCII - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::Gui Qt::GuiPrivate @@ -19,14 +26,11 @@ qt_internal_add_test(tst_qgraphicsview Qt::WidgetsPrivate ) -#### Keys ignored in scope 1:.:.:qgraphicsview.pro:<TRUE>: -# testcase.timeout = "500" - ## Scopes: ##################################################################### qt_internal_extend_target(tst_qgraphicsview CONDITION QT_FEATURE_opengl - PUBLIC_LIBRARIES + LIBRARIES Qt::OpenGL Qt::OpenGLWidgets ) diff --git a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp index 849e290351..7ed1f28b0a 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.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 <QtTest/private/qtesthelpers_p.h> +#include <QtWidgets/private/qapplication_p.h> + using namespace QTestPrivate; Q_DECLARE_METATYPE(ExpectedValueDescription) @@ -77,6 +79,12 @@ static void sendMouseRelease(QWidget *widget, const QPoint &point, Qt::MouseButt QApplication::sendEvent(widget, &event); } +static bool isPlatformEGLFS() +{ + static const bool isEGLFS = !QGuiApplication::platformName().compare(QLatin1String("eglfs"), Qt::CaseInsensitive); + return isEGLFS; +} + class EventSpy : public QObject { Q_OBJECT @@ -246,6 +254,8 @@ private slots: #ifndef QT_NO_CURSOR void QTBUG_7438_cursor(); #endif + void resizeContentsOnItemDrag_data(); + void resizeContentsOnItemDrag(); public slots: void dummySlot() {} @@ -644,6 +654,8 @@ void tst_QGraphicsView::openGLViewport() { if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::OpenGL)) QSKIP("QOpenGL is not supported on this platform."); + if (isPlatformEGLFS()) + QSKIP("", "Resizing does not work on EGLFS on top level window", Continue); QGraphicsScene scene; scene.setBackgroundBrush(Qt::white); @@ -665,16 +677,16 @@ void tst_QGraphicsView::openGLViewport() view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); - QTRY_VERIFY(spy1.count() > 0); - QTRY_VERIFY(spy2.count() >= spy1.count()); + QTRY_VERIFY(spy1.size() > 0); + QTRY_VERIFY(spy2.size() >= spy1.size()); spy1.clear(); spy2.clear(); // Now test for resize (QTBUG-52419). This is special when the viewport is // a QOpenGLWidget since the underlying FBO must also be maintained. view.resize(300, 300); - QTRY_VERIFY(spy1.count() > 0); - QTRY_VERIFY(spy2.count() >= spy1.count()); + QTRY_VERIFY(spy1.size() > 0); + QTRY_VERIFY(spy2.size() >= spy1.size()); // There is no sane way to check if the framebuffer contents got updated // (grabFramebuffer is no good for the viewport case as that does not go // through paintGL). So skip the actual verification. @@ -1044,10 +1056,10 @@ void tst_QGraphicsView::rotated_rubberBand() sendMousePress(view.viewport(), QPoint(midWidth - 2, 0), Qt::LeftButton); sendMouseMove(view.viewport(), QPoint(midWidth + 2, view.viewport()->height()), Qt::LeftButton, Qt::LeftButton); - QCOMPARE(scene.selectedItems().count(), dim); - foreach (const QGraphicsItem *item, scene.items()) { + QCOMPARE(scene.selectedItems().size(), dim); + const auto items = scene.items(); + for (const QGraphicsItem *item : items) QCOMPARE(item->isSelected(), item->data(0).toBool()); - } sendMouseRelease(view.viewport(), QPoint(), Qt::LeftButton); } @@ -1625,6 +1637,9 @@ void tst_QGraphicsView::itemsInRect_cosmeticAdjust_data() void tst_QGraphicsView::itemsInRect_cosmeticAdjust() { + if (isPlatformEGLFS()) + QSKIP("", "Resizing does not work on EGLFS on top level window", Continue); + QFETCH(QRect, updateRect); QFETCH(int, numPaints); QFETCH(bool, adjustForAntialiasing); @@ -1918,6 +1933,9 @@ void tst_QGraphicsView::mapToSceneRect_data() void tst_QGraphicsView::mapToSceneRect() { + if (isPlatformEGLFS()) + QSKIP("", "Resizing does not work on EGLFS on top level window", Continue); + QFETCH(QRect, viewRect); QFETCH(QPolygonF, scenePoly); QFETCH(qreal, rotation); @@ -2135,7 +2153,6 @@ void tst_QGraphicsView::sendEvent() QGraphicsView view(&scene); view.show(); - QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowExposed(&view)); QVERIFY(QTest::qWaitForWindowActive(&view)); QCOMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&view)); @@ -2203,7 +2220,6 @@ void tst_QGraphicsView::wheelEvent() // Assign a view. QGraphicsView view(&scene); view.show(); - QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowExposed(&view)); QVERIFY(QTest::qWaitForWindowActive(&view)); QCOMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&view)); @@ -2440,7 +2456,6 @@ void tst_QGraphicsView::viewportUpdateMode() // Show the view, and initialize our test. view.show(); - qApp->setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowExposed(&view)); QVERIFY(QTest::qWaitForWindowActive(&view)); QTRY_VERIFY(!view.lastUpdateRegions.isEmpty()); @@ -2523,7 +2538,6 @@ void tst_QGraphicsView::viewportUpdateMode2() const QMargins margins = view.contentsMargins(); view.resize(200 + margins.left() + margins.right(), 200 + margins.top() + margins.bottom()); toplevel.show(); - qApp->setActiveWindow(&toplevel); QVERIFY(QTest::qWaitForWindowExposed(&toplevel)); QVERIFY(QTest::qWaitForWindowActive(&toplevel)); QTRY_VERIFY(view.painted); @@ -2735,7 +2749,8 @@ void tst_QGraphicsView::optimizationFlags_dontSavePainterState2() rectB->setTransform(QTransform::fromTranslate(200, 200)); rectB->setPen(QPen(Qt::black, 0)); - foreach (QGraphicsItem *item, scene.items()) + const auto items = scene.items(); + for (QGraphicsItem *item : items) item->setOpacity(0.6); CustomView view(&scene); @@ -2872,6 +2887,9 @@ public: void tst_QGraphicsView::scrollBarRanges() { + if (isPlatformEGLFS()) + QSKIP("", "Resizing does not work on EGLFS on top level window", Continue); + QFETCH(QByteArray, style); QFETCH(QSize, viewportSize); QFETCH(QRectF, sceneRect); @@ -3167,7 +3185,6 @@ void tst_QGraphicsView::task172231_untransformableItems() view.scale(2, 1); view.show(); - QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowExposed(&view)); QVERIFY(QTest::qWaitForWindowActive(&view)); QCOMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&view)); @@ -3229,7 +3246,6 @@ void tst_QGraphicsView::task187791_setSceneCausesUpdate() QGraphicsScene scene(0, 0, 200, 200); QGraphicsView view(&scene); view.show(); - qApp->setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowExposed(&view)); EventSpy updateSpy(view.viewport(), QEvent::Paint); @@ -3254,7 +3270,8 @@ protected: { ++mouseMoves; QGraphicsView::mouseMoveEvent(event); - foreach (QGraphicsItem *item, scene()->items()) { + const auto items = scene()->items(); + for (QGraphicsItem *item : items) { scene()->removeItem(item); delete item; } @@ -3315,7 +3332,6 @@ void tst_QGraphicsView::task207546_focusCrash() widget.layout()->addWidget(gr2); widget.show(); widget.activateWindow(); - QApplication::setActiveWindow(&widget); QVERIFY(QTest::qWaitForWindowActive(&widget)); QCOMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&widget)); widget.focusNextPrevChild(true); @@ -3407,7 +3423,6 @@ void tst_QGraphicsView::task239729_noViewUpdate() QCOMPARE(spy.count(), 0); view->show(); - qApp->setActiveWindow(view); QVERIFY(QTest::qWaitForWindowActive(view)); QTRY_VERIFY(spy.count() >= 1); @@ -3539,6 +3554,9 @@ void tst_QGraphicsView::embeddedViewsWithFocus() void focusOutEvent(QFocusEvent *) override { --focusCount; } }; + if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + QSKIP("QWindow::requestActivate() is not supported."); + QGraphicsScene innerScene; FocusWidget *innerWidget = new FocusWidget; innerScene.addWidget(innerWidget); @@ -3640,6 +3658,9 @@ void tst_QGraphicsView::moveItemWhileScrolling_data() void tst_QGraphicsView::moveItemWhileScrolling() { + if (isPlatformEGLFS()) + QSKIP("", "Resizing does not work on EGLFS on top level window", Continue); + QFETCH(bool, adjustForAntialiasing); QFETCH(bool, changedConnected); @@ -4032,7 +4053,7 @@ void tst_QGraphicsView::exposeRegion() CustomView view; view.setScene(&scene); view.show(); - qApp->setActiveWindow(&view); + QApplicationPrivate::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowExposed(&view)); QVERIFY(QTest::qWaitForWindowActive(&view)); @@ -4106,7 +4127,6 @@ void tst_QGraphicsView::update() QVERIFY(QTest::qWaitForWindowExposed(&toplevel)); - QApplication::setActiveWindow(&toplevel); QApplication::processEvents(); QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&toplevel)); @@ -4163,6 +4183,9 @@ void tst_QGraphicsView::update2_data() void tst_QGraphicsView::update2() { + if (isPlatformEGLFS()) + QSKIP("", "Resizing does not work on EGLFS on top level window", Continue); + QFETCH(qreal, penWidth); QFETCH(bool, antialiasing); QFETCH(bool, changedConnected); @@ -4188,7 +4211,7 @@ void tst_QGraphicsView::update2() view.setFrameStyle(0); view.resize(200, 200); view.show(); - qApp->setActiveWindow(&view); + QApplicationPrivate::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowExposed(&view)); QVERIFY(QTest::qWaitForWindowActive(&view)); QTRY_VERIFY(rect->numPaints > 0); @@ -4258,7 +4281,7 @@ void tst_QGraphicsView::update_ancestorClipsChildrenToShape() CustomView view(&scene); view.show(); - qApp->setActiveWindow(&view); + QApplicationPrivate::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowExposed(&view)); QVERIFY(QTest::qWaitForWindowActive(&view)); QTRY_VERIFY(view.painted); @@ -4312,7 +4335,7 @@ void tst_QGraphicsView::update_ancestorClipsChildrenToShape2() CustomView view(&scene); view.show(); - qApp->setActiveWindow(&view); + QApplicationPrivate::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowExposed(&view)); QVERIFY(QTest::qWaitForWindowActive(&view)); QTRY_VERIFY(view.painted); @@ -4373,7 +4396,6 @@ void tst_QGraphicsView::inputMethodSensitivity() QGraphicsScene scene; QGraphicsView view(&scene); view.show(); - QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowExposed(&view)); QVERIFY(QTest::qWaitForWindowActive(&view)); QCOMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&view)); @@ -4471,7 +4493,6 @@ void tst_QGraphicsView::inputContextReset() QVERIFY(view.testAttribute(Qt::WA_InputMethodEnabled)); view.show(); - QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowExposed(&view)); QVERIFY(QTest::qWaitForWindowActive(&view)); QCOMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&view)); @@ -4619,7 +4640,6 @@ void tst_QGraphicsView::task255529_transformationAnchorMouseAndViewportMargins() VpGraphicsView view(&scene); view.setWindowFlags(Qt::X11BypassWindowManagerHint); view.show(); - qApp->setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowExposed(&view)); const bool isActiveWindow = QTest::qWaitForWindowActive(&view); if (!isActiveWindow) @@ -4762,6 +4782,9 @@ void tst_QGraphicsView::QTBUG_4151_clipAndIgnore() void tst_QGraphicsView::QTBUG_5859_exposedRect() { + if (isPlatformEGLFS()) + QSKIP("", "Resizing does not work on EGLFS on top level window", Continue); + class CustomScene : public QGraphicsScene { public: @@ -4790,7 +4813,6 @@ void tst_QGraphicsView::QTBUG_5859_exposedRect() QGraphicsView view(&scene); view.scale(4.15, 4.15); view.showNormal(); - QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowExposed(&view)); QVERIFY(QTest::qWaitForWindowActive(&view)); @@ -4862,7 +4884,6 @@ void tst_QGraphicsView::hoverLeave() scene.addItem(item); view.showNormal(); - qApp->setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowExposed(&view)); QWindow *viewWindow = view.window()->windowHandle(); @@ -4941,7 +4962,6 @@ void tst_QGraphicsView::QTBUG_70255_scrollTo() view.centerOn(0, 0); view.show(); - QApplication::setActiveWindow(&view); if (!QTest::qWaitForWindowExposed(&view) || !QTest::qWaitForWindowActive(&view)) QSKIP("Failed to show and activate window"); @@ -4955,5 +4975,111 @@ void tst_QGraphicsView::QTBUG_70255_scrollTo() QCOMPARE(point, QPoint(0, -500)); } +void tst_QGraphicsView::resizeContentsOnItemDrag_data() +{ + QTest::addColumn<Qt::Alignment>("alignment"); + QTest::addColumn<Qt::Orientation>("orientation"); + QTest::addRow("Center right") << Qt::Alignment(Qt::AlignCenter) << Qt::Horizontal; + QTest::addRow("Center down") << Qt::Alignment(Qt::AlignCenter) << Qt::Vertical; + QTest::addRow("BottomLeft right") << (Qt::AlignBottom | Qt::AlignLeft) << Qt::Horizontal; + QTest::addRow("TopRight down") << (Qt::AlignTop | Qt::AlignRight) << Qt::Vertical; +} + +void tst_QGraphicsView::resizeContentsOnItemDrag() +{ + QFETCH(Qt::Alignment, alignment); + QFETCH(Qt::Orientation, orientation); + + QGraphicsView view; + QGraphicsScene scene; + view.setFixedSize(200, 200); + view.setScene(&scene); + + view.setAlignment(alignment); + + class MovableItem : public QGraphicsEllipseItem + { + public: + using QGraphicsEllipseItem::QGraphicsEllipseItem; + + QList<QPointF> scenePositions; + + protected: + void mousePressEvent(QGraphicsSceneMouseEvent *event) override + { + scenePositions << event->scenePos(); + } + void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override + { + scenePositions << event->scenePos(); + QGraphicsEllipseItem::mouseMoveEvent(event); + } + }; + + MovableItem item(-10, -10, 20, 20); + item.setFlags(QGraphicsItem::ItemIsMovable); + scene.addItem(&item); + view.show(); + QVERIFY(QTest::qWaitForWindowExposed(&view)); + + // Position the item near the relevant edge of the view, with a few pixels + // to go until the scrollbars should be showing. + if (orientation == Qt::Horizontal) + item.setPos(view.width() - item.rect().width() - 5, 0); + else + item.setPos(0, view.height() - item.rect().height() - 5); + QApplication::processEvents(); // queued connection used to trigger recalculateContentSize + QPoint mousePos = view.mapFromScene(item.pos()); + + QTest::mousePress(view.viewport(), Qt::LeftButton, {}, mousePos); + QCOMPARE(item.scenePositions.count(), 1); + QCOMPARE(item.scenePositions.takeLast(), view.mapToScene(mousePos)); + + auto lastItemPos = item.pos(); + auto lastScenePos = view.mapToScene(mousePos); + int overshoot = 0; + const QScrollBar *scrollBar = orientation == Qt::Horizontal + ? view.horizontalScrollBar() + : view.verticalScrollBar(); + // Drag the item until the scroll bars become visible, and then for a few more pixels. + // Verify that the item doesn't jump when the scrollbar shows. + while (overshoot < 10) { + if (orientation == Qt::Horizontal) + mousePos.rx() += 1; + else + mousePos.ry() += 1; + QTest::mouseMove(view.viewport(), mousePos); + QApplication::processEvents(); // queued connection used to trigger recalculateContentSize + const bool scrollbarAvailable = scrollBar->maximum() > scrollBar->minimum(); + bool allowMoreEvents = false; + if (scrollbarAvailable) { + if (!overshoot) { + QTRY_VERIFY(scrollBar->isVisible()); + // scrollbar becoming visible triggers event replay, so we get more than one + allowMoreEvents = true; + } + ++overshoot; + } + if (allowMoreEvents) + QCOMPARE_GE(item.scenePositions.count(), 1); + else + QCOMPARE(item.scenePositions.count(), 1); + const auto scenePos = item.scenePositions.takeLast(); + item.scenePositions.clear(); + + const auto same = orientation == Qt::Horizontal ? &QPointF::y : &QPointF::x; + const auto moved = orientation == Qt::Horizontal ? &QPointF::x : &QPointF::y; + QCOMPARE((item.pos().*same)(), (lastItemPos.*same)()); + QCOMPARE_GE((item.pos().*moved)() - (lastItemPos.*moved)(), 1); + QCOMPARE_LE((item.pos().*moved)() - (lastItemPos.*moved)(), 2); + lastItemPos = item.pos(); + + QCOMPARE((scenePos.*same)(), (lastScenePos.*same)()); + QCOMPARE_GE((scenePos.*moved)() - (lastScenePos.*moved)(), 1); + QCOMPARE_LE((scenePos.*moved)() - (lastScenePos.*moved)(), 2); + lastScenePos = scenePos; + } +} + QTEST_MAIN(tst_QGraphicsView) #include "tst_qgraphicsview.moc" diff --git a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.h b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.h index 9fd35b325b..2fb5ed638c 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.h +++ b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.h @@ -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 #ifndef TST_QGRAPHICSVIEW_H #define TST_QGRAPHICSVIEW_H diff --git a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview_2.cpp b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview_2.cpp index 9e9a4093ba..1380e007e7 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview_2.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview_2.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> #include <QtCore/QSize> #include <QtCore/QRectF> diff --git a/tests/auto/widgets/graphicsview/qgraphicswidget/BLACKLIST b/tests/auto/widgets/graphicsview/qgraphicswidget/BLACKLIST index 65a6f5b8b9..cad381b7b7 100644 --- a/tests/auto/widgets/graphicsview/qgraphicswidget/BLACKLIST +++ b/tests/auto/widgets/graphicsview/qgraphicswidget/BLACKLIST @@ -6,6 +6,3 @@ b2qt [updateFocusChainWhenChildDie] b2qt qnx -[initialShow] -macos ci -opensuse-leap diff --git a/tests/auto/widgets/graphicsview/qgraphicswidget/CMakeLists.txt b/tests/auto/widgets/graphicsview/qgraphicswidget/CMakeLists.txt index 8cf7f92cc3..42e30e4f5d 100644 --- a/tests/auto/widgets/graphicsview/qgraphicswidget/CMakeLists.txt +++ b/tests/auto/widgets/graphicsview/qgraphicswidget/CMakeLists.txt @@ -1,13 +1,20 @@ -# Generated from qgraphicswidget.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qgraphicswidget Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qgraphicswidget LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qgraphicswidget SOURCES tst_qgraphicswidget.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::Gui Qt::GuiPrivate diff --git a/tests/auto/widgets/graphicsview/qgraphicswidget/tst_qgraphicswidget.cpp b/tests/auto/widgets/graphicsview/qgraphicswidget/tst_qgraphicswidget.cpp index 9553b939e2..9fd93ca91d 100644 --- a/tests/auto/widgets/graphicsview/qgraphicswidget/tst_qgraphicswidget.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicswidget/tst_qgraphicswidget.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> @@ -18,6 +18,8 @@ #include <qscreen.h> #include <qsignalspy.h> +#include <QtWidgets/private/qapplication_p.h> + typedef QList<QGraphicsItem *> QGraphicsItemList; class EventSpy : public QObject @@ -144,8 +146,16 @@ private slots: void QT_BUG_6544_tabFocusFirstUnsetWhenRemovingItems(); void QT_BUG_12056_tabFocusFirstUnsetWhenRemovingItems(); void QTBUG_45867_send_itemChildAddedChange_to_parent(); + +private: + static bool hasWindowActivation(); }; +bool tst_QGraphicsWidget::hasWindowActivation() +{ + return (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)); +} + // Subclass that exposes the protected functions. class SubQGraphicsWidget : public QGraphicsWidget { public: @@ -940,9 +950,9 @@ void tst_QGraphicsWidget::geometry() widget.setPos(pos); widget.resize(size); if (!size.isNull() && !pos.isNull()) - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); if (!size.isNull() && pos.isNull()) - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); QCOMPARE(widget.geometry(), QRectF(pos, size)); } @@ -953,10 +963,10 @@ void tst_QGraphicsWidget::geometryChanged() QCOMPARE(w.geometry(), QRectF(0, 0, 200, 200)); QSignalSpy spy(&w, SIGNAL(geometryChanged())); w.setGeometry(0, 0, 100, 100); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); QCOMPARE(w.geometry(), QRectF(0, 0, 100, 100)); w.setPos(10, 10); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); QCOMPARE(w.geometry(), QRectF(10, 10, 100, 100)); } @@ -968,10 +978,10 @@ void tst_QGraphicsWidget::width() QSignalSpy spy(&w, SIGNAL(widthChanged())); w.setProperty("width", qreal(50)); QCOMPARE(w.property("width").toReal(), qreal(50)); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); //calling old school setGeometry should work too w.setGeometry(0, 0, 200, 200); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); } void tst_QGraphicsWidget::height() @@ -981,10 +991,10 @@ void tst_QGraphicsWidget::height() QSignalSpy spy(&w, SIGNAL(heightChanged())); w.setProperty("height", qreal(50)); QCOMPARE(w.property("height").toReal(), qreal(50)); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); //calling old school setGeometry should work too w.setGeometry(0, 0, 200, 200); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); } void tst_QGraphicsWidget::getContentsMargins_data() @@ -1049,7 +1059,10 @@ void tst_QGraphicsWidget::initStyleOption() QGraphicsView view(&scene); view.resize(300, 300); view.show(); - QVERIFY(QTest::qWaitForWindowActive(&view)); + if (hasWindowActivation()) + QVERIFY(QTest::qWaitForWindowActive(&view)); + else + QVERIFY(QTest::qWaitForWindowExposed(&view)); view.setAlignment(Qt::AlignTop | Qt::AlignLeft); SubQGraphicsWidget *widget = new SubQGraphicsWidget; @@ -1063,10 +1076,12 @@ void tst_QGraphicsWidget::initStyleOption() QFETCH(bool, enabled); widget->setEnabled(enabled); QFETCH(bool, focus); - if (focus) { - widget->setFlag(QGraphicsItem::ItemIsFocusable, true); - widget->setFocus(); - QVERIFY(widget->hasFocus()); + if (hasWindowActivation()) { + if (focus) { + widget->setFlag(QGraphicsItem::ItemIsFocusable, true); + widget->setFocus(); + QVERIFY(widget->hasFocus()); + } } QFETCH(bool, underMouse); if (underMouse) { @@ -1085,8 +1100,10 @@ void tst_QGraphicsWidget::initStyleOption() bool isEnabled = option.state & QStyle::State_Enabled; QCOMPARE(isEnabled, enabled); - bool hasFocus = option.state & QStyle::State_HasFocus; - QCOMPARE(hasFocus, focus); + if (hasWindowActivation()) { + bool hasFocus = option.state & QStyle::State_HasFocus; + QCOMPARE(hasFocus, focus); + } bool isUnderMouse = option.state & QStyle::State_MouseOver; QCOMPARE(isUnderMouse, underMouse); // if (layoutDirection != Qt::LeftToRight) @@ -1123,12 +1140,12 @@ void tst_QGraphicsWidget::layout() widget.setLayout(layout); QTRY_COMPARE(widget.layout(), static_cast<QGraphicsLayout*>(layout)); - for (int i = 0; i < children.count(); ++i) { + for (int i = 0; i < children.size(); ++i) { SubQGraphicsWidget *item = children[i]; QCOMPARE(item->parentWidget(), (QGraphicsWidget *)&widget); QVERIFY(item->geometry() != QRectF(0, 0, -1, -1)); } - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); // don't crash widget.setLayout(0); } @@ -1161,7 +1178,7 @@ void tst_QGraphicsWidget::layoutDirection() QCOMPARE(widget.testAttribute(Qt::WA_SetLayoutDirection), true); view->show(); QVERIFY(QTest::qWaitForWindowExposed(view.data())); - for (int i = 0; i < children.count(); ++i) { + for (int i = 0; i < children.size(); ++i) { QTRY_COMPARE(children[i]->layoutDirection(), layoutDirection); QTRY_COMPARE(children[i]->testAttribute(Qt::WA_SetLayoutDirection), false); view->update(); @@ -1371,7 +1388,6 @@ void tst_QGraphicsWidget::setTabOrder() QGraphicsScene scene; QGraphicsView view(&scene); view.show(); - QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowActive(&view)); QGraphicsWidget *lastItem = nullptr; @@ -1399,7 +1415,7 @@ void tst_QGraphicsWidget::setTabOrder() QVERIFY(view.viewport()->hasFocus()); int currentItem = 0; - while (currentItem < children.count() - 1) { + while (currentItem < children.size() - 1) { QTest::keyPress(view.viewport(), Qt::Key_Tab); ++currentItem; QVERIFY(children[currentItem % children.size()]->hasFocus()); @@ -1443,7 +1459,6 @@ void tst_QGraphicsWidget::setTabOrderAndReparent() QGraphicsScene scene; QGraphicsView view(&scene); view.show(); - QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowActive(&view)); QCOMPARE(QApplication::activeWindow(), (QWidget*)&view); @@ -1548,7 +1563,7 @@ void tst_QGraphicsWidget::unsetLayoutDirection() widget.setLayoutDirection(layoutDirection); widget.unsetLayoutDirection(); QCOMPARE(widget.testAttribute(Qt::WA_SetLayoutDirection), false); - for (int i = 0; i < children.count(); ++i) { + for (int i = 0; i < children.size(); ++i) { QCOMPARE(children[i]->layoutDirection(), Qt::LeftToRight); } } @@ -1573,7 +1588,6 @@ void tst_QGraphicsWidget::verifyFocusChain() QGraphicsScene scene; QGraphicsView view(&scene); view.show(); - QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowActive(&view)); { @@ -1665,7 +1679,6 @@ void tst_QGraphicsWidget::verifyFocusChain() w1_2->setFocusPolicy(Qt::StrongFocus); scene.addItem(w1_2); window->show(); - QApplication::setActiveWindow(window.data()); QVERIFY(QTest::qWaitForWindowActive(window.data())); lineEdit->setFocus(); @@ -1713,13 +1726,16 @@ void tst_QGraphicsWidget::verifyFocusChain() void tst_QGraphicsWidget::updateFocusChainWhenChildDie() { + if (!hasWindowActivation()) + QSKIP("Window activation is not supported"); + const QRect availableGeometry = QGuiApplication::primaryScreen()->availableGeometry(); QGraphicsScene scene; QGraphicsView view(&scene); view.resize(200, 150); view.move(availableGeometry.topLeft() + QPoint(50, 50)); view.show(); - QApplication::setActiveWindow(&view); + view.activateWindow(); QVERIFY(QTest::qWaitForWindowActive(&view)); // delete item in focus chain with no focus and verify chain @@ -1748,13 +1764,8 @@ void tst_QGraphicsWidget::updateFocusChainWhenChildDie() w->setParentItem(parent); //We don't crash perfect QVERIFY(w); - const QPoint center(view.viewport()->width() / 2, view.viewport()->height() / 2); - QTest::mouseMove(view.viewport(), center); - QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, center); -#ifdef Q_OS_MAC - QEXPECT_FAIL("", "QTBUG-23699", Continue); -#endif - QTRY_COMPARE(qApp->activeWindow(), static_cast<QWidget *>(&view)); + view.activateWindow(); + QVERIFY(QTest::qWaitForWindowActive(&view)); QTRY_COMPARE(scene.focusItem(), static_cast<QGraphicsItem *>(w)); } @@ -1840,7 +1851,7 @@ enum WhichSize { MinimumSizeHint, PreferredSizeHint, MaximumSizeHint, - Size, + WidgetSize, None, }; @@ -1855,48 +1866,48 @@ void tst_QGraphicsWidget::setSizes_data() QTest::addColumn<QList<Inst>>("compareInstructions"); QTest::newRow("minSize1") << (QList<Inst>() - << Inst(Size, QSize(25, 25)) << Inst(MinimumSize, QSize(10, 10))) - << (QList<Inst>() << Inst(Size, QSize(25, 25))); - QTest::newRow("minSize2") << (QList<Inst>() << Inst(Size, QSizeF(20, 20)) + << Inst(WidgetSize, QSize(25, 25)) << Inst(MinimumSize, QSize(10, 10))) + << (QList<Inst>() << Inst(WidgetSize, QSize(25, 25))); + QTest::newRow("minSize2") << (QList<Inst>() << Inst(WidgetSize, QSizeF(20, 20)) << Inst(MinimumSize, QSizeF(25, 25))) - << (QList<Inst>() << Inst(Size, QSizeF(25, 25))); + << (QList<Inst>() << Inst(WidgetSize, QSizeF(25, 25))); QTest::newRow("minWidth1") << (QList<Inst>() - << Inst(Size, QSizeF(20, 20)) << Inst(MinimumWidth, 5.0)) - << (QList<Inst>() << Inst(Size, QSizeF(20, 20))); + << Inst(WidgetSize, QSizeF(20, 20)) << Inst(MinimumWidth, 5.0)) + << (QList<Inst>() << Inst(WidgetSize, QSizeF(20, 20))); QTest::newRow("minWidth2") << (QList<Inst>() - << Inst(Size, QSizeF(20, 20)) << Inst(MinimumWidth, 25.0)) - << (QList<Inst>() << Inst(Size, QSizeF(25, 20))); + << Inst(WidgetSize, QSizeF(20, 20)) << Inst(MinimumWidth, 25.0)) + << (QList<Inst>() << Inst(WidgetSize, QSizeF(25, 20))); QTest::newRow("minHeight1") << (QList<Inst>() - << Inst(Size, QSizeF(20, 20)) << Inst(MinimumHeight, 5.0)) - << (QList<Inst>() << Inst(Size, QSizeF(20, 20))); + << Inst(WidgetSize, QSizeF(20, 20)) << Inst(MinimumHeight, 5.0)) + << (QList<Inst>() << Inst(WidgetSize, QSizeF(20, 20))); QTest::newRow("minHeight2") << (QList<Inst>() - << Inst(Size, QSizeF(20, 20)) << Inst(MinimumHeight, 25.0)) - << (QList<Inst>() << Inst(Size, QSizeF(20, 25))); - QTest::newRow("maxSize1") << (QList<Inst>() << Inst(Size, QSizeF(40, 40)) + << Inst(WidgetSize, QSizeF(20, 20)) << Inst(MinimumHeight, 25.0)) + << (QList<Inst>() << Inst(WidgetSize, QSizeF(20, 25))); + QTest::newRow("maxSize1") << (QList<Inst>() << Inst(WidgetSize, QSizeF(40, 40)) << Inst(MaximumSize, QSizeF(30, 30))) - << (QList<Inst>() << Inst(Size, QSizeF(30, 30))); - QTest::newRow("maxSize2") << (QList<Inst>() << Inst(Size, QSizeF(40, 40)) + << (QList<Inst>() << Inst(WidgetSize, QSizeF(30, 30))); + QTest::newRow("maxSize2") << (QList<Inst>() << Inst(WidgetSize, QSizeF(40, 40)) << Inst(MaximumSize, QSizeF(30, -1))) - << (QList<Inst>() << Inst(Size, QSizeF(30, 40))); - QTest::newRow("maxSize3") << (QList<Inst>() << Inst(Size, QSizeF(40, 40)) + << (QList<Inst>() << Inst(WidgetSize, QSizeF(30, 40))); + QTest::newRow("maxSize3") << (QList<Inst>() << Inst(WidgetSize, QSizeF(40, 40)) << Inst(MaximumSize, QSizeF(-1, 30))) - << (QList<Inst>() << Inst(Size, QSizeF(40, 30))); + << (QList<Inst>() << Inst(WidgetSize, QSizeF(40, 30))); QTest::newRow("maxWidth1") << (QList<Inst>() - << Inst(Size, QSizeF(40, 40)) << Inst(MaximumWidth, 30)) - << (QList<Inst>() << Inst(Size, QSizeF(30, 40))); + << Inst(WidgetSize, QSizeF(40, 40)) << Inst(MaximumWidth, 30)) + << (QList<Inst>() << Inst(WidgetSize, QSizeF(30, 40))); QTest::newRow("maxHeight") << (QList<Inst>() - << Inst(Size, QSizeF(40, 40)) << Inst(MaximumHeight, 20)) - << (QList<Inst>() << Inst(Size, QSizeF(40, 20))); - QTest::newRow("unsetMinSize") << (QList<Inst>() << Inst(Size, QSizeF(40, 40)) + << Inst(WidgetSize, QSizeF(40, 40)) << Inst(MaximumHeight, 20)) + << (QList<Inst>() << Inst(WidgetSize, QSizeF(40, 20))); + QTest::newRow("unsetMinSize") << (QList<Inst>() << Inst(WidgetSize, QSizeF(40, 40)) << Inst(MinimumSize, QSizeF(-1, -1))) << (QList<Inst>() << Inst(MinimumSize, QSizeF(5, 5))); - QTest::newRow("unsetMaxSize") << (QList<Inst>() << Inst(Size, QSizeF(40, 40)) + QTest::newRow("unsetMaxSize") << (QList<Inst>() << Inst(WidgetSize, QSizeF(40, 40)) << Inst(MaximumSize, QSizeF(-1, -1))) << (QList<Inst>() << Inst(MaximumSize, QSizeF(500, 500))); QTest::newRow("unsetMinSize, expand size to minimumSizeHint") - << (QList<Inst>() << Inst(MinimumSize, QSize(0, 0)) << Inst(Size, QSize(1, 1)) + << (QList<Inst>() << Inst(MinimumSize, QSize(0, 0)) << Inst(WidgetSize, QSize(1, 1)) << Inst(MinimumSize, QSize(-1.0, -1.0))) - << (QList<Inst>() << Inst(Size, QSize(5, 5)) << Inst(MinimumSize, QSize(5, 5))); + << (QList<Inst>() << Inst(WidgetSize, QSize(5, 5)) << Inst(MinimumSize, QSize(5, 5))); } void tst_QGraphicsWidget::setSizes() @@ -1912,7 +1923,7 @@ void tst_QGraphicsWidget::setSizes() QSizeF max = QSizeF(50, 50); int i; - for (i = 0; i < inputInstructions.count(); ++i) { + for (i = 0; i < inputInstructions.size(); ++i) { Inst input = inputInstructions.at(i); // defaults @@ -1926,7 +1937,7 @@ void tst_QGraphicsWidget::setSizes() case MaximumSize: max = input.second.toSizeF(); break; - case Size: + case WidgetSize : widget->resize(input.second.toSizeF()); break; case MinimumWidth: @@ -1966,7 +1977,7 @@ void tst_QGraphicsWidget::setSizes() widget->setPreferredSize(pref); widget->setMaximumSize(max); - for (i = 0; i < compareInstructions.count(); ++i) { + for (i = 0; i < compareInstructions.size(); ++i) { Inst input = compareInstructions.at(i); switch (input.first) { case MinimumSize: @@ -1978,7 +1989,7 @@ void tst_QGraphicsWidget::setSizes() case MaximumSize: QTRY_COMPARE(widget->maximumSize(), input.second.toSizeF()); break; - case Size: + case WidgetSize: QTRY_COMPARE(widget->size(), input.second.toSizeF()); break; case MinimumWidth: @@ -2679,7 +2690,6 @@ void tst_QGraphicsWidget::task250119_shortcutContext() QGraphicsView view; view.setScene(&scene); view.show(); - QApplication::setActiveWindow(&view); QTRY_COMPARE(QApplication::activeWindow(), (QWidget*)&view); @@ -2716,11 +2726,11 @@ void tst_QGraphicsWidget::task250119_shortcutContext() w_signal.setFocus(); QTest::keyPress(&view, Qt::Key_B); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); w_signal.clearFocus(); QTest::keyPress(&view, Qt::Key_B); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); scene.removeItem(&w_signal); } @@ -3098,8 +3108,7 @@ void tst_QGraphicsWidget::initialShow() dummyView->setWindowFlags(Qt::X11BypassWindowManagerHint); EventSpy paintSpy(dummyView->viewport(), QEvent::Paint); dummyView->show(); - qApp->setActiveWindow(dummyView.data()); - QVERIFY(QTest::qWaitForWindowActive(dummyView.data())); + QVERIFY(QTest::qWaitForWindowExposed(dummyView.data())); const int expectedRepaintCount = paintSpy.count(); dummyView.reset(); @@ -3112,8 +3121,7 @@ void tst_QGraphicsWidget::initialShow() QGraphicsView view(&scene); view.setWindowFlags(view.windowFlags()|Qt::X11BypassWindowManagerHint); view.show(); - qApp->setActiveWindow(&view); - QVERIFY(QTest::qWaitForWindowActive(&view)); + QVERIFY(QTest::qWaitForWindowExposed(&view)); QTRY_COMPARE(widget->repaints, expectedRepaintCount); } |