QGIS API Documentation 3.41.0-Master (3440c17df1d)
Loading...
Searching...
No Matches
qgstextbackgroundsettings.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgstextbackgroundsettings.cpp
3 -----------------
4 begin : May 2020
5 copyright : (C) Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
17#include "qgstextrenderer_p.h"
18#include "qgsvectorlayer.h"
19#include "qgspallabeling.h"
20#include "qgssymbollayerutils.h"
21#include "qgsfillsymbollayer.h"
22#include "qgspainting.h"
25#include "qgsapplication.h"
26#include "qgsunittypes.h"
27#include "qgscolorutils.h"
28
30{
31 d = new QgsTextBackgroundSettingsPrivate();
32
33 // Create a default fill symbol to preserve API promise until QGIS 4.0
34 QgsSimpleFillSymbolLayer *fill = new QgsSimpleFillSymbolLayer( d->fillColor, Qt::SolidPattern, d->strokeColor );
35 fill->setStrokeWidth( d->strokeWidth );
36 fill->setStrokeWidthUnit( d->strokeWidthUnits );
37 fill->setStrokeWidthMapUnitScale( d->strokeWidthMapUnitScale );
38 fill->setStrokeStyle( !qgsDoubleNear( d->strokeWidth, 0.0 ) ? Qt::SolidLine : Qt::NoPen );
39 fill->setPenJoinStyle( d->joinStyle );
40
42 fillSymbol->changeSymbolLayer( 0, fill );
44}
45
47 : d( other.d )
48{
49
50}
51
53{
54 d = other.d;
55 return *this;
56}
57
62
64{
65 if ( d->enabled != other.enabled()
66 || d->type != other.type()
67 || d->svgFile != other.svgFile()
68 || d->sizeType != other.sizeType()
69 || d->size != other.size()
70 || d->sizeUnits != other.sizeUnit()
71 || d->sizeMapUnitScale != other.sizeMapUnitScale()
72 || d->rotationType != other.rotationType()
73 || d->rotation != other.rotation()
74 || d->offset != other.offset()
75 || d->offsetUnits != other.offsetUnit()
76 || d->offsetMapUnitScale != other.offsetMapUnitScale()
77 || d->radii != other.radii()
78 || d->radiiUnits != other.radiiUnit()
79 || d->radiiMapUnitScale != other.radiiMapUnitScale()
80 || d->blendMode != other.blendMode()
81 || d->fillColor != other.fillColor()
82 || d->strokeColor != other.strokeColor()
83 || d->opacity != other.opacity()
84 || d->strokeWidth != other.strokeWidth()
85 || d->strokeWidthUnits != other.strokeWidthUnit()
86 || d->strokeWidthMapUnitScale != other.strokeWidthMapUnitScale()
87 || d->joinStyle != other.joinStyle() )
88 return false;
89
90 if ( static_cast< bool >( d->paintEffect ) != static_cast< bool >( other.paintEffect() )
91 || ( d->paintEffect && d->paintEffect->properties() != other.paintEffect()->properties() ) )
92 return false;
93
94 if ( static_cast< bool >( d->markerSymbol ) != static_cast< bool >( other.markerSymbol() )
95 || ( d->markerSymbol && QgsSymbolLayerUtils::symbolProperties( d->markerSymbol.get() ) != QgsSymbolLayerUtils::symbolProperties( other.markerSymbol() ) ) )
96 return false;
97
98 if ( static_cast< bool >( d->fillSymbol ) != static_cast< bool >( other.fillSymbol() )
99 || ( d->fillSymbol && QgsSymbolLayerUtils::symbolProperties( d->fillSymbol.get() ) != QgsSymbolLayerUtils::symbolProperties( other.fillSymbol() ) ) )
100 return false;
101
102 return true;
103}
104
106{
107 return !( *this == other );
108}
109
111{
112 return d->enabled;
113}
114
116{
117 d->enabled = enabled;
118}
119
124
129
131{
132 return d->svgFile;
133}
134
135void QgsTextBackgroundSettings::setSvgFile( const QString &file )
136{
137 d->svgFile = file;
138}
139
141{
142 return d->markerSymbol.get();
143}
144
146{
147 if ( symbol )
148 // Remove symbol layer unique id to have correct settings equality
150
151 d->markerSymbol.reset( symbol );
152}
153
155{
156 return d->fillSymbol.get();
157}
158
160{
161 if ( symbol )
162 // Remove symbol layer unique id to have correct settings equality
164
165 d->fillSymbol.reset( symbol );
166}
167
172
177
179{
180 return d->size;
181}
182
184{
185 d->size = size;
186}
187
189{
190 return d->sizeUnits;
191}
192
194{
195 d->sizeUnits = unit;
196}
197
199{
200 return d->sizeMapUnitScale;
201}
202
204{
205 d->sizeMapUnitScale = scale;
206}
207
212
217
219{
220 return d->rotation;
221}
222
224{
225 d->rotation = rotation;
226}
227
229{
230 return d->offset;
231}
232
234{
235 d->offset = offset;
236}
237
239{
240 return d->offsetUnits;
241}
242
244{
245 d->offsetUnits = units;
246}
247
249{
250 return d->offsetMapUnitScale;
251}
252
254{
255 d->offsetMapUnitScale = scale;
256}
257
259{
260 return d->radii;
261}
262
264{
265 d->radii = radii;
266}
267
269{
270 return d->radiiUnits;
271}
272
274{
275 d->radiiUnits = units;
276}
277
279{
280 return d->radiiMapUnitScale;
281}
282
284{
285 d->radiiMapUnitScale = scale;
286}
287
289{
290 return d->opacity;
291}
292
294{
295 d->opacity = opacity;
296}
297
298QPainter::CompositionMode QgsTextBackgroundSettings::blendMode() const
299{
300 return d->blendMode;
301}
302
303void QgsTextBackgroundSettings::setBlendMode( QPainter::CompositionMode mode )
304{
305 d->blendMode = mode;
306}
307
309{
310 return d->fillSymbol ? d->fillSymbol->color() : d->fillColor;
311}
312
314{
315 d->fillColor = color;
316 if ( d->fillSymbol )
317 {
318 d->fillSymbol->setColor( color );
319 }
320}
321
323{
324 if ( d->fillSymbol && d->fillSymbol->symbolLayers().at( 0 )->layerType() == QLatin1String( "SimpleFill" ) )
325 {
326 return qgis::down_cast< QgsSimpleFillSymbolLayer * >( d->fillSymbol->symbolLayers().at( 0 ) )->strokeColor();
327 }
328 return d->strokeColor;
329}
330
332{
333 d->strokeColor = color;
334 if ( d->fillSymbol && d->fillSymbol->symbolLayers().at( 0 )->layerType() == QLatin1String( "SimpleFill" ) )
335 {
336 qgis::down_cast< QgsSimpleFillSymbolLayer * >( d->fillSymbol->symbolLayers().at( 0 ) )->setStrokeColor( color );
337 }
338}
339
341{
342 if ( d->fillSymbol && d->fillSymbol->symbolLayers().at( 0 )->layerType() == QLatin1String( "SimpleFill" ) )
343 {
344 return qgis::down_cast< QgsSimpleFillSymbolLayer * >( d->fillSymbol->symbolLayers().at( 0 ) )->strokeWidth();
345 }
346 return d->strokeWidth;
347}
348
350{
351 d->strokeWidth = width;
352 if ( d->fillSymbol && d->fillSymbol->symbolLayers().at( 0 )->layerType() == QLatin1String( "SimpleFill" ) )
353 {
354 QgsSimpleFillSymbolLayer *fill = qgis::down_cast< QgsSimpleFillSymbolLayer * >( d->fillSymbol->symbolLayers().at( 0 ) );
355 fill->setStrokeWidth( width );
356 fill->setStrokeStyle( !qgsDoubleNear( width, 0.0 ) ? Qt::SolidLine : Qt::NoPen );
357 }
358}
359
361{
362 if ( d->fillSymbol && d->fillSymbol->symbolLayers().at( 0 )->layerType() == QLatin1String( "SimpleFill" ) )
363 {
364 return qgis::down_cast< QgsSimpleFillSymbolLayer * >( d->fillSymbol->symbolLayers().at( 0 ) )->strokeWidthUnit();
365 }
366 return d->strokeWidthUnits;
367}
368
370{
371 d->strokeWidthUnits = units;
372 if ( d->fillSymbol && d->fillSymbol->symbolLayers().at( 0 )->layerType() == QLatin1String( "SimpleFill" ) )
373 {
374 qgis::down_cast< QgsSimpleFillSymbolLayer * >( d->fillSymbol->symbolLayers().at( 0 ) )->setStrokeWidthUnit( units );
375 }
376}
377
379{
380 if ( d->fillSymbol && d->fillSymbol->symbolLayers().at( 0 )->layerType() == QLatin1String( "SimpleFill" ) )
381 {
382 return qgis::down_cast< QgsSimpleFillSymbolLayer * >( d->fillSymbol->symbolLayers().at( 0 ) )->strokeWidthMapUnitScale();
383 }
384 return d->strokeWidthMapUnitScale;
385}
386
388{
389 d->strokeWidthMapUnitScale = scale;
390 if ( d->fillSymbol && d->fillSymbol->symbolLayers().at( 0 )->layerType() == QLatin1String( "SimpleFill" ) )
391 {
392 qgis::down_cast< QgsSimpleFillSymbolLayer * >( d->fillSymbol->symbolLayers().at( 0 ) )->setStrokeWidthMapUnitScale( scale );
393 }
394}
395
397{
398 if ( d->fillSymbol && d->fillSymbol->symbolLayers().at( 0 )->layerType() == QLatin1String( "SimpleFill" ) )
399 {
400 return qgis::down_cast< QgsSimpleFillSymbolLayer * >( d->fillSymbol->symbolLayers().at( 0 ) )->penJoinStyle();
401 }
402 return d->joinStyle;
403}
404
405void QgsTextBackgroundSettings::setJoinStyle( Qt::PenJoinStyle style )
406{
407 d->joinStyle = style;
408 if ( d->fillSymbol && d->fillSymbol->symbolLayers().at( 0 )->layerType() == QLatin1String( "SimpleFill" ) )
409 {
410 qgis::down_cast< QgsSimpleFillSymbolLayer * >( d->fillSymbol->symbolLayers().at( 0 ) )->setPenJoinStyle( style );
411 }
412}
413
415{
416 return d->paintEffect.get();
417}
418
420{
421 d->paintEffect.reset( effect );
422}
423
425{
426 d->enabled = layer->customProperty( QStringLiteral( "labeling/shapeDraw" ), QVariant( false ) ).toBool();
427 d->type = static_cast< ShapeType >( layer->customProperty( QStringLiteral( "labeling/shapeType" ), QVariant( ShapeRectangle ) ).toUInt() );
428 d->svgFile = layer->customProperty( QStringLiteral( "labeling/shapeSVGFile" ), QVariant( "" ) ).toString();
429 d->sizeType = static_cast< SizeType >( layer->customProperty( QStringLiteral( "labeling/shapeSizeType" ), QVariant( SizeBuffer ) ).toUInt() );
430 d->size = QSizeF( layer->customProperty( QStringLiteral( "labeling/shapeSizeX" ), QVariant( 0.0 ) ).toDouble(),
431 layer->customProperty( QStringLiteral( "labeling/shapeSizeY" ), QVariant( 0.0 ) ).toDouble() );
432
433 if ( layer->customProperty( QStringLiteral( "labeling/shapeSizeUnit" ) ).toString().isEmpty() )
434 {
435 d->sizeUnits = QgsTextRendererUtils::convertFromOldLabelUnit( layer->customProperty( QStringLiteral( "labeling/shapeSizeUnits" ), 0 ).toUInt() );
436 }
437 else
438 {
439 d->sizeUnits = QgsUnitTypes::decodeRenderUnit( layer->customProperty( QStringLiteral( "labeling/shapeSizeUnit" ) ).toString() );
440 }
441
442 if ( layer->customProperty( QStringLiteral( "labeling/shapeSizeMapUnitScale" ) ).toString().isEmpty() )
443 {
444 //fallback to older property
445 const double oldMin = layer->customProperty( QStringLiteral( "labeling/shapeSizeMapUnitMinScale" ), 0.0 ).toDouble();
446 d->sizeMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
447 const double oldMax = layer->customProperty( QStringLiteral( "labeling/shapeSizeMapUnitMaxScale" ), 0.0 ).toDouble();
448 d->sizeMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
449 }
450 else
451 {
452 d->sizeMapUnitScale = QgsSymbolLayerUtils::decodeMapUnitScale( layer->customProperty( QStringLiteral( "labeling/shapeSizeMapUnitScale" ) ).toString() );
453 }
454 d->rotationType = static_cast< RotationType >( layer->customProperty( QStringLiteral( "labeling/shapeRotationType" ), QVariant( RotationSync ) ).toUInt() );
455 d->rotation = layer->customProperty( QStringLiteral( "labeling/shapeRotation" ), QVariant( 0.0 ) ).toDouble();
456 d->offset = QPointF( layer->customProperty( QStringLiteral( "labeling/shapeOffsetX" ), QVariant( 0.0 ) ).toDouble(),
457 layer->customProperty( QStringLiteral( "labeling/shapeOffsetY" ), QVariant( 0.0 ) ).toDouble() );
458
459 if ( layer->customProperty( QStringLiteral( "labeling/shapeOffsetUnit" ) ).toString().isEmpty() )
460 {
461 d->offsetUnits = QgsTextRendererUtils::convertFromOldLabelUnit( layer->customProperty( QStringLiteral( "labeling/shapeOffsetUnits" ), 0 ).toUInt() );
462 }
463 else
464 {
465 d->offsetUnits = QgsUnitTypes::decodeRenderUnit( layer->customProperty( QStringLiteral( "labeling/shapeOffsetUnit" ) ).toString() );
466 }
467
468 if ( layer->customProperty( QStringLiteral( "labeling/shapeOffsetMapUnitScale" ) ).toString().isEmpty() )
469 {
470 //fallback to older property
471 const double oldMin = layer->customProperty( QStringLiteral( "labeling/shapeOffsetMapUnitMinScale" ), 0.0 ).toDouble();
472 d->offsetMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
473 const double oldMax = layer->customProperty( QStringLiteral( "labeling/shapeOffsetMapUnitMaxScale" ), 0.0 ).toDouble();
474 d->offsetMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
475 }
476 else
477 {
478 d->offsetMapUnitScale = QgsSymbolLayerUtils::decodeMapUnitScale( layer->customProperty( QStringLiteral( "labeling/shapeOffsetMapUnitScale" ) ).toString() );
479 }
480 d->radii = QSizeF( layer->customProperty( QStringLiteral( "labeling/shapeRadiiX" ), QVariant( 0.0 ) ).toDouble(),
481 layer->customProperty( QStringLiteral( "labeling/shapeRadiiY" ), QVariant( 0.0 ) ).toDouble() );
482
483
484 if ( layer->customProperty( QStringLiteral( "labeling/shapeRadiiUnit" ) ).toString().isEmpty() )
485 {
486 d->radiiUnits = QgsTextRendererUtils::convertFromOldLabelUnit( layer->customProperty( QStringLiteral( "labeling/shapeRadiiUnits" ), 0 ).toUInt() );
487 }
488 else
489 {
490 d->radiiUnits = QgsUnitTypes::decodeRenderUnit( layer->customProperty( QStringLiteral( "labeling/shapeRadiiUnit" ) ).toString() );
491 }
492
493 if ( layer->customProperty( QStringLiteral( "labeling/shapeRadiiMapUnitScale" ) ).toString().isEmpty() )
494 {
495 //fallback to older property
496 const double oldMin = layer->customProperty( QStringLiteral( "labeling/shapeRadiiMapUnitMinScale" ), 0.0 ).toDouble();
497 d->radiiMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
498 const double oldMax = layer->customProperty( QStringLiteral( "labeling/shapeRadiiMapUnitMaxScale" ), 0.0 ).toDouble();
499 d->radiiMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
500 }
501 else
502 {
503 d->radiiMapUnitScale = QgsSymbolLayerUtils::decodeMapUnitScale( layer->customProperty( QStringLiteral( "labeling/shapeRadiiMapUnitScale" ) ).toString() );
504 }
505 d->fillColor = QgsTextRendererUtils::readColor( layer, QStringLiteral( "labeling/shapeFillColor" ), Qt::white, true );
506 d->strokeColor = QgsTextRendererUtils::readColor( layer, QStringLiteral( "labeling/shapeBorderColor" ), Qt::darkGray, true );
507 d->strokeWidth = layer->customProperty( QStringLiteral( "labeling/shapeBorderWidth" ), QVariant( .0 ) ).toDouble();
508 if ( layer->customProperty( QStringLiteral( "labeling/shapeBorderWidthUnit" ) ).toString().isEmpty() )
509 {
510 d->strokeWidthUnits = QgsTextRendererUtils::convertFromOldLabelUnit( layer->customProperty( QStringLiteral( "labeling/shapeBorderWidthUnits" ), 0 ).toUInt() );
511 }
512 else
513 {
514 d->strokeWidthUnits = QgsUnitTypes::decodeRenderUnit( layer->customProperty( QStringLiteral( "labeling/shapeBorderWidthUnit" ) ).toString() );
515 }
516 if ( layer->customProperty( QStringLiteral( "labeling/shapeBorderWidthMapUnitScale" ) ).toString().isEmpty() )
517 {
518 //fallback to older property
519 const double oldMin = layer->customProperty( QStringLiteral( "labeling/shapeBorderWidthMapUnitMinScale" ), 0.0 ).toDouble();
520 d->strokeWidthMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
521 const double oldMax = layer->customProperty( QStringLiteral( "labeling/shapeBorderWidthMapUnitMaxScale" ), 0.0 ).toDouble();
522 d->strokeWidthMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
523 }
524 else
525 {
526 d->strokeWidthMapUnitScale = QgsSymbolLayerUtils::decodeMapUnitScale( layer->customProperty( QStringLiteral( "labeling/shapeBorderWidthMapUnitScale" ) ).toString() );
527 }
528 d->joinStyle = static_cast< Qt::PenJoinStyle >( layer->customProperty( QStringLiteral( "labeling/shapeJoinStyle" ), QVariant( Qt::BevelJoin ) ).toUInt() );
529
530 if ( layer->customProperty( QStringLiteral( "labeling/shapeOpacity" ) ).toString().isEmpty() )
531 {
532 d->opacity = ( 1 - layer->customProperty( QStringLiteral( "labeling/shapeTransparency" ) ).toInt() / 100.0 ); //0 -100
533 }
534 else
535 {
536 d->opacity = ( layer->customProperty( QStringLiteral( "labeling/shapeOpacity" ) ).toDouble() );
537 }
538 d->blendMode = QgsPainting::getCompositionMode(
539 static_cast< Qgis::BlendMode >( layer->customProperty( QStringLiteral( "labeling/shapeBlendMode" ), QVariant( static_cast< int>( Qgis::BlendMode::Normal ) ) ).toUInt() ) );
540
541 if ( layer->customProperty( QStringLiteral( "labeling/shapeEffect" ) ).isValid() )
542 {
543 QDomDocument doc( QStringLiteral( "effect" ) );
544 doc.setContent( layer->customProperty( QStringLiteral( "labeling/shapeEffect" ) ).toString() );
545 const QDomElement effectElem = doc.firstChildElement( QStringLiteral( "effect" ) ).firstChildElement( QStringLiteral( "effect" ) );
546 setPaintEffect( QgsApplication::paintEffectRegistry()->createEffect( effectElem ) );
547 }
548 else
549 setPaintEffect( nullptr );
550}
551
552void QgsTextBackgroundSettings::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
553{
554 const QDomElement backgroundElem = elem.firstChildElement( QStringLiteral( "background" ) );
555 d->enabled = backgroundElem.attribute( QStringLiteral( "shapeDraw" ), QStringLiteral( "0" ) ).toInt();
556 d->type = static_cast< ShapeType >( backgroundElem.attribute( QStringLiteral( "shapeType" ), QString::number( ShapeRectangle ) ).toUInt() );
557 d->svgFile = QgsSymbolLayerUtils::svgSymbolNameToPath( backgroundElem.attribute( QStringLiteral( "shapeSVGFile" ) ), context.pathResolver() );
558 d->sizeType = static_cast< SizeType >( backgroundElem.attribute( QStringLiteral( "shapeSizeType" ), QString::number( SizeBuffer ) ).toUInt() );
559 d->size = QSizeF( backgroundElem.attribute( QStringLiteral( "shapeSizeX" ), QStringLiteral( "0" ) ).toDouble(),
560 backgroundElem.attribute( QStringLiteral( "shapeSizeY" ), QStringLiteral( "0" ) ).toDouble() );
561
562 if ( !backgroundElem.hasAttribute( QStringLiteral( "shapeSizeUnit" ) ) )
563 {
564 d->sizeUnits = QgsTextRendererUtils::convertFromOldLabelUnit( backgroundElem.attribute( QStringLiteral( "shapeSizeUnits" ) ).toUInt() );
565 }
566 else
567 {
568 d->sizeUnits = QgsUnitTypes::decodeRenderUnit( backgroundElem.attribute( QStringLiteral( "shapeSizeUnit" ) ) );
569 }
570
571 if ( !backgroundElem.hasAttribute( QStringLiteral( "shapeSizeMapUnitScale" ) ) )
572 {
573 //fallback to older property
574 const double oldMin = backgroundElem.attribute( QStringLiteral( "shapeSizeMapUnitMinScale" ), QStringLiteral( "0" ) ).toDouble();
575 d->sizeMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
576 const double oldMax = backgroundElem.attribute( QStringLiteral( "shapeSizeMapUnitMaxScale" ), QStringLiteral( "0" ) ).toDouble();
577 d->sizeMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
578 }
579 else
580 {
581 d->sizeMapUnitScale = QgsSymbolLayerUtils::decodeMapUnitScale( backgroundElem.attribute( QStringLiteral( "shapeSizeMapUnitScale" ) ) );
582 }
583 d->rotationType = static_cast< RotationType >( backgroundElem.attribute( QStringLiteral( "shapeRotationType" ), QString::number( RotationSync ) ).toUInt() );
584 d->rotation = backgroundElem.attribute( QStringLiteral( "shapeRotation" ), QStringLiteral( "0" ) ).toDouble();
585 d->offset = QPointF( backgroundElem.attribute( QStringLiteral( "shapeOffsetX" ), QStringLiteral( "0" ) ).toDouble(),
586 backgroundElem.attribute( QStringLiteral( "shapeOffsetY" ), QStringLiteral( "0" ) ).toDouble() );
587
588 if ( !backgroundElem.hasAttribute( QStringLiteral( "shapeOffsetUnit" ) ) )
589 {
590 d->offsetUnits = QgsTextRendererUtils::convertFromOldLabelUnit( backgroundElem.attribute( QStringLiteral( "shapeOffsetUnits" ) ).toUInt() );
591 }
592 else
593 {
594 d->offsetUnits = QgsUnitTypes::decodeRenderUnit( backgroundElem.attribute( QStringLiteral( "shapeOffsetUnit" ) ) );
595 }
596
597 if ( !backgroundElem.hasAttribute( QStringLiteral( "shapeOffsetMapUnitScale" ) ) )
598 {
599 //fallback to older property
600 const double oldMin = backgroundElem.attribute( QStringLiteral( "shapeOffsetMapUnitMinScale" ), QStringLiteral( "0" ) ).toDouble();
601 d->offsetMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
602 const double oldMax = backgroundElem.attribute( QStringLiteral( "shapeOffsetMapUnitMaxScale" ), QStringLiteral( "0" ) ).toDouble();
603 d->offsetMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
604 }
605 else
606 {
607 d->offsetMapUnitScale = QgsSymbolLayerUtils::decodeMapUnitScale( backgroundElem.attribute( QStringLiteral( "shapeOffsetMapUnitScale" ) ) );
608 }
609 d->radii = QSizeF( backgroundElem.attribute( QStringLiteral( "shapeRadiiX" ), QStringLiteral( "0" ) ).toDouble(),
610 backgroundElem.attribute( QStringLiteral( "shapeRadiiY" ), QStringLiteral( "0" ) ).toDouble() );
611
612 if ( !backgroundElem.hasAttribute( QStringLiteral( "shapeRadiiUnit" ) ) )
613 {
614 d->radiiUnits = QgsTextRendererUtils::convertFromOldLabelUnit( backgroundElem.attribute( QStringLiteral( "shapeRadiiUnits" ) ).toUInt() );
615 }
616 else
617 {
618 d->radiiUnits = QgsUnitTypes::decodeRenderUnit( backgroundElem.attribute( QStringLiteral( "shapeRadiiUnit" ) ) );
619 }
620 if ( !backgroundElem.hasAttribute( QStringLiteral( "shapeRadiiMapUnitScale" ) ) )
621 {
622 //fallback to older property
623 const double oldMin = backgroundElem.attribute( QStringLiteral( "shapeRadiiMapUnitMinScale" ), QStringLiteral( "0" ) ).toDouble();
624 d->radiiMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
625 const double oldMax = backgroundElem.attribute( QStringLiteral( "shapeRadiiMapUnitMaxScale" ), QStringLiteral( "0" ) ).toDouble();
626 d->radiiMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
627 }
628 else
629 {
630 d->radiiMapUnitScale = QgsSymbolLayerUtils::decodeMapUnitScale( backgroundElem.attribute( QStringLiteral( "shapeRadiiMapUnitScale" ) ) );
631 }
632 d->fillColor = QgsColorUtils::colorFromString( backgroundElem.attribute( QStringLiteral( "shapeFillColor" ), QgsColorUtils::colorToString( Qt::white ) ) );
633 d->strokeColor = QgsColorUtils::colorFromString( backgroundElem.attribute( QStringLiteral( "shapeBorderColor" ), QgsColorUtils::colorToString( Qt::darkGray ) ) );
634 d->strokeWidth = backgroundElem.attribute( QStringLiteral( "shapeBorderWidth" ), QStringLiteral( "0" ) ).toDouble();
635
636 if ( !backgroundElem.hasAttribute( QStringLiteral( "shapeBorderWidthUnit" ) ) )
637 {
638 d->strokeWidthUnits = QgsTextRendererUtils::convertFromOldLabelUnit( backgroundElem.attribute( QStringLiteral( "shapeBorderWidthUnits" ) ).toUInt() );
639 }
640 else
641 {
642 d->strokeWidthUnits = QgsUnitTypes::decodeRenderUnit( backgroundElem.attribute( QStringLiteral( "shapeBorderWidthUnit" ) ) );
643 }
644 if ( !backgroundElem.hasAttribute( QStringLiteral( "shapeBorderWidthMapUnitScale" ) ) )
645 {
646 //fallback to older property
647 const double oldMin = backgroundElem.attribute( QStringLiteral( "shapeBorderWidthMapUnitMinScale" ), QStringLiteral( "0" ) ).toDouble();
648 d->strokeWidthMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
649 const double oldMax = backgroundElem.attribute( QStringLiteral( "shapeBorderWidthMapUnitMaxScale" ), QStringLiteral( "0" ) ).toDouble();
650 d->strokeWidthMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
651 }
652 else
653 {
654 d->strokeWidthMapUnitScale = QgsSymbolLayerUtils::decodeMapUnitScale( backgroundElem.attribute( QStringLiteral( "shapeBorderWidthMapUnitScale" ) ) );
655 }
656 d->joinStyle = static_cast< Qt::PenJoinStyle >( backgroundElem.attribute( QStringLiteral( "shapeJoinStyle" ), QString::number( Qt::BevelJoin ) ).toUInt() );
657
658 if ( !backgroundElem.hasAttribute( QStringLiteral( "shapeOpacity" ) ) )
659 {
660 d->opacity = ( 1 - backgroundElem.attribute( QStringLiteral( "shapeTransparency" ) ).toInt() / 100.0 ); //0 -100
661 }
662 else
663 {
664 d->opacity = ( backgroundElem.attribute( QStringLiteral( "shapeOpacity" ) ).toDouble() );
665 }
666
667 d->blendMode = QgsPainting::getCompositionMode(
668 static_cast< Qgis::BlendMode >( backgroundElem.attribute( QStringLiteral( "shapeBlendMode" ), QString::number( static_cast< int >( Qgis::BlendMode::Normal ) ) ).toUInt() ) );
669
670 const QDomElement effectElem = backgroundElem.firstChildElement( QStringLiteral( "effect" ) );
671 if ( !effectElem.isNull() )
672 setPaintEffect( QgsApplication::paintEffectRegistry()->createEffect( effectElem ) );
673 else
674 setPaintEffect( nullptr );
675
676 setMarkerSymbol( nullptr );
677 setFillSymbol( nullptr );
678 const QDomNodeList symbols = backgroundElem.elementsByTagName( QStringLiteral( "symbol" ) );
679 for ( int i = 0; i < symbols.size(); ++i )
680 {
681 if ( symbols.at( i ).isElement() )
682 {
683 const QDomElement symbolElement = symbols.at( i ).toElement();
684 const QString symbolElementName = symbolElement.attribute( QStringLiteral( "name" ) );
685 if ( symbolElementName == QLatin1String( "markerSymbol" ) )
686 {
687 setMarkerSymbol( QgsSymbolLayerUtils::loadSymbol< QgsMarkerSymbol >( symbolElement, context ) );
688 }
689 else if ( symbolElementName == QLatin1String( "fillSymbol" ) )
690 {
691 setFillSymbol( QgsSymbolLayerUtils::loadSymbol< QgsFillSymbol >( symbolElement, context ) );
692 }
693 }
694 }
695
696 if ( !d->fillSymbol )
697 {
698 QgsSimpleFillSymbolLayer *fill = new QgsSimpleFillSymbolLayer( d->fillColor, Qt::SolidPattern, d->strokeColor );
699 fill->setStrokeWidth( d->strokeWidth );
700 fill->setStrokeWidthUnit( d->strokeWidthUnits );
701 fill->setStrokeWidthMapUnitScale( d->strokeWidthMapUnitScale );
702 fill->setStrokeStyle( !qgsDoubleNear( d->strokeWidth, 0.0 ) ? Qt::SolidLine : Qt::NoPen );
703 fill->setPenJoinStyle( d->joinStyle );
704
706 fillSymbol->changeSymbolLayer( 0, fill );
708 }
709}
710
711QDomElement QgsTextBackgroundSettings::writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const
712{
713 QDomElement backgroundElem = doc.createElement( QStringLiteral( "background" ) );
714 backgroundElem.setAttribute( QStringLiteral( "shapeDraw" ), d->enabled );
715 backgroundElem.setAttribute( QStringLiteral( "shapeType" ), static_cast< unsigned int >( d->type ) );
716 backgroundElem.setAttribute( QStringLiteral( "shapeSVGFile" ), QgsSymbolLayerUtils::svgSymbolPathToName( d->svgFile, context.pathResolver() ) );
717 backgroundElem.setAttribute( QStringLiteral( "shapeSizeType" ), static_cast< unsigned int >( d->sizeType ) );
718 backgroundElem.setAttribute( QStringLiteral( "shapeSizeX" ), d->size.width() );
719 backgroundElem.setAttribute( QStringLiteral( "shapeSizeY" ), d->size.height() );
720 backgroundElem.setAttribute( QStringLiteral( "shapeSizeUnit" ), QgsUnitTypes::encodeUnit( d->sizeUnits ) );
721 backgroundElem.setAttribute( QStringLiteral( "shapeSizeMapUnitScale" ), QgsSymbolLayerUtils::encodeMapUnitScale( d->sizeMapUnitScale ) );
722 backgroundElem.setAttribute( QStringLiteral( "shapeRotationType" ), static_cast< unsigned int >( d->rotationType ) );
723 backgroundElem.setAttribute( QStringLiteral( "shapeRotation" ), d->rotation );
724 backgroundElem.setAttribute( QStringLiteral( "shapeOffsetX" ), d->offset.x() );
725 backgroundElem.setAttribute( QStringLiteral( "shapeOffsetY" ), d->offset.y() );
726 backgroundElem.setAttribute( QStringLiteral( "shapeOffsetUnit" ), QgsUnitTypes::encodeUnit( d->offsetUnits ) );
727 backgroundElem.setAttribute( QStringLiteral( "shapeOffsetMapUnitScale" ), QgsSymbolLayerUtils::encodeMapUnitScale( d->offsetMapUnitScale ) );
728 backgroundElem.setAttribute( QStringLiteral( "shapeRadiiX" ), d->radii.width() );
729 backgroundElem.setAttribute( QStringLiteral( "shapeRadiiY" ), d->radii.height() );
730 backgroundElem.setAttribute( QStringLiteral( "shapeRadiiUnit" ), QgsUnitTypes::encodeUnit( d->radiiUnits ) );
731 backgroundElem.setAttribute( QStringLiteral( "shapeRadiiMapUnitScale" ), QgsSymbolLayerUtils::encodeMapUnitScale( d->radiiMapUnitScale ) );
732 backgroundElem.setAttribute( QStringLiteral( "shapeFillColor" ), QgsColorUtils::colorToString( d->fillColor ) );
733 backgroundElem.setAttribute( QStringLiteral( "shapeBorderColor" ), QgsColorUtils::colorToString( d->strokeColor ) );
734 backgroundElem.setAttribute( QStringLiteral( "shapeBorderWidth" ), d->strokeWidth );
735 backgroundElem.setAttribute( QStringLiteral( "shapeBorderWidthUnit" ), QgsUnitTypes::encodeUnit( d->strokeWidthUnits ) );
736 backgroundElem.setAttribute( QStringLiteral( "shapeBorderWidthMapUnitScale" ), QgsSymbolLayerUtils::encodeMapUnitScale( d->strokeWidthMapUnitScale ) );
737 backgroundElem.setAttribute( QStringLiteral( "shapeJoinStyle" ), static_cast< unsigned int >( d->joinStyle ) );
738 backgroundElem.setAttribute( QStringLiteral( "shapeOpacity" ), d->opacity );
739 backgroundElem.setAttribute( QStringLiteral( "shapeBlendMode" ), static_cast< int >( QgsPainting::getBlendModeEnum( d->blendMode ) ) );
740 if ( d->paintEffect && !QgsPaintEffectRegistry::isDefaultStack( d->paintEffect.get() ) )
741 d->paintEffect->saveProperties( doc, backgroundElem );
742
743 if ( d->markerSymbol )
744 backgroundElem.appendChild( QgsSymbolLayerUtils::saveSymbol( QStringLiteral( "markerSymbol" ), d->markerSymbol.get(), doc, context ) );
745
746 if ( d->fillSymbol )
747 backgroundElem.appendChild( QgsSymbolLayerUtils::saveSymbol( QStringLiteral( "fillSymbol" ), d->fillSymbol.get(), doc, context ) );
748
749 return backgroundElem;
750}
751
753{
754 if ( !d->fillSymbol || d->fillSymbol->symbolLayers().at( 0 )->layerType() != QLatin1String( "SimpleFill" ) )
755 return;
756 QgsSimpleFillSymbolLayer *fill = qgis::down_cast< QgsSimpleFillSymbolLayer * >( d->fillSymbol->symbolLayers().at( 0 ) );
757
759 {
762 {
765 }
766
769 {
772 }
773
776 {
779 }
780
783 {
786 }
787 }
788}
789
791{
793 {
794 context.expressionContext().setOriginalValueVariable( d->enabled );
795 d->enabled = properties.valueAsBool( QgsPalLayerSettings::Property::ShapeDraw, context.expressionContext(), d->enabled );
796 }
797
799 {
800 context.expressionContext().setOriginalValueVariable( d->size.width() );
801 d->size.setWidth( properties.valueAsDouble( QgsPalLayerSettings::Property::ShapeSizeX, context.expressionContext(), d->size.width() ) );
802 }
804 {
805 context.expressionContext().setOriginalValueVariable( d->size.height() );
806 d->size.setHeight( properties.valueAsDouble( QgsPalLayerSettings::Property::ShapeSizeY, context.expressionContext(), d->size.height() ) );
807 }
808
809 QVariant exprVal = properties.value( QgsPalLayerSettings::Property::ShapeSizeUnits, context.expressionContext() );
810 if ( !QgsVariantUtils::isNull( exprVal ) )
811 {
812 const QString units = exprVal.toString();
813 if ( !units.isEmpty() )
814 {
815 bool ok;
816 const Qgis::RenderUnit res = QgsUnitTypes::decodeRenderUnit( units, &ok );
817 if ( ok )
818 d->sizeUnits = res;
819 }
820 }
821
822 exprVal = properties.value( QgsPalLayerSettings::Property::ShapeKind, context.expressionContext() );
823 if ( !QgsVariantUtils::isNull( exprVal ) )
824 {
825 const QString skind = exprVal.toString().trimmed();
826 if ( !skind.isEmpty() )
827 {
828 d->type = QgsTextRendererUtils::decodeShapeType( skind );
829 }
830 }
831
833 if ( !QgsVariantUtils::isNull( exprVal ) )
834 {
835 const QString stype = exprVal.toString().trimmed();
836 if ( !stype.isEmpty() )
837 {
839 }
840 }
841
842 // data defined shape SVG path?
843 context.expressionContext().setOriginalValueVariable( d->svgFile );
845 if ( !QgsVariantUtils::isNull( exprVal ) )
846 {
847 const QString svgfile = exprVal.toString().trimmed();
848 d->svgFile = QgsSymbolLayerUtils::svgSymbolNameToPath( svgfile, context.pathResolver() );
849 }
850
852 {
853 context.expressionContext().setOriginalValueVariable( d->rotation );
854 d->rotation = properties.valueAsDouble( QgsPalLayerSettings::Property::ShapeRotation, context.expressionContext(), d->rotation );
855 }
857 if ( !QgsVariantUtils::isNull( exprVal ) )
858 {
859 const QString rotstr = exprVal.toString().trimmed();
860 if ( !rotstr.isEmpty() )
861 {
862 d->rotationType = QgsTextRendererUtils::decodeBackgroundRotationType( rotstr );
863 }
864 }
865
866 exprVal = properties.value( QgsPalLayerSettings::Property::ShapeOffset, context.expressionContext() );
867 if ( !QgsVariantUtils::isNull( exprVal ) )
868 {
869 bool ok = false;
870 const QPointF res = QgsSymbolLayerUtils::toPoint( exprVal, &ok );
871 if ( ok )
872 {
873 d->offset = res;
874 }
875 }
877 if ( !QgsVariantUtils::isNull( exprVal ) )
878 {
879 const QString units = exprVal.toString();
880 if ( !units.isEmpty() )
881 {
882 bool ok;
883 const Qgis::RenderUnit res = QgsUnitTypes::decodeRenderUnit( units, &ok );
884 if ( ok )
885 d->offsetUnits = res;
886 }
887 }
888
889 exprVal = properties.value( QgsPalLayerSettings::Property::ShapeRadii, context.expressionContext() );
890 if ( !QgsVariantUtils::isNull( exprVal ) )
891 {
892 bool ok = false;
893 const QSizeF res = QgsSymbolLayerUtils::toSize( exprVal, &ok );
894 if ( ok )
895 {
896 d->radii = res;
897 }
898 }
899
901 if ( !QgsVariantUtils::isNull( exprVal ) )
902 {
903 const QString units = exprVal.toString();
904 if ( !units.isEmpty() )
905 {
906 bool ok;
907 const Qgis::RenderUnit res = QgsUnitTypes::decodeRenderUnit( units, &ok );
908 if ( ok )
909 d->radiiUnits = res;
910 }
911 }
912
914 {
915 context.expressionContext().setOriginalValueVariable( d->opacity * 100 );
916 const QVariant val = properties.value( QgsPalLayerSettings::Property::ShapeOpacity, context.expressionContext(), d->opacity * 100 );
917 if ( !QgsVariantUtils::isNull( val ) )
918 {
919 d->opacity = val.toDouble() / 100.0;
920 }
921 }
922
923 // for non-SVG background types, using data defined properties within the fill symbol is preferable
925 {
928 }
930 {
933 }
934
936 {
937 context.expressionContext().setOriginalValueVariable( d->strokeWidth );
939 }
941 if ( !QgsVariantUtils::isNull( exprVal ) )
942 {
943 const QString units = exprVal.toString();
944 if ( !units.isEmpty() )
945 {
946 bool ok;
947 const Qgis::RenderUnit res = QgsUnitTypes::decodeRenderUnit( units, &ok );
948 if ( ok )
949 setStrokeWidthUnit( res );
950 }
951 }
952
954 {
956 const QString blendstr = exprVal.toString().trimmed();
957 if ( !blendstr.isEmpty() )
958 d->blendMode = QgsSymbolLayerUtils::decodeBlendMode( blendstr );
959 }
960
962 {
964 const QString joinstr = exprVal.toString().trimmed();
965 if ( !joinstr.isEmpty() )
966 {
968 }
969 }
970}
971
973{
974 QSet< QString > fields;
975 if ( d->markerSymbol )
976 {
977 fields.unite( d->markerSymbol->usedAttributes( context ) );
978 }
979 if ( d->fillSymbol )
980 {
981 fields.unite( d->fillSymbol->usedAttributes( context ) );
982 }
983 return fields;
984}
BlendMode
Blending modes defining the available composition modes that can be used when painting.
Definition qgis.h:4594
RenderUnit
Rendering size units.
Definition qgis.h:4847
QColor valueAsColor(int key, const QgsExpressionContext &context, const QColor &defaultColor=QColor(), bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as a color.
bool valueAsBool(int key, const QgsExpressionContext &context, bool defaultValue=false, bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as an boolean.
double valueAsDouble(int key, const QgsExpressionContext &context, double defaultValue=0.0, bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as a double.
static QgsPaintEffectRegistry * paintEffectRegistry()
Returns the application's paint effect registry, used for managing paint effects.
static QColor colorFromString(const QString &string)
Decodes a string into a color value.
static QString colorToString(const QColor &color)
Encodes a color into a string value.
void setOriginalValueVariable(const QVariant &value)
Sets the original value variable value for the context.
A fill symbol type, for rendering Polygon and MultiPolygon geometries.
Q_INVOKABLE QVariant customProperty(const QString &value, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.
Struct for storing maximum and minimum scales for measurements in map units.
A marker symbol type, for rendering Point and MultiPoint geometries.
static bool isDefaultStack(QgsPaintEffect *effect)
Tests whether a paint effect matches the default effects stack.
Base class for visual effects which can be applied to QPicture drawings.
virtual QVariantMap properties() const =0
Returns the properties describing the paint effect encoded in a string format.
static Qgis::BlendMode getBlendModeEnum(QPainter::CompositionMode blendMode)
Returns a Qgis::BlendMode corresponding to a QPainter::CompositionMode.
static QPainter::CompositionMode getCompositionMode(Qgis::BlendMode blendMode)
Returns a QPainter::CompositionMode corresponding to a Qgis::BlendMode.
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
QVariant value(int key, const QgsExpressionContext &context, const QVariant &defaultValue=QVariant()) const final
Returns the calculated value of the property with the specified key from within the collection.
bool hasProperty(int key) const final
Returns true if the collection contains a property with the specified key.
void setProperty(int key, const QgsProperty &property)
Adds a property to the collection and takes ownership of it.
bool isActive(int key) const final
Returns true if the collection contains an active property with the specified key.
QgsProperty property(int key) const final
Returns a matching property from the collection, if one exists.
A store for object properties.
The class is used as a container of context for various read/write operations on other objects.
const QgsPathResolver & pathResolver() const
Returns path resolver for conversion between relative and absolute paths.
Contains information about the context of a rendering operation.
QgsExpressionContext & expressionContext()
Gets the expression context.
const QgsPathResolver & pathResolver() const
Returns the path resolver for conversion between relative and absolute paths during rendering operati...
Renders polygons using a single fill and stroke color.
void setStrokeWidthMapUnitScale(const QgsMapUnitScale &scale)
void setStrokeWidthUnit(Qgis::RenderUnit unit)
Sets the units for the width of the fill's stroke.
void setPenJoinStyle(Qt::PenJoinStyle style)
void setStrokeWidth(double strokeWidth)
void setStrokeStyle(Qt::PenStyle strokeStyle)
static void clearSymbolLayerIds(QgsSymbol *symbol)
Remove recursively unique id from all symbol symbol layers and set an empty string instead.
static Qt::PenJoinStyle decodePenJoinStyle(const QString &str)
static QString encodeMapUnitScale(const QgsMapUnitScale &mapUnitScale)
static QString svgSymbolPathToName(const QString &path, const QgsPathResolver &pathResolver)
Determines an SVG symbol's name from its path.
static QPointF toPoint(const QVariant &value, bool *ok=nullptr)
Converts a value to a point.
static QgsMapUnitScale decodeMapUnitScale(const QString &str)
static QSizeF toSize(const QVariant &value, bool *ok=nullptr)
Converts a value to a size.
static QPainter::CompositionMode decodeBlendMode(const QString &s)
static QString svgSymbolNameToPath(const QString &name, const QgsPathResolver &pathResolver)
Determines an SVG symbol's path from its name.
static QString encodeColor(const QColor &color)
static QDomElement saveSymbol(const QString &symbolName, const QgsSymbol *symbol, QDomDocument &doc, const QgsReadWriteContext &context)
Writes a symbol definition to XML.
static QString symbolProperties(QgsSymbol *symbol)
Returns a string representing the symbol.
@ StrokeColor
Stroke color.
@ JoinStyle
Line join style.
@ StrokeWidth
Stroke width.
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the symbol layer's property collection, used for data defined overrides.
bool changeSymbolLayer(int index, QgsSymbolLayer *layer)
Deletes the current layer at the specified index and replaces it with layer.
Container for settings relating to a text background object.
QgsMapUnitScale strokeWidthMapUnitScale() const
Returns the map unit scale object for the shape stroke width.
void setRadiiUnit(Qgis::RenderUnit units)
Sets the units used for the shape's radii.
void setFillSymbol(QgsFillSymbol *symbol)
Sets the current fill symbol for the background shape.
RotationType rotationType() const
Returns the method used for rotating the background shape.
QString svgFile() const
Returns the absolute path to the background SVG file, if set.
QSizeF size() const
Returns the size of the background shape.
QSizeF radii() const
Returns the radii used for rounding the corners of shapes.
QSet< QString > referencedFields(const QgsRenderContext &context) const
Returns all field names referenced by the configuration (e.g.
QgsMapUnitScale radiiMapUnitScale() const
Returns the map unit scale object for the shape radii.
void upgradeDataDefinedProperties(QgsPropertyCollection &properties)
Upgrade data defined properties when reading a project file saved in QGIS prior to version 3....
void setOpacity(double opacity)
Sets the background shape's opacity.
void setStrokeColor(const QColor &color)
Sets the color used for outlining the background shape.
Qgis::RenderUnit radiiUnit() const
Returns the units used for the shape's radii.
void setSizeMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale object for the shape size.
QPainter::CompositionMode blendMode() const
Returns the blending mode used for drawing the background shape.
Qt::PenJoinStyle joinStyle() const
Returns the join style used for drawing the background shape.
SizeType
Methods for determining the background shape size.
@ SizeBuffer
Shape size is determined by adding a buffer margin around text.
bool enabled() const
Returns whether the background is enabled.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Read settings from a DOM element.
void setJoinStyle(Qt::PenJoinStyle style)
Sets the join style used for drawing the background shape.
double opacity() const
Returns the background shape's opacity.
bool operator!=(const QgsTextBackgroundSettings &other) const
void updateDataDefinedProperties(QgsRenderContext &context, const QgsPropertyCollection &properties)
Updates the format by evaluating current values of data defined properties.
void setStrokeWidthMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale object for the shape stroke width.
double rotation() const
Returns the rotation for the background shape, in degrees clockwise.
QColor fillColor() const
Returns the color used for filing the background shape.
void setMarkerSymbol(QgsMarkerSymbol *symbol)
Sets the current marker symbol for the background shape.
void setRadii(QSizeF radii)
Sets the radii used for rounding the corners of shapes.
SizeType sizeType() const
Returns the method used to determine the size of the background shape (e.g., fixed size or buffer aro...
QgsTextBackgroundSettings & operator=(const QgsTextBackgroundSettings &other)
Qgis::RenderUnit strokeWidthUnit() const
Returns the units used for the shape's stroke width.
ShapeType type() const
Returns the type of background shape (e.g., square, ellipse, SVG).
double strokeWidth() const
Returns the width of the shape's stroke (stroke).
void setSizeType(SizeType type)
Sets the method used to determine the size of the background shape (e.g., fixed size or buffer around...
void setFillColor(const QColor &color)
Sets the color used for filing the background shape.
void setPaintEffect(QgsPaintEffect *effect)
Sets the current paint effect for the background shape.
void setSizeUnit(Qgis::RenderUnit unit)
Sets the units used for the shape's size.
Qgis::RenderUnit offsetUnit() const
Returns the units used for the shape's offset.
QColor strokeColor() const
Returns the color used for outlining the background shape.
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Write settings into a DOM element.
void setRotationType(RotationType type)
Sets the method used for rotating the background shape.
void setOffsetMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale object for the shape offset.
QgsFillSymbol * fillSymbol() const
Returns the fill symbol to be rendered in the background.
void setBlendMode(QPainter::CompositionMode mode)
Sets the blending mode used for drawing the background shape.
void readFromLayer(QgsVectorLayer *layer)
Reads settings from a layer's custom properties (for QGIS 2.x projects).
QgsMapUnitScale sizeMapUnitScale() const
Returns the map unit scale object for the shape size.
void setType(ShapeType type)
Sets the type of background shape to draw (e.g., square, ellipse, SVG).
Qgis::RenderUnit sizeUnit() const
Returns the units used for the shape's size.
RotationType
Methods for determining the rotation of the background shape.
@ RotationSync
Shape rotation is synced with text rotation.
bool operator==(const QgsTextBackgroundSettings &other) const
void setEnabled(bool enabled)
Sets whether the text background will be drawn.
QgsMarkerSymbol * markerSymbol() const
Returns the marker symbol to be rendered in the background.
void setRadiiMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale object for the shape radii.
void setRotation(double rotation)
Sets the rotation for the background shape, in degrees clockwise.
void setStrokeWidthUnit(Qgis::RenderUnit units)
Sets the units used for the shape's stroke width.
void setOffsetUnit(Qgis::RenderUnit units)
Sets the units used for the shape's offset.
void setOffset(QPointF offset)
Sets the offset used for drawing the background shape.
void setSize(QSizeF size)
Sets the size of the background shape.
const QgsPaintEffect * paintEffect() const
Returns the current paint effect for the background shape.
void setSvgFile(const QString &file)
Sets the path to the background SVG file.
QgsMapUnitScale offsetMapUnitScale() const
Returns the map unit scale object for the shape offset.
void setStrokeWidth(double width)
Sets the width of the shape's stroke (stroke).
QPointF offset() const
Returns the offset used for drawing the background shape.
static QgsTextBackgroundSettings::ShapeType decodeShapeType(const QString &string)
Decodes a string representation of a background shape type to a type.
static QColor readColor(QgsVectorLayer *layer, const QString &property, const QColor &defaultColor=Qt::black, bool withAlpha=true)
Converts an encoded color value from a layer property.
static QgsTextBackgroundSettings::RotationType decodeBackgroundRotationType(const QString &string)
Decodes a string representation of a background rotation type to a type.
static QgsTextBackgroundSettings::SizeType decodeBackgroundSizeType(const QString &string)
Decodes a string representation of a background size type to a type.
static Qgis::RenderUnit convertFromOldLabelUnit(int val)
Converts a unit from an old (pre 3.0) label unit.
static Q_INVOKABLE Qgis::RenderUnit decodeRenderUnit(const QString &string, bool *ok=nullptr)
Decodes a render unit from a string.
static Q_INVOKABLE QString encodeUnit(Qgis::DistanceUnit unit)
Encodes a distance unit to a string.
static bool isNull(const QVariant &variant, bool silenceNullWarnings=false)
Returns true if the specified variant should be considered a NULL value.
Represents a vector layer which manages a vector based data sets.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Definition qgis.h:5958