QQuickTableView: change order of row and column
The modelIndex() function is added for Qt 6.4, and therefore not yet in any release. Looking at the other functions in QQuickTableView that takes a row and column as arguments (e.g positionViewAtCell() and itemAtCell()), they all have column as first argument, and row as second. So change the modelIndex() function to do the same, so that the TableView API ends up consistent. Change-Id: Ia85ceb3a4719c1e3c16e2023aa039263fef83f6e Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
This commit is contained in:
parent
f9bc831600
commit
7d4b507cc8
|
@ -703,10 +703,10 @@
|
|||
*/
|
||||
|
||||
/*!
|
||||
\qmlmethod QModelIndex QtQuick::TableView::modelIndex(int row, int column)
|
||||
\qmlmethod QModelIndex QtQuick::TableView::modelIndex(int column, int row)
|
||||
\since 6.4
|
||||
|
||||
Returns the \l QModelIndex that maps to \a row and \a column in the view.
|
||||
Returns the \l QModelIndex that maps to \a column and \a row in the view.
|
||||
|
||||
\a row and \a column should be the row and column in the view (table row and
|
||||
table column), and not a row and column in the model.
|
||||
|
@ -4545,7 +4545,7 @@ QPoint QQuickTableView::cellAtIndex(const QModelIndex &index) const
|
|||
return {index.column(), index.row()};
|
||||
}
|
||||
|
||||
QModelIndex QQuickTableView::modelIndex(int row, int column) const
|
||||
QModelIndex QQuickTableView::modelIndex(int column, int row) const
|
||||
{
|
||||
return modelIndex({column, row});
|
||||
}
|
||||
|
|
|
@ -182,8 +182,8 @@ public:
|
|||
Q_REVISION(6, 2) Q_INVOKABLE qreal implicitRowHeight(int row) const;
|
||||
|
||||
Q_REVISION(6, 4) Q_INVOKABLE virtual QModelIndex modelIndex(const QPoint &cell) const;
|
||||
Q_REVISION(6, 4) Q_INVOKABLE virtual QModelIndex modelIndex(int column, int row) const;
|
||||
Q_REVISION(6, 4) Q_INVOKABLE virtual QPoint cellAtIndex(const QModelIndex &index) const;
|
||||
Q_REVISION(6, 4) Q_INVOKABLE virtual QModelIndex modelIndex(int row, int column) const;
|
||||
Q_REVISION(6, 4) Q_INVOKABLE int rowAtIndex(const QModelIndex &index) const;
|
||||
Q_REVISION(6, 4) Q_INVOKABLE int columnAtIndex(const QModelIndex &index) const;
|
||||
|
||||
|
|
|
@ -566,7 +566,7 @@ QPoint QQuickTreeView::cellAtIndex(const QModelIndex &index) const
|
|||
return QPoint(tableIndex.column(), tableIndex.row());
|
||||
}
|
||||
|
||||
QModelIndex QQuickTreeView::modelIndex(int row, int column) const
|
||||
QModelIndex QQuickTreeView::modelIndex(int column, int row) const
|
||||
{
|
||||
return modelIndex({column, row});
|
||||
}
|
||||
|
|
|
@ -80,8 +80,8 @@ public:
|
|||
Q_REVISION(6, 4) Q_INVOKABLE void expandToIndex(const QModelIndex &index);
|
||||
|
||||
Q_INVOKABLE QModelIndex modelIndex(const QPoint &cell) const override;
|
||||
Q_INVOKABLE QModelIndex modelIndex(int column, int row) const override;
|
||||
Q_INVOKABLE QPoint cellAtIndex(const QModelIndex &index) const override;
|
||||
Q_INVOKABLE QModelIndex modelIndex(int row, int column) const override;
|
||||
|
||||
signals:
|
||||
void expanded(int row, int depth);
|
||||
|
|
|
@ -483,7 +483,7 @@ void tst_qquicktreeview::expandRecursivelyRoot()
|
|||
// Check that all rows after rowToExpand, that are also
|
||||
// children of that row, is expanded (down to depth)
|
||||
for (int currentRow = rowToExpand + 1; currentRow < treeView->rows(); ++currentRow) {
|
||||
const auto modelIndex = treeView->modelIndex(currentRow, 0);
|
||||
const auto modelIndex = treeView->modelIndex(0, currentRow);
|
||||
const int currentDepth = treeView->depth(currentRow);
|
||||
const bool isChild = currentDepth > rowToExpandDepth;
|
||||
const bool isExpandable = model->rowCount(modelIndex) > 0;
|
||||
|
@ -554,7 +554,7 @@ void tst_qquicktreeview::expandRecursivelyChild()
|
|||
for (int currentRow = rowToExpand + 1; currentRow < treeView->rows(); ++currentRow) {
|
||||
const int currentDepth = treeView->depth(currentRow);
|
||||
const bool isChild = currentDepth > rowToExpandDepth;
|
||||
const auto modelIndex = treeView->modelIndex(currentRow, 0);
|
||||
const auto modelIndex = treeView->modelIndex(0, currentRow);
|
||||
const bool isExpandable = model->rowCount(modelIndex) > 0;
|
||||
const bool shouldBeExpanded = isChild && isExpandable && currentDepth < effectiveMaxDepth;
|
||||
QCOMPARE(treeView->isExpanded(currentRow), shouldBeExpanded);
|
||||
|
@ -577,7 +577,7 @@ void tst_qquicktreeview::expandRecursivelyWholeTree()
|
|||
|
||||
// Check that all rows that have children are expanded
|
||||
for (int currentRow = 0; currentRow < treeView->rows(); ++currentRow) {
|
||||
const auto modelIndex = treeView->modelIndex(currentRow, 0);
|
||||
const auto modelIndex = treeView->modelIndex(0, currentRow);
|
||||
const bool isExpandable = model->rowCount(modelIndex) > 0;
|
||||
QCOMPARE(treeView->isExpanded(currentRow), isExpandable);
|
||||
}
|
||||
|
@ -615,7 +615,7 @@ void tst_qquicktreeview::collapseRecursivelyRoot()
|
|||
// We can do that by simply iterate over the rows in the view as we expand.
|
||||
int currentRow = 0;
|
||||
while (currentRow < treeView->rows()) {
|
||||
const QModelIndex currentIndex = treeView->modelIndex(currentRow, 0);
|
||||
const QModelIndex currentIndex = treeView->modelIndex(0, currentRow);
|
||||
if (model->hasChildren(currentIndex)) {
|
||||
QVERIFY(!treeView->isExpanded(currentRow));
|
||||
treeView->expand(currentRow);
|
||||
|
@ -644,7 +644,7 @@ void tst_qquicktreeview::collapseRecursivelyChild()
|
|||
|
||||
// Collapse the 4th child recursive
|
||||
const int rowToCollapse = 4;
|
||||
QCOMPARE(model->data(treeView->modelIndex(rowToCollapse, 0), Qt::DisplayRole), QStringLiteral("3, 0"));
|
||||
QCOMPARE(model->data(treeView->modelIndex(0, rowToCollapse), Qt::DisplayRole), QStringLiteral("3, 0"));
|
||||
treeView->collapseRecursively(rowToCollapse);
|
||||
|
||||
QCOMPARE(spy.count(), 1);
|
||||
|
@ -662,7 +662,7 @@ void tst_qquicktreeview::collapseRecursivelyChild()
|
|||
// We can do that by simply iterate over the rows in the view as we expand.
|
||||
int currentRow = 1; // start at first child
|
||||
while (currentRow < treeView->rows()) {
|
||||
const QModelIndex currentIndex = treeView->modelIndex(currentRow, 0);
|
||||
const QModelIndex currentIndex = treeView->modelIndex(0, currentRow);
|
||||
if (model->hasChildren(currentIndex)) {
|
||||
QVERIFY(!treeView->isExpanded(currentRow));
|
||||
treeView->expand(currentRow);
|
||||
|
|
Loading…
Reference in New Issue