diff --git a/src/widgets/widgets/qmainwindowlayout.cpp b/src/widgets/widgets/qmainwindowlayout.cpp index 63a6c718bc..99c32e9acc 100644 --- a/src/widgets/widgets/qmainwindowlayout.cpp +++ b/src/widgets/widgets/qmainwindowlayout.cpp @@ -852,6 +852,25 @@ static QList findChildrenHelper(const QObject *o) return result; } +#ifndef QT_NO_DOCKWIDGET +static QList allMyDockWidgets(const QWidget *mainWindow) +{ + QList result; + for (QObject *c : mainWindow->children()) { + if (auto *dw = qobject_cast(c)) { + result.append(dw); + } else if (auto *gw = qobject_cast(c)) { + for (QObject *c : gw->children()) { + if (auto *dw = qobject_cast(c)) + result.append(dw); + } + } + } + + return result; +} +#endif // QT_NO_DOCKWIDGET + //pre4.3 tests the format that was used before 4.3 bool QMainWindowLayoutState::checkFormat(QDataStream &stream) { @@ -875,9 +894,7 @@ bool QMainWindowLayoutState::checkFormat(QDataStream &stream) #ifndef QT_NO_DOCKWIDGET case QDockAreaLayout::DockWidgetStateMarker: { - QList dockWidgets = findChildrenHelper(mainWindow); - foreach (QDockWidgetGroupWindow *floating, findChildrenHelper(mainWindow)) - dockWidgets += findChildrenHelper(floating); + const auto dockWidgets = allMyDockWidgets(mainWindow); if (!dockAreaLayout.restoreState(stream, dockWidgets, true /*testing*/)) { return false; } @@ -889,9 +906,7 @@ bool QMainWindowLayoutState::checkFormat(QDataStream &stream) QRect geom; stream >> geom; QDockAreaLayoutInfo info; - QList dockWidgets = findChildrenHelper(mainWindow); - foreach (QDockWidgetGroupWindow *floating, findChildrenHelper(mainWindow)) - dockWidgets += findChildrenHelper(floating); + auto dockWidgets = allMyDockWidgets(mainWindow); if (!info.restoreState(stream, dockWidgets, true /* testing*/)) return false; } @@ -935,9 +950,7 @@ bool QMainWindowLayoutState::restoreState(QDataStream &_stream, #ifndef QT_NO_DOCKWIDGET case QDockAreaLayout::DockWidgetStateMarker: { - QList dockWidgets = findChildrenHelper(mainWindow); - foreach (QDockWidgetGroupWindow *floating, findChildrenHelper(mainWindow)) - dockWidgets += findChildrenHelper(floating); + const auto dockWidgets = allMyDockWidgets(mainWindow); if (!dockAreaLayout.restoreState(stream, dockWidgets)) return false; @@ -961,9 +974,7 @@ bool QMainWindowLayoutState::restoreState(QDataStream &_stream, #ifndef QT_NO_TABBAR case QDockAreaLayout::FloatingDockWidgetTabMarker: { - QList dockWidgets = findChildrenHelper(mainWindow); - foreach (QDockWidgetGroupWindow *floating, findChildrenHelper(mainWindow)) - dockWidgets += findChildrenHelper(floating); + auto dockWidgets = allMyDockWidgets(mainWindow); QDockWidgetGroupWindow* floatingTab = qt_mainwindow_layout(mainWindow)->createTabbedDockWindow(); *floatingTab->layoutInfo() = QDockAreaLayoutInfo(&dockAreaLayout.sep, QInternal::LeftDock, Qt::Horizontal, QTabBar::RoundedSouth, mainWindow);