QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
29 const QString
type = element.attribute( QStringLiteral(
"type" ) );
30 if (
type == QLatin1String(
"rule-based" ) )
34 else if (
type == QLatin1String(
"simple" ) )
88 return QStringLiteral(
"simple" );
98 QDomElement elem = doc.createElement( QStringLiteral(
"labeling" ) );
99 elem.setAttribute( QStringLiteral(
"type" ), QStringLiteral(
"simple" ) );
100 elem.appendChild( mSettings->writeXml( doc, context ) );
106 Q_UNUSED( providerId )
115 if ( !visitor->
visit( &entity ) )
123 return mSettings->containsAdvancedEffects();
128 const QDomElement settingsElem = element.firstChildElement( QStringLiteral(
"settings" ) );
129 if ( !settingsElem.isNull() )
141 double quadOffsetX = 0.5, quadOffsetY = 0.5;
144 switch ( quadrantPosition )
146 case Qgis::LabelQuadrantPosition::AboveLeft:
150 case Qgis::LabelQuadrantPosition::Above:
154 case Qgis::LabelQuadrantPosition::AboveRight:
158 case Qgis::LabelQuadrantPosition::Left:
162 case Qgis::LabelQuadrantPosition::Right:
166 case Qgis::LabelQuadrantPosition::BelowLeft:
170 case Qgis::LabelQuadrantPosition::Below:
174 case Qgis::LabelQuadrantPosition::BelowRight:
178 case Qgis::LabelQuadrantPosition::Over:
182 return QPointF( quadOffsetX, quadOffsetY );
188 void appendSimpleFunction( QDomDocument &doc, QDomElement &parent,
const QString &name,
const QString &attribute )
190 QDomElement
function = doc.createElement( QStringLiteral(
"ogc:Function" ) );
191 function.setAttribute( QStringLiteral(
"name" ), name );
192 parent.appendChild(
function );
193 QDomElement
property = doc.createElement( QStringLiteral(
"ogc:PropertyName" ) );
194 property.appendChild( doc.createTextNode( attribute ) );
195 function.appendChild( property );
200 std::unique_ptr<QgsMarkerSymbolLayer> layer;
201 switch ( settings.
type() )
229 switch ( settings.
type() )
247 layer.reset( marker );
250 layer->setEnabled(
true );
252 const QSizeF size = settings.
size();
253 layer->setSize( std::max( 1., std::max( size.width(), size.height() ) ) );
254 layer->setSizeUnit( settings.
sizeUnit() );
260 const int alpha = std::round( settings.
opacity() * 255 );
261 fillColor.setAlpha( alpha );
262 strokeColor.setAlpha( alpha );
264 layer->setFillColor( fillColor );
265 layer->setStrokeColor( strokeColor );
269 layer->setAngle( settings.
rotation() );
272 layer->setOffset( settings.
offset() );
273 layer->setOffsetUnit( settings.
offsetUnit() );
280 QDomDocument doc = parent.ownerDocument();
283 QDomElement textSymbolizerElement = doc.createElement( QStringLiteral(
"se:TextSymbolizer" ) );
284 parent.appendChild( textSymbolizerElement );
288 const QFont font = format.
font();
289 QDomElement labelElement = doc.createElement( QStringLiteral(
"se:Label" ) );
290 textSymbolizerElement.appendChild( labelElement );
293 labelElement.appendChild( doc.createComment( QStringLiteral(
"SE Export for %1 not implemented yet" ).arg(
settings.
getLabelExpression()->
dump() ) ) );
294 labelElement.appendChild( doc.createTextNode(
"Placeholder" ) );
315 QDomElement propertyNameElement = doc.createElement( QStringLiteral(
"ogc:PropertyName" ) );
317 labelElement.appendChild( propertyNameElement );
322 QDomElement fontElement = doc.createElement( QStringLiteral(
"se:Font" ) );
323 textSymbolizerElement.appendChild( fontElement );
327 if ( format.
font().italic() )
331 if ( format.
font().bold() )
337 QDomElement labelPlacement = doc.createElement( QStringLiteral(
"se:LabelPlacement" ) );
338 textSymbolizerElement.appendChild( labelPlacement );
339 double maxDisplacement = 0;
340 double repeatDistance = 0;
345 QDomElement pointPlacement = doc.createElement(
"se:PointPlacement" );
346 labelPlacement.appendChild( pointPlacement );
361 QDomElement rotation = doc.createElement(
"se:Rotation" );
362 pointPlacement.appendChild( rotation );
370 QDomElement pointPlacement = doc.createElement(
"se:PointPlacement" );
371 labelPlacement.appendChild( pointPlacement );
378 const double offset = std::sqrt( radius * radius / 2 );
379 maxDisplacement = radius + 1;
388 QDomElement pointPlacement = doc.createElement(
"se:PointPlacement" );
389 labelPlacement.appendChild( pointPlacement );
400 QDomElement linePlacement = doc.createElement(
"se:LinePlacement" );
401 labelPlacement.appendChild( linePlacement );
408 QDomElement perpendicular = doc.createElement(
"se:PerpendicularOffset" );
409 linePlacement.appendChild( perpendicular );
416 QDomElement repeat = doc.createElement(
"se:Repeat" );
417 linePlacement.appendChild( repeat );
418 repeat.appendChild( doc.createTextNode( QStringLiteral(
"true" ) ) );
419 QDomElement gap = doc.createElement(
"se:Gap" );
420 linePlacement.appendChild( gap );
426 QDomElement generalize = doc.createElement(
"se:GeneralizeLine" );
427 linePlacement.appendChild( generalize );
428 generalize.appendChild( doc.createTextNode( QStringLiteral(
"true" ) ) );
437 QDomElement haloElement = doc.createElement( QStringLiteral(
"se:Halo" ) );
438 textSymbolizerElement.appendChild( haloElement );
440 QDomElement radiusElement = doc.createElement( QStringLiteral(
"se:Radius" ) );
441 haloElement.appendChild( radiusElement );
446 QDomElement fillElement = doc.createElement( QStringLiteral(
"se:Fill" ) );
447 haloElement.appendChild( fillElement );
456 QDomElement fillElement = doc.createElement( QStringLiteral(
"se:Fill" ) );
457 textSymbolizerElement.appendChild( fillElement );
469 layer->writeSldMarker( doc, textSymbolizerElement, props );
476 QDomElement priorityElement = doc.createElement( QStringLiteral(
"se:Priority" ) );
477 textSymbolizerElement.appendChild( priorityElement );
484 priorityElement.appendChild( doc.createTextNode( QString::number( priority ) ) );
488 if ( font.underline() )
491 textSymbolizerElement.appendChild( vo );
493 if ( font.strikeOut() )
496 textSymbolizerElement.appendChild( vo );
499 if ( maxDisplacement > 0 )
502 textSymbolizerElement.appendChild( vo );
507 textSymbolizerElement.appendChild( vo );
513 textSymbolizerElement.appendChild( vo );
516 if ( repeatDistance > 0 )
519 textSymbolizerElement.appendChild( vo );
529 textSymbolizerElement.appendChild( vo );
535 textSymbolizerElement.appendChild( vo );
540 textSymbolizerElement.appendChild( vo );
544 textSymbolizerElement.appendChild( vo );
558 resizeType = QStringLiteral(
"stretch" );
562 resizeType = QStringLiteral(
"proportional" );
565 textSymbolizerElement.appendChild( voResize );
568 const QSizeF size = background.
size();
569 if ( size.width() > 0 || size.height() > 0 )
582 textSymbolizerElement.appendChild( voMargin );
598 if ( mSettings->drawLabels )
600 QDomDocument doc = parent.ownerDocument();
602 QDomElement ruleElement = doc.createElement( QStringLiteral(
"se:Rule" ) );
603 parent.appendChild( ruleElement );
606 if ( mSettings->scaleVisibility )
608 QVariantMap scaleProps = QVariantMap();
611 scaleProps.insert(
"scaleMinDenom",
qgsDoubleToString( mSettings->maximumScale ) );
612 scaleProps.insert(
"scaleMaxDenom",
qgsDoubleToString( mSettings->minimumScale ) );
624 Q_UNUSED( providerId )
Qgis::LabelPlacement placement
Label placement mode.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Read settings from a DOM element.
@ Free
Arranges candidates scattered throughout a polygon feature. Candidates are rotated to respect the pol...
QgsUnitTypes::RenderUnit distUnits
Units the distance from feature to the label.
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.
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)
@ OrderedPositionsAroundPoint
Candidates are placed in predefined positions around a point. Preference is given to positions with g...
Qgis::LabelOffsetType offsetType
Offset type for layer (only applies in certain placement modes)
Contains settings for how a map layer will be labeled.
@ AllUppercase
Convert all characters to uppercase.
double zIndex
Z-Index of label, where labels with a higher z-index are rendered on top of labels with a lower z-ind...
@ OutsidePolygons
Candidates are placed outside of polygon boundaries. Applies to polygon layers only....
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.
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,...
QgsExpression * getLabelExpression()
Returns the QgsExpression for this label settings.
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.
static QgsPalLayerSettings defaultSettingsForLayer(const QgsVectorLayer *layer)
Returns the default layer settings to use for the specified vector layer.
virtual void writeTextSymbolizer(QDomNode &parent, QgsPalLayerSettings &settings, const QVariantMap &props) const
Writes a TextSymbolizer element contents based on the provided labeling settings.
double opacity() const
Returns the buffer opacity.
An interface for classes which can visit style entity (e.g. symbol) nodes (using the visitor pattern)...
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.
Qgis::LabelQuadrantPosition quadOffset
Sets the quadrant in which to offset labels from feature.
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.
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.
@ AllowOverlapIfRequired
Avoids overlapping labels when possible, but permit overlaps if labels for features cannot otherwise ...
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.
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.
const QgsLabelPlacementSettings & placementSettings() const
Returns the label placement settings.
void setStrokeWidthUnit(QgsUnitTypes::RenderUnit unit)
Sets the units for the stroke width.
QColor color() const
Returns the color that text will be rendered in.
LabelQuadrantPosition
Label quadrant positions.
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.
virtual QgsSymbolLayer * clone() const =0
Shall be reimplemented by subclasses to create a deep copy of the instance.
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.
@ ShapeRectangle
Rectangle.
bool mergeLines() const
Returns true if connected line features with identical label text should be merged prior to generatin...
@ Horizontal
Arranges horizontal candidates scattered throughout a polygon feature. Applies to polygon layers only...
static void applyScaleDependency(QDomDocument &doc, QDomElement &ruleElem, QVariantMap &props)
Checks if the properties contain scaleMinDenom and scaleMaxDenom, if available, they are added into t...
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).
Simple marker symbol layer, consisting of a rendered shape with solid fill color and an stroke.
void setFormat(const QgsTextFormat &format)
Sets the label text formatting settings, e.g., font settings, buffer settings, etc.
@ AllLowercase
Convert all characters to lowercase.
static double rescaleUom(double size, QgsUnitTypes::RenderUnit unit, const QVariantMap &props)
Rescales the given size based on the uomScale found in the props, if any is found,...
Qgis::Capitalization capitalization() const
Returns the text capitalization style.
@ MixedCase
Mixed case, ie no change.
@ OverPoint
Arranges candidates over a point (or centroid of a polygon), or at a preset offset from the point....
@ 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.
Capitalization
String capitalization options.
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.
void toSld(QDomNode &parent, const QVariantMap &props) const override
Writes the SE 1.1 TextSymbolizer element based on the current layer labeling settings.
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.
@ AllowOverlapAtNoCost
Labels may freely overlap other labels, at no cost.
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...
@ ForceFirstLetterToCapital
Convert just the first letter of each word to uppercase, leave the rest untouched.
double size() const
Returns the size of the buffer.
Qgis::UpsideDownLabelHandling upsidedownLabels
Controls whether upside down labels are displayed and how they are handled.
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.
@ PreventOverlap
Do not allow labels to overlap other labels.
QString fieldName
Name of field (or an expression) to use for label text.
Basic implementation of the labeling interface.
Represents a vector layer which manages a vector based data sets.
QString type() const override
Unique type string of the labeling configuration implementation.
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
QgsUnitTypes::RenderUnit offsetUnits
Units for offsets of label.
virtual bool visit(const QgsStyleEntityVisitorInterface::StyleLeaf &entity)
Called when the visitor will visit a style entity.
@ FromSymbolBounds
Offset distance applies from rendered symbol bounds.
QgsUnitTypes::RenderUnit sizeUnit() const
Returns the units used for the shape's size.
QgsProject * project() const
Returns the parent project if this map layer is added to a project.
@ PerimeterCurved
Arranges candidates following the curvature of a polygon's boundary. Applies to polygon layers only.
MarkerShape
Marker shapes.
@ ShapeMarkerSymbol
Marker symbol.
QColor color() const
Returns the color of the buffer.
@ Line
Arranges candidates parallel to a generalised line representing the feature or parallel to a polygon'...
@ RotationFixed
Shape rotation is a fixed angle.
Qgis::LabelOverlapHandling overlapHandling() const
Returns the technique used to handle overlapping labels.
QgsMarkerSymbol * markerSymbol() const
Returns the marker symbol to be rendered in the background.
QPointF quadOffsetToSldAnchor(Qgis::LabelQuadrantPosition quadrantPosition)
QString displayField() const
This is a shorthand for accessing the displayExpression if it is a simple field.
Q_INVOKABLE QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
virtual bool accept(QgsStyleEntityVisitorInterface *visitor) const
Accepts the specified symbology visitor, causing it to visit all symbols associated with the labeling...
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.
virtual QgsPalLayerSettings settings(const QString &providerId=QString()) const =0
Gets associated label settings.
@ AroundPoint
Arranges candidates in a circle around a point (or centroid of a polygon). Applies to point or polygo...
void setShape(Qgis::MarkerShape shape)
Sets the rendered marker shape.
QgsUnitTypes::RenderUnit offsetUnit() const
Returns the units used for the shape's offset.
int symbolLayerCount() const
Returns the total number of symbol layers contained in the symbol.
@ Curved
Arranges candidates following the curvature of a line feature. Applies to line layers only.