Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.trolltech.qt.gui
Class QDirModel

    java.lang.Object
      com.trolltech.qt.QSignalEmitter
          com.trolltech.qt.QtJambiObject
              com.trolltech.qt.core.QObject
                  com.trolltech.qt.core.QAbstractItemModel
                      com.trolltech.qt.gui.QDirModel

All Implemented Interfaces:
  QtJambiInterface

    public class QDirModel

extends QAbstractItemModel

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` keeps a cache with file information. The cache needs to be updated with `refresh()`.

A directory model that displays the contents of a default directory is usually constructed with a parent object:

        QDirModel model = new QDirModel();

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

        QTreeView tree = new QTreeView(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.

`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()` and `isDir()` 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.

Note:`QDirModel` requires an instance of a GUI application.

See also:
  `nameFilters()`, `setFilter()`, `filter()`, `QListView`, `QTreeView`, Dir View Example, and Model Classes.

Nested Class Summary
`static class` | `QDirModel.Roles`

Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter
`QSignalEmitter.Signal0, QSignalEmitter.Signal1, QSignalEmitter.Signal2, QSignalEmitter.Signal3, QSignalEmitter.Signal4, QSignalEmitter.Signal5, QSignalEmitter.Signal6, QSignalEmitter.Signal7, QSignalEmitter.Signal8, QSignalEmitter.Signal9`

Field Summary

Fields inherited from class com.trolltech.qt.core.QAbstractItemModel
`dataChanged, headerDataChanged, layoutAboutToBeChanged, layoutChanged`

Constructor Summary
`QDirModel()` Constructs a directory model with the given `parent`.
`QDirModel(java.util.List nameFilters, QDir.Filters filters, QDir.SortFlags sort)` Constructs a new directory model with the given `parent`.
`QDirModel(java.util.List nameFilters, QDir.Filters filters, QDir.SortFlags sort, QObject parent)` Constructs a new directory model with the given `parent`.
`QDirModel(QObject parent)` Constructs a directory model with the given `parent`.

Method Summary
`QIcon` | `fileIcon(QModelIndex index)` Returns the icons for the item stored in the model under the given `index`.
`QFileInfo` | `fileInfo(QModelIndex index)` Returns the file information for the specified model `index`.
`java.lang.String` | `fileName(QModelIndex index)` Returns the name of the item stored in the model under the `index` given.
`java.lang.String` | `filePath(QModelIndex index)` Returns the path of the item stored in the model under the `index` given.
`QDir.Filters` | `filter()` Returns the filter specification for the directory model.
`static QDirModel` | `fromNativePointer(QNativePointer nativePointer)` This method returns the QDirModel instance pointed to by `nativePointer`.
`QFileIconProvider` | `iconProvider()` Returns the file icon provider for this directory model.
`QModelIndex` | `index(java.lang.String path)` Returns the model item index for the given `path`.
`QModelIndex` | `index(java.lang.String path, int column)` Returns the model item index for the given `path`.
`boolean` | `isDir(QModelIndex index)` Returns true if the model item `index` represents a directory; otherwise returns false.
`boolean` | `isReadOnly()` This property holds Whether the directory model allows writing to the file system.
`boolean` | `lazyChildCount()` This property holds Whether the directory model optimizes the `hasChildren` function to only check if the item is a directory.
`QModelIndex` | `mkdir(QModelIndex parent, java.lang.String name)` Create a directory with the `name` in the `parent` model item.
`java.util.List` | `nameFilters()` Returns a list of filters applied to the names in the model.
`void` | `refresh()` `QDirModel` caches file information.
`void` | `refresh(QModelIndex parent)` `QDirModel` caches file information.
`boolean` | `remove(QModelIndex index)` Removes the model item `index` from the directory model and deletes the corresponding file from the file system, returning true if successful.
`boolean` | `resolveSymlinks()` This property holds Whether the directory model should resolve symbolic links.
`boolean` | `rmdir(QModelIndex index)` Removes the directory corresponding to the model item `index` in the directory model and deletes the corresponding directory from the file system, returning true if successful.
`void` | `setFilter(QDir.Filter[] filters)` Sets the directory model's filter to that specified by `filters`.
`void` | `setFilter(QDir.Filters filters)` Sets the directory model's filter to that specified by `filters`.
`void` | `setIconProvider(QFileIconProvider provider)` Sets the `provider` of file icons for the directory model.
`void` | `setLazyChildCount(boolean enable)` This property holds Whether the directory model optimizes the `hasChildren` function to only check if the item is a directory.
`void` | `setNameFilters(java.util.List filters)` Sets the name `filters` for the directory model.
`void` | `setReadOnly(boolean enable)` This property holds Whether the directory model allows writing to the file system.
`void` | `setResolveSymlinks(boolean enable)` This property holds Whether the directory model should resolve symbolic links.
`void` | `setSorting(QDir.SortFlag[] sort)` Sets the directory model's sorting order to that specified by `sort`.
`void` | `setSorting(QDir.SortFlags sort)` Sets the directory model's sorting order to that specified by `sort`.
`QDir.SortFlags` | `sorting()` Returns the sorting method used for the directory model.

Methods inherited from class com.trolltech.qt.core.QAbstractItemModel
`beginInsertColumns, beginInsertRows, beginRemoveColumns, beginRemoveRows, buddy, canFetchMore, changePersistentIndex, changePersistentIndexList, columnCount, columnCount, createIndex, createIndex, createIndex, data, data, data, data, dropMimeData, endInsertColumns, endInsertRows, endRemoveColumns, endRemoveRows, fetchMore, flags, hasChildren, hasChildren, hasIndex, hasIndex, headerData, headerData, index, index, insertColumn, insertColumn, insertColumns, insertColumns, insertRow, insertRow, insertRows, insertRows, itemData, match, match, match, match, mimeData, mimeTypes, parent, persistentIndexList, removeColumn, removeColumn, removeColumns, removeColumns, removeRow, removeRow, removeRows, removeRows, reset, revert, rowCount, rowCount, setData, setData, setData, setData, setHeaderData, setHeaderData, setItemData, setSupportedDragActions, setSupportedDragActions, sibling, sort, sort, span, submit, supportedDragActions, supportedDropActions`

Methods inherited from class com.trolltech.qt.core.QObject
`childEvent, children, connectSlotsByName, customEvent, disposeLater, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, event, eventFilter, findChild, findChild, findChild, findChildren, findChildren, findChildren, findChildren, indexOfProperty, installEventFilter, isWidgetType, killTimer, moveToThread, objectName, parent, properties, property, removeEventFilter, setObjectName, setParent, setProperty, startTimer, timerEvent, toString, userProperty`

Methods inherited from class com.trolltech.qt.QtJambiObject
`dispose, disposed, equals, finalize, reassignNativeResources, tr, tr, tr`

Methods inherited from class com.trolltech.qt.QSignalEmitter
`blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread`

Methods inherited from class java.lang.Object
`clone, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Methods inherited from interface com.trolltech.qt.QtJambiInterface
`disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership`

Constructor Detail

### QDirModel

    public QDirModel()

  Constructs a directory model with the given `parent`.

### QDirModel

    public QDirModel(QObject parent)

  Constructs a directory model with the given `parent`.

### QDirModel

    public QDirModel(java.util.List nameFilters,
                     QDir.Filters filters,
                     QDir.SortFlags sort)

  Constructs a new directory model with the given `parent`. Only those files matching the `nameFilters` and the `filters` are included in the model. The sort order is given by the `sort` flags.

### QDirModel

    public QDirModel(java.util.List nameFilters,
                     QDir.Filters filters,
                     QDir.SortFlags sort,
                     QObject parent)

  Constructs a new directory model with the given `parent`. Only those files matching the `nameFilters` and the `filters` are included in the model. The sort order is given by the `sort` flags.

Method Detail

### fileIcon

    public final QIcon fileIcon(QModelIndex index)

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

### fileInfo

    public final QFileInfo fileInfo(QModelIndex index)

  Returns the file information for the specified model `index`.

  Note: If the model index represents a symbolic link in the underlying filing system, the file information returned will contain information about the symbolic link itself, regardless of whether `resolveSymlinks` is enabled or not.

See also:
  `QFileInfo::symLinkTarget()`.

### fileName

    public final java.lang.String fileName(QModelIndex index)

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

### filePath

    public final java.lang.String filePath(QModelIndex index)

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

### filter

    public final QDir.Filters filter()

  Returns the filter specification for the directory model.

See also:
  `setFilter()`, and QDir::Filters.

### iconProvider

    public final QFileIconProvider iconProvider()

  Returns the file icon provider for this directory model.

See also:
  `setIconProvider()`.

### index

    public final QModelIndex index(java.lang.String path)

  Returns the model item index for the given `path`.

### index

    public final QModelIndex index(java.lang.String path,
                                   int column)

  Returns the model item index for the given `path`.

### isDir

    public final boolean isDir(QModelIndex index)

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

### isReadOnly

    public final boolean isReadOnly()

  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

### lazyChildCount

    public final boolean lazyChildCount()

  This property holds Whether the directory model optimizes the `hasChildren` function to only check if the item is a directory. If this property is set to false, the directory model will make sure that a directory actually containes any files before reporting that it has children. Otherwise the directory model will report that an item has children if the item is a directory.

  This property is false by default

### mkdir

    public final QModelIndex mkdir(QModelIndex parent,
                                   java.lang.String name)

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

### nameFilters

    public final java.util.List nameFilters()

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

See also:
  `setNameFilters()`.

### refresh

    public final void refresh()

  `QDirModel` caches file information. This function updates the cache. The `parent` parameter is the directory from which the model is updated; the default value will update the model from root directory of the file system (the entire model).

### refresh

    public final void refresh(QModelIndex parent)

  `QDirModel` caches file information. This function updates the cache. The `parent` parameter is the directory from which the model is updated; the default value will update the model from root directory of the file system (the entire model).

### remove

    public final boolean remove(QModelIndex index)

  Removes the model item `index` from the directory model and deletes 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 does not move them to a location where they can be recovered.

See also:
  `rmdir()`.

### resolveSymlinks

    public final boolean resolveSymlinks()

  This property holds Whether the directory model should resolve symbolic links. This is only relevant on operating systems that support symbolic links.

### rmdir

    public final boolean rmdir(QModelIndex index)

  Removes the directory corresponding to the model item `index` in the directory model and deletes 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 does not move them to a location where they can be recovered.

See also:
  `remove()`.

### setFilter

    public final void setFilter(QDir.Filter[] 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 `QDirModel` won't be able to read the directory structure.

See also:
  `filter()`, and QDir::Filters.

### setFilter

    public final void 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 `QDirModel` won't be able to read the directory structure.

See also:
  `filter()`, and QDir::Filters.

### setIconProvider

    public final void setIconProvider(QFileIconProvider provider)

  Sets the `provider` of file icons for the directory model.

See also:
  `iconProvider()`.

### setLazyChildCount

    public final void setLazyChildCount(boolean enable)

  This property holds Whether the directory model optimizes the `hasChildren` function to only check if the item is a directory. If this property is set to false, the directory model will make sure that a directory actually containes any files before reporting that it has children. Otherwise the directory model will report that an item has children if the item is a directory.

  This property is false by default

### setNameFilters

    public final void setNameFilters(java.util.List filters)

  Sets the name `filters` for the directory model.

See also:
  `nameFilters()`.

### setReadOnly

    public final void setReadOnly(boolean 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

### setResolveSymlinks

    public final void setResolveSymlinks(boolean enable)

  This property holds Whether the directory model should resolve symbolic links. This is only relevant on operating systems that support symbolic links.

### setSorting

    public final void setSorting(QDir.SortFlag[] sort)

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

See also:
  `sorting()`, and QDir::SortFlags.

### setSorting

    public final void setSorting(QDir.SortFlags sort)

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

See also:
  `sorting()`, and QDir::SortFlags.

### sorting

    public final QDir.SortFlags sorting()

  Returns the sorting method used for the directory model.

See also:
  `setSorting()`, and QDir::SortFlags.

### fromNativePointer

    public static QDirModel fromNativePointer(QNativePointer nativePointer)

  This method returns the QDirModel instance pointed to by `nativePointer`.

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD