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 <stephen.kelly@kdab.com>
This commit is contained in:
Thorbjørn Lund Martsum 2012-10-31 15:07:40 +01:00 committed by The Qt Project
parent 02c110e989
commit c6754c2720

View File

@ -3746,30 +3746,33 @@ void QAbstractItemView::doAutoScroll()
{ {
// find how much we should scroll with // find how much we should scroll with
Q_D(QAbstractItemView); Q_D(QAbstractItemView);
int verticalStep = verticalScrollBar()->pageStep(); QScrollBar *verticalScroll = verticalScrollBar();
int horizontalStep = horizontalScrollBar()->pageStep(); QScrollBar *horizontalScroll = horizontalScrollBar();
int verticalStep = verticalScroll->pageStep();
int horizontalStep = horizontalScroll->pageStep();
if (d->autoScrollCount < qMax(verticalStep, horizontalStep)) if (d->autoScrollCount < qMax(verticalStep, horizontalStep))
++d->autoScrollCount; ++d->autoScrollCount;
int margin = d->autoScrollMargin; int margin = d->autoScrollMargin;
int verticalValue = verticalScrollBar()->value(); int verticalValue = verticalScroll->value();
int horizontalValue = horizontalScrollBar()->value(); int horizontalValue = horizontalScroll->value();
QPoint pos = d->viewport->mapFromGlobal(QCursor::pos()); QPoint pos = d->viewport->mapFromGlobal(QCursor::pos());
QRect area = static_cast<QAbstractItemView*>(d->viewport)->d_func()->clipRect(); // access QWidget private by bending C++ rules QRect area = static_cast<QAbstractItemView*>(d->viewport)->d_func()->clipRect(); // access QWidget private by bending C++ rules
// do the scrolling if we are in the scroll margins // do the scrolling if we are in the scroll margins
if (pos.y() - area.top() < margin) if (pos.y() - area.top() < margin)
verticalScrollBar()->setValue(verticalValue - d->autoScrollCount); verticalScroll->setValue(verticalValue - d->autoScrollCount);
else if (area.bottom() - pos.y() < margin) else if (area.bottom() - pos.y() < margin)
verticalScrollBar()->setValue(verticalValue + d->autoScrollCount); verticalScroll->setValue(verticalValue + d->autoScrollCount);
if (pos.x() - area.left() < margin) if (pos.x() - area.left() < margin)
horizontalScrollBar()->setValue(horizontalValue - d->autoScrollCount); horizontalScroll->setValue(horizontalValue - d->autoScrollCount);
else if (area.right() - pos.x() < margin) else if (area.right() - pos.x() < margin)
horizontalScrollBar()->setValue(horizontalValue + d->autoScrollCount); horizontalScroll->setValue(horizontalValue + d->autoScrollCount);
// if nothing changed, stop scrolling // if nothing changed, stop scrolling
bool verticalUnchanged = (verticalValue == verticalScrollBar()->value()); bool verticalUnchanged = (verticalValue == verticalScroll->value());
bool horizontalUnchanged = (horizontalValue == horizontalScrollBar()->value()); bool horizontalUnchanged = (horizontalValue == horizontalScroll->value());
if (verticalUnchanged && horizontalUnchanged) { if (verticalUnchanged && horizontalUnchanged) {
stopAutoScroll(); stopAutoScroll();
} else { } else {