Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qfilesystemmodel.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 QFILESYSTEMMODEL_H
5#define QFILESYSTEMMODEL_H
6
7#include <QtGui/qtguiglobal.h>
8#include <QtCore/qabstractitemmodel.h>
9#include <QtCore/qpair.h>
10#include <QtCore/qdir.h>
11#include <QtGui/qicon.h>
12
13QT_REQUIRE_CONFIG(filesystemmodel);
14
16
17class ExtendedInformation;
20
21class Q_GUI_EXPORT QFileSystemModel : public QAbstractItemModel
22{
24 Q_PROPERTY(bool resolveSymlinks READ resolveSymlinks WRITE setResolveSymlinks)
25 Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly)
26 Q_PROPERTY(bool nameFilterDisables READ nameFilterDisables WRITE setNameFilterDisables)
27 Q_PROPERTY(Options options READ options WRITE setOptions)
28
30 void rootPathChanged(const QString &newPath);
31 void fileRenamed(const QString &path, const QString &oldName, const QString &newName);
32 void directoryLoaded(const QString &path);
33
34public:
35 // ### Qt 7: renumber these values to be before Qt::UserRole comment.
36 enum Roles {
37 FileIconRole = Qt::DecorationRole,
38 FileInfoRole = Qt::UserRole - 1,
39 FilePathRole = Qt::UserRole + 1,
40 FileNameRole = Qt::UserRole + 2,
41 FilePermissions = Qt::UserRole + 3,
42 };
43
44 enum Option
45 {
46 DontWatchForChanges = 0x00000001,
47 DontResolveSymlinks = 0x00000002,
48 DontUseCustomDirectoryIcons = 0x00000004
49 };
52
53 explicit QFileSystemModel(QObject *parent = nullptr);
55
56 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
57 QModelIndex index(const QString &path, int column = 0) const;
58 QModelIndex parent(const QModelIndex &child) const override;
59 using QObject::parent;
60 QModelIndex sibling(int row, int column, const QModelIndex &idx) const override;
61 bool hasChildren(const QModelIndex &parent = QModelIndex()) const override;
62 bool canFetchMore(const QModelIndex &parent) const override;
63 void fetchMore(const QModelIndex &parent) override;
64
65 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
66 int columnCount(const QModelIndex &parent = QModelIndex()) const override;
67
68 QVariant myComputer(int role = Qt::DisplayRole) const;
69 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
70 bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
71
72 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
73
74 Qt::ItemFlags flags(const QModelIndex &index) const override;
75
76 void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override;
77
78 QStringList mimeTypes() const override;
79 QMimeData *mimeData(const QModelIndexList &indexes) const override;
80 bool dropMimeData(const QMimeData *data, Qt::DropAction action,
81 int row, int column, const QModelIndex &parent) override;
82 Qt::DropActions supportedDropActions() const override;
83 QHash<int, QByteArray> roleNames() const override;
84
85 // QFileSystemModel specific API
86 QModelIndex setRootPath(const QString &path);
87 QString rootPath() const;
88 QDir rootDirectory() const;
89
90 void setIconProvider(QAbstractFileIconProvider *provider);
91 QAbstractFileIconProvider *iconProvider() const;
92
93 void setFilter(QDir::Filters filters);
94 QDir::Filters filter() const;
95
96 void setResolveSymlinks(bool enable);
97 bool resolveSymlinks() const;
98
99 void setReadOnly(bool enable);
100 bool isReadOnly() const;
101
102 void setNameFilterDisables(bool enable);
103 bool nameFilterDisables() const;
104
106 QStringList nameFilters() const;
107
108 void setOption(Option option, bool on = true);
109 bool testOption(Option option) const;
110 void setOptions(Options options);
111 Options options() const;
112
113 QString filePath(const QModelIndex &index) const;
114 bool isDir(const QModelIndex &index) const;
115 qint64 size(const QModelIndex &index) const;
116 QString type(const QModelIndex &index) const;
117
118 QDateTime lastModified(const QModelIndex &index) const;
119 QDateTime lastModified(const QModelIndex &index, const QTimeZone &tz) const;
120
121 QModelIndex mkdir(const QModelIndex &parent, const QString &name);
122 bool rmdir(const QModelIndex &index);
123 inline QString fileName(const QModelIndex &index) const;
124 inline QIcon fileIcon(const QModelIndex &index) const;
125 QFile::Permissions permissions(const QModelIndex &index) const;
126 QFileInfo fileInfo(const QModelIndex &index) const;
127 bool remove(const QModelIndex &index);
128
129protected:
131 void timerEvent(QTimerEvent *event) override;
132 bool event(QEvent *event) override;
133
134private:
135 Q_DECLARE_PRIVATE(QFileSystemModel)
136 Q_DISABLE_COPY(QFileSystemModel)
137
138 friend class QFileDialogPrivate;
139};
140
141inline QString QFileSystemModel::fileName(const QModelIndex &aindex) const
142{ return aindex.data(Qt::DisplayRole).toString(); }
144{ return qvariant_cast<QIcon>(aindex.data(Qt::DecorationRole)); }
145
146Q_DECLARE_OPERATORS_FOR_FLAGS(QFileSystemModel::Options)
147
149
150#endif // QFILESYSTEMMODEL_H
\inmodule QtCore\reentrant
Definition qdatetime.h:283
\inmodule QtCore
Definition qdir.h:20
\inmodule QtCore
Definition qcoreevent.h:45
The QFileSystemModel class provides a data model for the local filesystem.
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
\reimp
QIcon fileIcon(const QModelIndex &index) const
Returns the icon for the item stored in the model under the given index.
~QFileSystemModel()
Destroys this file system model.
Roles
\value FileIconRole \value FilePathRole \value FileNameRole \value FilePermissions \value FileInfoRol...
The QIcon class provides scalable icons in different modes and states.
Definition qicon.h:20
\inmodule QtCore
Definition qmimedata.h:16
\inmodule QtCore
\inmodule QtCore
Definition qobject.h:103
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore
Definition qtimezone.h:26
\inmodule QtCore
Definition qcoreevent.h:366
\inmodule QtCore
Definition qvariant.h:65
QString toString() const
Returns the variant as a QString if the variant has a userType() including, but not limited to:
Combined button and popup list for selecting options.
Orientation
Definition qnamespace.h:98
@ UserRole
@ DecorationRole
@ EditRole
@ DisplayRole
SortOrder
Definition qnamespace.h:121
@ AscendingOrder
Definition qnamespace.h:122
DropAction
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
#define Q_DECLARE_FLAGS(Flags, Enum)
Definition qflags.h:174
#define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
Definition qflags.h:194
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLuint index
[2]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum type
GLbitfield flags
GLboolean enable
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
GLuint name
GLenum GLenum GLsizei void GLsizei void * column
GLbyte GLbyte tz
struct _cl_event * event
GLsizei const GLchar *const * path
GLenum GLenum GLsizei void * row
GLuint GLenum option
GLfixed GLfixed GLint GLint order
#define QT_REQUIRE_CONFIG(feature)
#define Q_ENUM(x)
#define Q_PROPERTY(...)
#define Q_OBJECT
#define Q_SIGNALS
long long qint64
Definition qtypes.h:60
settings remove("monkey")
mimeData setData("text/csv", csvData)
QMimeData * mimeData
dialog setNameFilters(filters)
const QStringList filters({"Image files (*.png *.xpm *.jpg)", "Text files (*.txt)", "Any files (*)" })
[6]
QLayoutItem * child
[0]