~ubuntu-branches/ubuntu/utopic/qgis/utopic

« back to all changes in this revision

Viewing changes to src/core/qgsdiagramrendererv2.h

  • Committer: Package Import Robot
  • Author(s): Francesco Paolo Lovergine
  • Date: 2012-04-24 15:12:20 UTC
  • mfrom: (3.1.9 sid)
  • Revision ID: package-import@ubuntu.com-20120424151220-r88g00af5fpn5fc3
Tags: 1.7.4+1.7.5~20120320-1
The "Sometimes they come back" release.

* Branching from Qgis tree and adapting to current Debian Policy and
  standards. The target tree is currently set to release-1.7.
  (closes: #661491, #606304, #615683, #616182, #600308)
* Policy bumped to 3.9.3.
* Moving to debhelper compatibility level 9.
* Source format is now 3.0 with quilt support.
* Merged with 2bf42287 upstream git snapshot.
* Migrated to dh_python2 instead of python-central.
  (closes: #617048)
* Snapshot in qgis.org release-1.7: c936d031
* Added an automagic creation of a lintian override for sqlite embedding.
  This is required for uploading currently.
* Added missing ${misc:Depends} to make lintian happy.
* Copyright notes updated and debian/copyright moved to format 1.0.
* More licenses notices now reported in debian/copyright. Thanks ftpmasters.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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;
 
13
class QgsDiagramRendererV2;
 
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
 
 
32
  enum LinePlacementFlags
 
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
 
46
  Placement placement;
 
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;
 
52
 
 
53
  //assigned when layer gets prepared
 
54
  pal::Layer* palLayer;
 
55
  const QgsCoordinateTransform* ct;
 
56
  const QgsMapToPixel* xform;
 
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
 
82
  QColor backgroundColor;
 
83
  QColor penColor;
 
84
  double penWidth;
 
85
 
 
86
  //scale range (-1 if no lower / upper bound )
 
87
  double minScaleDenominator;
 
88
  double maxScaleDenominator;
 
89
 
 
90
  void readXML( const QDomElement& elem );
 
91
  void writeXML( QDomElement& rendererElem, QDomDocument& doc ) const;
 
92
};
 
93
 
 
94
/**Returns diagram settings for a feature*/
 
95
class CORE_EXPORT QgsDiagramRendererV2
 
96
{
 
97
  public:
 
98
 
 
99
    QgsDiagramRendererV2();
 
100
    virtual ~QgsDiagramRendererV2();
 
101
 
 
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 );
 
104
 
 
105
    virtual QString rendererName() const = 0;
 
106
 
 
107
    /**Returns attribute indices needed for diagram rendering*/
 
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
 
 
115
    /**Returns list with all diagram settings in the renderer*/
 
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
 
 
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
 
127
     */
 
128
    virtual bool diagramSettings( const QgsAttributeMap& att, const QgsRenderContext& c, QgsDiagramSettings& s ) = 0;
 
129
 
 
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;
 
132
 
 
133
    /**Converts size from mm to map units*/
 
134
    void convertSizeToMapUnits( QSizeF& size, const QgsRenderContext& context ) const;
 
135
 
 
136
    /**Returns the paint device dpi (or -1 in case of error*/
 
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
 
 
143
    /**Reference to the object that does the real diagram rendering*/
 
144
    QgsDiagram* mDiagram;
 
145
};
 
146
 
 
147
/**Renders the diagrams for all features with the same settings*/
 
148
class CORE_EXPORT QgsSingleCategoryDiagramRenderer: public QgsDiagramRendererV2
 
149
{
 
150
  public:
 
151
    QgsSingleCategoryDiagramRenderer();
 
152
    ~QgsSingleCategoryDiagramRenderer();
 
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:
 
166
    bool diagramSettings( const QgsAttributeMap&, const QgsRenderContext& c, QgsDiagramSettings& s );
 
167
 
 
168
    QSizeF diagramSize( const QgsAttributeMap& attributes, const QgsRenderContext& c ) { return mSettings.size; }
 
169
 
 
170
  private:
 
171
    QgsDiagramSettings mSettings;
 
172
};
 
173
 
 
174
class CORE_EXPORT QgsLinearlyInterpolatedDiagramRenderer: public QgsDiagramRendererV2
 
175
{
 
176
  public:
 
177
    QgsLinearlyInterpolatedDiagramRenderer();
 
178
    ~QgsLinearlyInterpolatedDiagramRenderer();
 
179
 
 
180
    /**Returns list with all diagram settings in the renderer*/
 
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:
 
208
    bool diagramSettings( const QgsAttributeMap&, const QgsRenderContext& c, QgsDiagramSettings& s );
 
209
 
 
210
    QSizeF diagramSize( const QgsAttributeMap& attributes, const QgsRenderContext& c );
 
211
 
 
212
  private:
 
213
    QgsDiagramSettings mSettings;
 
214
    QSizeF mLowerSize;
 
215
    QSizeF mUpperSize;
 
216
    double mLowerValue;
 
217
    double mUpperValue;
 
218
    /**Index of the classification attribute*/
 
219
    int mClassificationAttribute;
 
220
};
 
221
 
 
222
#endif // QGSDIAGRAMRENDERERV2_H