Class: QgsDataItem¶
Base class for all items in the model.
Parent/children hierarchy is not based on QObject.
Class Hierarchy¶
Base classes¶
Subclasses¶
A browser item for collections of data. |
|
A browser item that can be used to report problems (e.g. network error). |
|
A browser item representing a field domain. |
|
Contains a collection of field domain items. |
|
A data item representing a single field from a layer. |
|
A browser item which contains a collection of field items. |
|
A browser item that represents a layer that can be opened with one of the providers. |
|
Data item that can be used to represent QGIS projects. |
|
A browser item representing a relationship. |
|
Contains a collection of relationship items. |
Enums
alias of |
|
alias of |
|
alias of |
Methods
The item is scheduled to be deleted. |
|
Move object and all its descendants to thread |
|
Returns the name of the item (the displayed text for the item). |
|
Gets item parent. |
|
Returns the provider key that created this item (e.g. "PostGIS"). |
|
Sets the capabilities for the data item. |
|
Sets the name of the item (the displayed text for the item). |
|
Set item parent and connect / disconnect parent to / from item signals. |
|
Sets the provider key that created this item (e.g. "PostGIS"). |
|
Sets a custom sorting key for the item. |
|
Will request a repaint of this icon. |
Virtual Methods
In PyQGIS, only methods marked as virtual
can be safely overridden in a Python subclass of QgsDataItem. See the FAQ for more details.
Returns whether the item accepts drag and dropped layers - e.g. for importing a dataset to a provider. |
|
Returns the list of actions available for this item. |
|
Inserts a new child item. |
|
Returns the capabilities for the data item. |
|
Create children. |
|
For data items that represent a DB connection or one of its children, this method returns a connection. |
|
Removes and deletes a child item, emitting relevant signals to the model. |
|
Remove children recursively and set as not populated. |
|
Returns |
|
Called when a user double clicks on the item. |
|
Attempts to process the mime data dropped on this item. |
|
Returns |
|
Returns |
|
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. GPKG, OGR) may report multiple URIs (e.g. for vector and raster layer types). |
|
Returns source widget from data item for |
|
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 returns |
|
Writes the selected crs into data source. |
|
Set item state. |
|
Returns the sorting key for the item. |
Static Methods
Create path component replacing path separators |
Signals
Emitted before child items are added to this data item. |
|
Emitted before child items are removed from this data item. |
|
Emitted when the connections of the provider with the specified providerKey have changed. |
|
Emitted when data changes for an item. |
|
Emitted after child items have been added to this data item. |
|
Emitted after child items have been removed from this data item. |
|
Emitted when an item's state is changed. |
- class qgis.core.QgsDataItem[source]¶
Bases:
QObject
- __init__(type: Qgis.BrowserItemType, parent: QgsDataItem | None, name: str | None, path: str | None, providerKey: str | None = '')
Constructor for QgsDataItem, with the specified
parent
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, but QgsDataItem 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.- Parameters:
type (Qgis.BrowserItemType)
parent (Optional[QgsDataItem])
name (Optional[str])
path (Optional[str])
providerKey (Optional[str] = '')
- Capabilities¶
alias of
BrowserItemCapabilities
- Capability¶
alias of
BrowserItemCapability
- State¶
alias of
BrowserItemState
- Type¶
alias of
BrowserItemType
- virtual acceptDrop(self) bool [source]¶
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 3.10.
- Return type:
bool
- virtual actions(self, parent: QWidget | None) 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 (Optional[QWidget])
- Return type:
List[QAction]
- virtual addChildItem(self, child: QgsDataItem | None, refresh: bool = False)[source]¶
Inserts a new child item. The child will be inserted at a position using an alphabetical order based on mName.
- Parameters:
child (Optional[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
- signal beginInsertItems(parent: QgsDataItem, first: int, last: int)[source]¶
Emitted before child items are added to this data item.
This signal must be followed by
endInsertItems()
.- Parameters:
parent (QgsDataItem) – the parent item having children added, will always be this object
first (int) – index of first child item to be added
last (int) – index last child item, after the addition has occurred
See also
- signal beginRemoveItems(parent: QgsDataItem, first: int, last: int)[source]¶
Emitted before child items are removed from this data item.
This signal must be followed by
endRemoveItems()
.- Parameters:
parent (QgsDataItem) – the parent item having children removed, will always be this object
first (int) – index of first child item to be removed
last (int) – index of the last child item to be removed
See also
- virtual capabilities2(self) Qgis.BrowserItemCapabilities [source]¶
Returns the capabilities for the data item.
See also
- Return type:
- signal connectionsChanged(providerKey: str | None = None)[source]¶
Emitted when the connections of the provider with the specified
providerKey
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.
- Parameters:
providerKey (Optional[str] = None)
- virtual 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]
- signal dataChanged(item: QgsDataItem)[source]¶
Emitted when data changes for an
item
.- Parameters:
item (QgsDataItem)
- virtual databaseConnection(self) QgsAbstractDatabaseProviderConnection | None [source]¶
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.
Added in version 3.16.
- Return type:
Optional[QgsAbstractDatabaseProviderConnection]
- deferredDelete(self) bool [source]¶
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
- virtual deleteChildItem(self, child: QgsDataItem | None)[source]¶
Removes and deletes a child item, emitting relevant signals to the model.
- Parameters:
child (Optional[QgsDataItem]) – child to remove. Item must exist as a current child.
See also
- deleteLater(items: Iterable[QgsDataItem])[source]¶
- Parameters:
items (Iterable[QgsDataItem])
- deleteLater(self)[source]
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()
- virtual depopulate(self)[source]¶
Remove children recursively and set as not populated. This is used when refreshing collapsed items.
- signal endInsertItems[source]¶
Emitted after child items have been added to this data item.
This signal will always be preceded by
beginInsertItems()
.See also
- signal endRemoveItems[source]¶
Emitted after child items have been removed from this data item.
This signal will always be preceded by
beginRemoveItems()
.See also
- virtual equal(self, other: QgsDataItem | None) bool [source]¶
Returns
True
if this item is equal to another item (by testing item type and path).- Parameters:
other (Optional[QgsDataItem])
- Return type:
bool
- static findItem(items: Iterable[QgsDataItem], item: QgsDataItem | None) int [source]¶
- Parameters:
items (Iterable[QgsDataItem])
item (Optional[QgsDataItem])
- Return type:
int
- virtual handleDoubleClick(self) bool [source]¶
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.- Return type:
bool
- virtual handleDrop(self, a0: QMimeData | None, a1: Qt.DropAction) bool [source]¶
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 3.10.
- Parameters:
a0 (Optional[QMimeData])
a1 (Qt.DropAction)
- Return type:
bool
- virtual hasDragEnabled(self) bool [source]¶
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
- Return type:
bool
- virtual layerCollection(self) bool [source]¶
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.Added 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 (Optional[QWidget]) – a parent widget of the menu
- Return type:
List[QMenu]
- Returns:
list of menus
- virtual mimeUri(self) QgsMimeDataUtils.Uri [source]¶
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 3.18: Use
mimeUris()
instead.- Return type:
- virtual mimeUris(self) List[QgsMimeDataUtils.Uri] [source]¶
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.
Added in version 3.18.
- Return type:
List[QgsMimeDataUtils.Uri]
- moveToThread(self, targetThread: QThread | None)[source]¶
Move object and all its descendants to thread
- Parameters:
targetThread (Optional[QThread])
- name(self) str [source]¶
Returns the name of the item (the displayed text for the item).
See also
- Return type:
str
- virtual paramWidget(self) QWidget | None [source]¶
Returns source widget from data item for
QgsBrowserPropertiesWidget
Use
QgsDataItemGuiProvider.createParamWidget()
insteadDeprecated since version 3.10.
- Return type:
Optional[QWidget]
- parent(self) QgsDataItem | None [source]¶
Gets item parent.
QgsDataItem
maintains its own items hierarchy, it does not use QObject hierarchy.- Return type:
Optional[QgsDataItem]
- static pathComponent(component: str | None) str [source]¶
Create path component replacing path separators
- Parameters:
component (Optional[str])
- Return type:
str
- virtual populate(self, children: Iterable[QgsDataItem])[source]¶
- virtual populate(self, foreground: bool = False) None
- Parameters:
children (Iterable[QgsDataItem])
- virtual populate(self, foreground: bool = False)[source]
- Parameters:
foreground (bool = False)
- providerKey(self) str [source]¶
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”
Added in version 3.12.
- Return type:
str
- virtual refresh(self, children: Iterable[QgsDataItem])[source]¶
Refresh the items from a specified list of child items.
- Parameters:
children (Iterable[QgsDataItem])
- virtual refresh(self)[source]
- virtual refreshConnections(self, providerKey: str | None = '')[source]¶
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 (Optional[str] = '')
- virtual removeChildItem(self, child: QgsDataItem | None) QgsDataItem | None [source]¶
Removes a child item and returns it without deleting it. Emits relevant signals to model as required.
- Parameters:
child (Optional[QgsDataItem]) – child to remove
- Return type:
Optional[QgsDataItem]
- Returns:
pointer to the removed item or
None
if no such item was found
- virtual rename(self, name: str | None) bool [source]¶
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.
Added in version 3.4.
Deprecated since version 3.10.
- Parameters:
name (Optional[str])
- Return type:
bool
- setCapabilities(self, capabilities: int)[source]¶
Deprecated since version 3.40.
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, Qgis.BrowserItemCapability])
- virtual setCrs(self, crs: QgsCoordinateReferenceSystem) bool [source]¶
Writes the selected crs into data source. The original data source will be modified when calling this method.
Deprecated since version 3.6: This method is no longer used by QGIS and will be removed in QGIS 4.0.
- Parameters:
- Return type:
bool
- setName(self, name: str | None)[source]¶
Sets the
name
of the item (the displayed text for the item).See also
- Parameters:
name (Optional[str])
- setParent(self, parent: QgsDataItem | None)[source]¶
Set item parent and connect / disconnect parent to / from item signals. It does not add itself to parents children (mChildren)
- Parameters:
parent (Optional[QgsDataItem])
- setProviderKey(self, value: str | None)[source]¶
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”
Added in version 3.12.
- Parameters:
value (Optional[str])
- setSortKey(self, key: Any)[source]¶
Sets a custom sorting
key
for the item.See also
- Parameters:
key (Any)
- virtual setState(self, state: Qgis.BrowserItemState)[source]¶
Set item state. It also take care about starting/stopping loading icon animation.
- Parameters:
state (Qgis.BrowserItemState)
- virtual sortKey(self) Any [source]¶
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
- Return type:
Any
- state(self) Qgis.BrowserItemState [source]¶
- Return type:
- signal stateChanged(item: QgsDataItem, oldState: Qgis.BrowserItemState)[source]¶
Emitted when an item’s state is changed.
- Parameters:
item (QgsDataItem)
oldState (Qgis.BrowserItemState)
- type(self) Qgis.BrowserItemType [source]¶
- Return type: