QgsVectorLayerDiagramProvider class

The QgsVectorLayerDiagramProvider class implements support for diagrams within the labeling engine.

Parameters for the diagrams are taken from the layer settings.

Base classes

class QgsAbstractLabelProvider
The QgsAbstractLabelProvider class is an interface class.

Constructors, destructors, conversion operators

QgsVectorLayerDiagramProvider(QgsVectorLayer* layer, bool ownFeatureLoop = true) explicit
Convenience constructor to initialize the provider from given vector layer.
~QgsVectorLayerDiagramProvider() override
Clean up.

Public functions

void drawLabel(QgsRenderContext& context, pal::LabelPosition* label) const override
draw this label at the position determined by the labeling engine
auto labelFeatures(QgsRenderContext& context) -> QList<QgsLabelFeature*> override
Returns list of label features (they are owned by the provider and thus deleted on its destruction)
auto prepare(const QgsRenderContext& context, QSet<QString>& attributeNames) -> bool virtual
Prepare for registration of features.
void registerFeature(QgsFeature& feature, QgsRenderContext& context, const QgsGeometry& obstacleGeometry = QgsGeometry()) virtual
Register a feature for labeling as one or more QgsLabelFeature objects stored into mFeatures.

Protected functions

void init()
initialization method - called from constructors
auto registerDiagram(QgsFeature& feat, QgsRenderContext& context, const QgsGeometry& obstacleGeometry = QgsGeometry()) -> QgsLabelFeature*
helper method to register one diagram feature

Protected variables

QgsDiagramRenderer* mDiagRenderer
Diagram renderer instance (owned by mSettings)
QList<QgsLabelFeature*> mFeatures
List of generated label features (owned by the provider)
QgsFields mFields
Layer's fields.
QgsCoordinateReferenceSystem mLayerCrs
Layer's CRS.
bool mOwnsSource
Whether layer's feature source is owned.
QgsDiagramLayerSettings mSettings
Diagram layer settings.
QgsAbstractFeatureSource* mSource
Layer's feature source.

Function documentation

bool QgsVectorLayerDiagramProvider::prepare(const QgsRenderContext& context, QSet<QString>& attributeNames) virtual

Prepare for registration of features.

Parameters
context render context.
attributeNames list of attribute names to which additional required attributes shall be added
Returns Whether the preparation was successful - if not, the provider shall not be used

Must be called after provider has been added to engine (uses its map settings)

void QgsVectorLayerDiagramProvider::registerFeature(QgsFeature& feature, QgsRenderContext& context, const QgsGeometry& obstacleGeometry = QgsGeometry()) virtual

Register a feature for labeling as one or more QgsLabelFeature objects stored into mFeatures.

Parameters
feature feature for diagram
context render context. The QgsExpressionContext contained within the render context must have already had the feature and fields sets prior to calling this method.
obstacleGeometry optional obstacle geometry, if a different geometry to the feature's geometry should be used as an obstacle for labels (e.g., if the feature has been rendered with an offset point symbol, the obstacle geometry should represent the bounds of the offset symbol). If not set, the feature's original geometry will be used as an obstacle for labels. Ownership of obstacleGeometry is transferred.