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