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
Pick-to: 6.5 6.4 6.2
Change-Id: I47c3325bc9e51f75c87564a2ec1de4522e4a7e60
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
This commit is contained in:
Santhosh Kumar 2022-12-19 17:49:16 +01:00
parent f8207a204b
commit 19b35008e2
2 changed files with 19 additions and 11 deletions

View File

@ -3228,11 +3228,6 @@ void QQuickTableViewPrivate::processRebuildTable()
if (rebuildState == RebuildState::LayoutTable) {
layoutAfterLoadingInitialTable();
if (!moveToNextRebuildState())
return;
}
if (rebuildState == RebuildState::LoadAndUnloadAfterLayout) {
loadAndUnloadVisibleEdges();
if (!moveToNextRebuildState())
return;
@ -3245,6 +3240,12 @@ void QQuickTableViewPrivate::processRebuildTable()
return;
}
if (rebuildState == RebuildState::UpdateContentSize) {
updateContentSize();
if (!moveToNextRebuildState())
return;
}
const bool preload = (rebuildOptions & RebuildOption::All
&& reusableFlag == QQmlTableInstanceModel::Reusable);
@ -3511,12 +3512,8 @@ void QQuickTableViewPrivate::loadInitialTable()
loadAndUnloadVisibleEdges();
}
void QQuickTableViewPrivate::layoutAfterLoadingInitialTable()
void QQuickTableViewPrivate::updateContentSize()
{
clearEdgeSizeCache();
relayoutTableItems();
syncLoadedTableRectFromLoadedTable();
const bool allColumnsLoaded = atTableEnd(Qt::LeftEdge) && atTableEnd(Qt::RightEdge);
if (rebuildOptions.testFlag(RebuildOption::CalculateNewContentWidth) || allColumnsLoaded) {
updateAverageColumnWidth();
@ -3530,6 +3527,16 @@ void QQuickTableViewPrivate::layoutAfterLoadingInitialTable()
}
updateExtents();
}
void QQuickTableViewPrivate::layoutAfterLoadingInitialTable()
{
clearEdgeSizeCache();
relayoutTableItems();
syncLoadedTableRectFromLoadedTable();
updateContentSize();
adjustViewportXAccordingToAlignment();
adjustViewportYAccordingToAlignment();
}

View File

@ -216,8 +216,8 @@ public:
LoadInitalTable,
VerifyTable,
LayoutTable,
LoadAndUnloadAfterLayout,
CancelOvershoot,
UpdateContentSize,
PreloadColumns,
PreloadRows,
MovePreloadedItemsToPool,
@ -485,6 +485,7 @@ public:
void updateCursor();
#endif
void updateEditItem();
void updateContentSize();
QTypeRevision resolveImportVersion();
void createWrapperModel();