diff options
-rw-r--r-- | src/qml/types/qqmldelegatemodel.cpp | 14 | ||||
-rw-r--r-- | src/qml/types/qqmldelegatemodel_p_p.h | 3 | ||||
-rw-r--r-- | src/quick/items/qquicktableview.cpp | 2 | ||||
-rw-r--r-- | tests/auto/quick/qquicklistview/tst_qquicklistview.cpp | 33 | ||||
-rw-r--r-- | tests/auto/quick/shared/viewtestutil.cpp | 8 | ||||
-rw-r--r-- | tests/auto/quick/shared/viewtestutil.h | 3 |
6 files changed, 58 insertions, 5 deletions
diff --git a/src/qml/types/qqmldelegatemodel.cpp b/src/qml/types/qqmldelegatemodel.cpp index 68bb185eaa..33fe5f3438 100644 --- a/src/qml/types/qqmldelegatemodel.cpp +++ b/src/qml/types/qqmldelegatemodel.cpp @@ -213,6 +213,7 @@ QQmlDelegateModelPrivate::QQmlDelegateModelPrivate(QQmlContext *ctxt) , m_transaction(false) , m_incubatorCleanupScheduled(false) , m_waitingToFetchMore(false) + , m_useFirstColumnOnly(true) , m_cacheItems(nullptr) , m_items(nullptr) , m_persistedItems(nullptr) @@ -227,6 +228,11 @@ QQmlDelegateModelPrivate::~QQmlDelegateModelPrivate() m_cacheMetaType->release(); } +int QQmlDelegateModelPrivate::adaptorModelCount() const +{ + return m_useFirstColumnOnly ? m_adaptorModel.rowCount() : m_adaptorModel.count(); +} + void QQmlDelegateModelPrivate::requestMoreIfNecessary() { Q_Q(QQmlDelegateModel); @@ -336,7 +342,7 @@ void QQmlDelegateModel::componentComplete() static_cast<QQmlPartsModel *>(d->m_pendingParts.first())->updateFilterGroup(); QVector<Compositor::Insert> inserts; - d->m_count = d->m_adaptorModel.count(); + d->m_count = d->adaptorModelCount(); d->m_compositor.append( &d->m_adaptorModel, 0, @@ -383,7 +389,7 @@ void QQmlDelegateModel::setModel(const QVariant &model) } if (d->m_complete) { - _q_itemsInserted(0, d->m_adaptorModel.count()); + _q_itemsInserted(0, d->adaptorModelCount()); d->requestMoreIfNecessary(); } } @@ -475,7 +481,7 @@ void QQmlDelegateModel::setRootIndex(const QVariant &root) if (d->m_adaptorModel.canFetchMore()) d->m_adaptorModel.fetchMore(); if (d->m_complete) { - const int newCount = d->m_adaptorModel.count(); + const int newCount = d->adaptorModelCount(); if (oldCount) _q_itemsRemoved(0, oldCount); if (newCount) @@ -1545,7 +1551,7 @@ void QQmlDelegateModel::_q_modelReset() d->m_adaptorModel.rootIndex = QModelIndex(); if (d->m_complete) { - d->m_count = d->m_adaptorModel.count(); + d->m_count = d->adaptorModelCount(); const QList<QQmlDelegateModelItem *> cache = d->m_cache; for (int i = 0, c = cache.count(); i < c; ++i) { diff --git a/src/qml/types/qqmldelegatemodel_p_p.h b/src/qml/types/qqmldelegatemodel_p_p.h index d5f79fab62..a0c1f6aa12 100644 --- a/src/qml/types/qqmldelegatemodel_p_p.h +++ b/src/qml/types/qqmldelegatemodel_p_p.h @@ -302,6 +302,8 @@ public: bool insert(Compositor::insert_iterator &before, const QV4::Value &object, int groups); + int adaptorModelCount() const; + static void group_append(QQmlListProperty<QQmlDelegateModelGroup> *property, QQmlDelegateModelGroup *group); static int group_count(QQmlListProperty<QQmlDelegateModelGroup> *property); static QQmlDelegateModelGroup *group_at(QQmlListProperty<QQmlDelegateModelGroup> *property, int index); @@ -334,6 +336,7 @@ public: bool m_transaction : 1; bool m_incubatorCleanupScheduled : 1; bool m_waitingToFetchMore : 1; + bool m_useFirstColumnOnly : 1; union { struct { diff --git a/src/quick/items/qquicktableview.cpp b/src/quick/items/qquicktableview.cpp index 8c092c5894..bcdc06a783 100644 --- a/src/quick/items/qquicktableview.cpp +++ b/src/quick/items/qquicktableview.cpp @@ -42,6 +42,7 @@ #include <QtCore/qtimer.h> #include <QtQml/private/qqmldelegatemodel_p.h> +#include <QtQml/private/qqmldelegatemodel_p_p.h> #include <QtQml/private/qqmlincubator_p.h> #include <QtQml/private/qqmlchangeset_p.h> #include <QtQml/qqmlinfo.h> @@ -1392,6 +1393,7 @@ void QQuickTableView::setModel(const QVariant &newModel) } else { if (!d->delegateModel) d->createWrapperModel(); + QQmlDelegateModelPrivate::get(d->delegateModel)->m_useFirstColumnOnly = false; d->delegateModel->setModel(effectiveModelVariant); } 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<QQuickView> 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> testObject(new TestObject); + ctxt->setContextProperty("testObject", testObject.data()); + + window->setSource(testFileUrl("listviewtest.qml")); + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window.data())); + + QQuickListView *listview = findItem<QQuickListView>(window->rootObject(), "list"); + QTRY_VERIFY(listview != nullptr); + + QCOMPARE(listview->count(), rowCount); +} + void tst_QQuickListView::enforceRange() { QScopedPointer<QQuickView> window(createView()); diff --git a/tests/auto/quick/shared/viewtestutil.cpp b/tests/auto/quick/shared/viewtestutil.cpp index dc813b9d59..3bfa23173e 100644 --- a/tests/auto/quick/shared/viewtestutil.cpp +++ b/tests/auto/quick/shared/viewtestutil.cpp @@ -153,6 +153,12 @@ int QQuickViewTestUtil::QaimModel::rowCount(const QModelIndex &parent) const return list.count(); } +int QQuickViewTestUtil::QaimModel::columnCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent); + return columns; +} + QHash<int,QByteArray> QQuickViewTestUtil::QaimModel::roleNames() const { QHash<int,QByteArray> roles = QAbstractListModel::roleNames(); @@ -174,7 +180,7 @@ QVariant QQuickViewTestUtil::QaimModel::data(const QModelIndex &index, int role) int QQuickViewTestUtil::QaimModel::count() const { - return rowCount(); + return rowCount() * columnCount(); } QString QQuickViewTestUtil::QaimModel::name(int index) const diff --git a/tests/auto/quick/shared/viewtestutil.h b/tests/auto/quick/shared/viewtestutil.h index b11d5e4859..04e1771ef8 100644 --- a/tests/auto/quick/shared/viewtestutil.h +++ b/tests/auto/quick/shared/viewtestutil.h @@ -76,6 +76,7 @@ namespace QQuickViewTestUtil QaimModel(QObject *parent=0); int rowCount(const QModelIndex &parent=QModelIndex()) const; + int columnCount(const QModelIndex &parent=QModelIndex()) const; QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const; QHash<int,QByteArray> roleNames() const; @@ -104,6 +105,8 @@ namespace QQuickViewTestUtil using QAbstractListModel::dataChanged; + int columns = 1; + private: QList<QPair<QString,QString> > list; }; |