QGIS API Documentation  3.21.0-Master (909859188c)
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 
31 #include "qgis_sip.h"
32 #include "qgserror.h"
34 #include "qgsrectangle.h"
36 #include "qgsrendercontext.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 
60 /*
61  * Constants used to describe copy-paste MIME types
62  */
63 #define QGSCLIPBOARD_MAPLAYER_MIME "application/qgis.maplayer"
64 
65 
71 class CORE_EXPORT QgsMapLayer : public QObject
72 {
73  Q_OBJECT
74 
75  Q_PROPERTY( QString name READ name WRITE setName NOTIFY nameChanged )
76  Q_PROPERTY( int autoRefreshInterval READ autoRefreshInterval WRITE setAutoRefreshInterval NOTIFY autoRefreshIntervalChanged )
77  Q_PROPERTY( QgsLayerMetadata metadata READ metadata WRITE setMetadata NOTIFY metadataChanged )
78  Q_PROPERTY( QgsCoordinateReferenceSystem crs READ crs WRITE setCrs NOTIFY crsChanged )
79  Q_PROPERTY( QgsMapLayerType type READ type CONSTANT )
80  Q_PROPERTY( bool isValid READ isValid NOTIFY isValidChanged )
81  Q_PROPERTY( double opacity READ opacity WRITE setOpacity NOTIFY opacityChanged )
82 
83 #ifdef SIP_RUN
85  QgsMapLayer *layer = qobject_cast<QgsMapLayer *>( sipCpp );
86 
87  sipType = 0;
88 
89  if ( layer )
90  {
91  switch ( layer->type() )
92  {
94  sipType = sipType_QgsVectorLayer;
95  break;
97  sipType = sipType_QgsRasterLayer;
98  break;
100  sipType = sipType_QgsPluginLayer;
101  break;
103  sipType = sipType_QgsMeshLayer;
104  break;
106  sipType = sipType_QgsVectorTileLayer;
107  break;
109  sipType = sipType_QgsAnnotationLayer;
110  break;
112  sipType = sipType_QgsPointCloudLayer;
113  break;
114  default:
115  sipType = nullptr;
116  break;
117  }
118  }
119  SIP_END
120 #endif
121 
122  public:
123 
129  {
130  Style = 0,
132  };
133 
140  {
141  Identifiable = 1 << 0,
142  Removable = 1 << 1,
143  Searchable = 1 << 2,
144  Private = 1 << 3,
145  };
146  Q_ENUM( LayerFlag )
147  Q_DECLARE_FLAGS( LayerFlags, LayerFlag )
148  Q_FLAG( LayerFlags )
149 
150 
155  {
156  LayerConfiguration = 1 << 0,
157  Symbology = 1 << 1,
158  Symbology3D = 1 << 2,
159  Labeling = 1 << 3,
160  Fields = 1 << 4,
161  Forms = 1 << 5,
162  Actions = 1 << 6,
163  MapTips = 1 << 7,
164  Diagrams = 1 << 8,
165  AttributeTable = 1 << 9,
166  Rendering = 1 << 10,
167  CustomProperties = 1 << 11,
168  GeometryOptions = 1 << 12,
169  Relations = 1 << 13,
170  Temporal = 1 << 14,
171  Legend = 1 << 15,
172  Elevation = 1 << 16,
173  Notes = 1 << 17,
174  AllStyleCategories = LayerConfiguration | Symbology | Symbology3D | Labeling | Fields | Forms | Actions |
175  MapTips | Diagrams | AttributeTable | Rendering | CustomProperties | GeometryOptions | Relations | Temporal | Legend | Elevation | Notes,
176  };
177  Q_ENUM( StyleCategory )
178  Q_DECLARE_FLAGS( StyleCategories, StyleCategory )
179  Q_FLAG( StyleCategories )
180 
181 
187  QgsMapLayer( QgsMapLayerType type = QgsMapLayerType::VectorLayer, const QString &name = QString(), const QString &source = QString() );
188 
189  ~QgsMapLayer() override;
190 
192  QgsMapLayer( QgsMapLayer const & ) = delete;
194  QgsMapLayer &operator=( QgsMapLayer const & ) = delete;
195 
202  virtual QgsMapLayer *clone() const = 0;
203 
207  QgsMapLayerType type() const;
208 
219  QgsMapLayer::LayerFlags flags() const;
220 
231  void setFlags( QgsMapLayer::LayerFlags flags );
232 
242  virtual Qgis::MapLayerProperties properties() const;
243 
249  static QString extensionPropertyType( PropertyType type );
250 
252  QString id() const;
253 
259  void setName( const QString &name );
260 
265  QString name() const;
266 
270  Q_INVOKABLE virtual QgsDataProvider *dataProvider();
271 
276  virtual const QgsDataProvider *dataProvider() const SIP_SKIP;
277 
284  void setShortName( const QString &shortName ) { mShortName = shortName; }
285 
291  QString shortName() const;
292 
298  void setTitle( const QString &title ) { mTitle = title; }
299 
306  QString title() const { return mTitle; }
307 
314  void setAbstract( const QString &abstract ) { mAbstract = abstract; }
315 
322  QString abstract() const { return mAbstract; }
323 
330  void setKeywordList( const QString &keywords ) { mKeywordList = keywords; }
331 
338  QString keywordList() const { return mKeywordList; }
339 
340  /* Layer dataUrl information */
341 
349  void setDataUrl( const QString &dataUrl ) { mDataUrl = dataUrl; }
350 
358  QString dataUrl() const { return mDataUrl; }
359 
367  void setDataUrlFormat( const QString &dataUrlFormat ) { mDataUrlFormat = dataUrlFormat; }
368 
376  QString dataUrlFormat() const { return mDataUrlFormat; }
377 
378  /* Layer attribution information */
379 
387  void setAttribution( const QString &attrib ) { mAttribution = attrib; }
388 
396  QString attribution() const { return mAttribution; }
397 
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 
460  Q_DECL_DEPRECATED void setMetadataUrlType( const QString &metaUrlType ) SIP_DEPRECATED;
461 
471  Q_DECL_DEPRECATED QString metadataUrlType() const SIP_DEPRECATED;
472 
481  Q_DECL_DEPRECATED void setMetadataUrlFormat( const QString &metaUrlFormat ) SIP_DEPRECATED;
482 
492  Q_DECL_DEPRECATED QString metadataUrlFormat() const SIP_DEPRECATED;
493 
499  void setBlendMode( QPainter::CompositionMode blendMode );
500 
505  QPainter::CompositionMode blendMode() const;
506 
515  virtual void setOpacity( double opacity );
516 
525  virtual double opacity() const;
526 
528  bool readOnly() const { return isReadOnly(); }
529 
533  Q_INVOKABLE virtual void reload() {}
534 
540 
542  virtual QgsRectangle extent() const;
543 
552  QgsRectangle wgs84Extent( bool forceRecalculate = false ) const;
553 
559  bool isValid() const;
560 
567  QString publicSource() const;
568 
574  QString source() const;
575 
580  virtual QStringList subLayers() const;
581 
586  virtual void setLayerOrder( const QStringList &layers );
587 
593  virtual void setSubLayerVisibility( const QString &name, bool visible );
594 
601  virtual bool supportsEditing() const;
602 
604  virtual bool isEditable() const;
605 
611  virtual bool isModified() const;
612 
617  virtual bool isSpatial() const;
618 
628  virtual bool isTemporary() const;
629 
634  enum ReadFlag
635  {
636  FlagDontResolveLayers = 1 << 0,
637  FlagTrustLayerMetadata = 1 << 1,
638  FlagReadExtentFromXml = 1 << 2,
639  };
640  Q_DECLARE_FLAGS( ReadFlags, ReadFlag )
641 
642 
659  bool readLayerXml( const QDomElement &layerElement, QgsReadWriteContext &context, QgsMapLayer::ReadFlags flags = QgsMapLayer::ReadFlags() );
660 
678  bool writeLayerXml( QDomElement &layerElement, QDomDocument &document, const QgsReadWriteContext &context ) const;
679 
684  virtual void resolveReferences( QgsProject *project );
685 
691  Q_INVOKABLE QStringList customPropertyKeys() const;
692 
698  Q_INVOKABLE void setCustomProperty( const QString &key, const QVariant &value );
699 
704  Q_INVOKABLE QVariant customProperty( const QString &value, const QVariant &defaultValue = QVariant() ) const;
705 
710  void setCustomProperties( const QgsObjectCustomProperties &properties );
711 
717  const QgsObjectCustomProperties &customProperties() const;
718 
719 #ifndef SIP_RUN
720 
731  template <class T>
732  T customEnumProperty( const QString &key, const T &defaultValue )
733  {
734  const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
735  Q_ASSERT( metaEnum.isValid() );
736  if ( !metaEnum.isValid() )
737  {
738  QgsDebugMsg( QStringLiteral( "Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
739  }
740 
741  T v;
742  bool ok = false;
743 
744  if ( metaEnum.isValid() )
745  {
746  // read as string
747  QByteArray ba = customProperty( key, metaEnum.valueToKey( static_cast<int>( defaultValue ) ) ).toString().toUtf8();
748  const char *vs = ba.data();
749  v = static_cast<T>( metaEnum.keyToValue( vs, &ok ) );
750  if ( ok )
751  return v;
752  }
753 
754  // if failed, try to read as int (old behavior)
755  // this code shall be removed later
756  // then the method could be marked as const
757  v = static_cast<T>( customProperty( key, static_cast<int>( defaultValue ) ).toInt( &ok ) );
758  if ( metaEnum.isValid() )
759  {
760  if ( !ok || !metaEnum.valueToKey( static_cast<int>( v ) ) )
761  {
762  v = defaultValue;
763  }
764  else
765  {
766  // found property as an integer
767  // convert the property to the new form (string)
768  setCustomEnumProperty( key, v );
769  }
770  }
771 
772  return v;
773  }
774 
783  template <class T>
784  void setCustomEnumProperty( const QString &key, const T &value )
785  {
786  const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
787  Q_ASSERT( metaEnum.isValid() );
788  if ( metaEnum.isValid() )
789  {
790  setCustomProperty( key, metaEnum.valueToKey( static_cast<int>( value ) ) );
791  }
792  else
793  {
794  QgsDebugMsg( QStringLiteral( "Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
795  }
796  }
797 
809  template <class T>
810  T customFlagProperty( const QString &key, const T &defaultValue )
811  {
812  const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
813  Q_ASSERT( metaEnum.isValid() );
814  if ( !metaEnum.isValid() )
815  {
816  QgsDebugMsg( QStringLiteral( "Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
817  }
818 
819  T v = defaultValue;
820  bool ok = false;
821 
822  if ( metaEnum.isValid() )
823  {
824  // read as string
825  QByteArray ba = customProperty( key, metaEnum.valueToKeys( defaultValue ) ).toString().toUtf8();
826  const char *vs = ba.data();
827  v = static_cast<T>( metaEnum.keysToValue( vs, &ok ) );
828  }
829  if ( !ok )
830  {
831  // if failed, try to read as int
832  const int intValue = customProperty( key, static_cast<int>( defaultValue ) ).toInt( &ok );
833  if ( metaEnum.isValid() )
834  {
835  if ( ok )
836  {
837  // check that the int value does correspond to a flag
838  // see https://stackoverflow.com/a/68495949/1548052
839  const QByteArray keys = metaEnum.valueToKeys( intValue );
840  const int intValueCheck = metaEnum.keysToValue( keys );
841  if ( intValue != intValueCheck )
842  {
843  v = defaultValue;
844  }
845  else
846  {
847  // found property as an integer
848  v = T( intValue );
849  // convert the property to the new form (string)
850  // this code could be removed
851  // then the method could be marked as const
852  setCustomFlagProperty( key, v );
853  }
854  }
855  else
856  {
857  v = defaultValue;
858  }
859  }
860  }
861 
862  return v;
863  }
864 
873  template <class T>
874  void setCustomFlagProperty( const QString &key, const T &value )
875  {
876  const QMetaEnum metaEnum = QMetaEnum::fromType<T>();
877  Q_ASSERT( metaEnum.isValid() );
878  if ( metaEnum.isValid() )
879  {
880  setCustomProperty( key, metaEnum.valueToKeys( value ) );
881  }
882  else
883  {
884  QgsDebugMsg( QStringLiteral( "Invalid metaenum. Enum probably misses Q_ENUM or Q_FLAG declaration." ) );
885  }
886  }
887 #endif
888 
889 
894  void removeCustomProperty( const QString &key );
895 
901  virtual QgsError error() const;
902 
908 
910  void setCrs( const QgsCoordinateReferenceSystem &srs, bool emitSignal = true );
911 
917  QgsCoordinateTransformContext transformContext( ) const;
918 
919 
925  static QString formatLayerName( const QString &name );
926 
934  virtual QString metadataUri() const;
935 
942  void exportNamedMetadata( QDomDocument &doc, QString &errorMsg ) const;
943 
953  virtual QString saveDefaultMetadata( bool &resultFlag SIP_OUT );
954 
969  QString saveNamedMetadata( const QString &uri, bool &resultFlag );
970 
985  virtual QString loadNamedMetadata( const QString &uri, bool &resultFlag SIP_OUT );
986 
996  virtual QString loadDefaultMetadata( bool &resultFlag );
997 
1006  bool loadNamedMetadataFromDatabase( const QString &db, const QString &uri, QString &qmd );
1007 
1015  bool importNamedMetadata( QDomDocument &document, QString &errorMessage );
1016 
1024  virtual QString styleURI() const;
1025 
1035  virtual QString loadDefaultStyle( bool &resultFlag SIP_OUT );
1036 
1052  virtual QString loadNamedStyle( const QString &uri, bool &resultFlag SIP_OUT, QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories );
1053 
1061  virtual bool loadNamedStyleFromDatabase( const QString &db, const QString &uri, QString &qml SIP_OUT );
1062 
1072  virtual bool importNamedStyle( QDomDocument &doc, QString &errorMsg SIP_OUT,
1073  QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories );
1074 
1083  virtual void exportNamedStyle( QDomDocument &doc, QString &errorMsg SIP_OUT, const QgsReadWriteContext &context = QgsReadWriteContext(),
1084  QgsMapLayer::StyleCategories categories = QgsMapLayer::AllStyleCategories ) const;
1085 
1086 
1093  virtual void exportSldStyle( QDomDocument &doc, QString &errorMsg ) const;
1094 
1104  virtual QString saveDefaultStyle( bool &resultFlag SIP_OUT );
1105 
1121  virtual QString saveNamedStyle( const QString &uri, bool &resultFlag SIP_OUT, StyleCategories categories = AllStyleCategories );
1122 
1131  virtual QString saveSldStyle( const QString &uri, bool &resultFlag ) const;
1132 
1141  virtual QString loadSldStyle( const QString &uri, bool &resultFlag );
1142 
1143  virtual bool readSld( const QDomNode &node, QString &errorMessage )
1144  { Q_UNUSED( node ) errorMessage = QStringLiteral( "Layer type %1 not supported" ).arg( static_cast<int>( type() ) ); return false; }
1145 
1146 
1147 
1156  virtual bool readSymbology( const QDomNode &node, QString &errorMessage,
1157  QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories ) = 0;
1158 
1169  virtual bool readStyle( const QDomNode &node, QString &errorMessage,
1170  QgsReadWriteContext &context, StyleCategories categories = AllStyleCategories );
1171 
1182  virtual bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context,
1183  StyleCategories categories = AllStyleCategories ) const = 0;
1184 
1197  virtual bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context,
1198  StyleCategories categories = AllStyleCategories ) const;
1199 
1200 
1215  void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, bool loadDefaultStyleFlag = false );
1216 
1230  void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, bool loadDefaultStyleFlag = false );
1231 
1246  void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags );
1247 
1251  QString providerType() const;
1252 
1254  QUndoStack *undoStack();
1255 
1260  QUndoStack *undoStackStyles();
1261 
1265  void setLegendUrl( const QString &legendUrl ) { mLegendUrl = legendUrl; }
1266 
1270  QString legendUrl() const { return mLegendUrl; }
1271 
1275  void setLegendUrlFormat( const QString &legendUrlFormat ) { mLegendUrlFormat = legendUrlFormat; }
1276 
1280  QString legendUrlFormat() const { return mLegendUrlFormat; }
1281 
1287  void setLegend( QgsMapLayerLegend *legend SIP_TRANSFER );
1288 
1293  QgsMapLayerLegend *legend() const;
1294 
1299  QgsMapLayerStyleManager *styleManager() const;
1300 
1305  void setRenderer3D( QgsAbstract3DRenderer *renderer SIP_TRANSFER );
1306 
1311  QgsAbstract3DRenderer *renderer3D() const;
1312 
1322  bool isInScaleRange( double scale ) const;
1323 
1334  double minimumScale() const;
1335 
1346  double maximumScale() const;
1347 
1356  bool hasScaleBasedVisibility() const;
1357 
1364  bool hasAutoRefreshEnabled() const;
1365 
1373  int autoRefreshInterval() const;
1374 
1386  void setAutoRefreshInterval( int interval );
1387 
1394  void setAutoRefreshEnabled( bool enabled );
1395 
1402  virtual const QgsLayerMetadata &metadata() const;
1403 
1410  virtual void setMetadata( const QgsLayerMetadata &metadata );
1411 
1416  virtual QString htmlMetadata() const;
1417 
1419  virtual QDateTime timestamp() const;
1420 
1428  virtual QSet<QgsMapLayerDependency> dependencies() const;
1429 
1435  QString refreshOnNotifyMessage() const { return mRefreshOnNofifyMessage; }
1436 
1442  bool isRefreshOnNotifyEnabled() const { return mIsRefreshOnNofifyEnabled; }
1443 
1452  QString originalXmlProperties() const;
1453 
1461  void setOriginalXmlProperties( const QString &originalXmlProperties );
1462 
1467  static QString generateId( const QString &layerName );
1468 
1478  virtual bool accept( QgsStyleEntityVisitorInterface *visitor ) const;
1479 
1485  virtual QgsMapLayerTemporalProperties *temporalProperties() { return nullptr; }
1486 
1493 
1499  QString legendPlaceholderImage() const { return mLegendPlaceholderImage;}
1500 
1506  void setLegendPlaceholderImage( const QString &imgPath ) { mLegendPlaceholderImage = imgPath; }
1507 
1508  public slots:
1509 
1519  void setMinimumScale( double scale );
1520 
1530  void setMaximumScale( double scale );
1531 
1539  void setScaleBasedVisibility( bool enabled );
1540 
1549  void triggerRepaint( bool deferredUpdate = false );
1550 
1557  void trigger3DUpdate();
1558 
1563  void emitStyleChanged();
1564 
1573  virtual bool setDependencies( const QSet<QgsMapLayerDependency> &layers );
1574 
1580  void setRefreshOnNotifyEnabled( bool enabled );
1581 
1589  void setRefreshOnNofifyMessage( const QString &message ) { mRefreshOnNofifyMessage = message; }
1590 
1596  virtual void setTransformContext( const QgsCoordinateTransformContext &transformContext ) = 0;
1597 
1598 #ifdef SIP_RUN
1599  SIP_PYOBJECT __repr__();
1600  % MethodCode
1601  QString str = QStringLiteral( "<QgsMapLayer: '%1' (%2)>" ).arg( sipCpp->name(), sipCpp->dataProvider() ? sipCpp->dataProvider()->name() : QStringLiteral( "Invalid" ) );
1602  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
1603  % End
1604 #endif
1605 
1612  QgsProject *project() const;
1613 
1614  signals:
1615 
1623 
1625  void statusChanged( const QString &status );
1626 
1632  void nameChanged();
1633 
1635  void crsChanged();
1636 
1643  void repaintRequested( bool deferredUpdate = false );
1644 
1646  void recalculateExtents() const;
1647 
1649  void dataChanged();
1650 
1652  void blendModeChanged( QPainter::CompositionMode blendMode );
1653 
1662  void opacityChanged( double opacity );
1663 
1669 
1682 
1688 
1694 
1701 
1707 
1712 
1720 
1726  void autoRefreshIntervalChanged( int interval );
1727 
1735 
1743 
1752 
1758  void styleLoaded( QgsMapLayer::StyleCategories categories );
1759 
1766 
1772  void customPropertyChanged( const QString &key );
1773 
1779 
1785 
1791 
1792  private slots:
1793 
1794  void onNotified( const QString &message );
1795 
1811  virtual void setDataSourcePrivate( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags );
1812 
1813  protected:
1814 
1820  void clone( QgsMapLayer *layer ) const;
1821 
1823  virtual void setExtent( const QgsRectangle &rect );
1824 
1826  void setValid( bool valid );
1827 
1832  virtual bool readXml( const QDomNode &layer_node, QgsReadWriteContext &context );
1833 
1838  virtual bool writeXml( QDomNode &layer_node, QDomDocument &document, const QgsReadWriteContext &context ) const;
1839 
1851  virtual QString encodedSource( const QString &source, const QgsReadWriteContext &context ) const;
1852 
1865  virtual QString decodedSource( const QString &source, const QString &dataProvider, const QgsReadWriteContext &context ) const;
1866 
1872  void readCustomProperties( const QDomNode &layerNode, const QString &keyStartsWith = QString() );
1873 
1875  void writeCustomProperties( QDomNode &layerNode, QDomDocument &doc ) const;
1876 
1878  void readStyleManager( const QDomNode &layerNode );
1880  void writeStyleManager( QDomNode &layerNode, QDomDocument &doc ) const;
1881 
1886  void writeCommonStyle( QDomElement &layerElement, QDomDocument &document,
1887  const QgsReadWriteContext &context,
1888  StyleCategories categories = AllStyleCategories ) const;
1889 
1894  void readCommonStyle( const QDomElement &layerElement, const QgsReadWriteContext &context,
1895  StyleCategories categories = AllStyleCategories );
1896 
1898  void setProviderType( const QString &providerType );
1899 
1900 #ifndef SIP_RUN
1901 #if 0
1903  void connectNotify( const char *signal ) override;
1904 #endif
1905 #endif
1906 
1908  void appendError( const QgsErrorMessage &error ) { mError.append( error );}
1910  void setError( const QgsError &error ) { mError = error;}
1911 
1918  void invalidateWgs84Extent();
1919 
1921  bool mValid = false;
1922 
1924  QString mDataSource;
1925 
1927  QString mLayerName;
1928 
1929  QString mShortName;
1930  QString mTitle;
1931 
1933  QString mAbstract;
1934  QString mKeywordList;
1935 
1937  QString mDataUrl;
1939 
1941  QString mAttribution;
1943 
1945  QString mLegendUrl;
1947 
1950 
1952  QSet<QgsMapLayerDependency> mDependencies;
1953 
1959  Q_DECL_DEPRECATED bool hasDependencyCycle( const QSet<QgsMapLayerDependency> & ) const {return false;}
1960 
1961  bool mIsRefreshOnNofifyEnabled = false;
1963 
1965  QString mProviderKey;
1966 
1967  //TODO QGIS 4 - move to readXml as a new argument (breaks API)
1968 
1970  QgsMapLayer::ReadFlags mReadFlags = QgsMapLayer::ReadFlags();
1971 
1977  bool mShouldValidateCrs = true;
1978 
1984  double mLayerOpacity = 1.0;
1985 
1991  int mBlockStyleChangedSignal = 0;
1992 
1993 #ifndef SIP_RUN
1994 
2003  QString crsHtmlMetadata() const;
2004 #endif
2005 
2006 #ifndef SIP_RUN
2007 
2016  QString generalHtmlMetadata() const;
2017 #endif
2018 
2019  private:
2020 
2021  virtual QString baseURI( PropertyType type ) const;
2022  QString saveNamedProperty( const QString &uri, QgsMapLayer::PropertyType type,
2023  bool &resultFlag, StyleCategories categories = AllStyleCategories );
2024  QString loadNamedProperty( const QString &uri, QgsMapLayer::PropertyType type,
2025  bool &resultFlag, StyleCategories categories = AllStyleCategories );
2026  bool loadNamedPropertyFromDatabase( const QString &db, const QString &uri, QString &xml, QgsMapLayer::PropertyType type );
2027 
2028  // const method because extents are mutable
2029  void updateExtent( const QgsRectangle &extent ) const;
2030 
2035  virtual bool isReadOnly() const;
2036 
2042 
2044  QString mID;
2045 
2047  QgsMapLayerType mLayerType;
2048 
2049  LayerFlags mFlags = LayerFlags( Identifiable | Removable | Searchable );
2050 
2052  QPainter::CompositionMode mBlendMode = QPainter::CompositionMode_SourceOver;
2053 
2055  QString mTag;
2056 
2057  //set some generous defaults for scale based visibility
2058 
2060  double mMinScale = 0;
2062  double mMaxScale = 100000000;
2064  bool mScaleBasedVisibility = false;
2065 
2069  std::unique_ptr< QgsMapLayerServerProperties > mServerProperties;
2070 
2072  QUndoStack *mUndoStack = nullptr;
2073 
2074  QUndoStack *mUndoStackStyles = nullptr;
2075 
2077  QgsObjectCustomProperties mCustomProperties;
2078 
2080  QgsMapLayerLegend *mLegend = nullptr;
2081 
2083  QgsMapLayerStyleManager *mStyleManager = nullptr;
2084 
2086  QTimer *mRefreshTimer = nullptr;
2087 
2088  QgsLayerMetadata mMetadata;
2089 
2091  QgsAbstract3DRenderer *m3DRenderer = nullptr;
2092 
2094  mutable QgsRectangle mExtent;
2095 
2097  mutable QgsRectangle mWgs84Extent;
2098 
2104  QString mOriginalXmlProperties;
2105 
2107  bool mRepaintRequestedFired = false;
2108 
2110  QString mLegendPlaceholderImage;
2111 
2112  friend class QgsVectorLayer;
2113 };
2114 
2116 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapLayer::LayerFlags )
2117 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapLayer::StyleCategories )
2118 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapLayer::ReadFlags )
2119 
2120 
2121 #ifndef SIP_RUN
2122 
2128 typedef QPointer< QgsMapLayer > QgsWeakMapLayerPointer;
2129 
2135 typedef QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList;
2136 #endif
2137 
2138 #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:72
QString mKeywordList
Definition: qgsmaplayer.h:1934
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:1280
void dependenciesChanged()
Emitted when dependencies are changed.
void setError(const QgsError &error)
Sets error message.
Definition: qgsmaplayer.h:1910
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:314
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:1265
void request3DUpdate()
Signal emitted when a layer requires an update in any 3D maps.
QgsError mError
Error.
Definition: qgsmaplayer.h:1949
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:810
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:1959
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:1499
QString attribution() const
Returns the attribution of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:396
QString mRefreshOnNofifyMessage
Definition: qgsmaplayer.h:1962
QString mLegendUrl
WMS legend.
Definition: qgsmaplayer.h:1945
QString mLayerName
Name of the layer - used for display.
Definition: qgsmaplayer.h:1927
void setCustomFlagProperty(const QString &key, const T &value)
Set the value of a property based on a flag.
Definition: qgsmaplayer.h:874
void setAttributionUrl(const QString &attribUrl)
Sets the attribution URL of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:405
const QgsMapLayerServerProperties * serverProperties() const
Returns QGIS Server Properties const for the map layer.
Definition: qgsmaplayer.h:428
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:376
QgsMapLayerServerProperties * serverProperties()
Returns QGIS Server Properties for the map layer.
Definition: qgsmaplayer.h:422
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:1930
void setDataUrl(const QString &dataUrl)
Sets the DataUrl of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:349
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:330
void setAttribution(const QString &attrib)
Sets the attribution of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:387
bool isRefreshOnNotifyEnabled() const
Returns true if the refresh on provider nofification is enabled.
Definition: qgsmaplayer.h:1442
QSet< QgsMapLayerDependency > mDependencies
List of layers that may modify this layer on modification.
Definition: qgsmaplayer.h:1952
void setDataUrlFormat(const QString &dataUrlFormat)
Sets the DataUrl format of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:367
QString mLegendUrlFormat
Definition: qgsmaplayer.h:1946
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:1965
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:306
void crsChanged()
Emit a signal that layer's CRS has been reset.
QString mAttributionUrl
Definition: qgsmaplayer.h:1942
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:358
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:1589
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:1929
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:140
void setLegendPlaceholderImage(const QString &imgPath)
Set placeholder image for legend.
Definition: qgsmaplayer.h:1506
void appendError(const QgsErrorMessage &error)
Add error message.
Definition: qgsmaplayer.h:1908
QgsMapLayer & operator=(QgsMapLayer const &)=delete
QgsMapLayer cannot be copied.
QString mDataSource
Data source description string, varies by layer type.
Definition: qgsmaplayer.h:1924
QString refreshOnNotifyMessage() const
Returns the message that should be notified by the provider to triggerRepaint.
Definition: qgsmaplayer.h:1435
virtual bool readSld(const QDomNode &node, QString &errorMessage)
Definition: qgsmaplayer.h:1143
ReadFlag
Flags which control project read behavior.
Definition: qgsmaplayer.h:635
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:1933
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:1270
QString mDataUrlFormat
Definition: qgsmaplayer.h:1938
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:1275
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:1492
void nameChanged()
Emitted when the name has been changed.
QString mDataUrl
DataUrl of the layer.
Definition: qgsmaplayer.h:1937
T customEnumProperty(const QString &key, const T &defaultValue)
Returns the property value for a property based on an enum.
Definition: qgsmaplayer.h:732
StyleCategory
Categories of style to distinguish appropriate sections for import/export.
Definition: qgsmaplayer.h:155
@ AllStyleCategories
Definition: qgsmaplayer.h:174
void layerModified()
Emitted when modifications has been done on layer.
virtual Q_INVOKABLE void reload()
Synchronises with changes in the datasource.
Definition: qgsmaplayer.h:533
virtual QgsMapLayerTemporalProperties * temporalProperties()
Returns the layer's temporal properties.
Definition: qgsmaplayer.h:1485
QString mAttribution
Attribution of the layer.
Definition: qgsmaplayer.h:1941
void setCustomEnumProperty(const QString &key, const T &value)
Set the value of a property based on an enum.
Definition: qgsmaplayer.h:784
QString keywordList() const
Returns the keyword list of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:338
void setTitle(const QString &title)
Sets the title of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:298
PropertyType
Maplayer has a style and a metadata property.
Definition: qgsmaplayer.h:129
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
Added in 3.18.
@ MeshLayer
Added in 3.2.
@ VectorTileLayer
Added in 3.14.
@ AnnotationLayer
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
#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:2128
QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList
A list of weak pointers to QgsMapLayers.
Definition: qgsmaplayer.h:2135
Q_DECLARE_METATYPE(QgsMeshTimeSettings)
const QgsCoordinateReferenceSystem & crs
Setting options for creating vector data providers.