QGIS API Documentation 4.1.0-Master (31622b25bb0)
Loading...
Searching...
No Matches
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 "qgis.h"
18#include "qgsexpression.h"
19#include "qgsmarkersymbol.h"
21#include "qgsogcutils.h"
22#include "qgspallabeling.h"
24#include "qgssldexportcontext.h"
26#include "qgssymbollayer.h"
27#include "qgssymbollayerutils.h"
28#include "qgsvectorlayer.h"
29
30#include <QString>
31
32using namespace Qt::StringLiterals;
33
35{
36 const QString type = element.attribute( u"type"_s );
37 if ( type == "rule-based"_L1 )
38 {
39 return QgsRuleBasedLabeling::create( element, context );
40 }
41 else if ( type == "simple"_L1 )
42 {
43 return QgsVectorLayerSimpleLabeling::create( element, context );
44 }
45 else
46 {
47 return nullptr;
48 }
49}
50
51void QgsAbstractVectorLayerLabeling::toSld( QDomNode &parent, const QVariantMap &props ) const
52{
53 QgsSldExportContext context;
54 context.setExtraProperties( props );
55 toSld( parent, context );
56}
57
59{
60 context.pushError( QObject::tr( "%1 labeling cannot be exported to SLD" ).arg( type() ) );
61 return false;
62}
63
68
94
96{
97 return new QgsVectorLayerLabelProvider( layer, QString(), false, mSettings.get() );
98}
99
103
105{
106 return u"simple"_s;
107}
108
113
114QDomElement QgsVectorLayerSimpleLabeling::save( QDomDocument &doc, const QgsReadWriteContext &context ) const
115{
116 QDomElement elem = doc.createElement( u"labeling"_s );
117 elem.setAttribute( u"type"_s, u"simple"_s );
118 elem.appendChild( mSettings->writeXml( doc, context ) );
119 return elem;
120}
121
123{
124 Q_UNUSED( providerId )
125 return *mSettings;
126}
127
129{
130 if ( mSettings )
131 {
132 QgsStyleLabelSettingsEntity entity( *mSettings );
133 if ( !visitor->visit( &entity ) )
134 return false;
135 }
136 return true;
137}
138
143
145{
146 return mSettings->dataDefinedProperties().isActive( QgsPalLayerSettings::Property::FontBlendMode )
147 || mSettings->dataDefinedProperties().isActive( QgsPalLayerSettings::Property::ShapeBlendMode )
148 || mSettings->dataDefinedProperties().isActive( QgsPalLayerSettings::Property::BufferBlendMode )
149 || mSettings->dataDefinedProperties().isActive( QgsPalLayerSettings::Property::ShadowBlendMode )
150 || mSettings->format().hasNonDefaultCompositionMode();
151}
152
153QgsVectorLayerSimpleLabeling *QgsVectorLayerSimpleLabeling::create( const QDomElement &element, const QgsReadWriteContext &context ) // cppcheck-suppress duplInheritedMember
154{
155 const QDomElement settingsElem = element.firstChildElement( u"settings"_s );
156 if ( !settingsElem.isNull() )
157 {
159 settings.readXml( settingsElem, context );
161 }
162
164}
165
167{
168 double quadOffsetX = 0.5, quadOffsetY = 0.5;
169
170 // adjust quadrant offset of labels
171 switch ( quadrantPosition )
172 {
174 quadOffsetX = 1;
175 quadOffsetY = 0;
176 break;
178 quadOffsetX = 0.5;
179 quadOffsetY = 0;
180 break;
182 quadOffsetX = 0;
183 quadOffsetY = 0;
184 break;
186 quadOffsetX = 1;
187 quadOffsetY = 0.5;
188 break;
190 quadOffsetX = 0;
191 quadOffsetY = 0.5;
192 break;
194 quadOffsetX = 1;
195 quadOffsetY = 1;
196 break;
198 quadOffsetX = 0.5;
199 quadOffsetY = 1;
200 break;
202 quadOffsetX = 0;
203 quadOffsetY = 1.0;
204 break;
206 break;
207 }
208
209 return QPointF( quadOffsetX, quadOffsetY );
210}
211
212/*
213 * This is not a generic function encoder, just enough to encode the label case control functions
214 */
215void appendSimpleFunction( QDomDocument &doc, QDomElement &parent, const QString &name, const QString &attribute )
216{
217 QDomElement function = doc.createElement( u"ogc:Function"_s );
218 function.setAttribute( u"name"_s, name );
219 parent.appendChild( function );
220 QDomElement property = doc.createElement( u"ogc:PropertyName"_s );
221 property.appendChild( doc.createTextNode( attribute ) );
222 function.appendChild( property );
223}
224
225std::unique_ptr<QgsMarkerSymbolLayer> backgroundToMarkerLayer( const QgsTextBackgroundSettings &settings )
226{
227 std::unique_ptr<QgsMarkerSymbolLayer> layer;
228 switch ( settings.type() )
229 {
231 {
233 svg->setStrokeWidth( settings.strokeWidth() );
234 svg->setStrokeWidthUnit( settings.strokeWidthUnit() );
235 layer.reset( svg );
236 break;
237 }
239 {
240 // just grab the first layer and hope for the best
241 if ( settings.markerSymbol() && settings.markerSymbol()->symbolLayerCount() > 0 )
242 {
243 layer.reset( static_cast< QgsMarkerSymbolLayer * >( settings.markerSymbol()->symbolLayer( 0 )->clone() ) );
244 break;
245 }
246 [[fallthrough]]; // not set, just go with the default
247 }
252 {
254 // default value
256 switch ( settings.type() )
257 {
261 break;
265 break;
268 break;
269 }
270
271 marker->setShape( shape );
272 marker->setStrokeWidth( settings.strokeWidth() );
273 marker->setStrokeWidthUnit( settings.strokeWidthUnit() );
274 layer.reset( marker );
275 }
276 }
277 layer->setEnabled( true );
278 // a marker does not have a size x and y, just a size (and it should be at least one)
279 const QSizeF size = settings.size();
280 layer->setSize( std::max( 1., std::max( size.width(), size.height() ) ) );
281 layer->setSizeUnit( settings.sizeUnit() );
282 // fill and stroke
283 QColor fillColor = settings.fillColor();
284 QColor strokeColor = settings.strokeColor();
285 if ( settings.opacity() < 1 )
286 {
287 const int alpha = std::round( settings.opacity() * 255 );
288 fillColor.setAlpha( alpha );
289 strokeColor.setAlpha( alpha );
290 }
291 layer->setFillColor( fillColor );
292 layer->setStrokeColor( strokeColor );
293 // rotation
295 {
296 layer->setAngle( settings.rotation() );
297 }
298 // offset
299 layer->setOffset( settings.offset() );
300 layer->setOffsetUnit( settings.offsetUnit() );
301
302 return layer;
303}
304
305void QgsAbstractVectorLayerLabeling::writeTextSymbolizer( QDomNode &parent, QgsPalLayerSettings &settings, const QVariantMap &props ) const
306{
307 QgsSldExportContext context;
308 context.setExtraProperties( props );
309 writeTextSymbolizer( parent, settings, context );
310}
311
313{
314 QDomDocument doc = parent.ownerDocument();
315
316 // text symbolizer
317 QDomElement textSymbolizerElement = doc.createElement( u"se:TextSymbolizer"_s );
318 parent.appendChild( textSymbolizerElement );
319
320 // label
321 QgsTextFormat format = settings.format();
322 const QFont font = format.font();
323 QDomElement labelElement = doc.createElement( u"se:Label"_s );
324 textSymbolizerElement.appendChild( labelElement );
325
326 if ( settings.isExpression )
327 {
328 QString errorMsg;
329 // try to convert the expression to an SLD expression, if it fails we will log the error and add a placeholder text
330 QDomElement expressionElem = QgsOgcUtils::expressionToOgcExpression( *settings.getLabelExpression(), doc, &errorMsg );
331
332 if ( !expressionElem.isNull() )
333 {
334 labelElement.appendChild( expressionElem );
335 }
336 else
337 {
338 context.pushError( QObject::tr( "Complex expressions in labels cannot be exported to SLD: %1. Skipping label '%2'" ).arg( errorMsg, settings.getLabelExpression()->dump() ) );
339 labelElement.appendChild( doc.createTextNode( u"Placeholder"_s ) );
340 }
341 }
342
343 else
344 {
345 Qgis::Capitalization capitalization = format.capitalization();
346 if ( capitalization == Qgis::Capitalization::MixedCase && font.capitalization() != QFont::MixedCase )
347 capitalization = static_cast< Qgis::Capitalization >( font.capitalization() );
348 if ( capitalization == Qgis::Capitalization::AllUppercase )
349 {
350 appendSimpleFunction( doc, labelElement, u"strToUpperCase"_s, settings.fieldName );
351 }
352 else if ( capitalization == Qgis::Capitalization::AllLowercase )
353 {
354 appendSimpleFunction( doc, labelElement, u"strToLowerCase"_s, settings.fieldName );
355 }
356 else if ( capitalization == Qgis::Capitalization::ForceFirstLetterToCapital )
357 {
358 appendSimpleFunction( doc, labelElement, u"strCapitalize"_s, settings.fieldName );
359 }
360 else
361 {
362 QDomElement propertyNameElement = doc.createElement( u"ogc:PropertyName"_s );
363 propertyNameElement.appendChild( doc.createTextNode( settings.fieldName ) );
364 labelElement.appendChild( propertyNameElement );
365 }
366 }
367
368 // font
369 QDomElement fontElement = doc.createElement( u"se:Font"_s );
370 textSymbolizerElement.appendChild( fontElement );
371 fontElement.appendChild( QgsSymbolLayerUtils::createSvgParameterElement( doc, u"font-family"_s, font.family() ) );
372 const QVariantMap props = context.extraProperties();
373 const double fontSize = QgsSymbolLayerUtils::rescaleUom( format.size(), format.sizeUnit(), props );
374 fontElement.appendChild( QgsSymbolLayerUtils::createSvgParameterElement( doc, u"font-size"_s, QString::number( fontSize ) ) );
375 if ( format.font().italic() )
376 {
377 fontElement.appendChild( QgsSymbolLayerUtils::createSvgParameterElement( doc, u"font-style"_s, u"italic"_s ) );
378 }
379 if ( format.font().bold() )
380 {
381 fontElement.appendChild( QgsSymbolLayerUtils::createSvgParameterElement( doc, u"font-weight"_s, u"bold"_s ) );
382 }
383
384 // label placement
385 QDomElement labelPlacement = doc.createElement( u"se:LabelPlacement"_s );
386 textSymbolizerElement.appendChild( labelPlacement );
387 double maxDisplacement = 0;
388 double repeatDistance = 0;
389 switch ( settings.placement )
390 {
392 {
393 QDomElement pointPlacement = doc.createElement( "se:PointPlacement" );
394 labelPlacement.appendChild( pointPlacement );
395 // anchor point
396 const QPointF anchor = quadOffsetToSldAnchor( settings.pointSettings().quadrant() );
397 QgsSymbolLayerUtils::createAnchorPointElement( doc, pointPlacement, anchor );
398 // displacement
399 if ( settings.xOffset != 0 || settings.yOffset != 0 )
400 {
401 const Qgis::RenderUnit offsetUnit = settings.offsetUnits;
402 const double dx = QgsSymbolLayerUtils::rescaleUom( settings.xOffset, offsetUnit, props );
403 const double dy = QgsSymbolLayerUtils::rescaleUom( settings.yOffset, offsetUnit, props );
404 QgsSymbolLayerUtils::createDisplacementElement( doc, pointPlacement, QPointF( dx, dy ) );
405 }
406 // rotation
407 if ( settings.angleOffset != 0 )
408 {
409 QDomElement rotation = doc.createElement( "se:Rotation" );
410 pointPlacement.appendChild( rotation );
411 rotation.appendChild( doc.createTextNode( QString::number( settings.angleOffset ) ) );
412 }
413 }
414 break;
417 {
418 QDomElement pointPlacement = doc.createElement( "se:PointPlacement" );
419 labelPlacement.appendChild( pointPlacement );
420
421 // SLD cannot do either, but let's do a best effort setting the distance using
422 // anchor point and displacement
423 QgsSymbolLayerUtils::createAnchorPointElement( doc, pointPlacement, QPointF( 0, 0.5 ) );
424 const Qgis::RenderUnit distUnit = settings.distUnits;
425 const double radius = QgsSymbolLayerUtils::rescaleUom( settings.dist, distUnit, props );
426 const double offset = std::sqrt( radius * radius / 2 ); // make it start top/right
427 maxDisplacement = radius + 1; // lock the distance
428 QgsSymbolLayerUtils::createDisplacementElement( doc, pointPlacement, QPointF( offset, offset ) );
429 }
430 break;
434 {
435 // still a point placement (for "free" it's a fallback, there is no SLD equivalent)
436 QDomElement pointPlacement = doc.createElement( "se:PointPlacement" );
437 labelPlacement.appendChild( pointPlacement );
438 QgsSymbolLayerUtils::createAnchorPointElement( doc, pointPlacement, QPointF( 0.5, 0.5 ) );
439 const Qgis::RenderUnit distUnit = settings.distUnits;
440 const double dist = QgsSymbolLayerUtils::rescaleUom( settings.dist, distUnit, props );
441 QgsSymbolLayerUtils::createDisplacementElement( doc, pointPlacement, QPointF( 0, dist ) );
442 break;
443 }
447 {
448 QDomElement linePlacement = doc.createElement( "se:LinePlacement" );
449 labelPlacement.appendChild( linePlacement );
450
451 // perpendicular distance if required
452 if ( settings.dist > 0 )
453 {
454 const Qgis::RenderUnit distUnit = settings.distUnits;
455 const double dist = QgsSymbolLayerUtils::rescaleUom( settings.dist, distUnit, props );
456 QDomElement perpendicular = doc.createElement( "se:PerpendicularOffset" );
457 linePlacement.appendChild( perpendicular );
458 perpendicular.appendChild( doc.createTextNode( qgsDoubleToString( dist, 2 ) ) );
459 }
460
461 // repeat distance if required
462 if ( settings.repeatDistance > 0 )
463 {
464 QDomElement repeat = doc.createElement( "se:Repeat" );
465 linePlacement.appendChild( repeat );
466 repeat.appendChild( doc.createTextNode( u"true"_s ) );
467 QDomElement gap = doc.createElement( "se:Gap" );
468 linePlacement.appendChild( gap );
469 repeatDistance = QgsSymbolLayerUtils::rescaleUom( settings.repeatDistance, settings.repeatDistanceUnit, props );
470 gap.appendChild( doc.createTextNode( qgsDoubleToString( repeatDistance, 2 ) ) );
471 }
472
473 // always generalized
474 QDomElement generalize = doc.createElement( "se:GeneralizeLine" );
475 linePlacement.appendChild( generalize );
476 generalize.appendChild( doc.createTextNode( u"true"_s ) );
477 }
478 break;
479 }
480
481 // halo
482 const QgsTextBufferSettings buffer = format.buffer();
483 if ( buffer.enabled() )
484 {
485 QDomElement haloElement = doc.createElement( u"se:Halo"_s );
486 textSymbolizerElement.appendChild( haloElement );
487
488 QDomElement radiusElement = doc.createElement( u"se:Radius"_s );
489 haloElement.appendChild( radiusElement );
490 // the SLD uses a radius, which is actually half of the link thickness the buffer size specifies
491 const double radius = QgsSymbolLayerUtils::rescaleUom( buffer.size(), buffer.sizeUnit(), props ) / 2;
492 radiusElement.appendChild( doc.createTextNode( qgsDoubleToString( radius ) ) );
493
494 QDomElement fillElement = doc.createElement( u"se:Fill"_s );
495 haloElement.appendChild( fillElement );
496 fillElement.appendChild( QgsSymbolLayerUtils::createSvgParameterElement( doc, u"fill"_s, buffer.color().name() ) );
497 if ( buffer.opacity() != 1 )
498 {
499 fillElement.appendChild( QgsSymbolLayerUtils::createSvgParameterElement( doc, u"fill-opacity"_s, QString::number( buffer.opacity() ) ) );
500 }
501 }
502
503 // fill
504 QDomElement fillElement = doc.createElement( u"se:Fill"_s );
505 textSymbolizerElement.appendChild( fillElement );
506 fillElement.appendChild( QgsSymbolLayerUtils::createSvgParameterElement( doc, u"fill"_s, format.color().name() ) );
507 if ( format.opacity() != 1 )
508 {
509 fillElement.appendChild( QgsSymbolLayerUtils::createSvgParameterElement( doc, u"fill-opacity"_s, QString::number( format.opacity() ) ) );
510 }
511
512 // background graphic (not supported by SE 1.1, but supported by the GeoTools ecosystem as an extension)
513 const QgsTextBackgroundSettings background = format.background();
514 if ( background.enabled() )
515 {
516 std::unique_ptr<QgsMarkerSymbolLayer> layer = backgroundToMarkerLayer( background );
517 layer->writeSldMarker( doc, textSymbolizerElement, context );
518 }
519
520 // priority and zIndex, the default values are 0 and 5 in qgis (and between 0 and 10),
521 // in the GeoTools ecosystem there is a single priority value set at 1000 by default
522 if ( settings.priority != 5 || settings.zIndex > 0 )
523 {
524 QDomElement priorityElement = doc.createElement( u"se:Priority"_s );
525 textSymbolizerElement.appendChild( priorityElement );
526 int priority = 500 + 1000 * settings.zIndex + ( settings.priority - 5 ) * 100;
527 if ( settings.priority == 0 && settings.zIndex > 0 )
528 {
529 // small adjustment to make sure labels in z index n+1 are all above level n despite the priority value
530 priority += 1;
531 }
532 priorityElement.appendChild( doc.createTextNode( QString::number( priority ) ) );
533 }
534
535 // vendor options for text appearance
536 if ( font.underline() )
537 {
538 const QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, u"underlineText"_s, u"true"_s );
539 textSymbolizerElement.appendChild( vo );
540 }
541 if ( font.strikeOut() )
542 {
543 const QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, u"strikethroughText"_s, u"true"_s );
544 textSymbolizerElement.appendChild( vo );
545 }
546 // vendor options for text positioning
547 if ( maxDisplacement > 0 )
548 {
549 const QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, u"maxDisplacement"_s, qgsDoubleToString( maxDisplacement, 2 ) );
550 textSymbolizerElement.appendChild( vo );
551 }
552
553 switch ( settings.placement )
554 {
557 {
558 const QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, u"followLine"_s, u"true"_s );
559 textSymbolizerElement.appendChild( vo );
560 if ( settings.maxCurvedCharAngleIn > 0 || settings.maxCurvedCharAngleOut > 0 )
561 {
562 // SLD has no notion for this, the GeoTools ecosystem can only do a single angle
563 const double angle = std::min( std::fabs( settings.maxCurvedCharAngleIn ), std::fabs( settings.maxCurvedCharAngleOut ) );
564 const QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, u"maxAngleDelta"_s, qgsDoubleToString( angle ) );
565 textSymbolizerElement.appendChild( vo );
566 }
567 break;
568 }
569
577 break;
578 }
579
580 if ( repeatDistance > 0 )
581 {
582 const QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, u"repeat"_s, qgsDoubleToString( repeatDistance, 2 ) );
583 textSymbolizerElement.appendChild( vo );
584 }
585 // miscellaneous options
586 switch ( settings.placementSettings().overlapHandling() )
587 {
589 break;
592 const QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, u"conflictResolution"_s, u"false"_s );
593 textSymbolizerElement.appendChild( vo );
594 break;
595 }
597 {
598 const QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, u"forceLeftToRight"_s, u"false"_s );
599 textSymbolizerElement.appendChild( vo );
600 }
601 if ( settings.lineSettings().mergeLines() )
602 {
603 const QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, u"group"_s, u"yes"_s );
604 textSymbolizerElement.appendChild( vo );
605 switch ( settings.placementSettings().multiPartBehavior() )
606 {
609 break;
611 {
612 const QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, u"labelAllGroup"_s, u"true"_s );
613 textSymbolizerElement.appendChild( vo );
614 break;
615 }
616 }
617 }
618 // background symbol resize handling
619 if ( background.enabled() )
620 {
621 // enable resizing if needed
622 switch ( background.sizeType() )
623 {
625 {
626 QString resizeType;
628 {
629 resizeType = u"stretch"_s;
630 }
631 else
632 {
633 resizeType = u"proportional"_s;
634 }
635 const QDomElement voResize = QgsSymbolLayerUtils::createVendorOptionElement( doc, u"graphic-resize"_s, resizeType );
636 textSymbolizerElement.appendChild( voResize );
637
638 // now hadle margin
639 const QSizeF size = background.size();
640 if ( size.width() > 0 || size.height() > 0 )
641 {
642 double x = QgsSymbolLayerUtils::rescaleUom( size.width(), background.sizeUnit(), props );
643 double y = QgsSymbolLayerUtils::rescaleUom( size.height(), background.sizeUnit(), props );
644 // in case of ellipse qgis pads the size generously to make sure the text is inside the ellipse
645 // the following seems to do the trick and keep visual output similar
646 if ( background.type() == QgsTextBackgroundSettings::ShapeEllipse )
647 {
648 x += fontSize / 2;
649 y += fontSize;
650 }
651 const QString resizeSpec = QString( "%1 %2" ).arg( qgsDoubleToString( x, 2 ), qgsDoubleToString( y, 2 ) );
652 const QDomElement voMargin = QgsSymbolLayerUtils::createVendorOptionElement( doc, u"graphic-margin"_s, resizeSpec );
653 textSymbolizerElement.appendChild( voMargin );
654 }
655 break;
656 }
659 // nothing to do here
660 break;
661 }
662 }
663 return true;
664}
665
666void QgsVectorLayerSimpleLabeling::toSld( QDomNode &parent, const QVariantMap &props ) const
667{
668 QgsSldExportContext context;
669 context.setExtraProperties( props );
670 toSld( parent, context );
671}
672
673bool QgsVectorLayerSimpleLabeling::toSld( QDomNode &parent, QgsSldExportContext &context ) const
674{
675 if ( mSettings->drawLabels )
676 {
677 QDomDocument doc = parent.ownerDocument();
678
679 QDomElement ruleElement = doc.createElement( u"se:Rule"_s );
680 parent.appendChild( ruleElement );
681
682 // scale dependencies
683 if ( mSettings->scaleVisibility )
684 {
685 QVariantMap scaleProps = QVariantMap();
686 // tricky here, the max scale is expressed as its denominator, but it's still the max scale
687 // in other words, the smallest scale denominator....
688 scaleProps.insert( "scaleMinDenom", qgsDoubleToString( mSettings->maximumScale ) );
689 scaleProps.insert( "scaleMaxDenom", qgsDoubleToString( mSettings->minimumScale ) );
690 QgsSymbolLayerUtils::applyScaleDependency( doc, ruleElement, scaleProps );
691 }
692
693 writeTextSymbolizer( ruleElement, *mSettings, context );
694 }
695 return true;
696}
697
699{
700 QgsTextFormat format { mSettings->format() };
701 format.multiplyOpacity( opacityFactor );
702 mSettings->setFormat( format );
703}
704
706{
707 Q_UNUSED( providerId )
708
709 if ( mSettings.get() == settings )
710 return;
711
712 mSettings.reset( settings );
713}
@ LabelLargestPartOnly
Place a label only on the largest part from the geometry.
Definition qgis.h:1332
@ SplitLabelTextLinesOverParts
Splits the label text over the parts of the geometry, such that each consecutive part is labeled with...
Definition qgis.h:1334
@ LabelEveryPartWithEntireLabel
Place the (same) entire label over every part from the geometry.
Definition qgis.h:1333
@ FromSymbolBounds
Offset distance applies from rendered symbol bounds.
Definition qgis.h:1349
@ OverPoint
Arranges candidates over a point (or centroid of a polygon), or at a preset offset from the point....
Definition qgis.h:1275
@ Curved
Arranges candidates following the curvature of a line feature. Applies to line layers only.
Definition qgis.h:1277
@ AroundPoint
Arranges candidates in a circle around a point (or centroid of a polygon). Applies to point or polygo...
Definition qgis.h:1274
@ Line
Arranges candidates parallel to a generalised line representing the feature or parallel to a polygon'...
Definition qgis.h:1276
@ Free
Arranges candidates scattered throughout a polygon feature. Candidates are rotated to respect the pol...
Definition qgis.h:1279
@ OrderedPositionsAroundPoint
Candidates are placed in predefined positions around a point. Preference is given to positions with g...
Definition qgis.h:1280
@ Horizontal
Arranges horizontal candidates scattered throughout a polygon feature. Applies to polygon layers only...
Definition qgis.h:1278
@ PerimeterCurved
Arranges candidates following the curvature of a polygon's boundary. Applies to polygon layers only.
Definition qgis.h:1281
@ OutsidePolygons
Candidates are placed outside of polygon boundaries. Applies to polygon layers only.
Definition qgis.h:1282
MarkerShape
Marker shapes.
Definition qgis.h:3261
@ Circle
Circle.
Definition qgis.h:3270
@ Diamond
Diamond.
Definition qgis.h:3263
@ Square
Square.
Definition qgis.h:3262
Capitalization
String capitalization options.
Definition qgis.h:3570
@ MixedCase
Mixed case, ie no change.
Definition qgis.h:3571
@ AllLowercase
Convert all characters to lowercase.
Definition qgis.h:3573
@ ForceFirstLetterToCapital
Convert just the first letter of each word to uppercase, leave the rest untouched.
Definition qgis.h:3574
@ AllUppercase
Convert all characters to uppercase.
Definition qgis.h:3572
LabelQuadrantPosition
Label quadrant positions.
Definition qgis.h:1361
@ AboveRight
Above right.
Definition qgis.h:1364
@ BelowLeft
Below left.
Definition qgis.h:1368
@ Above
Above center.
Definition qgis.h:1363
@ BelowRight
Below right.
Definition qgis.h:1370
@ Right
Right middle.
Definition qgis.h:1367
@ AboveLeft
Above left.
Definition qgis.h:1362
@ Below
Below center.
Definition qgis.h:1369
@ Over
Center middle.
Definition qgis.h:1366
@ Point
Points.
Definition qgis.h:380
@ Line
Lines.
Definition qgis.h:381
@ Polygon
Polygons.
Definition qgis.h:382
@ Unknown
Unknown types.
Definition qgis.h:383
@ Null
No geometry.
Definition qgis.h:384
RenderUnit
Rendering size units.
Definition qgis.h:5552
@ AllowOverlapAtNoCost
Labels may freely overlap other labels, at no cost.
Definition qgis.h:1237
@ AllowOverlapIfRequired
Avoids overlapping labels when possible, but permit overlaps if labels for features cannot otherwise ...
Definition qgis.h:1236
@ PreventOverlap
Do not allow labels to overlap other labels.
Definition qgis.h:1235
@ AlwaysAllowUpsideDown
Show upside down for all labels, including dynamic ones.
Definition qgis.h:1432
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.
QgsProject * project() const
Returns the parent project if this map layer is added to a project.
Abstract base class for marker symbol layers.
static QDomElement expressionToOgcExpression(const QgsExpression &exp, QDomDocument &doc, QString *errorMessage=nullptr, bool requiresFilterElement=false)
Creates an OGC expression XML element from the exp expression with default values for the geometry na...
Contains settings for how a map layer will be labeled.
bool containsAdvancedEffects() const
Returns true if any component of the label settings requires advanced effects such as blend modes,...
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:1547
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:357
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.
void multiplyOpacity(double opacityFactor)
Multiply opacity by opacityFactor.
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.
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:7140
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)