QGIS API Documentation  2.99.0-Master (b8fd1fd)
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 
30 #include "qgis.h"
31 #include "qgserror.h"
33 #include "qgsrectangle.h"
35 #include "qgsrendercontext.h"
36 #include "qgsmaplayerdependency.h"
37 
38 class QgsMapLayerLegend;
41 class QgsPathResolver;
42 class QgsProject;
43 
44 class QDomDocument;
45 class QKeyEvent;
46 class QPainter;
47 
52 class CORE_EXPORT QgsMapLayer : public QObject
53 {
54  Q_OBJECT
55 
56  Q_PROPERTY( QString name READ name WRITE setName NOTIFY nameChanged )
57  Q_PROPERTY( int autoRefreshInterval READ autoRefreshInterval WRITE setAutoRefreshInterval NOTIFY autoRefreshIntervalChanged )
58 
59  public:
60 
62  enum LayerType
63  {
66  PluginLayer
67  };
68 
74  QgsMapLayer( QgsMapLayer::LayerType type = VectorLayer, const QString &name = QString::null, const QString &source = QString::null );
75 
76  virtual ~QgsMapLayer();
77 
79  QgsMapLayer( QgsMapLayer const & ) = delete;
81  QgsMapLayer &operator=( QgsMapLayer const & ) = delete;
82 
85  QgsMapLayer::LayerType type() const;
86 
88  QString id() const;
89 
96  void setName( const QString &name );
97 
102  QString name() const;
103 
107  QString originalName() const { return mLayerOrigName; }
108 
114  void setShortName( const QString &shortName ) { mShortName = shortName; }
115 
121  QString shortName() const { return mShortName; }
122 
128  void setTitle( const QString &title ) { mTitle = title; }
129 
135  QString title() const { return mTitle; }
136 
142  void setAbstract( const QString &abstract ) { mAbstract = abstract; }
143 
149  QString abstract() const { return mAbstract; }
150 
156  void setKeywordList( const QString &keywords ) { mKeywordList = keywords; }
157 
163  QString keywordList() const { return mKeywordList; }
164 
165  /* Layer dataUrl information */
166 
173  void setDataUrl( const QString &dataUrl ) { mDataUrl = dataUrl; }
174 
181  QString dataUrl() const { return mDataUrl; }
182 
189  void setDataUrlFormat( const QString &dataUrlFormat ) { mDataUrlFormat = dataUrlFormat; }
190 
197  QString dataUrlFormat() const { return mDataUrlFormat; }
198 
199  /* Layer attribution information */
200 
207  void setAttribution( const QString &attrib ) { mAttribution = attrib; }
208 
215  QString attribution() const { return mAttribution; }
216 
223  void setAttributionUrl( const QString &attribUrl ) { mAttributionUrl = attribUrl; }
224 
231  QString attributionUrl() const { return mAttributionUrl; }
232 
233  /* Layer metadataUrl information */
234 
241  void setMetadataUrl( const QString &metaUrl ) { mMetadataUrl = metaUrl; }
242 
249  QString metadataUrl() const { return mMetadataUrl; }
250 
257  void setMetadataUrlType( const QString &metaUrlType ) { mMetadataUrlType = metaUrlType; }
258 
265  QString metadataUrlType() const { return mMetadataUrlType; }
266 
273  void setMetadataUrlFormat( const QString &metaUrlFormat ) { mMetadataUrlFormat = metaUrlFormat; }
274 
281  QString metadataUrlFormat() const { return mMetadataUrlFormat; }
282 
287  void setBlendMode( QPainter::CompositionMode blendMode );
288 
292  QPainter::CompositionMode blendMode() const;
293 
295  bool readOnly() const { return isReadOnly(); }
296 
299  virtual void reload() {}
300 
304  virtual QgsMapLayerRenderer *createMapRenderer( QgsRenderContext &rendererContext ) = 0;
305 
307  virtual QgsRectangle extent() const;
308 
313  bool isValid() const;
314 
320  QString publicSource() const;
321 
326  QString source() const;
327 
332  virtual QStringList subLayers() const;
333 
338  virtual void setLayerOrder( const QStringList &layers );
339 
344  virtual void setSubLayerVisibility( const QString &name, bool visible );
345 
347  virtual bool isEditable() const;
348 
352  virtual bool isSpatial() const { return true; }
353 
369  bool readLayerXml( const QDomElement &layerElement, const QgsPathResolver &pathResolver );
370 
387  bool writeLayerXml( QDomElement &layerElement, QDomDocument &document, const QgsPathResolver &pathResolver ) const;
388 
393  void setCustomProperty( const QString &key, const QVariant &value );
394 
398  QVariant customProperty( const QString &value, const QVariant &defaultValue = QVariant() ) const;
399 
403  void removeCustomProperty( const QString &key );
404 
409  virtual QgsError error() const { return mError; }
410 
414  QgsCoordinateReferenceSystem crs() const;
415 
417  void setCrs( const QgsCoordinateReferenceSystem &srs, bool emitSignal = true );
418 
420  static QString capitalizeLayerName( const QString &name );
421 
428  virtual QString styleURI() const;
429 
438  virtual QString loadDefaultStyle( bool &resultFlag );
439 
453  virtual QString loadNamedStyle( const QString &uri, bool &resultFlag );
454 
461  virtual bool loadNamedStyleFromDatabase( const QString &db, const QString &uri, QString &qml );
462 
471  virtual bool importNamedStyle( QDomDocument &doc, QString &errorMsg );
472 
479  virtual void exportNamedStyle( QDomDocument &doc, QString &errorMsg ) const;
480 
481 
488  virtual void exportSldStyle( QDomDocument &doc, QString &errorMsg ) const;
489 
498  virtual QString saveDefaultStyle( bool &resultFlag );
499 
513  virtual QString saveNamedStyle( const QString &uri, bool &resultFlag );
514 
522  virtual QString saveSldStyle( const QString &uri, bool &resultFlag ) const;
523 
531  virtual QString loadSldStyle( const QString &uri, bool &resultFlag );
532 
533  virtual bool readSld( const QDomNode &node, QString &errorMessage )
534  { Q_UNUSED( node ); errorMessage = QStringLiteral( "Layer type %1 not supported" ).arg( type() ); return false; }
535 
536 
537 
543  virtual bool readSymbology( const QDomNode &node, QString &errorMessage ) = 0;
544 
552  virtual bool readStyle( const QDomNode &node, QString &errorMessage );
553 
560  virtual bool writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage ) const = 0;
561 
570  virtual bool writeStyle( QDomNode &node, QDomDocument &doc, QString &errorMessage ) const;
571 
573  QUndoStack *undoStack();
574 
578  QUndoStack *undoStackStyles();
579 
580  /* Layer legendUrl information */
581  void setLegendUrl( const QString &legendUrl ) { mLegendUrl = legendUrl; }
582  QString legendUrl() const { return mLegendUrl; }
583  void setLegendUrlFormat( const QString &legendUrlFormat ) { mLegendUrlFormat = legendUrlFormat; }
584  QString legendUrlFormat() const { return mLegendUrlFormat; }
585 
591  void setLegend( QgsMapLayerLegend *legend );
592 
597  QgsMapLayerLegend *legend() const;
598 
603  QgsMapLayerStyleManager *styleManager() const;
604 
613  bool isInScaleRange( double scale ) const;
614 
623  double minimumScale() const;
624 
633  double maximumScale() const;
634 
642  bool hasScaleBasedVisibility() const;
643 
650  bool hasAutoRefreshEnabled() const;
651 
659  int autoRefreshInterval() const;
660 
672  void setAutoRefreshInterval( int interval );
673 
680  void setAutoRefreshEnabled( bool enabled );
681 
682  public slots:
683 
685  virtual void invalidTransformInput();
686 
694  void setMinimumScale( double scale );
695 
703  void setMaximumScale( double scale );
704 
711  void setScaleBasedVisibility( const bool enabled );
712 
721  void triggerRepaint( bool deferredUpdate = false );
722 
724  virtual QString metadata() const;
725 
727  virtual QDateTime timestamp() const { return QDateTime() ; }
728 
732  void emitStyleChanged();
733 
742  virtual bool setDependencies( const QSet<QgsMapLayerDependency> &layers );
743 
751  virtual QSet<QgsMapLayerDependency> dependencies() const;
752 
753  signals:
754 
756  void statusChanged( const QString &status );
757 
763  void nameChanged();
764 
766  void crsChanged();
767 
773  void repaintRequested( bool deferredUpdate = false );
774 
776  void recalculateExtents() const;
777 
779  void dataChanged();
780 
782  void blendModeChanged( QPainter::CompositionMode blendMode );
783 
787  void rendererChanged();
788 
795  void styleChanged();
796 
801  void legendChanged();
802 
807  void configChanged();
808 
812  void dependenciesChanged();
813 
820  void willBeDeleted();
821 
827  void autoRefreshIntervalChanged( int interval );
828 
829  protected:
831  virtual void setExtent( const QgsRectangle &rect );
832 
834  void setValid( bool valid );
835 
839  virtual bool readXml( const QDomNode &layer_node );
840 
844  virtual bool writeXml( QDomNode &layer_node, QDomDocument &document ) const;
845 
846 
850  void readCustomProperties( const QDomNode &layerNode, const QString &keyStartsWith = "" );
851 
853  void writeCustomProperties( QDomNode &layerNode, QDomDocument &doc ) const;
854 
856  void readStyleManager( const QDomNode &layerNode );
858  void writeStyleManager( QDomNode &layerNode, QDomDocument &doc ) const;
859 
860 #if 0
861  void connectNotify( const char *signal ) override;
863 #endif
864 
866  void appendError( const QgsErrorMessage &error ) { mError.append( error );}
868  void setError( const QgsError &error ) { mError = error;}
869 
872 
874  bool mValid;
875 
877  QString mDataSource;
878 
880  QString mLayerName;
881 
884  QString mLayerOrigName;
885 
886  QString mShortName;
887  QString mTitle;
888 
890  QString mAbstract;
891  QString mKeywordList;
892 
894  QString mDataUrl;
895  QString mDataUrlFormat;
896 
898  QString mAttribution;
900 
902  QString mMetadataUrl;
905 
907  QString mLegendUrl;
909 
912 
914  QSet<QgsMapLayerDependency> mDependencies;
915 
917  bool hasDependencyCycle( const QSet<QgsMapLayerDependency> &layers ) const;
918 
919  private:
920 
925  virtual bool isReadOnly() const { return true; }
926 
930 
932  QString mID;
933 
935  QgsMapLayer::LayerType mLayerType;
936 
938  QPainter::CompositionMode mBlendMode;
939 
941  QString mTag;
942 
944  double mMinScale;
946  double mMaxScale;
948  bool mScaleBasedVisibility;
949 
951  QUndoStack mUndoStack;
952 
953  QUndoStack mUndoStackStyles;
954 
956  QgsObjectCustomProperties mCustomProperties;
957 
959  QgsMapLayerLegend *mLegend = nullptr;
960 
962  QgsMapLayerStyleManager *mStyleManager = nullptr;
963 
965  QTimer mRefreshTimer;
966 
967 };
968 
970 
971 
977 
983 typedef QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList;
984 
985 #endif
QString attributionUrl() const
Returns the attribution URL of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:231
QString mShortName
Definition: qgsmaplayer.h:886
void setMetadataUrl(const QString &metaUrl)
Sets the metadata URL of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:241
QString dataUrlFormat() const
Returns the DataUrl format of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:197
A rectangle specified with double values.
Definition: qgsrectangle.h:36
Base class for all map layer types.
Definition: qgsmaplayer.h:52
void setShortName(const QString &shortName)
Sets the short name of the layer used by QGIS Server to identify the layer.
Definition: qgsmaplayer.h:114
virtual bool isSpatial() const
Returns true if the layer is considered a spatial layer, ie it has some form of geometry associated w...
Definition: qgsmaplayer.h:352
QString mAttributionUrl
Definition: qgsmaplayer.h:899
QString mKeywordList
Definition: qgsmaplayer.h:891
QString shortName() const
Returns the short name of the layer used by QGIS Server to identify the layer.
Definition: qgsmaplayer.h:121
QString mDataUrlFormat
Definition: qgsmaplayer.h:895
QString dataUrl() const
Returns the DataUrl of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:181
virtual QgsError error() const
Get current status error.
Definition: qgsmaplayer.h:409
QString mLegendUrlFormat
Definition: qgsmaplayer.h:908
virtual void reload()
Synchronises with changes in the datasource.
Definition: qgsmaplayer.h:299
Q_DECLARE_METATYPE(QgsMimeDataUtils::UriList)
void setMetadataUrlType(const QString &metaUrlType)
Set the metadata type of the layer used by QGIS Server in GetCapabilities request MetadataUrlType ind...
Definition: qgsmaplayer.h:257
virtual QDateTime timestamp() const
Time stamp of data source in the moment when data/metadata were loaded by provider.
Definition: qgsmaplayer.h:727
QPointer< QgsMapLayer > QgsWeakMapLayerPointer
Weak pointer for QgsMapLayer.
Definition: qgsmaplayer.h:976
QString mLayerName
Name of the layer - used for display.
Definition: qgsmaplayer.h:880
QgsError mError
Error.
Definition: qgsmaplayer.h:911
QgsRectangle mExtent
Extent of the layer.
Definition: qgsmaplayer.h:871
QString mMetadataUrl
MetadataUrl of the layer.
Definition: qgsmaplayer.h:902
void setLegendUrlFormat(const QString &legendUrlFormat)
Definition: qgsmaplayer.h:583
QString metadataUrlFormat() const
Returns the metadata format of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:281
void setKeywordList(const QString &keywords)
Sets the keyword list of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:156
void setTitle(const QString &title)
Sets the title of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:128
QString originalName() const
Returns the original name of the layer.
Definition: qgsmaplayer.h:107
LayerType
Types of layers that can be added to a map.
Definition: qgsmaplayer.h:62
QSet< QgsMapLayerDependency > mDependencies
List of layers that may modify this layer on modification.
Definition: qgsmaplayer.h:914
QString keywordList() const
Returns the keyword list of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:163
QString mDataUrl
DataUrl of the layer.
Definition: qgsmaplayer.h:894
The QgsMapLayerLegend class is abstract interface for implementations of legends for one map layer...
QString legendUrl() const
Definition: qgsmaplayer.h:582
Reads and writes project states.
Definition: qgsproject.h:75
QgsErrorMessage represents single error message.
Definition: qgserror.h:31
bool mValid
Indicates if the layer is valid and can be drawn.
Definition: qgsmaplayer.h:874
void setDataUrlFormat(const QString &dataUrlFormat)
Sets the DataUrl format of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:189
QString mTitle
Definition: qgsmaplayer.h:887
virtual bool readSld(const QDomNode &node, QString &errorMessage)
Definition: qgsmaplayer.h:533
QString legendUrlFormat() const
Definition: qgsmaplayer.h:584
QString mMetadataUrlFormat
Definition: qgsmaplayer.h:904
void setLegendUrl(const QString &legendUrl)
Definition: qgsmaplayer.h:581
void setMetadataUrlFormat(const QString &metaUrlFormat)
Sets the metadata format of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:273
QString title() const
Returns the title of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:135
QString mAttribution
Attribution of the layer.
Definition: qgsmaplayer.h:898
QString mAbstract
Description of the layer.
Definition: qgsmaplayer.h:890
Contains information about the context of a rendering operation.
QString mDataSource
Data source description string, varies by layer type.
Definition: qgsmaplayer.h:877
QgsError is container for error messages (report).
Definition: qgserror.h:82
QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList
A list of weak pointers to QgsMapLayers.
Definition: qgsmaplayer.h:983
QString mLegendUrl
WMS legend.
Definition: qgsmaplayer.h:907
This class represents a coordinate reference system (CRS).
Simple key-value store (keys = strings, values = variants) that supports loading/saving to/from XML i...
void setAttributionUrl(const QString &attribUrl)
Sets the attribution URL of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:223
void appendError(const QgsErrorMessage &error)
Add error message.
Definition: qgsmaplayer.h:866
Base class for utility classes that encapsulate information necessary for rendering of map layers...
bool readOnly() const
Returns if this layer is read only.
Definition: qgsmaplayer.h:295
QString metadataUrl() const
Returns the metadata URL of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:249
void setAttribution(const QString &attrib)
Sets the attribution of the layer used by QGIS Server in GetCapabilities request. ...
Definition: qgsmaplayer.h:207
Resolves relative paths into absolute paths and vice versa.
Management of styles for use with one map layer.
void setDataUrl(const QString &dataUrl)
Sets the DataUrl of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:173
QString mLayerOrigName
Original name of the layer.
Definition: qgsmaplayer.h:884
QString mMetadataUrlType
Definition: qgsmaplayer.h:903
void setError(const QgsError &error)
Set error message.
Definition: qgsmaplayer.h:868
void setAbstract(const QString &abstract)
Sets the abstract of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:142
QString attribution() const
Returns the attribution of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:215
QString metadataUrlType() const
Returns the metadata type of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:265