|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.trolltech.qt.QSignalEmitter
com.trolltech.qt.QtJambiObject
com.trolltech.qt.core.QObject
com.trolltech.qt.core.QAbstractItemModel
com.trolltech.qt.gui.QDirModel
public class QDirModel
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.
View Example
,
Model ClassesNested 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, 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, 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 |
---|
public QDirModel(java.util.List<java.lang.String> nameFilters, QDir.Filters filters, QDir.SortFlags sort)
Equivalent to QDirModel(nameFilters, filters, sort, 0).
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.
public QDirModel()
Equivalent to QDirModel(0).
public QDirModel(QObject parent)
Constructs a directory model with the given parent.
Method Detail |
---|
public final QIcon fileIcon(QModelIndex index)
Returns the icons for the item stored in the model under the given index.
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.
public final java.lang.String fileName(QModelIndex index)
Returns the name of the item stored in the model under the index given.
public final java.lang.String filePath(QModelIndex index)
Returns the path of the item stored in the model under the index given.
public final QDir.Filters filter()
Returns the filter specification for the directory model.
public final QFileIconProvider iconProvider()
Returns the file icon provider for this directory model.
public final QModelIndex index(java.lang.String path)
Equivalent to index(path, 0).
public final QModelIndex index(java.lang.String path, int column)
Returns the model item index for the given path.
public final boolean isDir(QModelIndex index)
Returns true if the model item index represents a directory; otherwise returns false.
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
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
public final QModelIndex mkdir(QModelIndex parent, java.lang.String name)
Create a directory with the name in the parent model item.
public final java.util.List<java.lang.String> nameFilters()
Returns a list of filters applied to the names in the model.
public final void refresh()
Equivalent to refresh(QModelIndex()).
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).
public final boolean remove(QModelIndex index)
Removes the model item index from the directory model, returning true if successful. If the item cannot be removed, false is returned.
public final boolean resolveSymlinks()
Returns Whether the directory model should resolve symbolic links.
This is only relevant on operating systems that support symbolic links.
public final boolean rmdir(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.
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.
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.
public final void setIconProvider(QFileIconProvider provider)
Sets the provider of file icons for the directory model.
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
public final void setNameFilters(java.util.List<java.lang.String> filters)
Sets the name filters for the directory model.
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
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.
public final void setSorting(QDir.SortFlag... sort)
Sets the directory model's sorting order to that specified by sort.
public final void setSorting(QDir.SortFlags sort)
Sets the directory model's sorting order to that specified by sort.
public final QDir.SortFlags sorting()
Returns the sorting method used for the directory model.
public int columnCount(QModelIndex parent)
Returns the number of columns in the parent model item.
columnCount
in class QAbstractItemModel
public java.lang.Object data(QModelIndex index, int role)
Returns the data for the model item index with the given role.
data
in class QAbstractItemModel
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.
dropMimeData
in class QAbstractItemModel
public Qt.ItemFlags flags(QModelIndex index)
Returns the item flags for the given index in the model.
flags
in class QAbstractItemModel
public boolean hasChildren(QModelIndex index)
Returns true if the index model item has children; otherwise returns false.
hasChildren
in class QAbstractItemModel
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.
headerData
in class QAbstractItemModel
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.
index
in class QAbstractItemModel
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.
mimeData
in class QAbstractItemModel
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.
mimeTypes
in class QAbstractItemModel
public QModelIndex parent(QModelIndex child)
Return the parent of the given child model item.
parent
in class QAbstractItemModel
public int rowCount(QModelIndex parent)
Returns the number of rows in the parent model item.
rowCount
in class QAbstractItemModel
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.
setData
in class QAbstractItemModel
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.
sort
in class QAbstractItemModel
public Qt.DropActions supportedDropActions()
Returns the drop actions supported by this model.
supportedDropActions
in class QAbstractItemModel
public static QDirModel fromNativePointer(QNativePointer nativePointer)
nativePointer
- the QNativePointer of which object should be returned.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |