QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgslabelsink.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgslabelsink.cpp
3  ---------------------
4  begin : January 2014
5  copyright : (C) 2014 by Marco Hugentobler
6  email : marco at sourcepole dot ch
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "qgslabelsink.h"
19 #include "qgspallabeling.h"
20 #include "qgsmapsettings.h"
21 #include "qgslogger.h"
22 
23 QgsLabelSinkProvider::QgsLabelSinkProvider( QgsVectorLayer *layer, const QString &providerId, QgsLabelSink *dxf, const QgsPalLayerSettings *settings )
24  : QgsVectorLayerLabelProvider( layer, providerId, false, settings )
25  , mLabelSink( dxf )
26 {
27 }
28 
30 {
31  Q_ASSERT( mLabelSink );
32  mLabelSink->drawLabel( layerId(), context, label, mSettings );
33 }
34 
36  : QgsRuleBasedLabelProvider( rules, layer, false )
37  , mLabelSink( dxf )
38 {
39  mRules->rootRule()->createSubProviders( layer, mSubProviders, this );
40 }
41 
43 {
44  mRules->rootRule()->createSubProviders( layer, mSubProviders, this );
45 }
46 
47 QgsVectorLayerLabelProvider *QgsRuleBasedLabelSinkProvider::createProvider( QgsVectorLayer *layer, const QString &providerId, bool withFeatureLoop, const QgsPalLayerSettings *settings )
48 {
49  Q_UNUSED( withFeatureLoop )
50  return new QgsLabelSinkProvider( layer, providerId, mLabelSink, settings );
51 }
52 
54 {
55  Q_ASSERT( mLabelSink );
56  mLabelSink->drawLabel( layerId(), context, label, mSettings );
57 }
qgspallabeling.h
QgsAbstractLabelProvider::layerId
QString layerId() const
Returns ID of associated layer, or empty string if no layer is associated with the provider.
Definition: qgslabelingengine.h:127
QgsPalLayerSettings
Definition: qgspallabeling.h:207
QgsRuleBasedLabelProvider::mRules
std::unique_ptr< QgsRuleBasedLabeling > mRules
owned copy
Definition: qgsrulebasedlabeling.h:420
pal::LabelPosition
LabelPosition is a candidate feature label position.
Definition: labelposition.h:56
QgsLabelSink
Abstract base class that can be used to intercept rendered labels from a labeling / rendering job.
Definition: qgslabelsink.h:38
QgsRenderContext
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:58
qgsmapsettings.h
QgsRuleBasedLabelSinkProvider::QgsRuleBasedLabelSinkProvider
QgsRuleBasedLabelSinkProvider(const QgsRuleBasedLabeling &rules, QgsVectorLayer *layer, QgsLabelSink *sink)
Creates a rule based label sink provider which will draw/register labels in sink.
Definition: qgslabelsink.cpp:35
QgsVectorLayerLabelProvider
The QgsVectorLayerLabelProvider class implements a label provider for vector layers.
Definition: qgsvectorlayerlabelprovider.h:41
QgsRuleBasedLabeling
Definition: qgsrulebasedlabeling.h:41
QgsVectorLayerLabelProvider::settings
const QgsPalLayerSettings & settings() const
Returns the layer's settings.
Definition: qgsvectorlayerlabelprovider.cpp:654
QgsRuleBasedLabelProvider::mSubProviders
QgsRuleBasedLabeling::RuleToProviderMap mSubProviders
label providers are owned by labeling engine
Definition: qgsrulebasedlabeling.h:422
qgslabelsink.h
QgsRuleBasedLabelSinkProvider::drawLabel
void drawLabel(QgsRenderContext &context, pal::LabelPosition *label) const override
Draw this label at the position determined by the labeling engine.
Definition: qgslabelsink.cpp:53
QgsLabelSinkProvider::QgsLabelSinkProvider
QgsLabelSinkProvider(QgsVectorLayer *layer, const QString &providerId, QgsLabelSink *sink, const QgsPalLayerSettings *settings)
Creates a rule based label sink provider which will draw/register labels in sink.
Definition: qgslabelsink.cpp:23
QgsRuleBasedLabelSinkProvider::reinit
Q_DECL_DEPRECATED void reinit(QgsVectorLayer *layer)
Reinitialize the subproviders with QgsLabelSinkProviders.
Definition: qgslabelsink.cpp:42
QgsAbstractLabelProvider::providerId
QString providerId() const
Returns provider ID - useful in case there is more than one label provider within a layer (e....
Definition: qgslabelingengine.h:137
QgsLabelSink::drawLabel
virtual void drawLabel(const QString &layerId, QgsRenderContext &context, pal::LabelPosition *label, const QgsPalLayerSettings &settings)=0
The drawLabel method is called for each label that is being drawn.
QgsLabelSinkProvider::drawLabel
void drawLabel(QgsRenderContext &context, pal::LabelPosition *label) const override
Draw this label at the position determined by the labeling engine.
Definition: qgslabelsink.cpp:29
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:387
QgsLabelSinkProvider
Implements a derived label provider for use with QgsLabelSink.
Definition: qgslabelsink.h:58
QgsVectorLayerLabelProvider::mSettings
QgsPalLayerSettings mSettings
Layer's labeling configuration.
Definition: qgsvectorlayerlabelprovider.h:127
QgsAbstractLabelProvider::layer
QgsMapLayer * layer() const
Returns the associated layer, or nullptr if no layer is associated with the provider.
Definition: qgslabelingengine.h:130
qgslogger.h
QgsRuleBasedLabelSinkProvider::createProvider
QgsVectorLayerLabelProvider * createProvider(QgsVectorLayer *layer, const QString &providerId, bool withFeatureLoop, const QgsPalLayerSettings *settings) override
Creates a QgsRuleBasedLabelSinkProvider.
Definition: qgslabelsink.cpp:47
QgsRuleBasedLabelProvider
Definition: qgsrulebasedlabeling.h:402