QGIS API Documentation 3.35.0-Master (6cf940c20d6)
Loading...
Searching...
No Matches
qgsmaplayer.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsmaplayer.h - description
3 -------------------
4 begin : Fri Jun 28 2002
5 copyright : (C) 2002 by Gary E.Sherman
6 email : sherman at mrcc.com
7***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#ifndef QGSMAPLAYER_H
19#define QGSMAPLAYER_H
20
21#include "qgis_core.h"
22#include <QDateTime>
23#include <QDomNode>
24#include <QImage>
25#include <QObject>
26#include <QPainter>
27#include <QUndoStack>
28#include <QVariant>
29#include <QIcon>
30#include <QSet>
31
32#include "qgis_sip.h"
33#include "qgserror.h"
35#include "qgsrectangle.h"
38#include "qgslayermetadata.h"
40#include "qgsreadwritecontext.h"
41#include "qgsdataprovider.h"
42#include "qgis.h"
43#include "qgslogger.h"
44
46class QgsDataProvider;
50class QgsProject;
56
57class QDomDocument;
58class QKeyEvent;
59class QPainter;
61class QgsBox3D;
62
63/*
64 * Constants used to describe copy-paste MIME types
65 */
66#define QGSCLIPBOARD_MAPLAYER_MIME "application/qgis.maplayer"
67
68
74class CORE_EXPORT QgsMapLayer : public QObject
75{
76 Q_OBJECT
77
78 Q_PROPERTY( QString name READ name WRITE setName NOTIFY nameChanged )
79 Q_PROPERTY( int autoRefreshInterval READ autoRefreshInterval WRITE setAutoRefreshInterval NOTIFY autoRefreshIntervalChanged )
80 Q_PROPERTY( QgsLayerMetadata metadata READ metadata WRITE setMetadata NOTIFY metadataChanged )
81 Q_PROPERTY( QgsCoordinateReferenceSystem crs READ crs WRITE setCrs NOTIFY crsChanged )
82 Q_PROPERTY( Qgis::LayerType type READ type CONSTANT )
83 Q_PROPERTY( bool isValid READ isValid NOTIFY isValidChanged )
84 Q_PROPERTY( double opacity READ opacity WRITE setOpacity NOTIFY opacityChanged )
85 Q_PROPERTY( QString mapTipTemplate READ mapTipTemplate WRITE setMapTipTemplate NOTIFY mapTipTemplateChanged )
86 Q_PROPERTY( bool mapTipsEnabled READ mapTipsEnabled WRITE setMapTipsEnabled NOTIFY mapTipsEnabledChanged )
87
88#ifdef SIP_RUN
90 QgsMapLayer *layer = qobject_cast<QgsMapLayer *>( sipCpp );
91
92 sipType = 0;
93
94 if ( layer )
95 {
96 switch ( layer->type() )
97 {
99 sipType = sipType_QgsVectorLayer;
100 break;
102 sipType = sipType_QgsRasterLayer;
103 break;
105 sipType = sipType_QgsPluginLayer;
106 break;
108 sipType = sipType_QgsMeshLayer;
109 break;
111 sipType = sipType_QgsVectorTileLayer;
112 break;
114 sipType = sipType_QgsAnnotationLayer;
115 break;
117 sipType = sipType_QgsPointCloudLayer;
118 break;
120 sipType = sipType_QgsGroupLayer;
121 break;
123 sipType = sipType_QgsTiledSceneLayer;
124 break;
125 default:
126 sipType = nullptr;
127 break;
128 }
129 }
130 SIP_END
131#endif
132
133 public:
134
140 {
141 Style = 0,
143 };
144
151 {
152 Identifiable = 1 << 0,
153 Removable = 1 << 1,
154 Searchable = 1 << 2,
155 Private = 1 << 3,
156 };
157 Q_ENUM( LayerFlag )
158 Q_DECLARE_FLAGS( LayerFlags, LayerFlag )
159 Q_FLAG( LayerFlags )
160
161
166 {
167 LayerConfiguration = 1 << 0,
168 Symbology = 1 << 1,
169 Symbology3D = 1 << 2,
170 Labeling = 1 << 3,
171 Fields = 1 << 4,
172 Forms = 1 << 5,
173 Actions = 1 << 6,
174 MapTips = 1 << 7,
175 Diagrams = 1 << 8,
176 AttributeTable = 1 << 9,
177 Rendering = 1 << 10,
178 CustomProperties = 1 << 11,
179 GeometryOptions = 1 << 12,
180 Relations = 1 << 13,
181 Temporal = 1 << 14,
182 Legend = 1 << 15,
183 Elevation = 1 << 16,
184 Notes = 1 << 17,
185 AllStyleCategories = LayerConfiguration | Symbology | Symbology3D | Labeling | Fields | Forms | Actions |
186 MapTips | Diagrams | AttributeTable | Rendering | CustomProperties | GeometryOptions | Relations | Temporal | Legend | Elevation | Notes,
187 };
188 Q_ENUM( StyleCategory )
189 Q_DECLARE_FLAGS( StyleCategories, StyleCategory )
190 Q_FLAG( StyleCategories )
191
192
198 QgsMapLayer( Qgis::LayerType type = Qgis::LayerType::Vector, const QString &name = QString(), const QString &source = QString() );
199
200 ~QgsMapLayer() override;
201
203 QgsMapLayer( QgsMapLayer const & ) = delete;
205 QgsMapLayer &operator=( QgsMapLayer const & ) = delete;
206
213 virtual QgsMapLayer *clone() const = 0;
214
218 Qgis::LayerType type() const;
219
230 QgsMapLayer::LayerFlags flags() const;
231
242 void setFlags( QgsMapLayer::LayerFlags flags );
243
253 virtual Qgis::MapLayerProperties properties() const;
254
260 static QString extensionPropertyType( PropertyType type );
261
263 QString id() const;
264
270 void setName( const QString &name );
271
276 QString name() const;
277
281 Q_INVOKABLE virtual QgsDataProvider *dataProvider();
282
287 virtual const QgsDataProvider *dataProvider() const SIP_SKIP;
288
294 void setShortName( const QString &shortName ) { mShortName = shortName; }
295
301 QString shortName() const;
302
308 void setTitle( const QString &title ) { mTitle = title; }
309
316 QString title() const { return mTitle; }
317
323 void setAbstract( const QString &abstract ) { mAbstract = abstract; }
324
331 QString abstract() const { return mAbstract; }
332
338 void setKeywordList( const QString &keywords ) { mKeywordList = keywords; }
339
346 QString keywordList() const { return mKeywordList; }
347
348 /* Layer dataUrl information */
349
356 void setDataUrl( const QString &dataUrl ) { mDataUrl = dataUrl; }
357
365 QString dataUrl() const { return mDataUrl; }
366
373 void setDataUrlFormat( const QString &dataUrlFormat ) { mDataUrlFormat = dataUrlFormat; }
374
382 QString dataUrlFormat() const { return mDataUrlFormat; }
383
384 /* Layer attribution information */
385
392 void setAttribution( const QString &attrib ) { mAttribution = attrib; }
393
401 QString attribution() const { return mAttribution; }
402
409 void setAttributionUrl( const QString &attribUrl ) { mAttributionUrl = attribUrl; }
410
418 QString attributionUrl() const { return mAttributionUrl; }
419
420 /* Layer metadataUrl information */
421
426 QgsMapLayerServerProperties *serverProperties() { return mServerProperties.get(); };
427
432 const QgsMapLayerServerProperties *serverProperties() const { return mServerProperties.get(); } SIP_SKIP;
433
442 Q_DECL_DEPRECATED void setMetadataUrl( const QString &metaUrl ) SIP_DEPRECATED;
443
453 Q_DECL_DEPRECATED QString metadataUrl() const SIP_DEPRECATED;
454
463 Q_DECL_DEPRECATED void setMetadataUrlType( const QString &metaUrlType ) SIP_DEPRECATED;
464
474 Q_DECL_DEPRECATED QString metadataUrlType() const SIP_DEPRECATED;
475
484 Q_DECL_DEPRECATED void setMetadataUrlFormat( const QString &metaUrlFormat ) SIP_DEPRECATED;
485
495 Q_DECL_DEPRECATED QString metadataUrlFormat() const SIP_DEPRECATED;
496
502 void setBlendMode( QPainter::CompositionMode blendMode );
503
508 QPainter::CompositionMode blendMode() const;
509
518 virtual void setOpacity( double opacity );
519
528 virtual double opacity() const;
529
531 bool readOnly() const { return isReadOnly(); }
532
536 Q_INVOKABLE virtual void reload() {}
537
543
545 virtual QgsRectangle extent() const;
546
551 virtual QgsBox3D extent3D() const;
552
561 QgsRectangle wgs84Extent( bool forceRecalculate = false ) const;
562
568 bool isValid() const;
569
577 QString publicSource( bool hidePassword = false ) const;
578
584 QString source() const;
585
590 virtual QStringList subLayers() const;
591
596 virtual void setLayerOrder( const QStringList &layers );
597
603 virtual void setSubLayerVisibility( const QString &name, bool visible );
604
611 virtual bool supportsEditing() const;
612
614 virtual bool isEditable() const;
615
621 virtual bool isModified() const;
622
627 virtual bool isSpatial() const;
628
638 virtual bool isTemporary() const;
639
645 {
646 FlagDontResolveLayers = 1 << 0,
647 FlagTrustLayerMetadata = 1 << 1,
648 FlagReadExtentFromXml = 1 << 2,
649 FlagForceReadOnly = 1 << 3,
650 };
651 Q_DECLARE_FLAGS( ReadFlags, ReadFlag )
652
653
671 bool readLayerXml( const QDomElement &layerElement, QgsReadWriteContext &context,
672 QgsMapLayer::ReadFlags flags = QgsMapLayer::ReadFlags(), QgsDataProvider *preloadedProvider SIP_TRANSFER = nullptr );
673
691 bool writeLayerXml( QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context ) const;
692
697 virtual void resolveReferences( QgsProject *project );
698
704 Q_INVOKABLE QStringList customPropertyKeys() const;
705
711 Q_INVOKABLE void setCustomProperty( const QString &key, const QVariant &value );
712
717 Q_INVOKABLE QVariant customProperty( const QString &value, const QVariant &defaultValue = QVariant() ) const;
718
723 void setCustomProperties( const QgsObjectCustomProperties &properties );
724
730 const QgsObjectCustomProperties &customProperties() const;
731
741 virtual int listStylesInDatabase( QStringList &ids SIP_OUT, QStringList &names SIP_OUT,
742 QStringList &descriptions SIP_OUT, QString &msgError SIP_OUT );
743
747 virtual QString getStyleFromDatabase( const QString &styleId, QString &msgError SIP_OUT );
748
756 virtual bool deleteStyleFromDatabase( const QString &styleId, QString &msgError SIP_OUT );
757
774 virtual void saveStyleToDatabase( const QString &name, const QString &description,
775 bool useAsDefault, const QString &uiFileContent,
776 QString &msgError SIP_OUT,
777 QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories );
778
786 virtual QString loadNamedStyle( const QString &theURI, bool &resultFlag SIP_OUT, bool loadFromLocalDb,
787 QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories );
788
789#ifndef SIP_RUN
790
801 template <class T>
802 T customEnumProperty( const QString &key, const T &defaultValue )
803 {
804 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
805 Q_ASSERT( metaEnum.isValid() );
806 if ( !metaEnum.isValid() )
807 {
808 QgsDebugError( QStringLiteral( "Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
809 }
810
811 T v;
812 bool ok = false;
813
814 if ( metaEnum.isValid() )
815 {
816 // read as string
817 QByteArray ba = customProperty( key, metaEnum.valueToKey( static_cast<int>( defaultValue ) ) ).toString().toUtf8();
818 const char *vs = ba.data();
819 v = static_cast<T>( metaEnum.keyToValue( vs, &ok ) );
820 if ( ok )
821 return v;
822 }
823
824 // if failed, try to read as int (old behavior)
825 // this code shall be removed later
826 // then the method could be marked as const
827 v = static_cast<T>( customProperty( key, static_cast<int>( defaultValue ) ).toInt( &ok ) );
828 if ( metaEnum.isValid() )
829 {
830 if ( !ok || !metaEnum.valueToKey( static_cast<int>( v ) ) )
831 {
832 v = defaultValue;
833 }
834 else
835 {
836 // found property as an integer
837 // convert the property to the new form (string)
838 setCustomEnumProperty( key, v );
839 }
840 }
841
842 return v;
843 }
844
853 template <class T>
854 void setCustomEnumProperty( const QString &key, const T &value )
855 {
856 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
857 Q_ASSERT( metaEnum.isValid() );
858 if ( metaEnum.isValid() )
859 {
860 setCustomProperty( key, metaEnum.valueToKey( static_cast<int>( value ) ) );
861 }
862 else
863 {
864 QgsDebugError( QStringLiteral( "Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
865 }
866 }
867
879 template <class T>
880 T customFlagProperty( const QString &key, const T &defaultValue )
881 {
882 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
883 Q_ASSERT( metaEnum.isValid() );
884 if ( !metaEnum.isValid() )
885 {
886 QgsDebugError( QStringLiteral( "Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
887 }
888
889 T v = defaultValue;
890 bool ok = false;
891
892 if ( metaEnum.isValid() )
893 {
894 // read as string
895 QByteArray ba = customProperty( key, metaEnum.valueToKeys( defaultValue ) ).toString().toUtf8();
896 const char *vs = ba.data();
897 v = static_cast<T>( metaEnum.keysToValue( vs, &ok ) );
898 }
899 if ( !ok )
900 {
901 // if failed, try to read as int
902 const int intValue = customProperty( key, static_cast<int>( defaultValue ) ).toInt( &ok );
903 if ( metaEnum.isValid() )
904 {
905 if ( ok )
906 {
907 // check that the int value does correspond to a flag
908 // see https://stackoverflow.com/a/68495949/1548052
909 const QByteArray keys = metaEnum.valueToKeys( intValue );
910 const int intValueCheck = metaEnum.keysToValue( keys );
911 if ( intValue != intValueCheck )
912 {
913 v = defaultValue;
914 }
915 else
916 {
917 // found property as an integer
918 v = T( intValue );
919 // convert the property to the new form (string)
920 // this code could be removed
921 // then the method could be marked as const
922 setCustomFlagProperty( key, v );
923 }
924 }
925 else
926 {
927 v = defaultValue;
928 }
929 }
930 }
931
932 return v;
933 }
934
943 template <class T>
944 void setCustomFlagProperty( const QString &key, const T &value )
945 {
946 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
947 Q_ASSERT( metaEnum.isValid() );
948 if ( metaEnum.isValid() )
949 {
950 setCustomProperty( key, metaEnum.valueToKeys( value ) );
951 }
952 else
953 {
954 QgsDebugError( QStringLiteral( "Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
955 }
956 }
957#endif
958
959
964 void removeCustomProperty( const QString &key );
965
971 virtual QgsError error() const;
972
978
980 void setCrs( const QgsCoordinateReferenceSystem &srs, bool emitSignal = true );
981
987 QgsCoordinateTransformContext transformContext( ) const;
988
989
995 static QString formatLayerName( const QString &name );
996
1004 virtual QString metadataUri() const;
1005
1012 void exportNamedMetadata( QDomDocument &doc, QString &errorMsg ) const;
1013
1023 virtual QString saveDefaultMetadata( bool &resultFlag SIP_OUT );
1024
1039 QString saveNamedMetadata( const QString &uri, bool &resultFlag );
1040
1055 virtual QString loadNamedMetadata( const QString &uri, bool &resultFlag SIP_OUT );
1056
1066 virtual QString loadDefaultMetadata( bool &resultFlag );
1067
1076 bool loadNamedMetadataFromDatabase( const QString &db, const QString &uri, QString &qmd );
1077
1085 bool importNamedMetadata( QDomDocument &document, QString &errorMessage );
1086
1095 virtual QString styleURI() const;
1096
1106 virtual QString loadDefaultStyle( bool &resultFlag SIP_OUT );
1107
1123 virtual QString loadNamedStyle( const QString &uri, bool &resultFlag SIP_OUT, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories );
1124
1132 virtual bool loadNamedStyleFromDatabase( const QString &db, const QString &uri, QString &qml SIP_OUT );
1133
1143 virtual bool importNamedStyle( QDomDocument &doc, QString &errorMsg SIP_OUT,
1144 QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories );
1145
1154 virtual void exportNamedStyle( QDomDocument &doc, QString &errorMsg SIP_OUT, const QgsReadWriteContext &context = QgsReadWriteContext(),
1155 QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) const;
1156
1157
1165 virtual void exportSldStyle( QDomDocument &doc, QString &errorMsg ) const;
1166
1175 virtual void exportSldStyleV2( QDomDocument &doc, QString &errorMsg, const QgsSldExportContext &exportContext ) const;
1176
1188 virtual QString saveDefaultStyle( bool &resultFlag SIP_OUT, StyleCategories categories );
1189
1201 Q_DECL_DEPRECATED virtual QString saveDefaultStyle( bool &resultFlag SIP_OUT ) SIP_DEPRECATED;
1202
1218 virtual QString saveNamedStyle( const QString &uri, bool &resultFlag SIP_OUT, StyleCategories categories = AllStyleCategories );
1219
1229 virtual QString saveSldStyle( const QString &uri, bool &resultFlag ) const;
1230
1241 virtual QString saveSldStyleV2( bool &resultFlag SIP_OUT, const QgsSldExportContext &exportContext ) const;
1242
1251 virtual QString loadSldStyle( const QString &uri, bool &resultFlag );
1252
1253 virtual bool readSld( const QDomNode &node, QString &errorMessage )
1254 { Q_UNUSED( node ) errorMessage = QStringLiteral( "Layer type %1 not supported" ).arg( static_cast<int>( type() ) ); return false; }
1255
1256
1257
1266 virtual bool readSymbology( const QDomNode &node, QString &errorMessage,
1267 QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories ) = 0;
1268
1279 virtual bool readStyle( const QDomNode &node, QString &errorMessage,
1280 QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories );
1281
1292 virtual bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context,
1293 StyleCategories categories = AllStyleCategories ) const = 0;
1294
1307 virtual bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context,
1308 StyleCategories categories = AllStyleCategories ) const;
1309
1310
1340 void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, bool loadDefaultStyleFlag = false );
1341
1371 void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, bool loadDefaultStyleFlag = false );
1372
1402 void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags );
1403
1407 QString providerType() const;
1408
1410 QUndoStack *undoStack();
1411
1416 QUndoStack *undoStackStyles();
1417
1421 void setLegendUrl( const QString &legendUrl ) { mLegendUrl = legendUrl; }
1422
1426 QString legendUrl() const { return mLegendUrl; }
1427
1431 void setLegendUrlFormat( const QString &legendUrlFormat ) { mLegendUrlFormat = legendUrlFormat; }
1432
1436 QString legendUrlFormat() const { return mLegendUrlFormat; }
1437
1443 void setLegend( QgsMapLayerLegend *legend SIP_TRANSFER );
1444
1449 QgsMapLayerLegend *legend() const;
1450
1455 QgsMapLayerStyleManager *styleManager() const;
1456
1461 void setRenderer3D( QgsAbstract3DRenderer *renderer SIP_TRANSFER );
1462
1467 QgsAbstract3DRenderer *renderer3D() const;
1468
1478 bool isInScaleRange( double scale ) const;
1479
1490 double minimumScale() const;
1491
1502 double maximumScale() const;
1503
1512 bool hasScaleBasedVisibility() const;
1513
1520 Q_DECL_DEPRECATED bool hasAutoRefreshEnabled() const SIP_DEPRECATED;
1521
1528 Qgis::AutoRefreshMode autoRefreshMode() const;
1529
1537 int autoRefreshInterval() const;
1538
1550 void setAutoRefreshInterval( int interval );
1551
1558 Q_DECL_DEPRECATED void setAutoRefreshEnabled( bool enabled ) SIP_DEPRECATED;
1559
1566 void setAutoRefreshMode( Qgis::AutoRefreshMode mode );
1567
1574 virtual const QgsLayerMetadata &metadata() const;
1575
1582 virtual void setMetadata( const QgsLayerMetadata &metadata );
1583
1588 virtual QString htmlMetadata() const;
1589
1591 virtual QDateTime timestamp() const;
1592
1600 virtual QSet<QgsMapLayerDependency> dependencies() const;
1601
1607 QString refreshOnNotifyMessage() const { return mRefreshOnNofifyMessage; }
1608
1614 bool isRefreshOnNotifyEnabled() const { return mIsRefreshOnNofifyEnabled; }
1615
1624 QString originalXmlProperties() const;
1625
1633 void setOriginalXmlProperties( const QString &originalXmlProperties );
1634
1639 static QString generateId( const QString &layerName );
1640
1650 virtual bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
1651
1658
1665
1672
1678 QString legendPlaceholderImage() const { return mLegendPlaceholderImage;}
1679
1685 void setLegendPlaceholderImage( const QString &imgPath ) { mLegendPlaceholderImage = imgPath; }
1686
1693 virtual bool hasMapTips() const;
1694
1703 QString mapTipTemplate() const;
1704
1713 void setMapTipTemplate( const QString &mapTipTemplate );
1714
1721 void setMapTipsEnabled( bool enabled );
1722
1727 bool mapTipsEnabled() const;
1728
1736 static QgsDataProvider::ReadFlags providerReadFlags( const QDomNode &layerNode, QgsMapLayer::ReadFlags layerReadFlags );
1737
1738 public slots:
1739
1749 void setMinimumScale( double scale );
1750
1760 void setMaximumScale( double scale );
1761
1769 void setScaleBasedVisibility( bool enabled );
1770
1779 void triggerRepaint( bool deferredUpdate = false );
1780
1787 void trigger3DUpdate();
1788
1793 void emitStyleChanged();
1794
1803 virtual bool setDependencies( const QSet<QgsMapLayerDependency> &layers );
1804
1810 void setRefreshOnNotifyEnabled( bool enabled );
1811
1819 void setRefreshOnNofifyMessage( const QString &message ) { mRefreshOnNofifyMessage = message; }
1820
1826 virtual void setTransformContext( const QgsCoordinateTransformContext &transformContext ) = 0;
1827
1828#ifdef SIP_RUN
1829 SIP_PYOBJECT __repr__();
1830 % MethodCode
1831 QString str = QStringLiteral( "<QgsMapLayer: '%1' (%2)>" ).arg( sipCpp->name(), sipCpp->dataProvider() ? sipCpp->dataProvider()->name() : QStringLiteral( "Invalid" ) );
1832 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
1833 % End
1834#endif
1835
1842 QgsProject *project() const;
1843
1844 signals:
1845
1853
1855 void statusChanged( const QString &status );
1856
1863
1866
1873 void repaintRequested( bool deferredUpdate = false );
1874
1877
1880
1882 void blendModeChanged( QPainter::CompositionMode blendMode );
1883
1892 void opacityChanged( double opacity );
1893
1899
1912
1918
1924
1931
1937
1942
1950
1956 void autoRefreshIntervalChanged( int interval );
1957
1965
1973
1982
1988 void styleLoaded( QgsMapLayer::StyleCategories categories );
1989
1996
2002 void customPropertyChanged( const QString &key );
2003
2009
2015
2021
2029
2037
2038 private slots:
2039
2040 void onNotified( const QString &message );
2041
2057 virtual void setDataSourcePrivate( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags );
2058
2059 protected:
2060
2066 void clone( QgsMapLayer *layer ) const;
2067
2069 virtual void setExtent( const QgsRectangle &rect );
2070
2075 virtual void setExtent3D( const QgsBox3D &box );
2076
2078 void setValid( bool valid );
2079
2084 virtual bool readXml( const QDomNode &layer_node, QgsReadWriteContext &context );
2085
2090 virtual bool writeXml( QDomNode &layer_node, QDomDocument &document, const QgsReadWriteContext &context ) const;
2091
2103 virtual QString encodedSource( const QString &source, const QgsReadWriteContext &context ) const;
2104
2117 virtual QString decodedSource( const QString &source, const QString &dataProvider, const QgsReadWriteContext &context ) const;
2118
2124 void readCustomProperties( const QDomNode &layerNode, const QString &keyStartsWith = QString() );
2125
2127 void writeCustomProperties( QDomNode &layerNode, QDomDocument &doc ) const;
2128
2130 void readStyleManager( const QDomNode &layerNode );
2132 void writeStyleManager( QDomNode &layerNode, QDomDocument &doc ) const;
2133
2138 void writeCommonStyle( QDomElement &layerElement, QDomDocument &document,
2139 const QgsReadWriteContext &context,
2140 StyleCategories categories = AllStyleCategories ) const;
2141
2146 void readCommonStyle( const QDomElement &layerElement, const QgsReadWriteContext &context,
2147 StyleCategories categories = AllStyleCategories );
2148
2150 void setProviderType( const QString &providerType );
2151
2152#ifndef SIP_RUN
2153#if 0
2155 void connectNotify( const char *signal ) override;
2156#endif
2157#endif
2158
2160 void appendError( const QgsErrorMessage &error ) { mError.append( error );}
2162 void setError( const QgsError &error ) { mError = error;}
2163
2170 void invalidateWgs84Extent();
2171
2173 bool mValid = false;
2174
2177
2179 QString mLayerName;
2180
2181 QString mShortName;
2182 QString mTitle;
2183
2185 QString mAbstract;
2187
2189 QString mDataUrl;
2191
2195
2197 QString mLegendUrl;
2199
2202
2204 QSet<QgsMapLayerDependency> mDependencies;
2205
2211 Q_DECL_DEPRECATED bool hasDependencyCycle( const QSet<QgsMapLayerDependency> & ) const {return false;}
2212
2213 bool mIsRefreshOnNofifyEnabled = false;
2215
2218
2219 //TODO QGIS 4 - move to readXml as a new argument (breaks API)
2220
2222 QgsMapLayer::ReadFlags mReadFlags = QgsMapLayer::ReadFlags();
2223
2229 bool mShouldValidateCrs = true;
2230
2236 double mLayerOpacity = 1.0;
2237
2243 int mBlockStyleChangedSignal = 0;
2244
2245#ifndef SIP_RUN
2246
2255 QString crsHtmlMetadata() const;
2256#endif
2257
2258#ifndef SIP_RUN
2259
2268 QString generalHtmlMetadata() const;
2269#endif
2270
2271#ifndef SIP_RUN
2272
2280 std::unique_ptr<QgsDataProvider> mPreloadedProvider;
2281#endif
2282
2283 private:
2284
2285 virtual QString baseURI( PropertyType type ) const;
2286 QString saveNamedProperty( const QString &uri, QgsMapLayer::PropertyType type,
2287 bool &resultFlag, StyleCategories categories = AllStyleCategories );
2288 QString loadNamedProperty( const QString &uri, QgsMapLayer::PropertyType type,
2289 bool &resultFlag, StyleCategories categories = AllStyleCategories );
2290 bool loadNamedPropertyFromDatabase( const QString &db, const QString &uri, QString &xml, QgsMapLayer::PropertyType type );
2291
2292 // const method because extents are mutable
2293 void updateExtent( const QgsRectangle &extent ) const;
2294 void updateExtent( const QgsBox3D &extent ) const;
2295
2300 virtual bool isReadOnly() const;
2301
2307
2309 QString mID;
2310
2312 Qgis::LayerType mLayerType;
2313
2314 LayerFlags mFlags = LayerFlags( Identifiable | Removable | Searchable );
2315
2317 QPainter::CompositionMode mBlendMode = QPainter::CompositionMode_SourceOver;
2318
2320 QString mTag;
2321
2322 //set some generous defaults for scale based visibility
2323
2325 double mMinScale = 0;
2327 double mMaxScale = 100000000;
2329 bool mScaleBasedVisibility = false;
2330
2334 std::unique_ptr< QgsMapLayerServerProperties > mServerProperties;
2335
2337 QUndoStack *mUndoStack = nullptr;
2338
2339 QUndoStack *mUndoStackStyles = nullptr;
2340
2342 QgsObjectCustomProperties mCustomProperties;
2343
2345 QgsMapLayerLegend *mLegend = nullptr;
2346
2348 QgsMapLayerStyleManager *mStyleManager = nullptr;
2349
2351
2353 QTimer *mRefreshTimer = nullptr;
2354
2355 QgsLayerMetadata mMetadata;
2356
2358 QgsAbstract3DRenderer *m3DRenderer = nullptr;
2359
2361 mutable QgsBox3D mExtent;
2362
2364 mutable QgsRectangle mWgs84Extent;
2365
2371 QString mOriginalXmlProperties;
2372
2374 bool mRepaintRequestedFired = false;
2375
2377 QString mLegendPlaceholderImage;
2378
2380 QString mMapTipTemplate;
2381
2383 bool mMapTipsEnabled = true;
2384
2385 friend class QgsVectorLayer;
2386 friend class TestQgsMapLayer;
2387};
2388
2390Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapLayer::LayerFlags )
2391Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapLayer::StyleCategories )
2392Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapLayer::ReadFlags )
2393
2394
2395#ifndef SIP_RUN
2396
2402typedef QPointer< QgsMapLayer > QgsWeakMapLayerPointer;
2403
2409typedef QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList;
2410#endif
2411
2412#endif
The Qgis class provides global constants for use throughout the application.
Definition qgis.h:54
LayerType
Types of layers that can be added to a map.
Definition qgis.h:114
@ Group
Composite group layer. Added in QGIS 3.24.
@ Plugin
Plugin based layer.
@ TiledScene
Tiled scene layer. Added in QGIS 3.34.
@ Annotation
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
@ Vector
Vector layer.
@ VectorTile
Vector tile layer. Added in QGIS 3.14.
@ Mesh
Mesh layer. Added in QGIS 3.2.
@ Raster
Raster layer.
@ PointCloud
Point cloud layer. Added in QGIS 3.18.
AutoRefreshMode
Map layer properties.
Definition qgis.h:1696
@ Disabled
Automatic refreshing is disabled.
Base class for all renderers that may to participate in 3D view.
A 3-dimensional box composed of x, y, z coordinates.
Definition qgsbox3d.h:44
This class represents a coordinate reference system (CRS).
Contains information about the context in which a coordinate transform is executed.
Abstract base class for spatial data provider implementations.
QgsErrorMessage represents single error message.
Definition qgserror.h:33
QgsError is container for error messages (report).
Definition qgserror.h:81
A structured metadata store for a map layer.
This class models dependencies with or between map layers.
Base class for storage of map layer elevation properties.
The QgsMapLayerLegend class is abstract interface for implementations of legends for one map layer.
Base class for utility classes that encapsulate information necessary for rendering of map layers.
Base class for storage of map layer selection properties.
Manages QGIS Server properties for a map layer.
Management of styles for use with one map layer.
Base class for storage of map layer temporal properties.
Base class for all map layer types.
Definition qgsmaplayer.h:75
QString mKeywordList
virtual bool writeSymbology(QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories) const =0
Write the style for the layer into the document provided.
QString legendUrlFormat() const
Returns the format for a URL based layer legend.
void dependenciesChanged()
Emitted when dependencies are changed.
void setError(const QgsError &error)
Sets error message.
void legendChanged()
Signal emitted when legend of the layer has changed.
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.
void recalculateExtents() const
This is used to send a request that any mapcanvas using this layer update its extents.
void metadataChanged()
Emitted when the layer's metadata is changed.
void setLegendUrl(const QString &legendUrl)
Sets the URL for the layer's legend.
void request3DUpdate()
Signal emitted when a layer requires an update in any 3D maps.
QgsError mError
Error.
void configChanged()
Emitted whenever the configuration is changed.
void autoRefreshIntervalChanged(int interval)
Emitted when the auto refresh interval changes.
T customFlagProperty(const QString &key, const T &defaultValue)
Returns the property value for a property based on a flag.
Q_DECL_DEPRECATED bool hasDependencyCycle(const QSet< QgsMapLayerDependency > &) const
Checks whether a new set of dependencies will introduce a cycle this method is now deprecated and alw...
void editingStarted()
Emitted when editing on this layer has started.
void isValidChanged()
Emitted when the validity of this layer changed.
QString legendPlaceholderImage() const
Returns path to the placeholder image or an empty string if a generated legend is shown.
QgsMapLayerServerProperties * serverProperties()
Returns QGIS Server Properties for the map layer.
QString attribution() const
Returns the attribution of the layer used by QGIS Server in GetCapabilities request.
QString mRefreshOnNofifyMessage
QString mLegendUrl
WMS legend.
QString mLayerName
Name of the layer - used for display.
void setCustomFlagProperty(const QString &key, const T &value)
Set the value of a property based on a flag.
void mapTipTemplateChanged()
Emitted when the map tip template changes.
void setAttributionUrl(const QString &attribUrl)
Sets the attribution URL of the layer used by QGIS Server in GetCapabilities request.
void renderer3DChanged()
Signal emitted when 3D renderer associated with the layer has changed.
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.
QString dataUrlFormat() const
Returns the DataUrl format of the layer used by QGIS Server in GetCapabilities request.
void statusChanged(const QString &status)
Emit a signal with status (e.g. to be caught by QgisApp and display a msg on status bar)
QString mTitle
void setDataUrl(const QString &dataUrl)
Sets the DataUrl of the layer used by QGIS Server in GetCapabilities request.
QgsMapLayer(QgsMapLayer const &)=delete
QgsMapLayer cannot be copied.
void setKeywordList(const QString &keywords)
Sets the keyword list of the layer used by QGIS Server in GetCapabilities request.
void setAttribution(const QString &attrib)
Sets the attribution of the layer used by QGIS Server in GetCapabilities request.
bool isRefreshOnNotifyEnabled() const
Returns true if the refresh on provider nofification is enabled.
QSet< QgsMapLayerDependency > mDependencies
List of layers that may modify this layer on modification.
void setDataUrlFormat(const QString &dataUrlFormat)
Sets the DataUrl format of the layer used by QGIS Server in GetCapabilities request.
QString mLegendUrlFormat
const QgsMapLayerServerProperties * serverProperties() const
Returns QGIS Server Properties const for the map layer.
QString mProviderKey
Data provider key (name of the data provider)
void styleChanged()
Signal emitted whenever a change affects the layer's style.
std::unique_ptr< QgsDataProvider > mPreloadedProvider
Optionally used when loading a project, it is released when the layer is effectively created.
void rendererChanged()
Signal emitted when renderer is changed.
QString title() const
Returns the title of the layer used by QGIS Server in GetCapabilities request.
void crsChanged()
Emit a signal that layer's CRS has been reset.
QString mAttributionUrl
void dataSourceChanged()
Emitted whenever the layer's data source has been changed.
QString dataUrl() const
Returns the DataUrl of the layer used by QGIS Server in GetCapabilities request.
QgsMapLayer & operator=(QgsMapLayer const &)=delete
QgsMapLayer cannot be copied.
void setRefreshOnNofifyMessage(const QString &message)
Set the notification message that triggers repaint If refresh on notification is enabled,...
void opacityChanged(double opacity)
Emitted when the layer's opacity is changed, where opacity is a value between 0 (transparent) and 1 (...
void styleLoaded(QgsMapLayer::StyleCategories categories)
Emitted when a style has been loaded.
virtual QgsMapLayerTemporalProperties * temporalProperties()
Returns the layer's temporal properties.
QString mShortName
void dataChanged()
Data of layer changed.
virtual QgsMapLayerRenderer * createMapRenderer(QgsRenderContext &rendererContext)=0
Returns new instance of QgsMapLayerRenderer that will be used for rendering of given context.
void willBeDeleted()
Emitted in the destructor when the layer is about to be deleted, but it is still in a perfectly valid...
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()
virtual bool readSymbology(const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context, StyleCategories categories=AllStyleCategories)=0
Read the symbology for the current layer from the DOM node supplied.
LayerFlag
Flags for the map layer.
void setLegendPlaceholderImage(const QString &imgPath)
Set placeholder image for legend.
void appendError(const QgsErrorMessage &error)
Add error message.
QString mDataSource
Data source description string, varies by layer type.
virtual bool readSld(const QDomNode &node, QString &errorMessage)
ReadFlag
Flags which control project read behavior.
QString attributionUrl() const
Returns the attribution URL of the layer used by QGIS Server in GetCapabilities request.
QString mAbstract
Description of the layer.
void customPropertyChanged(const QString &key)
Emitted when a custom property of the layer has been changed or removed.
QString legendUrl() const
Returns the URL for the layer's legend.
QString mDataUrlFormat
void flagsChanged()
Emitted when layer's flags have been modified.
void repaintRequested(bool deferredUpdate=false)
By emitting this signal the layer tells that either appearance or content have been changed and any v...
void setLegendUrlFormat(const QString &legendUrlFormat)
Sets the format for a URL based layer legend.
void beforeResolveReferences(QgsProject *project)
Emitted when all layers are loaded and references can be resolved, just before the references of this...
virtual QgsMapLayerElevationProperties * elevationProperties()
Returns the layer's elevation properties.
virtual void setTransformContext(const QgsCoordinateTransformContext &transformContext)=0
Sets the coordinate transform context to transformContext.
void nameChanged()
Emitted when the name has been changed.
QString mDataUrl
DataUrl of the layer.
T customEnumProperty(const QString &key, const T &defaultValue)
Returns the property value for a property based on an enum.
StyleCategory
Categories of style to distinguish appropriate sections for import/export.
void layerModified()
Emitted when modifications has been done on layer.
virtual Q_INVOKABLE void reload()
Synchronises with changes in the datasource.
void mapTipsEnabledChanged()
Emitted when map tips are enabled or disabled for the layer.
QString mAttribution
Attribution of the layer.
void setCustomEnumProperty(const QString &key, const T &value)
Set the value of a property based on an enum.
QString keywordList() const
Returns the keyword list of the layer used by QGIS Server in GetCapabilities request.
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.
Simple key-value store (keys = strings, values = variants) that supports loading/saving to/from XML i...
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:107
The class is used as a container of context for various read/write operations on other objects.
A rectangle specified with double values.
Contains information about the context of a rendering operation.
The QgsSldExportContext class holds SLD export options and other information related to SLD export of...
An interface for classes which can visit style entity (e.g.
Represents a vector layer which manages a vector based data sets.
#define str(x)
Definition qgis.cpp:38
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition qgis_sip.h:186
#define SIP_DEPRECATED
Definition qgis_sip.h:106
#define SIP_SKIP
Definition qgis_sip.h:126
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_OUT
Definition qgis_sip.h:58
#define SIP_FACTORY
Definition qgis_sip.h:76
#define SIP_END
Definition qgis_sip.h:203
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)
#define QgsDebugError(str)
Definition qgslogger.h:38
QPointer< QgsMapLayer > QgsWeakMapLayerPointer
Weak pointer for QgsMapLayer.
QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList
A list of weak pointers to QgsMapLayers.
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsTextRendererUtils::CurvedTextFlags)
const QgsCoordinateReferenceSystem & crs
Setting options for creating vector data providers.