Class: QgsAbstractDataSourceWidget

Abstract base class for Data Source widgets to create connections and add layers.

This class provides common functionality and the interface for all source select dialogs used by data providers to configure data sources and add layers.

The implementation is generic enough to handle other layer search and selection widgets.

Class Hierarchy

Inheritance diagram of qgis.gui.QgsAbstractDataSourceWidget

Base classes

QDialog

QWidget

QObject

QPaintDevice

Subclasses

QgsAbstractDbSourceSelect

Base class for database source widget selectors.

QgsLayerMetadataSearchWidget

Offers layer metadata search and filtering.

QgsOWSSourceSelect

Dialog to create connections and add layers WCS etc.

Methods

addButton

Returns the add Button

browserModel

Returns the associated browser model (may be None).

setupButtons

Connect the ok and apply/add buttons to the slots

widgetMode

Returns the widget mode

Virtual Methods

In PyQGIS, only methods marked as virtual can be safely overridden in a Python subclass of QgsAbstractDataSourceWidget. See the FAQ for more details.

addButtonClicked

Triggered when the add button is clicked, the add layer signal is emitted Concrete classes should implement the right behavior depending on the layer being added.

configureFromUri

Configure the widget from a layer uri by selecting the layer path or connection options.

mapCanvas

Returns the dialog map canvas

refresh

Triggered when the provider's connections need to be refreshed The default implementation does nothing

reset

Called when this source select widget is being shown in a "new and clean" dialog.

setBrowserModel

Sets a browser model to use with the widget.

setMapCanvas

Sets the dialog map canvas

Signals

addDatabaseLayers

Emitted when a DB layer has been selected for addition

addLayer

Emitted when a layer has been selected for addition.

addMeshLayer

Emitted when a mesh layer has been selected for addition.

addPointCloudLayer

Emitted when a point cloud layer has been selected for addition.

addRasterLayer

Emitted when a raster layer has been selected for addition

addRasterLayers

Emitted when one or more GDAL supported layers are selected for addition

addVectorLayer

Emitted when a vector layer has been selected for addition.

addVectorLayers

Emitted when one or more OGR supported layers are selected for addition

addVectorTileLayer

Emitted when a vector tile layer has been selected for addition.

connectionsChanged

Emitted when the provider's connections have changed This signal is normally forwarded the app and used to refresh browser items

enableButtons

Emitted when the ok/add buttons should be enabled/disabled

progress

Emitted when a progress dialog is shown by the provider dialog.

progressMessage

Emitted when a progress dialog is shown by the provider dialog

pushMessage

Emitted when a message with title and level must be shown to the user using the parent visible message bar

replaceVectorLayer

Emitted when a layer needs to be replaced

class qgis.gui.QgsAbstractDataSourceWidget[source]

Bases: QDialog

__init__(parent: QWidget | None = None, fl: Qt.WindowFlags | Qt.WindowType = QgsGuiUtils.ModalDialogFlags, widgetMode: QgsProviderRegistry.WidgetMode = QgsProviderRegistry.WidgetMode.Standalone)

Constructor

Parameters:
  • parent (Optional[QWidget] = None)

  • fl (Union[Qt.WindowFlags, Qt.WindowType] = QgsGuiUtils.ModalDialogFlags)

  • widgetMode (QgsProviderRegistry.WidgetMode = QgsProviderRegistry.WidgetMode.Standalone)

addButton(self) QPushButton | None[source]

Returns the add Button

Return type:

Optional[QPushButton]

virtual addButtonClicked(self)[source]

Triggered when the add button is clicked, the add layer signal is emitted Concrete classes should implement the right behavior depending on the layer being added.

signal addDatabaseLayers(paths: List[str], providerKey: str)[source]

Emitted when a DB layer has been selected for addition

Parameters:
  • paths (List[str])

  • providerKey (str)

signal addLayer(type: Qgis.LayerType, url: str, baseName: str, providerKey: str)[source]

Emitted when a layer has been selected for addition.

This is a generic method, intended for replacing the specific layer type signals implemented above.

Warning

For QGIS versions < 4.x, the specific layer type added signals must be emitted for vector, raster, mesh, vector tile and point cloud layers in addition to this signal.

Added in version 3.34.

Parameters:
signal addMeshLayer[source]

Emitted when a mesh layer has been selected for addition.

Deprecated since version 3.40: Use addLayer() instead.

signal addPointCloudLayer[source]

Emitted when a point cloud layer has been selected for addition.

Deprecated since version 3.40: Use addLayer() instead.

signal addRasterLayer[source]

Emitted when a raster layer has been selected for addition

Deprecated since version 3.40: Use addLayer() instead.

signal addRasterLayers(layersList: List[str])[source]

Emitted when one or more GDAL supported layers are selected for addition

Parameters:

layersList (List[str]) – list of layers protocol URIs

Added in version 3.20.

signal addVectorLayer[source]

Emitted when a vector layer has been selected for addition.

If providerKey is not specified, the default provider key associated with the source will be used.

Deprecated since version 3.40: Use addLayer() instead.

signal addVectorLayers(layerList: List[str], encoding: str, dataSourceType: str)[source]

Emitted when one or more OGR supported layers are selected for addition

Parameters:
  • layerList (List[str]) – list of layers protocol URIs

  • encoding (str) – encoding

  • dataSourceType (str) – string (can be “file” or “database”)

signal addVectorTileLayer[source]

Emitted when a vector tile layer has been selected for addition.

Deprecated since version 3.40: Use addLayer() instead.

browserModel(self) QgsBrowserModel | None[source]

Returns the associated browser model (may be None).

Added in version 3.18.

Return type:

Optional[QgsBrowserModel]

virtual configureFromUri(self, uri: str | None) bool[source]

Configure the widget from a layer uri by selecting the layer path or connection options. The base implementation does nothing and returns False: providers with ConfigureSourceSelectFromUri capability must override to implement this functionality.

Return type:

bool

Returns:

True on success.

Note

Not all data providers may be able to configure the widget from the provided uri, in that case this method returns False.

Added in version 3.38.

Parameters:

uri (Optional[str])

signal connectionsChanged[source]

Emitted when the provider’s connections have changed This signal is normally forwarded the app and used to refresh browser items

signal enableButtons(enable: bool)[source]

Emitted when the ok/add buttons should be enabled/disabled

Parameters:

enable (bool)

virtual mapCanvas(self) QgsMapCanvas | None[source]

Returns the dialog map canvas

See also

setMapCanvas()

Return type:

Optional[QgsMapCanvas]

signal progress[source]

Emitted when a progress dialog is shown by the provider dialog.

Deprecated since version 3.4: This signal is no longer used. Use QgsProxyProgressTask instead to show progress reports.

signal progressMessage(message: str)[source]

Emitted when a progress dialog is shown by the provider dialog

Parameters:

message (str)

signal pushMessage(title: str, message: str, level: Qgis.MessageLevel = Qgis.MessageLevel.Info)[source]

Emitted when a message with title and level must be shown to the user using the parent visible message bar

Added in version 3.14.

Parameters:
  • title (str)

  • message (str)

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

virtual refresh(self)[source]

Triggered when the provider’s connections need to be refreshed The default implementation does nothing

signal replaceVectorLayer(oldId: str, source: str, name: str, provider: str)[source]

Emitted when a layer needs to be replaced

Parameters:
  • oldId (str) – old layer ID

  • source (str) – URI of the layer

  • name (str) – of the layer

  • provider (str) – key

virtual reset(self)[source]

Called when this source select widget is being shown in a “new and clean” dialog.

The data source manager recycles existing source select widgets but will call this method on every reopening. This should clear any selection that has previously been done.

Added in version 3.10.

virtual setBrowserModel(self, model: QgsBrowserModel | None)[source]

Sets a browser model to use with the widget.

See also

browserModel()

Added in version 3.18.

Parameters:

model (Optional[QgsBrowserModel])

virtual setMapCanvas(self, mapCanvas: QgsMapCanvas | None)[source]

Sets the dialog map canvas

See also

mapCanvas()

Parameters:

mapCanvas (Optional[QgsMapCanvas])

setupButtons(self, buttonBox: QDialogButtonBox | None)[source]

Connect the ok and apply/add buttons to the slots

Parameters:

buttonBox (Optional[QDialogButtonBox])

widgetMode(self) QgsProviderRegistry.WidgetMode[source]

Returns the widget mode

Return type:

QgsProviderRegistry.WidgetMode