Index: src/core/qgsvectorlayer.cpp =================================================================== --- src/core/qgsvectorlayer.cpp (revision 11856) +++ src/core/qgsvectorlayer.cpp (working copy) @@ -646,6 +646,11 @@ return ptr; } +void QgsVectorLayer::run( ) +{ + draw( mRenderContext ); +} + bool QgsVectorLayer::draw( QgsRenderContext& rendererContext ) { //set update threshold before each draw to make sure the current setting is picked up Index: src/core/raster/qgsrasterlayer.cpp =================================================================== --- src/core/raster/qgsrasterlayer.cpp (revision 11856) +++ src/core/raster/qgsrasterlayer.cpp (working copy) @@ -1343,6 +1343,11 @@ return mDataProvider; } +void QgsRasterLayer::run( ) +{ + draw( mRenderContext ); +} + bool QgsRasterLayer::draw( QgsRenderContext& rendererContext ) { QgsDebugMsg( "entered. (renderContext)" ); Index: src/core/raster/qgsrasterlayer.h =================================================================== --- src/core/raster/qgsrasterlayer.h (revision 11856) +++ src/core/raster/qgsrasterlayer.h (working copy) @@ -455,6 +455,11 @@ /** Returns the data provider in a const-correct manner */ const QgsRasterDataProvider* dataProvider() const; + /** Render the layer in a thread. + * @note Added in QGIS 1.4 + */ + void run(); + /** \brief This is called when the view on the raster layer needs to be redrawn */ bool draw( QgsRenderContext& rendererContext ); Index: src/core/qgsmaplayer.cpp =================================================================== --- src/core/qgsmaplayer.cpp (revision 11856) +++ src/core/qgsmaplayer.cpp (working copy) @@ -133,6 +133,16 @@ return mLayerExtent; } +void QgsMapLayer::setRenderContext( QgsRenderContext theContext ) +{ + mRenderContext = theContext; +} + +void QgsMapLayer::run( ) +{ + return ; +} + bool QgsMapLayer::draw( QgsRenderContext& rendererContext ) { return false; Index: src/core/qgsvectorlayer.h =================================================================== --- src/core/qgsvectorlayer.h (revision 11856) +++ src/core/qgsvectorlayer.h (working copy) @@ -363,6 +363,10 @@ QgsSnappingResult > & snappingResults, QgsSnapper::SnappingType snap_to ); + /** Draw the layer in its own thread + * @note - added in QGIS 1.4 + */ + void run(); /** Draws the layer * @return FALSE if an error occurred during drawing */ Index: src/core/qgsmaplayer.h =================================================================== --- src/core/qgsmaplayer.h (revision 11857) +++ src/core/qgsmaplayer.h (working copy) @@ -25,10 +25,10 @@ #include #include #include +#include #include "qgsrectangle.h" -class QgsRenderContext; class QgsCoordinateReferenceSystem; class QDomNode; @@ -36,13 +36,15 @@ class QKeyEvent; class QPainter; +#include "qgsrendercontext.h" + /** \ingroup core * Base class for all map layer types. * This is the base class for all map layer types (vector, raster). */ -class CORE_EXPORT QgsMapLayer : public QObject +class CORE_EXPORT QgsMapLayer : public QThread { - Q_OBJECT + Q_OBJECT; public: /** Layers enum defining the types of layers that can be added to a map */ @@ -79,11 +81,28 @@ */ QString const & name() const; + /** Render this layer onto the paint device + * specified in mRenderContext in a separate thread. + * + * @note Added in QGIS 1.4 + */ + virtual void run(); + + /** Set the render context onto which the layer will + * be drawn when the thread is started. + * @see run() + * @note Added in QGIS 1.4 + */ + void setRenderContext( QgsRenderContext theContext ); + /** This is the method that does the actual work of * drawing the layer onto a paint device. * @param QgsRenderContext - describes the extents, * resolution etc. that should be used when rendering the * layer. + * @note From QGIS 1.4 onwards for threaded drawing you should rather + * use setRenderContext and then call run() rather than call this + * method which may be deprecated in the future. */ virtual bool draw( QgsRenderContext& rendererContext ); @@ -381,6 +400,10 @@ * @note This property was added in QGIS 1.4 **/ QImage * mpCacheImage; + protected: + /** Render context defining the scale etc and paint device + * onto which the layer should be rendered when run is called. */ + QgsRenderContext mRenderContext; }; #endif