QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 
18 
19 QgsLabelFeature::QgsLabelFeature( QgsFeatureId id, GEOSGeometry* geometry, QSizeF size )
20  : mLayer( nullptr )
21  , mId( id )
22  , mGeometry( geometry )
23  , mObstacleGeometry( nullptr )
24  , mSize( size )
25  , mPriority( -1 )
26  , mZIndex( 0 )
27  , mHasFixedPosition( false )
28  , mHasFixedAngle( false )
29  , mFixedAngle( 0 )
30  , mHasFixedQuadrant( false )
31  , mDistLabel( 0 )
32  , mOffsetType( QgsPalLayerSettings::FromPoint )
33  , mRepeatDistance( 0 )
34  , mAlwaysShow( false )
35  , mIsObstacle( false )
36  , mObstacleFactor( 1 )
37  , mInfo( nullptr )
38  , mPermissibleZoneGeosPrepared( nullptr )
39 {
40 }
41 
43 {
44  if ( mGeometry )
45  GEOSGeom_destroy_r( QgsGeometry::getGEOSHandler(), mGeometry );
46 
47  if ( mObstacleGeometry )
48  GEOSGeom_destroy_r( QgsGeometry::getGEOSHandler(), mObstacleGeometry );
49 
50  if ( mPermissibleZoneGeosPrepared )
51  GEOSPreparedGeom_destroy_r( QgsGeometry::getGEOSHandler(), mPermissibleZoneGeosPrepared );
52 
53  delete mInfo;
54 }
55 
56 void QgsLabelFeature::setObstacleGeometry( GEOSGeometry* obstacleGeom )
57 {
58  if ( mObstacleGeometry )
59  GEOSGeom_destroy_r( QgsGeometry::getGEOSHandler(), mObstacleGeometry );
60 
61  mObstacleGeometry = obstacleGeom;
62 }
63 
65 {
67 
68  if ( mPermissibleZoneGeosPrepared )
69  {
70  GEOSPreparedGeom_destroy_r( QgsGeometry::getGEOSHandler(), mPermissibleZoneGeosPrepared );
71  mPermissibleZoneGeosPrepared = nullptr;
72  }
73 
74  if ( mPermissibleZone.isEmpty() )
75  return;
76 
77  const GEOSGeometry* zoneGeos = mPermissibleZone.asGeos();
78  if ( !zoneGeos )
79  return;
80 
81  mPermissibleZoneGeosPrepared = GEOSPrepare_r( QgsGeometry::getGEOSHandler(), zoneGeos );
82 }
virtual ~QgsLabelFeature()
Clean up geometry and curved label info (if present)
pal::LabelInfo * mInfo
extra information for curved labels (may be null)
QgsLabelFeature(QgsFeatureId id, GEOSGeometry *geometry, QSizeF size)
Create label feature, takes ownership of the geometry instance.
GEOSGeometry * geometry() const
Get access to the associated geometry.
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:76
GEOSGeometry * mObstacleGeometry
Optional geometry to use for label obstacles, if different to mGeometry.
void setPermissibleZone(const QgsGeometry &geometry)
Sets the label's permissible zone geometry.
GEOSGeometry * mGeometry
Geometry of the feature to be labelled.
bool isEmpty() const
Returns true if the geometry is empty (ie, contains no underlying geometry accessible via geometry)...
static GEOSContextHandle_t getGEOSHandler()
Return GEOS context handle.
const GEOSGeometry * asGeos(double precision=0) const
Returns a geos geometry.
void setObstacleGeometry(GEOSGeometry *obstacleGeom)
Sets the label's obstacle geometry, if different to the feature geometry.
qint64 QgsFeatureId
Definition: qgsfeature.h:31
QgsGeometry mPermissibleZone
Optional geometry to use for label's permissible zone.