Layer class
A set of features which influence the labeling process.
Contents
Constructors, destructors, conversion operators
-
Layer(QgsAbstractLabelProvider* provider,
const QString& name,
QgsPalLayerSettings::
Placement arrangement, double defaultPriority, bool active, bool toLabel, Pal* pal, bool displayAll = false) protected - Create a new layer.
Public functions
- auto active() const -> bool
- Returns whether the layer is currently active.
-
auto arrangement() const -> QgsPalLayerSettings::
Placement - Returns the layer's arrangement policy.
- auto arrangementFlags() const -> LineArrangementFlags
- Returns the layer's arrangement flags.
- auto centroidInside() const -> bool
- Returns whether labels placed at the centroid of features within the layer are forced to be placed inside the feature's geometry.
- void chopFeaturesAtRepeatDistance()
- Chop layer features at the repeat distance *.
- auto connectedFeatureId(QgsFeatureId featureId) const -> int
- Returns the connected feature ID for a label feature ID, which is unique for all features which have been joined as a result of joinConnectedFeatures()
- auto featureCount() -> int
- Returns the number of features in layer.
- auto isCurved() const -> bool
- Returns true if the layer has curved labels.
- void joinConnectedFeatures()
- Join connected features with the same label text.
- auto labelLayer() const -> bool
- Returns whether the layer will be labeled or not.
- auto labelMode() const -> LabelMode
- Returns the layer's labeling mode.
- auto mergeConnectedLines() const -> bool
- Returns whether connected lines will be merged before labeling.
- auto name() const -> QString
- Returns the layer's name.
-
auto obstacleType() const -> QgsPalLayerSettings::
ObstacleType - Returns the obstacle type, which controls how features within the layer act as obstacles for labels.
- auto priority() const -> double
- Returns the layer's priority, between 0 and 1.
- auto provider() const -> QgsAbstractLabelProvider*
- Returns pointer to the associated provider.
- auto registerFeature(QgsLabelFeature* label) -> bool
- Register a feature in the layer.
- void setActive(bool active)
- Sets whether the layer is currently active.
-
void setArrangement(QgsPalLayerSettings::
Placement arrangement) - Sets the layer's arrangement policy.
- void setArrangementFlags(LineArrangementFlags flags)
- Sets the layer's arrangement flags.
- void setCentroidInside(bool forceInside)
- Sets whether labels placed at the centroid of features within the layer are forced to be placed inside the feature's geometry.
- void setLabelLayer(bool toLabel)
- Sets whether the layer will be labeled.
- void setLabelMode(LabelMode mode)
- Sets the layer's labeling mode.
- void setMergeConnectedLines(bool merge)
- Sets whether connected lines should be merged before labeling.
-
void setObstacleType(QgsPalLayerSettings::
ObstacleType obstacleType) - Sets the obstacle type, which controls how features within the layer act as obstacles for labels.
- void setPriority(double priority)
- Sets the layer's priority.
- void setUpsidedownLabels(UpsideDownLabels ud)
- Sets how upside down labels will be handled within the layer.
- auto upsidedownLabels() const -> UpsideDownLabels
- Returns how upside down labels are handled within the layer.
Protected functions
- void addFeaturePart(FeaturePart* fpart, const QString& labelText = QString())
- Add newly created feature part into r tree and to the list.
- void addObstaclePart(FeaturePart* fpart)
- Add newly created obstacle part into r tree and to the list.
Protected variables
-
QgsPalLayerSettings::
Placement mArrangement - Optional flags used for some placement methods.
- QLinkedList<FeaturePart*> mFeatureParts
- List of feature parts.
- QHash<QgsFeatureId, QgsLabelFeature*> mHashtable
- Lookup table of label features (owned by the label feature provider that created them)
- QList<FeaturePart*> mObstacleParts
- List of obstacle parts.
Function documentation
pal:: Layer:: Layer(QgsAbstractLabelProvider* provider,
const QString& name,
QgsPalLayerSettings:: Placement arrangement,
double defaultPriority,
bool active,
bool toLabel,
Pal* pal,
bool displayAll = false) protected
Create a new layer.
| Parameters | |
|---|---|
| provider | Associated provider |
| name | Name of the layer (for stats, debugging - does not need to be unique) |
| arrangement | Arrangement mode : how to place candidates |
| defaultPriority | layer's prioriry (0 is the best, 1 the worst) |
| active | is the layer is active (currently displayed) |
| toLabel | the layer will be labeled whether toLablel is true |
| pal | pointer to the pal object |
| displayAll | if true, all features will be labelled even though overlaps occur |
bool pal:: Layer:: active() const
Returns whether the layer is currently active.
QgsPalLayerSettings:: Placement pal:: Layer:: arrangement() const
Returns the layer's arrangement policy.
LineArrangementFlags pal:: Layer:: arrangementFlags() const
Returns the layer's arrangement flags.
bool pal:: Layer:: centroidInside() const
Returns whether labels placed at the centroid of features within the layer are forced to be placed inside the feature's geometry.
int pal:: Layer:: connectedFeatureId(QgsFeatureId featureId) const
Returns the connected feature ID for a label feature ID, which is unique for all features which have been joined as a result of joinConnectedFeatures()
| Returns | connected feature ID, or -1 if feature was not joined |
|---|
bool pal:: Layer:: labelLayer() const
Returns whether the layer will be labeled or not.
bool pal:: Layer:: mergeConnectedLines() const
Returns whether connected lines will be merged before labeling.
QgsPalLayerSettings:: ObstacleType pal:: Layer:: obstacleType() const
Returns the obstacle type, which controls how features within the layer act as obstacles for labels.
double pal:: Layer:: priority() const
Returns the layer's priority, between 0 and 1.
0 corresponds to highest priority, 1 to lowest priority.
bool pal:: Layer:: registerFeature(QgsLabelFeature* label)
Register a feature in the layer.
| Returns | true on success (i.e. valid geometry) |
|---|---|
| Exceptions | |
| None | |
Does not take ownership of the label feature (it is owned by its provider).
void pal:: Layer:: setActive(bool active)
Sets whether the layer is currently active.
| Parameters | |
|---|---|
| active | set to true to make the layer active, or false to deactivate the layer |
Active means "is currently displayed or used as obstacles". When a layer is deactivated then feature of this layer will not be used for either labeling or as obstacles.
void pal:: Layer:: setArrangement(QgsPalLayerSettings:: Placement arrangement)
Sets the layer's arrangement policy.
| Parameters | |
|---|---|
| arrangement | arrangement policy |
void pal:: Layer:: setArrangementFlags(LineArrangementFlags flags)
Sets the layer's arrangement flags.
| Parameters | |
|---|---|
| flags | arrangement flags |
void pal:: Layer:: setCentroidInside(bool forceInside)
Sets whether labels placed at the centroid of features within the layer are forced to be placed inside the feature's geometry.
| Parameters | |
|---|---|
| forceInside | set to true to force centroid labels to be within the feature. If set to false then the centroid may fall outside the feature. |
void pal:: Layer:: setLabelLayer(bool toLabel)
Sets whether the layer will be labeled.
| Parameters | |
|---|---|
| toLabel | set to false disable labeling this layer |
void pal:: Layer:: setLabelMode(LabelMode mode)
Sets the layer's labeling mode.
| Parameters | |
|---|---|
| mode | label mode |
void pal:: Layer:: setMergeConnectedLines(bool merge)
Sets whether connected lines should be merged before labeling.
| Parameters | |
|---|---|
| merge | set to true to merge connected lines |
void pal:: Layer:: setObstacleType(QgsPalLayerSettings:: ObstacleType obstacleType)
Sets the obstacle type, which controls how features within the layer act as obstacles for labels.
| Parameters | |
|---|---|
| obstacleType | new obstacle type |
void pal:: Layer:: setPriority(double priority)
Sets the layer's priority.
| Parameters | |
|---|---|
| priority | layer priority, between 0 and 1. 0 corresponds to highest priority, 1 to lowest priority. |
void pal:: Layer:: setUpsidedownLabels(UpsideDownLabels ud)
Sets how upside down labels will be handled within the layer.
| Parameters | |
|---|---|
| ud | upside down label handling mode |
UpsideDownLabels pal:: Layer:: upsidedownLabels() const
Returns how upside down labels are handled within the layer.