21 #ifndef QGSPALLABELING_H
22 #define QGSPALLABELING_H
24 #include "qgis_core.h"
28 #include <QFontDatabase>
109 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(),
113 , cornerPoints( corners )
115 , labelGeometry( labelGeometry )
119 , labelText( labeltext )
120 , labelFont( labelfont )
121 , upsideDown( upside_down )
122 , isDiagram( diagram )
124 , providerID( providerId )
125 , isUnplaced( isUnplaced )
178 bool upsideDown =
false;
183 bool isDiagram =
false;
188 bool isPinned =
false;
200 bool isUnplaced =
false;
322 MultiFollowPlacement,
361 FontLetterSpacing = 28,
362 FontWordSpacing = 29,
366 MultiLineWrapChar = 31,
367 AutoWrapLength = 101,
368 MultiLineHeight = 32,
369 MultiLineAlignment = 33,
370 TextOrientation = 110,
374 DirSymbPlacement = 37,
387 BufferJoinStyle = 44,
388 BufferBlendMode = 45,
392 MaskBufferSize = 105,
393 MaskBufferUnit = 106,
405 ShapeRotationType = 52,
408 ShapeOffsetUnits = 55,
410 ShapeRadiiUnits = 57,
411 ShapeTransparency = 63,
415 ShapeStrokeColor = 59,
416 ShapeStrokeWidth = 60,
417 ShapeStrokeWidthUnits = 61,
423 ShadowOffsetAngle = 67,
424 ShadowOffsetDist = 68,
425 ShadowOffsetUnits = 69,
427 ShadowRadiusUnits = 71,
428 ShadowTransparency = 72,
432 ShadowBlendMode = 75,
442 CurvedCharAngleInOut = 83,
451 RepeatDistanceUnit = 86,
453 PredefinedPositionOrder = 91,
454 LinePlacementOptions = 99,
455 OverrunDistance = 102,
457 PolygonLabelOutside = 109,
458 LineAnchorPercent = 111,
461 ScaleVisibility = 23,
532 bool drawLabels =
true;
547 bool isExpression =
false;
557 Q_DECL_DEPRECATED QColor previewBkgrdColor = Qt::white;
562 bool useSubstitutions =
false;
579 int autoWrapLength = 0;
591 bool useMaxLineLengthForAutoWrap =
true;
602 bool formatNumbers =
false;
616 bool plusSign =
false;
642 bool centroidWhole =
false;
649 bool centroidInside =
false;
657 QVector< PredefinedPointPosition > predefinedPositionOrder
SIP_SKIP;
662 bool fitInPolygonOnly =
false;
693 double repeatDistance = 0;
747 double angleOffset = 0;
750 bool preserveRotation =
true;
756 double maxCurvedCharAngleIn = 25.0;
762 double maxCurvedCharAngleOut = -25.0;
777 bool scaleVisibility =
false;
789 double maximumScale = 0;
801 double minimumScale = 0;
808 bool fontLimitPixelSize =
false;
815 int fontMinPixelSize = 0;
822 int fontMaxPixelSize = 10000;
825 bool displayAll =
false;
834 bool labelPerPart =
false;
839 SIP_PROPERTY( name = limitNumLabels, get = _limitNumLabels, set = _setLimitNumLabels )
840 SIP_PROPERTY( name = maxNumLabels, get = _maxNumLabels, set = _setMaxNumLabels )
841 SIP_PROPERTY( name = minFeatureSize, get = _minFeatureSize, set = _setMinFeatureSize )
842 SIP_PROPERTY( name = obstacle, get = _getIsObstacle, set = _setIsObstacle )
843 SIP_PROPERTY( name = obstacleFactor, get = _getObstacleFactor, set = _setObstacleFactor )
844 SIP_PROPERTY( name = obstacleType, get = _getObstacleType, set = _setObstacleType )
845 SIP_PROPERTY( name = placementFlags, get = _getLinePlacementFlags, set = _setLinePlacementFlags )
846 SIP_PROPERTY( name = mergeLines, get = _getMergeLines, set = _setMergeLines )
847 SIP_PROPERTY( name = addDirectionSymbol, get = _getAddDirectionSymbol, set = _setAddDirectionSymbol )
848 SIP_PROPERTY( name = leftDirectionSymbol, get = _getLeftDirectionSymbol, set = _setLeftDirectionSymbol )
849 SIP_PROPERTY( name = rightDirectionSymbol, get = _getRightDirectionSymbol, set = _setRightDirectionSymbol )
850 SIP_PROPERTY( name = reverseDirectionSymbol, get = _getReverseDirectionSymbol, set = _setReverseDirectionSymbol )
851 SIP_PROPERTY( name = placeDirectionSymbol, get = _getPlaceDirectionSymbol, set = _setPlaceDirectionSymbol )
853 SIP_PROPERTY( name = overrunDistance, get = _getOverrunDistance, set = _setOverrunDistance )
854 SIP_PROPERTY( name = overrunDistanceUnit, get = _getOverrunDistanceUnit, set = _setOverrunDistanceUnit )
855 SIP_PROPERTY( name = overrunDistanceMapUnitScale, get = _getOverrunDistanceMapUnitScale, set = _setOverrunDistanceMapUnitScale )
859 bool _limitNumLabels()
const {
return mThinningSettings.limitNumberOfLabelsEnabled(); }
860 void _setLimitNumLabels(
bool limit ) { mThinningSettings.setLimitNumberLabelsEnabled( limit ); }
861 int _maxNumLabels()
const {
return mThinningSettings.maximumNumberLabels(); }
862 void _setMaxNumLabels(
int max ) { mThinningSettings.setMaximumNumberLabels( max ); }
863 double _minFeatureSize()
const {
return mThinningSettings.minimumFeatureSize(); }
864 void _setMinFeatureSize(
double size ) { mThinningSettings.setMinimumFeatureSize( size ); }
865 bool _getIsObstacle()
const {
return mObstacleSettings.isObstacle(); }
866 void _setIsObstacle(
bool obstacle ) { mObstacleSettings.setIsObstacle( obstacle ); }
867 double _getObstacleFactor()
const {
return mObstacleSettings.factor(); }
868 void _setObstacleFactor(
double factor ) { mObstacleSettings.setFactor( factor ); }
869 ObstacleType _getObstacleType()
const {
return static_cast< ObstacleType
>( mObstacleSettings.type() ); }
871 unsigned int _getLinePlacementFlags()
const {
return static_cast< unsigned int >( mLineSettings.placementFlags() ); }
872 void _setLinePlacementFlags(
unsigned int flags ) { mLineSettings.setPlacementFlags(
static_cast< QgsLabeling::LinePlacementFlags
>( flags ) ); }
873 bool _getMergeLines()
const {
return mLineSettings.mergeLines(); }
874 void _setMergeLines(
bool merge ) { mLineSettings.setMergeLines( merge ); }
875 bool _getAddDirectionSymbol()
const {
return mLineSettings.addDirectionSymbol(); }
876 void _setAddDirectionSymbol(
bool add ) { mLineSettings.setAddDirectionSymbol( add ); }
877 QString _getLeftDirectionSymbol()
const {
return mLineSettings.leftDirectionSymbol(); }
878 void _setLeftDirectionSymbol(
const QString &symbol ) { mLineSettings.setLeftDirectionSymbol( symbol ); }
879 QString _getRightDirectionSymbol()
const {
return mLineSettings.rightDirectionSymbol(); }
880 void _setRightDirectionSymbol(
const QString &symbol ) { mLineSettings.setRightDirectionSymbol( symbol ); }
881 bool _getReverseDirectionSymbol()
const {
return mLineSettings.reverseDirectionSymbol(); }
882 void _setReverseDirectionSymbol(
bool reverse ) { mLineSettings.setReverseDirectionSymbol( reverse ); }
884 DirectionSymbols _getPlaceDirectionSymbol()
const {
return static_cast< DirectionSymbols
>( mLineSettings.directionSymbolPlacement() ); }
887 double _getOverrunDistance()
const {
return mLineSettings.overrunDistance(); }
888 void _setOverrunDistance(
double distance ) { mLineSettings.setOverrunDistance( distance ); }
891 QgsMapUnitScale _getOverrunDistanceMapUnitScale()
const {
return mLineSettings.overrunDistanceMapUnitScale(); }
892 void _setOverrunDistanceMapUnitScale(
const QgsMapUnitScale &scale ) { mLineSettings.setOverrunDistanceMapUnitScale( scale ); }
905 bool geometryGeneratorEnabled =
false;
920 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,
923 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 );
1096 static QPixmap labelSettingsPreviewPixmap(
const QgsPalLayerSettings &settings, QSize size,
const QString &previewText = QString(),
int padding = 0 );
1108 int mFeaturesToLabel = 0;
1109 int mFeatsSendingToPal = 0;
1110 int mFeatsRegPal = 0;
1124 void readOldDataDefinedPropertyMap(
QgsVectorLayer *layer, QDomElement *parentElem );
1131 enum DataDefinedValueType
1150 bool dataDefinedValEval( DataDefinedValueType valType,
1152 QVariant &exprVal,
QgsExpressionContext &context,
const QVariant &originalValue = QVariant() );
1154 void parseTextStyle( QFont &labelFont,
1179 QMap<Property, QVariant> dataDefinedValues;
1186 QFontDatabase mFontDB;
1190 std::unique_ptr< QgsCallout > mCallout;
1196 QgsLabeling::PolygonPlacementFlags mPolygonPlacementFlags = QgsLabeling::PolygonPlacementFlag::AllowPlacementInsideOfPolygon;
1200 bool mRenderStarted =
false;
1202 static void initPropertyDefinitions();
1238 QList<QgsLabelPosition> labelsAtPosition(
const QgsPointXY &p )
const;
1240 QList<QgsLabelPosition> labelsWithinRect(
const QgsRectangle &r )
const;
1253 std::unique_ptr< QgsLabelSearchTree > mLabelSearchTree;
1273 static bool staticWillUseLayer(
const QgsMapLayer *layer );
1314 static QStringList splitToLines(
const QString &text,
const QString &wrapCharacter,
int autoWrapLength = 0,
bool useMaxLineLengthWhenAutoWrapping =
true );
1324 static QStringList splitToGraphemes(
const QString &text );
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 );
1349 const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues );
Abstract base class for callout renderers.
This class represents a coordinate reference system (CRS).
Stores the settings for rendering of all diagrams for a layer.
Exports QGIS layers to the DXF format.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Class for parsing and evaluation of expressions (formerly called "search strings").
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Container of fields for a vector layer.
A geometry is the spatial representation of a feature.
Represents a label candidate.
QgsLabelCandidate(const QRectF &r, double c)
The QgsLabelFeature class describes a feature that should be used within the labeling engine.
Contains settings related to how the label engine places and formats labels for line features (or pol...
DirectionSymbolPlacement
Placement options for direction symbols.
Contains settings related to how the label engine treats features as obstacles.
ObstacleType
Valid obstacle types, which affect how features within the layer will act as obstacles for labels.
Represents the calculated placement of a map label.
QgsGeometry labelGeometry
A polygon geometry representing the label's bounds in map coordinates.
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.
QString labelText
String shown in label.
QString providerID
ID of the associated label provider.
QgsLabelPosition()=default
Constructor for QgsLabelPosition.
QFont labelFont
Font which the label is rendered using.
QVector< QgsPointXY > cornerPoints
QString layerID
ID of associated map layer.
A class to query the labeling structure at a given point (small wrapper around pal RTree class)
Contains settings related to how the label engine removes candidate label positions and reduces the n...
The QgsLabelingEngine class provides map labeling functionality.
Class that stores computed placement from labeling engine.
QgsLabelingResults(const QgsLabelingResults &)=delete
QgsLabelingResults cannot be copied.
QgsLabelingResults & operator=(const QgsLabelingResults &rh)=delete
QgsLabelingResults cannot be copied.
Base class for all map layer types.
The QgsMapSettings class contains configuration for rendering of the map.
Perform transforms between map coordinates and device coordinates.
Struct for storing maximum and minimum scales for measurements in map units.
Contains settings for how a map layer will be labeled.
QgsMapUnitScale labelOffsetMapUnitScale
Map unit scale for label offset.
void setObstacleSettings(const QgsLabelObstacleSettings &settings)
Sets the label obstacle settings.
void setFormat(const QgsTextFormat &format)
Sets the label text formatting settings, e.g., font settings, buffer settings, etc.
QString wrapChar
Wrapping character string.
@ SymbolAbove
Place direction symbols on above label.
@ SymbolLeftRight
Place direction symbols on left/right of label.
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the label's property collection, used for data defined overrides.
QgsCoordinateTransform ct
@ ShowDefined
Show upside down when rotation is layer- or data-defined.
@ Upright
Upside-down labels (90 <= angle < 270) are shown upright.
void setLineSettings(const QgsLabelLineSettings &settings)
Sets the label line settings, which contain settings related to how the label engine places and forma...
QgsCallout * callout() const
Returns the label callout renderer, responsible for drawing label callouts.
Placement
Placement modes which determine how label candidates are generated for a feature.
@ PerimeterCurved
Arranges candidates following the curvature of a polygon's boundary. Applies to polygon layers only.
@ Curved
Arranges candidates following the curvature of a line feature. Applies to line layers only.
@ Horizontal
Arranges horizontal candidates scattered throughout a polygon feature. Applies to polygon layers only...
@ Free
Arranges candidates scattered throughout a polygon feature. Candidates are rotated to respect the pol...
@ OverPoint
Arranges candidates over a point (or centroid of a polygon), or at a preset offset from the point....
@ AroundPoint
Arranges candidates in a circle around a point (or centroid of a polygon). Applies to point or polygo...
@ Line
Arranges candidates parallel to a generalised line representing the feature or parallel to a polygon'...
@ OrderedPositionsAroundPoint
Candidates are placed in predefined positions around a point. Preference is given to positions with g...
@ OutsidePolygons
Candidates are placed outside of polygon boundaries. Applies to polygon layers only....
PredefinedPointPosition
Positions for labels when using the QgsPalLabeling::OrderedPositionsAroundPoint placement mode.
@ BottomSlightlyLeft
Label below point, slightly left of center.
@ BottomMiddle
Label directly below point.
@ BottomSlightlyRight
Label below point, slightly right of center.
@ MiddleLeft
Label on left of point.
@ TopSlightlyRight
Label on top of point, slightly right of center.
@ TopSlightlyLeft
Label on top of point, slightly left of center.
@ MiddleRight
Label on right of point.
@ TopMiddle
Label directly above point.
@ BottomRight
Label on bottom right of point.
@ BottomLeft
Label on bottom-left of point.
@ TopRight
Label on top-right of point.
@ TopLeft
Label on top-left of point.
const QgsPropertyCollection & dataDefinedProperties() const
Returns a reference to the label's property collection, used for data defined overrides.
Property
Data definable properties.
const QgsLabelLineSettings & lineSettings() const
Returns the label line settings, which contain settings related to how the label engine places and fo...
void setPolygonPlacementFlags(QgsLabeling::PolygonPlacementFlags flags)
Sets the polygon placement flags, which dictate how polygon labels can be placed.
const QgsLabelObstacleSettings & obstacleSettings() const
Returns the label obstacle settings.
OffsetType
Behavior modifier for label offset and distance, only applies in some label placement modes.
@ FromPoint
Offset distance applies from point geometry.
@ FromSymbolBounds
Offset distance applies from rendered symbol bounds.
void setThinningSettings(const QgsLabelThinningSettings &settings)
Sets the label thinning settings.
void setDataDefinedProperties(const QgsPropertyCollection &collection)
Sets the label's property collection, used for data defined overrides.
QgsLabeling::PolygonPlacementFlags polygonPlacementFlags() const
Returns the polygon placement flags, which dictate how polygon labels can be placed.
QString geometryGenerator
The geometry generator expression. Null if disabled.
QgsMapUnitScale distMapUnitScale
Map unit scale for label feature distance.
QgsStringReplacementCollection substitutions
Substitution collection for automatic text substitution with labels.
LinePlacementFlags
Line placement flags, which control how candidates are generated for a linear feature.
QgsMapUnitScale repeatDistanceMapUnitScale
Map unit scale for repeating labels for a single feature.
const QgsTextFormat & format() const
Returns the label text formatting settings, e.g., font settings, buffer settings, etc.
QString fieldName
Name of field (or an expression) to use for label text.
QgsLabelLineSettings & lineSettings()
Returns the label line settings, which contain settings related to how the label engine places and fo...
QgsLabelObstacleSettings & obstacleSettings()
Returns the label obstacle settings.
const QgsLabelThinningSettings & thinningSettings() const
Returns the label thinning settings.
ObstacleType
Valid obstacle types, which affect how features within the layer will act as obstacles for labels.
QgsLabelThinningSettings & thinningSettings()
Returns the label thinning settings.
A class to represent a 2D point.
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
The class is used as a container of context for various read/write operations on other objects.
A rectangle specified with double values.
Contains information about the context of a rendering operation.
A collection of string replacements (specified using QgsStringReplacement objects).
Abstract base class for all rendered symbols.
Represents a document consisting of one or more QgsTextBlock objects.
Container for all settings relating to text rendering.
Class that adds extra information to QgsLabelFeature for text labels.
RenderUnit
Rendering size units.
@ RenderMillimeters
Millimeters.
The QgsVectorLayerDiagramProvider class implements support for diagrams within the labeling engine.
The QgsVectorLayerLabelProvider class implements a label provider for vector layers.
Represents a vector layer which manages a vector based data sets.
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
LabelPosition is a candidate feature label position.
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
#define Q_NOWARN_DEPRECATED_POP
#define Q_NOWARN_DEPRECATED_PUSH
#define SIP_PROPERTY(name, getter, setter)
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.
const QgsCoordinateReferenceSystem & crs