diff options
author | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2022-02-24 15:37:48 +0100 |
---|---|---|
committer | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2022-03-05 13:33:24 +0100 |
commit | d958aae44739436aac26ee16b8ac6dd048919cf6 (patch) | |
tree | e6dfbd606a90f24a149f3a80c503f68e8eae777e | |
parent | b18fb72e7f0a886120f0208bd505354993990cfe (diff) |
QQuickTableView: implement private helper function: atTableEnd()
The pattern of checking if there are more rows or columns that can
be loaded around the currently loaded table, is a reoccuring
pattern. So factor it out into a more readable function.
Task-number: QTBUG-100696
Change-Id: Ia0117a6db0495f3ac1173e24084d074581ff5e7d
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
-rw-r--r-- | src/quick/items/qquicktableview.cpp | 42 | ||||
-rw-r--r-- | src/quick/items/qquicktableview_p_p.h | 6 |
2 files changed, 14 insertions, 34 deletions
diff --git a/src/quick/items/qquicktableview.cpp b/src/quick/items/qquicktableview.cpp index 9f7f49ffeb..e5a4eae4ce 100644 --- a/src/quick/items/qquicktableview.cpp +++ b/src/quick/items/qquicktableview.cpp @@ -748,8 +748,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* kRequiredProperties = "_qt_tableview_requiredpropertymask"; static const char* kRequiredProperty_selected = "selected"; @@ -1088,7 +1086,7 @@ QSizeF QQuickTableViewPrivate::scrollTowardsSelectionPoint(const QPointF &pos, c const bool outsideBottom = pos.y() >= viewportRect.bottom() - 1; if (outsideLeft) { - const bool firstColumnLoaded = nextVisibleEdgeIndexAroundLoadedTable(Qt::LeftEdge) == kEdgeIndexAtEnd; + const bool firstColumnLoaded = atTableEnd(Qt::LeftEdge); const qreal remainingDist = viewportRect.left() - loadedTableOuterRect.left(); if (remainingDist > 0 || !firstColumnLoaded) { qreal stepX = step.width(); @@ -1098,7 +1096,7 @@ QSizeF QQuickTableViewPrivate::scrollTowardsSelectionPoint(const QPointF &pos, c dist.setWidth(pos.x() - viewportRect.left() - 1); } } else if (outsideRight) { - const bool lastColumnLoaded = nextVisibleEdgeIndexAroundLoadedTable(Qt::RightEdge) == kEdgeIndexAtEnd; + const bool lastColumnLoaded = atTableEnd(Qt::RightEdge); const qreal remainingDist = loadedTableOuterRect.right() - viewportRect.right(); if (remainingDist > 0 || !lastColumnLoaded) { qreal stepX = step.width(); @@ -1110,7 +1108,7 @@ QSizeF QQuickTableViewPrivate::scrollTowardsSelectionPoint(const QPointF &pos, c } if (outsideTop) { - const bool firstRowLoaded = nextVisibleEdgeIndexAroundLoadedTable(Qt::TopEdge) == kEdgeIndexAtEnd; + const bool firstRowLoaded = atTableEnd(Qt::TopEdge); const qreal remainingDist = viewportRect.top() - loadedTableOuterRect.top(); if (remainingDist > 0 || !firstRowLoaded) { qreal stepY = step.height(); @@ -1120,7 +1118,7 @@ QSizeF QQuickTableViewPrivate::scrollTowardsSelectionPoint(const QPointF &pos, c dist.setHeight(pos.y() - viewportRect.top() - 1); } } else if (outsideBottom) { - const bool lastRowLoaded = nextVisibleEdgeIndexAroundLoadedTable(Qt::BottomEdge) == kEdgeIndexAtEnd; + const bool lastRowLoaded = atTableEnd(Qt::BottomEdge); const qreal remainingDist = loadedTableOuterRect.bottom() - viewportRect.bottom(); if (remainingDist > 0 || !lastRowLoaded) { qreal stepY = step.height(); @@ -1294,28 +1292,6 @@ 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 @@ -2462,14 +2438,14 @@ void QQuickTableViewPrivate::processRebuildTable() && reusableFlag == QQmlTableInstanceModel::Reusable); if (rebuildState == RebuildState::PreloadColumns) { - if (preload && nextVisibleEdgeIndexAroundLoadedTable(Qt::RightEdge) != kEdgeIndexAtEnd) + if (preload && !atTableEnd(Qt::RightEdge)) loadEdge(Qt::RightEdge, QQmlIncubator::AsynchronousIfNested); if (!moveToNextRebuildState()) return; } if (rebuildState == RebuildState::PreloadRows) { - if (preload && nextVisibleEdgeIndexAroundLoadedTable(Qt::BottomEdge) != kEdgeIndexAtEnd) + if (preload && !atTableEnd(Qt::BottomEdge)) loadEdge(Qt::BottomEdge, QQmlIncubator::AsynchronousIfNested); if (!moveToNextRebuildState()) return; @@ -2707,12 +2683,14 @@ void QQuickTableViewPrivate::layoutAfterLoadingInitialTable() 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(); } diff --git a/src/quick/items/qquicktableview_p_p.h b/src/quick/items/qquicktableview_p_p.h index 5ee978fd19..141d0cb3d3 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; @@ -402,8 +404,8 @@ public: int nextVisibleEdgeIndex(Qt::Edge edge, int startIndex) const; int nextVisibleEdgeIndexAroundLoadedTable(Qt::Edge edge) const; - bool allColumnsLoaded(); - bool allRowsLoaded(); + inline bool atTableEnd(Qt::Edge edge) const { return nextVisibleEdgeIndexAroundLoadedTable(edge) == kEdgeIndexAtEnd; } + inline bool atTableEnd(Qt::Edge edge, int startIndex) const { return nextVisibleEdgeIndex(edge, startIndex) == kEdgeIndexAtEnd; } inline int edgeToArrayIndex(Qt::Edge edge) const; void clearEdgeSizeCache(); |