Class: QgsLayerDefinition

class qgis.core.QgsLayerDefinition

Bases: sip.wrapper

The QgsLayerDefinition class holds generic methods for loading/exporting QLR files.

QLR files are an export of the layer xml including the style and datasource location. There is no link to the QLR file once loaded. Consider the QLR file a mini project file for layers and styles. QLR files also store the layer tree info for the exported layers, including group information.

Enums

Methods

exportLayerDefinition Export the selected layer tree nodes to a QLR file
exportLayerDefinitionLayers Returns the given layer as a layer definition document Layer definitions store the data source as well as styling and custom properties.
loadLayerDefinition Loads the QLR at path into QGIS.
loadLayerDefinitionLayers Creates new layers from a layer definition document.

Signals

Attributes

class DependencySorter(doc: QDomDocument)

Bases: sip.wrapper

Constructor

Parameters:doc – The XML document containing maplayer elements

QgsLayerDefinition.DependencySorter(fileName: str) Constructor

Parameters:fileName – The filename where the XML document is stored

QgsLayerDefinition.DependencySorter(QgsLayerDefinition.DependencySorter)

Class used to work with layer dependencies stored in a XML project or layer definition file

hasCycle(self) → bool

Whether some cyclic dependency has been detected

hasMissingDependency(self) → bool

Whether some dependency is missing

sortedLayerIds(self) → List[str]

Gets the layer IDs in an order where they can be loaded incrementally without dependency break

sortedLayerNodes(self) → object

Gets the layer nodes in an order where they can be loaded incrementally without dependency break

exportLayerDefinition(path: str, selectedTreeNodes: object) → Tuple[bool, str]

Export the selected layer tree nodes to a QLR file

exportLayerDefinition(doc: QDomDocument, selectedTreeNodes: Iterable[QgsLayerTreeNode], context: QgsReadWriteContext) -> Tuple[bool, str] Export the selected layer tree nodes to a QLR-XML document

exportLayerDefinitionLayers(layers: object, context: QgsReadWriteContext) → QDomDocument

Returns the given layer as a layer definition document Layer definitions store the data source as well as styling and custom properties.

Layer definitions can be used to load a layer and styling all from a single file.

This is a low-level routine that does not write layer tree.

loadLayerDefinition(path: str, project: QgsProject, rootGroup: QgsLayerTreeGroup) → Tuple[bool, str]

Loads the QLR at path into QGIS. New layers are added to given project into layer tree specified by rootGroup

loadLayerDefinition(doc: QDomDocument, project: QgsProject, rootGroup: QgsLayerTreeGroup, context: QgsReadWriteContext) -> Tuple[bool, str] Loads the QLR from the XML document. New layers are added to given project into layer tree specified by rootGroup

loadLayerDefinitionLayers(document: QDomDocument, context: QgsReadWriteContext) → List[QgsMapLayer]

Creates new layers from a layer definition document. This is a low-level routine that does not resolve layer ID conflicts, dependencies and joins

loadLayerDefinitionLayers(qlrfile: str) -> List[QgsMapLayer] Creates new layers from a layer definition file (.QLR) This is a low-level routine that does not resolve layer ID conflicts, dependencies and joins