QGIS API Documentation 3.43.0-Master (261ee7da134)
qgsvectorlayerlabeling.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsvectorlayerlabeling.cpp
3 ---------------------
4 begin : September 2015
5 copyright : (C) 2015 by Martin Dobias
6 email : wonder dot sk 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 ***************************************************************************/
16
17#include "qgspallabeling.h"
19#include "qgsvectorlayer.h"
20#include "qgssymbollayerutils.h"
21#include "qgssymbollayer.h"
23#include "qgis.h"
25#include "qgsmarkersymbol.h"
26#include "qgssldexportcontext.h"
27
29{
30 const QString type = element.attribute( QStringLiteral( "type" ) );
31 if ( type == QLatin1String( "rule-based" ) )
32 {
33 return QgsRuleBasedLabeling::create( element, context );
34 }
35 else if ( type == QLatin1String( "simple" ) )
36 {
37 return QgsVectorLayerSimpleLabeling::create( element, context );
38 }
39 else
40 {
41 return nullptr;
42 }
43}
44
45void QgsAbstractVectorLayerLabeling::toSld( QDomNode &parent, const QVariantMap &props ) const
46{
47 QgsSldExportContext context;
48 context.setExtraProperties( props );
49 toSld( parent, context );
50}
51
53{
54 context.pushError( QObject::tr( "%1 labeling cannot be exported to SLD" ).arg( type() ) );
55 return false;
56}
57
62
88
90{
91 return new QgsVectorLayerLabelProvider( layer, QString(), false, mSettings.get() );
92}
93
95 : mSettings( new QgsPalLayerSettings( settings ) )
96{
97
98}
99
101{
102 return QStringLiteral( "simple" );
103}
104
109
110QDomElement QgsVectorLayerSimpleLabeling::save( QDomDocument &doc, const QgsReadWriteContext &context ) const
111{
112 QDomElement elem = doc.createElement( QStringLiteral( "labeling" ) );
113 elem.setAttribute( QStringLiteral( "type" ), QStringLiteral( "simple" ) );
114 elem.appendChild( mSettings->writeXml( doc, context ) );
115 return elem;
116}
117
119{
120 Q_UNUSED( providerId )
121 return *mSettings;
122}
123
125{
126 if ( mSettings )
127 {
128 QgsStyleLabelSettingsEntity entity( *mSettings );
129 if ( !visitor->visit( &entity ) )
130 return false;
131 }
132 return true;
133}
134
136{
137 return mSettings->containsAdvancedEffects();
138}
139
141{
142 return mSettings->dataDefinedProperties().isActive( QgsPalLayerSettings::Property::FontBlendMode )
143 || mSettings->dataDefinedProperties().isActive( QgsPalLayerSettings::Property::ShapeBlendMode )
144 || mSettings->dataDefinedProperties().isActive( QgsPalLayerSettings::Property::BufferBlendMode )
145 || mSettings->dataDefinedProperties().isActive( QgsPalLayerSettings::Property::ShadowBlendMode )
146 || mSettings->format().hasNonDefaultCompositionMode();
147}
148
149QgsVectorLayerSimpleLabeling *QgsVectorLayerSimpleLabeling::create( const QDomElement &element, const QgsReadWriteContext &context ) // cppcheck-suppress duplInheritedMember
150{
151 const QDomElement settingsElem = element.firstChildElement( QStringLiteral( "settings" ) );
152 if ( !settingsElem.isNull() )
153 {
155 settings.readXml( settingsElem, context );
157 }
158
160}
161
163{
164 double quadOffsetX = 0.5, quadOffsetY = 0.5;
165
166 // adjust quadrant offset of labels
167 switch ( quadrantPosition )
168 {
170 quadOffsetX = 1;
171 quadOffsetY = 0;
172 break;
174 quadOffsetX = 0.5;
175 quadOffsetY = 0;
176 break;
178 quadOffsetX = 0;
179 quadOffsetY = 0;
180 break;
182 quadOffsetX = 1;
183 quadOffsetY = 0.5;
184 break;
186 quadOffsetX = 0;
187 quadOffsetY = 0.5;
188 break;
190 quadOffsetX = 1;
191 quadOffsetY = 1;
192 break;
194 quadOffsetX = 0.5;
195 quadOffsetY = 1;
196 break;
198 quadOffsetX = 0;
199 quadOffsetY = 1.0;
200 break;
202 break;
203 }
204
205 return QPointF( quadOffsetX, quadOffsetY );
206}
207
208/*
209 * This is not a generic function encoder, just enough to encode the label case control functions
210 */
211void appendSimpleFunction( QDomDocument &doc, QDomElement &parent, const QString &name, const QString &attribute )
212{
213 QDomElement function = doc.createElement( QStringLiteral( "ogc:Function" ) );
214 function.setAttribute( QStringLiteral( "name" ), name );
215 parent.appendChild( function );
216 QDomElement property = doc.createElement( QStringLiteral( "ogc:PropertyName" ) );
217 property.appendChild( doc.createTextNode( attribute ) );
218 function.appendChild( property );
219}
220
221std::unique_ptr<QgsMarkerSymbolLayer> backgroundToMarkerLayer( const QgsTextBackgroundSettings &settings )
222{
223 std::unique_ptr<QgsMarkerSymbolLayer> layer;
224 switch ( settings.type() )
225 {
227 {
229 svg->setStrokeWidth( settings.strokeWidth() );
230 svg->setStrokeWidthUnit( settings.strokeWidthUnit() );
231 layer.reset( svg );
232 break;
233 }
235 {
236 // just grab the first layer and hope for the best
237 if ( settings.markerSymbol() && settings.markerSymbol()->symbolLayerCount() > 0 )
238 {
239 layer.reset( static_cast< QgsMarkerSymbolLayer * >( settings.markerSymbol()->symbolLayer( 0 )->clone() ) );
240 break;
241 }
242 [[fallthrough]]; // not set, just go with the default
243 }
248 {
250 // default value
252 switch ( settings.type() )
253 {
257 break;
261 break;
264 break;
265 }
266
267 marker->setShape( shape );
268 marker->setStrokeWidth( settings.strokeWidth() );
269 marker->setStrokeWidthUnit( settings.strokeWidthUnit() );
270 layer.reset( marker );
271 }
272 }
273 layer->setEnabled( true );
274 // a marker does not have a size x and y, just a size (and it should be at least one)
275 const QSizeF size = settings.size();
276 layer->setSize( std::max( 1., std::max( size.width(), size.height() ) ) );
277 layer->setSizeUnit( settings.sizeUnit() );
278 // fill and stroke
279 QColor fillColor = settings.fillColor();
280 QColor strokeColor = settings.strokeColor();
281 if ( settings.opacity() < 1 )
282 {
283 const int alpha = std::round( settings.opacity() * 255 );
284 fillColor.setAlpha( alpha );
285 strokeColor.setAlpha( alpha );
286 }
287 layer->setFillColor( fillColor );
288 layer->setStrokeColor( strokeColor );
289 // rotation
291 {
292 layer->setAngle( settings.rotation() );
293 }
294 // offset
295 layer->setOffset( settings.offset() );
296 layer->setOffsetUnit( settings.offsetUnit() );
297
298 return layer;
299}
300
301void QgsAbstractVectorLayerLabeling::writeTextSymbolizer( QDomNode &parent, QgsPalLayerSettings &settings, const QVariantMap &props ) const
302{
303 QgsSldExportContext context;
304 context.setExtraProperties( props );
305 writeTextSymbolizer( parent, settings, context );
306}
307
309{
310 QDomDocument doc = parent.ownerDocument();
311
312 // text symbolizer
313 QDomElement textSymbolizerElement = doc.createElement( QStringLiteral( "se:TextSymbolizer" ) );
314 parent.appendChild( textSymbolizerElement );
315
316 // label
317 QgsTextFormat format = settings.format();
318 const QFont font = format.font();
319 QDomElement labelElement = doc.createElement( QStringLiteral( "se:Label" ) );
320 textSymbolizerElement.appendChild( labelElement );
322 {
323 context.pushError( QObject::tr( "Cannot export label expression %1 to SLD" ).arg( settings.getLabelExpression()->dump() ) );
324 labelElement.appendChild( doc.createTextNode( "Placeholder" ) );
325 }
326 else
327 {
328 Qgis::Capitalization capitalization = format.capitalization();
329 if ( capitalization == Qgis::Capitalization::MixedCase && font.capitalization() != QFont::MixedCase )
330 capitalization = static_cast< Qgis::Capitalization >( font.capitalization() );
331 if ( capitalization == Qgis::Capitalization::AllUppercase )
332 {
333 appendSimpleFunction( doc, labelElement, QStringLiteral( "strToUpperCase" ), settings.fieldName );
334 }
335 else if ( capitalization == Qgis::Capitalization::AllLowercase )
336 {
337 appendSimpleFunction( doc, labelElement, QStringLiteral( "strToLowerCase" ), settings.fieldName );
338 }
339 else if ( capitalization == Qgis::Capitalization::ForceFirstLetterToCapital )
340 {
341 appendSimpleFunction( doc, labelElement, QStringLiteral( "strCapitalize" ), settings.fieldName );
342 }
343 else
344 {
345 QDomElement propertyNameElement = doc.createElement( QStringLiteral( "ogc:PropertyName" ) );
346 propertyNameElement.appendChild( doc.createTextNode( settings.fieldName ) );
347 labelElement.appendChild( propertyNameElement );
348 }
349 }
350
351 // font
352 QDomElement fontElement = doc.createElement( QStringLiteral( "se:Font" ) );
353 textSymbolizerElement.appendChild( fontElement );
354 fontElement.appendChild( QgsSymbolLayerUtils::createSvgParameterElement( doc, QStringLiteral( "font-family" ), font.family() ) );
355 const QVariantMap props = context.extraProperties();
356 const double fontSize = QgsSymbolLayerUtils::rescaleUom( format.size(), format.sizeUnit(), props );
357 fontElement.appendChild( QgsSymbolLayerUtils::createSvgParameterElement( doc, QStringLiteral( "font-size" ), QString::number( fontSize ) ) );
358 if ( format.font().italic() )
359 {
360 fontElement.appendChild( QgsSymbolLayerUtils::createSvgParameterElement( doc, QStringLiteral( "font-style" ), QStringLiteral( "italic" ) ) );
361 }
362 if ( format.font().bold() )
363 {
364 fontElement.appendChild( QgsSymbolLayerUtils::createSvgParameterElement( doc, QStringLiteral( "font-weight" ), QStringLiteral( "bold" ) ) );
365 }
366
367 // label placement
368 QDomElement labelPlacement = doc.createElement( QStringLiteral( "se:LabelPlacement" ) );
369 textSymbolizerElement.appendChild( labelPlacement );
370 double maxDisplacement = 0;
371 double repeatDistance = 0;
372 switch ( settings.placement )
373 {
375 {
376 QDomElement pointPlacement = doc.createElement( "se:PointPlacement" );
377 labelPlacement.appendChild( pointPlacement );
378 // anchor point
379 const QPointF anchor = quadOffsetToSldAnchor( settings.pointSettings().quadrant() );
380 QgsSymbolLayerUtils::createAnchorPointElement( doc, pointPlacement, anchor );
381 // displacement
382 if ( settings.xOffset != 0 || settings.yOffset != 0 )
383 {
384 const Qgis::RenderUnit offsetUnit = settings.offsetUnits;
385 const double dx = QgsSymbolLayerUtils::rescaleUom( settings.xOffset, offsetUnit, props );
386 const double dy = QgsSymbolLayerUtils::rescaleUom( settings.yOffset, offsetUnit, props );
387 QgsSymbolLayerUtils::createDisplacementElement( doc, pointPlacement, QPointF( dx, dy ) );
388 }
389 // rotation
390 if ( settings.angleOffset != 0 )
391 {
392 QDomElement rotation = doc.createElement( "se:Rotation" );
393 pointPlacement.appendChild( rotation );
394 rotation.appendChild( doc.createTextNode( QString::number( settings.angleOffset ) ) );
395 }
396 }
397 break;
400 {
401 QDomElement pointPlacement = doc.createElement( "se:PointPlacement" );
402 labelPlacement.appendChild( pointPlacement );
403
404 // SLD cannot do either, but let's do a best effort setting the distance using
405 // anchor point and displacement
406 QgsSymbolLayerUtils::createAnchorPointElement( doc, pointPlacement, QPointF( 0, 0.5 ) );
407 const Qgis::RenderUnit distUnit = settings.distUnits;
408 const double radius = QgsSymbolLayerUtils::rescaleUom( settings.dist, distUnit, props );
409 const double offset = std::sqrt( radius * radius / 2 ); // make it start top/right
410 maxDisplacement = radius + 1; // lock the distance
411 QgsSymbolLayerUtils::createDisplacementElement( doc, pointPlacement, QPointF( offset, offset ) );
412 }
413 break;
417 {
418 // still a point placement (for "free" it's a fallback, there is no SLD equivalent)
419 QDomElement pointPlacement = doc.createElement( "se:PointPlacement" );
420 labelPlacement.appendChild( pointPlacement );
421 QgsSymbolLayerUtils::createAnchorPointElement( doc, pointPlacement, QPointF( 0.5, 0.5 ) );
422 const Qgis::RenderUnit distUnit = settings.distUnits;
423 const double dist = QgsSymbolLayerUtils::rescaleUom( settings.dist, distUnit, props );
424 QgsSymbolLayerUtils::createDisplacementElement( doc, pointPlacement, QPointF( 0, dist ) );
425 break;
426 }
430 {
431 QDomElement linePlacement = doc.createElement( "se:LinePlacement" );
432 labelPlacement.appendChild( linePlacement );
433
434 // perpendicular distance if required
435 if ( settings.dist > 0 )
436 {
437 const Qgis::RenderUnit distUnit = settings.distUnits;
438 const double dist = QgsSymbolLayerUtils::rescaleUom( settings.dist, distUnit, props );
439 QDomElement perpendicular = doc.createElement( "se:PerpendicularOffset" );
440 linePlacement.appendChild( perpendicular );
441 perpendicular.appendChild( doc.createTextNode( qgsDoubleToString( dist, 2 ) ) );
442 }
443
444 // repeat distance if required
445 if ( settings.repeatDistance > 0 )
446 {
447 QDomElement repeat = doc.createElement( "se:Repeat" );
448 linePlacement.appendChild( repeat );
449 repeat.appendChild( doc.createTextNode( QStringLiteral( "true" ) ) );
450 QDomElement gap = doc.createElement( "se:Gap" );
451 linePlacement.appendChild( gap );
453 gap.appendChild( doc.createTextNode( qgsDoubleToString( repeatDistance, 2 ) ) );
454 }
455
456 // always generalized
457 QDomElement generalize = doc.createElement( "se:GeneralizeLine" );
458 linePlacement.appendChild( generalize );
459 generalize.appendChild( doc.createTextNode( QStringLiteral( "true" ) ) );
460 }
461 break;
462 }
463
464 // halo
465 const QgsTextBufferSettings buffer = format.buffer();
466 if ( buffer.enabled() )
467 {
468 QDomElement haloElement = doc.createElement( QStringLiteral( "se:Halo" ) );
469 textSymbolizerElement.appendChild( haloElement );
470
471 QDomElement radiusElement = doc.createElement( QStringLiteral( "se:Radius" ) );
472 haloElement.appendChild( radiusElement );
473 // the SLD uses a radius, which is actually half of the link thickness the buffer size specifies
474 const double radius = QgsSymbolLayerUtils::rescaleUom( buffer.size(), buffer.sizeUnit(), props ) / 2;
475 radiusElement.appendChild( doc.createTextNode( qgsDoubleToString( radius ) ) );
476
477 QDomElement fillElement = doc.createElement( QStringLiteral( "se:Fill" ) );
478 haloElement.appendChild( fillElement );
479 fillElement.appendChild( QgsSymbolLayerUtils::createSvgParameterElement( doc, QStringLiteral( "fill" ), buffer.color().name() ) );
480 if ( buffer.opacity() != 1 )
481 {
482 fillElement.appendChild( QgsSymbolLayerUtils::createSvgParameterElement( doc, QStringLiteral( "fill-opacity" ), QString::number( buffer.opacity() ) ) );
483 }
484 }
485
486 // fill
487 QDomElement fillElement = doc.createElement( QStringLiteral( "se:Fill" ) );
488 textSymbolizerElement.appendChild( fillElement );
489 fillElement.appendChild( QgsSymbolLayerUtils::createSvgParameterElement( doc, QStringLiteral( "fill" ), format.color().name() ) );
490 if ( format.opacity() != 1 )
491 {
492 fillElement.appendChild( QgsSymbolLayerUtils::createSvgParameterElement( doc, QStringLiteral( "fill-opacity" ), QString::number( format.opacity() ) ) );
493 }
494
495 // background graphic (not supported by SE 1.1, but supported by the GeoTools ecosystem as an extension)
496 const QgsTextBackgroundSettings background = format.background();
497 if ( background.enabled() )
498 {
499 std::unique_ptr<QgsMarkerSymbolLayer> layer = backgroundToMarkerLayer( background );
500 layer->writeSldMarker( doc, textSymbolizerElement, context );
501 }
502
503 // priority and zIndex, the default values are 0 and 5 in qgis (and between 0 and 10),
504 // in the GeoTools ecosystem there is a single priority value set at 1000 by default
505 if ( settings.priority != 5 || settings.zIndex > 0 )
506 {
507 QDomElement priorityElement = doc.createElement( QStringLiteral( "se:Priority" ) );
508 textSymbolizerElement.appendChild( priorityElement );
509 int priority = 500 + 1000 * settings.zIndex + ( settings.priority - 5 ) * 100;
510 if ( settings.priority == 0 && settings.zIndex > 0 )
511 {
512 // small adjustment to make sure labels in z index n+1 are all above level n despite the priority value
513 priority += 1;
514 }
515 priorityElement.appendChild( doc.createTextNode( QString::number( priority ) ) );
516 }
517
518 // vendor options for text appearance
519 if ( font.underline() )
520 {
521 const QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, QStringLiteral( "underlineText" ), QStringLiteral( "true" ) );
522 textSymbolizerElement.appendChild( vo );
523 }
524 if ( font.strikeOut() )
525 {
526 const QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, QStringLiteral( "strikethroughText" ), QStringLiteral( "true" ) );
527 textSymbolizerElement.appendChild( vo );
528 }
529 // vendor options for text positioning
530 if ( maxDisplacement > 0 )
531 {
532 const QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, QStringLiteral( "maxDisplacement" ), qgsDoubleToString( maxDisplacement, 2 ) );
533 textSymbolizerElement.appendChild( vo );
534 }
535
536 switch ( settings.placement )
537 {
540 {
541 const QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, QStringLiteral( "followLine" ), QStringLiteral( "true" ) );
542 textSymbolizerElement.appendChild( vo );
544 {
545 // SLD has no notion for this, the GeoTools ecosystem can only do a single angle
546 const double angle = std::min( std::fabs( settings.maxCurvedCharAngleIn ), std::fabs( settings.maxCurvedCharAngleOut ) );
547 const QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, QStringLiteral( "maxAngleDelta" ), qgsDoubleToString( angle ) );
548 textSymbolizerElement.appendChild( vo );
549 }
550 break;
551 }
552
560 break;
561 }
562
563 if ( repeatDistance > 0 )
564 {
565 const QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, QStringLiteral( "repeat" ), qgsDoubleToString( repeatDistance, 2 ) );
566 textSymbolizerElement.appendChild( vo );
567 }
568 // miscellaneous options
570 {
572 break;
575 const QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, QStringLiteral( "conflictResolution" ), QStringLiteral( "false" ) );
576 textSymbolizerElement.appendChild( vo );
577 break;
578 }
580 {
581 const QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, QStringLiteral( "forceLeftToRight" ), QStringLiteral( "false" ) );
582 textSymbolizerElement.appendChild( vo );
583 }
585 {
586 const QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, QStringLiteral( "group" ), QStringLiteral( "yes" ) );
587 textSymbolizerElement.appendChild( vo );
589 {
590 const QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, QStringLiteral( "labelAllGroup" ), QStringLiteral( "true" ) );
591 textSymbolizerElement.appendChild( vo );
592 }
593 }
594 // background symbol resize handling
595 if ( background.enabled() )
596 {
597 // enable resizing if needed
598 switch ( background.sizeType() )
599 {
601 {
602 QString resizeType;
604 {
605 resizeType = QStringLiteral( "stretch" );
606 }
607 else
608 {
609 resizeType = QStringLiteral( "proportional" );
610 }
611 const QDomElement voResize = QgsSymbolLayerUtils::createVendorOptionElement( doc, QStringLiteral( "graphic-resize" ), resizeType );
612 textSymbolizerElement.appendChild( voResize );
613
614 // now hadle margin
615 const QSizeF size = background.size();
616 if ( size.width() > 0 || size.height() > 0 )
617 {
618 double x = QgsSymbolLayerUtils::rescaleUom( size.width(), background.sizeUnit(), props );
619 double y = QgsSymbolLayerUtils::rescaleUom( size.height(), background.sizeUnit(), props );
620 // in case of ellipse qgis pads the size generously to make sure the text is inside the ellipse
621 // the following seems to do the trick and keep visual output similar
622 if ( background.type() == QgsTextBackgroundSettings::ShapeEllipse )
623 {
624 x += fontSize / 2;
625 y += fontSize;
626 }
627 const QString resizeSpec = QString( "%1 %2" ).arg( qgsDoubleToString( x, 2 ), qgsDoubleToString( y, 2 ) );
628 const QDomElement voMargin = QgsSymbolLayerUtils::createVendorOptionElement( doc, QStringLiteral( "graphic-margin" ), resizeSpec );
629 textSymbolizerElement.appendChild( voMargin );
630 }
631 break;
632 }
635 // nothing to do here
636 break;
637 }
638 }
639 return true;
640}
641
642void QgsVectorLayerSimpleLabeling::toSld( QDomNode &parent, const QVariantMap &props ) const
643{
644 QgsSldExportContext context;
645 context.setExtraProperties( props );
646 toSld( parent, context );
647}
648
649bool QgsVectorLayerSimpleLabeling::toSld( QDomNode &parent, QgsSldExportContext &context ) const
650{
651 if ( mSettings->drawLabels )
652 {
653 QDomDocument doc = parent.ownerDocument();
654
655 QDomElement ruleElement = doc.createElement( QStringLiteral( "se:Rule" ) );
656 parent.appendChild( ruleElement );
657
658 // scale dependencies
659 if ( mSettings->scaleVisibility )
660 {
661 QVariantMap scaleProps = QVariantMap();
662 // tricky here, the max scale is expressed as its denominator, but it's still the max scale
663 // in other words, the smallest scale denominator....
664 scaleProps.insert( "scaleMinDenom", qgsDoubleToString( mSettings->maximumScale ) );
665 scaleProps.insert( "scaleMaxDenom", qgsDoubleToString( mSettings->minimumScale ) );
666 QgsSymbolLayerUtils::applyScaleDependency( doc, ruleElement, scaleProps );
667 }
668
669 writeTextSymbolizer( ruleElement, *mSettings, context );
670 }
671 return true;
672}
673
675{
676 QgsTextFormat format { mSettings->format() };
677 format.multiplyOpacity( opacityFactor );
678 mSettings->setFormat( format );
679}
680
681void QgsVectorLayerSimpleLabeling::setSettings( QgsPalLayerSettings *settings, const QString &providerId )
682{
683 Q_UNUSED( providerId )
684
685 if ( mSettings.get() == settings )
686 return;
687
688 mSettings.reset( settings );
689}
@ FromSymbolBounds
Offset distance applies from rendered symbol bounds.
@ OverPoint
Arranges candidates over a point (or centroid of a polygon), or at a preset offset from the point....
@ Curved
Arranges candidates following the curvature of a line feature. Applies to line layers only.
@ AroundPoint
Arranges candidates in a circle around a point (or centroid of a polygon). Applies to point or polygo...
@ Line
Arranges candidates parallel to a generalised line representing the feature or parallel to a polygon'...
@ Free
Arranges candidates scattered throughout a polygon feature. Candidates are rotated to respect the pol...
@ OrderedPositionsAroundPoint
Candidates are placed in predefined positions around a point. Preference is given to positions with g...
@ Horizontal
Arranges horizontal candidates scattered throughout a polygon feature. Applies to polygon layers only...
@ PerimeterCurved
Arranges candidates following the curvature of a polygon's boundary. Applies to polygon layers only.
@ OutsidePolygons
Candidates are placed outside of polygon boundaries. Applies to polygon layers only.
MarkerShape
Marker shapes.
Definition qgis.h:2974
Capitalization
String capitalization options.
Definition qgis.h:3257
@ MixedCase
Mixed case, ie no change.
@ AllLowercase
Convert all characters to lowercase.
@ ForceFirstLetterToCapital
Convert just the first letter of each word to uppercase, leave the rest untouched.
@ AllUppercase
Convert all characters to uppercase.
LabelQuadrantPosition
Label quadrant positions.
Definition qgis.h:1219
@ Polygon
Polygons.
@ Unknown
Unknown types.
@ Null
No geometry.
RenderUnit
Rendering size units.
Definition qgis.h:5029
@ AllowOverlapAtNoCost
Labels may freely overlap other labels, at no cost.
@ AllowOverlapIfRequired
Avoids overlapping labels when possible, but permit overlaps if labels for features cannot otherwise ...
@ PreventOverlap
Do not allow labels to overlap other labels.
@ AlwaysAllowUpsideDown
Show upside down for all labels, including dynamic ones.
Abstract base class - its implementations define different approaches to the labeling of a vector lay...
virtual bool accept(QgsStyleEntityVisitorInterface *visitor) const
Accepts the specified symbology visitor, causing it to visit all symbols associated with the labeling...
virtual Q_DECL_DEPRECATED void toSld(QDomNode &parent, const QVariantMap &props) const
Writes the SE 1.1 TextSymbolizer element based on the current layer labeling settings.
virtual Q_DECL_DEPRECATED void writeTextSymbolizer(QDomNode &parent, QgsPalLayerSettings &settings, const QVariantMap &props) const
Writes a TextSymbolizer element contents based on the provided labeling settings.
static QgsAbstractVectorLayerLabeling * create(const QDomElement &element, const QgsReadWriteContext &context)
Try to create instance of an implementation based on the XML data.
virtual QgsPalLayerSettings settings(const QString &providerId=QString()) const =0
Gets associated label settings.
static QgsPalLayerSettings defaultSettingsForLayer(const QgsVectorLayer *layer)
Returns the default layer settings to use for the specified vector layer.
virtual QString type() const =0
Unique type string of the labeling configuration implementation.
QString dump() const
Returns an expression string, constructed from the internal abstract syntax tree.
bool mergeLines() const
Returns true if connected line features with identical label text should be merged prior to generatin...
Qgis::LabelOverlapHandling overlapHandling() const
Returns the technique used to handle overlapping labels.
Qgis::LabelQuadrantPosition quadrant() const
Returns the quadrant in which to offset labels from the point.
QgsProject * project() const
Returns the parent project if this map layer is added to a project.
Abstract base class for marker symbol layers.
Contains settings for how a map layer will be labeled.
double yOffset
Vertical offset of label.
const QgsLabelPlacementSettings & placementSettings() const
Returns the label placement settings.
double maxCurvedCharAngleIn
Maximum angle between inside curved label characters (valid range 20.0 to 60.0).
void setFormat(const QgsTextFormat &format)
Sets the label text formatting settings, e.g., font settings, buffer settings, etc.
double zIndex
Z-Index of label, where labels with a higher z-index are rendered on top of labels with a lower z-ind...
Qgis::LabelOffsetType offsetType
Offset type for layer (only applies in certain placement modes)
double xOffset
Horizontal offset of label.
Qgis::LabelPlacement placement
Label placement mode.
QgsExpression * getLabelExpression()
Returns the QgsExpression for this label settings.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Read settings from a DOM element.
double repeatDistance
Distance for repeating labels for a single feature.
int priority
Label priority.
bool labelPerPart
true if every part of a multi-part feature should be labeled.
double angleOffset
Label rotation, in degrees clockwise.
double maxCurvedCharAngleOut
Maximum angle between outside curved label characters (valid range -20.0 to -95.0)
Qgis::RenderUnit offsetUnits
Units for offsets of label.
bool isExpression
true if this label is made from a expression string, e.g., FieldName || 'mm'
const QgsLabelLineSettings & lineSettings() const
Returns the label line settings, which contain settings related to how the label engine places and fo...
double dist
Distance from feature to the label.
Qgis::RenderUnit distUnits
Units the distance from feature to the label.
@ FontBlendMode
Text blend mode.
Qgis::RenderUnit repeatDistanceUnit
Units for repeating labels for a single feature.
Qgis::UpsideDownLabelHandling upsidedownLabels
Controls whether upside down labels are displayed and how they are handled.
QString fieldName
Name of field (or an expression) to use for label text.
const QgsTextFormat & format() const
Returns the label text formatting settings, e.g., font settings, buffer settings, etc.
const QgsLabelPointSettings & pointSettings() const
Returns the label point settings, which contain settings related to how the label engine places and f...
A container for the context for various read/write operations on objects.
static QgsRuleBasedLabeling * create(const QDomElement &element, const QgsReadWriteContext &context)
Create the instance from a DOM element with saved configuration.
void setShape(Qgis::MarkerShape shape)
Sets the rendered marker shape.
Simple marker symbol layer, consisting of a rendered shape with solid fill color and a stroke.
void setStrokeWidthUnit(Qgis::RenderUnit u)
Sets the unit for the width of the marker's stroke.
void setStrokeWidth(double w)
Sets the width of the marker's stroke.
Holds SLD export options and other information related to SLD export of a QGIS layer style.
void setExtraProperties(const QVariantMap &properties)
Sets the open ended set of properties that can drive/inform the SLD encoding.
QVariantMap extraProperties() const
Returns the open ended set of properties that can drive/inform the SLD encoding.
void pushError(const QString &error)
Pushes a error message generated during the conversion.
An interface for classes which can visit style entity (e.g.
virtual bool visit(const QgsStyleEntityVisitorInterface::StyleLeaf &entity)
Called when the visitor will visit a style entity.
A label settings entity for QgsStyle databases.
Definition qgsstyle.h:1490
static QgsTextFormat defaultTextFormatForProject(QgsProject *project, QgsStyle::TextFormatContext context=QgsStyle::TextFormatContext::Labeling)
Returns the default text format to use for new text based objects for the specified project,...
A marker symbol layer which renders an SVG graphic.
void setStrokeWidthUnit(Qgis::RenderUnit unit)
Sets the units for the stroke width.
static void createAnchorPointElement(QDomDocument &doc, QDomElement &element, QPointF anchor)
Creates a SE 1.1 anchor point element as a child of the specified element.
static void applyScaleDependency(QDomDocument &doc, QDomElement &ruleElem, QVariantMap &props)
Checks if the properties contain scaleMinDenom and scaleMaxDenom, if available, they are added into t...
static double rescaleUom(double size, Qgis::RenderUnit unit, const QVariantMap &props)
Rescales the given size based on the uomScale found in the props, if any is found,...
static QDomElement createVendorOptionElement(QDomDocument &doc, const QString &name, const QString &value)
static void createDisplacementElement(QDomDocument &doc, QDomElement &element, QPointF offset)
static QDomElement createSvgParameterElement(QDomDocument &doc, const QString &name, const QString &value)
virtual QgsSymbolLayer * clone() const =0
Shall be reimplemented by subclasses to create a deep copy of the instance.
QgsSymbolLayer * symbolLayer(int layer)
Returns the symbol layer at the specified index.
int symbolLayerCount() const
Returns the total number of symbol layers contained in the symbol.
Definition qgssymbol.h:353
Container for settings relating to a text background object.
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.
@ SizePercent
Shape size is determined by percent of text size.
@ SizeBuffer
Shape size is determined by adding a buffer margin around text.
bool enabled() const
Returns whether the background is enabled.
double opacity() const
Returns the background shape's opacity.
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.
SizeType sizeType() const
Returns the method used to determine the size of the background shape (e.g., fixed size or buffer aro...
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).
@ ShapeSquare
Square - buffered sizes only.
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.
Qgis::RenderUnit sizeUnit() const
Returns the units used for the shape's size.
@ RotationFixed
Shape rotation is a fixed angle.
QgsMarkerSymbol * markerSymbol() const
Returns the marker symbol to be rendered in the background.
QPointF offset() const
Returns the offset used for drawing the background shape.
Container for settings relating to a text buffer.
Qgis::RenderUnit sizeUnit() const
Returns the units for the buffer size.
double size() const
Returns the size of the buffer.
bool enabled() const
Returns whether the buffer is enabled.
double opacity() const
Returns the buffer opacity.
QColor color() const
Returns the color of the buffer.
Container for all settings relating to text rendering.
Qgis::Capitalization capitalization() const
Returns the text capitalization style.
QgsTextBackgroundSettings & background()
Returns a reference to the text background settings.
Qgis::RenderUnit sizeUnit() const
Returns the units for the size of rendered text.
double opacity() const
Returns the text's opacity.
double size() const
Returns the size for rendered text.
QColor color() const
Returns the color that text will be rendered in.
QFont font() const
Returns the font used for rendering text.
QgsTextBufferSettings & buffer()
Returns a reference to the text buffer settings.
Implements a label provider for vector layers.
Basic implementation of the labeling interface.
QString type() const override
Unique type string of the labeling configuration implementation.
void multiplyOpacity(double opacityFactor) override
Multiply opacity by opacityFactor.
bool accept(QgsStyleEntityVisitorInterface *visitor) const override
Accepts the specified symbology visitor, causing it to visit all symbols associated with the labeling...
QgsPalLayerSettings settings(const QString &providerId=QString()) const override
Gets associated label settings.
QDomElement save(QDomDocument &doc, const QgsReadWriteContext &context) const override
Returns labeling configuration as XML element.
bool requiresAdvancedEffects() const override
Returns true if drawing labels requires advanced effects like composition modes, which could prevent ...
QgsVectorLayerSimpleLabeling(const QgsPalLayerSettings &settings)
Constructs simple labeling configuration with given initial settings.
void setSettings(QgsPalLayerSettings *settings, const QString &providerId=QString()) override
Set pal settings (takes ownership).
QgsVectorLayerLabelProvider * provider(QgsVectorLayer *layer) const override
static QgsVectorLayerSimpleLabeling * create(const QDomElement &element, const QgsReadWriteContext &context)
Create the instance from a DOM element with saved configuration.
QgsAbstractVectorLayerLabeling * clone() const override
Returns a new copy of the object.
Q_DECL_DEPRECATED void toSld(QDomNode &parent, const QVariantMap &props) const override
Writes the SE 1.1 TextSymbolizer element based on the current layer labeling settings.
bool hasNonDefaultCompositionMode() const override
Returns true the labeling requires a non-default composition mode.
Represents a vector layer which manages a vector based dataset.
Q_INVOKABLE Qgis::GeometryType geometryType() const
Returns point, line or polygon.
QString displayField() const
This is a shorthand for accessing the displayExpression if it is a simple field.
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
Definition qgis.h:6219
std::unique_ptr< QgsMarkerSymbolLayer > backgroundToMarkerLayer(const QgsTextBackgroundSettings &settings)
void appendSimpleFunction(QDomDocument &doc, QDomElement &parent, const QString &name, const QString &attribute)
QPointF quadOffsetToSldAnchor(Qgis::LabelQuadrantPosition quadrantPosition)