8#include <QtCore/qloggingcategory.h>
32 bool sortReversed =
false;
33 bool showFiles =
true;
35 bool showDirsFirst =
false;
36 bool showDotAndDotDot =
false;
37 bool showOnlyReadable =
false;
38 bool showHidden =
false;
39 bool caseSensitive =
true;
40 bool sortCaseSensitive =
true;
49 void _q_sortFinished(
const QList<FileProperty> &
list);
59 qRegisterMetaType<QList<FileProperty> >(
"QList<FileProperty>");
60 qRegisterMetaType<QQuickFolderListModel::Status>(
"QQuickFolderListModel::Status");
77 QDir::SortFlags
flags;
97 emit q->layoutAboutToBeChanged();
109 qCDebug(lcFolderListModel) <<
"_q_directoryChanged called with directory" <<
directory;
115 qCDebug(lcFolderListModel) <<
"- endResetModel called";
116 emit q->rowCountChanged();
117 emit q->folderChanged();
128 QModelIndex modelIndexFrom =
q->createIndex(fromIndex, 0);
131 emit q->dataChanged(modelIndexFrom, modelIndexTo);
137 if (
data.size() > 0) {
138 q->beginRemoveRows(parent, 0,
data.size() - 1);
145 q->beginInsertRows(parent, 0,
data.size() - 1);
148 emit q->rowCountChanged();
155 qCDebug(lcFolderListModel) <<
"_q_sortFinished called with" <<
list.
size() <<
"files";
158 if (
data.size() > 0) {
159 qCDebug(lcFolderListModel) <<
"- removing all existing rows...";
160 q->beginRemoveRows(parent, 0,
data.size()-1);
163 qCDebug(lcFolderListModel) <<
"- ...removed all existing rows";
166 qCDebug(lcFolderListModel) <<
"- inserting sorted rows...";
167 q->beginInsertRows(parent, 0,
list.
size()-1);
170 qCDebug(lcFolderListModel) <<
"- ... inserted sorted rows";
179 emit q->statusChanged();
187 QString fullPath = localUrl.path();
188 if (localUrl.scheme().size())
189 fullPath = localUrl.scheme() +
QLatin1Char(
':') + fullPath;
332 if (
index.row() >=
d->data.size())
338 rv =
d->data.at(
index.row()).fileName();
341 rv =
d->data.at(
index.row()).filePath();
344 rv =
d->data.at(
index.row()).baseName();
347 rv =
d->data.at(
index.row()).suffix();
350 rv =
d->data.at(
index.row()).size();
353 rv =
d->data.at(
index.row()).lastModified();
356 rv =
d->data.at(
index.row()).lastRead();
359 rv =
d->data.at(
index.row()).isDir();
388 return d->data.size();
410 return d->currentDir;
422 qCDebug(lcFolderListModel) <<
"about to emit beginResetModel since our folder was set to" <<
folder;
426 if (!
d->currentDir.isEmpty())
427 d->fileInfoThread.removePath(
d->currentDir.path());
432 if (!
info.exists() || !
info.isDir()) {
443 d->fileInfoThread.setPath(resolvedPath);
470 if (!
info.exists() || !
info.isDir())
473 d->fileInfoThread.setRootPath(resolvedPath);
488 QString localFile =
d->currentDir.toLocalFile();
489 if (!localFile.isEmpty()) {
491 if (
dir.isRoot() || !
dir.cdUp())
493 localFile =
dir.path();
523 return d->nameFilters;
531 d->fileInfoThread.setNameFilters(
filters);
543 if (localPath.
isEmpty() || !
QDir(localPath).exists())
571 if (field !=
d->sortField) {
572 d->sortField = field;
580 return d->roleNames.key(roleName.toLatin1(), -1);
593 return d->sortReversed;
600 if (rev !=
d->sortReversed) {
601 d->sortReversed = rev;
646 d->fileInfoThread.setShowFiles(on);
672 d->fileInfoThread.setShowDirs(on);
688 return d->showDirsFirst;
695 d->fileInfoThread.setShowDirsFirst(on);
696 d->showDirsFirst = on;
713 return d->showDotAndDotDot;
720 if (on !=
d->showDotAndDotDot) {
721 d->fileInfoThread.setShowDotAndDotDot(on);
722 d->showDotAndDotDot = on;
739 return d->showHidden;
746 if (on !=
d->showHidden) {
747 d->fileInfoThread.setShowHidden(on);
765 return d->showOnlyReadable;
772 if (on !=
d->showOnlyReadable) {
773 d->fileInfoThread.setShowOnlyReadable(on);
774 d->showOnlyReadable = on;
790 return d->caseSensitive;
797 if (on !=
d->caseSensitive) {
798 d->fileInfoThread.setCaseSensitive(on);
799 d->caseSensitive = on;
853 return d->sortCaseSensitive;
860 if (on !=
d->sortCaseSensitive) {
861 d->sortCaseSensitive = on;
888 if (role >= 0 && idx >= 0)
905 return d->data.indexOf(toFind);
911#include "moc_qquickfolderlistmodel_p.cpp"
void setSortFlags(QDir::SortFlags flags)
void endResetModel()
Completes a model reset operation.
void beginResetModel()
Begins a model reset operation.
QModelIndex createIndex(int row, int column, const void *data=nullptr) const
Creates a model index for the given row and column with the internal pointer ptr.
QObject * parent() const
Returns a pointer to the parent object.
static QString cleanPath(const QString &path)
Returns path with directory separators normalized (that is, platform-native separators converted to "...
static QString currentPath()
Returns the absolute path of the application's current directory.
qsizetype size() const noexcept
constexpr bool isValid() const noexcept
Returns {true} if this model index is valid; otherwise returns {false}.
static QString urlToLocalFileOrQrc(const QString &)
If url is a local file returns a path suitable for passing to \l{QFile}.
static QString resolvePath(const QUrl &path)
void _q_sortFinished(const QList< FileProperty > &list)
QQuickFolderListModelPrivate(QQuickFolderListModel *q)
QHash< int, QByteArray > roleNames
QQuickFolderListModel::SortField sortField
QList< FileProperty > data
FileInfoThread fileInfoThread
void _q_directoryChanged(const QString &directory, const QList< FileProperty > &list)
void _q_statusChanged(QQuickFolderListModel::Status s)
~QQuickFolderListModelPrivate()
void _q_directoryUpdated(const QString &directory, const QList< FileProperty > &list, int fromIndex, int toIndex)
QQuickFolderListModel * q_ptr
QQuickFolderListModel::Status status
void setFolder(const QUrl &folder)
Q_INVOKABLE QVariant get(int idx, const QString &property) const
\qmlmethod var FolderListModel::get(int index, string property)
void setShowDirs(bool showDirs)
void setShowDirsFirst(bool showDirsFirst)
QHash< int, QByteArray > roleNames() const override
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
Returns the index of the data in row and column with parent.
void setNameFilters(const QStringList &filters)
void rowCountChanged() const
Q_INVOKABLE int indexOf(const QUrl &file) const
\qmlmethod int FolderListModel::indexOf(url file)
void setSortField(SortField field)
void setShowDotAndDotDot(bool on)
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
void setCaseSensitive(bool on)
Q_INVOKABLE bool isFolder(int index) const
[prop funcs]
void setShowFiles(bool showFiles)
QQuickFolderListModel(QObject *parent=nullptr)
[class props]
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Returns the data stored under the given role for the item referred to by the index.
void setSortCaseSensitive(bool on)
void setRootFolder(const QUrl &path)
FINALbool sortCaseSensitive
void setSortReversed(bool rev)
void classBegin() override
[parserstatus]
FINALbool showOnlyReadable
void setShowOnlyReadable(bool on)
void setShowHidden(bool on)
int rowCount(const QModelIndex &parent=QModelIndex()) const override
\qmlproperty int FolderListModel::count \readonly
int roleFromString(const QString &roleName) const
[parserstatus]
\macro QT_RESTRICTED_CAST_FROM_ASCII
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
static QUrl fromLocalFile(const QString &localfile)
Returns a QUrl representation of localFile, interpreted as a local file.
bool isValid() const
Returns true if the storage type of this variant is not QMetaType::UnknownType; otherwise returns fal...
bool toBool() const
Returns the variant as a bool if the variant has userType() Bool.
void statusChanged(QQmlComponent::Status status)
[1]
Combined button and popup list for selecting options.
#define Q_LOGGING_CATEGORY(name,...)
#define qCDebug(category,...)
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLdouble GLdouble GLdouble GLdouble q
GLsizei const GLchar *const * path
GLenum GLenum GLsizei void * row
QLatin1StringView QLatin1String
static QT_BEGIN_NAMESPACE void init(QTextBoundaryFinder::BoundaryType type, QStringView str, QCharAttributes *attributes)
static uint toIndex(ExecutionEngine *e, const Value &v)
const QStringList filters({"Image files (*.png *.xpm *.jpg)", "Text files (*.txt)", "Any files (*)" })
[6]
\inmodule QtCore \reentrant