Skip to content

Commit

Permalink
Add custom layer property to render a layer over labels in the map ca…
Browse files Browse the repository at this point in the history
…nvas

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.
  • Loading branch information
nyalldawson committed Feb 14, 2017
1 parent e025b58 commit e740890
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/core/qgsmaprendererjob.cpp
Expand Up @@ -457,10 +457,14 @@ QImage QgsMapRendererJob::composeImage( const QgsMapSettings& settings, const La

QPainter painter( &image );


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

if ( job.layer && job.layer->customProperty( QStringLiteral( "rendering/renderAboveLabels" ) ).toBool() )
continue; // skip layer for now, it will be rendered after labels

painter.setCompositionMode( job.blendMode );
painter.setOpacity( job.opacity );

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

// render any layers with the renderAboveLabels flag now
for ( LayerRenderJobs::const_iterator it = jobs.constBegin(); it != jobs.constEnd(); ++it )
{
const LayerRenderJob& job = *it;

if ( !job.layer || !job.layer->customProperty( QStringLiteral( "rendering/renderAboveLabels" ) ).toBool() )
continue;

painter.setCompositionMode( job.blendMode );
painter.setOpacity( job.opacity );

Q_ASSERT( job.img );

painter.drawImage( 0, 0, *job.img );
}

painter.end();
return image;
}
Expand Down

0 comments on commit e740890

Please sign in to comment.