QGIS API Documentation 3.43.0-Master (56aa1fd18d7)
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;
57
58class QDomDocument;
59class QKeyEvent;
60class QPainter;
62class QgsBox3D;
63
64/*
65 * Constants used to describe copy-paste MIME types
66 */
67#define QGSCLIPBOARD_MAPLAYER_MIME "application/qgis.maplayer"
68
69
76class CORE_EXPORT QgsMapLayer : public QObject
77{
78 Q_OBJECT
79
80 Q_PROPERTY( QString id READ id WRITE setId NOTIFY idChanged )
81 Q_PROPERTY( QString name READ name WRITE setName NOTIFY nameChanged )
82 Q_PROPERTY( int autoRefreshInterval READ autoRefreshInterval WRITE setAutoRefreshInterval NOTIFY autoRefreshIntervalChanged )
83 Q_PROPERTY( QgsLayerMetadata metadata READ metadata WRITE setMetadata NOTIFY metadataChanged )
84 Q_PROPERTY( QgsCoordinateReferenceSystem crs READ crs WRITE setCrs NOTIFY crsChanged )
85 Q_PROPERTY( QgsCoordinateReferenceSystem verticalCrs READ verticalCrs WRITE setVerticalCrs NOTIFY verticalCrsChanged )
86 Q_PROPERTY( QgsCoordinateReferenceSystem crs3D READ crs3D NOTIFY crs3DChanged )
87 Q_PROPERTY( Qgis::LayerType type READ type CONSTANT )
88 Q_PROPERTY( bool isValid READ isValid NOTIFY isValidChanged )
89 Q_PROPERTY( double opacity READ opacity WRITE setOpacity NOTIFY opacityChanged )
90 Q_PROPERTY( QString mapTipTemplate READ mapTipTemplate WRITE setMapTipTemplate NOTIFY mapTipTemplateChanged )
91 Q_PROPERTY( bool mapTipsEnabled READ mapTipsEnabled WRITE setMapTipsEnabled NOTIFY mapTipsEnabledChanged )
92
93#ifdef SIP_RUN
95 QgsMapLayer *layer = qobject_cast<QgsMapLayer *>( sipCpp );
96
97 sipType = 0;
98
99 if ( layer )
100 {
101 switch ( layer->type() )
102 {
104 sipType = sipType_QgsVectorLayer;
105 break;
107 sipType = sipType_QgsRasterLayer;
108 break;
110 sipType = sipType_QgsPluginLayer;
111 break;
113 sipType = sipType_QgsMeshLayer;
114 break;
116 sipType = sipType_QgsVectorTileLayer;
117 break;
119 sipType = sipType_QgsAnnotationLayer;
120 break;
122 sipType = sipType_QgsPointCloudLayer;
123 break;
125 sipType = sipType_QgsGroupLayer;
126 break;
128 sipType = sipType_QgsTiledSceneLayer;
129 break;
130 default:
131 sipType = nullptr;
132 break;
133 }
134 }
135 SIP_END
136#endif
137
138 public:
139
144 {
145 Style = 0,
147 };
148
155 {
156 Identifiable = 1 << 0,
157 Removable = 1 << 1,
158 Searchable = 1 << 2,
159 Private = 1 << 3,
160 };
161 Q_ENUM( LayerFlag )
162 Q_DECLARE_FLAGS( LayerFlags, LayerFlag )
163 Q_FLAG( LayerFlags )
164
170 {
171 LayerConfiguration = 1 << 0,
172 Symbology = 1 << 1,
173 Symbology3D = 1 << 2,
174 Labeling = 1 << 3,
175 Fields = 1 << 4,
176 Forms = 1 << 5,
177 Actions = 1 << 6,
178 MapTips = 1 << 7,
179 Diagrams = 1 << 8,
180 AttributeTable = 1 << 9,
181 Rendering = 1 << 10,
182 CustomProperties = 1 << 11,
183 GeometryOptions = 1 << 12,
184 Relations = 1 << 13,
185 Temporal = 1 << 14,
186 Legend = 1 << 15,
187 Elevation = 1 << 16,
188 Notes = 1 << 17,
189 AllStyleCategories = LayerConfiguration | Symbology | Symbology3D | Labeling | Fields | Forms | Actions |
190 MapTips | Diagrams | AttributeTable | Rendering | CustomProperties | GeometryOptions | Relations | Temporal | Legend | Elevation | Notes,
191 };
192 Q_ENUM( StyleCategory )
193 Q_DECLARE_FLAGS( StyleCategories, StyleCategory )
194 Q_FLAG( StyleCategories )
195
202 QgsMapLayer( Qgis::LayerType type = Qgis::LayerType::Vector, const QString &name = QString(), const QString &source = QString() );
203
204 ~QgsMapLayer() override;
205
206 QgsMapLayer( const QgsMapLayer & ) = delete;
207 QgsMapLayer &operator=( const QgsMapLayer & ) = delete;
208
214 virtual QgsMapLayer *clone() const = 0;
215
219 Qgis::LayerType type() const;
220
231 QgsMapLayer::LayerFlags flags() const;
232
243 void setFlags( QgsMapLayer::LayerFlags flags );
244
254 virtual Qgis::MapLayerProperties properties() const;
255
260 static QString extensionPropertyType( PropertyType type );
261
268 QString id() const;
269
285 bool setId( const QString &id );
286
291 void setName( const QString &name );
292
297 QString name() const;
298
302 Q_INVOKABLE virtual QgsDataProvider *dataProvider();
303
308 virtual const QgsDataProvider *dataProvider() const SIP_SKIP;
309
314 QgsProviderMetadata *providerMetadata() const;
315
321 Q_DECL_DEPRECATED void setShortName( const QString &shortName ) SIP_DEPRECATED;
322
328 Q_DECL_DEPRECATED QString shortName() const SIP_DEPRECATED;
329
335 Q_DECL_DEPRECATED void setTitle( const QString &title ) SIP_DEPRECATED;
336
342 Q_DECL_DEPRECATED QString title() const SIP_DEPRECATED;
343
349 Q_DECL_DEPRECATED void setAbstract( const QString &abstract ) SIP_DEPRECATED;
350
356 Q_DECL_DEPRECATED QString abstract() const SIP_DEPRECATED;
357
363 Q_DECL_DEPRECATED void setKeywordList( const QString &keywords ) SIP_DEPRECATED;
364
370 Q_DECL_DEPRECATED QString keywordList() const SIP_DEPRECATED;
371
377 Q_DECL_DEPRECATED void setDataUrl( const QString &dataUrl ) SIP_DEPRECATED;
378
384 Q_DECL_DEPRECATED QString dataUrl() const SIP_DEPRECATED;
385
391 Q_DECL_DEPRECATED void setDataUrlFormat( const QString &dataUrlFormat ) SIP_DEPRECATED;
392
398 Q_DECL_DEPRECATED QString dataUrlFormat() const SIP_DEPRECATED;
399
405 Q_DECL_DEPRECATED void setAttribution( const QString &attrib ) SIP_DEPRECATED;
406
412 Q_DECL_DEPRECATED QString attribution() const SIP_DEPRECATED;
413
419 Q_DECL_DEPRECATED void setAttributionUrl( const QString &attribUrl ) SIP_DEPRECATED;
420
426 Q_DECL_DEPRECATED QString attributionUrl() const SIP_DEPRECATED;
427
428 /* Layer metadataUrl information */
429
434 QgsMapLayerServerProperties *serverProperties() { return mServerProperties.get(); };
435
440 const QgsMapLayerServerProperties *serverProperties() const { return mServerProperties.get(); } SIP_SKIP;
441
450 Q_DECL_DEPRECATED void setMetadataUrl( const QString &metaUrl ) SIP_DEPRECATED;
451
461 Q_DECL_DEPRECATED QString metadataUrl() const SIP_DEPRECATED;
462
471 Q_DECL_DEPRECATED void setMetadataUrlType( const QString &metaUrlType ) SIP_DEPRECATED;
472
482 Q_DECL_DEPRECATED QString metadataUrlType() const SIP_DEPRECATED;
483
492 Q_DECL_DEPRECATED void setMetadataUrlFormat( const QString &metaUrlFormat ) SIP_DEPRECATED;
493
503 Q_DECL_DEPRECATED QString metadataUrlFormat() const SIP_DEPRECATED;
504
510 void setBlendMode( QPainter::CompositionMode blendMode );
511
516 QPainter::CompositionMode blendMode() const;
517
526 virtual void setOpacity( double opacity );
527
536 virtual double opacity() const;
537
539 bool readOnly() const { return isReadOnly(); }
540
544 Q_INVOKABLE virtual void reload() {}
545
550
552 virtual QgsRectangle extent() const;
553
558 virtual QgsBox3D extent3D() const;
559
568 QgsRectangle wgs84Extent( bool forceRecalculate = false ) const;
569
575 bool isValid() const;
576
577 // TODO QGIS 4.0: consider changing bool hidePassword to an enumeration: HIDE_CREDENTIALS / REDACT_CREDENTIALS
578 // to avoid the ambiguity of the double negation (hide = false)
579
587 QString publicSource( bool hidePassword = false ) const;
588
594 QString source() const;
595
600 virtual QStringList subLayers() const;
601
606 virtual void setLayerOrder( const QStringList &layers );
607
613 virtual void setSubLayerVisibility( const QString &name, bool visible );
614
621 virtual bool supportsEditing() const;
622
624 virtual bool isEditable() const;
625
631 virtual bool isModified() const;
632
636 virtual bool isSpatial() const;
637
647 virtual bool isTemporary() const;
648
654 {
655 FlagDontResolveLayers = 1 << 0,
656 FlagTrustLayerMetadata = 1 << 1,
657 FlagReadExtentFromXml = 1 << 2,
658 FlagForceReadOnly = 1 << 3,
659 };
660 Q_DECLARE_FLAGS( ReadFlags, ReadFlag )
661
662
679 bool readLayerXml( const QDomElement &layerElement, QgsReadWriteContext &context,
680 QgsMapLayer::ReadFlags flags = QgsMapLayer::ReadFlags(), QgsDataProvider *preloadedProvider SIP_TRANSFER = nullptr );
681
697 bool writeLayerXml( QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context ) const;
698
702 virtual void resolveReferences( QgsProject *project );
703
708 Q_INVOKABLE QStringList customPropertyKeys() const;
709
715 Q_INVOKABLE void setCustomProperty( const QString &key, const QVariant &value );
716
721 Q_INVOKABLE QVariant customProperty( const QString &value, const QVariant &defaultValue = QVariant() ) const;
722
726 void setCustomProperties( const QgsObjectCustomProperties &properties );
727
733 const QgsObjectCustomProperties &customProperties() const;
734
744 virtual int listStylesInDatabase( QStringList &ids SIP_OUT, QStringList &names SIP_OUT,
745 QStringList &descriptions SIP_OUT, QString &msgError SIP_OUT );
746
750 virtual QString getStyleFromDatabase( const QString &styleId, QString &msgError SIP_OUT );
751
758 virtual bool deleteStyleFromDatabase( const QString &styleId, QString &msgError SIP_OUT );
759
776 virtual void saveStyleToDatabase( const QString &name, const QString &description,
777 bool useAsDefault, const QString &uiFileContent,
778 QString &msgError SIP_OUT,
780
781
782 // TODO QGIS 4.0 -- fix this. We incorrectly have a single boolean flag which in which false is used inconsistently for "a style WAS found but an error occurred loading it" vs "no style was found".
783 // The first (style found, error occurred loading it) should trigger a user-facing warning, whereas the second (no style found) isn't reflective of an error at all.
784
795 virtual QString loadNamedStyle( const QString &theURI, bool &resultFlag SIP_OUT, bool loadFromLocalDb,
798
799#ifndef SIP_RUN
800
811 template <class T>
812 T customEnumProperty( const QString &key, const T &defaultValue )
813 {
814 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
815 Q_ASSERT( metaEnum.isValid() );
816 if ( !metaEnum.isValid() )
817 {
818 QgsDebugError( QStringLiteral( "Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
819 }
820
821 T v;
822 bool ok = false;
823
824 if ( metaEnum.isValid() )
825 {
826 // read as string
827 QByteArray ba = customProperty( key, metaEnum.valueToKey( static_cast<int>( defaultValue ) ) ).toString().toUtf8();
828 const char *vs = ba.data();
829 v = static_cast<T>( metaEnum.keyToValue( vs, &ok ) );
830 if ( ok )
831 return v;
832 }
833
834 // if failed, try to read as int (old behavior)
835 // this code shall be removed later
836 // then the method could be marked as const
837 v = static_cast<T>( customProperty( key, static_cast<int>( defaultValue ) ).toInt( &ok ) );
838 if ( metaEnum.isValid() )
839 {
840 if ( !ok || !metaEnum.valueToKey( static_cast<int>( v ) ) )
841 {
842 v = defaultValue;
843 }
844 else
845 {
846 // found property as an integer
847 // convert the property to the new form (string)
848 setCustomEnumProperty( key, v );
849 }
850 }
851
852 return v;
853 }
854
863 template <class T>
864 void setCustomEnumProperty( const QString &key, const T &value )
865 {
866 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
867 Q_ASSERT( metaEnum.isValid() );
868 if ( metaEnum.isValid() )
869 {
870 setCustomProperty( key, metaEnum.valueToKey( static_cast<int>( value ) ) );
871 }
872 else
873 {
874 QgsDebugError( QStringLiteral( "Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
875 }
876 }
877
889 template <class T>
890 T customFlagProperty( const QString &key, const T &defaultValue )
891 {
892 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
893 Q_ASSERT( metaEnum.isValid() );
894 if ( !metaEnum.isValid() )
895 {
896 QgsDebugError( QStringLiteral( "Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
897 }
898
899 T v = defaultValue;
900 bool ok = false;
901
902 if ( metaEnum.isValid() )
903 {
904 // read as string
905 QByteArray ba = customProperty( key, metaEnum.valueToKeys( defaultValue ) ).toString().toUtf8();
906 const char *vs = ba.data();
907 v = static_cast<T>( metaEnum.keysToValue( vs, &ok ) );
908 }
909 if ( !ok )
910 {
911 // if failed, try to read as int
912 const int intValue = customProperty( key, static_cast<int>( defaultValue ) ).toInt( &ok );
913 if ( metaEnum.isValid() )
914 {
915 if ( ok )
916 {
917 // check that the int value does correspond to a flag
918 // see https://stackoverflow.com/a/68495949/1548052
919 const QByteArray keys = metaEnum.valueToKeys( intValue );
920 const int intValueCheck = metaEnum.keysToValue( keys );
921 if ( intValue != intValueCheck )
922 {
923 v = defaultValue;
924 }
925 else
926 {
927 // found property as an integer
928 v = T( intValue );
929 // convert the property to the new form (string)
930 // this code could be removed
931 // then the method could be marked as const
932 setCustomFlagProperty( key, v );
933 }
934 }
935 else
936 {
937 v = defaultValue;
938 }
939 }
940 }
941
942 return v;
943 }
944
953 template <class T>
954 void setCustomFlagProperty( const QString &key, const T &value )
955 {
956 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
957 Q_ASSERT( metaEnum.isValid() );
958 if ( metaEnum.isValid() )
959 {
960 setCustomProperty( key, metaEnum.valueToKeys( value ) );
961 }
962 else
963 {
964 QgsDebugError( QStringLiteral( "Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
965 }
966 }
967#endif
968
969
974 void removeCustomProperty( const QString &key );
975
981 virtual QgsError error() const;
982
995
1014 QgsCoordinateReferenceSystem verticalCrs() const;
1015
1034 QgsCoordinateReferenceSystem crs3D() const;
1035
1046 void setCrs( const QgsCoordinateReferenceSystem &srs, bool emitSignal = true );
1047
1067 bool setVerticalCrs( const QgsCoordinateReferenceSystem &crs, QString *errorMessage SIP_OUT = nullptr );
1068
1074 QgsCoordinateTransformContext transformContext( ) const;
1075
1076
1081 static QString formatLayerName( const QString &name );
1082
1089 virtual QString metadataUri() const;
1090
1096 void exportNamedMetadata( QDomDocument &doc, QString &errorMsg ) const;
1097
1106 virtual QString saveDefaultMetadata( bool &resultFlag SIP_OUT );
1107
1121 QString saveNamedMetadata( const QString &uri, bool &resultFlag SIP_OUT );
1122
1123 // TODO QGIS 4.0 -- fix this. We incorrectly have a single boolean flag which in which false is used inconsistently for "metadata WAS found but an error occurred loading it" vs "no metadata was found".
1124 // The first (metadata found, error occurred loading it) should trigger a user-facing warning, whereas the second (no metadata found) isn't reflective of an error at all.
1125
1139 virtual QString loadNamedMetadata( const QString &uri, bool &resultFlag SIP_OUT );
1140
1141 // TODO QGIS 4.0 -- fix this. We incorrectly have a single boolean flag which in which false is used inconsistently for "metadata WAS found but an error occurred loading it" vs "no metadata was found".
1142 // The first (metadata found, error occurred loading it) should trigger a user-facing warning, whereas the second (no metadata found) isn't reflective of an error at all.
1143
1152 virtual QString loadDefaultMetadata( bool &resultFlag SIP_OUT );
1153
1161 bool loadNamedMetadataFromDatabase( const QString &db, const QString &uri, QString &qmd );
1162
1169 bool importNamedMetadata( QDomDocument &document, QString &errorMessage );
1170
1179 virtual QString styleURI() const;
1180
1181 // TODO QGIS 4.0 -- fix this. We incorrectly have a single boolean flag which in which false is used inconsistently for "a style WAS found but an error occurred loading it" vs "no style was found".
1182 // The first (style found, error occurred loading it) should trigger a user-facing warning, whereas the second (no style found) isn't reflective of an error at all.
1183
1193 virtual QString loadDefaultStyle( bool &resultFlag SIP_OUT );
1194
1195 // TODO QGIS 4.0 -- fix this. We incorrectly have a single boolean flag which in which false is used inconsistently for "a style WAS found but an error occurred loading it" vs "no style was found".
1196 // The first (style found, error occurred loading it) should trigger a user-facing warning, whereas the second (no style found) isn't reflective of an error at all.
1197
1214 virtual QString loadNamedStyle( const QString &uri, bool &resultFlag SIP_OUT, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories, Qgis::LoadStyleFlags flags = Qgis::LoadStyleFlags() );
1215
1223 virtual bool loadNamedStyleFromDatabase( const QString &db, const QString &uri, QString &qml SIP_OUT );
1224
1233 virtual bool importNamedStyle( QDomDocument &doc, QString &errorMsg SIP_OUT,
1235
1244 virtual void exportNamedStyle( QDomDocument &doc, QString &errorMsg SIP_OUT, const QgsReadWriteContext &context = QgsReadWriteContext(),
1246
1247
1255 Q_DECL_DEPRECATED virtual void exportSldStyle( QDomDocument &doc, QString &errorMsg ) const SIP_DEPRECATED;
1256
1264 Q_DECL_DEPRECATED virtual void exportSldStyleV2( QDomDocument &doc, QString &errorMsg, QgsSldExportContext &exportContext ) const SIP_DEPRECATED;
1265
1275 virtual QDomDocument exportSldStyleV3( QgsSldExportContext &exportContext ) const;
1276
1288 virtual QString saveDefaultStyle( bool &resultFlag SIP_OUT, StyleCategories categories );
1289
1301 Q_DECL_DEPRECATED virtual QString saveDefaultStyle( bool &resultFlag SIP_OUT ) SIP_DEPRECATED;
1302
1318 virtual QString saveNamedStyle( const QString &uri, bool &resultFlag SIP_OUT, StyleCategories categories = AllStyleCategories );
1319
1329 virtual QString saveSldStyle( const QString &uri, bool &resultFlag SIP_OUT ) const;
1330
1341 virtual QString saveSldStyleV2( bool &resultFlag SIP_OUT, QgsSldExportContext &exportContext ) const;
1342
1351 virtual QString loadSldStyle( const QString &uri, bool &resultFlag SIP_OUT );
1352
1353 virtual bool readSld( const QDomNode &node, QString &errorMessage )
1354 { Q_UNUSED( node ) errorMessage = QStringLiteral( "Layer type %1 not supported" ).arg( static_cast<int>( type() ) ); return false; }
1355
1356
1357
1366 virtual bool readSymbology( const QDomNode &node, QString &errorMessage,
1367 QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories ) = 0;
1368
1378 virtual bool readStyle( const QDomNode &node, QString &errorMessage,
1379 QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories );
1380
1391 virtual bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context,
1392 StyleCategories categories = AllStyleCategories ) const = 0;
1393
1405 virtual bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context,
1406 StyleCategories categories = AllStyleCategories ) const;
1407
1408
1439 void setDataSource( const QString &dataSource, const QString &baseName = QString(), const QString &provider = QString(), bool loadDefaultStyleFlag = false );
1440
1470 void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, bool loadDefaultStyleFlag = false );
1471
1501 void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, Qgis::DataProviderReadFlags flags );
1502
1506 QString providerType() const;
1507
1509 QUndoStack *undoStack();
1510
1514 QUndoStack *undoStackStyles();
1515
1521 Q_DECL_DEPRECATED void setLegendUrl( const QString &legendUrl ) SIP_DEPRECATED;
1522
1528 Q_DECL_DEPRECATED QString legendUrl() const SIP_DEPRECATED;
1529
1535 Q_DECL_DEPRECATED void setLegendUrlFormat( const QString &legendUrlFormat ) SIP_DEPRECATED;
1536
1542 Q_DECL_DEPRECATED QString legendUrlFormat() const SIP_DEPRECATED;
1543
1548 void setLegend( QgsMapLayerLegend *legend SIP_TRANSFER );
1549
1553 QgsMapLayerLegend *legend() const;
1554
1558 QgsMapLayerStyleManager *styleManager() const;
1559
1563 void setRenderer3D( QgsAbstract3DRenderer *renderer SIP_TRANSFER );
1564
1568 QgsAbstract3DRenderer *renderer3D() const;
1569
1578 bool isInScaleRange( double scale ) const;
1579
1590 double minimumScale() const;
1591
1602 double maximumScale() const;
1603
1612 bool hasScaleBasedVisibility() const;
1613
1620 Q_DECL_DEPRECATED bool hasAutoRefreshEnabled() const SIP_DEPRECATED;
1621
1628 Qgis::AutoRefreshMode autoRefreshMode() const;
1629
1636 int autoRefreshInterval() const;
1637
1648 void setAutoRefreshInterval( int interval );
1649
1656 Q_DECL_DEPRECATED void setAutoRefreshEnabled( bool enabled ) SIP_DEPRECATED;
1657
1664 void setAutoRefreshMode( Qgis::AutoRefreshMode mode );
1665
1671 virtual const QgsLayerMetadata &metadata() const;
1672
1678 virtual void setMetadata( const QgsLayerMetadata &metadata );
1679
1683 virtual QString htmlMetadata() const;
1684
1686 virtual QDateTime timestamp() const;
1687
1694 virtual QSet<QgsMapLayerDependency> dependencies() const;
1695
1700 QString refreshOnNotifyMessage() const { return mRefreshOnNofifyMessage; }
1701
1706 bool isRefreshOnNotifyEnabled() const { return mIsRefreshOnNofifyEnabled; }
1707
1716 QString originalXmlProperties() const;
1717
1725 void setOriginalXmlProperties( const QString &originalXmlProperties );
1726
1731 static QString generateId( const QString &layerName );
1732
1742 virtual bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
1743
1750
1757
1764
1770 QString legendPlaceholderImage() const { return mLegendPlaceholderImage;}
1771
1777 void setLegendPlaceholderImage( const QString &imgPath ) { mLegendPlaceholderImage = imgPath; }
1778
1785 virtual bool hasMapTips() const;
1786
1794 QString mapTipTemplate() const;
1795
1803 void setMapTipTemplate( const QString &mapTipTemplate );
1804
1811 void setMapTipsEnabled( bool enabled );
1812
1817 bool mapTipsEnabled() const;
1818
1826 static Qgis::DataProviderReadFlags providerReadFlags( const QDomNode &layerNode, QgsMapLayer::ReadFlags layerReadFlags );
1827
1828 public slots:
1829
1839 void setMinimumScale( double scale );
1840
1850 void setMaximumScale( double scale );
1851
1859 void setScaleBasedVisibility( bool enabled );
1860
1869 void triggerRepaint( bool deferredUpdate = false );
1870
1877 void trigger3DUpdate();
1878
1882 void emitStyleChanged();
1883
1891 virtual bool setDependencies( const QSet<QgsMapLayerDependency> &layers );
1892
1897 void setRefreshOnNotifyEnabled( bool enabled );
1898
1905 void setRefreshOnNofifyMessage( const QString &message ) { mRefreshOnNofifyMessage = message; }
1906
1912 virtual void setTransformContext( const QgsCoordinateTransformContext &transformContext ) = 0;
1913
1914#ifdef SIP_RUN
1915 SIP_PYOBJECT __repr__();
1916 % MethodCode
1917 QString str = QStringLiteral( "<QgsMapLayer: '%1' (%2)>" ).arg( sipCpp->name(), sipCpp->dataProvider() ? sipCpp->dataProvider()->name() : QStringLiteral( "Invalid" ) );
1918 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
1919 % End
1920#endif
1921
1928 QgsProject *project() const;
1929
1930 signals:
1931
1939
1941 void statusChanged( const QString &status );
1942
1951 void idChanged( const QString &id );
1952
1957
1967
1978
1995
2002 void repaintRequested( bool deferredUpdate = false );
2003
2006
2009
2011 void blendModeChanged( QPainter::CompositionMode blendMode );
2012
2021 void opacityChanged( double opacity );
2022
2028
2040
2045
2050
2057
2063
2068
2075
2080 void autoRefreshIntervalChanged( int interval );
2081
2088
2096
2105
2112
2119
2125 void customPropertyChanged( const QString &key );
2126
2132
2138
2144
2151
2159
2160 private slots:
2161
2162 void onNotified( const QString &message );
2163
2179 virtual void setDataSourcePrivate( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, Qgis::DataProviderReadFlags flags );
2180
2181 protected:
2182
2187 void clone( QgsMapLayer *layer ) const;
2188
2190 virtual void setExtent( const QgsRectangle &rect );
2191
2196 virtual void setExtent3D( const QgsBox3D &box );
2197
2199 void setValid( bool valid );
2200
2205 virtual bool readXml( const QDomNode &layer_node, QgsReadWriteContext &context );
2206
2211 virtual bool writeXml( QDomNode &layer_node, QDomDocument &document, const QgsReadWriteContext &context ) const;
2212
2224 virtual QString encodedSource( const QString &source, const QgsReadWriteContext &context ) const;
2225
2238 virtual QString decodedSource( const QString &source, const QString &dataProvider, const QgsReadWriteContext &context ) const;
2239
2245 void readCustomProperties( const QDomNode &layerNode, const QString &keyStartsWith = QString() );
2246
2248 void writeCustomProperties( QDomNode &layerNode, QDomDocument &doc ) const;
2249
2251 void readStyleManager( const QDomNode &layerNode );
2253 void writeStyleManager( QDomNode &layerNode, QDomDocument &doc ) const;
2254
2258 void writeCommonStyle( QDomElement &layerElement, QDomDocument &document,
2259 const QgsReadWriteContext &context,
2260 StyleCategories categories = AllStyleCategories ) const;
2261
2265 void readCommonStyle( const QDomElement &layerElement, const QgsReadWriteContext &context,
2266 StyleCategories categories = AllStyleCategories );
2267
2269 void setProviderType( const QString &providerType );
2270
2271#ifndef SIP_RUN
2272#if 0
2274 void connectNotify( const char *signal ) override;
2275#endif
2276#endif
2277
2279 void appendError( const QgsErrorMessage &error ) { mError.append( error );}
2281 void setError( const QgsError &error ) { mError = error;}
2282
2289 void invalidateWgs84Extent();
2290
2292 bool mValid = false;
2293
2296
2298 QString mLayerName;
2299
2302
2304 QSet<QgsMapLayerDependency> mDependencies;
2305
2311 Q_DECL_DEPRECATED bool hasDependencyCycle( const QSet<QgsMapLayerDependency> & ) const {return false;}
2312
2313 bool mIsRefreshOnNofifyEnabled = false;
2315
2318
2319 //TODO QGIS 4 - move to readXml as a new argument (breaks API)
2320
2323
2329 bool mShouldValidateCrs = true;
2330
2336 double mLayerOpacity = 1.0;
2337
2343 int mBlockStyleChangedSignal = 0;
2344
2345#ifndef SIP_RUN
2346
2355 QString crsHtmlMetadata() const;
2356#endif
2357
2358#ifndef SIP_RUN
2359
2368 QString generalHtmlMetadata() const;
2369
2378 QString customPropertyHtmlMetadata() const;
2379#endif
2380
2381#ifndef SIP_RUN
2382
2390 std::unique_ptr<QgsDataProvider> mPreloadedProvider;
2391#endif
2392
2393 private:
2394
2395 virtual QString baseURI( PropertyType type ) const;
2396 QString saveNamedProperty( const QString &uri, QgsMapLayer::PropertyType type,
2397 bool &resultFlag, StyleCategories categories = AllStyleCategories );
2398 QString loadNamedProperty( const QString &uri, QgsMapLayer::PropertyType type,
2399 bool &namedPropertyExists, bool &propertySuccessfullyLoaded, StyleCategories categories = AllStyleCategories, Qgis::LoadStyleFlags flags = Qgis::LoadStyleFlags() );
2400 bool loadNamedPropertyFromDatabase( const QString &db, const QString &uri, QString &xml, QgsMapLayer::PropertyType type );
2401
2402 // const method because extents are mutable
2403 void updateExtent( const QgsRectangle &extent ) const;
2404 void updateExtent( const QgsBox3D &extent ) const;
2405
2406 bool rebuildCrs3D( QString *error = nullptr );
2407
2412 virtual bool isReadOnly() const;
2413
2419 QgsCoordinateReferenceSystem mVerticalCrs;
2421
2423 QString mID;
2424
2426 Qgis::LayerType mLayerType;
2427
2428 LayerFlags mFlags = LayerFlags( Identifiable | Removable | Searchable );
2429
2431 QPainter::CompositionMode mBlendMode = QPainter::CompositionMode_SourceOver;
2432
2434 QString mTag;
2435
2436 //set some generous defaults for scale based visibility
2437
2439 double mMinScale = 0;
2441 double mMaxScale = 100000000;
2443 bool mScaleBasedVisibility = false;
2444
2448 std::unique_ptr< QgsMapLayerServerProperties > mServerProperties;
2449
2451 QUndoStack *mUndoStack = nullptr;
2452
2453 QUndoStack *mUndoStackStyles = nullptr;
2454
2456 QgsObjectCustomProperties mCustomProperties;
2457
2459 QgsMapLayerLegend *mLegend = nullptr;
2460
2462 std::unique_ptr<QgsMapLayerStyleManager> mStyleManager;
2463
2465
2467 QTimer *mRefreshTimer = nullptr;
2468
2469 QgsLayerMetadata mMetadata;
2470
2472 QgsAbstract3DRenderer *m3DRenderer = nullptr;
2473
2475 mutable QgsBox3D mExtent3D;
2476
2478 mutable QgsRectangle mExtent2D;
2479
2481 mutable QgsRectangle mWgs84Extent;
2482
2488 QString mOriginalXmlProperties;
2489
2491 bool mRepaintRequestedFired = false;
2492
2494 QString mLegendPlaceholderImage;
2495
2497 QString mMapTipTemplate;
2498
2500 bool mMapTipsEnabled = true;
2501
2502 friend class QgsVectorLayer;
2503 friend class TestQgsProject;
2504 friend class TestQgsMapLayer;
2505};
2506
2510
2511
2512#ifndef SIP_RUN
2513
2518typedef QPointer< QgsMapLayer > QgsWeakMapLayerPointer;
2519
2524typedef QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList;
2525#endif
2526
2527#endif
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:54
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
@ Group
Composite group layer. Added in QGIS 3.24.
@ Plugin
Plugin based layer.
@ TiledScene
Tiled scene layer. Added in QGIS 3.34.
@ Annotation
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
@ Vector
Vector layer.
@ VectorTile
Vector tile layer. Added in QGIS 3.14.
@ Mesh
Mesh layer. Added in QGIS 3.2.
@ Raster
Raster layer.
@ PointCloud
Point cloud layer. Added in QGIS 3.18.
QFlags< LoadStyleFlag > LoadStyleFlags
Flags for loading layer styles.
Definition qgis.h:225
AutoRefreshMode
Map layer automatic refresh modes.
Definition qgis.h:2244
@ Disabled
Automatic refreshing is disabled.
Base class for all renderers that participate in 3D views.
A 3-dimensional box composed of x, y, z coordinates.
Definition qgsbox3d.h:43
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.
Represents a single error message.
Definition qgserror.h:33
A container for error messages.
Definition qgserror.h:81
A structured metadata store for a map layer.
Models dependencies with or between map layers.
Base class for storage of map layer elevation properties.
An abstract interface for implementations of legends for one map layer.
Base class for utility classes that encapsulate information necessary for rendering of map layers.
Base class for storage of map layer selection properties.
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:77
void crs3DChanged()
Emitted when the crs3D() of the layer has changed.
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.
void dependenciesChanged()
Emitted when dependencies are changed.
void setError(const QgsError &error)
Sets error message.
void legendChanged()
Signal emitted when legend of the layer has changed.
QFlags< ReadFlag > ReadFlags
QFlags< LayerFlag > LayerFlags
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 request3DUpdate()
Signal emitted when a layer requires an update in any 3D maps.
QgsError mError
Error.
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.
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...
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.
QString mRefreshOnNofifyMessage
QString mLayerName
Name of the layer - used for display.
void setCustomFlagProperty(const QString &key, const T &value)
Set the value of a property based on a flag.
void mapTipTemplateChanged()
Emitted when the map tip template changes.
void renderer3DChanged()
Signal emitted when 3D renderer associated with the layer has changed.
virtual QgsMapLayerSelectionProperties * selectionProperties()
Returns the layer's selection properties.
void statusChanged(const QString &status)
Emit a signal with status (e.g. to be caught by QgisApp and display a msg on status bar)
bool isRefreshOnNotifyEnabled() const
Returns true if the refresh on provider nofification is enabled.
QSet< QgsMapLayerDependency > mDependencies
List of layers that may modify this layer on modification.
QFlags< StyleCategory > StyleCategories
const QgsMapLayerServerProperties * serverProperties() const
Returns QGIS Server Properties const for the map layer.
QString mProviderKey
Data provider key (name of the data provider)
void styleChanged()
Signal emitted whenever a change affects the layer's style.
std::unique_ptr< QgsDataProvider > mPreloadedProvider
Optionally used when loading a project, it is released when the layer is effectively created.
void rendererChanged()
Signal emitted when renderer is changed.
void crsChanged()
Emitted when the crs() of the layer has changed.
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.
void setRefreshOnNofifyMessage(const QString &message)
Set the notification message that triggers repaint If refresh on notification is enabled,...
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.
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...
void verticalCrsChanged()
Emitted when the verticalCrs() of the layer has changed.
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.
void setLegendPlaceholderImage(const QString &imgPath)
Set placeholder image for legend.
void appendError(const QgsErrorMessage &error)
Add error message.
QString mDataSource
Data source description string, varies by layer type.
virtual bool readSld(const QDomNode &node, QString &errorMessage)
ReadFlag
Flags which control project read behavior.
void customPropertyChanged(const QString &key)
Emitted when a custom property of the layer has been changed or removed.
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 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.
virtual void setTransformContext(const QgsCoordinateTransformContext &transformContext)=0
Sets the coordinate transform context to transformContext.
void nameChanged()
Emitted when the name has been changed.
T customEnumProperty(const QString &key, const T &defaultValue)
Returns the property value for a property based on an enum.
StyleCategory
Categories of style to distinguish appropriate sections for import/export.
void layerModified()
Emitted when modifications has been done on layer.
virtual Q_INVOKABLE void reload()
Synchronises with changes in the datasource.
void mapTipsEnabledChanged()
Emitted when map tips are enabled or disabled for the layer.
void setCustomEnumProperty(const QString &key, const T &value)
Set the value of a property based on an enum.
PropertyType
Maplayer has a style and a metadata property.
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:107
Holds data provider key, description, and associated shared library file or function pointer informat...
A container for the context for various read/write operations on objects.
A rectangle specified with double values.
Contains information about the context of a rendering operation.
Holds SLD export options and other information related to SLD export of a QGIS layer style.
An interface for classes which can visit style entity (e.g.
Represents a vector layer which manages a vector based dataset.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition qgis_sip.h:191
#define SIP_DEPRECATED
Definition qgis_sip.h:106
#define SIP_ENUM_BASETYPE(type)
Definition qgis_sip.h:278
#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:208
#define QgsDebugError(str)
Definition qgslogger.h:40
QPointer< QgsMapLayer > QgsWeakMapLayerPointer
Weak pointer for QgsMapLayer.
QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList
A list of weak pointers to QgsMapLayers.
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsTextRendererUtils::CurvedTextFlags)
const QgsCoordinateReferenceSystem & crs
Setting options for creating vector data providers.