diff options
Diffstat (limited to 'src/imports/folderlistmodel')
-rw-r--r-- | src/imports/folderlistmodel/fileinfothread.cpp | 5 | ||||
-rw-r--r-- | src/imports/folderlistmodel/fileinfothread_p.h | 2 | ||||
-rw-r--r-- | src/imports/folderlistmodel/plugin.cpp | 6 | ||||
-rw-r--r-- | src/imports/folderlistmodel/plugins.qmltypes | 15 | ||||
-rw-r--r-- | src/imports/folderlistmodel/qquickfolderlistmodel.cpp | 61 | ||||
-rw-r--r-- | src/imports/folderlistmodel/qquickfolderlistmodel.h | 7 |
6 files changed, 92 insertions, 4 deletions
diff --git a/src/imports/folderlistmodel/fileinfothread.cpp b/src/imports/folderlistmodel/fileinfothread.cpp index d3e256bb7e..4ef8d02810 100644 --- a/src/imports/folderlistmodel/fileinfothread.cpp +++ b/src/imports/folderlistmodel/fileinfothread.cpp @@ -222,8 +222,10 @@ void FileInfoThread::run() if (abort) { return; } - if (currentPath.isEmpty() || !needUpdate) + if (currentPath.isEmpty() || !needUpdate) { + emit statusChanged(currentPath.isEmpty() ? QQuickFolderListModel::Null : QQuickFolderListModel::Ready); condition.wait(&mutex); + } if (abort) { return; @@ -231,6 +233,7 @@ void FileInfoThread::run() if (!currentPath.isEmpty()) { updateFiles = true; + emit statusChanged(QQuickFolderListModel::Loading); } if (updateFiles) getFileInfos(currentPath); diff --git a/src/imports/folderlistmodel/fileinfothread_p.h b/src/imports/folderlistmodel/fileinfothread_p.h index b505ece750..67d2a1f5f7 100644 --- a/src/imports/folderlistmodel/fileinfothread_p.h +++ b/src/imports/folderlistmodel/fileinfothread_p.h @@ -59,6 +59,7 @@ #include <QDir> #include "fileproperty_p.h" +#include "qquickfolderlistmodel.h" class FileInfoThread : public QThread { @@ -68,6 +69,7 @@ Q_SIGNALS: void directoryChanged(const QString &directory, const QList<FileProperty> &list) const; void directoryUpdated(const QString &directory, const QList<FileProperty> &list, int fromIndex, int toIndex) const; void sortFinished(const QList<FileProperty> &list) const; + void statusChanged(QQuickFolderListModel::Status status) const; public: FileInfoThread(QObject *parent = 0); diff --git a/src/imports/folderlistmodel/plugin.cpp b/src/imports/folderlistmodel/plugin.cpp index 2b58a5677a..e90c8724e0 100644 --- a/src/imports/folderlistmodel/plugin.cpp +++ b/src/imports/folderlistmodel/plugin.cpp @@ -66,6 +66,12 @@ public: qmlRegisterType<QQuickFolderListModel>(uri,2,0,"FolderListModel"); qmlRegisterType<QQuickFolderListModel,1>(uri,2,1,"FolderListModel"); qmlRegisterType<QQuickFolderListModel,2>(uri,2,2,"FolderListModel"); + + // Auto-increment the import to stay in sync with ALL future QtQuick minor versions from 5.11 onward + qmlRegisterModule(uri, 2, QT_VERSION_MINOR); + + // revision in Qt 5.11: added status property + qmlRegisterType<QQuickFolderListModel,11>(uri, 2, 11, "FolderListModel"); } }; //![class decl] diff --git a/src/imports/folderlistmodel/plugins.qmltypes b/src/imports/folderlistmodel/plugins.qmltypes index e77b633932..a336b55022 100644 --- a/src/imports/folderlistmodel/plugins.qmltypes +++ b/src/imports/folderlistmodel/plugins.qmltypes @@ -4,7 +4,7 @@ import QtQuick.tooling 1.2 // It is used for QML tooling purposes only. // // This file was auto-generated by: -// 'qmlplugindump -nonrelocatable Qt.labs.folderlistmodel 2.2' +// 'qmlplugindump -nonrelocatable Qt.labs.folderlistmodel 2.11' Module { dependencies: ["QtQuick 2.8"] @@ -15,9 +15,10 @@ Module { "Qt.labs.folderlistmodel/FolderListModel 1.0", "Qt.labs.folderlistmodel/FolderListModel 2.0", "Qt.labs.folderlistmodel/FolderListModel 2.1", + "Qt.labs.folderlistmodel/FolderListModel 2.11", "Qt.labs.folderlistmodel/FolderListModel 2.2" ] - exportMetaObjectRevisions: [0, 0, 1, 2] + exportMetaObjectRevisions: [0, 0, 1, 11, 2] Enum { name: "SortField" values: { @@ -28,6 +29,14 @@ Module { "Type": 4 } } + Enum { + name: "Status" + values: { + "Null": 0, + "Ready": 1, + "Loading": 2 + } + } Property { name: "folder"; type: "QUrl" } Property { name: "rootFolder"; type: "QUrl" } Property { name: "parentFolder"; type: "QUrl"; isReadonly: true } @@ -42,8 +51,10 @@ Module { Property { name: "showOnlyReadable"; type: "bool" } Property { name: "caseSensitive"; revision: 2; type: "bool" } Property { name: "count"; type: "int"; isReadonly: true } + Property { name: "status"; revision: 11; type: "Status"; isReadonly: true } Signal { name: "rowCountChanged" } Signal { name: "countChanged"; revision: 1 } + Signal { name: "statusChanged"; revision: 11 } Method { name: "isFolder" type: "bool" diff --git a/src/imports/folderlistmodel/qquickfolderlistmodel.cpp b/src/imports/folderlistmodel/qquickfolderlistmodel.cpp index fdcce9c685..b2abf97898 100644 --- a/src/imports/folderlistmodel/qquickfolderlistmodel.cpp +++ b/src/imports/folderlistmodel/qquickfolderlistmodel.cpp @@ -55,7 +55,7 @@ public: : q_ptr(q), sortField(QQuickFolderListModel::Name), sortReversed(false), showFiles(true), showDirs(true), showDirsFirst(false), showDotAndDotDot(false), showOnlyReadable(false), - showHidden(false), caseSensitive(true) + showHidden(false), caseSensitive(true), status(QQuickFolderListModel::Null) { nameFilters << QLatin1String("*"); } @@ -77,6 +77,7 @@ public: bool showOnlyReadable; bool showHidden; bool caseSensitive; + QQuickFolderListModel::Status status; ~QQuickFolderListModelPrivate() {} void init(); @@ -86,6 +87,7 @@ public: void _q_directoryChanged(const QString &directory, const QList<FileProperty> &list); void _q_directoryUpdated(const QString &directory, const QList<FileProperty> &list, int fromIndex, int toIndex); void _q_sortFinished(const QList<FileProperty> &list); + void _q_statusChanged(QQuickFolderListModel::Status s); static QString resolvePath(const QUrl &path); }; @@ -95,12 +97,15 @@ void QQuickFolderListModelPrivate::init() { Q_Q(QQuickFolderListModel); qRegisterMetaType<QList<FileProperty> >("QList<FileProperty>"); + qRegisterMetaType<QQuickFolderListModel::Status>("QQuickFolderListModel::Status"); q->connect(&fileInfoThread, SIGNAL(directoryChanged(QString,QList<FileProperty>)), q, SLOT(_q_directoryChanged(QString,QList<FileProperty>))); q->connect(&fileInfoThread, SIGNAL(directoryUpdated(QString,QList<FileProperty>,int,int)), q, SLOT(_q_directoryUpdated(QString,QList<FileProperty>,int,int))); q->connect(&fileInfoThread, SIGNAL(sortFinished(QList<FileProperty>)), q, SLOT(_q_sortFinished(QList<FileProperty>))); + q->connect(&fileInfoThread, SIGNAL(statusChanged(QQuickFolderListModel::Status)), + q, SLOT(_q_statusChanged(QQuickFolderListModel::Status))); q->connect(q, SIGNAL(rowCountChanged()), q, SIGNAL(countChanged())); } @@ -198,6 +203,16 @@ void QQuickFolderListModelPrivate::_q_sortFinished(const QList<FileProperty> &li q->endInsertRows(); } +void QQuickFolderListModelPrivate::_q_statusChanged(QQuickFolderListModel::Status s) +{ + Q_Q(QQuickFolderListModel); + + if (status != s) { + status = s; + emit q->statusChanged(); + } +} + QString QQuickFolderListModelPrivate::resolvePath(const QUrl &path) { QString localPath = QQmlFile::urlToLocalFileOrQrc(path); @@ -437,6 +452,10 @@ void QQuickFolderListModel::setFolder(const QUrl &folder) d->data.clear(); endResetModel(); emit rowCountChanged(); + if (d->status != QQuickFolderListModel::Null) { + d->status = QQuickFolderListModel::Null; + emit statusChanged(); + } return; } @@ -795,6 +814,46 @@ void QQuickFolderListModel::setCaseSensitive(bool on) } /*! + \qmlproperty enumeration FolderListModel::status + \since 5.11 + + This property holds the status of folder reading. It can be one of: + \list + \li FolderListModel.Null - no \a folder has been set + \li FolderListModel.Ready - the folder has been loaded + \li FolderListModel.Loading - the folder is currently being loaded + \endlist + + Use this status to provide an update or respond to the status change in some way. + For example, you could: + + \list + \li Trigger a state change: + \qml + State { name: 'loaded'; when: folderModel.status == FolderListModel.Ready } + \endqml + + \li Implement an \c onStatusChanged signal handler: + \qml + FolderListModel { + id: folderModel + onStatusChanged: if (folderModel.status == FolderListModel.Ready) console.log('Loaded') + } + \endqml + + \li Bind to the status value: + \qml + Text { text: folderModel.status == FolderListModel.Ready ? 'Loaded' : 'Not loaded' } + \endqml + \endlist +*/ +QQuickFolderListModel::Status QQuickFolderListModel::status() const +{ + Q_D(const QQuickFolderListModel); + return d->status; +} + +/*! \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 dee73dff3e..a449f0dd0f 100644 --- a/src/imports/folderlistmodel/qquickfolderlistmodel.h +++ b/src/imports/folderlistmodel/qquickfolderlistmodel.h @@ -75,6 +75,7 @@ class QQuickFolderListModel : public QAbstractListModel, public QQmlParserStatus Q_PROPERTY(bool showOnlyReadable READ showOnlyReadable WRITE setShowOnlyReadable) 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) //![class props] //![abslistmodel] @@ -137,6 +138,10 @@ public: void setShowOnlyReadable(bool on); bool caseSensitive() const; void setCaseSensitive(bool on); + + enum Status { Null, Ready, Loading }; + Q_ENUM(Status) + Status status() const; //![prop funcs] Q_INVOKABLE bool isFolder(int index) const; @@ -155,6 +160,7 @@ Q_SIGNALS: void folderChanged(); void rowCountChanged() const; Q_REVISION(1) void countChanged() const; + Q_REVISION(11) void statusChanged(); //![notifier] //![class end] @@ -168,6 +174,7 @@ private: Q_PRIVATE_SLOT(d_func(), void _q_directoryChanged(const QString &directory, const QList<FileProperty> &list)) Q_PRIVATE_SLOT(d_func(), void _q_directoryUpdated(const QString &directory, const QList<FileProperty> &list, int fromIndex, int toIndex)) Q_PRIVATE_SLOT(d_func(), void _q_sortFinished(const QList<FileProperty> &list)) + Q_PRIVATE_SLOT(d_func(), void _q_statusChanged(QQuickFolderListModel::Status s)) }; //![class end] |