aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/imports/folderlistmodel/fileinfothread.cpp1
-rw-r--r--src/imports/folderlistmodel/plugin.cpp3
-rw-r--r--src/imports/folderlistmodel/qquickfolderlistmodel.cpp30
-rw-r--r--src/imports/folderlistmodel/qquickfolderlistmodel.h3
-rw-r--r--tests/auto/qml/qquickfolderlistmodel/data/sortdir/Uppercase.txt0
-rw-r--r--tests/auto/qml/qquickfolderlistmodel/data/sortdir/lowercase.txt0
-rw-r--r--tests/auto/qml/qquickfolderlistmodel/tst_qquickfolderlistmodel.cpp45
7 files changed, 74 insertions, 8 deletions
diff --git a/src/imports/folderlistmodel/fileinfothread.cpp b/src/imports/folderlistmodel/fileinfothread.cpp
index 5b44ed012f..a006f659c9 100644
--- a/src/imports/folderlistmodel/fileinfothread.cpp
+++ b/src/imports/folderlistmodel/fileinfothread.cpp
@@ -135,6 +135,7 @@ void FileInfoThread::setSortFlags(QDir::SortFlags flags)
QMutexLocker locker(&mutex);
sortFlags = flags;
sortUpdate = true;
+ needUpdate = true;
condition.wakeAll();
}
diff --git a/src/imports/folderlistmodel/plugin.cpp b/src/imports/folderlistmodel/plugin.cpp
index 7089fed4ad..31cd793737 100644
--- a/src/imports/folderlistmodel/plugin.cpp
+++ b/src/imports/folderlistmodel/plugin.cpp
@@ -65,6 +65,9 @@ public:
// revision in Qt 5.11: added status property
qmlRegisterType<QQuickFolderListModel,11>(uri, 2, 11, "FolderListModel");
+
+ // revision in Qt 5.12: added sortCaseSensitive property
+ qmlRegisterType<QQuickFolderListModel,12>(uri, 2, 12, "FolderListModel");
}
};
//![class decl]
diff --git a/src/imports/folderlistmodel/qquickfolderlistmodel.cpp b/src/imports/folderlistmodel/qquickfolderlistmodel.cpp
index 66d9e7ae46..3c00a76cc5 100644
--- a/src/imports/folderlistmodel/qquickfolderlistmodel.cpp
+++ b/src/imports/folderlistmodel/qquickfolderlistmodel.cpp
@@ -55,7 +55,9 @@ public:
: q_ptr(q),
sortField(QQuickFolderListModel::Name), sortReversed(false), showFiles(true),
showDirs(true), showDirsFirst(false), showDotAndDotDot(false), showOnlyReadable(false),
- showHidden(false), caseSensitive(true), status(QQuickFolderListModel::Null)
+ showHidden(false), caseSensitive(true), sortCaseSensitive(true),
+ status(QQuickFolderListModel::Null)
+
{
nameFilters << QLatin1String("*");
}
@@ -77,6 +79,7 @@ public:
bool showOnlyReadable;
bool showHidden;
bool caseSensitive;
+ bool sortCaseSensitive;
QQuickFolderListModel::Status status;
~QQuickFolderListModelPrivate() {}
@@ -140,6 +143,8 @@ void QQuickFolderListModelPrivate::updateSorting()
if (sortReversed)
flags |= QDir::Reversed;
+ if (!sortCaseSensitive)
+ flags |= QDir::IgnoreCase;
fileInfoThread.setSortFlags(flags);
}
@@ -856,6 +861,29 @@ QQuickFolderListModel::Status QQuickFolderListModel::status() const
}
/*!
+ \qmlproperty bool FolderListModel::sortCaseSensitive
+ \since 5.12
+
+ If set to true, the sort is case sensitive. This property is true by default.
+*/
+
+bool QQuickFolderListModel::sortCaseSensitive() const
+{
+ Q_D(const QQuickFolderListModel);
+ return d->sortCaseSensitive;
+}
+
+void QQuickFolderListModel::setSortCaseSensitive(bool on)
+{
+ Q_D(QQuickFolderListModel);
+
+ if (on != d->sortCaseSensitive) {
+ d->sortCaseSensitive = on;
+ d->updateSorting();
+ }
+}
+
+/*!
\qmlmethod var FolderListModel::get(int index, string property)
Get the folder property for the given index. The following properties
diff --git a/src/imports/folderlistmodel/qquickfolderlistmodel.h b/src/imports/folderlistmodel/qquickfolderlistmodel.h
index a449f0dd0f..cc03ff441b 100644
--- a/src/imports/folderlistmodel/qquickfolderlistmodel.h
+++ b/src/imports/folderlistmodel/qquickfolderlistmodel.h
@@ -76,6 +76,7 @@ class QQuickFolderListModel : public QAbstractListModel, public QQmlParserStatus
Q_PROPERTY(bool caseSensitive READ caseSensitive WRITE setCaseSensitive REVISION 2)
Q_PROPERTY(int count READ count NOTIFY countChanged)
Q_PROPERTY(Status status READ status NOTIFY statusChanged REVISION 11)
+ Q_PROPERTY(bool sortCaseSensitive READ sortCaseSensitive WRITE setSortCaseSensitive REVISION 12)
//![class props]
//![abslistmodel]
@@ -142,6 +143,8 @@ public:
enum Status { Null, Ready, Loading };
Q_ENUM(Status)
Status status() const;
+ bool sortCaseSensitive() const;
+ void setSortCaseSensitive(bool on);
//![prop funcs]
Q_INVOKABLE bool isFolder(int index) const;
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
--- /dev/null
+++ b/tests/auto/qml/qquickfolderlistmodel/data/sortdir/Uppercase.txt
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
--- /dev/null
+++ b/tests/auto/qml/qquickfolderlistmodel/data/sortdir/lowercase.txt
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<QAbstractListModel*>(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<bool>("sortCaseSensitive");
+ QTest::addColumn<QStringList>("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<QAbstractListModel*>(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"