QGIS API Documentation  3.8.0-Zanzibar (11aff65)
qgspointdisplacementrenderer.cpp
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 
19 #include "qgssymbollayerutils.h"
20 #include "qgsfontutils.h"
21 #include "qgspainteffectregistry.h"
22 #include "qgspainteffect.h"
24 
25 #include <QPainter>
26 #include <cmath>
27 
29  : QgsPointDistanceRenderer( QStringLiteral( "pointDisplacement" ), labelAttributeName )
30  , mCircleColor( QColor( 125, 125, 125 ) )
31 {
32  mCenterSymbol.reset( new QgsMarkerSymbol() );
33 }
34 
36 {
38  if ( mRenderer )
39  r->setEmbeddedRenderer( mRenderer->clone() );
40  r->setCircleWidth( mCircleWidth );
41  r->setCircleColor( mCircleColor );
44  r->setPlacement( mPlacement );
45  r->setCircleRadiusAddition( mCircleRadiusAddition );
46  r->setLabelDistanceFactor( mLabelDistanceFactor );
51  if ( mCenterSymbol )
52  {
53  r->setCenterSymbol( mCenterSymbol->clone() );
54  }
55  copyRendererData( r );
56  return r;
57 }
58 
59 void QgsPointDisplacementRenderer::drawGroup( QPointF centerPoint, QgsRenderContext &context, const ClusteredGroup &group )
60 {
61 
62  //calculate max diagonal size from all symbols in group
63  double diagonal = 0;
64  QVector<double> diagonals( group.size() );
65  double currentDiagonal;
66 
67  int groupPosition = 0;
68  for ( const GroupedFeature &feature : group )
69  {
70  if ( QgsMarkerSymbol *symbol = feature.symbol() )
71  {
72  currentDiagonal = M_SQRT2 * symbol->size( context );
73  diagonals[groupPosition] = currentDiagonal;
74  diagonal = std::max( diagonal, currentDiagonal );
75 
76  }
77  else
78  {
79  diagonals[groupPosition] = 0.0;
80  }
81  groupPosition++;
82  }
83 
84  QgsSymbolRenderContext symbolContext( context, QgsUnitTypes::RenderMillimeters, 1.0, false );
85 
86  QList<QPointF> symbolPositions;
87  QList<QPointF> labelPositions;
88  double circleRadius = -1.0;
89  double gridRadius = -1.0;
90  int gridSize = -1;
91 
92  calculateSymbolAndLabelPositions( symbolContext, centerPoint, group.size(), diagonal, symbolPositions, labelPositions, circleRadius, gridRadius, gridSize, diagonals );
93 
94  //only draw circle/grid if there's a pen present - otherwise skip drawing transparent grids
95  if ( mCircleColor.isValid() && mCircleColor.alpha() > 0 )
96  {
97  //draw circle
98  if ( circleRadius > 0 )
99  drawCircle( circleRadius, symbolContext, centerPoint, group.size() );
100  //draw grid
101  else
102  drawGrid( gridSize, symbolContext, symbolPositions, group.size() );
103  }
104 
105  if ( group.size() > 1 )
106  {
107  //draw mid point
108  QgsFeature firstFeature = group.at( 0 ).feature;
109  if ( mCenterSymbol )
110  {
111  mCenterSymbol->renderPoint( centerPoint, &firstFeature, context, -1, false );
112  }
113  else
114  {
115  const double rectSize = symbolContext.renderContext().convertToPainterUnits( 1, QgsUnitTypes::RenderMillimeters );
116  context.painter()->drawRect( QRectF( centerPoint.x() - rectSize, centerPoint.y() - rectSize, rectSize * 2, rectSize * 2 ) );
117  }
118  }
119 
120  //draw symbols on the circle
121  drawSymbols( group, context, symbolPositions );
122  //and also the labels
123  if ( mLabelIndex >= 0 )
124  {
125  drawLabels( centerPoint, symbolContext, labelPositions, group );
126  }
127 }
128 
129 
131 {
132  if ( mCenterSymbol )
133  {
134  mCenterSymbol->startRender( context, fields );
135  }
136 
137  QgsPointDistanceRenderer::startRender( context, fields );
138 }
139 
141 {
143  if ( mCenterSymbol )
144  {
145  mCenterSymbol->stopRender( context );
146  }
147 }
148 
150 {
152  r->setLabelAttributeName( symbologyElem.attribute( QStringLiteral( "labelAttributeName" ) ) );
153  QFont labelFont;
154  if ( !QgsFontUtils::setFromXmlChildNode( labelFont, symbologyElem, QStringLiteral( "labelFontProperties" ) ) )
155  {
156  labelFont.fromString( symbologyElem.attribute( QStringLiteral( "labelFont" ), QString() ) );
157  }
158  r->setLabelFont( labelFont );
159  r->setPlacement( static_cast< Placement >( symbologyElem.attribute( QStringLiteral( "placement" ), QStringLiteral( "0" ) ).toInt() ) );
160  r->setCircleWidth( symbologyElem.attribute( QStringLiteral( "circleWidth" ), QStringLiteral( "0.4" ) ).toDouble() );
161  r->setCircleColor( QgsSymbolLayerUtils::decodeColor( symbologyElem.attribute( QStringLiteral( "circleColor" ), QString() ) ) );
162  r->setLabelColor( QgsSymbolLayerUtils::decodeColor( symbologyElem.attribute( QStringLiteral( "labelColor" ), QString() ) ) );
163  r->setCircleRadiusAddition( symbologyElem.attribute( QStringLiteral( "circleRadiusAddition" ), QStringLiteral( "0.0" ) ).toDouble() );
164  r->setLabelDistanceFactor( symbologyElem.attribute( QStringLiteral( "labelDistanceFactor" ), QStringLiteral( "0.5" ) ).toDouble() );
165  r->setMinimumLabelScale( symbologyElem.attribute( QStringLiteral( "maxLabelScaleDenominator" ), QStringLiteral( "-1" ) ).toDouble() );
166  r->setTolerance( symbologyElem.attribute( QStringLiteral( "tolerance" ), QStringLiteral( "0.00001" ) ).toDouble() );
167  r->setToleranceUnit( QgsUnitTypes::decodeRenderUnit( symbologyElem.attribute( QStringLiteral( "toleranceUnit" ), QStringLiteral( "MapUnit" ) ) ) );
168  r->setToleranceMapUnitScale( QgsSymbolLayerUtils::decodeMapUnitScale( symbologyElem.attribute( QStringLiteral( "toleranceUnitScale" ) ) ) );
169 
170  //look for an embedded renderer <renderer-v2>
171  QDomElement embeddedRendererElem = symbologyElem.firstChildElement( QStringLiteral( "renderer-v2" ) );
172  if ( !embeddedRendererElem.isNull() )
173  {
174  r->setEmbeddedRenderer( QgsFeatureRenderer::load( embeddedRendererElem, context ) );
175  }
176 
177  //center symbol
178  QDomElement centerSymbolElem = symbologyElem.firstChildElement( QStringLiteral( "symbol" ) );
179  if ( !centerSymbolElem.isNull() )
180  {
181  r->setCenterSymbol( QgsSymbolLayerUtils::loadSymbol<QgsMarkerSymbol>( centerSymbolElem, context ) );
182  }
183  return r;
184 }
185 
187 {
188  return mCenterSymbol.get();
189 }
190 
191 QDomElement QgsPointDisplacementRenderer::save( QDomDocument &doc, const QgsReadWriteContext &context )
192 {
193  QDomElement rendererElement = doc.createElement( RENDERER_TAG_NAME );
194  rendererElement.setAttribute( QStringLiteral( "forceraster" ), ( mForceRaster ? QStringLiteral( "1" ) : QStringLiteral( "0" ) ) );
195  rendererElement.setAttribute( QStringLiteral( "type" ), QStringLiteral( "pointDisplacement" ) );
196  rendererElement.setAttribute( QStringLiteral( "labelAttributeName" ), mLabelAttributeName );
197  rendererElement.appendChild( QgsFontUtils::toXmlElement( mLabelFont, doc, QStringLiteral( "labelFontProperties" ) ) );
198  rendererElement.setAttribute( QStringLiteral( "circleWidth" ), QString::number( mCircleWidth ) );
199  rendererElement.setAttribute( QStringLiteral( "circleColor" ), QgsSymbolLayerUtils::encodeColor( mCircleColor ) );
200  rendererElement.setAttribute( QStringLiteral( "labelColor" ), QgsSymbolLayerUtils::encodeColor( mLabelColor ) );
201  rendererElement.setAttribute( QStringLiteral( "circleRadiusAddition" ), QString::number( mCircleRadiusAddition ) );
202  rendererElement.setAttribute( QStringLiteral( "labelDistanceFactor" ), QString::number( mLabelDistanceFactor ) );
203  rendererElement.setAttribute( QStringLiteral( "placement" ), static_cast< int >( mPlacement ) );
204  rendererElement.setAttribute( QStringLiteral( "maxLabelScaleDenominator" ), QString::number( mMinLabelScale ) );
205  rendererElement.setAttribute( QStringLiteral( "tolerance" ), QString::number( mTolerance ) );
206  rendererElement.setAttribute( QStringLiteral( "toleranceUnit" ), QgsUnitTypes::encodeUnit( mToleranceUnit ) );
207  rendererElement.setAttribute( QStringLiteral( "toleranceUnitScale" ), QgsSymbolLayerUtils::encodeMapUnitScale( mToleranceMapUnitScale ) );
208 
209  if ( mRenderer )
210  {
211  QDomElement embeddedRendererElem = mRenderer->save( doc, context );
212  rendererElement.appendChild( embeddedRendererElem );
213  }
214  if ( mCenterSymbol )
215  {
216  QDomElement centerSymbolElem = QgsSymbolLayerUtils::saveSymbol( QStringLiteral( "centerSymbol" ), mCenterSymbol.get(), doc, context );
217  rendererElement.appendChild( centerSymbolElem );
218  }
219 
221  mPaintEffect->saveProperties( doc, rendererElement );
222 
223  if ( !mOrderBy.isEmpty() )
224  {
225  QDomElement orderBy = doc.createElement( QStringLiteral( "orderby" ) );
226  mOrderBy.save( orderBy );
227  rendererElement.appendChild( orderBy );
228  }
229  rendererElement.setAttribute( QStringLiteral( "enableorderby" ), ( mOrderByEnabled ? QStringLiteral( "1" ) : QStringLiteral( "0" ) ) );
230 
231  return rendererElement;
232 }
233 
235 {
236  QSet<QString> attr = QgsPointDistanceRenderer::usedAttributes( context );
237  if ( mCenterSymbol )
238  attr.unite( mCenterSymbol->usedAttributes( context ) );
239  return attr;
240 }
241 
243 {
244  mCenterSymbol.reset( symbol );
245 }
246 
247 void QgsPointDisplacementRenderer::calculateSymbolAndLabelPositions( QgsSymbolRenderContext &symbolContext, QPointF centerPoint, int nPosition,
248  double symbolDiagonal, QList<QPointF> &symbolPositions, QList<QPointF> &labelShifts, double &circleRadius, double &gridRadius,
249  int &gridSize, QVector<double> &diagonals ) const
250 {
251  symbolPositions.clear();
252  labelShifts.clear();
253 
254  if ( nPosition < 1 )
255  {
256  return;
257  }
258  else if ( nPosition == 1 ) //If there is only one feature, draw it exactly at the center position
259  {
260  const double side = std::sqrt( std::pow( symbolDiagonal, 2 ) / 2.0 );
261  symbolPositions.append( centerPoint );
262  labelShifts.append( QPointF( side * mLabelDistanceFactor, -side * mLabelDistanceFactor ) );
263  return;
264  }
265 
266  double circleAdditionPainterUnits = symbolContext.renderContext().convertToPainterUnits( mCircleRadiusAddition, QgsUnitTypes::RenderMillimeters );
267 
268  switch ( mPlacement )
269  {
270  case Ring:
271  {
272  double minDiameterToFitSymbols = nPosition * symbolDiagonal / ( 2.0 * M_PI );
273  double radius = std::max( symbolDiagonal / 2, minDiameterToFitSymbols ) + circleAdditionPainterUnits;
274 
275  double fullPerimeter = 2 * M_PI;
276  double angleStep = fullPerimeter / nPosition;
277 
278  int featureIndex;
279  double currentAngle;
280  for ( currentAngle = 0.0, featureIndex = 0; currentAngle < fullPerimeter; currentAngle += angleStep, featureIndex++ )
281  {
282  double sinusCurrentAngle = std::sin( currentAngle );
283  double cosinusCurrentAngle = std::cos( currentAngle );
284  QPointF positionShift( radius * sinusCurrentAngle, radius * cosinusCurrentAngle );
285 
286  QPointF labelShift( ( radius + diagonals.at( featureIndex ) * mLabelDistanceFactor ) * sinusCurrentAngle, ( radius + diagonals.at( featureIndex ) * mLabelDistanceFactor ) * cosinusCurrentAngle );
287  symbolPositions.append( centerPoint + positionShift );
288  labelShifts.append( labelShift );
289  }
290  circleRadius = radius;
291  break;
292  }
293  case ConcentricRings:
294  {
295  double centerDiagonal = mCenterSymbol->size( symbolContext.renderContext() ) * M_SQRT2;
296 
297  int pointsRemaining = nPosition;
298  int ringNumber = 1;
299  double firstRingRadius = centerDiagonal / 2.0 + symbolDiagonal / 2.0;
300  int featureIndex = 0;
301  while ( pointsRemaining > 0 )
302  {
303  double radiusCurrentRing = std::max( firstRingRadius + ( ringNumber - 1 ) * symbolDiagonal + ringNumber * circleAdditionPainterUnits, 0.0 );
304  int maxPointsCurrentRing = std::max( std::floor( 2 * M_PI * radiusCurrentRing / symbolDiagonal ), 1.0 );
305  int actualPointsCurrentRing = std::min( maxPointsCurrentRing, pointsRemaining );
306 
307  double angleStep = 2 * M_PI / actualPointsCurrentRing;
308  double currentAngle = 0.0;
309  for ( int i = 0; i < actualPointsCurrentRing; ++i )
310  {
311  double sinusCurrentAngle = std::sin( currentAngle );
312  double cosinusCurrentAngle = std::cos( currentAngle );
313  QPointF positionShift( radiusCurrentRing * sinusCurrentAngle, radiusCurrentRing * cosinusCurrentAngle );
314  QPointF labelShift( ( radiusCurrentRing + diagonals.at( featureIndex ) * mLabelDistanceFactor ) * sinusCurrentAngle, ( radiusCurrentRing + diagonals.at( featureIndex ) * mLabelDistanceFactor ) * cosinusCurrentAngle );
315  symbolPositions.append( centerPoint + positionShift );
316  labelShifts.append( labelShift );
317  currentAngle += angleStep;
318  featureIndex++;
319  }
320 
321  pointsRemaining -= actualPointsCurrentRing;
322  ringNumber++;
323  circleRadius = radiusCurrentRing;
324  }
325  break;
326  }
327  case Grid:
328  {
329  double centerDiagonal = mCenterSymbol->size( symbolContext.renderContext() ) * M_SQRT2;
330  int pointsRemaining = nPosition;
331  gridSize = std::ceil( std::sqrt( pointsRemaining ) );
332  if ( pointsRemaining - std::pow( gridSize - 1, 2 ) < gridSize )
333  gridSize -= 1;
334  double originalPointRadius = ( ( centerDiagonal / 2.0 + symbolDiagonal / 2.0 ) + symbolDiagonal ) / 2;
335  double userPointRadius = originalPointRadius + circleAdditionPainterUnits;
336 
337  int yIndex = 0;
338  while ( pointsRemaining > 0 )
339  {
340  for ( int xIndex = 0; xIndex < gridSize && pointsRemaining > 0; ++xIndex )
341  {
342  QPointF positionShift( userPointRadius * xIndex, userPointRadius * yIndex );
343  symbolPositions.append( centerPoint + positionShift );
344  pointsRemaining--;
345  }
346  yIndex++;
347  }
348 
349  centralizeGrid( symbolPositions, userPointRadius, gridSize );
350 
351  int xFactor;
352  int yFactor;
353  double side = 0;
354  for ( int symbolIndex = 0; symbolIndex < symbolPositions.size(); ++symbolIndex )
355  {
356  if ( symbolPositions.at( symbolIndex ).x() < centerPoint.x() )
357  {
358  xFactor = -1;
359  }
360  else
361  {
362  xFactor = 1;
363  }
364 
365  if ( symbolPositions.at( symbolIndex ).y() < centerPoint.y() )
366  {
367  yFactor = 1;
368  }
369  else
370  {
371  yFactor = -1;
372  }
373 
374  side = std::sqrt( std::pow( diagonals.at( symbolIndex ), 2 ) / 2.0 );
375  QPointF labelShift( ( side * mLabelDistanceFactor * xFactor ), ( -side * mLabelDistanceFactor * yFactor ) );
376  labelShifts.append( symbolPositions.at( symbolIndex ) - centerPoint + labelShift );
377  }
378 
379  gridRadius = userPointRadius;
380  break;
381  }
382  }
383 }
384 
385 void QgsPointDisplacementRenderer::centralizeGrid( QList<QPointF> &pointSymbolPositions, double radius, int size ) const
386 {
387  double shiftAmount = -radius * ( size - 1.0 ) / 2.0;
388  QPointF centralShift( shiftAmount, shiftAmount );
389  for ( int i = 0; i < pointSymbolPositions.size(); ++i )
390  {
391  pointSymbolPositions[i] += centralShift;
392  }
393 }
394 
395 void QgsPointDisplacementRenderer::drawGrid( int gridSizeUnits, QgsSymbolRenderContext &context,
396  QList<QPointF> pointSymbolPositions, int nSymbols )
397 {
398  QPainter *p = context.renderContext().painter();
399  if ( nSymbols < 2 || !p ) //draw grid only if multiple features
400  {
401  return;
402  }
403 
404  QPen gridPen( mCircleColor );
405  gridPen.setWidthF( context.renderContext().convertToPainterUnits( mCircleWidth, QgsUnitTypes::RenderMillimeters ) );
406  p->setPen( gridPen );
407 
408  for ( int i = 0; i < pointSymbolPositions.size(); ++i )
409  {
410  if ( i + 1 < pointSymbolPositions.size() && 0 != ( i + 1 ) % gridSizeUnits )
411  {
412  QLineF gridLineRow( pointSymbolPositions[i], pointSymbolPositions[i + 1] );
413  p->drawLine( gridLineRow );
414  }
415 
416  if ( i + gridSizeUnits < pointSymbolPositions.size() )
417  {
418  QLineF gridLineColumn( pointSymbolPositions[i], pointSymbolPositions[i + gridSizeUnits] );
419  p->drawLine( gridLineColumn );
420  }
421  }
422 }
423 
424 void QgsPointDisplacementRenderer::drawCircle( double radiusPainterUnits, QgsSymbolRenderContext &context, QPointF centerPoint, int nSymbols )
425 {
426  QPainter *p = context.renderContext().painter();
427  if ( nSymbols < 2 || !p ) //draw circle only if multiple features
428  {
429  return;
430  }
431 
432  //draw Circle
433  QPen circlePen( mCircleColor );
434  circlePen.setWidthF( context.renderContext().convertToPainterUnits( mCircleWidth, QgsUnitTypes::RenderMillimeters ) );
435  p->setPen( circlePen );
436  p->drawArc( QRectF( centerPoint.x() - radiusPainterUnits, centerPoint.y() - radiusPainterUnits, 2 * radiusPainterUnits, 2 * radiusPainterUnits ), 0, 5760 );
437 }
438 
439 void QgsPointDisplacementRenderer::drawSymbols( const ClusteredGroup &group, QgsRenderContext &context, const QList<QPointF> &symbolPositions )
440 {
441  QList<QPointF>::const_iterator symbolPosIt = symbolPositions.constBegin();
442  ClusteredGroup::const_iterator groupIt = group.constBegin();
443  for ( ; symbolPosIt != symbolPositions.constEnd() && groupIt != group.constEnd();
444  ++symbolPosIt, ++groupIt )
445  {
446  context.expressionContext().setFeature( groupIt->feature );
447  groupIt->symbol()->startRender( context );
448  groupIt->symbol()->renderPoint( *symbolPosIt, &( groupIt->feature ), context, -1, groupIt->isSelected );
449  groupIt->symbol()->stopRender( context );
450  }
451 }
452 
454 {
455  if ( renderer->type() == QLatin1String( "pointDisplacement" ) )
456  {
457  return dynamic_cast<QgsPointDisplacementRenderer *>( renderer->clone() );
458  }
459  else if ( renderer->type() == QLatin1String( "singleSymbol" ) ||
460  renderer->type() == QLatin1String( "categorizedSymbol" ) ||
461  renderer->type() == QLatin1String( "graduatedSymbol" ) ||
462  renderer->type() == QLatin1String( "RuleRenderer" ) )
463  {
465  pointRenderer->setEmbeddedRenderer( renderer->clone() );
466  return pointRenderer;
467  }
468  else if ( renderer->type() == QLatin1String( "pointCluster" ) )
469  {
471  const QgsPointClusterRenderer *clusterRenderer = static_cast< const QgsPointClusterRenderer * >( renderer );
472  if ( clusterRenderer->embeddedRenderer() )
473  pointRenderer->setEmbeddedRenderer( clusterRenderer->embeddedRenderer()->clone() );
474  pointRenderer->setTolerance( clusterRenderer->tolerance() );
475  pointRenderer->setToleranceUnit( clusterRenderer->toleranceUnit() );
476  pointRenderer->setToleranceMapUnitScale( clusterRenderer->toleranceMapUnitScale() );
477  if ( const_cast< QgsPointClusterRenderer * >( clusterRenderer )->clusterSymbol() )
478  pointRenderer->setCenterSymbol( const_cast< QgsPointClusterRenderer * >( clusterRenderer )->clusterSymbol()->clone() );
479  return pointRenderer;
480  }
481  else
482  {
483  return nullptr;
484  }
485 }
An abstract base class for distance based point renderers (e.g., clusterer and displacement renderers...
The class is used as a container of context for various read/write operations on other objects...
QString mLabelAttributeName
Attribute name for labeling. An empty string indicates that no labels should be rendered.
static QgsFeatureRenderer * create(QDomElement &symbologyElem, const QgsReadWriteContext &context)
Create a renderer from XML element.
Place points in a grid around group.
QgsMarkerSymbol * centerSymbol()
Returns the symbol for the center of a displacement group (but not ownership of the symbol)...
QgsPointDisplacementRenderer * clone() const override
Create a deep copy of this renderer.
QgsUnitTypes::RenderUnit mToleranceUnit
Unit for distance tolerance.
QgsFeatureRequest::OrderBy mOrderBy
Definition: qgsrenderer.h:521
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
void setLabelFont(const QFont &font)
Sets the font used for labeling points.
QgsFeatureRequest::OrderBy orderBy() const
Gets the order in which features shall be processed by this renderer.
void setTolerance(double distance)
Sets the tolerance distance for grouping points.
static bool isDefaultStack(QgsPaintEffect *effect)
Tests whether a paint effect matches the default effects stack.
void setLabelColor(const QColor &color)
Sets the color to use for for labeling points.
void setToleranceMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale object for the distance tolerance.
void setToleranceUnit(QgsUnitTypes::RenderUnit unit)
Sets the units for the tolerance distance.
static QString encodeMapUnitScale(const QgsMapUnitScale &mapUnitScale)
Container of fields for a vector layer.
Definition: qgsfields.h:42
void stopRender(QgsRenderContext &context) override
Must be called when a render cycle has finished, to allow the renderer to clean up.
#define RENDERER_TAG_NAME
Definition: qgsrenderer.h:49
QgsPaintEffect * mPaintEffect
Definition: qgsrenderer.h:505
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:55
void startRender(QgsRenderContext &context, const QgsFields &fields) override
Must be called when a new render cycle is started.
void setCenterSymbol(QgsMarkerSymbol *symbol)
Sets the center symbol for a displacement group.
QgsUnitTypes::RenderUnit toleranceUnit() const
Returns the units for the tolerance distance.
A marker symbol type, for rendering Point and MultiPoint geometries.
Definition: qgssymbol.h:766
double mMinLabelScale
Maximum scale denominator for label display. A zero value indicates no scale limitation.
void drawLabels(QPointF centerPoint, QgsSymbolRenderContext &context, const QList< QPointF > &labelShifts, const ClusteredGroup &group)
Renders the labels for a group.
static QString encodeColor(const QColor &color)
QgsPointDisplacementRenderer(const QString &labelAttributeName=QString())
Constructor for QgsPointDisplacementRenderer.
QFont labelFont() const
Returns the font used for labeling points.
QString type() const
Definition: qgsrenderer.h:129
double mTolerance
Distance tolerance. Points that are closer together than this distance are considered clustered...
QDomElement save(QDomDocument &doc, const QgsReadWriteContext &context) override
store renderer info to XML element
static QgsFeatureRenderer * load(QDomElement &symbologyElem, const QgsReadWriteContext &context)
create a renderer from XML element
void setCircleColor(const QColor &color)
Sets the color used for drawing the displacement group circle.
void setLabelAttributeName(const QString &name)
Sets the attribute name for labeling points.
A renderer that automatically clusters points with the same geographic position.
Place points in concentric rings around group.
static bool setFromXmlChildNode(QFont &font, const QDomElement &element, const QString &childNode)
Sets the properties of a font to match the properties stored in an XML child node.
void setPlacement(Placement placement)
Sets the placement method used for dispersing the points.
QColor mLabelColor
Label text color.
void startRender(QgsRenderContext &context, const QgsFields &fields) override
Must be called when a new render cycle is started.
static Q_INVOKABLE QgsUnitTypes::RenderUnit decodeRenderUnit(const QString &string, bool *ok=nullptr)
Decodes a render unit from a string.
void setLabelDistanceFactor(double factor)
Sets a factor for increasing the label distances from the symbol.
QgsRenderContext & renderContext()
Returns a reference to the context&#39;s render context.
Definition: qgssymbol.h:574
QgsMapUnitScale mToleranceMapUnitScale
Map unit scale for distance tolerance.
double tolerance() const
Returns the tolerance distance for grouping points.
void stopRender(QgsRenderContext &context) override
Must be called when a render cycle has finished, to allow the renderer to clean up.
const QgsMapUnitScale & toleranceMapUnitScale() const
Returns the map unit scale object for the distance tolerance.
static Q_INVOKABLE QString encodeUnit(QgsUnitTypes::DistanceUnit unit)
Encodes a distance unit to a string.
Place points in a single ring around group.
QgsExpressionContext & expressionContext()
Gets the expression context.
Contains properties for a feature within a clustered group.
A renderer that automatically displaces points with the same geographic location. ...
const QgsFeatureRenderer * embeddedRenderer() const override
Returns the current embedded renderer (subrenderer) for this feature renderer.
Contains information about the context of a rendering operation.
double convertToPainterUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
Converts a size from the specified units to painter units (pixels).
QPainter * painter()
Returns the destination QPainter for the render operation.
void setMinimumLabelScale(double scale)
Sets the minimum map scale (i.e.
std::unique_ptr< QgsFeatureRenderer > mRenderer
Embedded base renderer. This can be used for rendering individual, isolated points.
void CORE_EXPORT save(QDomElement &elem) const
Serialize to XML.
static QDomElement saveSymbol(const QString &symbolName, QgsSymbol *symbol, QDomDocument &doc, const QgsReadWriteContext &context)
Writes a symbol definition to XML.
void copyRendererData(QgsFeatureRenderer *destRenderer) const
Clones generic renderer data to another renderer.
Definition: qgsrenderer.cpp:49
QList< QgsPointDistanceRenderer::GroupedFeature > ClusteredGroup
A group of clustered points (ie features within the distance tolerance).
static QgsMapUnitScale decodeMapUnitScale(const QString &str)
static QDomElement toXmlElement(const QFont &font, QDomDocument &document, const QString &elementName)
Returns a DOM element containing the properties of the font.
int mLabelIndex
Label attribute index (or -1 if none). This index is not stored, it is requested in the startRender()...
QSet< QString > usedAttributes(const QgsRenderContext &context) const override
Returns a list of attributes required by this renderer.
void setCircleRadiusAddition(double distance)
Sets a factor for increasing the ring size of displacement groups.
void setEmbeddedRenderer(QgsFeatureRenderer *r) override
Sets an embedded renderer (subrenderer) for this feature renderer.
static QgsPointDisplacementRenderer * convertFromRenderer(const QgsFeatureRenderer *renderer)
Creates a QgsPointDisplacementRenderer from an existing renderer.
virtual QgsFeatureRenderer * clone() const =0
Create a deep copy of this renderer.
void setCircleWidth(double width)
Sets the line width for the displacement group circle.
static QColor decodeColor(const QString &str)
QSet< QString > usedAttributes(const QgsRenderContext &context) const override
Returns a list of attributes required by this renderer.
virtual bool saveProperties(QDomDocument &doc, QDomElement &element) const
Saves the current state of the effect to a DOM element.