QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgspointdisplacementrenderer.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgspointdisplacementrenderer.cpp
3  --------------------------------
4  begin : January 26, 2010
5  copyright : (C) 2010 by Marco Hugentobler
6  email : marco at hugis dot net
7  ***************************************************************************/
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 QGSPOINTDISPLACEMENTRENDERER_H
19 #define QGSPOINTDISPLACEMENTRENDERER_H
20 
21 #include "qgis_core.h"
22 #include "qgis.h"
24 
31 {
32  public:
33 
37  enum Placement
38  {
39  Ring,
41  Grid
42  };
43 
48  QgsPointDisplacementRenderer( const QString &labelAttributeName = QString() );
49 
51  void startRender( QgsRenderContext &context, const QgsFields &fields ) override;
52  void stopRender( QgsRenderContext &context ) override;
53  QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context ) override;
54  QSet<QString> usedAttributes( const QgsRenderContext &context ) const override;
55  bool accept( QgsStyleEntityVisitorInterface *visitor ) const override;
56 
58  static QgsFeatureRenderer *create( QDomElement &symbologyElem, const QgsReadWriteContext &context ) SIP_FACTORY;
59 
66  void setCircleWidth( double width ) { mCircleWidth = width; }
67 
73  double circleWidth() const { return mCircleWidth; }
74 
81  void setCircleColor( const QColor &color ) { mCircleColor = color; }
82 
88  QColor circleColor() const { return mCircleColor; }
89 
95  void setCircleRadiusAddition( double distance ) { mCircleRadiusAddition = distance; }
96 
101  double circleRadiusAddition() const { return mCircleRadiusAddition; }
102 
109  void setLabelDistanceFactor( double factor ) { mLabelDistanceFactor = factor; }
110 
116  double labelDistanceFactor() const { return mLabelDistanceFactor; }
117 
123  Placement placement() const { return mPlacement; }
124 
131  void setPlacement( Placement placement ) { mPlacement = placement; }
132 
137  QgsMarkerSymbol *centerSymbol();
138 
144  void setCenterSymbol( QgsMarkerSymbol *symbol SIP_TRANSFER );
145 
151  static QgsPointDisplacementRenderer *convertFromRenderer( const QgsFeatureRenderer *renderer ) SIP_FACTORY;
152 
153  private:
154 #ifdef SIP_RUN
157 #endif
158 
160  std::unique_ptr< QgsMarkerSymbol > mCenterSymbol;
161 
163  Placement mPlacement = Ring;
164 
166  double mCircleWidth = 0.4;
168  QColor mCircleColor;
170  double mCircleRadiusAddition = 0;
172  double mLabelDistanceFactor = 0.5;
173 
174  void drawGroup( QPointF centerPoint, QgsRenderContext &context, const QgsPointDistanceRenderer::ClusteredGroup &group ) const override SIP_FORCE;
175 
176  //helper functions
177  void calculateSymbolAndLabelPositions( QgsSymbolRenderContext &symbolContext, QPointF centerPoint, int nPosition, double symbolDiagonal, QList<QPointF> &symbolPositions, QList<QPointF> &labelShifts, double &circleRadius,
178  double &gridRadius, int &gridSize, QVector<double> &diagonals ) const;
179  void drawCircle( double radiusPainterUnits, QgsSymbolRenderContext &context, QPointF centerPoint, int nSymbols ) const;
180  void drawSymbols( const ClusteredGroup &group, QgsRenderContext &context, const QList<QPointF> &symbolPositions ) const;
181  void drawGrid( int gridSizeUnits, QgsSymbolRenderContext &context,
182  QList<QPointF> pointSymbolPositions, int nSymbols ) const;
183  void centralizeGrid( QList<QPointF> &pointSymbolPositions, double radius, int size ) const;
184 };
185 
186 #endif // QGSPOINTDISPLACEMENTRENDERER_H
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:34
QgsFields
Container of fields for a vector layer.
Definition: qgsfields.h:44
QgsPointDisplacementRenderer::setPlacement
void setPlacement(Placement placement)
Sets the placement method used for dispersing the points.
Definition: qgspointdisplacementrenderer.h:131
QgsPointDisplacementRenderer::placement
Placement placement() const
Returns the placement method used for dispersing the points.
Definition: qgspointdisplacementrenderer.h:123
qgis.h
QgsRenderContext
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:59
QgsStyleEntityVisitorInterface
An interface for classes which can visit style entity (e.g. symbol) nodes (using the visitor pattern)...
Definition: qgsstyleentityvisitor.h:33
QgsPointDisplacementRenderer::setLabelDistanceFactor
void setLabelDistanceFactor(double factor)
Sets a factor for increasing the label distances from the symbol.
Definition: qgspointdisplacementrenderer.h:109
qgspointdistancerenderer.h
QgsPointDisplacementRenderer::setCircleRadiusAddition
void setCircleRadiusAddition(double distance)
Sets a factor for increasing the ring size of displacement groups.
Definition: qgspointdisplacementrenderer.h:95
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsPointDisplacementRenderer::circleWidth
double circleWidth() const
Returns the line width for the displacement group circle in mm.
Definition: qgspointdisplacementrenderer.h:73
QgsSymbolRenderContext
Definition: qgssymbolrendercontext.h:35
QgsMarkerSymbol
A marker symbol type, for rendering Point and MultiPoint geometries.
Definition: qgsmarkersymbol.h:30
QgsFeatureRenderer::clone
virtual QgsFeatureRenderer * clone() const =0
Create a deep copy of this renderer.
QgsPointDistanceRenderer
An abstract base class for distance based point renderers (e.g., clusterer and displacement renderers...
Definition: qgspointdistancerenderer.h:41
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
QgsPointDisplacementRenderer::Ring
@ Ring
Place points in a single ring around group.
Definition: qgspointdisplacementrenderer.h:39
QgsPointDisplacementRenderer::circleRadiusAddition
double circleRadiusAddition() const
Returns the factor for increasing the ring size of displacement groups.
Definition: qgspointdisplacementrenderer.h:101
QgsPointDisplacementRenderer::ConcentricRings
@ ConcentricRings
Place points in concentric rings around group.
Definition: qgspointdisplacementrenderer.h:40
QgsPointDistanceRenderer::ClusteredGroup
QList< QgsPointDistanceRenderer::GroupedFeature > ClusteredGroup
A group of clustered points (ie features within the distance tolerance).
Definition: qgspointdistancerenderer.h:76
QgsPointDisplacementRenderer::Placement
Placement
Placement methods for dispersing points.
Definition: qgspointdisplacementrenderer.h:37
QgsFeatureRenderer
Definition: qgsrenderer.h:101
QgsPointDisplacementRenderer
A renderer that automatically displaces points with the same geographic location.
Definition: qgspointdisplacementrenderer.h:30
SIP_FORCE
#define SIP_FORCE
Definition: qgis_sip.h:131
QgsPointDisplacementRenderer::setCircleColor
void setCircleColor(const QColor &color)
Sets the color used for drawing the displacement group circle.
Definition: qgspointdisplacementrenderer.h:81
QgsPointDisplacementRenderer::labelDistanceFactor
double labelDistanceFactor() const
Returns the factor for label distance from the symbol.
Definition: qgspointdisplacementrenderer.h:116
QgsPointDisplacementRenderer::circleColor
QColor circleColor() const
Returns the color used for drawing the displacement group circle.
Definition: qgspointdisplacementrenderer.h:88