QMainWindowLayout: eradicate Q_FOREACH loops: Extract Method allMyDockWidgets()
Extract a loop repeated four times in the code into a separate function. Port to use C++11 range-for loops and not create temporary QLists. Saves 2.4KiB in text size on optimized GCC 5.3 Linux AMD64 builds. Change-Id: I7eb78ffaac33627b595e35cafb6ce0769fb760a8 Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
This commit is contained in:
parent
fb591c7366
commit
0077435897
@ -852,6 +852,25 @@ static QList<T> findChildrenHelper(const QObject *o)
|
||||
return result;
|
||||
}
|
||||
|
||||
#ifndef QT_NO_DOCKWIDGET
|
||||
static QList<QDockWidget*> allMyDockWidgets(const QWidget *mainWindow)
|
||||
{
|
||||
QList<QDockWidget*> result;
|
||||
for (QObject *c : mainWindow->children()) {
|
||||
if (auto *dw = qobject_cast<QDockWidget*>(c)) {
|
||||
result.append(dw);
|
||||
} else if (auto *gw = qobject_cast<QDockWidgetGroupWindow*>(c)) {
|
||||
for (QObject *c : gw->children()) {
|
||||
if (auto *dw = qobject_cast<QDockWidget*>(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<QDockWidget *> dockWidgets = findChildrenHelper<QDockWidget*>(mainWindow);
|
||||
foreach (QDockWidgetGroupWindow *floating, findChildrenHelper<QDockWidgetGroupWindow*>(mainWindow))
|
||||
dockWidgets += findChildrenHelper<QDockWidget*>(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<QDockWidget *> dockWidgets = findChildrenHelper<QDockWidget*>(mainWindow);
|
||||
foreach (QDockWidgetGroupWindow *floating, findChildrenHelper<QDockWidgetGroupWindow*>(mainWindow))
|
||||
dockWidgets += findChildrenHelper<QDockWidget*>(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<QDockWidget *> dockWidgets = findChildrenHelper<QDockWidget*>(mainWindow);
|
||||
foreach (QDockWidgetGroupWindow *floating, findChildrenHelper<QDockWidgetGroupWindow*>(mainWindow))
|
||||
dockWidgets += findChildrenHelper<QDockWidget*>(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<QDockWidget *> dockWidgets = findChildrenHelper<QDockWidget*>(mainWindow);
|
||||
foreach (QDockWidgetGroupWindow *floating, findChildrenHelper<QDockWidgetGroupWindow*>(mainWindow))
|
||||
dockWidgets += findChildrenHelper<QDockWidget*>(floating);
|
||||
auto dockWidgets = allMyDockWidgets(mainWindow);
|
||||
QDockWidgetGroupWindow* floatingTab = qt_mainwindow_layout(mainWindow)->createTabbedDockWindow();
|
||||
*floatingTab->layoutInfo() = QDockAreaLayoutInfo(&dockAreaLayout.sep, QInternal::LeftDock,
|
||||
Qt::Horizontal, QTabBar::RoundedSouth, mainWindow);
|
||||
|
Loading…
Reference in New Issue
Block a user