diff options
author | Thierry Bastian <thierry.bastian@nokia.com> | 2009-06-24 16:03:28 (GMT) |
---|---|---|
committer | Thierry Bastian <thierry.bastian@nokia.com> | 2009-06-24 16:04:43 (GMT) |
commit | 117b9bb3d576d9974b3d05174d1fccf98e47cb22 (patch) | |
tree | 47e8fd427dfc17e2709f898e16d873450e2ca4b6 /src/gui/widgets/qtoolbararealayout.cpp | |
parent | 962d3938380dde01e2bd4915c51c95f47fafa0ec (diff) | |
download | Qt-117b9bb3d576d9974b3d05174d1fccf98e47cb22.zip Qt-117b9bb3d576d9974b3d05174d1fccf98e47cb22.tar.gz Qt-117b9bb3d576d9974b3d05174d1fccf98e47cb22.tar.bz2 |
QDockWidget/Toolbars refactor to avoid list copies
This also helps understanding the code better.
Diffstat (limited to 'src/gui/widgets/qtoolbararealayout.cpp')
-rw-r--r-- | src/gui/widgets/qtoolbararealayout.cpp | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/src/gui/widgets/qtoolbararealayout.cpp b/src/gui/widgets/qtoolbararealayout.cpp index 8a10355..db2afd6 100644 --- a/src/gui/widgets/qtoolbararealayout.cpp +++ b/src/gui/widgets/qtoolbararealayout.cpp @@ -526,9 +526,10 @@ QList<int> QToolBarAreaLayoutInfo::gapIndex(const QPoint &pos) const return QList<int>(); } -bool QToolBarAreaLayoutInfo::insertGap(QList<int> path, QLayoutItem *item) +bool QToolBarAreaLayoutInfo::insertGap(const QList<int> &path, QLayoutItem *item) { - int j = path.at(0); + Q_ASSERT(path.count() == 2); + int j = path.first(); if (j == lines.count()) lines.append(QToolBarAreaLayoutLine(o)); @@ -570,8 +571,9 @@ void QToolBarAreaLayoutInfo::clear() rect = QRect(); } -QRect QToolBarAreaLayoutInfo::itemRect(QList<int> path) const +QRect QToolBarAreaLayoutInfo::itemRect(const QList<int> &path) const { + Q_ASSERT(path.count() == 2); int j = path.at(0); int k = path.at(1); @@ -623,10 +625,8 @@ QRect QToolBarAreaLayoutInfo::appendLineDropRect() const ** QToolBarAreaLayout */ -QToolBarAreaLayout::QToolBarAreaLayout(QMainWindow *win) +QToolBarAreaLayout::QToolBarAreaLayout(const QMainWindow *win) : mainWindow(win), visible(true) { - visible = true; - mainWindow = win; for (int i = 0; i < QInternal::DockCount; ++i) { QInternal::DockPosition pos = static_cast<QInternal::DockPosition>(i); docks[i] = QToolBarAreaLayoutInfo(pos); @@ -1064,16 +1064,17 @@ QList<int> QToolBarAreaLayout::currentGapIndex() const return QList<int>(); } -bool QToolBarAreaLayout::insertGap(QList<int> path, QLayoutItem *item) +bool QToolBarAreaLayout::insertGap(const QList<int> &path, QLayoutItem *item) { - Q_ASSERT(!path.isEmpty()); - int i = path.takeFirst(); + Q_ASSERT(path.count() == 3); + const int i = path.first(); Q_ASSERT(i >= 0 && i < QInternal::DockCount); - return docks[i].insertGap(path, item); + return docks[i].insertGap(path.mid(1), item); } -void QToolBarAreaLayout::remove(QList<int> path) +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)); } @@ -1104,7 +1105,7 @@ void QToolBarAreaLayout::clear() rect = QRect(); } -QToolBarAreaLayoutItem &QToolBarAreaLayout::item(QList<int> path) +QToolBarAreaLayoutItem &QToolBarAreaLayout::item(const QList<int> &path) { Q_ASSERT(path.count() == 3); @@ -1116,18 +1117,18 @@ QToolBarAreaLayoutItem &QToolBarAreaLayout::item(QList<int> path) return line.toolBarItems[path.at(2)]; } -QRect QToolBarAreaLayout::itemRect(QList<int> path) const +QRect QToolBarAreaLayout::itemRect(const QList<int> &path) const { - int i = path.takeFirst(); + const int i = path.first(); - QRect r = docks[i].itemRect(path); + QRect r = docks[i].itemRect(path.mid(1)); if (docks[i].o == Qt::Horizontal) r = QStyle::visualRect(mainWindow->layoutDirection(), docks[i].rect, r); return r; } -QLayoutItem *QToolBarAreaLayout::plug(QList<int> path) +QLayoutItem *QToolBarAreaLayout::plug(const QList<int> &path) { QToolBarAreaLayoutItem &item = this->item(path); Q_ASSERT(item.gap); @@ -1136,9 +1137,10 @@ QLayoutItem *QToolBarAreaLayout::plug(QList<int> path) return item.widgetItem; } -QLayoutItem *QToolBarAreaLayout::unplug(QList<int> path, QToolBarAreaLayout *other) +QLayoutItem *QToolBarAreaLayout::unplug(const QList<int> &path, QToolBarAreaLayout *other) { //other needs to be update as well + Q_ASSERT(path.count() == 3); QToolBarAreaLayoutItem &item = this->item(path); //update the leading space here |