Class: QgsMimeDataUtils

Contains utility functions for working with MIME data.

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

QgsMimeDataUtils.Uri(encData: Optional[str]) Constructs URI from encoded data

QgsMimeDataUtils.Uri(layer: Optional[QgsMapLayer]) Constructs a URI corresponding to the specified layer.

Added in version 3.8.

QgsMimeDataUtils.Uri(a0: QgsMimeDataUtils.Uri)

data(self) str

Returns encoded representation of the object

Return type:

str

filePath: str

Path to file, if uri is associated with a file.

Added in version 3.22.

isValid(self) bool

Returns whether the object contains valid data

Return type:

bool

layerId: str

Layer ID, if uri is associated with a layer from a QgsProject.

Added in version 3.8.

layerType: str

Type of URI.

Recognized types include

  • “vector”: vector layers

  • “raster”: raster layers

  • “mesh”: mesh layers

  • “point-cloud”: point cloud layers (spelled with a dash since QGIS 3.42.0. In prior versions, there was no dash)

  • “vector-tile”: vector tile layers

  • “tiled-scene”: tiled scene layers

  • “annotation”: annotation layers

  • “group”: group layers

  • “plugin”: plugin layers

  • “custom”: custom types

  • “project”: QGS/QGZ project file

  • “directory”: directory path

Note: use QgsMapLayerFactory.typeToString() to convert from a Qgis.LayerType to a string (except for “custom”, “project” and “directory”)

Mime data from plugins may use additional custom layer types.

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.

Added in version 3.8.

Return type:

Optional[QgsMapLayer]

meshLayer(self, error: str | None)

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

Parameters:
  • owner – set to True if caller becomes owner

  • error (Optional[str]) -> (Optional[QgsMeshLayer]) – set to error message if cannot get raster

name: str

Human readable name to be used e.g. in layer tree

pId: str

Unique ID associated with application instance. Can be used to identify if mime data was created inside the current application instance or not.

Added in version 3.8.

providerKey: str

For “vector” / “raster” type: provider id. For “plugin” type: plugin layer type name. For “custom” type: key of its QgsCustomDropHandler For “project” and “directory” types: unused

rasterLayer(self, error: str | None)

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

Parameters:
  • owner – set to True if caller becomes owner

  • error (Optional[str]) -> (Optional[QgsRasterLayer]) – set to error message if cannot get raster

supportedCrs
supportedFormats
uri: str

Identifier of the data source recognized by its providerKey

vectorLayer(self, error: str | None)

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

Parameters:
  • owner – set to True if caller becomes owner

  • error (Optional[str]) -> (Optional[QgsVectorLayer]) – set to error message if cannot get vector

wkbType: WkbType

WKB type, if associated with a vector layer, or QgsWkbTypes.Unknown if not yet known.

Added in version 3.8.

static decodeUriList(data: QMimeData | None) List[QgsMimeDataUtils.Uri][source]
Parameters:

data (Optional[QMimeData])

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:

Optional[QMimeData]

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 (Optional[QMimeData])

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