From 4d8cdc7d69594602246807097b92f72b42f4f6e9 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Thu, 11 Oct 2018 14:47:54 +0200 Subject: Add sortCaseSensitive property so the sorting can ignore the case Change-Id: Id308272cc59eca8c95f1386db8cd64f266124579 Fixes: QTBUG-48757 Fixes: QTBUG-70212 Reviewed-by: Shawn Rutledge --- .../data/sortdir/Uppercase.txt | 0 .../data/sortdir/lowercase.txt | 0 .../tst_qquickfolderlistmodel.cpp | 45 ++++++++++++++++++---- 3 files changed, 38 insertions(+), 7 deletions(-) create mode 100644 tests/auto/qml/qquickfolderlistmodel/data/sortdir/Uppercase.txt create mode 100644 tests/auto/qml/qquickfolderlistmodel/data/sortdir/lowercase.txt (limited to 'tests') diff --git a/tests/auto/qml/qquickfolderlistmodel/data/sortdir/Uppercase.txt b/tests/auto/qml/qquickfolderlistmodel/data/sortdir/Uppercase.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/auto/qml/qquickfolderlistmodel/data/sortdir/lowercase.txt b/tests/auto/qml/qquickfolderlistmodel/data/sortdir/lowercase.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/auto/qml/qquickfolderlistmodel/tst_qquickfolderlistmodel.cpp b/tests/auto/qml/qquickfolderlistmodel/tst_qquickfolderlistmodel.cpp index 77fda3b555..4b2ae45bae 100644 --- a/tests/auto/qml/qquickfolderlistmodel/tst_qquickfolderlistmodel.cpp +++ b/tests/auto/qml/qquickfolderlistmodel/tst_qquickfolderlistmodel.cpp @@ -73,7 +73,8 @@ private slots: void showDotAndDotDot_data(); void sortReversed(); void introspectQrc(); - + void sortCaseSensitive_data(); + void sortCaseSensitive(); private: void checkNoErrors(const QQmlComponent& component); QQmlEngine engine; @@ -126,7 +127,7 @@ void tst_qquickfolderlistmodel::basicProperties() QSignalSpy folderChangedSpy(flm, SIGNAL(folderChanged())); flm->setProperty("folder", dataDirectoryUrl()); QVERIFY(folderChangedSpy.wait()); - QCOMPARE(flm->property("count").toInt(), 8); + QCOMPARE(flm->property("count").toInt(), 9); QCOMPARE(flm->property("folder").toUrl(), dataDirectoryUrl()); QCOMPARE(flm->property("parentFolder").toUrl(), QUrl::fromLocalFile(QDir(directory()).canonicalPath())); QCOMPARE(flm->property("sortField").toInt(), int(Name)); @@ -166,12 +167,12 @@ void tst_qquickfolderlistmodel::showFiles() QVERIFY(flm != nullptr); flm->setProperty("folder", dataDirectoryUrl()); - QTRY_COMPARE(flm->property("count").toInt(), 8); // wait for refresh + QTRY_COMPARE(flm->property("count").toInt(), 9); // wait for refresh QCOMPARE(flm->property("showFiles").toBool(), true); flm->setProperty("showFiles", false); QCOMPARE(flm->property("showFiles").toBool(), false); - QTRY_COMPARE(flm->property("count").toInt(), 2); // wait for refresh + QTRY_COMPARE(flm->property("count").toInt(), 3); // wait for refresh } void tst_qquickfolderlistmodel::resetFiltering() @@ -238,7 +239,7 @@ void tst_qquickfolderlistmodel::refresh() QVERIFY(flm != nullptr); flm->setProperty("folder", dataDirectoryUrl()); - QTRY_COMPARE(flm->property("count").toInt(),8); // wait for refresh + QTRY_COMPARE(flm->property("count").toInt(), 9); // wait for refresh int count = flm->rowCount(); @@ -342,7 +343,7 @@ void tst_qquickfolderlistmodel::showDotAndDotDot() flm->setProperty("rootFolder", rootFolder); flm->setProperty("showDotAndDotDot", showDotAndDotDot); - int count = 9; + int count = 10; if (showDot) count++; if (showDotDot) count++; QTRY_COMPARE(flm->property("count").toInt(), count); // wait for refresh @@ -373,7 +374,7 @@ void tst_qquickfolderlistmodel::sortReversed() QAbstractListModel *flm = qobject_cast(component.create()); QVERIFY(flm != nullptr); flm->setProperty("folder", dataDirectoryUrl()); - QTRY_COMPARE(flm->property("count").toInt(), 9); // wait for refresh + QTRY_COMPARE(flm->property("count").toInt(), 10); // wait for refresh QCOMPARE(flm->data(flm->index(0),FileNameRole).toString(), QLatin1String("txtdir")); } @@ -387,6 +388,36 @@ void tst_qquickfolderlistmodel::introspectQrc() QCOMPARE(flm->data(flm->index(0),FileNameRole).toString(), QLatin1String("hello.txt")); } +void tst_qquickfolderlistmodel::sortCaseSensitive_data() +{ + QTest::addColumn("sortCaseSensitive"); + QTest::addColumn("expectedOrder"); + + const QString upperFile = QLatin1String("Uppercase.txt"); + const QString lowerFile = QLatin1String("lowercase.txt"); + + QTest::newRow("caseSensitive") << true << (QStringList() << upperFile << lowerFile); + QTest::newRow("caseInsensitive") << false << (QStringList() << lowerFile << upperFile); +} + +void tst_qquickfolderlistmodel::sortCaseSensitive() +{ + QFETCH(bool, sortCaseSensitive); + QFETCH(QStringList, expectedOrder); + QQmlComponent component(&engine); + component.setData("import Qt.labs.folderlistmodel 1.0\n" + "FolderListModel { }", QUrl()); + checkNoErrors(component); + + QAbstractListModel *flm = qobject_cast(component.create()); + QVERIFY(flm != 0); + flm->setProperty("folder", QUrl::fromLocalFile(dataDirectoryUrl().path() + QLatin1String("/sortdir"))); + flm->setProperty("sortCaseSensitive", sortCaseSensitive); + QTRY_COMPARE(flm->property("count").toInt(), 2); // wait for refresh + for (int i = 0; i < 2; ++i) + QTRY_COMPARE(flm->data(flm->index(i),FileNameRole).toString(), expectedOrder.at(i)); +} + QTEST_MAIN(tst_qquickfolderlistmodel) #include "tst_qquickfolderlistmodel.moc" -- cgit v1.2.3