From da9da78adc4c82534c5648ed54df90e2df87225d Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Mon, 10 Jun 2024 16:14:47 +0200 Subject: [PATCH] QGraphicsView: add a failing test Task-number: QTBUG-53974 Pick-to: 6.7 6.5 Change-Id: Ibff3e32080a2978e533bd1f3215fec81bedb72b7 Reviewed-by: David Faure (cherry picked from commit f27534158e64ed1fb3aacc090995ea4b2d4b26fe) Reviewed-by: Qt Cherry-pick Bot --- .../qgraphicsview/tst_qgraphicsview.cpp | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp index 7ed1f28b0a9..ed99cd93a8f 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #if QT_CONFIG(opengl) #include #endif @@ -114,6 +115,7 @@ protected: #if defined QT_BUILD_INTERNAL class FriendlyGraphicsScene : public QGraphicsScene { + using QGraphicsScene::QGraphicsScene; friend class tst_QGraphicsView; Q_DECLARE_PRIVATE(QGraphicsScene); }; @@ -253,6 +255,9 @@ private slots: void QTBUG_70255_scrollTo(); #ifndef QT_NO_CURSOR void QTBUG_7438_cursor(); +#endif +#ifdef QT_BUILD_INTERNAL + void QTBUG_53974_mismatched_hide_show_events(); #endif void resizeContentsOnItemDrag_data(); void resizeContentsOnItemDrag(); @@ -4975,6 +4980,92 @@ void tst_QGraphicsView::QTBUG_70255_scrollTo() QCOMPARE(point, QPoint(0, -500)); } +#ifdef QT_BUILD_INTERNAL +void tst_QGraphicsView::QTBUG_53974_mismatched_hide_show_events() +{ + QGraphicsView *view = new QGraphicsView; + FriendlyGraphicsScene *scene = new FriendlyGraphicsScene(view); + view->setScene(scene); + + QStackedWidget *lowLevel = new QStackedWidget; + lowLevel->addWidget(new QLabel); + lowLevel->addWidget(view); + + QStackedWidget topLevel; + topLevel.addWidget(new QLabel); + topLevel.addWidget(lowLevel); + + QCOMPARE_EQ(scene->d_func()->activationRefCount, 0); + + topLevel.show(); + topLevel.activateWindow(); + QVERIFY(QTest::qWaitForWindowActive(&topLevel)); + + // Starting point + QCOMPARE_EQ(topLevel.currentIndex(), 0); + QCOMPARE_EQ(lowLevel->currentIndex(), 0); + + QCOMPARE_EQ(scene->d_func()->activationRefCount, 0); + + // lowLevel is not visible. Changing the current index there + // should not affect the refcount. + lowLevel->setCurrentIndex(1); + QCOMPARE_EQ(scene->d_func()->activationRefCount, 0); + + lowLevel->setCurrentIndex(0); + QEXPECT_FAIL("", "The view was already hidden, so the refcount should still be 0", Continue); + QCOMPARE_EQ(scene->d_func()->activationRefCount, 0); + scene->d_func()->activationRefCount = 0; + + // Make lowLevel visible. + topLevel.setCurrentIndex(1); + QCOMPARE_EQ(scene->d_func()->activationRefCount, 0); + + // Show and hide the QGV a couple of times. + lowLevel->setCurrentIndex(1); + QCOMPARE_EQ(scene->d_func()->activationRefCount, 1); + + lowLevel->setCurrentIndex(0); + QCOMPARE_EQ(scene->d_func()->activationRefCount, 0); + + lowLevel->setCurrentIndex(1); + QCOMPARE_EQ(scene->d_func()->activationRefCount, 1); + + lowLevel->setCurrentIndex(0); + QCOMPARE_EQ(scene->d_func()->activationRefCount, 0); + + // Make lowLevel hidden again. + topLevel.setCurrentIndex(0); + QCOMPARE_EQ(scene->d_func()->activationRefCount, 0); + + // Change the current index in the hidden lowLevel + lowLevel->setCurrentIndex(1); + QCOMPARE_EQ(scene->d_func()->activationRefCount, 0); + + lowLevel->setCurrentIndex(0); + QEXPECT_FAIL("", "The view was already hidden, so the refcount should still be 0", Continue); + QCOMPARE_EQ(scene->d_func()->activationRefCount, 0); + scene->d_func()->activationRefCount = 0; + + // Make lowLevel and the QGV visible. + lowLevel->setCurrentIndex(1); + QCOMPARE_EQ(scene->d_func()->activationRefCount, 0); + + topLevel.setCurrentIndex(1); + QCOMPARE_EQ(scene->d_func()->activationRefCount, 1); + + // Make lowLevel hidden (keeping the QGV as current index). + topLevel.setCurrentIndex(0); + QCOMPARE_EQ(scene->d_func()->activationRefCount, 0); + + // Hide the QGV: + lowLevel->setCurrentIndex(0); + QEXPECT_FAIL("", "The view was already hidden, so the refcount should still be 0", Continue); + QCOMPARE_EQ(scene->d_func()->activationRefCount, 0); + scene->d_func()->activationRefCount = 0; +} +#endif + void tst_QGraphicsView::resizeContentsOnItemDrag_data() { QTest::addColumn("alignment");