KDirModel Class Reference
from PyKDE4.kio import *
Inherits: QAbstractItemModel → QObject
Detailed Description
A model for a KIO-based directory tree.
KDirModel implements the QAbstractItemModel interface (for use with Qt's model/view widgets)
around the directory listing for one directory or a tree of directories.
Note that there are some cases when using QPersistentModelIndexes from this model will not give
expected results. QPersistentIndexes will remain valid and updated if its siblings are added or
removed. However, if the QPersistentIndex or one of its ancestors is moved, the QPersistentIndex will become
invalid. For example, if a file or directory is renamed after storing a QPersistentModelIndex for it,
the index (along with any stored children) will become invalid even though it is still in the model. The reason
for this is that moves of files and directories are treated as separate insert and remove actions.
- See also:
- KDirSortFilterProxyModel
- Author:
- David Faure
Based on work by Hamish Rodda and Pascal Letourneau
Enumerations |
<anonymous> | { ChildCountUnknown } |
AdditionalRoles | { FileItemRole, ChildCountRole } |
DropsAllowedFlag | { NoDrops, DropOnDirectory, DropOnAnyFile, DropOnLocalExecutable } |
ModelColumns | { Name, Size, ModifiedTime, Permissions, Owner, Group, Type, ColumnCount } |
Signals |
| expand (, QModelIndex index) |
| needSequenceIcon (, QModelIndex index, int sequenceIndex) |
Methods |
| __init__ (self, QObject parent=0) |
bool | canFetchMore (self, QModelIndex parent) |
int | columnCount (self, QModelIndex parent=QModelIndex()) |
QVariant | data (self, QModelIndex index, int role=Qt.DisplayRole) |
KDirLister | dirLister (self) |
bool | dropMimeData (self, QMimeData data, Qt::DropAction action, int row, int column, QModelIndex parent) |
| expand (self, QModelIndex index) |
| expandToUrl (self, KUrl url) |
| fetchMore (self, QModelIndex parent) |
Qt::ItemFlags | flags (self, QModelIndex index) |
bool | hasChildren (self, QModelIndex parent=QModelIndex()) |
QVariant | headerData (self, int section, Qt::Orientation orientation, int role=Qt.DisplayRole) |
QModelIndex | index (self, int row, int column, QModelIndex parent=QModelIndex()) |
QModelIndex | indexForItem (self, KFileItem a0) |
QModelIndex | indexForItem (self, KFileItem a0) |
QModelIndex | indexForUrl (self, KUrl url) |
| itemChanged (self, QModelIndex index) |
KFileItem | itemForIndex (self, QModelIndex index) |
QMimeData | mimeData (self, QModelIndexList indexes) |
QStringList | mimeTypes (self) |
| needSequenceIcon (self, QModelIndex index, int sequenceIndex) |
QModelIndex | parent (self, QModelIndex index) |
| requestSequenceIcon (self, QModelIndex index, int sequenceIndex) |
int | rowCount (self, QModelIndex parent=QModelIndex()) |
bool | setData (self, QModelIndex index, QVariant value, int role=Qt.EditRole) |
| setDirLister (self, KDirLister dirLister) |
| setDropsAllowed (self, KDirModel.DropsAllowed dropsAllowed) |
KUrl.List | simplifiedUrlList (self, KUrl.List urls) |
| sort (self, int column, Qt::SortOrder order=Qt.AscendingOrder) |
Method Documentation
__init__ |
( |
self, |
|
|
|
QObject |
parent=0 |
|
) |
|
|
|
int columnCount |
( |
self, |
|
|
|
QModelIndex |
parent=QModelIndex() |
|
) |
|
|
|
Return the directory lister used by this model.
Emitted for each subdirectory that is a parent of a url passed to expandToUrl
This allows to asynchronously open a tree view down to a given directory.
Also emitted for the final file, if expandToUrl is called with a file
(for instance so that it can be selected).
- Signal syntax:
QObject.connect(source, SIGNAL("expand(const QModelIndex&)"), target_slot)
expandToUrl |
( |
self, |
|
|
|
KUrl |
url |
|
) |
|
|
|
Lists subdirectories using fetchMore() as needed until the given url exists in the model.
When the model is used by a treeview, call KDirLister.openUrl with the base url of the tree,
then the treeview will take care of calling fetchMore() when the user opens directories.
However if you want the tree to show a given URL (i.e. open the tree recursively until that URL),
call expandToUrl().
Note that this is asynchronous; the necessary listing of subdirectories will take time so
the model will not immediately have this url available.
The model emits the signal expand() when an index has become available; this can be connected
to the treeview in order to let it open that index.
- Parameters:
-
| url | the url of a subdirectory of the directory model (or a file in a subdirectory)
|
bool hasChildren |
( |
self, |
|
|
|
QModelIndex |
parent=QModelIndex() |
|
) |
|
|
|
Return the index for a given kfileitem. This can be slow.
Return the index for a given kfileitem. This can be slow.
Return the index for a given url. This can be slow.
Notify the model that the item at this index has changed.
For instance because KMimeTypeResolver called determineMimeType on it.
This makes the model emit its dataChanged signal at this index, so that views repaint.
Note that for most things (renaming, changing size etc.), KDirLister's signals tell the model already.
Return the fileitem for a given index. This is O(1), i.e. fast.
needSequenceIcon |
( |
self, |
|
|
|
QModelIndex |
index, |
|
|
int |
sequenceIndex |
|
) |
|
|
|
Emitted when another icon sequence index is requested
- Parameters:
-
| index | Index of the item that should get another icon
|
| sequenceIndex | Index in the sequence. If it is zero, the standard icon should be assigned.
For higher indices, arbitrary different meaningful icons should be generated.
This is usually slowly counted up while the user hovers the icon.
If no meaningful alternative icons can be generated, this should be ignored.
|
- Since:
- 4.3
- Signal syntax:
QObject.connect(source, SIGNAL("needSequenceIcon(const QModelIndex&, int)"), target_slot)
requestSequenceIcon |
( |
self, |
|
|
|
QModelIndex |
index, |
|
|
int |
sequenceIndex |
|
) |
|
|
|
This emits the needSequenceIcon signal, requesting another sequence icon
If there is a KFilePreviewGenerator attached to this model, that generator will care
about creating another preview.
- Parameters:
-
| index | Index of the item that should get another icon
|
| sequenceIndex | Index in the sequence. If it is zero, the standard icon will be assigned.
For higher indices, arbitrary different meaningful icons will be generated.
|
- Since:
- 4.3
int rowCount |
( |
self, |
|
|
|
QModelIndex |
parent=QModelIndex() |
|
) |
|
|
|
Set the directory lister to use by this model, instead of the default KDirLister created internally.
The model takes ownership.
Remove urls from the list if an ancestor is present on the list. This can
be used to delete only the ancestor url and skip a potential error of a non-existent url.
For example, for a list of "/home/foo/a", "/home/foo/a/a.txt", "/home/foo/a/a/a.txt", "/home/foo/a/b/b.txt",
"home/foo/b/b.txt", this method will return the list "/home/foo/a", "/home/foo/b/b.txt".
- Returns:
- the list urls without parented urls inside.
- Since:
- 4.2
Enumeration Documentation
- Enumerator:
-
FileItemRole = 0x07A263FF | |
ChildCountRole = 0x2C4D0A40 | |
- Enumerator:
-
NoDrops = 0 | |
DropOnDirectory = 1 | |
DropOnAnyFile = 2 | |
DropOnLocalExecutable = 4 | |
*
Useful "default" columns. Views can use a proxy to have more control over this.
- Enumerator:
-
Name = 0 | |
Size | |
ModifiedTime | |
Permissions | |
Owner | |
Group | |
Type | |
ColumnCount | |