QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 }
QgsLabelLineSettings::AnchorTextPoint::StartOfText
@ StartOfText
Anchor using start of text.
QgsLabelFeature::mOverrunSmoothDistance
double mOverrunSmoothDistance
Distance to smooth angle of line start and end when calculating overruns.
Definition: qgslabelfeature.h:658
QgsLabelFeature::lineAnchorTextPoint
QgsLabelLineSettings::AnchorTextPoint lineAnchorTextPoint() const
Returns the line anchor text point, which dictates which part of the label text should be placed at t...
Definition: qgslabelfeature.cpp:101
qgslabelfeature.h
QgsLabelObstacleSettings
Contains settings related to how the label engine treats features as obstacles.
Definition: qgslabelobstaclesettings.h:34
QgsLabelFeature::mOverrunDistance
double mOverrunDistance
Distance to allow label to overrun linear features.
Definition: qgslabelfeature.h:656
geos::unique_ptr
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
Definition: qgsgeos.h:79
QgsLabelFeature::mPermissibleZone
QgsGeometry mPermissibleZone
Optional geometry to use for label's permissible zone.
Definition: qgslabelfeature.h:615
feature.h
QgsLabelFeature::obstacleSettings
const QgsLabelObstacleSettings & obstacleSettings() const
Returns the label's obstacle settings.
Definition: qgslabelfeature.cpp:118
QgsGeos::asGeos
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
QgsLabelFeature::mSize
QSizeF mSize
Width and height of the label.
Definition: qgslabelfeature.h:617
QgsLabelLineSettings::AnchorTextPoint::EndOfText
@ EndOfText
Anchor using end of text.
QgsLabelFeature::overrunDistance
double overrunDistance() const
Returns the permissible distance (in map units) which labels are allowed to overrun the start or end ...
Definition: qgslabelfeature.cpp:81
QgsLabelFeature::setOverrunDistance
void setOverrunDistance(double distance)
Sets the permissible distance (in map units) which labels are allowed to overrun the start or end of ...
Definition: qgslabelfeature.cpp:86
QgsLabelFeature::setObstacleSettings
void setObstacleSettings(const QgsLabelObstacleSettings &settings)
Sets the label's obstacle settings.
Definition: qgslabelfeature.cpp:123
QgsLabelLineSettings::AnchorTextPoint::CenterOfText
@ CenterOfText
Anchor using center of text.
QgsLabelFeature::setOverrunSmoothDistance
void setOverrunSmoothDistance(double distance)
Sets the distance (in map units) with which the ends of linear features are averaged over when calcul...
Definition: qgslabelfeature.cpp:96
QgsLabelFeature::setAnchorPosition
void setAnchorPosition(const QgsPointXY &anchorPosition)
In case of quadrand or aligned positioning, this is set to the anchor point.
Definition: qgslabelfeature.cpp:138
QgsLabelFeature::feature
QgsFeature feature() const
Returns the original feature associated with this label.
Definition: qgslabelfeature.cpp:57
QgsGeometry::isNull
bool isNull
Definition: qgsgeometry.h:127
QgsLabelLineSettings::AnchorTextPoint
AnchorTextPoint
Anchor point of label text.
Definition: qgslabellinesettings.h:83
QgsCoordinateReferenceSystem
This class represents a coordinate reference system (CRS).
Definition: qgscoordinatereferencesystem.h:211
QgsGeos::getGEOSHandler
static GEOSContextHandle_t getGEOSHandler()
Definition: qgsgeos.cpp:3369
QgsLabelFeature::QgsLabelFeature
QgsLabelFeature(QgsFeatureId id, geos::unique_ptr geometry, QSizeF size)
Create label feature, takes ownership of the geometry instance.
Definition: qgslabelfeature.cpp:20
QgsLabelFeature::setPermissibleZone
void setPermissibleZone(const QgsGeometry &geometry)
Sets the label's permissible zone geometry.
Definition: qgslabelfeature.cpp:36
QgsPointXY
A class to represent a 2D point.
Definition: qgspointxy.h:58
qgsgeometry.h
QgsLabelFeature::size
QSizeF size(double angle=0.0) const
Size of the label (in map units)
Definition: qgslabelfeature.cpp:62
QgsLabelFeature::geometry
GEOSGeometry * geometry() const
Gets access to the associated geometry.
Definition: qgslabelfeature.h:70
QgsGeometry
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:124
QgsLabelFeature::originalFeatureCrs
QgsCoordinateReferenceSystem originalFeatureCrs() const
Returns the original layer CRS of the feature associated with the label.
Definition: qgslabelfeature.cpp:128
QgsLabelFeature::overrunSmoothDistance
double overrunSmoothDistance() const
Returns the distance (in map units) with which the ends of linear features are averaged over when cal...
Definition: qgslabelfeature.cpp:91
QgsLabelFeature::anchorPosition
QgsPointXY anchorPosition() const
In case of quadrand or aligned positioning, this is set to the anchor point.
Definition: qgslabelfeature.cpp:71
QgsLabelFeature::~QgsLabelFeature
virtual ~QgsLabelFeature()
Clean up geometry and curved label info (if present)
Definition: qgslabelfeature.cpp:27
QgsFeature
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:55
QgsLabelFeature::setOriginalFeatureCrs
void setOriginalFeatureCrs(const QgsCoordinateReferenceSystem &crs)
Sets the original layer crs of the feature associated with the label.
Definition: qgslabelfeature.cpp:133
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::mRotatedSize
QSizeF mRotatedSize
Width and height of the label when rotated between 45 to 135 and 235 to 315 degrees;.
Definition: qgslabelfeature.h:619
QgsLabelFeature::setFeature
void setFeature(const QgsFeature &feature)
Sets the original feature associated with this label.
Definition: qgslabelfeature.cpp:76
qgsgeos.h
QgsLabelLineSettings::AnchorTextPoint::FollowPlacement
@ FollowPlacement
Automatically set the anchor point based on the lineAnchorPercent() value. Values <25% will use the s...
QgsFeatureId
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
Definition: qgsfeatureid.h:28