Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions |

# QDirModel Class Reference

The QDirModel class provides a data model for the local filesystem. More...

    #include <QDirModel>

Inherits QAbstractItemModel.

- List of all members, including inherited members

### Writable Properties

- readOnly : bool
- resolveSymlinks : bool

- 1 writable property inherited from QObject

### Public Functions

- QDirModel ( const QString & path = QString::null, const QStringList & nameFilters = QStringList(), QDir::Filters filters = QDir::NoFilter, QDir::SortFlags sort = QDir::NoSort, QObject * parent = 0 )
- QDirModel ( const QDir & directory, QObject * parent = 0 )
- ~QDirModel ()
- virtual int columnCount ( const QModelIndex & parent ) const
- virtual QVariant data ( const QModelIndex & index, int role = QAbstractItemModel::DisplayRole ) const
- virtual bool dropMimeData ( const QMimeData * data, QDrag::DropAction action, int row, const QModelIndex & parent )
- QFileInfo fileInfo ( const QModelIndex & index ) const
- QDir::Filters filter () const
- virtual QAbstractItemModel::ItemFlags flags ( const QModelIndex & index ) const
- virtual bool hasChildren ( const QModelIndex & parent ) const
- virtual QVariant headerData ( int section, Qt::Orientation orientation, int role ) const
- QIcon icon ( const QModelIndex & index ) const
- QFileIconProvider * iconProvider () const
- virtual QModelIndex index ( int row, int column, const QModelIndex & parent = QModelIndex() ) const
- QModelIndex index ( const QString & path, int column = 0 ) const
- bool isDir ( const QModelIndex & index ) const
- virtual QMimeData * mimeData ( const QModelIndexList & indexes ) const
- virtual QStringList mimeTypes () const
- QModelIndex mkdir ( const QModelIndex & parent, const QString & name )
- QString name ( const QModelIndex & index ) const
- QStringList nameFilters () const
- virtual QModelIndex parent ( const QModelIndex & child ) const
- QString path ( const QModelIndex & index ) const
- void refresh ( const QModelIndex & parent = QModelIndex() )
- bool remove ( const QModelIndex & index )
- bool rmdir ( const QModelIndex & index )
- virtual int rowCount ( const QModelIndex & parent ) const
- virtual bool setData ( const QModelIndex & index, const QVariant & value, int role )
- void setFilter ( QDir::Filters filters )
- void setIconProvider ( QFileIconProvider * provider )
- void setNameFilters ( const QStringList & filters )
- void setSorting ( QDir::SortFlags sort )
- virtual void sort ( int column, Qt::SortOrder order )
- QDir::SortFlags sorting () const
- virtual QDrag::DropActions supportedDropActions () const

- 31 public functions inherited from QAbstractItemModel
- 26 public functions inherited from QObject

### Public Slots

- 2 public slots inherited from QAbstractItemModel
- 1 public slot inherited from QObject

### Signals

- 6 signals inherited from QAbstractItemModel
- 1 signal inherited from QObject

### Static Public Members

- 4 static public members inherited from QObject

### Protected Functions

- 1 protected function inherited from QAbstractItemModel
- 7 protected functions inherited from QObject

## Detailed Description

The QDirModel 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 filer.

QDirModel does not store file information internally or cache file data.

A directory model that displays the contents of a default directory is constructed with a QDir to supply the file infomation, and a parent object:

        QDirModel *model = new QDirModel(QDir(), parent);

A tree view can be used to display the contents of the model:

        QTreeView *treeView = new QTreeView(window);
        treeView->setModel(model);

QDirModel 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(), name(), and path() functions provide information about the underlying files and directories related to items in the model. Directories can be created and removed using mkdir(), rmdir(), and the model will be automatically updated to take the changes into account.

See also nameFilters(), setFilter(), filter(), Model/View Programming, QListView, and QTreeView.

## Property Documentation

### readOnly : bool

`\bried`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 )

### resolveSymlinks : bool

This property holds whether the directory model should resolve symbolic links.

This is only relevant on operating systems that support symbolic links.

Access functions:

- bool resolveSymlinks () const
- void setResolveSymlinks ( bool enable )

## Member Function Documentation

### QDirModel::QDirModel ( const QString & path = QString::null, const QStringList & nameFilters = QStringList(), QDir::Filters filters = QDir::NoFilter, QDir::SortFlags sort = QDir::NoSort, QObject * parent = 0 )

Constructs a new directory model with the given parent. The model initially contains information about the directory specified by path. Only those files matching the nameFilters and the filter are included in the model. The sort order is given by sorting.

### QDirModel::QDirModel ( const QDir & directory, QObject * parent = 0 )

Constructs a directory model of the directory with a parent object.

### QDirModel::~QDirModel ()

Destroys this directory model.

### int QDirModel::columnCount ( const QModelIndex & parent ) const `[virtual]`

Returns the number of columns in the parent model item.

Reimplemented from QAbstractItemModel.

### QVariant QDirModel::data ( const QModelIndex & index, int role = QAbstractItemModel::DisplayRole ) const `[virtual]`

Returns the data for the model item index with the given role.

Reimplemented from QAbstractItemModel.

### bool QDirModel::dropMimeData ( const QMimeData * data, QDrag::DropAction action, int row, const QModelIndex & parent ) `[virtual]`

Returns true if this directory model (whose parent is parent), can decode drop event e.

Reimplemented from QAbstractItemModel.

### QFileInfo QDirModel::fileInfo ( const QModelIndex & index ) const

Returns the file information for the model item index.

### QDir::Filters QDirModel::filter () const

Returns the filter specification for the directory model.

See also QDir::Filters.

### QAbstractItemModel::ItemFlags QDirModel::flags ( const QModelIndex & index ) const `[virtual]`

###

Reimplemented from QAbstractItemModel.

### bool QDirModel::hasChildren ( const QModelIndex & parent ) const `[virtual]`

Returns true if the parent model item has children; otherwise returns false.

Reimplemented from QAbstractItemModel.

### QVariant QDirModel::headerData ( int section, Qt::Orientation orientation, int role ) const `[virtual]`

Returns the data for the header section section, role role.

Reimplemented from QAbstractItemModel.

### QIcon QDirModel::icon ( const QModelIndex & index ) const

Returns the icons for the item stored in the model under the given index.

### QFileIconProvider * QDirModel::iconProvider () const

Returns the file icon provider for this directory model.

### QModelIndex QDirModel::index ( int row, int column, const QModelIndex & parent = QModelIndex() ) const `[virtual]`

Returns the model item index for the item in the parent with the given row and column.

Reimplemented from QAbstractItemModel.

### QModelIndex QDirModel::index ( const QString & path, int column = 0 ) const

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Returns the model item index for the given path.

### bool QDirModel::isDir ( const QModelIndex & index ) const

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

### QMimeData * QDirModel::mimeData ( const QModelIndexList & indexes ) const `[virtual]`

Reimplemented from QAbstractItemModel.

### QStringList QDirModel::mimeTypes () const `[virtual]`

Reimplemented from QAbstractItemModel.

### QModelIndex QDirModel::mkdir ( const QModelIndex & parent, const QString & name )

Create a directory with the name in the parent model item.

### QString QDirModel::name ( const QModelIndex & index ) const

Returns the name of the item stored in the model under the index given.

### QStringList QDirModel::nameFilters () const

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

### QModelIndex QDirModel::parent ( const QModelIndex & child ) const `[virtual]`

Return the parent of the given child model item.

Reimplemented from QAbstractItemModel.

### QString QDirModel::path ( const QModelIndex & index ) const

Returns the path of the item stored in the model under the index given.

### void QDirModel::refresh ( const QModelIndex & parent = QModelIndex() )

Refreshes (rereads) the children of parent.

### bool QDirModel::remove ( const QModelIndex & index )

Removes the model item index from the directory model, returning true if successful. If the item cannot be removed, false is returned.

### bool QDirModel::rmdir ( const QModelIndex & index )

Removes the directory corresponding to the model item index in the directory model, returning true if successful. If the directory cannot be removed, false is returned.

### int QDirModel::rowCount ( const QModelIndex & parent ) const `[virtual]`

Returns the number of rows in the parent model item.

Reimplemented from QAbstractItemModel.

### bool QDirModel::setData ( const QModelIndex & index, const QVariant & value, int role ) `[virtual]`

Sets the data for the model item index with the given role to the data referenced by the value. Returns true if successful; otherwise returns false.

Reimplemented from QAbstractItemModel.

### void QDirModel::setFilter ( QDir::Filters filters )

Sets the directory model's filter to that specified by spec.

See also QDir::Filters.

### void QDirModel::setIconProvider ( QFileIconProvider * provider )

Sets the provider of file icons for the directory model.

### void QDirModel::setNameFilters ( const QStringList & filters )

Sets the name filters for the directory model.

### void QDirModel::setSorting ( QDir::SortFlags sort )

Sets the directory model's sorting order to that specified by spec.

See also QDir::SortFlags.

### void QDirModel::sort ( int column, Qt::SortOrder order ) `[virtual]`

Sort the model items in the column using the order given. The order is a value defined in Qt::SortOrder.

Reimplemented from QAbstractItemModel.

### QDir::SortFlags QDirModel::sorting () const

Returns the sorting method used for the directory model.

See also QDir::SortFlags.

### QDrag::DropActions QDirModel::supportedDropActions () const `[virtual]`

Reimplemented from QAbstractItemModel.