Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquickfolderlistmodel_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QQUICKFOLDERLISTMODEL_P_H
5#define QQUICKFOLDERLISTMODEL_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
19
20#include <QtQml/qqml.h>
21#include <QStringList>
22#include <QUrl>
23#include <QAbstractListModel>
24
26
27
28class QQmlContext;
29class QModelIndex;
30
31class QQuickFolderListModelPrivate;
32
33//![class begin]
34class Q_LABSFOLDERLISTMODEL_EXPORT QQuickFolderListModel : public QAbstractListModel, public QQmlParserStatus
35{
36 Q_OBJECT
37 Q_INTERFACES(QQmlParserStatus)
38//![class begin]
39
40//![class props]
41 Q_PROPERTY(QUrl folder READ folder WRITE setFolder NOTIFY folderChanged FINAL)
42 Q_PROPERTY(QUrl rootFolder READ rootFolder WRITE setRootFolder NOTIFY rootFolderChanged FINAL)
43 Q_PROPERTY(QUrl parentFolder READ parentFolder NOTIFY folderChanged FINAL)
44 Q_PROPERTY(QStringList nameFilters READ nameFilters WRITE setNameFilters NOTIFY nameFilterChanged FINAL)
45 Q_PROPERTY(SortField sortField READ sortField WRITE setSortField NOTIFY sortFieldChanged FINAL)
46 Q_PROPERTY(bool sortReversed READ sortReversed WRITE setSortReversed NOTIFY sortReversedChanged FINAL)
47 Q_PROPERTY(bool showFiles READ showFiles WRITE setShowFiles NOTIFY showFilesChanged REVISION(2, 1) FINAL)
48 Q_PROPERTY(bool showDirs READ showDirs WRITE setShowDirs NOTIFY showDirsChanged FINAL)
49 Q_PROPERTY(bool showDirsFirst READ showDirsFirst WRITE setShowDirsFirst NOTIFY showDirsFirstChanged FINAL)
50 Q_PROPERTY(bool showDotAndDotDot READ showDotAndDotDot WRITE setShowDotAndDotDot NOTIFY showDotAndDotDotChanged FINAL)
51 Q_PROPERTY(bool showHidden READ showHidden WRITE setShowHidden NOTIFY showHiddenChanged REVISION(2, 1) FINAL)
52 Q_PROPERTY(bool showOnlyReadable READ showOnlyReadable WRITE setShowOnlyReadable NOTIFY showOnlyReadableChanged FINAL)
53 Q_PROPERTY(bool caseSensitive READ caseSensitive WRITE setCaseSensitive NOTIFY caseSensitiveChanged REVISION(2, 2) FINAL)
54 Q_PROPERTY(int count READ count NOTIFY countChanged FINAL)
55 Q_PROPERTY(Status status READ status NOTIFY statusChanged REVISION(2, 11) FINAL)
56 Q_PROPERTY(bool sortCaseSensitive READ sortCaseSensitive WRITE setSortCaseSensitive NOTIFY sortCaseSensitiveChanged REVISION(2, 12) FINAL)
57//![class props]
58
59 QML_NAMED_ELEMENT(FolderListModel)
60 QML_ADDED_IN_VERSION(1, 0)
61//![abslistmodel]
62public:
63 QQuickFolderListModel(QObject *parent = nullptr);
64 ~QQuickFolderListModel();
65
66 enum Roles {
67 FileNameRole = Qt::UserRole + 1,
68 FilePathRole = Qt::UserRole + 2,
69 FileBaseNameRole = Qt::UserRole + 3,
70 FileSuffixRole = Qt::UserRole + 4,
71 FileSizeRole = Qt::UserRole + 5,
72 FileLastModifiedRole = Qt::UserRole + 6,
73 FileLastReadRole = Qt::UserRole +7,
74 FileIsDirRole = Qt::UserRole + 8,
75 FileUrlRole = Qt::UserRole + 9,
76 };
77
78 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
79 QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const override;
80 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
81 QHash<int, QByteArray> roleNames() const override;
82//![abslistmodel]
83
84//![count]
85 int count() const { return rowCount(QModelIndex()); }
86//![count]
87
88//![prop funcs]
89 QUrl folder() const;
90 void setFolder(const QUrl &folder);
91 QUrl rootFolder() const;
92 void setRootFolder(const QUrl &path);
93
94 QUrl parentFolder() const;
95
96 QStringList nameFilters() const;
97 void setNameFilters(const QStringList &filters);
98
99 enum SortField { Unsorted, Name, Time, Size, Type };
100 Q_ENUM(SortField)
101 SortField sortField() const;
102 void setSortField(SortField field);
103
104 bool sortReversed() const;
105 void setSortReversed(bool rev);
106
107 bool showFiles() const;
108 void setShowFiles(bool showFiles);
109 bool showDirs() const;
110 void setShowDirs(bool showDirs);
111 bool showDirsFirst() const;
112 void setShowDirsFirst(bool showDirsFirst);
113 bool showDotAndDotDot() const;
114 void setShowDotAndDotDot(bool on);
115 bool showHidden() const;
116 void setShowHidden(bool on);
117 bool showOnlyReadable() const;
118 void setShowOnlyReadable(bool on);
119 bool caseSensitive() const;
120 void setCaseSensitive(bool on);
121
122 enum Status { Null, Ready, Loading };
123 Q_ENUM(Status)
124 Status status() const;
125 bool sortCaseSensitive() const;
126 void setSortCaseSensitive(bool on);
127//![prop funcs]
128
129 Q_INVOKABLE bool isFolder(int index) const;
130 Q_INVOKABLE QVariant get(int idx, const QString &property) const;
131 Q_INVOKABLE int indexOf(const QUrl &file) const;
132
133//![parserstatus]
134 void classBegin() override;
135 void componentComplete() override;
136//![parserstatus]
137
138 int roleFromString(const QString &roleName) const;
139
140//![notifier]
141Q_SIGNALS:
142 void folderChanged();
143 void rowCountChanged() const;
144 void rootFolderChanged();
145 void nameFilterChanged();
146 void sortFieldChanged();
147 void sortReversedChanged();
148 void showFilesChanged();
149 void showDirsChanged();
150 void showDirsFirstChanged();
151 void showDotAndDotDotChanged();
152 void showHiddenChanged();
153 void showOnlyReadableChanged();
154 void caseSensitiveChanged();
155 void sortCaseSensitiveChanged();
156
157 Q_REVISION(2, 1) void countChanged() const;
158 Q_REVISION(2, 11) void statusChanged();
159
160//![notifier]
161
162//![class end]
163
164
165private:
166 Q_DISABLE_COPY(QQuickFolderListModel)
167 Q_DECLARE_PRIVATE(QQuickFolderListModel)
168 QScopedPointer<QQuickFolderListModelPrivate> d_ptr;
169
170 Q_PRIVATE_SLOT(d_func(), void _q_directoryChanged(const QString &directory, const QList<FileProperty> &list))
171 Q_PRIVATE_SLOT(d_func(), void _q_directoryUpdated(const QString &directory, const QList<FileProperty> &list, int fromIndex, int toIndex))
172 Q_PRIVATE_SLOT(d_func(), void _q_sortFinished(const QList<FileProperty> &list))
173 Q_PRIVATE_SLOT(d_func(), void _q_statusChanged(QQuickFolderListModel::Status s))
174};
175//![class end]
176
177QT_END_NAMESPACE
178
179#endif // QQUICKFOLDERLISTMODEL_P_H
void removePath(const QString &path)
void setRootPath(const QString &path)
void setShowFiles(bool show)
void directoryUpdated(const QString &directory, const QList< FileProperty > &list, int fromIndex, int toIndex) const
void setShowDotAndDotDot(bool on)
void statusChanged(QQuickFolderListModel::Status status) const
void setNameFilters(const QStringList &nameFilters)
FileInfoThread(QObject *parent=nullptr)
void setShowDirsFirst(bool show)
void setCaseSensitive(bool on)
void setShowDirs(bool showFolders)
void sortFinished(const QList< FileProperty > &list) const
void findChangeRange(const QList< FileProperty > &list, int &fromIndex, int &toIndex)
void setShowHidden(bool on)
void getFileInfos(const QString &path)
void setShowOnlyReadable(bool on)
void setPath(const QString &path)
void setSortFlags(QDir::SortFlags flags)
\inmodule QtCore
QString fileInfoListToString(const QFileInfoList &fileInfoList)
constexpr FileInfoThread::UpdateTypes operator|(FileInfoThread::UpdateType f1, FileInfoThread::UpdateTypes f2) noexcept
constexpr FileInfoThread::UpdateTypes operator&(FileInfoThread::UpdateType f1, FileInfoThread::UpdateTypes f2) noexcept