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"
33 
34 class QgsRenderContext;
37 
38 class QDomDocument;
39 class QKeyEvent;
40 class QPainter;
41 
46 class CORE_EXPORT QgsMapLayer : public QObject
47 {
48  Q_OBJECT
49 
50  public:
52  enum LayerType
53  {
56  PluginLayer // added in 1.5
57  };
58 
64  QgsMapLayer( QgsMapLayer::LayerType type = VectorLayer, QString lyrname = QString::null, QString source = QString::null );
65 
67  virtual ~QgsMapLayer();
68 
72  QgsMapLayer::LayerType type() const;
73 
77  QString id() const;
78 
82  void setLayerName( const QString & name );
83 
87  const QString & name() const;
88 
92  const QString & originalName() const { return mLayerOrigName; }
93 
94  void setTitle( const QString& title ) { mTitle = title; }
95  const QString& title() const { return mTitle; }
96 
97  void setAbstract( const QString& abstract ) { mAbstract = abstract; }
98  const QString& abstract() const { return mAbstract; }
99 
100  void setKeywordList( const QString& keywords ) { mKeywordList = keywords; }
101  const QString& keywordList() const { return mKeywordList; }
102 
103  /* Layer dataUrl information */
104  void setDataUrl( const QString& dataUrl ) { mDataUrl = dataUrl; }
105  const QString& dataUrl() const { return mDataUrl; }
106  void setDataUrlFormat( const QString& dataUrlFormat ) { mDataUrlFormat = dataUrlFormat; }
107  const QString& dataUrlFormat() const { return mDataUrlFormat; }
108 
109  /* Layer attribution information */
110  void setAttribution( const QString& attrib ) { mAttribution = attrib; }
111  const QString& attribution() const { return mAttribution; }
112  void setAttributionUrl( const QString& attribUrl ) { mAttributionUrl = attribUrl; }
113  const QString& attributionUrl() const { return mAttributionUrl; }
114 
115  /* Layer metadataUrl information */
116  void setMetadataUrl( const QString& metaUrl ) { mMetadataUrl = metaUrl; }
117  const QString& metadataUrl() const { return mMetadataUrl; }
118  void setMetadataUrlType( const QString& metaUrlType ) { mMetadataUrlType = metaUrlType; }
119  const QString& metadataUrlType() const { return mMetadataUrlType; }
120  void setMetadataUrlFormat( const QString& metaUrlFormat ) { mMetadataUrlFormat = metaUrlFormat; }
121  const QString& metadataUrlFormat() const { return mMetadataUrlFormat; }
122 
123  /* Set the blending mode used for rendering a layer */
124  void setBlendMode( const QPainter::CompositionMode &blendMode );
125  /* Returns the current blending mode for a layer */
126  QPainter::CompositionMode blendMode() const;
127 
130  virtual void reload() {}
131 
135  virtual QgsMapLayerRenderer* createMapRenderer( QgsRenderContext& rendererContext ) { Q_UNUSED( rendererContext ); return 0; }
136 
143  virtual bool draw( QgsRenderContext& rendererContext );
144 
148  virtual void drawLabels( QgsRenderContext& rendererContext );
149 
151  virtual QgsRectangle extent();
152 
157  bool isValid();
158 
163  QString publicSource() const;
164 
166  const QString &source() const;
167 
172  virtual QStringList subLayers() const;
173 
178  virtual void setLayerOrder( const QStringList &layers );
179 
181  virtual void setSubLayerVisibility( QString name, bool vis );
182 
184  virtual bool isEditable() const;
185 
200  bool readLayerXML( const QDomElement& layerElement );
201 
202 
218  bool writeLayerXML( QDomElement& layerElement, QDomDocument& document );
219 
225  QDomDocument asLayerDefinition( );
226 
229  static QgsMapLayer* fromLayerDefinition( QDomDocument& document );
230  static QgsMapLayer* fromLayerDefinitionFile( const QString qlrfile );
231 
234  void setCustomProperty( const QString& key, const QVariant& value );
237  QVariant customProperty( const QString& value, const QVariant& defaultValue = QVariant() ) const;
240  void removeCustomProperty( const QString& key );
241 
242 
244  Q_DECL_DEPRECATED virtual QString lastErrorTitle();
245 
247  Q_DECL_DEPRECATED virtual QString lastError();
248 
253  virtual QgsError error() const { return mError; }
254 
258  const QgsCoordinateReferenceSystem& crs() const;
259 
262  void setCrs( const QgsCoordinateReferenceSystem& srs, bool emitSignal = true );
263 
265  static QString capitaliseLayerName( const QString& name );
266 
274  virtual QString styleURI( );
275 
284  virtual QString loadDefaultStyle( bool & theResultFlag );
285 
299  virtual QString loadNamedStyle( const QString &theURI, bool &theResultFlag );
300 
301  virtual bool loadNamedStyleFromDb( const QString &db, const QString &theURI, QString &qml );
302 
303  //TODO edit infos
310  virtual void exportNamedStyle( QDomDocument &doc, QString &errorMsg );
311 
312 
319  virtual void exportSldStyle( QDomDocument &doc, QString &errorMsg );
320 
329  virtual QString saveDefaultStyle( bool & theResultFlag );
330 
344  virtual QString saveNamedStyle( const QString &theURI, bool &theResultFlag );
345 
346  virtual QString saveSldStyle( const QString &theURI, bool &theResultFlag );
347  virtual QString loadSldStyle( const QString &theURI, bool &theResultFlag );
348 
349  virtual bool readSld( const QDomNode &node, QString &errorMessage )
350  { Q_UNUSED( node ); errorMessage = QString( "Layer type %1 not supported" ).arg( type() ); return false; }
351 
352 
358  virtual bool readSymbology( const QDomNode& node, QString& errorMessage ) = 0;
359 
366  virtual bool writeSymbology( QDomNode &node, QDomDocument& doc, QString& errorMessage ) const = 0;
367 
369  QUndoStack *undoStack();
370 
372  Q_DECL_DEPRECATED QImage *cacheImage() { return 0; }
374  Q_DECL_DEPRECATED void setCacheImage( QImage * );
376  Q_DECL_DEPRECATED virtual void onCacheImageDelete() {}
377 
378  public slots:
379 
381  virtual void invalidTransformInput();
382 
384  void setMinimumScale( float theMinScale );
385  float minimumScale() const;
386 
388  void setMaximumScale( float theMaxScale );
389  float maximumScale() const;
390 
392  void toggleScaleBasedVisibility( bool theVisibilityFlag );
393  bool hasScaleBasedVisibility() const;
394 
397  Q_DECL_DEPRECATED void clearCacheImage();
398 
400  virtual QString metadata();
401 
403  virtual QDateTime timestamp() const { return QDateTime() ; }
404 
405  signals:
406 
408  void drawingProgress( int theProgress, int theTotalSteps );
409 
411  void statusChanged( QString theStatus );
412 
414  void layerNameChanged();
415 
419  void layerCrsChanged();
420 
424  void repaintRequested();
425 
427  void screenUpdateRequested();
428 
430  void recalculateExtents();
431 
434  void dataChanged();
435 
437  void blendModeChanged( const QPainter::CompositionMode &blendMode );
438 
439  protected:
441  virtual void setExtent( const QgsRectangle &rect );
442 
445  void setValid( bool valid );
446 
450  virtual bool readXml( const QDomNode& layer_node );
451 
455  virtual bool writeXml( QDomNode & layer_node, QDomDocument & document );
456 
457 
461  void readCustomProperties( const QDomNode& layerNode, const QString& keyStartsWith = "" );
462 
464  void writeCustomProperties( QDomNode & layerNode, QDomDocument & doc ) const;
465 
467  void connectNotify( const char * signal );
468 
470  void appendError( const QgsErrorMessage & theMessage ) { mError.append( theMessage );}
472  void setError( const QgsError & theError ) { mError = theError;}
473 
476 
478  bool mValid;
479 
481  QString mDataSource;
482 
484  QString mLayerName;
485 
489  QString mLayerOrigName;
490 
491  QString mTitle;
492 
494  QString mAbstract;
495  QString mKeywordList;
496 
498  QString mDataUrl;
499  QString mDataUrlFormat;
500 
502  QString mAttribution;
504 
506  QString mMetadataUrl;
509 
512 
513  private:
517 
519  QgsMapLayer( QgsMapLayer const & );
520 
522  QgsMapLayer & operator=( QgsMapLayer const & );
523 
525  QString mID;
526 
529 
531  QPainter::CompositionMode mBlendMode;
532 
534  QString mTag;
535 
537  float mMinScale;
539  float mMaxScale;
542 
544  QUndoStack mUndoStack;
545 
546  QMap<QString, QVariant> mCustomProperties;
547 
548 };
549 
550 #endif
void setMetadataUrl(const QString &metaUrl)
Definition: qgsmaplayer.h:116
A rectangle specified with double values.
Definition: qgsrectangle.h:35
Base class for all map layer types.
Definition: qgsmaplayer.h:46
QString mID
Unique ID of this layer - used to refer to this layer in map layer registry.
Definition: qgsmaplayer.h:525
QString mAttributionUrl
Definition: qgsmaplayer.h:503
QString mKeywordList
Definition: qgsmaplayer.h:495
QString mDataUrlFormat
Definition: qgsmaplayer.h:499
const QString & originalName() const
Get the original name of the layer.
Definition: qgsmaplayer.h:92
virtual void reload()
Synchronises with changes in the datasource.
Definition: qgsmaplayer.h:130
bool mScaleBasedVisibility
A flag that tells us whether to use the above vars to restrict layer visibility.
Definition: qgsmaplayer.h:541
const QString & attribution() const
Definition: qgsmaplayer.h:111
void setMetadataUrlType(const QString &metaUrlType)
Definition: qgsmaplayer.h:118
virtual QgsMapLayerRenderer * createMapRenderer(QgsRenderContext &rendererContext)
Return new instance of QgsMapLayerRenderer that will be used for rendering of given context...
Definition: qgsmaplayer.h:135
QUndoStack mUndoStack
Collection of undoable operations for this layer.
Definition: qgsmaplayer.h:544
QString mLayerName
Name of the layer - used for display.
Definition: qgsmaplayer.h:484
QgsError mError
Error.
Definition: qgsmaplayer.h:511
QgsRectangle mExtent
Extent of the layer.
Definition: qgsmaplayer.h:475
QPainter::CompositionMode mBlendMode
Blend mode for the layer.
Definition: qgsmaplayer.h:531
QString mMetadataUrl
MetadataUrl of the layer.
Definition: qgsmaplayer.h:506
void setError(const QgsError &theError)
Set error message.
Definition: qgsmaplayer.h:472
void setKeywordList(const QString &keywords)
Definition: qgsmaplayer.h:100
const QString & dataUrl() const
Definition: qgsmaplayer.h:105
void setTitle(const QString &title)
Definition: qgsmaplayer.h:94
Q_DECL_DEPRECATED QImage * cacheImage()
Definition: qgsmaplayer.h:372
const QString & metadataUrlType() const
Definition: qgsmaplayer.h:119
LayerType
Layers enum defining the types of layers that can be added to a map.
Definition: qgsmaplayer.h:52
QString mDataUrl
DataUrl of the layer.
Definition: qgsmaplayer.h:498
const QString & metadataUrl() const
Definition: qgsmaplayer.h:117
QgsErrorMessage represents single error message.
Definition: qgserror.h:29
bool mValid
Indicates if the layer is valid and can be drawn.
Definition: qgsmaplayer.h:478
void setDataUrlFormat(const QString &dataUrlFormat)
Definition: qgsmaplayer.h:106
virtual QgsError error() const
Get current status error.
Definition: qgsmaplayer.h:253
QString mTitle
Definition: qgsmaplayer.h:491
virtual bool readSld(const QDomNode &node, QString &errorMessage)
Definition: qgsmaplayer.h:349
QString mMetadataUrlFormat
Definition: qgsmaplayer.h:508
void setMetadataUrlFormat(const QString &metaUrlFormat)
Definition: qgsmaplayer.h:120
QString mAttribution
Attribution of the layer.
Definition: qgsmaplayer.h:502
QString mAbstract
Description of the layer.
Definition: qgsmaplayer.h:494
virtual Q_DECL_DEPRECATED void onCacheImageDelete()
Definition: qgsmaplayer.h:376
QMap< QString, QVariant > mCustomProperties
Definition: qgsmaplayer.h:546
Contains information about the context of a rendering operation.
QString mDataSource
data source description string, varies by layer type
Definition: qgsmaplayer.h:481
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:539
Class for storing a coordinate reference system (CRS)
void setAttributionUrl(const QString &attribUrl)
Definition: qgsmaplayer.h:112
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:470
QgsMapLayer::LayerType mLayerType
Type of the layer (eg.
Definition: qgsmaplayer.h:528
QgsCoordinateReferenceSystem * mCRS
layer's spatial reference system.
Definition: qgsmaplayer.h:516
virtual QDateTime timestamp() const
Time stamp of data source in the moment when data/metadata were loaded by provider.
Definition: qgsmaplayer.h:403
void setAttribution(const QString &attrib)
Definition: qgsmaplayer.h:110
const QString & attributionUrl() const
Definition: qgsmaplayer.h:113
const QString & metadataUrlFormat() const
Definition: qgsmaplayer.h:121
const QString & title() const
Definition: qgsmaplayer.h:95
void setDataUrl(const QString &dataUrl)
Definition: qgsmaplayer.h:104
QString mLayerOrigName
Original name of the layer.
Definition: qgsmaplayer.h:489
QString mMetadataUrlType
Definition: qgsmaplayer.h:507
QString mTag
Tag for embedding additional information.
Definition: qgsmaplayer.h:534
const QString & keywordList() const
Definition: qgsmaplayer.h:101
float mMinScale
Minimum scale denominator at which this layer should be displayed.
Definition: qgsmaplayer.h:537
void setAbstract(const QString &abstract)
Definition: qgsmaplayer.h:97
const QString & dataUrlFormat() const
Definition: qgsmaplayer.h:107