QGIS API Documentation 3.99.0-Master (a26b91b364d)
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
47class QgsDataProvider;
51class QgsProject;
58
59class QDomDocument;
60class QKeyEvent;
61class QPainter;
63class QgsBox3D;
64
65/*
66 * Constants used to describe copy-paste MIME types
67 */
68#define QGSCLIPBOARD_MAPLAYER_MIME "application/qgis.maplayer"
69
70
77class CORE_EXPORT QgsMapLayer : public QObject
78{
79 Q_OBJECT
80
81 Q_PROPERTY( QString id READ id WRITE setId NOTIFY idChanged )
82 Q_PROPERTY( QString name READ name WRITE setName NOTIFY nameChanged )
83 Q_PROPERTY( int autoRefreshInterval READ autoRefreshInterval WRITE setAutoRefreshInterval NOTIFY autoRefreshIntervalChanged )
84 Q_PROPERTY( QgsLayerMetadata metadata READ metadata WRITE setMetadata NOTIFY metadataChanged )
85 Q_PROPERTY( QgsCoordinateReferenceSystem crs READ crs WRITE setCrs NOTIFY crsChanged )
86 Q_PROPERTY( QgsCoordinateReferenceSystem verticalCrs READ verticalCrs WRITE setVerticalCrs NOTIFY verticalCrsChanged )
87 Q_PROPERTY( QgsCoordinateReferenceSystem crs3D READ crs3D NOTIFY crs3DChanged )
88 Q_PROPERTY( Qgis::LayerType type READ type CONSTANT )
89 Q_PROPERTY( bool isValid READ isValid NOTIFY isValidChanged )
90 Q_PROPERTY( double opacity READ opacity WRITE setOpacity NOTIFY opacityChanged )
91 Q_PROPERTY( QString mapTipTemplate READ mapTipTemplate WRITE setMapTipTemplate NOTIFY mapTipTemplateChanged )
92 Q_PROPERTY( bool mapTipsEnabled READ mapTipsEnabled WRITE setMapTipsEnabled NOTIFY mapTipsEnabledChanged )
93
94#ifdef SIP_RUN
96 QgsMapLayer *layer = qobject_cast<QgsMapLayer *>( sipCpp );
97
98 sipType = 0;
99
100 if ( layer )
101 {
102 switch ( layer->type() )
103 {
105 sipType = sipType_QgsVectorLayer;
106 break;
108 sipType = sipType_QgsRasterLayer;
109 break;
111 sipType = sipType_QgsPluginLayer;
112 break;
114 sipType = sipType_QgsMeshLayer;
115 break;
117 sipType = sipType_QgsVectorTileLayer;
118 break;
120 sipType = sipType_QgsAnnotationLayer;
121 break;
123 sipType = sipType_QgsPointCloudLayer;
124 break;
126 sipType = sipType_QgsGroupLayer;
127 break;
129 sipType = sipType_QgsTiledSceneLayer;
130 break;
131 default:
132 sipType = nullptr;
133 break;
134 }
135 }
136 SIP_END
137#endif
138
139 public:
140
145 {
146 Style = 0,
148 };
149
156 {
157 Identifiable = 1 << 0,
158 Removable = 1 << 1,
159 Searchable = 1 << 2,
160 Private = 1 << 3,
161 };
162 Q_ENUM( LayerFlag )
163 Q_DECLARE_FLAGS( LayerFlags, LayerFlag )
164 Q_FLAG( LayerFlags )
165
171 {
172 LayerConfiguration = 1 << 0,
173 Symbology = 1 << 1,
174 Symbology3D = 1 << 2,
175 Labeling = 1 << 3,
176 Fields = 1 << 4,
177 Forms = 1 << 5,
178 Actions = 1 << 6,
179 MapTips = 1 << 7,
180 Diagrams = 1 << 8,
181 AttributeTable = 1 << 9,
182 Rendering = 1 << 10,
183 CustomProperties = 1 << 11,
184 GeometryOptions = 1 << 12,
185 Relations = 1 << 13,
186 Temporal = 1 << 14,
187 Legend = 1 << 15,
188 Elevation = 1 << 16,
189 Notes = 1 << 17,
190 AllStyleCategories = LayerConfiguration | Symbology | Symbology3D | Labeling | Fields | Forms | Actions |
191 MapTips | Diagrams | AttributeTable | Rendering | CustomProperties | GeometryOptions | Relations | Temporal | Legend | Elevation | Notes,
192 };
193 Q_ENUM( StyleCategory )
194 Q_DECLARE_FLAGS( StyleCategories, StyleCategory )
195 Q_FLAG( StyleCategories )
196
203 QgsMapLayer( Qgis::LayerType type = Qgis::LayerType::Vector, const QString &name = QString(), const QString &source = QString() );
204
205 ~QgsMapLayer() override;
206
207 QgsMapLayer( const QgsMapLayer & ) = delete;
208 QgsMapLayer &operator=( const QgsMapLayer & ) = delete;
209
215 virtual QgsMapLayer *clone() const = 0;
216
220 Qgis::LayerType type() const;
221
232 QgsMapLayer::LayerFlags flags() const;
233
244 void setFlags( QgsMapLayer::LayerFlags flags );
245
255 virtual Qgis::MapLayerProperties properties() const;
256
261 static QString extensionPropertyType( PropertyType type );
262
269 QString id() const;
270
286 bool setId( const QString &id );
287
292 void setName( const QString &name );
293
298 QString name() const;
299
303 Q_INVOKABLE virtual QgsDataProvider *dataProvider();
304
309 virtual const QgsDataProvider *dataProvider() const SIP_SKIP;
310
315 QgsProviderMetadata *providerMetadata() const;
316
322 Q_DECL_DEPRECATED void setShortName( const QString &shortName ) SIP_DEPRECATED;
323
329 Q_DECL_DEPRECATED QString shortName() const SIP_DEPRECATED;
330
336 Q_DECL_DEPRECATED void setTitle( const QString &title ) SIP_DEPRECATED;
337
343 Q_DECL_DEPRECATED QString title() const SIP_DEPRECATED;
344
350 Q_DECL_DEPRECATED void setAbstract( const QString &abstract ) SIP_DEPRECATED;
351
357 Q_DECL_DEPRECATED QString abstract() const SIP_DEPRECATED;
358
364 Q_DECL_DEPRECATED void setKeywordList( const QString &keywords ) SIP_DEPRECATED;
365
371 Q_DECL_DEPRECATED QString keywordList() const SIP_DEPRECATED;
372
378 Q_DECL_DEPRECATED void setDataUrl( const QString &dataUrl ) SIP_DEPRECATED;
379
385 Q_DECL_DEPRECATED QString dataUrl() const SIP_DEPRECATED;
386
392 Q_DECL_DEPRECATED void setDataUrlFormat( const QString &dataUrlFormat ) SIP_DEPRECATED;
393
399 Q_DECL_DEPRECATED QString dataUrlFormat() const SIP_DEPRECATED;
400
406 Q_DECL_DEPRECATED void setAttribution( const QString &attrib ) SIP_DEPRECATED;
407
413 Q_DECL_DEPRECATED QString attribution() const SIP_DEPRECATED;
414
420 Q_DECL_DEPRECATED void setAttributionUrl( const QString &attribUrl ) SIP_DEPRECATED;
421
427 Q_DECL_DEPRECATED QString attributionUrl() const SIP_DEPRECATED;
428
429 /* Layer metadataUrl information */
430
435 QgsMapLayerServerProperties *serverProperties() { return mServerProperties.get(); };
436
441 const QgsMapLayerServerProperties *serverProperties() const { return mServerProperties.get(); } SIP_SKIP;
442
451 Q_DECL_DEPRECATED void setMetadataUrl( const QString &metaUrl ) SIP_DEPRECATED;
452
462 Q_DECL_DEPRECATED QString metadataUrl() const SIP_DEPRECATED;
463
472 Q_DECL_DEPRECATED void setMetadataUrlType( const QString &metaUrlType ) SIP_DEPRECATED;
473
483 Q_DECL_DEPRECATED QString metadataUrlType() const SIP_DEPRECATED;
484
493 Q_DECL_DEPRECATED void setMetadataUrlFormat( const QString &metaUrlFormat ) SIP_DEPRECATED;
494
504 Q_DECL_DEPRECATED QString metadataUrlFormat() const SIP_DEPRECATED;
505
511 void setBlendMode( QPainter::CompositionMode blendMode );
512
517 QPainter::CompositionMode blendMode() const;
518
527 virtual void setOpacity( double opacity );
528
537 virtual double opacity() const;
538
540 bool readOnly() const { return isReadOnly(); }
541
545 Q_INVOKABLE virtual void reload() {}
546
551
553 virtual QgsRectangle extent() const;
554
559 virtual QgsBox3D extent3D() const;
560
569 QgsRectangle wgs84Extent( bool forceRecalculate = false ) const;
570
576 bool isValid() const;
577
578 // TODO QGIS 4.0: consider changing bool hidePassword to an enumeration: HIDE_CREDENTIALS / REDACT_CREDENTIALS
579 // to avoid the ambiguity of the double negation (hide = false)
580
588 QString publicSource( bool hidePassword = false ) const;
589
595 QString source() const;
596
601 virtual QStringList subLayers() const;
602
607 virtual void setLayerOrder( const QStringList &layers );
608
614 virtual void setSubLayerVisibility( const QString &name, bool visible );
615
622 virtual bool supportsEditing() const;
623
625 virtual bool isEditable() const;
626
632 virtual bool isModified() const;
633
637 virtual bool isSpatial() const;
638
648 virtual bool isTemporary() const;
649
655 {
656 FlagDontResolveLayers = 1 << 0,
657 FlagTrustLayerMetadata = 1 << 1,
658 FlagReadExtentFromXml = 1 << 2,
659 FlagForceReadOnly = 1 << 3,
660 };
661 Q_DECLARE_FLAGS( ReadFlags, ReadFlag )
662
663
680 bool readLayerXml( const QDomElement &layerElement, QgsReadWriteContext &context,
681 QgsMapLayer::ReadFlags flags = QgsMapLayer::ReadFlags(), QgsDataProvider *preloadedProvider SIP_TRANSFER = nullptr );
682
698 bool writeLayerXml( QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context ) const;
699
703 virtual void resolveReferences( QgsProject *project );
704
709 Q_INVOKABLE QStringList customPropertyKeys() const;
710
716 Q_INVOKABLE void setCustomProperty( const QString &key, const QVariant &value );
717
722 Q_INVOKABLE QVariant customProperty( const QString &value, const QVariant &defaultValue = QVariant() ) const;
723
727 void setCustomProperties( const QgsObjectCustomProperties &properties );
728
734 const QgsObjectCustomProperties &customProperties() const;
735
745 virtual int listStylesInDatabase( QStringList &ids SIP_OUT, QStringList &names SIP_OUT,
746 QStringList &descriptions SIP_OUT, QString &msgError SIP_OUT );
747
751 virtual QString getStyleFromDatabase( const QString &styleId, QString &msgError SIP_OUT );
752
759 virtual bool deleteStyleFromDatabase( const QString &styleId, QString &msgError SIP_OUT );
760
766 enum class SaveStyleResult SIP_ENUM_BASETYPE( IntFlag )
767 {
768 Success = 0,
769 QmlGenerationFailed = 1 << 0,
770 SldGenerationFailed = 1 << 1,
771 DatabaseWriteFailed = 1 << 2,
772 };
773 Q_ENUM( SaveStyleResult )
774
775
781 Q_FLAG( SaveStyleResults )
782
800 Q_DECL_DEPRECATED virtual void saveStyleToDatabase( const QString &name, const QString &description,
801 bool useAsDefault, const QString &uiFileContent,
802 QString &msgError SIP_OUT,
803 QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) SIP_DEPRECATED;
804
818 QgsMapLayer::SaveStyleResults saveStyleToDatabaseV2( const QString &name, const QString &description,
819 bool useAsDefault, const QString &uiFileContent,
820 QString &msgError SIP_OUT,
821 QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories );
822
823 // 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".
824 // 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.
825
836 virtual QString loadNamedStyle( const QString &theURI, bool &resultFlag SIP_OUT, bool loadFromLocalDb,
837 QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories,
838 Qgis::LoadStyleFlags flags = Qgis::LoadStyleFlags() );
839
840#ifndef SIP_RUN
841
852 template <class T>
853 T customEnumProperty( const QString &key, const T &defaultValue )
854 {
855 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
856 Q_ASSERT( metaEnum.isValid() );
857 if ( !metaEnum.isValid() )
858 {
859 QgsDebugError( QStringLiteral( "Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
860 }
861
862 T v;
863 bool ok = false;
864
865 if ( metaEnum.isValid() )
866 {
867 // read as string
868 QByteArray ba = customProperty( key, metaEnum.valueToKey( static_cast<int>( defaultValue ) ) ).toString().toUtf8();
869 const char *vs = ba.data();
870 v = static_cast<T>( metaEnum.keyToValue( vs, &ok ) );
871 if ( ok )
872 return v;
873 }
874
875 // if failed, try to read as int (old behavior)
876 // this code shall be removed later
877 // then the method could be marked as const
878 v = static_cast<T>( customProperty( key, static_cast<int>( defaultValue ) ).toInt( &ok ) );
879 if ( metaEnum.isValid() )
880 {
881 if ( !ok || !metaEnum.valueToKey( static_cast<int>( v ) ) )
882 {
883 v = defaultValue;
884 }
885 else
886 {
887 // found property as an integer
888 // convert the property to the new form (string)
889 setCustomEnumProperty( key, v );
890 }
891 }
892
893 return v;
894 }
895
904 template <class T>
905 void setCustomEnumProperty( const QString &key, const T &value )
906 {
907 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
908 Q_ASSERT( metaEnum.isValid() );
909 if ( metaEnum.isValid() )
910 {
911 setCustomProperty( key, metaEnum.valueToKey( static_cast<int>( value ) ) );
912 }
913 else
914 {
915 QgsDebugError( QStringLiteral( "Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
916 }
917 }
918
930 template <class T>
931 T customFlagProperty( const QString &key, const T &defaultValue )
932 {
933 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
934 Q_ASSERT( metaEnum.isValid() );
935 if ( !metaEnum.isValid() )
936 {
937 QgsDebugError( QStringLiteral( "Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
938 }
939
940 T v = defaultValue;
941 bool ok = false;
942
943 if ( metaEnum.isValid() )
944 {
945 // read as string
946 QByteArray ba = customProperty( key, metaEnum.valueToKeys( defaultValue ) ).toString().toUtf8();
947 const char *vs = ba.data();
948 v = static_cast<T>( metaEnum.keysToValue( vs, &ok ) );
949 }
950 if ( !ok )
951 {
952 // if failed, try to read as int
953 const int intValue = customProperty( key, static_cast<int>( defaultValue ) ).toInt( &ok );
954 if ( metaEnum.isValid() )
955 {
956 if ( ok )
957 {
958 // check that the int value does correspond to a flag
959 // see https://stackoverflow.com/a/68495949/1548052
960 const QByteArray keys = metaEnum.valueToKeys( intValue );
961 const int intValueCheck = metaEnum.keysToValue( keys );
962 if ( intValue != intValueCheck )
963 {
964 v = defaultValue;
965 }
966 else
967 {
968 // found property as an integer
969 v = T( intValue );
970 // convert the property to the new form (string)
971 // this code could be removed
972 // then the method could be marked as const
973 setCustomFlagProperty( key, v );
974 }
975 }
976 else
977 {
978 v = defaultValue;
979 }
980 }
981 }
982
983 return v;
984 }
985
994 template <class T>
995 void setCustomFlagProperty( const QString &key, const T &value )
996 {
997 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
998 Q_ASSERT( metaEnum.isValid() );
999 if ( metaEnum.isValid() )
1000 {
1001 setCustomProperty( key, metaEnum.valueToKeys( value ) );
1002 }
1003 else
1004 {
1005 QgsDebugError( QStringLiteral( "Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
1006 }
1007 }
1008#endif
1009
1010
1015 void removeCustomProperty( const QString &key );
1016
1022 virtual QgsError error() const;
1023
1036
1055 QgsCoordinateReferenceSystem verticalCrs() const;
1056
1075 QgsCoordinateReferenceSystem crs3D() const;
1076
1087 void setCrs( const QgsCoordinateReferenceSystem &srs, bool emitSignal = true );
1088
1108 bool setVerticalCrs( const QgsCoordinateReferenceSystem &crs, QString *errorMessage SIP_OUT = nullptr );
1109
1115 QgsCoordinateTransformContext transformContext( ) const;
1116
1117
1122 static QString formatLayerName( const QString &name );
1123
1130 virtual QString metadataUri() const;
1131
1137 void exportNamedMetadata( QDomDocument &doc, QString &errorMsg ) const;
1138
1147 virtual QString saveDefaultMetadata( bool &resultFlag SIP_OUT );
1148
1162 QString saveNamedMetadata( const QString &uri, bool &resultFlag SIP_OUT );
1163
1164 // 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".
1165 // 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.
1166
1180 virtual QString loadNamedMetadata( const QString &uri, bool &resultFlag SIP_OUT );
1181
1182 // 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".
1183 // 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.
1184
1193 virtual QString loadDefaultMetadata( bool &resultFlag SIP_OUT );
1194
1202 bool loadNamedMetadataFromDatabase( const QString &db, const QString &uri, QString &qmd );
1203
1210 bool importNamedMetadata( QDomDocument &document, QString &errorMessage );
1211
1220 virtual QString styleURI() const;
1221
1222 // 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".
1223 // 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.
1224
1234 virtual QString loadDefaultStyle( bool &resultFlag SIP_OUT );
1235
1236 // 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".
1237 // 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.
1238
1255 virtual QString loadNamedStyle( const QString &uri, bool &resultFlag SIP_OUT, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories, Qgis::LoadStyleFlags flags = Qgis::LoadStyleFlags() );
1256
1264 virtual bool loadNamedStyleFromDatabase( const QString &db, const QString &uri, QString &qml SIP_OUT );
1265
1274 virtual bool importNamedStyle( QDomDocument &doc, QString &errorMsg SIP_OUT,
1276
1285 virtual void exportNamedStyle( QDomDocument &doc, QString &errorMsg SIP_OUT, const QgsReadWriteContext &context = QgsReadWriteContext(),
1287
1288
1296 Q_DECL_DEPRECATED virtual void exportSldStyle( QDomDocument &doc, QString &errorMsg ) const SIP_DEPRECATED;
1297
1305 Q_DECL_DEPRECATED virtual void exportSldStyleV2( QDomDocument &doc, QString &errorMsg, QgsSldExportContext &exportContext ) const SIP_DEPRECATED;
1306
1316 virtual QDomDocument exportSldStyleV3( QgsSldExportContext &exportContext ) const;
1317
1329 virtual QString saveDefaultStyle( bool &resultFlag SIP_OUT, StyleCategories categories );
1330
1342 Q_DECL_DEPRECATED virtual QString saveDefaultStyle( bool &resultFlag SIP_OUT ) SIP_DEPRECATED;
1343
1359 virtual QString saveNamedStyle( const QString &uri, bool &resultFlag SIP_OUT, StyleCategories categories = AllStyleCategories );
1360
1370 virtual QString saveSldStyle( const QString &uri, bool &resultFlag SIP_OUT ) const;
1371
1382 virtual QString saveSldStyleV2( bool &resultFlag SIP_OUT, QgsSldExportContext &exportContext ) const;
1383
1392 virtual QString loadSldStyle( const QString &uri, bool &resultFlag SIP_OUT );
1393
1394 virtual bool readSld( const QDomNode &node, QString &errorMessage )
1395 { Q_UNUSED( node ) errorMessage = QStringLiteral( "Layer type %1 not supported" ).arg( static_cast<int>( type() ) ); return false; }
1396
1397
1398
1407 virtual bool readSymbology( const QDomNode &node, QString &errorMessage,
1408 QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories ) = 0;
1409
1419 virtual bool readStyle( const QDomNode &node, QString &errorMessage,
1420 QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories );
1421
1432 virtual bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context,
1433 StyleCategories categories = AllStyleCategories ) const = 0;
1434
1446 virtual bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context,
1447 StyleCategories categories = AllStyleCategories ) const;
1448
1449
1480 void setDataSource( const QString &dataSource, const QString &baseName = QString(), const QString &provider = QString(), bool loadDefaultStyleFlag = false );
1481
1511 void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, bool loadDefaultStyleFlag = false );
1512
1542 void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, Qgis::DataProviderReadFlags flags );
1543
1547 QString providerType() const;
1548
1550 QUndoStack *undoStack();
1551
1555 QUndoStack *undoStackStyles();
1556
1562 Q_DECL_DEPRECATED void setLegendUrl( const QString &legendUrl ) SIP_DEPRECATED;
1563
1569 Q_DECL_DEPRECATED QString legendUrl() const SIP_DEPRECATED;
1570
1576 Q_DECL_DEPRECATED void setLegendUrlFormat( const QString &legendUrlFormat ) SIP_DEPRECATED;
1577
1583 Q_DECL_DEPRECATED QString legendUrlFormat() const SIP_DEPRECATED;
1584
1589 void setLegend( QgsMapLayerLegend *legend SIP_TRANSFER );
1590
1594 QgsMapLayerLegend *legend() const;
1595
1599 QgsMapLayerStyleManager *styleManager() const;
1600
1604 void setRenderer3D( QgsAbstract3DRenderer *renderer SIP_TRANSFER );
1605
1609 QgsAbstract3DRenderer *renderer3D() const;
1610
1619 bool isInScaleRange( double scale ) const;
1620
1631 double minimumScale() const;
1632
1643 double maximumScale() const;
1644
1653 bool hasScaleBasedVisibility() const;
1654
1661 Q_DECL_DEPRECATED bool hasAutoRefreshEnabled() const SIP_DEPRECATED;
1662
1669 Qgis::AutoRefreshMode autoRefreshMode() const;
1670
1677 int autoRefreshInterval() const;
1678
1689 void setAutoRefreshInterval( int interval );
1690
1697 Q_DECL_DEPRECATED void setAutoRefreshEnabled( bool enabled ) SIP_DEPRECATED;
1698
1705 void setAutoRefreshMode( Qgis::AutoRefreshMode mode );
1706
1712 virtual const QgsLayerMetadata &metadata() const;
1713
1719 virtual void setMetadata( const QgsLayerMetadata &metadata );
1720
1724 virtual QString htmlMetadata() const;
1725
1727 virtual QDateTime timestamp() const;
1728
1735 virtual QSet<QgsMapLayerDependency> dependencies() const;
1736
1741 QString refreshOnNotifyMessage() const { return mRefreshOnNofifyMessage; }
1742
1747 bool isRefreshOnNotifyEnabled() const { return mIsRefreshOnNofifyEnabled; }
1748
1757 QString originalXmlProperties() const;
1758
1766 void setOriginalXmlProperties( const QString &originalXmlProperties );
1767
1772 static QString generateId( const QString &layerName );
1773
1783 virtual bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
1784
1791
1798
1805
1806
1812 virtual QgsAbstractProfileSource *profileSource() { return nullptr; }
1813
1819 QString legendPlaceholderImage() const { return mLegendPlaceholderImage;}
1820
1826 void setLegendPlaceholderImage( const QString &imgPath ) { mLegendPlaceholderImage = imgPath; }
1827
1834 virtual bool hasMapTips() const;
1835
1843 QString mapTipTemplate() const;
1844
1852 void setMapTipTemplate( const QString &mapTipTemplate );
1853
1860 void setMapTipsEnabled( bool enabled );
1861
1866 bool mapTipsEnabled() const;
1867
1875 static Qgis::DataProviderReadFlags providerReadFlags( const QDomNode &layerNode, QgsMapLayer::ReadFlags layerReadFlags );
1876
1877 public slots:
1878
1888 void setMinimumScale( double scale );
1889
1899 void setMaximumScale( double scale );
1900
1908 void setScaleBasedVisibility( bool enabled );
1909
1918 void triggerRepaint( bool deferredUpdate = false );
1919
1926 void trigger3DUpdate();
1927
1931 void emitStyleChanged();
1932
1940 virtual bool setDependencies( const QSet<QgsMapLayerDependency> &layers );
1941
1946 void setRefreshOnNotifyEnabled( bool enabled );
1947
1954 void setRefreshOnNofifyMessage( const QString &message ) { mRefreshOnNofifyMessage = message; }
1955
1961 virtual void setTransformContext( const QgsCoordinateTransformContext &transformContext ) = 0;
1962
1963#ifdef SIP_RUN
1964 SIP_PYOBJECT __repr__();
1965 % MethodCode
1966 QString str = QStringLiteral( "<QgsMapLayer: '%1' (%2)>" ).arg( sipCpp->name(), sipCpp->dataProvider() ? sipCpp->dataProvider()->name() : QStringLiteral( "Invalid" ) );
1967 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
1968 % End
1969#endif
1970
1977 QgsProject *project() const;
1978
1979 signals:
1980
1988
1990 void statusChanged( const QString &status );
1991
2000 void idChanged( const QString &id );
2001
2006
2016
2027
2044
2051 void repaintRequested( bool deferredUpdate = false );
2052
2055
2058
2060 void blendModeChanged( QPainter::CompositionMode blendMode );
2061
2070 void opacityChanged( double opacity );
2071
2077
2089
2094
2099
2106
2112
2117
2124
2129 void autoRefreshIntervalChanged( int interval );
2130
2137
2145
2154
2161
2168
2174 void customPropertyChanged( const QString &key );
2175
2181
2187
2193
2200
2208
2209 private slots:
2210
2211 void onNotified( const QString &message );
2212
2228 virtual void setDataSourcePrivate( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, Qgis::DataProviderReadFlags flags );
2229
2230 protected:
2231
2236 void clone( QgsMapLayer *layer ) const;
2237
2239 virtual void setExtent( const QgsRectangle &rect );
2240
2245 virtual void setExtent3D( const QgsBox3D &box );
2246
2248 void setValid( bool valid );
2249
2254 virtual bool readXml( const QDomNode &layer_node, QgsReadWriteContext &context );
2255
2260 virtual bool writeXml( QDomNode &layer_node, QDomDocument &document, const QgsReadWriteContext &context ) const;
2261
2273 virtual QString encodedSource( const QString &source, const QgsReadWriteContext &context ) const;
2274
2287 virtual QString decodedSource( const QString &source, const QString &dataProvider, const QgsReadWriteContext &context ) const;
2288
2294 void readCustomProperties( const QDomNode &layerNode, const QString &keyStartsWith = QString() );
2295
2297 void writeCustomProperties( QDomNode &layerNode, QDomDocument &doc ) const;
2298
2300 void readStyleManager( const QDomNode &layerNode );
2302 void writeStyleManager( QDomNode &layerNode, QDomDocument &doc ) const;
2303
2307 void writeCommonStyle( QDomElement &layerElement, QDomDocument &document,
2308 const QgsReadWriteContext &context,
2309 StyleCategories categories = AllStyleCategories ) const;
2310
2314 void readCommonStyle( const QDomElement &layerElement, const QgsReadWriteContext &context,
2315 StyleCategories categories = AllStyleCategories );
2316
2318 void setProviderType( const QString &providerType );
2319
2320#ifndef SIP_RUN
2321#if 0
2323 void connectNotify( const char *signal ) override;
2324#endif
2325#endif
2326
2328 void appendError( const QgsErrorMessage &error ) { mError.append( error );}
2330 void setError( const QgsError &error ) { mError = error;}
2331
2338 void invalidateWgs84Extent();
2339
2341 bool mValid = false;
2342
2345
2347 QString mLayerName;
2348
2351
2353 QSet<QgsMapLayerDependency> mDependencies;
2354
2360 Q_DECL_DEPRECATED bool hasDependencyCycle( const QSet<QgsMapLayerDependency> & ) const {return false;}
2361
2362 bool mIsRefreshOnNofifyEnabled = false;
2364
2367
2368 //TODO QGIS 4 - move to readXml as a new argument (breaks API)
2369
2372
2378 bool mShouldValidateCrs = true;
2379
2385 double mLayerOpacity = 1.0;
2386
2392 int mBlockStyleChangedSignal = 0;
2393
2394#ifndef SIP_RUN
2395
2404 QString crsHtmlMetadata() const;
2405#endif
2406
2407#ifndef SIP_RUN
2408
2417 QString generalHtmlMetadata() const;
2418
2427 QString customPropertyHtmlMetadata() const;
2428#endif
2429
2430#ifndef SIP_RUN
2431
2439 std::unique_ptr<QgsDataProvider> mPreloadedProvider;
2440#endif
2441
2442 private:
2443
2444 virtual QString baseURI( PropertyType type ) const;
2445 QString saveNamedProperty( const QString &uri, QgsMapLayer::PropertyType type,
2446 bool &resultFlag, StyleCategories categories = AllStyleCategories );
2447 QString loadNamedProperty( const QString &uri, QgsMapLayer::PropertyType type,
2448 bool &namedPropertyExists, bool &propertySuccessfullyLoaded, StyleCategories categories = AllStyleCategories, Qgis::LoadStyleFlags flags = Qgis::LoadStyleFlags() );
2449 bool loadNamedPropertyFromDatabase( const QString &db, const QString &uri, QString &xml, QgsMapLayer::PropertyType type );
2450
2451 // const method because extents are mutable
2452 void updateExtent( const QgsRectangle &extent ) const;
2453 void updateExtent( const QgsBox3D &extent ) const;
2454
2455 bool rebuildCrs3D( QString *error = nullptr );
2456
2461 virtual bool isReadOnly() const;
2462
2468 QgsCoordinateReferenceSystem mVerticalCrs;
2470
2472 QString mID;
2473
2475 Qgis::LayerType mLayerType;
2476
2477 LayerFlags mFlags = LayerFlags( Identifiable | Removable | Searchable );
2478
2480 QPainter::CompositionMode mBlendMode = QPainter::CompositionMode_SourceOver;
2481
2483 QString mTag;
2484
2485 //set some generous defaults for scale based visibility
2486
2488 double mMinScale = 0;
2490 double mMaxScale = 100000000;
2492 bool mScaleBasedVisibility = false;
2493
2497 std::unique_ptr< QgsMapLayerServerProperties > mServerProperties;
2498
2500 QUndoStack *mUndoStack = nullptr;
2501
2502 QUndoStack *mUndoStackStyles = nullptr;
2503
2505 QgsObjectCustomProperties mCustomProperties;
2506
2508 std::unique_ptr<QgsMapLayerLegend> mLegend;
2509
2511 std::unique_ptr<QgsMapLayerStyleManager> mStyleManager;
2512
2514
2516 QTimer *mRefreshTimer = nullptr;
2517
2518 QgsLayerMetadata mMetadata;
2519
2521 std::unique_ptr<QgsAbstract3DRenderer> m3DRenderer;
2522
2524 mutable QgsBox3D mExtent3D;
2525
2527 mutable QgsRectangle mExtent2D;
2528
2530 mutable QgsRectangle mWgs84Extent;
2531
2537 QString mOriginalXmlProperties;
2538
2540 bool mRepaintRequestedFired = false;
2541
2543 QString mLegendPlaceholderImage;
2544
2546 QString mMapTipTemplate;
2547
2549 bool mMapTipsEnabled = true;
2550
2551 friend class QgsVectorLayer;
2552 friend class TestQgsProject;
2553 friend class TestQgsMapLayer;
2554};
2555
2559
2560
2561#ifndef SIP_RUN
2562
2567typedef QPointer< QgsMapLayer > QgsWeakMapLayerPointer;
2568
2573typedef QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList;
2574#endif
2575
2576#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.
Interface for classes which can generate elevation profiles.
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:78
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.
virtual QgsAbstractProfileSource * profileSource()
Returns the layer's profile source if it has profile capabilities.
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.