diff options
Diffstat (limited to 'src/widgets/widgets/qtoolbararealayout.cpp')
-rw-r--r-- | src/widgets/widgets/qtoolbararealayout.cpp | 220 |
1 files changed, 96 insertions, 124 deletions
diff --git a/src/widgets/widgets/qtoolbararealayout.cpp b/src/widgets/widgets/qtoolbararealayout.cpp index edf497111b..54c21b6038 100644 --- a/src/widgets/widgets/qtoolbararealayout.cpp +++ b/src/widgets/widgets/qtoolbararealayout.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWidgets module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include <QWidgetItem> #include <QToolBar> @@ -91,7 +55,7 @@ bool QToolBarAreaLayoutItem::skip() const { if (gap) return false; - return widgetItem == 0 || widgetItem->isEmpty(); + return widgetItem == nullptr || widgetItem->isEmpty(); } /****************************************************************************** @@ -106,7 +70,7 @@ QToolBarAreaLayoutLine::QToolBarAreaLayoutLine(Qt::Orientation orientation) QSize QToolBarAreaLayoutLine::sizeHint() const { int a = 0, b = 0; - for (int i = 0; i < toolBarItems.count(); ++i) { + for (int i = 0; i < toolBarItems.size(); ++i) { const QToolBarAreaLayoutItem &item = toolBarItems.at(i); if (item.skip()) continue; @@ -126,7 +90,7 @@ QSize QToolBarAreaLayoutLine::sizeHint() const QSize QToolBarAreaLayoutLine::minimumSize() const { int a = 0, b = 0; - for (int i = 0; i < toolBarItems.count(); ++i) { + for (int i = 0; i < toolBarItems.size(); ++i) { const QToolBarAreaLayoutItem &item = toolBarItems[i]; if (item.skip()) continue; @@ -150,7 +114,7 @@ void QToolBarAreaLayoutLine::fitLayout() int space = pick(o, rect.size()); int extra = qMax(0, space - min); - for (int i = 0; i < toolBarItems.count(); ++i) { + for (int i = 0; i < toolBarItems.size(); ++i) { QToolBarAreaLayoutItem &item = toolBarItems[i]; if (item.skip()) continue; @@ -173,7 +137,7 @@ void QToolBarAreaLayoutLine::fitLayout() // calculate the positions from the sizes int pos = 0; - for (int i = 0; i < toolBarItems.count(); ++i) { + for (int i = 0; i < toolBarItems.size(); ++i) { QToolBarAreaLayoutItem &item = toolBarItems[i]; if (item.skip()) continue; @@ -187,7 +151,7 @@ void QToolBarAreaLayoutLine::fitLayout() bool QToolBarAreaLayoutLine::skip() const { - for (int i = 0; i < toolBarItems.count(); ++i) { + for (int i = 0; i < toolBarItems.size(); ++i) { if (!toolBarItems.at(i).skip()) return false; } @@ -219,7 +183,7 @@ QToolBarAreaLayoutInfo::QToolBarAreaLayoutInfo(QInternal::DockPosition pos) QSize QToolBarAreaLayoutInfo::sizeHint() const { int a = 0, b = 0; - for (int i = 0; i < lines.count(); ++i) { + for (int i = 0; i < lines.size(); ++i) { const QToolBarAreaLayoutLine &l = lines.at(i); if (l.skip()) continue; @@ -239,7 +203,7 @@ QSize QToolBarAreaLayoutInfo::sizeHint() const QSize QToolBarAreaLayoutInfo::minimumSize() const { int a = 0, b = 0; - for (int i = 0; i < lines.count(); ++i) { + for (int i = 0; i < lines.size(); ++i) { const QToolBarAreaLayoutLine &l = lines.at(i); if (l.skip()) continue; @@ -264,9 +228,9 @@ void QToolBarAreaLayoutInfo::fitLayout() bool reverse = dockPos == QInternal::RightDock || dockPos == QInternal::BottomDock; - int i = reverse ? lines.count() - 1 : 0; + int i = reverse ? lines.size() - 1 : 0; for (;;) { - if ((reverse && i < 0) || (!reverse && i == lines.count())) + if ((reverse && i < 0) || (!reverse && i == lines.size())) break; QToolBarAreaLayoutLine &l = lines[i]; @@ -302,17 +266,17 @@ QLayoutItem *QToolBarAreaLayoutInfo::insertToolBar(QToolBar *before, QToolBar *t void QToolBarAreaLayoutInfo::insertItem(QToolBar *before, QLayoutItem *item) { - if (before == 0) { + if (before == nullptr) { if (lines.isEmpty()) lines.append(QToolBarAreaLayoutLine(o)); lines.last().toolBarItems.append(item); return; } - for (int j = 0; j < lines.count(); ++j) { + for (int j = 0; j < lines.size(); ++j) { QToolBarAreaLayoutLine &line = lines[j]; - for (int k = 0; k < line.toolBarItems.count(); ++k) { + for (int k = 0; k < line.toolBarItems.size(); ++k) { if (line.toolBarItems.at(k).widgetItem->widget() == before) { line.toolBarItems.insert(k, item); return; @@ -323,17 +287,17 @@ void QToolBarAreaLayoutInfo::insertItem(QToolBar *before, QLayoutItem *item) void QToolBarAreaLayoutInfo::removeToolBar(QToolBar *toolBar) { - for (int j = 0; j < lines.count(); ++j) { + for (int j = 0; j < lines.size(); ++j) { QToolBarAreaLayoutLine &line = lines[j]; - for (int k = 0; k < line.toolBarItems.count(); ++k) { + for (int k = 0; k < line.toolBarItems.size(); ++k) { QToolBarAreaLayoutItem &item = line.toolBarItems[k]; if (item.widgetItem->widget() == toolBar) { delete item.widgetItem; - item.widgetItem = 0; + item.widgetItem = nullptr; line.toolBarItems.removeAt(k); - if (line.toolBarItems.isEmpty() && j < lines.count() - 1) + if (line.toolBarItems.isEmpty() && j < lines.size() - 1) lines.removeAt(j); return; @@ -344,17 +308,17 @@ void QToolBarAreaLayoutInfo::removeToolBar(QToolBar *toolBar) void QToolBarAreaLayoutInfo::insertToolBarBreak(QToolBar *before) { - if (before == 0) { + if (before == nullptr) { if (!lines.isEmpty() && lines.constLast().toolBarItems.isEmpty()) return; lines.append(QToolBarAreaLayoutLine(o)); return; } - for (int j = 0; j < lines.count(); ++j) { + for (int j = 0; j < lines.size(); ++j) { QToolBarAreaLayoutLine &line = lines[j]; - for (int k = 0; k < line.toolBarItems.count(); ++k) { + for (int k = 0; k < line.toolBarItems.size(); ++k) { if (line.toolBarItems.at(k).widgetItem->widget() == before) { if (k == 0) return; @@ -372,10 +336,10 @@ void QToolBarAreaLayoutInfo::insertToolBarBreak(QToolBar *before) void QToolBarAreaLayoutInfo::removeToolBarBreak(QToolBar *before) { - for (int j = 0; j < lines.count(); ++j) { + for (int j = 0; j < lines.size(); ++j) { const QToolBarAreaLayoutLine &line = lines.at(j); - for (int k = 0; k < line.toolBarItems.count(); ++k) { + for (int k = 0; k < line.toolBarItems.size(); ++k) { if (line.toolBarItems.at(k).widgetItem->widget() == before) { if (k != 0) return; @@ -402,12 +366,12 @@ void QToolBarAreaLayoutInfo::moveToolBar(QToolBar *toolbar, int pos) pos -= rect.top(); //here we actually update the preferredSize for the line containing the toolbar so that we move it - for (int j = 0; j < lines.count(); ++j) { + for (int j = 0; j < lines.size(); ++j) { QToolBarAreaLayoutLine &line = lines[j]; int previousIndex = -1; int minPos = 0; - for (int k = 0; k < line.toolBarItems.count(); ++k) { + for (int k = 0; k < line.toolBarItems.size(); ++k) { QToolBarAreaLayoutItem ¤t = line.toolBarItems[k]; if (current.widgetItem->widget() == toolbar) { int newPos = current.pos; @@ -419,7 +383,7 @@ void QToolBarAreaLayoutInfo::moveToolBar(QToolBar *toolbar, int pos) } else { //we check the max value for the position (until everything at the right is "compressed") int maxPos = pick(o, rect.size()); - for(int l = k; l < line.toolBarItems.count(); ++l) { + for(int l = k; l < line.toolBarItems.size(); ++l) { const QToolBarAreaLayoutItem &item = line.toolBarItems.at(l); if (!item.skip()) { maxPos -= pick(o, item.minimumSize()); @@ -487,7 +451,7 @@ QList<int> QToolBarAreaLayoutInfo::gapIndex(const QPoint &pos, int *minDistance) // Since we're comparing p with item.pos, we put them in the same coordinate system. const int p = pick(o, pos - rect.topLeft()); - for (int j = 0; j < lines.count(); ++j) { + for (int j = 0; j < lines.size(); ++j) { const QToolBarAreaLayoutLine &line = lines.at(j); if (line.skip()) continue; @@ -495,7 +459,7 @@ QList<int> QToolBarAreaLayoutInfo::gapIndex(const QPoint &pos, int *minDistance) continue; int k = 0; - for (; k < line.toolBarItems.count(); ++k) { + for (; k < line.toolBarItems.size(); ++k) { const QToolBarAreaLayoutItem &item = line.toolBarItems.at(k); if (item.skip()) continue; @@ -521,7 +485,7 @@ QList<int> QToolBarAreaLayoutInfo::gapIndex(const QPoint &pos, int *minDistance) *minDistance = dist; QList<int> result; - result << lines.count() << 0; + result << lines.size() << 0; return result; } } @@ -531,9 +495,9 @@ QList<int> QToolBarAreaLayoutInfo::gapIndex(const QPoint &pos, int *minDistance) bool QToolBarAreaLayoutInfo::insertGap(const QList<int> &path, QLayoutItem *item) { - Q_ASSERT(path.count() == 2); + Q_ASSERT(path.size() == 2); int j = path.first(); - if (j == lines.count()) + if (j == lines.size()) lines.append(QToolBarAreaLayoutLine(o)); QToolBarAreaLayoutLine &line = lines[j]; @@ -576,7 +540,7 @@ void QToolBarAreaLayoutInfo::clear() QRect QToolBarAreaLayoutInfo::itemRect(const QList<int> &path) const { - Q_ASSERT(path.count() == 2); + Q_ASSERT(path.size() == 2); int j = path.at(0); int k = path.at(1); @@ -729,35 +693,35 @@ QRect QToolBarAreaLayout::rectHint(const QRect &r) const QLayoutItem *QToolBarAreaLayout::itemAt(int *x, int index) const { - Q_ASSERT(x != 0); + Q_ASSERT(x != nullptr); for (int i = 0; i < QInternal::DockCount; ++i) { const QToolBarAreaLayoutInfo &dock = docks[i]; - for (int j = 0; j < dock.lines.count(); ++j) { + for (int j = 0; j < dock.lines.size(); ++j) { const QToolBarAreaLayoutLine &line = dock.lines.at(j); - for (int k = 0; k < line.toolBarItems.count(); ++k) { + for (int k = 0; k < line.toolBarItems.size(); ++k) { if ((*x)++ == index) return line.toolBarItems.at(k).widgetItem; } } } - return 0; + return nullptr; } QLayoutItem *QToolBarAreaLayout::takeAt(int *x, int index) { - Q_ASSERT(x != 0); + Q_ASSERT(x != nullptr); for (int i = 0; i < QInternal::DockCount; ++i) { QToolBarAreaLayoutInfo &dock = docks[i]; - for (int j = 0; j < dock.lines.count(); ++j) { + for (int j = 0; j < dock.lines.size(); ++j) { QToolBarAreaLayoutLine &line = dock.lines[j]; - for (int k = 0; k < line.toolBarItems.count(); ++k) { + for (int k = 0; k < line.toolBarItems.size(); ++k) { if ((*x)++ == index) { QLayoutItem *result = line.toolBarItems.takeAt(k).widgetItem; if (line.toolBarItems.isEmpty()) @@ -768,7 +732,7 @@ QLayoutItem *QToolBarAreaLayout::takeAt(int *x, int index) } } - return 0; + return nullptr; } void QToolBarAreaLayout::deleteAllLayoutItems() @@ -776,28 +740,28 @@ void QToolBarAreaLayout::deleteAllLayoutItems() for (int i = 0; i < QInternal::DockCount; ++i) { QToolBarAreaLayoutInfo &dock = docks[i]; - for (int j = 0; j < dock.lines.count(); ++j) { + for (int j = 0; j < dock.lines.size(); ++j) { QToolBarAreaLayoutLine &line = dock.lines[j]; - for (int k = 0; k < line.toolBarItems.count(); ++k) { + for (int k = 0; k < line.toolBarItems.size(); ++k) { QToolBarAreaLayoutItem &item = line.toolBarItems[k]; if (!item.gap) delete item.widgetItem; - item.widgetItem = 0; + item.widgetItem = nullptr; } } } } -QInternal::DockPosition QToolBarAreaLayout::findToolBar(QToolBar *toolBar) const +QInternal::DockPosition QToolBarAreaLayout::findToolBar(const QToolBar *toolBar) const { for (int i = 0; i < QInternal::DockCount; ++i) { const QToolBarAreaLayoutInfo &dock = docks[i]; - for (int j = 0; j < dock.lines.count(); ++j) { + for (int j = 0; j < dock.lines.size(); ++j) { const QToolBarAreaLayoutLine &line = dock.lines.at(j); - for (int k = 0; k < line.toolBarItems.count(); ++k) { + for (int k = 0; k < line.toolBarItems.size(); ++k) { if (line.toolBarItems.at(k).widgetItem->widget() == toolBar) return static_cast<QInternal::DockPosition>(i); } @@ -811,7 +775,7 @@ QLayoutItem *QToolBarAreaLayout::insertToolBar(QToolBar *before, QToolBar *toolB { QInternal::DockPosition pos = findToolBar(before); if (pos == QInternal::DockCount) - return 0; + return nullptr; return docks[pos].insertToolBar(before, toolBar); } @@ -826,7 +790,7 @@ void QToolBarAreaLayout::removeToolBar(QToolBar *toolBar) QLayoutItem *QToolBarAreaLayout::addToolBar(QInternal::DockPosition pos, QToolBar *toolBar) { - return docks[pos].insertToolBar(0, toolBar); + return docks[pos].insertToolBar(nullptr, toolBar); } void QToolBarAreaLayout::insertToolBarBreak(QToolBar *before) @@ -847,7 +811,7 @@ void QToolBarAreaLayout::removeToolBarBreak(QToolBar *before) void QToolBarAreaLayout::addToolBarBreak(QInternal::DockPosition pos) { - docks[pos].insertToolBarBreak(0); + docks[pos].insertToolBarBreak(nullptr); } void QToolBarAreaLayout::moveToolBar(QToolBar *toolbar, int p) @@ -878,19 +842,19 @@ void QToolBarAreaLayout::insertItem(QToolBar *before, QLayoutItem *item) void QToolBarAreaLayout::apply(bool animate) { QMainWindowLayout *layout = qt_mainwindow_layout(mainWindow); - Q_ASSERT(layout != 0); + Q_ASSERT(layout != nullptr); Qt::LayoutDirection dir = mainWindow->layoutDirection(); for (int i = 0; i < QInternal::DockCount; ++i) { const QToolBarAreaLayoutInfo &dock = docks[i]; - for (int j = 0; j < dock.lines.count(); ++j) { + for (int j = 0; j < dock.lines.size(); ++j) { const QToolBarAreaLayoutLine &line = dock.lines.at(j); if (line.skip()) continue; - for (int k = 0; k < line.toolBarItems.count(); ++k) { + for (int k = 0; k < line.toolBarItems.size(); ++k) { const QToolBarAreaLayoutItem &item = line.toolBarItems.at(k); if (item.skip() || item.gap) continue; @@ -943,10 +907,10 @@ bool QToolBarAreaLayout::toolBarBreak(QToolBar *toolBar) const for (int i = 0; i < QInternal::DockCount; ++i) { const QToolBarAreaLayoutInfo &dock = docks[i]; - for (int j = 0; j < dock.lines.count(); ++j) { + for (int j = 0; j < dock.lines.size(); ++j) { const QToolBarAreaLayoutLine &line = dock.lines.at(j); - for (int k = 0; k < line.toolBarItems.count(); ++k) { + for (int k = 0; k < line.toolBarItems.size(); ++k) { if (line.toolBarItems.at(k).widgetItem->widget() == toolBar) return j > 0 && k == 0; } @@ -961,25 +925,25 @@ void QToolBarAreaLayout::getStyleOptionInfo(QStyleOptionToolBar *option, QToolBa for (int i = 0; i < QInternal::DockCount; ++i) { const QToolBarAreaLayoutInfo &dock = docks[i]; - for (int j = 0; j < dock.lines.count(); ++j) { + for (int j = 0; j < dock.lines.size(); ++j) { const QToolBarAreaLayoutLine &line = dock.lines.at(j); - for (int k = 0; k < line.toolBarItems.count(); ++k) { + for (int k = 0; k < line.toolBarItems.size(); ++k) { if (line.toolBarItems.at(k).widgetItem->widget() == toolBar) { - if (line.toolBarItems.count() == 1) + if (line.toolBarItems.size() == 1) option->positionWithinLine = QStyleOptionToolBar::OnlyOne; else if (k == 0) option->positionWithinLine = QStyleOptionToolBar::Beginning; - else if (k == line.toolBarItems.count() - 1) + else if (k == line.toolBarItems.size() - 1) option->positionWithinLine = QStyleOptionToolBar::End; else option->positionWithinLine = QStyleOptionToolBar::Middle; - if (dock.lines.count() == 1) + if (dock.lines.size() == 1) option->positionOfLine = QStyleOptionToolBar::OnlyOne; else if (j == 0) option->positionOfLine = QStyleOptionToolBar::Beginning; - else if (j == dock.lines.count() - 1) + else if (j == dock.lines.size() - 1) option->positionOfLine = QStyleOptionToolBar::End; else option->positionOfLine = QStyleOptionToolBar::Middle; @@ -1000,10 +964,10 @@ QList<int> QToolBarAreaLayout::indexOf(QWidget *toolBar) const for (int i = 0; i < QInternal::DockCount; ++i) { const QToolBarAreaLayoutInfo &dock = docks[i]; - for (int j = 0; j < dock.lines.count(); ++j) { + for (int j = 0; j < dock.lines.size(); ++j) { const QToolBarAreaLayoutLine &line = dock.lines.at(j); - for (int k = 0; k < line.toolBarItems.count(); ++k) { + for (int k = 0; k < line.toolBarItems.size(); ++k) { const QToolBarAreaLayoutItem &item = line.toolBarItems.at(k); if (!item.gap && item.widgetItem->widget() == toolBar) { found = true; @@ -1052,10 +1016,10 @@ QList<int> QToolBarAreaLayout::currentGapIndex() const for (int i = 0; i < QInternal::DockCount; ++i) { const QToolBarAreaLayoutInfo &dock = docks[i]; - for (int j = 0; j < dock.lines.count(); ++j) { + for (int j = 0; j < dock.lines.size(); ++j) { const QToolBarAreaLayoutLine &line = dock.lines[j]; - for (int k = 0; k < line.toolBarItems.count(); k++) { + for (int k = 0; k < line.toolBarItems.size(); k++) { if (line.toolBarItems[k].gap) { QList<int> result; result << i << j << k; @@ -1069,7 +1033,7 @@ QList<int> QToolBarAreaLayout::currentGapIndex() const bool QToolBarAreaLayout::insertGap(const QList<int> &path, QLayoutItem *item) { - Q_ASSERT(path.count() == 3); + Q_ASSERT(path.size() == 3); const int i = path.first(); Q_ASSERT(i >= 0 && i < QInternal::DockCount); return docks[i].insertGap(path.mid(1), item); @@ -1077,8 +1041,12 @@ bool QToolBarAreaLayout::insertGap(const QList<int> &path, QLayoutItem *item) void QToolBarAreaLayout::remove(const QList<int> &path) { - Q_ASSERT(path.count() == 3); - docks[path.at(0)].lines[path.at(1)].toolBarItems.removeAt(path.at(2)); + Q_ASSERT(path.size() == 3); + QToolBarAreaLayoutInfo &dock = docks[path.at(0)]; + QToolBarAreaLayoutLine &line = dock.lines[path.at(1)]; + line.toolBarItems.removeAt(path.at(2)); + if (line.toolBarItems.isEmpty()) + dock.lines.removeAt(path.at(1)); } void QToolBarAreaLayout::remove(QLayoutItem *item) @@ -1086,10 +1054,10 @@ void QToolBarAreaLayout::remove(QLayoutItem *item) for (int i = 0; i < QInternal::DockCount; ++i) { QToolBarAreaLayoutInfo &dock = docks[i]; - for (int j = 0; j < dock.lines.count(); ++j) { + for (int j = 0; j < dock.lines.size(); ++j) { QToolBarAreaLayoutLine &line = dock.lines[j]; - for (int k = 0; k < line.toolBarItems.count(); k++) { + for (int k = 0; k < line.toolBarItems.size(); k++) { if (line.toolBarItems[k].widgetItem == item) { line.toolBarItems.removeAt(k); if (line.toolBarItems.isEmpty()) @@ -1110,16 +1078,16 @@ void QToolBarAreaLayout::clear() QToolBarAreaLayoutItem *QToolBarAreaLayout::item(const QList<int> &path) { - Q_ASSERT(path.count() == 3); + Q_ASSERT(path.size() == 3); if (path.at(0) < 0 || path.at(0) >= QInternal::DockCount) - return 0; + return nullptr; QToolBarAreaLayoutInfo &info = docks[path.at(0)]; - if (path.at(1) < 0 || path.at(1) >= info.lines.count()) - return 0; + if (path.at(1) < 0 || path.at(1) >= info.lines.size()) + return nullptr; QToolBarAreaLayoutLine &line = info.lines[path.at(1)]; - if (path.at(2) < 0 || path.at(2) >= line.toolBarItems.count()) - return 0; + if (path.at(2) < 0 || path.at(2) >= line.toolBarItems.size()) + return nullptr; return &(line.toolBarItems[path.at(2)]); } @@ -1139,10 +1107,10 @@ QLayoutItem *QToolBarAreaLayout::plug(const QList<int> &path) QToolBarAreaLayoutItem *item = this->item(path); if (Q_UNLIKELY(!item)) { qWarning() << "No item at" << path; - return 0; + return nullptr; } Q_ASSERT(item->gap); - Q_ASSERT(item->widgetItem != 0); + Q_ASSERT(item->widgetItem != nullptr); item->gap = false; return item->widgetItem; } @@ -1150,7 +1118,7 @@ QLayoutItem *QToolBarAreaLayout::plug(const QList<int> &path) QLayoutItem *QToolBarAreaLayout::unplug(const QList<int> &path, QToolBarAreaLayout *other) { //other needs to be update as well - Q_ASSERT(path.count() == 3); + Q_ASSERT(path.size() == 3); QToolBarAreaLayoutItem *item = this->item(path); Q_ASSERT(item); @@ -1168,7 +1136,7 @@ QLayoutItem *QToolBarAreaLayout::unplug(const QList<int> &path, QToolBarAreaLayo if (!previous.skip()) { //we need to check if it has a previous element and a next one //the previous will get its size changed - for (int j = path.at(2) + 1; j < line.toolBarItems.count(); ++j) { + for (int j = path.at(2) + 1; j < line.toolBarItems.size(); ++j) { const QToolBarAreaLayoutItem &next = line.toolBarItems.at(j); if (!next.skip()) { newExtraSpace = next.pos - previous.pos - pick(line.o, previous.sizeHint()); @@ -1253,19 +1221,19 @@ void QToolBarAreaLayout::saveState(QDataStream &stream) const int lineCount = 0; for (int i = 0; i < QInternal::DockCount; ++i) - lineCount += docks[i].lines.count(); + lineCount += docks[i].lines.size(); stream << lineCount; for (int i = 0; i < QInternal::DockCount; ++i) { const QToolBarAreaLayoutInfo &dock = docks[i]; - for (int j = 0; j < dock.lines.count(); ++j) { + for (int j = 0; j < dock.lines.size(); ++j) { const QToolBarAreaLayoutLine &line = dock.lines.at(j); - stream << i << line.toolBarItems.count(); + stream << i << int(line.toolBarItems.size()); - for (int k = 0; k < line.toolBarItems.count(); ++k) { + for (int k = 0; k < line.toolBarItems.size(); ++k) { const QToolBarAreaLayoutItem &item = line.toolBarItems.at(k); QWidget *widget = const_cast<QLayoutItem*>(item.widgetItem)->widget(); QString objectName = widget->objectName(); @@ -1348,22 +1316,26 @@ bool QToolBarAreaLayout::restoreState(QDataStream &stream, const QList<QToolBar* rect = unpackRect(geom0, geom1, &floating); } - QToolBar *toolBar = 0; - for (int x = 0; x < toolBars.count(); ++x) { + QToolBar *toolBar = nullptr; + for (int x = 0; x < toolBars.size(); ++x) { if (toolBars.at(x)->objectName() == objectName) { toolBar = toolBars.takeAt(x); break; } } - if (toolBar == 0) { + if (toolBar == nullptr) { continue; } if (applyingLayout) { + // Clear the previous widgetItem for the toolBar, so that it's + // assigned correctly in QWidgetItemV2 constructor. + auto *toolBarPrivate = QWidgetPrivate::get(toolBar); + toolBarPrivate->widgetItem = nullptr; item.widgetItem = new QWidgetItemV2(toolBar); toolBar->setOrientation(floating ? ((shown & 2) ? Qt::Vertical : Qt::Horizontal) : dock.o); toolBar->setVisible(shown & 1); - toolBar->d_func()->setWindowState(floating, true, rect); + toolBar->d_func()->setWindowState(floating, false, rect); item.preferredSize = item.size; line.toolBarItems.append(item); |