Skip to content

Commit

Permalink
Workaround odd upstream Qt issue where a painter with a semi-transparent
Browse files Browse the repository at this point in the history
brush with no solid pattern incorrectly applies the brush opacity to
the pen when exporting to printer devices

Fixes #36580
  • Loading branch information
nyalldawson committed May 21, 2020
1 parent 150b373 commit 38c8218
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions src/core/symbology/qgsfillsymbollayer.cpp
Expand Up @@ -41,6 +41,10 @@
#include <QDomElement>
#include <random>

#ifndef QT_NO_PRINTER
#include <QPrinter>
#endif

QgsSimpleFillSymbolLayer::QgsSimpleFillSymbolLayer( const QColor &color, Qt::BrushStyle style, const QColor &strokeColor, Qt::PenStyle strokeStyle, double strokeWidth,
Qt::PenJoinStyle penJoinStyle )
: mBrushStyle( style )
Expand Down Expand Up @@ -273,9 +277,6 @@ void QgsSimpleFillSymbolLayer::renderPolygon( const QPolygonF &points, const QVe

applyDataDefinedSymbology( context, mBrush, mPen, mSelPen );

p->setBrush( context.selected() ? mSelBrush : mBrush );
p->setPen( context.selected() ? mSelPen : mPen );

QPointF offset;
if ( !mOffset.isNull() )
{
Expand All @@ -284,7 +285,29 @@ void QgsSimpleFillSymbolLayer::renderPolygon( const QPolygonF &points, const QVe
p->translate( offset );
}

_renderPolygon( p, points, rings, context );
#ifndef QT_NO_PRINTER
if ( mBrush.style() == Qt::SolidPattern || mBrush.style() == Qt::NoBrush || !dynamic_cast<QPrinter *>( p->device() ) )
#endif
{
p->setPen( context.selected() ? mSelPen : mPen );
p->setBrush( context.selected() ? mSelBrush : mBrush );
_renderPolygon( p, points, rings, context );
}
#ifndef QT_NO_PRINTER
else
{
// workaround upstream issue https://github.com/qgis/QGIS/issues/36580
// when a non-solid brush is set with opacity, the opacity incorrectly applies to the pen
// when exporting to PDF/print devices
p->setBrush( context.selected() ? mSelBrush : mBrush );
p->setPen( Qt::NoPen );
_renderPolygon( p, points, rings, context );

p->setPen( context.selected() ? mSelPen : mPen );
p->setBrush( Qt::NoBrush );
_renderPolygon( p, points, rings, context );
}
#endif

if ( !mOffset.isNull() )
{
Expand Down

0 comments on commit 38c8218

Please sign in to comment.