QGIS API Documentation  2.6.0-Brighton
 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"
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
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 
77  QString id() const;
78 
82  void setLayerName( const QString & name );
83 
87  const QString & name() const;
88 
90  const QString & originalName() const { return mLayerOrigName; }
91 
92  void setTitle( const QString& title ) { mTitle = title; }
93  const QString& title() const { return mTitle; }
94 
95  void setAbstract( const QString& abstract ) { mAbstract = abstract; }
96  const QString& abstract() const { return mAbstract; }
97 
98  void setKeywordList( const QString& keywords ) { mKeywordList = keywords; }
99  const QString& keywordList() const { return mKeywordList; }
100 
101  /* Layer dataUrl information */
102  void setDataUrl( const QString& dataUrl ) { mDataUrl = dataUrl; }
103  const QString& dataUrl() const { return mDataUrl; }
104  void setDataUrlFormat( const QString& dataUrlFormat ) { mDataUrlFormat = dataUrlFormat; }
105  const QString& dataUrlFormat() const { return mDataUrlFormat; }
106 
107  /* Layer attribution information */
108  void setAttribution( const QString& attrib ) { mAttribution = attrib; }
109  const QString& attribution() const { return mAttribution; }
110  void setAttributionUrl( const QString& attribUrl ) { mAttributionUrl = attribUrl; }
111  const QString& attributionUrl() const { return mAttributionUrl; }
112 
113  /* Layer metadataUrl information */
114  void setMetadataUrl( const QString& metaUrl ) { mMetadataUrl = metaUrl; }
115  const QString& metadataUrl() const { return mMetadataUrl; }
116  void setMetadataUrlType( const QString& metaUrlType ) { mMetadataUrlType = metaUrlType; }
117  const QString& metadataUrlType() const { return mMetadataUrlType; }
118  void setMetadataUrlFormat( const QString& metaUrlFormat ) { mMetadataUrlFormat = metaUrlFormat; }
119  const QString& metadataUrlFormat() const { return mMetadataUrlFormat; }
120 
121  /* Set the blending mode used for rendering a layer */
122  void setBlendMode( const QPainter::CompositionMode &blendMode );
123  /* Returns the current blending mode for a layer */
124  QPainter::CompositionMode blendMode() const;
125 
128  virtual void reload() {}
129 
133  virtual QgsMapLayerRenderer* createMapRenderer( QgsRenderContext& rendererContext ) { Q_UNUSED( rendererContext ); return 0; }
134 
141  virtual bool draw( QgsRenderContext& rendererContext );
142 
146  virtual void drawLabels( QgsRenderContext& rendererContext );
147 
149  virtual QgsRectangle extent();
150 
155  bool isValid();
156 
161  QString publicSource() const;
162 
164  const QString &source() const;
165 
170  virtual QStringList subLayers() const;
171 
176  virtual void setLayerOrder( const QStringList &layers );
177 
179  virtual void setSubLayerVisibility( QString name, bool vis );
180 
182  virtual bool isEditable() const;
183 
198  bool readLayerXML( const QDomElement& layerElement );
199 
200 
217  bool writeLayerXML( QDomElement& layerElement, QDomDocument& document, QString relativeBasePath = QString::null );
218 
224  static QDomDocument asLayerDefinition( QList<QgsMapLayer*> layers, QString relativeBasePath = QString::null );
225 
228  static QList<QgsMapLayer*> fromLayerDefinition( QDomDocument& document );
229  static QList<QgsMapLayer*> fromLayerDefinitionFile( const QString qlrfile );
230 
232  void setCustomProperty( const QString& key, const QVariant& value );
234  QVariant customProperty( const QString& value, const QVariant& defaultValue = QVariant() ) const;
236  void removeCustomProperty( const QString& key );
237 
238 
240  Q_DECL_DEPRECATED virtual QString lastErrorTitle();
241 
243  Q_DECL_DEPRECATED virtual QString lastError();
244 
249  virtual QgsError error() const { return mError; }
250 
254  const QgsCoordinateReferenceSystem& crs() const;
255 
257  void setCrs( const QgsCoordinateReferenceSystem& srs, bool emitSignal = true );
258 
260  static QString capitaliseLayerName( const QString& name );
261 
268  virtual QString styleURI();
269 
278  virtual QString loadDefaultStyle( bool & theResultFlag );
279 
293  virtual QString loadNamedStyle( const QString &theURI, bool &theResultFlag );
294 
295  virtual bool loadNamedStyleFromDb( const QString &db, const QString &theURI, QString &qml );
296 
297  //TODO edit infos
304  virtual void exportNamedStyle( QDomDocument &doc, QString &errorMsg );
305 
306 
313  virtual void exportSldStyle( QDomDocument &doc, QString &errorMsg );
314 
323  virtual QString saveDefaultStyle( bool & theResultFlag );
324 
338  virtual QString saveNamedStyle( const QString &theURI, bool &theResultFlag );
339 
340  virtual QString saveSldStyle( const QString &theURI, bool &theResultFlag );
341  virtual QString loadSldStyle( const QString &theURI, bool &theResultFlag );
342 
343  virtual bool readSld( const QDomNode &node, QString &errorMessage )
344  { Q_UNUSED( node ); errorMessage = QString( "Layer type %1 not supported" ).arg( type() ); return false; }
345 
346 
352  virtual bool readSymbology( const QDomNode& node, QString& errorMessage ) = 0;
353 
360  virtual bool writeSymbology( QDomNode &node, QDomDocument& doc, QString& errorMessage ) const = 0;
361 
363  QUndoStack *undoStack();
364 
365  /* Layer legendUrl information */
366  void setLegendUrl( const QString& legendUrl ) { mLegendUrl = legendUrl; }
367  const QString& legendUrl() const { return mLegendUrl; }
368  void setLegendUrlFormat( const QString& legendUrlFormat ) { mLegendUrlFormat = legendUrlFormat; }
369  const QString& legendUrlFormat() const { return mLegendUrlFormat; }
370 
372  Q_DECL_DEPRECATED QImage *cacheImage() { return 0; }
374  Q_DECL_DEPRECATED void setCacheImage( QImage * );
376  Q_DECL_DEPRECATED virtual void onCacheImageDelete() {}
377 
383  void setLegend( QgsMapLayerLegend* legend );
388  QgsMapLayerLegend* legend() const;
389 
390  public slots:
391 
393  virtual void invalidTransformInput();
394 
396  void setMinimumScale( float theMinScale );
397  float minimumScale() const;
398 
400  void setMaximumScale( float theMaxScale );
401  float maximumScale() const;
402 
404  void toggleScaleBasedVisibility( bool theVisibilityFlag );
405  bool hasScaleBasedVisibility() const;
406 
409  Q_DECL_DEPRECATED void clearCacheImage();
410 
417  void triggerRepaint();
418 
420  virtual QString metadata();
421 
423  virtual QDateTime timestamp() const { return QDateTime() ; }
424 
425  signals:
426 
428  void drawingProgress( int theProgress, int theTotalSteps );
429 
431  void statusChanged( QString theStatus );
432 
434  void layerNameChanged();
435 
437  void layerCrsChanged();
438 
442  void repaintRequested();
443 
445  void screenUpdateRequested();
446 
448  void recalculateExtents();
449 
451  void dataChanged();
452 
454  void blendModeChanged( const QPainter::CompositionMode &blendMode );
455 
457  void rendererChanged();
458 
463  void legendChanged();
464 
465  protected:
467  virtual void setExtent( const QgsRectangle &rect );
468 
470  void setValid( bool valid );
471 
475  virtual bool readXml( const QDomNode& layer_node );
476 
480  virtual bool writeXml( QDomNode & layer_node, QDomDocument & document );
481 
482 
486  void readCustomProperties( const QDomNode& layerNode, const QString& keyStartsWith = "" );
487 
489  void writeCustomProperties( QDomNode & layerNode, QDomDocument & doc ) const;
490 
492  void connectNotify( const char * signal );
493 
495  void appendError( const QgsErrorMessage & theMessage ) { mError.append( theMessage );}
497  void setError( const QgsError & theError ) { mError = theError;}
498 
501 
503  bool mValid;
504 
506  QString mDataSource;
507 
509  QString mLayerName;
510 
513  QString mLayerOrigName;
514 
515  QString mTitle;
516 
518  QString mAbstract;
519  QString mKeywordList;
520 
522  QString mDataUrl;
523  QString mDataUrlFormat;
524 
526  QString mAttribution;
528 
530  QString mMetadataUrl;
533 
535  QString mLegendUrl;
537 
540 
541  private:
545 
547  QgsMapLayer( QgsMapLayer const & );
548 
550  QgsMapLayer & operator=( QgsMapLayer const & );
551 
553  QString mID;
554 
556  QgsMapLayer::LayerType mLayerType;
557 
559  QPainter::CompositionMode mBlendMode;
560 
562  QString mTag;
563 
565  float mMinScale;
567  float mMaxScale;
569  bool mScaleBasedVisibility;
570 
572  QUndoStack mUndoStack;
573 
575  QgsObjectCustomProperties mCustomProperties;
576 
578  QgsMapLayerLegend* mLegend;
579 };
580 
581 #endif