QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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 <QUndoStack>
44#include <QVariant>
45
48class QgsDataProvider;
52class QgsProject;
60
61class QDomDocument;
62class QKeyEvent;
63class QPainter;
65class QgsBox3D;
66
67/*
68 * Constants used to describe copy-paste MIME types
69 */
70#define QGSCLIPBOARD_MAPLAYER_MIME "application/qgis.maplayer"
71
72
79class CORE_EXPORT QgsMapLayer : public QObject
80{
81 Q_OBJECT
82
83 Q_PROPERTY( QString id READ id WRITE setId NOTIFY idChanged )
84 Q_PROPERTY( QString name READ name WRITE setName NOTIFY nameChanged )
87 Q_PROPERTY( QgsCoordinateReferenceSystem crs READ crs WRITE setCrs NOTIFY crsChanged )
90 Q_PROPERTY( Qgis::LayerType type READ type CONSTANT )
91 Q_PROPERTY( bool isValid READ isValid NOTIFY isValidChanged )
92 Q_PROPERTY( double opacity READ opacity WRITE setOpacity NOTIFY opacityChanged )
96 Q_PROPERTY( QgsMapLayer::LayerFlags flags READ flags WRITE setFlags NOTIFY flagsChanged )
97
98#ifdef SIP_RUN
100 QgsMapLayer *layer = qobject_cast<QgsMapLayer *>( sipCpp );
101
102 sipType = 0;
103
104 if ( layer )
105 {
106 switch ( layer->type() )
107 {
109 sipType = sipType_QgsVectorLayer;
110 break;
112 sipType = sipType_QgsRasterLayer;
113 break;
115 sipType = sipType_QgsPluginLayer;
116 break;
118 sipType = sipType_QgsMeshLayer;
119 break;
121 sipType = sipType_QgsVectorTileLayer;
122 break;
124 sipType = sipType_QgsAnnotationLayer;
125 break;
127 sipType = sipType_QgsPointCloudLayer;
128 break;
130 sipType = sipType_QgsGroupLayer;
131 break;
133 sipType = sipType_QgsTiledSceneLayer;
134 break;
135 default:
136 sipType = nullptr;
137 break;
138 }
139 }
140 SIP_END
141#endif
142
143 public:
144
149 {
150 Style = 0,
152 };
153
160 {
161 Identifiable = 1 << 0,
162 Removable = 1 << 1,
163 Searchable = 1 << 2,
164 Private = 1 << 3,
165 };
166 Q_ENUM( LayerFlag )
167 Q_DECLARE_FLAGS( LayerFlags, LayerFlag )
168 Q_FLAG( LayerFlags )
169
199 Q_ENUM( StyleCategory )
200 Q_DECLARE_FLAGS( StyleCategories, StyleCategory )
201 Q_FLAG( StyleCategories )
202
209 QgsMapLayer( Qgis::LayerType type = Qgis::LayerType::Vector, const QString &name = QString(), const QString &source = QString() );
210
211 ~QgsMapLayer() override;
212
213 QgsMapLayer( const QgsMapLayer & ) = delete;
214 QgsMapLayer &operator=( const QgsMapLayer & ) = delete;
215
221 virtual QgsMapLayer *clone() const = 0;
222
226 Qgis::LayerType type() const;
227
239
251
261 virtual Qgis::MapLayerProperties properties() const;
262
267 static QString extensionPropertyType( PropertyType type );
268
275 QString id() const;
276
292 bool setId( const QString &id );
293
298 void setName( const QString &name );
299
304 QString name() const;
305
309 Q_INVOKABLE virtual QgsDataProvider *dataProvider();
310
315 virtual const QgsDataProvider *dataProvider() const SIP_SKIP;
316
322
328 Q_DECL_DEPRECATED void setShortName( const QString &shortName ) SIP_DEPRECATED;
329
335 Q_DECL_DEPRECATED QString shortName() const SIP_DEPRECATED;
336
342 Q_DECL_DEPRECATED void setTitle( const QString &title ) SIP_DEPRECATED;
343
349 Q_DECL_DEPRECATED QString title() const SIP_DEPRECATED;
350
356 Q_DECL_DEPRECATED void setAbstract( const QString &abstract ) SIP_DEPRECATED;
357
363 Q_DECL_DEPRECATED QString abstract() const SIP_DEPRECATED;
364
370 Q_DECL_DEPRECATED void setKeywordList( const QString &keywords ) SIP_DEPRECATED;
371
377 Q_DECL_DEPRECATED QString keywordList() const SIP_DEPRECATED;
378
384 Q_DECL_DEPRECATED void setDataUrl( const QString &dataUrl ) SIP_DEPRECATED;
385
391 Q_DECL_DEPRECATED QString dataUrl() const SIP_DEPRECATED;
392
398 Q_DECL_DEPRECATED void setDataUrlFormat( const QString &dataUrlFormat ) SIP_DEPRECATED;
399
405 Q_DECL_DEPRECATED QString dataUrlFormat() const SIP_DEPRECATED;
406
412 Q_DECL_DEPRECATED void setAttribution( const QString &attrib ) SIP_DEPRECATED;
413
419 Q_DECL_DEPRECATED QString attribution() const SIP_DEPRECATED;
420
426 Q_DECL_DEPRECATED void setAttributionUrl( const QString &attribUrl ) SIP_DEPRECATED;
427
433 Q_DECL_DEPRECATED QString attributionUrl() const SIP_DEPRECATED;
434
435 /* Layer metadataUrl information */
436
441 QgsMapLayerServerProperties *serverProperties() { return mServerProperties.get(); };
442
447 const QgsMapLayerServerProperties *serverProperties() const { return mServerProperties.get(); } SIP_SKIP;
448
457 Q_DECL_DEPRECATED void setMetadataUrl( const QString &metaUrl ) SIP_DEPRECATED;
458
468 Q_DECL_DEPRECATED QString metadataUrl() const SIP_DEPRECATED;
469
478 Q_DECL_DEPRECATED void setMetadataUrlType( const QString &metaUrlType ) SIP_DEPRECATED;
479
489 Q_DECL_DEPRECATED QString metadataUrlType() const SIP_DEPRECATED;
490
499 Q_DECL_DEPRECATED void setMetadataUrlFormat( const QString &metaUrlFormat ) SIP_DEPRECATED;
500
510 Q_DECL_DEPRECATED QString metadataUrlFormat() const SIP_DEPRECATED;
511
517 void setBlendMode( QPainter::CompositionMode blendMode );
518
523 QPainter::CompositionMode blendMode() const;
524
533 virtual void setOpacity( double opacity );
534
543 virtual double opacity() const;
544
546 bool readOnly() const { return isReadOnly(); }
547
551 Q_INVOKABLE virtual void reload() {}
552
557
559 virtual QgsRectangle extent() const;
560
565 virtual QgsBox3D extent3D() const;
566
575 QgsRectangle wgs84Extent( bool forceRecalculate = false ) const;
576
582 bool isValid() const;
583
584 // TODO QGIS 4.0: consider changing bool hidePassword to an enumeration: HIDE_CREDENTIALS / REDACT_CREDENTIALS
585 // to avoid the ambiguity of the double negation (hide = false)
586
594 QString publicSource( bool hidePassword = false ) const;
595
601 QString source() const;
602
607 virtual QStringList subLayers() const;
608
613 virtual void setLayerOrder( const QStringList &layers );
614
620 virtual void setSubLayerVisibility( const QString &name, bool visible );
621
628 virtual bool supportsEditing() const;
629
631 virtual bool isEditable() const;
632
638 virtual bool isModified() const;
639
643 virtual bool isSpatial() const;
644
654 virtual bool isTemporary() const;
655
667 Q_DECLARE_FLAGS( ReadFlags, ReadFlag )
668
669
686 bool readLayerXml( const QDomElement &layerElement, QgsReadWriteContext &context,
688
704 bool writeLayerXml( QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context ) const;
705
709 virtual void resolveReferences( QgsProject *project );
710
715 Q_INVOKABLE QStringList customPropertyKeys() const;
716
722 Q_INVOKABLE void setCustomProperty( const QString &key, const QVariant &value );
723
728 Q_INVOKABLE QVariant customProperty( const QString &value, const QVariant &defaultValue = QVariant() ) const;
729
734
741
751 virtual int listStylesInDatabase( QStringList &ids SIP_OUT, QStringList &names SIP_OUT,
752 QStringList &descriptions SIP_OUT, QString &msgError SIP_OUT );
753
757 virtual QString getStyleFromDatabase( const QString &styleId, QString &msgError SIP_OUT );
758
765 virtual bool deleteStyleFromDatabase( const QString &styleId, QString &msgError SIP_OUT );
766
772 enum class SaveStyleResult SIP_ENUM_BASETYPE( IntFlag )
773 {
774 Success = 0,
775 QmlGenerationFailed = 1 << 0,
776 SldGenerationFailed = 1 << 1,
777 DatabaseWriteFailed = 1 << 2,
778 };
779 Q_ENUM( SaveStyleResult )
780
781
787 Q_FLAG( SaveStyleResults )
788
806 Q_DECL_DEPRECATED virtual void saveStyleToDatabase( const QString &name, const QString &description,
807 bool useAsDefault, const QString &uiFileContent,
808 QString &msgError SIP_OUT,
810
824 QgsMapLayer::SaveStyleResults saveStyleToDatabaseV2( const QString &name, const QString &description,
825 bool useAsDefault, const QString &uiFileContent,
826 QString &msgError SIP_OUT,
828
829 // TODO QGIS 4.0 -- fix this. We incorrectly have a single boolean flag which in which false is used inconsistently for "a style WAS found but an error occurred loading it" vs "no style was found".
830 // 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.
831
842 virtual QString loadNamedStyle( const QString &theURI, bool &resultFlag SIP_OUT, bool loadFromLocalDb,
844 Qgis::LoadStyleFlags flags = Qgis::LoadStyleFlags() );
845
846#ifndef SIP_RUN
847
858 template <class T>
859 T customEnumProperty( const QString &key, const T &defaultValue )
860 {
861 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
862 Q_ASSERT( metaEnum.isValid() );
863 if ( !metaEnum.isValid() )
864 {
865 QgsDebugError( QStringLiteral( "Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
866 }
867
868 T v;
869 bool ok = false;
870
871 if ( metaEnum.isValid() )
872 {
873 // read as string
874 QByteArray ba = customProperty( key, metaEnum.valueToKey( static_cast<int>( defaultValue ) ) ).toString().toUtf8();
875 const char *vs = ba.data();
876 v = static_cast<T>( metaEnum.keyToValue( vs, &ok ) );
877 if ( ok )
878 return v;
879 }
880
881 // if failed, try to read as int (old behavior)
882 // this code shall be removed later
883 // then the method could be marked as const
884 v = static_cast<T>( customProperty( key, static_cast<int>( defaultValue ) ).toInt( &ok ) );
885 if ( metaEnum.isValid() )
886 {
887 if ( !ok || !metaEnum.valueToKey( static_cast<int>( v ) ) )
888 {
889 v = defaultValue;
890 }
891 else
892 {
893 // found property as an integer
894 // convert the property to the new form (string)
895 setCustomEnumProperty( key, v );
896 }
897 }
898
899 return v;
900 }
901
910 template <class T>
911 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( QStringLiteral( "Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
922 }
923 }
924
936 template <class T>
937 T customFlagProperty( const QString &key, const T &defaultValue )
938 {
939 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
940 Q_ASSERT( metaEnum.isValid() );
941 if ( !metaEnum.isValid() )
942 {
943 QgsDebugError( QStringLiteral( "Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
944 }
945
946 T v = defaultValue;
947 bool ok = false;
948
949 if ( metaEnum.isValid() )
950 {
951 // read as string
952 QByteArray ba = customProperty( key, metaEnum.valueToKeys( defaultValue ) ).toString().toUtf8();
953 const char *vs = ba.data();
954 v = static_cast<T>( metaEnum.keysToValue( vs, &ok ) );
955 }
956 if ( !ok )
957 {
958 // if failed, try to read as int
959 const int intValue = customProperty( key, static_cast<int>( defaultValue ) ).toInt( &ok );
960 if ( metaEnum.isValid() )
961 {
962 if ( ok )
963 {
964 // check that the int value does correspond to a flag
965 // see https://stackoverflow.com/a/68495949/1548052
966 const QByteArray keys = metaEnum.valueToKeys( intValue );
967 const int intValueCheck = metaEnum.keysToValue( keys );
968 if ( intValue != intValueCheck )
969 {
970 v = defaultValue;
971 }
972 else
973 {
974 // found property as an integer
975 v = T( intValue );
976 // convert the property to the new form (string)
977 // this code could be removed
978 // then the method could be marked as const
979 setCustomFlagProperty( key, v );
980 }
981 }
982 else
983 {
984 v = defaultValue;
985 }
986 }
987 }
988
989 return v;
990 }
991
1000 template <class T>
1001 void setCustomFlagProperty( const QString &key, const T &value )
1002 {
1003 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
1004 Q_ASSERT( metaEnum.isValid() );
1005 if ( metaEnum.isValid() )
1006 {
1007 setCustomProperty( key, metaEnum.valueToKeys( value ) );
1008 }
1009 else
1010 {
1011 QgsDebugError( QStringLiteral( "Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
1012 }
1013 }
1014#endif
1015
1016
1021 void removeCustomProperty( const QString &key );
1022
1028 virtual QgsError error() const;
1029
1041 QgsCoordinateReferenceSystem crs() const;
1042
1061 QgsCoordinateReferenceSystem verticalCrs() const;
1062
1081 QgsCoordinateReferenceSystem crs3D() const;
1082
1093 void setCrs( const QgsCoordinateReferenceSystem &srs, bool emitSignal = true );
1094
1114 bool setVerticalCrs( const QgsCoordinateReferenceSystem &crs, QString *errorMessage SIP_OUT = nullptr );
1115
1121 QgsCoordinateTransformContext transformContext( ) const;
1122
1123
1128 static QString formatLayerName( const QString &name );
1129
1136 virtual QString metadataUri() const;
1137
1143 void exportNamedMetadata( QDomDocument &doc, QString &errorMsg ) const;
1144
1153 virtual QString saveDefaultMetadata( bool &resultFlag SIP_OUT );
1154
1168 QString saveNamedMetadata( const QString &uri, bool &resultFlag SIP_OUT );
1169
1170 // TODO QGIS 4.0 -- fix this. We incorrectly have a single boolean flag which in which false is used inconsistently for "metadata WAS found but an error occurred loading it" vs "no metadata was found".
1171 // 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.
1172
1186 virtual QString loadNamedMetadata( const QString &uri, bool &resultFlag SIP_OUT );
1187
1188 // TODO QGIS 4.0 -- fix this. We incorrectly have a single boolean flag which in which false is used inconsistently for "metadata WAS found but an error occurred loading it" vs "no metadata was found".
1189 // 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.
1190
1199 virtual QString loadDefaultMetadata( bool &resultFlag SIP_OUT );
1200
1208 bool loadNamedMetadataFromDatabase( const QString &db, const QString &uri, QString &qmd );
1209
1216 bool importNamedMetadata( QDomDocument &document, QString &errorMessage );
1217
1226 virtual QString styleURI() const;
1227
1228 // TODO QGIS 4.0 -- fix this. We incorrectly have a single boolean flag which in which false is used inconsistently for "a style WAS found but an error occurred loading it" vs "no style was found".
1229 // 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.
1230
1240 virtual QString loadDefaultStyle( bool &resultFlag SIP_OUT );
1241
1242 // TODO QGIS 4.0 -- fix this. We incorrectly have a single boolean flag which in which false is used inconsistently for "a style WAS found but an error occurred loading it" vs "no style was found".
1243 // 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.
1244
1261 virtual QString loadNamedStyle( const QString &uri, bool &resultFlag SIP_OUT, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories, Qgis::LoadStyleFlags flags = Qgis::LoadStyleFlags() );
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,
1282
1291 virtual void exportNamedStyle( QDomDocument &doc, QString &errorMsg SIP_OUT, const QgsReadWriteContext &context = QgsReadWriteContext(),
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 { Q_UNUSED( node ) errorMessage = QStringLiteral( "Layer type %1 not supported" ).arg( static_cast<int>( type() ) ); return false; }
1402
1403
1404
1413 virtual bool readSymbology( const QDomNode &node, QString &errorMessage,
1414 QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories ) = 0;
1415
1425 virtual bool readStyle( const QDomNode &node, QString &errorMessage,
1427
1438 virtual bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context,
1439 StyleCategories categories = AllStyleCategories ) const = 0;
1440
1452 virtual bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context,
1453 StyleCategories categories = AllStyleCategories ) const;
1454
1455
1486 void setDataSource( const QString &dataSource, const QString &baseName = QString(), const QString &provider = QString(), bool loadDefaultStyleFlag = false );
1487
1517 void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, bool loadDefaultStyleFlag = false );
1518
1548 void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, Qgis::DataProviderReadFlags flags );
1549
1553 QString providerType() const;
1554
1556 QUndoStack *undoStack();
1557
1561 QUndoStack *undoStackStyles();
1562
1568 Q_DECL_DEPRECATED void setLegendUrl( const QString &legendUrl ) SIP_DEPRECATED;
1569
1575 Q_DECL_DEPRECATED QString legendUrl() const SIP_DEPRECATED;
1576
1582 Q_DECL_DEPRECATED void setLegendUrlFormat( const QString &legendUrlFormat ) SIP_DEPRECATED;
1583
1589 Q_DECL_DEPRECATED QString legendUrlFormat() const SIP_DEPRECATED;
1590
1596
1600 QgsMapLayerLegend *legend() const;
1601
1606
1611
1616
1625 bool isInScaleRange( double scale ) const;
1626
1637 double minimumScale() const;
1638
1649 double maximumScale() const;
1650
1659 bool hasScaleBasedVisibility() const;
1660
1667 Q_DECL_DEPRECATED bool hasAutoRefreshEnabled() const SIP_DEPRECATED;
1668
1675 Qgis::AutoRefreshMode autoRefreshMode() const;
1676
1683 int autoRefreshInterval() const;
1684
1695 void setAutoRefreshInterval( int interval );
1696
1703 Q_DECL_DEPRECATED void setAutoRefreshEnabled( bool enabled ) SIP_DEPRECATED;
1704
1711 void setAutoRefreshMode( Qgis::AutoRefreshMode mode );
1712
1718 virtual const QgsLayerMetadata &metadata() const;
1719
1725 virtual void setMetadata( const QgsLayerMetadata &metadata );
1726
1730 virtual QString htmlMetadata() const;
1731
1733 virtual QDateTime timestamp() const;
1734
1741 virtual QSet<QgsMapLayerDependency> dependencies() const;
1742
1748
1754
1763 QString originalXmlProperties() const;
1764
1772 void setOriginalXmlProperties( const QString &originalXmlProperties );
1773
1778 static QString generateId( const QString &layerName );
1779
1789 virtual bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
1790
1800 virtual bool accept( QgsObjectEntityVisitorInterface *visitor, const QgsObjectVisitorContext &context ) const;
1801
1808
1815
1822
1823
1829 virtual QgsAbstractProfileSource *profileSource() { return nullptr; }
1830
1836 QString legendPlaceholderImage() const { return mLegendPlaceholderImage;}
1837
1843 void setLegendPlaceholderImage( const QString &imgPath ) { mLegendPlaceholderImage = imgPath; }
1844
1851 virtual bool hasMapTips() const;
1852
1860 QString mapTipTemplate() const;
1861
1869 void setMapTipTemplate( const QString &mapTipTemplate );
1870
1877 void setMapTipsEnabled( bool enabled );
1878
1883 bool mapTipsEnabled() const;
1884
1892 static Qgis::DataProviderReadFlags providerReadFlags( const QDomNode &layerNode, QgsMapLayer::ReadFlags layerReadFlags );
1893
1894 public slots:
1895
1905 void setMinimumScale( double scale );
1906
1916 void setMaximumScale( double scale );
1917
1925 void setScaleBasedVisibility( bool enabled );
1926
1935 void triggerRepaint( bool deferredUpdate = false );
1936
1943 void trigger3DUpdate();
1944
1948 void emitStyleChanged();
1949
1957 virtual bool setDependencies( const QSet<QgsMapLayerDependency> &layers );
1958
1963 void setRefreshOnNotifyEnabled( bool enabled );
1964
1971 void setRefreshOnNofifyMessage( const QString &message ) { mRefreshOnNofifyMessage = message; }
1972
1979
1980#ifdef SIP_RUN
1981 SIP_PYOBJECT __repr__();
1982 % MethodCode
1983 QString str = QStringLiteral( "<QgsMapLayer: '%1' (%2)>" ).arg( sipCpp->name(), sipCpp->dataProvider() ? sipCpp->dataProvider()->name() : QStringLiteral( "Invalid" ) );
1984 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
1985 % End
1986#endif
1987
1994 QgsProject *project() const;
1995
1996 signals:
1997
2005
2007 void statusChanged( const QString &status );
2008
2017 void idChanged( const QString &id );
2018
2023
2033
2044
2061
2068 void repaintRequested( bool deferredUpdate = false );
2069
2072
2075
2077 void blendModeChanged( QPainter::CompositionMode blendMode );
2078
2087 void opacityChanged( double opacity );
2088
2094
2106
2111
2116
2123
2129
2134
2141
2146 void autoRefreshIntervalChanged( int interval );
2147
2154
2162
2171
2178
2185
2191 void customPropertyChanged( const QString &key );
2192
2198
2204
2210
2217
2225
2226 private slots:
2227
2228 void onNotified( const QString &message );
2229
2245 virtual void setDataSourcePrivate( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, Qgis::DataProviderReadFlags flags );
2246
2247 protected:
2248
2253 void clone( QgsMapLayer *layer ) const;
2254
2256 virtual void setExtent( const QgsRectangle &rect );
2257
2262 virtual void setExtent3D( const QgsBox3D &box );
2263
2265 void setValid( bool valid );
2266
2271 virtual bool readXml( const QDomNode &layer_node, QgsReadWriteContext &context );
2272
2277 virtual bool writeXml( QDomNode &layer_node, QDomDocument &document, const QgsReadWriteContext &context ) const;
2278
2290 virtual QString encodedSource( const QString &source, const QgsReadWriteContext &context ) const;
2291
2304 virtual QString decodedSource( const QString &source, const QString &dataProvider, const QgsReadWriteContext &context ) const;
2305
2311 void readCustomProperties( const QDomNode &layerNode, const QString &keyStartsWith = QString() );
2312
2314 void writeCustomProperties( QDomNode &layerNode, QDomDocument &doc ) const;
2315
2317 void readStyleManager( const QDomNode &layerNode );
2319 void writeStyleManager( QDomNode &layerNode, QDomDocument &doc ) const;
2320
2324 void writeCommonStyle( QDomElement &layerElement, QDomDocument &document,
2325 const QgsReadWriteContext &context,
2326 StyleCategories categories = AllStyleCategories ) const;
2327
2331 void readCommonStyle( const QDomElement &layerElement, const QgsReadWriteContext &context,
2332 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 4 - 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
2461 virtual QString baseURI( PropertyType type ) const;
2462 QString saveNamedProperty( const QString &uri, QgsMapLayer::PropertyType type,
2463 bool &resultFlag, StyleCategories categories = AllStyleCategories );
2464 QString loadNamedProperty( const QString &uri, QgsMapLayer::PropertyType type,
2465 bool &namedPropertyExists, bool &propertySuccessfullyLoaded, StyleCategories categories = AllStyleCategories, Qgis::LoadStyleFlags flags = Qgis::LoadStyleFlags() );
2466 bool loadNamedPropertyFromDatabase( const QString &db, const QString &uri, QString &xml, QgsMapLayer::PropertyType type );
2467
2468 // const method because extents are mutable
2469 void updateExtent( const QgsRectangle &extent ) const;
2470 void updateExtent( const QgsBox3D &extent ) const;
2471
2472 bool rebuildCrs3D( QString *error = nullptr );
2473
2478 virtual bool isReadOnly() const;
2479
2485 QgsCoordinateReferenceSystem mVerticalCrs;
2487
2489 QString mID;
2490
2492 Qgis::LayerType mLayerType;
2493
2495
2497 QPainter::CompositionMode mBlendMode = QPainter::CompositionMode_SourceOver;
2498
2500 QString mTag;
2501
2502 //set some generous defaults for scale based visibility
2503
2505 double mMinScale = 0;
2507 double mMaxScale = 100000000;
2509 bool mScaleBasedVisibility = false;
2510
2514 std::unique_ptr< QgsMapLayerServerProperties > mServerProperties;
2515
2517 QUndoStack *mUndoStack = nullptr;
2518
2519 QUndoStack *mUndoStackStyles = nullptr;
2520
2522 QgsObjectCustomProperties mCustomProperties;
2523
2525 std::unique_ptr<QgsMapLayerLegend> mLegend;
2526
2528 std::unique_ptr<QgsMapLayerStyleManager> mStyleManager;
2529
2531
2533 QTimer *mRefreshTimer = nullptr;
2534
2535 QgsLayerMetadata mMetadata;
2536
2538 std::unique_ptr<QgsAbstract3DRenderer> m3DRenderer;
2539
2541 mutable QgsBox3D mExtent3D;
2542
2544 mutable QgsRectangle mExtent2D;
2545
2547 mutable QgsRectangle mWgs84Extent;
2548
2554 QString mOriginalXmlProperties;
2555
2557 bool mRepaintRequestedFired = false;
2558
2560 QString mLegendPlaceholderImage;
2561
2563 QString mMapTipTemplate;
2564
2566 bool mMapTipsEnabled = true;
2567
2568 friend class QgsVectorLayer;
2569 friend class TestQgsProject;
2570 friend class TestQgsMapLayer;
2571};
2572
2576
2577
2578#ifndef SIP_RUN
2579
2584typedef QPointer< QgsMapLayer > QgsWeakMapLayerPointer;
2585
2590typedef QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList;
2591#endif
2592
2593#endif
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:56
QFlags< DataProviderReadFlag > DataProviderReadFlags
Flags which control data provider construction.
Definition qgis.h:486
LayerType
Types of layers that can be added to a map.
Definition qgis.h:190
@ Group
Composite group layer. Added in QGIS 3.24.
Definition qgis.h:198
@ Plugin
Plugin based layer.
Definition qgis.h:193
@ TiledScene
Tiled scene layer. Added in QGIS 3.34.
Definition qgis.h:199
@ Annotation
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
Definition qgis.h:196
@ Vector
Vector layer.
Definition qgis.h:191
@ VectorTile
Vector tile layer. Added in QGIS 3.14.
Definition qgis.h:195
@ Mesh
Mesh layer. Added in QGIS 3.2.
Definition qgis.h:194
@ Raster
Raster layer.
Definition qgis.h:192
@ PointCloud
Point cloud layer. Added in QGIS 3.18.
Definition qgis.h:197
QFlags< LoadStyleFlag > LoadStyleFlags
Flags for loading layer styles.
Definition qgis.h:246
AutoRefreshMode
Map layer automatic refresh modes.
Definition qgis.h:2295
@ Disabled
Automatic refreshing is disabled.
Definition qgis.h:2296
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:42
Represents a coordinate reference system (CRS).
Contains information about the context in which a coordinate transform is executed.
Abstract base class for spatial data provider implementations.
Represents a single error message.
Definition qgserror.h:33
A container for error messages.
Definition qgserror.h:81
A structured metadata store for a map layer.
Models dependencies with or between map layers.
Base class for storage of map layer elevation properties.
An abstract interface for implementations of legends for one map layer.
Base class for utility classes that encapsulate information necessary for rendering of map layers.
Base class for storage of map layer selection properties.
Manages QGIS Server properties for a map layer.
Management of styles for use with one map layer.
Base class for storage of map layer temporal properties.
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:84
friend class TestQgsMapLayer
void readStyleManager(const QDomNode &layerNode)
Read style manager's configuration (if any). To be called by subclasses.
virtual bool writeSymbology(QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories) const =0
Write the style for the layer into the document provided.
Q_DECL_DEPRECATED QString legendUrlFormat() const
Returns the format for a URL based layer legend.
QgsRectangle wgs84Extent(bool forceRecalculate=false) const
Returns the WGS84 extent (EPSG:4326) of the layer according to ReadFlag::FlagTrustLayerMetadata.
virtual bool isSpatial() const
Returns true if the layer is considered a spatial layer, ie it has some form of geometry associated w...
QgsAbstract3DRenderer * renderer3D() const
Returns 3D renderer associated with the layer.
virtual bool isTemporary() const
Returns true if the layer is considered a temporary layer.
bool setId(const QString &id)
Sets the layer's id.
void dependenciesChanged()
Emitted when dependencies are changed.
void setError(const QgsError &error)
Sets error message.
bool isInScaleRange(double scale) const
Tests whether the layer should be visible at the specified scale.
void legendChanged()
Signal emitted when legend of the layer has changed.
void writeStyleManager(QDomNode &layerNode, QDomDocument &doc) const
Write style manager's configuration (if exists). To be called by subclasses.
QgsMapLayerLegend * legend() const
Can be nullptr.
QFlags< ReadFlag > ReadFlags
QFlags< LayerFlag > LayerFlags
Q_DECL_DEPRECATED void setAbstract(const QString &abstract)
Sets the abstract of the layer used by QGIS Server in GetCapabilities request.
void editingStopped()
Emitted when edited changes have been successfully written to the data provider.
virtual QgsAbstractProfileSource * profileSource()
Returns the layer's profile source if it has profile capabilities.
void recalculateExtents() const
This is used to send a request that any mapcanvas using this layer update its extents.
void metadataChanged()
Emitted when the layer's metadata is changed.
virtual QgsRectangle extent() const
Returns the extent of the layer.
QString source() const
Returns the source for the layer.
Q_DECL_DEPRECATED void setLegendUrl(const QString &legendUrl)
Sets the URL for the layer's legend.
void request3DUpdate()
Signal emitted when a layer requires an update in any 3D maps.
Q_INVOKABLE QVariant customProperty(const QString &value, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.
QgsError mError
Error.
int mBlockStyleChangedSignal
If non-zero, the styleChanged signal should not be emitted.
SaveStyleResult
Results of saving styles to database.
QString providerType() const
Returns the provider type (provider key) for this layer.
virtual void setExtent3D(const QgsBox3D &box)
Sets the extent.
Qgis::AutoRefreshMode autoRefreshMode() const
Returns the layer's automatic refresh mode.
void configChanged()
Emitted whenever the configuration is changed.
void autoRefreshIntervalChanged(int interval)
Emitted when the auto refresh interval changes.
T customFlagProperty(const QString &key, const T &defaultValue)
Returns the property value for a property based on a flag.
virtual QSet< QgsMapLayerDependency > dependencies() const
Gets the list of dependencies.
void setCustomProperties(const QgsObjectCustomProperties &properties)
Set custom properties for layer.
Q_DECL_DEPRECATED bool hasDependencyCycle(const QSet< QgsMapLayerDependency > &) const
Checks whether a new set of dependencies will introduce a cycle this method is now deprecated and alw...
virtual QString loadNamedStyle(const QString &theURI, bool &resultFlag, bool loadFromLocalDb, QgsMapLayer::StyleCategories categories=QgsMapLayer::AllStyleCategories, Qgis::LoadStyleFlags flags=Qgis::LoadStyleFlags())
Loads a named style from file/local db/datasource db.
virtual QString encodedSource(const QString &source, const QgsReadWriteContext &context) const
Called by writeLayerXML(), used by derived classes to encode provider's specific data source to proje...
void editingStarted()
Emitted when editing on this layer has started.
QgsCoordinateReferenceSystem crs3D
Definition qgsmaplayer.h:89
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:87
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:86
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:90
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:96
bool hasScaleBasedVisibility() const
Returns whether scale based visibility is enabled for the layer.
QgsMapLayerSelectionProperties * selectionProperties
Definition qgsmaplayer.h:95
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:94
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:92
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:85
QgsCoordinateReferenceSystem verticalCrs
Definition qgsmaplayer.h:88
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:93
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:109
Holds data provider key, description, and associated shared library file or function pointer informat...
A container for the context for various read/write operations on objects.
A rectangle specified with double values.
Contains information about the context of a rendering operation.
Holds SLD export options and other information related to SLD export of a QGIS layer style.
An interface for classes which can visit style entity (e.g.
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition qgis_sip.h:199
#define SIP_DEPRECATED
Definition qgis_sip.h:114
#define SIP_ENUM_BASETYPE(type)
Definition qgis_sip.h:275
#define SIP_SKIP
Definition qgis_sip.h:134
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_OUT
Definition qgis_sip.h:58
#define SIP_FACTORY
Definition qgis_sip.h:84
#define SIP_END
Definition qgis_sip.h:216
#define QgsDebugError(str)
Definition qgslogger.h:57
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.