QGIS API Documentation 4.1.0-Master (60fea48833c)
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
101
103{
104 return u"simple"_s;
105}
106
111
112QDomElement QgsVectorLayerSimpleLabeling::save( QDomDocument &doc, const QgsReadWriteContext &context ) const
113{
114 QDomElement elem = doc.createElement( u"labeling"_s );
115 elem.setAttribute( u"type"_s, u"simple"_s );
116 elem.appendChild( mSettings->writeXml( doc, context ) );
117 return elem;
118}
119
121{
122 Q_UNUSED( providerId )
123 return *mSettings;
124}
125
127{
128 if ( mSettings )
129 {
130 QgsStyleLabelSettingsEntity entity( *mSettings );
131 if ( !visitor->visit( &entity ) )
132 return false;
133 }
134 return true;
135}
136
141
143{
144 return mSettings->dataDefinedProperties().isActive( QgsPalLayerSettings::Property::FontBlendMode )
145 || mSettings->dataDefinedProperties().isActive( QgsPalLayerSettings::Property::ShapeBlendMode )
146 || mSettings->dataDefinedProperties().isActive( QgsPalLayerSettings::Property::BufferBlendMode )
147 || mSettings->dataDefinedProperties().isActive( QgsPalLayerSettings::Property::ShadowBlendMode )
148 || mSettings->format().hasNonDefaultCompositionMode();
149}
150
151QgsVectorLayerSimpleLabeling *QgsVectorLayerSimpleLabeling::create( const QDomElement &element, const QgsReadWriteContext &context ) // cppcheck-suppress duplInheritedMember
152{
153 const QDomElement settingsElem = element.firstChildElement( u"settings"_s );
154 if ( !settingsElem.isNull() )
155 {
157 settings.readXml( settingsElem, context );
159 }
160
162}
163
165{
166 double quadOffsetX = 0.5, quadOffsetY = 0.5;
167
168 // adjust quadrant offset of labels
169 switch ( quadrantPosition )
170 {
172 quadOffsetX = 1;
173 quadOffsetY = 0;
174 break;
176 quadOffsetX = 0.5;
177 quadOffsetY = 0;
178 break;
180 quadOffsetX = 0;
181 quadOffsetY = 0;
182 break;
184 quadOffsetX = 1;
185 quadOffsetY = 0.5;
186 break;
188 quadOffsetX = 0;
189 quadOffsetY = 0.5;
190 break;
192 quadOffsetX = 1;
193 quadOffsetY = 1;
194 break;
196 quadOffsetX = 0.5;
197 quadOffsetY = 1;
198 break;
200 quadOffsetX = 0;
201 quadOffsetY = 1.0;
202 break;
204 break;
205 }
206
207 return QPointF( quadOffsetX, quadOffsetY );
208}
209
210/*
211 * This is not a generic function encoder, just enough to encode the label case control functions
212 */
213void appendSimpleFunction( QDomDocument &doc, QDomElement &parent, const QString &name, const QString &attribute )
214{
215 QDomElement function = doc.createElement( u"ogc:Function"_s );
216 function.setAttribute( u"name"_s, name );
217 parent.appendChild( function );
218 QDomElement property = doc.createElement( u"ogc:PropertyName"_s );
219 property.appendChild( doc.createTextNode( attribute ) );
220 function.appendChild( property );
221}
222
223std::unique_ptr<QgsMarkerSymbolLayer> backgroundToMarkerLayer( const QgsTextBackgroundSettings &settings )
224{
225 std::unique_ptr<QgsMarkerSymbolLayer> layer;
226 switch ( settings.type() )
227 {
229 {
231 svg->setStrokeWidth( settings.strokeWidth() );
232 svg->setStrokeWidthUnit( settings.strokeWidthUnit() );
233 layer.reset( svg );
234 break;
235 }
237 {
238 // just grab the first layer and hope for the best
239 if ( settings.markerSymbol() && settings.markerSymbol()->symbolLayerCount() > 0 )
240 {
241 layer.reset( static_cast< QgsMarkerSymbolLayer * >( settings.markerSymbol()->symbolLayer( 0 )->clone() ) );
242 break;
243 }
244 [[fallthrough]]; // not set, just go with the default
245 }
250 {
252 // default value
254 switch ( settings.type() )
255 {
259 break;
263 break;
266 break;
267 }
268
269 marker->setShape( shape );
270 marker->setStrokeWidth( settings.strokeWidth() );
271 marker->setStrokeWidthUnit( settings.strokeWidthUnit() );
272 layer.reset( marker );
273 }
274 }
275 layer->setEnabled( true );
276 // a marker does not have a size x and y, just a size (and it should be at least one)
277 const QSizeF size = settings.size();
278 layer->setSize( std::max( 1., std::max( size.width(), size.height() ) ) );
279 layer->setSizeUnit( settings.sizeUnit() );
280 // fill and stroke
281 QColor fillColor = settings.fillColor();
282 QColor strokeColor = settings.strokeColor();
283 if ( settings.opacity() < 1 )
284 {
285 const int alpha = std::round( settings.opacity() * 255 );
286 fillColor.setAlpha( alpha );
287 strokeColor.setAlpha( alpha );
288 }
289 layer->setFillColor( fillColor );
290 layer->setStrokeColor( strokeColor );
291 // rotation
293 {
294 layer->setAngle( settings.rotation() );
295 }
296 // offset
297 layer->setOffset( settings.offset() );
298 layer->setOffsetUnit( settings.offsetUnit() );
299
300 return layer;
301}
302
303void QgsAbstractVectorLayerLabeling::writeTextSymbolizer( QDomNode &parent, QgsPalLayerSettings &settings, const QVariantMap &props ) const
304{
305 QgsSldExportContext context;
306 context.setExtraProperties( props );
307 writeTextSymbolizer( parent, settings, context );
308}
309
311{
312 QDomDocument doc = parent.ownerDocument();
313
314 // text symbolizer
315 QDomElement textSymbolizerElement = doc.createElement( u"se:TextSymbolizer"_s );
316 parent.appendChild( textSymbolizerElement );
317
318 // label
319 QgsTextFormat format = settings.format();
320 const QFont font = format.font();
321 QDomElement labelElement = doc.createElement( u"se:Label"_s );
322 textSymbolizerElement.appendChild( labelElement );
323 if ( settings.isExpression )
324 {
325 context.pushError( QObject::tr( "Labels containing expressions cannot be exported to SLD. Skipping label '%1'" ).arg( settings.getLabelExpression()->dump() ) );
326 labelElement.appendChild( doc.createTextNode( "Placeholder" ) );
327 }
328 else
329 {
330 Qgis::Capitalization capitalization = format.capitalization();
331 if ( capitalization == Qgis::Capitalization::MixedCase && font.capitalization() != QFont::MixedCase )
332 capitalization = static_cast< Qgis::Capitalization >( font.capitalization() );
333 if ( capitalization == Qgis::Capitalization::AllUppercase )
334 {
335 appendSimpleFunction( doc, labelElement, u"strToUpperCase"_s, settings.fieldName );
336 }
337 else if ( capitalization == Qgis::Capitalization::AllLowercase )
338 {
339 appendSimpleFunction( doc, labelElement, u"strToLowerCase"_s, settings.fieldName );
340 }
341 else if ( capitalization == Qgis::Capitalization::ForceFirstLetterToCapital )
342 {
343 appendSimpleFunction( doc, labelElement, u"strCapitalize"_s, settings.fieldName );
344 }
345 else
346 {
347 QDomElement propertyNameElement = doc.createElement( u"ogc:PropertyName"_s );
348 propertyNameElement.appendChild( doc.createTextNode( settings.fieldName ) );
349 labelElement.appendChild( propertyNameElement );
350 }
351 }
352
353 // font
354 QDomElement fontElement = doc.createElement( u"se:Font"_s );
355 textSymbolizerElement.appendChild( fontElement );
356 fontElement.appendChild( QgsSymbolLayerUtils::createSvgParameterElement( doc, u"font-family"_s, font.family() ) );
357 const QVariantMap props = context.extraProperties();
358 const double fontSize = QgsSymbolLayerUtils::rescaleUom( format.size(), format.sizeUnit(), props );
359 fontElement.appendChild( QgsSymbolLayerUtils::createSvgParameterElement( doc, u"font-size"_s, QString::number( fontSize ) ) );
360 if ( format.font().italic() )
361 {
362 fontElement.appendChild( QgsSymbolLayerUtils::createSvgParameterElement( doc, u"font-style"_s, u"italic"_s ) );
363 }
364 if ( format.font().bold() )
365 {
366 fontElement.appendChild( QgsSymbolLayerUtils::createSvgParameterElement( doc, u"font-weight"_s, u"bold"_s ) );
367 }
368
369 // label placement
370 QDomElement labelPlacement = doc.createElement( u"se:LabelPlacement"_s );
371 textSymbolizerElement.appendChild( labelPlacement );
372 double maxDisplacement = 0;
373 double repeatDistance = 0;
374 switch ( settings.placement )
375 {
377 {
378 QDomElement pointPlacement = doc.createElement( "se:PointPlacement" );
379 labelPlacement.appendChild( pointPlacement );
380 // anchor point
381 const QPointF anchor = quadOffsetToSldAnchor( settings.pointSettings().quadrant() );
382 QgsSymbolLayerUtils::createAnchorPointElement( doc, pointPlacement, anchor );
383 // displacement
384 if ( settings.xOffset != 0 || settings.yOffset != 0 )
385 {
386 const Qgis::RenderUnit offsetUnit = settings.offsetUnits;
387 const double dx = QgsSymbolLayerUtils::rescaleUom( settings.xOffset, offsetUnit, props );
388 const double dy = QgsSymbolLayerUtils::rescaleUom( settings.yOffset, offsetUnit, props );
389 QgsSymbolLayerUtils::createDisplacementElement( doc, pointPlacement, QPointF( dx, dy ) );
390 }
391 // rotation
392 if ( settings.angleOffset != 0 )
393 {
394 QDomElement rotation = doc.createElement( "se:Rotation" );
395 pointPlacement.appendChild( rotation );
396 rotation.appendChild( doc.createTextNode( QString::number( settings.angleOffset ) ) );
397 }
398 }
399 break;
402 {
403 QDomElement pointPlacement = doc.createElement( "se:PointPlacement" );
404 labelPlacement.appendChild( pointPlacement );
405
406 // SLD cannot do either, but let's do a best effort setting the distance using
407 // anchor point and displacement
408 QgsSymbolLayerUtils::createAnchorPointElement( doc, pointPlacement, QPointF( 0, 0.5 ) );
409 const Qgis::RenderUnit distUnit = settings.distUnits;
410 const double radius = QgsSymbolLayerUtils::rescaleUom( settings.dist, distUnit, props );
411 const double offset = std::sqrt( radius * radius / 2 ); // make it start top/right
412 maxDisplacement = radius + 1; // lock the distance
413 QgsSymbolLayerUtils::createDisplacementElement( doc, pointPlacement, QPointF( offset, offset ) );
414 }
415 break;
419 {
420 // still a point placement (for "free" it's a fallback, there is no SLD equivalent)
421 QDomElement pointPlacement = doc.createElement( "se:PointPlacement" );
422 labelPlacement.appendChild( pointPlacement );
423 QgsSymbolLayerUtils::createAnchorPointElement( doc, pointPlacement, QPointF( 0.5, 0.5 ) );
424 const Qgis::RenderUnit distUnit = settings.distUnits;
425 const double dist = QgsSymbolLayerUtils::rescaleUom( settings.dist, distUnit, props );
426 QgsSymbolLayerUtils::createDisplacementElement( doc, pointPlacement, QPointF( 0, dist ) );
427 break;
428 }
432 {
433 QDomElement linePlacement = doc.createElement( "se:LinePlacement" );
434 labelPlacement.appendChild( linePlacement );
435
436 // perpendicular distance if required
437 if ( settings.dist > 0 )
438 {
439 const Qgis::RenderUnit distUnit = settings.distUnits;
440 const double dist = QgsSymbolLayerUtils::rescaleUom( settings.dist, distUnit, props );
441 QDomElement perpendicular = doc.createElement( "se:PerpendicularOffset" );
442 linePlacement.appendChild( perpendicular );
443 perpendicular.appendChild( doc.createTextNode( qgsDoubleToString( dist, 2 ) ) );
444 }
445
446 // repeat distance if required
447 if ( settings.repeatDistance > 0 )
448 {
449 QDomElement repeat = doc.createElement( "se:Repeat" );
450 linePlacement.appendChild( repeat );
451 repeat.appendChild( doc.createTextNode( u"true"_s ) );
452 QDomElement gap = doc.createElement( "se:Gap" );
453 linePlacement.appendChild( gap );
454 repeatDistance = QgsSymbolLayerUtils::rescaleUom( settings.repeatDistance, settings.repeatDistanceUnit, props );
455 gap.appendChild( doc.createTextNode( qgsDoubleToString( repeatDistance, 2 ) ) );
456 }
457
458 // always generalized
459 QDomElement generalize = doc.createElement( "se:GeneralizeLine" );
460 linePlacement.appendChild( generalize );
461 generalize.appendChild( doc.createTextNode( u"true"_s ) );
462 }
463 break;
464 }
465
466 // halo
467 const QgsTextBufferSettings buffer = format.buffer();
468 if ( buffer.enabled() )
469 {
470 QDomElement haloElement = doc.createElement( u"se:Halo"_s );
471 textSymbolizerElement.appendChild( haloElement );
472
473 QDomElement radiusElement = doc.createElement( u"se:Radius"_s );
474 haloElement.appendChild( radiusElement );
475 // the SLD uses a radius, which is actually half of the link thickness the buffer size specifies
476 const double radius = QgsSymbolLayerUtils::rescaleUom( buffer.size(), buffer.sizeUnit(), props ) / 2;
477 radiusElement.appendChild( doc.createTextNode( qgsDoubleToString( radius ) ) );
478
479 QDomElement fillElement = doc.createElement( u"se:Fill"_s );
480 haloElement.appendChild( fillElement );
481 fillElement.appendChild( QgsSymbolLayerUtils::createSvgParameterElement( doc, u"fill"_s, buffer.color().name() ) );
482 if ( buffer.opacity() != 1 )
483 {
484 fillElement.appendChild( QgsSymbolLayerUtils::createSvgParameterElement( doc, u"fill-opacity"_s, QString::number( buffer.opacity() ) ) );
485 }
486 }
487
488 // fill
489 QDomElement fillElement = doc.createElement( u"se:Fill"_s );
490 textSymbolizerElement.appendChild( fillElement );
491 fillElement.appendChild( QgsSymbolLayerUtils::createSvgParameterElement( doc, u"fill"_s, format.color().name() ) );
492 if ( format.opacity() != 1 )
493 {
494 fillElement.appendChild( QgsSymbolLayerUtils::createSvgParameterElement( doc, u"fill-opacity"_s, QString::number( format.opacity() ) ) );
495 }
496
497 // background graphic (not supported by SE 1.1, but supported by the GeoTools ecosystem as an extension)
498 const QgsTextBackgroundSettings background = format.background();
499 if ( background.enabled() )
500 {
501 std::unique_ptr<QgsMarkerSymbolLayer> layer = backgroundToMarkerLayer( background );
502 layer->writeSldMarker( doc, textSymbolizerElement, context );
503 }
504
505 // priority and zIndex, the default values are 0 and 5 in qgis (and between 0 and 10),
506 // in the GeoTools ecosystem there is a single priority value set at 1000 by default
507 if ( settings.priority != 5 || settings.zIndex > 0 )
508 {
509 QDomElement priorityElement = doc.createElement( u"se:Priority"_s );
510 textSymbolizerElement.appendChild( priorityElement );
511 int priority = 500 + 1000 * settings.zIndex + ( settings.priority - 5 ) * 100;
512 if ( settings.priority == 0 && settings.zIndex > 0 )
513 {
514 // small adjustment to make sure labels in z index n+1 are all above level n despite the priority value
515 priority += 1;
516 }
517 priorityElement.appendChild( doc.createTextNode( QString::number( priority ) ) );
518 }
519
520 // vendor options for text appearance
521 if ( font.underline() )
522 {
523 const QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, u"underlineText"_s, u"true"_s );
524 textSymbolizerElement.appendChild( vo );
525 }
526 if ( font.strikeOut() )
527 {
528 const QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, u"strikethroughText"_s, u"true"_s );
529 textSymbolizerElement.appendChild( vo );
530 }
531 // vendor options for text positioning
532 if ( maxDisplacement > 0 )
533 {
534 const QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, u"maxDisplacement"_s, qgsDoubleToString( maxDisplacement, 2 ) );
535 textSymbolizerElement.appendChild( vo );
536 }
537
538 switch ( settings.placement )
539 {
542 {
543 const QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, u"followLine"_s, u"true"_s );
544 textSymbolizerElement.appendChild( vo );
545 if ( settings.maxCurvedCharAngleIn > 0 || settings.maxCurvedCharAngleOut > 0 )
546 {
547 // SLD has no notion for this, the GeoTools ecosystem can only do a single angle
548 const double angle = std::min( std::fabs( settings.maxCurvedCharAngleIn ), std::fabs( settings.maxCurvedCharAngleOut ) );
549 const QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, u"maxAngleDelta"_s, qgsDoubleToString( angle ) );
550 textSymbolizerElement.appendChild( vo );
551 }
552 break;
553 }
554
562 break;
563 }
564
565 if ( repeatDistance > 0 )
566 {
567 const QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, u"repeat"_s, qgsDoubleToString( repeatDistance, 2 ) );
568 textSymbolizerElement.appendChild( vo );
569 }
570 // miscellaneous options
571 switch ( settings.placementSettings().overlapHandling() )
572 {
574 break;
577 const QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, u"conflictResolution"_s, u"false"_s );
578 textSymbolizerElement.appendChild( vo );
579 break;
580 }
582 {
583 const QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, u"forceLeftToRight"_s, u"false"_s );
584 textSymbolizerElement.appendChild( vo );
585 }
586 if ( settings.lineSettings().mergeLines() )
587 {
588 const QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, u"group"_s, u"yes"_s );
589 textSymbolizerElement.appendChild( vo );
590 switch ( settings.placementSettings().multiPartBehavior() )
591 {
594 break;
596 {
597 const QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, u"labelAllGroup"_s, u"true"_s );
598 textSymbolizerElement.appendChild( vo );
599 break;
600 }
601 }
602 }
603 // background symbol resize handling
604 if ( background.enabled() )
605 {
606 // enable resizing if needed
607 switch ( background.sizeType() )
608 {
610 {
611 QString resizeType;
613 {
614 resizeType = u"stretch"_s;
615 }
616 else
617 {
618 resizeType = u"proportional"_s;
619 }
620 const QDomElement voResize = QgsSymbolLayerUtils::createVendorOptionElement( doc, u"graphic-resize"_s, resizeType );
621 textSymbolizerElement.appendChild( voResize );
622
623 // now hadle margin
624 const QSizeF size = background.size();
625 if ( size.width() > 0 || size.height() > 0 )
626 {
627 double x = QgsSymbolLayerUtils::rescaleUom( size.width(), background.sizeUnit(), props );
628 double y = QgsSymbolLayerUtils::rescaleUom( size.height(), background.sizeUnit(), props );
629 // in case of ellipse qgis pads the size generously to make sure the text is inside the ellipse
630 // the following seems to do the trick and keep visual output similar
631 if ( background.type() == QgsTextBackgroundSettings::ShapeEllipse )
632 {
633 x += fontSize / 2;
634 y += fontSize;
635 }
636 const QString resizeSpec = QString( "%1 %2" ).arg( qgsDoubleToString( x, 2 ), qgsDoubleToString( y, 2 ) );
637 const QDomElement voMargin = QgsSymbolLayerUtils::createVendorOptionElement( doc, u"graphic-margin"_s, resizeSpec );
638 textSymbolizerElement.appendChild( voMargin );
639 }
640 break;
641 }
644 // nothing to do here
645 break;
646 }
647 }
648 return true;
649}
650
651void QgsVectorLayerSimpleLabeling::toSld( QDomNode &parent, const QVariantMap &props ) const
652{
653 QgsSldExportContext context;
654 context.setExtraProperties( props );
655 toSld( parent, context );
656}
657
658bool QgsVectorLayerSimpleLabeling::toSld( QDomNode &parent, QgsSldExportContext &context ) const
659{
660 if ( mSettings->drawLabels )
661 {
662 QDomDocument doc = parent.ownerDocument();
663
664 QDomElement ruleElement = doc.createElement( u"se:Rule"_s );
665 parent.appendChild( ruleElement );
666
667 // scale dependencies
668 if ( mSettings->scaleVisibility )
669 {
670 QVariantMap scaleProps = QVariantMap();
671 // tricky here, the max scale is expressed as its denominator, but it's still the max scale
672 // in other words, the smallest scale denominator....
673 scaleProps.insert( "scaleMinDenom", qgsDoubleToString( mSettings->maximumScale ) );
674 scaleProps.insert( "scaleMaxDenom", qgsDoubleToString( mSettings->minimumScale ) );
675 QgsSymbolLayerUtils::applyScaleDependency( doc, ruleElement, scaleProps );
676 }
677
678 writeTextSymbolizer( ruleElement, *mSettings, context );
679 }
680 return true;
681}
682
684{
685 QgsTextFormat format { mSettings->format() };
686 format.multiplyOpacity( opacityFactor );
687 mSettings->setFormat( format );
688}
689
691{
692 Q_UNUSED( providerId )
693
694 if ( mSettings.get() == settings )
695 return;
696
697 mSettings.reset( settings );
698}
@ LabelLargestPartOnly
Place a label only on the largest part from the geometry.
Definition qgis.h:1291
@ SplitLabelTextLinesOverParts
Splits the label text over the parts of the geometry, such that each consecutive part is labeled with...
Definition qgis.h:1293
@ LabelEveryPartWithEntireLabel
Place the (same) entire label over every part from the geometry.
Definition qgis.h:1292
@ FromSymbolBounds
Offset distance applies from rendered symbol bounds.
Definition qgis.h:1308
@ OverPoint
Arranges candidates over a point (or centroid of a polygon), or at a preset offset from the point....
Definition qgis.h:1234
@ Curved
Arranges candidates following the curvature of a line feature. Applies to line layers only.
Definition qgis.h:1236
@ AroundPoint
Arranges candidates in a circle around a point (or centroid of a polygon). Applies to point or polygo...
Definition qgis.h:1233
@ Line
Arranges candidates parallel to a generalised line representing the feature or parallel to a polygon'...
Definition qgis.h:1235
@ Free
Arranges candidates scattered throughout a polygon feature. Candidates are rotated to respect the pol...
Definition qgis.h:1238
@ OrderedPositionsAroundPoint
Candidates are placed in predefined positions around a point. Preference is given to positions with g...
Definition qgis.h:1239
@ Horizontal
Arranges horizontal candidates scattered throughout a polygon feature. Applies to polygon layers only...
Definition qgis.h:1237
@ PerimeterCurved
Arranges candidates following the curvature of a polygon's boundary. Applies to polygon layers only.
Definition qgis.h:1240
@ OutsidePolygons
Candidates are placed outside of polygon boundaries. Applies to polygon layers only.
Definition qgis.h:1241
MarkerShape
Marker shapes.
Definition qgis.h:3194
@ Circle
Circle.
Definition qgis.h:3203
@ Diamond
Diamond.
Definition qgis.h:3196
@ Square
Square.
Definition qgis.h:3195
Capitalization
String capitalization options.
Definition qgis.h:3503
@ MixedCase
Mixed case, ie no change.
Definition qgis.h:3504
@ AllLowercase
Convert all characters to lowercase.
Definition qgis.h:3506
@ ForceFirstLetterToCapital
Convert just the first letter of each word to uppercase, leave the rest untouched.
Definition qgis.h:3507
@ AllUppercase
Convert all characters to uppercase.
Definition qgis.h:3505
LabelQuadrantPosition
Label quadrant positions.
Definition qgis.h:1320
@ AboveRight
Above right.
Definition qgis.h:1323
@ BelowLeft
Below left.
Definition qgis.h:1327
@ Above
Above center.
Definition qgis.h:1322
@ BelowRight
Below right.
Definition qgis.h:1329
@ Right
Right middle.
Definition qgis.h:1326
@ AboveLeft
Above left.
Definition qgis.h:1321
@ Below
Below center.
Definition qgis.h:1328
@ Over
Center middle.
Definition qgis.h:1325
@ 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:5340
@ AllowOverlapAtNoCost
Labels may freely overlap other labels, at no cost.
Definition qgis.h:1196
@ AllowOverlapIfRequired
Avoids overlapping labels when possible, but permit overlaps if labels for features cannot otherwise ...
Definition qgis.h:1195
@ PreventOverlap
Do not allow labels to overlap other labels.
Definition qgis.h:1194
@ AlwaysAllowUpsideDown
Show upside down for all labels, including dynamic ones.
Definition qgis.h:1391
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:1478
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:6893
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)