diff options
Diffstat (limited to 'src/widgets/itemviews/qlistview.cpp')
-rw-r--r-- | src/widgets/itemviews/qlistview.cpp | 45 |
1 files changed, 29 insertions, 16 deletions
diff --git a/src/widgets/itemviews/qlistview.cpp b/src/widgets/itemviews/qlistview.cpp index 9c79509874..6e432a9ad7 100644 --- a/src/widgets/itemviews/qlistview.cpp +++ b/src/widgets/itemviews/qlistview.cpp @@ -46,11 +46,14 @@ #include <qscrollbar.h> #include <qrubberband.h> #include <private/qlistview_p.h> +#include <private/qscrollbar_p.h> #include <qdebug.h> #ifndef QT_NO_ACCESSIBILITY #include <qaccessible.h> #endif +#include <algorithm> + QT_BEGIN_NAMESPACE extern bool qt_sendSpontaneousEvent(QObject *receiver, QEvent *event); @@ -392,7 +395,7 @@ int QListView::spacing() const void QListView::setBatchSize(int batchSize) { Q_D(QListView); - if (batchSize <= 0) { + if (Q_UNLIKELY(batchSize <= 0)) { qWarning("Invalid batchSize (%d)", batchSize); return; } @@ -649,12 +652,13 @@ QItemViewPaintPairs QListViewPrivate::draggablePaintPairs(const QModelIndexList QRect &rect = *r; const QRect viewportRect = viewport->rect(); QItemViewPaintPairs ret; - const QSet<QModelIndex> visibleIndexes = intersectingSet(viewportRect.translated(q->horizontalOffset(), q->verticalOffset())).toList().toSet(); - for (int i = 0; i < indexes.count(); ++i) { - const QModelIndex &index = indexes.at(i); - if (visibleIndexes.contains(index)) { + QVector<QModelIndex> visibleIndexes = intersectingSet(viewportRect.translated(q->horizontalOffset(), q->verticalOffset())); + std::sort(visibleIndexes.begin(), visibleIndexes.end()); + for (const auto &index : indexes) { + if (std::binary_search(visibleIndexes.cbegin(), visibleIndexes.cend(), index)) { const QRect current = q->visualRect(index); - ret += qMakePair(current, index); + QItemViewPaintPair p = { current, index }; + ret += p; rect |= current; } } @@ -1396,16 +1400,16 @@ QRegion QListView::visualRegionForSelection(const QItemSelection &selection) con int c = d->column; QRegion selectionRegion; const QRect &viewportRect = d->viewport->rect(); - for (int i = 0; i < selection.count(); ++i) { - if (!selection.at(i).isValid()) + for (const auto &elem : selection) { + if (!elem.isValid()) continue; - QModelIndex parent = selection.at(i).topLeft().parent(); + QModelIndex parent = elem.topLeft().parent(); //we only display the children of the root in a listview //we're not interested in the other model indexes if (parent != d->root) continue; - int t = selection.at(i).topLeft().row(); - int b = selection.at(i).bottomRight().row(); + int t = elem.topLeft().row(); + int b = elem.bottomRight().row(); if (d->viewMode == IconMode || d->isWrapping()) { // in non-static mode, we have to go through all selected items for (int r = t; r <= b; ++r) { const QRect &rect = visualRect(d->model->index(r, c, parent)); @@ -1842,6 +1846,16 @@ bool QListViewPrivate::dropOn(QDropEvent *event, int *dropRow, int *dropCol, QMo } #endif +void QListViewPrivate::removeCurrentAndDisabled(QVector<QModelIndex> *indexes, const QModelIndex ¤t) const +{ + auto isCurrentOrDisabled = [=](const QModelIndex &index) { + return !isIndexEnabled(index) || index == current; + }; + indexes->erase(std::remove_if(indexes->begin(), indexes->end(), + isCurrentOrDisabled), + indexes->end()); +} + /* * Common ListView Implementation */ @@ -1867,7 +1881,7 @@ void QCommonListViewBase::paintDragDrop(QPainter *painter) void QCommonListViewBase::updateHorizontalScrollBar(const QSize &step) { - horizontalScrollBar()->setSingleStep(step.width() + spacing()); + horizontalScrollBar()->d_func()->itemviewChangeSingleStep(step.width() + spacing()); horizontalScrollBar()->setPageStep(viewport()->width()); // If both scroll bars are set to auto, we might end up in a situation with enough space @@ -1897,7 +1911,7 @@ void QCommonListViewBase::updateHorizontalScrollBar(const QSize &step) void QCommonListViewBase::updateVerticalScrollBar(const QSize &step) { - verticalScrollBar()->setSingleStep(step.height() + spacing()); + verticalScrollBar()->d_func()->itemviewChangeSingleStep(step.height() + spacing()); verticalScrollBar()->setPageStep(viewport()->height()); // If both scroll bars are set to auto, we might end up in a situation with enough space @@ -2769,9 +2783,8 @@ bool QIconModeViewBase::filterDropEvent(QDropEvent *e) } QPoint start = dd->pressedPosition; QPoint delta = (dd->movement == QListView::Snap ? snapToGrid(end) - snapToGrid(start) : end - start); - QList<QModelIndex> indexes = dd->selectionModel->selectedIndexes(); - for (int i = 0; i < indexes.count(); ++i) { - QModelIndex index = indexes.at(i); + const QList<QModelIndex> indexes = dd->selectionModel->selectedIndexes(); + for (const auto &index : indexes) { QRect rect = dd->rectForIndex(index); viewport()->update(dd->mapToViewport(rect, false)); QPoint dest = rect.topLeft() + delta; |