aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/items/qquicktableview.cpp
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@qt.io>2020-04-06 19:18:06 +0200
committerRichard Moe Gustavsen <richard.gustavsen@qt.io>2020-04-08 15:57:16 +0200
commitf296c300614cbe2c9de66fe05ea7201d79249062 (patch)
tree4fde16688d250e380ad0f046a815ac70233d37e2 /src/quick/items/qquicktableview.cpp
parentbe12b71faeba23a8ef0cf9695e11aa847b68ae7e (diff)
QQuickTableView: add function: itemAtCell(const QPoint)
Add a function to the API to let the application get the item loaded for a specific cell. [ChangeLog][TableView] A function 'itemAtCell()' has now been added to let the application get the delegate item loaded for a specific cell. Change-Id: Ie84ef44ea2a0a901487812c4d611b98d4c86ee22 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'src/quick/items/qquicktableview.cpp')
-rw-r--r--src/quick/items/qquicktableview.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/quick/items/qquicktableview.cpp b/src/quick/items/qquicktableview.cpp
index 28a5dee681..3548d20706 100644
--- a/src/quick/items/qquicktableview.cpp
+++ b/src/quick/items/qquicktableview.cpp
@@ -425,6 +425,23 @@
*/
/*!
+ \qmlmethod Item QtQuick::TableView::itemAtCell(point cell)
+
+ Returns the delegate item at \a cell if loaded, otherwise \c null.
+
+ \note only the items that are visible in the view are normally loaded.
+ As soon as a cell is flicked out of the view, the item inside will
+ either be unloaded or placed in the recycle pool. As such, the return
+ value should never be stored.
+*/
+
+/*!
+ \qmlmethod Item QtQuick::TableView::itemAtCell(int column, int row)
+
+ Convenience for calling \code itemAtCell(Qt.point(column, row)) \endcode
+*/
+
+/*!
\qmlattachedproperty TableView QtQuick::TableView::view
This attached property holds the view that manages the delegate instance.
@@ -3122,6 +3139,20 @@ void QQuickTableView::positionViewAtColumn(int column, Qt::Alignment alignment,
QQuickTableViewPrivate::RebuildOption::PositionViewAtColumn);
}
+QQuickItem *QQuickTableView::itemAtCell(const QPoint &cell) const
+{
+ Q_D(const QQuickTableView);
+ const int modelIndex = d->modelIndexAtCell(cell);
+ if (!d->loadedItems.contains(modelIndex))
+ return nullptr;
+ return d->loadedItems.value(modelIndex)->item;
+}
+
+QQuickItem *QQuickTableView::itemAtCell(int column, int row) const
+{
+ return itemAtCell(QPoint(column, row));
+}
+
void QQuickTableView::forceLayout()
{
d_func()->forceLayout();