QGIS API Documentation  2.0.1-Dufour
 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< int > categoryIndices;
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;
160 };
161 
163 class CORE_EXPORT QgsDiagramRendererV2
164 {
165  public:
166 
168  virtual ~QgsDiagramRendererV2();
169 
171  virtual QSizeF sizeMapUnits( const QgsAttributes& attributes, const QgsRenderContext& c );
172 
173  virtual QString rendererName() const = 0;
174 
176  virtual QList<int> diagramAttributes() const = 0;
177 
178  void renderDiagram( const QgsAttributes& att, QgsRenderContext& c, const QPointF& pos );
179 
180  void setDiagram( QgsDiagram* d );
181  const QgsDiagram* diagram() const { return mDiagram; }
182 
184  virtual QList<QgsDiagramSettings> diagramSettings() const = 0;
185 
186  virtual void readXML( const QDomElement& elem, const QgsVectorLayer* layer ) = 0;
187  virtual void writeXML( QDomElement& layerElem, QDomDocument& doc, const QgsVectorLayer* layer ) const = 0;
188 
189  protected:
190 
196  virtual bool diagramSettings( const QgsAttributes& att, const QgsRenderContext& c, QgsDiagramSettings& s ) = 0;
197 
199  virtual QSizeF diagramSize( const QgsAttributes& attributes, const QgsRenderContext& c ) = 0;
200 
202  void convertSizeToMapUnits( QSizeF& size, const QgsRenderContext& context ) const;
203 
205  static int dpiPaintDevice( const QPainter* );
206 
207  //read / write diagram
208  void _readXML( const QDomElement& elem, const QgsVectorLayer* layer );
209  void _writeXML( QDomElement& rendererElem, QDomDocument& doc, const QgsVectorLayer* layer ) const;
210 
212  QgsDiagram* mDiagram;
213 };
214 
217 {
218  public:
221 
222  QString rendererName() const { return "SingleCategory"; }
223 
224  QList<int> diagramAttributes() const { return mSettings.categoryIndices; }
225 
226  void setDiagramSettings( const QgsDiagramSettings& s ) { mSettings = s; }
227 
228  QList<QgsDiagramSettings> diagramSettings() const;
229 
230  void readXML( const QDomElement& elem, const QgsVectorLayer* layer );
231  void writeXML( QDomElement& layerElem, QDomDocument& doc, const QgsVectorLayer* layer ) const;
232 
233  protected:
235 
236  QSizeF diagramSize( const QgsAttributes& attributes, const QgsRenderContext& c );
237 
238  private:
240 };
241 
243 {
244  public:
247 
249  QList<QgsDiagramSettings> diagramSettings() const;
250 
251  void setDiagramSettings( const QgsDiagramSettings& s ) { mSettings = s; }
252 
253  QList<int> diagramAttributes() const;
254 
255  QString rendererName() const { return "LinearlyInterpolated"; }
256 
257  void setLowerValue( double val ) { mInterpolationSettings.lowerValue = val; }
258  double lowerValue() const { return mInterpolationSettings.lowerValue; }
259 
260  void setUpperValue( double val ) { mInterpolationSettings.upperValue = val; }
261  double upperValue() const { return mInterpolationSettings.upperValue; }
262 
263  void setLowerSize( QSizeF s ) { mInterpolationSettings.lowerSize = s; }
264  QSizeF lowerSize() const { return mInterpolationSettings.lowerSize; }
265 
266  void setUpperSize( QSizeF s ) { mInterpolationSettings.upperSize = s; }
267  QSizeF upperSize() const { return mInterpolationSettings.upperSize; }
268 
269  int classificationAttribute() const { return mInterpolationSettings.classificationAttribute; }
270  void setClassificationAttribute( int index ) { mInterpolationSettings.classificationAttribute = index; }
271 
272  void readXML( const QDomElement& elem, const QgsVectorLayer* layer );
273  void writeXML( QDomElement& layerElem, QDomDocument& doc, const QgsVectorLayer* layer ) const;
274 
275  protected:
277 
278  QSizeF diagramSize( const QgsAttributes& attributes, const QgsRenderContext& c );
279 
280  private:
283 };
284 
285 #endif // QGSDIAGRAMRENDERERV2_H