
We bake cookies in your browser for a better experience. Using this site means that you consent.Read More
TheQFileSystemModel class provides a data model for the local filesystem.More...
| Header: | #include <QFileSystemModel> |
| Since: | Qt 4.4 |
| Inherits: | QAbstractItemModel |
| enum | Roles { FileIconRole, FilePathRole, FileNameRole, FilePermissions } |
| QFileSystemModel(QObject * parent = 0) | |
| ~QFileSystemModel() | |
| QIcon | fileIcon(const QModelIndex & index) const |
| QFileInfo | fileInfo(const QModelIndex & index) const |
| QString | fileName(const QModelIndex & index) const |
| QString | filePath(const QModelIndex & index) const |
| QDir::Filters | filter() const |
| QFileIconProvider * | iconProvider() const |
| QModelIndex | index(const QString & path, int column = 0) const |
| bool | isDir(const QModelIndex & index) const |
| bool | isReadOnly() const |
| QDateTime | lastModified(const QModelIndex & index) const |
| QModelIndex | mkdir(const QModelIndex & parent, const QString & name) |
| QVariant | myComputer(int role = Qt::DisplayRole) const |
| bool | nameFilterDisables() const |
| QStringList | nameFilters() const |
| QFile::Permissions | permissions(const QModelIndex & index) const |
| bool | remove(const QModelIndex & index) const |
| bool | resolveSymlinks() const |
| bool | rmdir(const QModelIndex & index) const |
| QDir | rootDirectory() const |
| QString | rootPath() const |
| void | setFilter(QDir::Filters filters) |
| void | setIconProvider(QFileIconProvider * provider) |
| void | setNameFilterDisables(bool enable) |
| void | setNameFilters(const QStringList & filters) |
| void | setReadOnly(bool enable) |
| void | setResolveSymlinks(bool enable) |
| QModelIndex | setRootPath(const QString & newPath) |
| qint64 | size(const QModelIndex & index) const |
| QString | type(const QModelIndex & index) const |
| virtual bool | canFetchMore(const QModelIndex & parent) const |
| virtual int | columnCount(const QModelIndex & parent = QModelIndex()) const |
| virtual QVariant | data(const QModelIndex & index, int role = Qt::DisplayRole) const |
| virtual bool | dropMimeData(const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex & parent) |
| virtual void | fetchMore(const QModelIndex & parent) |
| virtual Qt::ItemFlags | flags(const QModelIndex & index) const |
| virtual bool | hasChildren(const QModelIndex & parent = QModelIndex()) const |
| virtual QVariant | headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const |
| virtual QModelIndex | index(int row, int column, const QModelIndex & parent = QModelIndex()) const |
| virtual QMimeData * | mimeData(const QModelIndexList & indexes) const |
| virtual QStringList | mimeTypes() const |
| virtual QModelIndex | parent(const QModelIndex & index) const |
| virtual int | rowCount(const QModelIndex & parent = QModelIndex()) const |
| virtual bool | setData(const QModelIndex & idx, const QVariant & value, int role = Qt::EditRole) |
| virtual void | sort(int column, Qt::SortOrder order = Qt::AscendingOrder) |
| virtual Qt::DropActions | supportedDropActions() const |
| void | directoryLoaded(const QString & path) |
| void | fileRenamed(const QString & path, const QString & oldName, const QString & newName) |
| void | rootPathChanged(const QString & newPath) |
| virtual bool | event(QEvent * event) |
| virtual void | timerEvent(QTimerEvent * event) |
TheQFileSystemModel class provides a data model for the local filesystem.
This class provides access to the local filesystem, providing functions for renaming and removing files and directories, and for creating new directories. In the simplest case, it can be used with a suitable display widget as part of a browser or filter.
QFileSystemModel can be accessed using the standard interface provided byQAbstractItemModel, but it also provides some convenience functions that are specific to a directory model. ThefileInfo(),isDir(),name(), and path() functions provide information about the underlying files and directories related to items in the model. Directories can be created and removed usingmkdir(),rmdir().
Note:QFileSystemModel requires an instance of a GUI application.
A directory model that displays the contents of a default directory is usually constructed with a parent object:
QFileSystemModel*model=newQFileSystemModel; model->setRootPath(QDir::currentPath());
A tree view can be used to display the contents of the model
and the contents of a particular directory can be displayed by setting the tree view's root index:
tree->setRootIndex(model->index(QDir::currentPath()));
The view's root index can be used to control how much of a hierarchical model is displayed. QDirModel provides a convenience function that returns a suitable model index for a path to a directory within the model.
QFileSystemModel will not fetch any files or directories untilsetRootPath() is called. This will prevent any unnecessary querying on the file system until that point such as listing the drives on Windows.
Unlike QDirModel,QFileSystemModel uses a separate thread to populate itself so it will not cause the main thread to hang as the file system is being queried. Calls torowCount() will return 0 until the model populates a directory.
QFileSystemModel keeps a cache with file information. The cache is automatically kept up to date using theQFileSystemWatcher.
See alsoModel Classes.
| Constant | Value |
|---|---|
QFileSystemModel::FileIconRole | Qt::DecorationRole |
QFileSystemModel::FilePathRole | Qt::UserRole + 1 |
QFileSystemModel::FileNameRole | Qt::UserRole + 2 |
QFileSystemModel::FilePermissions | Qt::UserRole + 3 |
This property holds whether files that don't pass the name filter are hidden or disabled.
This property is true by default
Access functions:
| bool | nameFilterDisables() const |
| void | setNameFilterDisables(bool enable) |
This property holds whether the directory model allows writing to the file system.
If this property is set to false, the directory model will allow renaming, copying and deleting of files and directories.
This property is true by default
Access functions:
| bool | isReadOnly() const |
| void | setReadOnly(bool enable) |
This property holds whether the directory model should resolve symbolic links.
This is only relevant on operating systems that support symbolic links.
By default, this property is false.
Access functions:
| bool | resolveSymlinks() const |
| void | setResolveSymlinks(bool enable) |
Constructs a file system model with the givenparent.
Destroys this file system model.
[virtual]bool QFileSystemModel::canFetchMore(constQModelIndex & parent) constReimplemented fromQAbstractItemModel::canFetchMore().
[virtual]int QFileSystemModel::columnCount(constQModelIndex & parent = QModelIndex()) constReimplemented fromQAbstractItemModel::columnCount().
[virtual]QVariant QFileSystemModel::data(constQModelIndex & index,int role = Qt::DisplayRole) constReimplemented fromQAbstractItemModel::data().
See alsosetData().
[signal]void QFileSystemModel::directoryLoaded(constQString & path)This signal is emitted when the gatherer thread has finished to load thepath.
This function was introduced in Qt 4.7.
[virtual]bool QFileSystemModel::dropMimeData(constQMimeData * data,Qt::DropAction action,int row,int column, constQModelIndex & parent)Reimplemented fromQAbstractItemModel::dropMimeData().
Handles thedata supplied by a drag and drop operation that ended with the givenaction over the row in the model specified by therow andcolumn and by theparent index.
See alsosupportedDropActions().
[virtual protected]bool QFileSystemModel::event(QEvent * event)Reimplemented fromQObject::event().
[virtual]void QFileSystemModel::fetchMore(constQModelIndex & parent)Reimplemented fromQAbstractItemModel::fetchMore().
Returns the icon for the item stored in the model under the givenindex.
Returns theQFileInfo for the item stored in the model under the givenindex.
Returns the file name for the item stored in the model under the givenindex.
Returns the path of the item stored in the model under theindex given.
[signal]void QFileSystemModel::fileRenamed(constQString & path, constQString & oldName, constQString & newName)This signal is emitted whenever a file with theoldName is successfully renamed tonewName. The file is located in in the directorypath.
Returns the filter specified for the directory model.
If a filter has not been set, the default filter isQDir::AllEntries |QDir::NoDotAndDotDot |QDir::AllDirs.
See alsosetFilter() andQDir::Filters.
[virtual]Qt::ItemFlags QFileSystemModel::flags(constQModelIndex & index) constReimplemented fromQAbstractItemModel::flags().
[virtual]bool QFileSystemModel::hasChildren(constQModelIndex & parent = QModelIndex()) constReimplemented fromQAbstractItemModel::hasChildren().
[virtual]QVariant QFileSystemModel::headerData(int section,Qt::Orientation orientation,int role = Qt::DisplayRole) constReimplemented fromQAbstractItemModel::headerData().
Returns the file icon provider for this directory model.
See alsosetIconProvider().
[virtual]QModelIndex QFileSystemModel::index(int row,int column, constQModelIndex & parent = QModelIndex()) constReimplemented fromQAbstractItemModel::index().
This is an overloaded function.
Returns the model item index for the givenpath andcolumn.
Returns true if the model itemindex represents a directory; otherwise returns false.
Returns the date and time whenindex was last modified.
[virtual]QMimeData * QFileSystemModel::mimeData(constQModelIndexList & indexes) constReimplemented fromQAbstractItemModel::mimeData().
Returns an object that contains a serialized description of the specifiedindexes. The format used to describe the items corresponding to the indexes is obtained from themimeTypes() function.
If the list of indexes is empty, 0 is returned rather than a serialized empty list.
[virtual]QStringList QFileSystemModel::mimeTypes() constReimplemented fromQAbstractItemModel::mimeTypes().
Returns a list of MIME types that can be used to describe a list of items in the model.
Create a directory with thename in theparent model index.
Returns the data stored under the givenrole for the item "My Computer".
See alsoQt::ItemDataRole.
Returns a list of filters applied to the names in the model.
See alsosetNameFilters().
[virtual]QModelIndex QFileSystemModel::parent(constQModelIndex & index) constReimplemented fromQAbstractItemModel::parent().
Returns the complete OR-ed together combination ofQFile::Permission for theindex.
Removes the model itemindex from the file system model anddeletes the corresponding file from the file system, returning true if successful. If the item cannot be removed, false is returned.
Warning: This function deletes files from the file system; it doesnot move them to a location where they can be recovered.
See alsormdir().
Removes the directory corresponding to the model itemindex in the file system model anddeletes the corresponding directory from the file system, returning true if successful. If the directory cannot be removed, false is returned.
Warning: This function deletes directories from the file system; it doesnot move them to a location where they can be recovered.
See alsoremove().
The currently set directory
See alsorootPath().
The currently set root path
See alsosetRootPath() androotDirectory().
[signal]void QFileSystemModel::rootPathChanged(constQString & newPath)This signal is emitted whenever the root path has been changed to anewPath.
[virtual]int QFileSystemModel::rowCount(constQModelIndex & parent = QModelIndex()) constReimplemented fromQAbstractItemModel::rowCount().
[virtual]bool QFileSystemModel::setData(constQModelIndex & idx, constQVariant & value,int role = Qt::EditRole)Reimplemented fromQAbstractItemModel::setData().
See alsodata().
Sets the directory model's filter to that specified byfilters.
Note that the filter you set should always include theQDir::AllDirs enum value, otherwiseQFileSystemModel won't be able to read the directory structure.
See alsofilter() andQDir::Filters.
Sets theprovider of file icons for the directory model.
See alsoiconProvider().
Sets the namefilters to apply against the existing files.
See alsonameFilters().
Sets the directory that is being watched by the model tonewPath by installing afile system watcher on it. Any changes to files and directories within this directory will be reflected in the model.
If the path is changed, therootPathChanged() signal will be emitted.
Note:This function does not change the structure of the model or modify the data available to views. In other words, the "root" of the model isnot changed to include only files and directories within the directory specified bynewPath in the file system.
See alsorootPath().
Returns the size in bytes ofindex. If the file does not exist, 0 is returned.
[virtual]void QFileSystemModel::sort(int column,Qt::SortOrder order = Qt::AscendingOrder)Reimplemented fromQAbstractItemModel::sort().
[virtual]Qt::DropActions QFileSystemModel::supportedDropActions() constReimplemented fromQAbstractItemModel::supportedDropActions().
[virtual protected]void QFileSystemModel::timerEvent(QTimerEvent * event)Reimplemented fromQObject::timerEvent().
Returns the type of fileindex such as "Directory" or "JPEG file".
© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.