QGIS API Documentation  2.5.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 
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 
112  QgsDiagramSettings(): sizeType( MM ), minScaleDenominator( -1 ), maxScaleDenominator( -1 )
113  {}
114  QFont font;
115  QList< QColor > categoryColors;
116  QList< QString > categoryAttributes;
117  QSizeF size; //size
118  SizeType sizeType; //mm or map units
120  QColor penColor;
121  double penWidth;
124  double barWidth;
125  int transparency; // 0 - 100
128 
129  //scale range (-1 if no lower / upper bound )
132 
134  double minimumSize;
135 
136  void readXML( const QDomElement& elem, const QgsVectorLayer* layer );
137  void writeXML( QDomElement& rendererElem, QDomDocument& doc, const QgsVectorLayer* layer ) const;
138 };
139 
140 //additional diagram settings for interpolated size rendering
142 {
143  public:
144  QSizeF lowerSize;
145  QSizeF upperSize;
146  double lowerValue;
147  double upperValue;
152 };
153 
155 class CORE_EXPORT QgsDiagramRendererV2
156 {
157  public:
158 
160  virtual ~QgsDiagramRendererV2();
161 
164  virtual QgsDiagramRendererV2* clone() const = 0;
165 
167  virtual QSizeF sizeMapUnits( const QgsFeature& feature, const QgsRenderContext& c );
168 
169  virtual QString rendererName() const = 0;
170 
172  virtual QList<QString> diagramAttributes() const = 0;
173 
174  void renderDiagram( const QgsFeature& feature, QgsRenderContext& c, const QPointF& pos );
175 
176  void setDiagram( QgsDiagram* d );
177  QgsDiagram* diagram() const { return mDiagram; }
178 
180  virtual QList<QgsDiagramSettings> diagramSettings() const = 0;
181 
182  virtual void readXML( const QDomElement& elem, const QgsVectorLayer* layer ) = 0;
183  virtual void writeXML( QDomElement& layerElem, QDomDocument& doc, const QgsVectorLayer* layer ) const = 0;
184 
185  protected:
187 
193  virtual bool diagramSettings( const QgsFeature &feature, const QgsRenderContext& c, QgsDiagramSettings& s ) = 0;
194 
196  virtual QSizeF diagramSize( const QgsFeature& features, const QgsRenderContext& c ) = 0;
197 
199  void convertSizeToMapUnits( QSizeF& size, const QgsRenderContext& context ) const;
200 
202  static int dpiPaintDevice( const QPainter* );
203 
204  //read / write diagram
205  void _readXML( const QDomElement& elem, const QgsVectorLayer* layer );
206  void _writeXML( QDomElement& rendererElem, QDomDocument& doc, const QgsVectorLayer* layer ) const;
207 
210 };
211 
214 {
215  public:
218 
219  QgsDiagramRendererV2* clone() const;
220 
221  QString rendererName() const { return "SingleCategory"; }
222 
223  QList<QString> diagramAttributes() const { return mSettings.categoryAttributes; }
224 
225  void setDiagramSettings( const QgsDiagramSettings& s ) { mSettings = s; }
226 
227  QList<QgsDiagramSettings> diagramSettings() const;
228 
229  void readXML( const QDomElement& elem, const QgsVectorLayer* layer );
230  void writeXML( QDomElement& layerElem, QDomDocument& doc, const QgsVectorLayer* layer ) const;
231 
232  protected:
233  bool diagramSettings( const QgsFeature &feature, const QgsRenderContext& c, QgsDiagramSettings& s );
234 
235  QSizeF diagramSize( const QgsFeature&, const QgsRenderContext& c );
236 
237  private:
238  QgsDiagramSettings mSettings;
239 };
240 
242 {
243  public:
246 
247  QgsDiagramRendererV2* clone() const;
248 
250  QList<QgsDiagramSettings> diagramSettings() const;
251 
252  void setDiagramSettings( const QgsDiagramSettings& s ) { mSettings = s; }
253 
254  QList<QString> diagramAttributes() const;
255 
256  QString rendererName() const { return "LinearlyInterpolated"; }
257 
258  void setLowerValue( double val ) { mInterpolationSettings.lowerValue = val; }
259  double lowerValue() const { return mInterpolationSettings.lowerValue; }
260 
261  void setUpperValue( double val ) { mInterpolationSettings.upperValue = val; }
262  double upperValue() const { return mInterpolationSettings.upperValue; }
263 
264  void setLowerSize( QSizeF s ) { mInterpolationSettings.lowerSize = s; }
265  QSizeF lowerSize() const { return mInterpolationSettings.lowerSize; }
266 
267  void setUpperSize( QSizeF s ) { mInterpolationSettings.upperSize = s; }
268  QSizeF upperSize() const { return mInterpolationSettings.upperSize; }
269 
270  int classificationAttribute() const { return mInterpolationSettings.classificationAttribute; }
271  void setClassificationAttribute( int index ) { mInterpolationSettings.classificationAttribute = index; }
272 
273  QString classificationAttributeExpression() const { return mInterpolationSettings.classificationAttributeExpression; }
274  void setClassificationAttributeExpression( QString expression ) { mInterpolationSettings.classificationAttributeExpression = expression; }
275 
276  bool classificationAttributeIsExpression() const { return mInterpolationSettings.classificationAttributeIsExpression; }
277  void setClassificationAttributeIsExpression( bool isExpression ) { mInterpolationSettings.classificationAttributeIsExpression = isExpression; }
278 
279  void readXML( const QDomElement& elem, const QgsVectorLayer* layer );
280  void writeXML( QDomElement& layerElem, QDomDocument& doc, const QgsVectorLayer* layer ) const;
281 
282  protected:
283  bool diagramSettings( const QgsFeature &feature, const QgsRenderContext& c, QgsDiagramSettings& s );
284 
285  QSizeF diagramSize( const QgsFeature&, const QgsRenderContext& c );
286 
287  private:
288  QgsDiagramSettings mSettings;
289  QgsDiagramInterpolationSettings mInterpolationSettings;
290 };
291 
292 #endif // QGSDIAGRAMRENDERERV2_H
void setClassificationAttributeIsExpression(bool isExpression)
Definition: qgsdiagramrendererv2.h:277
double minimumSize
Scale diagrams smaller than mMinimumSize to mMinimumSize.
Definition: qgsdiagramrendererv2.h:134
static unsigned index
Definition: mersenne-twister.cpp:36
Definition: qgsdiagramrendererv2.h:106
double minScaleDenominator
Definition: qgsdiagramrendererv2.h:130
Definition: qgsdiagramrendererv2.h:241
int angleOffset
Definition: qgsdiagramrendererv2.h:127
Renders the diagrams for all features with the same settings.
Definition: qgsdiagramrendererv2.h:213
QList< QString > categoryAttributes
Definition: qgsdiagramrendererv2.h:116
Definition: qgsdiagramrendererv2.h:46
virtual QList< QString > diagramAttributes() const =0
Returns attribute indices needed for diagram rendering.
bool scaleByArea
Definition: qgsdiagramrendererv2.h:126
int yPosColumn
Definition: qgsdiagramrendererv2.h:81
bool classificationAttributeIsExpression
Definition: qgsdiagramrendererv2.h:151
QgsDiagram * diagram() const
Definition: qgsdiagramrendererv2.h:177
A layer of spacial entites.
Definition: layer.h:65
virtual QList< QgsDiagramSettings > diagramSettings() const =0
Returns list with all diagram settings in the renderer.
QColor backgroundColor
Definition: qgsdiagramrendererv2.h:119
Container of fields for a vector layer.
Definition: qgsfield.h:172
int transparency
Definition: qgsdiagramrendererv2.h:125
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:113
QgsDiagramSettings()
Definition: qgsdiagramrendererv2.h:112
void setClassificationAttributeExpression(QString expression)
Definition: qgsdiagramrendererv2.h:274
Returns diagram settings for a feature.
Definition: qgsdiagramrendererv2.h:155
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.
QColor penColor
Definition: qgsdiagramrendererv2.h:120
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:33
virtual void writeXML(QDomElement &layerElem, QDomDocument &doc, const QgsVectorLayer *layer) const =0
Placement
Definition: qgsdiagramrendererv2.h:43
DiagramOrientation diagramOrientation
Definition: qgsdiagramrendererv2.h:123
double lowerValue() const
Definition: qgsdiagramrendererv2.h:259
const QgsMapToPixel * xform
Definition: qgsdiagramrendererv2.h:76
int xPosColumn
Definition: qgsdiagramrendererv2.h:80
QSizeF lowerSize() const
Definition: qgsdiagramrendererv2.h:265
bool obstacle
Definition: qgsdiagramrendererv2.h:69
void setDiagramSettings(const QgsDiagramSettings &s)
Definition: qgsdiagramrendererv2.h:225
QString classificationAttributeExpression
Definition: qgsdiagramrendererv2.h:150
void setLowerValue(double val)
Definition: qgsdiagramrendererv2.h:258
QSizeF upperSize() const
Definition: qgsdiagramrendererv2.h:268
LinePlacementFlags
Definition: qgsdiagramrendererv2.h:53
DiagramOrientation
Orientation of histogram.
Definition: qgsdiagramrendererv2.h:104
pal::Layer * palLayer
Definition: qgsdiagramrendererv2.h:74
Definition: qgspalgeometry.h:10
Definition: qgsdiagramrendererv2.h:49
SizeType sizeType
Definition: qgsdiagramrendererv2.h:118
QSizeF upperSize
Definition: qgsdiagramrendererv2.h:145
QgsDiagramRendererV2 * renderer
Definition: qgsdiagramrendererv2.h:71
Placement placement
Definition: qgsdiagramrendererv2.h:66
QFont font
Definition: qgsdiagramrendererv2.h:114
double barWidth
Definition: qgsdiagramrendererv2.h:124
Definition: qgsdiagramrendererv2.h:108
Definition: qgsdiagramrendererv2.h:48
Base class for all diagram types.
Definition: qgsdiagram.h:34
double dist
Definition: qgsdiagramrendererv2.h:70
double lowerValue
Definition: qgsdiagramrendererv2.h:146
double penWidth
Definition: qgsdiagramrendererv2.h:121
double upperValue
Definition: qgsdiagramrendererv2.h:147
void setUpperSize(QSizeF s)
Definition: qgsdiagramrendererv2.h:267
Definition: qgsdiagramrendererv2.h:39
Definition: qgsdiagramrendererv2.h:37
int classificationAttribute() const
Definition: qgsdiagramrendererv2.h:270
Definition: qgsdiagramrendererv2.h:141
LabelPlacementMethod
Definition: qgsdiagramrendererv2.h:97
QgsFields fields
Definition: qgsdiagramrendererv2.h:78
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:39
Definition: qgsdiagramrendererv2.h:99
QSizeF lowerSize
Definition: qgsdiagramrendererv2.h:144
double maxScaleDenominator
Definition: qgsdiagramrendererv2.h:131
bool classificationAttributeIsExpression() const
Definition: qgsdiagramrendererv2.h:276
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.
Definition: qgscoordinatetransform.h:52
QList< QString > diagramAttributes() const
Returns attribute indices needed for diagram rendering.
Definition: qgsdiagramrendererv2.h:223
int priority
Definition: qgsdiagramrendererv2.h:68
void setClassificationAttribute(int index)
Definition: qgsdiagramrendererv2.h:271
int classificationAttribute
Index of the classification attribute.
Definition: qgsdiagramrendererv2.h:149
QList< QgsPalGeometry * > geometries
Definition: qgsdiagramrendererv2.h:77
SizeType
Definition: qgsdiagramrendererv2.h:91
QSizeF size
Definition: qgsdiagramrendererv2.h:117
void setDiagramSettings(const QgsDiagramSettings &s)
Definition: qgsdiagramrendererv2.h:252
QString classificationAttributeExpression() const
Definition: qgsdiagramrendererv2.h:273
QString rendererName() const
Definition: qgsdiagramrendererv2.h:256
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:468
double size
Definition: qgssvgcache.cpp:77
QList< QColor > categoryColors
Definition: qgsdiagramrendererv2.h:115
double upperValue() const
Definition: qgsdiagramrendererv2.h:262
Definition: qgsdiagramrendererv2.h:93
QgsDiagram * mDiagram
Reference to the object that does the real diagram rendering.
Definition: qgsdiagramrendererv2.h:209
Definition: qgsdiagramrendererv2.h:47
void setLowerSize(QSizeF s)
Definition: qgsdiagramrendererv2.h:264
const QgsCoordinateTransform * ct
Definition: qgsdiagramrendererv2.h:75
Definition: qgsdiagramrendererv2.h:88
QString rendererName() const
Definition: qgsdiagramrendererv2.h:221
LabelPlacementMethod labelPlacementMethod
Definition: qgsdiagramrendererv2.h:122
LinePlacementFlags placementFlags
Definition: qgsdiagramrendererv2.h:67
Definition: qgsdiagramrendererv2.h:107
void setUpperValue(double val)
Definition: qgsdiagramrendererv2.h:261