QGIS API Documentation  3.23.0-Master (7c4a6de034)
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  FontStretchFactor = 113,
242 
243  // text formatting
244  MultiLineWrapChar = 31,
245  AutoWrapLength = 101,
246  MultiLineHeight = 32,
247  MultiLineAlignment = 33,
248  TextOrientation = 110,
249  DirSymbDraw = 34,
250  DirSymbLeft = 35,
251  DirSymbRight = 36,
252  DirSymbPlacement = 37,
253  DirSymbReverse = 38,
254  NumFormat = 39,
255  NumDecimals = 40,
256  NumPlusSign = 41,
257 
258  // text buffer
259  BufferDraw = 42,
260  BufferSize = 7,
261  BufferUnit = 43,
262  BufferColor = 8,
263  BufferTransp = 19,
264  BufferOpacity = 94,
265  BufferJoinStyle = 44,
266  BufferBlendMode = 45,
267 
268  // mask buffer
269  MaskEnabled = 104,
270  MaskBufferSize = 105,
271  MaskBufferUnit = 106,
272  MaskOpacity = 107,
273  MaskJoinStyle = 108,
274 
275  // background
276  ShapeDraw = 46,
277  ShapeKind = 47,
278  ShapeSVGFile = 48,
279  ShapeSizeType = 49,
280  ShapeSizeX = 50,
281  ShapeSizeY = 85,
282  ShapeSizeUnits = 51,
283  ShapeRotationType = 52,
284  ShapeRotation = 53,
285  ShapeOffset = 54,
286  ShapeOffsetUnits = 55,
287  ShapeRadii = 56,
288  ShapeRadiiUnits = 57,
289  ShapeTransparency = 63,
290  ShapeOpacity = 93,
291  ShapeBlendMode = 64,
292  ShapeFillColor = 58,
293  ShapeStrokeColor = 59,
294  ShapeStrokeWidth = 60,
295  ShapeStrokeWidthUnits = 61,
296  ShapeJoinStyle = 62,
297 
298  // drop shadow
299  ShadowDraw = 65,
300  ShadowUnder = 66,
301  ShadowOffsetAngle = 67,
302  ShadowOffsetDist = 68,
303  ShadowOffsetUnits = 69,
304  ShadowRadius = 70,
305  ShadowRadiusUnits = 71,
306  ShadowTransparency = 72,
307  ShadowOpacity = 95,
308  ShadowScale = 73,
309  ShadowColor = 74,
310  ShadowBlendMode = 75,
311 
312  // placement
313  CentroidWhole = 76,
314  OffsetQuad = 77,
315  OffsetXY = 78,
316  OffsetUnits = 80,
317  LabelDistance = 13,
318  DistanceUnits = 81,
319  OffsetRotation = 82,
320  CurvedCharAngleInOut = 83,
321  // (data defined only)
322  PositionX = 9,
323  PositionY = 10,
324  PositionPoint = 114,
325  Hali = 11,
326  Vali = 12,
327  Rotation = 14,
328  LabelRotation = 96,
329  RepeatDistance = 84,
330  RepeatDistanceUnit = 86,
331  Priority = 87,
332  PredefinedPositionOrder = 91,
333  LinePlacementOptions = 99,
334  OverrunDistance = 102,
335  LabelAllParts = 103,
336  PolygonLabelOutside = 109,
337  LineAnchorPercent = 111,
338  LineAnchorClipping = 112,
339 
340  // rendering
341  ScaleVisibility = 23,
342  MinScale = 16,
343  MinimumScale = 97,
344  MaxScale = 17,
345  MaximumScale = 98,
346  FontLimitPixel = 24,
347  FontMinPixel = 25,
348  FontMaxPixel = 26,
349  IsObstacle = 88,
350  ObstacleFactor = 89,
351  ZIndex = 90,
352  CalloutDraw = 100,
353 
354  // (data defined only)
355  Show = 15,
356  AlwaysShow = 20
357  };
358 
359 
371  bool prepare( QgsRenderContext &context, QSet<QString> &attributeNames SIP_INOUT, const QgsFields &fields, const QgsMapSettings &mapSettings, const QgsCoordinateReferenceSystem &crs );
372 
377  QSet<QString> referencedFields( const QgsRenderContext &context ) const;
378 
387  void startRender( QgsRenderContext &context );
388 
396  void stopRender( QgsRenderContext &context );
397 
403  bool containsAdvancedEffects() const;
404 
409  static const QgsPropertiesDefinition &propertyDefinitions();
410 
419  bool drawLabels = true;
420 
421  //-- text style
422 
428  QString fieldName;
429 
434  bool isExpression = false;
435 
439  QgsExpression *getLabelExpression();
440 
444  Q_DECL_DEPRECATED QColor previewBkgrdColor = Qt::white;
445 
449  bool useSubstitutions = false;
450 
451  //-- text formatting
452 
457  QString wrapChar;
458 
466  int autoWrapLength = 0;
467 
478  bool useMaxLineLengthForAutoWrap = true;
479 
481  MultiLineAlign multilineAlign = MultiFollowPlacement;
482 
489  bool formatNumbers = false;
490 
496  int decimals = 3;
497 
503  bool plusSign = false;
504 
505  //-- placement
506 
507  Placement placement = AroundPoint;
508 
515  QgsLabeling::PolygonPlacementFlags polygonPlacementFlags() const { return mPolygonPlacementFlags; }
516 
523  void setPolygonPlacementFlags( QgsLabeling::PolygonPlacementFlags flags ) { mPolygonPlacementFlags = flags; }
524 
529  bool centroidWhole = false;
530 
536  bool centroidInside = false;
537 
544  QVector< PredefinedPointPosition > predefinedPositionOrder SIP_SKIP;
545 
549  bool fitInPolygonOnly = false;
550 
556  double dist = 0;
557 
564 
571 
573  OffsetType offsetType = FromPoint;
574 
580  double repeatDistance = 0;
581 
588 
595 
599  QuadrantPosition quadOffset = QuadrantOver;
600 
607  double xOffset = 0;
608 
615  double yOffset = 0;
616 
624 
632 
634  double angleOffset = 0;
635 
637  bool preserveRotation = true;
638 
644  QgsUnitTypes::AngleUnit rotationUnit() const;
645 
651  void setRotationUnit( QgsUnitTypes::AngleUnit angleUnit );
652 
657  double maxCurvedCharAngleIn = 25.0;
658 
663  double maxCurvedCharAngleOut = -25.0;
664 
669  int priority = 5;
670 
671  //-- rendering
672 
678  bool scaleVisibility = false;
679 
690  double maximumScale = 0;
691 
702  double minimumScale = 0;
703 
709  bool fontLimitPixelSize = false;
710 
716  int fontMinPixelSize = 0;
717 
723  int fontMaxPixelSize = 10000;
724 
726  bool displayAll = false;
727 
729  UpsideDownLabels upsidedownLabels = Upright;
730 
735  bool labelPerPart = false;
736 
737  // TODO QGIS 4.0 - remove this junk
738 
739 #ifdef SIP_RUN
740  SIP_PROPERTY( name = limitNumLabels, get = _limitNumLabels, set = _setLimitNumLabels )
741  SIP_PROPERTY( name = maxNumLabels, get = _maxNumLabels, set = _setMaxNumLabels )
742  SIP_PROPERTY( name = minFeatureSize, get = _minFeatureSize, set = _setMinFeatureSize )
743  SIP_PROPERTY( name = obstacle, get = _getIsObstacle, set = _setIsObstacle )
744  SIP_PROPERTY( name = obstacleFactor, get = _getObstacleFactor, set = _setObstacleFactor )
745  SIP_PROPERTY( name = obstacleType, get = _getObstacleType, set = _setObstacleType )
746  SIP_PROPERTY( name = placementFlags, get = _getLinePlacementFlags, set = _setLinePlacementFlags )
747  SIP_PROPERTY( name = mergeLines, get = _getMergeLines, set = _setMergeLines )
748  SIP_PROPERTY( name = addDirectionSymbol, get = _getAddDirectionSymbol, set = _setAddDirectionSymbol )
749  SIP_PROPERTY( name = leftDirectionSymbol, get = _getLeftDirectionSymbol, set = _setLeftDirectionSymbol )
750  SIP_PROPERTY( name = rightDirectionSymbol, get = _getRightDirectionSymbol, set = _setRightDirectionSymbol )
751  SIP_PROPERTY( name = reverseDirectionSymbol, get = _getReverseDirectionSymbol, set = _setReverseDirectionSymbol )
752  SIP_PROPERTY( name = placeDirectionSymbol, get = _getPlaceDirectionSymbol, set = _setPlaceDirectionSymbol )
753 
754  SIP_PROPERTY( name = overrunDistance, get = _getOverrunDistance, set = _setOverrunDistance )
755  SIP_PROPERTY( name = overrunDistanceUnit, get = _getOverrunDistanceUnit, set = _setOverrunDistanceUnit )
756  SIP_PROPERTY( name = overrunDistanceMapUnitScale, get = _getOverrunDistanceMapUnitScale, set = _setOverrunDistanceMapUnitScale )
757 #endif
758 
760  bool _limitNumLabels() const { return mThinningSettings.limitNumberOfLabelsEnabled(); }
761  void _setLimitNumLabels( bool limit ) { mThinningSettings.setLimitNumberLabelsEnabled( limit ); }
762  int _maxNumLabels() const { return mThinningSettings.maximumNumberLabels(); }
763  void _setMaxNumLabels( int max ) { mThinningSettings.setMaximumNumberLabels( max ); }
764  double _minFeatureSize() const { return mThinningSettings.minimumFeatureSize(); }
765  void _setMinFeatureSize( double size ) { mThinningSettings.setMinimumFeatureSize( size ); }
766  bool _getIsObstacle() const { return mObstacleSettings.isObstacle(); }
767  void _setIsObstacle( bool obstacle ) { mObstacleSettings.setIsObstacle( obstacle ); }
768  double _getObstacleFactor() const { return mObstacleSettings.factor(); }
769  void _setObstacleFactor( double factor ) { mObstacleSettings.setFactor( factor ); }
770  ObstacleType _getObstacleType() const { return static_cast< ObstacleType>( mObstacleSettings.type() ); }
771  void _setObstacleType( ObstacleType type ) { mObstacleSettings.setType( static_cast< QgsLabelObstacleSettings::ObstacleType>( type ) ); }
772  unsigned int _getLinePlacementFlags() const { return static_cast< unsigned int >( mLineSettings.placementFlags() ); }
773  void _setLinePlacementFlags( unsigned int flags ) { mLineSettings.setPlacementFlags( static_cast< QgsLabeling::LinePlacementFlags >( flags ) ); }
774  bool _getMergeLines() const { return mLineSettings.mergeLines(); }
775  void _setMergeLines( bool merge ) { mLineSettings.setMergeLines( merge ); }
776  bool _getAddDirectionSymbol() const { return mLineSettings.addDirectionSymbol(); }
777  void _setAddDirectionSymbol( bool add ) { mLineSettings.setAddDirectionSymbol( add ); }
778  QString _getLeftDirectionSymbol() const { return mLineSettings.leftDirectionSymbol(); }
779  void _setLeftDirectionSymbol( const QString &symbol ) { mLineSettings.setLeftDirectionSymbol( symbol ); }
780  QString _getRightDirectionSymbol() const { return mLineSettings.rightDirectionSymbol(); }
781  void _setRightDirectionSymbol( const QString &symbol ) { mLineSettings.setRightDirectionSymbol( symbol ); }
782  bool _getReverseDirectionSymbol() const { return mLineSettings.reverseDirectionSymbol(); }
783  void _setReverseDirectionSymbol( bool reverse ) { mLineSettings.setReverseDirectionSymbol( reverse ); }
785  DirectionSymbols _getPlaceDirectionSymbol() const { return static_cast< DirectionSymbols>( mLineSettings.directionSymbolPlacement() ); }
786  void _setPlaceDirectionSymbol( DirectionSymbols placement ) { mLineSettings.setDirectionSymbolPlacement( static_cast< QgsLabelLineSettings::DirectionSymbolPlacement>( placement ) ); }
788  double _getOverrunDistance() const { return mLineSettings.overrunDistance(); }
789  void _setOverrunDistance( double distance ) { mLineSettings.setOverrunDistance( distance ); }
790  QgsUnitTypes::RenderUnit _getOverrunDistanceUnit() const { return mLineSettings.overrunDistanceUnit(); }
791  void _setOverrunDistanceUnit( QgsUnitTypes::RenderUnit unit ) { mLineSettings.setOverrunDistanceUnit( unit ); }
792  QgsMapUnitScale _getOverrunDistanceMapUnitScale() const { return mLineSettings.overrunDistanceMapUnitScale(); }
793  void _setOverrunDistanceMapUnitScale( const QgsMapUnitScale &scale ) { mLineSettings.setOverrunDistanceMapUnitScale( scale ); }
795 
797  double zIndex = 0;
798 
801 
803  QgsWkbTypes::GeometryType geometryGeneratorType = QgsWkbTypes::GeometryType::PointGeometry;
804 
806  bool geometryGeneratorEnabled = false;
807 
813 
818  void setLegendString( const QString &legendString ) { mLegendString = legendString; }
819 
824  QString legendString() const { return mLegendString; }
825 
832 #ifndef SIP_RUN
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  QgsTextDocument *document = nullptr );
835 #else
836  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 );
837 #endif
838 
848  void registerFeature( const QgsFeature &f, QgsRenderContext &context );
849 
850 #ifndef SIP_RUN
851 
868  std::unique_ptr< QgsLabelFeature > registerFeatureWithDetails( const QgsFeature &feature, QgsRenderContext &context,
869  QgsGeometry obstacleGeometry = QgsGeometry(), const QgsSymbol *symbol = nullptr );
870 #endif
871 
876  void readXml( const QDomElement &elem, const QgsReadWriteContext &context );
877 
882  QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const;
883 
889  QgsPropertyCollection &dataDefinedProperties() { return mDataDefinedProperties; }
890 
898  const QgsPropertyCollection &dataDefinedProperties() const SIP_SKIP { return mDataDefinedProperties; }
899 
907  void setDataDefinedProperties( const QgsPropertyCollection &collection ) { mDataDefinedProperties = collection; }
908 
914  const QgsTextFormat &format() const { return mFormat; }
915 
922  void setFormat( const QgsTextFormat &format ) { mFormat = format; }
923 
932  QgsCallout *callout() const { return mCallout.get(); }
933 
942  void setCallout( QgsCallout *callout SIP_TRANSFER );
943 
952  const QgsLabelLineSettings &lineSettings() const { return mLineSettings; } SIP_SKIP
953 
961  QgsLabelLineSettings &lineSettings() { return mLineSettings; }
962 
970  void setLineSettings( const QgsLabelLineSettings &settings ) { mLineSettings = settings; }
971 
978  const QgsLabelObstacleSettings &obstacleSettings() const { return mObstacleSettings; } SIP_SKIP
979 
985  QgsLabelObstacleSettings &obstacleSettings() { return mObstacleSettings; }
986 
992  void setObstacleSettings( const QgsLabelObstacleSettings &settings ) { mObstacleSettings = settings; }
993 
1000  const QgsLabelThinningSettings &thinningSettings() const { return mThinningSettings; } SIP_SKIP
1001 
1007  QgsLabelThinningSettings &thinningSettings() { return mThinningSettings; }
1008 
1014  void setThinningSettings( const QgsLabelThinningSettings &settings ) { mThinningSettings = settings; }
1015 
1024  static QPixmap labelSettingsPreviewPixmap( const QgsPalLayerSettings &settings, QSize size, const QString &previewText = QString(), int padding = 0 );
1025 
1032  Qgis::UnplacedLabelVisibility unplacedVisibility() const;
1033 
1040  void setUnplacedVisibility( Qgis::UnplacedLabelVisibility visibility );
1041 
1042  // temporary stuff: set when layer gets prepared or labeled
1043  const QgsFeature *mCurFeat = nullptr;
1045  int fieldIndex = 0;
1046  const QgsMapToPixel *xform = nullptr;
1048 
1052  int mFeaturesToLabel = 0; // total features that will probably be labeled, may be less (figured before PAL)
1053  int mFeatsSendingToPal = 0; // total features tested for sending into PAL (relative to maxNumLabels)
1054  int mFeatsRegPal = 0; // number of features registered in PAL, when using limitNumLabels
1055 
1056  private:
1057 
1058  friend class QgsVectorLayer; // to allow calling readFromLayerCustomProperties()
1059 
1064  void readFromLayerCustomProperties( QgsVectorLayer *layer );
1065 
1069  void readOldDataDefinedPropertyMap( QgsVectorLayer *layer, QDomElement *parentElem );
1070 
1074  void readOldDataDefinedProperty( QgsVectorLayer *layer, QgsPalLayerSettings::Property p );
1075 
1076  enum DataDefinedValueType
1077  {
1078  DDBool,
1079  DDInt,
1080  DDIntPos,
1081  DDDouble,
1082  DDDoublePos,
1083  DDRotation180,
1084  DDOpacity,
1085  DDString,
1086  DDUnits,
1087  DDColor,
1088  DDJoinStyle,
1089  DDBlendMode,
1090  DDPointF,
1091  DDSizeF,
1092  };
1093 
1094  // convenience data defined evaluation function
1095  bool dataDefinedValEval( DataDefinedValueType valType,
1097  QVariant &exprVal, QgsExpressionContext &context, const QVariant &originalValue = QVariant() );
1098 
1099  void parseTextStyle( QFont &labelFont,
1100  QgsUnitTypes::RenderUnit fontunits,
1101  QgsRenderContext &context );
1102 
1103  void parseTextBuffer( QgsRenderContext &context );
1104 
1105  void parseTextMask( QgsRenderContext &context );
1106 
1107  void parseTextFormatting( QgsRenderContext &context );
1108 
1109  void parseShapeBackground( QgsRenderContext &context );
1110 
1111  void parseDropShadow( QgsRenderContext &context );
1112 
1117  bool checkMinimumSizeMM( const QgsRenderContext &ct, const QgsGeometry &geom, double minSize ) const;
1118 
1122  std::unique_ptr< QgsLabelFeature > registerObstacleFeature( const QgsFeature &f, QgsRenderContext &context, const QgsGeometry &obstacleGeometry = QgsGeometry() );
1123 
1124  QMap<Property, QVariant> dataDefinedValues;
1125 
1127  QgsPropertyCollection mDataDefinedProperties;
1128 
1129  QgsExpression *expression = nullptr;
1130 
1131  std::unique_ptr< QFontDatabase > mFontDB;
1132 
1133  QgsTextFormat mFormat;
1134 
1135  std::unique_ptr< QgsCallout > mCallout;
1136 
1137  QgsLabelLineSettings mLineSettings;
1138  QgsLabelObstacleSettings mObstacleSettings;
1139  QgsLabelThinningSettings mThinningSettings;
1140 
1141  QgsLabeling::PolygonPlacementFlags mPolygonPlacementFlags = QgsLabeling::PolygonPlacementFlag::AllowPlacementInsideOfPolygon;
1142 
1143  QgsExpression mGeometryGeneratorExpression;
1144 
1145  bool mRenderStarted = false;
1146 
1147  QString mLegendString = QObject::tr( "Aa" );
1148 
1150 
1153 
1154  static void initPropertyDefinitions();
1155 };
1156 
1161 class CORE_EXPORT QgsLabelCandidate
1162 {
1163  public:
1164  QgsLabelCandidate( const QRectF &r, double c ): rect( r ), cost( c ) {}
1165 
1166  QRectF rect;
1167  double cost;
1168 };
1169 
1175 class CORE_EXPORT QgsPalLabeling
1176 {
1177  public:
1178 
1183  static bool staticWillUseLayer( const QgsMapLayer *layer );
1184 
1186  static void drawLabelCandidateRect( pal::LabelPosition *lp, QPainter *painter, const QgsMapToPixel *xform, QList<QgsLabelCandidate> *candidates = nullptr ) SIP_SKIP;
1187 
1198  static QgsGeometry prepareGeometry( const QgsGeometry &geometry, QgsRenderContext &context, const QgsCoordinateTransform &ct, const QgsGeometry &clipGeometry = QgsGeometry(), bool mergeLines = false ) SIP_FACTORY;
1199 
1210  static bool geometryRequiresPreparation( const QgsGeometry &geometry, QgsRenderContext &context, const QgsCoordinateTransform &ct, const QgsGeometry &clipGeometry = QgsGeometry(), bool mergeLines = false );
1211 
1224  static QStringList splitToLines( const QString &text, const QString &wrapCharacter, int autoWrapLength = 0, bool useMaxLineLengthWhenAutoWrapping = true );
1225 
1234  static QStringList splitToGraphemes( const QString &text );
1235 
1236  private:
1238  static void dataDefinedTextStyle( QgsPalLayerSettings &tmpLyr,
1239  const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues );
1240 
1242  static void dataDefinedTextFormatting( QgsPalLayerSettings &tmpLyr,
1243  const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues );
1244 
1246  static void dataDefinedTextBuffer( QgsPalLayerSettings &tmpLyr,
1247  const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues );
1248 
1250  static void dataDefinedTextMask( QgsPalLayerSettings &tmpLyr,
1251  const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues );
1252 
1254  static void dataDefinedShapeBackground( QgsPalLayerSettings &tmpLyr,
1255  const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues );
1256 
1258  static void dataDefinedDropShadow( QgsPalLayerSettings &tmpLyr,
1259  const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues );
1260 
1261  friend class QgsVectorLayerLabelProvider; // to allow calling the static methods above
1262  friend class QgsDxfExport; // to allow calling the static methods above
1263 
1272  static bool checkMinimumSizeMM( const QgsRenderContext &context, const QgsGeometry &geom, double minSize );
1273 
1274  friend class QgsPalLayerSettings;
1275 };
1276 
1277 
1278 #endif // QGSPALLABELING_H
UnplacedLabelVisibility
Unplaced label visibility.
Definition: qgis.h:444
@ 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:2042
#define Q_NOWARN_DEPRECATED_PUSH
Definition: qgis.h:2041
#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