aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/items/qquicktableview.cpp
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@qt.io>2020-10-19 23:25:22 +0200
committerRichard Moe Gustavsen <richard.gustavsen@qt.io>2020-10-23 13:43:56 +0200
commitb5501e9043cabcbf74d3d53b424ece5deb706a27 (patch)
tree78e27fa54ea44fff774d4d458f3b897247f46c1c /src/quick/items/qquicktableview.cpp
parent8528bd527f91f4717ec502f311e34aa5acbc946e (diff)
TableView: ensure we rebuild the sync view, even when flicking on a sync view child
When two table views are connect through the syncView property, both views will flick when you flick on either of them. This also means that if you fast-flick more than a page on the sync view child, the sync view needs to rebuild, like if you did the fast-flick directly on the sync view. Because we updated the sync view's viewportRect too soon while fast-flicking on the the sync child, we didn't detect that it was a fast-flick, and that a rebuild was needed. The result is that you could sometimes end up with the views getting out-of-sync. This patch will allow TableView to only move the viewport without updating the internal viewportRect while flicking. The viewportRect will instead be sync-ed at a later point, like we do when you flick on the sync view directly. This will ensure that we rebuild if needed, also while fast-flicking on the child view. Task-number: QTBUG-87821 Pick-to: 5.15 Change-Id: Ifc74473eb43406acaa8e24880066fb4ca89d3a4e Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/quick/items/qquicktableview.cpp')
-rw-r--r--src/quick/items/qquicktableview.cpp23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/quick/items/qquicktableview.cpp b/src/quick/items/qquicktableview.cpp
index 9a0a21cccd..6f16562455 100644
--- a/src/quick/items/qquicktableview.cpp
+++ b/src/quick/items/qquicktableview.cpp
@@ -2096,6 +2096,8 @@ void QQuickTableViewPrivate::loadInitialTable()
if (!syncVertically && rebuildOptions & RebuildOption::PositionViewAtRow)
setLocalViewportY(topLeftPos.y());
+ syncViewportRect();
+
if (!model) {
qCDebug(lcTableViewDelegateLifecycle()) << "no model found, leaving table empty";
return;
@@ -2180,6 +2182,8 @@ void QQuickTableViewPrivate::adjustViewportXAccordingToAlignment()
Q_TABLEVIEW_UNREACHABLE("options are checked in setter");
break;
}
+
+ syncViewportRect();
}
void QQuickTableViewPrivate::adjustViewportYAccordingToAlignment()
@@ -2213,6 +2217,8 @@ void QQuickTableViewPrivate::adjustViewportYAccordingToAlignment()
Q_TABLEVIEW_UNREACHABLE("options are checked in setter");
break;
}
+
+ syncViewportRect();
}
void QQuickTableViewPrivate::unloadEdge(Qt::Edge edge)
@@ -2559,9 +2565,8 @@ void QQuickTableViewPrivate::syncWithPendingChanges()
// we're e.g in the middle of e.g loading a new row. Since this will lead to
// unpredicted behavior, and possibly a crash, we need to postpone taking
// such assignments into effect until we're in a state that allows it.
- Q_Q(QQuickTableView);
- viewportRect = QRectF(q->contentX(), q->contentY(), q->width(), q->height());
+ syncViewportRect();
syncModel();
syncDelegate();
syncSyncView();
@@ -2907,10 +2912,6 @@ void QQuickTableViewPrivate::setLocalViewportX(qreal contentX)
return;
q->setContentX(contentX);
-
- // Keep our own viewportRect in sync
- viewportRect.moveLeft(contentX);
- qCDebug(lcTableViewDelegateLifecycle) << "viewportRect adjusted to:" << viewportRect;
}
void QQuickTableViewPrivate::setLocalViewportY(qreal contentY)
@@ -2925,10 +2926,14 @@ void QQuickTableViewPrivate::setLocalViewportY(qreal contentY)
return;
q->setContentY(contentY);
+}
- // Keep our own viewportRect in sync
- viewportRect.moveTop(contentY);
- qCDebug(lcTableViewDelegateLifecycle) << "viewportRect adjusted to:" << viewportRect;
+void QQuickTableViewPrivate::syncViewportRect()
+{
+ // Sync viewportRect so that it contains the actual geometry of the viewport
+ Q_Q(QQuickTableView);
+ viewportRect = QRectF(q->contentX(), q->contentY(), q->width(), q->height());
+ qCDebug(lcTableViewDelegateLifecycle) << viewportRect;
}
void QQuickTableViewPrivate::syncViewportPosRecursive()