diff options
author | Fabian Bumberger <fbumberger@rim.com> | 2013-10-10 21:45:19 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-10-17 12:53:26 +0200 |
commit | 83c466dd8c62ebfb80c753c458683ee24aeff907 (patch) | |
tree | c8ee68aa26adce5f16ac84e83913cdf0df979eeb | |
parent | a8cfbf6aa61c85bd082583388e5cfac84e0f4d3f (diff) |
Fix crash in FolderListModel
Change-Id: I8d012e9a356676dd3dad246579c7339eaddc1e91
Reviewed-by: Alan Alpert <aalpert@blackberry.com>
Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
3 files changed, 29 insertions, 8 deletions
diff --git a/src/imports/folderlistmodel/qquickfolderlistmodel.cpp b/src/imports/folderlistmodel/qquickfolderlistmodel.cpp index 032c32a241..7cab257d32 100644 --- a/src/imports/folderlistmodel/qquickfolderlistmodel.cpp +++ b/src/imports/folderlistmodel/qquickfolderlistmodel.cpp @@ -193,9 +193,11 @@ void QQuickFolderListModelPrivate::_q_sortFinished(const QList<FileProperty> &li Q_Q(QQuickFolderListModel); QModelIndex parent; - q->beginRemoveRows(parent, 0, data.size()-1); - data.clear(); - q->endRemoveRows(); + if (data.size() > 0) { + q->beginRemoveRows(parent, 0, data.size()-1); + data.clear(); + q->endRemoveRows(); + } q->beginInsertRows(parent, 0, list.size()-1); data = list; diff --git a/tests/auto/qml/qquickfolderlistmodel/data/sortReversed.qml b/tests/auto/qml/qquickfolderlistmodel/data/sortReversed.qml new file mode 100644 index 0000000000..37e9d4cdc1 --- /dev/null +++ b/tests/auto/qml/qquickfolderlistmodel/data/sortReversed.qml @@ -0,0 +1,7 @@ +import Qt.labs.folderlistmodel 1.0 + +FolderListModel { + showDotAndDotDot: false + sortReversed: true +} + diff --git a/tests/auto/qml/qquickfolderlistmodel/tst_qquickfolderlistmodel.cpp b/tests/auto/qml/qquickfolderlistmodel/tst_qquickfolderlistmodel.cpp index 7045263130..53df72d75f 100644 --- a/tests/auto/qml/qquickfolderlistmodel/tst_qquickfolderlistmodel.cpp +++ b/tests/auto/qml/qquickfolderlistmodel/tst_qquickfolderlistmodel.cpp @@ -81,6 +81,7 @@ private slots: #endif void showDotAndDotDot(); void showDotAndDotDot_data(); + void sortReversed(); private: void checkNoErrors(const QQmlComponent& component); @@ -115,7 +116,6 @@ void tst_qquickfolderlistmodel::basicProperties() QAbstractListModel *flm = qobject_cast<QAbstractListModel*>(component.create()); QVERIFY(flm != 0); - QCOMPARE(flm->property("nameFilters").toStringList(), QStringList() << "*.qml"); // from basic.qml QCOMPARE(flm->property("folder").toUrl(), QUrl::fromLocalFile(QDir::currentPath())); @@ -126,7 +126,7 @@ void tst_qquickfolderlistmodel::basicProperties() QSignalSpy folderChangedSpy(flm, SIGNAL(folderChanged())); flm->setProperty("folder", dataDirectoryUrl()); QVERIFY(folderChangedSpy.wait()); - QCOMPARE(flm->property("count").toInt(), 5); + QCOMPARE(flm->property("count").toInt(), 6); QCOMPARE(flm->property("folder").toUrl(), dataDirectoryUrl()); QCOMPARE(flm->property("parentFolder").toUrl(), QUrl::fromLocalFile(QDir(directory()).canonicalPath())); QCOMPARE(flm->property("sortField").toInt(), int(Name)); @@ -152,7 +152,7 @@ void tst_qquickfolderlistmodel::showFiles() QVERIFY(flm != 0); flm->setProperty("folder", dataDirectoryUrl()); - QTRY_COMPARE(flm->property("count").toInt(), 5); // wait for refresh + QTRY_COMPARE(flm->property("count").toInt(), 6); // wait for refresh QCOMPARE(flm->property("showFiles").toBool(), true); flm->setProperty("showFiles", false); @@ -200,7 +200,7 @@ void tst_qquickfolderlistmodel::refresh() QVERIFY(flm != 0); flm->setProperty("folder", dataDirectoryUrl()); - QTRY_COMPARE(flm->property("count").toInt(),5); // wait for refresh + QTRY_COMPARE(flm->property("count").toInt(),6); // wait for refresh int count = flm->rowCount(); @@ -304,7 +304,7 @@ void tst_qquickfolderlistmodel::showDotAndDotDot() flm->setProperty("rootFolder", rootFolder); flm->setProperty("showDotAndDotDot", showDotAndDotDot); - int count = 5; + int count = 6; if (showDot) count++; if (showDotDot) count++; QTRY_COMPARE(flm->property("count").toInt(), count); // wait for refresh @@ -326,7 +326,19 @@ void tst_qquickfolderlistmodel::showDotAndDotDot_data() QTest::newRow("false") << dataDirectoryUrl() << QUrl() << false << false << false; QTest::newRow("true") << dataDirectoryUrl() << QUrl() << true << true << true; QTest::newRow("true but root") << dataDirectoryUrl() << dataDirectoryUrl() << true << true << false; +} +void tst_qquickfolderlistmodel::sortReversed() +{ + QQmlComponent component(&engine, testFileUrl("sortReversed.qml")); + checkNoErrors(component); + QAbstractListModel *flm = qobject_cast<QAbstractListModel*>(component.create()); + QVERIFY(flm != 0); + flm->setProperty("folder", dataDirectoryUrl()); + + int count = 6; + QTRY_COMPARE(flm->property("count").toInt(), count); // wait for refresh + QCOMPARE(flm->data(flm->index(0),FileNameRole).toString(), QLatin1String("sortReversed.qml")); } QTEST_MAIN(tst_qquickfolderlistmodel) |