QGIS API Documentation  3.27.0-Master (597e8eebd4)
qgslabelfeature.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgslabelfeature.cpp
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 #include "qgslabelfeature.h"
16 #include "feature.h"
17 #include "qgsgeometry.h"
18 #include "qgsgeos.h"
19 
21  : mId( id )
22  , mGeometry( std::move( geometry ) )
23  , mSize( size )
24 {
25 }
26 
28 {
29  if ( mPermissibleZoneGeosPrepared )
30  {
31  mPermissibleZoneGeosPrepared.reset();
32  mPermissibleZoneGeos.reset();
33  }
34 }
35 
37 {
39 
40  if ( mPermissibleZoneGeosPrepared )
41  {
42  mPermissibleZoneGeosPrepared.reset();
43  mPermissibleZoneGeos.reset();
44  mPermissibleZoneGeosPrepared = nullptr;
45  }
46 
47  if ( mPermissibleZone.isNull() )
48  return;
49 
50  mPermissibleZoneGeos = QgsGeos::asGeos( mPermissibleZone );
51  if ( !mPermissibleZoneGeos )
52  return;
53 
54  mPermissibleZoneGeosPrepared.reset( GEOSPrepare_r( QgsGeos::getGEOSHandler(), mPermissibleZoneGeos.get() ) );
55 }
56 
58 {
59  return mFeature;
60 }
61 
62 QSizeF QgsLabelFeature::size( double angle ) const
63 {
64  if ( mRotatedSize.isEmpty() )
65  return mSize;
66 
67  // Between 45 to 135 and 235 to 315 degrees, return the rotated size
68  return ( angle >= 0.785398 && angle <= 2.35619 ) || ( angle >= 3.92699 && angle <= 5.49779 ) ? mRotatedSize : mSize;
69 }
70 
72 {
73  return mAnchorPosition;
74 }
75 
77 {
78  mFeature = feature;
79 }
80 
82 {
83  return mOverrunDistance;
84 }
85 
86 void QgsLabelFeature::setOverrunDistance( double overrunDistance )
87 {
89 }
90 
92 {
94 }
95 
96 void QgsLabelFeature::setOverrunSmoothDistance( double overrunSmoothDistance )
97 {
99 }
100 
102 {
104  {
105  if ( mLineAnchorPercent < 0.25 )
107  else if ( mLineAnchorPercent > 0.75 )
109  else
111  }
112  else
113  {
114  return mAnchorTextPoint;
115  }
116 }
117 
119 {
120  return mObstacleSettings;
121 }
122 
124 {
125  mObstacleSettings = settings;
126 }
127 
129 {
130  return mOriginalFeatureCrs;
131 }
132 
134 {
135  mOriginalFeatureCrs = originalFeatureCrs;
136 }
137 
138 void QgsLabelFeature::setAnchorPosition( const QgsPointXY &anchorPosition )
139 {
140  mAnchorPosition = anchorPosition;
141 }
This class 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:56
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:125
Q_GADGET bool isNull
Definition: qgsgeometry.h:127
static geos::unique_ptr asGeos(const QgsGeometry &geometry, double precision=0)
Returns a geos geometry - caller takes ownership of the object (should be deleted with GEOSGeom_destr...
Definition: qgsgeos.cpp:181
static GEOSContextHandle_t getGEOSHandler()
Definition: qgsgeos.cpp:3369
void setOriginalFeatureCrs(const QgsCoordinateReferenceSystem &crs)
Sets the original layer crs of the feature associated with the label.
QSizeF mRotatedSize
Width and height of the label when rotated between 45 to 135 and 235 to 315 degrees;.
double overrunSmoothDistance() const
Returns the distance (in map units) with which the ends of linear features are averaged over when cal...
const QgsLabelObstacleSettings & obstacleSettings() const
Returns the label's obstacle settings.
QgsLabelFeature(QgsFeatureId id, geos::unique_ptr geometry, QSizeF size)
Create label feature, takes ownership of the geometry instance.
QSizeF size(double angle=0.0) const
Size of the label (in map units)
QgsPointXY anchorPosition() const
In case of quadrand or aligned positioning, this is set to the anchor point.
virtual ~QgsLabelFeature()
Clean up geometry and curved label info (if present)
void setFeature(const QgsFeature &feature)
Sets the original feature associated with this label.
void setPermissibleZone(const QgsGeometry &geometry)
Sets the label's permissible zone geometry.
QgsCoordinateReferenceSystem originalFeatureCrs() const
Returns the original layer CRS of the feature associated with the label.
void setObstacleSettings(const QgsLabelObstacleSettings &settings)
Sets the label's obstacle settings.
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 setAnchorPosition(const QgsPointXY &anchorPosition)
In case of quadrand or aligned positioning, this is set to the anchor point.
QgsFeature feature() const
Returns the original feature associated with this label.
double overrunDistance() const
Returns the permissible distance (in map units) which labels are allowed to overrun the start or end ...
QSizeF mSize
Width and height of the label.
void setOverrunDistance(double distance)
Sets the permissible distance (in map units) which labels are allowed to overrun the start or end of ...
QgsLabelLineSettings::AnchorTextPoint lineAnchorTextPoint() const
Returns the line anchor text point, which dictates which part of the label text should be placed at t...
GEOSGeometry * geometry() const
Gets access to the associated geometry.
void setOverrunSmoothDistance(double distance)
Sets the distance (in map units) with which the ends of linear features are averaged over when calcul...
double mOverrunDistance
Distance to allow label to overrun linear features.
AnchorTextPoint
Anchor point of label text.
@ EndOfText
Anchor using end of text.
@ StartOfText
Anchor using start of text.
@ CenterOfText
Anchor using center of text.
@ FollowPlacement
Automatically set the anchor point based on the lineAnchorPercent() value. Values <25% will use the s...
Contains settings related to how the label engine treats features as obstacles.
A class to represent a 2D point.
Definition: qgspointxy.h:59
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
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
Definition: qgsgeos.h:79
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
Definition: qgsfeatureid.h:28