aboutsummaryrefslogtreecommitdiffstats
path: root/src/labs/folderlistmodel/qquickfolderlistmodel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/labs/folderlistmodel/qquickfolderlistmodel.cpp')
-rw-r--r--src/labs/folderlistmodel/qquickfolderlistmodel.cpp138
1 files changed, 61 insertions, 77 deletions
diff --git a/src/labs/folderlistmodel/qquickfolderlistmodel.cpp b/src/labs/folderlistmodel/qquickfolderlistmodel.cpp
index 33206e5fe6..af6fd3b2ef 100644
--- a/src/labs/folderlistmodel/qquickfolderlistmodel.cpp
+++ b/src/labs/folderlistmodel/qquickfolderlistmodel.cpp
@@ -1,51 +1,18 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the examples of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
//![code]
#include "qquickfolderlistmodel_p.h"
#include "fileinfothread_p.h"
#include "fileproperty_p.h"
+#include <QtCore/qloggingcategory.h>
#include <qqmlcontext.h>
#include <qqmlfile.h>
QT_BEGIN_NAMESPACE
+Q_LOGGING_CATEGORY(lcFolderListModel, "qt.labs.folderlistmodel")
+
class QQuickFolderListModelPrivate
{
Q_DECLARE_PUBLIC(QQuickFolderListModel)
@@ -139,11 +106,13 @@ void QQuickFolderListModelPrivate::updateSorting()
void QQuickFolderListModelPrivate::_q_directoryChanged(const QString &directory, const QList<FileProperty> &list)
{
+ qCDebug(lcFolderListModel) << "_q_directoryChanged called with directory" << directory;
Q_Q(QQuickFolderListModel);
Q_UNUSED(directory);
data = list;
q->endResetModel();
+ qCDebug(lcFolderListModel) << "- endResetModel called";
emit q->rowCountChanged();
emit q->folderChanged();
}
@@ -183,17 +152,22 @@ void QQuickFolderListModelPrivate::_q_directoryUpdated(const QString &directory,
void QQuickFolderListModelPrivate::_q_sortFinished(const QList<FileProperty> &list)
{
Q_Q(QQuickFolderListModel);
+ qCDebug(lcFolderListModel) << "_q_sortFinished called with" << list.size() << "files";
QModelIndex parent;
if (data.size() > 0) {
+ qCDebug(lcFolderListModel) << "- removing all existing rows...";
q->beginRemoveRows(parent, 0, data.size()-1);
data.clear();
q->endRemoveRows();
+ qCDebug(lcFolderListModel) << "- ...removed all existing rows";
}
+ qCDebug(lcFolderListModel) << "- inserting sorted rows...";
q->beginInsertRows(parent, 0, list.size()-1);
data = list;
q->endInsertRows();
+ qCDebug(lcFolderListModel) << "- ... inserted sorted rows";
}
void QQuickFolderListModelPrivate::_q_statusChanged(QQuickFolderListModel::Status s)
@@ -211,7 +185,7 @@ QString QQuickFolderListModelPrivate::resolvePath(const QUrl &path)
QString localPath = QQmlFile::urlToLocalFileOrQrc(path);
QUrl localUrl = QUrl(localPath);
QString fullPath = localUrl.path();
- if (localUrl.scheme().length())
+ if (localUrl.scheme().size())
fullPath = localUrl.scheme() + QLatin1Char(':') + fullPath;
return QDir::cleanPath(fullPath);
}
@@ -232,7 +206,7 @@ QString QQuickFolderListModelPrivate::resolvePath(const QUrl &path)
/*!
\qmltype FolderListModel
\inqmlmodule Qt.labs.folderlistmodel
- \instantiates QQuickFolderListModel
+//! \instantiates QQuickFolderListModel
\ingroup qtquick-models
\brief The FolderListModel provides a model of the contents of a file system folder.
@@ -243,6 +217,12 @@ QString QQuickFolderListModelPrivate::resolvePath(const QUrl &path)
\e{Elements in the Qt.labs module are not guaranteed to remain compatible
in future versions.}
+ \note Some features in FolderListModel depend on \l QFileSystemWatcher. If \l QFileSystemWatcher
+ is disabled, the folder set using \c setFolder is not watched for changes, which results in
+ signals typically emitted on directory changes (like directoryUpdated or directoryChanged) not
+ being emitted without manually calling \c setFolder again. For more information, see
+ \l{Qt Configure Options}.
+
\qml
import Qt.labs.folderlistmodel
\endqml
@@ -252,16 +232,16 @@ QString QQuickFolderListModelPrivate::resolvePath(const QUrl &path)
Components access names and paths via the following roles:
\list
- \li \c fileName
- \li \c filePath
- \li \c fileURL (since Qt 5.2; deprecated since Qt 5.15)
- \li \c fileUrl (since Qt 5.15)
- \li \c fileBaseName
- \li \c fileSuffix
- \li \c fileSize
- \li \c fileModified
- \li \c fileAccessed
- \li \c fileIsDir
+ \li \c fileName (\c string)
+ \li \c filePath (\c string)
+ \li \c fileURL (\c url) (since Qt 5.2; deprecated since Qt 5.15)
+ \li \c fileUrl (\c url) (since Qt 5.15)
+ \li \c fileBaseName (\c string)
+ \li \c fileSuffix (\c string)
+ \li \c fileSize (\c qlonglong)
+ \li \c fileModified (\c date)
+ \li \c fileAccessed (\c date)
+ \li \c fileIsDir (\c bool)
\endlist
Additionally a file entry can be differentiated from a folder entry via the
@@ -304,6 +284,7 @@ QString QQuickFolderListModelPrivate::resolvePath(const QUrl &path)
Component {
id: fileDelegate
+ required property string fileName
Text { text: fileName }
}
@@ -395,6 +376,7 @@ QHash<int, QByteArray> QQuickFolderListModel::roleNames() const
/*!
\qmlproperty int FolderListModel::count
+ \readonly
Returns the number of items in the current folder that match the
filter criteria.
@@ -419,7 +401,8 @@ QModelIndex QQuickFolderListModel::index(int row, int , const QModelIndex &) con
The value must be a \c file: or \c qrc: URL, or a relative URL.
- The default value is an invalid URL.
+ The default value is the application's working directory at the time
+ when the FolderListModel is first initialized.
*/
QUrl QQuickFolderListModel::folder() const
{
@@ -436,6 +419,7 @@ void QQuickFolderListModel::setFolder(const QUrl &folder)
QString resolvedPath = QQuickFolderListModelPrivate::resolvePath(folder);
+ qCDebug(lcFolderListModel) << "about to emit beginResetModel since our folder was set to" << folder;
beginResetModel();
//Remove the old path for the file system watcher
@@ -493,6 +477,7 @@ void QQuickFolderListModel::setRootFolder(const QUrl &path)
/*!
\qmlproperty url FolderListModel::parentFolder
+ \readonly
Returns the URL of the parent of the current \l folder.
*/
@@ -563,15 +548,14 @@ void QQuickFolderListModel::componentComplete()
/*!
\qmlproperty enumeration FolderListModel::sortField
- The \a sortField property contains field to use for sorting. sortField
- may be one of:
- \list
- \li Unsorted - no sorting is applied.
- \li Name - sort by filename
- \li Time - sort by time modified
- \li Size - sort by file size
- \li Type - sort by file type (extension)
- \endlist
+ The \a sortField property contains the field to use for sorting.
+ \c sortField may be one of:
+
+ \value FolderListModel.Unsorted no sorting is applied
+ \value FolderListModel.Name sort by filename (default)
+ \value FolderListModel.Time sort by time modified
+ \value FolderListModel.Size sort by file size
+ \value FolderListModel.Type sort by file type/extension
\sa sortReversed
*/
@@ -819,13 +803,13 @@ void QQuickFolderListModel::setCaseSensitive(bool on)
/*!
\qmlproperty enumeration FolderListModel::status
\since 5.11
+ \readonly
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
+
+ \value FolderListModel.Null no \a folder has been set
+ \value FolderListModel.Ready the folder has been loaded
+ \value FolderListModel.Loading the folder is currently being loaded
Use this status to provide an update or respond to the status change in some way.
For example, you could:
@@ -886,16 +870,16 @@ void QQuickFolderListModel::setSortCaseSensitive(bool on)
are available:
\list
- \li \c fileName
- \li \c filePath
- \li \c fileURL (since Qt 5.2; deprecated since Qt 5.15)
- \li \c fileUrl (since Qt 5.15)
- \li \c fileBaseName
- \li \c fileSuffix
- \li \c fileSize
- \li \c fileModified
- \li \c fileAccessed
- \li \c fileIsDir
+ \li \c fileName (\c string)
+ \li \c filePath (\c string)
+ \li \c fileURL (\c url) (since Qt 5.2; deprecated since Qt 5.15)
+ \li \c fileUrl (\c url) (since Qt 5.15)
+ \li \c fileBaseName (\c string)
+ \li \c fileSuffix (\c string)
+ \li \c fileSize (\c qlonglong)
+ \li \c fileModified (\c date)
+ \li \c fileAccessed (\c date)
+ \li \c fileIsDir (\c bool)
\endlist
*/
QVariant QQuickFolderListModel::get(int idx, const QString &property) const
@@ -921,7 +905,7 @@ int QQuickFolderListModel::indexOf(const QUrl &file) const
return d->data.indexOf(toFind);
}
-#include "moc_qquickfolderlistmodel_p.cpp"
-
//![code]
QT_END_NAMESPACE
+
+#include "moc_qquickfolderlistmodel_p.cpp"