Class: QgsMimeDataUtils

Contains utility functions for working with MIME data.

List of all members, including inherited members

Classes

Uri

Constructs invalid URI

Static Methods

decodeUriList

encodeUriList

Encodes a URI list to a new QMimeData object.

hasOriginatedFromCurrentAppInstance

Returns True if uri originated from the current QGIS application instance.

isUriList

layerTreeNodesToUriList

Returns encoded URI list from a list of layer tree nodes.

class qgis.core.QgsMimeDataUtils[source]

Bases: object

class Uri

Bases: object

Constructs invalid URI

__init__(encData: str | None)

Constructs URI from encoded data

Parameters:

encData (str|None)

__init__(layer: QgsMapLayer | None)

Constructs a URI corresponding to the specified layer.

Added in version 3.8.

Parameters:

layer (QgsMapLayer|None)

__init__(a0: QgsMimeDataUtils.Uri)
Parameters:

a0 (QgsMimeDataUtils.Uri)

data(self) → str

Returns encoded representation of the object

Return type:

str

filePath: str
isValid(self) → bool

Returns whether the object contains valid data

Return type:

bool

layerId: str
layerType: str
mapLayer(self) → QgsMapLayer | None

Returns the layer from the active project corresponding to this uri (if possible), otherwise returns None.

Unlike vectorLayer(), rasterLayer(), or meshLayer(), this method will not attempt to create a new layer corresponding to the URI.

Returns:

map layer if found in the active project, otherwise None

Added in version 3.8.

Deprecated since version 4.4: Use mapLayer() with explicit project parameter instead.

mapLayer(self, project: QgsProject|None) -> QgsMapLayer|None Returns the layer from project corresponding to this uri (if possible), otherwise returns None.

Unlike vectorLayer(), rasterLayer(), or meshLayer(), this method will not attempt to create a new layer corresponding to the URI.

Parameters:

project – used to obtain the layer

Return type:

QgsMapLayer|None

Returns:

map layer if found in the project, otherwise None

Added in version 4.4.

meshLayer(self)

Gets mesh layer from uri if possible, otherwise returns None and error is set

Returns:

  • mesh layer if successful, otherwise None

  • owner: set to True if caller becomes owner

  • error: set to error message if cannot get mesh

Deprecated since version 4.4: Use meshLayer() with explicit project parameter instead.

meshLayer(self, project: QgsProject|None) -> (QgsMeshLayer|None, bool, str) Gets mesh layer from uri if possible, otherwise returns None and error is set

Parameters:

project – project is used to obtain the layer

Return type:

(QgsMeshLayer|None, bool, str)

Returns:

  • mesh layer if successful, otherwise None

  • owner: set to True if caller becomes owner

  • error: set to error message if cannot get mesh

Added in version 4.4.

name: str
pId: str
providerKey: str
rasterLayer(self)

Gets raster layer from uri if possible, otherwise returns None and error is set

Returns:

  • raster layer if successful, otherwise None

  • owner: set to True if caller becomes owner

  • error: set to error message if cannot get raster

Deprecated since version 4.4: Use rasterLayer() with explicit project parameter instead.

rasterLayer(self, project: QgsProject|None) -> (QgsRasterLayer|None, bool, str) Gets raster layer from uri if possible, otherwise returns None and error is set

Parameters:

project – project is used to obtain the layer

Return type:

(QgsRasterLayer|None, bool, str)

Returns:

  • raster layer if successful, otherwise None

  • owner: set to True if caller becomes owner

  • error: set to error message if cannot get raster

Added in version 4.4.

supportedCrs
supportedFormats
uri: str
vectorLayer(self)

Gets vector layer from uri if possible, otherwise returns None and error is set

Returns:

  • vector layer if successful, otherwise None

  • owner: set to True if caller becomes owner

  • error: set to error message if cannot get vector

Deprecated since version 4.4: Use vectorLayer() with explicit project parameter instead.

vectorLayer(self, project: QgsProject|None) -> (QgsVectorLayer|None, bool, str) Gets vector layer from uri if possible, otherwise returns None and error is set

Parameters:

project – project is used to obtain the layer

Return type:

(QgsVectorLayer|None, bool, str)

Returns:

  • vector layer if successful, otherwise None

  • owner: set to True if caller becomes owner

  • error: set to error message if cannot get vector

Added in version 4.4.

wkbType: WkbType
static decodeUriList(data: QMimeData | None) → list[QgsMimeDataUtils.Uri][source]
Parameters:

data (QMimeData|None)

Return type:

list[QgsMimeDataUtils.Uri]

static encodeUriList(layers: Iterable[QgsMimeDataUtils.Uri]) → QMimeData | None[source]

Encodes a URI list to a new QMimeData object.

Parameters:

layers (Iterable[QgsMimeDataUtils.Uri])

Return type:

QMimeData|None

static hasOriginatedFromCurrentAppInstance(uri: QgsMimeDataUtils.Uri) → bool[source]

Returns True if uri originated from the current QGIS application instance.

Added in version 3.8.

Parameters:

uri (QgsMimeDataUtils.Uri)

Return type:

bool

static isUriList(data: QMimeData | None) → bool[source]
Parameters:

data (QMimeData|None)

Return type:

bool

static layerTreeNodesToUriList(nodes: Iterable[QgsLayerTreeNode]) → QByteArray[source]

Returns encoded URI list from a list of layer tree nodes.

Parameters:

nodes (Iterable[QgsLayerTreeNode])

Return type:

QByteArray