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 qgis#36580

(cherry picked from commit 38c8218)
  • Loading branch information
nyalldawson committed May 26, 2020
1 parent 68c6a0e commit a562b67
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions src/core/symbology/qgsfillsymbollayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
#include <QDomDocument>
#include <QDomElement>

#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 @@ -271,9 +275,6 @@ void QgsSimpleFillSymbolLayer::renderPolygon( const QPolygonF &points, QList<QPo

applyDataDefinedSymbology( context, mBrush, mPen, mSelPen );

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

QPointF offset;
if ( !mOffset.isNull() )
{
Expand All @@ -282,7 +283,29 @@ void QgsSimpleFillSymbolLayer::renderPolygon( const QPolygonF &points, QList<QPo
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 a562b67

Please sign in to comment.