Skip to content
Permalink
Browse files

Don't modify text format paint effects in place

Avoids race conditions when multiple threads are rendering the same
text format which contains paint effects

Fixes #37938

cherry-picked from 51d8ad7
  • Loading branch information
nyalldawson committed Jul 27, 2020
1 parent e5f3a53 commit c9f251a959cb36659e38797836ba06eb4f08d605
Showing with 14 additions and 11 deletions.
  1. +2 −2 python/core/auto_generated/qgstextrenderer.sip.in
  2. +10 −7 src/core/qgstextrenderer.cpp
  3. +2 −2 src/core/qgstextrenderer.h
@@ -223,7 +223,7 @@ Write settings into a DOM element.
.. seealso:: :py:func:`readXml`
%End

QgsPaintEffect *paintEffect() const;
const QgsPaintEffect *paintEffect() const;
%Docstring
Returns the current paint effect for the buffer.

@@ -796,7 +796,7 @@ Sets the join style used for drawing the background shape.
.. seealso:: :py:func:`joinStyle`
%End

QgsPaintEffect *paintEffect() const;
const QgsPaintEffect *paintEffect() const;
%Docstring
Returns the current paint effect for the background shape.

@@ -176,7 +176,7 @@ void QgsTextBufferSettings::setBlendMode( QPainter::CompositionMode mode )
d->blendMode = mode;
}

QgsPaintEffect *QgsTextBufferSettings::paintEffect() const
const QgsPaintEffect *QgsTextBufferSettings::paintEffect() const
{
return d->paintEffect.get();
}
@@ -667,7 +667,7 @@ void QgsTextBackgroundSettings::setJoinStyle( Qt::PenJoinStyle style )
d->joinStyle = style;
}

QgsPaintEffect *QgsTextBackgroundSettings::paintEffect() const
const QgsPaintEffect *QgsTextBackgroundSettings::paintEffect() const
{
return d->paintEffect.get();
}
@@ -2630,11 +2630,12 @@ void QgsTextRenderer::drawBuffer( QgsRenderContext &context, const QgsTextRender
{
context.setPainter( &buffp );

buffer.paintEffect()->begin( context );
std::unique_ptr< QgsPaintEffect > tmpEffect( buffer.paintEffect()->clone() );
tmpEffect->begin( context );
context.painter()->setPen( pen );
context.painter()->setBrush( tmpColor );
context.painter()->drawPath( path );
buffer.paintEffect()->end( context );
tmpEffect->end( context );

context.setPainter( p );
}
@@ -2775,9 +2776,11 @@ void QgsTextRenderer::drawBackground( QgsRenderContext &context, QgsTextRenderer

QPainter *prevP = context.painter();
QPainter *p = context.painter();
std::unique_ptr< QgsPaintEffect > tmpEffect;
if ( background.paintEffect() && background.paintEffect()->enabled() )
{
background.paintEffect()->begin( context );
tmpEffect.reset( background.paintEffect()->clone() );
tmpEffect->begin( context );
p = context.painter();
}

@@ -3145,9 +3148,9 @@ void QgsTextRenderer::drawBackground( QgsRenderContext &context, QgsTextRenderer
}
}

if ( background.paintEffect() && background.paintEffect()->enabled() )
if ( tmpEffect )
{
background.paintEffect()->end( context );
tmpEffect->end( context );
context.setPainter( prevP );
}
}
@@ -217,7 +217,7 @@ class CORE_EXPORT QgsTextBufferSettings
* \returns paint effect
* \see setPaintEffect()
*/
QgsPaintEffect *paintEffect() const;
const QgsPaintEffect *paintEffect() const;

/**
* Sets the current paint \a effect for the buffer.
@@ -679,7 +679,7 @@ class CORE_EXPORT QgsTextBackgroundSettings
* \returns paint effect
* \see setPaintEffect()
*/
QgsPaintEffect *paintEffect() const;
const QgsPaintEffect *paintEffect() const;

/**
* Sets the current paint \a effect for the background shape.

0 comments on commit c9f251a

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