QGIS API Documentation  2.5.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 
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
A rectangle specified with double values.
Definition: qgsrectangle.h:35
double tolerance() const
Definition: qgspointdisplacementrenderer.h:97
QList< QgsSymbolV2 * > QgsSymbolV2List
Definition: qgsrendererv2.h:37
double maxLabelScaleDenominator() const
Definition: qgspointdisplacementrenderer.h:89
void setLabelAttributeName(const QString &name)
Definition: qgspointdisplacementrenderer.h:62
void setLabelFont(const QFont &f)
Definition: qgspointdisplacementrenderer.h:73
virtual QDomElement save(QDomDocument &doc)
store renderer info to XML element
Definition: qgsrendererv2.cpp:395
virtual QgsLegendSymbolList legendSymbolItems(double scaleDenominator=-1, QString rule="")
return a list of item text / symbol
Definition: qgsrendererv2.cpp:529
void setMaxLabelScaleDenominator(double d)
Definition: qgspointdisplacementrenderer.h:88
Container of fields for a vector layer.
Definition: qgsfield.h:172
virtual QList< QString > usedAttributes()=0
double circleWidth() const
Definition: qgspointdisplacementrenderer.h:77
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
Definition: qgsrendererv2.cpp:505
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)=0
virtual void stopRender(QgsRenderContext &context)=0
virtual QgsSymbolV2List symbols()=0
for symbol levels
virtual bool renderFeature(QgsFeature &feature, QgsRenderContext &context, int layer=-1, bool selected=false, bool drawVertexMarker=false)
Definition: qgsrendererv2.cpp:214
virtual QgsFeatureRendererV2 * clone() const =0
QString labelAttributeName() const
Definition: qgspointdisplacementrenderer.h:63
void setLabelColor(const QColor &c)
Definition: qgspointdisplacementrenderer.h:82
Definition: qgssymbolv2.h:43
A class to represent a point geometry.
Definition: qgspoint.h:63
QList< QPair< QString, QPixmap > > QgsLegendSymbologyList
Definition: qgspluginlayer.h:20
QgsFeatureRendererV2 * embeddedRenderer() const
Definition: qgspointdisplacementrenderer.h:67
void setCircleRadiusAddition(double d)
Definition: qgspointdisplacementrenderer.h:85
QColor circleColor() const
Definition: qgspointdisplacementrenderer.h:80
virtual void toSld(QDomDocument &doc, QDomElement &element) const
used from subclasses to create SLD Rule elements following SLD v1.1 specs
Definition: qgsrendererv2.h:158
A renderer that automatically displaces points with the same position.
Definition: qgspointdisplacementrenderer.h:31
Definition: qgssymbolv2.h:229
void setCircleWidth(double w)
Definition: qgspointdisplacementrenderer.h:76
QFont labelFont() const
Definition: qgspointdisplacementrenderer.h:74
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:39
Definition: qgsspatialindex.h:44
Q_DECL_DEPRECATED void setDisplacementGroups(const QList< QMap< QgsFeatureId, QgsFeature > > &list)
not available in python bindings
Definition: qgspointdisplacementrenderer.h:71
void setCircleColor(const QColor &c)
Definition: qgspointdisplacementrenderer.h:79
Definition: qgsrendererv2.h:72
Definition: qgssymbolv2.h:167
QgsMarkerSymbolV2 * centerSymbol()
Returns the symbol for the center of a displacement group (but not ownership of the symbol) ...
Definition: qgspointdisplacementrenderer.h:92
QList< QPair< QString, QgsSymbolV2 * > > QgsLegendSymbolList
Definition: qgsrendererv2.h:41
virtual QgsSymbolV2 * symbolForFeature(QgsFeature &feature)=0
to be overridden
QColor labelColor() const
Definition: qgspointdisplacementrenderer.h:83
void setTolerance(double t)
Definition: qgspointdisplacementrenderer.h:96
double circleRadiusAddition() const
Definition: qgspointdisplacementrenderer.h:86