diff options
Diffstat (limited to 'tests/auto/widgets/widgets/qmdiarea/tst_qmdiarea.cpp')
-rw-r--r-- | tests/auto/widgets/widgets/qmdiarea/tst_qmdiarea.cpp | 78 |
1 files changed, 47 insertions, 31 deletions
diff --git a/tests/auto/widgets/widgets/qmdiarea/tst_qmdiarea.cpp b/tests/auto/widgets/widgets/qmdiarea/tst_qmdiarea.cpp index 946688f8b9..ef00dcaac0 100644 --- a/tests/auto/widgets/widgets/qmdiarea/tst_qmdiarea.cpp +++ b/tests/auto/widgets/widgets/qmdiarea/tst_qmdiarea.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> @@ -176,7 +176,7 @@ static bool verifyArrangement(QMdiArea *mdiArea, Arrangement arrangement, const // QWidget::childAt with the position of the first one and subsequently adding // dx and dy. QPoint subWindowPos(20, 5); - foreach (int expectedIndex, expectedIndices) { + for (int expectedIndex : expectedIndices) { QMdiSubWindow *expected = subWindows.at(expectedIndex); expected->raise(); if (mdiArea->viewport()->childAt(subWindowPos) != expected) @@ -187,7 +187,7 @@ static bool verifyArrangement(QMdiArea *mdiArea, Arrangement arrangement, const } // Restore stacking order. - foreach (QMdiSubWindow *subWindow, activationOrderList) { + for (QMdiSubWindow *subWindow : activationOrderList) { mdiArea->setActiveSubWindow(subWindow); qApp->processEvents(); } @@ -260,6 +260,7 @@ private slots: void task_236750(); void qtbug92240_title_data(); void qtbug92240_title(); + void tabbedview_singleSubWindow(); void tabbedview_activefirst(); void tabbedview_activesecond(); void tabbedview_activethird(); @@ -514,7 +515,6 @@ void tst_QMdiArea::subWindowActivatedWithMinimize() QSignalSpy spy(workspace, SIGNAL(subWindowActivated(QMdiSubWindow*))); connect( workspace, SIGNAL(subWindowActivated(QMdiSubWindow*)), this, SLOT(activeChanged(QMdiSubWindow*)) ); mw.show(); - QApplicationPrivate::setActiveWindow(&mw); QWidget *widget = new QWidget(workspace); widget->setAttribute(Qt::WA_DeleteOnClose); QMdiSubWindow *window1 = workspace->addSubWindow(widget); @@ -659,7 +659,6 @@ void tst_QMdiArea::changeWindowTitle() #endif mw->show(); - QApplicationPrivate::setActiveWindow(mw); #ifdef USE_SHOW mw->showFullScreen(); @@ -963,7 +962,6 @@ void tst_QMdiArea::activeSubWindow() mainWindow.addDockWidget(Qt::LeftDockWidgetArea, dockWidget); mainWindow.show(); - QApplicationPrivate::setActiveWindow(&mainWindow); QVERIFY(QTest::qWaitForWindowActive(&mainWindow)); QCOMPARE(mdiArea->activeSubWindow(), subWindow); QCOMPARE(qApp->focusWidget(), (QWidget *)subWindowLineEdit); @@ -986,10 +984,8 @@ void tst_QMdiArea::activeSubWindow() dummyTopLevel.show(); QVERIFY(QTest::qWaitForWindowExposed(&dummyTopLevel)); - QApplicationPrivate::setActiveWindow(&dummyTopLevel); QCOMPARE(mdiArea->activeSubWindow(), subWindow); - QApplicationPrivate::setActiveWindow(&mainWindow); QCOMPARE(mdiArea->activeSubWindow(), subWindow); //task 202657 @@ -1022,7 +1018,6 @@ void tst_QMdiArea::currentSubWindow() // Move focus to another top-level and check that we still // have an active window. - QApplicationPrivate::setActiveWindow(&dummyTopLevel); QCOMPARE(qApp->activeWindow(), (QWidget *)&dummyTopLevel); QVERIFY(mdiArea.activeSubWindow()); @@ -1044,11 +1039,9 @@ void tst_QMdiArea::currentSubWindow() QCOMPARE(mdiArea.activeSubWindow(), active); QCOMPARE(mdiArea.currentSubWindow(), active); - QApplicationPrivate::setActiveWindow(&dummyTopLevel); QVERIFY(mdiArea.activeSubWindow()); QCOMPARE(mdiArea.currentSubWindow(), active); - QApplicationPrivate::setActiveWindow(&mdiArea); active->show(); QCOMPARE(mdiArea.activeSubWindow(), active); @@ -1135,7 +1128,8 @@ void tst_QMdiArea::addAndRemoveWindows() } // removeSubWindow - foreach (QWidget *window, workspace.subWindowList()) { + const auto subWindows = workspace.subWindowList(); + for (QWidget *window : subWindows) { workspace.removeSubWindow(window); delete window; } @@ -1253,7 +1247,6 @@ void tst_QMdiArea::closeWindows() { QMdiArea workspace; workspace.show(); - QApplicationPrivate::setActiveWindow(&workspace); // Close widget QWidget *widget = new QWidget; @@ -1305,7 +1298,6 @@ void tst_QMdiArea::activateNextAndPreviousWindow() { QMdiArea workspace; workspace.show(); - QApplicationPrivate::setActiveWindow(&workspace); const int windowCount = 10; QMdiSubWindow *windows[windowCount]; @@ -1389,7 +1381,6 @@ void tst_QMdiArea::subWindowList() QMdiArea workspace; workspace.show(); - QApplicationPrivate::setActiveWindow(&workspace); QVERIFY(QTest::qWaitForWindowActive(&workspace)); QList<QMdiSubWindow *> activationOrder; @@ -1685,7 +1676,8 @@ void tst_QMdiArea::tileSubWindows() QTRY_COMPARE(workspace.size(), QSize(350, 150)); const QSize minSize(600, 130); - foreach (QMdiSubWindow *subWindow, workspace.subWindowList()) + const auto subWindows = workspace.subWindowList(); + for (QMdiSubWindow *subWindow : subWindows) subWindow->setMinimumSize(minSize); QCOMPARE(workspace.size(), QSize(350, 150)); @@ -1843,7 +1835,7 @@ void tst_QMdiArea::resizeMaximizedChildWindows() int newSize = startSize + increment * windowCount; QCOMPARE(workspaceSize, QSize(newSize, newSize)); - foreach (QWidget *window, windows) + for (QWidget *window : std::as_const(windows)) QCOMPARE(window->rect(), workspace.contentsRect()); } @@ -1877,7 +1869,6 @@ void tst_QMdiArea::dontMaximizeSubWindowOnActivation() QMdiArea mdiArea; mdiArea.show(); QVERIFY(QTest::qWaitForWindowExposed(&mdiArea)); - QApplicationPrivate::setActiveWindow(&mdiArea); // Add one maximized window. mdiArea.addSubWindow(new QWidget)->showMaximized(); @@ -1893,7 +1884,7 @@ void tst_QMdiArea::dontMaximizeSubWindowOnActivation() } // Verify that activated windows still are maximized on activation. - QList<QMdiSubWindow *> subWindows = mdiArea.subWindowList(); + const QList<QMdiSubWindow *> subWindows = mdiArea.subWindowList(); for (int i = 0; i < subWindows.size(); ++i) { mdiArea.activateNextSubWindow(); QMdiSubWindow *window = subWindows.at(i); @@ -1930,7 +1921,7 @@ void tst_QMdiArea::dontMaximizeSubWindowOnActivation() QVERIFY(mdiArea.activeSubWindow()->isMaximized()); // Minimize all windows. - foreach (QMdiSubWindow *window, subWindows) { + for (QMdiSubWindow *window : subWindows) { window->showMinimized(); QVERIFY(window->isMinimized()); qApp->processEvents(); @@ -2262,7 +2253,6 @@ void tst_QMdiArea::tabBetweenSubWindows() mdiArea.show(); QVERIFY(QTest::qWaitForWindowExposed(&mdiArea)); - QApplicationPrivate::setActiveWindow(&mdiArea); QWidget *focusWidget = subWindows.back()->widget(); QCOMPARE(qApp->focusWidget(), focusWidget); @@ -2317,7 +2307,7 @@ void tst_QMdiArea::setViewMode() QVERIFY(QTest::qWaitForWindowExposed(&mdiArea)); QMdiSubWindow *activeSubWindow = mdiArea.activeSubWindow(); - QList<QMdiSubWindow *> subWindows = mdiArea.subWindowList(); + const QList<QMdiSubWindow *> subWindows = mdiArea.subWindowList(); // Default. QVERIFY(!activeSubWindow->isMaximized()); @@ -2386,13 +2376,12 @@ void tst_QMdiArea::setViewMode() QVERIFY(tabBar->isTabEnabled(tabIndex)); // Remove sub-windows and make sure the tab is removed. - foreach (QMdiSubWindow *subWindow, subWindows) { + for (QMdiSubWindow *subWindow : subWindows) { if (subWindow != activeSubWindow) { mdiArea.removeSubWindow(subWindow); delete subWindow; } } - subWindows.clear(); QCOMPARE(tabBar->count(), 1); // Go back to default (QMdiArea::SubWindowView). @@ -2593,8 +2582,11 @@ void tst_QMdiArea::nativeSubWindows() // No native widgets. QVERIFY(!mdiArea.viewport()->internalWinId()); - foreach (QMdiSubWindow *subWindow, mdiArea.subWindowList()) - QVERIFY(!subWindow->internalWinId()); + { + const auto subWindows = mdiArea.subWindowList(); + for (QMdiSubWindow *subWindow : subWindows) + QVERIFY(!subWindow->internalWinId()); + } QWidget *nativeWidget = new QWidget; QVERIFY(nativeWidget->winId()); // enforce native window. @@ -2603,8 +2595,11 @@ void tst_QMdiArea::nativeSubWindows() // The viewport and all the sub-windows must be native. QVERIFY(mdiArea.viewport()->internalWinId()); - foreach (QMdiSubWindow *subWindow, mdiArea.subWindowList()) - QVERIFY(subWindow->internalWinId()); + { + const auto subWindows = mdiArea.subWindowList(); + for (QMdiSubWindow *subWindow : subWindows) + QVERIFY(subWindow->internalWinId()); + } // Add a non-native widget. This should become native. QMdiSubWindow *subWindow = new QMdiSubWindow; @@ -2625,8 +2620,11 @@ void tst_QMdiArea::nativeSubWindows() // The viewport and all the sub-windows must be native. QVERIFY(mdiArea.viewport()->internalWinId()); - foreach (QMdiSubWindow *subWindow, mdiArea.subWindowList()) - QVERIFY(subWindow->internalWinId()); + { + const auto subWindows = mdiArea.subWindowList(); + for (QMdiSubWindow *subWindow : subWindows) + QVERIFY(subWindow->internalWinId()); + } } { // Make a sub-window native *after* it's added to the area. @@ -2642,9 +2640,12 @@ void tst_QMdiArea::nativeSubWindows() // All the sub-windows should be native at this point QVERIFY(mdiArea.viewport()->internalWinId()); - foreach (QMdiSubWindow *subWindow, mdiArea.subWindowList()) + { + const auto subWindows = mdiArea.subWindowList(); + for (QMdiSubWindow *subWindow : subWindows) QVERIFY(subWindow->internalWinId()); } + } } void tst_QMdiArea::task_209615() @@ -2715,6 +2716,21 @@ void tst_QMdiArea::qtbug92240_title() QTRY_COMPARE(w.windowTitle(), QLatin1String("QTBUG-92240 - [2]")); } +void tst_QMdiArea::tabbedview_singleSubWindow() +{ + // With only one sub-window, setViewMode() before addSubWindow(); and addSubWindow() + // before show(), ensure the sub-window is properly activated. + QMdiArea mdiArea; + mdiArea.setViewMode(QMdiArea::TabbedView); + auto *w = new QWidget(&mdiArea); + mdiArea.addSubWindow(w); + mdiArea.show(); + QVERIFY(QTest::qWaitForWindowExposed(&mdiArea)); + auto *sub = mdiArea.subWindowList().at(0); + QCOMPARE(mdiArea.activeSubWindow(), sub); + QVERIFY(sub->isMaximized()); +} + static void setupMdiAreaWithTabbedView(QMdiArea &mdiArea) { mdiArea.setViewMode(QMdiArea::TabbedView); |