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
  • Loading branch information
nyalldawson committed Jul 26, 2020
1 parent 95bd7b2 commit 51d8ad75c5808bd83444d03159d22e15219766ac
@@ -558,7 +558,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.

@@ -226,7 +226,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.

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

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

QgsPaintEffect *QgsTextBufferSettings::paintEffect() const
const QgsPaintEffect *QgsTextBufferSettings::paintEffect() const
{
return d->paintEffect.get();
}
@@ -215,7 +215,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.
@@ -358,16 +358,17 @@ 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 );
if ( scaleFactor != 1.0 )
context.painter()->scale( 1 / scaleFactor, 1 / scaleFactor );
context.painter()->drawPath( path );
if ( scaleFactor != 1.0 )
context.painter()->scale( scaleFactor, scaleFactor );
buffer.paintEffect()->end( context );
tmpEffect->end( context );

context.setPainter( p );
}
@@ -700,9 +701,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();
}

@@ -1062,9 +1065,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 51d8ad7

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