QGIS API Documentation 3.30.0-'s-Hertogenbosch (f186b8efe0)
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;
55
56class QDomDocument;
57class QKeyEvent;
58class QPainter;
60
61/*
62 * Constants used to describe copy-paste MIME types
63 */
64#define QGSCLIPBOARD_MAPLAYER_MIME "application/qgis.maplayer"
65
66
72class CORE_EXPORT QgsMapLayer : public QObject
73{
74 Q_OBJECT
75
76 Q_PROPERTY( QString name READ name WRITE setName NOTIFY nameChanged )
77 Q_PROPERTY( int autoRefreshInterval READ autoRefreshInterval WRITE setAutoRefreshInterval NOTIFY autoRefreshIntervalChanged )
78 Q_PROPERTY( QgsLayerMetadata metadata READ metadata WRITE setMetadata NOTIFY metadataChanged )
79 Q_PROPERTY( QgsCoordinateReferenceSystem crs READ crs WRITE setCrs NOTIFY crsChanged )
80 Q_PROPERTY( Qgis::LayerType type READ type CONSTANT )
81 Q_PROPERTY( bool isValid READ isValid NOTIFY isValidChanged )
82 Q_PROPERTY( double opacity READ opacity WRITE setOpacity NOTIFY opacityChanged )
83 Q_PROPERTY( QString mapTipTemplate READ mapTipTemplate WRITE setMapTipTemplate NOTIFY mapTipTemplateChanged )
84
85#ifdef SIP_RUN
87 QgsMapLayer *layer = qobject_cast<QgsMapLayer *>( sipCpp );
88
89 sipType = 0;
90
91 if ( layer )
92 {
93 switch ( layer->type() )
94 {
95 case Qgis::LayerType::Vector:
96 sipType = sipType_QgsVectorLayer;
97 break;
98 case Qgis::LayerType::Raster:
99 sipType = sipType_QgsRasterLayer;
100 break;
101 case Qgis::LayerType::Plugin:
102 sipType = sipType_QgsPluginLayer;
103 break;
104 case Qgis::LayerType::Mesh:
105 sipType = sipType_QgsMeshLayer;
106 break;
107 case Qgis::LayerType::VectorTile:
108 sipType = sipType_QgsVectorTileLayer;
109 break;
110 case Qgis::LayerType::Annotation:
111 sipType = sipType_QgsAnnotationLayer;
112 break;
113 case Qgis::LayerType::PointCloud:
114 sipType = sipType_QgsPointCloudLayer;
115 break;
116 case Qgis::LayerType::Group:
117 sipType = sipType_QgsGroupLayer;
118 break;
119 default:
120 sipType = nullptr;
121 break;
122 }
123 }
124 SIP_END
125#endif
126
127 public:
128
134 {
135 Style = 0,
137 };
138
145 {
146 Identifiable = 1 << 0,
147 Removable = 1 << 1,
148 Searchable = 1 << 2,
149 Private = 1 << 3,
150 };
151 Q_ENUM( LayerFlag )
152 Q_DECLARE_FLAGS( LayerFlags, LayerFlag )
153 Q_FLAG( LayerFlags )
154
155
160 {
161 LayerConfiguration = 1 << 0,
162 Symbology = 1 << 1,
163 Symbology3D = 1 << 2,
164 Labeling = 1 << 3,
165 Fields = 1 << 4,
166 Forms = 1 << 5,
167 Actions = 1 << 6,
168 MapTips = 1 << 7,
169 Diagrams = 1 << 8,
170 AttributeTable = 1 << 9,
171 Rendering = 1 << 10,
172 CustomProperties = 1 << 11,
173 GeometryOptions = 1 << 12,
174 Relations = 1 << 13,
175 Temporal = 1 << 14,
176 Legend = 1 << 15,
177 Elevation = 1 << 16,
178 Notes = 1 << 17,
179 AllStyleCategories = LayerConfiguration | Symbology | Symbology3D | Labeling | Fields | Forms | Actions |
180 MapTips | Diagrams | AttributeTable | Rendering | CustomProperties | GeometryOptions | Relations | Temporal | Legend | Elevation | Notes,
181 };
182 Q_ENUM( StyleCategory )
183 Q_DECLARE_FLAGS( StyleCategories, StyleCategory )
184 Q_FLAG( StyleCategories )
185
186
192 QgsMapLayer( Qgis::LayerType type = Qgis::LayerType::Vector, const QString &name = QString(), const QString &source = QString() );
193
194 ~QgsMapLayer() override;
195
197 QgsMapLayer( QgsMapLayer const & ) = delete;
199 QgsMapLayer &operator=( QgsMapLayer const & ) = delete;
200
207 virtual QgsMapLayer *clone() const = 0;
208
212 Qgis::LayerType type() const;
213
224 QgsMapLayer::LayerFlags flags() const;
225
236 void setFlags( QgsMapLayer::LayerFlags flags );
237
247 virtual Qgis::MapLayerProperties properties() const;
248
254 static QString extensionPropertyType( PropertyType type );
255
257 QString id() const;
258
264 void setName( const QString &name );
265
270 QString name() const;
271
275 Q_INVOKABLE virtual QgsDataProvider *dataProvider();
276
281 virtual const QgsDataProvider *dataProvider() const SIP_SKIP;
282
288 void setShortName( const QString &shortName ) { mShortName = shortName; }
289
295 QString shortName() const;
296
302 void setTitle( const QString &title ) { mTitle = title; }
303
310 QString title() const { return mTitle; }
311
317 void setAbstract( const QString &abstract ) { mAbstract = abstract; }
318
325 QString abstract() const { return mAbstract; }
326
332 void setKeywordList( const QString &keywords ) { mKeywordList = keywords; }
333
340 QString keywordList() const { return mKeywordList; }
341
342 /* Layer dataUrl information */
343
350 void setDataUrl( const QString &dataUrl ) { mDataUrl = dataUrl; }
351
359 QString dataUrl() const { return mDataUrl; }
360
367 void setDataUrlFormat( const QString &dataUrlFormat ) { mDataUrlFormat = dataUrlFormat; }
368
376 QString dataUrlFormat() const { return mDataUrlFormat; }
377
378 /* Layer attribution information */
379
386 void setAttribution( const QString &attrib ) { mAttribution = attrib; }
387
395 QString attribution() const { return mAttribution; }
396
403 void setAttributionUrl( const QString &attribUrl ) { mAttributionUrl = attribUrl; }
404
412 QString attributionUrl() const { return mAttributionUrl; }
413
414 /* Layer metadataUrl information */
415
420 QgsMapLayerServerProperties *serverProperties() { return mServerProperties.get(); };
421
426 const QgsMapLayerServerProperties *serverProperties() const { return mServerProperties.get(); } SIP_SKIP;
427
436 Q_DECL_DEPRECATED void setMetadataUrl( const QString &metaUrl ) SIP_DEPRECATED;
437
447 Q_DECL_DEPRECATED QString metadataUrl() const SIP_DEPRECATED;
448
457 Q_DECL_DEPRECATED void setMetadataUrlType( const QString &metaUrlType ) SIP_DEPRECATED;
458
468 Q_DECL_DEPRECATED QString metadataUrlType() const SIP_DEPRECATED;
469
478 Q_DECL_DEPRECATED void setMetadataUrlFormat( const QString &metaUrlFormat ) SIP_DEPRECATED;
479
489 Q_DECL_DEPRECATED QString metadataUrlFormat() const SIP_DEPRECATED;
490
496 void setBlendMode( QPainter::CompositionMode blendMode );
497
502 QPainter::CompositionMode blendMode() const;
503
512 virtual void setOpacity( double opacity );
513
522 virtual double opacity() const;
523
525 bool readOnly() const { return isReadOnly(); }
526
530 Q_INVOKABLE virtual void reload() {}
531
537
539 virtual QgsRectangle extent() const;
540
549 QgsRectangle wgs84Extent( bool forceRecalculate = false ) const;
550
556 bool isValid() const;
557
564 QString publicSource() const;
565
571 QString source() const;
572
577 virtual QStringList subLayers() const;
578
583 virtual void setLayerOrder( const QStringList &layers );
584
590 virtual void setSubLayerVisibility( const QString &name, bool visible );
591
598 virtual bool supportsEditing() const;
599
601 virtual bool isEditable() const;
602
608 virtual bool isModified() const;
609
614 virtual bool isSpatial() const;
615
625 virtual bool isTemporary() const;
626
632 {
633 FlagDontResolveLayers = 1 << 0,
634 FlagTrustLayerMetadata = 1 << 1,
635 FlagReadExtentFromXml = 1 << 2,
636 FlagForceReadOnly = 1 << 3,
637 };
638 Q_DECLARE_FLAGS( ReadFlags, ReadFlag )
639
640
657 bool readLayerXml( const QDomElement &layerElement, QgsReadWriteContext &context, QgsMapLayer::ReadFlags flags = QgsMapLayer::ReadFlags() );
658
676 bool writeLayerXml( QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context ) const;
677
682 virtual void resolveReferences( QgsProject *project );
683
689 Q_INVOKABLE QStringList customPropertyKeys() const;
690
696 Q_INVOKABLE void setCustomProperty( const QString &key, const QVariant &value );
697
702 Q_INVOKABLE QVariant customProperty( const QString &value, const QVariant &defaultValue = QVariant() ) const;
703
708 void setCustomProperties( const QgsObjectCustomProperties &properties );
709
715 const QgsObjectCustomProperties &customProperties() const;
716
717#ifndef SIP_RUN
718
729 template <class T>
730 T customEnumProperty( const QString &key, const T &defaultValue )
731 {
732 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
733 Q_ASSERT( metaEnum.isValid() );
734 if ( !metaEnum.isValid() )
735 {
736 QgsDebugMsg( QStringLiteral( "Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
737 }
738
739 T v;
740 bool ok = false;
741
742 if ( metaEnum.isValid() )
743 {
744 // read as string
745 QByteArray ba = customProperty( key, metaEnum.valueToKey( static_cast<int>( defaultValue ) ) ).toString().toUtf8();
746 const char *vs = ba.data();
747 v = static_cast<T>( metaEnum.keyToValue( vs, &ok ) );
748 if ( ok )
749 return v;
750 }
751
752 // if failed, try to read as int (old behavior)
753 // this code shall be removed later
754 // then the method could be marked as const
755 v = static_cast<T>( customProperty( key, static_cast<int>( defaultValue ) ).toInt( &ok ) );
756 if ( metaEnum.isValid() )
757 {
758 if ( !ok || !metaEnum.valueToKey( static_cast<int>( v ) ) )
759 {
760 v = defaultValue;
761 }
762 else
763 {
764 // found property as an integer
765 // convert the property to the new form (string)
766 setCustomEnumProperty( key, v );
767 }
768 }
769
770 return v;
771 }
772
781 template <class T>
782 void setCustomEnumProperty( const QString &key, const T &value )
783 {
784 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
785 Q_ASSERT( metaEnum.isValid() );
786 if ( metaEnum.isValid() )
787 {
788 setCustomProperty( key, metaEnum.valueToKey( static_cast<int>( value ) ) );
789 }
790 else
791 {
792 QgsDebugMsg( QStringLiteral( "Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
793 }
794 }
795
807 template <class T>
808 T customFlagProperty( const QString &key, const T &defaultValue )
809 {
810 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
811 Q_ASSERT( metaEnum.isValid() );
812 if ( !metaEnum.isValid() )
813 {
814 QgsDebugMsg( QStringLiteral( "Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
815 }
816
817 T v = defaultValue;
818 bool ok = false;
819
820 if ( metaEnum.isValid() )
821 {
822 // read as string
823 QByteArray ba = customProperty( key, metaEnum.valueToKeys( defaultValue ) ).toString().toUtf8();
824 const char *vs = ba.data();
825 v = static_cast<T>( metaEnum.keysToValue( vs, &ok ) );
826 }
827 if ( !ok )
828 {
829 // if failed, try to read as int
830 const int intValue = customProperty( key, static_cast<int>( defaultValue ) ).toInt( &ok );
831 if ( metaEnum.isValid() )
832 {
833 if ( ok )
834 {
835 // check that the int value does correspond to a flag
836 // see https://stackoverflow.com/a/68495949/1548052
837 const QByteArray keys = metaEnum.valueToKeys( intValue );
838 const int intValueCheck = metaEnum.keysToValue( keys );
839 if ( intValue != intValueCheck )
840 {
841 v = defaultValue;
842 }
843 else
844 {
845 // found property as an integer
846 v = T( intValue );
847 // convert the property to the new form (string)
848 // this code could be removed
849 // then the method could be marked as const
850 setCustomFlagProperty( key, v );
851 }
852 }
853 else
854 {
855 v = defaultValue;
856 }
857 }
858 }
859
860 return v;
861 }
862
871 template <class T>
872 void setCustomFlagProperty( const QString &key, const T &value )
873 {
874 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
875 Q_ASSERT( metaEnum.isValid() );
876 if ( metaEnum.isValid() )
877 {
878 setCustomProperty( key, metaEnum.valueToKeys( value ) );
879 }
880 else
881 {
882 QgsDebugMsg( QStringLiteral( "Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
883 }
884 }
885#endif
886
887
892 void removeCustomProperty( const QString &key );
893
899 virtual QgsError error() const;
900
906
908 void setCrs( const QgsCoordinateReferenceSystem &srs, bool emitSignal = true );
909
915 QgsCoordinateTransformContext transformContext( ) const;
916
917
923 static QString formatLayerName( const QString &name );
924
932 virtual QString metadataUri() const;
933
940 void exportNamedMetadata( QDomDocument &doc, QString &errorMsg ) const;
941
951 virtual QString saveDefaultMetadata( bool &resultFlag SIP_OUT );
952
967 QString saveNamedMetadata( const QString &uri, bool &resultFlag );
968
983 virtual QString loadNamedMetadata( const QString &uri, bool &resultFlag SIP_OUT );
984
994 virtual QString loadDefaultMetadata( bool &resultFlag );
995
1004 bool loadNamedMetadataFromDatabase( const QString &db, const QString &uri, QString &qmd );
1005
1013 bool importNamedMetadata( QDomDocument &document, QString &errorMessage );
1014
1023 virtual QString styleURI() const;
1024
1034 virtual QString loadDefaultStyle( bool &resultFlag SIP_OUT );
1035
1051 virtual QString loadNamedStyle( const QString &uri, bool &resultFlag SIP_OUT, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories );
1052
1060 virtual bool loadNamedStyleFromDatabase( const QString &db, const QString &uri, QString &qml SIP_OUT );
1061
1071 virtual bool importNamedStyle( QDomDocument &doc, QString &errorMsg SIP_OUT,
1072 QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories );
1073
1082 virtual void exportNamedStyle( QDomDocument &doc, QString &errorMsg SIP_OUT, const QgsReadWriteContext &context = QgsReadWriteContext(),
1083 QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) const;
1084
1085
1093 virtual void exportSldStyle( QDomDocument &doc, QString &errorMsg ) const;
1094
1103 virtual void exportSldStyleV2( QDomDocument &doc, QString &errorMsg, const QgsSldExportContext &exportContext ) const;
1104
1116 virtual QString saveDefaultStyle( bool &resultFlag SIP_OUT, StyleCategories categories );
1117
1129 Q_DECL_DEPRECATED virtual QString saveDefaultStyle( bool &resultFlag SIP_OUT ) SIP_DEPRECATED;
1130
1146 virtual QString saveNamedStyle( const QString &uri, bool &resultFlag SIP_OUT, StyleCategories categories = AllStyleCategories );
1147
1157 virtual QString saveSldStyle( const QString &uri, bool &resultFlag ) const;
1158
1169 virtual QString saveSldStyleV2( bool &resultFlag SIP_OUT, const QgsSldExportContext &exportContext ) const;
1170
1179 virtual QString loadSldStyle( const QString &uri, bool &resultFlag );
1180
1181 virtual bool readSld( const QDomNode &node, QString &errorMessage )
1182 { Q_UNUSED( node ) errorMessage = QStringLiteral( "Layer type %1 not supported" ).arg( static_cast<int>( type() ) ); return false; }
1183
1184
1185
1194 virtual bool readSymbology( const QDomNode &node, QString &errorMessage,
1195 QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories ) = 0;
1196
1207 virtual bool readStyle( const QDomNode &node, QString &errorMessage,
1208 QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories );
1209
1220 virtual bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context,
1221 StyleCategories categories = AllStyleCategories ) const = 0;
1222
1235 virtual bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context,
1236 StyleCategories categories = AllStyleCategories ) const;
1237
1238
1253 void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, bool loadDefaultStyleFlag = false );
1254
1268 void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, bool loadDefaultStyleFlag = false );
1269
1284 void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags );
1285
1289 QString providerType() const;
1290
1292 QUndoStack *undoStack();
1293
1298 QUndoStack *undoStackStyles();
1299
1303 void setLegendUrl( const QString &legendUrl ) { mLegendUrl = legendUrl; }
1304
1308 QString legendUrl() const { return mLegendUrl; }
1309
1313 void setLegendUrlFormat( const QString &legendUrlFormat ) { mLegendUrlFormat = legendUrlFormat; }
1314
1318 QString legendUrlFormat() const { return mLegendUrlFormat; }
1319
1325 void setLegend( QgsMapLayerLegend *legend SIP_TRANSFER );
1326
1331 QgsMapLayerLegend *legend() const;
1332
1337 QgsMapLayerStyleManager *styleManager() const;
1338
1343 void setRenderer3D( QgsAbstract3DRenderer *renderer SIP_TRANSFER );
1344
1349 QgsAbstract3DRenderer *renderer3D() const;
1350
1360 bool isInScaleRange( double scale ) const;
1361
1372 double minimumScale() const;
1373
1384 double maximumScale() const;
1385
1394 bool hasScaleBasedVisibility() const;
1395
1402 bool hasAutoRefreshEnabled() const;
1403
1411 int autoRefreshInterval() const;
1412
1424 void setAutoRefreshInterval( int interval );
1425
1432 void setAutoRefreshEnabled( bool enabled );
1433
1440 virtual const QgsLayerMetadata &metadata() const;
1441
1448 virtual void setMetadata( const QgsLayerMetadata &metadata );
1449
1454 virtual QString htmlMetadata() const;
1455
1457 virtual QDateTime timestamp() const;
1458
1466 virtual QSet<QgsMapLayerDependency> dependencies() const;
1467
1473 QString refreshOnNotifyMessage() const { return mRefreshOnNofifyMessage; }
1474
1480 bool isRefreshOnNotifyEnabled() const { return mIsRefreshOnNofifyEnabled; }
1481
1490 QString originalXmlProperties() const;
1491
1499 void setOriginalXmlProperties( const QString &originalXmlProperties );
1500
1505 static QString generateId( const QString &layerName );
1506
1516 virtual bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
1517
1524
1531
1537 QString legendPlaceholderImage() const { return mLegendPlaceholderImage;}
1538
1544 void setLegendPlaceholderImage( const QString &imgPath ) { mLegendPlaceholderImage = imgPath; }
1545
1552 virtual bool hasMapTips() const;
1553
1562 QString mapTipTemplate() const;
1563
1572 void setMapTipTemplate( const QString &mapTipTemplate );
1573
1574 public slots:
1575
1585 void setMinimumScale( double scale );
1586
1596 void setMaximumScale( double scale );
1597
1605 void setScaleBasedVisibility( bool enabled );
1606
1615 void triggerRepaint( bool deferredUpdate = false );
1616
1623 void trigger3DUpdate();
1624
1629 void emitStyleChanged();
1630
1639 virtual bool setDependencies( const QSet<QgsMapLayerDependency> &layers );
1640
1646 void setRefreshOnNotifyEnabled( bool enabled );
1647
1655 void setRefreshOnNofifyMessage( const QString &message ) { mRefreshOnNofifyMessage = message; }
1656
1662 virtual void setTransformContext( const QgsCoordinateTransformContext &transformContext ) = 0;
1663
1664#ifdef SIP_RUN
1665 SIP_PYOBJECT __repr__();
1666 % MethodCode
1667 QString str = QStringLiteral( "<QgsMapLayer: '%1' (%2)>" ).arg( sipCpp->name(), sipCpp->dataProvider() ? sipCpp->dataProvider()->name() : QStringLiteral( "Invalid" ) );
1668 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
1669 % End
1670#endif
1671
1678 QgsProject *project() const;
1679
1680 signals:
1681
1689
1691 void statusChanged( const QString &status );
1692
1699
1702
1709 void repaintRequested( bool deferredUpdate = false );
1710
1713
1716
1718 void blendModeChanged( QPainter::CompositionMode blendMode );
1719
1728 void opacityChanged( double opacity );
1729
1735
1748
1754
1760
1767
1773
1778
1786
1792 void autoRefreshIntervalChanged( int interval );
1793
1801
1809
1818
1824 void styleLoaded( QgsMapLayer::StyleCategories categories );
1825
1832
1838 void customPropertyChanged( const QString &key );
1839
1845
1851
1857
1865
1866 private slots:
1867
1868 void onNotified( const QString &message );
1869
1885 virtual void setDataSourcePrivate( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags );
1886
1887 protected:
1888
1894 void clone( QgsMapLayer *layer ) const;
1895
1897 virtual void setExtent( const QgsRectangle &rect );
1898
1900 void setValid( bool valid );
1901
1906 virtual bool readXml( const QDomNode &layer_node, QgsReadWriteContext &context );
1907
1912 virtual bool writeXml( QDomNode &layer_node, QDomDocument &document, const QgsReadWriteContext &context ) const;
1913
1925 virtual QString encodedSource( const QString &source, const QgsReadWriteContext &context ) const;
1926
1939 virtual QString decodedSource( const QString &source, const QString &dataProvider, const QgsReadWriteContext &context ) const;
1940
1946 void readCustomProperties( const QDomNode &layerNode, const QString &keyStartsWith = QString() );
1947
1949 void writeCustomProperties( QDomNode &layerNode, QDomDocument &doc ) const;
1950
1952 void readStyleManager( const QDomNode &layerNode );
1954 void writeStyleManager( QDomNode &layerNode, QDomDocument &doc ) const;
1955
1960 void writeCommonStyle( QDomElement &layerElement, QDomDocument &document,
1961 const QgsReadWriteContext &context,
1962 StyleCategories categories = AllStyleCategories ) const;
1963
1968 void readCommonStyle( const QDomElement &layerElement, const QgsReadWriteContext &context,
1969 StyleCategories categories = AllStyleCategories );
1970
1972 void setProviderType( const QString &providerType );
1973
1974#ifndef SIP_RUN
1975#if 0
1977 void connectNotify( const char *signal ) override;
1978#endif
1979#endif
1980
1982 void appendError( const QgsErrorMessage &error ) { mError.append( error );}
1984 void setError( const QgsError &error ) { mError = error;}
1985
1992 void invalidateWgs84Extent();
1993
1995 bool mValid = false;
1996
1999
2001 QString mLayerName;
2002
2003 QString mShortName;
2004 QString mTitle;
2005
2007 QString mAbstract;
2009
2011 QString mDataUrl;
2013
2017
2019 QString mLegendUrl;
2021
2024
2026 QSet<QgsMapLayerDependency> mDependencies;
2027
2033 Q_DECL_DEPRECATED bool hasDependencyCycle( const QSet<QgsMapLayerDependency> & ) const {return false;}
2034
2035 bool mIsRefreshOnNofifyEnabled = false;
2037
2040
2041 //TODO QGIS 4 - move to readXml as a new argument (breaks API)
2042
2044 QgsMapLayer::ReadFlags mReadFlags = QgsMapLayer::ReadFlags();
2045
2051 bool mShouldValidateCrs = true;
2052
2058 double mLayerOpacity = 1.0;
2059
2065 int mBlockStyleChangedSignal = 0;
2066
2067#ifndef SIP_RUN
2068
2077 QString crsHtmlMetadata() const;
2078#endif
2079
2080#ifndef SIP_RUN
2081
2090 QString generalHtmlMetadata() const;
2091#endif
2092
2093 private:
2094
2095 virtual QString baseURI( PropertyType type ) const;
2096 QString saveNamedProperty( const QString &uri, QgsMapLayer::PropertyType type,
2097 bool &resultFlag, StyleCategories categories = AllStyleCategories );
2098 QString loadNamedProperty( const QString &uri, QgsMapLayer::PropertyType type,
2099 bool &resultFlag, StyleCategories categories = AllStyleCategories );
2100 bool loadNamedPropertyFromDatabase( const QString &db, const QString &uri, QString &xml, QgsMapLayer::PropertyType type );
2101
2102 // const method because extents are mutable
2103 void updateExtent( const QgsRectangle &extent ) const;
2104
2109 virtual bool isReadOnly() const;
2110
2116
2118 QString mID;
2119
2121 Qgis::LayerType mLayerType;
2122
2123 LayerFlags mFlags = LayerFlags( Identifiable | Removable | Searchable );
2124
2126 QPainter::CompositionMode mBlendMode = QPainter::CompositionMode_SourceOver;
2127
2129 QString mTag;
2130
2131 //set some generous defaults for scale based visibility
2132
2134 double mMinScale = 0;
2136 double mMaxScale = 100000000;
2138 bool mScaleBasedVisibility = false;
2139
2143 std::unique_ptr< QgsMapLayerServerProperties > mServerProperties;
2144
2146 QUndoStack *mUndoStack = nullptr;
2147
2148 QUndoStack *mUndoStackStyles = nullptr;
2149
2151 QgsObjectCustomProperties mCustomProperties;
2152
2154 QgsMapLayerLegend *mLegend = nullptr;
2155
2157 QgsMapLayerStyleManager *mStyleManager = nullptr;
2158
2160 QTimer *mRefreshTimer = nullptr;
2161
2162 QgsLayerMetadata mMetadata;
2163
2165 QgsAbstract3DRenderer *m3DRenderer = nullptr;
2166
2168 mutable QgsRectangle mExtent;
2169
2171 mutable QgsRectangle mWgs84Extent;
2172
2178 QString mOriginalXmlProperties;
2179
2181 bool mRepaintRequestedFired = false;
2182
2184 QString mLegendPlaceholderImage;
2185
2187 QString mMapTipTemplate;
2188
2189 friend class QgsVectorLayer;
2190 friend class TestQgsMapLayer;
2191};
2192
2194Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapLayer::LayerFlags )
2195Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapLayer::StyleCategories )
2196Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapLayer::ReadFlags )
2197
2198
2199#ifndef SIP_RUN
2200
2206typedef QPointer< QgsMapLayer > QgsWeakMapLayerPointer;
2207
2213typedef QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList;
2214#endif
2215
2216#endif
LayerType
Types of layers that can be added to a map.
Definition: qgis.h:115
Base class for all renderers that may to participate in 3D view.
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.
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.
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:73
QString mKeywordList
Definition: qgsmaplayer.h:2008
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.
Definition: qgsmaplayer.h:1318
void dependenciesChanged()
Emitted when dependencies are changed.
void setError(const QgsError &error)
Sets error message.
Definition: qgsmaplayer.h:1984
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.
Definition: qgsmaplayer.h:317
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.
Definition: qgsmaplayer.h:1303
void request3DUpdate()
Signal emitted when a layer requires an update in any 3D maps.
QgsError mError
Error.
Definition: qgsmaplayer.h:2023
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.
Definition: qgsmaplayer.h:808
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...
Definition: qgsmaplayer.h:2033
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.
Definition: qgsmaplayer.h:1537
QgsMapLayerServerProperties * serverProperties()
Returns QGIS Server Properties for the map layer.
Definition: qgsmaplayer.h:420
QString attribution() const
Returns the attribution of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:395
QString mRefreshOnNofifyMessage
Definition: qgsmaplayer.h:2036
QString mLegendUrl
WMS legend.
Definition: qgsmaplayer.h:2019
QString mLayerName
Name of the layer - used for display.
Definition: qgsmaplayer.h:2001
void setCustomFlagProperty(const QString &key, const T &value)
Set the value of a property based on a flag.
Definition: qgsmaplayer.h:872
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.
Definition: qgsmaplayer.h:403
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.
Definition: qgsmaplayer.h:325
QString dataUrlFormat() const
Returns the DataUrl format of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:376
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
Definition: qgsmaplayer.h:2004
void setDataUrl(const QString &dataUrl)
Sets the DataUrl of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:350
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.
Definition: qgsmaplayer.h:332
void setAttribution(const QString &attrib)
Sets the attribution of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:386
bool isRefreshOnNotifyEnabled() const
Returns true if the refresh on provider nofification is enabled.
Definition: qgsmaplayer.h:1480
QSet< QgsMapLayerDependency > mDependencies
List of layers that may modify this layer on modification.
Definition: qgsmaplayer.h:2026
void setDataUrlFormat(const QString &dataUrlFormat)
Sets the DataUrl format of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:367
QString mLegendUrlFormat
Definition: qgsmaplayer.h:2020
const QgsMapLayerServerProperties * serverProperties() const
Returns QGIS Server Properties const for the map layer.
Definition: qgsmaplayer.h:426
QString mProviderKey
Data provider key (name of the data provider)
Definition: qgsmaplayer.h:2039
void styleChanged()
Signal emitted whenever a change affects the layer's style.
void rendererChanged()
Signal emitted when renderer is changed.
QString title() const
Returns the title of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:310
void crsChanged()
Emit a signal that layer's CRS has been reset.
QString mAttributionUrl
Definition: qgsmaplayer.h:2016
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.
Definition: qgsmaplayer.h:359
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,...
Definition: qgsmaplayer.h:1655
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.
Definition: qgsmaplayer.h:1523
QString mShortName
Definition: qgsmaplayer.h:2003
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.
Definition: qgsmaplayer.h:145
void setLegendPlaceholderImage(const QString &imgPath)
Set placeholder image for legend.
Definition: qgsmaplayer.h:1544
void appendError(const QgsErrorMessage &error)
Add error message.
Definition: qgsmaplayer.h:1982
QString mDataSource
Data source description string, varies by layer type.
Definition: qgsmaplayer.h:1998
QString refreshOnNotifyMessage() const
Returns the message that should be notified by the provider to triggerRepaint.
Definition: qgsmaplayer.h:1473
virtual bool readSld(const QDomNode &node, QString &errorMessage)
Definition: qgsmaplayer.h:1181
ReadFlag
Flags which control project read behavior.
Definition: qgsmaplayer.h:632
QString attributionUrl() const
Returns the attribution URL of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:412
QString mAbstract
Description of the layer.
Definition: qgsmaplayer.h:2007
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.
Definition: qgsmaplayer.h:1308
QString mDataUrlFormat
Definition: qgsmaplayer.h:2012
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.
Definition: qgsmaplayer.h:1313
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.
Definition: qgsmaplayer.h:1530
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.
Definition: qgsmaplayer.h:2011
T customEnumProperty(const QString &key, const T &defaultValue)
Returns the property value for a property based on an enum.
Definition: qgsmaplayer.h:730
StyleCategory
Categories of style to distinguish appropriate sections for import/export.
Definition: qgsmaplayer.h:160
@ AllStyleCategories
Definition: qgsmaplayer.h:179
void layerModified()
Emitted when modifications has been done on layer.
virtual Q_INVOKABLE void reload()
Synchronises with changes in the datasource.
Definition: qgsmaplayer.h:530
QString mAttribution
Attribution of the layer.
Definition: qgsmaplayer.h:2015
void setCustomEnumProperty(const QString &key, const T &value)
Set the value of a property based on an enum.
Definition: qgsmaplayer.h:782
QString keywordList() const
Returns the keyword list of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:340
void setTitle(const QString &title)
Sets the title of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:302
PropertyType
Maplayer has a style and a metadata property.
Definition: qgsmaplayer.h:134
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:105
The class is used as a container of context for various read/write operations on other objects.
A rectangle specified with double values.
Definition: qgsrectangle.h:42
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:37
#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)
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsField::ConfigurationFlags) CORE_EXPORT QDataStream &operator<<(QDataStream &out
Writes the field to stream out. QGIS version compatibility is not guaranteed.
#define QgsDebugMsg(str)
Definition: qgslogger.h:38
QPointer< QgsMapLayer > QgsWeakMapLayerPointer
Weak pointer for QgsMapLayer.
Definition: qgsmaplayer.h:2206
QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList
A list of weak pointers to QgsMapLayers.
Definition: qgsmaplayer.h:2213
const QgsCoordinateReferenceSystem & crs
Setting options for creating vector data providers.