aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/quick/qquicktableview/testmodel.h2
-rw-r--r--tests/auto/quick/qquicktableview/tst_qquicktableview.cpp47
2 files changed, 48 insertions, 1 deletions
diff --git a/tests/auto/quick/qquicktableview/testmodel.h b/tests/auto/quick/qquicktableview/testmodel.h
index 8182278103..06384f7a5e 100644
--- a/tests/auto/quick/qquicktableview/testmodel.h
+++ b/tests/auto/quick/qquicktableview/testmodel.h
@@ -60,7 +60,7 @@ public:
int cell = index.row() + (index.column() * m_columns);
if (selectedCells.contains(cell))
return QStringLiteral("selected");
- return QString("%1,%2").arg(index.column()).arg(index.row());
+ return QString("%1").arg(index.row());
}
QHash<int, QByteArray> roleNames() const override
diff --git a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
index 29b8553af5..1de40aaae0 100644
--- a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
+++ b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp
@@ -96,6 +96,8 @@ private slots:
void checkTableMargins();
void fillTableViewButNothingMore_data();
void fillTableViewButNothingMore();
+ void checkInitialAttachedProperties_data();
+ void checkInitialAttachedProperties();
void flick_data();
void flick();
void flickOvershoot_data();
@@ -509,6 +511,51 @@ void tst_QQuickTableView::fillTableViewButNothingMore()
QCOMPARE(actualRows, expectedRows);
}
+void tst_QQuickTableView::checkInitialAttachedProperties_data()
+{
+ QTest::addColumn<QVariant>("model");
+
+ QTest::newRow("QAIM") << TestModelAsVariant(4, 4);
+ QTest::newRow("Number model") << QVariant::fromValue(4);
+ QTest::newRow("QStringList") << QVariant::fromValue(QStringList() << "0" << "1" << "2" << "3");
+}
+
+void tst_QQuickTableView::checkInitialAttachedProperties()
+{
+ // Check that the context and attached properties inside
+ // the delegate items are what we expect at start-up.
+ QFETCH(QVariant, model);
+ LOAD_TABLEVIEW("plaintableview.qml");
+
+ tableView->setModel(model);
+
+ WAIT_UNTIL_POLISHED;
+
+ 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 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(contextIndex, index);
+ QCOMPARE(contextModelData, QStringLiteral("%1").arg(cell.y()));
+ QCOMPARE(contextItemsIndex, index);
+ }
+}
+
void tst_QQuickTableView::flick_data()
{
QTest::addColumn<QSizeF>("spacing");