QGIS API Documentation 3.41.0-Master (af5edcb665c)
|
Class that adds extra information to QgsLabelFeature for text labels. More...
#include <qgstextlabelfeature.h>
Public Member Functions | |
QgsTextLabelFeature (QgsFeatureId id, geos::unique_ptr geometry, QSizeF size) | |
Construct text label feature. | |
~QgsTextLabelFeature () override | |
Clean up. | |
QgsTextCharacterFormat | characterFormat (int partId) const |
Returns the character format corresponding to the specified label part. | |
const QMap< QgsPalLayerSettings::Property, QVariant > & | dataDefinedValues () const |
Gets data-defined values. | |
QFont | definedFont () const |
Font to be used for rendering. | |
const QgsTextDocument & | document () const |
Returns the document for the label. | |
const QgsTextDocumentMetrics & | documentMetrics () const |
Returns the document metrics for the label. | |
bool | hasCharacterFormat (int partId) const |
Returns true if the feature contains specific character formatting for the part with matching ID. | |
double | maximumCharacterAngleInside () const |
Returns the maximum angle (in radians) between inside curved label characters. | |
double | maximumCharacterAngleOutside () const |
Returns the maximum angle (in radians) between outside curved label characters. | |
void | setDataDefinedValues (const QMap< QgsPalLayerSettings::Property, QVariant > &values) |
Sets data-defined values. | |
void | setDefinedFont (const QFont &f) |
Sets font to be used for rendering. | |
void | setDocument (const QgsTextDocument &document, const QgsTextDocumentMetrics &metrics) |
Sets the document and document metrics for the label. | |
void | setMaximumCharacterAngleInside (double angle) |
Sets the maximum angle (in radians) between inside curved label characters. | |
void | setMaximumCharacterAngleOutside (double angle) |
Sets the maximum angle (in radians) between outside curved label characters. | |
void | setTextMetrics (const QgsPrecalculatedTextMetrics &metrics) |
Sets additional text metrics required for curved label placement. | |
QString | text (int partId) const |
Returns the text component corresponding to a specified label part. | |
const QgsPrecalculatedTextMetrics * | textMetrics () const |
Returns additional info required for curved label placement. | |
Public Member Functions inherited from QgsLabelFeature | |
QgsLabelFeature (QgsFeatureId id, geos::unique_ptr geometry, QSizeF size) | |
Constructor for QgsLabelFeature. | |
virtual | ~QgsLabelFeature () |
bool | allowDegradedPlacement () const |
Returns true if the label can be placed in inferior fallback positions if it cannot otherwise be placed. | |
bool | alwaysShow () const |
Whether label should be always shown (sets very high label priority) | |
QgsPointXY | anchorPosition () const |
In case of quadrand or aligned positioning, this is set to the anchor point. | |
Qgis::LabelLinePlacementFlags | arrangementFlags () const |
Returns the feature's arrangement flags. | |
double | distLabel () const |
Applies to "around point" placement strategy or linestring features. | |
QgsFeature | feature () const |
Returns the original feature associated with this label. | |
double | fixedAngle () const |
Angle in radians of the fixed angle (relevant only if hasFixedAngle() returns true ) | |
QgsPointXY | fixedPosition () const |
Coordinates of the fixed position (relevant only if hasFixedPosition() returns true ) | |
GEOSGeometry * | geometry () const |
Gets access to the associated geometry. | |
bool | hasFixedAngle () const |
Whether the label should use a fixed angle instead of using angle from automatic placement. | |
bool | hasFixedPosition () const |
Whether the label should use a fixed position instead of being automatically placed. | |
bool | hasFixedQuadrant () const |
Returns whether the quadrant for the label is fixed. | |
QgsFeatureId | id () const |
Identifier of the label (unique within the parent label provider) | |
bool | labelAllParts () const |
Returns true if all parts of the feature should be labeled. | |
QString | labelText () const |
Text of the label. | |
pal::Layer * | layer () const |
Gets PAL layer of the label feature. Should be only used internally in PAL. | |
double | lineAnchorPercent () const |
Returns the percent along the line at which labels should be placed, for line labels only. | |
QgsLabelLineSettings::AnchorTextPoint | lineAnchorTextPoint () const |
Returns the line anchor text point, which dictates which part of the label text should be placed at the lineAnchorPercent(). | |
QgsLabelLineSettings::AnchorType | lineAnchorType () const |
Returns the line anchor type, which dictates how the lineAnchorPercent() setting is handled. | |
double | maximumDistance () const |
Returns the maximum distance which labels are allowed to be from their corresponding points. | |
double | minimumSize () const |
Returns the minimum size (in map unit) for a feature to be labelled. | |
const QgsLabelObstacleSettings & | obstacleSettings () const |
Returns the label's obstacle settings. | |
Qgis::LabelOffsetType | offsetType () const |
Returns the offset type, which determines how offsets and distance to label behaves. | |
QgsCoordinateReferenceSystem | originalFeatureCrs () const |
Returns the original layer CRS of the feature associated with the label. | |
QRectF | outerBounds () const |
Returns the extreme outer bounds of the label feature, including any surrounding content like borders or background shapes. | |
Qgis::LabelOverlapHandling | overlapHandling () const |
Returns the technique to use for handling overlapping labels for the feature. | |
double | overrunDistance () const |
Returns the permissible distance (in map units) which labels are allowed to overrun the start or end of linear features. | |
double | overrunSmoothDistance () const |
Returns the distance (in map units) with which the ends of linear features are averaged over when calculating the direction at which to overrun labels. | |
QgsGeometry | permissibleZone () const |
Returns the label's permissible zone geometry. | |
const GEOSPreparedGeometry * | permissibleZonePrepared () const |
Returns a GEOS prepared geometry representing the label's permissibleZone(). | |
Qgis::LabelPolygonPlacementFlags | polygonPlacementFlags () const |
Returns the polygon placement flags, which dictate how polygon labels can be placed. | |
QgsPointXY | positionOffset () const |
Applies only to "offset from point" placement strategy. | |
QVector< Qgis::LabelPredefinedPointPosition > | predefinedPositionOrder () const |
Returns the priority ordered list of predefined positions for label candidates. | |
Qgis::LabelPrioritization | prioritization () const |
Returns the label prioritization technique. | |
double | priority () const |
Returns the feature's labeling priority. | |
QgsAbstractLabelProvider * | provider () const |
Returns provider of this instance. | |
QPointF | quadOffset () const |
Applies to "offset from point" placement strategy and "around point" (in case hasFixedQuadrant() returns true ). | |
double | repeatDistance () const |
Applies only to linestring features - after what distance (in map units) the labels should be repeated (0 = no repetitions) | |
void | setAllowDegradedPlacement (bool allow) |
Sets whether the label can be placed in inferior fallback positions if it cannot otherwise be placed. | |
void | setAlwaysShow (bool enabled) |
Sets whether label should be always shown (sets very high label priority) | |
void | setAnchorPosition (const QgsPointXY &anchorPosition) |
In case of quadrand or aligned positioning, this is set to the anchor point. | |
void | setArrangementFlags (Qgis::LabelLinePlacementFlags flags) |
Sets the feature's arrangement flags. | |
void | setDistLabel (double dist) |
Applies to "around point" placement strategy or linestring features. | |
void | setFeature (const QgsFeature &feature) |
Sets the original feature associated with this label. | |
void | setFixedAngle (double angle) |
Sets the angle in radians of the fixed angle (relevant only if hasFixedAngle() returns true ). | |
void | setFixedPosition (const QgsPointXY &point) |
Sets coordinates of the fixed position (relevant only if hasFixedPosition() returns true ) | |
void | setHasFixedAngle (bool enabled) |
Sets whether the label should use a fixed angle instead of using angle from automatic placement. | |
void | setHasFixedPosition (bool enabled) |
Sets whether the label should use a fixed position instead of being automatically placed. | |
void | setHasFixedQuadrant (bool enabled) |
Sets whether the quadrant for the label must be respected. | |
void | setLabelAllParts (bool labelAllParts) |
Sets whether all parts of the feature should be labeled. | |
void | setLabelText (const QString &text) |
Sets text of the label. | |
void | setLayer (pal::Layer *layer) |
Assign PAL layer to the label feature. Should be only used internally in PAL. | |
void | setLineAnchorPercent (double percent) |
Sets the percent along the line at which labels should be placed, for line labels only. | |
void | setLineAnchorTextPoint (QgsLabelLineSettings::AnchorTextPoint point) |
Sets the line anchor text point, which dictates which part of the label text should be placed at the lineAnchorPercent(). | |
void | setLineAnchorType (QgsLabelLineSettings::AnchorType type) |
Sets the line anchor type, which dictates how the lineAnchorPercent() setting is handled. | |
void | setMaximumDistance (double distance) |
Sets the maximum distance which labels are allowed to be from their corresponding points. | |
void | setMinimumSize (double size) |
Sets the minimum size (in map unit) for a feature to be labelled. | |
void | setObstacleSettings (const QgsLabelObstacleSettings &settings) |
Sets the label's obstacle settings. | |
void | setOffsetType (Qgis::LabelOffsetType type) |
Sets the offset type, which determines how offsets and distance to label behaves. | |
void | setOriginalFeatureCrs (const QgsCoordinateReferenceSystem &crs) |
Sets the original layer crs of the feature associated with the label. | |
void | setOuterBounds (const QRectF &bounds) |
Sets the extreme outer bounds of the label feature, including any surrounding content like borders or background shapes. | |
void | setOverlapHandling (Qgis::LabelOverlapHandling handling) |
Sets the technique to use for handling overlapping labels for the feature. | |
void | setOverrunDistance (double distance) |
Sets the permissible distance (in map units) which labels are allowed to overrun the start or end of linear features. | |
void | setOverrunSmoothDistance (double distance) |
Sets the distance (in map units) with which the ends of linear features are averaged over when calculating the direction at which to overrun labels. | |
void | setPermissibleZone (const QgsGeometry &geometry) |
Sets the label's permissible zone geometry. | |
void | setPolygonPlacementFlags (Qgis::LabelPolygonPlacementFlags flags) |
Sets the polygon placement flags, which dictate how polygon labels can be placed. | |
void | setPositionOffset (const QgsPointXY &offset) |
Applies only to "offset from point" placement strategy. | |
void | setPredefinedPositionOrder (const QVector< Qgis::LabelPredefinedPointPosition > &order) |
Sets the priority ordered list of predefined positions for label candidates. | |
void | setPrioritization (Qgis::LabelPrioritization prioritization) |
Sets the label prioritization technique. | |
void | setPriority (double priority) |
Sets the priority for labeling the feature. | |
void | setQuadOffset (QPointF quadOffset) |
Set which side of the point to use. | |
void | setRepeatDistance (double dist) |
Applies only to linestring features - set after what distance (in map units) the labels should be repeated (0 = no repetitions) | |
void | setRotatedSize (QSizeF size) |
Sets an alternate label size to be used when a label rotation angle is between 45 to 135 and 235 to 313 degrees and the text rotation mode is set to rotation-based. | |
void | setSymbol (const QgsSymbol *symbol) |
Sets the feature symbol associated with this label. | |
void | setSymbolSize (QSizeF size) |
Sets the size of the rendered symbol associated with this feature. | |
void | setVisualMargin (const QgsMargins &margin) |
Sets the visual margin for the label feature. | |
void | setZIndex (double zIndex) |
Sets the label's z-index. | |
QSizeF | size (double angle=0.0) const |
Size of the label (in map units). | |
const QgsSymbol * | symbol () const |
Returns the feature symbol associated with this label. | |
const QSizeF & | symbolSize () const |
Returns the size of the rendered symbol associated with this feature, if applicable. | |
const QgsMargins & | visualMargin () const |
Returns the visual margin for the label feature. | |
double | zIndex () const |
Returns the label's z-index. | |
Static Public Member Functions | |
static QgsPrecalculatedTextMetrics | calculateTextMetrics (const QgsMapToPixel *xform, const QgsRenderContext &context, const QgsTextFormat &format, const QFont &baseFont, const QFontMetricsF &fontMetrics, double letterSpacing, double wordSpacing, const QString &text=QString(), QgsTextDocument *document=nullptr, QgsTextDocumentMetrics *metrics=nullptr) |
Calculate text metrics for later retrieval via textMetrics(). | |
Protected Attributes | |
QMap< QgsPalLayerSettings::Property, QVariant > | mDataDefinedValues |
Stores attribute values for data defined properties. | |
QFont | mDefinedFont |
Font for rendering. | |
QgsTextDocument | mDocument |
QgsTextDocumentMetrics | mDocumentMetrics |
double | mMaximumCharacterAngleInside = 0 |
double | mMaximumCharacterAngleOutside = 0 |
std::optional< QgsPrecalculatedTextMetrics > | mTextMetrics |
Protected Attributes inherited from QgsLabelFeature | |
bool | mAlwaysShow = false |
whether to always show label - even in case of collisions | |
Qgis::LabelLinePlacementFlags | mArrangementFlags = Qgis::LabelLinePlacementFlags() |
double | mDistLabel = 0 |
distance of label from the feature (only for "around point" placement or linestrings) | |
double | mFixedAngle = 0 |
fixed rotation for the label (instead of automatic choice) | |
QgsPointXY | mFixedPosition |
fixed position for the label (instead of automatic placement) | |
geos::unique_ptr | mGeometry |
Geometry of the feature to be labelled. | |
bool | mHasFixedAngle = false |
whether mFixedAngle should be respected | |
bool | mHasFixedPosition = false |
whether mFixedPosition should be respected | |
bool | mHasFixedQuadrant = false |
whether mQuadOffset should be respected (only for "around point" placement) | |
QgsFeatureId | mId |
Associated ID unique within the parent label provider. | |
QString | mLabelText |
text of the label | |
pal::Layer * | mLayer = nullptr |
Pointer to PAL layer (assigned when registered to PAL) | |
double | mMaximumDistance = 0 |
Maximum distance of label from the feature. | |
Qgis::LabelOffsetType | mOffsetType = Qgis::LabelOffsetType::FromPoint |
Offset type for certain placement modes. | |
QRectF | mOuterBounds |
Extreme outer bounds of the label feature, including any surrounding content like borders or background shapes. | |
double | mOverrunDistance = 0 |
Distance to allow label to overrun linear features. | |
double | mOverrunSmoothDistance = 0 |
Distance to smooth angle of line start and end when calculating overruns. | |
QgsGeometry | mPermissibleZone |
Optional geometry to use for label's permissible zone. | |
Qgis::LabelPolygonPlacementFlags | mPolygonPlacementFlags = Qgis::LabelPolygonPlacementFlag::AllowPlacementInsideOfPolygon |
QgsPointXY | mPositionOffset |
offset of label from the feature (only for "offset from point" placement) | |
QVector< Qgis::LabelPredefinedPointPosition > | mPredefinedPositionOrder |
Ordered list of predefined positions for label (only for OrderedPositionsAroundPoint placement) | |
double | mPriority = -1 |
Priority of the label. | |
QPointF | mQuadOffset |
whether the side of the label is fixed (only for "around point" placement) | |
double | mRepeatDistance = 0 |
distance after which label should be repeated (only for linestrings) | |
QSizeF | mRotatedSize |
Width and height of the label when rotated between 45 to 135 and 235 to 315 degrees;. | |
QSizeF | mSize |
Width and height of the label. | |
QSizeF | mSymbolSize |
Size of associated rendered symbol, if applicable. | |
QgsMargins | mVisualMargin |
Visual margin of label contents. | |
double | mZIndex = 0 |
Z-index of label (higher z-index labels are rendered on top of lower z-index labels) | |
Class that adds extra information to QgsLabelFeature for text labels.
Definition at line 35 of file qgstextlabelfeature.h.
QgsTextLabelFeature::QgsTextLabelFeature | ( | QgsFeatureId | id, |
geos::unique_ptr | geometry, | ||
QSizeF | size | ||
) |
Construct text label feature.
Definition at line 26 of file qgstextlabelfeature.cpp.
|
overridedefault |
Clean up.
|
static |
Calculate text metrics for later retrieval via textMetrics().
Definition at line 52 of file qgstextlabelfeature.cpp.
QgsTextCharacterFormat QgsTextLabelFeature::characterFormat | ( | int | partId | ) | const |
Returns the character format corresponding to the specified label part.
partId | Set to the required part index for labels which are broken into parts (curved labels) |
This only returns valid formats for curved label placements.
Definition at line 42 of file qgstextlabelfeature.cpp.
|
inline |
Gets data-defined values.
Definition at line 69 of file qgstextlabelfeature.h.
|
inline |
Font to be used for rendering.
Definition at line 76 of file qgstextlabelfeature.h.
|
inline |
Returns the document for the label.
Definition at line 109 of file qgstextlabelfeature.h.
|
inline |
Returns the document metrics for the label.
Definition at line 117 of file qgstextlabelfeature.h.
bool QgsTextLabelFeature::hasCharacterFormat | ( | int | partId | ) | const |
Returns true
if the feature contains specific character formatting for the part with matching ID.
Definition at line 47 of file qgstextlabelfeature.cpp.
|
inline |
Returns the maximum angle (in radians) between inside curved label characters.
Definition at line 141 of file qgstextlabelfeature.h.
|
inline |
Returns the maximum angle (in radians) between outside curved label characters.
Definition at line 157 of file qgstextlabelfeature.h.
|
inline |
Sets data-defined values.
Definition at line 71 of file qgstextlabelfeature.h.
|
inline |
Sets font to be used for rendering.
Definition at line 74 of file qgstextlabelfeature.h.
void QgsTextLabelFeature::setDocument | ( | const QgsTextDocument & | document, |
const QgsTextDocumentMetrics & | metrics | ||
) |
Sets the document and document metrics for the label.
Definition at line 226 of file qgstextlabelfeature.cpp.
|
inline |
Sets the maximum angle (in radians) between inside curved label characters.
Definition at line 133 of file qgstextlabelfeature.h.
|
inline |
Sets the maximum angle (in radians) between outside curved label characters.
Definition at line 149 of file qgstextlabelfeature.h.
|
inline |
Sets additional text metrics required for curved label placement.
Definition at line 94 of file qgstextlabelfeature.h.
QString QgsTextLabelFeature::text | ( | int | partId | ) | const |
Returns the text component corresponding to a specified label part.
partId | Set to -1 for labels which are not broken into parts (e.g., non-curved labels), or the required part index for labels which are broken into parts (curved labels) |
Definition at line 34 of file qgstextlabelfeature.cpp.
|
inline |
Returns additional info required for curved label placement.
Returns nullptr
if not set.
Definition at line 86 of file qgstextlabelfeature.h.
|
protected |
Stores attribute values for data defined properties.
Definition at line 165 of file qgstextlabelfeature.h.
|
protected |
Font for rendering.
Definition at line 162 of file qgstextlabelfeature.h.
|
protected |
Definition at line 167 of file qgstextlabelfeature.h.
|
protected |
Definition at line 168 of file qgstextlabelfeature.h.
|
protected |
Definition at line 170 of file qgstextlabelfeature.h.
|
protected |
Definition at line 171 of file qgstextlabelfeature.h.
|
protected |
Definition at line 173 of file qgstextlabelfeature.h.