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