QGIS API Documentation 3.37.0-Master (684a802617f)
Loading...
Searching...
No Matches
Classes | Static Public Member Functions | List of all members
QgsLayerDefinition Class Reference

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

#include <qgslayerdefinition.h>

Classes

class  DependencySorter
 Class used to work with layer dependencies stored in a XML project or layer definition file. More...
 

Static Public Member Functions

static bool exportLayerDefinition (const QString &path, const QList< QgsLayerTreeNode * > &selectedTreeNodes, Qgis::FilePathType pathType, QString &errorMessage)
 Exports the selected layer tree nodes to a QLR file.
 
static bool exportLayerDefinition (const QString &path, const QList< QgsLayerTreeNode * > &selectedTreeNodes, QString &errorMessage)
 Exports the selected layer tree nodes to a QLR file.
 
static bool exportLayerDefinition (QDomDocument doc, const QList< QgsLayerTreeNode * > &selectedTreeNodes, QString &errorMessage, const QgsReadWriteContext &context)
 Exports the selected layer tree nodes to a QLR XML document.
 
static QDomDocument exportLayerDefinitionLayers (const QList< QgsMapLayer * > &layers, const QgsReadWriteContext &context)
 Returns the given layer as a layer definition document Layer definitions store the data source as well as styling and custom properties.
 
static bool loadLayerDefinition (const QString &path, QgsProject *project, QgsLayerTreeGroup *rootGroup, QString &errorMessage, Qgis::LayerTreeInsertionMethod insertMethod=Qgis::LayerTreeInsertionMethod::OptimalInInsertionGroup, const QgsLayerTreeRegistryBridge::InsertionPoint *insertPoint=nullptr)
 Loads the QLR at path into QGIS.
 
static bool loadLayerDefinition (QDomDocument doc, QgsProject *project, QgsLayerTreeGroup *rootGroup, QString &errorMessage, QgsReadWriteContext &context, Qgis::LayerTreeInsertionMethod insertMethod=Qgis::LayerTreeInsertionMethod::OptimalInInsertionGroup, const QgsLayerTreeRegistryBridge::InsertionPoint *insertPoint=nullptr)
 Loads the QLR from the XML document.
 
static QList< QgsMapLayer * > loadLayerDefinitionLayers (const QString &qlrfile)
 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.
 
static QList< QgsMapLayer * > loadLayerDefinitionLayers (QDomDocument &document, QgsReadWriteContext &context)
 Creates new layers from a layer definition document.
 

Detailed Description

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.

Definition at line 45 of file qgslayerdefinition.h.

Member Function Documentation

◆ exportLayerDefinition() [1/3]

bool QgsLayerDefinition::exportLayerDefinition ( const QString &  path,
const QList< QgsLayerTreeNode * > &  selectedTreeNodes,
Qgis::FilePathType  pathType,
QString &  errorMessage 
)
static

Exports the selected layer tree nodes to a QLR file.

Parameters
pathfile path for exported QLR file
selectedTreeNodeslayer tree nodes to include in the QLR file
pathTypespecifies whether absolute or relative file paths should be used.
errorMessagewill be set to any error messages generated during the export
Returns
true if the export was successful
Since
QGIS 3.22

Definition at line 225 of file qgslayerdefinition.cpp.

◆ exportLayerDefinition() [2/3]

bool QgsLayerDefinition::exportLayerDefinition ( const QString &  path,
const QList< QgsLayerTreeNode * > &  selectedTreeNodes,
QString &  errorMessage 
)
static

Exports the selected layer tree nodes to a QLR file.

This method uses the QgsProject::instance()'s file path setting to determine whether absolute or relative paths are written. Use the variant with an explicit argument for file path type for control over this setting.

Parameters
pathfile path for exported QLR file
selectedTreeNodeslayer tree nodes to include in the QLR file
errorMessagewill be set to any error messages generated during the export
Returns
true if the export was successful

Definition at line 220 of file qgslayerdefinition.cpp.

◆ exportLayerDefinition() [3/3]

bool QgsLayerDefinition::exportLayerDefinition ( QDomDocument  doc,
const QList< QgsLayerTreeNode * > &  selectedTreeNodes,
QString &  errorMessage,
const QgsReadWriteContext context 
)
static

Exports the selected layer tree nodes to a QLR XML document.

Definition at line 256 of file qgslayerdefinition.cpp.

◆ exportLayerDefinitionLayers()

QDomDocument QgsLayerDefinition::exportLayerDefinitionLayers ( const QList< QgsMapLayer * > &  layers,
const QgsReadWriteContext context 
)
static

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.

See also
exportLayerDefinition()

Definition at line 289 of file qgslayerdefinition.cpp.

◆ loadLayerDefinition() [1/2]

bool QgsLayerDefinition::loadLayerDefinition ( const QString &  path,
QgsProject project,
QgsLayerTreeGroup rootGroup,
QString &  errorMessage,
Qgis::LayerTreeInsertionMethod  insertMethod = Qgis::LayerTreeInsertionMethod::OptimalInInsertionGroup,
const QgsLayerTreeRegistryBridge::InsertionPoint insertPoint = nullptr 
)
static

Loads the QLR at path into QGIS.

New layers are added to given project into layer tree specified by rootGroup

Parameters
pathfile path to the qlr
projectthe current project
rootGroupthe layer tree group to insert the qlr content
errorMessagethe returned error message
insertMethodmethod for layer tree (since QGIS 3.38)
insertPointdescribes where in rootGroup the qlr layers/groups shall be inserted (since QGIS 3.38)
Returns
true in case of success

Definition at line 41 of file qgslayerdefinition.cpp.

◆ loadLayerDefinition() [2/2]

bool QgsLayerDefinition::loadLayerDefinition ( QDomDocument  doc,
QgsProject project,
QgsLayerTreeGroup rootGroup,
QString &  errorMessage,
QgsReadWriteContext context,
Qgis::LayerTreeInsertionMethod  insertMethod = Qgis::LayerTreeInsertionMethod::OptimalInInsertionGroup,
const QgsLayerTreeRegistryBridge::InsertionPoint insertPoint = nullptr 
)
static

Loads the QLR from the XML document.

New layers are added to given project into layer tree specified by rootGroup

Parameters
docthe xml document
projectthe current project
rootGroupthe layer tree group to insert the qlr content
errorMessagethe returned error message
contextthe read write context
insertMethodmethod for layer tree (since QGIS 3.38)
insertPointdescribes where in rootGroup the qlr layers/groups shall be inserted (since QGIS 3.38)
Returns
true in case of success

Definition at line 68 of file qgslayerdefinition.cpp.

◆ loadLayerDefinitionLayers() [1/2]

QList< QgsMapLayer * > QgsLayerDefinition::loadLayerDefinitionLayers ( const QString &  qlrfile)
static

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.

See also
loadLayerDefinition()

Definition at line 389 of file qgslayerdefinition.cpp.

◆ loadLayerDefinitionLayers() [2/2]

QList< QgsMapLayer * > QgsLayerDefinition::loadLayerDefinitionLayers ( QDomDocument &  document,
QgsReadWriteContext context 
)
static

Creates new layers from a layer definition document.

This is a low-level routine that does not resolve layer ID conflicts, dependencies and joins

See also
loadLayerDefinition()

Definition at line 306 of file qgslayerdefinition.cpp.


The documentation for this class was generated from the following files: