QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
qgslabelfeature.h
Go to the documentation of this file.
1/***************************************************************************
2 qgslabelfeature.h
3 ---------------------
4 begin : December 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#ifndef QGSLABELFEATURE_H
16#define QGSLABELFEATURE_H
17
18#define SIP_NO_FILE
19
20#include "qgis_core.h"
21#include "geos_c.h"
22#include "qgsgeos.h"
23#include "qgsmargins.h"
26#include "qgsfeature.h"
28
29namespace pal
30{
31 class Layer;
32}
33
36class QgsGeometry;
37
38
55class CORE_EXPORT QgsLabelFeature
56{
57 public:
58
70 QgsLabelFeature( QgsFeatureId id, geos::unique_ptr geometry, QSizeF size );
71
72 virtual ~QgsLabelFeature();
73
75 QgsFeatureId id() const { return mId; }
76
78 GEOSGeometry *geometry() const { return mGeometry.get(); }
79
88 void setPermissibleZone( const QgsGeometry &geometry );
89
97 QgsGeometry permissibleZone() const { return mPermissibleZone; }
98
103 //TODO - remove when QgsGeometry caches GEOS preparedness
104 const GEOSPreparedGeometry *permissibleZonePrepared() const { return mPermissibleZoneGeosPrepared.get(); }
105
111 QSizeF size( double angle = 0.0 ) const;
112
120 QRectF outerBounds() const { return mOuterBounds; }
121
129 void setOuterBounds( const QRectF &bounds ) { mOuterBounds = bounds; }
130
141 void setVisualMargin( const QgsMargins &margin ) { mVisualMargin = margin; }
142
147 const QgsMargins &visualMargin() const { return mVisualMargin; }
148
155 void setSymbolSize( QSizeF size ) { mSymbolSize = size; }
156
164 const QSizeF &symbolSize() const { return mSymbolSize; }
165
172 double priority() const { return mPriority; }
173
181 void setPriority( double priority ) { mPriority = priority; }
182
188 double zIndex() const { return mZIndex; }
189
196 void setZIndex( double zIndex ) { mZIndex = zIndex; }
197
199 bool hasFixedPosition() const { return mHasFixedPosition; }
201 void setHasFixedPosition( bool enabled ) { mHasFixedPosition = enabled; }
203 QgsPointXY fixedPosition() const { return mFixedPosition; }
204
206 void setFixedPosition( const QgsPointXY &point ) { mFixedPosition = point; }
207
214 QgsPointXY anchorPosition() const;
215
222 void setAnchorPosition( const QgsPointXY &anchorPosition );
223
225 bool hasFixedAngle() const { return mHasFixedAngle; }
227 void setHasFixedAngle( bool enabled ) { mHasFixedAngle = enabled; }
228
233 double fixedAngle() const { return mFixedAngle; }
234
239 void setFixedAngle( double angle ) { mFixedAngle = angle; }
240
247 bool hasFixedQuadrant() const { return mHasFixedQuadrant; }
248
255 void setHasFixedQuadrant( bool enabled ) { mHasFixedQuadrant = enabled; }
256
263 QPointF quadOffset() const { return mQuadOffset; }
264
269 void setQuadOffset( QPointF quadOffset ) { mQuadOffset = quadOffset; }
270
275 QgsPointXY positionOffset() const { return mPositionOffset; }
276
281 void setPositionOffset( const QgsPointXY &offset ) { mPositionOffset = offset; }
282
289 Qgis::LabelOffsetType offsetType() const { return mOffsetType; }
290
297 void setOffsetType( Qgis::LabelOffsetType type ) { mOffsetType = type; }
298
303 double distLabel() const { return mDistLabel; }
304
309 void setDistLabel( double dist ) { mDistLabel = dist; }
310
316 QVector< Qgis::LabelPredefinedPointPosition > predefinedPositionOrder() const { return mPredefinedPositionOrder; }
317
323 void setPredefinedPositionOrder( const QVector< Qgis::LabelPredefinedPointPosition > &order ) { mPredefinedPositionOrder = order; }
324
329 double repeatDistance() const { return mRepeatDistance; }
330
335 void setRepeatDistance( double dist ) { mRepeatDistance = dist; }
336
338 bool alwaysShow() const { return mAlwaysShow; }
340 void setAlwaysShow( bool enabled ) { mAlwaysShow = enabled; }
341
346 Qgis::LabelLinePlacementFlags arrangementFlags() const { return mArrangementFlags; }
347
353 void setArrangementFlags( Qgis::LabelLinePlacementFlags flags ) { mArrangementFlags = flags; }
354
361 Qgis::LabelPolygonPlacementFlags polygonPlacementFlags() const { return mPolygonPlacementFlags; }
362
369 void setPolygonPlacementFlags( Qgis::LabelPolygonPlacementFlags flags ) { mPolygonPlacementFlags = flags; }
370
377 QString labelText() const { return mLabelText; }
379 void setLabelText( const QString &text ) { mLabelText = text; }
380
382 pal::Layer *layer() const { return mLayer; }
384 void setLayer( pal::Layer *layer ) { mLayer = layer; }
385
387 QgsAbstractLabelProvider *provider() const;
388
395 QgsFeature feature() const;
396
403 void setFeature( const QgsFeature &feature );
404
411 const QgsSymbol *symbol() const { return mSymbol; }
412
420 void setSymbol( const QgsSymbol *symbol ) { mSymbol = symbol; }
421
430 double overrunDistance() const;
431
440 void setOverrunDistance( double distance );
441
450 double overrunSmoothDistance() const;
451
460 void setOverrunSmoothDistance( double distance );
461
474 double lineAnchorPercent() const { return mLineAnchorPercent; }
475
488 void setLineAnchorPercent( double percent ) { mLineAnchorPercent = percent; }
489
497 QgsLabelLineSettings::AnchorType lineAnchorType() const { return mLineAnchorType; }
498
506 void setLineAnchorType( QgsLabelLineSettings::AnchorType type ) { mLineAnchorType = type; }
507
516 QgsLabelLineSettings::AnchorTextPoint lineAnchorTextPoint() const;
517
526 void setLineAnchorTextPoint( QgsLabelLineSettings::AnchorTextPoint point ) { mAnchorTextPoint = point; }
527
533 bool labelAllParts() const { return mLabelAllParts; }
534
540 void setLabelAllParts( bool labelAllParts ) { mLabelAllParts = labelAllParts; }
541
547 void setRotatedSize( QSizeF size ) { mRotatedSize = size; }
548
555 const QgsLabelObstacleSettings &obstacleSettings() const;
556
563 void setObstacleSettings( const QgsLabelObstacleSettings &settings );
564
571 QgsCoordinateReferenceSystem originalFeatureCrs() const;
572
579 void setOriginalFeatureCrs( const QgsCoordinateReferenceSystem &crs );
580
588 double minimumSize() const { return mMinimumSize; }
589
597 void setMinimumSize( double size ) { mMinimumSize = size; }
598
605 Qgis::LabelOverlapHandling overlapHandling() const { return mOverlapHandling; }
606
613 void setOverlapHandling( Qgis::LabelOverlapHandling handling ) { mOverlapHandling = handling; }
614
625 bool allowDegradedPlacement() const { return mAllowDegradedPlacement; }
626
637 void setAllowDegradedPlacement( bool allow ) { mAllowDegradedPlacement = allow; }
638
639 protected:
641 pal::Layer *mLayer = nullptr;
642
650 QSizeF mSize;
660 double mPriority = -1;
662 double mZIndex = 0;
664 bool mHasFixedPosition = false;
668 bool mHasFixedAngle = false;
670 double mFixedAngle = 0;
672 bool mHasFixedQuadrant = false;
674 QPointF mQuadOffset;
678 double mDistLabel = 0;
682 QVector< Qgis::LabelPredefinedPointPosition > mPredefinedPositionOrder;
684 double mRepeatDistance = 0;
686 bool mAlwaysShow = false;
688 QString mLabelText;
689
691 double mOverrunDistance = 0;
693 double mOverrunSmoothDistance = 0;
694
697
698 private:
699
701 geos::unique_ptr mPermissibleZoneGeos;
702
703 // TODO - not required when QgsGeometry caches geos preparedness
704 geos::prepared_unique_ptr mPermissibleZoneGeosPrepared;
705
706 QgsFeature mFeature;
707
708 const QgsSymbol *mSymbol = nullptr;
709
710 bool mLabelAllParts = false;
711
712 QgsLabelObstacleSettings mObstacleSettings{};
713
714 QgsPointXY mAnchorPosition;
715
716 double mLineAnchorPercent = 0.5;
719
721 bool mAllowDegradedPlacement = false;
722
723 QgsCoordinateReferenceSystem mOriginalFeatureCrs;
724
725 double mMinimumSize = 0.0;
726
727};
728
729#endif // QGSLABELFEATURE_H
LabelOffsetType
Behavior modifier for label offset and distance, only applies in some label placement modes.
Definition: qgis.h:960
@ FromPoint
Offset distance applies from point geometry.
@ AllowPlacementInsideOfPolygon
Labels can be placed inside a polygon feature.
QFlags< LabelLinePlacementFlag > LabelLinePlacementFlags
Line placement flags, which control how candidates are generated for a linear feature.
Definition: qgis.h:1009
QFlags< LabelPolygonPlacementFlag > LabelPolygonPlacementFlags
Polygon placement flags, which control how candidates are generated for a polygon feature.
Definition: qgis.h:1031
LabelOverlapHandling
Label overlap handling.
Definition: qgis.h:899
@ PreventOverlap
Do not allow labels to overlap other labels.
The QgsAbstractLabelProvider class is an interface class.
This class represents a coordinate reference system (CRS).
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:56
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:162
The QgsLabelFeature class describes a feature that should be used within the labeling engine.
void setMinimumSize(double size)
Sets the minimum size (in map unit) for a feature to be labelled.
QSizeF mSymbolSize
Size of associated rendered symbol, if applicable.
void setDistLabel(double dist)
Applies to "around point" placement strategy or linestring features.
void setAlwaysShow(bool enabled)
Sets whether label should be always shown (sets very high label priority)
QgsPointXY mFixedPosition
fixed position for the label (instead of automatic placement)
QSizeF mRotatedSize
Width and height of the label when rotated between 45 to 135 and 235 to 315 degrees;.
void setRepeatDistance(double dist)
Applies only to linestring features - set after what distance (in map units) the labels should be rep...
Qgis::LabelPolygonPlacementFlags polygonPlacementFlags() const
Returns the polygon placement flags, which dictate how polygon labels can be placed.
QVector< Qgis::LabelPredefinedPointPosition > mPredefinedPositionOrder
Ordered list of predefined positions for label (only for OrderedPositionsAroundPoint placement)
double fixedAngle() const
Angle in radians of the fixed angle (relevant only if hasFixedAngle() returns true)
const QSizeF & symbolSize() const
Returns the size of the rendered symbol associated with this feature, if applicable.
QVector< Qgis::LabelPredefinedPointPosition > predefinedPositionOrder() const
Returns the priority ordered list of predefined positions for label candidates.
double repeatDistance() const
Applies only to linestring features - after what distance (in map units) the labels should be repeate...
void setSymbolSize(QSizeF size)
Sets the size of the rendered symbol associated with this feature.
QgsPointXY positionOffset() const
Applies only to "offset from point" placement strategy.
void setLayer(pal::Layer *layer)
Assign PAL layer to the label feature. Should be only used internally in PAL.
QgsMargins mVisualMargin
Visual margin of label contents.
bool hasFixedQuadrant() const
Returns whether the quadrant for the label is fixed.
void setZIndex(double zIndex)
Sets the label's z-index.
void setLineAnchorType(QgsLabelLineSettings::AnchorType type)
Sets the line anchor type, which dictates how the lineAnchorPercent() setting is handled.
bool hasFixedAngle() const
Whether the label should use a fixed angle instead of using angle from automatic placement.
pal::Layer * layer() const
Gets PAL layer of the label feature. Should be only used internally in PAL.
QgsFeatureId mId
Associated ID unique within the parent label provider.
bool alwaysShow() const
Whether label should be always shown (sets very high label priority)
double lineAnchorPercent() const
Returns the percent along the line at which labels should be placed, for line labels only.
void setOffsetType(Qgis::LabelOffsetType type)
Sets the offset type, which determines how offsets and distance to label behaves.
const GEOSPreparedGeometry * permissibleZonePrepared() const
Returns a GEOS prepared geometry representing the label's permissibleZone().
void setLabelAllParts(bool labelAllParts)
Sets whether all parts of the feature should be labeled.
void setSymbol(const QgsSymbol *symbol)
Sets the feature symbol associated with this label.
void setHasFixedAngle(bool enabled)
Sets whether the label should use a fixed angle instead of using angle from automatic placement.
void setOuterBounds(const QRectF &bounds)
Sets the extreme outer bounds of the label feature, including any surrounding content like borders or...
QgsLabelLineSettings::AnchorType lineAnchorType() const
Returns the line anchor type, which dictates how the lineAnchorPercent() setting is handled.
double distLabel() const
Applies to "around point" placement strategy or linestring features.
GEOSGeometry * geometry() const
Gets access to the associated geometry.
void setPredefinedPositionOrder(const QVector< Qgis::LabelPredefinedPointPosition > &order)
Sets the priority ordered list of predefined positions for label candidates.
bool allowDegradedPlacement() const
Returns true if the label can be placed in inferior fallback positions if it cannot otherwise be plac...
QPointF quadOffset() const
Applies to "offset from point" placement strategy and "around point" (in case hasFixedQuadrant() retu...
QgsGeometry mPermissibleZone
Optional geometry to use for label's permissible zone.
void setPositionOffset(const QgsPointXY &offset)
Applies only to "offset from point" placement strategy.
Qgis::LabelOverlapHandling overlapHandling() const
Returns the technique to use for handling overlapping labels for the feature.
QgsPointXY mPositionOffset
offset of label from the feature (only for "offset from point" placement)
void setOverlapHandling(Qgis::LabelOverlapHandling handling)
Sets the technique to use for handling overlapping labels for the feature.
void setLineAnchorPercent(double percent)
Sets the percent along the line at which labels should be placed, for line labels only.
void setLineAnchorTextPoint(QgsLabelLineSettings::AnchorTextPoint point)
Sets the line anchor text point, which dictates which part of the label text should be placed at the ...
QgsFeatureId id() const
Identifier of the label (unique within the parent label provider)
QPointF mQuadOffset
whether the side of the label is fixed (only for "around point" placement)
QSizeF mSize
Width and height of the label.
double priority() const
Returns the feature's labeling priority.
void setAllowDegradedPlacement(bool allow)
Sets whether the label can be placed in inferior fallback positions if it cannot otherwise be placed.
double zIndex() const
Returns the label's z-index.
void setHasFixedQuadrant(bool enabled)
Sets whether the quadrant for the label must be respected.
void setPriority(double priority)
Sets the priority for labeling the feature.
void setQuadOffset(QPointF quadOffset)
Set which side of the point to use.
double minimumSize() const
Returns the minimum size (in map unit) for a feature to be labelled.
QgsGeometry permissibleZone() const
Returns the label's permissible zone geometry.
bool hasFixedPosition() const
Whether the label should use a fixed position instead of being automatically placed.
void setHasFixedPosition(bool enabled)
Sets whether the label should use a fixed position instead of being automatically placed.
geos::unique_ptr mGeometry
Geometry of the feature to be labelled.
const QgsMargins & visualMargin() const
Returns the visual margin for the label feature.
void setFixedPosition(const QgsPointXY &point)
Sets coordinates of the fixed position (relevant only if hasFixedPosition() returns true)
Qgis::LabelLinePlacementFlags arrangementFlags() const
Returns the feature's arrangement flags.
QString labelText() const
Text of the label.
QRectF mOuterBounds
Extreme outer bounds of the label feature, including any surrounding content like borders or backgrou...
void setArrangementFlags(Qgis::LabelLinePlacementFlags flags)
Sets the feature's arrangement flags.
void setVisualMargin(const QgsMargins &margin)
Sets the visual margin for the label feature.
Qgis::LabelOffsetType offsetType() const
Returns the offset type, which determines how offsets and distance to label behaves.
void setLabelText(const QString &text)
Sets text of the label.
QRectF outerBounds() const
Returns the extreme outer bounds of the label feature, including any surrounding content like borders...
const QgsSymbol * symbol() const
Returns the feature symbol associated with this label.
void setRotatedSize(QSizeF size)
Sets an alternate label size to be used when a label rotation angle is between 45 to 135 and 235 to 3...
void setPolygonPlacementFlags(Qgis::LabelPolygonPlacementFlags flags)
Sets the polygon placement flags, which dictate how polygon labels can be placed.
bool labelAllParts() const
Returns true if all parts of the feature should be labeled.
QString mLabelText
text of the label
QgsPointXY fixedPosition() const
Coordinates of the fixed position (relevant only if hasFixedPosition() returns true)
void setFixedAngle(double angle)
Sets the angle in radians of the fixed angle (relevant only if hasFixedAngle() returns true).
AnchorType
Line anchor types.
@ HintOnly
Line anchor is a hint for preferred placement only, but other placements close to the hint are permit...
AnchorTextPoint
Anchor point of label text.
@ CenterOfText
Anchor using center of text.
Contains settings related to how the label engine treats features as obstacles.
The QgsMargins class defines the four margins of a rectangle.
Definition: qgsmargins.h:37
A class to represent a 2D point.
Definition: qgspointxy.h:60
Contains information about the context of a rendering operation.
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:94
A set of features which influence the labeling process.
Definition: layer.h:63
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:716
std::unique_ptr< const GEOSPreparedGeometry, GeosDeleter > prepared_unique_ptr
Scoped GEOS prepared geometry pointer.
Definition: qgsgeos.h:78
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
Definition: qgsgeos.h:73
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
Definition: qgsfeatureid.h:28
const QgsCoordinateReferenceSystem & crs
struct GEOSGeom_t GEOSGeometry
Definition: util.h:41