QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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"
25 #include "pal.h"
26 
27 namespace pal
28 {
29  class LabelInfo;
30 }
31 
33 class QgsRenderContext;
34 class QgsGeometry;
35 
36 
54 class CORE_EXPORT QgsLabelFeature
55 {
56  public:
57 
59  QgsLabelFeature( QgsFeatureId id, geos::unique_ptr geometry, QSizeF size );
61  virtual ~QgsLabelFeature();
62 
64  QgsFeatureId id() const { return mId; }
65 
67  GEOSGeometry *geometry() const { return mGeometry.get(); }
68 
78  void setObstacleGeometry( geos::unique_ptr obstacleGeom );
79 
85  GEOSGeometry *obstacleGeometry() const { return mObstacleGeometry.get(); }
86 
96  void setPermissibleZone( const QgsGeometry &geometry );
97 
106  QgsGeometry permissibleZone() const { return mPermissibleZone; }
107 
113  //TODO - remove when QgsGeometry caches GEOS preparedness
114  const GEOSPreparedGeometry *permissibleZonePrepared() const { return mPermissibleZoneGeosPrepared.get(); }
115 
117  QSizeF size( double angle = 0.0 ) const;
118 
129  void setVisualMargin( const QgsMargins &margin ) { mVisualMargin = margin; }
130 
135  const QgsMargins &visualMargin() const { return mVisualMargin; }
136 
143  void setSymbolSize( QSizeF size ) { mSymbolSize = size; }
144 
152  const QSizeF &symbolSize() const { return mSymbolSize; }
153 
160  double priority() const { return mPriority; }
161 
169  void setPriority( double priority ) { mPriority = priority; }
170 
177  double zIndex() const { return mZIndex; }
178 
186  void setZIndex( double zIndex ) { mZIndex = zIndex; }
187 
189  bool hasFixedPosition() const { return mHasFixedPosition; }
191  void setHasFixedPosition( bool enabled ) { mHasFixedPosition = enabled; }
193  QgsPointXY fixedPosition() const { return mFixedPosition; }
195  void setFixedPosition( const QgsPointXY &point ) { mFixedPosition = point; }
196 
198  bool hasFixedAngle() const { return mHasFixedAngle; }
200  void setHasFixedAngle( bool enabled ) { mHasFixedAngle = enabled; }
202  double fixedAngle() const { return mFixedAngle; }
204  void setFixedAngle( double angle ) { mFixedAngle = angle; }
205 
212  bool hasFixedQuadrant() const { return mHasFixedQuadrant; }
213 
220  void setHasFixedQuadrant( bool enabled ) { mHasFixedQuadrant = enabled; }
221 
228  QPointF quadOffset() const { return mQuadOffset; }
229 
234  void setQuadOffset( QPointF quadOffset ) { mQuadOffset = quadOffset; }
235 
240  QgsPointXY positionOffset() const { return mPositionOffset; }
241 
246  void setPositionOffset( const QgsPointXY &offset ) { mPositionOffset = offset; }
247 
254  QgsPalLayerSettings::OffsetType offsetType() const { return mOffsetType; }
255 
262  void setOffsetType( QgsPalLayerSettings::OffsetType type ) { mOffsetType = type; }
263 
268  double distLabel() const { return mDistLabel; }
269 
274  void setDistLabel( double dist ) { mDistLabel = dist; }
275 
281  QVector< QgsPalLayerSettings::PredefinedPointPosition > predefinedPositionOrder() const { return mPredefinedPositionOrder; }
282 
288  void setPredefinedPositionOrder( const QVector< QgsPalLayerSettings::PredefinedPointPosition > &order ) { mPredefinedPositionOrder = order; }
289 
294  double repeatDistance() const { return mRepeatDistance; }
295 
300  void setRepeatDistance( double dist ) { mRepeatDistance = dist; }
301 
303  bool alwaysShow() const { return mAlwaysShow; }
305  void setAlwaysShow( bool enabled ) { mAlwaysShow = enabled; }
306 
312  bool isObstacle() const { return mIsObstacle; }
313 
319  void setIsObstacle( bool enabled ) { mIsObstacle = enabled; }
320 
326  double obstacleFactor() const { return mObstacleFactor; }
327 
336  void setObstacleFactor( double factor ) { mObstacleFactor = factor; }
337 
342  pal::LineArrangementFlags arrangementFlags() const { return mArrangementFlags; }
343 
349  void setArrangementFlags( pal::LineArrangementFlags flags ) { mArrangementFlags = flags; }
350 
351 
358  QString labelText() const { return mLabelText; }
360  void setLabelText( const QString &text ) { mLabelText = text; }
361 
363  pal::LabelInfo *curvedLabelInfo() const { return mInfo; }
365  void setCurvedLabelInfo( pal::LabelInfo *info ) { mInfo = info; }
366 
368  pal::Layer *layer() const { return mLayer; }
370  void setLayer( pal::Layer *layer ) { mLayer = layer; }
371 
373  QgsAbstractLabelProvider *provider() const;
374 
381  QgsFeature feature() const;
382 
389  void setFeature( const QgsFeature &feature );
390 
397  const QgsSymbol *symbol() { return mSymbol; }
398 
406  void setSymbol( const QgsSymbol *symbol ) { mSymbol = symbol; }
407 
416  double overrunDistance() const;
417 
426  void setOverrunDistance( double distance );
427 
436  double overrunSmoothDistance() const;
437 
446  void setOverrunSmoothDistance( double distance );
447 
453  bool labelAllParts() const { return mLabelAllParts; }
454 
460  void setLabelAllParts( bool labelAllParts ) { mLabelAllParts = labelAllParts; }
461 
467  void setRotatedSize( QSizeF size ) { mRotatedSize = size; }
468 
469  protected:
471  pal::Layer *mLayer = nullptr;
472 
482  QSizeF mSize;
484  QSizeF mRotatedSize;
488  QSizeF mSymbolSize;
490  double mPriority;
492  double mZIndex;
500  double mFixedAngle;
504  QPointF mQuadOffset;
508  double mDistLabel;
512  QVector< QgsPalLayerSettings::PredefinedPointPosition > mPredefinedPositionOrder;
522  QString mLabelText;
524  pal::LabelInfo *mInfo = nullptr;
525 
527  double mOverrunDistance = 0;
529  double mOverrunSmoothDistance = 0;
530 
531  pal::LineArrangementFlags mArrangementFlags = nullptr;
532 
533  private:
534 
536  geos::unique_ptr mPermissibleZoneGeos;
537 
538  // TODO - not required when QgsGeometry caches geos preparedness
539  geos::prepared_unique_ptr mPermissibleZoneGeosPrepared;
540 
541  QgsFeature mFeature;
542 
543  const QgsSymbol *mSymbol = nullptr;
544 
545  bool mLabelAllParts = false;
546 
547 };
548 
549 #endif // QGSLABELFEATURE_H
void setSymbol(const QgsSymbol *symbol)
Sets the feature symbol associated with this label.
QString labelText() const
Text of the label.
double obstacleFactor() const
Returns the obstacle factor for the feature.
double distLabel() const
Applies to "around point" placement strategy or linestring features.
QgsFeatureId id() const
Identifier of the label (unique within the parent label provider)
void setSymbolSize(QSizeF size)
Sets the size of the rendered symbol associated with this feature.
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:61
QgsPointXY mFixedPosition
fixed position for the label (instead of automatic placement)
void setLabelAllParts(bool labelAllParts)
Sets whether all parts of the feature should be labeled.
double priority() const
Returns the feature&#39;s labeling priority.
void setVisualMargin(const QgsMargins &margin)
Sets the visual margin for the label feature.
bool alwaysShow() const
Whether label should be always shown (sets very high label priority)
std::unique_ptr< const GEOSPreparedGeometry, GeosDeleter > prepared_unique_ptr
Scoped GEOS prepared geometry pointer.
Definition: qgsgeos.h:84
A set of features which influence the labeling process.
Definition: layer.h:63
A class to represent a 2D point.
Definition: qgspointxy.h:43
QString mLabelText
text of the label
const QgsSymbol * symbol()
Returns the feature symbol associated with this label.
QgsMargins mVisualMargin
Visual margin of label contents.
const GEOSPreparedGeometry * permissibleZonePrepared() const
Returns a GEOS prepared geometry representing the label&#39;s permissibleZone().
qint64 QgsFeatureId
Definition: qgsfeatureid.h:25
bool mIsObstacle
whether the feature geometry acts as an obstacle for labels
GEOSGeometry * geometry() const
Gets access to the associated geometry.
void setObstacleFactor(double factor)
Sets the obstacle factor for the feature.
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:122
const QSizeF & symbolSize() const
Returns the size of the rendered symbol associated with this feature, if applicable.
void setCurvedLabelInfo(pal::LabelInfo *info)
takes ownership of the instance
bool mHasFixedQuadrant
whether mQuadOffset should be respected (only for "around point" placement)
bool isObstacle() const
Returns whether the feature will act as an obstacle for labels.
double mRepeatDistance
distance after which label should be repeated (only for linestrings)
double mObstacleFactor
how strong is the geometry acting as obstacle
QgsFeatureId mId
Associated ID unique within the parent label provider.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:55
const QgsMargins & visualMargin() const
Returns the visual margin for the label feature.
void setAlwaysShow(bool enabled)
Sets whether label should be always shown (sets very high label priority)
void setLabelText(const QString &text)
Sets text of the label.
bool mHasFixedPosition
whether mFixedPosition should be respected
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
QgsPointXY positionOffset() const
Applies only to "offset from point" placement strategy.
void setHasFixedPosition(bool enabled)
Sets whether the label should use a fixed position instead of being automatically placed...
void setPositionOffset(const QgsPointXY &offset)
Applies only to "offset from point" placement strategy.
QSizeF mSize
Width and height of the label.
geos::unique_ptr mObstacleGeometry
Optional geometry to use for label obstacles, if different to mGeometry.
double mFixedAngle
fixed rotation for the label (instead of automatic choice)
double zIndex() const
Returns the label&#39;s z-index.
pal::LabelInfo * curvedLabelInfo() const
Gets additional infor required for curved label placement. Returns nullptr if not set...
void setIsObstacle(bool enabled)
Sets whether the feature will act as an obstacle for labels.
void setZIndex(double zIndex)
Sets the label&#39;s z-index.
bool hasFixedQuadrant() const
Returns whether the quadrant for the label is fixed.
QgsGeometry permissibleZone() const
Returns the label&#39;s permissible zone geometry.
QSizeF mRotatedSize
Width and height of the label when rotated between 45 to 135 and 235 to 315 degrees;.
QSizeF mSymbolSize
Size of associated rendered symbol, if applicable.
QVector< QgsPalLayerSettings::PredefinedPointPosition > mPredefinedPositionOrder
Ordered list of predefined positions for label (only for OrderedPositionsAroundPoint placement) ...
void setLayer(pal::Layer *layer)
Assign PAL layer to the label feature. Should be only used internally in PAL.
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
Definition: qgsgeos.h:79
Optional additional info about label (for curved labels)
Definition: feature.h:55
void setFixedAngle(double angle)
Sets angle in degrees of the fixed angle (relevant only if hasFixedAngle() returns true) ...
bool hasFixedAngle() const
Whether the label should use a fixed angle instead of using angle from automatic placement.
pal::LineArrangementFlags arrangementFlags() const
Returns the feature&#39;s arrangement flags.
pal::Layer * layer() const
Gets PAL layer of the label feature. Should be only used internally in PAL.
OffsetType
Behavior modifier for label offset and distance, only applies in some label placement modes...
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...
double fixedAngle() const
Angle in degrees of the fixed angle (relevant only if hasFixedAngle() returns true) ...
void setPredefinedPositionOrder(const QVector< QgsPalLayerSettings::PredefinedPointPosition > &order)
Sets the priority ordered list of predefined positions for label candidates.
void setOffsetType(QgsPalLayerSettings::OffsetType type)
Sets the offset type, which determines how offsets and distance to label behaves. ...
void setDistLabel(double dist)
Applies to "around point" placement strategy or linestring features.
bool mAlwaysShow
whether to always show label - even in case of collisions
The QgsAbstractLabelProvider class is an interface class.
double repeatDistance() const
Applies only to linestring features - after what distance (in map units) the labels should be repeate...
QgsPointXY mPositionOffset
offset of label from the feature (only for "offset from point" placement)
void setFixedPosition(const QgsPointXY &point)
Sets coordinates of the fixed position (relevant only if hasFixedPosition() returns true) ...
bool mHasFixedAngle
whether mFixedAngle should be respected
QPointF quadOffset() const
Applies to "offset from point" placement strategy and "around point" (in case hasFixedQuadrant() retu...
Contains information about the context of a rendering operation.
bool hasFixedPosition() const
Whether the label should use a fixed position instead of being automatically placed.
geos::unique_ptr mGeometry
Geometry of the feature to be labelled.
The QgsLabelFeature class describes a feature that should be used within the labeling engine...
double mPriority
Priority of the label.
GEOSGeometry * obstacleGeometry() const
Returns the label&#39;s obstacle geometry, if different to the feature geometry.
QgsPalLayerSettings::OffsetType offsetType() const
Returns the offset type, which determines how offsets and distance to label behaves.
void setHasFixedAngle(bool enabled)
Sets whether the label should use a fixed angle instead of using angle from automatic placement...
void setRepeatDistance(double dist)
Applies only to linestring features - set after what distance (in map units) the labels should be rep...
void setHasFixedQuadrant(bool enabled)
Sets whether the quadrant for the label must be respected.
QgsGeometry mPermissibleZone
Optional geometry to use for label&#39;s permissible zone.
QgsPointXY fixedPosition() const
Coordinates of the fixed position (relevant only if hasFixedPosition() returns true) ...
double mDistLabel
distance of label from the feature (only for "around point" placement or linestrings) ...
QVector< QgsPalLayerSettings::PredefinedPointPosition > predefinedPositionOrder() const
Returns the priority ordered list of predefined positions for label candidates.
double mZIndex
Z-index of label (higher z-index labels are rendered on top of lower z-index labels) ...
void setArrangementFlags(pal::LineArrangementFlags flags)
Sets the feature&#39;s arrangement flags.
bool labelAllParts() const
Returns true if all parts of the feature should be labeled.
QgsPalLayerSettings::OffsetType mOffsetType
Offset type for certain placement modes.
The QgsMargins class defines the four margins of a rectangle.
Definition: qgsmargins.h:37
void setQuadOffset(QPointF quadOffset)
Set which side of the point to use.
void setPriority(double priority)
Sets the priority for labeling the feature.
QPointF mQuadOffset
whether the side of the label is fixed (only for "around point" placement)