Skip to content
Permalink
Browse files
[api] add unplaced label handling to the QgsLabelSink class
  • Loading branch information
nirvn committed Jan 4, 2022
1 parent fb93c7b commit cf26d6088b3b90d6056f2093599bf9c13bf09ff0
Showing with 31 additions and 0 deletions.
  1. +12 −0 src/core/labeling/qgslabelsink.cpp
  2. +19 −0 src/core/labeling/qgslabelsink.h
@@ -32,6 +32,12 @@ void QgsLabelSinkProvider::drawLabel( QgsRenderContext &context, pal::LabelPosit
mLabelSink->drawLabel( layerId(), context, label, mSettings );
}

void QgsLabelSinkProvider::drawUnplacedLabel( QgsRenderContext &context, pal::LabelPosition *label ) const
{
Q_ASSERT( mLabelSink );
mLabelSink->drawUnplacedLabel( layerId(), context, label, mSettings );
}

QgsRuleBasedLabelSinkProvider::QgsRuleBasedLabelSinkProvider( const QgsRuleBasedLabeling &rules, QgsVectorLayer *layer, QgsLabelSink *sink )
: QgsRuleBasedLabelProvider( rules, layer, false )
, mLabelSink( sink )
@@ -55,3 +61,9 @@ void QgsRuleBasedLabelSinkProvider::drawLabel( QgsRenderContext &context, pal::L
Q_ASSERT( mLabelSink );
mLabelSink->drawLabel( layerId(), context, label, mSettings );
}

void QgsRuleBasedLabelSinkProvider::drawUnplacedLabel( QgsRenderContext &context, pal::LabelPosition *label ) const
{
Q_ASSERT( mLabelSink );
mLabelSink->drawUnplacedLabel( layerId(), context, label, mSettings );
}
@@ -45,6 +45,23 @@ class QgsLabelSink
* to another desired location.
*/
virtual void drawLabel( const QString &layerId, QgsRenderContext &context, pal::LabelPosition *label, const QgsPalLayerSettings &settings ) = 0;

/**
* The drawLabel method is called for each unplaced label.
* \param layerId The layer ID associated to the label
* \param context The render context object
* \param label The label object
* \param settings The layer labeling settings
* \since QGIS 3.24
*/
virtual void drawUnplacedLabel( const QString &layerId, QgsRenderContext &context, pal::LabelPosition *label, const QgsPalLayerSettings &settings )
{
Q_UNUSED( layerId );
Q_UNUSED( context )
Q_UNUSED( label );
Q_UNUSED( settings );
return;
}
};

/**
@@ -61,6 +78,7 @@ class QgsLabelSinkProvider : public QgsVectorLayerLabelProvider
explicit QgsLabelSinkProvider( QgsVectorLayer *layer, const QString &providerId, QgsLabelSink *sink, const QgsPalLayerSettings *settings );

void drawLabel( QgsRenderContext &context, pal::LabelPosition *label ) const override;
void drawUnplacedLabel( QgsRenderContext &context, pal::LabelPosition *label ) const override;

private:
QgsLabelSink *mLabelSink = nullptr;
@@ -86,6 +104,7 @@ class QgsRuleBasedLabelSinkProvider : public QgsRuleBasedLabelProvider
Q_DECL_DEPRECATED void reinit( QgsVectorLayer *layer );

void drawLabel( QgsRenderContext &context, pal::LabelPosition *label ) const override;
void drawUnplacedLabel( QgsRenderContext &context, pal::LabelPosition *label ) const override;

//! Creates a QgsRuleBasedLabelSinkProvider
QgsVectorLayerLabelProvider *createProvider( QgsVectorLayer *layer, const QString &providerId, bool withFeatureLoop, const QgsPalLayerSettings *settings ) override;

0 comments on commit cf26d60

Please sign in to comment.