@@ -629,6 +629,17 @@ void QgsTextBackgroundSettings::setJoinStyle( Qt::PenJoinStyle style )
629
629
d->joinStyle = style;
630
630
}
631
631
632
+ QgsPaintEffect *QgsTextBackgroundSettings::paintEffect () const
633
+ {
634
+ return d->paintEffect ;
635
+ }
636
+
637
+ void QgsTextBackgroundSettings::setPaintEffect ( QgsPaintEffect *effect )
638
+ {
639
+ delete d->paintEffect ;
640
+ d->paintEffect = effect;
641
+ }
642
+
632
643
void QgsTextBackgroundSettings::readFromLayer ( QgsVectorLayer *layer )
633
644
{
634
645
d->enabled = layer->customProperty ( QStringLiteral ( " labeling/shapeDraw" ), QVariant ( false ) ).toBool ();
@@ -737,6 +748,16 @@ void QgsTextBackgroundSettings::readFromLayer( QgsVectorLayer *layer )
737
748
}
738
749
d->blendMode = QgsPainting::getCompositionMode (
739
750
static_cast < QgsPainting::BlendMode >( layer->customProperty ( QStringLiteral ( " labeling/shapeBlendMode" ), QVariant ( QgsPainting::BlendNormal ) ).toUInt () ) );
751
+
752
+ if ( layer->customProperty ( QStringLiteral ( " labeling/shapeEffect" ) ).isValid () )
753
+ {
754
+ QDomDocument doc ( QStringLiteral ( " effect" ) );
755
+ doc.setContent ( layer->customProperty ( QStringLiteral ( " labeling/shapeEffect" ) ).toString () );
756
+ QDomElement effectElem = doc.firstChildElement ( QStringLiteral ( " effect" ) ).firstChildElement ( QStringLiteral ( " effect" ) );
757
+ setPaintEffect ( QgsApplication::paintEffectRegistry ()->createEffect ( effectElem ) );
758
+ }
759
+ else
760
+ setPaintEffect ( nullptr );
740
761
}
741
762
742
763
void QgsTextBackgroundSettings::writeToLayer ( QgsVectorLayer *layer ) const
@@ -767,6 +788,21 @@ void QgsTextBackgroundSettings::writeToLayer( QgsVectorLayer *layer ) const
767
788
layer->setCustomProperty ( QStringLiteral ( " labeling/shapeJoinStyle" ), static_cast < unsigned int >( d->joinStyle ) );
768
789
layer->setCustomProperty ( QStringLiteral ( " labeling/shapeOpacity" ), d->opacity );
769
790
layer->setCustomProperty ( QStringLiteral ( " labeling/shapeBlendMode" ), QgsPainting::getBlendModeEnum ( d->blendMode ) );
791
+
792
+ if ( d->paintEffect && !QgsPaintEffectRegistry::isDefaultStack ( d->paintEffect ) )
793
+ {
794
+ QDomDocument doc ( QStringLiteral ( " effect" ) );
795
+ QDomElement effectElem = doc.createElement ( QStringLiteral ( " effect" ) );
796
+ d->paintEffect ->saveProperties ( doc, effectElem );
797
+ QString effectProps;
798
+ QTextStream stream ( &effectProps );
799
+ effectElem.save ( stream, -1 );
800
+ layer->setCustomProperty ( QStringLiteral ( " labeling/shapeEffect" ), effectProps );
801
+ }
802
+ else
803
+ {
804
+ layer->removeCustomProperty ( QStringLiteral ( " labeling/shapeEffect" ) );
805
+ }
770
806
}
771
807
772
808
void QgsTextBackgroundSettings::readXml ( const QDomElement &elem )
@@ -879,6 +915,11 @@ void QgsTextBackgroundSettings::readXml( const QDomElement &elem )
879
915
d->blendMode = QgsPainting::getCompositionMode (
880
916
static_cast < QgsPainting::BlendMode >( backgroundElem.attribute ( QStringLiteral ( " shapeBlendMode" ), QString::number ( QgsPainting::BlendNormal ) ).toUInt () ) );
881
917
918
+ QDomElement effectElem = backgroundElem.firstChildElement ( QStringLiteral ( " effect" ) );
919
+ if ( !effectElem.isNull () )
920
+ setPaintEffect ( QgsApplication::paintEffectRegistry ()->createEffect ( effectElem ) );
921
+ else
922
+ setPaintEffect ( nullptr );
882
923
}
883
924
884
925
QDomElement QgsTextBackgroundSettings::writeXml ( QDomDocument &doc ) const
@@ -910,6 +951,8 @@ QDomElement QgsTextBackgroundSettings::writeXml( QDomDocument &doc ) const
910
951
backgroundElem.setAttribute ( QStringLiteral ( " shapeJoinStyle" ), static_cast < unsigned int >( d->joinStyle ) );
911
952
backgroundElem.setAttribute ( QStringLiteral ( " shapeOpacity" ), d->opacity );
912
953
backgroundElem.setAttribute ( QStringLiteral ( " shapeBlendMode" ), QgsPainting::getBlendModeEnum ( d->blendMode ) );
954
+ if ( d->paintEffect && !QgsPaintEffectRegistry::isDefaultStack ( d->paintEffect ) )
955
+ d->paintEffect ->saveProperties ( doc, backgroundElem );
913
956
return backgroundElem;
914
957
}
915
958
@@ -1952,7 +1995,14 @@ void QgsTextRenderer::drawBackground( QgsRenderContext &context, QgsTextRenderer
1952
1995
{
1953
1996
QgsTextBackgroundSettings background = format.background ();
1954
1997
1998
+ QPainter *prevP = context.painter ();
1955
1999
QPainter *p = context.painter ();
2000
+ if ( background.paintEffect () && background.paintEffect ()->enabled () )
2001
+ {
2002
+ background.paintEffect ()->begin ( context );
2003
+ p = context.painter ();
2004
+ }
2005
+
1956
2006
// QgsDebugMsgLevel( QString( "Background label rotation: %1" ).arg( component.rotation() ), 4 );
1957
2007
1958
2008
// shared calculations between shapes and SVG
@@ -2289,6 +2339,11 @@ void QgsTextRenderer::drawBackground( QgsRenderContext &context, QgsTextRenderer
2289
2339
p->drawPicture ( 0 , 0 , shapePict );
2290
2340
p->restore ();
2291
2341
}
2342
+ if ( background.paintEffect () && background.paintEffect ()->enabled () )
2343
+ {
2344
+ background.paintEffect ()->end ( context );
2345
+ context.setPainter ( prevP );
2346
+ }
2292
2347
}
2293
2348
2294
2349
void QgsTextRenderer::drawShadow ( QgsRenderContext &context, const QgsTextRenderer::Component &component, const QgsTextFormat &format )
0 commit comments