QGIS API Documentation  2.12.0-Lyon
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 
32 {
33  public:
34 
37  enum Placement
38  {
39  Ring,
40  ConcentricRings
41  };
42 
43  QgsPointDisplacementRenderer( const QString& labelAttributeName = "" );
45 
46  QgsFeatureRendererV2* clone() const override;
47 
48  virtual void toSld( QDomDocument& doc, QDomElement &element ) const override;
49 
51  bool renderFeature( QgsFeature& feature, QgsRenderContext& context, int layer = -1, bool selected = false, bool drawVertexMarker = false ) override;
52 
54  virtual QList<QString> usedAttributes() override;
56  virtual int capabilities() override;
58  virtual QgsSymbolV2List symbols( QgsRenderContext& context ) override;
60  virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature, QgsRenderContext& context ) override;
62  virtual QgsSymbolV2* originalSymbolForFeature( QgsFeature& feat, QgsRenderContext& context ) override;
64  virtual QgsSymbolV2List symbolsForFeature( QgsFeature& feat, QgsRenderContext& context ) override;
66  virtual QgsSymbolV2List originalSymbolsForFeature( QgsFeature& feat, QgsRenderContext& context ) override;
68  virtual bool willRenderFeature( QgsFeature& feat, QgsRenderContext& context ) override;
69 
70  virtual void startRender( QgsRenderContext& context, const QgsFields& fields ) override;
71 
72  void stopRender( QgsRenderContext& context ) override;
73 
75  static QgsFeatureRendererV2* create( QDomElement& symbologyElem );
76  QDomElement save( QDomDocument& doc ) override;
77 
79 
81  QgsLegendSymbolList legendSymbolItems( double scaleDenominator = -1, const QString& rule = "" ) override;
82 
83  void setLabelAttributeName( const QString& name ) { mLabelAttributeName = name; }
84  QString labelAttributeName() const { return mLabelAttributeName; }
85 
87  void setEmbeddedRenderer( QgsFeatureRendererV2* r );
88  QgsFeatureRendererV2* embeddedRenderer() const { return mRenderer;}
89 
92  Q_DECL_DEPRECATED void setDisplacementGroups( const QList<QMap<QgsFeatureId, QgsFeature> >& list ) { Q_UNUSED( list ); }
93 
94  void setLabelFont( const QFont& f ) { mLabelFont = f; }
95  QFont labelFont() const { return mLabelFont;}
96 
97  void setCircleWidth( double w ) { mCircleWidth = w; }
98  double circleWidth() const { return mCircleWidth; }
99 
100  void setCircleColor( const QColor& c ) { mCircleColor = c; }
101  QColor circleColor() const { return mCircleColor; }
102 
103  void setLabelColor( const QColor& c ) { mLabelColor = c;}
104  QColor labelColor() const { return mLabelColor; }
105 
106  void setCircleRadiusAddition( double d ) { mCircleRadiusAddition = d; }
107  double circleRadiusAddition() const { return mCircleRadiusAddition; }
108 
109  void setMaxLabelScaleDenominator( double d ) { mMaxLabelScaleDenominator = d; }
110  double maxLabelScaleDenominator() const { return mMaxLabelScaleDenominator; }
111 
116  Placement placement() const { return mPlacement; }
117 
123  void setPlacement( Placement placement ) { mPlacement = placement; }
124 
126  QgsMarkerSymbolV2* centerSymbol() { return mCenterSymbol;}
128  void setCenterSymbol( QgsMarkerSymbolV2* symbol );
129 
136  void setTolerance( double t ) { mTolerance = t; }
137 
143  double tolerance() const { return mTolerance; }
144 
151  void setToleranceUnit( QgsSymbolV2::OutputUnit unit ) { mToleranceUnit = unit; }
152 
158  QgsSymbolV2::OutputUnit toleranceUnit() const { return mToleranceUnit; }
159 
166  void setToleranceMapUnitScale( const QgsMapUnitScale& scale ) { mToleranceMapUnitScale = scale; }
167 
173  const QgsMapUnitScale& toleranceMapUnitScale() const { return mToleranceMapUnitScale; }
174 
178  static QgsPointDisplacementRenderer* convertFromRenderer( const QgsFeatureRendererV2 *renderer );
179 
180  private:
181 
183  QgsFeatureRendererV2* mRenderer;
184 
186  QString mLabelAttributeName;
188  int mLabelIndex;
189 
191  QgsMarkerSymbolV2* mCenterSymbol;
192 
194  double mTolerance;
195  QgsSymbolV2::OutputUnit mToleranceUnit;
196  QgsMapUnitScale mToleranceMapUnitScale;
197 
198  Placement mPlacement;
199 
201  QFont mLabelFont;
202  QColor mLabelColor;
204  double mCircleWidth;
206  QColor mCircleColor;
208  double mCircleRadiusAddition;
210  bool mDrawLabels;
212  double mMaxLabelScaleDenominator;
213 
214  typedef QMap<QgsFeatureId, QPair< QgsFeature, QgsSymbolV2* > > DisplacementGroup;
216  QList<DisplacementGroup> mDisplacementGroups;
218  QMap<QgsFeatureId, int> mGroupIndex;
220  QgsSpatialIndex* mSpatialIndex;
222  QSet<QgsFeatureId> mSelectedFeatures;
223 
225  QgsRectangle searchRect( const QgsPoint& p, double distance ) const;
227  void printInfoDisplacementGroups();
228 
230  QString getLabel( const QgsFeature& f );
231 
232  //rendering methods
233  void renderPoint( const QPointF& point, QgsSymbolV2RenderContext& context, const QList<QgsMarkerSymbolV2*>& symbols,
234  const QStringList& labels );
235 
236  //helper functions
237  void calculateSymbolAndLabelPositions( QgsSymbolV2RenderContext &symbolContext, const QPointF& centerPoint, int nPosition, double symbolDiagonal, QList<QPointF>& symbolPositions, QList<QPointF>& labelShifts , double &circleRadius ) const;
238  void drawGroup( const DisplacementGroup& group, QgsRenderContext& context );
239  void drawCircle( double radiusPainterUnits, QgsSymbolV2RenderContext& context, const QPointF& centerPoint, int nSymbols );
240  void drawSymbols( const QgsFeature& f, QgsRenderContext& context, const QList<QgsMarkerSymbolV2*>& symbolList, const QList<QPointF>& symbolPositions, bool selected = false );
241  void drawLabels( const QPointF& centerPoint, QgsSymbolV2RenderContext& context, const QList<QPointF>& labelShifts, const QStringList& labelList );
243  QgsSymbolV2* firstSymbolForFeature( QgsFeatureRendererV2* r, QgsFeature& f, QgsRenderContext& context );
244 };
245 
246 #endif // QGSPOINTDISPLACEMENTRENDERER_H
A rectangle specified with double values.
Definition: qgsrectangle.h:35
Placement
Placement methods for dispersing points.
OutputUnit
The unit of the output.
Definition: qgssymbolv2.h:55
double tolerance() const
Returns the tolerance distance for grouping points.
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
const QgsMapUnitScale & toleranceMapUnitScale() const
Returns the map unit scale object for the distance tolerance.
Container of fields for a vector layer.
Definition: qgsfield.h:177
virtual QList< QString > usedAttributes()=0
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:176
virtual Q_DECL_DEPRECATED bool willRenderFeature(QgsFeature &feat)
return whether the renderer will render a feature or not.
virtual QgsLegendSymbologyList legendSymbologyItems(QSize iconSize)
return a list of symbology items for the legend
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
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)
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
Placement placement() const
Returns the placement method used for dispersing the points.
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:63
QgsFeatureRendererV2 * embeddedRenderer() const
virtual void toSld(QDomDocument &doc, QDomElement &element) const
used from subclasses to create SLD Rule elements following SLD v1.1 specs
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)
return 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.
virtual int capabilities()
returns bitwise OR-ed capabilities of the renderer
QgsSymbolV2::OutputUnit toleranceUnit() const
Returns the units for the tolerance distance.
QgsMarkerSymbolV2 * centerSymbol()
Returns the symbol for the center of a displacement group (but not ownership of the symbol) ...
void setTolerance(double t)
Sets the tolerance distance for grouping points.