QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 "qgspallabeling.h"
22 #include "geos_c.h"
23 #include "qgsgeos.h"
24 #include "qgsmargins.h"
26 #include "qgslabeling.h"
27 
28 namespace pal
29 {
30  class LabelInfo;
31  class Layer;
32 }
33 
35 class QgsRenderContext;
36 class QgsGeometry;
37 
38 
56 class CORE_EXPORT QgsLabelFeature
57 {
58  public:
59 
61  QgsLabelFeature( QgsFeatureId id, geos::unique_ptr geometry, QSizeF size );
63  virtual ~QgsLabelFeature();
64 
66  QgsFeatureId id() const { return mId; }
67 
69  GEOSGeometry *geometry() const { return mGeometry.get(); }
70 
80  void setPermissibleZone( const QgsGeometry &geometry );
81 
90  QgsGeometry permissibleZone() const { return mPermissibleZone; }
91 
97  //TODO - remove when QgsGeometry caches GEOS preparedness
98  const GEOSPreparedGeometry *permissibleZonePrepared() const { return mPermissibleZoneGeosPrepared.get(); }
99 
101  QSizeF size( double angle = 0.0 ) const;
102 
113  void setVisualMargin( const QgsMargins &margin ) { mVisualMargin = margin; }
114 
119  const QgsMargins &visualMargin() const { return mVisualMargin; }
120 
127  void setSymbolSize( QSizeF size ) { mSymbolSize = size; }
128 
136  const QSizeF &symbolSize() const { return mSymbolSize; }
137 
144  double priority() const { return mPriority; }
145 
153  void setPriority( double priority ) { mPriority = priority; }
154 
161  double zIndex() const { return mZIndex; }
162 
170  void setZIndex( double zIndex ) { mZIndex = zIndex; }
171 
173  bool hasFixedPosition() const { return mHasFixedPosition; }
175  void setHasFixedPosition( bool enabled ) { mHasFixedPosition = enabled; }
177  QgsPointXY fixedPosition() const { return mFixedPosition; }
178 
180  void setFixedPosition( const QgsPointXY &point ) { mFixedPosition = point; }
181 
188  QgsPointXY anchorPosition() const;
189 
196  void setAnchorPosition( const QgsPointXY &anchorPosition );
197 
199  bool hasFixedAngle() const { return mHasFixedAngle; }
201  void setHasFixedAngle( bool enabled ) { mHasFixedAngle = enabled; }
203  double fixedAngle() const { return mFixedAngle; }
205  void setFixedAngle( double angle ) { mFixedAngle = angle; }
206 
213  bool hasFixedQuadrant() const { return mHasFixedQuadrant; }
214 
221  void setHasFixedQuadrant( bool enabled ) { mHasFixedQuadrant = enabled; }
222 
229  QPointF quadOffset() const { return mQuadOffset; }
230 
235  void setQuadOffset( QPointF quadOffset ) { mQuadOffset = quadOffset; }
236 
241  QgsPointXY positionOffset() const { return mPositionOffset; }
242 
247  void setPositionOffset( const QgsPointXY &offset ) { mPositionOffset = offset; }
248 
255  QgsPalLayerSettings::OffsetType offsetType() const { return mOffsetType; }
256 
263  void setOffsetType( QgsPalLayerSettings::OffsetType type ) { mOffsetType = type; }
264 
269  double distLabel() const { return mDistLabel; }
270 
275  void setDistLabel( double dist ) { mDistLabel = dist; }
276 
282  QVector< QgsPalLayerSettings::PredefinedPointPosition > predefinedPositionOrder() const { return mPredefinedPositionOrder; }
283 
289  void setPredefinedPositionOrder( const QVector< QgsPalLayerSettings::PredefinedPointPosition > &order ) { mPredefinedPositionOrder = order; }
290 
295  double repeatDistance() const { return mRepeatDistance; }
296 
301  void setRepeatDistance( double dist ) { mRepeatDistance = dist; }
302 
304  bool alwaysShow() const { return mAlwaysShow; }
306  void setAlwaysShow( bool enabled ) { mAlwaysShow = enabled; }
307 
312  QgsLabeling::LinePlacementFlags arrangementFlags() const { return mArrangementFlags; }
313 
319  void setArrangementFlags( QgsLabeling::LinePlacementFlags flags ) { mArrangementFlags = flags; }
320 
327  QgsLabeling::PolygonPlacementFlags polygonPlacementFlags() const { return mPolygonPlacementFlags; }
328 
335  void setPolygonPlacementFlags( QgsLabeling::PolygonPlacementFlags flags ) { mPolygonPlacementFlags = flags; }
336 
343  QString labelText() const { return mLabelText; }
345  void setLabelText( const QString &text ) { mLabelText = text; }
346 
348  pal::LabelInfo *curvedLabelInfo() const { return mInfo; }
350  void setCurvedLabelInfo( pal::LabelInfo *info ) { mInfo = info; }
351 
353  pal::Layer *layer() const { return mLayer; }
355  void setLayer( pal::Layer *layer ) { mLayer = layer; }
356 
358  QgsAbstractLabelProvider *provider() const;
359 
366  QgsFeature feature() const;
367 
374  void setFeature( const QgsFeature &feature );
375 
382  const QgsSymbol *symbol() { return mSymbol; }
383 
391  void setSymbol( const QgsSymbol *symbol ) { mSymbol = symbol; }
392 
401  double overrunDistance() const;
402 
411  void setOverrunDistance( double distance );
412 
421  double overrunSmoothDistance() const;
422 
431  void setOverrunSmoothDistance( double distance );
432 
445  double lineAnchorPercent() const { return mLineAnchorPercent; }
446 
459  void setLineAnchorPercent( double percent ) { mLineAnchorPercent = percent; }
460 
461 
469  QgsLabelLineSettings::AnchorType lineAnchorType() const { return mLineAnchorType; }
470 
478  void setLineAnchorType( QgsLabelLineSettings::AnchorType type ) { mLineAnchorType = type; }
479 
485  bool labelAllParts() const { return mLabelAllParts; }
486 
492  void setLabelAllParts( bool labelAllParts ) { mLabelAllParts = labelAllParts; }
493 
499  void setRotatedSize( QSizeF size ) { mRotatedSize = size; }
500 
507  const QgsLabelObstacleSettings &obstacleSettings() const;
508 
515  void setObstacleSettings( const QgsLabelObstacleSettings &settings );
516 
517  protected:
519  pal::Layer *mLayer = nullptr;
520 
528  QSizeF mSize;
530  QSizeF mRotatedSize;
534  QSizeF mSymbolSize;
536  double mPriority = -1;
538  double mZIndex = 0;
540  bool mHasFixedPosition = false;
544  bool mHasFixedAngle = false;
546  double mFixedAngle = 0;
548  bool mHasFixedQuadrant = false;
550  QPointF mQuadOffset;
554  double mDistLabel = 0;
558  QVector< QgsPalLayerSettings::PredefinedPointPosition > mPredefinedPositionOrder;
560  double mRepeatDistance = 0;
562  bool mAlwaysShow = false;
564  QString mLabelText;
566  pal::LabelInfo *mInfo = nullptr;
567 
569  double mOverrunDistance = 0;
571  double mOverrunSmoothDistance = 0;
572 
573  QgsLabeling::LinePlacementFlags mArrangementFlags = QgsLabeling::LinePlacementFlags();
574  QgsLabeling::PolygonPlacementFlags mPolygonPlacementFlags = QgsLabeling::PolygonPlacementFlag::AllowPlacementInsideOfPolygon;
575 
576  private:
577 
579  geos::unique_ptr mPermissibleZoneGeos;
580 
581  // TODO - not required when QgsGeometry caches geos preparedness
582  geos::prepared_unique_ptr mPermissibleZoneGeosPrepared;
583 
584  QgsFeature mFeature;
585 
586  const QgsSymbol *mSymbol = nullptr;
587 
588  bool mLabelAllParts = false;
589 
590  QgsLabelObstacleSettings mObstacleSettings{};
591 
592  QgsPointXY mAnchorPosition;
593 
594  double mLineAnchorPercent = 0.5;
596 };
597 
598 #endif // QGSLABELFEATURE_H
QgsLabelFeature::id
QgsFeatureId id() const
Identifier of the label (unique within the parent label provider)
Definition: qgslabelfeature.h:66
QgsLabelFeature::positionOffset
QgsPointXY positionOffset() const
Applies only to "offset from point" placement strategy.
Definition: qgslabelfeature.h:241
QgsLabelFeature::offsetType
QgsPalLayerSettings::OffsetType offsetType() const
Returns the offset type, which determines how offsets and distance to label behaves.
Definition: qgslabelfeature.h:255
QgsLabelFeature::setRotatedSize
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...
Definition: qgslabelfeature.h:499
QgsLabelFeature::setPredefinedPositionOrder
void setPredefinedPositionOrder(const QVector< QgsPalLayerSettings::PredefinedPointPosition > &order)
Sets the priority ordered list of predefined positions for label candidates.
Definition: qgslabelfeature.h:289
QgsLabelFeature::priority
double priority() const
Returns the feature's labeling priority.
Definition: qgslabelfeature.h:144
QgsLabelFeature::fixedAngle
double fixedAngle() const
Angle in degrees of the fixed angle (relevant only if hasFixedAngle() returns true)
Definition: qgslabelfeature.h:203
qgspallabeling.h
QgsLabelFeature::setDistLabel
void setDistLabel(double dist)
Applies to "around point" placement strategy or linestring features.
Definition: qgslabelfeature.h:275
QgsLabelFeature::setPriority
void setPriority(double priority)
Sets the priority for labeling the feature.
Definition: qgslabelfeature.h:153
pal::LabelInfo
Optional additional info about label (for curved labels)
Definition: feature.h:55
QgsLabelFeature::setPositionOffset
void setPositionOffset(const QgsPointXY &offset)
Applies only to "offset from point" placement strategy.
Definition: qgslabelfeature.h:247
QgsLabelFeature::symbolSize
const QSizeF & symbolSize() const
Returns the size of the rendered symbol associated with this feature, if applicable.
Definition: qgslabelfeature.h:136
QgsPalLayerSettings::FromPoint
@ FromPoint
Offset distance applies from point geometry.
Definition: qgspallabeling.h:260
QgsLabelFeature::mId
QgsFeatureId mId
Associated ID unique within the parent label provider.
Definition: qgslabelfeature.h:522
QgsLabelFeature::visualMargin
const QgsMargins & visualMargin() const
Returns the visual margin for the label feature.
Definition: qgslabelfeature.h:119
QgsPalLayerSettings::OffsetType
OffsetType
Behavior modifier for label offset and distance, only applies in some label placement modes.
Definition: qgspallabeling.h:259
QgsRenderContext
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:58
QgsLabelObstacleSettings
Contains settings related to how the label engine treats features as obstacles.
Definition: qgslabelobstaclesettings.h:35
QgsSymbol
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:64
QgsLabelFeature::permissibleZonePrepared
const GEOSPreparedGeometry * permissibleZonePrepared() const
Returns a GEOS prepared geometry representing the label's permissibleZone().
Definition: qgslabelfeature.h:98
QgsLabelFeature::arrangementFlags
QgsLabeling::LinePlacementFlags arrangementFlags() const
Returns the feature's arrangement flags.
Definition: qgslabelfeature.h:312
QgsLabelFeature::mQuadOffset
QPointF mQuadOffset
whether the side of the label is fixed (only for "around point" placement)
Definition: qgslabelfeature.h:550
pal
Definition: qgsdiagramrenderer.h:49
QgsLabelFeature::repeatDistance
double repeatDistance() const
Applies only to linestring features - after what distance (in map units) the labels should be repeate...
Definition: qgslabelfeature.h:295
QgsLabelFeature::hasFixedQuadrant
bool hasFixedQuadrant() const
Returns whether the quadrant for the label is fixed.
Definition: qgslabelfeature.h:213
geos::unique_ptr
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
Definition: qgsgeos.h:79
QgsLabelFeature::setSymbolSize
void setSymbolSize(QSizeF size)
Sets the size of the rendered symbol associated with this feature.
Definition: qgslabelfeature.h:127
QgsLabelFeature::mPermissibleZone
QgsGeometry mPermissibleZone
Optional geometry to use for label's permissible zone.
Definition: qgslabelfeature.h:526
QgsLabelFeature::hasFixedPosition
bool hasFixedPosition() const
Whether the label should use a fixed position instead of being automatically placed.
Definition: qgslabelfeature.h:173
QgsAbstractLabelProvider
The QgsAbstractLabelProvider class is an interface class.
Definition: qgslabelingengine.h:48
QgsLabelFeature::mSize
QSizeF mSize
Width and height of the label.
Definition: qgslabelfeature.h:528
QgsLabelFeature::labelAllParts
bool labelAllParts() const
Returns true if all parts of the feature should be labeled.
Definition: qgslabelfeature.h:485
QgsLabelFeature::hasFixedAngle
bool hasFixedAngle() const
Whether the label should use a fixed angle instead of using angle from automatic placement.
Definition: qgslabelfeature.h:199
QgsLabelFeature::lineAnchorPercent
double lineAnchorPercent() const
Returns the percent along the line at which labels should be placed, for line labels only.
Definition: qgslabelfeature.h:445
QgsLabelFeature::symbol
const QgsSymbol * symbol()
Returns the feature symbol associated with this label.
Definition: qgslabelfeature.h:382
QgsLabelFeature::mLabelText
QString mLabelText
text of the label
Definition: qgslabelfeature.h:564
QgsLabelFeature::setZIndex
void setZIndex(double zIndex)
Sets the label's z-index.
Definition: qgslabelfeature.h:170
QgsLabelFeature::setHasFixedAngle
void setHasFixedAngle(bool enabled)
Sets whether the label should use a fixed angle instead of using angle from automatic placement.
Definition: qgslabelfeature.h:201
QgsLabelFeature::setRepeatDistance
void setRepeatDistance(double dist)
Applies only to linestring features - set after what distance (in map units) the labels should be rep...
Definition: qgslabelfeature.h:301
QgsLabelFeature::lineAnchorType
QgsLabelLineSettings::AnchorType lineAnchorType() const
Returns the line anchor type, which dictates how the lineAnchorPercent() setting is handled.
Definition: qgslabelfeature.h:469
QgsLabelFeature::setHasFixedQuadrant
void setHasFixedQuadrant(bool enabled)
Sets whether the quadrant for the label must be respected.
Definition: qgslabelfeature.h:221
QgsLabelFeature::setLineAnchorType
void setLineAnchorType(QgsLabelLineSettings::AnchorType type)
Sets the line anchor type, which dictates how the lineAnchorPercent() setting is handled.
Definition: qgslabelfeature.h:478
QgsMargins
The QgsMargins class defines the four margins of a rectangle.
Definition: qgsmargins.h:38
QgsLabelFeature::setFixedPosition
void setFixedPosition(const QgsPointXY &point)
Sets coordinates of the fixed position (relevant only if hasFixedPosition() returns true)
Definition: qgslabelfeature.h:180
QgsLabelFeature::polygonPlacementFlags
QgsLabeling::PolygonPlacementFlags polygonPlacementFlags() const
Returns the polygon placement flags, which dictate how polygon labels can be placed.
Definition: qgslabelfeature.h:327
QgsLabelFeature::setLabelText
void setLabelText(const QString &text)
Sets text of the label.
Definition: qgslabelfeature.h:345
QgsLabelFeature::setHasFixedPosition
void setHasFixedPosition(bool enabled)
Sets whether the label should use a fixed position instead of being automatically placed.
Definition: qgslabelfeature.h:175
QgsLabelFeature::setLabelAllParts
void setLabelAllParts(bool labelAllParts)
Sets whether all parts of the feature should be labeled.
Definition: qgslabelfeature.h:492
QgsLabelFeature::layer
pal::Layer * layer() const
Gets PAL layer of the label feature. Should be only used internally in PAL.
Definition: qgslabelfeature.h:353
QgsLabelLineSettings::AnchorType::HintOnly
@ HintOnly
Line anchor is a hint for preferred placement only, but other placements close to the hint are permit...
QgsLabelLineSettings::AnchorType
AnchorType
Line anchor types.
Definition: qgslabellinesettings.h:57
QgsLabelFeature::alwaysShow
bool alwaysShow() const
Whether label should be always shown (sets very high label priority)
Definition: qgslabelfeature.h:304
QgsPointXY
A class to represent a 2D point.
Definition: qgspointxy.h:44
qgslabeling.h
QgsLabelFeature::setLineAnchorPercent
void setLineAnchorPercent(double percent)
Sets the percent along the line at which labels should be placed, for line labels only.
Definition: qgslabelfeature.h:459
QgsLabelFeature::zIndex
double zIndex() const
Returns the label's z-index.
Definition: qgslabelfeature.h:161
QgsLabelFeature::setSymbol
void setSymbol(const QgsSymbol *symbol)
Sets the feature symbol associated with this label.
Definition: qgslabelfeature.h:391
QgsLabelFeature::setQuadOffset
void setQuadOffset(QPointF quadOffset)
Set which side of the point to use.
Definition: qgslabelfeature.h:235
QgsLabelFeature::geometry
GEOSGeometry * geometry() const
Gets access to the associated geometry.
Definition: qgslabelfeature.h:69
QgsLabelFeature::quadOffset
QPointF quadOffset() const
Applies to "offset from point" placement strategy and "around point" (in case hasFixedQuadrant() retu...
Definition: qgslabelfeature.h:229
QgsGeometry
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:124
QgsLabelFeature::mSymbolSize
QSizeF mSymbolSize
Size of associated rendered symbol, if applicable.
Definition: qgslabelfeature.h:534
QgsLabelFeature::setCurvedLabelInfo
void setCurvedLabelInfo(pal::LabelInfo *info)
takes ownership of the instance
Definition: qgslabelfeature.h:350
QgsLabelFeature::setPolygonPlacementFlags
void setPolygonPlacementFlags(QgsLabeling::PolygonPlacementFlags flags)
Sets the polygon placement flags, which dictate how polygon labels can be placed.
Definition: qgslabelfeature.h:335
QgsLabelFeature::distLabel
double distLabel() const
Applies to "around point" placement strategy or linestring features.
Definition: qgslabelfeature.h:269
QgsLabelFeature::mPredefinedPositionOrder
QVector< QgsPalLayerSettings::PredefinedPointPosition > mPredefinedPositionOrder
Ordered list of predefined positions for label (only for OrderedPositionsAroundPoint placement)
Definition: qgslabelfeature.h:558
QgsLabelFeature::setLayer
void setLayer(pal::Layer *layer)
Assign PAL layer to the label feature. Should be only used internally in PAL.
Definition: qgslabelfeature.h:355
QgsLabelFeature::mFixedPosition
QgsPointXY mFixedPosition
fixed position for the label (instead of automatic placement)
Definition: qgslabelfeature.h:542
QgsLabelFeature::setFixedAngle
void setFixedAngle(double angle)
Sets angle in degrees of the fixed angle (relevant only if hasFixedAngle() returns true)
Definition: qgslabelfeature.h:205
QgsLabelFeature::fixedPosition
QgsPointXY fixedPosition() const
Coordinates of the fixed position (relevant only if hasFixedPosition() returns true)
Definition: qgslabelfeature.h:177
pal::Layer
A set of features which influence the labeling process.
Definition: layer.h:62
geos::prepared_unique_ptr
std::unique_ptr< const GEOSPreparedGeometry, GeosDeleter > prepared_unique_ptr
Scoped GEOS prepared geometry pointer.
Definition: qgsgeos.h:84
QgsLabelFeature::setOffsetType
void setOffsetType(QgsPalLayerSettings::OffsetType type)
Sets the offset type, which determines how offsets and distance to label behaves.
Definition: qgslabelfeature.h:263
QgsFeature
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:56
QgsLabelFeature::setVisualMargin
void setVisualMargin(const QgsMargins &margin)
Sets the visual margin for the label feature.
Definition: qgslabelfeature.h:113
QgsLabelFeature
The QgsLabelFeature class describes a feature that should be used within the labeling engine.
Definition: qgslabelfeature.h:57
QgsLabelFeature::setArrangementFlags
void setArrangementFlags(QgsLabeling::LinePlacementFlags flags)
Sets the feature's arrangement flags.
Definition: qgslabelfeature.h:319
QgsLabelFeature::mVisualMargin
QgsMargins mVisualMargin
Visual margin of label contents.
Definition: qgslabelfeature.h:532
QgsLabelFeature::curvedLabelInfo
pal::LabelInfo * curvedLabelInfo() const
Gets additional info required for curved label placement. Returns nullptr if not set.
Definition: qgslabelfeature.h:348
QgsLabelFeature::mPositionOffset
QgsPointXY mPositionOffset
offset of label from the feature (only for "offset from point" placement)
Definition: qgslabelfeature.h:552
MathUtils::angle
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:786
QgsLabelFeature::permissibleZone
QgsGeometry permissibleZone() const
Returns the label's permissible zone geometry.
Definition: qgslabelfeature.h:90
QgsLabelFeature::mRotatedSize
QSizeF mRotatedSize
Width and height of the label when rotated between 45 to 135 and 235 to 315 degrees;.
Definition: qgslabelfeature.h:530
QgsLabelFeature::predefinedPositionOrder
QVector< QgsPalLayerSettings::PredefinedPointPosition > predefinedPositionOrder() const
Returns the priority ordered list of predefined positions for label candidates.
Definition: qgslabelfeature.h:282
QgsLabelFeature::labelText
QString labelText() const
Text of the label.
Definition: qgslabelfeature.h:343
qgsgeos.h
QgsLabelFeature::mGeometry
geos::unique_ptr mGeometry
Geometry of the feature to be labelled.
Definition: qgslabelfeature.h:524
QgsLabelFeature::setAlwaysShow
void setAlwaysShow(bool enabled)
Sets whether label should be always shown (sets very high label priority)
Definition: qgslabelfeature.h:306
QgsFeatureId
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
Definition: qgsfeatureid.h:28
qgslabelobstaclesettings.h
qgsmargins.h