QGIS API Documentation  2.2.0-Valmiera
 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;
36 
37 class QDomDocument;
38 class QKeyEvent;
39 class QPainter;
40 
45 class CORE_EXPORT QgsMapLayer : public QObject
46 {
47  Q_OBJECT
48 
49  public:
51  enum LayerType
52  {
55  PluginLayer // added in 1.5
56  };
57 
63  QgsMapLayer( QgsMapLayer::LayerType type = VectorLayer, QString lyrname = QString::null, QString source = QString::null );
64 
66  virtual ~QgsMapLayer();
67 
71  QgsMapLayer::LayerType type() const;
72 
76  QString id() const;
77 
81  void setLayerName( const QString & name );
82 
86  const QString & name() const;
87 
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 
137  virtual bool draw( QgsRenderContext& rendererContext );
138 
142  virtual void drawLabels( QgsRenderContext& rendererContext );
143 
145  virtual QgsRectangle extent();
146 
151  bool isValid();
152 
157  QString publicSource() const;
158 
160  const QString &source() const;
161 
166  virtual QStringList subLayers() const;
167 
172  virtual void setLayerOrder( const QStringList &layers );
173 
175  virtual void setSubLayerVisibility( QString name, bool vis );
176 
178  virtual bool isEditable() const;
179 
194  bool readLayerXML( const QDomElement& layerElement );
195 
196 
212  bool writeLayerXML( QDomElement& layerElement, QDomDocument& document );
213 
216  void setCustomProperty( const QString& key, const QVariant& value );
219  QVariant customProperty( const QString& value, const QVariant& defaultValue = QVariant() ) const;
222  void removeCustomProperty( const QString& key );
223 
224 
231  virtual QString lastErrorTitle();
232 
239  virtual QString lastError();
240 
245  virtual QgsError error() const { return mError; }
246 
250  const QgsCoordinateReferenceSystem& crs() const;
251 
254  void setCrs( const QgsCoordinateReferenceSystem& srs, bool emitSignal = true );
255 
257  static QString capitaliseLayerName( const QString& name );
258 
266  virtual QString styleURI( );
267 
276  virtual QString loadDefaultStyle( bool & theResultFlag );
277 
291  virtual QString loadNamedStyle( const QString &theURI, bool &theResultFlag );
292 
293  virtual bool loadNamedStyleFromDb( const QString &db, const QString &theURI, QString &qml );
294 
295  //TODO edit infos
302  virtual void exportNamedStyle( QDomDocument &doc, QString &errorMsg );
303 
304 
311  virtual void exportSldStyle( QDomDocument &doc, QString &errorMsg );
312 
321  virtual QString saveDefaultStyle( bool & theResultFlag );
322 
336  virtual QString saveNamedStyle( const QString &theURI, bool &theResultFlag );
337 
338  virtual QString saveSldStyle( const QString &theURI, bool &theResultFlag );
339  virtual QString loadSldStyle( const QString &theURI, bool &theResultFlag );
340 
341  virtual bool readSld( const QDomNode &node, QString &errorMessage )
342  { Q_UNUSED( node ); errorMessage = QString( "Layer type %1 not supported" ).arg( type() ); return false; }
343 
344 
350  virtual bool readSymbology( const QDomNode& node, QString& errorMessage ) = 0;
351 
358  virtual bool writeSymbology( QDomNode &node, QDomDocument& doc, QString& errorMessage ) const = 0;
359 
361  QUndoStack *undoStack();
362 
365  QImage *cacheImage() { return mpCacheImage; }
368  void setCacheImage( QImage * thepImage );
369 
374  virtual void onCacheImageDelete() {}
375 
376  public slots:
377 
379  virtual void invalidTransformInput();
380 
382  void setMinimumScale( float theMinScale );
383  float minimumScale() const;
384 
386  void setMaximumScale( float theMaxScale );
387  float maximumScale() const;
388 
390  void toggleScaleBasedVisibility( bool theVisibilityFlag );
391  bool hasScaleBasedVisibility() const;
392 
395  void clearCacheImage();
396 
398  virtual QString metadata();
399 
401  virtual QDateTime timestamp() const { return QDateTime() ; }
402 
403  signals:
404 
406  void drawingProgress( int theProgress, int theTotalSteps );
407 
409  void statusChanged( QString theStatus );
410 
412  void layerNameChanged();
413 
417  void layerCrsChanged();
418 
422  void repaintRequested();
423 
426  void screenUpdateRequested();
427 
429  void recalculateExtents();
430 
433  void dataChanged();
434 
436  void blendModeChanged( const QPainter::CompositionMode &blendMode );
437 
438  protected:
440  virtual void setExtent( const QgsRectangle &rect );
441 
444  void setValid( bool valid );
445 
449  virtual bool readXml( const QDomNode& layer_node );
450 
454  virtual bool writeXml( QDomNode & layer_node, QDomDocument & document );
455 
456 
460  void readCustomProperties( const QDomNode& layerNode, const QString& keyStartsWith = "" );
461 
463  void writeCustomProperties( QDomNode & layerNode, QDomDocument & doc ) const;
464 
466  void connectNotify( const char * signal );
467 
469  void appendError( const QgsErrorMessage & theMessage ) { mError.append( theMessage );}
471  void setError( const QgsError & theError ) { mError = theError;}
472 
475 
477  bool mValid;
478 
480  QString mDataSource;
481 
483  QString mLayerName;
484 
488  QString mLayerOrigName;
489 
490  QString mTitle;
491 
493  QString mAbstract;
494  QString mKeywordList;
495 
497  QString mDataUrl;
498  QString mDataUrlFormat;
499 
501  QString mAttribution;
503 
505  QString mMetadataUrl;
508 
511 
512  private:
516 
518  QgsMapLayer( QgsMapLayer const & );
519 
521  QgsMapLayer & operator=( QgsMapLayer const & );
522 
524  QString mID;
525 
528 
530  QPainter::CompositionMode mBlendMode;
531 
533  QString mTag;
534 
536  float mMinScale;
538  float mMaxScale;
541 
543  QUndoStack mUndoStack;
544 
545  QMap<QString, QVariant> mCustomProperties;
546 
549  QImage * mpCacheImage;
550 
551 };
552 
553 #endif