QGIS API Documentation  3.17.0-Master (8af46bc54f)
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 //Note: although this file is in the core library, it is not part of the stable API
19 //and might change at any time!
20 
21 #ifndef QGSPALLABELING_H
22 #define QGSPALLABELING_H
23 
24 #include "qgis_core.h"
25 #include "qgis_sip.h"
26 #include <QString>
27 #include <QFont>
28 #include <QFontDatabase>
29 #include <QColor>
30 #include <QHash>
31 #include <QList>
32 #include <QPainter>
33 #include <QRectF>
34 #include <QMap>
35 #include "qgsfeature.h"
36 #include "qgsgeometry.h"
37 #include "qgsfields.h"
39 #include "qgspointxy.h"
40 #include "qgsmapunitscale.h"
41 #include "qgsstringutils.h"
42 #include "qgssymbol.h"
43 #include "qgstextformat.h"
44 #include "qgspropertycollection.h"
47 #include "qgslabellinesettings.h"
48 #include "qgslabeling.h"
49 
50 class QgsTextDocument;
51 
52 namespace pal SIP_SKIP
53 {
54  class Pal;
55  class Layer;
56  class LabelPosition;
57 }
58 
60 class QgsRectangle;
61 class QgsMapToPixel;
62 class QgsFeature;
64 class QgsVectorLayer;
65 class QgsExpression;
66 class QFontMetricsF;
67 class QPainter;
68 class QPicture;
69 class QgsGeometry;
71 class QgsLabelSearchTree;
72 class QgsMapSettings;
73 class QgsLabelFeature;
74 class QgsLabelingEngine;
77 class QgsDxfExport;
80 class QgsCallout;
81 
86 class CORE_EXPORT QgsLabelPosition
87 {
88  public:
89 
108  QgsLabelPosition( QgsFeatureId id, double r, const QVector< QgsPointXY > &corners, const QgsRectangle &rect, double w, double h, const QString &layer, const QString &labeltext, const QFont &labelfont, bool upside_down, bool diagram = false, bool pinned = false, const QString &providerId = QString(),
109  const QgsGeometry &labelGeometry = QgsGeometry(), bool isUnplaced = false )
110  : featureId( id )
111  , rotation( r )
112  , cornerPoints( corners )
113  , labelRect( rect )
114  , labelGeometry( labelGeometry )
115  , width( w )
116  , height( h )
117  , layerID( layer )
118  , labelText( labeltext )
119  , labelFont( labelfont )
120  , upsideDown( upside_down )
121  , isDiagram( diagram )
122  , isPinned( pinned )
123  , providerID( providerId )
124  , isUnplaced( isUnplaced )
125  {}
126 
128  QgsLabelPosition() = default;
129 
133  QgsFeatureId featureId = FID_NULL;
134 
138  double rotation = 0;
139 
140  QVector< QgsPointXY > cornerPoints;
142 
148 
152  double width = 0;
153 
157  double height = 0;
158 
162  QString layerID;
163 
167  QString labelText;
168 
172  QFont labelFont;
173 
177  bool upsideDown = false;
178 
182  bool isDiagram = false;
183 
187  bool isPinned = false;
188 
193  QString providerID;
194 
199  bool isUnplaced = false;
200 };
201 
206 class CORE_EXPORT QgsPalLayerSettings
207 {
208  public:
212 
214  QgsPalLayerSettings &operator=( const QgsPalLayerSettings &s );
215 
216  //TODO QGIS 4.0 - move to QgsLabelingEngine
217 
222  {
232  };
233 
234  //TODO QGIS 4.0 - move to QgsLabelingEngine
237  {
250  };
251 
252  //TODO QGIS 4.0 - move to QgsLabelingEngine
253 
259  {
262  };
263 
264  //TODO QGIS 4.0 - remove, replaced by QgsLabeling::LinePlacementFlags
265 
272  {
273  OnLine = 1,
274  AboveLine = 2,
277  BelowLine = 4,
280  MapOrientation = 8,
283  };
284 
286  {
296  };
297 
299  {
302  ShowAll
303  };
304 
305  //TODO QGIS 4.0 - Remove -- moved to QgsLabelEngineObstacleSettings
306 
309  {
312  SymbolBelow
313  };
314 
316  {
317  MultiLeft = 0,
320  MultiFollowPlacement,
323  };
324 
325  //TODO QGIS 4.0 - Remove -- moved to QgsLabelEngineObstacleSettings
326 
332  {
333  PolygonInterior,
335  PolygonBoundary,
337  PolygonWhole
341  };
342 
344  enum Property
345  {
346  // text style
347  Size = 0,
348  Bold = 1,
349  Italic = 2,
350  Underline = 3,
351  Color = 4,
352  Strikeout = 5,
353  Family = 6,
354  FontStyle = 21,
355  FontSizeUnit = 22,
356  FontTransp = 18,
357  FontOpacity = 92,
358  FontCase = 27,
359  FontLetterSpacing = 28,
360  FontWordSpacing = 29,
361  FontBlendMode = 30,
362 
363  // text formatting
364  MultiLineWrapChar = 31,
365  AutoWrapLength = 101,
366  MultiLineHeight = 32,
367  MultiLineAlignment = 33,
368  TextOrientation = 110,
369  DirSymbDraw = 34,
370  DirSymbLeft = 35,
371  DirSymbRight = 36,
372  DirSymbPlacement = 37,
373  DirSymbReverse = 38,
374  NumFormat = 39,
375  NumDecimals = 40,
376  NumPlusSign = 41,
377 
378  // text buffer
379  BufferDraw = 42,
380  BufferSize = 7,
381  BufferUnit = 43,
382  BufferColor = 8,
383  BufferTransp = 19,
384  BufferOpacity = 94,
385  BufferJoinStyle = 44,
386  BufferBlendMode = 45,
387 
388  // mask buffer
389  MaskEnabled = 104,
390  MaskBufferSize = 105,
391  MaskBufferUnit = 106,
392  MaskOpacity = 107,
393  MaskJoinStyle = 108,
394 
395  // background
396  ShapeDraw = 46,
397  ShapeKind = 47,
398  ShapeSVGFile = 48,
399  ShapeSizeType = 49,
400  ShapeSizeX = 50,
401  ShapeSizeY = 85,
402  ShapeSizeUnits = 51,
403  ShapeRotationType = 52,
404  ShapeRotation = 53,
405  ShapeOffset = 54,
406  ShapeOffsetUnits = 55,
407  ShapeRadii = 56,
408  ShapeRadiiUnits = 57,
409  ShapeTransparency = 63,
410  ShapeOpacity = 93,
411  ShapeBlendMode = 64,
412  ShapeFillColor = 58,
413  ShapeStrokeColor = 59,
414  ShapeStrokeWidth = 60,
415  ShapeStrokeWidthUnits = 61,
416  ShapeJoinStyle = 62,
417 
418  // drop shadow
419  ShadowDraw = 65,
420  ShadowUnder = 66,
421  ShadowOffsetAngle = 67,
422  ShadowOffsetDist = 68,
423  ShadowOffsetUnits = 69,
424  ShadowRadius = 70,
425  ShadowRadiusUnits = 71,
426  ShadowTransparency = 72,
427  ShadowOpacity = 95,
428  ShadowScale = 73,
429  ShadowColor = 74,
430  ShadowBlendMode = 75,
431 
432  // placement
433  CentroidWhole = 76,
434  OffsetQuad = 77,
435  OffsetXY = 78,
436  OffsetUnits = 80,
437  LabelDistance = 13,
438  DistanceUnits = 81,
439  OffsetRotation = 82,
440  CurvedCharAngleInOut = 83,
441  // (data defined only)
442  PositionX = 9,
443  PositionY = 10,
444  Hali = 11,
445  Vali = 12,
446  Rotation = 14,
447  LabelRotation = 96,
448  RepeatDistance = 84,
449  RepeatDistanceUnit = 86,
450  Priority = 87,
451  PredefinedPositionOrder = 91,
452  LinePlacementOptions = 99,
453  OverrunDistance = 102,
454  LabelAllParts = 103,
455  PolygonLabelOutside = 109,
456  LineAnchorPercent = 111,
457 
458  // rendering
459  ScaleVisibility = 23,
460  MinScale = 16,
461  MinimumScale = 97,
462  MaxScale = 17,
463  MaximumScale = 98,
464  FontLimitPixel = 24,
465  FontMinPixel = 25,
466  FontMaxPixel = 26,
467  IsObstacle = 88,
468  ObstacleFactor = 89,
469  ZIndex = 90,
470  CalloutDraw = 100,
471 
472  // (data defined only)
473  Show = 15,
474  AlwaysShow = 20
475  };
476 
477 
489  bool prepare( QgsRenderContext &context, QSet<QString> &attributeNames SIP_INOUT, const QgsFields &fields, const QgsMapSettings &mapSettings, const QgsCoordinateReferenceSystem &crs );
490 
495  QSet<QString> referencedFields( const QgsRenderContext &context ) const;
496 
505  void startRender( QgsRenderContext &context );
506 
514  void stopRender( QgsRenderContext &context );
515 
520  static const QgsPropertiesDefinition &propertyDefinitions();
521 
530  bool drawLabels = true;
531 
532  //-- text style
533 
539  QString fieldName;
540 
545  bool isExpression = false;
546 
550  QgsExpression *getLabelExpression();
551 
555  Q_DECL_DEPRECATED QColor previewBkgrdColor = Qt::white;
556 
560  bool useSubstitutions = false;
561 
562  //-- text formatting
563 
568  QString wrapChar;
569 
577  int autoWrapLength = 0;
578 
589  bool useMaxLineLengthForAutoWrap = true;
590 
592  MultiLineAlign multilineAlign = MultiFollowPlacement;
593 
600  bool formatNumbers = false;
601 
607  int decimals = 3;
608 
614  bool plusSign = false;
615 
616  //-- placement
617 
618  Placement placement = AroundPoint;
619 
626  QgsLabeling::PolygonPlacementFlags polygonPlacementFlags() const { return mPolygonPlacementFlags; }
627 
634  void setPolygonPlacementFlags( QgsLabeling::PolygonPlacementFlags flags ) { mPolygonPlacementFlags = flags; }
635 
640  bool centroidWhole = false;
641 
647  bool centroidInside = false;
648 
655  QVector< PredefinedPointPosition > predefinedPositionOrder SIP_SKIP;
656 
660  bool fitInPolygonOnly = false;
661 
667  double dist = 0;
668 
675 
682 
684  OffsetType offsetType = FromPoint;
685 
691  double repeatDistance = 0;
692 
699 
706 
710  QuadrantPosition quadOffset = QuadrantOver;
711 
718  double xOffset = 0;
719 
726  double yOffset = 0;
727 
735 
743 
745  double angleOffset = 0;
746 
748  bool preserveRotation = true;
749 
754  double maxCurvedCharAngleIn = 25.0;
755 
760  double maxCurvedCharAngleOut = -25.0;
761 
766  int priority = 5;
767 
768  //-- rendering
769 
775  bool scaleVisibility = false;
776 
787  double maximumScale = 0;
788 
799  double minimumScale = 0;
800 
806  bool fontLimitPixelSize = false;
807 
813  int fontMinPixelSize = 0;
814 
820  int fontMaxPixelSize = 10000;
821 
823  bool displayAll = false;
824 
826  UpsideDownLabels upsidedownLabels = Upright;
827 
832  bool labelPerPart = false;
833 
834  // TODO QGIS 4.0 - remove this junk
835 
836 #ifdef SIP_RUN
837  SIP_PROPERTY( name = limitNumLabels, get = _limitNumLabels, set = _setLimitNumLabels )
838  SIP_PROPERTY( name = maxNumLabels, get = _maxNumLabels, set = _setMaxNumLabels )
839  SIP_PROPERTY( name = minFeatureSize, get = _minFeatureSize, set = _setMinFeatureSize )
840  SIP_PROPERTY( name = obstacle, get = _getIsObstacle, set = _setIsObstacle )
841  SIP_PROPERTY( name = obstacleFactor, get = _getObstacleFactor, set = _setObstacleFactor )
842  SIP_PROPERTY( name = obstacleType, get = _getObstacleType, set = _setObstacleType )
843  SIP_PROPERTY( name = placementFlags, get = _getLinePlacementFlags, set = _setLinePlacementFlags )
844  SIP_PROPERTY( name = mergeLines, get = _getMergeLines, set = _setMergeLines )
845  SIP_PROPERTY( name = addDirectionSymbol, get = _getAddDirectionSymbol, set = _setAddDirectionSymbol )
846  SIP_PROPERTY( name = leftDirectionSymbol, get = _getLeftDirectionSymbol, set = _setLeftDirectionSymbol )
847  SIP_PROPERTY( name = rightDirectionSymbol, get = _getRightDirectionSymbol, set = _setRightDirectionSymbol )
848  SIP_PROPERTY( name = reverseDirectionSymbol, get = _getReverseDirectionSymbol, set = _setReverseDirectionSymbol )
849  SIP_PROPERTY( name = placeDirectionSymbol, get = _getPlaceDirectionSymbol, set = _setPlaceDirectionSymbol )
850 
851  SIP_PROPERTY( name = overrunDistance, get = _getOverrunDistance, set = _setOverrunDistance )
852  SIP_PROPERTY( name = overrunDistanceUnit, get = _getOverrunDistanceUnit, set = _setOverrunDistanceUnit )
853  SIP_PROPERTY( name = overrunDistanceMapUnitScale, get = _getOverrunDistanceMapUnitScale, set = _setOverrunDistanceMapUnitScale )
854 #endif
855 
857  bool _limitNumLabels() const { return mThinningSettings.limitNumberOfLabelsEnabled(); }
858  void _setLimitNumLabels( bool limit ) { mThinningSettings.setLimitNumberLabelsEnabled( limit ); }
859  int _maxNumLabels() const { return mThinningSettings.maximumNumberLabels(); }
860  void _setMaxNumLabels( int max ) { mThinningSettings.setMaximumNumberLabels( max ); }
861  double _minFeatureSize() const { return mThinningSettings.minimumFeatureSize(); }
862  void _setMinFeatureSize( double size ) { mThinningSettings.setMinimumFeatureSize( size ); }
863  bool _getIsObstacle() const { return mObstacleSettings.isObstacle(); }
864  void _setIsObstacle( bool obstacle ) { mObstacleSettings.setIsObstacle( obstacle ); }
865  double _getObstacleFactor() const { return mObstacleSettings.factor(); }
866  void _setObstacleFactor( double factor ) { mObstacleSettings.setFactor( factor ); }
867  ObstacleType _getObstacleType() const { return static_cast< ObstacleType>( mObstacleSettings.type() ); }
868  void _setObstacleType( ObstacleType type ) { mObstacleSettings.setType( static_cast< QgsLabelObstacleSettings::ObstacleType>( type ) ); }
869  unsigned int _getLinePlacementFlags() const { return static_cast< unsigned int >( mLineSettings.placementFlags() ); }
870  void _setLinePlacementFlags( unsigned int flags ) { mLineSettings.setPlacementFlags( static_cast< QgsLabeling::LinePlacementFlags >( flags ) ); }
871  bool _getMergeLines() const { return mLineSettings.mergeLines(); }
872  void _setMergeLines( bool merge ) { mLineSettings.setMergeLines( merge ); }
873  bool _getAddDirectionSymbol() const { return mLineSettings.addDirectionSymbol(); }
874  void _setAddDirectionSymbol( bool add ) { mLineSettings.setAddDirectionSymbol( add ); }
875  QString _getLeftDirectionSymbol() const { return mLineSettings.leftDirectionSymbol(); }
876  void _setLeftDirectionSymbol( const QString &symbol ) { mLineSettings.setLeftDirectionSymbol( symbol ); }
877  QString _getRightDirectionSymbol() const { return mLineSettings.rightDirectionSymbol(); }
878  void _setRightDirectionSymbol( const QString &symbol ) { mLineSettings.setRightDirectionSymbol( symbol ); }
879  bool _getReverseDirectionSymbol() const { return mLineSettings.reverseDirectionSymbol(); }
880  void _setReverseDirectionSymbol( bool reverse ) { mLineSettings.setReverseDirectionSymbol( reverse ); }
882  DirectionSymbols _getPlaceDirectionSymbol() const { return static_cast< DirectionSymbols>( mLineSettings.directionSymbolPlacement() ); }
883  void _setPlaceDirectionSymbol( DirectionSymbols placement ) { mLineSettings.setDirectionSymbolPlacement( static_cast< QgsLabelLineSettings::DirectionSymbolPlacement>( placement ) ); }
885  double _getOverrunDistance() const { return mLineSettings.overrunDistance(); }
886  void _setOverrunDistance( double distance ) { mLineSettings.setOverrunDistance( distance ); }
887  QgsUnitTypes::RenderUnit _getOverrunDistanceUnit() const { return mLineSettings.overrunDistanceUnit(); }
888  void _setOverrunDistanceUnit( QgsUnitTypes::RenderUnit unit ) { mLineSettings.setOverrunDistanceUnit( unit ); }
889  QgsMapUnitScale _getOverrunDistanceMapUnitScale() const { return mLineSettings.overrunDistanceMapUnitScale(); }
890  void _setOverrunDistanceMapUnitScale( const QgsMapUnitScale &scale ) { mLineSettings.setOverrunDistanceMapUnitScale( scale ); }
892 
894  double zIndex = 0;
895 
898 
900  QgsWkbTypes::GeometryType geometryGeneratorType = QgsWkbTypes::GeometryType::PointGeometry;
901 
903  bool geometryGeneratorEnabled = false;
904 
910 
917 #ifndef SIP_RUN
918  void calculateLabelSize( const QFontMetricsF *fm, const QString &text, double &labelX, double &labelY, const QgsFeature *f = nullptr, QgsRenderContext *context = nullptr, double *rotatedLabelX SIP_OUT = nullptr, double *rotatedLabelY SIP_OUT = nullptr,
919  QgsTextDocument *document = nullptr );
920 #else
921  void calculateLabelSize( const QFontMetricsF *fm, const QString &text, double &labelX, double &labelY, const QgsFeature *f = nullptr, QgsRenderContext *context = nullptr, double *rotatedLabelX SIP_OUT = nullptr, double *rotatedLabelY SIP_OUT = nullptr );
922 #endif
923 
938  void registerFeature( const QgsFeature &f, QgsRenderContext &context,
939  QgsLabelFeature **labelFeature SIP_PYARGREMOVE = nullptr,
940  QgsGeometry obstacleGeometry SIP_PYARGREMOVE = QgsGeometry(), const QgsSymbol *symbol SIP_PYARGREMOVE = nullptr );
941 
946  void readXml( const QDomElement &elem, const QgsReadWriteContext &context );
947 
952  QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const;
953 
959  QgsPropertyCollection &dataDefinedProperties() { return mDataDefinedProperties; }
960 
968  const QgsPropertyCollection &dataDefinedProperties() const SIP_SKIP { return mDataDefinedProperties; }
969 
977  void setDataDefinedProperties( const QgsPropertyCollection &collection ) { mDataDefinedProperties = collection; }
978 
984  const QgsTextFormat &format() const { return mFormat; }
985 
992  void setFormat( const QgsTextFormat &format ) { mFormat = format; }
993 
1002  QgsCallout *callout() const { return mCallout.get(); }
1003 
1012  void setCallout( QgsCallout *callout SIP_TRANSFER );
1013 
1022  const QgsLabelLineSettings &lineSettings() const { return mLineSettings; } SIP_SKIP
1023 
1031  QgsLabelLineSettings &lineSettings() { return mLineSettings; }
1032 
1040  void setLineSettings( const QgsLabelLineSettings &settings ) { mLineSettings = settings; }
1041 
1048  const QgsLabelObstacleSettings &obstacleSettings() const { return mObstacleSettings; } SIP_SKIP
1049 
1055  QgsLabelObstacleSettings &obstacleSettings() { return mObstacleSettings; }
1056 
1062  void setObstacleSettings( const QgsLabelObstacleSettings &settings ) { mObstacleSettings = settings; }
1063 
1070  const QgsLabelThinningSettings &thinningSettings() const { return mThinningSettings; } SIP_SKIP
1071 
1077  QgsLabelThinningSettings &thinningSettings() { return mThinningSettings; }
1078 
1084  void setThinningSettings( const QgsLabelThinningSettings &settings ) { mThinningSettings = settings; }
1085 
1094  static QPixmap labelSettingsPreviewPixmap( const QgsPalLayerSettings &settings, QSize size, const QString &previewText = QString(), int padding = 0 );
1095 
1096  // temporary stuff: set when layer gets prepared or labeled
1097  const QgsFeature *mCurFeat = nullptr;
1099  int fieldIndex = 0;
1100  const QgsMapToPixel *xform = nullptr;
1102 
1106  int mFeaturesToLabel = 0; // total features that will probably be labeled, may be less (figured before PAL)
1107  int mFeatsSendingToPal = 0; // total features tested for sending into PAL (relative to maxNumLabels)
1108  int mFeatsRegPal = 0; // number of features registered in PAL, when using limitNumLabels
1109  private:
1110 
1111  friend class QgsVectorLayer; // to allow calling readFromLayerCustomProperties()
1112 
1117  void readFromLayerCustomProperties( QgsVectorLayer *layer );
1118 
1122  void readOldDataDefinedPropertyMap( QgsVectorLayer *layer, QDomElement *parentElem );
1123 
1127  void readOldDataDefinedProperty( QgsVectorLayer *layer, QgsPalLayerSettings::Property p );
1128 
1129  enum DataDefinedValueType
1130  {
1131  DDBool,
1132  DDInt,
1133  DDIntPos,
1134  DDDouble,
1135  DDDoublePos,
1136  DDRotation180,
1137  DDOpacity,
1138  DDString,
1139  DDUnits,
1140  DDColor,
1141  DDJoinStyle,
1142  DDBlendMode,
1143  DDPointF,
1144  DDSizeF,
1145  };
1146 
1147  // convenience data defined evaluation function
1148  bool dataDefinedValEval( DataDefinedValueType valType,
1150  QVariant &exprVal, QgsExpressionContext &context, const QVariant &originalValue = QVariant() );
1151 
1152  void parseTextStyle( QFont &labelFont,
1153  QgsUnitTypes::RenderUnit fontunits,
1154  QgsRenderContext &context );
1155 
1156  void parseTextBuffer( QgsRenderContext &context );
1157 
1158  void parseTextMask( QgsRenderContext &context );
1159 
1160  void parseTextFormatting( QgsRenderContext &context );
1161 
1162  void parseShapeBackground( QgsRenderContext &context );
1163 
1164  void parseDropShadow( QgsRenderContext &context );
1165 
1170  bool checkMinimumSizeMM( const QgsRenderContext &ct, const QgsGeometry &geom, double minSize ) const;
1171 
1175  void registerObstacleFeature( const QgsFeature &f, QgsRenderContext &context, QgsLabelFeature **obstacleFeature, const QgsGeometry &obstacleGeometry = QgsGeometry() );
1176 
1177  QMap<Property, QVariant> dataDefinedValues;
1178 
1180  QgsPropertyCollection mDataDefinedProperties;
1181 
1182  QgsExpression *expression = nullptr;
1183 
1184  QFontDatabase mFontDB;
1185 
1186  QgsTextFormat mFormat;
1187 
1188  std::unique_ptr< QgsCallout > mCallout;
1189 
1190  QgsLabelLineSettings mLineSettings;
1191  QgsLabelObstacleSettings mObstacleSettings;
1192  QgsLabelThinningSettings mThinningSettings;
1193 
1194  QgsLabeling::PolygonPlacementFlags mPolygonPlacementFlags = QgsLabeling::PolygonPlacementFlag::AllowPlacementInsideOfPolygon;
1195 
1196  QgsExpression mGeometryGeneratorExpression;
1197 
1198  bool mRenderStarted = false;
1199 
1200  static void initPropertyDefinitions();
1201 };
1202 
1206 class CORE_EXPORT QgsLabelCandidate
1207 {
1208  public:
1209  QgsLabelCandidate( const QRectF &r, double c ): rect( r ), cost( c ) {}
1210 
1211  QRectF rect;
1212  double cost;
1213 };
1214 
1215 
1216 
1217 
1223 class CORE_EXPORT QgsLabelingResults
1224 {
1225  public:
1227  ~QgsLabelingResults();
1228 
1230  QgsLabelingResults( const QgsLabelingResults & ) = delete;
1232  QgsLabelingResults &operator=( const QgsLabelingResults &rh ) = delete;
1233 
1235  QList<QgsLabelPosition> labelsAtPosition( const QgsPointXY &p ) const;
1237  QList<QgsLabelPosition> labelsWithinRect( const QgsRectangle &r ) const;
1238 
1243  void setMapSettings( const QgsMapSettings &settings );
1244 
1245  private:
1246 #ifdef SIP_RUN
1248 #endif
1249 
1250  std::unique_ptr< QgsLabelSearchTree > mLabelSearchTree;
1251 
1252  friend class QgsPalLabeling;
1255 };
1256 
1261 class CORE_EXPORT QgsPalLabeling
1262 {
1263  public:
1264 
1269  static bool staticWillUseLayer( const QgsMapLayer *layer );
1270 
1272  static void drawLabelCandidateRect( pal::LabelPosition *lp, QPainter *painter, const QgsMapToPixel *xform, QList<QgsLabelCandidate> *candidates = nullptr ) SIP_SKIP;
1273 
1284  static QgsGeometry prepareGeometry( const QgsGeometry &geometry, QgsRenderContext &context, const QgsCoordinateTransform &ct, const QgsGeometry &clipGeometry = QgsGeometry(), bool mergeLines = false ) SIP_FACTORY;
1285 
1296  static bool geometryRequiresPreparation( const QgsGeometry &geometry, QgsRenderContext &context, const QgsCoordinateTransform &ct, const QgsGeometry &clipGeometry = QgsGeometry(), bool mergeLines = false );
1297 
1310  static QStringList splitToLines( const QString &text, const QString &wrapCharacter, int autoWrapLength = 0, bool useMaxLineLengthWhenAutoWrapping = true );
1311 
1320  static QStringList splitToGraphemes( const QString &text );
1321 
1322  private:
1324  static void dataDefinedTextStyle( QgsPalLayerSettings &tmpLyr,
1325  const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues );
1326 
1328  static void dataDefinedTextFormatting( QgsPalLayerSettings &tmpLyr,
1329  const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues );
1330 
1332  static void dataDefinedTextBuffer( QgsPalLayerSettings &tmpLyr,
1333  const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues );
1334 
1336  static void dataDefinedTextMask( QgsPalLayerSettings &tmpLyr,
1337  const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues );
1338 
1340  static void dataDefinedShapeBackground( QgsPalLayerSettings &tmpLyr,
1341  const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues );
1342 
1344  static void dataDefinedDropShadow( QgsPalLayerSettings &tmpLyr,
1345  const QMap< QgsPalLayerSettings::Property, QVariant > &ddValues );
1346 
1347  friend class QgsVectorLayerLabelProvider; // to allow calling the static methods above
1348  friend class QgsDxfExport; // to allow calling the static methods above
1349 
1358  static bool checkMinimumSizeMM( const QgsRenderContext &context, const QgsGeometry &geom, double minSize );
1359 
1360  friend class QgsPalLayerSettings;
1361 };
1362 
1363 
1364 #endif // QGSPALLABELING_H
Label on bottom right of point.
QgsRectangle labelRect
Class for parsing and evaluation of expressions (formerly called "search strings").
The class is used as a container of context for various read/write operations on other objects...
QString geometryGenerator
The geometry generator expression. Null if disabled.
QString labelText
String shown in label.
A rectangle specified with double values.
Definition: qgsrectangle.h:41
Base class for all map layer types.
Definition: qgsmaplayer.h:83
Label on bottom-left of point.
Abstract base class for callout renderers.
Definition: qgscallout.h:46
#define SIP_PROPERTY(name, getter, setter)
Definition: qgis_sip.h:262
Label on top of point, slightly left of center.
void setThinningSettings(const QgsLabelThinningSettings &settings)
Sets the label thinning settings.
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:64
A class to query the labeling structure at a given point (small wrapper around pal RTree class) ...
Label on top-left of point.
Contains settings related to how the label engine removes candidate label positions and reduces the n...
QgsLabelCandidate(const QRectF &r, double c)
#define FID_NULL
Definition: qgsfeatureid.h:29
Arranges candidates over a point (or centroid of a polygon), or at a preset offset from the point...
Arranges candidates following the curvature of a line feature. Applies to line layers only...
PredefinedPointPosition
Positions for labels when using the QgsPalLabeling::OrderedPositionsAroundPoint placement mode...
A class to represent a 2D point.
Definition: qgspointxy.h:43
void setLineSettings(const QgsLabelLineSettings &settings)
Sets the label line settings, which contain settings related to how the label engine places and forma...
QString layerID
ID of associated map layer.
Candidates are placed in predefined positions around a point. Preference is given to positions with g...
#define Q_NOWARN_DEPRECATED_PUSH
Definition: qgis.h:797
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features ...
Definition: qgsfeatureid.h:28
Class that adds extra information to QgsLabelFeature for text labels.
QgsLabelObstacleSettings & obstacleSettings()
Returns the label obstacle settings.
Container of fields for a vector layer.
Definition: qgsfields.h:44
Label on top-right of point.
The QgsVectorLayerLabelProvider class implements a label provider for vector layers.
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:123
Contains settings related to how the label engine places and formats labels for line features (or pol...
#define SIP_INOUT
Definition: qgis_sip.h:71
QgsMapUnitScale repeatDistanceMapUnitScale
Map unit scale for repeating labels for a single feature.
const QgsLabelLineSettings & lineSettings() const
Returns the label line settings, which contain settings related to how the label engine places and fo...
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:55
const QgsCoordinateReferenceSystem & crs
QgsGeometry labelGeometry
A polygon geometry representing the label&#39;s bounds in map coordinates.
QgsCoordinateTransform ct
Contains settings related to how the label engine treats features as obstacles.
void setFormat(const QgsTextFormat &format)
Sets the label text formatting settings, e.g., font settings, buffer settings, etc.
QgsStringReplacementCollection substitutions
Substitution collection for automatic text substitution with labels.
Arranges horizontal candidates scattered throughout a polygon feature. Applies to polygon layers only...
The QgsMapSettings class contains configuration for rendering of the map.
QgsLabelThinningSettings & thinningSettings()
Returns the label thinning settings.
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
Place direction symbols on left/right of label.
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:37
Property
Data definable properties.
const QgsPropertyCollection & dataDefinedProperties() const
Returns a reference to the label&#39;s property collection, used for data defined overrides.
Label on left of point.
Candidates are placed outside of polygon boundaries. Applies to polygon layers only. Since QGIS 3.14.
Offset distance applies from point geometry.
void setDataDefinedProperties(const QgsPropertyCollection &collection)
Sets the label&#39;s property collection, used for data defined overrides.
#define SIP_SKIP
Definition: qgis_sip.h:126
The QgsVectorLayerDiagramProvider class implements support for diagrams within the labeling engine...
QgsLabeling::PolygonPlacementFlags polygonPlacementFlags() const
Returns the polygon placement flags, which dictate how polygon labels can be placed.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
QVector< QgsPointXY > cornerPoints
Arranges candidates in a circle around a point (or centroid of a polygon). Applies to point or polygo...
#define SIP_TRANSFER
Definition: qgis_sip.h:36
Upside-down labels (90 <= angle < 270) are shown upright.
OffsetType
Behavior modifier for label offset and distance, only applies in some label placement modes...
#define SIP_FACTORY
Definition: qgis_sip.h:76
Label below point, slightly right of center.
void setObstacleSettings(const QgsLabelObstacleSettings &settings)
Sets the label obstacle settings.
Offset distance applies from rendered symbol bounds.
const QgsTextFormat & format() const
Returns the label text formatting settings, e.g., font settings, buffer settings, etc...
QMap< int, QgsPropertyDefinition > QgsPropertiesDefinition
Definition of available properties.
Place direction symbols on above label.
Stores the settings for rendering of all diagrams for a layer.
QString wrapChar
Wrapping character string.
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
Definition: qgswkbtypes.h:140
#define Q_NOWARN_DEPRECATED_POP
Definition: qgis.h:798
Placement
Placement modes which determine how label candidates are generated for a feature. ...
#define SIP_PYARGREMOVE
Definition: qgis_sip.h:146
void setPolygonPlacementFlags(QgsLabeling::PolygonPlacementFlags flags)
Sets the polygon placement flags, which dictate how polygon labels can be placed. ...
The QgsLabelingEngine class provides map labeling functionality.
Arranges candidates parallel to a generalised line representing the feature or parallel to a polygon&#39;...
Contains information about the context of a rendering operation.
QgsLabelLineSettings & lineSettings()
Returns the label line settings, which contain settings related to how the label engine places and fo...
The QgsLabelFeature class describes a feature that should be used within the labeling engine...
Label below point, slightly left of center.
QgsMapUnitScale distMapUnitScale
Map unit scale for label feature distance.
Struct for storing maximum and minimum scales for measurements in map units.
A collection of string replacements (specified using QgsStringReplacement objects).
const QgsLabelObstacleSettings & obstacleSettings() const
Returns the label obstacle settings.
#define SIP_OUT
Definition: qgis_sip.h:58
Label on top of point, slightly right of center.
const QgsLabelThinningSettings & thinningSettings() const
Returns the label thinning settings.
This class represents a coordinate reference system (CRS).
Label directly below point.
QFont labelFont
Font which the label is rendered using.
Class for doing transforms between two map coordinate systems.
LabelPosition is a candidate feature label position.
Definition: labelposition.h:55
Label directly above point.
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
Label on right of point.
QgsCallout * callout() const
Returns the label callout renderer, responsible for drawing label callouts.
Class that stores computed placement from labeling engine.
QgsLabelPosition(QgsFeatureId id, double r, const QVector< QgsPointXY > &corners, const QgsRectangle &rect, double w, double h, const QString &layer, const QString &labeltext, const QFont &labelfont, bool upside_down, bool diagram=false, bool pinned=false, const QString &providerId=QString(), const QgsGeometry &labelGeometry=QgsGeometry(), bool isUnplaced=false)
Constructor for QgsLabelPosition.
LinePlacementFlags
Line placement flags, which control how candidates are generated for a linear feature.
Show upside down when rotation is layer- or data-defined.
QString providerID
ID of the associated label provider.
Container for all settings relating to text rendering.
Definition: qgstextformat.h:39
Represents a document consisting of one or more QgsTextBlock objects.
Represents a vector layer which manages a vector based data sets.
Arranges candidates following the curvature of a polygon&#39;s boundary. Applies to polygon layers only...
QgsMapUnitScale labelOffsetMapUnitScale
Map unit scale for label offset.
RenderUnit
Rendering size units.
Definition: qgsunittypes.h:166
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the label&#39;s property collection, used for data defined overrides.
QString fieldName
Name of field (or an expression) to use for label text.
ObstacleType
Valid obstacle types, which affect how features within the layer will act as obstacles for labels...
Arranges candidates scattered throughout a polygon feature. Candidates are rotated to respect the pol...