Skip to content

Commit e740890

Browse files
committedFeb 14, 2017
Add custom layer property to render a layer over labels in the map canvas
Usage: layer.setCustomProperty('rendering/renderAboveLabels', True) This is exposed only as a layer custom property since it's really just exposing some private internals of the rendering map composition. It's not supported outside of canvas, and only works when parallel rendering with render cache is enabled. It's not exposed anywhere in GUI for this same reason. Consider it a hidden API call until someone implements proper handling of mixed layer/label stacking order.
1 parent e025b58 commit e740890

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
 

Diff for: ‎src/core/qgsmaprendererjob.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -457,10 +457,14 @@ QImage QgsMapRendererJob::composeImage( const QgsMapSettings& settings, const La
457457

458458
QPainter painter( &image );
459459

460+
460461
for ( LayerRenderJobs::const_iterator it = jobs.constBegin(); it != jobs.constEnd(); ++it )
461462
{
462463
const LayerRenderJob& job = *it;
463464

465+
if ( job.layer && job.layer->customProperty( QStringLiteral( "rendering/renderAboveLabels" ) ).toBool() )
466+
continue; // skip layer for now, it will be rendered after labels
467+
464468
painter.setCompositionMode( job.blendMode );
465469
painter.setOpacity( job.opacity );
466470

@@ -479,6 +483,22 @@ QImage QgsMapRendererJob::composeImage( const QgsMapSettings& settings, const La
479483
painter.drawImage( 0, 0, *labelJob.img );
480484
}
481485

486+
// render any layers with the renderAboveLabels flag now
487+
for ( LayerRenderJobs::const_iterator it = jobs.constBegin(); it != jobs.constEnd(); ++it )
488+
{
489+
const LayerRenderJob& job = *it;
490+
491+
if ( !job.layer || !job.layer->customProperty( QStringLiteral( "rendering/renderAboveLabels" ) ).toBool() )
492+
continue;
493+
494+
painter.setCompositionMode( job.blendMode );
495+
painter.setOpacity( job.opacity );
496+
497+
Q_ASSERT( job.img );
498+
499+
painter.drawImage( 0, 0, *job.img );
500+
}
501+
482502
painter.end();
483503
return image;
484504
}

0 commit comments

Comments
 (0)
Please sign in to comment.