QGIS API Documentation  2.7.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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  virtual QList<QString> usedAttributes();
47  virtual int capabilities();
49  virtual QgsSymbolV2List symbols();
51  virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature );
59  virtual bool willRenderFeature( QgsFeature& feat );
60 
61  void startRender( QgsRenderContext& context, const QgsFields& fields );
62 
63  void stopRender( QgsRenderContext& context );
64 
66  static QgsFeatureRendererV2* create( QDomElement& symbologyElem );
67  QDomElement save( QDomDocument& doc );
68 
70 
72  QgsLegendSymbolList legendSymbolItems( double scaleDenominator = -1, QString rule = "" );
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
virtual bool willRenderFeature(QgsFeature &feat)
return whether the renderer will render a feature or not.
A rectangle specified with double values.
Definition: qgsrectangle.h:35
virtual QgsSymbolV2 * originalSymbolForFeature(QgsFeature &feature)
Return symbol for feature.
Definition: qgsrendererv2.h:95
QList< QgsSymbolV2 * > QgsSymbolV2List
Definition: qgsrendererv2.h:38
void setLabelAttributeName(const QString &name)
virtual QDomElement save(QDomDocument &doc)
store renderer info to XML element
virtual QgsLegendSymbolList legendSymbolItems(double scaleDenominator=-1, QString rule="")
return a list of item text / symbol
Container of fields for a vector layer.
Definition: qgsfield.h:172
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:113
virtual QgsLegendSymbologyList legendSymbologyItems(QSize iconSize)
return a list of symbology items for the legend
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)=0
virtual void stopRender(QgsRenderContext &context)=0
virtual QgsSymbolV2List symbols()=0
for symbol levels
virtual 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
A class to represent a point.
Definition: qgspoint.h:63
QList< QPair< QString, QPixmap > > QgsLegendSymbologyList
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.
virtual 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
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) ...
QList< QPair< QString, QgsSymbolV2 * > > QgsLegendSymbolList
Definition: qgsrendererv2.h:42
virtual QgsSymbolV2 * symbolForFeature(QgsFeature &feature)=0
to be overridden