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 commit 51d8ad7)
  • Loading branch information
nyalldawson committed Jul 27, 2020
1 parent 7cdbfc3 commit 520d3da455c18285586ec75fc0b76be051456d0e
@@ -555,7 +555,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.

@@ -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.

@@ -284,7 +284,7 @@ void QgsTextBackgroundSettings::setJoinStyle( Qt::PenJoinStyle style )
d->joinStyle = style;
}

QgsPaintEffect *QgsTextBackgroundSettings::paintEffect() const
const QgsPaintEffect *QgsTextBackgroundSettings::paintEffect() const
{
return d->paintEffect.get();
}
@@ -475,7 +475,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.
@@ -134,7 +134,7 @@ void QgsTextBufferSettings::setBlendMode( QPainter::CompositionMode mode )
d->blendMode = mode;
}

QgsPaintEffect *QgsTextBufferSettings::paintEffect() const
const QgsPaintEffect *QgsTextBufferSettings::paintEffect() const
{
return d->paintEffect.get();
}
@@ -212,7 +212,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.
@@ -327,12 +327,13 @@ double QgsTextRenderer::drawBuffer( QgsRenderContext &context, const QgsTextRend
if ( buffer.paintEffect() && buffer.paintEffect()->enabled() )
{
context.setPainter( &buffp );
std::unique_ptr< QgsPaintEffect > tmpEffect( buffer.paintEffect()->clone() );

buffer.paintEffect()->begin( context );
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 );
}
@@ -616,9 +617,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();
}

@@ -986,9 +989,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 );
}
}

0 comments on commit 520d3da

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