QGIS API Documentation 3.99.0-Master (8e76e220402)
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 "qgsmarkersymbol.h"
20#include "qgspallabeling.h"
22#include "qgssldexportcontext.h"
24#include "qgssymbollayer.h"
25#include "qgssymbollayerutils.h"
26#include "qgsvectorlayer.h"
27
28#include <QString>
29
30using namespace Qt::StringLiterals;
31
33{
34 const QString type = element.attribute( u"type"_s );
35 if ( type == "rule-based"_L1 )
36 {
37 return QgsRuleBasedLabeling::create( element, context );
38 }
39 else if ( type == "simple"_L1 )
40 {
41 return QgsVectorLayerSimpleLabeling::create( element, context );
42 }
43 else
44 {
45 return nullptr;
46 }
47}
48
49void QgsAbstractVectorLayerLabeling::toSld( QDomNode &parent, const QVariantMap &props ) const
50{
51 QgsSldExportContext context;
52 context.setExtraProperties( props );
53 toSld( parent, context );
54}
55
57{
58 context.pushError( QObject::tr( "%1 labeling cannot be exported to SLD" ).arg( type() ) );
59 return false;
60}
61
66
92
94{
95 return new QgsVectorLayerLabelProvider( layer, QString(), false, mSettings.get() );
96}
97
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 if ( settings.isExpression )
326 {
327 context.pushError( QObject::tr( "Labels containing expressions cannot be exported to SLD. Skipping label '%1'" ).arg( settings.getLabelExpression()->dump() ) );
328 labelElement.appendChild( doc.createTextNode( "Placeholder" ) );
329 }
330 else
331 {
332 Qgis::Capitalization capitalization = format.capitalization();
333 if ( capitalization == Qgis::Capitalization::MixedCase && font.capitalization() != QFont::MixedCase )
334 capitalization = static_cast< Qgis::Capitalization >( font.capitalization() );
335 if ( capitalization == Qgis::Capitalization::AllUppercase )
336 {
337 appendSimpleFunction( doc, labelElement, u"strToUpperCase"_s, settings.fieldName );
338 }
339 else if ( capitalization == Qgis::Capitalization::AllLowercase )
340 {
341 appendSimpleFunction( doc, labelElement, u"strToLowerCase"_s, settings.fieldName );
342 }
343 else if ( capitalization == Qgis::Capitalization::ForceFirstLetterToCapital )
344 {
345 appendSimpleFunction( doc, labelElement, u"strCapitalize"_s, settings.fieldName );
346 }
347 else
348 {
349 QDomElement propertyNameElement = doc.createElement( u"ogc:PropertyName"_s );
350 propertyNameElement.appendChild( doc.createTextNode( settings.fieldName ) );
351 labelElement.appendChild( propertyNameElement );
352 }
353 }
354
355 // font
356 QDomElement fontElement = doc.createElement( u"se:Font"_s );
357 textSymbolizerElement.appendChild( fontElement );
358 fontElement.appendChild( QgsSymbolLayerUtils::createSvgParameterElement( doc, u"font-family"_s, font.family() ) );
359 const QVariantMap props = context.extraProperties();
360 const double fontSize = QgsSymbolLayerUtils::rescaleUom( format.size(), format.sizeUnit(), props );
361 fontElement.appendChild( QgsSymbolLayerUtils::createSvgParameterElement( doc, u"font-size"_s, QString::number( fontSize ) ) );
362 if ( format.font().italic() )
363 {
364 fontElement.appendChild( QgsSymbolLayerUtils::createSvgParameterElement( doc, u"font-style"_s, u"italic"_s ) );
365 }
366 if ( format.font().bold() )
367 {
368 fontElement.appendChild( QgsSymbolLayerUtils::createSvgParameterElement( doc, u"font-weight"_s, u"bold"_s ) );
369 }
370
371 // label placement
372 QDomElement labelPlacement = doc.createElement( u"se:LabelPlacement"_s );
373 textSymbolizerElement.appendChild( labelPlacement );
374 double maxDisplacement = 0;
375 double repeatDistance = 0;
376 switch ( settings.placement )
377 {
379 {
380 QDomElement pointPlacement = doc.createElement( "se:PointPlacement" );
381 labelPlacement.appendChild( pointPlacement );
382 // anchor point
383 const QPointF anchor = quadOffsetToSldAnchor( settings.pointSettings().quadrant() );
384 QgsSymbolLayerUtils::createAnchorPointElement( doc, pointPlacement, anchor );
385 // displacement
386 if ( settings.xOffset != 0 || settings.yOffset != 0 )
387 {
388 const Qgis::RenderUnit offsetUnit = settings.offsetUnits;
389 const double dx = QgsSymbolLayerUtils::rescaleUom( settings.xOffset, offsetUnit, props );
390 const double dy = QgsSymbolLayerUtils::rescaleUom( settings.yOffset, offsetUnit, props );
391 QgsSymbolLayerUtils::createDisplacementElement( doc, pointPlacement, QPointF( dx, dy ) );
392 }
393 // rotation
394 if ( settings.angleOffset != 0 )
395 {
396 QDomElement rotation = doc.createElement( "se:Rotation" );
397 pointPlacement.appendChild( rotation );
398 rotation.appendChild( doc.createTextNode( QString::number( settings.angleOffset ) ) );
399 }
400 }
401 break;
404 {
405 QDomElement pointPlacement = doc.createElement( "se:PointPlacement" );
406 labelPlacement.appendChild( pointPlacement );
407
408 // SLD cannot do either, but let's do a best effort setting the distance using
409 // anchor point and displacement
410 QgsSymbolLayerUtils::createAnchorPointElement( doc, pointPlacement, QPointF( 0, 0.5 ) );
411 const Qgis::RenderUnit distUnit = settings.distUnits;
412 const double radius = QgsSymbolLayerUtils::rescaleUom( settings.dist, distUnit, props );
413 const double offset = std::sqrt( radius * radius / 2 ); // make it start top/right
414 maxDisplacement = radius + 1; // lock the distance
415 QgsSymbolLayerUtils::createDisplacementElement( doc, pointPlacement, QPointF( offset, offset ) );
416 }
417 break;
421 {
422 // still a point placement (for "free" it's a fallback, there is no SLD equivalent)
423 QDomElement pointPlacement = doc.createElement( "se:PointPlacement" );
424 labelPlacement.appendChild( pointPlacement );
425 QgsSymbolLayerUtils::createAnchorPointElement( doc, pointPlacement, QPointF( 0.5, 0.5 ) );
426 const Qgis::RenderUnit distUnit = settings.distUnits;
427 const double dist = QgsSymbolLayerUtils::rescaleUom( settings.dist, distUnit, props );
428 QgsSymbolLayerUtils::createDisplacementElement( doc, pointPlacement, QPointF( 0, dist ) );
429 break;
430 }
434 {
435 QDomElement linePlacement = doc.createElement( "se:LinePlacement" );
436 labelPlacement.appendChild( linePlacement );
437
438 // perpendicular distance if required
439 if ( settings.dist > 0 )
440 {
441 const Qgis::RenderUnit distUnit = settings.distUnits;
442 const double dist = QgsSymbolLayerUtils::rescaleUom( settings.dist, distUnit, props );
443 QDomElement perpendicular = doc.createElement( "se:PerpendicularOffset" );
444 linePlacement.appendChild( perpendicular );
445 perpendicular.appendChild( doc.createTextNode( qgsDoubleToString( dist, 2 ) ) );
446 }
447
448 // repeat distance if required
449 if ( settings.repeatDistance > 0 )
450 {
451 QDomElement repeat = doc.createElement( "se:Repeat" );
452 linePlacement.appendChild( repeat );
453 repeat.appendChild( doc.createTextNode( u"true"_s ) );
454 QDomElement gap = doc.createElement( "se:Gap" );
455 linePlacement.appendChild( gap );
456 repeatDistance = QgsSymbolLayerUtils::rescaleUom( settings.repeatDistance, settings.repeatDistanceUnit, props );
457 gap.appendChild( doc.createTextNode( qgsDoubleToString( repeatDistance, 2 ) ) );
458 }
459
460 // always generalized
461 QDomElement generalize = doc.createElement( "se:GeneralizeLine" );
462 linePlacement.appendChild( generalize );
463 generalize.appendChild( doc.createTextNode( u"true"_s ) );
464 }
465 break;
466 }
467
468 // halo
469 const QgsTextBufferSettings buffer = format.buffer();
470 if ( buffer.enabled() )
471 {
472 QDomElement haloElement = doc.createElement( u"se:Halo"_s );
473 textSymbolizerElement.appendChild( haloElement );
474
475 QDomElement radiusElement = doc.createElement( u"se:Radius"_s );
476 haloElement.appendChild( radiusElement );
477 // the SLD uses a radius, which is actually half of the link thickness the buffer size specifies
478 const double radius = QgsSymbolLayerUtils::rescaleUom( buffer.size(), buffer.sizeUnit(), props ) / 2;
479 radiusElement.appendChild( doc.createTextNode( qgsDoubleToString( radius ) ) );
480
481 QDomElement fillElement = doc.createElement( u"se:Fill"_s );
482 haloElement.appendChild( fillElement );
483 fillElement.appendChild( QgsSymbolLayerUtils::createSvgParameterElement( doc, u"fill"_s, buffer.color().name() ) );
484 if ( buffer.opacity() != 1 )
485 {
486 fillElement.appendChild( QgsSymbolLayerUtils::createSvgParameterElement( doc, u"fill-opacity"_s, QString::number( buffer.opacity() ) ) );
487 }
488 }
489
490 // fill
491 QDomElement fillElement = doc.createElement( u"se:Fill"_s );
492 textSymbolizerElement.appendChild( fillElement );
493 fillElement.appendChild( QgsSymbolLayerUtils::createSvgParameterElement( doc, u"fill"_s, format.color().name() ) );
494 if ( format.opacity() != 1 )
495 {
496 fillElement.appendChild( QgsSymbolLayerUtils::createSvgParameterElement( doc, u"fill-opacity"_s, QString::number( format.opacity() ) ) );
497 }
498
499 // background graphic (not supported by SE 1.1, but supported by the GeoTools ecosystem as an extension)
500 const QgsTextBackgroundSettings background = format.background();
501 if ( background.enabled() )
502 {
503 std::unique_ptr<QgsMarkerSymbolLayer> layer = backgroundToMarkerLayer( background );
504 layer->writeSldMarker( doc, textSymbolizerElement, context );
505 }
506
507 // priority and zIndex, the default values are 0 and 5 in qgis (and between 0 and 10),
508 // in the GeoTools ecosystem there is a single priority value set at 1000 by default
509 if ( settings.priority != 5 || settings.zIndex > 0 )
510 {
511 QDomElement priorityElement = doc.createElement( u"se:Priority"_s );
512 textSymbolizerElement.appendChild( priorityElement );
513 int priority = 500 + 1000 * settings.zIndex + ( settings.priority - 5 ) * 100;
514 if ( settings.priority == 0 && settings.zIndex > 0 )
515 {
516 // small adjustment to make sure labels in z index n+1 are all above level n despite the priority value
517 priority += 1;
518 }
519 priorityElement.appendChild( doc.createTextNode( QString::number( priority ) ) );
520 }
521
522 // vendor options for text appearance
523 if ( font.underline() )
524 {
525 const QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, u"underlineText"_s, u"true"_s );
526 textSymbolizerElement.appendChild( vo );
527 }
528 if ( font.strikeOut() )
529 {
530 const QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, u"strikethroughText"_s, u"true"_s );
531 textSymbolizerElement.appendChild( vo );
532 }
533 // vendor options for text positioning
534 if ( maxDisplacement > 0 )
535 {
536 const QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, u"maxDisplacement"_s, qgsDoubleToString( maxDisplacement, 2 ) );
537 textSymbolizerElement.appendChild( vo );
538 }
539
540 switch ( settings.placement )
541 {
544 {
545 const QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, u"followLine"_s, u"true"_s );
546 textSymbolizerElement.appendChild( vo );
547 if ( settings.maxCurvedCharAngleIn > 0 || settings.maxCurvedCharAngleOut > 0 )
548 {
549 // SLD has no notion for this, the GeoTools ecosystem can only do a single angle
550 const double angle = std::min( std::fabs( settings.maxCurvedCharAngleIn ), std::fabs( settings.maxCurvedCharAngleOut ) );
551 const QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, u"maxAngleDelta"_s, qgsDoubleToString( angle ) );
552 textSymbolizerElement.appendChild( vo );
553 }
554 break;
555 }
556
564 break;
565 }
566
567 if ( repeatDistance > 0 )
568 {
569 const QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, u"repeat"_s, qgsDoubleToString( repeatDistance, 2 ) );
570 textSymbolizerElement.appendChild( vo );
571 }
572 // miscellaneous options
573 switch ( settings.placementSettings().overlapHandling() )
574 {
576 break;
579 const QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, u"conflictResolution"_s, u"false"_s );
580 textSymbolizerElement.appendChild( vo );
581 break;
582 }
584 {
585 const QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, u"forceLeftToRight"_s, u"false"_s );
586 textSymbolizerElement.appendChild( vo );
587 }
588 if ( settings.lineSettings().mergeLines() )
589 {
590 const QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, u"group"_s, u"yes"_s );
591 textSymbolizerElement.appendChild( vo );
592 switch ( settings.placementSettings().multiPartBehavior() )
593 {
596 break;
598 {
599 const QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, u"labelAllGroup"_s, u"true"_s );
600 textSymbolizerElement.appendChild( vo );
601 break;
602 }
603 }
604 }
605 // background symbol resize handling
606 if ( background.enabled() )
607 {
608 // enable resizing if needed
609 switch ( background.sizeType() )
610 {
612 {
613 QString resizeType;
615 {
616 resizeType = u"stretch"_s;
617 }
618 else
619 {
620 resizeType = u"proportional"_s;
621 }
622 const QDomElement voResize = QgsSymbolLayerUtils::createVendorOptionElement( doc, u"graphic-resize"_s, resizeType );
623 textSymbolizerElement.appendChild( voResize );
624
625 // now hadle margin
626 const QSizeF size = background.size();
627 if ( size.width() > 0 || size.height() > 0 )
628 {
629 double x = QgsSymbolLayerUtils::rescaleUom( size.width(), background.sizeUnit(), props );
630 double y = QgsSymbolLayerUtils::rescaleUom( size.height(), background.sizeUnit(), props );
631 // in case of ellipse qgis pads the size generously to make sure the text is inside the ellipse
632 // the following seems to do the trick and keep visual output similar
633 if ( background.type() == QgsTextBackgroundSettings::ShapeEllipse )
634 {
635 x += fontSize / 2;
636 y += fontSize;
637 }
638 const QString resizeSpec = QString( "%1 %2" ).arg( qgsDoubleToString( x, 2 ), qgsDoubleToString( y, 2 ) );
639 const QDomElement voMargin = QgsSymbolLayerUtils::createVendorOptionElement( doc, u"graphic-margin"_s, resizeSpec );
640 textSymbolizerElement.appendChild( voMargin );
641 }
642 break;
643 }
646 // nothing to do here
647 break;
648 }
649 }
650 return true;
651}
652
653void QgsVectorLayerSimpleLabeling::toSld( QDomNode &parent, const QVariantMap &props ) const
654{
655 QgsSldExportContext context;
656 context.setExtraProperties( props );
657 toSld( parent, context );
658}
659
660bool QgsVectorLayerSimpleLabeling::toSld( QDomNode &parent, QgsSldExportContext &context ) const
661{
662 if ( mSettings->drawLabels )
663 {
664 QDomDocument doc = parent.ownerDocument();
665
666 QDomElement ruleElement = doc.createElement( u"se:Rule"_s );
667 parent.appendChild( ruleElement );
668
669 // scale dependencies
670 if ( mSettings->scaleVisibility )
671 {
672 QVariantMap scaleProps = QVariantMap();
673 // tricky here, the max scale is expressed as its denominator, but it's still the max scale
674 // in other words, the smallest scale denominator....
675 scaleProps.insert( "scaleMinDenom", qgsDoubleToString( mSettings->maximumScale ) );
676 scaleProps.insert( "scaleMaxDenom", qgsDoubleToString( mSettings->minimumScale ) );
677 QgsSymbolLayerUtils::applyScaleDependency( doc, ruleElement, scaleProps );
678 }
679
680 writeTextSymbolizer( ruleElement, *mSettings, context );
681 }
682 return true;
683}
684
686{
687 QgsTextFormat format { mSettings->format() };
688 format.multiplyOpacity( opacityFactor );
689 mSettings->setFormat( format );
690}
691
693{
694 Q_UNUSED( providerId )
695
696 if ( mSettings.get() == settings )
697 return;
698
699 mSettings.reset( settings );
700}
@ LabelLargestPartOnly
Place a label only on the largest part from the geometry.
Definition qgis.h:1284
@ SplitLabelTextLinesOverParts
Splits the label text over the parts of the geometry, such that each consecutive part is labeled with...
Definition qgis.h:1286
@ LabelEveryPartWithEntireLabel
Place the (same) entire label over every part from the geometry.
Definition qgis.h:1285
@ FromSymbolBounds
Offset distance applies from rendered symbol bounds.
Definition qgis.h:1301
@ OverPoint
Arranges candidates over a point (or centroid of a polygon), or at a preset offset from the point....
Definition qgis.h:1227
@ Curved
Arranges candidates following the curvature of a line feature. Applies to line layers only.
Definition qgis.h:1229
@ AroundPoint
Arranges candidates in a circle around a point (or centroid of a polygon). Applies to point or polygo...
Definition qgis.h:1226
@ Line
Arranges candidates parallel to a generalised line representing the feature or parallel to a polygon'...
Definition qgis.h:1228
@ Free
Arranges candidates scattered throughout a polygon feature. Candidates are rotated to respect the pol...
Definition qgis.h:1231
@ OrderedPositionsAroundPoint
Candidates are placed in predefined positions around a point. Preference is given to positions with g...
Definition qgis.h:1232
@ Horizontal
Arranges horizontal candidates scattered throughout a polygon feature. Applies to polygon layers only...
Definition qgis.h:1230
@ PerimeterCurved
Arranges candidates following the curvature of a polygon's boundary. Applies to polygon layers only.
Definition qgis.h:1233
@ OutsidePolygons
Candidates are placed outside of polygon boundaries. Applies to polygon layers only.
Definition qgis.h:1234
MarkerShape
Marker shapes.
Definition qgis.h:3151
@ Circle
Circle.
Definition qgis.h:3160
@ Diamond
Diamond.
Definition qgis.h:3153
@ Square
Square.
Definition qgis.h:3152
Capitalization
String capitalization options.
Definition qgis.h:3460
@ MixedCase
Mixed case, ie no change.
Definition qgis.h:3461
@ AllLowercase
Convert all characters to lowercase.
Definition qgis.h:3463
@ ForceFirstLetterToCapital
Convert just the first letter of each word to uppercase, leave the rest untouched.
Definition qgis.h:3464
@ AllUppercase
Convert all characters to uppercase.
Definition qgis.h:3462
LabelQuadrantPosition
Label quadrant positions.
Definition qgis.h:1313
@ AboveRight
Above right.
Definition qgis.h:1316
@ BelowLeft
Below left.
Definition qgis.h:1320
@ Above
Above center.
Definition qgis.h:1315
@ BelowRight
Below right.
Definition qgis.h:1322
@ Right
Right middle.
Definition qgis.h:1319
@ AboveLeft
Above left.
Definition qgis.h:1314
@ Below
Below center.
Definition qgis.h:1321
@ Over
Center middle.
Definition qgis.h:1318
@ Point
Points.
Definition qgis.h:366
@ Line
Lines.
Definition qgis.h:367
@ Polygon
Polygons.
Definition qgis.h:368
@ Unknown
Unknown types.
Definition qgis.h:369
@ Null
No geometry.
Definition qgis.h:370
RenderUnit
Rendering size units.
Definition qgis.h:5290
@ AllowOverlapAtNoCost
Labels may freely overlap other labels, at no cost.
Definition qgis.h:1189
@ AllowOverlapIfRequired
Avoids overlapping labels when possible, but permit overlaps if labels for features cannot otherwise ...
Definition qgis.h:1188
@ PreventOverlap
Do not allow labels to overlap other labels.
Definition qgis.h:1187
@ AlwaysAllowUpsideDown
Show upside down for all labels, including dynamic ones.
Definition qgis.h:1384
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.
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:1491
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.
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:6852
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)