Class: QgsDataItemGuiProvider

class qgis.gui.QgsDataItemGuiProvider

Bases: sip.wrapper

Abstract base class for providers which affect how QgsDataItem items behave within the application GUI.

Providers must be registered via QgsDataItemGuiProviderRegistry.

New in version 3.6:

Methods

acceptDrop

Providers should return True if the drops are allowed (handleDrop() should be implemented in that case as well).

createParamWidget

Creates source widget from data item for QgsBrowserPropertiesWidget By default it returns None.

deleteLayer

Tries to permanently delete map layer representing the given item.

handleDoubleClick

Called when a user double clicks on an item.

handleDrop

Called when a user drops on an item.

name

Returns the provider's name.

notify

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.

populateContextMenu

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.

precedenceWhenPopulatingMenus

Returns the provider's precedence to use when populating context menus via calls to populateContextMenu().

rename

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

acceptDrop(self, item: QgsDataItem, context: QgsDataItemGuiContext) bool

Providers should return True if the drops are allowed (handleDrop() should be implemented in that case as well).

New in version 3.10.

Parameters:
Return type:

bool

createParamWidget(self, item: QgsDataItem, context: QgsDataItemGuiContext) QWidget

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()

New in version 3.10.

Parameters:
Return type:

QWidget

deleteLayer(self, item: QgsLayerItem, context: QgsDataItemGuiContext) bool

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.

New in version 3.10.

Parameters:
Return type:

bool

handleDoubleClick(self, item: QgsDataItem, context: QgsDataItemGuiContext) bool

Called when a user double clicks on an item. Providers should return True 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:
Return type:

bool

handleDrop(self, item: QgsDataItem, context: QgsDataItemGuiContext, data: QMimeData, action: Qt.DropAction) bool

Called when a user drops on an item. Providers should return True if the drop was handled and do not want other providers to handle the drop, and to prevent the default drop behavior for items.

New in version 3.10.

Parameters:
Return type:

bool

name(self) str

Returns the provider’s name.

Return type:

str

notify(title: str, message: str, context: QgsDataItemGuiContext, level: Qgis.MessageLevel = Qgis.MessageLevel.Info, duration: int = -1, parent: QWidget = None)

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.

Since QGIS 3.18, the optional duration argument can be used to specify the message timeout in seconds. If duration 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 message level should be used.

New in version 3.16.

Parameters:
  • title (str) –

  • message (str) –

  • context (QgsDataItemGuiContext) –

  • level (Qgis.MessageLevel = Qgis.MessageLevel.Info) –

  • duration (int = -1) –

  • parent (QWidget = None) –

populateContextMenu(self, item: QgsDataItem, menu: QMenu, selectedItems: Iterable[QgsDataItem], context: QgsDataItemGuiContext)

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. 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 the QgsDataItemGuiProviderRegistry. It is the QgsDataItemGuiProvider subclass’ responsibility to test the item and selectedItems for their properties and classes and decide what actions (if any) are appropriate to add to the context menu.

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:
precedenceWhenPopulatingMenus(self) int

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.

New in version 3.22.

Return type:

int

rename(self, item: QgsDataItem, name: str, context: QgsDataItemGuiContext) 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.10.

Parameters:
Return type:

bool