QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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 
26 class QgsFeatureRenderer;
27 class QgsSymbol;
28 
40 {
41  public:
42 
45  const QString &providerId,
46  bool withFeatureLoop,
47  const QgsPalLayerSettings *settings,
48  const QString &layerName = QString() );
49 
50  ~QgsVectorLayerLabelProvider() override;
51 
52  QList<QgsLabelFeature *> labelFeatures( QgsRenderContext &context ) override;
53 
54  void drawLabelBackground( QgsRenderContext &context, pal::LabelPosition *label ) const override;
55  void drawLabel( QgsRenderContext &context, pal::LabelPosition *label ) const override;
56  void drawUnplacedLabel( QgsRenderContext &context, pal::LabelPosition *label ) const override;
57  void startRender( QgsRenderContext &context ) override;
58  void stopRender( QgsRenderContext &context ) override;
59 
60  // new virtual methods
61 
68  virtual bool prepare( QgsRenderContext &context, QSet<QString> &attributeNames );
69 
82  virtual void registerFeature( const QgsFeature &feature, QgsRenderContext &context, const QgsGeometry &obstacleGeometry = QgsGeometry(), const QgsSymbol *symbol = nullptr );
83 
93  static QgsGeometry getPointObstacleGeometry( QgsFeature &fet, QgsRenderContext &context, const QgsSymbolList &symbols );
94 
99  const QgsPalLayerSettings &settings() const;
100 
101  protected:
103  void init();
105  void drawLabelPrivate( pal::LabelPosition *label, QgsRenderContext &context, QgsPalLayerSettings &tmpLyr, QgsTextRenderer::TextPart drawType, double dpiRatio = 1.0 ) const;
106 
107  protected:
112 
113  QgsFeatureRenderer *mRenderer = nullptr;
114 
115  // these are needed only if using own renderer loop
116 
122  std::unique_ptr<QgsAbstractFeatureSource> mSource;
123 
125  QList<QgsLabelFeature *> mLabels;
126 
127  private:
128 
129  friend class TestQgsLabelingEngine;
130  void drawCallout( QgsRenderContext &context, pal::LabelPosition *label ) const;
131 };
132 
133 #endif // QGSVECTORLAYERLABELPROVIDER_H
QList< QgsLabelFeature * > mLabels
List of generated.
QgsWkbTypes::GeometryType mLayerGeometryType
Geometry type of layer.
virtual void drawLabelBackground(QgsRenderContext &context, pal::LabelPosition *label) const
Draw the background for the specified label.
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:61
std::unique_ptr< QgsAbstractFeatureSource > mSource
Layer&#39;s feature source.
Container of fields for a vector layer.
Definition: qgsfields.h:42
The QgsVectorLayerLabelProvider class implements a label provider for vector layers.
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:122
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:55
virtual QList< QgsLabelFeature * > labelFeatures(QgsRenderContext &context)=0
Returns list of label features (they are owned by the provider and thus deleted on its destruction) ...
QList< QgsSymbol * > QgsSymbolList
Definition: qgsrenderer.h:44
QgsPalLayerSettings mSettings
Layer&#39;s labeling configuration.
virtual void drawUnplacedLabel(QgsRenderContext &context, pal::LabelPosition *label) const
Draw an unplaced label.
Base class that can be used for any class that is capable of returning features.
The QgsAbstractLabelProvider class is an interface class.
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
Definition: qgswkbtypes.h:139
TextPart
Components of text.
QgsFields mFields
Layer&#39;s fields.
Contains information about the context of a rendering operation.
QgsCoordinateReferenceSystem mCrs
Layer&#39;s CRS.
This class represents a coordinate reference system (CRS).
LabelPosition is a candidate feature label position.
Definition: labelposition.h:55
virtual void startRender(QgsRenderContext &context)
To be called before rendering of labels begins.
virtual void drawLabel(QgsRenderContext &context, pal::LabelPosition *label) const =0
Draw this label at the position determined by the labeling engine.
virtual void stopRender(QgsRenderContext &context)
To be called after rendering is complete.
Represents a vector layer which manages a vector based data sets.