QGIS API Documentation 3.29.0-Master (8c80f25a4f)
qgsmaplayer.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsmaplayer.cpp - description
3 -------------------
4 begin : Fri Jun 28 2002
5 copyright : (C) 2002 by Gary E.Sherman
6 email : sherman at mrcc.com
7***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18
19#include "qgssqliteutils.h"
22#include "qgsapplication.h"
24#include "qgsdatasourceuri.h"
25#include "qgsfileutils.h"
26#include "qgslogger.h"
27#include "qgsauthmanager.h"
28#include "qgsmaplayer.h"
29#include "qgsmaplayerlegend.h"
31#include "qgsmeshlayer.h"
32#include "qgspathresolver.h"
34#include "qgsproject.h"
35#include "qgsproviderregistry.h"
36#include "qgsrasterlayer.h"
37#include "qgsreadwritecontext.h"
38#include "qgsrectangle.h"
39#include "qgsvectorlayer.h"
41#include "qgsxmlutils.h"
42#include "qgsstringutils.h"
43#include "qgsmessagelog.h"
46#include "qgsprovidermetadata.h"
47#include "qgslayernotesutils.h"
48#include "qgsdatums.h"
49#include "qgsprojoperation.h"
50
51#include <QDir>
52#include <QDomDocument>
53#include <QDomElement>
54#include <QDomImplementation>
55#include <QDomNode>
56#include <QFile>
57#include <QFileInfo>
58#include <QLocale>
59#include <QTextStream>
60#include <QUrl>
61#include <QTimer>
62#include <QStandardPaths>
63#include <QUuid>
64#include <QRegularExpression>
65
66#include <sqlite3.h>
67
69{
70 switch ( type )
71 {
72 case Metadata:
73 return QStringLiteral( ".qmd" );
74
75 case Style:
76 return QStringLiteral( ".qml" );
77 }
78 return QString();
79}
80
82 const QString &lyrname,
83 const QString &source )
84 : mDataSource( source )
85 , mLayerName( lyrname )
86 , mLayerType( type )
87 , mServerProperties( std::make_unique<QgsMapLayerServerProperties>( this ) )
88 , mUndoStack( new QUndoStack( this ) )
89 , mUndoStackStyles( new QUndoStack( this ) )
90 , mStyleManager( new QgsMapLayerStyleManager( this ) )
91 , mRefreshTimer( new QTimer( this ) )
92{
93 mID = generateId( lyrname );
96 connect( mRefreshTimer, &QTimer::timeout, this, [ = ] { triggerRepaint( true ); } );
97}
98
100{
101 if ( project() && project()->pathResolver().writePath( mDataSource ).startsWith( "attachment:" ) )
102 {
104 }
105
106 delete m3DRenderer;
107 delete mLegend;
108 delete mStyleManager;
109}
110
111void QgsMapLayer::clone( QgsMapLayer *layer ) const
112{
113 layer->setBlendMode( blendMode() );
114
115 const auto constStyles = styleManager()->styles();
116 for ( const QString &s : constStyles )
117 {
118 layer->styleManager()->addStyle( s, styleManager()->style( s ) );
119 }
120
121 layer->setName( name() );
122 layer->setShortName( shortName() );
123 layer->setExtent( extent() );
124 layer->setMaximumScale( maximumScale() );
125 layer->setMinimumScale( minimumScale() );
127 layer->setTitle( title() );
128 layer->setAbstract( abstract() );
129 layer->setKeywordList( keywordList() );
130 layer->setDataUrl( dataUrl() );
132 layer->setAttribution( attribution() );
134 layer->setLegendUrl( legendUrl() );
136 layer->setDependencies( dependencies() );
138 layer->setCrs( crs() );
139 layer->setCustomProperties( mCustomProperties );
140 layer->setOpacity( mLayerOpacity );
141 layer->setMetadata( mMetadata );
142 layer->serverProperties()->copyTo( mServerProperties.get() );
143}
144
146{
147 return mLayerType;
148}
149
150QgsMapLayer::LayerFlags QgsMapLayer::flags() const
151{
152 return mFlags;
153}
154
155void QgsMapLayer::setFlags( QgsMapLayer::LayerFlags flags )
156{
157 if ( flags == mFlags )
158 return;
159
160 mFlags = flags;
161 emit flagsChanged();
162}
163
164Qgis::MapLayerProperties QgsMapLayer::properties() const
165{
166 return Qgis::MapLayerProperties();
167}
168
169QString QgsMapLayer::id() const
170{
171 return mID;
172}
173
174void QgsMapLayer::setName( const QString &name )
175{
176 if ( name == mLayerName )
177 return;
178
180
181 emit nameChanged();
182}
183
184QString QgsMapLayer::name() const
185{
186 QgsDebugMsgLevel( "returning name '" + mLayerName + '\'', 4 );
187 return mLayerName;
188}
189
191{
192 return nullptr;
193}
194
196{
197 return nullptr;
198}
199
201{
202 return mShortName;
203}
204
205void QgsMapLayer::setMetadataUrl( const QString &metaUrl )
206{
207 QList<QgsMapLayerServerProperties::MetadataUrl> urls = serverProperties()->metadataUrls();
208 if ( urls.isEmpty() )
209 {
210 const QgsMapLayerServerProperties::MetadataUrl newItem = QgsMapLayerServerProperties::MetadataUrl( metaUrl, QLatin1String(), QLatin1String() );
211 urls.prepend( newItem );
212 }
213 else
214 {
215 const QgsMapLayerServerProperties::MetadataUrl old = urls.takeFirst();
216 const QgsMapLayerServerProperties::MetadataUrl newItem( metaUrl, old.type, old.format );
217 urls.prepend( newItem );
218 }
220}
221
223{
224 if ( mServerProperties->metadataUrls().isEmpty() )
225 {
226 return QLatin1String();
227 }
228 else
229 {
230 return mServerProperties->metadataUrls().first().url;
231 }
232}
233
234void QgsMapLayer::setMetadataUrlType( const QString &metaUrlType )
235{
236 QList<QgsMapLayerServerProperties::MetadataUrl> urls = mServerProperties->metadataUrls();
237 if ( urls.isEmpty() )
238 {
239 const QgsMapLayerServerProperties::MetadataUrl newItem( QLatin1String(), metaUrlType, QLatin1String() );
240 urls.prepend( newItem );
241 }
242 else
243 {
244 const QgsMapLayerServerProperties::MetadataUrl old = urls.takeFirst();
245 const QgsMapLayerServerProperties::MetadataUrl newItem( old.url, metaUrlType, old.format );
246 urls.prepend( newItem );
247 }
248 mServerProperties->setMetadataUrls( urls );
249}
250
252{
253 if ( mServerProperties->metadataUrls().isEmpty() )
254 {
255 return QLatin1String();
256 }
257 else
258 {
259 return mServerProperties->metadataUrls().first().type;
260 }
261}
262
263void QgsMapLayer::setMetadataUrlFormat( const QString &metaUrlFormat )
264{
265 QList<QgsMapLayerServerProperties::MetadataUrl> urls = mServerProperties->metadataUrls();
266 if ( urls.isEmpty() )
267 {
268 const QgsMapLayerServerProperties::MetadataUrl newItem( QLatin1String(), QLatin1String(), metaUrlFormat );
269 urls.prepend( newItem );
270 }
271 else
272 {
273 const QgsMapLayerServerProperties::MetadataUrl old = urls.takeFirst( );
274 const QgsMapLayerServerProperties::MetadataUrl newItem( old.url, old.type, metaUrlFormat );
275 urls.prepend( newItem );
276 }
277 mServerProperties->setMetadataUrls( urls );
278}
279
281{
282 if ( mServerProperties->metadataUrls().isEmpty() )
283 {
284 return QString();
285 }
286 else
287 {
288 return mServerProperties->metadataUrls().first().format;
289 }
290}
291
293{
294 // Redo this every time we're asked for it, as we don't know if
295 // dataSource has changed.
296 QString safeName = QgsDataSourceUri::removePassword( mDataSource );
297 return safeName;
298}
299
300QString QgsMapLayer::source() const
301{
302 return mDataSource;
303}
304
306{
307 return mExtent;
308}
309
310void QgsMapLayer::setBlendMode( const QPainter::CompositionMode blendMode )
311{
312 if ( mBlendMode == blendMode )
313 return;
314
315 mBlendMode = blendMode;
318}
319
320QPainter::CompositionMode QgsMapLayer::blendMode() const
321{
322 return mBlendMode;
323}
324
325void QgsMapLayer::setOpacity( double opacity )
326{
328 return;
330 emit opacityChanged( opacity );
332}
333
335{
336 return mLayerOpacity;
337}
338
339bool QgsMapLayer::readLayerXml( const QDomElement &layerElement, QgsReadWriteContext &context, QgsMapLayer::ReadFlags flags )
340{
341 bool layerError;
343
344 QDomNode mnl;
345 QDomElement mne;
346
347 // read provider
348 QString provider;
349 mnl = layerElement.namedItem( QStringLiteral( "provider" ) );
350 mne = mnl.toElement();
351 provider = mne.text();
352
353 // set data source
354 mnl = layerElement.namedItem( QStringLiteral( "datasource" ) );
355 mne = mnl.toElement();
356 mDataSource = context.pathResolver().readPath( mne.text() );
357
358 // if the layer needs authentication, ensure the master password is set
359 const thread_local QRegularExpression rx( "authcfg=([a-z]|[A-Z]|[0-9]){7}" );
360 if ( rx.match( mDataSource ).hasMatch()
362 {
363 return false;
364 }
365
366 mDataSource = decodedSource( mDataSource, provider, context );
367
368 // Set the CRS from project file, asking the user if necessary.
369 // Make it the saved CRS to have WMS layer projected correctly.
370 // We will still overwrite whatever GDAL etc picks up anyway
371 // further down this function.
372 mnl = layerElement.namedItem( QStringLiteral( "layername" ) );
373 mne = mnl.toElement();
374
376 CUSTOM_CRS_VALIDATION savedValidation;
377
378 const QDomNode srsNode = layerElement.namedItem( QStringLiteral( "srs" ) );
379 mCRS.readXml( srsNode );
380 mCRS.setValidationHint( tr( "Specify CRS for layer %1" ).arg( mne.text() ) );
382 mCRS.validate();
383 savedCRS = mCRS;
384
385 // Do not validate any projections in children, they will be overwritten anyway.
386 // No need to ask the user for a projections when it is overwritten, is there?
389
390 const QgsReadWriteContextCategoryPopper p = context.enterCategory( tr( "Layer" ), mne.text() );
391
392 // the internal name is just the data source basename
393 //QFileInfo dataSourceFileInfo( mDataSource );
394 //internalName = dataSourceFileInfo.baseName();
395
396 // set ID
397 mnl = layerElement.namedItem( QStringLiteral( "id" ) );
398 if ( ! mnl.isNull() )
399 {
400 mne = mnl.toElement();
401 if ( ! mne.isNull() && mne.text().length() > 10 ) // should be at least 17 (yyyyMMddhhmmsszzz)
402 {
403 mID = mne.text();
404 }
405 }
406
407 // set name
408 mnl = layerElement.namedItem( QStringLiteral( "layername" ) );
409 mne = mnl.toElement();
410
411 //name can be translated
412 setName( context.projectTranslator()->translate( QStringLiteral( "project:layers:%1" ).arg( layerElement.namedItem( QStringLiteral( "id" ) ).toElement().text() ), mne.text() ) );
413
414 // now let the children grab what they need from the Dom node.
415 layerError = !readXml( layerElement, context );
416
417 // overwrite CRS with what we read from project file before the raster/vector
418 // file reading functions changed it. They will if projections is specified in the file.
419 // FIXME: is this necessary? Yes, it is (autumn 2019)
421 mCRS = savedCRS;
422
423 //short name
424 const QDomElement shortNameElem = layerElement.firstChildElement( QStringLiteral( "shortname" ) );
425 if ( !shortNameElem.isNull() )
426 {
427 mShortName = shortNameElem.text();
428 }
429
430 //title
431 const QDomElement titleElem = layerElement.firstChildElement( QStringLiteral( "title" ) );
432 if ( !titleElem.isNull() )
433 {
434 mTitle = titleElem.text();
435 }
436
437 //abstract
438 const QDomElement abstractElem = layerElement.firstChildElement( QStringLiteral( "abstract" ) );
439 if ( !abstractElem.isNull() )
440 {
441 mAbstract = abstractElem.text();
442 }
443
444 //keywordList
445 const QDomElement keywordListElem = layerElement.firstChildElement( QStringLiteral( "keywordList" ) );
446 if ( !keywordListElem.isNull() )
447 {
448 QStringList kwdList;
449 for ( QDomNode n = keywordListElem.firstChild(); !n.isNull(); n = n.nextSibling() )
450 {
451 kwdList << n.toElement().text();
452 }
453 mKeywordList = kwdList.join( QLatin1String( ", " ) );
454 }
455
456 //dataUrl
457 const QDomElement dataUrlElem = layerElement.firstChildElement( QStringLiteral( "dataUrl" ) );
458 if ( !dataUrlElem.isNull() )
459 {
460 mDataUrl = dataUrlElem.text();
461 mDataUrlFormat = dataUrlElem.attribute( QStringLiteral( "format" ), QString() );
462 }
463
464 //legendUrl
465 const QDomElement legendUrlElem = layerElement.firstChildElement( QStringLiteral( "legendUrl" ) );
466 if ( !legendUrlElem.isNull() )
467 {
468 mLegendUrl = legendUrlElem.text();
469 mLegendUrlFormat = legendUrlElem.attribute( QStringLiteral( "format" ), QString() );
470 }
471
472 //attribution
473 const QDomElement attribElem = layerElement.firstChildElement( QStringLiteral( "attribution" ) );
474 if ( !attribElem.isNull() )
475 {
476 mAttribution = attribElem.text();
477 mAttributionUrl = attribElem.attribute( QStringLiteral( "href" ), QString() );
478 }
479
480 serverProperties()->readXml( layerElement );
481
482 if ( serverProperties()->metadataUrls().isEmpty() )
483 {
484 // metadataUrl is still empty, maybe it's a QGIS Project < 3.22
485 // keep for legacy
486 const QDomElement metaUrlElem = layerElement.firstChildElement( QStringLiteral( "metadataUrl" ) );
487 if ( !metaUrlElem.isNull() )
488 {
489 const QString url = metaUrlElem.text();
490 const QString type = metaUrlElem.attribute( QStringLiteral( "type" ), QString() );
491 const QString format = metaUrlElem.attribute( QStringLiteral( "format" ), QString() );
492 const QgsMapLayerServerProperties::MetadataUrl newItem( url, type, format );
493 mServerProperties->setMetadataUrls( QList<QgsMapLayerServerProperties::MetadataUrl>() << newItem );
494 }
495 }
496
497 // mMetadata.readFromLayer( this );
498 const QDomElement metadataElem = layerElement.firstChildElement( QStringLiteral( "resourceMetadata" ) );
499 mMetadata.readMetadataXml( metadataElem );
500
501 setAutoRefreshInterval( layerElement.attribute( QStringLiteral( "autoRefreshTime" ), QStringLiteral( "0" ) ).toInt() );
502 setAutoRefreshEnabled( layerElement.attribute( QStringLiteral( "autoRefreshEnabled" ), QStringLiteral( "0" ) ).toInt() );
503 setRefreshOnNofifyMessage( layerElement.attribute( QStringLiteral( "refreshOnNotifyMessage" ), QString() ) );
504 setRefreshOnNotifyEnabled( layerElement.attribute( QStringLiteral( "refreshOnNotifyEnabled" ), QStringLiteral( "0" ) ).toInt() );
505
506 // geographic extent is read only if necessary
507 if ( mReadFlags & QgsMapLayer::ReadFlag::FlagTrustLayerMetadata )
508 {
509 const QDomNode wgs84ExtentNode = layerElement.namedItem( QStringLiteral( "wgs84extent" ) );
510 if ( !wgs84ExtentNode.isNull() )
511 mWgs84Extent = QgsXmlUtils::readRectangle( wgs84ExtentNode.toElement() );
512 }
513
514 mLegendPlaceholderImage = layerElement.attribute( QStringLiteral( "legendPlaceholderImage" ) );
515
516 return ! layerError;
517} // bool QgsMapLayer::readLayerXML
518
519
520bool QgsMapLayer::readXml( const QDomNode &layer_node, QgsReadWriteContext &context )
521{
522 Q_UNUSED( layer_node )
523 Q_UNUSED( context )
524 // NOP by default; children will over-ride with behavior specific to them
525
526 // read Extent
528 {
529 const QDomNode extentNode = layer_node.namedItem( QStringLiteral( "extent" ) );
530 if ( !extentNode.isNull() )
531 {
532 mExtent = QgsXmlUtils::readRectangle( extentNode.toElement() );
533 }
534 }
535
536 return true;
537} // void QgsMapLayer::readXml
538
539
540bool QgsMapLayer::writeLayerXml( QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context ) const
541{
542 if ( !extent().isNull() )
543 {
544 layerElement.appendChild( QgsXmlUtils::writeRectangle( mExtent, document ) );
545 layerElement.appendChild( QgsXmlUtils::writeRectangle( wgs84Extent( true ), document, QStringLiteral( "wgs84extent" ) ) );
546 }
547
548 layerElement.setAttribute( QStringLiteral( "autoRefreshTime" ), QString::number( mRefreshTimer->interval() ) );
549 layerElement.setAttribute( QStringLiteral( "autoRefreshEnabled" ), mRefreshTimer->isActive() ? 1 : 0 );
550 layerElement.setAttribute( QStringLiteral( "refreshOnNotifyEnabled" ), mIsRefreshOnNofifyEnabled ? 1 : 0 );
551 layerElement.setAttribute( QStringLiteral( "refreshOnNotifyMessage" ), mRefreshOnNofifyMessage );
552
553 // ID
554 QDomElement layerId = document.createElement( QStringLiteral( "id" ) );
555 const QDomText layerIdText = document.createTextNode( id() );
556 layerId.appendChild( layerIdText );
557
558 layerElement.appendChild( layerId );
559
560 // data source
561 QDomElement dataSource = document.createElement( QStringLiteral( "datasource" ) );
562 const QString src = context.pathResolver().writePath( encodedSource( source(), context ) );
563 const QDomText dataSourceText = document.createTextNode( src );
564 dataSource.appendChild( dataSourceText );
565 layerElement.appendChild( dataSource );
566
567 // layer name
568 QDomElement layerName = document.createElement( QStringLiteral( "layername" ) );
569 const QDomText layerNameText = document.createTextNode( name() );
570 layerName.appendChild( layerNameText );
571 layerElement.appendChild( layerName );
572
573 // layer short name
574 if ( !mShortName.isEmpty() )
575 {
576 QDomElement layerShortName = document.createElement( QStringLiteral( "shortname" ) );
577 const QDomText layerShortNameText = document.createTextNode( mShortName );
578 layerShortName.appendChild( layerShortNameText );
579 layerElement.appendChild( layerShortName );
580 }
581
582 // layer title
583 if ( !mTitle.isEmpty() )
584 {
585 QDomElement layerTitle = document.createElement( QStringLiteral( "title" ) );
586 const QDomText layerTitleText = document.createTextNode( mTitle );
587 layerTitle.appendChild( layerTitleText );
588 layerElement.appendChild( layerTitle );
589 }
590
591 // layer abstract
592 if ( !mAbstract.isEmpty() )
593 {
594 QDomElement layerAbstract = document.createElement( QStringLiteral( "abstract" ) );
595 const QDomText layerAbstractText = document.createTextNode( mAbstract );
596 layerAbstract.appendChild( layerAbstractText );
597 layerElement.appendChild( layerAbstract );
598 }
599
600 // layer keyword list
601 const QStringList keywordStringList = keywordList().split( ',' );
602 if ( !keywordStringList.isEmpty() )
603 {
604 QDomElement layerKeywordList = document.createElement( QStringLiteral( "keywordList" ) );
605 for ( int i = 0; i < keywordStringList.size(); ++i )
606 {
607 QDomElement layerKeywordValue = document.createElement( QStringLiteral( "value" ) );
608 const QDomText layerKeywordText = document.createTextNode( keywordStringList.at( i ).trimmed() );
609 layerKeywordValue.appendChild( layerKeywordText );
610 layerKeywordList.appendChild( layerKeywordValue );
611 }
612 layerElement.appendChild( layerKeywordList );
613 }
614
615 // layer dataUrl
616 const QString aDataUrl = dataUrl();
617 if ( !aDataUrl.isEmpty() )
618 {
619 QDomElement layerDataUrl = document.createElement( QStringLiteral( "dataUrl" ) );
620 const QDomText layerDataUrlText = document.createTextNode( aDataUrl );
621 layerDataUrl.appendChild( layerDataUrlText );
622 layerDataUrl.setAttribute( QStringLiteral( "format" ), dataUrlFormat() );
623 layerElement.appendChild( layerDataUrl );
624 }
625
626 // layer legendUrl
627 const QString aLegendUrl = legendUrl();
628 if ( !aLegendUrl.isEmpty() )
629 {
630 QDomElement layerLegendUrl = document.createElement( QStringLiteral( "legendUrl" ) );
631 const QDomText layerLegendUrlText = document.createTextNode( aLegendUrl );
632 layerLegendUrl.appendChild( layerLegendUrlText );
633 layerLegendUrl.setAttribute( QStringLiteral( "format" ), legendUrlFormat() );
634 layerElement.appendChild( layerLegendUrl );
635 }
636
637 // layer attribution
638 const QString aAttribution = attribution();
639 if ( !aAttribution.isEmpty() )
640 {
641 QDomElement layerAttribution = document.createElement( QStringLiteral( "attribution" ) );
642 const QDomText layerAttributionText = document.createTextNode( aAttribution );
643 layerAttribution.appendChild( layerAttributionText );
644 layerAttribution.setAttribute( QStringLiteral( "href" ), attributionUrl() );
645 layerElement.appendChild( layerAttribution );
646 }
647
648 // timestamp if supported
649 if ( timestamp() > QDateTime() )
650 {
651 QDomElement stamp = document.createElement( QStringLiteral( "timestamp" ) );
652 const QDomText stampText = document.createTextNode( timestamp().toString( Qt::ISODate ) );
653 stamp.appendChild( stampText );
654 layerElement.appendChild( stamp );
655 }
656
657 layerElement.appendChild( layerName );
658
659 // zorder
660 // This is no longer stored in the project file. It is superfluous since the layers
661 // are written and read in the proper order.
662
663 // spatial reference system id
664 QDomElement mySrsElement = document.createElement( QStringLiteral( "srs" ) );
665 mCRS.writeXml( mySrsElement, document );
666 layerElement.appendChild( mySrsElement );
667
668 // layer metadata
669 QDomElement myMetadataElem = document.createElement( QStringLiteral( "resourceMetadata" ) );
670 mMetadata.writeMetadataXml( myMetadataElem, document );
671 layerElement.appendChild( myMetadataElem );
672
673 layerElement.setAttribute( QStringLiteral( "legendPlaceholderImage" ), mLegendPlaceholderImage );
674
675 // now append layer node to map layer node
676 return writeXml( layerElement, document, context );
677}
678
679void QgsMapLayer::writeCommonStyle( QDomElement &layerElement, QDomDocument &document,
680 const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories ) const
681{
682 // save categories
683 const QMetaEnum metaEnum = QMetaEnum::fromType<QgsMapLayer::StyleCategories>();
684 const QString categoriesKeys( metaEnum.valueToKeys( static_cast<int>( categories ) ) );
685 layerElement.setAttribute( QStringLiteral( "styleCategories" ), categoriesKeys );
686
687 if ( categories.testFlag( Rendering ) )
688 {
689 // use scale dependent visibility flag
690 layerElement.setAttribute( QStringLiteral( "hasScaleBasedVisibilityFlag" ), hasScaleBasedVisibility() ? 1 : 0 );
691 layerElement.setAttribute( QStringLiteral( "maxScale" ), QString::number( maximumScale() ) );
692 layerElement.setAttribute( QStringLiteral( "minScale" ), QString::number( minimumScale() ) );
693 }
694
695 if ( categories.testFlag( Symbology3D ) )
696 {
697 if ( m3DRenderer )
698 {
699 QDomElement renderer3DElem = document.createElement( QStringLiteral( "renderer-3d" ) );
700 renderer3DElem.setAttribute( QStringLiteral( "type" ), m3DRenderer->type() );
701 m3DRenderer->writeXml( renderer3DElem, context );
702 layerElement.appendChild( renderer3DElem );
703 }
704 }
705
706 if ( categories.testFlag( LayerConfiguration ) )
707 {
708 // flags
709 // this code is saving automatically all the flags entries
710 QDomElement layerFlagsElem = document.createElement( QStringLiteral( "flags" ) );
711 const auto enumMap = qgsEnumMap<QgsMapLayer::LayerFlag>();
712 for ( auto it = enumMap.constBegin(); it != enumMap.constEnd(); ++it )
713 {
714 const bool flagValue = mFlags.testFlag( it.key() );
715 QDomElement flagElem = document.createElement( it.value() );
716 flagElem.appendChild( document.createTextNode( QString::number( flagValue ) ) );
717 layerFlagsElem.appendChild( flagElem );
718 }
719 layerElement.appendChild( layerFlagsElem );
720 }
721
722 if ( categories.testFlag( Temporal ) )
723 {
725 properties->writeXml( layerElement, document, context );
726 }
727
728 if ( categories.testFlag( Elevation ) )
729 {
731 properties->writeXml( layerElement, document, context );
732 }
733
734 if ( categories.testFlag( Notes ) && QgsLayerNotesUtils::layerHasNotes( this ) )
735 {
736 QDomElement notesElem = document.createElement( QStringLiteral( "userNotes" ) );
737 notesElem.setAttribute( QStringLiteral( "value" ), QgsLayerNotesUtils::layerNotes( this ) );
738 layerElement.appendChild( notesElem );
739 }
740
741 // custom properties
742 if ( categories.testFlag( CustomProperties ) )
743 {
744 writeCustomProperties( layerElement, document );
745 }
746}
747
748
749bool QgsMapLayer::writeXml( QDomNode &layer_node, QDomDocument &document, const QgsReadWriteContext &context ) const
750{
751 Q_UNUSED( layer_node )
752 Q_UNUSED( document )
753 Q_UNUSED( context )
754 // NOP by default; children will over-ride with behavior specific to them
755
756 return true;
757}
758
759QString QgsMapLayer::encodedSource( const QString &source, const QgsReadWriteContext &context ) const
760{
761 Q_UNUSED( context )
762 return source;
763}
764
765QString QgsMapLayer::decodedSource( const QString &source, const QString &dataProvider, const QgsReadWriteContext &context ) const
766{
767 Q_UNUSED( context )
768 Q_UNUSED( dataProvider )
769 return source;
770}
771
773{
775 if ( m3DRenderer )
776 m3DRenderer->resolveReferences( *project );
777}
778
779
780void QgsMapLayer::readCustomProperties( const QDomNode &layerNode, const QString &keyStartsWith )
781{
782 const QgsObjectCustomProperties oldKeys = mCustomProperties;
783
784 mCustomProperties.readXml( layerNode, keyStartsWith );
785
786 for ( const QString &key : mCustomProperties.keys() )
787 {
788 if ( !oldKeys.contains( key ) || mCustomProperties.value( key ) != oldKeys.value( key ) )
789 {
790 emit customPropertyChanged( key );
791 }
792 }
793}
794
795void QgsMapLayer::writeCustomProperties( QDomNode &layerNode, QDomDocument &doc ) const
796{
797 mCustomProperties.writeXml( layerNode, doc );
798}
799
800void QgsMapLayer::readStyleManager( const QDomNode &layerNode )
801{
802 const QDomElement styleMgrElem = layerNode.firstChildElement( QStringLiteral( "map-layer-style-manager" ) );
803 if ( !styleMgrElem.isNull() )
804 mStyleManager->readXml( styleMgrElem );
805 else
806 mStyleManager->reset();
807}
808
809void QgsMapLayer::writeStyleManager( QDomNode &layerNode, QDomDocument &doc ) const
810{
811 if ( mStyleManager )
812 {
813 QDomElement styleMgrElem = doc.createElement( QStringLiteral( "map-layer-style-manager" ) );
814 mStyleManager->writeXml( styleMgrElem );
815 layerNode.appendChild( styleMgrElem );
816 }
817}
818
820{
821 return mMapTipTemplate;
822}
823
824void QgsMapLayer::setMapTipTemplate( const QString &mapTip )
825{
826 if ( mMapTipTemplate == mapTip )
827 return;
828
829 mMapTipTemplate = mapTip;
831}
832
834{
835 return mValid;
836}
837
838#if 0
839void QgsMapLayer::connectNotify( const char *signal )
840{
841 Q_UNUSED( signal )
842 QgsDebugMsgLevel( "QgsMapLayer connected to " + QString( signal ), 3 );
843} // QgsMapLayer::connectNotify
844#endif
845
846bool QgsMapLayer::isInScaleRange( double scale ) const
847{
848 return !mScaleBasedVisibility ||
849 ( ( mMinScale == 0 || mMinScale * Qgis::SCALE_PRECISION < scale )
850 && ( mMaxScale == 0 || scale < mMaxScale ) );
851}
852
854{
855 return mScaleBasedVisibility;
856}
857
859{
860 return mRefreshTimer->isActive();
861}
862
864{
865 return mRefreshTimer->interval();
866}
867
869{
870 if ( interval <= 0 )
871 {
872 mRefreshTimer->stop();
873 mRefreshTimer->setInterval( 0 );
874 }
875 else
876 {
877 mRefreshTimer->setInterval( interval );
878 }
879 emit autoRefreshIntervalChanged( mRefreshTimer->isActive() ? mRefreshTimer->interval() : 0 );
880}
881
883{
884 if ( !enabled )
885 mRefreshTimer->stop();
886 else if ( mRefreshTimer->interval() > 0 )
887 mRefreshTimer->start();
888
889 emit autoRefreshIntervalChanged( mRefreshTimer->isActive() ? mRefreshTimer->interval() : 0 );
890}
891
893{
894 return mMetadata;
895}
896
898{
899 mMinScale = scale;
900}
901
903{
904 return mMinScale;
905}
906
907
909{
910 mMaxScale = scale;
911}
912
913void QgsMapLayer::setScaleBasedVisibility( const bool enabled )
914{
915 mScaleBasedVisibility = enabled;
916}
917
919{
920 return mMaxScale;
921}
922
923QStringList QgsMapLayer::subLayers() const
924{
925 return QStringList(); // Empty
926}
927
928void QgsMapLayer::setLayerOrder( const QStringList &layers )
929{
930 Q_UNUSED( layers )
931 // NOOP
932}
933
934void QgsMapLayer::setSubLayerVisibility( const QString &name, bool vis )
935{
936 Q_UNUSED( name )
937 Q_UNUSED( vis )
938 // NOOP
939}
940
942{
943 return false;
944}
945
947{
948 return mCRS;
949}
950
951void QgsMapLayer::setCrs( const QgsCoordinateReferenceSystem &srs, bool emitSignal )
952{
953 mCRS = srs;
954
956 {
957 mCRS.setValidationHint( tr( "Specify CRS for layer %1" ).arg( name() ) );
958 mCRS.validate();
959 }
960
961 if ( emitSignal )
962 emit crsChanged();
963}
964
966{
967 const QgsDataProvider *lDataProvider = dataProvider();
968 return lDataProvider ? lDataProvider->transformContext() : QgsCoordinateTransformContext();
969}
970
971QString QgsMapLayer::formatLayerName( const QString &name )
972{
973 QString layerName( name );
974 layerName.replace( '_', ' ' );
976 return layerName;
977}
978
979QString QgsMapLayer::baseURI( PropertyType type ) const
980{
981 QString myURI = publicSource();
982
983 // first get base path for delimited text, spatialite and OGR layers,
984 // as in these cases URI may contain layer name and/or additional
985 // information. This also strips prefix in case if VSIFILE mechanism
986 // is used
987 if ( providerType() == QLatin1String( "ogr" ) || providerType() == QLatin1String( "delimitedtext" )
988 || providerType() == QLatin1String( "gdal" ) || providerType() == QLatin1String( "spatialite" ) )
989 {
990 QVariantMap components = QgsProviderRegistry::instance()->decodeUri( providerType(), myURI );
991 myURI = components["path"].toString();
992 }
993
994 QFileInfo myFileInfo( myURI );
995 QString key;
996
997 if ( myFileInfo.exists() )
998 {
999 // if file is using the /vsizip/ or /vsigzip/ mechanism, cleanup the name
1000 if ( myURI.endsWith( QLatin1String( ".gz" ), Qt::CaseInsensitive ) )
1001 myURI.chop( 3 );
1002 else if ( myURI.endsWith( QLatin1String( ".zip" ), Qt::CaseInsensitive ) )
1003 myURI.chop( 4 );
1004 else if ( myURI.endsWith( QLatin1String( ".tar" ), Qt::CaseInsensitive ) )
1005 myURI.chop( 4 );
1006 else if ( myURI.endsWith( QLatin1String( ".tar.gz" ), Qt::CaseInsensitive ) )
1007 myURI.chop( 7 );
1008 else if ( myURI.endsWith( QLatin1String( ".tgz" ), Qt::CaseInsensitive ) )
1009 myURI.chop( 4 );
1010 myFileInfo.setFile( myURI );
1011 // get the file name for our .qml style file
1012 key = myFileInfo.path() + QDir::separator() + myFileInfo.completeBaseName() + QgsMapLayer::extensionPropertyType( type );
1013 }
1014 else
1015 {
1016 key = publicSource();
1017 }
1018
1019 return key;
1020}
1021
1023{
1024 return baseURI( PropertyType::Metadata );
1025}
1026
1027QString QgsMapLayer::saveDefaultMetadata( bool &resultFlag )
1028{
1029 if ( const QgsProviderMetadata *metadata = QgsProviderRegistry::instance()->providerMetadata( providerType() ) )
1030 {
1031 if ( metadata->providerCapabilities() & QgsProviderMetadata::SaveLayerMetadata )
1032 {
1033 try
1034 {
1035 QString errorMessage;
1036 resultFlag = QgsProviderRegistry::instance()->saveLayerMetadata( providerType(), mDataSource, mMetadata, errorMessage );
1037 if ( resultFlag )
1038 return tr( "Successfully saved default layer metadata" );
1039 else
1040 return errorMessage;
1041 }
1042 catch ( QgsNotSupportedException &e )
1043 {
1044 resultFlag = false;
1045 return e.what();
1046 }
1047 }
1048 }
1049
1050 // fallback default metadata saving method, for providers which don't support (or implement) saveLayerMetadata
1051 return saveNamedMetadata( metadataUri(), resultFlag );
1052}
1053
1054QString QgsMapLayer::loadDefaultMetadata( bool &resultFlag )
1055{
1056 return loadNamedMetadata( metadataUri(), resultFlag );
1057}
1058
1060{
1061 return baseURI( PropertyType::Style );
1062}
1063
1064QString QgsMapLayer::loadDefaultStyle( bool &resultFlag )
1065{
1066 return loadNamedStyle( styleURI(), resultFlag );
1067}
1068
1069bool QgsMapLayer::loadNamedMetadataFromDatabase( const QString &db, const QString &uri, QString &qmd )
1070{
1071 return loadNamedPropertyFromDatabase( db, uri, qmd, PropertyType::Metadata );
1072}
1073
1074bool QgsMapLayer::loadNamedStyleFromDatabase( const QString &db, const QString &uri, QString &qml )
1075{
1076 return loadNamedPropertyFromDatabase( db, uri, qml, PropertyType::Style );
1077}
1078
1079bool QgsMapLayer::loadNamedPropertyFromDatabase( const QString &db, const QString &uri, QString &xml, QgsMapLayer::PropertyType type )
1080{
1081 QgsDebugMsgLevel( QStringLiteral( "db = %1 uri = %2" ).arg( db, uri ), 4 );
1082
1083 bool resultFlag = false;
1084
1085 // read from database
1088
1089 int myResult;
1090
1091 QgsDebugMsgLevel( QStringLiteral( "Trying to load style or metadata for \"%1\" from \"%2\"" ).arg( uri, db ), 4 );
1092
1093 if ( db.isEmpty() || !QFile( db ).exists() )
1094 return false;
1095
1096 myResult = database.open_v2( db, SQLITE_OPEN_READONLY, nullptr );
1097 if ( myResult != SQLITE_OK )
1098 {
1099 return false;
1100 }
1101
1102 QString mySql;
1103 switch ( type )
1104 {
1105 case Metadata:
1106 mySql = QStringLiteral( "select qmd from tbl_metadata where metadata=?" );
1107 break;
1108
1109 case Style:
1110 mySql = QStringLiteral( "select qml from tbl_styles where style=?" );
1111 break;
1112 }
1113
1114 statement = database.prepare( mySql, myResult );
1115 if ( myResult == SQLITE_OK )
1116 {
1117 QByteArray param = uri.toUtf8();
1118
1119 if ( sqlite3_bind_text( statement.get(), 1, param.data(), param.length(), SQLITE_STATIC ) == SQLITE_OK &&
1120 sqlite3_step( statement.get() ) == SQLITE_ROW )
1121 {
1122 xml = QString::fromUtf8( reinterpret_cast< const char * >( sqlite3_column_text( statement.get(), 0 ) ) );
1123 resultFlag = true;
1124 }
1125 }
1126 return resultFlag;
1127}
1128
1129
1130QString QgsMapLayer::loadNamedStyle( const QString &uri, bool &resultFlag, QgsMapLayer::StyleCategories categories )
1131{
1132 return loadNamedProperty( uri, PropertyType::Style, resultFlag, categories );
1133}
1134
1135QString QgsMapLayer::loadNamedProperty( const QString &uri, QgsMapLayer::PropertyType type, bool &resultFlag, StyleCategories categories )
1136{
1137 QgsDebugMsgLevel( QStringLiteral( "uri = %1 myURI = %2" ).arg( uri, publicSource() ), 4 );
1138
1139 resultFlag = false;
1140 if ( uri.isEmpty() )
1141 return QString();
1142
1143 QDomDocument myDocument( QStringLiteral( "qgis" ) );
1144
1145 // location of problem associated with errorMsg
1146 int line, column;
1147 QString myErrorMessage;
1148
1149 QFile myFile( uri );
1150 if ( myFile.open( QFile::ReadOnly ) )
1151 {
1152 QgsDebugMsgLevel( QStringLiteral( "file found %1" ).arg( uri ), 2 );
1153 // read file
1154 resultFlag = myDocument.setContent( &myFile, &myErrorMessage, &line, &column );
1155 if ( !resultFlag )
1156 myErrorMessage = tr( "%1 at line %2 column %3" ).arg( myErrorMessage ).arg( line ).arg( column );
1157 myFile.close();
1158 }
1159 else
1160 {
1161 const QFileInfo project( QgsProject::instance()->fileName() );
1162 QgsDebugMsgLevel( QStringLiteral( "project fileName: %1" ).arg( project.absoluteFilePath() ), 4 );
1163
1164 QString xml;
1165 switch ( type )
1166 {
1167 case QgsMapLayer::Style:
1168 {
1169 if ( loadNamedStyleFromDatabase( QDir( QgsApplication::qgisSettingsDirPath() ).absoluteFilePath( QStringLiteral( "qgis.qmldb" ) ), uri, xml ) ||
1170 ( project.exists() && loadNamedStyleFromDatabase( project.absoluteDir().absoluteFilePath( project.baseName() + ".qmldb" ), uri, xml ) ) ||
1171 loadNamedStyleFromDatabase( QDir( QgsApplication::pkgDataPath() ).absoluteFilePath( QStringLiteral( "resources/qgis.qmldb" ) ), uri, xml ) )
1172 {
1173 resultFlag = myDocument.setContent( xml, &myErrorMessage, &line, &column );
1174 if ( !resultFlag )
1175 {
1176 myErrorMessage = tr( "%1 at line %2 column %3" ).arg( myErrorMessage ).arg( line ).arg( column );
1177 }
1178 }
1179 else
1180 {
1181 myErrorMessage = tr( "Style not found in database" );
1182 resultFlag = false;
1183 }
1184 break;
1185 }
1187 {
1188 if ( loadNamedMetadataFromDatabase( QDir( QgsApplication::qgisSettingsDirPath() ).absoluteFilePath( QStringLiteral( "qgis.qmldb" ) ), uri, xml ) ||
1189 ( project.exists() && loadNamedMetadataFromDatabase( project.absoluteDir().absoluteFilePath( project.baseName() + ".qmldb" ), uri, xml ) ) ||
1190 loadNamedMetadataFromDatabase( QDir( QgsApplication::pkgDataPath() ).absoluteFilePath( QStringLiteral( "resources/qgis.qmldb" ) ), uri, xml ) )
1191 {
1192 resultFlag = myDocument.setContent( xml, &myErrorMessage, &line, &column );
1193 if ( !resultFlag )
1194 {
1195 myErrorMessage = tr( "%1 at line %2 column %3" ).arg( myErrorMessage ).arg( line ).arg( column );
1196 }
1197 }
1198 else
1199 {
1200 myErrorMessage = tr( "Metadata not found in database" );
1201 resultFlag = false;
1202 }
1203 break;
1204 }
1205 }
1206 }
1207
1208 if ( !resultFlag )
1209 {
1210 return myErrorMessage;
1211 }
1212
1213 switch ( type )
1214 {
1215 case QgsMapLayer::Style:
1216 resultFlag = importNamedStyle( myDocument, myErrorMessage, categories );
1217 if ( !resultFlag )
1218 myErrorMessage = tr( "Loading style file %1 failed because:\n%2" ).arg( uri, myErrorMessage );
1219 break;
1221 resultFlag = importNamedMetadata( myDocument, myErrorMessage );
1222 if ( !resultFlag )
1223 myErrorMessage = tr( "Loading metadata file %1 failed because:\n%2" ).arg( uri, myErrorMessage );
1224 break;
1225 }
1226 return myErrorMessage;
1227}
1228
1229bool QgsMapLayer::importNamedMetadata( QDomDocument &document, QString &errorMessage )
1230{
1231 const QDomElement myRoot = document.firstChildElement( QStringLiteral( "qgis" ) );
1232 if ( myRoot.isNull() )
1233 {
1234 errorMessage = tr( "Root <qgis> element could not be found" );
1235 return false;
1236 }
1237
1238 return mMetadata.readMetadataXml( myRoot );
1239}
1240
1241bool QgsMapLayer::importNamedStyle( QDomDocument &myDocument, QString &myErrorMessage, QgsMapLayer::StyleCategories categories )
1242{
1243 const QDomElement myRoot = myDocument.firstChildElement( QStringLiteral( "qgis" ) );
1244 if ( myRoot.isNull() )
1245 {
1246 myErrorMessage = tr( "Root <qgis> element could not be found" );
1247 return false;
1248 }
1249
1250 // get style file version string, if any
1251 const QgsProjectVersion fileVersion( myRoot.attribute( QStringLiteral( "version" ) ) );
1252 const QgsProjectVersion thisVersion( Qgis::version() );
1253
1254 if ( thisVersion > fileVersion )
1255 {
1256 QgsProjectFileTransform styleFile( myDocument, fileVersion );
1257 styleFile.updateRevision( thisVersion );
1258 }
1259
1260 // Get source categories
1261 const QgsMapLayer::StyleCategories sourceCategories = QgsXmlUtils::readFlagAttribute( myRoot, QStringLiteral( "styleCategories" ), QgsMapLayer::AllStyleCategories );
1262
1263 //Test for matching geometry type on vector layers when applying, if geometry type is given in the style
1264 if ( ( sourceCategories.testFlag( QgsMapLayer::Symbology ) || sourceCategories.testFlag( QgsMapLayer::Symbology3D ) ) &&
1265 ( categories.testFlag( QgsMapLayer::Symbology ) || categories.testFlag( QgsMapLayer::Symbology3D ) ) )
1266 {
1267 if ( type() == QgsMapLayerType::VectorLayer && !myRoot.firstChildElement( QStringLiteral( "layerGeometryType" ) ).isNull() )
1268 {
1269 QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( this );
1270 const QgsWkbTypes::GeometryType importLayerGeometryType = static_cast<QgsWkbTypes::GeometryType>( myRoot.firstChildElement( QStringLiteral( "layerGeometryType" ) ).text().toInt() );
1271 if ( importLayerGeometryType != QgsWkbTypes::GeometryType::UnknownGeometry && vl->geometryType() != importLayerGeometryType )
1272 {
1273 myErrorMessage = tr( "Cannot apply style with symbology to layer with a different geometry type" );
1274 return false;
1275 }
1276 }
1277 }
1278
1280 return readSymbology( myRoot, myErrorMessage, context, categories ); // TODO: support relative paths in QML?
1281}
1282
1283void QgsMapLayer::exportNamedMetadata( QDomDocument &doc, QString &errorMsg ) const
1284{
1285 QDomImplementation DomImplementation;
1286 const QDomDocumentType documentType = DomImplementation.createDocumentType( QStringLiteral( "qgis" ), QStringLiteral( "http://mrcc.com/qgis.dtd" ), QStringLiteral( "SYSTEM" ) );
1287 QDomDocument myDocument( documentType );
1288
1289 QDomElement myRootNode = myDocument.createElement( QStringLiteral( "qgis" ) );
1290 myRootNode.setAttribute( QStringLiteral( "version" ), Qgis::version() );
1291 myDocument.appendChild( myRootNode );
1292
1293 if ( !mMetadata.writeMetadataXml( myRootNode, myDocument ) )
1294 {
1295 errorMsg = QObject::tr( "Could not save metadata" );
1296 return;
1297 }
1298
1299 doc = myDocument;
1300}
1301
1302void QgsMapLayer::exportNamedStyle( QDomDocument &doc, QString &errorMsg, const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories ) const
1303{
1304 QDomImplementation DomImplementation;
1305 const QDomDocumentType documentType = DomImplementation.createDocumentType( QStringLiteral( "qgis" ), QStringLiteral( "http://mrcc.com/qgis.dtd" ), QStringLiteral( "SYSTEM" ) );
1306 QDomDocument myDocument( documentType );
1307
1308 QDomElement myRootNode = myDocument.createElement( QStringLiteral( "qgis" ) );
1309 myRootNode.setAttribute( QStringLiteral( "version" ), Qgis::version() );
1310 myDocument.appendChild( myRootNode );
1311
1312 if ( !writeSymbology( myRootNode, myDocument, errorMsg, context, categories ) ) // TODO: support relative paths in QML?
1313 {
1314 errorMsg = QObject::tr( "Could not save symbology because:\n%1" ).arg( errorMsg );
1315 return;
1316 }
1317
1318 /*
1319 * Check to see if the layer is vector - in which case we should also export its geometryType
1320 * to avoid eventually pasting to a layer with a different geometry
1321 */
1323 {
1324 //Getting the selectionLayer geometry
1325 const QgsVectorLayer *vl = qobject_cast<const QgsVectorLayer *>( this );
1326 const QString geoType = QString::number( vl->geometryType() );
1327
1328 //Adding geometryinformation
1329 QDomElement layerGeometryType = myDocument.createElement( QStringLiteral( "layerGeometryType" ) );
1330 const QDomText type = myDocument.createTextNode( geoType );
1331
1332 layerGeometryType.appendChild( type );
1333 myRootNode.appendChild( layerGeometryType );
1334 }
1335
1336 doc = myDocument;
1337}
1338
1339QString QgsMapLayer::saveDefaultStyle( bool &resultFlag )
1340{
1341 return saveDefaultStyle( resultFlag, AllStyleCategories );
1342}
1343
1344QString QgsMapLayer::saveDefaultStyle( bool &resultFlag, StyleCategories categories )
1345{
1346 return saveNamedStyle( styleURI(), resultFlag, categories );
1347}
1348
1349QString QgsMapLayer::saveNamedMetadata( const QString &uri, bool &resultFlag )
1350{
1351 return saveNamedProperty( uri, QgsMapLayer::Metadata, resultFlag );
1352}
1353
1354QString QgsMapLayer::loadNamedMetadata( const QString &uri, bool &resultFlag )
1355{
1356 return loadNamedProperty( uri, QgsMapLayer::Metadata, resultFlag );
1357}
1358
1359QString QgsMapLayer::saveNamedProperty( const QString &uri, QgsMapLayer::PropertyType type, bool &resultFlag, StyleCategories categories )
1360{
1361 // check if the uri is a file or ends with .qml/.qmd,
1362 // which indicates that it should become one
1363 // everything else goes to the database
1364 QString filename;
1365
1366 QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( this );
1367 if ( vlayer && vlayer->providerType() == QLatin1String( "ogr" ) )
1368 {
1369 QStringList theURIParts = uri.split( '|' );
1370 filename = theURIParts[0];
1371 }
1372 else if ( vlayer && vlayer->providerType() == QLatin1String( "gpx" ) )
1373 {
1374 QStringList theURIParts = uri.split( '?' );
1375 filename = theURIParts[0];
1376 }
1377 else if ( vlayer && vlayer->providerType() == QLatin1String( "delimitedtext" ) )
1378 {
1379 filename = QUrl::fromEncoded( uri.toLatin1() ).toLocalFile();
1380 // toLocalFile() returns an empty string if theURI is a plain Windows-path, e.g. "C:/style.qml"
1381 if ( filename.isEmpty() )
1382 filename = uri;
1383 }
1384 else
1385 {
1386 filename = uri;
1387 }
1388
1389 QString myErrorMessage;
1390 QDomDocument myDocument;
1391 switch ( type )
1392 {
1393 case Metadata:
1394 exportNamedMetadata( myDocument, myErrorMessage );
1395 break;
1396
1397 case Style:
1398 const QgsReadWriteContext context;
1399 exportNamedStyle( myDocument, myErrorMessage, context, categories );
1400 break;
1401 }
1402
1403 const QFileInfo myFileInfo( filename );
1404 if ( myFileInfo.exists() || filename.endsWith( QgsMapLayer::extensionPropertyType( type ), Qt::CaseInsensitive ) )
1405 {
1406 const QFileInfo myDirInfo( myFileInfo.path() ); //excludes file name
1407 if ( !myDirInfo.isWritable() )
1408 {
1409 return tr( "The directory containing your dataset needs to be writable!" );
1410 }
1411
1412 // now construct the file name for our .qml or .qmd file
1413 const QString myFileName = myFileInfo.path() + QDir::separator() + myFileInfo.completeBaseName() + QgsMapLayer::extensionPropertyType( type );
1414
1415 QFile myFile( myFileName );
1416 if ( myFile.open( QFile::WriteOnly | QFile::Truncate ) )
1417 {
1418 QTextStream myFileStream( &myFile );
1419 // save as utf-8 with 2 spaces for indents
1420 myDocument.save( myFileStream, 2 );
1421 myFile.close();
1422 resultFlag = true;
1423 switch ( type )
1424 {
1425 case Metadata:
1426 return tr( "Created default metadata file as %1" ).arg( myFileName );
1427
1428 case Style:
1429 return tr( "Created default style file as %1" ).arg( myFileName );
1430 }
1431
1432 }
1433 else
1434 {
1435 resultFlag = false;
1436 switch ( type )
1437 {
1438 case Metadata:
1439 return tr( "ERROR: Failed to created default metadata file as %1. Check file permissions and retry." ).arg( myFileName );
1440
1441 case Style:
1442 return tr( "ERROR: Failed to created default style file as %1. Check file permissions and retry." ).arg( myFileName );
1443 }
1444 }
1445 }
1446 else
1447 {
1448 const QString qml = myDocument.toString();
1449
1450 // read from database
1453
1454 int myResult = database.open( QDir( QgsApplication::qgisSettingsDirPath() ).absoluteFilePath( QStringLiteral( "qgis.qmldb" ) ) );
1455 if ( myResult != SQLITE_OK )
1456 {
1457 return tr( "User database could not be opened." );
1458 }
1459
1460 QByteArray param0 = uri.toUtf8();
1461 QByteArray param1 = qml.toUtf8();
1462
1463 QString mySql;
1464 switch ( type )
1465 {
1466 case Metadata:
1467 mySql = QStringLiteral( "create table if not exists tbl_metadata(metadata varchar primary key,qmd varchar)" );
1468 break;
1469
1470 case Style:
1471 mySql = QStringLiteral( "create table if not exists tbl_styles(style varchar primary key,qml varchar)" );
1472 break;
1473 }
1474
1475 statement = database.prepare( mySql, myResult );
1476 if ( myResult == SQLITE_OK )
1477 {
1478 if ( sqlite3_step( statement.get() ) != SQLITE_DONE )
1479 {
1480 resultFlag = false;
1481 switch ( type )
1482 {
1483 case Metadata:
1484 return tr( "The metadata table could not be created." );
1485
1486 case Style:
1487 return tr( "The style table could not be created." );
1488 }
1489 }
1490 }
1491
1492 switch ( type )
1493 {
1494 case Metadata:
1495 mySql = QStringLiteral( "insert into tbl_metadata(metadata,qmd) values (?,?)" );
1496 break;
1497
1498 case Style:
1499 mySql = QStringLiteral( "insert into tbl_styles(style,qml) values (?,?)" );
1500 break;
1501 }
1502 statement = database.prepare( mySql, myResult );
1503 if ( myResult == SQLITE_OK )
1504 {
1505 if ( sqlite3_bind_text( statement.get(), 1, param0.data(), param0.length(), SQLITE_STATIC ) == SQLITE_OK &&
1506 sqlite3_bind_text( statement.get(), 2, param1.data(), param1.length(), SQLITE_STATIC ) == SQLITE_OK &&
1507 sqlite3_step( statement.get() ) == SQLITE_DONE )
1508 {
1509 resultFlag = true;
1510 switch ( type )
1511 {
1512 case Metadata:
1513 myErrorMessage = tr( "The metadata %1 was saved to database" ).arg( uri );
1514 break;
1515
1516 case Style:
1517 myErrorMessage = tr( "The style %1 was saved to database" ).arg( uri );
1518 break;
1519 }
1520 }
1521 }
1522
1523 if ( !resultFlag )
1524 {
1525 QString mySql;
1526 switch ( type )
1527 {
1528 case Metadata:
1529 mySql = QStringLiteral( "update tbl_metadata set qmd=? where metadata=?" );
1530 break;
1531
1532 case Style:
1533 mySql = QStringLiteral( "update tbl_styles set qml=? where style=?" );
1534 break;
1535 }
1536 statement = database.prepare( mySql, myResult );
1537 if ( myResult == SQLITE_OK )
1538 {
1539 if ( sqlite3_bind_text( statement.get(), 2, param0.data(), param0.length(), SQLITE_STATIC ) == SQLITE_OK &&
1540 sqlite3_bind_text( statement.get(), 1, param1.data(), param1.length(), SQLITE_STATIC ) == SQLITE_OK &&
1541 sqlite3_step( statement.get() ) == SQLITE_DONE )
1542 {
1543 resultFlag = true;
1544 switch ( type )
1545 {
1546 case Metadata:
1547 myErrorMessage = tr( "The metadata %1 was updated in the database." ).arg( uri );
1548 break;
1549
1550 case Style:
1551 myErrorMessage = tr( "The style %1 was updated in the database." ).arg( uri );
1552 break;
1553 }
1554 }
1555 else
1556 {
1557 resultFlag = false;
1558 switch ( type )
1559 {
1560 case Metadata:
1561 myErrorMessage = tr( "The metadata %1 could not be updated in the database." ).arg( uri );
1562 break;
1563
1564 case Style:
1565 myErrorMessage = tr( "The style %1 could not be updated in the database." ).arg( uri );
1566 break;
1567 }
1568 }
1569 }
1570 else
1571 {
1572 resultFlag = false;
1573 switch ( type )
1574 {
1575 case Metadata:
1576 myErrorMessage = tr( "The metadata %1 could not be inserted into database." ).arg( uri );
1577 break;
1578
1579 case Style:
1580 myErrorMessage = tr( "The style %1 could not be inserted into database." ).arg( uri );
1581 break;
1582 }
1583 }
1584 }
1585 }
1586
1587 return myErrorMessage;
1588}
1589
1590QString QgsMapLayer::saveNamedStyle( const QString &uri, bool &resultFlag, StyleCategories categories )
1591{
1592 return saveNamedProperty( uri, QgsMapLayer::Style, resultFlag, categories );
1593}
1594
1595void QgsMapLayer::exportSldStyle( QDomDocument &doc, QString &errorMsg ) const
1596{
1597 QDomDocument myDocument = QDomDocument();
1598
1599 const QDomNode header = myDocument.createProcessingInstruction( QStringLiteral( "xml" ), QStringLiteral( "version=\"1.0\" encoding=\"UTF-8\"" ) );
1600 myDocument.appendChild( header );
1601
1602 const QgsVectorLayer *vlayer = qobject_cast<const QgsVectorLayer *>( this );
1603 const QgsRasterLayer *rlayer = qobject_cast<const QgsRasterLayer *>( this );
1604 if ( !vlayer && !rlayer )
1605 {
1606 errorMsg = tr( "Could not save symbology because:\n%1" )
1607 .arg( tr( "Only vector and raster layers are supported" ) );
1608 return;
1609 }
1610
1611 // Create the root element
1612 QDomElement root = myDocument.createElementNS( QStringLiteral( "http://www.opengis.net/sld" ), QStringLiteral( "StyledLayerDescriptor" ) );
1613 QDomElement layerNode;
1614 if ( vlayer )
1615 {
1616 root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.1.0" ) );
1617 root.setAttribute( QStringLiteral( "xsi:schemaLocation" ), QStringLiteral( "http://www.opengis.net/sld http://schemas.opengis.net/sld/1.1.0/StyledLayerDescriptor.xsd" ) );
1618 root.setAttribute( QStringLiteral( "xmlns:ogc" ), QStringLiteral( "http://www.opengis.net/ogc" ) );
1619 root.setAttribute( QStringLiteral( "xmlns:se" ), QStringLiteral( "http://www.opengis.net/se" ) );
1620 root.setAttribute( QStringLiteral( "xmlns:xlink" ), QStringLiteral( "http://www.w3.org/1999/xlink" ) );
1621 root.setAttribute( QStringLiteral( "xmlns:xsi" ), QStringLiteral( "http://www.w3.org/2001/XMLSchema-instance" ) );
1622 myDocument.appendChild( root );
1623
1624 // Create the NamedLayer element
1625 layerNode = myDocument.createElement( QStringLiteral( "NamedLayer" ) );
1626 root.appendChild( layerNode );
1627 }
1628
1629 // note: Only SLD 1.0 version is generated because seems none is using SE1.1.0 at least for rasters
1630 if ( rlayer )
1631 {
1632 // Create the root element
1633 root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0.0" ) );
1634 root.setAttribute( QStringLiteral( "xmlns:gml" ), QStringLiteral( "http://www.opengis.net/gml" ) );
1635 root.setAttribute( QStringLiteral( "xmlns:ogc" ), QStringLiteral( "http://www.opengis.net/ogc" ) );
1636 root.setAttribute( QStringLiteral( "xmlns:sld" ), QStringLiteral( "http://www.opengis.net/sld" ) );
1637 myDocument.appendChild( root );
1638
1639 // Create the NamedLayer element
1640 layerNode = myDocument.createElement( QStringLiteral( "UserLayer" ) );
1641 root.appendChild( layerNode );
1642 }
1643
1644 QVariantMap props;
1646 {
1647 props[ QStringLiteral( "scaleMinDenom" ) ] = QString::number( mMinScale );
1648 props[ QStringLiteral( "scaleMaxDenom" ) ] = QString::number( mMaxScale );
1649 }
1650
1651 if ( vlayer )
1652 {
1653 if ( !vlayer->writeSld( layerNode, myDocument, errorMsg, props ) )
1654 {
1655 errorMsg = tr( "Could not save symbology because:\n%1" ).arg( errorMsg );
1656 return;
1657 }
1658 }
1659
1660 if ( rlayer )
1661 {
1662 if ( !rlayer->writeSld( layerNode, myDocument, errorMsg, props ) )
1663 {
1664 errorMsg = tr( "Could not save symbology because:\n%1" ).arg( errorMsg );
1665 return;
1666 }
1667 }
1668
1669 doc = myDocument;
1670}
1671
1672QString QgsMapLayer::saveSldStyle( const QString &uri, bool &resultFlag ) const
1673{
1674 const QgsMapLayer *mlayer = qobject_cast<const QgsMapLayer *>( this );
1675
1676 QString errorMsg;
1677 QDomDocument myDocument;
1678 mlayer->exportSldStyle( myDocument, errorMsg );
1679 if ( !errorMsg.isNull() )
1680 {
1681 resultFlag = false;
1682 return errorMsg;
1683 }
1684 // check if the uri is a file or ends with .sld,
1685 // which indicates that it should become one
1686 QString filename;
1687 if ( mlayer->providerType() == QLatin1String( "ogr" ) )
1688 {
1689 QStringList theURIParts = uri.split( '|' );
1690 filename = theURIParts[0];
1691 }
1692 else if ( mlayer->providerType() == QLatin1String( "gpx" ) )
1693 {
1694 QStringList theURIParts = uri.split( '?' );
1695 filename = theURIParts[0];
1696 }
1697 else if ( mlayer->providerType() == QLatin1String( "delimitedtext" ) )
1698 {
1699 filename = QUrl::fromEncoded( uri.toLatin1() ).toLocalFile();
1700 // toLocalFile() returns an empty string if theURI is a plain Windows-path, e.g. "C:/style.qml"
1701 if ( filename.isEmpty() )
1702 filename = uri;
1703 }
1704 else
1705 {
1706 filename = uri;
1707 }
1708
1709 const QFileInfo myFileInfo( filename );
1710 if ( myFileInfo.exists() || filename.endsWith( QLatin1String( ".sld" ), Qt::CaseInsensitive ) )
1711 {
1712 const QFileInfo myDirInfo( myFileInfo.path() ); //excludes file name
1713 if ( !myDirInfo.isWritable() )
1714 {
1715 return tr( "The directory containing your dataset needs to be writable!" );
1716 }
1717
1718 // now construct the file name for our .sld style file
1719 const QString myFileName = myFileInfo.path() + QDir::separator() + myFileInfo.completeBaseName() + ".sld";
1720
1721 QFile myFile( myFileName );
1722 if ( myFile.open( QFile::WriteOnly | QFile::Truncate ) )
1723 {
1724 QTextStream myFileStream( &myFile );
1725 // save as utf-8 with 2 spaces for indents
1726 myDocument.save( myFileStream, 2 );
1727 myFile.close();
1728 resultFlag = true;
1729 return tr( "Created default style file as %1" ).arg( myFileName );
1730 }
1731 }
1732
1733 resultFlag = false;
1734 return tr( "ERROR: Failed to created SLD style file as %1. Check file permissions and retry." ).arg( filename );
1735}
1736
1737QString QgsMapLayer::loadSldStyle( const QString &uri, bool &resultFlag )
1738{
1739 resultFlag = false;
1740
1741 QDomDocument myDocument;
1742
1743 // location of problem associated with errorMsg
1744 int line, column;
1745 QString myErrorMessage;
1746
1747 QFile myFile( uri );
1748 if ( myFile.open( QFile::ReadOnly ) )
1749 {
1750 // read file
1751 resultFlag = myDocument.setContent( &myFile, true, &myErrorMessage, &line, &column );
1752 if ( !resultFlag )
1753 myErrorMessage = tr( "%1 at line %2 column %3" ).arg( myErrorMessage ).arg( line ).arg( column );
1754 myFile.close();
1755 }
1756 else
1757 {
1758 myErrorMessage = tr( "Unable to open file %1" ).arg( uri );
1759 }
1760
1761 if ( !resultFlag )
1762 {
1763 return myErrorMessage;
1764 }
1765
1766 // check for root SLD element
1767 const QDomElement myRoot = myDocument.firstChildElement( QStringLiteral( "StyledLayerDescriptor" ) );
1768 if ( myRoot.isNull() )
1769 {
1770 myErrorMessage = QStringLiteral( "Error: StyledLayerDescriptor element not found in %1" ).arg( uri );
1771 resultFlag = false;
1772 return myErrorMessage;
1773 }
1774
1775 // now get the style node out and pass it over to the layer
1776 // to deserialise...
1777 const QDomElement namedLayerElem = myRoot.firstChildElement( QStringLiteral( "NamedLayer" ) );
1778 if ( namedLayerElem.isNull() )
1779 {
1780 myErrorMessage = QStringLiteral( "Info: NamedLayer element not found." );
1781 resultFlag = false;
1782 return myErrorMessage;
1783 }
1784
1785 QString errorMsg;
1786 resultFlag = readSld( namedLayerElem, errorMsg );
1787 if ( !resultFlag )
1788 {
1789 myErrorMessage = tr( "Loading style file %1 failed because:\n%2" ).arg( uri, errorMsg );
1790 return myErrorMessage;
1791 }
1792
1793 return QString();
1794}
1795
1796bool QgsMapLayer::readStyle( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories )
1797{
1798 Q_UNUSED( node )
1799 Q_UNUSED( errorMessage )
1800 Q_UNUSED( context )
1801 Q_UNUSED( categories )
1802 return false;
1803}
1804
1805bool QgsMapLayer::writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage,
1806 const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories ) const
1807{
1808 Q_UNUSED( node )
1809 Q_UNUSED( doc )
1810 Q_UNUSED( errorMessage )
1811 Q_UNUSED( context )
1812 Q_UNUSED( categories )
1813 return false;
1814}
1815
1816
1817void QgsMapLayer::setDataSource( const QString &dataSource, const QString &baseName, const QString &provider,
1818 bool loadDefaultStyleFlag )
1819{
1821
1822 QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags();
1823 if ( loadDefaultStyleFlag )
1824 {
1826 }
1827
1829 {
1831 }
1832 setDataSource( dataSource, baseName, provider, options, flags );
1833}
1834
1835void QgsMapLayer::setDataSource( const QString &dataSource, const QString &baseName, const QString &provider,
1836 const QgsDataProvider::ProviderOptions &options, bool loadDefaultStyleFlag )
1837{
1838 QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags();
1839 if ( loadDefaultStyleFlag )
1840 {
1842 }
1843
1845 {
1847 }
1848 setDataSource( dataSource, baseName, provider, options, flags );
1849}
1850
1851void QgsMapLayer::setDataSource( const QString &dataSource, const QString &baseName, const QString &provider,
1852 const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags )
1853{
1854
1857 {
1859 }
1860 setDataSourcePrivate( dataSource, baseName, provider, options, flags );
1861 emit dataSourceChanged();
1862 emit dataChanged();
1864}
1865
1866
1867void QgsMapLayer::setDataSourcePrivate( const QString &dataSource, const QString &baseName, const QString &provider,
1868 const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags )
1869{
1870 Q_UNUSED( dataSource )
1871 Q_UNUSED( baseName )
1872 Q_UNUSED( provider )
1873 Q_UNUSED( options )
1874 Q_UNUSED( flags )
1875}
1876
1877
1879{
1880 return mProviderKey;
1881}
1882
1883void QgsMapLayer::readCommonStyle( const QDomElement &layerElement, const QgsReadWriteContext &context,
1884 QgsMapLayer::StyleCategories categories )
1885{
1886 if ( categories.testFlag( Symbology3D ) )
1887 {
1888 const QgsReadWriteContextCategoryPopper p = context.enterCategory( tr( "3D Symbology" ) );
1889
1890 QgsAbstract3DRenderer *r3D = nullptr;
1891 QDomElement renderer3DElem = layerElement.firstChildElement( QStringLiteral( "renderer-3d" ) );
1892 if ( !renderer3DElem.isNull() )
1893 {
1894 const QString type3D = renderer3DElem.attribute( QStringLiteral( "type" ) );
1896 if ( meta3D )
1897 {
1898 r3D = meta3D->createRenderer( renderer3DElem, context );
1899 }
1900 }
1901 setRenderer3D( r3D );
1902 }
1903
1904 if ( categories.testFlag( CustomProperties ) )
1905 {
1906 // read custom properties before passing reading further to a subclass, so that
1907 // the subclass can also read custom properties
1908 readCustomProperties( layerElement );
1909 }
1910
1911 // use scale dependent visibility flag
1912 if ( categories.testFlag( Rendering ) )
1913 {
1914 setScaleBasedVisibility( layerElement.attribute( QStringLiteral( "hasScaleBasedVisibilityFlag" ) ).toInt() == 1 );
1915 if ( layerElement.hasAttribute( QStringLiteral( "minimumScale" ) ) )
1916 {
1917 // older element, when scales were reversed
1918 setMaximumScale( layerElement.attribute( QStringLiteral( "minimumScale" ) ).toDouble() );
1919 setMinimumScale( layerElement.attribute( QStringLiteral( "maximumScale" ) ).toDouble() );
1920 }
1921 else
1922 {
1923 setMaximumScale( layerElement.attribute( QStringLiteral( "maxScale" ) ).toDouble() );
1924 setMinimumScale( layerElement.attribute( QStringLiteral( "minScale" ) ).toDouble() );
1925 }
1926 }
1927
1928 if ( categories.testFlag( LayerConfiguration ) )
1929 {
1930 // flags
1931 const QDomElement flagsElem = layerElement.firstChildElement( QStringLiteral( "flags" ) );
1932 LayerFlags flags = mFlags;
1933 const auto enumMap = qgsEnumMap<QgsMapLayer::LayerFlag>();
1934 for ( auto it = enumMap.constBegin(); it != enumMap.constEnd(); ++it )
1935 {
1936 const QDomNode flagNode = flagsElem.namedItem( it.value() );
1937 if ( flagNode.isNull() )
1938 continue;
1939 const bool flagValue = flagNode.toElement().text() == "1" ? true : false;
1940 if ( flags.testFlag( it.key() ) && !flagValue )
1941 flags &= ~it.key();
1942 else if ( !flags.testFlag( it.key() ) && flagValue )
1943 flags |= it.key();
1944 }
1945 setFlags( flags );
1946 }
1947
1948 if ( categories.testFlag( Temporal ) )
1949 {
1950 const QgsReadWriteContextCategoryPopper p = context.enterCategory( tr( "Temporal" ) );
1951
1953 properties->readXml( layerElement.toElement(), context );
1954 }
1955
1956 if ( categories.testFlag( Elevation ) )
1957 {
1958 const QgsReadWriteContextCategoryPopper p = context.enterCategory( tr( "Elevation" ) );
1959
1961 properties->readXml( layerElement.toElement(), context );
1962 }
1963
1964 if ( categories.testFlag( Notes ) )
1965 {
1966 const QDomElement notesElem = layerElement.firstChildElement( QStringLiteral( "userNotes" ) );
1967 if ( !notesElem.isNull() )
1968 {
1969 const QString notes = notesElem.attribute( QStringLiteral( "value" ) );
1970 QgsLayerNotesUtils::setLayerNotes( this, notes );
1971 }
1972 }
1973}
1974
1976{
1977 return mUndoStack;
1978}
1979
1981{
1982 return mUndoStackStyles;
1983}
1984
1986{
1987 return mCustomProperties.keys();
1988}
1989
1990void QgsMapLayer::setCustomProperty( const QString &key, const QVariant &value )
1991{
1992 if ( !mCustomProperties.contains( key ) || mCustomProperties.value( key ) != value )
1993 {
1994 mCustomProperties.setValue( key, value );
1995 emit customPropertyChanged( key );
1996 }
1997}
1998
2000{
2001 mCustomProperties = properties;
2002 for ( const QString &key : mCustomProperties.keys() )
2003 {
2004 emit customPropertyChanged( key );
2005 }
2006}
2007
2009{
2010 return mCustomProperties;
2011}
2012
2013QVariant QgsMapLayer::customProperty( const QString &value, const QVariant &defaultValue ) const
2014{
2015 return mCustomProperties.value( value, defaultValue );
2016}
2017
2018void QgsMapLayer::removeCustomProperty( const QString &key )
2019{
2020
2021 if ( mCustomProperties.contains( key ) )
2022 {
2023 mCustomProperties.remove( key );
2024 emit customPropertyChanged( key );
2025 }
2026}
2027
2029{
2030 return mError;
2031}
2032
2033
2034
2036{
2037 return false;
2038}
2039
2041{
2042 return false;
2043}
2044
2046{
2047 return true;
2048}
2049
2051{
2052 // invalid layers are temporary? -- who knows?!
2053 if ( !isValid() )
2054 return false;
2055
2056 if ( mProviderKey == QLatin1String( "memory" ) )
2057 return true;
2058
2059 const QVariantMap sourceParts = QgsProviderRegistry::instance()->decodeUri( mProviderKey, mDataSource );
2060 const QString path = sourceParts.value( QStringLiteral( "path" ) ).toString();
2061 if ( path.isEmpty() )
2062 return false;
2063
2064 // check if layer path is inside one of the standard temporary file locations for this platform
2065 const QStringList tempPaths = QStandardPaths::standardLocations( QStandardPaths::TempLocation );
2066 for ( const QString &tempPath : tempPaths )
2067 {
2068 if ( path.startsWith( tempPath ) )
2069 return true;
2070 }
2071
2072 return false;
2073}
2074
2075void QgsMapLayer::setValid( bool valid )
2076{
2077 if ( mValid == valid )
2078 return;
2079
2080 mValid = valid;
2081 emit isValidChanged();
2082}
2083
2085{
2086 if ( legend == mLegend )
2087 return;
2088
2089 delete mLegend;
2090 mLegend = legend;
2091
2092 if ( mLegend )
2093 {
2094 mLegend->setParent( this );
2095 connect( mLegend, &QgsMapLayerLegend::itemsChanged, this, &QgsMapLayer::legendChanged, Qt::UniqueConnection );
2096 }
2097
2098 emit legendChanged();
2099}
2100
2102{
2103 return mLegend;
2104}
2105
2107{
2108 return mStyleManager;
2109}
2110
2112{
2113 if ( renderer == m3DRenderer )
2114 return;
2115
2116 delete m3DRenderer;
2117 m3DRenderer = renderer;
2118 emit renderer3DChanged();
2119 emit repaintRequested();
2121}
2122
2124{
2125 return m3DRenderer;
2126}
2127
2128void QgsMapLayer::triggerRepaint( bool deferredUpdate )
2129{
2130 if ( mRepaintRequestedFired )
2131 return;
2132 mRepaintRequestedFired = true;
2133 emit repaintRequested( deferredUpdate );
2134 mRepaintRequestedFired = false;
2135}
2136
2138{
2139 emit request3DUpdate();
2140}
2141
2143{
2144 mMetadata = metadata;
2145// mMetadata.saveToLayer( this );
2146 emit metadataChanged();
2147}
2148
2150{
2151 return QString();
2152}
2153
2154QDateTime QgsMapLayer::timestamp() const
2155{
2156 return QDateTime();
2157}
2158
2160{
2162 emit styleChanged();
2163}
2164
2166{
2167 updateExtent( extent );
2168}
2169
2170bool QgsMapLayer::isReadOnly() const
2171{
2172 return true;
2173}
2174
2176{
2177 return mOriginalXmlProperties;
2178}
2179
2180void QgsMapLayer::setOriginalXmlProperties( const QString &originalXmlProperties )
2181{
2182 mOriginalXmlProperties = originalXmlProperties;
2183}
2184
2185QString QgsMapLayer::generateId( const QString &layerName )
2186{
2187 // Generate the unique ID of this layer
2188 const QString uuid = QUuid::createUuid().toString();
2189 // trim { } from uuid
2190 QString id = layerName + '_' + uuid.mid( 1, uuid.length() - 2 );
2191 // Tidy the ID up to avoid characters that may cause problems
2192 // elsewhere (e.g in some parts of XML). Replaces every non-word
2193 // character (word characters are the alphabet, numbers and
2194 // underscore) with an underscore.
2195 // Note that the first backslash in the regular expression is
2196 // there for the compiler, so the pattern is actually \W
2197 id.replace( QRegularExpression( "[\\W]" ), QStringLiteral( "_" ) );
2198 return id;
2199}
2200
2202{
2203 return true;
2204}
2205
2206void QgsMapLayer::setProviderType( const QString &providerType )
2207{
2209}
2210
2211QSet<QgsMapLayerDependency> QgsMapLayer::dependencies() const
2212{
2213 return mDependencies;
2214}
2215
2216bool QgsMapLayer::setDependencies( const QSet<QgsMapLayerDependency> &oDeps )
2217{
2218 QSet<QgsMapLayerDependency> deps;
2219 const auto constODeps = oDeps;
2220 for ( const QgsMapLayerDependency &dep : constODeps )
2221 {
2222 if ( dep.origin() == QgsMapLayerDependency::FromUser )
2223 deps << dep;
2224 }
2225
2226 mDependencies = deps;
2227 emit dependenciesChanged();
2228 return true;
2229}
2230
2232{
2233 QgsDataProvider *lDataProvider = dataProvider();
2234
2235 if ( !lDataProvider )
2236 return;
2237
2238 if ( enabled && !isRefreshOnNotifyEnabled() )
2239 {
2240 lDataProvider->setListening( enabled );
2241 connect( lDataProvider, &QgsDataProvider::notify, this, &QgsMapLayer::onNotified );
2242 }
2243 else if ( !enabled && isRefreshOnNotifyEnabled() )
2244 {
2245 // we don't want to disable provider listening because someone else could need it (e.g. actions)
2246 disconnect( lDataProvider, &QgsDataProvider::notify, this, &QgsMapLayer::onNotified );
2247 }
2248 mIsRefreshOnNofifyEnabled = enabled;
2249}
2250
2252{
2253 if ( QgsMapLayerStore *store = qobject_cast<QgsMapLayerStore *>( parent() ) )
2254 {
2255 return qobject_cast<QgsProject *>( store->parent() );
2256 }
2257 return nullptr;
2258}
2259
2260void QgsMapLayer::onNotified( const QString &message )
2261{
2262 if ( refreshOnNotifyMessage().isEmpty() || refreshOnNotifyMessage() == message )
2263 {
2265 emit dataChanged();
2266 }
2267}
2268
2269QgsRectangle QgsMapLayer::wgs84Extent( bool forceRecalculate ) const
2270{
2272
2273 if ( ! forceRecalculate && ! mWgs84Extent.isNull() )
2274 {
2275 wgs84Extent = mWgs84Extent;
2276 }
2277 else if ( ! mExtent.isNull() )
2278 {
2280 transformer.setBallparkTransformsAreAppropriate( true );
2281 try
2282 {
2283 wgs84Extent = transformer.transformBoundingBox( mExtent );
2284 }
2285 catch ( const QgsCsException &cse )
2286 {
2287 QgsMessageLog::logMessage( tr( "Error transforming extent: %1" ).arg( cse.what() ) );
2289 }
2290 }
2291 return wgs84Extent;
2292}
2293
2294void QgsMapLayer::updateExtent( const QgsRectangle &extent ) const
2295{
2296 if ( extent == mExtent )
2297 return;
2298
2299 mExtent = extent;
2300
2301 // do not update the wgs84 extent if we trust layer metadata
2302 if ( mReadFlags & QgsMapLayer::ReadFlag::FlagTrustLayerMetadata )
2303 return;
2304
2305 mWgs84Extent = wgs84Extent( true );
2306}
2307
2309{
2310 // do not update the wgs84 extent if we trust layer metadata
2311 if ( mReadFlags & QgsMapLayer::ReadFlag::FlagTrustLayerMetadata )
2312 return;
2313
2314 mWgs84Extent = QgsRectangle();
2315}
2316
2318{
2319 QString metadata = QStringLiteral( "<h1>" ) + tr( "General" ) + QStringLiteral( "</h1>\n<hr>\n" ) + QStringLiteral( "<table class=\"list-view\">\n" );
2320
2321 // name
2322 metadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Name" ) + QStringLiteral( "</td><td>" ) + name() + QStringLiteral( "</td></tr>\n" );
2323
2324 QString path;
2325 bool isLocalPath = false;
2326 if ( dataProvider() )
2327 {
2328 // local path
2329 QVariantMap uriComponents = QgsProviderRegistry::instance()->decodeUri( dataProvider()->name(), publicSource() );
2330 if ( uriComponents.contains( QStringLiteral( "path" ) ) )
2331 {
2332 path = uriComponents[QStringLiteral( "path" )].toString();
2333 QFileInfo fi( path );
2334 if ( fi.exists() )
2335 {
2336 isLocalPath = true;
2337 metadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Path" ) + QStringLiteral( "</td><td>%1" ).arg( QStringLiteral( "<a href=\"%1\">%2</a>" ).arg( QUrl::fromLocalFile( path ).toString(), QDir::toNativeSeparators( path ) ) ) + QStringLiteral( "</td></tr>\n" );
2338
2339 QDateTime lastModified = fi.lastModified();
2340 QString lastModifiedFileName;
2341 QSet<QString> sidecarFiles = QgsFileUtils::sidecarFilesForPath( path );
2342 if ( fi.isFile() )
2343 {
2344 qint64 fileSize = fi.size();
2345 if ( !sidecarFiles.isEmpty() )
2346 {
2347 lastModifiedFileName = fi.fileName();
2348 QStringList sidecarFileNames;
2349 for ( const QString &sidecarFile : sidecarFiles )
2350 {
2351 QFileInfo sidecarFi( sidecarFile );
2352 fileSize += sidecarFi.size();
2353 if ( sidecarFi.lastModified() > lastModified )
2354 {
2355 lastModified = sidecarFi.lastModified();
2356 lastModifiedFileName = sidecarFi.fileName();
2357 }
2358 sidecarFileNames << sidecarFi.fileName();
2359 }
2360 metadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + ( sidecarFiles.size() > 1 ? tr( "Sidecar files" ) : tr( "Sidecar file" ) ) + QStringLiteral( "</td><td>%1" ).arg( sidecarFileNames.join( QLatin1String( ", " ) ) ) + QStringLiteral( "</td></tr>\n" );
2361 }
2362 metadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + ( !sidecarFiles.isEmpty() ? tr( "Total size" ) : tr( "Size" ) ) + QStringLiteral( "</td><td>%1" ).arg( QgsFileUtils::representFileSize( fileSize ) ) + QStringLiteral( "</td></tr>\n" );
2363 }
2364 metadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Last modified" ) + QStringLiteral( "</td><td>%1" ).arg( QLocale().toString( fi.lastModified() ) ) + ( !lastModifiedFileName.isEmpty() ? QStringLiteral( " (%1)" ).arg( lastModifiedFileName ) : QString() ) + QStringLiteral( "</td></tr>\n" );
2365 }
2366 }
2367 if ( uriComponents.contains( QStringLiteral( "url" ) ) )
2368 {
2369 const QString url = uriComponents[QStringLiteral( "url" )].toString();
2370 metadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "URL" ) + QStringLiteral( "</td><td>%1" ).arg( QStringLiteral( "<a href=\"%1\">%2</a>" ).arg( QUrl( url ).toString(), url ) ) + QStringLiteral( "</td></tr>\n" );
2371 }
2372 }
2373
2374 // data source
2375 if ( publicSource() != path || !isLocalPath )
2376 metadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Source" ) + QStringLiteral( "</td><td>%1" ).arg( publicSource() != path ? publicSource() : path ) + QStringLiteral( "</td></tr>\n" );
2377
2378 // provider
2379 if ( dataProvider() )
2380 metadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Provider" ) + QStringLiteral( "</td><td>%1" ).arg( dataProvider()->name() ) + QStringLiteral( "</td></tr>\n" );
2381
2382 metadata += QLatin1String( "</table>\n<br><br>" );
2383 return metadata;
2384}
2385
2387{
2388 QString metadata = QStringLiteral( "<h1>" ) + tr( "Coordinate Reference System (CRS)" ) + QStringLiteral( "</h1>\n<hr>\n" );
2389 metadata += QLatin1String( "<table class=\"list-view\">\n" );
2390
2391 // Identifier
2393 if ( !c.isValid() )
2394 metadata += QStringLiteral( "<tr><td colspan=\"2\" class=\"highlight\">" ) + tr( "Unknown" ) + QStringLiteral( "</td></tr>\n" );
2395 else
2396 {
2397 metadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Name" ) + QStringLiteral( "</td><td>" ) + c.userFriendlyIdentifier( QgsCoordinateReferenceSystem::FullString ) + QStringLiteral( "</td></tr>\n" );
2398
2399 // map units
2400 metadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Units" ) + QStringLiteral( "</td><td>" )
2401 + ( c.isGeographic() ? tr( "Geographic (uses latitude and longitude for coordinates)" ) : QgsUnitTypes::toString( c.mapUnits() ) )
2402 + QStringLiteral( "</td></tr>\n" );
2403
2404
2405 // operation
2406 const QgsProjOperation operation = c.operation();
2407 metadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Method" ) + QStringLiteral( "</td><td>" ) + operation.description() + QStringLiteral( "</td></tr>\n" );
2408
2409 // celestial body
2410 try
2411 {
2412 const QString celestialBody = c.celestialBodyName();
2413 if ( !celestialBody.isEmpty() )
2414 {
2415 metadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Celestial body" ) + QStringLiteral( "</td><td>" ) + celestialBody + QStringLiteral( "</td></tr>\n" );
2416 }
2417 }
2418 catch ( QgsNotSupportedException & )
2419 {
2420
2421 }
2422
2423 QString accuracyString;
2424 // dynamic crs with no epoch?
2425 if ( c.isDynamic() && std::isnan( c.coordinateEpoch() ) )
2426 {
2427 accuracyString = tr( "Based on a dynamic CRS, but no coordinate epoch is set. Coordinates are ambiguous and of limited accuracy." );
2428 }
2429
2430 // based on datum ensemble?
2431 try
2432 {
2433 const QgsDatumEnsemble ensemble = c.datumEnsemble();
2434 if ( ensemble.isValid() )
2435 {
2436 QString id;
2437 if ( !ensemble.code().isEmpty() )
2438 id = QStringLiteral( "<i>%1</i> (%2:%3)" ).arg( ensemble.name(), ensemble.authority(), ensemble.code() );
2439 else
2440 id = QStringLiteral( "<i>%</i>”" ).arg( ensemble.name() );
2441
2442 if ( ensemble.accuracy() > 0 )
2443 {
2444 accuracyString = tr( "Based on %1, which has a limited accuracy of <b>at best %2 meters</b>." ).arg( id ).arg( ensemble.accuracy() );
2445 }
2446 else
2447 {
2448 accuracyString = tr( "Based on %1, which has a limited accuracy." ).arg( id );
2449 }
2450 }
2451 }
2452 catch ( QgsNotSupportedException & )
2453 {
2454
2455 }
2456
2457 if ( !accuracyString.isEmpty() )
2458 {
2459 metadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Accuracy" ) + QStringLiteral( "</td><td>" ) + accuracyString + QStringLiteral( "</td></tr>\n" );
2460 }
2461
2462 // static/dynamic
2463 metadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Reference" ) + QStringLiteral( "</td><td>%1</td></tr>\n" ).arg( c.isDynamic() ? tr( "Dynamic (relies on a datum which is not plate-fixed)" ) : tr( "Static (relies on a datum which is plate-fixed)" ) );
2464
2465 // coordinate epoch
2466 if ( !std::isnan( c.coordinateEpoch() ) )
2467 {
2468 metadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Coordinate epoch" ) + QStringLiteral( "</td><td>%1</td></tr>\n" ).arg( c.coordinateEpoch() );
2469 }
2470 }
2471
2472 metadata += QLatin1String( "</table>\n<br><br>\n" );
2473 return metadata;
2474}
static QString version()
Version string.
Definition: qgis.cpp:277
static const double SCALE_PRECISION
Fudge factor used to compare two scales.
Definition: qgis.h:2665
@ ForceFirstLetterToCapital
Convert just the first letter of each word to uppercase, leave the rest untouched.
Base metadata class for 3D renderers.
virtual QgsAbstract3DRenderer * createRenderer(QDomElement &elem, const QgsReadWriteContext &context)=0
Returns new instance of the renderer given the DOM element.
Qgs3DRendererAbstractMetadata * rendererMetadata(const QString &type) const
Returns metadata for a 3D renderer type (may be used to create a new instance of the type)
Base class for all renderers that may to participate in 3D view.
virtual QString type() const =0
Returns unique identifier of the renderer class (used to identify subclass)
virtual void writeXml(QDomElement &elem, const QgsReadWriteContext &context) const =0
Writes renderer's properties to given XML element.
virtual void resolveReferences(const QgsProject &project)
Resolves references to other objects - second phase of loading - after readXml()
static QString pkgDataPath()
Returns the common root path of all application data directories.
static QString qgisSettingsDirPath()
Returns the path to the settings directory in user's home dir.
static QgsAuthManager * authManager()
Returns the application's authentication manager instance.
static Qgs3DRendererRegistry * renderer3DRegistry()
Returns registry of available 3D renderers.
bool setMasterPassword(bool verify=false)
Main call to initially set or continually check master password is set.
This class represents a coordinate reference system (CRS).
static QgsCoordinateReferenceSystem fromOgcWmsCrs(const QString &ogcCrs)
Creates a CRS from a given OGC WMS-format Coordinate Reference System string.
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
void validate()
Perform some validation on this CRS.
static CUSTOM_CRS_VALIDATION customCrsValidation()
Gets custom function.
bool readXml(const QDomNode &node)
Restores state from the given DOM node.
static void setCustomCrsValidation(CUSTOM_CRS_VALIDATION f)
Sets custom function to force valid CRS.
void setValidationHint(const QString &html)
Set user hint for validation.
@ FullString
Full definition – possibly a very lengthy string, e.g. with no truncation of custom WKT definitions.
bool writeXml(QDomNode &node, QDomDocument &doc) const
Stores state to the given Dom node in the given document.
Contains information about the context in which a coordinate transform is executed.
Class for doing transforms between two map coordinate systems.
Custom exception class for Coordinate Reference System related exceptions.
Definition: qgsexception.h:66
Abstract base class for spatial data provider implementations.
@ FlagLoadDefaultStyle
Reset the layer's style to the default for the datasource.
@ FlagTrustDataSource
Trust datasource config (primary key unicity, geometry type and srid, etc). Improves provider load ti...
QgsCoordinateTransformContext transformContext() const
Returns data provider coordinate transform context.
virtual void setListening(bool isListening)
Set whether the provider will listen to datasource notifications If set, the provider will issue noti...
void notify(const QString &msg)
Emitted when the datasource issues a notification.
static QString removePassword(const QString &aUri)
Removes the password element from a URI.
Contains information about a datum ensemble.
Definition: qgsdatums.h:95
QString code() const
Identification code, e.g.
Definition: qgsdatums.h:122
QString authority() const
Authority name, e.g.
Definition: qgsdatums.h:117
bool isValid() const
Returns true if the datum ensemble is a valid object, or false if it is a null/invalid object.
Definition: qgsdatums.h:102
QString name() const
Display name of datum ensemble.
Definition: qgsdatums.h:107
double accuracy() const
Positional accuracy (in meters).
Definition: qgsdatums.h:112
QgsError is container for error messages (report).
Definition: qgserror.h:81
QString what() const
Definition: qgsexception.h:48
static QSet< QString > sidecarFilesForPath(const QString &path)
Returns a list of the sidecar files which exist for the dataset a the specified path.
static QString representFileSize(qint64 bytes)
Returns the human size from bytes.
A structured metadata store for a map layer.
bool readMetadataXml(const QDomElement &metadataElement) override
Sets state from DOM document.
bool writeMetadataXml(QDomElement &metadataElement, QDomDocument &document) const override
Stores state in a DOM node.
static void setLayerNotes(QgsMapLayer *layer, const QString &notes)
Sets the notes for the specified layer, where notes is a HTML formatted string.
static bool layerHasNotes(const QgsMapLayer *layer)
Returns true if the specified layer has notes available.
static QString layerNotes(const QgsMapLayer *layer)
Returns the notes for the specified layer.
This class models dependencies with or between map layers.
Base class for storage of map layer elevation properties.
The QgsMapLayerLegend class is abstract interface for implementations of legends for one map layer.
void itemsChanged()
Emitted when existing items/nodes got invalid and should be replaced by new ones.
Manages QGIS Server properties for a map layer.
void readXml(const QDomNode &layer_node)
Reads server properties from project file.
void copyTo(QgsMapLayerServerProperties *properties) const
Copy properties to another instance.
A storage object for map layers, in which the layers are owned by the store and have their lifetime b...
Management of styles for use with one map layer.
bool addStyle(const QString &name, const QgsMapLayerStyle &style)
Add a style with given name and data.
QStringList styles() const
Returns list of all defined style names.
void writeXml(QDomElement &mgrElement) const
Write configuration (for project saving)
void reset()
Reset the style manager to a basic state - with one default style which is set as current.
void readXml(const QDomElement &mgrElement)
Read configuration (for project loading)
Base class for storage of map layer temporal properties.
Base class for all map layer types.
Definition: qgsmaplayer.h:73
QString mKeywordList
Definition: qgsmaplayer.h:1982
void setShortName(const QString &shortName)
Sets the short name of the layer used by QGIS Server to identify the layer.
Definition: qgsmaplayer.h:289
bool importNamedMetadata(QDomDocument &document, QString &errorMessage)
Import the metadata of this layer from a QDomDocument.
QString name
Definition: qgsmaplayer.h:76
void readStyleManager(const QDomNode &layerNode)
Read style manager's configuration (if any). To be called by subclasses.
virtual bool writeSymbology(QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories) const =0
Write the style for the layer into the document provided.
QString legendUrlFormat() const
Returns the format for a URL based layer legend.
Definition: qgsmaplayer.h:1299
QgsRectangle wgs84Extent(bool forceRecalculate=false) const
Returns the WGS84 extent (EPSG:4326) of the layer according to ReadFlag::FlagTrustLayerMetadata.
void setRefreshOnNotifyEnabled(bool enabled)
Set whether provider notification is connected to triggerRepaint.
virtual bool isSpatial() const
Returns true if the layer is considered a spatial layer, ie it has some form of geometry associated w...
QgsAbstract3DRenderer * renderer3D() const
Returns 3D renderer associated with the layer.
virtual bool isTemporary() const
Returns true if the layer is considered a temporary layer.
virtual void exportNamedStyle(QDomDocument &doc, QString &errorMsg, const QgsReadWriteContext &context=QgsReadWriteContext(), QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories) const
Export the properties of this layer as named style in a QDomDocument.
virtual bool accept(QgsStyleEntityVisitorInterface *visitor) const
Accepts the specified symbology visitor, causing it to visit all symbols associated with the layer.
void dependenciesChanged()
Emitted when dependencies are changed.
bool isInScaleRange(double scale) const
Tests whether the layer should be visible at the specified scale.
void legendChanged()
Signal emitted when legend of the layer has changed.
void writeStyleManager(QDomNode &layerNode, QDomDocument &doc) const
Write style manager's configuration (if exists). To be called by subclasses.
QgsMapLayerLegend * legend() const
Can be nullptr.
virtual bool importNamedStyle(QDomDocument &doc, QString &errorMsg, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories)
Import the properties of this layer from a QDomDocument.
void setAbstract(const QString &abstract)
Sets the abstract of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:319
void metadataChanged()
Emitted when the layer's metadata is changed.
virtual QgsRectangle extent() const
Returns the extent of the layer.
virtual QString saveSldStyle(const QString &uri, bool &resultFlag) const
Saves the properties of this layer to an SLD format file.
QString source() const
Returns the source for the layer.
void setLegendUrl(const QString &legendUrl)
Sets the URL for the layer's legend.
Definition: qgsmaplayer.h:1284
virtual bool setDependencies(const QSet< QgsMapLayerDependency > &layers)
Sets the list of dependencies.
void request3DUpdate()
Signal emitted when a layer requires an update in any 3D maps.
Q_INVOKABLE QVariant customProperty(const QString &value, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.
QgsError mError
Error.
Definition: qgsmaplayer.h:1997
int mBlockStyleChangedSignal
If non-zero, the styleChanged signal should not be emitted.
Definition: qgsmaplayer.h:2039
QString providerType() const
Returns the provider type (provider key) for this layer.
void removeCustomProperty(const QString &key)
Remove a custom property from layer.
void setBlendMode(QPainter::CompositionMode blendMode)
Set the blending mode used for rendering a layer.
QgsMapLayerType type
Definition: qgsmaplayer.h:80
void configChanged()
Emitted whenever the configuration is changed.
void trigger3DUpdate()
Will advise any 3D maps that this layer requires to be updated in the scene.
void autoRefreshIntervalChanged(int interval)
Emitted when the auto refresh interval changes.
void setMinimumScale(double scale)
Sets the minimum map scale (i.e.
virtual QSet< QgsMapLayerDependency > dependencies() const
Gets the list of dependencies.
void setCustomProperties(const QgsObjectCustomProperties &properties)
Set custom properties for layer.
virtual QString encodedSource(const QString &source, const QgsReadWriteContext &context) const
Called by writeLayerXML(), used by derived classes to encode provider's specific data source to proje...
QgsMapLayer(QgsMapLayerType type=QgsMapLayerType::VectorLayer, const QString &name=QString(), const QString &source=QString())
Constructor for QgsMapLayer.
Definition: qgsmaplayer.cpp:81
QString publicSource() const
Gets a version of the internal layer definition that has sensitive bits removed (for example,...
QgsMapLayer::LayerFlags flags() const
Returns the flags for this layer.
virtual void setSubLayerVisibility(const QString &name, bool visible)
Set the visibility of the given sublayer name.
void isValidChanged()
Emitted when the validity of this layer changed.
QgsCoordinateReferenceSystem crs
Definition: qgsmaplayer.h:79
bool loadNamedMetadataFromDatabase(const QString &db, const QString &uri, QString &qmd)
Retrieve a named metadata for this layer from a sqlite database.
virtual bool readXml(const QDomNode &layer_node, QgsReadWriteContext &context)
Called by readLayerXML(), used by children to read state specific to them from project files.
QgsMapLayerServerProperties * serverProperties()
Returns QGIS Server Properties for the map layer.
Definition: qgsmaplayer.h:427
QString attribution() const
Returns the attribution of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:401
void setOriginalXmlProperties(const QString &originalXmlProperties)
Sets the original XML properties for the layer to originalXmlProperties.
void writeCustomProperties(QDomNode &layerNode, QDomDocument &doc) const
Write custom properties to project file.
QString mRefreshOnNofifyMessage
Definition: qgsmaplayer.h:2010
QString mLegendUrl
WMS legend.
Definition: qgsmaplayer.h:1993
QString id() const
Returns the layer's unique ID, which is used to access this layer from QgsProject.
virtual QString loadDefaultStyle(bool &resultFlag)
Retrieve the default style for this layer if one exists (either as a .qml file on disk or as a record...
QString mLayerName
Name of the layer - used for display.
Definition: qgsmaplayer.h:1975
virtual QString loadNamedMetadata(const QString &uri, bool &resultFlag)
Retrieve a named metadata for this layer if one exists (either as a .qmd file on disk or as a record ...
virtual bool writeXml(QDomNode &layer_node, QDomDocument &document, const QgsReadWriteContext &context) const
Called by writeLayerXML(), used by children to write state specific to them to project files.
bool hasAutoRefreshEnabled() const
Returns true if auto refresh is enabled for the layer.
void mapTipTemplateChanged()
Emitted when the map tip template changes.
void triggerRepaint(bool deferredUpdate=false)
Will advise the map canvas (and any other interested party) that this layer requires to be repainted.
QString crsHtmlMetadata() const
Returns a HTML fragment containing the layer's CRS metadata, for use in the htmlMetadata() method.
void setAttributionUrl(const QString &attribUrl)
Sets the attribution URL of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:410
void setAutoRefreshEnabled(bool enabled)
Sets whether auto refresh is enabled for the layer.
void setMaximumScale(double scale)
Sets the maximum map scale (i.e.
QgsLayerMetadata metadata
Definition: qgsmaplayer.h:78
static QString formatLayerName(const QString &name)
A convenience function to capitalize and format a layer name.
void renderer3DChanged()
Signal emitted when 3D renderer associated with the layer has changed.
QString abstract() const
Returns the abstract of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:327
QString originalXmlProperties() const
Returns the XML properties of the original layer as they were when the layer was first read from the ...
QString dataUrlFormat() const
Returns the DataUrl format of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:381
QPainter::CompositionMode blendMode() const
Returns the current blending mode for a layer.
QString mTitle
Definition: qgsmaplayer.h:1978
void setDataUrl(const QString &dataUrl)
Sets the DataUrl of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:354
virtual void setOpacity(double opacity)
Sets the opacity for the layer, where opacity is a value between 0 (totally transparent) and 1....
void setKeywordList(const QString &keywords)
Sets the keyword list of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:335
void setAttribution(const QString &attrib)
Sets the attribution of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:392
void setFlags(QgsMapLayer::LayerFlags flags)
Returns the flags for this layer.
bool isRefreshOnNotifyEnabled() const
Returns true if the refresh on provider nofification is enabled.
Definition: qgsmaplayer.h:1461
QString shortName() const
Returns the short name of the layer used by QGIS Server to identify the layer.
QSet< QgsMapLayerDependency > mDependencies
List of layers that may modify this layer on modification.
Definition: qgsmaplayer.h:2000
void readCustomProperties(const QDomNode &layerNode, const QString &keyStartsWith=QString())
Read custom properties from project file.
virtual Qgis::MapLayerProperties properties() const
Returns the map layer properties of this layer.
virtual QString loadSldStyle(const QString &uri, bool &resultFlag)
Attempts to style the layer using the formatting from an SLD type file.
virtual void setMetadata(const QgsLayerMetadata &metadata)
Sets the layer's metadata store.
virtual bool readStyle(const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories)
Read the style for the current layer from the DOM node supplied.
virtual QString saveDefaultMetadata(bool &resultFlag)
Save the current metadata of this layer as the default metadata (either as a .qmd file on disk or as ...
virtual bool supportsEditing() const
Returns whether the layer supports editing or not.
void setDataUrlFormat(const QString &dataUrlFormat)
Sets the DataUrl format of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:372
QString mLegendUrlFormat
Definition: qgsmaplayer.h:1994
Q_INVOKABLE void setCustomProperty(const QString &key, const QVariant &value)
Set a custom property for layer.
QString mProviderKey
Data provider key (name of the data provider)
Definition: qgsmaplayer.h:2013
QgsCoordinateTransformContext transformContext() const
Returns the layer data provider coordinate transform context or a default transform context if the la...
void styleChanged()
Signal emitted whenever a change affects the layer's style.
virtual bool isEditable() const
Returns true if the layer can be edited.
QUndoStack * undoStack()
Returns pointer to layer's undo stack.
QString title() const
Returns the title of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:311
void crsChanged()
Emit a signal that layer's CRS has been reset.
virtual QgsError error() const
Gets current status error.
bool writeLayerXml(QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context) const
Stores state in DOM node.
virtual QString styleURI() const
Retrieve the style URI for this layer (either as a .qml file on disk or as a record in the users styl...
QString mAttributionUrl
Definition: qgsmaplayer.h:1990
void setScaleBasedVisibility(bool enabled)
Sets whether scale based visibility is enabled for the layer.
void dataSourceChanged()
Emitted whenever the layer's data source has been changed.
QString dataUrl() const
Returns the DataUrl of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:363
bool readLayerXml(const QDomElement &layerElement, QgsReadWriteContext &context, QgsMapLayer::ReadFlags flags=QgsMapLayer::ReadFlags())
Sets state from DOM document.
bool hasScaleBasedVisibility() const
Returns whether scale based visibility is enabled for the layer.
virtual QString loadNamedStyle(const QString &uri, bool &resultFlag, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories)
Retrieve a named style for this layer if one exists (either as a .qml file on disk or as a record in ...
Q_DECL_DEPRECATED QString metadataUrlFormat() const
Returns the metadata format of the layer used by QGIS Server in GetCapabilities request.
void setRefreshOnNofifyMessage(const QString &message)
Set the notification message that triggers repaint If refresh on notification is enabled,...
Definition: qgsmaplayer.h:1629
static QString generateId(const QString &layerName)
Generates an unique identifier for this layer, the generate ID is prefixed by layerName.
void opacityChanged(double opacity)
Emitted when the layer's opacity is changed, where opacity is a value between 0 (transparent) and 1 (...
virtual bool isModified() const
Returns true if the layer has been modified since last commit/save.
void emitStyleChanged()
Triggers an emission of the styleChanged() signal.
virtual QgsMapLayerTemporalProperties * temporalProperties()
Returns the layer's temporal properties.
Definition: qgsmaplayer.h:1504
QString mShortName
Definition: qgsmaplayer.h:1977
QUndoStack * undoStackStyles()
Returns pointer to layer's style undo stack.
void dataChanged()
Data of layer changed.
virtual QStringList subLayers() const
Returns the sublayers of this layer.
virtual QString htmlMetadata() const
Obtain a formatted HTML string containing assorted metadata for this layer.
Q_DECL_DEPRECATED void setMetadataUrlFormat(const QString &metaUrlFormat)
Sets the metadata format of the layer used by QGIS Server in GetCapabilities request.
virtual bool loadNamedStyleFromDatabase(const QString &db, const QString &uri, QString &qml)
Retrieve a named style for this layer from a sqlite database.
static QString extensionPropertyType(PropertyType type)
Returns the extension of a Property.
Definition: qgsmaplayer.cpp:68
virtual QgsMapLayer * clone() const =0
Returns a new instance equivalent to this one except for the id which is still unique.
void blendModeChanged(QPainter::CompositionMode blendMode)
Signal emitted when the blend mode is changed, through QgsMapLayer::setBlendMode()
void setName(const QString &name)
Set the display name of the layer.
void setAutoRefreshInterval(int interval)
Sets the auto refresh interval (in milliseconds) for the layer.
virtual bool readSymbology(const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories)=0
Read the symbology for the current layer from the DOM node supplied.
Q_DECL_DEPRECATED QString metadataUrl() const
Returns the metadata URL of the layer used by QGIS Server in GetCapabilities request.
virtual void setExtent(const QgsRectangle &rect)
Sets the extent.
virtual void resolveReferences(QgsProject *project)
Resolve references to other layers (kept as layer IDs after reading XML) into layer objects.
QString saveNamedMetadata(const QString &uri, bool &resultFlag)
Save the current metadata of this layer as a named metadata (either as a .qmd file on disk or as a re...
bool isValid
Definition: qgsmaplayer.h:81
QString mDataSource
Data source description string, varies by layer type.
Definition: qgsmaplayer.h:1972
QString refreshOnNotifyMessage() const
Returns the message that should be notified by the provider to triggerRepaint.
Definition: qgsmaplayer.h:1454
virtual bool readSld(const QDomNode &node, QString &errorMessage)
Definition: qgsmaplayer.h:1162
virtual QString loadDefaultMetadata(bool &resultFlag)
Retrieve the default metadata for this layer if one exists (either as a .qmd file on disk or as a rec...
@ FlagReadExtentFromXml
Read extent from xml and skip get extent from provider.
Definition: qgsmaplayer.h:643
@ FlagTrustLayerMetadata
Trust layer metadata. Improves layer load time by skipping expensive checks like primary key unicity,...
Definition: qgsmaplayer.h:642
void setValid(bool valid)
Sets whether layer is valid or not.
QString attributionUrl() const
Returns the attribution URL of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:419
void readCommonStyle(const QDomElement &layerElement, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories)
Read style data common to all layer types.
QString mAbstract
Description of the layer.
Definition: qgsmaplayer.h:1981
void customPropertyChanged(const QString &key)
Emitted when a custom property of the layer has been changed or removed.
QgsMapLayer::ReadFlags mReadFlags
Read flags. It's up to the subclass to respect these when restoring state from XML.
Definition: qgsmaplayer.h:2018
void setDataSource(const QString &dataSource, const QString &baseName, const QString &provider, bool loadDefaultStyleFlag=false)
Updates the data source of the layer.
double minimumScale() const
Returns the minimum map scale (i.e.
QgsMapLayerStyleManager * styleManager() const
Gets access to the layer's style manager.
QString legendUrl() const
Returns the URL for the layer's legend.
Definition: qgsmaplayer.h:1289
QString mDataUrlFormat
Definition: qgsmaplayer.h:1986
void flagsChanged()
Emitted when layer's flags have been modified.
void repaintRequested(bool deferredUpdate=false)
By emitting this signal the layer tells that either appearance or content have been changed and any v...
void setLegendUrlFormat(const QString &legendUrlFormat)
Sets the format for a URL based layer legend.
Definition: qgsmaplayer.h:1294
void exportNamedMetadata(QDomDocument &doc, QString &errorMsg) const
Export the current metadata of this layer as named metadata in a QDomDocument.
virtual QString saveNamedStyle(const QString &uri, bool &resultFlag, StyleCategories categories=AllStyleCategories)
Save the properties of this layer as a named style (either as a .qml file on disk or as a record in t...
virtual void exportSldStyle(QDomDocument &doc, QString &errorMsg) const
Export the properties of this layer as SLD style in a QDomDocument.
void beforeResolveReferences(QgsProject *project)
Emitted when all layers are loaded and references can be resolved, just before the references of this...
void setMapTipTemplate(const QString &mapTipTemplate)
The mapTip is a pretty, html representation for feature information.
Q_DECL_DEPRECATED void setMetadataUrl(const QString &metaUrl)
Sets the metadata URL of the layer used by QGIS Server in GetCapabilities request.
virtual QgsMapLayerElevationProperties * elevationProperties()
Returns the layer's elevation properties.
Definition: qgsmaplayer.h:1511
Q_INVOKABLE QStringList customPropertyKeys() const
Returns list of all keys within custom properties.
QgsProject * project() const
Returns the parent project if this map layer is added to a project.
Q_DECL_DEPRECATED void setMetadataUrlType(const QString &metaUrlType)
Set the metadata type of the layer used by QGIS Server in GetCapabilities request MetadataUrlType ind...
void setLegend(QgsMapLayerLegend *legend)
Assign a legend controller to the map layer.
double opacity
Definition: qgsmaplayer.h:82
virtual QString decodedSource(const QString &source, const QString &dataProvider, const QgsReadWriteContext &context) const
Called by readLayerXML(), used by derived classes to decode provider's specific data source from proj...
void nameChanged()
Emitted when the name has been changed.
virtual QString metadataUri() const
Retrieve the metadata URI for this layer (either as a .qmd file on disk or as a record in the users s...
int autoRefreshInterval
Definition: qgsmaplayer.h:77
virtual bool writeStyle(QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories) const
Write just the symbology information for the layer into the document.
bool mIsRefreshOnNofifyEnabled
Definition: qgsmaplayer.h:2009
QString mDataUrl
DataUrl of the layer.
Definition: qgsmaplayer.h:1985
virtual Q_INVOKABLE QgsDataProvider * dataProvider()
Returns the layer's data provider, it may be nullptr.
double mLayerOpacity
Layer opacity.
Definition: qgsmaplayer.h:2032
bool mValid
Indicates if the layer is valid and can be drawn.
Definition: qgsmaplayer.h:1969
@ AllStyleCategories
Definition: qgsmaplayer.h:179
@ LayerConfiguration
General configuration: identifiable, removable, searchable, display expression, read-only.
Definition: qgsmaplayer.h:161
@ Symbology
Symbology.
Definition: qgsmaplayer.h:162
@ Notes
Layer user notes (since QGIS 3.20)
Definition: qgsmaplayer.h:178
@ Temporal
Temporal properties (since QGIS 3.14)
Definition: qgsmaplayer.h:175
@ Rendering
Rendering: scale visibility, simplify method, opacity.
Definition: qgsmaplayer.h:171
@ Elevation
Elevation settings (since QGIS 3.18)
Definition: qgsmaplayer.h:177
@ Symbology3D
3D symbology
Definition: qgsmaplayer.h:163
@ CustomProperties
Custom properties (by plugins for instance)
Definition: qgsmaplayer.h:172
virtual QDateTime timestamp() const
Time stamp of data source in the moment when data/metadata were loaded by provider.
void setProviderType(const QString &providerType)
Sets the providerType (provider key)
virtual QString saveDefaultStyle(bool &resultFlag, StyleCategories categories)
Save the properties of this layer as the default style (either as a .qml file on disk or as a record ...
void setRenderer3D(QgsAbstract3DRenderer *renderer)
Sets 3D renderer for the layer.
QString mAttribution
Attribution of the layer.
Definition: qgsmaplayer.h:1989
~QgsMapLayer() override
Definition: qgsmaplayer.cpp:99
const QgsObjectCustomProperties & customProperties() const
Read all custom properties from layer.
QString generalHtmlMetadata() const
Returns an HTML fragment containing general metadata information, for use in the htmlMetadata() metho...
Q_DECL_DEPRECATED QString metadataUrlType() const
Returns the metadata type of the layer used by QGIS Server in GetCapabilities request.
void writeCommonStyle(QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories) const
Write style data common to all layer types.
double maximumScale() const
Returns the maximum map scale (i.e.
QString keywordList() const
Returns the keyword list of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:343
virtual void setLayerOrder(const QStringList &layers)
Reorders the previously selected sublayers of this layer from bottom to top.
void invalidateWgs84Extent()
Invalidates the WGS84 extent.
QString mapTipTemplate
Definition: qgsmaplayer.h:83
void setTitle(const QString &title)
Sets the title of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:303
PropertyType
Maplayer has a style and a metadata property.
Definition: qgsmaplayer.h:134
bool mShouldValidateCrs
true if the layer's CRS should be validated and invalid CRSes are not permitted.
Definition: qgsmaplayer.h:2025
void setCrs(const QgsCoordinateReferenceSystem &srs, bool emitSignal=true)
Sets layer's spatial reference system.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
Custom exception class which is raised when an operation is not supported.
Definition: qgsexception.h:118
Simple key-value store (keys = strings, values = variants) that supports loading/saving to/from XML i...
void setValue(const QString &key, const QVariant &value)
Add an entry to the store with the specified key.
QStringList keys() const
Returns a list of all stored keys.
void writeXml(QDomNode &parentNode, QDomDocument &doc) const
Writes the store contents to an XML node.
void remove(const QString &key)
Removes a key (entry) from the store.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
Returns the value for the given key.
void readXml(const QDomNode &parentNode, const QString &keyStartsWith=QString())
Read store contents from an XML node.
bool contains(const QString &key) const
Returns true if the properties contains a key with the specified name.
QString writePath(const QString &filename) const
Prepare a filename to save it to the project file.
QString readPath(const QString &filename) const
Turn filename read from the project file to an absolute path.
Contains information about a PROJ operation.
QString description() const
Description.
Class to convert from older project file versions to newer.
bool updateRevision(const QgsProjectVersion &version)
virtual QString translate(const QString &context, const QString &sourceText, const char *disambiguation=nullptr, int n=-1) const =0
The derived translate() translates with QTranslator and qm file the sourceText.
A class to describe the version of a project.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:105
bool removeAttachedFile(const QString &path)
Removes the attached file.
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:476
QString baseName() const
Returns the base name of the project file without the path and without extension - derived from fileN...
Definition: qgsproject.cpp:830
QString absoluteFilePath() const
Returns full absolute path to the project file if the project is stored in a file system - derived fr...
Definition: qgsproject.cpp:819
Holds data provider key, description, and associated shared library file or function pointer informat...
@ SaveLayerMetadata
Indicates that the provider supports saving native layer metadata (since QGIS 3.20)
QVariantMap decodeUri(const QString &providerKey, const QString &uri)
Breaks a provider data source URI into its component paths (e.g.
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
bool saveLayerMetadata(const QString &providerKey, const QString &uri, const QgsLayerMetadata &metadata, QString &errorMessage) SIP_THROW(QgsNotSupportedException)
Saves metadata to the layer corresponding to the specified uri.
Represents a raster layer.
bool writeSld(QDomNode &node, QDomDocument &doc, QString &errorMessage, const QVariantMap &props=QVariantMap()) const
Writes the symbology of the layer into the document provided in SLD 1.0.0 format.
Allows entering a context category and takes care of leaving this category on deletion of the class.
The class is used as a container of context for various read/write operations on other objects.
MAYBE_UNUSED NODISCARD QgsReadWriteContextCategoryPopper enterCategory(const QString &category, const QString &details=QString()) const
Push a category to the stack.
const QgsProjectTranslator * projectTranslator() const
Returns the project translator.
const QgsPathResolver & pathResolver() const
Returns path resolver for conversion between relative and absolute paths.
A rectangle specified with double values.
Definition: qgsrectangle.h:42
bool isNull() const
Test if the rectangle is null (all coordinates zero or after call to setMinimal()).
Definition: qgsrectangle.h:479
void setMetadataUrls(const QList< QgsServerMetadataUrlProperties::MetadataUrl > &metaUrls)
Sets a the list of metadata URL for the layer.
QList< QgsServerMetadataUrlProperties::MetadataUrl > metadataUrls() const
Returns a list of metadataUrl resources associated for the layer.
static QString capitalize(const QString &string, Qgis::Capitalization capitalization)
Converts a string by applying capitalization rules to the string.
An interface for classes which can visit style entity (e.g.
static Q_INVOKABLE QString toString(QgsUnitTypes::DistanceUnit unit)
Returns a translated string representing a distance unit.
Represents a vector layer which manages a vector based data sets.
Q_INVOKABLE QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
bool writeSld(QDomNode &node, QDomDocument &doc, QString &errorMessage, const QVariantMap &props=QVariantMap()) const
Writes the symbology of the layer into the document provided in SLD 1.1 format.
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
Definition: qgswkbtypes.h:141
static T readFlagAttribute(const QDomElement &element, const QString &attributeName, T defaultValue)
Read a flag value from an attribute of the element.
Definition: qgsxmlutils.h:99
static QDomElement writeRectangle(const QgsRectangle &rect, QDomDocument &doc, const QString &elementName=QStringLiteral("extent"))
Encodes a rectangle to a DOM element.
Definition: qgsxmlutils.cpp:81
static QgsRectangle readRectangle(const QDomElement &element)
Definition: qgsxmlutils.cpp:39
Unique pointer for sqlite3 databases, which automatically closes the database when the pointer goes o...
sqlite3_statement_unique_ptr prepare(const QString &sql, int &resultCode) const
Prepares a sql statement, returning the result.
int open(const QString &path)
Opens the database at the specified file path.
int open_v2(const QString &path, int flags, const char *zVfs)
Opens the database at the specified file path.
Unique pointer for sqlite3 prepared statements, which automatically finalizes the statement when the ...
QgsMapLayerType
Types of layers that can be added to a map.
Definition: qgis.h:47
@ VectorLayer
Vector layer.
@ AnnotationLayer
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Definition: qgis.h:2915
CONSTLATIN1STRING geoEpsgCrsAuthId()
Geographic coord sys from EPSG authority.
Definition: qgis.h:3411
void(* CUSTOM_CRS_VALIDATION)(QgsCoordinateReferenceSystem &)
#define QgsDebugMsgLevel(str, level)
Definition: qgslogger.h:39
Setting options for creating vector data providers.
QString format
Format specification of online resource.