summaryrefslogtreecommitdiffstats
path: root/src/widgets/itemviews
diff options
context:
space:
mode:
authorAnton Kudryavtsev <a.kudryavtsev@netris.ru>2016-07-05 12:12:45 +0300
committerAnton Kudryavtsev <a.kudryavtsev@netris.ru>2016-07-05 18:58:51 +0000
commitb073ba57f821b2e79c553f974d9fba2cbb034ee9 (patch)
treeaaf3ca06f251ce52591438ccec83924739693813 /src/widgets/itemviews
parentf217894152a29d4be14aaf604ee4230cb40b9c97 (diff)
Widgets: use const (and const APIs) more
For CoW types, prefer const methods to avoid needless detach()ing. Change-Id: Ia6cad50a10facf6fd4f73d1390edb8642a0aed32 Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Diffstat (limited to 'src/widgets/itemviews')
-rw-r--r--src/widgets/itemviews/qcolumnview.cpp20
-rw-r--r--src/widgets/itemviews/qdirmodel.cpp2
-rw-r--r--src/widgets/itemviews/qlistview.cpp6
-rw-r--r--src/widgets/itemviews/qtreeview.cpp8
4 files changed, 18 insertions, 18 deletions
diff --git a/src/widgets/itemviews/qcolumnview.cpp b/src/widgets/itemviews/qcolumnview.cpp
index 26173b5e92..6c7c914bc0 100644
--- a/src/widgets/itemviews/qcolumnview.cpp
+++ b/src/widgets/itemviews/qcolumnview.cpp
@@ -412,9 +412,9 @@ void QColumnViewPrivate::updateScrollbars()
// find the total horizontal length of the laid out columns
int horizontalLength = 0;
if (!columns.isEmpty()) {
- horizontalLength = (columns.last()->x() + columns.last()->width()) - columns.first()->x();
+ horizontalLength = (columns.constLast()->x() + columns.constLast()->width()) - columns.constFirst()->x();
if (horizontalLength <= 0) // reverse mode
- horizontalLength = (columns.first()->x() + columns.first()->width()) - columns.last()->x();
+ horizontalLength = (columns.constFirst()->x() + columns.constFirst()->width()) - columns.constLast()->x();
}
QSize viewportSize = viewport->size();
@@ -629,7 +629,7 @@ void QColumnViewPrivate::closeColumns(const QModelIndex &parent, bool build)
while (!dirsToAppend.isEmpty()) {
QAbstractItemView *newView = createColumn(dirsToAppend.takeLast(), true);
if (!dirsToAppend.isEmpty())
- newView->setCurrentIndex(dirsToAppend.last());
+ newView->setCurrentIndex(dirsToAppend.constLast());
}
if (build && !alreadyExists)
@@ -713,8 +713,8 @@ QAbstractItemView *QColumnViewPrivate::createColumn(const QModelIndex &index, bo
columnSizes.resize(qMax(columnSizes.count(), columns.count() + 1));
columnSizes[columns.count()] = initialWidth;
}
- if (!columns.isEmpty() && columns.last()->isHidden())
- columns.last()->setVisible(true);
+ if (!columns.isEmpty() && columns.constLast()->isHidden())
+ columns.constLast()->setVisible(true);
columns.append(view);
doLayout();
@@ -835,7 +835,7 @@ void QColumnViewPrivate::setPreviewWidget(QWidget *widget)
{
Q_Q(QColumnView);
if (previewColumn) {
- if (!columns.isEmpty() && columns.last() == previewColumn)
+ if (!columns.isEmpty() && columns.constLast() == previewColumn)
columns.removeLast();
previewColumn->deleteLater();
}
@@ -1003,11 +1003,11 @@ void QColumnViewPrivate::_q_changeCurrentColumn()
parentColumn->setCurrentIndex(current.parent());
}
- if (columns.last()->isHidden()) {
- columns.last()->setVisible(true);
+ if (columns.constLast()->isHidden()) {
+ columns.constLast()->setVisible(true);
}
- if (columns.last()->selectionModel())
- columns.last()->selectionModel()->clear();
+ if (columns.constLast()->selectionModel())
+ columns.constLast()->selectionModel()->clear();
updateScrollbars();
}
diff --git a/src/widgets/itemviews/qdirmodel.cpp b/src/widgets/itemviews/qdirmodel.cpp
index dfb1d7619e..58e586980f 100644
--- a/src/widgets/itemviews/qdirmodel.cpp
+++ b/src/widgets/itemviews/qdirmodel.cpp
@@ -885,7 +885,7 @@ QModelIndex QDirModel::index(const QString &path, int column) const
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
if (absolutePath.startsWith(QLatin1String("//"))) { // UNC path
- QString host = pathElements.first();
+ QString host = pathElements.constFirst();
int r = 0;
for (; r < d->root.children.count(); ++r)
if (d->root.children.at(r).info.fileName() == host)
diff --git a/src/widgets/itemviews/qlistview.cpp b/src/widgets/itemviews/qlistview.cpp
index 3303aac6ed..0788e0287a 100644
--- a/src/widgets/itemviews/qlistview.cpp
+++ b/src/widgets/itemviews/qlistview.cpp
@@ -2396,9 +2396,9 @@ QPoint QListModeViewBase::initStaticLayout(const QListViewLayoutInfo &info)
} else if (info.wrap) {
if (info.flow == QListView::LeftToRight) {
x = batchSavedPosition;
- y = segmentPositions.last();
+ y = segmentPositions.constLast();
} else { // flow == QListView::TopToBottom
- x = segmentPositions.last();
+ x = segmentPositions.constLast();
y = batchSavedPosition;
}
} else { // not first and not wrap
@@ -2613,7 +2613,7 @@ int QListModeViewBase::perItemScrollingPageSteps(int length, int bounds, bool wr
int steps = positions.count() - 1;
int max = qMax(length, bounds);
int min = qMin(length, bounds);
- int pos = min - (max - positions.last());
+ int pos = min - (max - positions.constLast());
while (pos >= 0 && steps > 0) {
pos -= (positions.at(steps) - positions.at(steps - 1));
diff --git a/src/widgets/itemviews/qtreeview.cpp b/src/widgets/itemviews/qtreeview.cpp
index b6fd9f8ba8..4ce7da0229 100644
--- a/src/widgets/itemviews/qtreeview.cpp
+++ b/src/widgets/itemviews/qtreeview.cpp
@@ -2357,10 +2357,10 @@ void QTreeView::setSelection(const QRect &rect, QItemSelectionModel::SelectionFl
return;
}
if (!topLeft.isValid() && !d->viewItems.isEmpty())
- topLeft = d->viewItems.first().index;
+ topLeft = d->viewItems.constFirst().index;
if (!bottomRight.isValid() && !d->viewItems.isEmpty()) {
const int column = d->header->logicalIndex(d->header->count() - 1);
- const QModelIndex index = d->viewItems.last().index;
+ const QModelIndex index = d->viewItems.constLast().index;
bottomRight = index.sibling(index.row(), column);
}
@@ -2668,9 +2668,9 @@ void QTreeView::selectAll()
SelectionMode mode = d->selectionMode;
d->executePostedLayout(); //make sure we lay out the items
if (mode != SingleSelection && mode != NoSelection && !d->viewItems.isEmpty()) {
- const QModelIndex &idx = d->viewItems.last().index;
+ const QModelIndex &idx = d->viewItems.constLast().index;
QModelIndex lastItemIndex = idx.sibling(idx.row(), d->model->columnCount(idx.parent()) - 1);
- d->select(d->viewItems.first().index, lastItemIndex,
+ d->select(d->viewItems.constFirst().index, lastItemIndex,
QItemSelectionModel::ClearAndSelect
|QItemSelectionModel::Rows);
}