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. |
- 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
parentitem.The
nameargument specifies the text to show in the model for the item. A translated string should be used wherever appropriate.The
pathargument gives the item path in the browser tree. Thepathstring can take any form, but QgsDataItem items pointing to different logical locations should always use a different itempath.The optional
providerKeystring (added in QGIS 3.12) can be used to specify the key for theQgsDataItemProviderthat 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
Trueto refresh populated item, emitting relevant signals to the model
See also
- signal beginInsertItems[source]¶
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.
- signal beginRemoveItems[source]¶
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.
- virtual capabilities2(self) Qgis.BrowserItemCapabilities[source]¶
Returns the capabilities for the data item.
See also
- Return type:
- signal connectionsChanged[source]¶
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.
- virtual createChildren(self) List[QgsDataItem]¶
Create children. Children are not expected to have parent set.
Warning
This method MUST BE THREAD SAFE.
- Return type:
- signal dataChanged[source]¶
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.
- 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]¶
Returns
Trueif 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()returnsTrueand item will be deleted once Populating finished. Items with slowreateChildren()(for example network or database based) may check duringcreateChildren()ifdeferredDelete()returnsTrueand 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]¶
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]¶
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.
- signal endRemoveItems[source]¶
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.
- virtual equal(self, other: QgsDataItem | None) bool[source]¶
Returns
Trueif 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
Trueif 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
Trueif 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
Trueif 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:
- 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
QgsBrowserPropertiesWidgetUse
QgsDataItemGuiProvider.createParamWidget()insteadDeprecated since version 3.10.
- Return type:
Optional[QWidget]
- parent(self) QgsDataItem | None[source]¶
Gets item parent.
QgsDataItemmaintains 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)
- Parameters:
children (Iterable[QgsDataItem])
- 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.
refresh(self)
- Parameters:
children (Iterable[QgsDataItem])
- virtual refreshConnections(self, providerKey: str | None = '')[source]¶
Causes a data item provider to refresh all registered connections.
If
providerKeyis 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
Noneif no such item was found
- virtual rename(self, name: str | None) bool[source]¶
Sets a new
namefor the item, and returnsTrueif 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
nameof 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
keyfor 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:
- state(self) Qgis.BrowserItemState[source]¶
- Return type:
- signal stateChanged[source]¶
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.
- type(self) Qgis.BrowserItemType[source]¶
- Return type: