QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties 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 <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;
37 class QgsMapLayerLegend;
39 
40 class QDomDocument;
41 class QKeyEvent;
42 class QPainter;
43 
48 class CORE_EXPORT QgsMapLayer : public QObject
49 {
50  Q_OBJECT
51 
52  public:
54  enum LayerType
55  {
58  PluginLayer // added in 1.5
59  };
60 
66  QgsMapLayer( QgsMapLayer::LayerType type = VectorLayer, QString lyrname = QString::null, QString source = QString::null );
67 
69  virtual ~QgsMapLayer();
70 
74  QgsMapLayer::LayerType type() const;
75 
79  QString id() const;
80 
84  void setLayerName( const QString & name );
85 
89  const QString & name() const;
90 
94  const QString & originalName() const { return mLayerOrigName; }
95 
96  void setTitle( const QString& title ) { mTitle = title; }
97  const QString& title() const { return mTitle; }
98 
99  void setAbstract( const QString& abstract ) { mAbstract = abstract; }
100  const QString& abstract() const { return mAbstract; }
101 
102  void setKeywordList( const QString& keywords ) { mKeywordList = keywords; }
103  const QString& keywordList() const { return mKeywordList; }
104 
105  /* Layer dataUrl information */
106  void setDataUrl( const QString& dataUrl ) { mDataUrl = dataUrl; }
107  const QString& dataUrl() const { return mDataUrl; }
108  void setDataUrlFormat( const QString& dataUrlFormat ) { mDataUrlFormat = dataUrlFormat; }
109  const QString& dataUrlFormat() const { return mDataUrlFormat; }
110 
111  /* Layer attribution information */
112  void setAttribution( const QString& attrib ) { mAttribution = attrib; }
113  const QString& attribution() const { return mAttribution; }
114  void setAttributionUrl( const QString& attribUrl ) { mAttributionUrl = attribUrl; }
115  const QString& attributionUrl() const { return mAttributionUrl; }
116 
117  /* Layer metadataUrl information */
118  void setMetadataUrl( const QString& metaUrl ) { mMetadataUrl = metaUrl; }
119  const QString& metadataUrl() const { return mMetadataUrl; }
120  void setMetadataUrlType( const QString& metaUrlType ) { mMetadataUrlType = metaUrlType; }
121  const QString& metadataUrlType() const { return mMetadataUrlType; }
122  void setMetadataUrlFormat( const QString& metaUrlFormat ) { mMetadataUrlFormat = metaUrlFormat; }
123  const QString& metadataUrlFormat() const { return mMetadataUrlFormat; }
124 
125  /* Set the blending mode used for rendering a layer */
126  void setBlendMode( const QPainter::CompositionMode &blendMode );
127  /* Returns the current blending mode for a layer */
128  QPainter::CompositionMode blendMode() const;
129 
132  virtual void reload() {}
133 
137  virtual QgsMapLayerRenderer* createMapRenderer( QgsRenderContext& rendererContext ) { Q_UNUSED( rendererContext ); return 0; }
138 
145  virtual bool draw( QgsRenderContext& rendererContext );
146 
150  virtual void drawLabels( QgsRenderContext& rendererContext );
151 
153  virtual QgsRectangle extent();
154 
159  bool isValid();
160 
165  QString publicSource() const;
166 
168  const QString &source() const;
169 
174  virtual QStringList subLayers() const;
175 
180  virtual void setLayerOrder( const QStringList &layers );
181 
183  virtual void setSubLayerVisibility( QString name, bool vis );
184 
186  virtual bool isEditable() const;
187 
202  bool readLayerXML( const QDomElement& layerElement );
203 
204 
220  bool writeLayerXML( QDomElement& layerElement, QDomDocument& document );
221 
227  static QDomDocument asLayerDefinition( QList<QgsMapLayer*> layers );
228 
231  static QList<QgsMapLayer*> fromLayerDefinition( QDomDocument& document );
232  static QList<QgsMapLayer*> fromLayerDefinitionFile( const QString qlrfile );
233 
236  void setCustomProperty( const QString& key, const QVariant& value );
239  QVariant customProperty( const QString& value, const QVariant& defaultValue = QVariant() ) const;
242  void removeCustomProperty( const QString& key );
243 
244 
246  Q_DECL_DEPRECATED virtual QString lastErrorTitle();
247 
249  Q_DECL_DEPRECATED virtual QString lastError();
250 
255  virtual QgsError error() const { return mError; }
256 
260  const QgsCoordinateReferenceSystem& crs() const;
261 
264  void setCrs( const QgsCoordinateReferenceSystem& srs, bool emitSignal = true );
265 
267  static QString capitaliseLayerName( const QString& name );
268 
276  virtual QString styleURI( );
277 
286  virtual QString loadDefaultStyle( bool & theResultFlag );
287 
301  virtual QString loadNamedStyle( const QString &theURI, bool &theResultFlag );
302 
303  virtual bool loadNamedStyleFromDb( const QString &db, const QString &theURI, QString &qml );
304 
305  //TODO edit infos
312  virtual void exportNamedStyle( QDomDocument &doc, QString &errorMsg );
313 
314 
321  virtual void exportSldStyle( QDomDocument &doc, QString &errorMsg );
322 
331  virtual QString saveDefaultStyle( bool & theResultFlag );
332 
346  virtual QString saveNamedStyle( const QString &theURI, bool &theResultFlag );
347 
348  virtual QString saveSldStyle( const QString &theURI, bool &theResultFlag );
349  virtual QString loadSldStyle( const QString &theURI, bool &theResultFlag );
350 
351  virtual bool readSld( const QDomNode &node, QString &errorMessage )
352  { Q_UNUSED( node ); errorMessage = QString( "Layer type %1 not supported" ).arg( type() ); return false; }
353 
354 
360  virtual bool readSymbology( const QDomNode& node, QString& errorMessage ) = 0;
361 
368  virtual bool writeSymbology( QDomNode &node, QDomDocument& doc, QString& errorMessage ) const = 0;
369 
371  QUndoStack *undoStack();
372 
373  /* Layer legendUrl information */
374  void setLegendUrl( const QString& legendUrl ) { mLegendUrl = legendUrl; }
375  const QString& legendUrl() const { return mLegendUrl; }
376  void setLegendUrlFormat( const QString& legendUrlFormat ) { mLegendUrlFormat = legendUrlFormat; }
377  const QString& legendUrlFormat() const { return mLegendUrlFormat; }
378 
380  Q_DECL_DEPRECATED QImage *cacheImage() { return 0; }
382  Q_DECL_DEPRECATED void setCacheImage( QImage * );
384  Q_DECL_DEPRECATED virtual void onCacheImageDelete() {}
385 
391  void setLegend( QgsMapLayerLegend* legend );
396  QgsMapLayerLegend* legend() const;
397 
398  public slots:
399 
401  virtual void invalidTransformInput();
402 
404  void setMinimumScale( float theMinScale );
405  float minimumScale() const;
406 
408  void setMaximumScale( float theMaxScale );
409  float maximumScale() const;
410 
412  void toggleScaleBasedVisibility( bool theVisibilityFlag );
413  bool hasScaleBasedVisibility() const;
414 
417  Q_DECL_DEPRECATED void clearCacheImage();
418 
420  virtual QString metadata();
421 
423  virtual QDateTime timestamp() const { return QDateTime() ; }
424 
425  signals:
426 
428  void drawingProgress( int theProgress, int theTotalSteps );
429 
431  void statusChanged( QString theStatus );
432 
434  void layerNameChanged();
435 
439  void layerCrsChanged();
440 
444  void repaintRequested();
445 
447  void screenUpdateRequested();
448 
450  void recalculateExtents();
451 
454  void dataChanged();
455 
457  void blendModeChanged( const QPainter::CompositionMode &blendMode );
458 
460  void rendererChanged();
461 
466  void legendChanged();
467 
468  protected:
470  virtual void setExtent( const QgsRectangle &rect );
471 
474  void setValid( bool valid );
475 
479  virtual bool readXml( const QDomNode& layer_node );
480 
484  virtual bool writeXml( QDomNode & layer_node, QDomDocument & document );
485 
486 
490  void readCustomProperties( const QDomNode& layerNode, const QString& keyStartsWith = "" );
491 
493  void writeCustomProperties( QDomNode & layerNode, QDomDocument & doc ) const;
494 
496  void connectNotify( const char * signal );
497 
499  void appendError( const QgsErrorMessage & theMessage ) { mError.append( theMessage );}
501  void setError( const QgsError & theError ) { mError = theError;}
502 
505 
507  bool mValid;
508 
510  QString mDataSource;
511 
513  QString mLayerName;
514 
518  QString mLayerOrigName;
519 
520  QString mTitle;
521 
523  QString mAbstract;
524  QString mKeywordList;
525 
527  QString mDataUrl;
528  QString mDataUrlFormat;
529 
531  QString mAttribution;
533 
535  QString mMetadataUrl;
538 
540  QString mLegendUrl;
542 
545 
546  private:
550 
552  QgsMapLayer( QgsMapLayer const & );
553 
555  QgsMapLayer & operator=( QgsMapLayer const & );
556 
558  QString mID;
559 
562 
564  QPainter::CompositionMode mBlendMode;
565 
567  QString mTag;
568 
570  float mMinScale;
572  float mMaxScale;
575 
577  QUndoStack mUndoStack;
578 
581 
584 };
585 
586 #endif
void setMetadataUrl(const QString &metaUrl)
Definition: qgsmaplayer.h:118
A rectangle specified with double values.
Definition: qgsrectangle.h:35
Base class for all map layer types.
Definition: qgsmaplayer.h:48
QString mID
Unique ID of this layer - used to refer to this layer in map layer registry.
Definition: qgsmaplayer.h:558
QString mAttributionUrl
Definition: qgsmaplayer.h:532
QString mKeywordList
Definition: qgsmaplayer.h:524
LayerType
Layers enum defining the types of layers that can be added to a map.
Definition: qgsmaplayer.h:54
QString mDataUrlFormat
Definition: qgsmaplayer.h:528
const QString & originalName() const
Get the original name of the layer.
Definition: qgsmaplayer.h:94
QString mLegendUrlFormat
Definition: qgsmaplayer.h:541
virtual void reload()
Synchronises with changes in the datasource.
Definition: qgsmaplayer.h:132
bool mScaleBasedVisibility
A flag that tells us whether to use the above vars to restrict layer visibility.
Definition: qgsmaplayer.h:574
const QString & attribution() const
Definition: qgsmaplayer.h:113
void setMetadataUrlType(const QString &metaUrlType)
Definition: qgsmaplayer.h:120
virtual QgsMapLayerRenderer * createMapRenderer(QgsRenderContext &rendererContext)
Return new instance of QgsMapLayerRenderer that will be used for rendering of given context...
Definition: qgsmaplayer.h:137
QUndoStack mUndoStack
Collection of undoable operations for this layer.
Definition: qgsmaplayer.h:577
QString mLayerName
Name of the layer - used for display.
Definition: qgsmaplayer.h:513
QgsError mError
Error.
Definition: qgsmaplayer.h:544
const QString & legendUrl() const
Definition: qgsmaplayer.h:375
QgsRectangle mExtent
Extent of the layer.
Definition: qgsmaplayer.h:504
QPainter::CompositionMode mBlendMode
Blend mode for the layer.
Definition: qgsmaplayer.h:564
QString mMetadataUrl
MetadataUrl of the layer.
Definition: qgsmaplayer.h:535
void setLegendUrlFormat(const QString &legendUrlFormat)
Definition: qgsmaplayer.h:376
void setError(const QgsError &theError)
Set error message.
Definition: qgsmaplayer.h:501
void setKeywordList(const QString &keywords)
Definition: qgsmaplayer.h:102
const QString & dataUrl() const
Definition: qgsmaplayer.h:107
void setTitle(const QString &title)
Definition: qgsmaplayer.h:96
Q_DECL_DEPRECATED QImage * cacheImage()
Definition: qgsmaplayer.h:380
const QString & metadataUrlType() const
Definition: qgsmaplayer.h:121
QgsObjectCustomProperties mCustomProperties
Layer's persistent storage of additional properties (may be used by plugins)
Definition: qgsmaplayer.h:580
QString mDataUrl
DataUrl of the layer.
Definition: qgsmaplayer.h:527
const QString & metadataUrl() const
Definition: qgsmaplayer.h:119
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:507
void setDataUrlFormat(const QString &dataUrlFormat)
Definition: qgsmaplayer.h:108
virtual QgsError error() const
Get current status error.
Definition: qgsmaplayer.h:255
QString mTitle
Definition: qgsmaplayer.h:520
virtual bool readSld(const QDomNode &node, QString &errorMessage)
Definition: qgsmaplayer.h:351
QString mMetadataUrlFormat
Definition: qgsmaplayer.h:537
void setLegendUrl(const QString &legendUrl)
Definition: qgsmaplayer.h:374
void setMetadataUrlFormat(const QString &metaUrlFormat)
Definition: qgsmaplayer.h:122
QString mAttribution
Attribution of the layer.
Definition: qgsmaplayer.h:531
QString mAbstract
Description of the layer.
Definition: qgsmaplayer.h:523
virtual Q_DECL_DEPRECATED void onCacheImageDelete()
Definition: qgsmaplayer.h:384
Contains information about the context of a rendering operation.
QString mDataSource
data source description string, varies by layer type
Definition: qgsmaplayer.h:510
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:572
QString mLegendUrl
WMS legend.
Definition: qgsmaplayer.h:540
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:114
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:499
QgsMapLayer::LayerType mLayerType
Type of the layer (eg.
Definition: qgsmaplayer.h:561
QgsCoordinateReferenceSystem * mCRS
layer's spatial reference system.
Definition: qgsmaplayer.h:549
virtual QDateTime timestamp() const
Time stamp of data source in the moment when data/metadata were loaded by provider.
Definition: qgsmaplayer.h:423
void setAttribution(const QString &attrib)
Definition: qgsmaplayer.h:112
const QString & attributionUrl() const
Definition: qgsmaplayer.h:115
const QString & metadataUrlFormat() const
Definition: qgsmaplayer.h:123
const QString & legendUrlFormat() const
Definition: qgsmaplayer.h:377
QgsMapLayerLegend * mLegend
Controller of legend items of this layer.
Definition: qgsmaplayer.h:583
const QString & title() const
Definition: qgsmaplayer.h:97
void setDataUrl(const QString &dataUrl)
Definition: qgsmaplayer.h:106
QString mLayerOrigName
Original name of the layer.
Definition: qgsmaplayer.h:518
QString mMetadataUrlType
Definition: qgsmaplayer.h:536
QString mTag
Tag for embedding additional information.
Definition: qgsmaplayer.h:567
const QString & keywordList() const
Definition: qgsmaplayer.h:103
float mMinScale
Minimum scale denominator at which this layer should be displayed.
Definition: qgsmaplayer.h:570
void setAbstract(const QString &abstract)
Definition: qgsmaplayer.h:99
const QString & dataUrlFormat() const
Definition: qgsmaplayer.h:109