QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgsvectorlayerlabelprovider.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsvectorlayerlabelprovider.h
3  --------------------------------------
4  Date : September 2015
5  Copyright : (C) 2015 by Martin Dobias
6  Email : wonder dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSVECTORLAYERLABELPROVIDER_H
17 #define QGSVECTORLAYERLABELPROVIDER_H
18 
19 #define SIP_NO_FILE
20 
21 #include "qgis_core.h"
22 #include "qgslabelingengine.h"
23 #include "qgsrenderer.h"
24 #include "qgstextrenderer.h"
25 
27 class QgsFeatureRenderer;
28 class QgsSymbol;
29 
41 {
42  public:
43 
46  const QString &providerId,
47  bool withFeatureLoop,
48  const QgsPalLayerSettings *settings,
49  const QString &layerName = QString() );
50 
53  const QgsFields &fields,
55  const QString &providerId,
56  const QgsPalLayerSettings *settings,
57  QgsMapLayer *layer,
58  const QString &layerName = QString() );
59 
60  ~QgsVectorLayerLabelProvider() override;
61 
62  QList<QgsLabelFeature *> labelFeatures( QgsRenderContext &context ) override;
63 
64  void drawLabelBackground( QgsRenderContext &context, pal::LabelPosition *label ) const override;
65  void drawLabel( QgsRenderContext &context, pal::LabelPosition *label ) const override;
66  void drawUnplacedLabel( QgsRenderContext &context, pal::LabelPosition *label ) const override;
67  void startRender( QgsRenderContext &context ) override;
68  void stopRender( QgsRenderContext &context ) override;
69 
70  // new virtual methods
71 
78  virtual bool prepare( QgsRenderContext &context, QSet<QString> &attributeNames );
79 
92  virtual void registerFeature( const QgsFeature &feature, QgsRenderContext &context, const QgsGeometry &obstacleGeometry = QgsGeometry(), const QgsSymbol *symbol = nullptr );
93 
103  static QgsGeometry getPointObstacleGeometry( QgsFeature &fet, QgsRenderContext &context, const QgsSymbolList &symbols );
104 
109  const QgsPalLayerSettings &settings() const;
110 
117  void setFields( const QgsFields &fields ) { mFields = fields; }
118 
119  protected:
121  void init();
123  void drawLabelPrivate( pal::LabelPosition *label, QgsRenderContext &context, QgsPalLayerSettings &tmpLyr, QgsTextRenderer::TextPart drawType, double dpiRatio = 1.0 ) const;
124 
125  protected:
130 
131  QgsFeatureRenderer *mRenderer = nullptr;
132 
133  // these are needed only if using own renderer loop
134 
140  std::unique_ptr<QgsAbstractFeatureSource> mSource;
141 
143  QList<QgsLabelFeature *> mLabels;
144 
145  private:
146 
147  friend class TestQgsLabelingEngine;
148  void drawCallout( QgsRenderContext &context, pal::LabelPosition *label ) const;
149 };
150 
151 #endif // QGSVECTORLAYERLABELPROVIDER_H
QgsAbstractLabelProvider::drawLabel
virtual void drawLabel(QgsRenderContext &context, pal::LabelPosition *label) const =0
Draw this label at the position determined by the labeling engine.
QgsAbstractLabelProvider::stopRender
virtual void stopRender(QgsRenderContext &context)
To be called after rendering is complete.
Definition: qgslabelingengine.cpp:643
QgsTextRenderer::TextPart
TextPart
Components of text.
Definition: qgstextrenderer.h:50
qgstextrenderer.h
QgsPalLayerSettings
Definition: qgspallabeling.h:207
crs
const QgsCoordinateReferenceSystem & crs
Definition: qgswfsgetfeature.cpp:51
pal::LabelPosition
LabelPosition is a candidate feature label position.
Definition: labelposition.h:56
QgsVectorLayerLabelProvider::setFields
void setFields(const QgsFields &fields)
Sets fields of this label provider.
Definition: qgsvectorlayerlabelprovider.h:117
QgsFields
Container of fields for a vector layer.
Definition: qgsfields.h:45
QgsRenderContext
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:58
QgsSymbol
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:64
QgsAbstractLabelProvider::drawUnplacedLabel
virtual void drawUnplacedLabel(QgsRenderContext &context, pal::LabelPosition *label) const
Draw an unplaced label.
Definition: qgslabelingengine.cpp:624
QgsVectorLayerLabelProvider
The QgsVectorLayerLabelProvider class implements a label provider for vector layers.
Definition: qgsvectorlayerlabelprovider.h:41
QgsVectorLayerLabelProvider::mSource
std::unique_ptr< QgsAbstractFeatureSource > mSource
Layer's feature source.
Definition: qgsvectorlayerlabelprovider.h:140
QgsVectorLayerLabelProvider::mFields
QgsFields mFields
Layer's fields.
Definition: qgsvectorlayerlabelprovider.h:136
QgsAbstractLabelProvider
The QgsAbstractLabelProvider class is an interface class.
Definition: qgslabelingengine.h:48
QgsSymbolList
QList< QgsSymbol * > QgsSymbolList
Definition: qgsrenderer.h:45
QgsAbstractLabelProvider::labelFeatures
virtual QList< QgsLabelFeature * > labelFeatures(QgsRenderContext &context)=0
Returns list of label features (they are owned by the provider and thus deleted on its destruction)
QgsAbstractFeatureSource
Base class that can be used for any class that is capable of returning features.
Definition: qgsfeaturerequest.h:743
qgsrenderer.h
QgsCoordinateReferenceSystem
This class represents a coordinate reference system (CRS).
Definition: qgscoordinatereferencesystem.h:206
QgsAbstractLabelProvider::drawLabelBackground
virtual void drawLabelBackground(QgsRenderContext &context, pal::LabelPosition *label) const
Draw the background for the specified label.
Definition: qgslabelingengine.cpp:629
QgsAbstractLabelProvider::startRender
virtual void startRender(QgsRenderContext &context)
To be called before rendering of labels begins.
Definition: qgslabelingengine.cpp:634
QgsFeatureRenderer
Definition: qgsrenderer.h:103
QgsWkbTypes::GeometryType
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
Definition: qgswkbtypes.h:141
QgsGeometry
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:124
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:387
QgsMapLayer
Base class for all map layer types.
Definition: qgsmaplayer.h:83
QgsVectorLayerLabelProvider::mSettings
QgsPalLayerSettings mSettings
Layer's labeling configuration.
Definition: qgsvectorlayerlabelprovider.h:127
QgsVectorLayerLabelProvider::mLabels
QList< QgsLabelFeature * > mLabels
List of generated.
Definition: qgsvectorlayerlabelprovider.h:143
QgsFeature
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:56
QgsVectorLayerLabelProvider::mLayerGeometryType
QgsWkbTypes::GeometryType mLayerGeometryType
Geometry type of layer.
Definition: qgsvectorlayerlabelprovider.h:129
qgslabelingengine.h
QgsVectorLayerLabelProvider::mCrs
QgsCoordinateReferenceSystem mCrs
Layer's CRS.
Definition: qgsvectorlayerlabelprovider.h:138