QGIS API Documentation  2.17.0-Master (06698cd)
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 
325  bool readLayerXML( const QDomElement& layerElement );
326 
327 
344  bool writeLayerXML( QDomElement& layerElement, QDomDocument& document, const QString& relativeBasePath = QString::null );
345 
351  static QDomDocument asLayerDefinition( const QList<QgsMapLayer*>& layers, const QString& relativeBasePath = QString::null );
352 
355  static QList<QgsMapLayer*> fromLayerDefinition( QDomDocument& document, bool addToRegistry = false, bool addToLegend = false );
356  static QList<QgsMapLayer*> fromLayerDefinitionFile( const QString &qlrfile );
357 
359  void setCustomProperty( const QString& key, const QVariant& value );
361  QVariant customProperty( const QString& value, const QVariant& defaultValue = QVariant() ) const;
363  void removeCustomProperty( const QString& key );
364 
365 
367  Q_DECL_DEPRECATED virtual QString lastErrorTitle();
368 
370  Q_DECL_DEPRECATED virtual QString lastError();
371 
376  virtual QgsError error() const { return mError; }
377 
381  //TODO QGIS 3.0 - return QgsCoordinateReferenceSystem object, not reference (since they are implicitly shared)
382  const QgsCoordinateReferenceSystem& crs() const;
383 
385  void setCrs( const QgsCoordinateReferenceSystem& srs, bool emitSignal = true );
386 
388  static QString capitaliseLayerName( const QString& name );
389 
396  virtual QString styleURI();
397 
406  virtual QString loadDefaultStyle( bool & theResultFlag );
407 
421  virtual QString loadNamedStyle( const QString &theURI, bool &theResultFlag );
422 
423  virtual bool loadNamedStyleFromDb( const QString &db, const QString &theURI, QString &qml );
424 
433  virtual bool importNamedStyle( QDomDocument& doc, QString &errorMsg );
434 
441  virtual void exportNamedStyle( QDomDocument &doc, QString &errorMsg );
442 
443 
450  virtual void exportSldStyle( QDomDocument &doc, QString &errorMsg );
451 
460  virtual QString saveDefaultStyle( bool & theResultFlag );
461 
475  virtual QString saveNamedStyle( const QString &theURI, bool &theResultFlag );
476 
477  virtual QString saveSldStyle( const QString &theURI, bool &theResultFlag );
478  virtual QString loadSldStyle( const QString &theURI, bool &theResultFlag );
479 
480  virtual bool readSld( const QDomNode &node, QString &errorMessage )
481  { Q_UNUSED( node ); errorMessage = QString( "Layer type %1 not supported" ).arg( type() ); return false; }
482 
483 
484 
490  virtual bool readSymbology( const QDomNode& node, QString& errorMessage ) = 0;
491 
499  virtual bool readStyle( const QDomNode& node, QString& errorMessage );
500 
507  virtual bool writeSymbology( QDomNode &node, QDomDocument& doc, QString& errorMessage ) const = 0;
508 
517  virtual bool writeStyle( QDomNode& node, QDomDocument& doc, QString& errorMessage ) const;
518 
520  QUndoStack *undoStack();
521 
525  QUndoStack *undoStackStyles();
526 
527  /* Layer legendUrl information */
528  void setLegendUrl( const QString& legendUrl ) { mLegendUrl = legendUrl; }
529  QString legendUrl() const { return mLegendUrl; }
530  void setLegendUrlFormat( const QString& legendUrlFormat ) { mLegendUrlFormat = legendUrlFormat; }
531  QString legendUrlFormat() const { return mLegendUrlFormat; }
532 
534  Q_DECL_DEPRECATED QImage *cacheImage() { return nullptr; }
536  Q_DECL_DEPRECATED void setCacheImage( QImage * );
538  Q_DECL_DEPRECATED virtual void onCacheImageDelete() {}
539 
545  void setLegend( QgsMapLayerLegend* legend );
550  QgsMapLayerLegend* legend() const;
551 
556  QgsMapLayerStyleManager* styleManager() const;
557 
566  bool isInScaleRange( double scale ) const;
567 
576  double minimumScale() const;
577 
586  double maximumScale() const;
587 
595  bool hasScaleBasedVisibility() const;
596 
597  public slots:
598 
600  virtual void invalidTransformInput();
601 
609  void setMinimumScale( double theMinScale );
610 
618  void setMaximumScale( double theMaxScale );
619 
626  void setScaleBasedVisibility( const bool enabled );
627 
631  Q_DECL_DEPRECATED void toggleScaleBasedVisibility( bool theVisibilityFlag );
632 
636  Q_DECL_DEPRECATED void clearCacheImage();
637 
644  void triggerRepaint();
645 
647  virtual QString metadata();
648 
650  virtual QDateTime timestamp() const { return QDateTime() ; }
651 
655  void emitStyleChanged();
656 
657  signals:
658 
660  Q_DECL_DEPRECATED void drawingProgress( int theProgress, int theTotalSteps );
661 
663  void statusChanged( const QString& theStatus );
664 
668  Q_DECL_DEPRECATED void layerNameChanged();
669 
675  void nameChanged();
676 
678  void layerCrsChanged();
679 
683  void repaintRequested();
684 
686  void screenUpdateRequested();
687 
689  void recalculateExtents();
690 
692  void dataChanged();
693 
695  void blendModeChanged( QPainter::CompositionMode blendMode );
696 
700  void rendererChanged();
701 
708  void styleChanged();
709 
714  void legendChanged();
715 
720  void configChanged();
721 
722  protected:
724  virtual void setExtent( const QgsRectangle &rect );
725 
727  void setValid( bool valid );
728 
732  virtual bool readXml( const QDomNode& layer_node );
733 
737  virtual bool writeXml( QDomNode & layer_node, QDomDocument & document );
738 
739 
743  void readCustomProperties( const QDomNode& layerNode, const QString& keyStartsWith = "" );
744 
746  void writeCustomProperties( QDomNode & layerNode, QDomDocument & doc ) const;
747 
749  void readStyleManager( const QDomNode& layerNode );
751  void writeStyleManager( QDomNode& layerNode, QDomDocument& doc ) const;
752 
753 #if 0
754 
755  void connectNotify( const char * signal ) override;
756 #endif
757 
759  void appendError( const QgsErrorMessage & theMessage ) { mError.append( theMessage );}
761  void setError( const QgsError & theError ) { mError = theError;}
762 
765 
767  bool mValid;
768 
771 
774 
778 
781 
785 
789 
793 
798 
802 
805 
806  private:
811  virtual bool isReadOnly() const { return true; }
812 
816 
818  QgsMapLayer( QgsMapLayer const & );
819 
821  QgsMapLayer & operator=( QgsMapLayer const & );
822 
824  QString mID;
825 
827  QgsMapLayer::LayerType mLayerType;
828 
830  QPainter::CompositionMode mBlendMode;
831 
833  QString mTag;
834 
836  double mMinScale;
838  double mMaxScale;
840  bool mScaleBasedVisibility;
841 
843  QUndoStack mUndoStack;
844 
845  QUndoStack mUndoStackStyles;
846 
848  QgsObjectCustomProperties mCustomProperties;
849 
851  QgsMapLayerLegend* mLegend;
852 
854  QgsMapLayerStyleManager* mStyleManager;
855 };
856 
858 
859 #endif
QString mShortName
Definition: qgsmaplayer.h:779
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
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
QString shortName() const
Get the short name of the layer used by QGIS Server to identify the layer.
Definition: qgsmaplayer.h:115
QString mAttributionUrl
Definition: qgsmaplayer.h:792
QString mKeywordList
Definition: qgsmaplayer.h:784
QString mDataUrlFormat
Definition: qgsmaplayer.h:788
QString mLegendUrlFormat
Definition: qgsmaplayer.h:801
virtual void reload()
Synchronises with changes in the datasource.
Definition: qgsmaplayer.h:250
QString title() const
Get the title of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:126
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
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
Q_DECLARE_METATYPE(QModelIndex)
QString mLayerName
Name of the layer - used for display.
Definition: qgsmaplayer.h:773
bool readOnly() const
Returns if this layer is read only.
Definition: qgsmaplayer.h:246
QgsError mError
Error.
Definition: qgsmaplayer.h:804
QgsRectangle mExtent
Extent of the layer.
Definition: qgsmaplayer.h:764
const char * name() const
QString mMetadataUrl
MetadataUrl of the layer.
Definition: qgsmaplayer.h:795
void setLegendUrlFormat(const QString &legendUrlFormat)
Definition: qgsmaplayer.h:530
void setError(const QgsError &theError)
Set error message.
Definition: qgsmaplayer.h:761
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:534
LayerType
Layers enum defining the types of layers that can be added to a map.
Definition: qgsmaplayer.h:57
QString mDataUrl
DataUrl of the layer.
Definition: qgsmaplayer.h:787
The QgsMapLayerLegend class is abstract interface for implementations of legends for one map layer...
QString attributionUrl() const
Get the attribution URL of the layer used by QGIS Server in GetCapabilities request Attribution indic...
Definition: qgsmaplayer.h:200
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
QgsErrorMessage represents single error message.
Definition: qgserror.h:29
bool mValid
Indicates if the layer is valid and can be drawn.
Definition: qgsmaplayer.h:767
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
virtual QgsError error() const
Get current status error.
Definition: qgsmaplayer.h:376
QString mTitle
Definition: qgsmaplayer.h:780
virtual bool readSld(const QDomNode &node, QString &errorMessage)
Definition: qgsmaplayer.h:480
QString mMetadataUrlFormat
Definition: qgsmaplayer.h:797
void setName(const char *name)
void setLegendUrl(const QString &legendUrl)
Definition: qgsmaplayer.h:528
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 mAttribution
Attribution of the layer.
Definition: qgsmaplayer.h:791
QString mAbstract
Description of the layer.
Definition: qgsmaplayer.h:783
virtual Q_DECL_DEPRECATED void onCacheImageDelete()
Definition: qgsmaplayer.h:538
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
Contains information about the context of a rendering operation.
QString legendUrlFormat() const
Definition: qgsmaplayer.h:531
QString mDataSource
Data source description string, varies by layer type.
Definition: qgsmaplayer.h:770
QString legendUrl() const
Definition: qgsmaplayer.h:529
QgsError is container for error messages (report).
Definition: qgserror.h:80
QString mLegendUrl
WMS legend.
Definition: qgsmaplayer.h:800
Class for storing a coordinate reference system (CRS)
QString originalName() const
Get the original name of the layer.
Definition: qgsmaplayer.h:104
QString metadataUrlType() const
Get the metadata type of the layer used by QGIS Server in GetCapabilities request MetadataUrlType ind...
Definition: qgsmaplayer.h:226
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...
void appendError(const QgsErrorMessage &theMessage)
Add error message.
Definition: qgsmaplayer.h:759
virtual QDateTime timestamp() const
Time stamp of data source in the moment when data/metadata were loaded by provider.
Definition: qgsmaplayer.h:650
void setAttribution(const QString &attrib)
Set the attribution of the layer used by QGIS Server in GetCapabilities request Attribution indicates...
Definition: qgsmaplayer.h:182
QString keywordList() const
Get the keyword list of the layer used by QGIS Server in GetCapabilities request. ...
Definition: qgsmaplayer.h:148
Management of styles for use with one map layer.
QString attribution() const
Get the attribution of the layer used by QGIS Server in GetCapabilities request Attribution indicates...
Definition: qgsmaplayer.h:188
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:777
QString mMetadataUrlType
Definition: qgsmaplayer.h:796
QString metadataUrlFormat() const
Get the metadata format of the layer used by QGIS Server in GetCapabilities request MetadataUrlType i...
Definition: qgsmaplayer.h:238
void setAbstract(const QString &abstract)
Set the abstract of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:132
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