QGIS API Documentation  2.11.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 <QDomNode>
23 #include <QImage>
24 #include <QObject>
25 #include <QPainter>
26 #include <QUndoStack>
27 #include <QVariant>
28 
29 #include "qgis.h"
30 #include "qgserror.h"
31 #include "qgsmaprenderer.h"
33 #include "qgsrectangle.h"
34 
35 class QgsRenderContext;
37 class QgsMapLayerLegend;
40 
41 class QDomDocument;
42 class QKeyEvent;
43 class QPainter;
44 
49 class CORE_EXPORT QgsMapLayer : public QObject
50 {
51  Q_OBJECT
52 
53  public:
55  enum LayerType
56  {
59  PluginLayer
60  };
61 
67  QgsMapLayer( QgsMapLayer::LayerType type = VectorLayer, QString lyrname = QString::null, QString source = QString::null );
68 
70  virtual ~QgsMapLayer();
71 
75  QgsMapLayer::LayerType type() const;
76 
78  QString id() const;
79 
83  void setLayerName( const QString & name );
84 
88  const QString & name() const;
89 
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 
123  void setBlendMode( const QPainter::CompositionMode &blendMode );
125  QPainter::CompositionMode blendMode() const;
126 
129  virtual void reload() {}
130 
134  virtual QgsMapLayerRenderer* createMapRenderer( QgsRenderContext& rendererContext ) { Q_UNUSED( rendererContext ); return 0; }
135 
142  virtual bool draw( QgsRenderContext& rendererContext );
143 
147  virtual void drawLabels( QgsRenderContext& rendererContext );
148 
150  virtual QgsRectangle extent();
151 
156  bool isValid();
157 
162  QString publicSource() const;
163 
165  const QString &source() const;
166 
171  virtual QStringList subLayers() const;
172 
177  virtual void setLayerOrder( const QStringList &layers );
178 
180  virtual void setSubLayerVisibility( QString name, bool vis );
181 
183  virtual bool isEditable() const;
184 
199  bool readLayerXML( const QDomElement& layerElement );
200 
201 
218  bool writeLayerXML( QDomElement& layerElement, QDomDocument& document, QString relativeBasePath = QString::null );
219 
225  static QDomDocument asLayerDefinition( QList<QgsMapLayer*> layers, QString relativeBasePath = QString::null );
226 
229  static QList<QgsMapLayer*> fromLayerDefinition( QDomDocument& document );
230  static QList<QgsMapLayer*> fromLayerDefinitionFile( const QString &qlrfile );
231 
233  void setCustomProperty( const QString& key, const QVariant& value );
235  QVariant customProperty( const QString& value, const QVariant& defaultValue = QVariant() ) const;
237  void removeCustomProperty( const QString& key );
238 
239 
241  Q_DECL_DEPRECATED virtual QString lastErrorTitle();
242 
244  Q_DECL_DEPRECATED virtual QString lastError();
245 
250  virtual QgsError error() const { return mError; }
251 
255  const QgsCoordinateReferenceSystem& crs() const;
256 
258  void setCrs( const QgsCoordinateReferenceSystem& srs, bool emitSignal = true );
259 
261  static QString capitaliseLayerName( const QString& name );
262 
269  virtual QString styleURI();
270 
279  virtual QString loadDefaultStyle( bool & theResultFlag );
280 
294  virtual QString loadNamedStyle( const QString &theURI, bool &theResultFlag );
295 
296  virtual bool loadNamedStyleFromDb( const QString &db, const QString &theURI, QString &qml );
297 
306  virtual bool importNamedStyle( QDomDocument& doc, QString &errorMsg );
307 
314  virtual void exportNamedStyle( QDomDocument &doc, QString &errorMsg );
315 
316 
323  virtual void exportSldStyle( QDomDocument &doc, QString &errorMsg );
324 
333  virtual QString saveDefaultStyle( bool & theResultFlag );
334 
348  virtual QString saveNamedStyle( const QString &theURI, bool &theResultFlag );
349 
350  virtual QString saveSldStyle( const QString &theURI, bool &theResultFlag );
351  virtual QString loadSldStyle( const QString &theURI, bool &theResultFlag );
352 
353  virtual bool readSld( const QDomNode &node, QString &errorMessage )
354  { Q_UNUSED( node ); errorMessage = QString( "Layer type %1 not supported" ).arg( type() ); return false; }
355 
356 
357 
363  virtual bool readSymbology( const QDomNode& node, QString& errorMessage ) = 0;
364 
371  virtual bool writeSymbology( QDomNode &node, QDomDocument& doc, QString& errorMessage ) const = 0;
372 
374  QUndoStack *undoStack();
375 
376  /* Layer legendUrl information */
377  void setLegendUrl( const QString& legendUrl ) { mLegendUrl = legendUrl; }
378  const QString& legendUrl() const { return mLegendUrl; }
379  void setLegendUrlFormat( const QString& legendUrlFormat ) { mLegendUrlFormat = legendUrlFormat; }
380  const QString& legendUrlFormat() const { return mLegendUrlFormat; }
381 
383  Q_DECL_DEPRECATED QImage *cacheImage() { return 0; }
385  Q_DECL_DEPRECATED void setCacheImage( QImage * );
387  Q_DECL_DEPRECATED virtual void onCacheImageDelete() {}
388 
394  void setLegend( QgsMapLayerLegend* legend );
399  QgsMapLayerLegend* legend() const;
400 
405  QgsMapLayerStyleManager* styleManager() const;
406 
414  float minimumScale() const;
415 
423  float maximumScale() const;
424 
431  bool hasScaleBasedVisibility() const;
432 
433  public slots:
434 
436  virtual void invalidTransformInput();
437 
445  void setMinimumScale( const float theMinScale );
446 
454  void setMaximumScale( const float theMaxScale );
455 
462  void setScaleBasedVisibility( const bool enabled );
463 
467  Q_DECL_DEPRECATED void toggleScaleBasedVisibility( bool theVisibilityFlag );
468 
471  Q_DECL_DEPRECATED void clearCacheImage();
472 
479  void triggerRepaint();
480 
482  virtual QString metadata();
483 
485  virtual QDateTime timestamp() const { return QDateTime() ; }
486 
487  signals:
488 
490  void drawingProgress( int theProgress, int theTotalSteps );
491 
493  void statusChanged( QString theStatus );
494 
496  void layerNameChanged();
497 
499  void layerCrsChanged();
500 
504  void repaintRequested();
505 
507  void screenUpdateRequested();
508 
510  void recalculateExtents();
511 
513  void dataChanged();
514 
516  void blendModeChanged( const QPainter::CompositionMode &blendMode );
517 
519  void rendererChanged();
520 
525  void legendChanged();
526 
527  protected:
529  virtual void setExtent( const QgsRectangle &rect );
530 
532  void setValid( bool valid );
533 
537  virtual bool readXml( const QDomNode& layer_node );
538 
542  virtual bool writeXml( QDomNode & layer_node, QDomDocument & document );
543 
544 
548  void readCustomProperties( const QDomNode& layerNode, const QString& keyStartsWith = "" );
549 
551  void writeCustomProperties( QDomNode & layerNode, QDomDocument & doc ) const;
552 
554  void readStyleManager( const QDomNode& layerNode );
556  void writeStyleManager( QDomNode& layerNode, QDomDocument& doc ) const;
557 
558 #if 0
559 
560  void connectNotify( const char * signal ) override;
561 #endif
562 
564  void appendError( const QgsErrorMessage & theMessage ) { mError.append( theMessage );}
566  void setError( const QgsError & theError ) { mError = theError;}
567 
570 
572  bool mValid;
573 
576 
579 
583 
585 
589 
593 
597 
602 
606 
609 
610  private:
614 
616  QgsMapLayer( QgsMapLayer const & );
617 
619  QgsMapLayer & operator=( QgsMapLayer const & );
620 
622  QString mID;
623 
625  QgsMapLayer::LayerType mLayerType;
626 
628  QPainter::CompositionMode mBlendMode;
629 
631  QString mTag;
632 
634  float mMinScale;
636  float mMaxScale;
638  bool mScaleBasedVisibility;
639 
641  QUndoStack mUndoStack;
642 
644  QgsObjectCustomProperties mCustomProperties;
645 
647  QgsMapLayerLegend* mLegend;
648 
650  QgsMapLayerStyleManager* mStyleManager;
651 };
652 
653 #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:49
QString mAttributionUrl
Definition: qgsmaplayer.h:596
QString mKeywordList
Definition: qgsmaplayer.h:588
LayerType
Layers enum defining the types of layers that can be added to a map.
Definition: qgsmaplayer.h:55
QString mDataUrlFormat
Definition: qgsmaplayer.h:592
const QString & originalName() const
Get the original name of the layer.
Definition: qgsmaplayer.h:91
QString mLegendUrlFormat
Definition: qgsmaplayer.h:605
virtual void reload()
Synchronises with changes in the datasource.
Definition: qgsmaplayer.h:129
const QString & attribution() const
Definition: qgsmaplayer.h:110
void setMetadataUrlType(const QString &metaUrlType)
Definition: qgsmaplayer.h:117
virtual QgsMapLayerRenderer * createMapRenderer(QgsRenderContext &rendererContext)
Return new instance of QgsMapLayerRenderer that will be used for rendering of given context...
Definition: qgsmaplayer.h:134
QString mLayerName
Name of the layer - used for display.
Definition: qgsmaplayer.h:578
QgsError mError
Error.
Definition: qgsmaplayer.h:608
const QString & legendUrl() const
Definition: qgsmaplayer.h:378
QgsRectangle mExtent
Extent of the layer.
Definition: qgsmaplayer.h:569
const char * name() const
QString mMetadataUrl
MetadataUrl of the layer.
Definition: qgsmaplayer.h:599
void setLegendUrlFormat(const QString &legendUrlFormat)
Definition: qgsmaplayer.h:379
void setError(const QgsError &theError)
Set error message.
Definition: qgsmaplayer.h:566
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
Q_DECL_DEPRECATED QImage * cacheImage()
Definition: qgsmaplayer.h:383
const QString & metadataUrlType() const
Definition: qgsmaplayer.h:118
QString mDataUrl
DataUrl of the layer.
Definition: qgsmaplayer.h:591
const QString & metadataUrl() const
Definition: qgsmaplayer.h:116
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:572
void setDataUrlFormat(const QString &dataUrlFormat)
Definition: qgsmaplayer.h:105
virtual QgsError error() const
Get current status error.
Definition: qgsmaplayer.h:250
QString mTitle
Definition: qgsmaplayer.h:584
virtual bool readSld(const QDomNode &node, QString &errorMessage)
Definition: qgsmaplayer.h:353
QString mMetadataUrlFormat
Definition: qgsmaplayer.h:601
void setLegendUrl(const QString &legendUrl)
Definition: qgsmaplayer.h:377
virtual void connectNotify(const char *signal)
void setMetadataUrlFormat(const QString &metaUrlFormat)
Definition: qgsmaplayer.h:119
QString mAttribution
Attribution of the layer.
Definition: qgsmaplayer.h:595
QString mAbstract
Description of the layer.
Definition: qgsmaplayer.h:587
virtual Q_DECL_DEPRECATED void onCacheImageDelete()
Definition: qgsmaplayer.h:387
Contains information about the context of a rendering operation.
QString mDataSource
Data source description string, varies by layer type.
Definition: qgsmaplayer.h:575
QgsError is container for error messages (report).
Definition: qgserror.h:77
QString mLegendUrl
WMS legend.
Definition: qgsmaplayer.h:604
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:111
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:564
virtual QDateTime timestamp() const
Time stamp of data source in the moment when data/metadata were loaded by provider.
Definition: qgsmaplayer.h:485
void setAttribution(const QString &attrib)
Definition: qgsmaplayer.h:109
const QString & attributionUrl() const
Definition: qgsmaplayer.h:112
Management of styles for use with one map layer.
const QString & metadataUrlFormat() const
Definition: qgsmaplayer.h:120
const QString & legendUrlFormat() const
Definition: qgsmaplayer.h:380
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
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:582
QString mMetadataUrlType
Definition: qgsmaplayer.h:600
const QString & keywordList() const
Definition: qgsmaplayer.h:100
void setAbstract(const QString &abstract)
Definition: qgsmaplayer.h:96
const QString & dataUrlFormat() const
Definition: qgsmaplayer.h:106