QGIS API Documentation
3.16.0-Hannover (43b64b13f3)
|
The QgsVectorLayerLabelProvider class implements a label provider for vector layers. More...
#include <qgsvectorlayerlabelprovider.h>
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 (QgsWkbTypes::GeometryType geometryType, const QgsFields &fields, const QgsCoordinateReferenceSystem &crs, const QString &providerId, const QgsPalLayerSettings *settings, QgsMapLayer *layer, const QString &layerName=QString()) | |
Constructor to initialize the provider from any map layer (e.g. vector tile 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... | |
void | drawLabelBackground (QgsRenderContext &context, pal::LabelPosition *label) const override |
Draw the background for the specified label. More... | |
void | drawUnplacedLabel (QgsRenderContext &context, pal::LabelPosition *label) const override |
Draw an unplaced label. 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 (QgsRenderContext &context, QSet< QString > &attributeNames) |
Prepare for registration of features. More... | |
virtual void | registerFeature (const QgsFeature &feature, QgsRenderContext &context, const QgsGeometry &obstacleGeometry=QgsGeometry(), const QgsSymbol *symbol=nullptr) |
Register a feature for labeling as one or more QgsLabelFeature objects stored into mLabels. More... | |
void | setFields (const QgsFields &fields) |
Sets fields of this label provider. More... | |
const QgsPalLayerSettings & | settings () const |
Returns the layer's settings. More... | |
void | startRender (QgsRenderContext &context) override |
To be called before rendering of labels begins. More... | |
void | stopRender (QgsRenderContext &context) override |
To be called after rendering is complete. 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... | |
QgsMapLayer * | layer () 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... | |
QString | name () const |
Name of the layer (for statistics, debugging etc.) - does not need to be unique. More... | |
QgsLabelObstacleSettings::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... | |
QgsFeatureRenderer * | mRenderer = nullptr |
QgsPalLayerSettings | mSettings |
Layer's labeling configuration. More... | |
std::unique_ptr< QgsAbstractFeatureSource > | mSource |
Layer's feature source. More... | |
Protected Attributes inherited from QgsAbstractLabelProvider | |
const QgsLabelingEngine * | mEngine = 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... | |
QString | mName |
Name of the layer. More... | |
QgsLabelObstacleSettings::ObstacleType | mObstacleType = QgsLabelObstacleSettings::PolygonBoundary |
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... | |
Friends | |
class | TestQgsLabelingEngine |
Additional Inherited Members | |
Public Types inherited from QgsAbstractLabelProvider | |
enum | Flag { DrawLabels = 1 << 1, DrawAllLabels = 1 << 2, MergeConnectedLines = 1 << 3, CentroidMustBeInside = 1 << 4 } |
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.
Definition at line 40 of file qgsvectorlayerlabelprovider.h.
|
explicit |
Convenience constructor to initialize the provider from given vector layer.
Definition at line 46 of file qgsvectorlayerlabelprovider.cpp.
|
explicit |
Constructor to initialize the provider from any map layer (e.g. vector tile layer)
Definition at line 64 of file qgsvectorlayerlabelprovider.cpp.
|
override |
Definition at line 106 of file qgsvectorlayerlabelprovider.cpp.
|
overridevirtual |
Draw this label at the position determined by the labeling engine.
Before any calls to drawLabel(), a provider should be prepared for rendering by a call to startRender() and a corresponding call to stopRender().
Implements QgsAbstractLabelProvider.
Definition at line 337 of file qgsvectorlayerlabelprovider.cpp.
|
overridevirtual |
Draw the background for the specified label.
This is called in turn for each label provider before any actual labels are rendered, and allows the provider to render content which should be drawn below ALL map labels (such as background rectangles or callout lines).
Before any calls to drawLabelBackground(), a provider should be prepared for rendering by a call to startRender() and a corresponding call to stopRender().
Reimplemented from QgsAbstractLabelProvider.
Definition at line 301 of file qgsvectorlayerlabelprovider.cpp.
|
protected |
Internal label drawing method.
Definition at line 471 of file qgsvectorlayerlabelprovider.cpp.
|
overridevirtual |
Draw an unplaced label.
These correspond to features which were registered for labeling, but which could not be labeled (e.g. due to conflicting labels).
The default behavior is to draw nothing for these labels.
Reimplemented from QgsAbstractLabelProvider.
Definition at line 453 of file qgsvectorlayerlabelprovider.cpp.
|
static |
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.
fet | point feature |
context | render context |
symbols | symbols rendered for point feature |
Definition at line 199 of file qgsvectorlayerlabelprovider.cpp.
|
protected |
initialization method - called from constructors
Definition at line 77 of file qgsvectorlayerlabelprovider.cpp.
|
overridevirtual |
Returns list of label features (they are owned by the provider and thus deleted on its destruction)
Implements QgsAbstractLabelProvider.
Definition at line 131 of file qgsvectorlayerlabelprovider.cpp.
|
virtual |
Prepare for registration of features.
Must be called after provider has been added to engine (uses its map settings)
context | render context. |
attributeNames | list of attribute names to which additional required attributes shall be added |
Reimplemented in QgsVectorTileBasicLabelProvider, and QgsRuleBasedLabelProvider.
Definition at line 112 of file qgsvectorlayerlabelprovider.cpp.
|
virtual |
Register a feature for labeling as one or more QgsLabelFeature objects stored into mLabels.
feature | feature to label |
context | render context. The QgsExpressionContext contained within the render context must have already had the feature and fields sets prior to calling this method. |
obstacleGeometry | optional 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. |
symbol | feature symbol to label (ownership is not transferred - the symbol must exist until after labeling is complete) |
Reimplemented in QgsRuleBasedLabelProvider.
Definition at line 190 of file qgsvectorlayerlabelprovider.cpp.
|
inline |
Sets fields of this label provider.
Normally this is not needed, but when used for vector tiles, fields are not known at the time of creation of label providers. It should be called before a call to prepare() which uses the list of fields.
Definition at line 117 of file qgsvectorlayerlabelprovider.h.
const QgsPalLayerSettings & QgsVectorLayerLabelProvider::settings | ( | ) | const |
Returns the layer's settings.
Definition at line 654 of file qgsvectorlayerlabelprovider.cpp.
|
overridevirtual |
To be called before rendering of labels begins.
Must be accompanied by a corresponding call to stopRender()
Reimplemented from QgsAbstractLabelProvider.
Definition at line 119 of file qgsvectorlayerlabelprovider.cpp.
|
overridevirtual |
To be called after rendering is complete.
Reimplemented from QgsAbstractLabelProvider.
Definition at line 125 of file qgsvectorlayerlabelprovider.cpp.
|
friend |
Definition at line 147 of file qgsvectorlayerlabelprovider.h.
|
protected |
Layer's CRS.
Definition at line 138 of file qgsvectorlayerlabelprovider.h.
|
protected |
Layer's fields.
Definition at line 136 of file qgsvectorlayerlabelprovider.h.
|
protected |
List of generated.
Definition at line 143 of file qgsvectorlayerlabelprovider.h.
|
protected |
Geometry type of layer.
Definition at line 129 of file qgsvectorlayerlabelprovider.h.
|
protected |
Definition at line 131 of file qgsvectorlayerlabelprovider.h.
|
protected |
Layer's labeling configuration.
Definition at line 127 of file qgsvectorlayerlabelprovider.h.
|
protected |
Layer's feature source.
Definition at line 140 of file qgsvectorlayerlabelprovider.h.