QGIS API Documentation  3.0.2-Girona (307d082)
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 "qgsmargins.h"
24 
25 namespace pal
26 {
27  class LabelInfo;
28 }
29 
31 class QgsRenderContext;
32 class QgsGeometry;
33 
34 
52 class CORE_EXPORT QgsLabelFeature
53 {
54  public:
55 
57  QgsLabelFeature( QgsFeatureId id, GEOSGeometry *geometry, QSizeF size );
59  virtual ~QgsLabelFeature();
60 
62  QgsFeatureId id() const { return mId; }
63 
65  GEOSGeometry *geometry() const { return mGeometry; }
66 
76  void setObstacleGeometry( GEOSGeometry *obstacleGeom );
77 
83  GEOSGeometry *obstacleGeometry() const { return mObstacleGeometry; }
84 
94  void setPermissibleZone( const QgsGeometry &geometry );
95 
104  QgsGeometry permissibleZone() const { return mPermissibleZone; }
105 
111  //TODO - remove when QgsGeometry caches GEOS preparedness
112  const GEOSPreparedGeometry *permissibleZonePrepared() const { return mPermissibleZoneGeosPrepared; }
113 
115  QSizeF size() const { return mSize; }
116 
127  void setVisualMargin( const QgsMargins &margin ) { mVisualMargin = margin; }
128 
133  const QgsMargins &visualMargin() const { return mVisualMargin; }
134 
141  void setSymbolSize( QSizeF size ) { mSymbolSize = size; }
142 
150  const QSizeF &symbolSize() const { return mSymbolSize; }
151 
158  double priority() const { return mPriority; }
159 
167  void setPriority( double priority ) { mPriority = priority; }
168 
175  double zIndex() const { return mZIndex; }
176 
184  void setZIndex( double zIndex ) { mZIndex = zIndex; }
185 
187  bool hasFixedPosition() const { return mHasFixedPosition; }
189  void setHasFixedPosition( bool enabled ) { mHasFixedPosition = enabled; }
191  QgsPointXY fixedPosition() const { return mFixedPosition; }
193  void setFixedPosition( const QgsPointXY &point ) { mFixedPosition = point; }
194 
196  bool hasFixedAngle() const { return mHasFixedAngle; }
198  void setHasFixedAngle( bool enabled ) { mHasFixedAngle = enabled; }
200  double fixedAngle() const { return mFixedAngle; }
202  void setFixedAngle( double angle ) { mFixedAngle = angle; }
203 
210  bool hasFixedQuadrant() const { return mHasFixedQuadrant; }
211 
218  void setHasFixedQuadrant( bool enabled ) { mHasFixedQuadrant = enabled; }
219 
226  QPointF quadOffset() const { return mQuadOffset; }
227 
232  void setQuadOffset( QPointF quadOffset ) { mQuadOffset = quadOffset; }
233 
238  QgsPointXY positionOffset() const { return mPositionOffset; }
239 
244  void setPositionOffset( const QgsPointXY &offset ) { mPositionOffset = offset; }
245 
252  QgsPalLayerSettings::OffsetType offsetType() const { return mOffsetType; }
253 
260  void setOffsetType( QgsPalLayerSettings::OffsetType type ) { mOffsetType = type; }
261 
266  double distLabel() const { return mDistLabel; }
267 
272  void setDistLabel( double dist ) { mDistLabel = dist; }
273 
279  QVector< QgsPalLayerSettings::PredefinedPointPosition > predefinedPositionOrder() const { return mPredefinedPositionOrder; }
280 
286  void setPredefinedPositionOrder( const QVector< QgsPalLayerSettings::PredefinedPointPosition > &order ) { mPredefinedPositionOrder = order; }
287 
292  double repeatDistance() const { return mRepeatDistance; }
293 
298  void setRepeatDistance( double dist ) { mRepeatDistance = dist; }
299 
301  bool alwaysShow() const { return mAlwaysShow; }
303  void setAlwaysShow( bool enabled ) { mAlwaysShow = enabled; }
304 
310  bool isObstacle() const { return mIsObstacle; }
311 
317  void setIsObstacle( bool enabled ) { mIsObstacle = enabled; }
318 
324  double obstacleFactor() const { return mObstacleFactor; }
325 
334  void setObstacleFactor( double factor ) { mObstacleFactor = factor; }
335 
342  QString labelText() const { return mLabelText; }
344  void setLabelText( const QString &text ) { mLabelText = text; }
345 
347  pal::LabelInfo *curvedLabelInfo() const { return mInfo; }
349  void setCurvedLabelInfo( pal::LabelInfo *info ) { mInfo = info; }
350 
352  pal::Layer *layer() const { return mLayer; }
354  void setLayer( pal::Layer *layer ) { mLayer = layer; }
355 
357  QgsAbstractLabelProvider *provider() const;
358 
359  protected:
361  pal::Layer *mLayer = nullptr;
362 
366  GEOSGeometry *mGeometry = nullptr;
368  GEOSGeometry *mObstacleGeometry = nullptr;
372  QSizeF mSize;
376  QSizeF mSymbolSize;
378  double mPriority;
380  double mZIndex;
388  double mFixedAngle;
392  QPointF mQuadOffset;
396  double mDistLabel;
400  QVector< QgsPalLayerSettings::PredefinedPointPosition > mPredefinedPositionOrder;
410  QString mLabelText;
412  pal::LabelInfo *mInfo = nullptr;
413 
414  private:
415 
417  GEOSGeometry *mPermissibleZoneGeos = nullptr;
418 
419  // TODO - not required when QgsGeometry caches geos preparedness
420  const GEOSPreparedGeometry *mPermissibleZoneGeosPrepared = nullptr;
421 
422 };
423 
424 #endif // QGSLABELFEATURE_H
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.
QgsPointXY mFixedPosition
fixed position for the label (instead of automatic placement)
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)
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
QgsMargins mVisualMargin
Visual margin of label contents.
const GEOSPreparedGeometry * permissibleZonePrepared() const
Returns a GEOS prepared geometry representing the label&#39;s permissibleZone().
bool mIsObstacle
whether the feature geometry acts as an obstacle for labels
GEOSGeometry * geometry() const
Get 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:111
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.
const QgsMargins & visualMargin() const
Returns the visual margin for the label feature.
void setAlwaysShow(bool enabled)
Set whether label should be always shown (sets very high label priority)
void setLabelText(const QString &text)
Set 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)
Set 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.
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
Get additional infor required for curved label placement. Returns null 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 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.
Optional additional info about label (for curved labels)
Definition: feature.h:55
void setFixedAngle(double angle)
Set 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::Layer * layer() const
Get 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...
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...
QSizeF size() const
Size of the label (in map units)
QgsPointXY mPositionOffset
offset of label from the feature (only for "offset from point" placement)
void setFixedPosition(const QgsPointXY &point)
Set 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.
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)
Set 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.
qint64 QgsFeatureId
Definition: qgsfeature.h:37
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) ...
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)