diff options
-rw-r--r-- | src/qml/types/qqmldelegatemodel.cpp | 18 | ||||
-rw-r--r-- | src/qml/types/qqmldelegatemodel_p.h | 2 | ||||
-rw-r--r-- | tests/auto/quick/qquicklistview/data/qtbug39492.qml | 40 | ||||
-rw-r--r-- | tests/auto/quick/qquicklistview/tst_qquicklistview.cpp | 88 | ||||
-rw-r--r-- | tools/qmlplugindump/main.cpp | 1 |
5 files changed, 145 insertions, 4 deletions
diff --git a/src/qml/types/qqmldelegatemodel.cpp b/src/qml/types/qqmldelegatemodel.cpp index 23bdeb55b2..aab385ceb5 100644 --- a/src/qml/types/qqmldelegatemodel.cpp +++ b/src/qml/types/qqmldelegatemodel.cpp @@ -1521,6 +1521,18 @@ void QQmlDelegateModel::_q_dataChanged(const QModelIndex &begin, const QModelInd _q_itemsChanged(begin.row(), end.row() - begin.row() + 1, roles); } +bool QQmlDelegateModel::isDescendantOf(const QPersistentModelIndex& desc, const QList< QPersistentModelIndex >& parents) const +{ + for (int i = 0, c = parents.count(); i < c; ++i) { + for (QPersistentModelIndex parent = desc; parent.isValid(); parent = parent.parent()) { + if (parent == parents[i]) + return true; + } + } + + return false; +} + void QQmlDelegateModel::_q_layoutAboutToBeChanged(const QList<QPersistentModelIndex> &parents, QAbstractItemModel::LayoutChangeHint hint) { Q_D(QQmlDelegateModel); @@ -1529,8 +1541,9 @@ void QQmlDelegateModel::_q_layoutAboutToBeChanged(const QList<QPersistentModelIn if (hint == QAbstractItemModel::VerticalSortHint) { d->m_storedPersistentIndexes.clear(); - if (!parents.contains(d->m_adaptorModel.rootIndex)) + if (!parents.isEmpty() && d->m_adaptorModel.rootIndex.isValid() && !isDescendantOf(d->m_adaptorModel.rootIndex, parents)) { return; + } for (int i = 0; i < d->m_count; ++i) { const QModelIndex index = d->m_adaptorModel.aim()->index(i, 0, d->m_adaptorModel.rootIndex); @@ -1550,8 +1563,9 @@ void QQmlDelegateModel::_q_layoutChanged(const QList<QPersistentModelIndex> &par return; if (hint == QAbstractItemModel::VerticalSortHint) { - if (!parents.contains(d->m_adaptorModel.rootIndex)) + if (!parents.isEmpty() && d->m_adaptorModel.rootIndex.isValid() && !isDescendantOf(d->m_adaptorModel.rootIndex, parents)) { return; + } for (int i = 0, c = d->m_storedPersistentIndexes.count(); i < c; ++i) { const QPersistentModelIndex &index = d->m_storedPersistentIndexes.at(i); diff --git a/src/qml/types/qqmldelegatemodel_p.h b/src/qml/types/qqmldelegatemodel_p.h index 0b67179163..53cc94bbdf 100644 --- a/src/qml/types/qqmldelegatemodel_p.h +++ b/src/qml/types/qqmldelegatemodel_p.h @@ -143,6 +143,8 @@ private Q_SLOTS: void _q_layoutChanged(const QList<QPersistentModelIndex>&, QAbstractItemModel::LayoutChangeHint); private: + bool isDescendantOf(const QPersistentModelIndex &desc, const QList<QPersistentModelIndex> &parents) const; + Q_DISABLE_COPY(QQmlDelegateModel) }; diff --git a/tests/auto/quick/qquicklistview/data/qtbug39492.qml b/tests/auto/quick/qquicklistview/data/qtbug39492.qml new file mode 100644 index 0000000000..4df3a080d7 --- /dev/null +++ b/tests/auto/quick/qquicklistview/data/qtbug39492.qml @@ -0,0 +1,40 @@ +import QtQuick 2.0 +import QtQml.Models 2.1 + +Rectangle { + id: root + width: 240 + height: 320 + color: "#ffffff" + + + Component { + id: myDelegate + Rectangle { + id: wrapper + objectName: "wrapper" + height: 20 + width: 240 + Text { + objectName: "delegateText" + text: display + } + color: ListView.isCurrentItem ? "lightsteelblue" : "white" + } + } + + DelegateModel { + id: delegateModel + objectName: "delegateModel" + model: testModel + delegate: myDelegate + } + + ListView { + id: list + objectName: "listView" + model: delegateModel; + focus: true + anchors.fill: parent + } +} diff --git a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp index 4fcf186690..d22f3487da 100644 --- a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp +++ b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp @@ -41,6 +41,8 @@ #include <QtTest/QtTest> #include <QtCore/QStringListModel> +#include <QtCore/QSortFilterProxyModel> +#include <QtGui/QStandardItemModel> #include <QtQuick/qquickview.h> #include <QtQml/qqmlengine.h> #include <QtQml/qqmlcontext.h> @@ -50,6 +52,7 @@ #include <QtQuick/private/qquicktext_p.h> #include <QtQml/private/qqmlobjectmodel_p.h> #include <QtQml/private/qqmllistmodel_p.h> +#include <QtQml/private/qqmldelegatemodel_p.h> #include "../../shared/util.h" #include "../shared/viewtestutil.h" #include "../shared/visualtestutil.h" @@ -63,6 +66,7 @@ Q_DECLARE_METATYPE(QQuickItemView::VerticalLayoutDirection) Q_DECLARE_METATYPE(QQuickItemView::PositionMode) Q_DECLARE_METATYPE(QQuickListView::Orientation) Q_DECLARE_METATYPE(Qt::Key) +Q_DECLARE_METATYPE(QPersistentModelIndex) using namespace QQuickViewTestUtil; using namespace QQuickVisualTestUtil; @@ -234,6 +238,9 @@ private slots: void layoutChange(); + void QTBUG_39492_data(); + void QTBUG_39492(); + private: template <class T> void items(const QUrl &source); template <class T> void changed(const QUrl &source); @@ -7403,8 +7410,85 @@ void tst_QQuickListView::layoutChange() } } -QTEST_MAIN(tst_QQuickListView) +void tst_QQuickListView::QTBUG_39492_data() +{ + QStandardItemModel *sourceModel = new QStandardItemModel(this); + for (int i = 0; i < 5; ++i) { + QStandardItem *item = new QStandardItem(QString::number(i)); + for (int j = 0; j < 5; ++j) { + QStandardItem *subItem = new QStandardItem(QString("%1-%2").arg(i).arg(j)); + item->appendRow(subItem); + } + sourceModel->appendRow(item); + } -#include "tst_qquicklistview.moc" + QSortFilterProxyModel *sortModel = new QSortFilterProxyModel(this); + sortModel->setSourceModel(sourceModel); + + QTest::addColumn<QSortFilterProxyModel*>("model"); + QTest::addColumn<QPersistentModelIndex>("rootIndex"); + + QTest::newRow("invalid rootIndex") + << sortModel + << QPersistentModelIndex(); + + QTest::newRow("rootIndex 1") + << sortModel + << QPersistentModelIndex(sortModel->index(1, 0)); + QTest::newRow("rootIndex 3") + << sortModel + << QPersistentModelIndex(sortModel->index(3, 0)); + const QModelIndex rootIndex2 = sortModel->index(2, 0); + QTest::newRow("rootIndex 2-1") + << sortModel + << QPersistentModelIndex(sortModel->index(1, 0, rootIndex2)); +} + +void tst_QQuickListView::QTBUG_39492() +{ + QFETCH(QSortFilterProxyModel*, model); + QFETCH(QPersistentModelIndex, rootIndex); + + QQuickView *window = getView(); + window->rootContext()->setContextProperty("testModel", QVariant::fromValue(model)); + window->setSource(testFileUrl("qtbug39492.qml")); + + QQuickListView *listview = window->rootObject()->findChild<QQuickListView *>("listView"); + QVERIFY(listview); + + QQmlDelegateModel *delegateModel = window->rootObject()->findChild<QQmlDelegateModel *>("delegateModel"); + QVERIFY(delegateModel); + + delegateModel->setRootIndex(QVariant::fromValue(QModelIndex(rootIndex))); + model->sort(0, Qt::AscendingOrder); + listview->forceLayout(); + + for (int i = 0; i < model->rowCount(rootIndex); ++i) { + QQuickItem *delegateItem = listview->itemAt(10, 10 + i * 20); + QVERIFY(delegateItem); + QQuickItem *delegateText = delegateItem->findChild<QQuickItem *>("delegateText"); + QVERIFY(delegateText); + QCOMPARE(delegateText->property("text").toString(), + model->index(i, 0, rootIndex).data().toString()); + } + + model->sort(0, Qt::DescendingOrder); + listview->forceLayout(); + + for (int i = 0; i < model->rowCount(rootIndex); ++i) { + QQuickItem *delegateItem = listview->itemAt(10, 10 + i * 20); + QVERIFY(delegateItem); + QQuickItem *delegateText = delegateItem->findChild<QQuickItem *>("delegateText"); + QVERIFY(delegateText); + QCOMPARE(delegateText->property("text").toString(), + model->index(i, 0, rootIndex).data().toString()); + } + + releaseView(window); +} + +QTEST_MAIN(tst_QQuickListView) + +#include "tst_qquicklistview.moc" diff --git a/tools/qmlplugindump/main.cpp b/tools/qmlplugindump/main.cpp index bc55c40434..192c85513f 100644 --- a/tools/qmlplugindump/main.cpp +++ b/tools/qmlplugindump/main.cpp @@ -306,6 +306,7 @@ QSet<const QMetaObject *> collectReachableMetaObjects(QQmlEngine *engine, std::cerr << "Got " << qPrintable( tyName ) << " (" << qPrintable( QString::fromUtf8(ty->typeName()) ) << ")" << std::endl; collectReachableMetaObjects(object, &metas); + object->deleteLater(); } else { std::cerr << "Could not create" << qPrintable(tyName) << std::endl; } |