aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/items/qquicktableview.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/quick/items/qquicktableview.cpp')
-rw-r--r--src/quick/items/qquicktableview.cpp67
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();
}
}