QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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
18#include "qgsapplication.h"
19#include "qgscolorutils.h"
20#include "qgsfillsymbollayer.h"
22#include "qgspainting.h"
23#include "qgspallabeling.h"
24#include "qgssymbollayerutils.h"
25#include "qgstextrenderer_p.h"
27#include "qgsunittypes.h"
28#include "qgsvectorlayer.h"
29
31{
32 d = new QgsTextBackgroundSettingsPrivate();
33
34 // Create a default fill symbol to preserve API promise until QGIS 4.0
35 QgsSimpleFillSymbolLayer *fill = new QgsSimpleFillSymbolLayer( d->fillColor, Qt::SolidPattern, d->strokeColor );
36 fill->setStrokeWidth( d->strokeWidth );
37 fill->setStrokeWidthUnit( d->strokeWidthUnits );
38 fill->setStrokeWidthMapUnitScale( d->strokeWidthMapUnitScale );
39 fill->setStrokeStyle( !qgsDoubleNear( d->strokeWidth, 0.0 ) ? Qt::SolidLine : Qt::NoPen );
40 fill->setPenJoinStyle( d->joinStyle );
41
43 fillSymbol->changeSymbolLayer( 0, fill );
45}
46
48 : d( other.d )
49{
50
51}
52
54 : d( std::move( other.d ) )
55{
56
57}
58
60{
61 if ( &other == this )
62 return *this;
63
64 d = other.d;
65 return *this;
66}
67
69{
70 if ( &other == this )
71 return *this;
72
73 d = std::move( other.d );
74 return *this;
75}
76
81
83{
84 if ( d->enabled != other.enabled()
85 || d->type != other.type()
86 || d->svgFile != other.svgFile()
87 || d->sizeType != other.sizeType()
88 || d->size != other.size()
89 || d->sizeUnits != other.sizeUnit()
90 || d->sizeMapUnitScale != other.sizeMapUnitScale()
91 || d->rotationType != other.rotationType()
92 || d->rotation != other.rotation()
93 || d->offset != other.offset()
94 || d->offsetUnits != other.offsetUnit()
95 || d->offsetMapUnitScale != other.offsetMapUnitScale()
96 || d->radii != other.radii()
97 || d->radiiUnits != other.radiiUnit()
98 || d->radiiMapUnitScale != other.radiiMapUnitScale()
99 || d->blendMode != other.blendMode()
100 || d->fillColor != other.fillColor()
101 || d->strokeColor != other.strokeColor()
102 || d->opacity != other.opacity()
103 || d->strokeWidth != other.strokeWidth()
104 || d->strokeWidthUnits != other.strokeWidthUnit()
105 || d->strokeWidthMapUnitScale != other.strokeWidthMapUnitScale()
106 || d->joinStyle != other.joinStyle() )
107 return false;
108
109 if ( static_cast< bool >( d->paintEffect ) != static_cast< bool >( other.paintEffect() )
110 || ( d->paintEffect && d->paintEffect->properties() != other.paintEffect()->properties() ) )
111 return false;
112
113 if ( static_cast< bool >( d->markerSymbol ) != static_cast< bool >( other.markerSymbol() )
114 || ( d->markerSymbol && QgsSymbolLayerUtils::symbolProperties( d->markerSymbol.get() ) != QgsSymbolLayerUtils::symbolProperties( other.markerSymbol() ) ) )
115 return false;
116
117 if ( static_cast< bool >( d->fillSymbol ) != static_cast< bool >( other.fillSymbol() )
118 || ( d->fillSymbol && QgsSymbolLayerUtils::symbolProperties( d->fillSymbol.get() ) != QgsSymbolLayerUtils::symbolProperties( other.fillSymbol() ) ) )
119 return false;
120
121 return true;
122}
123
125{
126 return !( *this == other );
127}
128
130{
131 return d->enabled;
132}
133
135{
136 d->enabled = enabled;
137}
138
143
148
150{
151 return d->svgFile;
152}
153
154void QgsTextBackgroundSettings::setSvgFile( const QString &file )
155{
156 d->svgFile = file;
157}
158
160{
161 return d->markerSymbol.get();
162}
163
165{
166 if ( symbol )
167 // Remove symbol layer unique id to have correct settings equality
169
170 d->markerSymbol.reset( symbol );
171}
172
174{
175 return d->fillSymbol.get();
176}
177
179{
180 if ( symbol )
181 // Remove symbol layer unique id to have correct settings equality
183
184 d->fillSymbol.reset( symbol );
185}
186
191
196
198{
199 return d->size;
200}
201
203{
204 d->size = size;
205}
206
208{
209 return d->sizeUnits;
210}
211
213{
214 d->sizeUnits = unit;
215}
216
218{
219 return d->sizeMapUnitScale;
220}
221
223{
224 d->sizeMapUnitScale = scale;
225}
226
231
236
238{
239 return d->rotation;
240}
241
243{
244 d->rotation = rotation;
245}
246
248{
249 return d->offset;
250}
251
253{
254 d->offset = offset;
255}
256
258{
259 return d->offsetUnits;
260}
261
263{
264 d->offsetUnits = units;
265}
266
268{
269 return d->offsetMapUnitScale;
270}
271
273{
274 d->offsetMapUnitScale = scale;
275}
276
278{
279 return d->radii;
280}
281
283{
284 d->radii = radii;
285}
286
288{
289 return d->radiiUnits;
290}
291
293{
294 d->radiiUnits = units;
295}
296
298{
299 return d->radiiMapUnitScale;
300}
301
303{
304 d->radiiMapUnitScale = scale;
305}
306
308{
309 return d->opacity;
310}
311
313{
314 d->opacity = opacity;
315}
316
317QPainter::CompositionMode QgsTextBackgroundSettings::blendMode() const
318{
319 return d->blendMode;
320}
321
322void QgsTextBackgroundSettings::setBlendMode( QPainter::CompositionMode mode )
323{
324 d->blendMode = mode;
325}
326
328{
329 return d->fillSymbol ? d->fillSymbol->color() : d->fillColor;
330}
331
333{
334 d->fillColor = color;
335 if ( d->fillSymbol )
336 {
337 d->fillSymbol->setColor( color );
338 }
339}
340
342{
343 if ( d->fillSymbol && d->fillSymbol->symbolLayers().at( 0 )->layerType() == QLatin1String( "SimpleFill" ) )
344 {
345 return qgis::down_cast< QgsSimpleFillSymbolLayer * >( d->fillSymbol->symbolLayers().at( 0 ) )->strokeColor();
346 }
347 return d->strokeColor;
348}
349
351{
352 d->strokeColor = color;
353 if ( d->fillSymbol && d->fillSymbol->symbolLayers().at( 0 )->layerType() == QLatin1String( "SimpleFill" ) )
354 {
355 qgis::down_cast< QgsSimpleFillSymbolLayer * >( d->fillSymbol->symbolLayers().at( 0 ) )->setStrokeColor( color );
356 }
357}
358
360{
361 if ( d->fillSymbol && d->fillSymbol->symbolLayers().at( 0 )->layerType() == QLatin1String( "SimpleFill" ) )
362 {
363 return qgis::down_cast< QgsSimpleFillSymbolLayer * >( d->fillSymbol->symbolLayers().at( 0 ) )->strokeWidth();
364 }
365 return d->strokeWidth;
366}
367
369{
370 d->strokeWidth = width;
371 if ( d->fillSymbol && d->fillSymbol->symbolLayers().at( 0 )->layerType() == QLatin1String( "SimpleFill" ) )
372 {
373 QgsSimpleFillSymbolLayer *fill = qgis::down_cast< QgsSimpleFillSymbolLayer * >( d->fillSymbol->symbolLayers().at( 0 ) );
374 fill->setStrokeWidth( width );
375 fill->setStrokeStyle( !qgsDoubleNear( width, 0.0 ) ? Qt::SolidLine : Qt::NoPen );
376 }
377}
378
380{
381 if ( d->fillSymbol && d->fillSymbol->symbolLayers().at( 0 )->layerType() == QLatin1String( "SimpleFill" ) )
382 {
383 return qgis::down_cast< QgsSimpleFillSymbolLayer * >( d->fillSymbol->symbolLayers().at( 0 ) )->strokeWidthUnit();
384 }
385 return d->strokeWidthUnits;
386}
387
389{
390 d->strokeWidthUnits = units;
391 if ( d->fillSymbol && d->fillSymbol->symbolLayers().at( 0 )->layerType() == QLatin1String( "SimpleFill" ) )
392 {
393 qgis::down_cast< QgsSimpleFillSymbolLayer * >( d->fillSymbol->symbolLayers().at( 0 ) )->setStrokeWidthUnit( units );
394 }
395}
396
398{
399 if ( d->fillSymbol && d->fillSymbol->symbolLayers().at( 0 )->layerType() == QLatin1String( "SimpleFill" ) )
400 {
401 return qgis::down_cast< QgsSimpleFillSymbolLayer * >( d->fillSymbol->symbolLayers().at( 0 ) )->strokeWidthMapUnitScale();
402 }
403 return d->strokeWidthMapUnitScale;
404}
405
407{
408 d->strokeWidthMapUnitScale = scale;
409 if ( d->fillSymbol && d->fillSymbol->symbolLayers().at( 0 )->layerType() == QLatin1String( "SimpleFill" ) )
410 {
411 qgis::down_cast< QgsSimpleFillSymbolLayer * >( d->fillSymbol->symbolLayers().at( 0 ) )->setStrokeWidthMapUnitScale( scale );
412 }
413}
414
416{
417 if ( d->fillSymbol && d->fillSymbol->symbolLayers().at( 0 )->layerType() == QLatin1String( "SimpleFill" ) )
418 {
419 return qgis::down_cast< QgsSimpleFillSymbolLayer * >( d->fillSymbol->symbolLayers().at( 0 ) )->penJoinStyle();
420 }
421 return d->joinStyle;
422}
423
424void QgsTextBackgroundSettings::setJoinStyle( Qt::PenJoinStyle style )
425{
426 d->joinStyle = style;
427 if ( d->fillSymbol && d->fillSymbol->symbolLayers().at( 0 )->layerType() == QLatin1String( "SimpleFill" ) )
428 {
429 qgis::down_cast< QgsSimpleFillSymbolLayer * >( d->fillSymbol->symbolLayers().at( 0 ) )->setPenJoinStyle( style );
430 }
431}
432
434{
435 return d->paintEffect.get();
436}
437
439{
440 d->paintEffect.reset( effect );
441}
442
444{
445 d->enabled = layer->customProperty( QStringLiteral( "labeling/shapeDraw" ), QVariant( false ) ).toBool();
446 d->type = static_cast< ShapeType >( layer->customProperty( QStringLiteral( "labeling/shapeType" ), QVariant( ShapeRectangle ) ).toUInt() );
447 d->svgFile = layer->customProperty( QStringLiteral( "labeling/shapeSVGFile" ), QVariant( "" ) ).toString();
448 d->sizeType = static_cast< SizeType >( layer->customProperty( QStringLiteral( "labeling/shapeSizeType" ), QVariant( SizeBuffer ) ).toUInt() );
449 d->size = QSizeF( layer->customProperty( QStringLiteral( "labeling/shapeSizeX" ), QVariant( 0.0 ) ).toDouble(),
450 layer->customProperty( QStringLiteral( "labeling/shapeSizeY" ), QVariant( 0.0 ) ).toDouble() );
451
452 if ( layer->customProperty( QStringLiteral( "labeling/shapeSizeUnit" ) ).toString().isEmpty() )
453 {
454 d->sizeUnits = QgsTextRendererUtils::convertFromOldLabelUnit( layer->customProperty( QStringLiteral( "labeling/shapeSizeUnits" ), 0 ).toUInt() );
455 }
456 else
457 {
458 d->sizeUnits = QgsUnitTypes::decodeRenderUnit( layer->customProperty( QStringLiteral( "labeling/shapeSizeUnit" ) ).toString() );
459 }
460
461 if ( layer->customProperty( QStringLiteral( "labeling/shapeSizeMapUnitScale" ) ).toString().isEmpty() )
462 {
463 //fallback to older property
464 const double oldMin = layer->customProperty( QStringLiteral( "labeling/shapeSizeMapUnitMinScale" ), 0.0 ).toDouble();
465 d->sizeMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
466 const double oldMax = layer->customProperty( QStringLiteral( "labeling/shapeSizeMapUnitMaxScale" ), 0.0 ).toDouble();
467 d->sizeMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
468 }
469 else
470 {
471 d->sizeMapUnitScale = QgsSymbolLayerUtils::decodeMapUnitScale( layer->customProperty( QStringLiteral( "labeling/shapeSizeMapUnitScale" ) ).toString() );
472 }
473 d->rotationType = static_cast< RotationType >( layer->customProperty( QStringLiteral( "labeling/shapeRotationType" ), QVariant( RotationSync ) ).toUInt() );
474 d->rotation = layer->customProperty( QStringLiteral( "labeling/shapeRotation" ), QVariant( 0.0 ) ).toDouble();
475 d->offset = QPointF( layer->customProperty( QStringLiteral( "labeling/shapeOffsetX" ), QVariant( 0.0 ) ).toDouble(),
476 layer->customProperty( QStringLiteral( "labeling/shapeOffsetY" ), QVariant( 0.0 ) ).toDouble() );
477
478 if ( layer->customProperty( QStringLiteral( "labeling/shapeOffsetUnit" ) ).toString().isEmpty() )
479 {
480 d->offsetUnits = QgsTextRendererUtils::convertFromOldLabelUnit( layer->customProperty( QStringLiteral( "labeling/shapeOffsetUnits" ), 0 ).toUInt() );
481 }
482 else
483 {
484 d->offsetUnits = QgsUnitTypes::decodeRenderUnit( layer->customProperty( QStringLiteral( "labeling/shapeOffsetUnit" ) ).toString() );
485 }
486
487 if ( layer->customProperty( QStringLiteral( "labeling/shapeOffsetMapUnitScale" ) ).toString().isEmpty() )
488 {
489 //fallback to older property
490 const double oldMin = layer->customProperty( QStringLiteral( "labeling/shapeOffsetMapUnitMinScale" ), 0.0 ).toDouble();
491 d->offsetMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
492 const double oldMax = layer->customProperty( QStringLiteral( "labeling/shapeOffsetMapUnitMaxScale" ), 0.0 ).toDouble();
493 d->offsetMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
494 }
495 else
496 {
497 d->offsetMapUnitScale = QgsSymbolLayerUtils::decodeMapUnitScale( layer->customProperty( QStringLiteral( "labeling/shapeOffsetMapUnitScale" ) ).toString() );
498 }
499 d->radii = QSizeF( layer->customProperty( QStringLiteral( "labeling/shapeRadiiX" ), QVariant( 0.0 ) ).toDouble(),
500 layer->customProperty( QStringLiteral( "labeling/shapeRadiiY" ), QVariant( 0.0 ) ).toDouble() );
501
502
503 if ( layer->customProperty( QStringLiteral( "labeling/shapeRadiiUnit" ) ).toString().isEmpty() )
504 {
505 d->radiiUnits = QgsTextRendererUtils::convertFromOldLabelUnit( layer->customProperty( QStringLiteral( "labeling/shapeRadiiUnits" ), 0 ).toUInt() );
506 }
507 else
508 {
509 d->radiiUnits = QgsUnitTypes::decodeRenderUnit( layer->customProperty( QStringLiteral( "labeling/shapeRadiiUnit" ) ).toString() );
510 }
511
512 if ( layer->customProperty( QStringLiteral( "labeling/shapeRadiiMapUnitScale" ) ).toString().isEmpty() )
513 {
514 //fallback to older property
515 const double oldMin = layer->customProperty( QStringLiteral( "labeling/shapeRadiiMapUnitMinScale" ), 0.0 ).toDouble();
516 d->radiiMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
517 const double oldMax = layer->customProperty( QStringLiteral( "labeling/shapeRadiiMapUnitMaxScale" ), 0.0 ).toDouble();
518 d->radiiMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
519 }
520 else
521 {
522 d->radiiMapUnitScale = QgsSymbolLayerUtils::decodeMapUnitScale( layer->customProperty( QStringLiteral( "labeling/shapeRadiiMapUnitScale" ) ).toString() );
523 }
524 d->fillColor = QgsTextRendererUtils::readColor( layer, QStringLiteral( "labeling/shapeFillColor" ), Qt::white, true );
525 d->strokeColor = QgsTextRendererUtils::readColor( layer, QStringLiteral( "labeling/shapeBorderColor" ), Qt::darkGray, true );
526 d->strokeWidth = layer->customProperty( QStringLiteral( "labeling/shapeBorderWidth" ), QVariant( .0 ) ).toDouble();
527 if ( layer->customProperty( QStringLiteral( "labeling/shapeBorderWidthUnit" ) ).toString().isEmpty() )
528 {
529 d->strokeWidthUnits = QgsTextRendererUtils::convertFromOldLabelUnit( layer->customProperty( QStringLiteral( "labeling/shapeBorderWidthUnits" ), 0 ).toUInt() );
530 }
531 else
532 {
533 d->strokeWidthUnits = QgsUnitTypes::decodeRenderUnit( layer->customProperty( QStringLiteral( "labeling/shapeBorderWidthUnit" ) ).toString() );
534 }
535 if ( layer->customProperty( QStringLiteral( "labeling/shapeBorderWidthMapUnitScale" ) ).toString().isEmpty() )
536 {
537 //fallback to older property
538 const double oldMin = layer->customProperty( QStringLiteral( "labeling/shapeBorderWidthMapUnitMinScale" ), 0.0 ).toDouble();
539 d->strokeWidthMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
540 const double oldMax = layer->customProperty( QStringLiteral( "labeling/shapeBorderWidthMapUnitMaxScale" ), 0.0 ).toDouble();
541 d->strokeWidthMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
542 }
543 else
544 {
545 d->strokeWidthMapUnitScale = QgsSymbolLayerUtils::decodeMapUnitScale( layer->customProperty( QStringLiteral( "labeling/shapeBorderWidthMapUnitScale" ) ).toString() );
546 }
547 d->joinStyle = static_cast< Qt::PenJoinStyle >( layer->customProperty( QStringLiteral( "labeling/shapeJoinStyle" ), QVariant( Qt::BevelJoin ) ).toUInt() );
548
549 if ( layer->customProperty( QStringLiteral( "labeling/shapeOpacity" ) ).toString().isEmpty() )
550 {
551 d->opacity = ( 1 - layer->customProperty( QStringLiteral( "labeling/shapeTransparency" ) ).toInt() / 100.0 ); //0 -100
552 }
553 else
554 {
555 d->opacity = ( layer->customProperty( QStringLiteral( "labeling/shapeOpacity" ) ).toDouble() );
556 }
557 d->blendMode = QgsPainting::getCompositionMode(
558 static_cast< Qgis::BlendMode >( layer->customProperty( QStringLiteral( "labeling/shapeBlendMode" ), QVariant( static_cast< int>( Qgis::BlendMode::Normal ) ) ).toUInt() ) );
559
560 if ( layer->customProperty( QStringLiteral( "labeling/shapeEffect" ) ).isValid() )
561 {
562 QDomDocument doc( QStringLiteral( "effect" ) );
563 doc.setContent( layer->customProperty( QStringLiteral( "labeling/shapeEffect" ) ).toString() );
564 const QDomElement effectElem = doc.firstChildElement( QStringLiteral( "effect" ) ).firstChildElement( QStringLiteral( "effect" ) );
565 setPaintEffect( QgsApplication::paintEffectRegistry()->createEffect( effectElem ) );
566 }
567 else
568 setPaintEffect( nullptr );
569}
570
571void QgsTextBackgroundSettings::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
572{
573 const QDomElement backgroundElem = elem.firstChildElement( QStringLiteral( "background" ) );
574 d->enabled = backgroundElem.attribute( QStringLiteral( "shapeDraw" ), QStringLiteral( "0" ) ).toInt();
575 d->type = static_cast< ShapeType >( backgroundElem.attribute( QStringLiteral( "shapeType" ), QString::number( ShapeRectangle ) ).toUInt() );
576 d->svgFile = QgsSymbolLayerUtils::svgSymbolNameToPath( backgroundElem.attribute( QStringLiteral( "shapeSVGFile" ) ), context.pathResolver() );
577 d->sizeType = static_cast< SizeType >( backgroundElem.attribute( QStringLiteral( "shapeSizeType" ), QString::number( SizeBuffer ) ).toUInt() );
578 d->size = QSizeF( backgroundElem.attribute( QStringLiteral( "shapeSizeX" ), QStringLiteral( "0" ) ).toDouble(),
579 backgroundElem.attribute( QStringLiteral( "shapeSizeY" ), QStringLiteral( "0" ) ).toDouble() );
580
581 if ( !backgroundElem.hasAttribute( QStringLiteral( "shapeSizeUnit" ) ) )
582 {
583 d->sizeUnits = QgsTextRendererUtils::convertFromOldLabelUnit( backgroundElem.attribute( QStringLiteral( "shapeSizeUnits" ) ).toUInt() );
584 }
585 else
586 {
587 d->sizeUnits = QgsUnitTypes::decodeRenderUnit( backgroundElem.attribute( QStringLiteral( "shapeSizeUnit" ) ) );
588 }
589
590 if ( !backgroundElem.hasAttribute( QStringLiteral( "shapeSizeMapUnitScale" ) ) )
591 {
592 //fallback to older property
593 const double oldMin = backgroundElem.attribute( QStringLiteral( "shapeSizeMapUnitMinScale" ), QStringLiteral( "0" ) ).toDouble();
594 d->sizeMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
595 const double oldMax = backgroundElem.attribute( QStringLiteral( "shapeSizeMapUnitMaxScale" ), QStringLiteral( "0" ) ).toDouble();
596 d->sizeMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
597 }
598 else
599 {
600 d->sizeMapUnitScale = QgsSymbolLayerUtils::decodeMapUnitScale( backgroundElem.attribute( QStringLiteral( "shapeSizeMapUnitScale" ) ) );
601 }
602 d->rotationType = static_cast< RotationType >( backgroundElem.attribute( QStringLiteral( "shapeRotationType" ), QString::number( RotationSync ) ).toUInt() );
603 d->rotation = backgroundElem.attribute( QStringLiteral( "shapeRotation" ), QStringLiteral( "0" ) ).toDouble();
604 d->offset = QPointF( backgroundElem.attribute( QStringLiteral( "shapeOffsetX" ), QStringLiteral( "0" ) ).toDouble(),
605 backgroundElem.attribute( QStringLiteral( "shapeOffsetY" ), QStringLiteral( "0" ) ).toDouble() );
606
607 if ( !backgroundElem.hasAttribute( QStringLiteral( "shapeOffsetUnit" ) ) )
608 {
609 d->offsetUnits = QgsTextRendererUtils::convertFromOldLabelUnit( backgroundElem.attribute( QStringLiteral( "shapeOffsetUnits" ) ).toUInt() );
610 }
611 else
612 {
613 d->offsetUnits = QgsUnitTypes::decodeRenderUnit( backgroundElem.attribute( QStringLiteral( "shapeOffsetUnit" ) ) );
614 }
615
616 if ( !backgroundElem.hasAttribute( QStringLiteral( "shapeOffsetMapUnitScale" ) ) )
617 {
618 //fallback to older property
619 const double oldMin = backgroundElem.attribute( QStringLiteral( "shapeOffsetMapUnitMinScale" ), QStringLiteral( "0" ) ).toDouble();
620 d->offsetMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
621 const double oldMax = backgroundElem.attribute( QStringLiteral( "shapeOffsetMapUnitMaxScale" ), QStringLiteral( "0" ) ).toDouble();
622 d->offsetMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
623 }
624 else
625 {
626 d->offsetMapUnitScale = QgsSymbolLayerUtils::decodeMapUnitScale( backgroundElem.attribute( QStringLiteral( "shapeOffsetMapUnitScale" ) ) );
627 }
628 d->radii = QSizeF( backgroundElem.attribute( QStringLiteral( "shapeRadiiX" ), QStringLiteral( "0" ) ).toDouble(),
629 backgroundElem.attribute( QStringLiteral( "shapeRadiiY" ), QStringLiteral( "0" ) ).toDouble() );
630
631 if ( !backgroundElem.hasAttribute( QStringLiteral( "shapeRadiiUnit" ) ) )
632 {
633 d->radiiUnits = QgsTextRendererUtils::convertFromOldLabelUnit( backgroundElem.attribute( QStringLiteral( "shapeRadiiUnits" ) ).toUInt() );
634 }
635 else
636 {
637 d->radiiUnits = QgsUnitTypes::decodeRenderUnit( backgroundElem.attribute( QStringLiteral( "shapeRadiiUnit" ) ) );
638 }
639 if ( !backgroundElem.hasAttribute( QStringLiteral( "shapeRadiiMapUnitScale" ) ) )
640 {
641 //fallback to older property
642 const double oldMin = backgroundElem.attribute( QStringLiteral( "shapeRadiiMapUnitMinScale" ), QStringLiteral( "0" ) ).toDouble();
643 d->radiiMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
644 const double oldMax = backgroundElem.attribute( QStringLiteral( "shapeRadiiMapUnitMaxScale" ), QStringLiteral( "0" ) ).toDouble();
645 d->radiiMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
646 }
647 else
648 {
649 d->radiiMapUnitScale = QgsSymbolLayerUtils::decodeMapUnitScale( backgroundElem.attribute( QStringLiteral( "shapeRadiiMapUnitScale" ) ) );
650 }
651 d->fillColor = QgsColorUtils::colorFromString( backgroundElem.attribute( QStringLiteral( "shapeFillColor" ), QgsColorUtils::colorToString( Qt::white ) ) );
652 d->strokeColor = QgsColorUtils::colorFromString( backgroundElem.attribute( QStringLiteral( "shapeBorderColor" ), QgsColorUtils::colorToString( Qt::darkGray ) ) );
653 d->strokeWidth = backgroundElem.attribute( QStringLiteral( "shapeBorderWidth" ), QStringLiteral( "0" ) ).toDouble();
654
655 if ( !backgroundElem.hasAttribute( QStringLiteral( "shapeBorderWidthUnit" ) ) )
656 {
657 d->strokeWidthUnits = QgsTextRendererUtils::convertFromOldLabelUnit( backgroundElem.attribute( QStringLiteral( "shapeBorderWidthUnits" ) ).toUInt() );
658 }
659 else
660 {
661 d->strokeWidthUnits = QgsUnitTypes::decodeRenderUnit( backgroundElem.attribute( QStringLiteral( "shapeBorderWidthUnit" ) ) );
662 }
663 if ( !backgroundElem.hasAttribute( QStringLiteral( "shapeBorderWidthMapUnitScale" ) ) )
664 {
665 //fallback to older property
666 const double oldMin = backgroundElem.attribute( QStringLiteral( "shapeBorderWidthMapUnitMinScale" ), QStringLiteral( "0" ) ).toDouble();
667 d->strokeWidthMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
668 const double oldMax = backgroundElem.attribute( QStringLiteral( "shapeBorderWidthMapUnitMaxScale" ), QStringLiteral( "0" ) ).toDouble();
669 d->strokeWidthMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
670 }
671 else
672 {
673 d->strokeWidthMapUnitScale = QgsSymbolLayerUtils::decodeMapUnitScale( backgroundElem.attribute( QStringLiteral( "shapeBorderWidthMapUnitScale" ) ) );
674 }
675 d->joinStyle = static_cast< Qt::PenJoinStyle >( backgroundElem.attribute( QStringLiteral( "shapeJoinStyle" ), QString::number( Qt::BevelJoin ) ).toUInt() );
676
677 if ( !backgroundElem.hasAttribute( QStringLiteral( "shapeOpacity" ) ) )
678 {
679 d->opacity = ( 1 - backgroundElem.attribute( QStringLiteral( "shapeTransparency" ) ).toInt() / 100.0 ); //0 -100
680 }
681 else
682 {
683 d->opacity = ( backgroundElem.attribute( QStringLiteral( "shapeOpacity" ) ).toDouble() );
684 }
685
686 d->blendMode = QgsPainting::getCompositionMode(
687 static_cast< Qgis::BlendMode >( backgroundElem.attribute( QStringLiteral( "shapeBlendMode" ), QString::number( static_cast< int >( Qgis::BlendMode::Normal ) ) ).toUInt() ) );
688
689 const QDomElement effectElem = backgroundElem.firstChildElement( QStringLiteral( "effect" ) );
690 if ( !effectElem.isNull() )
691 setPaintEffect( QgsApplication::paintEffectRegistry()->createEffect( effectElem ) );
692 else
693 setPaintEffect( nullptr );
694
695 setMarkerSymbol( nullptr );
696 setFillSymbol( nullptr );
697 const QDomNodeList symbols = backgroundElem.elementsByTagName( QStringLiteral( "symbol" ) );
698 for ( int i = 0; i < symbols.size(); ++i )
699 {
700 if ( symbols.at( i ).isElement() )
701 {
702 const QDomElement symbolElement = symbols.at( i ).toElement();
703 const QString symbolElementName = symbolElement.attribute( QStringLiteral( "name" ) );
704 if ( symbolElementName == QLatin1String( "markerSymbol" ) )
705 {
706 setMarkerSymbol( QgsSymbolLayerUtils::loadSymbol< QgsMarkerSymbol >( symbolElement, context ).release() );
707 }
708 else if ( symbolElementName == QLatin1String( "fillSymbol" ) )
709 {
710 setFillSymbol( QgsSymbolLayerUtils::loadSymbol< QgsFillSymbol >( symbolElement, context ).release() );
711 }
712 }
713 }
714
715 if ( !d->fillSymbol )
716 {
717 QgsSimpleFillSymbolLayer *fill = new QgsSimpleFillSymbolLayer( d->fillColor, Qt::SolidPattern, d->strokeColor );
718 fill->setStrokeWidth( d->strokeWidth );
719 fill->setStrokeWidthUnit( d->strokeWidthUnits );
720 fill->setStrokeWidthMapUnitScale( d->strokeWidthMapUnitScale );
721 fill->setStrokeStyle( !qgsDoubleNear( d->strokeWidth, 0.0 ) ? Qt::SolidLine : Qt::NoPen );
722 fill->setPenJoinStyle( d->joinStyle );
723
725 fillSymbol->changeSymbolLayer( 0, fill );
727 }
728}
729
730QDomElement QgsTextBackgroundSettings::writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const
731{
732 QDomElement backgroundElem = doc.createElement( QStringLiteral( "background" ) );
733 backgroundElem.setAttribute( QStringLiteral( "shapeDraw" ), d->enabled );
734 backgroundElem.setAttribute( QStringLiteral( "shapeType" ), static_cast< unsigned int >( d->type ) );
735 backgroundElem.setAttribute( QStringLiteral( "shapeSVGFile" ), QgsSymbolLayerUtils::svgSymbolPathToName( d->svgFile, context.pathResolver() ) );
736 backgroundElem.setAttribute( QStringLiteral( "shapeSizeType" ), static_cast< unsigned int >( d->sizeType ) );
737 backgroundElem.setAttribute( QStringLiteral( "shapeSizeX" ), d->size.width() );
738 backgroundElem.setAttribute( QStringLiteral( "shapeSizeY" ), d->size.height() );
739 backgroundElem.setAttribute( QStringLiteral( "shapeSizeUnit" ), QgsUnitTypes::encodeUnit( d->sizeUnits ) );
740 backgroundElem.setAttribute( QStringLiteral( "shapeSizeMapUnitScale" ), QgsSymbolLayerUtils::encodeMapUnitScale( d->sizeMapUnitScale ) );
741 backgroundElem.setAttribute( QStringLiteral( "shapeRotationType" ), static_cast< unsigned int >( d->rotationType ) );
742 backgroundElem.setAttribute( QStringLiteral( "shapeRotation" ), d->rotation );
743 backgroundElem.setAttribute( QStringLiteral( "shapeOffsetX" ), d->offset.x() );
744 backgroundElem.setAttribute( QStringLiteral( "shapeOffsetY" ), d->offset.y() );
745 backgroundElem.setAttribute( QStringLiteral( "shapeOffsetUnit" ), QgsUnitTypes::encodeUnit( d->offsetUnits ) );
746 backgroundElem.setAttribute( QStringLiteral( "shapeOffsetMapUnitScale" ), QgsSymbolLayerUtils::encodeMapUnitScale( d->offsetMapUnitScale ) );
747 backgroundElem.setAttribute( QStringLiteral( "shapeRadiiX" ), d->radii.width() );
748 backgroundElem.setAttribute( QStringLiteral( "shapeRadiiY" ), d->radii.height() );
749 backgroundElem.setAttribute( QStringLiteral( "shapeRadiiUnit" ), QgsUnitTypes::encodeUnit( d->radiiUnits ) );
750 backgroundElem.setAttribute( QStringLiteral( "shapeRadiiMapUnitScale" ), QgsSymbolLayerUtils::encodeMapUnitScale( d->radiiMapUnitScale ) );
751 backgroundElem.setAttribute( QStringLiteral( "shapeFillColor" ), QgsColorUtils::colorToString( d->fillColor ) );
752 backgroundElem.setAttribute( QStringLiteral( "shapeBorderColor" ), QgsColorUtils::colorToString( d->strokeColor ) );
753 backgroundElem.setAttribute( QStringLiteral( "shapeBorderWidth" ), d->strokeWidth );
754 backgroundElem.setAttribute( QStringLiteral( "shapeBorderWidthUnit" ), QgsUnitTypes::encodeUnit( d->strokeWidthUnits ) );
755 backgroundElem.setAttribute( QStringLiteral( "shapeBorderWidthMapUnitScale" ), QgsSymbolLayerUtils::encodeMapUnitScale( d->strokeWidthMapUnitScale ) );
756 backgroundElem.setAttribute( QStringLiteral( "shapeJoinStyle" ), static_cast< unsigned int >( d->joinStyle ) );
757 backgroundElem.setAttribute( QStringLiteral( "shapeOpacity" ), d->opacity );
758 backgroundElem.setAttribute( QStringLiteral( "shapeBlendMode" ), static_cast< int >( QgsPainting::getBlendModeEnum( d->blendMode ) ) );
759 if ( d->paintEffect && !QgsPaintEffectRegistry::isDefaultStack( d->paintEffect.get() ) )
760 d->paintEffect->saveProperties( doc, backgroundElem );
761
762 if ( d->markerSymbol )
763 backgroundElem.appendChild( QgsSymbolLayerUtils::saveSymbol( QStringLiteral( "markerSymbol" ), d->markerSymbol.get(), doc, context ) );
764
765 if ( d->fillSymbol )
766 backgroundElem.appendChild( QgsSymbolLayerUtils::saveSymbol( QStringLiteral( "fillSymbol" ), d->fillSymbol.get(), doc, context ) );
767
768 return backgroundElem;
769}
770
772{
773 if ( !d->fillSymbol || d->fillSymbol->symbolLayers().at( 0 )->layerType() != QLatin1String( "SimpleFill" ) )
774 return;
775 QgsSimpleFillSymbolLayer *fill = qgis::down_cast< QgsSimpleFillSymbolLayer * >( d->fillSymbol->symbolLayers().at( 0 ) );
776
778 {
781 {
784 }
785
788 {
791 }
792
795 {
798 }
799
802 {
805 }
806 }
807}
808
810{
812 {
813 context.expressionContext().setOriginalValueVariable( d->enabled );
814 d->enabled = properties.valueAsBool( QgsPalLayerSettings::Property::ShapeDraw, context.expressionContext(), d->enabled );
815 }
816
818 {
819 context.expressionContext().setOriginalValueVariable( d->size.width() );
820 d->size.setWidth( properties.valueAsDouble( QgsPalLayerSettings::Property::ShapeSizeX, context.expressionContext(), d->size.width() ) );
821 }
823 {
824 context.expressionContext().setOriginalValueVariable( d->size.height() );
825 d->size.setHeight( properties.valueAsDouble( QgsPalLayerSettings::Property::ShapeSizeY, context.expressionContext(), d->size.height() ) );
826 }
827
828 QVariant exprVal = properties.value( QgsPalLayerSettings::Property::ShapeSizeUnits, context.expressionContext() );
829 if ( !QgsVariantUtils::isNull( exprVal ) )
830 {
831 const QString units = exprVal.toString();
832 if ( !units.isEmpty() )
833 {
834 bool ok;
835 const Qgis::RenderUnit res = QgsUnitTypes::decodeRenderUnit( units, &ok );
836 if ( ok )
837 d->sizeUnits = res;
838 }
839 }
840
841 exprVal = properties.value( QgsPalLayerSettings::Property::ShapeKind, context.expressionContext() );
842 if ( !QgsVariantUtils::isNull( exprVal ) )
843 {
844 const QString skind = exprVal.toString().trimmed();
845 if ( !skind.isEmpty() )
846 {
847 d->type = QgsTextRendererUtils::decodeShapeType( skind );
848 }
849 }
850
852 if ( !QgsVariantUtils::isNull( exprVal ) )
853 {
854 const QString stype = exprVal.toString().trimmed();
855 if ( !stype.isEmpty() )
856 {
858 }
859 }
860
861 // data defined shape SVG path?
862 context.expressionContext().setOriginalValueVariable( d->svgFile );
864 if ( !QgsVariantUtils::isNull( exprVal ) )
865 {
866 const QString svgfile = exprVal.toString().trimmed();
867 d->svgFile = QgsSymbolLayerUtils::svgSymbolNameToPath( svgfile, context.pathResolver() );
868 }
869
871 {
872 context.expressionContext().setOriginalValueVariable( d->rotation );
873 d->rotation = properties.valueAsDouble( QgsPalLayerSettings::Property::ShapeRotation, context.expressionContext(), d->rotation );
874 }
876 if ( !QgsVariantUtils::isNull( exprVal ) )
877 {
878 const QString rotstr = exprVal.toString().trimmed();
879 if ( !rotstr.isEmpty() )
880 {
881 d->rotationType = QgsTextRendererUtils::decodeBackgroundRotationType( rotstr );
882 }
883 }
884
885 exprVal = properties.value( QgsPalLayerSettings::Property::ShapeOffset, context.expressionContext() );
886 if ( !QgsVariantUtils::isNull( exprVal ) )
887 {
888 bool ok = false;
889 const QPointF res = QgsSymbolLayerUtils::toPoint( exprVal, &ok );
890 if ( ok )
891 {
892 d->offset = res;
893 }
894 }
896 if ( !QgsVariantUtils::isNull( exprVal ) )
897 {
898 const QString units = exprVal.toString();
899 if ( !units.isEmpty() )
900 {
901 bool ok;
902 const Qgis::RenderUnit res = QgsUnitTypes::decodeRenderUnit( units, &ok );
903 if ( ok )
904 d->offsetUnits = res;
905 }
906 }
907
908 exprVal = properties.value( QgsPalLayerSettings::Property::ShapeRadii, context.expressionContext() );
909 if ( !QgsVariantUtils::isNull( exprVal ) )
910 {
911 bool ok = false;
912 const QSizeF res = QgsSymbolLayerUtils::toSize( exprVal, &ok );
913 if ( ok )
914 {
915 d->radii = res;
916 }
917 }
918
920 if ( !QgsVariantUtils::isNull( exprVal ) )
921 {
922 const QString units = exprVal.toString();
923 if ( !units.isEmpty() )
924 {
925 bool ok;
926 const Qgis::RenderUnit res = QgsUnitTypes::decodeRenderUnit( units, &ok );
927 if ( ok )
928 d->radiiUnits = res;
929 }
930 }
931
933 {
934 context.expressionContext().setOriginalValueVariable( d->opacity * 100 );
935 const QVariant val = properties.value( QgsPalLayerSettings::Property::ShapeOpacity, context.expressionContext(), d->opacity * 100 );
936 if ( !QgsVariantUtils::isNull( val ) )
937 {
938 d->opacity = val.toDouble() / 100.0;
939 }
940 }
941
942 // for non-SVG background types, using data defined properties within the fill symbol is preferable
944 {
947 }
949 {
952 }
953
955 {
956 context.expressionContext().setOriginalValueVariable( d->strokeWidth );
958 }
960 if ( !QgsVariantUtils::isNull( exprVal ) )
961 {
962 const QString units = exprVal.toString();
963 if ( !units.isEmpty() )
964 {
965 bool ok;
966 const Qgis::RenderUnit res = QgsUnitTypes::decodeRenderUnit( units, &ok );
967 if ( ok )
968 setStrokeWidthUnit( res );
969 }
970 }
971
973 {
975 const QString blendstr = exprVal.toString().trimmed();
976 if ( !blendstr.isEmpty() )
977 d->blendMode = QgsSymbolLayerUtils::decodeBlendMode( blendstr );
978 }
979
981 {
983 const QString joinstr = exprVal.toString().trimmed();
984 if ( !joinstr.isEmpty() )
985 {
987 }
988 }
989}
990
992{
993 QSet< QString > fields;
994 if ( d->markerSymbol )
995 {
996 fields.unite( d->markerSymbol->usedAttributes( context ) );
997 }
998 if ( d->fillSymbol )
999 {
1000 fields.unite( d->fillSymbol->usedAttributes( context ) );
1001 }
1002 return fields;
1003}
BlendMode
Blending modes defining the available composition modes that can be used when painting.
Definition qgis.h:4930
@ Normal
Normal.
Definition qgis.h:4931
RenderUnit
Rendering size units.
Definition qgis.h:5183
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.
bool enabled() const
Returns whether the effect is enabled.
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 an 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.
A container for the context for various read/write operations on 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 std::unique_ptr< QgsSymbol > loadSymbol(const QDomElement &element, const QgsReadWriteContext &context)
Attempts to load a symbol from a DOM element.
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.
@ JoinStyle
Line join style.
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the symbol layer's property collection, used for data defined overrides.
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 dataset.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference).
Definition qgis.h:6607