From aeb521054fdc070e3480f30c6595155075c10136 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Thu, 21 Jun 2018 10:28:02 +0200 Subject: QQmlDelegateModel: even for QAIM, only use first column by default In 2f9afadd5d9b4899397dca, we introduced a change in QQmlAdaptorModel so that a QAIM model report that it contains "rows * cols" number of model items, and not just "rows". This was needed, otherwise TableView would only display the first column of such models. It turns out, however, that also ListView will now detect that a QAIM contain more items than just the items in the first column. The result will be that it ends up adding all the other columns underneath the first column in the view. To avoid this unforseen change, this patch will revert this logic, and instead add a private variable that can be set if the new behavior is wanted (e.g by TableView). Change-Id: I8c13da99f05e2f922362e498d1fa1779cdbd0d72 Reviewed-by: Mitch Curtis --- .../quick/qquicklistview/tst_qquicklistview.cpp | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'tests/auto/quick/qquicklistview') diff --git a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp index c1daddb561..5d6708a765 100644 --- a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp +++ b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp @@ -118,6 +118,7 @@ private slots: void noCurrentIndex(); void keyNavigation(); void keyNavigation_data(); + void checkCountForMultiColumnModels(); void enforceRange(); void enforceRange_withoutHighlight(); void spacing(); @@ -1855,6 +1856,38 @@ void tst_QQuickListView::swapWithFirstItem() delete testObject; } +void tst_QQuickListView::checkCountForMultiColumnModels() +{ + // Check that a list view will only load items for the first + // column, even if the model reports that it got several columns. + // We test this since QQmlDelegateModel has been changed to + // also understand multi-column models, but this should not affect ListView. + QScopedPointer window(createView()); + + const int rowCount = 10; + const int columnCount = 10; + + QaimModel model; + model.columns = columnCount; + for (int i = 0; i < rowCount; i++) + model.addItem("Item" + QString::number(i), ""); + + QQmlContext *ctxt = window->rootContext(); + ctxt->setContextProperty("testModel", &model); + + QScopedPointer testObject(new TestObject); + ctxt->setContextProperty("testObject", testObject.data()); + + window->setSource(testFileUrl("listviewtest.qml")); + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window.data())); + + QQuickListView *listview = findItem(window->rootObject(), "list"); + QTRY_VERIFY(listview != nullptr); + + QCOMPARE(listview->count(), rowCount); +} + void tst_QQuickListView::enforceRange() { QScopedPointer window(createView()); -- cgit v1.2.3