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;
|
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
|
//pre4.3 tests the format that was used before 4.3
|
||||||
bool QMainWindowLayoutState::checkFormat(QDataStream &stream)
|
bool QMainWindowLayoutState::checkFormat(QDataStream &stream)
|
||||||
{
|
{
|
||||||
@ -875,9 +894,7 @@ bool QMainWindowLayoutState::checkFormat(QDataStream &stream)
|
|||||||
#ifndef QT_NO_DOCKWIDGET
|
#ifndef QT_NO_DOCKWIDGET
|
||||||
case QDockAreaLayout::DockWidgetStateMarker:
|
case QDockAreaLayout::DockWidgetStateMarker:
|
||||||
{
|
{
|
||||||
QList<QDockWidget *> dockWidgets = findChildrenHelper<QDockWidget*>(mainWindow);
|
const auto dockWidgets = allMyDockWidgets(mainWindow);
|
||||||
foreach (QDockWidgetGroupWindow *floating, findChildrenHelper<QDockWidgetGroupWindow*>(mainWindow))
|
|
||||||
dockWidgets += findChildrenHelper<QDockWidget*>(floating);
|
|
||||||
if (!dockAreaLayout.restoreState(stream, dockWidgets, true /*testing*/)) {
|
if (!dockAreaLayout.restoreState(stream, dockWidgets, true /*testing*/)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -889,9 +906,7 @@ bool QMainWindowLayoutState::checkFormat(QDataStream &stream)
|
|||||||
QRect geom;
|
QRect geom;
|
||||||
stream >> geom;
|
stream >> geom;
|
||||||
QDockAreaLayoutInfo info;
|
QDockAreaLayoutInfo info;
|
||||||
QList<QDockWidget *> dockWidgets = findChildrenHelper<QDockWidget*>(mainWindow);
|
auto dockWidgets = allMyDockWidgets(mainWindow);
|
||||||
foreach (QDockWidgetGroupWindow *floating, findChildrenHelper<QDockWidgetGroupWindow*>(mainWindow))
|
|
||||||
dockWidgets += findChildrenHelper<QDockWidget*>(floating);
|
|
||||||
if (!info.restoreState(stream, dockWidgets, true /* testing*/))
|
if (!info.restoreState(stream, dockWidgets, true /* testing*/))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -935,9 +950,7 @@ bool QMainWindowLayoutState::restoreState(QDataStream &_stream,
|
|||||||
#ifndef QT_NO_DOCKWIDGET
|
#ifndef QT_NO_DOCKWIDGET
|
||||||
case QDockAreaLayout::DockWidgetStateMarker:
|
case QDockAreaLayout::DockWidgetStateMarker:
|
||||||
{
|
{
|
||||||
QList<QDockWidget *> dockWidgets = findChildrenHelper<QDockWidget*>(mainWindow);
|
const auto dockWidgets = allMyDockWidgets(mainWindow);
|
||||||
foreach (QDockWidgetGroupWindow *floating, findChildrenHelper<QDockWidgetGroupWindow*>(mainWindow))
|
|
||||||
dockWidgets += findChildrenHelper<QDockWidget*>(floating);
|
|
||||||
if (!dockAreaLayout.restoreState(stream, dockWidgets))
|
if (!dockAreaLayout.restoreState(stream, dockWidgets))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -961,9 +974,7 @@ bool QMainWindowLayoutState::restoreState(QDataStream &_stream,
|
|||||||
#ifndef QT_NO_TABBAR
|
#ifndef QT_NO_TABBAR
|
||||||
case QDockAreaLayout::FloatingDockWidgetTabMarker:
|
case QDockAreaLayout::FloatingDockWidgetTabMarker:
|
||||||
{
|
{
|
||||||
QList<QDockWidget *> dockWidgets = findChildrenHelper<QDockWidget*>(mainWindow);
|
auto dockWidgets = allMyDockWidgets(mainWindow);
|
||||||
foreach (QDockWidgetGroupWindow *floating, findChildrenHelper<QDockWidgetGroupWindow*>(mainWindow))
|
|
||||||
dockWidgets += findChildrenHelper<QDockWidget*>(floating);
|
|
||||||
QDockWidgetGroupWindow* floatingTab = qt_mainwindow_layout(mainWindow)->createTabbedDockWindow();
|
QDockWidgetGroupWindow* floatingTab = qt_mainwindow_layout(mainWindow)->createTabbedDockWindow();
|
||||||
*floatingTab->layoutInfo() = QDockAreaLayoutInfo(&dockAreaLayout.sep, QInternal::LeftDock,
|
*floatingTab->layoutInfo() = QDockAreaLayoutInfo(&dockAreaLayout.sep, QInternal::LeftDock,
|
||||||
Qt::Horizontal, QTabBar::RoundedSouth, mainWindow);
|
Qt::Horizontal, QTabBar::RoundedSouth, mainWindow);
|
||||||
|
Loading…
Reference in New Issue
Block a user