QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 );
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 
252 void QgsAbstractVectorLayerLabeling::writeTextSymbolizer( QDomNode &parent, QgsPalLayerSettings &settings, const QgsStringMap &props ) const
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  {
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 ) );
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;
357  {
358  // still a point placement (for "free" it's a fallback, there is no SLD equivalent)
359  QDomElement pointPlacement = doc.createElement( "se:PointPlacement" );
360  labelPlacement.appendChild( pointPlacement );
361  QgsSymbolLayerUtils::createAnchorPointElement( doc, pointPlacement, QPointF( 0.5, 0.5 ) );
363  double dist = QgsSymbolLayerUtils::rescaleUom( settings.dist, distUnit, props );
364  QgsSymbolLayerUtils::createDisplacementElement( doc, pointPlacement, QPointF( 0, dist ) );
365  break;
366  }
370  {
371  QDomElement linePlacement = doc.createElement( "se:LinePlacement" );
372  labelPlacement.appendChild( linePlacement );
373 
374  // perpendicular distance if required
375  if ( settings.dist > 0 )
376  {
378  double dist = QgsSymbolLayerUtils::rescaleUom( settings.dist, distUnit, props );
379  QDomElement perpendicular = doc.createElement( "se:PerpendicularOffset" );
380  linePlacement.appendChild( perpendicular );
381  perpendicular.appendChild( doc.createTextNode( qgsDoubleToString( dist, 2 ) ) );
382  }
383 
384  // repeat distance if required
385  if ( settings.repeatDistance > 0 )
386  {
387  QDomElement repeat = doc.createElement( "se:Repeat" );
388  linePlacement.appendChild( repeat );
389  repeat.appendChild( doc.createTextNode( QStringLiteral( "true" ) ) );
390  QDomElement gap = doc.createElement( "se:Gap" );
391  linePlacement.appendChild( gap );
393  gap.appendChild( doc.createTextNode( qgsDoubleToString( repeatDistance, 2 ) ) );
394  }
395 
396  // always generalized
397  QDomElement generalize = doc.createElement( "se:GeneralizeLine" );
398  linePlacement.appendChild( generalize );
399  generalize.appendChild( doc.createTextNode( QStringLiteral( "true" ) ) );
400  }
401  break;
402  }
403 
404  // halo
405  QgsTextBufferSettings buffer = format.buffer();
406  if ( buffer.enabled() )
407  {
408  QDomElement haloElement = doc.createElement( QStringLiteral( "se:Halo" ) );
409  textSymbolizerElement.appendChild( haloElement );
410 
411  QDomElement radiusElement = doc.createElement( QStringLiteral( "se:Radius" ) );
412  haloElement.appendChild( radiusElement );
413  // the SLD uses a radius, which is actually half of the link thickness the buffer size specifies
414  double radius = QgsSymbolLayerUtils::rescaleUom( buffer.size(), buffer.sizeUnit(), props ) / 2;
415  radiusElement.appendChild( doc.createTextNode( qgsDoubleToString( radius ) ) );
416 
417  QDomElement fillElement = doc.createElement( QStringLiteral( "se:Fill" ) );
418  haloElement.appendChild( fillElement );
419  fillElement.appendChild( QgsSymbolLayerUtils::createSvgParameterElement( doc, QStringLiteral( "fill" ), buffer.color().name() ) );
420  if ( buffer.opacity() != 1 )
421  {
422  fillElement.appendChild( QgsSymbolLayerUtils::createSvgParameterElement( doc, QStringLiteral( "fill-opacity" ), QString::number( buffer.opacity() ) ) );
423  }
424  }
425 
426  // fill
427  QDomElement fillElement = doc.createElement( QStringLiteral( "se:Fill" ) );
428  textSymbolizerElement.appendChild( fillElement );
429  fillElement.appendChild( QgsSymbolLayerUtils::createSvgParameterElement( doc, QStringLiteral( "fill" ), format.color().name() ) );
430  if ( format.opacity() != 1 )
431  {
432  fillElement.appendChild( QgsSymbolLayerUtils::createSvgParameterElement( doc, QStringLiteral( "fill-opacity" ), QString::number( format.opacity() ) ) );
433  }
434 
435  // background graphic (not supported by SE 1.1, but supported by the GeoTools ecosystem as an extension)
436  QgsTextBackgroundSettings background = format.background();
437  if ( background.enabled() )
438  {
439  std::unique_ptr<QgsMarkerSymbolLayer> layer = backgroundToMarkerLayer( background );
440  layer->writeSldMarker( doc, textSymbolizerElement, props );
441  }
442 
443  // priority and zIndex, the default values are 0 and 5 in qgis (and between 0 and 10),
444  // in the GeoTools ecosystem there is a single priority value set at 1000 by default
445  if ( settings.priority != 5 || settings.zIndex > 0 )
446  {
447  QDomElement priorityElement = doc.createElement( QStringLiteral( "se:Priority" ) );
448  textSymbolizerElement.appendChild( priorityElement );
449  int priority = 500 + 1000 * settings.zIndex + ( settings.priority - 5 ) * 100;
450  if ( settings.priority == 0 && settings.zIndex > 0 )
451  {
452  // small adjustment to make sure labels in z index n+1 are all above level n despite the priority value
453  priority += 1;
454  }
455  priorityElement.appendChild( doc.createTextNode( QString::number( priority ) ) );
456  }
457 
458  // vendor options for text appearance
459  if ( font.underline() )
460  {
461  QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, QStringLiteral( "underlineText" ), QStringLiteral( "true" ) );
462  textSymbolizerElement.appendChild( vo );
463  }
464  if ( font.strikeOut() )
465  {
466  QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, QStringLiteral( "strikethroughText" ), QStringLiteral( "true" ) );
467  textSymbolizerElement.appendChild( vo );
468  }
469  // vendor options for text positioning
470  if ( maxDisplacement > 0 )
471  {
472  QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, QStringLiteral( "maxDisplacement" ), qgsDoubleToString( maxDisplacement, 2 ) );
473  textSymbolizerElement.appendChild( vo );
474  }
476  {
477  QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, QStringLiteral( "followLine" ), QStringLiteral( "true" ) );
478  textSymbolizerElement.appendChild( vo );
480  {
481  // SLD has no notion for this, the GeoTools ecosystem can only do a single angle
482  double angle = std::min( std::fabs( settings.maxCurvedCharAngleIn ), std::fabs( settings.maxCurvedCharAngleOut ) );
483  QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, QStringLiteral( "maxAngleDelta" ), qgsDoubleToString( angle ) );
484  textSymbolizerElement.appendChild( vo );
485  }
486  }
487  if ( repeatDistance > 0 )
488  {
489  QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, QStringLiteral( "repeat" ), qgsDoubleToString( repeatDistance, 2 ) );
490  textSymbolizerElement.appendChild( vo );
491  }
492  // miscellaneous options
493  if ( settings.displayAll )
494  {
495  QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, QStringLiteral( "conflictResolution" ), QStringLiteral( "false" ) );
496  textSymbolizerElement.appendChild( vo );
497  }
499  {
500  QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, QStringLiteral( "forceLeftToRight" ), QStringLiteral( "false" ) );
501  textSymbolizerElement.appendChild( vo );
502  }
503  if ( settings.mergeLines )
504  {
505  QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, QStringLiteral( "group" ), QStringLiteral( "yes" ) );
506  textSymbolizerElement.appendChild( vo );
507  if ( settings.labelPerPart )
508  {
509  QDomElement vo = QgsSymbolLayerUtils::createVendorOptionElement( doc, QStringLiteral( "labelAllGroup" ), QStringLiteral( "true" ) );
510  textSymbolizerElement.appendChild( vo );
511  }
512  }
513  // background symbol resize handling
514  if ( background.enabled() )
515  {
516  // enable resizing if needed
517  switch ( background.sizeType() )
518  {
520  {
521  QString resizeType;
523  {
524  resizeType = QStringLiteral( "stretch" );
525  }
526  else
527  {
528  resizeType = QStringLiteral( "proportional" );
529  }
530  QDomElement voResize = QgsSymbolLayerUtils::createVendorOptionElement( doc, QStringLiteral( "graphic-resize" ), resizeType );
531  textSymbolizerElement.appendChild( voResize );
532 
533  // now hadle margin
534  QSizeF size = background.size();
535  if ( size.width() > 0 || size.height() > 0 )
536  {
537  double x = QgsSymbolLayerUtils::rescaleUom( size.width(), background.sizeUnit(), props );
538  double y = QgsSymbolLayerUtils::rescaleUom( size.height(), background.sizeUnit(), props );
539  // in case of ellipse qgis pads the size generously to make sure the text is inside the ellipse
540  // the following seems to do the trick and keep visual output similar
541  if ( background.type() == QgsTextBackgroundSettings::ShapeEllipse )
542  {
543  x += fontSize / 2;
544  y += fontSize;
545  }
546  QString resizeSpec = QString( "%1 %2" ).arg( qgsDoubleToString( x, 2 ), qgsDoubleToString( y, 2 ) );
547  QDomElement voMargin = QgsSymbolLayerUtils::createVendorOptionElement( doc, QStringLiteral( "graphic-margin" ), resizeSpec );
548  textSymbolizerElement.appendChild( voMargin );
549  }
550  break;
551  }
554  // nothing to do here
555  break;
556  }
557  }
558 }
559 
560 
561 void QgsVectorLayerSimpleLabeling::toSld( QDomNode &parent, const QgsStringMap &props ) const
562 {
563 
564  if ( mSettings->drawLabels )
565  {
566  QDomDocument doc = parent.ownerDocument();
567 
568  QDomElement ruleElement = doc.createElement( QStringLiteral( "se:Rule" ) );
569  parent.appendChild( ruleElement );
570 
571  // scale dependencies
572  if ( mSettings->scaleVisibility )
573  {
574  QgsStringMap scaleProps = QgsStringMap();
575  // tricky here, the max scale is expressed as its denominator, but it's still the max scale
576  // in other words, the smallest scale denominator....
577  scaleProps.insert( "scaleMinDenom", qgsDoubleToString( mSettings->maximumScale ) );
578  scaleProps.insert( "scaleMaxDenom", qgsDoubleToString( mSettings->minimumScale ) );
579  QgsSymbolLayerUtils::applyScaleDependency( doc, ruleElement, scaleProps );
580  }
581 
582  writeTextSymbolizer( ruleElement, *mSettings, props );
583  }
584 
585 
586 }
587 
588 void QgsVectorLayerSimpleLabeling::setSettings( QgsPalLayerSettings *settings, const QString &providerId )
589 {
590  Q_UNUSED( providerId )
591 
592  if ( mSettings.get() == settings )
593  return;
594 
595  mSettings.reset( settings );
596 }
QgsPalLayerSettings::readXml
void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Read settings from a DOM element.
Definition: qgspallabeling.cpp:910
QgsPalLayerSettings::distUnits
QgsUnitTypes::RenderUnit distUnits
Units the distance from feature to the label.
Definition: qgspallabeling.h:707
QgsTextFormat::buffer
QgsTextBufferSettings & buffer()
Returns a reference to the text buffer settings.
Definition: qgstextformat.h:66
quadOffsetToSldAnchor
QPointF quadOffsetToSldAnchor(QgsPalLayerSettings::QuadrantPosition quadrantPosition)
Definition: qgsvectorlayerlabeling.cpp:113
qgspallabeling.h
QgsPalLayerSettings::PerimeterCurved
@ PerimeterCurved
Arranges candidates following the curvature of a polygon's boundary. Applies to polygon layers only.
Definition: qgspallabeling.h:229
QgsVectorLayerSimpleLabeling::accept
bool accept(QgsStyleEntityVisitorInterface *visitor) const override
Accepts the specified symbology visitor, causing it to visit all symbols associated with the labeling...
Definition: qgsvectorlayerlabeling.cpp:84
QgsPalLayerSettings::angleOffset
double angleOffset
Label rotation, in degrees clockwise.
Definition: qgspallabeling.h:802
QgsUnitTypes::RenderUnit
RenderUnit
Rendering size units.
Definition: qgsunittypes.h:166
QgsPalLayerSettings::AroundPoint
@ AroundPoint
Arranges candidates in a circle around a point (or centroid of a polygon). Applies to point or polygo...
Definition: qgspallabeling.h:222
QgsReadWriteContext
Definition: qgsreadwritecontext.h:34
QgsTextBackgroundSettings::enabled
bool enabled() const
Returns whether the background is enabled.
Definition: qgstextbackgroundsettings.cpp:47
QgsVectorLayerSimpleLabeling::save
QDomElement save(QDomDocument &doc, const QgsReadWriteContext &context) const override
Returns labeling configuration as XML element.
Definition: qgsvectorlayerlabeling.cpp:70
QgsPalLayerSettings::maxCurvedCharAngleOut
double maxCurvedCharAngleOut
Maximum angle between outside curved label characters (valid range -20.0 to -95.0)
Definition: qgspallabeling.h:817
QgsPalLayerSettings
Definition: qgspallabeling.h:205
QgsPalLayerSettings::zIndex
double zIndex
Z-Index of label, where labels with a higher z-index are rendered on top of labels with a lower z-ind...
Definition: qgspallabeling.h:925
QgsPalLayerSettings::labelPerPart
bool labelPerPart
true if every part of a multi-part feature should be labeled.
Definition: qgspallabeling.h:889
QgsExpression::dump
QString dump() const
Returns an expression string, constructed from the internal abstract syntax tree.
Definition: qgsexpression.cpp:389
QgsPalLayerSettings::getLabelExpression
QgsExpression * getLabelExpression()
Returns the QgsExpression for this label settings.
Definition: qgspallabeling.cpp:585
QgsPalLayerSettings::upsidedownLabels
UpsideDownLabels upsidedownLabels
Controls whether upside down labels are displayed and how they are handled.
Definition: qgspallabeling.h:883
qgssymbollayerutils.h
QgsPalLayerSettings::yOffset
double yOffset
Vertical offset of label.
Definition: qgspallabeling.h:783
QgsTextFormat::sizeUnit
QgsUnitTypes::RenderUnit sizeUnit() const
Returns the units for the size of rendered text.
Definition: qgstextformat.cpp:96
qgsmarkersymbollayer.h
QgsTextBackgroundSettings::fillColor
QColor fillColor() const
Returns the color used for filing the background shape.
Definition: qgstextbackgroundsettings.cpp:227
QgsTextBackgroundSettings
Definition: qgstextbackgroundsettings.h:45
QgsTextBufferSettings::opacity
double opacity() const
Returns the buffer opacity.
Definition: qgstextbuffersettings.cpp:107
qgis.h
QgsPalLayerSettings::QuadrantPosition
QuadrantPosition
Definition: qgspallabeling.h:282
QgsPalLayerSettings::mergeLines
bool mergeLines
true if connected line features with identical label text should be merged prior to generating label ...
Definition: qgspallabeling.h:895
QgsStyleEntityVisitorInterface
Definition: qgsstyleentityvisitor.h:33
QgsTextBackgroundSettings::offset
QPointF offset() const
Returns the offset used for drawing the background shape.
Definition: qgstextbackgroundsettings.cpp:147
QgsMarkerSymbolLayer
Abstract base class for marker symbol layers.
Definition: qgssymbollayer.h:575
QgsSymbolLayerUtils::createAnchorPointElement
static void createAnchorPointElement(QDomDocument &doc, QDomElement &element, QPointF anchor)
Creates a SE 1.1 anchor point element as a child of the specified element.
Definition: qgssymbollayerutils.cpp:2538
QgsTextBackgroundSettings::opacity
double opacity() const
Returns the background shape's opacity.
Definition: qgstextbackgroundsettings.cpp:207
QgsVectorLayerSimpleLabeling::setSettings
void setSettings(QgsPalLayerSettings *settings, const QString &providerId=QString()) override
Set pal settings (takes ownership).
Definition: qgsvectorlayerlabeling.cpp:588
FALLTHROUGH
#define FALLTHROUGH
Definition: qgis.h:783
QgsTextBackgroundSettings::strokeWidthUnit
QgsUnitTypes::RenderUnit strokeWidthUnit() const
Returns the units used for the shape's stroke width.
Definition: qgstextbackgroundsettings.cpp:257
QgsPalLayerSettings::Line
@ Line
Arranges candidates parallel to a generalised line representing the feature or parallel to a polygon'...
Definition: qgspallabeling.h:224
QgsSymbol::symbolLayer
QgsSymbolLayer * symbolLayer(int layer)
Returns the symbol layer at the specified index.
Definition: qgssymbol.cpp:366
QgsAbstractVectorLayerLabeling::type
virtual QString type() const =0
Unique type string of the labeling configuration implementation.
QgsTextBackgroundSettings::sizeType
SizeType sizeType() const
Returns the method used to determine the size of the background shape (e.g., fixed size or buffer aro...
Definition: qgstextbackgroundsettings.cpp:87
QgsVectorLayerLabelProvider
The QgsVectorLayerLabelProvider class implements a label provider for vector layers....
Definition: qgsvectorlayerlabelprovider.h:40
QgsPalLayerSettings::dist
double dist
Distance from feature to the label.
Definition: qgspallabeling.h:700
QgsPalLayerSettings::OverPoint
@ OverPoint
Arranges candidates over a point (or centroid of a polygon), or at a preset offset from the point....
Definition: qgspallabeling.h:223
qgsDoubleToString
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
Definition: qgis.h:275
QgsSimpleMarkerSymbolLayer::setStrokeWidthUnit
void setStrokeWidthUnit(QgsUnitTypes::RenderUnit u)
Sets the unit for the width of the marker's stroke.
Definition: qgsmarkersymbollayer.h:337
QgsPalLayerSettings::QuadrantAboveRight
@ QuadrantAboveRight
Definition: qgspallabeling.h:286
QgsTextBackgroundSettings::ShapeSquare
@ ShapeSquare
Square - buffered sizes only.
Definition: qgstextbackgroundsettings.h:55
QgsSvgMarkerSymbolLayer::setStrokeWidthUnit
void setStrokeWidthUnit(QgsUnitTypes::RenderUnit unit)
Sets the units for the stroke width.
Definition: qgsmarkersymbollayer.h:588
QgsTextFormat::color
QColor color() const
Returns the color that text will be rendered in.
Definition: qgstextformat.cpp:126
QgsSymbolLayerUtils::createDisplacementElement
static void createDisplacementElement(QDomDocument &doc, QDomElement &element, QPointF offset)
Definition: qgssymbollayerutils.cpp:2520
QgsPalLayerSettings::repeatDistance
double repeatDistance
Distance for repeating labels for a single feature.
Definition: qgspallabeling.h:724
QgsPalLayerSettings::QuadrantBelowLeft
@ QuadrantBelowLeft
Definition: qgspallabeling.h:290
QgsPalLayerSettings::repeatDistanceUnit
QgsUnitTypes::RenderUnit repeatDistanceUnit
Units for repeating labels for a single feature.
Definition: qgspallabeling.h:731
QgsPalLayerSettings::xOffset
double xOffset
Horizontal offset of label.
Definition: qgspallabeling.h:775
QgsPalLayerSettings::displayAll
bool displayAll
If true, all features will be labelled even when overlaps occur.
Definition: qgspallabeling.h:880
QgsSimpleMarkerSymbolLayerBase::setShape
void setShape(QgsSimpleMarkerSymbolLayerBase::Shape shape)
Sets the rendered marker shape.
Definition: qgsmarkersymbollayer.h:108
QgsSymbolLayer::clone
virtual QgsSymbolLayer * clone() const =0
Shall be reimplemented by subclasses to create a deep copy of the instance.
QgsPalLayerSettings::OrderedPositionsAroundPoint
@ OrderedPositionsAroundPoint
Candidates are placed in predefined positions around a point. Preference is given to positions with g...
Definition: qgspallabeling.h:228
QgsTextBackgroundSettings::rotationType
RotationType rotationType() const
Returns the method used for rotating the background shape.
Definition: qgstextbackgroundsettings.cpp:127
QgsTextFormat
Definition: qgstextformat.h:38
QgsTextBackgroundSettings::size
QSizeF size() const
Returns the size of the background shape.
Definition: qgstextbackgroundsettings.cpp:97
QgsAbstractVectorLayerLabeling::create
static QgsAbstractVectorLayerLabeling * create(const QDomElement &element, const QgsReadWriteContext &context)
Try to create instance of an implementation based on the XML data.
Definition: qgsvectorlayerlabeling.cpp:27
QgsPalLayerSettings::Curved
@ Curved
Arranges candidates following the curvature of a line feature. Applies to line layers only.
Definition: qgspallabeling.h:225
QgsTextBackgroundSettings::ShapeRectangle
@ ShapeRectangle
Rectangle.
Definition: qgstextbackgroundsettings.h:54
QgsSimpleMarkerSymbolLayerBase::Shape
Shape
Marker symbol shapes.
Definition: qgsmarkersymbollayer.h:48
qgsrulebasedlabeling.h
QgsPalLayerSettings::QuadrantLeft
@ QuadrantLeft
Definition: qgspallabeling.h:287
QgsVectorLayerSimpleLabeling::QgsVectorLayerSimpleLabeling
QgsVectorLayerSimpleLabeling(const QgsPalLayerSettings &settings)
Constructs simple labeling configuration with given initial settings.
Definition: qgsvectorlayerlabeling.cpp:54
QgsSvgMarkerSymbolLayer::setStrokeWidth
void setStrokeWidth(double w)
Definition: qgsmarkersymbollayer.h:581
QgsTextBackgroundSettings::ShapeCircle
@ ShapeCircle
Circle.
Definition: qgstextbackgroundsettings.h:57
QgsPalLayerSettings::format
const QgsTextFormat & format() const
Returns the label text formatting settings, e.g., font settings, buffer settings, etc.
Definition: qgspallabeling.h:1015
QgsTextBackgroundSettings::strokeWidth
double strokeWidth() const
Returns the width of the shape's stroke (stroke).
Definition: qgstextbackgroundsettings.cpp:247
QgsSymbolLayerUtils::rescaleUom
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,...
Definition: qgssymbollayerutils.cpp:4262
QgsSimpleMarkerSymbolLayer
Simple marker symbol layer, consisting of a rendered shape with solid fill color and an stroke.
Definition: qgsmarkersymbollayer.h:198
QgsSvgMarkerSymbolLayer
Definition: qgsmarkersymbollayer.h:482
QgsPalLayerSettings::placement
Placement placement
Definition: qgspallabeling.h:645
QgsSimpleMarkerSymbolLayerBase::Circle
@ Circle
Circle.
Definition: qgsmarkersymbollayer.h:58
QgsTextBackgroundSettings::SizeBuffer
@ SizeBuffer
Shape size is determined by adding a buffer margin around text.
Definition: qgstextbackgroundsettings.h:67
QgsTextBackgroundSettings::rotation
double rotation() const
Returns the rotation for the background shape, in degrees clockwise.
Definition: qgstextbackgroundsettings.cpp:137
qgssymbollayer.h
QgsTextFormat::opacity
double opacity() const
Returns the text's opacity.
Definition: qgstextformat.cpp:136
QgsSymbolLayerUtils::createVendorOptionElement
static QDomElement createVendorOptionElement(QDomDocument &doc, const QString &name, const QString &value)
Definition: qgssymbollayerutils.cpp:2887
QgsVectorLayerSimpleLabeling::settings
QgsPalLayerSettings settings(const QString &providerId=QString()) const override
Gets associated label settings.
Definition: qgsvectorlayerlabeling.cpp:78
QgsVectorLayerSimpleLabeling::create
static QgsVectorLayerSimpleLabeling * create(const QDomElement &element, const QgsReadWriteContext &context)
Create the instance from a DOM element with saved configuration.
Definition: qgsvectorlayerlabeling.cpp:100
QgsTextBufferSettings
Definition: qgstextbuffersettings.h:42
QgsSimpleMarkerSymbolLayer::setStrokeWidth
void setStrokeWidth(double w)
Sets the width of the marker's stroke.
Definition: qgsmarkersymbollayer.h:328
QgsTextBufferSettings::sizeUnit
QgsUnitTypes::RenderUnit sizeUnit() const
Returns the units for the buffer size.
Definition: qgstextbuffersettings.cpp:67
QgsTextBackgroundSettings::type
ShapeType type() const
Returns the type of background shape (e.g., square, ellipse, SVG).
Definition: qgstextbackgroundsettings.cpp:57
QgsTextBackgroundSettings::svgFile
QString svgFile() const
Returns the absolute path to the background SVG file, if set.
Definition: qgstextbackgroundsettings.cpp:67
QgsStyleLabelSettingsEntity
Definition: qgsstyle.h:1227
QgsAbstractVectorLayerLabeling
Definition: qgsvectorlayerlabeling.h:41
QgsPalLayerSettings::Horizontal
@ Horizontal
Arranges horizontal candidates scattered throughout a polygon feature. Applies to polygon layers only...
Definition: qgspallabeling.h:226
QgsTextBufferSettings::size
double size() const
Returns the size of the buffer.
Definition: qgstextbuffersettings.cpp:57
QgsTextBackgroundSettings::ShapeEllipse
@ ShapeEllipse
Ellipse.
Definition: qgstextbackgroundsettings.h:56
QgsSymbolLayerUtils::applyScaleDependency
static void applyScaleDependency(QDomDocument &doc, QDomElement &ruleElem, QgsStringMap &props)
Checks if the properties contain scaleMinDenom and scaleMaxDenom, if available, they are added into t...
Definition: qgssymbollayerutils.cpp:4357
qgsvectorlayer.h
QgsPalLayerSettings::QuadrantBelowRight
@ QuadrantBelowRight
Definition: qgspallabeling.h:292
QgsPalLayerSettings::QuadrantBelow
@ QuadrantBelow
Definition: qgspallabeling.h:291
QgsTextFormat::size
double size() const
Returns the size for rendered text.
Definition: qgstextformat.cpp:116
QgsSimpleMarkerSymbolLayerBase::Square
@ Square
Square.
Definition: qgsmarkersymbollayer.h:50
QgsSymbolLayerUtils::createSvgParameterElement
static QDomElement createSvgParameterElement(QDomDocument &doc, const QString &name, const QString &value)
Definition: qgssymbollayerutils.cpp:2840
appendSimpleFunction
void appendSimpleFunction(QDomDocument &doc, QDomElement &parent, const QString &name, const QString &attribute)
Definition: qgsvectorlayerlabeling.cpp:162
backgroundToMarkerLayer
std::unique_ptr< QgsMarkerSymbolLayer > backgroundToMarkerLayer(const QgsTextBackgroundSettings &settings)
Definition: qgsvectorlayerlabeling.cpp:172
QgsPalLayerSettings::priority
int priority
Label priority.
Definition: qgspallabeling.h:823
QgsTextBufferSettings::enabled
bool enabled() const
Returns whether the buffer is enabled.
Definition: qgstextbuffersettings.cpp:47
QgsStringMap
QMap< QString, QString > QgsStringMap
Definition: qgis.h:714
QgsPalLayerSettings::fieldName
QString fieldName
Name of field (or an expression) to use for label text.
Definition: qgspallabeling.h:531
QgsVectorLayerSimpleLabeling
Definition: qgsvectorlayerlabeling.h:156
QgsTextBackgroundSettings::ShapeSVG
@ ShapeSVG
SVG file.
Definition: qgstextbackgroundsettings.h:58
QgsTextBackgroundSettings::SizeFixed
@ SizeFixed
Fixed size.
Definition: qgstextbackgroundsettings.h:68
QgsVectorLayer
Definition: qgsvectorlayer.h:385
QgsPalLayerSettings::OutsidePolygons
@ OutsidePolygons
Candidates are placed outside of polygon boundaries. Applies to polygon layers only....
Definition: qgspallabeling.h:230
QgsPalLayerSettings::QuadrantRight
@ QuadrantRight
Definition: qgspallabeling.h:289
QgsVectorLayerSimpleLabeling::type
QString type() const override
Unique type string of the labeling configuration implementation.
Definition: qgsvectorlayerlabeling.cpp:60
QgsPalLayerSettings::quadOffset
QuadrantPosition quadOffset
Sets the quadrant in which to offset labels from feature.
Definition: qgspallabeling.h:767
QgsVectorLayerSimpleLabeling::requiresAdvancedEffects
bool requiresAdvancedEffects() const override
Returns true if drawing labels requires advanced effects like composition modes, which could prevent ...
Definition: qgsvectorlayerlabeling.cpp:95
QgsPalLayerSettings::maxCurvedCharAngleIn
double maxCurvedCharAngleIn
Maximum angle between inside curved label characters (valid range 20.0 to 60.0).
Definition: qgspallabeling.h:811
QgsPalLayerSettings::isExpression
bool isExpression
true if this label is made from a expression string, e.g., FieldName || 'mm'
Definition: qgspallabeling.h:537
QgsTextBackgroundSettings::SizePercent
@ SizePercent
Shape size is determined by percent of text size.
Definition: qgstextbackgroundsettings.h:69
QgsTextFormat::font
QFont font() const
Returns the font used for rendering text.
Definition: qgstextformat.cpp:62
QgsPalLayerSettings::QuadrantOver
@ QuadrantOver
Definition: qgspallabeling.h:288
QgsVectorLayerSimpleLabeling::provider
QgsVectorLayerLabelProvider * provider(QgsVectorLayer *layer) const override
Definition: qgsvectorlayerlabeling.cpp:49
QgsVectorLayerSimpleLabeling::toSld
void toSld(QDomNode &parent, const QgsStringMap &props) const override
Writes the SE 1.1 TextSymbolizer element based on the current layer labeling settings.
Definition: qgsvectorlayerlabeling.cpp:561
QgsPalLayerSettings::offsetUnits
QgsUnitTypes::RenderUnit offsetUnits
Units for offsets of label.
Definition: qgspallabeling.h:791
QgsStyleEntityVisitorInterface::visit
virtual bool visit(const QgsStyleEntityVisitorInterface::StyleLeaf &entity)
Called when the visitor will visit a style entity.
Definition: qgsstyleentityvisitor.h:153
QgsTextFormat::background
QgsTextBackgroundSettings & background()
Returns a reference to the text background settings.
Definition: qgstextformat.h:85
QgsTextBackgroundSettings::sizeUnit
QgsUnitTypes::RenderUnit sizeUnit() const
Returns the units used for the shape's size.
Definition: qgstextbackgroundsettings.cpp:107
qgsvectorlayerlabeling.h
QgsAbstractVectorLayerLabeling::writeTextSymbolizer
virtual void writeTextSymbolizer(QDomNode &parent, QgsPalLayerSettings &settings, const QgsStringMap &props) const
Writes a TextSymbolizer element contents based on the provided labeling settings.
Definition: qgsvectorlayerlabeling.cpp:252
QgsPalLayerSettings::QuadrantAboveLeft
@ QuadrantAboveLeft
Definition: qgspallabeling.h:284
QgsTextBackgroundSettings::ShapeMarkerSymbol
@ ShapeMarkerSymbol
Marker symbol.
Definition: qgstextbackgroundsettings.h:59
QgsTextBufferSettings::color
QColor color() const
Returns the color of the buffer.
Definition: qgstextbuffersettings.cpp:87
QgsTextBackgroundSettings::RotationFixed
@ RotationFixed
Shape rotation is a fixed angle.
Definition: qgstextbackgroundsettings.h:79
QgsTextBackgroundSettings::markerSymbol
QgsMarkerSymbol * markerSymbol() const
Returns the marker symbol to be rendered in the background.
Definition: qgstextbackgroundsettings.cpp:77
QgsAbstractVectorLayerLabeling::accept
virtual bool accept(QgsStyleEntityVisitorInterface *visitor) const
Accepts the specified symbology visitor, causing it to visit all symbols associated with the labeling...
Definition: qgsvectorlayerlabeling.cpp:44
QgsPalLayerSettings::Free
@ Free
Arranges candidates scattered throughout a polygon feature. Candidates are rotated to respect the pol...
Definition: qgspallabeling.h:227
MathUtils::angle
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
QgsVectorLayerSimpleLabeling::clone
QgsAbstractVectorLayerLabeling * clone() const override
Returns a new copy of the object.
Definition: qgsvectorlayerlabeling.cpp:65
QgsRuleBasedLabeling::create
static QgsRuleBasedLabeling * create(const QDomElement &element, const QgsReadWriteContext &context)
Create the instance from a DOM element with saved configuration.
Definition: qgsrulebasedlabeling.cpp:458
QgsTextBackgroundSettings::strokeColor
QColor strokeColor() const
Returns the color used for outlining the background shape.
Definition: qgstextbackgroundsettings.cpp:237
QgsAbstractVectorLayerLabeling::settings
virtual QgsPalLayerSettings settings(const QString &providerId=QString()) const =0
Gets associated label settings.
QgsPalLayerSettings::QuadrantAbove
@ QuadrantAbove
Definition: qgspallabeling.h:285
QgsTextBackgroundSettings::offsetUnit
QgsUnitTypes::RenderUnit offsetUnit() const
Returns the units used for the shape's offset.
Definition: qgstextbackgroundsettings.cpp:157
qgsstyleentityvisitor.h
QgsPalLayerSettings::ShowAll
@ ShowAll
Show upside down for all labels, including dynamic ones.
Definition: qgspallabeling.h:299
QgsSymbol::symbolLayerCount
int symbolLayerCount() const
Returns the total number of symbol layers contained in the symbol.
Definition: qgssymbol.h:183
QgsSimpleMarkerSymbolLayerBase::Diamond
@ Diamond
Diamond.
Definition: qgsmarkersymbollayer.h:51