QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
qgslabelfeature.h
Go to the documentation of this file.
1 #ifndef QGSLABELFEATURE_H
2 #define QGSLABELFEATURE_H
3 
4 #include "qgsgeometry.h"
5 
6 #include "qgspallabeling.h"
7 
8 namespace pal
9 {
10  class LabelInfo;
11 }
12 
14 class QgsRenderContext;
15 class QgsGeometry;
16 
17 
34 class CORE_EXPORT QgsLabelFeature
35 {
36  public:
37 
40  struct VisualMargin
41  {
45  : left( 0.0 )
46  , right( 0.0 )
47  , top( 0.0 )
48  , bottom( 0.0 )
49  {}
50 
57  VisualMargin( double top, double right, double bottom, double left )
58  : left( left )
59  , right( right )
60  , top( top )
61  , bottom( bottom )
62  {}
63 
65  double left;
67  double right;
69  double top;
71  double bottom;
72 
73  VisualMargin& operator *=( double value )
74  {
75  left *= value;
76  right *= value;
77  top *= value;
78  bottom *= value;
79  return *this;
80  }
81  };
82 
84  QgsLabelFeature( QgsFeatureId id, GEOSGeometry* geometry, QSizeF size );
86  virtual ~QgsLabelFeature();
87 
89  QgsFeatureId id() const { return mId; }
90 
92  GEOSGeometry* geometry() const { return mGeometry; }
93 
102  void setObstacleGeometry( GEOSGeometry* obstacleGeom );
103 
108  GEOSGeometry* obstacleGeometry() const { return mObstacleGeometry; }
109 
118  void setPermissibleZone( const QgsGeometry& geometry );
119 
127  QgsGeometry permissibleZone() const { return mPermissibleZone; }
128 
133  //TODO - remove when QgsGeometry caches GEOS preparedness
134  const GEOSPreparedGeometry* permissibleZonePrepared() const { return mPermissibleZoneGeosPrepared; }
135 
137  QSizeF size() const { return mSize; }
138 
148  void setVisualMargin( const VisualMargin& margin ) { mVisualMargin = margin; }
149 
153  const VisualMargin& visualMargin() const { return mVisualMargin; }
154 
160  void setSymbolSize( QSizeF size ) { mSymbolSize = size; }
161 
168  const QSizeF& symbolSize() const { return mSymbolSize; }
169 
175  double priority() const { return mPriority; }
182  void setPriority( double priority ) { mPriority = priority; }
183 
189  double zIndex() const { return mZIndex; }
190 
197  void setZIndex( double zIndex ) { mZIndex = zIndex; }
198 
200  bool hasFixedPosition() const { return mHasFixedPosition; }
202  void setHasFixedPosition( bool enabled ) { mHasFixedPosition = enabled; }
204  QgsPoint fixedPosition() const { return mFixedPosition; }
206  void setFixedPosition( const QgsPoint& point ) { mFixedPosition = point; }
207 
209  bool hasFixedAngle() const { return mHasFixedAngle; }
211  void setHasFixedAngle( bool enabled ) { mHasFixedAngle = enabled; }
213  double fixedAngle() const { return mFixedAngle; }
215  void setFixedAngle( double angle ) { mFixedAngle = angle; }
216 
222  bool hasFixedQuadrant() const { return mHasFixedQuadrant; }
228  void setHasFixedQuadrant( bool enabled ) { mHasFixedQuadrant = enabled; }
233  QPointF quadOffset() const { return mQuadOffset; }
236  void setQuadOffset( QPointF quadOffset ) { mQuadOffset = quadOffset; }
239  QgsPoint positionOffset() const { return mPositionOffset; }
242  void setPositionOffset( const QgsPoint& offset ) { mPositionOffset = offset; }
243 
249  QgsPalLayerSettings::OffsetType offsetType() const { return mOffsetType; }
250 
256  void setOffsetType( QgsPalLayerSettings::OffsetType type ) { mOffsetType = type; }
257 
260  double distLabel() const { return mDistLabel; }
263  void setDistLabel( double dist ) { mDistLabel = dist; }
264 
270 
275  void setPredefinedPositionOrder( const QVector< QgsPalLayerSettings::PredefinedPointPosition >& order ) { mPredefinedPositionOrder = order; }
276 
279  double repeatDistance() const { return mRepeatDistance; }
282  void setRepeatDistance( double dist ) { mRepeatDistance = dist; }
283 
285  bool alwaysShow() const { return mAlwaysShow; }
287  void setAlwaysShow( bool enabled ) { mAlwaysShow = enabled; }
288 
293  bool isObstacle() const { return mIsObstacle; }
298  void setIsObstacle( bool enabled ) { mIsObstacle = enabled; }
303  double obstacleFactor() const { return mObstacleFactor; }
311  void setObstacleFactor( double factor ) { mObstacleFactor = factor; }
312 
318  QString labelText() const { return mLabelText; }
320  void setLabelText( const QString& text ) { mLabelText = text; }
321 
323  pal::LabelInfo* curvedLabelInfo() const { return mInfo; }
325  void setCurvedLabelInfo( pal::LabelInfo* info ) { mInfo = info; }
326 
328  pal::Layer* layer() const { return mLayer; }
330  void setLayer( pal::Layer* layer ) { mLayer = layer; }
331 
333  QgsAbstractLabelProvider* provider() const;
334 
335  protected:
338 
342  GEOSGeometry* mGeometry;
344  GEOSGeometry* mObstacleGeometry;
354  double mPriority;
356  double mZIndex;
364  double mFixedAngle;
372  double mDistLabel;
389 
390  private:
391 
392  // TODO - not required when QgsGeometry caches geos preparedness
393  const GEOSPreparedGeometry* mPermissibleZoneGeosPrepared;
394 
395 };
396 
397 #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.
double priority() const
Returns the feature&#39;s labeling priority.
bool alwaysShow() const
Whether label should be always shown (sets very high label priority)
QgsPoint positionOffset() const
Applies only to "offset from point" placement strategy.
A set of features which influence the labelling process.
Definition: layer.h:58
QString mLabelText
text of the label
const GEOSPreparedGeometry * permissibleZonePrepared() const
Returns a GEOS prepared geometry representing the label&#39;s permissibleZone().
pal::LabelInfo * mInfo
extra information for curved labels (may be null)
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:76
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.
QgsPoint fixedPosition() const
Coordinates of the fixed position (relevant only if hasFixedPosition() returns true) ...
void setFixedPosition(const QgsPoint &point)
Set coordinates of the fixed position (relevant only if hasFixedPosition() returns true) ...
QgsPoint mFixedPosition
fixed position for the label (instead of automatic placement)
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
GEOSGeometry * mObstacleGeometry
Optional geometry to use for label obstacles, if different to mGeometry.
void setHasFixedPosition(bool enabled)
Set whether the label should use a fixed position instead of being automatically placed.
QSizeF mSize
Width and height of the label.
double mFixedAngle
fixed rotation for the label (instead of automatic choice)
VisualMargin()
Default constructor, all margins are set to 0.0.
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.
double bottom
Bottom margin.
Optional additional info about label (for curved labels)
Definition: feature.h:52
void setFixedAngle(double angle)
Set angle in degrees of the fixed angle (relevant only if hasFixedAngle() returns true) ...
GEOSGeometry * mGeometry
Geometry of the feature to be labelled.
void setVisualMargin(const VisualMargin &margin)
Sets the visual margin for the label feature.
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
Behaviour 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
Stores visual margins for labels (left, right, top and bottom)
A class to represent a point.
Definition: qgspoint.h:117
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)
double ANALYSIS_EXPORT angle(Point3D *p1, Point3D *p2, Point3D *p3, Point3D *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
bool mHasFixedAngle
whether mFixedAngle should be respected
QPointF quadOffset() const
Applies to "offset from point" placement strategy and "around point" (in case hasFixedQuadrant() retu...
const VisualMargin & visualMargin() const
Returns the visual margin for the label feature.
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...
VisualMargin(double top, double right, double bottom, double left)
Constructor allowing margins to be specified.
double right
Right margin.
QgsPoint mPositionOffset
offset of label from the feature (only for "offset from point" placement)
VisualMargin mVisualMargin
Visual margin of label contents.
void setHasFixedQuadrant(bool enabled)
Sets whether the quadrant for the label must be respected.
qint64 QgsFeatureId
Definition: qgsfeature.h:31
pal::Layer * mLayer
Pointer to PAL layer (assigned when registered to PAL)
void setPositionOffset(const QgsPoint &offset)
Applies only to "offset from point" placement strategy.
QgsGeometry mPermissibleZone
Optional geometry to use for label&#39;s permissible zone.
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.
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)