Skip to content
Permalink
Browse files

Fix layers with layer wide opacity "flashing" by rendering

intermediate states without opacity

(cherry-picked from 19f6b62)
  • Loading branch information
nyalldawson committed Oct 6, 2016
1 parent 61c0f18 commit 971b41332421bf4baae892c2b419361648dcc188
@@ -273,7 +273,9 @@ void QgsMapRendererCustomPainterJob::doRender()
if ( job.img )
{
// If we flattened this layer for alternate blend modes, composite it now
mPainter->setOpacity( job.opacity );
mPainter->drawImage( 0, 0, *job.img );
mPainter->setOpacity( 1.0 );
}

}
@@ -245,6 +245,11 @@ LayerRenderJobs QgsMapRendererJob::prepareJobs( QPainter* painter, QgsPalLabelin
job.cached = false;
job.img = nullptr;
job.blendMode = ml->blendMode();
job.opacity = 1.0;
if ( QgsVectorLayer* vl = qobject_cast<QgsVectorLayer *>( ml ) )
{
job.opacity = 1.0 - vl->layerTransparency() / 100.0;
}
job.layerId = ml->id();
job.renderingTime = -1;

@@ -361,8 +366,10 @@ QImage QgsMapRendererJob::composeImage( const QgsMapSettings& settings, const La
const LayerRenderJob& job = *it;

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

Q_ASSERT( job.img );

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

@@ -46,6 +46,7 @@ struct LayerRenderJob
QImage* img; // may be null if it is not necessary to draw to separate image (e.g. sequential rendering)
QgsMapLayerRenderer* renderer; // must be deleted
QPainter::CompositionMode blendMode;
double opacity;
bool cached; // if true, img already contains cached image from previous rendering
QString layerId;
int renderingTime; //!< time it took to render the layer in ms (it is -1 if not rendered or still rendering)
@@ -53,7 +53,6 @@ QgsVectorLayerRenderer::QgsVectorLayerRenderer( QgsVectorLayer* layer, QgsRender
, mDiagrams( false )
, mLabelProvider( nullptr )
, mDiagramProvider( nullptr )
, mLayerTransparency( 0 )
{
mSource = new QgsVectorLayerFeatureSource( layer );

@@ -64,7 +63,6 @@ QgsVectorLayerRenderer::QgsVectorLayerRenderer( QgsVectorLayer* layer, QgsRender

mGeometryType = layer->geometryType();

mLayerTransparency = layer->layerTransparency();
mFeatureBlendMode = layer->featureBlendMode();

mSimplifyMethod = layer->simplifyMethod();
@@ -262,18 +260,6 @@ bool QgsVectorLayerRenderer::render()
mRendererV2->paintEffect()->end( mContext );
}

//apply layer transparency for vector layers
if ( mContext.useAdvancedEffects() && mLayerTransparency != 0 )
{
// a layer transparency has been set, so update the alpha for the flattened layer
// by combining it with the layer transparency
QColor transparentFillColor = QColor( 0, 0, 0, 255 - ( 255 * mLayerTransparency / 100 ) );
// use destination in composition mode to merge source's alpha with destination
mContext.painter()->setCompositionMode( QPainter::CompositionMode_DestinationIn );
mContext.painter()->fillRect( 0, 0, mContext.painter()->device()->width(),
mContext.painter()->device()->height(), transparentFillColor );
}

return true;
}

@@ -136,7 +136,6 @@ class QgsVectorLayerRenderer : public QgsMapLayerRenderer
//! may be null. no need to delete: if exists it is owned by labeling engine
QgsVectorLayerDiagramProvider* mDiagramProvider;

int mLayerTransparency;
QPainter::CompositionMode mFeatureBlendMode;

QgsVectorSimplifyMethod mSimplifyMethod;
Binary file not shown.

0 comments on commit 971b413

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