aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@qt.io>2021-03-10 17:21:07 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-03-29 08:03:43 +0000
commit30c9ed29bec622cb4e345d20101153d2a6a2ba05 (patch)
tree720b7e9a345a0fd31de3cb59d74e7b86539bb0f1 /src
parentca8a985871e50d292d475ed10da423dd7020a914 (diff)
QQuickTableView: always update content size when rebuilding small tables
If you have a TableView with only a couple of rows, and you add a third one, the contentHeight doesn't update. This is fine if not all rows are loaded (some are outside the viewport), but when they are all inside, it should update to reflect the exact height. The same is also the case for the contentWidth. If you add a new row that increases the with of a column (and all columns are visible), the contentWidth should update. This patch adds an extra check when we do a rebuild (which we do when you add a new row), to see if all rows or columns are loaded. And if that is the case, we update contentHeight or contentWidth, respecitively. Fixes: QTBUG-92099 Change-Id: I806bfb7c3606fca97c5d27cbb91856cc40df9fb8 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io> (cherry picked from commit d6a5afd120838647e0dd2a420dacf06389f0a48e) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src')
-rw-r--r--src/quick/items/qquicktableview.cpp26
-rw-r--r--src/quick/items/qquicktableview_p_p.h2
2 files changed, 26 insertions, 2 deletions
diff --git a/src/quick/items/qquicktableview.cpp b/src/quick/items/qquicktableview.cpp
index 47c9d76318..6e91b78bd9 100644
--- a/src/quick/items/qquicktableview.cpp
+++ b/src/quick/items/qquicktableview.cpp
@@ -777,6 +777,28 @@ int QQuickTableViewPrivate::nextVisibleEdgeIndex(Qt::Edge edge, int startIndex)
return foundIndex;
}
+bool QQuickTableViewPrivate::allColumnsLoaded()
+{
+ // Returns true if all the columns in the model (that are not
+ // hidden by the columnWidthProvider) are currently loaded and visible.
+ const bool firstColumnLoaded = nextVisibleEdgeIndexAroundLoadedTable(Qt::LeftEdge) == kEdgeIndexAtEnd;
+ if (!firstColumnLoaded)
+ return false;
+ bool lastColumnLoaded = nextVisibleEdgeIndexAroundLoadedTable(Qt::RightEdge) == kEdgeIndexAtEnd;
+ return lastColumnLoaded;
+}
+
+bool QQuickTableViewPrivate::allRowsLoaded()
+{
+ // Returns true if all the rows in the model (that are not hidden
+ // by the columnWidthProvider) are currently loaded and visible.
+ const bool firstColumnLoaded = nextVisibleEdgeIndexAroundLoadedTable(Qt::TopEdge) == kEdgeIndexAtEnd;
+ if (!firstColumnLoaded)
+ return false;
+ bool lastColumnLoaded = nextVisibleEdgeIndexAroundLoadedTable(Qt::BottomEdge) == kEdgeIndexAtEnd;
+ return lastColumnLoaded;
+}
+
void QQuickTableViewPrivate::updateContentWidth()
{
// Note that we actually never really know what the content size / size of the full table will
@@ -2136,12 +2158,12 @@ void QQuickTableViewPrivate::layoutAfterLoadingInitialTable()
relayoutTableItems();
syncLoadedTableRectFromLoadedTable();
- if (rebuildOptions.testFlag(RebuildOption::CalculateNewContentWidth)) {
+ if (rebuildOptions.testFlag(RebuildOption::CalculateNewContentWidth) || allColumnsLoaded()) {
updateAverageColumnWidth();
updateContentWidth();
}
- if (rebuildOptions.testFlag(RebuildOption::CalculateNewContentHeight)) {
+ if (rebuildOptions.testFlag(RebuildOption::CalculateNewContentHeight) || allRowsLoaded()) {
updateAverageRowHeight();
updateContentHeight();
}
diff --git a/src/quick/items/qquicktableview_p_p.h b/src/quick/items/qquicktableview_p_p.h
index ef408be668..b01fe3cf93 100644
--- a/src/quick/items/qquicktableview_p_p.h
+++ b/src/quick/items/qquicktableview_p_p.h
@@ -385,6 +385,8 @@ public:
int nextVisibleEdgeIndex(Qt::Edge edge, int startIndex);
int nextVisibleEdgeIndexAroundLoadedTable(Qt::Edge edge);
+ bool allColumnsLoaded();
+ bool allRowsLoaded();
inline int edgeToArrayIndex(Qt::Edge edge);
void clearEdgeSizeCache();