Class: QgsDataItemGuiProvider¶
Abstract base class for providers which affect how
QgsDataItem
items behave within the application GUI.
Providers must be registered via
QgsDataItemGuiProviderRegistry
.
Added in version 3.6.
Note
This is an abstract class, with methods which must be implemented by a subclass.
The following methods must be implemented: name()
Abstract Methods
Returns the provider's name. |
Virtual Methods
In PyQGIS, only methods marked as virtual
can be safely overridden in a Python subclass of QgsDataItemGuiProvider. See the FAQ for more details.
Providers should return |
|
Creates source widget from data item for |
|
Tries to permanently delete map layer representing the given item. |
|
Called when a user double clicks on an item. |
|
Called when a user drops on an item. |
|
Called when the given context menu is being populated for the given item, allowing the provider to add its own actions and submenus to the context menu. |
|
Returns the provider's precedence to use when populating context menus via calls to |
|
Sets a new name for the item, and returns |
Static Methods
Notify the user showing a message with title and level If the context has a message bar the message will be shown in the message bar else a message dialog will be used. |
- class qgis.gui.QgsDataItemGuiProvider[source]¶
Bases:
object
- virtual acceptDrop(self, item: QgsDataItem | None, context: QgsDataItemGuiContext) bool [source]¶
Providers should return
True
if the drops are allowed (handleDrop()
should be implemented in that case as well).Added in version 3.10.
- Parameters:
item (Optional[QgsDataItem])
context (QgsDataItemGuiContext)
- Return type:
bool
- virtual createParamWidget(self, item: QgsDataItem | None, context: QgsDataItemGuiContext) QWidget | None [source]¶
Creates source widget from data item for
QgsBrowserPropertiesWidget
By default it returns None. Caller takes responsibility of deleting created.The function is replacement of
QgsDataItem.paramWidget()
Added in version 3.10.
- Parameters:
item (Optional[QgsDataItem])
context (QgsDataItemGuiContext)
- Return type:
Optional[QWidget]
- virtual deleteLayer(self, item: QgsLayerItem | None, context: QgsDataItemGuiContext) bool [source]¶
Tries to permanently delete map layer representing the given item. Returns
True
if the layer was successfully deleted.Items which implement this method should return the
QgsDataItem
.Delete capability.The default implementation does nothing.
Added in version 3.10.
- Parameters:
item (Optional[QgsLayerItem])
context (QgsDataItemGuiContext)
- Return type:
bool
- virtual handleDoubleClick(self, item: QgsDataItem | None, context: QgsDataItemGuiContext) bool [source]¶
Called when a user double clicks on an
item
. Providers should returnTrue
if the double-click was handled and do not want other providers to handle the double-click, and to prevent the default double-click behavior for items.- Parameters:
item (Optional[QgsDataItem])
context (QgsDataItemGuiContext)
- Return type:
bool
- virtual handleDrop(self, item: QgsDataItem | None, context: QgsDataItemGuiContext, data: QMimeData | None, action: Qt.DropAction) bool [source]¶
Called when a user drops on an
item
. Providers should returnTrue
if the drop was handled and do not want other providers to handle the drop, and to prevent the default drop behavior for items.Added in version 3.10.
- Parameters:
item (Optional[QgsDataItem])
context (QgsDataItemGuiContext)
data (Optional[QMimeData])
action (Qt.DropAction)
- Return type:
bool
- static notify(title: str | None, message: str | None, context: QgsDataItemGuiContext, level: Qgis.MessageLevel = Qgis.MessageLevel.Info, duration: int = -1, parent: QWidget | None = None)[source]¶
Notify the user showing a
message
withtitle
andlevel
If the context has a message bar the message will be shown in the message bar else a message dialog will be used.Since QGIS 3.18, the optional
duration
argument can be used to specify the message timeout in seconds. Ifduration
is set to 0, then the message must be manually dismissed by the user. A duration of -1 indicates that the default timeout for the messagelevel
should be used.Added in version 3.16.
- Parameters:
title (Optional[str])
message (Optional[str])
context (QgsDataItemGuiContext)
level (Qgis.MessageLevel = Qgis.MessageLevel.Info)
duration (int = -1)
parent (Optional[QWidget] = None)
- virtual populateContextMenu(self, item: QgsDataItem | None, menu: QMenu | None, selectedItems: Iterable[QgsDataItem], context: QgsDataItemGuiContext)[source]¶
Called when the given context
menu
is being populated for the givenitem
, allowing the provider to add its own actions and submenus to the context menu. Additionally, providers could potentially alter menus and actions added by other providers if desired, or use standard QMenu API to insert their items and submenus into the desired location within the context menu.The
selectedItems
list contains a list of ALL currently selected items within the browser view. Subclasses can utilize this list in order to create actions which operate on multiple items at once, e.g. to allow deletion of multiple layers from a database at once.When creating a context menu, this method is called for EVERY
QgsDataItemGuiProvider
within theQgsDataItemGuiProviderRegistry
. It is theQgsDataItemGuiProvider
subclass’ responsibility to test theitem
andselectedItems
for their properties and classes and decide what actions (if any) are appropriate to add to the contextmenu
.Care must be taken to correctly parent newly created sub menus and actions to the provided
menu
to avoid memory leaks.The
context
argument gives the wider context under which the context menu is being shown, and contains accessors for useful objects like the application message bar.The base class method has no effect.
- Parameters:
item (Optional[QgsDataItem])
menu (Optional[QMenu])
selectedItems (Iterable[QgsDataItem])
context (QgsDataItemGuiContext)
- virtual precedenceWhenPopulatingMenus(self) int [source]¶
Returns the provider’s precedence to use when populating context menus via calls to
populateContextMenu()
.Providers which return larger values will be called AFTER other providers when the menu is being populated. This allows them to nicely insert their corresponding menu items in the desired location with respect to existing items added by other providers.
The default implementation returns 0.
Added in version 3.22.
- Return type:
int
- virtual rename(self, item: QgsDataItem | None, name: str | None, context: QgsDataItemGuiContext) 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.10.
- Parameters:
item (Optional[QgsDataItem])
name (Optional[str])
context (QgsDataItemGuiContext)
- Return type:
bool