QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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"
31 #include "qgsmaprenderer.h"
33 #include "qgsrectangle.h"
34 
35 class QgsRenderContext;
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:
57  enum LayerType
58  {
61  PluginLayer
62  };
63 
69  QgsMapLayer( QgsMapLayer::LayerType type = VectorLayer, const QString& lyrname = QString::null, const QString& source = QString::null );
70 
72  virtual ~QgsMapLayer();
73 
77  QgsMapLayer::LayerType type() const;
78 
80  QString id() const;
81 
86  Q_DECL_DEPRECATED void setLayerName( const QString & name );
87 
94  void setName( const QString& name );
95 
99  QString name() const;
100 
104  QString originalName() const { return mLayerOrigName; }
105 
110  void setShortName( const QString& shortName ) { mShortName = shortName; }
115  QString shortName() const { return mShortName; }
116 
121  void setTitle( const QString& title ) { mTitle = title; }
126  QString title() const { return mTitle; }
127 
132  void setAbstract( const QString& abstract ) { mAbstract = abstract; }
137  QString abstract() const { return mAbstract; }
138 
143  void setKeywordList( const QString& keywords ) { mKeywordList = keywords; }
148  QString keywordList() const { return mKeywordList; }
149 
150  /* Layer dataUrl information */
156  void setDataUrl( const QString& dataUrl ) { mDataUrl = dataUrl; }
162  QString dataUrl() const { return mDataUrl; }
168  void setDataUrlFormat( const QString& dataUrlFormat ) { mDataUrlFormat = dataUrlFormat; }
174  QString dataUrlFormat() const { return mDataUrlFormat; }
175 
176  /* Layer attribution information */
182  void setAttribution( const QString& attrib ) { mAttribution = attrib; }
188  QString attribution() const { return mAttribution; }
194  void setAttributionUrl( const QString& attribUrl ) { mAttributionUrl = attribUrl; }
200  QString attributionUrl() const { return mAttributionUrl; }
201 
202  /* Layer metadataUrl information */
208  void setMetadataUrl( const QString& metaUrl ) { mMetadataUrl = metaUrl; }
214  QString metadataUrl() const { return mMetadataUrl; }
220  void setMetadataUrlType( const QString& metaUrlType ) { mMetadataUrlType = metaUrlType; }
226  QString metadataUrlType() const { return mMetadataUrlType; }
232  void setMetadataUrlFormat( const QString& metaUrlFormat ) { mMetadataUrlFormat = metaUrlFormat; }
238  QString metadataUrlFormat() const { return mMetadataUrlFormat; }
239 
241  void setBlendMode( QPainter::CompositionMode blendMode );
243  QPainter::CompositionMode blendMode() const;
244 
246  bool readOnly() const { return isReadOnly(); }
247 
250  virtual void reload() {}
251 
255  virtual QgsMapLayerRenderer* createMapRenderer( QgsRenderContext& rendererContext ) { Q_UNUSED( rendererContext ); return nullptr; }
256 
263  virtual bool draw( QgsRenderContext& rendererContext );
264 
268  virtual void drawLabels( QgsRenderContext& rendererContext );
269 
271  virtual QgsRectangle extent();
272 
277  bool isValid();
278 
283  QString publicSource() const;
284 
286  QString source() const;
287 
292  virtual QStringList subLayers() const;
293 
298  virtual void setLayerOrder( const QStringList &layers );
299 
301  virtual void setSubLayerVisibility( const QString& name, bool vis );
302 
304  virtual bool isEditable() const;
305 
309  virtual bool isSpatial() const { return true; }
310 
326  bool readLayerXML( const QDomElement& layerElement, const QString& relativeBasePath = QString() );
327 
328 
345  bool writeLayerXML( QDomElement& layerElement, QDomDocument& document, const QString& relativeBasePath = QString() );
346 
352  static QDomDocument asLayerDefinition( const QList<QgsMapLayer*>& layers, const QString& relativeBasePath = QString() );
353 
356  static QList<QgsMapLayer*> fromLayerDefinition( QDomDocument& document, bool addToRegistry = false, bool addToLegend = false, const QString& relativeBasePath = QString() );
357  static QList<QgsMapLayer*> fromLayerDefinitionFile( const QString &qlrfile );
358 
360  void setCustomProperty( const QString& key, const QVariant& value );
362  QVariant customProperty( const QString& value, const QVariant& defaultValue = QVariant() ) const;
364  void removeCustomProperty( const QString& key );
365 
366 
368  Q_DECL_DEPRECATED virtual QString lastErrorTitle();
369 
371  Q_DECL_DEPRECATED virtual QString lastError();
372 
377  virtual QgsError error() const { return mError; }
378 
382  //TODO QGIS 3.0 - return QgsCoordinateReferenceSystem object, not reference (since they are implicitly shared)
383  const QgsCoordinateReferenceSystem& crs() const;
384 
386  void setCrs( const QgsCoordinateReferenceSystem& srs, bool emitSignal = true );
387 
389  static QString capitaliseLayerName( const QString& name );
390 
397  virtual QString styleURI();
398 
407  virtual QString loadDefaultStyle( bool & theResultFlag );
408 
422  virtual QString loadNamedStyle( const QString &theURI, bool &theResultFlag );
423 
424  virtual bool loadNamedStyleFromDb( const QString &db, const QString &theURI, QString &qml );
425 
434  virtual bool importNamedStyle( QDomDocument& doc, QString &errorMsg );
435 
442  virtual void exportNamedStyle( QDomDocument &doc, QString &errorMsg );
443 
444 
451  virtual void exportSldStyle( QDomDocument &doc, QString &errorMsg );
452 
461  virtual QString saveDefaultStyle( bool & theResultFlag );
462 
476  virtual QString saveNamedStyle( const QString &theURI, bool &theResultFlag );
477 
478  virtual QString saveSldStyle( const QString &theURI, bool &theResultFlag );
479  virtual QString loadSldStyle( const QString &theURI, bool &theResultFlag );
480 
481  virtual bool readSld( const QDomNode &node, QString &errorMessage )
482  { Q_UNUSED( node ); errorMessage = QString( "Layer type %1 not supported" ).arg( type() ); return false; }
483 
484 
485 
491  virtual bool readSymbology( const QDomNode& node, QString& errorMessage ) = 0;
492 
500  virtual bool readStyle( const QDomNode& node, QString& errorMessage );
501 
508  virtual bool writeSymbology( QDomNode &node, QDomDocument& doc, QString& errorMessage ) const = 0;
509 
518  virtual bool writeStyle( QDomNode& node, QDomDocument& doc, QString& errorMessage ) const;
519 
521  QUndoStack *undoStack();
522 
526  QUndoStack *undoStackStyles();
527 
528  /* Layer legendUrl information */
529  void setLegendUrl( const QString& legendUrl ) { mLegendUrl = legendUrl; }
530  QString legendUrl() const { return mLegendUrl; }
531  void setLegendUrlFormat( const QString& legendUrlFormat ) { mLegendUrlFormat = legendUrlFormat; }
532  QString legendUrlFormat() const { return mLegendUrlFormat; }
533 
535  Q_DECL_DEPRECATED QImage *cacheImage() { return nullptr; }
537  Q_DECL_DEPRECATED void setCacheImage( QImage * );
539  Q_DECL_DEPRECATED virtual void onCacheImageDelete() {}
540 
546  void setLegend( QgsMapLayerLegend* legend );
551  QgsMapLayerLegend* legend() const;
552 
557  QgsMapLayerStyleManager* styleManager() const;
558 
567  bool isInScaleRange( double scale ) const;
568 
577  double minimumScale() const;
578 
587  double maximumScale() const;
588 
596  bool hasScaleBasedVisibility() const;
597 
598  public slots:
599 
601  virtual void invalidTransformInput();
602 
610  void setMinimumScale( double theMinScale );
611 
619  void setMaximumScale( double theMaxScale );
620 
627  void setScaleBasedVisibility( const bool enabled );
628 
632  Q_DECL_DEPRECATED void toggleScaleBasedVisibility( bool theVisibilityFlag );
633 
637  Q_DECL_DEPRECATED void clearCacheImage();
638 
645  void triggerRepaint();
646 
648  virtual QString metadata();
649 
651  virtual QDateTime timestamp() const { return QDateTime() ; }
652 
656  void emitStyleChanged();
657 
658  signals:
659 
661  Q_DECL_DEPRECATED void drawingProgress( int theProgress, int theTotalSteps );
662 
664  void statusChanged( const QString& theStatus );
665 
669  Q_DECL_DEPRECATED void layerNameChanged();
670 
676  void nameChanged();
677 
679  void layerCrsChanged();
680 
684  void repaintRequested();
685 
687  void screenUpdateRequested();
688 
690  void recalculateExtents();
691 
693  void dataChanged();
694 
696  void blendModeChanged( QPainter::CompositionMode blendMode );
697 
701  void rendererChanged();
702 
709  void styleChanged();
710 
715  void legendChanged();
716 
721  void configChanged();
722 
723  protected:
725  virtual void setExtent( const QgsRectangle &rect );
726 
728  void setValid( bool valid );
729 
733  virtual bool readXml( const QDomNode& layer_node );
734 
738  virtual bool writeXml( QDomNode & layer_node, QDomDocument & document );
739 
740 
744  void readCustomProperties( const QDomNode& layerNode, const QString& keyStartsWith = "" );
745 
747  void writeCustomProperties( QDomNode & layerNode, QDomDocument & doc ) const;
748 
750  void readStyleManager( const QDomNode& layerNode );
752  void writeStyleManager( QDomNode& layerNode, QDomDocument& doc ) const;
753 
754 #if 0
755 
756  void connectNotify( const char * signal ) override;
757 #endif
758 
760  void appendError( const QgsErrorMessage & theMessage ) { mError.append( theMessage );}
762  void setError( const QgsError & theError ) { mError = theError;}
763 
766 
768  bool mValid;
769 
772 
775 
779 
782 
786 
790 
794 
799 
803 
806 
807  private:
812  virtual bool isReadOnly() const { return true; }
813 
817 
819  QgsMapLayer( QgsMapLayer const & );
820 
822  QgsMapLayer & operator=( QgsMapLayer const & );
823 
825  QString mID;
826 
828  QgsMapLayer::LayerType mLayerType;
829 
831  QPainter::CompositionMode mBlendMode;
832 
834  QString mTag;
835 
837  double mMinScale;
839  double mMaxScale;
841  bool mScaleBasedVisibility;
842 
844  QUndoStack mUndoStack;
845 
846  QUndoStack mUndoStackStyles;
847 
849  QgsObjectCustomProperties mCustomProperties;
850 
852  QgsMapLayerLegend* mLegend;
853 
855  QgsMapLayerStyleManager* mStyleManager;
856 };
857 
859 
860 #endif
QString attributionUrl() const
Get the attribution URL of the layer used by QGIS Server in GetCapabilities request Attribution indic...
Definition: qgsmaplayer.h:200
QString mShortName
Definition: qgsmaplayer.h:780
void setMetadataUrl(const QString &metaUrl)
Set the metadata URL of the layer used by QGIS Server in GetCapabilities request MetadataUrl is a a l...
Definition: qgsmaplayer.h:208
QString dataUrlFormat() const
Get the DataUrl format of the layer used by QGIS Server in GetCapabilities request DataUrl is a a lin...
Definition: qgsmaplayer.h:174
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)
Set the short name of the layer used by QGIS Server to identify the layer.
Definition: qgsmaplayer.h:110
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:309
QString mAttributionUrl
Definition: qgsmaplayer.h:793
QString mKeywordList
Definition: qgsmaplayer.h:785
QString shortName() const
Get the short name of the layer used by QGIS Server to identify the layer.
Definition: qgsmaplayer.h:115
QString mDataUrlFormat
Definition: qgsmaplayer.h:789
QString dataUrl() const
Get the DataUrl of the layer used by QGIS Server in GetCapabilities request DataUrl is a a link to th...
Definition: qgsmaplayer.h:162
virtual QgsError error() const
Get current status error.
Definition: qgsmaplayer.h:377
QString mLegendUrlFormat
Definition: qgsmaplayer.h:802
virtual void reload()
Synchronises with changes in the datasource.
Definition: qgsmaplayer.h:250
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:220
virtual QgsMapLayerRenderer * createMapRenderer(QgsRenderContext &rendererContext)
Return new instance of QgsMapLayerRenderer that will be used for rendering of given context...
Definition: qgsmaplayer.h:255
virtual QDateTime timestamp() const
Time stamp of data source in the moment when data/metadata were loaded by provider.
Definition: qgsmaplayer.h:651
QString mLayerName
Name of the layer - used for display.
Definition: qgsmaplayer.h:774
QgsError mError
Error.
Definition: qgsmaplayer.h:805
QgsRectangle mExtent
Extent of the layer.
Definition: qgsmaplayer.h:765
const char * name() const
QString mMetadataUrl
MetadataUrl of the layer.
Definition: qgsmaplayer.h:796
void setLegendUrlFormat(const QString &legendUrlFormat)
Definition: qgsmaplayer.h:531
QString metadataUrlFormat() const
Get the metadata format of the layer used by QGIS Server in GetCapabilities request MetadataUrlType i...
Definition: qgsmaplayer.h:238
void setError(const QgsError &theError)
Set error message.
Definition: qgsmaplayer.h:762
void setKeywordList(const QString &keywords)
Set the keyword list of the layer used by QGIS Server in GetCapabilities request. ...
Definition: qgsmaplayer.h:143
void setTitle(const QString &title)
Set the title of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:121
Q_DECL_DEPRECATED QImage * cacheImage()
Definition: qgsmaplayer.h:535
QString originalName() const
Get the original name of the layer.
Definition: qgsmaplayer.h:104
LayerType
Layers enum defining the types of layers that can be added to a map.
Definition: qgsmaplayer.h:57
QString keywordList() const
Get the keyword list of the layer used by QGIS Server in GetCapabilities request. ...
Definition: qgsmaplayer.h:148
QString mDataUrl
DataUrl of the layer.
Definition: qgsmaplayer.h:788
The QgsMapLayerLegend class is abstract interface for implementations of legends for one map layer...
QString legendUrl() const
Definition: qgsmaplayer.h:530
QgsErrorMessage represents single error message.
Definition: qgserror.h:29
bool mValid
Indicates if the layer is valid and can be drawn.
Definition: qgsmaplayer.h:768
void setDataUrlFormat(const QString &dataUrlFormat)
Set the DataUrl format of the layer used by QGIS Server in GetCapabilities request DataUrl is a a lin...
Definition: qgsmaplayer.h:168
QString mTitle
Definition: qgsmaplayer.h:781
virtual bool readSld(const QDomNode &node, QString &errorMessage)
Definition: qgsmaplayer.h:481
QString legendUrlFormat() const
Definition: qgsmaplayer.h:532
QString mMetadataUrlFormat
Definition: qgsmaplayer.h:798
void setName(const char *name)
void setLegendUrl(const QString &legendUrl)
Definition: qgsmaplayer.h:529
virtual void connectNotify(const char *signal)
void setMetadataUrlFormat(const QString &metaUrlFormat)
Set the metadata format of the layer used by QGIS Server in GetCapabilities request MetadataUrlType i...
Definition: qgsmaplayer.h:232
QString title() const
Get 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:792
QString mAbstract
Description of the layer.
Definition: qgsmaplayer.h:784
virtual Q_DECL_DEPRECATED void onCacheImageDelete()
Definition: qgsmaplayer.h:539
Contains information about the context of a rendering operation.
QString mDataSource
Data source description string, varies by layer type.
Definition: qgsmaplayer.h:771
QgsError is container for error messages (report).
Definition: qgserror.h:80
QString mLegendUrl
WMS legend.
Definition: qgsmaplayer.h:801
Class for storing 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)
Set the attribution URL of the layer used by QGIS Server in GetCapabilities request Attribution indic...
Definition: qgsmaplayer.h:194
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:246
void appendError(const QgsErrorMessage &theMessage)
Add error message.
Definition: qgsmaplayer.h:760
QString metadataUrl() const
Get the metadata URL of the layer used by QGIS Server in GetCapabilities request MetadataUrl is a a l...
Definition: qgsmaplayer.h:214
void setAttribution(const QString &attrib)
Set the attribution of the layer used by QGIS Server in GetCapabilities request Attribution indicates...
Definition: qgsmaplayer.h:182
Management of styles for use with one map layer.
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
void setDataUrl(const QString &dataUrl)
Set the DataUrl of the layer used by QGIS Server in GetCapabilities request DataUrl is a a link to th...
Definition: qgsmaplayer.h:156
QString mLayerOrigName
Original name of the layer.
Definition: qgsmaplayer.h:778
QString mMetadataUrlType
Definition: qgsmaplayer.h:797
void setAbstract(const QString &abstract)
Set the abstract of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:132
QString attribution() const
Get the attribution of the layer used by QGIS Server in GetCapabilities request Attribution indicates...
Definition: qgsmaplayer.h:188
QString metadataUrlType() const
Get the metadata type of the layer used by QGIS Server in GetCapabilities request MetadataUrlType ind...
Definition: qgsmaplayer.h:226