aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/quick/items/qquicktableview.cpp23
-rw-r--r--src/quick/items/qquicktableview_p_p.h1
-rw-r--r--tests/auto/quick/qquicktableview/tst_qquicktableview.cpp37
3 files changed, 52 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()
diff --git a/src/quick/items/qquicktableview_p_p.h b/src/quick/items/qquicktableview_p_p.h
index 6a8c5fa7fa..ef408be668 100644
--- a/src/quick/items/qquicktableview_p_p.h
+++ b/src/quick/items/qquicktableview_p_p.h
@@ -454,6 +454,7 @@ public:
void scheduleRebuildIfFastFlick();
void setLocalViewportX(qreal contentX);
void setLocalViewportY(qreal contentY);
+ void syncViewportRect();
void syncViewportPosRecursive();
void fetchMoreData();
diff --git a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
index 0375b74386..e9c9505d6c 100644
--- a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
+++ b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
@@ -175,6 +175,7 @@ private slots:
void checkSyncView_differentSizedModels();
void checkSyncView_connect_late_data();
void checkSyncView_connect_late();
+ void checkSyncView_pageFlicking();
void delegateWithRequiredProperties();
void checkThatFetchMoreIsCalledWhenScrolledToTheEndOfTable();
void replaceModel();
@@ -2704,6 +2705,42 @@ void tst_QQuickTableView::checkSyncView_connect_late()
QCOMPARE(tableViewHVPrivate->loadedTableOuterRect, tableViewPrivate->loadedTableOuterRect);
}
+void tst_QQuickTableView::checkSyncView_pageFlicking()
+{
+ // Check that we rebuild the syncView (instead of refilling
+ // edges), if the sync child moves more than a page (the size of TableView).
+ // The point is that it shouldn't matter if you fast-flick the
+ // sync view itself, or a sync child. Either way, the sync view
+ // needs to rebuild. This, in turn, will eventually rebuild the
+ // sync children as well when they sync up later.
+ LOAD_TABLEVIEW("syncviewsimple.qml");
+ GET_QML_TABLEVIEW(tableViewH);
+ GET_QML_TABLEVIEW(tableViewV);
+ GET_QML_TABLEVIEW(tableViewHV);
+ QQuickTableView *views[] = {tableViewH, tableViewV, tableViewHV};
+
+ auto model = TestModelAsVariant(100, 100);
+
+ tableView->setModel(model);
+
+ WAIT_UNTIL_POLISHED;
+
+ // Move the viewport more than a "page"
+ tableViewHV->setContentX(tableViewHV->width() * 2);
+
+ QVERIFY(tableViewPrivate->scheduledRebuildOptions & QQuickTableViewPrivate::RebuildOption::ViewportOnly);
+ QVERIFY(tableViewPrivate->scheduledRebuildOptions & QQuickTableViewPrivate::RebuildOption::CalculateNewTopLeftColumn);
+ QVERIFY(!(tableViewPrivate->scheduledRebuildOptions & QQuickTableViewPrivate::RebuildOption::CalculateNewTopLeftRow));
+
+ WAIT_UNTIL_POLISHED;
+
+ tableViewHV->setContentY(tableViewHV->height() * 2);
+
+ QVERIFY(tableViewPrivate->scheduledRebuildOptions & QQuickTableViewPrivate::RebuildOption::ViewportOnly);
+ QVERIFY(!(tableViewPrivate->scheduledRebuildOptions & QQuickTableViewPrivate::RebuildOption::CalculateNewTopLeftColumn));
+ QVERIFY(tableViewPrivate->scheduledRebuildOptions & QQuickTableViewPrivate::RebuildOption::CalculateNewTopLeftRow);
+}
+
void tst_QQuickTableView::checkThatFetchMoreIsCalledWhenScrolledToTheEndOfTable()
{
LOAD_TABLEVIEW("plaintableview.qml");