QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
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
139 {
140 Style = 0,
142 };
143
150 {
151 Identifiable = 1 << 0,
152 Removable = 1 << 1,
153 Searchable = 1 << 2,
154 Private = 1 << 3,
155 };
156 Q_ENUM( LayerFlag )
157 Q_DECLARE_FLAGS( LayerFlags, LayerFlag )
158 Q_FLAG( LayerFlags )
159
165 {
166 LayerConfiguration = 1 << 0,
167 Symbology = 1 << 1,
168 Symbology3D = 1 << 2,
169 Labeling = 1 << 3,
170 Fields = 1 << 4,
171 Forms = 1 << 5,
172 Actions = 1 << 6,
173 MapTips = 1 << 7,
174 Diagrams = 1 << 8,
175 AttributeTable = 1 << 9,
176 Rendering = 1 << 10,
177 CustomProperties = 1 << 11,
178 GeometryOptions = 1 << 12,
179 Relations = 1 << 13,
180 Temporal = 1 << 14,
181 Legend = 1 << 15,
182 Elevation = 1 << 16,
183 Notes = 1 << 17,
184 AllStyleCategories = LayerConfiguration | Symbology | Symbology3D | Labeling | Fields | Forms | Actions |
185 MapTips | Diagrams | AttributeTable | Rendering | CustomProperties | GeometryOptions | Relations | Temporal | Legend | Elevation | Notes,
186 };
187 Q_ENUM( StyleCategory )
188 Q_DECLARE_FLAGS( StyleCategories, StyleCategory )
189 Q_FLAG( StyleCategories )
190
197 QgsMapLayer( Qgis::LayerType type = Qgis::LayerType::Vector, const QString &name = QString(), const QString &source = QString() );
198
199 ~QgsMapLayer() override;
200
202 QgsMapLayer( QgsMapLayer const & ) = delete;
204 QgsMapLayer &operator=( QgsMapLayer const & ) = delete;
205
211 virtual QgsMapLayer *clone() const = 0;
212
216 Qgis::LayerType type() const;
217
228 QgsMapLayer::LayerFlags flags() const;
229
240 void setFlags( QgsMapLayer::LayerFlags flags );
241
251 virtual Qgis::MapLayerProperties properties() const;
252
257 static QString extensionPropertyType( PropertyType type );
258
260 QString id() const;
261
266 void setName( const QString &name );
267
272 QString name() const;
273
277 Q_INVOKABLE virtual QgsDataProvider *dataProvider();
278
283 virtual const QgsDataProvider *dataProvider() const SIP_SKIP;
284
290 void setShortName( const QString &shortName ) { mShortName = shortName; }
291
297 QString shortName() const;
298
304 void setTitle( const QString &title ) { mTitle = title; }
305
312 QString title() const { return mTitle; }
313
319 void setAbstract( const QString &abstract ) { mAbstract = abstract; }
320
327 QString abstract() const { return mAbstract; }
328
334 void setKeywordList( const QString &keywords ) { mKeywordList = keywords; }
335
342 QString keywordList() const { return mKeywordList; }
343
344 /* Layer dataUrl information */
345
352 void setDataUrl( const QString &dataUrl ) { mDataUrl = dataUrl; }
353
361 QString dataUrl() const { return mDataUrl; }
362
369 void setDataUrlFormat( const QString &dataUrlFormat ) { mDataUrlFormat = dataUrlFormat; }
370
378 QString dataUrlFormat() const { return mDataUrlFormat; }
379
380 /* Layer attribution information */
381
388 void setAttribution( const QString &attrib ) { mAttribution = attrib; }
389
397 QString attribution() const { return mAttribution; }
398
405 void setAttributionUrl( const QString &attribUrl ) { mAttributionUrl = attribUrl; }
406
414 QString attributionUrl() const { return mAttributionUrl; }
415
416 /* Layer metadataUrl information */
417
422 QgsMapLayerServerProperties *serverProperties() { return mServerProperties.get(); };
423
428 const QgsMapLayerServerProperties *serverProperties() const { return mServerProperties.get(); } SIP_SKIP;
429
438 Q_DECL_DEPRECATED void setMetadataUrl( const QString &metaUrl ) SIP_DEPRECATED;
439
449 Q_DECL_DEPRECATED QString metadataUrl() const SIP_DEPRECATED;
450
459 Q_DECL_DEPRECATED void setMetadataUrlType( const QString &metaUrlType ) SIP_DEPRECATED;
460
470 Q_DECL_DEPRECATED QString metadataUrlType() const SIP_DEPRECATED;
471
480 Q_DECL_DEPRECATED void setMetadataUrlFormat( const QString &metaUrlFormat ) SIP_DEPRECATED;
481
491 Q_DECL_DEPRECATED QString metadataUrlFormat() const SIP_DEPRECATED;
492
498 void setBlendMode( QPainter::CompositionMode blendMode );
499
504 QPainter::CompositionMode blendMode() const;
505
514 virtual void setOpacity( double opacity );
515
524 virtual double opacity() const;
525
527 bool readOnly() const { return isReadOnly(); }
528
532 Q_INVOKABLE virtual void reload() {}
533
538
540 virtual QgsRectangle extent() const;
541
546 virtual QgsBox3D extent3D() const;
547
556 QgsRectangle wgs84Extent( bool forceRecalculate = false ) const;
557
563 bool isValid() const;
564
572 QString publicSource( bool hidePassword = false ) const;
573
579 QString source() const;
580
585 virtual QStringList subLayers() const;
586
591 virtual void setLayerOrder( const QStringList &layers );
592
598 virtual void setSubLayerVisibility( const QString &name, bool visible );
599
606 virtual bool supportsEditing() const;
607
609 virtual bool isEditable() const;
610
616 virtual bool isModified() const;
617
621 virtual bool isSpatial() const;
622
632 virtual bool isTemporary() const;
633
639 {
640 FlagDontResolveLayers = 1 << 0,
641 FlagTrustLayerMetadata = 1 << 1,
642 FlagReadExtentFromXml = 1 << 2,
643 FlagForceReadOnly = 1 << 3,
644 };
645 Q_DECLARE_FLAGS( ReadFlags, ReadFlag )
646
647
665 bool readLayerXml( const QDomElement &layerElement, QgsReadWriteContext &context,
666 QgsMapLayer::ReadFlags flags = QgsMapLayer::ReadFlags(), QgsDataProvider *preloadedProvider SIP_TRANSFER = nullptr );
667
685 bool writeLayerXml( QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context ) const;
686
690 virtual void resolveReferences( QgsProject *project );
691
696 Q_INVOKABLE QStringList customPropertyKeys() const;
697
703 Q_INVOKABLE void setCustomProperty( const QString &key, const QVariant &value );
704
709 Q_INVOKABLE QVariant customProperty( const QString &value, const QVariant &defaultValue = QVariant() ) const;
710
714 void setCustomProperties( const QgsObjectCustomProperties &properties );
715
721 const QgsObjectCustomProperties &customProperties() const;
722
732 virtual int listStylesInDatabase( QStringList &ids SIP_OUT, QStringList &names SIP_OUT,
733 QStringList &descriptions SIP_OUT, QString &msgError SIP_OUT );
734
738 virtual QString getStyleFromDatabase( const QString &styleId, QString &msgError SIP_OUT );
739
746 virtual bool deleteStyleFromDatabase( const QString &styleId, QString &msgError SIP_OUT );
747
764 virtual void saveStyleToDatabase( const QString &name, const QString &description,
765 bool useAsDefault, const QString &uiFileContent,
766 QString &msgError SIP_OUT,
768
776 virtual QString loadNamedStyle( const QString &theURI, bool &resultFlag SIP_OUT, bool loadFromLocalDb,
778
779#ifndef SIP_RUN
780
791 template <class T>
792 T customEnumProperty( const QString &key, const T &defaultValue )
793 {
794 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
795 Q_ASSERT( metaEnum.isValid() );
796 if ( !metaEnum.isValid() )
797 {
798 QgsDebugError( QStringLiteral( "Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
799 }
800
801 T v;
802 bool ok = false;
803
804 if ( metaEnum.isValid() )
805 {
806 // read as string
807 QByteArray ba = customProperty( key, metaEnum.valueToKey( static_cast<int>( defaultValue ) ) ).toString().toUtf8();
808 const char *vs = ba.data();
809 v = static_cast<T>( metaEnum.keyToValue( vs, &ok ) );
810 if ( ok )
811 return v;
812 }
813
814 // if failed, try to read as int (old behavior)
815 // this code shall be removed later
816 // then the method could be marked as const
817 v = static_cast<T>( customProperty( key, static_cast<int>( defaultValue ) ).toInt( &ok ) );
818 if ( metaEnum.isValid() )
819 {
820 if ( !ok || !metaEnum.valueToKey( static_cast<int>( v ) ) )
821 {
822 v = defaultValue;
823 }
824 else
825 {
826 // found property as an integer
827 // convert the property to the new form (string)
828 setCustomEnumProperty( key, v );
829 }
830 }
831
832 return v;
833 }
834
843 template <class T>
844 void setCustomEnumProperty( const QString &key, const T &value )
845 {
846 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
847 Q_ASSERT( metaEnum.isValid() );
848 if ( metaEnum.isValid() )
849 {
850 setCustomProperty( key, metaEnum.valueToKey( static_cast<int>( value ) ) );
851 }
852 else
853 {
854 QgsDebugError( QStringLiteral( "Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
855 }
856 }
857
869 template <class T>
870 T customFlagProperty( const QString &key, const T &defaultValue )
871 {
872 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
873 Q_ASSERT( metaEnum.isValid() );
874 if ( !metaEnum.isValid() )
875 {
876 QgsDebugError( QStringLiteral( "Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
877 }
878
879 T v = defaultValue;
880 bool ok = false;
881
882 if ( metaEnum.isValid() )
883 {
884 // read as string
885 QByteArray ba = customProperty( key, metaEnum.valueToKeys( defaultValue ) ).toString().toUtf8();
886 const char *vs = ba.data();
887 v = static_cast<T>( metaEnum.keysToValue( vs, &ok ) );
888 }
889 if ( !ok )
890 {
891 // if failed, try to read as int
892 const int intValue = customProperty( key, static_cast<int>( defaultValue ) ).toInt( &ok );
893 if ( metaEnum.isValid() )
894 {
895 if ( ok )
896 {
897 // check that the int value does correspond to a flag
898 // see https://stackoverflow.com/a/68495949/1548052
899 const QByteArray keys = metaEnum.valueToKeys( intValue );
900 const int intValueCheck = metaEnum.keysToValue( keys );
901 if ( intValue != intValueCheck )
902 {
903 v = defaultValue;
904 }
905 else
906 {
907 // found property as an integer
908 v = T( intValue );
909 // convert the property to the new form (string)
910 // this code could be removed
911 // then the method could be marked as const
912 setCustomFlagProperty( key, v );
913 }
914 }
915 else
916 {
917 v = defaultValue;
918 }
919 }
920 }
921
922 return v;
923 }
924
933 template <class T>
934 void setCustomFlagProperty( const QString &key, const T &value )
935 {
936 const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
937 Q_ASSERT( metaEnum.isValid() );
938 if ( metaEnum.isValid() )
939 {
940 setCustomProperty( key, metaEnum.valueToKeys( value ) );
941 }
942 else
943 {
944 QgsDebugError( QStringLiteral( "Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
945 }
946 }
947#endif
948
949
954 void removeCustomProperty( const QString &key );
955
961 virtual QgsError error() const;
962
967
969 void setCrs( const QgsCoordinateReferenceSystem &srs, bool emitSignal = true );
970
976 QgsCoordinateTransformContext transformContext( ) const;
977
978
983 static QString formatLayerName( const QString &name );
984
991 virtual QString metadataUri() const;
992
998 void exportNamedMetadata( QDomDocument &doc, QString &errorMsg ) const;
999
1008 virtual QString saveDefaultMetadata( bool &resultFlag SIP_OUT );
1009
1023 QString saveNamedMetadata( const QString &uri, bool &resultFlag );
1024
1038 virtual QString loadNamedMetadata( const QString &uri, bool &resultFlag SIP_OUT );
1039
1048 virtual QString loadDefaultMetadata( bool &resultFlag );
1049
1057 bool loadNamedMetadataFromDatabase( const QString &db, const QString &uri, QString &qmd );
1058
1065 bool importNamedMetadata( QDomDocument &document, QString &errorMessage );
1066
1075 virtual QString styleURI() const;
1076
1086 virtual QString loadDefaultStyle( bool &resultFlag SIP_OUT );
1087
1103 virtual QString loadNamedStyle( const QString &uri, bool &resultFlag SIP_OUT, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories );
1104
1112 virtual bool loadNamedStyleFromDatabase( const QString &db, const QString &uri, QString &qml SIP_OUT );
1113
1122 virtual bool importNamedStyle( QDomDocument &doc, QString &errorMsg SIP_OUT,
1124
1133 virtual void exportNamedStyle( QDomDocument &doc, QString &errorMsg SIP_OUT, const QgsReadWriteContext &context = QgsReadWriteContext(),
1135
1136
1144 virtual void exportSldStyle( QDomDocument &doc, QString &errorMsg ) const;
1145
1154 virtual void exportSldStyleV2( QDomDocument &doc, QString &errorMsg, const QgsSldExportContext &exportContext ) const;
1155
1167 virtual QString saveDefaultStyle( bool &resultFlag SIP_OUT, StyleCategories categories );
1168
1180 Q_DECL_DEPRECATED virtual QString saveDefaultStyle( bool &resultFlag SIP_OUT ) SIP_DEPRECATED;
1181
1197 virtual QString saveNamedStyle( const QString &uri, bool &resultFlag SIP_OUT, StyleCategories categories = AllStyleCategories );
1198
1208 virtual QString saveSldStyle( const QString &uri, bool &resultFlag ) const;
1209
1220 virtual QString saveSldStyleV2( bool &resultFlag SIP_OUT, const QgsSldExportContext &exportContext ) const;
1221
1230 virtual QString loadSldStyle( const QString &uri, bool &resultFlag );
1231
1232 virtual bool readSld( const QDomNode &node, QString &errorMessage )
1233 { Q_UNUSED( node ) errorMessage = QStringLiteral( "Layer type %1 not supported" ).arg( static_cast<int>( type() ) ); return false; }
1234
1235
1236
1245 virtual bool readSymbology( const QDomNode &node, QString &errorMessage,
1246 QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories ) = 0;
1247
1257 virtual bool readStyle( const QDomNode &node, QString &errorMessage,
1258 QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories );
1259
1270 virtual bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context,
1271 StyleCategories categories = AllStyleCategories ) const = 0;
1272
1284 virtual bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context,
1285 StyleCategories categories = AllStyleCategories ) const;
1286
1287
1317 void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, bool loadDefaultStyleFlag = false );
1318
1348 void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, bool loadDefaultStyleFlag = false );
1349
1379 void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags );
1380
1384 QString providerType() const;
1385
1387 QUndoStack *undoStack();
1388
1392 QUndoStack *undoStackStyles();
1393
1397 void setLegendUrl( const QString &legendUrl ) { mLegendUrl = legendUrl; }
1398
1402 QString legendUrl() const { return mLegendUrl; }
1403
1407 void setLegendUrlFormat( const QString &legendUrlFormat ) { mLegendUrlFormat = legendUrlFormat; }
1408
1412 QString legendUrlFormat() const { return mLegendUrlFormat; }
1413
1418 void setLegend( QgsMapLayerLegend *legend SIP_TRANSFER );
1419
1423 QgsMapLayerLegend *legend() const;
1424
1428 QgsMapLayerStyleManager *styleManager() const;
1429
1433 void setRenderer3D( QgsAbstract3DRenderer *renderer SIP_TRANSFER );
1434
1438 QgsAbstract3DRenderer *renderer3D() const;
1439
1448 bool isInScaleRange( double scale ) const;
1449
1460 double minimumScale() const;
1461
1472 double maximumScale() const;
1473
1482 bool hasScaleBasedVisibility() const;
1483
1490 Q_DECL_DEPRECATED bool hasAutoRefreshEnabled() const SIP_DEPRECATED;
1491
1498 Qgis::AutoRefreshMode autoRefreshMode() const;
1499
1506 int autoRefreshInterval() const;
1507
1518 void setAutoRefreshInterval( int interval );
1519
1526 Q_DECL_DEPRECATED void setAutoRefreshEnabled( bool enabled ) SIP_DEPRECATED;
1527
1534 void setAutoRefreshMode( Qgis::AutoRefreshMode mode );
1535
1541 virtual const QgsLayerMetadata &metadata() const;
1542
1548 virtual void setMetadata( const QgsLayerMetadata &metadata );
1549
1553 virtual QString htmlMetadata() const;
1554
1556 virtual QDateTime timestamp() const;
1557
1564 virtual QSet<QgsMapLayerDependency> dependencies() const;
1565
1570 QString refreshOnNotifyMessage() const { return mRefreshOnNofifyMessage; }
1571
1576 bool isRefreshOnNotifyEnabled() const { return mIsRefreshOnNofifyEnabled; }
1577
1586 QString originalXmlProperties() const;
1587
1595 void setOriginalXmlProperties( const QString &originalXmlProperties );
1596
1601 static QString generateId( const QString &layerName );
1602
1612 virtual bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
1613
1620
1627
1634
1640 QString legendPlaceholderImage() const { return mLegendPlaceholderImage;}
1641
1647 void setLegendPlaceholderImage( const QString &imgPath ) { mLegendPlaceholderImage = imgPath; }
1648
1655 virtual bool hasMapTips() const;
1656
1664 QString mapTipTemplate() const;
1665
1673 void setMapTipTemplate( const QString &mapTipTemplate );
1674
1681 void setMapTipsEnabled( bool enabled );
1682
1687 bool mapTipsEnabled() const;
1688
1696 static QgsDataProvider::ReadFlags providerReadFlags( const QDomNode &layerNode, QgsMapLayer::ReadFlags layerReadFlags );
1697
1698 public slots:
1699
1709 void setMinimumScale( double scale );
1710
1720 void setMaximumScale( double scale );
1721
1729 void setScaleBasedVisibility( bool enabled );
1730
1739 void triggerRepaint( bool deferredUpdate = false );
1740
1747 void trigger3DUpdate();
1748
1752 void emitStyleChanged();
1753
1761 virtual bool setDependencies( const QSet<QgsMapLayerDependency> &layers );
1762
1767 void setRefreshOnNotifyEnabled( bool enabled );
1768
1775 void setRefreshOnNofifyMessage( const QString &message ) { mRefreshOnNofifyMessage = message; }
1776
1782 virtual void setTransformContext( const QgsCoordinateTransformContext &transformContext ) = 0;
1783
1784#ifdef SIP_RUN
1785 SIP_PYOBJECT __repr__();
1786 % MethodCode
1787 QString str = QStringLiteral( "<QgsMapLayer: '%1' (%2)>" ).arg( sipCpp->name(), sipCpp->dataProvider() ? sipCpp->dataProvider()->name() : QStringLiteral( "Invalid" ) );
1788 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
1789 % End
1790#endif
1791
1798 QgsProject *project() const;
1799
1800 signals:
1801
1809
1811 void statusChanged( const QString &status );
1812
1818
1821
1828 void repaintRequested( bool deferredUpdate = false );
1829
1832
1835
1837 void blendModeChanged( QPainter::CompositionMode blendMode );
1838
1847 void opacityChanged( double opacity );
1848
1854
1866
1871
1876
1883
1889
1894
1901
1906 void autoRefreshIntervalChanged( int interval );
1907
1914
1922
1931
1938
1945
1951 void customPropertyChanged( const QString &key );
1952
1958
1964
1970
1977
1985
1986 private slots:
1987
1988 void onNotified( const QString &message );
1989
2005 virtual void setDataSourcePrivate( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags );
2006
2007 protected:
2008
2013 void clone( QgsMapLayer *layer ) const;
2014
2016 virtual void setExtent( const QgsRectangle &rect );
2017
2022 virtual void setExtent3D( const QgsBox3D &box );
2023
2025 void setValid( bool valid );
2026
2031 virtual bool readXml( const QDomNode &layer_node, QgsReadWriteContext &context );
2032
2037 virtual bool writeXml( QDomNode &layer_node, QDomDocument &document, const QgsReadWriteContext &context ) const;
2038
2050 virtual QString encodedSource( const QString &source, const QgsReadWriteContext &context ) const;
2051
2064 virtual QString decodedSource( const QString &source, const QString &dataProvider, const QgsReadWriteContext &context ) const;
2065
2071 void readCustomProperties( const QDomNode &layerNode, const QString &keyStartsWith = QString() );
2072
2074 void writeCustomProperties( QDomNode &layerNode, QDomDocument &doc ) const;
2075
2077 void readStyleManager( const QDomNode &layerNode );
2079 void writeStyleManager( QDomNode &layerNode, QDomDocument &doc ) const;
2080
2084 void writeCommonStyle( QDomElement &layerElement, QDomDocument &document,
2085 const QgsReadWriteContext &context,
2086 StyleCategories categories = AllStyleCategories ) const;
2087
2091 void readCommonStyle( const QDomElement &layerElement, const QgsReadWriteContext &context,
2092 StyleCategories categories = AllStyleCategories );
2093
2095 void setProviderType( const QString &providerType );
2096
2097#ifndef SIP_RUN
2098#if 0
2100 void connectNotify( const char *signal ) override;
2101#endif
2102#endif
2103
2105 void appendError( const QgsErrorMessage &error ) { mError.append( error );}
2107 void setError( const QgsError &error ) { mError = error;}
2108
2115 void invalidateWgs84Extent();
2116
2118 bool mValid = false;
2119
2122
2124 QString mLayerName;
2125
2126 QString mShortName;
2127 QString mTitle;
2128
2130 QString mAbstract;
2132
2134 QString mDataUrl;
2136
2140
2142 QString mLegendUrl;
2144
2147
2149 QSet<QgsMapLayerDependency> mDependencies;
2150
2156 Q_DECL_DEPRECATED bool hasDependencyCycle( const QSet<QgsMapLayerDependency> & ) const {return false;}
2157
2158 bool mIsRefreshOnNofifyEnabled = false;
2160
2163
2164 //TODO QGIS 4 - move to readXml as a new argument (breaks API)
2165
2168
2174 bool mShouldValidateCrs = true;
2175
2181 double mLayerOpacity = 1.0;
2182
2188 int mBlockStyleChangedSignal = 0;
2189
2190#ifndef SIP_RUN
2191
2200 QString crsHtmlMetadata() const;
2201#endif
2202
2203#ifndef SIP_RUN
2204
2213 QString generalHtmlMetadata() const;
2214#endif
2215
2216#ifndef SIP_RUN
2217
2225 std::unique_ptr<QgsDataProvider> mPreloadedProvider;
2226#endif
2227
2228 private:
2229
2230 virtual QString baseURI( PropertyType type ) const;
2231 QString saveNamedProperty( const QString &uri, QgsMapLayer::PropertyType type,
2232 bool &resultFlag, StyleCategories categories = AllStyleCategories );
2233 QString loadNamedProperty( const QString &uri, QgsMapLayer::PropertyType type,
2234 bool &resultFlag, StyleCategories categories = AllStyleCategories );
2235 bool loadNamedPropertyFromDatabase( const QString &db, const QString &uri, QString &xml, QgsMapLayer::PropertyType type );
2236
2237 // const method because extents are mutable
2238 void updateExtent( const QgsRectangle &extent ) const;
2239 void updateExtent( const QgsBox3D &extent ) const;
2240
2245 virtual bool isReadOnly() const;
2246
2252
2254 QString mID;
2255
2257 Qgis::LayerType mLayerType;
2258
2259 LayerFlags mFlags = LayerFlags( Identifiable | Removable | Searchable );
2260
2262 QPainter::CompositionMode mBlendMode = QPainter::CompositionMode_SourceOver;
2263
2265 QString mTag;
2266
2267 //set some generous defaults for scale based visibility
2268
2270 double mMinScale = 0;
2272 double mMaxScale = 100000000;
2274 bool mScaleBasedVisibility = false;
2275
2279 std::unique_ptr< QgsMapLayerServerProperties > mServerProperties;
2280
2282 QUndoStack *mUndoStack = nullptr;
2283
2284 QUndoStack *mUndoStackStyles = nullptr;
2285
2287 QgsObjectCustomProperties mCustomProperties;
2288
2290 QgsMapLayerLegend *mLegend = nullptr;
2291
2293 QgsMapLayerStyleManager *mStyleManager = nullptr;
2294
2296
2298 QTimer *mRefreshTimer = nullptr;
2299
2300 QgsLayerMetadata mMetadata;
2301
2303 QgsAbstract3DRenderer *m3DRenderer = nullptr;
2304
2306 mutable QgsBox3D mExtent3D;
2307
2309 mutable QgsRectangle mExtent2D;
2310
2312 mutable QgsRectangle mWgs84Extent;
2313
2319 QString mOriginalXmlProperties;
2320
2322 bool mRepaintRequestedFired = false;
2323
2325 QString mLegendPlaceholderImage;
2326
2328 QString mMapTipTemplate;
2329
2331 bool mMapTipsEnabled = true;
2332
2333 friend class QgsVectorLayer;
2334 friend class TestQgsMapLayer;
2335};
2336
2341
2342
2343#ifndef SIP_RUN
2344
2349typedef QPointer< QgsMapLayer > QgsWeakMapLayerPointer;
2350
2355typedef QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList;
2356#endif
2357
2358#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 automatic refresh modes.
Definition: qgis.h:1834
@ 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:43
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.
QFlags< ReadFlag > ReadFlags
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
Definition: qgsmaplayer.h:2131
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:1412
void dependenciesChanged()
Emitted when dependencies are changed.
void setError(const QgsError &error)
Sets error message.
Definition: qgsmaplayer.h:2107
void legendChanged()
Signal emitted when legend of the layer has changed.
QFlags< ReadFlag > ReadFlags
Definition: qgsmaplayer.h:645
QFlags< LayerFlag > LayerFlags
Definition: qgsmaplayer.h:157
void setAbstract(const QString &abstract)
Sets the abstract of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:319
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:1397
void request3DUpdate()
Signal emitted when a layer requires an update in any 3D maps.
QgsError mError
Error.
Definition: qgsmaplayer.h:2146
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:870
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:2156
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:1640
QgsMapLayerServerProperties * serverProperties()
Returns QGIS Server Properties for the map layer.
Definition: qgsmaplayer.h:422
QString attribution() const
Returns the attribution of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:397
QString mRefreshOnNofifyMessage
Definition: qgsmaplayer.h:2159
QString mLegendUrl
WMS legend.
Definition: qgsmaplayer.h:2142
QString mLayerName
Name of the layer - used for display.
Definition: qgsmaplayer.h:2124
void setCustomFlagProperty(const QString &key, const T &value)
Set the value of a property based on a flag.
Definition: qgsmaplayer.h:934
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:405
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:327
virtual QgsMapLayerSelectionProperties * selectionProperties()
Returns the layer's selection properties.
Definition: qgsmaplayer.h:1619
QString dataUrlFormat() const
Returns the DataUrl format of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:378
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:2127
void setDataUrl(const QString &dataUrl)
Sets the DataUrl of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:352
void setKeywordList(const QString &keywords)
Sets the keyword list of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:334
void setAttribution(const QString &attrib)
Sets the attribution of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:388
bool isRefreshOnNotifyEnabled() const
Returns true if the refresh on provider nofification is enabled.
Definition: qgsmaplayer.h:1576
QSet< QgsMapLayerDependency > mDependencies
List of layers that may modify this layer on modification.
Definition: qgsmaplayer.h:2149
void setDataUrlFormat(const QString &dataUrlFormat)
Sets the DataUrl format of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:369
QString mLegendUrlFormat
Definition: qgsmaplayer.h:2143
QFlags< StyleCategory > StyleCategories
Definition: qgsmaplayer.h:188
const QgsMapLayerServerProperties * serverProperties() const
Returns QGIS Server Properties const for the map layer.
Definition: qgsmaplayer.h:428
QString mProviderKey
Data provider key (name of the data provider)
Definition: qgsmaplayer.h:2162
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:2225
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:312
void crsChanged()
Emit a signal that layer's CRS has been reset.
QString mAttributionUrl
Definition: qgsmaplayer.h:2139
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:361
void setRefreshOnNofifyMessage(const QString &message)
Set the notification message that triggers repaint If refresh on notification is enabled,...
Definition: qgsmaplayer.h:1775
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:1626
QString mShortName
Definition: qgsmaplayer.h:2126
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...
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:150
void setLegendPlaceholderImage(const QString &imgPath)
Set placeholder image for legend.
Definition: qgsmaplayer.h:1647
void appendError(const QgsErrorMessage &error)
Add error message.
Definition: qgsmaplayer.h:2105
QString mDataSource
Data source description string, varies by layer type.
Definition: qgsmaplayer.h:2121
virtual bool readSld(const QDomNode &node, QString &errorMessage)
Definition: qgsmaplayer.h:1232
ReadFlag
Flags which control project read behavior.
Definition: qgsmaplayer.h:639
QString attributionUrl() const
Returns the attribution URL of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:414
QString mAbstract
Description of the layer.
Definition: qgsmaplayer.h:2130
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:1402
QString mDataUrlFormat
Definition: qgsmaplayer.h:2135
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:1407
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:1633
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:2134
T customEnumProperty(const QString &key, const T &defaultValue)
Returns the property value for a property based on an enum.
Definition: qgsmaplayer.h:792
StyleCategory
Categories of style to distinguish appropriate sections for import/export.
Definition: qgsmaplayer.h:165
@ AllStyleCategories
Definition: qgsmaplayer.h:184
void layerModified()
Emitted when modifications has been done on layer.
virtual Q_INVOKABLE void reload()
Synchronises with changes in the datasource.
Definition: qgsmaplayer.h:532
void mapTipsEnabledChanged()
Emitted when map tips are enabled or disabled for the layer.
QString mAttribution
Attribution of the layer.
Definition: qgsmaplayer.h:2138
void setCustomEnumProperty(const QString &key, const T &value)
Set the value of a property based on an enum.
Definition: qgsmaplayer.h:844
QString keywordList() const
Returns the keyword list of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:342
void setTitle(const QString &title)
Sets the title of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:304
PropertyType
Maplayer has a style and a metadata property.
Definition: qgsmaplayer.h:139
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:191
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
#define SIP_ENUM_BASETYPE(type)
Definition: qgis_sip.h:278
#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:208
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)
#define QgsDebugError(str)
Definition: qgslogger.h:38
QPointer< QgsMapLayer > QgsWeakMapLayerPointer
Weak pointer for QgsMapLayer.
Definition: qgsmaplayer.h:2349
QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList
A list of weak pointers to QgsMapLayers.
Definition: qgsmaplayer.h:2355
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsTextRendererUtils::CurvedTextFlags)
const QgsCoordinateReferenceSystem & crs
Setting options for creating vector data providers.