diff options
author | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2018-06-06 15:53:16 +0200 |
---|---|---|
committer | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2018-06-09 16:58:13 +0000 |
commit | 7d55fb4029f4cc9bc5e5b4cef7ef5a456d42f83f (patch) | |
tree | 2be582752ffde4fa72dbe67c5528b963cd11b143 /tests | |
parent | 90fea15e0dfc62ecd668d1b0462d121dba5c1b7e (diff) |
QQmlDelegateModelItem: move row and column up to the base class
Change 8c33c70 injected row and column (alongside index) into
the QML context of a delegate when the view had a
QAbstractItemModel as model.
Rather than only inject those properties when using QAIM, this patch
will move the code to the base class. This way, if a view uses e.g
a javascript list as model, row and column is still be available. This
is useful, since then the delegate can bind to both row and column
regardless of what kind of model the view uses. In the case of a
list model, the column property will always be 0.
Change-Id: I1d9f11c0b7d7a5beb83198184ba12cc1e48cd100
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/quick/qquicktableview/testmodel.h | 2 | ||||
-rw-r--r-- | tests/auto/quick/qquicktableview/tst_qquicktableview.cpp | 47 |
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"); |