QGIS API Documentation  3.21.0-Master (56b4176581)
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 
47 class QgsTextDocument;
48 
49 namespace pal SIP_SKIP
50 {
51  class Pal;
52  class Layer;
53  class LabelPosition;
54 }
55 
57 class QgsRectangle;
58 class QgsMapToPixel;
59 class QgsFeature;
61 class QgsVectorLayer;
62 class QgsExpression;
63 class QFontMetricsF;
64 class QPainter;
65 class QPicture;
66 class QgsGeometry;
68 class QgsLabelSearchTree;
69 class QgsMapSettings;
70 class QgsLabelFeature;
71 class QgsLabelingEngine;
74 class QgsDxfExport;
77 class QgsCallout;
78 
84 class CORE_EXPORT QgsPalLayerSettings
85 {
86  public:
90 
92  QgsPalLayerSettings &operator=( const QgsPalLayerSettings &s );
93 
94  //TODO QGIS 4.0 - move to QgsLabelingEngine
95 
99  enum Placement
100  {
110  };
111 
112  //TODO QGIS 4.0 - move to QgsLabelingEngine
115  {
128  };
129 
130  //TODO QGIS 4.0 - move to QgsLabelingEngine
131 
137  {
140  };
141 
142  //TODO QGIS 4.0 - remove, replaced by QgsLabeling::LinePlacementFlags
143 
150  {
151  OnLine = 1,
152  AboveLine = 2,
155  BelowLine = 4,
158  MapOrientation = 8,
161  };
162 
164  {
174  };
175 
177  {
180  ShowAll
181  };
182 
183  //TODO QGIS 4.0 - Remove -- moved to QgsLabelEngineObstacleSettings
184 
187  {
190  SymbolBelow
191  };
192 
194  {
195  MultiLeft = 0,
198  MultiFollowPlacement,
201  };
202 
203  //TODO QGIS 4.0 - Remove -- moved to QgsLabelEngineObstacleSettings
204 
210  {
211  PolygonInterior,
213  PolygonBoundary,
215  PolygonWhole
219  };
220 
222  enum Property
223  {
224  // text style
225  Size = 0,
226  Bold = 1,
227  Italic = 2,
228  Underline = 3,
229  Color = 4,
230  Strikeout = 5,
231  Family = 6,
232  FontStyle = 21,
233  FontSizeUnit = 22,
234  FontTransp = 18,
235  FontOpacity = 92,
236  FontCase = 27,
237  FontLetterSpacing = 28,
238  FontWordSpacing = 29,
239  FontBlendMode = 30,
240 
241  // text formatting
242  MultiLineWrapChar = 31,
243  AutoWrapLength = 101,
244  MultiLineHeight = 32,
245  MultiLineAlignment = 33,
246  TextOrientation = 110,
247  DirSymbDraw = 34,
248  DirSymbLeft = 35,
249  DirSymbRight = 36,
250  DirSymbPlacement = 37,
251  DirSymbReverse = 38,
252  NumFormat = 39,
253  NumDecimals = 40,
254  NumPlusSign = 41,
255 
256  // text buffer
257  BufferDraw = 42,
258  BufferSize = 7,
259  BufferUnit = 43,
260  BufferColor = 8,
261  BufferTransp = 19,
262  BufferOpacity = 94,
263  BufferJoinStyle = 44,
264  BufferBlendMode = 45,
265 
266  // mask buffer
267  MaskEnabled = 104,
268  MaskBufferSize = 105,
269  MaskBufferUnit = 106,
270  MaskOpacity = 107,
271  MaskJoinStyle = 108,
272 
273  // background
274  ShapeDraw = 46,
275  ShapeKind = 47,
276  ShapeSVGFile = 48,
277  ShapeSizeType = 49,
278  ShapeSizeX = 50,
279  ShapeSizeY = 85,
280  ShapeSizeUnits = 51,
281  ShapeRotationType = 52,
282  ShapeRotation = 53,
283  ShapeOffset = 54,
284  ShapeOffsetUnits = 55,
285  ShapeRadii = 56,
286  ShapeRadiiUnits = 57,
287  ShapeTransparency = 63,
288  ShapeOpacity = 93,
289  ShapeBlendMode = 64,
290  ShapeFillColor = 58,
291  ShapeStrokeColor = 59,
292  ShapeStrokeWidth = 60,
293  ShapeStrokeWidthUnits = 61,
294  ShapeJoinStyle = 62,
295 
296  // drop shadow
297  ShadowDraw = 65,
298  ShadowUnder = 66,
299  ShadowOffsetAngle = 67,
300  ShadowOffsetDist = 68,
301  ShadowOffsetUnits = 69,
302  ShadowRadius = 70,
303  ShadowRadiusUnits = 71,
304  ShadowTransparency = 72,
305  ShadowOpacity = 95,
306  ShadowScale = 73,
307  ShadowColor = 74,
308  ShadowBlendMode = 75,
309 
310  // placement
311  CentroidWhole = 76,
312  OffsetQuad = 77,
313  OffsetXY = 78,
314  OffsetUnits = 80,
315  LabelDistance = 13,
316  DistanceUnits = 81,
317  OffsetRotation = 82,
318  CurvedCharAngleInOut = 83,
319  // (data defined only)
320  PositionX = 9,
321  PositionY = 10,
322  Hali = 11,
323  Vali = 12,
324  Rotation = 14,
325  LabelRotation = 96,
326  RepeatDistance = 84,
327  RepeatDistanceUnit = 86,
328  Priority = 87,
329  PredefinedPositionOrder = 91,
330  LinePlacementOptions = 99,
331  OverrunDistance = 102,
332  LabelAllParts = 103,
333  PolygonLabelOutside = 109,
334  LineAnchorPercent = 111,
335  LineAnchorClipping = 112,
336 
337  // rendering
338  ScaleVisibility = 23,
339  MinScale = 16,
340  MinimumScale = 97,
341  MaxScale = 17,
342  MaximumScale = 98,
343  FontLimitPixel = 24,
344  FontMinPixel = 25,
345  FontMaxPixel = 26,
346  IsObstacle = 88,
347  ObstacleFactor = 89,
348  ZIndex = 90,
349  CalloutDraw = 100,
350 
351  // (data defined only)
352  Show = 15,
353  AlwaysShow = 20
354  };
355 
356 
368  bool prepare( QgsRenderContext &context, QSet<QString> &attributeNames SIP_INOUT, const QgsFields &fields, const QgsMapSettings &mapSettings, const QgsCoordinateReferenceSystem &crs );
369 
374  QSet<QString> referencedFields( const QgsRenderContext &context ) const;
375 
384  void startRender( QgsRenderContext &context );
385 
393  void stopRender( QgsRenderContext &context );
394 
400  bool containsAdvancedEffects() const;
401 
406  static const QgsPropertiesDefinition &propertyDefinitions();
407 
416  bool drawLabels = true;
417 
418  //-- text style
419 
425  QString fieldName;
426 
431  bool isExpression = false;
432 
436  QgsExpression *getLabelExpression();
437 
441  Q_DECL_DEPRECATED QColor previewBkgrdColor = Qt::white;
442 
446  bool useSubstitutions = false;
447 
448  //-- text formatting
449 
454  QString wrapChar;
455 
463  int autoWrapLength = 0;
464 
475  bool useMaxLineLengthForAutoWrap = true;
476 
478  MultiLineAlign multilineAlign = MultiFollowPlacement;
479 
486  bool formatNumbers = false;
487 
493  int decimals = 3;
494 
500  bool plusSign = false;
501 
502  //-- placement
503 
504  Placement placement = AroundPoint;
505 
512  QgsLabeling::PolygonPlacementFlags polygonPlacementFlags() const { return mPolygonPlacementFlags; }
513 
520  void setPolygonPlacementFlags( QgsLabeling::PolygonPlacementFlags flags ) { mPolygonPlacementFlags = flags; }
521 
526  bool centroidWhole = false;
527 
533  bool centroidInside = false;
534 
541  QVector< PredefinedPointPosition > predefinedPositionOrder SIP_SKIP;
542 
546  bool fitInPolygonOnly = false;
547 
553  double dist = 0;
554 
561 
568 
570  OffsetType offsetType = FromPoint;
571 
577  double repeatDistance = 0;
578 
585 
592 
596  QuadrantPosition quadOffset = QuadrantOver;
597 
604  double xOffset = 0;
605 
612  double yOffset = 0;
613 
621 
629 
631  double angleOffset = 0;
632 
634  bool preserveRotation = true;
635 
641  QgsUnitTypes::AngleUnit rotationUnit() const;
642 
648  void setRotationUnit( QgsUnitTypes::AngleUnit angleUnit );
649 
654  double maxCurvedCharAngleIn = 25.0;
655 
660  double maxCurvedCharAngleOut = -25.0;
661 
666  int priority = 5;
667 
668  //-- rendering
669 
675  bool scaleVisibility = false;
676 
687  double maximumScale = 0;
688 
699  double minimumScale = 0;
700 
706  bool fontLimitPixelSize = false;
707 
713  int fontMinPixelSize = 0;
714 
720  int fontMaxPixelSize = 10000;
721 
723  bool displayAll = false;
724 
726  UpsideDownLabels upsidedownLabels = Upright;
727 
732  bool labelPerPart = false;
733 
734  // TODO QGIS 4.0 - remove this junk
735 
736 #ifdef SIP_RUN
737  SIP_PROPERTY( name = limitNumLabels, get = _limitNumLabels, set = _setLimitNumLabels )
738  SIP_PROPERTY( name = maxNumLabels, get = _maxNumLabels, set = _setMaxNumLabels )
739  SIP_PROPERTY( name = minFeatureSize, get = _minFeatureSize, set = _setMinFeatureSize )
740  SIP_PROPERTY( name = obstacle, get = _getIsObstacle, set = _setIsObstacle )
741  SIP_PROPERTY( name = obstacleFactor, get = _getObstacleFactor, set = _setObstacleFactor )
742  SIP_PROPERTY( name = obstacleType, get = _getObstacleType, set = _setObstacleType )
743  SIP_PROPERTY( name = placementFlags, get = _getLinePlacementFlags, set = _setLinePlacementFlags )
744  SIP_PROPERTY( name = mergeLines, get = _getMergeLines, set = _setMergeLines )
745  SIP_PROPERTY( name = addDirectionSymbol, get = _getAddDirectionSymbol, set = _setAddDirectionSymbol )
746  SIP_PROPERTY( name = leftDirectionSymbol, get = _getLeftDirectionSymbol, set = _setLeftDirectionSymbol )
747  SIP_PROPERTY( name = rightDirectionSymbol, get = _getRightDirectionSymbol, set = _setRightDirectionSymbol )
748  SIP_PROPERTY( name = reverseDirectionSymbol, get = _getReverseDirectionSymbol, set = _setReverseDirectionSymbol )
749  SIP_PROPERTY( name = placeDirectionSymbol, get = _getPlaceDirectionSymbol, set = _setPlaceDirectionSymbol )
750 
751  SIP_PROPERTY( name = overrunDistance, get = _getOverrunDistance, set = _setOverrunDistance )
752  SIP_PROPERTY( name = overrunDistanceUnit, get = _getOverrunDistanceUnit, set = _setOverrunDistanceUnit )
753  SIP_PROPERTY( name = overrunDistanceMapUnitScale, get = _getOverrunDistanceMapUnitScale, set = _setOverrunDistanceMapUnitScale )
754 #endif
755 
757  bool _limitNumLabels() const { return mThinningSettings.limitNumberOfLabelsEnabled(); }
758  void _setLimitNumLabels( bool limit ) { mThinningSettings.setLimitNumberLabelsEnabled( limit ); }
759  int _maxNumLabels() const { return mThinningSettings.maximumNumberLabels(); }
760  void _setMaxNumLabels( int max ) { mThinningSettings.setMaximumNumberLabels( max ); }
761  double _minFeatureSize() const { return mThinningSettings.minimumFeatureSize(); }
762  void _setMinFeatureSize( double size ) { mThinningSettings.setMinimumFeatureSize( size ); }
763  bool _getIsObstacle() const { return mObstacleSettings.isObstacle(); }
764  void _setIsObstacle( bool obstacle ) { mObstacleSettings.setIsObstacle( obstacle ); }
765  double _getObstacleFactor() const { return mObstacleSettings.factor(); }
766  void _setObstacleFactor( double factor ) { mObstacleSettings.setFactor( factor ); }
767  ObstacleType _getObstacleType() const { return static_cast< ObstacleType>( mObstacleSettings.type() ); }
768  void _setObstacleType( ObstacleType type ) { mObstacleSettings.setType( static_cast< QgsLabelObstacleSettings::ObstacleType>( type ) ); }
769  unsigned int _getLinePlacementFlags() const { return static_cast< unsigned int >( mLineSettings.placementFlags() ); }
770  void _setLinePlacementFlags( unsigned int flags ) { mLineSettings.setPlacementFlags( static_cast< QgsLabeling::LinePlacementFlags >( flags ) ); }
771  bool _getMergeLines() const { return mLineSettings.mergeLines(); }
772  void _setMergeLines( bool merge ) { mLineSettings.setMergeLines( merge ); }
773  bool _getAddDirectionSymbol() const { return mLineSettings.addDirectionSymbol(); }
774  void _setAddDirectionSymbol( bool add ) { mLineSettings.setAddDirectionSymbol( add ); }
775  QString _getLeftDirectionSymbol() const { return mLineSettings.leftDirectionSymbol(); }
776  void _setLeftDirectionSymbol( const QString &symbol ) { mLineSettings.setLeftDirectionSymbol( symbol ); }
777  QString _getRightDirectionSymbol() const { return mLineSettings.rightDirectionSymbol(); }
778  void _setRightDirectionSymbol( const QString &symbol ) { mLineSettings.setRightDirectionSymbol( symbol ); }
779  bool _getReverseDirectionSymbol() const { return mLineSettings.reverseDirectionSymbol(); }
780  void _setReverseDirectionSymbol( bool reverse ) { mLineSettings.setReverseDirectionSymbol( reverse ); }
782  DirectionSymbols _getPlaceDirectionSymbol() const { return static_cast< DirectionSymbols>( mLineSettings.directionSymbolPlacement() ); }
783  void _setPlaceDirectionSymbol( DirectionSymbols placement ) { mLineSettings.setDirectionSymbolPlacement( static_cast< QgsLabelLineSettings::DirectionSymbolPlacement>( placement ) ); }
785  double _getOverrunDistance() const { return mLineSettings.overrunDistance(); }
786  void _setOverrunDistance( double distance ) { mLineSettings.setOverrunDistance( distance ); }
787  QgsUnitTypes::RenderUnit _getOverrunDistanceUnit() const { return mLineSettings.overrunDistanceUnit(); }
788  void _setOverrunDistanceUnit( QgsUnitTypes::RenderUnit unit ) { mLineSettings.setOverrunDistanceUnit( unit ); }
789  QgsMapUnitScale _getOverrunDistanceMapUnitScale() const { return mLineSettings.overrunDistanceMapUnitScale(); }
790  void _setOverrunDistanceMapUnitScale( const QgsMapUnitScale &scale ) { mLineSettings.setOverrunDistanceMapUnitScale( scale ); }
792 
794  double zIndex = 0;
795 
798 
800  QgsWkbTypes::GeometryType geometryGeneratorType = QgsWkbTypes::GeometryType::PointGeometry;
801 
803  bool geometryGeneratorEnabled = false;
804 
810 
815  void setLegendString( const QString &legendString ) { mLegendString = legendString; }
816 
821  QString legendString() const { return mLegendString; }
822 
829 #ifndef SIP_RUN
830  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,
831  QgsTextDocument *document = nullptr );
832 #else
833  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 );
834 #endif
835 
845  void registerFeature( const QgsFeature &f, QgsRenderContext &context );
846 
847 #ifndef SIP_RUN
848 
865  std::unique_ptr< QgsLabelFeature > registerFeatureWithDetails( const QgsFeature &feature, QgsRenderContext &context,
866  QgsGeometry obstacleGeometry = QgsGeometry(), const QgsSymbol *symbol = nullptr );
867 #endif
868 
873  void readXml( const QDomElement &elem, const QgsReadWriteContext &context );
874 
879  QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const;
880 
886  QgsPropertyCollection &dataDefinedProperties() { return mDataDefinedProperties; }
887 
895  const QgsPropertyCollection &dataDefinedProperties() const SIP_SKIP { return mDataDefinedProperties; }
896 
904  void setDataDefinedProperties( const QgsPropertyCollection &collection ) { mDataDefinedProperties = collection; }
905 
911  const QgsTextFormat &format() const { return mFormat; }
912 
919  void setFormat( const QgsTextFormat &format ) { mFormat = format; }
920 
929  QgsCallout *callout() const { return mCallout.get(); }
930 
939  void setCallout( QgsCallout *callout SIP_TRANSFER );
940 
949  const QgsLabelLineSettings &lineSettings() const { return mLineSettings; } SIP_SKIP
950 
958  QgsLabelLineSettings &lineSettings() { return mLineSettings; }
959 
967  void setLineSettings( const QgsLabelLineSettings &settings ) { mLineSettings = settings; }
968 
975  const QgsLabelObstacleSettings &obstacleSettings() const { return mObstacleSettings; } SIP_SKIP
976 
982  QgsLabelObstacleSettings &obstacleSettings() { return mObstacleSettings; }
983 
989  void setObstacleSettings( const QgsLabelObstacleSettings &settings ) { mObstacleSettings = settings; }
990 
997  const QgsLabelThinningSettings &thinningSettings() const { return mThinningSettings; } SIP_SKIP
998 
1004  QgsLabelThinningSettings &thinningSettings() { return mThinningSettings; }
1005 
1011  void setThinningSettings( const QgsLabelThinningSettings &settings ) { mThinningSettings = settings; }
1012 
1021  static QPixmap labelSettingsPreviewPixmap( const QgsPalLayerSettings &settings, QSize size, const QString &previewText = QString(), int padding = 0 );
1022 
1029  Qgis::UnplacedLabelVisibility unplacedVisibility() const;
1030 
1037  void setUnplacedVisibility( Qgis::UnplacedLabelVisibility visibility );
1038 
1039  // temporary stuff: set when layer gets prepared or labeled
1040  const QgsFeature *mCurFeat = nullptr;
1042  int fieldIndex = 0;
1043  const QgsMapToPixel *xform = nullptr;
1045 
1049  int mFeaturesToLabel = 0; // total features that will probably be labeled, may be less (figured before PAL)
1050  int mFeatsSendingToPal = 0; // total features tested for sending into PAL (relative to maxNumLabels)
1051  int mFeatsRegPal = 0; // number of features registered in PAL, when using limitNumLabels
1052 
1053  private:
1054 
1055  friend class QgsVectorLayer; // to allow calling readFromLayerCustomProperties()
1056 
1061  void readFromLayerCustomProperties( QgsVectorLayer *layer );
1062 
1066  void readOldDataDefinedPropertyMap( QgsVectorLayer *layer, QDomElement *parentElem );
1067 
1071  void readOldDataDefinedProperty( QgsVectorLayer *layer, QgsPalLayerSettings::Property p );
1072 
1073  enum DataDefinedValueType
1074  {
1075  DDBool,
1076  DDInt,
1077  DDIntPos,
1078  DDDouble,
1079  DDDoublePos,
1080  DDRotation180,
1081  DDOpacity,
1082  DDString,
1083  DDUnits,
1084  DDColor,
1085  DDJoinStyle,
1086  DDBlendMode,
1087  DDPointF,
1088  DDSizeF,
1089  };
1090 
1091  // convenience data defined evaluation function
1092  bool dataDefinedValEval( DataDefinedValueType valType,
1094  QVariant &exprVal, QgsExpressionContext &context, const QVariant &originalValue = QVariant() );
1095 
1096  void parseTextStyle( QFont &labelFont,
1097  QgsUnitTypes::RenderUnit fontunits,
1098  QgsRenderContext &context );
1099 
1100  void parseTextBuffer( QgsRenderContext &context );
1101 
1102  void parseTextMask( QgsRenderContext &context );
1103 
1104  void parseTextFormatting( QgsRenderContext &context );
1105 
1106  void parseShapeBackground( QgsRenderContext &context );
1107 
1108  void parseDropShadow( QgsRenderContext &context );
1109 
1114  bool checkMinimumSizeMM( const QgsRenderContext &ct, const QgsGeometry &geom, double minSize ) const;
1115 
1119  std::unique_ptr< QgsLabelFeature > registerObstacleFeature( const QgsFeature &f, QgsRenderContext &context, const QgsGeometry &obstacleGeometry = QgsGeometry() );
1120 
1121  QMap<Property, QVariant> dataDefinedValues;
1122 
1124  QgsPropertyCollection mDataDefinedProperties;
1125 
1126  QgsExpression *expression = nullptr;
1127 
1128  std::unique_ptr< QFontDatabase > mFontDB;
1129 
1130  QgsTextFormat mFormat;
1131 
1132  std::unique_ptr< QgsCallout > mCallout;
1133 
1134  QgsLabelLineSettings mLineSettings;
1135  QgsLabelObstacleSettings mObstacleSettings;
1136  QgsLabelThinningSettings mThinningSettings;
1137 
1138  QgsLabeling::PolygonPlacementFlags mPolygonPlacementFlags = QgsLabeling::PolygonPlacementFlag::AllowPlacementInsideOfPolygon;
1139 
1140  QgsExpression mGeometryGeneratorExpression;
1141 
1142  bool mRenderStarted = false;
1143 
1144  QString mLegendString = QObject::tr( "Aa" );
1145 
1147 
1150 
1151  static void initPropertyDefinitions();
1152 };
1153 
1158 class CORE_EXPORT QgsLabelCandidate
1159 {
1160  public:
1161  QgsLabelCandidate( const QRectF &r, double c ): rect( r ), cost( c ) {}
1162 
1163  QRectF rect;
1164  double cost;
1165 };
1166 
1172 class CORE_EXPORT QgsPalLabeling
1173 {
1174  public:
1175 
1180  static bool staticWillUseLayer( const QgsMapLayer *layer );
1181 
1183  static void drawLabelCandidateRect( pal::LabelPosition *lp, QPainter *painter, const QgsMapToPixel *xform, QList<QgsLabelCandidate> *candidates = nullptr ) SIP_SKIP;
1184 
1195  static QgsGeometry prepareGeometry( const QgsGeometry &geometry, QgsRenderContext &context, const QgsCoordinateTransform &ct, const QgsGeometry &clipGeometry = QgsGeometry(), bool mergeLines = false ) SIP_FACTORY;
1196 
1207  static bool geometryRequiresPreparation( const QgsGeometry &geometry, QgsRenderContext &context, const QgsCoordinateTransform &ct, const QgsGeometry &clipGeometry = QgsGeometry(), bool mergeLines = false );
1208 
1221  static QStringList splitToLines( const QString &text, const QString &wrapCharacter, int autoWrapLength = 0, bool useMaxLineLengthWhenAutoWrapping = true );
1222 
1231  static QStringList splitToGraphemes( const QString &text );
1232 
1233  private:
1235  static void dataDefinedTextStyle( QgsPalLayerSettings &tmpLyr,
1236  const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues );
1237 
1239  static void dataDefinedTextFormatting( QgsPalLayerSettings &tmpLyr,
1240  const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues );
1241 
1243  static void dataDefinedTextBuffer( QgsPalLayerSettings &tmpLyr,
1244  const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues );
1245 
1247  static void dataDefinedTextMask( QgsPalLayerSettings &tmpLyr,
1248  const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues );
1249 
1251  static void dataDefinedShapeBackground( QgsPalLayerSettings &tmpLyr,
1252  const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues );
1253 
1255  static void dataDefinedDropShadow( QgsPalLayerSettings &tmpLyr,
1256  const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues );
1257 
1258  friend class QgsVectorLayerLabelProvider; // to allow calling the static methods above
1259  friend class QgsDxfExport; // to allow calling the static methods above
1260 
1269  static bool checkMinimumSizeMM( const QgsRenderContext &context, const QgsGeometry &geom, double minSize );
1270 
1271  friend class QgsPalLayerSettings;
1272 };
1273 
1274 
1275 #endif // QGSPALLABELING_H
UnplacedLabelVisibility
Unplaced label visibility.
Definition: qgis.h:423
@ 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:64
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:124
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:72
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:1629
#define Q_NOWARN_DEPRECATED_PUSH
Definition: qgis.h:1628
#define SIP_PROPERTY(name, getter, setter)
Definition: qgis_sip.h:263
#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