QGIS API Documentation  2.6.0-Brighton
 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;
38 
39  virtual void toSld( QDomDocument& doc, QDomElement &element ) const;
40 
42  bool renderFeature( QgsFeature& feature, QgsRenderContext& context, int layer = -1, bool selected = false, bool drawVertexMarker = false );
43 
45 
46  void startRender( QgsRenderContext& context, const QgsFields& fields );
47 
48  void stopRender( QgsRenderContext& context );
49 
50  QList<QString> usedAttributes();
52 
54  static QgsFeatureRendererV2* create( QDomElement& symbologyElem );
55  QDomElement save( QDomDocument& doc );
56 
58 
60  QgsLegendSymbolList legendSymbolItems( double scaleDenominator = -1, QString rule = "" );
61 
62  void setLabelAttributeName( const QString& name ) { mLabelAttributeName = name; }
63  QString labelAttributeName() const { return mLabelAttributeName; }
64 
66  void setEmbeddedRenderer( QgsFeatureRendererV2* r );
67  QgsFeatureRendererV2* embeddedRenderer() const { return mRenderer;}
68 
71  Q_DECL_DEPRECATED void setDisplacementGroups( const QList<QMap<QgsFeatureId, QgsFeature> >& list ) { Q_UNUSED( list ); }
72 
73  void setLabelFont( const QFont& f ) { mLabelFont = f; }
74  QFont labelFont() const { return mLabelFont;}
75 
76  void setCircleWidth( double w ) { mCircleWidth = w; }
77  double circleWidth() const { return mCircleWidth; }
78 
79  void setCircleColor( const QColor& c ) { mCircleColor = c; }
80  QColor circleColor() const { return mCircleColor; }
81 
82  void setLabelColor( const QColor& c ) { mLabelColor = c;}
83  QColor labelColor() const { return mLabelColor; }
84 
85  void setCircleRadiusAddition( double d ) { mCircleRadiusAddition = d; }
86  double circleRadiusAddition() const { return mCircleRadiusAddition; }
87 
88  void setMaxLabelScaleDenominator( double d ) { mMaxLabelScaleDenominator = d; }
89  double maxLabelScaleDenominator() const { return mMaxLabelScaleDenominator; }
90 
92  QgsMarkerSymbolV2* centerSymbol() { return mCenterSymbol;}
94  void setCenterSymbol( QgsMarkerSymbolV2* symbol );
95 
96  void setTolerance( double t ) { mTolerance = t; }
97  double tolerance() const { return mTolerance; }
98 
102  static QgsPointDisplacementRenderer* convertFromRenderer( const QgsFeatureRendererV2 *renderer );
103 
104  private:
105 
107  QgsFeatureRendererV2* mRenderer;
108 
110  QString mLabelAttributeName;
112  int mLabelIndex;
113 
115  QgsMarkerSymbolV2* mCenterSymbol;
116 
118  double mTolerance;
119 
121  QFont mLabelFont;
122  QColor mLabelColor;
124  double mCircleWidth;
126  QColor mCircleColor;
128  double mCircleRadiusAddition;
130  bool mDrawLabels;
132  double mMaxLabelScaleDenominator;
133 
134  typedef QMap<QgsFeatureId, QgsFeature> DisplacementGroup;
136  QList<DisplacementGroup> mDisplacementGroups;
138  QMap<QgsFeatureId, int> mGroupIndex;
140  QgsSpatialIndex* mSpatialIndex;
142  QSet<QgsFeatureId> mSelectedFeatures;
143 
145  QgsRectangle searchRect( const QgsPoint& p ) const;
147  void printInfoDisplacementGroups();
148 
150  QString getLabel( const QgsFeature& f );
151 
152  //rendering methods
153  void renderPoint( const QPointF& point, QgsSymbolV2RenderContext& context, const QList<QgsMarkerSymbolV2*>& symbols,
154  const QStringList& labels );
155 
156  //helper functions
157  void calculateSymbolAndLabelPositions( const QPointF& centerPoint, int nPosition, double radius, double symbolDiagonal, QList<QPointF>& symbolPositions, QList<QPointF>& labelShifts ) const;
158  void drawGroup( const DisplacementGroup& group, QgsRenderContext& context );
159  void drawCircle( double radiusPainterUnits, QgsSymbolV2RenderContext& context, const QPointF& centerPoint, int nSymbols );
160  void drawSymbols( const QgsFeature& f, QgsRenderContext& context, const QList<QgsMarkerSymbolV2*>& symbolList, const QList<QPointF>& symbolPositions, bool selected = false );
161  void drawLabels( const QPointF& centerPoint, QgsSymbolV2RenderContext& context, const QList<QPointF>& labelShifts, const QStringList& labelList );
163  QgsSymbolV2* firstSymbolForFeature( QgsFeatureRendererV2* r, QgsFeature& f );
164 };
165 
166 #endif // QGSPOINTDISPLACEMENTRENDERER_H