QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 "qgsfeature.h"
22 #include "qgssymbolv2.h"
23 #include "qgspoint.h"
24 #include "qgsrendererv2.h"
25 #include <QFont>
26 #include <QSet>
27 
28 class QgsSpatialIndex;
29 
34 {
35  public:
36 
39  enum Placement
40  {
41  Ring,
42  ConcentricRings
43  };
44 
45  QgsPointDisplacementRenderer( const QString& labelAttributeName = "" );
47 
48  QgsPointDisplacementRenderer* clone() const override;
49 
51  virtual void toSld( QDomDocument& doc, QDomElement &element ) const override;
53  virtual void toSld( QDomDocument& doc, QDomElement &element, const QgsStringMap& props ) const override;
54 
56  bool renderFeature( QgsFeature& feature, QgsRenderContext& context, int layer = -1, bool selected = false, bool drawVertexMarker = false ) override;
57 
59  virtual QList<QString> usedAttributes() override;
61  virtual int capabilities() override;
65  virtual QgsSymbolV2List symbols( QgsRenderContext& context ) override;
69  virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature, QgsRenderContext& context ) override;
73  virtual QgsSymbolV2* originalSymbolForFeature( QgsFeature& feat, QgsRenderContext& context ) override;
77  virtual QgsSymbolV2List symbolsForFeature( QgsFeature& feat, QgsRenderContext& context ) override;
81  virtual QgsSymbolV2List originalSymbolsForFeature( QgsFeature& feat, QgsRenderContext& context ) override;
85  virtual QSet< QString > legendKeysForFeature( QgsFeature& feature, QgsRenderContext& context ) override;
89  virtual bool willRenderFeature( QgsFeature& feat, QgsRenderContext& context ) override;
90 
91  virtual void startRender( QgsRenderContext& context, const QgsFields& fields ) override;
92 
93  void stopRender( QgsRenderContext& context ) override;
94 
96  static QgsFeatureRendererV2* create( QDomElement& symbologyElem );
97  QDomElement save( QDomDocument& doc ) override;
98 
100 
102  QgsLegendSymbolList legendSymbolItems( double scaleDenominator = -1, const QString& rule = "" ) override;
103 
104  void setLabelAttributeName( const QString& name ) { mLabelAttributeName = name; }
105  QString labelAttributeName() const { return mLabelAttributeName; }
106 
107  void setEmbeddedRenderer( QgsFeatureRendererV2* r ) override;
108  const QgsFeatureRendererV2* embeddedRenderer() const override;
109 
110  virtual void setLegendSymbolItem( const QString& key, QgsSymbolV2* symbol ) override;
111 
112  virtual bool legendSymbolItemsCheckable() const override;
113  virtual bool legendSymbolItemChecked( const QString& key ) override;
114  virtual void checkLegendSymbolItem( const QString& key, bool state = true ) override;
115 
118  Q_DECL_DEPRECATED void setDisplacementGroups( const QList<QMap<QgsFeatureId, QgsFeature> >& list ) { Q_UNUSED( list ); }
119 
120  void setLabelFont( const QFont& f ) { mLabelFont = f; }
121  QFont labelFont() const { return mLabelFont;}
122 
123  void setCircleWidth( double w ) { mCircleWidth = w; }
124  double circleWidth() const { return mCircleWidth; }
125 
126  void setCircleColor( const QColor& c ) { mCircleColor = c; }
127  QColor circleColor() const { return mCircleColor; }
128 
129  void setLabelColor( const QColor& c ) { mLabelColor = c;}
130  QColor labelColor() const { return mLabelColor; }
131 
132  void setCircleRadiusAddition( double d ) { mCircleRadiusAddition = d; }
133  double circleRadiusAddition() const { return mCircleRadiusAddition; }
134 
135  void setMaxLabelScaleDenominator( double d ) { mMaxLabelScaleDenominator = d; }
136  double maxLabelScaleDenominator() const { return mMaxLabelScaleDenominator; }
137 
142  Placement placement() const { return mPlacement; }
143 
149  void setPlacement( Placement placement ) { mPlacement = placement; }
150 
152  QgsMarkerSymbolV2* centerSymbol() { return mCenterSymbol;}
154  void setCenterSymbol( QgsMarkerSymbolV2* symbol );
155 
162  void setTolerance( double t ) { mTolerance = t; }
163 
169  double tolerance() const { return mTolerance; }
170 
177  void setToleranceUnit( QgsSymbolV2::OutputUnit unit ) { mToleranceUnit = unit; }
178 
184  QgsSymbolV2::OutputUnit toleranceUnit() const { return mToleranceUnit; }
185 
192  void setToleranceMapUnitScale( const QgsMapUnitScale& scale ) { mToleranceMapUnitScale = scale; }
193 
199  const QgsMapUnitScale& toleranceMapUnitScale() const { return mToleranceMapUnitScale; }
200 
204  static QgsPointDisplacementRenderer* convertFromRenderer( const QgsFeatureRendererV2 *renderer );
205 
206  private:
207 
209  QgsFeatureRendererV2* mRenderer;
210 
212  QString mLabelAttributeName;
214  int mLabelIndex;
215 
217  QgsMarkerSymbolV2* mCenterSymbol;
218 
220  double mTolerance;
221  QgsSymbolV2::OutputUnit mToleranceUnit;
222  QgsMapUnitScale mToleranceMapUnitScale;
223 
224  Placement mPlacement;
225 
227  QFont mLabelFont;
228  QColor mLabelColor;
230  double mCircleWidth;
232  QColor mCircleColor;
234  double mCircleRadiusAddition;
236  bool mDrawLabels;
238  double mMaxLabelScaleDenominator;
239 
242  QList<DisplacementGroup> mDisplacementGroups;
244  QMap<QgsFeatureId, int> mGroupIndex;
246  QgsSpatialIndex* mSpatialIndex;
248  QSet<QgsFeatureId> mSelectedFeatures;
249 
251  QgsRectangle searchRect( const QgsPoint& p, double distance ) const;
253  void printInfoDisplacementGroups();
254 
256  QString getLabel( const QgsFeature& f );
257 
258  //rendering methods
259  void renderPoint( const QPointF& point, QgsSymbolV2RenderContext& context, const QList<QgsMarkerSymbolV2*>& symbols,
260  const QStringList& labels );
261 
262  //helper functions
263  void calculateSymbolAndLabelPositions( QgsSymbolV2RenderContext &symbolContext, QPointF centerPoint, int nPosition, double symbolDiagonal, QList<QPointF>& symbolPositions, QList<QPointF>& labelShifts , double &circleRadius ) const;
264  void drawGroup( const DisplacementGroup& group, QgsRenderContext& context );
265  void drawCircle( double radiusPainterUnits, QgsSymbolV2RenderContext& context, QPointF centerPoint, int nSymbols );
266  void drawSymbols( const QgsFeatureList& features, QgsRenderContext& context, const QList< QgsMarkerSymbolV2* >& symbolList, const QList<QPointF>& symbolPositions, bool selected = false );
267  void drawLabels( QPointF centerPoint, QgsSymbolV2RenderContext& context, const QList<QPointF>& labelShifts, const QStringList& labelList );
269  QgsSymbolV2* firstSymbolForFeature( QgsFeatureRendererV2* r, QgsFeature& f, QgsRenderContext& context );
270 };
271 
272 #endif // QGSPOINTDISPLACEMENTRENDERER_H
A rectangle specified with double values.
Definition: qgsrectangle.h:35
Placement
Placement methods for dispersing points.
virtual QSet< QString > legendKeysForFeature(QgsFeature &feature, QgsRenderContext &context)
Return legend keys matching a specified feature.
OutputUnit
The unit of the output.
Definition: qgssymbolv2.h:65
const QgsMapUnitScale & toleranceMapUnitScale() const
Returns the map unit scale object for the distance tolerance.
QgsSymbolV2::OutputUnit toleranceUnit() const
Returns the units for the tolerance distance.
virtual Q_DECL_DEPRECATED QgsSymbolV2 * originalSymbolForFeature(QgsFeature &feature)
Return symbol for feature.
void setLabelAttributeName(const QString &name)
virtual QDomElement save(QDomDocument &doc)
store renderer info to XML element
Container of fields for a vector layer.
Definition: qgsfield.h:252
double tolerance() const
Returns the tolerance distance for grouping points.
virtual QList< QString > usedAttributes()=0
Returns a set of attributes required for this renderer.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:187
virtual void toSld(QDomDocument &doc, QDomElement &element) const
used from subclasses to create SLD Rule elements following SLD v1.1 specs
virtual Q_DECL_DEPRECATED bool willRenderFeature(QgsFeature &feat)
Returns whether the renderer will render a feature or not.
virtual bool legendSymbolItemChecked(const QString &key)
items of symbology items in legend is checked
virtual void checkLegendSymbolItem(const QString &key, bool state=true)
item in symbology was checked
virtual QgsLegendSymbologyList legendSymbologyItems(QSize iconSize)
return a list of symbology items for the legend
virtual const QgsFeatureRendererV2 * embeddedRenderer() const
Returns the current embedded renderer (subrenderer) for this feature renderer.
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)=0
Needs to be called when a new render cycle is started.
void setToleranceUnit(QgsSymbolV2::OutputUnit unit)
Sets the units for the tolerance distance.
virtual void stopRender(QgsRenderContext &context)=0
Needs to be called when a render cycle has finished to clean up.
virtual Q_DECL_DEPRECATED QgsSymbolV2List originalSymbolsForFeature(QgsFeature &feat)
Equivalent of originalSymbolsForFeature() call extended to support renderers that may use more symbol...
virtual bool renderFeature(QgsFeature &feature, QgsRenderContext &context, int layer=-1, bool selected=false, bool drawVertexMarker=false)
Render a feature using this renderer in the given context.
virtual void setEmbeddedRenderer(QgsFeatureRendererV2 *subRenderer)
Sets an embedded renderer (subrenderer) for this feature renderer.
virtual QgsFeatureRendererV2 * clone() const =0
virtual Q_DECL_DEPRECATED QgsSymbolV2 * symbolForFeature(QgsFeature &feature)
To be overridden.
virtual QgsLegendSymbolList legendSymbolItems(double scaleDenominator=-1, const QString &rule="")
return a list of item text / symbol
void setPlacement(Placement placement)
Sets the placement method used for dispersing the points.
virtual Q_DECL_DEPRECATED QgsSymbolV2List symbols()
For symbol levels.
A class to represent a point.
Definition: qgspoint.h:117
A renderer that automatically displaces points with the same position.
Contains information about the context of a rendering operation.
Struct for storing maximum and minimum scales for measurements in map units.
virtual Q_DECL_DEPRECATED QgsSymbolV2List symbolsForFeature(QgsFeature &feat)
Returns list of symbols used for rendering the feature.
Q_DECL_DEPRECATED void setDisplacementGroups(const QList< QMap< QgsFeatureId, QgsFeature > > &list)
not available in python bindings
void setToleranceMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale object for the distance tolerance.
Placement placement() const
Returns the placement method used for dispersing the points.
virtual bool legendSymbolItemsCheckable() const
items of symbology items in legend should be checkable
virtual int capabilities()
returns bitwise OR-ed capabilities of the renderer
QgsMarkerSymbolV2 * centerSymbol()
Returns the symbol for the center of a displacement group (but not ownership of the symbol) ...
virtual void setLegendSymbolItem(const QString &key, QgsSymbolV2 *symbol)
Sets the symbol to be used for a legend symbol item.
void setTolerance(double t)
Sets the tolerance distance for grouping points.