QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
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"
25#include "qgsdatasourceuri.h"
26#include "qgsfileutils.h"
27#include "qgslogger.h"
28#include "qgsauthmanager.h"
29#include "qgsmaplayer.h"
30#include "moc_qgsmaplayer.cpp"
31#include "qgsmaplayerlegend.h"
33#include "qgspathresolver.h"
35#include "qgsproject.h"
36#include "qgsproviderregistry.h"
37#include "qgsprovidermetadata.h"
38#include "qgsrasterlayer.h"
39#include "qgsreadwritecontext.h"
40#include "qgsrectangle.h"
41#include "qgsscaleutils.h"
42#include "qgssldexportcontext.h"
43#include "qgsvectorlayer.h"
44#include "qgsxmlutils.h"
45#include "qgsstringutils.h"
46#include "qgsmessagelog.h"
49#include "qgslayernotesutils.h"
50#include "qgsdatums.h"
51#include "qgsprojoperation.h"
52#include "qgsthreadingutils.h"
53#include "qgsunittypes.h"
54
55#include <QDir>
56#include <QDomDocument>
57#include <QDomElement>
58#include <QDomImplementation>
59#include <QDomNode>
60#include <QFile>
61#include <QFileInfo>
62#include <QLocale>
63#include <QTextStream>
64#include <QUrl>
65#include <QTimer>
66#include <QStandardPaths>
67#include <QUuid>
68#include <QRegularExpression>
69
70#include <sqlite3.h>
71
73{
74 switch ( type )
75 {
76 case Metadata:
77 return QStringLiteral( ".qmd" );
78
79 case Style:
80 return QStringLiteral( ".qml" );
81 }
82 return QString();
83}
84
86 const QString &lyrname,
87 const QString &source )
88 : mDataSource( source )
89 , mLayerName( lyrname )
90 , mLayerType( type )
91 , mServerProperties( std::make_unique<QgsMapLayerServerProperties>( this ) )
92 , mUndoStack( new QUndoStack( this ) )
93 , mUndoStackStyles( new QUndoStack( this ) )
94 , mStyleManager( new QgsMapLayerStyleManager( this ) )
95 , mRefreshTimer( new QTimer( this ) )
96{
97 mID = generateId( lyrname );
100 connect( mRefreshTimer, &QTimer::timeout, this, [this]
101 {
102
103 switch ( mAutoRefreshMode )
104 {
106 break;
108 triggerRepaint( true );
109 break;
111 reload();
112 break;
113 }
114 } );
115}
116
118{
119 if ( project() && project()->pathResolver().writePath( mDataSource ).startsWith( "attachment:" ) )
120 {
122 }
123
124 delete m3DRenderer;
125 delete mLegend;
126 delete mStyleManager;
127}
128
129void QgsMapLayer::clone( QgsMapLayer *layer ) const
130{
132
133 QgsDebugMsgLevel( QStringLiteral( "Cloning layer '%1'" ).arg( name() ), 3 );
134 layer->setBlendMode( blendMode() );
135
136 const auto constStyles = styleManager()->styles();
137 for ( const QString &s : constStyles )
138 {
139 layer->styleManager()->addStyle( s, styleManager()->style( s ) );
140 }
141
142 layer->setName( name() );
143
144 if ( layer->dataProvider() && layer->dataProvider()->elevationProperties() )
145 {
147 layer->mExtent3D = mExtent3D;
148 else
149 layer->mExtent2D = mExtent2D;
150 }
151
152 layer->setMaximumScale( maximumScale() );
153 layer->setMinimumScale( minimumScale() );
155 layer->setLegendUrl( legendUrl() );
157 layer->setDependencies( dependencies() );
159 layer->setCrs( crs() );
160 layer->setCustomProperties( mCustomProperties );
161 layer->setOpacity( mLayerOpacity );
162 layer->setMetadata( mMetadata );
163 layer->serverProperties()->copyTo( mServerProperties.get() );
164}
165
167{
168 // because QgsVirtualLayerProvider is not anywhere NEAR thread safe:
170
171 return mLayerType;
172}
173
180
182{
184
185 if ( flags == mFlags )
186 return;
187
188 mFlags = flags;
189 emit flagsChanged();
190}
191
198
199QString QgsMapLayer::id() const
200{
201 // because QgsVirtualLayerProvider is not anywhere NEAR thread safe:
203
204 return mID;
205}
206
207bool QgsMapLayer::setId( const QString &id )
208{
210 if ( qobject_cast< QgsMapLayerStore * >( parent() ) )
211 {
212 // layer is already registered, cannot change id
213 return false;
214 }
215
216 if ( id == mID )
217 return false;
218
219 mID = id;
220 emit idChanged( id );
221 return true;
222}
223
224void QgsMapLayer::setName( const QString &name )
225{
227
228 if ( name == mLayerName )
229 return;
230
232
233 emit nameChanged();
234}
235
236QString QgsMapLayer::name() const
237{
238 // because QgsVirtualLayerProvider is not anywhere NEAR thread safe:
240
241 QgsDebugMsgLevel( "returning name '" + mLayerName + '\'', 4 );
242 return mLayerName;
243}
244
251
253{
255
256 return nullptr;
257}
258
263
264void QgsMapLayer::setShortName( const QString &shortName )
265{
267
268 mServerProperties->setShortName( shortName );
269}
270
272{
274
275 return mServerProperties->shortName();
276}
277
278void QgsMapLayer::setTitle( const QString &title )
279{
281
282 mServerProperties->setTitle( title );
283}
284
285QString QgsMapLayer::title() const
286{
288
289 return mServerProperties->title();
290}
291
292void QgsMapLayer::setAbstract( const QString &abstract )
293{
295
296 mServerProperties->setAbstract( abstract );
297}
298
300{
302
303 return mServerProperties->abstract();
304}
305
306void QgsMapLayer::setKeywordList( const QString &keywords )
307{
309
310 mServerProperties->setKeywordList( keywords );
311}
312
314{
316
317 return mServerProperties->keywordList();
318}
319
320void QgsMapLayer::setDataUrl( const QString &dataUrl )
321{
323
324 mServerProperties->setDataUrl( dataUrl );
325}
326
327QString QgsMapLayer::dataUrl() const
328{
330
331 return mServerProperties->dataUrl();
332}
333
334void QgsMapLayer::setDataUrlFormat( const QString &dataUrlFormat )
335{
337
338 mServerProperties->setDataUrlFormat( dataUrlFormat );
339}
340
342{
344
345 return mServerProperties->dataUrlFormat();
346}
347
348void QgsMapLayer::setAttribution( const QString &attrib )
349{
351
352 mServerProperties->setAttribution( attrib );
353}
354
356{
358
359 return mServerProperties->attribution();
360}
361
362void QgsMapLayer::setAttributionUrl( const QString &attribUrl )
363{
365
366 mServerProperties->setAttributionUrl( attribUrl );
367}
368
370{
372
373 return mServerProperties->attributionUrl();
374
375}
376
377void QgsMapLayer::setMetadataUrl( const QString &metaUrl )
378{
380
381 QList<QgsMapLayerServerProperties::MetadataUrl> urls = serverProperties()->metadataUrls();
382 if ( urls.isEmpty() )
383 {
384 const QgsMapLayerServerProperties::MetadataUrl newItem = QgsMapLayerServerProperties::MetadataUrl( metaUrl, QLatin1String(), QLatin1String() );
385 urls.prepend( newItem );
386 }
387 else
388 {
389 const QgsMapLayerServerProperties::MetadataUrl old = urls.takeFirst();
390 const QgsMapLayerServerProperties::MetadataUrl newItem( metaUrl, old.type, old.format );
391 urls.prepend( newItem );
392 }
394}
395
397{
399
400 if ( mServerProperties->metadataUrls().isEmpty() )
401 {
402 return QLatin1String();
403 }
404 else
405 {
406 return mServerProperties->metadataUrls().first().url;
407 }
408}
409
410void QgsMapLayer::setMetadataUrlType( const QString &metaUrlType )
411{
413
414 QList<QgsMapLayerServerProperties::MetadataUrl> urls = mServerProperties->metadataUrls();
415 if ( urls.isEmpty() )
416 {
417 const QgsMapLayerServerProperties::MetadataUrl newItem( QLatin1String(), metaUrlType, QLatin1String() );
418 urls.prepend( newItem );
419 }
420 else
421 {
422 const QgsMapLayerServerProperties::MetadataUrl old = urls.takeFirst();
423 const QgsMapLayerServerProperties::MetadataUrl newItem( old.url, metaUrlType, old.format );
424 urls.prepend( newItem );
425 }
426 mServerProperties->setMetadataUrls( urls );
427}
428
430{
432
433 if ( mServerProperties->metadataUrls().isEmpty() )
434 {
435 return QLatin1String();
436 }
437 else
438 {
439 return mServerProperties->metadataUrls().first().type;
440 }
441}
442
443void QgsMapLayer::setMetadataUrlFormat( const QString &metaUrlFormat )
444{
446
447 QList<QgsMapLayerServerProperties::MetadataUrl> urls = mServerProperties->metadataUrls();
448 if ( urls.isEmpty() )
449 {
450 const QgsMapLayerServerProperties::MetadataUrl newItem( QLatin1String(), QLatin1String(), metaUrlFormat );
451 urls.prepend( newItem );
452 }
453 else
454 {
455 const QgsMapLayerServerProperties::MetadataUrl old = urls.takeFirst( );
456 const QgsMapLayerServerProperties::MetadataUrl newItem( old.url, old.type, metaUrlFormat );
457 urls.prepend( newItem );
458 }
459 mServerProperties->setMetadataUrls( urls );
460}
461
463{
465
466 if ( mServerProperties->metadataUrls().isEmpty() )
467 {
468 return QString();
469 }
470 else
471 {
472 return mServerProperties->metadataUrls().first().format;
473 }
474}
475
476QString QgsMapLayer::publicSource( bool hidePassword ) const
477{
479
480 // Redo this every time we're asked for it, as we don't know if
481 // dataSource has changed.
482 QString safeName = QgsDataSourceUri::removePassword( mDataSource, hidePassword );
483 return safeName;
484}
485
486QString QgsMapLayer::source() const
487{
489
490 return mDataSource;
491}
492
494{
496
497 return mExtent2D.isNull() ? mExtent3D.toRectangle() : mExtent2D;
498}
499
501{
503
504 return mExtent3D;
505}
506
507void QgsMapLayer::setBlendMode( const QPainter::CompositionMode blendMode )
508{
510
511 if ( mBlendMode == blendMode )
512 return;
513
514 mBlendMode = blendMode;
517}
518
519QPainter::CompositionMode QgsMapLayer::blendMode() const
520{
521 // non fatal for now -- the "rasterize" processing algorithm is not thread safe and calls this
523
524 return mBlendMode;
525}
526
527void QgsMapLayer::setOpacity( double opacity )
528{
530
532 return;
534 emit opacityChanged( opacity );
536}
537
539{
540 // non fatal for now -- the "rasterize" processing algorithm is not thread safe and calls this
542
543 return mLayerOpacity;
544}
545
546bool QgsMapLayer::readLayerXml( const QDomElement &layerElement, QgsReadWriteContext &context, QgsMapLayer::ReadFlags flags, QgsDataProvider *preloadedProvider )
547{
549
550 mPreloadedProvider.reset( preloadedProvider );
551
552 bool layerError;
554
555 QDomNode mnl;
556 QDomElement mne;
557
558 // read provider
559 QString provider;
560 mnl = layerElement.namedItem( QStringLiteral( "provider" ) );
561 mne = mnl.toElement();
562 provider = mne.text();
563
564 // set data source
565 mnl = layerElement.namedItem( QStringLiteral( "datasource" ) );
566 mne = mnl.toElement();
567 const QString dataSourceRaw = mne.text();
568 mDataSource = provider.isEmpty() ? dataSourceRaw : QgsProviderRegistry::instance()->relativeToAbsoluteUri( provider, dataSourceRaw, context );
569
570 // if the layer needs authentication, ensure the master password is set
571 const thread_local QRegularExpression rx( "authcfg=([a-z]|[A-Z]|[0-9]){7}" );
572 if ( rx.match( mDataSource ).hasMatch()
574 {
575 return false;
576 }
577
578 mDataSource = decodedSource( mDataSource, provider, context );
579
580 // Set the CRS from project file, asking the user if necessary.
581 // Make it the saved CRS to have WMS layer projected correctly.
582 // We will still overwrite whatever GDAL etc picks up anyway
583 // further down this function.
584 mnl = layerElement.namedItem( QStringLiteral( "layername" ) );
585 mne = mnl.toElement();
586
588 CUSTOM_CRS_VALIDATION savedValidation;
589
590 const QDomNode srsNode = layerElement.namedItem( QStringLiteral( "srs" ) );
591 mCRS.readXml( srsNode );
592 mCRS.setValidationHint( tr( "Specify CRS for layer %1" ).arg( mne.text() ) );
594 mCRS.validate();
595 savedCRS = mCRS;
596
597 // Do not validate any projections in children, they will be overwritten anyway.
598 // No need to ask the user for a projections when it is overwritten, is there?
601
602 const QgsReadWriteContextCategoryPopper p = context.enterCategory( tr( "Layer" ), mne.text() );
603
604 // the internal name is just the data source basename
605 //QFileInfo dataSourceFileInfo( mDataSource );
606 //internalName = dataSourceFileInfo.baseName();
607
608 // set ID
609 mnl = layerElement.namedItem( QStringLiteral( "id" ) );
610 if ( ! mnl.isNull() )
611 {
612 mne = mnl.toElement();
613 if ( ! mne.isNull() && mne.text().length() > 10 ) // should be at least 17 (yyyyMMddhhmmsszzz)
614 {
615 const QString newId = mne.text();
616 if ( newId != mID )
617 {
618 mID = mne.text();
619 emit idChanged( mID );
620 }
621 }
622 }
623
624 // set name
625 mnl = layerElement.namedItem( QStringLiteral( "layername" ) );
626 mne = mnl.toElement();
627
628 //name can be translated
629 setName( context.projectTranslator()->translate( QStringLiteral( "project:layers:%1" ).arg( layerElement.namedItem( QStringLiteral( "id" ) ).toElement().text() ), mne.text() ) );
630
631 // now let the children grab what they need from the Dom node.
632 layerError = !readXml( layerElement, context );
633
634 const QgsCoordinateReferenceSystem oldVerticalCrs = verticalCrs();
635 const QgsCoordinateReferenceSystem oldCrs3D = mCrs3D;
636
637 // overwrite CRS with what we read from project file before the raster/vector
638 // file reading functions changed it. They will if projections is specified in the file.
639 // FIXME: is this necessary? Yes, it is (autumn 2019)
641 mCRS = savedCRS;
642
643 //vertical CRS
644 {
646 const QDomNode verticalCrsNode = layerElement.firstChildElement( QStringLiteral( "verticalCrs" ) );
647 if ( !verticalCrsNode.isNull() )
648 {
649 verticalCrs.readXml( verticalCrsNode );
650 }
651 mVerticalCrs = verticalCrs;
652 }
653 rebuildCrs3D();
654
655 //legendUrl
656 const QDomElement legendUrlElem = layerElement.firstChildElement( QStringLiteral( "legendUrl" ) );
657 if ( !legendUrlElem.isNull() )
658 {
659 mLegendUrl = legendUrlElem.text();
660 mLegendUrlFormat = legendUrlElem.attribute( QStringLiteral( "format" ), QString() );
661 }
662
663 serverProperties()->readXml( layerElement );
664
665 if ( serverProperties()->metadataUrls().isEmpty() )
666 {
667 // metadataUrl is still empty, maybe it's a QGIS Project < 3.22
668 // keep for legacy
669 const QDomElement metaUrlElem = layerElement.firstChildElement( QStringLiteral( "metadataUrl" ) );
670 if ( !metaUrlElem.isNull() )
671 {
672 const QString url = metaUrlElem.text();
673 const QString type = metaUrlElem.attribute( QStringLiteral( "type" ), QString() );
674 const QString format = metaUrlElem.attribute( QStringLiteral( "format" ), QString() );
675 const QgsMapLayerServerProperties::MetadataUrl newItem( url, type, format );
676 mServerProperties->setMetadataUrls( QList<QgsMapLayerServerProperties::MetadataUrl>() << newItem );
677 }
678 }
679
680 // mMetadata.readFromLayer( this );
681 const QDomElement metadataElem = layerElement.firstChildElement( QStringLiteral( "resourceMetadata" ) );
682 mMetadata.readMetadataXml( metadataElem );
683
684 setAutoRefreshInterval( layerElement.attribute( QStringLiteral( "autoRefreshTime" ), QStringLiteral( "0" ) ).toInt() );
685 if ( layerElement.hasAttribute( QStringLiteral( "autoRefreshMode" ) ) )
686 {
687 setAutoRefreshMode( qgsEnumKeyToValue( layerElement.attribute( QStringLiteral( "autoRefreshMode" ) ), Qgis::AutoRefreshMode::Disabled ) );
688 }
689 else
690 {
691 setAutoRefreshMode( layerElement.attribute( QStringLiteral( "autoRefreshEnabled" ), QStringLiteral( "0" ) ).toInt() ? Qgis::AutoRefreshMode::RedrawOnly : Qgis::AutoRefreshMode::Disabled );
692 }
693 setRefreshOnNofifyMessage( layerElement.attribute( QStringLiteral( "refreshOnNotifyMessage" ), QString() ) );
694 setRefreshOnNotifyEnabled( layerElement.attribute( QStringLiteral( "refreshOnNotifyEnabled" ), QStringLiteral( "0" ) ).toInt() );
695
696 // geographic extent is read only if necessary
698 {
699 const QDomNode wgs84ExtentNode = layerElement.namedItem( QStringLiteral( "wgs84extent" ) );
700 if ( !wgs84ExtentNode.isNull() )
701 mWgs84Extent = QgsXmlUtils::readRectangle( wgs84ExtentNode.toElement() );
702 }
703
704 mLegendPlaceholderImage = layerElement.attribute( QStringLiteral( "legendPlaceholderImage" ) );
705
706 if ( verticalCrs() != oldVerticalCrs )
707 emit verticalCrsChanged();
708 if ( mCrs3D != oldCrs3D )
709 emit crs3DChanged();
710
711 return ! layerError;
712} // bool QgsMapLayer::readLayerXML
713
714
715bool QgsMapLayer::readXml( const QDomNode &layer_node, QgsReadWriteContext &context )
716{
718
719 Q_UNUSED( layer_node )
720 Q_UNUSED( context )
721 // NOP by default; children will over-ride with behavior specific to them
722
723 // read Extent
725 {
726 const QDomNode extent3DNode = layer_node.namedItem( QStringLiteral( "extent3D" ) );
727 if ( extent3DNode.isNull() )
728 {
729 const QDomNode extentNode = layer_node.namedItem( QStringLiteral( "extent" ) );
730 if ( !extentNode.isNull() )
731 {
732 mExtent2D = QgsXmlUtils::readRectangle( extentNode.toElement() );
733 }
734 }
735 else
736 {
737 mExtent3D = QgsXmlUtils::readBox3D( extent3DNode.toElement() );
738 }
739 }
740
741 return true;
742} // void QgsMapLayer::readXml
743
744
745bool QgsMapLayer::writeLayerXml( QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context ) const
746{
748
749 if ( !mExtent3D.isNull() && dataProvider() && dataProvider()->elevationProperties() && dataProvider()->elevationProperties()->containsElevationData() )
750 layerElement.appendChild( QgsXmlUtils::writeBox3D( mExtent3D, document ) );
751 else if ( !mExtent2D.isNull() )
752 layerElement.appendChild( QgsXmlUtils::writeRectangle( mExtent2D, document ) );
753
754 if ( const QgsRectangle lWgs84Extent = wgs84Extent( true ); !lWgs84Extent.isNull() )
755 {
756 layerElement.appendChild( QgsXmlUtils::writeRectangle( lWgs84Extent, document, QStringLiteral( "wgs84extent" ) ) );
757 }
758
759 layerElement.setAttribute( QStringLiteral( "autoRefreshTime" ), QString::number( mRefreshTimer->interval() ) );
760 layerElement.setAttribute( QStringLiteral( "autoRefreshMode" ), qgsEnumValueToKey( mAutoRefreshMode ) );
761 layerElement.setAttribute( QStringLiteral( "refreshOnNotifyEnabled" ), mIsRefreshOnNofifyEnabled ? 1 : 0 );
762 layerElement.setAttribute( QStringLiteral( "refreshOnNotifyMessage" ), mRefreshOnNofifyMessage );
763
764 // ID
765 QDomElement layerId = document.createElement( QStringLiteral( "id" ) );
766 const QDomText layerIdText = document.createTextNode( id() );
767 layerId.appendChild( layerIdText );
768
769 layerElement.appendChild( layerId );
770
771 if ( mVerticalCrs.isValid() )
772 {
773 QDomElement verticalSrsNode = document.createElement( QStringLiteral( "verticalCrs" ) );
774 mVerticalCrs.writeXml( verticalSrsNode, document );
775 layerElement.appendChild( verticalSrsNode );
776 }
777
778 // data source
779 QDomElement dataSource = document.createElement( QStringLiteral( "datasource" ) );
780 const QgsDataProvider *provider = dataProvider();
781 const QString providerKey = provider ? provider->name() : QString();
782 const QString srcRaw = encodedSource( source(), context );
783 const QString src = providerKey.isEmpty() ? srcRaw : QgsProviderRegistry::instance()->absoluteToRelativeUri( providerKey, srcRaw, context );
784 const QDomText dataSourceText = document.createTextNode( src );
785 dataSource.appendChild( dataSourceText );
786 layerElement.appendChild( dataSource );
787
788 // layer name
789 QDomElement layerName = document.createElement( QStringLiteral( "layername" ) );
790 const QDomText layerNameText = document.createTextNode( name() );
791 layerName.appendChild( layerNameText );
792 layerElement.appendChild( layerName );
793
794 // layer short name
795
796 // TODO -- ideally this would be in QgsMapLayerServerProperties::writeXml, but that's currently
797 // only called for SOME map layer subclasses!
798 if ( !mServerProperties->shortName().isEmpty() )
799 {
800 QDomElement layerShortName = document.createElement( QStringLiteral( "shortname" ) );
801 const QDomText layerShortNameText = document.createTextNode( mServerProperties->shortName() );
802 layerShortName.appendChild( layerShortNameText );
803 layerElement.appendChild( layerShortName );
804 }
805
806 // layer title
807 if ( !mServerProperties->title().isEmpty() )
808 {
809 QDomElement layerTitle = document.createElement( QStringLiteral( "title" ) );
810 const QDomText layerTitleText = document.createTextNode( mServerProperties->title() );
811 layerTitle.appendChild( layerTitleText );
812
813 if ( mServerProperties->title() != mServerProperties->wfsTitle() )
814 {
815 layerTitle.setAttribute( "wfs", mServerProperties->wfsTitle() );
816 }
817
818 layerElement.appendChild( layerTitle );
819 }
820
821 // layer abstract
822 if ( !mServerProperties->abstract().isEmpty() )
823 {
824 QDomElement layerAbstract = document.createElement( QStringLiteral( "abstract" ) );
825 const QDomText layerAbstractText = document.createTextNode( mServerProperties->abstract() );
826 layerAbstract.appendChild( layerAbstractText );
827 layerElement.appendChild( layerAbstract );
828 }
829
830 // layer keyword list
831 const QStringList keywordStringList = mServerProperties->keywordList().split( ',' );
832 if ( !keywordStringList.isEmpty() )
833 {
834 QDomElement layerKeywordList = document.createElement( QStringLiteral( "keywordList" ) );
835 for ( int i = 0; i < keywordStringList.size(); ++i )
836 {
837 QDomElement layerKeywordValue = document.createElement( QStringLiteral( "value" ) );
838 const QDomText layerKeywordText = document.createTextNode( keywordStringList.at( i ).trimmed() );
839 layerKeywordValue.appendChild( layerKeywordText );
840 layerKeywordList.appendChild( layerKeywordValue );
841 }
842 layerElement.appendChild( layerKeywordList );
843 }
844
845 // layer dataUrl
846 const QString aDataUrl = mServerProperties->dataUrl();
847 if ( !aDataUrl.isEmpty() )
848 {
849 QDomElement layerDataUrl = document.createElement( QStringLiteral( "dataUrl" ) );
850 const QDomText layerDataUrlText = document.createTextNode( aDataUrl );
851 layerDataUrl.appendChild( layerDataUrlText );
852 layerDataUrl.setAttribute( QStringLiteral( "format" ), mServerProperties->dataUrlFormat() );
853 layerElement.appendChild( layerDataUrl );
854 }
855
856 // layer legendUrl
857 const QString aLegendUrl = legendUrl();
858 if ( !aLegendUrl.isEmpty() )
859 {
860 QDomElement layerLegendUrl = document.createElement( QStringLiteral( "legendUrl" ) );
861 const QDomText layerLegendUrlText = document.createTextNode( aLegendUrl );
862 layerLegendUrl.appendChild( layerLegendUrlText );
863 layerLegendUrl.setAttribute( QStringLiteral( "format" ), legendUrlFormat() );
864 layerElement.appendChild( layerLegendUrl );
865 }
866
867 // layer attribution
868 const QString aAttribution = mServerProperties->attribution();
869 if ( !aAttribution.isEmpty() )
870 {
871 QDomElement layerAttribution = document.createElement( QStringLiteral( "attribution" ) );
872 const QDomText layerAttributionText = document.createTextNode( aAttribution );
873 layerAttribution.appendChild( layerAttributionText );
874 layerAttribution.setAttribute( QStringLiteral( "href" ), mServerProperties->attributionUrl() );
875 layerElement.appendChild( layerAttribution );
876 }
877
878 // timestamp if supported
879 if ( timestamp() > QDateTime() )
880 {
881 QDomElement stamp = document.createElement( QStringLiteral( "timestamp" ) );
882 const QDomText stampText = document.createTextNode( timestamp().toString( Qt::ISODate ) );
883 stamp.appendChild( stampText );
884 layerElement.appendChild( stamp );
885 }
886
887 layerElement.appendChild( layerName );
888
889 // zorder
890 // This is no longer stored in the project file. It is superfluous since the layers
891 // are written and read in the proper order.
892
893 // spatial reference system id
894 QDomElement mySrsElement = document.createElement( QStringLiteral( "srs" ) );
895 mCRS.writeXml( mySrsElement, document );
896 layerElement.appendChild( mySrsElement );
897
898 // layer metadata
899 QDomElement myMetadataElem = document.createElement( QStringLiteral( "resourceMetadata" ) );
900 mMetadata.writeMetadataXml( myMetadataElem, document );
901 layerElement.appendChild( myMetadataElem );
902
903 layerElement.setAttribute( QStringLiteral( "legendPlaceholderImage" ), mLegendPlaceholderImage );
904
905 // now append layer node to map layer node
906 return writeXml( layerElement, document, context );
907}
908
909void QgsMapLayer::writeCommonStyle( QDomElement &layerElement, QDomDocument &document,
910 const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories ) const
911{
913
914 // save categories
915 const QMetaEnum metaEnum = QMetaEnum::fromType<QgsMapLayer::StyleCategories>();
916 const QString categoriesKeys( metaEnum.valueToKeys( static_cast<int>( categories ) ) );
917 layerElement.setAttribute( QStringLiteral( "styleCategories" ), categoriesKeys );
918
919 if ( categories.testFlag( Rendering ) )
920 {
921 // use scale dependent visibility flag
922 layerElement.setAttribute( QStringLiteral( "hasScaleBasedVisibilityFlag" ), hasScaleBasedVisibility() ? 1 : 0 );
923 layerElement.setAttribute( QStringLiteral( "maxScale" ), QString::number( maximumScale() ) );
924 layerElement.setAttribute( QStringLiteral( "minScale" ), QString::number( minimumScale() ) );
925 layerElement.setAttribute( QStringLiteral( "autoRefreshMode" ), qgsEnumValueToKey( mAutoRefreshMode ) );
926 layerElement.setAttribute( QStringLiteral( "autoRefreshTime" ), QString::number( autoRefreshInterval() ) );
927 }
928
929 if ( categories.testFlag( Symbology3D ) )
930 {
931 if ( m3DRenderer )
932 {
933 QDomElement renderer3DElem = document.createElement( QStringLiteral( "renderer-3d" ) );
934 renderer3DElem.setAttribute( QStringLiteral( "type" ), m3DRenderer->type() );
935 m3DRenderer->writeXml( renderer3DElem, context );
936 layerElement.appendChild( renderer3DElem );
937 }
938 }
939
940 if ( categories.testFlag( LayerConfiguration ) )
941 {
942 // flags
943 // this code is saving automatically all the flags entries
944 QDomElement layerFlagsElem = document.createElement( QStringLiteral( "flags" ) );
945 const auto enumMap = qgsEnumMap<QgsMapLayer::LayerFlag>();
946 for ( auto it = enumMap.constBegin(); it != enumMap.constEnd(); ++it )
947 {
948 const bool flagValue = mFlags.testFlag( it.key() );
949 QDomElement flagElem = document.createElement( it.value() );
950 flagElem.appendChild( document.createTextNode( QString::number( flagValue ) ) );
951 layerFlagsElem.appendChild( flagElem );
952 }
953 layerElement.appendChild( layerFlagsElem );
954 }
955
956 if ( categories.testFlag( Temporal ) )
957 {
959 properties->writeXml( layerElement, document, context );
960 }
961
962 if ( categories.testFlag( Elevation ) )
963 {
965 properties->writeXml( layerElement, document, context );
966 }
967
968 if ( categories.testFlag( Notes ) && QgsLayerNotesUtils::layerHasNotes( this ) )
969 {
970 QDomElement notesElem = document.createElement( QStringLiteral( "userNotes" ) );
971 notesElem.setAttribute( QStringLiteral( "value" ), QgsLayerNotesUtils::layerNotes( this ) );
972 layerElement.appendChild( notesElem );
973 }
974
975 // custom properties
976 if ( categories.testFlag( CustomProperties ) )
977 {
978 writeCustomProperties( layerElement, document );
979 }
980}
981
982
983bool QgsMapLayer::writeXml( QDomNode &layer_node, QDomDocument &document, const QgsReadWriteContext &context ) const
984{
986
987 Q_UNUSED( layer_node )
988 Q_UNUSED( document )
989 Q_UNUSED( context )
990 // NOP by default; children will over-ride with behavior specific to them
991
992 return true;
993}
994
995QString QgsMapLayer::encodedSource( const QString &source, const QgsReadWriteContext &context ) const
996{
998
999 Q_UNUSED( context )
1000 return source;
1001}
1002
1003QString QgsMapLayer::decodedSource( const QString &source, const QString &dataProvider, const QgsReadWriteContext &context ) const
1004{
1006
1007 Q_UNUSED( context )
1008 Q_UNUSED( dataProvider )
1009 return source;
1010}
1011
1013{
1015
1017 if ( m3DRenderer )
1018 m3DRenderer->resolveReferences( *project );
1019}
1020
1021
1022void QgsMapLayer::readCustomProperties( const QDomNode &layerNode, const QString &keyStartsWith )
1023{
1025
1026 const QgsObjectCustomProperties oldKeys = mCustomProperties;
1027
1028 mCustomProperties.readXml( layerNode, keyStartsWith );
1029
1030 for ( const QString &key : mCustomProperties.keys() )
1031 {
1032 if ( !oldKeys.contains( key ) || mCustomProperties.value( key ) != oldKeys.value( key ) )
1033 {
1034 emit customPropertyChanged( key );
1035 }
1036 }
1037}
1038
1039void QgsMapLayer::writeCustomProperties( QDomNode &layerNode, QDomDocument &doc ) const
1040{
1042
1043 mCustomProperties.writeXml( layerNode, doc );
1044}
1045
1046void QgsMapLayer::readStyleManager( const QDomNode &layerNode )
1047{
1049
1050 const QDomElement styleMgrElem = layerNode.firstChildElement( QStringLiteral( "map-layer-style-manager" ) );
1051 if ( !styleMgrElem.isNull() )
1052 mStyleManager->readXml( styleMgrElem );
1053 else
1054 mStyleManager->reset();
1055}
1056
1057void QgsMapLayer::writeStyleManager( QDomNode &layerNode, QDomDocument &doc ) const
1058{
1060
1061 if ( mStyleManager )
1062 {
1063 QDomElement styleMgrElem = doc.createElement( QStringLiteral( "map-layer-style-manager" ) );
1064 mStyleManager->writeXml( styleMgrElem );
1065 layerNode.appendChild( styleMgrElem );
1066 }
1067}
1068
1070{
1072
1073 return mMapTipTemplate;
1074}
1075
1076void QgsMapLayer::setMapTipTemplate( const QString &mapTip )
1077{
1079
1080 if ( mMapTipTemplate == mapTip )
1081 return;
1082
1083 mMapTipTemplate = mapTip;
1084 emit mapTipTemplateChanged();
1085}
1086
1088{
1090
1091 if ( mMapTipsEnabled == enabled )
1092 return;
1093
1094 mMapTipsEnabled = enabled;
1095 emit mapTipsEnabledChanged();
1096}
1097
1099{
1101
1102 return mMapTipsEnabled;
1103}
1104
1106{
1108 if ( layerReadFlags & QgsMapLayer::FlagTrustLayerMetadata )
1109 {
1111 }
1112 if ( layerReadFlags & QgsMapLayer::FlagForceReadOnly )
1113 {
1115 }
1116
1117 if ( layerReadFlags & QgsMapLayer::FlagReadExtentFromXml )
1118 {
1119 const QDomNode extent3DNode = layerNode.namedItem( QStringLiteral( "extent3D" ) );
1120 if ( extent3DNode.isNull() )
1121 {
1122 const QDomNode extentNode = layerNode.namedItem( QStringLiteral( "extent" ) );
1123 if ( !extentNode.isNull() )
1124 {
1126 }
1127 }
1128 else
1129 {
1131 }
1132 }
1133
1134 return flags;
1135}
1136
1138{
1139 // because QgsVirtualLayerProvider is not anywhere NEAR thread safe:
1141
1142 return mValid;
1143}
1144
1145#if 0
1146void QgsMapLayer::connectNotify( const char *signal )
1147{
1148 Q_UNUSED( signal )
1149 QgsDebugMsgLevel( "QgsMapLayer connected to " + QString( signal ), 3 );
1150} // QgsMapLayer::connectNotify
1151#endif
1152
1153bool QgsMapLayer::isInScaleRange( double scale ) const
1154{
1155 // non fatal for now -- the "rasterize" processing algorithm is not thread safe and calls this
1157
1158 // mMinScale (denominator!) is inclusive ( >= --> In range )
1159 // mMaxScale (denominator!) is exclusive ( < --> In range )
1160 return !mScaleBasedVisibility
1161 || ( ( mMinScale == 0 || !QgsScaleUtils::lessThanMaximumScale( scale, mMinScale ) )
1162 && ( mMaxScale == 0 || !QgsScaleUtils::equalToOrGreaterThanMinimumScale( scale, mMaxScale ) ) );
1163}
1164
1166{
1167 // non fatal for now -- the "rasterize" processing algorithm is not thread safe and calls this
1169
1170 return mScaleBasedVisibility;
1171}
1172
1174{
1176
1177 return mAutoRefreshMode != Qgis::AutoRefreshMode::Disabled;;
1178}
1179
1181{
1183
1184 return mAutoRefreshMode;
1185}
1186
1188{
1190
1191 return mRefreshTimer->interval();
1192}
1193
1195{
1197
1198 if ( interval <= 0 )
1199 {
1200 mRefreshTimer->stop();
1201 mRefreshTimer->setInterval( 0 );
1203 }
1204 else
1205 {
1206 mRefreshTimer->setInterval( interval );
1207 }
1208 emit autoRefreshIntervalChanged( mRefreshTimer->isActive() ? mRefreshTimer->interval() : 0 );
1209}
1210
1217
1219{
1221
1222 if ( mode == mAutoRefreshMode )
1223 return;
1224
1225 mAutoRefreshMode = mode;
1226 switch ( mAutoRefreshMode )
1227 {
1229 mRefreshTimer->stop();
1230 break;
1231
1234 if ( mRefreshTimer->interval() > 0 )
1235 mRefreshTimer->start();
1236 break;
1237 }
1238
1239 emit autoRefreshIntervalChanged( mRefreshTimer->isActive() ? mRefreshTimer->interval() : 0 );
1240}
1241
1243{
1245
1246 return mMetadata;
1247}
1248
1250{
1252
1253 mMinScale = scale;
1254}
1255
1257{
1259
1260 return mMinScale;
1261}
1262
1264{
1266
1267 mMaxScale = scale;
1268}
1269
1271{
1273
1274 mScaleBasedVisibility = enabled;
1275}
1276
1278{
1280
1281 return mMaxScale;
1282}
1283
1284QStringList QgsMapLayer::subLayers() const
1285{
1287
1288 return QStringList();
1289}
1290
1291void QgsMapLayer::setLayerOrder( const QStringList &layers )
1292{
1294
1295 Q_UNUSED( layers )
1296}
1297
1298void QgsMapLayer::setSubLayerVisibility( const QString &name, bool vis )
1299{
1301
1302 Q_UNUSED( name )
1303 Q_UNUSED( vis )
1304}
1305
1307{
1309
1310 return false;
1311}
1312
1314{
1315 // non fatal for now -- the "rasterize" processing algorithm is not thread safe and calls this
1317
1318 return mCRS;
1319}
1320
1322{
1323 // non fatal for now -- the "rasterize" processing algorithm is not thread safe and calls this
1325
1326 switch ( mCRS.type() )
1327 {
1328 case Qgis::CrsType::Vertical: // would hope this never happens!
1329 QgsDebugError( QStringLiteral( "Layer has a vertical CRS set as the horizontal CRS!" ) );
1330 return mCRS;
1331
1333 return mCRS.verticalCrs();
1334
1346 break;
1347 }
1348 return mVerticalCrs;
1349}
1350
1352{
1354
1355 return mCrs3D.isValid() ? mCrs3D : mCRS;
1356}
1357
1358void QgsMapLayer::setCrs( const QgsCoordinateReferenceSystem &srs, bool emitSignal )
1359{
1361 const bool needToValidateCrs = mShouldValidateCrs && isSpatial() && !srs.isValid() && type() != Qgis::LayerType::Annotation;
1362
1363 if ( mCRS == srs && !needToValidateCrs )
1364 return;
1365
1366 const QgsCoordinateReferenceSystem oldVerticalCrs = verticalCrs();
1367 const QgsCoordinateReferenceSystem oldCrs3D = mCrs3D;
1368 const QgsCoordinateReferenceSystem oldCrs = mCRS;
1369
1370 mCRS = srs;
1371
1372 if ( needToValidateCrs )
1373 {
1374 mCRS.setValidationHint( tr( "Specify CRS for layer %1" ).arg( name() ) );
1375 mCRS.validate();
1376 }
1377
1378 rebuildCrs3D();
1379
1380 if ( emitSignal && mCRS != oldCrs )
1381 emit crsChanged();
1382
1383 // Did vertical crs also change as a result of this? If so, emit signal
1384 if ( oldVerticalCrs != verticalCrs() )
1385 emit verticalCrsChanged();
1386 if ( oldCrs3D != mCrs3D )
1387 emit crs3DChanged();
1388}
1389
1391{
1393 bool res = true;
1394 if ( crs.isValid() )
1395 {
1396 // validate that passed crs is a vertical crs
1397 switch ( crs.type() )
1398 {
1400 break;
1401
1414 if ( errorMessage )
1415 *errorMessage = QObject::tr( "Specified CRS is a %1 CRS, not a Vertical CRS" ).arg( qgsEnumValueToKey( crs.type() ) );
1416 return false;
1417 }
1418 }
1419
1420 if ( crs != mVerticalCrs )
1421 {
1422 const QgsCoordinateReferenceSystem oldVerticalCrs = verticalCrs();
1423 const QgsCoordinateReferenceSystem oldCrs3D = mCrs3D;
1424
1425 switch ( mCRS.type() )
1426 {
1428 if ( crs != oldVerticalCrs )
1429 {
1430 if ( errorMessage )
1431 *errorMessage = QObject::tr( "Layer CRS is a Compound CRS, specified Vertical CRS will be ignored" );
1432 return false;
1433 }
1434 break;
1435
1437 if ( crs != oldVerticalCrs )
1438 {
1439 if ( errorMessage )
1440 *errorMessage = QObject::tr( "Layer CRS is a Geographic 3D CRS, specified Vertical CRS will be ignored" );
1441 return false;
1442 }
1443 break;
1444
1446 if ( crs != oldVerticalCrs )
1447 {
1448 if ( errorMessage )
1449 *errorMessage = QObject::tr( "Layer CRS is a Geocentric CRS, specified Vertical CRS will be ignored" );
1450 return false;
1451 }
1452 break;
1453
1455 if ( mCRS.hasVerticalAxis() && crs != oldVerticalCrs )
1456 {
1457 if ( errorMessage )
1458 *errorMessage = QObject::tr( "Layer CRS is a Projected 3D CRS, specified Vertical CRS will be ignored" );
1459 return false;
1460 }
1461 break;
1462
1472 break;
1473 }
1474
1475 mVerticalCrs = crs;
1476 res = rebuildCrs3D( errorMessage );
1477
1478 // only emit signal if vertical crs was actually changed, so eg if mCrs is compound
1479 // then we haven't actually changed the vertical crs by this call!
1480 if ( verticalCrs() != oldVerticalCrs )
1481 emit verticalCrsChanged();
1482 if ( mCrs3D != oldCrs3D )
1483 emit crs3DChanged();
1484 }
1485 return res;
1486}
1487
1489{
1491
1492 const QgsDataProvider *lDataProvider = dataProvider();
1493 return lDataProvider ? lDataProvider->transformContext() : QgsCoordinateTransformContext();
1494}
1495
1496QString QgsMapLayer::formatLayerName( const QString &name )
1497{
1498 QString layerName( name );
1499 layerName.replace( '_', ' ' );
1501 return layerName;
1502}
1503
1504QString QgsMapLayer::baseURI( PropertyType type ) const
1505{
1507
1508 QString myURI = publicSource();
1509
1510 // first get base path for delimited text, spatialite and OGR layers,
1511 // as in these cases URI may contain layer name and/or additional
1512 // information. This also strips prefix in case if VSIFILE mechanism
1513 // is used
1514 if ( providerType() == QLatin1String( "ogr" ) || providerType() == QLatin1String( "delimitedtext" )
1515 || providerType() == QLatin1String( "gdal" ) || providerType() == QLatin1String( "spatialite" ) )
1516 {
1517 QVariantMap components = QgsProviderRegistry::instance()->decodeUri( providerType(), myURI );
1518 myURI = components["path"].toString();
1519 }
1520
1521 QFileInfo myFileInfo( myURI );
1522 QString key;
1523
1524 if ( myFileInfo.exists() )
1525 {
1526 // if file is using the /vsizip/ or /vsigzip/ mechanism, cleanup the name
1527 if ( myURI.endsWith( QLatin1String( ".gz" ), Qt::CaseInsensitive ) )
1528 myURI.chop( 3 );
1529 else if ( myURI.endsWith( QLatin1String( ".zip" ), Qt::CaseInsensitive ) )
1530 myURI.chop( 4 );
1531 else if ( myURI.endsWith( QLatin1String( ".tar" ), Qt::CaseInsensitive ) )
1532 myURI.chop( 4 );
1533 else if ( myURI.endsWith( QLatin1String( ".tar.gz" ), Qt::CaseInsensitive ) )
1534 myURI.chop( 7 );
1535 else if ( myURI.endsWith( QLatin1String( ".tgz" ), Qt::CaseInsensitive ) )
1536 myURI.chop( 4 );
1537 myFileInfo.setFile( myURI );
1538 // get the file name for our .qml style file
1539 key = myFileInfo.path() + QDir::separator() + myFileInfo.completeBaseName() + QgsMapLayer::extensionPropertyType( type );
1540 }
1541 else
1542 {
1543 key = publicSource();
1544 }
1545
1546 return key;
1547}
1548
1550{
1552
1553 return baseURI( PropertyType::Metadata );
1554}
1555
1556QString QgsMapLayer::saveDefaultMetadata( bool &resultFlag )
1557{
1559
1561 {
1562 if ( metadata->providerCapabilities() & QgsProviderMetadata::SaveLayerMetadata )
1563 {
1564 try
1565 {
1566 QString errorMessage;
1567 resultFlag = QgsProviderRegistry::instance()->saveLayerMetadata( providerType(), mDataSource, mMetadata, errorMessage );
1568 if ( resultFlag )
1569 return tr( "Successfully saved default layer metadata" );
1570 else
1571 return errorMessage;
1572 }
1573 catch ( QgsNotSupportedException &e )
1574 {
1575 resultFlag = false;
1576 return e.what();
1577 }
1578 }
1579 }
1580
1581 // fallback default metadata saving method, for providers which don't support (or implement) saveLayerMetadata
1582 return saveNamedMetadata( metadataUri(), resultFlag );
1583}
1584
1585QString QgsMapLayer::loadDefaultMetadata( bool &resultFlag )
1586{
1588
1589 return loadNamedMetadata( metadataUri(), resultFlag );
1590}
1591
1593{
1595
1596 return baseURI( PropertyType::Style );
1597}
1598
1605
1606bool QgsMapLayer::loadNamedMetadataFromDatabase( const QString &db, const QString &uri, QString &qmd )
1607{
1609
1610 return loadNamedPropertyFromDatabase( db, uri, qmd, PropertyType::Metadata );
1611}
1612
1613bool QgsMapLayer::loadNamedStyleFromDatabase( const QString &db, const QString &uri, QString &qml )
1614{
1616
1617 return loadNamedPropertyFromDatabase( db, uri, qml, PropertyType::Style );
1618}
1619
1620bool QgsMapLayer::loadNamedPropertyFromDatabase( const QString &db, const QString &uri, QString &xml, QgsMapLayer::PropertyType type )
1621{
1623
1624 QgsDebugMsgLevel( QStringLiteral( "db = %1 uri = %2" ).arg( db, uri ), 4 );
1625
1626 bool resultFlag = false;
1627
1628 // read from database
1631
1632 int myResult;
1633
1634 QgsDebugMsgLevel( QStringLiteral( "Trying to load style or metadata for \"%1\" from \"%2\"" ).arg( uri, db ), 4 );
1635
1636 if ( db.isEmpty() || !QFile( db ).exists() )
1637 return false;
1638
1639 myResult = database.open_v2( db, SQLITE_OPEN_READONLY, nullptr );
1640 if ( myResult != SQLITE_OK )
1641 {
1642 return false;
1643 }
1644
1645 QString mySql;
1646 switch ( type )
1647 {
1648 case Metadata:
1649 mySql = QStringLiteral( "select qmd from tbl_metadata where metadata=?" );
1650 break;
1651
1652 case Style:
1653 mySql = QStringLiteral( "select qml from tbl_styles where style=?" );
1654 break;
1655 }
1656
1657 statement = database.prepare( mySql, myResult );
1658 if ( myResult == SQLITE_OK )
1659 {
1660 QByteArray param = uri.toUtf8();
1661
1662 if ( sqlite3_bind_text( statement.get(), 1, param.data(), param.length(), SQLITE_STATIC ) == SQLITE_OK &&
1663 sqlite3_step( statement.get() ) == SQLITE_ROW )
1664 {
1665 xml = QString::fromUtf8( reinterpret_cast< const char * >( sqlite3_column_text( statement.get(), 0 ) ) );
1666 resultFlag = true;
1667 }
1668 }
1669 return resultFlag;
1670}
1671
1672
1673QString QgsMapLayer::loadNamedStyle( const QString &uri, bool &resultFlag, QgsMapLayer::StyleCategories categories, Qgis::LoadStyleFlags flags )
1674{
1676
1677 return loadNamedStyle( uri, resultFlag, false, categories, flags );
1678}
1679
1680QString QgsMapLayer::loadNamedProperty( const QString &uri, QgsMapLayer::PropertyType type, bool &namedPropertyExists, bool &propertySuccessfullyLoaded, StyleCategories categories, Qgis::LoadStyleFlags flags )
1681{
1683
1684 QgsDebugMsgLevel( QStringLiteral( "uri = %1 myURI = %2" ).arg( uri, publicSource() ), 4 );
1685
1686 namedPropertyExists = false;
1687 propertySuccessfullyLoaded = false;
1688 if ( uri.isEmpty() )
1689 return QString();
1690
1691 QDomDocument myDocument( QStringLiteral( "qgis" ) );
1692
1693 // location of problem associated with errorMsg
1694 int line, column;
1695 QString myErrorMessage;
1696
1697 QFile myFile( uri );
1698 if ( myFile.open( QFile::ReadOnly ) )
1699 {
1700 QgsDebugMsgLevel( QStringLiteral( "file found %1" ).arg( uri ), 2 );
1701 namedPropertyExists = true;
1702
1703 // read file
1704 propertySuccessfullyLoaded = myDocument.setContent( &myFile, &myErrorMessage, &line, &column );
1705 if ( !propertySuccessfullyLoaded )
1706 myErrorMessage = tr( "%1 at line %2 column %3" ).arg( myErrorMessage ).arg( line ).arg( column );
1707 myFile.close();
1708 }
1709 else
1710 {
1711 const QFileInfo project( QgsProject::instance()->fileName() ); // skip-keyword-check
1712 QgsDebugMsgLevel( QStringLiteral( "project fileName: %1" ).arg( project.absoluteFilePath() ), 4 );
1713
1714 QString xml;
1715 switch ( type )
1716 {
1717 case QgsMapLayer::Style:
1718 {
1719 if ( loadNamedStyleFromDatabase( QDir( QgsApplication::qgisSettingsDirPath() ).absoluteFilePath( QStringLiteral( "qgis.qmldb" ) ), uri, xml ) ||
1720 ( project.exists() && loadNamedStyleFromDatabase( project.absoluteDir().absoluteFilePath( project.baseName() + ".qmldb" ), uri, xml ) ) ||
1721 loadNamedStyleFromDatabase( QDir( QgsApplication::pkgDataPath() ).absoluteFilePath( QStringLiteral( "resources/qgis.qmldb" ) ), uri, xml ) )
1722 {
1723 namedPropertyExists = true;
1724 propertySuccessfullyLoaded = myDocument.setContent( xml, &myErrorMessage, &line, &column );
1725 if ( !propertySuccessfullyLoaded )
1726 {
1727 myErrorMessage = tr( "%1 at line %2 column %3" ).arg( myErrorMessage ).arg( line ).arg( column );
1728 }
1729 }
1730 else
1731 {
1733 {
1734 myErrorMessage = tr( "Style not found in database" );
1735 }
1736 }
1737 break;
1738 }
1740 {
1741 if ( loadNamedMetadataFromDatabase( QDir( QgsApplication::qgisSettingsDirPath() ).absoluteFilePath( QStringLiteral( "qgis.qmldb" ) ), uri, xml ) ||
1742 ( project.exists() && loadNamedMetadataFromDatabase( project.absoluteDir().absoluteFilePath( project.baseName() + ".qmldb" ), uri, xml ) ) ||
1743 loadNamedMetadataFromDatabase( QDir( QgsApplication::pkgDataPath() ).absoluteFilePath( QStringLiteral( "resources/qgis.qmldb" ) ), uri, xml ) )
1744 {
1745 namedPropertyExists = true;
1746 propertySuccessfullyLoaded = myDocument.setContent( xml, &myErrorMessage, &line, &column );
1747 if ( !propertySuccessfullyLoaded )
1748 {
1749 myErrorMessage = tr( "%1 at line %2 column %3" ).arg( myErrorMessage ).arg( line ).arg( column );
1750 }
1751 }
1752 else
1753 {
1754 myErrorMessage = tr( "Metadata not found in database" );
1755 }
1756 break;
1757 }
1758 }
1759 }
1760
1761 if ( !propertySuccessfullyLoaded )
1762 {
1763 return myErrorMessage;
1764 }
1765
1766 switch ( type )
1767 {
1768 case QgsMapLayer::Style:
1769 propertySuccessfullyLoaded = importNamedStyle( myDocument, myErrorMessage, categories );
1770 if ( !propertySuccessfullyLoaded )
1771 myErrorMessage = tr( "Loading style file %1 failed because:\n%2" ).arg( uri, myErrorMessage );
1772 break;
1774 propertySuccessfullyLoaded = importNamedMetadata( myDocument, myErrorMessage );
1775 if ( !propertySuccessfullyLoaded )
1776 myErrorMessage = tr( "Loading metadata file %1 failed because:\n%2" ).arg( uri, myErrorMessage );
1777 break;
1778 }
1779 return myErrorMessage;
1780}
1781
1782bool QgsMapLayer::importNamedMetadata( QDomDocument &document, QString &errorMessage )
1783{
1785
1786 const QDomElement myRoot = document.firstChildElement( QStringLiteral( "qgis" ) );
1787 if ( myRoot.isNull() )
1788 {
1789 errorMessage = tr( "Root <qgis> element could not be found" );
1790 return false;
1791 }
1792
1793 return mMetadata.readMetadataXml( myRoot );
1794}
1795
1796bool QgsMapLayer::importNamedStyle( QDomDocument &myDocument, QString &myErrorMessage, QgsMapLayer::StyleCategories categories )
1797{
1799
1800 const QDomElement myRoot = myDocument.firstChildElement( QStringLiteral( "qgis" ) );
1801 if ( myRoot.isNull() )
1802 {
1803 myErrorMessage = tr( "Root <qgis> element could not be found" );
1804 return false;
1805 }
1806
1807 // get style file version string, if any
1808 const QgsProjectVersion fileVersion( myRoot.attribute( QStringLiteral( "version" ) ) );
1809 const QgsProjectVersion thisVersion( Qgis::version() );
1810
1811 if ( thisVersion > fileVersion )
1812 {
1813 QgsProjectFileTransform styleFile( myDocument, fileVersion );
1814 styleFile.updateRevision( thisVersion );
1815 }
1816
1817 // Get source categories
1818 const QgsMapLayer::StyleCategories sourceCategories = QgsXmlUtils::readFlagAttribute( myRoot, QStringLiteral( "styleCategories" ), QgsMapLayer::AllStyleCategories );
1819
1820 //Test for matching geometry type on vector layers when applying, if geometry type is given in the style
1821 if ( ( sourceCategories.testFlag( QgsMapLayer::Symbology ) || sourceCategories.testFlag( QgsMapLayer::Symbology3D ) ) &&
1822 ( categories.testFlag( QgsMapLayer::Symbology ) || categories.testFlag( QgsMapLayer::Symbology3D ) ) )
1823 {
1824 if ( type() == Qgis::LayerType::Vector && !myRoot.firstChildElement( QStringLiteral( "layerGeometryType" ) ).isNull() )
1825 {
1826 QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( this );
1827 const Qgis::GeometryType importLayerGeometryType = static_cast<Qgis::GeometryType>( myRoot.firstChildElement( QStringLiteral( "layerGeometryType" ) ).text().toInt() );
1828 if ( importLayerGeometryType != Qgis::GeometryType::Unknown && vl->geometryType() != importLayerGeometryType )
1829 {
1830 myErrorMessage = tr( "Cannot apply style with symbology to layer with a different geometry type" );
1831 return false;
1832 }
1833 }
1834 }
1835
1837 return readSymbology( myRoot, myErrorMessage, context, categories ); // TODO: support relative paths in QML?
1838}
1839
1840void QgsMapLayer::exportNamedMetadata( QDomDocument &doc, QString &errorMsg ) const
1841{
1843
1844 QDomImplementation DomImplementation;
1845 const QDomDocumentType documentType = DomImplementation.createDocumentType( QStringLiteral( "qgis" ), QStringLiteral( "http://mrcc.com/qgis.dtd" ), QStringLiteral( "SYSTEM" ) );
1846 QDomDocument myDocument( documentType );
1847
1848 QDomElement myRootNode = myDocument.createElement( QStringLiteral( "qgis" ) );
1849 myRootNode.setAttribute( QStringLiteral( "version" ), Qgis::version() );
1850 myDocument.appendChild( myRootNode );
1851
1852 if ( !mMetadata.writeMetadataXml( myRootNode, myDocument ) )
1853 {
1854 errorMsg = QObject::tr( "Could not save metadata" );
1855 return;
1856 }
1857
1858 doc = myDocument;
1859}
1860
1861void QgsMapLayer::exportNamedStyle( QDomDocument &doc, QString &errorMsg, const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories ) const
1862{
1864
1865 QDomImplementation DomImplementation;
1866 const QDomDocumentType documentType = DomImplementation.createDocumentType( QStringLiteral( "qgis" ), QStringLiteral( "http://mrcc.com/qgis.dtd" ), QStringLiteral( "SYSTEM" ) );
1867 QDomDocument myDocument( documentType );
1868
1869 QDomElement myRootNode = myDocument.createElement( QStringLiteral( "qgis" ) );
1870 myRootNode.setAttribute( QStringLiteral( "version" ), Qgis::version() );
1871 myDocument.appendChild( myRootNode );
1872
1873 if ( !writeSymbology( myRootNode, myDocument, errorMsg, context, categories ) ) // TODO: support relative paths in QML?
1874 {
1875 errorMsg = QObject::tr( "Could not save symbology because:\n%1" ).arg( errorMsg );
1876 return;
1877 }
1878
1879 /*
1880 * Check to see if the layer is vector - in which case we should also export its geometryType
1881 * to avoid eventually pasting to a layer with a different geometry
1882 */
1883 if ( type() == Qgis::LayerType::Vector )
1884 {
1885 //Getting the selectionLayer geometry
1886 const QgsVectorLayer *vl = qobject_cast<const QgsVectorLayer *>( this );
1887 const QString geoType = QString::number( static_cast<int>( vl->geometryType() ) );
1888
1889 //Adding geometryinformation
1890 QDomElement layerGeometryType = myDocument.createElement( QStringLiteral( "layerGeometryType" ) );
1891 const QDomText type = myDocument.createTextNode( geoType );
1892
1893 layerGeometryType.appendChild( type );
1894 myRootNode.appendChild( layerGeometryType );
1895 }
1896
1897 doc = myDocument;
1898}
1899
1900QString QgsMapLayer::saveDefaultStyle( bool &resultFlag )
1901{
1903
1904 return saveDefaultStyle( resultFlag, AllStyleCategories );
1905}
1906
1907QString QgsMapLayer::saveDefaultStyle( bool &resultFlag, StyleCategories categories )
1908{
1910
1911 return saveNamedStyle( styleURI(), resultFlag, categories );
1912}
1913
1914QString QgsMapLayer::saveNamedMetadata( const QString &uri, bool &resultFlag )
1915{
1917
1918 return saveNamedProperty( uri, QgsMapLayer::Metadata, resultFlag );
1919}
1920
1921QString QgsMapLayer::loadNamedMetadata( const QString &uri, bool &resultFlag )
1922{
1924
1925 bool metadataExists = false;
1926 bool metadataSuccessfullyLoaded = false;
1927 const QString message = loadNamedProperty( uri, QgsMapLayer::Metadata, metadataExists, metadataSuccessfullyLoaded );
1928
1929 // TODO QGIS 4.0 -- fix API for loadNamedMetadata so we can return metadataExists too
1930 ( void )metadataExists;
1931 resultFlag = metadataSuccessfullyLoaded;
1932 return message;
1933}
1934
1935QString QgsMapLayer::saveNamedProperty( const QString &uri, QgsMapLayer::PropertyType type, bool &resultFlag, StyleCategories categories )
1936{
1938
1939 // check if the uri is a file or ends with .qml/.qmd,
1940 // which indicates that it should become one
1941 // everything else goes to the database
1942 QString filename;
1943
1944 QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( this );
1945 if ( vlayer && vlayer->providerType() == QLatin1String( "ogr" ) )
1946 {
1947 QStringList theURIParts = uri.split( '|' );
1948 filename = theURIParts[0];
1949 }
1950 else if ( vlayer && vlayer->providerType() == QLatin1String( "gpx" ) )
1951 {
1952 QStringList theURIParts = uri.split( '?' );
1953 filename = theURIParts[0];
1954 }
1955 else if ( vlayer && vlayer->providerType() == QLatin1String( "delimitedtext" ) )
1956 {
1957 filename = QUrl::fromEncoded( uri.toLatin1() ).toLocalFile();
1958 // toLocalFile() returns an empty string if theURI is a plain Windows-path, e.g. "C:/style.qml"
1959 if ( filename.isEmpty() )
1960 filename = uri;
1961 }
1962 else
1963 {
1964 filename = uri;
1965 }
1966
1967 QString myErrorMessage;
1968 QDomDocument myDocument;
1969 switch ( type )
1970 {
1971 case Metadata:
1972 exportNamedMetadata( myDocument, myErrorMessage );
1973 break;
1974
1975 case Style:
1976 const QgsReadWriteContext context;
1977 exportNamedStyle( myDocument, myErrorMessage, context, categories );
1978 break;
1979 }
1980
1981 const QFileInfo myFileInfo( filename );
1982 if ( myFileInfo.exists() || filename.endsWith( QgsMapLayer::extensionPropertyType( type ), Qt::CaseInsensitive ) )
1983 {
1984 const QFileInfo myDirInfo( myFileInfo.path() ); //excludes file name
1985 if ( !myDirInfo.isWritable() )
1986 {
1987 resultFlag = false;
1988 return tr( "The directory containing your dataset needs to be writable!" );
1989 }
1990
1991 // now construct the file name for our .qml or .qmd file
1992 const QString myFileName = myFileInfo.path() + QDir::separator() + myFileInfo.completeBaseName() + QgsMapLayer::extensionPropertyType( type );
1993
1994 QFile myFile( myFileName );
1995 if ( myFile.open( QFile::WriteOnly | QFile::Truncate ) )
1996 {
1997 QTextStream myFileStream( &myFile );
1998 // save as utf-8 with 2 spaces for indents
1999 myDocument.save( myFileStream, 2 );
2000 myFile.close();
2001 resultFlag = true;
2002 switch ( type )
2003 {
2004 case Metadata:
2005 return tr( "Created default metadata file as %1" ).arg( myFileName );
2006
2007 case Style:
2008 return tr( "Created default style file as %1" ).arg( myFileName );
2009 }
2010
2011 }
2012 else
2013 {
2014 resultFlag = false;
2015 switch ( type )
2016 {
2017 case Metadata:
2018 return tr( "ERROR: Failed to created default metadata file as %1. Check file permissions and retry." ).arg( myFileName );
2019
2020 case Style:
2021 return tr( "ERROR: Failed to created default style file as %1. Check file permissions and retry." ).arg( myFileName );
2022 }
2023 }
2024 }
2025 else
2026 {
2027 const QString qml = myDocument.toString();
2028
2029 // read from database
2032
2033 int myResult = database.open( QDir( QgsApplication::qgisSettingsDirPath() ).absoluteFilePath( QStringLiteral( "qgis.qmldb" ) ) );
2034 if ( myResult != SQLITE_OK )
2035 {
2036 return tr( "User database could not be opened." );
2037 }
2038
2039 QByteArray param0 = uri.toUtf8();
2040 QByteArray param1 = qml.toUtf8();
2041
2042 QString mySql;
2043 switch ( type )
2044 {
2045 case Metadata:
2046 mySql = QStringLiteral( "create table if not exists tbl_metadata(metadata varchar primary key,qmd varchar)" );
2047 break;
2048
2049 case Style:
2050 mySql = QStringLiteral( "create table if not exists tbl_styles(style varchar primary key,qml varchar)" );
2051 break;
2052 }
2053
2054 statement = database.prepare( mySql, myResult );
2055 if ( myResult == SQLITE_OK )
2056 {
2057 if ( sqlite3_step( statement.get() ) != SQLITE_DONE )
2058 {
2059 resultFlag = false;
2060 switch ( type )
2061 {
2062 case Metadata:
2063 return tr( "The metadata table could not be created." );
2064
2065 case Style:
2066 return tr( "The style table could not be created." );
2067 }
2068 }
2069 }
2070
2071 switch ( type )
2072 {
2073 case Metadata:
2074 mySql = QStringLiteral( "insert into tbl_metadata(metadata,qmd) values (?,?)" );
2075 break;
2076
2077 case Style:
2078 mySql = QStringLiteral( "insert into tbl_styles(style,qml) values (?,?)" );
2079 break;
2080 }
2081 statement = database.prepare( mySql, myResult );
2082 if ( myResult == SQLITE_OK )
2083 {
2084 if ( sqlite3_bind_text( statement.get(), 1, param0.data(), param0.length(), SQLITE_STATIC ) == SQLITE_OK &&
2085 sqlite3_bind_text( statement.get(), 2, param1.data(), param1.length(), SQLITE_STATIC ) == SQLITE_OK &&
2086 sqlite3_step( statement.get() ) == SQLITE_DONE )
2087 {
2088 resultFlag = true;
2089 switch ( type )
2090 {
2091 case Metadata:
2092 myErrorMessage = tr( "The metadata %1 was saved to database" ).arg( uri );
2093 break;
2094
2095 case Style:
2096 myErrorMessage = tr( "The style %1 was saved to database" ).arg( uri );
2097 break;
2098 }
2099 }
2100 }
2101
2102 if ( !resultFlag )
2103 {
2104 QString mySql;
2105 switch ( type )
2106 {
2107 case Metadata:
2108 mySql = QStringLiteral( "update tbl_metadata set qmd=? where metadata=?" );
2109 break;
2110
2111 case Style:
2112 mySql = QStringLiteral( "update tbl_styles set qml=? where style=?" );
2113 break;
2114 }
2115 statement = database.prepare( mySql, myResult );
2116 if ( myResult == SQLITE_OK )
2117 {
2118 if ( sqlite3_bind_text( statement.get(), 2, param0.data(), param0.length(), SQLITE_STATIC ) == SQLITE_OK &&
2119 sqlite3_bind_text( statement.get(), 1, param1.data(), param1.length(), SQLITE_STATIC ) == SQLITE_OK &&
2120 sqlite3_step( statement.get() ) == SQLITE_DONE )
2121 {
2122 resultFlag = true;
2123 switch ( type )
2124 {
2125 case Metadata:
2126 myErrorMessage = tr( "The metadata %1 was updated in the database." ).arg( uri );
2127 break;
2128
2129 case Style:
2130 myErrorMessage = tr( "The style %1 was updated in the database." ).arg( uri );
2131 break;
2132 }
2133 }
2134 else
2135 {
2136 resultFlag = false;
2137 switch ( type )
2138 {
2139 case Metadata:
2140 myErrorMessage = tr( "The metadata %1 could not be updated in the database." ).arg( uri );
2141 break;
2142
2143 case Style:
2144 myErrorMessage = tr( "The style %1 could not be updated in the database." ).arg( uri );
2145 break;
2146 }
2147 }
2148 }
2149 else
2150 {
2151 resultFlag = false;
2152 switch ( type )
2153 {
2154 case Metadata:
2155 myErrorMessage = tr( "The metadata %1 could not be inserted into database." ).arg( uri );
2156 break;
2157
2158 case Style:
2159 myErrorMessage = tr( "The style %1 could not be inserted into database." ).arg( uri );
2160 break;
2161 }
2162 }
2163 }
2164 }
2165
2166 return myErrorMessage;
2167}
2168
2169QString QgsMapLayer::saveNamedStyle( const QString &uri, bool &resultFlag, StyleCategories categories )
2170{
2172
2173 return saveNamedProperty( uri, QgsMapLayer::Style, resultFlag, categories );
2174}
2175
2176void QgsMapLayer::exportSldStyle( QDomDocument &doc, QString &errorMsg ) const
2177{
2178
2179 return exportSldStyleV2( doc, errorMsg, QgsSldExportContext() );
2180}
2181
2182void QgsMapLayer::exportSldStyleV2( QDomDocument &doc, QString &errorMsg, const QgsSldExportContext &exportContext ) const
2183{
2185
2186 QDomDocument myDocument = QDomDocument();
2187
2188 const QDomNode header = myDocument.createProcessingInstruction( QStringLiteral( "xml" ), QStringLiteral( "version=\"1.0\" encoding=\"UTF-8\"" ) );
2189 myDocument.appendChild( header );
2190
2191 const QgsVectorLayer *vlayer = qobject_cast<const QgsVectorLayer *>( this );
2192 const QgsRasterLayer *rlayer = qobject_cast<const QgsRasterLayer *>( this );
2193 if ( !vlayer && !rlayer )
2194 {
2195 errorMsg = tr( "Could not save symbology because:\n%1" )
2196 .arg( tr( "Only vector and raster layers are supported" ) );
2197 return;
2198 }
2199
2200 // Create the root element
2201 QDomElement root = myDocument.createElementNS( QStringLiteral( "http://www.opengis.net/sld" ), QStringLiteral( "StyledLayerDescriptor" ) );
2202 QDomElement layerNode;
2203 if ( vlayer )
2204 {
2205 root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.1.0" ) );
2206 root.setAttribute( QStringLiteral( "xsi:schemaLocation" ), QStringLiteral( "http://www.opengis.net/sld http://schemas.opengis.net/sld/1.1.0/StyledLayerDescriptor.xsd" ) );
2207 root.setAttribute( QStringLiteral( "xmlns:ogc" ), QStringLiteral( "http://www.opengis.net/ogc" ) );
2208 root.setAttribute( QStringLiteral( "xmlns:se" ), QStringLiteral( "http://www.opengis.net/se" ) );
2209 root.setAttribute( QStringLiteral( "xmlns:xlink" ), QStringLiteral( "http://www.w3.org/1999/xlink" ) );
2210 root.setAttribute( QStringLiteral( "xmlns:xsi" ), QStringLiteral( "http://www.w3.org/2001/XMLSchema-instance" ) );
2211 myDocument.appendChild( root );
2212
2213 // Create the NamedLayer element
2214 layerNode = myDocument.createElement( QStringLiteral( "NamedLayer" ) );
2215 root.appendChild( layerNode );
2216 }
2217
2218 // note: Only SLD 1.0 version is generated because seems none is using SE1.1.0 at least for rasters
2219 if ( rlayer )
2220 {
2221 // Create the root element
2222 root.setAttribute( QStringLiteral( "version" ), QStringLiteral( "1.0.0" ) );
2223 root.setAttribute( QStringLiteral( "xmlns:gml" ), QStringLiteral( "http://www.opengis.net/gml" ) );
2224 root.setAttribute( QStringLiteral( "xmlns:ogc" ), QStringLiteral( "http://www.opengis.net/ogc" ) );
2225 root.setAttribute( QStringLiteral( "xmlns:sld" ), QStringLiteral( "http://www.opengis.net/sld" ) );
2226 myDocument.appendChild( root );
2227
2228 // Create the NamedLayer element
2229 layerNode = myDocument.createElement( QStringLiteral( "UserLayer" ) );
2230 root.appendChild( layerNode );
2231 }
2232
2233 QVariantMap props;
2234
2235 QVariant context;
2236 context.setValue( exportContext );
2237
2238 props[ QStringLiteral( "SldExportContext" ) ] = context;
2239
2241 {
2242 props[ QStringLiteral( "scaleMinDenom" ) ] = QString::number( mMinScale );
2243 props[ QStringLiteral( "scaleMaxDenom" ) ] = QString::number( mMaxScale );
2244 }
2245
2246 if ( vlayer )
2247 {
2248 if ( !vlayer->writeSld( layerNode, myDocument, errorMsg, props ) )
2249 {
2250 errorMsg = tr( "Could not save symbology because:\n%1" ).arg( errorMsg );
2251 return;
2252 }
2253 }
2254
2255 if ( rlayer )
2256 {
2257 if ( !rlayer->writeSld( layerNode, myDocument, errorMsg, props ) )
2258 {
2259 errorMsg = tr( "Could not save symbology because:\n%1" ).arg( errorMsg );
2260 return;
2261 }
2262 }
2263
2264 doc = myDocument;
2265}
2266
2267QString QgsMapLayer::saveSldStyle( const QString &uri, bool &resultFlag ) const
2268{
2269 QgsSldExportContext context;
2270 context.setExportFilePath( uri );
2271 return saveSldStyleV2( resultFlag, context );
2272}
2273
2274QString QgsMapLayer::saveSldStyleV2( bool &resultFlag, const QgsSldExportContext &exportContext ) const
2275{
2277
2278 const QgsMapLayer *mlayer = qobject_cast<const QgsMapLayer *>( this );
2279
2280 const QString uri { exportContext.exportFilePath() };
2281
2282 // check if the uri is a file or ends with .sld,
2283 // which indicates that it should become one
2284 QString filename;
2285 if ( mlayer->providerType() == QLatin1String( "ogr" ) )
2286 {
2287 QStringList theURIParts = uri.split( '|' );
2288 filename = theURIParts[0];
2289 }
2290 else if ( mlayer->providerType() == QLatin1String( "gpx" ) )
2291 {
2292 QStringList theURIParts = uri.split( '?' );
2293 filename = theURIParts[0];
2294 }
2295 else if ( mlayer->providerType() == QLatin1String( "delimitedtext" ) )
2296 {
2297 filename = QUrl::fromEncoded( uri.toLatin1() ).toLocalFile();
2298 // toLocalFile() returns an empty string if theURI is a plain Windows-path, e.g. "C:/style.qml"
2299 if ( filename.isEmpty() )
2300 filename = uri;
2301 }
2302 else
2303 {
2304 filename = uri;
2305 }
2306
2307 const QFileInfo myFileInfo( filename );
2308 if ( myFileInfo.exists() || filename.endsWith( QLatin1String( ".sld" ), Qt::CaseInsensitive ) )
2309 {
2310 const QFileInfo myDirInfo( myFileInfo.path() ); //excludes file name
2311 if ( !myDirInfo.isWritable() )
2312 {
2313 resultFlag = false;
2314 return tr( "The directory containing your dataset needs to be writable!" );
2315 }
2316
2317 // now construct the file name for our .sld style file
2318 const QString myFileName = myFileInfo.path() + QDir::separator() + myFileInfo.completeBaseName() + ".sld";
2319
2320 QString errorMsg;
2321 QDomDocument myDocument;
2322
2323 QgsSldExportContext context { exportContext };
2324 context.setExportFilePath( myFileName );
2325
2326 mlayer->exportSldStyleV2( myDocument, errorMsg, context );
2327
2328 if ( !errorMsg.isNull() )
2329 {
2330 resultFlag = false;
2331 return errorMsg;
2332 }
2333
2334 QFile myFile( myFileName );
2335 if ( myFile.open( QFile::WriteOnly | QFile::Truncate ) )
2336 {
2337 QTextStream myFileStream( &myFile );
2338 // save as utf-8 with 2 spaces for indents
2339 myDocument.save( myFileStream, 2 );
2340 myFile.close();
2341 resultFlag = true;
2342 return tr( "Created default style file as %1" ).arg( myFileName );
2343 }
2344 }
2345
2346 resultFlag = false;
2347 return tr( "ERROR: Failed to created SLD style file as %1. Check file permissions and retry." ).arg( filename );
2348
2349}
2350
2351QString QgsMapLayer::loadSldStyle( const QString &uri, bool &resultFlag )
2352{
2354
2355 resultFlag = false;
2356
2357 QDomDocument myDocument;
2358
2359 // location of problem associated with errorMsg
2360 int line, column;
2361 QString myErrorMessage;
2362
2363 QFile myFile( uri );
2364 if ( myFile.open( QFile::ReadOnly ) )
2365 {
2366 // read file
2367 resultFlag = myDocument.setContent( &myFile, true, &myErrorMessage, &line, &column );
2368 if ( !resultFlag )
2369 myErrorMessage = tr( "%1 at line %2 column %3" ).arg( myErrorMessage ).arg( line ).arg( column );
2370 myFile.close();
2371 }
2372 else
2373 {
2374 myErrorMessage = tr( "Unable to open file %1" ).arg( uri );
2375 }
2376
2377 if ( !resultFlag )
2378 {
2379 return myErrorMessage;
2380 }
2381
2382 // check for root SLD element
2383 const QDomElement myRoot = myDocument.firstChildElement( QStringLiteral( "StyledLayerDescriptor" ) );
2384 if ( myRoot.isNull() )
2385 {
2386 myErrorMessage = QStringLiteral( "Error: StyledLayerDescriptor element not found in %1" ).arg( uri );
2387 resultFlag = false;
2388 return myErrorMessage;
2389 }
2390
2391 // now get the style node out and pass it over to the layer
2392 // to deserialise...
2393 const QDomElement namedLayerElem = myRoot.firstChildElement( QStringLiteral( "NamedLayer" ) );
2394 if ( namedLayerElem.isNull() )
2395 {
2396 myErrorMessage = QStringLiteral( "Info: NamedLayer element not found." );
2397 resultFlag = false;
2398 return myErrorMessage;
2399 }
2400
2401 QString errorMsg;
2402 resultFlag = readSld( namedLayerElem, errorMsg );
2403 if ( !resultFlag )
2404 {
2405 myErrorMessage = tr( "Loading style file %1 failed because:\n%2" ).arg( uri, errorMsg );
2406 return myErrorMessage;
2407 }
2408
2409 return QString();
2410}
2411
2412bool QgsMapLayer::readStyle( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories )
2413{
2415
2416 Q_UNUSED( node )
2417 Q_UNUSED( errorMessage )
2418 Q_UNUSED( context )
2419 Q_UNUSED( categories )
2420 return false;
2421}
2422
2423bool QgsMapLayer::writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage,
2424 const QgsReadWriteContext &context, QgsMapLayer::StyleCategories categories ) const
2425{
2427
2428 Q_UNUSED( node )
2429 Q_UNUSED( doc )
2430 Q_UNUSED( errorMessage )
2431 Q_UNUSED( context )
2432 Q_UNUSED( categories )
2433 return false;
2434}
2435
2436
2437void QgsMapLayer::setDataSource( const QString &dataSource, const QString &baseName, const QString &provider,
2438 bool loadDefaultStyleFlag )
2439{
2441
2443
2445 if ( loadDefaultStyleFlag )
2446 {
2448 }
2449
2451 {
2453 }
2454 setDataSource( dataSource,
2455 baseName.isEmpty() ? mLayerName : baseName,
2456 provider.isEmpty() ? mProviderKey : provider,
2457 options, flags );
2458}
2459
2460void QgsMapLayer::setDataSource( const QString &dataSource, const QString &baseName, const QString &provider,
2461 const QgsDataProvider::ProviderOptions &options, bool loadDefaultStyleFlag )
2462{
2464
2466 if ( loadDefaultStyleFlag )
2467 {
2469 }
2470
2472 {
2474 }
2475 setDataSource( dataSource, baseName, provider, options, flags );
2476}
2477
2478void QgsMapLayer::setDataSource( const QString &dataSource, const QString &baseName, const QString &provider,
2480{
2482
2485 {
2487 }
2488 setDataSourcePrivate( dataSource, baseName, provider, options, flags );
2489 emit dataSourceChanged();
2490 emit dataChanged();
2492}
2493
2494
2495void QgsMapLayer::setDataSourcePrivate( const QString &dataSource, const QString &baseName, const QString &provider,
2497{
2499
2500 Q_UNUSED( dataSource )
2501 Q_UNUSED( baseName )
2502 Q_UNUSED( provider )
2503 Q_UNUSED( options )
2504 Q_UNUSED( flags )
2505}
2506
2507
2509{
2511
2512 return mProviderKey;
2513}
2514
2515void QgsMapLayer::readCommonStyle( const QDomElement &layerElement, const QgsReadWriteContext &context,
2516 QgsMapLayer::StyleCategories categories )
2517{
2519
2520 if ( categories.testFlag( Symbology3D ) )
2521 {
2522 const QgsReadWriteContextCategoryPopper p = context.enterCategory( tr( "3D Symbology" ) );
2523
2524 QgsAbstract3DRenderer *r3D = nullptr;
2525 QDomElement renderer3DElem = layerElement.firstChildElement( QStringLiteral( "renderer-3d" ) );
2526 if ( !renderer3DElem.isNull() )
2527 {
2528 const QString type3D = renderer3DElem.attribute( QStringLiteral( "type" ) );
2530 if ( meta3D )
2531 {
2532 r3D = meta3D->createRenderer( renderer3DElem, context );
2533 }
2534 }
2535 setRenderer3D( r3D );
2536 }
2537
2538 if ( categories.testFlag( CustomProperties ) )
2539 {
2540 // read custom properties before passing reading further to a subclass, so that
2541 // the subclass can also read custom properties
2542 readCustomProperties( layerElement );
2543 }
2544
2545 // use scale dependent visibility flag
2546 if ( categories.testFlag( Rendering ) )
2547 {
2548 setScaleBasedVisibility( layerElement.attribute( QStringLiteral( "hasScaleBasedVisibilityFlag" ) ).toInt() == 1 );
2549 if ( layerElement.hasAttribute( QStringLiteral( "minimumScale" ) ) )
2550 {
2551 // older element, when scales were reversed
2552 setMaximumScale( layerElement.attribute( QStringLiteral( "minimumScale" ) ).toDouble() );
2553 setMinimumScale( layerElement.attribute( QStringLiteral( "maximumScale" ) ).toDouble() );
2554 }
2555 else
2556 {
2557 setMaximumScale( layerElement.attribute( QStringLiteral( "maxScale" ) ).toDouble() );
2558 setMinimumScale( layerElement.attribute( QStringLiteral( "minScale" ) ).toDouble() );
2559 }
2560 if ( layerElement.hasAttribute( QStringLiteral( "autoRefreshMode" ) ) )
2561 {
2562 setAutoRefreshMode( qgsEnumKeyToValue( layerElement.attribute( QStringLiteral( "autoRefreshMode" ) ), Qgis::AutoRefreshMode::Disabled ) );
2563 setAutoRefreshInterval( layerElement.attribute( QStringLiteral( "autoRefreshTime" ) ).toInt() );
2564 }
2565 }
2566
2567 if ( categories.testFlag( LayerConfiguration ) )
2568 {
2569 // flags
2570 const QDomElement flagsElem = layerElement.firstChildElement( QStringLiteral( "flags" ) );
2571 LayerFlags flags = mFlags;
2572 const auto enumMap = qgsEnumMap<QgsMapLayer::LayerFlag>();
2573 for ( auto it = enumMap.constBegin(); it != enumMap.constEnd(); ++it )
2574 {
2575 const QDomNode flagNode = flagsElem.namedItem( it.value() );
2576 if ( flagNode.isNull() )
2577 continue;
2578 const bool flagValue = flagNode.toElement().text() == "1" ? true : false;
2579 if ( flags.testFlag( it.key() ) && !flagValue )
2580 flags &= ~it.key();
2581 else if ( !flags.testFlag( it.key() ) && flagValue )
2582 flags |= it.key();
2583 }
2584 setFlags( flags );
2585 }
2586
2587 if ( categories.testFlag( Temporal ) )
2588 {
2589 const QgsReadWriteContextCategoryPopper p = context.enterCategory( tr( "Temporal" ) );
2590
2592 properties->readXml( layerElement.toElement(), context );
2593 }
2594
2595 if ( categories.testFlag( Elevation ) )
2596 {
2597 const QgsReadWriteContextCategoryPopper p = context.enterCategory( tr( "Elevation" ) );
2598
2600 properties->readXml( layerElement.toElement(), context );
2601 }
2602
2603 if ( categories.testFlag( Notes ) )
2604 {
2605 const QDomElement notesElem = layerElement.firstChildElement( QStringLiteral( "userNotes" ) );
2606 if ( !notesElem.isNull() )
2607 {
2608 const QString notes = notesElem.attribute( QStringLiteral( "value" ) );
2609 QgsLayerNotesUtils::setLayerNotes( this, notes );
2610 }
2611 }
2612}
2613
2615{
2617
2618 return mUndoStack;
2619}
2620
2622{
2624
2625 return mUndoStackStyles;
2626}
2627
2629{
2631
2632 return mCustomProperties.keys();
2633}
2634
2635void QgsMapLayer::setCustomProperty( const QString &key, const QVariant &value )
2636{
2638
2639 if ( !mCustomProperties.contains( key ) || mCustomProperties.value( key ) != value )
2640 {
2641 mCustomProperties.setValue( key, value );
2642 emit customPropertyChanged( key );
2643 }
2644}
2645
2647{
2649
2650 mCustomProperties = properties;
2651 for ( const QString &key : mCustomProperties.keys() )
2652 {
2653 emit customPropertyChanged( key );
2654 }
2655}
2656
2658{
2660
2661 return mCustomProperties;
2662}
2663
2664QVariant QgsMapLayer::customProperty( const QString &value, const QVariant &defaultValue ) const
2665{
2666 // non fatal for now -- the "rasterize" processing algorithm is not thread safe and calls this
2668
2669 return mCustomProperties.value( value, defaultValue );
2670}
2671
2672void QgsMapLayer::removeCustomProperty( const QString &key )
2673{
2675
2676 if ( mCustomProperties.contains( key ) )
2677 {
2678 mCustomProperties.remove( key );
2679 emit customPropertyChanged( key );
2680 }
2681}
2682
2683int QgsMapLayer::listStylesInDatabase( QStringList &ids, QStringList &names, QStringList &descriptions, QString &msgError )
2684{
2686
2687 return QgsProviderRegistry::instance()->listStyles( mProviderKey, mDataSource, ids, names, descriptions, msgError );
2688}
2689
2690QString QgsMapLayer::getStyleFromDatabase( const QString &styleId, QString &msgError )
2691{
2693
2694 return QgsProviderRegistry::instance()->getStyleById( mProviderKey, mDataSource, styleId, msgError );
2695}
2696
2697bool QgsMapLayer::deleteStyleFromDatabase( const QString &styleId, QString &msgError )
2698{
2700
2702}
2703
2704void QgsMapLayer::saveStyleToDatabase( const QString &name, const QString &description,
2705 bool useAsDefault, const QString &uiFileContent, QString &msgError, QgsMapLayer::StyleCategories categories )
2706{
2708
2709 QString sldStyle, qmlStyle;
2710 QDomDocument qmlDocument, sldDocument;
2711 QgsReadWriteContext context;
2712 exportNamedStyle( qmlDocument, msgError, context, categories );
2713 if ( !msgError.isNull() )
2714 {
2715 return;
2716 }
2717 qmlStyle = qmlDocument.toString();
2718
2719 this->exportSldStyle( sldDocument, msgError );
2720 if ( !msgError.isNull() )
2721 {
2722 return;
2723 }
2724 sldStyle = sldDocument.toString();
2725
2727 mDataSource, qmlStyle, sldStyle, name,
2728 description, uiFileContent, useAsDefault, msgError );
2729}
2730
2731QString QgsMapLayer::loadNamedStyle( const QString &theURI, bool &resultFlag, bool loadFromLocalDB, QgsMapLayer::StyleCategories categories, Qgis::LoadStyleFlags flags )
2732{
2734
2735 QString returnMessage;
2736 QString qml, errorMsg;
2737 QString styleName;
2738 if ( !loadFromLocalDB && dataProvider() && dataProvider()->styleStorageCapabilities().testFlag( Qgis::ProviderStyleStorageCapability::LoadFromDatabase ) )
2739 {
2741 }
2742
2743 // Style was successfully loaded from provider storage
2744 if ( !qml.isEmpty() )
2745 {
2746 QDomDocument myDocument( QStringLiteral( "qgis" ) );
2747 myDocument.setContent( qml );
2748 resultFlag = importNamedStyle( myDocument, errorMsg );
2749 returnMessage = QObject::tr( "Loaded from Provider" );
2750 }
2751 else
2752 {
2754
2755 bool styleExists = false;
2756 bool styleSuccessfullyLoaded = false;
2757
2758 returnMessage = loadNamedProperty( theURI, PropertyType::Style, styleExists, styleSuccessfullyLoaded, categories, flags );
2759
2760 // TODO QGIS 4.0 -- fix API for loadNamedStyle so we can return styleExists too
2761 ( void )styleExists;
2762 resultFlag = styleSuccessfullyLoaded;
2763 }
2764
2765 if ( ! styleName.isEmpty() )
2766 {
2767 styleManager()->renameStyle( styleManager()->currentStyle(), styleName );
2768 }
2769
2770 if ( resultFlag )
2771 emit styleLoaded( categories );
2772
2773 return returnMessage;
2774}
2775
2782
2784{
2786
2787 return false;
2788}
2789
2791{
2793
2794 return false;
2795}
2796
2798{
2800
2801 return true;
2802}
2803
2805{
2807
2808 // invalid layers are temporary? -- who knows?!
2809 if ( !isValid() )
2810 return false;
2811
2812 if ( mProviderKey == QLatin1String( "memory" ) )
2813 return true;
2814
2815 const QVariantMap sourceParts = QgsProviderRegistry::instance()->decodeUri( mProviderKey, mDataSource );
2816 const QString path = sourceParts.value( QStringLiteral( "path" ) ).toString();
2817 if ( path.isEmpty() )
2818 return false;
2819
2820 // check if layer path is inside one of the standard temporary file locations for this platform
2821 const QStringList tempPaths = QStandardPaths::standardLocations( QStandardPaths::TempLocation );
2822 for ( const QString &tempPath : tempPaths )
2823 {
2824 if ( path.startsWith( tempPath ) )
2825 return true;
2826 }
2827
2828 return false;
2829}
2830
2831void QgsMapLayer::setValid( bool valid )
2832{
2834
2835 if ( mValid == valid )
2836 return;
2837
2838 mValid = valid;
2839 emit isValidChanged();
2840}
2841
2843{
2845
2846 if ( legend == mLegend )
2847 return;
2848
2849 delete mLegend;
2850 mLegend = legend;
2851
2852 if ( mLegend )
2853 {
2854 mLegend->setParent( this );
2855 connect( mLegend, &QgsMapLayerLegend::itemsChanged, this, &QgsMapLayer::legendChanged, Qt::UniqueConnection );
2856 }
2857
2858 emit legendChanged();
2859}
2860
2862{
2864
2865 return mLegend;
2866}
2867
2869{
2871
2872 return mStyleManager;
2873}
2874
2876{
2878
2879 if ( renderer == m3DRenderer )
2880 return;
2881
2882 delete m3DRenderer;
2883 m3DRenderer = renderer;
2884 emit renderer3DChanged();
2885 emit repaintRequested();
2887}
2888
2890{
2892
2893 return m3DRenderer;
2894}
2895
2896void QgsMapLayer::triggerRepaint( bool deferredUpdate )
2897{
2899
2900 if ( mRepaintRequestedFired )
2901 return;
2902 mRepaintRequestedFired = true;
2903 emit repaintRequested( deferredUpdate );
2904 mRepaintRequestedFired = false;
2905}
2906
2913
2915{
2917
2918 mMetadata = metadata;
2919// mMetadata.saveToLayer( this );
2920 emit metadataChanged();
2921}
2922
2924{
2926
2927 return QString();
2928}
2929
2930QDateTime QgsMapLayer::timestamp() const
2931{
2933
2934 return QDateTime();
2935}
2936
2944
2946{
2947 updateExtent( extent );
2948}
2949
2951{
2953
2954 updateExtent( extent );
2955}
2956
2957bool QgsMapLayer::isReadOnly() const
2958{
2960
2961 return true;
2962}
2963
2965{
2967
2968 return mOriginalXmlProperties;
2969}
2970
2971void QgsMapLayer::setOriginalXmlProperties( const QString &originalXmlProperties )
2972{
2974
2975 mOriginalXmlProperties = originalXmlProperties;
2976}
2977
2978QString QgsMapLayer::generateId( const QString &layerName )
2979{
2980 // Generate the unique ID of this layer
2981 const QString uuid = QUuid::createUuid().toString();
2982 // trim { } from uuid
2983 QString id = layerName + '_' + uuid.mid( 1, uuid.length() - 2 );
2984 // Tidy the ID up to avoid characters that may cause problems
2985 // elsewhere (e.g in some parts of XML). Replaces every non-word
2986 // character (word characters are the alphabet, numbers and
2987 // underscore) with an underscore.
2988 // Note that the first backslash in the regular expression is
2989 // there for the compiler, so the pattern is actually \W
2990 const thread_local QRegularExpression idRx( QStringLiteral( "[\\W]" ) );
2991 id.replace( idRx, QStringLiteral( "_" ) );
2992 return id;
2993}
2994
2996{
2998
2999 return true;
3000}
3001
3003{
3005
3006 return mapTipsEnabled() && !mMapTipTemplate.isEmpty();
3007}
3008
3009void QgsMapLayer::setProviderType( const QString &providerType )
3010{
3012
3014}
3015
3016QSet<QgsMapLayerDependency> QgsMapLayer::dependencies() const
3017{
3019
3020 return mDependencies;
3021}
3022
3023bool QgsMapLayer::setDependencies( const QSet<QgsMapLayerDependency> &oDeps )
3024{
3026
3027 QSet<QgsMapLayerDependency> deps;
3028 const auto constODeps = oDeps;
3029 for ( const QgsMapLayerDependency &dep : constODeps )
3030 {
3031 if ( dep.origin() == QgsMapLayerDependency::FromUser )
3032 deps << dep;
3033 }
3034
3035 mDependencies = deps;
3036 emit dependenciesChanged();
3037 return true;
3038}
3039
3041{
3043
3044 QgsDataProvider *lDataProvider = dataProvider();
3045
3046 if ( !lDataProvider )
3047 return;
3048
3049 if ( enabled && !isRefreshOnNotifyEnabled() )
3050 {
3051 lDataProvider->setListening( enabled );
3052 connect( lDataProvider, &QgsDataProvider::notify, this, &QgsMapLayer::onNotified );
3053 }
3054 else if ( !enabled && isRefreshOnNotifyEnabled() )
3055 {
3056 // we don't want to disable provider listening because someone else could need it (e.g. actions)
3057 disconnect( lDataProvider, &QgsDataProvider::notify, this, &QgsMapLayer::onNotified );
3058 }
3059 mIsRefreshOnNofifyEnabled = enabled;
3060}
3061
3063{
3065
3066 if ( QgsMapLayerStore *store = qobject_cast<QgsMapLayerStore *>( parent() ) )
3067 {
3068 return qobject_cast<QgsProject *>( store->parent() );
3069 }
3070 return nullptr;
3071}
3072
3073void QgsMapLayer::onNotified( const QString &message )
3074{
3076
3077 if ( refreshOnNotifyMessage().isEmpty() || refreshOnNotifyMessage() == message )
3078 {
3080 emit dataChanged();
3081 }
3082}
3083
3084QgsRectangle QgsMapLayer::wgs84Extent( bool forceRecalculate ) const
3085{
3087
3089
3090 if ( ! forceRecalculate && ! mWgs84Extent.isNull() )
3091 {
3092 wgs84Extent = mWgs84Extent;
3093 }
3094 else if ( ! mExtent2D.isNull() || ! mExtent3D.isNull() )
3095 {
3097 transformer.setBallparkTransformsAreAppropriate( true );
3098 try
3099 {
3100 if ( mExtent2D.isNull() )
3101 wgs84Extent = transformer.transformBoundingBox( mExtent3D.toRectangle() );
3102 else
3103 wgs84Extent = transformer.transformBoundingBox( mExtent2D );
3104 }
3105 catch ( const QgsCsException &cse )
3106 {
3107 QgsMessageLog::logMessage( tr( "Error transforming extent: %1" ).arg( cse.what() ) );
3109 }
3110 }
3111 return wgs84Extent;
3112}
3113
3114void QgsMapLayer::updateExtent( const QgsRectangle &extent ) const
3115{
3117
3118 if ( extent == mExtent2D )
3119 return;
3120
3121 mExtent2D = extent;
3122
3123 // do not update the wgs84 extent if we trust layer metadata
3125 return;
3126
3127 mWgs84Extent = wgs84Extent( true );
3128}
3129
3130void QgsMapLayer::updateExtent( const QgsBox3D &extent ) const
3131{
3133
3134 if ( extent == mExtent3D )
3135 return;
3136
3137 if ( extent.isNull() )
3138 {
3139 if ( !extent.toRectangle().isNull() )
3140 {
3141 // bad 3D extent param but valid in 2d --> update 2D extent
3142 updateExtent( extent.toRectangle() );
3143 }
3144 else
3145 {
3146 QgsDebugMsgLevel( QStringLiteral( "Unable to update extent with empty parameter" ), 1 );
3147 }
3148 }
3149 else
3150 {
3151 mExtent3D = extent;
3152
3153 // do not update the wgs84 extent if we trust layer metadata
3155 return;
3156
3157 mWgs84Extent = wgs84Extent( true );
3158 }
3159}
3160
3161bool QgsMapLayer::rebuildCrs3D( QString *error )
3162{
3163 bool res = true;
3164 if ( !mCRS.isValid() )
3165 {
3167 }
3168 else if ( !mVerticalCrs.isValid() )
3169 {
3170 mCrs3D = mCRS;
3171 }
3172 else
3173 {
3174 switch ( mCRS.type() )
3175 {
3179 mCrs3D = mCRS;
3180 break;
3181
3183 {
3184 QString tempError;
3185 mCrs3D = mCRS.hasVerticalAxis() ? mCRS : QgsCoordinateReferenceSystem::createCompoundCrs( mCRS, mVerticalCrs, error ? *error : tempError );
3186 res = mCrs3D.isValid();
3187 break;
3188 }
3189
3191 // nonsense situation
3193 res = false;
3194 break;
3195
3204 {
3205 QString tempError;
3206 mCrs3D = QgsCoordinateReferenceSystem::createCompoundCrs( mCRS, mVerticalCrs, error ? *error : tempError );
3207 res = mCrs3D.isValid();
3208 break;
3209 }
3210 }
3211 }
3212 return res;
3213}
3214
3216{
3218
3219 // do not update the wgs84 extent if we trust layer metadata
3221 return;
3222
3223 mWgs84Extent = QgsRectangle();
3224}
3225
3227{
3229
3230 QString metadata = QStringLiteral( "<h1>" ) + tr( "General" ) + QStringLiteral( "</h1>\n<hr>\n" ) + QStringLiteral( "<table class=\"list-view\">\n" );
3231
3232 // name
3233 metadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Name" ) + QStringLiteral( "</td><td>" ) + name() + QStringLiteral( "</td></tr>\n" );
3234
3235 QString path;
3236 bool isLocalPath = false;
3237 if ( dataProvider() )
3238 {
3239 // local path
3240 QVariantMap uriComponents = QgsProviderRegistry::instance()->decodeUri( dataProvider()->name(), publicSource() );
3241 if ( uriComponents.contains( QStringLiteral( "path" ) ) )
3242 {
3243 path = uriComponents[QStringLiteral( "path" )].toString();
3244 QFileInfo fi( path );
3245 if ( fi.exists() )
3246 {
3247 isLocalPath = true;
3248 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" );
3249
3250 QDateTime lastModified = fi.lastModified();
3251 QString lastModifiedFileName;
3252 QSet<QString> sidecarFiles = QgsFileUtils::sidecarFilesForPath( path );
3253 if ( fi.isFile() )
3254 {
3255 qint64 fileSize = fi.size();
3256 if ( !sidecarFiles.isEmpty() )
3257 {
3258 lastModifiedFileName = fi.fileName();
3259 QStringList sidecarFileNames;
3260 for ( const QString &sidecarFile : sidecarFiles )
3261 {
3262 QFileInfo sidecarFi( sidecarFile );
3263 fileSize += sidecarFi.size();
3264 if ( sidecarFi.lastModified() > lastModified )
3265 {
3266 lastModified = sidecarFi.lastModified();
3267 lastModifiedFileName = sidecarFi.fileName();
3268 }
3269 sidecarFileNames << sidecarFi.fileName();
3270 }
3271 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" );
3272 }
3273 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" );
3274 }
3275 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" );
3276 }
3277 }
3278 if ( uriComponents.contains( QStringLiteral( "url" ) ) )
3279 {
3280 const QString url = uriComponents[QStringLiteral( "url" )].toString();
3281 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" );
3282 }
3283 }
3284
3285 // data source
3286 if ( publicSource() != path || !isLocalPath )
3287 metadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Source" ) + QStringLiteral( "</td><td>%1" ).arg( publicSource() != path ? publicSource() : path ) + QStringLiteral( "</td></tr>\n" );
3288
3289 // provider
3290 if ( dataProvider() )
3291 metadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Provider" ) + QStringLiteral( "</td><td>%1" ).arg( dataProvider()->name() ) + QStringLiteral( "</td></tr>\n" );
3292
3293 metadata += QLatin1String( "</table>\n<br><br>" );
3294
3295 return metadata;
3296}
3297
3299{
3300 QString metadata;
3301 // custom properties
3302 if ( const auto keys = customPropertyKeys(); !keys.isEmpty() )
3303 {
3304 metadata += QStringLiteral( "<h1>" ) + tr( "Custom properties" ) + QStringLiteral( "</h1>\n<hr>\n" );
3305 metadata += QLatin1String( "<table class=\"list-view\">\n<tbody>" );
3306 for ( const QString &key : keys )
3307 {
3308 // keys prefaced with _ are considered private/internal details
3309 if ( key.startsWith( '_' ) )
3310 continue;
3311
3312 const QVariant propValue = customProperty( key );
3313 QString stringValue;
3314 if ( propValue.type() == QVariant::List || propValue.type() == QVariant::StringList )
3315 {
3316 for ( const QString &s : propValue.toStringList() )
3317 {
3318 stringValue += "<p style=\"margin: 0;\">" + s.toHtmlEscaped() + "</p>";
3319 }
3320 }
3321 else
3322 {
3323 stringValue = propValue.toString().toHtmlEscaped();
3324
3325 //if the result string is empty but propValue is not, the conversion has failed
3326 if ( stringValue.isEmpty() && !QgsVariantUtils::isNull( propValue ) )
3327 stringValue = tr( "<i>value cannot be displayed</i>" );
3328 }
3329
3330 metadata += QStringLiteral( "<tr><td class=\"highlight\">%1</td><td>%2</td></tr>" ).arg( key.toHtmlEscaped(), stringValue );
3331 }
3332 metadata += QLatin1String( "</tbody></table>\n" );
3333 metadata += QLatin1String( "<br><br>\n" );
3334 }
3335 return metadata;
3336}
3337
3339{
3341 QString metadata;
3342
3343 auto addCrsInfo = [&metadata]( const QgsCoordinateReferenceSystem & c, bool includeType, bool includeOperation, bool includeCelestialBody )
3344 {
3345 if ( !c.isValid() )
3346 metadata += QStringLiteral( "<tr><td colspan=\"2\" class=\"highlight\">" ) + tr( "Unknown" ) + QStringLiteral( "</td></tr>\n" );
3347 else
3348 {
3349 metadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Name" ) + QStringLiteral( "</td><td>" ) + c.userFriendlyIdentifier( Qgis::CrsIdentifierType::FullString ) + QStringLiteral( "</td></tr>\n" );
3350
3351 // map units
3352 metadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Units" ) + QStringLiteral( "</td><td>" )
3353 + ( c.isGeographic() ? tr( "Geographic (uses latitude and longitude for coordinates)" ) : QgsUnitTypes::toString( c.mapUnits() ) )
3354 + QStringLiteral( "</td></tr>\n" );
3355
3356 if ( includeType )
3357 {
3358 metadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Type" ) + QStringLiteral( "</td><td>" ) + QgsCoordinateReferenceSystemUtils::crsTypeToString( c.type() ) + QStringLiteral( "</td></tr>\n" );
3359 }
3360
3361 if ( includeOperation )
3362 {
3363 // operation
3364 const QgsProjOperation operation = c.operation();
3365 metadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Method" ) + QStringLiteral( "</td><td>" ) + operation.description() + QStringLiteral( "</td></tr>\n" );
3366 }
3367
3368 if ( includeCelestialBody )
3369 {
3370 // celestial body
3371 try
3372 {
3373 const QString celestialBody = c.celestialBodyName();
3374 if ( !celestialBody.isEmpty() )
3375 {
3376 metadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Celestial Body" ) + QStringLiteral( "</td><td>" ) + celestialBody + QStringLiteral( "</td></tr>\n" );
3377 }
3378 }
3379 catch ( QgsNotSupportedException & )
3380 {
3381
3382 }
3383 }
3384
3385 QString accuracyString;
3386 // dynamic crs with no epoch?
3387 if ( c.isDynamic() && std::isnan( c.coordinateEpoch() ) )
3388 {
3389 accuracyString = tr( "Based on a dynamic CRS, but no coordinate epoch is set. Coordinates are ambiguous and of limited accuracy." );
3390 }
3391
3392 // based on datum ensemble?
3393 try
3394 {
3395 const QgsDatumEnsemble ensemble = c.datumEnsemble();
3396 if ( ensemble.isValid() )
3397 {
3398 QString id;
3399 if ( !ensemble.code().isEmpty() )
3400 id = QStringLiteral( "<i>%1</i> (%2:%3)" ).arg( ensemble.name(), ensemble.authority(), ensemble.code() );
3401 else
3402 id = QStringLiteral( "<i>%</i>”" ).arg( ensemble.name() );
3403
3404 if ( ensemble.accuracy() > 0 )
3405 {
3406 accuracyString = tr( "Based on %1, which has a limited accuracy of <b>at best %2 meters</b>." ).arg( id ).arg( ensemble.accuracy() );
3407 }
3408 else
3409 {
3410 accuracyString = tr( "Based on %1, which has a limited accuracy." ).arg( id );
3411 }
3412 }
3413 }
3414 catch ( QgsNotSupportedException & )
3415 {
3416
3417 }
3418
3419 if ( !accuracyString.isEmpty() )
3420 {
3421 metadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Accuracy" ) + QStringLiteral( "</td><td>" ) + accuracyString + QStringLiteral( "</td></tr>\n" );
3422 }
3423
3424 // static/dynamic
3425 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)" ) );
3426
3427 // coordinate epoch
3428 if ( !std::isnan( c.coordinateEpoch() ) )
3429 {
3430 metadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Coordinate Epoch" ) + QStringLiteral( "</td><td>%1</td></tr>\n" ).arg( qgsDoubleToString( c.coordinateEpoch(), 3 ) );
3431 }
3432 }
3433 };
3434
3435 metadata += QStringLiteral( "<h1>" ) + tr( "Coordinate Reference System (CRS)" ) + QStringLiteral( "</h1>\n<hr>\n" );
3436 metadata += QLatin1String( "<table class=\"list-view\">\n" );
3437 addCrsInfo( crs(), true, true, true );
3438 metadata += QLatin1String( "</table>\n<br><br>\n" );
3439
3440 if ( verticalCrs().isValid() )
3441 {
3442 metadata += QStringLiteral( "<h1>" ) + tr( "Vertical Coordinate Reference System (CRS)" ) + QStringLiteral( "</h1>\n<hr>\n" );
3443 metadata += QLatin1String( "<table class=\"list-view\">\n" );
3444 addCrsInfo( verticalCrs(), false, false, false );
3445 metadata += QLatin1String( "</table>\n<br><br>\n" );
3446 }
3447
3448 return metadata;
3449}
static QString version()
Version string.
Definition qgis.cpp:259
@ FullString
Full definition – possibly a very lengthy string, e.g. with no truncation of custom WKT definitions.
@ Vertical
Vertical CRS.
@ Temporal
Temporal CRS.
@ Compound
Compound (horizontal + vertical) CRS.
@ Projected
Projected CRS.
@ Other
Other type.
@ Bound
Bound CRS.
@ DerivedProjected
Derived projected CRS.
@ Unknown
Unknown type.
@ Engineering
Engineering CRS.
@ Geographic3d
3D geopraphic CRS
@ Geodetic
Geodetic CRS.
@ Geographic2d
2D geographic CRS
@ Geocentric
Geocentric CRS.
@ ForceFirstLetterToCapital
Convert just the first letter of each word to uppercase, leave the rest untouched.
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition qgis.h:337
@ Unknown
Unknown types.
QFlags< DataProviderReadFlag > DataProviderReadFlags
Flags which control data provider construction.
Definition qgis.h:450
LayerType
Types of layers that can be added to a map.
Definition qgis.h:169
@ Annotation
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
@ Vector
Vector layer.
QFlags< MapLayerProperty > MapLayerProperties
Map layer properties.
Definition qgis.h:2163
QFlags< LoadStyleFlag > LoadStyleFlags
Flags for loading layer styles.
Definition qgis.h:225
@ LoadDefaultStyle
Reset the layer's style to the default for the datasource.
@ ForceReadOnly
Open layer in a read-only mode.
@ SkipGetExtent
Skip the extent from provider.
@ TrustDataSource
Trust datasource config (primary key unicity, geometry type and srid, etc). Improves provider load ti...
@ IgnoreMissingStyleErrors
If the style is missing, then don't flag it as an error. This flag can be used when the caller is not...
AutoRefreshMode
Map layer automatic refresh modes.
Definition qgis.h:2173
@ RedrawOnly
Redraw current data only.
@ ReloadData
Reload data (and draw the new data)
@ Disabled
Automatic refreshing is disabled.
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.
A 3-dimensional box composed of x, y, z coordinates.
Definition qgsbox3d.h:43
QgsRectangle toRectangle() const
Converts the box to a 2D rectangle.
Definition qgsbox3d.h:394
bool isNull() const
Test if the box is null (holding no spatial information).
Definition qgsbox3d.cpp:310
static QString crsTypeToString(Qgis::CrsType type)
Returns a translated string representing a CRS type.
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.
bool hasVerticalAxis() const
Returns true if the CRS has a vertical axis.
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 QgsCoordinateReferenceSystem createCompoundCrs(const QgsCoordinateReferenceSystem &horizontalCrs, const QgsCoordinateReferenceSystem &verticalCrs, QString &error)
Given a horizontal and vertical CRS, attempts to create a compound CRS from them.
static void setCustomCrsValidation(CUSTOM_CRS_VALIDATION f)
Sets custom function to force valid CRS.
void setValidationHint(const QString &html)
Set user hint for validation.
QgsCoordinateReferenceSystem verticalCrs() const
Returns the vertical CRS associated with this CRS object.
bool writeXml(QDomNode &node, QDomDocument &doc) const
Stores state to the given Dom node in the given document.
Qgis::CrsType type() const
Returns the type of the CRS.
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.
virtual bool containsElevationData() const
Returns true if the data provider definitely contains elevation related data.
Abstract base class for spatial data provider implementations.
virtual QString name() const =0
Returns a provider name.
void notify(const QString &msg)
Emitted when the datasource issues a notification.
virtual QgsDataProviderElevationProperties * elevationProperties()
Returns the provider's elevation properties.
static QString removePassword(const QString &aUri, bool hide=false)
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
A container for error messages.
Definition qgserror.h:81
QString what() const
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.
bool renameStyle(const QString &name, const QString &newName)
Rename a stored style to a different name.
QgsMapLayerStyle style(const QString &name) const
Returns data of a stored style - accessed by its unique name.
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:76
void crs3DChanged()
Emitted when the crs3D() of the layer has changed.
Q_DECL_DEPRECATED void setShortName(const QString &shortName)
Sets the short name of the layer used by QGIS Server to identify the layer.
virtual bool deleteStyleFromDatabase(const QString &styleId, QString &msgError)
Deletes a style from the database.
bool importNamedMetadata(QDomDocument &document, QString &errorMessage)
Import the metadata of this layer from a QDomDocument.
QString name
Definition qgsmaplayer.h:80
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.
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.
bool setId(const QString &id)
Sets the layer's id.
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.
virtual bool hasMapTips() const
Returns true if the layer contains map tips.
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.
QFlags< ReadFlag > ReadFlags
QFlags< LayerFlag > LayerFlags
virtual bool importNamedStyle(QDomDocument &doc, QString &errorMsg, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories)
Import the properties of this layer from a QDomDocument.
Q_DECL_DEPRECATED void setAbstract(const QString &abstract)
Sets the abstract of the layer used by QGIS Server in GetCapabilities request.
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.
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.
int mBlockStyleChangedSignal
If non-zero, the styleChanged signal should not be emitted.
QString providerType() const
Returns the provider type (provider key) for this layer.
virtual void setExtent3D(const QgsBox3D &box)
Sets the extent.
void removeCustomProperty(const QString &key)
Remove a custom property from layer.
Qgis::AutoRefreshMode autoRefreshMode() const
Returns the layer's automatic refresh mode.
void setBlendMode(QPainter::CompositionMode blendMode)
Set the blending mode used for rendering a layer.
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.
static Qgis::DataProviderReadFlags providerReadFlags(const QDomNode &layerNode, QgsMapLayer::ReadFlags layerReadFlags)
Returns provider read flag deduced from layer read flags layerReadFlags and a dom node layerNode that...
virtual QString loadNamedStyle(const QString &theURI, bool &resultFlag, bool loadFromLocalDb, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories, Qgis::LoadStyleFlags flags=Qgis::LoadStyleFlags())
Loads a named style from file/local db/datasource db.
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::LayerFlags flags() const
Returns the flags for this layer.
QgsCoordinateReferenceSystem crs3D
Definition qgsmaplayer.h:85
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:83
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.
Q_DECL_DEPRECATED QString attribution() const
Returns the attribution of the layer used by QGIS Server in GetCapabilities request.
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
QString mLegendUrl
WMS legend.
virtual int listStylesInDatabase(QStringList &ids, QStringList &names, QStringList &descriptions, QString &msgError)
Lists all the style in db split into related to the layer and not related to.
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...
void setDataSource(const QString &dataSource, const QString &baseName=QString(), const QString &provider=QString(), bool loadDefaultStyleFlag=false)
Updates the data source of the layer.
QString mLayerName
Name of the layer - used for display.
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.
Q_DECL_DEPRECATED bool hasAutoRefreshEnabled() const
Returns true if auto refresh is enabled for the layer.
QString id
Definition qgsmaplayer.h:79
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.
Q_DECL_DEPRECATED void setAttributionUrl(const QString &attribUrl)
Sets the attribution URL of the layer used by QGIS Server in GetCapabilities request.
Q_DECL_DEPRECATED 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:82
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.
Q_DECL_DEPRECATED QString abstract() const
Returns the abstract of the layer used by QGIS Server in GetCapabilities request.
QgsMapLayer(Qgis::LayerType type=Qgis::LayerType::Vector, const QString &name=QString(), const QString &source=QString())
Constructor for QgsMapLayer.
QString originalXmlProperties() const
Returns the XML properties of the original layer as they were when the layer was first read from the ...
Qgis::LayerType type
Definition qgsmaplayer.h:86
Q_DECL_DEPRECATED QString dataUrlFormat() const
Returns the DataUrl format of the layer used by QGIS Server in GetCapabilities request.
QPainter::CompositionMode blendMode() const
Returns the current blending mode for a layer.
Q_DECL_DEPRECATED void setDataUrl(const QString &dataUrl)
Sets the DataUrl of the layer used by QGIS Server in GetCapabilities request.
virtual void setOpacity(double opacity)
Sets the opacity for the layer, where opacity is a value between 0 (totally transparent) and 1....
Q_DECL_DEPRECATED void setKeywordList(const QString &keywords)
Sets the keyword list of the layerused by QGIS Server in GetCapabilities request.
Q_DECL_DEPRECATED void setAttribution(const QString &attrib)
Sets the attribution of the layerused by QGIS Server in GetCapabilities request.
void setFlags(QgsMapLayer::LayerFlags flags)
Returns the flags for this layer.
bool isRefreshOnNotifyEnabled() const
Returns true if the refresh on provider nofification is enabled.
QString publicSource(bool hidePassword=false) const
Gets a version of the internal layer definition that has sensitive bits removed (for example,...
Q_DECL_DEPRECATED 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.
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.
Q_DECL_DEPRECATED void setDataUrlFormat(const QString &dataUrlFormat)
Sets the DataUrl format of the layer used by QGIS Server in GetCapabilities request.
QString mLegendUrlFormat
QFlags< StyleCategory > StyleCategories
virtual void saveStyleToDatabase(const QString &name, const QString &description, bool useAsDefault, const QString &uiFileContent, QString &msgError, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories)
Saves named and sld style of the layer to the style table in the db.
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)
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.
std::unique_ptr< QgsDataProvider > mPreloadedProvider
Optionally used when loading a project, it is released when the layer is effectively created.
Q_DECL_DEPRECATED QString title() const
Returns the title of the layer used by QGIS Server in GetCapabilities request.
void crsChanged()
Emitted when the crs() of the layer has changed.
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...
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.
void idChanged(const QString &id)
Emitted when the layer's ID has been changed.
Q_DECL_DEPRECATED QString dataUrl() const
Returns the DataUrl of the layer used by QGIS Server in GetCapabilities request.
bool hasScaleBasedVisibility() const
Returns whether scale based visibility is enabled for the layer.
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,...
static QString generateId(const QString &layerName)
Generates an unique identifier for this layer, the generate ID is prefixed by layerName.
QgsProviderMetadata * providerMetadata() const
Returns the layer data provider's metadata, it may be nullptr.
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 styleLoaded(QgsMapLayer::StyleCategories categories)
Emitted when a style has been loaded.
virtual QString getStyleFromDatabase(const QString &styleId, QString &msgError)
Returns the named style corresponding to style id provided.
void emitStyleChanged()
Triggers an emission of the styleChanged() signal.
virtual QgsMapLayerTemporalProperties * temporalProperties()
Returns the layer's temporal properties.
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.
void verticalCrsChanged()
Emitted when the verticalCrs() of the layer has changed.
virtual QgsBox3D extent3D() const
Returns the 3D extent of the layer.
static QString extensionPropertyType(PropertyType type)
Returns the extension of a Property.
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()
virtual QString saveSldStyleV2(bool &resultFlag, const QgsSldExportContext &exportContext) const
Saves the properties of this layer to an SLD format file.
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...
QString mDataSource
Data source description string, varies by layer type.
void setAutoRefreshMode(Qgis::AutoRefreshMode mode)
Sets the automatic refresh mode for the layer.
QString refreshOnNotifyMessage() const
Returns the message that should be notified by the provider to triggerRepaint.
virtual bool readSld(const QDomNode &node, QString &errorMessage)
void setMapTipsEnabled(bool enabled)
Enable or disable map tips for this layer.
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.
@ FlagTrustLayerMetadata
Trust layer metadata. Improves layer load time by skipping expensive checks like primary key unicity,...
@ FlagForceReadOnly
Force open as read only.
void setValid(bool valid)
Sets whether layer is valid or not.
Q_DECL_DEPRECATED QString attributionUrl() const
Returns the attribution URL of the layer used by QGIS Server in GetCapabilities request.
void readCommonStyle(const QDomElement &layerElement, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories)
Read style data common to all layer types.
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.
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.
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.
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.
bool setVerticalCrs(const QgsCoordinateReferenceSystem &crs, QString *errorMessage=nullptr)
Sets the layer's vertical coordinate reference system.
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...
bool mapTipsEnabled
Definition qgsmaplayer.h:90
bool readLayerXml(const QDomElement &layerElement, QgsReadWriteContext &context, QgsMapLayer::ReadFlags flags=QgsMapLayer::ReadFlags(), QgsDataProvider *preloadedProvider=nullptr)
Sets state from DOM document.
void setLegend(QgsMapLayerLegend *legend)
Assign a legend controller to the map layer.
double opacity
Definition qgsmaplayer.h:88
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:81
QgsCoordinateReferenceSystem verticalCrs
Definition qgsmaplayer.h:84
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
virtual Q_INVOKABLE QgsDataProvider * dataProvider()
Returns the layer's data provider, it may be nullptr.
double mLayerOpacity
Layer opacity.
bool mValid
Indicates if the layer is valid and can be drawn.
@ LayerConfiguration
General configuration: identifiable, removable, searchable, display expression, read-only.
@ Symbology
Symbology.
@ Notes
Layer user notes.
@ Temporal
Temporal properties.
@ Rendering
Rendering: scale visibility, simplify method, opacity.
@ Elevation
Elevation settings.
@ Symbology3D
3D symbology
@ CustomProperties
Custom properties (by plugins for instance)
virtual Q_INVOKABLE void reload()
Synchronises with changes in the datasource.
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)
void mapTipsEnabledChanged()
Emitted when map tips are enabled or disabled for the layer.
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.
~QgsMapLayer() override
QString customPropertyHtmlMetadata() const
Returns an HTML fragment containing custom property information, for use in the htmlMetadata() method...
const QgsObjectCustomProperties & customProperties() const
Read all custom properties from layer.
virtual void exportSldStyleV2(QDomDocument &doc, QString &errorMsg, const QgsSldExportContext &exportContext) const
Export the properties of this layer as SLD style in a QDomDocument.
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.
Q_DECL_DEPRECATED QString keywordList() const
Returns the keyword list of the layer used by QGIS Server in GetCapabilities request.
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:89
Q_DECL_DEPRECATED void setTitle(const QString &title)
Sets the title of the layer used by QGIS Server in GetCapabilities request.
PropertyType
Maplayer has a style and a metadata property.
bool mShouldValidateCrs
true if the layer's CRS should be validated and invalid CRSes are not permitted.
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.
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.
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
Translates a string using the Qt QTranslator mechanism.
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:107
bool removeAttachedFile(const QString &path)
Removes the attached file.
static QgsProject * instance()
Returns the QgsProject singleton instance.
QString baseName() const
Returns the base name of the project file without the path and without extension - derived from fileN...
QString absoluteFilePath() const
Returns full absolute path to the project file if the project is stored in a file system - derived fr...
Holds data provider key, description, and associated shared library file or function pointer informat...
@ SaveLayerMetadata
Indicates that the provider supports saving native layer metadata.
QString absoluteToRelativeUri(const QString &providerKey, const QString &uri, const QgsReadWriteContext &context) const
Converts absolute path(s) to relative path(s) in the given provider-specific URI.
QString getStyleById(const QString &providerKey, const QString &uri, const QString &styleId, QString &errCause)
Gets a layer style defined by styleId.
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)
Saves metadata to the layer corresponding to the specified uri.
bool deleteStyleById(const QString &providerKey, const QString &uri, const QString &styleId, QString &errCause)
Deletes a layer style defined by styleId.
QString loadStoredStyle(const QString &providerKey, const QString &uri, QString &styleName, QString &errCause)
Loads a layer style from the provider storage, reporting its name.
QString relativeToAbsoluteUri(const QString &providerKey, const QString &uri, const QgsReadWriteContext &context) const
Converts relative path(s) to absolute path(s) in the given provider-specific URI.
QgsProviderMetadata * providerMetadata(const QString &providerKey) const
Returns metadata of the provider or nullptr if not found.
int listStyles(const QString &providerKey, const QString &uri, QStringList &ids, QStringList &names, QStringList &descriptions, QString &errCause)
Lists stored layer styles in the provider defined by providerKey and uri.
bool saveStyle(const QString &providerKey, const QString &uri, const QString &qmlStyle, const QString &sldStyle, const QString &styleName, const QString &styleDescription, const QString &uiFileContent, bool useAsDefault, QString &errCause)
Saves a layer style to provider.
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.
A rectangle specified with double values.
static bool equalToOrGreaterThanMinimumScale(const double scale, const double minScale)
Returns whether the scale is equal to or greater than the minScale, taking non-round numbers into acc...
static bool lessThanMaximumScale(const double scale, const double maxScale)
Returns whether the scale is less than the maxScale, taking non-round numbers into account.
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.
The QgsSldExportContext class holds SLD export options and other information related to SLD export of...
QString exportFilePath() const
Returns the export file path for the SLD.
void setExportFilePath(const QString &exportFilePath)
Sets the export file path for the SLD to exportFilePath.
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(Qgis::DistanceUnit unit)
Returns a translated string representing a distance unit.
static bool isNull(const QVariant &variant, bool silenceNullWarnings=false)
Returns true if the specified variant should be considered a NULL value.
Represents a vector layer which manages a vector based data sets.
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.
Q_INVOKABLE Qgis::GeometryType geometryType() const
Returns point, line or polygon.
static T readFlagAttribute(const QDomElement &element, const QString &attributeName, T defaultValue)
Read a flag value from an attribute of the element.
static QDomElement writeBox3D(const QgsBox3D &box, QDomDocument &doc, const QString &elementName=QStringLiteral("extent3D"))
Encodes a 3D box to a DOM element.
static QgsBox3D readBox3D(const QDomElement &element)
Decodes a DOM element to a 3D box.
static QDomElement writeRectangle(const QgsRectangle &rect, QDomDocument &doc, const QString &elementName=QStringLiteral("extent"))
Encodes a rectangle to a DOM element.
static QgsRectangle readRectangle(const QDomElement &element)
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 ...
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
T qgsEnumKeyToValue(const QString &key, const T &defaultValue, bool tryValueAsKey=true, bool *returnOk=nullptr)
Returns the value corresponding to the given key of an enum.
Definition qgis.h:6234
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
Definition qgis.h:5941
QString qgsEnumValueToKey(const T &value, bool *returnOk=nullptr)
Returns the value for the given key of an enum.
Definition qgis.h:6215
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Definition qgis.h:6024
CONSTLATIN1STRING geoEpsgCrsAuthId()
Geographic coord sys from EPSG authority.
Definition qgis.h:6513
void(* CUSTOM_CRS_VALIDATION)(QgsCoordinateReferenceSystem &)
#define QgsDebugMsgLevel(str, level)
Definition qgslogger.h:39
#define QgsDebugError(str)
Definition qgslogger.h:38
#define QGIS_PROTECT_QOBJECT_THREAD_ACCESS_NON_FATAL
#define QGIS_PROTECT_QOBJECT_THREAD_ACCESS
const QgsCoordinateReferenceSystem & crs
Setting options for creating vector data providers.
QString format
Format specification of online resource.