Quantum GIS API Documentation  1.8
src/core/qgsmaplayer.h
Go to the documentation of this file.
00001 /***************************************************************************
00002                           qgsmaplayer.h  -  description
00003                              -------------------
00004     begin                : Fri Jun 28 2002
00005     copyright            : (C) 2002 by Gary E.Sherman
00006     email                : sherman at mrcc.com
00007 ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #ifndef QGSMAPLAYER_H
00019 #define QGSMAPLAYER_H
00020 
00021 #include <QDateTime>
00022 #include <QObject>
00023 #include <QUndoStack>
00024 #include <QVariant>
00025 #include <QImage>
00026 #include <QDomNode>
00027 
00028 #include "qgis.h"
00029 #include "qgsrectangle.h"
00030 
00031 class QgsRenderContext;
00032 class QgsCoordinateReferenceSystem;
00033 
00034 class QDomDocument;
00035 class QKeyEvent;
00036 class QPainter;
00037 
00042 class CORE_EXPORT QgsMapLayer : public QObject
00043 {
00044     Q_OBJECT
00045 
00046   public:
00048     enum LayerType
00049     {
00050       VectorLayer,
00051       RasterLayer,
00052       PluginLayer // added in 1.5
00053     };
00054 
00060     QgsMapLayer( QgsMapLayer::LayerType type = VectorLayer, QString lyrname = QString::null, QString source = QString::null );
00061 
00063     virtual ~QgsMapLayer();
00064 
00068     QgsMapLayer::LayerType type() const;
00069 
00073     QString id() const;
00074 
00078     Q_DECL_DEPRECATED QString getLayerID() const { return id(); }
00079 
00083     void setLayerName( const QString & name );
00084 
00088     QString const & name() const;
00089 
00090     void setTitle( const QString& title ) { mTitle = title; }
00091     const QString& title() const { return mTitle; }
00092 
00093     void setAbstract( const QString& abstract ) { mAbstract = abstract; }
00094     const QString& abstract() const { return mAbstract; }
00095 
00098     virtual void reload() {}
00099 
00106     virtual bool draw( QgsRenderContext& rendererContext );
00107 
00111     virtual void drawLabels( QgsRenderContext& rendererContext );
00112 
00114     QgsRectangle extent() const;
00115 
00120     bool isValid();
00121 
00126     QString publicSource() const;
00127 
00129     QString const & source() const;
00130 
00135     virtual QStringList subLayers() const;
00136 
00141     virtual void setLayerOrder( const QStringList &layers );
00142 
00144     virtual void setSubLayerVisibility( QString name, bool vis );
00145 
00147     virtual bool isEditable() const;
00148 
00163     bool readXML( const QDomNode& layer_node );
00164 
00165 
00181     bool writeXML( QDomNode & layer_node, QDomDocument & document );
00182 
00185     void setCustomProperty( const QString& key, const QVariant& value );
00188     QVariant customProperty( const QString& value, const QVariant& defaultValue = QVariant() ) const;
00191     void removeCustomProperty( const QString& key );
00192 
00194     virtual bool copySymbologySettings( const QgsMapLayer& other ) = 0;
00195 
00197     virtual bool hasCompatibleSymbology( const QgsMapLayer& other ) const = 0;
00198 
00200     unsigned int getTransparency();
00201 
00203     void setTransparency( unsigned int );
00204 
00211     virtual QString lastErrorTitle();
00212 
00219     virtual QString lastError();
00220 
00224     const QgsCoordinateReferenceSystem& crs() const;
00225 
00231     Q_DECL_DEPRECATED const QgsCoordinateReferenceSystem& srs();
00232 
00235     void setCrs( const QgsCoordinateReferenceSystem& srs, bool emitSignal = true );
00236 
00238     static QString capitaliseLayerName( const QString name );
00239 
00247     virtual QString styleURI( );
00248 
00257     virtual QString loadDefaultStyle( bool & theResultFlag );
00258 
00272     virtual QString loadNamedStyle( const QString theURI, bool & theResultFlag );
00273 
00274     virtual bool loadNamedStyleFromDb( const QString db, const QString theURI, QString &qml );
00275 
00284     virtual QString saveDefaultStyle( bool & theResultFlag );
00285 
00299     virtual QString saveNamedStyle( const QString theURI, bool & theResultFlag );
00300 
00301     virtual QString saveSldStyle( const QString theURI, bool & theResultFlag );
00302     virtual QString loadSldStyle( const QString theURI, bool &theResultFlag );
00303 
00304     virtual bool readSld( const QDomNode& node, QString& errorMessage )
00305     { Q_UNUSED( node ); errorMessage = QString( "Layer type %1 not supported" ).arg( type() ); return false; }
00306 
00307 
00313     virtual bool readSymbology( const QDomNode& node, QString& errorMessage ) = 0;
00314 
00321     virtual bool writeSymbology( QDomNode &node, QDomDocument& doc, QString& errorMessage ) const = 0;
00322 
00324     QUndoStack* undoStack();
00325 
00328     QImage * cacheImage() { return mpCacheImage; }
00331     void setCacheImage( QImage * thepImage );
00332 
00333   public slots:
00334 
00336     virtual void invalidTransformInput();
00337 
00339     void setMinimumScale( float theMinScale );
00340     float minimumScale();
00341 
00343     void setMaximumScale( float theMaxScale );
00344     float maximumScale();
00345 
00347     void toggleScaleBasedVisibility( bool theVisibilityFlag );
00348     bool hasScaleBasedVisibility();
00349 
00352     void clearCacheImage();
00353 
00355     virtual QString metadata();
00356 
00358     virtual QDateTime timestamp() const { return QDateTime() ; }
00359 
00360   signals:
00361 
00363     void drawingProgress( int theProgress, int theTotalSteps );
00364 
00366     void statusChanged( QString theStatus );
00367 
00369     void layerNameChanged();
00370 
00374     void layerCrsChanged();
00375 
00379     void repaintRequested();
00380 
00383     void screenUpdateRequested();
00384 
00386     void recalculateExtents();
00387 
00390     void dataChanged();
00391 
00392   protected:
00393 
00396     void setValid( bool valid );
00397 
00401     virtual bool readXml( const QDomNode& layer_node );
00402 
00406     virtual bool writeXml( QDomNode & layer_node, QDomDocument & document );
00407 
00408 
00412     void readCustomProperties( const QDomNode& layerNode, const QString& keyStartsWith = "" );
00413 
00415     void writeCustomProperties( QDomNode & layerNode, QDomDocument & doc ) const;
00416 
00418     void connectNotify( const char * signal );
00419 
00421     unsigned int mTransparencyLevel;
00422 
00424     QgsRectangle mLayerExtent;
00425 
00427     bool mValid;
00428 
00430     QString mDataSource;
00431 
00433     QString mLayerName;
00434 
00435     QString mTitle;
00436 
00438     QString mAbstract;
00439 
00440   private:
00443     QgsCoordinateReferenceSystem* mCRS;
00444 
00446     QgsMapLayer( QgsMapLayer const & );
00447 
00449     QgsMapLayer & operator=( QgsMapLayer const & );
00450 
00452     QString mID;
00453 
00455     QgsMapLayer::LayerType mLayerType;
00456 
00458     QString mTag;
00459 
00461     float mMinScale;
00463     float mMaxScale;
00465     bool mScaleBasedVisibility;
00466 
00468     QUndoStack mUndoStack;
00469 
00470     QMap<QString, QVariant> mCustomProperties;
00471 
00474     QImage * mpCacheImage;
00475 
00476 };
00477 
00478 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines