# class KDirModel

###

Module | kio
Namespace |
Class | KDirModel
Inherits | QAbstractItemModel

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

### enums

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

enum details

### methods

- KDirModel (parent)

  returns ctor
  KDE 4.1.0 and later only

  Argument | Type | Default
  --- | --- | ---
  parent | QObject | 0

  parent - parent qobject

- KDirModel (a0)

  returns ctor
  before KDE 4.1.0 only

  Argument | Type | Default
  --- | --- | ---
  a0 | QObject | 0

- canFetchMore (parent)

  returns bool

  Argument | Type | Default
  --- | --- | ---
  parent | QModelIndex |

  Reimplemented from QAbstractItemModel. Returns true for empty directories.

- columnCount (parent)

  returns int

  Argument | Type | Default
  --- | --- | ---
  parent | QModelIndex | QModelIndex()

  Reimplemented from QAbstractItemModel. Returns ColumnCount.

- data (index, role)

  returns QVariant

  Argument | Type | Default
  --- | --- | ---
  index | QModelIndex |
  role | int | Qt.DisplayRole

  Reimplemented from QAbstractItemModel.

- dirLister ( )

  returns KDirLister

  Return the directory lister used by this model.

- dropMimeData (data, action, row, column, parent)

  returns bool

  Argument | Type | Default
  --- | --- | ---
  data | QMimeData |
  action | Qt.DropAction |
  row | int |
  column | int |
  parent | QModelIndex |

  Reimplemented from QAbstractItemModel. Not implemented yet.

- expand (index)

  returns Nothing
  SIGNAL ("expand (const QModelIndex&)")

  Argument | Type | Default
  --- | --- | ---
  index | QModelIndex |

  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.

- expandToUrl (url)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  url | KUrl |

  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.

  url - the url of a subdirectory of the directory model

- fetchMore (parent)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  parent | QModelIndex |

  Reimplemented from QAbstractItemModel. Lists the subdirectory.

- flags (index)

  returns Qt.ItemFlags

  Argument | Type | Default
  --- | --- | ---
  index | QModelIndex |

  Reimplemented from QAbstractItemModel.

- hasChildren (parent)

  returns bool

  Argument | Type | Default
  --- | --- | ---
  parent | QModelIndex | QModelIndex()

  Reimplemented from QAbstractItemModel. Returns true for directories.

- headerData (section, orientation, role)

  returns QVariant

  Argument | Type | Default
  --- | --- | ---
  section | int |
  orientation | Qt.Orientation |
  role | int | Qt.DisplayRole

  Reimplemented from QAbstractItemModel. Returns the column titles.

- index (row, column, parent)

  returns QModelIndex

  Argument | Type | Default
  --- | --- | ---
  row | int |
  column | int |
  parent | QModelIndex | QModelIndex()

  Reimplemented from QAbstractItemModel. O(1)

- indexForItem (a0)

  returns QModelIndex

  Argument | Type | Default
  --- | --- | ---
  a0 | KFileItem |

  Return the index for a given kfileitem. This can be slow. Deprecated use the method that takes a KFileItem by value

- indexForItem (a0)

  returns QModelIndex

  Argument | Type | Default
  --- | --- | ---
  a0 | KFileItem |

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

- indexForUrl (url)

  returns QModelIndex

  Argument | Type | Default
  --- | --- | ---
  url | KUrl |

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

- itemChanged (index)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  index | QModelIndex |

  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.

- itemForIndex (index)

  returns KFileItem

  Argument | Type | Default
  --- | --- | ---
  index | QModelIndex |

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

- mimeData (indexes)

  returns QMimeData

  Argument | Type | Default
  --- | --- | ---
  indexes | QModelIndexList |

  Reimplemented from QAbstractItemModel.

- mimeTypes ( )

  returns QStringList

  Reimplemented from QAbstractItemModel.

- parent (index)

  returns QModelIndex

  Argument | Type | Default
  --- | --- | ---
  index | QModelIndex |

  Reimplemented from QAbstractItemModel.

- rowCount (parent)

  returns int

  Argument | Type | Default
  --- | --- | ---
  parent | QModelIndex | QModelIndex()

  Reimplemented from QAbstractItemModel.

- setData (index, value, role)

  returns bool

  Argument | Type | Default
  --- | --- | ---
  index | QModelIndex |
  value | QVariant |
  role | int | Qt.EditRole

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

- setDirLister (dirLister)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  dirLister | KDirLister |

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

- setDropsAllowed (dropsAllowed)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  dropsAllowed | KDirModel.DropsAllowed |

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

- sort (column, order)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  column | int |
  order | Qt.SortOrder | Qt.AscendingOrder

  Reimplemented from QAbstractItemModel. Not implemented.

  See also KDirSortFilterProxyModel

### enums - detail

- AdditionalRoles { FileItemRole, ChildCountRole }

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

  | FileItemRole | - 0x07A263FF | - |
  | ChildCountRole | - 0x2C4D0A40 | - |

- DropsAllowedFlag { NoDrops, DropOnDirectory, DropOnAnyFile, DropOnLocalExecutable }

  returns the number of items in a directory, or ChildCountUnknown

  typesafe object: DropsAllowed

NoDrops - 0 -
DropOnDirectory - 1 -
DropOnAnyFile - 2 -
DropOnLocalExecutable - 4 -

- ModelColumns { Name, Size, ModifiedTime, Permissions, Owner, Group, Type, ColumnCount }

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

  | Name | - 0 | - |
  | Size | - | - |
  | ModifiedTime | - | - |
  | Permissions | - | - |
  | Owner | - | - |
  | Group | - | - |
  | Type | - | - |
  | ColumnCount | - | - |

- anonymous { ChildCountUnknown }

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

  | ChildCountUnknown | - -1 | - |