QGIS API Documentation  2.2.0-Valmiera
 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  : placement( AroundPoint )
63  , placementFlags( OnLine )
64  , priority( 5 )
65  , obstacle( false )
66  , dist( 0.0 )
67  , renderer( 0 )
68  , palLayer( 0 )
69  , ct( 0 )
70  , xform( 0 )
71  , xPosColumn( -1 )
72  , yPosColumn( -1 )
73  {
74  }
75 
76  //pal placement properties
79  int priority; // 0 = low, 10 = high
80  bool obstacle; // whether it's an obstacle
81  double dist; // distance from the feature (in mm)
83 
84  //assigned when layer gets prepared
85  pal::Layer* palLayer;
88  QList<QgsPalGeometry*> geometries;
89 
90  int xPosColumn; //attribute index for x coordinate (or -1 if position not data defined)
91  int yPosColumn;//attribute index for y coordinate (or -1 if position not data defined)
92 
93  void readXML( const QDomElement& elem, const QgsVectorLayer* layer );
94  void writeXML( QDomElement& layerElem, QDomDocument& doc, const QgsVectorLayer* layer ) const;
95 };
96 
97 //diagram settings for rendering
98 class CORE_EXPORT QgsDiagramSettings
99 {
100  public:
101  enum SizeType
102  {
103  MM,
104  MapUnits
105  };
106 
108  {
110  XHeight
111  };
112 
115  {
116  Up,
119  Right
120  };
121 
122  QgsDiagramSettings(): sizeType( MM ), minScaleDenominator( -1 ), maxScaleDenominator( -1 )
123  {}
124  QFont font;
125  QList< QColor > categoryColors;
126  QList< QString > categoryAttributes;
127  QSizeF size; //size
128  SizeType sizeType; //mm or map units
130  QColor penColor;
131  double penWidth;
134  double barWidth;
135  int transparency; // 0 - 100
138 
139  //scale range (-1 if no lower / upper bound )
142 
144  double minimumSize;
145 
146  void readXML( const QDomElement& elem, const QgsVectorLayer* layer );
147  void writeXML( QDomElement& rendererElem, QDomDocument& doc, const QgsVectorLayer* layer ) const;
148 };
149 
150 //additional diagram settings for interpolated size rendering
152 {
153  public:
154  QSizeF lowerSize;
155  QSizeF upperSize;
156  double lowerValue;
157  double upperValue;
162 };
163 
165 class CORE_EXPORT QgsDiagramRendererV2
166 {
167  public:
168 
170  virtual ~QgsDiagramRendererV2();
171 
173  virtual QSizeF sizeMapUnits( const QgsFeature& feature, const QgsRenderContext& c );
174 
175  virtual QString rendererName() const = 0;
176 
178  virtual QList<QString> diagramAttributes() const = 0;
179 
180  void renderDiagram( const QgsFeature& feature, QgsRenderContext& c, const QPointF& pos );
181 
182  void setDiagram( QgsDiagram* d );
183  QgsDiagram* diagram() const { return mDiagram; }
184 
186  virtual QList<QgsDiagramSettings> diagramSettings() const = 0;
187 
188  virtual void readXML( const QDomElement& elem, const QgsVectorLayer* layer ) = 0;
189  virtual void writeXML( QDomElement& layerElem, QDomDocument& doc, const QgsVectorLayer* layer ) const = 0;
190 
191  protected:
192 
198  virtual bool diagramSettings( const QgsFeature &feature, const QgsRenderContext& c, QgsDiagramSettings& s ) = 0;
199 
201  virtual QSizeF diagramSize( const QgsFeature& features, const QgsRenderContext& c ) = 0;
202 
204  void convertSizeToMapUnits( QSizeF& size, const QgsRenderContext& context ) const;
205 
207  static int dpiPaintDevice( const QPainter* );
208 
209  //read / write diagram
210  void _readXML( const QDomElement& elem, const QgsVectorLayer* layer );
211  void _writeXML( QDomElement& rendererElem, QDomDocument& doc, const QgsVectorLayer* layer ) const;
212 
214  QgsDiagram* mDiagram;
215 };
216 
219 {
220  public:
223 
224  QString rendererName() const { return "SingleCategory"; }
225 
226  QList<QString> diagramAttributes() const { return mSettings.categoryAttributes; }
227 
228  void setDiagramSettings( const QgsDiagramSettings& s ) { mSettings = s; }
229 
230  QList<QgsDiagramSettings> diagramSettings() const;
231 
232  void readXML( const QDomElement& elem, const QgsVectorLayer* layer );
233  void writeXML( QDomElement& layerElem, QDomDocument& doc, const QgsVectorLayer* layer ) const;
234 
235  protected:
236  bool diagramSettings( const QgsFeature &feature, const QgsRenderContext& c, QgsDiagramSettings& s );
237 
238  QSizeF diagramSize( const QgsFeature&, const QgsRenderContext& c );
239 
240  private:
242 };
243 
245 {
246  public:
249 
251  QList<QgsDiagramSettings> diagramSettings() const;
252 
253  void setDiagramSettings( const QgsDiagramSettings& s ) { mSettings = s; }
254 
255  QList<QString> diagramAttributes() const;
256 
257  QString rendererName() const { return "LinearlyInterpolated"; }
258 
259  void setLowerValue( double val ) { mInterpolationSettings.lowerValue = val; }
260  double lowerValue() const { return mInterpolationSettings.lowerValue; }
261 
262  void setUpperValue( double val ) { mInterpolationSettings.upperValue = val; }
263  double upperValue() const { return mInterpolationSettings.upperValue; }
264 
265  void setLowerSize( QSizeF s ) { mInterpolationSettings.lowerSize = s; }
266  QSizeF lowerSize() const { return mInterpolationSettings.lowerSize; }
267 
268  void setUpperSize( QSizeF s ) { mInterpolationSettings.upperSize = s; }
269  QSizeF upperSize() const { return mInterpolationSettings.upperSize; }
270 
271  int classificationAttribute() const { return mInterpolationSettings.classificationAttribute; }
272  void setClassificationAttribute( int index ) { mInterpolationSettings.classificationAttribute = index; }
273 
274  QString classificationAttributeExpression() const { return mInterpolationSettings.classificationAttributeExpression; }
275  void setClassificationAttributeExpression( QString expression ) { mInterpolationSettings.classificationAttributeExpression = expression; }
276 
277  bool classificationAttributeIsExpression() const { return mInterpolationSettings.classificationAttributeIsExpression; }
278  void setClassificationAttributeIsExpression( bool isExpression ) { mInterpolationSettings.classificationAttributeIsExpression = isExpression; }
279 
280  void readXML( const QDomElement& elem, const QgsVectorLayer* layer );
281  void writeXML( QDomElement& layerElem, QDomDocument& doc, const QgsVectorLayer* layer ) const;
282 
283  protected:
284  bool diagramSettings( const QgsFeature &feature, const QgsRenderContext& c, QgsDiagramSettings& s );
285 
286  QSizeF diagramSize( const QgsFeature&, const QgsRenderContext& c );
287 
288  private:
291 };
292 
293 #endif // QGSDIAGRAMRENDERERV2_H