QgsAbstractLabelProvider class
The QgsAbstractLabelProvider class is an interface class.
Contents
Implementations return list of labels and their associated geometries - these are used by QgsLabelingEngine to compute the final layout of labels.
Implementations also take care of drawing the returned final label positions.
Derived classes
- class QgsVectorLayerDiagramProvider
- The QgsVectorLayerDiagramProvider class implements support for diagrams within the labeling engine.
- class QgsVectorLayerLabelProvider
- The QgsVectorLayerLabelProvider class implements a label provider for vector layers.
Public types
- enum Flag { DrawLabels = 1 << 1, DrawAllLabels = 1 << 2, MergeConnectedLines = 1 << 3, CentroidMustBeInside = 1 << 4, LabelPerFeaturePart = 1 << 6 }
Constructors, destructors, conversion operators
- QgsAbstractLabelProvider(QgsMapLayer* layer, const QString& providerId = QString())
- Construct the provider with default values.
Public functions
-
void drawLabel(QgsRenderContext& context,
pal::
LabelPosition* label) const pure virtual - draw this label at the position determined by the labeling engine
- auto flags() const -> Flags
- Flags associated with the provider.
- auto labelFeatures(QgsRenderContext& context) -> QList<QgsLabelFeature*> pure virtual
- Returns list of label features (they are owned by the provider and thus deleted on its destruction)
- auto layer() const -> QgsMapLayer*
- Returns the associated layer, or nullptr if no layer is associated with the provider.
- auto layerId() const -> QString
- Returns ID of associated layer, or empty string if no layer is associated with the provider.
- auto linePlacementFlags() const -> unsigned int
- For layers with linestring geometries - extra placement flags (or-ed combination of QgsPalLayerSettings::
LinePlacementFlags) - auto name() const -> QString
- Name of the layer (for statistics, debugging etc.) - does not need to be unique.
-
auto obstacleType() const -> QgsPalLayerSettings::
ObstacleType - How the feature geometries will work as obstacles.
-
auto placement() const -> QgsPalLayerSettings::
Placement - What placement strategy to use for the labels.
- auto priority() const -> double
- Default priority of labels (may be overridden by individual labels)
- auto providerId() const -> QString
- Returns provider ID - useful in case there is more than one label provider within a layer (e.g.
- void setEngine(const QgsLabelingEngine* engine)
- Associate provider with a labeling engine (should be only called internally from QgsLabelingEngine)
- auto subProviders() -> QList<QgsAbstractLabelProvider*> virtual
- Returns list of child providers - useful if the provider needs to put labels into more layers with different configuration.
-
auto upsidedownLabels() const -> QgsPalLayerSettings::
UpsideDownLabels - How to handle labels that would be upside down.
Protected variables
- const QgsLabelingEngine* mEngine
- Associated labeling engine.
- Flags mFlags
- Flags altering drawing and registration of features.
- QgsWeakMapLayerPointer mLayer
- Weak pointer to source layer.
- QString mLayerId
- Associated layer's ID, if applicable.
- unsigned int mLinePlacementFlags
- Extra placement flags for linestring geometries.
- QString mName
- Name of the layer.
-
QgsPalLayerSettings::
ObstacleType mObstacleType - Type of the obstacle of feature geometries.
-
QgsPalLayerSettings::
Placement mPlacement - Placement strategy.
- double mPriority
- Default priority of labels.
- QString mProviderId
- Associated provider ID (one layer may have multiple providers, e.g. in rule-based labeling)
-
QgsPalLayerSettings::
UpsideDownLabels mUpsidedownLabels - How to handle labels that would be upside down.
Enum documentation
enum QgsAbstractLabelProvider:: Flag
| Enumerators | |
|---|---|
| DrawLabels |
Whether the labels should be rendered. |
| DrawAllLabels |
Whether all features will be labelled even though overlaps occur. |
| MergeConnectedLines |
Whether adjacent lines (with the same label text) should be merged. |
| CentroidMustBeInside |
Whether location of centroid must be inside of polygons. |
| LabelPerFeaturePart |
Whether to label each part of multi-part features separately. |
Function documentation
QString QgsAbstractLabelProvider:: providerId() const
Returns provider ID - useful in case there is more than one label provider within a layer (e.g.
in case of rule-based labeling - provider ID = rule's key). May be empty string if layer ID is sufficient for identification of provider's configuration.