Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:07:58

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