Class: QgsDataItem

class qgis.core.QgsDataItem(type: QgsDataItem.Type, parent: QgsDataItem, name: str, path: str)

Bases: PyQt5.QtCore.QObject

Create new data item.

Base class for all items in the model. Parent/children hierarchy is not based on QObject.

Methods

acceptDrop Returns whether the item accepts drag and dropped layers - e.g.
actions Returns the list of actions available for this item.
addChildItem Inserts a new child item.
capabilities2 Returns the capabilities for the data item.
childEvent
children
childrenCreated
connectNotify
createChildren Create children.
customEvent
deferredDelete The item is scheduled to be deleted.
deleteChildItem Removes and deletes a child item, emitting relevant signals to the model.
deleteLater deleteLater(self) Safely delete the item: - disconnects parent - unsets parent (but does not remove itself) - deletes all its descendants recursively - waits until Populating state (createChildren() in thread) finished without blocking main thread - calls QObject.deleteLater()
depopulate Remove children recursively and set as not populated.
disconnectNotify
equal Returns true if this item is equal to another item (by testing item type and path).
findItem
handleDoubleClick Called when a user double clicks on the item.
handleDrop Attempts to process the mime data dropped on this item.
hasChildren
hasDragEnabled Returns true if the item may be dragged.
icon
isSignalConnected
menus Returns the list of menus available for this item.
mimeUri Returns mime URI for the data item.
moveToThread Move object and all its descendants to thread
name Returns the name of the item (the displayed text for the item).
paramWidget
parent Gets item parent.
path
pathComponent Create path component replacing path separators
populate populate(self, foreground: bool = False)
receivers
refresh Refresh the items from a specified list of child items.
refreshConnections Refresh connections: update GUI and emit signal
removeChildItem Removes a child item and returns it without deleting it.
rename Sets a new name for the item, and returns true if the item was successfully renamed.
rowCount
sender
senderSignalIndex
setCapabilities Sets the capabilities for the data item.
setCrs Writes the selected crs into data source.
setIcon
setIconName
setName Sets the name of the item (the displayed text for the item).
setParent Set item parent and connect / disconnect parent to / from item signals.
setPath
setSortKey Sets a custom sorting key for the item.
setState Set item state.
setToolTip
sortKey Returns the sorting key for the item.
state

New in version 2.8.

timerEvent
toolTip
type
updateIcon Will request a repaint of this icon.

Signals

beginInsertItems beginInsertItems(self, QgsDataItem, int, int) [signal]
beginRemoveItems beginRemoveItems(self, QgsDataItem, int, int) [signal]
connectionsChanged Emitted when the provider’s connections of the child items have changed This signal is normally forwarded to the app in order to refresh the connection item in the provider dialogs and to refresh the connection items in the other open browsers [signal]
dataChanged dataChanged(self, QgsDataItem) [signal]
endInsertItems endInsertItems(self) [signal]
endRemoveItems endRemoveItems(self) [signal]
stateChanged stateChanged(self, QgsDataItem, QgsDataItem.State) [signal]

Attributes

Collapse
Collection
Custom
Delete
Directory
Error
Fast
Favorites
Fertile
Layer
NoCapabilities
NotPopulated
Populated
Populating
Project
Rename
SetCrs
class Capabilities

Bases: sip.wrapper

QgsDataItem.Capabilities(Union[QgsDataItem.Capabilities, QgsDataItem.Capability]) QgsDataItem.Capabilities(QgsDataItem.Capabilities)

class Capability

Bases: int

Collapse = 8
Collection = 0
Custom = 6
Delete = 32
Directory = 1
Error = 3
Fast = 4
Favorites = 4
Fertile = 2
Layer = 2
NoCapabilities = 0
NotPopulated = 0
Populated = 2
Populating = 1
Project = 5
Rename = 16
SetCrs = 1
class State

Bases: int

baseClass

alias of QgsDataItem

class Type

Bases: int

baseClass

alias of QgsDataItem

acceptDrop(self) → bool

Returns whether the item accepts drag and dropped layers - e.g. for importing a dataset to a provider. Subclasses should override this and handleDrop() to accept dropped layers.

See also

handleDrop()

actions(self, parent: QWidget) → List[QAction]

Returns the list of actions available for this item. This is usually used for the popup menu on right-clicking the item. Subclasses should override this to provide actions.

Subclasses should ensure that ownership of created actions is correctly handled by parenting them to the specified parent widget.

addChildItem(self, child: QgsDataItem, refresh: bool = False)

Inserts a new child item. The child will be inserted at a position using an alphabetical order based on mName.

Parameters:
  • child – child item to insert. Ownership is transferred, and item parent will be set and relevant connections made.
  • refresh
    • set to true to refresh populated item, emitting relevant signals to the model
beginInsertItems

beginInsertItems(self, QgsDataItem, int, int) [signal]

beginRemoveItems

beginRemoveItems(self, QgsDataItem, int, int) [signal]

capabilities2(self) → QgsDataItem.Capabilities

Returns the capabilities for the data item.

childEvent()
children(self) → object
childrenCreated(self)
connectNotify()
connectionsChanged

Emitted when the provider’s connections of the child items have changed This signal is normally forwarded to the app in order to refresh the connection item in the provider dialogs and to refresh the connection items in the other open browsers [signal]

createChildren(self) → object

Create children. Children are not expected to have parent set. This method MUST BE THREAD SAFE. *

customEvent()
dataChanged

dataChanged(self, QgsDataItem) [signal]

deferredDelete(self) → bool

The item is scheduled to be deleted. E.g. if deleteLater() is called when item is in Populating state (createChildren() running in another thread), the deferredDelete() returns true and item will be deleted once Populating finished. Items with slow reateChildren() (for example network or database based) may check during createChildren() if deferredDelete() returns true and return from createChildren() immediately because result will be useless. *

deleteChildItem(self, child: QgsDataItem)

Removes and deletes a child item, emitting relevant signals to the model.

Parameters:child – child to remove. Item must exist as a current child.

See also

addChildItem()

deleteLater(items: object)

deleteLater(self) Safely delete the item: - disconnects parent - unsets parent (but does not remove itself) - deletes all its descendants recursively - waits until Populating state (createChildren() in thread) finished without blocking main thread - calls QObject.deleteLater()

depopulate(self)

Remove children recursively and set as not populated. This is used when refreshing collapsed items.

disconnectNotify()
endInsertItems

endInsertItems(self) [signal]

endRemoveItems

endRemoveItems(self) [signal]

equal(self, other: QgsDataItem) → bool

Returns true if this item is equal to another item (by testing item type and path).

findItem(items: object, item: QgsDataItem) → int
handleDoubleClick(self) → bool

Called when a user double clicks on the item. Subclasses should return true if they have implemented a double-click handler and do not want the default double-click behavior for items.

New in version 3.0.

handleDrop(self, QMimeData, Qt.DropAction) → bool

Attempts to process the mime data dropped on this item. Subclasses must override this and acceptDrop() if they accept dropped layers.

See also

acceptDrop()

hasChildren(self) → bool
hasDragEnabled(self) → bool

Returns true if the item may be dragged. Default implementation returns false. A draggable item has to implement mimeUri() that will be used to pass data.

See also

mimeUri()

New in version 3.0.

icon(self) → QIcon
isSignalConnected()
menus(self, parent: QWidget) → object

Returns the list of menus available for this item. This is usually used for the popup menu on right-clicking the item. Subclasses should override this to provide actions. Subclasses should ensure that ownership of created menus is correctly handled by parenting them to the specified parent widget.

Parameters:parent – a parent widget of the menu
Returns:list of menus

New in version 3.0.

mimeUri(self) → QgsMimeDataUtils.Uri

Returns mime URI for the data item. Items that return valid URI will be returned in mime data when dragging a selection from browser model.

See also

hasDragEnabled()

New in version 3.0.

moveToThread(self, targetThread: QThread)

Move object and all its descendants to thread

name(self) → str

Returns the name of the item (the displayed text for the item).

See also

setName()

paramWidget(self) → QWidget
parent(self) → QgsDataItem

Gets item parent. QgsDataItem maintains its own items hierarchy, it does not use QObject hierarchy. *

path(self) → str
pathComponent(component: str) → str

Create path component replacing path separators

populate(self, children: object)

populate(self, foreground: bool = False)

receivers()
refresh(self, children: object)

Refresh the items from a specified list of child items.

refresh(self)

refreshConnections(self)

Refresh connections: update GUI and emit signal

removeChildItem(self, child: QgsDataItem) → QgsDataItem

Removes a child item and returns it without deleting it. Emits relevant signals to model as required.

Parameters:child – child to remove
Returns:pointer to the removed item or null if no such item was found
rename(self, name: str) → bool

Sets a new name for the item, and returns true if the item was successfully renamed.

Items which implement this method should return the QgsDataItem.Rename capability.

The default implementation does nothing.

New in version 3.4.

rowCount(self) → int
sender()
senderSignalIndex()
setCapabilities(self, capabilities: Union[QgsDataItem.Capabilities, QgsDataItem.Capability])

Sets the capabilities for the data item.

See also

capabilities2()

setCrs(self, crs: QgsCoordinateReferenceSystem) → bool

Writes the selected crs into data source. The original data source will be modified when calling this method.

setIcon(self, icon: QIcon)
setIconName(self, iconName: str)
setName(self, name: str)

Sets the name of the item (the displayed text for the item).

See also

name()

setParent(self, parent: QgsDataItem)

Set item parent and connect / disconnect parent to / from item signals. It does not add itself to parents children (mChildren) *

setPath(self, path: str)
setSortKey(self, key: Any)

Sets a custom sorting key for the item.

See also

sortKey()

New in version 3.0.

setState(self, state: QgsDataItem.State)

Set item state. It also take care about starting/stopping loading icon animation.

Parameters:state

New in version 2.8.

setToolTip(self, msg: str)
sortKey(self) → Any

Returns the sorting key for the item. By default name() is returned, but setSortKey() can be used to set a custom sort key for the item.

Alternatively subclasses can override this method to return a custom sort key.

See also

setSortKey()

New in version 3.0.

state(self) → QgsDataItem.State

New in version 2.8.

stateChanged

stateChanged(self, QgsDataItem, QgsDataItem.State) [signal]

timerEvent()
toolTip(self) → str
type(self) → QgsDataItem.Type
updateIcon(self)

Will request a repaint of this icon.

New in version 3.0.