QGIS API Documentation  2.5.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"
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 // added in 1.5
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 
79  QString id() const;
80 
84  void setLayerName( const QString & name );
85 
89  const QString & name() const;
90 
94  const QString & originalName() const { return mLayerOrigName; }
95 
96  void setTitle( const QString& title ) { mTitle = title; }
97  const QString& title() const { return mTitle; }
98 
99  void setAbstract( const QString& abstract ) { mAbstract = abstract; }
100  const QString& abstract() const { return mAbstract; }
101 
102  void setKeywordList( const QString& keywords ) { mKeywordList = keywords; }
103  const QString& keywordList() const { return mKeywordList; }
104 
105  /* Layer dataUrl information */
106  void setDataUrl( const QString& dataUrl ) { mDataUrl = dataUrl; }
107  const QString& dataUrl() const { return mDataUrl; }
108  void setDataUrlFormat( const QString& dataUrlFormat ) { mDataUrlFormat = dataUrlFormat; }
109  const QString& dataUrlFormat() const { return mDataUrlFormat; }
110 
111  /* Layer attribution information */
112  void setAttribution( const QString& attrib ) { mAttribution = attrib; }
113  const QString& attribution() const { return mAttribution; }
114  void setAttributionUrl( const QString& attribUrl ) { mAttributionUrl = attribUrl; }
115  const QString& attributionUrl() const { return mAttributionUrl; }
116 
117  /* Layer metadataUrl information */
118  void setMetadataUrl( const QString& metaUrl ) { mMetadataUrl = metaUrl; }
119  const QString& metadataUrl() const { return mMetadataUrl; }
120  void setMetadataUrlType( const QString& metaUrlType ) { mMetadataUrlType = metaUrlType; }
121  const QString& metadataUrlType() const { return mMetadataUrlType; }
122  void setMetadataUrlFormat( const QString& metaUrlFormat ) { mMetadataUrlFormat = metaUrlFormat; }
123  const QString& metadataUrlFormat() const { return mMetadataUrlFormat; }
124 
125  /* Set the blending mode used for rendering a layer */
126  void setBlendMode( const QPainter::CompositionMode &blendMode );
127  /* Returns the current blending mode for a layer */
128  QPainter::CompositionMode blendMode() const;
129 
132  virtual void reload() {}
133 
137  virtual QgsMapLayerRenderer* createMapRenderer( QgsRenderContext& rendererContext ) { Q_UNUSED( rendererContext ); return 0; }
138 
145  virtual bool draw( QgsRenderContext& rendererContext );
146 
150  virtual void drawLabels( QgsRenderContext& rendererContext );
151 
153  virtual QgsRectangle extent();
154 
159  bool isValid();
160 
165  QString publicSource() const;
166 
168  const QString &source() const;
169 
174  virtual QStringList subLayers() const;
175 
180  virtual void setLayerOrder( const QStringList &layers );
181 
183  virtual void setSubLayerVisibility( QString name, bool vis );
184 
186  virtual bool isEditable() const;
187 
202  bool readLayerXML( const QDomElement& layerElement );
203 
204 
220  bool writeLayerXML( QDomElement& layerElement, QDomDocument& document );
221 
227  static QDomDocument asLayerDefinition( QList<QgsMapLayer*> layers );
228 
231  static QList<QgsMapLayer*> fromLayerDefinition( QDomDocument& document );
232  static QList<QgsMapLayer*> fromLayerDefinitionFile( const QString qlrfile );
233 
236  void setCustomProperty( const QString& key, const QVariant& value );
239  QVariant customProperty( const QString& value, const QVariant& defaultValue = QVariant() ) const;
242  void removeCustomProperty( const QString& key );
243 
244 
246  Q_DECL_DEPRECATED virtual QString lastErrorTitle();
247 
249  Q_DECL_DEPRECATED virtual QString lastError();
250 
255  virtual QgsError error() const { return mError; }
256 
260  const QgsCoordinateReferenceSystem& crs() const;
261 
264  void setCrs( const QgsCoordinateReferenceSystem& srs, bool emitSignal = true );
265 
267  static QString capitaliseLayerName( const QString& name );
268 
276  virtual QString styleURI( );
277 
286  virtual QString loadDefaultStyle( bool & theResultFlag );
287 
301  virtual QString loadNamedStyle( const QString &theURI, bool &theResultFlag );
302 
303  virtual bool loadNamedStyleFromDb( const QString &db, const QString &theURI, QString &qml );
304 
305  //TODO edit infos
312  virtual void exportNamedStyle( QDomDocument &doc, QString &errorMsg );
313 
314 
321  virtual void exportSldStyle( QDomDocument &doc, QString &errorMsg );
322 
331  virtual QString saveDefaultStyle( bool & theResultFlag );
332 
346  virtual QString saveNamedStyle( const QString &theURI, bool &theResultFlag );
347 
348  virtual QString saveSldStyle( const QString &theURI, bool &theResultFlag );
349  virtual QString loadSldStyle( const QString &theURI, bool &theResultFlag );
350 
351  virtual bool readSld( const QDomNode &node, QString &errorMessage )
352  { Q_UNUSED( node ); errorMessage = QString( "Layer type %1 not supported" ).arg( type() ); return false; }
353 
354 
360  virtual bool readSymbology( const QDomNode& node, QString& errorMessage ) = 0;
361 
368  virtual bool writeSymbology( QDomNode &node, QDomDocument& doc, QString& errorMessage ) const = 0;
369 
371  QUndoStack *undoStack();
372 
373  /* Layer legendUrl information */
374  void setLegendUrl( const QString& legendUrl ) { mLegendUrl = legendUrl; }
375  const QString& legendUrl() const { return mLegendUrl; }
376  void setLegendUrlFormat( const QString& legendUrlFormat ) { mLegendUrlFormat = legendUrlFormat; }
377  const QString& legendUrlFormat() const { return mLegendUrlFormat; }
378 
380  Q_DECL_DEPRECATED QImage *cacheImage() { return 0; }
382  Q_DECL_DEPRECATED void setCacheImage( QImage * );
384  Q_DECL_DEPRECATED virtual void onCacheImageDelete() {}
385 
391  void setLegend( QgsMapLayerLegend* legend );
395  QgsMapLayerLegend* legend() const;
396 
397  public slots:
398 
400  virtual void invalidTransformInput();
401 
403  void setMinimumScale( float theMinScale );
404  float minimumScale() const;
405 
407  void setMaximumScale( float theMaxScale );
408  float maximumScale() const;
409 
411  void toggleScaleBasedVisibility( bool theVisibilityFlag );
412  bool hasScaleBasedVisibility() const;
413 
416  Q_DECL_DEPRECATED void clearCacheImage();
417 
419  virtual QString metadata();
420 
422  virtual QDateTime timestamp() const { return QDateTime() ; }
423 
424  signals:
425 
427  void drawingProgress( int theProgress, int theTotalSteps );
428 
430  void statusChanged( QString theStatus );
431 
433  void layerNameChanged();
434 
438  void layerCrsChanged();
439 
443  void repaintRequested();
444 
446  void screenUpdateRequested();
447 
449  void recalculateExtents();
450 
453  void dataChanged();
454 
456  void blendModeChanged( const QPainter::CompositionMode &blendMode );
457 
459  void rendererChanged();
460 
465  void legendChanged();
466 
467  protected:
469  virtual void setExtent( const QgsRectangle &rect );
470 
473  void setValid( bool valid );
474 
478  virtual bool readXml( const QDomNode& layer_node );
479 
483  virtual bool writeXml( QDomNode & layer_node, QDomDocument & document );
484 
485 
489  void readCustomProperties( const QDomNode& layerNode, const QString& keyStartsWith = "" );
490 
492  void writeCustomProperties( QDomNode & layerNode, QDomDocument & doc ) const;
493 
495  void connectNotify( const char * signal );
496 
498  void appendError( const QgsErrorMessage & theMessage ) { mError.append( theMessage );}
500  void setError( const QgsError & theError ) { mError = theError;}
501 
504 
506  bool mValid;
507 
509  QString mDataSource;
510 
512  QString mLayerName;
513 
517  QString mLayerOrigName;
518 
519  QString mTitle;
520 
522  QString mAbstract;
523  QString mKeywordList;
524 
526  QString mDataUrl;
527  QString mDataUrlFormat;
528 
530  QString mAttribution;
532 
534  QString mMetadataUrl;
537 
539  QString mLegendUrl;
541 
544 
545  private:
549 
551  QgsMapLayer( QgsMapLayer const & );
552 
554  QgsMapLayer & operator=( QgsMapLayer const & );
555 
557  QString mID;
558 
561 
563  QPainter::CompositionMode mBlendMode;
564 
566  QString mTag;
567 
569  float mMinScale;
571  float mMaxScale;
574 
576  QUndoStack mUndoStack;
577 
580 
583 };
584 
585 #endif