QGIS API Documentation 3.99.0-Master (c03dd32cbdd)
Loading...
Searching...
No Matches
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
19#include <geos_c.h>
20
21#include "qgis_core.h"
23#include "qgsfeature.h"
24#include "qgsgeos.h"
28#include "qgsmargins.h"
29
30#define SIP_NO_FILE
31
32namespace pal
33{
34 class Layer;
35}
36
39class QgsGeometry;
40
41
59class CORE_EXPORT QgsLabelFeature
60{
61 public:
62
78
79 virtual ~QgsLabelFeature();
80
82 QgsFeatureId id() const { return mId; }
83
85 int subPartId() const { return mSubPartId; }
86
88 GEOSGeometry *geometry() const { return mGeometry.get(); }
89
98 void setPermissibleZone( const QgsGeometry &geometry );
99
108
113 //TODO - remove when QgsGeometry caches GEOS preparedness
114 const GEOSPreparedGeometry *permissibleZonePrepared() const { return mPermissibleZoneGeosPrepared.get(); }
115
121 QSizeF size( double angle = 0.0 ) const;
122
130 QRectF outerBounds() const { return mOuterBounds; }
131
139 void setOuterBounds( const QRectF &bounds ) { mOuterBounds = bounds; }
140
151 void setVisualMargin( const QgsMargins &margin ) { mVisualMargin = margin; }
152
157 const QgsMargins &visualMargin() const { return mVisualMargin; }
158
165 void setSymbolSize( QSizeF size ) { mSymbolSize = size; }
166
174 const QSizeF &symbolSize() const { return mSymbolSize; }
175
182 double priority() const { return mPriority; }
183
192
198 double zIndex() const { return mZIndex; }
199
206 void setZIndex( double zIndex ) { mZIndex = zIndex; }
207
209 bool hasFixedPosition() const { return mHasFixedPosition; }
211 void setHasFixedPosition( bool enabled ) { mHasFixedPosition = enabled; }
214
216 void setFixedPosition( const QgsPointXY &point ) { mFixedPosition = point; }
217
224 QgsPointXY anchorPosition() const;
225
232 void setAnchorPosition( const QgsPointXY &anchorPosition );
233
235 bool hasFixedAngle() const { return mHasFixedAngle; }
237 void setHasFixedAngle( bool enabled ) { mHasFixedAngle = enabled; }
238
243 double fixedAngle() const { return mFixedAngle; }
244
249 void setFixedAngle( double angle ) { mFixedAngle = angle; }
250
257 bool hasFixedQuadrant() const { return mHasFixedQuadrant; }
258
265 void setHasFixedQuadrant( bool enabled ) { mHasFixedQuadrant = enabled; }
266
273 QPointF quadOffset() const { return mQuadOffset; }
274
280
286
291 void setPositionOffset( const QgsPointXY &offset ) { mPositionOffset = offset; }
292
300
308
316 double distLabel() const { return mDistLabel; }
317
325 void setDistLabel( double dist ) { mDistLabel = dist; }
326
341 double maximumDistance() const { return mMaximumDistance; }
342
357 void setMaximumDistance( double distance ) { mMaximumDistance = distance; }
358
364 QVector< Qgis::LabelPredefinedPointPosition > predefinedPositionOrder() const { return mPredefinedPositionOrder; }
365
371 void setPredefinedPositionOrder( const QVector< Qgis::LabelPredefinedPointPosition > &order ) { mPredefinedPositionOrder = order; }
372
377 double repeatDistance() const { return mRepeatDistance; }
378
383 void setRepeatDistance( double dist ) { mRepeatDistance = dist; }
384
386 bool alwaysShow() const { return mAlwaysShow; }
388 void setAlwaysShow( bool enabled ) { mAlwaysShow = enabled; }
389
395
402
410
418
425 QString labelText() const { return mLabelText; }
427 void setLabelText( const QString &text ) { mLabelText = text; }
428
430 pal::Layer *layer() const { return mLayer; }
433
435 QgsAbstractLabelProvider *provider() const;
436
443 QgsFeature feature() const;
444
451 void setFeature( const QgsFeature &feature );
452
459 const QgsSymbol *symbol() const { return mSymbol; }
460
468 void setSymbol( const QgsSymbol *symbol ) { mSymbol = symbol; }
469
478 double overrunDistance() const;
479
488 void setOverrunDistance( double distance );
489
498 double overrunSmoothDistance() const;
499
508 void setOverrunSmoothDistance( double distance );
509
522 double lineAnchorPercent() const { return mLineAnchorPercent; }
523
536 void setLineAnchorPercent( double percent ) { mLineAnchorPercent = percent; }
537
545 QgsLabelLineSettings::AnchorType lineAnchorType() const { return mLineAnchorType; }
546
554 void setLineAnchorType( QgsLabelLineSettings::AnchorType type ) { mLineAnchorType = type; }
555
564 QgsLabelLineSettings::AnchorTextPoint lineAnchorTextPoint() const;
565
574 void setLineAnchorTextPoint( QgsLabelLineSettings::AnchorTextPoint point ) { mAnchorTextPoint = point; }
575
582 Qgis::CurvedLabelMode curvedLabelMode() const { return mCurvedLabelMode; }
583
590 void setCurvedLabelMode( Qgis::CurvedLabelMode mode ) { mCurvedLabelMode = mode; }
591
599 Qgis::MultiPartLabelingBehavior multiPartBehavior() const { return mMultiPartBehavior; }
600
608 void setMultiPartBehavior( Qgis::MultiPartLabelingBehavior behavior ) { mMultiPartBehavior = behavior; }
609
615 void setRotatedSize( QSizeF size ) { mRotatedSize = size; }
616
623 const QgsLabelObstacleSettings &obstacleSettings() const;
624
631 void setObstacleSettings( const QgsLabelObstacleSettings &settings );
632
638 const QgsLabelFeatureThinningSettings &thinningSettings() const { return mThinningSettings; }
639
645 void setThinningSettings( const QgsLabelFeatureThinningSettings &settings ) { mThinningSettings = settings; }
646
653 QgsCoordinateReferenceSystem originalFeatureCrs() const;
654
661 void setOriginalFeatureCrs( const QgsCoordinateReferenceSystem &crs );
662
670 double minimumSize() const { return mMinimumSize; }
671
679 void setMinimumSize( double size ) { mMinimumSize = size; }
680
687 Qgis::LabelOverlapHandling overlapHandling() const { return mOverlapHandling; }
688
695 void setOverlapHandling( Qgis::LabelOverlapHandling handling ) { mOverlapHandling = handling; }
696
707 bool allowDegradedPlacement() const { return mAllowDegradedPlacement; }
708
715 Qgis::LabelPrioritization prioritization() const { return mPrioritization; }
716
724
735 void setAllowDegradedPlacement( bool allow ) { mAllowDegradedPlacement = allow; }
736
744 Qgis::LabelWhitespaceCollisionHandling whitespaceCollisionHandling() const { return mWhitespaceCollisionHandling; }
745
753 void setWhitespaceCollisionHandling( Qgis::LabelWhitespaceCollisionHandling handling ) { mWhitespaceCollisionHandling = handling; }
754
755 protected:
757 pal::Layer *mLayer = nullptr;
758
762 int mSubPartId = 0;
768 QSizeF mSize;
778 double mPriority = -1;
780 double mZIndex = 0;
782 bool mHasFixedPosition = false;
786 bool mHasFixedAngle = false;
788 double mFixedAngle = 0;
790 bool mHasFixedQuadrant = false;
792 QPointF mQuadOffset;
796 double mDistLabel = 0;
797
800
804 QVector< Qgis::LabelPredefinedPointPosition > mPredefinedPositionOrder;
806 double mRepeatDistance = 0;
808 bool mAlwaysShow = false;
810 QString mLabelText;
811
816
819
820 private:
821
823 geos::unique_ptr mPermissibleZoneGeos;
824
825 // TODO - not required when QgsGeometry caches geos preparedness
826 geos::prepared_unique_ptr mPermissibleZoneGeosPrepared;
827
828 QgsFeature mFeature;
829
830 const QgsSymbol *mSymbol = nullptr;
831
833
834 QgsLabelObstacleSettings mObstacleSettings;
835 QgsLabelFeatureThinningSettings mThinningSettings;
836
837 QgsPointXY mAnchorPosition;
838
839 double mLineAnchorPercent = 0.5;
843
845 bool mAllowDegradedPlacement = false;
847
848 QgsCoordinateReferenceSystem mOriginalFeatureCrs;
849
850 double mMinimumSize = 0.0;
851
853
854};
855
856#endif // QGSLABELFEATURE_H
CurvedLabelMode
Modes which determine how curved labels are generated and placed.
Definition qgis.h:1246
@ Default
Default curved placement, characters are placed in an optimal position along the line....
Definition qgis.h:1247
MultiPartLabelingBehavior
Behavior modifier for labeling features with multi-part geometries.
Definition qgis.h:1285
@ LabelLargestPartOnly
Place a label only on the largest part from the geometry.
Definition qgis.h:1286
LabelOffsetType
Behavior modifier for label offset and distance, only applies in some label placement modes.
Definition qgis.h:1301
@ FromPoint
Offset distance applies from point geometry.
Definition qgis.h:1302
LabelPrioritization
Label prioritization.
Definition qgis.h:1213
@ PreferCloser
Prefer closer labels, falling back to alternate positions before larger distances.
Definition qgis.h:1214
@ AllowPlacementInsideOfPolygon
Labels can be placed inside a polygon feature.
Definition qgis.h:1362
QFlags< LabelLinePlacementFlag > LabelLinePlacementFlags
Line placement flags, which control how candidates are generated for a linear feature.
Definition qgis.h:1350
QFlags< LabelPolygonPlacementFlag > LabelPolygonPlacementFlags
Polygon placement flags, which control how candidates are generated for a polygon feature.
Definition qgis.h:1372
LabelWhitespaceCollisionHandling
Label whitespace collision handling.
Definition qgis.h:1201
@ TreatWhitespaceAsCollision
Treat overlapping whitespace text in labels and whitespace overlapping obstacles as collisions.
Definition qgis.h:1202
LabelOverlapHandling
Label overlap handling.
Definition qgis.h:1188
@ PreventOverlap
Do not allow labels to overlap other labels.
Definition qgis.h:1189
An abstract interface class for label providers.
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:60
A geometry is the spatial representation of a feature.
Contains settings related to how the label engine removes candidate label positions and reduces the n...
double maximumDistance() const
Returns the maximum distance which labels are allowed to be from their corresponding points.
void setMinimumSize(double size)
Sets the minimum size (in map unit) for a feature to be labelled.
void setWhitespaceCollisionHandling(Qgis::LabelWhitespaceCollisionHandling handling)
Sets the whitespace collision handling.
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).
bool mHasFixedAngle
whether mFixedAngle should be respected
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;.
double mRepeatDistance
distance after which label should be repeated (only for linestrings)
Qgis::MultiPartLabelingBehavior multiPartBehavior() const
Returns the multipart labeling behavior.
void setRepeatDistance(double dist)
Applies only to linestring features - set after what distance (in map units) the labels should be rep...
void setCurvedLabelMode(Qgis::CurvedLabelMode mode)
Sets the mode which determine how curved labels are generated and placed.
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).
void setPrioritization(Qgis::LabelPrioritization prioritization)
Sets the label prioritization technique.
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...
QSizeF size(double angle=0.0) const
Size of the label (in map units).
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.
double mPriority
Priority of the label.
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 setMaximumDistance(double distance)
Sets the maximum distance which labels are allowed to be from their corresponding points.
double mDistLabel
distance of label from the feature (only for "around point" placement or linestrings)
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...
bool mHasFixedQuadrant
whether mQuadOffset should be respected (only for "around point" placement)
QgsLabelLineSettings::AnchorType lineAnchorType() const
Returns the line anchor type, which dictates how the lineAnchorPercent() setting is handled.
Qgis::LabelWhitespaceCollisionHandling whitespaceCollisionHandling() const
Returns the whitespace collision handling.
int mSubPartId
Associated sub part ID, for features which register multiple different labels.
pal::Layer * mLayer
Pointer to PAL layer (assigned when registered to PAL).
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.
Qgis::LabelOffsetType mOffsetType
Offset type for certain placement modes.
bool allowDegradedPlacement() const
Returns true if the label can be placed in inferior fallback positions if it cannot otherwise be plac...
QgsLabelFeature(QgsFeatureId id, geos::unique_ptr geometry, QSizeF size, int subPartId=0)
Constructor for QgsLabelFeature.
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.
double mOverrunSmoothDistance
Distance to smooth angle of line start and end when calculating overruns.
void setPositionOffset(const QgsPointXY &offset)
Applies only to "offset from point" placement strategy.
const QgsLabelFeatureThinningSettings & thinningSettings() const
Returns the thinning settings for this label.
Qgis::LabelOverlapHandling overlapHandling() const
Returns the technique to use for handling overlapping labels for the feature.
double mFixedAngle
fixed rotation for the label (instead of automatic choice)
double mZIndex
Z-index of label (higher z-index labels are rendered on top of lower z-index labels).
QgsPointXY mPositionOffset
offset of label from the feature (only for "offset from point" placement)
Qgis::LabelPrioritization prioritization() const
Returns the label prioritization technique.
bool mAlwaysShow
whether to always show label - even in case of collisions
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 ...
void setMultiPartBehavior(Qgis::MultiPartLabelingBehavior behavior)
Sets the multipart labeling behavior.
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.
bool mHasFixedPosition
whether mFixedPosition should be respected
void setAllowDegradedPlacement(bool allow)
Sets whether the label can be placed in inferior fallback positions if it cannot otherwise be placed.
void setThinningSettings(const QgsLabelFeatureThinningSettings &settings)
Sets the thinning settings for this label.
double zIndex() const
Returns the label's z-index.
void setHasFixedQuadrant(bool enabled)
Sets whether the quadrant for the label must be respected.
Qgis::LabelPolygonPlacementFlags mPolygonPlacementFlags
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...
Qgis::LabelLinePlacementFlags mArrangementFlags
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...
double mOverrunDistance
Distance to allow label to overrun linear features.
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.
double mMaximumDistance
Maximum distance of label from the feature.
Qgis::CurvedLabelMode curvedLabelMode() const
Returns the mode which determine how curved labels are generated and placed.
QString mLabelText
text of the label
QgsPointXY fixedPosition() const
Coordinates of the fixed position (relevant only if hasFixedPosition() returns true).
int subPartId() const
Sub part identifier (for features which register multiple labels).
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.
Defines the four margins of a rectangle.
Definition qgsmargins.h:40
Represents a 2D point.
Definition qgspointxy.h:62
Contains information about the context of a rendering operation.
Abstract base class for all rendered symbols.
Definition qgssymbol.h:231
A set of features which influence the labeling process.
Definition layer.h:64
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
Definition qgsgeos.h:114
std::unique_ptr< const GEOSPreparedGeometry, GeosDeleter > prepared_unique_ptr
Scoped GEOS prepared geometry pointer.
Definition qgsgeos.h:119
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
struct GEOSGeom_t GEOSGeometry
Definition util.h:42