QGIS API Documentation 4.3.0-Master (0cfde48c85b)
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
203 Q_ENUM( StyleCategory )
204 Q_DECLARE_FLAGS( StyleCategories, StyleCategory )
205 Q_FLAG( StyleCategories )
206
213 QgsMapLayer( Qgis::LayerType type = Qgis::LayerType::Vector, const QString &name = QString(), const QString &source = QString() );
214
215 ~QgsMapLayer() override;
216
217 QgsMapLayer( const QgsMapLayer & ) = delete;
218 QgsMapLayer &operator=( const QgsMapLayer & ) = delete;
219
225 virtual QgsMapLayer *clone() const = 0;
226
230 Qgis::LayerType type() const;
231
243
255
265 virtual Qgis::MapLayerProperties properties() const;
266
271 static QString extensionPropertyType( PropertyType type );
272
279 QString id() const;
280
296 bool setId( const QString &id );
297
302 void setName( const QString &name );
303
308 QString name() const;
309
313 Q_INVOKABLE virtual QgsDataProvider *dataProvider();
314
319 virtual const QgsDataProvider *dataProvider() const SIP_SKIP;
320
326
332 Q_DECL_DEPRECATED void setShortName( const QString &shortName ) SIP_DEPRECATED;
333
339 Q_DECL_DEPRECATED QString shortName() const SIP_DEPRECATED;
340
346 Q_DECL_DEPRECATED void setTitle( const QString &title ) SIP_DEPRECATED;
347
353 Q_DECL_DEPRECATED QString title() const SIP_DEPRECATED;
354
360 Q_DECL_DEPRECATED void setAbstract( const QString &abstract ) SIP_DEPRECATED;
361
367 Q_DECL_DEPRECATED QString abstract() const SIP_DEPRECATED;
368
374 Q_DECL_DEPRECATED void setKeywordList( const QString &keywords ) SIP_DEPRECATED;
375
381 Q_DECL_DEPRECATED QString keywordList() const SIP_DEPRECATED;
382
388 Q_DECL_DEPRECATED void setDataUrl( const QString &dataUrl ) SIP_DEPRECATED;
389
395 Q_DECL_DEPRECATED QString dataUrl() const SIP_DEPRECATED;
396
402 Q_DECL_DEPRECATED void setDataUrlFormat( const QString &dataUrlFormat ) SIP_DEPRECATED;
403
409 Q_DECL_DEPRECATED QString dataUrlFormat() const SIP_DEPRECATED;
410
416 Q_DECL_DEPRECATED void setAttribution( const QString &attrib ) SIP_DEPRECATED;
417
423 Q_DECL_DEPRECATED QString attribution() const SIP_DEPRECATED;
424
430 Q_DECL_DEPRECATED void setAttributionUrl( const QString &attribUrl ) SIP_DEPRECATED;
431
437 Q_DECL_DEPRECATED QString attributionUrl() const SIP_DEPRECATED;
438
439 /* Layer metadataUrl information */
440
445 QgsMapLayerServerProperties *serverProperties() SIP_DISALLOWNONE { return mServerProperties.get(); };
446
451 const QgsMapLayerServerProperties *serverProperties() const { return mServerProperties.get(); }
452 SIP_SKIP;
453
462 Q_DECL_DEPRECATED void setMetadataUrl( const QString &metaUrl ) SIP_DEPRECATED;
463
473 Q_DECL_DEPRECATED QString metadataUrl() const SIP_DEPRECATED;
474
483 Q_DECL_DEPRECATED void setMetadataUrlType( const QString &metaUrlType ) SIP_DEPRECATED;
484
494 Q_DECL_DEPRECATED QString metadataUrlType() const SIP_DEPRECATED;
495
504 Q_DECL_DEPRECATED void setMetadataUrlFormat( const QString &metaUrlFormat ) SIP_DEPRECATED;
505
515 Q_DECL_DEPRECATED QString metadataUrlFormat() const SIP_DEPRECATED;
516
522 void setBlendMode( QPainter::CompositionMode blendMode );
523
528 QPainter::CompositionMode blendMode() const;
529
538 virtual void setOpacity( double opacity );
539
548 virtual double opacity() const;
549
551 bool readOnly() const { return isReadOnly(); }
552
556 Q_INVOKABLE virtual void reload() {}
557
562
564 Q_INVOKABLE virtual QgsRectangle extent() const;
565
570 virtual QgsBox3D extent3D() const;
571
580 Q_INVOKABLE QgsRectangle wgs84Extent( bool forceRecalculate = false ) const;
581
587 bool isValid() const;
588
589 // TODO QGIS 5.0: consider changing bool hidePassword to an enumeration: HIDE_CREDENTIALS / REDACT_CREDENTIALS
590 // to avoid the ambiguity of the double negation (hide = false)
591
599 QString publicSource( bool hidePassword = false ) const;
600
606 QString source() const;
607
612 virtual QStringList subLayers() const;
613
618 virtual void setLayerOrder( const QStringList &layers );
619
625 virtual void setSubLayerVisibility( const QString &name, bool visible );
626
633 virtual bool supportsEditing() const;
634
636 virtual bool isEditable() const;
637
643 virtual bool isModified() const;
644
648 virtual bool isSpatial() const;
649
659 virtual bool isTemporary() const;
660
673 Q_DECLARE_FLAGS( ReadFlags, ReadFlag )
674
675
692 bool readLayerXml( const QDomElement &layerElement, QgsReadWriteContext &context, QgsMapLayer::ReadFlags flags = QgsMapLayer::ReadFlags(), QgsDataProvider *preloadedProvider SIP_TRANSFER = nullptr );
693
709 bool writeLayerXml( QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context ) const;
710
714 virtual void resolveReferences( QgsProject *project );
715
720 Q_INVOKABLE QStringList customPropertyKeys() const;
721
727 Q_INVOKABLE void setCustomProperty( const QString &key, const QVariant &value );
728
733 Q_INVOKABLE QVariant customProperty( const QString &value, const QVariant &defaultValue = QVariant() ) const;
734
739
746
756 virtual int listStylesInDatabase( QStringList &ids SIP_OUT, QStringList &names SIP_OUT, QStringList &descriptions SIP_OUT, QString &msgError SIP_OUT );
757
761 virtual QString getStyleFromDatabase( const QString &styleId, QString &msgError SIP_OUT );
762
769 virtual bool deleteStyleFromDatabase( const QString &styleId, QString &msgError SIP_OUT );
770
776 enum class SaveStyleResult SIP_ENUM_BASETYPE( IntFlag )
777 {
778 Success = 0,
779 QmlGenerationFailed = 1 << 0,
780 SldGenerationFailed = 1 << 1,
781 DatabaseWriteFailed = 1 << 2,
782 };
783 Q_ENUM( SaveStyleResult )
784
785
791 Q_FLAG( SaveStyleResults )
792
810 Q_DECL_DEPRECATED virtual void saveStyleToDatabase(
811 const QString &name, const QString &description, bool useAsDefault, const QString &uiFileContent, QString &msgError SIP_OUT, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories
813
828 const QString &name, const QString &description, bool useAsDefault, const QString &uiFileContent, QString &msgError SIP_OUT, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories
829 );
830
831 // 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".
832 // 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.
833
844 virtual QString loadNamedStyle(
845 const QString &theURI, bool &resultFlag SIP_OUT, bool loadFromLocalDb, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories, Qgis::LoadStyleFlags flags = Qgis::LoadStyleFlags()
846 );
847
848#ifndef SIP_RUN
849
860 template<class T> T customEnumProperty( const QString &key, const T &defaultValue )
861 {
862 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
863 Q_ASSERT( metaEnum.isValid() );
864 if ( !metaEnum.isValid() )
865 {
866 QgsDebugError( u"Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration."_s );
867 }
868
869 T v;
870 bool ok = false;
871
872 if ( metaEnum.isValid() )
873 {
874 // read as string
875 QByteArray ba = customProperty( key, metaEnum.valueToKey( static_cast<int>( defaultValue ) ) ).toString().toUtf8();
876 const char *vs = ba.data();
877 v = static_cast<T>( metaEnum.keyToValue( vs, &ok ) );
878 if ( ok )
879 return v;
880 }
881
882 // if failed, try to read as int (old behavior)
883 // this code shall be removed later
884 // then the method could be marked as const
885 v = static_cast<T>( customProperty( key, static_cast<int>( defaultValue ) ).toInt( &ok ) );
886 if ( metaEnum.isValid() )
887 {
888 if ( !ok || !metaEnum.valueToKey( static_cast<int>( v ) ) )
889 {
890 v = defaultValue;
891 }
892 else
893 {
894 // found property as an integer
895 // convert the property to the new form (string)
896 setCustomEnumProperty( key, v );
897 }
898 }
899
900 return v;
901 }
902
911 template<class T> void setCustomEnumProperty( const QString &key, const T &value )
912 {
913 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
914 Q_ASSERT( metaEnum.isValid() );
915 if ( metaEnum.isValid() )
916 {
917 setCustomProperty( key, metaEnum.valueToKey( static_cast<int>( value ) ) );
918 }
919 else
920 {
921 QgsDebugError( u"Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration."_s );
922 }
923 }
924
936 template<class T> T customFlagProperty( const QString &key, const T &defaultValue )
937 {
938 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
939 Q_ASSERT( metaEnum.isValid() );
940 if ( !metaEnum.isValid() )
941 {
942 QgsDebugError( u"Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration."_s );
943 }
944
945 T v = defaultValue;
946 bool ok = false;
947
948 if ( metaEnum.isValid() )
949 {
950 // read as string
951 QByteArray ba = customProperty( key, metaEnum.valueToKeys( defaultValue ) ).toString().toUtf8();
952 const char *vs = ba.data();
953 v = static_cast<T>( metaEnum.keysToValue( vs, &ok ) );
954 }
955 if ( !ok )
956 {
957 // if failed, try to read as int
958 const int intValue = customProperty( key, static_cast<int>( defaultValue ) ).toInt( &ok );
959 if ( metaEnum.isValid() )
960 {
961 if ( ok )
962 {
963 // check that the int value does correspond to a flag
964 // see https://stackoverflow.com/a/68495949/1548052
965 const QByteArray keys = metaEnum.valueToKeys( intValue );
966 const int intValueCheck = metaEnum.keysToValue( keys );
967 if ( intValue != intValueCheck )
968 {
969 v = defaultValue;
970 }
971 else
972 {
973 // found property as an integer
974 v = T( intValue );
975 // convert the property to the new form (string)
976 // this code could be removed
977 // then the method could be marked as const
978 setCustomFlagProperty( key, v );
979 }
980 }
981 else
982 {
983 v = defaultValue;
984 }
985 }
986 }
987
988 return v;
989 }
990
999 template<class T> void setCustomFlagProperty( const QString &key, const T &value )
1000 {
1001 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
1002 Q_ASSERT( metaEnum.isValid() );
1003 if ( metaEnum.isValid() )
1004 {
1005 setCustomProperty( key, metaEnum.valueToKeys( value ) );
1006 }
1007 else
1008 {
1009 QgsDebugError( u"Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration."_s );
1010 }
1011 }
1012#endif
1013
1014
1019 void removeCustomProperty( const QString &key );
1020
1026 virtual QgsError error() const;
1027
1039 QgsCoordinateReferenceSystem crs() const;
1040
1059 QgsCoordinateReferenceSystem verticalCrs() const;
1060
1079 QgsCoordinateReferenceSystem crs3D() const;
1080
1091 void setCrs( const QgsCoordinateReferenceSystem &srs, bool emitSignal = true );
1092
1112 bool setVerticalCrs( const QgsCoordinateReferenceSystem &crs, QString *errorMessage SIP_OUT = nullptr );
1113
1119 QgsCoordinateTransformContext transformContext() const;
1120
1121
1126 static QString formatLayerName( const QString &name );
1127
1134 virtual QString metadataUri() const;
1135
1141 void exportNamedMetadata( QDomDocument &doc, QString &errorMsg ) const;
1142
1151 virtual QString saveDefaultMetadata( bool &resultFlag SIP_OUT );
1152
1166 QString saveNamedMetadata( const QString &uri, bool &resultFlag SIP_OUT );
1167
1168 // 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".
1169 // 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.
1170
1184 virtual QString loadNamedMetadata( const QString &uri, bool &resultFlag SIP_OUT );
1185
1186 // 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".
1187 // 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.
1188
1197 virtual QString loadDefaultMetadata( bool &resultFlag SIP_OUT );
1198
1206 bool loadNamedMetadataFromDatabase( const QString &db, const QString &uri, QString &qmd );
1207
1214 bool importNamedMetadata( QDomDocument &document, QString &errorMessage );
1215
1224 virtual QString styleURI() const;
1225
1226 // 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".
1227 // 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.
1228
1238 virtual QString loadDefaultStyle( bool &resultFlag SIP_OUT );
1239
1240 // 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".
1241 // 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.
1242
1259 virtual QString loadNamedStyle(
1260 const QString &uri, bool &resultFlag SIP_OUT, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories, Qgis::LoadStyleFlags flags = Qgis::LoadStyleFlags()
1261 );
1262
1270 virtual bool loadNamedStyleFromDatabase( const QString &db, const QString &uri, QString &qml SIP_OUT );
1271
1280 virtual bool importNamedStyle( QDomDocument &doc, QString &errorMsg SIP_OUT, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories );
1281
1290 virtual void exportNamedStyle(
1291 QDomDocument &doc, QString &errorMsg SIP_OUT, const QgsReadWriteContext &context = QgsReadWriteContext(), QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories
1292 ) const;
1293
1294
1302 Q_DECL_DEPRECATED virtual void exportSldStyle( QDomDocument &doc, QString &errorMsg ) const SIP_DEPRECATED;
1303
1311 Q_DECL_DEPRECATED virtual void exportSldStyleV2( QDomDocument &doc, QString &errorMsg, QgsSldExportContext &exportContext ) const SIP_DEPRECATED;
1312
1322 virtual QDomDocument exportSldStyleV3( QgsSldExportContext &exportContext ) const;
1323
1335 virtual QString saveDefaultStyle( bool &resultFlag SIP_OUT, StyleCategories categories );
1336
1348 Q_DECL_DEPRECATED virtual QString saveDefaultStyle( bool &resultFlag SIP_OUT ) SIP_DEPRECATED;
1349
1365 virtual QString saveNamedStyle( const QString &uri, bool &resultFlag SIP_OUT, StyleCategories categories = AllStyleCategories );
1366
1376 virtual QString saveSldStyle( const QString &uri, bool &resultFlag SIP_OUT ) const;
1377
1388 virtual QString saveSldStyleV2( bool &resultFlag SIP_OUT, QgsSldExportContext &exportContext ) const;
1389
1398 virtual QString loadSldStyle( const QString &uri, bool &resultFlag SIP_OUT );
1399
1400 virtual bool readSld( const QDomNode &node, QString &errorMessage )
1401 {
1402 Q_UNUSED( node )
1403 errorMessage = u"Layer type %1 not supported"_s.arg( static_cast<int>( type() ) );
1404 return false;
1405 }
1406
1407
1416 virtual bool readSymbology( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories ) = 0;
1417
1427 virtual bool readStyle( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories );
1428
1439 virtual bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories ) const = 0;
1440
1452 virtual bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories ) const;
1453
1454
1485 void setDataSource( const QString &dataSource, const QString &baseName = QString(), const QString &provider = QString(), bool loadDefaultStyleFlag = false );
1486
1516 void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, bool loadDefaultStyleFlag = false );
1517
1547 void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, Qgis::DataProviderReadFlags flags );
1548
1552 QString providerType() const;
1553
1555 QUndoStack *undoStack() SIP_DISALLOWNONE;
1556
1560 QUndoStack *undoStackStyles() SIP_DISALLOWNONE;
1561
1567 Q_DECL_DEPRECATED void setLegendUrl( const QString &legendUrl ) SIP_DEPRECATED;
1568
1574 Q_DECL_DEPRECATED QString legendUrl() const SIP_DEPRECATED;
1575
1581 Q_DECL_DEPRECATED void setLegendUrlFormat( const QString &legendUrlFormat ) SIP_DEPRECATED;
1582
1588 Q_DECL_DEPRECATED QString legendUrlFormat() const SIP_DEPRECATED;
1589
1595
1599 QgsMapLayerLegend *legend() const;
1600
1605
1610
1615
1624 bool isInScaleRange( double scale ) const;
1625
1636 double minimumScale() const;
1637
1648 double maximumScale() const;
1649
1658 bool hasScaleBasedVisibility() const;
1659
1666 Q_DECL_DEPRECATED bool hasAutoRefreshEnabled() const SIP_DEPRECATED;
1667
1674 Qgis::AutoRefreshMode autoRefreshMode() const;
1675
1682 int autoRefreshInterval() const;
1683
1694 void setAutoRefreshInterval( int interval );
1695
1702 Q_DECL_DEPRECATED void setAutoRefreshEnabled( bool enabled ) SIP_DEPRECATED;
1703
1710 void setAutoRefreshMode( Qgis::AutoRefreshMode mode );
1711
1717 virtual const QgsLayerMetadata &metadata() const;
1718
1724 virtual void setMetadata( const QgsLayerMetadata &metadata );
1725
1729 virtual QString htmlMetadata() const;
1730
1732 virtual QDateTime timestamp() const;
1733
1740 virtual QSet<QgsMapLayerDependency> dependencies() const;
1741
1747
1753
1762 QString originalXmlProperties() const;
1763
1771 void setOriginalXmlProperties( const QString &originalXmlProperties );
1772
1780 static QString generateId( const QString &layerName );
1781
1791 virtual bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
1792
1802 virtual bool accept( QgsObjectEntityVisitorInterface *visitor, const QgsObjectVisitorContext &context ) const;
1803
1810
1817
1824
1825
1831 virtual QgsAbstractProfileSource *profileSource() { return nullptr; }
1832
1838 QString legendPlaceholderImage() const { return mLegendPlaceholderImage; }
1839
1845 void setLegendPlaceholderImage( const QString &imgPath ) { mLegendPlaceholderImage = imgPath; }
1846
1853 virtual bool hasMapTips() const;
1854
1862 QString mapTipTemplate() const;
1863
1871 void setMapTipTemplate( const QString &mapTipTemplate );
1872
1879 void setMapTipsEnabled( bool enabled );
1880
1885 bool mapTipsEnabled() const;
1886
1894 static Qgis::DataProviderReadFlags providerReadFlags( const QDomNode &layerNode, QgsMapLayer::ReadFlags layerReadFlags );
1895
1896 public slots:
1897
1907 void setMinimumScale( double scale );
1908
1918 void setMaximumScale( double scale );
1919
1927 void setScaleBasedVisibility( bool enabled );
1928
1937 void triggerRepaint( bool deferredUpdate = false );
1938
1945 void trigger3DUpdate();
1946
1950 void emitStyleChanged();
1951
1959 virtual bool setDependencies( const QSet<QgsMapLayerDependency> &layers );
1960
1965 void setRefreshOnNotifyEnabled( bool enabled );
1966
1973 void setRefreshOnNofifyMessage( const QString &message ) { mRefreshOnNofifyMessage = message; }
1974
1981
1982#ifdef SIP_RUN
1983 // clang-format off
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// clang-format on
1990#endif
1991
1998 QgsProject *project() const;
1999
2000 signals:
2001
2009
2011 void statusChanged( const QString &status );
2012
2021 void idChanged( const QString &id );
2022
2027
2037
2048
2065
2072 void repaintRequested( bool deferredUpdate = false );
2073
2076
2079
2081 void blendModeChanged( QPainter::CompositionMode blendMode );
2082
2091 void opacityChanged( double opacity );
2092
2098
2110
2115
2120
2127
2133
2138
2145
2150 void autoRefreshIntervalChanged( int interval );
2151
2158
2166
2175
2182
2189
2195 void customPropertyChanged( const QString &key );
2196
2202
2208
2214
2221
2229
2230 private slots:
2231
2232 void onNotified( const QString &message );
2233
2249 virtual void setDataSourcePrivate( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, Qgis::DataProviderReadFlags flags );
2250
2251 protected:
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, const QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories ) const;
2328
2332 void readCommonStyle( const QDomElement &layerElement, const QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories );
2333
2335 void setProviderType( const QString &providerType );
2336
2337#ifndef SIP_RUN
2338#if 0
2340 void connectNotify( const char *signal ) override;
2341#endif
2342#endif
2343
2345 void appendError( const QgsErrorMessage &error ) { mError.append( error ); }
2347 void setError( const QgsError &error ) { mError = error; }
2348
2355 void invalidateWgs84Extent();
2356
2358 bool mValid = false;
2359
2362
2364 QString mLayerName;
2365
2368
2370 QSet<QgsMapLayerDependency> mDependencies;
2371
2377 Q_DECL_DEPRECATED bool hasDependencyCycle( const QSet<QgsMapLayerDependency> & ) const { return false; }
2378
2381
2384
2385 //TODO QGIS 5 - move to readXml as a new argument (breaks API)
2386
2389
2396
2402 double mLayerOpacity = 1.0;
2403
2410
2411#ifndef SIP_RUN
2412
2421 QString crsHtmlMetadata() const;
2422#endif
2423
2424#ifndef SIP_RUN
2425
2434 QString generalHtmlMetadata() const;
2435
2444 QString customPropertyHtmlMetadata() const;
2445#endif
2446
2447#ifndef SIP_RUN
2448
2456 std::unique_ptr<QgsDataProvider> mPreloadedProvider;
2457#endif
2458
2459 private:
2460 virtual QString baseURI( PropertyType type ) const;
2461 QString saveNamedProperty( const QString &uri, QgsMapLayer::PropertyType type, bool &resultFlag, StyleCategories categories = AllStyleCategories );
2462 QString loadNamedProperty(
2463 const QString &uri,
2465 bool &namedPropertyExists,
2466 bool &propertySuccessfullyLoaded,
2469 );
2470 bool loadNamedPropertyFromDatabase( const QString &db, const QString &uri, QString &xml, QgsMapLayer::PropertyType type );
2471
2472 // const method because extents are mutable
2473 void updateExtent( const QgsRectangle &extent ) const;
2474 void updateExtent( const QgsBox3D &extent ) const;
2475
2476 bool rebuildCrs3D( QString *error = nullptr );
2477
2482 virtual bool isReadOnly() const;
2483
2489 QgsCoordinateReferenceSystem mVerticalCrs;
2491
2493 QString mID;
2494
2496 Qgis::LayerType mLayerType;
2497
2499
2501 QPainter::CompositionMode mBlendMode = QPainter::CompositionMode_SourceOver;
2502
2504 QString mTag;
2505
2506 //set some generous defaults for scale based visibility
2507
2509 double mMinScale = 0;
2511 double mMaxScale = 100000000;
2513 bool mScaleBasedVisibility = false;
2514
2518 std::unique_ptr< QgsMapLayerServerProperties > mServerProperties;
2519
2521 QUndoStack *mUndoStack = nullptr;
2522
2523 QUndoStack *mUndoStackStyles = nullptr;
2524
2526 QgsObjectCustomProperties mCustomProperties;
2527
2529 std::unique_ptr<QgsMapLayerLegend> mLegend;
2530
2532 std::unique_ptr<QgsMapLayerStyleManager> mStyleManager;
2533
2535
2537 QTimer *mRefreshTimer = nullptr;
2538
2539 QgsLayerMetadata mMetadata;
2540
2542 std::unique_ptr<QgsAbstract3DRenderer> m3DRenderer;
2543
2545 mutable QgsBox3D mExtent3D;
2546
2548 mutable QgsRectangle mExtent2D;
2549
2551 mutable QgsRectangle mWgs84Extent;
2552
2558 QString mOriginalXmlProperties;
2559
2561 bool mRepaintRequestedFired = false;
2562
2564 QString mLegendPlaceholderImage;
2565
2567 QString mMapTipTemplate;
2568
2570 bool mMapTipsEnabled = true;
2571
2572 friend class QgsVectorLayer;
2573 friend class TestQgsProject;
2574 friend class TestQgsMapLayer;
2575};
2576
2580
2581
2582#ifndef SIP_RUN
2583
2588typedef QPointer< QgsMapLayer > QgsWeakMapLayerPointer;
2589
2594typedef QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList;
2595#endif
2596
2597#endif
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:62
QFlags< DataProviderReadFlag > DataProviderReadFlags
Flags which control data provider construction.
Definition qgis.h:532
LayerType
Types of layers that can be added to a map.
Definition qgis.h:206
@ Group
Composite group layer. Added in QGIS 3.24.
Definition qgis.h:214
@ Plugin
Plugin based layer.
Definition qgis.h:209
@ TiledScene
Tiled scene layer. Added in QGIS 3.34.
Definition qgis.h:215
@ Annotation
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
Definition qgis.h:212
@ Vector
Vector layer.
Definition qgis.h:207
@ VectorTile
Vector tile layer. Added in QGIS 3.14.
Definition qgis.h:211
@ Mesh
Mesh layer. Added in QGIS 3.2.
Definition qgis.h:210
@ Raster
Raster layer.
Definition qgis.h:208
@ PointCloud
Point cloud layer. Added in QGIS 3.18.
Definition qgis.h:213
QFlags< LoadStyleFlag > LoadStyleFlags
Flags for loading layer styles.
Definition qgis.h:283
AutoRefreshMode
Map layer automatic refresh modes.
Definition qgis.h:2481
@ Disabled
Automatic refreshing is disabled.
Definition qgis.h:2482
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.
Q_INVOKABLE 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 Q_INVOKABLE 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:114
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:203
#define SIP_DEPRECATED
Definition qgis_sip.h:113
#define SIP_DISALLOWNONE
Definition qgis_sip.h:133
#define SIP_ENUM_BASETYPE(type)
Definition qgis_sip.h:277
#define SIP_SKIP
Definition qgis_sip.h:138
#define SIP_TRANSFER
Definition qgis_sip.h:35
#define SIP_OUT
Definition qgis_sip.h:57
#define SIP_FACTORY
Definition qgis_sip.h:83
#define SIP_END
Definition qgis_sip.h:220
#define QgsDebugError(str)
Definition qgslogger.h:71
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.