Skip to content

Commit

Permalink
Fix layers with layer wide opacity "flashing" by rendering
Browse files Browse the repository at this point in the history
intermediate states without opacity
  • Loading branch information
nyalldawson committed Oct 3, 2016
1 parent d3f8763 commit 19f6b62
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 15 deletions.
2 changes: 2 additions & 0 deletions src/core/qgsmaprenderercustompainterjob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,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 );
}

}
Expand Down
7 changes: 7 additions & 0 deletions src/core/qgsmaprendererjob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,11 @@ LayerRenderJobs QgsMapRendererJob::prepareJobs( QPainter* painter, QgsLabelingEn
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;

Expand Down Expand Up @@ -360,8 +365,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 );
}

Expand Down
1 change: 1 addition & 0 deletions src/core/qgsmaprendererjob.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 0 additions & 14 deletions src/core/qgsvectorlayerrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ QgsVectorLayerRenderer::QgsVectorLayerRenderer( QgsVectorLayer* layer, QgsRender
, mDiagrams( false )
, mLabelProvider( nullptr )
, mDiagramProvider( nullptr )
, mLayerTransparency( 0 )
{
mSource = new QgsVectorLayerFeatureSource( layer );

Expand All @@ -66,7 +65,6 @@ QgsVectorLayerRenderer::QgsVectorLayerRenderer( QgsVectorLayer* layer, QgsRender

mGeometryType = layer->geometryType();

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

mSimplifyMethod = layer->simplifyMethod();
Expand Down Expand Up @@ -264,18 +262,6 @@ bool QgsVectorLayerRenderer::render()
mRenderer->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;
}

Expand Down
1 change: 0 additions & 1 deletion src/core/qgsvectorlayerrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 19f6b62

Please sign in to comment.