diff options
5 files changed, 63 insertions, 2 deletions
diff --git a/src/imports/folderlistmodel/fileinfothread.cpp b/src/imports/folderlistmodel/fileinfothread.cpp index ad09f54381..4aa43b2d3f 100644 --- a/src/imports/folderlistmodel/fileinfothread.cpp +++ b/src/imports/folderlistmodel/fileinfothread.cpp @@ -55,6 +55,7 @@ FileInfoThread::FileInfoThread(QObject *parent) needUpdate(true), folderUpdate(false), sortUpdate(false), + showFiles(true), showDirs(true), showDirsFirst(false), showDotAndDotDot(false), @@ -142,6 +143,14 @@ void FileInfoThread::setNameFilters(const QStringList & filters) condition.wakeAll(); } +void FileInfoThread::setShowFiles(bool show) +{ + QMutexLocker locker(&mutex); + showFiles = show; + folderUpdate = true; + condition.wakeAll(); +} + void FileInfoThread::setShowDirs(bool showFolders) { QMutexLocker locker(&mutex); @@ -213,7 +222,9 @@ void FileInfoThread::run() void FileInfoThread::getFileInfos(const QString &path) { QDir::Filters filter; - filter = QDir::Files | QDir::CaseSensitive; + filter = QDir::CaseSensitive; + if (showFiles) + filter = filter | QDir::Files; if (showDirs) filter = filter | QDir::AllDirs | QDir::Drives; if (!showDotAndDotDot) diff --git a/src/imports/folderlistmodel/fileinfothread_p.h b/src/imports/folderlistmodel/fileinfothread_p.h index cf6572a279..d50361de3a 100644 --- a/src/imports/folderlistmodel/fileinfothread_p.h +++ b/src/imports/folderlistmodel/fileinfothread_p.h @@ -70,6 +70,7 @@ public: void setRootPath(const QString &path); void setSortFlags(QDir::SortFlags flags); void setNameFilters(const QStringList & nameFilters); + void setShowFiles(bool show); void setShowDirs(bool showFolders); void setShowDirsFirst(bool show); void setShowDotAndDotDot(bool on); @@ -102,6 +103,7 @@ private: bool needUpdate; bool folderUpdate; bool sortUpdate; + bool showFiles; bool showDirs; bool showDirsFirst; bool showDotAndDotDot; diff --git a/src/imports/folderlistmodel/qquickfolderlistmodel.cpp b/src/imports/folderlistmodel/qquickfolderlistmodel.cpp index 85b59e9c73..4dbbcf359d 100644 --- a/src/imports/folderlistmodel/qquickfolderlistmodel.cpp +++ b/src/imports/folderlistmodel/qquickfolderlistmodel.cpp @@ -55,7 +55,8 @@ class QQuickFolderListModelPrivate public: QQuickFolderListModelPrivate(QQuickFolderListModel *q) : q_ptr(q), - sortField(QQuickFolderListModel::Name), sortReversed(false), showDirs(true), showDirsFirst(false), showDotAndDotDot(false), showOnlyReadable(false) + sortField(QQuickFolderListModel::Name), sortReversed(false), showFiles(true), + showDirs(true), showDirsFirst(false), showDotAndDotDot(false), showOnlyReadable(false) { nameFilters << QLatin1String("*"); } @@ -70,6 +71,7 @@ public: QQuickFolderListModel::SortField sortField; QStringList nameFilters; bool sortReversed; + bool showFiles; bool showDirs; bool showDirsFirst; bool showDotAndDotDot; @@ -619,6 +621,30 @@ bool QQuickFolderListModel::isFolder(int index) const } /*! + \qmlproperty bool FolderListModel::showFiles + + If true, files are included in the model; otherwise only directories + are included. + + By default, this property is true. + + \sa showDirs +*/ +bool QQuickFolderListModel::showFiles() const +{ + Q_D(const QQuickFolderListModel); + return d->showFiles; +} + +void QQuickFolderListModel::setShowFiles(bool on) +{ + Q_D(QQuickFolderListModel); + + d->fileInfoThread.setShowFiles(on); + d->showFiles = on; +} + +/*! \qmlproperty bool FolderListModel::showDirs If true, directories are included in the model; otherwise only files diff --git a/src/imports/folderlistmodel/qquickfolderlistmodel.h b/src/imports/folderlistmodel/qquickfolderlistmodel.h index 03cb24d368..43af77adf5 100644 --- a/src/imports/folderlistmodel/qquickfolderlistmodel.h +++ b/src/imports/folderlistmodel/qquickfolderlistmodel.h @@ -69,6 +69,7 @@ class QQuickFolderListModel : public QAbstractListModel, public QQmlParserStatus Q_PROPERTY(QStringList nameFilters READ nameFilters WRITE setNameFilters) Q_PROPERTY(SortField sortField READ sortField WRITE setSortField) Q_PROPERTY(bool sortReversed READ sortReversed WRITE setSortReversed) + Q_PROPERTY(bool showFiles READ showFiles WRITE setShowFiles) Q_PROPERTY(bool showDirs READ showDirs WRITE setShowDirs) Q_PROPERTY(bool showDirsFirst READ showDirsFirst WRITE setShowDirsFirst) Q_PROPERTY(bool showDotAndDotDot READ showDotAndDotDot WRITE setShowDotAndDotDot) @@ -121,6 +122,8 @@ public: bool sortReversed() const; void setSortReversed(bool rev); + bool showFiles() const; + void setShowFiles(bool showFiles); bool showDirs() const; void setShowDirs(bool showDirs); bool showDirsFirst() const; diff --git a/tests/auto/qml/qquickfolderlistmodel/tst_qquickfolderlistmodel.cpp b/tests/auto/qml/qquickfolderlistmodel/tst_qquickfolderlistmodel.cpp index b845faca7d..9308bc6f40 100644 --- a/tests/auto/qml/qquickfolderlistmodel/tst_qquickfolderlistmodel.cpp +++ b/tests/auto/qml/qquickfolderlistmodel/tst_qquickfolderlistmodel.cpp @@ -71,6 +71,7 @@ public slots: private slots: void basicProperties(); + void showFiles(); void resetFiltering(); void refresh(); #if defined (Q_OS_WIN) && !defined (Q_OS_WINCE) @@ -121,6 +122,7 @@ void tst_qquickfolderlistmodel::basicProperties() QCOMPARE(flm->property("sortField").toInt(), int(Name)); QCOMPARE(flm->property("nameFilters").toStringList(), QStringList() << "*.qml"); QCOMPARE(flm->property("sortReversed").toBool(), false); + QCOMPARE(flm->property("showFiles").toBool(), true); QCOMPARE(flm->property("showDirs").toBool(), true); QCOMPARE(flm->property("showDotAndDotDot").toBool(), false); QCOMPARE(flm->property("showOnlyReadable").toBool(), false); @@ -131,6 +133,23 @@ void tst_qquickfolderlistmodel::basicProperties() QCOMPARE(flm->property("folder").toUrl(), QUrl::fromLocalFile("")); } +void tst_qquickfolderlistmodel::showFiles() +{ + QQmlComponent component(&engine, testFileUrl("basic.qml")); + checkNoErrors(component); + + QAbstractListModel *flm = qobject_cast<QAbstractListModel*>(component.create()); + QVERIFY(flm != 0); + + flm->setProperty("folder", dataDirectoryUrl()); + QTRY_COMPARE(flm->property("count").toInt(), 5); // 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(), 1); // wait for refresh +} + void tst_qquickfolderlistmodel::resetFiltering() { // see QTBUG-17837 |