55 , mLayerGeometryType( layer->geometryType() )
56 , mRenderer( layer->rendererV2() )
57 , mFields( layer->fields() )
58 , mCrs( layer->crs() )
62 if ( withFeatureLoop )
180 attributeNames.
append( name );
212 attributeNames.
append( name );
268 if ( !
prepare( ctx, attrNames ) )
355 bounds = bounds.
united( static_cast< QgsMarkerSymbolV2* >( symbol )->bounds( pt, context, fet ) );
357 bounds =
static_cast< QgsMarkerSymbolV2*
>( symbol )->bounds( pt, context, fet );
370 for (
int i = 0; i < boundLineString->
numPoints(); ++i )
373 boundLineString->
setXAt( i, point.
x() );
374 boundLineString->
setYAt( i, point.
y() );
380 boundLineString->
close();
391 obstacleGeom = obstaclePolygon;
424 case LabelPosition::QuadrantAboveLeft:
425 case LabelPosition::QuadrantLeft:
426 case LabelPosition::QuadrantBelowLeft:
429 case LabelPosition::QuadrantAbove:
430 case LabelPosition::QuadrantOver:
431 case LabelPosition::QuadrantBelow:
434 case LabelPosition::QuadrantAboveRight:
435 case LabelPosition::QuadrantRight:
436 case LabelPosition::QuadrantBelowRight:
528 QRectF rect( 0, 0, outPt2.
x() - outPt.
x(), outPt2.
y() - outPt.
y() );
561 double xc = outPt2.
x() - outPt.
x();
562 double yc = outPt2.
y() - outPt.
y();
565 double xd = xc * cos( angle ) - yc * sin( angle );
566 double yd = xc * sin( angle ) + yc * cos( angle );
568 centerPt.
setX( centerPt.
x() + xd );
569 centerPt.
setY( centerPt.
y() + yd );
590 bool prependSymb =
false;
636 int lines = multiLineList.
size();
638 double labelWidest = 0.0;
639 for (
int i = 0; i < lines; ++i )
641 double labelWidth = labelfm->
width( multiLineList.
at( i ) );
642 if ( labelWidth > labelWidest )
644 labelWidest = labelWidth;
652 double ascentOffset = 0.25 * labelfm->
ascent();
654 for (
int i = 0; i < lines; ++i )
657 #if 0 // TODO: generalize some of this 661 double cx = lp->
getX() + w / 2.0;
662 double cy = lp->
getY() + h / 2.0;
665 double sw = w * scale;
666 double sh = h * scale;
667 QRectF rect( -sw / 2, -sh / 2, sw, sh );
672 if ( lp->
getFeaturePart()->getLayer()->getArrangement() != P_POINT &&
673 lp->
getFeaturePart()->getLayer()->getArrangement() != P_POINT_OVER &&
676 painter->
rotate( rotation );
691 double xMultiLineOffset = 0.0;
692 double labelWidth = labelfm->
width( multiLineList.
at( i ) );
695 double labelWidthDiff = labelWidest - labelWidth;
700 xMultiLineOffset = labelWidthDiff;
704 double yMultiLineOffset = ( lines - 1 - i ) * labelHeight * tmpLyr.
multilineHeight;
705 painter->
translate(
QPointF( xMultiLineOffset, - ascentOffset - yMultiLineOffset ) );
707 component.
setText( multiLineList.
at( i ) );
728 textp.
begin( &textPict );
729 textp.
setPen( Qt::NoPen );
Class for parsing and evaluation of expressions (formerly called "search strings").
void setExpressionParams(const QMap< QString, QVariant > ¶ms)
Wrapper for iterator of features from vector data provider or vector layer.
QString labelText() const
Text of the label.
double xAt(int index) const
Returns the x-coordinate of the specified node in the line string.
QgsFeatureRendererV2 * mRenderer
void close()
Closes the line string by appending the first point to the end of the line, if it is not already clos...
A rectangle specified with double values.
double rendererScale() const
QgsPoint center() const
Center point of the rectangle.
QString & append(QChar ch)
QString leftDirectionSymbol
static void dataDefinedShapeBackground(QgsPalLayerSettings &tmpLyr, const QMap< QgsPalLayerSettings::DataDefinedProperties, QVariant > &ddValues)
void setMapRotation(double degrees, double cx, double cy)
Set map rotation in degrees (clockwise)
QgsPalLayerSettings::Placement mPlacement
Placement strategy.
static void dataDefinedTextStyle(QgsPalLayerSettings &tmpLyr, const QMap< QgsPalLayerSettings::DataDefinedProperties, QVariant > &ddValues)
A container class for data source field mapping or expression.
QgsFeatureId featureId() const
Returns the unique ID of the feature.
void setOrigin(const QgsPoint &point)
void setCompositionMode(CompositionMode mode)
void setRenderHint(RenderHint hint, bool on)
QgsLabelFeature * feature()
Returns the parent feature.
QPointF toQPointF() const
Converts a point to a QPointF.
double rotation() const
Return the rotation of the resulting map image Units are clockwise degrees.
Q_DECL_DEPRECATED bool prepare(const QgsFields &fields)
Get the expression ready for evaluation - find out column indexes.
UpsideDownLabels upsidedownLabels
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.
Whether to show debugging rectangles for drop shadows.
double getY(int i=0) const
get the down-left y coordinate
QStringList referencedColumns() const
Get list of columns referenced by the expression.
QString & prepend(QChar ch)
void scale(qreal sx, qreal sy)
const_iterator constBegin() const
const T & at(int i) const
const QMap< QgsPalLayerSettings::DataDefinedProperties, QVariant > & dataDefinedValues() const
Get data-defined values.
static void drawLabelBuffer(QgsRenderContext &context, const QgsLabelComponent &component, const QgsPalLayerSettings &tmpLyr)
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
bool hasCrsTransformEnabled() const
returns true if projections are enabled for this layer set
Class that adds extra information to QgsLabelFeature for text labels.
QString evalErrorString() const
Returns evaluation error.
Abstract base class for all geometries.
static QgsGeometry * getPointObstacleGeometry(QgsFeature &fet, QgsRenderContext &context, const QgsSymbolV2List &symbols)
Returns the geometry for a point feature which should be used as an obstacle for labels.
Container of fields for a vector layer.
QgsPoint toMapCoordinates(int x, int y) const
A geometry is the spatial representation of a feature.
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.
static void _fixQPictureDPI(QPainter *p)
const QgsGeometry * constGeometry() const
Gets a const pointer to the geometry object associated with this feature.
static void dataDefinedDropShadow(QgsPalLayerSettings &tmpLyr, const QMap< QgsPalLayerSettings::DataDefinedProperties, QVariant > &ddValues)
MultiLineAlign multilineAlign
The QGis class provides global constants for use throughout the application.
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...
void addText(const QPointF &point, const QFont &font, const QString &text)
double y() const
Returns the point's y-coordinate.
const QgsMapSettings & mapSettings() const
Get associated map settings.
static QStringList splitToLines(const QString &text, const QString &wrapCharacter)
Splits a text string to a list of separate lines, using a specified wrap character.
virtual bool prepare(const QgsRenderContext &context, QStringList &attributeNames)
Prepare for registration of features.
void drawLabelPrivate(pal::LabelPosition *label, QgsRenderContext &context, QgsPalLayerSettings &tmpLyr, QgsPalLabeling::DrawLabelType drawType, double dpiRatio=1.0) const
Internal label drawing method.
qreal width(const QString &text) const
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)
bool reverseDirectionSymbol
void setRotationOffset(const double rotation)
static void drawLabelBackground(QgsRenderContext &context, QgsLabelComponent component, const QgsPalLayerSettings &tmpLyr)
double y() const
Get the y value of the point.
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)=0
Needs to be called when a new render cycle is started.
double mapRotation() const
Return current map rotation in degrees.
QList< QgsLabelFeature * > mLabels
List of generated.
whether adjacent lines (with the same label text) should be merged
The QgsMapSettings class contains configuration for rendering of the map.
QString styleName() const
virtual void stopRender(QgsRenderContext &context)=0
Needs to be called when a render cycle has finished to clean up.
virtual 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
QgsPoint transform(const QgsPoint &p) const
Transform the point from map (world) coordinates to device coordinates.
virtual Q_DECL_DEPRECATED QgsSymbolV2List originalSymbolsForFeature(QgsFeature &feat)
Equivalent of originalSymbolsForFeature() call extended to support renderers that may use more symbol...
void drawRect(const QRectF &rectangle)
Perform transforms between map coordinates and device coordinates.
void setFont(const QFont &font)
QgsExpressionContextScope * lastScope()
Returns the last scope added to the context.
ObstacleType obstacleType
Controls how features act as obstacles for labels.
void setRotation(const double rotation)
void append(const T &value)
static void dataDefinedTextBuffer(QgsPalLayerSettings &tmpLyr, const QMap< QgsPalLayerSettings::DataDefinedProperties, QVariant > &ddValues)
QString id() const
Get this layer's unique ID, this ID is used to access this layer from map layer registry.
virtual void setExteriorRing(QgsCurveV2 *ring) override
Sets the exterior ring of the polygon.
const QgsCoordinateTransform * ct
double rasterCompressFactor
void setFillRule(Qt::FillRule fillRule)
Utility class for identifying a unique vertex within a geometry.
#define QgsDebugMsgLevel(str, level)
const QgsRectangle & extent() const
Line string geometry type, with support for z-dimension and m-values.
QPainter::CompositionMode blendMode
unsigned int mLinePlacementFlags
Extra placement flags for linestring geometries.
void setPen(const QColor &color)
Point geometry type, with support for z-dimension and m-values.
QgsPalLayerSettings mSettings
Layer's labeling configuration.
const_iterator constEnd() const
void setCenter(const QgsPoint &point)
LabelPosition * getNextPart() const
const QgsMapToPixel * xform
QgsVectorLayerLabelProvider(QgsVectorLayer *layer, const QString &providerId, bool withFeatureLoop=true, const QgsPalLayerSettings *settings=nullptr, const QString &layerName=QString())
Convenience constructor to initialize the provider from given vector layer.
QMap< QgsPalLayerSettings::DataDefinedProperties, QgsDataDefined *> dataDefinedProperties
Map of current data defined properties.
QPaintDevice * device() const
const QgsCoordinateTransform * coordinateTransform() const
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
bool isEmpty() const
Returns true if the geometry is empty (ie, contains no underlying geometry accessible via geometry)...
void setBrush(const QBrush &brush)
void drawText(const QPointF &position, const QString &text)
double x() const
Returns the point's x-coordinate.
void setText(const QString &text)
const QgsLabelingEngineV2 * mEngine
Associated labeling engine.
QRectF united(const QRectF &rectangle) const
void registerFeature(QgsFeature &f, QgsRenderContext &context, QgsLabelFeature **labelFeature=nullptr, QgsGeometry *obstacleGeometry=nullptr)
Register a feature for labelling.
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
void setYAt(int index, double y)
Sets the y-coordinate of the specified node in the line string.
Single scope for storing variables and functions for use within a QgsExpressionContext.
QGis::GeometryType type() const
Returns type of the geometry as a QGis::GeometryType.
double mapUnitsPerPixel() const
Return current map units per pixel.
Base class that can be used for any class that is capable of returning features.
A class to represent a point.
const QgsMapToPixel & mapToPixel() const
The QgsAbstractLabelProvider class is an interface class.
QString layerId() const
Returns ID of associated layer, or empty string if no layer is associated with the provider...
double ANALYSIS_EXPORT angle(Point3D *p1, Point3D *p2, Point3D *p3, Point3D *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
void setDpiRatio(const double ratio)
virtual int nCoordinates() const
Returns the number of nodes contained in the geometry.
QgsLabelingResults * results() const
For internal use by the providers.
int fieldNameIndex(const QString &fieldName) const
Look up field's index from name also looks up case-insensitive if there is no match otherwise...
virtual void registerFeature(QgsFeature &feature, QgsRenderContext &context, QgsGeometry *obstacleGeometry=nullptr)
Register a feature for labeling as one or more QgsLabelFeature objects stored into mLabels...
void setXAt(int index, double x)
Sets the x-coordinate of the specified node in the line string.
Partial snapshot of vector layer's state (only the members necessary for access to features) ...
void setX(double x)
Sets the x value of the point.
void setY(double y)
Sets the y value of the point.
double yAt(int index) const
Returns the y-coordinate of the specified node in the line string.
QgsExpressionContext & expressionContext()
Gets the expression context.
unsigned int placementFlags
QgsFields mFields
Layer's fields.
QgsAbstractFeatureSource * mSource
Layer's feature source.
QString rightDirectionSymbol
void addVertex(const QgsPointV2 &pt)
Adds a new vertex to the end of the line string.
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.
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 setPicture(QPicture *picture)
QgsAbstractGeometryV2 * geometry() const
Returns the underlying geometry store.
The QgsLabelFeature class describes a feature that should be used within the labeling engine...
const QgsMapToPixel & mapToPixel() const
void drawPath(const QPainterPath &path)
QString name() const
Name of the layer (for statistics, debugging etc.) - does not need to be unique.
Whether to only draw the label rect and not the actual label text (used for unit tests) ...
double getAlpha() const
get alpha
void setOffset(const QgsPoint &point)
QString mName
Name of the layer.
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
void transform(const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection d=QgsCoordinateTransform::ForwardTransform, bool transformZ=false) override
Transforms the geometry using a coordinate transform.
int rotate(double rotation, const QgsPoint ¢er)
Rotate this geometry around the Z axis.
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
bool useAdvancedEffects() const
Returns true if advanced effects such as blend modes such be used.
Class for storing a coordinate reference system (CRS)
bool testFlag(Flag f) const
Test whether a particular flag is enabled.
QPointF bottomLeft() const
QString mProviderId
Associated provider ID (one layer may have multiple providers, e.g. in rule-based labeling) ...
static QgsGeometry * fromRect(const QgsRectangle &rect)
Creates a new geometry from a QgsRectangle.
LabelPosition is a candidate feature label position.
void translate(const QPointF &offset)
QgsPalLayerSettings::ObstacleType mObstacleType
Type of the obstacle of feature geometries.
QgsPalLayerSettings::UpsideDownLabels mUpsidedownLabels
How to handle labels that would be upside down.
Multi polygon geometry collection.
whether the labels should be rendered
iterator insert(const Key &key, const T &value)
bool isExpression
Is this label made from a expression string eg FieldName || 'mm'.
void setSize(const QgsPoint &point)
void drawPicture(const QPointF &point, const QPicture &picture)
QPointF bottomRight() const
virtual QgsFeatureIterator getFeatures(const QgsFeatureRequest &request)=0
Get an iterator for features matching the specified request.
double rasterScaleFactor() const
void setPictureBuffer(const double buffer)
QgsExpressionContextScope * popScope()
Removes the last scope from the expression context and return it.
bool nextFeature(QgsFeature &f)
QFontMetricsF * labelFontMetrics()
Metrics of the font for rendering.
bool hasEvalError() const
Returns true if an error occurred when evaluating last input.
double scaleFactor() const
Represents a vector layer which manages a vector based data sets.
bool begin(QPaintDevice *device)
~QgsVectorLayerLabelProvider()
QString mLayerId
Associated layer's ID, if applicable.
static QgsExpressionContextScope * updateSymbolScope(const QgsSymbolV2 *symbol, QgsExpressionContextScope *symbolScope=nullptr)
Updates a symbol scope related to a QgsSymbolV2 to an expression context.
Q_GUI_EXPORT int qt_defaultDpiY()
Whether to render labels as text or outlines.
const QgsCoordinateReferenceSystem & destinationCrs() const
returns CRS of destination coordinate reference system
Maintains current state of more grainular and temporal values when creating/painting component parts ...
virtual void drawLabel(QgsRenderContext &context, pal::LabelPosition *label) const override
draw this label at the position determined by the labeling engine
Q_DECL_DEPRECATED QStringList referencedColumns(QgsVectorLayer *layer)
Returns the columns referenced by the QgsDataDefined.
Q_GUI_EXPORT int qt_defaultDpiX()
QgsFeatureRequest & setFilterRect(const QgsRectangle &rect)
Set rectangle from which features will be taken.
double x() const
Get the x value of the point.
virtual QgsPointV2 vertexAt(QgsVertexId id) const =0
Returns the point corresponding to a specified vertex id.
QGis::GeometryType mLayerGeometryType
Geometry type of layer.
int numPoints() const override
Returns the number of points in the curve.
DirectionSymbols placeDirectionSymbol
static void drawLabelShadow(QgsRenderContext &context, const QgsLabelComponent &component, const QgsPalLayerSettings &tmpLyr)
static void dataDefinedTextFormatting(QgsPalLayerSettings &tmpLyr, const QMap< QgsPalLayerSettings::DataDefinedProperties, QVariant > &ddValues)