From c6754c2720d09488ba7483bb6ef8c37a9b7f833c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lund=20Martsum?= Date: Wed, 31 Oct 2012 15:07:40 +0100 Subject: QAbstractItemView - prepare fix for auto scroll on sectionmove There are no semantic changes in this patch. We just avoid many calls to horizontalScrollBar() and verticalScrollBar() by storing the result of them in local variables, that are used instead. This is just a prepare for auto-scroll when a user is moving a section. Change-Id: I4b3d3ecbf3a29992e6f578d4b0442d7f494125e4 Reviewed-by: Stephen Kelly --- src/widgets/itemviews/qabstractitemview.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/widgets/itemviews/qabstractitemview.cpp b/src/widgets/itemviews/qabstractitemview.cpp index 0308fb44a9..8ba078ffd3 100644 --- a/src/widgets/itemviews/qabstractitemview.cpp +++ b/src/widgets/itemviews/qabstractitemview.cpp @@ -3746,30 +3746,33 @@ void QAbstractItemView::doAutoScroll() { // find how much we should scroll with Q_D(QAbstractItemView); - int verticalStep = verticalScrollBar()->pageStep(); - int horizontalStep = horizontalScrollBar()->pageStep(); + QScrollBar *verticalScroll = verticalScrollBar(); + QScrollBar *horizontalScroll = horizontalScrollBar(); + + int verticalStep = verticalScroll->pageStep(); + int horizontalStep = horizontalScroll->pageStep(); if (d->autoScrollCount < qMax(verticalStep, horizontalStep)) ++d->autoScrollCount; int margin = d->autoScrollMargin; - int verticalValue = verticalScrollBar()->value(); - int horizontalValue = horizontalScrollBar()->value(); + int verticalValue = verticalScroll->value(); + int horizontalValue = horizontalScroll->value(); QPoint pos = d->viewport->mapFromGlobal(QCursor::pos()); QRect area = static_cast(d->viewport)->d_func()->clipRect(); // access QWidget private by bending C++ rules // do the scrolling if we are in the scroll margins if (pos.y() - area.top() < margin) - verticalScrollBar()->setValue(verticalValue - d->autoScrollCount); + verticalScroll->setValue(verticalValue - d->autoScrollCount); else if (area.bottom() - pos.y() < margin) - verticalScrollBar()->setValue(verticalValue + d->autoScrollCount); + verticalScroll->setValue(verticalValue + d->autoScrollCount); if (pos.x() - area.left() < margin) - horizontalScrollBar()->setValue(horizontalValue - d->autoScrollCount); + horizontalScroll->setValue(horizontalValue - d->autoScrollCount); else if (area.right() - pos.x() < margin) - horizontalScrollBar()->setValue(horizontalValue + d->autoScrollCount); + horizontalScroll->setValue(horizontalValue + d->autoScrollCount); // if nothing changed, stop scrolling - bool verticalUnchanged = (verticalValue == verticalScrollBar()->value()); - bool horizontalUnchanged = (horizontalValue == horizontalScrollBar()->value()); + bool verticalUnchanged = (verticalValue == verticalScroll->value()); + bool horizontalUnchanged = (horizontalValue == horizontalScroll->value()); if (verticalUnchanged && horizontalUnchanged) { stopAutoScroll(); } else { -- cgit v1.2.3