From 96b99fb2acc5fe3704f2a472a9a71009b616e69e Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Fri, 3 May 2019 13:37:41 +0200 Subject: QQuickTableView: improve updateAverageEdgeSize() When we know the exact size of the content view, we can take advantage of this to calculate the exact average cell size. This in turn will improve the positioning of rows and columns whenever we need to rebuild, since we have a better idea where they should end up in the content view. Change-Id: I46c3e87eb38ab032df7c28b6144d1b2de1b9d4ef Reviewed-by: Mitch Curtis --- src/quick/items/qquicktableview.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'src/quick') diff --git a/src/quick/items/qquicktableview.cpp b/src/quick/items/qquicktableview.cpp index 17352221d3..48736f8d47 100644 --- a/src/quick/items/qquicktableview.cpp +++ b/src/quick/items/qquicktableview.cpp @@ -714,12 +714,21 @@ void QQuickTableViewPrivate::enforceTableAtOrigin() void QQuickTableViewPrivate::updateAverageEdgeSize() { - const int loadedRowCount = loadedRows.count(); - const int loadedColumnCount = loadedColumns.count(); - const qreal accRowSpacing = (loadedRowCount - 1) * cellSpacing.height(); - const qreal accColumnSpacing = (loadedColumnCount - 1) * cellSpacing.width(); - averageEdgeSize.setHeight((loadedTableOuterRect.height() - accRowSpacing) / loadedRowCount); - averageEdgeSize.setWidth((loadedTableOuterRect.width() - accColumnSpacing) / loadedColumnCount); + if (explicitContentWidth.isValid()) { + const qreal accColumnSpacing = (tableSize.width() - 1) * cellSpacing.width(); + averageEdgeSize.setWidth((explicitContentWidth - accColumnSpacing) / tableSize.width()); + } else { + const qreal accColumnSpacing = (loadedColumns.count() - 1) * cellSpacing.width(); + averageEdgeSize.setWidth((loadedTableOuterRect.width() - accColumnSpacing) / loadedColumns.count()); + } + + if (explicitContentHeight.isValid()) { + const qreal accRowSpacing = (tableSize.height() - 1) * cellSpacing.height(); + averageEdgeSize.setHeight((explicitContentHeight - accRowSpacing) / tableSize.height()); + } else { + const qreal accRowSpacing = (loadedRows.count() - 1) * cellSpacing.height(); + averageEdgeSize.setHeight((loadedTableOuterRect.height() - accRowSpacing) / loadedRows.count()); + } } void QQuickTableViewPrivate::syncLoadedTableRectFromLoadedTable() -- cgit v1.2.3