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 QtWidgets module 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 QDIRMODEL_H
41#define QDIRMODEL_H
42
43#include <QtWidgets/qtwidgetsglobal.h>
44#include <QtCore/qabstractitemmodel.h>
45#include <QtCore/qdir.h>
46#include <QtWidgets/qfileiconprovider.h>
47
48#if QT_DEPRECATED_SINCE(5, 15)
49
50QT_REQUIRE_CONFIG(dirmodel);
51
52QT_BEGIN_NAMESPACE
53
54class QDirModelPrivate;
55
56class Q_WIDGETS_EXPORT QDirModel : public QAbstractItemModel
57{
58 Q_OBJECT
59 Q_PROPERTY(bool resolveSymlinks READ resolveSymlinks WRITE setResolveSymlinks)
60 Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly)
61 Q_PROPERTY(bool lazyChildCount READ lazyChildCount WRITE setLazyChildCount)
62
63public:
64 enum Roles {
65 FileIconRole = Qt::DecorationRole,
66 FilePathRole = Qt::UserRole + 1,
67 FileNameRole
68 };
69
70 QT_DEPRECATED_VERSION_X_5_15("Use QFileSystemModel") QDirModel(const QStringList &nameFilters,
71 QDir::Filters filters, QDir::SortFlags sort,
72 QObject *parent = nullptr);
73 QT_DEPRECATED_VERSION_X_5_15("Use QFileSystemModel") explicit QDirModel(QObject *parent = nullptr);
74 ~QDirModel();
75
76 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
77 QModelIndex parent(const QModelIndex &child) const override;
78
79 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
80 int columnCount(const QModelIndex &parent = QModelIndex()) const override;
81
82 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
83 bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
84
85 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
86
87 bool hasChildren(const QModelIndex &index = QModelIndex()) const override;
88 Qt::ItemFlags flags(const QModelIndex &index) const override;
89
90 void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override;
91
92 QStringList mimeTypes() const override;
93 QMimeData *mimeData(const QModelIndexList &indexes) const override;
94 bool dropMimeData(const QMimeData *data, Qt::DropAction action,
95 int row, int column, const QModelIndex &parent) override;
96 Qt::DropActions supportedDropActions() const override;
97
98 // QDirModel specific API
99
100 void setIconProvider(QFileIconProvider *provider);
101 QFileIconProvider *iconProvider() const;
102
103 void setNameFilters(const QStringList &filters);
104 QStringList nameFilters() const;
105
106 void setFilter(QDir::Filters filters);
107 QDir::Filters filter() const;
108
109 void setSorting(QDir::SortFlags sort);
110 QDir::SortFlags sorting() const;
111
112 void setResolveSymlinks(bool enable);
113 bool resolveSymlinks() const;
114
115 void setReadOnly(bool enable);
116 bool isReadOnly() const;
117
118 void setLazyChildCount(bool enable);
119 bool lazyChildCount() const;
120
121 QModelIndex index(const QString &path, int column = 0) const;
122
123 bool isDir(const QModelIndex &index) const;
124 QModelIndex mkdir(const QModelIndex &parent, const QString &name);
125 bool rmdir(const QModelIndex &index);
126 bool remove(const QModelIndex &index);
127
128 QString filePath(const QModelIndex &index) const;
129 QString fileName(const QModelIndex &index) const;
130 QIcon fileIcon(const QModelIndex &index) const;
131 QFileInfo fileInfo(const QModelIndex &index) const;
132
133 using QObject::parent;
134
135public Q_SLOTS:
136 void refresh(const QModelIndex &parent = QModelIndex());
137
138protected:
139 QDirModel(QDirModelPrivate &, QObject *parent = nullptr);
140 friend class QFileDialogPrivate;
141
142private:
143 Q_DECLARE_PRIVATE(QDirModel)
144 Q_DISABLE_COPY(QDirModel)
145 Q_PRIVATE_SLOT(d_func(), void _q_refresh())
146};
147
148QT_END_NAMESPACE
149
150#endif // QT_DEPRECATED_SINCE(5, 15)
151
152#endif // QDIRMODEL_H
153

source code of qtbase/src/widgets/itemviews/qdirmodel.h