diff options
Diffstat (limited to 'tests/auto/widgets/graphicsview/qgraphicsview')
6 files changed, 389 insertions, 222 deletions
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; |