QGIS API Documentation  2.9.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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  bool showAll;
83 
84  void readXML( const QDomElement& elem, const QgsVectorLayer* layer );
85  void writeXML( QDomElement& layerElem, QDomDocument& doc, const QgsVectorLayer* layer ) const;
86 };
87 
88 //diagram settings for rendering
89 class CORE_EXPORT QgsDiagramSettings
90 {
91  public:
92  enum SizeType
93  {
94  MM,
95  MapUnits
96  };
97 
99  {
101  XHeight
102  };
103 
106  {
107  Up,
110  Right
111  };
112 
114  : enabled( true )
115  , sizeType( MM )
116  , penWidth( 0.0 )
117  , labelPlacementMethod( QgsDiagramSettings::Height )
118  , diagramOrientation( QgsDiagramSettings::Up )
119  , barWidth( 5.0 )
120  , transparency( 0 )
121  , scaleByArea( true )
122  , angleOffset( 90 * 16 ) //top
123  , minScaleDenominator( -1 )
124  , maxScaleDenominator( -1 )
125  , minimumSize( 0.0 )
126  {}
127  bool enabled;
128  QFont font;
129  QList< QColor > categoryColors;
130  QList< QString > categoryAttributes;
131  QSizeF size; //size
132  SizeType sizeType; //mm or map units
134  QColor penColor;
135  double penWidth;
138  double barWidth;
139  int transparency; // 0 - 100
142 
143  //scale range (-1 if no lower / upper bound )
146 
148  double minimumSize;
149 
150  void readXML( const QDomElement& elem, const QgsVectorLayer* layer );
151  void writeXML( QDomElement& rendererElem, QDomDocument& doc, const QgsVectorLayer* layer ) const;
152 };
153 
154 //additional diagram settings for interpolated size rendering
156 {
157  public:
158  QSizeF lowerSize;
159  QSizeF upperSize;
160  double lowerValue;
161  double upperValue;
166 };
167 
169 class CORE_EXPORT QgsDiagramRendererV2
170 {
171  public:
172 
174  virtual ~QgsDiagramRendererV2();
175 
178  virtual QgsDiagramRendererV2* clone() const = 0;
179 
181  virtual QSizeF sizeMapUnits( const QgsFeature& feature, const QgsRenderContext& c );
182 
183  virtual QString rendererName() const = 0;
184 
186  virtual QList<QString> diagramAttributes() const = 0;
187 
188  void renderDiagram( const QgsFeature& feature, QgsRenderContext& c, const QPointF& pos );
189 
190  void setDiagram( QgsDiagram* d );
191  QgsDiagram* diagram() const { return mDiagram; }
192 
194  virtual QList<QgsDiagramSettings> diagramSettings() const = 0;
195 
196  virtual void readXML( const QDomElement& elem, const QgsVectorLayer* layer ) = 0;
197  virtual void writeXML( QDomElement& layerElem, QDomDocument& doc, const QgsVectorLayer* layer ) const = 0;
198 
199  protected:
201 
207  virtual bool diagramSettings( const QgsFeature &feature, const QgsRenderContext& c, QgsDiagramSettings& s ) = 0;
208 
210  virtual QSizeF diagramSize( const QgsFeature& features, const QgsRenderContext& c ) = 0;
211 
213  void convertSizeToMapUnits( QSizeF& size, const QgsRenderContext& context ) const;
214 
216  static int dpiPaintDevice( const QPainter* );
217 
218  //read / write diagram
219  void _readXML( const QDomElement& elem, const QgsVectorLayer* layer );
220  void _writeXML( QDomElement& rendererElem, QDomDocument& doc, const QgsVectorLayer* layer ) const;
221 
224 };
225 
228 {
229  public:
232 
233  QgsDiagramRendererV2* clone() const override;
234 
235  QString rendererName() const override { return "SingleCategory"; }
236 
237  QList<QString> diagramAttributes() const override { return mSettings.categoryAttributes; }
238 
239  void setDiagramSettings( const QgsDiagramSettings& s ) { mSettings = s; }
240 
241  QList<QgsDiagramSettings> diagramSettings() const override;
242 
243  void readXML( const QDomElement& elem, const QgsVectorLayer* layer ) override;
244  void writeXML( QDomElement& layerElem, QDomDocument& doc, const QgsVectorLayer* layer ) const override;
245 
246  protected:
247  bool diagramSettings( const QgsFeature &feature, const QgsRenderContext& c, QgsDiagramSettings& s ) override;
248 
249  QSizeF diagramSize( const QgsFeature&, const QgsRenderContext& c ) override;
250 
251  private:
252  QgsDiagramSettings mSettings;
253 };
254 
256 {
257  public:
260 
261  QgsDiagramRendererV2* clone() const override;
262 
264  QList<QgsDiagramSettings> diagramSettings() const override;
265 
266  void setDiagramSettings( const QgsDiagramSettings& s ) { mSettings = s; }
267 
268  QList<QString> diagramAttributes() const override;
269 
270  QString rendererName() const override { return "LinearlyInterpolated"; }
271 
272  void setLowerValue( double val ) { mInterpolationSettings.lowerValue = val; }
273  double lowerValue() const { return mInterpolationSettings.lowerValue; }
274 
275  void setUpperValue( double val ) { mInterpolationSettings.upperValue = val; }
276  double upperValue() const { return mInterpolationSettings.upperValue; }
277 
278  void setLowerSize( QSizeF s ) { mInterpolationSettings.lowerSize = s; }
279  QSizeF lowerSize() const { return mInterpolationSettings.lowerSize; }
280 
281  void setUpperSize( QSizeF s ) { mInterpolationSettings.upperSize = s; }
282  QSizeF upperSize() const { return mInterpolationSettings.upperSize; }
283 
284  int classificationAttribute() const { return mInterpolationSettings.classificationAttribute; }
285  void setClassificationAttribute( int index ) { mInterpolationSettings.classificationAttribute = index; }
286 
287  QString classificationAttributeExpression() const { return mInterpolationSettings.classificationAttributeExpression; }
288  void setClassificationAttributeExpression( QString expression ) { mInterpolationSettings.classificationAttributeExpression = expression; }
289 
290  bool classificationAttributeIsExpression() const { return mInterpolationSettings.classificationAttributeIsExpression; }
291  void setClassificationAttributeIsExpression( bool isExpression ) { mInterpolationSettings.classificationAttributeIsExpression = isExpression; }
292 
293  void readXML( const QDomElement& elem, const QgsVectorLayer* layer ) override;
294  void writeXML( QDomElement& layerElem, QDomDocument& doc, const QgsVectorLayer* layer ) const override;
295 
296  protected:
297  bool diagramSettings( const QgsFeature &feature, const QgsRenderContext& c, QgsDiagramSettings& s ) override;
298 
299  QSizeF diagramSize( const QgsFeature&, const QgsRenderContext& c ) override;
300 
301  private:
302  QgsDiagramSettings mSettings;
303  QgsDiagramInterpolationSettings mInterpolationSettings;
304 };
305 
306 #endif // QGSDIAGRAMRENDERERV2_H
void setClassificationAttributeIsExpression(bool isExpression)
double minimumSize
Scale diagrams smaller than mMinimumSize to mMinimumSize.
static unsigned index
Renders the diagrams for all features with the same settings.
QList< QString > categoryAttributes
virtual QList< QString > diagramAttributes() const =0
Returns attribute indices needed for diagram rendering.
QgsDiagram * diagram() const
A layer of spacial entites.
Definition: layer.h:65
virtual QList< QgsDiagramSettings > diagramSettings() const =0
Returns list with all diagram settings in the renderer.
Container of fields for a vector layer.
Definition: qgsfield.h:172
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:113
void setClassificationAttributeExpression(QString expression)
Returns diagram settings for a feature.
virtual QSizeF diagramSize(const QgsFeature &features, const QgsRenderContext &c)=0
Returns size of the diagram (in painter units) or an invalid size in case of error.
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:34
virtual void writeXML(QDomElement &layerElem, QDomDocument &doc, const QgsVectorLayer *layer) const =0
DiagramOrientation diagramOrientation
const QgsMapToPixel * xform
QList< QString > diagramAttributes() const override
Returns attribute indices needed for diagram rendering.
void setDiagramSettings(const QgsDiagramSettings &s)
DiagramOrientation
Orientation of histogram.
QgsDiagramRendererV2 * renderer
QString rendererName() const override
Base class for all diagram types.
Definition: qgsdiagram.h:34
Contains information about the context of a rendering operation.
virtual void readXML(const QDomElement &elem, const QgsVectorLayer *layer)=0
virtual QgsDiagramRendererV2 * clone() const =0
Returns new instance that is equivalent to this one.
Class for doing transforms between two map coordinate systems.
int classificationAttribute
Index of the classification attribute.
QList< QgsPalGeometry * > geometries
void setDiagramSettings(const QgsDiagramSettings &s)
Represents a vector layer which manages a vector based data sets.
double size
Definition: qgssvgcache.cpp:77
QList< QColor > categoryColors
QgsDiagram * mDiagram
Reference to the object that does the real diagram rendering.
const QgsCoordinateTransform * ct
LabelPlacementMethod labelPlacementMethod
LinePlacementFlags placementFlags