QGIS API Documentation  2.3.0-Master
 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 
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() { 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 
99  private:
100 
103 
108 
111 
113  double mTolerance;
114 
116  QFont mLabelFont;
117  QColor mLabelColor;
119  double mCircleWidth;
121  QColor mCircleColor;
128 
129  typedef QMap<QgsFeatureId, QgsFeature> DisplacementGroup;
131  QList<DisplacementGroup> mDisplacementGroups;
133  QMap<QgsFeatureId, int> mGroupIndex;
137  QSet<QgsFeatureId> mSelectedFeatures;
138 
140  QgsRectangle searchRect( const QgsPoint& p ) const;
142  void printInfoDisplacementGroups();
143 
145  QString getLabel( const QgsFeature& f );
146 
147  //rendering methods
148  void renderPoint( const QPointF& point, QgsSymbolV2RenderContext& context, const QList<QgsMarkerSymbolV2*>& symbols,
149  const QStringList& labels );
150 
151  //helper functions
152  void calculateSymbolAndLabelPositions( const QPointF& centerPoint, int nPosition, double radius, double symbolDiagonal, QList<QPointF>& symbolPositions, QList<QPointF>& labelShifts ) const;
153  void drawGroup( const DisplacementGroup& group, QgsRenderContext& context );
154  void drawCircle( double radiusPainterUnits, QgsSymbolV2RenderContext& context, const QPointF& centerPoint, int nSymbols );
155  void drawSymbols( const QgsFeature& f, QgsRenderContext& context, const QList<QgsMarkerSymbolV2*>& symbolList, const QList<QPointF>& symbolPositions, bool selected = false );
156  void drawLabels( const QPointF& centerPoint, QgsSymbolV2RenderContext& context, const QList<QPointF>& labelShifts, const QStringList& labelList );
158  QgsSymbolV2* firstSymbolForFeature( QgsFeatureRendererV2* r, QgsFeature& f );
159 };
160 
161 #endif // QGSPOINTDISPLACEMENTRENDERER_H
A rectangle specified with double values.
Definition: qgsrectangle.h:35
QgsMarkerSymbolV2 * mCenterSymbol
Center symbol for a displacement group.
QList< QgsSymbolV2 * > QgsSymbolV2List
Definition: qgsrendererv2.h:37
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:164
virtual QList< QString > usedAttributes()=0
QColor mCircleColor
Color to draw the circle.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:114
double mCircleWidth
Line width for the circle.
virtual QgsLegendSymbologyList legendSymbologyItems(QSize iconSize)
return a list of symbology items for the legend
int mLabelIndex
Label attribute index (or -1 if none).
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)
QFont mLabelFont
Font that is passed to the renderer.
virtual QgsFeatureRendererV2 * clone()=0
QgsFeatureRendererV2 * embeddedRenderer()
QSet< QgsFeatureId > mSelectedFeatures
keeps trask which features are selected
double mMaxLabelScaleDenominator
Maximum scale denominator for label display.
bool mDrawLabels
Is set internally from startRender() depending on scale denominator.
QString mLabelAttributeName
Attribute name for labeling.
A class to represent a point geometry.
Definition: qgspoint.h:63
QList< QPair< QString, QPixmap > > QgsLegendSymbologyList
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.
QMap< QgsFeatureId, QgsFeature > DisplacementGroup
QgsSpatialIndex * mSpatialIndex
Spatial index for fast lookup of close points.
Contains information about the context of a rendering operation.
double mCircleRadiusAddition
Addition to the default circle radius.
QgsFeatureRendererV2 * mRenderer
Embedded renderer.
Q_DECL_DEPRECATED void setDisplacementGroups(const QList< QMap< QgsFeatureId, QgsFeature > > &list)
not available in python bindings
QMap< QgsFeatureId, int > mGroupIndex
Mapping from feature ID to its group index.
QList< DisplacementGroup > mDisplacementGroups
Groups of features that have the same position.
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:41
virtual QgsSymbolV2 * symbolForFeature(QgsFeature &feature)=0
to be overridden