QGIS API Documentation 3.43.0-Master (c67cf405802)
qgsmaplayer.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsmaplayer.h - description
3 -------------------
4 begin : Fri Jun 28 2002
5 copyright : (C) 2002 by Gary E.Sherman
6 email : sherman at mrcc.com
7***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#ifndef QGSMAPLAYER_H
19#define QGSMAPLAYER_H
20
21#include "qgis_core.h"
22#include <QDateTime>
23#include <QDomNode>
24#include <QImage>
25#include <QObject>
26#include <QPainter>
27#include <QUndoStack>
28#include <QVariant>
29#include <QIcon>
30#include <QSet>
31
32#include "qgis_sip.h"
33#include "qgserror.h"
35#include "qgsrectangle.h"
38#include "qgslayermetadata.h"
40#include "qgsreadwritecontext.h"
41#include "qgsdataprovider.h"
42#include "qgis.h"
43#include "qgslogger.h"
44
46class QgsDataProvider;
50class QgsProject;
57
58class QDomDocument;
59class QKeyEvent;
60class QPainter;
62class QgsBox3D;
63
64/*
65 * Constants used to describe copy-paste MIME types
66 */
67#define QGSCLIPBOARD_MAPLAYER_MIME "application/qgis.maplayer"
68
69
76class CORE_EXPORT QgsMapLayer : public QObject
77{
78 Q_OBJECT
79
80 Q_PROPERTY( QString id READ id WRITE setId NOTIFY idChanged )
81 Q_PROPERTY( QString name READ name WRITE setName NOTIFY nameChanged )
82 Q_PROPERTY( int autoRefreshInterval READ autoRefreshInterval WRITE setAutoRefreshInterval NOTIFY autoRefreshIntervalChanged )
83 Q_PROPERTY( QgsLayerMetadata metadata READ metadata WRITE setMetadata NOTIFY metadataChanged )
84 Q_PROPERTY( QgsCoordinateReferenceSystem crs READ crs WRITE setCrs NOTIFY crsChanged )
85 Q_PROPERTY( QgsCoordinateReferenceSystem verticalCrs READ verticalCrs WRITE setVerticalCrs NOTIFY verticalCrsChanged )
86 Q_PROPERTY( QgsCoordinateReferenceSystem crs3D READ crs3D NOTIFY crs3DChanged )
87 Q_PROPERTY( Qgis::LayerType type READ type CONSTANT )
88 Q_PROPERTY( bool isValid READ isValid NOTIFY isValidChanged )
89 Q_PROPERTY( double opacity READ opacity WRITE setOpacity NOTIFY opacityChanged )
90 Q_PROPERTY( QString mapTipTemplate READ mapTipTemplate WRITE setMapTipTemplate NOTIFY mapTipTemplateChanged )
91 Q_PROPERTY( bool mapTipsEnabled READ mapTipsEnabled WRITE setMapTipsEnabled NOTIFY mapTipsEnabledChanged )
92
93#ifdef SIP_RUN
95 QgsMapLayer *layer = qobject_cast<QgsMapLayer *>( sipCpp );
96
97 sipType = 0;
98
99 if ( layer )
100 {
101 switch ( layer->type() )
102 {
104 sipType = sipType_QgsVectorLayer;
105 break;
107 sipType = sipType_QgsRasterLayer;
108 break;
110 sipType = sipType_QgsPluginLayer;
111 break;
113 sipType = sipType_QgsMeshLayer;
114 break;
116 sipType = sipType_QgsVectorTileLayer;
117 break;
119 sipType = sipType_QgsAnnotationLayer;
120 break;
122 sipType = sipType_QgsPointCloudLayer;
123 break;
125 sipType = sipType_QgsGroupLayer;
126 break;
128 sipType = sipType_QgsTiledSceneLayer;
129 break;
130 default:
131 sipType = nullptr;
132 break;
133 }
134 }
135 SIP_END
136#endif
137
138 public:
139
144 {
145 Style = 0,
147 };
148
155 {
156 Identifiable = 1 << 0,
157 Removable = 1 << 1,
158 Searchable = 1 << 2,
159 Private = 1 << 3,
160 };
161 Q_ENUM( LayerFlag )
162 Q_DECLARE_FLAGS( LayerFlags, LayerFlag )
163 Q_FLAG( LayerFlags )
164
170 {
171 LayerConfiguration = 1 << 0,
172 Symbology = 1 << 1,
173 Symbology3D = 1 << 2,
174 Labeling = 1 << 3,
175 Fields = 1 << 4,
176 Forms = 1 << 5,
177 Actions = 1 << 6,
178 MapTips = 1 << 7,
179 Diagrams = 1 << 8,
180 AttributeTable = 1 << 9,
181 Rendering = 1 << 10,
182 CustomProperties = 1 << 11,
183 GeometryOptions = 1 << 12,
184 Relations = 1 << 13,
185 Temporal = 1 << 14,
186 Legend = 1 << 15,
187 Elevation = 1 << 16,
188 Notes = 1 << 17,
189 AllStyleCategories = LayerConfiguration | Symbology | Symbology3D | Labeling | Fields | Forms | Actions |
190 MapTips | Diagrams | AttributeTable | Rendering | CustomProperties | GeometryOptions | Relations | Temporal | Legend | Elevation | Notes,
191 };
192 Q_ENUM( StyleCategory )
193 Q_DECLARE_FLAGS( StyleCategories, StyleCategory )
194 Q_FLAG( StyleCategories )
195
202 QgsMapLayer( Qgis::LayerType type = Qgis::LayerType::Vector, const QString &name = QString(), const QString &source = QString() );
203
204 ~QgsMapLayer() override;
205
206 QgsMapLayer( const QgsMapLayer & ) = delete;
207 QgsMapLayer &operator=( const QgsMapLayer & ) = delete;
208
214 virtual QgsMapLayer *clone() const = 0;
215
219 Qgis::LayerType type() const;
220
231 QgsMapLayer::LayerFlags flags() const;
232
243 void setFlags( QgsMapLayer::LayerFlags flags );
244
254 virtual Qgis::MapLayerProperties properties() const;
255
260 static QString extensionPropertyType( PropertyType type );
261
268 QString id() const;
269
285 bool setId( const QString &id );
286
291 void setName( const QString &name );
292
297 QString name() const;
298
302 Q_INVOKABLE virtual QgsDataProvider *dataProvider();
303
308 virtual const QgsDataProvider *dataProvider() const SIP_SKIP;
309
314 QgsProviderMetadata *providerMetadata() const;
315
321 Q_DECL_DEPRECATED void setShortName( const QString &shortName ) SIP_DEPRECATED;
322
328 Q_DECL_DEPRECATED QString shortName() const SIP_DEPRECATED;
329
335 Q_DECL_DEPRECATED void setTitle( const QString &title ) SIP_DEPRECATED;
336
342 Q_DECL_DEPRECATED QString title() const SIP_DEPRECATED;
343
349 Q_DECL_DEPRECATED void setAbstract( const QString &abstract ) SIP_DEPRECATED;
350
356 Q_DECL_DEPRECATED QString abstract() const SIP_DEPRECATED;
357
363 Q_DECL_DEPRECATED void setKeywordList( const QString &keywords ) SIP_DEPRECATED;
364
370 Q_DECL_DEPRECATED QString keywordList() const SIP_DEPRECATED;
371
377 Q_DECL_DEPRECATED void setDataUrl( const QString &dataUrl ) SIP_DEPRECATED;
378
384 Q_DECL_DEPRECATED QString dataUrl() const SIP_DEPRECATED;
385
391 Q_DECL_DEPRECATED void setDataUrlFormat( const QString &dataUrlFormat ) SIP_DEPRECATED;
392
398 Q_DECL_DEPRECATED QString dataUrlFormat() const SIP_DEPRECATED;
399
405 Q_DECL_DEPRECATED void setAttribution( const QString &attrib ) SIP_DEPRECATED;
406
412 Q_DECL_DEPRECATED QString attribution() const SIP_DEPRECATED;
413
419 Q_DECL_DEPRECATED void setAttributionUrl( const QString &attribUrl ) SIP_DEPRECATED;
420
426 Q_DECL_DEPRECATED QString attributionUrl() const SIP_DEPRECATED;
427
428 /* Layer metadataUrl information */
429
434 QgsMapLayerServerProperties *serverProperties() { return mServerProperties.get(); };
435
440 const QgsMapLayerServerProperties *serverProperties() const { return mServerProperties.get(); } SIP_SKIP;
441
450 Q_DECL_DEPRECATED void setMetadataUrl( const QString &metaUrl ) SIP_DEPRECATED;
451
461 Q_DECL_DEPRECATED QString metadataUrl() const SIP_DEPRECATED;
462
471 Q_DECL_DEPRECATED void setMetadataUrlType( const QString &metaUrlType ) SIP_DEPRECATED;
472
482 Q_DECL_DEPRECATED QString metadataUrlType() const SIP_DEPRECATED;
483
492 Q_DECL_DEPRECATED void setMetadataUrlFormat( const QString &metaUrlFormat ) SIP_DEPRECATED;
493
503 Q_DECL_DEPRECATED QString metadataUrlFormat() const SIP_DEPRECATED;
504
510 void setBlendMode( QPainter::CompositionMode blendMode );
511
516 QPainter::CompositionMode blendMode() const;
517
526 virtual void setOpacity( double opacity );
527
536 virtual double opacity() const;
537
539 bool readOnly() const { return isReadOnly(); }
540
544 Q_INVOKABLE virtual void reload() {}
545
550
552 virtual QgsRectangle extent() const;
553
558 virtual QgsBox3D extent3D() const;
559
568 QgsRectangle wgs84Extent( bool forceRecalculate = false ) const;
569
575 bool isValid() const;
576
577 // TODO QGIS 4.0: consider changing bool hidePassword to an enumeration: HIDE_CREDENTIALS / REDACT_CREDENTIALS
578 // to avoid the ambiguity of the double negation (hide = false)
579
587 QString publicSource( bool hidePassword = false ) const;
588
594 QString source() const;
595
600 virtual QStringList subLayers() const;
601
606 virtual void setLayerOrder( const QStringList &layers );
607
613 virtual void setSubLayerVisibility( const QString &name, bool visible );
614
621 virtual bool supportsEditing() const;
622
624 virtual bool isEditable() const;
625
631 virtual bool isModified() const;
632
636 virtual bool isSpatial() const;
637
647 virtual bool isTemporary() const;
648
654 {
655 FlagDontResolveLayers = 1 << 0,
656 FlagTrustLayerMetadata = 1 << 1,
657 FlagReadExtentFromXml = 1 << 2,
658 FlagForceReadOnly = 1 << 3,
659 };
660 Q_DECLARE_FLAGS( ReadFlags, ReadFlag )
661
662
679 bool readLayerXml( const QDomElement &layerElement, QgsReadWriteContext &context,
680 QgsMapLayer::ReadFlags flags = QgsMapLayer::ReadFlags(), QgsDataProvider *preloadedProvider SIP_TRANSFER = nullptr );
681
697 bool writeLayerXml( QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context ) const;
698
702 virtual void resolveReferences( QgsProject *project );
703
708 Q_INVOKABLE QStringList customPropertyKeys() const;
709
715 Q_INVOKABLE void setCustomProperty( const QString &key, const QVariant &value );
716
721 Q_INVOKABLE QVariant customProperty( const QString &value, const QVariant &defaultValue = QVariant() ) const;
722
726 void setCustomProperties( const QgsObjectCustomProperties &properties );
727
733 const QgsObjectCustomProperties &customProperties() const;
734
744 virtual int listStylesInDatabase( QStringList &ids SIP_OUT, QStringList &names SIP_OUT,
745 QStringList &descriptions SIP_OUT, QString &msgError SIP_OUT );
746
750 virtual QString getStyleFromDatabase( const QString &styleId, QString &msgError SIP_OUT );
751
758 virtual bool deleteStyleFromDatabase( const QString &styleId, QString &msgError SIP_OUT );
759
776 virtual void saveStyleToDatabase( const QString &name, const QString &description,
777 bool useAsDefault, const QString &uiFileContent,
778 QString &msgError SIP_OUT,
780
781
782 // TODO QGIS 4.0 -- fix this. We incorrectly have a single boolean flag which in which false is used inconsistently for "a style WAS found but an error occurred loading it" vs "no style was found".
783 // The first (style found, error occurred loading it) should trigger a user-facing warning, whereas the second (no style found) isn't reflective of an error at all.
784
795 virtual QString loadNamedStyle( const QString &theURI, bool &resultFlag SIP_OUT, bool loadFromLocalDb,
798
799#ifndef SIP_RUN
800
811 template <class T>
812 T customEnumProperty( const QString &key, const T &defaultValue )
813 {
814 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
815 Q_ASSERT( metaEnum.isValid() );
816 if ( !metaEnum.isValid() )
817 {
818 QgsDebugError( QStringLiteral( "Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
819 }
820
821 T v;
822 bool ok = false;
823
824 if ( metaEnum.isValid() )
825 {
826 // read as string
827 QByteArray ba = customProperty( key, metaEnum.valueToKey( static_cast<int>( defaultValue ) ) ).toString().toUtf8();
828 const char *vs = ba.data();
829 v = static_cast<T>( metaEnum.keyToValue( vs, &ok ) );
830 if ( ok )
831 return v;
832 }
833
834 // if failed, try to read as int (old behavior)
835 // this code shall be removed later
836 // then the method could be marked as const
837 v = static_cast<T>( customProperty( key, static_cast<int>( defaultValue ) ).toInt( &ok ) );
838 if ( metaEnum.isValid() )
839 {
840 if ( !ok || !metaEnum.valueToKey( static_cast<int>( v ) ) )
841 {
842 v = defaultValue;
843 }
844 else
845 {
846 // found property as an integer
847 // convert the property to the new form (string)
848 setCustomEnumProperty( key, v );
849 }
850 }
851
852 return v;
853 }
854
863 template <class T>
864 void setCustomEnumProperty( const QString &key, const T &value )
865 {
866 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
867 Q_ASSERT( metaEnum.isValid() );
868 if ( metaEnum.isValid() )
869 {
870 setCustomProperty( key, metaEnum.valueToKey( static_cast<int>( value ) ) );
871 }
872 else
873 {
874 QgsDebugError( QStringLiteral( "Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
875 }
876 }
877
889 template <class T>
890 T customFlagProperty( const QString &key, const T &defaultValue )
891 {
892 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
893 Q_ASSERT( metaEnum.isValid() );
894 if ( !metaEnum.isValid() )
895 {
896 QgsDebugError( QStringLiteral( "Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
897 }
898
899 T v = defaultValue;
900 bool ok = false;
901
902 if ( metaEnum.isValid() )
903 {
904 // read as string
905 QByteArray ba = customProperty( key, metaEnum.valueToKeys( defaultValue ) ).toString().toUtf8();
906 const char *vs = ba.data();
907 v = static_cast<T>( metaEnum.keysToValue( vs, &ok ) );
908 }
909 if ( !ok )
910 {
911 // if failed, try to read as int
912 const int intValue = customProperty( key, static_cast<int>( defaultValue ) ).toInt( &ok );
913 if ( metaEnum.isValid() )
914 {
915 if ( ok )
916 {
917 // check that the int value does correspond to a flag
918 // see https://stackoverflow.com/a/68495949/1548052
919 const QByteArray keys = metaEnum.valueToKeys( intValue );
920 const int intValueCheck = metaEnum.keysToValue( keys );
921 if ( intValue != intValueCheck )
922 {
923 v = defaultValue;
924 }
925 else
926 {
927 // found property as an integer
928 v = T( intValue );
929 // convert the property to the new form (string)
930 // this code could be removed
931 // then the method could be marked as const
932 setCustomFlagProperty( key, v );
933 }
934 }
935 else
936 {
937 v = defaultValue;
938 }
939 }
940 }
941
942 return v;
943 }
944
953 template <class T>
954 void setCustomFlagProperty( const QString &key, const T &value )
955 {
956 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
957 Q_ASSERT( metaEnum.isValid() );
958 if ( metaEnum.isValid() )
959 {
960 setCustomProperty( key, metaEnum.valueToKeys( value ) );
961 }
962 else
963 {
964 QgsDebugError( QStringLiteral( "Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
965 }
966 }
967#endif
968
969
974 void removeCustomProperty( const QString &key );
975
981 virtual QgsError error() const;
982
995
1014 QgsCoordinateReferenceSystem verticalCrs() const;
1015
1034 QgsCoordinateReferenceSystem crs3D() const;
1035
1046 void setCrs( const QgsCoordinateReferenceSystem &srs, bool emitSignal = true );
1047
1067 bool setVerticalCrs( const QgsCoordinateReferenceSystem &crs, QString *errorMessage SIP_OUT = nullptr );
1068
1074 QgsCoordinateTransformContext transformContext( ) const;
1075
1076
1081 static QString formatLayerName( const QString &name );
1082
1089 virtual QString metadataUri() const;
1090
1096 void exportNamedMetadata( QDomDocument &doc, QString &errorMsg ) const;
1097
1106 virtual QString saveDefaultMetadata( bool &resultFlag SIP_OUT );
1107
1121 QString saveNamedMetadata( const QString &uri, bool &resultFlag );
1122
1123 // TODO QGIS 4.0 -- fix this. We incorrectly have a single boolean flag which in which false is used inconsistently for "metadata WAS found but an error occurred loading it" vs "no metadata was found".
1124 // The first (metadata found, error occurred loading it) should trigger a user-facing warning, whereas the second (no metadata found) isn't reflective of an error at all.
1125
1139 virtual QString loadNamedMetadata( const QString &uri, bool &resultFlag SIP_OUT );
1140
1141 // TODO QGIS 4.0 -- fix this. We incorrectly have a single boolean flag which in which false is used inconsistently for "metadata WAS found but an error occurred loading it" vs "no metadata was found".
1142 // The first (metadata found, error occurred loading it) should trigger a user-facing warning, whereas the second (no metadata found) isn't reflective of an error at all.
1143
1152 virtual QString loadDefaultMetadata( bool &resultFlag );
1153
1161 bool loadNamedMetadataFromDatabase( const QString &db, const QString &uri, QString &qmd );
1162
1169 bool importNamedMetadata( QDomDocument &document, QString &errorMessage );
1170
1179 virtual QString styleURI() const;
1180
1181 // TODO QGIS 4.0 -- fix this. We incorrectly have a single boolean flag which in which false is used inconsistently for "a style WAS found but an error occurred loading it" vs "no style was found".
1182 // The first (style found, error occurred loading it) should trigger a user-facing warning, whereas the second (no style found) isn't reflective of an error at all.
1183
1193 virtual QString loadDefaultStyle( bool &resultFlag SIP_OUT );
1194
1195 // TODO QGIS 4.0 -- fix this. We incorrectly have a single boolean flag which in which false is used inconsistently for "a style WAS found but an error occurred loading it" vs "no style was found".
1196 // The first (style found, error occurred loading it) should trigger a user-facing warning, whereas the second (no style found) isn't reflective of an error at all.
1197
1214 virtual QString loadNamedStyle( const QString &uri, bool &resultFlag SIP_OUT, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories, Qgis::LoadStyleFlags flags = Qgis::LoadStyleFlags() );
1215
1223 virtual bool loadNamedStyleFromDatabase( const QString &db, const QString &uri, QString &qml SIP_OUT );
1224
1233 virtual bool importNamedStyle( QDomDocument &doc, QString &errorMsg SIP_OUT,
1235
1244 virtual void exportNamedStyle( QDomDocument &doc, QString &errorMsg SIP_OUT, const QgsReadWriteContext &context = QgsReadWriteContext(),
1246
1247
1255 virtual void exportSldStyle( QDomDocument &doc, QString &errorMsg ) const;
1256
1265 virtual void exportSldStyleV2( QDomDocument &doc, QString &errorMsg, const QgsSldExportContext &exportContext ) const;
1266
1278 virtual QString saveDefaultStyle( bool &resultFlag SIP_OUT, StyleCategories categories );
1279
1291 Q_DECL_DEPRECATED virtual QString saveDefaultStyle( bool &resultFlag SIP_OUT ) SIP_DEPRECATED;
1292
1308 virtual QString saveNamedStyle( const QString &uri, bool &resultFlag SIP_OUT, StyleCategories categories = AllStyleCategories );
1309
1319 virtual QString saveSldStyle( const QString &uri, bool &resultFlag ) const;
1320
1331 virtual QString saveSldStyleV2( bool &resultFlag SIP_OUT, const QgsSldExportContext &exportContext ) const;
1332
1341 virtual QString loadSldStyle( const QString &uri, bool &resultFlag );
1342
1343 virtual bool readSld( const QDomNode &node, QString &errorMessage )
1344 { Q_UNUSED( node ) errorMessage = QStringLiteral( "Layer type %1 not supported" ).arg( static_cast<int>( type() ) ); return false; }
1345
1346
1347
1356 virtual bool readSymbology( const QDomNode &node, QString &errorMessage,
1357 QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories ) = 0;
1358
1368 virtual bool readStyle( const QDomNode &node, QString &errorMessage,
1369 QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories );
1370
1381 virtual bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context,
1382 StyleCategories categories = AllStyleCategories ) const = 0;
1383
1395 virtual bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context,
1396 StyleCategories categories = AllStyleCategories ) const;
1397
1398
1429 void setDataSource( const QString &dataSource, const QString &baseName = QString(), const QString &provider = QString(), bool loadDefaultStyleFlag = false );
1430
1460 void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, bool loadDefaultStyleFlag = false );
1461
1491 void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, Qgis::DataProviderReadFlags flags );
1492
1496 QString providerType() const;
1497
1499 QUndoStack *undoStack();
1500
1504 QUndoStack *undoStackStyles();
1505
1511 Q_DECL_DEPRECATED void setLegendUrl( const QString &legendUrl ) SIP_DEPRECATED;
1512
1518 Q_DECL_DEPRECATED QString legendUrl() const SIP_DEPRECATED;
1519
1525 Q_DECL_DEPRECATED void setLegendUrlFormat( const QString &legendUrlFormat ) SIP_DEPRECATED;
1526
1532 Q_DECL_DEPRECATED QString legendUrlFormat() const SIP_DEPRECATED;
1533
1538 void setLegend( QgsMapLayerLegend *legend SIP_TRANSFER );
1539
1543 QgsMapLayerLegend *legend() const;
1544
1548 QgsMapLayerStyleManager *styleManager() const;
1549
1553 void setRenderer3D( QgsAbstract3DRenderer *renderer SIP_TRANSFER );
1554
1558 QgsAbstract3DRenderer *renderer3D() const;
1559
1568 bool isInScaleRange( double scale ) const;
1569
1580 double minimumScale() const;
1581
1592 double maximumScale() const;
1593
1602 bool hasScaleBasedVisibility() const;
1603
1610 Q_DECL_DEPRECATED bool hasAutoRefreshEnabled() const SIP_DEPRECATED;
1611
1618 Qgis::AutoRefreshMode autoRefreshMode() const;
1619
1626 int autoRefreshInterval() const;
1627
1638 void setAutoRefreshInterval( int interval );
1639
1646 Q_DECL_DEPRECATED void setAutoRefreshEnabled( bool enabled ) SIP_DEPRECATED;
1647
1654 void setAutoRefreshMode( Qgis::AutoRefreshMode mode );
1655
1661 virtual const QgsLayerMetadata &metadata() const;
1662
1668 virtual void setMetadata( const QgsLayerMetadata &metadata );
1669
1673 virtual QString htmlMetadata() const;
1674
1676 virtual QDateTime timestamp() const;
1677
1684 virtual QSet<QgsMapLayerDependency> dependencies() const;
1685
1690 QString refreshOnNotifyMessage() const { return mRefreshOnNofifyMessage; }
1691
1696 bool isRefreshOnNotifyEnabled() const { return mIsRefreshOnNofifyEnabled; }
1697
1706 QString originalXmlProperties() const;
1707
1715 void setOriginalXmlProperties( const QString &originalXmlProperties );
1716
1721 static QString generateId( const QString &layerName );
1722
1732 virtual bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
1733
1740
1747
1754
1760 QString legendPlaceholderImage() const { return mLegendPlaceholderImage;}
1761
1767 void setLegendPlaceholderImage( const QString &imgPath ) { mLegendPlaceholderImage = imgPath; }
1768
1775 virtual bool hasMapTips() const;
1776
1784 QString mapTipTemplate() const;
1785
1793 void setMapTipTemplate( const QString &mapTipTemplate );
1794
1801 void setMapTipsEnabled( bool enabled );
1802
1807 bool mapTipsEnabled() const;
1808
1816 static Qgis::DataProviderReadFlags providerReadFlags( const QDomNode &layerNode, QgsMapLayer::ReadFlags layerReadFlags );
1817
1818 public slots:
1819
1829 void setMinimumScale( double scale );
1830
1840 void setMaximumScale( double scale );
1841
1849 void setScaleBasedVisibility( bool enabled );
1850
1859 void triggerRepaint( bool deferredUpdate = false );
1860
1867 void trigger3DUpdate();
1868
1872 void emitStyleChanged();
1873
1881 virtual bool setDependencies( const QSet<QgsMapLayerDependency> &layers );
1882
1887 void setRefreshOnNotifyEnabled( bool enabled );
1888
1895 void setRefreshOnNofifyMessage( const QString &message ) { mRefreshOnNofifyMessage = message; }
1896
1902 virtual void setTransformContext( const QgsCoordinateTransformContext &transformContext ) = 0;
1903
1904#ifdef SIP_RUN
1905 SIP_PYOBJECT __repr__();
1906 % MethodCode
1907 QString str = QStringLiteral( "<QgsMapLayer: '%1' (%2)>" ).arg( sipCpp->name(), sipCpp->dataProvider() ? sipCpp->dataProvider()->name() : QStringLiteral( "Invalid" ) );
1908 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
1909 % End
1910#endif
1911
1918 QgsProject *project() const;
1919
1920 signals:
1921
1929
1931 void statusChanged( const QString &status );
1932
1941 void idChanged( const QString &id );
1942
1947
1957
1968
1985
1992 void repaintRequested( bool deferredUpdate = false );
1993
1996
1999
2001 void blendModeChanged( QPainter::CompositionMode blendMode );
2002
2011 void opacityChanged( double opacity );
2012
2018
2030
2035
2040
2047
2053
2058
2065
2070 void autoRefreshIntervalChanged( int interval );
2071
2078
2086
2095
2102
2109
2115 void customPropertyChanged( const QString &key );
2116
2122
2128
2134
2141
2149
2150 private slots:
2151
2152 void onNotified( const QString &message );
2153
2169 virtual void setDataSourcePrivate( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, Qgis::DataProviderReadFlags flags );
2170
2171 protected:
2172
2177 void clone( QgsMapLayer *layer ) const;
2178
2180 virtual void setExtent( const QgsRectangle &rect );
2181
2186 virtual void setExtent3D( const QgsBox3D &box );
2187
2189 void setValid( bool valid );
2190
2195 virtual bool readXml( const QDomNode &layer_node, QgsReadWriteContext &context );
2196
2201 virtual bool writeXml( QDomNode &layer_node, QDomDocument &document, const QgsReadWriteContext &context ) const;
2202
2214 virtual QString encodedSource( const QString &source, const QgsReadWriteContext &context ) const;
2215
2228 virtual QString decodedSource( const QString &source, const QString &dataProvider, const QgsReadWriteContext &context ) const;
2229
2235 void readCustomProperties( const QDomNode &layerNode, const QString &keyStartsWith = QString() );
2236
2238 void writeCustomProperties( QDomNode &layerNode, QDomDocument &doc ) const;
2239
2241 void readStyleManager( const QDomNode &layerNode );
2243 void writeStyleManager( QDomNode &layerNode, QDomDocument &doc ) const;
2244
2248 void writeCommonStyle( QDomElement &layerElement, QDomDocument &document,
2249 const QgsReadWriteContext &context,
2250 StyleCategories categories = AllStyleCategories ) const;
2251
2255 void readCommonStyle( const QDomElement &layerElement, const QgsReadWriteContext &context,
2256 StyleCategories categories = AllStyleCategories );
2257
2259 void setProviderType( const QString &providerType );
2260
2261#ifndef SIP_RUN
2262#if 0
2264 void connectNotify( const char *signal ) override;
2265#endif
2266#endif
2267
2269 void appendError( const QgsErrorMessage &error ) { mError.append( error );}
2271 void setError( const QgsError &error ) { mError = error;}
2272
2279 void invalidateWgs84Extent();
2280
2282 bool mValid = false;
2283
2286
2288 QString mLayerName;
2289
2292
2294 QSet<QgsMapLayerDependency> mDependencies;
2295
2301 Q_DECL_DEPRECATED bool hasDependencyCycle( const QSet<QgsMapLayerDependency> & ) const {return false;}
2302
2303 bool mIsRefreshOnNofifyEnabled = false;
2305
2308
2309 //TODO QGIS 4 - move to readXml as a new argument (breaks API)
2310
2313
2319 bool mShouldValidateCrs = true;
2320
2326 double mLayerOpacity = 1.0;
2327
2333 int mBlockStyleChangedSignal = 0;
2334
2335#ifndef SIP_RUN
2336
2345 QString crsHtmlMetadata() const;
2346#endif
2347
2348#ifndef SIP_RUN
2349
2358 QString generalHtmlMetadata() const;
2359
2368 QString customPropertyHtmlMetadata() const;
2369#endif
2370
2371#ifndef SIP_RUN
2372
2380 std::unique_ptr<QgsDataProvider> mPreloadedProvider;
2381#endif
2382
2383 private:
2384
2385 virtual QString baseURI( PropertyType type ) const;
2386 QString saveNamedProperty( const QString &uri, QgsMapLayer::PropertyType type,
2387 bool &resultFlag, StyleCategories categories = AllStyleCategories );
2388 QString loadNamedProperty( const QString &uri, QgsMapLayer::PropertyType type,
2389 bool &namedPropertyExists, bool &propertySuccessfullyLoaded, StyleCategories categories = AllStyleCategories, Qgis::LoadStyleFlags flags = Qgis::LoadStyleFlags() );
2390 bool loadNamedPropertyFromDatabase( const QString &db, const QString &uri, QString &xml, QgsMapLayer::PropertyType type );
2391
2392 // const method because extents are mutable
2393 void updateExtent( const QgsRectangle &extent ) const;
2394 void updateExtent( const QgsBox3D &extent ) const;
2395
2396 bool rebuildCrs3D( QString *error = nullptr );
2397
2402 virtual bool isReadOnly() const;
2403
2409 QgsCoordinateReferenceSystem mVerticalCrs;
2411
2413 QString mID;
2414
2416 Qgis::LayerType mLayerType;
2417
2418 LayerFlags mFlags = LayerFlags( Identifiable | Removable | Searchable );
2419
2421 QPainter::CompositionMode mBlendMode = QPainter::CompositionMode_SourceOver;
2422
2424 QString mTag;
2425
2426 //set some generous defaults for scale based visibility
2427
2429 double mMinScale = 0;
2431 double mMaxScale = 100000000;
2433 bool mScaleBasedVisibility = false;
2434
2438 std::unique_ptr< QgsMapLayerServerProperties > mServerProperties;
2439
2441 QUndoStack *mUndoStack = nullptr;
2442
2443 QUndoStack *mUndoStackStyles = nullptr;
2444
2446 QgsObjectCustomProperties mCustomProperties;
2447
2449 QgsMapLayerLegend *mLegend = nullptr;
2450
2452 QgsMapLayerStyleManager *mStyleManager = nullptr;
2453
2455
2457 QTimer *mRefreshTimer = nullptr;
2458
2459 QgsLayerMetadata mMetadata;
2460
2462 QgsAbstract3DRenderer *m3DRenderer = nullptr;
2463
2465 mutable QgsBox3D mExtent3D;
2466
2468 mutable QgsRectangle mExtent2D;
2469
2471 mutable QgsRectangle mWgs84Extent;
2472
2478 QString mOriginalXmlProperties;
2479
2481 bool mRepaintRequestedFired = false;
2482
2484 QString mLegendPlaceholderImage;
2485
2487 QString mMapTipTemplate;
2488
2490 bool mMapTipsEnabled = true;
2491
2492 friend class QgsVectorLayer;
2493 friend class TestQgsProject;
2494 friend class TestQgsMapLayer;
2495};
2496
2500
2501
2502#ifndef SIP_RUN
2503
2508typedef QPointer< QgsMapLayer > QgsWeakMapLayerPointer;
2509
2514typedef QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList;
2515#endif
2516
2517#endif
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:54
QFlags< DataProviderReadFlag > DataProviderReadFlags
Flags which control data provider construction.
Definition qgis.h:450
LayerType
Types of layers that can be added to a map.
Definition qgis.h:169
@ Group
Composite group layer. Added in QGIS 3.24.
@ Plugin
Plugin based layer.
@ TiledScene
Tiled scene layer. Added in QGIS 3.34.
@ Annotation
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
@ Vector
Vector layer.
@ VectorTile
Vector tile layer. Added in QGIS 3.14.
@ Mesh
Mesh layer. Added in QGIS 3.2.
@ Raster
Raster layer.
@ PointCloud
Point cloud layer. Added in QGIS 3.18.
QFlags< LoadStyleFlag > LoadStyleFlags
Flags for loading layer styles.
Definition qgis.h:225
AutoRefreshMode
Map layer automatic refresh modes.
Definition qgis.h:2244
@ Disabled
Automatic refreshing is disabled.
Base class for all renderers that participate in 3D views.
A 3-dimensional box composed of x, y, z coordinates.
Definition qgsbox3d.h:43
Represents a coordinate reference system (CRS).
Contains information about the context in which a coordinate transform is executed.
Abstract base class for spatial data provider implementations.
Represents a single error message.
Definition qgserror.h:33
A container for error messages.
Definition qgserror.h:81
A structured metadata store for a map layer.
Models dependencies with or between map layers.
Base class for storage of map layer elevation properties.
An abstract interface for implementations of legends for one map layer.
Base class for utility classes that encapsulate information necessary for rendering of map layers.
Base class for storage of map layer selection properties.
Manages QGIS Server properties for a map layer.
Management of styles for use with one map layer.
Base class for storage of map layer temporal properties.
Base class for all map layer types.
Definition qgsmaplayer.h:77
void crs3DChanged()
Emitted when the crs3D() of the layer has changed.
virtual bool writeSymbology(QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories) const =0
Write the style for the layer into the document provided.
void dependenciesChanged()
Emitted when dependencies are changed.
void setError(const QgsError &error)
Sets error message.
void legendChanged()
Signal emitted when legend of the layer has changed.
QFlags< ReadFlag > ReadFlags
QFlags< LayerFlag > LayerFlags
void editingStopped()
Emitted when edited changes have been successfully written to the data provider.
void recalculateExtents() const
This is used to send a request that any mapcanvas using this layer update its extents.
void metadataChanged()
Emitted when the layer's metadata is changed.
void request3DUpdate()
Signal emitted when a layer requires an update in any 3D maps.
QgsError mError
Error.
void configChanged()
Emitted whenever the configuration is changed.
void autoRefreshIntervalChanged(int interval)
Emitted when the auto refresh interval changes.
T customFlagProperty(const QString &key, const T &defaultValue)
Returns the property value for a property based on a flag.
Q_DECL_DEPRECATED bool hasDependencyCycle(const QSet< QgsMapLayerDependency > &) const
Checks whether a new set of dependencies will introduce a cycle this method is now deprecated and alw...
void editingStarted()
Emitted when editing on this layer has started.
void isValidChanged()
Emitted when the validity of this layer changed.
QString legendPlaceholderImage() const
Returns path to the placeholder image or an empty string if a generated legend is shown.
QString mRefreshOnNofifyMessage
QString mLayerName
Name of the layer - used for display.
void setCustomFlagProperty(const QString &key, const T &value)
Set the value of a property based on a flag.
void mapTipTemplateChanged()
Emitted when the map tip template changes.
void renderer3DChanged()
Signal emitted when 3D renderer associated with the layer has changed.
virtual QgsMapLayerSelectionProperties * selectionProperties()
Returns the layer's selection properties.
void statusChanged(const QString &status)
Emit a signal with status (e.g. to be caught by QgisApp and display a msg on status bar)
bool isRefreshOnNotifyEnabled() const
Returns true if the refresh on provider nofification is enabled.
QSet< QgsMapLayerDependency > mDependencies
List of layers that may modify this layer on modification.
QFlags< StyleCategory > StyleCategories
const QgsMapLayerServerProperties * serverProperties() const
Returns QGIS Server Properties const for the map layer.
QString mProviderKey
Data provider key (name of the data provider)
void styleChanged()
Signal emitted whenever a change affects the layer's style.
std::unique_ptr< QgsDataProvider > mPreloadedProvider
Optionally used when loading a project, it is released when the layer is effectively created.
void rendererChanged()
Signal emitted when renderer is changed.
void crsChanged()
Emitted when the crs() of the layer has changed.
void dataSourceChanged()
Emitted whenever the layer's data source has been changed.
void idChanged(const QString &id)
Emitted when the layer's ID has been changed.
void setRefreshOnNofifyMessage(const QString &message)
Set the notification message that triggers repaint If refresh on notification is enabled,...
void opacityChanged(double opacity)
Emitted when the layer's opacity is changed, where opacity is a value between 0 (transparent) and 1 (...
void styleLoaded(QgsMapLayer::StyleCategories categories)
Emitted when a style has been loaded.
virtual QgsMapLayerTemporalProperties * temporalProperties()
Returns the layer's temporal properties.
void dataChanged()
Data of layer changed.
virtual QgsMapLayerRenderer * createMapRenderer(QgsRenderContext &rendererContext)=0
Returns new instance of QgsMapLayerRenderer that will be used for rendering of given context.
void willBeDeleted()
Emitted in the destructor when the layer is about to be deleted, but it is still in a perfectly valid...
void verticalCrsChanged()
Emitted when the verticalCrs() of the layer has changed.
void blendModeChanged(QPainter::CompositionMode blendMode)
Signal emitted when the blend mode is changed, through QgsMapLayer::setBlendMode()
virtual bool readSymbology(const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories)=0
Read the symbology for the current layer from the DOM node supplied.
LayerFlag
Flags for the map layer.
void setLegendPlaceholderImage(const QString &imgPath)
Set placeholder image for legend.
void appendError(const QgsErrorMessage &error)
Add error message.
QString mDataSource
Data source description string, varies by layer type.
virtual bool readSld(const QDomNode &node, QString &errorMessage)
ReadFlag
Flags which control project read behavior.
void customPropertyChanged(const QString &key)
Emitted when a custom property of the layer has been changed or removed.
void flagsChanged()
Emitted when layer's flags have been modified.
void repaintRequested(bool deferredUpdate=false)
By emitting this signal the layer tells that either appearance or content have been changed and any v...
void beforeResolveReferences(QgsProject *project)
Emitted when all layers are loaded and references can be resolved, just before the references of this...
virtual QgsMapLayerElevationProperties * elevationProperties()
Returns the layer's elevation properties.
virtual void setTransformContext(const QgsCoordinateTransformContext &transformContext)=0
Sets the coordinate transform context to transformContext.
void nameChanged()
Emitted when the name has been changed.
T customEnumProperty(const QString &key, const T &defaultValue)
Returns the property value for a property based on an enum.
StyleCategory
Categories of style to distinguish appropriate sections for import/export.
void layerModified()
Emitted when modifications has been done on layer.
virtual Q_INVOKABLE void reload()
Synchronises with changes in the datasource.
void mapTipsEnabledChanged()
Emitted when map tips are enabled or disabled for the layer.
void setCustomEnumProperty(const QString &key, const T &value)
Set the value of a property based on an enum.
PropertyType
Maplayer has a style and a metadata property.
Simple key-value store (keys = strings, values = variants) that supports loading/saving to/from XML i...
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:107
Holds data provider key, description, and associated shared library file or function pointer informat...
A container for the context for various read/write operations on objects.
A rectangle specified with double values.
Contains information about the context of a rendering operation.
Holds SLD export options and other information related to SLD export of a QGIS layer style.
An interface for classes which can visit style entity (e.g.
Represents a vector layer which manages a vector based dataset.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition qgis_sip.h:191
#define SIP_DEPRECATED
Definition qgis_sip.h:106
#define SIP_ENUM_BASETYPE(type)
Definition qgis_sip.h:278
#define SIP_SKIP
Definition qgis_sip.h:126
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_OUT
Definition qgis_sip.h:58
#define SIP_FACTORY
Definition qgis_sip.h:76
#define SIP_END
Definition qgis_sip.h:208
#define QgsDebugError(str)
Definition qgslogger.h:40
QPointer< QgsMapLayer > QgsWeakMapLayerPointer
Weak pointer for QgsMapLayer.
QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList
A list of weak pointers to QgsMapLayers.
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsTextRendererUtils::CurvedTextFlags)
const QgsCoordinateReferenceSystem & crs
Setting options for creating vector data providers.