QGIS API Documentation 4.3.0-Master (0ff9723465c)
Loading...
Searching...
No Matches
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
20#include "qgis_core.h"
21#include "qgslabelingengine.h"
22#include "qgspallabeling.h"
23#include "qgsrenderer.h"
24
25#define SIP_NO_FILE
26
29class QgsSymbol;
30
38class CORE_EXPORT QgsLabelFeatureDetails
39{
40 public:
53
65 void setObstacleGeometry( const QgsGeometry &geometry );
66
72 const QgsSymbol *symbol() const;
73
81 void setSymbol( const QgsSymbol *symbol );
82
88 bool isSelected() const;
89
95 void setIsSelected( bool selected );
96
97 private:
98 QgsGeometry mObstacleGeometry;
99 const QgsSymbol *mSymbol = nullptr;
100 bool mIsSelected = false;
101};
102
114{
115 public:
117 explicit QgsVectorLayerLabelProvider( QgsVectorLayer *layer, const QString &providerId, bool withFeatureLoop, const QgsPalLayerSettings *settings, const QString &layerName = QString() );
118
121 Qgis::GeometryType geometryType,
122 const QgsFields &fields,
124 const QString &providerId,
127 const QString &layerName = QString()
128 );
129
131
132 QList<QgsLabelFeature *> labelFeatures( QgsRenderContext &context ) override;
133
134 void drawLabelBackground( QgsRenderContext &context, pal::LabelPosition *label ) const override;
135 void drawLabel( QgsRenderContext &context, pal::LabelPosition *label ) const override;
136 void drawUnplacedLabel( QgsRenderContext &context, pal::LabelPosition *label ) const override;
137 void startRender( QgsRenderContext &context ) override;
138 void stopRender( QgsRenderContext &context ) override;
139
140 // new virtual methods
141
148 virtual bool prepare( QgsRenderContext &context, QSet<QString> &attributeNames );
149
160 virtual QList< QgsLabelFeature * > registerFeature( const QgsFeature &feature, QgsRenderContext &context, const QgsLabelFeatureDetails &details = QgsLabelFeatureDetails() );
161
170 static QgsGeometry getPointObstacleGeometry( QgsFeature &fet, QgsRenderContext &context, const QgsSymbolList &symbols );
171
176 const QgsPalLayerSettings &settings() const;
177
184 void setFields( const QgsFields &fields );
185
186 protected:
188 void init();
190 void drawLabelPrivate( pal::LabelPosition *label, QgsRenderContext &context, QgsPalLayerSettings &tmpLyr, Qgis::TextComponent drawType, double dpiRatio = 1.0 ) const;
191
192 protected:
197
199
200 // these are needed only if using own renderer loop
201
207 std::unique_ptr<QgsAbstractFeatureSource> mSource;
208
210 QList<QgsLabelFeature *> mLabels;
211
212 private:
215
216 void drawCallout( QgsRenderContext &context, pal::LabelPosition *label ) const;
217};
218
219#endif // QGSVECTORLAYERLABELPROVIDER_H
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition qgis.h:379
TextComponent
Text components.
Definition qgis.h:3123
Base class that can be used for any class that is capable of returning features.
QgsMapLayer * layer() const
Returns the associated layer, or nullptr if no layer is associated with the provider.
QString providerId() const
Returns provider ID - useful in case there is more than one label provider within a layer (e....
QgsAbstractLabelProvider(QgsMapLayer *layer, const QString &providerId=QString())
Construct the provider with default values.
Represents a coordinate reference system (CRS).
Abstract base class for all 2D vector feature renderers.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:60
Container of fields for a vector layer.
Definition qgsfields.h:45
A geometry is the spatial representation of a feature.
Encapsulates details for an individual feature to label.
void setIsSelected(bool selected)
Sets whether the feature associated with the label is currently selected.
void setSymbol(const QgsSymbol *symbol)
Sets the (optional) symbol associated with the feature to label.
QgsGeometry obstacleGeometry() const
Returns the (optional) obstacle geometry for the label.
bool isSelected() const
Returns true if the feature associated with the label is currently selected.
const QgsSymbol * symbol() const
Returns the (optional) symbol associated with the feature to label.
void setObstacleGeometry(const QgsGeometry &geometry)
Sets the (optional) obstacle geometry for the label.
Base class for all map layer types.
Definition qgsmaplayer.h:83
Contains settings for how a map layer will be labeled.
Contains information about the context of a rendering operation.
Abstract base class for all rendered symbols.
Definition qgssymbol.h:227
virtual QList< QgsLabelFeature * > registerFeature(const QgsFeature &feature, QgsRenderContext &context, const QgsLabelFeatureDetails &details=QgsLabelFeatureDetails())
Register a feature for labeling as one or more QgsLabelFeature objects stored into mLabels.
void stopRender(QgsRenderContext &context) override
To be called after rendering is complete.
QgsCoordinateReferenceSystem mCrs
Layer's CRS.
virtual bool prepare(QgsRenderContext &context, QSet< QString > &attributeNames)
Prepare for registration of features.
void drawUnplacedLabel(QgsRenderContext &context, pal::LabelPosition *label) const override
Draw an unplaced label.
QList< QgsLabelFeature * > mLabels
List of generated.
QgsVectorLayerLabelProvider(QgsVectorLayer *layer, const QString &providerId, bool withFeatureLoop, const QgsPalLayerSettings *settings, const QString &layerName=QString())
Convenience constructor to initialize the provider from given vector layer.
void startRender(QgsRenderContext &context) override
To be called before rendering of labels begins.
const QgsPalLayerSettings & settings() const
Returns the layer's settings.
void drawLabelPrivate(pal::LabelPosition *label, QgsRenderContext &context, QgsPalLayerSettings &tmpLyr, Qgis::TextComponent drawType, double dpiRatio=1.0) const
Internal label drawing method.
Qgis::GeometryType mLayerGeometryType
Geometry type of layer.
static QgsGeometry getPointObstacleGeometry(QgsFeature &fet, QgsRenderContext &context, const QgsSymbolList &symbols)
Returns the geometry for a point feature which should be used as an obstacle for labels.
QgsPalLayerSettings mSettings
Layer's labeling configuration.
std::unique_ptr< QgsAbstractFeatureSource > mSource
Layer's feature source.
QList< QgsLabelFeature * > labelFeatures(QgsRenderContext &context) override
Returns list of label features (they are owned by the provider and thus deleted on its destruction).
void init()
initialization method - called from constructors
void setFields(const QgsFields &fields)
Sets fields of this label provider.
void drawLabel(QgsRenderContext &context, pal::LabelPosition *label) const override
Draw this label at the position determined by the labeling engine.
void drawLabelBackground(QgsRenderContext &context, pal::LabelPosition *label) const override
Draw the background for the specified label.
Represents a vector layer which manages a vector based dataset.
LabelPosition is a candidate feature label position.
QList< QgsSymbol * > QgsSymbolList
Definition qgsrenderer.h:51