| QGIS API Documentation
    3.16.0-Hannover (43b64b13f3)
    | 
 
 
 
Go to the documentation of this file.
   29   QString 
type = element.attribute( QStringLiteral( 
"type" ) );
 
   30   if ( 
type == QLatin1String( 
"rule-based" ) )
 
   34   else if ( 
type == QLatin1String( 
"simple" ) )
 
   62   return QStringLiteral( 
"simple" );
 
   72   QDomElement elem = doc.createElement( QStringLiteral( 
"labeling" ) );
 
   73   elem.setAttribute( QStringLiteral( 
"type" ), QStringLiteral( 
"simple" ) );
 
   74   elem.appendChild( mSettings->writeXml( doc, context ) );
 
   80   Q_UNUSED( providerId )
 
   89     if ( !visitor->
visit( &entity ) )
 
   97   return mSettings->format().containsAdvancedEffects();
 
  102   QDomElement settingsElem = element.firstChildElement( QStringLiteral( 
"settings" ) );
 
  103   if ( !settingsElem.isNull() )
 
  115   double quadOffsetX = 0.5, quadOffsetY = 0.5;
 
  118   switch ( quadrantPosition )
 
  156   return QPointF( quadOffsetX, quadOffsetY );
 
  162 void appendSimpleFunction( QDomDocument &doc, QDomElement &parent, 
const QString &name, 
const QString &attribute )
 
  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 );
 
  174   std::unique_ptr<QgsMarkerSymbolLayer> layer;
 
  175   switch ( settings.
type() )
 
  203       switch ( settings.
type() )
 
  221       layer.reset( marker );
 
  224   layer->setEnabled( 
true );
 
  226   QSizeF size = settings.
size();
 
  227   layer->setSize( std::max( 1., std::max( size.width(), size.height() ) ) );
 
  228   layer->setSizeUnit( settings.
sizeUnit() );
 
  234     int alpha = std::round( settings.
opacity() * 255 );
 
  235     fillColor.setAlpha( alpha );
 
  236     strokeColor.setAlpha( alpha );
 
  238   layer->setFillColor( fillColor );
 
  239   layer->setStrokeColor( strokeColor );
 
  243     layer->setAngle( settings.
rotation() );
 
  246   layer->setOffset( settings.
offset() );
 
  247   layer->setOffsetUnit( settings.
offsetUnit() );
 
  254   QDomDocument doc = parent.ownerDocument();
 
  257   QDomElement textSymbolizerElement = doc.createElement( QStringLiteral( 
"se:TextSymbolizer" ) );
 
  258   parent.appendChild( textSymbolizerElement );
 
  262   QFont font = format.
font();
 
  263   QDomElement labelElement = doc.createElement( QStringLiteral( 
"se:Label" ) );
 
  264   textSymbolizerElement.appendChild( labelElement );
 
  267     labelElement.appendChild( doc.createComment( QStringLiteral( 
"SE Export for %1 not implemented yet" ).arg( 
settings.
getLabelExpression()->
dump() ) ) );
 
  268     labelElement.appendChild( doc.createTextNode( 
"Placeholder" ) );
 
  289       QDomElement propertyNameElement = doc.createElement( QStringLiteral( 
"ogc:PropertyName" ) );
 
  291       labelElement.appendChild( propertyNameElement );
 
  296   QDomElement fontElement = doc.createElement( QStringLiteral( 
"se:Font" ) );
 
  297   textSymbolizerElement.appendChild( fontElement );
 
  301   if ( format.
font().italic() )
 
  305   if ( format.
font().bold() )
 
  311   QDomElement labelPlacement = doc.createElement( QStringLiteral( 
"se:LabelPlacement" ) );
 
  312   textSymbolizerElement.appendChild( labelPlacement );
 
  313   double maxDisplacement = 0;
 
  314   double repeatDistance = 0;
 
  319       QDomElement pointPlacement = doc.createElement( 
"se:PointPlacement" );
 
  320       labelPlacement.appendChild( pointPlacement );
 
  335         QDomElement rotation = doc.createElement( 
"se:Rotation" );
 
  336         pointPlacement.appendChild( rotation );
 
  344       QDomElement pointPlacement = doc.createElement( 
"se:PointPlacement" );
 
  345       labelPlacement.appendChild( pointPlacement );
 
  352       double offset = std::sqrt( radius * radius / 2 ); 
 
  353       maxDisplacement = radius + 1; 
 
  362       QDomElement pointPlacement = doc.createElement( 
"se:PointPlacement" );
 
  363       labelPlacement.appendChild( pointPlacement );
 
  374       QDomElement linePlacement = doc.createElement( 
"se:LinePlacement" );
 
  375       labelPlacement.appendChild( linePlacement );
 
  382         QDomElement perpendicular = doc.createElement( 
"se:PerpendicularOffset" );
 
  383         linePlacement.appendChild( perpendicular );
 
  390         QDomElement repeat = doc.createElement( 
"se:Repeat" );
 
  391         linePlacement.appendChild( repeat );
 
  392         repeat.appendChild( doc.createTextNode( QStringLiteral( 
"true" ) ) );
 
  393         QDomElement gap = doc.createElement( 
"se:Gap" );
 
  394         linePlacement.appendChild( gap );
 
  400       QDomElement generalize = doc.createElement( 
"se:GeneralizeLine" );
 
  401       linePlacement.appendChild( generalize );
 
  402       generalize.appendChild( doc.createTextNode( QStringLiteral( 
"true" ) ) );
 
  411     QDomElement haloElement = doc.createElement( QStringLiteral( 
"se:Halo" ) );
 
  412     textSymbolizerElement.appendChild( haloElement );
 
  414     QDomElement radiusElement = doc.createElement( QStringLiteral( 
"se:Radius" ) );
 
  415     haloElement.appendChild( radiusElement );
 
  420     QDomElement fillElement = doc.createElement( QStringLiteral( 
"se:Fill" ) );
 
  421     haloElement.appendChild( fillElement );
 
  430   QDomElement fillElement = doc.createElement( QStringLiteral( 
"se:Fill" ) );
 
  431   textSymbolizerElement.appendChild( fillElement );
 
  443     layer->writeSldMarker( doc, textSymbolizerElement, props );
 
  450     QDomElement priorityElement = doc.createElement( QStringLiteral( 
"se:Priority" ) );
 
  451     textSymbolizerElement.appendChild( priorityElement );
 
  458     priorityElement.appendChild( doc.createTextNode( QString::number( priority ) ) );
 
  462   if ( font.underline() )
 
  465     textSymbolizerElement.appendChild( vo );
 
  467   if ( font.strikeOut() )
 
  470     textSymbolizerElement.appendChild( vo );
 
  473   if ( maxDisplacement > 0 )
 
  476     textSymbolizerElement.appendChild( vo );
 
  481     textSymbolizerElement.appendChild( vo );
 
  487       textSymbolizerElement.appendChild( vo );
 
  490   if ( repeatDistance > 0 )
 
  493     textSymbolizerElement.appendChild( vo );
 
  499     textSymbolizerElement.appendChild( vo );
 
  504     textSymbolizerElement.appendChild( vo );
 
  509     textSymbolizerElement.appendChild( vo );
 
  513       textSymbolizerElement.appendChild( vo );
 
  527           resizeType = QStringLiteral( 
"stretch" );
 
  531           resizeType = QStringLiteral( 
"proportional" );
 
  534         textSymbolizerElement.appendChild( voResize );
 
  537         QSizeF size = background.
size();
 
  538         if ( size.width() > 0 || size.height() > 0 )
 
  551           textSymbolizerElement.appendChild( voMargin );
 
  567   if ( mSettings->drawLabels )
 
  569     QDomDocument doc = parent.ownerDocument();
 
  571     QDomElement ruleElement = doc.createElement( QStringLiteral( 
"se:Rule" ) );
 
  572     parent.appendChild( ruleElement );
 
  575     if ( mSettings->scaleVisibility )
 
  580       scaleProps.insert( 
"scaleMinDenom", 
qgsDoubleToString( mSettings->maximumScale ) );
 
  581       scaleProps.insert( 
"scaleMaxDenom", 
qgsDoubleToString( mSettings->minimumScale ) );
 
  593   Q_UNUSED( providerId )
 
  
void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Read settings from a DOM element.
QgsUnitTypes::RenderUnit distUnits
Units the distance from feature to the label.
QPointF quadOffsetToSldAnchor(QgsPalLayerSettings::QuadrantPosition quadrantPosition)
@ PerimeterCurved
Arranges candidates following the curvature of a polygon's boundary. Applies to polygon layers only.
bool accept(QgsStyleEntityVisitorInterface *visitor) const override
Accepts the specified symbology visitor, causing it to visit all symbols associated with the labeling...
double angleOffset
Label rotation, in degrees clockwise.
RenderUnit
Rendering size units.
@ AroundPoint
Arranges candidates in a circle around a point (or centroid of a polygon). Applies to point or polygo...
The class is used as a container of context for various read/write operations on other objects.
bool enabled() const
Returns whether the background is enabled.
QDomElement save(QDomDocument &doc, const QgsReadWriteContext &context) const override
Returns labeling configuration as XML element.
double maxCurvedCharAngleOut
Maximum angle between outside curved label characters (valid range -20.0 to -95.0)
double zIndex
Z-Index of label, where labels with a higher z-index are rendered on top of labels with a lower z-ind...
bool labelPerPart
true if every part of a multi-part feature should be labeled.
QString dump() const
Returns an expression string, constructed from the internal abstract syntax tree.
QgsTextBufferSettings & buffer()
Returns a reference to the text buffer settings.
QgsExpression * getLabelExpression()
Returns the QgsExpression for this label settings.
UpsideDownLabels upsidedownLabels
Controls whether upside down labels are displayed and how they are handled.
QgsTextBackgroundSettings & background()
Returns a reference to the text background settings.
double yOffset
Vertical offset of label.
QgsUnitTypes::RenderUnit sizeUnit() const
Returns the units for the size of rendered text.
QColor fillColor() const
Returns the color used for filing the background shape.
Container for settings relating to a text background object.
double opacity() const
Returns the buffer opacity.
An interface for classes which can visit style entity (e.g.
QPointF offset() const
Returns the offset used for drawing the background shape.
Abstract base class for marker symbol layers.
static void createAnchorPointElement(QDomDocument &doc, QDomElement &element, QPointF anchor)
Creates a SE 1.1 anchor point element as a child of the specified element.
double opacity() const
Returns the background shape's opacity.
void setSettings(QgsPalLayerSettings *settings, const QString &providerId=QString()) override
Set pal settings (takes ownership).
QgsUnitTypes::RenderUnit strokeWidthUnit() const
Returns the units used for the shape's stroke width.
Capitalization
Capitalization options.
@ Line
Arranges candidates parallel to a generalised line representing the feature or parallel to a polygon'...
QgsSymbolLayer * symbolLayer(int layer)
Returns the symbol layer at the specified index.
virtual QString type() const =0
Unique type string of the labeling configuration implementation.
SizeType sizeType() const
Returns the method used to determine the size of the background shape (e.g., fixed size or buffer aro...
The QgsVectorLayerLabelProvider class implements a label provider for vector layers.
double dist
Distance from feature to the label.
@ OverPoint
Arranges candidates over a point (or centroid of a polygon), or at a preset offset from the point....
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
void setStrokeWidthUnit(QgsUnitTypes::RenderUnit u)
Sets the unit for the width of the marker's stroke.
@ ShapeSquare
Square - buffered sizes only.
void setStrokeWidthUnit(QgsUnitTypes::RenderUnit unit)
Sets the units for the stroke width.
QColor color() const
Returns the color that text will be rendered in.
static void createDisplacementElement(QDomDocument &doc, QDomElement &element, QPointF offset)
double repeatDistance
Distance for repeating labels for a single feature.
QgsUnitTypes::RenderUnit repeatDistanceUnit
Units for repeating labels for a single feature.
double xOffset
Horizontal offset of label.
bool displayAll
If true, all features will be labelled even when overlaps occur.
void setShape(QgsSimpleMarkerSymbolLayerBase::Shape shape)
Sets the rendered marker shape.
virtual QgsSymbolLayer * clone() const =0
Shall be reimplemented by subclasses to create a deep copy of the instance.
@ OrderedPositionsAroundPoint
Candidates are placed in predefined positions around a point. Preference is given to positions with g...
RotationType rotationType() const
Returns the method used for rotating the background shape.
Container for all settings relating to text rendering.
QSizeF size() const
Returns the size of the background shape.
static QgsAbstractVectorLayerLabeling * create(const QDomElement &element, const QgsReadWriteContext &context)
Try to create instance of an implementation based on the XML data.
@ Curved
Arranges candidates following the curvature of a line feature. Applies to line layers only.
@ ShapeRectangle
Rectangle.
bool mergeLines() const
Returns true if connected line features with identical label text should be merged prior to generatin...
Shape
Marker symbol shapes.
@ MixedCase
Mixed case, ie no change.
QgsVectorLayerSimpleLabeling(const QgsPalLayerSettings &settings)
Constructs simple labeling configuration with given initial settings.
void setStrokeWidth(double w)
const QgsTextFormat & format() const
Returns the label text formatting settings, e.g., font settings, buffer settings, etc.
double strokeWidth() const
Returns the width of the shape's stroke (stroke).
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,...
Simple marker symbol layer, consisting of a rendered shape with solid fill color and an stroke.
@ AllLowercase
Convert all characters to lowercase.
@ SizeBuffer
Shape size is determined by adding a buffer margin around text.
double rotation() const
Returns the rotation for the background shape, in degrees clockwise.
const QgsLabelLineSettings & lineSettings() const
Returns the label line settings, which contain settings related to how the label engine places and fo...
double opacity() const
Returns the text's opacity.
static QDomElement createVendorOptionElement(QDomDocument &doc, const QString &name, const QString &value)
QgsPalLayerSettings settings(const QString &providerId=QString()) const override
Gets associated label settings.
QgsStringUtils::Capitalization capitalization() const
Returns the text capitalization style.
static QgsVectorLayerSimpleLabeling * create(const QDomElement &element, const QgsReadWriteContext &context)
Create the instance from a DOM element with saved configuration.
Container for settings relating to a text buffer.
void setStrokeWidth(double w)
Sets the width of the marker's stroke.
QgsUnitTypes::RenderUnit sizeUnit() const
Returns the units for the buffer size.
ShapeType type() const
Returns the type of background shape (e.g., square, ellipse, SVG).
QString svgFile() const
Returns the absolute path to the background SVG file, if set.
A label settings entity for QgsStyle databases.
Abstract base class - its implementations define different approaches to the labeling of a vector lay...
@ Horizontal
Arranges horizontal candidates scattered throughout a polygon feature. Applies to polygon layers only...
double size() const
Returns the size of the buffer.
static void applyScaleDependency(QDomDocument &doc, QDomElement &ruleElem, QgsStringMap &props)
Checks if the properties contain scaleMinDenom and scaleMaxDenom, if available, they are added into t...
double size() const
Returns the size for rendered text.
static QDomElement createSvgParameterElement(QDomDocument &doc, const QString &name, const QString &value)
void appendSimpleFunction(QDomDocument &doc, QDomElement &parent, const QString &name, const QString &attribute)
std::unique_ptr< QgsMarkerSymbolLayer > backgroundToMarkerLayer(const QgsTextBackgroundSettings &settings)
int priority
Label priority.
bool enabled() const
Returns whether the buffer is enabled.
QMap< QString, QString > QgsStringMap
QString fieldName
Name of field (or an expression) to use for label text.
Basic implementation of the labeling interface.
@ ForceFirstLetterToCapital
Convert just the first letter of each word to uppercase, leave the rest untouched.
Represents a vector layer which manages a vector based data sets.
@ OutsidePolygons
Candidates are placed outside of polygon boundaries. Applies to polygon layers only....
QString type() const override
Unique type string of the labeling configuration implementation.
QuadrantPosition quadOffset
Sets the quadrant in which to offset labels from feature.
bool requiresAdvancedEffects() const override
Returns true if drawing labels requires advanced effects like composition modes, which could prevent ...
double maxCurvedCharAngleIn
Maximum angle between inside curved label characters (valid range 20.0 to 60.0).
bool isExpression
true if this label is made from a expression string, e.g., FieldName || 'mm'
@ SizePercent
Shape size is determined by percent of text size.
QFont font() const
Returns the font used for rendering text.
QgsVectorLayerLabelProvider * provider(QgsVectorLayer *layer) const override
void toSld(QDomNode &parent, const QgsStringMap &props) const override
Writes the SE 1.1 TextSymbolizer element based on the current layer labeling settings.
QgsUnitTypes::RenderUnit offsetUnits
Units for offsets of label.
virtual bool visit(const QgsStyleEntityVisitorInterface::StyleLeaf &entity)
Called when the visitor will visit a style entity.
QgsUnitTypes::RenderUnit sizeUnit() const
Returns the units used for the shape's size.
virtual void writeTextSymbolizer(QDomNode &parent, QgsPalLayerSettings &settings, const QgsStringMap &props) const
Writes a TextSymbolizer element contents based on the provided labeling settings.
@ ShapeMarkerSymbol
Marker symbol.
QColor color() const
Returns the color of the buffer.
@ RotationFixed
Shape rotation is a fixed angle.
QgsMarkerSymbol * markerSymbol() const
Returns the marker symbol to be rendered in the background.
virtual bool accept(QgsStyleEntityVisitorInterface *visitor) const
Accepts the specified symbology visitor, causing it to visit all symbols associated with the labeling...
@ Free
Arranges candidates scattered throughout a polygon feature. Candidates are rotated to respect the pol...
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)
QgsAbstractVectorLayerLabeling * clone() const override
Returns a new copy of the object.
static QgsRuleBasedLabeling * create(const QDomElement &element, const QgsReadWriteContext &context)
Create the instance from a DOM element with saved configuration.
QColor strokeColor() const
Returns the color used for outlining the background shape.
@ AllUppercase
Convert all characters to uppercase.
virtual QgsPalLayerSettings settings(const QString &providerId=QString()) const =0
Gets associated label settings.
QgsUnitTypes::RenderUnit offsetUnit() const
Returns the units used for the shape's offset.
@ ShowAll
Show upside down for all labels, including dynamic ones.
int symbolLayerCount() const
Returns the total number of symbol layers contained in the symbol.