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

- resolveSymlinks : bool

- 1 writable property inherited from QObject

### Public Functions

- QDirModel ( const QString & path = QString::null, const QStringList & nameFilters = QStringList(), int filter = QDir::DefaultFilter, int sorting = QDir::DefaultSort, QObject * parent = 0 )
- QDirModel ( const QDir & directory, QObject * parent = 0 )
- ~QDirModel ()
- virtual bool canDecode ( QMimeSource * source ) const
- virtual int columnCount ( const QModelIndex & parent ) const
- virtual QVariant data ( const QModelIndex & index, int role = QAbstractItemModel::DisplayRole ) const
- virtual bool decode ( QDropEvent * e, const QModelIndex & parent )
- virtual QDragObject * dragObject ( const QModelIndexList & indexes, QWidget * dragSource )
- virtual bool equal ( const QModelIndex & first, const QModelIndex & second ) const
- QFileInfo fileInfo ( const QModelIndex & index ) const
- QDir::FilterSpec 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::Null ) const
- QModelIndex index ( const QString & path ) const
- bool isDir ( const QModelIndex & index ) const
- bool isEditable ( const QModelIndex & index ) const
- virtual bool isSortable () const
- virtual bool lessThan ( const QModelIndex & first, const QModelIndex & second ) 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::Null )
- bool remove ( const QModelIndex & index )
- bool rmdir ( const QModelIndex & index )
- virtual int rowCount ( const QModelIndex & parent ) const
- virtual bool setData ( const QModelIndex & index, int role, const QVariant & value )
- void setFilter ( int spec )
- void setIconProvider ( QFileIconProvider * provider )
- void setNameFilters ( const QStringList & filters )
- void setSorting ( int spec )
- virtual void sort ( int column, const QModelIndex & parent, Qt::SortOrder order )
- QDir::SortSpec sorting () const

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

### Public Slots

- 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
- 9 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.

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

### 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(), int filter = QDir::DefaultFilter, int sorting = QDir::DefaultSort, 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.

### bool QDirModel::canDecode ( QMimeSource * source ) const `[virtual]`

Returns true if the directory model can decode the source information; otherwise returns false.

Reimplemented from QAbstractItemModel.

### 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::decode ( QDropEvent * e, const QModelIndex & parent ) `[virtual]`

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

Reimplemented from QAbstractItemModel.

### QDragObject * QDirModel::dragObject ( const QModelIndexList & indexes, QWidget * dragSource ) `[virtual]`

Returns the drag object for the list of model item indexes originally dragged from the dragSource widget.

Reimplemented from QAbstractItemModel.

### bool QDirModel::equal ( const QModelIndex & first, const QModelIndex & second ) const `[virtual]`

Returns true if the first model index is equal to the second index given.

Reimplemented from QAbstractItemModel.

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

Returns the file information for the model item index.

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

Returns the filter specification for the directory model.

See also QDir::FilterSpec.

### 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::Null ) 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 ) 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.

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

Returns true if the model item index in the directory model is editable; otherwise returns false.

### bool QDirModel::isSortable () const `[virtual]`

Returns true if the items in the directory model can be sorted; otherwise returns false.

Reimplemented from QAbstractItemModel.

### bool QDirModel::lessThan ( const QModelIndex & first, const QModelIndex & second ) const `[virtual]`

Returns true if the first model item is less than the second item given.

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::Null )

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, int role, const QVariant & value ) `[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 ( int spec )

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

See also QDir::FilterSpec.

### 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 ( int spec )

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

See also QDir::SortSpec.

### void QDirModel::sort ( int column, const QModelIndex & parent, 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::SortSpec QDirModel::sorting () const

Returns the sorting method used for the directory model.

See also QDir::SortSpec.