QGIS API Documentation  2.15.0-Master (af20121)
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  public:
55  enum LayerType
56  {
59  PluginLayer
60  };
61 
67  QgsMapLayer( QgsMapLayer::LayerType type = VectorLayer, const QString& lyrname = QString::null, const QString& source = QString::null );
68 
70  virtual ~QgsMapLayer();
71 
75  QgsMapLayer::LayerType type() const;
76 
78  QString id() const;
79 
83  void setLayerName( const QString & name );
84 
88  QString name() const;
89 
93  QString originalName() const { return mLayerOrigName; }
94 
99  void setShortName( const QString& shortName ) { mShortName = shortName; }
104  QString shortName() const { return mShortName; }
105 
110  void setTitle( const QString& title ) { mTitle = title; }
115  QString title() const { return mTitle; }
116 
121  void setAbstract( const QString& abstract ) { mAbstract = abstract; }
126  QString abstract() const { return mAbstract; }
127 
132  void setKeywordList( const QString& keywords ) { mKeywordList = keywords; }
137  QString keywordList() const { return mKeywordList; }
138 
139  /* Layer dataUrl information */
145  void setDataUrl( const QString& dataUrl ) { mDataUrl = dataUrl; }
151  QString dataUrl() const { return mDataUrl; }
157  void setDataUrlFormat( const QString& dataUrlFormat ) { mDataUrlFormat = dataUrlFormat; }
163  QString dataUrlFormat() const { return mDataUrlFormat; }
164 
165  /* Layer attribution information */
171  void setAttribution( const QString& attrib ) { mAttribution = attrib; }
177  QString attribution() const { return mAttribution; }
183  void setAttributionUrl( const QString& attribUrl ) { mAttributionUrl = attribUrl; }
189  QString attributionUrl() const { return mAttributionUrl; }
190 
191  /* Layer metadataUrl information */
197  void setMetadataUrl( const QString& metaUrl ) { mMetadataUrl = metaUrl; }
203  QString metadataUrl() const { return mMetadataUrl; }
209  void setMetadataUrlType( const QString& metaUrlType ) { mMetadataUrlType = metaUrlType; }
215  QString metadataUrlType() const { return mMetadataUrlType; }
221  void setMetadataUrlFormat( const QString& metaUrlFormat ) { mMetadataUrlFormat = metaUrlFormat; }
227  QString metadataUrlFormat() const { return mMetadataUrlFormat; }
228 
230  void setBlendMode( QPainter::CompositionMode blendMode );
232  QPainter::CompositionMode blendMode() const;
233 
235  bool readOnly() const { return isReadOnly(); }
236 
239  virtual void reload() {}
240 
244  virtual QgsMapLayerRenderer* createMapRenderer( QgsRenderContext& rendererContext ) { Q_UNUSED( rendererContext ); return nullptr; }
245 
252  virtual bool draw( QgsRenderContext& rendererContext );
253 
257  virtual void drawLabels( QgsRenderContext& rendererContext );
258 
260  virtual QgsRectangle extent();
261 
266  bool isValid();
267 
272  QString publicSource() const;
273 
275  QString source() const;
276 
281  virtual QStringList subLayers() const;
282 
287  virtual void setLayerOrder( const QStringList &layers );
288 
290  virtual void setSubLayerVisibility( const QString& name, bool vis );
291 
293  virtual bool isEditable() const;
294 
298  virtual bool isSpatial() const { return true; }
299 
314  bool readLayerXML( const QDomElement& layerElement );
315 
316 
333  bool writeLayerXML( QDomElement& layerElement, QDomDocument& document, const QString& relativeBasePath = QString::null );
334 
340  static QDomDocument asLayerDefinition( const QList<QgsMapLayer*>& layers, const QString& relativeBasePath = QString::null );
341 
344  static QList<QgsMapLayer*> fromLayerDefinition( QDomDocument& document, bool addToRegistry = false, bool addToLegend = false );
345  static QList<QgsMapLayer*> fromLayerDefinitionFile( const QString &qlrfile );
346 
348  void setCustomProperty( const QString& key, const QVariant& value );
350  QVariant customProperty( const QString& value, const QVariant& defaultValue = QVariant() ) const;
352  void removeCustomProperty( const QString& key );
353 
354 
356  Q_DECL_DEPRECATED virtual QString lastErrorTitle();
357 
359  Q_DECL_DEPRECATED virtual QString lastError();
360 
365  virtual QgsError error() const { return mError; }
366 
370  //TODO QGIS 3.0 - return QgsCoordinateReferenceSystem object, not reference (since they are implicitly shared)
371  const QgsCoordinateReferenceSystem& crs() const;
372 
374  void setCrs( const QgsCoordinateReferenceSystem& srs, bool emitSignal = true );
375 
377  static QString capitaliseLayerName( const QString& name );
378 
385  virtual QString styleURI();
386 
395  virtual QString loadDefaultStyle( bool & theResultFlag );
396 
410  virtual QString loadNamedStyle( const QString &theURI, bool &theResultFlag );
411 
412  virtual bool loadNamedStyleFromDb( const QString &db, const QString &theURI, QString &qml );
413 
422  virtual bool importNamedStyle( QDomDocument& doc, QString &errorMsg );
423 
430  virtual void exportNamedStyle( QDomDocument &doc, QString &errorMsg );
431 
432 
439  virtual void exportSldStyle( QDomDocument &doc, QString &errorMsg );
440 
449  virtual QString saveDefaultStyle( bool & theResultFlag );
450 
464  virtual QString saveNamedStyle( const QString &theURI, bool &theResultFlag );
465 
466  virtual QString saveSldStyle( const QString &theURI, bool &theResultFlag );
467  virtual QString loadSldStyle( const QString &theURI, bool &theResultFlag );
468 
469  virtual bool readSld( const QDomNode &node, QString &errorMessage )
470  { Q_UNUSED( node ); errorMessage = QString( "Layer type %1 not supported" ).arg( type() ); return false; }
471 
472 
473 
479  virtual bool readSymbology( const QDomNode& node, QString& errorMessage ) = 0;
480 
486  virtual bool readStyle( const QDomNode& node, QString& errorMessage ) = 0;
487 
494  virtual bool writeSymbology( QDomNode &node, QDomDocument& doc, QString& errorMessage ) const = 0;
495 
502  virtual bool writeStyle( QDomNode& node, QDomDocument& doc, QString& errorMessage ) const = 0;
503 
505  QUndoStack *undoStack();
506 
508  QUndoStack *undoStackStyles();
509 
510  /* Layer legendUrl information */
511  void setLegendUrl( const QString& legendUrl ) { mLegendUrl = legendUrl; }
512  QString legendUrl() const { return mLegendUrl; }
513  void setLegendUrlFormat( const QString& legendUrlFormat ) { mLegendUrlFormat = legendUrlFormat; }
514  QString legendUrlFormat() const { return mLegendUrlFormat; }
515 
517  Q_DECL_DEPRECATED QImage *cacheImage() { return nullptr; }
519  Q_DECL_DEPRECATED void setCacheImage( QImage * );
521  Q_DECL_DEPRECATED virtual void onCacheImageDelete() {}
522 
528  void setLegend( QgsMapLayerLegend* legend );
533  QgsMapLayerLegend* legend() const;
534 
539  QgsMapLayerStyleManager* styleManager() const;
540 
549  bool isInScaleRange( double scale ) const;
550 
559  double minimumScale() const;
560 
569  double maximumScale() const;
570 
578  bool hasScaleBasedVisibility() const;
579 
580  public slots:
581 
583  virtual void invalidTransformInput();
584 
592  void setMinimumScale( double theMinScale );
593 
601  void setMaximumScale( double theMaxScale );
602 
609  void setScaleBasedVisibility( const bool enabled );
610 
614  Q_DECL_DEPRECATED void toggleScaleBasedVisibility( bool theVisibilityFlag );
615 
619  Q_DECL_DEPRECATED void clearCacheImage();
620 
627  void triggerRepaint();
628 
630  virtual QString metadata();
631 
633  virtual QDateTime timestamp() const { return QDateTime() ; }
634 
635  signals:
636 
638  Q_DECL_DEPRECATED void drawingProgress( int theProgress, int theTotalSteps );
639 
641  void statusChanged( const QString& theStatus );
642 
644  void layerNameChanged();
645 
647  void layerCrsChanged();
648 
652  void repaintRequested();
653 
655  void screenUpdateRequested();
656 
658  void recalculateExtents();
659 
661  void dataChanged();
662 
664  void blendModeChanged( QPainter::CompositionMode blendMode );
665 
667  void rendererChanged();
668 
673  void legendChanged();
674 
675  protected:
677  virtual void setExtent( const QgsRectangle &rect );
678 
680  void setValid( bool valid );
681 
685  virtual bool readXml( const QDomNode& layer_node );
686 
690  virtual bool writeXml( QDomNode & layer_node, QDomDocument & document );
691 
692 
696  void readCustomProperties( const QDomNode& layerNode, const QString& keyStartsWith = "" );
697 
699  void writeCustomProperties( QDomNode & layerNode, QDomDocument & doc ) const;
700 
702  void readStyleManager( const QDomNode& layerNode );
704  void writeStyleManager( QDomNode& layerNode, QDomDocument& doc ) const;
705 
706 #if 0
707 
708  void connectNotify( const char * signal ) override;
709 #endif
710 
712  void appendError( const QgsErrorMessage & theMessage ) { mError.append( theMessage );}
714  void setError( const QgsError & theError ) { mError = theError;}
715 
718 
720  bool mValid;
721 
724 
727 
731 
734 
738 
742 
746 
751 
755 
758 
759  private:
764  virtual bool isReadOnly() const { return true; }
765 
769 
771  QgsMapLayer( QgsMapLayer const & );
772 
774  QgsMapLayer & operator=( QgsMapLayer const & );
775 
777  QString mID;
778 
780  QgsMapLayer::LayerType mLayerType;
781 
783  QPainter::CompositionMode mBlendMode;
784 
786  QString mTag;
787 
789  double mMinScale;
791  double mMaxScale;
793  bool mScaleBasedVisibility;
794 
796  QUndoStack mUndoStack;
797 
798  QUndoStack mUndoStackStyles;
799 
801  QgsObjectCustomProperties mCustomProperties;
802 
804  QgsMapLayerLegend* mLegend;
805 
807  QgsMapLayerStyleManager* mStyleManager;
808 };
809 
810 Q_DECLARE_METATYPE( QgsMapLayer* )
811 
812 #endif
QString mShortName
Definition: qgsmaplayer.h:732
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:197
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:99
QString shortName() const
Get the short name of the layer used by QGIS Server to identify the layer.
Definition: qgsmaplayer.h:104
QString mAttributionUrl
Definition: qgsmaplayer.h:745
QString mKeywordList
Definition: qgsmaplayer.h:737
QString mDataUrlFormat
Definition: qgsmaplayer.h:741
QString mLegendUrlFormat
Definition: qgsmaplayer.h:754
virtual void reload()
Synchronises with changes in the datasource.
Definition: qgsmaplayer.h:239
QString title() const
Get the title of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:115
void setMetadataUrlType(const QString &metaUrlType)
Set the metadata type of the layer used by QGIS Server in GetCapabilities request MetadataUrlType ind...
Definition: qgsmaplayer.h:209
virtual QgsMapLayerRenderer * createMapRenderer(QgsRenderContext &rendererContext)
Return new instance of QgsMapLayerRenderer that will be used for rendering of given context...
Definition: qgsmaplayer.h:244
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:151
QString mLayerName
Name of the layer - used for display.
Definition: qgsmaplayer.h:726
bool readOnly() const
Returns if this layer is read only.
Definition: qgsmaplayer.h:235
QgsError mError
Error.
Definition: qgsmaplayer.h:757
QgsRectangle mExtent
Extent of the layer.
Definition: qgsmaplayer.h:717
const char * name() const
QString mMetadataUrl
MetadataUrl of the layer.
Definition: qgsmaplayer.h:748
void setLegendUrlFormat(const QString &legendUrlFormat)
Definition: qgsmaplayer.h:513
void setError(const QgsError &theError)
Set error message.
Definition: qgsmaplayer.h:714
void setKeywordList(const QString &keywords)
Set the keyword list of the layer used by QGIS Server in GetCapabilities request. ...
Definition: qgsmaplayer.h:132
void setTitle(const QString &title)
Set the title of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:110
Q_DECL_DEPRECATED QImage * cacheImage()
Definition: qgsmaplayer.h:517
LayerType
Layers enum defining the types of layers that can be added to a map.
Definition: qgsmaplayer.h:55
QString mDataUrl
DataUrl of the layer.
Definition: qgsmaplayer.h:740
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:189
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:163
QgsErrorMessage represents single error message.
Definition: qgserror.h:29
bool mValid
Indicates if the layer is valid and can be drawn.
Definition: qgsmaplayer.h:720
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:157
virtual QgsError error() const
Get current status error.
Definition: qgsmaplayer.h:365
QString mTitle
Definition: qgsmaplayer.h:733
virtual bool readSld(const QDomNode &node, QString &errorMessage)
Definition: qgsmaplayer.h:469
QString mMetadataUrlFormat
Definition: qgsmaplayer.h:750
void setLegendUrl(const QString &legendUrl)
Definition: qgsmaplayer.h:511
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:221
QString mAttribution
Attribution of the layer.
Definition: qgsmaplayer.h:744
QString mAbstract
Description of the layer.
Definition: qgsmaplayer.h:736
virtual Q_DECL_DEPRECATED void onCacheImageDelete()
Definition: qgsmaplayer.h:521
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:203
Contains information about the context of a rendering operation.
QString legendUrlFormat() const
Definition: qgsmaplayer.h:514
QString mDataSource
Data source description string, varies by layer type.
Definition: qgsmaplayer.h:723
QString legendUrl() const
Definition: qgsmaplayer.h:512
QgsError is container for error messages (report).
Definition: qgserror.h:80
QString mLegendUrl
WMS legend.
Definition: qgsmaplayer.h:753
Class for storing a coordinate reference system (CRS)
QString originalName() const
Get the original name of the layer.
Definition: qgsmaplayer.h:93
QString metadataUrlType() const
Get the metadata type of the layer used by QGIS Server in GetCapabilities request MetadataUrlType ind...
Definition: qgsmaplayer.h:215
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:183
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:712
virtual QDateTime timestamp() const
Time stamp of data source in the moment when data/metadata were loaded by provider.
Definition: qgsmaplayer.h:633
void setAttribution(const QString &attrib)
Set the attribution of the layer used by QGIS Server in GetCapabilities request Attribution indicates...
Definition: qgsmaplayer.h:171
QString keywordList() const
Get the keyword list of the layer used by QGIS Server in GetCapabilities request. ...
Definition: qgsmaplayer.h:137
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:177
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:145
QString mLayerOrigName
Original name of the layer.
Definition: qgsmaplayer.h:730
QString mMetadataUrlType
Definition: qgsmaplayer.h:749
QString metadataUrlFormat() const
Get the metadata format of the layer used by QGIS Server in GetCapabilities request MetadataUrlType i...
Definition: qgsmaplayer.h:227
void setAbstract(const QString &abstract)
Set the abstract of the layer used by QGIS Server in GetCapabilities request.
Definition: qgsmaplayer.h:121
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:298