QGIS API Documentation 3.99.0-Master (d270888f95f)
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.h"
22#include "qgis_core.h"
23#include "qgis_sip.h"
25#include "qgsdataprovider.h"
26#include "qgserror.h"
27#include "qgslayermetadata.h"
28#include "qgslogger.h"
33#include "qgsreadwritecontext.h"
34#include "qgsrectangle.h"
35
36#include <QDateTime>
37#include <QDomNode>
38#include <QIcon>
39#include <QImage>
40#include <QObject>
41#include <QPainter>
42#include <QSet>
43#include <QString>
44#include <QUndoStack>
45#include <QVariant>
46
47using namespace Qt::StringLiterals;
48
51class QgsDataProvider;
55class QgsProject;
63
64class QDomDocument;
65class QKeyEvent;
66class QPainter;
68class QgsBox3D;
69
70/*
71 * Constants used to describe copy-paste MIME types
72 */
73#define QGSCLIPBOARD_MAPLAYER_MIME "application/qgis.maplayer"
74
75
82class CORE_EXPORT QgsMapLayer : public QObject
83{
84 Q_OBJECT
85
86 Q_PROPERTY( QString id READ id WRITE setId NOTIFY idChanged )
87 Q_PROPERTY( QString name READ name WRITE setName NOTIFY nameChanged )
90 Q_PROPERTY( QgsCoordinateReferenceSystem crs READ crs WRITE setCrs NOTIFY crsChanged )
93 Q_PROPERTY( Qgis::LayerType type READ type CONSTANT )
94 Q_PROPERTY( bool isValid READ isValid NOTIFY isValidChanged )
95 Q_PROPERTY( double opacity READ opacity WRITE setOpacity NOTIFY opacityChanged )
99 Q_PROPERTY( QgsMapLayer::LayerFlags flags READ flags WRITE setFlags NOTIFY flagsChanged )
100
101#ifdef SIP_RUN
103 QgsMapLayer *layer = qobject_cast<QgsMapLayer *>( sipCpp );
104
105 sipType = 0;
106
107 if ( layer )
108 {
109 switch ( layer->type() )
110 {
112 sipType = sipType_QgsVectorLayer;
113 break;
115 sipType = sipType_QgsRasterLayer;
116 break;
118 sipType = sipType_QgsPluginLayer;
119 break;
121 sipType = sipType_QgsMeshLayer;
122 break;
124 sipType = sipType_QgsVectorTileLayer;
125 break;
127 sipType = sipType_QgsAnnotationLayer;
128 break;
130 sipType = sipType_QgsPointCloudLayer;
131 break;
133 sipType = sipType_QgsGroupLayer;
134 break;
136 sipType = sipType_QgsTiledSceneLayer;
137 break;
138 default:
139 sipType = nullptr;
140 break;
141 }
142 }
143 SIP_END
144#endif
145
146 public:
147
152 {
153 Style = 0,
155 };
156
163 {
164 Identifiable = 1 << 0,
165 Removable = 1 << 1,
166 Searchable = 1 << 2,
167 Private = 1 << 3,
168 };
169 Q_ENUM( LayerFlag )
170 Q_DECLARE_FLAGS( LayerFlags, LayerFlag )
171 Q_FLAG( LayerFlags )
172
202 Q_ENUM( StyleCategory )
203 Q_DECLARE_FLAGS( StyleCategories, StyleCategory )
204 Q_FLAG( StyleCategories )
205
212 QgsMapLayer( Qgis::LayerType type = Qgis::LayerType::Vector, const QString &name = QString(), const QString &source = QString() );
213
214 ~QgsMapLayer() override;
215
216 QgsMapLayer( const QgsMapLayer & ) = delete;
217 QgsMapLayer &operator=( const QgsMapLayer & ) = delete;
218
224 virtual QgsMapLayer *clone() const = 0;
225
229 Qgis::LayerType type() const;
230
242
254
264 virtual Qgis::MapLayerProperties properties() const;
265
270 static QString extensionPropertyType( PropertyType type );
271
278 QString id() const;
279
295 bool setId( const QString &id );
296
301 void setName( const QString &name );
302
307 QString name() const;
308
312 Q_INVOKABLE virtual QgsDataProvider *dataProvider();
313
318 virtual const QgsDataProvider *dataProvider() const SIP_SKIP;
319
325
331 Q_DECL_DEPRECATED void setShortName( const QString &shortName ) SIP_DEPRECATED;
332
338 Q_DECL_DEPRECATED QString shortName() const SIP_DEPRECATED;
339
345 Q_DECL_DEPRECATED void setTitle( const QString &title ) SIP_DEPRECATED;
346
352 Q_DECL_DEPRECATED QString title() const SIP_DEPRECATED;
353
359 Q_DECL_DEPRECATED void setAbstract( const QString &abstract ) SIP_DEPRECATED;
360
366 Q_DECL_DEPRECATED QString abstract() const SIP_DEPRECATED;
367
373 Q_DECL_DEPRECATED void setKeywordList( const QString &keywords ) SIP_DEPRECATED;
374
380 Q_DECL_DEPRECATED QString keywordList() const SIP_DEPRECATED;
381
387 Q_DECL_DEPRECATED void setDataUrl( const QString &dataUrl ) SIP_DEPRECATED;
388
394 Q_DECL_DEPRECATED QString dataUrl() const SIP_DEPRECATED;
395
401 Q_DECL_DEPRECATED void setDataUrlFormat( const QString &dataUrlFormat ) SIP_DEPRECATED;
402
408 Q_DECL_DEPRECATED QString dataUrlFormat() const SIP_DEPRECATED;
409
415 Q_DECL_DEPRECATED void setAttribution( const QString &attrib ) SIP_DEPRECATED;
416
422 Q_DECL_DEPRECATED QString attribution() const SIP_DEPRECATED;
423
429 Q_DECL_DEPRECATED void setAttributionUrl( const QString &attribUrl ) SIP_DEPRECATED;
430
436 Q_DECL_DEPRECATED QString attributionUrl() const SIP_DEPRECATED;
437
438 /* Layer metadataUrl information */
439
444 QgsMapLayerServerProperties *serverProperties() { return mServerProperties.get(); };
445
450 const QgsMapLayerServerProperties *serverProperties() const { return mServerProperties.get(); } SIP_SKIP;
451
460 Q_DECL_DEPRECATED void setMetadataUrl( const QString &metaUrl ) SIP_DEPRECATED;
461
471 Q_DECL_DEPRECATED QString metadataUrl() const SIP_DEPRECATED;
472
481 Q_DECL_DEPRECATED void setMetadataUrlType( const QString &metaUrlType ) SIP_DEPRECATED;
482
492 Q_DECL_DEPRECATED QString metadataUrlType() const SIP_DEPRECATED;
493
502 Q_DECL_DEPRECATED void setMetadataUrlFormat( const QString &metaUrlFormat ) SIP_DEPRECATED;
503
513 Q_DECL_DEPRECATED QString metadataUrlFormat() const SIP_DEPRECATED;
514
520 void setBlendMode( QPainter::CompositionMode blendMode );
521
526 QPainter::CompositionMode blendMode() const;
527
536 virtual void setOpacity( double opacity );
537
546 virtual double opacity() const;
547
549 bool readOnly() const { return isReadOnly(); }
550
554 Q_INVOKABLE virtual void reload() {}
555
560
562 virtual QgsRectangle extent() const;
563
568 virtual QgsBox3D extent3D() const;
569
578 QgsRectangle wgs84Extent( bool forceRecalculate = false ) const;
579
585 bool isValid() const;
586
587 // TODO QGIS 5.0: consider changing bool hidePassword to an enumeration: HIDE_CREDENTIALS / REDACT_CREDENTIALS
588 // to avoid the ambiguity of the double negation (hide = false)
589
597 QString publicSource( bool hidePassword = false ) const;
598
604 QString source() const;
605
610 virtual QStringList subLayers() const;
611
616 virtual void setLayerOrder( const QStringList &layers );
617
623 virtual void setSubLayerVisibility( const QString &name, bool visible );
624
631 virtual bool supportsEditing() const;
632
634 virtual bool isEditable() const;
635
641 virtual bool isModified() const;
642
646 virtual bool isSpatial() const;
647
657 virtual bool isTemporary() const;
658
670 Q_DECLARE_FLAGS( ReadFlags, ReadFlag )
671
672
689 bool readLayerXml( const QDomElement &layerElement, QgsReadWriteContext &context,
691
707 bool writeLayerXml( QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context ) const;
708
712 virtual void resolveReferences( QgsProject *project );
713
718 Q_INVOKABLE QStringList customPropertyKeys() const;
719
725 Q_INVOKABLE void setCustomProperty( const QString &key, const QVariant &value );
726
731 Q_INVOKABLE QVariant customProperty( const QString &value, const QVariant &defaultValue = QVariant() ) const;
732
737
744
754 virtual int listStylesInDatabase( QStringList &ids SIP_OUT, QStringList &names SIP_OUT,
755 QStringList &descriptions SIP_OUT, QString &msgError SIP_OUT );
756
760 virtual QString getStyleFromDatabase( const QString &styleId, QString &msgError SIP_OUT );
761
768 virtual bool deleteStyleFromDatabase( const QString &styleId, QString &msgError SIP_OUT );
769
775 enum class SaveStyleResult SIP_ENUM_BASETYPE( IntFlag )
776 {
777 Success = 0,
778 QmlGenerationFailed = 1 << 0,
779 SldGenerationFailed = 1 << 1,
780 DatabaseWriteFailed = 1 << 2,
781 };
782 Q_ENUM( SaveStyleResult )
783
784
790 Q_FLAG( SaveStyleResults )
791
809 Q_DECL_DEPRECATED virtual void saveStyleToDatabase( const QString &name, const QString &description,
810 bool useAsDefault, const QString &uiFileContent,
811 QString &msgError SIP_OUT,
813
827 QgsMapLayer::SaveStyleResults saveStyleToDatabaseV2( const QString &name, const QString &description,
828 bool useAsDefault, const QString &uiFileContent,
829 QString &msgError SIP_OUT,
831
832 // TODO QGIS 5.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".
833 // 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.
834
845 virtual QString loadNamedStyle( const QString &theURI, bool &resultFlag SIP_OUT, bool loadFromLocalDb,
847 Qgis::LoadStyleFlags flags = Qgis::LoadStyleFlags() );
848
849#ifndef SIP_RUN
850
861 template <class T>
862 T customEnumProperty( const QString &key, const T &defaultValue )
863 {
864 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
865 Q_ASSERT( metaEnum.isValid() );
866 if ( !metaEnum.isValid() )
867 {
868 QgsDebugError( u"Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration."_s );
869 }
870
871 T v;
872 bool ok = false;
873
874 if ( metaEnum.isValid() )
875 {
876 // read as string
877 QByteArray ba = customProperty( key, metaEnum.valueToKey( static_cast<int>( defaultValue ) ) ).toString().toUtf8();
878 const char *vs = ba.data();
879 v = static_cast<T>( metaEnum.keyToValue( vs, &ok ) );
880 if ( ok )
881 return v;
882 }
883
884 // if failed, try to read as int (old behavior)
885 // this code shall be removed later
886 // then the method could be marked as const
887 v = static_cast<T>( customProperty( key, static_cast<int>( defaultValue ) ).toInt( &ok ) );
888 if ( metaEnum.isValid() )
889 {
890 if ( !ok || !metaEnum.valueToKey( static_cast<int>( v ) ) )
891 {
892 v = defaultValue;
893 }
894 else
895 {
896 // found property as an integer
897 // convert the property to the new form (string)
898 setCustomEnumProperty( key, v );
899 }
900 }
901
902 return v;
903 }
904
913 template <class T>
914 void setCustomEnumProperty( const QString &key, const T &value )
915 {
916 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
917 Q_ASSERT( metaEnum.isValid() );
918 if ( metaEnum.isValid() )
919 {
920 setCustomProperty( key, metaEnum.valueToKey( static_cast<int>( value ) ) );
921 }
922 else
923 {
924 QgsDebugError( u"Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration."_s );
925 }
926 }
927
939 template <class T>
940 T customFlagProperty( const QString &key, const T &defaultValue )
941 {
942 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
943 Q_ASSERT( metaEnum.isValid() );
944 if ( !metaEnum.isValid() )
945 {
946 QgsDebugError( u"Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration."_s );
947 }
948
949 T v = defaultValue;
950 bool ok = false;
951
952 if ( metaEnum.isValid() )
953 {
954 // read as string
955 QByteArray ba = customProperty( key, metaEnum.valueToKeys( defaultValue ) ).toString().toUtf8();
956 const char *vs = ba.data();
957 v = static_cast<T>( metaEnum.keysToValue( vs, &ok ) );
958 }
959 if ( !ok )
960 {
961 // if failed, try to read as int
962 const int intValue = customProperty( key, static_cast<int>( defaultValue ) ).toInt( &ok );
963 if ( metaEnum.isValid() )
964 {
965 if ( ok )
966 {
967 // check that the int value does correspond to a flag
968 // see https://stackoverflow.com/a/68495949/1548052
969 const QByteArray keys = metaEnum.valueToKeys( intValue );
970 const int intValueCheck = metaEnum.keysToValue( keys );
971 if ( intValue != intValueCheck )
972 {
973 v = defaultValue;
974 }
975 else
976 {
977 // found property as an integer
978 v = T( intValue );
979 // convert the property to the new form (string)
980 // this code could be removed
981 // then the method could be marked as const
982 setCustomFlagProperty( key, v );
983 }
984 }
985 else
986 {
987 v = defaultValue;
988 }
989 }
990 }
991
992 return v;
993 }
994
1003 template <class T>
1004 void setCustomFlagProperty( const QString &key, const T &value )
1005 {
1006 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
1007 Q_ASSERT( metaEnum.isValid() );
1008 if ( metaEnum.isValid() )
1009 {
1010 setCustomProperty( key, metaEnum.valueToKeys( value ) );
1011 }
1012 else
1013 {
1014 QgsDebugError( u"Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration."_s );
1015 }
1016 }
1017#endif
1018
1019
1024 void removeCustomProperty( const QString &key );
1025
1031 virtual QgsError error() const;
1032
1044 QgsCoordinateReferenceSystem crs() const;
1045
1064 QgsCoordinateReferenceSystem verticalCrs() const;
1065
1084 QgsCoordinateReferenceSystem crs3D() const;
1085
1096 void setCrs( const QgsCoordinateReferenceSystem &srs, bool emitSignal = true );
1097
1117 bool setVerticalCrs( const QgsCoordinateReferenceSystem &crs, QString *errorMessage SIP_OUT = nullptr );
1118
1124 QgsCoordinateTransformContext transformContext( ) const;
1125
1126
1131 static QString formatLayerName( const QString &name );
1132
1139 virtual QString metadataUri() const;
1140
1146 void exportNamedMetadata( QDomDocument &doc, QString &errorMsg ) const;
1147
1156 virtual QString saveDefaultMetadata( bool &resultFlag SIP_OUT );
1157
1171 QString saveNamedMetadata( const QString &uri, bool &resultFlag SIP_OUT );
1172
1173 // TODO QGIS 5.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".
1174 // 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.
1175
1189 virtual QString loadNamedMetadata( const QString &uri, bool &resultFlag SIP_OUT );
1190
1191 // TODO QGIS 5.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".
1192 // 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.
1193
1202 virtual QString loadDefaultMetadata( bool &resultFlag SIP_OUT );
1203
1211 bool loadNamedMetadataFromDatabase( const QString &db, const QString &uri, QString &qmd );
1212
1219 bool importNamedMetadata( QDomDocument &document, QString &errorMessage );
1220
1229 virtual QString styleURI() const;
1230
1231 // TODO QGIS 5.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".
1232 // 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.
1233
1243 virtual QString loadDefaultStyle( bool &resultFlag SIP_OUT );
1244
1245 // TODO QGIS 5.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".
1246 // 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.
1247
1264 virtual QString loadNamedStyle( const QString &uri, bool &resultFlag SIP_OUT, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories, Qgis::LoadStyleFlags flags = Qgis::LoadStyleFlags() );
1265
1273 virtual bool loadNamedStyleFromDatabase( const QString &db, const QString &uri, QString &qml SIP_OUT );
1274
1283 virtual bool importNamedStyle( QDomDocument &doc, QString &errorMsg SIP_OUT,
1285
1294 virtual void exportNamedStyle( QDomDocument &doc, QString &errorMsg SIP_OUT, const QgsReadWriteContext &context = QgsReadWriteContext(),
1296
1297
1305 Q_DECL_DEPRECATED virtual void exportSldStyle( QDomDocument &doc, QString &errorMsg ) const SIP_DEPRECATED;
1306
1314 Q_DECL_DEPRECATED virtual void exportSldStyleV2( QDomDocument &doc, QString &errorMsg, QgsSldExportContext &exportContext ) const SIP_DEPRECATED;
1315
1325 virtual QDomDocument exportSldStyleV3( QgsSldExportContext &exportContext ) const;
1326
1338 virtual QString saveDefaultStyle( bool &resultFlag SIP_OUT, StyleCategories categories );
1339
1351 Q_DECL_DEPRECATED virtual QString saveDefaultStyle( bool &resultFlag SIP_OUT ) SIP_DEPRECATED;
1352
1368 virtual QString saveNamedStyle( const QString &uri, bool &resultFlag SIP_OUT, StyleCategories categories = AllStyleCategories );
1369
1379 virtual QString saveSldStyle( const QString &uri, bool &resultFlag SIP_OUT ) const;
1380
1391 virtual QString saveSldStyleV2( bool &resultFlag SIP_OUT, QgsSldExportContext &exportContext ) const;
1392
1401 virtual QString loadSldStyle( const QString &uri, bool &resultFlag SIP_OUT );
1402
1403 virtual bool readSld( const QDomNode &node, QString &errorMessage )
1404 { Q_UNUSED( node ) errorMessage = u"Layer type %1 not supported"_s.arg( static_cast<int>( type() ) ); return false; }
1405
1406
1407
1416 virtual bool readSymbology( const QDomNode &node, QString &errorMessage,
1417 QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories ) = 0;
1418
1428 virtual bool readStyle( const QDomNode &node, QString &errorMessage,
1430
1441 virtual bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context,
1442 StyleCategories categories = AllStyleCategories ) const = 0;
1443
1455 virtual bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context,
1456 StyleCategories categories = AllStyleCategories ) const;
1457
1458
1489 void setDataSource( const QString &dataSource, const QString &baseName = QString(), const QString &provider = QString(), bool loadDefaultStyleFlag = false );
1490
1520 void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, bool loadDefaultStyleFlag = false );
1521
1551 void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, Qgis::DataProviderReadFlags flags );
1552
1556 QString providerType() const;
1557
1559 QUndoStack *undoStack();
1560
1564 QUndoStack *undoStackStyles();
1565
1571 Q_DECL_DEPRECATED void setLegendUrl( const QString &legendUrl ) SIP_DEPRECATED;
1572
1578 Q_DECL_DEPRECATED QString legendUrl() const SIP_DEPRECATED;
1579
1585 Q_DECL_DEPRECATED void setLegendUrlFormat( const QString &legendUrlFormat ) SIP_DEPRECATED;
1586
1592 Q_DECL_DEPRECATED QString legendUrlFormat() const SIP_DEPRECATED;
1593
1599
1603 QgsMapLayerLegend *legend() const;
1604
1609
1614
1619
1628 bool isInScaleRange( double scale ) const;
1629
1640 double minimumScale() const;
1641
1652 double maximumScale() const;
1653
1662 bool hasScaleBasedVisibility() const;
1663
1670 Q_DECL_DEPRECATED bool hasAutoRefreshEnabled() const SIP_DEPRECATED;
1671
1678 Qgis::AutoRefreshMode autoRefreshMode() const;
1679
1686 int autoRefreshInterval() const;
1687
1698 void setAutoRefreshInterval( int interval );
1699
1706 Q_DECL_DEPRECATED void setAutoRefreshEnabled( bool enabled ) SIP_DEPRECATED;
1707
1714 void setAutoRefreshMode( Qgis::AutoRefreshMode mode );
1715
1721 virtual const QgsLayerMetadata &metadata() const;
1722
1728 virtual void setMetadata( const QgsLayerMetadata &metadata );
1729
1733 virtual QString htmlMetadata() const;
1734
1736 virtual QDateTime timestamp() const;
1737
1744 virtual QSet<QgsMapLayerDependency> dependencies() const;
1745
1751
1757
1766 QString originalXmlProperties() const;
1767
1775 void setOriginalXmlProperties( const QString &originalXmlProperties );
1776
1781 static QString generateId( const QString &layerName );
1782
1792 virtual bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
1793
1803 virtual bool accept( QgsObjectEntityVisitorInterface *visitor, const QgsObjectVisitorContext &context ) const;
1804
1811
1818
1825
1826
1832 virtual QgsAbstractProfileSource *profileSource() { return nullptr; }
1833
1839 QString legendPlaceholderImage() const { return mLegendPlaceholderImage;}
1840
1846 void setLegendPlaceholderImage( const QString &imgPath ) { mLegendPlaceholderImage = imgPath; }
1847
1854 virtual bool hasMapTips() const;
1855
1863 QString mapTipTemplate() const;
1864
1872 void setMapTipTemplate( const QString &mapTipTemplate );
1873
1880 void setMapTipsEnabled( bool enabled );
1881
1886 bool mapTipsEnabled() const;
1887
1895 static Qgis::DataProviderReadFlags providerReadFlags( const QDomNode &layerNode, QgsMapLayer::ReadFlags layerReadFlags );
1896
1897 public slots:
1898
1908 void setMinimumScale( double scale );
1909
1919 void setMaximumScale( double scale );
1920
1928 void setScaleBasedVisibility( bool enabled );
1929
1938 void triggerRepaint( bool deferredUpdate = false );
1939
1946 void trigger3DUpdate();
1947
1951 void emitStyleChanged();
1952
1960 virtual bool setDependencies( const QSet<QgsMapLayerDependency> &layers );
1961
1966 void setRefreshOnNotifyEnabled( bool enabled );
1967
1974 void setRefreshOnNofifyMessage( const QString &message ) { mRefreshOnNofifyMessage = message; }
1975
1982
1983#ifdef SIP_RUN
1984 SIP_PYOBJECT __repr__();
1985 % MethodCode
1986 QString str = u"<QgsMapLayer: '%1' (%2)>"_s.arg( sipCpp->name(), sipCpp->dataProvider() ? sipCpp->dataProvider()->name() : u"Invalid"_s );
1987 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
1988 % End
1989#endif
1990
1997 QgsProject *project() const;
1998
1999 signals:
2000
2008
2010 void statusChanged( const QString &status );
2011
2020 void idChanged( const QString &id );
2021
2026
2036
2047
2064
2071 void repaintRequested( bool deferredUpdate = false );
2072
2075
2078
2080 void blendModeChanged( QPainter::CompositionMode blendMode );
2081
2090 void opacityChanged( double opacity );
2091
2097
2109
2114
2119
2126
2132
2137
2144
2149 void autoRefreshIntervalChanged( int interval );
2150
2157
2165
2174
2181
2188
2194 void customPropertyChanged( const QString &key );
2195
2201
2207
2213
2220
2228
2229 private slots:
2230
2231 void onNotified( const QString &message );
2232
2248 virtual void setDataSourcePrivate( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, Qgis::DataProviderReadFlags flags );
2249
2250 protected:
2251
2256 void clone( QgsMapLayer *layer ) const;
2257
2259 virtual void setExtent( const QgsRectangle &rect );
2260
2265 virtual void setExtent3D( const QgsBox3D &box );
2266
2268 void setValid( bool valid );
2269
2274 virtual bool readXml( const QDomNode &layer_node, QgsReadWriteContext &context );
2275
2280 virtual bool writeXml( QDomNode &layer_node, QDomDocument &document, const QgsReadWriteContext &context ) const;
2281
2293 virtual QString encodedSource( const QString &source, const QgsReadWriteContext &context ) const;
2294
2307 virtual QString decodedSource( const QString &source, const QString &dataProvider, const QgsReadWriteContext &context ) const;
2308
2314 void readCustomProperties( const QDomNode &layerNode, const QString &keyStartsWith = QString() );
2315
2317 void writeCustomProperties( QDomNode &layerNode, QDomDocument &doc ) const;
2318
2320 void readStyleManager( const QDomNode &layerNode );
2322 void writeStyleManager( QDomNode &layerNode, QDomDocument &doc ) const;
2323
2327 void writeCommonStyle( QDomElement &layerElement, QDomDocument &document,
2328 const QgsReadWriteContext &context,
2329 StyleCategories categories = AllStyleCategories ) const;
2330
2334 void readCommonStyle( const QDomElement &layerElement, const QgsReadWriteContext &context,
2335 StyleCategories categories = AllStyleCategories );
2336
2338 void setProviderType( const QString &providerType );
2339
2340#ifndef SIP_RUN
2341#if 0
2343 void connectNotify( const char *signal ) override;
2344#endif
2345#endif
2346
2348 void appendError( const QgsErrorMessage &error ) { mError.append( error );}
2350 void setError( const QgsError &error ) { mError = error;}
2351
2358 void invalidateWgs84Extent();
2359
2361 bool mValid = false;
2362
2365
2367 QString mLayerName;
2368
2371
2373 QSet<QgsMapLayerDependency> mDependencies;
2374
2380 Q_DECL_DEPRECATED bool hasDependencyCycle( const QSet<QgsMapLayerDependency> & ) const {return false;}
2381
2384
2387
2388 //TODO QGIS 5 - move to readXml as a new argument (breaks API)
2389
2392
2399
2405 double mLayerOpacity = 1.0;
2406
2413
2414#ifndef SIP_RUN
2415
2424 QString crsHtmlMetadata() const;
2425#endif
2426
2427#ifndef SIP_RUN
2428
2437 QString generalHtmlMetadata() const;
2438
2447 QString customPropertyHtmlMetadata() const;
2448#endif
2449
2450#ifndef SIP_RUN
2451
2459 std::unique_ptr<QgsDataProvider> mPreloadedProvider;
2460#endif
2461
2462 private:
2463
2464 virtual QString baseURI( PropertyType type ) const;
2465 QString saveNamedProperty( const QString &uri, QgsMapLayer::PropertyType type,
2466 bool &resultFlag, StyleCategories categories = AllStyleCategories );
2467 QString loadNamedProperty( const QString &uri, QgsMapLayer::PropertyType type,
2468 bool &namedPropertyExists, bool &propertySuccessfullyLoaded, StyleCategories categories = AllStyleCategories, Qgis::LoadStyleFlags flags = Qgis::LoadStyleFlags() );
2469 bool loadNamedPropertyFromDatabase( const QString &db, const QString &uri, QString &xml, QgsMapLayer::PropertyType type );
2470
2471 // const method because extents are mutable
2472 void updateExtent( const QgsRectangle &extent ) const;
2473 void updateExtent( const QgsBox3D &extent ) const;
2474
2475 bool rebuildCrs3D( QString *error = nullptr );
2476
2481 virtual bool isReadOnly() const;
2482
2488 QgsCoordinateReferenceSystem mVerticalCrs;
2490
2492 QString mID;
2493
2495 Qgis::LayerType mLayerType;
2496
2498
2500 QPainter::CompositionMode mBlendMode = QPainter::CompositionMode_SourceOver;
2501
2503 QString mTag;
2504
2505 //set some generous defaults for scale based visibility
2506
2508 double mMinScale = 0;
2510 double mMaxScale = 100000000;
2512 bool mScaleBasedVisibility = false;
2513
2517 std::unique_ptr< QgsMapLayerServerProperties > mServerProperties;
2518
2520 QUndoStack *mUndoStack = nullptr;
2521
2522 QUndoStack *mUndoStackStyles = nullptr;
2523
2525 QgsObjectCustomProperties mCustomProperties;
2526
2528 std::unique_ptr<QgsMapLayerLegend> mLegend;
2529
2531 std::unique_ptr<QgsMapLayerStyleManager> mStyleManager;
2532
2534
2536 QTimer *mRefreshTimer = nullptr;
2537
2538 QgsLayerMetadata mMetadata;
2539
2541 std::unique_ptr<QgsAbstract3DRenderer> m3DRenderer;
2542
2544 mutable QgsBox3D mExtent3D;
2545
2547 mutable QgsRectangle mExtent2D;
2548
2550 mutable QgsRectangle mWgs84Extent;
2551
2557 QString mOriginalXmlProperties;
2558
2560 bool mRepaintRequestedFired = false;
2561
2563 QString mLegendPlaceholderImage;
2564
2566 QString mMapTipTemplate;
2567
2569 bool mMapTipsEnabled = true;
2570
2571 friend class QgsVectorLayer;
2572 friend class TestQgsProject;
2573 friend class TestQgsMapLayer;
2574};
2575
2579
2580
2581#ifndef SIP_RUN
2582
2587typedef QPointer< QgsMapLayer > QgsWeakMapLayerPointer;
2588
2593typedef QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList;
2594#endif
2595
2596#endif
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:59
QFlags< DataProviderReadFlag > DataProviderReadFlags
Flags which control data provider construction.
Definition qgis.h:505
LayerType
Types of layers that can be added to a map.
Definition qgis.h:193
@ Group
Composite group layer. Added in QGIS 3.24.
Definition qgis.h:201
@ Plugin
Plugin based layer.
Definition qgis.h:196
@ TiledScene
Tiled scene layer. Added in QGIS 3.34.
Definition qgis.h:202
@ Annotation
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
Definition qgis.h:199
@ Vector
Vector layer.
Definition qgis.h:194
@ VectorTile
Vector tile layer. Added in QGIS 3.14.
Definition qgis.h:198
@ Mesh
Mesh layer. Added in QGIS 3.2.
Definition qgis.h:197
@ Raster
Raster layer.
Definition qgis.h:195
@ PointCloud
Point cloud layer. Added in QGIS 3.18.
Definition qgis.h:200
QFlags< LoadStyleFlag > LoadStyleFlags
Flags for loading layer styles.
Definition qgis.h:249
AutoRefreshMode
Map layer automatic refresh modes.
Definition qgis.h:2353
@ Disabled
Automatic refreshing is disabled.
Definition qgis.h:2354
Base class for all renderers that participate in 3D views.
Interface for classes which can generate elevation profiles.
A 3-dimensional box composed of x, y, z coordinates.
Definition qgsbox3d.h:45
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:35
A container for error messages.
Definition qgserror.h:83
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.
void crs3DChanged()
Emitted when the crs3D() of the layer has changed.
Q_DECL_DEPRECATED void setShortName(const QString &shortName)
Sets the short name of the layer used by QGIS Server to identify the layer.
virtual bool deleteStyleFromDatabase(const QString &styleId, QString &msgError)
Deletes a style from the database.
QString name
Definition qgsmaplayer.h:87
friend class TestQgsMapLayer
void readStyleManager(const QDomNode &layerNode)
Read style manager's configuration (if any). To be called by subclasses.
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.
Q_DECL_DEPRECATED QString legendUrlFormat() const
Returns the format for a URL based layer legend.
QgsRectangle wgs84Extent(bool forceRecalculate=false) const
Returns the WGS84 extent (EPSG:4326) of the layer according to ReadFlag::FlagTrustLayerMetadata.
virtual bool isSpatial() const
Returns true if the layer is considered a spatial layer, ie it has some form of geometry associated w...
QgsAbstract3DRenderer * renderer3D() const
Returns 3D renderer associated with the layer.
virtual bool isTemporary() const
Returns true if the layer is considered a temporary layer.
bool setId(const QString &id)
Sets the layer's id.
void dependenciesChanged()
Emitted when dependencies are changed.
void setError(const QgsError &error)
Sets error message.
bool isInScaleRange(double scale) const
Tests whether the layer should be visible at the specified scale.
void legendChanged()
Signal emitted when legend of the layer has changed.
void writeStyleManager(QDomNode &layerNode, QDomDocument &doc) const
Write style manager's configuration (if exists). To be called by subclasses.
QgsMapLayerLegend * legend() const
Can be nullptr.
QFlags< ReadFlag > ReadFlags
QFlags< LayerFlag > LayerFlags
Q_DECL_DEPRECATED void setAbstract(const QString &abstract)
Sets the abstract of the layer used by QGIS Server in GetCapabilities request.
void editingStopped()
Emitted when edited changes have been successfully written to the data provider.
virtual QgsAbstractProfileSource * profileSource()
Returns the layer's profile source if it has profile capabilities.
void recalculateExtents() const
This is used to send a request that any mapcanvas using this layer update its extents.
void metadataChanged()
Emitted when the layer's metadata is changed.
virtual QgsRectangle extent() const
Returns the extent of the layer.
QString source() const
Returns the source for the layer.
Q_DECL_DEPRECATED 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.
Q_INVOKABLE QVariant customProperty(const QString &value, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.
QgsError mError
Error.
int mBlockStyleChangedSignal
If non-zero, the styleChanged signal should not be emitted.
SaveStyleResult
Results of saving styles to database.
QString providerType() const
Returns the provider type (provider key) for this layer.
virtual void setExtent3D(const QgsBox3D &box)
Sets the extent.
Qgis::AutoRefreshMode autoRefreshMode() const
Returns the layer's automatic refresh mode.
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.
virtual QSet< QgsMapLayerDependency > dependencies() const
Gets the list of dependencies.
void setCustomProperties(const QgsObjectCustomProperties &properties)
Set custom properties for layer.
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...
virtual QString loadNamedStyle(const QString &theURI, bool &resultFlag, bool loadFromLocalDb, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories, Qgis::LoadStyleFlags flags=Qgis::LoadStyleFlags())
Loads a named style from file/local db/datasource db.
virtual QString encodedSource(const QString &source, const QgsReadWriteContext &context) const
Called by writeLayerXML(), used by derived classes to encode provider's specific data source to proje...
void editingStarted()
Emitted when editing on this layer has started.
QgsCoordinateReferenceSystem crs3D
Definition qgsmaplayer.h:92
virtual void setSubLayerVisibility(const QString &name, bool visible)
Set the visibility of the given sublayer name.
void isValidChanged()
Emitted when the validity of this layer changed.
QgsCoordinateReferenceSystem crs
Definition qgsmaplayer.h:90
QString legendPlaceholderImage() const
Returns path to the placeholder image or an empty string if a generated legend is shown.
friend class QgsVectorLayer
virtual bool readXml(const QDomNode &layer_node, QgsReadWriteContext &context)
Called by readLayerXML(), used by children to read state specific to them from project files.
QgsMapLayerServerProperties * serverProperties()
Returns QGIS Server Properties for the map layer.
Q_DECL_DEPRECATED QString attribution() const
Returns the attribution of the layer used by QGIS Server in GetCapabilities request.
void writeCustomProperties(QDomNode &layerNode, QDomDocument &doc) const
Write custom properties to project file.
QString mRefreshOnNofifyMessage
virtual int listStylesInDatabase(QStringList &ids, QStringList &names, QStringList &descriptions, QString &msgError)
Lists all the style in db split into related to the layer and not related to.
void setDataSource(const QString &dataSource, const QString &baseName=QString(), const QString &provider=QString(), bool loadDefaultStyleFlag=false)
Updates the data source of the layer.
QString mLayerName
Name of the layer - used for display.
virtual bool writeXml(QDomNode &layer_node, QDomDocument &document, const QgsReadWriteContext &context) const
Called by writeLayerXML(), used by children to write state specific to them to project files.
void setCustomFlagProperty(const QString &key, const T &value)
Set the value of a property based on a flag.
Q_DECL_DEPRECATED bool hasAutoRefreshEnabled() const
Returns true if auto refresh is enabled for the layer.
void mapTipTemplateChanged()
Emitted when the map tip template changes.
QString crsHtmlMetadata() const
Returns a HTML fragment containing the layer's CRS metadata, for use in the htmlMetadata() method.
Q_DECL_DEPRECATED void setAttributionUrl(const QString &attribUrl)
Sets the attribution URL of the layer used by QGIS Server in GetCapabilities request.
QgsMapLayer::SaveStyleResults saveStyleToDatabaseV2(const QString &name, const QString &description, bool useAsDefault, const QString &uiFileContent, QString &msgError, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories)
Saves QML and SLD representations of the layer's style to a table in the database.
Q_DECL_DEPRECATED void setAutoRefreshEnabled(bool enabled)
Sets whether auto refresh is enabled for the layer.
QgsLayerMetadata metadata
Definition qgsmaplayer.h:89
void renderer3DChanged()
Signal emitted when 3D renderer associated with the layer has changed.
Q_DECL_DEPRECATED QString abstract() const
Returns the abstract of the layer used by QGIS Server in GetCapabilities request.
virtual QgsMapLayerSelectionProperties * selectionProperties()
Returns the layer's selection properties.
QgsMapLayer(Qgis::LayerType type=Qgis::LayerType::Vector, const QString &name=QString(), const QString &source=QString())
Constructor for QgsMapLayer.
Qgis::LayerType type
Definition qgsmaplayer.h:93
Q_DECL_DEPRECATED QString dataUrlFormat() const
Returns the DataUrl format of the layer used by QGIS Server in GetCapabilities request.
QPainter::CompositionMode blendMode() const
Returns the current blending mode for a layer.
void statusChanged(const QString &status)
Emit a signal with status (e.g. to be caught by QgisApp and display a msg on status bar).
Q_DECL_DEPRECATED void setDataUrl(const QString &dataUrl)
Sets the DataUrl of the layer used by QGIS Server in GetCapabilities request.
virtual void setOpacity(double opacity)
Sets the opacity for the layer, where opacity is a value between 0 (totally transparent) and 1....
Q_DECL_DEPRECATED void setKeywordList(const QString &keywords)
Sets the keyword list of the layerused by QGIS Server in GetCapabilities request.
Q_DECL_DEPRECATED void setAttribution(const QString &attrib)
Sets the attribution of the layerused by QGIS Server in GetCapabilities request.
void setFlags(QgsMapLayer::LayerFlags flags)
Returns the flags for this layer.
bool isRefreshOnNotifyEnabled() const
Returns true if the refresh on provider nofification is enabled.
QString publicSource(bool hidePassword=false) const
Gets a version of the internal layer definition that has sensitive bits removed (for example,...
Q_DECL_DEPRECATED QString shortName() const
Returns the short name of the layer used by QGIS Server to identify the layer.
QSet< QgsMapLayerDependency > mDependencies
List of layers that may modify this layer on modification.
void readCustomProperties(const QDomNode &layerNode, const QString &keyStartsWith=QString())
Read custom properties from project file.
virtual Qgis::MapLayerProperties properties() const
Returns the map layer properties of this layer.
virtual void setMetadata(const QgsLayerMetadata &metadata)
Sets the layer's metadata store.
virtual bool readStyle(const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories)
Read the style for the current layer from the DOM node supplied.
virtual bool supportsEditing() const
Returns whether the layer supports editing or not.
Q_DECL_DEPRECATED void setDataUrlFormat(const QString &dataUrlFormat)
Sets the DataUrl format of the layer used by QGIS Server in GetCapabilities request.
QFlags< StyleCategory > StyleCategories
virtual Q_DECL_DEPRECATED void saveStyleToDatabase(const QString &name, const QString &description, bool useAsDefault, const QString &uiFileContent, QString &msgError, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories)
Saves QML and SLD representations of the layer's style to a table in the database.
const QgsMapLayerServerProperties * serverProperties() const
Returns QGIS Server Properties const for the map layer.
Q_INVOKABLE void setCustomProperty(const QString &key, const QVariant &value)
Set a custom property for layer.
QString mProviderKey
Data provider key (name of the data provider).
QgsCoordinateTransformContext transformContext() const
Returns the layer data provider coordinate transform context or a default transform context if the la...
void styleChanged()
Signal emitted whenever a change affects the layer's style.
virtual bool isEditable() const
Returns true if the layer can be edited.
QUndoStack * undoStack()
Returns pointer to layer's undo stack.
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.
Q_DECL_DEPRECATED QString title() const
Returns the title of the layer used by QGIS Server in GetCapabilities request.
void crsChanged()
Emitted when the crs() of the layer has changed.
virtual QgsError error() const
Gets current status error.
bool writeLayerXml(QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context) const
Stores state in DOM node.
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.
Q_DECL_DEPRECATED QString dataUrl() const
Returns the DataUrl of the layer used by QGIS Server in GetCapabilities request.
QgsMapLayer::LayerFlags flags
Definition qgsmaplayer.h:99
bool hasScaleBasedVisibility() const
Returns whether scale based visibility is enabled for the layer.
QgsMapLayerSelectionProperties * selectionProperties
Definition qgsmaplayer.h:98
void setRefreshOnNofifyMessage(const QString &message)
Set the notification message that triggers repaint If refresh on notification is enabled,...
QgsProviderMetadata * providerMetadata() const
Returns the layer data provider's metadata, it may be nullptr.
void opacityChanged(double opacity)
Emitted when the layer's opacity is changed, where opacity is a value between 0 (transparent) and 1 (...
virtual bool isModified() const
Returns true if the layer has been modified since last commit/save.
void styleLoaded(QgsMapLayer::StyleCategories categories)
Emitted when a style has been loaded.
virtual QString getStyleFromDatabase(const QString &styleId, QString &msgError)
Returns the named style corresponding to style id provided.
virtual QgsMapLayerTemporalProperties * temporalProperties()
Returns the layer's temporal properties.
QUndoStack * undoStackStyles()
Returns pointer to layer's style undo stack.
void dataChanged()
Data of layer changed.
virtual QStringList subLayers() const
Returns the sublayers of this layer.
virtual QgsMapLayerRenderer * createMapRenderer(QgsRenderContext &rendererContext)=0
Returns new instance of QgsMapLayerRenderer that will be used for rendering of given context.
virtual QString htmlMetadata() const
Obtain a formatted HTML string containing assorted metadata for this layer.
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.
virtual QgsBox3D extent3D() const
Returns the 3D extent of the layer.
static QString extensionPropertyType(PropertyType type)
Returns the extension of a Property.
virtual QgsMapLayer * clone() const =0
Returns a new instance equivalent to this one except for the id which is still unique.
void blendModeChanged(QPainter::CompositionMode blendMode)
Signal emitted when the blend mode is changed, through QgsMapLayer::setBlendMode().
bool readOnly() const
Returns if this layer is read only.
void setName(const QString &name)
Set the display name of the layer.
void setAutoRefreshInterval(int interval)
Sets the auto refresh interval (in milliseconds) for the layer.
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.
virtual void setExtent(const QgsRectangle &rect)
Sets the extent.
virtual void resolveReferences(QgsProject *project)
Resolve references to other layers (kept as layer IDs after reading XML) into layer objects.
LayerFlag
Flags for the map layer.
@ Identifiable
If the layer is identifiable using the identify map tool and as a WMS layer.
@ Removable
If the layer can be removed from the project. The layer will not be removable from the legend menu en...
@ Searchable
Only for vector-layer, determines if the layer is used in the 'search all layers' locator.
@ Private
Determines if the layer is meant to be exposed to the GUI, i.e. visible in the layer legend tree.
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.
void setAutoRefreshMode(Qgis::AutoRefreshMode mode)
Sets the automatic refresh mode for the layer.
QString refreshOnNotifyMessage() const
Returns the message that should be notified by the provider to triggerRepaint.
virtual bool readSld(const QDomNode &node, QString &errorMessage)
void setMapTipsEnabled(bool enabled)
Enable or disable map tips for this layer.
ReadFlag
Flags which control project read behavior.
@ FlagReadExtentFromXml
Read extent from xml and skip get extent from provider.
@ FlagTrustLayerMetadata
Trust layer metadata. Improves layer load time by skipping expensive checks like primary key unicity,...
@ FlagForceReadOnly
Force open as read only.
@ FlagDontResolveLayers
Don't resolve layer paths or create data providers for layers.
void setValid(bool valid)
Sets whether layer is valid or not.
Q_DECL_DEPRECATED QString attributionUrl() const
Returns the attribution URL of the layer used by QGIS Server in GetCapabilities request.
void readCommonStyle(const QDomElement &layerElement, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories)
Read style data common to all layer types.
void customPropertyChanged(const QString &key)
Emitted when a custom property of the layer has been changed or removed.
QgsMapLayer::ReadFlags mReadFlags
Read flags. It's up to the subclass to respect these when restoring state from XML.
double minimumScale() const
Returns the minimum map scale (i.e.
QgsMapLayerStyleManager * styleManager() const
Gets access to the layer's style manager.
Q_DECL_DEPRECATED 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...
Q_DECL_DEPRECATED 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...
void setMapTipTemplate(const QString &mapTipTemplate)
The mapTip is a pretty, html representation for feature information.
virtual QgsMapLayerElevationProperties * elevationProperties()
Returns the layer's elevation properties.
bool setVerticalCrs(const QgsCoordinateReferenceSystem &crs, QString *errorMessage=nullptr)
Sets the layer's vertical coordinate reference system.
Q_INVOKABLE QStringList customPropertyKeys() const
Returns list of all keys within custom properties.
QgsProject * project() const
Returns the parent project if this map layer is added to a project.
bool mapTipsEnabled
Definition qgsmaplayer.h:97
virtual void setTransformContext(const QgsCoordinateTransformContext &transformContext)=0
Sets the coordinate transform context to transformContext.
bool readLayerXml(const QDomElement &layerElement, QgsReadWriteContext &context, QgsMapLayer::ReadFlags flags=QgsMapLayer::ReadFlags(), QgsDataProvider *preloadedProvider=nullptr)
Sets state from DOM document.
void setLegend(QgsMapLayerLegend *legend)
Assign a legend controller to the map layer.
double opacity
Definition qgsmaplayer.h:95
virtual QString decodedSource(const QString &source, const QString &dataProvider, const QgsReadWriteContext &context) const
Called by readLayerXML(), used by derived classes to decode provider's specific data source from proj...
void nameChanged()
Emitted when the name has been changed.
int autoRefreshInterval
Definition qgsmaplayer.h:88
QgsCoordinateReferenceSystem verticalCrs
Definition qgsmaplayer.h:91
virtual bool writeStyle(QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories) const
Write just the symbology information for the layer into the document.
bool mIsRefreshOnNofifyEnabled
virtual Q_INVOKABLE QgsDataProvider * dataProvider()
Returns the layer's data provider, it may be nullptr.
double mLayerOpacity
Layer opacity.
T customEnumProperty(const QString &key, const T &defaultValue)
Returns the property value for a property based on an enum.
bool mValid
Indicates if the layer is valid and can be drawn.
StyleCategory
Categories of style to distinguish appropriate sections for import/export.
@ GeometryOptions
Geometry validation configuration.
@ AttributeTable
Attribute table settings: choice and order of columns, conditional styling.
@ AllVisualStyleCategories
All categories dealing with map canvas rendering.
@ LayerConfiguration
General configuration: identifiable, removable, searchable, display expression, read-only.
@ Symbology
Symbology.
@ MapTips
Map tips.
@ Notes
Layer user notes.
@ Temporal
Temporal properties.
@ Rendering
Rendering: scale visibility, simplify method, opacity.
@ Relations
Relations.
@ Elevation
Elevation settings.
@ Symbology3D
3D symbology
@ CustomProperties
Custom properties (by plugins for instance).
@ Actions
Actions.
@ Forms
Feature form.
@ Fields
Aliases, widgets, WMS/WFS, expressions, constraints, virtual fields.
@ AllAttributeCategories
All categories dealing with attributes and attribute form.
@ Legend
Legend settings.
@ Diagrams
Diagrams.
@ Labeling
Labeling.
void layerModified()
Emitted when modifications has been done on layer.
virtual Q_INVOKABLE void reload()
Synchronises with changes in the datasource.
virtual QDateTime timestamp() const
Time stamp of data source in the moment when data/metadata were loaded by provider.
void setProviderType(const QString &providerType)
Sets the providerType (provider key).
friend class TestQgsProject
void mapTipsEnabledChanged()
Emitted when map tips are enabled or disabled for the layer.
QFlags< SaveStyleResult > SaveStyleResults
Results of saving styles to database.
void setRenderer3D(QgsAbstract3DRenderer *renderer)
Sets 3D renderer for the layer.
QString customPropertyHtmlMetadata() const
Returns an HTML fragment containing custom property information, for use in the htmlMetadata() method...
const QgsObjectCustomProperties & customProperties() const
Read all custom properties from layer.
QString generalHtmlMetadata() const
Returns an HTML fragment containing general metadata information, for use in the htmlMetadata() metho...
void writeCommonStyle(QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories) const
Write style data common to all layer types.
void setCustomEnumProperty(const QString &key, const T &value)
Set the value of a property based on an enum.
double maximumScale() const
Returns the maximum map scale (i.e.
Q_DECL_DEPRECATED QString keywordList() const
Returns the keyword list of the layer used by QGIS Server in GetCapabilities request.
virtual void setLayerOrder(const QStringList &layers)
Reorders the previously selected sublayers of this layer from bottom to top.
QString mapTipTemplate
Definition qgsmaplayer.h:96
Q_DECL_DEPRECATED void setTitle(const QString &title)
Sets the title of the layer used by QGIS Server in GetCapabilities request.
PropertyType
Maplayer has a style and a metadata property.
bool mShouldValidateCrs
true if the layer's CRS should be validated and invalid CRSes are not permitted.
void setCrs(const QgsCoordinateReferenceSystem &srs, bool emitSignal=true)
Sets layer's spatial reference system.
Simple key-value store (keys = strings, values = variants) that supports loading/saving to/from XML i...
An interface for classes which can visit various object entity (e.g.
A QgsObjectEntityVisitorInterface context object.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:112
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.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition qgis_sip.h:199
#define SIP_DEPRECATED
Definition qgis_sip.h:114
#define SIP_ENUM_BASETYPE(type)
Definition qgis_sip.h:275
#define SIP_SKIP
Definition qgis_sip.h:134
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_OUT
Definition qgis_sip.h:58
#define SIP_FACTORY
Definition qgis_sip.h:84
#define SIP_END
Definition qgis_sip.h:216
#define QgsDebugError(str)
Definition qgslogger.h:59
QPointer< QgsMapLayer > QgsWeakMapLayerPointer
Weak pointer for QgsMapLayer.
QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList
A list of weak pointers to QgsMapLayers.
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsProjectionSelectionWidget::CrsOptions)
Setting options for creating vector data providers.