QGIS API Documentation  2.3.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 <QObject>
23 #include <QUndoStack>
24 #include <QVariant>
25 #include <QImage>
26 #include <QDomNode>
27 #include <QPainter>
28 
29 #include "qgis.h"
30 #include "qgserror.h"
31 #include "qgsrectangle.h"
32 #include "qgsmaprenderer.h"
34 
35 class QgsRenderContext;
38 
39 class QDomDocument;
40 class QKeyEvent;
41 class QPainter;
42 
47 class CORE_EXPORT QgsMapLayer : public QObject
48 {
49  Q_OBJECT
50 
51  public:
53  enum LayerType
54  {
57  PluginLayer // added in 1.5
58  };
59 
65  QgsMapLayer( QgsMapLayer::LayerType type = VectorLayer, QString lyrname = QString::null, QString source = QString::null );
66 
68  virtual ~QgsMapLayer();
69 
73  QgsMapLayer::LayerType type() const;
74 
78  QString id() const;
79 
83  void setLayerName( const QString & name );
84 
88  const QString & name() const;
89 
93  const QString & originalName() const { return mLayerOrigName; }
94 
95  void setTitle( const QString& title ) { mTitle = title; }
96  const QString& title() const { return mTitle; }
97 
98  void setAbstract( const QString& abstract ) { mAbstract = abstract; }
99  const QString& abstract() const { return mAbstract; }
100 
101  void setKeywordList( const QString& keywords ) { mKeywordList = keywords; }
102  const QString& keywordList() const { return mKeywordList; }
103 
104  /* Layer dataUrl information */
105  void setDataUrl( const QString& dataUrl ) { mDataUrl = dataUrl; }
106  const QString& dataUrl() const { return mDataUrl; }
107  void setDataUrlFormat( const QString& dataUrlFormat ) { mDataUrlFormat = dataUrlFormat; }
108  const QString& dataUrlFormat() const { return mDataUrlFormat; }
109 
110  /* Layer attribution information */
111  void setAttribution( const QString& attrib ) { mAttribution = attrib; }
112  const QString& attribution() const { return mAttribution; }
113  void setAttributionUrl( const QString& attribUrl ) { mAttributionUrl = attribUrl; }
114  const QString& attributionUrl() const { return mAttributionUrl; }
115 
116  /* Layer metadataUrl information */
117  void setMetadataUrl( const QString& metaUrl ) { mMetadataUrl = metaUrl; }
118  const QString& metadataUrl() const { return mMetadataUrl; }
119  void setMetadataUrlType( const QString& metaUrlType ) { mMetadataUrlType = metaUrlType; }
120  const QString& metadataUrlType() const { return mMetadataUrlType; }
121  void setMetadataUrlFormat( const QString& metaUrlFormat ) { mMetadataUrlFormat = metaUrlFormat; }
122  const QString& metadataUrlFormat() const { return mMetadataUrlFormat; }
123 
124  /* Set the blending mode used for rendering a layer */
125  void setBlendMode( const QPainter::CompositionMode &blendMode );
126  /* Returns the current blending mode for a layer */
127  QPainter::CompositionMode blendMode() const;
128 
131  virtual void reload() {}
132 
136  virtual QgsMapLayerRenderer* createMapRenderer( QgsRenderContext& rendererContext ) { Q_UNUSED( rendererContext ); return 0; }
137 
144  virtual bool draw( QgsRenderContext& rendererContext );
145 
149  virtual void drawLabels( QgsRenderContext& rendererContext );
150 
152  virtual QgsRectangle extent();
153 
158  bool isValid();
159 
164  QString publicSource() const;
165 
167  const QString &source() const;
168 
173  virtual QStringList subLayers() const;
174 
179  virtual void setLayerOrder( const QStringList &layers );
180 
182  virtual void setSubLayerVisibility( QString name, bool vis );
183 
185  virtual bool isEditable() const;
186 
201  bool readLayerXML( const QDomElement& layerElement );
202 
203 
219  bool writeLayerXML( QDomElement& layerElement, QDomDocument& document );
220 
226  QDomDocument asLayerDefinition( );
227 
230  static QgsMapLayer* fromLayerDefinition( QDomDocument& document );
231  static QgsMapLayer* fromLayerDefinitionFile( const QString qlrfile );
232 
235  void setCustomProperty( const QString& key, const QVariant& value );
238  QVariant customProperty( const QString& value, const QVariant& defaultValue = QVariant() ) const;
241  void removeCustomProperty( const QString& key );
242 
243 
245  Q_DECL_DEPRECATED virtual QString lastErrorTitle();
246 
248  Q_DECL_DEPRECATED virtual QString lastError();
249 
254  virtual QgsError error() const { return mError; }
255 
259  const QgsCoordinateReferenceSystem& crs() const;
260 
263  void setCrs( const QgsCoordinateReferenceSystem& srs, bool emitSignal = true );
264 
266  static QString capitaliseLayerName( const QString& name );
267 
275  virtual QString styleURI( );
276 
285  virtual QString loadDefaultStyle( bool & theResultFlag );
286 
300  virtual QString loadNamedStyle( const QString &theURI, bool &theResultFlag );
301 
302  virtual bool loadNamedStyleFromDb( const QString &db, const QString &theURI, QString &qml );
303 
304  //TODO edit infos
311  virtual void exportNamedStyle( QDomDocument &doc, QString &errorMsg );
312 
313 
320  virtual void exportSldStyle( QDomDocument &doc, QString &errorMsg );
321 
330  virtual QString saveDefaultStyle( bool & theResultFlag );
331 
345  virtual QString saveNamedStyle( const QString &theURI, bool &theResultFlag );
346 
347  virtual QString saveSldStyle( const QString &theURI, bool &theResultFlag );
348  virtual QString loadSldStyle( const QString &theURI, bool &theResultFlag );
349 
350  virtual bool readSld( const QDomNode &node, QString &errorMessage )
351  { Q_UNUSED( node ); errorMessage = QString( "Layer type %1 not supported" ).arg( type() ); return false; }
352 
353 
359  virtual bool readSymbology( const QDomNode& node, QString& errorMessage ) = 0;
360 
367  virtual bool writeSymbology( QDomNode &node, QDomDocument& doc, QString& errorMessage ) const = 0;
368 
370  QUndoStack *undoStack();
371 
372  /* Layer legendUrl information */
373  void setLegendUrl( const QString& legendUrl ) { mLegendUrl = legendUrl; }
374  const QString& legendUrl() const { return mLegendUrl; }
375  void setLegendUrlFormat( const QString& legendUrlFormat ) { mLegendUrlFormat = legendUrlFormat; }
376  const QString& legendUrlFormat() const { return mLegendUrlFormat; }
377 
379  Q_DECL_DEPRECATED QImage *cacheImage() { return 0; }
381  Q_DECL_DEPRECATED void setCacheImage( QImage * );
383  Q_DECL_DEPRECATED virtual void onCacheImageDelete() {}
384 
385  public slots:
386 
388  virtual void invalidTransformInput();
389 
391  void setMinimumScale( float theMinScale );
392  float minimumScale() const;
393 
395  void setMaximumScale( float theMaxScale );
396  float maximumScale() const;
397 
399  void toggleScaleBasedVisibility( bool theVisibilityFlag );
400  bool hasScaleBasedVisibility() const;
401 
404  Q_DECL_DEPRECATED void clearCacheImage();
405 
407  virtual QString metadata();
408 
410  virtual QDateTime timestamp() const { return QDateTime() ; }
411 
412  signals:
413 
415  void drawingProgress( int theProgress, int theTotalSteps );
416 
418  void statusChanged( QString theStatus );
419 
421  void layerNameChanged();
422 
426  void layerCrsChanged();
427 
431  void repaintRequested();
432 
434  void screenUpdateRequested();
435 
437  void recalculateExtents();
438 
441  void dataChanged();
442 
444  void blendModeChanged( const QPainter::CompositionMode &blendMode );
445 
446  protected:
448  virtual void setExtent( const QgsRectangle &rect );
449 
452  void setValid( bool valid );
453 
457  virtual bool readXml( const QDomNode& layer_node );
458 
462  virtual bool writeXml( QDomNode & layer_node, QDomDocument & document );
463 
464 
468  void readCustomProperties( const QDomNode& layerNode, const QString& keyStartsWith = "" );
469 
471  void writeCustomProperties( QDomNode & layerNode, QDomDocument & doc ) const;
472 
474  void connectNotify( const char * signal );
475 
477  void appendError( const QgsErrorMessage & theMessage ) { mError.append( theMessage );}
479  void setError( const QgsError & theError ) { mError = theError;}
480 
483 
485  bool mValid;
486 
488  QString mDataSource;
489 
491  QString mLayerName;
492 
496  QString mLayerOrigName;
497 
498  QString mTitle;
499 
501  QString mAbstract;
502  QString mKeywordList;
503 
505  QString mDataUrl;
506  QString mDataUrlFormat;
507 
509  QString mAttribution;
511 
513  QString mMetadataUrl;
516 
518  QString mLegendUrl;
520 
523 
524  private:
528 
530  QgsMapLayer( QgsMapLayer const & );
531 
533  QgsMapLayer & operator=( QgsMapLayer const & );
534 
536  QString mID;
537 
540 
542  QPainter::CompositionMode mBlendMode;
543 
545  QString mTag;
546 
548  float mMinScale;
550  float mMaxScale;
553 
555  QUndoStack mUndoStack;
556 
559 };
560 
561 #endif
void setMetadataUrl(const QString &metaUrl)
Definition: qgsmaplayer.h:117
A rectangle specified with double values.
Definition: qgsrectangle.h:35
Base class for all map layer types.
Definition: qgsmaplayer.h:47
QString mID
Unique ID of this layer - used to refer to this layer in map layer registry.
Definition: qgsmaplayer.h:536
QString mAttributionUrl
Definition: qgsmaplayer.h:510
QString mKeywordList
Definition: qgsmaplayer.h:502
QString mDataUrlFormat
Definition: qgsmaplayer.h:506
const QString & originalName() const
Get the original name of the layer.
Definition: qgsmaplayer.h:93
QString mLegendUrlFormat
Definition: qgsmaplayer.h:519
virtual void reload()
Synchronises with changes in the datasource.
Definition: qgsmaplayer.h:131
bool mScaleBasedVisibility
A flag that tells us whether to use the above vars to restrict layer visibility.
Definition: qgsmaplayer.h:552
const QString & attribution() const
Definition: qgsmaplayer.h:112
void setMetadataUrlType(const QString &metaUrlType)
Definition: qgsmaplayer.h:119
virtual QgsMapLayerRenderer * createMapRenderer(QgsRenderContext &rendererContext)
Return new instance of QgsMapLayerRenderer that will be used for rendering of given context...
Definition: qgsmaplayer.h:136
QUndoStack mUndoStack
Collection of undoable operations for this layer.
Definition: qgsmaplayer.h:555
QString mLayerName
Name of the layer - used for display.
Definition: qgsmaplayer.h:491
QgsError mError
Error.
Definition: qgsmaplayer.h:522
const QString & legendUrl() const
Definition: qgsmaplayer.h:374
QgsRectangle mExtent
Extent of the layer.
Definition: qgsmaplayer.h:482
QPainter::CompositionMode mBlendMode
Blend mode for the layer.
Definition: qgsmaplayer.h:542
QString mMetadataUrl
MetadataUrl of the layer.
Definition: qgsmaplayer.h:513
void setLegendUrlFormat(const QString &legendUrlFormat)
Definition: qgsmaplayer.h:375
void setError(const QgsError &theError)
Set error message.
Definition: qgsmaplayer.h:479
void setKeywordList(const QString &keywords)
Definition: qgsmaplayer.h:101
const QString & dataUrl() const
Definition: qgsmaplayer.h:106
void setTitle(const QString &title)
Definition: qgsmaplayer.h:95
Q_DECL_DEPRECATED QImage * cacheImage()
Definition: qgsmaplayer.h:379
const QString & metadataUrlType() const
Definition: qgsmaplayer.h:120
LayerType
Layers enum defining the types of layers that can be added to a map.
Definition: qgsmaplayer.h:53
QgsObjectCustomProperties mCustomProperties
Layer's persistent storage of additional properties (may be used by plugins)
Definition: qgsmaplayer.h:558
QString mDataUrl
DataUrl of the layer.
Definition: qgsmaplayer.h:505
const QString & metadataUrl() const
Definition: qgsmaplayer.h:118
QgsErrorMessage represents single error message.
Definition: qgserror.h:29
bool mValid
Indicates if the layer is valid and can be drawn.
Definition: qgsmaplayer.h:485
void setDataUrlFormat(const QString &dataUrlFormat)
Definition: qgsmaplayer.h:107
virtual QgsError error() const
Get current status error.
Definition: qgsmaplayer.h:254
QString mTitle
Definition: qgsmaplayer.h:498
virtual bool readSld(const QDomNode &node, QString &errorMessage)
Definition: qgsmaplayer.h:350
QString mMetadataUrlFormat
Definition: qgsmaplayer.h:515
void setLegendUrl(const QString &legendUrl)
Definition: qgsmaplayer.h:373
void setMetadataUrlFormat(const QString &metaUrlFormat)
Definition: qgsmaplayer.h:121
QString mAttribution
Attribution of the layer.
Definition: qgsmaplayer.h:509
QString mAbstract
Description of the layer.
Definition: qgsmaplayer.h:501
virtual Q_DECL_DEPRECATED void onCacheImageDelete()
Definition: qgsmaplayer.h:383
Contains information about the context of a rendering operation.
QString mDataSource
data source description string, varies by layer type
Definition: qgsmaplayer.h:488
QgsError is container for error messages (report).
Definition: qgserror.h:77
float mMaxScale
Maximum scale denominator at which this layer should be displayed.
Definition: qgsmaplayer.h:550
QString mLegendUrl
WMS legend.
Definition: qgsmaplayer.h:518
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:113
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:477
QgsMapLayer::LayerType mLayerType
Type of the layer (eg.
Definition: qgsmaplayer.h:539
QgsCoordinateReferenceSystem * mCRS
layer's spatial reference system.
Definition: qgsmaplayer.h:527
virtual QDateTime timestamp() const
Time stamp of data source in the moment when data/metadata were loaded by provider.
Definition: qgsmaplayer.h:410
void setAttribution(const QString &attrib)
Definition: qgsmaplayer.h:111
const QString & attributionUrl() const
Definition: qgsmaplayer.h:114
const QString & metadataUrlFormat() const
Definition: qgsmaplayer.h:122
const QString & legendUrlFormat() const
Definition: qgsmaplayer.h:376
const QString & title() const
Definition: qgsmaplayer.h:96
void setDataUrl(const QString &dataUrl)
Definition: qgsmaplayer.h:105
QString mLayerOrigName
Original name of the layer.
Definition: qgsmaplayer.h:496
QString mMetadataUrlType
Definition: qgsmaplayer.h:514
QString mTag
Tag for embedding additional information.
Definition: qgsmaplayer.h:545
const QString & keywordList() const
Definition: qgsmaplayer.h:102
float mMinScale
Minimum scale denominator at which this layer should be displayed.
Definition: qgsmaplayer.h:548
void setAbstract(const QString &abstract)
Definition: qgsmaplayer.h:98
const QString & dataUrlFormat() const
Definition: qgsmaplayer.h:108