QGIS API Documentation 4.3.0-Master (375ff838570)
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;
64
65class QDomDocument;
66class QKeyEvent;
67class QPainter;
69class QgsBox3D;
70
71/*
72 * Constants used to describe copy-paste MIME types
73 */
74#define QGSCLIPBOARD_MAPLAYER_MIME "application/qgis.maplayer"
75
76
83class CORE_EXPORT QgsMapLayer : public QObject
84{
85 Q_OBJECT
86
87 Q_PROPERTY( QString id READ id WRITE setId NOTIFY idChanged )
88 Q_PROPERTY( QString name READ name WRITE setName NOTIFY nameChanged )
91 Q_PROPERTY( QgsCoordinateReferenceSystem crs READ crs WRITE setCrs NOTIFY crsChanged )
94 Q_PROPERTY( Qgis::LayerType type READ type CONSTANT )
95 Q_PROPERTY( bool isValid READ isValid NOTIFY isValidChanged )
96 Q_PROPERTY( double opacity READ opacity WRITE setOpacity NOTIFY opacityChanged )
100 Q_PROPERTY( QgsMapLayer::LayerFlags flags READ flags WRITE setFlags NOTIFY flagsChanged )
101
102#ifdef SIP_RUN
104 QgsMapLayer *layer = qobject_cast<QgsMapLayer *>( sipCpp );
105
106 sipType = 0;
107
108 if ( layer )
109 {
110 switch ( layer->type() )
111 {
113 sipType = sipType_QgsVectorLayer;
114 break;
116 sipType = sipType_QgsRasterLayer;
117 break;
119 sipType = sipType_QgsPluginLayer;
120 break;
122 sipType = sipType_QgsMeshLayer;
123 break;
125 sipType = sipType_QgsVectorTileLayer;
126 break;
128 sipType = sipType_QgsAnnotationLayer;
129 break;
131 sipType = sipType_QgsPointCloudLayer;
132 break;
134 sipType = sipType_QgsGroupLayer;
135 break;
137 sipType = sipType_QgsTiledSceneLayer;
138 break;
139 default:
140 sipType = nullptr;
141 break;
142 }
143 }
144 SIP_END
145#endif
146
147 public:
148
153 {
154 Style = 0,
156 };
157
164 {
165 Identifiable = 1 << 0,
166 Removable = 1 << 1,
167 Searchable = 1 << 2,
168 Private = 1 << 3,
169 };
170 Q_ENUM( LayerFlag )
171 Q_DECLARE_FLAGS( LayerFlags, LayerFlag )
172 Q_FLAG( LayerFlags )
173
204 Q_ENUM( StyleCategory )
205 Q_DECLARE_FLAGS( StyleCategories, StyleCategory )
206 Q_FLAG( StyleCategories )
207
214 QgsMapLayer( Qgis::LayerType type = Qgis::LayerType::Vector, const QString &name = QString(), const QString &source = QString() );
215
216 ~QgsMapLayer() override;
217
218 QgsMapLayer( const QgsMapLayer & ) = delete;
219 QgsMapLayer &operator=( const QgsMapLayer & ) = delete;
220
226 virtual QgsMapLayer *clone() const = 0;
227
231 Qgis::LayerType type() const;
232
244
256
266 virtual Qgis::MapLayerProperties properties() const;
267
272 static QString extensionPropertyType( PropertyType type );
273
280 QString id() const;
281
297 bool setId( const QString &id );
298
303 void setName( const QString &name );
304
309 QString name() const;
310
314 Q_INVOKABLE virtual QgsDataProvider *dataProvider();
315
320 virtual const QgsDataProvider *dataProvider() const SIP_SKIP;
321
327
333 Q_DECL_DEPRECATED void setShortName( const QString &shortName ) SIP_DEPRECATED;
334
340 Q_DECL_DEPRECATED QString shortName() const SIP_DEPRECATED;
341
347 Q_DECL_DEPRECATED void setTitle( const QString &title ) SIP_DEPRECATED;
348
354 Q_DECL_DEPRECATED QString title() const SIP_DEPRECATED;
355
361 Q_DECL_DEPRECATED void setAbstract( const QString &abstract ) SIP_DEPRECATED;
362
368 Q_DECL_DEPRECATED QString abstract() const SIP_DEPRECATED;
369
375 Q_DECL_DEPRECATED void setKeywordList( const QString &keywords ) SIP_DEPRECATED;
376
382 Q_DECL_DEPRECATED QString keywordList() const SIP_DEPRECATED;
383
389 Q_DECL_DEPRECATED void setDataUrl( const QString &dataUrl ) SIP_DEPRECATED;
390
396 Q_DECL_DEPRECATED QString dataUrl() const SIP_DEPRECATED;
397
403 Q_DECL_DEPRECATED void setDataUrlFormat( const QString &dataUrlFormat ) SIP_DEPRECATED;
404
410 Q_DECL_DEPRECATED QString dataUrlFormat() const SIP_DEPRECATED;
411
417 Q_DECL_DEPRECATED void setAttribution( const QString &attrib ) SIP_DEPRECATED;
418
424 Q_DECL_DEPRECATED QString attribution() const SIP_DEPRECATED;
425
431 Q_DECL_DEPRECATED void setAttributionUrl( const QString &attribUrl ) SIP_DEPRECATED;
432
438 Q_DECL_DEPRECATED QString attributionUrl() const SIP_DEPRECATED;
439
440 /* Layer metadataUrl information */
441
446 QgsMapLayerServerProperties *serverProperties() SIP_DISALLOWNONE { return mServerProperties.get(); };
447
452 const QgsMapLayerServerProperties *serverProperties() const { return mServerProperties.get(); }
453 SIP_SKIP;
454
463 Q_DECL_DEPRECATED void setMetadataUrl( const QString &metaUrl ) SIP_DEPRECATED;
464
474 Q_DECL_DEPRECATED QString metadataUrl() const SIP_DEPRECATED;
475
484 Q_DECL_DEPRECATED void setMetadataUrlType( const QString &metaUrlType ) SIP_DEPRECATED;
485
495 Q_DECL_DEPRECATED QString metadataUrlType() const SIP_DEPRECATED;
496
505 Q_DECL_DEPRECATED void setMetadataUrlFormat( const QString &metaUrlFormat ) SIP_DEPRECATED;
506
516 Q_DECL_DEPRECATED QString metadataUrlFormat() const SIP_DEPRECATED;
517
523 void setBlendMode( QPainter::CompositionMode blendMode );
524
529 QPainter::CompositionMode blendMode() const;
530
539 virtual void setOpacity( double opacity );
540
549 virtual double opacity() const;
550
552 bool readOnly() const { return isReadOnly(); }
553
557 Q_INVOKABLE virtual void reload() {}
558
563
565 Q_INVOKABLE virtual QgsRectangle extent() const;
566
571 virtual QgsBox3D extent3D() const;
572
581 Q_INVOKABLE QgsRectangle wgs84Extent( bool forceRecalculate = false ) const;
582
588 bool isValid() const;
589
590 // TODO QGIS 5.0: consider changing bool hidePassword to an enumeration: HIDE_CREDENTIALS / REDACT_CREDENTIALS
591 // to avoid the ambiguity of the double negation (hide = false)
592
600 QString publicSource( bool hidePassword = false ) const;
601
607 QString source() const;
608
613 virtual QStringList subLayers() const;
614
619 virtual void setLayerOrder( const QStringList &layers );
620
626 virtual void setSubLayerVisibility( const QString &name, bool visible );
627
634 virtual bool supportsEditing() const;
635
637 virtual bool isEditable() const;
638
644 virtual bool isModified() const;
645
649 virtual bool isSpatial() const;
650
660 virtual bool isTemporary() const;
661
674 Q_DECLARE_FLAGS( ReadFlags, ReadFlag )
675
676
693 bool readLayerXml( const QDomElement &layerElement, QgsReadWriteContext &context, QgsMapLayer::ReadFlags flags = QgsMapLayer::ReadFlags(), QgsDataProvider *preloadedProvider SIP_TRANSFER = nullptr );
694
710 bool writeLayerXml( QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context ) const;
711
715 virtual void resolveReferences( QgsProject *project );
716
721 Q_INVOKABLE QStringList customPropertyKeys() const;
722
728 Q_INVOKABLE void setCustomProperty( const QString &key, const QVariant &value );
729
734 Q_INVOKABLE QVariant customProperty( const QString &value, const QVariant &defaultValue = QVariant() ) const;
735
740
747
757 virtual int listStylesInDatabase( QStringList &ids SIP_OUT, QStringList &names SIP_OUT, QStringList &descriptions SIP_OUT, QString &msgError SIP_OUT );
758
762 virtual QString getStyleFromDatabase( const QString &styleId, QString &msgError SIP_OUT );
763
770 virtual bool deleteStyleFromDatabase( const QString &styleId, QString &msgError SIP_OUT );
771
777 enum class SaveStyleResult SIP_ENUM_BASETYPE( IntFlag )
778 {
779 Success = 0,
780 QmlGenerationFailed = 1 << 0,
781 SldGenerationFailed = 1 << 1,
782 DatabaseWriteFailed = 1 << 2,
783 };
784 Q_ENUM( SaveStyleResult )
785
786
792 Q_FLAG( SaveStyleResults )
793
811 Q_DECL_DEPRECATED virtual void saveStyleToDatabase(
812 const QString &name, const QString &description, bool useAsDefault, const QString &uiFileContent, QString &msgError SIP_OUT, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories
814
829 const QString &name, const QString &description, bool useAsDefault, const QString &uiFileContent, QString &msgError SIP_OUT, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories
830 );
831
849 const QString &name, const QString &description, bool useAsDefault, const QString &uiFileContent, const Qgis::SaveStyleFormats formats, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories
850 );
851
852 // 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".
853 // 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.
854
865 virtual QString loadNamedStyle(
866 const QString &theURI, bool &resultFlag SIP_OUT, bool loadFromLocalDb, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories, Qgis::LoadStyleFlags flags = Qgis::LoadStyleFlags()
867 );
868
869#ifndef SIP_RUN
870
881 template<class T> T customEnumProperty( const QString &key, const T &defaultValue )
882 {
883 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
884 Q_ASSERT( metaEnum.isValid() );
885 if ( !metaEnum.isValid() )
886 {
887 QgsDebugError( u"Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration."_s );
888 }
889
890 T v;
891 bool ok = false;
892
893 if ( metaEnum.isValid() )
894 {
895 // read as string
896 QByteArray ba = customProperty( key, metaEnum.valueToKey( static_cast<int>( defaultValue ) ) ).toString().toUtf8();
897 const char *vs = ba.data();
898 v = static_cast<T>( metaEnum.keyToValue( vs, &ok ) );
899 if ( ok )
900 return v;
901 }
902
903 // if failed, try to read as int (old behavior)
904 // this code shall be removed later
905 // then the method could be marked as const
906 v = static_cast<T>( customProperty( key, static_cast<int>( defaultValue ) ).toInt( &ok ) );
907 if ( metaEnum.isValid() )
908 {
909 if ( !ok || !metaEnum.valueToKey( static_cast<int>( v ) ) )
910 {
911 v = defaultValue;
912 }
913 else
914 {
915 // found property as an integer
916 // convert the property to the new form (string)
917 setCustomEnumProperty( key, v );
918 }
919 }
920
921 return v;
922 }
923
932 template<class T> void setCustomEnumProperty( const QString &key, const T &value )
933 {
934 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
935 Q_ASSERT( metaEnum.isValid() );
936 if ( metaEnum.isValid() )
937 {
938 setCustomProperty( key, metaEnum.valueToKey( static_cast<int>( value ) ) );
939 }
940 else
941 {
942 QgsDebugError( u"Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration."_s );
943 }
944 }
945
957 template<class T> T customFlagProperty( const QString &key, const T &defaultValue )
958 {
959 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
960 Q_ASSERT( metaEnum.isValid() );
961 if ( !metaEnum.isValid() )
962 {
963 QgsDebugError( u"Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration."_s );
964 }
965
966 T v = defaultValue;
967 bool ok = false;
968
969 if ( metaEnum.isValid() )
970 {
971 // read as string
972 QByteArray ba = customProperty( key, metaEnum.valueToKeys( defaultValue ) ).toString().toUtf8();
973 const char *vs = ba.data();
974 v = static_cast<T>( metaEnum.keysToValue( vs, &ok ) );
975 }
976 if ( !ok )
977 {
978 // if failed, try to read as int
979 const int intValue = customProperty( key, static_cast<int>( defaultValue ) ).toInt( &ok );
980 if ( metaEnum.isValid() )
981 {
982 if ( ok )
983 {
984 // check that the int value does correspond to a flag
985 // see https://stackoverflow.com/a/68495949/1548052
986 const QByteArray keys = metaEnum.valueToKeys( intValue );
987 const int intValueCheck = metaEnum.keysToValue( keys );
988 if ( intValue != intValueCheck )
989 {
990 v = defaultValue;
991 }
992 else
993 {
994 // found property as an integer
995 v = T( intValue );
996 // convert the property to the new form (string)
997 // this code could be removed
998 // then the method could be marked as const
999 setCustomFlagProperty( key, v );
1000 }
1001 }
1002 else
1003 {
1004 v = defaultValue;
1005 }
1006 }
1007 }
1008
1009 return v;
1010 }
1011
1020 template<class T> void setCustomFlagProperty( const QString &key, const T &value )
1021 {
1022 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
1023 Q_ASSERT( metaEnum.isValid() );
1024 if ( metaEnum.isValid() )
1025 {
1026 setCustomProperty( key, metaEnum.valueToKeys( value ) );
1027 }
1028 else
1029 {
1030 QgsDebugError( u"Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration."_s );
1031 }
1032 }
1033#endif
1034
1035
1040 void removeCustomProperty( const QString &key );
1041
1047 virtual QgsError error() const;
1048
1060 QgsCoordinateReferenceSystem crs() const;
1061
1080 QgsCoordinateReferenceSystem verticalCrs() const;
1081
1100 QgsCoordinateReferenceSystem crs3D() const;
1101
1112 void setCrs( const QgsCoordinateReferenceSystem &srs, bool emitSignal = true );
1113
1133 bool setVerticalCrs( const QgsCoordinateReferenceSystem &crs, QString *errorMessage SIP_OUT = nullptr );
1134
1140 QgsCoordinateTransformContext transformContext() const;
1141
1142
1147 static QString formatLayerName( const QString &name );
1148
1155 virtual QString metadataUri() const;
1156
1162 void exportNamedMetadata( QDomDocument &doc, QString &errorMsg ) const;
1163
1172 virtual QString saveDefaultMetadata( bool &resultFlag SIP_OUT );
1173
1187 QString saveNamedMetadata( const QString &uri, bool &resultFlag SIP_OUT );
1188
1189 // 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".
1190 // 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.
1191
1205 virtual QString loadNamedMetadata( const QString &uri, bool &resultFlag SIP_OUT );
1206
1207 // 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".
1208 // 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.
1209
1218 virtual QString loadDefaultMetadata( bool &resultFlag SIP_OUT );
1219
1227 bool loadNamedMetadataFromDatabase( const QString &db, const QString &uri, QString &qmd );
1228
1235 bool importNamedMetadata( QDomDocument &document, QString &errorMessage );
1236
1245 virtual QString styleURI() const;
1246
1247 // 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".
1248 // 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.
1249
1259 virtual QString loadDefaultStyle( bool &resultFlag SIP_OUT );
1260
1261 // 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".
1262 // 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.
1263
1280 virtual QString loadNamedStyle(
1281 const QString &uri, bool &resultFlag SIP_OUT, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories, Qgis::LoadStyleFlags flags = Qgis::LoadStyleFlags()
1282 );
1283
1291 virtual bool loadNamedStyleFromDatabase( const QString &db, const QString &uri, QString &qml SIP_OUT );
1292
1301 virtual bool importNamedStyle( QDomDocument &doc, QString &errorMsg SIP_OUT, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories );
1302
1311 virtual void exportNamedStyle(
1312 QDomDocument &doc, QString &errorMsg SIP_OUT, const QgsReadWriteContext &context = QgsReadWriteContext(), QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories
1313 ) const;
1314
1315
1323 Q_DECL_DEPRECATED virtual void exportSldStyle( QDomDocument &doc, QString &errorMsg ) const SIP_DEPRECATED;
1324
1332 Q_DECL_DEPRECATED virtual void exportSldStyleV2( QDomDocument &doc, QString &errorMsg, QgsSldExportContext &exportContext ) const SIP_DEPRECATED;
1333
1343 virtual QDomDocument exportSldStyleV3( QgsSldExportContext &exportContext ) const;
1344
1356 virtual QString saveDefaultStyle( bool &resultFlag SIP_OUT, StyleCategories categories );
1357
1369 Q_DECL_DEPRECATED virtual QString saveDefaultStyle( bool &resultFlag SIP_OUT ) SIP_DEPRECATED;
1370
1386 virtual QString saveNamedStyle( const QString &uri, bool &resultFlag SIP_OUT, StyleCategories categories = AllStyleCategories );
1387
1397 virtual QString saveSldStyle( const QString &uri, bool &resultFlag SIP_OUT ) const;
1398
1409 virtual QString saveSldStyleV2( bool &resultFlag SIP_OUT, QgsSldExportContext &exportContext ) const;
1410
1419 virtual QString loadSldStyle( const QString &uri, bool &resultFlag SIP_OUT );
1420
1421 virtual bool readSld( const QDomNode &node, QString &errorMessage )
1422 {
1423 Q_UNUSED( node )
1424 errorMessage = u"Layer type %1 not supported"_s.arg( static_cast<int>( type() ) );
1425 return false;
1426 }
1427
1428
1437 virtual bool readSymbology( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories ) = 0;
1438
1448 virtual bool readStyle( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories );
1449
1460 virtual bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories ) const = 0;
1461
1473 virtual bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories ) const;
1474
1475
1506 void setDataSource( const QString &dataSource, const QString &baseName = QString(), const QString &provider = QString(), bool loadDefaultStyleFlag = false );
1507
1537 void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, bool loadDefaultStyleFlag = false );
1538
1568 void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, Qgis::DataProviderReadFlags flags );
1569
1573 QString providerType() const;
1574
1576 QUndoStack *undoStack() SIP_DISALLOWNONE;
1577
1581 QUndoStack *undoStackStyles() SIP_DISALLOWNONE;
1582
1588 Q_DECL_DEPRECATED void setLegendUrl( const QString &legendUrl ) SIP_DEPRECATED;
1589
1595 Q_DECL_DEPRECATED QString legendUrl() const SIP_DEPRECATED;
1596
1602 Q_DECL_DEPRECATED void setLegendUrlFormat( const QString &legendUrlFormat ) SIP_DEPRECATED;
1603
1609 Q_DECL_DEPRECATED QString legendUrlFormat() const SIP_DEPRECATED;
1610
1616
1620 QgsMapLayerLegend *legend() const;
1621
1626
1631
1636
1645 bool isInScaleRange( double scale ) const;
1646
1657 double minimumScale() const;
1658
1669 double maximumScale() const;
1670
1679 bool hasScaleBasedVisibility() const;
1680
1687 Q_DECL_DEPRECATED bool hasAutoRefreshEnabled() const SIP_DEPRECATED;
1688
1695 Qgis::AutoRefreshMode autoRefreshMode() const;
1696
1703 int autoRefreshInterval() const;
1704
1715 void setAutoRefreshInterval( int interval );
1716
1723 Q_DECL_DEPRECATED void setAutoRefreshEnabled( bool enabled ) SIP_DEPRECATED;
1724
1731 void setAutoRefreshMode( Qgis::AutoRefreshMode mode );
1732
1738 virtual const QgsLayerMetadata &metadata() const;
1739
1745 virtual void setMetadata( const QgsLayerMetadata &metadata );
1746
1750 virtual QString htmlMetadata() const;
1751
1753 virtual QDateTime timestamp() const;
1754
1761 virtual QSet<QgsMapLayerDependency> dependencies() const;
1762
1768
1774
1783 QString originalXmlProperties() const;
1784
1792 void setOriginalXmlProperties( const QString &originalXmlProperties );
1793
1801 static QString generateId( const QString &layerName );
1802
1812 virtual bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
1813
1823 virtual bool accept( QgsObjectEntityVisitorInterface *visitor, const QgsObjectVisitorContext &context ) const;
1824
1831
1838
1845
1846
1852 virtual QgsAbstractProfileSource *profileSource() { return nullptr; }
1853
1859 QString legendPlaceholderImage() const { return mLegendPlaceholderImage; }
1860
1866 void setLegendPlaceholderImage( const QString &imgPath ) { mLegendPlaceholderImage = imgPath; }
1867
1874 virtual bool hasMapTips() const;
1875
1883 QString mapTipTemplate() const;
1884
1892 void setMapTipTemplate( const QString &mapTipTemplate );
1893
1900 void setMapTipsEnabled( bool enabled );
1901
1906 bool mapTipsEnabled() const;
1907
1915 static Qgis::DataProviderReadFlags providerReadFlags( const QDomNode &layerNode, QgsMapLayer::ReadFlags layerReadFlags );
1916
1917 public slots:
1918
1928 void setMinimumScale( double scale );
1929
1939 void setMaximumScale( double scale );
1940
1948 void setScaleBasedVisibility( bool enabled );
1949
1958 void triggerRepaint( bool deferredUpdate = false );
1959
1966 void trigger3DUpdate();
1967
1971 void emitStyleChanged();
1972
1980 virtual bool setDependencies( const QSet<QgsMapLayerDependency> &layers );
1981
1986 void setRefreshOnNotifyEnabled( bool enabled );
1987
1994 void setRefreshOnNofifyMessage( const QString &message ) { mRefreshOnNofifyMessage = message; }
1995
2002
2003#ifdef SIP_RUN
2004 // clang-format off
2005 SIP_PYOBJECT __repr__();
2006 % MethodCode
2007 QString str = u"<QgsMapLayer: '%1' (%2)>"_s.arg( sipCpp->name(), sipCpp->dataProvider() ? sipCpp->dataProvider()->name() : u"Invalid"_s );
2008 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
2009 % End
2010// clang-format on
2011#endif
2012
2019 QgsProject *project() const;
2020
2021 signals:
2022
2030
2032 void statusChanged( const QString &status );
2033
2042 void idChanged( const QString &id );
2043
2048
2058
2069
2086
2093 void repaintRequested( bool deferredUpdate = false );
2094
2097
2100
2102 void blendModeChanged( QPainter::CompositionMode blendMode );
2103
2112 void opacityChanged( double opacity );
2113
2119
2131
2136
2141
2148
2154
2159
2166
2171 void autoRefreshIntervalChanged( int interval );
2172
2179
2187
2196
2203
2210
2216 void customPropertyChanged( const QString &key );
2217
2223
2229
2235
2242
2250
2251 private slots:
2252
2253 void onNotified( const QString &message );
2254
2270 virtual void setDataSourcePrivate( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, Qgis::DataProviderReadFlags flags );
2271
2272 protected:
2277 void clone( QgsMapLayer *layer ) const;
2278
2280 virtual void setExtent( const QgsRectangle &rect );
2281
2286 virtual void setExtent3D( const QgsBox3D &box );
2287
2289 void setValid( bool valid );
2290
2295 virtual bool readXml( const QDomNode &layer_node, QgsReadWriteContext &context );
2296
2301 virtual bool writeXml( QDomNode &layer_node, QDomDocument &document, const QgsReadWriteContext &context ) const;
2302
2314 virtual QString encodedSource( const QString &source, const QgsReadWriteContext &context ) const;
2315
2328 virtual QString decodedSource( const QString &source, const QString &dataProvider, const QgsReadWriteContext &context ) const;
2329
2335 void readCustomProperties( const QDomNode &layerNode, const QString &keyStartsWith = QString() );
2336
2338 void writeCustomProperties( QDomNode &layerNode, QDomDocument &doc ) const;
2339
2341 void readStyleManager( const QDomNode &layerNode );
2343 void writeStyleManager( QDomNode &layerNode, QDomDocument &doc ) const;
2344
2348 void writeCommonStyle( QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories ) const;
2349
2353 void readCommonStyle( const QDomElement &layerElement, const QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories );
2354
2356 void setProviderType( const QString &providerType );
2357
2358#ifndef SIP_RUN
2359#if 0
2361 void connectNotify( const char *signal ) override;
2362#endif
2363#endif
2364
2366 void appendError( const QgsErrorMessage &error ) { mError.append( error ); }
2368 void setError( const QgsError &error ) { mError = error; }
2369
2376 void invalidateWgs84Extent();
2377
2379 bool mValid = false;
2380
2383
2385 QString mLayerName;
2386
2389
2391 QSet<QgsMapLayerDependency> mDependencies;
2392
2398 Q_DECL_DEPRECATED bool hasDependencyCycle( const QSet<QgsMapLayerDependency> & ) const { return false; }
2399
2402
2405
2406 //TODO QGIS 5 - move to readXml as a new argument (breaks API)
2407
2410
2417
2423 double mLayerOpacity = 1.0;
2424
2431
2432#ifndef SIP_RUN
2433
2442 QString crsHtmlMetadata() const;
2443#endif
2444
2445#ifndef SIP_RUN
2446
2455 QString generalHtmlMetadata() const;
2456
2465 QString customPropertyHtmlMetadata() const;
2466#endif
2467
2468#ifndef SIP_RUN
2469
2477 std::unique_ptr<QgsDataProvider> mPreloadedProvider;
2478#endif
2479
2480 private:
2481 virtual QString baseURI( PropertyType type ) const;
2482 QString saveNamedProperty( const QString &uri, QgsMapLayer::PropertyType type, bool &resultFlag, StyleCategories categories = AllStyleCategories );
2483 QString loadNamedProperty(
2484 const QString &uri,
2486 bool &namedPropertyExists,
2487 bool &propertySuccessfullyLoaded,
2490 );
2491 bool loadNamedPropertyFromDatabase( const QString &db, const QString &uri, QString &xml, QgsMapLayer::PropertyType type );
2492
2493 // const method because extents are mutable
2494 void updateExtent( const QgsRectangle &extent ) const;
2495 void updateExtent( const QgsBox3D &extent ) const;
2496
2497 bool rebuildCrs3D( QString *error = nullptr );
2498
2503 virtual bool isReadOnly() const;
2504
2510 QgsCoordinateReferenceSystem mVerticalCrs;
2512
2514 QString mID;
2515
2517 Qgis::LayerType mLayerType;
2518
2520
2522 QPainter::CompositionMode mBlendMode = QPainter::CompositionMode_SourceOver;
2523
2525 QString mTag;
2526
2527 //set some generous defaults for scale based visibility
2528
2530 double mMinScale = 0;
2532 double mMaxScale = 100000000;
2534 bool mScaleBasedVisibility = false;
2535
2539 std::unique_ptr< QgsMapLayerServerProperties > mServerProperties;
2540
2542 QUndoStack *mUndoStack = nullptr;
2543
2544 QUndoStack *mUndoStackStyles = nullptr;
2545
2547 QgsObjectCustomProperties mCustomProperties;
2548
2550 QgsMapLayerLegend *mLegend = nullptr;
2551
2553 QgsMapLayerStyleManager *mStyleManager = nullptr;
2554
2556
2558 QTimer *mRefreshTimer = nullptr;
2559
2560 QgsLayerMetadata mMetadata;
2561
2563 std::unique_ptr<QgsAbstract3DRenderer> m3DRenderer;
2564
2566 mutable QgsBox3D mExtent3D;
2567
2569 mutable QgsRectangle mExtent2D;
2570
2572 mutable QgsRectangle mWgs84Extent;
2573
2579 QString mOriginalXmlProperties;
2580
2582 bool mRepaintRequestedFired = false;
2583
2585 QString mLegendPlaceholderImage;
2586
2588 QString mMapTipTemplate;
2589
2591 bool mMapTipsEnabled = true;
2592
2593 friend class QgsVectorLayer;
2594 friend class TestQgsProject;
2595 friend class TestQgsMapLayer;
2596};
2597
2601
2602
2603#ifndef SIP_RUN
2604
2609typedef QPointer< QgsMapLayer > QgsWeakMapLayerPointer;
2610
2615typedef QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList;
2616#endif
2617
2618#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:88
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:93
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:91
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:90
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:94
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
bool hasScaleBasedVisibility() const
Returns whether scale based visibility is enabled for the layer.
QgsMapLayerSelectionProperties * selectionProperties
Definition qgsmaplayer.h:99
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:98
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:96
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.
QgsSaveStyleResult saveStyleToDatabaseV3(const QString &name, const QString &description, bool useAsDefault, const QString &uiFileContent, const Qgis::SaveStyleFormats formats, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories)
Saves selected representation of the layer's style to a table in the database.
int autoRefreshInterval
Definition qgsmaplayer.h:89
QgsCoordinateReferenceSystem verticalCrs
Definition qgsmaplayer.h:92
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:97
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.
Represents the result of saving a style.
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
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsTimeZoneComboBox::StandardItems)
#define QgsDebugError(str)
Definition qgslogger.h:71
QPointer< QgsMapLayer > QgsWeakMapLayerPointer
Weak pointer for QgsMapLayer.
QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList
A list of weak pointers to QgsMapLayers.
Setting options for creating vector data providers.