1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the examples of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QQUICKFOLDERLISTMODEL_H
41#define QQUICKFOLDERLISTMODEL_H
42
43#include <qqml.h>
44#include <QStringList>
45#include <QUrl>
46#include <QAbstractListModel>
47
48QT_BEGIN_NAMESPACE
49
50
51class QQmlContext;
52class QModelIndex;
53
54class QQuickFolderListModelPrivate;
55
56//![class begin]
57class QQuickFolderListModel : public QAbstractListModel, public QQmlParserStatus
58{
59 Q_OBJECT
60 Q_INTERFACES(QQmlParserStatus)
61//![class begin]
62
63//![class props]
64 Q_PROPERTY(QUrl folder READ folder WRITE setFolder NOTIFY folderChanged)
65 Q_PROPERTY(QUrl rootFolder READ rootFolder WRITE setRootFolder)
66 Q_PROPERTY(QUrl parentFolder READ parentFolder NOTIFY folderChanged)
67 Q_PROPERTY(QStringList nameFilters READ nameFilters WRITE setNameFilters)
68 Q_PROPERTY(SortField sortField READ sortField WRITE setSortField)
69 Q_PROPERTY(bool sortReversed READ sortReversed WRITE setSortReversed)
70 Q_PROPERTY(bool showFiles READ showFiles WRITE setShowFiles REVISION 1)
71 Q_PROPERTY(bool showDirs READ showDirs WRITE setShowDirs)
72 Q_PROPERTY(bool showDirsFirst READ showDirsFirst WRITE setShowDirsFirst)
73 Q_PROPERTY(bool showDotAndDotDot READ showDotAndDotDot WRITE setShowDotAndDotDot)
74 Q_PROPERTY(bool showHidden READ showHidden WRITE setShowHidden REVISION 1)
75 Q_PROPERTY(bool showOnlyReadable READ showOnlyReadable WRITE setShowOnlyReadable)
76 Q_PROPERTY(bool caseSensitive READ caseSensitive WRITE setCaseSensitive REVISION 2)
77 Q_PROPERTY(int count READ count NOTIFY countChanged)
78 Q_PROPERTY(Status status READ status NOTIFY statusChanged REVISION 11)
79 Q_PROPERTY(bool sortCaseSensitive READ sortCaseSensitive WRITE setSortCaseSensitive REVISION 12)
80//![class props]
81
82 QML_NAMED_ELEMENT(FolderListModel)
83//![abslistmodel]
84public:
85 QQuickFolderListModel(QObject *parent = nullptr);
86 ~QQuickFolderListModel();
87
88 enum Roles {
89 FileNameRole = Qt::UserRole + 1,
90 FilePathRole = Qt::UserRole + 2,
91 FileBaseNameRole = Qt::UserRole + 3,
92 FileSuffixRole = Qt::UserRole + 4,
93 FileSizeRole = Qt::UserRole + 5,
94 FileLastModifiedRole = Qt::UserRole + 6,
95 FileLastReadRole = Qt::UserRole +7,
96 FileIsDirRole = Qt::UserRole + 8,
97 FileUrlRole = Qt::UserRole + 9,
98 FileURLRole = Qt::UserRole + 10
99 };
100
101 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
102 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
103 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
104 QHash<int, QByteArray> roleNames() const override;
105//![abslistmodel]
106
107//![count]
108 int count() const { return rowCount(parent: QModelIndex()); }
109//![count]
110
111//![prop funcs]
112 QUrl folder() const;
113 void setFolder(const QUrl &folder);
114 QUrl rootFolder() const;
115 void setRootFolder(const QUrl &path);
116
117 QUrl parentFolder() const;
118
119 QStringList nameFilters() const;
120 void setNameFilters(const QStringList &filters);
121
122 enum SortField { Unsorted, Name, Time, Size, Type };
123 Q_ENUM(SortField)
124 SortField sortField() const;
125 void setSortField(SortField field);
126
127 bool sortReversed() const;
128 void setSortReversed(bool rev);
129
130 bool showFiles() const;
131 void setShowFiles(bool showFiles);
132 bool showDirs() const;
133 void setShowDirs(bool showDirs);
134 bool showDirsFirst() const;
135 void setShowDirsFirst(bool showDirsFirst);
136 bool showDotAndDotDot() const;
137 void setShowDotAndDotDot(bool on);
138 bool showHidden() const;
139 void setShowHidden(bool on);
140 bool showOnlyReadable() const;
141 void setShowOnlyReadable(bool on);
142 bool caseSensitive() const;
143 void setCaseSensitive(bool on);
144
145 enum Status { Null, Ready, Loading };
146 Q_ENUM(Status)
147 Status status() const;
148 bool sortCaseSensitive() const;
149 void setSortCaseSensitive(bool on);
150//![prop funcs]
151
152 Q_INVOKABLE bool isFolder(int index) const;
153 Q_INVOKABLE QVariant get(int idx, const QString &property) const;
154 Q_INVOKABLE int indexOf(const QUrl &file) const;
155
156//![parserstatus]
157 void classBegin() override;
158 void componentComplete() override;
159//![parserstatus]
160
161 int roleFromString(const QString &roleName) const;
162
163//![notifier]
164Q_SIGNALS:
165 void folderChanged();
166 void rowCountChanged() const;
167 Q_REVISION(1) void countChanged() const;
168 Q_REVISION(11) void statusChanged();
169//![notifier]
170
171//![class end]
172
173
174private:
175 Q_DISABLE_COPY(QQuickFolderListModel)
176 Q_DECLARE_PRIVATE(QQuickFolderListModel)
177 QScopedPointer<QQuickFolderListModelPrivate> d_ptr;
178
179 Q_PRIVATE_SLOT(d_func(), void _q_directoryChanged(const QString &directory, const QList<FileProperty> &list))
180 Q_PRIVATE_SLOT(d_func(), void _q_directoryUpdated(const QString &directory, const QList<FileProperty> &list, int fromIndex, int toIndex))
181 Q_PRIVATE_SLOT(d_func(), void _q_sortFinished(const QList<FileProperty> &list))
182 Q_PRIVATE_SLOT(d_func(), void _q_statusChanged(QQuickFolderListModel::Status s))
183};
184//![class end]
185
186QT_END_NAMESPACE
187
188#endif // QQUICKFOLDERLISTMODEL_H
189

source code of qtdeclarative/src/imports/folderlistmodel/qquickfolderlistmodel.h