Class: QgsDataItem¶
- class qgis.core.QgsDataItem¶
Bases:
PyQt5.QtCore.QObject
Base class for all items in the model.
Parent/children hierarchy is not based on QObject.
QgsDataItem(type: Qgis.BrowserItemType, parent:
QgsDataItem
, name: str, path: str, providerKey: str = ‘’) Constructor forQgsDataItem
, with the specifiedparent
item.The
name
argument specifies the text to show in the model for the item. A translated string should be used wherever appropriate.The
path
argument gives the item path in the browser tree. Thepath
string can take any form, butQgsDataItem
items pointing to different logical locations should always use a different itempath
.The optional
providerKey
string (added in QGIS 3.12) can be used to specify the key for theQgsDataItemProvider
that created this item.Enums
alias of
BrowserItemCapability
alias of
BrowserItemState
alias of
BrowserItemType
Methods
Returns whether the item accepts drag and dropped layers - e.g.
Returns the list of actions available for this item.
Inserts a new child item.
Returns the capabilities for the data item.
- rtype:
List[QgsDataItem]
Create children.
For data items that represent a DB connection or one of its children, this method returns a connection.
The item is scheduled to be deleted.
Removes and deletes a child item, emitting relevant signals to the model.
deleteLater(self) Safely delete the item:
Remove children recursively and set as not populated.
Returns
True
if this item is equal to another item (by testing item type and path).- param items:
Called when a user double clicks on the item.
Attempts to process the mime data dropped on this item.
- rtype:
bool
Returns
True
if the item may be dragged.- rtype:
QIcon
Returns
True
if the data item is a collection of layers The default implementation returnsFalse
, subclasses must implement this method if their children are layers.Returns the list of menus available for this item.
Returns mime URI for the data item.
Returns mime URIs for the data item, most data providers will only return a single URI but some data collection items (e.g.
Move object and all its descendants to thread
Returns the name of the item (the displayed text for the item).
Returns source widget from data item for
QgsBrowserPropertiesWidget
Gets item parent.
- rtype:
str
Create path component replacing path separators
- param children:
Returns the provider key that created this item (e.g.
Refresh the items from a specified list of child items.
Causes a data item provider to refresh all registered connections.
Removes a child item and returns it without deleting it.
Sets a new
name
for the item, and returnsTrue
if the item was successfully renamed.- rtype:
int
Sets the capabilities for the data item.
Writes the selected crs into data source.
- param icon:
- param iconName:
Sets the
name
of the item (the displayed text for the item).Set item parent and connect / disconnect parent to / from item signals.
- param path:
Sets the provider key that created this item (e.g.
Sets a custom sorting
key
for the item.Set item state.
- param msg:
Returns the sorting key for the item.
New in version 2.8.
- rtype:
str
- rtype:
Qgis.BrowserItemType
Will request a repaint of this icon.
Signals
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
- Capabilities¶
alias of
BrowserItemCapabilities
- Capability¶
alias of
BrowserItemCapability
- State¶
alias of
BrowserItemState
- Type¶
alias of
BrowserItemType
- 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
See also
QgsDataItemGuiProvider.handleDrop()
Deprecated since version QGIS: 3.10
- Return type:
bool
- 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.
- Parameters:
parent (QWidget) –
- Return type:
List[QAction]
- 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 (QgsDataItem) – child item to insert. Ownership is transferred, and item parent will be set and relevant connections made.
refresh (bool = False) –
set to
True
to refresh populated item, emitting relevant signals to the model
See also
- beginInsertItems¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- beginRemoveItems¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- capabilities2(self) Qgis.BrowserItemCapabilities ¶
Returns the capabilities for the data item.
See also
- Return type:
- childEvent(self, QChildEvent)¶
- children(self) List[QgsDataItem] ¶
- Return type:
List[QgsDataItem]
- childrenCreated(self)¶
- connectNotify(self, QMetaMethod)¶
- connectionsChanged¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- createChildren(self) List[QgsDataItem] ¶
Create children. Children are not expected to have parent set.
Warning
This method MUST BE THREAD SAFE.
- Return type:
List[QgsDataItem]
- customEvent(self, QEvent)¶
- dataChanged¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- databaseConnection(self) QgsAbstractDatabaseProviderConnection ¶
For data items that represent a DB connection or one of its children, this method returns a connection. All other data items will return NULL.
Ownership of the returned objects is transferred to the caller.
New in version 3.16.
- Return type:
- 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), thedeferredDelete()
returnsTrue
and item will be deleted once Populating finished. Items with slowreateChildren()
(for example network or database based) may check duringcreateChildren()
ifdeferredDelete()
returnsTrue
and return fromcreateChildren()
immediately because result will be useless.- Return type:
bool
- deleteChildItem(self, child: QgsDataItem)¶
Removes and deletes a child item, emitting relevant signals to the model.
- Parameters:
child (QgsDataItem) – child to remove. Item must exist as a current child.
See also
- deleteLater(items: Iterable[QgsDataItem])¶
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 threadcalls QObject.deleteLater()
- Parameters:
items (Iterable[QgsDataItem]) –
- depopulate(self)¶
Remove children recursively and set as not populated. This is used when refreshing collapsed items.
- disconnectNotify(self, QMetaMethod)¶
- endInsertItems¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- endRemoveItems¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- equal(self, other: QgsDataItem) bool ¶
Returns
True
if this item is equal to another item (by testing item type and path).- Parameters:
other (QgsDataItem) –
- Return type:
bool
- findItem(items: Iterable[QgsDataItem], item: QgsDataItem) int ¶
- Parameters:
items (Iterable[QgsDataItem]) –
item (QgsDataItem) –
- Return type:
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.
- Return type:
bool
- 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
See also
QgsDataItemGuiProvider.handleDrop()
Deprecated since version QGIS: 3.10
- Return type:
bool
- hasChildren(self) bool ¶
- Return type:
bool
- hasDragEnabled(self) bool ¶
Returns
True
if the item may be dragged. Default implementation returnsFalse
. A draggable item has to implementmimeUris()
that will be used to pass data.See also
New in version 3.0.
- Return type:
bool
- icon(self) QIcon ¶
- Return type:
QIcon
- isSignalConnected(self, QMetaMethod) bool ¶
- layerCollection(self) bool ¶
Returns
True
if the data item is a collection of layers The default implementation returnsFalse
, subclasses must implement this method if their children are layers.New in version 3.14.
- Return type:
bool
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 (QWidget) – a parent widget of the menu
- Return type:
List[QMenu]
- 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
Deprecated since version QGIS: 3.18 use
mimeUris()
insteadNew in version 3.0.
- Return type:
- mimeUris(self) List[QgsMimeDataUtils.Uri] ¶
Returns mime URIs for the data item, most data providers will only return a single URI but some data collection items (e.g. GPKG, OGR) may report multiple URIs (e.g. for vector and raster layer types).
Items that return valid URI will be returned in mime data when dragging a selection from browser model.
New in version 3.18.
- Return type:
List[QgsMimeDataUtils.Uri]
- moveToThread(self, targetThread: QThread)¶
Move object and all its descendants to thread
- Parameters:
targetThread (QThread) –
- name(self) str ¶
Returns the name of the item (the displayed text for the item).
See also
- Return type:
str
- paramWidget(self) QWidget ¶
Returns source widget from data item for
QgsBrowserPropertiesWidget
Use
QgsDataItemGuiProvider.createParamWidget()
insteadDeprecated since version QGIS: 3.10
- Return type:
QWidget
- parent(self) QgsDataItem ¶
Gets item parent.
QgsDataItem
maintains its own items hierarchy, it does not use QObject hierarchy.- Return type:
- path(self) str ¶
- Return type:
str
- pathComponent(component: str) str ¶
Create path component replacing path separators
- Parameters:
component (str) –
- Return type:
str
- populate(self, children: Iterable[QgsDataItem])¶
- populate(self, foreground: bool = False) None
- Parameters:
children (Iterable[QgsDataItem]) –
- providerKey(self) str ¶
Returns the provider key that created this item (e.g. “PostGIS”)
If key has a prefix “special:”, it marks that the item was not created with a provider, but manually. For example “special:Favorites”, “special:Home”
New in version 3.12.
- Return type:
str
- receivers(self, PYQT_SIGNAL) int ¶
- refresh(self, children: Iterable[QgsDataItem])¶
Refresh the items from a specified list of child items.
refresh(self)
- Parameters:
children (Iterable[QgsDataItem]) –
- refreshConnections(self, providerKey: str = '')¶
Causes a data item provider to refresh all registered connections.
If
providerKey
is specified then only the matching provider will be refreshed. Otherwise, all providers will be refreshed (which is potentially very expensive!).- Parameters:
providerKey (str = '') –
- removeChildItem(self, child: QgsDataItem) QgsDataItem ¶
Removes a child item and returns it without deleting it. Emits relevant signals to model as required.
- Parameters:
child (QgsDataItem) – child to remove
- Return type:
- Returns:
pointer to the removed item or
None
if no such item was found
- rename(self, name: str) bool ¶
Sets a new
name
for the item, and returnsTrue
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.
Deprecated since version QGIS: 3.10
- Parameters:
name (str) –
- Return type:
bool
- rowCount(self) int ¶
- Return type:
int
- sender(self) QObject ¶
- senderSignalIndex(self) int ¶
- setCapabilities(self, capabilities: int)¶
Deprecated since version use: setCapabilitiesV2 instead.
- Parameters:
capabilities (int) –
- setCapabilitiesV2(self, capabilities: Qgis.BrowserItemCapabilities | Qgis.BrowserItemCapability)¶
Sets the capabilities for the data item.
See also
- Parameters:
capabilities (Union[Qgis.BrowserItemCapabilities) –
- setCrs(self, crs: QgsCoordinateReferenceSystem) bool ¶
Writes the selected crs into data source. The original data source will be modified when calling this method.
Deprecated since version QGIS: 3.6. This method is no longer used by QGIS and will be removed in QGIS 4.0.
- Parameters:
crs (QgsCoordinateReferenceSystem) –
- Return type:
bool
- setIcon(self, icon: QIcon)¶
- Parameters:
icon (QIcon) –
- setIconName(self, iconName: str)¶
- Parameters:
iconName (str) –
- setName(self, name: str)¶
Sets the
name
of the item (the displayed text for the item).See also
- Parameters:
name (str) –
- setParent(self, parent: QgsDataItem)¶
Set item parent and connect / disconnect parent to / from item signals. It does not add itself to parents children (mChildren)
- Parameters:
parent (QgsDataItem) –
- setPath(self, path: str)¶
- Parameters:
path (str) –
- setProviderKey(self, value: str)¶
Sets the provider key that created this item (e.g. “PostGIS”)
If key has a prefix “special:”, it marks that the item was not created with a provider, but manually. For example “special:Favorites”
New in version 3.12.
- Parameters:
value (str) –
- setSortKey(self, key: Any)¶
Sets a custom sorting
key
for the item.See also
New in version 3.0.
- Parameters:
key (Any) –
- setState(self, state: Qgis.BrowserItemState)¶
Set item state. It also take care about starting/stopping loading icon animation.
- Parameters:
state (Qgis.BrowserItemState) –
New in version 2.8.
- setToolTip(self, msg: str)¶
- Parameters:
msg (str) –
- sortKey(self) Any ¶
Returns the sorting key for the item. By default
name()
is returned, butsetSortKey()
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
New in version 3.0.
- Return type:
Any
- state(self) Qgis.BrowserItemState ¶
New in version 2.8.
- Return type:
- stateChanged¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- timerEvent(self, QTimerEvent)¶
- toolTip(self) str ¶
- Return type:
str
- type(self) Qgis.BrowserItemType ¶
- Return type:
- updateIcon(self)¶
Will request a repaint of this icon.
New in version 3.0.