aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/quick/items/qquicktableview.cpp9
-rw-r--r--src/quick/items/qquicktableview_p.h22
-rw-r--r--tests/auto/quick/qquicktableview/tst_qquicktableview.cpp33
-rw-r--r--tests/manual/tableview/abstracttablemodel/main.qml4
-rw-r--r--tests/manual/tableview/listmodel/main.qml2
5 files changed, 21 insertions, 49 deletions
diff --git a/src/quick/items/qquicktableview.cpp b/src/quick/items/qquicktableview.cpp
index 0485f7c7b8..26aa409cec 100644
--- a/src/quick/items/qquicktableview.cpp
+++ b/src/quick/items/qquicktableview.cpp
@@ -1201,16 +1201,7 @@ void QQuickTableViewPrivate::initItemCallback(int modelIndex, QObject *object)
if (!attached)
return;
- // Even though row and column is injected directly into the context of a delegate item
- // from QQmlDelegateModel and its model classes, they will only return which row and
- // column an item represents in the model. This might be different from which
- // cell an item ends up in in the Table, if a different rows/columns has been set
- // on it (which is typically the case for list models). For those cases, Table.row
- // and Table.column can be helpful.
- QPoint cell = cellAtModelIndex(modelIndex);
attached->setTableView(q_func());
- attached->setColumn(cell.x());
- attached->setRow(cell.y());
}
void QQuickTableViewPrivate::modelUpdated(const QQmlChangeSet &changeSet, bool reset)
diff --git a/src/quick/items/qquicktableview_p.h b/src/quick/items/qquicktableview_p.h
index f3a589b9e4..d2c3f17bc4 100644
--- a/src/quick/items/qquicktableview_p.h
+++ b/src/quick/items/qquicktableview_p.h
@@ -144,8 +144,6 @@ class Q_QUICK_PRIVATE_EXPORT QQuickTableViewAttached : public QObject
Q_PROPERTY(QQuickTableView *tableView READ tableView NOTIFY tableViewChanged)
Q_PROPERTY(qreal cellWidth READ cellWidth WRITE setCellWidth NOTIFY cellWidthChanged)
Q_PROPERTY(qreal cellHeight READ cellHeight WRITE setCellHeight NOTIFY cellHeightChanged)
- Q_PROPERTY(int row READ row NOTIFY rowChanged)
- Q_PROPERTY(int column READ column NOTIFY columnChanged)
public:
QQuickTableViewAttached(QObject *parent)
@@ -175,33 +173,13 @@ public:
Q_EMIT cellHeightChanged();
}
- int row() const { return m_row; }
- void setRow(int newRow) {
- if (newRow == m_row)
- return;
- m_row = newRow;
- Q_EMIT rowChanged();
- }
-
- int column() const { return m_column; }
- void setColumn(int newColumn) {
- if (newColumn == m_column)
- return;
- m_column = newColumn;
- Q_EMIT columnChanged();
- }
-
Q_SIGNALS:
void tableViewChanged();
void cellWidthChanged();
void cellHeightChanged();
- void rowChanged();
- void columnChanged();
private:
QPointer<QQuickTableView> m_tableview;
- int m_row = -1;
- int m_column = -1;
QQmlNullableValue<qreal> m_cellWidth;
QQmlNullableValue<qreal> m_cellHeight;
diff --git a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
index 6714779fc8..8caced4396 100644
--- a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
+++ b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
@@ -75,6 +75,7 @@ public:
tst_QQuickTableView();
QQuickTableViewAttached *getAttachedObject(const QObject *object) const;
+ QPoint getContextRowAndColumn(const QQuickItem *item) const;
private slots:
void initTestCase() override;
@@ -119,6 +120,14 @@ QQuickTableViewAttached *tst_QQuickTableView::getAttachedObject(const QObject *o
return static_cast<QQuickTableViewAttached *>(attachedObject);
}
+QPoint tst_QQuickTableView::getContextRowAndColumn(const QQuickItem *item) const
+{
+ const auto context = qmlContext(item);
+ const int row = context->contextProperty("row").toInt();
+ const int column = context->contextProperty("column").toInt();
+ return QPoint(column, row);
+}
+
void tst_QQuickTableView::setAndGetModel_data()
{
QTest::addColumn<QVariant>("model");
@@ -343,11 +352,9 @@ void tst_QQuickTableView::checkLayoutOfEqualSizedDelegateItems()
QVERIFY(item);
QCOMPARE(item->parentItem(), tableView->contentItem());
- auto attached = getAttachedObject(item);
- int row = attached->row();
- int column = attached->column();
- qreal expectedX = margins.left() + (column * (expectedItemWidth + spacing.width()));
- qreal expectedY = margins.top() + (row * (expectedItemHeight + spacing.height()));
+ const QPoint cell = getContextRowAndColumn(item);
+ qreal expectedX = margins.left() + (cell.x() * (expectedItemWidth + spacing.width()));
+ qreal expectedY = margins.top() + (cell.y() * (expectedItemHeight + spacing.height()));
QCOMPARE(item->x(), expectedX);
QCOMPARE(item->y(), expectedY);
QCOMPARE(item->width(), expectedItemWidth);
@@ -452,7 +459,7 @@ void tst_QQuickTableView::fillTableViewButNothingMore()
auto const bottomRightFxItem = tableViewPrivate->loadedTableItem(tableViewPrivate->loadedTable.bottomRight());
auto const bottomRightItem = bottomRightFxItem->item;
- auto bottomRightAttached = getAttachedObject(bottomRightItem);
+ const QPoint bottomRightCell = getContextRowAndColumn(bottomRightItem.data());
// Check that the right-most item is overlapping the right edge of the view
QVERIFY(bottomRightItem->x() < tableView->width());
@@ -462,7 +469,7 @@ void tst_QQuickTableView::fillTableViewButNothingMore()
qreal cellWidth = bottomRightItem->width() + spacing.width();
qreal availableWidth = tableView->width() - margins.left();
int expectedColumns = qCeil(availableWidth / cellWidth);
- int actualColumns = bottomRightAttached->column() + 1;
+ int actualColumns = bottomRightCell.x() + 1;
QCOMPARE(actualColumns, expectedColumns);
// Check that the bottom-most item is overlapping the bottom edge of the view
@@ -473,7 +480,7 @@ void tst_QQuickTableView::fillTableViewButNothingMore()
qreal cellHeight = bottomRightItem->height() + spacing.height();
qreal availableHeight = tableView->height() - margins.top();
int expectedRows = qCeil(availableHeight / cellHeight);
- int actualRows = bottomRightAttached->row() + 1;
+ int actualRows = bottomRightCell.y() + 1;
QCOMPARE(actualRows, expectedRows);
}
@@ -500,22 +507,18 @@ void tst_QQuickTableView::checkInitialAttachedProperties()
for (auto fxItem : tableViewPrivate->loadedItems) {
const int index = fxItem->index;
const auto item = fxItem->item;
- const auto attached = getAttachedObject(item);
const auto context = qmlContext(item.data());
const QPoint cell = tableViewPrivate->cellAtModelIndex(index);
const int contextIndex = context->contextProperty("index").toInt();
- const int contextRow = context->contextProperty("row").toInt();
- const int contextColumn = context->contextProperty("column").toInt();
+ const QPoint contextCell = getContextRowAndColumn(item.data());
const QString contextModelData = context->contextProperty("modelData").toString();
const QQmlDelegateModelAttached *delegateModelAttached =
static_cast<QQmlDelegateModelAttached *>(
qmlAttachedPropertiesObject<QQmlDelegateModel>(item));
const int contextItemsIndex = delegateModelAttached->property("itemsIndex").toInt();
- QCOMPARE(attached->row(), cell.y());
- QCOMPARE(attached->column(), cell.x());
- QCOMPARE(contextRow, cell.y());
- QCOMPARE(contextColumn, cell.x());
+ QCOMPARE(contextCell.y(), cell.y());
+ QCOMPARE(contextCell.x(), cell.x());
QCOMPARE(contextIndex, index);
QCOMPARE(contextModelData, QStringLiteral("%1").arg(cell.y()));
QCOMPARE(contextItemsIndex, index);
diff --git a/tests/manual/tableview/abstracttablemodel/main.qml b/tests/manual/tableview/abstracttablemodel/main.qml
index c448815a7c..271752aaf1 100644
--- a/tests/manual/tableview/abstracttablemodel/main.qml
+++ b/tests/manual/tableview/abstracttablemodel/main.qml
@@ -76,8 +76,8 @@ Window {
Component {
id: tableViewDelegate
Rectangle {
- TableView.cellWidth: TableView.column % 3 ? 80 : 50
- TableView.cellHeight: TableView.row % 3 ? 80 : 50
+ TableView.cellWidth: column % 3 ? 80 : 50
+ TableView.cellHeight: row % 3 ? 80 : 50
Text {
anchors.centerIn: parent
diff --git a/tests/manual/tableview/listmodel/main.qml b/tests/manual/tableview/listmodel/main.qml
index b5a1ab8379..ca39e6a2b9 100644
--- a/tests/manual/tableview/listmodel/main.qml
+++ b/tests/manual/tableview/listmodel/main.qml
@@ -77,7 +77,7 @@ Window {
Text {
anchors.centerIn: parent
- text: name + "\n[" + tableDelegate.TableView.column + ", " + tableDelegate.TableView.row + "]"
+ text: name + "\n[" + column + ", " + row + "]"
}
}
}