QGIS API Documentation  3.22.4-Białowieża (ce8e65e95e)
qgspallabeling.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgspallabeling.h
3  Smart labeling for vector layers
4  -------------------
5  begin : June 2009
6  copyright : (C) Martin Dobias
7  email : wonder dot sk at gmail dot com
8 
9  ***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef QGSPALLABELING_H
19 #define QGSPALLABELING_H
20 
21 #include "qgis_core.h"
22 #include "qgis_sip.h"
23 #include <QString>
24 #include <QFont>
25 #include <QFontDatabase>
26 #include <QColor>
27 #include <QHash>
28 #include <QList>
29 #include <QPainter>
30 #include <QRectF>
31 #include <QMap>
32 #include "qgsfeature.h"
33 #include "qgsgeometry.h"
34 #include "qgsfields.h"
36 #include "qgspointxy.h"
37 #include "qgsmapunitscale.h"
38 #include "qgsstringutils.h"
39 #include "qgstextformat.h"
40 #include "qgspropertycollection.h"
43 #include "qgslabellinesettings.h"
44 #include "qgslabeling.h"
45 #include "qgslabelposition.h"
46 #include "qgscoordinatetransform.h"
47 
48 class QgsTextDocument;
49 
50 namespace pal SIP_SKIP
51 {
52  class Pal;
53  class Layer;
54  class LabelPosition;
55 }
56 
58 class QgsRectangle;
59 class QgsMapToPixel;
60 class QgsFeature;
62 class QgsVectorLayer;
63 class QgsExpression;
64 class QFontMetricsF;
65 class QPainter;
66 class QPicture;
67 class QgsGeometry;
69 class QgsLabelSearchTree;
70 class QgsMapSettings;
71 class QgsLabelFeature;
72 class QgsLabelingEngine;
75 class QgsDxfExport;
78 class QgsCallout;
79 
85 class CORE_EXPORT QgsPalLayerSettings
86 {
87  public:
91 
93  QgsPalLayerSettings &operator=( const QgsPalLayerSettings &s );
94 
95  //TODO QGIS 4.0 - move to QgsLabelingEngine
96 
101  {
111  };
112 
113  //TODO QGIS 4.0 - move to QgsLabelingEngine
116  {
129  };
130 
131  //TODO QGIS 4.0 - move to QgsLabelingEngine
132 
138  {
141  };
142 
143  //TODO QGIS 4.0 - remove, replaced by QgsLabeling::LinePlacementFlags
144 
151  {
152  OnLine = 1,
153  AboveLine = 2,
156  BelowLine = 4,
159  MapOrientation = 8,
162  };
163 
165  {
175  };
176 
178  {
181  ShowAll
182  };
183 
184  //TODO QGIS 4.0 - Remove -- moved to QgsLabelEngineObstacleSettings
185 
188  {
191  SymbolBelow
192  };
193 
195  {
196  MultiLeft = 0,
199  MultiFollowPlacement,
202  };
203 
204  //TODO QGIS 4.0 - Remove -- moved to QgsLabelEngineObstacleSettings
205 
211  {
212  PolygonInterior,
214  PolygonBoundary,
216  PolygonWhole
220  };
221 
223  enum Property
224  {
225  // text style
226  Size = 0,
227  Bold = 1,
228  Italic = 2,
229  Underline = 3,
230  Color = 4,
231  Strikeout = 5,
232  Family = 6,
233  FontStyle = 21,
234  FontSizeUnit = 22,
235  FontTransp = 18,
236  FontOpacity = 92,
237  FontCase = 27,
238  FontLetterSpacing = 28,
239  FontWordSpacing = 29,
240  FontBlendMode = 30,
241 
242  // text formatting
243  MultiLineWrapChar = 31,
244  AutoWrapLength = 101,
245  MultiLineHeight = 32,
246  MultiLineAlignment = 33,
247  TextOrientation = 110,
248  DirSymbDraw = 34,
249  DirSymbLeft = 35,
250  DirSymbRight = 36,
251  DirSymbPlacement = 37,
252  DirSymbReverse = 38,
253  NumFormat = 39,
254  NumDecimals = 40,
255  NumPlusSign = 41,
256 
257  // text buffer
258  BufferDraw = 42,
259  BufferSize = 7,
260  BufferUnit = 43,
261  BufferColor = 8,
262  BufferTransp = 19,
263  BufferOpacity = 94,
264  BufferJoinStyle = 44,
265  BufferBlendMode = 45,
266 
267  // mask buffer
268  MaskEnabled = 104,
269  MaskBufferSize = 105,
270  MaskBufferUnit = 106,
271  MaskOpacity = 107,
272  MaskJoinStyle = 108,
273 
274  // background
275  ShapeDraw = 46,
276  ShapeKind = 47,
277  ShapeSVGFile = 48,
278  ShapeSizeType = 49,
279  ShapeSizeX = 50,
280  ShapeSizeY = 85,
281  ShapeSizeUnits = 51,
282  ShapeRotationType = 52,
283  ShapeRotation = 53,
284  ShapeOffset = 54,
285  ShapeOffsetUnits = 55,
286  ShapeRadii = 56,
287  ShapeRadiiUnits = 57,
288  ShapeTransparency = 63,
289  ShapeOpacity = 93,
290  ShapeBlendMode = 64,
291  ShapeFillColor = 58,
292  ShapeStrokeColor = 59,
293  ShapeStrokeWidth = 60,
294  ShapeStrokeWidthUnits = 61,
295  ShapeJoinStyle = 62,
296 
297  // drop shadow
298  ShadowDraw = 65,
299  ShadowUnder = 66,
300  ShadowOffsetAngle = 67,
301  ShadowOffsetDist = 68,
302  ShadowOffsetUnits = 69,
303  ShadowRadius = 70,
304  ShadowRadiusUnits = 71,
305  ShadowTransparency = 72,
306  ShadowOpacity = 95,
307  ShadowScale = 73,
308  ShadowColor = 74,
309  ShadowBlendMode = 75,
310 
311  // placement
312  CentroidWhole = 76,
313  OffsetQuad = 77,
314  OffsetXY = 78,
315  OffsetUnits = 80,
316  LabelDistance = 13,
317  DistanceUnits = 81,
318  OffsetRotation = 82,
319  CurvedCharAngleInOut = 83,
320  // (data defined only)
321  PositionX = 9,
322  PositionY = 10,
323  Hali = 11,
324  Vali = 12,
325  Rotation = 14,
326  LabelRotation = 96,
327  RepeatDistance = 84,
328  RepeatDistanceUnit = 86,
329  Priority = 87,
330  PredefinedPositionOrder = 91,
331  LinePlacementOptions = 99,
332  OverrunDistance = 102,
333  LabelAllParts = 103,
334  PolygonLabelOutside = 109,
335  LineAnchorPercent = 111,
336  LineAnchorClipping = 112,
337 
338  // rendering
339  ScaleVisibility = 23,
340  MinScale = 16,
341  MinimumScale = 97,
342  MaxScale = 17,
343  MaximumScale = 98,
344  FontLimitPixel = 24,
345  FontMinPixel = 25,
346  FontMaxPixel = 26,
347  IsObstacle = 88,
348  ObstacleFactor = 89,
349  ZIndex = 90,
350  CalloutDraw = 100,
351 
352  // (data defined only)
353  Show = 15,
354  AlwaysShow = 20
355  };
356 
357 
369  bool prepare( QgsRenderContext &context, QSet<QString> &attributeNames SIP_INOUT, const QgsFields &fields, const QgsMapSettings &mapSettings, const QgsCoordinateReferenceSystem &crs );
370 
375  QSet<QString> referencedFields( const QgsRenderContext &context ) const;
376 
385  void startRender( QgsRenderContext &context );
386 
394  void stopRender( QgsRenderContext &context );
395 
401  bool containsAdvancedEffects() const;
402 
407  static const QgsPropertiesDefinition &propertyDefinitions();
408 
417  bool drawLabels = true;
418 
419  //-- text style
420 
426  QString fieldName;
427 
432  bool isExpression = false;
433 
437  QgsExpression *getLabelExpression();
438 
442  Q_DECL_DEPRECATED QColor previewBkgrdColor = Qt::white;
443 
447  bool useSubstitutions = false;
448 
449  //-- text formatting
450 
455  QString wrapChar;
456 
464  int autoWrapLength = 0;
465 
476  bool useMaxLineLengthForAutoWrap = true;
477 
479  MultiLineAlign multilineAlign = MultiFollowPlacement;
480 
487  bool formatNumbers = false;
488 
494  int decimals = 3;
495 
501  bool plusSign = false;
502 
503  //-- placement
504 
505  Placement placement = AroundPoint;
506 
513  QgsLabeling::PolygonPlacementFlags polygonPlacementFlags() const { return mPolygonPlacementFlags; }
514 
521  void setPolygonPlacementFlags( QgsLabeling::PolygonPlacementFlags flags ) { mPolygonPlacementFlags = flags; }
522 
527  bool centroidWhole = false;
528 
534  bool centroidInside = false;
535 
542  QVector< PredefinedPointPosition > predefinedPositionOrder SIP_SKIP;
543 
547  bool fitInPolygonOnly = false;
548 
554  double dist = 0;
555 
562 
569 
571  OffsetType offsetType = FromPoint;
572 
578  double repeatDistance = 0;
579 
586 
593 
597  QuadrantPosition quadOffset = QuadrantOver;
598 
605  double xOffset = 0;
606 
613  double yOffset = 0;
614 
622 
630 
632  double angleOffset = 0;
633 
635  bool preserveRotation = true;
636 
642  QgsUnitTypes::AngleUnit rotationUnit() const;
643 
649  void setRotationUnit( QgsUnitTypes::AngleUnit angleUnit );
650 
655  double maxCurvedCharAngleIn = 25.0;
656 
661  double maxCurvedCharAngleOut = -25.0;
662 
667  int priority = 5;
668 
669  //-- rendering
670 
676  bool scaleVisibility = false;
677 
688  double maximumScale = 0;
689 
700  double minimumScale = 0;
701 
707  bool fontLimitPixelSize = false;
708 
714  int fontMinPixelSize = 0;
715 
721  int fontMaxPixelSize = 10000;
722 
724  bool displayAll = false;
725 
727  UpsideDownLabels upsidedownLabels = Upright;
728 
733  bool labelPerPart = false;
734 
735  // TODO QGIS 4.0 - remove this junk
736 
737 #ifdef SIP_RUN
738  SIP_PROPERTY( name = limitNumLabels, get = _limitNumLabels, set = _setLimitNumLabels )
739  SIP_PROPERTY( name = maxNumLabels, get = _maxNumLabels, set = _setMaxNumLabels )
740  SIP_PROPERTY( name = minFeatureSize, get = _minFeatureSize, set = _setMinFeatureSize )
741  SIP_PROPERTY( name = obstacle, get = _getIsObstacle, set = _setIsObstacle )
742  SIP_PROPERTY( name = obstacleFactor, get = _getObstacleFactor, set = _setObstacleFactor )
743  SIP_PROPERTY( name = obstacleType, get = _getObstacleType, set = _setObstacleType )
744  SIP_PROPERTY( name = placementFlags, get = _getLinePlacementFlags, set = _setLinePlacementFlags )
745  SIP_PROPERTY( name = mergeLines, get = _getMergeLines, set = _setMergeLines )
746  SIP_PROPERTY( name = addDirectionSymbol, get = _getAddDirectionSymbol, set = _setAddDirectionSymbol )
747  SIP_PROPERTY( name = leftDirectionSymbol, get = _getLeftDirectionSymbol, set = _setLeftDirectionSymbol )
748  SIP_PROPERTY( name = rightDirectionSymbol, get = _getRightDirectionSymbol, set = _setRightDirectionSymbol )
749  SIP_PROPERTY( name = reverseDirectionSymbol, get = _getReverseDirectionSymbol, set = _setReverseDirectionSymbol )
750  SIP_PROPERTY( name = placeDirectionSymbol, get = _getPlaceDirectionSymbol, set = _setPlaceDirectionSymbol )
751 
752  SIP_PROPERTY( name = overrunDistance, get = _getOverrunDistance, set = _setOverrunDistance )
753  SIP_PROPERTY( name = overrunDistanceUnit, get = _getOverrunDistanceUnit, set = _setOverrunDistanceUnit )
754  SIP_PROPERTY( name = overrunDistanceMapUnitScale, get = _getOverrunDistanceMapUnitScale, set = _setOverrunDistanceMapUnitScale )
755 #endif
756 
758  bool _limitNumLabels() const { return mThinningSettings.limitNumberOfLabelsEnabled(); }
759  void _setLimitNumLabels( bool limit ) { mThinningSettings.setLimitNumberLabelsEnabled( limit ); }
760  int _maxNumLabels() const { return mThinningSettings.maximumNumberLabels(); }
761  void _setMaxNumLabels( int max ) { mThinningSettings.setMaximumNumberLabels( max ); }
762  double _minFeatureSize() const { return mThinningSettings.minimumFeatureSize(); }
763  void _setMinFeatureSize( double size ) { mThinningSettings.setMinimumFeatureSize( size ); }
764  bool _getIsObstacle() const { return mObstacleSettings.isObstacle(); }
765  void _setIsObstacle( bool obstacle ) { mObstacleSettings.setIsObstacle( obstacle ); }
766  double _getObstacleFactor() const { return mObstacleSettings.factor(); }
767  void _setObstacleFactor( double factor ) { mObstacleSettings.setFactor( factor ); }
768  ObstacleType _getObstacleType() const { return static_cast< ObstacleType>( mObstacleSettings.type() ); }
769  void _setObstacleType( ObstacleType type ) { mObstacleSettings.setType( static_cast< QgsLabelObstacleSettings::ObstacleType>( type ) ); }
770  unsigned int _getLinePlacementFlags() const { return static_cast< unsigned int >( mLineSettings.placementFlags() ); }
771  void _setLinePlacementFlags( unsigned int flags ) { mLineSettings.setPlacementFlags( static_cast< QgsLabeling::LinePlacementFlags >( flags ) ); }
772  bool _getMergeLines() const { return mLineSettings.mergeLines(); }
773  void _setMergeLines( bool merge ) { mLineSettings.setMergeLines( merge ); }
774  bool _getAddDirectionSymbol() const { return mLineSettings.addDirectionSymbol(); }
775  void _setAddDirectionSymbol( bool add ) { mLineSettings.setAddDirectionSymbol( add ); }
776  QString _getLeftDirectionSymbol() const { return mLineSettings.leftDirectionSymbol(); }
777  void _setLeftDirectionSymbol( const QString &symbol ) { mLineSettings.setLeftDirectionSymbol( symbol ); }
778  QString _getRightDirectionSymbol() const { return mLineSettings.rightDirectionSymbol(); }
779  void _setRightDirectionSymbol( const QString &symbol ) { mLineSettings.setRightDirectionSymbol( symbol ); }
780  bool _getReverseDirectionSymbol() const { return mLineSettings.reverseDirectionSymbol(); }
781  void _setReverseDirectionSymbol( bool reverse ) { mLineSettings.setReverseDirectionSymbol( reverse ); }
783  DirectionSymbols _getPlaceDirectionSymbol() const { return static_cast< DirectionSymbols>( mLineSettings.directionSymbolPlacement() ); }
784  void _setPlaceDirectionSymbol( DirectionSymbols placement ) { mLineSettings.setDirectionSymbolPlacement( static_cast< QgsLabelLineSettings::DirectionSymbolPlacement>( placement ) ); }
786  double _getOverrunDistance() const { return mLineSettings.overrunDistance(); }
787  void _setOverrunDistance( double distance ) { mLineSettings.setOverrunDistance( distance ); }
788  QgsUnitTypes::RenderUnit _getOverrunDistanceUnit() const { return mLineSettings.overrunDistanceUnit(); }
789  void _setOverrunDistanceUnit( QgsUnitTypes::RenderUnit unit ) { mLineSettings.setOverrunDistanceUnit( unit ); }
790  QgsMapUnitScale _getOverrunDistanceMapUnitScale() const { return mLineSettings.overrunDistanceMapUnitScale(); }
791  void _setOverrunDistanceMapUnitScale( const QgsMapUnitScale &scale ) { mLineSettings.setOverrunDistanceMapUnitScale( scale ); }
793 
795  double zIndex = 0;
796 
799 
801  QgsWkbTypes::GeometryType geometryGeneratorType = QgsWkbTypes::GeometryType::PointGeometry;
802 
804  bool geometryGeneratorEnabled = false;
805 
811 
816  void setLegendString( const QString &legendString ) { mLegendString = legendString; }
817 
822  QString legendString() const { return mLegendString; }
823 
830 #ifndef SIP_RUN
831  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,
832  QgsTextDocument *document = nullptr );
833 #else
834  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 );
835 #endif
836 
846  void registerFeature( const QgsFeature &f, QgsRenderContext &context );
847 
848 #ifndef SIP_RUN
849 
866  std::unique_ptr< QgsLabelFeature > registerFeatureWithDetails( const QgsFeature &feature, QgsRenderContext &context,
867  QgsGeometry obstacleGeometry = QgsGeometry(), const QgsSymbol *symbol = nullptr );
868 #endif
869 
874  void readXml( const QDomElement &elem, const QgsReadWriteContext &context );
875 
880  QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const;
881 
887  QgsPropertyCollection &dataDefinedProperties() { return mDataDefinedProperties; }
888 
896  const QgsPropertyCollection &dataDefinedProperties() const SIP_SKIP { return mDataDefinedProperties; }
897 
905  void setDataDefinedProperties( const QgsPropertyCollection &collection ) { mDataDefinedProperties = collection; }
906 
912  const QgsTextFormat &format() const { return mFormat; }
913 
920  void setFormat( const QgsTextFormat &format ) { mFormat = format; }
921 
930  QgsCallout *callout() const { return mCallout.get(); }
931 
940  void setCallout( QgsCallout *callout SIP_TRANSFER );
941 
950  const QgsLabelLineSettings &lineSettings() const { return mLineSettings; } SIP_SKIP
951 
959  QgsLabelLineSettings &lineSettings() { return mLineSettings; }
960 
968  void setLineSettings( const QgsLabelLineSettings &settings ) { mLineSettings = settings; }
969 
976  const QgsLabelObstacleSettings &obstacleSettings() const { return mObstacleSettings; } SIP_SKIP
977 
983  QgsLabelObstacleSettings &obstacleSettings() { return mObstacleSettings; }
984 
990  void setObstacleSettings( const QgsLabelObstacleSettings &settings ) { mObstacleSettings = settings; }
991 
998  const QgsLabelThinningSettings &thinningSettings() const { return mThinningSettings; } SIP_SKIP
999 
1005  QgsLabelThinningSettings &thinningSettings() { return mThinningSettings; }
1006 
1012  void setThinningSettings( const QgsLabelThinningSettings &settings ) { mThinningSettings = settings; }
1013 
1022  static QPixmap labelSettingsPreviewPixmap( const QgsPalLayerSettings &settings, QSize size, const QString &previewText = QString(), int padding = 0 );
1023 
1030  Qgis::UnplacedLabelVisibility unplacedVisibility() const;
1031 
1038  void setUnplacedVisibility( Qgis::UnplacedLabelVisibility visibility );
1039 
1040  // temporary stuff: set when layer gets prepared or labeled
1041  const QgsFeature *mCurFeat = nullptr;
1043  int fieldIndex = 0;
1044  const QgsMapToPixel *xform = nullptr;
1046 
1050  int mFeaturesToLabel = 0; // total features that will probably be labeled, may be less (figured before PAL)
1051  int mFeatsSendingToPal = 0; // total features tested for sending into PAL (relative to maxNumLabels)
1052  int mFeatsRegPal = 0; // number of features registered in PAL, when using limitNumLabels
1053 
1054  private:
1055 
1056  friend class QgsVectorLayer; // to allow calling readFromLayerCustomProperties()
1057 
1062  void readFromLayerCustomProperties( QgsVectorLayer *layer );
1063 
1067  void readOldDataDefinedPropertyMap( QgsVectorLayer *layer, QDomElement *parentElem );
1068 
1072  void readOldDataDefinedProperty( QgsVectorLayer *layer, QgsPalLayerSettings::Property p );
1073 
1074  enum DataDefinedValueType
1075  {
1076  DDBool,
1077  DDInt,
1078  DDIntPos,
1079  DDDouble,
1080  DDDoublePos,
1081  DDRotation180,
1082  DDOpacity,
1083  DDString,
1084  DDUnits,
1085  DDColor,
1086  DDJoinStyle,
1087  DDBlendMode,
1088  DDPointF,
1089  DDSizeF,
1090  };
1091 
1092  // convenience data defined evaluation function
1093  bool dataDefinedValEval( DataDefinedValueType valType,
1095  QVariant &exprVal, QgsExpressionContext &context, const QVariant &originalValue = QVariant() );
1096 
1097  void parseTextStyle( QFont &labelFont,
1098  QgsUnitTypes::RenderUnit fontunits,
1099  QgsRenderContext &context );
1100 
1101  void parseTextBuffer( QgsRenderContext &context );
1102 
1103  void parseTextMask( QgsRenderContext &context );
1104 
1105  void parseTextFormatting( QgsRenderContext &context );
1106 
1107  void parseShapeBackground( QgsRenderContext &context );
1108 
1109  void parseDropShadow( QgsRenderContext &context );
1110 
1115  bool checkMinimumSizeMM( const QgsRenderContext &ct, const QgsGeometry &geom, double minSize ) const;
1116 
1120  std::unique_ptr< QgsLabelFeature > registerObstacleFeature( const QgsFeature &f, QgsRenderContext &context, const QgsGeometry &obstacleGeometry = QgsGeometry() );
1121 
1122  QMap<Property, QVariant> dataDefinedValues;
1123 
1125  QgsPropertyCollection mDataDefinedProperties;
1126 
1127  QgsExpression *expression = nullptr;
1128 
1129  std::unique_ptr< QFontDatabase > mFontDB;
1130 
1131  QgsTextFormat mFormat;
1132 
1133  std::unique_ptr< QgsCallout > mCallout;
1134 
1135  QgsLabelLineSettings mLineSettings;
1136  QgsLabelObstacleSettings mObstacleSettings;
1137  QgsLabelThinningSettings mThinningSettings;
1138 
1139  QgsLabeling::PolygonPlacementFlags mPolygonPlacementFlags = QgsLabeling::PolygonPlacementFlag::AllowPlacementInsideOfPolygon;
1140 
1141  QgsExpression mGeometryGeneratorExpression;
1142 
1143  bool mRenderStarted = false;
1144 
1145  QString mLegendString = QObject::tr( "Aa" );
1146 
1148 
1151 
1152  static void initPropertyDefinitions();
1153 };
1154 
1159 class CORE_EXPORT QgsLabelCandidate
1160 {
1161  public:
1162  QgsLabelCandidate( const QRectF &r, double c ): rect( r ), cost( c ) {}
1163 
1164  QRectF rect;
1165  double cost;
1166 };
1167 
1173 class CORE_EXPORT QgsPalLabeling
1174 {
1175  public:
1176 
1181  static bool staticWillUseLayer( const QgsMapLayer *layer );
1182 
1184  static void drawLabelCandidateRect( pal::LabelPosition *lp, QPainter *painter, const QgsMapToPixel *xform, QList<QgsLabelCandidate> *candidates = nullptr ) SIP_SKIP;
1185 
1196  static QgsGeometry prepareGeometry( const QgsGeometry &geometry, QgsRenderContext &context, const QgsCoordinateTransform &ct, const QgsGeometry &clipGeometry = QgsGeometry(), bool mergeLines = false ) SIP_FACTORY;
1197 
1208  static bool geometryRequiresPreparation( const QgsGeometry &geometry, QgsRenderContext &context, const QgsCoordinateTransform &ct, const QgsGeometry &clipGeometry = QgsGeometry(), bool mergeLines = false );
1209 
1222  static QStringList splitToLines( const QString &text, const QString &wrapCharacter, int autoWrapLength = 0, bool useMaxLineLengthWhenAutoWrapping = true );
1223 
1232  static QStringList splitToGraphemes( const QString &text );
1233 
1234  private:
1236  static void dataDefinedTextStyle( QgsPalLayerSettings &tmpLyr,
1237  const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues );
1238 
1240  static void dataDefinedTextFormatting( QgsPalLayerSettings &tmpLyr,
1241  const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues );
1242 
1244  static void dataDefinedTextBuffer( QgsPalLayerSettings &tmpLyr,
1245  const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues );
1246 
1248  static void dataDefinedTextMask( QgsPalLayerSettings &tmpLyr,
1249  const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues );
1250 
1252  static void dataDefinedShapeBackground( QgsPalLayerSettings &tmpLyr,
1253  const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues );
1254 
1256  static void dataDefinedDropShadow( QgsPalLayerSettings &tmpLyr,
1257  const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues );
1258 
1259  friend class QgsVectorLayerLabelProvider; // to allow calling the static methods above
1260  friend class QgsDxfExport; // to allow calling the static methods above
1261 
1270  static bool checkMinimumSizeMM( const QgsRenderContext &context, const QgsGeometry &geom, double minSize );
1271 
1272  friend class QgsPalLayerSettings;
1273 };
1274 
1275 
1276 #endif // QGSPALLABELING_H
UnplacedLabelVisibility
Unplaced label visibility.
Definition: qgis.h:430
@ FollowEngineSetting
Respect the label engine setting.
Abstract base class for callout renderers.
Definition: qgscallout.h:53
This class represents a coordinate reference system (CRS).
Class for doing transforms between two map coordinate systems.
Stores the settings for rendering of all diagrams for a layer.
Exports QGIS layers to the DXF format.
Definition: qgsdxfexport.h:65
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 unique ID, geometry and a list of field...
Definition: qgsfeature.h:56
Container of fields for a vector layer.
Definition: qgsfields.h:45
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:125
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.
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.
Base class for all map layer types.
Definition: qgsmaplayer.h:73
The QgsMapSettings class contains configuration for rendering of the map.
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:39
Struct for storing maximum and minimum scales for measurements in map units.
PAL labeling utilities.
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
QString legendString() const
legendString
@ 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....
@ MultiJustify
Justified.
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 setLegendString(const QString &legendString)
setLegendString
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.
Definition: qgspointxy.h:59
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.
Definition: qgsrectangle.h:42
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.
Definition: qgssymbol.h:38
Represents a document consisting of one or more QgsTextBlock objects.
Container for all settings relating to text rendering.
Definition: qgstextformat.h:41
Class that adds extra information to QgsLabelFeature for text labels.
AngleUnit
Units of angles.
Definition: qgsunittypes.h:132
@ AngleDegrees
Degrees.
Definition: qgsunittypes.h:133
RenderUnit
Rendering size units.
Definition: qgsunittypes.h:168
@ RenderMillimeters
Millimeters.
Definition: qgsunittypes.h:169
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.
Definition: qgswkbtypes.h:141
LabelPosition is a candidate feature label position.
Definition: labelposition.h:56
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
Definition: qgis.h:1742
#define Q_NOWARN_DEPRECATED_PUSH
Definition: qgis.h:1741
#define SIP_PROPERTY(name, getter, setter)
Definition: qgis_sip.h:264
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_OUT
Definition: qgis_sip.h:58
#define SIP_FACTORY
Definition: qgis_sip.h:76
#define SIP_INOUT
Definition: qgis_sip.h:71
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.
const QgsCoordinateReferenceSystem & crs