QGIS API Documentation 3.41.0-Master (45a0abf3bec)
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
QgsVectorLayerDiagramProvider Class Reference

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

#include <qgsvectorlayerdiagramprovider.h>

Inheritance diagram for QgsVectorLayerDiagramProvider:
Inheritance graph
[legend]

Public Member Functions

 QgsVectorLayerDiagramProvider (QgsVectorLayer *layer, bool ownFeatureLoop=true)
 Convenience constructor to initialize the provider from given vector layer.
 
 ~QgsVectorLayerDiagramProvider () override
 Clean up.
 
void drawLabel (QgsRenderContext &context, pal::LabelPosition *label) const override
 Draw this label at the position determined by the labeling engine.
 
QList< QgsLabelFeature * > labelFeatures (QgsRenderContext &context) override
 Returns list of label features (they are owned by the provider and thus deleted on its destruction)
 
virtual bool prepare (const QgsRenderContext &context, QSet< QString > &attributeNames)
 Prepare for registration of features.
 
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.
 
void setClipFeatureGeometry (const QgsGeometry &geometry)
 Sets a geometry to use to clip features to when registering them as diagrams.
 
- Public Member Functions inherited from QgsAbstractLabelProvider
 QgsAbstractLabelProvider (QgsMapLayer *layer, const QString &providerId=QString())
 Construct the provider with default values.
 
virtual ~QgsAbstractLabelProvider ()=default
 
virtual void drawLabelBackground (QgsRenderContext &context, pal::LabelPosition *label) const
 Draw the background for the specified label.
 
virtual void drawUnplacedLabel (QgsRenderContext &context, pal::LabelPosition *label) const
 Draw an unplaced label.
 
Flags flags () const
 Flags associated with the provider.
 
QgsMapLayerlayer () const
 Returns the associated layer, or nullptr if no layer is associated with the provider.
 
QgsExpressionContextScopelayerExpressionContextScope () const
 Returns the expression context scope created from the layer associated with this provider.
 
QString layerId () const
 Returns ID of associated layer, or empty string if no layer is associated with the provider.
 
double layerReferenceScale () const
 Returns the symbology reference scale of the layer associated with this provider.
 
QString name () const
 Name of the layer (for statistics, debugging etc.) - does not need to be unique.
 
QgsLabelObstacleSettings::ObstacleType obstacleType () const
 How the feature geometries will work as obstacles.
 
Qgis::LabelPlacement placement () const
 What placement strategy to use for the labels.
 
double priority () const
 Default priority of labels (may be overridden by individual labels)
 
QString providerId () const
 Returns provider ID - useful in case there is more than one label provider within a layer (e.g.
 
void setEngine (const QgsLabelingEngine *engine)
 Associate provider with a labeling engine (should be only called internally from QgsLabelingEngine)
 
virtual void startRender (QgsRenderContext &context)
 To be called before rendering of labels begins.
 
virtual void stopRender (QgsRenderContext &context)
 To be called after rendering is complete.
 
virtual QList< QgsAbstractLabelProvider * > subProviders ()
 Returns list of child providers - useful if the provider needs to put labels into more layers with different configuration.
 
Qgis::UpsideDownLabelHandling upsidedownLabels () const
 How to handle labels that would be upside down.
 

Protected Member Functions

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

Protected Attributes

QgsDiagramRenderermDiagRenderer = nullptr
 Diagram renderer instance (owned by mSettings)
 
QList< QgsLabelFeature * > mFeatures
 List of generated label features (owned by the provider)
 
QgsFields mFields
 Layer's fields.
 
QgsGeometry mLabelClipFeatureGeom
 
QgsCoordinateReferenceSystem mLayerCrs
 Layer's CRS.
 
std::unique_ptr< QgsExpressionContextScopemLayerScope
 
bool mOwnsSource
 Whether layer's feature source is owned.
 
QgsDiagramLayerSettings mSettings
 Diagram layer settings.
 
QgsAbstractFeatureSourcemSource = nullptr
 Layer's feature source.
 
- Protected Attributes inherited from QgsAbstractLabelProvider
const QgsLabelingEnginemEngine = nullptr
 Associated labeling engine.
 
Flags mFlags = DrawLabels
 Flags altering drawing and registration of features.
 
QgsWeakMapLayerPointer mLayer
 Weak pointer to source layer.
 
QString mLayerId
 Associated layer's ID, if applicable.
 
QString mName
 Name of the layer.
 
QgsLabelObstacleSettings::ObstacleType mObstacleType = QgsLabelObstacleSettings::ObstacleType::PolygonBoundary
 Type of the obstacle of feature geometries.
 
Qgis::LabelPlacement mPlacement = Qgis::LabelPlacement::AroundPoint
 Placement strategy.
 
double mPriority = 0.5
 Default priority of labels.
 
QString mProviderId
 Associated provider ID (one layer may have multiple providers, e.g. in rule-based labeling)
 
Qgis::UpsideDownLabelHandling mUpsidedownLabels = Qgis::UpsideDownLabelHandling::FlipUpsideDownLabels
 How to handle labels that would be upside down.
 

Additional Inherited Members

- Public Types inherited from QgsAbstractLabelProvider
enum  Flag { DrawLabels = 1 << 1 , MergeConnectedLines = 1 << 3 , CentroidMustBeInside = 1 << 4 }
 
typedef QFlags< FlagFlags
 

Detailed Description

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

Parameters for the diagrams are taken from the layer settings.

Note
this class is not a part of public API yet. See notes in QgsLabelingEngine
not available in Python bindings

Definition at line 56 of file qgsvectorlayerdiagramprovider.h.

Constructor & Destructor Documentation

◆ QgsVectorLayerDiagramProvider()

QgsVectorLayerDiagramProvider::QgsVectorLayerDiagramProvider ( QgsVectorLayer layer,
bool  ownFeatureLoop = true 
)
explicit

Convenience constructor to initialize the provider from given vector layer.

Definition at line 32 of file qgsvectorlayerdiagramprovider.cpp.

◆ ~QgsVectorLayerDiagramProvider()

QgsVectorLayerDiagramProvider::~QgsVectorLayerDiagramProvider ( )
override

Clean up.

Definition at line 56 of file qgsvectorlayerdiagramprovider.cpp.

Member Function Documentation

◆ drawLabel()

void QgsVectorLayerDiagramProvider::drawLabel ( QgsRenderContext context,
pal::LabelPosition label 
) const
overridevirtual

Draw this label at the position determined by the labeling engine.

Before any calls to drawLabel(), a provider should be prepared for rendering by a call to startRender() and a corresponding call to stopRender().

Implements QgsAbstractLabelProvider.

Definition at line 109 of file qgsvectorlayerdiagramprovider.cpp.

◆ init()

void QgsVectorLayerDiagramProvider::init ( )
protected

initialization method - called from constructors

Definition at line 48 of file qgsvectorlayerdiagramprovider.cpp.

◆ labelFeatures()

QList< QgsLabelFeature * > QgsVectorLayerDiagramProvider::labelFeatures ( QgsRenderContext context)
overridevirtual

Returns list of label features (they are owned by the provider and thus deleted on its destruction)

Implements QgsAbstractLabelProvider.

Definition at line 67 of file qgsvectorlayerdiagramprovider.cpp.

◆ prepare()

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

Prepare for registration of features.

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

Parameters
contextrender context.
attributeNameslist 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

Definition at line 151 of file qgsvectorlayerdiagramprovider.cpp.

◆ registerDiagram()

QgsLabelFeature * QgsVectorLayerDiagramProvider::registerDiagram ( const QgsFeature feat,
QgsRenderContext context,
const QgsGeometry obstacleGeometry = QgsGeometry() 
)
protected

helper method to register one diagram feature

Definition at line 188 of file qgsvectorlayerdiagramprovider.cpp.

◆ registerFeature()

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
featurefeature for diagram
contextrender context. The QgsExpressionContext contained within the render context must have already had the feature and fields sets prior to calling this method.
obstacleGeometryoptional 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.

Definition at line 176 of file qgsvectorlayerdiagramprovider.cpp.

◆ setClipFeatureGeometry()

void QgsVectorLayerDiagramProvider::setClipFeatureGeometry ( const QgsGeometry geometry)

Sets a geometry to use to clip features to when registering them as diagrams.

Since
QGIS 3.16

Definition at line 183 of file qgsvectorlayerdiagramprovider.cpp.

Member Data Documentation

◆ mDiagRenderer

QgsDiagramRenderer* QgsVectorLayerDiagramProvider::mDiagRenderer = nullptr
protected

Diagram renderer instance (owned by mSettings)

Definition at line 112 of file qgsvectorlayerdiagramprovider.h.

◆ mFeatures

QList<QgsLabelFeature *> QgsVectorLayerDiagramProvider::mFeatures
protected

List of generated label features (owned by the provider)

Definition at line 126 of file qgsvectorlayerdiagramprovider.h.

◆ mFields

QgsFields QgsVectorLayerDiagramProvider::mFields
protected

Layer's fields.

Definition at line 117 of file qgsvectorlayerdiagramprovider.h.

◆ mLabelClipFeatureGeom

QgsGeometry QgsVectorLayerDiagramProvider::mLabelClipFeatureGeom
protected

Definition at line 130 of file qgsvectorlayerdiagramprovider.h.

◆ mLayerCrs

QgsCoordinateReferenceSystem QgsVectorLayerDiagramProvider::mLayerCrs
protected

Layer's CRS.

Definition at line 119 of file qgsvectorlayerdiagramprovider.h.

◆ mLayerScope

std::unique_ptr< QgsExpressionContextScope > QgsVectorLayerDiagramProvider::mLayerScope
protected

Definition at line 128 of file qgsvectorlayerdiagramprovider.h.

◆ mOwnsSource

bool QgsVectorLayerDiagramProvider::mOwnsSource
protected

Whether layer's feature source is owned.

Definition at line 123 of file qgsvectorlayerdiagramprovider.h.

◆ mSettings

QgsDiagramLayerSettings QgsVectorLayerDiagramProvider::mSettings
protected

Diagram layer settings.

Definition at line 110 of file qgsvectorlayerdiagramprovider.h.

◆ mSource

QgsAbstractFeatureSource* QgsVectorLayerDiagramProvider::mSource = nullptr
protected

Layer's feature source.

Definition at line 121 of file qgsvectorlayerdiagramprovider.h.


The documentation for this class was generated from the following files: