QgsRuleBasedLabelProvider class

Base classes

class QgsVectorLayerLabelProvider
The QgsVectorLayerLabelProvider class implements a label provider for vector layers.

Derived classes

class QgsDxfRuleBasedLabelProvider
Implements a derived label provider for rule based labels internally used for DXF export.

Public functions

auto createProvider(QgsVectorLayer* layer, const QString& providerId, bool withFeatureLoop, const QgsPalLayerSettings* settings) -> QgsVectorLayerLabelProvider* virtual
create a label provider
auto prepare(const QgsRenderContext& context, QSet<QString>& attributeNames) -> bool override
Prepare for registration of features.
void registerFeature(QgsFeature& feature, QgsRenderContext& context, const QgsGeometry& obstacleGeometry = QgsGeometry()) override
Register a feature for labeling as one or more QgsLabelFeature objects stored into mLabels.
auto subProviders() -> QList<QgsAbstractLabelProvider*> override
Returns subproviders.

Protected variables

std::unique_ptr<QgsRuleBasedLabeling> mRules
owned copy
QgsRuleBasedLabeling::RuleToProviderMap mSubProviders
label providers are owned by labeling engine

Function documentation

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

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 QgsRuleBasedLabelProvider::registerFeature(QgsFeature& feature, QgsRenderContext& context, const QgsGeometry& obstacleGeometry = QgsGeometry()) override

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

Parameters
feature feature to label
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.