diff options
Diffstat (limited to 'src/widgets/itemviews/qabstractitemview.cpp')
-rw-r--r-- | src/widgets/itemviews/qabstractitemview.cpp | 39 |
1 files changed, 27 insertions, 12 deletions
diff --git a/src/widgets/itemviews/qabstractitemview.cpp b/src/widgets/itemviews/qabstractitemview.cpp index ad7be840d0..edfb5c0f57 100644 --- a/src/widgets/itemviews/qabstractitemview.cpp +++ b/src/widgets/itemviews/qabstractitemview.cpp @@ -54,6 +54,7 @@ #include <private/qabstractitemview_p.h> #include <private/qabstractitemmodel_p.h> #include <private/qguiapplication_p.h> +#include <private/qscrollbar_p.h> #ifndef QT_NO_ACCESSIBILITY #include <qaccessible.h> #endif @@ -427,6 +428,11 @@ void QAbstractItemViewPrivate::_q_scrollerStateChanged() \since 4.2 \enum QAbstractItemView::ScrollMode + Describes how the scrollbar should behave. When setting the scroll mode + to ScrollPerPixel the single step size will adjust automatically unless + it was set explicitly using \l{QAbstractSlider::}{setSingleStep()}. + The automatic adjustment can be restored by setting the single step size to -1. + \value ScrollPerItem The view will scroll the contents one item at a time. \value ScrollPerPixel The view will scroll the contents one pixel at a time. */ @@ -758,7 +764,7 @@ void QAbstractItemView::setSelectionModel(QItemSelectionModel *selectionModel) Q_ASSERT(selectionModel); Q_D(QAbstractItemView); - if (selectionModel->model() != d->model) { + if (Q_UNLIKELY(selectionModel->model() != d->model)) { qWarning("QAbstractItemView::setSelectionModel() failed: " "Trying to set a selection model, which works on " "a different model than the view."); @@ -1113,7 +1119,7 @@ void QAbstractItemView::reset() void QAbstractItemView::setRootIndex(const QModelIndex &index) { Q_D(QAbstractItemView); - if (index.isValid() && index.model() != d->model) { + if (Q_UNLIKELY(index.isValid() && index.model() != d->model)) { qWarning("QAbstractItemView::setRootIndex failed : index must be from the currently set model"); return; } @@ -1166,9 +1172,9 @@ void QAbstractItemView::selectAll() void QAbstractItemView::edit(const QModelIndex &index) { Q_D(QAbstractItemView); - if (!d->isIndexValid(index)) + if (Q_UNLIKELY(!d->isIndexValid(index))) qWarning("edit: index was invalid"); - if (!edit(index, AllEditTriggers, 0)) + if (Q_UNLIKELY(!edit(index, AllEditTriggers, 0))) qWarning("edit: editing failed"); } @@ -1235,6 +1241,10 @@ void QAbstractItemView::setVerticalScrollMode(ScrollMode mode) return; QModelIndex topLeft = indexAt(QPoint(0, 0)); d->verticalScrollMode = mode; + if (mode == ScrollPerItem) + verticalScrollBar()->d_func()->itemviewChangeSingleStep(1); // setSingleStep(-1) => step with 1 + else + verticalScrollBar()->setSingleStep(-1); // Ensure that the view can update single step updateGeometries(); // update the scroll bars scrollTo(topLeft, QAbstractItemView::PositionAtTop); } @@ -1257,7 +1267,13 @@ QAbstractItemView::ScrollMode QAbstractItemView::verticalScrollMode() const void QAbstractItemView::setHorizontalScrollMode(ScrollMode mode) { Q_D(QAbstractItemView); + if (mode == d->horizontalScrollMode) + return; d->horizontalScrollMode = mode; + if (mode == ScrollPerItem) + horizontalScrollBar()->d_func()->itemviewChangeSingleStep(1); // setSingleStep(-1) => step with 1 + else + horizontalScrollBar()->setSingleStep(-1); // Ensure that the view can update single step updateGeometries(); // update the scroll bars } @@ -4274,9 +4290,8 @@ QModelIndex QAbstractItemViewPrivate::indexForEditor(QWidget *editor) const void QAbstractItemViewPrivate::removeEditor(QWidget *editor) { - QEditorIndexHash::iterator it = editorIndexHash.find(editor); - if (it != editorIndexHash.end()) - { + const auto it = editorIndexHash.constFind(editor); + if (it != editorIndexHash.cend()) { indexEditorHash.remove(it.value()); editorIndexHash.erase(it); } @@ -4335,11 +4350,11 @@ QItemViewPaintPairs QAbstractItemViewPrivate::draggablePaintPairs(const QModelIn QRect &rect = *r; const QRect viewportRect = viewport->rect(); QItemViewPaintPairs ret; - for (int i = 0; i < indexes.count(); ++i) { - const QModelIndex &index = indexes.at(i); + for (const auto &index : indexes) { const QRect current = q->visualRect(index); if (current.intersects(viewportRect)) { - ret += qMakePair(current, index); + QItemViewPaintPair p = { current, index }; + ret += p; rect |= current; } } @@ -4359,8 +4374,8 @@ QPixmap QAbstractItemViewPrivate::renderToPixmap(const QModelIndexList &indexes, QStyleOptionViewItem option = viewOptionsV1(); option.state |= QStyle::State_Selected; for (int j = 0; j < paintPairs.count(); ++j) { - option.rect = paintPairs.at(j).first.translated(-r->topLeft()); - const QModelIndex ¤t = paintPairs.at(j).second; + option.rect = paintPairs.at(j).rect.translated(-r->topLeft()); + const QModelIndex ¤t = paintPairs.at(j).index; adjustViewOptionsForIndex(&option, current); delegateForIndex(current)->paint(&painter, option, current); } |