diff options
author | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2022-02-17 15:27:09 +0100 |
---|---|---|
committer | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2022-03-07 14:07:06 +0100 |
commit | 3f2c9e5253317d1cd97453f668098b2becb41165 (patch) | |
tree | 80a1f2bd5173aa808164f0e8ee929c070bb45503 /src/quick/items/qquicktableview.cpp | |
parent | 91eca07923e924c3bd65364d5d0c7195fe6ef460 (diff) |
QQuickTableView: refactor cancelOvershoot()
Since Flickable already has horizontalOvershoot() and
verticalOvershoot() functions, there is no reason
to calculate this again in TableView.
This patch will refactor the overshoot code to use the
already available API in Flickable.
Task-number: QTBUG-100696
Change-Id: Ifc666e079b0147c3e1cfc6bba2beb287977b303e
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/quick/items/qquicktableview.cpp')
-rw-r--r-- | src/quick/items/qquicktableview.cpp | 67 |
1 files changed, 17 insertions, 50 deletions
diff --git a/src/quick/items/qquicktableview.cpp b/src/quick/items/qquicktableview.cpp index ff3ef6638d..adde42321c 100644 --- a/src/quick/items/qquicktableview.cpp +++ b/src/quick/items/qquicktableview.cpp @@ -2420,15 +2420,8 @@ void QQuickTableViewPrivate::processRebuildTable() return; } - if (rebuildState == RebuildState::CancelOvershootBottomRight) { - cancelOvershootBottomRight(); - loadAndUnloadVisibleEdges(); - if (!moveToNextRebuildState()) - return; - } - - if (rebuildState == RebuildState::CancelOvershootTopLeft) { - cancelOvershootTopLeft(); + if (rebuildState == RebuildState::CancelOvershoot) { + cancelOvershootAfterLayout(); loadAndUnloadVisibleEdges(); if (!moveToNextRebuildState()) return; @@ -2770,54 +2763,28 @@ void QQuickTableViewPrivate::adjustViewportYAccordingToAlignment() syncViewportRect(); } -void QQuickTableViewPrivate::cancelOvershootBottomRight() -{ - // After doing a layout with positioning specified, the table might end up in an - // overshooting state (meaning that the table is dragged beyond the bounds - // of the viewport, with the result that it will bounce back in once you touch it). - // This happens because the layouting might try to e.g position the last row in the - // model in the center of the viewport, which will leave a big blank space from the - // last row towards the bottom. - // This space will be detected by updateExtents(), which will adjust the extents so - // that the superfluous blank area ends up as an overshoot. But we shouldn't leave the - // table in an overshooting state after a rebuild, so we clamp it here so thatit's - // either aligned to the top/left or to the bottom/right of the viewport. - // An exception is if we're not rebuilding because of positionViewAtCell(), since - // the app is allowed to set contentX and contentY at start-up. A second exception is - // if this view is a sync child, since then we can end up with extra space at the end - // if our model has fewer rows/columns than the syncView. - const qreal blankSpaceRight = viewportRect.right() - loadedTableOuterRect.right(); - const qreal blankSpaceBottom = viewportRect.bottom() - loadedTableOuterRect.bottom(); - const bool positionVertically = rebuildOptions.testFlag(RebuildOption::PositionViewAtRow); - const bool positionHorizontally = rebuildOptions.testFlag(RebuildOption::PositionViewAtColumn); - - if (positionVertically && !syncVertically && viewportRect.top() > 0 && blankSpaceBottom > 0) { - qCDebug(lcTableViewDelegateLifecycle()) << "cancelling overshoot at bottom:" << blankSpaceBottom; - setLocalViewportY(viewportRect.y() - blankSpaceBottom); - syncViewportRect(); - } - - if (positionHorizontally && !syncHorizontally && viewportRect.left() > 0 && blankSpaceRight > 0) { - qCDebug(lcTableViewDelegateLifecycle()) << "cancelling overshoot at right:" << blankSpaceRight; - setLocalViewportX(viewportRect.x() - blankSpaceRight); - syncViewportRect(); - } -} - -void QQuickTableViewPrivate::cancelOvershootTopLeft() +void QQuickTableViewPrivate::cancelOvershootAfterLayout() { + Q_Q(QQuickTableView); + + // Note: we only want to cancel overshoot from a rebuild if we're supposed to position + // the view on a specific cell. The app is allowed to overshoot by setting contentX and + // contentY manually. Also, if this view is a sync child, we should always stay in sync + // with the syncView, so then we don't do anything. const bool positionVertically = rebuildOptions.testFlag(RebuildOption::PositionViewAtRow); const bool positionHorizontally = rebuildOptions.testFlag(RebuildOption::PositionViewAtColumn); + const bool cancelVertically = positionVertically && !syncVertically; + const bool cancelHorizontally = positionHorizontally && !syncHorizontally; - if (positionVertically && !syncVertically && viewportRect.top() < 0) { - qCDebug(lcTableViewDelegateLifecycle()) << "cancelling overshoot at top:" << viewportRect.top(); - setLocalViewportY(0); + if (cancelHorizontally && !qFuzzyIsNull(q->horizontalOvershoot())) { + qCDebug(lcTableViewDelegateLifecycle()) << "cancelling overshoot horizontally:" << q->horizontalOvershoot(); + setLocalViewportX(q->horizontalOvershoot() < 0 ? -q->minXExtent() : -q->maxXExtent()); syncViewportRect(); } - if (positionHorizontally && !syncHorizontally && viewportRect.left() < 0) { - qCDebug(lcTableViewDelegateLifecycle()) << "cancelling overshoot at left:" << viewportRect.left(); - setLocalViewportX(0); + if (cancelVertically && !qFuzzyIsNull(q->verticalOvershoot())) { + qCDebug(lcTableViewDelegateLifecycle()) << "cancelling overshoot vertically:" << q->verticalOvershoot(); + setLocalViewportY(q->verticalOvershoot() < 0 ? -q->minYExtent() : -q->maxYExtent()); syncViewportRect(); } } |