@@ -1,658 +1,658 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qabstractaxis.h" |
|
21 | #include "qabstractaxis.h" | |
22 | #include "qabstractaxis_p.h" |
|
22 | #include "qabstractaxis_p.h" | |
23 |
|
23 | |||
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
25 |
|
25 | |||
26 | /*! |
|
26 | /*! | |
27 | \class QAbstractAxis |
|
27 | \class QAbstractAxis | |
28 | \brief The QAbstractAxis class is used for manipulating chart's axis. |
|
28 | \brief The QAbstractAxis class is used for manipulating chart's axis. | |
29 | \mainclass |
|
29 | \mainclass | |
30 |
|
30 | |||
31 | There is only one x Axis visible at the time, however there can be multiple y axes. |
|
31 | There is only one x Axis visible at the time, however there can be multiple y axes. | |
32 | Each chart series can be bound to exactly one Y axis and the shared common X axis. |
|
32 | Each chart series can be bound to exactly one Y axis and the shared common X axis. | |
33 | Axis can be setup to show axis line with tick marks, grid lines and shades. |
|
33 | Axis can be setup to show axis line with tick marks, grid lines and shades. | |
34 | */ |
|
34 | */ | |
35 |
|
35 | |||
36 | /*! |
|
36 | /*! | |
37 | \qmlclass AbstractAxis QAbstractAxis |
|
37 | \qmlclass AbstractAxis QAbstractAxis | |
38 | \brief The Axis element is used for manipulating chart's axes |
|
38 | \brief The Axis element is used for manipulating chart's axes | |
39 |
|
39 | |||
40 | There is only one x Axis visible at the time, however there can be multiple y axes on a ChartView. |
|
40 | There is only one x Axis visible at the time, however there can be multiple y axes on a ChartView. | |
41 | Each chart series can be bound to exactly one Y axis and the shared common X axis. |
|
41 | Each chart series can be bound to exactly one Y axis and the shared common X axis. | |
42 | Axis can be setup to show axis line with tick marks, grid lines and shades. |
|
42 | Axis can be setup to show axis line with tick marks, grid lines and shades. | |
43 |
|
43 | |||
44 | To access Axes you can use ChartView API. For example: |
|
44 | To access Axes you can use ChartView API. For example: | |
45 | \code |
|
45 | \code | |
46 | ChartView { |
|
46 | ChartView { | |
47 | axisX.min: 0 |
|
47 | axisX.min: 0 | |
48 | axisX.max: 3 |
|
48 | axisX.max: 3 | |
49 | axisX.ticksCount: 4 |
|
49 | axisX.ticksCount: 4 | |
50 | axisY.min: 0 |
|
50 | axisY.min: 0 | |
51 | axisY.max: 4 |
|
51 | axisY.max: 4 | |
52 | // Add a few series... |
|
52 | // Add a few series... | |
53 | } |
|
53 | } | |
54 | \endcode |
|
54 | \endcode | |
55 | */ |
|
55 | */ | |
56 |
|
56 | |||
57 | /*! |
|
57 | /*! | |
58 | \enum QAbstractAxis::AxisType |
|
58 | \enum QAbstractAxis::AxisType | |
59 |
|
59 | |||
60 | The type of the series object. |
|
60 | The type of the series object. | |
61 |
|
61 | |||
62 | \value AxisTypeNoAxis |
|
62 | \value AxisTypeNoAxis | |
63 | \value AxisTypeValue |
|
63 | \value AxisTypeValue | |
64 | \value AxisTypeBarCategory |
|
64 | \value AxisTypeBarCategory | |
65 | \value AxisTypeCategory |
|
65 | \value AxisTypeCategory | |
66 | \value AxisTypeDateTime |
|
66 | \value AxisTypeDateTime | |
67 | */ |
|
67 | */ | |
68 |
|
68 | |||
69 | /*! |
|
69 | /*! | |
70 | *\fn void QAbstractAxis::type() const |
|
70 | *\fn void QAbstractAxis::type() const | |
71 | Returns the type of the axis |
|
71 | Returns the type of the axis | |
72 | */ |
|
72 | */ | |
73 |
|
73 | |||
74 | /*! |
|
74 | /*! | |
75 | \property QAbstractAxis::lineVisible |
|
75 | \property QAbstractAxis::lineVisible | |
76 | The visibility of the axis line |
|
76 | The visibility of the axis line | |
77 | */ |
|
77 | */ | |
78 | /*! |
|
78 | /*! | |
79 | \qmlproperty bool AbstractAxis::lineVisible |
|
79 | \qmlproperty bool AbstractAxis::lineVisible | |
80 | The visibility of the axis line |
|
80 | The visibility of the axis line | |
81 | */ |
|
81 | */ | |
82 |
|
82 | |||
83 | /*! |
|
83 | /*! | |
84 | \property QAbstractAxis::labelsVisible |
|
84 | \property QAbstractAxis::labelsVisible | |
85 | Defines if axis labels are visible. |
|
85 | Defines if axis labels are visible. | |
86 | */ |
|
86 | */ | |
87 | /*! |
|
87 | /*! | |
88 | \qmlproperty bool AbstractAxis::labelsVisible |
|
88 | \qmlproperty bool AbstractAxis::labelsVisible | |
89 | Defines if axis labels are visible. |
|
89 | Defines if axis labels are visible. | |
90 | */ |
|
90 | */ | |
91 |
|
91 | |||
92 | /*! |
|
92 | /*! | |
93 | \property QAbstractAxis::visible |
|
93 | \property QAbstractAxis::visible | |
94 | The visibility of the axis. |
|
94 | The visibility of the axis. | |
95 | */ |
|
95 | */ | |
96 | /*! |
|
96 | /*! | |
97 | \qmlproperty bool AbstractAxis::visible |
|
97 | \qmlproperty bool AbstractAxis::visible | |
98 | The visibility of the axis. |
|
98 | The visibility of the axis. | |
99 | */ |
|
99 | */ | |
100 |
|
100 | |||
101 | /*! |
|
101 | /*! | |
102 | \property QAbstractAxis::gridVisible |
|
102 | \property QAbstractAxis::gridVisible | |
103 | The visibility of the grid lines. |
|
103 | The visibility of the grid lines. | |
104 | */ |
|
104 | */ | |
105 | /*! |
|
105 | /*! | |
106 | \qmlproperty bool AbstractAxis::gridVisible |
|
106 | \qmlproperty bool AbstractAxis::gridVisible | |
107 | The visibility of the grid lines. |
|
107 | The visibility of the grid lines. | |
108 | */ |
|
108 | */ | |
109 |
|
109 | |||
110 | /*! |
|
110 | /*! | |
111 | \property QAbstractAxis::color |
|
111 | \property QAbstractAxis::color | |
112 | The color of the axis and ticks. |
|
112 | The color of the axis and ticks. | |
113 | */ |
|
113 | */ | |
114 | /*! |
|
114 | /*! | |
115 | \qmlproperty color AbstractAxis::color |
|
115 | \qmlproperty color AbstractAxis::color | |
116 | The color of the axis and ticks. |
|
116 | The color of the axis and ticks. | |
117 | */ |
|
117 | */ | |
118 |
|
118 | |||
119 | /*! |
|
119 | /*! | |
120 | \property QAbstractAxis::labelsFont |
|
120 | \property QAbstractAxis::labelsFont | |
121 | The font of the axis labels. |
|
121 | The font of the axis labels. | |
122 | */ |
|
122 | */ | |
123 |
|
123 | |||
124 | /*! |
|
124 | /*! | |
125 | \qmlproperty Font AbstractAxis::labelsFont |
|
125 | \qmlproperty Font AbstractAxis::labelsFont | |
126 | The font of the axis labels. |
|
126 | The font of the axis labels. | |
127 |
|
127 | |||
128 | See the \l {Font} {QML Font Element} for detailed documentation. |
|
128 | See the \l {Font} {QML Font Element} for detailed documentation. | |
129 | */ |
|
129 | */ | |
130 |
|
130 | |||
131 | /*! |
|
131 | /*! | |
132 | \property QAbstractAxis::labelsColor |
|
132 | \property QAbstractAxis::labelsColor | |
133 | The color of the axis labels. |
|
133 | The color of the axis labels. | |
134 | */ |
|
134 | */ | |
135 | /*! |
|
135 | /*! | |
136 | \qmlproperty color AbstractAxis::labelsColor |
|
136 | \qmlproperty color AbstractAxis::labelsColor | |
137 | The color of the axis labels. |
|
137 | The color of the axis labels. | |
138 | */ |
|
138 | */ | |
139 |
|
139 | |||
140 | /*! |
|
140 | /*! | |
141 | \property QAbstractAxis::labelsAngle |
|
141 | \property QAbstractAxis::labelsAngle | |
142 | The angle of the axis labels in degrees. |
|
142 | The angle of the axis labels in degrees. | |
143 | */ |
|
143 | */ | |
144 | /*! |
|
144 | /*! | |
145 | \qmlproperty int AbstractAxis::labelsAngle |
|
145 | \qmlproperty int AbstractAxis::labelsAngle | |
146 | The angle of the axis labels in degrees. |
|
146 | The angle of the axis labels in degrees. | |
147 | */ |
|
147 | */ | |
148 |
|
148 | |||
149 | /*! |
|
149 | /*! | |
150 | \property QAbstractAxis::shadesVisible |
|
150 | \property QAbstractAxis::shadesVisible | |
151 | The visibility of the axis shades. |
|
151 | The visibility of the axis shades. | |
152 | */ |
|
152 | */ | |
153 | /*! |
|
153 | /*! | |
154 | \qmlproperty bool AbstractAxis::shadesVisible |
|
154 | \qmlproperty bool AbstractAxis::shadesVisible | |
155 | The visibility of the axis shades. |
|
155 | The visibility of the axis shades. | |
156 | */ |
|
156 | */ | |
157 |
|
157 | |||
158 | /*! |
|
158 | /*! | |
159 | \property QAbstractAxis::shadesColor |
|
159 | \property QAbstractAxis::shadesColor | |
160 | The fill (brush) color of the axis shades. |
|
160 | The fill (brush) color of the axis shades. | |
161 | */ |
|
161 | */ | |
162 | /*! |
|
162 | /*! | |
163 | \qmlproperty color AbstractAxis::shadesColor |
|
163 | \qmlproperty color AbstractAxis::shadesColor | |
164 | The fill (brush) color of the axis shades. |
|
164 | The fill (brush) color of the axis shades. | |
165 | */ |
|
165 | */ | |
166 |
|
166 | |||
167 | /*! |
|
167 | /*! | |
168 | \property QAbstractAxis::shadesBorderColor |
|
168 | \property QAbstractAxis::shadesBorderColor | |
169 | The border (pen) color of the axis shades. |
|
169 | The border (pen) color of the axis shades. | |
170 | */ |
|
170 | */ | |
171 | /*! |
|
171 | /*! | |
172 | \qmlproperty color AbstractAxis::shadesBorderColor |
|
172 | \qmlproperty color AbstractAxis::shadesBorderColor | |
173 | The border (pen) color of the axis shades. |
|
173 | The border (pen) color of the axis shades. | |
174 | */ |
|
174 | */ | |
175 |
|
175 | |||
176 | /*! |
|
176 | /*! | |
177 | \fn void QAbstractAxis::visibleChanged(bool visible) |
|
177 | \fn void QAbstractAxis::visibleChanged(bool visible) | |
178 | Visiblity of the axis has changed to \a visible. |
|
178 | Visibility of the axis has changed to \a visible. | |
179 | */ |
|
179 | */ | |
180 | /*! |
|
180 | /*! | |
181 | \qmlsignal AbstractAxis::onVisibleChanged(bool visible) |
|
181 | \qmlsignal AbstractAxis::onVisibleChanged(bool visible) | |
182 | Visiblity of the axis has changed to \a visible. |
|
182 | Visibility of the axis has changed to \a visible. | |
183 | */ |
|
183 | */ | |
184 |
|
184 | |||
185 | /*! |
|
185 | /*! | |
186 | \fn void QAbstractAxis::lineVisibleChanged(bool visible) |
|
186 | \fn void QAbstractAxis::lineVisibleChanged(bool visible) | |
187 | Visiblity of the axis line has changed to \a visible. |
|
187 | Visibility of the axis line has changed to \a visible. | |
188 | */ |
|
188 | */ | |
189 | /*! |
|
189 | /*! | |
190 | \qmlsignal AbstractAxis::onLineVisibleChanged(bool visible) |
|
190 | \qmlsignal AbstractAxis::onLineVisibleChanged(bool visible) | |
191 | Visiblity of the axis line has changed to \a visible. |
|
191 | Visibility of the axis line has changed to \a visible. | |
192 | */ |
|
192 | */ | |
193 |
|
193 | |||
194 | /*! |
|
194 | /*! | |
195 | \fn void QAbstractAxis::labelsVisibleChanged(bool visible) |
|
195 | \fn void QAbstractAxis::labelsVisibleChanged(bool visible) | |
196 | Visiblity of the labels of the axis has changed to \a visible. |
|
196 | Visibility of the labels of the axis has changed to \a visible. | |
197 | */ |
|
197 | */ | |
198 | /*! |
|
198 | /*! | |
199 | \qmlsignal AbstractAxis::onLabelsVisibleChanged(bool visible) |
|
199 | \qmlsignal AbstractAxis::onLabelsVisibleChanged(bool visible) | |
200 | Visiblity of the labels of the axis has changed to \a visible. |
|
200 | Visibility of the labels of the axis has changed to \a visible. | |
201 | */ |
|
201 | */ | |
202 |
|
202 | |||
203 | /*! |
|
203 | /*! | |
204 | \fn void QAbstractAxis::gridVisibleChanged(bool visible) |
|
204 | \fn void QAbstractAxis::gridVisibleChanged(bool visible) | |
205 | Visiblity of the grid lines of the axis has changed to \a visible. |
|
205 | Visibility of the grid lines of the axis has changed to \a visible. | |
206 | */ |
|
206 | */ | |
207 | /*! |
|
207 | /*! | |
208 | \qmlsignal AbstractAxis::onGridVisibleChanged(bool visible) |
|
208 | \qmlsignal AbstractAxis::onGridVisibleChanged(bool visible) | |
209 | Visiblity of the grid lines of the axis has changed to \a visible. |
|
209 | Visibility of the grid lines of the axis has changed to \a visible. | |
210 | */ |
|
210 | */ | |
211 |
|
211 | |||
212 | /*! |
|
212 | /*! | |
213 | \fn void QAbstractAxis::colorChanged(QColor color) |
|
213 | \fn void QAbstractAxis::colorChanged(QColor color) | |
214 | Emitted if the \a color of the axis is changed. |
|
214 | Emitted if the \a color of the axis is changed. | |
215 | */ |
|
215 | */ | |
216 | /*! |
|
216 | /*! | |
217 | \qmlsignal AbstractAxis::onColorChanged(QColor color) |
|
217 | \qmlsignal AbstractAxis::onColorChanged(QColor color) | |
218 | Emitted if the \a color of the axis is changed. |
|
218 | Emitted if the \a color of the axis is changed. | |
219 | */ |
|
219 | */ | |
220 |
|
220 | |||
221 | /*! |
|
221 | /*! | |
222 | \fn void QAbstractAxis::labelsColorChanged(QColor color) |
|
222 | \fn void QAbstractAxis::labelsColorChanged(QColor color) | |
223 | Emitted if the \a color of the axis labels is changed. |
|
223 | Emitted if the \a color of the axis labels is changed. | |
224 | */ |
|
224 | */ | |
225 | /*! |
|
225 | /*! | |
226 | \qmlsignal AbstractAxis::onLabelsColorChanged(QColor color) |
|
226 | \qmlsignal AbstractAxis::onLabelsColorChanged(QColor color) | |
227 | Emitted if the \a color of the axis labels is changed. |
|
227 | Emitted if the \a color of the axis labels is changed. | |
228 | */ |
|
228 | */ | |
229 |
|
229 | |||
230 | /*! |
|
230 | /*! | |
231 | \fn void QAbstractAxis::shadesVisibleChanged(bool) |
|
231 | \fn void QAbstractAxis::shadesVisibleChanged(bool) | |
232 | Emitted if the visibility of the axis shades is changed to \a visible. |
|
232 | Emitted if the visibility of the axis shades is changed to \a visible. | |
233 | */ |
|
233 | */ | |
234 | /*! |
|
234 | /*! | |
235 | \qmlsignal AbstractAxis::onShadesVisibleChanged(bool visible) |
|
235 | \qmlsignal AbstractAxis::onShadesVisibleChanged(bool visible) | |
236 | Emitted if the visibility of the axis shades is changed to \a visible. |
|
236 | Emitted if the visibility of the axis shades is changed to \a visible. | |
237 | */ |
|
237 | */ | |
238 |
|
238 | |||
239 | /*! |
|
239 | /*! | |
240 | \fn void QAbstractAxis::shadesColorChanged(QColor color) |
|
240 | \fn void QAbstractAxis::shadesColorChanged(QColor color) | |
241 | Emitted if the \a color of the axis shades is changed. |
|
241 | Emitted if the \a color of the axis shades is changed. | |
242 | */ |
|
242 | */ | |
243 | /*! |
|
243 | /*! | |
244 | \qmlsignal AbstractAxis::onShadesColorChanged(QColor color) |
|
244 | \qmlsignal AbstractAxis::onShadesColorChanged(QColor color) | |
245 | Emitted if the \a color of the axis shades is changed. |
|
245 | Emitted if the \a color of the axis shades is changed. | |
246 | */ |
|
246 | */ | |
247 |
|
247 | |||
248 | /*! |
|
248 | /*! | |
249 | \fn void QAbstractAxis::shadesBorderColorChanged(QColor) |
|
249 | \fn void QAbstractAxis::shadesBorderColorChanged(QColor) | |
250 | Emitted if the border \a color of the axis shades is changed. |
|
250 | Emitted if the border \a color of the axis shades is changed. | |
251 | */ |
|
251 | */ | |
252 | /*! |
|
252 | /*! | |
253 | \qmlsignal AbstractAxis::onBorderColorChanged(QColor color) |
|
253 | \qmlsignal AbstractAxis::onBorderColorChanged(QColor color) | |
254 | Emitted if the border \a color of the axis shades is changed. |
|
254 | Emitted if the border \a color of the axis shades is changed. | |
255 | */ |
|
255 | */ | |
256 |
|
256 | |||
257 | /*! |
|
257 | /*! | |
258 | \internal |
|
258 | \internal | |
259 | Constructs new axis object which is a child of \a parent. Ownership is taken by |
|
259 | Constructs new axis object which is a child of \a parent. Ownership is taken by | |
260 | QChart when axis added. |
|
260 | QChart when axis added. | |
261 | */ |
|
261 | */ | |
262 |
|
262 | |||
263 | QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent) : |
|
263 | QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent) : | |
264 | QObject(parent), |
|
264 | QObject(parent), | |
265 | d_ptr(&d) |
|
265 | d_ptr(&d) | |
266 | { |
|
266 | { | |
267 | } |
|
267 | } | |
268 |
|
268 | |||
269 | /*! |
|
269 | /*! | |
270 | Destructor of the axis object. When axis is added to chart, chart object takes ownership. |
|
270 | Destructor of the axis object. When axis is added to chart, chart object takes ownership. | |
271 | */ |
|
271 | */ | |
272 |
|
272 | |||
273 | QAbstractAxis::~QAbstractAxis() |
|
273 | QAbstractAxis::~QAbstractAxis() | |
274 | { |
|
274 | { | |
275 | if(d_ptr->m_dataset) qFatal("Still binded axis detected !"); |
|
275 | if(d_ptr->m_dataset) qFatal("Still binded axis detected !"); | |
276 | } |
|
276 | } | |
277 |
|
277 | |||
278 | /*! |
|
278 | /*! | |
279 | Sets \a pen used to draw axis line and ticks. |
|
279 | Sets \a pen used to draw axis line and ticks. | |
280 | */ |
|
280 | */ | |
281 | void QAbstractAxis::setLinePen(const QPen &pen) |
|
281 | void QAbstractAxis::setLinePen(const QPen &pen) | |
282 | { |
|
282 | { | |
283 | if (d_ptr->m_axisPen!=pen) { |
|
283 | if (d_ptr->m_axisPen!=pen) { | |
284 | d_ptr->m_axisPen = pen; |
|
284 | d_ptr->m_axisPen = pen; | |
285 | d_ptr->emitUpdated(); |
|
285 | d_ptr->emitUpdated(); | |
286 | } |
|
286 | } | |
287 | } |
|
287 | } | |
288 |
|
288 | |||
289 | /*! |
|
289 | /*! | |
290 | Returns pen used to draw axis and ticks. |
|
290 | Returns pen used to draw axis and ticks. | |
291 | */ |
|
291 | */ | |
292 | QPen QAbstractAxis::linePen() const |
|
292 | QPen QAbstractAxis::linePen() const | |
293 | { |
|
293 | { | |
294 | return d_ptr->m_axisPen; |
|
294 | return d_ptr->m_axisPen; | |
295 | } |
|
295 | } | |
296 |
|
296 | |||
297 | void QAbstractAxis::setLinePenColor(QColor color) |
|
297 | void QAbstractAxis::setLinePenColor(QColor color) | |
298 | { |
|
298 | { | |
299 | QPen p = d_ptr->m_axisPen; |
|
299 | QPen p = d_ptr->m_axisPen; | |
300 | if (p.color() != color) { |
|
300 | if (p.color() != color) { | |
301 | p.setColor(color); |
|
301 | p.setColor(color); | |
302 | setLinePen(p); |
|
302 | setLinePen(p); | |
303 | emit colorChanged(color); |
|
303 | emit colorChanged(color); | |
304 | } |
|
304 | } | |
305 | } |
|
305 | } | |
306 |
|
306 | |||
307 | QColor QAbstractAxis::linePenColor() const |
|
307 | QColor QAbstractAxis::linePenColor() const | |
308 | { |
|
308 | { | |
309 | return d_ptr->m_axisPen.color(); |
|
309 | return d_ptr->m_axisPen.color(); | |
310 | } |
|
310 | } | |
311 |
|
311 | |||
312 | /*! |
|
312 | /*! | |
313 | Sets if axis and ticks are \a visible. |
|
313 | Sets if axis and ticks are \a visible. | |
314 | */ |
|
314 | */ | |
315 | void QAbstractAxis::setLineVisible(bool visible) |
|
315 | void QAbstractAxis::setLineVisible(bool visible) | |
316 | { |
|
316 | { | |
317 | if (d_ptr->m_arrowVisible != visible) { |
|
317 | if (d_ptr->m_arrowVisible != visible) { | |
318 | d_ptr->m_arrowVisible = visible; |
|
318 | d_ptr->m_arrowVisible = visible; | |
319 | d_ptr->emitUpdated(); |
|
319 | d_ptr->emitUpdated(); | |
320 | emit lineVisibleChanged(visible); |
|
320 | emit lineVisibleChanged(visible); | |
321 | } |
|
321 | } | |
322 | } |
|
322 | } | |
323 |
|
323 | |||
324 | bool QAbstractAxis::isLineVisible() const |
|
324 | bool QAbstractAxis::isLineVisible() const | |
325 | { |
|
325 | { | |
326 | return d_ptr->m_arrowVisible; |
|
326 | return d_ptr->m_arrowVisible; | |
327 | } |
|
327 | } | |
328 |
|
328 | |||
329 | void QAbstractAxis::setGridLineVisible(bool visible) |
|
329 | void QAbstractAxis::setGridLineVisible(bool visible) | |
330 | { |
|
330 | { | |
331 | if (d_ptr->m_gridLineVisible != visible) { |
|
331 | if (d_ptr->m_gridLineVisible != visible) { | |
332 | d_ptr->m_gridLineVisible = visible; |
|
332 | d_ptr->m_gridLineVisible = visible; | |
333 | d_ptr->emitUpdated(); |
|
333 | d_ptr->emitUpdated(); | |
334 | emit gridVisibleChanged(visible); |
|
334 | emit gridVisibleChanged(visible); | |
335 | } |
|
335 | } | |
336 | } |
|
336 | } | |
337 |
|
337 | |||
338 | bool QAbstractAxis::isGridLineVisible() const |
|
338 | bool QAbstractAxis::isGridLineVisible() const | |
339 | { |
|
339 | { | |
340 | return d_ptr->m_gridLineVisible; |
|
340 | return d_ptr->m_gridLineVisible; | |
341 | } |
|
341 | } | |
342 |
|
342 | |||
343 | /*! |
|
343 | /*! | |
344 | Sets \a pen used to draw grid line. |
|
344 | Sets \a pen used to draw grid line. | |
345 | */ |
|
345 | */ | |
346 | void QAbstractAxis::setGridLinePen(const QPen &pen) |
|
346 | void QAbstractAxis::setGridLinePen(const QPen &pen) | |
347 | { |
|
347 | { | |
348 | if (d_ptr->m_gridLinePen != pen) { |
|
348 | if (d_ptr->m_gridLinePen != pen) { | |
349 | d_ptr->m_gridLinePen = pen; |
|
349 | d_ptr->m_gridLinePen = pen; | |
350 | d_ptr->emitUpdated(); |
|
350 | d_ptr->emitUpdated(); | |
351 | } |
|
351 | } | |
352 | } |
|
352 | } | |
353 |
|
353 | |||
354 | /*! |
|
354 | /*! | |
355 | Returns pen used to draw grid. |
|
355 | Returns pen used to draw grid. | |
356 | */ |
|
356 | */ | |
357 | QPen QAbstractAxis::gridLinePen() const |
|
357 | QPen QAbstractAxis::gridLinePen() const | |
358 | { |
|
358 | { | |
359 | return d_ptr->m_gridLinePen; |
|
359 | return d_ptr->m_gridLinePen; | |
360 | } |
|
360 | } | |
361 |
|
361 | |||
362 | void QAbstractAxis::setLabelsVisible(bool visible) |
|
362 | void QAbstractAxis::setLabelsVisible(bool visible) | |
363 | { |
|
363 | { | |
364 | if (d_ptr->m_labelsVisible != visible) { |
|
364 | if (d_ptr->m_labelsVisible != visible) { | |
365 | d_ptr->m_labelsVisible = visible; |
|
365 | d_ptr->m_labelsVisible = visible; | |
366 | d_ptr->emitUpdated(); |
|
366 | d_ptr->emitUpdated(); | |
367 | emit labelsVisibleChanged(visible); |
|
367 | emit labelsVisibleChanged(visible); | |
368 | } |
|
368 | } | |
369 | } |
|
369 | } | |
370 |
|
370 | |||
371 | bool QAbstractAxis::labelsVisible() const |
|
371 | bool QAbstractAxis::labelsVisible() const | |
372 | { |
|
372 | { | |
373 | return d_ptr->m_labelsVisible; |
|
373 | return d_ptr->m_labelsVisible; | |
374 | } |
|
374 | } | |
375 |
|
375 | |||
376 | /*! |
|
376 | /*! | |
377 | Sets \a pen used to draw labels. |
|
377 | Sets \a pen used to draw labels. | |
378 | */ |
|
378 | */ | |
379 | void QAbstractAxis::setLabelsPen(const QPen &pen) |
|
379 | void QAbstractAxis::setLabelsPen(const QPen &pen) | |
380 | { |
|
380 | { | |
381 | if (d_ptr->m_labelsPen != pen) { |
|
381 | if (d_ptr->m_labelsPen != pen) { | |
382 | d_ptr->m_labelsPen = pen; |
|
382 | d_ptr->m_labelsPen = pen; | |
383 | d_ptr->emitUpdated(); |
|
383 | d_ptr->emitUpdated(); | |
384 | } |
|
384 | } | |
385 | } |
|
385 | } | |
386 |
|
386 | |||
387 | /*! |
|
387 | /*! | |
388 | Returns the pen used to labels. |
|
388 | Returns the pen used to labels. | |
389 | */ |
|
389 | */ | |
390 | QPen QAbstractAxis::labelsPen() const |
|
390 | QPen QAbstractAxis::labelsPen() const | |
391 | { |
|
391 | { | |
392 | return d_ptr->m_labelsPen; |
|
392 | return d_ptr->m_labelsPen; | |
393 | } |
|
393 | } | |
394 |
|
394 | |||
395 | /*! |
|
395 | /*! | |
396 | Sets \a brush used to draw labels. |
|
396 | Sets \a brush used to draw labels. | |
397 | */ |
|
397 | */ | |
398 | void QAbstractAxis::setLabelsBrush(const QBrush &brush) |
|
398 | void QAbstractAxis::setLabelsBrush(const QBrush &brush) | |
399 | { |
|
399 | { | |
400 | if (d_ptr->m_labelsBrush != brush) { |
|
400 | if (d_ptr->m_labelsBrush != brush) { | |
401 | d_ptr->m_labelsBrush = brush; |
|
401 | d_ptr->m_labelsBrush = brush; | |
402 | d_ptr->emitUpdated(); |
|
402 | d_ptr->emitUpdated(); | |
403 | } |
|
403 | } | |
404 | } |
|
404 | } | |
405 |
|
405 | |||
406 | /*! |
|
406 | /*! | |
407 | Returns brush used to draw labels. |
|
407 | Returns brush used to draw labels. | |
408 | */ |
|
408 | */ | |
409 | QBrush QAbstractAxis::labelsBrush() const |
|
409 | QBrush QAbstractAxis::labelsBrush() const | |
410 | { |
|
410 | { | |
411 | return d_ptr->m_labelsBrush; |
|
411 | return d_ptr->m_labelsBrush; | |
412 | } |
|
412 | } | |
413 |
|
413 | |||
414 | /*! |
|
414 | /*! | |
415 | Sets \a font used to draw labels. |
|
415 | Sets \a font used to draw labels. | |
416 | */ |
|
416 | */ | |
417 | void QAbstractAxis::setLabelsFont(const QFont &font) |
|
417 | void QAbstractAxis::setLabelsFont(const QFont &font) | |
418 | { |
|
418 | { | |
419 | if (d_ptr->m_labelsFont != font) { |
|
419 | if (d_ptr->m_labelsFont != font) { | |
420 | d_ptr->m_labelsFont = font; |
|
420 | d_ptr->m_labelsFont = font; | |
421 | d_ptr->emitUpdated(); |
|
421 | d_ptr->emitUpdated(); | |
422 | } |
|
422 | } | |
423 | } |
|
423 | } | |
424 |
|
424 | |||
425 | /*! |
|
425 | /*! | |
426 | Returns font used to draw labels. |
|
426 | Returns font used to draw labels. | |
427 | */ |
|
427 | */ | |
428 | QFont QAbstractAxis::labelsFont() const |
|
428 | QFont QAbstractAxis::labelsFont() const | |
429 | { |
|
429 | { | |
430 | return d_ptr->m_labelsFont; |
|
430 | return d_ptr->m_labelsFont; | |
431 | } |
|
431 | } | |
432 |
|
432 | |||
433 | void QAbstractAxis::setLabelsAngle(int angle) |
|
433 | void QAbstractAxis::setLabelsAngle(int angle) | |
434 | { |
|
434 | { | |
435 | if (d_ptr->m_labelsAngle != angle) { |
|
435 | if (d_ptr->m_labelsAngle != angle) { | |
436 | d_ptr->m_labelsAngle = angle; |
|
436 | d_ptr->m_labelsAngle = angle; | |
437 | d_ptr->emitUpdated(); |
|
437 | d_ptr->emitUpdated(); | |
438 | } |
|
438 | } | |
439 | } |
|
439 | } | |
440 |
|
440 | |||
441 | int QAbstractAxis::labelsAngle() const |
|
441 | int QAbstractAxis::labelsAngle() const | |
442 | { |
|
442 | { | |
443 | return d_ptr->m_labelsAngle; |
|
443 | return d_ptr->m_labelsAngle; | |
444 | } |
|
444 | } | |
445 |
|
445 | |||
446 | void QAbstractAxis::setLabelsColor(QColor color) |
|
446 | void QAbstractAxis::setLabelsColor(QColor color) | |
447 | { |
|
447 | { | |
448 | QBrush b = d_ptr->m_labelsBrush; |
|
448 | QBrush b = d_ptr->m_labelsBrush; | |
449 | if (b.color() != color) { |
|
449 | if (b.color() != color) { | |
450 | b.setColor(color); |
|
450 | b.setColor(color); | |
451 | setLabelsBrush(b); |
|
451 | setLabelsBrush(b); | |
452 | emit labelsColorChanged(color); |
|
452 | emit labelsColorChanged(color); | |
453 | } |
|
453 | } | |
454 | } |
|
454 | } | |
455 |
|
455 | |||
456 | QColor QAbstractAxis::labelsColor() const |
|
456 | QColor QAbstractAxis::labelsColor() const | |
457 | { |
|
457 | { | |
458 | return d_ptr->m_labelsBrush.color(); |
|
458 | return d_ptr->m_labelsBrush.color(); | |
459 | } |
|
459 | } | |
460 |
|
460 | |||
461 | void QAbstractAxis::setShadesVisible(bool visible) |
|
461 | void QAbstractAxis::setShadesVisible(bool visible) | |
462 | { |
|
462 | { | |
463 | if (d_ptr->m_shadesVisible != visible) { |
|
463 | if (d_ptr->m_shadesVisible != visible) { | |
464 | d_ptr->m_shadesVisible = visible; |
|
464 | d_ptr->m_shadesVisible = visible; | |
465 | d_ptr->emitUpdated(); |
|
465 | d_ptr->emitUpdated(); | |
466 | emit shadesVisibleChanged(visible); |
|
466 | emit shadesVisibleChanged(visible); | |
467 | } |
|
467 | } | |
468 | } |
|
468 | } | |
469 |
|
469 | |||
470 | bool QAbstractAxis::shadesVisible() const |
|
470 | bool QAbstractAxis::shadesVisible() const | |
471 | { |
|
471 | { | |
472 | return d_ptr->m_shadesVisible; |
|
472 | return d_ptr->m_shadesVisible; | |
473 | } |
|
473 | } | |
474 |
|
474 | |||
475 | /*! |
|
475 | /*! | |
476 | Sets \a pen used to draw shades. |
|
476 | Sets \a pen used to draw shades. | |
477 | */ |
|
477 | */ | |
478 | void QAbstractAxis::setShadesPen(const QPen &pen) |
|
478 | void QAbstractAxis::setShadesPen(const QPen &pen) | |
479 | { |
|
479 | { | |
480 | if (d_ptr->m_shadesPen != pen) { |
|
480 | if (d_ptr->m_shadesPen != pen) { | |
481 | d_ptr->m_shadesPen = pen; |
|
481 | d_ptr->m_shadesPen = pen; | |
482 | d_ptr->emitUpdated(); |
|
482 | d_ptr->emitUpdated(); | |
483 | } |
|
483 | } | |
484 | } |
|
484 | } | |
485 |
|
485 | |||
486 | /*! |
|
486 | /*! | |
487 | Returns pen used to draw shades. |
|
487 | Returns pen used to draw shades. | |
488 | */ |
|
488 | */ | |
489 | QPen QAbstractAxis::shadesPen() const |
|
489 | QPen QAbstractAxis::shadesPen() const | |
490 | { |
|
490 | { | |
491 | return d_ptr->m_shadesPen; |
|
491 | return d_ptr->m_shadesPen; | |
492 | } |
|
492 | } | |
493 |
|
493 | |||
494 | /*! |
|
494 | /*! | |
495 | Sets \a brush used to draw shades. |
|
495 | Sets \a brush used to draw shades. | |
496 | */ |
|
496 | */ | |
497 | void QAbstractAxis::setShadesBrush(const QBrush &brush) |
|
497 | void QAbstractAxis::setShadesBrush(const QBrush &brush) | |
498 | { |
|
498 | { | |
499 | if (d_ptr->m_shadesBrush != brush) { |
|
499 | if (d_ptr->m_shadesBrush != brush) { | |
500 | d_ptr->m_shadesBrush = brush; |
|
500 | d_ptr->m_shadesBrush = brush; | |
501 | d_ptr->emitUpdated(); |
|
501 | d_ptr->emitUpdated(); | |
502 | emit shadesColorChanged(brush.color()); |
|
502 | emit shadesColorChanged(brush.color()); | |
503 | } |
|
503 | } | |
504 | } |
|
504 | } | |
505 |
|
505 | |||
506 | /*! |
|
506 | /*! | |
507 | Returns brush used to draw shades. |
|
507 | Returns brush used to draw shades. | |
508 | */ |
|
508 | */ | |
509 | QBrush QAbstractAxis::shadesBrush() const |
|
509 | QBrush QAbstractAxis::shadesBrush() const | |
510 | { |
|
510 | { | |
511 | return d_ptr->m_shadesBrush; |
|
511 | return d_ptr->m_shadesBrush; | |
512 | } |
|
512 | } | |
513 |
|
513 | |||
514 | void QAbstractAxis::setShadesColor(QColor color) |
|
514 | void QAbstractAxis::setShadesColor(QColor color) | |
515 | { |
|
515 | { | |
516 | QBrush b = d_ptr->m_shadesBrush; |
|
516 | QBrush b = d_ptr->m_shadesBrush; | |
517 | b.setColor(color); |
|
517 | b.setColor(color); | |
518 | setShadesBrush(b); |
|
518 | setShadesBrush(b); | |
519 | } |
|
519 | } | |
520 |
|
520 | |||
521 | QColor QAbstractAxis::shadesColor() const |
|
521 | QColor QAbstractAxis::shadesColor() const | |
522 | { |
|
522 | { | |
523 | return d_ptr->m_shadesBrush.color(); |
|
523 | return d_ptr->m_shadesBrush.color(); | |
524 | } |
|
524 | } | |
525 |
|
525 | |||
526 | void QAbstractAxis::setShadesBorderColor(QColor color) |
|
526 | void QAbstractAxis::setShadesBorderColor(QColor color) | |
527 | { |
|
527 | { | |
528 | QPen p = d_ptr->m_shadesPen; |
|
528 | QPen p = d_ptr->m_shadesPen; | |
529 | p.setColor(color); |
|
529 | p.setColor(color); | |
530 | setShadesPen(p); |
|
530 | setShadesPen(p); | |
531 | } |
|
531 | } | |
532 |
|
532 | |||
533 | QColor QAbstractAxis::shadesBorderColor() const |
|
533 | QColor QAbstractAxis::shadesBorderColor() const | |
534 | { |
|
534 | { | |
535 | return d_ptr->m_shadesPen.color(); |
|
535 | return d_ptr->m_shadesPen.color(); | |
536 | } |
|
536 | } | |
537 |
|
537 | |||
538 |
|
538 | |||
539 | bool QAbstractAxis::isVisible() const |
|
539 | bool QAbstractAxis::isVisible() const | |
540 | { |
|
540 | { | |
541 | return d_ptr->m_visible; |
|
541 | return d_ptr->m_visible; | |
542 | } |
|
542 | } | |
543 |
|
543 | |||
544 | /*! |
|
544 | /*! | |
545 | Sets axis, shades, labels and grid lines to be visible. |
|
545 | Sets axis, shades, labels and grid lines to be visible. | |
546 | */ |
|
546 | */ | |
547 | void QAbstractAxis::setVisible(bool visible) |
|
547 | void QAbstractAxis::setVisible(bool visible) | |
548 | { |
|
548 | { | |
549 | if(d_ptr->m_visible!=visible){ |
|
549 | if(d_ptr->m_visible!=visible){ | |
550 | d_ptr->m_visible=visible; |
|
550 | d_ptr->m_visible=visible; | |
551 | d_ptr->emitUpdated(); |
|
551 | d_ptr->emitUpdated(); | |
552 | emit visibleChanged(visible); |
|
552 | emit visibleChanged(visible); | |
553 | } |
|
553 | } | |
554 | } |
|
554 | } | |
555 |
|
555 | |||
556 |
|
556 | |||
557 | /*! |
|
557 | /*! | |
558 | Sets axis, shades, labels and grid lines to be visible. |
|
558 | Sets axis, shades, labels and grid lines to be visible. | |
559 | */ |
|
559 | */ | |
560 | void QAbstractAxis::show() |
|
560 | void QAbstractAxis::show() | |
561 | { |
|
561 | { | |
562 | setVisible(true); |
|
562 | setVisible(true); | |
563 | } |
|
563 | } | |
564 |
|
564 | |||
565 | /*! |
|
565 | /*! | |
566 | Sets axis, shades, labels and grid lines to not be visible. |
|
566 | Sets axis, shades, labels and grid lines to not be visible. | |
567 | */ |
|
567 | */ | |
568 | void QAbstractAxis::hide() |
|
568 | void QAbstractAxis::hide() | |
569 | { |
|
569 | { | |
570 | setVisible(false); |
|
570 | setVisible(false); | |
571 | } |
|
571 | } | |
572 |
|
572 | |||
573 | /*! |
|
573 | /*! | |
574 | Sets the minimum value shown on the axis. |
|
574 | Sets the minimum value shown on the axis. | |
575 | Depending on the actual axis type the \a min paramter is converted to appropriate type. |
|
575 | Depending on the actual axis type the \a min paramter is converted to appropriate type. | |
576 | If the conversion is impossible then the function call does nothing |
|
576 | If the conversion is impossible then the function call does nothing | |
577 | */ |
|
577 | */ | |
578 | void QAbstractAxis::setMin(const QVariant &min) |
|
578 | void QAbstractAxis::setMin(const QVariant &min) | |
579 | { |
|
579 | { | |
580 | d_ptr->setMin(min); |
|
580 | d_ptr->setMin(min); | |
581 | } |
|
581 | } | |
582 |
|
582 | |||
583 | /*! |
|
583 | /*! | |
584 | Sets the maximum value shown on the axis. |
|
584 | Sets the maximum value shown on the axis. | |
585 | Depending on the actual axis type the \a max paramter is converted to appropriate type. |
|
585 | Depending on the actual axis type the \a max paramter is converted to appropriate type. | |
586 | If the conversion is impossible then the function call does nothing |
|
586 | If the conversion is impossible then the function call does nothing | |
587 | */ |
|
587 | */ | |
588 | void QAbstractAxis::setMax(const QVariant &max) |
|
588 | void QAbstractAxis::setMax(const QVariant &max) | |
589 | { |
|
589 | { | |
590 | d_ptr->setMax(max); |
|
590 | d_ptr->setMax(max); | |
591 | } |
|
591 | } | |
592 |
|
592 | |||
593 | /*! |
|
593 | /*! | |
594 | Sets the range shown on the axis. |
|
594 | Sets the range shown on the axis. | |
595 | Depending on the actual axis type the \a min and \a max paramters are converted to appropriate types. |
|
595 | Depending on the actual axis type the \a min and \a max paramters are converted to appropriate types. | |
596 | If the conversion is impossible then the function call does nothing. |
|
596 | If the conversion is impossible then the function call does nothing. | |
597 | */ |
|
597 | */ | |
598 | void QAbstractAxis::setRange(const QVariant &min, const QVariant &max) |
|
598 | void QAbstractAxis::setRange(const QVariant &min, const QVariant &max) | |
599 | { |
|
599 | { | |
600 | d_ptr->setRange(min,max); |
|
600 | d_ptr->setRange(min,max); | |
601 | } |
|
601 | } | |
602 |
|
602 | |||
603 |
|
603 | |||
604 | /*! |
|
604 | /*! | |
605 | Returns the orientation in which the axis is being used (Vertical or Horizontal) |
|
605 | Returns the orientation in which the axis is being used (Vertical or Horizontal) | |
606 | */ |
|
606 | */ | |
607 | Qt::Orientation QAbstractAxis::orientation() |
|
607 | Qt::Orientation QAbstractAxis::orientation() | |
608 | { |
|
608 | { | |
609 | return d_ptr->m_orientation; |
|
609 | return d_ptr->m_orientation; | |
610 | } |
|
610 | } | |
611 |
|
611 | |||
612 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
612 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
613 |
|
613 | |||
614 | QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis* q): |
|
614 | QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis* q): | |
615 | q_ptr(q), |
|
615 | q_ptr(q), | |
616 | m_orientation(Qt::Orientation(0)), |
|
616 | m_orientation(Qt::Orientation(0)), | |
617 | m_dataset(0), |
|
617 | m_dataset(0), | |
618 | m_visible(false), |
|
618 | m_visible(false), | |
619 | m_arrowVisible(true), |
|
619 | m_arrowVisible(true), | |
620 | m_gridLineVisible(true), |
|
620 | m_gridLineVisible(true), | |
621 | m_labelsVisible(true), |
|
621 | m_labelsVisible(true), | |
622 | m_labelsAngle(0), |
|
622 | m_labelsAngle(0), | |
623 | m_shadesVisible(false), |
|
623 | m_shadesVisible(false), | |
624 | m_shadesBrush(Qt::SolidPattern), |
|
624 | m_shadesBrush(Qt::SolidPattern), | |
625 | m_shadesOpacity(1.0), |
|
625 | m_shadesOpacity(1.0), | |
626 | m_dirty(false) |
|
626 | m_dirty(false) | |
627 | { |
|
627 | { | |
628 |
|
628 | |||
629 | } |
|
629 | } | |
630 |
|
630 | |||
631 | QAbstractAxisPrivate::~QAbstractAxisPrivate() |
|
631 | QAbstractAxisPrivate::~QAbstractAxisPrivate() | |
632 | { |
|
632 | { | |
633 |
|
633 | |||
634 | } |
|
634 | } | |
635 |
|
635 | |||
636 | void QAbstractAxisPrivate::emitUpdated() |
|
636 | void QAbstractAxisPrivate::emitUpdated() | |
637 | { |
|
637 | { | |
638 | if(!m_dirty){ |
|
638 | if(!m_dirty){ | |
639 | m_dirty=true; |
|
639 | m_dirty=true; | |
640 | emit updated(); |
|
640 | emit updated(); | |
641 | } |
|
641 | } | |
642 | } |
|
642 | } | |
643 |
|
643 | |||
644 | void QAbstractAxisPrivate::setDirty(bool dirty) |
|
644 | void QAbstractAxisPrivate::setDirty(bool dirty) | |
645 | { |
|
645 | { | |
646 | m_dirty=dirty; |
|
646 | m_dirty=dirty; | |
647 | } |
|
647 | } | |
648 |
|
648 | |||
649 | void QAbstractAxisPrivate::setOrientation(Qt::Orientation orientation) |
|
649 | void QAbstractAxisPrivate::setOrientation(Qt::Orientation orientation) | |
650 | { |
|
650 | { | |
651 | m_orientation=orientation; |
|
651 | m_orientation=orientation; | |
652 | } |
|
652 | } | |
653 |
|
653 | |||
654 |
|
654 | |||
655 | #include "moc_qabstractaxis.cpp" |
|
655 | #include "moc_qabstractaxis.cpp" | |
656 | #include "moc_qabstractaxis_p.cpp" |
|
656 | #include "moc_qabstractaxis_p.cpp" | |
657 |
|
657 | |||
658 | QTCOMMERCIALCHART_END_NAMESPACE |
|
658 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,870 +1,870 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qabstractbarseries.h" |
|
21 | #include "qabstractbarseries.h" | |
22 | #include "qabstractbarseries_p.h" |
|
22 | #include "qabstractbarseries_p.h" | |
23 | #include "qbarset.h" |
|
23 | #include "qbarset.h" | |
24 | #include "qbarset_p.h" |
|
24 | #include "qbarset_p.h" | |
25 | #include "domain_p.h" |
|
25 | #include "domain_p.h" | |
26 | #include "legendmarker_p.h" |
|
26 | #include "legendmarker_p.h" | |
27 | #include "chartdataset_p.h" |
|
27 | #include "chartdataset_p.h" | |
28 | #include "charttheme_p.h" |
|
28 | #include "charttheme_p.h" | |
29 | #include "qvalueaxis.h" |
|
29 | #include "qvalueaxis.h" | |
30 | #include "qbarcategoryaxis.h" |
|
30 | #include "qbarcategoryaxis.h" | |
31 |
|
31 | |||
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
33 |
|
33 | |||
34 | /*! |
|
34 | /*! | |
35 | \class QAbstractBarSeries |
|
35 | \class QAbstractBarSeries | |
36 | \brief Series for creating a bar chart |
|
36 | \brief Series for creating a bar chart | |
37 | \mainclass |
|
37 | \mainclass | |
38 |
|
38 | |||
39 | QAbstractBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to |
|
39 | QAbstractBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to | |
40 | the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar |
|
40 | the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar | |
41 | and y-value is the height of the bar. The category names are ignored with this series and x-axis |
|
41 | and y-value is the height of the bar. The category names are ignored with this series and x-axis | |
42 | shows the x-values. |
|
42 | shows the x-values. | |
43 |
|
43 | |||
44 | See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart. |
|
44 | See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart. | |
45 | \image examples_barchart.png |
|
45 | \image examples_barchart.png | |
46 |
|
46 | |||
47 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries |
|
47 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries | |
48 | */ |
|
48 | */ | |
49 | /*! |
|
49 | /*! | |
50 | \qmlclass AbstractBarSeries QAbstractBarSeries |
|
50 | \qmlclass AbstractBarSeries QAbstractBarSeries | |
51 | \inherits QAbstractSeries |
|
51 | \inherits QAbstractSeries | |
52 |
|
52 | |||
53 | The following QML shows how to create a simple bar chart: |
|
53 | The following QML shows how to create a simple bar chart: | |
54 | \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1 |
|
54 | \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1 | |
55 |
|
55 | |||
56 | \beginfloatleft |
|
56 | \beginfloatleft | |
57 | \image demos_qmlchart6.png |
|
57 | \image demos_qmlchart6.png | |
58 | \endfloat |
|
58 | \endfloat | |
59 | \clearfloat |
|
59 | \clearfloat | |
60 | */ |
|
60 | */ | |
61 |
|
61 | |||
62 | /*! |
|
62 | /*! | |
63 | \property QAbstractBarSeries::barWidth |
|
63 | \property QAbstractBarSeries::barWidth | |
64 | The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars |
|
64 | The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars | |
65 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
65 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen | |
66 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
66 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. | |
67 | Note that with QBarSeries this value means the width of one group of bars instead of just one bar. |
|
67 | Note that with QBarSeries this value means the width of one group of bars instead of just one bar. | |
68 | \sa QBarSeries |
|
68 | \sa QBarSeries | |
69 | */ |
|
69 | */ | |
70 | /*! |
|
70 | /*! | |
71 | \qmlproperty real AbstractBarSeries::barWidth |
|
71 | \qmlproperty real AbstractBarSeries::barWidth | |
72 | The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars |
|
72 | The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars | |
73 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
73 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen | |
74 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
74 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. | |
75 | Note that with QBarSeries this value means the width of one group of bars instead of just one bar. |
|
75 | Note that with QBarSeries this value means the width of one group of bars instead of just one bar. | |
76 | */ |
|
76 | */ | |
77 |
|
77 | |||
78 | /*! |
|
78 | /*! | |
79 | \property QAbstractBarSeries::count |
|
79 | \property QAbstractBarSeries::count | |
80 | Holds the number of sets in series. |
|
80 | Holds the number of sets in series. | |
81 | */ |
|
81 | */ | |
82 | /*! |
|
82 | /*! | |
83 | \qmlproperty int AbstractBarSeries::count |
|
83 | \qmlproperty int AbstractBarSeries::count | |
84 | Holds the number of sets in series. |
|
84 | Holds the number of sets in series. | |
85 | */ |
|
85 | */ | |
86 |
|
86 | |||
87 | /*! |
|
87 | /*! | |
88 | \property QAbstractBarSeries::labelsVisible |
|
88 | \property QAbstractBarSeries::labelsVisible | |
89 | Defines the visibility of the labels in series |
|
89 | Defines the visibility of the labels in series | |
90 | */ |
|
90 | */ | |
91 | /*! |
|
91 | /*! | |
92 | \qmlproperty bool AbstractBarSeries::labelsVisible |
|
92 | \qmlproperty bool AbstractBarSeries::labelsVisible | |
93 | Defines the visibility of the labels in series |
|
93 | Defines the visibility of the labels in series | |
94 | */ |
|
94 | */ | |
95 |
|
95 | |||
96 | /*! |
|
96 | /*! | |
97 | \fn void QAbstractBarSeries::clicked(int index, QBarSet *barset) |
|
97 | \fn void QAbstractBarSeries::clicked(int index, QBarSet *barset) | |
98 | The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset. |
|
98 | The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset. | |
99 | Clicked bar inside set is indexed by \a index |
|
99 | Clicked bar inside set is indexed by \a index | |
100 | */ |
|
100 | */ | |
101 | /*! |
|
101 | /*! | |
102 | \qmlsignal AbstractBarSeries::onClicked(int index, BarSet barset) |
|
102 | \qmlsignal AbstractBarSeries::onClicked(int index, BarSet barset) | |
103 | The signal is emitted if the user clicks with a mouse on top of BarSet. |
|
103 | The signal is emitted if the user clicks with a mouse on top of BarSet. | |
104 | Clicked bar inside set is indexed by \a index |
|
104 | Clicked bar inside set is indexed by \a index | |
105 | */ |
|
105 | */ | |
106 |
|
106 | |||
107 | /*! |
|
107 | /*! | |
108 | \fn void QAbstractBarSeries::hovered(bool status, QBarSet* barset) |
|
108 | \fn void QAbstractBarSeries::hovered(bool status, QBarSet* barset) | |
109 |
|
109 | |||
110 | The signal is emitted if mouse is hovered on top of series. |
|
110 | The signal is emitted if mouse is hovered on top of series. | |
111 | Parameter \a barset is the pointer of barset, where hover happened. |
|
111 | Parameter \a barset is the pointer of barset, where hover happened. | |
112 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
112 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. | |
113 | */ |
|
113 | */ | |
114 | /*! |
|
114 | /*! | |
115 | \qmlsignal AbstractBarSeries::onHovered(bool status, BarSet barset) |
|
115 | \qmlsignal AbstractBarSeries::onHovered(bool status, BarSet barset) | |
116 |
|
116 | |||
117 | The signal is emitted if mouse is hovered on top of series. |
|
117 | The signal is emitted if mouse is hovered on top of series. | |
118 | Parameter \a barset is the pointer of barset, where hover happened. |
|
118 | Parameter \a barset is the pointer of barset, where hover happened. | |
119 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
119 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. | |
120 | */ |
|
120 | */ | |
121 |
|
121 | |||
122 | /*! |
|
122 | /*! | |
123 | \fn void QAbstractBarSeries::countChanged() |
|
123 | \fn void QAbstractBarSeries::countChanged() | |
124 | This signal is emitted when barset count has been changed, for example by append or remove. |
|
124 | This signal is emitted when barset count has been changed, for example by append or remove. | |
125 | */ |
|
125 | */ | |
126 | /*! |
|
126 | /*! | |
127 | \qmlsignal AbstractBarSeries::onCountChanged() |
|
127 | \qmlsignal AbstractBarSeries::onCountChanged() | |
128 | This signal is emitted when barset count has been changed, for example by append or remove. |
|
128 | This signal is emitted when barset count has been changed, for example by append or remove. | |
129 | */ |
|
129 | */ | |
130 |
|
130 | |||
131 | /*! |
|
131 | /*! | |
132 | \fn void QAbstractBarSeries::labelsVisibleChanged() |
|
132 | \fn void QAbstractBarSeries::labelsVisibleChanged() | |
133 | This signal is emitted when labels visibility have changed. |
|
133 | This signal is emitted when labels visibility have changed. | |
134 | \sa isLabelsVisible(), setLabelsVisible() |
|
134 | \sa isLabelsVisible(), setLabelsVisible() | |
135 | */ |
|
135 | */ | |
136 |
|
136 | |||
137 | /*! |
|
137 | /*! | |
138 | \fn void QAbstractBarSeries::barsetsAdded(QList<QBarSet*> sets) |
|
138 | \fn void QAbstractBarSeries::barsetsAdded(QList<QBarSet*> sets) | |
139 | This signal is emitted when \a sets have been added to the series. |
|
139 | This signal is emitted when \a sets have been added to the series. | |
140 | \sa append(), insert() |
|
140 | \sa append(), insert() | |
141 | */ |
|
141 | */ | |
142 | /*! |
|
142 | /*! | |
143 | \qmlsignal AbstractBarSeries::onAdded(BarSet barset) |
|
143 | \qmlsignal AbstractBarSeries::onAdded(BarSet barset) | |
144 | Emitted when \a barset has been added to the series. |
|
144 | Emitted when \a barset has been added to the series. | |
145 | */ |
|
145 | */ | |
146 |
|
146 | |||
147 | /*! |
|
147 | /*! | |
148 | \fn void QAbstractBarSeries::barsetsRemoved(QList<QBarSet*> sets) |
|
148 | \fn void QAbstractBarSeries::barsetsRemoved(QList<QBarSet*> sets) | |
149 | This signal is emitted when \a sets have been removed from the series. |
|
149 | This signal is emitted when \a sets have been removed from the series. | |
150 | \sa remove() |
|
150 | \sa remove() | |
151 | */ |
|
151 | */ | |
152 | /*! |
|
152 | /*! | |
153 | \qmlsignal AbstractBarSeries::onRemoved(BarSet barset) |
|
153 | \qmlsignal AbstractBarSeries::onRemoved(BarSet barset) | |
154 | Emitted when \a barset has been removed from the series. |
|
154 | Emitted when \a barset has been removed from the series. | |
155 | */ |
|
155 | */ | |
156 |
|
156 | |||
157 | /*! |
|
157 | /*! | |
158 | \qmlmethod BarSet AbstractBarSeries::at(int index) |
|
158 | \qmlmethod BarSet AbstractBarSeries::at(int index) | |
159 | Returns bar set at \a index. Returns null if the index is not valid. |
|
159 | Returns bar set at \a index. Returns null if the index is not valid. | |
160 | */ |
|
160 | */ | |
161 |
|
161 | |||
162 | /*! |
|
162 | /*! | |
163 | \qmlmethod BarSet AbstractBarSeries::append(string label, VariantList values) |
|
163 | \qmlmethod BarSet AbstractBarSeries::append(string label, VariantList values) | |
164 | Adds a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints. |
|
164 | Adds a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints. | |
165 | For example: |
|
165 | For example: | |
166 | \code |
|
166 | \code | |
167 | myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]); |
|
167 | myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]); | |
168 | myBarSeries.append("set 2", [Qt.point(0, 1), Qt.point(2, 2.5), Qt.point(3.5, 2.2)]); |
|
168 | myBarSeries.append("set 2", [Qt.point(0, 1), Qt.point(2, 2.5), Qt.point(3.5, 2.2)]); | |
169 | \endcode |
|
169 | \endcode | |
170 | */ |
|
170 | */ | |
171 |
|
171 | |||
172 | /*! |
|
172 | /*! | |
173 | \qmlmethod BarSet AbstractBarSeries::insert(int index, string label, VariantList values) |
|
173 | \qmlmethod BarSet AbstractBarSeries::insert(int index, string label, VariantList values) | |
174 | Inserts a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints. |
|
174 | Inserts a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints. | |
175 | If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is |
|
175 | If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is | |
176 | appended. |
|
176 | appended. | |
177 | \sa AbstractBarSeries::append() |
|
177 | \sa AbstractBarSeries::append() | |
178 | */ |
|
178 | */ | |
179 |
|
179 | |||
180 | /*! |
|
180 | /*! | |
181 | \qmlmethod bool AbstractBarSeries::remove(BarSet barset) |
|
181 | \qmlmethod bool AbstractBarSeries::remove(BarSet barset) | |
182 |
Removes the barset from the series. Returns true if successful |
|
182 | Removes the barset from the series. Returns true if successful, false otherwise. | |
183 | */ |
|
183 | */ | |
184 |
|
184 | |||
185 | /*! |
|
185 | /*! | |
186 | \qmlmethod AbstractBarSeries::clear() |
|
186 | \qmlmethod AbstractBarSeries::clear() | |
187 | Removes all barsets from the series. |
|
187 | Removes all barsets from the series. | |
188 | */ |
|
188 | */ | |
189 |
|
189 | |||
190 | /*! |
|
190 | /*! | |
191 | Destructs abstractbarseries and owned barsets. |
|
191 | Destructs abstractbarseries and owned barsets. | |
192 | */ |
|
192 | */ | |
193 | QAbstractBarSeries::~QAbstractBarSeries() |
|
193 | QAbstractBarSeries::~QAbstractBarSeries() | |
194 | { |
|
194 | { | |
195 |
|
195 | |||
196 | } |
|
196 | } | |
197 |
|
197 | |||
198 | /*! |
|
198 | /*! | |
199 | \internal |
|
199 | \internal | |
200 | */ |
|
200 | */ | |
201 | QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &d, QObject *parent) : |
|
201 | QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &d, QObject *parent) : | |
202 | QAbstractSeries(d,parent) |
|
202 | QAbstractSeries(d,parent) | |
203 | { |
|
203 | { | |
204 | } |
|
204 | } | |
205 |
|
205 | |||
206 | /*! |
|
206 | /*! | |
207 | Sets the width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars |
|
207 | Sets the width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars | |
208 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
208 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen | |
209 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
209 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. | |
210 | Note that with \link QBarSeries \endlink this value means the width of one group of bars instead of just one bar. |
|
210 | Note that with \link QBarSeries \endlink this value means the width of one group of bars instead of just one bar. | |
211 | */ |
|
211 | */ | |
212 | void QAbstractBarSeries::setBarWidth(qreal width) |
|
212 | void QAbstractBarSeries::setBarWidth(qreal width) | |
213 | { |
|
213 | { | |
214 | Q_D(QAbstractBarSeries); |
|
214 | Q_D(QAbstractBarSeries); | |
215 | d->setBarWidth(width); |
|
215 | d->setBarWidth(width); | |
216 | } |
|
216 | } | |
217 |
|
217 | |||
218 | /*! |
|
218 | /*! | |
219 | Returns the width of the bars of the series. |
|
219 | Returns the width of the bars of the series. | |
220 | \sa setBarWidth() |
|
220 | \sa setBarWidth() | |
221 | */ |
|
221 | */ | |
222 | qreal QAbstractBarSeries::barWidth() const |
|
222 | qreal QAbstractBarSeries::barWidth() const | |
223 | { |
|
223 | { | |
224 | Q_D(const QAbstractBarSeries); |
|
224 | Q_D(const QAbstractBarSeries); | |
225 | return d->barWidth(); |
|
225 | return d->barWidth(); | |
226 | } |
|
226 | } | |
227 |
|
227 | |||
228 | /*! |
|
228 | /*! | |
229 | Adds a set of bars to series. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. |
|
229 | Adds a set of bars to series. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. | |
230 | Returns true, if appending succeeded. |
|
230 | Returns true, if appending succeeded. | |
231 | */ |
|
231 | */ | |
232 | bool QAbstractBarSeries::append(QBarSet *set) |
|
232 | bool QAbstractBarSeries::append(QBarSet *set) | |
233 | { |
|
233 | { | |
234 | Q_D(QAbstractBarSeries); |
|
234 | Q_D(QAbstractBarSeries); | |
235 | bool success = d->append(set); |
|
235 | bool success = d->append(set); | |
236 | if (success) { |
|
236 | if (success) { | |
237 | QList<QBarSet*> sets; |
|
237 | QList<QBarSet*> sets; | |
238 | sets.append(set); |
|
238 | sets.append(set); | |
239 | set->setParent(this); |
|
239 | set->setParent(this); | |
240 | emit barsetsAdded(sets); |
|
240 | emit barsetsAdded(sets); | |
241 | emit countChanged(); |
|
241 | emit countChanged(); | |
242 | } |
|
242 | } | |
243 | return success; |
|
243 | return success; | |
244 | } |
|
244 | } | |
245 |
|
245 | |||
246 | /*! |
|
246 | /*! | |
247 | Removes barset from series. Releases ownership of \a set. Deletes the set, if remove |
|
247 | Removes barset from series. Releases ownership of \a set. Deletes the set, if remove | |
248 | was successful. |
|
248 | was successful. | |
249 | Returns true, if set was removed. |
|
249 | Returns true, if set was removed. | |
250 | */ |
|
250 | */ | |
251 | bool QAbstractBarSeries::remove(QBarSet *set) |
|
251 | bool QAbstractBarSeries::remove(QBarSet *set) | |
252 | { |
|
252 | { | |
253 | Q_D(QAbstractBarSeries); |
|
253 | Q_D(QAbstractBarSeries); | |
254 | bool success = d->remove(set); |
|
254 | bool success = d->remove(set); | |
255 | if (success) { |
|
255 | if (success) { | |
256 | QList<QBarSet*> sets; |
|
256 | QList<QBarSet*> sets; | |
257 | sets.append(set); |
|
257 | sets.append(set); | |
258 | set->setParent(0); |
|
258 | set->setParent(0); | |
259 | emit barsetsRemoved(sets); |
|
259 | emit barsetsRemoved(sets); | |
260 | emit countChanged(); |
|
260 | emit countChanged(); | |
261 | delete set; |
|
261 | delete set; | |
262 | set = 0; |
|
262 | set = 0; | |
263 | } |
|
263 | } | |
264 | return success; |
|
264 | return success; | |
265 | } |
|
265 | } | |
266 |
|
266 | |||
267 | /*! |
|
267 | /*! | |
268 | Takes a single \a set from the series. Does not delete the barset object. |
|
268 | Takes a single \a set from the series. Does not delete the barset object. | |
269 |
|
269 | |||
270 | NOTE: The series remains as the barset's parent object. You must set the |
|
270 | NOTE: The series remains as the barset's parent object. You must set the | |
271 | parent object to take full ownership. |
|
271 | parent object to take full ownership. | |
272 |
|
272 | |||
273 |
Returns true if take was successful |
|
273 | Returns true if take was successful. | |
274 | */ |
|
274 | */ | |
275 | bool QAbstractBarSeries::take(QBarSet *set) |
|
275 | bool QAbstractBarSeries::take(QBarSet *set) | |
276 | { |
|
276 | { | |
277 | Q_D(QAbstractBarSeries); |
|
277 | Q_D(QAbstractBarSeries); | |
278 | bool success = d->remove(set); |
|
278 | bool success = d->remove(set); | |
279 | if (success) { |
|
279 | if (success) { | |
280 | QList<QBarSet*> sets; |
|
280 | QList<QBarSet*> sets; | |
281 | sets.append(set); |
|
281 | sets.append(set); | |
282 | emit barsetsRemoved(sets); |
|
282 | emit barsetsRemoved(sets); | |
283 | emit countChanged(); |
|
283 | emit countChanged(); | |
284 | } |
|
284 | } | |
285 | return success; |
|
285 | return success; | |
286 | } |
|
286 | } | |
287 |
|
287 | |||
288 | /*! |
|
288 | /*! | |
289 | Adds a list of barsets to series. Takes ownership of \a sets. |
|
289 | Adds a list of barsets to series. Takes ownership of \a sets. | |
290 | Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series, |
|
290 | Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series, | |
291 | nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended |
|
291 | nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended | |
292 | and function returns false. |
|
292 | and function returns false. | |
293 | */ |
|
293 | */ | |
294 | bool QAbstractBarSeries::append(QList<QBarSet* > sets) |
|
294 | bool QAbstractBarSeries::append(QList<QBarSet* > sets) | |
295 | { |
|
295 | { | |
296 | Q_D(QAbstractBarSeries); |
|
296 | Q_D(QAbstractBarSeries); | |
297 | bool success = d->append(sets); |
|
297 | bool success = d->append(sets); | |
298 | if (success) { |
|
298 | if (success) { | |
299 | emit barsetsAdded(sets); |
|
299 | emit barsetsAdded(sets); | |
300 | emit countChanged(); |
|
300 | emit countChanged(); | |
301 | } |
|
301 | } | |
302 | return success; |
|
302 | return success; | |
303 | } |
|
303 | } | |
304 |
|
304 | |||
305 | /*! |
|
305 | /*! | |
306 | Insert a set of bars to series at \a index postion. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. |
|
306 | Insert a set of bars to series at \a index postion. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. | |
307 | Returns true, if inserting succeeded. |
|
307 | Returns true, if inserting succeeded. | |
308 |
|
308 | |||
309 | */ |
|
309 | */ | |
310 | bool QAbstractBarSeries::insert(int index, QBarSet *set) |
|
310 | bool QAbstractBarSeries::insert(int index, QBarSet *set) | |
311 | { |
|
311 | { | |
312 | Q_D(QAbstractBarSeries); |
|
312 | Q_D(QAbstractBarSeries); | |
313 | bool success = d->insert(index, set); |
|
313 | bool success = d->insert(index, set); | |
314 | if (success) { |
|
314 | if (success) { | |
315 | QList<QBarSet*> sets; |
|
315 | QList<QBarSet*> sets; | |
316 | sets.append(set); |
|
316 | sets.append(set); | |
317 | emit barsetsAdded(sets); |
|
317 | emit barsetsAdded(sets); | |
318 | emit countChanged(); |
|
318 | emit countChanged(); | |
319 | } |
|
319 | } | |
320 | return success; |
|
320 | return success; | |
321 | } |
|
321 | } | |
322 |
|
322 | |||
323 | /*! |
|
323 | /*! | |
324 | Removes all barsets from the series. Deletes removed sets. |
|
324 | Removes all barsets from the series. Deletes removed sets. | |
325 | */ |
|
325 | */ | |
326 | void QAbstractBarSeries::clear() |
|
326 | void QAbstractBarSeries::clear() | |
327 | { |
|
327 | { | |
328 | Q_D(QAbstractBarSeries); |
|
328 | Q_D(QAbstractBarSeries); | |
329 | QList<QBarSet *> sets = barSets(); |
|
329 | QList<QBarSet *> sets = barSets(); | |
330 | bool success = d->remove(sets); |
|
330 | bool success = d->remove(sets); | |
331 | if (success) { |
|
331 | if (success) { | |
332 | emit barsetsRemoved(sets); |
|
332 | emit barsetsRemoved(sets); | |
333 | emit countChanged(); |
|
333 | emit countChanged(); | |
334 | foreach (QBarSet* set, sets) { |
|
334 | foreach (QBarSet* set, sets) { | |
335 | delete set; |
|
335 | delete set; | |
336 | } |
|
336 | } | |
337 | } |
|
337 | } | |
338 | } |
|
338 | } | |
339 |
|
339 | |||
340 | /*! |
|
340 | /*! | |
341 | Returns number of sets in series. |
|
341 | Returns number of sets in series. | |
342 | */ |
|
342 | */ | |
343 | int QAbstractBarSeries::count() const |
|
343 | int QAbstractBarSeries::count() const | |
344 | { |
|
344 | { | |
345 | Q_D(const QAbstractBarSeries); |
|
345 | Q_D(const QAbstractBarSeries); | |
346 | return d->m_barSets.count(); |
|
346 | return d->m_barSets.count(); | |
347 | } |
|
347 | } | |
348 |
|
348 | |||
349 | /*! |
|
349 | /*! | |
350 | Returns a list of sets in series. Keeps ownership of sets. |
|
350 | Returns a list of sets in series. Keeps ownership of sets. | |
351 | */ |
|
351 | */ | |
352 | QList<QBarSet*> QAbstractBarSeries::barSets() const |
|
352 | QList<QBarSet*> QAbstractBarSeries::barSets() const | |
353 | { |
|
353 | { | |
354 | Q_D(const QAbstractBarSeries); |
|
354 | Q_D(const QAbstractBarSeries); | |
355 | return d->m_barSets; |
|
355 | return d->m_barSets; | |
356 | } |
|
356 | } | |
357 |
|
357 | |||
358 | /*! |
|
358 | /*! | |
359 | Sets the visibility of labels in series to \a visible |
|
359 | Sets the visibility of labels in series to \a visible | |
360 | */ |
|
360 | */ | |
361 | void QAbstractBarSeries::setLabelsVisible(bool visible) |
|
361 | void QAbstractBarSeries::setLabelsVisible(bool visible) | |
362 | { |
|
362 | { | |
363 | Q_D(QAbstractBarSeries); |
|
363 | Q_D(QAbstractBarSeries); | |
364 | if (d->m_labelsVisible != visible) { |
|
364 | if (d->m_labelsVisible != visible) { | |
365 | d->setLabelsVisible(visible); |
|
365 | d->setLabelsVisible(visible); | |
366 | emit labelsVisibleChanged(); |
|
366 | emit labelsVisibleChanged(); | |
367 | } |
|
367 | } | |
368 | } |
|
368 | } | |
369 |
|
369 | |||
370 | /*! |
|
370 | /*! | |
371 | Returns the visibility of labels |
|
371 | Returns the visibility of labels | |
372 | */ |
|
372 | */ | |
373 | bool QAbstractBarSeries::isLabelsVisible() const |
|
373 | bool QAbstractBarSeries::isLabelsVisible() const | |
374 | { |
|
374 | { | |
375 | Q_D(const QAbstractBarSeries); |
|
375 | Q_D(const QAbstractBarSeries); | |
376 | return d->m_labelsVisible; |
|
376 | return d->m_labelsVisible; | |
377 | } |
|
377 | } | |
378 |
|
378 | |||
379 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
379 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
380 |
|
380 | |||
381 | QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) : |
|
381 | QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) : | |
382 | QAbstractSeriesPrivate(q), |
|
382 | QAbstractSeriesPrivate(q), | |
383 | m_barWidth(0.5), // Default value is 50% of category width |
|
383 | m_barWidth(0.5), // Default value is 50% of category width | |
384 | m_labelsVisible(false), |
|
384 | m_labelsVisible(false), | |
385 | m_visible(true) |
|
385 | m_visible(true) | |
386 | { |
|
386 | { | |
387 | } |
|
387 | } | |
388 |
|
388 | |||
389 | int QAbstractBarSeriesPrivate::categoryCount() const |
|
389 | int QAbstractBarSeriesPrivate::categoryCount() const | |
390 | { |
|
390 | { | |
391 | // No categories defined. return count of longest set. |
|
391 | // No categories defined. return count of longest set. | |
392 | int count = 0; |
|
392 | int count = 0; | |
393 | for (int i=0; i<m_barSets.count(); i++) { |
|
393 | for (int i=0; i<m_barSets.count(); i++) { | |
394 | if (m_barSets.at(i)->count() > count) { |
|
394 | if (m_barSets.at(i)->count() > count) { | |
395 | count = m_barSets.at(i)->count(); |
|
395 | count = m_barSets.at(i)->count(); | |
396 | } |
|
396 | } | |
397 | } |
|
397 | } | |
398 |
|
398 | |||
399 | return count; |
|
399 | return count; | |
400 | } |
|
400 | } | |
401 |
|
401 | |||
402 | void QAbstractBarSeriesPrivate::setBarWidth(qreal width) |
|
402 | void QAbstractBarSeriesPrivate::setBarWidth(qreal width) | |
403 | { |
|
403 | { | |
404 | if (width < 0.0) { |
|
404 | if (width < 0.0) { | |
405 | width = 0.0; |
|
405 | width = 0.0; | |
406 | } |
|
406 | } | |
407 | m_barWidth = width; |
|
407 | m_barWidth = width; | |
408 | emit updatedLayout(); |
|
408 | emit updatedLayout(); | |
409 | } |
|
409 | } | |
410 |
|
410 | |||
411 | qreal QAbstractBarSeriesPrivate::barWidth() const |
|
411 | qreal QAbstractBarSeriesPrivate::barWidth() const | |
412 | { |
|
412 | { | |
413 | return m_barWidth; |
|
413 | return m_barWidth; | |
414 | } |
|
414 | } | |
415 |
|
415 | |||
416 | QBarSet* QAbstractBarSeriesPrivate::barsetAt(int index) |
|
416 | QBarSet* QAbstractBarSeriesPrivate::barsetAt(int index) | |
417 | { |
|
417 | { | |
418 | return m_barSets.at(index); |
|
418 | return m_barSets.at(index); | |
419 | } |
|
419 | } | |
420 |
|
420 | |||
421 | void QAbstractBarSeriesPrivate::setVisible(bool visible) |
|
421 | void QAbstractBarSeriesPrivate::setVisible(bool visible) | |
422 | { |
|
422 | { | |
423 | m_visible = visible; |
|
423 | m_visible = visible; | |
424 | emit visibleChanged(); |
|
424 | emit visibleChanged(); | |
425 | } |
|
425 | } | |
426 |
|
426 | |||
427 | void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible) |
|
427 | void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible) | |
428 | { |
|
428 | { | |
429 | m_labelsVisible = visible; |
|
429 | m_labelsVisible = visible; | |
430 | emit labelsVisibleChanged(visible); |
|
430 | emit labelsVisibleChanged(visible); | |
431 | } |
|
431 | } | |
432 |
|
432 | |||
433 | qreal QAbstractBarSeriesPrivate::min() |
|
433 | qreal QAbstractBarSeriesPrivate::min() | |
434 | { |
|
434 | { | |
435 | if (m_barSets.count() <= 0) { |
|
435 | if (m_barSets.count() <= 0) { | |
436 | return 0; |
|
436 | return 0; | |
437 | } |
|
437 | } | |
438 | qreal min = INT_MAX; |
|
438 | qreal min = INT_MAX; | |
439 |
|
439 | |||
440 | for (int i = 0; i < m_barSets.count(); i++) { |
|
440 | for (int i = 0; i < m_barSets.count(); i++) { | |
441 | int categoryCount = m_barSets.at(i)->count(); |
|
441 | int categoryCount = m_barSets.at(i)->count(); | |
442 | for (int j = 0; j < categoryCount; j++) { |
|
442 | for (int j = 0; j < categoryCount; j++) { | |
443 | qreal temp = m_barSets.at(i)->at(j); |
|
443 | qreal temp = m_barSets.at(i)->at(j); | |
444 | if (temp < min) |
|
444 | if (temp < min) | |
445 | min = temp; |
|
445 | min = temp; | |
446 | } |
|
446 | } | |
447 | } |
|
447 | } | |
448 | return min; |
|
448 | return min; | |
449 | } |
|
449 | } | |
450 |
|
450 | |||
451 | qreal QAbstractBarSeriesPrivate::max() |
|
451 | qreal QAbstractBarSeriesPrivate::max() | |
452 | { |
|
452 | { | |
453 | if (m_barSets.count() <= 0) { |
|
453 | if (m_barSets.count() <= 0) { | |
454 | return 0; |
|
454 | return 0; | |
455 | } |
|
455 | } | |
456 | qreal max = INT_MIN; |
|
456 | qreal max = INT_MIN; | |
457 |
|
457 | |||
458 | for (int i = 0; i < m_barSets.count(); i++) { |
|
458 | for (int i = 0; i < m_barSets.count(); i++) { | |
459 | int categoryCount = m_barSets.at(i)->count(); |
|
459 | int categoryCount = m_barSets.at(i)->count(); | |
460 | for (int j = 0; j < categoryCount; j++) { |
|
460 | for (int j = 0; j < categoryCount; j++) { | |
461 | qreal temp = m_barSets.at(i)->at(j); |
|
461 | qreal temp = m_barSets.at(i)->at(j); | |
462 | if (temp > max) |
|
462 | if (temp > max) | |
463 | max = temp; |
|
463 | max = temp; | |
464 | } |
|
464 | } | |
465 | } |
|
465 | } | |
466 |
|
466 | |||
467 | return max; |
|
467 | return max; | |
468 | } |
|
468 | } | |
469 |
|
469 | |||
470 | qreal QAbstractBarSeriesPrivate::valueAt(int set, int category) |
|
470 | qreal QAbstractBarSeriesPrivate::valueAt(int set, int category) | |
471 | { |
|
471 | { | |
472 | if ((set < 0) || (set >= m_barSets.count())) { |
|
472 | if ((set < 0) || (set >= m_barSets.count())) { | |
473 | // No set, no value. |
|
473 | // No set, no value. | |
474 | return 0; |
|
474 | return 0; | |
475 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
475 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { | |
476 | // No category, no value. |
|
476 | // No category, no value. | |
477 | return 0; |
|
477 | return 0; | |
478 | } |
|
478 | } | |
479 |
|
479 | |||
480 | return m_barSets.at(set)->at(category); |
|
480 | return m_barSets.at(set)->at(category); | |
481 | } |
|
481 | } | |
482 |
|
482 | |||
483 | qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category) |
|
483 | qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category) | |
484 | { |
|
484 | { | |
485 | if ((set < 0) || (set >= m_barSets.count())) { |
|
485 | if ((set < 0) || (set >= m_barSets.count())) { | |
486 | // No set, no value. |
|
486 | // No set, no value. | |
487 | return 0; |
|
487 | return 0; | |
488 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
488 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { | |
489 | // No category, no value. |
|
489 | // No category, no value. | |
490 | return 0; |
|
490 | return 0; | |
491 | } |
|
491 | } | |
492 |
|
492 | |||
493 | qreal value = m_barSets.at(set)->at(category); |
|
493 | qreal value = m_barSets.at(set)->at(category); | |
494 | qreal sum = categorySum(category); |
|
494 | qreal sum = categorySum(category); | |
495 | if ( qFuzzyIsNull(sum) ) { |
|
495 | if ( qFuzzyIsNull(sum) ) { | |
496 | return 0; |
|
496 | return 0; | |
497 | } |
|
497 | } | |
498 |
|
498 | |||
499 | return value / sum; |
|
499 | return value / sum; | |
500 | } |
|
500 | } | |
501 |
|
501 | |||
502 | qreal QAbstractBarSeriesPrivate::categorySum(int category) |
|
502 | qreal QAbstractBarSeriesPrivate::categorySum(int category) | |
503 | { |
|
503 | { | |
504 | qreal sum(0); |
|
504 | qreal sum(0); | |
505 | int count = m_barSets.count(); // Count sets |
|
505 | int count = m_barSets.count(); // Count sets | |
506 | for (int set = 0; set < count; set++) { |
|
506 | for (int set = 0; set < count; set++) { | |
507 | if (category < m_barSets.at(set)->count()) |
|
507 | if (category < m_barSets.at(set)->count()) | |
508 | sum += m_barSets.at(set)->at(category); |
|
508 | sum += m_barSets.at(set)->at(category); | |
509 | } |
|
509 | } | |
510 | return sum; |
|
510 | return sum; | |
511 | } |
|
511 | } | |
512 |
|
512 | |||
513 | qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category) |
|
513 | qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category) | |
514 | { |
|
514 | { | |
515 | qreal sum(0); |
|
515 | qreal sum(0); | |
516 | int count = m_barSets.count(); // Count sets |
|
516 | int count = m_barSets.count(); // Count sets | |
517 | for (int set = 0; set < count; set++) { |
|
517 | for (int set = 0; set < count; set++) { | |
518 | if (category < m_barSets.at(set)->count()) |
|
518 | if (category < m_barSets.at(set)->count()) | |
519 | sum += qAbs(m_barSets.at(set)->at(category)); |
|
519 | sum += qAbs(m_barSets.at(set)->at(category)); | |
520 | } |
|
520 | } | |
521 | return sum; |
|
521 | return sum; | |
522 | } |
|
522 | } | |
523 |
|
523 | |||
524 | qreal QAbstractBarSeriesPrivate::maxCategorySum() |
|
524 | qreal QAbstractBarSeriesPrivate::maxCategorySum() | |
525 | { |
|
525 | { | |
526 | qreal max = INT_MIN; |
|
526 | qreal max = INT_MIN; | |
527 | int count = categoryCount(); |
|
527 | int count = categoryCount(); | |
528 | for (int i = 0; i < count; i++) { |
|
528 | for (int i = 0; i < count; i++) { | |
529 | qreal sum = categorySum(i); |
|
529 | qreal sum = categorySum(i); | |
530 | if (sum > max) |
|
530 | if (sum > max) | |
531 | max = sum; |
|
531 | max = sum; | |
532 | } |
|
532 | } | |
533 | return max; |
|
533 | return max; | |
534 | } |
|
534 | } | |
535 |
|
535 | |||
536 | qreal QAbstractBarSeriesPrivate::minX() |
|
536 | qreal QAbstractBarSeriesPrivate::minX() | |
537 | { |
|
537 | { | |
538 | if (m_barSets.count() <= 0) { |
|
538 | if (m_barSets.count() <= 0) { | |
539 | return 0; |
|
539 | return 0; | |
540 | } |
|
540 | } | |
541 | qreal min = INT_MAX; |
|
541 | qreal min = INT_MAX; | |
542 |
|
542 | |||
543 | for (int i = 0; i < m_barSets.count(); i++) { |
|
543 | for (int i = 0; i < m_barSets.count(); i++) { | |
544 | int categoryCount = m_barSets.at(i)->count(); |
|
544 | int categoryCount = m_barSets.at(i)->count(); | |
545 | for (int j = 0; j < categoryCount; j++) { |
|
545 | for (int j = 0; j < categoryCount; j++) { | |
546 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); |
|
546 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); | |
547 | if (temp < min) |
|
547 | if (temp < min) | |
548 | min = temp; |
|
548 | min = temp; | |
549 | } |
|
549 | } | |
550 | } |
|
550 | } | |
551 | return min; |
|
551 | return min; | |
552 | } |
|
552 | } | |
553 |
|
553 | |||
554 | qreal QAbstractBarSeriesPrivate::maxX() |
|
554 | qreal QAbstractBarSeriesPrivate::maxX() | |
555 | { |
|
555 | { | |
556 | if (m_barSets.count() <= 0) { |
|
556 | if (m_barSets.count() <= 0) { | |
557 | return 0; |
|
557 | return 0; | |
558 | } |
|
558 | } | |
559 | qreal max = INT_MIN; |
|
559 | qreal max = INT_MIN; | |
560 |
|
560 | |||
561 | for (int i = 0; i < m_barSets.count(); i++) { |
|
561 | for (int i = 0; i < m_barSets.count(); i++) { | |
562 | int categoryCount = m_barSets.at(i)->count(); |
|
562 | int categoryCount = m_barSets.at(i)->count(); | |
563 | for (int j = 0; j < categoryCount; j++) { |
|
563 | for (int j = 0; j < categoryCount; j++) { | |
564 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); |
|
564 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); | |
565 | if (temp > max) |
|
565 | if (temp > max) | |
566 | max = temp; |
|
566 | max = temp; | |
567 | } |
|
567 | } | |
568 | } |
|
568 | } | |
569 |
|
569 | |||
570 | return max; |
|
570 | return max; | |
571 | } |
|
571 | } | |
572 |
|
572 | |||
573 | qreal QAbstractBarSeriesPrivate::categoryTop(int category) |
|
573 | qreal QAbstractBarSeriesPrivate::categoryTop(int category) | |
574 | { |
|
574 | { | |
575 | // Returns top (sum of all positive values) of category. |
|
575 | // Returns top (sum of all positive values) of category. | |
576 | // Returns 0, if all values are negative |
|
576 | // Returns 0, if all values are negative | |
577 | qreal top(0); |
|
577 | qreal top(0); | |
578 | int count = m_barSets.count(); |
|
578 | int count = m_barSets.count(); | |
579 | for (int set = 0; set < count; set++) { |
|
579 | for (int set = 0; set < count; set++) { | |
580 | if (category < m_barSets.at(set)->count()) { |
|
580 | if (category < m_barSets.at(set)->count()) { | |
581 | qreal temp = m_barSets.at(set)->at(category); |
|
581 | qreal temp = m_barSets.at(set)->at(category); | |
582 | if (temp > 0) { |
|
582 | if (temp > 0) { | |
583 | top += temp; |
|
583 | top += temp; | |
584 | } |
|
584 | } | |
585 | } |
|
585 | } | |
586 | } |
|
586 | } | |
587 | return top; |
|
587 | return top; | |
588 | } |
|
588 | } | |
589 |
|
589 | |||
590 | qreal QAbstractBarSeriesPrivate::categoryBottom(int category) |
|
590 | qreal QAbstractBarSeriesPrivate::categoryBottom(int category) | |
591 | { |
|
591 | { | |
592 | // Returns bottom (sum of all negative values) of category |
|
592 | // Returns bottom (sum of all negative values) of category | |
593 | // Returns 0, if all values are positive |
|
593 | // Returns 0, if all values are positive | |
594 | qreal bottom(0); |
|
594 | qreal bottom(0); | |
595 | int count = m_barSets.count(); |
|
595 | int count = m_barSets.count(); | |
596 | for (int set = 0; set < count; set++) { |
|
596 | for (int set = 0; set < count; set++) { | |
597 | if (category < m_barSets.at(set)->count()) { |
|
597 | if (category < m_barSets.at(set)->count()) { | |
598 | qreal temp = m_barSets.at(set)->at(category); |
|
598 | qreal temp = m_barSets.at(set)->at(category); | |
599 | if (temp < 0) { |
|
599 | if (temp < 0) { | |
600 | bottom += temp; |
|
600 | bottom += temp; | |
601 | } |
|
601 | } | |
602 | } |
|
602 | } | |
603 | } |
|
603 | } | |
604 | return bottom; |
|
604 | return bottom; | |
605 | } |
|
605 | } | |
606 |
|
606 | |||
607 | qreal QAbstractBarSeriesPrivate::top() |
|
607 | qreal QAbstractBarSeriesPrivate::top() | |
608 | { |
|
608 | { | |
609 | // Returns top of all categories |
|
609 | // Returns top of all categories | |
610 | qreal top(0); |
|
610 | qreal top(0); | |
611 | int count = categoryCount(); |
|
611 | int count = categoryCount(); | |
612 | for (int i=0; i<count; i++) { |
|
612 | for (int i=0; i<count; i++) { | |
613 | qreal temp = categoryTop(i); |
|
613 | qreal temp = categoryTop(i); | |
614 | if (temp > top) { |
|
614 | if (temp > top) { | |
615 | top = temp; |
|
615 | top = temp; | |
616 | } |
|
616 | } | |
617 | } |
|
617 | } | |
618 | return top; |
|
618 | return top; | |
619 | } |
|
619 | } | |
620 |
|
620 | |||
621 | qreal QAbstractBarSeriesPrivate::bottom() |
|
621 | qreal QAbstractBarSeriesPrivate::bottom() | |
622 | { |
|
622 | { | |
623 | // Returns bottom of all categories |
|
623 | // Returns bottom of all categories | |
624 | qreal bottom(0); |
|
624 | qreal bottom(0); | |
625 | int count = categoryCount(); |
|
625 | int count = categoryCount(); | |
626 | for (int i=0; i<count; i++) { |
|
626 | for (int i=0; i<count; i++) { | |
627 | qreal temp = categoryBottom(i); |
|
627 | qreal temp = categoryBottom(i); | |
628 | if (temp < bottom) { |
|
628 | if (temp < bottom) { | |
629 | bottom = temp; |
|
629 | bottom = temp; | |
630 | } |
|
630 | } | |
631 | } |
|
631 | } | |
632 | return bottom; |
|
632 | return bottom; | |
633 | } |
|
633 | } | |
634 |
|
634 | |||
635 |
|
635 | |||
636 | void QAbstractBarSeriesPrivate::scaleDomain(Domain& domain) |
|
636 | void QAbstractBarSeriesPrivate::scaleDomain(Domain& domain) | |
637 | { |
|
637 | { | |
638 | qreal minX(domain.minX()); |
|
638 | qreal minX(domain.minX()); | |
639 | qreal minY(domain.minY()); |
|
639 | qreal minY(domain.minY()); | |
640 | qreal maxX(domain.maxX()); |
|
640 | qreal maxX(domain.maxX()); | |
641 | qreal maxY(domain.maxY()); |
|
641 | qreal maxY(domain.maxY()); | |
642 |
|
642 | |||
643 | qreal seriesMinX = this->minX(); |
|
643 | qreal seriesMinX = this->minX(); | |
644 | qreal seriesMaxX = this->maxX(); |
|
644 | qreal seriesMaxX = this->maxX(); | |
645 | qreal y = max(); |
|
645 | qreal y = max(); | |
646 | minX = qMin(minX, seriesMinX - (qreal)0.5); |
|
646 | minX = qMin(minX, seriesMinX - (qreal)0.5); | |
647 | minY = qMin(minY, y); |
|
647 | minY = qMin(minY, y); | |
648 | maxX = qMax(maxX, seriesMaxX + (qreal)0.5); |
|
648 | maxX = qMax(maxX, seriesMaxX + (qreal)0.5); | |
649 | maxY = qMax(maxY, y); |
|
649 | maxY = qMax(maxY, y); | |
650 |
|
650 | |||
651 | domain.setRange(minX,maxX,minY,maxY); |
|
651 | domain.setRange(minX,maxX,minY,maxY); | |
652 | } |
|
652 | } | |
653 |
|
653 | |||
654 | ChartElement* QAbstractBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
654 | ChartElement* QAbstractBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
655 | { |
|
655 | { | |
656 | Q_UNUSED(presenter); |
|
656 | Q_UNUSED(presenter); | |
657 | qWarning() << "QAbstractBarSeriesPrivate::createGraphics called"; |
|
657 | qWarning() << "QAbstractBarSeriesPrivate::createGraphics called"; | |
658 | return 0; |
|
658 | return 0; | |
659 | } |
|
659 | } | |
660 |
|
660 | |||
661 | QList<LegendMarker*> QAbstractBarSeriesPrivate::createLegendMarker(QLegend* legend) |
|
661 | QList<LegendMarker*> QAbstractBarSeriesPrivate::createLegendMarker(QLegend* legend) | |
662 | { |
|
662 | { | |
663 | Q_Q(QAbstractBarSeries); |
|
663 | Q_Q(QAbstractBarSeries); | |
664 | QList<LegendMarker*> markers; |
|
664 | QList<LegendMarker*> markers; | |
665 | foreach(QBarSet* set, q->barSets()) { |
|
665 | foreach(QBarSet* set, q->barSets()) { | |
666 | BarLegendMarker* marker = new BarLegendMarker(q,set,legend); |
|
666 | BarLegendMarker* marker = new BarLegendMarker(q,set,legend); | |
667 | markers << marker; |
|
667 | markers << marker; | |
668 | } |
|
668 | } | |
669 |
|
669 | |||
670 | return markers; |
|
670 | return markers; | |
671 | } |
|
671 | } | |
672 |
|
672 | |||
673 | bool QAbstractBarSeriesPrivate::append(QBarSet *set) |
|
673 | bool QAbstractBarSeriesPrivate::append(QBarSet *set) | |
674 | { |
|
674 | { | |
675 | Q_Q(QAbstractBarSeries); |
|
675 | Q_Q(QAbstractBarSeries); | |
676 | if ((m_barSets.contains(set)) || (set == 0)) { |
|
676 | if ((m_barSets.contains(set)) || (set == 0)) { | |
677 | // Fail if set is already in list or set is null. |
|
677 | // Fail if set is already in list or set is null. | |
678 | return false; |
|
678 | return false; | |
679 | } |
|
679 | } | |
680 | m_barSets.append(set); |
|
680 | m_barSets.append(set); | |
681 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); |
|
681 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); | |
682 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
682 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
683 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
683 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
684 | emit restructuredBars(); // this notifies barchartitem |
|
684 | emit restructuredBars(); // this notifies barchartitem | |
685 | if (m_dataset) { |
|
685 | if (m_dataset) { | |
686 | m_dataset->updateSeries(q); // this notifies legend |
|
686 | m_dataset->updateSeries(q); // this notifies legend | |
687 | } |
|
687 | } | |
688 | return true; |
|
688 | return true; | |
689 | } |
|
689 | } | |
690 |
|
690 | |||
691 | bool QAbstractBarSeriesPrivate::remove(QBarSet *set) |
|
691 | bool QAbstractBarSeriesPrivate::remove(QBarSet *set) | |
692 | { |
|
692 | { | |
693 | Q_Q(QAbstractBarSeries); |
|
693 | Q_Q(QAbstractBarSeries); | |
694 | if (!m_barSets.contains(set)) { |
|
694 | if (!m_barSets.contains(set)) { | |
695 | // Fail if set is not in list |
|
695 | // Fail if set is not in list | |
696 | return false; |
|
696 | return false; | |
697 | } |
|
697 | } | |
698 | m_barSets.removeOne(set); |
|
698 | m_barSets.removeOne(set); | |
699 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); |
|
699 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); | |
700 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
700 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
701 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
701 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
702 | emit restructuredBars(); // this notifies barchartitem |
|
702 | emit restructuredBars(); // this notifies barchartitem | |
703 | if (m_dataset) { |
|
703 | if (m_dataset) { | |
704 | m_dataset->updateSeries(q); // this notifies legend |
|
704 | m_dataset->updateSeries(q); // this notifies legend | |
705 | } |
|
705 | } | |
706 | return true; |
|
706 | return true; | |
707 | } |
|
707 | } | |
708 |
|
708 | |||
709 | bool QAbstractBarSeriesPrivate::append(QList<QBarSet* > sets) |
|
709 | bool QAbstractBarSeriesPrivate::append(QList<QBarSet* > sets) | |
710 | { |
|
710 | { | |
711 | Q_Q(QAbstractBarSeries); |
|
711 | Q_Q(QAbstractBarSeries); | |
712 | foreach (QBarSet* set, sets) { |
|
712 | foreach (QBarSet* set, sets) { | |
713 | if ((set == 0) || (m_barSets.contains(set))) { |
|
713 | if ((set == 0) || (m_barSets.contains(set))) { | |
714 | // Fail if any of the sets is null or is already appended. |
|
714 | // Fail if any of the sets is null or is already appended. | |
715 | return false; |
|
715 | return false; | |
716 | } |
|
716 | } | |
717 | if (sets.count(set) != 1) { |
|
717 | if (sets.count(set) != 1) { | |
718 | // Also fail if same set is more than once in given list. |
|
718 | // Also fail if same set is more than once in given list. | |
719 | return false; |
|
719 | return false; | |
720 | } |
|
720 | } | |
721 | } |
|
721 | } | |
722 |
|
722 | |||
723 | foreach (QBarSet* set, sets) { |
|
723 | foreach (QBarSet* set, sets) { | |
724 | m_barSets.append(set); |
|
724 | m_barSets.append(set); | |
725 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); |
|
725 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); | |
726 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
726 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
727 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
727 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
728 | } |
|
728 | } | |
729 | emit restructuredBars(); // this notifies barchartitem |
|
729 | emit restructuredBars(); // this notifies barchartitem | |
730 | if (m_dataset) { |
|
730 | if (m_dataset) { | |
731 | m_dataset->updateSeries(q); // this notifies legend |
|
731 | m_dataset->updateSeries(q); // this notifies legend | |
732 | } |
|
732 | } | |
733 | return true; |
|
733 | return true; | |
734 | } |
|
734 | } | |
735 |
|
735 | |||
736 | bool QAbstractBarSeriesPrivate::remove(QList<QBarSet* > sets) |
|
736 | bool QAbstractBarSeriesPrivate::remove(QList<QBarSet* > sets) | |
737 | { |
|
737 | { | |
738 | Q_Q(QAbstractBarSeries); |
|
738 | Q_Q(QAbstractBarSeries); | |
739 | if (sets.count() == 0) { |
|
739 | if (sets.count() == 0) { | |
740 | return false; |
|
740 | return false; | |
741 | } |
|
741 | } | |
742 | foreach (QBarSet* set, sets) { |
|
742 | foreach (QBarSet* set, sets) { | |
743 | if ((set == 0) || (!m_barSets.contains(set))) { |
|
743 | if ((set == 0) || (!m_barSets.contains(set))) { | |
744 | // Fail if any of the sets is null or is not in series |
|
744 | // Fail if any of the sets is null or is not in series | |
745 | return false; |
|
745 | return false; | |
746 | } |
|
746 | } | |
747 | if (sets.count(set) != 1) { |
|
747 | if (sets.count(set) != 1) { | |
748 | // Also fail if same set is more than once in given list. |
|
748 | // Also fail if same set is more than once in given list. | |
749 | return false; |
|
749 | return false; | |
750 | } |
|
750 | } | |
751 | } |
|
751 | } | |
752 |
|
752 | |||
753 | foreach (QBarSet* set, sets) { |
|
753 | foreach (QBarSet* set, sets) { | |
754 | m_barSets.removeOne(set); |
|
754 | m_barSets.removeOne(set); | |
755 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); |
|
755 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); | |
756 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
756 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
757 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
757 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
758 | } |
|
758 | } | |
759 |
|
759 | |||
760 | emit restructuredBars(); // this notifies barchartitem |
|
760 | emit restructuredBars(); // this notifies barchartitem | |
761 | if (m_dataset) { |
|
761 | if (m_dataset) { | |
762 | m_dataset->updateSeries(q); // this notifies legend |
|
762 | m_dataset->updateSeries(q); // this notifies legend | |
763 | } |
|
763 | } | |
764 | return true; |
|
764 | return true; | |
765 | } |
|
765 | } | |
766 |
|
766 | |||
767 | bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set) |
|
767 | bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set) | |
768 | { |
|
768 | { | |
769 | Q_Q(QAbstractBarSeries); |
|
769 | Q_Q(QAbstractBarSeries); | |
770 | if ((m_barSets.contains(set)) || (set == 0)) { |
|
770 | if ((m_barSets.contains(set)) || (set == 0)) { | |
771 | // Fail if set is already in list or set is null. |
|
771 | // Fail if set is already in list or set is null. | |
772 | return false; |
|
772 | return false; | |
773 | } |
|
773 | } | |
774 | m_barSets.insert(index, set); |
|
774 | m_barSets.insert(index, set); | |
775 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); |
|
775 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); | |
776 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
776 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
777 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
777 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
778 | emit restructuredBars(); // this notifies barchartitem |
|
778 | emit restructuredBars(); // this notifies barchartitem | |
779 | if (m_dataset) { |
|
779 | if (m_dataset) { | |
780 | m_dataset->updateSeries(q); // this notifies legend |
|
780 | m_dataset->updateSeries(q); // this notifies legend | |
781 | } |
|
781 | } | |
782 | return true; |
|
782 | return true; | |
783 | } |
|
783 | } | |
784 |
|
784 | |||
785 | void QAbstractBarSeriesPrivate::initializeAxis(QAbstractAxis* axis) |
|
785 | void QAbstractBarSeriesPrivate::initializeAxis(QAbstractAxis* axis) | |
786 | { |
|
786 | { | |
787 | Q_Q(QAbstractBarSeries); |
|
787 | Q_Q(QAbstractBarSeries); | |
788 |
|
788 | |||
789 | if(axis->type()==QAbstractAxis::AxisTypeBarCategory) { |
|
789 | if(axis->type()==QAbstractAxis::AxisTypeBarCategory) { | |
790 |
|
790 | |||
791 | switch(q->type()) { |
|
791 | switch(q->type()) { | |
792 |
|
792 | |||
793 | case QAbstractSeries::SeriesTypeHorizontalBar: |
|
793 | case QAbstractSeries::SeriesTypeHorizontalBar: | |
794 | case QAbstractSeries::SeriesTypeHorizontalPercentBar: |
|
794 | case QAbstractSeries::SeriesTypeHorizontalPercentBar: | |
795 | case QAbstractSeries::SeriesTypeHorizontalStackedBar: { |
|
795 | case QAbstractSeries::SeriesTypeHorizontalStackedBar: { | |
796 |
|
796 | |||
797 | if(axis->orientation()==Qt::Vertical) |
|
797 | if(axis->orientation()==Qt::Vertical) | |
798 | { |
|
798 | { | |
799 | populateCategories(qobject_cast<QBarCategoryAxis*>(axis)); |
|
799 | populateCategories(qobject_cast<QBarCategoryAxis*>(axis)); | |
800 | } |
|
800 | } | |
801 | break; |
|
801 | break; | |
802 | } |
|
802 | } | |
803 | case QAbstractSeries::SeriesTypeBar: |
|
803 | case QAbstractSeries::SeriesTypeBar: | |
804 | case QAbstractSeries::SeriesTypePercentBar: |
|
804 | case QAbstractSeries::SeriesTypePercentBar: | |
805 | case QAbstractSeries::SeriesTypeStackedBar: { |
|
805 | case QAbstractSeries::SeriesTypeStackedBar: { | |
806 |
|
806 | |||
807 | if(axis->orientation()==Qt::Horizontal) |
|
807 | if(axis->orientation()==Qt::Horizontal) | |
808 | { |
|
808 | { | |
809 | populateCategories(qobject_cast<QBarCategoryAxis*>(axis)); |
|
809 | populateCategories(qobject_cast<QBarCategoryAxis*>(axis)); | |
810 | } |
|
810 | } | |
811 | break; |
|
811 | break; | |
812 | } |
|
812 | } | |
813 | default: |
|
813 | default: | |
814 | qWarning()<<"Unexpected series type"; |
|
814 | qWarning()<<"Unexpected series type"; | |
815 | break; |
|
815 | break; | |
816 |
|
816 | |||
817 | } |
|
817 | } | |
818 | } |
|
818 | } | |
819 | } |
|
819 | } | |
820 |
|
820 | |||
821 | QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const |
|
821 | QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const | |
822 | { |
|
822 | { | |
823 | Q_Q(const QAbstractBarSeries); |
|
823 | Q_Q(const QAbstractBarSeries); | |
824 |
|
824 | |||
825 | switch(q->type()) { |
|
825 | switch(q->type()) { | |
826 |
|
826 | |||
827 | case QAbstractSeries::SeriesTypeHorizontalBar: |
|
827 | case QAbstractSeries::SeriesTypeHorizontalBar: | |
828 | case QAbstractSeries::SeriesTypeHorizontalPercentBar: |
|
828 | case QAbstractSeries::SeriesTypeHorizontalPercentBar: | |
829 | case QAbstractSeries::SeriesTypeHorizontalStackedBar: { |
|
829 | case QAbstractSeries::SeriesTypeHorizontalStackedBar: { | |
830 |
|
830 | |||
831 | if(orientation==Qt::Vertical) |
|
831 | if(orientation==Qt::Vertical) | |
832 | { |
|
832 | { | |
833 | return QAbstractAxis::AxisTypeBarCategory; |
|
833 | return QAbstractAxis::AxisTypeBarCategory; | |
834 | } |
|
834 | } | |
835 | break; |
|
835 | break; | |
836 | } |
|
836 | } | |
837 | case QAbstractSeries::SeriesTypeBar: |
|
837 | case QAbstractSeries::SeriesTypeBar: | |
838 | case QAbstractSeries::SeriesTypePercentBar: |
|
838 | case QAbstractSeries::SeriesTypePercentBar: | |
839 | case QAbstractSeries::SeriesTypeStackedBar: { |
|
839 | case QAbstractSeries::SeriesTypeStackedBar: { | |
840 |
|
840 | |||
841 | if(orientation==Qt::Horizontal) |
|
841 | if(orientation==Qt::Horizontal) | |
842 | { |
|
842 | { | |
843 | return QAbstractAxis::AxisTypeBarCategory; |
|
843 | return QAbstractAxis::AxisTypeBarCategory; | |
844 | } |
|
844 | } | |
845 | break; |
|
845 | break; | |
846 | } |
|
846 | } | |
847 | default: |
|
847 | default: | |
848 | qWarning()<<"Unexpected series type"; |
|
848 | qWarning()<<"Unexpected series type"; | |
849 | break; |
|
849 | break; | |
850 |
|
850 | |||
851 | } |
|
851 | } | |
852 | return QAbstractAxis::AxisTypeValue; |
|
852 | return QAbstractAxis::AxisTypeValue; | |
853 |
|
853 | |||
854 | } |
|
854 | } | |
855 |
|
855 | |||
856 | void QAbstractBarSeriesPrivate::populateCategories(QBarCategoryAxis* axis) |
|
856 | void QAbstractBarSeriesPrivate::populateCategories(QBarCategoryAxis* axis) | |
857 | { |
|
857 | { | |
858 | QStringList categories; |
|
858 | QStringList categories; | |
859 | if(axis->categories().isEmpty()) { |
|
859 | if(axis->categories().isEmpty()) { | |
860 | for (int i(1); i < categoryCount()+1; i++) |
|
860 | for (int i(1); i < categoryCount()+1; i++) | |
861 | categories << QString::number(i); |
|
861 | categories << QString::number(i); | |
862 | axis->append(categories); |
|
862 | axis->append(categories); | |
863 | } |
|
863 | } | |
864 | } |
|
864 | } | |
865 |
|
865 | |||
866 | #include "moc_qabstractbarseries.cpp" |
|
866 | #include "moc_qabstractbarseries.cpp" | |
867 | #include "moc_qabstractbarseries_p.cpp" |
|
867 | #include "moc_qabstractbarseries_p.cpp" | |
868 |
|
868 | |||
869 |
|
869 | |||
870 | QTCOMMERCIALCHART_END_NAMESPACE |
|
870 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,650 +1,650 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qbarset.h" |
|
21 | #include "qbarset.h" | |
22 | #include "qbarset_p.h" |
|
22 | #include "qbarset_p.h" | |
23 |
|
23 | |||
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
25 |
|
25 | |||
26 | /*! |
|
26 | /*! | |
27 | \class QBarSet |
|
27 | \class QBarSet | |
28 | \brief Building block for different bar charts |
|
28 | \brief Building block for different bar charts | |
29 |
|
29 | |||
30 | QBarSet represents one set of bars. Set of bars contains one data value for each category. |
|
30 | QBarSet represents one set of bars. Set of bars contains one data value for each category. | |
31 | First value of set is assumed to belong to first category, second to second category and so on. |
|
31 | First value of set is assumed to belong to first category, second to second category and so on. | |
32 | If set has fewer values than there are categories, then the missing values are assumed to be |
|
32 | If set has fewer values than there are categories, then the missing values are assumed to be | |
33 | at the end of set. For missing values in middle of a set, numerical value of zero is used. |
|
33 | at the end of set. For missing values in middle of a set, numerical value of zero is used. | |
34 |
|
34 | |||
35 | \mainclass |
|
35 | \mainclass | |
36 |
|
36 | |||
37 | \sa QAbstractBarSeries, QBarSeries, QStackedBarSeries, QPercentBarSeries |
|
37 | \sa QAbstractBarSeries, QBarSeries, QStackedBarSeries, QPercentBarSeries | |
38 | */ |
|
38 | */ | |
39 | /*! |
|
39 | /*! | |
40 | \qmlclass BarSet QBarSet |
|
40 | \qmlclass BarSet QBarSet | |
41 |
|
41 | |||
42 | BarSet represents one set of bars. Set of bars contains one data value for each category. |
|
42 | BarSet represents one set of bars. Set of bars contains one data value for each category. | |
43 | First value of set is assumed to belong to first category, second to second category and so on. |
|
43 | First value of set is assumed to belong to first category, second to second category and so on. | |
44 | If set has fewer values than there are categories, then the missing values are assumed to be |
|
44 | If set has fewer values than there are categories, then the missing values are assumed to be | |
45 | at the end of set. For missing values in middle of a set, numerical value of zero is used. |
|
45 | at the end of set. For missing values in middle of a set, numerical value of zero is used. | |
46 | \sa AbstractBarSeries, BarSeries, StackedBarSeries, PercentBarSeries |
|
46 | \sa AbstractBarSeries, BarSeries, StackedBarSeries, PercentBarSeries | |
47 | */ |
|
47 | */ | |
48 |
|
48 | |||
49 | /*! |
|
49 | /*! | |
50 | \property QBarSet::label |
|
50 | \property QBarSet::label | |
51 | Defines the label of the barSet. |
|
51 | Defines the label of the barSet. | |
52 | */ |
|
52 | */ | |
53 | /*! |
|
53 | /*! | |
54 | \qmlproperty string BarSet::label |
|
54 | \qmlproperty string BarSet::label | |
55 | Defines the label of the barSet. |
|
55 | Defines the label of the barSet. | |
56 | */ |
|
56 | */ | |
57 |
|
57 | |||
58 | /*! |
|
58 | /*! | |
59 | \property QBarSet::pen |
|
59 | \property QBarSet::pen | |
60 | \brief Defines the pen used by the barSet. |
|
60 | \brief Defines the pen used by the barSet. | |
61 | */ |
|
61 | */ | |
62 |
|
62 | |||
63 | /*! |
|
63 | /*! | |
64 | \property QBarSet::brush |
|
64 | \property QBarSet::brush | |
65 | \brief Defines the brush used by the barSet. |
|
65 | \brief Defines the brush used by the barSet. | |
66 | */ |
|
66 | */ | |
67 |
|
67 | |||
68 | /*! |
|
68 | /*! | |
69 | \property QBarSet::labelBrush |
|
69 | \property QBarSet::labelBrush | |
70 | \brief Defines the brush used by the barSet's label. |
|
70 | \brief Defines the brush used by the barSet's label. | |
71 | */ |
|
71 | */ | |
72 |
|
72 | |||
73 | /*! |
|
73 | /*! | |
74 | \property QBarSet::labelFont |
|
74 | \property QBarSet::labelFont | |
75 | \brief Defines the font used by the barSet's label. |
|
75 | \brief Defines the font used by the barSet's label. | |
76 | */ |
|
76 | */ | |
77 |
|
77 | |||
78 | /*! |
|
78 | /*! | |
79 | \qmlproperty Font BarSet::labelFont |
|
79 | \qmlproperty Font BarSet::labelFont | |
80 | Defines the font used by the barSet's label. |
|
80 | Defines the font used by the barSet's label. | |
81 |
|
81 | |||
82 | See the \l {Font} {QML Font Element} for detailed documentation. |
|
82 | See the \l {Font} {QML Font Element} for detailed documentation. | |
83 | */ |
|
83 | */ | |
84 |
|
84 | |||
85 | /*! |
|
85 | /*! | |
86 | \property QBarSet::color |
|
86 | \property QBarSet::color | |
87 | The fill (brush) color of the bar set. |
|
87 | The fill (brush) color of the bar set. | |
88 | */ |
|
88 | */ | |
89 | /*! |
|
89 | /*! | |
90 | \qmlproperty color BarSet::color |
|
90 | \qmlproperty color BarSet::color | |
91 | The fill (brush) color of the bar set. |
|
91 | The fill (brush) color of the bar set. | |
92 | */ |
|
92 | */ | |
93 |
|
93 | |||
94 | /*! |
|
94 | /*! | |
95 | \property QBarSet::borderColor |
|
95 | \property QBarSet::borderColor | |
96 | The line (pen) color of the bar set. |
|
96 | The line (pen) color of the bar set. | |
97 | */ |
|
97 | */ | |
98 | /*! |
|
98 | /*! | |
99 | \qmlproperty color BarSet::borderColor |
|
99 | \qmlproperty color BarSet::borderColor | |
100 | The line (pen) color of the bar set. |
|
100 | The line (pen) color of the bar set. | |
101 | */ |
|
101 | */ | |
102 |
|
102 | |||
103 | /*! |
|
103 | /*! | |
104 | \qmlproperty real BarSet::borderWidth |
|
104 | \qmlproperty real BarSet::borderWidth | |
105 | The width of the border line. By default the width is 2.0. |
|
105 | The width of the border line. By default the width is 2.0. | |
106 | */ |
|
106 | */ | |
107 |
|
107 | |||
108 | /*! |
|
108 | /*! | |
109 | \property QBarSet::labelColor |
|
109 | \property QBarSet::labelColor | |
110 | The text (label) color of the bar set. |
|
110 | The text (label) color of the bar set. | |
111 | */ |
|
111 | */ | |
112 | /*! |
|
112 | /*! | |
113 | \qmlproperty color BarSet::labelColor |
|
113 | \qmlproperty color BarSet::labelColor | |
114 | The text (label) color of the bar set. |
|
114 | The text (label) color of the bar set. | |
115 | */ |
|
115 | */ | |
116 |
|
116 | |||
117 | /*! |
|
117 | /*! | |
118 | \fn void QBarSet::clicked(int index) |
|
118 | \fn void QBarSet::clicked(int index) | |
119 |
|
119 | |||
120 | The signal is emitted if the user clicks with a mouse on top of barset. |
|
120 | The signal is emitted if the user clicks with a mouse on top of barset. | |
121 | Clicked bar inside set is indexed by \a index |
|
121 | Clicked bar inside set is indexed by \a index | |
122 | */ |
|
122 | */ | |
123 |
|
123 | |||
124 | /*! |
|
124 | /*! | |
125 | \fn void QBarSet::hovered(bool status) |
|
125 | \fn void QBarSet::hovered(bool status) | |
126 |
|
126 | |||
127 | The signal is emitted if mouse is hovered on top of barset. |
|
127 | The signal is emitted if mouse is hovered on top of barset. | |
128 | Parameter \a status is true, if mouse entered on top of barset, false if mouse left from top of barset. |
|
128 | Parameter \a status is true, if mouse entered on top of barset, false if mouse left from top of barset. | |
129 | */ |
|
129 | */ | |
130 |
|
130 | |||
131 |
|
131 | |||
132 | /*! |
|
132 | /*! | |
133 | \fn void QBarSet::labelChanged() |
|
133 | \fn void QBarSet::labelChanged() | |
134 | This signal is emitted when the label of the barSet has changed. |
|
134 | This signal is emitted when the label of the barSet has changed. | |
135 | \sa label |
|
135 | \sa label | |
136 | */ |
|
136 | */ | |
137 | /*! |
|
137 | /*! | |
138 | \qmlsignal BarSet::onLabelChanged() |
|
138 | \qmlsignal BarSet::onLabelChanged() | |
139 | This signal is emitted when the label of the barSet has changed. |
|
139 | This signal is emitted when the label of the barSet has changed. | |
140 | */ |
|
140 | */ | |
141 |
|
141 | |||
142 | /*! |
|
142 | /*! | |
143 | \fn void QBarSet::penChanged() |
|
143 | \fn void QBarSet::penChanged() | |
144 | This signal is emitted when the pen of the barSet has changed. |
|
144 | This signal is emitted when the pen of the barSet has changed. | |
145 | \sa pen |
|
145 | \sa pen | |
146 | */ |
|
146 | */ | |
147 |
|
147 | |||
148 | /*! |
|
148 | /*! | |
149 | \fn void QBarSet::brushChanged() |
|
149 | \fn void QBarSet::brushChanged() | |
150 | This signal is emitted when the brush of the barSet has changed. |
|
150 | This signal is emitted when the brush of the barSet has changed. | |
151 | \sa brush |
|
151 | \sa brush | |
152 | */ |
|
152 | */ | |
153 |
|
153 | |||
154 | /*! |
|
154 | /*! | |
155 | \fn void QBarSet::labelBrushChanged() |
|
155 | \fn void QBarSet::labelBrushChanged() | |
156 | This signal is emitted when the brush of the barSet's label has changed. |
|
156 | This signal is emitted when the brush of the barSet's label has changed. | |
157 | \sa labelBrush |
|
157 | \sa labelBrush | |
158 | */ |
|
158 | */ | |
159 |
|
159 | |||
160 | /*! |
|
160 | /*! | |
161 | \fn void QBarSet::labelFontChanged() |
|
161 | \fn void QBarSet::labelFontChanged() | |
162 | This signal is emitted when the font of the barSet's label has changed. |
|
162 | This signal is emitted when the font of the barSet's label has changed. | |
163 | \sa labelBrush |
|
163 | \sa labelBrush | |
164 | */ |
|
164 | */ | |
165 |
|
165 | |||
166 | /*! |
|
166 | /*! | |
167 | \fn void QBarSet::colorChanged(QColor) |
|
167 | \fn void QBarSet::colorChanged(QColor) | |
168 | This signal is emitted when the fill (brush) color of the set has changed to \a color. |
|
168 | This signal is emitted when the fill (brush) color of the set has changed to \a color. | |
169 | */ |
|
169 | */ | |
170 | /*! |
|
170 | /*! | |
171 | \qmlsignal BarSet::onColorChanged(color color) |
|
171 | \qmlsignal BarSet::onColorChanged(color color) | |
172 | This signal is emitted when the fill (brush) color of the set has changed to \a color. |
|
172 | This signal is emitted when the fill (brush) color of the set has changed to \a color. | |
173 | */ |
|
173 | */ | |
174 |
|
174 | |||
175 | /*! |
|
175 | /*! | |
176 | \fn void QBarSet::borderColorChanged(QColor) |
|
176 | \fn void QBarSet::borderColorChanged(QColor) | |
177 | This signal is emitted when the line (pen) color of the set has changed to \a color. |
|
177 | This signal is emitted when the line (pen) color of the set has changed to \a color. | |
178 | */ |
|
178 | */ | |
179 | /*! |
|
179 | /*! | |
180 | \qmlsignal BarSet::onBorderColorChanged(color color) |
|
180 | \qmlsignal BarSet::onBorderColorChanged(color color) | |
181 | This signal is emitted when the line (pen) color of the set has changed to \a color. |
|
181 | This signal is emitted when the line (pen) color of the set has changed to \a color. | |
182 | */ |
|
182 | */ | |
183 |
|
183 | |||
184 | /*! |
|
184 | /*! | |
185 | \fn void QBarSet::labelColorChanged(QColor) |
|
185 | \fn void QBarSet::labelColorChanged(QColor) | |
186 | This signal is emitted when the text (label) color of the set has changed to \a color. |
|
186 | This signal is emitted when the text (label) color of the set has changed to \a color. | |
187 | */ |
|
187 | */ | |
188 | /*! |
|
188 | /*! | |
189 | \qmlsignal BarSet::onLabelColorChanged(color color) |
|
189 | \qmlsignal BarSet::onLabelColorChanged(color color) | |
190 | This signal is emitted when the text (label) color of the set has changed to \a color. |
|
190 | This signal is emitted when the text (label) color of the set has changed to \a color. | |
191 | */ |
|
191 | */ | |
192 |
|
192 | |||
193 | /*! |
|
193 | /*! | |
194 | \fn void QBarSet::valuesAdded(int index, int count) |
|
194 | \fn void QBarSet::valuesAdded(int index, int count) | |
195 | This signal is emitted when new values have been added to the set. |
|
195 | This signal is emitted when new values have been added to the set. | |
196 | Parameter \a index indicates the position of the first inserted value. |
|
196 | Parameter \a index indicates the position of the first inserted value. | |
197 | Parameter \a count is the number of iserted values. |
|
197 | Parameter \a count is the number of iserted values. | |
198 | \sa append(), insert() |
|
198 | \sa append(), insert() | |
199 | */ |
|
199 | */ | |
200 | /*! |
|
200 | /*! | |
201 | \qmlsignal BarSet::onValuesAdded(int index, int count) |
|
201 | \qmlsignal BarSet::onValuesAdded(int index, int count) | |
202 | This signal is emitted when new values have been added to the set. |
|
202 | This signal is emitted when new values have been added to the set. | |
203 | Parameter \a index indicates the position of the first inserted value. |
|
203 | Parameter \a index indicates the position of the first inserted value. | |
204 | Parameter \a count is the number of iserted values. |
|
204 | Parameter \a count is the number of iserted values. | |
205 | */ |
|
205 | */ | |
206 |
|
206 | |||
207 | /*! |
|
207 | /*! | |
208 | \fn void QBarSet::valuesRemoved(int index, int count) |
|
208 | \fn void QBarSet::valuesRemoved(int index, int count) | |
209 | This signal is emitted values have been removed from the set. |
|
209 | This signal is emitted values have been removed from the set. | |
210 | Parameter \a index indicates the position of the first removed value. |
|
210 | Parameter \a index indicates the position of the first removed value. | |
211 | Parameter \a count is the number of removed values. |
|
211 | Parameter \a count is the number of removed values. | |
212 | \sa remove() |
|
212 | \sa remove() | |
213 | */ |
|
213 | */ | |
214 | /*! |
|
214 | /*! | |
215 | \qmlsignal BarSet::onValuesRemoved(int index, int count) |
|
215 | \qmlsignal BarSet::onValuesRemoved(int index, int count) | |
216 | This signal is emitted values have been removed from the set. |
|
216 | This signal is emitted values have been removed from the set. | |
217 | Parameter \a index indicates the position of the first removed value. |
|
217 | Parameter \a index indicates the position of the first removed value. | |
218 | Parameter \a count is the number of removed values. |
|
218 | Parameter \a count is the number of removed values. | |
219 | */ |
|
219 | */ | |
220 |
|
220 | |||
221 | /*! |
|
221 | /*! | |
222 | \fn void QBarSet::valueChanged(int index) |
|
222 | \fn void QBarSet::valueChanged(int index) | |
223 | This signal is emitted values the value in the set has been modified. |
|
223 | This signal is emitted values the value in the set has been modified. | |
224 | Parameter \a index indicates the position of the modified value. |
|
224 | Parameter \a index indicates the position of the modified value. | |
225 | \sa at() |
|
225 | \sa at() | |
226 | */ |
|
226 | */ | |
227 | /*! |
|
227 | /*! | |
228 | \qmlsignal BarSet::onValueChanged(int index) |
|
228 | \qmlsignal BarSet::onValueChanged(int index) | |
229 | This signal is emitted values the value in the set has been modified. |
|
229 | This signal is emitted values the value in the set has been modified. | |
230 | Parameter \a index indicates the position of the modified value. |
|
230 | Parameter \a index indicates the position of the modified value. | |
231 | */ |
|
231 | */ | |
232 |
|
232 | |||
233 | /*! |
|
233 | /*! | |
234 | \qmlproperty int BarSet::count |
|
234 | \qmlproperty int BarSet::count | |
235 | The count of values on the barset |
|
235 | The count of values on the barset | |
236 | */ |
|
236 | */ | |
237 |
|
237 | |||
238 | /*! |
|
238 | /*! | |
239 | \qmlproperty QVariantList BarSet::values |
|
239 | \qmlproperty QVariantList BarSet::values | |
240 | The values of the barset. You can set either a list of reals or a list of points as values. If you set a list of |
|
240 | The values of the barset. You can set either a list of reals or a list of points as values. If you set a list of | |
241 | reals as values, the values are automatically completed to points by using the index of a value as it's |
|
241 | reals as values, the values are automatically completed to points by using the index of a value as it's | |
242 | x-coordinate. For example: |
|
242 | x-coordinate. For example: | |
243 | \code |
|
243 | \code | |
244 | myBarSet1.values = [0, 5, 1, 5]; |
|
244 | myBarSet1.values = [0, 5, 1, 5]; | |
245 | myBarSet2.values = [Qt.point(0, 1), Qt.point(1, 5), Qt.point(2.2, 4.3)]; |
|
245 | myBarSet2.values = [Qt.point(0, 1), Qt.point(1, 5), Qt.point(2.2, 4.3)]; | |
246 | \endcode |
|
246 | \endcode | |
247 | */ |
|
247 | */ | |
248 |
|
248 | |||
249 | /*! |
|
249 | /*! | |
250 | Constructs QBarSet with a label of \a label and with parent of \a parent |
|
250 | Constructs QBarSet with a label of \a label and with parent of \a parent | |
251 | */ |
|
251 | */ | |
252 | QBarSet::QBarSet(const QString label, QObject *parent) |
|
252 | QBarSet::QBarSet(const QString label, QObject *parent) | |
253 | : QObject(parent) |
|
253 | : QObject(parent) | |
254 | ,d_ptr(new QBarSetPrivate(label,this)) |
|
254 | ,d_ptr(new QBarSetPrivate(label,this)) | |
255 | { |
|
255 | { | |
256 | } |
|
256 | } | |
257 |
|
257 | |||
258 | /*! |
|
258 | /*! | |
259 | Destroys the barset |
|
259 | Destroys the barset | |
260 | */ |
|
260 | */ | |
261 | QBarSet::~QBarSet() |
|
261 | QBarSet::~QBarSet() | |
262 | { |
|
262 | { | |
263 | // NOTE: d_ptr destroyed by QObject |
|
263 | // NOTE: d_ptr destroyed by QObject | |
264 | } |
|
264 | } | |
265 |
|
265 | |||
266 | /*! |
|
266 | /*! | |
267 | Sets new \a label for set. |
|
267 | Sets new \a label for set. | |
268 | */ |
|
268 | */ | |
269 | void QBarSet::setLabel(const QString label) |
|
269 | void QBarSet::setLabel(const QString label) | |
270 | { |
|
270 | { | |
271 | d_ptr->m_label = label; |
|
271 | d_ptr->m_label = label; | |
272 | emit labelChanged(); |
|
272 | emit labelChanged(); | |
273 | } |
|
273 | } | |
274 |
|
274 | |||
275 | /*! |
|
275 | /*! | |
276 | Returns label of the set. |
|
276 | Returns label of the set. | |
277 | */ |
|
277 | */ | |
278 | QString QBarSet::label() const |
|
278 | QString QBarSet::label() const | |
279 | { |
|
279 | { | |
280 | return d_ptr->m_label; |
|
280 | return d_ptr->m_label; | |
281 | } |
|
281 | } | |
282 |
|
282 | |||
283 | /*! |
|
283 | /*! | |
284 | Appends new value \a value to the end of set. |
|
284 | Appends new value \a value to the end of set. | |
285 | */ |
|
285 | */ | |
286 | void QBarSet::append(const qreal value) |
|
286 | void QBarSet::append(const qreal value) | |
287 | { |
|
287 | { | |
288 | // Convert to QPointF |
|
288 | // Convert to QPointF | |
289 | int index = d_ptr->m_values.count(); |
|
289 | int index = d_ptr->m_values.count(); | |
290 | d_ptr->append(QPointF(d_ptr->m_values.count(), value)); |
|
290 | d_ptr->append(QPointF(d_ptr->m_values.count(), value)); | |
291 | emit valuesAdded(index, 1); |
|
291 | emit valuesAdded(index, 1); | |
292 | } |
|
292 | } | |
293 |
|
293 | |||
294 | /*! |
|
294 | /*! | |
295 | Appends a list of reals to set. Works like append with single real value. The \a values in list |
|
295 | Appends a list of reals to set. Works like append with single real value. The \a values in list | |
296 | are appended to end of barset |
|
296 | are appended to end of barset | |
297 | \sa append() |
|
297 | \sa append() | |
298 | */ |
|
298 | */ | |
299 | void QBarSet::append(const QList<qreal> &values) |
|
299 | void QBarSet::append(const QList<qreal> &values) | |
300 | { |
|
300 | { | |
301 | int index = d_ptr->m_values.count(); |
|
301 | int index = d_ptr->m_values.count(); | |
302 | d_ptr->append(values); |
|
302 | d_ptr->append(values); | |
303 | emit valuesAdded(index, values.count()); |
|
303 | emit valuesAdded(index, values.count()); | |
304 | } |
|
304 | } | |
305 |
|
305 | |||
306 | /*! |
|
306 | /*! | |
307 |
Conv |
|
307 | Convenience operator. Same as append, with real \a value. | |
308 | \sa append() |
|
308 | \sa append() | |
309 | */ |
|
309 | */ | |
310 | QBarSet& QBarSet::operator << (const qreal &value) |
|
310 | QBarSet& QBarSet::operator << (const qreal &value) | |
311 | { |
|
311 | { | |
312 | append(value); |
|
312 | append(value); | |
313 | return *this; |
|
313 | return *this; | |
314 | } |
|
314 | } | |
315 |
|
315 | |||
316 | /*! |
|
316 | /*! | |
317 | Inserts new \a value on the \a index position. |
|
317 | Inserts new \a value on the \a index position. | |
318 | The value that is currently at this postion is moved to postion index + 1 |
|
318 | The value that is currently at this postion is moved to postion index + 1 | |
319 | \sa remove() |
|
319 | \sa remove() | |
320 | */ |
|
320 | */ | |
321 | void QBarSet::insert(const int index, const qreal value) |
|
321 | void QBarSet::insert(const int index, const qreal value) | |
322 | { |
|
322 | { | |
323 | d_ptr->insert(index, value); |
|
323 | d_ptr->insert(index, value); | |
324 | emit valuesAdded(index,1); |
|
324 | emit valuesAdded(index,1); | |
325 | } |
|
325 | } | |
326 |
|
326 | |||
327 | /*! |
|
327 | /*! | |
328 | Removes \a count number of values from the set starting at \a index. |
|
328 | Removes \a count number of values from the set starting at \a index. | |
329 | \sa insert() |
|
329 | \sa insert() | |
330 | */ |
|
330 | */ | |
331 | void QBarSet::remove(const int index, const int count) |
|
331 | void QBarSet::remove(const int index, const int count) | |
332 | { |
|
332 | { | |
333 | int removedCount = d_ptr->remove(index,count); |
|
333 | int removedCount = d_ptr->remove(index,count); | |
334 | if (removedCount > 0) { |
|
334 | if (removedCount > 0) { | |
335 | emit valuesRemoved(index,removedCount); |
|
335 | emit valuesRemoved(index,removedCount); | |
336 | } |
|
336 | } | |
337 | return; |
|
337 | return; | |
338 | } |
|
338 | } | |
339 |
|
339 | |||
340 | /*! |
|
340 | /*! | |
341 | Sets a new value \a value to set, indexed by \a index |
|
341 | Sets a new value \a value to set, indexed by \a index | |
342 | */ |
|
342 | */ | |
343 | void QBarSet::replace(const int index, const qreal value) |
|
343 | void QBarSet::replace(const int index, const qreal value) | |
344 | { |
|
344 | { | |
345 | if (index >= 0 && index < d_ptr->m_values.count()) { |
|
345 | if (index >= 0 && index < d_ptr->m_values.count()) { | |
346 | d_ptr->replace(index,value); |
|
346 | d_ptr->replace(index,value); | |
347 | emit valueChanged(index); |
|
347 | emit valueChanged(index); | |
348 | } |
|
348 | } | |
349 | } |
|
349 | } | |
350 |
|
350 | |||
351 |
|
351 | |||
352 | /*! |
|
352 | /*! | |
353 | Returns value of set indexed by \a index. |
|
353 | Returns value of set indexed by \a index. | |
354 | If the index is out of bounds 0.0 is returned. |
|
354 | If the index is out of bounds 0.0 is returned. | |
355 | */ |
|
355 | */ | |
356 | qreal QBarSet::at(const int index) const |
|
356 | qreal QBarSet::at(const int index) const | |
357 | { |
|
357 | { | |
358 | if (index < 0 || index >= d_ptr->m_values.count()) { |
|
358 | if (index < 0 || index >= d_ptr->m_values.count()) { | |
359 | return 0; |
|
359 | return 0; | |
360 | } |
|
360 | } | |
361 |
|
361 | |||
362 | return d_ptr->m_values.at(index).y(); |
|
362 | return d_ptr->m_values.at(index).y(); | |
363 | } |
|
363 | } | |
364 |
|
364 | |||
365 | /*! |
|
365 | /*! | |
366 | Returns value of set indexed by \a index. |
|
366 | Returns value of set indexed by \a index. | |
367 | If the index is out of bounds 0.0 is returned. |
|
367 | If the index is out of bounds 0.0 is returned. | |
368 | */ |
|
368 | */ | |
369 | qreal QBarSet::operator [](const int index) const |
|
369 | qreal QBarSet::operator [](const int index) const | |
370 | { |
|
370 | { | |
371 | return at(index); |
|
371 | return at(index); | |
372 | } |
|
372 | } | |
373 |
|
373 | |||
374 | /*! |
|
374 | /*! | |
375 | Returns count of values in set. |
|
375 | Returns count of values in set. | |
376 | */ |
|
376 | */ | |
377 | int QBarSet::count() const |
|
377 | int QBarSet::count() const | |
378 | { |
|
378 | { | |
379 | return d_ptr->m_values.count(); |
|
379 | return d_ptr->m_values.count(); | |
380 | } |
|
380 | } | |
381 |
|
381 | |||
382 | /*! |
|
382 | /*! | |
383 | Returns sum of all values in barset. |
|
383 | Returns sum of all values in barset. | |
384 | */ |
|
384 | */ | |
385 | qreal QBarSet::sum() const |
|
385 | qreal QBarSet::sum() const | |
386 | { |
|
386 | { | |
387 | qreal total(0); |
|
387 | qreal total(0); | |
388 | for (int i=0; i < d_ptr->m_values.count(); i++) { |
|
388 | for (int i=0; i < d_ptr->m_values.count(); i++) { | |
389 | total += d_ptr->m_values.at(i).y(); |
|
389 | total += d_ptr->m_values.at(i).y(); | |
390 | } |
|
390 | } | |
391 | return total; |
|
391 | return total; | |
392 | } |
|
392 | } | |
393 |
|
393 | |||
394 | /*! |
|
394 | /*! | |
395 | Sets pen for set. Bars of this set are drawn using \a pen |
|
395 | Sets pen for set. Bars of this set are drawn using \a pen | |
396 | */ |
|
396 | */ | |
397 | void QBarSet::setPen(const QPen &pen) |
|
397 | void QBarSet::setPen(const QPen &pen) | |
398 | { |
|
398 | { | |
399 | if(d_ptr->m_pen!=pen){ |
|
399 | if(d_ptr->m_pen!=pen){ | |
400 | d_ptr->m_pen = pen; |
|
400 | d_ptr->m_pen = pen; | |
401 | emit d_ptr->updatedBars(); |
|
401 | emit d_ptr->updatedBars(); | |
402 | emit penChanged(); |
|
402 | emit penChanged(); | |
403 | } |
|
403 | } | |
404 | } |
|
404 | } | |
405 |
|
405 | |||
406 | /*! |
|
406 | /*! | |
407 | Returns pen of the set. |
|
407 | Returns pen of the set. | |
408 | */ |
|
408 | */ | |
409 | QPen QBarSet::pen() const |
|
409 | QPen QBarSet::pen() const | |
410 | { |
|
410 | { | |
411 | return d_ptr->m_pen; |
|
411 | return d_ptr->m_pen; | |
412 | } |
|
412 | } | |
413 |
|
413 | |||
414 | /*! |
|
414 | /*! | |
415 | Sets brush for the set. Bars of this set are drawn using \a brush |
|
415 | Sets brush for the set. Bars of this set are drawn using \a brush | |
416 | */ |
|
416 | */ | |
417 | void QBarSet::setBrush(const QBrush &brush) |
|
417 | void QBarSet::setBrush(const QBrush &brush) | |
418 | { |
|
418 | { | |
419 | if(d_ptr->m_brush!=brush){ |
|
419 | if(d_ptr->m_brush!=brush){ | |
420 | d_ptr->m_brush = brush; |
|
420 | d_ptr->m_brush = brush; | |
421 | emit d_ptr->updatedBars(); |
|
421 | emit d_ptr->updatedBars(); | |
422 | emit brushChanged(); |
|
422 | emit brushChanged(); | |
423 | } |
|
423 | } | |
424 | } |
|
424 | } | |
425 |
|
425 | |||
426 | /*! |
|
426 | /*! | |
427 | Returns brush of the set. |
|
427 | Returns brush of the set. | |
428 | */ |
|
428 | */ | |
429 | QBrush QBarSet::brush() const |
|
429 | QBrush QBarSet::brush() const | |
430 | { |
|
430 | { | |
431 | return d_ptr->m_brush; |
|
431 | return d_ptr->m_brush; | |
432 | } |
|
432 | } | |
433 |
|
433 | |||
434 | /*! |
|
434 | /*! | |
435 | Sets \a brush of the values that are drawn on top of this barset |
|
435 | Sets \a brush of the values that are drawn on top of this barset | |
436 | */ |
|
436 | */ | |
437 | void QBarSet::setLabelBrush(const QBrush &brush) |
|
437 | void QBarSet::setLabelBrush(const QBrush &brush) | |
438 | { |
|
438 | { | |
439 | if(d_ptr->m_labelBrush!=brush){ |
|
439 | if(d_ptr->m_labelBrush!=brush){ | |
440 | d_ptr->m_labelBrush = brush; |
|
440 | d_ptr->m_labelBrush = brush; | |
441 | emit d_ptr->updatedBars(); |
|
441 | emit d_ptr->updatedBars(); | |
442 | emit labelBrushChanged(); |
|
442 | emit labelBrushChanged(); | |
443 | } |
|
443 | } | |
444 | } |
|
444 | } | |
445 |
|
445 | |||
446 | /*! |
|
446 | /*! | |
447 | Returns brush of the values that are drawn on top of this barset |
|
447 | Returns brush of the values that are drawn on top of this barset | |
448 | */ |
|
448 | */ | |
449 | QBrush QBarSet::labelBrush() const |
|
449 | QBrush QBarSet::labelBrush() const | |
450 | { |
|
450 | { | |
451 | return d_ptr->m_labelBrush; |
|
451 | return d_ptr->m_labelBrush; | |
452 | } |
|
452 | } | |
453 |
|
453 | |||
454 | /*! |
|
454 | /*! | |
455 | Sets the \a font for values that are drawn on top of this barset |
|
455 | Sets the \a font for values that are drawn on top of this barset | |
456 | */ |
|
456 | */ | |
457 | void QBarSet::setLabelFont(const QFont &font) |
|
457 | void QBarSet::setLabelFont(const QFont &font) | |
458 | { |
|
458 | { | |
459 | if(d_ptr->m_labelFont!=font) { |
|
459 | if(d_ptr->m_labelFont!=font) { | |
460 | d_ptr->m_labelFont = font; |
|
460 | d_ptr->m_labelFont = font; | |
461 | emit d_ptr->updatedBars(); |
|
461 | emit d_ptr->updatedBars(); | |
462 | emit labelFontChanged(); |
|
462 | emit labelFontChanged(); | |
463 | } |
|
463 | } | |
464 |
|
464 | |||
465 | } |
|
465 | } | |
466 |
|
466 | |||
467 | /*! |
|
467 | /*! | |
468 | Returns the pen for values that are drawn on top of this barset |
|
468 | Returns the pen for values that are drawn on top of this barset | |
469 | */ |
|
469 | */ | |
470 | QFont QBarSet::labelFont() const |
|
470 | QFont QBarSet::labelFont() const | |
471 | { |
|
471 | { | |
472 | return d_ptr->m_labelFont; |
|
472 | return d_ptr->m_labelFont; | |
473 | } |
|
473 | } | |
474 |
|
474 | |||
475 | /*! |
|
475 | /*! | |
476 | Returns the color of the brush of barset. |
|
476 | Returns the color of the brush of barset. | |
477 | */ |
|
477 | */ | |
478 | QColor QBarSet::color() |
|
478 | QColor QBarSet::color() | |
479 | { |
|
479 | { | |
480 | return brush().color(); |
|
480 | return brush().color(); | |
481 | } |
|
481 | } | |
482 |
|
482 | |||
483 | /*! |
|
483 | /*! | |
484 | Sets the \a color of brush for this barset |
|
484 | Sets the \a color of brush for this barset | |
485 | */ |
|
485 | */ | |
486 | void QBarSet::setColor(QColor color) |
|
486 | void QBarSet::setColor(QColor color) | |
487 | { |
|
487 | { | |
488 | QBrush b = brush(); |
|
488 | QBrush b = brush(); | |
489 | if ((b.color() != color) || (b.style() == Qt::NoBrush)) { |
|
489 | if ((b.color() != color) || (b.style() == Qt::NoBrush)) { | |
490 | b.setColor(color); |
|
490 | b.setColor(color); | |
491 | if (b.style() == Qt::NoBrush) { |
|
491 | if (b.style() == Qt::NoBrush) { | |
492 | // Set tyle to Qt::SolidPattern. (Default is Qt::NoBrush) |
|
492 | // Set tyle to Qt::SolidPattern. (Default is Qt::NoBrush) | |
493 | // This prevents theme to override color defined in QML side: |
|
493 | // This prevents theme to override color defined in QML side: | |
494 | // BarSet { label: "Bob"; color:"red"; values: [1,2,3] } |
|
494 | // BarSet { label: "Bob"; color:"red"; values: [1,2,3] } | |
495 | // The color must be obeyed, since user wanted it. |
|
495 | // The color must be obeyed, since user wanted it. | |
496 | b.setStyle(Qt::SolidPattern); |
|
496 | b.setStyle(Qt::SolidPattern); | |
497 | } |
|
497 | } | |
498 | setBrush(b); |
|
498 | setBrush(b); | |
499 | emit colorChanged(color); |
|
499 | emit colorChanged(color); | |
500 | } |
|
500 | } | |
501 | } |
|
501 | } | |
502 |
|
502 | |||
503 | /*! |
|
503 | /*! | |
504 | Returns the color of pen of this barset |
|
504 | Returns the color of pen of this barset | |
505 | */ |
|
505 | */ | |
506 | QColor QBarSet::borderColor() |
|
506 | QColor QBarSet::borderColor() | |
507 | { |
|
507 | { | |
508 | return pen().color(); |
|
508 | return pen().color(); | |
509 | } |
|
509 | } | |
510 |
|
510 | |||
511 | /*! |
|
511 | /*! | |
512 | Sets the color of pen for this barset |
|
512 | Sets the color of pen for this barset | |
513 | */ |
|
513 | */ | |
514 | void QBarSet::setBorderColor(QColor color) |
|
514 | void QBarSet::setBorderColor(QColor color) | |
515 | { |
|
515 | { | |
516 | QPen p = pen(); |
|
516 | QPen p = pen(); | |
517 | if (p.color() != color) { |
|
517 | if (p.color() != color) { | |
518 | p.setColor(color); |
|
518 | p.setColor(color); | |
519 | setPen(p); |
|
519 | setPen(p); | |
520 | emit borderColorChanged(color); |
|
520 | emit borderColorChanged(color); | |
521 | } |
|
521 | } | |
522 | } |
|
522 | } | |
523 |
|
523 | |||
524 | /*! |
|
524 | /*! | |
525 | Returns the color of labels of this barset |
|
525 | Returns the color of labels of this barset | |
526 | */ |
|
526 | */ | |
527 | QColor QBarSet::labelColor() |
|
527 | QColor QBarSet::labelColor() | |
528 | { |
|
528 | { | |
529 | return labelBrush().color(); |
|
529 | return labelBrush().color(); | |
530 | } |
|
530 | } | |
531 |
|
531 | |||
532 | /*! |
|
532 | /*! | |
533 | Sets the color of labels for this barset |
|
533 | Sets the color of labels for this barset | |
534 | */ |
|
534 | */ | |
535 | void QBarSet::setLabelColor(QColor color) |
|
535 | void QBarSet::setLabelColor(QColor color) | |
536 | { |
|
536 | { | |
537 | QBrush b = labelBrush(); |
|
537 | QBrush b = labelBrush(); | |
538 | if (b == QBrush()) |
|
538 | if (b == QBrush()) | |
539 | b.setStyle(Qt::SolidPattern); |
|
539 | b.setStyle(Qt::SolidPattern); | |
540 |
|
540 | |||
541 | if (b.color() != color) { |
|
541 | if (b.color() != color) { | |
542 | b.setColor(color); |
|
542 | b.setColor(color); | |
543 | setLabelBrush(b); |
|
543 | setLabelBrush(b); | |
544 | emit labelColorChanged(color); |
|
544 | emit labelColorChanged(color); | |
545 | } |
|
545 | } | |
546 | } |
|
546 | } | |
547 |
|
547 | |||
548 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
548 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
549 |
|
549 | |||
550 | QBarSetPrivate::QBarSetPrivate(const QString label, QBarSet *parent) : QObject(parent), |
|
550 | QBarSetPrivate::QBarSetPrivate(const QString label, QBarSet *parent) : QObject(parent), | |
551 | q_ptr(parent), |
|
551 | q_ptr(parent), | |
552 | m_label(label) |
|
552 | m_label(label) | |
553 | { |
|
553 | { | |
554 | } |
|
554 | } | |
555 |
|
555 | |||
556 | QBarSetPrivate::~QBarSetPrivate() |
|
556 | QBarSetPrivate::~QBarSetPrivate() | |
557 | { |
|
557 | { | |
558 | } |
|
558 | } | |
559 |
|
559 | |||
560 | void QBarSetPrivate::append(QPointF value) |
|
560 | void QBarSetPrivate::append(QPointF value) | |
561 | { |
|
561 | { | |
562 | m_values.append(value); |
|
562 | m_values.append(value); | |
563 | emit restructuredBars(); |
|
563 | emit restructuredBars(); | |
564 | } |
|
564 | } | |
565 |
|
565 | |||
566 | void QBarSetPrivate::append(QList<QPointF> values) |
|
566 | void QBarSetPrivate::append(QList<QPointF> values) | |
567 | { |
|
567 | { | |
568 | for (int i=0; i<values.count(); i++) { |
|
568 | for (int i=0; i<values.count(); i++) { | |
569 | m_values.append(values.at(i)); |
|
569 | m_values.append(values.at(i)); | |
570 | } |
|
570 | } | |
571 | emit restructuredBars(); |
|
571 | emit restructuredBars(); | |
572 | } |
|
572 | } | |
573 |
|
573 | |||
574 | void QBarSetPrivate::append(QList<qreal> values) |
|
574 | void QBarSetPrivate::append(QList<qreal> values) | |
575 | { |
|
575 | { | |
576 | int index = m_values.count(); |
|
576 | int index = m_values.count(); | |
577 | for (int i=0; i<values.count(); i++) { |
|
577 | for (int i=0; i<values.count(); i++) { | |
578 | m_values.append(QPointF(index,values.at(i))); |
|
578 | m_values.append(QPointF(index,values.at(i))); | |
579 | index++; |
|
579 | index++; | |
580 | } |
|
580 | } | |
581 | emit restructuredBars(); |
|
581 | emit restructuredBars(); | |
582 | } |
|
582 | } | |
583 |
|
583 | |||
584 | void QBarSetPrivate::insert(const int index, const qreal value) |
|
584 | void QBarSetPrivate::insert(const int index, const qreal value) | |
585 | { |
|
585 | { | |
586 | m_values.insert(index, QPointF(index, value)); |
|
586 | m_values.insert(index, QPointF(index, value)); | |
587 | emit restructuredBars(); |
|
587 | emit restructuredBars(); | |
588 | } |
|
588 | } | |
589 |
|
589 | |||
590 | void QBarSetPrivate::insert(const int index, const QPointF value) |
|
590 | void QBarSetPrivate::insert(const int index, const QPointF value) | |
591 | { |
|
591 | { | |
592 | m_values.insert(index, value); |
|
592 | m_values.insert(index, value); | |
593 | emit restructuredBars(); |
|
593 | emit restructuredBars(); | |
594 | } |
|
594 | } | |
595 |
|
595 | |||
596 | int QBarSetPrivate::remove(const int index, const int count) |
|
596 | int QBarSetPrivate::remove(const int index, const int count) | |
597 | { |
|
597 | { | |
598 | int removeCount = count; |
|
598 | int removeCount = count; | |
599 |
|
599 | |||
600 | if ((index <0) || (m_values.count() == 0)) { |
|
600 | if ((index <0) || (m_values.count() == 0)) { | |
601 | // Invalid index or not values in list, remove nothing. |
|
601 | // Invalid index or not values in list, remove nothing. | |
602 | return 0; |
|
602 | return 0; | |
603 | } else if ((index + count) > m_values.count()) { |
|
603 | } else if ((index + count) > m_values.count()) { | |
604 | // Trying to remove more items than list has. Limit amount to be removed. |
|
604 | // Trying to remove more items than list has. Limit amount to be removed. | |
605 | removeCount = m_values.count() - index; |
|
605 | removeCount = m_values.count() - index; | |
606 | } |
|
606 | } | |
607 |
|
607 | |||
608 | int c = 0; |
|
608 | int c = 0; | |
609 | while (c < removeCount) { |
|
609 | while (c < removeCount) { | |
610 | m_values.removeAt(index); |
|
610 | m_values.removeAt(index); | |
611 | c++; |
|
611 | c++; | |
612 | } |
|
612 | } | |
613 | emit restructuredBars(); |
|
613 | emit restructuredBars(); | |
614 | return removeCount; |
|
614 | return removeCount; | |
615 | } |
|
615 | } | |
616 |
|
616 | |||
617 | void QBarSetPrivate::replace(const int index, const qreal value) |
|
617 | void QBarSetPrivate::replace(const int index, const qreal value) | |
618 | { |
|
618 | { | |
619 | m_values.replace(index,QPointF(index,value)); |
|
619 | m_values.replace(index,QPointF(index,value)); | |
620 | emit updatedLayout(); |
|
620 | emit updatedLayout(); | |
621 | } |
|
621 | } | |
622 |
|
622 | |||
623 | void QBarSetPrivate::replace(const int index, const QPointF value) |
|
623 | void QBarSetPrivate::replace(const int index, const QPointF value) | |
624 | { |
|
624 | { | |
625 | m_values.replace(index,value); |
|
625 | m_values.replace(index,value); | |
626 | emit updatedLayout(); |
|
626 | emit updatedLayout(); | |
627 | } |
|
627 | } | |
628 |
|
628 | |||
629 | qreal QBarSetPrivate::pos(const int index) |
|
629 | qreal QBarSetPrivate::pos(const int index) | |
630 | { |
|
630 | { | |
631 | if (index < 0 || index >= m_values.count()) { |
|
631 | if (index < 0 || index >= m_values.count()) { | |
632 | return 0; |
|
632 | return 0; | |
633 | } |
|
633 | } | |
634 |
|
634 | |||
635 | return m_values.at(index).x(); |
|
635 | return m_values.at(index).x(); | |
636 | } |
|
636 | } | |
637 |
|
637 | |||
638 | qreal QBarSetPrivate::value(const int index) |
|
638 | qreal QBarSetPrivate::value(const int index) | |
639 | { |
|
639 | { | |
640 | if (index < 0 || index >= m_values.count()) { |
|
640 | if (index < 0 || index >= m_values.count()) { | |
641 | return 0; |
|
641 | return 0; | |
642 | } |
|
642 | } | |
643 |
|
643 | |||
644 | return m_values.at(index).y(); |
|
644 | return m_values.at(index).y(); | |
645 | } |
|
645 | } | |
646 |
|
646 | |||
647 | #include "moc_qbarset.cpp" |
|
647 | #include "moc_qbarset.cpp" | |
648 | #include "moc_qbarset_p.cpp" |
|
648 | #include "moc_qbarset_p.cpp" | |
649 |
|
649 | |||
650 | QTCOMMERCIALCHART_END_NAMESPACE |
|
650 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,875 +1,875 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qpieseries.h" |
|
21 | #include "qpieseries.h" | |
22 | #include "qpieseries_p.h" |
|
22 | #include "qpieseries_p.h" | |
23 | #include "qpieslice.h" |
|
23 | #include "qpieslice.h" | |
24 | #include "qpieslice_p.h" |
|
24 | #include "qpieslice_p.h" | |
25 | #include "pieslicedata_p.h" |
|
25 | #include "pieslicedata_p.h" | |
26 | #include "chartdataset_p.h" |
|
26 | #include "chartdataset_p.h" | |
27 | #include "charttheme_p.h" |
|
27 | #include "charttheme_p.h" | |
28 | #include "legendmarker_p.h" |
|
28 | #include "legendmarker_p.h" | |
29 | #include "qabstractaxis.h" |
|
29 | #include "qabstractaxis.h" | |
30 | #include "pieanimation_p.h" |
|
30 | #include "pieanimation_p.h" | |
31 |
|
31 | |||
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
33 |
|
33 | |||
34 | /*! |
|
34 | /*! | |
35 | \class QPieSeries |
|
35 | \class QPieSeries | |
36 | \brief Pie series API for QtCommercial Charts |
|
36 | \brief Pie series API for QtCommercial Charts | |
37 |
|
37 | |||
38 | The pie series defines a pie chart which consists of pie slices which are defined as QPieSlice objects. |
|
38 | The pie series defines a pie chart which consists of pie slices which are defined as QPieSlice objects. | |
39 | The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices. |
|
39 | The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices. | |
40 | The actual slice size is determined by that relative value. |
|
40 | The actual slice size is determined by that relative value. | |
41 |
|
41 | |||
42 | Pie size and position on the chart is controlled by using relative values which range from 0.0 to 1.0 |
|
42 | Pie size and position on the chart is controlled by using relative values which range from 0.0 to 1.0 | |
43 | These relate to the actual chart rectangle. |
|
43 | These relate to the actual chart rectangle. | |
44 |
|
44 | |||
45 | By default the pie is defined as a full pie but it can also be a partial pie. |
|
45 | By default the pie is defined as a full pie but it can also be a partial pie. | |
46 | This can be done by setting a starting angle and angle span to the series. |
|
46 | This can be done by setting a starting angle and angle span to the series. | |
47 | Full pie is 360 degrees where 0 is at 12 a'clock. |
|
47 | Full pie is 360 degrees where 0 is at 12 a'clock. | |
48 |
|
48 | |||
49 | See the \l {PieChart Example} {pie chart example} or \l {DonutChart Example} {donut chart example} to learn how to use QPieSeries. |
|
49 | See the \l {PieChart Example} {pie chart example} or \l {DonutChart Example} {donut chart example} to learn how to use QPieSeries. | |
50 | \table 100% |
|
50 | \table 100% | |
51 | \row |
|
51 | \row | |
52 | \o \image examples_piechart.png |
|
52 | \o \image examples_piechart.png | |
53 | \o \image examples_donut.png |
|
53 | \o \image examples_donut.png | |
54 | \endtable |
|
54 | \endtable | |
55 | */ |
|
55 | */ | |
56 | /*! |
|
56 | /*! | |
57 | \qmlclass PieSeries QPieSeries |
|
57 | \qmlclass PieSeries QPieSeries | |
58 | \inherits AbstractSeries |
|
58 | \inherits AbstractSeries | |
59 |
|
59 | |||
60 | The following QML shows how to create a simple pie chart. |
|
60 | The following QML shows how to create a simple pie chart. | |
61 |
|
61 | |||
62 | \snippet ../demos/qmlchart/qml/qmlchart/View1.qml 1 |
|
62 | \snippet ../demos/qmlchart/qml/qmlchart/View1.qml 1 | |
63 |
|
63 | |||
64 | \beginfloatleft |
|
64 | \beginfloatleft | |
65 | \image demos_qmlchart1.png |
|
65 | \image demos_qmlchart1.png | |
66 | \endfloat |
|
66 | \endfloat | |
67 | \clearfloat |
|
67 | \clearfloat | |
68 | */ |
|
68 | */ | |
69 |
|
69 | |||
70 | /*! |
|
70 | /*! | |
71 | \property QPieSeries::horizontalPosition |
|
71 | \property QPieSeries::horizontalPosition | |
72 | \brief Defines the horizontal position of the pie. |
|
72 | \brief Defines the horizontal position of the pie. | |
73 |
|
73 | |||
74 | The value is a relative value to the chart rectangle where: |
|
74 | The value is a relative value to the chart rectangle where: | |
75 |
|
75 | |||
76 | \list |
|
76 | \list | |
77 | \o 0.0 is the absolute left. |
|
77 | \o 0.0 is the absolute left. | |
78 | \o 1.0 is the absolute right. |
|
78 | \o 1.0 is the absolute right. | |
79 | \endlist |
|
79 | \endlist | |
80 | Default value is 0.5 (center). |
|
80 | Default value is 0.5 (center). | |
81 | \sa verticalPosition |
|
81 | \sa verticalPosition | |
82 | */ |
|
82 | */ | |
83 |
|
83 | |||
84 | /*! |
|
84 | /*! | |
85 | \qmlproperty real PieSeries::horizontalPosition |
|
85 | \qmlproperty real PieSeries::horizontalPosition | |
86 |
|
86 | |||
87 | Defines the horizontal position of the pie. |
|
87 | Defines the horizontal position of the pie. | |
88 |
|
88 | |||
89 | The value is a relative value to the chart rectangle where: |
|
89 | The value is a relative value to the chart rectangle where: | |
90 |
|
90 | |||
91 | \list |
|
91 | \list | |
92 | \o 0.0 is the absolute left. |
|
92 | \o 0.0 is the absolute left. | |
93 | \o 1.0 is the absolute right. |
|
93 | \o 1.0 is the absolute right. | |
94 | \endlist |
|
94 | \endlist | |
95 | Default value is 0.5 (center). |
|
95 | Default value is 0.5 (center). | |
96 | \sa verticalPosition |
|
96 | \sa verticalPosition | |
97 | */ |
|
97 | */ | |
98 |
|
98 | |||
99 | /*! |
|
99 | /*! | |
100 | \property QPieSeries::verticalPosition |
|
100 | \property QPieSeries::verticalPosition | |
101 | \brief Defines the vertical position of the pie. |
|
101 | \brief Defines the vertical position of the pie. | |
102 |
|
102 | |||
103 | The value is a relative value to the chart rectangle where: |
|
103 | The value is a relative value to the chart rectangle where: | |
104 |
|
104 | |||
105 | \list |
|
105 | \list | |
106 | \o 0.0 is the absolute top. |
|
106 | \o 0.0 is the absolute top. | |
107 | \o 1.0 is the absolute bottom. |
|
107 | \o 1.0 is the absolute bottom. | |
108 | \endlist |
|
108 | \endlist | |
109 | Default value is 0.5 (center). |
|
109 | Default value is 0.5 (center). | |
110 | \sa horizontalPosition |
|
110 | \sa horizontalPosition | |
111 | */ |
|
111 | */ | |
112 |
|
112 | |||
113 | /*! |
|
113 | /*! | |
114 | \qmlproperty real PieSeries::verticalPosition |
|
114 | \qmlproperty real PieSeries::verticalPosition | |
115 |
|
115 | |||
116 | Defines the vertical position of the pie. |
|
116 | Defines the vertical position of the pie. | |
117 |
|
117 | |||
118 | The value is a relative value to the chart rectangle where: |
|
118 | The value is a relative value to the chart rectangle where: | |
119 |
|
119 | |||
120 | \list |
|
120 | \list | |
121 | \o 0.0 is the absolute top. |
|
121 | \o 0.0 is the absolute top. | |
122 | \o 1.0 is the absolute bottom. |
|
122 | \o 1.0 is the absolute bottom. | |
123 | \endlist |
|
123 | \endlist | |
124 | Default value is 0.5 (center). |
|
124 | Default value is 0.5 (center). | |
125 | \sa horizontalPosition |
|
125 | \sa horizontalPosition | |
126 | */ |
|
126 | */ | |
127 |
|
127 | |||
128 | /*! |
|
128 | /*! | |
129 | \property QPieSeries::size |
|
129 | \property QPieSeries::size | |
130 | \brief Defines the pie size. |
|
130 | \brief Defines the pie size. | |
131 |
|
131 | |||
132 | The value is a relative value to the chart rectangle where: |
|
132 | The value is a relative value to the chart rectangle where: | |
133 |
|
133 | |||
134 | \list |
|
134 | \list | |
135 | \o 0.0 is the minimum size (pie not drawn). |
|
135 | \o 0.0 is the minimum size (pie not drawn). | |
136 | \o 1.0 is the maximum size that can fit the chart. |
|
136 | \o 1.0 is the maximum size that can fit the chart. | |
137 | \endlist |
|
137 | \endlist | |
138 |
|
138 | |||
139 | When setting this property the holeSize property is adjusted if necessary, to ensure that the hole size is not greater than the outer size. |
|
139 | When setting this property the holeSize property is adjusted if necessary, to ensure that the hole size is not greater than the outer size. | |
140 |
|
140 | |||
141 | Default value is 0.7. |
|
141 | Default value is 0.7. | |
142 | */ |
|
142 | */ | |
143 |
|
143 | |||
144 | /*! |
|
144 | /*! | |
145 | \qmlproperty real PieSeries::size |
|
145 | \qmlproperty real PieSeries::size | |
146 |
|
146 | |||
147 | Defines the pie size. |
|
147 | Defines the pie size. | |
148 |
|
148 | |||
149 | The value is a relative value to the chart rectangle where: |
|
149 | The value is a relative value to the chart rectangle where: | |
150 |
|
150 | |||
151 | \list |
|
151 | \list | |
152 | \o 0.0 is the minimum size (pie not drawn). |
|
152 | \o 0.0 is the minimum size (pie not drawn). | |
153 | \o 1.0 is the maximum size that can fit the chart. |
|
153 | \o 1.0 is the maximum size that can fit the chart. | |
154 | \endlist |
|
154 | \endlist | |
155 |
|
155 | |||
156 | Default value is 0.7. |
|
156 | Default value is 0.7. | |
157 | */ |
|
157 | */ | |
158 |
|
158 | |||
159 | /*! |
|
159 | /*! | |
160 | \property QPieSeries::holeSize |
|
160 | \property QPieSeries::holeSize | |
161 | \brief Defines the donut hole size. |
|
161 | \brief Defines the donut hole size. | |
162 |
|
162 | |||
163 | The value is a relative value to the chart rectangle where: |
|
163 | The value is a relative value to the chart rectangle where: | |
164 |
|
164 | |||
165 | \list |
|
165 | \list | |
166 | \o 0.0 is the minimum size (full pie drawn, without any hole inside). |
|
166 | \o 0.0 is the minimum size (full pie drawn, without any hole inside). | |
167 | \o 1.0 is the maximum size that can fit the chart. (donut has no width) |
|
167 | \o 1.0 is the maximum size that can fit the chart. (donut has no width) | |
168 | \endlist |
|
168 | \endlist | |
169 |
|
169 | |||
170 | The value is never greater then size property. |
|
170 | The value is never greater then size property. | |
171 | Default value is 0.0. |
|
171 | Default value is 0.0. | |
172 | */ |
|
172 | */ | |
173 |
|
173 | |||
174 | /*! |
|
174 | /*! | |
175 | \qmlproperty real PieSeries::holeSize |
|
175 | \qmlproperty real PieSeries::holeSize | |
176 |
|
176 | |||
177 | Defines the donut hole size. |
|
177 | Defines the donut hole size. | |
178 |
|
178 | |||
179 | The value is a relative value to the chart rectangle where: |
|
179 | The value is a relative value to the chart rectangle where: | |
180 |
|
180 | |||
181 | \list |
|
181 | \list | |
182 | \o 0.0 is the minimum size (full pie drawn, without any hole inside). |
|
182 | \o 0.0 is the minimum size (full pie drawn, without any hole inside). | |
183 | \o 1.0 is the maximum size that can fit the chart. (donut has no width) |
|
183 | \o 1.0 is the maximum size that can fit the chart. (donut has no width) | |
184 | \endlist |
|
184 | \endlist | |
185 |
|
185 | |||
186 | When setting this property the size property is adjusted if necessary, to ensure that the inner size is not greater than the outer size. |
|
186 | When setting this property the size property is adjusted if necessary, to ensure that the inner size is not greater than the outer size. | |
187 |
|
187 | |||
188 | Default value is 0.0. |
|
188 | Default value is 0.0. | |
189 | */ |
|
189 | */ | |
190 |
|
190 | |||
191 | /*! |
|
191 | /*! | |
192 | \property QPieSeries::startAngle |
|
192 | \property QPieSeries::startAngle | |
193 | \brief Defines the starting angle of the pie. |
|
193 | \brief Defines the starting angle of the pie. | |
194 |
|
194 | |||
195 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
195 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
196 |
|
196 | |||
197 | Default is value is 0. |
|
197 | Default is value is 0. | |
198 | */ |
|
198 | */ | |
199 |
|
199 | |||
200 | /*! |
|
200 | /*! | |
201 | \qmlproperty real PieSeries::startAngle |
|
201 | \qmlproperty real PieSeries::startAngle | |
202 |
|
202 | |||
203 | Defines the starting angle of the pie. |
|
203 | Defines the starting angle of the pie. | |
204 |
|
204 | |||
205 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
205 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
206 |
|
206 | |||
207 | Default is value is 0. |
|
207 | Default is value is 0. | |
208 | */ |
|
208 | */ | |
209 |
|
209 | |||
210 | /*! |
|
210 | /*! | |
211 | \property QPieSeries::endAngle |
|
211 | \property QPieSeries::endAngle | |
212 | \brief Defines the ending angle of the pie. |
|
212 | \brief Defines the ending angle of the pie. | |
213 |
|
213 | |||
214 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
214 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
215 |
|
215 | |||
216 | Default is value is 360. |
|
216 | Default is value is 360. | |
217 | */ |
|
217 | */ | |
218 |
|
218 | |||
219 | /*! |
|
219 | /*! | |
220 | \qmlproperty real PieSeries::endAngle |
|
220 | \qmlproperty real PieSeries::endAngle | |
221 |
|
221 | |||
222 | Defines the ending angle of the pie. |
|
222 | Defines the ending angle of the pie. | |
223 |
|
223 | |||
224 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
224 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
225 |
|
225 | |||
226 | Default is value is 360. |
|
226 | Default is value is 360. | |
227 | */ |
|
227 | */ | |
228 |
|
228 | |||
229 | /*! |
|
229 | /*! | |
230 | \property QPieSeries::count |
|
230 | \property QPieSeries::count | |
231 |
|
231 | |||
232 | Number of slices in the series. |
|
232 | Number of slices in the series. | |
233 | */ |
|
233 | */ | |
234 |
|
234 | |||
235 | /*! |
|
235 | /*! | |
236 | \qmlproperty int PieSeries::count |
|
236 | \qmlproperty int PieSeries::count | |
237 |
|
237 | |||
238 | Number of slices in the series. |
|
238 | Number of slices in the series. | |
239 | */ |
|
239 | */ | |
240 |
|
240 | |||
241 | /*! |
|
241 | /*! | |
242 | \fn void QPieSeries::countChanged() |
|
242 | \fn void QPieSeries::countChanged() | |
243 | Emitted when the slice count has changed. |
|
243 | Emitted when the slice count has changed. | |
244 | \sa count |
|
244 | \sa count | |
245 | */ |
|
245 | */ | |
246 | /*! |
|
246 | /*! | |
247 | \qmlsignal PieSeries::onCountChanged() |
|
247 | \qmlsignal PieSeries::onCountChanged() | |
248 | Emitted when the slice count has changed. |
|
248 | Emitted when the slice count has changed. | |
249 | */ |
|
249 | */ | |
250 |
|
250 | |||
251 | /*! |
|
251 | /*! | |
252 | \property QPieSeries::sum |
|
252 | \property QPieSeries::sum | |
253 |
|
253 | |||
254 | Sum of all slices. |
|
254 | Sum of all slices. | |
255 |
|
255 | |||
256 | The series keeps track of the sum of all slices it holds. |
|
256 | The series keeps track of the sum of all slices it holds. | |
257 | */ |
|
257 | */ | |
258 |
|
258 | |||
259 | /*! |
|
259 | /*! | |
260 | \qmlproperty real PieSeries::sum |
|
260 | \qmlproperty real PieSeries::sum | |
261 |
|
261 | |||
262 | Sum of all slices. |
|
262 | Sum of all slices. | |
263 |
|
263 | |||
264 | The series keeps track of the sum of all slices it holds. |
|
264 | The series keeps track of the sum of all slices it holds. | |
265 | */ |
|
265 | */ | |
266 |
|
266 | |||
267 | /*! |
|
267 | /*! | |
268 | \fn void QPieSeries::sumChanged() |
|
268 | \fn void QPieSeries::sumChanged() | |
269 | Emitted when the sum of all slices has changed. |
|
269 | Emitted when the sum of all slices has changed. | |
270 | \sa sum |
|
270 | \sa sum | |
271 | */ |
|
271 | */ | |
272 | /*! |
|
272 | /*! | |
273 | \qmlsignal PieSeries::onSumChanged() |
|
273 | \qmlsignal PieSeries::onSumChanged() | |
274 | Emitted when the sum of all slices has changed. This may happen for example if you add or remove slices, or if you |
|
274 | Emitted when the sum of all slices has changed. This may happen for example if you add or remove slices, or if you | |
275 | change value of a slice. |
|
275 | change value of a slice. | |
276 | */ |
|
276 | */ | |
277 |
|
277 | |||
278 | /*! |
|
278 | /*! | |
279 | \fn void QPieSeries::added(QList<QPieSlice*> slices) |
|
279 | \fn void QPieSeries::added(QList<QPieSlice*> slices) | |
280 |
|
280 | |||
281 | This signal is emitted when \a slices have been added to the series. |
|
281 | This signal is emitted when \a slices have been added to the series. | |
282 |
|
282 | |||
283 | \sa append(), insert() |
|
283 | \sa append(), insert() | |
284 | */ |
|
284 | */ | |
285 | /*! |
|
285 | /*! | |
286 | \qmlsignal PieSeries::onAdded(PieSlice slice) |
|
286 | \qmlsignal PieSeries::onAdded(PieSlice slice) | |
287 | Emitted when \a slice has been added to the series. |
|
287 | Emitted when \a slice has been added to the series. | |
288 | */ |
|
288 | */ | |
289 |
|
289 | |||
290 | /*! |
|
290 | /*! | |
291 | \fn void QPieSeries::removed(QList<QPieSlice*> slices) |
|
291 | \fn void QPieSeries::removed(QList<QPieSlice*> slices) | |
292 | This signal is emitted when \a slices have been removed from the series. |
|
292 | This signal is emitted when \a slices have been removed from the series. | |
293 | \sa remove() |
|
293 | \sa remove() | |
294 | */ |
|
294 | */ | |
295 | /*! |
|
295 | /*! | |
296 | \qmlsignal PieSeries::onRemoved(PieSlice slice) |
|
296 | \qmlsignal PieSeries::onRemoved(PieSlice slice) | |
297 | Emitted when \a slice has been removed from the series. |
|
297 | Emitted when \a slice has been removed from the series. | |
298 | */ |
|
298 | */ | |
299 |
|
299 | |||
300 | /*! |
|
300 | /*! | |
301 | \fn void QPieSeries::clicked(QPieSlice* slice) |
|
301 | \fn void QPieSeries::clicked(QPieSlice* slice) | |
302 | This signal is emitted when a \a slice has been clicked. |
|
302 | This signal is emitted when a \a slice has been clicked. | |
303 | \sa QPieSlice::clicked() |
|
303 | \sa QPieSlice::clicked() | |
304 | */ |
|
304 | */ | |
305 | /*! |
|
305 | /*! | |
306 | \qmlsignal PieSeries::onClicked(PieSlice slice) |
|
306 | \qmlsignal PieSeries::onClicked(PieSlice slice) | |
307 | This signal is emitted when a \a slice has been clicked. |
|
307 | This signal is emitted when a \a slice has been clicked. | |
308 | */ |
|
308 | */ | |
309 |
|
309 | |||
310 | /*! |
|
310 | /*! | |
311 | \fn void QPieSeries::hovered(QPieSlice* slice, bool state) |
|
311 | \fn void QPieSeries::hovered(QPieSlice* slice, bool state) | |
312 | This signal is emitted when user has hovered over or away from the \a slice. |
|
312 | This signal is emitted when user has hovered over or away from the \a slice. | |
313 | \a state is true when user has hovered over the slice and false when hover has moved away from the slice. |
|
313 | \a state is true when user has hovered over the slice and false when hover has moved away from the slice. | |
314 | \sa QPieSlice::hovered() |
|
314 | \sa QPieSlice::hovered() | |
315 | */ |
|
315 | */ | |
316 | /*! |
|
316 | /*! | |
317 | \qmlsignal PieSeries::onHovered(PieSlice slice, bool state) |
|
317 | \qmlsignal PieSeries::onHovered(PieSlice slice, bool state) | |
318 | This signal is emitted when user has hovered over or away from the \a slice. \a state is true when user has hovered |
|
318 | This signal is emitted when user has hovered over or away from the \a slice. \a state is true when user has hovered | |
319 | over the slice and false when hover has moved away from the slice. |
|
319 | over the slice and false when hover has moved away from the slice. | |
320 | */ |
|
320 | */ | |
321 |
|
321 | |||
322 | /*! |
|
322 | /*! | |
323 | \qmlmethod PieSlice PieSeries::at(int index) |
|
323 | \qmlmethod PieSlice PieSeries::at(int index) | |
324 | Returns slice at \a index. Returns null if the index is not valid. |
|
324 | Returns slice at \a index. Returns null if the index is not valid. | |
325 | */ |
|
325 | */ | |
326 |
|
326 | |||
327 | /*! |
|
327 | /*! | |
328 | \qmlmethod PieSlice PieSeries::find(string label) |
|
328 | \qmlmethod PieSlice PieSeries::find(string label) | |
329 | Returns the first slice with \a label. Returns null if the index is not valid. |
|
329 | Returns the first slice with \a label. Returns null if the index is not valid. | |
330 | */ |
|
330 | */ | |
331 |
|
331 | |||
332 | /*! |
|
332 | /*! | |
333 | \qmlmethod PieSlice PieSeries::append(string label, real value) |
|
333 | \qmlmethod PieSlice PieSeries::append(string label, real value) | |
334 | Adds a new slice with \a label and \a value to the pie. |
|
334 | Adds a new slice with \a label and \a value to the pie. | |
335 | */ |
|
335 | */ | |
336 |
|
336 | |||
337 | /*! |
|
337 | /*! | |
338 | \qmlmethod bool PieSeries::remove(PieSlice slice) |
|
338 | \qmlmethod bool PieSeries::remove(PieSlice slice) | |
339 |
Removes the \a slice from the pie. Returns true if the removal was successful |
|
339 | Removes the \a slice from the pie. Returns true if the removal was successful, false otherwise. | |
340 | */ |
|
340 | */ | |
341 |
|
341 | |||
342 | /*! |
|
342 | /*! | |
343 | \qmlmethod PieSeries::clear() |
|
343 | \qmlmethod PieSeries::clear() | |
344 | Removes all slices from the pie. |
|
344 | Removes all slices from the pie. | |
345 | */ |
|
345 | */ | |
346 |
|
346 | |||
347 | /*! |
|
347 | /*! | |
348 | Constructs a series object which is a child of \a parent. |
|
348 | Constructs a series object which is a child of \a parent. | |
349 | */ |
|
349 | */ | |
350 | QPieSeries::QPieSeries(QObject *parent) : |
|
350 | QPieSeries::QPieSeries(QObject *parent) : | |
351 | QAbstractSeries(*new QPieSeriesPrivate(this),parent) |
|
351 | QAbstractSeries(*new QPieSeriesPrivate(this),parent) | |
352 | { |
|
352 | { | |
353 |
|
353 | |||
354 | } |
|
354 | } | |
355 |
|
355 | |||
356 | /*! |
|
356 | /*! | |
357 | Destroys the series and its slices. |
|
357 | Destroys the series and its slices. | |
358 | */ |
|
358 | */ | |
359 | QPieSeries::~QPieSeries() |
|
359 | QPieSeries::~QPieSeries() | |
360 | { |
|
360 | { | |
361 | // NOTE: d_prt destroyed by QObject |
|
361 | // NOTE: d_prt destroyed by QObject | |
362 | } |
|
362 | } | |
363 |
|
363 | |||
364 | /*! |
|
364 | /*! | |
365 | Returns QChartSeries::SeriesTypePie. |
|
365 | Returns QChartSeries::SeriesTypePie. | |
366 | */ |
|
366 | */ | |
367 | QAbstractSeries::SeriesType QPieSeries::type() const |
|
367 | QAbstractSeries::SeriesType QPieSeries::type() const | |
368 | { |
|
368 | { | |
369 | return QAbstractSeries::SeriesTypePie; |
|
369 | return QAbstractSeries::SeriesTypePie; | |
370 | } |
|
370 | } | |
371 |
|
371 | |||
372 | /*! |
|
372 | /*! | |
373 | Appends a single \a slice to the series. |
|
373 | Appends a single \a slice to the series. | |
374 | Slice ownership is passed to the series. |
|
374 | Slice ownership is passed to the series. | |
375 |
|
375 | |||
376 | Returns true if append was succesfull. |
|
376 | Returns true if append was succesfull. | |
377 | */ |
|
377 | */ | |
378 | bool QPieSeries::append(QPieSlice* slice) |
|
378 | bool QPieSeries::append(QPieSlice* slice) | |
379 | { |
|
379 | { | |
380 | return append(QList<QPieSlice*>() << slice); |
|
380 | return append(QList<QPieSlice*>() << slice); | |
381 | } |
|
381 | } | |
382 |
|
382 | |||
383 | /*! |
|
383 | /*! | |
384 | Appends an array of \a slices to the series. |
|
384 | Appends an array of \a slices to the series. | |
385 | Slice ownership is passed to the series. |
|
385 | Slice ownership is passed to the series. | |
386 |
|
386 | |||
387 |
Returns true if append was successful |
|
387 | Returns true if append was successful. | |
388 | */ |
|
388 | */ | |
389 | bool QPieSeries::append(QList<QPieSlice*> slices) |
|
389 | bool QPieSeries::append(QList<QPieSlice*> slices) | |
390 | { |
|
390 | { | |
391 | Q_D(QPieSeries); |
|
391 | Q_D(QPieSeries); | |
392 |
|
392 | |||
393 | if (slices.count() == 0) |
|
393 | if (slices.count() == 0) | |
394 | return false; |
|
394 | return false; | |
395 |
|
395 | |||
396 | foreach (QPieSlice* s, slices) { |
|
396 | foreach (QPieSlice* s, slices) { | |
397 | if (!s || d->m_slices.contains(s)) |
|
397 | if (!s || d->m_slices.contains(s)) | |
398 | return false; |
|
398 | return false; | |
399 | if (s->series()) // already added to some series |
|
399 | if (s->series()) // already added to some series | |
400 | return false; |
|
400 | return false; | |
401 | } |
|
401 | } | |
402 |
|
402 | |||
403 | foreach (QPieSlice* s, slices) { |
|
403 | foreach (QPieSlice* s, slices) { | |
404 | s->setParent(this); |
|
404 | s->setParent(this); | |
405 | QPieSlicePrivate::fromSlice(s)->m_series = this; |
|
405 | QPieSlicePrivate::fromSlice(s)->m_series = this; | |
406 | d->m_slices << s; |
|
406 | d->m_slices << s; | |
407 | } |
|
407 | } | |
408 |
|
408 | |||
409 | d->updateDerivativeData(); |
|
409 | d->updateDerivativeData(); | |
410 |
|
410 | |||
411 | foreach (QPieSlice* s, slices) { |
|
411 | foreach (QPieSlice* s, slices) { | |
412 | connect(s, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged())); |
|
412 | connect(s, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged())); | |
413 | connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked())); |
|
413 | connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked())); | |
414 | connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool))); |
|
414 | connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool))); | |
415 | } |
|
415 | } | |
416 |
|
416 | |||
417 | emit added(slices); |
|
417 | emit added(slices); | |
418 | emit countChanged(); |
|
418 | emit countChanged(); | |
419 |
|
419 | |||
420 | return true; |
|
420 | return true; | |
421 | } |
|
421 | } | |
422 |
|
422 | |||
423 | /*! |
|
423 | /*! | |
424 | Appends a single \a slice to the series and returns a reference to the series. |
|
424 | Appends a single \a slice to the series and returns a reference to the series. | |
425 | Slice ownership is passed to the series. |
|
425 | Slice ownership is passed to the series. | |
426 | */ |
|
426 | */ | |
427 | QPieSeries& QPieSeries::operator << (QPieSlice* slice) |
|
427 | QPieSeries& QPieSeries::operator << (QPieSlice* slice) | |
428 | { |
|
428 | { | |
429 | append(slice); |
|
429 | append(slice); | |
430 | return *this; |
|
430 | return *this; | |
431 | } |
|
431 | } | |
432 |
|
432 | |||
433 |
|
433 | |||
434 | /*! |
|
434 | /*! | |
435 | Appends a single slice to the series with give \a value and \a label. |
|
435 | Appends a single slice to the series with give \a value and \a label. | |
436 | Slice ownership is passed to the series. |
|
436 | Slice ownership is passed to the series. | |
437 | */ |
|
437 | */ | |
438 | QPieSlice* QPieSeries::append(QString label, qreal value) |
|
438 | QPieSlice* QPieSeries::append(QString label, qreal value) | |
439 | { |
|
439 | { | |
440 | QPieSlice* slice = new QPieSlice(label, value); |
|
440 | QPieSlice* slice = new QPieSlice(label, value); | |
441 | append(slice); |
|
441 | append(slice); | |
442 | return slice; |
|
442 | return slice; | |
443 | } |
|
443 | } | |
444 |
|
444 | |||
445 | /*! |
|
445 | /*! | |
446 | Inserts a single \a slice to the series before the slice at \a index position. |
|
446 | Inserts a single \a slice to the series before the slice at \a index position. | |
447 | Slice ownership is passed to the series. |
|
447 | Slice ownership is passed to the series. | |
448 |
|
448 | |||
449 |
Returns true if insert was successful |
|
449 | Returns true if insert was successful. | |
450 | */ |
|
450 | */ | |
451 | bool QPieSeries::insert(int index, QPieSlice* slice) |
|
451 | bool QPieSeries::insert(int index, QPieSlice* slice) | |
452 | { |
|
452 | { | |
453 | Q_D(QPieSeries); |
|
453 | Q_D(QPieSeries); | |
454 |
|
454 | |||
455 | if (index < 0 || index > d->m_slices.count()) |
|
455 | if (index < 0 || index > d->m_slices.count()) | |
456 | return false; |
|
456 | return false; | |
457 |
|
457 | |||
458 | if (!slice || d->m_slices.contains(slice)) |
|
458 | if (!slice || d->m_slices.contains(slice)) | |
459 | return false; |
|
459 | return false; | |
460 |
|
460 | |||
461 | if (slice->series()) // already added to some series |
|
461 | if (slice->series()) // already added to some series | |
462 | return false; |
|
462 | return false; | |
463 |
|
463 | |||
464 | slice->setParent(this); |
|
464 | slice->setParent(this); | |
465 | QPieSlicePrivate::fromSlice(slice)->m_series = this; |
|
465 | QPieSlicePrivate::fromSlice(slice)->m_series = this; | |
466 | d->m_slices.insert(index, slice); |
|
466 | d->m_slices.insert(index, slice); | |
467 |
|
467 | |||
468 | d->updateDerivativeData(); |
|
468 | d->updateDerivativeData(); | |
469 |
|
469 | |||
470 | connect(slice, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged())); |
|
470 | connect(slice, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged())); | |
471 | connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked())); |
|
471 | connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked())); | |
472 | connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool))); |
|
472 | connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool))); | |
473 |
|
473 | |||
474 | emit added(QList<QPieSlice*>() << slice); |
|
474 | emit added(QList<QPieSlice*>() << slice); | |
475 | emit countChanged(); |
|
475 | emit countChanged(); | |
476 |
|
476 | |||
477 | return true; |
|
477 | return true; | |
478 | } |
|
478 | } | |
479 |
|
479 | |||
480 | /*! |
|
480 | /*! | |
481 | Removes a single \a slice from the series and deletes the slice. |
|
481 | Removes a single \a slice from the series and deletes the slice. | |
482 |
|
482 | |||
483 | Do not reference the pointer after this call. |
|
483 | Do not reference the pointer after this call. | |
484 |
|
484 | |||
485 |
Returns true if remove was successful |
|
485 | Returns true if remove was successful. | |
486 | */ |
|
486 | */ | |
487 | bool QPieSeries::remove(QPieSlice* slice) |
|
487 | bool QPieSeries::remove(QPieSlice* slice) | |
488 | { |
|
488 | { | |
489 | Q_D(QPieSeries); |
|
489 | Q_D(QPieSeries); | |
490 |
|
490 | |||
491 | if (!d->m_slices.removeOne(slice)) |
|
491 | if (!d->m_slices.removeOne(slice)) | |
492 | return false; |
|
492 | return false; | |
493 |
|
493 | |||
494 | d->updateDerivativeData(); |
|
494 | d->updateDerivativeData(); | |
495 |
|
495 | |||
496 | emit removed(QList<QPieSlice*>() << slice); |
|
496 | emit removed(QList<QPieSlice*>() << slice); | |
497 | emit countChanged(); |
|
497 | emit countChanged(); | |
498 |
|
498 | |||
499 | delete slice; |
|
499 | delete slice; | |
500 | slice = 0; |
|
500 | slice = 0; | |
501 |
|
501 | |||
502 | return true; |
|
502 | return true; | |
503 | } |
|
503 | } | |
504 |
|
504 | |||
505 | /*! |
|
505 | /*! | |
506 | Takes a single \a slice from the series. Does not destroy the slice object. |
|
506 | Takes a single \a slice from the series. Does not destroy the slice object. | |
507 |
|
507 | |||
508 | NOTE: The series remains as the slice's parent object. You must set the |
|
508 | NOTE: The series remains as the slice's parent object. You must set the | |
509 | parent object to take full ownership. |
|
509 | parent object to take full ownership. | |
510 |
|
510 | |||
511 |
Returns true if take was successful |
|
511 | Returns true if take was successful. | |
512 | */ |
|
512 | */ | |
513 | bool QPieSeries::take(QPieSlice* slice) |
|
513 | bool QPieSeries::take(QPieSlice* slice) | |
514 | { |
|
514 | { | |
515 | Q_D(QPieSeries); |
|
515 | Q_D(QPieSeries); | |
516 |
|
516 | |||
517 | if (!d->m_slices.removeOne(slice)) |
|
517 | if (!d->m_slices.removeOne(slice)) | |
518 | return false; |
|
518 | return false; | |
519 |
|
519 | |||
520 | QPieSlicePrivate::fromSlice(slice)->m_series = 0; |
|
520 | QPieSlicePrivate::fromSlice(slice)->m_series = 0; | |
521 |
|
521 | |||
522 | d->updateDerivativeData(); |
|
522 | d->updateDerivativeData(); | |
523 |
|
523 | |||
524 | emit removed(QList<QPieSlice*>() << slice); |
|
524 | emit removed(QList<QPieSlice*>() << slice); | |
525 | emit countChanged(); |
|
525 | emit countChanged(); | |
526 |
|
526 | |||
527 | return true; |
|
527 | return true; | |
528 | } |
|
528 | } | |
529 |
|
529 | |||
530 | /*! |
|
530 | /*! | |
531 | Clears all slices from the series. |
|
531 | Clears all slices from the series. | |
532 | */ |
|
532 | */ | |
533 | void QPieSeries::clear() |
|
533 | void QPieSeries::clear() | |
534 | { |
|
534 | { | |
535 | Q_D(QPieSeries); |
|
535 | Q_D(QPieSeries); | |
536 | if (d->m_slices.count() == 0) |
|
536 | if (d->m_slices.count() == 0) | |
537 | return; |
|
537 | return; | |
538 |
|
538 | |||
539 | QList<QPieSlice*> slices = d->m_slices; |
|
539 | QList<QPieSlice*> slices = d->m_slices; | |
540 | foreach (QPieSlice* s, d->m_slices) { |
|
540 | foreach (QPieSlice* s, d->m_slices) { | |
541 | d->m_slices.removeOne(s); |
|
541 | d->m_slices.removeOne(s); | |
542 | delete s; |
|
542 | delete s; | |
543 | } |
|
543 | } | |
544 |
|
544 | |||
545 | d->updateDerivativeData(); |
|
545 | d->updateDerivativeData(); | |
546 |
|
546 | |||
547 | emit removed(slices); |
|
547 | emit removed(slices); | |
548 | emit countChanged(); |
|
548 | emit countChanged(); | |
549 | } |
|
549 | } | |
550 |
|
550 | |||
551 | /*! |
|
551 | /*! | |
552 | Returns a list of slices that belong to this series. |
|
552 | Returns a list of slices that belong to this series. | |
553 | */ |
|
553 | */ | |
554 | QList<QPieSlice*> QPieSeries::slices() const |
|
554 | QList<QPieSlice*> QPieSeries::slices() const | |
555 | { |
|
555 | { | |
556 | Q_D(const QPieSeries); |
|
556 | Q_D(const QPieSeries); | |
557 | return d->m_slices; |
|
557 | return d->m_slices; | |
558 | } |
|
558 | } | |
559 |
|
559 | |||
560 | /*! |
|
560 | /*! | |
561 | returns the number of the slices in this series. |
|
561 | returns the number of the slices in this series. | |
562 | */ |
|
562 | */ | |
563 | int QPieSeries::count() const |
|
563 | int QPieSeries::count() const | |
564 | { |
|
564 | { | |
565 | Q_D(const QPieSeries); |
|
565 | Q_D(const QPieSeries); | |
566 | return d->m_slices.count(); |
|
566 | return d->m_slices.count(); | |
567 | } |
|
567 | } | |
568 |
|
568 | |||
569 | /*! |
|
569 | /*! | |
570 | Returns true is the series is empty. |
|
570 | Returns true is the series is empty. | |
571 | */ |
|
571 | */ | |
572 | bool QPieSeries::isEmpty() const |
|
572 | bool QPieSeries::isEmpty() const | |
573 | { |
|
573 | { | |
574 | Q_D(const QPieSeries); |
|
574 | Q_D(const QPieSeries); | |
575 | return d->m_slices.isEmpty(); |
|
575 | return d->m_slices.isEmpty(); | |
576 | } |
|
576 | } | |
577 |
|
577 | |||
578 | /*! |
|
578 | /*! | |
579 | Returns the sum of all slice values in this series. |
|
579 | Returns the sum of all slice values in this series. | |
580 |
|
580 | |||
581 | \sa QPieSlice::value(), QPieSlice::setValue(), QPieSlice::percentage() |
|
581 | \sa QPieSlice::value(), QPieSlice::setValue(), QPieSlice::percentage() | |
582 | */ |
|
582 | */ | |
583 | qreal QPieSeries::sum() const |
|
583 | qreal QPieSeries::sum() const | |
584 | { |
|
584 | { | |
585 | Q_D(const QPieSeries); |
|
585 | Q_D(const QPieSeries); | |
586 | return d->m_sum; |
|
586 | return d->m_sum; | |
587 | } |
|
587 | } | |
588 |
|
588 | |||
589 | void QPieSeries::setHoleSize(qreal holeSize) |
|
589 | void QPieSeries::setHoleSize(qreal holeSize) | |
590 | { |
|
590 | { | |
591 | Q_D(QPieSeries); |
|
591 | Q_D(QPieSeries); | |
592 | holeSize = qBound((qreal)0.0, holeSize, (qreal)1.0); |
|
592 | holeSize = qBound((qreal)0.0, holeSize, (qreal)1.0); | |
593 | d->setSizes(holeSize, qMax(d->m_pieRelativeSize, holeSize)); |
|
593 | d->setSizes(holeSize, qMax(d->m_pieRelativeSize, holeSize)); | |
594 | } |
|
594 | } | |
595 |
|
595 | |||
596 | qreal QPieSeries::holeSize() const |
|
596 | qreal QPieSeries::holeSize() const | |
597 | { |
|
597 | { | |
598 | Q_D(const QPieSeries); |
|
598 | Q_D(const QPieSeries); | |
599 | return d->m_holeRelativeSize; |
|
599 | return d->m_holeRelativeSize; | |
600 | } |
|
600 | } | |
601 |
|
601 | |||
602 | void QPieSeries::setHorizontalPosition(qreal relativePosition) |
|
602 | void QPieSeries::setHorizontalPosition(qreal relativePosition) | |
603 | { |
|
603 | { | |
604 | Q_D(QPieSeries); |
|
604 | Q_D(QPieSeries); | |
605 |
|
605 | |||
606 | if (relativePosition < 0.0) |
|
606 | if (relativePosition < 0.0) | |
607 | relativePosition = 0.0; |
|
607 | relativePosition = 0.0; | |
608 | if (relativePosition > 1.0) |
|
608 | if (relativePosition > 1.0) | |
609 | relativePosition = 1.0; |
|
609 | relativePosition = 1.0; | |
610 |
|
610 | |||
611 | if (!qFuzzyIsNull(d->m_pieRelativeHorPos - relativePosition)) { |
|
611 | if (!qFuzzyIsNull(d->m_pieRelativeHorPos - relativePosition)) { | |
612 | d->m_pieRelativeHorPos = relativePosition; |
|
612 | d->m_pieRelativeHorPos = relativePosition; | |
613 | emit d->horizontalPositionChanged(); |
|
613 | emit d->horizontalPositionChanged(); | |
614 | } |
|
614 | } | |
615 | } |
|
615 | } | |
616 |
|
616 | |||
617 | qreal QPieSeries::horizontalPosition() const |
|
617 | qreal QPieSeries::horizontalPosition() const | |
618 | { |
|
618 | { | |
619 | Q_D(const QPieSeries); |
|
619 | Q_D(const QPieSeries); | |
620 | return d->m_pieRelativeHorPos; |
|
620 | return d->m_pieRelativeHorPos; | |
621 | } |
|
621 | } | |
622 |
|
622 | |||
623 | void QPieSeries::setVerticalPosition(qreal relativePosition) |
|
623 | void QPieSeries::setVerticalPosition(qreal relativePosition) | |
624 | { |
|
624 | { | |
625 | Q_D(QPieSeries); |
|
625 | Q_D(QPieSeries); | |
626 |
|
626 | |||
627 | if (relativePosition < 0.0) |
|
627 | if (relativePosition < 0.0) | |
628 | relativePosition = 0.0; |
|
628 | relativePosition = 0.0; | |
629 | if (relativePosition > 1.0) |
|
629 | if (relativePosition > 1.0) | |
630 | relativePosition = 1.0; |
|
630 | relativePosition = 1.0; | |
631 |
|
631 | |||
632 | if (!qFuzzyIsNull(d->m_pieRelativeVerPos - relativePosition)) { |
|
632 | if (!qFuzzyIsNull(d->m_pieRelativeVerPos - relativePosition)) { | |
633 | d->m_pieRelativeVerPos = relativePosition; |
|
633 | d->m_pieRelativeVerPos = relativePosition; | |
634 | emit d->verticalPositionChanged(); |
|
634 | emit d->verticalPositionChanged(); | |
635 | } |
|
635 | } | |
636 | } |
|
636 | } | |
637 |
|
637 | |||
638 | qreal QPieSeries::verticalPosition() const |
|
638 | qreal QPieSeries::verticalPosition() const | |
639 | { |
|
639 | { | |
640 | Q_D(const QPieSeries); |
|
640 | Q_D(const QPieSeries); | |
641 | return d->m_pieRelativeVerPos; |
|
641 | return d->m_pieRelativeVerPos; | |
642 | } |
|
642 | } | |
643 |
|
643 | |||
644 | void QPieSeries::setPieSize(qreal relativeSize) |
|
644 | void QPieSeries::setPieSize(qreal relativeSize) | |
645 | { |
|
645 | { | |
646 | Q_D(QPieSeries); |
|
646 | Q_D(QPieSeries); | |
647 | relativeSize = qBound((qreal)0.0, relativeSize, (qreal)1.0); |
|
647 | relativeSize = qBound((qreal)0.0, relativeSize, (qreal)1.0); | |
648 | d->setSizes(qMin(d->m_holeRelativeSize, relativeSize), relativeSize); |
|
648 | d->setSizes(qMin(d->m_holeRelativeSize, relativeSize), relativeSize); | |
649 |
|
649 | |||
650 | } |
|
650 | } | |
651 |
|
651 | |||
652 | qreal QPieSeries::pieSize() const |
|
652 | qreal QPieSeries::pieSize() const | |
653 | { |
|
653 | { | |
654 | Q_D(const QPieSeries); |
|
654 | Q_D(const QPieSeries); | |
655 | return d->m_pieRelativeSize; |
|
655 | return d->m_pieRelativeSize; | |
656 | } |
|
656 | } | |
657 |
|
657 | |||
658 |
|
658 | |||
659 | void QPieSeries::setPieStartAngle(qreal angle) |
|
659 | void QPieSeries::setPieStartAngle(qreal angle) | |
660 | { |
|
660 | { | |
661 | Q_D(QPieSeries); |
|
661 | Q_D(QPieSeries); | |
662 | if (qFuzzyIsNull(d->m_pieStartAngle - angle)) |
|
662 | if (qFuzzyIsNull(d->m_pieStartAngle - angle)) | |
663 | return; |
|
663 | return; | |
664 | d->m_pieStartAngle = angle; |
|
664 | d->m_pieStartAngle = angle; | |
665 | d->updateDerivativeData(); |
|
665 | d->updateDerivativeData(); | |
666 | emit d->pieStartAngleChanged(); |
|
666 | emit d->pieStartAngleChanged(); | |
667 | } |
|
667 | } | |
668 |
|
668 | |||
669 | qreal QPieSeries::pieStartAngle() const |
|
669 | qreal QPieSeries::pieStartAngle() const | |
670 | { |
|
670 | { | |
671 | Q_D(const QPieSeries); |
|
671 | Q_D(const QPieSeries); | |
672 | return d->m_pieStartAngle; |
|
672 | return d->m_pieStartAngle; | |
673 | } |
|
673 | } | |
674 |
|
674 | |||
675 | /*! |
|
675 | /*! | |
676 | Sets the end angle of the pie. |
|
676 | Sets the end angle of the pie. | |
677 |
|
677 | |||
678 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
678 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
679 |
|
679 | |||
680 | \a angle must be greater than start angle. |
|
680 | \a angle must be greater than start angle. | |
681 |
|
681 | |||
682 | \sa pieEndAngle(), pieStartAngle(), setPieStartAngle() |
|
682 | \sa pieEndAngle(), pieStartAngle(), setPieStartAngle() | |
683 | */ |
|
683 | */ | |
684 | void QPieSeries::setPieEndAngle(qreal angle) |
|
684 | void QPieSeries::setPieEndAngle(qreal angle) | |
685 | { |
|
685 | { | |
686 | Q_D(QPieSeries); |
|
686 | Q_D(QPieSeries); | |
687 | if (qFuzzyIsNull(d->m_pieEndAngle - angle)) |
|
687 | if (qFuzzyIsNull(d->m_pieEndAngle - angle)) | |
688 | return; |
|
688 | return; | |
689 | d->m_pieEndAngle = angle; |
|
689 | d->m_pieEndAngle = angle; | |
690 | d->updateDerivativeData(); |
|
690 | d->updateDerivativeData(); | |
691 | emit d->pieEndAngleChanged(); |
|
691 | emit d->pieEndAngleChanged(); | |
692 | } |
|
692 | } | |
693 |
|
693 | |||
694 | /*! |
|
694 | /*! | |
695 | Returns the end angle of the pie. |
|
695 | Returns the end angle of the pie. | |
696 |
|
696 | |||
697 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
697 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
698 |
|
698 | |||
699 | \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle() |
|
699 | \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle() | |
700 | */ |
|
700 | */ | |
701 | qreal QPieSeries::pieEndAngle() const |
|
701 | qreal QPieSeries::pieEndAngle() const | |
702 | { |
|
702 | { | |
703 | Q_D(const QPieSeries); |
|
703 | Q_D(const QPieSeries); | |
704 | return d->m_pieEndAngle; |
|
704 | return d->m_pieEndAngle; | |
705 | } |
|
705 | } | |
706 |
|
706 | |||
707 | /*! |
|
707 | /*! | |
708 | Sets the all the slice labels \a visible or invisible. |
|
708 | Sets the all the slice labels \a visible or invisible. | |
709 |
|
709 | |||
710 | Note that this affects only the current slices in the series. |
|
710 | Note that this affects only the current slices in the series. | |
711 | If user adds a new slice the default label visibility is false. |
|
711 | If user adds a new slice the default label visibility is false. | |
712 |
|
712 | |||
713 | \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible() |
|
713 | \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible() | |
714 | */ |
|
714 | */ | |
715 | void QPieSeries::setLabelsVisible(bool visible) |
|
715 | void QPieSeries::setLabelsVisible(bool visible) | |
716 | { |
|
716 | { | |
717 | Q_D(QPieSeries); |
|
717 | Q_D(QPieSeries); | |
718 | foreach (QPieSlice* s, d->m_slices) |
|
718 | foreach (QPieSlice* s, d->m_slices) | |
719 | s->setLabelVisible(visible); |
|
719 | s->setLabelVisible(visible); | |
720 | } |
|
720 | } | |
721 |
|
721 | |||
722 | /*! |
|
722 | /*! | |
723 | Sets the all the slice labels \a position |
|
723 | Sets the all the slice labels \a position | |
724 |
|
724 | |||
725 | Note that this affects only the current slices in the series. |
|
725 | Note that this affects only the current slices in the series. | |
726 | If user adds a new slice the default label position is LabelOutside |
|
726 | If user adds a new slice the default label position is LabelOutside | |
727 |
|
727 | |||
728 | \sa QPieSlice::labelPosition(), QPieSlice::setLabelPosition() |
|
728 | \sa QPieSlice::labelPosition(), QPieSlice::setLabelPosition() | |
729 | */ |
|
729 | */ | |
730 | void QPieSeries::setLabelsPosition(QPieSlice::LabelPosition position) |
|
730 | void QPieSeries::setLabelsPosition(QPieSlice::LabelPosition position) | |
731 | { |
|
731 | { | |
732 | Q_D(QPieSeries); |
|
732 | Q_D(QPieSeries); | |
733 | foreach (QPieSlice* s, d->m_slices) |
|
733 | foreach (QPieSlice* s, d->m_slices) | |
734 | s->setLabelPosition(position); |
|
734 | s->setLabelPosition(position); | |
735 | } |
|
735 | } | |
736 |
|
736 | |||
737 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
737 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
738 |
|
738 | |||
739 |
|
739 | |||
740 | QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) : |
|
740 | QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) : | |
741 | QAbstractSeriesPrivate(parent), |
|
741 | QAbstractSeriesPrivate(parent), | |
742 | m_pieRelativeHorPos(0.5), |
|
742 | m_pieRelativeHorPos(0.5), | |
743 | m_pieRelativeVerPos(0.5), |
|
743 | m_pieRelativeVerPos(0.5), | |
744 | m_pieRelativeSize(0.7), |
|
744 | m_pieRelativeSize(0.7), | |
745 | m_pieStartAngle(0), |
|
745 | m_pieStartAngle(0), | |
746 | m_pieEndAngle(360), |
|
746 | m_pieEndAngle(360), | |
747 | m_sum(0), |
|
747 | m_sum(0), | |
748 | m_holeRelativeSize(0.0) |
|
748 | m_holeRelativeSize(0.0) | |
749 | { |
|
749 | { | |
750 | } |
|
750 | } | |
751 |
|
751 | |||
752 | QPieSeriesPrivate::~QPieSeriesPrivate() |
|
752 | QPieSeriesPrivate::~QPieSeriesPrivate() | |
753 | { |
|
753 | { | |
754 | } |
|
754 | } | |
755 |
|
755 | |||
756 | void QPieSeriesPrivate::updateDerivativeData() |
|
756 | void QPieSeriesPrivate::updateDerivativeData() | |
757 | { |
|
757 | { | |
758 | // calculate sum of all slices |
|
758 | // calculate sum of all slices | |
759 | qreal sum = 0; |
|
759 | qreal sum = 0; | |
760 | foreach (QPieSlice* s, m_slices) |
|
760 | foreach (QPieSlice* s, m_slices) | |
761 | sum += s->value(); |
|
761 | sum += s->value(); | |
762 |
|
762 | |||
763 | if (!qFuzzyIsNull(m_sum - sum)) { |
|
763 | if (!qFuzzyIsNull(m_sum - sum)) { | |
764 | m_sum = sum; |
|
764 | m_sum = sum; | |
765 | emit q_func()->sumChanged(); |
|
765 | emit q_func()->sumChanged(); | |
766 | } |
|
766 | } | |
767 |
|
767 | |||
768 | // nothing to show.. |
|
768 | // nothing to show.. | |
769 | if (qFuzzyIsNull(m_sum)) |
|
769 | if (qFuzzyIsNull(m_sum)) | |
770 | return; |
|
770 | return; | |
771 |
|
771 | |||
772 | // update slice attributes |
|
772 | // update slice attributes | |
773 | qreal sliceAngle = m_pieStartAngle; |
|
773 | qreal sliceAngle = m_pieStartAngle; | |
774 | qreal pieSpan = m_pieEndAngle - m_pieStartAngle; |
|
774 | qreal pieSpan = m_pieEndAngle - m_pieStartAngle; | |
775 | QVector<QPieSlice*> changed; |
|
775 | QVector<QPieSlice*> changed; | |
776 | foreach (QPieSlice* s, m_slices) { |
|
776 | foreach (QPieSlice* s, m_slices) { | |
777 | QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s); |
|
777 | QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s); | |
778 | d->setPercentage(s->value() / m_sum); |
|
778 | d->setPercentage(s->value() / m_sum); | |
779 | d->setStartAngle(sliceAngle); |
|
779 | d->setStartAngle(sliceAngle); | |
780 | d->setAngleSpan(pieSpan * s->percentage()); |
|
780 | d->setAngleSpan(pieSpan * s->percentage()); | |
781 | sliceAngle += s->angleSpan(); |
|
781 | sliceAngle += s->angleSpan(); | |
782 | } |
|
782 | } | |
783 |
|
783 | |||
784 |
|
784 | |||
785 | emit calculatedDataChanged(); |
|
785 | emit calculatedDataChanged(); | |
786 | } |
|
786 | } | |
787 |
|
787 | |||
788 | void QPieSeriesPrivate::setSizes(qreal innerSize, qreal outerSize) |
|
788 | void QPieSeriesPrivate::setSizes(qreal innerSize, qreal outerSize) | |
789 | { |
|
789 | { | |
790 | bool changed = false; |
|
790 | bool changed = false; | |
791 |
|
791 | |||
792 | if (!qFuzzyIsNull(m_holeRelativeSize - innerSize)) { |
|
792 | if (!qFuzzyIsNull(m_holeRelativeSize - innerSize)) { | |
793 | m_holeRelativeSize = innerSize; |
|
793 | m_holeRelativeSize = innerSize; | |
794 | changed = true; |
|
794 | changed = true; | |
795 | } |
|
795 | } | |
796 |
|
796 | |||
797 | if (!qFuzzyIsNull(m_pieRelativeSize - outerSize)) { |
|
797 | if (!qFuzzyIsNull(m_pieRelativeSize - outerSize)) { | |
798 | m_pieRelativeSize = outerSize; |
|
798 | m_pieRelativeSize = outerSize; | |
799 | changed = true; |
|
799 | changed = true; | |
800 | } |
|
800 | } | |
801 |
|
801 | |||
802 | if (changed) |
|
802 | if (changed) | |
803 | emit pieSizeChanged(); |
|
803 | emit pieSizeChanged(); | |
804 | } |
|
804 | } | |
805 |
|
805 | |||
806 | QPieSeriesPrivate* QPieSeriesPrivate::fromSeries(QPieSeries *series) |
|
806 | QPieSeriesPrivate* QPieSeriesPrivate::fromSeries(QPieSeries *series) | |
807 | { |
|
807 | { | |
808 | return series->d_func(); |
|
808 | return series->d_func(); | |
809 | } |
|
809 | } | |
810 |
|
810 | |||
811 | void QPieSeriesPrivate::sliceValueChanged() |
|
811 | void QPieSeriesPrivate::sliceValueChanged() | |
812 | { |
|
812 | { | |
813 | Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender()))); |
|
813 | Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender()))); | |
814 | updateDerivativeData(); |
|
814 | updateDerivativeData(); | |
815 | } |
|
815 | } | |
816 |
|
816 | |||
817 | void QPieSeriesPrivate::sliceClicked() |
|
817 | void QPieSeriesPrivate::sliceClicked() | |
818 | { |
|
818 | { | |
819 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); |
|
819 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | |
820 | Q_ASSERT(m_slices.contains(slice)); |
|
820 | Q_ASSERT(m_slices.contains(slice)); | |
821 | Q_Q(QPieSeries); |
|
821 | Q_Q(QPieSeries); | |
822 | emit q->clicked(slice); |
|
822 | emit q->clicked(slice); | |
823 | } |
|
823 | } | |
824 |
|
824 | |||
825 | void QPieSeriesPrivate::sliceHovered(bool state) |
|
825 | void QPieSeriesPrivate::sliceHovered(bool state) | |
826 | { |
|
826 | { | |
827 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); |
|
827 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | |
828 | Q_ASSERT(m_slices.contains(slice)); |
|
828 | Q_ASSERT(m_slices.contains(slice)); | |
829 | Q_Q(QPieSeries); |
|
829 | Q_Q(QPieSeries); | |
830 | emit q->hovered(slice, state); |
|
830 | emit q->hovered(slice, state); | |
831 | } |
|
831 | } | |
832 |
|
832 | |||
833 | void QPieSeriesPrivate::scaleDomain(Domain& domain) |
|
833 | void QPieSeriesPrivate::scaleDomain(Domain& domain) | |
834 | { |
|
834 | { | |
835 | Q_UNUSED(domain); |
|
835 | Q_UNUSED(domain); | |
836 | // does not apply to pie |
|
836 | // does not apply to pie | |
837 | } |
|
837 | } | |
838 |
|
838 | |||
839 | ChartElement* QPieSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
839 | ChartElement* QPieSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
840 | { |
|
840 | { | |
841 | Q_Q(QPieSeries); |
|
841 | Q_Q(QPieSeries); | |
842 | PieChartItem* pie = new PieChartItem(q,presenter); |
|
842 | PieChartItem* pie = new PieChartItem(q,presenter); | |
843 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
843 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
844 | pie->setAnimation(new PieAnimation(pie)); |
|
844 | pie->setAnimation(new PieAnimation(pie)); | |
845 | } |
|
845 | } | |
846 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
846 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
847 | return pie; |
|
847 | return pie; | |
848 | } |
|
848 | } | |
849 |
|
849 | |||
850 | QList<LegendMarker*> QPieSeriesPrivate::createLegendMarker(QLegend* legend) |
|
850 | QList<LegendMarker*> QPieSeriesPrivate::createLegendMarker(QLegend* legend) | |
851 | { |
|
851 | { | |
852 | Q_Q(QPieSeries); |
|
852 | Q_Q(QPieSeries); | |
853 | QList<LegendMarker*> markers; |
|
853 | QList<LegendMarker*> markers; | |
854 | foreach(QPieSlice* slice, q->slices()) { |
|
854 | foreach(QPieSlice* slice, q->slices()) { | |
855 | PieLegendMarker* marker = new PieLegendMarker(q,slice,legend); |
|
855 | PieLegendMarker* marker = new PieLegendMarker(q,slice,legend); | |
856 | markers << marker; |
|
856 | markers << marker; | |
857 | } |
|
857 | } | |
858 | return markers; |
|
858 | return markers; | |
859 | } |
|
859 | } | |
860 |
|
860 | |||
861 | void QPieSeriesPrivate::initializeAxis(QAbstractAxis* axis) |
|
861 | void QPieSeriesPrivate::initializeAxis(QAbstractAxis* axis) | |
862 | { |
|
862 | { | |
863 | Q_UNUSED(axis); |
|
863 | Q_UNUSED(axis); | |
864 | } |
|
864 | } | |
865 |
|
865 | |||
866 | QAbstractAxis::AxisType QPieSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const |
|
866 | QAbstractAxis::AxisType QPieSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const | |
867 | { |
|
867 | { | |
868 | Q_UNUSED(orientation); |
|
868 | Q_UNUSED(orientation); | |
869 | return QAbstractAxis::AxisTypeNoAxis; |
|
869 | return QAbstractAxis::AxisTypeNoAxis; | |
870 | } |
|
870 | } | |
871 |
|
871 | |||
872 | #include "moc_qpieseries.cpp" |
|
872 | #include "moc_qpieseries.cpp" | |
873 | #include "moc_qpieseries_p.cpp" |
|
873 | #include "moc_qpieseries_p.cpp" | |
874 |
|
874 | |||
875 | QTCOMMERCIALCHART_END_NAMESPACE |
|
875 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now