summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/graphicsview
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/widgets/graphicsview')
-rw-r--r--tests/auto/widgets/graphicsview/.prev_CMakeLists.txt24
-rw-r--r--tests/auto/widgets/graphicsview/CMakeLists.txt18
-rw-r--r--tests/auto/widgets/graphicsview/graphicsview.pro32
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsanchorlayout/BLACKLIST2
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsanchorlayout/CMakeLists.txt13
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsanchorlayout/qgraphicsanchorlayout.pro5
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp53
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsanchorlayout1/CMakeLists.txt13
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsanchorlayout1/qgraphicsanchorlayout1.pro5
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp59
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicseffectsource/CMakeLists.txt13
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicseffectsource/qgraphicseffectsource.pro7
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicseffectsource/tst_qgraphicseffectsource.cpp51
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsgridlayout/CMakeLists.txt13
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsgridlayout/qgraphicsgridlayout.pro5
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp56
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsitem/BLACKLIST4
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsitem/CMakeLists.txt17
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsitem/qgraphicsitem.pro8
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp147
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsitemanimation/CMakeLists.txt13
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsitemanimation/qgraphicsitemanimation.pro6
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsitemanimation/tst_qgraphicsitemanimation.cpp35
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicslayout/CMakeLists.txt13
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicslayout/qgraphicslayout.pro9
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicslayout/tst_qgraphicslayout.cpp93
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicslayoutitem/CMakeLists.txt13
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicslayoutitem/qgraphicslayoutitem.pro5
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicslayoutitem/tst_qgraphicslayoutitem.cpp41
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicslinearlayout/CMakeLists.txt13
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicslinearlayout/qgraphicslinearlayout.pro4
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicslinearlayout/tst_qgraphicslinearlayout.cpp60
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsobject/CMakeLists.txt13
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsobject/qgraphicsobject.pro7
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsobject/tst_qgraphicsobject.cpp115
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicspixmapitem/CMakeLists.txt13
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicspixmapitem/qgraphicspixmapitem.pro5
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicspixmapitem/tst_qgraphicspixmapitem.cpp39
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicspolygonitem/CMakeLists.txt13
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicspolygonitem/qgraphicspolygonitem.pro4
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicspolygonitem/tst_qgraphicspolygonitem.cpp39
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsproxywidget/BLACKLIST11
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsproxywidget/CMakeLists.txt13
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsproxywidget/qgraphicsproxywidget.pro9
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp1188
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsscene/BLACKLIST5
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsscene/CMakeLists.txt55
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsscene/qgraphicsscene.pro12
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsscene/testdata.qrc32
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp389
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicssceneindex/CMakeLists.txt16
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicssceneindex/qgraphicssceneindex.pro6
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicssceneindex/tst_qgraphicssceneindex.cpp108
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicstransform/CMakeLists.txt13
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicstransform/qgraphicstransform.pro4
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicstransform/tst_qgraphicstransform.cpp37
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsview/BLACKLIST51
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsview/CMakeLists.txt20
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsview/qgraphicsview.pro12
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp462
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.h33
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview_2.cpp33
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicswidget/BLACKLIST8
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicswidget/CMakeLists.txt13
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicswidget/qgraphicswidget.pro8
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicswidget/tst_qgraphicswidget.cpp397
66 files changed, 2000 insertions, 2033 deletions
diff --git a/tests/auto/widgets/graphicsview/.prev_CMakeLists.txt b/tests/auto/widgets/graphicsview/.prev_CMakeLists.txt
deleted file mode 100644
index 28a641ac61..0000000000
--- a/tests/auto/widgets/graphicsview/.prev_CMakeLists.txt
+++ /dev/null
@@ -1,24 +0,0 @@
-# Generated from graphicsview.pro.
-
-if(QT_FEATURE_private_tests)
- add_subdirectory(qgraphicsanchorlayout)
- add_subdirectory(qgraphicsanchorlayout1)
- add_subdirectory(qgraphicsitem)
- add_subdirectory(qgraphicsscene)
- add_subdirectory(qgraphicssceneindex)
-endif()
-add_subdirectory(qgraphicseffectsource)
-add_subdirectory(qgraphicsgridlayout)
-add_subdirectory(qgraphicsitemanimation)
-add_subdirectory(qgraphicslayout)
-add_subdirectory(qgraphicslayoutitem)
-add_subdirectory(qgraphicslinearlayout)
-add_subdirectory(qgraphicsobject)
-add_subdirectory(qgraphicspixmapitem)
-add_subdirectory(qgraphicspolygonitem)
-add_subdirectory(qgraphicstransform)
-add_subdirectory(qgraphicsview)
-if(QT_FEATURE_style_fusion)
- add_subdirectory(qgraphicsproxywidget)
- add_subdirectory(qgraphicswidget)
-endif()
diff --git a/tests/auto/widgets/graphicsview/CMakeLists.txt b/tests/auto/widgets/graphicsview/CMakeLists.txt
index d995d3c1e0..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,17 +18,6 @@ add_subdirectory(qgraphicsobject)
add_subdirectory(qgraphicspixmapitem)
add_subdirectory(qgraphicspolygonitem)
add_subdirectory(qgraphicstransform)
+add_subdirectory(qgraphicsproxywidget)
+add_subdirectory(qgraphicswidget)
add_subdirectory(qgraphicsview)
-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()
diff --git a/tests/auto/widgets/graphicsview/graphicsview.pro b/tests/auto/widgets/graphicsview/graphicsview.pro
deleted file mode 100644
index e99897a4f6..0000000000
--- a/tests/auto/widgets/graphicsview/graphicsview.pro
+++ /dev/null
@@ -1,32 +0,0 @@
-TEMPLATE=subdirs
-SUBDIRS=\
- qgraphicsanchorlayout \
- qgraphicsanchorlayout1 \
- qgraphicseffectsource \
- qgraphicsgridlayout \
- qgraphicsitem \
- qgraphicsitemanimation \
- qgraphicslayout \
- qgraphicslayoutitem \
- qgraphicslinearlayout \
- qgraphicsobject \
- qgraphicspixmapitem \
- qgraphicspolygonitem \
- qgraphicsproxywidget \
- qgraphicsscene \
- qgraphicssceneindex \
- qgraphicstransform \
- qgraphicsview \
- qgraphicswidget \
-
-!qtConfig(private_tests): SUBDIRS -= \
- qgraphicsanchorlayout \
- qgraphicsanchorlayout1 \
- qgraphicsitem \
- qgraphicsscene \
- qgraphicssceneindex \
-
-# These tests require the fusion style
-!contains(styles, fusion):SUBDIRS -= \
- qgraphicsproxywidget \
- qgraphicswidget \
diff --git a/tests/auto/widgets/graphicsview/qgraphicsanchorlayout/BLACKLIST b/tests/auto/widgets/graphicsview/qgraphicsanchorlayout/BLACKLIST
new file mode 100644
index 0000000000..fde971443d
--- /dev/null
+++ b/tests/auto/widgets/graphicsview/qgraphicsanchorlayout/BLACKLIST
@@ -0,0 +1,2 @@
+[layoutDirection]
+ubuntu-22.04
diff --git a/tests/auto/widgets/graphicsview/qgraphicsanchorlayout/CMakeLists.txt b/tests/auto/widgets/graphicsview/qgraphicsanchorlayout/CMakeLists.txt
index 8bf6a5b5ad..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:
#####################################################################
-qt_add_test(tst_qgraphicsanchorlayout
+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/qgraphicsanchorlayout.pro b/tests/auto/widgets/graphicsview/qgraphicsanchorlayout/qgraphicsanchorlayout.pro
deleted file mode 100644
index 8e8c0708a3..0000000000
--- a/tests/auto/widgets/graphicsview/qgraphicsanchorlayout/qgraphicsanchorlayout.pro
+++ /dev/null
@@ -1,5 +0,0 @@
-CONFIG += testcase
-TARGET = tst_qgraphicsanchorlayout
-QT += widgets widgets-private testlib
-QT += core-private gui-private
-SOURCES += tst_qgraphicsanchorlayout.cpp
diff --git a/tests/auto/widgets/graphicsview/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp b/tests/auto/widgets/graphicsview/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp
index e19ef4c308..cf37aa5639 100644
--- a/tests/auto/widgets/graphicsview/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp
+++ b/tests/auto/widgets/graphicsview/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp
@@ -1,32 +1,7 @@
-/****************************************************************************
-**
-** 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$
-**
-****************************************************************************/
-
-#include <QtTest/QtTest>
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#include <QTest>
#include <QtWidgets/qgraphicsanchorlayout.h>
#include <private/qgraphicsanchorlayout_p.h>
#include <QtWidgets/qgraphicswidget.h>
@@ -85,9 +60,9 @@ private slots:
class RectWidget : public QGraphicsWidget
{
public:
- RectWidget(QGraphicsItem *parent = 0) : QGraphicsWidget(parent){}
+ RectWidget(QGraphicsItem *parent = nullptr) : QGraphicsWidget(parent){}
- 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);
@@ -1112,8 +1087,8 @@ public:
vspacing = 10;
}
- virtual int pixelMetric(PixelMetric metric, const QStyleOption * option = 0,
- const QWidget * widget = 0 ) const;
+ virtual int pixelMetric(PixelMetric metric, const QStyleOption * option = nullptr,
+ const QWidget * widget = nullptr) const override;
int hspacing;
int vspacing;
@@ -1121,8 +1096,8 @@ public:
int layoutSpacing(QSizePolicy::ControlType control1,
QSizePolicy::ControlType control2,
Qt::Orientation orientation,
- const QStyleOption *option = 0,
- const QWidget *widget = 0) const;
+ const QStyleOption *option = nullptr,
+ const QWidget *widget = nullptr) const override;
};
@@ -1132,8 +1107,8 @@ public:
int CustomLayoutStyle::layoutSpacing(QSizePolicy::ControlType control1,
QSizePolicy::ControlType control2,
Qt::Orientation orientation,
- const QStyleOption * /*option = 0*/,
- const QWidget * /*widget = 0*/) const
+ const QStyleOption * /*option = nullptr*/,
+ const QWidget * /*widget = nullptr*/) const
{
if (orientation == Qt::Horizontal) {
switch (CT2(control1, control2)) {
@@ -1153,8 +1128,8 @@ int CustomLayoutStyle::layoutSpacing(QSizePolicy::ControlType control1,
}
}
-int CustomLayoutStyle::pixelMetric(PixelMetric metric, const QStyleOption * option /*= 0*/,
- const QWidget * widget /*= 0*/ ) const
+int CustomLayoutStyle::pixelMetric(PixelMetric metric, const QStyleOption * option /*= nullptr*/,
+ const QWidget * widget /*= nullptr*/ ) const
{
switch (metric) {
case PM_LayoutLeftMargin:
diff --git a/tests/auto/widgets/graphicsview/qgraphicsanchorlayout1/CMakeLists.txt b/tests/auto/widgets/graphicsview/qgraphicsanchorlayout1/CMakeLists.txt
index a945cbf86f..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:
#####################################################################
-qt_add_test(tst_qgraphicsanchorlayout1
+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/qgraphicsanchorlayout1.pro b/tests/auto/widgets/graphicsview/qgraphicsanchorlayout1/qgraphicsanchorlayout1.pro
deleted file mode 100644
index a1064d1c73..0000000000
--- a/tests/auto/widgets/graphicsview/qgraphicsanchorlayout1/qgraphicsanchorlayout1.pro
+++ /dev/null
@@ -1,5 +0,0 @@
-CONFIG += testcase
-TARGET = tst_qgraphicsanchorlayout1
-QT += widgets widgets-private testlib
-QT += core-private gui-private
-SOURCES += tst_qgraphicsanchorlayout1.cpp
diff --git a/tests/auto/widgets/graphicsview/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp b/tests/auto/widgets/graphicsview/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp
index 65480bf665..9a047b876d 100644
--- a/tests/auto/widgets/graphicsview/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp
+++ b/tests/auto/widgets/graphicsview/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp
@@ -1,33 +1,8 @@
-/****************************************************************************
-**
-** 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 <QtTest/QtTest>
+#include <QTest>
#include <QTest>
#include <QMetaType>
#include <QtWidgets/qgraphicsanchorlayout.h>
@@ -149,7 +124,7 @@ Q_DECLARE_METATYPE(AnchorItemSizeHintList)
class TestWidget : public QGraphicsWidget
{
public:
- inline TestWidget(QGraphicsItem *parent = 0, const QString &name = QString())
+ inline TestWidget(QGraphicsItem *parent = nullptr, const QString &name = QString())
: QGraphicsWidget(parent)
{
setContentsMargins( 0,0,0,0 );
@@ -163,7 +138,7 @@ public:
}
protected:
- QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const;
+ QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const override;
};
QSizeF TestWidget::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
@@ -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 a508934554..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:
#####################################################################
-qt_add_test(tst_qgraphicseffectsource
+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/qgraphicseffectsource.pro b/tests/auto/widgets/graphicsview/qgraphicseffectsource/qgraphicseffectsource.pro
deleted file mode 100644
index 550d3debf7..0000000000
--- a/tests/auto/widgets/graphicsview/qgraphicseffectsource/qgraphicseffectsource.pro
+++ /dev/null
@@ -1,7 +0,0 @@
-CONFIG += testcase
-TARGET = tst_qgraphicseffectsource
-
-QT += widgets widgets-private testlib
-QT += core-private gui-private
-
-SOURCES += tst_qgraphicseffectsource.cpp
diff --git a/tests/auto/widgets/graphicsview/qgraphicseffectsource/tst_qgraphicseffectsource.cpp b/tests/auto/widgets/graphicsview/qgraphicseffectsource/tst_qgraphicseffectsource.cpp
index eaad5e478d..28c439dbcd 100644
--- a/tests/auto/widgets/graphicsview/qgraphicseffectsource/tst_qgraphicseffectsource.cpp
+++ b/tests/auto/widgets/graphicsview/qgraphicseffectsource/tst_qgraphicseffectsource.cpp
@@ -1,32 +1,7 @@
-/****************************************************************************
-**
-** 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$
-**
-****************************************************************************/
-
-#include <QtTest/QtTest>
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#include <QTest>
#include <QtWidgets/qgraphicseffect.h>
#include <QtWidgets/qgraphicsview.h>
#include <QtWidgets/qgraphicsscene.h>
@@ -43,7 +18,7 @@ public:
m_painter(0)
{}
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
{
m_painter = painter;
++numRepaints;
@@ -70,7 +45,7 @@ public:
m_painter(0), m_source(0)
{}
- QRectF boundingRectFor(const QRectF &rect) const
+ QRectF boundingRectFor(const QRectF &rect) const override
{ return rect.adjusted(-m_margin, -m_margin, m_margin, m_margin); }
void reset()
@@ -94,7 +69,7 @@ public:
int margin() const
{ return m_margin; }
- void draw(QPainter *painter)
+ void draw(QPainter *painter) override
{
++numRepaints;
if (storeDeviceDependentStuff) {
@@ -109,7 +84,7 @@ public:
source()->draw(painter);
}
- void sourceChanged(ChangeFlags)
+ void sourceChanged(ChangeFlags) override
{ m_sourceChanged = true; }
void sourceBoundingRectChanged()
@@ -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()
@@ -310,11 +285,13 @@ public:
{
}
- QRectF boundingRectFor(const QRectF &src) const {
+ QRectF boundingRectFor(const QRectF &src) const override
+ {
return src.adjusted(-10, -10, 10, 10);
}
- void draw(QPainter *) {
+ void draw(QPainter *) override
+ {
pix = source()->pixmap(coordinateMode, &offset, padMode);
}
diff --git a/tests/auto/widgets/graphicsview/qgraphicsgridlayout/CMakeLists.txt b/tests/auto/widgets/graphicsview/qgraphicsgridlayout/CMakeLists.txt
index 778f30d7bf..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:
#####################################################################
-qt_add_test(tst_qgraphicsgridlayout
+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/qgraphicsgridlayout.pro b/tests/auto/widgets/graphicsview/qgraphicsgridlayout/qgraphicsgridlayout.pro
deleted file mode 100644
index e49139a8ad..0000000000
--- a/tests/auto/widgets/graphicsview/qgraphicsgridlayout/qgraphicsgridlayout.pro
+++ /dev/null
@@ -1,5 +0,0 @@
-CONFIG += testcase
-TARGET = tst_qgraphicsgridlayout
-
-QT += widgets testlib
-SOURCES += tst_qgraphicsgridlayout.cpp
diff --git a/tests/auto/widgets/graphicsview/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp b/tests/auto/widgets/graphicsview/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp
index 4d5857c3c8..c91a0803ee 100644
--- a/tests/auto/widgets/graphicsview/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp
+++ b/tests/auto/widgets/graphicsview/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp
@@ -1,33 +1,8 @@
-/****************************************************************************
-**
-** 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$
-**
-****************************************************************************/
-
-
-#include <QtTest/QtTest>
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+
+#include <QTest>
#include <qgraphicsgridlayout.h>
#include <qgraphicswidget.h>
#include <qgraphicsscene.h>
@@ -119,9 +94,9 @@ private slots:
class RectWidget : public QGraphicsWidget
{
public:
- RectWidget(QGraphicsItem *parent = 0) : QGraphicsWidget(parent), m_fnConstraint(0) {}
+ RectWidget(QGraphicsItem *parent = nullptr) : QGraphicsWidget(parent), m_fnConstraint(0) {}
- 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);
@@ -130,7 +105,7 @@ public:
painter->drawLine(rect().bottomLeft(), rect().topRight());
}
- QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const
+ QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const override
{
if (constraint.width() < 0 && constraint.height() < 0 && m_sizeHints[which].isValid()) {
return m_sizeHints[which];
@@ -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));
}
@@ -3181,7 +3156,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 013315c9b2..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:
#####################################################################
-qt_add_test(tst_qgraphicsitem
+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
@@ -21,7 +28,7 @@ qt_add_test(tst_qgraphicsitem
## Scopes:
#####################################################################
-qt_extend_target(tst_qgraphicsitem CONDITION WIN32
- PUBLIC_LIBRARIES
+qt_internal_extend_target(tst_qgraphicsitem CONDITION WIN32
+ LIBRARIES
user32
)
diff --git a/tests/auto/widgets/graphicsview/qgraphicsitem/qgraphicsitem.pro b/tests/auto/widgets/graphicsview/qgraphicsitem/qgraphicsitem.pro
deleted file mode 100644
index 7c95972222..0000000000
--- a/tests/auto/widgets/graphicsview/qgraphicsitem/qgraphicsitem.pro
+++ /dev/null
@@ -1,8 +0,0 @@
-CONFIG += testcase
-TARGET = tst_qgraphicsitem
-QT += widgets widgets-private testlib testlib-private
-QT += core-private gui-private
-SOURCES += tst_qgraphicsitem.cpp
-DEFINES += QT_NO_CAST_TO_ASCII
-
-win32: QMAKE_USE += user32
diff --git a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp
index aa08f1c44d..35356adcfc 100644
--- a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp
+++ b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp
@@ -1,33 +1,8 @@
-/****************************************************************************
-**
-** 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$
-**
-****************************************************************************/
-
-
-#include <QtTest/QtTest>
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+
+#include <QTest>
#include <QtTest/private/qtesthelpers_p.h>
#include <private/qgraphicsitem_p.h>
@@ -60,6 +35,12 @@
#include <float.h>
#include <QStyleHints>
#include <QPainterPath>
+#include <QSignalSpy>
+#include <QTimer>
+
+#include <QtGui/private/qeventpoint_p.h>
+
+#include <QtWidgets/private/qapplication_p.h>
using AbstractGraphicsShapeItemPtr = QSharedPointer<QAbstractGraphicsShapeItem>;
using GraphicsItems = QList<QGraphicsItem *>;
@@ -72,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");
@@ -286,9 +267,6 @@ class tst_QGraphicsItem : public QObject
{
Q_OBJECT
-public:
- static void initMain();
-
private slots:
void cleanup();
void construction();
@@ -494,14 +472,6 @@ private:
QPointingDevice *m_touchDevice = QTest::createTouchDevice();
};
-void tst_QGraphicsItem::initMain()
-{
-#ifdef Q_OS_WIN
- // Ensure minimum size constraints of framed windows on High DPI screens
- QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
-#endif
-}
-
void tst_QGraphicsItem::cleanup()
{
QVERIFY(QApplication::topLevelWidgets().isEmpty());
@@ -1023,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));
@@ -1080,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));
{
@@ -2238,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();
@@ -2246,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);
@@ -3406,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()));
@@ -3633,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);
}
@@ -4976,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));
@@ -5369,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
@@ -5596,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);
@@ -5712,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;
@@ -6940,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);
@@ -7297,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());
@@ -7331,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
@@ -7515,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
@@ -7979,7 +7949,6 @@ public:
} else {
QVERIFY(option->exposedRect != QRect());
QVERIFY(option->exposedRect != boundingRect());
- QCOMPARE(option->matrix, sceneTransform());
}
}
QGraphicsRectItem::paint(painter, option, widget);
@@ -8177,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();
@@ -8249,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();
@@ -8283,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));
@@ -9303,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));
}
@@ -9701,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);
@@ -10781,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();
@@ -10835,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();
@@ -10950,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());
@@ -11001,11 +10977,11 @@ protected:
{
switch (ev->type()) {
case QEvent::TouchBegin:
- m_touchBeginPoints.append(static_cast<const QTouchEvent *>(ev)->touchPoints().constFirst());
+ m_touchBeginPoints.append(static_cast<const QTouchEvent *>(ev)->points().constFirst());
ev->accept();
return true;
case QEvent::TouchUpdate:
- m_touchUpdatePoints.append(static_cast<const QTouchEvent *>(ev)->touchPoints().constFirst());
+ m_touchUpdatePoints.append(static_cast<const QTouchEvent *>(ev)->points().constFirst());
ev->accept();
return true;
default:
@@ -11027,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;
}
@@ -11355,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));
@@ -11409,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();
@@ -11445,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
@@ -11462,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));
@@ -11603,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
@@ -11637,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);
}
@@ -11668,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);
}
@@ -11718,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 63adc2ea78..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:
#####################################################################
-qt_add_test(tst_qgraphicsitemanimation
+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/qgraphicsitemanimation.pro b/tests/auto/widgets/graphicsview/qgraphicsitemanimation/qgraphicsitemanimation.pro
deleted file mode 100644
index 3515d259d0..0000000000
--- a/tests/auto/widgets/graphicsview/qgraphicsitemanimation/qgraphicsitemanimation.pro
+++ /dev/null
@@ -1,6 +0,0 @@
-CONFIG += testcase
-TARGET = tst_qgraphicsitemanimation
-QT += widgets testlib
-SOURCES += tst_qgraphicsitemanimation.cpp
-DEFINES += QT_NO_CAST_TO_ASCII
-
diff --git a/tests/auto/widgets/graphicsview/qgraphicsitemanimation/tst_qgraphicsitemanimation.cpp b/tests/auto/widgets/graphicsview/qgraphicsitemanimation/tst_qgraphicsitemanimation.cpp
index 0d8e5b4d54..9cf74c23fe 100644
--- a/tests/auto/widgets/graphicsview/qgraphicsitemanimation/tst_qgraphicsitemanimation.cpp
+++ b/tests/auto/widgets/graphicsview/qgraphicsitemanimation/tst_qgraphicsitemanimation.cpp
@@ -1,33 +1,8 @@
-/****************************************************************************
-**
-** 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$
-**
-****************************************************************************/
-
-
-#include <QtTest/QtTest>
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+
+#include <QTest>
#include <qgraphicsitemanimation.h>
#include <QtCore/qtimeline.h>
diff --git a/tests/auto/widgets/graphicsview/qgraphicslayout/CMakeLists.txt b/tests/auto/widgets/graphicsview/qgraphicslayout/CMakeLists.txt
index f11bcfe0a1..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:
#####################################################################
-qt_add_test(tst_qgraphicslayout
+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/qgraphicslayout.pro b/tests/auto/widgets/graphicsview/qgraphicslayout/qgraphicslayout.pro
deleted file mode 100644
index 1be43692d5..0000000000
--- a/tests/auto/widgets/graphicsview/qgraphicslayout/qgraphicslayout.pro
+++ /dev/null
@@ -1,9 +0,0 @@
-############################################################
-# Project file for autotest for file qlayout.h
-############################################################
-
-CONFIG += testcase
-TARGET = tst_qgraphicslayout
-QT += widgets testlib
-SOURCES += tst_qgraphicslayout.cpp
-DEFINES += QT_USE_USING_NAMESPACE
diff --git a/tests/auto/widgets/graphicsview/qgraphicslayout/tst_qgraphicslayout.cpp b/tests/auto/widgets/graphicsview/qgraphicslayout/tst_qgraphicslayout.cpp
index c5009e9847..268195d7d3 100644
--- a/tests/auto/widgets/graphicsview/qgraphicslayout/tst_qgraphicslayout.cpp
+++ b/tests/auto/widgets/graphicsview/qgraphicslayout/tst_qgraphicslayout.cpp
@@ -1,33 +1,8 @@
-/****************************************************************************
-**
-** 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$
-**
-****************************************************************************/
-
-
-#include <QtTest/QtTest>
+// 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 <math.h>
@@ -90,10 +65,11 @@ enum FunctionType {
class TestGraphicsWidget : public QGraphicsWidget {
public:
- TestGraphicsWidget(QGraphicsWidget *parent = 0) : QGraphicsWidget(parent)
+ TestGraphicsWidget(QGraphicsWidget *parent = nullptr) : QGraphicsWidget(parent)
{ }
- bool event(QEvent *e) {
+ bool event(QEvent *e) override
+ {
++(m_eventCount[int(e->type())]);
return QGraphicsWidget::event(e);
}
@@ -111,7 +87,7 @@ public:
functionCount.clear();
}
- void setGeometry(const QRectF &rect)
+ void setGeometry(const QRectF &rect) override
{
QGraphicsWidget::setGeometry(rect);
++(functionCount[SetGeometry]);
@@ -228,20 +204,20 @@ void tst_QGraphicsLayout::automaticReparenting()
class TestLayout : public QGraphicsLinearLayout
{
public:
- TestLayout(QGraphicsLayoutItem *parent = 0)
+ TestLayout(QGraphicsLayoutItem *parent = nullptr)
: QGraphicsLinearLayout(parent)
{
setContentsMargins(0,0,0,0);
setSpacing(0);
}
- void setGeometry(const QRectF &rect)
+ void setGeometry(const QRectF &rect) override
{
++(functionCount[SetGeometry]);
QGraphicsLinearLayout::setGeometry(rect);
}
- void invalidate()
+ void invalidate() override
{
++(functionCount[Invalidate]);
QGraphicsLinearLayout::invalidate();
@@ -569,27 +545,29 @@ class Layout : public QGraphicsLayout
public:
Layout(QGraphicsLayoutItem *parentItem = 0) : QGraphicsLayout(parentItem) {}
- void setGeometry(const QRectF &rect)
+ void setGeometry(const QRectF &rect) override
{
QGraphicsLayout::setGeometry(rect);
}
- int count() const {
+ int count() const override
+ {
return 0;
}
- QGraphicsLayoutItem *itemAt(int index) const {
+ QGraphicsLayoutItem *itemAt(int index) const override
+ {
Q_UNUSED(index);
return 0;
}
- void removeAt(int index)
+ void removeAt(int index) override
{
Q_UNUSED(index);
}
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);
Q_UNUSED(which);
@@ -634,9 +612,9 @@ public:
setGraphicsItem(item);
}
- void setGeometry(const QRectF &geom);
+ void setGeometry(const QRectF &geom) override;
- QSizeF sizeHint(Qt::SizeHint which, const QSizeF & constraint = QSizeF() ) const;
+ QSizeF sizeHint(Qt::SizeHint which, const QSizeF & constraint = QSizeF() ) const override;
inline QGraphicsRectItem *rectItem() {
return static_cast<QGraphicsRectItem *>(graphicsItem());
@@ -674,7 +652,8 @@ public:
connect(&m_timeline, SIGNAL(valueChanged(qreal)), this, SLOT(valueChanged(qreal)));
}
- void setGeometry(const QRectF &geom) {
+ void setGeometry(const QRectF &geom) override
+ {
fromGeoms.clear();
toGeoms.clear();
for (int i = 0; i < count(); ++i) {
@@ -691,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);
@@ -759,7 +738,7 @@ public:
setOwnedByLayout(true);
}
- QSizeF sizeHint(Qt::SizeHint which, const QSizeF & constraint = QSizeF() ) const;
+ QSizeF sizeHint(Qt::SizeHint which, const QSizeF & constraint = QSizeF() ) const override;
~CustomLayoutItem() {
m_destructedSet->insert(this);
@@ -790,9 +769,9 @@ public:
m_destructedSet = destructedSet;
}
- QSizeF sizeHint(Qt::SizeHint which, const QSizeF & constraint = QSizeF() ) const;
+ QSizeF sizeHint(Qt::SizeHint which, const QSizeF & constraint = QSizeF() ) const override;
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget * = 0)
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget * = 0) override
{
const QRect r = option->rect.adjusted(0, 0, -1, -1);
painter->drawLine(r.topLeft(), r.bottomRight());
@@ -844,30 +823,30 @@ CustomLayout(QGraphicsLayoutItem *parent)
{
}
-int count() const
+int count() const override
{
- return items.count();
+ return items.size();
}
-QGraphicsLayoutItem* itemAt(int index) const
+QGraphicsLayoutItem* itemAt(int index) const override
{
return items.at(index);
}
-void removeAt(int index)
+void removeAt(int index) override
{
items.removeAt(index);
}
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);
@@ -875,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);
@@ -897,7 +876,7 @@ void updateParentWidget(QGraphicsWidget *item)
}
}
-QSizeF sizeHint(Qt::SizeHint /* which */, const QSizeF & /* constraint */) const
+QSizeF sizeHint(Qt::SizeHint /* which */, const QSizeF & /* constraint */) const override
{
return QSizeF(50,50);
}
@@ -943,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 36d7177f22..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:
#####################################################################
-qt_add_test(tst_qgraphicslayoutitem
+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/qgraphicslayoutitem.pro b/tests/auto/widgets/graphicsview/qgraphicslayoutitem/qgraphicslayoutitem.pro
deleted file mode 100644
index e4a970201a..0000000000
--- a/tests/auto/widgets/graphicsview/qgraphicslayoutitem/qgraphicslayoutitem.pro
+++ /dev/null
@@ -1,5 +0,0 @@
-CONFIG += testcase
-TARGET = tst_qgraphicslayoutitem
-QT += widgets testlib
-SOURCES += tst_qgraphicslayoutitem.cpp
-
diff --git a/tests/auto/widgets/graphicsview/qgraphicslayoutitem/tst_qgraphicslayoutitem.cpp b/tests/auto/widgets/graphicsview/qgraphicslayoutitem/tst_qgraphicslayoutitem.cpp
index af21b9f391..87b703a286 100644
--- a/tests/auto/widgets/graphicsview/qgraphicslayoutitem/tst_qgraphicslayoutitem.cpp
+++ b/tests/auto/widgets/graphicsview/qgraphicslayoutitem/tst_qgraphicslayoutitem.cpp
@@ -1,33 +1,8 @@
-/****************************************************************************
-**
-** 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$
-**
-****************************************************************************/
-
-
-#include <QtTest/QtTest>
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+
+#include <QTest>
#include <qgraphicslayoutitem.h>
#include <float.h>
#include <limits.h>
@@ -72,13 +47,13 @@ public:
{ return QRectF(); }
// QGraphicsLayoutItem::setGeometry is a pure virtual function
- void setGeometry(QRectF const&) {}
+ void setGeometry(QRectF const&) override {}
// QGraphicsLayoutItem::sizeHint is a pure virtual function
- QSizeF sizeHint(Qt::SizeHint, QSizeF const& = QSizeF()) const
+ QSizeF sizeHint(Qt::SizeHint, QSizeF const& = QSizeF()) const override
{ return QSizeF(); }
- void updateGeometry()
+ void updateGeometry() override
{ updateGeometryCalled++; QGraphicsLayoutItem::updateGeometry(); }
int updateGeometryCalled;
diff --git a/tests/auto/widgets/graphicsview/qgraphicslinearlayout/CMakeLists.txt b/tests/auto/widgets/graphicsview/qgraphicslinearlayout/CMakeLists.txt
index 96dbadc4b9..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:
#####################################################################
-qt_add_test(tst_qgraphicslinearlayout
+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/qgraphicslinearlayout.pro b/tests/auto/widgets/graphicsview/qgraphicslinearlayout/qgraphicslinearlayout.pro
deleted file mode 100644
index 2bf1a1d676..0000000000
--- a/tests/auto/widgets/graphicsview/qgraphicslinearlayout/qgraphicslinearlayout.pro
+++ /dev/null
@@ -1,4 +0,0 @@
-CONFIG += testcase
-TARGET = tst_qgraphicslinearlayout
-QT += widgets testlib
-SOURCES += tst_qgraphicslinearlayout.cpp
diff --git a/tests/auto/widgets/graphicsview/qgraphicslinearlayout/tst_qgraphicslinearlayout.cpp b/tests/auto/widgets/graphicsview/qgraphicslinearlayout/tst_qgraphicslinearlayout.cpp
index 817f67540e..65212e94cc 100644
--- a/tests/auto/widgets/graphicsview/qgraphicslinearlayout/tst_qgraphicslinearlayout.cpp
+++ b/tests/auto/widgets/graphicsview/qgraphicslinearlayout/tst_qgraphicslinearlayout.cpp
@@ -1,33 +1,8 @@
-/****************************************************************************
-**
-** 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$
-**
-****************************************************************************/
-
-
-#include <QtTest/QtTest>
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+
+#include <QTest>
#include <qgraphicslinearlayout.h>
#include <qgraphicsproxywidget.h>
#include <qgraphicswidget.h>
@@ -107,7 +82,7 @@ public:
layoutDirectionChange(0)
{ }
- void widgetEvent(QEvent *e)
+ void widgetEvent(QEvent *e) override
{
switch (e->type()) {
case QEvent::GraphicsSceneResize:
@@ -143,9 +118,9 @@ void tst_QGraphicsLinearLayout::initTestCase()
class RectWidget : public QGraphicsWidget
{
public:
- RectWidget(QGraphicsItem *parent = 0, const QBrush &brush = QBrush()) : QGraphicsWidget(parent){ m_brush = brush;}
+ RectWidget(QGraphicsItem *parent = nullptr, const QBrush &brush = QBrush()) : QGraphicsWidget(parent){ m_brush = brush;}
- 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);
@@ -158,7 +133,8 @@ public:
updateGeometry();
}
- virtual QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const {
+ virtual QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const override
+ {
if (m_sizeHints[which].isValid()) {
return m_sizeHints[which];
}
@@ -513,7 +489,7 @@ void tst_QGraphicsLinearLayout::insertItem()
for (int i = 0; i < layoutCount; ++i)
layout.addItem(new SubQGraphicsLinearLayout);
- QGraphicsLayoutItem *item = 0;
+ QGraphicsLayoutItem *item = nullptr;
if (isWidget)
item = new QGraphicsWidget;
else
@@ -570,7 +546,7 @@ void tst_QGraphicsLinearLayout::insertStretch()
scene.addItem(widget);
QList<QGraphicsWidget *>items;
- QGraphicsWidget *item = 0;
+ QGraphicsWidget *item = nullptr;
for (int i = 0; i < itemCount; ++i) {
item = new RectWidget;
item->setMinimumSize(10, 10);
@@ -747,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));
@@ -791,7 +767,7 @@ void tst_QGraphicsLinearLayout::removeAt()
layout.addItem(new SubQGraphicsLinearLayout);
QSizeF oldSizeHint = layout.sizeHint(Qt::PreferredSize, QSizeF());
- QGraphicsLayoutItem *w = 0;
+ QGraphicsLayoutItem *w = nullptr;
if (removeItemAt >= 0 && removeItemAt < layout.count())
w = layout.itemAt(removeItemAt);
if (w) {
@@ -841,7 +817,7 @@ void tst_QGraphicsLinearLayout::removeItem()
for (int i = 0; i < layoutCount; ++i)
layout.addItem(new SubQGraphicsLinearLayout);
- QGraphicsLayoutItem *w = 0;
+ QGraphicsLayoutItem *w = nullptr;
if (removeItemAt >= 0 && removeItemAt < layout.count())
w = layout.itemAt(removeItemAt);
QSizeF oldSizeHint = layout.sizeHint(Qt::PreferredSize, QSizeF());
@@ -1145,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);
@@ -1163,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);
@@ -1321,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 f999e13162..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:
#####################################################################
-qt_add_test(tst_qgraphicsobject
+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/qgraphicsobject.pro b/tests/auto/widgets/graphicsview/qgraphicsobject/qgraphicsobject.pro
deleted file mode 100644
index 483f123fa7..0000000000
--- a/tests/auto/widgets/graphicsview/qgraphicsobject/qgraphicsobject.pro
+++ /dev/null
@@ -1,7 +0,0 @@
-CONFIG += testcase
-TARGET = tst_qgraphicsobject
-
-QT += widgets testlib
-QT += core-private
-
-SOURCES += tst_qgraphicsobject.cpp
diff --git a/tests/auto/widgets/graphicsview/qgraphicsobject/tst_qgraphicsobject.cpp b/tests/auto/widgets/graphicsview/qgraphicsobject/tst_qgraphicsobject.cpp
index 6ef17a14af..674a7f73d5 100644
--- a/tests/auto/widgets/graphicsview/qgraphicsobject/tst_qgraphicsobject.cpp
+++ b/tests/auto/widgets/graphicsview/qgraphicsobject/tst_qgraphicsobject.cpp
@@ -1,33 +1,10 @@
-/****************************************************************************
-**
-** 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$
-**
-****************************************************************************/
-
-
-#include <QtTest/QtTest>
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+
+#include <QTest>
+#include <QSignalSpy>
+
#include <qgraphicsitem.h>
#include <qgraphicsscene.h>
#include <qgraphicssceneevent.h>
@@ -53,8 +30,8 @@ class MyGraphicsObject : public QGraphicsObject
{
public:
MyGraphicsObject() : QGraphicsObject() {}
- virtual QRectF boundingRect() const { return QRectF(); }
- virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) {}
+ virtual QRectF boundingRect() const override { return QRectF(); }
+ virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override {}
};
void tst_QGraphicsObject::pos()
@@ -64,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));
}
@@ -96,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));
}
@@ -119,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));
}
@@ -141,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));
}
@@ -159,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);
}
@@ -177,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());
}
@@ -195,22 +172,22 @@ 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());
}
class DeleteTester : public QGraphicsObject
{
public:
- DeleteTester(bool *w, bool *pw, QGraphicsItem *parent = 0)
+ DeleteTester(bool *w, bool *pw, QGraphicsItem *parent = nullptr)
: QGraphicsObject(parent), wasDeleted(w), parentWasDeleted(pw)
{ }
@@ -223,9 +200,9 @@ public:
}
}
- void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget * = 0)
+ void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget * = nullptr) override
{ }
- QRectF boundingRect() const
+ QRectF boundingRect() const override
{ return QRectF(); }
bool *wasDeleted;
diff --git a/tests/auto/widgets/graphicsview/qgraphicspixmapitem/CMakeLists.txt b/tests/auto/widgets/graphicsview/qgraphicspixmapitem/CMakeLists.txt
index 8cb278720b..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:
#####################################################################
-qt_add_test(tst_qgraphicspixmapitem
+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/qgraphicspixmapitem.pro b/tests/auto/widgets/graphicsview/qgraphicspixmapitem/qgraphicspixmapitem.pro
deleted file mode 100644
index 123f1050ec..0000000000
--- a/tests/auto/widgets/graphicsview/qgraphicspixmapitem/qgraphicspixmapitem.pro
+++ /dev/null
@@ -1,5 +0,0 @@
-CONFIG += testcase
-TARGET = tst_qgraphicspixmapitem
-QT += widgets testlib
-SOURCES += tst_qgraphicspixmapitem.cpp
-
diff --git a/tests/auto/widgets/graphicsview/qgraphicspixmapitem/tst_qgraphicspixmapitem.cpp b/tests/auto/widgets/graphicsview/qgraphicspixmapitem/tst_qgraphicspixmapitem.cpp
index e7bba010d9..fd8f8bd37d 100644
--- a/tests/auto/widgets/graphicsview/qgraphicspixmapitem/tst_qgraphicspixmapitem.cpp
+++ b/tests/auto/widgets/graphicsview/qgraphicspixmapitem/tst_qgraphicspixmapitem.cpp
@@ -1,33 +1,8 @@
-/****************************************************************************
-**
-** 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$
-**
-****************************************************************************/
-
-
-#include <QtTest/QtTest>
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+
+#include <QTest>
#include <qgraphicsscene.h>
#include <qgraphicsitem.h>
#include <qpainterpath.h>
@@ -74,11 +49,11 @@ public:
enum Extension {
UserExtension = QGraphicsItem::UserExtension
};
- SubQGraphicsPixmapItem(QGraphicsItem *parent = 0) : QGraphicsPixmapItem(parent)
+ SubQGraphicsPixmapItem(QGraphicsItem *parent = nullptr) : QGraphicsPixmapItem(parent)
{
}
- SubQGraphicsPixmapItem(const QPixmap &pixmap, QGraphicsItem *parent = 0) : QGraphicsPixmapItem(pixmap, parent)
+ SubQGraphicsPixmapItem(const QPixmap &pixmap, QGraphicsItem *parent = nullptr) : QGraphicsPixmapItem(pixmap, parent)
{
}
diff --git a/tests/auto/widgets/graphicsview/qgraphicspolygonitem/CMakeLists.txt b/tests/auto/widgets/graphicsview/qgraphicspolygonitem/CMakeLists.txt
index 5742353892..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:
#####################################################################
-qt_add_test(tst_qgraphicspolygonitem
+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/qgraphicspolygonitem.pro b/tests/auto/widgets/graphicsview/qgraphicspolygonitem/qgraphicspolygonitem.pro
deleted file mode 100644
index 89847e9ed2..0000000000
--- a/tests/auto/widgets/graphicsview/qgraphicspolygonitem/qgraphicspolygonitem.pro
+++ /dev/null
@@ -1,4 +0,0 @@
-CONFIG += testcase
-TARGET = tst_qgraphicspolygonitem
-QT += widgets testlib
-SOURCES += tst_qgraphicspolygonitem.cpp
diff --git a/tests/auto/widgets/graphicsview/qgraphicspolygonitem/tst_qgraphicspolygonitem.cpp b/tests/auto/widgets/graphicsview/qgraphicspolygonitem/tst_qgraphicspolygonitem.cpp
index 5380dd0daf..9412fab0ee 100644
--- a/tests/auto/widgets/graphicsview/qgraphicspolygonitem/tst_qgraphicspolygonitem.cpp
+++ b/tests/auto/widgets/graphicsview/qgraphicspolygonitem/tst_qgraphicspolygonitem.cpp
@@ -1,33 +1,8 @@
-/****************************************************************************
-**
-** 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$
-**
-****************************************************************************/
-
-
-#include <QtTest/QtTest>
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+
+#include <QTest>
#include <qgraphicsitem.h>
#include <qpainterpath.h>
#include <qpen.h>
@@ -70,11 +45,11 @@ public:
UserExtension = QGraphicsItem::UserExtension
};
- SubQGraphicsPolygonItem(QGraphicsItem *parent = 0) : QGraphicsPolygonItem(parent)
+ SubQGraphicsPolygonItem(QGraphicsItem *parent = nullptr) : QGraphicsPolygonItem(parent)
{
}
- SubQGraphicsPolygonItem(const QPolygonF &polygon, QGraphicsItem *parent = 0) : QGraphicsPolygonItem(polygon, parent)
+ SubQGraphicsPolygonItem(const QPolygonF &polygon, QGraphicsItem *parent = nullptr) : QGraphicsPolygonItem(polygon, parent)
{
}
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 67509dae98..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:
#####################################################################
-qt_add_test(tst_qgraphicsproxywidget
+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/qgraphicsproxywidget.pro b/tests/auto/widgets/graphicsview/qgraphicsproxywidget/qgraphicsproxywidget.pro
deleted file mode 100644
index c10cbe1b1a..0000000000
--- a/tests/auto/widgets/graphicsview/qgraphicsproxywidget/qgraphicsproxywidget.pro
+++ /dev/null
@@ -1,9 +0,0 @@
-CONFIG += testcase
-TARGET = tst_qgraphicsproxywidget
-
-QT += widgets widgets-private testlib
-QT += core-private gui-private
-
-DEFINES += QTEST_QPA_MOUSE_HANDLING
-SOURCES += tst_qgraphicsproxywidget.cpp
-
diff --git a/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp b/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp
index ebf340db2a..4b047db344 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$
-**
-****************************************************************************/
-
-
-#include <QtTest/QtTest>
+// 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 = 0) : 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); }
+ using QGraphicsProxyWidget::QGraphicsProxyWidget;
- void call_mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event)
- { return SubQGraphicsProxyWidget::mouseDoubleClickEvent(event); }
-
- void call_mouseMoveEvent(QGraphicsSceneMouseEvent* event)
- { return SubQGraphicsProxyWidget::mouseMoveEvent(event); }
-
- 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 = 0) {
+ 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(QEvent *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);
-
- QTRY_COMPARE(widget->selectedText(), hasWidget ? QString("foo") : QString());
+ QTest::mousePress(view.viewport(), Qt::LeftButton, {}, pointInLineEdit);
+ QTest::mouseRelease(view.viewport(), Qt::LeftButton, {}, pointInLineEdit);
+ QTest::mouseDClick(view.viewport(), Qt::LeftButton, {}, pointInLineEdit);
- 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));
}
@@ -1482,13 +1269,13 @@ void tst_QGraphicsProxyWidget::maximumSize()
class View : public QGraphicsView
{
public:
- View(QGraphicsScene *scene, QWidget *parent = 0)
+ View(QGraphicsScene *scene, QWidget *parent = nullptr)
: QGraphicsView(scene, parent), npaints(0)
{ }
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 &region)
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,7 @@ void tst_QGraphicsProxyWidget::tabFocus_simpleWidget()
window.setLayout(layout);
window.show();
- QApplication::setActiveWindow(&window);
+ QApplicationPrivate::setActiveWindow(&window);
window.activateWindow();
QVERIFY(QTest::qWaitForWindowActive(&window));
@@ -1832,7 +1622,7 @@ void tst_QGraphicsProxyWidget::tabFocus_simpleTwoWidgets()
window.setLayout(layout);
window.show();
- QApplication::setActiveWindow(&window);
+ QApplicationPrivate::setActiveWindow(&window);
window.activateWindow();
QVERIFY(QTest::qWaitForWindowActive(&window));
@@ -1965,7 +1755,7 @@ void tst_QGraphicsProxyWidget::tabFocus_complexWidget()
window.setLayout(layout);
window.show();
- QApplication::setActiveWindow(&window);
+ QApplicationPrivate::setActiveWindow(&window);
window.activateWindow();
QVERIFY(QTest::qWaitForWindowActive(&window));
@@ -2102,7 +1892,7 @@ void tst_QGraphicsProxyWidget::tabFocus_complexTwoWidgets()
window.setLayout(layout);
window.show();
- QApplication::setActiveWindow(&window);
+ QApplicationPrivate::setActiveWindow(&window);
window.activateWindow();
QVERIFY(QTest::qWaitForWindowActive(&window));
@@ -2276,7 +2066,7 @@ void tst_QGraphicsProxyWidget::setFocus_simpleWidget()
window.setLayout(layout);
window.show();
- QApplication::setActiveWindow(&window);
+ QApplicationPrivate::setActiveWindow(&window);
window.activateWindow();
QVERIFY(QTest::qWaitForWindowActive(&window));
QCOMPARE(QApplication::activeWindow(), &window);
@@ -2348,7 +2138,7 @@ void tst_QGraphicsProxyWidget::setFocus_simpleTwoWidgets()
window.setLayout(layout);
window.show();
- QApplication::setActiveWindow(&window);
+ QApplicationPrivate::setActiveWindow(&window);
window.activateWindow();
QVERIFY(QTest::qWaitForWindowActive(&window));
QCOMPARE(QApplication::activeWindow(), &window);
@@ -2427,7 +2217,7 @@ void tst_QGraphicsProxyWidget::setFocus_complexTwoWidgets()
window.setLayout(layout);
window.show();
- QApplication::setActiveWindow(&window);
+ QApplicationPrivate::setActiveWindow(&window);
window.activateWindow();
QVERIFY(QTest::qWaitForWindowActive(&window));
QCOMPARE(QApplication::activeWindow(), &window);
@@ -2500,28 +2290,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 +2321,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 +2401,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 +2462,7 @@ void tst_QGraphicsProxyWidget::tooltip_basic()
QGraphicsView view(&scene);
view.setFixedSize(200, 200);
view.show();
- QApplication::setActiveWindow(&view);
+ QApplicationPrivate::setActiveWindow(&view);
QVERIFY(QTest::qWaitForWindowActive(&view));
{
QHelpEvent helpEvent(QEvent::ToolTip, view.viewport()->rect().topLeft(),
@@ -2681,7 +2472,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 +2525,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 = 0;
- 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 +2600,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 +2612,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 +2706,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 +2898,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 +2931,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 +2943,7 @@ protected:
}
return QWidget::event(event);
}
- void contextMenuEvent(QContextMenuEvent *)
+ void contextMenuEvent(QContextMenuEvent *) override
{
gotContextMenuEvent = true;
}
@@ -3212,7 +2998,7 @@ void tst_QGraphicsProxyWidget::actionsContextMenu()
view.resize(200, 200);
view.move(QGuiApplication::primaryScreen()->geometry().center() - QPoint(100, 100));
view.show();
- QApplication::setActiveWindow(&view);
+ QApplicationPrivate::setActiveWindow(&view);
QVERIFY(QTest::qWaitForWindowActive(&view));
view.setFocus();
QTRY_VERIFY(view.hasFocus());
@@ -3282,17 +3068,22 @@ 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;
QGraphicsView view(&scene);
view.show();
+ QApplicationPrivate::setActiveWindow(&view);
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 +3103,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 +3110,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 +3272,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 +3284,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 +3346,7 @@ void tst_QGraphicsProxyWidget::clickFocus()
view.setFrameStyle(0);
view.resize(300, 300);
view.show();
- QApplication::setActiveWindow(&view);
+ QApplicationPrivate::setActiveWindow(&view);
QVERIFY(QTest::qWaitForWindowActive(&view));
QVERIFY(!proxy->hasFocus());
@@ -3568,7 +3360,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 +3418,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 +3427,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 +3439,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 +3459,51 @@ void tst_QGraphicsProxyWidget::windowFrameMargins()
QVERIFY(top > 0);
}
-class HoverButton : public QPushButton
+void tst_QGraphicsProxyWidget::QTBUG_6986_sendMouseEventToAlienWidget()
{
-public:
- HoverButton(QWidget *parent = 0) : 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);
+ QApplicationPrivate::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 +3534,7 @@ 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);
+ QApplicationPrivate::setActiveWindow(&view);
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
const QPoint embeddedCenter = embeddedWidget->rect().center();
@@ -3766,8 +3542,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 +3554,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());
}
@@ -3830,9 +3607,9 @@ void tst_QGraphicsProxyWidget::QTBUG_43780_visibility()
class TouchWidget : public QWidget
{
public:
- TouchWidget(QWidget *parent = 0) : QWidget(parent) {}
+ TouchWidget(QWidget *parent = nullptr) : QWidget(parent) {}
- bool event(QEvent *event)
+ bool event(QEvent *event) override
{
switch (event->type()) {
case QEvent::TouchBegin:
@@ -3840,7 +3617,6 @@ public:
case QEvent::TouchEnd:
event->accept();
return true;
- break;
default:
break;
}
@@ -3849,48 +3625,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 3208cf2b36..c0dd8995b8 100644
--- a/tests/auto/widgets/graphicsview/qgraphicsscene/CMakeLists.txt
+++ b/tests/auto/widgets/graphicsview/qgraphicsscene/CMakeLists.txt
@@ -1,35 +1,20 @@
-# Generated from qgraphicsscene.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qgraphicsscene Test:
#####################################################################
-qt_add_test(tst_qgraphicsscene
- 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_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"
@@ -60,18 +45,26 @@ set(testdata_resource_files
"testData/render/topright-topleft-untransformed.png"
)
-qt_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_extend_target(tst_qgraphicsscene CONDITION WIN32
- PUBLIC_LIBRARIES
+qt_internal_extend_target(tst_qgraphicsscene CONDITION WIN32
+ LIBRARIES
user32
)
diff --git a/tests/auto/widgets/graphicsview/qgraphicsscene/qgraphicsscene.pro b/tests/auto/widgets/graphicsview/qgraphicsscene/qgraphicsscene.pro
deleted file mode 100644
index fe8e83ee0a..0000000000
--- a/tests/auto/widgets/graphicsview/qgraphicsscene/qgraphicsscene.pro
+++ /dev/null
@@ -1,12 +0,0 @@
-CONFIG += testcase
-TARGET = tst_qgraphicsscene
-QT += widgets widgets-private testlib
-QT += core-private gui-private
-SOURCES += tst_qgraphicsscene.cpp
-RESOURCES += images.qrc
-win32: QMAKE_USE += user32
-
-DEFINES += SRCDIR=\\\"$$PWD\\\"
-DEFINES += QT_NO_CAST_TO_ASCII
-
-RESOURCES += testdata.qrc
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 5ecb401284..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>
@@ -40,7 +15,11 @@
#include <QtGui/QPainterPath>
#include <QtGui/QScreen>
-#include <QtTest/QtTest>
+#include <QTest>
+#include <QTestEventLoop>
+#include <QRandomGenerator>
+#include <QSignalSpy>
+#include <QMimeData>
#include <QtCore/QDebug>
#include <QtCore/QLoggingCategory>
@@ -52,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 \
@@ -122,7 +103,7 @@ public:
bool isHovered = false;
protected:
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *)
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *) override
{
isHovered = (option->state & QStyle::State_MouseOver);
@@ -185,7 +166,6 @@ class tst_QGraphicsScene : public QObject
Q_OBJECT
public:
tst_QGraphicsScene();
- static void initMain() { QCoreApplication::setAttribute(Qt::AA_DisableHighDpiScaling); }
public slots:
void cleanup();
@@ -275,6 +255,7 @@ private slots:
void focusItemChangedSignal();
void minimumRenderSize();
void focusOnTouch();
+ void clearSelection();
// task specific tests below me
void task139710_bspTreeCrash();
@@ -289,6 +270,9 @@ private slots:
void taskQTBUG_15977_renderWithDeviceCoordinateCache();
void taskQTBUG_16401_focusItem();
void taskQTBUG_42915_focusNextPrevChild();
+ void taskQTBUG_85088_previewTextfailWhenLostFocus();
+
+ void deleteItemsOnChange();
private:
QRect m_availableGeometry = QGuiApplication::primaryScreen()->availableGeometry();
@@ -337,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);
@@ -365,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());
}
@@ -550,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);
@@ -615,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());
@@ -962,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));
@@ -999,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()
@@ -1038,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));
@@ -1053,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));
@@ -1068,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));
@@ -1078,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));
@@ -1087,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()
@@ -1214,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());
}
@@ -1310,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);
@@ -1618,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));
@@ -1688,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);
@@ -1750,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);
@@ -1766,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
@@ -1790,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
@@ -1800,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
@@ -2191,7 +2172,7 @@ public:
bool ignoresDragMove = false;
protected:
- void dragEnterEvent(QGraphicsSceneDragDropEvent *event)
+ void dragEnterEvent(QGraphicsSceneDragDropEvent *event) override
{
storeLastEvent(event);
event->setAccepted(!ignoresDragEnter);
@@ -2200,20 +2181,20 @@ protected:
eventList << event->type();
}
- void dragMoveEvent(QGraphicsSceneDragDropEvent *event)
+ void dragMoveEvent(QGraphicsSceneDragDropEvent *event) override
{
storeLastEvent(event);
event->setAccepted(!ignoresDragMove);
eventList << event->type();
}
- void dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
+ void dragLeaveEvent(QGraphicsSceneDragDropEvent *event) override
{
storeLastEvent(event);
eventList << event->type();
}
- void dropEvent(QGraphicsSceneDragDropEvent *event)
+ void dropEvent(QGraphicsSceneDragDropEvent *event) override
{
storeLastEvent(event);
eventList << event->type();
@@ -2281,8 +2262,8 @@ void tst_QGraphicsScene::dragAndDrop_simple()
QCOMPARE(item->eventList.size(), 2);
QCOMPARE(item->eventList.at(0), QEvent::GraphicsSceneDragEnter);
QCOMPARE(item->eventList.at(1), QEvent::GraphicsSceneDragMove);
- QCOMPARE(item->lastEvent->screenPos(), view.mapToGlobal(dragMove.pos()));
- QCOMPARE(item->lastEvent->scenePos(), view.mapToScene(dragMove.pos()));
+ QCOMPARE(item->lastEvent->screenPos(), view.mapToGlobal(dragMove.position().toPoint()));
+ QCOMPARE(item->lastEvent->scenePos(), view.mapToScene(dragMove.position().toPoint()));
QVERIFY(item->lastEvent->isAccepted());
QCOMPARE(item->lastEvent->dropAction(), Qt::IgnoreAction);
}
@@ -2294,8 +2275,8 @@ void tst_QGraphicsScene::dragAndDrop_simple()
QCOMPARE(dragMove.dropAction(), Qt::IgnoreAction);
QCOMPARE(item->eventList.size(), 3);
QCOMPARE(item->eventList.at(2), QEvent::GraphicsSceneDragMove);
- QCOMPARE(item->lastEvent->screenPos(), view.mapToGlobal(dragMove.pos()));
- QCOMPARE(item->lastEvent->scenePos(), view.mapToScene(dragMove.pos()));
+ QCOMPARE(item->lastEvent->screenPos(), view.mapToGlobal(dragMove.position().toPoint()));
+ QCOMPARE(item->lastEvent->scenePos(), view.mapToScene(dragMove.position().toPoint()));
QVERIFY(item->lastEvent->isAccepted());
QCOMPARE(item->lastEvent->dropAction(), Qt::IgnoreAction);
}
@@ -2307,8 +2288,8 @@ void tst_QGraphicsScene::dragAndDrop_simple()
QCOMPARE(dragMove.dropAction(), Qt::CopyAction);
QCOMPARE(item->eventList.size(), 4);
QCOMPARE(item->eventList.at(3), QEvent::GraphicsSceneDragLeave);
- QCOMPARE(item->lastEvent->screenPos(), view.mapToGlobal(dragMove.pos()));
- QCOMPARE(item->lastEvent->scenePos(), view.mapToScene(dragMove.pos()));
+ QCOMPARE(item->lastEvent->screenPos(), view.mapToGlobal(dragMove.position().toPoint()));
+ QCOMPARE(item->lastEvent->scenePos(), view.mapToScene(dragMove.position().toPoint()));
QVERIFY(item->lastEvent->isAccepted());
QCOMPARE(item->lastEvent->dropAction(), Qt::CopyAction);
}
@@ -2321,8 +2302,8 @@ void tst_QGraphicsScene::dragAndDrop_simple()
QCOMPARE(item->eventList.size(), 6);
QCOMPARE(item->eventList.at(4), QEvent::GraphicsSceneDragEnter);
QCOMPARE(item->eventList.at(5), QEvent::GraphicsSceneDragMove);
- QCOMPARE(item->lastEvent->screenPos(), view.mapToGlobal(dragMove.pos()));
- QCOMPARE(item->lastEvent->scenePos(), view.mapToScene(dragMove.pos()));
+ QCOMPARE(item->lastEvent->screenPos(), view.mapToGlobal(dragMove.position().toPoint()));
+ QCOMPARE(item->lastEvent->scenePos(), view.mapToScene(dragMove.position().toPoint()));
QVERIFY(item->lastEvent->isAccepted());
QCOMPARE(item->lastEvent->dropAction(), Qt::IgnoreAction);
}
@@ -2334,8 +2315,8 @@ void tst_QGraphicsScene::dragAndDrop_simple()
QCOMPARE(drop.dropAction(), Qt::CopyAction);
QCOMPARE(item->eventList.size(), 7);
QCOMPARE(item->eventList.at(6), QEvent::GraphicsSceneDrop);
- QCOMPARE(item->lastEvent->screenPos(), view.mapToGlobal(drop.pos()));
- QCOMPARE(item->lastEvent->scenePos(), view.mapToScene(drop.pos()));
+ QCOMPARE(item->lastEvent->screenPos(), view.mapToGlobal(drop.position().toPoint()));
+ QCOMPARE(item->lastEvent->scenePos(), view.mapToScene(drop.position().toPoint()));
QVERIFY(item->lastEvent->isAccepted());
QCOMPARE(item->lastEvent->dropAction(), Qt::CopyAction);
}
@@ -2693,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.
@@ -2773,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
@@ -2850,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)
@@ -2867,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;
@@ -3057,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));
@@ -3109,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));
@@ -3163,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());
@@ -3247,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));
@@ -3286,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());
@@ -3335,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));
@@ -3420,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());
@@ -3549,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()
@@ -3680,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());
}
}
@@ -3694,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());
}
}
@@ -3838,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);
@@ -3868,7 +3848,7 @@ void tst_QGraphicsScene::inputMethod()
item->eventCalls = 0;
QCoreApplication::sendEvent(&scene, &event);
- QCOMPARE(item->eventCalls, 0);
+ QCOMPARE(item->eventCalls, callFocusItem ? 1 : 0);
item->queryCalls = 0;
scene.inputMethodQuery(Qt::InputMethodQuery(0));
@@ -4043,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);
@@ -4054,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());
@@ -4083,7 +4062,6 @@ void tst_QGraphicsScene::isActive()
view1->setVisible(false);
toplevel1.show();
- QApplication::setActiveWindow(&toplevel1);
QVERIFY(QTest::qWaitForWindowActive(&toplevel1));
QCOMPARE(QApplication::activeWindow(), &toplevel1);
@@ -4112,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);
@@ -4152,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);
@@ -4202,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);
@@ -4230,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());
@@ -4260,7 +4238,6 @@ void tst_QGraphicsScene::isActive()
toplevel3.show();
- QApplication::setActiveWindow(&toplevel3);
QVERIFY(QTest::qWaitForWindowActive(&toplevel3));
QCOMPARE(QApplication::activeWindow(), &toplevel3);
@@ -4373,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
@@ -4623,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()
@@ -4640,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;
@@ -4658,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);
@@ -4667,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);
@@ -4675,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);
@@ -4704,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);
@@ -4723,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);
@@ -4735,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);
@@ -4831,7 +4807,6 @@ void tst_QGraphicsScene::focusOnTouch()
rect->setFlag(QGraphicsItem::ItemIsFocusable, true);
view.show();
- QApplication::setActiveWindow(&view);
QVERIFY(QTest::qWaitForWindowActive(&view));
QVERIFY(!rect->hasFocus());
@@ -4854,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;
@@ -4885,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());
@@ -4927,11 +4948,111 @@ 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);
}
+void tst_QGraphicsScene::taskQTBUG_85088_previewTextfailWhenLostFocus()
+{
+ QString str = "simpleTextItem";
+ QGraphicsScene scene;
+ QGraphicsView view(&scene);
+
+ QGraphicsTextItem *simpleTextItem = new QGraphicsTextItem;
+ simpleTextItem->setFlag(QGraphicsTextItem::ItemIsFocusScope);
+ simpleTextItem->setTextInteractionFlags(Qt::TextEditorInteraction);
+ simpleTextItem->setPlainText(str);
+ scene.addItem(simpleTextItem);
+
+ scene.setFocusItem(simpleTextItem);
+ view.setGeometry(100, 100, 600, 400);
+ view.show();
+
+ QInputMethodEvent inputEvent;
+ QString &preedictStr = const_cast<QString &>(inputEvent.preeditString());
+ preedictStr = str;
+ QApplication::sendEvent(&scene, &inputEvent);
+ QCOMPARE(simpleTextItem->toPlainText(), str);
+
+ // 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);
+
+ preedictStr.clear();
+ inputEvent.setCommitString(str);
+ QApplication::sendEvent(&scene, &inputEvent);
+ 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 607bcd0ea4..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()
@@ -8,16 +15,13 @@ endif()
## tst_qgraphicssceneindex Test:
#####################################################################
-qt_add_test(tst_qgraphicssceneindex
+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/qgraphicssceneindex.pro b/tests/auto/widgets/graphicsview/qgraphicssceneindex/qgraphicssceneindex.pro
deleted file mode 100644
index 42c260d480..0000000000
--- a/tests/auto/widgets/graphicsview/qgraphicssceneindex/qgraphicssceneindex.pro
+++ /dev/null
@@ -1,6 +0,0 @@
-CONFIG += testcase
-TARGET = tst_qgraphicssceneindex
-requires(qtConfig(private_tests))
-QT += widgets widgets-private testlib
-QT += core-private gui-private
-SOURCES += tst_qgraphicssceneindex.cpp
diff --git a/tests/auto/widgets/graphicsview/qgraphicssceneindex/tst_qgraphicssceneindex.cpp b/tests/auto/widgets/graphicsview/qgraphicssceneindex/tst_qgraphicssceneindex.cpp
index 4f2c310135..b6d48b52d5 100644
--- a/tests/auto/widgets/graphicsview/qgraphicssceneindex/tst_qgraphicssceneindex.cpp
+++ b/tests/auto/widgets/graphicsview/qgraphicssceneindex/tst_qgraphicssceneindex.cpp
@@ -1,38 +1,14 @@
-/****************************************************************************
-**
-** 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$
-**
-****************************************************************************/
-
-
-#include <QtTest/QtTest>
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+
+#include <QTest>
#include <QtGui/QPainterPath>
#include <QtWidgets/qgraphicsscene.h>
#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
{
@@ -73,7 +49,7 @@ void tst_QGraphicsSceneIndex::common_data()
QGraphicsSceneIndex *tst_QGraphicsSceneIndex::createIndex(const QString &indexMethod)
{
- QGraphicsSceneIndex *index = 0;
+ QGraphicsSceneIndex *index = nullptr;
QGraphicsScene *scene = new QGraphicsScene();
if (indexMethod == "bsp")
index = new QGraphicsSceneBspTreeIndex(scene);
@@ -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()
@@ -228,9 +204,9 @@ class CustomShapeItem : public QGraphicsItem
public:
CustomShapeItem(const QPainterPath &shape) : QGraphicsItem(0), mShape(shape) {}
- QPainterPath shape() const { return mShape; }
- QRectF boundingRect() const { return mShape.boundingRect(); }
- void paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget*) {}
+ QPainterPath shape() const override { return mShape; }
+ QRectF boundingRect() const override { return mShape.boundingRect(); }
+ void paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget*) override {}
private:
QPainterPath mShape;
};
@@ -277,11 +253,11 @@ class RectWidget : public QGraphicsWidget
{
Q_OBJECT
public:
- RectWidget(QGraphicsItem *parent = 0) : QGraphicsWidget(parent)
+ RectWidget(QGraphicsItem *parent = nullptr) : QGraphicsWidget(parent)
{
}
- void paint(QPainter *painter, const QStyleOptionGraphicsItem * /* option */, QWidget * /* widget */)
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem * /* option */, QWidget * /* widget */) override
{
painter->setBrush(brush);
painter->drawRect(boundingRect());
@@ -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);
@@ -333,11 +308,11 @@ void tst_QGraphicsSceneIndex::clear()
class MyItem : public QGraphicsItem
{
public:
- MyItem(QGraphicsItem *parent = 0) : QGraphicsItem(parent), numPaints(0) {}
+ MyItem(QGraphicsItem *parent = nullptr) : QGraphicsItem(parent), numPaints(0) {}
int numPaints;
protected:
- QRectF boundingRect() const { return QRectF(0, 0, 10, 10); }
- void paint(QPainter * /* painter */, const QStyleOptionGraphicsItem *, QWidget *)
+ QRectF boundingRect() const override { return QRectF(0, 0, 10, 10); }
+ void paint(QPainter * /* painter */, const QStyleOptionGraphicsItem *, QWidget *) override
{ ++numPaints; }
};
@@ -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 a3a19931e6..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:
#####################################################################
-qt_add_test(tst_qgraphicstransform
+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/qgraphicstransform.pro b/tests/auto/widgets/graphicsview/qgraphicstransform/qgraphicstransform.pro
deleted file mode 100644
index 68ee58d0d7..0000000000
--- a/tests/auto/widgets/graphicsview/qgraphicstransform/qgraphicstransform.pro
+++ /dev/null
@@ -1,4 +0,0 @@
-CONFIG += testcase
-TARGET = tst_qgraphicstransform
-QT += widgets testlib
-SOURCES += tst_qgraphicstransform.cpp
diff --git a/tests/auto/widgets/graphicsview/qgraphicstransform/tst_qgraphicstransform.cpp b/tests/auto/widgets/graphicsview/qgraphicstransform/tst_qgraphicstransform.cpp
index da3270d527..3ee63d288b 100644
--- a/tests/auto/widgets/graphicsview/qgraphicstransform/tst_qgraphicstransform.cpp
+++ b/tests/auto/widgets/graphicsview/qgraphicstransform/tst_qgraphicstransform.cpp
@@ -1,33 +1,8 @@
-/****************************************************************************
-**
-** 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$
-**
-****************************************************************************/
-
-
-#include <QtTest/QtTest>
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+
+#include <QTest>
#include <qgraphicsitem.h>
#include <qgraphicstransform.h>
@@ -116,7 +91,7 @@ void tst_QGraphicsTransform::scale()
// fuzzyCompareNonZero is a very slightly looser version of qFuzzyCompare
// for use with values that are not very close to zero
-Q_DECL_CONSTEXPR static inline bool fuzzyCompareNonZero(float p1, float p2)
+constexpr static inline bool fuzzyCompareNonZero(float p1, float p2)
{
return (qAbs(p1 - p2) <= 0.00003f * qMin(qAbs(p1), qAbs(p2)));
}
diff --git a/tests/auto/widgets/graphicsview/qgraphicsview/BLACKLIST b/tests/auto/widgets/graphicsview/qgraphicsview/BLACKLIST
index f59544f336..ae5cbf7d6a 100644
--- a/tests/auto/widgets/graphicsview/qgraphicsview/BLACKLIST
+++ b/tests/auto/widgets/graphicsview/qgraphicsview/BLACKLIST
@@ -1,20 +1,37 @@
-[task255529_transformationAnchorMouseAndViewportMargins]
-opensuse-leap
-[cursor]
-opensuse-leap
[cursor2]
-ubuntu-16.04
-[sendEvent]
-ubuntu-16.04
-opensuse-42.3
+osx
[resizeAnchor]
-opensuse-leap
-rhel-7.6
-ubuntu
-[update2]
-opensuse-42.3
+rhel
+# QTBUG-87397
+[itemsAtPoint]
+android
[itemsInRect_cosmeticAdjust]
-# QTBUG-66815
-ubuntu-16.04
-[fitInView]
-osx
+android
+[itemAt]
+android
+[mapToScenePath]
+android
+[mapFromScenePoly]
+android
+[mapFromScenePath]
+android
+[viewportUpdateMode]
+android
+[scrollBarRanges]
+android
+[moveItemWhileScrolling]
+android
+[exposeRegion]
+android
+[update2]
+android
+[update_ancestorClipsChildrenToShape]
+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 c8ead072a2..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:
#####################################################################
-qt_add_test(tst_qgraphicsview
+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_add_test(tst_qgraphicsview
Qt::WidgetsPrivate
)
-#### Keys ignored in scope 1:.:.:qgraphicsview.pro:<TRUE>:
-# testcase.timeout = "500"
-
## Scopes:
#####################################################################
-qt_extend_target(tst_qgraphicsview CONDITION QT_FEATURE_opengl
- PUBLIC_LIBRARIES
+qt_internal_extend_target(tst_qgraphicsview CONDITION QT_FEATURE_opengl
+ LIBRARIES
Qt::OpenGL
Qt::OpenGLWidgets
)
diff --git a/tests/auto/widgets/graphicsview/qgraphicsview/qgraphicsview.pro b/tests/auto/widgets/graphicsview/qgraphicsview/qgraphicsview.pro
deleted file mode 100644
index 13998d5494..0000000000
--- a/tests/auto/widgets/graphicsview/qgraphicsview/qgraphicsview.pro
+++ /dev/null
@@ -1,12 +0,0 @@
-CONFIG += testcase
-testcase.timeout = 500 # this test is slow
-TARGET = tst_qgraphicsview
-
-QT += widgets widgets-private testlib
-QT += core-private gui-private testlib-private
-qtConfig(opengl): QT += opengl openglwidgets
-
-SOURCES += tst_qgraphicsview.cpp tst_qgraphicsview_2.cpp
-HEADERS += tst_qgraphicsview.h
-DEFINES += QT_NO_CAST_TO_ASCII
-
diff --git a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp
index 84841428f0..7ed1f28b0a 100644
--- a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp
+++ b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp
@@ -1,33 +1,10 @@
-/****************************************************************************
-**
-** 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$
-**
-****************************************************************************/
-
-
-#include <QtTest/QtTest>
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+
+#include <QTest>
+#include <QSignalSpy>
+#include <QTimer>
#include <qgraphicsitem.h>
#include <qgraphicsscene.h>
@@ -48,6 +25,7 @@
#include <QtWidgets/QBoxLayout>
#include <QtWidgets/QStyle>
#include <QtWidgets/QPushButton>
+#include <QtWidgets/QScroller>
#if QT_CONFIG(opengl)
#include <QtOpenGLWidgets/QOpenGLWidget>
#endif
@@ -62,6 +40,8 @@
#include <QtTest/private/qtesthelpers_p.h>
+#include <QtWidgets/private/qapplication_p.h>
+
using namespace QTestPrivate;
Q_DECLARE_METATYPE(ExpectedValueDescription)
@@ -99,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
@@ -113,7 +99,7 @@ public:
void reset() { _count = 0; }
protected:
- bool eventFilter(QObject *watched, QEvent *event)
+ bool eventFilter(QObject *watched, QEvent *event) override
{
Q_UNUSED(watched);
if (event->type() == spied)
@@ -223,6 +209,7 @@ private slots:
void replayMouseMove();
void itemsUnderMouse();
void embeddedViews();
+ void embeddedViewsWithFocus();
void scrollAfterResize_data();
void scrollAfterResize();
void moveItemWhileScrolling_data();
@@ -263,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() {}
@@ -315,13 +305,13 @@ void tst_QGraphicsView::construction()
class TestItem : public QGraphicsItem
{
public:
- QRectF boundingRect() const
+ QRectF boundingRect() const override
{ return QRectF(-10, -10, 20, 20); }
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override
{ hints = painter->renderHints(); painter->drawRect(boundingRect()); }
- bool sceneEvent(QEvent *event)
+ bool sceneEvent(QEvent *event) override
{
events << event->type();
return QGraphicsItem::sceneEvent(event);
@@ -664,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);
@@ -685,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.
@@ -738,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);
@@ -755,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);
@@ -767,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);
@@ -781,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);
@@ -803,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);
}
@@ -860,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);
@@ -875,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);
@@ -890,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);
@@ -902,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);
@@ -1054,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);
}
@@ -1593,7 +1595,7 @@ public:
: QGraphicsRectItem(rect), numPaints(0)
{ }
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0)
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override
{
++numPaints;
QGraphicsRectItem::paint(painter, option, widget);
@@ -1635,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);
@@ -1928,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);
@@ -2145,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));
@@ -2188,7 +2195,7 @@ class MouseWheelScene : public QGraphicsScene
public:
Qt::Orientation orientation;
- void wheelEvent(QGraphicsSceneWheelEvent *event)
+ void wheelEvent(QGraphicsSceneWheelEvent *event) override
{
orientation = event->orientation();
QGraphicsScene::wheelEvent(event);
@@ -2213,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));
@@ -2422,14 +2428,14 @@ class CustomView : public QGraphicsView
{
Q_OBJECT
public:
- CustomView(QGraphicsScene *s = 0) : QGraphicsView(s) {}
+ CustomView(QGraphicsScene *s = nullptr) : QGraphicsView(s) {}
CustomView(QGraphicsScene *s, QWidget *parent)
: QGraphicsView(s, parent) {}
QList<QRegion> lastUpdateRegions;
bool painted;
protected:
- void paintEvent(QPaintEvent *event)
+ void paintEvent(QPaintEvent *event) override
{
lastUpdateRegions << event->region();
painted = true;
@@ -2450,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());
@@ -2533,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);
@@ -2634,7 +2638,7 @@ public:
using QGraphicsRectItem::QGraphicsRectItem;
bool dirtyPainter = false;
bool receivedPaintEvent = false;
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *w)
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *w) override
{
receivedPaintEvent = true;
dirtyPainter = (painter->pen().color() != w->palette().color(w->foregroundRole()));
@@ -2648,12 +2652,14 @@ public:
MyGraphicsView(QGraphicsScene * scene) : QGraphicsView(scene)
{ }
- void drawBackground(QPainter * painter, const QRectF & rect) {
+ void drawBackground(QPainter * painter, const QRectF & rect) override
+ {
painter->setCompositionMode(QPainter::CompositionMode_Source);
painter->drawRect(rect);
}
- void drawItems (QPainter * painter, int numItems, QGraphicsItem *items[], const QStyleOptionGraphicsItem options[]) {
+ void drawItems (QPainter * painter, int numItems, QGraphicsItem *items[], const QStyleOptionGraphicsItem options[]) override
+ {
if (!(optimizationFlags() & QGraphicsView::DontSavePainterState))
QCOMPARE(painter->compositionMode(),QPainter::CompositionMode_SourceOver);
else
@@ -2721,10 +2727,10 @@ void tst_QGraphicsView::optimizationFlags_dontSavePainterState2()
class MyScene : public QGraphicsScene
{
public:
- void drawBackground(QPainter *p, const QRectF &)
+ void drawBackground(QPainter *p, const QRectF &) override
{ transformInDrawBackground = p->worldTransform(); opacityInDrawBackground = p->opacity(); }
- void drawForeground(QPainter *p, const QRectF &)
+ void drawForeground(QPainter *p, const QRectF &) override
{ transformInDrawForeground = p->worldTransform(); opacityInDrawForeground = p->opacity(); }
QTransform transformInDrawBackground;
@@ -2743,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);
@@ -2800,7 +2807,7 @@ public:
LodItem(const QRectF &rect) : QGraphicsRectItem(rect), lastLod(-42)
{ }
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *viewport)
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *viewport) override
{
lastLod = option->levelOfDetailFromTransform(painter->worldTransform());
QGraphicsRectItem::paint(painter, option, viewport);
@@ -2863,14 +2870,15 @@ void tst_QGraphicsView::scrollBarRanges_data()
// Simulates motif scrollbar for range tests
class FauxMotifStyle : public QCommonStyle {
public:
- int styleHint(StyleHint hint, const QStyleOption *option,
- const QWidget *widget, QStyleHintReturn *returnData) const {
+ int styleHint(StyleHint hint, const QStyleOption *option, const QWidget *widget, QStyleHintReturn *returnData) const override
+ {
if (hint == QStyle::SH_ScrollView_FrameOnlyAroundContents)
return true;
return QCommonStyle::styleHint(hint, option, widget, returnData);
}
- int pixelMetric(PixelMetric m, const QStyleOption *opt, const QWidget *widget) const {
+ int pixelMetric(PixelMetric m, const QStyleOption *opt, const QWidget *widget) const override
+ {
if (m == QStyle::PM_ScrollView_ScrollBarSpacing)
return 4;
return QCommonStyle::pixelMetric(m, opt, widget);
@@ -2879,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);
@@ -2892,7 +2903,7 @@ void tst_QGraphicsView::scrollBarRanges()
QFETCH(ExpectedValueDescription, vmax);
QFETCH(bool, useStyledPanel);
- if (useStyledPanel && style == "macintosh" && platformName == QStringLiteral("cocoa"))
+ if (useStyledPanel && style == "macOS" && platformName == QStringLiteral("cocoa"))
QSKIP("Insignificant on OSX");
QScopedPointer<QStyle> stylePtr;
@@ -2959,12 +2970,12 @@ public:
bool doubleClickAccepted;
protected:
- void mousePressEvent(QMouseEvent *event)
+ void mousePressEvent(QMouseEvent *event) override
{
QGraphicsView::mousePressEvent(event);
pressAccepted = event->isAccepted();
}
- void mouseDoubleClickEvent(QMouseEvent *event)
+ void mouseDoubleClickEvent(QMouseEvent *event) override
{
QGraphicsView::mouseDoubleClickEvent(event);
doubleClickAccepted = event->isAccepted();
@@ -3020,12 +3031,12 @@ public:
bool doubleClickForwarded;
protected:
- void mousePressEvent(QMouseEvent *event)
+ void mousePressEvent(QMouseEvent *event) override
{
QWidget::mousePressEvent(event);
pressForwarded = true;
}
- void mouseDoubleClickEvent(QMouseEvent *event)
+ void mouseDoubleClickEvent(QMouseEvent *event) override
{
QWidget::mouseDoubleClickEvent(event);
doubleClickForwarded = true;
@@ -3149,10 +3160,10 @@ void tst_QGraphicsView::itemsUnderMouse()
class QGraphicsTextItem_task172231 : public QGraphicsTextItem
{
public:
- QGraphicsTextItem_task172231(const QString & text, QGraphicsItem * parent = 0)
+ QGraphicsTextItem_task172231(const QString & text, QGraphicsItem * parent = nullptr)
: QGraphicsTextItem(text, parent) {}
QRectF exposedRect;
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
{
exposedRect = option->exposedRect;
QGraphicsTextItem::paint(painter, option, widget);
@@ -3174,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));
@@ -3202,9 +3212,9 @@ public:
int releases;
protected:
- void mousePressEvent(QGraphicsSceneMouseEvent *event)
+ void mousePressEvent(QGraphicsSceneMouseEvent *event) override
{ ++presses; QGraphicsScene::mousePressEvent(event); }
- void mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
+ void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override
{ ++releases; QGraphicsScene::mouseReleaseEvent(event); }
};
@@ -3236,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);
@@ -3257,11 +3266,12 @@ public:
{ }
int mouseMoves;
protected:
- void mouseMoveEvent(QMouseEvent *event)
+ void mouseMoveEvent(QMouseEvent *event) override
{
++mouseMoves;
QGraphicsView::mouseMoveEvent(event);
- foreach (QGraphicsItem *item, scene()->items()) {
+ const auto items = scene()->items();
+ for (QGraphicsItem *item : items) {
scene()->removeItem(item);
delete item;
}
@@ -3287,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);
@@ -3295,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);
@@ -3310,7 +3322,7 @@ void tst_QGraphicsView::task207546_focusCrash()
class _Widget : public QWidget
{
public:
- bool focusNextPrevChild(bool next) { return QWidget::focusNextPrevChild(next); }
+ bool focusNextPrevChild(bool next) override { return QWidget::focusNextPrevChild(next); }
} widget;
widget.setLayout(new QVBoxLayout());
@@ -3320,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);
@@ -3341,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);
}
@@ -3350,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);
}
@@ -3359,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);
}
@@ -3394,7 +3409,7 @@ void tst_QGraphicsView::task239729_noViewUpdate()
// The scene's changed signal is connected to something that isn't a view.
QGraphicsScene scene;
ChangedListener cl;
- QGraphicsView *view = 0;
+ QGraphicsView *view = nullptr;
if (a) {
view = new QGraphicsView(&scene);
@@ -3408,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);
@@ -3487,7 +3501,7 @@ public:
{
}
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override
{
transform = painter->transform();
}
@@ -3519,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");
@@ -3587,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);
@@ -3612,7 +3686,7 @@ void tst_QGraphicsView::moveItemWhileScrolling()
}
protected:
QEventLoop eventLoop;
- void paintEvent(QPaintEvent *event)
+ void paintEvent(QPaintEvent *event) override
{
painted = true;
lastPaintedRegion = event->region();
@@ -3809,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);
}
@@ -3918,8 +3993,7 @@ public:
: QGraphicsRectItem(rect), paints(0)
{ }
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
- QWidget *widget)
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
{
QGraphicsRectItem::paint(painter, option, widget);
++paints;
@@ -3979,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));
@@ -4053,7 +4127,6 @@ void tst_QGraphicsView::update()
QVERIFY(QTest::qWaitForWindowExposed(&toplevel));
- QApplication::setActiveWindow(&toplevel);
QApplication::processEvents();
QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&toplevel));
@@ -4110,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);
@@ -4135,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);
@@ -4205,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);
@@ -4259,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);
@@ -4306,7 +4382,7 @@ public:
m_viewHasIMEnabledInFocusInEvent = false;
}
- void focusInEvent(QFocusEvent * /* event */)
+ void focusInEvent(QFocusEvent * /* event */) override
{
QGraphicsView *view = scene()->views().first();
m_viewHasIMEnabledInFocusInEvent = view->testAttribute(Qt::WA_InputMethodEnabled);
@@ -4320,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));
@@ -4418,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));
@@ -4470,7 +4544,7 @@ void tst_QGraphicsView::indirectPainting()
class MyScene : public QGraphicsScene
{ public:
MyScene() : QGraphicsScene(), drawCount(0) {}
- void drawItems(QPainter *, int, QGraphicsItem **, const QStyleOptionGraphicsItem *, QWidget *)
+ void drawItems(QPainter *, int, QGraphicsItem **, const QStyleOptionGraphicsItem *, QWidget *) override
{ ++drawCount; }
int drawCount;
};
@@ -4498,7 +4572,7 @@ void tst_QGraphicsView::compositionModeInDrawBackground()
painted(false), compositionMode(QPainter::CompositionMode_SourceOver) {}
bool painted;
QPainter::CompositionMode compositionMode;
- void drawBackground(QPainter *painter, const QRectF &)
+ void drawBackground(QPainter *painter, const QRectF &) override
{
compositionMode = painter->compositionMode();
painted = true;
@@ -4566,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)
@@ -4624,7 +4697,7 @@ void tst_QGraphicsView::task259503_scrollingArtifacts()
QRegion updateRegion;
bool itSTimeToTest;
- void paintEvent(QPaintEvent *event)
+ void paintEvent(QPaintEvent *event) override
{
QGraphicsView::paintEvent(event);
@@ -4709,11 +4782,14 @@ 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:
CustomScene(const QRectF &rect) : QGraphicsScene(rect) { }
- void drawBackground(QPainter * /* painter */, const QRectF &rect)
+ void drawBackground(QPainter * /* painter */, const QRectF &rect) override
{ lastBackgroundExposedRect = rect; }
QRectF lastBackgroundExposedRect;
};
@@ -4723,7 +4799,7 @@ void tst_QGraphicsView::QTBUG_5859_exposedRect()
public:
CustomRectItem(const QRectF &rect) : QGraphicsRectItem(rect)
{ setFlag(QGraphicsItem::ItemUsesExtendedStyleOption); }
- void paint(QPainter * /* painter */, const QStyleOptionGraphicsItem *option, QWidget * /* widget */ = 0)
+ void paint(QPainter * /* painter */, const QStyleOptionGraphicsItem *option, QWidget * /* widget */ = 0) override
{ lastExposedRect = option->exposedRect; }
QRectF lastExposedRect;
};
@@ -4737,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));
@@ -4778,7 +4853,7 @@ public:
setAcceptHoverEvents(true);
}
- bool sceneEvent(QEvent *event)
+ bool sceneEvent(QEvent *event) override
{
if (!checkEvents) // ensures that we don't look at stray events before we are ready
return QGraphicsRectItem::sceneEvent(event);
@@ -4809,7 +4884,6 @@ void tst_QGraphicsView::hoverLeave()
scene.addItem(item);
view.showNormal();
- qApp->setActiveWindow(&view);
QVERIFY(QTest::qWaitForWindowExposed(&view));
QWindow *viewWindow = view.window()->windowHandle();
@@ -4833,14 +4907,15 @@ void tst_QGraphicsView::hoverLeave()
class IMItem : public QGraphicsRectItem
{
public:
- IMItem(QGraphicsItem *parent = 0):
+ IMItem(QGraphicsItem *parent = nullptr):
QGraphicsRectItem(QRectF(0, 0, 20, 20), parent)
{
setFlag(QGraphicsItem::ItemIsFocusable, true);
setFlag(QGraphicsItem::ItemAcceptsInputMethod, true);
+ setPen(Qt::NoPen); // Avoid adding a half pixel border to the rect.
}
- QVariant inputMethodQuery(Qt::InputMethodQuery) const
+ QVariant inputMethodQuery(Qt::InputMethodQuery) const override
{
return mf;
}
@@ -4873,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 ed16878ecb..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
@@ -34,7 +9,7 @@
// value to add/remove has to be obtained in test run using the actual style.
struct ExpectedValueDescription {
- Q_DECL_CONSTEXPR ExpectedValueDescription(int v = 0, int sbeta = 0, int sta = 0)
+ constexpr ExpectedValueDescription(int v = 0, int sbeta = 0, int sta = 0)
: value(v)
, scrollBarExtentsToAdd(sbeta)
, spacingsToAdd(sta)
@@ -55,7 +30,7 @@ struct ExpectedValueDescription {
// Describes how often the scroll bar width/height has to be added to/removed
// from the according side of the sceneRect.
struct ScrollBarCount {
- Q_DECL_CONSTEXPR ScrollBarCount(int l = 0, int t = 0, int r = 0, int b = 0 )
+ constexpr ScrollBarCount(int l = 0, int t = 0, int r = 0, int b = 0 )
: left(l)
, top(t)
, right(r)
diff --git a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview_2.cpp b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview_2.cpp
index 297e83421b..1380e007e7 100644
--- a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview_2.cpp
+++ b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview_2.cpp
@@ -1,31 +1,6 @@
-/****************************************************************************
-**
-** 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$
-**
-****************************************************************************/
-#include <QtTest/QtTest>
+// 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>
#include <QtGui/QTransform>
@@ -49,7 +24,7 @@ static void _scrollBarRanges_addTestData(const QByteArray &style, bool styled)
const int viewWidth = 250;
const int viewHeight = 100;
- static Q_CONSTEXPR struct Data {
+ static constexpr struct Data {
const char *name;
QRectF sceneRect;
ScrollBarCount sceneRectOffsetFactors;
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 d519985662..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:
#####################################################################
-qt_add_test(tst_qgraphicswidget
+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/qgraphicswidget.pro b/tests/auto/widgets/graphicsview/qgraphicswidget/qgraphicswidget.pro
deleted file mode 100644
index 042c42f63f..0000000000
--- a/tests/auto/widgets/graphicsview/qgraphicswidget/qgraphicswidget.pro
+++ /dev/null
@@ -1,8 +0,0 @@
-CONFIG += testcase
-TARGET = tst_qgraphicswidget
-
-QT += widgets widgets-private testlib
-QT += core-private gui-private
-
-SOURCES += tst_qgraphicswidget.cpp
-
diff --git a/tests/auto/widgets/graphicsview/qgraphicswidget/tst_qgraphicswidget.cpp b/tests/auto/widgets/graphicsview/qgraphicswidget/tst_qgraphicswidget.cpp
index 882aa8bcbd..9fd93ca91d 100644
--- a/tests/auto/widgets/graphicsview/qgraphicswidget/tst_qgraphicswidget.cpp
+++ b/tests/auto/widgets/graphicsview/qgraphicswidget/tst_qgraphicswidget.cpp
@@ -1,33 +1,8 @@
-/****************************************************************************
-**
-** 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$
-**
-****************************************************************************/
-
-
-#include <QtTest/QtTest>
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+
+#include <QTest>
#include <qgraphicswidget.h>
#include <qgraphicsscene.h>
#include <qgraphicssceneevent.h>
@@ -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,16 +146,24 @@ 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:
- SubQGraphicsWidget(QGraphicsItem *parent = 0, Qt::WindowFlags windowFlags = { })
+ SubQGraphicsWidget(QGraphicsItem *parent = nullptr, Qt::WindowFlags windowFlags = { })
: 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);
@@ -254,7 +239,7 @@ protected:
class SizeHinter : public QGraphicsWidget
{
public:
- SizeHinter(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = { },
+ SizeHinter(QGraphicsItem *parent = nullptr, Qt::WindowFlags wFlags = { },
const QSizeF &min = QSizeF(5,5),
const QSizeF &pref = QSizeF(50, 50),
const QSizeF &max = QSizeF(500, 500))
@@ -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];
@@ -382,7 +367,7 @@ void tst_QGraphicsWidget::dumpFocusChain()
// ### this test is very strange...
QFETCH(bool, scene);
SubQGraphicsWidget *parent = new SubQGraphicsWidget;
- QGraphicsScene *theScene = 0;
+ QGraphicsScene *theScene = nullptr;
if (scene) {
theScene = new QGraphicsScene(this);
theScene->addItem(parent);
@@ -518,11 +503,14 @@ void tst_QGraphicsWidget::focusWidget2()
class FocusWatchWidget : public QGraphicsWidget
{
public:
- FocusWatchWidget(QGraphicsItem *parent = 0) : 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()
@@ -640,11 +628,11 @@ void tst_QGraphicsWidget::fontPropagatesResolveToChildren()
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
- QCOMPARE(font.resolve(), uint(QFont::StyleResolved));
- QCOMPARE(root->font().resolve(), uint(QFont::StyleResolved));
- QCOMPARE(child1->font().resolve(), uint(QFont::StyleResolved));
- QCOMPARE(child2->font().resolve(), uint(QFont::StyleResolved));
- QCOMPARE(child3->font().resolve(), uint(QFont::StyleResolved));
+ QCOMPARE(font.resolveMask(), uint(QFont::StyleResolved));
+ QCOMPARE(root->font().resolveMask(), uint(QFont::StyleResolved));
+ QCOMPARE(child1->font().resolveMask(), uint(QFont::StyleResolved));
+ QCOMPARE(child2->font().resolveMask(), uint(QFont::StyleResolved));
+ QCOMPARE(child3->font().resolveMask(), uint(QFont::StyleResolved));
}
void tst_QGraphicsWidget::fontPropagatesResolveToGrandChildren()
@@ -675,12 +663,12 @@ void tst_QGraphicsWidget::fontPropagatesResolveToGrandChildren()
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
- QCOMPARE(font.resolve(), uint(QFont::StyleResolved));
- QCOMPARE(grandChild1->font().resolve(), uint(QFont::StyleResolved));
- QCOMPARE(grandChild2->font().resolve(), uint(QFont::StyleResolved));
- QCOMPARE(grandChild3->font().resolve(), uint(QFont::StyleResolved));
- QCOMPARE(grandChild4->font().resolve(), uint(QFont::StyleResolved));
- QCOMPARE(grandChild5->font().resolve(), uint(QFont::StyleResolved));
+ QCOMPARE(font.resolveMask(), uint(QFont::StyleResolved));
+ QCOMPARE(grandChild1->font().resolveMask(), uint(QFont::StyleResolved));
+ QCOMPARE(grandChild2->font().resolveMask(), uint(QFont::StyleResolved));
+ QCOMPARE(grandChild3->font().resolveMask(), uint(QFont::StyleResolved));
+ QCOMPARE(grandChild4->font().resolveMask(), uint(QFont::StyleResolved));
+ QCOMPARE(grandChild5->font().resolveMask(), uint(QFont::StyleResolved));
}
void tst_QGraphicsWidget::fontPropagatesResolveViaNonWidget()
@@ -711,12 +699,12 @@ void tst_QGraphicsWidget::fontPropagatesResolveViaNonWidget()
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
- QCOMPARE(font.resolve(), uint(QFont::StyleResolved));
- QCOMPARE(grandChild1->font().resolve(), uint(QFont::StyleResolved));
- QCOMPARE(grandChild2->font().resolve(), uint(QFont::StyleResolved));
- QCOMPARE(grandChild3->font().resolve(), uint(QFont::StyleResolved));
- QCOMPARE(grandChild4->font().resolve(), uint(QFont::StyleResolved));
- QCOMPARE(grandChild5->font().resolve(), uint(QFont::StyleResolved));
+ QCOMPARE(font.resolveMask(), uint(QFont::StyleResolved));
+ QCOMPARE(grandChild1->font().resolveMask(), uint(QFont::StyleResolved));
+ QCOMPARE(grandChild2->font().resolveMask(), uint(QFont::StyleResolved));
+ QCOMPARE(grandChild3->font().resolveMask(), uint(QFont::StyleResolved));
+ QCOMPARE(grandChild4->font().resolveMask(), uint(QFont::StyleResolved));
+ QCOMPARE(grandChild5->font().resolveMask(), uint(QFont::StyleResolved));
}
void tst_QGraphicsWidget::fontPropagatesResolveFromScene()
@@ -747,16 +735,16 @@ void tst_QGraphicsWidget::fontPropagatesResolveFromScene()
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
- QCOMPARE(font.resolve(), uint(QFont::StyleResolved));
- QCOMPARE(root->font().resolve(), uint(QFont::StyleResolved));
- QCOMPARE(child1->font().resolve(), uint(QFont::StyleResolved));
- QCOMPARE(child2->font().resolve(), uint(QFont::StyleResolved));
- QCOMPARE(child3->font().resolve(), uint(QFont::StyleResolved));
- QCOMPARE(grandChild1->font().resolve(), uint(QFont::StyleResolved));
- QCOMPARE(grandChild2->font().resolve(), uint(QFont::StyleResolved));
- QCOMPARE(grandChild3->font().resolve(), uint(QFont::StyleResolved));
- QCOMPARE(grandChild4->font().resolve(), uint(QFont::StyleResolved));
- QCOMPARE(grandChild5->font().resolve(), uint(QFont::StyleResolved));
+ QCOMPARE(font.resolveMask(), uint(QFont::StyleResolved));
+ QCOMPARE(root->font().resolveMask(), uint(QFont::StyleResolved));
+ QCOMPARE(child1->font().resolveMask(), uint(QFont::StyleResolved));
+ QCOMPARE(child2->font().resolveMask(), uint(QFont::StyleResolved));
+ QCOMPARE(child3->font().resolveMask(), uint(QFont::StyleResolved));
+ QCOMPARE(grandChild1->font().resolveMask(), uint(QFont::StyleResolved));
+ QCOMPARE(grandChild2->font().resolveMask(), uint(QFont::StyleResolved));
+ QCOMPARE(grandChild3->font().resolveMask(), uint(QFont::StyleResolved));
+ QCOMPARE(grandChild4->font().resolveMask(), uint(QFont::StyleResolved));
+ QCOMPARE(grandChild5->font().resolveMask(), uint(QFont::StyleResolved));
}
void tst_QGraphicsWidget::fontPropagatesResolveInParentChange()
@@ -785,8 +773,8 @@ void tst_QGraphicsWidget::fontPropagatesResolveInParentChange()
QVERIFY(!grandChild2->font().italic());
QVERIFY(grandChild2->font().bold());
- QCOMPARE(grandChild1->font().resolve(), uint(QFont::StyleResolved));
- QCOMPARE(grandChild2->font().resolve(), uint(QFont::WeightResolved));
+ QCOMPARE(grandChild1->font().resolveMask(), uint(QFont::StyleResolved));
+ QCOMPARE(grandChild2->font().resolveMask(), uint(QFont::WeightResolved));
grandChild2->setParentItem(child1);
@@ -800,8 +788,8 @@ void tst_QGraphicsWidget::fontPropagatesResolveInParentChange()
QVERIFY(grandChild2->font().italic());
QVERIFY(!grandChild2->font().bold());
- QCOMPARE(grandChild1->font().resolve(), uint(QFont::StyleResolved));
- QCOMPARE(grandChild2->font().resolve(), uint(QFont::StyleResolved));
+ QCOMPARE(grandChild1->font().resolveMask(), uint(QFont::StyleResolved));
+ QCOMPARE(grandChild2->font().resolveMask(), uint(QFont::StyleResolved));
}
@@ -911,12 +899,12 @@ void tst_QGraphicsWidget::fontPropagationWidgetItemWidget()
widget->setFont(font);
QCOMPARE(widget2->font().pointSize(), 43);
- QCOMPARE(widget2->font().resolve(), uint(QFont::SizeResolved));
+ QCOMPARE(widget2->font().resolveMask(), uint(QFont::SizeResolved));
widget->setFont(QFont());
QCOMPARE(widget2->font().pointSize(), qApp->font().pointSize());
- QCOMPARE(widget2->font().resolve(), QFont().resolve());
+ QCOMPARE(widget2->font().resolveMask(), QFont().resolveMask());
}
void tst_QGraphicsWidget::fontPropagationSceneChange()
@@ -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,10 +1388,9 @@ void tst_QGraphicsWidget::setTabOrder()
QGraphicsScene scene;
QGraphicsView view(&scene);
view.show();
- QApplication::setActiveWindow(&view);
QVERIFY(QTest::qWaitForWindowActive(&view));
- QGraphicsWidget *lastItem = 0;
+ QGraphicsWidget *lastItem = nullptr;
QTest::ignoreMessage(QtWarningMsg, "QGraphicsWidget::setTabOrder(0, 0) is undefined");
QGraphicsWidget::setTabOrder(0, 0);
@@ -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));
}
@@ -2587,17 +2576,17 @@ void tst_QGraphicsWidget::shortcutsDeletion()
class MessUpPainterWidget : public QGraphicsWidget
{
public:
- MessUpPainterWidget(QGraphicsItem * parent = 0, Qt::WindowFlags wFlags = { })
+ MessUpPainterWidget(QGraphicsItem * parent = nullptr, Qt::WindowFlags wFlags = { })
: 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());
}
@@ -3278,8 +3238,7 @@ void tst_QGraphicsWidget::itemSendGeometryPosChangesDeactivated()
item->setGeometry(QRectF(0, 0, 60, 60));
QCOMPARE(item->geometry(), QRectF(0, 0, 60, 60));
QCOMPARE(item->pos(), QPointF(0, 0));
- item->setPos(QPointF(10, 10));
- QCOMPARE(item->pos(), QPointF(10, 10));
+ item->setPos(QPointF(10, 10)); QCOMPARE(item->pos(), QPointF(10, 10));
QCOMPARE(item->geometry(), QRectF(10, 10, 60, 60));
}
@@ -3287,15 +3246,15 @@ class TabFocusWidget : public QGraphicsWidget
{
Q_OBJECT
public:
- TabFocusWidget(const QString &name, QGraphicsItem *parent = 0)
+ TabFocusWidget(const QString &name, QGraphicsItem *parent = nullptr)
: QGraphicsWidget(parent)
{ setFocusPolicy(Qt::TabFocus); setData(0, name); }
};
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();