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 showDot READ showDot WRITE setShowDot NOTIFY showDotChanged REVISION(6, 12))
52 Q_PROPERTY(bool showDotDot READ showDotDot WRITE setShowDotDot NOTIFY showDotDotChanged REVISION(6, 12))
53 Q_PROPERTY(bool showHidden READ showHidden WRITE setShowHidden NOTIFY showHiddenChanged REVISION(2, 1) FINAL)
54 Q_PROPERTY(bool showOnlyReadable READ showOnlyReadable WRITE setShowOnlyReadable NOTIFY showOnlyReadableChanged FINAL)
55 Q_PROPERTY(bool caseSensitive READ caseSensitive WRITE setCaseSensitive NOTIFY caseSensitiveChanged REVISION(2, 2) FINAL)
56 Q_PROPERTY(int count READ count NOTIFY countChanged FINAL)
57 Q_PROPERTY(Status status READ status NOTIFY statusChanged REVISION(2, 11) FINAL)
58 Q_PROPERTY(bool sortCaseSensitive READ sortCaseSensitive WRITE setSortCaseSensitive NOTIFY sortCaseSensitiveChanged REVISION(2, 12) FINAL)
59//![class props]
60
61 QML_NAMED_ELEMENT(FolderListModel)
62 QML_ADDED_IN_VERSION(1, 0)
63//![abslistmodel]
64public:
65 QQuickFolderListModel(QObject *parent = nullptr);
66 ~QQuickFolderListModel();
67
68 enum Roles {
69 FileNameRole = Qt::UserRole + 1,
70 FilePathRole = Qt::UserRole + 2,
71 FileBaseNameRole = Qt::UserRole + 3,
72 FileSuffixRole = Qt::UserRole + 4,
73 FileSizeRole = Qt::UserRole + 5,
74 FileLastModifiedRole = Qt::UserRole + 6,
75 FileLastReadRole = Qt::UserRole +7,
76 FileIsDirRole = Qt::UserRole + 8,
77 FileUrlRole = Qt::UserRole + 9,
78 };
79
80 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
81 QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const override;
82 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
83 QHash<int, QByteArray> roleNames() const override;
84//![abslistmodel]
85
86//![count]
87 int count() const { return rowCount(QModelIndex()); }
88//![count]
89
90//![prop funcs]
91 QUrl folder() const;
92 void setFolder(const QUrl &folder);
93 QUrl rootFolder() const;
94 void setRootFolder(const QUrl &path);
95
96 QUrl parentFolder() const;
97
98 QStringList nameFilters() const;
99 void setNameFilters(const QStringList &filters);
100
101 enum SortField { Unsorted, Name, Time, Size, Type };
102 Q_ENUM(SortField)
103 SortField sortField() const;
104 void setSortField(SortField field);
105
106 bool sortReversed() const;
107 void setSortReversed(bool rev);
108
109 bool showFiles() const;
110 void setShowFiles(bool showFiles);
111 bool showDirs() const;
112 void setShowDirs(bool showDirs);
113 bool showDirsFirst() const;
114 void setShowDirsFirst(bool showDirsFirst);
115 bool showDotAndDotDot() const;
116 void setShowDotAndDotDot(bool on);
117 bool showDot() const;
118 void setShowDot(bool on);
119 bool showDotDot() const;
120 void setShowDotDot(bool on);
121 bool showHidden() const;
122 void setShowHidden(bool on);
123 bool showOnlyReadable() const;
124 void setShowOnlyReadable(bool on);
125 bool caseSensitive() const;
126 void setCaseSensitive(bool on);
127
128 enum Status { Null, Ready, Loading };
129 Q_ENUM(Status)
130 Status status() const;
131 bool sortCaseSensitive() const;
132 void setSortCaseSensitive(bool on);
133//![prop funcs]
134
135 Q_INVOKABLE bool isFolder(int index) const;
136 Q_INVOKABLE QVariant get(int idx, const QString &property) const;
137 Q_INVOKABLE int indexOf(const QUrl &file) const;
138
139//![parserstatus]
140 void classBegin() override;
141 void componentComplete() override;
142//![parserstatus]
143
144 int roleFromString(const QString &roleName) const;
145
146//![notifier]
147Q_SIGNALS:
148 void folderChanged();
149 void rowCountChanged() const;
150 void rootFolderChanged();
151 void nameFilterChanged();
152 void sortFieldChanged();
153 void sortReversedChanged();
154 void showFilesChanged();
155 void showDirsChanged();
156 void showDirsFirstChanged();
157 void showDotAndDotDotChanged();
158 Q_REVISION(6, 12) void showDotChanged();
159 Q_REVISION(6, 12) void showDotDotChanged();
160 void showHiddenChanged();
161 void showOnlyReadableChanged();
162 void caseSensitiveChanged();
163 void sortCaseSensitiveChanged();
164
165 Q_REVISION(2, 1) void countChanged() const;
166 Q_REVISION(2, 11) void statusChanged();
167
168//![notifier]
169
170//![class end]
171
172
173private:
174 Q_DISABLE_COPY(QQuickFolderListModel)
175 Q_DECLARE_PRIVATE(QQuickFolderListModel)
176 QScopedPointer<QQuickFolderListModelPrivate> d_ptr;
177
178 Q_PRIVATE_SLOT(d_func(), void _q_directoryChanged(const QString &directory, const QList<FileProperty> &list))
179 Q_PRIVATE_SLOT(d_func(), void _q_directoryUpdated(const QString &directory, const QList<FileProperty> &list, int fromIndex, int toIndex))
180 Q_PRIVATE_SLOT(d_func(), void _q_sortFinished(const QList<FileProperty> &list))
181 Q_PRIVATE_SLOT(d_func(), void _q_statusChanged(QQuickFolderListModel::Status s))
182};
183//![class end]
184
185QT_END_NAMESPACE
186
187#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 setShowDotDot(bool on)
void statusChanged(QQuickFolderListModel::Status status) const
void setShowDot(bool on)
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
Combined button and popup list for selecting options.