QGIS API Documentation  2.8.2-Wien
 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 
113  : sizeType( MM )
114  , penWidth( 0.0 )
115  , labelPlacementMethod( QgsDiagramSettings::Height )
116  , diagramOrientation( QgsDiagramSettings::Up )
117  , barWidth( 5.0 )
118  , transparency( 0 )
119  , scaleByArea( true )
120  , angleOffset( 90 * 16 ) //top
121  , minScaleDenominator( -1 )
122  , maxScaleDenominator( -1 )
123  , minimumSize( 0.0 )
124  {}
125  QFont font;
126  QList< QColor > categoryColors;
127  QList< QString > categoryAttributes;
128  QSizeF size; //size
129  SizeType sizeType; //mm or map units
131  QColor penColor;
132  double penWidth;
135  double barWidth;
136  int transparency; // 0 - 100
139 
140  //scale range (-1 if no lower / upper bound )
143 
145  double minimumSize;
146 
147  void readXML( const QDomElement& elem, const QgsVectorLayer* layer );
148  void writeXML( QDomElement& rendererElem, QDomDocument& doc, const QgsVectorLayer* layer ) const;
149 };
150 
151 //additional diagram settings for interpolated size rendering
153 {
154  public:
155  QSizeF lowerSize;
156  QSizeF upperSize;
157  double lowerValue;
158  double upperValue;
163 };
164 
166 class CORE_EXPORT QgsDiagramRendererV2
167 {
168  public:
169 
171  virtual ~QgsDiagramRendererV2();
172 
175  virtual QgsDiagramRendererV2* clone() const = 0;
176 
178  virtual QSizeF sizeMapUnits( const QgsFeature& feature, const QgsRenderContext& c );
179 
180  virtual QString rendererName() const = 0;
181 
183  virtual QList<QString> diagramAttributes() const = 0;
184 
185  void renderDiagram( const QgsFeature& feature, QgsRenderContext& c, const QPointF& pos );
186 
187  void setDiagram( QgsDiagram* d );
188  QgsDiagram* diagram() const { return mDiagram; }
189 
191  virtual QList<QgsDiagramSettings> diagramSettings() const = 0;
192 
193  virtual void readXML( const QDomElement& elem, const QgsVectorLayer* layer ) = 0;
194  virtual void writeXML( QDomElement& layerElem, QDomDocument& doc, const QgsVectorLayer* layer ) const = 0;
195 
196  protected:
198 
204  virtual bool diagramSettings( const QgsFeature &feature, const QgsRenderContext& c, QgsDiagramSettings& s ) = 0;
205 
207  virtual QSizeF diagramSize( const QgsFeature& features, const QgsRenderContext& c ) = 0;
208 
210  void convertSizeToMapUnits( QSizeF& size, const QgsRenderContext& context ) const;
211 
213  static int dpiPaintDevice( const QPainter* );
214 
215  //read / write diagram
216  void _readXML( const QDomElement& elem, const QgsVectorLayer* layer );
217  void _writeXML( QDomElement& rendererElem, QDomDocument& doc, const QgsVectorLayer* layer ) const;
218 
221 };
222 
225 {
226  public:
229 
230  QgsDiagramRendererV2* clone() const override;
231 
232  QString rendererName() const override { return "SingleCategory"; }
233 
234  QList<QString> diagramAttributes() const override { return mSettings.categoryAttributes; }
235 
236  void setDiagramSettings( const QgsDiagramSettings& s ) { mSettings = s; }
237 
238  QList<QgsDiagramSettings> diagramSettings() const override;
239 
240  void readXML( const QDomElement& elem, const QgsVectorLayer* layer ) override;
241  void writeXML( QDomElement& layerElem, QDomDocument& doc, const QgsVectorLayer* layer ) const override;
242 
243  protected:
244  bool diagramSettings( const QgsFeature &feature, const QgsRenderContext& c, QgsDiagramSettings& s ) override;
245 
246  QSizeF diagramSize( const QgsFeature&, const QgsRenderContext& c ) override;
247 
248  private:
249  QgsDiagramSettings mSettings;
250 };
251 
253 {
254  public:
257 
258  QgsDiagramRendererV2* clone() const override;
259 
261  QList<QgsDiagramSettings> diagramSettings() const override;
262 
263  void setDiagramSettings( const QgsDiagramSettings& s ) { mSettings = s; }
264 
265  QList<QString> diagramAttributes() const override;
266 
267  QString rendererName() const override { return "LinearlyInterpolated"; }
268 
269  void setLowerValue( double val ) { mInterpolationSettings.lowerValue = val; }
270  double lowerValue() const { return mInterpolationSettings.lowerValue; }
271 
272  void setUpperValue( double val ) { mInterpolationSettings.upperValue = val; }
273  double upperValue() const { return mInterpolationSettings.upperValue; }
274 
275  void setLowerSize( QSizeF s ) { mInterpolationSettings.lowerSize = s; }
276  QSizeF lowerSize() const { return mInterpolationSettings.lowerSize; }
277 
278  void setUpperSize( QSizeF s ) { mInterpolationSettings.upperSize = s; }
279  QSizeF upperSize() const { return mInterpolationSettings.upperSize; }
280 
281  int classificationAttribute() const { return mInterpolationSettings.classificationAttribute; }
282  void setClassificationAttribute( int index ) { mInterpolationSettings.classificationAttribute = index; }
283 
284  QString classificationAttributeExpression() const { return mInterpolationSettings.classificationAttributeExpression; }
285  void setClassificationAttributeExpression( QString expression ) { mInterpolationSettings.classificationAttributeExpression = expression; }
286 
287  bool classificationAttributeIsExpression() const { return mInterpolationSettings.classificationAttributeIsExpression; }
288  void setClassificationAttributeIsExpression( bool isExpression ) { mInterpolationSettings.classificationAttributeIsExpression = isExpression; }
289 
290  void readXML( const QDomElement& elem, const QgsVectorLayer* layer ) override;
291  void writeXML( QDomElement& layerElem, QDomDocument& doc, const QgsVectorLayer* layer ) const override;
292 
293  protected:
294  bool diagramSettings( const QgsFeature &feature, const QgsRenderContext& c, QgsDiagramSettings& s ) override;
295 
296  QSizeF diagramSize( const QgsFeature&, const QgsRenderContext& c ) override;
297 
298  private:
299  QgsDiagramSettings mSettings;
300  QgsDiagramInterpolationSettings mInterpolationSettings;
301 };
302 
303 #endif // QGSDIAGRAMRENDERERV2_H