40 , mLayerGeometryType( layer->geometryType() )
41 , mRenderer( layer->renderer() )
42 , mFields( layer->fields() )
43 , mCrs( layer->crs() )
45 mName = layerName.isEmpty() ? layer->
id() : layerName;
47 if ( withFeatureLoop )
119 if ( exp.hasEvalError() )
145 if ( exp->hasEvalError() )
149 Q_FOREACH (
const QString &
name, exp->referencedColumns() )
152 attributeNames.insert( name );
210 QSet<QString> attrNames;
211 if ( !
prepare( ctx, attrNames ) )
212 return QList<QgsLabelFeature *>();
240 if ( !symbols.isEmpty() )
297 if ( bounds.isValid() )
298 bounds = bounds.united( static_cast< QgsMarkerSymbol * >( symbol )->bounds( pt, context, fet ) );
300 bounds =
static_cast< QgsMarkerSymbol *
>( symbol )->bounds( pt, context, fet );
305 QVector< double > bX;
306 bX << bounds.left() << bounds.right() << bounds.right() << bounds.left();
307 QVector< double > bY;
308 bY << bounds.top() << bounds.top() << bounds.bottom() << bounds.bottom();
313 for (
int i = 0; i < boundLineString->
numPoints(); ++i )
316 boundLineString->
setXAt( i, point.
x() );
317 boundLineString->
setYAt( i, point.
y() );
323 boundLineString->
close();
330 static_cast<QgsMultiPolygon *
>( obstacleGeom )->addGeometry( obstaclePolygon );
334 obstacleGeom = obstaclePolygon;
354 const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues = lf->
dataDefinedValues();
359 QgsDebugMsgLevel( QString(
"PAL font definedFont: %1, Style: %2" ).arg( dFont.toString(), dFont.styleName() ), 4 );
366 format.
setSize( dFont.pixelSize() );
375 case LabelPosition::QuadrantAboveLeft:
376 case LabelPosition::QuadrantLeft:
377 case LabelPosition::QuadrantBelowLeft:
380 case LabelPosition::QuadrantAbove:
381 case LabelPosition::QuadrantOver:
382 case LabelPosition::QuadrantBelow:
385 case LabelPosition::QuadrantAboveRight:
386 case LabelPosition::QuadrantRight:
387 case LabelPosition::QuadrantBelowRight:
394 QgsPalLabeling::dataDefinedTextStyle( tmpLyr, ddValues );
397 QgsPalLabeling::dataDefinedTextBuffer( tmpLyr, ddValues );
400 QgsPalLabeling::dataDefinedTextFormatting( tmpLyr, ddValues );
403 QgsPalLabeling::dataDefinedShapeBackground( tmpLyr, ddValues );
406 QgsPalLabeling::dataDefinedDropShadow( tmpLyr, ddValues );
452 QPainter *painter = context.
painter();
470 QRectF rect( 0, 0, outPt2.
x() - outPt.x(), outPt2.
y() - outPt.y() );
472 painter->setRenderHint( QPainter::Antialiasing,
false );
473 painter->translate( QPointF( outPt.x(), outPt.y() ) );
474 painter->rotate( -label->
getAlpha() * 180 / M_PI );
478 painter->setBrush( QColor( 255, 0, 0, 100 ) );
479 painter->setPen( QColor( 255, 0, 0, 150 ) );
483 painter->setBrush( QColor( 0, 255, 0, 100 ) );
484 painter->setPen( QColor( 0, 255, 0, 150 ) );
487 painter->drawRect( rect );
496 QgsTextRenderer::Component component;
497 component.dpiRatio = dpiRatio;
498 component.origin = outPt;
499 component.rotation = label->
getAlpha();
506 QPointF centerPt( outPt );
510 double xc = outPt2.
x() - outPt.x();
511 double yc = outPt2.
y() - outPt.y();
513 double angle = -component.rotation;
514 double xd = xc * std::cos( angle ) - yc * std::sin( angle );
515 double yd = xc * std::sin( angle ) + yc * std::cos( angle );
517 centerPt.setX( centerPt.x() + xd );
518 centerPt.setY( centerPt.y() + yd );
520 component.center = centerPt;
526 component.size = QSizeF( labelWidthPx, labelHeightPx );
528 QgsTextRenderer::drawBackground( context, component, tmpLyr.
format(), QStringList(), QgsTextRenderer::Label );
544 bool prependSymb =
false;
570 symb = symb + QStringLiteral(
"\n" );
575 symb = QStringLiteral(
"\n" ) + symb;
597 QgsTextRenderer::Component component;
598 component.origin = outPt;
599 component.rotation = label->
getAlpha();
600 QgsTextRenderer::drawTextInternal( drawType, context, tmpLyr.
format(), component, multiLineList, labelfm,
int lookupField(const QString &fieldName) const
Look up field's index from the field name.
QList< QgsLabelFeature * > mLabels
List of generated.
static QgsExpressionContextScope * updateSymbolScope(const QgsSymbol *symbol, QgsExpressionContextScope *symbolScope=nullptr)
Updates a symbol scope related to a QgsSymbol to an expression context.
Wrapper for iterator of features from vector data provider or vector layer.
virtual QgsSymbolList originalSymbolsForFeature(QgsFeature &feat, QgsRenderContext &context)
Equivalent of originalSymbolsForFeature() call extended to support renderers that may use more symbol...
QgsVectorLayerLabelProvider(QgsVectorLayer *layer, const QString &providerId, bool withFeatureLoop, const QgsPalLayerSettings *settings, const QString &layerName=QString())
Convenience constructor to initialize the provider from given vector layer.
QString labelText() const
Text of the label.
A rectangle specified with double values.
QString leftDirectionSymbol
String to use for left direction arrows.
QgsWkbTypes::GeometryType mLayerGeometryType
Geometry type of layer.
void setMapRotation(double degrees, double cx, double cy)
Set map rotation in degrees (clockwise)
QgsTextShadowSettings::ShadowPlacement shadowPlacement() const
Returns the placement for the drop shadow.
QgsPalLayerSettings::Placement mPlacement
Placement strategy.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context, which stores various information regarding which datum tran...
QgsFeatureId featureId() const
Returns the unique ID of the feature.
QgsLabelFeature * feature()
Returns the parent feature.
double rotation() const
Returns the rotation of the resulting map image, in degrees clockwise.
void registerFeature(QgsFeature &f, QgsRenderContext &context, QgsLabelFeature **labelFeature=nullptr, QgsGeometry obstacleGeometry=QgsGeometry())
Register a feature for labeling.
const QgsLabelingEngine * mEngine
Associated labeling engine.
Draw shadow under buffer.
UpsideDownLabels upsidedownLabels
Controls whether upside down labels are displayed and how they are handled.
Place direction symbols on below label.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
double mPriority
Default priority of labels.
bool mOwnsSource
Whether layer's feature source is owned.
QgsTextShadowSettings & shadow()
Returns a reference to the text drop shadow settings.
double getY(int i=0) const
get the down-left y coordinate
A class to represent a 2D point.
OperationResult rotate(double rotation, const QgsPointXY ¢er)
Rotate this geometry around the Z axis.
HAlignment
Horizontal alignment.
void setFont(const QFont &font)
Sets the font used for rendering text.
const QMap< QgsPalLayerSettings::DataDefinedProperties, QVariant > & dataDefinedValues() const
Get data-defined values.
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
virtual QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest())=0
Get an iterator for features matching the specified request.
Class that adds extra information to QgsLabelFeature for text labels.
bool addDirectionSymbol
If true, '<' or '>' (or custom strings set via leftDirectionSymbol and rightDirectionSymbol) will be ...
A geometry is the spatial representation of a feature.
Whether to only draw the label rect and not the actual label text (used for unit tests) ...
bool drawLabels
Whether to draw labels for this layer.
bool insertLabel(pal::LabelPosition *labelPos, int featureId, const QString &layerName, const QString &labeltext, const QFont &labelfont, bool diagram=false, bool pinned=false, const QString &providerId=QString())
Inserts label position.
bool mergeLines
True if connected line features with identical label text should be merged prior to generating label ...
void setYAt(int index, double y)
Sets the y-coordinate of the specified node in the line string.
MultiLineAlign multilineAlign
Horizontal alignment of multi-line labels.
Whether to label each part of multi-part features separately.
FeaturePart * getFeaturePart()
return the feature corresponding to this labelposition
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
bool hasGeometry() const
Returns true if the feature has an associated geometry.
static QStringList splitToLines(const QString &text, const QString &wrapCharacter)
Splits a text string to a list of separate lines, using a specified wrap character.
QgsCoordinateTransform ct
QgsRectangle visibleExtent() const
Return the actual extent derived from requested extent that takes takes output image size into accoun...
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
Compare two doubles (but allow some difference)
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)
bool reverseDirectionSymbol
True if direction symbols should be reversed.
void setXAt(int index, double x)
Sets the x-coordinate of the specified node in the line string.
void transform(const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection d=QgsCoordinateTransform::ForwardTransform, bool transformZ=false) override
Transforms the geometry using a coordinate transform.
void setFormat(const QgsTextFormat &format)
Sets the label text formatting settings, e.g., font settings, buffer settings, etc.
QgsCoordinateReferenceSystem destinationCrs() const
returns CRS of destination coordinate reference system
Whether to render labels as text or outlines.
int numPoints() const override
Returns the number of points in the curve.
Whether adjacent lines (with the same label text) should be merged.
The QgsMapSettings class contains configuration for rendering of the map.
QList< QgsLabelFeature * > labelFeatures(QgsRenderContext &context) override
Return list of label features (they are owned by the provider and thus deleted on its destruction) ...
void transformInPlace(double &x, double &y) const
Transform device coordinates to map coordinates.
void init()
initialization method - called from constructors
Perform transforms between map coordinates and device coordinates.
QgsPointXY transform(const QgsPointXY &p) const
Transform the point from map (world) coordinates to device coordinates.
static QgsGeometry fromRect(const QgsRectangle &rect)
Creates a new geometry from a QgsRectangle.
bool prepare(const QgsExpressionContext &context=QgsExpressionContext()) const override
Prepares the collection against a specified expression context.
QgsExpressionContextScope * lastScope()
Returns the last scope added to the context.
ObstacleType obstacleType
Controls how features act as obstacles for labels.
QList< QgsSymbol * > QgsSymbolList
bool displayAll
If true, all features will be labelled even when overlaps occur.
void setSize(double size)
Sets the size for rendered text.
QString id() const
Returns the layer's unique ID, which is used to access this layer from QgsProject.
const QgsLabelingEngineSettings & engineSettings() const
Get associated labeling engine settings.
virtual bool prepare(const QgsRenderContext &context, QSet< QString > &attributeNames)
Prepare for registration of features.
Utility class for identifying a unique vertex within a geometry.
#define QgsDebugMsgLevel(str, level)
const QgsRectangle & extent() const
unsigned int mLinePlacementFlags
Extra placement flags for linestring geometries.
QgsPalLayerSettings mSettings
Layer's labeling configuration.
double yAt(int index) const override
Returns the y-coordinate of the specified node in the line string.
LabelPosition * getNextPart() const
const QgsMapToPixel * xform
This class wraps a request for features to a vector layer (or directly its vector data provider)...
Flags mFlags
Flags altering drawing and registration of features.
Whether location of centroid must be inside of polygons.
Quadrant getQuadrant() const
QgsFeatureRequest & setFilterRect(const QgsRectangle &rectangle)
Sets the rectangle from which features will be taken.
QgsTextBackgroundSettings & background()
Returns a reference to the text background settings.
QgsTextBufferSettings & buffer()
Returns a reference to the text buffer settings.
void setSizeUnit(QgsUnitTypes::RenderUnit unit)
Sets the units for the size of rendered text.
void close()
Closes the line string by appending the first point to the end of the line, if it is not already clos...
QgsCoordinateTransform coordinateTransform() const
Returns the current coordinate transform for the context, or an invalid transform is no coordinate tr...
QString text(int partId) const
Returns the text component corresponding to a specified label part.
Whether all features will be labelled even though overlaps occur.
virtual void registerFeature(QgsFeature &feature, QgsRenderContext &context, const QgsGeometry &obstacleGeometry=QgsGeometry())
Register a feature for labeling as one or more QgsLabelFeature objects stored into mLabels...
Single scope for storing variables and functions for use within a QgsExpressionContext.
Abstract base class for all geometries.
QgsGeometry geometry() const
Returns the geometry associated with this feature.
Point geometry type, with support for z-dimension and m-values.
const QgsMapToPixel & mapToPixel() const
QgsWkbTypes::GeometryType type() const
Returns type of the geometry as a QgsWkbTypes::GeometryType.
The QgsAbstractLabelProvider class is an interface class.
const QgsTextFormat & format() const
Returns the label text formatting settings, e.g., font settings, buffer settings, etc...
Partial snapshot of vector layer's state (only the members necessary for access to features) ...
Place direction symbols on above label.
Draw shadow below all text components.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
QgsExpressionContext & expressionContext()
Gets the expression context.
unsigned int placementFlags
QString wrapChar
Wrapping character string.
TextPart
Components of text.
QSet< QString > referencedFields(const QgsExpressionContext &context=QgsExpressionContext()) const override
Returns the set of any fields referenced by the active properties from the collection.
QgsFields mFields
Layer's fields.
QgsAbstractFeatureSource * mSource
Layer's feature source.
QString rightDirectionSymbol
String to use for right direction arrows.
QgsExpression * getLabelExpression()
Returns the QgsExpression for this label settings.
Arranges candidates over a point (or centroid of a polygon), or at a preset offset from the point...
Contains information about the context of a rendering operation.
double convertToPainterUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
Converts a size from the specified units to painter units (pixels).
QFont definedFont()
Font to be used for rendering.
bool hasFixedPosition() const
Whether the label should use a fixed position instead of being automatically placed.
void setExteriorRing(QgsCurve *ring) override
Sets the exterior ring of the polygon.
QPainter * painter()
Returns the destination QPainter for the render operation.
The QgsLabelFeature class describes a feature that should be used within the labeling engine...
const QgsMapToPixel & mapToPixel() const
QString name() const
Name of the layer (for statistics, debugging etc.) - does not need to be unique.
double getAlpha() const
get alpha
Multi polygon geometry collection.
QString mName
Name of the layer.
bool enabled() const
Returns whether the shadow is enabled.
Struct for storing maximum and minimum scales for measurements in map units.
QgsCoordinateReferenceSystem mCrs
Layer's CRS.
bool conflictsWithObstacle() const
Returns whether the position is marked as conflicting with an obstacle feature.
double getX(int i=0) const
get the down-left x coordinate
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)
Must be called when a new render cycle is started.
Line string geometry type, with support for z-dimension and m-values.
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
~QgsVectorLayerLabelProvider() override
const QgsMapSettings & mapSettings() const
Get associated map settings.
bool enabled() const
Returns whether the background is enabled.
bool testFlag(Flag f) const
Test whether a particular flag is enabled.
QgsLabelingResults * results() const
For internal use by the providers.
virtual void stopRender(QgsRenderContext &context)
Must be called when a render cycle has finished, to allow the renderer to clean up.
QString mProviderId
Associated provider ID (one layer may have multiple providers, e.g. in rule-based labeling) ...
LabelPosition is a candidate feature label position.
QgsPalLayerSettings::ObstacleType mObstacleType
Type of the obstacle of feature geometries.
bool enabled() const
Returns whether the buffer is enabled.
double xAt(int index) const override
Returns the x-coordinate of the specified node in the line string.
QgsPalLayerSettings::UpsideDownLabels mUpsidedownLabels
How to handle labels that would be upside down.
void setShadowPlacement(QgsTextShadowSettings::ShadowPlacement placement)
Sets the placement for the drop shadow.
Draw shadow under background shape.
Whether the labels should be rendered.
bool isExpression
True if this label is made from a expression string, e.g., FieldName || 'mm'.
QgsPointXY center() const
Returns the center point of the rectangle.
QgsExpressionContextScope * popScope()
Removes the last scope from the expression context and return it.
bool nextFeature(QgsFeature &f)
Container for all settings relating to text rendering.
QFontMetricsF * labelFontMetrics()
Metrics of the font for rendering.
bool centroidInside
True if centroid positioned labels must be placed inside their corresponding feature polygon...
virtual QgsPoint vertexAt(QgsVertexId id) const =0
Returns the point corresponding to a specified vertex id.
virtual int nCoordinates() const
Returns the number of nodes contained in the geometry.
Represents a vector layer which manages a vector based data sets.
QString mLayerId
Associated layer's ID, if applicable.
QFont font() const
Returns the font used for rendering text.
int priority
Label priority.
QgsFeatureRenderer * mRenderer
QgsPointXY toMapCoordinates(int x, int y) const
bool labelPerPart
True if every part of a multi-part feature should be labeled.
void drawLabel(QgsRenderContext &context, pal::LabelPosition *label) const override
draw this label at the position determined by the labeling engine
void drawLabelPrivate(pal::LabelPosition *label, QgsRenderContext &context, QgsPalLayerSettings &tmpLyr, QgsTextRenderer::TextPart drawType, double dpiRatio=1.0) const
Internal label drawing method.
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the label's property collection, used for data defined overrides.
static QgsGeometry getPointObstacleGeometry(QgsFeature &fet, QgsRenderContext &context, const QgsSymbolList &symbols)
Returns the geometry for a point feature which should be used as an obstacle for labels.
QString fieldName
Name of field (or an expression) to use for label text.
DirectionSymbols placeDirectionSymbol
Placement option for direction symbols.