diff options
Diffstat (limited to 'tests/auto/widgets/graphicsview/qgraphicsview')
5 files changed, 223 insertions, 161 deletions
diff --git a/tests/auto/widgets/graphicsview/qgraphicsview/BLACKLIST b/tests/auto/widgets/graphicsview/qgraphicsview/BLACKLIST index fe3d929e9e..ae5cbf7d6a 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsview/BLACKLIST +++ b/tests/auto/widgets/graphicsview/qgraphicsview/BLACKLIST @@ -1,23 +1,7 @@ -[task255529_transformationAnchorMouseAndViewportMargins] -opensuse-leap -[cursor] -opensuse-leap [cursor2] -ubuntu-16.04 -[sendEvent] -ubuntu-16.04 -opensuse-42.3 -[resizeAnchor] -opensuse-leap -rhel-7.6 -ubuntu -[update2] -opensuse-42.3 -[itemsInRect_cosmeticAdjust] -# QTBUG-66815 -ubuntu-16.04 -[fitInView] osx +[resizeAnchor] +rhel # QTBUG-87397 [itemsAtPoint] android @@ -45,3 +29,9 @@ android android [update_ancestorClipsChildrenToShape2] android +[QTBUG_70255_scrollTo] +android # QTBUG-87397 +[embeddedViewsWithFocus] +android # QTBUG-87397 +[viewportUpdateMode2] +android # QTBUG-87397 diff --git a/tests/auto/widgets/graphicsview/qgraphicsview/CMakeLists.txt b/tests/auto/widgets/graphicsview/qgraphicsview/CMakeLists.txt index be9c4a3bc4..cf33de0b33 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsview/CMakeLists.txt +++ b/tests/auto/widgets/graphicsview/qgraphicsview/CMakeLists.txt @@ -1,16 +1,23 @@ -# Generated from qgraphicsview.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qgraphicsview Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qgraphicsview LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qgraphicsview SOURCES tst_qgraphicsview.cpp tst_qgraphicsview.h tst_qgraphicsview_2.cpp DEFINES QT_NO_CAST_TO_ASCII - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::Gui Qt::GuiPrivate @@ -19,14 +26,11 @@ qt_internal_add_test(tst_qgraphicsview Qt::WidgetsPrivate ) -#### Keys ignored in scope 1:.:.:qgraphicsview.pro:<TRUE>: -# testcase.timeout = "500" - ## Scopes: ##################################################################### qt_internal_extend_target(tst_qgraphicsview CONDITION QT_FEATURE_opengl - PUBLIC_LIBRARIES + LIBRARIES Qt::OpenGL Qt::OpenGLWidgets ) diff --git a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp index 8e44912d37..7ed1f28b0a 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> @@ -65,6 +40,8 @@ #include <QtTest/private/qtesthelpers_p.h> +#include <QtWidgets/private/qapplication_p.h> + using namespace QTestPrivate; Q_DECLARE_METATYPE(ExpectedValueDescription) @@ -102,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 @@ -271,6 +254,8 @@ private slots: #ifndef QT_NO_CURSOR void QTBUG_7438_cursor(); #endif + void resizeContentsOnItemDrag_data(); + void resizeContentsOnItemDrag(); public slots: void dummySlot() {} @@ -669,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); @@ -690,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. @@ -743,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); @@ -760,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); @@ -772,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); @@ -786,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); @@ -808,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); } @@ -865,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); @@ -880,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); @@ -895,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); @@ -907,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); @@ -1059,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); } @@ -1640,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); @@ -1933,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); @@ -2150,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)); @@ -2218,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)); @@ -2455,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()); @@ -2538,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); @@ -2750,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); @@ -2887,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); @@ -3182,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)); @@ -3244,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); @@ -3269,7 +3270,8 @@ protected: { ++mouseMoves; QGraphicsView::mouseMoveEvent(event); - foreach (QGraphicsItem *item, scene()->items()) { + const auto items = scene()->items(); + for (QGraphicsItem *item : items) { scene()->removeItem(item); delete item; } @@ -3295,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); @@ -3303,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); @@ -3328,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); @@ -3349,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); } @@ -3358,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); } @@ -3367,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); } @@ -3416,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); @@ -3548,6 +3554,9 @@ void tst_QGraphicsView::embeddedViewsWithFocus() void focusOutEvent(QFocusEvent *) override { --focusCount; } }; + if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)) + QSKIP("QWindow::requestActivate() is not supported."); + QGraphicsScene innerScene; FocusWidget *innerWidget = new FocusWidget; innerScene.addWidget(innerWidget); @@ -3649,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); @@ -3871,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); } @@ -4040,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)); @@ -4114,7 +4127,6 @@ void tst_QGraphicsView::update() QVERIFY(QTest::qWaitForWindowExposed(&toplevel)); - QApplication::setActiveWindow(&toplevel); QApplication::processEvents(); QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&toplevel)); @@ -4171,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); @@ -4196,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); @@ -4266,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); @@ -4320,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); @@ -4381,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)); @@ -4479,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)); @@ -4627,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) @@ -4770,6 +4782,9 @@ void tst_QGraphicsView::QTBUG_4151_clipAndIgnore() void tst_QGraphicsView::QTBUG_5859_exposedRect() { + if (isPlatformEGLFS()) + QSKIP("", "Resizing does not work on EGLFS on top level window", Continue); + class CustomScene : public QGraphicsScene { public: @@ -4798,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)); @@ -4870,7 +4884,6 @@ void tst_QGraphicsView::hoverLeave() scene.addItem(item); view.showNormal(); - qApp->setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowExposed(&view)); QWindow *viewWindow = view.window()->windowHandle(); @@ -4949,7 +4962,6 @@ void tst_QGraphicsView::QTBUG_70255_scrollTo() view.centerOn(0, 0); view.show(); - QApplication::setActiveWindow(&view); if (!QTest::qWaitForWindowExposed(&view) || !QTest::qWaitForWindowActive(&view)) QSKIP("Failed to show and activate window"); @@ -4963,5 +4975,111 @@ void tst_QGraphicsView::QTBUG_70255_scrollTo() QCOMPARE(point, QPoint(0, -500)); } +void tst_QGraphicsView::resizeContentsOnItemDrag_data() +{ + QTest::addColumn<Qt::Alignment>("alignment"); + QTest::addColumn<Qt::Orientation>("orientation"); + QTest::addRow("Center right") << Qt::Alignment(Qt::AlignCenter) << Qt::Horizontal; + QTest::addRow("Center down") << Qt::Alignment(Qt::AlignCenter) << Qt::Vertical; + QTest::addRow("BottomLeft right") << (Qt::AlignBottom | Qt::AlignLeft) << Qt::Horizontal; + QTest::addRow("TopRight down") << (Qt::AlignTop | Qt::AlignRight) << Qt::Vertical; +} + +void tst_QGraphicsView::resizeContentsOnItemDrag() +{ + QFETCH(Qt::Alignment, alignment); + QFETCH(Qt::Orientation, orientation); + + QGraphicsView view; + QGraphicsScene scene; + view.setFixedSize(200, 200); + view.setScene(&scene); + + view.setAlignment(alignment); + + class MovableItem : public QGraphicsEllipseItem + { + public: + using QGraphicsEllipseItem::QGraphicsEllipseItem; + + QList<QPointF> scenePositions; + + protected: + void mousePressEvent(QGraphicsSceneMouseEvent *event) override + { + scenePositions << event->scenePos(); + } + void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override + { + scenePositions << event->scenePos(); + QGraphicsEllipseItem::mouseMoveEvent(event); + } + }; + + MovableItem item(-10, -10, 20, 20); + item.setFlags(QGraphicsItem::ItemIsMovable); + scene.addItem(&item); + view.show(); + QVERIFY(QTest::qWaitForWindowExposed(&view)); + + // Position the item near the relevant edge of the view, with a few pixels + // to go until the scrollbars should be showing. + if (orientation == Qt::Horizontal) + item.setPos(view.width() - item.rect().width() - 5, 0); + else + item.setPos(0, view.height() - item.rect().height() - 5); + QApplication::processEvents(); // queued connection used to trigger recalculateContentSize + QPoint mousePos = view.mapFromScene(item.pos()); + + QTest::mousePress(view.viewport(), Qt::LeftButton, {}, mousePos); + QCOMPARE(item.scenePositions.count(), 1); + QCOMPARE(item.scenePositions.takeLast(), view.mapToScene(mousePos)); + + auto lastItemPos = item.pos(); + auto lastScenePos = view.mapToScene(mousePos); + int overshoot = 0; + const QScrollBar *scrollBar = orientation == Qt::Horizontal + ? view.horizontalScrollBar() + : view.verticalScrollBar(); + // Drag the item until the scroll bars become visible, and then for a few more pixels. + // Verify that the item doesn't jump when the scrollbar shows. + while (overshoot < 10) { + if (orientation == Qt::Horizontal) + mousePos.rx() += 1; + else + mousePos.ry() += 1; + QTest::mouseMove(view.viewport(), mousePos); + QApplication::processEvents(); // queued connection used to trigger recalculateContentSize + const bool scrollbarAvailable = scrollBar->maximum() > scrollBar->minimum(); + bool allowMoreEvents = false; + if (scrollbarAvailable) { + if (!overshoot) { + QTRY_VERIFY(scrollBar->isVisible()); + // scrollbar becoming visible triggers event replay, so we get more than one + allowMoreEvents = true; + } + ++overshoot; + } + if (allowMoreEvents) + QCOMPARE_GE(item.scenePositions.count(), 1); + else + QCOMPARE(item.scenePositions.count(), 1); + const auto scenePos = item.scenePositions.takeLast(); + item.scenePositions.clear(); + + const auto same = orientation == Qt::Horizontal ? &QPointF::y : &QPointF::x; + const auto moved = orientation == Qt::Horizontal ? &QPointF::x : &QPointF::y; + QCOMPARE((item.pos().*same)(), (lastItemPos.*same)()); + QCOMPARE_GE((item.pos().*moved)() - (lastItemPos.*moved)(), 1); + QCOMPARE_LE((item.pos().*moved)() - (lastItemPos.*moved)(), 2); + lastItemPos = item.pos(); + + QCOMPARE((scenePos.*same)(), (lastScenePos.*same)()); + QCOMPARE_GE((scenePos.*moved)() - (lastScenePos.*moved)(), 1); + QCOMPARE_LE((scenePos.*moved)() - (lastScenePos.*moved)(), 2); + lastScenePos = scenePos; + } +} + QTEST_MAIN(tst_QGraphicsView) #include "tst_qgraphicsview.moc" diff --git a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.h b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.h index 42e9e6e2a3..2fb5ed638c 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.h +++ b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef TST_QGRAPHICSVIEW_H #define TST_QGRAPHICSVIEW_H diff --git a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview_2.cpp b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview_2.cpp index 72b5acc654..1380e007e7 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview_2.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview_2.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> #include <QtCore/QSize> #include <QtCore/QRectF> |