QGIS API Documentation  2.9.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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, QString lyrname = QString::null, 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  const QString & name() const;
89 
91  const QString & originalName() const { return mLayerOrigName; }
92 
93  void setTitle( const QString& title ) { mTitle = title; }
94  const QString& title() const { return mTitle; }
95 
96  void setAbstract( const QString& abstract ) { mAbstract = abstract; }
97  const QString& abstract() const { return mAbstract; }
98 
99  void setKeywordList( const QString& keywords ) { mKeywordList = keywords; }
100  const QString& keywordList() const { return mKeywordList; }
101 
102  /* Layer dataUrl information */
103  void setDataUrl( const QString& dataUrl ) { mDataUrl = dataUrl; }
104  const QString& dataUrl() const { return mDataUrl; }
105  void setDataUrlFormat( const QString& dataUrlFormat ) { mDataUrlFormat = dataUrlFormat; }
106  const QString& dataUrlFormat() const { return mDataUrlFormat; }
107 
108  /* Layer attribution information */
109  void setAttribution( const QString& attrib ) { mAttribution = attrib; }
110  const QString& attribution() const { return mAttribution; }
111  void setAttributionUrl( const QString& attribUrl ) { mAttributionUrl = attribUrl; }
112  const QString& attributionUrl() const { return mAttributionUrl; }
113 
114  /* Layer metadataUrl information */
115  void setMetadataUrl( const QString& metaUrl ) { mMetadataUrl = metaUrl; }
116  const QString& metadataUrl() const { return mMetadataUrl; }
117  void setMetadataUrlType( const QString& metaUrlType ) { mMetadataUrlType = metaUrlType; }
118  const QString& metadataUrlType() const { return mMetadataUrlType; }
119  void setMetadataUrlFormat( const QString& metaUrlFormat ) { mMetadataUrlFormat = metaUrlFormat; }
120  const QString& metadataUrlFormat() const { return mMetadataUrlFormat; }
121 
122  /* Set the blending mode used for rendering a layer */
123  void setBlendMode( const QPainter::CompositionMode &blendMode );
124  /* Returns the current blending mode for a layer */
125  QPainter::CompositionMode blendMode() const;
126 
129  virtual void reload() {}
130 
134  virtual QgsMapLayerRenderer* createMapRenderer( QgsRenderContext& rendererContext ) { Q_UNUSED( rendererContext ); return 0; }
135 
142  virtual bool draw( QgsRenderContext& rendererContext );
143 
147  virtual void drawLabels( QgsRenderContext& rendererContext );
148 
150  virtual QgsRectangle extent();
151 
156  bool isValid();
157 
162  QString publicSource() const;
163 
165  const QString &source() const;
166 
171  virtual QStringList subLayers() const;
172 
177  virtual void setLayerOrder( const QStringList &layers );
178 
180  virtual void setSubLayerVisibility( QString name, bool vis );
181 
183  virtual bool isEditable() const;
184 
199  bool readLayerXML( const QDomElement& layerElement );
200 
201 
218  bool writeLayerXML( QDomElement& layerElement, QDomDocument& document, QString relativeBasePath = QString::null );
219 
225  static QDomDocument asLayerDefinition( QList<QgsMapLayer*> layers, QString relativeBasePath = QString::null );
226 
229  static QList<QgsMapLayer*> fromLayerDefinition( QDomDocument& document );
230  static QList<QgsMapLayer*> fromLayerDefinitionFile( const QString &qlrfile );
231 
233  void setCustomProperty( const QString& key, const QVariant& value );
235  QVariant customProperty( const QString& value, const QVariant& defaultValue = QVariant() ) const;
237  void removeCustomProperty( const QString& key );
238 
239 
241  Q_DECL_DEPRECATED virtual QString lastErrorTitle();
242 
244  Q_DECL_DEPRECATED virtual QString lastError();
245 
250  virtual QgsError error() const { return mError; }
251 
255  const QgsCoordinateReferenceSystem& crs() const;
256 
258  void setCrs( const QgsCoordinateReferenceSystem& srs, bool emitSignal = true );
259 
261  static QString capitaliseLayerName( const QString& name );
262 
269  virtual QString styleURI();
270 
279  virtual QString loadDefaultStyle( bool & theResultFlag );
280 
294  virtual QString loadNamedStyle( const QString &theURI, bool &theResultFlag );
295 
296  virtual bool loadNamedStyleFromDb( const QString &db, const QString &theURI, QString &qml );
297 
306  virtual bool importNamedStyle( QDomDocument& doc, QString &errorMsg );
307 
314  virtual void exportNamedStyle( QDomDocument &doc, QString &errorMsg );
315 
316 
323  virtual void exportSldStyle( QDomDocument &doc, QString &errorMsg );
324 
333  virtual QString saveDefaultStyle( bool & theResultFlag );
334 
348  virtual QString saveNamedStyle( const QString &theURI, bool &theResultFlag );
349 
350  virtual QString saveSldStyle( const QString &theURI, bool &theResultFlag );
351  virtual QString loadSldStyle( const QString &theURI, bool &theResultFlag );
352 
353  virtual bool readSld( const QDomNode &node, QString &errorMessage )
354  { Q_UNUSED( node ); errorMessage = QString( "Layer type %1 not supported" ).arg( type() ); return false; }
355 
356 
362  virtual bool readSymbology( const QDomNode& node, QString& errorMessage ) = 0;
363 
370  virtual bool writeSymbology( QDomNode &node, QDomDocument& doc, QString& errorMessage ) const = 0;
371 
373  QUndoStack *undoStack();
374 
375  /* Layer legendUrl information */
376  void setLegendUrl( const QString& legendUrl ) { mLegendUrl = legendUrl; }
377  const QString& legendUrl() const { return mLegendUrl; }
378  void setLegendUrlFormat( const QString& legendUrlFormat ) { mLegendUrlFormat = legendUrlFormat; }
379  const QString& legendUrlFormat() const { return mLegendUrlFormat; }
380 
382  Q_DECL_DEPRECATED QImage *cacheImage() { return 0; }
384  Q_DECL_DEPRECATED void setCacheImage( QImage * );
386  Q_DECL_DEPRECATED virtual void onCacheImageDelete() {}
387 
393  void setLegend( QgsMapLayerLegend* legend );
398  QgsMapLayerLegend* legend() const;
399 
404  QgsMapLayerStyleManager* styleManager() const;
405 
413  float minimumScale() const;
414 
422  float maximumScale() const;
423 
430  bool hasScaleBasedVisibility() const;
431 
432  public slots:
433 
435  virtual void invalidTransformInput();
436 
444  void setMinimumScale( const float theMinScale );
445 
453  void setMaximumScale( const float theMaxScale );
454 
461  void setScaleBasedVisibility( const bool enabled );
462 
466  Q_DECL_DEPRECATED void toggleScaleBasedVisibility( bool theVisibilityFlag );
467 
470  Q_DECL_DEPRECATED void clearCacheImage();
471 
478  void triggerRepaint();
479 
481  virtual QString metadata();
482 
484  virtual QDateTime timestamp() const { return QDateTime() ; }
485 
486  signals:
487 
489  void drawingProgress( int theProgress, int theTotalSteps );
490 
492  void statusChanged( QString theStatus );
493 
495  void layerNameChanged();
496 
498  void layerCrsChanged();
499 
503  void repaintRequested();
504 
506  void screenUpdateRequested();
507 
509  void recalculateExtents();
510 
512  void dataChanged();
513 
515  void blendModeChanged( const QPainter::CompositionMode &blendMode );
516 
518  void rendererChanged();
519 
524  void legendChanged();
525 
526  protected:
528  virtual void setExtent( const QgsRectangle &rect );
529 
531  void setValid( bool valid );
532 
536  virtual bool readXml( const QDomNode& layer_node );
537 
541  virtual bool writeXml( QDomNode & layer_node, QDomDocument & document );
542 
543 
547  void readCustomProperties( const QDomNode& layerNode, const QString& keyStartsWith = "" );
548 
550  void writeCustomProperties( QDomNode & layerNode, QDomDocument & doc ) const;
551 
553  void readStyleManager( const QDomNode& layerNode );
555  void writeStyleManager( QDomNode& layerNode, QDomDocument& doc ) const;
556 
557 #if 0
558 
559  void connectNotify( const char * signal ) override;
560 #endif
561 
563  void appendError( const QgsErrorMessage & theMessage ) { mError.append( theMessage );}
565  void setError( const QgsError & theError ) { mError = theError;}
566 
569 
571  bool mValid;
572 
574  QString mDataSource;
575 
577  QString mLayerName;
578 
581  QString mLayerOrigName;
582 
583  QString mTitle;
584 
586  QString mAbstract;
587  QString mKeywordList;
588 
590  QString mDataUrl;
591  QString mDataUrlFormat;
592 
594  QString mAttribution;
596 
598  QString mMetadataUrl;
601 
603  QString mLegendUrl;
605 
608 
609  private:
613 
615  QgsMapLayer( QgsMapLayer const & );
616 
618  QgsMapLayer & operator=( QgsMapLayer const & );
619 
621  QString mID;
622 
624  QgsMapLayer::LayerType mLayerType;
625 
627  QPainter::CompositionMode mBlendMode;
628 
630  QString mTag;
631 
633  float mMinScale;
635  float mMaxScale;
637  bool mScaleBasedVisibility;
638 
640  QUndoStack mUndoStack;
641 
643  QgsObjectCustomProperties mCustomProperties;
644 
646  QgsMapLayerLegend* mLegend;
647 
649  QgsMapLayerStyleManager* mStyleManager;
650 };
651 
652 #endif
void setMetadataUrl(const QString &metaUrl)
Definition: qgsmaplayer.h:115
A rectangle specified with double values.
Definition: qgsrectangle.h:35
Base class for all map layer types.
Definition: qgsmaplayer.h:49
QString mAttributionUrl
Definition: qgsmaplayer.h:595
QString mKeywordList
Definition: qgsmaplayer.h:587
LayerType
Layers enum defining the types of layers that can be added to a map.
Definition: qgsmaplayer.h:55
QString mDataUrlFormat
Definition: qgsmaplayer.h:591
const QString & originalName() const
Get the original name of the layer.
Definition: qgsmaplayer.h:91
QString mLegendUrlFormat
Definition: qgsmaplayer.h:604
virtual void reload()
Synchronises with changes in the datasource.
Definition: qgsmaplayer.h:129
const QString & attribution() const
Definition: qgsmaplayer.h:110
void setMetadataUrlType(const QString &metaUrlType)
Definition: qgsmaplayer.h:117
virtual QgsMapLayerRenderer * createMapRenderer(QgsRenderContext &rendererContext)
Return new instance of QgsMapLayerRenderer that will be used for rendering of given context...
Definition: qgsmaplayer.h:134
QString mLayerName
Name of the layer - used for display.
Definition: qgsmaplayer.h:577
QgsError mError
Error.
Definition: qgsmaplayer.h:607
const QString & legendUrl() const
Definition: qgsmaplayer.h:377
QgsRectangle mExtent
Extent of the layer.
Definition: qgsmaplayer.h:568
QString mMetadataUrl
MetadataUrl of the layer.
Definition: qgsmaplayer.h:598
void setLegendUrlFormat(const QString &legendUrlFormat)
Definition: qgsmaplayer.h:378
void setError(const QgsError &theError)
Set error message.
Definition: qgsmaplayer.h:565
void setKeywordList(const QString &keywords)
Definition: qgsmaplayer.h:99
const QString & dataUrl() const
Definition: qgsmaplayer.h:104
void setTitle(const QString &title)
Definition: qgsmaplayer.h:93
Q_DECL_DEPRECATED QImage * cacheImage()
Definition: qgsmaplayer.h:382
const QString & metadataUrlType() const
Definition: qgsmaplayer.h:118
QString mDataUrl
DataUrl of the layer.
Definition: qgsmaplayer.h:590
const QString & metadataUrl() const
Definition: qgsmaplayer.h:116
The QgsMapLayerLegend class is abstract interface for implementations of legends for one map layer...
QgsErrorMessage represents single error message.
Definition: qgserror.h:29
bool mValid
Indicates if the layer is valid and can be drawn.
Definition: qgsmaplayer.h:571
void setDataUrlFormat(const QString &dataUrlFormat)
Definition: qgsmaplayer.h:105
virtual QgsError error() const
Get current status error.
Definition: qgsmaplayer.h:250
QString mTitle
Definition: qgsmaplayer.h:583
virtual bool readSld(const QDomNode &node, QString &errorMessage)
Definition: qgsmaplayer.h:353
QString mMetadataUrlFormat
Definition: qgsmaplayer.h:600
void setLegendUrl(const QString &legendUrl)
Definition: qgsmaplayer.h:376
void setMetadataUrlFormat(const QString &metaUrlFormat)
Definition: qgsmaplayer.h:119
QString mAttribution
Attribution of the layer.
Definition: qgsmaplayer.h:594
QString mAbstract
Description of the layer.
Definition: qgsmaplayer.h:586
virtual Q_DECL_DEPRECATED void onCacheImageDelete()
Definition: qgsmaplayer.h:386
Contains information about the context of a rendering operation.
QString mDataSource
data source description string, varies by layer type
Definition: qgsmaplayer.h:574
QgsError is container for error messages (report).
Definition: qgserror.h:77
QString mLegendUrl
WMS legend.
Definition: qgsmaplayer.h:603
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)
Definition: qgsmaplayer.h:111
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:563
virtual QDateTime timestamp() const
Time stamp of data source in the moment when data/metadata were loaded by provider.
Definition: qgsmaplayer.h:484
void setAttribution(const QString &attrib)
Definition: qgsmaplayer.h:109
const QString & attributionUrl() const
Definition: qgsmaplayer.h:112
Management of styles for use with one map layer.
const QString & metadataUrlFormat() const
Definition: qgsmaplayer.h:120
const QString & legendUrlFormat() const
Definition: qgsmaplayer.h:379
const QString & title() const
Definition: qgsmaplayer.h:94
void setDataUrl(const QString &dataUrl)
Definition: qgsmaplayer.h:103
QString mLayerOrigName
Original name of the layer.
Definition: qgsmaplayer.h:581
QString mMetadataUrlType
Definition: qgsmaplayer.h:599
const QString & keywordList() const
Definition: qgsmaplayer.h:100
void setAbstract(const QString &abstract)
Definition: qgsmaplayer.h:96
const QString & dataUrlFormat() const
Definition: qgsmaplayer.h:106