QGIS API Documentation 3.38.0-Grenoble (exported)
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;
56
57class QDomDocument;
58class QKeyEvent;
59class QPainter;
61class QgsBox3D;
62
63/*
64 * Constants used to describe copy-paste MIME types
65 */
66#define QGSCLIPBOARD_MAPLAYER_MIME "application/qgis.maplayer"
67
68
74class CORE_EXPORT QgsMapLayer : public QObject
75{
76 Q_OBJECT
77
78 Q_PROPERTY( QString id READ id WRITE setId NOTIFY idChanged )
79 Q_PROPERTY( QString name READ name WRITE setName NOTIFY nameChanged )
80 Q_PROPERTY( int autoRefreshInterval READ autoRefreshInterval WRITE setAutoRefreshInterval NOTIFY autoRefreshIntervalChanged )
81 Q_PROPERTY( QgsLayerMetadata metadata READ metadata WRITE setMetadata NOTIFY metadataChanged )
82 Q_PROPERTY( QgsCoordinateReferenceSystem crs READ crs WRITE setCrs NOTIFY crsChanged )
83 Q_PROPERTY( QgsCoordinateReferenceSystem verticalCrs READ verticalCrs WRITE setVerticalCrs NOTIFY verticalCrsChanged )
84 Q_PROPERTY( QgsCoordinateReferenceSystem crs3D READ crs3D NOTIFY crs3DChanged )
85 Q_PROPERTY( Qgis::LayerType type READ type CONSTANT )
86 Q_PROPERTY( bool isValid READ isValid NOTIFY isValidChanged )
87 Q_PROPERTY( double opacity READ opacity WRITE setOpacity NOTIFY opacityChanged )
88 Q_PROPERTY( QString mapTipTemplate READ mapTipTemplate WRITE setMapTipTemplate NOTIFY mapTipTemplateChanged )
89 Q_PROPERTY( bool mapTipsEnabled READ mapTipsEnabled WRITE setMapTipsEnabled NOTIFY mapTipsEnabledChanged )
90
91#ifdef SIP_RUN
93 QgsMapLayer *layer = qobject_cast<QgsMapLayer *>( sipCpp );
94
95 sipType = 0;
96
97 if ( layer )
98 {
99 switch ( layer->type() )
100 {
102 sipType = sipType_QgsVectorLayer;
103 break;
105 sipType = sipType_QgsRasterLayer;
106 break;
108 sipType = sipType_QgsPluginLayer;
109 break;
111 sipType = sipType_QgsMeshLayer;
112 break;
114 sipType = sipType_QgsVectorTileLayer;
115 break;
117 sipType = sipType_QgsAnnotationLayer;
118 break;
120 sipType = sipType_QgsPointCloudLayer;
121 break;
123 sipType = sipType_QgsGroupLayer;
124 break;
126 sipType = sipType_QgsTiledSceneLayer;
127 break;
128 default:
129 sipType = nullptr;
130 break;
131 }
132 }
133 SIP_END
134#endif
135
136 public:
137
142 {
143 Style = 0,
145 };
146
153 {
154 Identifiable = 1 << 0,
155 Removable = 1 << 1,
156 Searchable = 1 << 2,
157 Private = 1 << 3,
158 };
159 Q_ENUM( LayerFlag )
160 Q_DECLARE_FLAGS( LayerFlags, LayerFlag )
161 Q_FLAG( LayerFlags )
162
168 {
169 LayerConfiguration = 1 << 0,
170 Symbology = 1 << 1,
171 Symbology3D = 1 << 2,
172 Labeling = 1 << 3,
173 Fields = 1 << 4,
174 Forms = 1 << 5,
175 Actions = 1 << 6,
176 MapTips = 1 << 7,
177 Diagrams = 1 << 8,
178 AttributeTable = 1 << 9,
179 Rendering = 1 << 10,
180 CustomProperties = 1 << 11,
181 GeometryOptions = 1 << 12,
182 Relations = 1 << 13,
183 Temporal = 1 << 14,
184 Legend = 1 << 15,
185 Elevation = 1 << 16,
186 Notes = 1 << 17,
187 AllStyleCategories = LayerConfiguration | Symbology | Symbology3D | Labeling | Fields | Forms | Actions |
188 MapTips | Diagrams | AttributeTable | Rendering | CustomProperties | GeometryOptions | Relations | Temporal | Legend | Elevation | Notes,
189 };
190 Q_ENUM( StyleCategory )
191 Q_DECLARE_FLAGS( StyleCategories, StyleCategory )
192 Q_FLAG( StyleCategories )
193
200 QgsMapLayer( Qgis::LayerType type = Qgis::LayerType::Vector, const QString &name = QString(), const QString &source = QString() );
201
202 ~QgsMapLayer() override;
203
205 QgsMapLayer( QgsMapLayer const & ) = delete;
207 QgsMapLayer &operator=( QgsMapLayer const & ) = 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
315 Q_DECL_DEPRECATED void setShortName( const QString &shortName ) SIP_DEPRECATED;
316
322 Q_DECL_DEPRECATED QString shortName() const SIP_DEPRECATED;
323
329 Q_DECL_DEPRECATED void setTitle( const QString &title ) SIP_DEPRECATED;
330
336 Q_DECL_DEPRECATED QString title() const SIP_DEPRECATED;
337
343 Q_DECL_DEPRECATED void setAbstract( const QString &abstract ) SIP_DEPRECATED;
344
350 Q_DECL_DEPRECATED QString abstract() const SIP_DEPRECATED;
351
357 Q_DECL_DEPRECATED void setKeywordList( const QString &keywords ) SIP_DEPRECATED;
358
364 Q_DECL_DEPRECATED QString keywordList() const SIP_DEPRECATED;
365
371 Q_DECL_DEPRECATED void setDataUrl( const QString &dataUrl ) SIP_DEPRECATED;
372
378 Q_DECL_DEPRECATED QString dataUrl() const SIP_DEPRECATED;
379
385 Q_DECL_DEPRECATED void setDataUrlFormat( const QString &dataUrlFormat ) SIP_DEPRECATED;
386
392 Q_DECL_DEPRECATED QString dataUrlFormat() const SIP_DEPRECATED;
393
399 Q_DECL_DEPRECATED void setAttribution( const QString &attrib ) SIP_DEPRECATED;
400
406 Q_DECL_DEPRECATED QString attribution() const SIP_DEPRECATED;
407
413 Q_DECL_DEPRECATED void setAttributionUrl( const QString &attribUrl ) SIP_DEPRECATED;
414
420 Q_DECL_DEPRECATED QString attributionUrl() const SIP_DEPRECATED;
421
422 /* Layer metadataUrl information */
423
428 QgsMapLayerServerProperties *serverProperties() { return mServerProperties.get(); };
429
434 const QgsMapLayerServerProperties *serverProperties() const { return mServerProperties.get(); } SIP_SKIP;
435
444 Q_DECL_DEPRECATED void setMetadataUrl( const QString &metaUrl ) SIP_DEPRECATED;
445
455 Q_DECL_DEPRECATED QString metadataUrl() const SIP_DEPRECATED;
456
465 Q_DECL_DEPRECATED void setMetadataUrlType( const QString &metaUrlType ) SIP_DEPRECATED;
466
476 Q_DECL_DEPRECATED QString metadataUrlType() const SIP_DEPRECATED;
477
486 Q_DECL_DEPRECATED void setMetadataUrlFormat( const QString &metaUrlFormat ) SIP_DEPRECATED;
487
497 Q_DECL_DEPRECATED QString metadataUrlFormat() const SIP_DEPRECATED;
498
504 void setBlendMode( QPainter::CompositionMode blendMode );
505
510 QPainter::CompositionMode blendMode() const;
511
520 virtual void setOpacity( double opacity );
521
530 virtual double opacity() const;
531
533 bool readOnly() const { return isReadOnly(); }
534
538 Q_INVOKABLE virtual void reload() {}
539
544
546 virtual QgsRectangle extent() const;
547
552 virtual QgsBox3D extent3D() const;
553
562 QgsRectangle wgs84Extent( bool forceRecalculate = false ) const;
563
569 bool isValid() const;
570
578 QString publicSource( bool hidePassword = false ) const;
579
585 QString source() const;
586
591 virtual QStringList subLayers() const;
592
597 virtual void setLayerOrder( const QStringList &layers );
598
604 virtual void setSubLayerVisibility( const QString &name, bool visible );
605
612 virtual bool supportsEditing() const;
613
615 virtual bool isEditable() const;
616
622 virtual bool isModified() const;
623
627 virtual bool isSpatial() const;
628
638 virtual bool isTemporary() const;
639
645 {
646 FlagDontResolveLayers = 1 << 0,
647 FlagTrustLayerMetadata = 1 << 1,
648 FlagReadExtentFromXml = 1 << 2,
649 FlagForceReadOnly = 1 << 3,
650 };
651 Q_DECLARE_FLAGS( ReadFlags, ReadFlag )
652
653
671 bool readLayerXml( const QDomElement &layerElement, QgsReadWriteContext &context,
672 QgsMapLayer::ReadFlags flags = QgsMapLayer::ReadFlags(), QgsDataProvider *preloadedProvider SIP_TRANSFER = nullptr );
673
691 bool writeLayerXml( QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context ) const;
692
696 virtual void resolveReferences( QgsProject *project );
697
702 Q_INVOKABLE QStringList customPropertyKeys() const;
703
709 Q_INVOKABLE void setCustomProperty( const QString &key, const QVariant &value );
710
715 Q_INVOKABLE QVariant customProperty( const QString &value, const QVariant &defaultValue = QVariant() ) const;
716
720 void setCustomProperties( const QgsObjectCustomProperties &properties );
721
727 const QgsObjectCustomProperties &customProperties() const;
728
738 virtual int listStylesInDatabase( QStringList &ids SIP_OUT, QStringList &names SIP_OUT,
739 QStringList &descriptions SIP_OUT, QString &msgError SIP_OUT );
740
744 virtual QString getStyleFromDatabase( const QString &styleId, QString &msgError SIP_OUT );
745
752 virtual bool deleteStyleFromDatabase( const QString &styleId, QString &msgError SIP_OUT );
753
770 virtual void saveStyleToDatabase( const QString &name, const QString &description,
771 bool useAsDefault, const QString &uiFileContent,
772 QString &msgError SIP_OUT,
774
775
776 // 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".
777 // 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.
778
787 virtual QString loadNamedStyle( const QString &theURI, bool &resultFlag SIP_OUT, bool loadFromLocalDb,
790
791#ifndef SIP_RUN
792
803 template <class T>
804 T customEnumProperty( const QString &key, const T &defaultValue )
805 {
806 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
807 Q_ASSERT( metaEnum.isValid() );
808 if ( !metaEnum.isValid() )
809 {
810 QgsDebugError( QStringLiteral( "Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
811 }
812
813 T v;
814 bool ok = false;
815
816 if ( metaEnum.isValid() )
817 {
818 // read as string
819 QByteArray ba = customProperty( key, metaEnum.valueToKey( static_cast<int>( defaultValue ) ) ).toString().toUtf8();
820 const char *vs = ba.data();
821 v = static_cast<T>( metaEnum.keyToValue( vs, &ok ) );
822 if ( ok )
823 return v;
824 }
825
826 // if failed, try to read as int (old behavior)
827 // this code shall be removed later
828 // then the method could be marked as const
829 v = static_cast<T>( customProperty( key, static_cast<int>( defaultValue ) ).toInt( &ok ) );
830 if ( metaEnum.isValid() )
831 {
832 if ( !ok || !metaEnum.valueToKey( static_cast<int>( v ) ) )
833 {
834 v = defaultValue;
835 }
836 else
837 {
838 // found property as an integer
839 // convert the property to the new form (string)
840 setCustomEnumProperty( key, v );
841 }
842 }
843
844 return v;
845 }
846
855 template <class T>
856 void setCustomEnumProperty( const QString &key, const T &value )
857 {
858 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
859 Q_ASSERT( metaEnum.isValid() );
860 if ( metaEnum.isValid() )
861 {
862 setCustomProperty( key, metaEnum.valueToKey( static_cast<int>( value ) ) );
863 }
864 else
865 {
866 QgsDebugError( QStringLiteral( "Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
867 }
868 }
869
881 template <class T>
882 T customFlagProperty( const QString &key, const T &defaultValue )
883 {
884 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
885 Q_ASSERT( metaEnum.isValid() );
886 if ( !metaEnum.isValid() )
887 {
888 QgsDebugError( QStringLiteral( "Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
889 }
890
891 T v = defaultValue;
892 bool ok = false;
893
894 if ( metaEnum.isValid() )
895 {
896 // read as string
897 QByteArray ba = customProperty( key, metaEnum.valueToKeys( defaultValue ) ).toString().toUtf8();
898 const char *vs = ba.data();
899 v = static_cast<T>( metaEnum.keysToValue( vs, &ok ) );
900 }
901 if ( !ok )
902 {
903 // if failed, try to read as int
904 const int intValue = customProperty( key, static_cast<int>( defaultValue ) ).toInt( &ok );
905 if ( metaEnum.isValid() )
906 {
907 if ( ok )
908 {
909 // check that the int value does correspond to a flag
910 // see https://stackoverflow.com/a/68495949/1548052
911 const QByteArray keys = metaEnum.valueToKeys( intValue );
912 const int intValueCheck = metaEnum.keysToValue( keys );
913 if ( intValue != intValueCheck )
914 {
915 v = defaultValue;
916 }
917 else
918 {
919 // found property as an integer
920 v = T( intValue );
921 // convert the property to the new form (string)
922 // this code could be removed
923 // then the method could be marked as const
924 setCustomFlagProperty( key, v );
925 }
926 }
927 else
928 {
929 v = defaultValue;
930 }
931 }
932 }
933
934 return v;
935 }
936
945 template <class T>
946 void setCustomFlagProperty( const QString &key, const T &value )
947 {
948 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
949 Q_ASSERT( metaEnum.isValid() );
950 if ( metaEnum.isValid() )
951 {
952 setCustomProperty( key, metaEnum.valueToKeys( value ) );
953 }
954 else
955 {
956 QgsDebugError( QStringLiteral( "Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
957 }
958 }
959#endif
960
961
966 void removeCustomProperty( const QString &key );
967
973 virtual QgsError error() const;
974
987
1006 QgsCoordinateReferenceSystem verticalCrs() const;
1007
1026 QgsCoordinateReferenceSystem crs3D() const;
1027
1038 void setCrs( const QgsCoordinateReferenceSystem &srs, bool emitSignal = true );
1039
1059 bool setVerticalCrs( const QgsCoordinateReferenceSystem &crs, QString *errorMessage SIP_OUT = nullptr );
1060
1066 QgsCoordinateTransformContext transformContext( ) const;
1067
1068
1073 static QString formatLayerName( const QString &name );
1074
1081 virtual QString metadataUri() const;
1082
1088 void exportNamedMetadata( QDomDocument &doc, QString &errorMsg ) const;
1089
1098 virtual QString saveDefaultMetadata( bool &resultFlag SIP_OUT );
1099
1113 QString saveNamedMetadata( const QString &uri, bool &resultFlag );
1114
1115 // 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".
1116 // 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.
1117
1131 virtual QString loadNamedMetadata( const QString &uri, bool &resultFlag SIP_OUT );
1132
1133 // 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".
1134 // 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.
1135
1144 virtual QString loadDefaultMetadata( bool &resultFlag );
1145
1153 bool loadNamedMetadataFromDatabase( const QString &db, const QString &uri, QString &qmd );
1154
1161 bool importNamedMetadata( QDomDocument &document, QString &errorMessage );
1162
1171 virtual QString styleURI() const;
1172
1173 // 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".
1174 // 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.
1175
1185 virtual QString loadDefaultStyle( bool &resultFlag SIP_OUT );
1186
1187 // 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".
1188 // 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.
1189
1206 virtual QString loadNamedStyle( const QString &uri, bool &resultFlag SIP_OUT, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories, Qgis::LoadStyleFlags flags = Qgis::LoadStyleFlags() );
1207
1215 virtual bool loadNamedStyleFromDatabase( const QString &db, const QString &uri, QString &qml SIP_OUT );
1216
1225 virtual bool importNamedStyle( QDomDocument &doc, QString &errorMsg SIP_OUT,
1227
1236 virtual void exportNamedStyle( QDomDocument &doc, QString &errorMsg SIP_OUT, const QgsReadWriteContext &context = QgsReadWriteContext(),
1238
1239
1247 virtual void exportSldStyle( QDomDocument &doc, QString &errorMsg ) const;
1248
1257 virtual void exportSldStyleV2( QDomDocument &doc, QString &errorMsg, const QgsSldExportContext &exportContext ) const;
1258
1270 virtual QString saveDefaultStyle( bool &resultFlag SIP_OUT, StyleCategories categories );
1271
1283 Q_DECL_DEPRECATED virtual QString saveDefaultStyle( bool &resultFlag SIP_OUT ) SIP_DEPRECATED;
1284
1300 virtual QString saveNamedStyle( const QString &uri, bool &resultFlag SIP_OUT, StyleCategories categories = AllStyleCategories );
1301
1311 virtual QString saveSldStyle( const QString &uri, bool &resultFlag ) const;
1312
1323 virtual QString saveSldStyleV2( bool &resultFlag SIP_OUT, const QgsSldExportContext &exportContext ) const;
1324
1333 virtual QString loadSldStyle( const QString &uri, bool &resultFlag );
1334
1335 virtual bool readSld( const QDomNode &node, QString &errorMessage )
1336 { Q_UNUSED( node ) errorMessage = QStringLiteral( "Layer type %1 not supported" ).arg( static_cast<int>( type() ) ); return false; }
1337
1338
1339
1348 virtual bool readSymbology( const QDomNode &node, QString &errorMessage,
1349 QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories ) = 0;
1350
1360 virtual bool readStyle( const QDomNode &node, QString &errorMessage,
1361 QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories );
1362
1373 virtual bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context,
1374 StyleCategories categories = AllStyleCategories ) const = 0;
1375
1387 virtual bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context,
1388 StyleCategories categories = AllStyleCategories ) const;
1389
1390
1420 void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, bool loadDefaultStyleFlag = false );
1421
1451 void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, bool loadDefaultStyleFlag = false );
1452
1482 void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags );
1483
1487 QString providerType() const;
1488
1490 QUndoStack *undoStack();
1491
1495 QUndoStack *undoStackStyles();
1496
1500 void setLegendUrl( const QString &legendUrl ) { mLegendUrl = legendUrl; }
1501
1505 QString legendUrl() const { return mLegendUrl; }
1506
1510 void setLegendUrlFormat( const QString &legendUrlFormat ) { mLegendUrlFormat = legendUrlFormat; }
1511
1515 QString legendUrlFormat() const { return mLegendUrlFormat; }
1516
1521 void setLegend( QgsMapLayerLegend *legend SIP_TRANSFER );
1522
1526 QgsMapLayerLegend *legend() const;
1527
1531 QgsMapLayerStyleManager *styleManager() const;
1532
1536 void setRenderer3D( QgsAbstract3DRenderer *renderer SIP_TRANSFER );
1537
1541 QgsAbstract3DRenderer *renderer3D() const;
1542
1551 bool isInScaleRange( double scale ) const;
1552
1563 double minimumScale() const;
1564
1575 double maximumScale() const;
1576
1585 bool hasScaleBasedVisibility() const;
1586
1593 Q_DECL_DEPRECATED bool hasAutoRefreshEnabled() const SIP_DEPRECATED;
1594
1601 Qgis::AutoRefreshMode autoRefreshMode() const;
1602
1609 int autoRefreshInterval() const;
1610
1621 void setAutoRefreshInterval( int interval );
1622
1629 Q_DECL_DEPRECATED void setAutoRefreshEnabled( bool enabled ) SIP_DEPRECATED;
1630
1637 void setAutoRefreshMode( Qgis::AutoRefreshMode mode );
1638
1644 virtual const QgsLayerMetadata &metadata() const;
1645
1651 virtual void setMetadata( const QgsLayerMetadata &metadata );
1652
1656 virtual QString htmlMetadata() const;
1657
1659 virtual QDateTime timestamp() const;
1660
1667 virtual QSet<QgsMapLayerDependency> dependencies() const;
1668
1673 QString refreshOnNotifyMessage() const { return mRefreshOnNofifyMessage; }
1674
1679 bool isRefreshOnNotifyEnabled() const { return mIsRefreshOnNofifyEnabled; }
1680
1689 QString originalXmlProperties() const;
1690
1698 void setOriginalXmlProperties( const QString &originalXmlProperties );
1699
1704 static QString generateId( const QString &layerName );
1705
1715 virtual bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
1716
1723
1730
1737
1743 QString legendPlaceholderImage() const { return mLegendPlaceholderImage;}
1744
1750 void setLegendPlaceholderImage( const QString &imgPath ) { mLegendPlaceholderImage = imgPath; }
1751
1758 virtual bool hasMapTips() const;
1759
1767 QString mapTipTemplate() const;
1768
1776 void setMapTipTemplate( const QString &mapTipTemplate );
1777
1784 void setMapTipsEnabled( bool enabled );
1785
1790 bool mapTipsEnabled() const;
1791
1799 static QgsDataProvider::ReadFlags providerReadFlags( const QDomNode &layerNode, QgsMapLayer::ReadFlags layerReadFlags );
1800
1801 public slots:
1802
1812 void setMinimumScale( double scale );
1813
1823 void setMaximumScale( double scale );
1824
1832 void setScaleBasedVisibility( bool enabled );
1833
1842 void triggerRepaint( bool deferredUpdate = false );
1843
1850 void trigger3DUpdate();
1851
1855 void emitStyleChanged();
1856
1864 virtual bool setDependencies( const QSet<QgsMapLayerDependency> &layers );
1865
1870 void setRefreshOnNotifyEnabled( bool enabled );
1871
1878 void setRefreshOnNofifyMessage( const QString &message ) { mRefreshOnNofifyMessage = message; }
1879
1885 virtual void setTransformContext( const QgsCoordinateTransformContext &transformContext ) = 0;
1886
1887#ifdef SIP_RUN
1888 SIP_PYOBJECT __repr__();
1889 % MethodCode
1890 QString str = QStringLiteral( "<QgsMapLayer: '%1' (%2)>" ).arg( sipCpp->name(), sipCpp->dataProvider() ? sipCpp->dataProvider()->name() : QStringLiteral( "Invalid" ) );
1891 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
1892 % End
1893#endif
1894
1901 QgsProject *project() const;
1902
1903 signals:
1904
1912
1914 void statusChanged( const QString &status );
1915
1924 void idChanged( const QString &id );
1925
1930
1940
1951
1968
1975 void repaintRequested( bool deferredUpdate = false );
1976
1979
1982
1984 void blendModeChanged( QPainter::CompositionMode blendMode );
1985
1994 void opacityChanged( double opacity );
1995
2001
2013
2018
2023
2030
2036
2041
2048
2053 void autoRefreshIntervalChanged( int interval );
2054
2061
2069
2078
2085
2092
2098 void customPropertyChanged( const QString &key );
2099
2105
2111
2117
2124
2132
2133 private slots:
2134
2135 void onNotified( const QString &message );
2136
2152 virtual void setDataSourcePrivate( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags );
2153
2154 protected:
2155
2160 void clone( QgsMapLayer *layer ) const;
2161
2163 virtual void setExtent( const QgsRectangle &rect );
2164
2169 virtual void setExtent3D( const QgsBox3D &box );
2170
2172 void setValid( bool valid );
2173
2178 virtual bool readXml( const QDomNode &layer_node, QgsReadWriteContext &context );
2179
2184 virtual bool writeXml( QDomNode &layer_node, QDomDocument &document, const QgsReadWriteContext &context ) const;
2185
2197 virtual QString encodedSource( const QString &source, const QgsReadWriteContext &context ) const;
2198
2211 virtual QString decodedSource( const QString &source, const QString &dataProvider, const QgsReadWriteContext &context ) const;
2212
2218 void readCustomProperties( const QDomNode &layerNode, const QString &keyStartsWith = QString() );
2219
2221 void writeCustomProperties( QDomNode &layerNode, QDomDocument &doc ) const;
2222
2224 void readStyleManager( const QDomNode &layerNode );
2226 void writeStyleManager( QDomNode &layerNode, QDomDocument &doc ) const;
2227
2231 void writeCommonStyle( QDomElement &layerElement, QDomDocument &document,
2232 const QgsReadWriteContext &context,
2233 StyleCategories categories = AllStyleCategories ) const;
2234
2238 void readCommonStyle( const QDomElement &layerElement, const QgsReadWriteContext &context,
2239 StyleCategories categories = AllStyleCategories );
2240
2242 void setProviderType( const QString &providerType );
2243
2244#ifndef SIP_RUN
2245#if 0
2247 void connectNotify( const char *signal ) override;
2248#endif
2249#endif
2250
2252 void appendError( const QgsErrorMessage &error ) { mError.append( error );}
2254 void setError( const QgsError &error ) { mError = error;}
2255
2262 void invalidateWgs84Extent();
2263
2265 bool mValid = false;
2266
2269
2271 QString mLayerName;
2272
2274 QString mLegendUrl;
2276
2279
2281 QSet<QgsMapLayerDependency> mDependencies;
2282
2288 Q_DECL_DEPRECATED bool hasDependencyCycle( const QSet<QgsMapLayerDependency> & ) const {return false;}
2289
2290 bool mIsRefreshOnNofifyEnabled = false;
2292
2295
2296 //TODO QGIS 4 - move to readXml as a new argument (breaks API)
2297
2300
2306 bool mShouldValidateCrs = true;
2307
2313 double mLayerOpacity = 1.0;
2314
2320 int mBlockStyleChangedSignal = 0;
2321
2322#ifndef SIP_RUN
2323
2332 QString crsHtmlMetadata() const;
2333#endif
2334
2335#ifndef SIP_RUN
2336
2345 QString generalHtmlMetadata() const;
2346#endif
2347
2348#ifndef SIP_RUN
2349
2357 std::unique_ptr<QgsDataProvider> mPreloadedProvider;
2358#endif
2359
2360 private:
2361
2362 virtual QString baseURI( PropertyType type ) const;
2363 QString saveNamedProperty( const QString &uri, QgsMapLayer::PropertyType type,
2364 bool &resultFlag, StyleCategories categories = AllStyleCategories );
2365 QString loadNamedProperty( const QString &uri, QgsMapLayer::PropertyType type,
2366 bool &namedPropertyExists, bool &propertySuccessfullyLoaded, StyleCategories categories = AllStyleCategories, Qgis::LoadStyleFlags flags = Qgis::LoadStyleFlags() );
2367 bool loadNamedPropertyFromDatabase( const QString &db, const QString &uri, QString &xml, QgsMapLayer::PropertyType type );
2368
2369 // const method because extents are mutable
2370 void updateExtent( const QgsRectangle &extent ) const;
2371 void updateExtent( const QgsBox3D &extent ) const;
2372
2373 bool rebuildCrs3D( QString *error = nullptr );
2374
2379 virtual bool isReadOnly() const;
2380
2386 QgsCoordinateReferenceSystem mVerticalCrs;
2388
2390 QString mID;
2391
2393 Qgis::LayerType mLayerType;
2394
2395 LayerFlags mFlags = LayerFlags( Identifiable | Removable | Searchable );
2396
2398 QPainter::CompositionMode mBlendMode = QPainter::CompositionMode_SourceOver;
2399
2401 QString mTag;
2402
2403 //set some generous defaults for scale based visibility
2404
2406 double mMinScale = 0;
2408 double mMaxScale = 100000000;
2410 bool mScaleBasedVisibility = false;
2411
2415 std::unique_ptr< QgsMapLayerServerProperties > mServerProperties;
2416
2418 QUndoStack *mUndoStack = nullptr;
2419
2420 QUndoStack *mUndoStackStyles = nullptr;
2421
2423 QgsObjectCustomProperties mCustomProperties;
2424
2426 QgsMapLayerLegend *mLegend = nullptr;
2427
2429 QgsMapLayerStyleManager *mStyleManager = nullptr;
2430
2432
2434 QTimer *mRefreshTimer = nullptr;
2435
2436 QgsLayerMetadata mMetadata;
2437
2439 QgsAbstract3DRenderer *m3DRenderer = nullptr;
2440
2442 mutable QgsBox3D mExtent3D;
2443
2445 mutable QgsRectangle mExtent2D;
2446
2448 mutable QgsRectangle mWgs84Extent;
2449
2455 QString mOriginalXmlProperties;
2456
2458 bool mRepaintRequestedFired = false;
2459
2461 QString mLegendPlaceholderImage;
2462
2464 QString mMapTipTemplate;
2465
2467 bool mMapTipsEnabled = true;
2468
2469 friend class QgsVectorLayer;
2470 friend class TestQgsProject;
2471 friend class TestQgsMapLayer;
2472};
2473
2478
2479
2480#ifndef SIP_RUN
2481
2486typedef QPointer< QgsMapLayer > QgsWeakMapLayerPointer;
2487
2492typedef QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList;
2493#endif
2494
2495#endif
The Qgis class provides global constants for use throughout the application.
Definition qgis.h:54
LayerType
Types of layers that can be added to a map.
Definition qgis.h:114
@ 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:170
AutoRefreshMode
Map layer automatic refresh modes.
Definition qgis.h:1928
@ 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.
QFlags< ReadFlag > ReadFlags
QgsErrorMessage represents single error message.
Definition qgserror.h:33
QgsError is container for error messages (report).
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:75
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
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 str(x)
Definition qgis.cpp:38
#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
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)
#define QgsDebugError(str)
Definition qgslogger.h:38
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.