QGIS API Documentation  master-3f58142
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 #include <QPainter>
00028 
00029 #include "qgis.h"
00030 #include "qgserror.h"
00031 #include "qgsrectangle.h"
00032 #include "qgsmaprenderer.h"
00033 
00034 class QgsRenderContext;
00035 class QgsCoordinateReferenceSystem;
00036 
00037 class QDomDocument;
00038 class QKeyEvent;
00039 class QPainter;
00040 
00045 class CORE_EXPORT QgsMapLayer : public QObject
00046 {
00047     Q_OBJECT
00048 
00049   public:
00051     enum LayerType
00052     {
00053       VectorLayer,
00054       RasterLayer,
00055       PluginLayer // added in 1.5
00056     };
00057 
00063     QgsMapLayer( QgsMapLayer::LayerType type = VectorLayer, QString lyrname = QString::null, QString source = QString::null );
00064 
00066     virtual ~QgsMapLayer();
00067 
00071     QgsMapLayer::LayerType type() const;
00072 
00076     QString id() const;
00077 
00081     void setLayerName( const QString & name );
00082 
00086     const QString & name() const;
00087 
00091     const QString & originalName() const { return mLayerOrigName; }
00092 
00093     void setTitle( const QString& title ) { mTitle = title; }
00094     const QString& title() const { return mTitle; }
00095 
00096     void setAbstract( const QString& abstract ) { mAbstract = abstract; }
00097     const QString& abstract() const { return mAbstract; }
00098 
00099     /* Set the blending mode used for rendering a layer */
00100     void setBlendMode( const QPainter::CompositionMode blendMode );
00101     /* Returns the current blending mode for a layer */
00102     QPainter::CompositionMode blendMode() const;
00103 
00106     virtual void reload() {}
00107 
00114     virtual bool draw( QgsRenderContext& rendererContext );
00115 
00119     virtual void drawLabels( QgsRenderContext& rendererContext );
00120 
00122     virtual QgsRectangle extent();
00123 
00128     bool isValid();
00129 
00134     QString publicSource() const;
00135 
00137     const QString &source() const;
00138 
00143     virtual QStringList subLayers() const;
00144 
00149     virtual void setLayerOrder( const QStringList &layers );
00150 
00152     virtual void setSubLayerVisibility( QString name, bool vis );
00153 
00155     virtual bool isEditable() const;
00156 
00171     bool readLayerXML( const QDomElement& layerElement );
00172 
00173 
00189     bool writeLayerXML( QDomElement& layerElement, QDomDocument& document );
00190 
00193     void setCustomProperty( const QString& key, const QVariant& value );
00196     QVariant customProperty( const QString& value, const QVariant& defaultValue = QVariant() ) const;
00199     void removeCustomProperty( const QString& key );
00200 
00201 #if 0
00202 
00203     unsigned int getTransparency();
00204 
00206     virtual void setTransparency( unsigned int );
00207 #endif
00208 
00215     virtual QString lastErrorTitle();
00216 
00223     virtual QString lastError();
00224 
00229     virtual QgsError error() const { return mError; }
00230 
00234     const QgsCoordinateReferenceSystem& crs() const;
00235 
00238     void setCrs( const QgsCoordinateReferenceSystem& srs, bool emitSignal = true );
00239 
00241     static QString capitaliseLayerName( const QString& name );
00242 
00250     virtual QString styleURI( );
00251 
00260     virtual QString loadDefaultStyle( bool & theResultFlag );
00261 
00275     virtual QString loadNamedStyle( const QString theURI, bool & theResultFlag );
00276 
00277     virtual bool loadNamedStyleFromDb( const QString db, const QString theURI, QString &qml );
00278 
00279     //TODO edit infos
00286     virtual void exportNamedStyle( QDomDocument &doc, QString &errorMsg );
00287 
00288 
00295     virtual void exportSldStyle( QDomDocument &doc, QString &errorMsg );
00296 
00305     virtual QString saveDefaultStyle( bool & theResultFlag );
00306 
00320     virtual QString saveNamedStyle( const QString theURI, bool & theResultFlag );
00321 
00322     virtual QString saveSldStyle( const QString theURI, bool & theResultFlag );
00323     virtual QString loadSldStyle( const QString theURI, bool &theResultFlag );
00324 
00325     virtual bool readSld( const QDomNode& node, QString& errorMessage )
00326     { Q_UNUSED( node ); errorMessage = QString( "Layer type %1 not supported" ).arg( type() ); return false; }
00327 
00328 
00334     virtual bool readSymbology( const QDomNode& node, QString& errorMessage ) = 0;
00335 
00342     virtual bool writeSymbology( QDomNode &node, QDomDocument& doc, QString& errorMessage ) const = 0;
00343 
00345     QUndoStack* undoStack();
00346 
00349     QImage *cacheImage() { return mpCacheImage; }
00352     void setCacheImage( QImage * thepImage );
00353 
00358     virtual void onCacheImageDelete() {};
00359 
00360   public slots:
00361 
00363     virtual void invalidTransformInput();
00364 
00366     void setMinimumScale( float theMinScale );
00367     float minimumScale();
00368 
00370     void setMaximumScale( float theMaxScale );
00371     float maximumScale();
00372 
00374     void toggleScaleBasedVisibility( bool theVisibilityFlag );
00375     bool hasScaleBasedVisibility();
00376 
00379     void clearCacheImage();
00380 
00382     virtual QString metadata();
00383 
00385     virtual QDateTime timestamp() const { return QDateTime() ; }
00386 
00387   signals:
00388 
00390     void drawingProgress( int theProgress, int theTotalSteps );
00391 
00393     void statusChanged( QString theStatus );
00394 
00396     void layerNameChanged();
00397 
00401     void layerCrsChanged();
00402 
00406     void repaintRequested();
00407 
00410     void screenUpdateRequested();
00411 
00413     void recalculateExtents();
00414 
00417     void dataChanged();
00418 
00419   protected:
00421     virtual void setExtent( const QgsRectangle &rect );
00422 
00425     void setValid( bool valid );
00426 
00430     virtual bool readXml( const QDomNode& layer_node );
00431 
00435     virtual bool writeXml( QDomNode & layer_node, QDomDocument & document );
00436 
00437 
00441     void readCustomProperties( const QDomNode& layerNode, const QString& keyStartsWith = "" );
00442 
00444     void writeCustomProperties( QDomNode & layerNode, QDomDocument & doc ) const;
00445 
00447     void connectNotify( const char * signal );
00448 
00450     void appendError( const QgsErrorMessage & theMessage ) { mError.append( theMessage );}
00452     void setError( const QgsError & theError ) { mError = theError;}
00453 
00455     unsigned int mTransparencyLevel;
00456 
00458     QgsRectangle mExtent;
00459 
00461     bool mValid;
00462 
00464     QString mDataSource;
00465 
00467     QString mLayerName;
00468 
00472     QString mLayerOrigName;
00473 
00474     QString mTitle;
00475 
00477     QString mAbstract;
00478 
00480     QgsError mError;
00481 
00482   private:
00485     QgsCoordinateReferenceSystem* mCRS;
00486 
00488     QgsMapLayer( QgsMapLayer const & );
00489 
00491     QgsMapLayer & operator=( QgsMapLayer const & );
00492 
00494     QString mID;
00495 
00497     QgsMapLayer::LayerType mLayerType;
00498 
00500     QPainter::CompositionMode mBlendMode;
00501 
00503     QString mTag;
00504 
00506     float mMinScale;
00508     float mMaxScale;
00510     bool mScaleBasedVisibility;
00511 
00513     QUndoStack mUndoStack;
00514 
00515     QMap<QString, QVariant> mCustomProperties;
00516 
00519     QImage * mpCacheImage;
00520 
00521 };
00522 
00523 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines