From 95aa526987a2ef536c07d2607e8fdfc21c3e9096 Mon Sep 17 00:00:00 2001 From: Tasuku Suzuki Date: Mon, 25 Feb 2013 23:45:22 +0900 Subject: [PATCH] fix Folderlistmodel "showDotAndDotDot" didn't show "." Task-number: QTBUG-29858 Change-Id: Ia736776e2587601a80d0aef22bb5cfce74040d39 Reviewed-by: Alan Alpert --- src/imports/folderlistmodel/fileinfothread.cpp | 12 +++--- src/imports/folderlistmodel/fileinfothread_p.h | 4 +- .../folderlistmodel/qquickfolderlistmodel.cpp | 10 ++--- .../data/showDotAndDotDot.qml | 5 +++ .../tst_qquickfolderlistmodel.cpp | 49 +++++++++++++++++++++- 5 files changed, 66 insertions(+), 14 deletions(-) create mode 100644 tests/auto/qml/qquickfolderlistmodel/data/showDotAndDotDot.qml diff --git a/src/imports/folderlistmodel/fileinfothread.cpp b/src/imports/folderlistmodel/fileinfothread.cpp index 64a4b02..0f984be 100644 --- a/src/imports/folderlistmodel/fileinfothread.cpp +++ b/src/imports/folderlistmodel/fileinfothread.cpp @@ -57,7 +57,7 @@ FileInfoThread::FileInfoThread(QObject *parent) sortUpdate(false), showDirs(true), showDirsFirst(false), - showDotDot(false), + showDotAndDotDot(false), showOnlyReadable(false) { #ifndef QT_NO_FILESYSTEMWATCHER @@ -158,10 +158,10 @@ void FileInfoThread::setShowDirsFirst(bool show) condition.wakeAll(); } -void FileInfoThread::setShowDotDot(bool on) +void FileInfoThread::setShowDotAndDotDot(bool on) { QMutexLocker locker(&mutex); - showDotDot = on; + showDotAndDotDot = on; folderUpdate = true; condition.wakeAll(); } @@ -212,10 +212,12 @@ void FileInfoThread::run() void FileInfoThread::getFileInfos(const QString &path) { QDir::Filters filter; - filter = QDir::Files | QDir::NoDot | QDir::CaseSensitive; + filter = QDir::Files | QDir::CaseSensitive; if (showDirs) filter = filter | QDir::AllDirs | QDir::Drives; - if ((path == rootPath) || !showDotDot) + if (!showDotAndDotDot) + filter = filter | QDir::NoDot | QDir::NoDotDot; + else if (path == rootPath) filter = filter | QDir::NoDotDot; if (showOnlyReadable) filter = filter | QDir::Readable; diff --git a/src/imports/folderlistmodel/fileinfothread_p.h b/src/imports/folderlistmodel/fileinfothread_p.h index f9340ca..cf6572a 100644 --- a/src/imports/folderlistmodel/fileinfothread_p.h +++ b/src/imports/folderlistmodel/fileinfothread_p.h @@ -72,7 +72,7 @@ public: void setNameFilters(const QStringList & nameFilters); void setShowDirs(bool showFolders); void setShowDirsFirst(bool show); - void setShowDotDot(bool on); + void setShowDotAndDotDot(bool on); void setShowOnlyReadable(bool on); public Q_SLOTS: @@ -104,7 +104,7 @@ private: bool sortUpdate; bool showDirs; bool showDirsFirst; - bool showDotDot; + bool showDotAndDotDot; bool showOnlyReadable; }; diff --git a/src/imports/folderlistmodel/qquickfolderlistmodel.cpp b/src/imports/folderlistmodel/qquickfolderlistmodel.cpp index 7ba2981..85b59e9 100644 --- a/src/imports/folderlistmodel/qquickfolderlistmodel.cpp +++ b/src/imports/folderlistmodel/qquickfolderlistmodel.cpp @@ -55,7 +55,7 @@ class QQuickFolderListModelPrivate public: QQuickFolderListModelPrivate(QQuickFolderListModel *q) : q_ptr(q), - sortField(QQuickFolderListModel::Name), sortReversed(false), showDirs(true), showDirsFirst(false), showDots(false), showOnlyReadable(false) + sortField(QQuickFolderListModel::Name), sortReversed(false), showDirs(true), showDirsFirst(false), showDotAndDotDot(false), showOnlyReadable(false) { nameFilters << QLatin1String("*"); } @@ -72,7 +72,7 @@ public: bool sortReversed; bool showDirs; bool showDirsFirst; - bool showDots; + bool showDotAndDotDot; bool showOnlyReadable; ~QQuickFolderListModelPrivate() {} @@ -681,15 +681,15 @@ void QQuickFolderListModel::setShowDirsFirst(bool on) bool QQuickFolderListModel::showDotAndDotDot() const { Q_D(const QQuickFolderListModel); - return d->showDots; + return d->showDotAndDotDot; } void QQuickFolderListModel::setShowDotAndDotDot(bool on) { Q_D(QQuickFolderListModel); - if (on != d->showDots) { - d->fileInfoThread.setShowDotDot(on); + if (on != d->showDotAndDotDot) { + d->fileInfoThread.setShowDotAndDotDot(on); } } diff --git a/tests/auto/qml/qquickfolderlistmodel/data/showDotAndDotDot.qml b/tests/auto/qml/qquickfolderlistmodel/data/showDotAndDotDot.qml new file mode 100644 index 0000000..b65ace2 --- /dev/null +++ b/tests/auto/qml/qquickfolderlistmodel/data/showDotAndDotDot.qml @@ -0,0 +1,5 @@ +import Qt.labs.folderlistmodel 1.0 + +FolderListModel { + showDotAndDotDot: false +} diff --git a/tests/auto/qml/qquickfolderlistmodel/tst_qquickfolderlistmodel.cpp b/tests/auto/qml/qquickfolderlistmodel/tst_qquickfolderlistmodel.cpp index 9230608..b845fac 100644 --- a/tests/auto/qml/qquickfolderlistmodel/tst_qquickfolderlistmodel.cpp +++ b/tests/auto/qml/qquickfolderlistmodel/tst_qquickfolderlistmodel.cpp @@ -77,6 +77,8 @@ private slots: // WinCE does not have drive concept, so lets execute this test only on desktop Windows. void changeDrive(); #endif + void showDotAndDotDot(); + void showDotAndDotDot_data(); private: void checkNoErrors(const QQmlComponent& component); @@ -113,7 +115,7 @@ void tst_qquickfolderlistmodel::basicProperties() QVERIFY(flm != 0); flm->setProperty("folder", dataDirectoryUrl()); - QTRY_COMPARE(flm->property("count").toInt(),4); // wait for refresh + QTRY_COMPARE(flm->property("count").toInt(),5); // wait for refresh QCOMPARE(flm->property("folder").toUrl(), dataDirectoryUrl()); QCOMPARE(flm->property("parentFolder").toUrl(), QUrl::fromLocalFile(QDir(directory()).canonicalPath())); QCOMPARE(flm->property("sortField").toInt(), int(Name)); @@ -169,7 +171,7 @@ void tst_qquickfolderlistmodel::refresh() QVERIFY(flm != 0); flm->setProperty("folder", dataDirectoryUrl()); - QTRY_COMPARE(flm->property("count").toInt(),4); // wait for refresh + QTRY_COMPARE(flm->property("count").toInt(),5); // wait for refresh int count = flm->rowCount(); @@ -228,6 +230,49 @@ void tst_qquickfolderlistmodel::changeDrive() } #endif +void tst_qquickfolderlistmodel::showDotAndDotDot() +{ + QFETCH(QUrl, folder); + QFETCH(QUrl, rootFolder); + QFETCH(bool, showDotAndDotDot); + QFETCH(bool, showDot); + QFETCH(bool, showDotDot); + + QQmlComponent component(&engine, testFileUrl("showDotAndDotDot.qml")); + checkNoErrors(component); + + QAbstractListModel *flm = qobject_cast(component.create()); + QVERIFY(flm != 0); + + flm->setProperty("folder", folder); + flm->setProperty("rootFolder", rootFolder); + flm->setProperty("showDotAndDotDot", showDotAndDotDot); + + int count = 5; + if (showDot) count++; + if (showDotDot) count++; + QTRY_COMPARE(flm->property("count").toInt(), count); // wait for refresh + + if (showDot) + QCOMPARE(flm->data(flm->index(0),FileNameRole).toString(), QLatin1String(".")); + if (showDotDot) + QCOMPARE(flm->data(flm->index(1),FileNameRole).toString(), QLatin1String("..")); +} + +void tst_qquickfolderlistmodel::showDotAndDotDot_data() +{ + QTest::addColumn("folder"); + QTest::addColumn("rootFolder"); + QTest::addColumn("showDotAndDotDot"); + QTest::addColumn("showDot"); + QTest::addColumn("showDotDot"); + + 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; + +} + QTEST_MAIN(tst_qquickfolderlistmodel) #include "tst_qquickfolderlistmodel.moc" -- 2.7.4