1
#ifndef QGSDIAGRAMRENDERERV2_H
2
#define QGSDIAGRAMRENDERERV2_H
9
#include "qgsfeature.h"
10
#include "qgspallabeling.h"
13
class QgsDiagramRendererV2;
15
class QgsRenderContext;
17
namespace pal { class Layer; }
19
struct CORE_EXPORT QgsDiagramLayerSettings
21
//avoid inclusion of QgsPalLabeling
24
AroundPoint, // Point / Polygon
25
OverPoint, // Point / Polygon
26
Line, // Line / Polygon
28
Horizontal, // Polygon
32
enum LinePlacementFlags
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 )
45
//pal placement properties
47
LinePlacementFlags placementFlags;
48
int priority; // 0 = low, 10 = high
49
bool obstacle; // whether it's an obstacle
50
double dist; // distance from the feature (in mm)
51
QgsDiagramRendererV2* renderer;
53
//assigned when layer gets prepared
55
const QgsCoordinateTransform* ct;
56
const QgsMapToPixel* xform;
57
QList<QgsPalGeometry*> geometries;
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)
62
void readXML( const QDomElement& elem );
63
void writeXML( QDomElement& layerElem, QDomDocument& doc ) const;
66
//diagram settings for rendering
67
struct CORE_EXPORT QgsDiagramSettings
75
QgsDiagramSettings(): sizeType( MM ), minScaleDenominator( -1 ), maxScaleDenominator( -1 )
78
QList< QColor > categoryColors;
79
QList< int > categoryIndices;
81
SizeType sizeType; //mm or map units
82
QColor backgroundColor;
86
//scale range (-1 if no lower / upper bound )
87
double minScaleDenominator;
88
double maxScaleDenominator;
90
void readXML( const QDomElement& elem );
91
void writeXML( QDomElement& rendererElem, QDomDocument& doc ) const;
94
/**Returns diagram settings for a feature*/
95
class CORE_EXPORT QgsDiagramRendererV2
99
QgsDiagramRendererV2();
100
virtual ~QgsDiagramRendererV2();
102
/**Returns size of the diagram for feature f in map units. Returns an invalid QSizeF in case of error*/
103
virtual QSizeF sizeMapUnits( const QgsAttributeMap& attributes, const QgsRenderContext& c );
105
virtual QString rendererName() const = 0;
107
/**Returns attribute indices needed for diagram rendering*/
108
virtual QList<int> diagramAttributes() const = 0;
110
void renderDiagram( const QgsAttributeMap& att, QgsRenderContext& c, const QPointF& pos );
112
void setDiagram( QgsDiagram* d );
113
const QgsDiagram* diagram() const { return mDiagram; }
115
/**Returns list with all diagram settings in the renderer*/
116
virtual QList<QgsDiagramSettings> diagramSettings() const = 0;
118
virtual void readXML( const QDomElement& elem ) = 0;
119
virtual void writeXML( QDomElement& layerElem, QDomDocument& doc ) const = 0;
123
/**Returns diagram settings for a feature (or false if the diagram for the feature is not to be rendered). Used internally within renderDiagram()
124
* @param att attribute map
125
* @param c render context
126
* @param s out: diagram settings for the feature
128
virtual bool diagramSettings( const QgsAttributeMap& att, const QgsRenderContext& c, QgsDiagramSettings& s ) = 0;
130
/**Returns size of the diagram (in painter units) or an invalid size in case of error*/
131
virtual QSizeF diagramSize( const QgsAttributeMap& attributes, const QgsRenderContext& c ) = 0;
133
/**Converts size from mm to map units*/
134
void convertSizeToMapUnits( QSizeF& size, const QgsRenderContext& context ) const;
136
/**Returns the paint device dpi (or -1 in case of error*/
137
static int dpiPaintDevice( const QPainter* );
139
//read / write diagram
140
void _readXML( const QDomElement& elem );
141
void _writeXML( QDomElement& rendererElem, QDomDocument& doc ) const;
143
/**Reference to the object that does the real diagram rendering*/
144
QgsDiagram* mDiagram;
147
/**Renders the diagrams for all features with the same settings*/
148
class CORE_EXPORT QgsSingleCategoryDiagramRenderer: public QgsDiagramRendererV2
151
QgsSingleCategoryDiagramRenderer();
152
~QgsSingleCategoryDiagramRenderer();
154
QString rendererName() const { return "SingleCategory"; }
156
QList<int> diagramAttributes() const { return mSettings.categoryIndices; }
158
void setDiagramSettings( const QgsDiagramSettings& s ) { mSettings = s; }
160
QList<QgsDiagramSettings> diagramSettings() const;
162
void readXML( const QDomElement& elem );
163
void writeXML( QDomElement& layerElem, QDomDocument& doc ) const;
166
bool diagramSettings( const QgsAttributeMap&, const QgsRenderContext& c, QgsDiagramSettings& s );
168
QSizeF diagramSize( const QgsAttributeMap& attributes, const QgsRenderContext& c ) { return mSettings.size; }
171
QgsDiagramSettings mSettings;
174
class CORE_EXPORT QgsLinearlyInterpolatedDiagramRenderer: public QgsDiagramRendererV2
177
QgsLinearlyInterpolatedDiagramRenderer();
178
~QgsLinearlyInterpolatedDiagramRenderer();
180
/**Returns list with all diagram settings in the renderer*/
181
QList<QgsDiagramSettings> diagramSettings() const;
183
void setDiagramSettings( const QgsDiagramSettings& s ) { mSettings = s; }
185
QList<int> diagramAttributes() const;
187
QString rendererName() const { return "LinearlyInterpolated"; }
189
void setLowerValue( double val ) { mLowerValue = val; }
190
double lowerValue() const { return mLowerValue; }
192
void setUpperValue( double val ) { mUpperValue = val; }
193
double upperValue() const { return mUpperValue; }
195
void setLowerSize( QSizeF s ) { mLowerSize = s; }
196
QSizeF lowerSize() const { return mLowerSize; }
198
void setUpperSize( QSizeF s ) { mUpperSize = s; }
199
QSizeF upperSize() const { return mUpperSize; }
201
int classificationAttribute() const { return mClassificationAttribute; }
202
void setClassificationAttribute( int index ) { mClassificationAttribute = index; }
204
void readXML( const QDomElement& elem );
205
void writeXML( QDomElement& layerElem, QDomDocument& doc ) const;
208
bool diagramSettings( const QgsAttributeMap&, const QgsRenderContext& c, QgsDiagramSettings& s );
210
QSizeF diagramSize( const QgsAttributeMap& attributes, const QgsRenderContext& c );
213
QgsDiagramSettings mSettings;
218
/**Index of the classification attribute*/
219
int mClassificationAttribute;
222
#endif // QGSDIAGRAMRENDERERV2_H