Quantum GIS API Documentation  1.7.5-Wroclaw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
qgsdiagramrendererv2.h
Go to the documentation of this file.
1 #ifndef QGSDIAGRAMRENDERERV2_H
2 #define QGSDIAGRAMRENDERERV2_H
3 
4 #include <QColor>
5 #include <QFont>
6 #include <QList>
7 #include <QPointF>
8 #include <QSizeF>
9 #include "qgsfeature.h"
10 #include "qgspallabeling.h"
11 
12 class QgsDiagram;
14 class QgsFeature;
15 class QgsRenderContext;
16 class QDomElement;
17 namespace pal { class Layer; }
18 
19 struct CORE_EXPORT QgsDiagramLayerSettings
20 {
21  //avoid inclusion of QgsPalLabeling
22  enum Placement
23  {
24  AroundPoint, // Point / Polygon
25  OverPoint, // Point / Polygon
26  Line, // Line / Polygon
27  Curved, // Line
28  Horizontal, // Polygon
29  Free // Polygon
30  };
31 
33  {
34  OnLine = 1,
35  AboveLine = 2,
36  BelowLine = 4,
37  MapOrientation = 8
38  };
39 
40  QgsDiagramLayerSettings(): placement( AroundPoint ), placementFlags( OnLine ), priority( 5 ), obstacle( false ), dist( 0.0 ), renderer( 0 ),
41  palLayer( 0 ), ct( 0 ), xform( 0 ), xPosColumn( -1 ), yPosColumn( -1 )
42  {
43  }
44 
45  //pal placement properties
48  int priority; // 0 = low, 10 = high
49  bool obstacle; // whether it's an obstacle
50  double dist; // distance from the feature (in mm)
52 
53  //assigned when layer gets prepared
54  pal::Layer* palLayer;
57  QList<QgsPalGeometry*> geometries;
58 
59  int xPosColumn; //attribute index for x coordinate (or -1 if position not data defined)
60  int yPosColumn;//attribute index for y coordinate (or -1 if position not data defined)
61 
62  void readXML( const QDomElement& elem );
63  void writeXML( QDomElement& layerElem, QDomDocument& doc ) const;
64 };
65 
66 //diagram settings for rendering
67 struct CORE_EXPORT QgsDiagramSettings
68 {
69  enum SizeType
70  {
71  MM,
72  MapUnits
73  };
74 
75  QgsDiagramSettings(): sizeType( MM ), minScaleDenominator( -1 ), maxScaleDenominator( -1 )
76  {}
77  QFont font;
78  QList< QColor > categoryColors;
79  QList< int > categoryIndices;
80  QSizeF size; //size
81  SizeType sizeType; //mm or map units
83  QColor penColor;
84  double penWidth;
85 
86  //scale range (-1 if no lower / upper bound )
89 
90  void readXML( const QDomElement& elem );
91  void writeXML( QDomElement& rendererElem, QDomDocument& doc ) const;
92 };
93 
95 class CORE_EXPORT QgsDiagramRendererV2
96 {
97  public:
98 
100  virtual ~QgsDiagramRendererV2();
101 
103  virtual QSizeF sizeMapUnits( const QgsAttributeMap& attributes, const QgsRenderContext& c );
104 
105  virtual QString rendererName() const = 0;
106 
108  virtual QList<int> diagramAttributes() const = 0;
109 
110  void renderDiagram( const QgsAttributeMap& att, QgsRenderContext& c, const QPointF& pos );
111 
112  void setDiagram( QgsDiagram* d );
113  const QgsDiagram* diagram() const { return mDiagram; }
114 
116  virtual QList<QgsDiagramSettings> diagramSettings() const = 0;
117 
118  virtual void readXML( const QDomElement& elem ) = 0;
119  virtual void writeXML( QDomElement& layerElem, QDomDocument& doc ) const = 0;
120 
121  protected:
122 
128  virtual bool diagramSettings( const QgsAttributeMap& att, const QgsRenderContext& c, QgsDiagramSettings& s ) = 0;
129 
131  virtual QSizeF diagramSize( const QgsAttributeMap& attributes, const QgsRenderContext& c ) = 0;
132 
134  void convertSizeToMapUnits( QSizeF& size, const QgsRenderContext& context ) const;
135 
137  static int dpiPaintDevice( const QPainter* );
138 
139  //read / write diagram
140  void _readXML( const QDomElement& elem );
141  void _writeXML( QDomElement& rendererElem, QDomDocument& doc ) const;
142 
145 };
146 
149 {
150  public:
153 
154  QString rendererName() const { return "SingleCategory"; }
155 
156  QList<int> diagramAttributes() const { return mSettings.categoryIndices; }
157 
158  void setDiagramSettings( const QgsDiagramSettings& s ) { mSettings = s; }
159 
160  QList<QgsDiagramSettings> diagramSettings() const;
161 
162  void readXML( const QDomElement& elem );
163  void writeXML( QDomElement& layerElem, QDomDocument& doc ) const;
164 
165  protected:
167 
168  QSizeF diagramSize( const QgsAttributeMap& attributes, const QgsRenderContext& c ) { return mSettings.size; }
169 
170  private:
172 };
173 
175 {
176  public:
179 
181  QList<QgsDiagramSettings> diagramSettings() const;
182 
183  void setDiagramSettings( const QgsDiagramSettings& s ) { mSettings = s; }
184 
185  QList<int> diagramAttributes() const;
186 
187  QString rendererName() const { return "LinearlyInterpolated"; }
188 
189  void setLowerValue( double val ) { mLowerValue = val; }
190  double lowerValue() const { return mLowerValue; }
191 
192  void setUpperValue( double val ) { mUpperValue = val; }
193  double upperValue() const { return mUpperValue; }
194 
195  void setLowerSize( QSizeF s ) { mLowerSize = s; }
196  QSizeF lowerSize() const { return mLowerSize; }
197 
198  void setUpperSize( QSizeF s ) { mUpperSize = s; }
199  QSizeF upperSize() const { return mUpperSize; }
200 
201  int classificationAttribute() const { return mClassificationAttribute; }
202  void setClassificationAttribute( int index ) { mClassificationAttribute = index; }
203 
204  void readXML( const QDomElement& elem );
205  void writeXML( QDomElement& layerElem, QDomDocument& doc ) const;
206 
207  protected:
209 
210  QSizeF diagramSize( const QgsAttributeMap& attributes, const QgsRenderContext& c );
211 
212  private:
214  QSizeF mLowerSize;
215  QSizeF mUpperSize;
216  double mLowerValue;
217  double mUpperValue;
220 };
221 
222 #endif // QGSDIAGRAMRENDERERV2_H