KDE 4.2 PyKDE API Reference
  • KDE's Python API
  • Overview
  • PyKDE Home
  • Sitemap
  • Contact Us
 

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.

See also:
KDirSortFilterProxyModel

Author:
David Faure
Based on work by Hamish Rodda and Pascal Letourneau


Enumerations

AdditionalRoles { FileItemRole, ChildCountRole }
DropsAllowedFlag { NoDrops, DropOnDirectory, DropOnAnyFile, DropOnLocalExecutable }
Typesafe wrapper: DropsAllowed
ModelColumns { Name, Size, ModifiedTime, Permissions, Owner, Group, Type, ColumnCount }
anonymous { ChildCountUnknown }

Signals

 expand (QModelIndex index)

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)
QModelIndex parent (self, QModelIndex index)
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)
 sort (self, int column, Qt.SortOrder order=Qt.AscendingOrder)

Static Methods

KUrl.List simplifiedUrlList (KUrl.List urls)

Method Documentation

__init__ (  self,
QObject  parent=0
)

Parameters:
parent  parent qobject

bool canFetchMore (  self,
QModelIndex  parent
)

Reimplemented from QAbstractItemModel. Returns true for empty directories.

int columnCount (  self,
QModelIndex  parent=QModelIndex()
)

Reimplemented from QAbstractItemModel. Returns ColumnCount.

QVariant data (  self,
QModelIndex  index,
int  role=Qt.DisplayRole
)

Reimplemented from QAbstractItemModel.

KDirLister dirLister (   self )

Return the directory lister used by this model.

bool dropMimeData (  self,
QMimeData  data,
Qt.DropAction  action,
int  row,
int  column,
QModelIndex  parent
)

Reimplemented from QAbstractItemModel. Not implemented yet.

expand (  self,
QModelIndex  index
)

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)

fetchMore (  self,
QModelIndex  parent
)

Reimplemented from QAbstractItemModel. Lists the subdirectory.

Qt.ItemFlags flags (  self,
QModelIndex  index
)

Reimplemented from QAbstractItemModel.

bool hasChildren (  self,
QModelIndex  parent=QModelIndex()
)

Reimplemented from QAbstractItemModel. Returns true for directories.

QVariant headerData (  self,
int  section,
Qt.Orientation  orientation,
int  role=Qt.DisplayRole
)

Reimplemented from QAbstractItemModel. Returns the column titles.

QModelIndex index (  self,
int  row,
int  column,
QModelIndex  parent=QModelIndex()
)

Reimplemented from QAbstractItemModel. O(1)

QModelIndex indexForItem (  self,
KFileItem  a0
)

Return the index for a given kfileitem. This can be slow.

Deprecated:
use the method that takes a KFileItem by value

QModelIndex indexForItem (  self,
KFileItem  a0
)

Return the index for a given kfileitem. This can be slow.

QModelIndex indexForUrl (  self,
KUrl  url
)

Return the index for a given url. This can be slow.

itemChanged (  self,
QModelIndex  index
)

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.

KFileItem itemForIndex (  self,
QModelIndex  index
)

Return the fileitem for a given index. This is O(1), i.e. fast.

QMimeData mimeData (  self,
QModelIndexList  indexes
)

Reimplemented from QAbstractItemModel.

QStringList mimeTypes (   self )

Reimplemented from QAbstractItemModel.

QModelIndex parent (  self,
QModelIndex  index
)

Reimplemented from QAbstractItemModel.

int rowCount (  self,
QModelIndex  parent=QModelIndex()
)

Reimplemented from QAbstractItemModel.

bool setData (  self,
QModelIndex  index,
QVariant  value,
int  role=Qt.EditRole
)

Reimplemented from QAbstractItemModel. Call this to set a new icon, e.g. a preview

setDirLister (  self,
KDirLister  dirLister
)

Set the directory lister to use by this model, instead of the default KDirLister created internally. The model takes ownership.

setDropsAllowed (  self,
KDirModel.DropsAllowed  dropsAllowed
)

Set whether dropping onto items should be allowed, and for which kind of item Drops are disabled by default.

KUrl.List simplifiedUrlList ( KUrl.List  urls
)

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

sort (  self,
int  column,
Qt.SortOrder  order=Qt.AscendingOrder
)

Reimplemented from QAbstractItemModel. Not implemented.

See also:
KDirSortFilterProxyModel


Enumeration Documentation

AdditionalRoles

Possible return value for data(ChildCountRole), meaning the item isn't a directory, or we haven't calculated its child count yet

Enumerator:
FileItemRole = 0x07A263FF
ChildCountRole = 0x2C4D0A40

DropsAllowedFlag

returns the number of items in a directory, or ChildCountUnknown

Note:
It is necessary to wrap members of this enumeration in a DropsAllowed instance when passing them to a method as group of flags. For example: DropsAllowed( NoDrops | DropOnDirectory)
Enumerator:
NoDrops = 0
DropOnDirectory = 1
DropOnAnyFile = 2
DropOnLocalExecutable = 4

ModelColumns

* Useful "default" columns. Views can use a proxy to have more control over this.

Enumerator:
Name = 0
Size 
ModifiedTime 
Permissions 
Owner 
Group 
Type 
ColumnCount 

anonymous

Possible return value for data(ChildCountRole), meaning the item isn't a directory, or we haven't calculated its child count yet

Enumerator:
ChildCountUnknown = -1

  • Full Index

Modules

  • akonadi
  • dnssd
  • kdecore
  • kdeui
  • khtml
  • kio
  • knewstuff
  • kparts
  • kutils
  • nepomuk
  • phonon
  • plasma
  • solid
  • soprano
This documentation is maintained by Simon Edwards.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal