diff options
author | Santhosh Kumar <santhosh.kumar.selvaraj@qt.io> | 2022-12-19 17:49:16 +0100 |
---|---|---|
committer | Santhosh Kumar <santhosh.kumar.selvaraj@qt.io> | 2023-01-25 16:47:53 +0100 |
commit | 1577111519a7a5f7cfe47ce25517ecf993672a00 (patch) | |
tree | fee0298dd284c6b3e2323f6ed4049ad2f081060c /src | |
parent | 58e55b68d9c43d2b4d0a8dfb3e0497a814cc61a7 (diff) |
Fix content position of table view control
The estimated width in the table view has been used to layout
and accordingly, edges of the table be loaded. This estimated
width will be passed to flickable to adjust its parameters and
width/position of scroll bar. This in turn change geometry of
table view with respect to view port.
In some scenarios, this estimated width during layout causes
table view to be misaligned. This can be avoided by calculating
and updating latest content width of the table view once after
loading the edges of table.
Fixes: QTBUG-108664
Change-Id: I47c3325bc9e51f75c87564a2ec1de4522e4a7e60
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
(cherry picked from commit 19b35008e2b2bebef10a9d52c8389920df1e1953)
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/quick/items/qquicktableview.cpp | 35 | ||||
-rw-r--r-- | src/quick/items/qquicktableview_p_p.h | 9 |
2 files changed, 29 insertions, 15 deletions
diff --git a/src/quick/items/qquicktableview.cpp b/src/quick/items/qquicktableview.cpp index 445ef073e7..be1114d4d4 100644 --- a/src/quick/items/qquicktableview.cpp +++ b/src/quick/items/qquicktableview.cpp @@ -688,8 +688,6 @@ Q_LOGGING_CATEGORY(lcTableViewDelegateLifecycle, "qt.quick.tableview.lifecycle") #define Q_TABLEVIEW_ASSERT(cond, output) Q_ASSERT((cond) || [&](){ dumpTable(); qWarning() << "output:" << output; return false;}()) static const Qt::Edge allTableEdges[] = { Qt::LeftEdge, Qt::RightEdge, Qt::TopEdge, Qt::BottomEdge }; -static const int kEdgeIndexNotSet = -2; -static const int kEdgeIndexAtEnd = -3; static const char* kRequiredProperty = "_qt_isrequiredpropery_selected"; @@ -2340,11 +2338,6 @@ void QQuickTableViewPrivate::processRebuildTable() if (rebuildState == RebuildState::LayoutTable) { layoutAfterLoadingInitialTable(); - if (!moveToNextRebuildState()) - return; - } - - if (rebuildState == RebuildState::LoadAndUnloadAfterLayout) { loadAndUnloadVisibleEdges(); if (!moveToNextRebuildState()) return; @@ -2364,6 +2357,12 @@ void QQuickTableViewPrivate::processRebuildTable() return; } + if (rebuildState == RebuildState::UpdateContentSize) { + updateContentSize(); + if (!moveToNextRebuildState()) + return; + } + const bool preload = (rebuildOptions & RebuildOption::All && reusableFlag == QQmlTableInstanceModel::Reusable); @@ -2607,23 +2606,31 @@ void QQuickTableViewPrivate::loadInitialTable() loadAndUnloadVisibleEdges(); } -void QQuickTableViewPrivate::layoutAfterLoadingInitialTable() +void QQuickTableViewPrivate::updateContentSize() { - clearEdgeSizeCache(); - relayoutTableItems(); - syncLoadedTableRectFromLoadedTable(); - - if (rebuildOptions.testFlag(RebuildOption::CalculateNewContentWidth) || allColumnsLoaded()) { + const bool allColumnsLoaded = atTableEnd(Qt::LeftEdge) && atTableEnd(Qt::RightEdge); + if (rebuildOptions.testFlag(RebuildOption::CalculateNewContentWidth) || allColumnsLoaded) { updateAverageColumnWidth(); updateContentWidth(); } - if (rebuildOptions.testFlag(RebuildOption::CalculateNewContentHeight) || allRowsLoaded()) { + const bool allRowsLoaded = atTableEnd(Qt::TopEdge) && atTableEnd(Qt::BottomEdge); + if (rebuildOptions.testFlag(RebuildOption::CalculateNewContentHeight) || allRowsLoaded) { updateAverageRowHeight(); updateContentHeight(); } updateExtents(); +} + +void QQuickTableViewPrivate::layoutAfterLoadingInitialTable() +{ + clearEdgeSizeCache(); + relayoutTableItems(); + syncLoadedTableRectFromLoadedTable(); + + updateContentSize(); + adjustViewportXAccordingToAlignment(); adjustViewportYAccordingToAlignment(); } diff --git a/src/quick/items/qquicktableview_p_p.h b/src/quick/items/qquicktableview_p_p.h index d5ed96bc37..a3a9db4793 100644 --- a/src/quick/items/qquicktableview_p_p.h +++ b/src/quick/items/qquicktableview_p_p.h @@ -71,6 +71,8 @@ Q_DECLARE_LOGGING_CATEGORY(lcTableViewDelegateLifecycle) static const qreal kDefaultRowHeight = 50; static const qreal kDefaultColumnWidth = 50; +static const int kEdgeIndexNotSet = -2; +static const int kEdgeIndexAtEnd = -3; class FxTableItem; class QQuickTableSectionSizeProviderPrivate; @@ -201,9 +203,9 @@ public: LoadInitalTable, VerifyTable, LayoutTable, - LoadAndUnloadAfterLayout, CancelOvershootBottomRight, CancelOvershootTopLeft, + UpdateContentSize, PreloadColumns, PreloadRows, MovePreloadedItemsToPool, @@ -400,6 +402,9 @@ public: int nextVisibleEdgeIndex(Qt::Edge edge, int startIndex); int nextVisibleEdgeIndexAroundLoadedTable(Qt::Edge edge); + inline bool atTableEnd(Qt::Edge edge) { + return nextVisibleEdgeIndexAroundLoadedTable(edge) == kEdgeIndexAtEnd; + } bool allColumnsLoaded(); bool allRowsLoaded(); inline int edgeToArrayIndex(Qt::Edge edge); @@ -441,6 +446,8 @@ public: void scheduleRebuildTable(QQuickTableViewPrivate::RebuildOptions options); + void updateContentSize(); + QTypeRevision resolveImportVersion(); void createWrapperModel(); |