Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Do not overwrite renderContext in QgsMapRendererJob::drawLabeling
Dedicated QgsRenderContext is already created and configured in prepareLabelingJob.
  • Loading branch information
arnaud-morvan authored and nyalldawson committed Jan 28, 2019
1 parent 4d33588 commit c97645e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
1 change: 1 addition & 0 deletions python/core/auto_generated/qgsmaprendererjob.sip.in
Expand Up @@ -183,6 +183,7 @@ emitted when asynchronous rendering is finished (or canceled).




};


Expand Down
19 changes: 9 additions & 10 deletions src/core/qgsmaprenderercustompainterjob.cpp
Expand Up @@ -295,12 +295,12 @@ void QgsMapRendererCustomPainterJob::doRender()
mLabelJob.img->fill( 0 );
painter.begin( mLabelJob.img );
mLabelJob.context.setPainter( &painter );
drawLabeling( mSettings, mLabelJob.context, mLabelingEngineV2.get(), &painter );
drawLabeling( mLabelJob.context, mLabelingEngineV2.get(), &painter );
painter.end();
}
else
{
drawLabeling( mSettings, mLabelJob.context, mLabelingEngineV2.get(), mPainter );
drawLabeling( mLabelJob.context, mLabelingEngineV2.get(), mPainter );
}

mLabelJob.complete = true;
Expand All @@ -318,8 +318,7 @@ void QgsMapRendererCustomPainterJob::doRender()
QgsDebugMsgLevel( "Rendering completed in (seconds): " + QString( "%1" ).arg( renderTime.elapsed() / 1000.0 ), 2 );
}


void QgsMapRendererJob::drawLabeling( const QgsMapSettings &settings, QgsRenderContext &renderContext, QgsLabelingEngine *labelingEngine2, QPainter *painter )
void QgsMapRendererJob::drawLabeling( QgsRenderContext &renderContext, QgsLabelingEngine *labelingEngine2, QPainter *painter )
{
QgsDebugMsgLevel( QStringLiteral( "Draw labeling start" ), 5 );

Expand All @@ -329,22 +328,22 @@ void QgsMapRendererJob::drawLabeling( const QgsMapSettings &settings, QgsRenderC
// Reset the composition mode before rendering the labels
painter->setCompositionMode( QPainter::CompositionMode_SourceOver );

// TODO: this is not ideal - we could override rendering stopped flag that has been set in meanwhile
renderContext = QgsRenderContext::fromMapSettings( settings );
renderContext.setPainter( painter );

if ( labelingEngine2 )
{
// set correct extent
renderContext.setExtent( settings.visibleExtent() );
renderContext.setCoordinateTransform( QgsCoordinateTransform() );

labelingEngine2->run( renderContext );
}

QgsDebugMsg( QStringLiteral( "Draw labeling took (seconds): %1" ).arg( t.elapsed() / 1000. ) );
}

void QgsMapRendererJob::drawLabeling( const QgsMapSettings &settings, QgsRenderContext &renderContext, QgsLabelingEngine *labelingEngine2, QPainter *painter )
{
Q_UNUSED( settings );

drawLabeling( renderContext, labelingEngine2, painter );
}

bool QgsMapRendererJob::needTemporaryImage( QgsMapLayer *ml )
{
Expand Down
8 changes: 7 additions & 1 deletion src/core/qgsmaprendererjob.h
Expand Up @@ -286,8 +286,14 @@ class CORE_EXPORT QgsMapRendererJob : public QObject
*/
void cleanupLabelJob( LabelRenderJob &job ) SIP_SKIP;

/**
* \note not available in Python bindings
* \deprecated Will be removed in QGIS 4.0
*/
Q_DECL_DEPRECATED static void drawLabeling( const QgsMapSettings &settings, QgsRenderContext &renderContext, QgsLabelingEngine *labelingEngine2, QPainter *painter ) SIP_SKIP;

//! \note not available in Python bindings
static void drawLabeling( const QgsMapSettings &settings, QgsRenderContext &renderContext, QgsLabelingEngine *labelingEngine2, QPainter *painter ) SIP_SKIP;
static void drawLabeling( QgsRenderContext &renderContext, QgsLabelingEngine *labelingEngine2, QPainter *painter ) SIP_SKIP;

private:

Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsmaprendererparalleljob.cpp
Expand Up @@ -297,7 +297,7 @@ void QgsMapRendererParallelJob::renderLabelsStatic( QgsMapRendererParallelJob *s
// draw the labels!
try
{
drawLabeling( self->mSettings, job.context, self->mLabelingEngineV2.get(), &painter );
drawLabeling( job.context, self->mLabelingEngineV2.get(), &painter );
}
catch ( QgsException &e )
{
Expand Down

0 comments on commit c97645e

Please sign in to comment.