QGIS API Documentation  2.2.0-Valmiera
 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 QgsVectorLayer;
29 
32 {
33  public:
34  QgsPointDisplacementRenderer( const QString& labelAttributeName = "" );
36 
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 QgsVectorLayer *vlayer );
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() { return mRenderer;}
68 
70  void setDisplacementGroups( const QList<QMap<QgsFeatureId, QgsFeature> >& list );
71 
72  void setLabelFont( const QFont& f ) { mLabelFont = f; }
73  QFont labelFont() const { return mLabelFont;}
74 
75  void setCircleWidth( double w ) { mCircleWidth = w; }
76  double circleWidth() const { return mCircleWidth; }
77 
78  void setCircleColor( const QColor& c ) { mCircleColor = c; }
79  QColor circleColor() const { return mCircleColor; }
80 
81  void setLabelColor( const QColor& c ) { mLabelColor = c;}
82  QColor labelColor() const { return mLabelColor; }
83 
84  void setCircleRadiusAddition( double d ) { mCircleRadiusAddition = d; }
85  double circleRadiusAddition() const { return mCircleRadiusAddition; }
86 
87  void setMaxLabelScaleDenominator( double d ) { mMaxLabelScaleDenominator = d; }
88  double maxLabelScaleDenominator() const { return mMaxLabelScaleDenominator; }
89 
91  QgsMarkerSymbolV2* centerSymbol() { return mCenterSymbol;}
93  void setCenterSymbol( QgsMarkerSymbolV2* symbol );
94 
95  void setTolerance( double t ) { mTolerance = t; }
96  double tolerance() const { return mTolerance; }
97 
98  private:
99 
102 
107 
110 
112  double mTolerance;
113 
115  QFont mLabelFont;
116  QColor mLabelColor;
118  double mCircleWidth;
120  QColor mCircleColor;
127 
129  QList<QMap<QgsFeatureId, QgsFeature> > mDisplacementGroups;
131  QSet<QgsFeatureId> mDisplacementIds;
132 
134  void createDisplacementGroups( QgsVectorLayer *vlayer, const QgsRectangle& viewExtent );
136  QgsRectangle searchRect( const QgsPoint& p ) const;
138  void printInfoDisplacementGroups();
139 
141  QString getLabel( const QgsFeature& f );
142 
143  //rendering methods
144  void renderPoint( const QPointF& point, QgsSymbolV2RenderContext& context, const QList<QgsMarkerSymbolV2*>& symbols,
145  const QStringList& labels );
146 
147  //helper functions
148  void calculateSymbolAndLabelPositions( const QPointF& centerPoint, int nPosition, double radius, double symbolDiagonal, QList<QPointF>& symbolPositions, QList<QPointF>& labelShifts ) const;
149  void drawCircle( double radiusPainterUnits, QgsSymbolV2RenderContext& context, const QPointF& centerPoint, int nSymbols );
150  void drawSymbols( QgsFeature& f, QgsRenderContext& context, const QList<QgsMarkerSymbolV2*>& symbolList, const QList<QPointF>& symbolPositions, bool selected = false );
151  void drawLabels( const QPointF& centerPoint, QgsSymbolV2RenderContext& context, const QList<QPointF>& labelShifts, const QStringList& labelList );
153  QgsSymbolV2* firstSymbolForFeature( QgsFeatureRendererV2* r, QgsFeature& f );
154 };
155 
156 #endif // QGSPOINTDISPLACEMENTRENDERER_H