Qt Jambi Home

com.trolltech.qt.gui
Class QDirModel

java.lang.Object
  extended by com.trolltech.qt.QSignalEmitter
      extended by com.trolltech.qt.QtJambiObject
          extended by com.trolltech.qt.core.QObject
              extended by com.trolltech.qt.core.QAbstractItemModel
                  extended by 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, 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, QListView, QTreeView, View Example, Model Classes

Nested Class Summary
static class QDirModel.Roles
          Press link for info on QDirModel.Roles
 
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter
QSignalEmitter.Signal0, QSignalEmitter.Signal1<A>, QSignalEmitter.Signal2<A,B>, QSignalEmitter.Signal3<A,B,C>, QSignalEmitter.Signal4<A,B,C,D>, QSignalEmitter.Signal5<A,B,C,D,E>, QSignalEmitter.Signal6<A,B,C,D,E,F>, QSignalEmitter.Signal7<A,B,C,D,E,F,G>, QSignalEmitter.Signal8<A,B,C,D,E,F,G,H>, QSignalEmitter.Signal9<A,B,C,D,E,F,G,H,I>
 
Field Summary
 
Fields inherited from class com.trolltech.qt.core.QAbstractItemModel
dataChanged, headerDataChanged, layoutAboutToBeChanged, layoutChanged
 
Constructor Summary
QDirModel()
          Equivalent to QDirModel(0).
QDirModel(java.util.List<java.lang.String> nameFilters, QDir.Filters filters, QDir.SortFlags sort)
          Equivalent to QDirModel(nameFilters, filters, sort, 0).
QDirModel(java.util.List<java.lang.String> 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
 int columnCount(QModelIndex parent)
          Returns the number of columns in the parent model item.
 java.lang.Object data(QModelIndex index, int role)
          Returns the data for the model item index with the given role.
 boolean dropMimeData(QMimeData data, Qt.DropAction action, int row, int column, QModelIndex parent)
          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.
 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.
 Qt.ItemFlags flags(QModelIndex index)
          Returns the item flags for the given index in the model.
static QDirModel fromNativePointer(QNativePointer nativePointer)
          This function returns the QDirModel instance pointed to by nativePointer
 boolean hasChildren(QModelIndex index)
          Returns true if the index model item has children; otherwise returns false.
 java.lang.Object headerData(int section, Qt.Orientation orientation, int role)
          Returns the data stored under the given role for the specified section of the header with the given orientation.
 QFileIconProvider iconProvider()
          Returns the file icon provider for this directory model.
 QModelIndex index(int row, int column, QModelIndex parent)
          Returns the model item index for the item in the parent with the given row and column.
 QModelIndex index(java.lang.String path)
          Equivalent to index(path, 0).
 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()
          Returns Whether the directory model allows writing to the file system.
 boolean lazyChildCount()
          Returns Whether the directory model optimizes the hasChildren function to only check if the item is a directory..
 QMimeData mimeData(java.util.List<QModelIndex> indexes)
          Returns an object that contains a serialized description of the specified indexes.
 java.util.List<java.lang.String> mimeTypes()
          Returns a list of MIME types that can be used to describe a list of items in the model.
 QModelIndex mkdir(QModelIndex parent, java.lang.String name)
          Create a directory with the name in the parent model item.
 java.util.List<java.lang.String> nameFilters()
          Returns a list of filters applied to the names in the model.
 QModelIndex parent(QModelIndex child)
          Return the parent of the given child model item.
 void refresh()
          Equivalent to refresh(QModelIndex()).
 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()
          Returns 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.
 int rowCount(QModelIndex parent)
          Returns the number of rows in the parent model item.
 boolean setData(QModelIndex index, java.lang.Object value, int role)
          Sets the data for the model item index with the given role to the data referenced by the value.
 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)
          Sets Whether the directory model optimizes the hasChildren function to only check if the item is a directory.
 void setNameFilters(java.util.List<java.lang.String> filters)
          Sets the name filters for the directory model.
 void setReadOnly(boolean enable)
          Sets Whether the directory model allows writing to the file system to enable.
 void setResolveSymlinks(boolean enable)
          Sets Whether the directory model should resolve symbolic links to enable.
 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.
 void sort(int column, Qt.SortOrder order)
          Sort the model items in the column using the order given.
 QDir.SortFlags sorting()
          Returns the sorting method used for the directory model.
 Qt.DropActions supportedDropActions()
          Returns the drop actions supported by this model.
 
Methods inherited from class com.trolltech.qt.core.QAbstractItemModel
beginInsertColumns, beginInsertRows, beginRemoveColumns, beginRemoveRows, buddy, canFetchMore, changePersistentIndex, changePersistentIndexList, columnCount, createIndex, createIndex, createIndex, data, data, data, decodeData, encodeData, endInsertColumns, endInsertRows, endRemoveColumns, endRemoveRows, fetchMore, hasChildren, hasIndex, hasIndex, headerData, index, insertColumn, insertColumn, insertColumns, insertColumns, insertRow, insertRow, insertRows, insertRows, itemData, match, match, match, match, persistentIndexList, removeColumn, removeColumn, removeColumns, removeColumns, removeRow, removeRow, removeRows, removeRows, reset, revert, rowCount, setData, setData, setData, setHeaderData, setHeaderData, setItemData, setSupportedDragActions, setSupportedDragActions, sibling, sort, span, submit, supportedDragActions
 
Methods inherited from class com.trolltech.qt.core.QObject
blockSignals, childEvent, children, connectSlotsByName, customEvent, disposeLater, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, event, eventFilter, findChild, findChild, findChild, findChildren, findChildren, findChildren, findChildren, installEventFilter, isWidgetType, killTimer, moveToThread, objectName, parent, property, removeEventFilter, setObjectName, setParent, setProperty, signalsBlocked, startTimer, thread, timerEvent
 
Methods inherited from class com.trolltech.qt.QtJambiObject
dispose, disposed, finalize, reassignNativeResources, tr, tr, tr
 
Methods inherited from class com.trolltech.qt.QSignalEmitter
disconnect, disconnect, signalSender
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.trolltech.qt.QtJambiInterface
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership
 

Constructor Detail

QDirModel

public QDirModel(java.util.List<java.lang.String> nameFilters,
                 QDir.Filters filters,
                 QDir.SortFlags sort)

Equivalent to QDirModel(nameFilters, filters, sort, 0).


QDirModel

public QDirModel(java.util.List<java.lang.String> 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.


QDirModel

public QDirModel()

Equivalent to QDirModel(0).


QDirModel

public QDirModel(QObject parent)

Constructs a directory model with the given parent.

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

Equivalent to index(path, 0).


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

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

Returns 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

See Also:
setLazyChildCount

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<java.lang.String> nameFilters()

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

See Also:
setNameFilters

refresh

public final void refresh()

Equivalent to refresh(QModelIndex()).


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

Returns Whether the directory model should resolve symbolic links.

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

See Also:
setResolveSymlinks

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

Sets Whether the directory model optimizes the hasChildren function to only check if the item is a directory. to enable.

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

See Also:
lazyChildCount

setNameFilters

public final void setNameFilters(java.util.List<java.lang.String> filters)

Sets the name filters for the directory model.

See Also:
nameFilters

setReadOnly

public final void setReadOnly(boolean enable)

Sets Whether the directory model allows writing to the file system to enable.

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

See Also:
isReadOnly

setResolveSymlinks

public final void setResolveSymlinks(boolean enable)

Sets Whether the directory model should resolve symbolic links to enable.

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

See Also:
resolveSymlinks

setSorting

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

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

See Also:
sorting, 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, QDir::SortFlags

sorting

public final QDir.SortFlags sorting()

Returns the sorting method used for the directory model.

See Also:
setSorting, QDir::SortFlags

columnCount

public int columnCount(QModelIndex parent)

Returns the number of columns in the parent model item.

Specified by:
columnCount in class QAbstractItemModel
See Also:
rowCount

data

public java.lang.Object data(QModelIndex index,
                             int role)

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

Specified by:
data in class QAbstractItemModel
See Also:
setData

dropMimeData

public boolean dropMimeData(QMimeData data,
                            Qt.DropAction action,
                            int row,
                            int column,
                            QModelIndex parent)

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.

Overrides:
dropMimeData in class QAbstractItemModel
See Also:
supportedDropActions

flags

public Qt.ItemFlags flags(QModelIndex index)

Returns the item flags for the given index in the model.

Overrides:
flags in class QAbstractItemModel
See Also:
Qt::ItemFlags

hasChildren

public boolean hasChildren(QModelIndex index)

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

Overrides:
hasChildren in class QAbstractItemModel
See Also:
parent, index

headerData

public java.lang.Object headerData(int section,
                                   Qt.Orientation orientation,
                                   int role)

Returns the data stored under the given role for the specified section of the header with the given orientation.

Overrides:
headerData in class QAbstractItemModel
See Also:
Qt::ItemDataRole, setHeaderData, QHeaderView

index

public QModelIndex index(int row,
                         int column,
                         QModelIndex parent)

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

Specified by:
index in class QAbstractItemModel
See Also:
createIndex

mimeData

public QMimeData mimeData(java.util.List<QModelIndex> indexes)

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, 0 is returned rather than a serialized empty list.

Overrides:
mimeData in class QAbstractItemModel
See Also:
mimeTypes, dropMimeData

mimeTypes

public java.util.List<java.lang.String> mimeTypes()

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

Overrides:
mimeTypes in class QAbstractItemModel
See Also:
mimeData

parent

public QModelIndex parent(QModelIndex child)

Return the parent of the given child model item.

Specified by:
parent in class QAbstractItemModel
See Also:
createIndex

rowCount

public int rowCount(QModelIndex parent)

Returns the number of rows in the parent model item.

Specified by:
rowCount in class QAbstractItemModel
See Also:
columnCount

setData

public boolean setData(QModelIndex index,
                       java.lang.Object value,
                       int role)

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.

Overrides:
setData in class QAbstractItemModel
See Also:
data, Qt::ItemDataRole

sort

public void sort(int column,
                 Qt.SortOrder order)

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

Overrides:
sort in class QAbstractItemModel

supportedDropActions

public Qt.DropActions supportedDropActions()

Returns the drop actions supported by this model.

Overrides:
supportedDropActions in class QAbstractItemModel
See Also:
Qt::DropActions

fromNativePointer

public static QDirModel fromNativePointer(QNativePointer nativePointer)
This function returns the QDirModel instance pointed to by nativePointer

Parameters:
nativePointer - the QNativePointer of which object should be returned.

Qt Jambi Home