QGIS API Documentation  2.99.0-Master (0a63d1f)
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 
42 class QDomDocument;
43 class QKeyEvent;
44 class QPainter;
45 
50 class CORE_EXPORT QgsMapLayer : public QObject
51 {
52  Q_OBJECT
53 
54  Q_PROPERTY( QString name READ name WRITE setName NOTIFY nameChanged )
55 
56  public:
57 
59  enum LayerType
60  {
63  PluginLayer
64  };
65 
71  QgsMapLayer( QgsMapLayer::LayerType type = VectorLayer, const QString& name = QString::null, const QString& source = QString::null );
72 
73  virtual ~QgsMapLayer();
74 
76  QgsMapLayer( QgsMapLayer const & ) = delete;
78  QgsMapLayer & operator=( QgsMapLayer const & ) = delete;
79 
82  QgsMapLayer::LayerType type() const;
83 
85  QString id() const;
86 
93  void setName( const QString& name );
94 
99  QString name() const;
100 
104  QString originalName() const { return mLayerOrigName; }
105 
111  void setShortName( const QString& shortName ) { mShortName = shortName; }
112 
118  QString shortName() const { return mShortName; }
119 
125  void setTitle( const QString& title ) { mTitle = title; }
126 
132  QString title() const { return mTitle; }
133 
139  void setAbstract( const QString& abstract ) { mAbstract = abstract; }
140 
146  QString abstract() const { return mAbstract; }
147 
153  void setKeywordList( const QString& keywords ) { mKeywordList = keywords; }
154 
160  QString keywordList() const { return mKeywordList; }
161 
162  /* Layer dataUrl information */
163 
170  void setDataUrl( const QString& dataUrl ) { mDataUrl = dataUrl; }
171 
178  QString dataUrl() const { return mDataUrl; }
179 
186  void setDataUrlFormat( const QString& dataUrlFormat ) { mDataUrlFormat = dataUrlFormat; }
187 
194  QString dataUrlFormat() const { return mDataUrlFormat; }
195 
196  /* Layer attribution information */
197 
204  void setAttribution( const QString& attrib ) { mAttribution = attrib; }
205 
212  QString attribution() const { return mAttribution; }
213 
220  void setAttributionUrl( const QString& attribUrl ) { mAttributionUrl = attribUrl; }
221 
228  QString attributionUrl() const { return mAttributionUrl; }
229 
230  /* Layer metadataUrl information */
231 
238  void setMetadataUrl( const QString& metaUrl ) { mMetadataUrl = metaUrl; }
239 
246  QString metadataUrl() const { return mMetadataUrl; }
247 
254  void setMetadataUrlType( const QString& metaUrlType ) { mMetadataUrlType = metaUrlType; }
255 
262  QString metadataUrlType() const { return mMetadataUrlType; }
263 
270  void setMetadataUrlFormat( const QString& metaUrlFormat ) { mMetadataUrlFormat = metaUrlFormat; }
271 
278  QString metadataUrlFormat() const { return mMetadataUrlFormat; }
279 
284  void setBlendMode( QPainter::CompositionMode blendMode );
285 
289  QPainter::CompositionMode blendMode() const;
290 
292  bool readOnly() const { return isReadOnly(); }
293 
296  virtual void reload() {}
297 
301  virtual QgsMapLayerRenderer* createMapRenderer( QgsRenderContext& rendererContext ) = 0;
302 
304  virtual QgsRectangle extent() const;
305 
310  bool isValid() const;
311 
317  QString publicSource() const;
318 
323  QString source() const;
324 
329  virtual QStringList subLayers() const;
330 
335  virtual void setLayerOrder( const QStringList &layers );
336 
341  virtual void setSubLayerVisibility( const QString& name, bool visible );
342 
344  virtual bool isEditable() const;
345 
349  virtual bool isSpatial() const { return true; }
350 
365  bool readLayerXml( const QDomElement& layerElement );
366 
367 
384  bool writeLayerXml( QDomElement& layerElement, QDomDocument& document, const QString& relativeBasePath = QString::null ) const;
385 
391  static QDomDocument asLayerDefinition( const QList<QgsMapLayer*>& layers, const QString& relativeBasePath = QString::null );
392 
395  static QList<QgsMapLayer*> fromLayerDefinition( QDomDocument& document, bool addToRegistry = false, bool addToLegend = false );
396  static QList<QgsMapLayer*> fromLayerDefinitionFile( const QString &qlrfile );
397 
402  void setCustomProperty( const QString& key, const QVariant& value );
403 
407  QVariant customProperty( const QString& value, const QVariant& defaultValue = QVariant() ) const;
408 
412  void removeCustomProperty( const QString& key );
413 
418  virtual QgsError error() const { return mError; }
419 
423  QgsCoordinateReferenceSystem crs() const;
424 
426  void setCrs( const QgsCoordinateReferenceSystem& srs, bool emitSignal = true );
427 
429  static QString capitalizeLayerName( const QString& name );
430 
437  virtual QString styleURI() const;
438 
447  virtual QString loadDefaultStyle( bool & resultFlag );
448 
462  virtual QString loadNamedStyle( const QString& uri, bool &resultFlag );
463 
470  virtual bool loadNamedStyleFromDb( const QString &db, const QString &uri, QString &qml );
471 
480  virtual bool importNamedStyle( QDomDocument& doc, QString &errorMsg );
481 
488  virtual void exportNamedStyle( QDomDocument &doc, QString &errorMsg ) const;
489 
490 
497  virtual void exportSldStyle( QDomDocument &doc, QString &errorMsg ) const;
498 
507  virtual QString saveDefaultStyle( bool & resultFlag );
508 
522  virtual QString saveNamedStyle( const QString &uri, bool &resultFlag );
523 
531  virtual QString saveSldStyle( const QString &uri, bool &resultFlag ) const;
532 
540  virtual QString loadSldStyle( const QString &uri, bool &resultFlag );
541 
542  virtual bool readSld( const QDomNode &node, QString &errorMessage )
543  { Q_UNUSED( node ); errorMessage = QStringLiteral( "Layer type %1 not supported" ).arg( type() ); return false; }
544 
545 
546 
552  virtual bool readSymbology( const QDomNode& node, QString& errorMessage ) = 0;
553 
561  virtual bool readStyle( const QDomNode& node, QString& errorMessage );
562 
569  virtual bool writeSymbology( QDomNode &node, QDomDocument& doc, QString& errorMessage ) const = 0;
570 
579  virtual bool writeStyle( QDomNode& node, QDomDocument& doc, QString& errorMessage ) const;
580 
582  QUndoStack *undoStack();
583 
587  QUndoStack *undoStackStyles();
588 
589  /* Layer legendUrl information */
590  void setLegendUrl( const QString& legendUrl ) { mLegendUrl = legendUrl; }
591  QString legendUrl() const { return mLegendUrl; }
592  void setLegendUrlFormat( const QString& legendUrlFormat ) { mLegendUrlFormat = legendUrlFormat; }
593  QString legendUrlFormat() const { return mLegendUrlFormat; }
594 
600  void setLegend( QgsMapLayerLegend* legend );
601 
606  QgsMapLayerLegend* legend() const;
607 
612  QgsMapLayerStyleManager* styleManager() const;
613 
622  bool isInScaleRange( double scale ) const;
623 
632  double minimumScale() const;
633 
642  double maximumScale() const;
643 
651  bool hasScaleBasedVisibility() const;
652 
653  public slots:
654 
656  virtual void invalidTransformInput();
657 
665  void setMinimumScale( double scale );
666 
674  void setMaximumScale( double scale );
675 
682  void setScaleBasedVisibility( const bool enabled );
683 
690  void triggerRepaint();
691 
693  virtual QString metadata() const;
694 
696  virtual QDateTime timestamp() const { return QDateTime() ; }
697 
701  void emitStyleChanged();
702 
711  virtual bool setDependencies( const QSet<QgsMapLayerDependency>& layers );
712 
720  virtual QSet<QgsMapLayerDependency> dependencies() const;
721 
722  signals:
723 
725  void statusChanged( const QString& status );
726 
732  void nameChanged();
733 
735  void crsChanged();
736 
740  void repaintRequested();
741 
743  void recalculateExtents() const;
744 
746  void dataChanged();
747 
749  void blendModeChanged( QPainter::CompositionMode blendMode );
750 
754  void rendererChanged();
755 
762  void styleChanged();
763 
768  void legendChanged();
769 
774  void configChanged();
775 
779  void dependenciesChanged();
780 
787  void willBeDeleted();
788 
789  protected:
791  virtual void setExtent( const QgsRectangle &rect );
792 
794  void setValid( bool valid );
795 
799  virtual bool readXml( const QDomNode& layer_node );
800 
804  virtual bool writeXml( QDomNode & layer_node, QDomDocument & document ) const;
805 
806 
810  void readCustomProperties( const QDomNode& layerNode, const QString& keyStartsWith = "" );
811 
813  void writeCustomProperties( QDomNode & layerNode, QDomDocument & doc ) const;
814 
816  void readStyleManager( const QDomNode& layerNode );
818  void writeStyleManager( QDomNode& layerNode, QDomDocument& doc ) const;
819 
820 #if 0
821  void connectNotify( const char * signal ) override;
823 #endif
824 
826  void appendError( const QgsErrorMessage & error ) { mError.append( error );}
828  void setError( const QgsError & error ) { mError = error;}
829 
832 
834  bool mValid;
835 
837  QString mDataSource;
838 
840  QString mLayerName;
841 
844  QString mLayerOrigName;
845 
846  QString mShortName;
847  QString mTitle;
848 
850  QString mAbstract;
851  QString mKeywordList;
852 
854  QString mDataUrl;
855  QString mDataUrlFormat;
856 
858  QString mAttribution;
860 
862  QString mMetadataUrl;
865 
867  QString mLegendUrl;
869 
872 
874  QSet<QgsMapLayerDependency> mDependencies;
875 
877  bool hasDependencyCycle( const QSet<QgsMapLayerDependency>& layers ) const;
878 
879  private:
880 
885  virtual bool isReadOnly() const { return true; }
886 
890 
892  QString mID;
893 
895  QgsMapLayer::LayerType mLayerType;
896 
898  QPainter::CompositionMode mBlendMode;
899 
901  QString mTag;
902 
904  double mMinScale;
906  double mMaxScale;
908  bool mScaleBasedVisibility;
909 
911  QUndoStack mUndoStack;
912 
913  QUndoStack mUndoStackStyles;
914 
916  QgsObjectCustomProperties mCustomProperties;
917 
919  QgsMapLayerLegend* mLegend;
920 
922  QgsMapLayerStyleManager* mStyleManager;
923 };
924 
926 
927 #endif
QString attributionUrl() const
Returns the attribution URL of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:228
QString mShortName
Definition: qgsmaplayer.h:846
void setMetadataUrl(const QString &metaUrl)
Sets the metadata URL of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:238
QString dataUrlFormat() const
Returns the DataUrl format of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:194
A rectangle specified with double values.
Definition: qgsrectangle.h:36
Base class for all map layer types.
Definition: qgsmaplayer.h:50
void setShortName(const QString &shortName)
Sets the short name of the layer used by QGIS Server to identify the layer.
Definition: qgsmaplayer.h:111
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:349
QString mAttributionUrl
Definition: qgsmaplayer.h:859
QString mKeywordList
Definition: qgsmaplayer.h:851
QString shortName() const
Returns the short name of the layer used by QGIS Server to identify the layer.
Definition: qgsmaplayer.h:118
QString mDataUrlFormat
Definition: qgsmaplayer.h:855
QString dataUrl() const
Returns the DataUrl of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:178
virtual QgsError error() const
Get current status error.
Definition: qgsmaplayer.h:418
QString mLegendUrlFormat
Definition: qgsmaplayer.h:868
virtual void reload()
Synchronises with changes in the datasource.
Definition: qgsmaplayer.h:296
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:254
virtual QDateTime timestamp() const
Time stamp of data source in the moment when data/metadata were loaded by provider.
Definition: qgsmaplayer.h:696
QString mLayerName
Name of the layer - used for display.
Definition: qgsmaplayer.h:840
QgsError mError
Error.
Definition: qgsmaplayer.h:871
QgsRectangle mExtent
Extent of the layer.
Definition: qgsmaplayer.h:831
QString mMetadataUrl
MetadataUrl of the layer.
Definition: qgsmaplayer.h:862
void setLegendUrlFormat(const QString &legendUrlFormat)
Definition: qgsmaplayer.h:592
QString metadataUrlFormat() const
Returns the metadata format of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:278
void setKeywordList(const QString &keywords)
Sets the keyword list of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:153
void setTitle(const QString &title)
Sets the title of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:125
QString originalName() const
Returns the original name of the layer.
Definition: qgsmaplayer.h:104
LayerType
Types of layers that can be added to a map.
Definition: qgsmaplayer.h:59
QSet< QgsMapLayerDependency > mDependencies
List of layers that may modify this layer on modification.
Definition: qgsmaplayer.h:874
QString keywordList() const
Returns the keyword list of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:160
QString mDataUrl
DataUrl of the layer.
Definition: qgsmaplayer.h:854
The QgsMapLayerLegend class is abstract interface for implementations of legends for one map layer...
QString legendUrl() const
Definition: qgsmaplayer.h:591
QgsErrorMessage represents single error message.
Definition: qgserror.h:31
bool mValid
Indicates if the layer is valid and can be drawn.
Definition: qgsmaplayer.h:834
void setDataUrlFormat(const QString &dataUrlFormat)
Sets the DataUrl format of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:186
QString mTitle
Definition: qgsmaplayer.h:847
virtual bool readSld(const QDomNode &node, QString &errorMessage)
Definition: qgsmaplayer.h:542
QString legendUrlFormat() const
Definition: qgsmaplayer.h:593
QString mMetadataUrlFormat
Definition: qgsmaplayer.h:864
void setLegendUrl(const QString &legendUrl)
Definition: qgsmaplayer.h:590
void setMetadataUrlFormat(const QString &metaUrlFormat)
Sets the metadata format of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:270
QString title() const
Returns the title of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:132
QString mAttribution
Attribution of the layer.
Definition: qgsmaplayer.h:858
QString mAbstract
Description of the layer.
Definition: qgsmaplayer.h:850
Contains information about the context of a rendering operation.
QString mDataSource
Data source description string, varies by layer type.
Definition: qgsmaplayer.h:837
QgsError is container for error messages (report).
Definition: qgserror.h:82
QString mLegendUrl
WMS legend.
Definition: qgsmaplayer.h:867
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:220
void appendError(const QgsErrorMessage &error)
Add error message.
Definition: qgsmaplayer.h:826
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:292
QString metadataUrl() const
Returns the metadata URL of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:246
void setAttribution(const QString &attrib)
Sets the attribution of the layer used by QGIS Server in GetCapabilities request. ...
Definition: qgsmaplayer.h:204
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:170
QString mLayerOrigName
Original name of the layer.
Definition: qgsmaplayer.h:844
QString mMetadataUrlType
Definition: qgsmaplayer.h:863
void setError(const QgsError &error)
Set error message.
Definition: qgsmaplayer.h:828
void setAbstract(const QString &abstract)
Sets the abstract of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:139
QString attribution() const
Returns the attribution of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:212
QString metadataUrlType() const
Returns the metadata type of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:262