QGIS API Documentation 3.32.0-Lima (311a8cb8a6)
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 Q_PROPERTY( bool mapTipsEnabled READ mapTipsEnabled WRITE setMapTipsEnabled NOTIFY mapTipsEnabledChanged )
85
86#ifdef SIP_RUN
88 QgsMapLayer *layer = qobject_cast<QgsMapLayer *>( sipCpp );
89
90 sipType = 0;
91
92 if ( layer )
93 {
94 switch ( layer->type() )
95 {
96 case Qgis::LayerType::Vector:
97 sipType = sipType_QgsVectorLayer;
98 break;
99 case Qgis::LayerType::Raster:
100 sipType = sipType_QgsRasterLayer;
101 break;
102 case Qgis::LayerType::Plugin:
103 sipType = sipType_QgsPluginLayer;
104 break;
105 case Qgis::LayerType::Mesh:
106 sipType = sipType_QgsMeshLayer;
107 break;
108 case Qgis::LayerType::VectorTile:
109 sipType = sipType_QgsVectorTileLayer;
110 break;
111 case Qgis::LayerType::Annotation:
112 sipType = sipType_QgsAnnotationLayer;
113 break;
114 case Qgis::LayerType::PointCloud:
115 sipType = sipType_QgsPointCloudLayer;
116 break;
117 case Qgis::LayerType::Group:
118 sipType = sipType_QgsGroupLayer;
119 break;
120 default:
121 sipType = nullptr;
122 break;
123 }
124 }
125 SIP_END
126#endif
127
128 public:
129
135 {
136 Style = 0,
138 };
139
146 {
147 Identifiable = 1 << 0,
148 Removable = 1 << 1,
149 Searchable = 1 << 2,
150 Private = 1 << 3,
151 };
152 Q_ENUM( LayerFlag )
153 Q_DECLARE_FLAGS( LayerFlags, LayerFlag )
154 Q_FLAG( LayerFlags )
155
156
161 {
162 LayerConfiguration = 1 << 0,
163 Symbology = 1 << 1,
164 Symbology3D = 1 << 2,
165 Labeling = 1 << 3,
166 Fields = 1 << 4,
167 Forms = 1 << 5,
168 Actions = 1 << 6,
169 MapTips = 1 << 7,
170 Diagrams = 1 << 8,
171 AttributeTable = 1 << 9,
172 Rendering = 1 << 10,
173 CustomProperties = 1 << 11,
174 GeometryOptions = 1 << 12,
175 Relations = 1 << 13,
176 Temporal = 1 << 14,
177 Legend = 1 << 15,
178 Elevation = 1 << 16,
179 Notes = 1 << 17,
180 AllStyleCategories = LayerConfiguration | Symbology | Symbology3D | Labeling | Fields | Forms | Actions |
181 MapTips | Diagrams | AttributeTable | Rendering | CustomProperties | GeometryOptions | Relations | Temporal | Legend | Elevation | Notes,
182 };
183 Q_ENUM( StyleCategory )
184 Q_DECLARE_FLAGS( StyleCategories, StyleCategory )
185 Q_FLAG( StyleCategories )
186
187
193 QgsMapLayer( Qgis::LayerType type = Qgis::LayerType::Vector, const QString &name = QString(), const QString &source = QString() );
194
195 ~QgsMapLayer() override;
196
198 QgsMapLayer( QgsMapLayer const & ) = delete;
200 QgsMapLayer &operator=( QgsMapLayer const & ) = delete;
201
208 virtual QgsMapLayer *clone() const = 0;
209
213 Qgis::LayerType type() const;
214
225 QgsMapLayer::LayerFlags flags() const;
226
237 void setFlags( QgsMapLayer::LayerFlags flags );
238
248 virtual Qgis::MapLayerProperties properties() const;
249
255 static QString extensionPropertyType( PropertyType type );
256
258 QString id() const;
259
265 void setName( const QString &name );
266
271 QString name() const;
272
276 Q_INVOKABLE virtual QgsDataProvider *dataProvider();
277
282 virtual const QgsDataProvider *dataProvider() const SIP_SKIP;
283
289 void setShortName( const QString &shortName ) { mShortName = shortName; }
290
296 QString shortName() const;
297
303 void setTitle( const QString &title ) { mTitle = title; }
304
311 QString title() const { return mTitle; }
312
318 void setAbstract( const QString &abstract ) { mAbstract = abstract; }
319
326 QString abstract() const { return mAbstract; }
327
333 void setKeywordList( const QString &keywords ) { mKeywordList = keywords; }
334
341 QString keywordList() const { return mKeywordList; }
342
343 /* Layer dataUrl information */
344
351 void setDataUrl( const QString &dataUrl ) { mDataUrl = dataUrl; }
352
360 QString dataUrl() const { return mDataUrl; }
361
368 void setDataUrlFormat( const QString &dataUrlFormat ) { mDataUrlFormat = dataUrlFormat; }
369
377 QString dataUrlFormat() const { return mDataUrlFormat; }
378
379 /* Layer attribution information */
380
387 void setAttribution( const QString &attrib ) { mAttribution = attrib; }
388
396 QString attribution() const { return mAttribution; }
397
404 void setAttributionUrl( const QString &attribUrl ) { mAttributionUrl = attribUrl; }
405
413 QString attributionUrl() const { return mAttributionUrl; }
414
415 /* Layer metadataUrl information */
416
421 QgsMapLayerServerProperties *serverProperties() { return mServerProperties.get(); };
422
427 const QgsMapLayerServerProperties *serverProperties() const { return mServerProperties.get(); } SIP_SKIP;
428
437 Q_DECL_DEPRECATED void setMetadataUrl( const QString &metaUrl ) SIP_DEPRECATED;
438
448 Q_DECL_DEPRECATED QString metadataUrl() const SIP_DEPRECATED;
449
458 Q_DECL_DEPRECATED void setMetadataUrlType( const QString &metaUrlType ) SIP_DEPRECATED;
459
469 Q_DECL_DEPRECATED QString metadataUrlType() const SIP_DEPRECATED;
470
479 Q_DECL_DEPRECATED void setMetadataUrlFormat( const QString &metaUrlFormat ) SIP_DEPRECATED;
480
490 Q_DECL_DEPRECATED QString metadataUrlFormat() const SIP_DEPRECATED;
491
497 void setBlendMode( QPainter::CompositionMode blendMode );
498
503 QPainter::CompositionMode blendMode() const;
504
513 virtual void setOpacity( double opacity );
514
523 virtual double opacity() const;
524
526 bool readOnly() const { return isReadOnly(); }
527
531 Q_INVOKABLE virtual void reload() {}
532
538
540 virtual QgsRectangle extent() const;
541
550 QgsRectangle wgs84Extent( bool forceRecalculate = false ) const;
551
557 bool isValid() const;
558
565 QString publicSource() const;
566
572 QString source() const;
573
578 virtual QStringList subLayers() const;
579
584 virtual void setLayerOrder( const QStringList &layers );
585
591 virtual void setSubLayerVisibility( const QString &name, bool visible );
592
599 virtual bool supportsEditing() const;
600
602 virtual bool isEditable() const;
603
609 virtual bool isModified() const;
610
615 virtual bool isSpatial() const;
616
626 virtual bool isTemporary() const;
627
633 {
634 FlagDontResolveLayers = 1 << 0,
635 FlagTrustLayerMetadata = 1 << 1,
636 FlagReadExtentFromXml = 1 << 2,
637 FlagForceReadOnly = 1 << 3,
638 };
639 Q_DECLARE_FLAGS( ReadFlags, ReadFlag )
640
641
659 bool readLayerXml( const QDomElement &layerElement, QgsReadWriteContext &context,
660 QgsMapLayer::ReadFlags flags = QgsMapLayer::ReadFlags(), QgsDataProvider *preloadedProvider SIP_TRANSFER = nullptr );
661
679 bool writeLayerXml( QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context ) const;
680
685 virtual void resolveReferences( QgsProject *project );
686
692 Q_INVOKABLE QStringList customPropertyKeys() const;
693
699 Q_INVOKABLE void setCustomProperty( const QString &key, const QVariant &value );
700
705 Q_INVOKABLE QVariant customProperty( const QString &value, const QVariant &defaultValue = QVariant() ) const;
706
711 void setCustomProperties( const QgsObjectCustomProperties &properties );
712
718 const QgsObjectCustomProperties &customProperties() const;
719
720#ifndef SIP_RUN
721
732 template <class T>
733 T customEnumProperty( const QString &key, const T &defaultValue )
734 {
735 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
736 Q_ASSERT( metaEnum.isValid() );
737 if ( !metaEnum.isValid() )
738 {
739 QgsDebugError( QStringLiteral( "Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
740 }
741
742 T v;
743 bool ok = false;
744
745 if ( metaEnum.isValid() )
746 {
747 // read as string
748 QByteArray ba = customProperty( key, metaEnum.valueToKey( static_cast<int>( defaultValue ) ) ).toString().toUtf8();
749 const char *vs = ba.data();
750 v = static_cast<T>( metaEnum.keyToValue( vs, &ok ) );
751 if ( ok )
752 return v;
753 }
754
755 // if failed, try to read as int (old behavior)
756 // this code shall be removed later
757 // then the method could be marked as const
758 v = static_cast<T>( customProperty( key, static_cast<int>( defaultValue ) ).toInt( &ok ) );
759 if ( metaEnum.isValid() )
760 {
761 if ( !ok || !metaEnum.valueToKey( static_cast<int>( v ) ) )
762 {
763 v = defaultValue;
764 }
765 else
766 {
767 // found property as an integer
768 // convert the property to the new form (string)
769 setCustomEnumProperty( key, v );
770 }
771 }
772
773 return v;
774 }
775
784 template <class T>
785 void setCustomEnumProperty( const QString &key, const T &value )
786 {
787 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
788 Q_ASSERT( metaEnum.isValid() );
789 if ( metaEnum.isValid() )
790 {
791 setCustomProperty( key, metaEnum.valueToKey( static_cast<int>( value ) ) );
792 }
793 else
794 {
795 QgsDebugError( QStringLiteral( "Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
796 }
797 }
798
810 template <class T>
811 T customFlagProperty( const QString &key, const T &defaultValue )
812 {
813 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
814 Q_ASSERT( metaEnum.isValid() );
815 if ( !metaEnum.isValid() )
816 {
817 QgsDebugError( QStringLiteral( "Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
818 }
819
820 T v = defaultValue;
821 bool ok = false;
822
823 if ( metaEnum.isValid() )
824 {
825 // read as string
826 QByteArray ba = customProperty( key, metaEnum.valueToKeys( defaultValue ) ).toString().toUtf8();
827 const char *vs = ba.data();
828 v = static_cast<T>( metaEnum.keysToValue( vs, &ok ) );
829 }
830 if ( !ok )
831 {
832 // if failed, try to read as int
833 const int intValue = customProperty( key, static_cast<int>( defaultValue ) ).toInt( &ok );
834 if ( metaEnum.isValid() )
835 {
836 if ( ok )
837 {
838 // check that the int value does correspond to a flag
839 // see https://stackoverflow.com/a/68495949/1548052
840 const QByteArray keys = metaEnum.valueToKeys( intValue );
841 const int intValueCheck = metaEnum.keysToValue( keys );
842 if ( intValue != intValueCheck )
843 {
844 v = defaultValue;
845 }
846 else
847 {
848 // found property as an integer
849 v = T( intValue );
850 // convert the property to the new form (string)
851 // this code could be removed
852 // then the method could be marked as const
853 setCustomFlagProperty( key, v );
854 }
855 }
856 else
857 {
858 v = defaultValue;
859 }
860 }
861 }
862
863 return v;
864 }
865
874 template <class T>
875 void setCustomFlagProperty( const QString &key, const T &value )
876 {
877 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
878 Q_ASSERT( metaEnum.isValid() );
879 if ( metaEnum.isValid() )
880 {
881 setCustomProperty( key, metaEnum.valueToKeys( value ) );
882 }
883 else
884 {
885 QgsDebugError( QStringLiteral( "Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
886 }
887 }
888#endif
889
890
895 void removeCustomProperty( const QString &key );
896
902 virtual QgsError error() const;
903
909
911 void setCrs( const QgsCoordinateReferenceSystem &srs, bool emitSignal = true );
912
918 QgsCoordinateTransformContext transformContext( ) const;
919
920
926 static QString formatLayerName( const QString &name );
927
935 virtual QString metadataUri() const;
936
943 void exportNamedMetadata( QDomDocument &doc, QString &errorMsg ) const;
944
954 virtual QString saveDefaultMetadata( bool &resultFlag SIP_OUT );
955
970 QString saveNamedMetadata( const QString &uri, bool &resultFlag );
971
986 virtual QString loadNamedMetadata( const QString &uri, bool &resultFlag SIP_OUT );
987
997 virtual QString loadDefaultMetadata( bool &resultFlag );
998
1007 bool loadNamedMetadataFromDatabase( const QString &db, const QString &uri, QString &qmd );
1008
1016 bool importNamedMetadata( QDomDocument &document, QString &errorMessage );
1017
1026 virtual QString styleURI() const;
1027
1037 virtual QString loadDefaultStyle( bool &resultFlag SIP_OUT );
1038
1054 virtual QString loadNamedStyle( const QString &uri, bool &resultFlag SIP_OUT, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories );
1055
1063 virtual bool loadNamedStyleFromDatabase( const QString &db, const QString &uri, QString &qml SIP_OUT );
1064
1074 virtual bool importNamedStyle( QDomDocument &doc, QString &errorMsg SIP_OUT,
1075 QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories );
1076
1085 virtual void exportNamedStyle( QDomDocument &doc, QString &errorMsg SIP_OUT, const QgsReadWriteContext &context = QgsReadWriteContext(),
1086 QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) const;
1087
1088
1096 virtual void exportSldStyle( QDomDocument &doc, QString &errorMsg ) const;
1097
1106 virtual void exportSldStyleV2( QDomDocument &doc, QString &errorMsg, const QgsSldExportContext &exportContext ) const;
1107
1119 virtual QString saveDefaultStyle( bool &resultFlag SIP_OUT, StyleCategories categories );
1120
1132 Q_DECL_DEPRECATED virtual QString saveDefaultStyle( bool &resultFlag SIP_OUT ) SIP_DEPRECATED;
1133
1149 virtual QString saveNamedStyle( const QString &uri, bool &resultFlag SIP_OUT, StyleCategories categories = AllStyleCategories );
1150
1160 virtual QString saveSldStyle( const QString &uri, bool &resultFlag ) const;
1161
1172 virtual QString saveSldStyleV2( bool &resultFlag SIP_OUT, const QgsSldExportContext &exportContext ) const;
1173
1182 virtual QString loadSldStyle( const QString &uri, bool &resultFlag );
1183
1184 virtual bool readSld( const QDomNode &node, QString &errorMessage )
1185 { Q_UNUSED( node ) errorMessage = QStringLiteral( "Layer type %1 not supported" ).arg( static_cast<int>( type() ) ); return false; }
1186
1187
1188
1197 virtual bool readSymbology( const QDomNode &node, QString &errorMessage,
1198 QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories ) = 0;
1199
1210 virtual bool readStyle( const QDomNode &node, QString &errorMessage,
1211 QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories );
1212
1223 virtual bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context,
1224 StyleCategories categories = AllStyleCategories ) const = 0;
1225
1238 virtual bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context,
1239 StyleCategories categories = AllStyleCategories ) const;
1240
1241
1256 void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, bool loadDefaultStyleFlag = false );
1257
1271 void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, bool loadDefaultStyleFlag = false );
1272
1287 void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags );
1288
1292 QString providerType() const;
1293
1295 QUndoStack *undoStack();
1296
1301 QUndoStack *undoStackStyles();
1302
1306 void setLegendUrl( const QString &legendUrl ) { mLegendUrl = legendUrl; }
1307
1311 QString legendUrl() const { return mLegendUrl; }
1312
1316 void setLegendUrlFormat( const QString &legendUrlFormat ) { mLegendUrlFormat = legendUrlFormat; }
1317
1321 QString legendUrlFormat() const { return mLegendUrlFormat; }
1322
1328 void setLegend( QgsMapLayerLegend *legend SIP_TRANSFER );
1329
1334 QgsMapLayerLegend *legend() const;
1335
1340 QgsMapLayerStyleManager *styleManager() const;
1341
1346 void setRenderer3D( QgsAbstract3DRenderer *renderer SIP_TRANSFER );
1347
1352 QgsAbstract3DRenderer *renderer3D() const;
1353
1363 bool isInScaleRange( double scale ) const;
1364
1375 double minimumScale() const;
1376
1387 double maximumScale() const;
1388
1397 bool hasScaleBasedVisibility() const;
1398
1405 bool hasAutoRefreshEnabled() const;
1406
1414 int autoRefreshInterval() const;
1415
1427 void setAutoRefreshInterval( int interval );
1428
1435 void setAutoRefreshEnabled( bool enabled );
1436
1443 virtual const QgsLayerMetadata &metadata() const;
1444
1451 virtual void setMetadata( const QgsLayerMetadata &metadata );
1452
1457 virtual QString htmlMetadata() const;
1458
1460 virtual QDateTime timestamp() const;
1461
1469 virtual QSet<QgsMapLayerDependency> dependencies() const;
1470
1476 QString refreshOnNotifyMessage() const { return mRefreshOnNofifyMessage; }
1477
1483 bool isRefreshOnNotifyEnabled() const { return mIsRefreshOnNofifyEnabled; }
1484
1493 QString originalXmlProperties() const;
1494
1502 void setOriginalXmlProperties( const QString &originalXmlProperties );
1503
1508 static QString generateId( const QString &layerName );
1509
1519 virtual bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
1520
1527
1534
1540 QString legendPlaceholderImage() const { return mLegendPlaceholderImage;}
1541
1547 void setLegendPlaceholderImage( const QString &imgPath ) { mLegendPlaceholderImage = imgPath; }
1548
1555 virtual bool hasMapTips() const;
1556
1565 QString mapTipTemplate() const;
1566
1575 void setMapTipTemplate( const QString &mapTipTemplate );
1576
1583 void setMapTipsEnabled( bool enabled );
1584
1589 bool mapTipsEnabled() const;
1590
1598 static QgsDataProvider::ReadFlags providerReadFlags( const QDomNode &layerNode, QgsMapLayer::ReadFlags layerReadFlags );
1599
1600 public slots:
1601
1611 void setMinimumScale( double scale );
1612
1622 void setMaximumScale( double scale );
1623
1631 void setScaleBasedVisibility( bool enabled );
1632
1641 void triggerRepaint( bool deferredUpdate = false );
1642
1649 void trigger3DUpdate();
1650
1655 void emitStyleChanged();
1656
1665 virtual bool setDependencies( const QSet<QgsMapLayerDependency> &layers );
1666
1672 void setRefreshOnNotifyEnabled( bool enabled );
1673
1681 void setRefreshOnNofifyMessage( const QString &message ) { mRefreshOnNofifyMessage = message; }
1682
1688 virtual void setTransformContext( const QgsCoordinateTransformContext &transformContext ) = 0;
1689
1690#ifdef SIP_RUN
1691 SIP_PYOBJECT __repr__();
1692 % MethodCode
1693 QString str = QStringLiteral( "<QgsMapLayer: '%1' (%2)>" ).arg( sipCpp->name(), sipCpp->dataProvider() ? sipCpp->dataProvider()->name() : QStringLiteral( "Invalid" ) );
1694 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
1695 % End
1696#endif
1697
1704 QgsProject *project() const;
1705
1706 signals:
1707
1715
1717 void statusChanged( const QString &status );
1718
1725
1728
1735 void repaintRequested( bool deferredUpdate = false );
1736
1739
1742
1744 void blendModeChanged( QPainter::CompositionMode blendMode );
1745
1754 void opacityChanged( double opacity );
1755
1761
1774
1780
1786
1793
1799
1804
1812
1818 void autoRefreshIntervalChanged( int interval );
1819
1827
1835
1844
1850 void styleLoaded( QgsMapLayer::StyleCategories categories );
1851
1858
1864 void customPropertyChanged( const QString &key );
1865
1871
1877
1883
1891
1899
1900 private slots:
1901
1902 void onNotified( const QString &message );
1903
1919 virtual void setDataSourcePrivate( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags );
1920
1921 protected:
1922
1928 void clone( QgsMapLayer *layer ) const;
1929
1931 virtual void setExtent( const QgsRectangle &rect );
1932
1934 void setValid( bool valid );
1935
1940 virtual bool readXml( const QDomNode &layer_node, QgsReadWriteContext &context );
1941
1946 virtual bool writeXml( QDomNode &layer_node, QDomDocument &document, const QgsReadWriteContext &context ) const;
1947
1959 virtual QString encodedSource( const QString &source, const QgsReadWriteContext &context ) const;
1960
1973 virtual QString decodedSource( const QString &source, const QString &dataProvider, const QgsReadWriteContext &context ) const;
1974
1980 void readCustomProperties( const QDomNode &layerNode, const QString &keyStartsWith = QString() );
1981
1983 void writeCustomProperties( QDomNode &layerNode, QDomDocument &doc ) const;
1984
1986 void readStyleManager( const QDomNode &layerNode );
1988 void writeStyleManager( QDomNode &layerNode, QDomDocument &doc ) const;
1989
1994 void writeCommonStyle( QDomElement &layerElement, QDomDocument &document,
1995 const QgsReadWriteContext &context,
1996 StyleCategories categories = AllStyleCategories ) const;
1997
2002 void readCommonStyle( const QDomElement &layerElement, const QgsReadWriteContext &context,
2003 StyleCategories categories = AllStyleCategories );
2004
2006 void setProviderType( const QString &providerType );
2007
2008#ifndef SIP_RUN
2009#if 0
2011 void connectNotify( const char *signal ) override;
2012#endif
2013#endif
2014
2016 void appendError( const QgsErrorMessage &error ) { mError.append( error );}
2018 void setError( const QgsError &error ) { mError = error;}
2019
2026 void invalidateWgs84Extent();
2027
2029 bool mValid = false;
2030
2033
2035 QString mLayerName;
2036
2037 QString mShortName;
2038 QString mTitle;
2039
2041 QString mAbstract;
2043
2045 QString mDataUrl;
2047
2051
2053 QString mLegendUrl;
2055
2058
2060 QSet<QgsMapLayerDependency> mDependencies;
2061
2067 Q_DECL_DEPRECATED bool hasDependencyCycle( const QSet<QgsMapLayerDependency> & ) const {return false;}
2068
2069 bool mIsRefreshOnNofifyEnabled = false;
2071
2074
2075 //TODO QGIS 4 - move to readXml as a new argument (breaks API)
2076
2078 QgsMapLayer::ReadFlags mReadFlags = QgsMapLayer::ReadFlags();
2079
2085 bool mShouldValidateCrs = true;
2086
2092 double mLayerOpacity = 1.0;
2093
2099 int mBlockStyleChangedSignal = 0;
2100
2101#ifndef SIP_RUN
2102
2111 QString crsHtmlMetadata() const;
2112#endif
2113
2114#ifndef SIP_RUN
2115
2124 QString generalHtmlMetadata() const;
2125#endif
2126
2127#ifndef SIP_RUN
2128
2136 std::unique_ptr<QgsDataProvider> mPreloadedProvider;
2137#endif
2138
2139 private:
2140
2141 virtual QString baseURI( PropertyType type ) const;
2142 QString saveNamedProperty( const QString &uri, QgsMapLayer::PropertyType type,
2143 bool &resultFlag, StyleCategories categories = AllStyleCategories );
2144 QString loadNamedProperty( const QString &uri, QgsMapLayer::PropertyType type,
2145 bool &resultFlag, StyleCategories categories = AllStyleCategories );
2146 bool loadNamedPropertyFromDatabase( const QString &db, const QString &uri, QString &xml, QgsMapLayer::PropertyType type );
2147
2148 // const method because extents are mutable
2149 void updateExtent( const QgsRectangle &extent ) const;
2150
2155 virtual bool isReadOnly() const;
2156
2162
2164 QString mID;
2165
2167 Qgis::LayerType mLayerType;
2168
2169 LayerFlags mFlags = LayerFlags( Identifiable | Removable | Searchable );
2170
2172 QPainter::CompositionMode mBlendMode = QPainter::CompositionMode_SourceOver;
2173
2175 QString mTag;
2176
2177 //set some generous defaults for scale based visibility
2178
2180 double mMinScale = 0;
2182 double mMaxScale = 100000000;
2184 bool mScaleBasedVisibility = false;
2185
2189 std::unique_ptr< QgsMapLayerServerProperties > mServerProperties;
2190
2192 QUndoStack *mUndoStack = nullptr;
2193
2194 QUndoStack *mUndoStackStyles = nullptr;
2195
2197 QgsObjectCustomProperties mCustomProperties;
2198
2200 QgsMapLayerLegend *mLegend = nullptr;
2201
2203 QgsMapLayerStyleManager *mStyleManager = nullptr;
2204
2206 QTimer *mRefreshTimer = nullptr;
2207
2208 QgsLayerMetadata mMetadata;
2209
2211 QgsAbstract3DRenderer *m3DRenderer = nullptr;
2212
2214 mutable QgsRectangle mExtent;
2215
2217 mutable QgsRectangle mWgs84Extent;
2218
2224 QString mOriginalXmlProperties;
2225
2227 bool mRepaintRequestedFired = false;
2228
2230 QString mLegendPlaceholderImage;
2231
2233 QString mMapTipTemplate;
2234
2236 bool mMapTipsEnabled = true;
2237
2238 friend class QgsVectorLayer;
2239 friend class TestQgsMapLayer;
2240};
2241
2243Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapLayer::LayerFlags )
2244Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapLayer::StyleCategories )
2245Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapLayer::ReadFlags )
2246
2247
2248#ifndef SIP_RUN
2249
2255typedef QPointer< QgsMapLayer > QgsWeakMapLayerPointer;
2256
2262typedef QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList;
2263#endif
2264
2265#endif
LayerType
Types of layers that can be added to a map.
Definition: qgis.h:114
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:2042
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:1321
void dependenciesChanged()
Emitted when dependencies are changed.
void setError(const QgsError &error)
Sets error message.
Definition: qgsmaplayer.h:2018
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:318
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:1306
void request3DUpdate()
Signal emitted when a layer requires an update in any 3D maps.
QgsError mError
Error.
Definition: qgsmaplayer.h:2057
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:811
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:2067
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:1540
QgsMapLayerServerProperties * serverProperties()
Returns QGIS Server Properties for the map layer.
Definition: qgsmaplayer.h:421
QString attribution() const
Returns the attribution of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:396
QString mRefreshOnNofifyMessage
Definition: qgsmaplayer.h:2070
QString mLegendUrl
WMS legend.
Definition: qgsmaplayer.h:2053
QString mLayerName
Name of the layer - used for display.
Definition: qgsmaplayer.h:2035
void setCustomFlagProperty(const QString &key, const T &value)
Set the value of a property based on a flag.
Definition: qgsmaplayer.h:875
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:404
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:326
QString dataUrlFormat() const
Returns the DataUrl format of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:377
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:2038
void setDataUrl(const QString &dataUrl)
Sets the DataUrl of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:351
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:333
void setAttribution(const QString &attrib)
Sets the attribution of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:387
bool isRefreshOnNotifyEnabled() const
Returns true if the refresh on provider nofification is enabled.
Definition: qgsmaplayer.h:1483
QSet< QgsMapLayerDependency > mDependencies
List of layers that may modify this layer on modification.
Definition: qgsmaplayer.h:2060
void setDataUrlFormat(const QString &dataUrlFormat)
Sets the DataUrl format of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:368
QString mLegendUrlFormat
Definition: qgsmaplayer.h:2054
const QgsMapLayerServerProperties * serverProperties() const
Returns QGIS Server Properties const for the map layer.
Definition: qgsmaplayer.h:427
QString mProviderKey
Data provider key (name of the data provider)
Definition: qgsmaplayer.h:2073
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.
Definition: qgsmaplayer.h:2136
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:311
void crsChanged()
Emit a signal that layer's CRS has been reset.
QString mAttributionUrl
Definition: qgsmaplayer.h:2050
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:360
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:1681
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:1526
QString mShortName
Definition: qgsmaplayer.h:2037
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:146
void setLegendPlaceholderImage(const QString &imgPath)
Set placeholder image for legend.
Definition: qgsmaplayer.h:1547
void appendError(const QgsErrorMessage &error)
Add error message.
Definition: qgsmaplayer.h:2016
QString mDataSource
Data source description string, varies by layer type.
Definition: qgsmaplayer.h:2032
QString refreshOnNotifyMessage() const
Returns the message that should be notified by the provider to triggerRepaint.
Definition: qgsmaplayer.h:1476
virtual bool readSld(const QDomNode &node, QString &errorMessage)
Definition: qgsmaplayer.h:1184
ReadFlag
Flags which control project read behavior.
Definition: qgsmaplayer.h:633
QString attributionUrl() const
Returns the attribution URL of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:413
QString mAbstract
Description of the layer.
Definition: qgsmaplayer.h:2041
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:1311
QString mDataUrlFormat
Definition: qgsmaplayer.h:2046
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:1316
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:1533
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:2045
T customEnumProperty(const QString &key, const T &defaultValue)
Returns the property value for a property based on an enum.
Definition: qgsmaplayer.h:733
StyleCategory
Categories of style to distinguish appropriate sections for import/export.
Definition: qgsmaplayer.h:161
@ AllStyleCategories
Definition: qgsmaplayer.h:180
void layerModified()
Emitted when modifications has been done on layer.
virtual Q_INVOKABLE void reload()
Synchronises with changes in the datasource.
Definition: qgsmaplayer.h:531
void mapTipsEnabledChanged()
Emitted when map tips are enabled or disabled for the layer.
QString mAttribution
Attribution of the layer.
Definition: qgsmaplayer.h:2049
void setCustomEnumProperty(const QString &key, const T &value)
Set the value of a property based on an enum.
Definition: qgsmaplayer.h:785
QString keywordList() const
Returns the keyword list of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:341
void setTitle(const QString &title)
Sets the title of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:303
PropertyType
Maplayer has a style and a metadata property.
Definition: qgsmaplayer.h:135
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.
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: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)
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 QgsDebugError(str)
Definition: qgslogger.h:38
QPointer< QgsMapLayer > QgsWeakMapLayerPointer
Weak pointer for QgsMapLayer.
Definition: qgsmaplayer.h:2255
QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList
A list of weak pointers to QgsMapLayers.
Definition: qgsmaplayer.h:2262
const QgsCoordinateReferenceSystem & crs
Setting options for creating vector data providers.