QGIS API Documentation  2.99.0-Master (e077efd)
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 <QDateTime>
22 #include <QDomNode>
23 #include <QImage>
24 #include <QObject>
25 #include <QPainter>
26 #include <QUndoStack>
27 #include <QVariant>
28 
29 #include "qgis.h"
30 #include "qgserror.h"
32 #include "qgsrectangle.h"
34 #include "qgsrendercontext.h"
35 #include "qgsmaplayerdependency.h"
36 
37 class QgsMapLayerLegend;
40 
41 class QDomDocument;
42 class QKeyEvent;
43 class QPainter;
44 
49 class CORE_EXPORT QgsMapLayer : public QObject
50 {
51  Q_OBJECT
52 
53  Q_PROPERTY( QString name READ name WRITE setName NOTIFY nameChanged )
54 
55  public:
56 
58  enum LayerType
59  {
62  PluginLayer
63  };
64 
70  QgsMapLayer( QgsMapLayer::LayerType type = VectorLayer, const QString& name = QString::null, const QString& source = QString::null );
71 
72  virtual ~QgsMapLayer();
73 
76  QgsMapLayer::LayerType type() const;
77 
79  QString id() const;
80 
87  void setName( const QString& name );
88 
93  QString name() const;
94 
98  QString originalName() const { return mLayerOrigName; }
99 
105  void setShortName( const QString& shortName ) { mShortName = shortName; }
106 
112  QString shortName() const { return mShortName; }
113 
119  void setTitle( const QString& title ) { mTitle = title; }
120 
126  QString title() const { return mTitle; }
127 
133  void setAbstract( const QString& abstract ) { mAbstract = abstract; }
134 
140  QString abstract() const { return mAbstract; }
141 
147  void setKeywordList( const QString& keywords ) { mKeywordList = keywords; }
148 
154  QString keywordList() const { return mKeywordList; }
155 
156  /* Layer dataUrl information */
157 
164  void setDataUrl( const QString& dataUrl ) { mDataUrl = dataUrl; }
165 
172  QString dataUrl() const { return mDataUrl; }
173 
180  void setDataUrlFormat( const QString& dataUrlFormat ) { mDataUrlFormat = dataUrlFormat; }
181 
188  QString dataUrlFormat() const { return mDataUrlFormat; }
189 
190  /* Layer attribution information */
191 
198  void setAttribution( const QString& attrib ) { mAttribution = attrib; }
199 
206  QString attribution() const { return mAttribution; }
207 
214  void setAttributionUrl( const QString& attribUrl ) { mAttributionUrl = attribUrl; }
215 
222  QString attributionUrl() const { return mAttributionUrl; }
223 
224  /* Layer metadataUrl information */
225 
232  void setMetadataUrl( const QString& metaUrl ) { mMetadataUrl = metaUrl; }
233 
240  QString metadataUrl() const { return mMetadataUrl; }
241 
248  void setMetadataUrlType( const QString& metaUrlType ) { mMetadataUrlType = metaUrlType; }
249 
256  QString metadataUrlType() const { return mMetadataUrlType; }
257 
264  void setMetadataUrlFormat( const QString& metaUrlFormat ) { mMetadataUrlFormat = metaUrlFormat; }
265 
272  QString metadataUrlFormat() const { return mMetadataUrlFormat; }
273 
278  void setBlendMode( QPainter::CompositionMode blendMode );
279 
283  QPainter::CompositionMode blendMode() const;
284 
286  bool readOnly() const { return isReadOnly(); }
287 
290  virtual void reload() {}
291 
295  virtual QgsMapLayerRenderer* createMapRenderer( QgsRenderContext& rendererContext ) = 0;
296 
298  virtual QgsRectangle extent() const;
299 
304  bool isValid() const;
305 
311  QString publicSource() const;
312 
317  QString source() const;
318 
323  virtual QStringList subLayers() const;
324 
329  virtual void setLayerOrder( const QStringList &layers );
330 
335  virtual void setSubLayerVisibility( const QString& name, bool visible );
336 
338  virtual bool isEditable() const;
339 
343  virtual bool isSpatial() const { return true; }
344 
359  bool readLayerXml( const QDomElement& layerElement );
360 
361 
378  bool writeLayerXml( QDomElement& layerElement, QDomDocument& document, const QString& relativeBasePath = QString::null ) const;
379 
385  static QDomDocument asLayerDefinition( const QList<QgsMapLayer*>& layers, const QString& relativeBasePath = QString::null );
386 
389  static QList<QgsMapLayer*> fromLayerDefinition( QDomDocument& document, bool addToRegistry = false, bool addToLegend = false );
390  static QList<QgsMapLayer*> fromLayerDefinitionFile( const QString &qlrfile );
391 
396  void setCustomProperty( const QString& key, const QVariant& value );
397 
401  QVariant customProperty( const QString& value, const QVariant& defaultValue = QVariant() ) const;
402 
406  void removeCustomProperty( const QString& key );
407 
412  virtual QgsError error() const { return mError; }
413 
417  QgsCoordinateReferenceSystem crs() const;
418 
420  void setCrs( const QgsCoordinateReferenceSystem& srs, bool emitSignal = true );
421 
423  static QString capitaliseLayerName( const QString& name );
424 
431  virtual QString styleURI() const;
432 
441  virtual QString loadDefaultStyle( bool & resultFlag );
442 
456  virtual QString loadNamedStyle( const QString& uri, bool &resultFlag );
457 
464  virtual bool loadNamedStyleFromDb( const QString &db, const QString &uri, QString &qml );
465 
474  virtual bool importNamedStyle( QDomDocument& doc, QString &errorMsg );
475 
482  virtual void exportNamedStyle( QDomDocument &doc, QString &errorMsg ) const;
483 
484 
491  virtual void exportSldStyle( QDomDocument &doc, QString &errorMsg ) const;
492 
501  virtual QString saveDefaultStyle( bool & resultFlag );
502 
516  virtual QString saveNamedStyle( const QString &uri, bool &resultFlag );
517 
525  virtual QString saveSldStyle( const QString &uri, bool &resultFlag ) const;
526 
534  virtual QString loadSldStyle( const QString &uri, bool &resultFlag );
535 
536  virtual bool readSld( const QDomNode &node, QString &errorMessage )
537  { Q_UNUSED( node ); errorMessage = QStringLiteral( "Layer type %1 not supported" ).arg( type() ); return false; }
538 
539 
540 
546  virtual bool readSymbology( const QDomNode& node, QString& errorMessage ) = 0;
547 
555  virtual bool readStyle( const QDomNode& node, QString& errorMessage );
556 
563  virtual bool writeSymbology( QDomNode &node, QDomDocument& doc, QString& errorMessage ) const = 0;
564 
573  virtual bool writeStyle( QDomNode& node, QDomDocument& doc, QString& errorMessage ) const;
574 
576  QUndoStack *undoStack();
577 
581  QUndoStack *undoStackStyles();
582 
583  /* Layer legendUrl information */
584  void setLegendUrl( const QString& legendUrl ) { mLegendUrl = legendUrl; }
585  QString legendUrl() const { return mLegendUrl; }
586  void setLegendUrlFormat( const QString& legendUrlFormat ) { mLegendUrlFormat = legendUrlFormat; }
587  QString legendUrlFormat() const { return mLegendUrlFormat; }
588 
594  void setLegend( QgsMapLayerLegend* legend );
595 
600  QgsMapLayerLegend* legend() const;
601 
606  QgsMapLayerStyleManager* styleManager() const;
607 
616  bool isInScaleRange( double scale ) const;
617 
626  double minimumScale() const;
627 
636  double maximumScale() const;
637 
645  bool hasScaleBasedVisibility() const;
646 
647  public slots:
648 
650  virtual void invalidTransformInput();
651 
659  void setMinimumScale( double scale );
660 
668  void setMaximumScale( double scale );
669 
676  void setScaleBasedVisibility( const bool enabled );
677 
684  void triggerRepaint();
685 
687  virtual QString metadata() const;
688 
690  virtual QDateTime timestamp() const { return QDateTime() ; }
691 
695  void emitStyleChanged();
696 
705  virtual bool setDependencies( const QSet<QgsMapLayerDependency>& layers );
706 
714  virtual QSet<QgsMapLayerDependency> dependencies() const;
715 
716  signals:
717 
719  void statusChanged( const QString& status );
720 
726  void nameChanged();
727 
729  void crsChanged();
730 
734  void repaintRequested();
735 
737  void recalculateExtents() const;
738 
740  void dataChanged();
741 
743  void blendModeChanged( QPainter::CompositionMode blendMode );
744 
748  void rendererChanged();
749 
756  void styleChanged();
757 
762  void legendChanged();
763 
768  void configChanged();
769 
773  void dependenciesChanged();
774 
775  protected:
777  virtual void setExtent( const QgsRectangle &rect );
778 
780  void setValid( bool valid );
781 
785  virtual bool readXml( const QDomNode& layer_node );
786 
790  virtual bool writeXml( QDomNode & layer_node, QDomDocument & document ) const;
791 
792 
796  void readCustomProperties( const QDomNode& layerNode, const QString& keyStartsWith = "" );
797 
799  void writeCustomProperties( QDomNode & layerNode, QDomDocument & doc ) const;
800 
802  void readStyleManager( const QDomNode& layerNode );
804  void writeStyleManager( QDomNode& layerNode, QDomDocument& doc ) const;
805 
806 #if 0
807  void connectNotify( const char * signal ) override;
809 #endif
810 
812  void appendError( const QgsErrorMessage & error ) { mError.append( error );}
814  void setError( const QgsError & error ) { mError = error;}
815 
818 
820  bool mValid;
821 
823  QString mDataSource;
824 
826  QString mLayerName;
827 
830  QString mLayerOrigName;
831 
832  QString mShortName;
833  QString mTitle;
834 
836  QString mAbstract;
837  QString mKeywordList;
838 
840  QString mDataUrl;
841  QString mDataUrlFormat;
842 
844  QString mAttribution;
846 
848  QString mMetadataUrl;
851 
853  QString mLegendUrl;
855 
858 
860  QSet<QgsMapLayerDependency> mDependencies;
861 
863  bool hasDependencyCycle( const QSet<QgsMapLayerDependency>& layers ) const;
864 
865  private:
866 
871  virtual bool isReadOnly() const { return true; }
872 
876 
878  QgsMapLayer( QgsMapLayer const & );
879 
881  QgsMapLayer & operator=( QgsMapLayer const & );
882 
884  QString mID;
885 
887  QgsMapLayer::LayerType mLayerType;
888 
890  QPainter::CompositionMode mBlendMode;
891 
893  QString mTag;
894 
896  double mMinScale;
898  double mMaxScale;
900  bool mScaleBasedVisibility;
901 
903  QUndoStack mUndoStack;
904 
905  QUndoStack mUndoStackStyles;
906 
908  QgsObjectCustomProperties mCustomProperties;
909 
911  QgsMapLayerLegend* mLegend;
912 
914  QgsMapLayerStyleManager* mStyleManager;
915 };
916 
918 
919 #endif
QString attributionUrl() const
Returns the attribution URL of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:222
QString mShortName
Definition: qgsmaplayer.h:832
void setMetadataUrl(const QString &metaUrl)
Sets the metadata URL of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:232
QString dataUrlFormat() const
Returns the DataUrl format of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:188
A rectangle specified with double values.
Definition: qgsrectangle.h:35
Base class for all map layer types.
Definition: qgsmaplayer.h:49
void setShortName(const QString &shortName)
Sets the short name of the layer used by QGIS Server to identify the layer.
Definition: qgsmaplayer.h:105
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:343
QString mAttributionUrl
Definition: qgsmaplayer.h:845
QString mKeywordList
Definition: qgsmaplayer.h:837
QString shortName() const
Returns the short name of the layer used by QGIS Server to identify the layer.
Definition: qgsmaplayer.h:112
QString mDataUrlFormat
Definition: qgsmaplayer.h:841
QString dataUrl() const
Returns the DataUrl of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:172
virtual QgsError error() const
Get current status error.
Definition: qgsmaplayer.h:412
QString mLegendUrlFormat
Definition: qgsmaplayer.h:854
virtual void reload()
Synchronises with changes in the datasource.
Definition: qgsmaplayer.h:290
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:248
virtual QDateTime timestamp() const
Time stamp of data source in the moment when data/metadata were loaded by provider.
Definition: qgsmaplayer.h:690
QString mLayerName
Name of the layer - used for display.
Definition: qgsmaplayer.h:826
QgsError mError
Error.
Definition: qgsmaplayer.h:857
QgsRectangle mExtent
Extent of the layer.
Definition: qgsmaplayer.h:817
QString mMetadataUrl
MetadataUrl of the layer.
Definition: qgsmaplayer.h:848
void setLegendUrlFormat(const QString &legendUrlFormat)
Definition: qgsmaplayer.h:586
QString metadataUrlFormat() const
Returns the metadata format of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:272
void setKeywordList(const QString &keywords)
Sets the keyword list of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:147
void setTitle(const QString &title)
Sets the title of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:119
QString originalName() const
Returns the original name of the layer.
Definition: qgsmaplayer.h:98
LayerType
Types of layers that can be added to a map.
Definition: qgsmaplayer.h:58
QSet< QgsMapLayerDependency > mDependencies
List of layers that may modify this layer on modification.
Definition: qgsmaplayer.h:860
QString keywordList() const
Returns the keyword list of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:154
QString mDataUrl
DataUrl of the layer.
Definition: qgsmaplayer.h:840
The QgsMapLayerLegend class is abstract interface for implementations of legends for one map layer...
QString legendUrl() const
Definition: qgsmaplayer.h:585
QgsErrorMessage represents single error message.
Definition: qgserror.h:29
bool mValid
Indicates if the layer is valid and can be drawn.
Definition: qgsmaplayer.h:820
void setDataUrlFormat(const QString &dataUrlFormat)
Sets the DataUrl format of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:180
QString mTitle
Definition: qgsmaplayer.h:833
virtual bool readSld(const QDomNode &node, QString &errorMessage)
Definition: qgsmaplayer.h:536
QString legendUrlFormat() const
Definition: qgsmaplayer.h:587
QString mMetadataUrlFormat
Definition: qgsmaplayer.h:850
void setLegendUrl(const QString &legendUrl)
Definition: qgsmaplayer.h:584
void setMetadataUrlFormat(const QString &metaUrlFormat)
Sets the metadata format of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:264
QString title() const
Returns the title of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:126
QString mAttribution
Attribution of the layer.
Definition: qgsmaplayer.h:844
QString mAbstract
Description of the layer.
Definition: qgsmaplayer.h:836
Contains information about the context of a rendering operation.
QString mDataSource
Data source description string, varies by layer type.
Definition: qgsmaplayer.h:823
QgsError is container for error messages (report).
Definition: qgserror.h:80
QString mLegendUrl
WMS legend.
Definition: qgsmaplayer.h:853
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:214
void appendError(const QgsErrorMessage &error)
Add error message.
Definition: qgsmaplayer.h:812
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:286
QString metadataUrl() const
Returns the metadata URL of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:240
void setAttribution(const QString &attrib)
Sets the attribution of the layer used by QGIS Server in GetCapabilities request. ...
Definition: qgsmaplayer.h:198
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:164
QString mLayerOrigName
Original name of the layer.
Definition: qgsmaplayer.h:830
QString mMetadataUrlType
Definition: qgsmaplayer.h:849
void setError(const QgsError &error)
Set error message.
Definition: qgsmaplayer.h:814
void setAbstract(const QString &abstract)
Sets the abstract of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:133
QString attribution() const
Returns the attribution of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:206
QString metadataUrlType() const
Returns the metadata type of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:256