QtBase
v6.3.1
|
The QFileSystemModel class provides a data model for the local filesystem. More...
#include <qfilesystemmodel.h>
Public Types | |
enum | Roles { FileIconRole = Qt::DecorationRole , FilePathRole = Qt::UserRole + 1 , FileNameRole = Qt::UserRole + 2 , FilePermissions = Qt::UserRole + 3 } |
enum | Option { DontWatchForChanges = 0x00000001 , DontResolveSymlinks = 0x00000002 , DontUseCustomDirectoryIcons = 0x00000004 } |
Public Types inherited from QAbstractItemModel | |
enum | LayoutChangeHint { NoLayoutChangeHint , VerticalSortHint , HorizontalSortHint } |
enum class | CheckIndexOption { NoOption = 0x0000 , IndexIsValid = 0x0001 , DoNotUseParent = 0x0002 , ParentIsInvalid = 0x0004 } |
Properties | |
bool | resolveSymlinks |
Whether the directory model should resolve symbolic links. More... | |
bool | readOnly |
Whether the directory model allows writing to the file system. More... | |
bool | nameFilterDisables |
Whether files that don't pass the name filter are hidden or disabled. More... | |
Options | options |
the various options that affect the model More... | |
Properties inherited from QObject | |
QString | objectName |
the name of this object More... | |
The QFileSystemModel class provides a data model for the local filesystem.
\inmodule QtGui
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 by QAbstractItemModel, but it also provides some convenience functions that are specific to a directory model. The fileInfo(), isDir(), fileName() and filePath() functions provide information about the underlying files and directories related to items in the model. Directories can be created and removed using mkdir(), rmdir().
Definition at line 58 of file qfilesystemmodel.h.
\value DontWatchForChanges Do not add file watchers to the paths. This reduces overhead when using the model for simple tasks like line edit completion.
\value DontResolveSymlinks Don't resolve symlinks in the file system model. By default, symlinks are resolved.
\value DontUseCustomDirectoryIcons Always use the default directory icon. Some platforms allow the user to set a different icon. Custom icon lookup causes a big performance impact over network or removable drives. This sets the QFileIconProvider::DontUseCustomDirectoryIcons option in the icon provider accordingly.
Enumerator | |
---|---|
DontWatchForChanges | |
DontResolveSymlinks | |
DontUseCustomDirectoryIcons |
Definition at line 79 of file qfilesystemmodel.h.
\value FileIconRole \value FilePathRole \value FileNameRole \value FilePermissions
Enumerator | |
---|---|
FileIconRole | |
FilePathRole | |
FileNameRole | |
FilePermissions |
Definition at line 72 of file qfilesystemmodel.h.
Constructs a file system model with the given parent.
Definition at line 227 of file qfilesystemmodel.cpp.
|
default |
Destroys this file system model.
|
protected |
Definition at line 235 of file qfilesystemmodel.cpp.
|
overridevirtual |
\reimp
Reimplemented from QAbstractItemModel.
Definition at line 641 of file qfilesystemmodel.cpp.
|
overridevirtual |
\reimp
Implements QAbstractItemModel.
Definition at line 686 of file qfilesystemmodel.cpp.
|
overridevirtual |
\reimp
Implements QAbstractItemModel.
Definition at line 715 of file qfilesystemmodel.cpp.
This signal is emitted when the gatherer thread has finished to load the path.
|
overridevirtual |
Handles the data supplied by a drag and drop operation that ended with the given action over the row in the model specified by the row and column and by the parent index. Returns true if the operation was successful.
Reimplemented from QAbstractItemModel.
Definition at line 1206 of file qfilesystemmodel.cpp.
|
overrideprotectedvirtual |
\reimp
Reimplemented from QObject.
Definition at line 1744 of file qfilesystemmodel.cpp.
|
overridevirtual |
\reimp
Reimplemented from QAbstractItemModel.
Definition at line 653 of file qfilesystemmodel.cpp.
|
inline |
Returns the icon for the item stored in the model under the given index.
Definition at line 183 of file qfilesystemmodel.h.
QFileInfo QFileSystemModel::fileInfo | ( | const QModelIndex & | index | ) | const |
Returns the QFileInfo for the item stored in the model under the given index.
Definition at line 164 of file qfilesystemmodel.cpp.
|
inline |
Returns the file name for the item stored in the model under the given index.
Definition at line 181 of file qfilesystemmodel.h.
QString QFileSystemModel::filePath | ( | const QModelIndex & | index | ) | const |
Returns the path of the item stored in the model under the index given.
Definition at line 1373 of file qfilesystemmodel.cpp.
|
signal |
This signal is emitted whenever a file with the oldName is successfully renamed to newName. The file is located in in the directory path.
QDir::Filters QFileSystemModel::filter | ( | ) | const |
Returns the filter specified for the directory model.
If a filter has not been set, the default filter is QDir::AllEntries | QDir::NoDotAndDotDot | QDir::AllDirs.
Definition at line 1614 of file qfilesystemmodel.cpp.
|
overridevirtual |
\reimp
Reimplemented from QAbstractItemModel.
Definition at line 975 of file qfilesystemmodel.cpp.
|
overridevirtual |
\reimp
Reimplemented from QAbstractItemModel.
Definition at line 624 of file qfilesystemmodel.cpp.
|
overridevirtual |
\reimp
Reimplemented from QAbstractItemModel.
Definition at line 929 of file qfilesystemmodel.cpp.
QAbstractFileIconProvider * QFileSystemModel::iconProvider | ( | ) | const |
Returns the file icon provider for this directory model.
Definition at line 1574 of file qfilesystemmodel.cpp.
QModelIndex QFileSystemModel::index | ( | const QString & | path, |
int | column = 0 |
||
) | const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Returns the model item index for the given path and column.
Definition at line 292 of file qfilesystemmodel.cpp.
|
overridevirtual |
\reimp
Implements QAbstractItemModel.
Definition at line 250 of file qfilesystemmodel.cpp.
bool QFileSystemModel::isDir | ( | const QModelIndex & | index | ) | const |
Returns true
if the model item index represents a directory; otherwise returns false
.
Definition at line 531 of file qfilesystemmodel.cpp.
bool QFileSystemModel::isReadOnly | ( | ) | const |
QDateTime QFileSystemModel::lastModified | ( | const QModelIndex & | index | ) | const |
Returns the date and time when index was last modified.
Definition at line 568 of file qfilesystemmodel.cpp.
|
overridevirtual |
Returns an object that contains a serialized description of the specified indexes. The format used to describe the items corresponding to the indexes is obtained from the mimeTypes() function.
If the list of indexes is empty, \nullptr is returned rather than a serialized empty list.
Reimplemented from QAbstractItemModel.
Definition at line 1186 of file qfilesystemmodel.cpp.
|
overridevirtual |
Returns a list of MIME types that can be used to describe a list of items in the model.
Reimplemented from QAbstractItemModel.
Definition at line 1173 of file qfilesystemmodel.cpp.
QModelIndex QFileSystemModel::mkdir | ( | const QModelIndex & | parent, |
const QString & | name | ||
) |
Create a directory with the name in the parent model index.
Definition at line 1428 of file qfilesystemmodel.cpp.
QVariant QFileSystemModel::myComputer | ( | int | role = Qt::DisplayRole | ) | const |
Returns the data stored under the given role for the item "My Computer".
Definition at line 696 of file qfilesystemmodel.cpp.
bool QFileSystemModel::nameFilterDisables | ( | ) | const |
Definition at line 1687 of file qfilesystemmodel.cpp.
QStringList QFileSystemModel::nameFilters | ( | ) | const |
Returns a list of filters applied to the names in the model.
Definition at line 1731 of file qfilesystemmodel.cpp.
QFileSystemModel::Options QFileSystemModel::options | ( | ) | const |
Definition at line 1352 of file qfilesystemmodel.cpp.
|
inline |
Returns a pointer to the parent object.
Definition at line 409 of file qobject.h.
|
overridevirtual |
\reimp
Implements QAbstractItemModel.
Definition at line 579 of file qfilesystemmodel.cpp.
QFile::Permissions QFileSystemModel::permissions | ( | const QModelIndex & | index | ) | const |
Returns the complete OR-ed together combination of QFile::Permission for the index.
Definition at line 1451 of file qfilesystemmodel.cpp.
bool QFileSystemModel::remove | ( | const QModelIndex & | index | ) |
Removes the model item index from the file system model and {deletes the corresponding file from the file system}, returning true if successful. If the item cannot be removed, false is returned.
Definition at line 204 of file qfilesystemmodel.cpp.
bool QFileSystemModel::resolveSymlinks | ( | ) | const |
Definition at line 1640 of file qfilesystemmodel.cpp.
bool QFileSystemModel::rmdir | ( | const QModelIndex & | index | ) |
Removes the directory corresponding to the model item index in the file system model and {deletes the corresponding directory from the file system}, returning true if successful. If the directory cannot be removed, false is returned.
Definition at line 1756 of file qfilesystemmodel.cpp.
|
overridevirtual |
\reimp
Reimplemented from QAbstractItemModel.
Definition at line 1257 of file qfilesystemmodel.cpp.
QDir QFileSystemModel::rootDirectory | ( | ) | const |
The currently set directory
Definition at line 1550 of file qfilesystemmodel.cpp.
QString QFileSystemModel::rootPath | ( | ) | const |
The currently set root path
Definition at line 1539 of file qfilesystemmodel.cpp.
This signal is emitted whenever the root path has been changed to a newPath.
|
overridevirtual |
\reimp
Implements QAbstractItemModel.
Definition at line 670 of file qfilesystemmodel.cpp.
|
overridevirtual |
\reimp
Reimplemented from QAbstractItemModel.
Definition at line 864 of file qfilesystemmodel.cpp.
void QFileSystemModel::setFilter | ( | QDir::Filters | filters | ) |
Sets the directory model's filter to that specified by filters.
Note that the filter you set should always include the QDir::AllDirs enum value, otherwise QFileSystemModel won't be able to read the directory structure.
Definition at line 1592 of file qfilesystemmodel.cpp.
void QFileSystemModel::setIconProvider | ( | QAbstractFileIconProvider * | provider | ) |
Sets the provider of file icons for the directory model.
Definition at line 1562 of file qfilesystemmodel.cpp.
void QFileSystemModel::setNameFilterDisables | ( | bool | enable | ) |
void QFileSystemModel::setNameFilters | ( | const QStringList & | filters | ) |
Sets the name filters to apply against the existing files.
Definition at line 1696 of file qfilesystemmodel.cpp.
Options should be set before changing properties.
Definition at line 1297 of file qfilesystemmodel.cpp.
void QFileSystemModel::setReadOnly | ( | bool | enable | ) |
void QFileSystemModel::setResolveSymlinks | ( | bool | enable | ) |
QModelIndex QFileSystemModel::setRootPath | ( | const QString & | newPath | ) |
Sets the directory that is being watched by the model to newPath by installing a \l{QFileSystemWatcher}{file system watcher} on it. Any changes to files and directories within this directory will be reflected in the model.
If the path is changed, the rootPathChanged() signal will be emitted.
Definition at line 1470 of file qfilesystemmodel.cpp.
|
overridevirtual |
\reimp
Reimplemented from QAbstractItemModel.
Definition at line 275 of file qfilesystemmodel.cpp.
qint64 QFileSystemModel::size | ( | const QModelIndex & | index | ) | const |
Returns the size in bytes of index. If the file does not exist, 0 is returned.
Definition at line 546 of file qfilesystemmodel.cpp.
|
overridevirtual |
\reimp
Reimplemented from QAbstractItemModel.
Definition at line 1133 of file qfilesystemmodel.cpp.
|
overridevirtual |
bool QFileSystemModel::testOption | ( | Option | option | ) | const |
Returns true
if the given option is enabled; otherwise, returns false.
Definition at line 1311 of file qfilesystemmodel.cpp.
|
overrideprotectedvirtual |
\reimp
Reimplemented from QObject.
Definition at line 507 of file qfilesystemmodel.cpp.
QString QFileSystemModel::type | ( | const QModelIndex & | index | ) | const |
Returns the type of file index such as "Directory" or "JPEG file".
Definition at line 557 of file qfilesystemmodel.cpp.
|
readwrite |
Whether files that don't pass the name filter are hidden or disabled.
This property is true
by default
Definition at line 188 of file qfilesystemmodel.h.
|
readwrite |
the various options that affect the model
By default, all options are disabled.
Options should be set before changing properties.
Definition at line 188 of file qfilesystemmodel.h.
|
readwrite |
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
Definition at line 188 of file qfilesystemmodel.h.
|
readwrite |
Whether the directory model should resolve symbolic links.
This is only relevant on Windows.
By default, this property is true
.
Definition at line 188 of file qfilesystemmodel.h.