QGIS API Documentation 3.41.0-Master (88383c3d16f)
Loading...
Searching...
No Matches
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
75class CORE_EXPORT QgsMapLayer : public QObject
76{
77 Q_OBJECT
78
79 Q_PROPERTY( QString id READ id WRITE setId NOTIFY idChanged )
80 Q_PROPERTY( QString name READ name WRITE setName NOTIFY nameChanged )
81 Q_PROPERTY( int autoRefreshInterval READ autoRefreshInterval WRITE setAutoRefreshInterval NOTIFY autoRefreshIntervalChanged )
82 Q_PROPERTY( QgsLayerMetadata metadata READ metadata WRITE setMetadata NOTIFY metadataChanged )
83 Q_PROPERTY( QgsCoordinateReferenceSystem crs READ crs WRITE setCrs NOTIFY crsChanged )
84 Q_PROPERTY( QgsCoordinateReferenceSystem verticalCrs READ verticalCrs WRITE setVerticalCrs NOTIFY verticalCrsChanged )
85 Q_PROPERTY( QgsCoordinateReferenceSystem crs3D READ crs3D NOTIFY crs3DChanged )
86 Q_PROPERTY( Qgis::LayerType type READ type CONSTANT )
87 Q_PROPERTY( bool isValid READ isValid NOTIFY isValidChanged )
88 Q_PROPERTY( double opacity READ opacity WRITE setOpacity NOTIFY opacityChanged )
89 Q_PROPERTY( QString mapTipTemplate READ mapTipTemplate WRITE setMapTipTemplate NOTIFY mapTipTemplateChanged )
90 Q_PROPERTY( bool mapTipsEnabled READ mapTipsEnabled WRITE setMapTipsEnabled NOTIFY mapTipsEnabledChanged )
91
92#ifdef SIP_RUN
94 QgsMapLayer *layer = qobject_cast<QgsMapLayer *>( sipCpp );
95
96 sipType = 0;
97
98 if ( layer )
99 {
100 switch ( layer->type() )
101 {
103 sipType = sipType_QgsVectorLayer;
104 break;
106 sipType = sipType_QgsRasterLayer;
107 break;
109 sipType = sipType_QgsPluginLayer;
110 break;
112 sipType = sipType_QgsMeshLayer;
113 break;
115 sipType = sipType_QgsVectorTileLayer;
116 break;
118 sipType = sipType_QgsAnnotationLayer;
119 break;
121 sipType = sipType_QgsPointCloudLayer;
122 break;
124 sipType = sipType_QgsGroupLayer;
125 break;
127 sipType = sipType_QgsTiledSceneLayer;
128 break;
129 default:
130 sipType = nullptr;
131 break;
132 }
133 }
134 SIP_END
135#endif
136
137 public:
138
143 {
144 Style = 0,
146 };
147
154 {
155 Identifiable = 1 << 0,
156 Removable = 1 << 1,
157 Searchable = 1 << 2,
158 Private = 1 << 3,
159 };
160 Q_ENUM( LayerFlag )
161 Q_DECLARE_FLAGS( LayerFlags, LayerFlag )
162 Q_FLAG( LayerFlags )
163
169 {
170 LayerConfiguration = 1 << 0,
171 Symbology = 1 << 1,
172 Symbology3D = 1 << 2,
173 Labeling = 1 << 3,
174 Fields = 1 << 4,
175 Forms = 1 << 5,
176 Actions = 1 << 6,
177 MapTips = 1 << 7,
178 Diagrams = 1 << 8,
179 AttributeTable = 1 << 9,
180 Rendering = 1 << 10,
181 CustomProperties = 1 << 11,
182 GeometryOptions = 1 << 12,
183 Relations = 1 << 13,
184 Temporal = 1 << 14,
185 Legend = 1 << 15,
186 Elevation = 1 << 16,
187 Notes = 1 << 17,
188 AllStyleCategories = LayerConfiguration | Symbology | Symbology3D | Labeling | Fields | Forms | Actions |
189 MapTips | Diagrams | AttributeTable | Rendering | CustomProperties | GeometryOptions | Relations | Temporal | Legend | Elevation | Notes,
190 };
191 Q_ENUM( StyleCategory )
192 Q_DECLARE_FLAGS( StyleCategories, StyleCategory )
193 Q_FLAG( StyleCategories )
194
201 QgsMapLayer( Qgis::LayerType type = Qgis::LayerType::Vector, const QString &name = QString(), const QString &source = QString() );
202
203 ~QgsMapLayer() override;
204
205 QgsMapLayer( const QgsMapLayer & ) = delete;
206 QgsMapLayer &operator=( const QgsMapLayer & ) = delete;
207
213 virtual QgsMapLayer *clone() const = 0;
214
218 Qgis::LayerType type() const;
219
230 QgsMapLayer::LayerFlags flags() const;
231
242 void setFlags( QgsMapLayer::LayerFlags flags );
243
253 virtual Qgis::MapLayerProperties properties() const;
254
259 static QString extensionPropertyType( PropertyType type );
260
267 QString id() const;
268
284 bool setId( const QString &id );
285
290 void setName( const QString &name );
291
296 QString name() const;
297
301 Q_INVOKABLE virtual QgsDataProvider *dataProvider();
302
307 virtual const QgsDataProvider *dataProvider() const SIP_SKIP;
308
313 QgsProviderMetadata *providerMetadata() const;
314
320 Q_DECL_DEPRECATED void setShortName( const QString &shortName ) SIP_DEPRECATED;
321
327 Q_DECL_DEPRECATED QString shortName() const SIP_DEPRECATED;
328
334 Q_DECL_DEPRECATED void setTitle( const QString &title ) SIP_DEPRECATED;
335
341 Q_DECL_DEPRECATED QString title() const SIP_DEPRECATED;
342
348 Q_DECL_DEPRECATED void setAbstract( const QString &abstract ) SIP_DEPRECATED;
349
355 Q_DECL_DEPRECATED QString abstract() const SIP_DEPRECATED;
356
362 Q_DECL_DEPRECATED void setKeywordList( const QString &keywords ) SIP_DEPRECATED;
363
369 Q_DECL_DEPRECATED QString keywordList() const SIP_DEPRECATED;
370
376 Q_DECL_DEPRECATED void setDataUrl( const QString &dataUrl ) SIP_DEPRECATED;
377
383 Q_DECL_DEPRECATED QString dataUrl() const SIP_DEPRECATED;
384
390 Q_DECL_DEPRECATED void setDataUrlFormat( const QString &dataUrlFormat ) SIP_DEPRECATED;
391
397 Q_DECL_DEPRECATED QString dataUrlFormat() const SIP_DEPRECATED;
398
404 Q_DECL_DEPRECATED void setAttribution( const QString &attrib ) SIP_DEPRECATED;
405
411 Q_DECL_DEPRECATED QString attribution() const SIP_DEPRECATED;
412
418 Q_DECL_DEPRECATED void setAttributionUrl( const QString &attribUrl ) SIP_DEPRECATED;
419
425 Q_DECL_DEPRECATED QString attributionUrl() const SIP_DEPRECATED;
426
427 /* Layer metadataUrl information */
428
433 QgsMapLayerServerProperties *serverProperties() { return mServerProperties.get(); };
434
439 const QgsMapLayerServerProperties *serverProperties() const { return mServerProperties.get(); } SIP_SKIP;
440
449 Q_DECL_DEPRECATED void setMetadataUrl( const QString &metaUrl ) SIP_DEPRECATED;
450
460 Q_DECL_DEPRECATED QString metadataUrl() const SIP_DEPRECATED;
461
470 Q_DECL_DEPRECATED void setMetadataUrlType( const QString &metaUrlType ) SIP_DEPRECATED;
471
481 Q_DECL_DEPRECATED QString metadataUrlType() const SIP_DEPRECATED;
482
491 Q_DECL_DEPRECATED void setMetadataUrlFormat( const QString &metaUrlFormat ) SIP_DEPRECATED;
492
502 Q_DECL_DEPRECATED QString metadataUrlFormat() const SIP_DEPRECATED;
503
509 void setBlendMode( QPainter::CompositionMode blendMode );
510
515 QPainter::CompositionMode blendMode() const;
516
525 virtual void setOpacity( double opacity );
526
535 virtual double opacity() const;
536
538 bool readOnly() const { return isReadOnly(); }
539
543 Q_INVOKABLE virtual void reload() {}
544
549
551 virtual QgsRectangle extent() const;
552
557 virtual QgsBox3D extent3D() const;
558
567 QgsRectangle wgs84Extent( bool forceRecalculate = false ) const;
568
574 bool isValid() const;
575
576 // TODO QGIS 4.0: consider changing bool hidePassword to an enumeration: HIDE_CREDENTIALS / REDACT_CREDENTIALS
577 // to avoid the ambiguity of the double negation (hide = false)
578
586 QString publicSource( bool hidePassword = false ) const;
587
593 QString source() const;
594
599 virtual QStringList subLayers() const;
600
605 virtual void setLayerOrder( const QStringList &layers );
606
612 virtual void setSubLayerVisibility( const QString &name, bool visible );
613
620 virtual bool supportsEditing() const;
621
623 virtual bool isEditable() const;
624
630 virtual bool isModified() const;
631
635 virtual bool isSpatial() const;
636
646 virtual bool isTemporary() const;
647
653 {
654 FlagDontResolveLayers = 1 << 0,
655 FlagTrustLayerMetadata = 1 << 1,
656 FlagReadExtentFromXml = 1 << 2,
657 FlagForceReadOnly = 1 << 3,
658 };
659 Q_DECLARE_FLAGS( ReadFlags, ReadFlag )
660
661
678 bool readLayerXml( const QDomElement &layerElement, QgsReadWriteContext &context,
679 QgsMapLayer::ReadFlags flags = QgsMapLayer::ReadFlags(), QgsDataProvider *preloadedProvider SIP_TRANSFER = nullptr );
680
696 bool writeLayerXml( QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context ) const;
697
701 virtual void resolveReferences( QgsProject *project );
702
707 Q_INVOKABLE QStringList customPropertyKeys() const;
708
714 Q_INVOKABLE void setCustomProperty( const QString &key, const QVariant &value );
715
720 Q_INVOKABLE QVariant customProperty( const QString &value, const QVariant &defaultValue = QVariant() ) const;
721
725 void setCustomProperties( const QgsObjectCustomProperties &properties );
726
732 const QgsObjectCustomProperties &customProperties() const;
733
743 virtual int listStylesInDatabase( QStringList &ids SIP_OUT, QStringList &names SIP_OUT,
744 QStringList &descriptions SIP_OUT, QString &msgError SIP_OUT );
745
749 virtual QString getStyleFromDatabase( const QString &styleId, QString &msgError SIP_OUT );
750
757 virtual bool deleteStyleFromDatabase( const QString &styleId, QString &msgError SIP_OUT );
758
775 virtual void saveStyleToDatabase( const QString &name, const QString &description,
776 bool useAsDefault, const QString &uiFileContent,
777 QString &msgError SIP_OUT,
779
780
781 // 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".
782 // 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.
783
794 virtual QString loadNamedStyle( const QString &theURI, bool &resultFlag SIP_OUT, bool loadFromLocalDb,
797
798#ifndef SIP_RUN
799
810 template <class T>
811 T customEnumProperty( const QString &key, const T &defaultValue )
812 {
813 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
814 Q_ASSERT( metaEnum.isValid() );
815 if ( !metaEnum.isValid() )
816 {
817 QgsDebugError( QStringLiteral( "Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
818 }
819
820 T v;
821 bool ok = false;
822
823 if ( metaEnum.isValid() )
824 {
825 // read as string
826 QByteArray ba = customProperty( key, metaEnum.valueToKey( static_cast<int>( defaultValue ) ) ).toString().toUtf8();
827 const char *vs = ba.data();
828 v = static_cast<T>( metaEnum.keyToValue( vs, &ok ) );
829 if ( ok )
830 return v;
831 }
832
833 // if failed, try to read as int (old behavior)
834 // this code shall be removed later
835 // then the method could be marked as const
836 v = static_cast<T>( customProperty( key, static_cast<int>( defaultValue ) ).toInt( &ok ) );
837 if ( metaEnum.isValid() )
838 {
839 if ( !ok || !metaEnum.valueToKey( static_cast<int>( v ) ) )
840 {
841 v = defaultValue;
842 }
843 else
844 {
845 // found property as an integer
846 // convert the property to the new form (string)
847 setCustomEnumProperty( key, v );
848 }
849 }
850
851 return v;
852 }
853
862 template <class T>
863 void setCustomEnumProperty( const QString &key, const T &value )
864 {
865 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
866 Q_ASSERT( metaEnum.isValid() );
867 if ( metaEnum.isValid() )
868 {
869 setCustomProperty( key, metaEnum.valueToKey( static_cast<int>( value ) ) );
870 }
871 else
872 {
873 QgsDebugError( QStringLiteral( "Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
874 }
875 }
876
888 template <class T>
889 T customFlagProperty( const QString &key, const T &defaultValue )
890 {
891 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
892 Q_ASSERT( metaEnum.isValid() );
893 if ( !metaEnum.isValid() )
894 {
895 QgsDebugError( QStringLiteral( "Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
896 }
897
898 T v = defaultValue;
899 bool ok = false;
900
901 if ( metaEnum.isValid() )
902 {
903 // read as string
904 QByteArray ba = customProperty( key, metaEnum.valueToKeys( defaultValue ) ).toString().toUtf8();
905 const char *vs = ba.data();
906 v = static_cast<T>( metaEnum.keysToValue( vs, &ok ) );
907 }
908 if ( !ok )
909 {
910 // if failed, try to read as int
911 const int intValue = customProperty( key, static_cast<int>( defaultValue ) ).toInt( &ok );
912 if ( metaEnum.isValid() )
913 {
914 if ( ok )
915 {
916 // check that the int value does correspond to a flag
917 // see https://stackoverflow.com/a/68495949/1548052
918 const QByteArray keys = metaEnum.valueToKeys( intValue );
919 const int intValueCheck = metaEnum.keysToValue( keys );
920 if ( intValue != intValueCheck )
921 {
922 v = defaultValue;
923 }
924 else
925 {
926 // found property as an integer
927 v = T( intValue );
928 // convert the property to the new form (string)
929 // this code could be removed
930 // then the method could be marked as const
931 setCustomFlagProperty( key, v );
932 }
933 }
934 else
935 {
936 v = defaultValue;
937 }
938 }
939 }
940
941 return v;
942 }
943
952 template <class T>
953 void setCustomFlagProperty( const QString &key, const T &value )
954 {
955 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
956 Q_ASSERT( metaEnum.isValid() );
957 if ( metaEnum.isValid() )
958 {
959 setCustomProperty( key, metaEnum.valueToKeys( value ) );
960 }
961 else
962 {
963 QgsDebugError( QStringLiteral( "Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
964 }
965 }
966#endif
967
968
973 void removeCustomProperty( const QString &key );
974
980 virtual QgsError error() const;
981
994
1013 QgsCoordinateReferenceSystem verticalCrs() const;
1014
1033 QgsCoordinateReferenceSystem crs3D() const;
1034
1045 void setCrs( const QgsCoordinateReferenceSystem &srs, bool emitSignal = true );
1046
1066 bool setVerticalCrs( const QgsCoordinateReferenceSystem &crs, QString *errorMessage SIP_OUT = nullptr );
1067
1073 QgsCoordinateTransformContext transformContext( ) const;
1074
1075
1080 static QString formatLayerName( const QString &name );
1081
1088 virtual QString metadataUri() const;
1089
1095 void exportNamedMetadata( QDomDocument &doc, QString &errorMsg ) const;
1096
1105 virtual QString saveDefaultMetadata( bool &resultFlag SIP_OUT );
1106
1120 QString saveNamedMetadata( const QString &uri, bool &resultFlag );
1121
1122 // 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".
1123 // 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.
1124
1138 virtual QString loadNamedMetadata( const QString &uri, bool &resultFlag SIP_OUT );
1139
1140 // 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".
1141 // 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.
1142
1151 virtual QString loadDefaultMetadata( bool &resultFlag );
1152
1160 bool loadNamedMetadataFromDatabase( const QString &db, const QString &uri, QString &qmd );
1161
1168 bool importNamedMetadata( QDomDocument &document, QString &errorMessage );
1169
1178 virtual QString styleURI() const;
1179
1180 // 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".
1181 // 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.
1182
1192 virtual QString loadDefaultStyle( bool &resultFlag SIP_OUT );
1193
1194 // 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".
1195 // 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.
1196
1213 virtual QString loadNamedStyle( const QString &uri, bool &resultFlag SIP_OUT, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories, Qgis::LoadStyleFlags flags = Qgis::LoadStyleFlags() );
1214
1222 virtual bool loadNamedStyleFromDatabase( const QString &db, const QString &uri, QString &qml SIP_OUT );
1223
1232 virtual bool importNamedStyle( QDomDocument &doc, QString &errorMsg SIP_OUT,
1234
1243 virtual void exportNamedStyle( QDomDocument &doc, QString &errorMsg SIP_OUT, const QgsReadWriteContext &context = QgsReadWriteContext(),
1245
1246
1254 virtual void exportSldStyle( QDomDocument &doc, QString &errorMsg ) const;
1255
1264 virtual void exportSldStyleV2( QDomDocument &doc, QString &errorMsg, const QgsSldExportContext &exportContext ) const;
1265
1277 virtual QString saveDefaultStyle( bool &resultFlag SIP_OUT, StyleCategories categories );
1278
1290 Q_DECL_DEPRECATED virtual QString saveDefaultStyle( bool &resultFlag SIP_OUT ) SIP_DEPRECATED;
1291
1307 virtual QString saveNamedStyle( const QString &uri, bool &resultFlag SIP_OUT, StyleCategories categories = AllStyleCategories );
1308
1318 virtual QString saveSldStyle( const QString &uri, bool &resultFlag ) const;
1319
1330 virtual QString saveSldStyleV2( bool &resultFlag SIP_OUT, const QgsSldExportContext &exportContext ) const;
1331
1340 virtual QString loadSldStyle( const QString &uri, bool &resultFlag );
1341
1342 virtual bool readSld( const QDomNode &node, QString &errorMessage )
1343 { Q_UNUSED( node ) errorMessage = QStringLiteral( "Layer type %1 not supported" ).arg( static_cast<int>( type() ) ); return false; }
1344
1345
1346
1355 virtual bool readSymbology( const QDomNode &node, QString &errorMessage,
1356 QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories ) = 0;
1357
1367 virtual bool readStyle( const QDomNode &node, QString &errorMessage,
1368 QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories );
1369
1380 virtual bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context,
1381 StyleCategories categories = AllStyleCategories ) const = 0;
1382
1394 virtual bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context,
1395 StyleCategories categories = AllStyleCategories ) const;
1396
1397
1428 void setDataSource( const QString &dataSource, const QString &baseName = QString(), const QString &provider = QString(), bool loadDefaultStyleFlag = false );
1429
1459 void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, bool loadDefaultStyleFlag = false );
1460
1490 void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, Qgis::DataProviderReadFlags flags );
1491
1495 QString providerType() const;
1496
1498 QUndoStack *undoStack();
1499
1503 QUndoStack *undoStackStyles();
1504
1508 void setLegendUrl( const QString &legendUrl ) { mLegendUrl = legendUrl; }
1509
1513 QString legendUrl() const { return mLegendUrl; }
1514
1518 void setLegendUrlFormat( const QString &legendUrlFormat ) { mLegendUrlFormat = legendUrlFormat; }
1519
1523 QString legendUrlFormat() const { return mLegendUrlFormat; }
1524
1529 void setLegend( QgsMapLayerLegend *legend SIP_TRANSFER );
1530
1534 QgsMapLayerLegend *legend() const;
1535
1539 QgsMapLayerStyleManager *styleManager() const;
1540
1544 void setRenderer3D( QgsAbstract3DRenderer *renderer SIP_TRANSFER );
1545
1549 QgsAbstract3DRenderer *renderer3D() const;
1550
1559 bool isInScaleRange( double scale ) const;
1560
1571 double minimumScale() const;
1572
1583 double maximumScale() const;
1584
1593 bool hasScaleBasedVisibility() const;
1594
1601 Q_DECL_DEPRECATED bool hasAutoRefreshEnabled() const SIP_DEPRECATED;
1602
1609 Qgis::AutoRefreshMode autoRefreshMode() const;
1610
1617 int autoRefreshInterval() const;
1618
1629 void setAutoRefreshInterval( int interval );
1630
1637 Q_DECL_DEPRECATED void setAutoRefreshEnabled( bool enabled ) SIP_DEPRECATED;
1638
1645 void setAutoRefreshMode( Qgis::AutoRefreshMode mode );
1646
1652 virtual const QgsLayerMetadata &metadata() const;
1653
1659 virtual void setMetadata( const QgsLayerMetadata &metadata );
1660
1664 virtual QString htmlMetadata() const;
1665
1667 virtual QDateTime timestamp() const;
1668
1675 virtual QSet<QgsMapLayerDependency> dependencies() const;
1676
1681 QString refreshOnNotifyMessage() const { return mRefreshOnNofifyMessage; }
1682
1687 bool isRefreshOnNotifyEnabled() const { return mIsRefreshOnNofifyEnabled; }
1688
1697 QString originalXmlProperties() const;
1698
1706 void setOriginalXmlProperties( const QString &originalXmlProperties );
1707
1712 static QString generateId( const QString &layerName );
1713
1723 virtual bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
1724
1731
1738
1745
1751 QString legendPlaceholderImage() const { return mLegendPlaceholderImage;}
1752
1758 void setLegendPlaceholderImage( const QString &imgPath ) { mLegendPlaceholderImage = imgPath; }
1759
1766 virtual bool hasMapTips() const;
1767
1775 QString mapTipTemplate() const;
1776
1784 void setMapTipTemplate( const QString &mapTipTemplate );
1785
1792 void setMapTipsEnabled( bool enabled );
1793
1798 bool mapTipsEnabled() const;
1799
1807 static Qgis::DataProviderReadFlags providerReadFlags( const QDomNode &layerNode, QgsMapLayer::ReadFlags layerReadFlags );
1808
1809 public slots:
1810
1820 void setMinimumScale( double scale );
1821
1831 void setMaximumScale( double scale );
1832
1840 void setScaleBasedVisibility( bool enabled );
1841
1850 void triggerRepaint( bool deferredUpdate = false );
1851
1858 void trigger3DUpdate();
1859
1863 void emitStyleChanged();
1864
1872 virtual bool setDependencies( const QSet<QgsMapLayerDependency> &layers );
1873
1878 void setRefreshOnNotifyEnabled( bool enabled );
1879
1886 void setRefreshOnNofifyMessage( const QString &message ) { mRefreshOnNofifyMessage = message; }
1887
1893 virtual void setTransformContext( const QgsCoordinateTransformContext &transformContext ) = 0;
1894
1895#ifdef SIP_RUN
1896 SIP_PYOBJECT __repr__();
1897 % MethodCode
1898 QString str = QStringLiteral( "<QgsMapLayer: '%1' (%2)>" ).arg( sipCpp->name(), sipCpp->dataProvider() ? sipCpp->dataProvider()->name() : QStringLiteral( "Invalid" ) );
1899 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
1900 % End
1901#endif
1902
1909 QgsProject *project() const;
1910
1911 signals:
1912
1920
1922 void statusChanged( const QString &status );
1923
1932 void idChanged( const QString &id );
1933
1938
1948
1959
1976
1983 void repaintRequested( bool deferredUpdate = false );
1984
1987
1990
1992 void blendModeChanged( QPainter::CompositionMode blendMode );
1993
2002 void opacityChanged( double opacity );
2003
2009
2021
2026
2031
2038
2044
2049
2056
2061 void autoRefreshIntervalChanged( int interval );
2062
2069
2077
2086
2093
2100
2106 void customPropertyChanged( const QString &key );
2107
2113
2119
2125
2132
2140
2141 private slots:
2142
2143 void onNotified( const QString &message );
2144
2160 virtual void setDataSourcePrivate( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, Qgis::DataProviderReadFlags flags );
2161
2162 protected:
2163
2168 void clone( QgsMapLayer *layer ) const;
2169
2171 virtual void setExtent( const QgsRectangle &rect );
2172
2177 virtual void setExtent3D( const QgsBox3D &box );
2178
2180 void setValid( bool valid );
2181
2186 virtual bool readXml( const QDomNode &layer_node, QgsReadWriteContext &context );
2187
2192 virtual bool writeXml( QDomNode &layer_node, QDomDocument &document, const QgsReadWriteContext &context ) const;
2193
2205 virtual QString encodedSource( const QString &source, const QgsReadWriteContext &context ) const;
2206
2219 virtual QString decodedSource( const QString &source, const QString &dataProvider, const QgsReadWriteContext &context ) const;
2220
2226 void readCustomProperties( const QDomNode &layerNode, const QString &keyStartsWith = QString() );
2227
2229 void writeCustomProperties( QDomNode &layerNode, QDomDocument &doc ) const;
2230
2232 void readStyleManager( const QDomNode &layerNode );
2234 void writeStyleManager( QDomNode &layerNode, QDomDocument &doc ) const;
2235
2239 void writeCommonStyle( QDomElement &layerElement, QDomDocument &document,
2240 const QgsReadWriteContext &context,
2241 StyleCategories categories = AllStyleCategories ) const;
2242
2246 void readCommonStyle( const QDomElement &layerElement, const QgsReadWriteContext &context,
2247 StyleCategories categories = AllStyleCategories );
2248
2250 void setProviderType( const QString &providerType );
2251
2252#ifndef SIP_RUN
2253#if 0
2255 void connectNotify( const char *signal ) override;
2256#endif
2257#endif
2258
2260 void appendError( const QgsErrorMessage &error ) { mError.append( error );}
2262 void setError( const QgsError &error ) { mError = error;}
2263
2270 void invalidateWgs84Extent();
2271
2273 bool mValid = false;
2274
2277
2279 QString mLayerName;
2280
2282 QString mLegendUrl;
2284
2287
2289 QSet<QgsMapLayerDependency> mDependencies;
2290
2296 Q_DECL_DEPRECATED bool hasDependencyCycle( const QSet<QgsMapLayerDependency> & ) const {return false;}
2297
2298 bool mIsRefreshOnNofifyEnabled = false;
2300
2303
2304 //TODO QGIS 4 - move to readXml as a new argument (breaks API)
2305
2308
2314 bool mShouldValidateCrs = true;
2315
2321 double mLayerOpacity = 1.0;
2322
2328 int mBlockStyleChangedSignal = 0;
2329
2330#ifndef SIP_RUN
2331
2340 QString crsHtmlMetadata() const;
2341#endif
2342
2343#ifndef SIP_RUN
2344
2353 QString generalHtmlMetadata() const;
2354
2363 QString customPropertyHtmlMetadata() const;
2364#endif
2365
2366#ifndef SIP_RUN
2367
2375 std::unique_ptr<QgsDataProvider> mPreloadedProvider;
2376#endif
2377
2378 private:
2379
2380 virtual QString baseURI( PropertyType type ) const;
2381 QString saveNamedProperty( const QString &uri, QgsMapLayer::PropertyType type,
2382 bool &resultFlag, StyleCategories categories = AllStyleCategories );
2383 QString loadNamedProperty( const QString &uri, QgsMapLayer::PropertyType type,
2384 bool &namedPropertyExists, bool &propertySuccessfullyLoaded, StyleCategories categories = AllStyleCategories, Qgis::LoadStyleFlags flags = Qgis::LoadStyleFlags() );
2385 bool loadNamedPropertyFromDatabase( const QString &db, const QString &uri, QString &xml, QgsMapLayer::PropertyType type );
2386
2387 // const method because extents are mutable
2388 void updateExtent( const QgsRectangle &extent ) const;
2389 void updateExtent( const QgsBox3D &extent ) const;
2390
2391 bool rebuildCrs3D( QString *error = nullptr );
2392
2397 virtual bool isReadOnly() const;
2398
2404 QgsCoordinateReferenceSystem mVerticalCrs;
2406
2408 QString mID;
2409
2411 Qgis::LayerType mLayerType;
2412
2413 LayerFlags mFlags = LayerFlags( Identifiable | Removable | Searchable );
2414
2416 QPainter::CompositionMode mBlendMode = QPainter::CompositionMode_SourceOver;
2417
2419 QString mTag;
2420
2421 //set some generous defaults for scale based visibility
2422
2424 double mMinScale = 0;
2426 double mMaxScale = 100000000;
2428 bool mScaleBasedVisibility = false;
2429
2433 std::unique_ptr< QgsMapLayerServerProperties > mServerProperties;
2434
2436 QUndoStack *mUndoStack = nullptr;
2437
2438 QUndoStack *mUndoStackStyles = nullptr;
2439
2441 QgsObjectCustomProperties mCustomProperties;
2442
2444 QgsMapLayerLegend *mLegend = nullptr;
2445
2447 QgsMapLayerStyleManager *mStyleManager = nullptr;
2448
2450
2452 QTimer *mRefreshTimer = nullptr;
2453
2454 QgsLayerMetadata mMetadata;
2455
2457 QgsAbstract3DRenderer *m3DRenderer = nullptr;
2458
2460 mutable QgsBox3D mExtent3D;
2461
2463 mutable QgsRectangle mExtent2D;
2464
2466 mutable QgsRectangle mWgs84Extent;
2467
2473 QString mOriginalXmlProperties;
2474
2476 bool mRepaintRequestedFired = false;
2477
2479 QString mLegendPlaceholderImage;
2480
2482 QString mMapTipTemplate;
2483
2485 bool mMapTipsEnabled = true;
2486
2487 friend class QgsVectorLayer;
2488 friend class TestQgsProject;
2489 friend class TestQgsMapLayer;
2490};
2491
2495
2496
2497#ifndef SIP_RUN
2498
2503typedef QPointer< QgsMapLayer > QgsWeakMapLayerPointer;
2504
2509typedef QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList;
2510#endif
2511
2512#endif
The Qgis class provides global constants 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:2211
@ Disabled
Automatic refreshing is disabled.
Base class for all renderers that may to participate in 3D view.
A 3-dimensional box composed of x, y, z coordinates.
Definition qgsbox3d.h:43
This class represents a coordinate reference system (CRS).
Contains information about the context in which a coordinate transform is executed.
Abstract base class for spatial data provider implementations.
QgsErrorMessage represents single error message.
Definition qgserror.h:33
A container for error messages.
Definition qgserror.h:81
A structured metadata store for a map layer.
This class models dependencies with or between map layers.
Base class for storage of map layer elevation properties.
The QgsMapLayerLegend class is abstract interface for implementations of legends for one map layer.
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:76
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.
QString legendUrlFormat() const
Returns the format for a URL based layer legend.
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 setLegendUrl(const QString &legendUrl)
Sets the URL for the layer's legend.
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 mLegendUrl
WMS legend.
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.
QString mLegendUrlFormat
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.
QString legendUrl() const
Returns the URL for the layer's legend.
void flagsChanged()
Emitted when layer's flags have been modified.
void repaintRequested(bool deferredUpdate=false)
By emitting this signal the layer tells that either appearance or content have been changed and any v...
void setLegendUrlFormat(const QString &legendUrlFormat)
Sets the format for a URL based layer legend.
void 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...
The class is used as a container of context for various read/write operations on other objects.
A rectangle specified with double values.
Contains information about the context of a rendering operation.
The QgsSldExportContext class holds SLD export options and other information related to SLD export of...
An interface for classes which can visit style entity (e.g.
Represents a vector layer which manages a vector based data sets.
#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.