QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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  ***************************************************************************/
15 #include "qgsvectorlayerlabeling.h"
16 
17 #include "qgspallabeling.h"
18 #include "qgsrulebasedlabeling.h"
19 #include "qgsvectorlayer.h"
20 #include "qgssymbollayerutils.h"
21 #include "qgssymbollayer.h"
22 #include "qgsmarkersymbollayer.h"
23 #include "qgis.h"
24 #include "qgsstyleentityvisitor.h"
25 
26 
28 {
29  QString type = element.attribute( QStringLiteral( "type" ) );
30  if ( type == QLatin1String( "rule-based" ) )
31  {
32  return QgsRuleBasedLabeling::create( element, context );
33  }
34  else if ( type == QLatin1String( "simple" ) )
35  {
36  return QgsVectorLayerSimpleLabeling::create( element, context );
37  }
38  else
39  {
40  return nullptr;
41  }
42 }
43 
45 {
46  return true;
47 }
48 
50 {
51  return new QgsVectorLayerLabelProvider( layer, QString(), false, mSettings.get() );
52 }
53 
55  : mSettings( new QgsPalLayerSettings( settings ) )
56 {
57 
58 }
59 
61 {
62  return QStringLiteral( "simple" );
63 }
64 
66 {
67  return new QgsVectorLayerSimpleLabeling( *mSettings );
68 }
69 
70 QDomElement QgsVectorLayerSimpleLabeling::save( QDomDocument &doc, const QgsReadWriteContext &context ) const
71 {
72  QDomElement elem = doc.createElement( QStringLiteral( "labeling" ) );
73  elem.setAttribute( QStringLiteral( "type" ), QStringLiteral( "simple" ) );
74  elem.appendChild( mSettings->writeXml( doc, context ) );
75  return elem;
76 }
77 
79 {
80  Q_UNUSED( providerId )
81  return *mSettings;
82 }
83 
85 {
86  if ( mSettings )
87  {
88  QgsStyleLabelSettingsEntity entity( *mSettings );
89  if ( !visitor->visit( &entity ) )
90  return false;
91  }
92  return true;
93 }
94 
96 {
97  return mSettings->format().containsAdvancedEffects();
98 }
99 
101 {
102  QDomElement settingsElem = element.firstChildElement( QStringLiteral( "settings" ) );
103  if ( !settingsElem.isNull() )
104  {
106  settings.readXml( settingsElem, context );
107  return new QgsVectorLayerSimpleLabeling( settings );
108  }
109 
111 }
112 
114 {
115  double quadOffsetX = 0.5, quadOffsetY = 0.5;
116 
117  // adjust quadrant offset of labels
118  switch ( quadrantPosition )
119  {
121  quadOffsetX = 1;
122  quadOffsetY = 0;
123  break;
125  quadOffsetX = 0.5;
126  quadOffsetY = 0;
127  break;
129  quadOffsetX = 0;
130  quadOffsetY = 0;
131  break;
133  quadOffsetX = 1;
134  quadOffsetY = 0.5;
135  break;
137  quadOffsetX = 0;
138  quadOffsetY = 0.5;
139  break;
141  quadOffsetX = 1;
142  quadOffsetY = 1;
143  break;
145  quadOffsetX = 0.5;
146  quadOffsetY = 1;
147  break;
149  quadOffsetX = 0;
150  quadOffsetY = 1.0;
151  break;
153  break;
154  }
155 
156  return QPointF( quadOffsetX, quadOffsetY );
157 }
158 
159 /*
160  * This is not a generic function encoder, just enough to encode the label case control functions
161  */
162 void appendSimpleFunction( QDomDocument &doc, QDomElement &parent, const QString &name, const QString &attribute )
163 {
164  QDomElement function = doc.createElement( QStringLiteral( "ogc:Function" ) );
165  function.setAttribute( QStringLiteral( "name" ), name );
166  parent.appendChild( function );
167  QDomElement property = doc.createElement( QStringLiteral( "ogc:PropertyName" ) );
168  property.appendChild( doc.createTextNode( attribute ) );
169  function.appendChild( property );
170 }
171 
172 std::unique_ptr<QgsMarkerSymbolLayer> backgroundToMarkerLayer( const QgsTextBackgroundSettings &settings )
173 {
174  std::unique_ptr<QgsMarkerSymbolLayer> layer;
175  switch ( settings.type() )
176  {
178  {
180  svg->setStrokeWidth( settings.strokeWidth() );
181  svg->setStrokeWidthUnit( settings.strokeWidthUnit() );
182  layer.reset( svg );
183  break;
184  }
186  {
187  // just grab the first layer and hope for the best
188  if ( settings.markerSymbol() && settings.markerSymbol()->symbolLayerCount() > 0 )
189  {
190  layer.reset( static_cast< QgsMarkerSymbolLayer * >( settings.markerSymbol()->symbolLayer( 0 )->clone() ) );
191  break;
192  }
193  FALLTHROUGH // not set, just go with the default
194  }
199  {
201  // default value
203  switch ( settings.type() )
204  {
208  break;
212  break;
215  break;
216  }
217 
218  marker->setShape( shape );
219  marker->setStrokeWidth( settings.strokeWidth() );
220  marker->setStrokeWidthUnit( settings.strokeWidthUnit() );
221  layer.reset( marker );
222  }
223  }
224  layer->setEnabled( true );
225  // a marker does not have a size x and y, just a size (and it should be at least one)
226  QSizeF size = settings.size();
227  layer->setSize( std::max( 1., std::max( size.width(), size.height() ) ) );
228  layer->setSizeUnit( settings.sizeUnit() );
229  // fill and stroke
230  QColor fillColor = settings.fillColor();
231  QColor strokeColor = settings.strokeColor();
232  if ( settings.opacity() < 1 )
233  {
234  int alpha = std::round( settings.opacity() * 255 );
235  fillColor.setAlpha( alpha );
236  strokeColor.setAlpha( alpha );
237  }
238  layer->setFillColor( fillColor );
239  layer->setStrokeColor( strokeColor );
240  // rotation
242  {
243  layer->setAngle( settings.rotation() );
244  }
245  // offset
246  layer->setOffset( settings.offset() );
247  layer->setOffsetUnit( settings.offsetUnit() );
248 
249  return layer;
250 }
251 
253 {
254  QDomDocument doc = parent.ownerDocument();
255 
256  // text symbolizer
257  QDomElement textSymbolizerElement = doc.createElement( QStringLiteral( "se:TextSymbolizer" ) );
258  parent.appendChild( textSymbolizerElement );
259 
260  // label
261  QgsTextFormat format = settings.format();
262  QFont font = format.font();
263  QDomElement labelElement = doc.createElement( QStringLiteral( "se:Label" ) );
264  textSymbolizerElement.appendChild( labelElement );
265  if ( settings.isExpression )
266  {
267  labelElement.appendChild( doc.createComment( QStringLiteral( "SE Export for %1 not implemented yet" ).arg( settings.getLabelExpression()->dump() ) ) );
268  labelElement.appendChild( doc.createTextNode( "Placeholder" ) );
269  }
270  else
271  {
272  if ( font.capitalization() == QFont::AllUppercase )
273  {
274  appendSimpleFunction( doc, labelElement, QStringLiteral( "strToUpperCase" ), settings.fieldName );
275  }
276  else if ( font.capitalization() == QFont::AllLowercase )
277  {
278  appendSimpleFunction( doc, labelElement, QStringLiteral( "strToLowerCase" ), settings.fieldName );
279  }
280  else if ( font.capitalization() == QFont::Capitalize )
281  {
282  appendSimpleFunction( doc, labelElement, QStringLiteral( "strCapitalize" ), settings.fieldName );
283  }
284  else
285  {
286  QDomElement propertyNameElement = doc.createElement( QStringLiteral( "ogc:PropertyName" ) );
287  propertyNameElement.appendChild( doc.createTextNode( settings.fieldName ) );
288  labelElement.appendChild( propertyNameElement );
289  }
290  }
291 
292  // font
293  QDomElement fontElement = doc.createElement( QStringLiteral( "se:Font" ) );
294  textSymbolizerElement.appendChild( fontElement );
295  fontElement.appendChild( QgsSymbolLayerUtils::createSvgParameterElement( doc, QStringLiteral( "font-family" ), font.family() ) );
296  double fontSize = QgsSymbolLayerUtils::rescaleUom( format.size(), format.sizeUnit(), props );
297  fontElement.appendChild( QgsSymbolLayerUtils::createSvgParameterElement( doc, QStringLiteral( "font-size" ), QString::number( fontSize ) ) );
298  if ( format.font().italic() )
299  {
300  fontElement.appendChild( QgsSymbolLayerUtils::createSvgParameterElement( doc, QStringLiteral( "font-style" ), QStringLiteral( "italic" ) ) );
301  }
302  if ( format.font().bold() )
303  {
304  fontElement.appendChild( QgsSymbolLayerUtils::createSvgParameterElement( doc, QStringLiteral( "font-weight" ), QStringLiteral( "bold" ) ) );
305  }
306 
307  // label placement
308  QDomElement labelPlacement = doc.createElement( QStringLiteral( "se:LabelPlacement" ) );
309  textSymbolizerElement.appendChild( labelPlacement );
310  double maxDisplacement = 0;
311  double repeatDistance = 0;
312  switch ( settings.placement )
313  {
315  {
316  QDomElement pointPlacement = doc.createElement( "se:PointPlacement" );
317  labelPlacement.appendChild( pointPlacement );
318  // anchor point
319  QPointF anchor = quadOffsetToSldAnchor( settings.quadOffset );
320  QgsSymbolLayerUtils::createAnchorPointElement( doc, pointPlacement, anchor );
321  // displacement
322  if ( settings.xOffset > 0 || settings.yOffset > 0 )
323  {
324  QgsUnitTypes::RenderUnit offsetUnit = settings.offsetUnits;
325  double dx = QgsSymbolLayerUtils::rescaleUom( settings.xOffset, offsetUnit, props );
326  double dy = QgsSymbolLayerUtils::rescaleUom( settings.yOffset, offsetUnit, props );
327  QgsSymbolLayerUtils::createDisplacementElement( doc, pointPlacement, QPointF( dx, dy ) );
328  }
329  // rotation
330  if ( settings.angleOffset != 0 )
331  {
332  QDomElement rotation = doc.createElement( "se:Rotation" );
333  pointPlacement.appendChild( rotation );
334  rotation.appendChild( doc.createTextNode( QString::number( settings.angleOffset ) ) );
335  }
336  }
337  break;
340  {
341  QDomElement pointPlacement = doc.createElement( "se:PointPlacement" );
342  labelPlacement.appendChild( pointPlacement );
343 
344  // SLD cannot do either, but let's do a best effort setting the distance using
345  // anchor point and displacement
346  QgsSymbolLayerUtils::createAnchorPointElement( doc, pointPlacement, QPointF( 0, 0.5 ) );
347  QgsUnitTypes::RenderUnit distUnit = settings.distUnits;
348  double radius = QgsSymbolLayerUtils::rescaleUom( settings.dist, distUnit, props );
349  double offset = std::sqrt( radius * radius / 2 ); // make it start top/right
350  maxDisplacement = radius + 1; // lock the distance
351  QgsSymbolLayerUtils::createDisplacementElement( doc, pointPlacement, QPointF( offset, offset ) );
352  }
353  break;
356  {
357  // still a point placement (for "free" it's a fallback, there is no SLD equivalent)
358  QDomElement pointPlacement = doc.createElement( "se:PointPlacement" );
359  labelPlacement.appendChild( pointPlacement );
360  QgsSymbolLayerUtils::createAnchorPointElement( doc, pointPlacement, QPointF( 0.5, 0.5 ) );
361  QgsUnitTypes::RenderUnit distUnit = settings.distUnits;
362  double dist = QgsSymbolLayerUtils::rescaleUom( settings.dist, distUnit, props );
363  QgsSymbolLayerUtils::createDisplacementElement( doc, pointPlacement, QPointF( 0, dist ) );
364  break;
365  }
369  {
370  QDomElement linePlacement = doc.createElement( "se:LinePlacement" );
371  labelPlacement.appendChild( linePlacement );
372 
373  // perpendicular distance if required
374  if ( settings.dist > 0 )
375  {
376  QgsUnitTypes::RenderUnit distUnit = settings.distUnits;
377  double dist = QgsSymbolLayerUtils::rescaleUom( settings.dist, distUnit, props );
378  QDomElement perpendicular = doc.createElement( "se:PerpendicularOffset" );
379  linePlacement.appendChild( perpendicular );
380  perpendicular.appendChild( doc.createTextNode( qgsDoubleToString( dist, 2 ) ) );
381  }
382 
383  // repeat distance if required
384  if ( settings.repeatDistance > 0 )
385  {
386  QDomElement repeat = doc.createElement( "se:Repeat" );
387  linePlacement.appendChild( repeat );
388  repeat.appendChild( doc.createTextNode( QStringLiteral( "true" ) ) );
389  QDomElement gap = doc.createElement( "se:Gap" );
390  linePlacement.appendChild( gap );
391  repeatDistance = QgsSymbolLayerUtils::rescaleUom( settings.repeatDistance, settings.repeatDistanceUnit, props );
392  gap.appendChild( doc.createTextNode( qgsDoubleToString( repeatDistance, 2 ) ) );
393  }
394 
395  // always generalized
396  QDomElement generalize = doc.createElement( "se:GeneralizeLine" );
397  linePlacement.appendChild( generalize );
398  generalize.appendChild( doc.createTextNode( QStringLiteral( "true" ) ) );
399  }
400  break;
401  }
402 
403  // halo
404  QgsTextBufferSettings buffer = format.buffer();
405  if ( buffer.enabled() )
406  {
407  QDomElement haloElement = doc.createElement( QStringLiteral( "se:Halo" ) );
408  textSymbolizerElement.appendChild( haloElement );
409 
410  QDomElement radiusElement = doc.createElement( QStringLiteral( "se:Radius" ) );
411  haloElement.appendChild( radiusElement );
412  // the SLD uses a radius, which is actually half of the link thickness the buffer size specifies
413  double radius = QgsSymbolLayerUtils::rescaleUom( buffer.size(), buffer.sizeUnit(), props ) / 2;
414  radiusElement.appendChild( doc.createTextNode( qgsDoubleToString( radius ) ) );
415 
416  QDomElement fillElement = doc.createElement( QStringLiteral( "se:Fill" ) );
417  haloElement.appendChild( fillElement );
418  fillElement.appendChild( QgsSymbolLayerUtils::createSvgParameterElement( doc, QStringLiteral( "fill" ), buffer.color().name() ) );
419  if ( buffer.opacity() != 1 )
420  {
421  fillElement.appendChild( QgsSymbolLayerUtils::createSvgParameterElement( doc, QStringLiteral( "fill-opacity" ), QString::number( buffer.opacity() ) ) );
422  }
423  }
424 
425  // fill
426  QDomElement fillElement = doc.createElement( QStringLiteral( "se:Fill" ) );
427  textSymbolizerElement.appendChild( fillElement );
428  fillElement.appendChild( QgsSymbolLayerUtils::createSvgParameterElement( doc, QStringLiteral( "fill" ), format.color().name() ) );
429  if ( format.opacity() != 1 )
430  {
431  fillElement.appendChild( QgsSymbolLayerUtils::createSvgParameterElement( doc, QStringLiteral( "fill-opacity" ), QString::number( format.opacity() ) ) );
432  }
433 
434  // background graphic (not supported by SE 1.1, but supported by the GeoTools ecosystem as an extension)
435  QgsTextBackgroundSettings background = format.background();
436  if ( background.enabled() )
437  {
438  std::unique_ptr<QgsMarkerSymbolLayer> layer = backgroundToMarkerLayer( background );
439  layer->writeSldMarker( doc, textSymbolizerElement, props );
440  }
441 
442  // priority and zIndex, the default values are 0 and 5 in qgis (and between 0 and 10),
443  // in the GeoTools ecosystem there is a single priority value set at 1000 by default
444  if ( settings.priority != 5 || settings.zIndex > 0 )
445  {
446  QDomElement priorityElement = doc.createElement( QStringLiteral( "se:Priority" ) );
447  textSymbolizerElement.appendChild( priorityElement );
448  int priority = 500 + 1000 * settings.zIndex + ( settings.priority - 5 ) * 100;
449  if ( settings.priority == 0 && settings.zIndex > 0 )
450  {
451  // small adjustment to make sure labels in z index n+1 are all above level n despite the priority value
452  priority += 1;
453  }
454  priorityElement.appendChild( doc.createTextNode( QString::number( priority ) ) );
455  }
456 
457  // vendor options for text appearance
458  if ( font.underline() )
459  {
460  QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, QStringLiteral( "underlineText" ), QStringLiteral( "true" ) );
461  textSymbolizerElement.appendChild( vo );
462  }
463  if ( font.strikeOut() )
464  {
465  QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, QStringLiteral( "strikethroughText" ), QStringLiteral( "true" ) );
466  textSymbolizerElement.appendChild( vo );
467  }
468  // vendor options for text positioning
469  if ( maxDisplacement > 0 )
470  {
471  QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, QStringLiteral( "maxDisplacement" ), qgsDoubleToString( maxDisplacement, 2 ) );
472  textSymbolizerElement.appendChild( vo );
473  }
475  {
476  QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, QStringLiteral( "followLine" ), QStringLiteral( "true" ) );
477  textSymbolizerElement.appendChild( vo );
478  if ( settings.maxCurvedCharAngleIn > 0 || settings.maxCurvedCharAngleOut > 0 )
479  {
480  // SLD has no notion for this, the GeoTools ecosystem can only do a single angle
481  double angle = std::min( std::fabs( settings.maxCurvedCharAngleIn ), std::fabs( settings.maxCurvedCharAngleOut ) );
482  QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, QStringLiteral( "maxAngleDelta" ), qgsDoubleToString( angle ) );
483  textSymbolizerElement.appendChild( vo );
484  }
485  }
486  if ( repeatDistance > 0 )
487  {
488  QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, QStringLiteral( "repeat" ), qgsDoubleToString( repeatDistance, 2 ) );
489  textSymbolizerElement.appendChild( vo );
490  }
491  // miscellaneous options
492  if ( settings.displayAll )
493  {
494  QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, QStringLiteral( "conflictResolution" ), QStringLiteral( "false" ) );
495  textSymbolizerElement.appendChild( vo );
496  }
498  {
499  QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, QStringLiteral( "forceLeftToRight" ), QStringLiteral( "false" ) );
500  textSymbolizerElement.appendChild( vo );
501  }
502  if ( settings.mergeLines )
503  {
504  QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, QStringLiteral( "group" ), QStringLiteral( "yes" ) );
505  textSymbolizerElement.appendChild( vo );
506  if ( settings.labelPerPart )
507  {
508  QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, QStringLiteral( "labelAllGroup" ), QStringLiteral( "true" ) );
509  textSymbolizerElement.appendChild( vo );
510  }
511  }
512  // background symbol resize handling
513  if ( background.enabled() )
514  {
515  // enable resizing if needed
516  switch ( background.sizeType() )
517  {
519  {
520  QString resizeType;
522  {
523  resizeType = QStringLiteral( "stretch" );
524  }
525  else
526  {
527  resizeType = QStringLiteral( "proportional" );
528  }
529  QDomElement voResize = QgsSymbolLayerUtils::createVendorOptionElement( doc, QStringLiteral( "graphic-resize" ), resizeType );
530  textSymbolizerElement.appendChild( voResize );
531 
532  // now hadle margin
533  QSizeF size = background.size();
534  if ( size.width() > 0 || size.height() > 0 )
535  {
536  double x = QgsSymbolLayerUtils::rescaleUom( size.width(), background.sizeUnit(), props );
537  double y = QgsSymbolLayerUtils::rescaleUom( size.height(), background.sizeUnit(), props );
538  // in case of ellipse qgis pads the size generously to make sure the text is inside the ellipse
539  // the following seems to do the trick and keep visual output similar
540  if ( background.type() == QgsTextBackgroundSettings::ShapeEllipse )
541  {
542  x += fontSize / 2;
543  y += fontSize;
544  }
545  QString resizeSpec = QString( "%1 %2" ).arg( qgsDoubleToString( x, 2 ), qgsDoubleToString( y, 2 ) );
546  QDomElement voMargin = QgsSymbolLayerUtils::createVendorOptionElement( doc, QStringLiteral( "graphic-margin" ), resizeSpec );
547  textSymbolizerElement.appendChild( voMargin );
548  }
549  break;
550  }
553  // nothing to do here
554  break;
555  }
556  }
557 }
558 
559 
560 void QgsVectorLayerSimpleLabeling::toSld( QDomNode &parent, const QgsStringMap &props ) const
561 {
562 
563  if ( mSettings->drawLabels )
564  {
565  QDomDocument doc = parent.ownerDocument();
566 
567  QDomElement ruleElement = doc.createElement( QStringLiteral( "se:Rule" ) );
568  parent.appendChild( ruleElement );
569 
570  // scale dependencies
571  if ( mSettings->scaleVisibility )
572  {
573  QgsStringMap scaleProps = QgsStringMap();
574  // tricky here, the max scale is expressed as its denominator, but it's still the max scale
575  // in other words, the smallest scale denominator....
576  scaleProps.insert( "scaleMinDenom", qgsDoubleToString( mSettings->maximumScale ) );
577  scaleProps.insert( "scaleMaxDenom", qgsDoubleToString( mSettings->minimumScale ) );
578  QgsSymbolLayerUtils::applyScaleDependency( doc, ruleElement, scaleProps );
579  }
580 
581  writeTextSymbolizer( ruleElement, *mSettings, props );
582  }
583 
584 
585 }
586 
588 {
589  Q_UNUSED( providerId )
590 
591  if ( mSettings.get() == settings )
592  return;
593 
594  mSettings.reset( settings );
595 }
QString type() const override
Unique type string of the labeling configuration implementation.
double xOffset
Horizontal offset of label.
The class is used as a container of context for various read/write operations on other objects...
QColor strokeColor() const
Returns the color used for outlining the background shape.
Shape size is determined by adding a buffer margin around text.
void toSld(QDomNode &parent, const QgsStringMap &props) const override
Writes the SE 1.1 TextSymbolizer element based on the current layer labeling settings.
double maxCurvedCharAngleOut
Maximum angle between outside curved label characters (valid range -20.0 to -95.0) ...
QgsVectorLayerLabelProvider * provider(QgsVectorLayer *layer) const override
QgsUnitTypes::RenderUnit repeatDistanceUnit
Units for repeating labels for a single feature.
static QDomElement createVendorOptionElement(QDomDocument &doc, const QString &name, const QString &value)
QSizeF size() const
Returns the size of the background shape.
double opacity() const
Returns the text&#39;s opacity.
QPointF offset() const
Returns the offset used for drawing the background shape.
QColor fillColor() const
Returns the color used for filing the background shape.
bool requiresAdvancedEffects() const override
Returns true if drawing labels requires advanced effects like composition modes, which could prevent ...
void setStrokeWidthUnit(QgsUnitTypes::RenderUnit u)
Sets the unit for the width of the marker&#39;s stroke.
double angleOffset
Label rotation, in degrees clockwise.
Simple marker symbol layer, consisting of a rendered shape with solid fill color and an stroke...
static void applyScaleDependency(QDomDocument &doc, QDomElement &ruleElem, QgsStringMap &props)
Checks if the properties contain scaleMinDenom and scaleMaxDenom, if available, they are added into t...
UpsideDownLabels upsidedownLabels
Controls whether upside down labels are displayed and how they are handled.
Arranges candidates over a point (or centroid of a polygon), or at a preset offset from the point...
Arranges candidates following the curvature of a line feature. Applies to line layers only...
static QDomElement createSvgParameterElement(QDomDocument &doc, const QString &name, const QString &value)
double opacity() const
Returns the background shape&#39;s opacity.
QString dump() const
Returns an expression string, constructed from the internal abstract syntax tree. ...
double strokeWidth() const
Returns the width of the shape&#39;s stroke (stroke).
double repeatDistance
Distance for repeating labels for a single feature.
QgsVectorLayerSimpleLabeling(const QgsPalLayerSettings &settings)
Constructs simple labeling configuration with given initial settings.
Candidates are placed in predefined positions around a point. Preference is given to positions with g...
QuadrantPosition quadOffset
Sets the quadrant in which to offset labels from feature.
QgsUnitTypes::RenderUnit offsetUnits
Units for offsets of label.
QColor color() const
Returns the color that text will be rendered in.
double yOffset
Vertical offset of label.
void setStrokeWidth(double w)
Sets the width of the marker&#39;s stroke.
The QgsVectorLayerLabelProvider class implements a label provider for vector layers.
static void createDisplacementElement(QDomDocument &doc, QDomElement &element, QPointF offset)
bool mergeLines
true if connected line features with identical label text should be merged prior to generating label ...
int symbolLayerCount() const
Returns the total number of symbol layers contained in the symbol.
Definition: qgssymbol.h:173
static QgsVectorLayerSimpleLabeling * create(const QDomElement &element, const QgsReadWriteContext &context)
Create the instance from a DOM element with saved configuration.
Shape size is determined by percent of text size.
Container for settings relating to a text background object.
An interface for classes which can visit style entity (e.g.
QgsAbstractVectorLayerLabeling * clone() const override
Returns a new copy of the object.
QMap< QString, QString > QgsStringMap
Definition: qgis.h:612
double maxCurvedCharAngleIn
Maximum angle between inside curved label characters (valid range 20.0 to 60.0).
double ANALYSIS_EXPORT angle(QgsPoint *p1, QgsPoint *p2, QgsPoint *p3, QgsPoint *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
Definition: MathUtils.cpp:786
ShapeType type() const
Returns the type of background shape (e.g., square, ellipse, SVG).
virtual bool visit(const QgsStyleEntityVisitorInterface::StyleLeaf &entity)
Called when the visitor will visit a style entity.
double zIndex
Z-Index of label, where labels with a higher z-index are rendered on top of labels with a lower z-ind...
Arranges horizontal candidates scattered throughout a polygon feature. Applies to polygon layers only...
static double rescaleUom(double size, QgsUnitTypes::RenderUnit unit, const QgsStringMap &props)
Rescales the given size based on the uomScale found in the props, if any is found, otherwise returns the value un-modified.
Shape rotation is a fixed angle.
void setStrokeWidthUnit(QgsUnitTypes::RenderUnit unit)
Sets the units for the stroke width.
bool displayAll
If true, all features will be labelled even when overlaps occur.
#define FALLTHROUGH
Definition: qgis.h:681
std::unique_ptr< QgsMarkerSymbolLayer > backgroundToMarkerLayer(const QgsTextBackgroundSettings &settings)
virtual QgsPalLayerSettings settings(const QString &providerId=QString()) const =0
Gets associated label settings.
RotationType rotationType() const
Returns the method used for rotating the background shape.
Show upside down for all labels, including dynamic ones.
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
Definition: qgis.h:240
virtual bool accept(QgsStyleEntityVisitorInterface *visitor) const
Accepts the specified symbology visitor, causing it to visit all symbols associated with the labeling...
virtual QgsSymbolLayer * clone() const =0
Shall be reimplemented by subclasses to create a deep copy of the instance.
Arranges candidates in a circle around a point (or centroid of a polygon). Applies to point or polygo...
QString svgFile() const
Returns the absolute path to the background SVG file, if set.
QgsTextBackgroundSettings & background()
Returns a reference to the text background settings.
QgsTextBufferSettings & buffer()
Returns a reference to the text buffer settings.
double opacity() const
Returns the buffer opacity.
QgsSymbolLayer * symbolLayer(int layer)
Returns the symbol layer at the specified index.
Definition: qgssymbol.cpp:362
QgsUnitTypes::RenderUnit strokeWidthUnit() const
Returns the units used for the shape&#39;s stroke width.
void setSettings(QgsPalLayerSettings *settings, const QString &providerId=QString()) override
Set pal settings (takes ownership).
const QgsTextFormat & format() const
Returns the label text formatting settings, e.g., font settings, buffer settings, etc...
static QgsRuleBasedLabeling * create(const QDomElement &element, const QgsReadWriteContext &context)
Create the instance from a DOM element with saved configuration.
QgsUnitTypes::RenderUnit offsetUnit() const
Returns the units used for the shape&#39;s offset.
double rotation() const
Returns the rotation for the background shape, in degrees clockwise.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Read settings from a DOM element.
QgsExpression * getLabelExpression()
Returns the QgsExpression for this label settings.
Arranges candidates parallel to a generalised line representing the feature or parallel to a polygon&#39;...
void setShape(QgsSimpleMarkerSymbolLayerBase::Shape shape)
Sets the rendered marker shape.
QgsUnitTypes::RenderUnit sizeUnit() const
Returns the units for the buffer size.
QDomElement save(QDomDocument &doc, const QgsReadWriteContext &context) const override
Returns labeling configuration as XML element.
QColor color() const
Returns the color of the buffer.
double size() const
Returns the size of the buffer.
static void createAnchorPointElement(QDomDocument &doc, QDomElement &element, QPointF anchor)
Creates a SE 1.1 anchor point element as a child of the specified element.
Container for settings relating to a text buffer.
double dist
Distance from feature to the label.
double size() const
Returns the size for rendered text.
A label settings entity for QgsStyle databases.
Definition: qgsstyle.h:1064
bool enabled() const
Returns whether the background is enabled.
Abstract base class - its implementations define different approaches to the labeling of a vector lay...
QPointF quadOffsetToSldAnchor(QgsPalLayerSettings::QuadrantPosition quadrantPosition)
virtual void writeTextSymbolizer(QDomNode &parent, QgsPalLayerSettings &settings, const QgsStringMap &props) const
Writes a TextSymbolizer element contents based on the provided labeling settings. ...
SizeType sizeType() const
Returns the method used to determine the size of the background shape (e.g., fixed size or buffer aro...
bool enabled() const
Returns whether the buffer is enabled.
Basic implementation of the labeling interface.
bool accept(QgsStyleEntityVisitorInterface *visitor) const override
Accepts the specified symbology visitor, causing it to visit all symbols associated with the labeling...
bool isExpression
true if this label is made from a expression string, e.g., FieldName || &#39;mm&#39;
QgsPalLayerSettings settings(const QString &providerId=QString()) const override
Gets associated label settings.
virtual QString type() const =0
Unique type string of the labeling configuration implementation.
Container for all settings relating to text rendering.
QgsUnitTypes::RenderUnit sizeUnit() const
Returns the units for the size of rendered text.
Represents a vector layer which manages a vector based data sets.
Arranges candidates following the curvature of a polygon&#39;s boundary. Applies to polygon layers only...
Square - buffered sizes only.
QFont font() const
Returns the font used for rendering text.
void appendSimpleFunction(QDomDocument &doc, QDomElement &parent, const QString &name, const QString &attribute)
int priority
Label priority.
QgsUnitTypes::RenderUnit sizeUnit() const
Returns the units used for the shape&#39;s size.
bool labelPerPart
true if every part of a multi-part feature should be labeled.
QgsUnitTypes::RenderUnit distUnits
Units the distance from feature to the label.
static QgsAbstractVectorLayerLabeling * create(const QDomElement &element, const QgsReadWriteContext &context)
Try to create instance of an implementation based on the XML data.
RenderUnit
Rendering size units.
Definition: qgsunittypes.h:145
QgsMarkerSymbol * markerSymbol() const
Returns the marker symbol to be rendered in the background.
QString fieldName
Name of field (or an expression) to use for label text.
Arranges candidates scattered throughout a polygon feature. Candidates are rotated to respect the pol...