diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2015-12-30 02:04:26 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2016-02-26 18:56:43 +0000 |
commit | 1d8030cc64df2cdfdc0faf3d06ea7d9ed0306948 (patch) | |
tree | 86e7246682e6bb4345a1fd5e5f54352a5eea592e /src/widgets/widgets/qmainwindowlayout.cpp | |
parent | bc5917a10a16dd33b8c12c61db981f0328882049 (diff) |
QtWidgets: prevent detach attempts from first()/etc. use [dialogs, kernel, util, widgets]
The algorithm used was:
- If possible, just declare the container const
- Otherwise, for first()/last(), use constFirst()/constLast()
and for front()/back(), to not destroy the use of the STL
API subset, use qAsConst()
Did some caching of function returns here and there, and
converted one 0 to nullptr as a drive-by.
Also saves almost 4KiB in text size on optimized GCC 4.9
Linux AMD64 builds.
Change-Id: I04b7bfd68dc85c22de247cb65a310e1cbbca1e8c
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Diffstat (limited to 'src/widgets/widgets/qmainwindowlayout.cpp')
-rw-r--r-- | src/widgets/widgets/qmainwindowlayout.cpp | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/widgets/widgets/qmainwindowlayout.cpp b/src/widgets/widgets/qmainwindowlayout.cpp index ae87ea526d..e46063917d 100644 --- a/src/widgets/widgets/qmainwindowlayout.cpp +++ b/src/widgets/widgets/qmainwindowlayout.cpp @@ -1163,7 +1163,7 @@ void QMainWindowLayout::insertToolBar(QToolBar *before, QToolBar *toolbar) // copy the toolbar also in the saved state savedState.toolBarAreaLayout.insertItem(before, item); } - if (!currentGapPos.isEmpty() && currentGapPos.first() == 0) { + if (!currentGapPos.isEmpty() && currentGapPos.constFirst() == 0) { currentGapPos = layoutState.toolBarAreaLayout.currentGapIndex(); if (!currentGapPos.isEmpty()) { currentGapPos.prepend(0); @@ -1501,7 +1501,7 @@ void QMainWindowLayout::splitDockWidget(QDockWidget *after, Qt::DockWidgetArea QMainWindowLayout::dockWidgetArea(QWidget *widget) const { - QList<int> pathToWidget = layoutState.dockAreaLayout.indexOf(widget); + const QList<int> pathToWidget = layoutState.dockAreaLayout.indexOf(widget); if (pathToWidget.isEmpty()) return Qt::NoDockWidgetArea; return toDockWidgetArea(pathToWidget.first()); @@ -1783,7 +1783,7 @@ QLayoutItem *QMainWindowLayout::takeAt(int index) } #ifndef QT_NO_TOOLBAR - if (!currentGapPos.isEmpty() && currentGapPos.first() == 0) { + if (!currentGapPos.isEmpty() && currentGapPos.constFirst() == 0) { currentGapPos = layoutState.toolBarAreaLayout.currentGapIndex(); if (!currentGapPos.isEmpty()) { currentGapPos.prepend(0); @@ -2057,7 +2057,7 @@ void QMainWindowLayout::animationFinished(QWidget *widget) if (parentInfo->tabbed) { // merge the two tab widgets - int idx = path.last(); + int idx = path.constLast(); Q_ASSERT(parentInfo->item_list[idx].widgetItem->widget() == dwgw); delete parentInfo->item_list[idx].widgetItem; parentInfo->item_list.removeAt(idx); @@ -2283,7 +2283,7 @@ QLayoutItem *QMainWindowLayout::unplug(QWidget *widget, bool group) #ifndef QT_NO_DOCKWIDGET if (QDockWidget *dw = qobject_cast<QDockWidget*>(widget)) { - Q_ASSERT(path.first() == 1); + Q_ASSERT(path.constFirst() == 1); bool actualGroup = false; #ifndef QT_NO_TABBAR if (group && (dockOptions & QMainWindow::GroupedDragging) && path.size() > 3) { |