QGIS API Documentation  3.0.2-Girona (307d082)
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 
19 QgsLabelFeature::QgsLabelFeature( QgsFeatureId id, GEOSGeometry *geometry, QSizeF size )
20  : mId( id )
21  , mGeometry( geometry )
22  , mSize( size )
23  , mPriority( -1 )
24  , mZIndex( 0 )
25  , mHasFixedPosition( false )
26  , mHasFixedAngle( false )
27  , mFixedAngle( 0 )
28  , mHasFixedQuadrant( false )
29  , mDistLabel( 0 )
30  , mOffsetType( QgsPalLayerSettings::FromPoint )
31  , mRepeatDistance( 0 )
32  , mAlwaysShow( false )
33  , mIsObstacle( false )
34  , mObstacleFactor( 1 )
35 {
36 }
37 
39 {
40  if ( mGeometry )
41  GEOSGeom_destroy_r( QgsGeometry::getGEOSHandler(), mGeometry );
42 
43  if ( mObstacleGeometry )
44  GEOSGeom_destroy_r( QgsGeometry::getGEOSHandler(), mObstacleGeometry );
45 
46  if ( mPermissibleZoneGeosPrepared )
47  {
48  GEOSPreparedGeom_destroy_r( QgsGeometry::getGEOSHandler(), mPermissibleZoneGeosPrepared );
49  GEOSGeom_destroy_r( QgsGeometry::getGEOSHandler(), mPermissibleZoneGeos );
50  }
51 
52  delete mInfo;
53 }
54 
55 void QgsLabelFeature::setObstacleGeometry( GEOSGeometry *obstacleGeom )
56 {
57  if ( mObstacleGeometry )
58  GEOSGeom_destroy_r( QgsGeometry::getGEOSHandler(), mObstacleGeometry );
59 
60  mObstacleGeometry = obstacleGeom;
61 }
62 
64 {
66 
67  if ( mPermissibleZoneGeosPrepared )
68  {
69  GEOSPreparedGeom_destroy_r( QgsGeometry::getGEOSHandler(), mPermissibleZoneGeosPrepared );
70  GEOSGeom_destroy_r( QgsGeometry::getGEOSHandler(), mPermissibleZoneGeos );
71  mPermissibleZoneGeosPrepared = nullptr;
72  mPermissibleZoneGeos = nullptr;
73  }
74 
75  if ( mPermissibleZone.isNull() )
76  return;
77 
78  mPermissibleZoneGeos = mPermissibleZone.exportToGeos();
79  if ( !mPermissibleZoneGeos )
80  return;
81 
82  mPermissibleZoneGeosPrepared = GEOSPrepare_r( QgsGeometry::getGEOSHandler(), mPermissibleZoneGeos );
83 }
bool isNull() const
Returns true if the geometry is null (ie, contains no underlying geometry accessible via geometry() )...
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:111
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.
static GEOSContextHandle_t getGEOSHandler()
Return GEOS context handle.
GEOSGeometry * exportToGeos(double precision=0) const
Returns a geos geometry - caller takes ownership of the object (should be deleted with GEOSGeom_destr...
void setObstacleGeometry(GEOSGeometry *obstacleGeom)
Sets the label's obstacle geometry, if different to the feature geometry.
qint64 QgsFeatureId
Definition: qgsfeature.h:37
QgsGeometry mPermissibleZone
Optional geometry to use for label's permissible zone.