15
15
***************************************************************************/
16
16
17
17
#include " qgstextrenderer.h"
18
+ #include " qgis.h"
18
19
#include " qgstextrenderer_p.h"
19
20
#include " qgsfontutils.h"
20
21
#include " qgsvectorlayer.h"
21
22
#include " qgssymbollayerutils.h"
22
23
#include " qgspainting.h"
23
24
#include " qgsmarkersymbollayer.h"
25
+ #include " qgspainteffectregistry.h"
24
26
#include < QFontDatabase>
25
27
26
28
Q_GUI_EXPORT extern int qt_defaultDpiX ();
@@ -179,6 +181,17 @@ void QgsTextBufferSettings::setBlendMode( QPainter::CompositionMode mode )
179
181
d->blendMode = mode;
180
182
}
181
183
184
+ QgsPaintEffect *QgsTextBufferSettings::paintEffect () const
185
+ {
186
+ return d->paintEffect ;
187
+ }
188
+
189
+ void QgsTextBufferSettings::setPaintEffect ( QgsPaintEffect *effect )
190
+ {
191
+ delete d->paintEffect ;
192
+ d->paintEffect = effect;
193
+ }
194
+
182
195
void QgsTextBufferSettings::readFromLayer ( QgsVectorLayer *layer )
183
196
{
184
197
// text buffer
@@ -236,6 +249,16 @@ void QgsTextBufferSettings::readFromLayer( QgsVectorLayer *layer )
236
249
d->joinStyle = static_cast < Qt::PenJoinStyle >( layer->customProperty ( QStringLiteral ( " labeling/bufferJoinStyle" ), QVariant ( Qt::RoundJoin ) ).toUInt () );
237
250
238
251
d->fillBufferInterior = !layer->customProperty ( QStringLiteral ( " labeling/bufferNoFill" ), QVariant ( false ) ).toBool ();
252
+
253
+ if ( layer->customProperty ( QStringLiteral ( " labeling/bufferEffect" ) ).isValid () )
254
+ {
255
+ QDomDocument doc ( QStringLiteral ( " effect" ) );
256
+ doc.setContent ( layer->customProperty ( QStringLiteral ( " labeling/bufferEffect" ) ).toString () );
257
+ QDomElement effectElem = doc.firstChildElement ( QStringLiteral ( " effect" ) ).firstChildElement ( QStringLiteral ( " effect" ) );
258
+ setPaintEffect ( QgsApplication::paintEffectRegistry ()->createEffect ( effectElem ) );
259
+ }
260
+ else
261
+ setPaintEffect ( nullptr );
239
262
}
240
263
241
264
void QgsTextBufferSettings::writeToLayer ( QgsVectorLayer *layer ) const
@@ -249,6 +272,21 @@ void QgsTextBufferSettings::writeToLayer( QgsVectorLayer *layer ) const
249
272
layer->setCustomProperty ( QStringLiteral ( " labeling/bufferOpacity" ), d->opacity );
250
273
layer->setCustomProperty ( QStringLiteral ( " labeling/bufferJoinStyle" ), static_cast < unsigned int >( d->joinStyle ) );
251
274
layer->setCustomProperty ( QStringLiteral ( " labeling/bufferBlendMode" ), QgsPainting::getBlendModeEnum ( d->blendMode ) );
275
+
276
+ if ( d->paintEffect && !QgsPaintEffectRegistry::isDefaultStack ( d->paintEffect ) )
277
+ {
278
+ QDomDocument doc ( QStringLiteral ( " effect" ) );
279
+ QDomElement effectElem = doc.createElement ( QStringLiteral ( " effect" ) );
280
+ d->paintEffect ->saveProperties ( doc, effectElem );
281
+ QString effectProps;
282
+ QTextStream stream ( &effectProps );
283
+ effectElem.save ( stream, -1 );
284
+ layer->setCustomProperty ( QStringLiteral ( " labeling/bufferEffect" ), effectProps );
285
+ }
286
+ else
287
+ {
288
+ layer->removeCustomProperty ( QStringLiteral ( " labeling/bufferEffect" ) );
289
+ }
252
290
}
253
291
254
292
void QgsTextBufferSettings::readXml ( const QDomElement &elem )
@@ -309,6 +347,11 @@ void QgsTextBufferSettings::readXml( const QDomElement &elem )
309
347
static_cast < QgsPainting::BlendMode >( textBufferElem.attribute ( QStringLiteral ( " bufferBlendMode" ), QString::number ( QgsPainting::BlendNormal ) ).toUInt () ) );
310
348
d->joinStyle = static_cast < Qt::PenJoinStyle >( textBufferElem.attribute ( QStringLiteral ( " bufferJoinStyle" ), QString::number ( Qt::RoundJoin ) ).toUInt () );
311
349
d->fillBufferInterior = !textBufferElem.attribute ( QStringLiteral ( " bufferNoFill" ), QStringLiteral ( " 0" ) ).toInt ();
350
+ QDomElement effectElem = textBufferElem.firstChildElement ( QStringLiteral ( " effect" ) );
351
+ if ( !effectElem.isNull () )
352
+ setPaintEffect ( QgsApplication::paintEffectRegistry ()->createEffect ( effectElem ) );
353
+ else
354
+ setPaintEffect ( nullptr );
312
355
}
313
356
314
357
QDomElement QgsTextBufferSettings::writeXml ( QDomDocument &doc ) const
@@ -324,6 +367,8 @@ QDomElement QgsTextBufferSettings::writeXml( QDomDocument &doc ) const
324
367
textBufferElem.setAttribute ( QStringLiteral ( " bufferOpacity" ), d->opacity );
325
368
textBufferElem.setAttribute ( QStringLiteral ( " bufferJoinStyle" ), static_cast < unsigned int >( d->joinStyle ) );
326
369
textBufferElem.setAttribute ( QStringLiteral ( " bufferBlendMode" ), QgsPainting::getBlendModeEnum ( d->blendMode ) );
370
+ if ( d->paintEffect && !QgsPaintEffectRegistry::isDefaultStack ( d->paintEffect ) )
371
+ d->paintEffect ->saveProperties ( doc, textBufferElem );
327
372
return textBufferElem;
328
373
}
329
374
@@ -1809,9 +1854,25 @@ void QgsTextRenderer::drawBuffer( QgsRenderContext &context, const QgsTextRender
1809
1854
QPicture buffPict;
1810
1855
QPainter buffp;
1811
1856
buffp.begin ( &buffPict );
1812
- buffp.setPen ( pen );
1813
- buffp.setBrush ( tmpColor );
1814
- buffp.drawPath ( path );
1857
+
1858
+ if ( buffer.paintEffect () && buffer.paintEffect ()->enabled () )
1859
+ {
1860
+ context.setPainter ( &buffp );
1861
+
1862
+ buffer.paintEffect ()->begin ( context );
1863
+ context.painter ()->setPen ( pen );
1864
+ context.painter ()->setBrush ( tmpColor );
1865
+ context.painter ()->drawPath ( path );
1866
+ buffer.paintEffect ()->end ( context );
1867
+
1868
+ context.setPainter ( p );
1869
+ }
1870
+ else
1871
+ {
1872
+ buffp.setPen ( pen );
1873
+ buffp.setBrush ( tmpColor );
1874
+ buffp.drawPath ( path );
1875
+ }
1815
1876
buffp.end ();
1816
1877
1817
1878
if ( format.shadow ().enabled () && format.shadow ().shadowPlacement () == QgsTextShadowSettings::ShadowBuffer )
@@ -1822,7 +1883,6 @@ void QgsTextRenderer::drawBuffer( QgsRenderContext &context, const QgsTextRender
1822
1883
bufferComponent.pictureBuffer = penSize / 2.0 ;
1823
1884
drawShadow ( context, bufferComponent, format );
1824
1885
}
1825
-
1826
1886
p->save ();
1827
1887
if ( context.useAdvancedEffects () )
1828
1888
{
@@ -2562,3 +2622,4 @@ void QgsTextRenderer::drawTextInternal( TextPart drawType,
2562
2622
i++;
2563
2623
}
2564
2624
}
2625
+
0 commit comments