QGIS API Documentation  2.8.2-Wien
 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 <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 
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 
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 
362  virtual bool readSymbology( const QDomNode& node, QString& errorMessage ) = 0;
363 
370  virtual bool writeSymbology( QDomNode &node, QDomDocument& doc, QString& errorMessage ) const = 0;
371 
373  QUndoStack *undoStack();
374 
375  /* Layer legendUrl information */
376  void setLegendUrl( const QString& legendUrl ) { mLegendUrl = legendUrl; }
377  const QString& legendUrl() const { return mLegendUrl; }
378  void setLegendUrlFormat( const QString& legendUrlFormat ) { mLegendUrlFormat = legendUrlFormat; }
379  const QString& legendUrlFormat() const { return mLegendUrlFormat; }
380 
382  Q_DECL_DEPRECATED QImage *cacheImage() { return 0; }
384  Q_DECL_DEPRECATED void setCacheImage( QImage * );
386  Q_DECL_DEPRECATED virtual void onCacheImageDelete() {}
387 
393  void setLegend( QgsMapLayerLegend* legend );
398  QgsMapLayerLegend* legend() const;
399 
404  QgsMapLayerStyleManager* styleManager() const;
405 
413  float minimumScale() const;
414 
422  float maximumScale() const;
423 
430  bool hasScaleBasedVisibility() const;
431 
432  public slots:
433 
435  virtual void invalidTransformInput();
436 
444  void setMinimumScale( const float theMinScale );
445 
453  void setMaximumScale( const float theMaxScale );
454 
461  void setScaleBasedVisibility( const bool enabled );
462 
466  Q_DECL_DEPRECATED void toggleScaleBasedVisibility( bool theVisibilityFlag );
467 
470  Q_DECL_DEPRECATED void clearCacheImage();
471 
478  void triggerRepaint();
479 
481  virtual QString metadata();
482 
484  virtual QDateTime timestamp() const { return QDateTime() ; }
485 
486  signals:
487 
489  void drawingProgress( int theProgress, int theTotalSteps );
490 
492  void statusChanged( QString theStatus );
493 
495  void layerNameChanged();
496 
498  void layerCrsChanged();
499 
503  void repaintRequested();
504 
506  void screenUpdateRequested();
507 
509  void recalculateExtents();
510 
512  void dataChanged();
513 
515  void blendModeChanged( const QPainter::CompositionMode &blendMode );
516 
518  void rendererChanged();
519 
524  void legendChanged();
525 
526  protected:
528  virtual void setExtent( const QgsRectangle &rect );
529 
531  void setValid( bool valid );
532 
536  virtual bool readXml( const QDomNode& layer_node );
537 
541  virtual bool writeXml( QDomNode & layer_node, QDomDocument & document );
542 
543 
547  void readCustomProperties( const QDomNode& layerNode, const QString& keyStartsWith = "" );
548 
550  void writeCustomProperties( QDomNode & layerNode, QDomDocument & doc ) const;
551 
553  void readStyleManager( const QDomNode& layerNode );
555  void writeStyleManager( QDomNode& layerNode, QDomDocument& doc ) const;
556 
557 #if 0
558 
559  void connectNotify( const char * signal ) override;
560 #endif
561 
563  void appendError( const QgsErrorMessage & theMessage ) { mError.append( theMessage );}
565  void setError( const QgsError & theError ) { mError = theError;}
566 
569 
571  bool mValid;
572 
574  QString mDataSource;
575 
577  QString mLayerName;
578 
581  QString mLayerOrigName;
582 
583  QString mTitle;
584 
586  QString mAbstract;
587  QString mKeywordList;
588 
590  QString mDataUrl;
591  QString mDataUrlFormat;
592 
594  QString mAttribution;
596 
598  QString mMetadataUrl;
601 
603  QString mLegendUrl;
605 
608 
609  private:
613 
615  QgsMapLayer( QgsMapLayer const & );
616 
618  QgsMapLayer & operator=( QgsMapLayer const & );
619 
621  QString mID;
622 
624  QgsMapLayer::LayerType mLayerType;
625 
627  QPainter::CompositionMode mBlendMode;
628 
630  QString mTag;
631 
633  float mMinScale;
635  float mMaxScale;
637  bool mScaleBasedVisibility;
638 
640  QUndoStack mUndoStack;
641 
643  QgsObjectCustomProperties mCustomProperties;
644 
646  QgsMapLayerLegend* mLegend;
647 
649  QgsMapLayerStyleManager* mStyleManager;
650 };
651 
652 #endif