QGIS API Documentation  3.24.2-Tisler (13c1a02865)
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"
37 #include "qgsmaplayerdependency.h"
38 #include "qgslayermetadata.h"
40 #include "qgsmaplayerstyle.h"
41 #include "qgsreadwritecontext.h"
42 #include "qgsdataprovider.h"
43 #include "qgis.h"
44 #include "qgslogger.h"
45 
47 class QgsDataProvider;
48 class QgsMapLayerLegend;
51 class QgsProject;
55 
56 class QDomDocument;
57 class QKeyEvent;
58 class QPainter;
59 class QgsRenderContext;
60 
61 /*
62  * Constants used to describe copy-paste MIME types
63  */
64 #define QGSCLIPBOARD_MAPLAYER_MIME "application/qgis.maplayer"
65 
66 
72 class 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( QgsMapLayerType 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 
84 #ifdef SIP_RUN
86  QgsMapLayer *layer = qobject_cast<QgsMapLayer *>( sipCpp );
87 
88  sipType = 0;
89 
90  if ( layer )
91  {
92  switch ( layer->type() )
93  {
95  sipType = sipType_QgsVectorLayer;
96  break;
98  sipType = sipType_QgsRasterLayer;
99  break;
101  sipType = sipType_QgsPluginLayer;
102  break;
104  sipType = sipType_QgsMeshLayer;
105  break;
107  sipType = sipType_QgsVectorTileLayer;
108  break;
110  sipType = sipType_QgsAnnotationLayer;
111  break;
113  sipType = sipType_QgsPointCloudLayer;
114  break;
116  sipType = sipType_QgsGroupLayer;
117  break;
118  default:
119  sipType = nullptr;
120  break;
121  }
122  }
123  SIP_END
124 #endif
125 
126  public:
127 
133  {
134  Style = 0,
136  };
137 
144  {
145  Identifiable = 1 << 0,
146  Removable = 1 << 1,
147  Searchable = 1 << 2,
148  Private = 1 << 3,
149  };
150  Q_ENUM( LayerFlag )
151  Q_DECLARE_FLAGS( LayerFlags, LayerFlag )
152  Q_FLAG( LayerFlags )
153 
154 
159  {
160  LayerConfiguration = 1 << 0,
161  Symbology = 1 << 1,
162  Symbology3D = 1 << 2,
163  Labeling = 1 << 3,
164  Fields = 1 << 4,
165  Forms = 1 << 5,
166  Actions = 1 << 6,
167  MapTips = 1 << 7,
168  Diagrams = 1 << 8,
169  AttributeTable = 1 << 9,
170  Rendering = 1 << 10,
171  CustomProperties = 1 << 11,
172  GeometryOptions = 1 << 12,
173  Relations = 1 << 13,
174  Temporal = 1 << 14,
175  Legend = 1 << 15,
176  Elevation = 1 << 16,
177  Notes = 1 << 17,
178  AllStyleCategories = LayerConfiguration | Symbology | Symbology3D | Labeling | Fields | Forms | Actions |
179  MapTips | Diagrams | AttributeTable | Rendering | CustomProperties | GeometryOptions | Relations | Temporal | Legend | Elevation | Notes,
180  };
181  Q_ENUM( StyleCategory )
182  Q_DECLARE_FLAGS( StyleCategories, StyleCategory )
183  Q_FLAG( StyleCategories )
184 
185 
191  QgsMapLayer( QgsMapLayerType type = QgsMapLayerType::VectorLayer, const QString &name = QString(), const QString &source = QString() );
192 
193  ~QgsMapLayer() override;
194 
196  QgsMapLayer( QgsMapLayer const & ) = delete;
198  QgsMapLayer &operator=( QgsMapLayer const & ) = delete;
199 
206  virtual QgsMapLayer *clone() const = 0;
207 
211  QgsMapLayerType type() const;
212 
223  QgsMapLayer::LayerFlags flags() const;
224 
235  void setFlags( QgsMapLayer::LayerFlags flags );
236 
246  virtual Qgis::MapLayerProperties properties() const;
247 
253  static QString extensionPropertyType( PropertyType type );
254 
256  QString id() const;
257 
263  void setName( const QString &name );
264 
269  QString name() const;
270 
274  Q_INVOKABLE virtual QgsDataProvider *dataProvider();
275 
280  virtual const QgsDataProvider *dataProvider() const SIP_SKIP;
281 
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 
318  void setAbstract( const QString &abstract ) { mAbstract = abstract; }
319 
326  QString abstract() const { return mAbstract; }
327 
334  void setKeywordList( const QString &keywords ) { mKeywordList = keywords; }
335 
342  QString keywordList() const { return mKeywordList; }
343 
344  /* Layer dataUrl information */
345 
353  void setDataUrl( const QString &dataUrl ) { mDataUrl = dataUrl; }
354 
362  QString dataUrl() const { return mDataUrl; }
363 
371  void setDataUrlFormat( const QString &dataUrlFormat ) { mDataUrlFormat = dataUrlFormat; }
372 
380  QString dataUrlFormat() const { return mDataUrlFormat; }
381 
382  /* Layer attribution information */
383 
391  void setAttribution( const QString &attrib ) { mAttribution = attrib; }
392 
400  QString attribution() const { return mAttribution; }
401 
409  void setAttributionUrl( const QString &attribUrl ) { mAttributionUrl = attribUrl; }
410 
418  QString attributionUrl() const { return mAttributionUrl; }
419 
420  /* Layer metadataUrl information */
421 
426  QgsMapLayerServerProperties *serverProperties() { return mServerProperties.get(); };
427 
432  const QgsMapLayerServerProperties *serverProperties() const { return mServerProperties.get(); } SIP_SKIP;
433 
442  Q_DECL_DEPRECATED void setMetadataUrl( const QString &metaUrl ) SIP_DEPRECATED;
443 
453  Q_DECL_DEPRECATED QString metadataUrl() const SIP_DEPRECATED;
454 
464  Q_DECL_DEPRECATED void setMetadataUrlType( const QString &metaUrlType ) SIP_DEPRECATED;
465 
475  Q_DECL_DEPRECATED QString metadataUrlType() const SIP_DEPRECATED;
476 
485  Q_DECL_DEPRECATED void setMetadataUrlFormat( const QString &metaUrlFormat ) SIP_DEPRECATED;
486 
496  Q_DECL_DEPRECATED QString metadataUrlFormat() const SIP_DEPRECATED;
497 
503  void setBlendMode( QPainter::CompositionMode blendMode );
504 
509  QPainter::CompositionMode blendMode() const;
510 
519  virtual void setOpacity( double opacity );
520 
529  virtual double opacity() const;
530 
532  bool readOnly() const { return isReadOnly(); }
533 
537  Q_INVOKABLE virtual void reload() {}
538 
544 
546  virtual QgsRectangle extent() const;
547 
556  QgsRectangle wgs84Extent( bool forceRecalculate = false ) const;
557 
563  bool isValid() const;
564 
571  QString publicSource() const;
572 
578  QString source() const;
579 
584  virtual QStringList subLayers() const;
585 
590  virtual void setLayerOrder( const QStringList &layers );
591 
597  virtual void setSubLayerVisibility( const QString &name, bool visible );
598 
605  virtual bool supportsEditing() const;
606 
608  virtual bool isEditable() const;
609 
615  virtual bool isModified() const;
616 
621  virtual bool isSpatial() const;
622 
632  virtual bool isTemporary() const;
633 
638  enum ReadFlag
639  {
640  FlagDontResolveLayers = 1 << 0,
641  FlagTrustLayerMetadata = 1 << 1,
642  FlagReadExtentFromXml = 1 << 2,
643  };
644  Q_DECLARE_FLAGS( ReadFlags, ReadFlag )
645 
646 
663  bool readLayerXml( const QDomElement &layerElement, QgsReadWriteContext &context, QgsMapLayer::ReadFlags flags = QgsMapLayer::ReadFlags() );
664 
682  bool writeLayerXml( QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context ) const;
683 
688  virtual void resolveReferences( QgsProject *project );
689 
695  Q_INVOKABLE QStringList customPropertyKeys() const;
696 
702  Q_INVOKABLE void setCustomProperty( const QString &key, const QVariant &value );
703 
708  Q_INVOKABLE QVariant customProperty( const QString &value, const QVariant &defaultValue = QVariant() ) const;
709 
714  void setCustomProperties( const QgsObjectCustomProperties &properties );
715 
721  const QgsObjectCustomProperties &customProperties() const;
722 
723 #ifndef SIP_RUN
724 
735  template <class T>
736  T customEnumProperty( const QString &key, const T &defaultValue )
737  {
738  const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
739  Q_ASSERT( metaEnum.isValid() );
740  if ( !metaEnum.isValid() )
741  {
742  QgsDebugMsg( QStringLiteral( "Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
743  }
744 
745  T v;
746  bool ok = false;
747 
748  if ( metaEnum.isValid() )
749  {
750  // read as string
751  QByteArray ba = customProperty( key, metaEnum.valueToKey( static_cast<int>( defaultValue ) ) ).toString().toUtf8();
752  const char *vs = ba.data();
753  v = static_cast<T>( metaEnum.keyToValue( vs, &ok ) );
754  if ( ok )
755  return v;
756  }
757 
758  // if failed, try to read as int (old behavior)
759  // this code shall be removed later
760  // then the method could be marked as const
761  v = static_cast<T>( customProperty( key, static_cast<int>( defaultValue ) ).toInt( &ok ) );
762  if ( metaEnum.isValid() )
763  {
764  if ( !ok || !metaEnum.valueToKey( static_cast<int>( v ) ) )
765  {
766  v = defaultValue;
767  }
768  else
769  {
770  // found property as an integer
771  // convert the property to the new form (string)
772  setCustomEnumProperty( key, v );
773  }
774  }
775 
776  return v;
777  }
778 
787  template <class T>
788  void setCustomEnumProperty( const QString &key, const T &value )
789  {
790  const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
791  Q_ASSERT( metaEnum.isValid() );
792  if ( metaEnum.isValid() )
793  {
794  setCustomProperty( key, metaEnum.valueToKey( static_cast<int>( value ) ) );
795  }
796  else
797  {
798  QgsDebugMsg( QStringLiteral( "Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
799  }
800  }
801 
813  template <class T>
814  T customFlagProperty( const QString &key, const T &defaultValue )
815  {
816  const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
817  Q_ASSERT( metaEnum.isValid() );
818  if ( !metaEnum.isValid() )
819  {
820  QgsDebugMsg( QStringLiteral( "Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
821  }
822 
823  T v = defaultValue;
824  bool ok = false;
825 
826  if ( metaEnum.isValid() )
827  {
828  // read as string
829  QByteArray ba = customProperty( key, metaEnum.valueToKeys( defaultValue ) ).toString().toUtf8();
830  const char *vs = ba.data();
831  v = static_cast<T>( metaEnum.keysToValue( vs, &ok ) );
832  }
833  if ( !ok )
834  {
835  // if failed, try to read as int
836  const int intValue = customProperty( key, static_cast<int>( defaultValue ) ).toInt( &ok );
837  if ( metaEnum.isValid() )
838  {
839  if ( ok )
840  {
841  // check that the int value does correspond to a flag
842  // see https://stackoverflow.com/a/68495949/1548052
843  const QByteArray keys = metaEnum.valueToKeys( intValue );
844  const int intValueCheck = metaEnum.keysToValue( keys );
845  if ( intValue != intValueCheck )
846  {
847  v = defaultValue;
848  }
849  else
850  {
851  // found property as an integer
852  v = T( intValue );
853  // convert the property to the new form (string)
854  // this code could be removed
855  // then the method could be marked as const
856  setCustomFlagProperty( key, v );
857  }
858  }
859  else
860  {
861  v = defaultValue;
862  }
863  }
864  }
865 
866  return v;
867  }
868 
877  template <class T>
878  void setCustomFlagProperty( const QString &key, const T &value )
879  {
880  const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
881  Q_ASSERT( metaEnum.isValid() );
882  if ( metaEnum.isValid() )
883  {
884  setCustomProperty( key, metaEnum.valueToKeys( value ) );
885  }
886  else
887  {
888  QgsDebugMsg( QStringLiteral( "Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
889  }
890  }
891 #endif
892 
893 
898  void removeCustomProperty( const QString &key );
899 
905  virtual QgsError error() const;
906 
912 
914  void setCrs( const QgsCoordinateReferenceSystem &srs, bool emitSignal = true );
915 
921  QgsCoordinateTransformContext transformContext( ) const;
922 
923 
929  static QString formatLayerName( const QString &name );
930 
938  virtual QString metadataUri() const;
939 
946  void exportNamedMetadata( QDomDocument &doc, QString &errorMsg ) const;
947 
957  virtual QString saveDefaultMetadata( bool &resultFlag SIP_OUT );
958 
973  QString saveNamedMetadata( const QString &uri, bool &resultFlag );
974 
989  virtual QString loadNamedMetadata( const QString &uri, bool &resultFlag SIP_OUT );
990 
1000  virtual QString loadDefaultMetadata( bool &resultFlag );
1001 
1010  bool loadNamedMetadataFromDatabase( const QString &db, const QString &uri, QString &qmd );
1011 
1019  bool importNamedMetadata( QDomDocument &document, QString &errorMessage );
1020 
1028  virtual QString styleURI() const;
1029 
1039  virtual QString loadDefaultStyle( bool &resultFlag SIP_OUT );
1040 
1056  virtual QString loadNamedStyle( const QString &uri, bool &resultFlag SIP_OUT, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories );
1057 
1065  virtual bool loadNamedStyleFromDatabase( const QString &db, const QString &uri, QString &qml SIP_OUT );
1066 
1076  virtual bool importNamedStyle( QDomDocument &doc, QString &errorMsg SIP_OUT,
1077  QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories );
1078 
1087  virtual void exportNamedStyle( QDomDocument &doc, QString &errorMsg SIP_OUT, const QgsReadWriteContext &context = QgsReadWriteContext(),
1088  QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) const;
1089 
1090 
1097  virtual void exportSldStyle( QDomDocument &doc, QString &errorMsg ) const;
1098 
1108  virtual QString saveDefaultStyle( bool &resultFlag SIP_OUT );
1109 
1125  virtual QString saveNamedStyle( const QString &uri, bool &resultFlag SIP_OUT, StyleCategories categories = AllStyleCategories );
1126 
1135  virtual QString saveSldStyle( const QString &uri, bool &resultFlag ) const;
1136 
1145  virtual QString loadSldStyle( const QString &uri, bool &resultFlag );
1146 
1147  virtual bool readSld( const QDomNode &node, QString &errorMessage )
1148  { Q_UNUSED( node ) errorMessage = QStringLiteral( "Layer type %1 not supported" ).arg( static_cast<int>( type() ) ); return false; }
1149 
1150 
1151 
1160  virtual bool readSymbology( const QDomNode &node, QString &errorMessage,
1161  QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories ) = 0;
1162 
1173  virtual bool readStyle( const QDomNode &node, QString &errorMessage,
1174  QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories );
1175 
1186  virtual bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context,
1187  StyleCategories categories = AllStyleCategories ) const = 0;
1188 
1201  virtual bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context,
1202  StyleCategories categories = AllStyleCategories ) const;
1203 
1204 
1219  void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, bool loadDefaultStyleFlag = false );
1220 
1234  void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, bool loadDefaultStyleFlag = false );
1235 
1250  void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags );
1251 
1255  QString providerType() const;
1256 
1258  QUndoStack *undoStack();
1259 
1264  QUndoStack *undoStackStyles();
1265 
1269  void setLegendUrl( const QString &legendUrl ) { mLegendUrl = legendUrl; }
1270 
1274  QString legendUrl() const { return mLegendUrl; }
1275 
1279  void setLegendUrlFormat( const QString &legendUrlFormat ) { mLegendUrlFormat = legendUrlFormat; }
1280 
1284  QString legendUrlFormat() const { return mLegendUrlFormat; }
1285 
1291  void setLegend( QgsMapLayerLegend *legend SIP_TRANSFER );
1292 
1297  QgsMapLayerLegend *legend() const;
1298 
1303  QgsMapLayerStyleManager *styleManager() const;
1304 
1309  void setRenderer3D( QgsAbstract3DRenderer *renderer SIP_TRANSFER );
1310 
1315  QgsAbstract3DRenderer *renderer3D() const;
1316 
1326  bool isInScaleRange( double scale ) const;
1327 
1338  double minimumScale() const;
1339 
1350  double maximumScale() const;
1351 
1360  bool hasScaleBasedVisibility() const;
1361 
1368  bool hasAutoRefreshEnabled() const;
1369 
1377  int autoRefreshInterval() const;
1378 
1390  void setAutoRefreshInterval( int interval );
1391 
1398  void setAutoRefreshEnabled( bool enabled );
1399 
1406  virtual const QgsLayerMetadata &metadata() const;
1407 
1414  virtual void setMetadata( const QgsLayerMetadata &metadata );
1415 
1420  virtual QString htmlMetadata() const;
1421 
1423  virtual QDateTime timestamp() const;
1424 
1432  virtual QSet<QgsMapLayerDependency> dependencies() const;
1433 
1439  QString refreshOnNotifyMessage() const { return mRefreshOnNofifyMessage; }
1440 
1446  bool isRefreshOnNotifyEnabled() const { return mIsRefreshOnNofifyEnabled; }
1447 
1456  QString originalXmlProperties() const;
1457 
1465  void setOriginalXmlProperties( const QString &originalXmlProperties );
1466 
1471  static QString generateId( const QString &layerName );
1472 
1482  virtual bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
1483 
1489  virtual QgsMapLayerTemporalProperties *temporalProperties() { return nullptr; }
1490 
1497 
1503  QString legendPlaceholderImage() const { return mLegendPlaceholderImage;}
1504 
1510  void setLegendPlaceholderImage( const QString &imgPath ) { mLegendPlaceholderImage = imgPath; }
1511 
1512  public slots:
1513 
1523  void setMinimumScale( double scale );
1524 
1534  void setMaximumScale( double scale );
1535 
1543  void setScaleBasedVisibility( bool enabled );
1544 
1553  void triggerRepaint( bool deferredUpdate = false );
1554 
1561  void trigger3DUpdate();
1562 
1567  void emitStyleChanged();
1568 
1577  virtual bool setDependencies( const QSet<QgsMapLayerDependency> &layers );
1578 
1584  void setRefreshOnNotifyEnabled( bool enabled );
1585 
1593  void setRefreshOnNofifyMessage( const QString &message ) { mRefreshOnNofifyMessage = message; }
1594 
1600  virtual void setTransformContext( const QgsCoordinateTransformContext &transformContext ) = 0;
1601 
1602 #ifdef SIP_RUN
1603  SIP_PYOBJECT __repr__();
1604  % MethodCode
1605  QString str = QStringLiteral( "<QgsMapLayer: '%1' (%2)>" ).arg( sipCpp->name(), sipCpp->dataProvider() ? sipCpp->dataProvider()->name() : QStringLiteral( "Invalid" ) );
1606  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
1607  % End
1608 #endif
1609 
1616  QgsProject *project() const;
1617 
1618  signals:
1619 
1627 
1629  void statusChanged( const QString &status );
1630 
1636  void nameChanged();
1637 
1639  void crsChanged();
1640 
1647  void repaintRequested( bool deferredUpdate = false );
1648 
1650  void recalculateExtents() const;
1651 
1653  void dataChanged();
1654 
1656  void blendModeChanged( QPainter::CompositionMode blendMode );
1657 
1666  void opacityChanged( double opacity );
1667 
1673 
1686 
1692 
1698 
1705 
1711 
1716 
1724 
1730  void autoRefreshIntervalChanged( int interval );
1731 
1739 
1747 
1756 
1762  void styleLoaded( QgsMapLayer::StyleCategories categories );
1763 
1770 
1776  void customPropertyChanged( const QString &key );
1777 
1783 
1789 
1795 
1796  private slots:
1797 
1798  void onNotified( const QString &message );
1799 
1815  virtual void setDataSourcePrivate( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags );
1816 
1817  protected:
1818 
1824  void clone( QgsMapLayer *layer ) const;
1825 
1827  virtual void setExtent( const QgsRectangle &rect );
1828 
1830  void setValid( bool valid );
1831 
1836  virtual bool readXml( const QDomNode &layer_node, QgsReadWriteContext &context );
1837 
1842  virtual bool writeXml( QDomNode &layer_node, QDomDocument &document, const QgsReadWriteContext &context ) const;
1843 
1855  virtual QString encodedSource( const QString &source, const QgsReadWriteContext &context ) const;
1856 
1869  virtual QString decodedSource( const QString &source, const QString &dataProvider, const QgsReadWriteContext &context ) const;
1870 
1876  void readCustomProperties( const QDomNode &layerNode, const QString &keyStartsWith = QString() );
1877 
1879  void writeCustomProperties( QDomNode &layerNode, QDomDocument &doc ) const;
1880 
1882  void readStyleManager( const QDomNode &layerNode );
1884  void writeStyleManager( QDomNode &layerNode, QDomDocument &doc ) const;
1885 
1890  void writeCommonStyle( QDomElement &layerElement, QDomDocument &document,
1891  const QgsReadWriteContext &context,
1892  StyleCategories categories = AllStyleCategories ) const;
1893 
1898  void readCommonStyle( const QDomElement &layerElement, const QgsReadWriteContext &context,
1899  StyleCategories categories = AllStyleCategories );
1900 
1902  void setProviderType( const QString &providerType );
1903 
1904 #ifndef SIP_RUN
1905 #if 0
1907  void connectNotify( const char *signal ) override;
1908 #endif
1909 #endif
1910 
1912  void appendError( const QgsErrorMessage &error ) { mError.append( error );}
1914  void setError( const QgsError &error ) { mError = error;}
1915 
1922  void invalidateWgs84Extent();
1923 
1925  bool mValid = false;
1926 
1928  QString mDataSource;
1929 
1931  QString mLayerName;
1932 
1933  QString mShortName;
1934  QString mTitle;
1935 
1937  QString mAbstract;
1938  QString mKeywordList;
1939 
1941  QString mDataUrl;
1943 
1945  QString mAttribution;
1947 
1949  QString mLegendUrl;
1951 
1954 
1956  QSet<QgsMapLayerDependency> mDependencies;
1957 
1963  Q_DECL_DEPRECATED bool hasDependencyCycle( const QSet<QgsMapLayerDependency> & ) const {return false;}
1964 
1965  bool mIsRefreshOnNofifyEnabled = false;
1967 
1969  QString mProviderKey;
1970 
1971  //TODO QGIS 4 - move to readXml as a new argument (breaks API)
1972 
1974  QgsMapLayer::ReadFlags mReadFlags = QgsMapLayer::ReadFlags();
1975 
1981  bool mShouldValidateCrs = true;
1982 
1988  double mLayerOpacity = 1.0;
1989 
1995  int mBlockStyleChangedSignal = 0;
1996 
1997 #ifndef SIP_RUN
1998 
2007  QString crsHtmlMetadata() const;
2008 #endif
2009 
2010 #ifndef SIP_RUN
2011 
2020  QString generalHtmlMetadata() const;
2021 #endif
2022 
2023  private:
2024 
2025  virtual QString baseURI( PropertyType type ) const;
2026  QString saveNamedProperty( const QString &uri, QgsMapLayer::PropertyType type,
2027  bool &resultFlag, StyleCategories categories = AllStyleCategories );
2028  QString loadNamedProperty( const QString &uri, QgsMapLayer::PropertyType type,
2029  bool &resultFlag, StyleCategories categories = AllStyleCategories );
2030  bool loadNamedPropertyFromDatabase( const QString &db, const QString &uri, QString &xml, QgsMapLayer::PropertyType type );
2031 
2032  // const method because extents are mutable
2033  void updateExtent( const QgsRectangle &extent ) const;
2034 
2039  virtual bool isReadOnly() const;
2040 
2046 
2048  QString mID;
2049 
2051  QgsMapLayerType mLayerType;
2052 
2053  LayerFlags mFlags = LayerFlags( Identifiable | Removable | Searchable );
2054 
2056  QPainter::CompositionMode mBlendMode = QPainter::CompositionMode_SourceOver;
2057 
2059  QString mTag;
2060 
2061  //set some generous defaults for scale based visibility
2062 
2064  double mMinScale = 0;
2066  double mMaxScale = 100000000;
2068  bool mScaleBasedVisibility = false;
2069 
2073  std::unique_ptr< QgsMapLayerServerProperties > mServerProperties;
2074 
2076  QUndoStack *mUndoStack = nullptr;
2077 
2078  QUndoStack *mUndoStackStyles = nullptr;
2079 
2081  QgsObjectCustomProperties mCustomProperties;
2082 
2084  QgsMapLayerLegend *mLegend = nullptr;
2085 
2087  QgsMapLayerStyleManager *mStyleManager = nullptr;
2088 
2090  QTimer *mRefreshTimer = nullptr;
2091 
2092  QgsLayerMetadata mMetadata;
2093 
2095  QgsAbstract3DRenderer *m3DRenderer = nullptr;
2096 
2098  mutable QgsRectangle mExtent;
2099 
2101  mutable QgsRectangle mWgs84Extent;
2102 
2108  QString mOriginalXmlProperties;
2109 
2111  bool mRepaintRequestedFired = false;
2112 
2114  QString mLegendPlaceholderImage;
2115 
2116  friend class QgsVectorLayer;
2117  friend class TestQgsMapLayer;
2118 };
2119 
2121 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapLayer::LayerFlags )
2122 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapLayer::StyleCategories )
2123 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapLayer::ReadFlags )
2124 
2125 
2126 #ifndef SIP_RUN
2127 
2133 typedef QPointer< QgsMapLayer > QgsWeakMapLayerPointer;
2134 
2140 typedef QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList;
2141 #endif
2142 
2143 #endif
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:1938
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:1284
void dependenciesChanged()
Emitted when dependencies are changed.
void setError(const QgsError &error)
Sets error message.
Definition: qgsmaplayer.h:1914
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:1269
void request3DUpdate()
Signal emitted when a layer requires an update in any 3D maps.
QgsError mError
Error.
Definition: qgsmaplayer.h:1953
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:814
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:1963
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:1503
QString attribution() const
Returns the attribution of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:400
QString mRefreshOnNofifyMessage
Definition: qgsmaplayer.h:1966
QString mLegendUrl
WMS legend.
Definition: qgsmaplayer.h:1949
QString mLayerName
Name of the layer - used for display.
Definition: qgsmaplayer.h:1931
void setCustomFlagProperty(const QString &key, const T &value)
Set the value of a property based on a flag.
Definition: qgsmaplayer.h:878
void setAttributionUrl(const QString &attribUrl)
Sets the attribution URL of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:409
const QgsMapLayerServerProperties * serverProperties() const
Returns QGIS Server Properties const for the map layer.
Definition: qgsmaplayer.h:432
void renderer3DChanged()
Signal emitted when 3D renderer associated with the layer has changed.
QString dataUrlFormat() const
Returns the DataUrl format of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:380
QgsMapLayerServerProperties * serverProperties()
Returns QGIS Server Properties for the map layer.
Definition: qgsmaplayer.h:426
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:1934
void setDataUrl(const QString &dataUrl)
Sets the DataUrl of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:353
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:334
void setAttribution(const QString &attrib)
Sets the attribution of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:391
bool isRefreshOnNotifyEnabled() const
Returns true if the refresh on provider nofification is enabled.
Definition: qgsmaplayer.h:1446
QSet< QgsMapLayerDependency > mDependencies
List of layers that may modify this layer on modification.
Definition: qgsmaplayer.h:1956
void setDataUrlFormat(const QString &dataUrlFormat)
Sets the DataUrl format of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:371
QString mLegendUrlFormat
Definition: qgsmaplayer.h:1950
virtual QgsMapLayerRenderer * createMapRenderer(QgsRenderContext &rendererContext)=0
Returns new instance of QgsMapLayerRenderer that will be used for rendering of given context.
QString mProviderKey
Data provider key (name of the data provider)
Definition: qgsmaplayer.h:1969
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:1946
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:362
virtual QgsMapLayer * clone() const =0
Returns a new instance equivalent to this one except for the id which is still unique.
void setRefreshOnNofifyMessage(const QString &message)
Set the notification message that triggers repaint If refresh on notification is enabled,...
Definition: qgsmaplayer.h:1593
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.
QString mShortName
Definition: qgsmaplayer.h:1933
void dataChanged()
Data of layer changed.
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:144
void setLegendPlaceholderImage(const QString &imgPath)
Set placeholder image for legend.
Definition: qgsmaplayer.h:1510
void appendError(const QgsErrorMessage &error)
Add error message.
Definition: qgsmaplayer.h:1912
QgsMapLayer & operator=(QgsMapLayer const &)=delete
QgsMapLayer cannot be copied.
QString mDataSource
Data source description string, varies by layer type.
Definition: qgsmaplayer.h:1928
QString refreshOnNotifyMessage() const
Returns the message that should be notified by the provider to triggerRepaint.
Definition: qgsmaplayer.h:1439
virtual bool readSld(const QDomNode &node, QString &errorMessage)
Definition: qgsmaplayer.h:1147
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:418
QString mAbstract
Description of the layer.
Definition: qgsmaplayer.h:1937
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:1274
QString mDataUrlFormat
Definition: qgsmaplayer.h:1942
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:1279
void beforeResolveReferences(QgsProject *project)
Emitted when all layers are loaded and references can be resolved, just before the references of this...
virtual void setTransformContext(const QgsCoordinateTransformContext &transformContext)=0
Sets the coordinate transform context to transformContext.
virtual QgsMapLayerElevationProperties * elevationProperties()
Returns the layer's elevation properties.
Definition: qgsmaplayer.h:1496
void nameChanged()
Emitted when the name has been changed.
QString mDataUrl
DataUrl of the layer.
Definition: qgsmaplayer.h:1941
T customEnumProperty(const QString &key, const T &defaultValue)
Returns the property value for a property based on an enum.
Definition: qgsmaplayer.h:736
StyleCategory
Categories of style to distinguish appropriate sections for import/export.
Definition: qgsmaplayer.h:159
@ AllStyleCategories
Definition: qgsmaplayer.h:178
void layerModified()
Emitted when modifications has been done on layer.
virtual Q_INVOKABLE void reload()
Synchronises with changes in the datasource.
Definition: qgsmaplayer.h:537
virtual QgsMapLayerTemporalProperties * temporalProperties()
Returns the layer's temporal properties.
Definition: qgsmaplayer.h:1489
QString mAttribution
Attribution of the layer.
Definition: qgsmaplayer.h:1945
void setCustomEnumProperty(const QString &key, const T &value)
Set the value of a property based on an enum.
Definition: qgsmaplayer.h:788
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:302
PropertyType
Maplayer has a style and a metadata property.
Definition: qgsmaplayer.h:133
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:101
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.
An interface for classes which can visit style entity (e.g.
Represents a vector layer which manages a vector based data sets.
QgsMapLayerType
Types of layers that can be added to a map.
Definition: qgis.h:47
@ PointCloudLayer
Point cloud layer. Added in QGIS 3.18.
@ MeshLayer
Mesh layer. Added in QGIS 3.2.
@ VectorLayer
Vector layer.
@ RasterLayer
Raster layer.
@ GroupLayer
Composite group layer. Added in QGIS 3.24.
@ VectorTileLayer
Vector tile layer. Added in QGIS 3.14.
@ AnnotationLayer
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
@ PluginLayer
Plugin based layer.
#define str(x)
Definition: qgis.cpp:37
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:177
#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:194
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:2133
QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList
A list of weak pointers to QgsMapLayers.
Definition: qgsmaplayer.h:2140
Q_DECLARE_METATYPE(QgsMeshTimeSettings)
const QgsCoordinateReferenceSystem & crs
Setting options for creating vector data providers.