Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-09 08:34:01

0001 // Copyright (C) 2016 The Qt Company Ltd.
0002 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0003 // Qt-Security score:significant reason:default
0004 
0005 #ifndef QFILESYSTEMMODEL_H
0006 #define QFILESYSTEMMODEL_H
0007 
0008 #include <QtGui/qtguiglobal.h>
0009 #include <QtCore/qabstractitemmodel.h>
0010 #include <QtCore/qdir.h>
0011 #include <QtGui/qicon.h>
0012 
0013 QT_REQUIRE_CONFIG(filesystemmodel);
0014 
0015 QT_BEGIN_NAMESPACE
0016 
0017 class ExtendedInformation;
0018 class QFileSystemModelPrivate;
0019 class QAbstractFileIconProvider;
0020 
0021 class Q_GUI_EXPORT QFileSystemModel : public QAbstractItemModel
0022 {
0023     Q_OBJECT
0024     Q_PROPERTY(bool resolveSymlinks READ resolveSymlinks WRITE setResolveSymlinks)
0025     Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly)
0026     Q_PROPERTY(bool nameFilterDisables READ nameFilterDisables WRITE setNameFilterDisables)
0027     Q_PROPERTY(Options options READ options WRITE setOptions)
0028 
0029 Q_SIGNALS:
0030     void rootPathChanged(const QString &newPath);
0031     void fileRenamed(const QString &path, const QString &oldName, const QString &newName);
0032     void directoryLoaded(const QString &path);
0033 
0034 public:
0035     enum Roles {
0036         FileIconRole = Qt::DecorationRole,
0037 
0038         FileInfoRole = Qt::FileInfoRole, // New values go before, -5, -6 ..etc
0039         QT7_ONLY(
0040         FilePathRole = Qt::UserRole - 3,
0041         FileNameRole = Qt::UserRole - 2,
0042         FilePermissions = Qt::UserRole - 1,
0043         )
0044 
0045         QT6_ONLY(
0046         FilePathRole = Qt::UserRole + 1,
0047         FileNameRole = Qt::UserRole + 2,
0048         FilePermissions = Qt::UserRole + 3,
0049         )
0050     };
0051 
0052     enum Option
0053     {
0054         DontWatchForChanges         = 0x00000001,
0055         DontResolveSymlinks         = 0x00000002,
0056         DontUseCustomDirectoryIcons = 0x00000004
0057     };
0058     Q_ENUM(Option)
0059     Q_DECLARE_FLAGS(Options, Option)
0060 
0061     explicit QFileSystemModel(QObject *parent = nullptr);
0062     ~QFileSystemModel();
0063 
0064     QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
0065     QModelIndex index(const QString &path, int column = 0) const;
0066     QModelIndex parent(const QModelIndex &child) const override;
0067     using QObject::parent;
0068     QModelIndex sibling(int row, int column, const QModelIndex &idx) const override;
0069     bool hasChildren(const QModelIndex &parent = QModelIndex()) const override;
0070     bool canFetchMore(const QModelIndex &parent) const override;
0071     void fetchMore(const QModelIndex &parent) override;
0072 
0073     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0074     int columnCount(const QModelIndex &parent = QModelIndex()) const override;
0075 
0076     QVariant myComputer(int role = Qt::DisplayRole) const;
0077     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0078     bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
0079 
0080     QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
0081 
0082     Qt::ItemFlags flags(const QModelIndex &index) const override;
0083 
0084     void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override;
0085 
0086     QStringList mimeTypes() const override;
0087     QMimeData *mimeData(const QModelIndexList &indexes) const override;
0088     bool dropMimeData(const QMimeData *data, Qt::DropAction action,
0089                       int row, int column, const QModelIndex &parent) override;
0090     Qt::DropActions supportedDropActions() const override;
0091     QHash<int, QByteArray> roleNames() const override;
0092 
0093     // QFileSystemModel specific API
0094     QModelIndex setRootPath(const QString &path);
0095     QString rootPath() const;
0096     QDir rootDirectory() const;
0097 
0098     void setIconProvider(QAbstractFileIconProvider *provider);
0099     QAbstractFileIconProvider *iconProvider() const;
0100 
0101     void setFilter(QDir::Filters filters);
0102     QDir::Filters filter() const;
0103 
0104     void setResolveSymlinks(bool enable);
0105     bool resolveSymlinks() const;
0106 
0107     void setReadOnly(bool enable);
0108     bool isReadOnly() const;
0109 
0110     void setNameFilterDisables(bool enable);
0111     bool nameFilterDisables() const;
0112 
0113     void setNameFilters(const QStringList &filters);
0114     QStringList nameFilters() const;
0115 
0116     void setOption(Option option, bool on = true);
0117     bool testOption(Option option) const;
0118     void setOptions(Options options);
0119     Options options() const;
0120 
0121     QString filePath(const QModelIndex &index) const;
0122     bool isDir(const QModelIndex &index) const;
0123     qint64 size(const QModelIndex &index) const;
0124     QString type(const QModelIndex &index) const;
0125 
0126     QDateTime lastModified(const QModelIndex &index) const;
0127     QDateTime lastModified(const QModelIndex &index, const QTimeZone &tz) const;
0128 
0129     QModelIndex mkdir(const QModelIndex &parent, const QString &name);
0130     bool rmdir(const QModelIndex &index);
0131     inline QString fileName(const QModelIndex &index) const;
0132     inline QIcon fileIcon(const QModelIndex &index) const;
0133     QFile::Permissions permissions(const QModelIndex &index) const;
0134     QFileInfo fileInfo(const QModelIndex &index) const;
0135     bool remove(const QModelIndex &index);
0136 
0137 protected:
0138     QFileSystemModel(QFileSystemModelPrivate &, QObject *parent = nullptr);
0139     void timerEvent(QTimerEvent *event) override;
0140     bool event(QEvent *event) override;
0141 
0142 private:
0143     Q_DECLARE_PRIVATE(QFileSystemModel)
0144     Q_DISABLE_COPY(QFileSystemModel)
0145 
0146     friend class QFileDialogPrivate;
0147 };
0148 
0149 inline QString QFileSystemModel::fileName(const QModelIndex &aindex) const
0150 {
0151     return aindex.data(FileNameRole).toString();
0152 }
0153 inline QIcon QFileSystemModel::fileIcon(const QModelIndex &aindex) const
0154 { return qvariant_cast<QIcon>(aindex.data(Qt::DecorationRole)); }
0155 
0156 Q_DECLARE_OPERATORS_FOR_FLAGS(QFileSystemModel::Options)
0157 
0158 QT_END_NAMESPACE
0159 
0160 #endif // QFILESYSTEMMODEL_H