Do not overwrite renderContext in QgsMapRendererJob::drawLabeling

Dedicated QgsRenderContext is already created and configured in prepareLabelingJob.
This commit is contained in:
arnaud.morvan@camptocamp.com 2019-01-08 14:13:50 +01:00
parent 2c8acf136e
commit 948048cd4d
4 changed files with 18 additions and 12 deletions

View File

@ -183,6 +183,7 @@ emitted when asynchronous rendering is finished (or canceled).
}; };

View File

@ -295,12 +295,12 @@ void QgsMapRendererCustomPainterJob::doRender()
mLabelJob.img->fill( 0 ); mLabelJob.img->fill( 0 );
painter.begin( mLabelJob.img ); painter.begin( mLabelJob.img );
mLabelJob.context.setPainter( &painter ); mLabelJob.context.setPainter( &painter );
drawLabeling( mSettings, mLabelJob.context, mLabelingEngineV2.get(), &painter ); drawLabeling( mLabelJob.context, mLabelingEngineV2.get(), &painter );
painter.end(); painter.end();
} }
else else
{ {
drawLabeling( mSettings, mLabelJob.context, mLabelingEngineV2.get(), mPainter ); drawLabeling( mLabelJob.context, mLabelingEngineV2.get(), mPainter );
} }
mLabelJob.complete = true; mLabelJob.complete = true;
@ -318,8 +318,7 @@ void QgsMapRendererCustomPainterJob::doRender()
QgsDebugMsgLevel( "Rendering completed in (seconds): " + QString( "%1" ).arg( renderTime.elapsed() / 1000.0 ), 2 ); QgsDebugMsgLevel( "Rendering completed in (seconds): " + QString( "%1" ).arg( renderTime.elapsed() / 1000.0 ), 2 );
} }
void QgsMapRendererJob::drawLabeling( QgsRenderContext &renderContext, QgsLabelingEngine *labelingEngine2, QPainter *painter )
void QgsMapRendererJob::drawLabeling( const QgsMapSettings &settings, QgsRenderContext &renderContext, QgsLabelingEngine *labelingEngine2, QPainter *painter )
{ {
QgsDebugMsgLevel( QStringLiteral( "Draw labeling start" ), 5 ); QgsDebugMsgLevel( QStringLiteral( "Draw labeling start" ), 5 );
@ -329,22 +328,22 @@ void QgsMapRendererJob::drawLabeling( const QgsMapSettings &settings, QgsRenderC
// Reset the composition mode before rendering the labels // Reset the composition mode before rendering the labels
painter->setCompositionMode( QPainter::CompositionMode_SourceOver ); 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 ); renderContext.setPainter( painter );
if ( labelingEngine2 ) if ( labelingEngine2 )
{ {
// set correct extent
renderContext.setExtent( settings.visibleExtent() );
renderContext.setCoordinateTransform( QgsCoordinateTransform() );
labelingEngine2->run( renderContext ); labelingEngine2->run( renderContext );
} }
QgsDebugMsg( QStringLiteral( "Draw labeling took (seconds): %1" ).arg( t.elapsed() / 1000. ) ); 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 ) bool QgsMapRendererJob::needTemporaryImage( QgsMapLayer *ml )
{ {

View File

@ -286,8 +286,14 @@ class CORE_EXPORT QgsMapRendererJob : public QObject
*/ */
void cleanupLabelJob( LabelRenderJob &job ) SIP_SKIP; 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 //! \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: private:

View File

@ -297,7 +297,7 @@ void QgsMapRendererParallelJob::renderLabelsStatic( QgsMapRendererParallelJob *s
// draw the labels! // draw the labels!
try try
{ {
drawLabeling( self->mSettings, job.context, self->mLabelingEngineV2.get(), &painter ); drawLabeling( job.context, self->mLabelingEngineV2.get(), &painter );
} }
catch ( QgsException &e ) catch ( QgsException &e )
{ {