QGIS API Documentation  2.2.0-Valmiera
 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"
33 
34 class QgsRenderContext;
36 
37 class QDomDocument;
38 class QKeyEvent;
39 class QPainter;
40 
45 class CORE_EXPORT QgsMapLayer : public QObject
46 {
47  Q_OBJECT
48 
49  public:
51  enum LayerType
52  {
55  PluginLayer // added in 1.5
56  };
57 
63  QgsMapLayer( QgsMapLayer::LayerType type = VectorLayer, QString lyrname = QString::null, QString source = QString::null );
64 
66  virtual ~QgsMapLayer();
67 
71  QgsMapLayer::LayerType type() const;
72 
76  QString id() const;
77 
81  void setLayerName( const QString & name );
82 
86  const QString & name() const;
87 
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 
137  virtual bool draw( QgsRenderContext& rendererContext );
138 
142  virtual void drawLabels( QgsRenderContext& rendererContext );
143 
145  virtual QgsRectangle extent();
146 
151  bool isValid();
152 
157  QString publicSource() const;
158 
160  const QString &source() const;
161 
166  virtual QStringList subLayers() const;
167 
172  virtual void setLayerOrder( const QStringList &layers );
173 
175  virtual void setSubLayerVisibility( QString name, bool vis );
176 
178  virtual bool isEditable() const;
179 
194  bool readLayerXML( const QDomElement& layerElement );
195 
196 
212  bool writeLayerXML( QDomElement& layerElement, QDomDocument& document );
213 
216  void setCustomProperty( const QString& key, const QVariant& value );
219  QVariant customProperty( const QString& value, const QVariant& defaultValue = QVariant() ) const;
222  void removeCustomProperty( const QString& key );
223 
224 
231  virtual QString lastErrorTitle();
232 
239  virtual QString lastError();
240 
245  virtual QgsError error() const { return mError; }
246 
250  const QgsCoordinateReferenceSystem& crs() const;
251 
254  void setCrs( const QgsCoordinateReferenceSystem& srs, bool emitSignal = true );
255 
257  static QString capitaliseLayerName( const QString& name );
258 
266  virtual QString styleURI( );
267 
276  virtual QString loadDefaultStyle( bool & theResultFlag );
277 
291  virtual QString loadNamedStyle( const QString &theURI, bool &theResultFlag );
292 
293  virtual bool loadNamedStyleFromDb( const QString &db, const QString &theURI, QString &qml );
294 
295  //TODO edit infos
302  virtual void exportNamedStyle( QDomDocument &doc, QString &errorMsg );
303 
304 
311  virtual void exportSldStyle( QDomDocument &doc, QString &errorMsg );
312 
321  virtual QString saveDefaultStyle( bool & theResultFlag );
322 
336  virtual QString saveNamedStyle( const QString &theURI, bool &theResultFlag );
337 
338  virtual QString saveSldStyle( const QString &theURI, bool &theResultFlag );
339  virtual QString loadSldStyle( const QString &theURI, bool &theResultFlag );
340 
341  virtual bool readSld( const QDomNode &node, QString &errorMessage )
342  { Q_UNUSED( node ); errorMessage = QString( "Layer type %1 not supported" ).arg( type() ); return false; }
343 
344 
350  virtual bool readSymbology( const QDomNode& node, QString& errorMessage ) = 0;
351 
358  virtual bool writeSymbology( QDomNode &node, QDomDocument& doc, QString& errorMessage ) const = 0;
359 
361  QUndoStack *undoStack();
362 
365  QImage *cacheImage() { return mpCacheImage; }
368  void setCacheImage( QImage * thepImage );
369 
374  virtual void onCacheImageDelete() {}
375 
376  public slots:
377 
379  virtual void invalidTransformInput();
380 
382  void setMinimumScale( float theMinScale );
383  float minimumScale() const;
384 
386  void setMaximumScale( float theMaxScale );
387  float maximumScale() const;
388 
390  void toggleScaleBasedVisibility( bool theVisibilityFlag );
391  bool hasScaleBasedVisibility() const;
392 
395  void clearCacheImage();
396 
398  virtual QString metadata();
399 
401  virtual QDateTime timestamp() const { return QDateTime() ; }
402 
403  signals:
404 
406  void drawingProgress( int theProgress, int theTotalSteps );
407 
409  void statusChanged( QString theStatus );
410 
412  void layerNameChanged();
413 
417  void layerCrsChanged();
418 
422  void repaintRequested();
423 
426  void screenUpdateRequested();
427 
429  void recalculateExtents();
430 
433  void dataChanged();
434 
436  void blendModeChanged( const QPainter::CompositionMode &blendMode );
437 
438  protected:
440  virtual void setExtent( const QgsRectangle &rect );
441 
444  void setValid( bool valid );
445 
449  virtual bool readXml( const QDomNode& layer_node );
450 
454  virtual bool writeXml( QDomNode & layer_node, QDomDocument & document );
455 
456 
460  void readCustomProperties( const QDomNode& layerNode, const QString& keyStartsWith = "" );
461 
463  void writeCustomProperties( QDomNode & layerNode, QDomDocument & doc ) const;
464 
466  void connectNotify( const char * signal );
467 
469  void appendError( const QgsErrorMessage & theMessage ) { mError.append( theMessage );}
471  void setError( const QgsError & theError ) { mError = theError;}
472 
475 
477  bool mValid;
478 
480  QString mDataSource;
481 
483  QString mLayerName;
484 
488  QString mLayerOrigName;
489 
490  QString mTitle;
491 
493  QString mAbstract;
494  QString mKeywordList;
495 
497  QString mDataUrl;
498  QString mDataUrlFormat;
499 
501  QString mAttribution;
503 
505  QString mMetadataUrl;
508 
511 
512  private:
516 
518  QgsMapLayer( QgsMapLayer const & );
519 
521  QgsMapLayer & operator=( QgsMapLayer const & );
522 
524  QString mID;
525 
528 
530  QPainter::CompositionMode mBlendMode;
531 
533  QString mTag;
534 
536  float mMinScale;
538  float mMaxScale;
541 
543  QUndoStack mUndoStack;
544 
545  QMap<QString, QVariant> mCustomProperties;
546 
549  QImage * mpCacheImage;
550 
551 };
552 
553 #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:45
QString mID
Unique ID of this layer - used to refer to this layer in map layer registry.
Definition: qgsmaplayer.h:524
QString mAttributionUrl
Definition: qgsmaplayer.h:502
QString mKeywordList
Definition: qgsmaplayer.h:494
QString mDataUrlFormat
Definition: qgsmaplayer.h:498
const QString & originalName() const
Get the original name of the layer.
Definition: qgsmaplayer.h:91
virtual void reload()
Synchronises with changes in the datasource.
Definition: qgsmaplayer.h:129
bool mScaleBasedVisibility
A flag that tells us whether to use the above vars to restrict layer visibility.
Definition: qgsmaplayer.h:540
QImage * cacheImage()
Get the QImage used for caching render operations.
Definition: qgsmaplayer.h:365
const QString & attribution() const
Definition: qgsmaplayer.h:110
void setMetadataUrlType(const QString &metaUrlType)
Definition: qgsmaplayer.h:117
QUndoStack mUndoStack
Collection of undoable operations for this layer.
Definition: qgsmaplayer.h:543
QString mLayerName
Name of the layer - used for display.
Definition: qgsmaplayer.h:483
QgsError mError
Error.
Definition: qgsmaplayer.h:510
QgsRectangle mExtent
Extent of the layer.
Definition: qgsmaplayer.h:474
QPainter::CompositionMode mBlendMode
Blend mode for the layer.
Definition: qgsmaplayer.h:530
QString mMetadataUrl
MetadataUrl of the layer.
Definition: qgsmaplayer.h:505
void setError(const QgsError &theError)
Set error message.
Definition: qgsmaplayer.h:471
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
const QString & metadataUrlType() const
Definition: qgsmaplayer.h:118
LayerType
Layers enum defining the types of layers that can be added to a map.
Definition: qgsmaplayer.h:51
QString mDataUrl
DataUrl of the layer.
Definition: qgsmaplayer.h:497
const QString & metadataUrl() const
Definition: qgsmaplayer.h:116
QgsErrorMessage represents single error message.
Definition: qgserror.h:29
bool mValid
Indicates if the layer is valid and can be drawn.
Definition: qgsmaplayer.h:477
void setDataUrlFormat(const QString &dataUrlFormat)
Definition: qgsmaplayer.h:105
virtual QgsError error() const
Get current status error.
Definition: qgsmaplayer.h:245
QString mTitle
Definition: qgsmaplayer.h:490
virtual bool readSld(const QDomNode &node, QString &errorMessage)
Definition: qgsmaplayer.h:341
QString mMetadataUrlFormat
Definition: qgsmaplayer.h:507
void setMetadataUrlFormat(const QString &metaUrlFormat)
Definition: qgsmaplayer.h:119
QString mAttribution
Attribution of the layer.
Definition: qgsmaplayer.h:501
QString mAbstract
Description of the layer.
Definition: qgsmaplayer.h:493
QMap< QString, QVariant > mCustomProperties
Definition: qgsmaplayer.h:545
Contains information about the context of a rendering operation.
QString mDataSource
data source description string, varies by layer type
Definition: qgsmaplayer.h:480
virtual void onCacheImageDelete()
Is called when the cache image is being deleted.
Definition: qgsmaplayer.h:374
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:538
Class for storing a coordinate reference system (CRS)
void setAttributionUrl(const QString &attribUrl)
Definition: qgsmaplayer.h:111
void appendError(const QgsErrorMessage &theMessage)
Add error message.
Definition: qgsmaplayer.h:469
QgsMapLayer::LayerType mLayerType
Type of the layer (eg.
Definition: qgsmaplayer.h:527
QgsCoordinateReferenceSystem * mCRS
layer's spatial reference system.
Definition: qgsmaplayer.h:515
virtual QDateTime timestamp() const
Time stamp of data source in the moment when data/metadata were loaded by provider.
Definition: qgsmaplayer.h:401
void setAttribution(const QString &attrib)
Definition: qgsmaplayer.h:109
const QString & attributionUrl() const
Definition: qgsmaplayer.h:112
const QString & metadataUrlFormat() const
Definition: qgsmaplayer.h:120
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:488
QString mMetadataUrlType
Definition: qgsmaplayer.h:506
QString mTag
Tag for embedding additional information.
Definition: qgsmaplayer.h:533
const QString & keywordList() const
Definition: qgsmaplayer.h:100
float mMinScale
Minimum scale denominator at which this layer should be displayed.
Definition: qgsmaplayer.h:536
void setAbstract(const QString &abstract)
Definition: qgsmaplayer.h:96
const QString & dataUrlFormat() const
Definition: qgsmaplayer.h:106
QImage * mpCacheImage
QImage for caching of rendering operations.
Definition: qgsmaplayer.h:549