Go to the
documentation of this file.
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #ifndef QFILESYSTEMMODEL_H
00043 #define QFILESYSTEMMODEL_H
00044
00045 #include <QtCore/qabstractitemmodel.h>
00046 #include <QtCore/qpair.h>
00047 #include <QtCore/qdir.h>
00048 #include <QtGui/qicon.h>
00049 #include <QtCore/qdiriterator.h>
00050
00051 QT_BEGIN_HEADER
00052
00053 QT_BEGIN_NAMESPACE
00054
00055 QT_MODULE(Gui)
00056
00057 #ifndef QT_NO_FILESYSTEMMODEL
00058
00059 class ExtendedInformation;
00060 class QFileSystemModelPrivate;
00061 class QFileIconProvider;
00062
00063 class Q_GUI_EXPORT QFileSystemModel : public QAbstractItemModel
00064 {
00065 Q_OBJECT
00066 Q_PROPERTY(bool resolveSymlinks READ resolveSymlinks WRITE setResolveSymlinks)
00067 Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly)
00068 Q_PROPERTY(bool nameFilterDisables READ nameFilterDisables WRITE setNameFilterDisables)
00069
00070 Q_SIGNALS:
00071 void rootPathChanged(const QString &newPath);
00072 void fileRenamed(const QString &path, const QString &oldName, const QString &newName);
00073 void directoryLoaded(const QString &path);
00074
00075 public:
00076 enum Roles {
00077 FileIconRole = Qt::DecorationRole,
00078 FilePathRole = Qt::UserRole + 1,
00079 FileNameRole = Qt::UserRole + 2,
00080 FilePermissions = Qt::UserRole + 3
00081 };
00082
00083 explicit QFileSystemModel(QObject *parent = 0);
00084 ~QFileSystemModel();
00085
00086 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
00087 QModelIndex index(const QString &path, int column = 0) const;
00088 QModelIndex parent(const QModelIndex &child) const;
00089 bool hasChildren(const QModelIndex &parent = QModelIndex()) const;
00090 bool canFetchMore(const QModelIndex &parent) const;
00091 void fetchMore(const QModelIndex &parent);
00092
00093 int rowCount(const QModelIndex &parent = QModelIndex()) const;
00094 int columnCount(const QModelIndex &parent = QModelIndex()) const;
00095
00096 QVariant myComputer(int role = Qt::DisplayRole) const;
00097 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
00098 bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
00099
00100 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
00101
00102 Qt::ItemFlags flags(const QModelIndex &index) const;
00103
00104 void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
00105
00106 QStringList mimeTypes() const;
00107 QMimeData *mimeData(const QModelIndexList &indexes) const;
00108 bool dropMimeData(const QMimeData *data, Qt::DropAction action,
00109 int row, int column, const QModelIndex &parent);
00110 Qt::DropActions supportedDropActions() const;
00111
00112
00113 QModelIndex setRootPath(const QString &path);
00114 QString rootPath() const;
00115 QDir rootDirectory() const;
00116
00117 void setIconProvider(QFileIconProvider *provider);
00118 QFileIconProvider *iconProvider() const;
00119
00120 void setFilter(QDir::Filters filters);
00121 QDir::Filters filter() const;
00122
00123 void setResolveSymlinks(bool enable);
00124 bool resolveSymlinks() const;
00125
00126 void setReadOnly(bool enable);
00127 bool isReadOnly() const;
00128
00129 void setNameFilterDisables(bool enable);
00130 bool nameFilterDisables() const;
00131
00132 void setNameFilters(const QStringList &filters);
00133 QStringList nameFilters() const;
00134
00135 QString filePath(const QModelIndex &index) const;
00136 bool isDir(const QModelIndex &index) const;
00137 qint64 size(const QModelIndex &index) const;
00138 QString type(const QModelIndex &index) const;
00139 QDateTime lastModified(const QModelIndex &index) const;
00140
00141 QModelIndex mkdir(const QModelIndex &parent, const QString &name);
00142 inline bool rmdir(const QModelIndex &index) const;
00143 inline QString fileName(const QModelIndex &index) const;
00144 inline QIcon fileIcon(const QModelIndex &index) const;
00145 QFile::Permissions permissions(const QModelIndex &index) const;
00146 inline QFileInfo fileInfo(const QModelIndex &index) const;
00147 bool remove(const QModelIndex &index) const;
00148
00149 protected:
00150 QFileSystemModel(QFileSystemModelPrivate &, QObject *parent = 0);
00151 void timerEvent(QTimerEvent *event);
00152 bool event(QEvent *event);
00153
00154 private:
00155 Q_DECLARE_PRIVATE(QFileSystemModel)
00156 Q_DISABLE_COPY(QFileSystemModel)
00157
00158 Q_PRIVATE_SLOT(d_func(), void _q_directoryChanged(const QString &directory, const QStringList &list))
00159 Q_PRIVATE_SLOT(d_func(), void _q_performDelayedSort())
00160 Q_PRIVATE_SLOT(d_func(), void _q_fileSystemChanged(const QString &path, const QList<QPair<QString, QFileInfo> > &))
00161 Q_PRIVATE_SLOT(d_func(), void _q_resolvedName(const QString &fileName, const QString &resolvedName))
00162
00163 friend class QFileDialogPrivate;
00164 };
00165
00166 inline bool QFileSystemModel::rmdir(const QModelIndex &aindex) const
00167 { QDir dir; return dir.rmdir(filePath(aindex)); }
00168 inline QString QFileSystemModel::fileName(const QModelIndex &aindex) const
00169 { return aindex.data(Qt::DisplayRole).toString(); }
00170 inline QIcon QFileSystemModel::fileIcon(const QModelIndex &aindex) const
00171 { return qvariant_cast<QIcon>(aindex.data(Qt::DecorationRole)); }
00172 inline QFileInfo QFileSystemModel::fileInfo(const QModelIndex &aindex) const
00173 { return QFileInfo(filePath(aindex)); }
00174
00175 #endif // QT_NO_FILESYSTEMMODEL
00176
00177 QT_END_NAMESPACE
00178
00179 QT_END_HEADER
00180
00181 #endif // QFILESYSTEMMODEL_H
00182