Skip to content
Permalink
Browse files

Remove QgsMapLayer::draw() method from API (replaced by createMapRend…

…erer()) (#3501)
  • Loading branch information
wonder-sk committed Sep 16, 2016
1 parent 2e1abda commit a9105b7e7a95597be43e1fab672c34492b017044
@@ -816,6 +816,8 @@ and the new ramp can be retrieved after executing the dialog by calling ramp().<

<ul>
<li>crs() now returns a QgsCoordinateReferenceSystem object, not a reference. This change has no effect for PyQGIS code.</li>
<li>createMapRenderer() has been made pure virtual.</li>
<li>draw() has been removed. Use createMapRenderer() method for rendering of layers.</li>
<li>setLayerName() was removed, use setName() instead. The layerNameChanged() signal has been replaced by nameChanged().</li>
<li>toggleScaleBasedVisibility() was replaced by setScaleBasedVisibility()</li>
<li>lastErrorTitle(), lastError(), cacheImage(), onCacheImageDelete(), clearCacheImage() and the signals drawingProgress(),
@@ -933,6 +935,12 @@ be used instead of a null pointer if no transformation is required.</li>
<li>prepareGeometry() and geometryRequiresPreparation() now take a QgsCoordinateTransform reference, not a pointer. An invalid QgsCoordinateTransform should be used instead of a null pointer if no transformation is required.</li>
</ul>

\subsection qgis_api_break_3_0_QgsPluginLayer QgsPluginLayer

<ul>
<li>createMapRenderer(): default implementation (which called plugin's draw() method) has been removed. Plugin layers must implement createMapRenderer().</li>
</ul>

\subsection qgis_api_break_3_0_QgsPointLocator QgsPointLocator

<ul>
@@ -274,15 +274,7 @@ class QgsMapLayer : QObject
/** Return new instance of QgsMapLayerRenderer that will be used for rendering of given context
* @note added in 2.4
*/
virtual QgsMapLayerRenderer* createMapRenderer( QgsRenderContext& rendererContext ) /Factory/;

/** This is the method that does the actual work of
* drawing the layer onto a paint device.
* @param rendererContext describes the extents,
* resolumon etc. that should be used when rendering the
* layer.
*/
virtual bool draw( QgsRenderContext& rendererContext );
virtual QgsMapLayerRenderer* createMapRenderer( QgsRenderContext& rendererContext ) = 0 /Factory/;

/** Returns the extent of the layer. */
virtual QgsRectangle extent() const;
@@ -24,14 +24,4 @@ class QgsPluginLayer : QgsMapLayer
//! @note Added in v2.1
virtual QgsLegendSymbologyList legendSymbologyItems( QSize iconSize );

/** Return new instance of QgsMapLayerRenderer that will be used for rendering of given context
*
* The default implementation returns map layer renderer which just calls draw().
* This may work, but it is unsafe for multi-threaded rendering because of the run
* conditions that may happen (e.g. something is changed in the layer while it is
* being rendered).
*
* @note added in 2.4
*/
virtual QgsMapLayerRenderer* createMapRenderer( QgsRenderContext& rendererContext ) /Factory/;
};
@@ -995,11 +995,6 @@ class QgsVectorLayer : QgsMapLayer
*/
virtual QgsMapLayerRenderer* createMapRenderer( QgsRenderContext& rendererContext ) /Factory/;

/** Draws the layer
* @return false if an error occurred during drawing
*/
bool draw( QgsRenderContext& rendererContext );

/** Return the extent of the layer */
QgsRectangle extent() const;

@@ -133,9 +133,6 @@ class QgsRasterLayer : QgsMapLayer
*/
virtual QgsMapLayerRenderer* createMapRenderer( QgsRenderContext& rendererContext ) /Factory/;

/** \brief This is called when the view on the raster layer needs to be redrawn */
bool draw( QgsRenderContext& rendererContext );

/** \brief This is an overloaded version of the draw() function that is called by both draw() and thumbnailAsPixmap */
void draw( QPainter * theQPainter,
QgsRasterViewPort * myRasterViewPort,
@@ -154,11 +154,6 @@ QPainter::CompositionMode QgsMapLayer::blendMode() const
return mBlendMode;
}

bool QgsMapLayer::draw( QgsRenderContext& rendererContext )
{
Q_UNUSED( rendererContext );
return false;
}

bool QgsMapLayer::readLayerXml( const QDomElement& layerElement )
{
@@ -292,15 +292,7 @@ class CORE_EXPORT QgsMapLayer : public QObject
/** Return new instance of QgsMapLayerRenderer that will be used for rendering of given context
* @note added in 2.4
*/
virtual QgsMapLayerRenderer* createMapRenderer( QgsRenderContext& rendererContext ) { Q_UNUSED( rendererContext ); return nullptr; }

/** This is the method that does the actual work of
* drawing the layer onto a paint device.
* @param rendererContext describes the extents,
* resolumon etc. that should be used when rendering the
* layer.
*/
virtual bool draw( QgsRenderContext& rendererContext );
virtual QgsMapLayerRenderer* createMapRenderer( QgsRenderContext& rendererContext ) = 0;

/** Returns the extent of the layer. */
virtual QgsRectangle extent() const;
@@ -44,33 +44,3 @@ QgsLegendSymbologyList QgsPluginLayer::legendSymbologyItems( QSize iconSize )
Q_UNUSED( iconSize );
return QgsLegendSymbologyList();
}

/**
* \ingroup core
* Fallback layer renderer implementation for layer that do not support map renderer yet.
* @note added in 2.4
* @note not available in Python bindings
*/
class QgsPluginLayerRenderer : public QgsMapLayerRenderer
{
public:
QgsPluginLayerRenderer( QgsPluginLayer* layer, QgsRenderContext& rendererContext )
: QgsMapLayerRenderer( layer->id() )
, mLayer( layer )
, mRendererContext( rendererContext )
{}

virtual bool render() override
{
return mLayer->draw( mRendererContext );
}

protected:
QgsPluginLayer* mLayer;
QgsRenderContext& mRendererContext;
};

QgsMapLayerRenderer* QgsPluginLayer::createMapRenderer( QgsRenderContext& rendererContext )
{
return new QgsPluginLayerRenderer( this, rendererContext );
}
@@ -50,17 +50,6 @@ class CORE_EXPORT QgsPluginLayer : public QgsMapLayer
//! @note Added in v2.1
virtual QgsLegendSymbologyList legendSymbologyItems( QSize iconSize );

/** Return new instance of QgsMapLayerRenderer that will be used for rendering of given context
*
* The default implementation returns map layer renderer which just calls draw().
* This may work, but it is unsafe for multi-threaded rendering because of the run
* conditions that may happen (e.g. something is changed in the layer while it is
* being rendered).
*
* @note added in 2.4
*/
virtual QgsMapLayerRenderer* createMapRenderer( QgsRenderContext& rendererContext ) override;

protected:
QString mPluginLayerType;
};
@@ -238,11 +238,6 @@ QgsMapLayerRenderer* QgsVectorLayer::createMapRenderer( QgsRenderContext& render
return new QgsVectorLayerRenderer( this, rendererContext );
}

bool QgsVectorLayer::draw( QgsRenderContext& rendererContext )
{
QgsVectorLayerRenderer renderer( this, rendererContext );
return renderer.render();
}

void QgsVectorLayer::drawVertexMarker( double x, double y, QPainter& p, QgsVectorLayer::VertexMarkerType type, int m )
{
@@ -1119,11 +1119,6 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
*/
virtual QgsMapLayerRenderer* createMapRenderer( QgsRenderContext& rendererContext ) override;

/** Draws the layer
* @return false if an error occurred during drawing
*/
bool draw( QgsRenderContext& rendererContext ) override;

/** Return the extent of the layer */
QgsRectangle extent() const override;

@@ -263,21 +263,6 @@ QgsMapLayerRenderer *QgsRasterLayer::createMapRenderer( QgsRenderContext& render
return new QgsRasterLayerRenderer( this, rendererContext );
}

bool QgsRasterLayer::draw( QgsRenderContext& rendererContext )
{
QgsDebugMsgLevel( "entered. (renderContext)", 4 );

QgsDebugMsgLevel( "checking timestamp.", 4 );

// Check timestamp
if ( !update() )
{
return false;
}

QgsRasterLayerRenderer renderer( this, rendererContext );
return renderer.render();
}

void QgsRasterLayer::draw( QPainter * theQPainter,
QgsRasterViewPort * theRasterViewPort,
@@ -259,9 +259,6 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
*/
virtual QgsMapLayerRenderer* createMapRenderer( QgsRenderContext& rendererContext ) override;

/** \brief This is called when the view on the raster layer needs to be redrawn */
bool draw( QgsRenderContext& rendererContext ) override;

/** \brief This is an overloaded version of the draw() function that is called by both draw() and thumbnailAsPixmap */
void draw( QPainter * theQPainter,
QgsRasterViewPort * myRasterViewPort,
@@ -22,6 +22,7 @@
#include "qgsmessagelog.h"
#include "qgsmaprenderer.h"
#include "qgsscalecalculator.h"
#include "qgsmaplayerrenderer.h"
#include "qgsmaptopixel.h"
#include "qgsmaplayer.h"
#include "qgsmaplayerregistry.h"
@@ -236,6 +237,14 @@ void QgsMapRenderer::adjustExtentToSize()
}


static bool drawLayer( QgsMapLayer* ml, QgsRenderContext& context )
{
QgsMapLayerRenderer* mlr = ml->createMapRenderer( context );
bool res = mlr->render();
delete mlr;
return res;
}

void QgsMapRenderer::render( QPainter* painter, double* forceWidthScale )
{
//Lock render method for concurrent threads (e.g. from globe)
@@ -498,7 +507,7 @@ void QgsMapRenderer::render( QPainter* painter, double* forceWidthScale )
mRenderContext.painter()->scale( 1.0 / rasterScaleFactor, 1.0 / rasterScaleFactor );
}

if ( !ml->draw( mRenderContext ) )
if ( !drawLayer( ml, mRenderContext ) )
{
emit drawError( ml );
}
@@ -510,7 +519,7 @@ void QgsMapRenderer::render( QPainter* painter, double* forceWidthScale )
if ( split )
{
mRenderContext.setExtent( r2 );
if ( !ml->draw( mRenderContext ) )
if ( !drawLayer( ml, mRenderContext ) )
{
emit drawError( ml );
}

0 comments on commit a9105b7

Please sign in to comment.
You can’t perform that action at this time.