QGIS API Documentation  2.5.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 <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
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 
77  QString id() const;
78 
82  void setLayerName( const QString & name );
83 
87  const QString & name() const;
88 
90  const QString & originalName() const { return mLayerOrigName; }
91 
92  void setTitle( const QString& title ) { mTitle = title; }
93  const QString& title() const { return mTitle; }
94 
95  void setAbstract( const QString& abstract ) { mAbstract = abstract; }
96  const QString& abstract() const { return mAbstract; }
97 
98  void setKeywordList( const QString& keywords ) { mKeywordList = keywords; }
99  const QString& keywordList() const { return mKeywordList; }
100 
101  /* Layer dataUrl information */
102  void setDataUrl( const QString& dataUrl ) { mDataUrl = dataUrl; }
103  const QString& dataUrl() const { return mDataUrl; }
104  void setDataUrlFormat( const QString& dataUrlFormat ) { mDataUrlFormat = dataUrlFormat; }
105  const QString& dataUrlFormat() const { return mDataUrlFormat; }
106 
107  /* Layer attribution information */
108  void setAttribution( const QString& attrib ) { mAttribution = attrib; }
109  const QString& attribution() const { return mAttribution; }
110  void setAttributionUrl( const QString& attribUrl ) { mAttributionUrl = attribUrl; }
111  const QString& attributionUrl() const { return mAttributionUrl; }
112 
113  /* Layer metadataUrl information */
114  void setMetadataUrl( const QString& metaUrl ) { mMetadataUrl = metaUrl; }
115  const QString& metadataUrl() const { return mMetadataUrl; }
116  void setMetadataUrlType( const QString& metaUrlType ) { mMetadataUrlType = metaUrlType; }
117  const QString& metadataUrlType() const { return mMetadataUrlType; }
118  void setMetadataUrlFormat( const QString& metaUrlFormat ) { mMetadataUrlFormat = metaUrlFormat; }
119  const QString& metadataUrlFormat() const { return mMetadataUrlFormat; }
120 
121  /* Set the blending mode used for rendering a layer */
122  void setBlendMode( const QPainter::CompositionMode &blendMode );
123  /* Returns the current blending mode for a layer */
124  QPainter::CompositionMode blendMode() const;
125 
128  virtual void reload() {}
129 
133  virtual QgsMapLayerRenderer* createMapRenderer( QgsRenderContext& rendererContext ) { Q_UNUSED( rendererContext ); return 0; }
134 
141  virtual bool draw( QgsRenderContext& rendererContext );
142 
146  virtual void drawLabels( QgsRenderContext& rendererContext );
147 
149  virtual QgsRectangle extent();
150 
155  bool isValid();
156 
161  QString publicSource() const;
162 
164  const QString &source() const;
165 
170  virtual QStringList subLayers() const;
171 
176  virtual void setLayerOrder( const QStringList &layers );
177 
179  virtual void setSubLayerVisibility( QString name, bool vis );
180 
182  virtual bool isEditable() const;
183 
198  bool readLayerXML( const QDomElement& layerElement );
199 
200 
217  bool writeLayerXML( QDomElement& layerElement, QDomDocument& document, QString relativeBasePath = QString::null );
218 
224  static QDomDocument asLayerDefinition( QList<QgsMapLayer*> layers, QString relativeBasePath = QString::null );
225 
228  static QList<QgsMapLayer*> fromLayerDefinition( QDomDocument& document );
229  static QList<QgsMapLayer*> fromLayerDefinitionFile( const QString qlrfile );
230 
232  void setCustomProperty( const QString& key, const QVariant& value );
234  QVariant customProperty( const QString& value, const QVariant& defaultValue = QVariant() ) const;
236  void removeCustomProperty( const QString& key );
237 
238 
240  Q_DECL_DEPRECATED virtual QString lastErrorTitle();
241 
243  Q_DECL_DEPRECATED virtual QString lastError();
244 
249  virtual QgsError error() const { return mError; }
250 
254  const QgsCoordinateReferenceSystem& crs() const;
255 
257  void setCrs( const QgsCoordinateReferenceSystem& srs, bool emitSignal = true );
258 
260  static QString capitaliseLayerName( const QString& name );
261 
268  virtual QString styleURI();
269 
278  virtual QString loadDefaultStyle( bool & theResultFlag );
279 
293  virtual QString loadNamedStyle( const QString &theURI, bool &theResultFlag );
294 
295  virtual bool loadNamedStyleFromDb( const QString &db, const QString &theURI, QString &qml );
296 
297  //TODO edit infos
304  virtual void exportNamedStyle( QDomDocument &doc, QString &errorMsg );
305 
306 
313  virtual void exportSldStyle( QDomDocument &doc, QString &errorMsg );
314 
323  virtual QString saveDefaultStyle( bool & theResultFlag );
324 
338  virtual QString saveNamedStyle( const QString &theURI, bool &theResultFlag );
339 
340  virtual QString saveSldStyle( const QString &theURI, bool &theResultFlag );
341  virtual QString loadSldStyle( const QString &theURI, bool &theResultFlag );
342 
343  virtual bool readSld( const QDomNode &node, QString &errorMessage )
344  { Q_UNUSED( node ); errorMessage = QString( "Layer type %1 not supported" ).arg( type() ); return false; }
345 
346 
352  virtual bool readSymbology( const QDomNode& node, QString& errorMessage ) = 0;
353 
360  virtual bool writeSymbology( QDomNode &node, QDomDocument& doc, QString& errorMessage ) const = 0;
361 
363  QUndoStack *undoStack();
364 
365  /* Layer legendUrl information */
366  void setLegendUrl( const QString& legendUrl ) { mLegendUrl = legendUrl; }
367  const QString& legendUrl() const { return mLegendUrl; }
368  void setLegendUrlFormat( const QString& legendUrlFormat ) { mLegendUrlFormat = legendUrlFormat; }
369  const QString& legendUrlFormat() const { return mLegendUrlFormat; }
370 
372  Q_DECL_DEPRECATED QImage *cacheImage() { return 0; }
374  Q_DECL_DEPRECATED void setCacheImage( QImage * );
376  Q_DECL_DEPRECATED virtual void onCacheImageDelete() {}
377 
383  void setLegend( QgsMapLayerLegend* legend );
388  QgsMapLayerLegend* legend() const;
389 
390  public slots:
391 
393  virtual void invalidTransformInput();
394 
396  void setMinimumScale( float theMinScale );
397  float minimumScale() const;
398 
400  void setMaximumScale( float theMaxScale );
401  float maximumScale() const;
402 
404  void toggleScaleBasedVisibility( bool theVisibilityFlag );
405  bool hasScaleBasedVisibility() const;
406 
409  Q_DECL_DEPRECATED void clearCacheImage();
410 
417  void triggerRepaint();
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 
437  void layerCrsChanged();
438 
442  void repaintRequested();
443 
445  void screenUpdateRequested();
446 
448  void recalculateExtents();
449 
451  void dataChanged();
452 
454  void blendModeChanged( const QPainter::CompositionMode &blendMode );
455 
457  void rendererChanged();
458 
463  void legendChanged();
464 
465  protected:
467  virtual void setExtent( const QgsRectangle &rect );
468 
470  void setValid( bool valid );
471 
475  virtual bool readXml( const QDomNode& layer_node );
476 
480  virtual bool writeXml( QDomNode & layer_node, QDomDocument & document );
481 
482 
486  void readCustomProperties( const QDomNode& layerNode, const QString& keyStartsWith = "" );
487 
489  void writeCustomProperties( QDomNode & layerNode, QDomDocument & doc ) const;
490 
492  void connectNotify( const char * signal );
493 
495  void appendError( const QgsErrorMessage & theMessage ) { mError.append( theMessage );}
497  void setError( const QgsError & theError ) { mError = theError;}
498 
501 
503  bool mValid;
504 
506  QString mDataSource;
507 
509  QString mLayerName;
510 
513  QString mLayerOrigName;
514 
515  QString mTitle;
516 
518  QString mAbstract;
519  QString mKeywordList;
520 
522  QString mDataUrl;
523  QString mDataUrlFormat;
524 
526  QString mAttribution;
528 
530  QString mMetadataUrl;
533 
535  QString mLegendUrl;
537 
540 
541  private:
545 
547  QgsMapLayer( QgsMapLayer const & );
548 
550  QgsMapLayer & operator=( QgsMapLayer const & );
551 
553  QString mID;
554 
556  QgsMapLayer::LayerType mLayerType;
557 
559  QPainter::CompositionMode mBlendMode;
560 
562  QString mTag;
563 
565  float mMinScale;
567  float mMaxScale;
569  bool mScaleBasedVisibility;
570 
572  QUndoStack mUndoStack;
573 
575  QgsObjectCustomProperties mCustomProperties;
576 
578  QgsMapLayerLegend* mLegend;
579 };
580 
581 #endif
void setMetadataUrl(const QString &metaUrl)
Definition: qgsmaplayer.h:114
A rectangle specified with double values.
Definition: qgsrectangle.h:35
Base class for all map layer types.
Definition: qgsmaplayer.h:48
QString mAttributionUrl
Definition: qgsmaplayer.h:527
QString mKeywordList
Definition: qgsmaplayer.h:519
LayerType
Layers enum defining the types of layers that can be added to a map.
Definition: qgsmaplayer.h:54
QString mDataUrlFormat
Definition: qgsmaplayer.h:523
const QString & originalName() const
Get the original name of the layer.
Definition: qgsmaplayer.h:90
QString mLegendUrlFormat
Definition: qgsmaplayer.h:536
virtual void reload()
Synchronises with changes in the datasource.
Definition: qgsmaplayer.h:128
const QString & attribution() const
Definition: qgsmaplayer.h:109
void setMetadataUrlType(const QString &metaUrlType)
Definition: qgsmaplayer.h:116
virtual QgsMapLayerRenderer * createMapRenderer(QgsRenderContext &rendererContext)
Return new instance of QgsMapLayerRenderer that will be used for rendering of given context...
Definition: qgsmaplayer.h:133
QString mLayerName
Name of the layer - used for display.
Definition: qgsmaplayer.h:509
Definition: qgsmaplayer.h:57
QgsError mError
Error.
Definition: qgsmaplayer.h:539
const QString & legendUrl() const
Definition: qgsmaplayer.h:367
QgsRectangle mExtent
Extent of the layer.
Definition: qgsmaplayer.h:500
QString mMetadataUrl
MetadataUrl of the layer.
Definition: qgsmaplayer.h:530
void setLegendUrlFormat(const QString &legendUrlFormat)
Definition: qgsmaplayer.h:368
void setError(const QgsError &theError)
Set error message.
Definition: qgsmaplayer.h:497
void setKeywordList(const QString &keywords)
Definition: qgsmaplayer.h:98
const QString & dataUrl() const
Definition: qgsmaplayer.h:103
void setTitle(const QString &title)
Definition: qgsmaplayer.h:92
Q_DECL_DEPRECATED QImage * cacheImage()
Definition: qgsmaplayer.h:372
const QString & metadataUrlType() const
Definition: qgsmaplayer.h:117
QString mDataUrl
DataUrl of the layer.
Definition: qgsmaplayer.h:522
const QString & metadataUrl() const
Definition: qgsmaplayer.h:115
The QgsMapLayerLegend class is abstract interface for implementations of legends for one map layer...
Definition: qgsmaplayerlegend.h:34
QgsErrorMessage represents single error message.
Definition: qgserror.h:29
bool mValid
Indicates if the layer is valid and can be drawn.
Definition: qgsmaplayer.h:503
void setDataUrlFormat(const QString &dataUrlFormat)
Definition: qgsmaplayer.h:104
virtual QgsError error() const
Get current status error.
Definition: qgsmaplayer.h:249
QString mTitle
Definition: qgsmaplayer.h:515
virtual bool readSld(const QDomNode &node, QString &errorMessage)
Definition: qgsmaplayer.h:343
QString mMetadataUrlFormat
Definition: qgsmaplayer.h:532
void setLegendUrl(const QString &legendUrl)
Definition: qgsmaplayer.h:366
void setMetadataUrlFormat(const QString &metaUrlFormat)
Definition: qgsmaplayer.h:118
QString mAttribution
Attribution of the layer.
Definition: qgsmaplayer.h:526
QString mAbstract
Description of the layer.
Definition: qgsmaplayer.h:518
virtual Q_DECL_DEPRECATED void onCacheImageDelete()
Definition: qgsmaplayer.h:376
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:39
QString mDataSource
data source description string, varies by layer type
Definition: qgsmaplayer.h:506
QgsError is container for error messages (report).
Definition: qgserror.h:77
Definition: qgsmaplayer.h:56
QString mLegendUrl
WMS legend.
Definition: qgsmaplayer.h:535
Class for storing a coordinate reference system (CRS)
Definition: qgscoordinatereferencesystem.h:50
Simple key-value store (keys = strings, values = variants) that supports loading/saving to/from XML i...
Definition: qgsobjectcustomproperties.h:33
void setAttributionUrl(const QString &attribUrl)
Definition: qgsmaplayer.h:110
Base class for utility classes that encapsulate information necessary for rendering of map layers...
Definition: qgsmaplayerrenderer.h:43
void appendError(const QgsErrorMessage &theMessage)
Add error message.
Definition: qgsmaplayer.h:495
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:108
const QString & attributionUrl() const
Definition: qgsmaplayer.h:111
const QString & metadataUrlFormat() const
Definition: qgsmaplayer.h:119
const QString & legendUrlFormat() const
Definition: qgsmaplayer.h:369
const QString & title() const
Definition: qgsmaplayer.h:93
void setDataUrl(const QString &dataUrl)
Definition: qgsmaplayer.h:102
QString mLayerOrigName
Original name of the layer.
Definition: qgsmaplayer.h:513
QString mMetadataUrlType
Definition: qgsmaplayer.h:531
const QString & keywordList() const
Definition: qgsmaplayer.h:99
void setAbstract(const QString &abstract)
Definition: qgsmaplayer.h:95
const QString & dataUrlFormat() const
Definition: qgsmaplayer.h:105