diff options
Diffstat (limited to 'tests/auto/widgets/graphicsview')
46 files changed, 1661 insertions, 1608 deletions
diff --git a/tests/auto/widgets/graphicsview/CMakeLists.txt b/tests/auto/widgets/graphicsview/CMakeLists.txt index 5e6fddccce..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) @@ -17,20 +18,6 @@ add_subdirectory(qgraphicsobject) add_subdirectory(qgraphicspixmapitem) add_subdirectory(qgraphicspolygonitem) add_subdirectory(qgraphicstransform) -if(QT_FEATURE_style_fusion) - # special case begin - # These tests are never run in coin with qmake since the statement - # !qtConfig(style-fusion): always passes causing the subdirs to be removed. - # For these tests to be generated the .pro file needs to be patched and - # the above line changed to !qtConfig(style-fusion). That being said, - # one of the test fails and needs to be corrected by someone with know how in - # that area. Until then we will disable them to mimic the behavior seen in - # coin. - #add_subdirectory(qgraphicsproxywidget) - #add_subdirectory(qgraphicswidget) - # special case end -endif() -# QTBUG-87671 # special case -if(NOT ANDROID) - add_subdirectory(qgraphicsview) -endif() +add_subdirectory(qgraphicsproxywidget) +add_subdirectory(qgraphicswidget) +add_subdirectory(qgraphicsview) 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 92cffa0226..cf37aa5639 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// 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 9e0293d875..9a047b876d 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QtGui> #include <QTest> @@ -1688,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); @@ -1703,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), @@ -1720,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(); @@ -1732,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 @@ -2193,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); @@ -2210,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), @@ -2220,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), @@ -2236,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); @@ -3024,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); @@ -3050,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), @@ -3067,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); } @@ -3076,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 ba8a309674..28c439dbcd 100644 --- a/tests/auto/widgets/graphicsview/qgraphicseffectsource/tst_qgraphicseffectsource.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicseffectsource/tst_qgraphicseffectsource.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> #include <QtWidgets/qgraphicseffect.h> @@ -179,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 effd8a28c1..fad75ec045 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> @@ -1683,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); @@ -2184,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); @@ -2199,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)); } @@ -2343,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); @@ -2358,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)); } @@ -2921,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); @@ -2936,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)); } @@ -3001,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; @@ -3181,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 81e95cc3df..35356adcfc 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> @@ -63,6 +38,10 @@ #include <QSignalSpy> #include <QTimer> +#include <QtGui/private/qeventpoint_p.h> + +#include <QtWidgets/private/qapplication_p.h> + using AbstractGraphicsShapeItemPtr = QSharedPointer<QAbstractGraphicsShapeItem>; using GraphicsItems = QList<QGraphicsItem *>; using GraphicsItemsList = QList<QGraphicsItem *>; @@ -74,7 +53,7 @@ Q_DECLARE_METATYPE(QSizeF) Q_DECLARE_METATYPE(QTransform) #if defined(Q_OS_WIN) -#include <windows.h> +#include <qt_windows.h> #define Q_CHECK_PAINTEVENTS \ if (::SwitchDesktop(::GetThreadDesktop(::GetCurrentThreadId())) == 0) \ QSKIP("The Graphics View doesn't get the paint events"); @@ -1014,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)); @@ -1071,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)); { @@ -2229,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(); @@ -2237,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); @@ -3397,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())); @@ -3624,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); } @@ -4967,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)); @@ -5360,8 +5336,9 @@ void tst_QGraphicsItem::deleteItemInEventHandlers() #ifndef QT_NO_CONTEXTMENU if (!HarakiriItem::dead) { - QContextMenuEvent event(QContextMenuEvent::Other, - view.mapFromScene(item->scenePos())); + auto viewPos = view.mapFromScene(item->scenePos()); + QContextMenuEvent event(QContextMenuEvent::Other, viewPos, + view.mapToGlobal(viewPos)); QCoreApplication::sendEvent(view.viewport(), &event); } #endif // QT_NO_CONTEXTMENU @@ -5587,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); @@ -5703,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; @@ -6931,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); @@ -7288,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()); @@ -7322,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 @@ -7506,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 @@ -8167,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(); @@ -8239,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(); @@ -8273,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)); @@ -9293,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)); } @@ -9691,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); @@ -10771,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(); @@ -10825,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(); @@ -10940,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()); @@ -11017,13 +11003,13 @@ static QList<QEventPoint> QEventPoint::State state = QEventPoint::State::Pressed) { const QPointF screenPos = view.viewport()->mapToGlobal(view.mapFromScene(scenePos)); - QMutableEventPoint tp(0, state, scenePos, screenPos); - tp.setState(state); - tp.setScenePosition(scenePos); - tp.setGlobalPosition(screenPos); - tp.setGlobalPressPosition(screenPos); - tp.setGlobalLastPosition(screenPos); - tp.setEllipseDiameters(ellipseDiameters); + QEventPoint tp(0, state, scenePos, screenPos); + QMutableEventPoint::setState(tp, state); + QMutableEventPoint::setScenePosition(tp, scenePos); + QMutableEventPoint::setGlobalPosition(tp, screenPos); + QMutableEventPoint::setGlobalPressPosition(tp, screenPos); + QMutableEventPoint::setGlobalLastPosition(tp, screenPos); + QMutableEventPoint::setEllipseDiameters(tp, ellipseDiameters); return QList<QEventPoint>() << tp; } @@ -11345,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)); @@ -11399,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(); @@ -11435,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 @@ -11452,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)); @@ -11593,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 @@ -11627,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); } @@ -11658,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); } @@ -11708,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 46e834afdb..9cf74c23fe 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsitemanimation/tst_qgraphicsitemanimation.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsitemanimation/tst_qgraphicsitemanimation.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// 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 167f418c3d..268195d7d3 100644 --- a/tests/auto/widgets/graphicsview/qgraphicslayout/tst_qgraphicslayout.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicslayout/tst_qgraphicslayout.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> @@ -695,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); @@ -850,7 +825,7 @@ CustomLayout(QGraphicsLayoutItem *parent) int count() const override { - return items.count(); + return items.size(); } QGraphicsLayoutItem* itemAt(int index) const override @@ -866,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); @@ -879,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); @@ -947,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 7e0a8b6033..87b703a286 100644 --- a/tests/auto/widgets/graphicsview/qgraphicslayoutitem/tst_qgraphicslayoutitem.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicslayoutitem/tst_qgraphicslayoutitem.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// 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 eef554ad87..65212e94cc 100644 --- a/tests/auto/widgets/graphicsview/qgraphicslinearlayout/tst_qgraphicslinearlayout.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicslinearlayout/tst_qgraphicslinearlayout.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> @@ -748,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)); @@ -1146,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); @@ -1164,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); @@ -1322,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 58c965a7d0..674a7f73d5 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsobject/tst_qgraphicsobject.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsobject/tst_qgraphicsobject.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> @@ -66,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)); } @@ -98,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)); } @@ -121,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)); } @@ -143,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)); } @@ -161,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); } @@ -179,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()); } @@ -197,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 22b81773b9..fd8f8bd37d 100644 --- a/tests/auto/widgets/graphicsview/qgraphicspixmapitem/tst_qgraphicspixmapitem.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicspixmapitem/tst_qgraphicspixmapitem.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// 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 90d69ca853..9412fab0ee 100644 --- a/tests/auto/widgets/graphicsview/qgraphicspolygonitem/tst_qgraphicspolygonitem.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicspolygonitem/tst_qgraphicspolygonitem.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// 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 new file mode 100644 index 0000000000..731b3ae253 --- /dev/null +++ b/tests/auto/widgets/graphicsview/qgraphicsproxywidget/BLACKLIST @@ -0,0 +1,11 @@ +[scrollUpdate] +android +b2qt +[windowOpacity] +macos ci +[wheelEventPropagation] +android +[forwardTouchEvent] +android +[touchEventPropagation] +android 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 e9ba24f4fc..ee1a8c530a 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp @@ -1,38 +1,18 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> #include <QtGui> #include <QtWidgets> +#include <QSignalSpy> #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") + /* Notes: @@ -60,7 +40,7 @@ public: QMap<QEvent::Type, int> counts; protected: - bool eventFilter(QObject *, QEvent *event) + bool eventFilter(QObject *, QEvent *event) override { ++counts[event->type()]; return false; @@ -74,7 +54,6 @@ class tst_QGraphicsProxyWidget : public QObject private slots: void initTestCase(); void cleanup(); - void qgraphicsproxywidget_data(); void qgraphicsproxywidget(); void paint(); void paint_2(); @@ -92,13 +71,10 @@ private slots: void focusProxy_QTBUG_51856(); void hoverEnterLeaveEvent_data(); void hoverEnterLeaveEvent(); - void hoverMoveEvent_data(); - void hoverMoveEvent(); void keyPressEvent_data(); void keyPressEvent(); void keyReleaseEvent_data(); void keyReleaseEvent(); - void mouseDoubleClickEvent_data(); void mouseDoubleClickEvent(); void mousePressReleaseEvent_data(); void mousePressReleaseEvent(); @@ -108,8 +84,6 @@ private slots: #if QT_CONFIG(wheelevent) void wheelEvent(); #endif - void sizeHint_data(); - void sizeHint(); void sizePolicy(); void minimumSize(); void maximumSize(); @@ -162,88 +136,39 @@ private slots: void mapToGlobal(); void mapToGlobalWithoutScene(); void QTBUG_43780_visibility(); +#if QT_CONFIG(wheelevent) + void wheelEventPropagation(); +#endif void forwardTouchEvent(); + void touchEventPropagation(); }; // Subclass that exposes the protected functions. class SubQGraphicsProxyWidget : public QGraphicsProxyWidget { - + friend tst_QGraphicsProxyWidget; public: - SubQGraphicsProxyWidget(QGraphicsItem *parent = nullptr) : QGraphicsProxyWidget(parent), - paintCount(0), keyPress(0), focusOut(0) - {} - - bool call_eventFilter(QObject* object, QEvent* event) - { return SubQGraphicsProxyWidget::eventFilter(object, event); } - - void call_focusInEvent(QFocusEvent* event) - { return SubQGraphicsProxyWidget::focusInEvent(event); } - - bool call_focusNextPrevChild(bool next) - { return SubQGraphicsProxyWidget::focusNextPrevChild(next); } - - void call_focusOutEvent(QFocusEvent* event) - { return SubQGraphicsProxyWidget::focusOutEvent(event); } - - void call_hideEvent(QHideEvent* event) - { return SubQGraphicsProxyWidget::hideEvent(event); } - - void call_hoverEnterEvent(QGraphicsSceneHoverEvent* event) - { return SubQGraphicsProxyWidget::hoverEnterEvent(event); } - - void call_hoverLeaveEvent(QGraphicsSceneHoverEvent* event) - { return SubQGraphicsProxyWidget::hoverLeaveEvent(event); } - - void call_hoverMoveEvent(QGraphicsSceneHoverEvent* event) - { return SubQGraphicsProxyWidget::hoverMoveEvent(event); } - - void call_keyPressEvent(QKeyEvent* event) - { return SubQGraphicsProxyWidget::keyPressEvent(event); } - - void call_keyReleaseEvent(QKeyEvent* event) - { return SubQGraphicsProxyWidget::keyReleaseEvent(event); } - - void call_mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event) - { return SubQGraphicsProxyWidget::mouseDoubleClickEvent(event); } - - void call_mouseMoveEvent(QGraphicsSceneMouseEvent* event) - { return SubQGraphicsProxyWidget::mouseMoveEvent(event); } + using QGraphicsProxyWidget::QGraphicsProxyWidget; - void call_mousePressEvent(QGraphicsSceneMouseEvent* event) - { return SubQGraphicsProxyWidget::mousePressEvent(event); } - - void call_mouseReleaseEvent(QGraphicsSceneMouseEvent* event) - { return SubQGraphicsProxyWidget::mouseReleaseEvent(event); } - - void call_resizeEvent(QGraphicsSceneResizeEvent* event) - { return SubQGraphicsProxyWidget::resizeEvent(event); } - - QSizeF call_sizeHint(Qt::SizeHint which, QSizeF const& constraint = QSizeF()) const - { return SubQGraphicsProxyWidget::sizeHint(which, constraint); } - - void call_showEvent(QShowEvent* event) - { return SubQGraphicsProxyWidget::showEvent(event); } - - void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) { + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override { paintCount++; QGraphicsProxyWidget::paint(painter, option, widget); } - void focusOutEvent(QFocusEvent *event) + void focusOutEvent(QFocusEvent *event) override { focusOut++; QGraphicsProxyWidget::focusOutEvent(event); } - bool eventFilter(QObject *object, QEvent *event) { + bool eventFilter(QObject *object, QEvent *event) override { if (event->type() == QEvent::KeyPress && object == widget()) keyPress++; return QGraphicsProxyWidget::eventFilter(object, event); } - int paintCount; - int keyPress; - int focusOut; + int paintCount = 0; + int keyPress = 0; + int focusOut = 0; }; #if QT_CONFIG(wheelevent) @@ -252,7 +177,7 @@ class WheelWidget : public QWidget public: WheelWidget() : wheelEventCalled(false) { setFocusPolicy(Qt::WheelFocus); } - virtual void wheelEvent(QWheelEvent *event) { event->accept(); wheelEventCalled = true; } + virtual void wheelEvent(QWheelEvent *event) override { event->accept(); wheelEventCalled = true; } bool wheelEventCalled; }; @@ -276,10 +201,6 @@ void tst_QGraphicsProxyWidget::cleanup() QTRY_VERIFY(QApplication::topLevelWidgets().isEmpty()); } -void tst_QGraphicsProxyWidget::qgraphicsproxywidget_data() -{ -} - void tst_QGraphicsProxyWidget::qgraphicsproxywidget() { SubQGraphicsProxyWidget proxy; @@ -288,46 +209,47 @@ void tst_QGraphicsProxyWidget::qgraphicsproxywidget() QCOMPARE(proxy.type(), int(QGraphicsProxyWidget::Type)); QVERIFY(!proxy.widget()); QEvent event(QEvent::None); - proxy.call_eventFilter(0, &event); + proxy.eventFilter(0, &event); QFocusEvent focusEvent(QEvent::FocusIn); focusEvent.ignore(); - proxy.call_focusInEvent(&focusEvent); + proxy.focusInEvent(&focusEvent); QCOMPARE(focusEvent.isAccepted(), false); - QCOMPARE(proxy.call_focusNextPrevChild(false), false); - QCOMPARE(proxy.call_focusNextPrevChild(true), false); - proxy.call_focusOutEvent(&focusEvent); + QCOMPARE(proxy.focusNextPrevChild(false), false); + QCOMPARE(proxy.focusNextPrevChild(true), false); + proxy.focusOutEvent(&focusEvent); QHideEvent hideEvent; - proxy.call_hideEvent(&hideEvent); + proxy.hideEvent(&hideEvent); QGraphicsSceneHoverEvent hoverEvent; - proxy.call_hoverEnterEvent(&hoverEvent); - proxy.call_hoverLeaveEvent(&hoverEvent); - proxy.call_hoverMoveEvent(&hoverEvent); + proxy.hoverEnterEvent(&hoverEvent); + proxy.hoverLeaveEvent(&hoverEvent); + proxy.hoverMoveEvent(&hoverEvent); QKeyEvent keyEvent(QEvent::KeyPress, 0, Qt::NoModifier); - proxy.call_keyPressEvent(&keyEvent); - proxy.call_keyReleaseEvent(&keyEvent); + proxy.keyPressEvent(&keyEvent); + proxy.keyReleaseEvent(&keyEvent); QGraphicsSceneMouseEvent mouseEvent; - proxy.call_mouseDoubleClickEvent(&mouseEvent); - proxy.call_mouseMoveEvent(&mouseEvent); - proxy.call_mousePressEvent(&mouseEvent); - proxy.call_mouseReleaseEvent(&mouseEvent); + proxy.mouseDoubleClickEvent(&mouseEvent); + proxy.mouseMoveEvent(&mouseEvent); + proxy.mousePressEvent(&mouseEvent); + proxy.mouseReleaseEvent(&mouseEvent); QGraphicsSceneResizeEvent resizeEvent; - proxy.call_resizeEvent(&resizeEvent); + proxy.resizeEvent(&resizeEvent); QShowEvent showEvent; - proxy.call_showEvent(&showEvent); - proxy.call_sizeHint(Qt::PreferredSize, QSizeF()); + proxy.showEvent(&showEvent); + proxy.sizeHint(Qt::PreferredSize, QSizeF()); } // public void paint(QPainter* painter, QStyleOptionGraphicsItem const* option, QWidget* widget) void tst_QGraphicsProxyWidget::paint() { SubQGraphicsProxyWidget proxy; + proxy.paint(0, 0, 0); } class MyProxyWidget : public QGraphicsProxyWidget { public: - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override { // Make sure QGraphicsProxyWidget::paint does not modify the render hints set on the painter. painter->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform @@ -386,6 +308,8 @@ void tst_QGraphicsProxyWidget::setWidget() QGraphicsView view(&scene); view.show(); QScopedPointer<QStyle> style(QStyleFactory::create(QLatin1String("Fusion"))); + if (style.isNull()) + QSKIP("This test requires the Fusion style"); QVERIFY(QTest::qWaitForWindowExposed(&view)); QPointer<SubQGraphicsProxyWidget> proxy = new SubQGraphicsProxyWidget; SubQGraphicsProxyWidget parentProxy; @@ -411,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); @@ -433,6 +357,10 @@ void tst_QGraphicsProxyWidget::setWidget() if (shouldBeInsertable) subWidget->setAttribute(Qt::WA_QuitOnClose, true); + if (hasParent) { + QTest::ignoreMessage(QtWarningMsg, QRegularExpression( + "QGraphicsProxyWidget::setWidget: cannot embed widget .* which is not a toplevel widget, and is not a child of an embedded widget")); + } proxy->setWidget(subWidget); if (shouldBeInsertable) { @@ -548,7 +476,7 @@ void tst_QGraphicsProxyWidget::testEventFilter() switch (eventType) { case QEvent::None: { QEvent event(QEvent::None); - proxy->call_eventFilter(widget, &event); + proxy->eventFilter(widget, &event); break; } case QEvent::Resize: { @@ -580,7 +508,7 @@ void tst_QGraphicsProxyWidget::testEventFilter() widget->hide(); } else { QHideEvent event; - proxy->call_eventFilter(widget, &event); + proxy->eventFilter(widget, &event); } QCOMPARE(proxy->isVisible(), false); break; @@ -592,7 +520,7 @@ void tst_QGraphicsProxyWidget::testEventFilter() widget->show(); } else { QShowEvent event; - proxy->call_eventFilter(widget, &event); + proxy->eventFilter(widget, &event); } QCOMPARE(proxy->isVisible(), true); break; @@ -607,7 +535,7 @@ void tst_QGraphicsProxyWidget::testEventFilter() QCOMPARE(proxy->isEnabled(), false); } else { QEvent event(QEvent::EnabledChange); - proxy->call_eventFilter(widget, &event); + proxy->eventFilter(widget, &event); // match the widget not the event QCOMPARE(proxy->isEnabled(), false); } @@ -635,7 +563,7 @@ void tst_QGraphicsProxyWidget::testEventFilter() QTest::keyPress(widget, Qt::Key_A, Qt::NoModifier); } else { QKeyEvent event(QEvent::KeyPress, Qt::Key_A, Qt::NoModifier); - proxy->call_eventFilter(widget, &event); + proxy->eventFilter(widget, &event); } QCOMPARE(proxy->keyPress, 1); break; @@ -695,7 +623,7 @@ void tst_QGraphicsProxyWidget::focusInEvent() QFocusEvent event(QEvent::FocusIn, Qt::TabFocusReason); event.ignore(); - proxy->call_focusInEvent(&event); + proxy->focusInEvent(&event); QTRY_COMPARE(widget->hasFocus(), widgetCanHaveFocus); } @@ -712,7 +640,7 @@ void tst_QGraphicsProxyWidget::focusInEventNoWidget() QFocusEvent event(QEvent::FocusIn, Qt::TabFocusReason); event.ignore(); //should not crash - proxy->call_focusInEvent(&event); + proxy->focusInEvent(&event); } void tst_QGraphicsProxyWidget::focusNextPrevChild_data() @@ -750,23 +678,40 @@ void tst_QGraphicsProxyWidget::focusNextPrevChild() // otherwise respect the scene // Respect the widget over the scene! - SubQGraphicsProxyWidget *proxy = new SubQGraphicsProxyWidget; - - QLabel *widget = new QLabel; - // I can't believe designer adds this much junk! - widget->setText("<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\"> p, li { white-space: pre-wrap; } </style></head><body style=\" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;\"> <p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><a href=\"http://www.slashdot.org\"><span style=\" text-decoration: underline; color:#0000ff;\">old</span></a> foo <a href=\"http://www.reddit.org\"><span style=\" text-decoration: underline; color:#0000ff;\">new</span></a></p></body></html>"); - widget->setTextInteractionFlags(Qt::TextBrowserInteraction); + std::unique_ptr<SubQGraphicsProxyWidget> proxyGuard(new SubQGraphicsProxyWidget); + auto *proxy = proxyGuard.get(); - if (hasWidget) + if (hasWidget) { + QLabel *widget = new QLabel; + widget->setText(R"( + <html> + <head> + <meta name=\"qrichtext\" content=\"1\" /> + <style type=\"text/css\"> + p, li { white-space: pre-wrap; } + </style> + </head> + <body> + <p> + <a href=\"http://www.slashdot.org\"> + <span style=\" text-decoration: underline; color:#0000ff;\">old</span> + </a> foo + <a href=\"http://www.reddit.org\"> + <span style=\" text-decoration: underline; color:#0000ff;\">new</span> + </a> + </p> + </body> + </html>)"); + widget->setTextInteractionFlags(Qt::TextBrowserInteraction); proxy->setWidget(widget); + } QGraphicsScene scene; QGraphicsView view(&scene); view.show(); - QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowActive(&view)); if (hasScene) { - scene.addItem(proxy); + scene.addItem(proxyGuard.release()); proxy->show(); // widget should take precedence over scene so make scene.focusNextPrevChild return false @@ -781,12 +726,7 @@ void tst_QGraphicsProxyWidget::focusNextPrevChild() QVERIFY(proxy->hasFocus()); } - QCOMPARE(proxy->call_focusNextPrevChild(next), focusNextPrevChild); - - if (!hasScene) - delete proxy; - if (!hasWidget) - delete widget; + QCOMPARE(proxy->focusNextPrevChild(next), focusNextPrevChild); } void tst_QGraphicsProxyWidget::focusOutEvent_data() @@ -810,18 +750,17 @@ void tst_QGraphicsProxyWidget::focusOutEvent() SubQGraphicsProxyWidget *proxy = new SubQGraphicsProxyWidget; scene.addItem(proxy); view.show(); - QApplication::setActiveWindow(&view); view.activateWindow(); view.setFocus(); QVERIFY(QTest::qWaitForWindowActive(&view)); QTRY_VERIFY(view.isVisible()); QTRY_COMPARE(QApplication::activeWindow(), (QWidget*)&view); - QScopedPointer<QWidget> widgetGuard(new QWidget); - QWidget *widget = widgetGuard.data(); - widget->setFocusPolicy(Qt::WheelFocus); + std::unique_ptr<QWidget> widgetGuard(new QWidget); + QWidget *widget = widgetGuard.get(); + widgetGuard->setFocusPolicy(Qt::WheelFocus); if (hasWidget) - proxy->setWidget(widgetGuard.take()); + proxy->setWidget(widgetGuard.release()); proxy->show(); proxy->setFocus(); QVERIFY(proxy->hasFocus()); @@ -832,41 +771,20 @@ void tst_QGraphicsProxyWidget::focusOutEvent() if (!call) { QWidget *other = new QLineEdit(&view); other->show(); - QApplication::processEvents(); QTRY_VERIFY(other->isVisible()); other->setFocus(); QTRY_VERIFY(other->hasFocus()); - qApp->processEvents(); QTRY_COMPARE(proxy->hasFocus(), false); QVERIFY(proxy->focusOut); QCOMPARE(widget->hasFocus(), false); - } else { - { - /* - ### Test doesn't make sense - QFocusEvent focusEvent(QEvent::FocusOut); - proxy->call_focusOutEvent(&focusEvent); - QCOMPARE(focusEvent.isAccepted(), hasWidget); - qApp->processEvents(); - QCOMPARE(proxy->paintCount, hasWidget ? 1 : 0); - */ - } - { - /* - ### Test doesn't make sense - proxy->setFlag(QGraphicsItem::ItemIsFocusable, false); - QFocusEvent focusEvent(QEvent::FocusOut); - proxy->call_focusOutEvent(&focusEvent); - QCOMPARE(focusEvent.isAccepted(), hasWidget); - qApp->processEvents(); - QCOMPARE(proxy->paintCount, 0); - */ - } } } 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 @@ -889,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; @@ -943,19 +864,19 @@ public: installEventFilter(this); } - void enterEvent(QEnterEvent *event) + void enterEvent(QEnterEvent *event) override { enterCount++; QWidget::enterEvent(event); } - void leaveEvent(QEvent *event ) + void leaveEvent(QEvent *event ) override { leaveCount++; QWidget::leaveEvent(event); } - void mouseMoveEvent(QMouseEvent *event) + void mouseMoveEvent(QMouseEvent *event) override { event->setAccepted(true); moveCount++; @@ -970,7 +891,7 @@ public: int hoverLeave; int hoverMove; protected: - bool eventFilter(QObject *object, QEvent *event) + bool eventFilter(QObject *object, QEvent *event) override { switch (event->type()) { case QEvent::HoverEnter: @@ -1010,22 +931,21 @@ void tst_QGraphicsProxyWidget::hoverEnterLeaveEvent() QGraphicsScene scene; QGraphicsView view(&scene); view.show(); - QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowActive(&view)); SubQGraphicsProxyWidget *proxy = new SubQGraphicsProxyWidget; - QScopedPointer<EventLogger> widgetGuard(new EventLogger); - EventLogger *widget = widgetGuard.data(); + std::unique_ptr<EventLogger> widgetGuard(new EventLogger); + EventLogger *widget = widgetGuard.get(); widget->resize(50, 50); widget->setAttribute(Qt::WA_Hover, hoverEnabled); widget->setMouseTracking(true); view.resize(100, 100); if (hasWidget) - proxy->setWidget(widgetGuard.take()); + proxy->setWidget(widgetGuard.release()); 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)); @@ -1048,75 +968,6 @@ void tst_QGraphicsProxyWidget::hoverEnterLeaveEvent() QTRY_COMPARE(widget->hoverLeave, (hasWidget && hoverEnabled) ? 1 : 0); } -void tst_QGraphicsProxyWidget::hoverMoveEvent_data() -{ - QTest::addColumn<bool>("hasWidget"); - QTest::addColumn<bool>("hoverEnabled"); - QTest::addColumn<bool>("mouseTracking"); - QTest::addColumn<bool>("mouseDown"); - for (int i = 0; i < 2; ++i) { - for (int j = 0; j < 2; ++j) { - for (int k = 0; k < 2; ++k) { - for (int l = 0; l < 2; ++l) { - bool hasWidget = (i == 0); - bool hoverEnabled = (j == 0); - bool mouseTracking = (k == 0); - bool mouseDown = (l == 0); - QByteArray name = QByteArrayLiteral("hasWidget:") + (hasWidget ? '1' : '0') + ", hover:" - + (hoverEnabled ? '1' : '0') + ", mouseTracking:" - + (mouseTracking ? '1' : '0') + ", mouseDown: " + (mouseDown ? '1' : '0'); - QTest::newRow(name.constData()) << hasWidget << hoverEnabled << mouseTracking << mouseDown; - } - } - } - } -} - -// protected void hoverMoveEvent(QGraphicsSceneHoverEvent* event) -void tst_QGraphicsProxyWidget::hoverMoveEvent() -{ - QFETCH(bool, hasWidget); - QFETCH(bool, hoverEnabled); - QFETCH(bool, mouseTracking); - QFETCH(bool, mouseDown); - - QSKIP("Ambiguous test..."); - - // proxy should translate the move events to what the widget would expect - - QGraphicsScene scene; - QGraphicsView view(&scene); - view.show(); - - SubQGraphicsProxyWidget *proxy = new SubQGraphicsProxyWidget; - proxy->setFlag(QGraphicsItem::ItemIsFocusable, true); // ### remove me!!! - EventLogger *widget = new EventLogger; - widget->resize(50, 50); - widget->setAttribute(Qt::WA_Hover, hoverEnabled); - if (mouseTracking) - widget->setMouseTracking(true); - view.resize(100, 100); - if (hasWidget) - proxy->setWidget(widget); - proxy->setPos(50, 0); - scene.addItem(proxy); - - // in - QTest::mouseMove(&view, QPoint(50, 50)); - QTest::qWait(12); - - if (mouseDown) - QTest::mousePress(view.viewport(), Qt::LeftButton); - - // move a little bit - QTest::mouseMove(&view, QPoint(60, 60)); - QTRY_COMPARE(widget->hoverEnter, (hasWidget && hoverEnabled) ? 1 : 0); - QCOMPARE(widget->moveCount, (hasWidget && mouseTracking) || (hasWidget && mouseDown) ? 1 : 0); - - if (!hasWidget) - delete widget; -} - void tst_QGraphicsProxyWidget::keyPressEvent_data() { QTest::addColumn<bool>("hasWidget"); @@ -1133,30 +984,27 @@ void tst_QGraphicsProxyWidget::keyPressEvent() QGraphicsView view(&scene); view.show(); view.viewport()->setFocus(); - QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowActive(&view)); QCOMPARE(QApplication::activeWindow(), (QWidget*)&view); SubQGraphicsProxyWidget *proxy = new SubQGraphicsProxyWidget; proxy->setFlag(QGraphicsItem::ItemIsFocusable, true); // ### remove me!!! - QLineEdit *widget = new QLineEdit; + std::unique_ptr<QLineEdit> widgetGuard(new QLineEdit); + QLineEdit *widget = widgetGuard.get(); widget->resize(50, 50); view.resize(100, 100); - if (hasWidget) { - proxy->setWidget(widget); - proxy->show(); - } - proxy->setPos(50, 0); + if (hasWidget) + proxy->setWidget(widgetGuard.release()); + scene.addItem(proxy); + proxy->show(); + proxy->setPos(50, 0); proxy->setFocus(); QTest::keyPress(view.viewport(), 'x'); QTRY_COMPARE(widget->text(), hasWidget ? QString("x") : QString()); - - if (!hasWidget) - delete widget; } void tst_QGraphicsProxyWidget::keyReleaseEvent_data() @@ -1174,19 +1022,18 @@ void tst_QGraphicsProxyWidget::keyReleaseEvent() QGraphicsScene scene; QGraphicsView view(&scene); view.show(); - QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowActive(&view)); QCOMPARE(QApplication::activeWindow(), (QWidget*)&view); SubQGraphicsProxyWidget *proxy = new SubQGraphicsProxyWidget; proxy->setFlag(QGraphicsItem::ItemIsFocusable, true); // ### remove me!!! - QPushButton *widget = new QPushButton; - QSignalSpy spy(widget, SIGNAL(clicked())); - widget->resize(50, 50); + std::unique_ptr<QPushButton> widgetGuard(new QPushButton); + QSignalSpy spy(widgetGuard.get(), SIGNAL(clicked())); + widgetGuard->resize(50, 50); view.resize(100, 100); if (hasWidget) { - proxy->setWidget(widget); + proxy->setWidget(widgetGuard.release()); proxy->show(); } proxy->setPos(50, 0); @@ -1194,59 +1041,43 @@ 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); - - if (!hasWidget) - delete widget; -} - -void tst_QGraphicsProxyWidget::mouseDoubleClickEvent_data() -{ - QTest::addColumn<bool>("hasWidget"); - QTest::newRow("widget") << true; - QTest::newRow("no widget") << false; + QTRY_COMPARE(spy.size(), hasWidget ? 1 : 0); } // protected void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event) void tst_QGraphicsProxyWidget::mouseDoubleClickEvent() { - QFETCH(bool, hasWidget); - QGraphicsScene scene; QGraphicsView view(&scene); - view.show(); - - QApplication::setActiveWindow(&view); - QVERIFY(QTest::qWaitForWindowActive(&view)); - QCOMPARE(QApplication::activeWindow(), (QWidget*)&view); SubQGraphicsProxyWidget *proxy = new SubQGraphicsProxyWidget; proxy->setFlag(QGraphicsItem::ItemIsFocusable, true); // ### remove me!!! QLineEdit *widget = new QLineEdit; widget->setText("foo"); widget->resize(50, 50); - view.resize(100, 100); - if (hasWidget) - proxy->setWidget(widget); + proxy->setWidget(widget); + proxy->setPos(50, 0); QSignalSpy sceneChangedSpy(&scene, &QGraphicsScene::changed); scene.addItem(proxy); proxy->setFocus(); + view.resize(100, 100); + view.show(); + + 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, 0, pointInLineEdit); - QTest::mouseRelease(view.viewport(), Qt::LeftButton, 0, pointInLineEdit); - QTest::mouseDClick(view.viewport(), Qt::LeftButton, 0, pointInLineEdit); + QTest::mousePress(view.viewport(), Qt::LeftButton, {}, pointInLineEdit); + QTest::mouseRelease(view.viewport(), Qt::LeftButton, {}, pointInLineEdit); + QTest::mouseDClick(view.viewport(), Qt::LeftButton, {}, pointInLineEdit); - QTRY_COMPARE(widget->selectedText(), hasWidget ? QString("foo") : QString()); - - if (!hasWidget) - delete widget; + QTRY_COMPARE(widget->selectedText(), QString("foo")); } void tst_QGraphicsProxyWidget::mousePressReleaseEvent_data() @@ -1269,27 +1100,24 @@ void tst_QGraphicsProxyWidget::mousePressReleaseEvent() SubQGraphicsProxyWidget *proxy = new SubQGraphicsProxyWidget; proxy->setFlag(QGraphicsItem::ItemIsFocusable, true); // ### remove me!!! - QPushButton *widget = new QPushButton; - QSignalSpy spy(widget, SIGNAL(clicked())); - widget->resize(50, 50); + std::unique_ptr<QPushButton> widgetGuard(new QPushButton); + QSignalSpy spy(widgetGuard.get(), SIGNAL(clicked())); + widgetGuard->resize(50, 50); if (hasWidget) - proxy->setWidget(widget); + proxy->setWidget(widgetGuard.release()); proxy->setPos(50, 0); QSignalSpy sceneChangedSpy(&scene, &QGraphicsScene::changed); scene.addItem(proxy); 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, 0, buttonCenter); - QTRY_COMPARE(spy.count(), 0); - QTest::mouseRelease(view.viewport(), Qt::LeftButton, 0, buttonCenter); - QTRY_COMPARE(spy.count(), (hasWidget) ? 1 : 0); - - if (!hasWidget) - delete widget; + QTest::mousePress(view.viewport(), Qt::LeftButton, {}, buttonCenter); + QTRY_COMPARE(spy.size(), 0); + QTest::mouseRelease(view.viewport(), Qt::LeftButton, {}, buttonCenter); + QTRY_COMPARE(spy.size(), hasWidget ? 1 : 0); } void tst_QGraphicsProxyWidget::resizeEvent_data() @@ -1305,19 +1133,17 @@ void tst_QGraphicsProxyWidget::resizeEvent() QFETCH(bool, hasWidget); SubQGraphicsProxyWidget proxy; - QWidget *widget = new QWidget; + if (hasWidget) - proxy.setWidget(widget); + proxy.setWidget(new QWidget); QSize newSize(100, 100); QGraphicsSceneResizeEvent event; event.setOldSize(QSize(10, 10)); event.setNewSize(newSize); - proxy.call_resizeEvent(&event); + proxy.resizeEvent(&event); if (hasWidget) - QCOMPARE(widget->size(), newSize); - if (!hasWidget) - delete widget; + QCOMPARE(proxy.widget()->size(), newSize); } void tst_QGraphicsProxyWidget::paintEvent() @@ -1326,7 +1152,6 @@ void tst_QGraphicsProxyWidget::paintEvent() QGraphicsScene scene; QGraphicsView view(&scene); view.show(); - QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowActive(&view)); QVERIFY(view.isActiveWindow()); @@ -1342,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(); @@ -1376,48 +1201,13 @@ void tst_QGraphicsProxyWidget::wheelEvent() } #endif // QT_CONFIG(wheelevent) -Q_DECLARE_METATYPE(Qt::SizeHint) -void tst_QGraphicsProxyWidget::sizeHint_data() -{ - QTest::addColumn<Qt::SizeHint>("which"); - QTest::addColumn<QSizeF>("constraint"); - QTest::addColumn<QSizeF>("sizeHint"); - QTest::addColumn<bool>("hasWidget"); - - for (int i = 0; i < 2; ++i) { - bool hasWidget = (i == 0); - // ### What should these do? - QTest::newRow("min") << Qt::MinimumSize << QSizeF() << QSizeF() << hasWidget; - QTest::newRow("pre") << Qt::PreferredSize << QSizeF() << QSizeF() << hasWidget; - QTest::newRow("max") << Qt::MaximumSize << QSizeF() << QSizeF() << hasWidget; - QTest::newRow("mindes") << Qt::MinimumDescent << QSizeF() << QSizeF() << hasWidget; - QTest::newRow("nsize") << Qt::NSizeHints << QSizeF() << QSizeF() << hasWidget; - } -} - -// protected QSizeF sizeHint(Qt::SizeHint which, QSizeF const& constraint = QSizeF()) const -void tst_QGraphicsProxyWidget::sizeHint() -{ - QFETCH(Qt::SizeHint, which); - QFETCH(QSizeF, constraint); - QFETCH(QSizeF, sizeHint); - QFETCH(bool, hasWidget); - QSKIP("Broken test"); - SubQGraphicsProxyWidget proxy; - QWidget *widget = new QWidget; - if (hasWidget) - proxy.setWidget(widget); - QCOMPARE(proxy.call_sizeHint(which, constraint), sizeHint); - if (!hasWidget) - delete widget; -} - void tst_QGraphicsProxyWidget::sizePolicy() { for (int p = 0; p < 2; ++p) { bool hasWidget = (p == 0); - SubQGraphicsProxyWidget proxy; - QWidget *widget = new QWidget; + QGraphicsProxyWidget proxy; + std::unique_ptr<QWidget> widgetGuard(new QWidget); + QWidget *widget = widgetGuard.get(); QSizePolicy proxyPol(QSizePolicy::Maximum, QSizePolicy::Expanding); proxy.setSizePolicy(proxyPol); QSizePolicy widgetPol(QSizePolicy::Fixed, QSizePolicy::Minimum); @@ -1426,7 +1216,7 @@ void tst_QGraphicsProxyWidget::sizePolicy() QCOMPARE(proxy.sizePolicy(), proxyPol); QCOMPARE(widget->sizePolicy(), widgetPol); if (hasWidget) { - proxy.setWidget(widget); + proxy.setWidget(widgetGuard.release()); QCOMPARE(proxy.sizePolicy(), widgetPol); } else { QCOMPARE(proxy.sizePolicy(), proxyPol); @@ -1439,42 +1229,39 @@ void tst_QGraphicsProxyWidget::sizePolicy() QCOMPARE(proxy.sizePolicy(), proxyPol); else QCOMPARE(proxy.sizePolicy(), widgetPol); - - if (!hasWidget) - delete widget; } } void tst_QGraphicsProxyWidget::minimumSize() { - SubQGraphicsProxyWidget proxy; - QWidget *widget = new QWidget; + QGraphicsProxyWidget proxy; + std::unique_ptr<QWidget> widgetGuard(new QWidget); QSize minSize(50, 50); - widget->setMinimumSize(minSize); + widgetGuard->setMinimumSize(minSize); proxy.resize(30, 30); - widget->resize(30,30); + widgetGuard->resize(30,30); QCOMPARE(proxy.size(), QSizeF(30, 30)); - proxy.setWidget(widget); + proxy.setWidget(widgetGuard.release()); QCOMPARE(proxy.size().toSize(), minSize); QCOMPARE(proxy.minimumSize().toSize(), minSize); - widget->setMinimumSize(70, 70); + proxy.widget()->setMinimumSize(70, 70); QCOMPARE(proxy.minimumSize(), QSizeF(70, 70)); QCOMPARE(proxy.size(), QSizeF(70, 70)); } void tst_QGraphicsProxyWidget::maximumSize() { - SubQGraphicsProxyWidget proxy; - QWidget *widget = new QWidget; + QGraphicsProxyWidget proxy; + std::unique_ptr<QWidget> widgetGuard(new QWidget); QSize maxSize(150, 150); - widget->setMaximumSize(maxSize); + widgetGuard->setMaximumSize(maxSize); proxy.resize(200, 200); - widget->resize(200,200); + widgetGuard->resize(200,200); QCOMPARE(proxy.size(), QSizeF(200, 200)); - proxy.setWidget(widget); + proxy.setWidget(widgetGuard.release()); QCOMPARE(proxy.size().toSize(), maxSize); QCOMPARE(proxy.maximumSize().toSize(), maxSize); - widget->setMaximumSize(70, 70); + proxy.widget()->setMaximumSize(70, 70); QCOMPARE(proxy.maximumSize(), QSizeF(70, 70)); QCOMPARE(proxy.size(), QSizeF(70, 70)); } @@ -1488,7 +1275,7 @@ public: QRegion paintEventRegion; int npaints; protected: - void paintEvent(QPaintEvent *event) + void paintEvent(QPaintEvent *event) override { ++npaints; paintEventRegion += event->region(); @@ -1515,7 +1302,7 @@ public slots: } protected: - void paintEvent(QPaintEvent *event) + void paintEvent(QPaintEvent *event) override { ++npaints; paintEventRegion += event->region(); @@ -1535,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; @@ -1544,7 +1334,7 @@ void tst_QGraphicsProxyWidget::scrollUpdate() view.show(); QVERIFY(QTest::qWaitForWindowActive(&view)); QTRY_VERIFY(view.npaints >= 1); - QTest::qWait(20); + QTest::qWait(150); widget->paintEventRegion = QRegion(); widget->npaints = 0; view.paintEventRegion = QRegion(); @@ -1748,7 +1538,6 @@ void tst_QGraphicsProxyWidget::tabFocus_simpleWidget() window.setLayout(layout); window.show(); - QApplication::setActiveWindow(&window); window.activateWindow(); QVERIFY(QTest::qWaitForWindowActive(&window)); @@ -1832,7 +1621,6 @@ void tst_QGraphicsProxyWidget::tabFocus_simpleTwoWidgets() window.setLayout(layout); window.show(); - QApplication::setActiveWindow(&window); window.activateWindow(); QVERIFY(QTest::qWaitForWindowActive(&window)); @@ -1965,7 +1753,6 @@ void tst_QGraphicsProxyWidget::tabFocus_complexWidget() window.setLayout(layout); window.show(); - QApplication::setActiveWindow(&window); window.activateWindow(); QVERIFY(QTest::qWaitForWindowActive(&window)); @@ -2102,7 +1889,6 @@ void tst_QGraphicsProxyWidget::tabFocus_complexTwoWidgets() window.setLayout(layout); window.show(); - QApplication::setActiveWindow(&window); window.activateWindow(); QVERIFY(QTest::qWaitForWindowActive(&window)); @@ -2276,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); @@ -2348,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); @@ -2427,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); @@ -2500,28 +2283,29 @@ void tst_QGraphicsProxyWidget::setFocus_complexTwoWidgets() void tst_QGraphicsProxyWidget::popup_basic() { - QScopedPointer<QComboBox> box(new QComboBox); + std::unique_ptr<QComboBox> boxGuard(new QComboBox); QStyleOptionComboBox opt; - opt.initFrom(box.data()); - opt.editable = box->isEditable(); - if (box->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt)) + opt.initFrom(boxGuard.get()); + opt.editable = boxGuard->isEditable(); + if (boxGuard->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt)) QSKIP("Does not work due to SH_Combobox_Popup"); // ProxyWidget should automatically create proxy's when the widget creates a child - QGraphicsScene *scene = new QGraphicsScene; - QGraphicsView view(scene); + QGraphicsScene scene; + QGraphicsView view(&scene); view.setAlignment(Qt::AlignLeft | Qt::AlignTop); view.setGeometry(0, 100, 480, 500); view.show(); - SubQGraphicsProxyWidget *proxy = new SubQGraphicsProxyWidget; + QComboBox *box = boxGuard.get(); + QGraphicsProxyWidget *proxy = new QGraphicsProxyWidget; box->setGeometry(0, 0, 320, 40); box->addItems(QStringList() << "monday" << "tuesday" << "wednesday" << "thursday" << "saturday" << "sunday"); - QCOMPARE(proxy->childItems().count(), 0); - proxy->setWidget(box.data()); + QCOMPARE(proxy->childItems().size(), 0); + proxy->setWidget(boxGuard.release()); proxy->show(); - scene->addItem(proxy); + scene.addItem(proxy); QCOMPARE(box->pos(), QPoint()); QCOMPARE(proxy->pos(), QPointF()); @@ -2530,16 +2314,16 @@ void tst_QGraphicsProxyWidget::popup_basic() QTest::qWait(125); QApplication::processEvents(); - QTest::mousePress(view.viewport(), Qt::LeftButton, 0, + QTest::mousePress(view.viewport(), Qt::LeftButton, {}, view.mapFromScene(proxy->mapToScene(proxy->boundingRect().center()))); 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()); - QCOMPARE(child->widget()->parent(), static_cast<QObject*>(box.data())); + QCOMPARE(child->widget()->parent(), box); QTRY_COMPARE(proxy->pos(), QPointF(box->pos())); QCOMPARE(child->x(), qreal(box->x())); @@ -2610,12 +2394,12 @@ void tst_QGraphicsProxyWidget::changingCursor_basic() view.show(); QVERIFY(QTest::qWaitForWindowActive(&view)); - SubQGraphicsProxyWidget *proxy = new SubQGraphicsProxyWidget; + QGraphicsProxyWidget *proxy = new QGraphicsProxyWidget; QLineEdit *widget = new QLineEdit; 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()))); @@ -2671,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(), @@ -2681,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")) @@ -2733,56 +2517,46 @@ void tst_QGraphicsProxyWidget::childPos() QGraphicsScene scene; - QComboBox *box = new QComboBox; - box->addItem("Item 1"); - box->addItem("Item 2"); - box->addItem("Item 3"); - box->addItem("Item 4"); + QComboBox box; + box.addItem("Item 1"); + box.addItem("Item 2"); + box.addItem("Item 3"); + box.addItem("Item 4"); if (moveCombo) - box->move(comboPos); + box.move(comboPos); - QGraphicsProxyWidget *proxy = scene.addWidget(box); + QGraphicsProxyWidget *proxy = scene.addWidget(&box); proxy->show(); QVERIFY(proxy->isVisible()); - QVERIFY(box->isVisible()); + QVERIFY(box.isVisible()); if (!moveCombo) proxy->setPos(proxyPos); QCOMPARE(proxy->pos(), proxyPos); - QCOMPARE(box->pos(), comboPos); + QCOMPARE(box.pos(), comboPos); for (int i = 0; i < 2; ++i) { - box->showPopup(); - QApplication::processEvents(); - QApplication::processEvents(); - - QWidget *menu = nullptr; - foreach (QObject *child, box->children()) { - if ((menu = qobject_cast<QWidget *>(child))) - break; - } + box.showPopup(); + QWidget *menu = box.findChild<QWidget *>(); QVERIFY(menu); - QVERIFY(menu->isVisible()); + QTRY_VERIFY(menu->isVisible()); QVERIFY(menu->testAttribute(Qt::WA_DontShowOnScreen)); QCOMPARE(proxy->childItems().size(), 1); - QGraphicsProxyWidget *proxyChild = 0; - foreach (QGraphicsItem *child, proxy->childItems()) { - if (child->isWidget() && (proxyChild = qobject_cast<QGraphicsProxyWidget *>(static_cast<QGraphicsWidget *>(child)))) - break; - } + QGraphicsProxyWidget *proxyChild = qobject_cast<QGraphicsProxyWidget *>( + static_cast<QGraphicsWidget *>(proxy->childItems().first())); QVERIFY(proxyChild); QVERIFY(proxyChild->isVisible()); qreal expectedXPosition = 0.0; -#if defined(Q_OS_MAC) && !defined(QT_NO_STYLE_MAC) + // The Mac style wants the popup to show up at QPoint(4 - 11, 1). // See QMacStyle::subControlRect SC_ComboBoxListBoxPopup. if (QApplication::style()->inherits("QMacStyle")) expectedXPosition = qreal(4 - 11); -#endif - QCOMPARE(proxyChild->pos().x(), expectedXPosition); + + QTRY_COMPARE(proxyChild->pos().x(), expectedXPosition); menu->hide(); } } @@ -2818,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()); @@ -2830,18 +2604,20 @@ void tst_QGraphicsProxyWidget::windowOpacity() QVERIFY(widget->isVisible()); widget->setWindowOpacity(0.5); - QApplication::processEvents(); // Make sure setWindowOpacity triggers an update on the scene, // and not on the widget or the proxy itself. The entire proxy needs an update // in case it has a window decoration. Update: QGraphicsItem::CacheMode is // disabled on platforms without alpha channel support in QPixmap (e.g., - // X11 without XRender). + // X11 without XRender). On macOS, we always get a paint event. int paints = 0; +#ifdef Q_OS_MACOS + paints = 1; +#endif QTRY_COMPARE(eventSpy.counts[QEvent::UpdateRequest], 0); QTRY_COMPARE(eventSpy.counts[QEvent::Paint], paints); - QCOMPARE(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); @@ -2922,6 +2698,8 @@ void tst_QGraphicsProxyWidget::palettePropagation() QCOMPARE(editSpy.counts[QEvent::PaletteChange], 3); QCOMPARE(proxySpy.counts[QEvent::PaletteChange], 1); QVERIFY(!edit->testAttribute(Qt::WA_SetPalette)); + if (edit->palette() != palette) + QEXPECT_FAIL("", "Test case fails unless run alone", Abort); QCOMPARE(edit->palette(), palette); QCOMPARE(edit->palette(), proxy.palette()); QCOMPARE(edit->palette().color(QPalette::Text), QColor(Qt::red)); @@ -3112,12 +2890,12 @@ void tst_QGraphicsProxyWidget::createProxyForChildWidget() QSignalSpy spy(checkbox, SIGNAL(clicked())); - QTest::mousePress(view.viewport(), Qt::LeftButton, 0, + QTest::mousePress(view.viewport(), Qt::LeftButton, {}, view.mapFromScene(checkboxProxy->mapToScene(QPointF(8,8)))); - QTRY_COMPARE(spy.count(), 0); - QTest::mouseRelease(view.viewport(), Qt::LeftButton, 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); @@ -3145,7 +2923,7 @@ public: bool embeddedPopup; bool gotContextMenuEvent; protected: - bool event(QEvent *event) + bool event(QEvent *event) override { if (event->type() == QEvent::ContextMenu) { if (!m_timer) { @@ -3157,7 +2935,7 @@ protected: } return QWidget::event(event); } - void contextMenuEvent(QContextMenuEvent *) + void contextMenuEvent(QContextMenuEvent *) override { gotContextMenuEvent = true; } @@ -3212,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()); @@ -3282,9 +3059,13 @@ void tst_QGraphicsProxyWidget::bypassGraphicsProxyWidget_data() void tst_QGraphicsProxyWidget::bypassGraphicsProxyWidget() { + if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + QSKIP("QWindow::requestActivate() is not supported."); + QFETCH(bool, bypass); - QWidget *widget = new QWidget; + std::unique_ptr<QWidget> widgetGuard(new QWidget); + QWidget *widget = widgetGuard.get(); widget->resize(100, 100); QGraphicsScene scene; @@ -3292,7 +3073,7 @@ void tst_QGraphicsProxyWidget::bypassGraphicsProxyWidget() view.show(); QVERIFY(QTest::qWaitForWindowActive(&view)); - QGraphicsProxyWidget *proxy = scene.addWidget(widget); + QGraphicsProxyWidget *proxy = scene.addWidget(widgetGuard.release()); QCOMPARE(proxy->widget(), widget); QVERIFY(proxy->childItems().isEmpty()); @@ -3312,8 +3093,6 @@ void tst_QGraphicsProxyWidget::bypassGraphicsProxyWidget() dialog->hide(); QApplication::processEvents(); - delete dialog; - delete widget; } static void makeDndEvent(QGraphicsSceneDragDropEvent *event, QGraphicsView *view, const QPointF &pos) @@ -3321,7 +3100,7 @@ static void makeDndEvent(QGraphicsSceneDragDropEvent *event, QGraphicsView *view event->setScenePos(pos); event->setScreenPos(view->mapToGlobal(view->mapFromScene(pos))); event->setButtons(Qt::LeftButton); - event->setModifiers(0); + event->setModifiers({}); event->setPossibleActions(Qt::CopyAction); event->setProposedAction(Qt::CopyAction); event->setDropAction(Qt::CopyAction); @@ -3483,7 +3262,7 @@ void tst_QGraphicsProxyWidget::updateAndDelete() class InputMethod_LineEdit : public QLineEdit { - bool event(QEvent *e) + bool event(QEvent *e) override { if (e->type() == QEvent::InputMethod) ++inputMethodEvents; @@ -3495,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 @@ -3554,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()); @@ -3568,7 +3349,7 @@ void tst_QGraphicsProxyWidget::clickFocus() QPointF lineEditCenter = proxy->mapToScene(proxy->boundingRect().center()); // Spontaneous mouse click sets focus on a clickable widget. for (int retry = 0; retry < 50 && !proxy->hasFocus(); retry++) - QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(lineEditCenter)); + QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, view.mapFromScene(lineEditCenter)); QVERIFY(proxy->hasFocus()); QVERIFY(proxy->widget()->hasFocus()); QCOMPARE(proxySpy.counts[QEvent::FocusIn], 1); @@ -3626,7 +3407,7 @@ void tst_QGraphicsProxyWidget::clickFocus() // Spontaneous click on non-clickable widget does not give focus. proxy->widget()->setFocusPolicy(Qt::NoFocus); - QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(lineEditCenter)); + QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, view.mapFromScene(lineEditCenter)); QVERIFY(!proxy->hasFocus()); QVERIFY(!proxy->widget()->hasFocus()); @@ -3635,8 +3416,8 @@ void tst_QGraphicsProxyWidget::clickFocus() scene.setFocusItem(0); QVERIFY(!proxy->hasFocus()); QVERIFY(!proxy->widget()->hasFocus()); - QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(lineEditCenter)); - QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(lineEditCenter)); + QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, view.mapFromScene(lineEditCenter)); + QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, view.mapFromScene(lineEditCenter)); QVERIFY(proxy->hasFocus()); QVERIFY(proxy->widget()->hasFocus()); QCOMPARE(widgetSpy.counts[QEvent::FocusIn], 1); @@ -3647,7 +3428,7 @@ void tst_QGraphicsProxyWidget::clickFocus() void tst_QGraphicsProxyWidget::windowFrameMargins() { // Make sure the top margin is non-zero when passing Qt::Window. - QGraphicsProxyWidget *proxy = new QGraphicsProxyWidget(0, Qt::Window); + QGraphicsProxyWidget *proxy = new QGraphicsProxyWidget(nullptr, Qt::Window); qreal left, top, right, bottom; proxy->getWindowFrameMargins(&left, &top, &right, &bottom); @@ -3667,67 +3448,50 @@ void tst_QGraphicsProxyWidget::windowFrameMargins() QVERIFY(top > 0); } -class HoverButton : public QPushButton +void tst_QGraphicsProxyWidget::QTBUG_6986_sendMouseEventToAlienWidget() { -public: - HoverButton(QWidget *parent = nullptr) : QPushButton(parent), hoverLeaveReceived(false) - {} - - bool hoverLeaveReceived; - - bool event(QEvent* e) + struct HoverButton : public QPushButton { - if(QEvent::HoverLeave == e->type()) - hoverLeaveReceived = true; - return QPushButton::event(e); - } -}; + using QPushButton::QPushButton; + bool hoverLeaveReceived = false; -class Scene : public QGraphicsScene -{ -Q_OBJECT -public: - Scene() { - QWidget *background = new QWidget; - background->setGeometry(0, 0, 500, 500); - hoverButton = new HoverButton; - hoverButton->setParent(background); - hoverButton->setText("Second button"); - hoverButton->setGeometry(10, 10, 200, 50); - addWidget(background); - - QPushButton *hideButton = new QPushButton("I'm a button with a very very long text"); - hideButton->setGeometry(10, 10, 400, 50); - topButton = addWidget(hideButton); - connect(hideButton, &QPushButton::clicked, this, [&]() { topButton->hide(); }); - topButton->setFocus(); - } - - QGraphicsProxyWidget *topButton; - HoverButton *hoverButton; -}; + bool event(QEvent* e) override + { + if (QEvent::HoverLeave == e->type()) + hoverLeaveReceived = true; + return QPushButton::event(e); + } + }; -void tst_QGraphicsProxyWidget::QTBUG_6986_sendMouseEventToAlienWidget() -{ - if (QGuiApplication::platformName() == QLatin1String("cocoa")) { - // The "Second button" does not receive QEvent::HoverLeave - QSKIP("This test fails only on Cocoa. Investigate why. See QTBUG-69219"); - } + QGraphicsScene scene; + QWidget *background = new QWidget; + background->setGeometry(0, 0, 500, 500); + HoverButton *hoverButton = new HoverButton(background); + hoverButton->setText("Second button"); + hoverButton->setGeometry(10, 10, 200, 50); + scene.addWidget(background); + + QPushButton *hideButton = new QPushButton("I'm a button with a very very long text"); + hideButton->setGeometry(10, 10, 400, 50); + QGraphicsProxyWidget *topButton = scene.addWidget(hideButton); + connect(hideButton, &QPushButton::clicked, &scene, [&]() { topButton->hide(); }); + topButton->setFocus(); - QGraphicsView view; - Scene scene; - view.setScene(&scene); + QGraphicsView view(&scene); view.resize(600, 600); - QApplication::setActiveWindow(&view); view.show(); QVERIFY(QTest::qWaitForWindowActive(&view)); - QPoint topButtonTopLeftCorner = view.mapFromScene(scene.topButton->scenePos()); - QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, topButtonTopLeftCorner); + QPoint topButtonTopLeftCorner = view.mapFromScene(topButton->scenePos()); + QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, topButtonTopLeftCorner); // move to the bottom right corner (buttons are placed in the top left corner) - QCOMPARE(scene.hoverButton->hoverLeaveReceived, false); + QCOMPARE(hoverButton->hoverLeaveReceived, false); QTest::mouseMove(view.viewport(), view.viewport()->rect().bottomRight()); - QTRY_COMPARE(scene.hoverButton->hoverLeaveReceived, true); + if (QGuiApplication::platformName() == QLatin1String("cocoa")) { + // The "Second button" does not receive QEvent::HoverLeave + QEXPECT_FAIL("", "This test fails only on Cocoa. Investigate why. See QTBUG-69219", Continue); + } + QTRY_COMPARE(hoverButton->hoverLeaveReceived, true); } static QByteArray msgPointMismatch(const QPoint &actual, const QPoint &expected) @@ -3758,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(); @@ -3766,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 @@ -3777,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()); } @@ -3832,7 +3596,7 @@ class TouchWidget : public QWidget public: TouchWidget(QWidget *parent = nullptr) : QWidget(parent) {} - bool event(QEvent *event) + bool event(QEvent *event) override { switch (event->type()) { case QEvent::TouchBegin: @@ -3840,7 +3604,6 @@ public: case QEvent::TouchEnd: event->accept(); return true; - break; default: break; } @@ -3849,48 +3612,416 @@ public: } }; +#if QT_CONFIG(wheelevent) +/*! + QGraphicsProxyWidget receives wheel events from QGraphicsScene, and then + generates a new event that is sent spontaneously in order to enable event + propagation. This requires extra handling of the wheel grabbing we do for + high-precision wheel event streams. + + Test that this doesn't trigger infinite recursion, while still resulting in + event propagation within the embedded widget hierarchy, and back to the + QGraphicsView if the event is not accepted. + + See tst_QApplication::wheelEventPropagation for a similar test. +*/ +void tst_QGraphicsProxyWidget::wheelEventPropagation() +{ + QGraphicsScene scene(0, 0, 600, 600); + + QWidget *label = new QLabel("Direct"); + label->setFixedSize(300, 30); + QGraphicsProxyWidget *labelProxy = scene.addWidget(label); + labelProxy->setPos(0, 50); + labelProxy->show(); + + class NestedWidget : public QWidget + { + public: + NestedWidget(const QString &text) + { + setObjectName("Nested Label"); + QLabel *nested = new QLabel(text); + QHBoxLayout *hbox = new QHBoxLayout; + hbox->addWidget(nested); + setLayout(hbox); + } + + int wheelEventCount = 0; + protected: + void wheelEvent(QWheelEvent *) override + { + ++wheelEventCount; + } + }; + NestedWidget *nestedWidget = new NestedWidget("Nested"); + nestedWidget->setFixedSize(300, 60); + QGraphicsProxyWidget *nestedProxy = scene.addWidget(nestedWidget); + nestedProxy->setPos(0, 120); + nestedProxy->show(); + + QGraphicsView view(&scene); + view.setFixedHeight(200); + view.show(); + + QVERIFY(QTest::qWaitForWindowActive(&view)); + QVERIFY(view.verticalScrollBar()->isVisible()); + + view.verticalScrollBar()->setValue(0); + QSignalSpy scrollSpy(view.verticalScrollBar(), &QScrollBar::valueChanged); + + const QPoint wheelPosition(50, 25); + auto wheelUp = [&view, wheelPosition](Qt::ScrollPhase phase) { + const QPoint global = view.mapToGlobal(wheelPosition); + const QPoint pixelDelta(0, -25); + const QPoint angleDelta(0, -120); + QWindowSystemInterface::handleWheelEvent(view.windowHandle(), wheelPosition, global, + pixelDelta, angleDelta, Qt::NoModifier, + phase); + QCoreApplication::processEvents(); + }; + + int scrollCount = 0; + // test non-kinetic events; they are not grabbed, and should scroll the view unless + // accepted by the embedded widget + QCOMPARE(view.itemAt(wheelPosition), nullptr); + wheelUp(Qt::NoScrollPhase); + 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.size(), ++scrollCount); + QCOMPARE(view.itemAt(wheelPosition), labelProxy); + wheelUp(Qt::NoScrollPhase); + QCOMPARE(scrollSpy.size(), ++scrollCount); + + // left the widget + QCOMPARE(view.itemAt(wheelPosition), nullptr); + wheelUp(Qt::NoScrollPhase); + 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.size(), scrollCount); + QCOMPARE(nestedWidget->wheelEventCount, 1); + + // reset, try with kinetic events + view.verticalScrollBar()->setValue(0); + ++scrollCount; + + // starting a scroll outside any widget and scrolling through the widgets should work, + // no matter if the widget accepts wheel events - the view has the grab + QCOMPARE(view.itemAt(wheelPosition), nullptr); + wheelUp(Qt::ScrollBegin); + QCOMPARE(scrollSpy.size(), ++scrollCount); + for (int i = 0; i < 5; ++i) { + wheelUp(Qt::ScrollUpdate); + QCOMPARE(scrollSpy.size(), ++scrollCount); + } + wheelUp(Qt::ScrollEnd); + QCOMPARE(scrollSpy.size(), ++scrollCount); + + // reset + view.verticalScrollBar()->setValue(0); + 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.size(); + + QCOMPARE(view.itemAt(wheelPosition), labelProxy); + wheelUp(Qt::ScrollBegin); + QCOMPARE(scrollSpy.size(), ++scrollCount); + for (int i = 0; i < 5; ++i) { + wheelUp(Qt::ScrollUpdate); + QCOMPARE(scrollSpy.size(), ++scrollCount); + } + wheelUp(Qt::ScrollEnd); + 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.size(); + + QCOMPARE(view.itemAt(wheelPosition), nestedProxy); + wheelUp(Qt::ScrollBegin); + QCOMPARE(scrollSpy.size(), scrollCount); +} +#endif // QT_CONFIG(wheelevent) + // QTBUG_45737 void tst_QGraphicsProxyWidget::forwardTouchEvent() { - QGraphicsScene *scene = new QGraphicsScene; + QGraphicsScene scene; TouchWidget *widget = new TouchWidget; - widget->setAttribute(Qt::WA_AcceptTouchEvents); - QGraphicsProxyWidget *proxy = new QGraphicsProxyWidget; - + QGraphicsProxyWidget *proxy = scene.addWidget(widget); proxy->setAcceptTouchEvents(true); - proxy->setWidget(widget); - - scene->addItem(proxy); - QGraphicsView *view = new QGraphicsView(scene); - - view->show(); + QGraphicsView view(&scene); + view.show(); + QVERIFY(QTest::qWaitForWindowActive(&view)); EventSpy eventSpy(widget); QPointingDevice *device = QTest::createTouchDevice(); + QVERIFY(device); QCOMPARE(eventSpy.counts[QEvent::TouchBegin], 0); QCOMPARE(eventSpy.counts[QEvent::TouchUpdate], 0); QCOMPARE(eventSpy.counts[QEvent::TouchEnd], 0); - QTest::touchEvent(view, device).press(0, QPoint(10, 10), view); - QTest::touchEvent(view, device).move(0, QPoint(15, 15), view); - QTest::touchEvent(view, device).move(0, QPoint(16, 16), view); - QTest::touchEvent(view, device).release(0, QPoint(15, 15), view); + QTest::touchEvent(&view, device).press(0, QPoint(10, 10), &view); + QTest::touchEvent(&view, device).move(0, QPoint(15, 15), &view); + QTest::touchEvent(&view, device).move(0, QPoint(16, 16), &view); + QTest::touchEvent(&view, device).release(0, QPoint(15, 15), &view); QApplication::processEvents(); QCOMPARE(eventSpy.counts[QEvent::TouchBegin], 1); QCOMPARE(eventSpy.counts[QEvent::TouchUpdate], 2); QCOMPARE(eventSpy.counts[QEvent::TouchEnd], 1); +} - delete view; - delete proxy; - delete scene; +void tst_QGraphicsProxyWidget::touchEventPropagation() +{ + QGraphicsScene scene(0, 0, 300, 200); + QWidget *simpleWidget = new QWidget; + simpleWidget->setObjectName("simpleWidget"); + simpleWidget->setAttribute(Qt::WA_AcceptTouchEvents, true); + QGraphicsProxyWidget *simpleProxy = scene.addWidget(simpleWidget); + simpleProxy->setAcceptTouchEvents(true); + simpleProxy->setGeometry(QRectF(0, 0, 30, 30)); + + QWidget *formWidget = new QWidget; + formWidget->setObjectName("formWidget"); + formWidget->setAttribute(Qt::WA_AcceptTouchEvents, true); + QPushButton *pushButton1 = new QPushButton("One"); + pushButton1->setObjectName("pushButton1"); + pushButton1->setAttribute(Qt::WA_AcceptTouchEvents, true); + QPushButton *pushButton2 = new QPushButton("Two"); + pushButton2->setObjectName("pushButton2"); + pushButton2->setAttribute(Qt::WA_AcceptTouchEvents, true); + TouchWidget *touchWidget1 = new TouchWidget; + touchWidget1->setObjectName("touchWidget1"); + touchWidget1->setAttribute(Qt::WA_AcceptTouchEvents, true); + touchWidget1->setFixedSize(pushButton1->sizeHint()); + TouchWidget *touchWidget2 = new TouchWidget; + touchWidget2->setObjectName("touchWidget2"); + touchWidget2->setAttribute(Qt::WA_AcceptTouchEvents, true); + touchWidget2->setFixedSize(pushButton2->sizeHint()); + QVBoxLayout *vbox = new QVBoxLayout; + vbox->addWidget(pushButton1); + vbox->addWidget(pushButton2); + vbox->addWidget(touchWidget1); + vbox->addWidget(touchWidget2); + formWidget->setLayout(vbox); + QGraphicsProxyWidget *formProxy = scene.addWidget(formWidget); + formProxy->setAcceptTouchEvents(true); + formProxy->setGeometry(QRectF(50, 50, 200, 160)); + + QGraphicsView view(&scene); + view.setFixedSize(scene.width(), scene.height()); + view.verticalScrollBar()->setValue(0); + view.horizontalScrollBar()->setValue(0); + view.viewport()->setObjectName("GraphicsView's Viewport"); + view.show(); + QVERIFY(QTest::qWaitForWindowExposed(&view)); + + class TouchEventSpy : public QObject + { + public: + using QObject::QObject; + + struct TouchRecord { + QObject *receiver; + QEvent::Type eventType; + QPointF position; + }; + QHash<int, QList<TouchRecord>> records; + QWidget *mousePressReceiver = nullptr; + + 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() + { + records.clear(); + mousePressReceiver = nullptr; + } + protected: + bool eventFilter(QObject *receiver, QEvent *event) override + { + switch (event->type()) { + case QEvent::TouchBegin: + case QEvent::TouchUpdate: + case QEvent::TouchCancel: + case QEvent::TouchEnd: { + QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event); + // instead of detaching each QEventPoint, just store the relative positions + for (const auto &touchPoint : touchEvent->points()) + records[touchPoint.id()] << TouchRecord{receiver, event->type(), touchPoint.position()}; + qCDebug(lcTests) << "Recording" << event << receiver; + break; + } + case QEvent::MouseButtonPress: + mousePressReceiver = qobject_cast<QWidget*>(receiver); + break; + default: + break; + } + return QObject::eventFilter(receiver, event); + } + } eventSpy; + qApp->installEventFilter(&eventSpy); + + auto touchDevice = QTest::createTouchDevice(); + const QPointF simpleCenter = simpleProxy->geometry().center(); + + // On systems without double conversion we might get different rounding behavior. + // One pixel off in any direction is acceptable for this test. + constexpr auto closeEnough = [](QPointF exp, QPointF act) -> bool { + const QRectF expArea(exp - QPointF(1., 1.), exp + QPointF(1., 1.)); + const bool contains = expArea.contains(act); + if (!contains) + qWarning() << act << "not in" << exp; + return contains; + }; + + // verify that the embedded widget gets the correctly translated event + QTest::touchEvent(&view, touchDevice).press(0, simpleCenter.toPoint()); + // window, viewport, scene, simpleProxy, simpleWidget + QCOMPARE(eventSpy.count(), 5); + QCOMPARE(eventSpy.at(0).receiver, view.windowHandle()); + QCOMPARE(eventSpy.at(1).receiver, view.viewport()); + QCOMPARE(eventSpy.at(2).receiver, &scene); + QCOMPARE(eventSpy.at(3).receiver, simpleProxy); + auto record = eventSpy.at(4); + QCOMPARE(record.receiver, simpleWidget); + QCOMPARE(record.eventType, QEvent::TouchBegin); + QVERIFY(closeEnough(record.position, simpleCenter)); + eventSpy.clear(); + + // verify that the layout of formWidget is how we expect it to be + QCOMPARE(formWidget->childAt(QPoint(5, 5)), nullptr); + const QPoint pb1Center = pushButton1->rect().center(); + QCOMPARE(formWidget->childAt(pushButton1->pos() + pb1Center), pushButton1); + const QPoint pb2Center = pushButton2->rect().center(); + QCOMPARE(formWidget->childAt(pushButton2->pos() + pb2Center), pushButton2); + const QPoint tw1Center = touchWidget1->rect().center(); + QCOMPARE(formWidget->childAt(touchWidget1->pos() + tw1Center), touchWidget1); + const QPoint tw2Center = touchWidget2->rect().center(); + QCOMPARE(formWidget->childAt(touchWidget2->pos() + tw2Center), touchWidget2); + + // touch events are sent to the view, in view coordinates + const QPoint formProxyPox = view.mapFromScene(formProxy->pos().toPoint()); + const QPoint pb1TouchPos = pushButton1->pos() + pb1Center + formProxyPox; + const QPoint pb2TouchPos = pushButton2->pos() + pb2Center + formProxyPox; + const QPoint tw1TouchPos = touchWidget1->pos() + tw1Center + formProxyPox; + const QPoint tw2TouchPos = touchWidget2->pos() + tw2Center + formProxyPox; + + QSignalSpy clickedSpy(pushButton1, &QPushButton::clicked); + // Single touch point to nested widget not accepting event. + // Event should bubble up and translate correctly, TouchUpdate and TouchEnd events + // stop at the window since nobody accepted the TouchBegin. A mouse event will be generated. + QTest::touchEvent(&view, touchDevice).press(0, pb1TouchPos); + QTest::touchEvent(&view, touchDevice).move(0, pb1TouchPos + QPoint(1, 1)); + QTest::touchEvent(&view, touchDevice).release(0, pb1TouchPos + QPoint(1, 1)); + // ..., formProxy, pushButton1, formWidget, window, window + QCOMPARE(eventSpy.count(), 8); + QCOMPARE(eventSpy.at(3).receiver, formProxy); // formProxy dispatches to the right subwidget + record = eventSpy.at(4); + QCOMPARE(record.receiver, pushButton1); + QVERIFY(closeEnough(record.position, pb1Center)); + QCOMPARE(record.eventType, QEvent::TouchBegin); + // pushButton doesn't accept the point, so the TouchBegin propagates to parent + record = eventSpy.at(5); + QCOMPARE(record.receiver, formWidget); + QVERIFY(closeEnough(record.position, pushButton1->pos() + pb1Center)); + QCOMPARE(record.eventType, QEvent::TouchBegin); + record = eventSpy.at(6); + QCOMPARE(record.receiver, view.windowHandle()); + QCOMPARE(record.eventType, QEvent::TouchUpdate); + record = eventSpy.at(7); + QCOMPARE(record.receiver, view.windowHandle()); + QCOMPARE(record.eventType, QEvent::TouchEnd); + QCOMPARE(eventSpy.mousePressReceiver, pushButton1); + QCOMPARE(clickedSpy.size(), 1); + eventSpy.clear(); + clickedSpy.clear(); + + // Single touch point to nested widget accepting event. + QTest::touchEvent(&view, touchDevice).press(0, tw1TouchPos); + QTest::touchEvent(&view, touchDevice).move(0, tw1TouchPos + QPoint(5, 5)); + QTest::touchEvent(&view, touchDevice).release(0, tw1TouchPos + QPoint(5, 5)); + // Press: ..., formProxy, touchWidget1 (5) + // Move: window, touchWidget1 (2) + // Release: window, touchWidget1 (2) + QCOMPARE(eventSpy.count(), 9); + QCOMPARE(eventSpy.at(3).receiver, formProxy); // form proxy dispatches TouchBegin to the right widget + record = eventSpy.at(4); + QCOMPARE(record.receiver, touchWidget1); + QVERIFY(closeEnough(record.position, tw1Center)); + QCOMPARE(record.eventType, QEvent::TouchBegin); + QCOMPARE(eventSpy.at(5).receiver, view.windowHandle()); // QWidgetWindow dispatches TouchUpdate + record = eventSpy.at(6); + QCOMPARE(record.receiver, touchWidget1); + QVERIFY(closeEnough(record.position, tw1Center + QPoint(5, 5))); + QCOMPARE(record.eventType, QEvent::TouchUpdate); + QCOMPARE(eventSpy.at(7).receiver, view.windowHandle()); // QWidgetWindow dispatches TouchEnd + record = eventSpy.at(8); + QCOMPARE(record.receiver, touchWidget1); + QVERIFY(closeEnough(record.position, tw1Center + QPoint(5, 5))); + QCOMPARE(record.eventType, QEvent::TouchEnd); + eventSpy.clear(); + + // to simplify the remaining test, install the event spy explicitly on the target widgets + qApp->removeEventFilter(&eventSpy); + formWidget->installEventFilter(&eventSpy); + pushButton1->installEventFilter(&eventSpy); + pushButton2->installEventFilter(&eventSpy); + touchWidget1->installEventFilter(&eventSpy); + touchWidget2->installEventFilter(&eventSpy); + + // multi-touch to different widgets, some do and some don't accept the event + QTest::touchEvent(&view, touchDevice) + .press(0, pb1TouchPos) + .press(1, tw1TouchPos) + .press(2, pb2TouchPos) + .press(3, tw2TouchPos); + QTest::touchEvent(&view, touchDevice) + .move(0, pb1TouchPos + QPoint(1, 1)) + .move(1, tw1TouchPos + QPoint(1, 1)) + .move(2, pb2TouchPos + QPoint(1, 1)) + .move(3, tw2TouchPos + QPoint(1, 1)); + QTest::touchEvent(&view, touchDevice) + .release(0, pb1TouchPos + QPoint(1, 1)) + .release(1, tw1TouchPos + QPoint(1, 1)) + .release(2, pb2TouchPos + QPoint(1, 1)) + .release(3, tw2TouchPos + QPoint(1, 1)); + + QCOMPARE(eventSpy.count(0), 2); // Begin never accepted, so move up and then stop + QCOMPARE(eventSpy.count(1), 3); // Begin accepted, so not propagated and update/end received + QCOMPARE(eventSpy.count(2), 2); // Begin never accepted + QCOMPARE(eventSpy.count(3), 3); // Begin accepted + QCOMPARE(eventSpy.at(0, 0).receiver, pushButton1); + QCOMPARE(eventSpy.at(1, 0).receiver, formWidget); + QCOMPARE(eventSpy.at(0, 1).receiver, touchWidget1); + QCOMPARE(eventSpy.at(1, 1).receiver, touchWidget1); + QCOMPARE(eventSpy.at(2, 1).receiver, touchWidget1); + QCOMPARE(eventSpy.at(0, 2).receiver, pushButton2); + QCOMPARE(eventSpy.at(1, 2).receiver, formWidget); + QCOMPARE(eventSpy.at(0, 3).receiver, touchWidget2); + QCOMPARE(eventSpy.at(1, 3).receiver, touchWidget2); + QCOMPARE(eventSpy.at(2, 3).receiver, touchWidget2); + 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 cf71701669..c0dd8995b8 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsscene/CMakeLists.txt +++ b/tests/auto/widgets/graphicsview/qgraphicsscene/CMakeLists.txt @@ -1,36 +1,20 @@ -# Generated from qgraphicsscene.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qgraphicsscene Test: ##################################################################### -qt_internal_add_test(tst_qgraphicsscene - LOWDPI # special case - SOURCES - tst_qgraphicsscene.cpp - DEFINES - QT_NO_CAST_TO_ASCII - SRCDIR=\\\"${CMAKE_CURRENT_SOURCE_DIR}\\\" - PUBLIC_LIBRARIES - Qt::CorePrivate - Qt::Gui - Qt::GuiPrivate - Qt::Widgets - Qt::WidgetsPrivate -) +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(images_resource_files - "Ash_European.jpg" -) -qt_internal_add_resource(tst_qgraphicsscene "images" - PREFIX - "/" - FILES - ${images_resource_files} -) set(testdata_resource_files + "Ash_European.jpg" "testData/render/all-all-45-deg-left.png" "testData/render/all-all-45-deg-right.png" "testData/render/all-all-scale-2x.png" @@ -61,18 +45,26 @@ set(testdata_resource_files "testData/render/topright-topleft-untransformed.png" ) -qt_internal_add_resource(tst_qgraphicsscene "testdata" - PREFIX - "/" - FILES - ${testdata_resource_files} +qt_internal_add_test(tst_qgraphicsscene + LOWDPI + SOURCES + tst_qgraphicsscene.cpp + DEFINES + QT_NO_CAST_TO_ASCII + LIBRARIES + Qt::CorePrivate + Qt::Gui + Qt::GuiPrivate + Qt::Widgets + Qt::WidgetsPrivate + TESTDATA ${testdata_resource_files} + BUILTIN_TESTDATA ) - ## Scopes: ##################################################################### qt_internal_extend_target(tst_qgraphicsscene CONDITION WIN32 - PUBLIC_LIBRARIES + LIBRARIES user32 ) diff --git a/tests/auto/widgets/graphicsview/qgraphicsscene/testdata.qrc b/tests/auto/widgets/graphicsview/qgraphicsscene/testdata.qrc deleted file mode 100644 index 07a0579cdc..0000000000 --- a/tests/auto/widgets/graphicsview/qgraphicsscene/testdata.qrc +++ /dev/null @@ -1,32 +0,0 @@ -<RCC> - <qresource prefix="/"> - <file>testData/render/all-all-45-deg-left.png</file> - <file>testData/render/all-all-45-deg-right.png</file> - <file>testData/render/all-all-scale-2x.png</file> - <file>testData/render/all-all-translate-0-50.png</file> - <file>testData/render/all-all-translate-50-0.png</file> - <file>testData/render/all-all-untransformed-clip-ellipse.png</file> - <file>testData/render/all-all-untransformed-clip-rect.png</file> - <file>testData/render/all-all-untransformed.png</file> - <file>testData/render/all-bottomleft-untransformed.png</file> - <file>testData/render/all-bottomright-untransformed.png</file> - <file>testData/render/all-topleft-untransformed.png</file> - <file>testData/render/all-topright-untransformed.png</file> - <file>testData/render/bottom-bottomright-untransformed.png</file> - <file>testData/render/bottom-topleft-untransformed.png</file> - <file>testData/render/bottomleft-all-untransformed.png</file> - <file>testData/render/bottomleft-topleft-untransformed.png</file> - <file>testData/render/bottomright-all-untransformed.png</file> - <file>testData/render/bottomright-topleft-untransformed.png</file> - <file>testData/render/left-bottomright-untransformed.png</file> - <file>testData/render/left-topleft-untransformed.png</file> - <file>testData/render/right-bottomright-untransformed.png</file> - <file>testData/render/right-topleft-untransformed.png</file> - <file>testData/render/top-bottomright-untransformed.png</file> - <file>testData/render/top-topleft-untransformed.png</file> - <file>testData/render/topleft-all-untransformed.png</file> - <file>testData/render/topleft-topleft-untransformed.png</file> - <file>testData/render/topright-all-untransformed.png</file> - <file>testData/render/topright-topleft-untransformed.png</file> - </qresource> -</RCC> diff --git a/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp b/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp index bfb746ed95..515ba80bbe 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2019 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2021 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QtWidgets/QApplication> #include <QtWidgets/QDial> @@ -56,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 \ @@ -278,6 +255,7 @@ private slots: void focusItemChangedSignal(); void minimumRenderSize(); void focusOnTouch(); + void clearSelection(); // task specific tests below me void task139710_bspTreeCrash(); @@ -294,6 +272,8 @@ private slots: void taskQTBUG_42915_focusNextPrevChild(); void taskQTBUG_85088_previewTextfailWhenLostFocus(); + void deleteItemsOnChange(); + private: QRect m_availableGeometry = QGuiApplication::primaryScreen()->availableGeometry(); QSize m_testSize; @@ -341,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); @@ -369,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()); } @@ -554,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); @@ -619,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()); @@ -966,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)); @@ -1003,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() @@ -1042,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)); @@ -1057,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)); @@ -1072,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)); @@ -1082,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)); @@ -1091,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() @@ -1218,10 +1198,10 @@ void tst_QGraphicsScene::addPath() QVERIFY(scene.items(QPointF(10, 10)).isEmpty()); QVERIFY(scene.items(QPointF(-10, 20)).isEmpty()); QVERIFY(scene.items(QPointF(10, 20)).isEmpty()); -if (sizeof(qreal) != sizeof(double)) - QWARN("Skipping test because of rounding errors when qreal != double"); -else - QVERIFY(scene.items(QPointF(-10, 30)).isEmpty()); + if (sizeof(qreal) != sizeof(double)) + qWarning("Skipping test because of rounding errors when qreal != double"); + else + QVERIFY(scene.items(QPointF(-10, 30)).isEmpty()); QVERIFY(scene.items(QPointF(10.1, 30)).isEmpty()); } @@ -1314,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); @@ -1622,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)); @@ -1692,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); @@ -1754,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); @@ -1770,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 @@ -1794,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 @@ -1804,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 @@ -2697,9 +2674,12 @@ void tst_QGraphicsScene::render() void tst_QGraphicsScene::renderItemsWithNegativeWidthOrHeight() { -#if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_EMBEDDED) +#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. @@ -2777,7 +2757,7 @@ protected: void tst_QGraphicsScene::contextMenuEvent_ItemIgnoresTransformations() { -#if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_EMBEDDED) +#ifdef Q_OS_ANDROID QSKIP("Test fails on some Android devices (QTBUG-44430)"); #endif @@ -2854,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) @@ -2871,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; @@ -3061,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)); @@ -3113,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)); @@ -3167,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()); @@ -3251,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)); @@ -3290,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()); @@ -3339,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)); @@ -3424,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()); @@ -3553,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() @@ -3684,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()); } } @@ -3698,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()); } } @@ -3842,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); @@ -4047,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); @@ -4058,12 +4034,11 @@ void tst_QGraphicsScene::polishItems2() void tst_QGraphicsScene::isActive() { - if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) - QSKIP("Window activation is not supported"); - -#if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_EMBEDDED) +#ifdef Q_OS_ANDROID QSKIP("Fails on Android (QTBUG-44430)"); #endif + if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + QSKIP("Window activation is not supported"); QGraphicsScene scene1; QVERIFY(!scene1.isActive()); @@ -4087,7 +4062,6 @@ void tst_QGraphicsScene::isActive() view1->setVisible(false); toplevel1.show(); - QApplication::setActiveWindow(&toplevel1); QVERIFY(QTest::qWaitForWindowActive(&toplevel1)); QCOMPARE(QApplication::activeWindow(), &toplevel1); @@ -4116,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); @@ -4156,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); @@ -4206,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); @@ -4234,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()); @@ -4264,7 +4238,6 @@ void tst_QGraphicsScene::isActive() toplevel3.show(); - QApplication::setActiveWindow(&toplevel3); QVERIFY(QTest::qWaitForWindowActive(&toplevel3)); QCOMPARE(QApplication::activeWindow(), &toplevel3); @@ -4377,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 @@ -4627,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() @@ -4644,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; @@ -4662,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); @@ -4671,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); @@ -4679,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); @@ -4708,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); @@ -4727,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); @@ -4739,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); @@ -4835,7 +4807,6 @@ void tst_QGraphicsScene::focusOnTouch() rect->setFlag(QGraphicsItem::ItemIsFocusable, true); view.show(); - QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowActive(&view)); QVERIFY(!rect->hasFocus()); @@ -4858,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; @@ -4889,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()); @@ -4931,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); @@ -4961,6 +4977,7 @@ void tst_QGraphicsScene::taskQTBUG_85088_previewTextfailWhenLostFocus() // focusItem will lose focus QMouseEvent pressEvent(QEvent::MouseButtonPress, QPointF(0, 0), + view.viewport()->mapToGlobal(QPointF()), Qt::LeftButton, Qt::NoButton, Qt::NoModifier); QApplication::sendEvent(view.viewport(), &pressEvent); @@ -4970,5 +4987,72 @@ void tst_QGraphicsScene::taskQTBUG_85088_previewTextfailWhenLostFocus() QCOMPARE(simpleTextItem->toPlainText(), str + str); } +void tst_QGraphicsScene::deleteItemsOnChange() +{ + QGraphicsScene scene; + + class SelectionItem : public QGraphicsRectItem { + public: + QRectF boundingRect() const override { return QRectF(); } + }; + + class ChangeItem : public QGraphicsItem + { + public: + ChangeItem() + { + setFlag(QGraphicsItem::ItemIsSelectable, true); + setFlag(QGraphicsItem::ItemIsMovable, true); + } + QRectF boundingRect() const override + { + return QRectF(0,0,100,100); + } + + protected: + void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override + { + painter->fillRect(boundingRect().toRect(), isSelected() ? Qt::yellow : Qt::cyan); + } + + QVariant itemChange(GraphicsItemChange change, const QVariant &value) override + { + if (change != QGraphicsItem::ItemSelectedHasChanged) + return QGraphicsItem::itemChange(change, value); + if (value.toBool()) { + selectionRect = new SelectionItem; + scene()->addItem(selectionRect); + } else { + // this recreates the selectedItems QSet inside of QGraphicsScene, + // invalidating iterators. See QTBUG-101651. + scene()->selectedItems(); + delete selectionRect; + selectionRect = nullptr; + } + return QGraphicsItem::itemChange(change, value); + } + private: + SelectionItem *selectionRect = nullptr; + }; + + ChangeItem item1; + item1.setPos(0, 0); + ChangeItem item2; + item1.setPos(50, 50); + + scene.addItem(&item1); + scene.addItem(&item2); + + QGraphicsView view; + view.setScene(&scene); + view.show(); + + QVERIFY(QTest::qWaitForWindowExposed(&view)); + + // this should not crash - see QTBUG-101651 + QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, QPoint(120, 120)); + QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, QPoint(25, 25)); +} + QTEST_MAIN(tst_QGraphicsScene) #include "tst_qgraphicsscene.moc" 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 9645b9a7fb..b6d48b52d5 100644 --- a/tests/auto/widgets/graphicsview/qgraphicssceneindex/tst_qgraphicssceneindex.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicssceneindex/tst_qgraphicssceneindex.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> @@ -33,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 { @@ -99,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() @@ -124,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() @@ -153,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() @@ -315,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); @@ -347,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 5d5323a3a2..3ee63d288b 100644 --- a/tests/auto/widgets/graphicsview/qgraphicstransform/tst_qgraphicstransform.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicstransform/tst_qgraphicstransform.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// 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 fe3d929e9e..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 @@ -45,3 +29,9 @@ android android [update_ancestorClipsChildrenToShape2] android +[QTBUG_70255_scrollTo] +android # QTBUG-87397 +[embeddedViewsWithFocus] +android # QTBUG-87397 +[viewportUpdateMode2] +android # QTBUG-87397 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 e666ac24c9..7ed1f28b0a 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> @@ -50,6 +25,7 @@ #include <QtWidgets/QBoxLayout> #include <QtWidgets/QStyle> #include <QtWidgets/QPushButton> +#include <QtWidgets/QScroller> #if QT_CONFIG(opengl) #include <QtOpenGLWidgets/QOpenGLWidget> #endif @@ -64,6 +40,8 @@ #include <QtTest/private/qtesthelpers_p.h> +#include <QtWidgets/private/qapplication_p.h> + using namespace QTestPrivate; Q_DECLARE_METATYPE(ExpectedValueDescription) @@ -101,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 @@ -225,6 +209,7 @@ private slots: void replayMouseMove(); void itemsUnderMouse(); void embeddedViews(); + void embeddedViewsWithFocus(); void scrollAfterResize_data(); void scrollAfterResize(); void moveItemWhileScrolling_data(); @@ -265,9 +250,12 @@ private slots: void QTBUG_5859_exposedRect(); void hoverLeave(); void QTBUG_16063_microFocusRect(); + void QTBUG_70255_scrollTo(); #ifndef QT_NO_CURSOR void QTBUG_7438_cursor(); #endif + void resizeContentsOnItemDrag_data(); + void resizeContentsOnItemDrag(); public slots: void dummySlot() {} @@ -666,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); @@ -687,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. @@ -740,8 +730,9 @@ void tst_QGraphicsView::dragMode_scrollHand() int verticalScrollBarValue = view.verticalScrollBar()->value(); { // Press - QMouseEvent event(QEvent::MouseButtonPress, - view.viewport()->rect().center(), + auto pos = view.viewport()->rect().center(); + QMouseEvent event(QEvent::MouseButtonPress, pos, + view.viewport()->mapToGlobal(pos), Qt::LeftButton, Qt::LeftButton, {}); event.setAccepted(true); QApplication::sendEvent(view.viewport(), &event); @@ -757,8 +748,9 @@ void tst_QGraphicsView::dragMode_scrollHand() #endif { // Move - QMouseEvent event(QEvent::MouseMove, - view.viewport()->rect().center() + QPoint(10, 0), + auto pos = view.viewport()->rect().center() + QPoint(10, 0); + QMouseEvent event(QEvent::MouseMove, pos, + view.viewport()->mapToGlobal(pos), Qt::LeftButton, Qt::LeftButton, {}); event.setAccepted(true); QApplication::sendEvent(view.viewport(), &event); @@ -769,8 +761,9 @@ void tst_QGraphicsView::dragMode_scrollHand() QCOMPARE(view.verticalScrollBar()->value(), verticalScrollBarValue); { // Move - QMouseEvent event(QEvent::MouseMove, - view.viewport()->rect().center() + QPoint(10, 10), + auto pos = view.viewport()->rect().center() + QPoint(10, 10); + QMouseEvent event(QEvent::MouseMove, pos, + view.viewport()->mapToGlobal(pos), Qt::LeftButton, Qt::LeftButton, {}); event.setAccepted(true); QApplication::sendEvent(view.viewport(), &event); @@ -783,8 +776,9 @@ void tst_QGraphicsView::dragMode_scrollHand() { // Release - QMouseEvent event(QEvent::MouseButtonRelease, - view.viewport()->rect().center() + QPoint(10, 10), + auto pos = view.viewport()->rect().center() + QPoint(10, 10); + QMouseEvent event(QEvent::MouseButtonRelease, pos, + view.viewport()->mapToGlobal(pos), Qt::LeftButton, Qt::LeftButton, {}); event.setAccepted(true); QApplication::sendEvent(view.viewport(), &event); @@ -805,15 +799,17 @@ void tst_QGraphicsView::dragMode_scrollHand() // Check that a click will still unselect the item. { // Press - QMouseEvent event(QEvent::MouseButtonPress, - view.viewport()->rect().center() + QPoint(10, 10), + auto pos = view.viewport()->rect().center() + QPoint(10, 10); + QMouseEvent event(QEvent::MouseButtonPress, pos, + view.viewport()->mapToGlobal(pos), Qt::LeftButton, Qt::LeftButton, {}); QApplication::sendEvent(view.viewport(), &event); } { // Release - QMouseEvent event(QEvent::MouseButtonRelease, - view.viewport()->rect().center() + QPoint(10, 10), + auto pos = view.viewport()->rect().center() + QPoint(10, 10); + QMouseEvent event(QEvent::MouseButtonRelease, pos, + view.viewport()->mapToGlobal(pos), Qt::LeftButton, Qt::LeftButton, {}); QApplication::sendEvent(view.viewport(), &event); } @@ -862,8 +858,9 @@ void tst_QGraphicsView::dragMode_rubberBand() int verticalScrollBarValue = view.verticalScrollBar()->value(); { // Press - QMouseEvent event(QEvent::MouseButtonPress, - view.viewport()->rect().center(), + auto pos = view.viewport()->rect().center(); + QMouseEvent event(QEvent::MouseButtonPress, pos, + view.viewport()->mapToGlobal(pos), Qt::LeftButton, Qt::LeftButton, {}); event.setAccepted(true); QApplication::sendEvent(view.viewport(), &event); @@ -877,8 +874,9 @@ void tst_QGraphicsView::dragMode_rubberBand() { // Move - QMouseEvent event(QEvent::MouseMove, - view.viewport()->rect().center() + QPoint(100, 0), + auto pos = view.viewport()->rect().center() + QPoint(100, 0); + QMouseEvent event(QEvent::MouseMove, pos, + view.viewport()->mapToGlobal(pos), Qt::LeftButton, Qt::LeftButton, {}); event.setAccepted(true); QApplication::sendEvent(view.viewport(), &event); @@ -892,8 +890,9 @@ void tst_QGraphicsView::dragMode_rubberBand() { // Move - QMouseEvent event(QEvent::MouseMove, - view.viewport()->rect().center() + QPoint(100, 100), + auto pos = view.viewport()->rect().center() + QPoint(100, 100); + QMouseEvent event(QEvent::MouseMove, pos, + view.viewport()->mapToGlobal(pos), Qt::LeftButton, Qt::LeftButton, {}); event.setAccepted(true); QApplication::sendEvent(view.viewport(), &event); @@ -904,8 +903,9 @@ void tst_QGraphicsView::dragMode_rubberBand() { // Release - QMouseEvent event(QEvent::MouseButtonRelease, - view.viewport()->rect().center() + QPoint(100, 100), + auto pos = view.viewport()->rect().center() + QPoint(100, 100); + QMouseEvent event(QEvent::MouseButtonRelease, pos, + view.viewport()->mapToGlobal(pos), Qt::LeftButton, Qt::LeftButton, {}); event.setAccepted(true); QApplication::sendEvent(view.viewport(), &event); @@ -1056,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); } @@ -1637,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); @@ -1930,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); @@ -2147,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)); @@ -2215,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)); @@ -2452,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()); @@ -2535,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); @@ -2747,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); @@ -2884,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); @@ -3179,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)); @@ -3241,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); @@ -3266,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; } @@ -3292,7 +3297,8 @@ void tst_QGraphicsView::task186827_deleteReplayedItem() QCOMPARE(view.mouseMoves, 0); { - QMouseEvent event(QEvent::MouseMove, view.mapFromScene(25, 25), Qt::NoButton, {}, {}); + auto pos = view.mapFromScene(25, 25); + QMouseEvent event(QEvent::MouseMove, pos, view.viewport()->mapToGlobal(pos), Qt::NoButton, {}, {}); QApplication::sendEvent(view.viewport(), &event); } QCOMPARE(view.mouseMoves, 1); @@ -3300,7 +3306,8 @@ void tst_QGraphicsView::task186827_deleteReplayedItem() QTRY_COMPARE(view.mouseMoves, 1); QTest::qWait(25); { - QMouseEvent event(QEvent::MouseMove, view.mapFromScene(25, 25), Qt::NoButton, {}, {}); + auto pos = view.mapFromScene(25, 25); + QMouseEvent event(QEvent::MouseMove, pos, view.viewport()->mapToGlobal(pos), Qt::NoButton, {}, {}); QApplication::sendEvent(view.viewport(), &event); } QCOMPARE(view.mouseMoves, 2); @@ -3325,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); @@ -3346,8 +3352,10 @@ void tst_QGraphicsView::task210599_unsetDragWhileDragging() // Enable and do a drag { view.setDragMode(QGraphicsView::ScrollHandDrag); - QMouseEvent press(QEvent::MouseButtonPress, origPos, Qt::LeftButton, {}, {}); - QMouseEvent move(QEvent::MouseMove, step1Pos, Qt::LeftButton, {}, {}); + QMouseEvent press(QEvent::MouseButtonPress, origPos, + view.viewport()->mapToGlobal(origPos), Qt::LeftButton, {}, {}); + QMouseEvent move(QEvent::MouseMove, step1Pos, + view.viewport()->mapToGlobal(step1Pos), Qt::LeftButton, {}, {}); QApplication::sendEvent(view.viewport(), &press); QApplication::sendEvent(view.viewport(), &move); } @@ -3355,7 +3363,8 @@ void tst_QGraphicsView::task210599_unsetDragWhileDragging() // unset drag and release mouse, inverse order { view.setDragMode(QGraphicsView::NoDrag); - QMouseEvent release(QEvent::MouseButtonRelease, step1Pos, Qt::LeftButton, {}, {}); + QMouseEvent release(QEvent::MouseButtonRelease, step1Pos, + view.viewport()->mapToGlobal(step1Pos), Qt::LeftButton, {}, {}); QApplication::sendEvent(view.viewport(), &release); } @@ -3364,7 +3373,8 @@ void tst_QGraphicsView::task210599_unsetDragWhileDragging() // reset drag, and move mouse without holding button down. { view.setDragMode(QGraphicsView::ScrollHandDrag); - QMouseEvent move(QEvent::MouseMove, step2Pos, Qt::LeftButton, {}, {}); + QMouseEvent move(QEvent::MouseMove, step2Pos, + view.viewport()->mapToGlobal(step2Pos), Qt::LeftButton, {}, {}); QApplication::sendEvent(view.viewport(), &move); } @@ -3413,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); @@ -3524,6 +3533,63 @@ void tst_QGraphicsView::embeddedViews() delete v1; } +/*! + Verify that a nested graphics view and embedded widgets receive window + activation and focus correctly. + + See QTBUG-94091. +*/ +void tst_QGraphicsView::embeddedViewsWithFocus() +{ + class FocusWidget : public QWidget + { + public: + FocusWidget() { setFocusPolicy(Qt::StrongFocus); } + QSize sizeHint() const override { return QSize(100, 100); } + + int focusCount = 0; + protected: + void mousePressEvent(QMouseEvent *) override {} // accept event to avoid warning + void focusInEvent(QFocusEvent *) override { ++focusCount; } + 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); + QGraphicsView *innerView = new QGraphicsView(&innerScene); + + QGraphicsScene outerScene; + FocusWidget *outerWidget = new FocusWidget; + QGraphicsProxyWidget *outerProxy = outerScene.addWidget(outerWidget); + QGraphicsProxyWidget *nestedProxy = outerScene.addWidget(innerView); + outerProxy->setPos(0, 0); + nestedProxy->setPos(0, outerWidget->sizeHint().height()); + QGraphicsView outerView(&outerScene); + outerView.show(); + outerView.activateWindow(); + QVERIFY(QTest::qWaitForWindowActive(&outerView)); + const QPoint outerCenter(QPoint(innerWidget->sizeHint().width() / 2, + innerWidget->sizeHint().height() / 2)); + const QPoint innerCenter(outerCenter + QPoint(0, innerWidget->sizeHint().height())); + QCOMPARE(outerView.itemAt(outerCenter), outerProxy); + QCOMPARE(outerView.itemAt(innerCenter), nestedProxy); + QVERIFY(outerScene.isActive()); + QVERIFY(innerScene.isActive()); + + QCOMPARE(outerWidget->focusCount, 0); + QCOMPARE(innerWidget->focusCount, 0); + QTest::mouseClick(outerView.viewport(), Qt::LeftButton, {}, outerCenter); + QCOMPARE(outerWidget->focusCount, 1); + QCOMPARE(innerWidget->focusCount, 0); + QTest::mouseClick(outerView.viewport(), Qt::LeftButton, {}, innerCenter); + QCOMPARE(outerWidget->focusCount, 0); + QCOMPARE(innerWidget->focusCount, 1); +} + void tst_QGraphicsView::scrollAfterResize_data() { QTest::addColumn<bool>("reverse"); @@ -3592,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); @@ -3814,8 +3883,9 @@ void tst_QGraphicsView::mouseTracking2() EventSpy spy(&scene, QEvent::GraphicsSceneMouseMove); QCOMPARE(spy.count(), 0); - QMouseEvent event(QEvent::MouseMove,view.viewport()->rect().center(), Qt::NoButton, - Qt::MouseButtons(Qt::NoButton), {}); + auto pos = view.viewport()->rect().center(); + QMouseEvent event(QEvent::MouseMove, pos, view.viewport()->mapToGlobal(pos), + Qt::NoButton, Qt::MouseButtons(Qt::NoButton), {}); QApplication::sendEvent(view.viewport(), &event); QCOMPARE(spy.count(), 1); } @@ -3983,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)); @@ -4057,7 +4127,6 @@ void tst_QGraphicsView::update() QVERIFY(QTest::qWaitForWindowExposed(&toplevel)); - QApplication::setActiveWindow(&toplevel); QApplication::processEvents(); QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&toplevel)); @@ -4114,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); @@ -4139,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); @@ -4209,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); @@ -4263,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); @@ -4324,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)); @@ -4422,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)); @@ -4570,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) @@ -4713,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: @@ -4741,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)); @@ -4813,7 +4884,6 @@ void tst_QGraphicsView::hoverLeave() scene.addItem(item); view.showNormal(); - qApp->setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowExposed(&view)); QWindow *viewWindow = view.window()->windowHandle(); @@ -4878,5 +4948,138 @@ void tst_QGraphicsView::QTBUG_16063_microFocusRect() QCOMPARE(mfv, IMItem::mf.translated(-view.mapToScene(view.sceneRect().toRect()).boundingRect().topLeft())); } +void tst_QGraphicsView::QTBUG_70255_scrollTo() +{ + QGraphicsView view; + QGraphicsScene scene; + view.setFixedSize(200, 200); + scene.setSceneRect(0, 0, 1000, 1000); + QGraphicsRectItem item; + item.setRect(-20, -20, 40, 40); + item.setFlag(QGraphicsItem::ItemIsMovable, true); + scene.addItem(&item); + view.setScene(&scene); + view.centerOn(0, 0); + + view.show(); + if (!QTest::qWaitForWindowExposed(&view) || !QTest::qWaitForWindowActive(&view)) + QSKIP("Failed to show and activate window"); + + QPoint point = view.mapFromScene(0, 0); + QCOMPARE(point, QPoint(0, 0)); + + QScroller::scroller(&view)->scrollTo(QPointF(0, 500), 100); + QTest::qWait(200); + + point = view.mapFromScene(0, 0); + 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 42e9e6e2a3..2fb5ed638c 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.h +++ b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// 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 72b5acc654..1380e007e7 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview_2.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview_2.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// 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 new file mode 100644 index 0000000000..cad381b7b7 --- /dev/null +++ b/tests/auto/widgets/graphicsview/qgraphicswidget/BLACKLIST @@ -0,0 +1,8 @@ +[initStyleOption] +macos ci +android +b2qt +# QTBUG-100930 +[updateFocusChainWhenChildDie] +b2qt +qnx 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 c22195fada..9fd93ca91d 100644 --- a/tests/auto/widgets/graphicsview/qgraphicswidget/tst_qgraphicswidget.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicswidget/tst_qgraphicswidget.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> @@ -41,6 +16,9 @@ #include <qcommonstyle.h> #include <qstylefactory.h> #include <qscreen.h> +#include <qsignalspy.h> + +#include <QtWidgets/private/qapplication_p.h> typedef QList<QGraphicsItem *> QGraphicsItemList; @@ -57,7 +35,7 @@ public: int count() const { return _count; } protected: - bool eventFilter(QObject *watched, QEvent *event) + bool eventFilter(QObject *watched, QEvent *event) override { Q_UNUSED(watched); if (event->type() == spied) @@ -151,7 +129,6 @@ private slots: void polishEvent2(); void autoFillBackground(); void initialShow(); - void initialShow2(); void itemChangeEvents(); void itemSendGeometryPosChangesDeactivated(); void fontPropagatesResolveToChildren(); @@ -169,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: @@ -178,7 +163,7 @@ public: : QGraphicsWidget(parent, windowFlags), eventCount(0) { } - void initStyleOption(QStyleOption *option) const + void initStyleOption(QStyleOption *option) const override { QGraphicsWidget::initStyleOption(option); } void call_changeEvent(QEvent* event) @@ -232,7 +217,7 @@ public: int eventCount; Qt::LayoutDirection m_painterLayoutDirection; - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override { m_painterLayoutDirection = painter->layoutDirection(); QGraphicsWidget::paint(painter, option, widget); @@ -244,7 +229,7 @@ public: } protected: - bool event(QEvent *event) + bool event(QEvent *event) override { eventCount++; return QGraphicsWidget::event(event); @@ -271,7 +256,7 @@ public: } protected: - QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const + QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const override { Q_UNUSED(constraint); return m_sizes[which]; @@ -518,11 +503,14 @@ void tst_QGraphicsWidget::focusWidget2() class FocusWatchWidget : public QGraphicsWidget { public: - FocusWatchWidget(QGraphicsItem *parent = nullptr) : QGraphicsWidget(parent) { gotFocusInCount = 0; gotFocusOutCount = 0; } + FocusWatchWidget(QGraphicsItem *parent = nullptr) + : QGraphicsWidget(parent) { gotFocusInCount = 0; gotFocusOutCount = 0; } int gotFocusInCount, gotFocusOutCount; protected: - void focusInEvent(QFocusEvent *fe) { gotFocusInCount++; QGraphicsWidget::focusInEvent(fe); } - void focusOutEvent(QFocusEvent *fe) { gotFocusOutCount++; QGraphicsWidget::focusOutEvent(fe); } + void focusInEvent(QFocusEvent *fe) override + { gotFocusInCount++; QGraphicsWidget::focusInEvent(fe); } + void focusOutEvent(QFocusEvent *fe) override + { gotFocusOutCount++; QGraphicsWidget::focusOutEvent(fe); } }; void tst_QGraphicsWidget::focusWidget3() @@ -962,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)); } @@ -975,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)); } @@ -990,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() @@ -1003,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() @@ -1071,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; @@ -1085,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) { @@ -1107,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) @@ -1145,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); } @@ -1183,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(); @@ -1216,8 +1211,6 @@ void tst_QGraphicsWidget::palettePropagation() // These colors are unlikely to be imposed on the default palette of // QWidget ;-). - QColor sysPalText(21, 22, 23); - QColor sysPalToolTipBase(12, 13, 14); QColor overridePalText(42, 43, 44); QColor overridePalToolTipBase(45, 46, 47); QColor sysPalButton(99, 98, 97); @@ -1375,6 +1368,8 @@ void tst_QGraphicsWidget::setStyle() // cleanup widget.setStyle(0); +#else + QSKIP("This test requires the Fusion style"); #endif } @@ -1393,7 +1388,6 @@ void tst_QGraphicsWidget::setTabOrder() QGraphicsScene scene; QGraphicsView view(&scene); view.show(); - QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowActive(&view)); QGraphicsWidget *lastItem = nullptr; @@ -1421,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()); @@ -1465,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); @@ -1570,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); } } @@ -1595,7 +1588,6 @@ void tst_QGraphicsWidget::verifyFocusChain() QGraphicsScene scene; QGraphicsView view(&scene); view.show(); - QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowActive(&view)); { @@ -1687,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(); @@ -1735,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 @@ -1770,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, 0, 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)); } @@ -1862,7 +1851,7 @@ enum WhichSize { MinimumSizeHint, PreferredSizeHint, MaximumSizeHint, - Size, + WidgetSize, None, }; @@ -1877,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() @@ -1934,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 @@ -1948,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: @@ -1988,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: @@ -2000,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: @@ -2318,7 +2307,7 @@ public: int ngrab; int nungrab; protected: - bool sceneEvent(QEvent *event) + bool sceneEvent(QEvent *event) override { switch (event->type()) { case QEvent::GrabMouse: @@ -2333,17 +2322,17 @@ protected: return QGraphicsRectItem::sceneEvent(event); } - void mousePressEvent(QGraphicsSceneMouseEvent *) + void mousePressEvent(QGraphicsSceneMouseEvent *) override { grabMouse(); ++npress; } - void mouseReleaseEvent(QGraphicsSceneMouseEvent *) + void mouseReleaseEvent(QGraphicsSceneMouseEvent *) override { ungrabMouse(); ++nrelease; } - void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *) + void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *) override { ++ndoubleClick; } @@ -2369,7 +2358,7 @@ void tst_QGraphicsWidget::doubleClickAfterExplicitMouseGrab() { QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseRelease); event.setButton(Qt::LeftButton); - event.setButtons(0); + event.setButtons({}); event.ignore(); event.setScenePos(QPointF(50, 50)); qApp->sendEvent(&scene, &event); @@ -2391,7 +2380,7 @@ void tst_QGraphicsWidget::doubleClickAfterExplicitMouseGrab() { QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseRelease); event.setButton(Qt::LeftButton); - event.setButtons(0); + event.setButtons({}); event.ignore(); event.setScenePos(QPointF(50, 50)); qApp->sendEvent(&scene, &event); @@ -2538,7 +2527,7 @@ void tst_QGraphicsWidget::windowFlags() QCOMPARE(widget2.windowFlags(), Qt::WindowFlags(outputFlags)); // Reset flags - widget2.setWindowFlags(0); + widget2.setWindowFlags({}); QVERIFY(!widget2.windowFlags()); // Set flags back again @@ -2555,7 +2544,7 @@ void tst_QGraphicsWidget::windowFlags() QCOMPARE(widget4.windowFlags(), Qt::WindowFlags(inputFlags | Qt::FramelessWindowHint)); // Reset flags - widget4.setWindowFlags(0); + widget4.setWindowFlags({}); QVERIFY(!widget4.windowFlags()); // Set custom flags back again @@ -2565,7 +2554,7 @@ void tst_QGraphicsWidget::windowFlags() QGraphicsWidget *widget5 = new QGraphicsWidget; widget5->setWindowFlags(Qt::WindowFlags(inputFlags)); QCOMPARE(widget5->windowFlags(), Qt::WindowFlags(outputFlags)); - QGraphicsWidget window(0, Qt::Window); + QGraphicsWidget window(nullptr, Qt::Window); widget5->setParentItem(&window); QCOMPARE(widget5->windowFlags(), Qt::WindowFlags(outputFlags)); } @@ -2591,13 +2580,13 @@ public: : QGraphicsWidget(parent, wFlags) {} - void paintWindowFrame(QPainter * painter, const QStyleOptionGraphicsItem *option, QWidget *widget) + void paintWindowFrame(QPainter * painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override { QCOMPARE(painter->opacity(), 1.0); painter->setOpacity(0.0); QGraphicsWidget::paintWindowFrame(painter, option, widget); } - void paint(QPainter * painter, const QStyleOptionGraphicsItem *option, QWidget *widget) + void paint(QPainter * painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override { QCOMPARE(painter->opacity(), 1.0); painter->drawRect(0, 0, 100, 100); @@ -2624,7 +2613,7 @@ public: m_proxyStyle = proxyStyle; } - int pixelMetric(QStyle::PixelMetric metric, const QStyleOption *option = 0, const QWidget *widget = 0) const + int pixelMetric(QStyle::PixelMetric metric, const QStyleOption *option = 0, const QWidget *widget = 0) const override { return m_proxyStyle->pixelMetric(metric, option, widget); } @@ -2676,14 +2665,14 @@ public: int shortcutEvents; private: - bool event(QEvent *event) + bool event(QEvent *event) override { if (event->type() == QEvent::Shortcut) shortcutEvents++; return QGraphicsWidget::event(event); } - void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) + void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override { if (hasFocus()) { painter->setPen(QPen(Qt::black, 0, Qt::DashLine)); @@ -2701,7 +2690,6 @@ void tst_QGraphicsWidget::task250119_shortcutContext() QGraphicsView view; view.setScene(&scene); view.show(); - QApplication::setActiveWindow(&view); QTRY_COMPARE(QApplication::activeWindow(), (QWidget*)&view); @@ -2738,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); } @@ -2753,7 +2741,7 @@ public: QList<QGraphicsItem *> drawnItems; protected: void drawItems(QPainter *painter, int numItems, QGraphicsItem *items[], - const QStyleOptionGraphicsItem options[], QWidget *widget = 0) + const QStyleOptionGraphicsItem options[], QWidget *widget = 0) override { drawnItems.clear(); for (int i = 0; i < numItems; ++i) @@ -2768,7 +2756,7 @@ public: RectWidget(Qt::GlobalColor color, QGraphicsItem *parent=0) : QGraphicsWidget(parent), mColor(color) {} - void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) + void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override { painter->setBrush(QBrush(mColor)); painter->drawRect(boundingRect()); @@ -2783,10 +2771,10 @@ public: RectItem(Qt::GlobalColor color, QGraphicsItem *parent=0) : QGraphicsItem(parent), mColor(color) {} - QRectF boundingRect() const + QRectF boundingRect() const override {return QRectF(10,10,50,50);} - void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) + void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override { painter->setBrush(QBrush(mColor)); painter->drawRect(boundingRect()); @@ -2844,7 +2832,7 @@ public: QList<QVariant> values; QList<QVariant> oldValues; protected: - QVariant itemChange(GraphicsItemChange change, const QVariant &value) + QVariant itemChange(GraphicsItemChange change, const QVariant &value) override { changes << change; values << value; @@ -2864,7 +2852,7 @@ protected: void tst_QGraphicsWidget::widgetSendsGeometryChanges() { ItemChangeTester widget; - widget.setFlags(0); + widget.setFlags({}); widget.clear(); QPointF pos(10, 10); @@ -2906,7 +2894,7 @@ public: setSizePolicy(sp); } - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override { Q_UNUSED(option); Q_UNUSED(widget); @@ -2918,7 +2906,7 @@ public: } protected: - QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const + QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const override { qreal w = constraint.width(); switch (which) { @@ -2941,9 +2929,6 @@ protected: void tst_QGraphicsWidget::respectHFW() { -#if defined(Q_OS_DARWIN) - QSKIP("This test is platform dependent, it fails on Apple platforms. Please fix."); -#else QGraphicsScene scene; HFWWidget *window = new HFWWidget; scene.addItem(window); @@ -2958,22 +2943,22 @@ void tst_QGraphicsWidget::respectHFW() { // here we go - simulate a interactive resize of the window QTest::mouseMove(view.data(), view->mapFromScene(71, 71)); // bottom right corner - QTest::mousePress(view->viewport(), Qt::LeftButton, 0, view->mapFromScene(71, 71), 200); + QTest::mousePress(view->viewport(), Qt::LeftButton, {}, view->mapFromScene(71, 71), 200); view->grabMouse(); // move both mouse cursor and set correct event in order to emulate resize QTest::mouseMove(view->viewport(), view->mapFromScene(60, 30), 200); - QMouseEvent e = QMouseEvent(QEvent::MouseMove, - view->mapFromScene(60, 20), - Qt::NoButton, - Qt::LeftButton, - Qt::NoModifier); + auto pos = view->mapFromScene(60, 20); + QMouseEvent e(QEvent::MouseMove, pos, view->mapToGlobal(pos), + Qt::NoButton, Qt::LeftButton, Qt::NoModifier); QApplication::sendEvent(view->viewport(), &e); view->releaseMouse(); } const QSizeF winSize = window->size(); qreal minHFW = window->effectiveSizeHint(Qt::MinimumSize, QSizeF(winSize.width(), -1)).height(); - QTRY_VERIFY(qAbs(minHFW - winSize.height()) < 1); +#ifdef Q_OS_DARWIN + QEXPECT_FAIL("", "This test is known to fail on Apple platforms.", Continue); #endif + QTRY_VERIFY(qAbs(minHFW - winSize.height()) < 1); } class PolishWidget : public QGraphicsWidget @@ -2985,13 +2970,13 @@ public: { } - void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) + void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override { painter->setBrush(QBrush(mColor)); painter->drawRect(boundingRect()); } - void polishEvent() + void polishEvent() override { if (!parentWidget()) { //We add a child in the polish event for the parent @@ -3031,9 +3016,9 @@ void tst_QGraphicsWidget::polishEvent() { class MyGraphicsWidget : public QGraphicsWidget { public: - void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) + void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override { events << QEvent::Paint; } - void polishEvent() + void polishEvent() override { events << QEvent::Polish; } QList<QEvent::Type> events; }; @@ -3058,7 +3043,7 @@ void tst_QGraphicsWidget::polishEvent2() { class MyGraphicsWidget : public QGraphicsWidget { public: - void polishEvent() + void polishEvent() override { events << QEvent::Polish; } QList<QEvent::Type> events; }; @@ -3107,31 +3092,8 @@ void tst_QGraphicsWidget::initialShow() { public: MyGraphicsWidget() : repaints(0) {} int repaints; - void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget*) { ++repaints; } - void polishEvent() { update(); } - }; - - QGraphicsScene scene; - MyGraphicsWidget *widget = new MyGraphicsWidget; - - QGraphicsView view(&scene); - view.show(); - qApp->setActiveWindow(&view); - QVERIFY(QTest::qWaitForWindowActive(&view)); - - scene.addItem(widget); - - QTRY_COMPARE(widget->repaints, 1); -} - -void tst_QGraphicsWidget::initialShow2() -{ - class MyGraphicsWidget : public QGraphicsWidget - { public: - MyGraphicsWidget() : repaints(0) {} - int repaints; - void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget*) { ++repaints; } - void polishEvent() { update(); } + void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget*) override { ++repaints; } + void polishEvent() override { update(); } }; // Don't let paint events triggered by the windowing system @@ -3146,8 +3108,7 @@ void tst_QGraphicsWidget::initialShow2() 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(); @@ -3160,8 +3121,7 @@ void tst_QGraphicsWidget::initialShow2() 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); } @@ -3172,7 +3132,7 @@ void tst_QGraphicsWidget::itemChangeEvents() { public: TestGraphicsWidget() : QGraphicsWidget() {} QHash<QEvent::Type, QVariant> valueDuringEvents; - bool event(QEvent *event) { + bool event(QEvent *event) override { Q_UNUSED(event); switch (event->type()) { case QEvent::EnabledChange: { @@ -3203,11 +3163,11 @@ void tst_QGraphicsWidget::itemChangeEvents() } return true; } - void showEvent(QShowEvent *event) { + void showEvent(QShowEvent *event) override { Q_UNUSED(event); valueDuringEvents.insert(QEvent::Show, isVisible()); } - void hideEvent(QHideEvent *event) { + void hideEvent(QHideEvent *event) override { Q_UNUSED(event); valueDuringEvents.insert(QEvent::Hide, isVisible()); } @@ -3293,8 +3253,8 @@ public: void verifyTabFocus(QGraphicsScene *scene, const QList<QGraphicsWidget *> &chain, bool wrapsAround) { - QKeyEvent tabEvent(QEvent::KeyPress, Qt::Key_Tab, 0); - QKeyEvent backtabEvent(QEvent::KeyPress, Qt::Key_Backtab, 0); + QKeyEvent tabEvent(QEvent::KeyPress, Qt::Key_Tab, {}); + QKeyEvent backtabEvent(QEvent::KeyPress, Qt::Key_Backtab, {}); for (int i = 0; i < chain.size(); ++i) chain.at(i)->clearFocus(); |