QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgsvectorlayerdiagramprovider.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsvectorlayerdiagramprovider.cpp
3  --------------------------------------
4  Date : September 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 
17 
18 #include "qgsgeometry.h"
19 #include "qgslabelsearchtree.h"
20 #include "qgsvectorlayer.h"
22 #include "diagram/qgsdiagram.h"
23 #include "qgsgeos.h"
24 #include "qgslabelingresults.h"
25 #include "qgsrendercontext.h"
27 
28 #include "feature.h"
29 #include "labelposition.h"
30 
32  : QgsAbstractLabelProvider( layer )
33  , mSettings( *layer->diagramLayerSettings() )
34  , mDiagRenderer( layer->diagramRenderer()->clone() )
35  , mFields( layer->fields() )
36  , mLayerCrs( layer->crs() )
37  , mSource( ownFeatureLoop ? new QgsVectorLayerFeatureSource( layer ) : nullptr )
38  , mOwnsSource( ownFeatureLoop )
39 {
40  init();
41 
42  // we have to create an expression context scope for the layer in advance, while we still have access to the layer itself
43  mLayerScope.reset( layer->createExpressionContextScope() );
44 }
45 
46 
48 {
49  mName = mLayerId;
50  mPriority = 1 - mSettings.priority() / 10.0; // convert 0..10 --> 1..0
51  mPlacement = static_cast< Qgis::LabelPlacement >( mSettings.placement() );
52 }
53 
54 
56 {
57  if ( mOwnsSource )
58  delete mSource;
59 
60  qDeleteAll( mFeatures );
61 
62  // renderer is owned by mSettings
63 }
64 
65 
67 {
68  if ( !mSource )
69  {
70  // we have created the provider with "own feature loop" == false
71  // so it is assumed that prepare() has been already called followed by registerFeature() calls
72  return mFeatures;
73  }
74 
75  QSet<QString> attributeNames;
76  if ( !prepare( context, attributeNames ) )
77  return QList<QgsLabelFeature *>();
78 
79  QgsRectangle layerExtent = context.extent();
81  {
83  extentTransform.setBallparkTransformsAreAppropriate( true );
84  layerExtent = extentTransform.transformBoundingBox( context.extent(), Qgis::TransformDirection::Reverse );
85  }
86 
87  QgsFeatureRequest request;
88  request.setFilterRect( layerExtent );
89  request.setSubsetOfAttributes( attributeNames, mFields );
90  const QgsFeatureFilterProvider *featureFilterProvider = context.featureFilterProvider();
91  if ( featureFilterProvider )
92  {
93  featureFilterProvider->filterFeatures( qobject_cast<QgsVectorLayer *>( mLayer ), request );
94  }
95  QgsFeatureIterator fit = mSource->getFeatures( request );
96 
97  QgsFeature fet;
98  while ( fit.nextFeature( fet ) )
99  {
100  context.expressionContext().setFeature( fet );
101  registerFeature( fet, context );
102  }
103 
104  return mFeatures;
105 }
106 
107 
109 {
110 #if 1 // XXX strk
111  // features are pre-rotated but not scaled/translated,
112  // so we only disable rotation here. Ideally, they'd be
113  // also pre-scaled/translated, as suggested here:
114  // https://github.com/qgis/QGIS/issues/20071
115  QgsMapToPixel xform = context.mapToPixel();
116  xform.setMapRotation( 0, 0, 0 );
117 #else
118  const QgsMapToPixel &xform = context.mapToPixel();
119 #endif
120 
121  QgsDiagramLabelFeature *dlf = dynamic_cast<QgsDiagramLabelFeature *>( label->getFeaturePart()->feature() );
122  const QgsFeature feature = dlf->feature();
123 
124  // at time of drawing labels the expression context won't contain a layer scope -- so we manually add it here so that
125  // associated variables work correctly
127  context.expressionContext().setFeature( feature );
128 
129  //calculate top-left point for diagram
130  //first, calculate the centroid of the label (accounts for PAL creating
131  //rotated labels when we do not want to draw the diagrams rotated)
132  double centerX = 0;
133  double centerY = 0;
134  for ( int i = 0; i < 4; ++i )
135  {
136  centerX += label->getX( i );
137  centerY += label->getY( i );
138  }
139  QgsPointXY outPt( centerX / 4.0, centerY / 4.0 );
140  //then, calculate the top left point for the diagram with this center position
141  QgsPointXY centerPt = xform.transform( outPt.x() - label->getWidth() / 2,
142  outPt.y() - label->getHeight() / 2 );
143 
144  mSettings.renderer()->renderDiagram( feature, context, centerPt.toQPointF(), mSettings.dataDefinedProperties() );
145 
146  //insert into label search tree to manipulate position interactively
147  mEngine->results()->mLabelSearchTree->insertLabel( label, label->getFeaturePart()->featureId(), mLayerId, QString(), QFont(), true, false );
148 }
149 
150 bool QgsVectorLayerDiagramProvider::prepare( const QgsRenderContext &context, QSet<QString> &attributeNames )
151 {
153  const QgsMapSettings &mapSettings = mEngine->mapSettings();
154 
155  if ( context.coordinateTransform().isValid() )
156  // this is context for layer rendering
158  else
159  {
160  // otherwise fall back to creating our own CT
162  }
163 
165 
166  bool result = s2.prepare( context.expressionContext() );
167 
168  //add attributes needed by the diagram renderer
169  attributeNames.unite( s2.referencedFields( context.expressionContext() ) );
170 
171  return result;
172 }
173 
174 
176 {
177  QgsLabelFeature *label = registerDiagram( feature, context, obstacleGeometry );
178  if ( label )
179  mFeatures << label;
180 }
181 
183 {
184  mLabelClipFeatureGeom = geometry;
185 }
186 
188 {
189  const QgsMapSettings &mapSettings = mEngine->mapSettings();
190 
191  const QgsDiagramRenderer *dr = mSettings.renderer();
192  if ( dr )
193  {
194  QList<QgsDiagramSettings> settingList = dr->diagramSettings();
195  if ( !settingList.isEmpty() && settingList.at( 0 ).scaleBasedVisibility )
196  {
197  double maxScale = settingList.at( 0 ).maximumScale;
198  if ( maxScale > 0 && context.rendererScale() < maxScale )
199  {
200  return nullptr;
201  }
202 
203  double minScale = settingList.at( 0 ).minimumScale;
204  if ( minScale > 0 && context.rendererScale() > minScale )
205  {
206  return nullptr;
207  }
208  }
209  }
210 
211  // data defined show diagram? check this before doing any other processing
213  return nullptr;
214 
215  // data defined obstacle?
217 
218  //convert geom to geos
219  QgsGeometry geom = feat.geometry();
220  QgsGeometry extentGeom = QgsGeometry::fromRect( mapSettings.visibleExtent() );
221  if ( !qgsDoubleNear( mapSettings.rotation(), 0.0 ) )
222  {
223  //PAL features are prerotated, so extent also needs to be unrotated
224  extentGeom.rotate( -mapSettings.rotation(), mapSettings.visibleExtent().center() );
225  }
226 
227  if ( QgsPalLabeling::geometryRequiresPreparation( geom, context, mSettings.coordinateTransform(), extentGeom ) )
228  {
229  geom = QgsPalLabeling::prepareGeometry( geom, context, mSettings.coordinateTransform(), extentGeom );
230  }
231  if ( geom.isEmpty() )
232  return nullptr;
233 
235  if ( !clipGeometry.isEmpty() )
236  {
237  const QgsWkbTypes::GeometryType expectedType = geom.type();
238  geom = geom.intersection( clipGeometry );
239  geom.convertGeometryCollectionToSubclass( expectedType );
240  }
241  if ( geom.isEmpty() )
242  return nullptr;
243 
244  QgsGeometry preparedObstacleGeom;
245  if ( isObstacle && !obstacleGeometry.isNull() && QgsPalLabeling::geometryRequiresPreparation( obstacleGeometry, context, mSettings.coordinateTransform(), extentGeom ) )
246  {
247  preparedObstacleGeom = QgsPalLabeling::prepareGeometry( obstacleGeometry, context, mSettings.coordinateTransform(), extentGeom );
248  }
249  else if ( mSettings.isObstacle() && !obstacleGeometry.isNull() )
250  {
251  preparedObstacleGeom = obstacleGeometry;
252  }
253 
254  double diagramWidth = 0;
255  double diagramHeight = 0;
256  if ( dr )
257  {
258  QSizeF diagSize = dr->sizeMapUnits( feat, context );
259  if ( diagSize.isValid() )
260  {
261  diagramWidth = diagSize.width();
262  diagramHeight = diagSize.height();
263  }
264  }
265 
266  // feature to the layer
267  bool alwaysShow = mSettings.showAllDiagrams();
268  context.expressionContext().setOriginalValueVariable( alwaysShow );
270 
271  // new style data defined position
272  bool ddPos = false;
273  double ddPosX = 0.0;
274  double ddPosY = 0.0;
279  {
280  ddPosX = mSettings.dataDefinedProperties().valueAsDouble( QgsDiagramLayerSettings::PositionX, context.expressionContext(), std::numeric_limits<double>::quiet_NaN() );
281  ddPosY = mSettings.dataDefinedProperties().valueAsDouble( QgsDiagramLayerSettings::PositionY, context.expressionContext(), std::numeric_limits<double>::quiet_NaN() );
282 
283  ddPos = !std::isnan( ddPosX ) && !std::isnan( ddPosY );
284 
285  if ( ddPos )
286  {
288  if ( ct.isValid() && !ct.isShortCircuited() )
289  {
290  double z = 0;
291  ct.transformInPlace( ddPosX, ddPosY, z );
292  }
293  //data defined diagram position is always centered
294  ddPosX -= diagramWidth / 2.0;
295  ddPosY -= diagramHeight / 2.0;
296  }
297  }
298 
299  QgsDiagramLabelFeature *lf = new QgsDiagramLabelFeature( feat, QgsGeos::asGeos( geom ), QSizeF( diagramWidth, diagramHeight ) );
300  lf->setHasFixedPosition( ddPos );
301  lf->setFixedPosition( QgsPointXY( ddPosX, ddPosY ) );
302  lf->setHasFixedAngle( true );
303  lf->setFixedAngle( 0 );
304  lf->setAlwaysShow( alwaysShow );
306  os.setIsObstacle( isObstacle );
307  os.setObstacleGeometry( preparedObstacleGeom );
308  lf->setObstacleSettings( os );
309 
310  // data defined priority?
313  {
316  priorityD = std::clamp( priorityD, 0.0, 10.0 );
317  priorityD = 1 - priorityD / 10.0; // convert 0..10 --> 1..0
318  lf->setPriority( priorityD );
319  }
320 
321  // z-Index
322  double zIndex = mSettings.zIndex();
325  {
326  context.expressionContext().setOriginalValueVariable( zIndex );
328  }
329  lf->setZIndex( zIndex );
330 
331  // label distance
332  QgsPointXY ptZero = mapSettings.mapToPixel().toMapCoordinates( 0, 0 );
333  QgsPointXY ptOne = mapSettings.mapToPixel().toMapCoordinates( 1, 0 );
334  double dist = mSettings.distance();
335 
338  {
341  }
342 
343  dist *= ptOne.distance( ptZero );
344 
345  lf->setDistLabel( dist );
346  return lf;
347 }
348 
QgsProperty::isActive
bool isActive() const
Returns whether the property is currently active.
Definition: qgsproperty.cpp:291
QgsPointXY::distance
double distance(double x, double y) const SIP_HOLDGIL
Returns the distance between this point and a specified x, y coordinate.
Definition: qgspointxy.h:211
QgsDiagramLayerSettings::showAllDiagrams
bool showAllDiagrams() const
Returns whether the layer should show all diagrams, including overlapping diagrams.
Definition: qgsdiagramrenderer.h:267
qgsexpressioncontextutils.h
QgsLabelObstacleSettings::setObstacleGeometry
void setObstacleGeometry(const QgsGeometry &obstacleGeom)
Sets the label's obstacle geometry, if different to the feature geometry.
Definition: qgslabelobstaclesettings.cpp:21
QgsCoordinateTransform::transformInPlace
void transformInPlace(double &x, double &y, double &z, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward) const SIP_THROW(QgsCsException)
Transforms an array of x, y and z double coordinates in place, from the source CRS to the destination...
Definition: qgscoordinatetransform.cpp:364
QgsDiagramLayerSettings::isObstacle
bool isObstacle() const
Returns whether the feature associated with a diagram acts as an obstacle for other labels or diagram...
Definition: qgsdiagramrenderer.h:198
pal::LabelPosition::getY
double getY(int i=0) const
Returns the down-left y coordinate.
Definition: labelposition.cpp:343
QgsExpressionContextScopePopper
RAII class to pop scope from an expression context on destruction.
Definition: qgsexpressioncontextutils.h:361
QgsAbstractPropertyCollection::valueAsDouble
double valueAsDouble(int key, const QgsExpressionContext &context, double defaultValue=0.0, bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as a double.
Definition: qgspropertycollection.cpp:66
QgsPointXY::y
double y
Definition: qgspointxy.h:63
QgsLabelFeature::setDistLabel
void setDistLabel(double dist)
Applies to "around point" placement strategy or linestring features.
Definition: qgslabelfeature.h:276
QgsLabelFeature::setPriority
void setPriority(double priority)
Sets the priority for labeling the feature.
Definition: qgslabelfeature.h:154
QgsGeometry::convertGeometryCollectionToSubclass
bool convertGeometryCollectionToSubclass(QgsWkbTypes::GeometryType geomType)
Converts geometry collection to a the desired geometry type subclass (multi-point,...
Definition: qgsgeometry.cpp:1625
QgsRenderContext::mapToPixel
const QgsMapToPixel & mapToPixel() const
Returns the context's map to pixel transform, which transforms between map coordinates and device coo...
Definition: qgsrendercontext.h:258
qgslabelsearchtree.h
QgsVectorLayerDiagramProvider::mSettings
QgsDiagramLayerSettings mSettings
Diagram layer settings.
Definition: qgsvectorlayerdiagramprovider.h:111
QgsDiagramLayerSettings::coordinateTransform
QgsCoordinateTransform coordinateTransform() const
Returns the coordinate transform associated with the layer, or an invalid transform if no transformat...
Definition: qgsdiagramrenderer.h:252
QgsRenderContext::featureClipGeometry
QgsGeometry featureClipGeometry() const
Returns the geometry to use to clip features at render time.
Definition: qgsrendercontext.cpp:630
QgsRenderContext::expressionContext
QgsExpressionContext & expressionContext()
Gets the expression context.
Definition: qgsrendercontext.h:625
QgsDiagramLayerSettings::priority
int priority() const
Returns the diagram priority.
Definition: qgsdiagramrenderer.h:164
QgsVectorLayerDiagramProvider::init
void init()
initialization method - called from constructors
Definition: qgsvectorlayerdiagramprovider.cpp:47
QgsDiagramLayerSettings::renderer
QgsDiagramRenderer * renderer()
Returns the diagram renderer associated with the layer.
Definition: qgsdiagramrenderer.h:228
QgsDiagramLayerSettings::dataDefinedProperties
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the diagram's property collection, used for data defined overrides.
Definition: qgsdiagramrenderer.h:309
labelposition.h
QgsVectorLayerDiagramProvider::mDiagRenderer
QgsDiagramRenderer * mDiagRenderer
Diagram renderer instance (owned by mSettings)
Definition: qgsvectorlayerdiagramprovider.h:113
QgsVectorLayerDiagramProvider::mLayerScope
std::unique_ptr< QgsExpressionContextScope > mLayerScope
Definition: qgsvectorlayerdiagramprovider.h:129
QgsRectangle::center
QgsPointXY center() const SIP_HOLDGIL
Returns the center point of the rectangle.
Definition: qgsrectangle.h:251
crs
const QgsCoordinateReferenceSystem & crs
Definition: qgswfsgetfeature.cpp:105
QgsAbstractLabelProvider::mName
QString mName
Name of the layer.
Definition: qgslabelingengine.h:181
pal::LabelPosition
LabelPosition is a candidate feature label position.
Definition: labelposition.h:55
QgsVectorLayerDiagramProvider::QgsVectorLayerDiagramProvider
QgsVectorLayerDiagramProvider(QgsVectorLayer *layer, bool ownFeatureLoop=true)
Convenience constructor to initialize the provider from given vector layer.
Definition: qgsvectorlayerdiagramprovider.cpp:31
QgsExpressionContext::setOriginalValueVariable
void setOriginalValueVariable(const QVariant &value)
Sets the original value variable value for the context.
Definition: qgsexpressioncontext.cpp:600
QgsCoordinateTransform::transformBoundingBox
QgsRectangle transformBoundingBox(const QgsRectangle &rectangle, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool handle180Crossover=false) const SIP_THROW(QgsCsException)
Transforms a rectangle from the source CRS to the destination CRS.
Definition: qgscoordinatetransform.cpp:560
QgsFeature::geometry
QgsGeometry geometry
Definition: qgsfeature.h:71
QgsPalLabeling::prepareGeometry
static QgsGeometry prepareGeometry(const QgsGeometry &geometry, QgsRenderContext &context, const QgsCoordinateTransform &ct, const QgsGeometry &clipGeometry=QgsGeometry(), bool mergeLines=false)
Prepares a geometry for registration with PAL.
Definition: qgspallabeling.cpp:3907
QgsRenderContext
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:59
QgsPointXY::toQPointF
QPointF toQPointF() const
Converts a point to a QPointF.
Definition: qgspointxy.h:169
QgsDiagramLabelFeature
Class that adds extra information to QgsLabelFeature for labeling of diagrams.
Definition: qgsvectorlayerdiagramprovider.h:33
QgsVectorLayerDiagramProvider::registerDiagram
QgsLabelFeature * registerDiagram(const QgsFeature &feat, QgsRenderContext &context, const QgsGeometry &obstacleGeometry=QgsGeometry())
helper method to register one diagram feature
Definition: qgsvectorlayerdiagramprovider.cpp:187
qgsdiagram.h
QgsLabelObstacleSettings::setIsObstacle
void setIsObstacle(bool isObstacle)
Sets whether features are obstacles to labels of other layers.
Definition: qgslabelobstaclesettings.h:71
QgsFeatureRequest::setSubsetOfAttributes
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
Definition: qgsfeaturerequest.cpp:228
QgsLabelObstacleSettings
Contains settings related to how the label engine treats features as obstacles.
Definition: qgslabelobstaclesettings.h:34
QgsDiagramRenderer::sizeMapUnits
virtual QSizeF sizeMapUnits(const QgsFeature &feature, const QgsRenderContext &c) const
Returns size of the diagram for a feature in map units. Returns an invalid QSizeF in case of error.
Definition: qgsdiagramrenderer.cpp:497
QgsMapToPixel::toMapCoordinates
QgsPointXY toMapCoordinates(int x, int y) const
Transforms device coordinates to map (world) coordinates.
Definition: qgsmaptopixel.h:173
QgsCoordinateTransform::isValid
bool isValid() const
Returns true if the coordinate transform is valid, ie both the source and destination CRS have been s...
Definition: qgscoordinatetransform.cpp:900
QgsRenderContext::extent
const QgsRectangle & extent() const
When rendering a map layer, calling this method returns the "clipping" extent for the layer (in the l...
Definition: qgsrendercontext.h:239
QgsDiagramLayerSettings::Show
@ Show
Whether to show the diagram.
Definition: qgsdiagramrenderer.h:101
QgsDiagramLayerSettings::referencedFields
QSet< QString > referencedFields(const QgsExpressionContext &context=QgsExpressionContext()) const
Returns the set of any fields referenced by the layer's diagrams.
Definition: qgsdiagramrenderer.cpp:164
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:41
pal::LabelPosition::getFeaturePart
FeaturePart * getFeaturePart() const
Returns the feature corresponding to this labelposition.
Definition: labelposition.cpp:361
QgsGeometry::intersection
QgsGeometry intersection(const QgsGeometry &geometry) const
Returns a geometry representing the points shared by this geometry and other.
Definition: qgsgeometry.cpp:2616
QgsPropertyCollection::property
QgsProperty property(int key) const override
Returns a matching property from the collection, if one exists.
Definition: qgspropertycollection.cpp:214
QgsDiagramLayerSettings::PositionY
@ PositionY
Y-coordinate data defined diagram position.
Definition: qgsdiagramrenderer.h:96
qgslabelingresults.h
QgsFeatureRequest::setFilterRect
QgsFeatureRequest & setFilterRect(const QgsRectangle &rectangle)
Sets the rectangle from which features will be taken.
Definition: qgsfeaturerequest.cpp:101
QgsDiagramLayerSettings::ZIndex
@ ZIndex
Z-index for diagram ordering.
Definition: qgsdiagramrenderer.h:99
qgsvectorlayerdiagramprovider.h
QgsVectorLayerDiagramProvider::prepare
virtual bool prepare(const QgsRenderContext &context, QSet< QString > &attributeNames)
Prepare for registration of features.
Definition: qgsvectorlayerdiagramprovider.cpp:150
QgsRenderContext::coordinateTransform
QgsCoordinateTransform coordinateTransform() const
Returns the current coordinate transform for the context.
Definition: qgsrendercontext.h:178
QgsFeatureRequest
This class wraps a request for features to a vector layer (or directly its vector data provider).
Definition: qgsfeaturerequest.h:83
feature.h
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
QgsFeatureFilterProvider::filterFeatures
virtual void filterFeatures(const QgsVectorLayer *layer, QgsFeatureRequest &featureRequest) const =0
Add additional filters to the feature request to further restrict the features returned by the reques...
QgsAbstractLabelProvider::mLayerId
QString mLayerId
Associated layer's ID, if applicable.
Definition: qgslabelingengine.h:183
QgsCoordinateTransform::isShortCircuited
bool isShortCircuited() const
Returns true if the transform short circuits because the source and destination are equivalent.
Definition: qgscoordinatetransform.cpp:905
QgsPalLabeling::geometryRequiresPreparation
static bool geometryRequiresPreparation(const QgsGeometry &geometry, QgsRenderContext &context, const QgsCoordinateTransform &ct, const QgsGeometry &clipGeometry=QgsGeometry(), bool mergeLines=false)
Checks whether a geometry requires preparation before registration with PAL.
Definition: qgspallabeling.cpp:3830
QgsMapSettings::rotation
double rotation() const
Returns the rotation of the resulting map image, in degrees clockwise.
Definition: qgsmapsettings.cpp:102
QgsAbstractLabelProvider
The QgsAbstractLabelProvider class is an interface class. Implementations return list of labels and t...
Definition: qgslabelingengine.h:52
QgsDiagramRenderer::renderDiagram
void renderDiagram(const QgsFeature &feature, QgsRenderContext &c, QPointF pos, const QgsPropertyCollection &properties=QgsPropertyCollection()) const
Renders the diagram for a specified feature at a specific position in the passed render context.
Definition: qgsdiagramrenderer.cpp:462
QgsDiagramLayerSettings::prepare
bool prepare(const QgsExpressionContext &context=QgsExpressionContext()) const
Prepares the diagrams for a specified expression context.
Definition: qgsdiagramrenderer.cpp:159
QgsCoordinateTransform::setBallparkTransformsAreAppropriate
void setBallparkTransformsAreAppropriate(bool appropriate)
Sets whether approximate "ballpark" results are appropriate for this coordinate transform.
Definition: qgscoordinatetransform.cpp:939
QgsVectorLayerDiagramProvider::mOwnsSource
bool mOwnsSource
Whether layer's feature source is owned.
Definition: qgsvectorlayerdiagramprovider.h:124
QgsVectorLayerDiagramProvider::drawLabel
void drawLabel(QgsRenderContext &context, pal::LabelPosition *label) const override
Draw this label at the position determined by the labeling engine.
Definition: qgsvectorlayerdiagramprovider.cpp:108
QgsDiagramLayerSettings::Distance
@ Distance
Distance to diagram from feature.
Definition: qgsdiagramrenderer.h:97
QgsVectorLayerDiagramProvider::setClipFeatureGeometry
void setClipFeatureGeometry(const QgsGeometry &geometry)
Sets a geometry to use to clip features to when registering them as diagrams.
Definition: qgsvectorlayerdiagramprovider.cpp:182
qgsDoubleNear
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Definition: qgis.h:2265
QgsRenderContext::featureFilterProvider
const QgsFeatureFilterProvider * featureFilterProvider() const
Gets the filter feature provider used for additional filtering of rendered features.
Definition: qgsrendercontext.cpp:362
QgsLabelFeature::setZIndex
void setZIndex(double zIndex)
Sets the label's z-index.
Definition: qgslabelfeature.h:171
QgsLabelFeature::setHasFixedAngle
void setHasFixedAngle(bool enabled)
Sets whether the label should use a fixed angle instead of using angle from automatic placement.
Definition: qgslabelfeature.h:202
QgsVectorLayerDiagramProvider::mFeatures
QList< QgsLabelFeature * > mFeatures
List of generated label features (owned by the provider)
Definition: qgsvectorlayerdiagramprovider.h:127
QgsGeometry::rotate
Qgis::GeometryOperationResult rotate(double rotation, const QgsPointXY &center)
Rotate this geometry around the Z axis.
Definition: qgsgeometry.cpp:910
QgsLabelFeature::setObstacleSettings
void setObstacleSettings(const QgsLabelObstacleSettings &settings)
Sets the label's obstacle settings.
Definition: qgslabelfeature.cpp:123
qgsrendercontext.h
QgsVectorLayerDiagramProvider::mFields
QgsFields mFields
Layer's fields.
Definition: qgsvectorlayerdiagramprovider.h:118
QgsDiagramLayerSettings
Stores the settings for rendering of all diagrams for a layer.
Definition: qgsdiagramrenderer.h:61
QgsLabelFeature::setFixedPosition
void setFixedPosition(const QgsPointXY &point)
Sets coordinates of the fixed position (relevant only if hasFixedPosition() returns true)
Definition: qgslabelfeature.h:181
QgsVectorLayerDiagramProvider::mLayerCrs
QgsCoordinateReferenceSystem mLayerCrs
Layer's CRS.
Definition: qgsvectorlayerdiagramprovider.h:120
QgsDiagramRenderer
Evaluates and returns the diagram settings relating to a diagram for a specific feature.
Definition: qgsdiagramrenderer.h:684
QgsGeometry::isEmpty
bool isEmpty() const
Returns true if the geometry is empty (eg a linestring with no vertices, or a collection with no geom...
Definition: qgsgeometry.cpp:379
qgsvectorlayerfeatureiterator.h
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
QgsAbstractLabelProvider::mPlacement
Qgis::LabelPlacement mPlacement
Placement strategy.
Definition: qgslabelingengine.h:191
QgsLabelFeature::setHasFixedPosition
void setHasFixedPosition(bool enabled)
Sets whether the label should use a fixed position instead of being automatically placed.
Definition: qgslabelfeature.h:176
QgsDiagramRenderer::diagramSettings
virtual QList< QgsDiagramSettings > diagramSettings() const =0
Returns list with all diagram settings in the renderer.
QgsAbstractLabelProvider::mEngine
const QgsLabelingEngine * mEngine
Associated labeling engine.
Definition: qgslabelingengine.h:178
QgsMapToPixel::transform
QgsPointXY transform(const QgsPointXY &p) const
Transforms a point p from map (world) coordinates to device coordinates.
Definition: qgsmaptopixel.h:90
QgsDiagramLayerSettings::placement
Placement placement() const
Returns the diagram placement.
Definition: qgsdiagramrenderer.h:129
QgsExpressionContextScope
Single scope for storing variables and functions for use within a QgsExpressionContext....
Definition: qgsexpressioncontext.h:113
QgsDiagramLayerSettings::zIndex
double zIndex() const
Returns the diagram z-index.
Definition: qgsdiagramrenderer.h:182
QgsAbstractLabelProvider::mLayer
QgsWeakMapLayerPointer mLayer
Weak pointer to source layer.
Definition: qgslabelingengine.h:185
qgsvectorlayer.h
QgsPointXY
A class to represent a 2D point.
Definition: qgspointxy.h:58
QgsMapSettings::destinationCrs
QgsCoordinateReferenceSystem destinationCrs() const
Returns the destination coordinate reference system for the map render.
Definition: qgsmapsettings.cpp:358
QgsDiagramLayerSettings::setRenderer
void setRenderer(QgsDiagramRenderer *diagramRenderer)
Sets the diagram renderer associated with the layer.
Definition: qgsdiagramrenderer.cpp:108
qgsgeometry.h
QgsLabelingEngine::mapSettings
const QgsMapSettings & mapSettings() const
Gets associated map settings.
Definition: qgslabelingengine.h:359
QgsWkbTypes::GeometryType
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
Definition: qgswkbtypes.h:140
pal::LabelPosition::getHeight
double getHeight() const
Definition: labelposition.h:261
QgsFeatureIterator::nextFeature
bool nextFeature(QgsFeature &f)
Definition: qgsfeatureiterator.h:399
QgsGeometry
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:124
QgsAbstractPropertyCollection::valueAsBool
bool valueAsBool(int key, const QgsExpressionContext &context, bool defaultValue=false, bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as an boolean.
Definition: qgspropertycollection.cpp:88
QgsMapToPixel
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:38
QgsDiagramLayerSettings::distance
double distance() const
Returns the distance between the diagram and the feature (in mm).
Definition: qgsdiagramrenderer.h:213
QgsLabelingEngine::results
QgsLabelingResults * results() const
For internal use by the providers.
Definition: qgslabelingengine.h:395
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
QgsRenderContext::transformContext
QgsCoordinateTransformContext transformContext() const
Returns the context's coordinate transform context, which stores various information regarding which ...
Definition: qgsrendercontext.cpp:184
QgsPointXY::x
double x
Definition: qgspointxy.h:62
pal::LabelPosition::getX
double getX(int i=0) const
Returns the down-left x coordinate.
Definition: labelposition.cpp:338
QgsVectorLayerFeatureSource
Partial snapshot of vector layer's state (only the members necessary for access to features)
Definition: qgsvectorlayerfeatureiterator.h:52
QgsGeometry::fromRect
static QgsGeometry fromRect(const QgsRectangle &rect) SIP_HOLDGIL
Creates a new geometry from a QgsRectangle.
Definition: qgsgeometry.cpp:241
QgsVectorLayerDiagramProvider::~QgsVectorLayerDiagramProvider
~QgsVectorLayerDiagramProvider() override
Clean up.
Definition: qgsvectorlayerdiagramprovider.cpp:55
QgsPropertyCollection::hasProperty
bool hasProperty(int key) const override
Returns true if the collection contains a property with the specified key.
Definition: qgspropertycollection.cpp:203
QgsAbstractLabelProvider::layer
QgsMapLayer * layer() const
Returns the associated layer, or nullptr if no layer is associated with the provider.
Definition: qgslabelingengine.h:138
QgsVectorLayerDiagramProvider::mLabelClipFeatureGeom
QgsGeometry mLabelClipFeatureGeom
Definition: qgsvectorlayerdiagramprovider.h:131
QgsFeatureFilterProvider
Abstract interface for use by classes that filter the features or attributes of a layer.
Definition: qgsfeaturefilterprovider.h:43
QgsLabelFeature::setFixedAngle
void setFixedAngle(double angle)
Sets angle in degrees of the fixed angle (relevant only if hasFixedAngle() returns true)
Definition: qgslabelfeature.h:206
QgsAbstractFeatureSource::getFeatures
virtual QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest())=0
Gets an iterator for features matching the specified request.
QgsVectorLayerDiagramProvider::mSource
QgsAbstractFeatureSource * mSource
Layer's feature source.
Definition: qgsvectorlayerdiagramprovider.h:122
QgsFeature
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:55
QgsLabelFeature
The QgsLabelFeature class describes a feature that should be used within the labeling engine....
Definition: qgslabelfeature.h:57
QgsDiagramLayerSettings::AlwaysShow
@ AlwaysShow
Whether the diagram should always be shown, even if it overlaps other diagrams/labels.
Definition: qgsdiagramrenderer.h:102
QgsDiagramLayerSettings::PositionX
@ PositionX
X-coordinate data defined diagram position.
Definition: qgsdiagramrenderer.h:95
pal::FeaturePart::featureId
QgsFeatureId featureId() const
Returns the unique ID of the feature.
Definition: feature.cpp:159
QgsRenderContext::rendererScale
double rendererScale() const
Returns the renderer map scale.
Definition: qgsrendercontext.h:344
QgsVectorLayerDiagramProvider::registerFeature
virtual void registerFeature(QgsFeature &feature, QgsRenderContext &context, const QgsGeometry &obstacleGeometry=QgsGeometry())
Register a feature for labeling as one or more QgsLabelFeature objects stored into mFeatures.
Definition: qgsvectorlayerdiagramprovider.cpp:175
QgsMapSettings
The QgsMapSettings class contains configuration for rendering of the map. The rendering itself is don...
Definition: qgsmapsettings.h:88
QgsMapSettings::visibleExtent
QgsRectangle visibleExtent() const
Returns the actual extent derived from requested extent that takes output image size into account.
Definition: qgsmapsettings.cpp:411
QgsCoordinateTransform
Class for doing transforms between two map coordinate systems.
Definition: qgscoordinatetransform.h:57
pal::FeaturePart::feature
QgsLabelFeature * feature()
Returns the parent feature.
Definition: feature.h:94
QgsGeometry::type
QgsWkbTypes::GeometryType type
Definition: qgsgeometry.h:128
QgsFeatureIterator
Wrapper for iterator of features from vector data provider or vector layer.
Definition: qgsfeatureiterator.h:289
QgsVectorLayerDiagramProvider::labelFeatures
QList< QgsLabelFeature * > labelFeatures(QgsRenderContext &context) override
Returns list of label features (they are owned by the provider and thus deleted on its destruction)
Definition: qgsvectorlayerdiagramprovider.cpp:66
QgsMapToPixel::setMapRotation
void setMapRotation(double degrees, double cx, double cy)
Sets map rotation in degrees (clockwise).
Definition: qgsmaptopixel.cpp:95
QgsDiagramLayerSettings::IsObstacle
@ IsObstacle
Whether diagram features act as obstacles for other diagrams/labels.
Definition: qgsdiagramrenderer.h:100
QgsMapSettings::mapToPixel
const QgsMapToPixel & mapToPixel() const
Definition: qgsmapsettings.h:527
QgsDiagramLayerSettings::Priority
@ Priority
Diagram priority (between 0 and 10)
Definition: qgsdiagramrenderer.h:98
QgsAbstractLabelProvider::mPriority
double mPriority
Default priority of labels.
Definition: qgslabelingengine.h:193
qgsgeos.h
QgsDiagramLayerSettings::setCoordinateTransform
void setCoordinateTransform(const QgsCoordinateTransform &transform)
Sets the coordinate transform associated with the layer.
Definition: qgsdiagramrenderer.cpp:117
Qgis::LabelPlacement
LabelPlacement
Placement modes which determine how label candidates are generated for a feature.
Definition: qgis.h:560
QgsLabelFeature::setAlwaysShow
void setAlwaysShow(bool enabled)
Sets whether label should be always shown (sets very high label priority)
Definition: qgslabelfeature.h:307
QgsExpressionContext::setFeature
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
Definition: qgsexpressioncontext.cpp:525
pal::LabelPosition::getWidth
double getWidth() const
Definition: labelposition.h:260