QGIS API Documentation  2.6.0-Brighton
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsdiagramrendererv2.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsdiagramrendererv2.h
3  ---------------------
4  begin : March 2011
5  copyright : (C) 2011 by Marco Hugentobler
6  email : marco dot hugentobler at sourcepole dot ch
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 #ifndef QGSDIAGRAMRENDERERV2_H
16 #define QGSDIAGRAMRENDERERV2_H
17 
18 #include <QColor>
19 #include <QFont>
20 #include <QList>
21 #include <QPointF>
22 #include <QSizeF>
23 #include <QDomDocument>
24 
25 #include "qgsfeature.h"
26 
27 class QgsDiagram;
29 class QgsFeature;
30 class QgsRenderContext;
31 class QDomElement;
32 class QgsPalGeometry;
34 class QgsMapToPixel;
35 class QgsVectorLayer;
36 
37 namespace pal { class Layer; }
38 
39 class CORE_EXPORT QgsDiagramLayerSettings
40 {
41  public:
42  //avoid inclusion of QgsPalLabeling
43  enum Placement
44  {
45  AroundPoint = 0, // Point / Polygon
46  OverPoint, // Point / Polygon
47  Line, // Line / Polygon
48  Curved, // Line
49  Horizontal, // Polygon
50  Free // Polygon
51  };
52 
54  {
55  OnLine = 1,
56  AboveLine = 2,
57  BelowLine = 4,
58  MapOrientation = 8
59  };
60 
62 
64 
65  //pal placement properties
68  int priority; // 0 = low, 10 = high
69  bool obstacle; // whether it's an obstacle
70  double dist; // distance from the feature (in mm)
71  QgsDiagramRendererV2* renderer; // if any renderer is assigned, it is owned by this class
72 
73  //assigned when layer gets prepared
77  QList<QgsPalGeometry*> geometries;
79 
80  int xPosColumn; //attribute index for x coordinate (or -1 if position not data defined)
81  int yPosColumn;//attribute index for y coordinate (or -1 if position not data defined)
82 
83  void readXML( const QDomElement& elem, const QgsVectorLayer* layer );
84  void writeXML( QDomElement& layerElem, QDomDocument& doc, const QgsVectorLayer* layer ) const;
85 };
86 
87 //diagram settings for rendering
88 class CORE_EXPORT QgsDiagramSettings
89 {
90  public:
91  enum SizeType
92  {
93  MM,
94  MapUnits
95  };
96 
98  {
100  XHeight
101  };
102 
105  {
106  Up,
109  Right
110  };
111 
112  QgsDiagramSettings(): sizeType( MM ), minScaleDenominator( -1 ), maxScaleDenominator( -1 )
113  {}
114  QFont font;
115  QList< QColor > categoryColors;
116  QList< QString > categoryAttributes;
117  QSizeF size; //size
118  SizeType sizeType; //mm or map units
120  QColor penColor;
121  double penWidth;
124  double barWidth;
125  int transparency; // 0 - 100
128 
129  //scale range (-1 if no lower / upper bound )
132 
134  double minimumSize;
135 
136  void readXML( const QDomElement& elem, const QgsVectorLayer* layer );
137  void writeXML( QDomElement& rendererElem, QDomDocument& doc, const QgsVectorLayer* layer ) const;
138 };
139 
140 //additional diagram settings for interpolated size rendering
142 {
143  public:
144  QSizeF lowerSize;
145  QSizeF upperSize;
146  double lowerValue;
147  double upperValue;
152 };
153 
155 class CORE_EXPORT QgsDiagramRendererV2
156 {
157  public:
158 
160  virtual ~QgsDiagramRendererV2();
161 
164  virtual QgsDiagramRendererV2* clone() const = 0;
165 
167  virtual QSizeF sizeMapUnits( const QgsFeature& feature, const QgsRenderContext& c );
168 
169  virtual QString rendererName() const = 0;
170 
172  virtual QList<QString> diagramAttributes() const = 0;
173 
174  void renderDiagram( const QgsFeature& feature, QgsRenderContext& c, const QPointF& pos );
175 
176  void setDiagram( QgsDiagram* d );
177  QgsDiagram* diagram() const { return mDiagram; }
178 
180  virtual QList<QgsDiagramSettings> diagramSettings() const = 0;
181 
182  virtual void readXML( const QDomElement& elem, const QgsVectorLayer* layer ) = 0;
183  virtual void writeXML( QDomElement& layerElem, QDomDocument& doc, const QgsVectorLayer* layer ) const = 0;
184 
185  protected:
187 
193  virtual bool diagramSettings( const QgsFeature &feature, const QgsRenderContext& c, QgsDiagramSettings& s ) = 0;
194 
196  virtual QSizeF diagramSize( const QgsFeature& features, const QgsRenderContext& c ) = 0;
197 
199  void convertSizeToMapUnits( QSizeF& size, const QgsRenderContext& context ) const;
200 
202  static int dpiPaintDevice( const QPainter* );
203 
204  //read / write diagram
205  void _readXML( const QDomElement& elem, const QgsVectorLayer* layer );
206  void _writeXML( QDomElement& rendererElem, QDomDocument& doc, const QgsVectorLayer* layer ) const;
207 
210 };
211 
214 {
215  public:
218 
219  QgsDiagramRendererV2* clone() const;
220 
221  QString rendererName() const { return "SingleCategory"; }
222 
223  QList<QString> diagramAttributes() const { return mSettings.categoryAttributes; }
224 
225  void setDiagramSettings( const QgsDiagramSettings& s ) { mSettings = s; }
226 
227  QList<QgsDiagramSettings> diagramSettings() const;
228 
229  void readXML( const QDomElement& elem, const QgsVectorLayer* layer );
230  void writeXML( QDomElement& layerElem, QDomDocument& doc, const QgsVectorLayer* layer ) const;
231 
232  protected:
233  bool diagramSettings( const QgsFeature &feature, const QgsRenderContext& c, QgsDiagramSettings& s );
234 
235  QSizeF diagramSize( const QgsFeature&, const QgsRenderContext& c );
236 
237  private:
238  QgsDiagramSettings mSettings;
239 };
240 
242 {
243  public:
246 
247  QgsDiagramRendererV2* clone() const;
248 
250  QList<QgsDiagramSettings> diagramSettings() const;
251 
252  void setDiagramSettings( const QgsDiagramSettings& s ) { mSettings = s; }
253 
254  QList<QString> diagramAttributes() const;
255 
256  QString rendererName() const { return "LinearlyInterpolated"; }
257 
258  void setLowerValue( double val ) { mInterpolationSettings.lowerValue = val; }
259  double lowerValue() const { return mInterpolationSettings.lowerValue; }
260 
261  void setUpperValue( double val ) { mInterpolationSettings.upperValue = val; }
262  double upperValue() const { return mInterpolationSettings.upperValue; }
263 
264  void setLowerSize( QSizeF s ) { mInterpolationSettings.lowerSize = s; }
265  QSizeF lowerSize() const { return mInterpolationSettings.lowerSize; }
266 
267  void setUpperSize( QSizeF s ) { mInterpolationSettings.upperSize = s; }
268  QSizeF upperSize() const { return mInterpolationSettings.upperSize; }
269 
270  int classificationAttribute() const { return mInterpolationSettings.classificationAttribute; }
271  void setClassificationAttribute( int index ) { mInterpolationSettings.classificationAttribute = index; }
272 
273  QString classificationAttributeExpression() const { return mInterpolationSettings.classificationAttributeExpression; }
274  void setClassificationAttributeExpression( QString expression ) { mInterpolationSettings.classificationAttributeExpression = expression; }
275 
276  bool classificationAttributeIsExpression() const { return mInterpolationSettings.classificationAttributeIsExpression; }
277  void setClassificationAttributeIsExpression( bool isExpression ) { mInterpolationSettings.classificationAttributeIsExpression = isExpression; }
278 
279  void readXML( const QDomElement& elem, const QgsVectorLayer* layer );
280  void writeXML( QDomElement& layerElem, QDomDocument& doc, const QgsVectorLayer* layer ) const;
281 
282  protected:
283  bool diagramSettings( const QgsFeature &feature, const QgsRenderContext& c, QgsDiagramSettings& s );
284 
285  QSizeF diagramSize( const QgsFeature&, const QgsRenderContext& c );
286 
287  private:
288  QgsDiagramSettings mSettings;
289  QgsDiagramInterpolationSettings mInterpolationSettings;
290 };
291 
292 #endif // QGSDIAGRAMRENDERERV2_H