1 /***************************************************************************
2                          qgslabelsink.h
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 #ifndef QGSLABELSINK_H
19 #define QGSLABELSINK_H
20 
21 #define SIP_NO_FILE
22 
23 #include "qgsvectorlayerlabelprovider.h"
24 #include "qgsrulebasedlabeling.h"
25 
26 class QgsPalLayerSettings;
27 class QgsRuleBasedLabeling;
28 
29 /**
30  * \ingroup core
31  * \brief Abstract base class that can be used to intercept rendered labels from
32  * a labeling / rendering job.
33  *
34  * \note not available in Python bindings
35  * \since QGIS 3.14
36  */
37 class QgsLabelSink
38 {
39   public:
40     virtual ~QgsLabelSink() = default;
41 
42     /**
43      * The drawLabel method is called for each label that is being drawn.
44      * Every subclass must implement this method to draw the label or send the information from \a label
45      * to another desired location.
46      */
47     virtual void drawLabel( const QString &layerId, QgsRenderContext &context, pal::LabelPosition *label, const QgsPalLayerSettings &settings ) = 0;
48 };
49 
50 /**
51  * \ingroup core
52  * \brief Implements a derived label provider for use with QgsLabelSink.
53  *
54  * \note not available in Python bindings
55  * \since QGIS 3.14
56  */
57 class QgsLabelSinkProvider : public QgsVectorLayerLabelProvider
58 {
59   public:
60     //! Creates a rule based label sink provider which will draw/register labels in \a sink.
61     explicit QgsLabelSinkProvider( QgsVectorLayer *layer, const QString &providerId, QgsLabelSink *sink, const QgsPalLayerSettings *settings );
62 
63     void drawLabel( QgsRenderContext &context, pal::LabelPosition *label ) const override;
64 
65   private:
66     QgsLabelSink *mLabelSink = nullptr;
67 };
68 
69 /**
70  * \ingroup core
71  * \brief Implements a derived label provider for rule based labels for use with QgsLabelSink.
72  *
73  * \note not available in Python bindings
74  * \since QGIS 3.14
75  */
76 class QgsRuleBasedLabelSinkProvider : public QgsRuleBasedLabelProvider
77 {
78   public:
79     //! Creates a rule based label sink provider which will draw/register labels in \a sink.
80     explicit QgsRuleBasedLabelSinkProvider( const QgsRuleBasedLabeling &rules, QgsVectorLayer *layer, QgsLabelSink *sink );
81 
82     /**
83      * Reinitialize the subproviders with QgsLabelSinkProviders
84      * \deprecated since QGIS 3.12
85      */
86     Q_DECL_DEPRECATED void reinit( QgsVectorLayer *layer );
87 
88     void drawLabel( QgsRenderContext &context, pal::LabelPosition *label ) const override;
89 
90     //! Creates a  QgsRuleBasedLabelSinkProvider
91     QgsVectorLayerLabelProvider *createProvider( QgsVectorLayer *layer, const QString &providerId, bool withFeatureLoop, const QgsPalLayerSettings *settings ) override;
92 
93   private:
94     QgsLabelSink *mLabelSink = nullptr;
95 };
96 
97 
98 
99 #endif // QGSLABELSINK_H
100