QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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  QgsPointDisplacementRenderer( const QString& labelAttributeName = "" );
36 
37  QgsFeatureRendererV2* clone() const override;
38 
39  virtual void toSld( QDomDocument& doc, QDomElement &element ) const override;
40 
42  bool renderFeature( QgsFeature& feature, QgsRenderContext& context, int layer = -1, bool selected = false, bool drawVertexMarker = false ) override;
43 
45  virtual QList<QString> usedAttributes() override;
47  virtual int capabilities() override;
49  virtual QgsSymbolV2List symbols() override;
51  virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature ) override;
53  virtual QgsSymbolV2* originalSymbolForFeature( QgsFeature& feat ) override;
55  virtual QgsSymbolV2List symbolsForFeature( QgsFeature& feat ) override;
57  virtual QgsSymbolV2List originalSymbolsForFeature( QgsFeature& feat ) override;
59  virtual bool willRenderFeature( QgsFeature& feat ) override;
60 
61  void startRender( QgsRenderContext& context, const QgsFields& fields ) override;
62 
63  void stopRender( QgsRenderContext& context ) override;
64 
66  static QgsFeatureRendererV2* create( QDomElement& symbologyElem );
67  QDomElement save( QDomDocument& doc ) override;
68 
69  QgsLegendSymbologyList legendSymbologyItems( QSize iconSize ) override;
70 
72  QgsLegendSymbolList legendSymbolItems( double scaleDenominator = -1, QString rule = "" ) override;
73 
74  void setLabelAttributeName( const QString& name ) { mLabelAttributeName = name; }
75  QString labelAttributeName() const { return mLabelAttributeName; }
76 
78  void setEmbeddedRenderer( QgsFeatureRendererV2* r );
79  QgsFeatureRendererV2* embeddedRenderer() const { return mRenderer;}
80 
83  Q_DECL_DEPRECATED void setDisplacementGroups( const QList<QMap<QgsFeatureId, QgsFeature> >& list ) { Q_UNUSED( list ); }
84 
85  void setLabelFont( const QFont& f ) { mLabelFont = f; }
86  QFont labelFont() const { return mLabelFont;}
87 
88  void setCircleWidth( double w ) { mCircleWidth = w; }
89  double circleWidth() const { return mCircleWidth; }
90 
91  void setCircleColor( const QColor& c ) { mCircleColor = c; }
92  QColor circleColor() const { return mCircleColor; }
93 
94  void setLabelColor( const QColor& c ) { mLabelColor = c;}
95  QColor labelColor() const { return mLabelColor; }
96 
97  void setCircleRadiusAddition( double d ) { mCircleRadiusAddition = d; }
98  double circleRadiusAddition() const { return mCircleRadiusAddition; }
99 
100  void setMaxLabelScaleDenominator( double d ) { mMaxLabelScaleDenominator = d; }
101  double maxLabelScaleDenominator() const { return mMaxLabelScaleDenominator; }
102 
104  QgsMarkerSymbolV2* centerSymbol() { return mCenterSymbol;}
106  void setCenterSymbol( QgsMarkerSymbolV2* symbol );
107 
108  void setTolerance( double t ) { mTolerance = t; }
109  double tolerance() const { return mTolerance; }
110 
114  static QgsPointDisplacementRenderer* convertFromRenderer( const QgsFeatureRendererV2 *renderer );
115 
116  private:
117 
119  QgsFeatureRendererV2* mRenderer;
120 
122  QString mLabelAttributeName;
124  int mLabelIndex;
125 
127  QgsMarkerSymbolV2* mCenterSymbol;
128 
130  double mTolerance;
131 
133  QFont mLabelFont;
134  QColor mLabelColor;
136  double mCircleWidth;
138  QColor mCircleColor;
140  double mCircleRadiusAddition;
142  bool mDrawLabels;
144  double mMaxLabelScaleDenominator;
145 
146  typedef QMap<QgsFeatureId, QgsFeature> DisplacementGroup;
148  QList<DisplacementGroup> mDisplacementGroups;
150  QMap<QgsFeatureId, int> mGroupIndex;
152  QgsSpatialIndex* mSpatialIndex;
154  QSet<QgsFeatureId> mSelectedFeatures;
155 
157  QgsRectangle searchRect( const QgsPoint& p ) const;
159  void printInfoDisplacementGroups();
160 
162  QString getLabel( const QgsFeature& f );
163 
164  //rendering methods
165  void renderPoint( const QPointF& point, QgsSymbolV2RenderContext& context, const QList<QgsMarkerSymbolV2*>& symbols,
166  const QStringList& labels );
167 
168  //helper functions
169  void calculateSymbolAndLabelPositions( const QPointF& centerPoint, int nPosition, double radius, double symbolDiagonal, QList<QPointF>& symbolPositions, QList<QPointF>& labelShifts ) const;
170  void drawGroup( const DisplacementGroup& group, QgsRenderContext& context );
171  void drawCircle( double radiusPainterUnits, QgsSymbolV2RenderContext& context, const QPointF& centerPoint, int nSymbols );
172  void drawSymbols( const QgsFeature& f, QgsRenderContext& context, const QList<QgsMarkerSymbolV2*>& symbolList, const QList<QPointF>& symbolPositions, bool selected = false );
173  void drawLabels( const QPointF& centerPoint, QgsSymbolV2RenderContext& context, const QList<QPointF>& labelShifts, const QStringList& labelList );
175  QgsSymbolV2* firstSymbolForFeature( QgsFeatureRendererV2* r, QgsFeature& f );
176 };
177 
178 #endif // QGSPOINTDISPLACEMENTRENDERER_H