QGIS API Documentation  3.2.0-Bonn (bc43194)
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
QgsVectorLayerLabelProvider Class Reference

The QgsVectorLayerLabelProvider class implements a label provider for vector layers. More...

#include <qgsvectorlayerlabelprovider.h>

Inheritance diagram for QgsVectorLayerLabelProvider:
Inheritance graph

Public Member Functions

 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. More...
 ~QgsVectorLayerLabelProvider () override
void drawLabel (QgsRenderContext &context, pal::LabelPosition *label) const override
 draw this label at the position determined by the labeling engine More...
QList< QgsLabelFeature * > labelFeatures (QgsRenderContext &context) override
 Returns list of label features (they are owned by the provider and thus deleted on its destruction) More...
virtual bool prepare (const QgsRenderContext &context, QSet< QString > &attributeNames)
 Prepare for registration of features. More...
virtual void registerFeature (QgsFeature &feature, QgsRenderContext &context, const QgsGeometry &obstacleGeometry=QgsGeometry())
 Register a feature for labeling as one or more QgsLabelFeature objects stored into mLabels. More...
- Public Member Functions inherited from QgsAbstractLabelProvider
 QgsAbstractLabelProvider (QgsMapLayer *layer, const QString &providerId=QString())
 Construct the provider with default values. More...
virtual ~QgsAbstractLabelProvider ()=default
Flags flags () const
 Flags associated with the provider. More...
QgsMapLayerlayer () const
 Returns the associated layer, or nullptr if no layer is associated with the provider. More...
QString layerId () const
 Returns ID of associated layer, or empty string if no layer is associated with the provider. More...
unsigned int linePlacementFlags () const
 For layers with linestring geometries - extra placement flags (or-ed combination of QgsPalLayerSettings::LinePlacementFlags) More...
QString name () const
 Name of the layer (for statistics, debugging etc.) - does not need to be unique. More...
QgsPalLayerSettings::ObstacleType obstacleType () const
 How the feature geometries will work as obstacles. More...
QgsPalLayerSettings::Placement placement () const
 What placement strategy to use for the labels. More...
double priority () const
 Default priority of labels (may be overridden by individual labels) More...
QString providerId () const
 Returns provider ID - useful in case there is more than one label provider within a layer (e.g. More...
void setEngine (const QgsLabelingEngine *engine)
 Associate provider with a labeling engine (should be only called internally from QgsLabelingEngine) More...
virtual QList< QgsAbstractLabelProvider * > subProviders ()
 Returns list of child providers - useful if the provider needs to put labels into more layers with different configuration. More...
QgsPalLayerSettings::UpsideDownLabels upsidedownLabels () const
 How to handle labels that would be upside down. More...

Static Public Member Functions

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. More...

Protected Member Functions

void drawLabelPrivate (pal::LabelPosition *label, QgsRenderContext &context, QgsPalLayerSettings &tmpLyr, QgsTextRenderer::TextPart drawType, double dpiRatio=1.0) const
 Internal label drawing method. More...
void init ()
 initialization method - called from constructors More...

Protected Attributes

QgsCoordinateReferenceSystem mCrs
 Layer's CRS. More...
QgsFields mFields
 Layer's fields. More...
QList< QgsLabelFeature * > mLabels
 List of generated. More...
QgsWkbTypes::GeometryType mLayerGeometryType
 Geometry type of layer. More...
bool mOwnsSource
 Whether layer's feature source is owned. More...
QgsFeatureRenderermRenderer = nullptr
QgsPalLayerSettings mSettings
 Layer's labeling configuration. More...
QgsAbstractFeatureSourcemSource = nullptr
 Layer's feature source. More...
- Protected Attributes inherited from QgsAbstractLabelProvider
const QgsLabelingEnginemEngine = nullptr
 Associated labeling engine. More...
Flags mFlags
 Flags altering drawing and registration of features. More...
QgsWeakMapLayerPointer mLayer
 Weak pointer to source layer. More...
QString mLayerId
 Associated layer's ID, if applicable. More...
unsigned int mLinePlacementFlags
 Extra placement flags for linestring geometries. More...
QString mName
 Name of the layer. More...
QgsPalLayerSettings::ObstacleType mObstacleType
 Type of the obstacle of feature geometries. More...
QgsPalLayerSettings::Placement mPlacement
 Placement strategy. More...
double mPriority
 Default priority of labels. More...
QString mProviderId
 Associated provider ID (one layer may have multiple providers, e.g. in rule-based labeling) More...
QgsPalLayerSettings::UpsideDownLabels mUpsidedownLabels
 How to handle labels that would be upside down. More...


class TestQgsLabelingEngine

Additional Inherited Members

- Public Types inherited from QgsAbstractLabelProvider
enum  Flag {
  DrawLabels = 1 << 1, DrawAllLabels = 1 << 2, MergeConnectedLines = 1 << 3, CentroidMustBeInside = 1 << 4,
  LabelPerFeaturePart = 1 << 6

Detailed Description

The QgsVectorLayerLabelProvider class implements a label provider for vector layers.

Parameters for the labeling are taken from the layer's custom properties or from the given settings.

this class is not a part of public API yet. See notes in QgsLabelingEngine
not available in Python bindings
QGIS 2.12

Definition at line 39 of file qgsvectorlayerlabelprovider.h.

Constructor & Destructor Documentation

◆ QgsVectorLayerLabelProvider()

QgsVectorLayerLabelProvider::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.

Definition at line 37 of file qgsvectorlayerlabelprovider.cpp.

◆ ~QgsVectorLayerLabelProvider()

QgsVectorLayerLabelProvider::~QgsVectorLayerLabelProvider ( )

Definition at line 93 of file qgsvectorlayerlabelprovider.cpp.

Member Function Documentation

◆ drawLabel()

void QgsVectorLayerLabelProvider::drawLabel ( QgsRenderContext context,
pal::LabelPosition label 
) const

draw this label at the position determined by the labeling engine

Implements QgsAbstractLabelProvider.

Reimplemented in QgsDxfRuleBasedLabelProvider, and QgsDxfLabelProvider.

Definition at line 366 of file qgsvectorlayerlabelprovider.cpp.

◆ drawLabelPrivate()

void QgsVectorLayerLabelProvider::drawLabelPrivate ( pal::LabelPosition label,
QgsRenderContext context,
QgsPalLayerSettings tmpLyr,
QgsTextRenderer::TextPart  drawType,
double  dpiRatio = 1.0 
) const

Internal label drawing method.

Definition at line 474 of file qgsvectorlayerlabelprovider.cpp.

◆ getPointObstacleGeometry()

QgsGeometry QgsVectorLayerLabelProvider::getPointObstacleGeometry ( QgsFeature fet,
QgsRenderContext context,
const QgsSymbolList symbols 

Returns the geometry for a point feature which should be used as an obstacle for labels.

This obstacle geometry will respect the dimensions and offsets of the symbol used to render the point, and ensures that labels will not overlap large or offset points.

fetpoint feature
contextrender context
symbolssymbols rendered for point feature
QGIS 2.14

Definition at line 266 of file qgsvectorlayerlabelprovider.cpp.

◆ init()

void QgsVectorLayerLabelProvider::init ( )

initialization method - called from constructors

Definition at line 61 of file qgsvectorlayerlabelprovider.cpp.

◆ labelFeatures()

QList< QgsLabelFeature * > QgsVectorLayerLabelProvider::labelFeatures ( QgsRenderContext context)

Returns list of label features (they are owned by the provider and thus deleted on its destruction)

Implements QgsAbstractLabelProvider.

Definition at line 201 of file qgsvectorlayerlabelprovider.cpp.

◆ prepare()

bool QgsVectorLayerLabelProvider::prepare ( const QgsRenderContext context,
QSet< QString > &  attributeNames 

Prepare for registration of features.

Must be called after provider has been added to engine (uses its map settings)

contextrender context.
attributeNameslist of attribute names to which additional required attributes shall be added
Whether the preparation was successful - if not, the provider shall not be used

Reimplemented in QgsRuleBasedLabelProvider.

Definition at line 102 of file qgsvectorlayerlabelprovider.cpp.

◆ registerFeature()

void QgsVectorLayerLabelProvider::registerFeature ( QgsFeature feature,
QgsRenderContext context,
const QgsGeometry obstacleGeometry = QgsGeometry() 

Register a feature for labeling as one or more QgsLabelFeature objects stored into mLabels.

featurefeature to label
contextrender context. The QgsExpressionContext contained within the render context must have already had the feature and fields sets prior to calling this method.
obstacleGeometryoptional obstacle geometry, if a different geometry to the feature's geometry should be used as an obstacle for labels (e.g., if the feature has been rendered with an offset point symbol, the obstacle geometry should represent the bounds of the offset symbol). If not set, the feature's original geometry will be used as an obstacle for labels.

Reimplemented in QgsRuleBasedLabelProvider.

Definition at line 258 of file qgsvectorlayerlabelprovider.cpp.

Friends And Related Function Documentation

◆ TestQgsLabelingEngine

friend class TestQgsLabelingEngine

Definition at line 118 of file qgsvectorlayerlabelprovider.h.

Member Data Documentation

◆ mCrs

QgsCoordinateReferenceSystem QgsVectorLayerLabelProvider::mCrs

Layer's CRS.

Definition at line 109 of file qgsvectorlayerlabelprovider.h.

◆ mFields

QgsFields QgsVectorLayerLabelProvider::mFields

Layer's fields.

Definition at line 107 of file qgsvectorlayerlabelprovider.h.

◆ mLabels

QList<QgsLabelFeature *> QgsVectorLayerLabelProvider::mLabels

List of generated.

Definition at line 116 of file qgsvectorlayerlabelprovider.h.

◆ mLayerGeometryType

QgsWkbTypes::GeometryType QgsVectorLayerLabelProvider::mLayerGeometryType

Geometry type of layer.

Definition at line 100 of file qgsvectorlayerlabelprovider.h.

◆ mOwnsSource

bool QgsVectorLayerLabelProvider::mOwnsSource

Whether layer's feature source is owned.

Definition at line 113 of file qgsvectorlayerlabelprovider.h.

◆ mRenderer

QgsFeatureRenderer* QgsVectorLayerLabelProvider::mRenderer = nullptr

Definition at line 102 of file qgsvectorlayerlabelprovider.h.

◆ mSettings

QgsPalLayerSettings QgsVectorLayerLabelProvider::mSettings

Layer's labeling configuration.

Definition at line 98 of file qgsvectorlayerlabelprovider.h.

◆ mSource

QgsAbstractFeatureSource* QgsVectorLayerLabelProvider::mSource = nullptr

Layer's feature source.

Definition at line 111 of file qgsvectorlayerlabelprovider.h.

The documentation for this class was generated from the following files: