QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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  delete mInfo;
36 }
37 
39 {
41 
42  if ( mPermissibleZoneGeosPrepared )
43  {
44  mPermissibleZoneGeosPrepared.reset();
45  mPermissibleZoneGeos.reset();
46  mPermissibleZoneGeosPrepared = nullptr;
47  }
48 
49  if ( mPermissibleZone.isNull() )
50  return;
51 
52  mPermissibleZoneGeos = QgsGeos::asGeos( mPermissibleZone );
53  if ( !mPermissibleZoneGeos )
54  return;
55 
56  mPermissibleZoneGeosPrepared.reset( GEOSPrepare_r( QgsGeos::getGEOSHandler(), mPermissibleZoneGeos.get() ) );
57 }
58 
60 {
61  return mFeature;
62 }
63 
64 QSizeF QgsLabelFeature::size( double angle ) const
65 {
66  if ( mRotatedSize.isEmpty() )
67  return mSize;
68 
69  // Between 45 to 135 and 235 to 315 degrees, return the rotated size
70  return ( angle >= 0.785398 && angle <= 2.35619 ) || ( angle >= 3.92699 && angle <= 5.49779 ) ? mRotatedSize : mSize;
71 }
72 
74 {
75  return mAnchorPosition;
76 }
77 
79 {
80  mFeature = feature;
81 }
82 
84 {
85  return mOverrunDistance;
86 }
87 
88 void QgsLabelFeature::setOverrunDistance( double overrunDistance )
89 {
91 }
92 
94 {
96 }
97 
98 void QgsLabelFeature::setOverrunSmoothDistance( double overrunSmoothDistance )
99 {
101 }
102 
104 {
105  return mObstacleSettings;
106 }
107 
109 {
110  mObstacleSettings = settings;
111 }
112 
113 void QgsLabelFeature::setAnchorPosition( const QgsPointXY &anchorPosition )
114 {
115  mAnchorPosition = anchorPosition;
116 }
QgsLabelFeature::mOverrunSmoothDistance
double mOverrunSmoothDistance
Distance to smooth angle of line start and end when calculating overruns.
Definition: qgslabelfeature.h:571
QgsGeometry::isNull
Q_GADGET bool isNull
Definition: qgsgeometry.h:126
qgslabelfeature.h
QgsLabelObstacleSettings
Contains settings related to how the label engine treats features as obstacles.
Definition: qgslabelobstaclesettings.h:35
QgsLabelFeature::mOverrunDistance
double mOverrunDistance
Distance to allow label to overrun linear features.
Definition: qgslabelfeature.h:569
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:526
feature.h
QgsLabelFeature::obstacleSettings
const QgsLabelObstacleSettings & obstacleSettings() const
Returns the label's obstacle settings.
Definition: qgslabelfeature.cpp:103
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:163
QgsLabelFeature::mSize
QSizeF mSize
Width and height of the label.
Definition: qgslabelfeature.h:528
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:83
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:88
QgsLabelFeature::setObstacleSettings
void setObstacleSettings(const QgsLabelObstacleSettings &settings)
Sets the label's obstacle settings.
Definition: qgslabelfeature.cpp:108
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:98
QgsLabelFeature::setAnchorPosition
void setAnchorPosition(const QgsPointXY &anchorPosition)
In case of quadrand or aligned positioning, this is set to the anchor point.
Definition: qgslabelfeature.cpp:113
QgsLabelFeature::feature
QgsFeature feature() const
Returns the original feature associated with this label.
Definition: qgslabelfeature.cpp:59
QgsGeos::getGEOSHandler
static GEOSContextHandle_t getGEOSHandler()
Definition: qgsgeos.cpp:2888
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:38
QgsPointXY
A class to represent a 2D point.
Definition: qgspointxy.h:44
qgsgeometry.h
QgsLabelFeature::size
QSizeF size(double angle=0.0) const
Size of the label (in map units)
Definition: qgslabelfeature.cpp:64
QgsLabelFeature::geometry
GEOSGeometry * geometry() const
Gets access to the associated geometry.
Definition: qgslabelfeature.h:69
QgsGeometry
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:124
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:93
QgsLabelFeature::anchorPosition
QgsPointXY anchorPosition() const
In case of quadrand or aligned positioning, this is set to the anchor point.
Definition: qgslabelfeature.cpp:73
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 id, geometry and a list of field/values...
Definition: qgsfeature.h:56
QgsLabelFeature::mInfo
pal::LabelInfo * mInfo
extra information for curved labels (may be nullptr)
Definition: qgslabelfeature.h:566
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:530
QgsLabelFeature::setFeature
void setFeature(const QgsFeature &feature)
Sets the original feature associated with this label.
Definition: qgslabelfeature.cpp:78
qgsgeos.h
QgsFeatureId
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
Definition: qgsfeatureid.h:28