QGIS API Documentation 3.29.0-Master (19d7edcfed)
qgsmaplayer.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsmaplayer.h - 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#ifndef QGSMAPLAYER_H
19#define QGSMAPLAYER_H
20
21#include "qgis_core.h"
22#include <QDateTime>
23#include <QDomNode>
24#include <QImage>
25#include <QObject>
26#include <QPainter>
27#include <QUndoStack>
28#include <QVariant>
29#include <QIcon>
30#include <QSet>
31
32#include "qgis_sip.h"
33#include "qgserror.h"
35#include "qgsrectangle.h"
38#include "qgslayermetadata.h"
40#include "qgsreadwritecontext.h"
41#include "qgsdataprovider.h"
42#include "qgis.h"
43#include "qgslogger.h"
44
46class QgsDataProvider;
50class QgsProject;
55
56class QDomDocument;
57class QKeyEvent;
58class QPainter;
60
61/*
62 * Constants used to describe copy-paste MIME types
63 */
64#define QGSCLIPBOARD_MAPLAYER_MIME "application/qgis.maplayer"
65
66
72class CORE_EXPORT QgsMapLayer : public QObject
73{
74 Q_OBJECT
75
76 Q_PROPERTY( QString name READ name WRITE setName NOTIFY nameChanged )
77 Q_PROPERTY( int autoRefreshInterval READ autoRefreshInterval WRITE setAutoRefreshInterval NOTIFY autoRefreshIntervalChanged )
78 Q_PROPERTY( QgsLayerMetadata metadata READ metadata WRITE setMetadata NOTIFY metadataChanged )
79 Q_PROPERTY( QgsCoordinateReferenceSystem crs READ crs WRITE setCrs NOTIFY crsChanged )
80 Q_PROPERTY( QgsMapLayerType type READ type CONSTANT )
81 Q_PROPERTY( bool isValid READ isValid NOTIFY isValidChanged )
82 Q_PROPERTY( double opacity READ opacity WRITE setOpacity NOTIFY opacityChanged )
83 Q_PROPERTY( QString mapTipTemplate READ mapTipTemplate WRITE setMapTipTemplate NOTIFY mapTipTemplateChanged )
84
85#ifdef SIP_RUN
87 QgsMapLayer *layer = qobject_cast<QgsMapLayer *>( sipCpp );
88
89 sipType = 0;
90
91 if ( layer )
92 {
93 switch ( layer->type() )
94 {
96 sipType = sipType_QgsVectorLayer;
97 break;
99 sipType = sipType_QgsRasterLayer;
100 break;
102 sipType = sipType_QgsPluginLayer;
103 break;
105 sipType = sipType_QgsMeshLayer;
106 break;
108 sipType = sipType_QgsVectorTileLayer;
109 break;
111 sipType = sipType_QgsAnnotationLayer;
112 break;
114 sipType = sipType_QgsPointCloudLayer;
115 break;
117 sipType = sipType_QgsGroupLayer;
118 break;
119 default:
120 sipType = nullptr;
121 break;
122 }
123 }
124 SIP_END
125#endif
126
127 public:
128
134 {
135 Style = 0,
137 };
138
145 {
146 Identifiable = 1 << 0,
147 Removable = 1 << 1,
148 Searchable = 1 << 2,
149 Private = 1 << 3,
150 };
151 Q_ENUM( LayerFlag )
152 Q_DECLARE_FLAGS( LayerFlags, LayerFlag )
153 Q_FLAG( LayerFlags )
154
155
160 {
161 LayerConfiguration = 1 << 0,
162 Symbology = 1 << 1,
163 Symbology3D = 1 << 2,
164 Labeling = 1 << 3,
165 Fields = 1 << 4,
166 Forms = 1 << 5,
167 Actions = 1 << 6,
168 MapTips = 1 << 7,
169 Diagrams = 1 << 8,
170 AttributeTable = 1 << 9,
171 Rendering = 1 << 10,
172 CustomProperties = 1 << 11,
173 GeometryOptions = 1 << 12,
174 Relations = 1 << 13,
175 Temporal = 1 << 14,
176 Legend = 1 << 15,
177 Elevation = 1 << 16,
178 Notes = 1 << 17,
179 AllStyleCategories = LayerConfiguration | Symbology | Symbology3D | Labeling | Fields | Forms | Actions |
180 MapTips | Diagrams | AttributeTable | Rendering | CustomProperties | GeometryOptions | Relations | Temporal | Legend | Elevation | Notes,
181 };
182 Q_ENUM( StyleCategory )
183 Q_DECLARE_FLAGS( StyleCategories, StyleCategory )
184 Q_FLAG( StyleCategories )
185
186
192 QgsMapLayer( QgsMapLayerType type = QgsMapLayerType::VectorLayer, const QString &name = QString(), const QString &source = QString() );
193
194 ~QgsMapLayer() override;
195
197 QgsMapLayer( QgsMapLayer const & ) = delete;
199 QgsMapLayer &operator=( QgsMapLayer const & ) = delete;
200
207 virtual QgsMapLayer *clone() const = 0;
208
212 QgsMapLayerType type() const;
213
224 QgsMapLayer::LayerFlags flags() const;
225
236 void setFlags( QgsMapLayer::LayerFlags flags );
237
247 virtual Qgis::MapLayerProperties properties() const;
248
254 static QString extensionPropertyType( PropertyType type );
255
257 QString id() const;
258
264 void setName( const QString &name );
265
270 QString name() const;
271
275 Q_INVOKABLE virtual QgsDataProvider *dataProvider();
276
281 virtual const QgsDataProvider *dataProvider() const SIP_SKIP;
282
288 void setShortName( const QString &shortName ) { mShortName = shortName; }
289
295 QString shortName() const;
296
302 void setTitle( const QString &title ) { mTitle = title; }
303
310 QString title() const { return mTitle; }
311
317 void setAbstract( const QString &abstract ) { mAbstract = abstract; }
318
325 QString abstract() const { return mAbstract; }
326
332 void setKeywordList( const QString &keywords ) { mKeywordList = keywords; }
333
340 QString keywordList() const { return mKeywordList; }
341
342 /* Layer dataUrl information */
343
350 void setDataUrl( const QString &dataUrl ) { mDataUrl = dataUrl; }
351
359 QString dataUrl() const { return mDataUrl; }
360
367 void setDataUrlFormat( const QString &dataUrlFormat ) { mDataUrlFormat = dataUrlFormat; }
368
376 QString dataUrlFormat() const { return mDataUrlFormat; }
377
378 /* Layer attribution information */
379
386 void setAttribution( const QString &attrib ) { mAttribution = attrib; }
387
395 QString attribution() const { return mAttribution; }
396
403 void setAttributionUrl( const QString &attribUrl ) { mAttributionUrl = attribUrl; }
404
412 QString attributionUrl() const { return mAttributionUrl; }
413
414 /* Layer metadataUrl information */
415
420 QgsMapLayerServerProperties *serverProperties() { return mServerProperties.get(); };
421
426 const QgsMapLayerServerProperties *serverProperties() const { return mServerProperties.get(); } SIP_SKIP;
427
436 Q_DECL_DEPRECATED void setMetadataUrl( const QString &metaUrl ) SIP_DEPRECATED;
437
447 Q_DECL_DEPRECATED QString metadataUrl() const SIP_DEPRECATED;
448
457 Q_DECL_DEPRECATED void setMetadataUrlType( const QString &metaUrlType ) SIP_DEPRECATED;
458
468 Q_DECL_DEPRECATED QString metadataUrlType() const SIP_DEPRECATED;
469
478 Q_DECL_DEPRECATED void setMetadataUrlFormat( const QString &metaUrlFormat ) SIP_DEPRECATED;
479
489 Q_DECL_DEPRECATED QString metadataUrlFormat() const SIP_DEPRECATED;
490
496 void setBlendMode( QPainter::CompositionMode blendMode );
497
502 QPainter::CompositionMode blendMode() const;
503
512 virtual void setOpacity( double opacity );
513
522 virtual double opacity() const;
523
525 bool readOnly() const { return isReadOnly(); }
526
530 Q_INVOKABLE virtual void reload() {}
531
537
539 virtual QgsRectangle extent() const;
540
549 QgsRectangle wgs84Extent( bool forceRecalculate = false ) const;
550
556 bool isValid() const;
557
564 QString publicSource() const;
565
571 QString source() const;
572
577 virtual QStringList subLayers() const;
578
583 virtual void setLayerOrder( const QStringList &layers );
584
590 virtual void setSubLayerVisibility( const QString &name, bool visible );
591
598 virtual bool supportsEditing() const;
599
601 virtual bool isEditable() const;
602
608 virtual bool isModified() const;
609
614 virtual bool isSpatial() const;
615
625 virtual bool isTemporary() const;
626
632 {
633 FlagDontResolveLayers = 1 << 0,
634 FlagTrustLayerMetadata = 1 << 1,
635 FlagReadExtentFromXml = 1 << 2,
636 FlagForceReadOnly = 1 << 3,
637 };
638 Q_DECLARE_FLAGS( ReadFlags, ReadFlag )
639
640
657 bool readLayerXml( const QDomElement &layerElement, QgsReadWriteContext &context, QgsMapLayer::ReadFlags flags = QgsMapLayer::ReadFlags() );
658
676 bool writeLayerXml( QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context ) const;
677
682 virtual void resolveReferences( QgsProject *project );
683
689 Q_INVOKABLE QStringList customPropertyKeys() const;
690
696 Q_INVOKABLE void setCustomProperty( const QString &key, const QVariant &value );
697
702 Q_INVOKABLE QVariant customProperty( const QString &value, const QVariant &defaultValue = QVariant() ) const;
703
708 void setCustomProperties( const QgsObjectCustomProperties &properties );
709
715 const QgsObjectCustomProperties &customProperties() const;
716
717#ifndef SIP_RUN
718
729 template <class T>
730 T customEnumProperty( const QString &key, const T &defaultValue )
731 {
732 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
733 Q_ASSERT( metaEnum.isValid() );
734 if ( !metaEnum.isValid() )
735 {
736 QgsDebugMsg( QStringLiteral( "Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
737 }
738
739 T v;
740 bool ok = false;
741
742 if ( metaEnum.isValid() )
743 {
744 // read as string
745 QByteArray ba = customProperty( key, metaEnum.valueToKey( static_cast<int>( defaultValue ) ) ).toString().toUtf8();
746 const char *vs = ba.data();
747 v = static_cast<T>( metaEnum.keyToValue( vs, &ok ) );
748 if ( ok )
749 return v;
750 }
751
752 // if failed, try to read as int (old behavior)
753 // this code shall be removed later
754 // then the method could be marked as const
755 v = static_cast<T>( customProperty( key, static_cast<int>( defaultValue ) ).toInt( &ok ) );
756 if ( metaEnum.isValid() )
757 {
758 if ( !ok || !metaEnum.valueToKey( static_cast<int>( v ) ) )
759 {
760 v = defaultValue;
761 }
762 else
763 {
764 // found property as an integer
765 // convert the property to the new form (string)
766 setCustomEnumProperty( key, v );
767 }
768 }
769
770 return v;
771 }
772
781 template <class T>
782 void setCustomEnumProperty( const QString &key, const T &value )
783 {
784 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
785 Q_ASSERT( metaEnum.isValid() );
786 if ( metaEnum.isValid() )
787 {
788 setCustomProperty( key, metaEnum.valueToKey( static_cast<int>( value ) ) );
789 }
790 else
791 {
792 QgsDebugMsg( QStringLiteral( "Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
793 }
794 }
795
807 template <class T>
808 T customFlagProperty( const QString &key, const T &defaultValue )
809 {
810 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
811 Q_ASSERT( metaEnum.isValid() );
812 if ( !metaEnum.isValid() )
813 {
814 QgsDebugMsg( QStringLiteral( "Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
815 }
816
817 T v = defaultValue;
818 bool ok = false;
819
820 if ( metaEnum.isValid() )
821 {
822 // read as string
823 QByteArray ba = customProperty( key, metaEnum.valueToKeys( defaultValue ) ).toString().toUtf8();
824 const char *vs = ba.data();
825 v = static_cast<T>( metaEnum.keysToValue( vs, &ok ) );
826 }
827 if ( !ok )
828 {
829 // if failed, try to read as int
830 const int intValue = customProperty( key, static_cast<int>( defaultValue ) ).toInt( &ok );
831 if ( metaEnum.isValid() )
832 {
833 if ( ok )
834 {
835 // check that the int value does correspond to a flag
836 // see https://stackoverflow.com/a/68495949/1548052
837 const QByteArray keys = metaEnum.valueToKeys( intValue );
838 const int intValueCheck = metaEnum.keysToValue( keys );
839 if ( intValue != intValueCheck )
840 {
841 v = defaultValue;
842 }
843 else
844 {
845 // found property as an integer
846 v = T( intValue );
847 // convert the property to the new form (string)
848 // this code could be removed
849 // then the method could be marked as const
850 setCustomFlagProperty( key, v );
851 }
852 }
853 else
854 {
855 v = defaultValue;
856 }
857 }
858 }
859
860 return v;
861 }
862
871 template <class T>
872 void setCustomFlagProperty( const QString &key, const T &value )
873 {
874 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
875 Q_ASSERT( metaEnum.isValid() );
876 if ( metaEnum.isValid() )
877 {
878 setCustomProperty( key, metaEnum.valueToKeys( value ) );
879 }
880 else
881 {
882 QgsDebugMsg( QStringLiteral( "Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
883 }
884 }
885#endif
886
887
892 void removeCustomProperty( const QString &key );
893
899 virtual QgsError error() const;
900
906
908 void setCrs( const QgsCoordinateReferenceSystem &srs, bool emitSignal = true );
909
915 QgsCoordinateTransformContext transformContext( ) const;
916
917
923 static QString formatLayerName( const QString &name );
924
932 virtual QString metadataUri() const;
933
940 void exportNamedMetadata( QDomDocument &doc, QString &errorMsg ) const;
941
951 virtual QString saveDefaultMetadata( bool &resultFlag SIP_OUT );
952
967 QString saveNamedMetadata( const QString &uri, bool &resultFlag );
968
983 virtual QString loadNamedMetadata( const QString &uri, bool &resultFlag SIP_OUT );
984
994 virtual QString loadDefaultMetadata( bool &resultFlag );
995
1004 bool loadNamedMetadataFromDatabase( const QString &db, const QString &uri, QString &qmd );
1005
1013 bool importNamedMetadata( QDomDocument &document, QString &errorMessage );
1014
1023 virtual QString styleURI() const;
1024
1034 virtual QString loadDefaultStyle( bool &resultFlag SIP_OUT );
1035
1051 virtual QString loadNamedStyle( const QString &uri, bool &resultFlag SIP_OUT, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories );
1052
1060 virtual bool loadNamedStyleFromDatabase( const QString &db, const QString &uri, QString &qml SIP_OUT );
1061
1071 virtual bool importNamedStyle( QDomDocument &doc, QString &errorMsg SIP_OUT,
1072 QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories );
1073
1082 virtual void exportNamedStyle( QDomDocument &doc, QString &errorMsg SIP_OUT, const QgsReadWriteContext &context = QgsReadWriteContext(),
1083 QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) const;
1084
1085
1093 virtual void exportSldStyle( QDomDocument &doc, QString &errorMsg ) const;
1094
1103 virtual void exportSldStyleV2( QDomDocument &doc, QString &errorMsg, const QgsSldExportContext &exportContext ) const;
1104
1116 virtual QString saveDefaultStyle( bool &resultFlag SIP_OUT, StyleCategories categories );
1117
1129 Q_DECL_DEPRECATED virtual QString saveDefaultStyle( bool &resultFlag SIP_OUT ) SIP_DEPRECATED;
1130
1146 virtual QString saveNamedStyle( const QString &uri, bool &resultFlag SIP_OUT, StyleCategories categories = AllStyleCategories );
1147
1157 virtual QString saveSldStyle( const QString &uri, bool &resultFlag ) const;
1158
1169 virtual QString saveSldStyleV2( bool &resultFlag SIP_OUT, const QgsSldExportContext &exportContext ) const;
1170
1179 virtual QString loadSldStyle( const QString &uri, bool &resultFlag );
1180
1181 virtual bool readSld( const QDomNode &node, QString &errorMessage )
1182 { Q_UNUSED( node ) errorMessage = QStringLiteral( "Layer type %1 not supported" ).arg( static_cast<int>( type() ) ); return false; }
1183
1184
1185
1194 virtual bool readSymbology( const QDomNode &node, QString &errorMessage,
1195 QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories ) = 0;
1196
1207 virtual bool readStyle( const QDomNode &node, QString &errorMessage,
1208 QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories );
1209
1220 virtual bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context,
1221 StyleCategories categories = AllStyleCategories ) const = 0;
1222
1235 virtual bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context,
1236 StyleCategories categories = AllStyleCategories ) const;
1237
1238
1253 void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, bool loadDefaultStyleFlag = false );
1254
1268 void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, bool loadDefaultStyleFlag = false );
1269
1284 void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags );
1285
1289 QString providerType() const;
1290
1292 QUndoStack *undoStack();
1293
1298 QUndoStack *undoStackStyles();
1299
1303 void setLegendUrl( const QString &legendUrl ) { mLegendUrl = legendUrl; }
1304
1308 QString legendUrl() const { return mLegendUrl; }
1309
1313 void setLegendUrlFormat( const QString &legendUrlFormat ) { mLegendUrlFormat = legendUrlFormat; }
1314
1318 QString legendUrlFormat() const { return mLegendUrlFormat; }
1319
1325 void setLegend( QgsMapLayerLegend *legend SIP_TRANSFER );
1326
1331 QgsMapLayerLegend *legend() const;
1332
1337 QgsMapLayerStyleManager *styleManager() const;
1338
1343 void setRenderer3D( QgsAbstract3DRenderer *renderer SIP_TRANSFER );
1344
1349 QgsAbstract3DRenderer *renderer3D() const;
1350
1360 bool isInScaleRange( double scale ) const;
1361
1372 double minimumScale() const;
1373
1384 double maximumScale() const;
1385
1394 bool hasScaleBasedVisibility() const;
1395
1402 bool hasAutoRefreshEnabled() const;
1403
1411 int autoRefreshInterval() const;
1412
1424 void setAutoRefreshInterval( int interval );
1425
1432 void setAutoRefreshEnabled( bool enabled );
1433
1440 virtual const QgsLayerMetadata &metadata() const;
1441
1448 virtual void setMetadata( const QgsLayerMetadata &metadata );
1449
1454 virtual QString htmlMetadata() const;
1455
1457 virtual QDateTime timestamp() const;
1458
1466 virtual QSet<QgsMapLayerDependency> dependencies() const;
1467
1473 QString refreshOnNotifyMessage() const { return mRefreshOnNofifyMessage; }
1474
1480 bool isRefreshOnNotifyEnabled() const { return mIsRefreshOnNofifyEnabled; }
1481
1490 QString originalXmlProperties() const;
1491
1499 void setOriginalXmlProperties( const QString &originalXmlProperties );
1500
1505 static QString generateId( const QString &layerName );
1506
1516 virtual bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
1517
1524
1531
1537 QString legendPlaceholderImage() const { return mLegendPlaceholderImage;}
1538
1544 void setLegendPlaceholderImage( const QString &imgPath ) { mLegendPlaceholderImage = imgPath; }
1545
1554 QString mapTipTemplate() const;
1555
1564 void setMapTipTemplate( const QString &mapTipTemplate );
1565
1566
1567 public slots:
1568
1578 void setMinimumScale( double scale );
1579
1589 void setMaximumScale( double scale );
1590
1598 void setScaleBasedVisibility( bool enabled );
1599
1608 void triggerRepaint( bool deferredUpdate = false );
1609
1616 void trigger3DUpdate();
1617
1622 void emitStyleChanged();
1623
1632 virtual bool setDependencies( const QSet<QgsMapLayerDependency> &layers );
1633
1639 void setRefreshOnNotifyEnabled( bool enabled );
1640
1648 void setRefreshOnNofifyMessage( const QString &message ) { mRefreshOnNofifyMessage = message; }
1649
1655 virtual void setTransformContext( const QgsCoordinateTransformContext &transformContext ) = 0;
1656
1657#ifdef SIP_RUN
1658 SIP_PYOBJECT __repr__();
1659 % MethodCode
1660 QString str = QStringLiteral( "<QgsMapLayer: '%1' (%2)>" ).arg( sipCpp->name(), sipCpp->dataProvider() ? sipCpp->dataProvider()->name() : QStringLiteral( "Invalid" ) );
1661 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
1662 % End
1663#endif
1664
1671 QgsProject *project() const;
1672
1673 signals:
1674
1682
1684 void statusChanged( const QString &status );
1685
1692
1695
1702 void repaintRequested( bool deferredUpdate = false );
1703
1706
1709
1711 void blendModeChanged( QPainter::CompositionMode blendMode );
1712
1721 void opacityChanged( double opacity );
1722
1728
1741
1747
1753
1760
1766
1771
1779
1785 void autoRefreshIntervalChanged( int interval );
1786
1794
1802
1811
1817 void styleLoaded( QgsMapLayer::StyleCategories categories );
1818
1825
1831 void customPropertyChanged( const QString &key );
1832
1838
1844
1850
1858
1859 private slots:
1860
1861 void onNotified( const QString &message );
1862
1878 virtual void setDataSourcePrivate( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags );
1879
1880 protected:
1881
1887 void clone( QgsMapLayer *layer ) const;
1888
1890 virtual void setExtent( const QgsRectangle &rect );
1891
1893 void setValid( bool valid );
1894
1899 virtual bool readXml( const QDomNode &layer_node, QgsReadWriteContext &context );
1900
1905 virtual bool writeXml( QDomNode &layer_node, QDomDocument &document, const QgsReadWriteContext &context ) const;
1906
1918 virtual QString encodedSource( const QString &source, const QgsReadWriteContext &context ) const;
1919
1932 virtual QString decodedSource( const QString &source, const QString &dataProvider, const QgsReadWriteContext &context ) const;
1933
1939 void readCustomProperties( const QDomNode &layerNode, const QString &keyStartsWith = QString() );
1940
1942 void writeCustomProperties( QDomNode &layerNode, QDomDocument &doc ) const;
1943
1945 void readStyleManager( const QDomNode &layerNode );
1947 void writeStyleManager( QDomNode &layerNode, QDomDocument &doc ) const;
1948
1953 void writeCommonStyle( QDomElement &layerElement, QDomDocument &document,
1954 const QgsReadWriteContext &context,
1955 StyleCategories categories = AllStyleCategories ) const;
1956
1961 void readCommonStyle( const QDomElement &layerElement, const QgsReadWriteContext &context,
1962 StyleCategories categories = AllStyleCategories );
1963
1965 void setProviderType( const QString &providerType );
1966
1967#ifndef SIP_RUN
1968#if 0
1970 void connectNotify( const char *signal ) override;
1971#endif
1972#endif
1973
1975 void appendError( const QgsErrorMessage &error ) { mError.append( error );}
1977 void setError( const QgsError &error ) { mError = error;}
1978
1985 void invalidateWgs84Extent();
1986
1988 bool mValid = false;
1989
1992
1994 QString mLayerName;
1995
1996 QString mShortName;
1997 QString mTitle;
1998
2000 QString mAbstract;
2002
2004 QString mDataUrl;
2006
2010
2012 QString mLegendUrl;
2014
2017
2019 QSet<QgsMapLayerDependency> mDependencies;
2020
2026 Q_DECL_DEPRECATED bool hasDependencyCycle( const QSet<QgsMapLayerDependency> & ) const {return false;}
2027
2028 bool mIsRefreshOnNofifyEnabled = false;
2030
2033
2034 //TODO QGIS 4 - move to readXml as a new argument (breaks API)
2035
2037 QgsMapLayer::ReadFlags mReadFlags = QgsMapLayer::ReadFlags();
2038
2044 bool mShouldValidateCrs = true;
2045
2051 double mLayerOpacity = 1.0;
2052
2058 int mBlockStyleChangedSignal = 0;
2059
2060#ifndef SIP_RUN
2061
2070 QString crsHtmlMetadata() const;
2071#endif
2072
2073#ifndef SIP_RUN
2074
2083 QString generalHtmlMetadata() const;
2084#endif
2085
2086 private:
2087
2088 virtual QString baseURI( PropertyType type ) const;
2089 QString saveNamedProperty( const QString &uri, QgsMapLayer::PropertyType type,
2090 bool &resultFlag, StyleCategories categories = AllStyleCategories );
2091 QString loadNamedProperty( const QString &uri, QgsMapLayer::PropertyType type,
2092 bool &resultFlag, StyleCategories categories = AllStyleCategories );
2093 bool loadNamedPropertyFromDatabase( const QString &db, const QString &uri, QString &xml, QgsMapLayer::PropertyType type );
2094
2095 // const method because extents are mutable
2096 void updateExtent( const QgsRectangle &extent ) const;
2097
2102 virtual bool isReadOnly() const;
2103
2109
2111 QString mID;
2112
2114 QgsMapLayerType mLayerType;
2115
2116 LayerFlags mFlags = LayerFlags( Identifiable | Removable | Searchable );
2117
2119 QPainter::CompositionMode mBlendMode = QPainter::CompositionMode_SourceOver;
2120
2122 QString mTag;
2123
2124 //set some generous defaults for scale based visibility
2125
2127 double mMinScale = 0;
2129 double mMaxScale = 100000000;
2131 bool mScaleBasedVisibility = false;
2132
2136 std::unique_ptr< QgsMapLayerServerProperties > mServerProperties;
2137
2139 QUndoStack *mUndoStack = nullptr;
2140
2141 QUndoStack *mUndoStackStyles = nullptr;
2142
2144 QgsObjectCustomProperties mCustomProperties;
2145
2147 QgsMapLayerLegend *mLegend = nullptr;
2148
2150 QgsMapLayerStyleManager *mStyleManager = nullptr;
2151
2153 QTimer *mRefreshTimer = nullptr;
2154
2155 QgsLayerMetadata mMetadata;
2156
2158 QgsAbstract3DRenderer *m3DRenderer = nullptr;
2159
2161 mutable QgsRectangle mExtent;
2162
2164 mutable QgsRectangle mWgs84Extent;
2165
2171 QString mOriginalXmlProperties;
2172
2174 bool mRepaintRequestedFired = false;
2175
2177 QString mLegendPlaceholderImage;
2178
2180 QString mMapTipTemplate;
2181
2182 friend class QgsVectorLayer;
2183 friend class TestQgsMapLayer;
2184};
2185
2187Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapLayer::LayerFlags )
2188Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapLayer::StyleCategories )
2189Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapLayer::ReadFlags )
2190
2191
2192#ifndef SIP_RUN
2193
2199typedef QPointer< QgsMapLayer > QgsWeakMapLayerPointer;
2200
2206typedef QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList;
2207#endif
2208
2209#endif
Base class for all renderers that may to participate in 3D view.
This class represents a coordinate reference system (CRS).
Contains information about the context in which a coordinate transform is executed.
Abstract base class for spatial data provider implementations.
QgsErrorMessage represents single error message.
Definition: qgserror.h:33
QgsError is container for error messages (report).
Definition: qgserror.h:81
A structured metadata store for a map layer.
Base class for storage of map layer elevation properties.
The QgsMapLayerLegend class is abstract interface for implementations of legends for one map layer.
Base class for utility classes that encapsulate information necessary for rendering of map layers.
Manages QGIS Server properties for a map layer.
Management of styles for use with one map layer.
Base class for storage of map layer temporal properties.
Base class for all map layer types.
Definition: qgsmaplayer.h:73
QString mKeywordList
Definition: qgsmaplayer.h:2001
virtual bool writeSymbology(QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories) const =0
Write the style for the layer into the document provided.
QString legendUrlFormat() const
Returns the format for a URL based layer legend.
Definition: qgsmaplayer.h:1318
void dependenciesChanged()
Emitted when dependencies are changed.
void setError(const QgsError &error)
Sets error message.
Definition: qgsmaplayer.h:1977
void legendChanged()
Signal emitted when legend of the layer has changed.
void setAbstract(const QString &abstract)
Sets the abstract of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:317
void editingStopped()
Emitted when edited changes have been successfully written to the data provider.
void recalculateExtents() const
This is used to send a request that any mapcanvas using this layer update its extents.
void metadataChanged()
Emitted when the layer's metadata is changed.
void setLegendUrl(const QString &legendUrl)
Sets the URL for the layer's legend.
Definition: qgsmaplayer.h:1303
void request3DUpdate()
Signal emitted when a layer requires an update in any 3D maps.
QgsError mError
Error.
Definition: qgsmaplayer.h:2016
void configChanged()
Emitted whenever the configuration is changed.
void autoRefreshIntervalChanged(int interval)
Emitted when the auto refresh interval changes.
T customFlagProperty(const QString &key, const T &defaultValue)
Returns the property value for a property based on a flag.
Definition: qgsmaplayer.h:808
Q_DECL_DEPRECATED bool hasDependencyCycle(const QSet< QgsMapLayerDependency > &) const
Checks whether a new set of dependencies will introduce a cycle this method is now deprecated and alw...
Definition: qgsmaplayer.h:2026
void editingStarted()
Emitted when editing on this layer has started.
void isValidChanged()
Emitted when the validity of this layer changed.
QString legendPlaceholderImage() const
Returns path to the placeholder image or an empty string if a generated legend is shown.
Definition: qgsmaplayer.h:1537
QgsMapLayerServerProperties * serverProperties()
Returns QGIS Server Properties for the map layer.
Definition: qgsmaplayer.h:420
QString attribution() const
Returns the attribution of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:395
QString mRefreshOnNofifyMessage
Definition: qgsmaplayer.h:2029
QString mLegendUrl
WMS legend.
Definition: qgsmaplayer.h:2012
QString mLayerName
Name of the layer - used for display.
Definition: qgsmaplayer.h:1994
void setCustomFlagProperty(const QString &key, const T &value)
Set the value of a property based on a flag.
Definition: qgsmaplayer.h:872
void mapTipTemplateChanged()
Emitted when the map tip template changes.
void setAttributionUrl(const QString &attribUrl)
Sets the attribution URL of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:403
void renderer3DChanged()
Signal emitted when 3D renderer associated with the layer has changed.
QString abstract() const
Returns the abstract of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:325
QString dataUrlFormat() const
Returns the DataUrl format of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:376
void statusChanged(const QString &status)
Emit a signal with status (e.g. to be caught by QgisApp and display a msg on status bar)
QString mTitle
Definition: qgsmaplayer.h:1997
void setDataUrl(const QString &dataUrl)
Sets the DataUrl of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:350
QgsMapLayer(QgsMapLayer const &)=delete
QgsMapLayer cannot be copied.
void setKeywordList(const QString &keywords)
Sets the keyword list of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:332
void setAttribution(const QString &attrib)
Sets the attribution of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:386
bool isRefreshOnNotifyEnabled() const
Returns true if the refresh on provider nofification is enabled.
Definition: qgsmaplayer.h:1480
QSet< QgsMapLayerDependency > mDependencies
List of layers that may modify this layer on modification.
Definition: qgsmaplayer.h:2019
void setDataUrlFormat(const QString &dataUrlFormat)
Sets the DataUrl format of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:367
QString mLegendUrlFormat
Definition: qgsmaplayer.h:2013
const QgsMapLayerServerProperties * serverProperties() const
Returns QGIS Server Properties const for the map layer.
Definition: qgsmaplayer.h:426
QString mProviderKey
Data provider key (name of the data provider)
Definition: qgsmaplayer.h:2032
void styleChanged()
Signal emitted whenever a change affects the layer's style.
void rendererChanged()
Signal emitted when renderer is changed.
QString title() const
Returns the title of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:310
void crsChanged()
Emit a signal that layer's CRS has been reset.
QString mAttributionUrl
Definition: qgsmaplayer.h:2009
void dataSourceChanged()
Emitted whenever the layer's data source has been changed.
QString dataUrl() const
Returns the DataUrl of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:359
QgsMapLayer & operator=(QgsMapLayer const &)=delete
QgsMapLayer cannot be copied.
void setRefreshOnNofifyMessage(const QString &message)
Set the notification message that triggers repaint If refresh on notification is enabled,...
Definition: qgsmaplayer.h:1648
void opacityChanged(double opacity)
Emitted when the layer's opacity is changed, where opacity is a value between 0 (transparent) and 1 (...
void styleLoaded(QgsMapLayer::StyleCategories categories)
Emitted when a style has been loaded.
virtual QgsMapLayerTemporalProperties * temporalProperties()
Returns the layer's temporal properties.
Definition: qgsmaplayer.h:1523
QString mShortName
Definition: qgsmaplayer.h:1996
void dataChanged()
Data of layer changed.
virtual QgsMapLayerRenderer * createMapRenderer(QgsRenderContext &rendererContext)=0
Returns new instance of QgsMapLayerRenderer that will be used for rendering of given context.
void willBeDeleted()
Emitted in the destructor when the layer is about to be deleted, but it is still in a perfectly valid...
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 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.
LayerFlag
Flags for the map layer.
Definition: qgsmaplayer.h:145
void setLegendPlaceholderImage(const QString &imgPath)
Set placeholder image for legend.
Definition: qgsmaplayer.h:1544
void appendError(const QgsErrorMessage &error)
Add error message.
Definition: qgsmaplayer.h:1975
QString mDataSource
Data source description string, varies by layer type.
Definition: qgsmaplayer.h:1991
QString refreshOnNotifyMessage() const
Returns the message that should be notified by the provider to triggerRepaint.
Definition: qgsmaplayer.h:1473
virtual bool readSld(const QDomNode &node, QString &errorMessage)
Definition: qgsmaplayer.h:1181
ReadFlag
Flags which control project read behavior.
Definition: qgsmaplayer.h:632
QString attributionUrl() const
Returns the attribution URL of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:412
QString mAbstract
Description of the layer.
Definition: qgsmaplayer.h:2000
void customPropertyChanged(const QString &key)
Emitted when a custom property of the layer has been changed or removed.
QString legendUrl() const
Returns the URL for the layer's legend.
Definition: qgsmaplayer.h:1308
QString mDataUrlFormat
Definition: qgsmaplayer.h:2005
void flagsChanged()
Emitted when layer's flags have been modified.
void repaintRequested(bool deferredUpdate=false)
By emitting this signal the layer tells that either appearance or content have been changed and any v...
void setLegendUrlFormat(const QString &legendUrlFormat)
Sets the format for a URL based layer legend.
Definition: qgsmaplayer.h:1313
void beforeResolveReferences(QgsProject *project)
Emitted when all layers are loaded and references can be resolved, just before the references of this...
virtual QgsMapLayerElevationProperties * elevationProperties()
Returns the layer's elevation properties.
Definition: qgsmaplayer.h:1530
virtual void setTransformContext(const QgsCoordinateTransformContext &transformContext)=0
Sets the coordinate transform context to transformContext.
void nameChanged()
Emitted when the name has been changed.
QString mDataUrl
DataUrl of the layer.
Definition: qgsmaplayer.h:2004
T customEnumProperty(const QString &key, const T &defaultValue)
Returns the property value for a property based on an enum.
Definition: qgsmaplayer.h:730
StyleCategory
Categories of style to distinguish appropriate sections for import/export.
Definition: qgsmaplayer.h:160
@ AllStyleCategories
Definition: qgsmaplayer.h:179
void layerModified()
Emitted when modifications has been done on layer.
virtual Q_INVOKABLE void reload()
Synchronises with changes in the datasource.
Definition: qgsmaplayer.h:530
QString mAttribution
Attribution of the layer.
Definition: qgsmaplayer.h:2008
void setCustomEnumProperty(const QString &key, const T &value)
Set the value of a property based on an enum.
Definition: qgsmaplayer.h:782
QString keywordList() const
Returns the keyword list of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:340
void setTitle(const QString &title)
Sets the title of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:302
PropertyType
Maplayer has a style and a metadata property.
Definition: qgsmaplayer.h:134
Simple key-value store (keys = strings, values = variants) that supports loading/saving to/from XML i...
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:105
The class is used as a container of context for various read/write operations on other objects.
A rectangle specified with double values.
Definition: qgsrectangle.h:42
Contains information about the context of a rendering operation.
The QgsSldExportContext class holds SLD export options and other information related to SLD export of...
An interface for classes which can visit style entity (e.g.
Represents a vector layer which manages a vector based data sets.
QgsMapLayerType
Types of layers that can be added to a map.
Definition: qgis.h:47
@ PointCloudLayer
Point cloud layer. Added in QGIS 3.18.
@ MeshLayer
Mesh layer. Added in QGIS 3.2.
@ VectorLayer
Vector layer.
@ RasterLayer
Raster layer.
@ GroupLayer
Composite group layer. Added in QGIS 3.24.
@ VectorTileLayer
Vector tile layer. Added in QGIS 3.14.
@ AnnotationLayer
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
@ PluginLayer
Plugin based layer.
#define str(x)
Definition: qgis.cpp:37
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:186
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_OUT
Definition: qgis_sip.h:58
#define SIP_FACTORY
Definition: qgis_sip.h:76
#define SIP_END
Definition: qgis_sip.h:203
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsField::ConfigurationFlags) CORE_EXPORT QDataStream &operator<<(QDataStream &out
Writes the field to stream out. QGIS version compatibility is not guaranteed.
#define QgsDebugMsg(str)
Definition: qgslogger.h:38
QPointer< QgsMapLayer > QgsWeakMapLayerPointer
Weak pointer for QgsMapLayer.
Definition: qgsmaplayer.h:2199
QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList
A list of weak pointers to QgsMapLayers.
Definition: qgsmaplayer.h:2206
const QgsCoordinateReferenceSystem & crs
Setting options for creating vector data providers.