QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 
543  virtual QgsMapLayerRenderer *createMapRenderer( QgsRenderContext &rendererContext ) = 0 SIP_FACTORY;
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 
1109  virtual QString saveDefaultStyle( bool &resultFlag SIP_OUT, StyleCategories categories );
1110 
1121  Q_DECL_DEPRECATED virtual QString saveDefaultStyle( bool &resultFlag SIP_OUT ) SIP_DEPRECATED;
1122 
1138  virtual QString saveNamedStyle( const QString &uri, bool &resultFlag SIP_OUT, StyleCategories categories = AllStyleCategories );
1139 
1148  virtual QString saveSldStyle( const QString &uri, bool &resultFlag ) const;
1149 
1158  virtual QString loadSldStyle( const QString &uri, bool &resultFlag );
1159 
1160  virtual bool readSld( const QDomNode &node, QString &errorMessage )
1161  { Q_UNUSED( node ) errorMessage = QStringLiteral( "Layer type %1 not supported" ).arg( static_cast<int>( type() ) ); return false; }
1162 
1163 
1164 
1173  virtual bool readSymbology( const QDomNode &node, QString &errorMessage,
1174  QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories ) = 0;
1175 
1186  virtual bool readStyle( const QDomNode &node, QString &errorMessage,
1187  QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories );
1188 
1199  virtual bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context,
1200  StyleCategories categories = AllStyleCategories ) const = 0;
1201 
1214  virtual bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context,
1215  StyleCategories categories = AllStyleCategories ) const;
1216 
1217 
1232  void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, bool loadDefaultStyleFlag = false );
1233 
1247  void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, bool loadDefaultStyleFlag = false );
1248 
1263  void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags );
1264 
1268  QString providerType() const;
1269 
1271  QUndoStack *undoStack();
1272 
1277  QUndoStack *undoStackStyles();
1278 
1282  void setLegendUrl( const QString &legendUrl ) { mLegendUrl = legendUrl; }
1283 
1287  QString legendUrl() const { return mLegendUrl; }
1288 
1292  void setLegendUrlFormat( const QString &legendUrlFormat ) { mLegendUrlFormat = legendUrlFormat; }
1293 
1297  QString legendUrlFormat() const { return mLegendUrlFormat; }
1298 
1304  void setLegend( QgsMapLayerLegend *legend SIP_TRANSFER );
1305 
1310  QgsMapLayerLegend *legend() const;
1311 
1316  QgsMapLayerStyleManager *styleManager() const;
1317 
1322  void setRenderer3D( QgsAbstract3DRenderer *renderer SIP_TRANSFER );
1323 
1328  QgsAbstract3DRenderer *renderer3D() const;
1329 
1339  bool isInScaleRange( double scale ) const;
1340 
1351  double minimumScale() const;
1352 
1363  double maximumScale() const;
1364 
1373  bool hasScaleBasedVisibility() const;
1374 
1381  bool hasAutoRefreshEnabled() const;
1382 
1390  int autoRefreshInterval() const;
1391 
1403  void setAutoRefreshInterval( int interval );
1404 
1411  void setAutoRefreshEnabled( bool enabled );
1412 
1419  virtual const QgsLayerMetadata &metadata() const;
1420 
1427  virtual void setMetadata( const QgsLayerMetadata &metadata );
1428 
1433  virtual QString htmlMetadata() const;
1434 
1436  virtual QDateTime timestamp() const;
1437 
1445  virtual QSet<QgsMapLayerDependency> dependencies() const;
1446 
1452  QString refreshOnNotifyMessage() const { return mRefreshOnNofifyMessage; }
1453 
1459  bool isRefreshOnNotifyEnabled() const { return mIsRefreshOnNofifyEnabled; }
1460 
1469  QString originalXmlProperties() const;
1470 
1478  void setOriginalXmlProperties( const QString &originalXmlProperties );
1479 
1484  static QString generateId( const QString &layerName );
1485 
1495  virtual bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
1496 
1502  virtual QgsMapLayerTemporalProperties *temporalProperties() { return nullptr; }
1503 
1510 
1516  QString legendPlaceholderImage() const { return mLegendPlaceholderImage;}
1517 
1523  void setLegendPlaceholderImage( const QString &imgPath ) { mLegendPlaceholderImage = imgPath; }
1524 
1525  public slots:
1526 
1536  void setMinimumScale( double scale );
1537 
1547  void setMaximumScale( double scale );
1548 
1556  void setScaleBasedVisibility( bool enabled );
1557 
1566  void triggerRepaint( bool deferredUpdate = false );
1567 
1574  void trigger3DUpdate();
1575 
1580  void emitStyleChanged();
1581 
1590  virtual bool setDependencies( const QSet<QgsMapLayerDependency> &layers );
1591 
1597  void setRefreshOnNotifyEnabled( bool enabled );
1598 
1606  void setRefreshOnNofifyMessage( const QString &message ) { mRefreshOnNofifyMessage = message; }
1607 
1613  virtual void setTransformContext( const QgsCoordinateTransformContext &transformContext ) = 0;
1614 
1615 #ifdef SIP_RUN
1616  SIP_PYOBJECT __repr__();
1617  % MethodCode
1618  QString str = QStringLiteral( "<QgsMapLayer: '%1' (%2)>" ).arg( sipCpp->name(), sipCpp->dataProvider() ? sipCpp->dataProvider()->name() : QStringLiteral( "Invalid" ) );
1619  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
1620  % End
1621 #endif
1622 
1629  QgsProject *project() const;
1630 
1631  signals:
1632 
1639  void beforeResolveReferences( QgsProject *project );
1640 
1642  void statusChanged( const QString &status );
1643 
1649  void nameChanged();
1650 
1652  void crsChanged();
1653 
1660  void repaintRequested( bool deferredUpdate = false );
1661 
1663  void recalculateExtents() const;
1664 
1666  void dataChanged();
1667 
1669  void blendModeChanged( QPainter::CompositionMode blendMode );
1670 
1679  void opacityChanged( double opacity );
1680 
1685  void rendererChanged();
1686 
1698  void styleChanged();
1699 
1704  void legendChanged();
1705 
1710  void renderer3DChanged();
1711 
1717  void request3DUpdate();
1718 
1723  void configChanged();
1724 
1728  void dependenciesChanged();
1729 
1736  void willBeDeleted();
1737 
1743  void autoRefreshIntervalChanged( int interval );
1744 
1751  void metadataChanged();
1752 
1759  void flagsChanged();
1760 
1768  void dataSourceChanged();
1769 
1775  void styleLoaded( QgsMapLayer::StyleCategories categories );
1776 
1782  void isValidChanged();
1783 
1789  void customPropertyChanged( const QString &key );
1790 
1795  void editingStarted();
1796 
1801  void editingStopped();
1802 
1807  void layerModified();
1808 
1809  private slots:
1810 
1811  void onNotified( const QString &message );
1812 
1828  virtual void setDataSourcePrivate( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags );
1829 
1830  protected:
1831 
1837  void clone( QgsMapLayer *layer ) const;
1838 
1840  virtual void setExtent( const QgsRectangle &rect );
1841 
1843  void setValid( bool valid );
1844 
1849  virtual bool readXml( const QDomNode &layer_node, QgsReadWriteContext &context );
1850 
1855  virtual bool writeXml( QDomNode &layer_node, QDomDocument &document, const QgsReadWriteContext &context ) const;
1856 
1868  virtual QString encodedSource( const QString &source, const QgsReadWriteContext &context ) const;
1869 
1882  virtual QString decodedSource( const QString &source, const QString &dataProvider, const QgsReadWriteContext &context ) const;
1883 
1889  void readCustomProperties( const QDomNode &layerNode, const QString &keyStartsWith = QString() );
1890 
1892  void writeCustomProperties( QDomNode &layerNode, QDomDocument &doc ) const;
1893 
1895  void readStyleManager( const QDomNode &layerNode );
1897  void writeStyleManager( QDomNode &layerNode, QDomDocument &doc ) const;
1898 
1903  void writeCommonStyle( QDomElement &layerElement, QDomDocument &document,
1904  const QgsReadWriteContext &context,
1905  StyleCategories categories = AllStyleCategories ) const;
1906 
1911  void readCommonStyle( const QDomElement &layerElement, const QgsReadWriteContext &context,
1912  StyleCategories categories = AllStyleCategories );
1913 
1915  void setProviderType( const QString &providerType );
1916 
1917 #ifndef SIP_RUN
1918 #if 0
1919  void connectNotify( const char *signal ) override;
1921 #endif
1922 #endif
1923 
1925  void appendError( const QgsErrorMessage &error ) { mError.append( error );}
1927  void setError( const QgsError &error ) { mError = error;}
1928 
1935  void invalidateWgs84Extent();
1936 
1938  bool mValid = false;
1939 
1941  QString mDataSource;
1942 
1944  QString mLayerName;
1945 
1946  QString mShortName;
1947  QString mTitle;
1948 
1950  QString mAbstract;
1951  QString mKeywordList;
1952 
1954  QString mDataUrl;
1956 
1958  QString mAttribution;
1960 
1962  QString mLegendUrl;
1964 
1967 
1969  QSet<QgsMapLayerDependency> mDependencies;
1970 
1976  Q_DECL_DEPRECATED bool hasDependencyCycle( const QSet<QgsMapLayerDependency> & ) const {return false;}
1977 
1978  bool mIsRefreshOnNofifyEnabled = false;
1980 
1982  QString mProviderKey;
1983 
1984  //TODO QGIS 4 - move to readXml as a new argument (breaks API)
1985 
1987  QgsMapLayer::ReadFlags mReadFlags = QgsMapLayer::ReadFlags();
1988 
1994  bool mShouldValidateCrs = true;
1995 
2001  double mLayerOpacity = 1.0;
2002 
2008  int mBlockStyleChangedSignal = 0;
2009 
2010 #ifndef SIP_RUN
2011 
2020  QString crsHtmlMetadata() const;
2021 #endif
2022 
2023 #ifndef SIP_RUN
2024 
2033  QString generalHtmlMetadata() const;
2034 #endif
2035 
2036  private:
2037 
2038  virtual QString baseURI( PropertyType type ) const;
2039  QString saveNamedProperty( const QString &uri, QgsMapLayer::PropertyType type,
2040  bool &resultFlag, StyleCategories categories = AllStyleCategories );
2041  QString loadNamedProperty( const QString &uri, QgsMapLayer::PropertyType type,
2042  bool &resultFlag, StyleCategories categories = AllStyleCategories );
2043  bool loadNamedPropertyFromDatabase( const QString &db, const QString &uri, QString &xml, QgsMapLayer::PropertyType type );
2044 
2045  // const method because extents are mutable
2046  void updateExtent( const QgsRectangle &extent ) const;
2047 
2052  virtual bool isReadOnly() const;
2053 
2059 
2061  QString mID;
2062 
2064  QgsMapLayerType mLayerType;
2065 
2066  LayerFlags mFlags = LayerFlags( Identifiable | Removable | Searchable );
2067 
2069  QPainter::CompositionMode mBlendMode = QPainter::CompositionMode_SourceOver;
2070 
2072  QString mTag;
2073 
2074  //set some generous defaults for scale based visibility
2075 
2077  double mMinScale = 0;
2079  double mMaxScale = 100000000;
2081  bool mScaleBasedVisibility = false;
2082 
2086  std::unique_ptr< QgsMapLayerServerProperties > mServerProperties;
2087 
2089  QUndoStack *mUndoStack = nullptr;
2090 
2091  QUndoStack *mUndoStackStyles = nullptr;
2092 
2094  QgsObjectCustomProperties mCustomProperties;
2095 
2097  QgsMapLayerLegend *mLegend = nullptr;
2098 
2100  QgsMapLayerStyleManager *mStyleManager = nullptr;
2101 
2103  QTimer *mRefreshTimer = nullptr;
2104 
2105  QgsLayerMetadata mMetadata;
2106 
2108  QgsAbstract3DRenderer *m3DRenderer = nullptr;
2109 
2111  mutable QgsRectangle mExtent;
2112 
2114  mutable QgsRectangle mWgs84Extent;
2115 
2121  QString mOriginalXmlProperties;
2122 
2124  bool mRepaintRequestedFired = false;
2125 
2127  QString mLegendPlaceholderImage;
2128 
2129  friend class QgsVectorLayer;
2130  friend class TestQgsMapLayer;
2131 };
2132 
2134 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapLayer::LayerFlags )
2135 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapLayer::StyleCategories )
2136 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapLayer::ReadFlags )
2137 
2138 
2139 #ifndef SIP_RUN
2140 
2146 typedef QPointer< QgsMapLayer > QgsWeakMapLayerPointer;
2147 
2153 typedef QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList;
2154 #endif
2155 
2156 #endif
QgsMapLayer::setError
void setError(const QgsError &error)
Sets error message.
Definition: qgsmaplayer.h:1927
qgsmaplayerserverproperties.h
QgsMapLayer::setAbstract
void setAbstract(const QString &abstract)
Sets the abstract of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:318
qgsmaplayerstyle.h
QgsMapLayer::attributionUrl
QString attributionUrl() const
Returns the attribution URL of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:418
QgsCoordinateTransformContext
Contains information about the context in which a coordinate transform is executed.
Definition: qgscoordinatetransformcontext.h:57
QgsMapLayer::refreshOnNotifyMessage
QString refreshOnNotifyMessage() const
Returns the message that should be notified by the provider to triggerRepaint.
Definition: qgsmaplayer.h:1452
QgsWeakMapLayerPointerList
QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList
A list of weak pointers to QgsMapLayers.
Definition: qgsmaplayer.h:2153
QgsMapLayer::dataUrlFormat
QString dataUrlFormat() const
Returns the DataUrl format of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:380
QgsDataProvider::ProviderOptions
Setting options for creating vector data providers.
Definition: qgsdataprovider.h:107
QgsMapLayerType::MeshLayer
@ MeshLayer
Mesh layer. Added in QGIS 3.2.
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:34
QgsDataProvider
Abstract base class for spatial data provider implementations.
Definition: qgsdataprovider.h:40
qgsrectangle.h
QgsMapLayerType::VectorLayer
@ VectorLayer
Vector layer.
QgsMapLayerElevationProperties
Base class for storage of map layer elevation properties.
Definition: qgsmaplayerelevationproperties.h:41
QgsMapLayer::mLegendUrlFormat
QString mLegendUrlFormat
Definition: qgsmaplayer.h:1963
qgsmaplayerdependency.h
QgsAbstract3DRenderer
Base class for all renderers that may to participate in 3D view.
Definition: qgsabstract3drenderer.h:48
QgsMapLayer::mAttributionUrl
QString mAttributionUrl
Definition: qgsmaplayer.h:1959
qgsreadwritecontext.h
SIP_OUT
#define SIP_OUT
Definition: qgis_sip.h:58
crs
const QgsCoordinateReferenceSystem & crs
Definition: qgswfsgetfeature.cpp:105
QgsMapLayer::isRefreshOnNotifyEnabled
bool isRefreshOnNotifyEnabled() const
Returns true if the refresh on provider nofification is enabled.
Definition: qgsmaplayer.h:1459
QgsMapLayerType::AnnotationLayer
@ AnnotationLayer
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
QgsMapLayer::serverProperties
const QgsMapLayerServerProperties * serverProperties() const
Returns QGIS Server Properties const for the map layer.
Definition: qgsmaplayer.h:432
QgsLayerMetadata
A structured metadata store for a map layer.
Definition: qgslayermetadata.h:56
QgsMapLayerType
QgsMapLayerType
Types of layers that can be added to a map.
Definition: qgis.h:46
QgsMapLayer::mDataUrlFormat
QString mDataUrlFormat
Definition: qgsmaplayer.h:1955
QgsError
QgsError is container for error messages (report). It may contain chain (sort of traceback) of error ...
Definition: qgserror.h:80
QgsMapLayerLegend
The QgsMapLayerLegend class is abstract interface for implementations of legends for one map layer.
Definition: qgsmaplayerlegend.h:47
qgis.h
QgsMapLayer::Metadata
@ Metadata
Definition: qgsmaplayer.h:135
QgsRenderContext
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:59
QgsStyleEntityVisitorInterface
An interface for classes which can visit style entity (e.g. symbol) nodes (using the visitor pattern)...
Definition: qgsstyleentityvisitor.h:33
QgsMapLayer::PropertyType
PropertyType
Maplayer has a style and a metadata property.
Definition: qgsmaplayer.h:132
QgsMapLayer::reload
virtual Q_INVOKABLE void reload()
Synchronises with changes in the datasource.
Definition: qgsmaplayer.h:537
QgsMapLayer::ReadFlag
ReadFlag
Flags which control project read behavior.
Definition: qgsmaplayer.h:638
QgsDebugMsg
#define QgsDebugMsg(str)
Definition: qgslogger.h:38
QgsMapLayer::setCustomEnumProperty
void setCustomEnumProperty(const QString &key, const T &value)
Set the value of a property based on an enum.
Definition: qgsmaplayer.h:788
QgsMapLayer::mError
QgsError mError
Error.
Definition: qgsmaplayer.h:1966
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:41
QgsMapLayer::dataUrl
QString dataUrl() const
Returns the DataUrl of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:362
QgsMapLayer::mProviderKey
QString mProviderKey
Data provider key (name of the data provider)
Definition: qgsmaplayer.h:1982
QgsProject
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:103
QgsMapLayerRenderer
Base class for utility classes that encapsulate information necessary for rendering of map layers.
Definition: qgsmaplayerrenderer.h:54
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsMapLayer::setLegendUrlFormat
void setLegendUrlFormat(const QString &legendUrlFormat)
Sets the format for a URL based layer legend.
Definition: qgsmaplayer.h:1292
QgsMapLayer::mLayerName
QString mLayerName
Name of the layer - used for display.
Definition: qgsmaplayer.h:1944
SIP_DEPRECATED
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
SIP_CONVERT_TO_SUBCLASS_CODE
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:186
qgslayermetadata.h
QgsMapLayerStyleManager
Management of styles for use with one map layer.
Definition: qgsmaplayerstylemanager.h:57
qgsobjectcustomproperties.h
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
qgserror.h
QgsMapLayer::customEnumProperty
T customEnumProperty(const QString &key, const T &defaultValue)
Returns the property value for a property based on an enum.
Definition: qgsmaplayer.h:736
QgsMapLayer::keywordList
QString keywordList() const
Returns the keyword list of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:342
QgsMapLayer::readSld
virtual bool readSld(const QDomNode &node, QString &errorMessage)
Definition: qgsmaplayer.h:1160
QgsMapLayer::legendUrlFormat
QString legendUrlFormat() const
Returns the format for a URL based layer legend.
Definition: qgsmaplayer.h:1297
QgsMapLayerType::GroupLayer
@ GroupLayer
Composite group layer. Added in QGIS 3.24.
QgsMapLayer::setCustomFlagProperty
void setCustomFlagProperty(const QString &key, const T &value)
Set the value of a property based on a flag.
Definition: qgsmaplayer.h:878
QgsMapLayer::mAttribution
QString mAttribution
Attribution of the layer.
Definition: qgsmaplayer.h:1958
QgsMapLayerType::RasterLayer
@ RasterLayer
Raster layer.
QgsMapLayer::mDependencies
QSet< QgsMapLayerDependency > mDependencies
List of layers that may modify this layer on modification.
Definition: qgsmaplayer.h:1969
qgis_sip.h
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
QgsMapLayer::temporalProperties
virtual QgsMapLayerTemporalProperties * temporalProperties()
Returns the layer's temporal properties.
Definition: qgsmaplayer.h:1502
Q_DECLARE_OPERATORS_FOR_FLAGS
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.
QgsMapLayer::mTitle
QString mTitle
Definition: qgsmaplayer.h:1947
QgsMapLayerServerProperties
Manages QGIS Server properties for a map layer.
Definition: qgsmaplayerserverproperties.h:272
QgsMapLayer::mDataUrl
QString mDataUrl
DataUrl of the layer.
Definition: qgsmaplayer.h:1954
QgsMapLayer::setKeywordList
void setKeywordList(const QString &keywords)
Sets the keyword list of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:334
QgsMapLayer::title
QString title() const
Returns the title of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:310
QgsMapLayer::setTitle
void setTitle(const QString &title)
Sets the title of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:302
QgsMapLayerTemporalProperties
Base class for storage of map layer temporal properties.
Definition: qgsmaplayertemporalproperties.h:42
QgsMapLayer::mDataSource
QString mDataSource
Data source description string, varies by layer type.
Definition: qgsmaplayer.h:1941
QgsWeakMapLayerPointer
QPointer< QgsMapLayer > QgsWeakMapLayerPointer
Weak pointer for QgsMapLayer.
Definition: qgsmaplayer.h:2146
QgsMapLayer::legendPlaceholderImage
QString legendPlaceholderImage() const
Returns path to the placeholder image or an empty string if a generated legend is shown.
Definition: qgsmaplayer.h:1516
QgsErrorMessage
QgsErrorMessage represents single error message.
Definition: qgserror.h:32
QgsCoordinateReferenceSystem
This class represents a coordinate reference system (CRS).
Definition: qgscoordinatereferencesystem.h:211
QgsMapLayer::setAttributionUrl
void setAttributionUrl(const QString &attribUrl)
Sets the attribution URL of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:409
QgsMapLayer::legendUrl
QString legendUrl() const
Returns the URL for the layer's legend.
Definition: qgsmaplayer.h:1287
QgsMapLayer::appendError
void appendError(const QgsErrorMessage &error)
Add error message.
Definition: qgsmaplayer.h:1925
QgsMapLayer::LayerFlag
LayerFlag
Flags for the map layer.
Definition: qgsmaplayer.h:143
QgsMapLayer::mAbstract
QString mAbstract
Description of the layer.
Definition: qgsmaplayer.h:1950
QgsMapLayer::customFlagProperty
T customFlagProperty(const QString &key, const T &defaultValue)
Returns the property value for a property based on a flag.
Definition: qgsmaplayer.h:814
QgsMapLayer::setRefreshOnNofifyMessage
void setRefreshOnNofifyMessage(const QString &message)
Set the notification message that triggers repaint If refresh on notification is enabled,...
Definition: qgsmaplayer.h:1606
QgsMapLayer::setDataUrlFormat
void setDataUrlFormat(const QString &dataUrlFormat)
Sets the DataUrl format of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:371
str
#define str(x)
Definition: qgis.cpp:37
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
QgsObjectCustomProperties
Simple key-value store (keys = strings, values = variants) that supports loading/saving to/from XML i...
Definition: qgsobjectcustomproperties.h:35
QgsMapLayer
Base class for all map layer types. This is the base class for all map layer types (vector,...
Definition: qgsmaplayer.h:72
QgsMapLayer::setLegendUrl
void setLegendUrl(const QString &legendUrl)
Sets the URL for the layer's legend.
Definition: qgsmaplayer.h:1282
QgsMapLayer::hasDependencyCycle
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:1976
QgsMapLayerType::VectorTileLayer
@ VectorTileLayer
Vector tile layer. Added in QGIS 3.14.
Q_DECLARE_METATYPE
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)
QgsMapLayer::StyleCategory
StyleCategory
Categories of style to distinguish appropriate sections for import/export.
Definition: qgsmaplayer.h:158
qgsdataprovider.h
QgsMapLayer::setAttribution
void setAttribution(const QString &attrib)
Sets the attribution of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:391
QgsMapLayer::mRefreshOnNofifyMessage
QString mRefreshOnNofifyMessage
Definition: qgsmaplayer.h:1979
QgsMapLayer::mLegendUrl
QString mLegendUrl
WMS legend.
Definition: qgsmaplayer.h:1962
QgsMapLayer::serverProperties
QgsMapLayerServerProperties * serverProperties()
Returns QGIS Server Properties for the map layer.
Definition: qgsmaplayer.h:426
QgsMapLayer::setLegendPlaceholderImage
void setLegendPlaceholderImage(const QString &imgPath)
Set placeholder image for legend.
Definition: qgsmaplayer.h:1523
qgslogger.h
QgsMapLayer::setDataUrl
void setDataUrl(const QString &dataUrl)
Sets the DataUrl of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:353
QgsMapLayer::AllStyleCategories
@ AllStyleCategories
Definition: qgsmaplayer.h:178
QgsMapLayerType::PointCloudLayer
@ PointCloudLayer
Point cloud layer. Added in QGIS 3.18.
QgsMapLayer::attribution
QString attribution() const
Returns the attribution of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:400
SIP_END
#define SIP_END
Definition: qgis_sip.h:203
qgscoordinatereferencesystem.h
QgsMapLayer::mKeywordList
QString mKeywordList
Definition: qgsmaplayer.h:1951
QgsMapLayerType::PluginLayer
@ PluginLayer
Plugin based layer.
QgsMapLayer::elevationProperties
virtual QgsMapLayerElevationProperties * elevationProperties()
Returns the layer's elevation properties.
Definition: qgsmaplayer.h:1509
QgsMapLayer::mShortName
QString mShortName
Definition: qgsmaplayer.h:1946