QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 
25 #include "feature.h"
26 #include "labelposition.h"
27 
29  : QgsAbstractLabelProvider( layer )
30  , mSettings( *layer->diagramLayerSettings() )
31  , mDiagRenderer( layer->diagramRenderer()->clone() )
32  , mFields( layer->fields() )
33  , mLayerCrs( layer->crs() )
34  , mSource( ownFeatureLoop ? new QgsVectorLayerFeatureSource( layer ) : nullptr )
35  , mOwnsSource( ownFeatureLoop )
36 {
37  init();
38 }
39 
40 
42 {
43  mName = mLayerId;
44  mPriority = 1 - mSettings.priority() / 10.0; // convert 0..10 --> 1..0
46 }
47 
48 
50 {
51  if ( mOwnsSource )
52  delete mSource;
53 
54  qDeleteAll( mFeatures );
55 
56  // renderer is owned by mSettings
57 }
58 
59 
61 {
62  if ( !mSource )
63  {
64  // we have created the provider with "own feature loop" == false
65  // so it is assumed that prepare() has been already called followed by registerFeature() calls
66  return mFeatures;
67  }
68 
69  QSet<QString> attributeNames;
70  if ( !prepare( context, attributeNames ) )
71  return QList<QgsLabelFeature *>();
72 
73  QgsRectangle layerExtent = context.extent();
76 
77  QgsFeatureRequest request;
78  request.setFilterRect( layerExtent );
79  request.setSubsetOfAttributes( attributeNames, mFields );
80  const QgsFeatureFilterProvider *featureFilterProvider = context.featureFilterProvider();
81  if ( featureFilterProvider )
82  {
83  featureFilterProvider->filterFeatures( qobject_cast<QgsVectorLayer *>( mLayer ), request );
84  }
85  QgsFeatureIterator fit = mSource->getFeatures( request );
86 
87  QgsFeature fet;
88  while ( fit.nextFeature( fet ) )
89  {
90  context.expressionContext().setFeature( fet );
91  registerFeature( fet, context );
92  }
93 
94  return mFeatures;
95 }
96 
97 
99 {
100 #if 1 // XXX strk
101  // features are pre-rotated but not scaled/translated,
102  // so we only disable rotation here. Ideally, they'd be
103  // also pre-scaled/translated, as suggested here:
104  // https://github.com/qgis/QGIS/issues/20071
105  QgsMapToPixel xform = context.mapToPixel();
106  xform.setMapRotation( 0, 0, 0 );
107 #else
108  const QgsMapToPixel &xform = context.mapToPixel();
109 #endif
110 
111  QgsDiagramLabelFeature *dlf = dynamic_cast<QgsDiagramLabelFeature *>( label->getFeaturePart()->feature() );
112 
113  QgsFeature feature;
114  feature.setFields( mFields );
115  feature.setValid( true );
116  feature.setId( label->getFeaturePart()->featureId() );
117  feature.setAttributes( dlf->attributes() );
118 
119  context.expressionContext().setFeature( feature );
120 
121  //calculate top-left point for diagram
122  //first, calculate the centroid of the label (accounts for PAL creating
123  //rotated labels when we do not want to draw the diagrams rotated)
124  double centerX = 0;
125  double centerY = 0;
126  for ( int i = 0; i < 4; ++i )
127  {
128  centerX += label->getX( i );
129  centerY += label->getY( i );
130  }
131  QgsPointXY outPt( centerX / 4.0, centerY / 4.0 );
132  //then, calculate the top left point for the diagram with this center position
133  QgsPointXY centerPt = xform.transform( outPt.x() - label->getWidth() / 2,
134  outPt.y() - label->getHeight() / 2 );
135 
136  mSettings.renderer()->renderDiagram( feature, context, centerPt.toQPointF(), mSettings.dataDefinedProperties() );
137 
138  //insert into label search tree to manipulate position interactively
139  mEngine->results()->mLabelSearchTree->insertLabel( label, label->getFeaturePart()->featureId(), mLayerId, QString(), QFont(), true, false );
140 
141 }
142 
143 
144 bool QgsVectorLayerDiagramProvider::prepare( const QgsRenderContext &context, QSet<QString> &attributeNames )
145 {
147  const QgsMapSettings &mapSettings = mEngine->mapSettings();
148 
149  if ( context.coordinateTransform().isValid() )
150  // this is context for layer rendering
152  else
153  {
154  // otherwise fall back to creating our own CT
156  }
157 
159 
160  bool result = s2.prepare( context.expressionContext() );
161 
162  //add attributes needed by the diagram renderer
163  attributeNames.unite( s2.referencedFields( context.expressionContext() ) );
164 
165  return result;
166 }
167 
168 
170 {
171  QgsLabelFeature *label = registerDiagram( feature, context, obstacleGeometry );
172  if ( label )
173  mFeatures << label;
174 }
175 
176 
178 {
179  const QgsMapSettings &mapSettings = mEngine->mapSettings();
180 
181  const QgsDiagramRenderer *dr = mSettings.renderer();
182  if ( dr )
183  {
184  QList<QgsDiagramSettings> settingList = dr->diagramSettings();
185  if ( !settingList.isEmpty() && settingList.at( 0 ).scaleBasedVisibility )
186  {
187  double maxScale = settingList.at( 0 ).maximumScale;
188  if ( maxScale > 0 && context.rendererScale() < maxScale )
189  {
190  return nullptr;
191  }
192 
193  double minScale = settingList.at( 0 ).minimumScale;
194  if ( minScale > 0 && context.rendererScale() > minScale )
195  {
196  return nullptr;
197  }
198  }
199  }
200 
201  // data defined show diagram? check this before doing any other processing
203  return nullptr;
204 
205  // data defined obstacle?
207 
208  //convert geom to geos
209  QgsGeometry geom = feat.geometry();
210  QgsGeometry extentGeom = QgsGeometry::fromRect( mapSettings.visibleExtent() );
211  if ( !qgsDoubleNear( mapSettings.rotation(), 0.0 ) )
212  {
213  //PAL features are prerotated, so extent also needs to be unrotated
214  extentGeom.rotate( -mapSettings.rotation(), mapSettings.visibleExtent().center() );
215  }
216 
217  geos::unique_ptr geomCopy;
218  std::unique_ptr<QgsGeometry> scopedPreparedGeom;
219  if ( QgsPalLabeling::geometryRequiresPreparation( geom, context, mSettings.coordinateTransform(), extentGeom ) )
220  {
221  scopedPreparedGeom.reset( new QgsGeometry( QgsPalLabeling::prepareGeometry( geom, context, mSettings.coordinateTransform(), extentGeom ) ) );
222  QgsGeometry *preparedGeom = scopedPreparedGeom.get();
223  if ( preparedGeom->isNull() )
224  return nullptr;
225  geomCopy = QgsGeos::asGeos( *preparedGeom );
226  }
227  else
228  {
229  geomCopy = QgsGeos::asGeos( geom );
230  }
231 
232  if ( !geomCopy )
233  return nullptr; // invalid geometry
234 
235  QgsGeometry preparedObstacleGeom;
236  if ( isObstacle && !obstacleGeometry.isNull() && QgsPalLabeling::geometryRequiresPreparation( obstacleGeometry, context, mSettings.coordinateTransform(), extentGeom ) )
237  {
238  preparedObstacleGeom = QgsPalLabeling::prepareGeometry( obstacleGeometry, context, mSettings.coordinateTransform(), extentGeom );
239  }
240  else if ( mSettings.isObstacle() && !obstacleGeometry.isNull() )
241  {
242  preparedObstacleGeom = obstacleGeometry;
243  }
244 
245  double diagramWidth = 0;
246  double diagramHeight = 0;
247  if ( dr )
248  {
249  QSizeF diagSize = dr->sizeMapUnits( feat, context );
250  if ( diagSize.isValid() )
251  {
252  diagramWidth = diagSize.width();
253  diagramHeight = diagSize.height();
254  }
255  }
256 
257  // feature to the layer
258  bool alwaysShow = mSettings.showAllDiagrams();
259  context.expressionContext().setOriginalValueVariable( alwaysShow );
261 
262  // new style data defined position
263  bool ddPos = false;
264  double ddPosX = 0.0;
265  double ddPosY = 0.0;
270  {
271  ddPosX = mSettings.dataDefinedProperties().valueAsDouble( QgsDiagramLayerSettings::PositionX, context.expressionContext(), std::numeric_limits<double>::quiet_NaN() );
272  ddPosY = mSettings.dataDefinedProperties().valueAsDouble( QgsDiagramLayerSettings::PositionY, context.expressionContext(), std::numeric_limits<double>::quiet_NaN() );
273 
274  ddPos = !std::isnan( ddPosX ) && !std::isnan( ddPosY );
275 
276  if ( ddPos )
277  {
279  if ( ct.isValid() && !ct.isShortCircuited() )
280  {
281  double z = 0;
282  ct.transformInPlace( ddPosX, ddPosY, z );
283  }
284  //data defined diagram position is always centered
285  ddPosX -= diagramWidth / 2.0;
286  ddPosY -= diagramHeight / 2.0;
287  }
288  }
289 
290  QgsDiagramLabelFeature *lf = new QgsDiagramLabelFeature( feat.id(), std::move( geomCopy ), QSizeF( diagramWidth, diagramHeight ) );
291  lf->setHasFixedPosition( ddPos );
292  lf->setFixedPosition( QgsPointXY( ddPosX, ddPosY ) );
293  lf->setHasFixedAngle( true );
294  lf->setFixedAngle( 0 );
295  lf->setAlwaysShow( alwaysShow );
297  os.setIsObstacle( isObstacle );
298  os.setObstacleGeometry( preparedObstacleGeom );
299  lf->setObstacleSettings( os );
300 
301  if ( dr )
302  {
303  //append the diagram attributes to lbl
304  lf->setAttributes( feat.attributes() );
305  }
306 
307  // data defined priority?
310  {
313  priorityD = qBound( 0.0, priorityD, 10.0 );
314  priorityD = 1 - priorityD / 10.0; // convert 0..10 --> 1..0
315  lf->setPriority( priorityD );
316  }
317 
318  // z-Index
319  double zIndex = mSettings.zIndex();
322  {
323  context.expressionContext().setOriginalValueVariable( zIndex );
325  }
326  lf->setZIndex( zIndex );
327 
328  // label distance
329  QgsPointXY ptZero = mapSettings.mapToPixel().toMapCoordinates( 0, 0 );
330  QgsPointXY ptOne = mapSettings.mapToPixel().toMapCoordinates( 1, 0 );
331  double dist = mSettings.distance();
332 
335  {
338  }
339 
340  dist *= ptOne.distance( ptZero );
341 
342  lf->setDistLabel( dist );
343  return lf;
344 }
QgsProperty::isActive
bool isActive() const
Returns whether the property is currently active.
Definition: qgsproperty.cpp:266
QgsDiagramLayerSettings::showAllDiagrams
bool showAllDiagrams() const
Returns whether the layer should show all diagrams, including overlapping diagrams.
Definition: qgsdiagramrenderer.h:266
QgsLabelObstacleSettings::setObstacleGeometry
void setObstacleGeometry(const QgsGeometry &obstacleGeom)
Sets the label's obstacle geometry, if different to the feature geometry.
Definition: qgslabelobstaclesettings.cpp:21
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:197
pal::LabelPosition::getY
double getY(int i=0) const
Returns the down-left y coordinate.
Definition: labelposition.cpp:353
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:48
QgsLabelFeature::setDistLabel
void setDistLabel(double dist)
Applies to "around point" placement strategy or linestring features.
Definition: qgslabelfeature.h:275
QgsLabelFeature::setPriority
void setPriority(double priority)
Sets the priority for labeling the feature.
Definition: qgslabelfeature.h:153
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:309
qgslabelsearchtree.h
QgsVectorLayerDiagramProvider::mSettings
QgsDiagramLayerSettings mSettings
Diagram layer settings.
Definition: qgsvectorlayerdiagramprovider.h:109
QgsDiagramLayerSettings::coordinateTransform
QgsCoordinateTransform coordinateTransform() const
Returns the coordinate transform associated with the layer, or an invalid transform if no transformat...
Definition: qgsdiagramrenderer.h:251
QgsRenderContext::expressionContext
QgsExpressionContext & expressionContext()
Gets the expression context.
Definition: qgsrendercontext.h:580
QgsDiagramLayerSettings::priority
int priority() const
Returns the diagram priority.
Definition: qgsdiagramrenderer.h:163
QgsVectorLayerDiagramProvider::init
void init()
initialization method - called from constructors
Definition: qgsvectorlayerdiagramprovider.cpp:41
QgsDiagramLayerSettings::renderer
QgsDiagramRenderer * renderer()
Returns the diagram renderer associated with the layer.
Definition: qgsdiagramrenderer.h:227
QgsDiagramLayerSettings::dataDefinedProperties
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the diagram's property collection, used for data defined overrides.
Definition: qgsdiagramrenderer.h:308
QgsFeature::setId
void setId(QgsFeatureId id)
Sets the feature ID for this feature.
Definition: qgsfeature.cpp:112
labelposition.h
QgsVectorLayerDiagramProvider::mDiagRenderer
QgsDiagramRenderer * mDiagRenderer
Diagram renderer instance (owned by mSettings)
Definition: qgsvectorlayerdiagramprovider.h:111
crs
const QgsCoordinateReferenceSystem & crs
Definition: qgswfsgetfeature.cpp:105
QgsAbstractLabelProvider::mName
QString mName
Name of the layer.
Definition: qgslabelingengine.h:159
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:28
QgsExpressionContext::setOriginalValueVariable
void setOriginalValueVariable(const QVariant &value)
Sets the original value variable value for the context.
Definition: qgsexpressioncontext.cpp:566
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:3619
QgsFeature::setValid
void setValid(bool validity)
Sets the validity of the feature.
Definition: qgsfeature.cpp:188
QgsRenderContext
Definition: qgsrendercontext.h:57
QgsPointXY::toQPointF
QPointF toQPointF() const
Converts a point to a QPointF.
Definition: qgspointxy.h:154
QgsDiagramLabelFeature
Definition: qgsvectorlayerdiagramprovider.h:33
QgsGeometry::rotate
OperationResult rotate(double rotation, const QgsPointXY &center)
Rotate this geometry around the Z axis.
Definition: qgsgeometry.cpp:803
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:190
QgsLabelObstacleSettings
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:495
QgsMapToPixel::toMapCoordinates
QgsPointXY toMapCoordinates(int x, int y) const
Transform device coordinates to map (world) coordinates.
Definition: qgsmaptopixel.cpp:108
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:876
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:290
QgsDiagramLayerSettings::Show
@ Show
Whether to show the diagram.
Definition: qgsdiagramrenderer.h:100
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:162
QgsRectangle
Definition: qgsrectangle.h:41
QgsCoordinateTransform::ReverseTransform
@ ReverseTransform
Transform from destination to source CRS.
Definition: qgscoordinatetransform.h:61
pal::LabelPosition::getFeaturePart
FeaturePart * getFeaturePart() const
Returns the feature corresponding to this labelposition.
Definition: labelposition.cpp:371
QgsCoordinateTransform::transformBoundingBox
QgsRectangle transformBoundingBox(const QgsRectangle &rectangle, TransformDirection direction=ForwardTransform, bool handle180Crossover=false) const SIP_THROW(QgsCsException)
Transforms a rectangle from the source CRS to the destination CRS.
Definition: qgscoordinatetransform.cpp:511
QgsGeometry::fromRect
static QgsGeometry fromRect(const QgsRectangle &rect)
Creates a new geometry from a QgsRectangle.
Definition: qgsgeometry.cpp:229
QgsPropertyCollection::property
QgsProperty property(int key) const override
Returns a matching property from the collection, if one exists.
Definition: qgspropertycollection.cpp:204
QgsDiagramLayerSettings::PositionY
@ PositionY
Y-coordinate data defined diagram position.
Definition: qgsdiagramrenderer.h:95
QgsVectorLayerDiagramProvider::registerDiagram
QgsLabelFeature * registerDiagram(QgsFeature &feat, QgsRenderContext &context, const QgsGeometry &obstacleGeometry=QgsGeometry())
helper method to register one diagram feature
Definition: qgsvectorlayerdiagramprovider.cpp:177
geos::unique_ptr
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
Definition: qgsgeos.h:79
QgsFeatureRequest::setFilterRect
QgsFeatureRequest & setFilterRect(const QgsRectangle &rectangle)
Sets the rectangle from which features will be taken.
Definition: qgsfeaturerequest.cpp:97
QgsDiagramLayerSettings::ZIndex
@ ZIndex
Z-index for diagram ordering.
Definition: qgsdiagramrenderer.h:98
qgsvectorlayerdiagramprovider.h
QgsVectorLayerDiagramProvider::prepare
virtual bool prepare(const QgsRenderContext &context, QSet< QString > &attributeNames)
Prepare for registration of features.
Definition: qgsvectorlayerdiagramprovider.cpp:144
QgsFeature::id
QgsFeatureId id
Definition: qgsfeature.h:68
QgsRenderContext::coordinateTransform
QgsCoordinateTransform coordinateTransform() const
Returns the current coordinate transform for the context.
Definition: qgsrendercontext.h:229
QgsFeatureRequest
Definition: qgsfeaturerequest.h:75
feature.h
QgsPalLayerSettings::Placement
Placement
Placement modes which determine how label candidates are generated for a feature.
Definition: qgspallabeling.h:220
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:166
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:161
QgsCoordinateTransform::isShortCircuited
bool isShortCircuited() const
Returns true if the transform short circuits because the source and destination are equivalent.
Definition: qgscoordinatetransform.cpp:881
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:3542
QgsMapSettings::rotation
double rotation() const
Returns the rotation of the resulting map image, in degrees clockwise.
Definition: qgsmapsettings.cpp:101
QgsAbstractLabelProvider
The QgsAbstractLabelProvider class is an interface class. Implementations return list of labels and t...
Definition: qgslabelingengine.h:47
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:460
QgsDiagramLayerSettings::prepare
bool prepare(const QgsExpressionContext &context=QgsExpressionContext()) const
Prepares the diagrams for a specified expression context.
Definition: qgsdiagramrenderer.cpp:157
QgsVectorLayerDiagramProvider::mOwnsSource
bool mOwnsSource
Whether layer's feature source is owned.
Definition: qgsvectorlayerdiagramprovider.h:122
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:98
QgsFeature::setFields
void setFields(const QgsFields &fields, bool initAttributes=false)
Assign a field map with the feature to allow attribute access by attribute name.
Definition: qgsfeature.cpp:162
QgsDiagramLayerSettings::Distance
@ Distance
Distance to diagram from feature.
Definition: qgsdiagramrenderer.h:96
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:315
QgsRenderContext::featureFilterProvider
const QgsFeatureFilterProvider * featureFilterProvider() const
Gets the filter feature provider used for additional filtering of rendered features.
Definition: qgsrendercontext.cpp:282
QgsLabelFeature::setZIndex
void setZIndex(double zIndex)
Sets the label's z-index.
Definition: qgslabelfeature.h:170
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:201
QgsVectorLayerDiagramProvider::mFeatures
QList< QgsLabelFeature * > mFeatures
List of generated label features (owned by the provider)
Definition: qgsvectorlayerdiagramprovider.h:125
QgsPointXY::distance
double distance(double x, double y) const
Returns the distance between this point and a specified x, y coordinate.
Definition: qgspointxy.h:196
QgsLabelFeature::setObstacleSettings
void setObstacleSettings(const QgsLabelObstacleSettings &settings)
Sets the label's obstacle settings.
Definition: qgslabelfeature.cpp:108
QgsVectorLayerDiagramProvider::mFields
QgsFields mFields
Layer's fields.
Definition: qgsvectorlayerdiagramprovider.h:116
QgsDiagramLayerSettings
Stores the settings for rendering of all diagrams for a layer.
Definition: qgsdiagramrenderer.h:60
QgsLabelFeature::setFixedPosition
void setFixedPosition(const QgsPointXY &point)
Sets coordinates of the fixed position (relevant only if hasFixedPosition() returns true)
Definition: qgslabelfeature.h:180
QgsVectorLayerDiagramProvider::mLayerCrs
QgsCoordinateReferenceSystem mLayerCrs
Layer's CRS.
Definition: qgsvectorlayerdiagramprovider.h:118
QgsDiagramRenderer
Evaluates and returns the diagram settings relating to a diagram for a specific feature.
Definition: qgsdiagramrenderer.h:683
qgsvectorlayerfeatureiterator.h
QgsGeometry::isNull
bool isNull
Definition: qgsgeometry.h:125
QgsLabelFeature::setHasFixedPosition
void setHasFixedPosition(bool enabled)
Sets whether the label should use a fixed position instead of being automatically placed.
Definition: qgslabelfeature.h:175
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:156
QgsFeature::attributes
QgsAttributes attributes
Definition: qgsfeature.h:69
QgsMapToPixel::transform
QgsPointXY transform(const QgsPointXY &p) const
Transform the point from map (world) coordinates to device coordinates.
Definition: qgsmaptopixel.cpp:217
QgsDiagramLayerSettings::placement
Placement placement() const
Returns the diagram placement.
Definition: qgsdiagramrenderer.h:128
QgsDiagramLayerSettings::zIndex
double zIndex() const
Returns the diagram z-index.
Definition: qgsdiagramrenderer.h:181
QgsAbstractLabelProvider::mLayer
QgsWeakMapLayerPointer mLayer
Weak pointer to source layer.
Definition: qgslabelingengine.h:163
qgsvectorlayer.h
QgsPointXY
Definition: qgspointxy.h:43
QgsMapSettings::destinationCrs
QgsCoordinateReferenceSystem destinationCrs() const
returns CRS of destination coordinate reference system
Definition: qgsmapsettings.cpp:317
QgsDiagramLayerSettings::setRenderer
void setRenderer(QgsDiagramRenderer *diagramRenderer)
Sets the diagram renderer associated with the layer.
Definition: qgsdiagramrenderer.cpp:106
QgsGeometry::get
QgsAbstractGeometry * get()
Returns a modifiable (non-const) reference to the underlying abstract geometry primitive.
Definition: qgsgeometry.cpp:133
qgsgeometry.h
QgsRectangle::center
QgsPointXY center() const
Returns the center point of the rectangle.
Definition: qgsrectangle.h:230
QgsLabelingEngine::mapSettings
const QgsMapSettings & mapSettings() const
Gets associated map settings.
Definition: qgslabelingengine.h:230
pal::LabelPosition::getHeight
double getHeight() const
Definition: labelposition.h:260
QgsFeatureIterator::nextFeature
bool nextFeature(QgsFeature &f)
Definition: qgsfeatureiterator.h:373
QgsGeometry
Definition: qgsgeometry.h:122
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
Definition: qgsmaptopixel.h:37
QgsDiagramLayerSettings::distance
double distance() const
Returns the distance between the diagram and the feature (in mm).
Definition: qgsdiagramrenderer.h:212
QgsLabelingEngine::results
QgsLabelingResults * results() const
For internal use by the providers.
Definition: qgslabelingengine.h:266
QgsVectorLayer
Definition: qgsvectorlayer.h:385
QgsRenderContext::transformContext
QgsCoordinateTransformContext transformContext() const
Returns the context's coordinate transform context, which stores various information regarding which ...
Definition: qgsrendercontext.cpp:130
QgsDiagramLabelFeature::attributes
const QgsAttributes & attributes()
Gets feature's attributes - used for rendering of diagrams.
Definition: qgsvectorlayerdiagramprovider.h:43
QgsPointXY::x
double x
Definition: qgspointxy.h:47
pal::LabelPosition::getX
double getX(int i=0) const
Returns the down-left x coordinate.
Definition: labelposition.cpp:348
QgsVectorLayerFeatureSource
Definition: qgsvectorlayerfeatureiterator.h:51
QgsVectorLayerDiagramProvider::~QgsVectorLayerDiagramProvider
~QgsVectorLayerDiagramProvider() override
Clean up.
Definition: qgsvectorlayerdiagramprovider.cpp:49
QgsPropertyCollection::hasProperty
bool hasProperty(int key) const override
Returns true if the collection contains a property with the specified key.
Definition: qgspropertycollection.cpp:193
QgsDiagramLabelFeature::setAttributes
void setAttributes(const QgsAttributes &attrs)
Store feature's attributes - used for rendering of diagrams.
Definition: qgsvectorlayerdiagramprovider.h:41
QgsFeatureFilterProvider
Definition: qgsfeaturefilterprovider.h:40
QgsLabelFeature::setFixedAngle
void setFixedAngle(double angle)
Sets angle in degrees of the fixed angle (relevant only if hasFixedAngle() returns true)
Definition: qgslabelfeature.h:205
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:120
QgsFeature
Definition: qgsfeature.h:55
QgsLabelFeature
The QgsLabelFeature class describes a feature that should be used within the labeling engine....
Definition: qgslabelfeature.h:56
QgsDiagramLayerSettings::AlwaysShow
@ AlwaysShow
Whether the diagram should always be shown, even if it overlaps other diagrams/labels.
Definition: qgsdiagramrenderer.h:101
QgsDiagramLayerSettings::PositionX
@ PositionX
X-coordinate data defined diagram position.
Definition: qgsdiagramrenderer.h:94
QgsFeature::setAttributes
void setAttributes(const QgsAttributes &attrs)
Sets the feature's attributes.
Definition: qgsfeature.cpp:127
pal::FeaturePart::featureId
QgsFeatureId featureId() const
Returns the unique ID of the feature.
Definition: feature.cpp:157
QgsRenderContext::rendererScale
double rendererScale() const
Returns the renderer map scale.
Definition: qgsrendercontext.h:361
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:169
QgsMapSettings
Definition: qgsmapsettings.h:86
QgsMapSettings::visibleExtent
QgsRectangle visibleExtent() const
Returns the actual extent derived from requested extent that takes takes output image size into accou...
Definition: qgsmapsettings.cpp:370
QgsCoordinateTransform
Definition: qgscoordinatetransform.h:52
pal::FeaturePart::feature
QgsLabelFeature * feature()
Returns the parent feature.
Definition: feature.h:117
QgsFeatureIterator
Definition: qgsfeatureiterator.h:263
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:60
QgsMapToPixel::setMapRotation
void setMapRotation(double degrees, double cx, double cy)
Set map rotation in degrees (clockwise)
Definition: qgsmaptopixel.cpp:133
QgsAbstractLabelProvider::mPlacement
QgsPalLayerSettings::Placement mPlacement
Placement strategy.
Definition: qgslabelingengine.h:169
QgsDiagramLayerSettings::IsObstacle
@ IsObstacle
Whether diagram features act as obstacles for other diagrams/labels.
Definition: qgsdiagramrenderer.h:99
QgsMapSettings::mapToPixel
const QgsMapToPixel & mapToPixel() const
Definition: qgsmapsettings.h:433
QgsDiagramLayerSettings::Priority
@ Priority
Diagram priority (between 0 and 10)
Definition: qgsdiagramrenderer.h:97
QgsAbstractLabelProvider::mPriority
double mPriority
Default priority of labels.
Definition: qgslabelingengine.h:171
qgsgeos.h
QgsDiagramLayerSettings::setCoordinateTransform
void setCoordinateTransform(const QgsCoordinateTransform &transform)
Sets the coordinate transform associated with the layer.
Definition: qgsdiagramrenderer.cpp:115
QgsLabelFeature::setAlwaysShow
void setAlwaysShow(bool enabled)
Sets whether label should be always shown (sets very high label priority)
Definition: qgslabelfeature.h:306
QgsExpressionContext::setFeature
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
Definition: qgsexpressioncontext.cpp:521
pal::LabelPosition::getWidth
double getWidth() const
Definition: labelposition.h:259
QgsCoordinateTransform::transformInPlace
void transformInPlace(double &x, double &y, double &z, TransformDirection direction=ForwardTransform) 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:313