QGIS API Documentation 3.41.0-Master (45a0abf3bec)
Loading...
Searching...
No Matches
qgslayerdefinition.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgslayerdefinition.cpp
3 ---------------------
4 begin : January 2015
5 copyright : (C) 2015 by Nathan Woodrow
6 email : woodrow dot nathan at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15#include <QFileInfo>
16#include <QFile>
17#include <QDir>
18#include <QTextStream>
19
20#include "qgslayerdefinition.h"
21#include "qgslogger.h"
22#include "qgsmaplayer.h"
23#include "qgspathresolver.h"
24#include "qgspluginlayer.h"
26#include "qgsproject.h"
27#include "qgsrasterlayer.h"
28#include "qgsreadwritecontext.h"
29#include "qgsvectorlayer.h"
30#include "qgsvectortilelayer.h"
31#include "qgstiledscenelayer.h"
32#include "qgsapplication.h"
33#include "qgsmaplayerfactory.h"
34#include "qgsmeshlayer.h"
35#include "qgspointcloudlayer.h"
36#include "qgsfileutils.h"
37#include "qgsgrouplayer.h"
38#include "qgslayertreegroup.h"
39#include "qgslayertreelayer.h"
40
41bool QgsLayerDefinition::loadLayerDefinition( const QString &path, QgsProject *project, QgsLayerTreeGroup *rootGroup, QString &errorMessage, Qgis::LayerTreeInsertionMethod insertMethod, const QgsLayerTreeRegistryBridge::InsertionPoint *insertPoint )
42{
43 QFile file( path );
44 if ( !file.open( QIODevice::ReadOnly ) )
45 {
46 errorMessage = QStringLiteral( "Can not open file" );
47 return false;
48 }
49
50 QDomDocument doc;
51 QString message;
52 if ( !doc.setContent( &file, &message ) )
53 {
54 errorMessage = message;
55 return false;
56 }
57
58 const QFileInfo fileinfo( file );
59 QDir::setCurrent( fileinfo.absoluteDir().path() );
60
61 QgsReadWriteContext context;
62 context.setPathResolver( QgsPathResolver( path ) );
63 context.setProjectTranslator( project );
64
65 return loadLayerDefinition( doc, project, rootGroup, errorMessage, context, insertMethod, insertPoint );
66}
67
68bool QgsLayerDefinition::loadLayerDefinition( QDomDocument doc, QgsProject *project, QgsLayerTreeGroup *rootGroup, QString &errorMessage, QgsReadWriteContext &context, Qgis::LayerTreeInsertionMethod insertMethod, const QgsLayerTreeRegistryBridge::InsertionPoint *insertPoint )
69{
70 errorMessage.clear();
71
73
74 // reorder maplayer nodes based on dependencies
75 // dependencies have to be resolved before IDs get changed
76 const DependencySorter depSorter( doc );
77 if ( !depSorter.hasMissingDependency() )
78 {
79 const QVector<QDomNode> sortedLayerNodes = depSorter.sortedLayerNodes();
80 QVector<QDomNode> clonedSorted;
81 const auto constSortedLayerNodes = sortedLayerNodes;
82 for ( const QDomNode &node : constSortedLayerNodes )
83 {
84 clonedSorted << node.cloneNode();
85 }
86 QDomNode layersNode = doc.elementsByTagName( QStringLiteral( "maplayers" ) ).at( 0 );
87 // replace old children with new ones
88 QDomNode childNode = layersNode.firstChild();
89 for ( int i = 0; ! childNode.isNull(); i++ )
90 {
91 layersNode.replaceChild( clonedSorted.at( i ), childNode );
92 childNode = childNode.nextSibling();
93 }
94 }
95 // if a dependency is missing, we still try to load layers, since dependencies may already be loaded
96
97 // IDs of layers should be changed otherwise we may have more then one layer with the same id
98 // We have to replace the IDs before we load them because it's too late once they are loaded
99 const QDomNodeList treeLayerNodes = doc.elementsByTagName( QStringLiteral( "layer-tree-layer" ) );
100 for ( int i = 0; i < treeLayerNodes.length(); ++i )
101 {
102 const QDomNode treeLayerNode = treeLayerNodes.item( i );
103 QDomElement treeLayerElem = treeLayerNode.toElement();
104 const QString oldid = treeLayerElem.attribute( QStringLiteral( "id" ) );
105 const QString layername = treeLayerElem.attribute( QStringLiteral( "name" ) );
106 const QString newid = QgsMapLayer::generateId( layername );
107 treeLayerElem.setAttribute( QStringLiteral( "id" ), newid );
108
109 // Replace IDs for map layers
110 const QDomNodeList ids = doc.elementsByTagName( QStringLiteral( "id" ) );
111 QDomNode idnode = ids.at( 0 );
112 for ( int j = 0; ! idnode.isNull() ; ++j )
113 {
114 idnode = ids.at( j );
115 const QDomElement idElem = idnode.toElement();
116 if ( idElem.text() == oldid )
117 {
118 idElem.firstChild().setNodeValue( newid );
119 }
120 }
121
122 // change layer IDs for vector joins
123 const QDomNodeList vectorJoinNodes = doc.elementsByTagName( QStringLiteral( "join" ) ); // TODO: Find a better way of searching for vectorjoins, there might be other <join> elements within the project.
124 for ( int j = 0; j < vectorJoinNodes.size(); ++j )
125 {
126 const QDomNode joinNode = vectorJoinNodes.at( j );
127 const QDomElement joinElement = joinNode.toElement();
128 if ( joinElement.attribute( QStringLiteral( "joinLayerId" ) ) == oldid )
129 {
130 joinNode.toElement().setAttribute( QStringLiteral( "joinLayerId" ), newid );
131 }
132 }
133
134 // change IDs of dependencies
135 const QDomNodeList dataDeps = doc.elementsByTagName( QStringLiteral( "dataDependencies" ) );
136 for ( int i = 0; i < dataDeps.size(); i++ )
137 {
138 const QDomNodeList layers = dataDeps.at( i ).childNodes();
139 for ( int j = 0; j < layers.size(); j++ )
140 {
141 QDomElement elt = layers.at( j ).toElement();
142 if ( elt.attribute( QStringLiteral( "id" ) ) == oldid )
143 {
144 elt.setAttribute( QStringLiteral( "id" ), newid );
145 }
146 }
147 }
148
149 // Change IDs of widget config values
150 const QDomNodeList widgetConfig = doc.elementsByTagName( QStringLiteral( "editWidget" ) );
151 for ( int i = 0; i < widgetConfig.size(); i++ )
152 {
153 const QDomNodeList config = widgetConfig.at( i ).childNodes();
154 for ( int j = 0; j < config.size(); j++ )
155 {
156 const QDomNodeList optMap = config.at( j ).childNodes();
157 for ( int z = 0; z < optMap.size(); z++ )
158 {
159 const QDomNodeList opts = optMap.at( z ).childNodes();
160 for ( int k = 0; k < opts.size(); k++ )
161 {
162 QDomElement opt = opts.at( k ).toElement();
163 if ( opt.attribute( QStringLiteral( "value" ) ) == oldid )
164 {
165 opt.setAttribute( QStringLiteral( "value" ), newid );
166 }
167 }
168 }
169 }
170 }
171 }
172
173 QDomElement layerTreeElem = doc.documentElement().firstChildElement( QStringLiteral( "layer-tree-group" ) );
174 bool loadInLegend = true;
175 if ( !layerTreeElem.isNull() )
176 {
177 root->readChildrenFromXml( layerTreeElem, context );
178 loadInLegend = false;
179 }
180
181 const QList<QgsMapLayer *> layers = QgsLayerDefinition::loadLayerDefinitionLayersInternal( doc, context, errorMessage );
182
183 project->addMapLayers( layers, loadInLegend );
184
185 // Now that all layers are loaded, refresh the vectorjoins to get the joined fields
186 const auto constLayers = layers;
187 for ( QgsMapLayer *layer : constLayers )
188 {
189 layer->resolveReferences( project );
190 }
191
192 root->resolveReferences( project );
193
194 const QList<QgsLayerTreeNode *> nodes = root->children();
195 root->abandonChildren();
196 delete root;
197
198 switch ( insertMethod )
199 {
201 if ( insertPoint )
202 {
203 insertPoint->group->insertChildNodes( insertPoint->position, nodes );
204 }
205 else
206 {
207 rootGroup->insertChildNodes( -1, nodes );
208 }
209 break;
211 rootGroup->insertChildNodes( 0, nodes );
212 break;
213 default: //Keep current behavior for Qgis::LayerTreeInsertionMethod::OptimalInInsertionGroup
214 rootGroup->insertChildNodes( -1, nodes );
215 }
216
217 return true;
218}
219
220bool QgsLayerDefinition::exportLayerDefinition( const QString &path, const QList<QgsLayerTreeNode *> &selectedTreeNodes, QString &errorMessage )
221{
222 return exportLayerDefinition( path, selectedTreeNodes, QgsProject::instance()->filePathStorage(), errorMessage ); // skip-keyword-check
223}
224
225bool QgsLayerDefinition::exportLayerDefinition( const QString &p, const QList<QgsLayerTreeNode *> &selectedTreeNodes, Qgis::FilePathType pathType, QString &errorMessage )
226{
227 const QString path = QgsFileUtils::ensureFileNameHasExtension( p, { QStringLiteral( "qlr" )} );
228
229 QFile file( path );
230 if ( !file.open( QFile::WriteOnly | QFile::Truncate ) )
231 {
232 errorMessage = file.errorString();
233 return false;
234 }
235
236 QgsReadWriteContext context;
237 switch ( pathType )
238 {
240 context.setPathResolver( QgsPathResolver( QString() ) );
241 break;
243 context.setPathResolver( QgsPathResolver( path ) );
244 break;
245 }
246
247 const QDomDocument doc( QStringLiteral( "qgis-layer-definition" ) );
248 if ( !exportLayerDefinition( doc, selectedTreeNodes, errorMessage, context ) )
249 return false;
250
251 QTextStream qlayerstream( &file );
252 doc.save( qlayerstream, 2 );
253 return true;
254}
255
256bool QgsLayerDefinition::exportLayerDefinition( QDomDocument doc, const QList<QgsLayerTreeNode *> &selectedTreeNodes, QString &errorMessage, const QgsReadWriteContext &context )
257{
258 Q_UNUSED( errorMessage )
259 QDomElement qgiselm = doc.createElement( QStringLiteral( "qlr" ) );
260 doc.appendChild( qgiselm );
261 const QList<QgsLayerTreeNode *> nodes = selectedTreeNodes;
263 const auto constNodes = nodes;
264 for ( QgsLayerTreeNode *node : constNodes )
265 {
266 QgsLayerTreeNode *newnode = node->clone();
267 root->addChildNode( newnode );
268 }
269 root->writeXml( qgiselm, context );
270
271 QDomElement layerselm = doc.createElement( QStringLiteral( "maplayers" ) );
272 const QList<QgsLayerTreeLayer *> layers = root->findLayers();
273 const auto constLayers = layers;
274 for ( QgsLayerTreeLayer *layer : constLayers )
275 {
276 if ( ! layer->layer() )
277 {
278 QgsDebugMsgLevel( QStringLiteral( "Not a valid map layer: skipping %1" ).arg( layer->name( ) ), 4 );
279 continue;
280 }
281 QDomElement layerelm = doc.createElement( QStringLiteral( "maplayer" ) );
282 layer->layer()->writeLayerXml( layerelm, doc, context );
283 layerselm.appendChild( layerelm );
284 }
285 qgiselm.appendChild( layerselm );
286 return true;
287}
288
289QDomDocument QgsLayerDefinition::exportLayerDefinitionLayers( const QList<QgsMapLayer *> &layers, const QgsReadWriteContext &context )
290{
291 QDomDocument doc( QStringLiteral( "qgis-layer-definition" ) );
292 QDomElement qgiselm = doc.createElement( QStringLiteral( "qlr" ) );
293 doc.appendChild( qgiselm );
294 QDomElement layerselm = doc.createElement( QStringLiteral( "maplayers" ) );
295 const auto constLayers = layers;
296 for ( QgsMapLayer *layer : constLayers )
297 {
298 QDomElement layerelm = doc.createElement( QStringLiteral( "maplayer" ) );
299 layer->writeLayerXml( layerelm, doc, context );
300 layerselm.appendChild( layerelm );
301 }
302 qgiselm.appendChild( layerselm );
303 return doc;
304}
305
306QList<QgsMapLayer *> QgsLayerDefinition::loadLayerDefinitionLayers( QDomDocument &document, QgsReadWriteContext &context )
307{
308 QString errorMessage;
309 return loadLayerDefinitionLayersInternal( document, context, errorMessage );
310}
311
312QList<QgsMapLayer *> QgsLayerDefinition::loadLayerDefinitionLayersInternal( QDomDocument &document, QgsReadWriteContext &context, QString &errorMessage )
313{
314 QList<QgsMapLayer *> layers;
315 QDomElement layerElem = document.documentElement().firstChildElement( QStringLiteral( "projectlayers" ) ).firstChildElement( QStringLiteral( "maplayer" ) );
316 // For QLR:
317 if ( layerElem.isNull() )
318 {
319 layerElem = document.documentElement().firstChildElement( QStringLiteral( "maplayers" ) ).firstChildElement( QStringLiteral( "maplayer" ) );
320 }
321
322 while ( ! layerElem.isNull() )
323 {
324 const QString type = layerElem.attribute( QStringLiteral( "type" ) );
325 QgsMapLayer *layer = nullptr;
326
327 bool ok = false;
328 const Qgis::LayerType layerType = QgsMapLayerFactory::typeFromString( type, ok );
329 if ( ok )
330 {
331 switch ( layerType )
332 {
334 layer = new QgsVectorLayer();
335 break;
336
338 layer = new QgsRasterLayer();
339 break;
340
342 {
343 const QString typeName = layerElem.attribute( QStringLiteral( "name" ) );
345 break;
346 }
347
349 layer = new QgsMeshLayer();
350 break;
351
353 layer = new QgsVectorTileLayer;
354 break;
355
357 layer = new QgsPointCloudLayer();
358 break;
359
361 layer = new QgsTiledSceneLayer;
362 break;
363
366 break;
367
369 break;
370 }
371 }
372
373 if ( layer )
374 {
375 // always add the layer, even if the source is invalid -- this allows users to fix the source
376 // at a later stage and still retain all the layer properties intact
377 layer->readLayerXml( layerElem, context );
378 layers << layer;
379 }
380 else
381 {
382 errorMessage = QObject::tr( "Unsupported layer type: %1" ).arg( type );
383 }
384 layerElem = layerElem.nextSiblingElement( QStringLiteral( "maplayer" ) );
385 }
386 return layers;
387}
388
389QList<QgsMapLayer *> QgsLayerDefinition::loadLayerDefinitionLayers( const QString &qlrfile )
390{
391 QFile file( qlrfile );
392 if ( !file.open( QIODevice::ReadOnly ) )
393 {
394 QgsDebugError( QStringLiteral( "Can't open file" ) );
395 return QList<QgsMapLayer *>();
396 }
397
398 QDomDocument doc;
399 if ( !doc.setContent( &file ) )
400 {
401 QgsDebugError( QStringLiteral( "Can't set content" ) );
402 return QList<QgsMapLayer *>();
403 }
404
405 QgsReadWriteContext context;
406 context.setPathResolver( QgsPathResolver( qlrfile ) );
407 //no project translator defined here
409}
410
411void QgsLayerDefinition::DependencySorter::init( const QDomDocument &doc )
412{
413 // Determine a loading order of layers based on a graph of dependencies
414 QMap< QString, QVector< QString > > dependencies;
415 QStringList sortedLayers;
416 QList< QPair<QString, QDomNode> > layersToSort;
417 QStringList layerIds;
418
419 QDomElement layerElem = doc.documentElement().firstChildElement( QStringLiteral( "projectlayers" ) ).firstChildElement( QStringLiteral( "maplayer" ) );
420 // For QLR:
421 if ( layerElem.isNull() )
422 {
423 layerElem = doc.documentElement().firstChildElement( QStringLiteral( "maplayers" ) ).firstChildElement( QStringLiteral( "maplayer" ) );
424 }
425 // For tests (I don't know if there is a real use case for such a document except for test_qgslayerdefinition.py)
426 if ( layerElem.isNull() )
427 {
428 layerElem = doc.documentElement().firstChildElement( QStringLiteral( "maplayer" ) );
429 }
430
431 const QDomElement &firstElement { layerElem };
432
433 QVector<QString> deps; //avoid expensive allocation for list for every iteration
434 while ( !layerElem.isNull() )
435 {
436 deps.resize( 0 ); // preserve capacity - don't use clear
437
438 const QString id = layerElem.namedItem( QStringLiteral( "id" ) ).toElement().text();
439 layerIds << id;
440
441 // dependencies for this layer
442 const QDomElement layerDependenciesElem = layerElem.firstChildElement( QStringLiteral( "layerDependencies" ) );
443 if ( !layerDependenciesElem.isNull() )
444 {
445 const QDomNodeList dependencyList = layerDependenciesElem.elementsByTagName( QStringLiteral( "layer" ) );
446 for ( int j = 0; j < dependencyList.size(); ++j )
447 {
448 const QDomElement depElem = dependencyList.at( j ).toElement();
449 deps << depElem.attribute( QStringLiteral( "id" ) );
450 }
451 }
452 dependencies[id] = deps;
453
454 if ( deps.empty() )
455 {
456 sortedLayers << id;
457 mSortedLayerNodes << layerElem;
458 mSortedLayerIds << id;
459 }
460 else
461 {
462 layersToSort << qMakePair( id, layerElem );
463 mDependentLayerIds.insert( id );
464 }
465 layerElem = layerElem.nextSiblingElement( );
466 }
467
468 // check that all dependencies are present
469 const auto constDependencies = dependencies;
470 for ( const QVector< QString > &ids : constDependencies )
471 {
472 const auto constIds = ids;
473 for ( const QString &depId : constIds )
474 {
475 if ( !dependencies.contains( depId ) )
476 {
477 // some dependencies are not satisfied
478 mHasMissingDependency = true;
479 layerElem = firstElement;
480 while ( ! layerElem.isNull() )
481 {
482 mSortedLayerNodes << layerElem;
483 layerElem = layerElem.nextSiblingElement( );
484 }
485 mSortedLayerIds = layerIds;
486 return;
487 }
488 }
489 }
490
491 // cycles should be very rare, since layers with cyclic dependencies may only be created by
492 // manually modifying the project file
493 mHasCycle = false;
494
495 while ( !layersToSort.empty() && !mHasCycle )
496 {
497 QList< QPair<QString, QDomNode> >::iterator it = layersToSort.begin();
498 while ( it != layersToSort.end() )
499 {
500 const QString idToSort = it->first;
501 const QDomNode node = it->second;
502 mHasCycle = true;
503 bool resolved = true;
504 const auto deps { dependencies.value( idToSort ) };
505 for ( const QString &dep : deps )
506 {
507 if ( !sortedLayers.contains( dep ) )
508 {
509 resolved = false;
510 break;
511 }
512 }
513 if ( resolved ) // dependencies for this layer are resolved
514 {
515 sortedLayers << idToSort;
516 mSortedLayerNodes << node;
517 mSortedLayerIds << idToSort;
518 it = layersToSort.erase( it ); // erase and go to the next
519 mHasCycle = false;
520 }
521 else
522 {
523 ++it;
524 }
525 }
526 }
527}
528
530 : mHasCycle( false )
531 , mHasMissingDependency( false )
532{
533 init( doc );
534}
535
537 : mHasCycle( false )
538 , mHasMissingDependency( false )
539{
540 QString qgsProjectFile = fileName;
541 QgsProjectArchive archive;
542 if ( fileName.endsWith( QLatin1String( ".qgz" ), Qt::CaseInsensitive ) )
543 {
544 archive.unzip( fileName );
545 qgsProjectFile = archive.projectFile();
546 }
547
548 QDomDocument doc;
549 QFile pFile( qgsProjectFile );
550 ( void )pFile.open( QIODevice::ReadOnly );
551 ( void )doc.setContent( &pFile );
552 init( doc );
553}
554
556{
557 return mDependentLayerIds.contains( layerId );
558}
559
560
LayerTreeInsertionMethod
Layer tree insertion methods.
Definition qgis.h:4225
@ TopOfTree
Layers are added at the top of the layer tree.
@ AboveInsertionPoint
Layers are added in the tree above the insertion point.
FilePathType
File path types.
Definition qgis.h:1523
@ Relative
Relative path.
@ Absolute
Absolute path.
LayerType
Types of layers that can be added to a map.
Definition qgis.h:169
@ Group
Composite group layer. Added in QGIS 3.24.
@ Plugin
Plugin based layer.
@ TiledScene
Tiled scene layer. Added in QGIS 3.34.
@ Annotation
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
@ Vector
Vector layer.
@ VectorTile
Vector tile layer. Added in QGIS 3.14.
@ Mesh
Mesh layer. Added in QGIS 3.2.
@ Raster
Raster layer.
@ PointCloud
Point cloud layer. Added in QGIS 3.18.
static QgsPluginLayerRegistry * pluginLayerRegistry()
Returns the application's plugin layer registry, used for managing plugin layer types.
Contains information about the context in which a coordinate transform is executed.
static QString ensureFileNameHasExtension(const QString &fileName, const QStringList &extensions)
Ensures that a fileName ends with an extension from the provided list of extensions.
A map layer which consists of a set of child layers, where all component layers are rendered as a sin...
Class used to work with layer dependencies stored in a XML project or layer definition file.
bool hasMissingDependency() const
Whether some dependency is missing.
bool isLayerDependent(const QString &layerId) const
Returns whether the layer associated with thelayerId is dependent from another layer.
DependencySorter(const QDomDocument &doc)
Constructor.
QVector< QDomNode > sortedLayerNodes() const
Gets the layer nodes in an order where they can be loaded incrementally without dependency break.
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 wel...
static QList< QgsMapLayer * > loadLayerDefinitionLayers(QDomDocument &document, QgsReadWriteContext &context)
Creates new layers from a layer definition document.
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 exportLayerDefinition(const QString &path, const QList< QgsLayerTreeNode * > &selectedTreeNodes, QString &errorMessage)
Exports the selected layer tree nodes to a QLR file.
Layer tree group node serves as a container for layers and further groups.
void resolveReferences(const QgsProject *project, bool looseMatching=false) override
Calls resolveReferences() on child tree nodes.
void writeXml(QDomElement &parentElement, const QgsReadWriteContext &context) override
Write group (tree) as XML element <layer-tree-group> and add it to the given parent element.
void addChildNode(QgsLayerTreeNode *node)
Append an existing node.
void insertChildNodes(int index, const QList< QgsLayerTreeNode * > &nodes)
Insert existing nodes at specified position.
void readChildrenFromXml(QDomElement &element, const QgsReadWriteContext &context)
Read children from XML and append them to the group.
QList< QgsLayerTreeLayer * > findLayers() const
Find all layer nodes.
Layer tree node points to a map layer.
This class is a base class for nodes in a layer tree.
QList< QgsLayerTreeNode * > abandonChildren()
Removes the children, disconnect all the forwarded and external signals and sets their parent to null...
QList< QgsLayerTreeNode * > children()
Gets list of children of the node. Children are owned by the parent.
virtual QgsLayerTreeNode * clone() const =0
Create a copy of the node. Returns new instance.
static Qgis::LayerType typeFromString(const QString &string, bool &ok)
Returns the map layer type corresponding a string value.
Base class for all map layer types.
Definition qgsmaplayer.h:76
static QString generateId(const QString &layerName)
Generates an unique identifier for this layer, the generate ID is prefixed by layerName.
bool readLayerXml(const QDomElement &layerElement, QgsReadWriteContext &context, QgsMapLayer::ReadFlags flags=QgsMapLayer::ReadFlags(), QgsDataProvider *preloadedProvider=nullptr)
Sets state from DOM document.
Represents a mesh layer supporting display of data on structured or unstructured meshes.
Resolves relative paths into absolute paths and vice versa.
QgsPluginLayer * createLayer(const QString &typeName, const QString &uri=QString())
Returns new layer if corresponding plugin has been found else returns nullptr.
Represents a map layer supporting display of point clouds.
Class allowing to manage the zip/unzip actions on project file.
Definition qgsarchive.h:111
QString projectFile() const
Returns the current .qgs project file or an empty string if there's none.
bool unzip(const QString &zipFilename) override
Clear the current content of this archive and unzip.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:107
QList< QgsMapLayer * > addMapLayers(const QList< QgsMapLayer * > &mapLayers, bool addToLegend=true, bool takeOwnership=true)
Add a list of layers to the map of loaded layers.
static QgsProject * instance()
Returns the QgsProject singleton instance.
Represents a raster layer.
The class is used as a container of context for various read/write operations on other objects.
void setProjectTranslator(QgsProjectTranslator *projectTranslator)
Sets the project translator.
void setPathResolver(const QgsPathResolver &resolver)
Sets up path resolver for conversion between relative and absolute paths.
Represents a map layer supporting display of tiled scene objects.
Represents a vector layer which manages a vector based data sets.
Implements a map layer that is dedicated to rendering of vector tiles.
#define QgsDebugMsgLevel(str, level)
Definition qgslogger.h:39
#define QgsDebugError(str)
Definition qgslogger.h:38
const QString & typeName
Setting options for loading group layers.
A structure to define the insertion point to the layer tree.