QGraphicsView: add a failing test

Task-number: QTBUG-53974
Pick-to: 6.7 6.5
Change-Id: Ibff3e32080a2978e533bd1f3215fec81bedb72b7
Reviewed-by: David Faure <david.faure@kdab.com>
(cherry picked from commit f27534158e64ed1fb3aacc090995ea4b2d4b26fe)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Giuseppe D'Angelo 2024-06-10 16:14:47 +02:00 committed by Qt Cherry-pick Bot
parent 72c97d17bc
commit da9da78adc

View File

@ -26,6 +26,7 @@
#include <QtWidgets/QStyle>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QScroller>
#include <QtWidgets/QStackedWidget>
#if QT_CONFIG(opengl)
#include <QtOpenGLWidgets/QOpenGLWidget>
#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<Qt::Alignment>("alignment");