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

Label provider for rule based labeling. More...

#include <qgsrulebasedlabeling.h>

Inheritance diagram for QgsRuleBasedLabelProvider:
Inheritance graph
[legend]

Public Member Functions

 QgsRuleBasedLabelProvider (const QgsRuleBasedLabeling &rules, QgsVectorLayer *layer, bool withFeatureLoop=true)
 
virtual QgsVectorLayerLabelProvidercreateProvider (QgsVectorLayer *layer, const QString &providerId, bool withFeatureLoop, const QgsPalLayerSettings *settings)
 create a label provider
 
bool prepare (QgsRenderContext &context, QSet< QString > &attributeNames) override
 Prepare for registration of features.
 
QList< QgsLabelFeature * > registerFeature (const QgsFeature &feature, QgsRenderContext &context, const QgsGeometry &obstacleGeometry=QgsGeometry(), const QgsSymbol *symbol=nullptr) override
 Register a feature for labeling as one or more QgsLabelFeature objects stored into mLabels.
 
QList< QgsAbstractLabelProvider * > subProviders () override
 Returns subproviders.
 
- Public Member Functions inherited from QgsVectorLayerLabelProvider
 QgsVectorLayerLabelProvider (Qgis::GeometryType geometryType, const QgsFields &fields, const QgsCoordinateReferenceSystem &crs, const QString &providerId, const QgsPalLayerSettings *settings, QgsMapLayer *layer, const QString &layerName=QString())
 Constructor to initialize the provider from any map layer (e.g. vector tile layer)
 
 QgsVectorLayerLabelProvider (QgsVectorLayer *layer, const QString &providerId, bool withFeatureLoop, const QgsPalLayerSettings *settings, const QString &layerName=QString())
 Convenience constructor to initialize the provider from given vector layer.
 
 ~QgsVectorLayerLabelProvider () override
 
void drawLabel (QgsRenderContext &context, pal::LabelPosition *label) const override
 Draw this label at the position determined by the labeling engine.
 
void drawLabelBackground (QgsRenderContext &context, pal::LabelPosition *label) const override
 Draw the background for the specified label.
 
void drawUnplacedLabel (QgsRenderContext &context, pal::LabelPosition *label) const override
 Draw an unplaced label.
 
QList< QgsLabelFeature * > labelFeatures (QgsRenderContext &context) override
 Returns list of label features (they are owned by the provider and thus deleted on its destruction)
 
void setFields (const QgsFields &fields)
 Sets fields of this label provider.
 
const QgsPalLayerSettingssettings () const
 Returns the layer's settings.
 
void startRender (QgsRenderContext &context) override
 To be called before rendering of labels begins.
 
void stopRender (QgsRenderContext &context) override
 To be called after rendering is complete.
 
- Public Member Functions inherited from QgsAbstractLabelProvider
 QgsAbstractLabelProvider (QgsMapLayer *layer, const QString &providerId=QString())
 Construct the provider with default values.
 
virtual ~QgsAbstractLabelProvider ()=default
 
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)
 
Qgis::UpsideDownLabelHandling upsidedownLabels () const
 How to handle labels that would be upside down.
 

Protected Attributes

std::unique_ptr< QgsRuleBasedLabelingmRules
 owned copy
 
QgsRuleBasedLabeling::RuleToProviderMap mSubProviders
 label providers are owned by labeling engine
 
- Protected Attributes inherited from QgsVectorLayerLabelProvider
QgsCoordinateReferenceSystem mCrs
 Layer's CRS.
 
QgsFields mFields
 Layer's fields.
 
QList< QgsLabelFeature * > mLabels
 List of generated.
 
Qgis::GeometryType mLayerGeometryType
 Geometry type of layer.
 
QgsFeatureRenderermRenderer = nullptr
 
QgsPalLayerSettings mSettings
 Layer's labeling configuration.
 
std::unique_ptr< QgsAbstractFeatureSourcemSource
 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
 
- Static Public Member Functions inherited from QgsVectorLayerLabelProvider
static QgsGeometry getPointObstacleGeometry (QgsFeature &fet, QgsRenderContext &context, const QgsSymbolList &symbols)
 Returns the geometry for a point feature which should be used as an obstacle for labels.
 
- Protected Member Functions inherited from QgsVectorLayerLabelProvider
void drawLabelPrivate (pal::LabelPosition *label, QgsRenderContext &context, QgsPalLayerSettings &tmpLyr, Qgis::TextComponent drawType, double dpiRatio=1.0) const
 Internal label drawing method.
 
void init ()
 initialization method - called from constructors
 

Detailed Description

Label provider for rule based labeling.

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

Definition at line 407 of file qgsrulebasedlabeling.h.

Constructor & Destructor Documentation

◆ QgsRuleBasedLabelProvider()

QgsRuleBasedLabelProvider::QgsRuleBasedLabelProvider ( const QgsRuleBasedLabeling rules,
QgsVectorLayer layer,
bool  withFeatureLoop = true 
)

Definition at line 20 of file qgsrulebasedlabeling.cpp.

Member Function Documentation

◆ createProvider()

QgsVectorLayerLabelProvider * QgsRuleBasedLabelProvider::createProvider ( QgsVectorLayer layer,
const QString &  providerId,
bool  withFeatureLoop,
const QgsPalLayerSettings settings 
)
virtual

create a label provider

Reimplemented in QgsRuleBasedLabelSinkProvider.

Definition at line 27 of file qgsrulebasedlabeling.cpp.

◆ prepare()

bool QgsRuleBasedLabelProvider::prepare ( QgsRenderContext context,
QSet< QString > &  attributeNames 
)
overridevirtual

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

Reimplemented from QgsVectorLayerLabelProvider.

Definition at line 32 of file qgsrulebasedlabeling.cpp.

◆ registerFeature()

QList< QgsLabelFeature * > QgsRuleBasedLabelProvider::registerFeature ( const QgsFeature feature,
QgsRenderContext context,
const QgsGeometry obstacleGeometry = QgsGeometry(),
const QgsSymbol symbol = nullptr 
)
overridevirtual

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

Parameters
featurefeature to label
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.
symbolfeature symbol to label (ownership is not transferred - the symbol must exist until after labeling is complete)
Returns
a list of the newly generated label features. Ownership of these label features is not transferred (it has already been assigned to the label provider).

Reimplemented from QgsVectorLayerLabelProvider.

Definition at line 42 of file qgsrulebasedlabeling.cpp.

◆ subProviders()

QList< QgsAbstractLabelProvider * > QgsRuleBasedLabelProvider::subProviders ( )
overridevirtual

Returns subproviders.

Reimplemented from QgsAbstractLabelProvider.

Definition at line 48 of file qgsrulebasedlabeling.cpp.

Member Data Documentation

◆ mRules

std::unique_ptr<QgsRuleBasedLabeling> QgsRuleBasedLabelProvider::mRules
protected

owned copy

Definition at line 426 of file qgsrulebasedlabeling.h.

◆ mSubProviders

QgsRuleBasedLabeling::RuleToProviderMap QgsRuleBasedLabelProvider::mSubProviders
protected

label providers are owned by labeling engine

Definition at line 428 of file qgsrulebasedlabeling.h.


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