TableView: deprecate itemAtCell(column, row) in favor of itemAtIndex(modelIndex)
After deprecating modelIndex(column, row) in favor of index(row, column), we should now do the same to itemAtCell(column, row), to be consistent. This function will therefore deprecate itemAtCell(column, row) and instead offer a new function itemAtIndex(modelIndex). [ChangeLog][Quick][TableView] itemAtCell(column, row) has been deprecated in favor of itemAtIndex(modelIndex). Task-number: QTBUG-109542 Pick-to: 6.5 Change-Id: Ibd009cb3b9d6ce7ba19da5e20df9e307a31f5090 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
parent
aea8c9e093
commit
3343c57b02
|
@ -879,8 +879,27 @@
|
|||
|
||||
/*!
|
||||
\qmlmethod Item QtQuick::TableView::itemAtCell(int column, int row)
|
||||
\deprecated
|
||||
|
||||
Convenience for calling \c{itemAtCell(Qt.point(column, row))}.
|
||||
Use \l {itemAtIndex()}{itemAtIndex(index(row, column))} instead.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\qmlmethod Item QtQuick::TableView::itemAtIndex(QModelIndex index)
|
||||
\since 6.5
|
||||
|
||||
Returns the instantiated delegate item for the cell that represents
|
||||
\a index. If the item is not \l {isRowLoaded()}{loaded}, the value
|
||||
will be \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.
|
||||
|
||||
\note If the \l model is not a QAbstractItemModel, you can also use
|
||||
\l {itemAtCell()}{itemAtCell(Qt.point(column, row))}. But be aware
|
||||
that \c {point.x} maps to columns and \c {point.y} maps to rows.
|
||||
*/
|
||||
|
||||
/*!
|
||||
|
@ -5744,10 +5763,21 @@ QQuickItem *QQuickTableView::itemAtCell(const QPoint &cell) const
|
|||
return d->loadedItems.value(modelIndex)->item;
|
||||
}
|
||||
|
||||
#if QT_DEPRECATED_SINCE(6, 5)
|
||||
QQuickItem *QQuickTableView::itemAtCell(int column, int row) const
|
||||
{
|
||||
return itemAtCell(QPoint(column, row));
|
||||
}
|
||||
#endif
|
||||
|
||||
QQuickItem *QQuickTableView::itemAtIndex(const QModelIndex &index) const
|
||||
{
|
||||
Q_D(const QQuickTableView);
|
||||
const int serializedIndex = d->modelIndexToCellIndex(index);
|
||||
if (!d->loadedItems.contains(serializedIndex))
|
||||
return nullptr;
|
||||
return d->loadedItems.value(serializedIndex)->item;
|
||||
}
|
||||
|
||||
#if QT_DEPRECATED_SINCE(6, 4)
|
||||
QPoint QQuickTableView::cellAtPos(qreal x, qreal y, bool includeSpacing) const
|
||||
|
|
|
@ -178,7 +178,6 @@ public:
|
|||
Q_INVOKABLE void positionViewAtRow(int row, PositionMode mode, qreal offset = 0, const QRectF &subRect = QRectF());
|
||||
Q_INVOKABLE void positionViewAtColumn(int column, PositionMode mode, qreal offset = 0, const QRectF &subRect = QRectF());
|
||||
Q_INVOKABLE QQuickItem *itemAtCell(const QPoint &cell) const;
|
||||
Q_INVOKABLE QQuickItem *itemAtCell(int column, int row) const;
|
||||
|
||||
Q_REVISION(6, 4) Q_INVOKABLE QPoint cellAtPosition(const QPointF &position, bool includeSpacing = false) const;
|
||||
Q_REVISION(6, 4) Q_INVOKABLE QPoint cellAtPosition(qreal x, qreal y, bool includeSpacing = false) const;
|
||||
|
@ -215,6 +214,13 @@ public:
|
|||
Q_REVISION(6, 5) Q_INVOKABLE void edit(const QModelIndex &index);
|
||||
Q_REVISION(6, 5) Q_INVOKABLE void closeEditor();
|
||||
|
||||
Q_REVISION(6, 5) Q_INVOKABLE QQuickItem *itemAtIndex(const QModelIndex &index) const;
|
||||
|
||||
#if QT_DEPRECATED_SINCE(6, 5)
|
||||
QT_DEPRECATED_VERSION_X_6_5("Use itemAtIndex(index(row, column)) instead")
|
||||
Q_INVOKABLE QQuickItem *itemAtCell(int column, int row) const;
|
||||
#endif
|
||||
|
||||
static QQuickTableViewAttached *qmlAttachedProperties(QObject *);
|
||||
|
||||
Q_SIGNALS:
|
||||
|
|
|
@ -443,7 +443,7 @@ void tst_QQuickTableView::checkZeroSizedTableView()
|
|||
WAIT_UNTIL_POLISHED;
|
||||
|
||||
QCOMPARE(tableViewPrivate->loadedItems.size(), 2);
|
||||
const auto item = tableView->itemAtCell(0, 0);
|
||||
const auto item = tableView->itemAtIndex(tableView->index(0, 0));
|
||||
QVERIFY(item);
|
||||
QCOMPARE(item->width(), 200);
|
||||
|
||||
|
@ -4758,7 +4758,7 @@ void tst_QQuickTableView::clearSelectionOnTap()
|
|||
QCOMPARE(tableView->selectionModel()->selectedIndexes().size(), 1);
|
||||
|
||||
// Click on a cell. This should remove the selection
|
||||
const auto item = tableView->itemAtCell(0, 0);
|
||||
const auto item = tableView->itemAtIndex(tableView->index(0, 0));
|
||||
QVERIFY(item);
|
||||
QPoint localPos = QPoint(item->width() / 2, item->height() / 2);
|
||||
QPoint pos = item->window()->contentItem()->mapFromItem(item, localPos).toPoint();
|
||||
|
@ -5754,7 +5754,7 @@ void tst_QQuickTableView::boundDelegateComponent()
|
|||
QVERIFY(inner != nullptr);
|
||||
QQuickTableView *tableView = qobject_cast<QQuickTableView *>(inner);
|
||||
QVERIFY(tableView != nullptr);
|
||||
QObject *item = tableView->itemAtCell(0, 0);
|
||||
QObject *item = tableView->itemAtCell({0, 0});
|
||||
QVERIFY(item);
|
||||
QCOMPARE(item->objectName(), QLatin1String("fooouterundefined"));
|
||||
|
||||
|
@ -5762,7 +5762,7 @@ void tst_QQuickTableView::boundDelegateComponent()
|
|||
QVERIFY(inner2 != nullptr);
|
||||
QQuickTableView *tableView2 = qobject_cast<QQuickTableView *>(inner2);
|
||||
QVERIFY(tableView2 != nullptr);
|
||||
QObject *item2 = tableView2->itemAtCell(0, 0);
|
||||
QObject *item2 = tableView2->itemAtCell({0, 0});
|
||||
QVERIFY(item2);
|
||||
QCOMPARE(item2->objectName(), QLatin1String("fooouter0"));
|
||||
|
||||
|
@ -5784,7 +5784,7 @@ void tst_QQuickTableView::boundDelegateComponent()
|
|||
QVERIFY(innerTableView != nullptr);
|
||||
QCOMPARE(innerTableView->rows(), 3);
|
||||
for (int i = 0; i < 3; ++i)
|
||||
QVERIFY(innerTableView->itemAtCell(0, i)->objectName().isEmpty());
|
||||
QVERIFY(innerTableView->itemAtIndex(innerTableView->index(i, 0))->objectName().isEmpty());
|
||||
}
|
||||
|
||||
void tst_QQuickTableView::setColumnWidth_data()
|
||||
|
@ -6161,7 +6161,7 @@ void tst_QQuickTableView::columnResizing()
|
|||
QSignalSpy currentIndexSpy(tableView->selectionModel(), &QItemSelectionModel::currentChanged);
|
||||
QSignalSpy selectionSpy(tableView->selectionModel(), &QItemSelectionModel::selectionChanged);
|
||||
|
||||
const auto item = tableView->itemAtCell(column, 0);
|
||||
const auto item = tableView->itemAtIndex(tableView->index(0, column));
|
||||
QQuickWindow *window = item->window();
|
||||
|
||||
const qreal columnStartWidth = tableView->columnWidth(column);
|
||||
|
@ -6212,7 +6212,7 @@ void tst_QQuickTableView::rowResizing()
|
|||
QSignalSpy currentIndexSpy(tableView->selectionModel(), &QItemSelectionModel::currentChanged);
|
||||
QSignalSpy selectionSpy(tableView->selectionModel(), &QItemSelectionModel::selectionChanged);
|
||||
|
||||
const auto item = tableView->itemAtCell(0, row);
|
||||
const auto item = tableView->itemAtIndex(tableView->index(row, 0));
|
||||
QQuickWindow *window = item->window();
|
||||
|
||||
const qreal rowStartHeight = tableView->rowHeight(row);
|
||||
|
@ -6265,7 +6265,7 @@ void tst_QQuickTableView::rowAndColumnResizing()
|
|||
QCOMPARE(tableView->explicitColumnWidth(rowAndColumn), -1);
|
||||
QCOMPARE(tableView->explicitRowHeight(rowAndColumn), -1);
|
||||
|
||||
const auto item = tableView->itemAtCell(rowAndColumn, rowAndColumn);
|
||||
const auto item = tableView->itemAtIndex(tableView->index(rowAndColumn, rowAndColumn));
|
||||
QVERIFY(item);
|
||||
|
||||
if (addDelegateDragHandler) {
|
||||
|
@ -6320,7 +6320,7 @@ void tst_QQuickTableView::columnResizingDisabled()
|
|||
const int row = 1;
|
||||
QCOMPARE(tableView->explicitRowHeight(row), -1);
|
||||
|
||||
const auto item = tableView->itemAtCell(0, row);
|
||||
const auto item = tableView->itemAtIndex(tableView->index(row, 0));
|
||||
QQuickWindow *window = item->window();
|
||||
|
||||
const QPoint localPos = QPoint(item->width() / 2, item->height());
|
||||
|
@ -6357,7 +6357,7 @@ void tst_QQuickTableView::rowResizingDisabled()
|
|||
const int row = 1;
|
||||
QCOMPARE(tableView->explicitRowHeight(row), -1);
|
||||
|
||||
const auto item = tableView->itemAtCell(0, row);
|
||||
const auto item = tableView->itemAtIndex(tableView->index(row, 0));
|
||||
QQuickWindow *window = item->window();
|
||||
|
||||
const QPoint localPos = QPoint(item->width() / 2, item->height());
|
||||
|
@ -6395,7 +6395,7 @@ void tst_QQuickTableView::dragFromCellCenter()
|
|||
const int row = 1;
|
||||
QCOMPARE(tableView->explicitRowHeight(row), -1);
|
||||
|
||||
const auto item = tableView->itemAtCell(0, row);
|
||||
const auto item = tableView->itemAtIndex(tableView->index(row, 0));
|
||||
QQuickWindow *window = item->window();
|
||||
|
||||
const QPoint localPos = QPoint(item->width() / 2, item->height() / 2);
|
||||
|
|
|
@ -791,7 +791,7 @@ void tst_qquicktreeview::expandAndCollapsUsingDoubleClick()
|
|||
QCOMPARE(treeViewPrivate->loadedRows.count(), 1);
|
||||
|
||||
// Expand the root by double clicking on the row
|
||||
const auto item = treeView->itemAtCell(0, 0);
|
||||
const auto item = treeView->itemAtIndex(treeView->index(0, 0));
|
||||
QVERIFY(item);
|
||||
const QPoint localPos = QPoint(item->width() / 2, item->height() / 2);
|
||||
const QPoint pos = item->window()->contentItem()->mapFromItem(item, localPos).toPoint();
|
||||
|
|
|
@ -91,7 +91,7 @@ void tst_qquicktreeviewdelegate::expandAndCollapsUsingDoubleClick()
|
|||
QCOMPARE(treeViewPrivate->loadedRows.count(), 1);
|
||||
|
||||
// Expand the root by double clicking on the row
|
||||
const auto item = treeView->itemAtCell(0, 0);
|
||||
const auto item = treeView->itemAtIndex(treeView->index(0, 0));
|
||||
QVERIFY(item);
|
||||
const QPoint localPos = QPoint(item->width() / 2, item->height() / 2);
|
||||
const QPoint pos = item->window()->contentItem()->mapFromItem(item, localPos).toPoint();
|
||||
|
@ -128,7 +128,7 @@ void tst_qquicktreeviewdelegate::expandAndCollapseClickOnIndicator()
|
|||
QCOMPARE(treeViewPrivate->loadedRows.count(), 1);
|
||||
|
||||
// Expand the root by clicking on the indicator
|
||||
const auto item = qobject_cast<QQuickTreeViewDelegate *>(treeView->itemAtCell(0, 0));
|
||||
const auto item = qobject_cast<QQuickTreeViewDelegate *>(treeView->itemAtIndex(treeView->index(0, 0)));
|
||||
QVERIFY(item);
|
||||
const auto indicator = item->indicator();
|
||||
const QPoint localPos = QPoint(indicator->width() / 2, indicator->height() / 2);
|
||||
|
@ -159,7 +159,7 @@ void tst_qquicktreeviewdelegate::pointerNavigationDisabled()
|
|||
QVERIFY(!treeView->isExpanded(0));
|
||||
|
||||
// Try to expand the root by clicking on the indicator
|
||||
const auto item = qobject_cast<QQuickTreeViewDelegate *>(treeView->itemAtCell(0, 0));
|
||||
const auto item = qobject_cast<QQuickTreeViewDelegate *>(treeView->itemAtIndex(treeView->index(0, 0)));
|
||||
QVERIFY(item);
|
||||
const auto indicator = item->indicator();
|
||||
QPoint localPos = QPoint(indicator->width() / 2, indicator->height() / 2);
|
||||
|
@ -292,7 +292,7 @@ void tst_qquicktreeviewdelegate::checkClickedSignal()
|
|||
LOAD_TREEVIEW("unmodified.qml");
|
||||
treeView->setPointerNavigationEnabled(pointerNavigationEnabled);
|
||||
|
||||
const auto item = treeView->itemAtCell(0, 0);
|
||||
const auto item = treeView->itemAtIndex(treeView->index(0, 0));
|
||||
QVERIFY(item);
|
||||
|
||||
QSignalSpy clickedSpy(item, SIGNAL(clicked()));
|
||||
|
@ -323,7 +323,7 @@ void tst_qquicktreeviewdelegate::clearSelectionOnClick()
|
|||
QCOMPARE(treeView->selectionModel()->selectedIndexes().size(), 1);
|
||||
|
||||
// Click on a cell. This should remove the selection
|
||||
const auto item = qobject_cast<QQuickTreeViewDelegate *>(treeView->itemAtCell(0, 0));
|
||||
const auto item = qobject_cast<QQuickTreeViewDelegate *>(treeView->itemAtIndex(treeView->index(0, 0)));
|
||||
QVERIFY(item);
|
||||
QPoint localPos = QPoint(item->width() / 2, item->height() / 2);
|
||||
QPoint pos = item->window()->contentItem()->mapFromItem(item, localPos).toPoint();
|
||||
|
@ -348,8 +348,8 @@ void tst_qquicktreeviewdelegate::dragToSelect()
|
|||
QCOMPARE(treeView->selectionBehavior(), QQuickTableView::SelectRows);
|
||||
|
||||
// Drag on from cell 0,0 to 0,1
|
||||
const auto item0_0 = treeView->itemAtCell(0, 0);
|
||||
const auto item0_1 = treeView->itemAtCell(0, 1);
|
||||
const auto item0_0 = treeView->itemAtIndex(treeView->index(0, 0));
|
||||
const auto item0_1 = treeView->itemAtIndex(treeView->index(1, 0));
|
||||
QVERIFY(item0_0);
|
||||
QVERIFY(item0_1);
|
||||
|
||||
|
@ -385,7 +385,7 @@ void tst_qquicktreeviewdelegate::pressAndHoldToSelect()
|
|||
QCOMPARE(treeView->selectionBehavior(), QQuickTableView::SelectRows);
|
||||
|
||||
// PressAndHold on cell 0,0
|
||||
const auto item0_0 = treeView->itemAtCell(0, 0);
|
||||
const auto item0_0 = treeView->itemAtIndex(treeView->index(0, 0));
|
||||
QVERIFY(item0_0);
|
||||
|
||||
QQuickWindow *window = treeView->window();
|
||||
|
|
Loading…
Reference in New Issue