QGIS API Documentation
3.16.0-Hannover (43b64b13f3)
|
Go to the documentation of this file.
21 #ifndef QGSPALLABELING_H
22 #define QGSPALLABELING_H
24 #include "qgis_core.h"
28 #include <QFontDatabase>
108 QgsLabelPosition(
QgsFeatureId id,
double r,
const QVector< QgsPointXY > &corners,
const QgsRectangle &rect,
double w,
double h,
const QString &layer,
const QString &labeltext,
const QFont &labelfont,
bool upside_down,
bool diagram =
false,
bool pinned =
false,
const QString &providerId = QString(),
112 , cornerPoints( corners )
114 , labelGeometry( labelGeometry )
118 , labelText( labeltext )
119 , labelFont( labelfont )
120 , upsideDown( upside_down )
121 , isDiagram( diagram )
123 , providerID( providerId )
124 , isUnplaced( isUnplaced )
177 bool upsideDown =
false;
182 bool isDiagram =
false;
187 bool isPinned =
false;
199 bool isUnplaced =
false;
271 enum Q_DECL_DEPRECATED LinePlacementFlags
308 enum Q_DECL_DEPRECATED DirectionSymbols
320 MultiFollowPlacement,
359 FontLetterSpacing = 28,
360 FontWordSpacing = 29,
364 MultiLineWrapChar = 31,
365 AutoWrapLength = 101,
366 MultiLineHeight = 32,
367 MultiLineAlignment = 33,
368 TextOrientation = 110,
372 DirSymbPlacement = 37,
385 BufferJoinStyle = 44,
386 BufferBlendMode = 45,
390 MaskBufferSize = 105,
391 MaskBufferUnit = 106,
403 ShapeRotationType = 52,
406 ShapeOffsetUnits = 55,
408 ShapeRadiiUnits = 57,
409 ShapeTransparency = 63,
413 ShapeStrokeColor = 59,
414 ShapeStrokeWidth = 60,
415 ShapeStrokeWidthUnits = 61,
421 ShadowOffsetAngle = 67,
422 ShadowOffsetDist = 68,
423 ShadowOffsetUnits = 69,
425 ShadowRadiusUnits = 71,
426 ShadowTransparency = 72,
430 ShadowBlendMode = 75,
440 CurvedCharAngleInOut = 83,
449 RepeatDistanceUnit = 86,
451 PredefinedPositionOrder = 91,
452 LinePlacementOptions = 99,
453 OverrunDistance = 102,
455 PolygonLabelOutside = 109,
456 LineAnchorPercent = 111,
459 ScaleVisibility = 23,
530 bool drawLabels =
true;
545 bool isExpression =
false;
555 Q_DECL_DEPRECATED QColor previewBkgrdColor = Qt::white;
560 bool useSubstitutions =
false;
577 int autoWrapLength = 0;
589 bool useMaxLineLengthForAutoWrap =
true;
600 bool formatNumbers =
false;
614 bool plusSign =
false;
640 bool centroidWhole =
false;
647 bool centroidInside =
false;
655 QVector< PredefinedPointPosition > predefinedPositionOrder
SIP_SKIP;
660 bool fitInPolygonOnly =
false;
691 double repeatDistance = 0;
745 double angleOffset = 0;
748 bool preserveRotation =
true;
754 double maxCurvedCharAngleIn = 25.0;
760 double maxCurvedCharAngleOut = -25.0;
775 bool scaleVisibility =
false;
787 double maximumScale = 0;
799 double minimumScale = 0;
806 bool fontLimitPixelSize =
false;
813 int fontMinPixelSize = 0;
820 int fontMaxPixelSize = 10000;
823 bool displayAll =
false;
832 bool labelPerPart =
false;
837 SIP_PROPERTY( name = limitNumLabels, get = _limitNumLabels, set = _setLimitNumLabels )
838 SIP_PROPERTY( name = maxNumLabels, get = _maxNumLabels, set = _setMaxNumLabels )
839 SIP_PROPERTY( name = minFeatureSize, get = _minFeatureSize, set = _setMinFeatureSize )
840 SIP_PROPERTY( name = obstacle, get = _getIsObstacle, set = _setIsObstacle )
841 SIP_PROPERTY( name = obstacleFactor, get = _getObstacleFactor, set = _setObstacleFactor )
842 SIP_PROPERTY( name = obstacleType, get = _getObstacleType, set = _setObstacleType )
843 SIP_PROPERTY( name = placementFlags, get = _getLinePlacementFlags, set = _setLinePlacementFlags )
844 SIP_PROPERTY( name = mergeLines, get = _getMergeLines, set = _setMergeLines )
845 SIP_PROPERTY( name = addDirectionSymbol, get = _getAddDirectionSymbol, set = _setAddDirectionSymbol )
846 SIP_PROPERTY( name = leftDirectionSymbol, get = _getLeftDirectionSymbol, set = _setLeftDirectionSymbol )
847 SIP_PROPERTY( name = rightDirectionSymbol, get = _getRightDirectionSymbol, set = _setRightDirectionSymbol )
848 SIP_PROPERTY( name = reverseDirectionSymbol, get = _getReverseDirectionSymbol, set = _setReverseDirectionSymbol )
849 SIP_PROPERTY( name = placeDirectionSymbol, get = _getPlaceDirectionSymbol, set = _setPlaceDirectionSymbol )
851 SIP_PROPERTY( name = overrunDistance, get = _getOverrunDistance, set = _setOverrunDistance )
852 SIP_PROPERTY( name = overrunDistanceUnit, get = _getOverrunDistanceUnit, set = _setOverrunDistanceUnit )
853 SIP_PROPERTY( name = overrunDistanceMapUnitScale, get = _getOverrunDistanceMapUnitScale, set = _setOverrunDistanceMapUnitScale )
857 bool _limitNumLabels()
const {
return mThinningSettings.limitNumberOfLabelsEnabled(); }
858 void _setLimitNumLabels(
bool limit ) { mThinningSettings.setLimitNumberLabelsEnabled( limit ); }
859 int _maxNumLabels()
const {
return mThinningSettings.maximumNumberLabels(); }
860 void _setMaxNumLabels(
int max ) { mThinningSettings.setMaximumNumberLabels( max ); }
861 double _minFeatureSize()
const {
return mThinningSettings.minimumFeatureSize(); }
862 void _setMinFeatureSize(
double size ) { mThinningSettings.setMinimumFeatureSize( size ); }
863 bool _getIsObstacle()
const {
return mObstacleSettings.isObstacle(); }
864 void _setIsObstacle(
bool obstacle ) { mObstacleSettings.setIsObstacle( obstacle ); }
865 double _getObstacleFactor()
const {
return mObstacleSettings.factor(); }
866 void _setObstacleFactor(
double factor ) { mObstacleSettings.setFactor( factor ); }
867 ObstacleType _getObstacleType()
const {
return static_cast< ObstacleType
>( mObstacleSettings.type() ); }
869 unsigned int _getLinePlacementFlags()
const {
return static_cast< unsigned int >( mLineSettings.placementFlags() ); }
870 void _setLinePlacementFlags(
unsigned int flags ) { mLineSettings.setPlacementFlags(
static_cast< QgsLabeling::LinePlacementFlags
>( flags ) ); }
871 bool _getMergeLines()
const {
return mLineSettings.mergeLines(); }
872 void _setMergeLines(
bool merge ) { mLineSettings.setMergeLines( merge ); }
873 bool _getAddDirectionSymbol()
const {
return mLineSettings.addDirectionSymbol(); }
874 void _setAddDirectionSymbol(
bool add ) { mLineSettings.setAddDirectionSymbol( add ); }
875 QString _getLeftDirectionSymbol()
const {
return mLineSettings.leftDirectionSymbol(); }
876 void _setLeftDirectionSymbol(
const QString &symbol ) { mLineSettings.setLeftDirectionSymbol( symbol ); }
877 QString _getRightDirectionSymbol()
const {
return mLineSettings.rightDirectionSymbol(); }
878 void _setRightDirectionSymbol(
const QString &symbol ) { mLineSettings.setRightDirectionSymbol( symbol ); }
879 bool _getReverseDirectionSymbol()
const {
return mLineSettings.reverseDirectionSymbol(); }
880 void _setReverseDirectionSymbol(
bool reverse ) { mLineSettings.setReverseDirectionSymbol( reverse ); }
882 DirectionSymbols _getPlaceDirectionSymbol()
const {
return static_cast< DirectionSymbols
>( mLineSettings.directionSymbolPlacement() ); }
885 double _getOverrunDistance()
const {
return mLineSettings.overrunDistance(); }
886 void _setOverrunDistance(
double distance ) { mLineSettings.setOverrunDistance( distance ); }
889 QgsMapUnitScale _getOverrunDistanceMapUnitScale()
const {
return mLineSettings.overrunDistanceMapUnitScale(); }
890 void _setOverrunDistanceMapUnitScale(
const QgsMapUnitScale &scale ) { mLineSettings.setOverrunDistanceMapUnitScale( scale ); }
903 bool geometryGeneratorEnabled =
false;
918 void calculateLabelSize(
const QFontMetricsF *fm,
const QString &text,
double &labelX,
double &labelY,
const QgsFeature *f =
nullptr,
QgsRenderContext *context =
nullptr,
double *rotatedLabelX
SIP_OUT =
nullptr,
double *rotatedLabelY
SIP_OUT =
nullptr,
921 void calculateLabelSize(
const QFontMetricsF *fm,
const QString &text,
double &labelX,
double &labelY,
const QgsFeature *f =
nullptr,
QgsRenderContext *context =
nullptr,
double *rotatedLabelX
SIP_OUT =
nullptr,
double *rotatedLabelY
SIP_OUT =
nullptr );
1094 static QPixmap labelSettingsPreviewPixmap(
const QgsPalLayerSettings &settings, QSize size,
const QString &previewText = QString(),
int padding = 0 );
1106 int mFeaturesToLabel = 0;
1107 int mFeatsSendingToPal = 0;
1108 int mFeatsRegPal = 0;
1122 void readOldDataDefinedPropertyMap(
QgsVectorLayer *layer, QDomElement *parentElem );
1129 enum DataDefinedValueType
1148 bool dataDefinedValEval( DataDefinedValueType valType,
1150 QVariant &exprVal,
QgsExpressionContext &context,
const QVariant &originalValue = QVariant() );
1152 void parseTextStyle( QFont &labelFont,
1177 QMap<Property, QVariant> dataDefinedValues;
1184 QFontDatabase mFontDB;
1188 std::unique_ptr< QgsCallout > mCallout;
1194 QgsLabeling::PolygonPlacementFlags mPolygonPlacementFlags = QgsLabeling::PolygonPlacementFlag::AllowPlacementInsideOfPolygon;
1198 bool mRenderStarted =
false;
1200 static void initPropertyDefinitions();
1235 QList<QgsLabelPosition> labelsAtPosition(
const QgsPointXY &p )
const;
1237 QList<QgsLabelPosition> labelsWithinRect(
const QgsRectangle &r )
const;
1250 std::unique_ptr< QgsLabelSearchTree > mLabelSearchTree;
1269 static bool staticWillUseLayer(
const QgsMapLayer *layer );
1310 static QStringList splitToLines(
const QString &text,
const QString &wrapCharacter,
int autoWrapLength = 0,
bool useMaxLineLengthWhenAutoWrapping =
true );
1320 static QStringList splitToGraphemes(
const QString &text );
1325 const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues );
1329 const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues );
1333 const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues );
1337 const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues );
1341 const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues );
1345 const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues );
1364 #endif // QGSPALLABELING_H
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
QgsCoordinateTransform ct
@ PerimeterCurved
Arranges candidates following the curvature of a polygon's boundary. Applies to polygon layers only.
RenderUnit
Rendering size units.
@ AroundPoint
Arranges candidates in a circle around a point (or centroid of a polygon). Applies to point or polygo...
QgsLabelCandidate(const QRectF &r, double c)
The class is used as a container of context for various read/write operations on other objects.
@ FromSymbolBounds
Offset distance applies from rendered symbol bounds.
QgsLabelLineSettings & lineSettings()
Returns the label line settings, which contain settings related to how the label engine places and fo...
Abstract base class for callout renderers.
void setPolygonPlacementFlags(QgsLabeling::PolygonPlacementFlags flags)
Sets the polygon placement flags, which dictate how polygon labels can be placed.
SymbolLeftRight
Place direction symbols on left/right of label.
QgsLabelingResults(const QgsLabelingResults &)=delete
QgsLabelingResults cannot be copied.
const QgsCoordinateReferenceSystem & crs
LabelPosition is a candidate feature label position.
QgsLabelObstacleSettings & obstacleSettings()
Returns the label obstacle settings.
MapOrientation
Signifies that the AboveLine and BelowLine flags should respect the map's orientation rather than the...
The QgsVectorLayerDiagramProvider class implements support for diagrams within the labeling engine.
@ FromPoint
Offset distance applies from point geometry.
Container of fields for a vector layer.
AboveLine
Labels can be placed above a line feature.
const QgsLabelThinningSettings & thinningSettings() const
Returns the label thinning settings.
const QgsLabelObstacleSettings & obstacleSettings() const
Returns the label obstacle settings.
Class that stores computed placement from labeling engine.
@ MiddleRight
Label on right of point.
@ TopRight
Label on top-right of point.
OffsetType
Behavior modifier for label offset and distance, only applies in some label placement modes.
Contains information about the context of a rendering operation.
@ RenderMillimeters
Millimeters.
QFont labelFont
Font which the label is rendered using.
QgsStringReplacementCollection substitutions
Substitution collection for automatic text substitution with labels.
Contains settings related to how the label engine treats features as obstacles.
Abstract base class for all rendered symbols.
@ Line
Arranges candidates parallel to a generalised line representing the feature or parallel to a polygon'...
Class that adds extra information to QgsLabelFeature for text labels.
@ TopSlightlyRight
Label on top of point, slightly right of center.
The QgsVectorLayerLabelProvider class implements a label provider for vector layers.
A rectangle specified with double values.
@ OverPoint
Arranges candidates over a point (or centroid of a polygon), or at a preset offset from the point....
QgsLabelPosition(QgsFeatureId id, double r, const QVector< QgsPointXY > &corners, const QgsRectangle &rect, double w, double h, const QString &layer, const QString &labeltext, const QFont &labelfont, bool upside_down, bool diagram=false, bool pinned=false, const QString &providerId=QString(), const QgsGeometry &labelGeometry=QgsGeometry(), bool isUnplaced=false)
Constructor for QgsLabelPosition.
ObstacleType
Valid obstacle types, which affect how features within the layer will act as obstacles for labels.
@ TopMiddle
Label directly above point.
void setThinningSettings(const QgsLabelThinningSettings &settings)
Sets the label thinning settings.
QString providerID
ID of the associated label provider.
@ BottomMiddle
Label directly below point.
#define Q_NOWARN_DEPRECATED_POP
@ OrderedPositionsAroundPoint
Candidates are placed in predefined positions around a point. Preference is given to positions with g...
Container for all settings relating to text rendering.
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.
Placement
Placement modes which determine how label candidates are generated for a feature.
@ Curved
Arranges candidates following the curvature of a line feature. Applies to line layers only.
void setDataDefinedProperties(const QgsPropertyCollection &collection)
Sets the label's property collection, used for data defined overrides.
QString wrapChar
Wrapping character string.
@ TopSlightlyLeft
Label on top of point, slightly left of center.
@ BottomSlightlyLeft
Label below point, slightly left of center.
const QgsTextFormat & format() const
Returns the label text formatting settings, e.g., font settings, buffer settings, etc.
QgsLabelingResults & operator=(const QgsLabelingResults &rh)=delete
QgsLabelingResults cannot be copied.
void setFormat(const QgsTextFormat &format)
Sets the label text formatting settings, e.g., font settings, buffer settings, etc.
QgsMapUnitScale repeatDistanceMapUnitScale
Map unit scale for repeating labels for a single feature.
QgsLabelThinningSettings & thinningSettings()
Returns the label thinning settings.
Stores the settings for rendering of all diagrams for a layer.
@ Upright
Upside-down labels (90 <= angle < 270) are shown upright.
@ MiddleLeft
Label on left of point.
PredefinedPointPosition
Positions for labels when using the QgsPalLabeling::OrderedPositionsAroundPoint placement mode.
const QgsLabelLineSettings & lineSettings() const
Returns the label line settings, which contain settings related to how the label engine places and fo...
@ ShowDefined
Show upside down when rotation is layer- or data-defined.
Struct for storing maximum and minimum scales for measurements in map units.
QString labelText
String shown in label.
const QgsPropertyCollection & dataDefinedProperties() const
Returns a reference to the label's property collection, used for data defined overrides.
Contains settings related to how the label engine removes candidate label positions and reduces the n...
A collection of string replacements (specified using QgsStringReplacement objects).
QString layerID
ID of associated map layer.
This class represents a coordinate reference system (CRS).
@ BottomSlightlyRight
Label below point, slightly right of center.
@ Horizontal
Arranges horizontal candidates scattered throughout a polygon feature. Applies to polygon layers only...
The QgsLabelingEngine class provides map labeling functionality.
OnLine
Labels can be placed directly over a line feature.
A class to represent a 2D point.
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
@ TopLeft
Label on top-left of point.
Contains settings related to how the label engine places and formats labels for line features (or pol...
QString fieldName
Name of field (or an expression) to use for label text.
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
A geometry is the spatial representation of a feature.
Perform transforms between map coordinates and device coordinates.
QString geometryGenerator
The geometry generator expression. Null if disabled.
Represents a vector layer which manages a vector based data sets.
Base class for all map layer types.
@ OutsidePolygons
Candidates are placed outside of polygon boundaries. Applies to polygon layers only....
void setLineSettings(const QgsLabelLineSettings &settings)
Sets the label line settings, which contain settings related to how the label engine places and forma...
Represents a document consisting of one or more QgsTextBlock objects.
QgsCallout * callout() const
Returns the label callout renderer, responsible for drawing label callouts.
QgsLabelPosition()=default
Constructor for QgsLabelPosition.
QgsMapUnitScale labelOffsetMapUnitScale
Map unit scale for label offset.
@ BottomRight
Label on bottom right of point.
#define SIP_PROPERTY(name, getter, setter)
QgsGeometry labelGeometry
A polygon geometry representing the label's bounds in map coordinates.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Property
Data definable properties.
ObstacleType
Valid obstacle types, which affect how features within the layer will act as obstacles for labels.
A class to query the labeling structure at a given point (small wrapper around pal RTree class)
The QgsLabelFeature class describes a feature that should be used within the labeling engine.
Class for parsing and evaluation of expressions (formerly called "search strings").
The QgsMapSettings class contains configuration for rendering of the map.
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the label's property collection, used for data defined overrides.
#define Q_NOWARN_DEPRECATED_PUSH
@ Free
Arranges candidates scattered throughout a polygon feature. Candidates are rotated to respect the pol...
DirectionSymbolPlacement
Placement options for direction symbols.
QgsLabeling::PolygonPlacementFlags polygonPlacementFlags() const
Returns the polygon placement flags, which dictate how polygon labels can be placed.
BelowLine
Labels can be placed below a line feature.
QVector< QgsPointXY > cornerPoints
void setObstacleSettings(const QgsLabelObstacleSettings &settings)
Sets the label obstacle settings.
QgsMapUnitScale distMapUnitScale
Map unit scale for label feature distance.
@ BottomLeft
Label on bottom-left of point.
SymbolAbove
Place direction symbols on above label.
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features