Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

QFileSystemModel Class

TheQFileSystemModel class provides a data model for the local filesystem.More...

Header:#include <QFileSystemModel>
Since: Qt 4.4
Inherits:QAbstractItemModel

Public Types

enumRoles { FileIconRole, FilePathRole, FileNameRole, FilePermissions }

Properties

Public Functions

QFileSystemModel(QObject * parent = 0)
~QFileSystemModel()
QIconfileIcon(const QModelIndex & index) const
QFileInfofileInfo(const QModelIndex & index) const
QStringfileName(const QModelIndex & index) const
QStringfilePath(const QModelIndex & index) const
QDir::Filtersfilter() const
QFileIconProvider *iconProvider() const
QModelIndexindex(const QString & path, int column = 0) const
boolisDir(const QModelIndex & index) const
boolisReadOnly() const
QDateTimelastModified(const QModelIndex & index) const
QModelIndexmkdir(const QModelIndex & parent, const QString & name)
QVariantmyComputer(int role = Qt::DisplayRole) const
boolnameFilterDisables() const
QStringListnameFilters() const
QFile::Permissionspermissions(const QModelIndex & index) const
boolremove(const QModelIndex & index) const
boolresolveSymlinks() const
boolrmdir(const QModelIndex & index) const
QDirrootDirectory() const
QStringrootPath() const
voidsetFilter(QDir::Filters filters)
voidsetIconProvider(QFileIconProvider * provider)
voidsetNameFilterDisables(bool enable)
voidsetNameFilters(const QStringList & filters)
voidsetReadOnly(bool enable)
voidsetResolveSymlinks(bool enable)
QModelIndexsetRootPath(const QString & newPath)
qint64size(const QModelIndex & index) const
QStringtype(const QModelIndex & index) const

Reimplemented Public Functions

virtual boolcanFetchMore(const QModelIndex & parent) const
virtual intcolumnCount(const QModelIndex & parent = QModelIndex()) const
virtual QVariantdata(const QModelIndex & index, int role = Qt::DisplayRole) const
virtual booldropMimeData(const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex & parent)
virtual voidfetchMore(const QModelIndex & parent)
virtual Qt::ItemFlagsflags(const QModelIndex & index) const
virtual boolhasChildren(const QModelIndex & parent = QModelIndex()) const
virtual QVariantheaderData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const
virtual QModelIndexindex(int row, int column, const QModelIndex & parent = QModelIndex()) const
virtual QMimeData *mimeData(const QModelIndexList & indexes) const
virtual QStringListmimeTypes() const
virtual QModelIndexparent(const QModelIndex & index) const
virtual introwCount(const QModelIndex & parent = QModelIndex()) const
virtual boolsetData(const QModelIndex & idx, const QVariant & value, int role = Qt::EditRole)
virtual voidsort(int column, Qt::SortOrder order = Qt::AscendingOrder)
virtual Qt::DropActionssupportedDropActions() const

Signals

voiddirectoryLoaded(const QString & path)
voidfileRenamed(const QString & path, const QString & oldName, const QString & newName)
voidrootPathChanged(const QString & newPath)

Reimplemented Protected Functions

virtual boolevent(QEvent * event)
virtual voidtimerEvent(QTimerEvent * event)

Additional Inherited Members

Detailed Description

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.

Example Usage

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

QTreeView*tree=newQTreeView(splitter);    tree->setModel(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.

Caching and Performance

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.

Member Type Documentation

enum QFileSystemModel::Roles

ConstantValue
QFileSystemModel::FileIconRoleQt::DecorationRole
QFileSystemModel::FilePathRoleQt::UserRole + 1
QFileSystemModel::FileNameRoleQt::UserRole + 2
QFileSystemModel::FilePermissionsQt::UserRole + 3

Property Documentation

nameFilterDisables :bool

This property holds whether files that don't pass the name filter are hidden or disabled.

This property is true by default

Access functions:

boolnameFilterDisables() const
voidsetNameFilterDisables(bool enable)

readOnly :bool

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:

boolisReadOnly() const
voidsetReadOnly(bool enable)

resolveSymlinks :bool

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:

boolresolveSymlinks() const
voidsetResolveSymlinks(bool enable)

Member Function Documentation

QFileSystemModel::QFileSystemModel(QObject * parent = 0)

Constructs a file system model with the givenparent.

QFileSystemModel::~QFileSystemModel()

Destroys this file system model.

[virtual]bool QFileSystemModel::canFetchMore(constQModelIndex & parent) const

Reimplemented fromQAbstractItemModel::canFetchMore().

[virtual]int QFileSystemModel::columnCount(constQModelIndex & parent = QModelIndex()) const

Reimplemented fromQAbstractItemModel::columnCount().

[virtual]QVariant QFileSystemModel::data(constQModelIndex & index,int role = Qt::DisplayRole) const

Reimplemented 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().

QIcon QFileSystemModel::fileIcon(constQModelIndex & index) const

Returns the icon for the item stored in the model under the givenindex.

QFileInfo QFileSystemModel::fileInfo(constQModelIndex & index) const

Returns theQFileInfo for the item stored in the model under the givenindex.

QString QFileSystemModel::fileName(constQModelIndex & index) const

Returns the file name for the item stored in the model under the givenindex.

QString QFileSystemModel::filePath(constQModelIndex & index) const

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.

QDir::Filters QFileSystemModel::filter() const

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) const

Reimplemented fromQAbstractItemModel::flags().

[virtual]bool QFileSystemModel::hasChildren(constQModelIndex & parent = QModelIndex()) const

Reimplemented fromQAbstractItemModel::hasChildren().

[virtual]QVariant QFileSystemModel::headerData(int section,Qt::Orientation orientation,int role = Qt::DisplayRole) const

Reimplemented fromQAbstractItemModel::headerData().

QFileIconProvider * QFileSystemModel::iconProvider() const

Returns the file icon provider for this directory model.

See alsosetIconProvider().

[virtual]QModelIndex QFileSystemModel::index(int row,int column, constQModelIndex & parent = QModelIndex()) const

Reimplemented fromQAbstractItemModel::index().

QModelIndex QFileSystemModel::index(constQString & path,int column = 0) const

This is an overloaded function.

Returns the model item index for the givenpath andcolumn.

bool QFileSystemModel::isDir(constQModelIndex & index) const

Returns true if the model itemindex represents a directory; otherwise returns false.

QDateTime QFileSystemModel::lastModified(constQModelIndex & index) const

Returns the date and time whenindex was last modified.

[virtual]QMimeData * QFileSystemModel::mimeData(constQModelIndexList & indexes) const

Reimplemented 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() const

Reimplemented fromQAbstractItemModel::mimeTypes().

Returns a list of MIME types that can be used to describe a list of items in the model.

QModelIndex QFileSystemModel::mkdir(constQModelIndex & parent, constQString & name)

Create a directory with thename in theparent model index.

QVariant QFileSystemModel::myComputer(int role = Qt::DisplayRole) const

Returns the data stored under the givenrole for the item "My Computer".

See alsoQt::ItemDataRole.

QStringList QFileSystemModel::nameFilters() const

Returns a list of filters applied to the names in the model.

See alsosetNameFilters().

[virtual]QModelIndex QFileSystemModel::parent(constQModelIndex & index) const

Reimplemented fromQAbstractItemModel::parent().

QFile::Permissions QFileSystemModel::permissions(constQModelIndex & index) const

Returns the complete OR-ed together combination ofQFile::Permission for theindex.

bool QFileSystemModel::remove(constQModelIndex & index) const

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().

bool QFileSystemModel::rmdir(constQModelIndex & index) const

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().

QDir QFileSystemModel::rootDirectory() const

The currently set directory

See alsorootPath().

QString QFileSystemModel::rootPath() const

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()) const

Reimplemented fromQAbstractItemModel::rowCount().

[virtual]bool QFileSystemModel::setData(constQModelIndex & idx, constQVariant & value,int role = Qt::EditRole)

Reimplemented fromQAbstractItemModel::setData().

See alsodata().

void QFileSystemModel::setFilter(QDir::Filters filters)

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.

void QFileSystemModel::setIconProvider(QFileIconProvider * provider)

Sets theprovider of file icons for the directory model.

See alsoiconProvider().

void QFileSystemModel::setNameFilters(constQStringList & filters)

Sets the namefilters to apply against the existing files.

See alsonameFilters().

QModelIndex QFileSystemModel::setRootPath(constQString & newPath)

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().

qint64 QFileSystemModel::size(constQModelIndex & index) const

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() const

Reimplemented fromQAbstractItemModel::supportedDropActions().

[virtual protected]void QFileSystemModel::timerEvent(QTimerEvent * event)

Reimplemented fromQObject::timerEvent().

QString QFileSystemModel::type(constQModelIndex & index) const

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.


[8]ページ先頭

©2009-2025 Movatter.jp