summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp')
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp100
1 files changed, 85 insertions, 15 deletions
diff --git a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp
index 346469a6ea..5a316dd55e 100644
--- a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp
+++ b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp
@@ -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);
};
@@ -254,6 +256,9 @@ private slots:
#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();
@@ -2153,7 +2158,6 @@ void tst_QGraphicsView::sendEvent()
QGraphicsView view(&scene);
view.show();
- QApplicationPrivate::setActiveWindow(&view);
QVERIFY(QTest::qWaitForWindowExposed(&view));
QVERIFY(QTest::qWaitForWindowActive(&view));
QCOMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&view));
@@ -2221,7 +2225,6 @@ void tst_QGraphicsView::wheelEvent()
// Assign a view.
QGraphicsView view(&scene);
view.show();
- QApplicationPrivate::setActiveWindow(&view);
QVERIFY(QTest::qWaitForWindowExposed(&view));
QVERIFY(QTest::qWaitForWindowActive(&view));
QCOMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&view));
@@ -2458,7 +2461,6 @@ void tst_QGraphicsView::viewportUpdateMode()
// Show the view, and initialize our test.
view.show();
- QApplicationPrivate::setActiveWindow(&view);
QVERIFY(QTest::qWaitForWindowExposed(&view));
QVERIFY(QTest::qWaitForWindowActive(&view));
QTRY_VERIFY(!view.lastUpdateRegions.isEmpty());
@@ -2541,7 +2543,6 @@ void tst_QGraphicsView::viewportUpdateMode2()
const QMargins margins = view.contentsMargins();
view.resize(200 + margins.left() + margins.right(), 200 + margins.top() + margins.bottom());
toplevel.show();
- QApplicationPrivate::setActiveWindow(&toplevel);
QVERIFY(QTest::qWaitForWindowExposed(&toplevel));
QVERIFY(QTest::qWaitForWindowActive(&toplevel));
QTRY_VERIFY(view.painted);
@@ -3189,7 +3190,6 @@ void tst_QGraphicsView::task172231_untransformableItems()
view.scale(2, 1);
view.show();
- QApplicationPrivate::setActiveWindow(&view);
QVERIFY(QTest::qWaitForWindowExposed(&view));
QVERIFY(QTest::qWaitForWindowActive(&view));
QCOMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&view));
@@ -3251,7 +3251,6 @@ void tst_QGraphicsView::task187791_setSceneCausesUpdate()
QGraphicsScene scene(0, 0, 200, 200);
QGraphicsView view(&scene);
view.show();
- QApplicationPrivate::setActiveWindow(&view);
QVERIFY(QTest::qWaitForWindowExposed(&view));
EventSpy updateSpy(view.viewport(), QEvent::Paint);
@@ -3338,7 +3337,6 @@ void tst_QGraphicsView::task207546_focusCrash()
widget.layout()->addWidget(gr2);
widget.show();
widget.activateWindow();
- QApplicationPrivate::setActiveWindow(&widget);
QVERIFY(QTest::qWaitForWindowActive(&widget));
QCOMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&widget));
widget.focusNextPrevChild(true);
@@ -3430,7 +3428,6 @@ void tst_QGraphicsView::task239729_noViewUpdate()
QCOMPARE(spy.count(), 0);
view->show();
- QApplicationPrivate::setActiveWindow(view);
QVERIFY(QTest::qWaitForWindowActive(view));
QTRY_VERIFY(spy.count() >= 1);
@@ -4135,7 +4132,6 @@ void tst_QGraphicsView::update()
QVERIFY(QTest::qWaitForWindowExposed(&toplevel));
- QApplicationPrivate::setActiveWindow(&toplevel);
QApplication::processEvents();
QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&toplevel));
@@ -4405,7 +4401,6 @@ void tst_QGraphicsView::inputMethodSensitivity()
QGraphicsScene scene;
QGraphicsView view(&scene);
view.show();
- QApplicationPrivate::setActiveWindow(&view);
QVERIFY(QTest::qWaitForWindowExposed(&view));
QVERIFY(QTest::qWaitForWindowActive(&view));
QCOMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&view));
@@ -4503,7 +4498,6 @@ void tst_QGraphicsView::inputContextReset()
QVERIFY(view.testAttribute(Qt::WA_InputMethodEnabled));
view.show();
- QApplicationPrivate::setActiveWindow(&view);
QVERIFY(QTest::qWaitForWindowExposed(&view));
QVERIFY(QTest::qWaitForWindowActive(&view));
QCOMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&view));
@@ -4651,7 +4645,6 @@ void tst_QGraphicsView::task255529_transformationAnchorMouseAndViewportMargins()
VpGraphicsView view(&scene);
view.setWindowFlags(Qt::X11BypassWindowManagerHint);
view.show();
- QApplicationPrivate::setActiveWindow(&view);
QVERIFY(QTest::qWaitForWindowExposed(&view));
const bool isActiveWindow = QTest::qWaitForWindowActive(&view);
if (!isActiveWindow)
@@ -4825,7 +4818,6 @@ void tst_QGraphicsView::QTBUG_5859_exposedRect()
QGraphicsView view(&scene);
view.scale(4.15, 4.15);
view.showNormal();
- QApplicationPrivate::setActiveWindow(&view);
QVERIFY(QTest::qWaitForWindowExposed(&view));
QVERIFY(QTest::qWaitForWindowActive(&view));
@@ -4897,7 +4889,6 @@ void tst_QGraphicsView::hoverLeave()
scene.addItem(item);
view.showNormal();
- QApplicationPrivate::setActiveWindow(&view);
QVERIFY(QTest::qWaitForWindowExposed(&view));
QWindow *viewWindow = view.window()->windowHandle();
@@ -4976,7 +4967,6 @@ void tst_QGraphicsView::QTBUG_70255_scrollTo()
view.centerOn(0, 0);
view.show();
- QApplicationPrivate::setActiveWindow(&view);
if (!QTest::qWaitForWindowExposed(&view) || !QTest::qWaitForWindowActive(&view))
QSKIP("Failed to show and activate window");
@@ -4990,6 +4980,86 @@ 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);
+ QCOMPARE_EQ(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);
+ QCOMPARE_EQ(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);
+ QCOMPARE_EQ(scene->d_func()->activationRefCount, 0);
+}
+#endif
+
void tst_QGraphicsView::resizeContentsOnItemDrag_data()
{
QTest::addColumn<Qt::Alignment>("alignment");