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 // 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 
221  bool writeLayerXML( QDomElement& layerElement, QDomDocument& document, QString relativeBasePath = QString::null );
222 
228  static QDomDocument asLayerDefinition( QList<QgsMapLayer*> layers, QString relativeBasePath = QString::null );
229 
232  static QList<QgsMapLayer*> fromLayerDefinition( QDomDocument& document );
233  static QList<QgsMapLayer*> fromLayerDefinitionFile( const QString qlrfile );
234 
237  void setCustomProperty( const QString& key, const QVariant& value );
240  QVariant customProperty( const QString& value, const QVariant& defaultValue = QVariant() ) const;
243  void removeCustomProperty( const QString& key );
244 
245 
247  Q_DECL_DEPRECATED virtual QString lastErrorTitle();
248 
250  Q_DECL_DEPRECATED virtual QString lastError();
251 
256  virtual QgsError error() const { return mError; }
257 
261  const QgsCoordinateReferenceSystem& crs() const;
262 
265  void setCrs( const QgsCoordinateReferenceSystem& srs, bool emitSignal = true );
266 
268  static QString capitaliseLayerName( const QString& name );
269 
277  virtual QString styleURI();
278 
287  virtual QString loadDefaultStyle( bool & theResultFlag );
288 
302  virtual QString loadNamedStyle( const QString &theURI, bool &theResultFlag );
303 
304  virtual bool loadNamedStyleFromDb( const QString &db, const QString &theURI, QString &qml );
305 
306  //TODO edit infos
313  virtual void exportNamedStyle( QDomDocument &doc, QString &errorMsg );
314 
315 
322  virtual void exportSldStyle( QDomDocument &doc, QString &errorMsg );
323 
332  virtual QString saveDefaultStyle( bool & theResultFlag );
333 
347  virtual QString saveNamedStyle( const QString &theURI, bool &theResultFlag );
348 
349  virtual QString saveSldStyle( const QString &theURI, bool &theResultFlag );
350  virtual QString loadSldStyle( const QString &theURI, bool &theResultFlag );
351 
352  virtual bool readSld( const QDomNode &node, QString &errorMessage )
353  { Q_UNUSED( node ); errorMessage = QString( "Layer type %1 not supported" ).arg( type() ); return false; }
354 
355 
361  virtual bool readSymbology( const QDomNode& node, QString& errorMessage ) = 0;
362 
369  virtual bool writeSymbology( QDomNode &node, QDomDocument& doc, QString& errorMessage ) const = 0;
370 
372  QUndoStack *undoStack();
373 
374  /* Layer legendUrl information */
375  void setLegendUrl( const QString& legendUrl ) { mLegendUrl = legendUrl; }
376  const QString& legendUrl() const { return mLegendUrl; }
377  void setLegendUrlFormat( const QString& legendUrlFormat ) { mLegendUrlFormat = legendUrlFormat; }
378  const QString& legendUrlFormat() const { return mLegendUrlFormat; }
379 
381  Q_DECL_DEPRECATED QImage *cacheImage() { return 0; }
383  Q_DECL_DEPRECATED void setCacheImage( QImage * );
385  Q_DECL_DEPRECATED virtual void onCacheImageDelete() {}
386 
392  void setLegend( QgsMapLayerLegend* legend );
397  QgsMapLayerLegend* legend() const;
398 
399  public slots:
400 
402  virtual void invalidTransformInput();
403 
405  void setMinimumScale( float theMinScale );
406  float minimumScale() const;
407 
409  void setMaximumScale( float theMaxScale );
410  float maximumScale() const;
411 
413  void toggleScaleBasedVisibility( bool theVisibilityFlag );
414  bool hasScaleBasedVisibility() const;
415 
418  Q_DECL_DEPRECATED void clearCacheImage();
419 
426  void triggerRepaint();
427 
429  virtual QString metadata();
430 
432  virtual QDateTime timestamp() const { return QDateTime() ; }
433 
434  signals:
435 
437  void drawingProgress( int theProgress, int theTotalSteps );
438 
440  void statusChanged( QString theStatus );
441 
443  void layerNameChanged();
444 
448  void layerCrsChanged();
449 
453  void repaintRequested();
454 
456  void screenUpdateRequested();
457 
459  void recalculateExtents();
460 
463  void dataChanged();
464 
466  void blendModeChanged( const QPainter::CompositionMode &blendMode );
467 
469  void rendererChanged();
470 
475  void legendChanged();
476 
477  protected:
479  virtual void setExtent( const QgsRectangle &rect );
480 
483  void setValid( bool valid );
484 
488  virtual bool readXml( const QDomNode& layer_node );
489 
493  virtual bool writeXml( QDomNode & layer_node, QDomDocument & document );
494 
495 
499  void readCustomProperties( const QDomNode& layerNode, const QString& keyStartsWith = "" );
500 
502  void writeCustomProperties( QDomNode & layerNode, QDomDocument & doc ) const;
503 
505  void connectNotify( const char * signal );
506 
508  void appendError( const QgsErrorMessage & theMessage ) { mError.append( theMessage );}
510  void setError( const QgsError & theError ) { mError = theError;}
511 
514 
516  bool mValid;
517 
519  QString mDataSource;
520 
522  QString mLayerName;
523 
527  QString mLayerOrigName;
528 
529  QString mTitle;
530 
532  QString mAbstract;
533  QString mKeywordList;
534 
536  QString mDataUrl;
537  QString mDataUrlFormat;
538 
540  QString mAttribution;
542 
544  QString mMetadataUrl;
547 
549  QString mLegendUrl;
551 
554 
555  private:
559 
561  QgsMapLayer( QgsMapLayer const & );
562 
564  QgsMapLayer & operator=( QgsMapLayer const & );
565 
567  QString mID;
568 
570  QgsMapLayer::LayerType mLayerType;
571 
573  QPainter::CompositionMode mBlendMode;
574 
576  QString mTag;
577 
579  float mMinScale;
581  float mMaxScale;
583  bool mScaleBasedVisibility;
584 
586  QUndoStack mUndoStack;
587 
589  QgsObjectCustomProperties mCustomProperties;
590 
592  QgsMapLayerLegend* mLegend;
593 };
594 
595 #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 mAttributionUrl
Definition: qgsmaplayer.h:541
QString mKeywordList
Definition: qgsmaplayer.h:533
LayerType
Layers enum defining the types of layers that can be added to a map.
Definition: qgsmaplayer.h:54
QString mDataUrlFormat
Definition: qgsmaplayer.h:537
const QString & originalName() const
Get the original name of the layer.
Definition: qgsmaplayer.h:94
QString mLegendUrlFormat
Definition: qgsmaplayer.h:550
virtual void reload()
Synchronises with changes in the datasource.
Definition: qgsmaplayer.h:132
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
QString mLayerName
Name of the layer - used for display.
Definition: qgsmaplayer.h:522
Definition: qgsmaplayer.h:57
QgsError mError
Error.
Definition: qgsmaplayer.h:553
const QString & legendUrl() const
Definition: qgsmaplayer.h:376
QgsRectangle mExtent
Extent of the layer.
Definition: qgsmaplayer.h:513
QString mMetadataUrl
MetadataUrl of the layer.
Definition: qgsmaplayer.h:544
void setLegendUrlFormat(const QString &legendUrlFormat)
Definition: qgsmaplayer.h:377
void setError(const QgsError &theError)
Set error message.
Definition: qgsmaplayer.h:510
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:381
const QString & metadataUrlType() const
Definition: qgsmaplayer.h:121
QString mDataUrl
DataUrl of the layer.
Definition: qgsmaplayer.h:536
const QString & metadataUrl() const
Definition: qgsmaplayer.h:119
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:516
void setDataUrlFormat(const QString &dataUrlFormat)
Definition: qgsmaplayer.h:108
virtual QgsError error() const
Get current status error.
Definition: qgsmaplayer.h:256
QString mTitle
Definition: qgsmaplayer.h:529
virtual bool readSld(const QDomNode &node, QString &errorMessage)
Definition: qgsmaplayer.h:352
QString mMetadataUrlFormat
Definition: qgsmaplayer.h:546
void setLegendUrl(const QString &legendUrl)
Definition: qgsmaplayer.h:375
void setMetadataUrlFormat(const QString &metaUrlFormat)
Definition: qgsmaplayer.h:122
QString mAttribution
Attribution of the layer.
Definition: qgsmaplayer.h:540
QString mAbstract
Description of the layer.
Definition: qgsmaplayer.h:532
virtual Q_DECL_DEPRECATED void onCacheImageDelete()
Definition: qgsmaplayer.h:385
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:519
QgsError is container for error messages (report).
Definition: qgserror.h:77
Definition: qgsmaplayer.h:56
QString mLegendUrl
WMS legend.
Definition: qgsmaplayer.h:549
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:114
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:508
virtual QDateTime timestamp() const
Time stamp of data source in the moment when data/metadata were loaded by provider.
Definition: qgsmaplayer.h:432
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:378
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:527
QString mMetadataUrlType
Definition: qgsmaplayer.h:545
const QString & keywordList() const
Definition: qgsmaplayer.h:103
void setAbstract(const QString &abstract)
Definition: qgsmaplayer.h:99
const QString & dataUrlFormat() const
Definition: qgsmaplayer.h:109