QGIS API Documentation  2.9.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 <QString>
25 #include <QFont>
26 #include <QFontDatabase>
27 #include <QColor>
28 #include <QHash>
29 #include <QList>
30 #include <QRectF>
31 #include "qgspoint.h"
32 #include "qgsmaprenderer.h" // definition of QgsLabelingEngineInterface
33 #include "qgsdiagramrendererv2.h"
34 #include "qgsmapunitscale.h"
35 
36 namespace pal
37 {
38  class Pal;
39  class Layer;
40  class LabelPosition;
41 }
42 
43 class QgsRectangle;
44 class QgsMapToPixel;
45 class QgsFeature;
46 class QgsPalGeometry;
47 class QgsVectorLayer;
48 class QgsDataDefined;
49 class QgsExpression;
50 class QFontMetricsF;
51 class QPainter;
52 class QPicture;
53 class QgsGeometry;
54 class QgsMapRenderer;
56 class QgsLabelSearchTree;
57 class QgsMapSettings;
58 
59 class CORE_EXPORT QgsPalLayerSettings
60 {
61  public:
65 
67  static QgsPalLayerSettings fromLayer( QgsVectorLayer* layer );
68 
69  enum Placement
70  {
71  AroundPoint, // Point / Polygon
72  OverPoint, // Point / Polygon
73  Line, // Line / Polygon
74  Curved, // Line
75  Horizontal, // Polygon
76  Free // Polygon
77  };
78 
80  {
81  OnLine = 1,
82  AboveLine = 2,
83  BelowLine = 4,
84  MapOrientation = 8
85  };
86 
88  {
97  QuadrantBelowRight
98  };
99 
101  {
102  Upright, // upside-down labels (90 <= angle < 270) are shown upright
103  ShowDefined, // show upside down when rotation is layer- or data-defined
104  ShowAll // show upside down for all labels, including dynamic ones
105  };
106 
108  {
109  SymbolLeftRight, // place direction symbols on left/right of label
110  SymbolAbove, // place direction symbols on above label
111  SymbolBelow // place direction symbols on below label
112  };
113 
115  {
116  MultiLeft = 0,
119  MultiFollowPlacement /*< Alignment follows placement of label, eg labels to the left of a feature
120  will be drawn with right alignment*/
121  };
122 
124  {
125  ShapeRectangle = 0,
129  ShapeSVG
130  };
131 
132  enum SizeType
133  {
134  SizeBuffer = 0,
136  SizePercent
137  };
138 
140  {
141  RotationSync = 0,
143  RotationFixed
144  };
145 
147  enum SizeUnit
148  {
149  Points = 0,
150  MM,
152  Percent
153  };
154 
156  {
157  ShadowLowest = 0,
160  ShadowShape
161  };
162 
163  // update mDataDefinedNames QMap in constructor when adding/deleting enum value
165  {
166  // text style
167  Size = 0,
168  Bold = 1,
169  Italic = 2,
170  Underline = 3,
171  Color = 4,
172  Strikeout = 5,
173  Family = 6,
174  FontStyle = 21,
175  FontSizeUnit = 22,
176  FontTransp = 18,
177  FontCase = 27,
178  FontLetterSpacing = 28,
179  FontWordSpacing = 29,
180  FontBlendMode = 30,
181 
182  // text formatting
183  MultiLineWrapChar = 31,
184  MultiLineHeight = 32,
185  MultiLineAlignment = 33,
186  DirSymbDraw = 34,
187  DirSymbLeft = 35,
188  DirSymbRight = 36,
189  DirSymbPlacement = 37,
190  DirSymbReverse = 38,
191  NumFormat = 39,
192  NumDecimals = 40,
193  NumPlusSign = 41,
194 
195  // text buffer
196  BufferDraw = 42,
197  BufferSize = 7,
198  BufferUnit = 43,
199  BufferColor = 8,
200  BufferTransp = 19,
201  BufferJoinStyle = 44,
202  BufferBlendMode = 45,
203 
204  // background
205  ShapeDraw = 46,
206  ShapeKind = 47,
207  ShapeSVGFile = 48,
208  ShapeSizeType = 49,
209  ShapeSizeX = 50,
210  ShapeSizeY = 85,
211  ShapeSizeUnits = 51,
212  ShapeRotationType = 52,
213  ShapeRotation = 53,
214  ShapeOffset = 54,
215  ShapeOffsetUnits = 55,
216  ShapeRadii = 56,
217  ShapeRadiiUnits = 57,
218  ShapeTransparency = 63,
219  ShapeBlendMode = 64,
220  ShapeFillColor = 58,
221  ShapeBorderColor = 59,
222  ShapeBorderWidth = 60,
223  ShapeBorderWidthUnits = 61,
224  ShapeJoinStyle = 62,
225 
226  // drop shadow
227  ShadowDraw = 65,
228  ShadowUnder = 66,
229  ShadowOffsetAngle = 67,
230  ShadowOffsetDist = 68,
231  ShadowOffsetUnits = 69,
232  ShadowRadius = 70,
233  ShadowRadiusUnits = 71,
234  ShadowTransparency = 72,
235  ShadowScale = 73,
236  ShadowColor = 74,
237  ShadowBlendMode = 75,
238 
239  // placement
240  CentroidWhole = 76,
241  OffsetQuad = 77,
242  OffsetXY = 78,
243  OffsetUnits = 80,
244  LabelDistance = 13,
245  DistanceUnits = 81,
246  OffsetRotation = 82,
247  CurvedCharAngleInOut = 83,
248  // (data defined only)
249  PositionX = 9, //x-coordinate data defined label position
250  PositionY = 10, //y-coordinate data defined label position
251  Hali = 11, //horizontal alignment for data defined label position (Left, Center, Right)
252  Vali = 12, //vertical alignment for data defined label position (Bottom, Base, Half, Cap, Top)
253  Rotation = 14, //data defined rotation
254  RepeatDistance = 84,
255  RepeatDistanceUnit = 86,
256 
257  // rendering
258  ScaleVisibility = 23,
259  MinScale = 16,
260  MaxScale = 17,
261  FontLimitPixel = 24,
262  FontMinPixel = 25,
263  FontMaxPixel = 26,
264  // (data defined only)
265  Show = 15,
266  AlwaysShow = 20
267  };
268 
269  // whether to label this layer
270  bool enabled;
271 
272  //-- text style
273 
274  QString fieldName;
275 
279 
282  QgsExpression* getLabelExpression();
283 
284  QFont textFont;
285  QString textNamedStyle;
286  bool fontSizeInMapUnits; //true if font size is in map units (otherwise in points)
287  QgsMapUnitScale fontSizeMapUnitScale; // scale range for map units for font size
288  QColor textColor;
290  QPainter::CompositionMode blendMode;
292 
293  //-- text formatting
294 
295  QString wrapChar;
296  double multilineHeight; //0.0 to 10.0, leading between lines as multiplyer of line height
297  MultiLineAlign multilineAlign; // horizontal alignment of multi-line labels
298 
299  // Adds '<' or '>', or user-defined symbol to the label string pointing to the
300  // direction of the line / polygon ring
301  // Works only if Placement == Line
305  DirectionSymbols placeDirectionSymbol; // whether to place left/right, above or below label
307 
309  int decimals;
310  bool plusSign;
311 
312  //-- text buffer
313 
315  double bufferSize; // buffer size
316  bool bufferSizeInMapUnits; //true if buffer is in map units (otherwise in mm)
317  QgsMapUnitScale bufferSizeMapUnitScale; // scale range for map units for buffer size
318  QColor bufferColor;
319  bool bufferNoFill; //set interior of buffer to 100% transparent
321  Qt::PenJoinStyle bufferJoinStyle;
322  QPainter::CompositionMode bufferBlendMode;
323 
324  //-- shape background
325 
326  bool shapeDraw;
328  QString shapeSVGFile;
330  QPointF shapeSize;
335  QPointF shapeOffset;
338  QPointF shapeRadii;
342  QPainter::CompositionMode shapeBlendMode;
348  Qt::PenJoinStyle shapeJoinStyle;
349 
350  //-- drop shadow
351 
359  double shadowRadius;
365  QColor shadowColor;
366  QPainter::CompositionMode shadowBlendMode;
367 
368  //-- placement
369 
371  unsigned int placementFlags;
372 
373  bool centroidWhole; // whether centroid calculated from whole or visible polygon
374  bool centroidInside; // whether centroid-point calculated must be inside polygon
375  double dist; // distance from the feature (in mm)
376  bool distInMapUnits; //true if distance is in map units (otherwise in mm)
378 
382 
383  // offset labels of point/centroid features default to center
384  // move label to quadrant: left/down, don't move, right/up (-1, 0, 1)
386 
387  double xOffset; // offset from point in mm or map units
388  double yOffset; // offset from point in mm or map units
389  bool labelOffsetInMapUnits; //true if label offset is in map units (otherwise in mm)
391  double angleOffset; // rotation applied to offset labels
392  bool preserveRotation; // preserve predefined rotation data during label pin/unpin operations
393 
394  double maxCurvedCharAngleIn; // maximum angle between inside curved label characters (defaults to 20.0, range 20.0 to 60.0)
395  double maxCurvedCharAngleOut; // maximum angle between outside curved label characters (defaults to -20.0, range -20.0 to -95.0)
396 
397  int priority; // 0 = low, 10 = high
398 
399  //-- rendering
400 
402  int scaleMin;
403  int scaleMax;
404 
405  bool fontLimitPixelSize; // true is label should be limited by fontMinPixelSize/fontMaxPixelSize
406  int fontMinPixelSize; // minimum pixel size for showing rendered map unit labels (1 - 1000)
407  int fontMaxPixelSize; // maximum pixel size for showing rendered map unit labels (1 - 10000)
408 
409  bool displayAll; // if true, all features will be labelled even though overlaps occur
410  unsigned int upsidedownLabels; // whether, or how, to show upsidedown labels
411 
412  bool labelPerPart; // whether to label every feature's part or only the biggest one
414 
415  bool limitNumLabels; // whether to limit the number of labels to be drawn
416  int maxNumLabels; // maximum number of labels to be drawn
417 
418  double minFeatureSize; // minimum feature size to be labelled (in mm)
419  bool obstacle; // whether features for layer are obstacles to labels of other layers
420 
421  //-- scale factors
422  double vectorScaleFactor; //scale factor painter units->pixels
423  double rasterCompressFactor; //pixel resolution scale factor
424 
425  // called from register feature hook
426  void calculateLabelSize( const QFontMetricsF* fm, QString text, double& labelX, double& labelY, QgsFeature* f = 0 );
427 
428  // implementation of register feature hook
429  void registerFeature( QgsFeature& f, const QgsRenderContext& context, QString dxfLayer );
430 
431  void readFromLayer( QgsVectorLayer* layer );
432  void writeToLayer( QgsVectorLayer* layer );
433 
438 
442  void setDataDefinedProperty( QgsPalLayerSettings::DataDefinedProperties p,
443  bool active, bool useExpr, const QString& expr, const QString& field );
444 
446  void removeDataDefinedProperty( QgsPalLayerSettings::DataDefinedProperties p );
447 
451  QString updateDataDefinedString( const QString& value );
452 
456  QMap<QString, QString> dataDefinedMap( QgsPalLayerSettings::DataDefinedProperties p ) const;
457 
462  QVariant dataDefinedValue( QgsPalLayerSettings::DataDefinedProperties p, QgsFeature& f, const QgsFields& fields ) const;
463 
468  bool dataDefinedEvaluate( QgsPalLayerSettings::DataDefinedProperties p, QVariant& exprVal ) const;
469 
472  bool dataDefinedIsActive( QgsPalLayerSettings::DataDefinedProperties p ) const;
473 
476  bool dataDefinedUseExpression( QgsPalLayerSettings::DataDefinedProperties p ) const;
477 
480  QMap< QgsPalLayerSettings::DataDefinedProperties, QgsDataDefined* > dataDefinedProperties;
481 
482 
491  int sizeToPixel( double size, const QgsRenderContext& c, SizeUnit unit, bool rasterfactor = false, const QgsMapUnitScale& mapUnitScale = QgsMapUnitScale() ) const;
492 
501  double scaleToPixelContext( double size, const QgsRenderContext& c, SizeUnit unit, bool rasterfactor = false, const QgsMapUnitScale& mapUnitScale = QgsMapUnitScale() ) const;
502 
507  QMap<QgsPalLayerSettings::DataDefinedProperties, QPair<QString, int> > dataDefinedNames() const { return mDataDefinedNames; }
508 
509  // temporary stuff: set when layer gets prepared or labeled
510  // NOTE: not in Python binding
517  QgsPoint ptZero, ptOne;
518  QList<QgsPalGeometry*> geometries;
520  int mFeaturesToLabel; // total features that will probably be labeled, may be less (figured before PAL)
521  int mFeatsSendingToPal; // total features tested for sending into PAL (relative to maxNumLabels)
522  int mFeatsRegPal; // number of features registered in PAL, when using limitNumLabels
523 
526 
527  bool showingShadowRects; // whether to show debug rectangles for drop shadows
528 
529  private:
530  void readDataDefinedPropertyMap( QgsVectorLayer* layer,
532  QgsDataDefined* > & propertyMap );
533  void writeDataDefinedPropertyMap( QgsVectorLayer* layer,
535  QgsDataDefined* > & propertyMap );
536  void readDataDefinedProperty( QgsVectorLayer* layer,
539  QgsDataDefined* > & propertyMap );
540 
541  // convenience data defined evaluation function
542  bool dataDefinedValEval( const QString& valType,
544  QVariant& exprVal );
545 
546  void parseTextStyle( QFont& labelFont,
548  const QgsRenderContext& context );
549 
550  void parseTextBuffer();
551 
552  void parseTextFormatting();
553 
554  void parseShapeBackground();
555 
556  void parseDropShadow();
557 
560  bool checkMinimumSizeMM( const QgsRenderContext& ct, QgsGeometry* geom, double minSize ) const;
561 
562 
563  QMap<DataDefinedProperties, QVariant> dataDefinedValues;
564  QgsExpression* expression;
565  QMap<QgsPalLayerSettings::DataDefinedProperties, QPair<QString, int> > mDataDefinedNames;
566 
567  QFontDatabase mFontDB;
568 };
569 
570 class CORE_EXPORT QgsLabelCandidate
571 {
572  public:
573  QgsLabelCandidate( QRectF r, double c ): rect( r ), cost( c ) {}
574 
575  QRectF rect;
576  double cost;
577 };
578 
583 class CORE_EXPORT QgsLabelComponent
584 {
585  public:
587  : mText( QString() )
588  , mOrigin( QgsPoint() )
589  , mUseOrigin( false )
590  , mRotation( 0.0 )
591  , mRotationOffset( 0.0 )
592  , mUseRotation( false )
593  , mCenter( QgsPoint() )
594  , mUseCenter( false )
595  , mSize( QgsPoint() )
596  , mOffset( QgsPoint() )
597  , mPicture( 0 )
598  , mPictureBuffer( 0.0 )
599  , mDpiRatio( 1.0 )
600  {}
601 
602  // methods
603 
604  const QString& text() const { return mText; }
605  void setText( const QString& text ) { mText = text; }
606 
607  const QgsPoint& origin() const { return mOrigin; }
608  void setOrigin( const QgsPoint& point ) { mOrigin = point; }
609 
610  bool useOrigin() const { return mUseOrigin; }
611  void setUseOrigin( const bool use ) { mUseOrigin = use; }
612 
613  double rotation() const { return mRotation; }
614  void setRotation( const double rotation ) { mRotation = rotation; }
615 
616  double rotationOffset() const { return mRotationOffset; }
617  void setRotationOffset( const double rotation ) { mRotationOffset = rotation; }
618 
619  bool useRotation() const { return mUseRotation; }
620  void setUseRotation( const bool use ) { mUseRotation = use; }
621 
622  const QgsPoint& center() const { return mCenter; }
623  void setCenter( const QgsPoint& point ) { mCenter = point; }
624 
625  bool useCenter() const { return mUseCenter; }
626  void setUseCenter( const bool use ) { mUseCenter = use; }
627 
628  const QgsPoint& size() const { return mSize; }
629  void setSize( const QgsPoint& point ) { mSize = point; }
630 
631  const QgsPoint& offset() const { return mOffset; }
632  void setOffset( const QgsPoint& point ) { mOffset = point; }
633 
634  const QPicture* picture() const { return mPicture; }
635  void setPicture( QPicture* picture ) { mPicture = picture; }
636 
637  double pictureBuffer() const { return mPictureBuffer; }
638  void setPictureBuffer( const double buffer ) { mPictureBuffer = buffer; }
639 
640  double dpiRatio() const { return mDpiRatio; }
641  void setDpiRatio( const double ratio ) { mDpiRatio = ratio; }
642 
643  private:
644  // current label component text,
645  // e.g. single line in a multi-line label or charcater in curved labeling
646  QString mText;
647  // current origin point for painting (generally current painter rotation point)
648  QgsPoint mOrigin;
649  // whether to translate the painter to supplied origin
650  bool mUseOrigin;
651  // any rotation to be applied to painter (in radians)
652  double mRotation;
653  // any rotation to be applied to painter (in radians) after initial rotation
654  double mRotationOffset;
655  // whether to use the rotation to rotate the painter
656  bool mUseRotation;
657  // current center point of label compnent, after rotation
658  QgsPoint mCenter;
659  // whether to translate the painter to supplied origin based upon center
660  bool mUseCenter;
661  // width and height of label component, transformed and ready for painting
662  QgsPoint mSize;
663  // any translation offsets to be applied before painting, transformed and ready for painting
664  QgsPoint mOffset;
665 
666  // a stored QPicture of painting for the component
667  QPicture* mPicture;
668  // buffer for component to accommodate graphic items ignored by QPicture,
669  // e.g. half-width of an applied QPen, which would extend beyond boundingRect() of QPicture
670  double mPictureBuffer;
671 
672  // a ratio of native painter dpi and that of rendering context's painter
673  double mDpiRatio;
674 };
675 
676 
681 class CORE_EXPORT QgsLabelingResults
682 {
683  public:
686 
688  QList<QgsLabelPosition> labelsAtPosition( const QgsPoint& p ) const;
690  QList<QgsLabelPosition> labelsWithinRect( const QgsRectangle& r ) const;
691 
692  private:
693  QgsLabelingResults( const QgsLabelingResults& ) {} // no copying allowed
694 
695  QgsLabelSearchTree* mLabelSearchTree;
696 
697  friend class QgsPalLabeling;
698 };
699 
701 class CORE_EXPORT QgsPalLabeling : public QgsLabelingEngineInterface
702 {
703  public:
705  {
706  LabelText = 0,
710  LabelShadow
711  };
712 
713  QgsPalLabeling();
714  ~QgsPalLabeling();
715 
716  QgsPalLayerSettings& layer( const QString& layerName ) override;
717 
718  void numCandidatePositions( int& candPoint, int& candLine, int& candPolygon );
719  void setNumCandidatePositions( int candPoint, int candLine, int candPolygon );
720 
721  enum Search { Chain, Popmusic_Tabu, Popmusic_Chain, Popmusic_Tabu_Chain, Falp };
722 
723  void setSearchMethod( Search s );
724  Search searchMethod() const;
725 
726  bool isShowingCandidates() const { return mShowingCandidates; }
727  void setShowingCandidates( bool showing ) { mShowingCandidates = showing; }
728  const QList<QgsLabelCandidate>& candidates() { return mCandidates; }
729 
730  bool isShowingShadowRectangles() const { return mShowingShadowRects; }
731  void setShowingShadowRectangles( bool showing ) { mShowingShadowRects = showing; }
732 
733  bool isShowingAllLabels() const { return mShowingAllLabels; }
734  void setShowingAllLabels( bool showing ) { mShowingAllLabels = showing; }
735 
736  bool isShowingPartialsLabels() const { return mShowingPartialsLabels; }
737  void setShowingPartialsLabels( bool showing ) { mShowingPartialsLabels = showing; }
738 
740  bool isDrawingOutlineLabels() const { return mDrawOutlineLabels; }
741  void setDrawingOutlineLabels( bool outline ) { mDrawOutlineLabels = outline; }
742 
743  // implemented methods from labeling engine interface
744 
747  Q_DECL_DEPRECATED virtual void init( QgsMapRenderer* mr ) override;
749  virtual void init( const QgsMapSettings& mapSettings ) override;
751  virtual bool willUseLayer( QgsVectorLayer* layer ) override;
752 
755  static bool staticWillUseLayer( QgsVectorLayer* layer );
756  static bool staticWillUseLayer( const QString& layerID );
757 
759  virtual void clearActiveLayers() override;
761  virtual void clearActiveLayer( const QString& layerID ) override;
763  virtual int prepareLayer( QgsVectorLayer* layer, QStringList &attrNames, QgsRenderContext& ctx ) override;
765  virtual int addDiagramLayer( QgsVectorLayer* layer, const QgsDiagramLayerSettings *s ) override;
767  virtual void registerFeature( const QString& layerID, QgsFeature& feat, const QgsRenderContext& context = QgsRenderContext(), QString dxfLayer = QString::null ) override;
768  virtual void registerDiagramFeature( const QString& layerID, QgsFeature& feat, const QgsRenderContext& context = QgsRenderContext() ) override;
770  virtual void drawLabeling( QgsRenderContext& context ) override;
772  virtual void exit() override;
773 
776  Q_DECL_DEPRECATED virtual QList<QgsLabelPosition> labelsAtPosition( const QgsPoint& p ) override;
779  Q_DECL_DEPRECATED virtual QList<QgsLabelPosition> labelsWithinRect( const QgsRectangle& r ) override;
780 
783  QgsLabelingResults* takeResults();
784 
786  virtual QgsLabelingEngineInterface* clone() override;
787 
789  void drawLabelCandidateRect( pal::LabelPosition* lp, QPainter* painter, const QgsMapToPixel* xform );
792  virtual void drawLabel( pal::LabelPosition* label, QgsRenderContext& context, QgsPalLayerSettings& tmpLyr, DrawLabelType drawType, double dpiRatio = 1.0 );
793 
794  static void drawLabelBuffer( QgsRenderContext& context,
795  const QgsLabelComponent &component,
796  const QgsPalLayerSettings& tmpLyr );
797 
798  static void drawLabelBackground( QgsRenderContext& context,
799  QgsLabelComponent component,
800  const QgsPalLayerSettings& tmpLyr );
801 
802  static void drawLabelShadow( QgsRenderContext &context,
803  const QgsLabelComponent &component,
804  const QgsPalLayerSettings& tmpLyr );
805 
807  void loadEngineSettings();
808  void saveEngineSettings();
809  void clearEngineSettings();
811  Q_DECL_DEPRECATED bool isStoredWithProject() const { return true; }
813  Q_DECL_DEPRECATED void setStoredWithProject( bool store ) { Q_UNUSED( store ); }
814 
824  static QgsGeometry* prepareGeometry( QgsGeometry *geometry, const QgsRenderContext &context, const QgsCoordinateTransform *ct, double minSize = 0, QgsGeometry *clipGeometry = 0 );
825 
834  static bool geometryRequiresPreparation( QgsGeometry *geometry, const QgsRenderContext &context, const QgsCoordinateTransform *ct, QgsGeometry *clipGeometry = 0 );
835 
836  protected:
837  // update temporary QgsPalLayerSettings with any data defined text style values
838  void dataDefinedTextStyle( QgsPalLayerSettings& tmpLyr,
839  const QMap< QgsPalLayerSettings::DataDefinedProperties, QVariant >& ddValues );
840 
841  // update temporary QgsPalLayerSettings with any data defined text formatting values
842  void dataDefinedTextFormatting( QgsPalLayerSettings& tmpLyr,
843  const QMap< QgsPalLayerSettings::DataDefinedProperties, QVariant >& ddValues );
844 
845  // update temporary QgsPalLayerSettings with any data defined text buffer values
846  void dataDefinedTextBuffer( QgsPalLayerSettings& tmpLyr,
847  const QMap< QgsPalLayerSettings::DataDefinedProperties, QVariant >& ddValues );
848 
849  // update temporary QgsPalLayerSettings with any data defined shape background values
850  void dataDefinedShapeBackground( QgsPalLayerSettings& tmpLyr,
851  const QMap< QgsPalLayerSettings::DataDefinedProperties, QVariant >& ddValues );
852 
853  // update temporary QgsPalLayerSettings with any data defined drop shadow values
854  void dataDefinedDropShadow( QgsPalLayerSettings& tmpLyr,
855  const QMap< QgsPalLayerSettings::DataDefinedProperties, QVariant >& ddValues );
856 
857  void deleteTemporaryData();
858 
866  static bool checkMinimumSizeMM( const QgsRenderContext &context, QgsGeometry *geom, double minSize );
867 
868  // hashtable of layer settings, being filled during labeling (key = layer ID)
869  QHash<QString, QgsPalLayerSettings> mActiveLayers;
870  // hashtable of active diagram layers (key = layer ID)
871  QHash<QString, QgsDiagramLayerSettings> mActiveDiagramLayers;
873 
875  int mCandPoint, mCandLine, mCandPolygon;
877 
879 
880  // list of candidates from last labeling
881  QList<QgsLabelCandidate> mCandidates;
883  bool mShowingAllLabels; // whether to avoid collisions or not
884  bool mShowingShadowRects; // whether to show debugging rectangles for drop shadows
885  bool mShowingPartialsLabels; // whether to avoid partials labels or not
886  bool mDrawOutlineLabels; // whether to draw labels as text or outlines
887 
889 
890 };
892 
893 
894 #endif // QGSPALLABELING_H
virtual void exit()=0
called when we're done with rendering
Class for parsing and evaluation of expressions (formerly called "search strings").
Definition: qgsexpression.h:86
void setShowingCandidates(bool showing)
virtual void clearActiveLayers()=0
clears all PAL layer settings for registered layers
virtual Q_DECL_DEPRECATED void init(QgsMapRenderer *mp)=0
called when we're going to start with rendering
A rectangle specified with double values.
Definition: qgsrectangle.h:35
QgsMapUnitScale shapeSizeMapUnitScale
A container class for data source field mapping or expression.
QgsMapUnitScale shadowRadiusMapUnitScale
pal::Layer * palLayer
virtual int prepareLayer(QgsVectorLayer *layer, QStringList &attrNames, QgsRenderContext &ctx)=0
called when starting rendering of a layer
void setOrigin(const QgsPoint &point)
const QgsMapSettings * mMapSettings
pal::Pal * mPal
const QString & text() const
virtual void clearActiveLayer(const QString &layerID)=0
clears data defined objects from PAL layer settings for a registered layer
virtual QgsPalLayerSettings & layer(const QString &layerName)=0
returns PAL layer settings for a registered layer
A class to query the labeling structure at a given point (small wraper around pal RTree class) ...
QColor outline
Definition: qgssvgcache.cpp:82
void setShowingPartialsLabels(bool showing)
QPainter::CompositionMode bufferBlendMode
A layer of spacial entites.
Definition: layer.h:65
double rotationOffset() const
QgsMapUnitScale shadowOffsetMapUnitScale
const QgsPoint & size() const
bool mShowingPartialsLabels
#define Q_NOWARN_DEPRECATED_PUSH
Definition: qgis.h:461
QuadrantPosition quadOffset
bool useRotation() const
void setUseOrigin(const bool use)
Pal main class.
Definition: pal.h:126
Container of fields for a vector layer.
Definition: qgsfield.h:172
void setUseCenter(const bool use)
QgsMapUnitScale repeatDistanceMapUnitScale
MultiLineAlign multilineAlign
virtual int addDiagramLayer(QgsVectorLayer *layer, const QgsDiagramLayerSettings *s)
adds a diagram layer to the labeling engine
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:113
bool useCenter() const
const QgsPoint & origin() const
double dpiRatio() const
A non GUI class for rendering a map layer set onto a QPainter.
virtual Q_DECL_DEPRECATED QList< QgsLabelPosition > labelsWithinRect(const QgsRectangle &r)=0
return infos about labels within a given (map) rectangle
const QgsPoint & center() const
void setRotationOffset(const double rotation)
Qt::PenJoinStyle bufferJoinStyle
QgsMapUnitScale fontSizeMapUnitScale
const QgsPoint & offset() const
The QgsMapSettings class contains configuration for rendering of the map.
QgsMapUnitScale shapeBorderWidthMapUnitScale
QgsGeometry * extentGeom
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:34
double rotation() const
Q_DECL_DEPRECATED void setStoredWithProject(bool store)
void setRotation(const double rotation)
QList< QgsPalGeometry * > geometries
const QgsCoordinateTransform * ct
bool useOrigin() const
QgsMapUnitScale shapeRadiiMapUnitScale
virtual Q_DECL_DEPRECATED QList< QgsLabelPosition > labelsAtPosition(const QgsPoint &p)=0
return infos about labels at a given (map) position
const QPicture * picture() const
QgsPalLayerSettings mInvalidLayerSettings
virtual QgsLabelingEngineInterface * clone()=0
called when passing engine among map renderers
SizeUnit shapeBorderWidthUnits
QPainter::CompositionMode blendMode
QHash< QString, QgsDiagramLayerSettings > mActiveDiagramLayers
Q_DECL_DEPRECATED bool isStoredWithProject() const
struct pal::_chain Chain
void setCenter(const QgsPoint &point)
const QgsMapToPixel * xform
QMap< QgsPalLayerSettings::DataDefinedProperties, QgsDataDefined * > dataDefinedProperties
Map of current data defined properties.
bool isShowingPartialsLabels() const
void setText(const QString &text)
QgsMapUnitScale bufferSizeMapUnitScale
QgsFeature * mCurFeat
QPainter::CompositionMode shapeBlendMode
SizeUnit
Units used for option sizes, before being converted to rendered sizes.
const QList< QgsLabelCandidate > & candidates()
A class to represent a point.
Definition: qgspoint.h:63
QHash< QString, QgsPalLayerSettings > mActiveLayers
Qt::PenJoinStyle shapeJoinStyle
unsigned int upsidedownLabels
void setDpiRatio(const double ratio)
unsigned int placementFlags
#define Q_NOWARN_DEPRECATED_POP
Definition: qgis.h:462
bool isShowingCandidates() const
void setDrawingOutlineLabels(bool outline)
Contains information about the context of a rendering operation.
void setShowingShadowRectangles(bool showing)
void setPicture(QPicture *picture)
void setOffset(const QgsPoint &point)
virtual void registerFeature(const QString &layerID, QgsFeature &feat, const QgsRenderContext &context=QgsRenderContext(), QString dxfLayer=QString::null)=0
called for every feature
QgsMapUnitScale distMapUnitScale
virtual void drawLabeling(QgsRenderContext &context)=0
called when the map is drawn and labels should be placed
Class for doing transforms between two map coordinate systems.
QgsLabelCandidate(QRectF r, double c)
LabelPosition is a candidate feature label position.
Definition: labelposition.h:53
double pictureBuffer() const
QPainter::CompositionMode shadowBlendMode
bool isExpression
Is this label made from a expression string eg FieldName || 'mm'.
void setSize(const QgsPoint &point)
Class that stores computed placement from labeling engine.
virtual bool willUseLayer(QgsVectorLayer *layer)=0
called to find out whether the layer is used for labeling
bool isShowingAllLabels() const
void setShowingAllLabels(bool showing)
QMap< QgsPalLayerSettings::DataDefinedProperties, QPair< QString, int > > dataDefinedNames() const
Map of data defined enum to names and old-style indecies The QPair contains a new string for layer pr...
bool isShowingShadowRectangles() const
QgsMapUnitScale shapeOffsetMapUnitScale
QList< QgsLabelCandidate > mCandidates
Labeling engine interface.
void setPictureBuffer(const double buffer)
bool isDrawingOutlineLabels() const
void setUseRotation(const bool use)
virtual void registerDiagramFeature(const QString &layerID, QgsFeature &feat, const QgsRenderContext &context=QgsRenderContext())
called for every diagram feature
Represents a vector layer which manages a vector based data sets.
double size
Definition: qgssvgcache.cpp:77
Maintains current state of more grainular and temporal values when creating/painting component parts ...
RotationType shapeRotationType
QgsMapUnitScale labelOffsetMapUnitScale
QgsLabelingResults * mResults
const QgsFields * mCurFields
DirectionSymbols placeDirectionSymbol