QGIS API Documentation 3.99.0-Master (c637e42516f)
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
765 enum class SaveStyleResult SIP_ENUM_BASETYPE( IntFlag )
766 {
767 Success = 0,
768 QmlGenerationFailed = 1 << 0,
769 SldGenerationFailed = 1 << 1,
770 DatabaseWriteFailed = 1 << 2,
771 };
772 Q_ENUM( SaveStyleResult )
773
774
780 Q_FLAG( SaveStyleResults )
781
799 Q_DECL_DEPRECATED virtual void saveStyleToDatabase( const QString &name, const QString &description,
800 bool useAsDefault, const QString &uiFileContent,
801 QString &msgError SIP_OUT,
802 QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) SIP_DEPRECATED;
803
817 QgsMapLayer::SaveStyleResults saveStyleToDatabaseV2( const QString &name, const QString &description,
818 bool useAsDefault, const QString &uiFileContent,
819 QString &msgError SIP_OUT,
820 QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories );
821
822 // 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".
823 // 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.
824
835 virtual QString loadNamedStyle( const QString &theURI, bool &resultFlag SIP_OUT, bool loadFromLocalDb,
836 QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories,
837 Qgis::LoadStyleFlags flags = Qgis::LoadStyleFlags() );
838
839#ifndef SIP_RUN
840
851 template <class T>
852 T customEnumProperty( const QString &key, const T &defaultValue )
853 {
854 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
855 Q_ASSERT( metaEnum.isValid() );
856 if ( !metaEnum.isValid() )
857 {
858 QgsDebugError( QStringLiteral( "Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
859 }
860
861 T v;
862 bool ok = false;
863
864 if ( metaEnum.isValid() )
865 {
866 // read as string
867 QByteArray ba = customProperty( key, metaEnum.valueToKey( static_cast<int>( defaultValue ) ) ).toString().toUtf8();
868 const char *vs = ba.data();
869 v = static_cast<T>( metaEnum.keyToValue( vs, &ok ) );
870 if ( ok )
871 return v;
872 }
873
874 // if failed, try to read as int (old behavior)
875 // this code shall be removed later
876 // then the method could be marked as const
877 v = static_cast<T>( customProperty( key, static_cast<int>( defaultValue ) ).toInt( &ok ) );
878 if ( metaEnum.isValid() )
879 {
880 if ( !ok || !metaEnum.valueToKey( static_cast<int>( v ) ) )
881 {
882 v = defaultValue;
883 }
884 else
885 {
886 // found property as an integer
887 // convert the property to the new form (string)
888 setCustomEnumProperty( key, v );
889 }
890 }
891
892 return v;
893 }
894
903 template <class T>
904 void setCustomEnumProperty( const QString &key, const T &value )
905 {
906 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
907 Q_ASSERT( metaEnum.isValid() );
908 if ( metaEnum.isValid() )
909 {
910 setCustomProperty( key, metaEnum.valueToKey( static_cast<int>( value ) ) );
911 }
912 else
913 {
914 QgsDebugError( QStringLiteral( "Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
915 }
916 }
917
929 template <class T>
930 T customFlagProperty( const QString &key, const T &defaultValue )
931 {
932 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
933 Q_ASSERT( metaEnum.isValid() );
934 if ( !metaEnum.isValid() )
935 {
936 QgsDebugError( QStringLiteral( "Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
937 }
938
939 T v = defaultValue;
940 bool ok = false;
941
942 if ( metaEnum.isValid() )
943 {
944 // read as string
945 QByteArray ba = customProperty( key, metaEnum.valueToKeys( defaultValue ) ).toString().toUtf8();
946 const char *vs = ba.data();
947 v = static_cast<T>( metaEnum.keysToValue( vs, &ok ) );
948 }
949 if ( !ok )
950 {
951 // if failed, try to read as int
952 const int intValue = customProperty( key, static_cast<int>( defaultValue ) ).toInt( &ok );
953 if ( metaEnum.isValid() )
954 {
955 if ( ok )
956 {
957 // check that the int value does correspond to a flag
958 // see https://stackoverflow.com/a/68495949/1548052
959 const QByteArray keys = metaEnum.valueToKeys( intValue );
960 const int intValueCheck = metaEnum.keysToValue( keys );
961 if ( intValue != intValueCheck )
962 {
963 v = defaultValue;
964 }
965 else
966 {
967 // found property as an integer
968 v = T( intValue );
969 // convert the property to the new form (string)
970 // this code could be removed
971 // then the method could be marked as const
972 setCustomFlagProperty( key, v );
973 }
974 }
975 else
976 {
977 v = defaultValue;
978 }
979 }
980 }
981
982 return v;
983 }
984
993 template <class T>
994 void setCustomFlagProperty( const QString &key, const T &value )
995 {
996 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
997 Q_ASSERT( metaEnum.isValid() );
998 if ( metaEnum.isValid() )
999 {
1000 setCustomProperty( key, metaEnum.valueToKeys( value ) );
1001 }
1002 else
1003 {
1004 QgsDebugError( QStringLiteral( "Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
1005 }
1006 }
1007#endif
1008
1009
1014 void removeCustomProperty( const QString &key );
1015
1021 virtual QgsError error() const;
1022
1035
1054 QgsCoordinateReferenceSystem verticalCrs() const;
1055
1074 QgsCoordinateReferenceSystem crs3D() const;
1075
1086 void setCrs( const QgsCoordinateReferenceSystem &srs, bool emitSignal = true );
1087
1107 bool setVerticalCrs( const QgsCoordinateReferenceSystem &crs, QString *errorMessage SIP_OUT = nullptr );
1108
1114 QgsCoordinateTransformContext transformContext( ) const;
1115
1116
1121 static QString formatLayerName( const QString &name );
1122
1129 virtual QString metadataUri() const;
1130
1136 void exportNamedMetadata( QDomDocument &doc, QString &errorMsg ) const;
1137
1146 virtual QString saveDefaultMetadata( bool &resultFlag SIP_OUT );
1147
1161 QString saveNamedMetadata( const QString &uri, bool &resultFlag SIP_OUT );
1162
1163 // 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".
1164 // 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.
1165
1179 virtual QString loadNamedMetadata( const QString &uri, bool &resultFlag SIP_OUT );
1180
1181 // 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".
1182 // 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.
1183
1192 virtual QString loadDefaultMetadata( bool &resultFlag SIP_OUT );
1193
1201 bool loadNamedMetadataFromDatabase( const QString &db, const QString &uri, QString &qmd );
1202
1209 bool importNamedMetadata( QDomDocument &document, QString &errorMessage );
1210
1219 virtual QString styleURI() const;
1220
1221 // 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".
1222 // 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.
1223
1233 virtual QString loadDefaultStyle( bool &resultFlag SIP_OUT );
1234
1235 // 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".
1236 // 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.
1237
1254 virtual QString loadNamedStyle( const QString &uri, bool &resultFlag SIP_OUT, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories, Qgis::LoadStyleFlags flags = Qgis::LoadStyleFlags() );
1255
1263 virtual bool loadNamedStyleFromDatabase( const QString &db, const QString &uri, QString &qml SIP_OUT );
1264
1273 virtual bool importNamedStyle( QDomDocument &doc, QString &errorMsg SIP_OUT,
1275
1284 virtual void exportNamedStyle( QDomDocument &doc, QString &errorMsg SIP_OUT, const QgsReadWriteContext &context = QgsReadWriteContext(),
1286
1287
1295 Q_DECL_DEPRECATED virtual void exportSldStyle( QDomDocument &doc, QString &errorMsg ) const SIP_DEPRECATED;
1296
1304 Q_DECL_DEPRECATED virtual void exportSldStyleV2( QDomDocument &doc, QString &errorMsg, QgsSldExportContext &exportContext ) const SIP_DEPRECATED;
1305
1315 virtual QDomDocument exportSldStyleV3( QgsSldExportContext &exportContext ) const;
1316
1328 virtual QString saveDefaultStyle( bool &resultFlag SIP_OUT, StyleCategories categories );
1329
1341 Q_DECL_DEPRECATED virtual QString saveDefaultStyle( bool &resultFlag SIP_OUT ) SIP_DEPRECATED;
1342
1358 virtual QString saveNamedStyle( const QString &uri, bool &resultFlag SIP_OUT, StyleCategories categories = AllStyleCategories );
1359
1369 virtual QString saveSldStyle( const QString &uri, bool &resultFlag SIP_OUT ) const;
1370
1381 virtual QString saveSldStyleV2( bool &resultFlag SIP_OUT, QgsSldExportContext &exportContext ) const;
1382
1391 virtual QString loadSldStyle( const QString &uri, bool &resultFlag SIP_OUT );
1392
1393 virtual bool readSld( const QDomNode &node, QString &errorMessage )
1394 { Q_UNUSED( node ) errorMessage = QStringLiteral( "Layer type %1 not supported" ).arg( static_cast<int>( type() ) ); return false; }
1395
1396
1397
1406 virtual bool readSymbology( const QDomNode &node, QString &errorMessage,
1407 QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories ) = 0;
1408
1418 virtual bool readStyle( const QDomNode &node, QString &errorMessage,
1419 QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories );
1420
1431 virtual bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context,
1432 StyleCategories categories = AllStyleCategories ) const = 0;
1433
1445 virtual bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context,
1446 StyleCategories categories = AllStyleCategories ) const;
1447
1448
1479 void setDataSource( const QString &dataSource, const QString &baseName = QString(), const QString &provider = QString(), bool loadDefaultStyleFlag = false );
1480
1510 void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, bool loadDefaultStyleFlag = false );
1511
1541 void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, Qgis::DataProviderReadFlags flags );
1542
1546 QString providerType() const;
1547
1549 QUndoStack *undoStack();
1550
1554 QUndoStack *undoStackStyles();
1555
1561 Q_DECL_DEPRECATED void setLegendUrl( const QString &legendUrl ) SIP_DEPRECATED;
1562
1568 Q_DECL_DEPRECATED QString legendUrl() const SIP_DEPRECATED;
1569
1575 Q_DECL_DEPRECATED void setLegendUrlFormat( const QString &legendUrlFormat ) SIP_DEPRECATED;
1576
1582 Q_DECL_DEPRECATED QString legendUrlFormat() const SIP_DEPRECATED;
1583
1588 void setLegend( QgsMapLayerLegend *legend SIP_TRANSFER );
1589
1593 QgsMapLayerLegend *legend() const;
1594
1598 QgsMapLayerStyleManager *styleManager() const;
1599
1603 void setRenderer3D( QgsAbstract3DRenderer *renderer SIP_TRANSFER );
1604
1608 QgsAbstract3DRenderer *renderer3D() const;
1609
1618 bool isInScaleRange( double scale ) const;
1619
1630 double minimumScale() const;
1631
1642 double maximumScale() const;
1643
1652 bool hasScaleBasedVisibility() const;
1653
1660 Q_DECL_DEPRECATED bool hasAutoRefreshEnabled() const SIP_DEPRECATED;
1661
1668 Qgis::AutoRefreshMode autoRefreshMode() const;
1669
1676 int autoRefreshInterval() const;
1677
1688 void setAutoRefreshInterval( int interval );
1689
1696 Q_DECL_DEPRECATED void setAutoRefreshEnabled( bool enabled ) SIP_DEPRECATED;
1697
1704 void setAutoRefreshMode( Qgis::AutoRefreshMode mode );
1705
1711 virtual const QgsLayerMetadata &metadata() const;
1712
1718 virtual void setMetadata( const QgsLayerMetadata &metadata );
1719
1723 virtual QString htmlMetadata() const;
1724
1726 virtual QDateTime timestamp() const;
1727
1734 virtual QSet<QgsMapLayerDependency> dependencies() const;
1735
1740 QString refreshOnNotifyMessage() const { return mRefreshOnNofifyMessage; }
1741
1746 bool isRefreshOnNotifyEnabled() const { return mIsRefreshOnNofifyEnabled; }
1747
1756 QString originalXmlProperties() const;
1757
1765 void setOriginalXmlProperties( const QString &originalXmlProperties );
1766
1771 static QString generateId( const QString &layerName );
1772
1782 virtual bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
1783
1790
1797
1804
1810 QString legendPlaceholderImage() const { return mLegendPlaceholderImage;}
1811
1817 void setLegendPlaceholderImage( const QString &imgPath ) { mLegendPlaceholderImage = imgPath; }
1818
1825 virtual bool hasMapTips() const;
1826
1834 QString mapTipTemplate() const;
1835
1843 void setMapTipTemplate( const QString &mapTipTemplate );
1844
1851 void setMapTipsEnabled( bool enabled );
1852
1857 bool mapTipsEnabled() const;
1858
1866 static Qgis::DataProviderReadFlags providerReadFlags( const QDomNode &layerNode, QgsMapLayer::ReadFlags layerReadFlags );
1867
1868 public slots:
1869
1879 void setMinimumScale( double scale );
1880
1890 void setMaximumScale( double scale );
1891
1899 void setScaleBasedVisibility( bool enabled );
1900
1909 void triggerRepaint( bool deferredUpdate = false );
1910
1917 void trigger3DUpdate();
1918
1922 void emitStyleChanged();
1923
1931 virtual bool setDependencies( const QSet<QgsMapLayerDependency> &layers );
1932
1937 void setRefreshOnNotifyEnabled( bool enabled );
1938
1945 void setRefreshOnNofifyMessage( const QString &message ) { mRefreshOnNofifyMessage = message; }
1946
1952 virtual void setTransformContext( const QgsCoordinateTransformContext &transformContext ) = 0;
1953
1954#ifdef SIP_RUN
1955 SIP_PYOBJECT __repr__();
1956 % MethodCode
1957 QString str = QStringLiteral( "<QgsMapLayer: '%1' (%2)>" ).arg( sipCpp->name(), sipCpp->dataProvider() ? sipCpp->dataProvider()->name() : QStringLiteral( "Invalid" ) );
1958 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
1959 % End
1960#endif
1961
1968 QgsProject *project() const;
1969
1970 signals:
1971
1979
1981 void statusChanged( const QString &status );
1982
1991 void idChanged( const QString &id );
1992
1997
2007
2018
2035
2042 void repaintRequested( bool deferredUpdate = false );
2043
2046
2049
2051 void blendModeChanged( QPainter::CompositionMode blendMode );
2052
2061 void opacityChanged( double opacity );
2062
2068
2080
2085
2090
2097
2103
2108
2115
2120 void autoRefreshIntervalChanged( int interval );
2121
2128
2136
2145
2152
2159
2165 void customPropertyChanged( const QString &key );
2166
2172
2178
2184
2191
2199
2200 private slots:
2201
2202 void onNotified( const QString &message );
2203
2219 virtual void setDataSourcePrivate( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, Qgis::DataProviderReadFlags flags );
2220
2221 protected:
2222
2227 void clone( QgsMapLayer *layer ) const;
2228
2230 virtual void setExtent( const QgsRectangle &rect );
2231
2236 virtual void setExtent3D( const QgsBox3D &box );
2237
2239 void setValid( bool valid );
2240
2245 virtual bool readXml( const QDomNode &layer_node, QgsReadWriteContext &context );
2246
2251 virtual bool writeXml( QDomNode &layer_node, QDomDocument &document, const QgsReadWriteContext &context ) const;
2252
2264 virtual QString encodedSource( const QString &source, const QgsReadWriteContext &context ) const;
2265
2278 virtual QString decodedSource( const QString &source, const QString &dataProvider, const QgsReadWriteContext &context ) const;
2279
2285 void readCustomProperties( const QDomNode &layerNode, const QString &keyStartsWith = QString() );
2286
2288 void writeCustomProperties( QDomNode &layerNode, QDomDocument &doc ) const;
2289
2291 void readStyleManager( const QDomNode &layerNode );
2293 void writeStyleManager( QDomNode &layerNode, QDomDocument &doc ) const;
2294
2298 void writeCommonStyle( QDomElement &layerElement, QDomDocument &document,
2299 const QgsReadWriteContext &context,
2300 StyleCategories categories = AllStyleCategories ) const;
2301
2305 void readCommonStyle( const QDomElement &layerElement, const QgsReadWriteContext &context,
2306 StyleCategories categories = AllStyleCategories );
2307
2309 void setProviderType( const QString &providerType );
2310
2311#ifndef SIP_RUN
2312#if 0
2314 void connectNotify( const char *signal ) override;
2315#endif
2316#endif
2317
2319 void appendError( const QgsErrorMessage &error ) { mError.append( error );}
2321 void setError( const QgsError &error ) { mError = error;}
2322
2329 void invalidateWgs84Extent();
2330
2332 bool mValid = false;
2333
2336
2338 QString mLayerName;
2339
2342
2344 QSet<QgsMapLayerDependency> mDependencies;
2345
2351 Q_DECL_DEPRECATED bool hasDependencyCycle( const QSet<QgsMapLayerDependency> & ) const {return false;}
2352
2353 bool mIsRefreshOnNofifyEnabled = false;
2355
2358
2359 //TODO QGIS 4 - move to readXml as a new argument (breaks API)
2360
2363
2369 bool mShouldValidateCrs = true;
2370
2376 double mLayerOpacity = 1.0;
2377
2383 int mBlockStyleChangedSignal = 0;
2384
2385#ifndef SIP_RUN
2386
2395 QString crsHtmlMetadata() const;
2396#endif
2397
2398#ifndef SIP_RUN
2399
2408 QString generalHtmlMetadata() const;
2409
2418 QString customPropertyHtmlMetadata() const;
2419#endif
2420
2421#ifndef SIP_RUN
2422
2430 std::unique_ptr<QgsDataProvider> mPreloadedProvider;
2431#endif
2432
2433 private:
2434
2435 virtual QString baseURI( PropertyType type ) const;
2436 QString saveNamedProperty( const QString &uri, QgsMapLayer::PropertyType type,
2437 bool &resultFlag, StyleCategories categories = AllStyleCategories );
2438 QString loadNamedProperty( const QString &uri, QgsMapLayer::PropertyType type,
2439 bool &namedPropertyExists, bool &propertySuccessfullyLoaded, StyleCategories categories = AllStyleCategories, Qgis::LoadStyleFlags flags = Qgis::LoadStyleFlags() );
2440 bool loadNamedPropertyFromDatabase( const QString &db, const QString &uri, QString &xml, QgsMapLayer::PropertyType type );
2441
2442 // const method because extents are mutable
2443 void updateExtent( const QgsRectangle &extent ) const;
2444 void updateExtent( const QgsBox3D &extent ) const;
2445
2446 bool rebuildCrs3D( QString *error = nullptr );
2447
2452 virtual bool isReadOnly() const;
2453
2459 QgsCoordinateReferenceSystem mVerticalCrs;
2461
2463 QString mID;
2464
2466 Qgis::LayerType mLayerType;
2467
2468 LayerFlags mFlags = LayerFlags( Identifiable | Removable | Searchable );
2469
2471 QPainter::CompositionMode mBlendMode = QPainter::CompositionMode_SourceOver;
2472
2474 QString mTag;
2475
2476 //set some generous defaults for scale based visibility
2477
2479 double mMinScale = 0;
2481 double mMaxScale = 100000000;
2483 bool mScaleBasedVisibility = false;
2484
2488 std::unique_ptr< QgsMapLayerServerProperties > mServerProperties;
2489
2491 QUndoStack *mUndoStack = nullptr;
2492
2493 QUndoStack *mUndoStackStyles = nullptr;
2494
2496 QgsObjectCustomProperties mCustomProperties;
2497
2499 std::unique_ptr<QgsMapLayerLegend> mLegend;
2500
2502 std::unique_ptr<QgsMapLayerStyleManager> mStyleManager;
2503
2505
2507 QTimer *mRefreshTimer = nullptr;
2508
2509 QgsLayerMetadata mMetadata;
2510
2512 std::unique_ptr<QgsAbstract3DRenderer> m3DRenderer;
2513
2515 mutable QgsBox3D mExtent3D;
2516
2518 mutable QgsRectangle mExtent2D;
2519
2521 mutable QgsRectangle mWgs84Extent;
2522
2528 QString mOriginalXmlProperties;
2529
2531 bool mRepaintRequestedFired = false;
2532
2534 QString mLegendPlaceholderImage;
2535
2537 QString mMapTipTemplate;
2538
2540 bool mMapTipsEnabled = true;
2541
2542 friend class QgsVectorLayer;
2543 friend class TestQgsProject;
2544 friend class TestQgsMapLayer;
2545};
2546
2550
2551
2552#ifndef SIP_RUN
2553
2558typedef QPointer< QgsMapLayer > QgsWeakMapLayerPointer;
2559
2564typedef QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList;
2565#endif
2566
2567#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:2245
@ 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.
SaveStyleResult
Results of saving styles to database.
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.
QFlags< SaveStyleResult > SaveStyleResults
Results of saving styles to database.
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.