@@ -1,384 +1,398 | |||||
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 "qareaseries.h" |
|
21 | #include "qareaseries.h" | |
22 | #include "qareaseries_p.h" |
|
22 | #include "qareaseries_p.h" | |
23 | #include "qlineseries.h" |
|
23 | #include "qlineseries.h" | |
24 | #include "areachartitem_p.h" |
|
24 | #include "areachartitem_p.h" | |
25 | #include "legendmarker_p.h" |
|
25 | #include "legendmarker_p.h" | |
26 | #include "domain_p.h" |
|
26 | #include "domain_p.h" | |
27 | #include "chartdataset_p.h" |
|
27 | #include "chartdataset_p.h" | |
28 | #include "charttheme_p.h" |
|
28 | #include "charttheme_p.h" | |
29 | #include "chartanimator_p.h" |
|
29 | #include "chartanimator_p.h" | |
|
30 | #include "qvaluesaxis.h" | |||
30 |
|
31 | |||
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
32 |
|
33 | |||
33 | /*! |
|
34 | /*! | |
34 | \class QAreaSeries |
|
35 | \class QAreaSeries | |
35 | \brief The QAreaSeries class is used for making area charts. |
|
36 | \brief The QAreaSeries class is used for making area charts. | |
36 |
|
37 | |||
37 | \mainclass |
|
38 | \mainclass | |
38 |
|
39 | |||
39 | An area chart is used to show quantitative data. It is based on line chart, in the way that area between axis and the line |
|
40 | An area chart is used to show quantitative data. It is based on line chart, in the way that area between axis and the line | |
40 | is emphasized with color. Since the area chart is based on line chart, QAreaSeries constructor needs QLineSeries instance, |
|
41 | is emphasized with color. Since the area chart is based on line chart, QAreaSeries constructor needs QLineSeries instance, | |
41 | which defines "upper" boundary of the area. "Lower" boundary is defined by default by axis X. Instead of axis X "lower" boundary can be specified by other line. |
|
42 | which defines "upper" boundary of the area. "Lower" boundary is defined by default by axis X. Instead of axis X "lower" boundary can be specified by other line. | |
42 | In that case QAreaSeries should be initiated with two QLineSeries instances. Please note terms "upper" and "lower" boundary can be misleading in cases |
|
43 | In that case QAreaSeries should be initiated with two QLineSeries instances. Please note terms "upper" and "lower" boundary can be misleading in cases | |
43 | where "lower" boundary had bigger values than the "upper" one, however the main point that area between these two boundary lines will be filled. |
|
44 | where "lower" boundary had bigger values than the "upper" one, however the main point that area between these two boundary lines will be filled. | |
44 |
|
45 | |||
45 | See the \l {AreaChart Example} {area chart example} to learn how to create a simple area chart. |
|
46 | See the \l {AreaChart Example} {area chart example} to learn how to create a simple area chart. | |
46 | \image examples_areachart.png |
|
47 | \image examples_areachart.png | |
47 | */ |
|
48 | */ | |
48 | /*! |
|
49 | /*! | |
49 | \qmlclass AreaSeries QAreaSeries |
|
50 | \qmlclass AreaSeries QAreaSeries | |
50 |
|
51 | |||
51 | The following QML shows how to create a simple area chart: |
|
52 | The following QML shows how to create a simple area chart: | |
52 | \snippet ../demos/qmlchart/qml/qmlchart/View4.qml 1 |
|
53 | \snippet ../demos/qmlchart/qml/qmlchart/View4.qml 1 | |
53 | \beginfloatleft |
|
54 | \beginfloatleft | |
54 | \image demos_qmlchart4.png |
|
55 | \image demos_qmlchart4.png | |
55 | \endfloat |
|
56 | \endfloat | |
56 | \clearfloat |
|
57 | \clearfloat | |
57 | */ |
|
58 | */ | |
58 |
|
59 | |||
59 | /*! |
|
60 | /*! | |
60 | \property QAreaSeries::upperSeries |
|
61 | \property QAreaSeries::upperSeries | |
61 | \brief The upper one of the two line series used to define area series boundaries. |
|
62 | \brief The upper one of the two line series used to define area series boundaries. | |
62 | */ |
|
63 | */ | |
63 | /*! |
|
64 | /*! | |
64 | \qmlproperty LineSeries AreaSeries::upperSeries |
|
65 | \qmlproperty LineSeries AreaSeries::upperSeries | |
65 | The upper one of the two line series used to define area series boundaries. |
|
66 | The upper one of the two line series used to define area series boundaries. | |
66 | */ |
|
67 | */ | |
67 |
|
68 | |||
68 | /*! |
|
69 | /*! | |
69 | \property QAreaSeries::lowerSeries |
|
70 | \property QAreaSeries::lowerSeries | |
70 | The lower one of the two line series used to define are series boundaries. Note if |
|
71 | The lower one of the two line series used to define are series boundaries. Note if | |
71 | QAreaSeries was counstucted wihtout a\ lowerSeries this is null. |
|
72 | QAreaSeries was counstucted wihtout a\ lowerSeries this is null. | |
72 | */ |
|
73 | */ | |
73 | /*! |
|
74 | /*! | |
74 | \qmlproperty LineSeries AreaSeries::lowerSeries |
|
75 | \qmlproperty LineSeries AreaSeries::lowerSeries | |
75 | The lower one of the two line series used to define are series boundaries. Note if |
|
76 | The lower one of the two line series used to define are series boundaries. Note if | |
76 | AreaSeries was counstucted wihtout a\ lowerSeries this is null. |
|
77 | AreaSeries was counstucted wihtout a\ lowerSeries this is null. | |
77 | */ |
|
78 | */ | |
78 |
|
79 | |||
79 | /*! |
|
80 | /*! | |
80 | \property QAreaSeries::color |
|
81 | \property QAreaSeries::color | |
81 | Fill (brush) color of the series. This is a convenience property for modifying the color of brush. |
|
82 | Fill (brush) color of the series. This is a convenience property for modifying the color of brush. | |
82 | \sa QAreaSeries::brush() |
|
83 | \sa QAreaSeries::brush() | |
83 | */ |
|
84 | */ | |
84 | /*! |
|
85 | /*! | |
85 | \qmlproperty color AreaSeries::color |
|
86 | \qmlproperty color AreaSeries::color | |
86 | Fill (brush) color of the series. |
|
87 | Fill (brush) color of the series. | |
87 | */ |
|
88 | */ | |
88 |
|
89 | |||
89 | /*! |
|
90 | /*! | |
90 | \property QAreaSeries::borderColor |
|
91 | \property QAreaSeries::borderColor | |
91 | Line (pen) color of the series. This is a convenience property for modifying the color of pen. |
|
92 | Line (pen) color of the series. This is a convenience property for modifying the color of pen. | |
92 | \sa QAreaSeries::pen() |
|
93 | \sa QAreaSeries::pen() | |
93 | */ |
|
94 | */ | |
94 | /*! |
|
95 | /*! | |
95 | \qmlproperty color AreaSeries::borderColor |
|
96 | \qmlproperty color AreaSeries::borderColor | |
96 | Line (pen) color of the series. |
|
97 | Line (pen) color of the series. | |
97 | */ |
|
98 | */ | |
98 |
|
99 | |||
99 | /*! |
|
100 | /*! | |
100 | \fn QPen QAreaSeries::pen() const |
|
101 | \fn QPen QAreaSeries::pen() const | |
101 | \brief Returns the pen used to draw line for this series. |
|
102 | \brief Returns the pen used to draw line for this series. | |
102 | \sa setPen() |
|
103 | \sa setPen() | |
103 | */ |
|
104 | */ | |
104 |
|
105 | |||
105 | /*! |
|
106 | /*! | |
106 | \fn QPen QAreaSeries::brush() const |
|
107 | \fn QPen QAreaSeries::brush() const | |
107 | \brief Returns the brush used to draw line for this series. |
|
108 | \brief Returns the brush used to draw line for this series. | |
108 | \sa setBrush() |
|
109 | \sa setBrush() | |
109 | */ |
|
110 | */ | |
110 |
|
111 | |||
111 | /*! |
|
112 | /*! | |
112 | \fn void QAreaSeries::colorChanged(QColor color) |
|
113 | \fn void QAreaSeries::colorChanged(QColor color) | |
113 | \brief Signal is emitted when the fill (brush) color has changed to \a color. |
|
114 | \brief Signal is emitted when the fill (brush) color has changed to \a color. | |
114 | */ |
|
115 | */ | |
115 | /*! |
|
116 | /*! | |
116 | \qmlsignal AreaSeries::onColorChanged(color color) |
|
117 | \qmlsignal AreaSeries::onColorChanged(color color) | |
117 | Signal is emitted when the fill (brush) color has changed to \a color. |
|
118 | Signal is emitted when the fill (brush) color has changed to \a color. | |
118 | */ |
|
119 | */ | |
119 |
|
120 | |||
120 | /*! |
|
121 | /*! | |
121 | \fn void QAreaSeries::borderColorChanged(QColor color) |
|
122 | \fn void QAreaSeries::borderColorChanged(QColor color) | |
122 | \brief Signal is emitted when the line (pen) color has changed to \a color. |
|
123 | \brief Signal is emitted when the line (pen) color has changed to \a color. | |
123 | */ |
|
124 | */ | |
124 | /*! |
|
125 | /*! | |
125 | \qmlsignal AreaSeries::onBorderColorChanged(color color) |
|
126 | \qmlsignal AreaSeries::onBorderColorChanged(color color) | |
126 | Signal is emitted when the line (pen) color has changed to \a color. |
|
127 | Signal is emitted when the line (pen) color has changed to \a color. | |
127 | */ |
|
128 | */ | |
128 |
|
129 | |||
129 | /*! |
|
130 | /*! | |
130 | \fn void QAreaSeries::clicked(const QPointF& point) |
|
131 | \fn void QAreaSeries::clicked(const QPointF& point) | |
131 | \brief Signal is emitted when user clicks the \a point on area chart. |
|
132 | \brief Signal is emitted when user clicks the \a point on area chart. | |
132 | */ |
|
133 | */ | |
133 | /*! |
|
134 | /*! | |
134 | \qmlsignal AreaSeries::onClicked(QPointF point) |
|
135 | \qmlsignal AreaSeries::onClicked(QPointF point) | |
135 | Signal is emitted when user clicks the \a point on area chart. |
|
136 | Signal is emitted when user clicks the \a point on area chart. | |
136 | */ |
|
137 | */ | |
137 |
|
138 | |||
138 | /*! |
|
139 | /*! | |
139 | \fn void QAreaSeries::selected() |
|
140 | \fn void QAreaSeries::selected() | |
140 | The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be |
|
141 | The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be | |
141 | implemented by the user of QAreaSeries API. |
|
142 | implemented by the user of QAreaSeries API. | |
142 | */ |
|
143 | */ | |
143 | /*! |
|
144 | /*! | |
144 | \qmlsignal AreaSeries::onSelected() |
|
145 | \qmlsignal AreaSeries::onSelected() | |
145 | The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be |
|
146 | The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be | |
146 | implemented by the user of AreaSeries API. |
|
147 | implemented by the user of AreaSeries API. | |
147 | */ |
|
148 | */ | |
148 |
|
149 | |||
149 | /*! |
|
150 | /*! | |
150 | \fn void QAreaSeriesPrivate::updated() |
|
151 | \fn void QAreaSeriesPrivate::updated() | |
151 | \brief \internal |
|
152 | \brief \internal | |
152 | */ |
|
153 | */ | |
153 |
|
154 | |||
154 | /*! |
|
155 | /*! | |
155 | Constructs area series object which is a child of \a upperSeries. Area will be spanned between \a |
|
156 | Constructs area series object which is a child of \a upperSeries. Area will be spanned between \a | |
156 | upperSeries line and \a lowerSeries line. If no \a lowerSeries is passed to constructor, area is specified by axis x (y=0) instead. |
|
157 | upperSeries line and \a lowerSeries line. If no \a lowerSeries is passed to constructor, area is specified by axis x (y=0) instead. | |
157 | When series object is added to QChartView or QChart instance ownerships is transferred. |
|
158 | When series object is added to QChartView or QChart instance ownerships is transferred. | |
158 | */ |
|
159 | */ | |
159 | QAreaSeries::QAreaSeries(QLineSeries *upperSeries, QLineSeries *lowerSeries) |
|
160 | QAreaSeries::QAreaSeries(QLineSeries *upperSeries, QLineSeries *lowerSeries) | |
160 | : QAbstractSeries(*new QAreaSeriesPrivate(upperSeries,lowerSeries,this),upperSeries) |
|
161 | : QAbstractSeries(*new QAreaSeriesPrivate(upperSeries,lowerSeries,this),upperSeries) | |
161 | { |
|
162 | { | |
162 | } |
|
163 | } | |
163 |
|
164 | |||
164 | /*! |
|
165 | /*! | |
165 | Constructs area series object without upper or lower series with \a parent object. |
|
166 | Constructs area series object without upper or lower series with \a parent object. | |
166 | */ |
|
167 | */ | |
167 | QAreaSeries::QAreaSeries(QObject *parent) |
|
168 | QAreaSeries::QAreaSeries(QObject *parent) | |
168 | : QAbstractSeries(*new QAreaSeriesPrivate(0, 0, this), parent) |
|
169 | : QAbstractSeries(*new QAreaSeriesPrivate(0, 0, this), parent) | |
169 | { |
|
170 | { | |
170 | } |
|
171 | } | |
171 |
|
172 | |||
172 | /*! |
|
173 | /*! | |
173 | Destroys the object. |
|
174 | Destroys the object. | |
174 | */ |
|
175 | */ | |
175 | QAreaSeries::~QAreaSeries() |
|
176 | QAreaSeries::~QAreaSeries() | |
176 | { |
|
177 | { | |
177 | } |
|
178 | } | |
178 |
|
179 | |||
179 | /*! |
|
180 | /*! | |
180 | Returns QChartSeries::SeriesTypeArea. |
|
181 | Returns QChartSeries::SeriesTypeArea. | |
181 | */ |
|
182 | */ | |
182 | QAbstractSeries::SeriesType QAreaSeries::type() const |
|
183 | QAbstractSeries::SeriesType QAreaSeries::type() const | |
183 | { |
|
184 | { | |
184 | return QAbstractSeries::SeriesTypeArea; |
|
185 | return QAbstractSeries::SeriesTypeArea; | |
185 | } |
|
186 | } | |
186 |
|
187 | |||
187 | /*! |
|
188 | /*! | |
188 | Sets the \a series that is to be used as the area chart upper series. |
|
189 | Sets the \a series that is to be used as the area chart upper series. | |
189 | */ |
|
190 | */ | |
190 | void QAreaSeries::setUpperSeries(QLineSeries* series) |
|
191 | void QAreaSeries::setUpperSeries(QLineSeries* series) | |
191 | { |
|
192 | { | |
192 | Q_D(QAreaSeries); |
|
193 | Q_D(QAreaSeries); | |
193 | d->m_upperSeries = series; |
|
194 | d->m_upperSeries = series; | |
194 | } |
|
195 | } | |
195 |
|
196 | |||
196 | QLineSeries* QAreaSeries::upperSeries() const |
|
197 | QLineSeries* QAreaSeries::upperSeries() const | |
197 | { |
|
198 | { | |
198 | Q_D(const QAreaSeries); |
|
199 | Q_D(const QAreaSeries); | |
199 | return d->m_upperSeries; |
|
200 | return d->m_upperSeries; | |
200 | } |
|
201 | } | |
201 |
|
202 | |||
202 | /*! |
|
203 | /*! | |
203 | Sets the \a series that is to be used as the area chart lower series. |
|
204 | Sets the \a series that is to be used as the area chart lower series. | |
204 | */ |
|
205 | */ | |
205 | void QAreaSeries::setLowerSeries(QLineSeries* series) |
|
206 | void QAreaSeries::setLowerSeries(QLineSeries* series) | |
206 | { |
|
207 | { | |
207 | Q_D(QAreaSeries); |
|
208 | Q_D(QAreaSeries); | |
208 | d->m_lowerSeries = series; |
|
209 | d->m_lowerSeries = series; | |
209 | } |
|
210 | } | |
210 |
|
211 | |||
211 | QLineSeries* QAreaSeries::lowerSeries() const |
|
212 | QLineSeries* QAreaSeries::lowerSeries() const | |
212 | { |
|
213 | { | |
213 | Q_D(const QAreaSeries); |
|
214 | Q_D(const QAreaSeries); | |
214 | return d->m_lowerSeries; |
|
215 | return d->m_lowerSeries; | |
215 | } |
|
216 | } | |
216 |
|
217 | |||
217 | /*! |
|
218 | /*! | |
218 | Sets \a pen used for drawing area outline. |
|
219 | Sets \a pen used for drawing area outline. | |
219 | */ |
|
220 | */ | |
220 | void QAreaSeries::setPen(const QPen &pen) |
|
221 | void QAreaSeries::setPen(const QPen &pen) | |
221 | { |
|
222 | { | |
222 | Q_D(QAreaSeries); |
|
223 | Q_D(QAreaSeries); | |
223 | if (d->m_pen != pen) { |
|
224 | if (d->m_pen != pen) { | |
224 | d->m_pen = pen; |
|
225 | d->m_pen = pen; | |
225 | emit d->updated(); |
|
226 | emit d->updated(); | |
226 | } |
|
227 | } | |
227 | } |
|
228 | } | |
228 |
|
229 | |||
229 | QPen QAreaSeries::pen() const |
|
230 | QPen QAreaSeries::pen() const | |
230 | { |
|
231 | { | |
231 | Q_D(const QAreaSeries); |
|
232 | Q_D(const QAreaSeries); | |
232 | return d->m_pen; |
|
233 | return d->m_pen; | |
233 | } |
|
234 | } | |
234 |
|
235 | |||
235 | /*! |
|
236 | /*! | |
236 | Sets \a brush used for filling the area. |
|
237 | Sets \a brush used for filling the area. | |
237 | */ |
|
238 | */ | |
238 | void QAreaSeries::setBrush(const QBrush &brush) |
|
239 | void QAreaSeries::setBrush(const QBrush &brush) | |
239 | { |
|
240 | { | |
240 | Q_D(QAreaSeries); |
|
241 | Q_D(QAreaSeries); | |
241 | if (d->m_brush != brush) { |
|
242 | if (d->m_brush != brush) { | |
242 | d->m_brush = brush; |
|
243 | d->m_brush = brush; | |
243 | emit d->updated(); |
|
244 | emit d->updated(); | |
244 | } |
|
245 | } | |
245 | } |
|
246 | } | |
246 |
|
247 | |||
247 | QBrush QAreaSeries::brush() const |
|
248 | QBrush QAreaSeries::brush() const | |
248 | { |
|
249 | { | |
249 | Q_D(const QAreaSeries); |
|
250 | Q_D(const QAreaSeries); | |
250 | return d->m_brush; |
|
251 | return d->m_brush; | |
251 | } |
|
252 | } | |
252 |
|
253 | |||
253 | void QAreaSeries::setColor(const QColor &color) |
|
254 | void QAreaSeries::setColor(const QColor &color) | |
254 | { |
|
255 | { | |
255 | QBrush b = brush(); |
|
256 | QBrush b = brush(); | |
256 | if (b.color() != color) { |
|
257 | if (b.color() != color) { | |
257 | b.setColor(color); |
|
258 | b.setColor(color); | |
258 | setBrush(b); |
|
259 | setBrush(b); | |
259 | emit colorChanged(color); |
|
260 | emit colorChanged(color); | |
260 | } |
|
261 | } | |
261 | } |
|
262 | } | |
262 |
|
263 | |||
263 | QColor QAreaSeries::color() const |
|
264 | QColor QAreaSeries::color() const | |
264 | { |
|
265 | { | |
265 | return brush().color(); |
|
266 | return brush().color(); | |
266 | } |
|
267 | } | |
267 |
|
268 | |||
268 | void QAreaSeries::setBorderColor(const QColor &color) |
|
269 | void QAreaSeries::setBorderColor(const QColor &color) | |
269 | { |
|
270 | { | |
270 | QPen p = pen(); |
|
271 | QPen p = pen(); | |
271 | if (p.color() != color) { |
|
272 | if (p.color() != color) { | |
272 | p.setColor(color); |
|
273 | p.setColor(color); | |
273 | setPen(p); |
|
274 | setPen(p); | |
274 | emit borderColorChanged(color); |
|
275 | emit borderColorChanged(color); | |
275 | } |
|
276 | } | |
276 | } |
|
277 | } | |
277 |
|
278 | |||
278 | QColor QAreaSeries::borderColor() const |
|
279 | QColor QAreaSeries::borderColor() const | |
279 | { |
|
280 | { | |
280 | return pen().color(); |
|
281 | return pen().color(); | |
281 | } |
|
282 | } | |
282 |
|
283 | |||
283 | /*! |
|
284 | /*! | |
284 | Sets if data points are \a visible and should be drawn on line. |
|
285 | Sets if data points are \a visible and should be drawn on line. | |
285 | */ |
|
286 | */ | |
286 | void QAreaSeries::setPointsVisible(bool visible) |
|
287 | void QAreaSeries::setPointsVisible(bool visible) | |
287 | { |
|
288 | { | |
288 | Q_D(QAreaSeries); |
|
289 | Q_D(QAreaSeries); | |
289 | if (d->m_pointsVisible != visible) { |
|
290 | if (d->m_pointsVisible != visible) { | |
290 | d->m_pointsVisible = visible; |
|
291 | d->m_pointsVisible = visible; | |
291 | emit d->updated(); |
|
292 | emit d->updated(); | |
292 | } |
|
293 | } | |
293 | } |
|
294 | } | |
294 |
|
295 | |||
295 | /*! |
|
296 | /*! | |
296 | Returns if the points are drawn for this series. |
|
297 | Returns if the points are drawn for this series. | |
297 | \sa setPointsVisible() |
|
298 | \sa setPointsVisible() | |
298 | */ |
|
299 | */ | |
299 | bool QAreaSeries::pointsVisible() const |
|
300 | bool QAreaSeries::pointsVisible() const | |
300 | { |
|
301 | { | |
301 | Q_D(const QAreaSeries); |
|
302 | Q_D(const QAreaSeries); | |
302 | return d->m_pointsVisible; |
|
303 | return d->m_pointsVisible; | |
303 | } |
|
304 | } | |
304 |
|
305 | |||
305 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
306 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
306 |
|
307 | |||
307 | QAreaSeriesPrivate::QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries,QAreaSeries* q) : |
|
308 | QAreaSeriesPrivate::QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries,QAreaSeries* q) : | |
308 | QAbstractSeriesPrivate(q), |
|
309 | QAbstractSeriesPrivate(q), | |
309 | m_upperSeries(upperSeries), |
|
310 | m_upperSeries(upperSeries), | |
310 | m_lowerSeries(lowerSeries), |
|
311 | m_lowerSeries(lowerSeries), | |
311 | m_pointsVisible(false) |
|
312 | m_pointsVisible(false) | |
312 | { |
|
313 | { | |
313 | } |
|
314 | } | |
314 |
|
315 | |||
315 | void QAreaSeriesPrivate::scaleDomain(Domain& domain) |
|
316 | void QAreaSeriesPrivate::scaleDomain(Domain& domain) | |
316 | { |
|
317 | { | |
317 | Q_Q(QAreaSeries); |
|
318 | Q_Q(QAreaSeries); | |
318 |
|
319 | |||
319 | qreal minX(domain.minX()); |
|
320 | qreal minX(domain.minX()); | |
320 | qreal minY(domain.minY()); |
|
321 | qreal minY(domain.minY()); | |
321 | qreal maxX(domain.maxX()); |
|
322 | qreal maxX(domain.maxX()); | |
322 | qreal maxY(domain.maxY()); |
|
323 | qreal maxY(domain.maxY()); | |
323 | int tickXCount(domain.tickXCount()); |
|
324 | int tickXCount(domain.tickXCount()); | |
324 | int tickYCount(domain.tickYCount()); |
|
325 | int tickYCount(domain.tickYCount()); | |
325 |
|
326 | |||
326 | QLineSeries* upperSeries = q->upperSeries(); |
|
327 | QLineSeries* upperSeries = q->upperSeries(); | |
327 | QLineSeries* lowerSeries = q->lowerSeries(); |
|
328 | QLineSeries* lowerSeries = q->lowerSeries(); | |
328 |
|
329 | |||
329 | const QList<QPointF>& points = upperSeries->points(); |
|
330 | const QList<QPointF>& points = upperSeries->points(); | |
330 |
|
331 | |||
331 | for (int i = 0; i < points.count(); i++) |
|
332 | for (int i = 0; i < points.count(); i++) | |
332 | { |
|
333 | { | |
333 | qreal x = points[i].x(); |
|
334 | qreal x = points[i].x(); | |
334 | qreal y = points[i].y(); |
|
335 | qreal y = points[i].y(); | |
335 | minX = qMin(minX, x); |
|
336 | minX = qMin(minX, x); | |
336 | minY = qMin(minY, y); |
|
337 | minY = qMin(minY, y); | |
337 | maxX = qMax(maxX, x); |
|
338 | maxX = qMax(maxX, x); | |
338 | maxY = qMax(maxY, y); |
|
339 | maxY = qMax(maxY, y); | |
339 | } |
|
340 | } | |
340 | if(lowerSeries) { |
|
341 | if(lowerSeries) { | |
341 |
|
342 | |||
342 | const QList<QPointF>& points = lowerSeries->points(); |
|
343 | const QList<QPointF>& points = lowerSeries->points(); | |
343 |
|
344 | |||
344 | for (int i = 0; i < points.count(); i++) |
|
345 | for (int i = 0; i < points.count(); i++) | |
345 | { |
|
346 | { | |
346 | qreal x = points[i].x(); |
|
347 | qreal x = points[i].x(); | |
347 | qreal y = points[i].y(); |
|
348 | qreal y = points[i].y(); | |
348 | minX = qMin(minX, x); |
|
349 | minX = qMin(minX, x); | |
349 | minY = qMin(minY, y); |
|
350 | minY = qMin(minY, y); | |
350 | maxX = qMax(maxX, x); |
|
351 | maxX = qMax(maxX, x); | |
351 | maxY = qMax(maxY, y); |
|
352 | maxY = qMax(maxY, y); | |
352 | }} |
|
353 | }} | |
353 |
|
354 | |||
354 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
355 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); | |
355 | } |
|
356 | } | |
356 |
|
357 | |||
357 | Chart* QAreaSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
358 | Chart* QAreaSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
358 | { |
|
359 | { | |
359 | Q_Q(QAreaSeries); |
|
360 | Q_Q(QAreaSeries); | |
360 |
|
361 | |||
361 | AreaChartItem* area = new AreaChartItem(q,presenter); |
|
362 | AreaChartItem* area = new AreaChartItem(q,presenter); | |
362 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
363 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
363 | area->upperLineItem()->setAnimator(presenter->animator()); |
|
364 | area->upperLineItem()->setAnimator(presenter->animator()); | |
364 | area->upperLineItem()->setAnimation(new XYAnimation(area->upperLineItem())); |
|
365 | area->upperLineItem()->setAnimation(new XYAnimation(area->upperLineItem())); | |
365 | if(q->lowerSeries()) { |
|
366 | if(q->lowerSeries()) { | |
366 | area->lowerLineItem()->setAnimator(presenter->animator()); |
|
367 | area->lowerLineItem()->setAnimator(presenter->animator()); | |
367 | area->lowerLineItem()->setAnimation(new XYAnimation(area->lowerLineItem())); |
|
368 | area->lowerLineItem()->setAnimation(new XYAnimation(area->lowerLineItem())); | |
368 | } |
|
369 | } | |
369 | } |
|
370 | } | |
370 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
371 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
371 | return area; |
|
372 | return area; | |
372 | } |
|
373 | } | |
373 |
|
374 | |||
374 | QList<LegendMarker*> QAreaSeriesPrivate::createLegendMarker(QLegend* legend) |
|
375 | QList<LegendMarker*> QAreaSeriesPrivate::createLegendMarker(QLegend* legend) | |
375 | { |
|
376 | { | |
376 | Q_Q(QAreaSeries); |
|
377 | Q_Q(QAreaSeries); | |
377 | QList<LegendMarker*> list; |
|
378 | QList<LegendMarker*> list; | |
378 | return list << new AreaLegendMarker(q,legend); |
|
379 | return list << new AreaLegendMarker(q,legend); | |
379 | } |
|
380 | } | |
380 |
|
381 | |||
|
382 | ||||
|
383 | QAbstractAxis* QAreaSeriesPrivate::createAxisX() | |||
|
384 | { | |||
|
385 | // TODO: parent? | |||
|
386 | return new QValuesAxis(this); | |||
|
387 | } | |||
|
388 | ||||
|
389 | QAbstractAxis* QAreaSeriesPrivate::createAxisY() | |||
|
390 | { | |||
|
391 | // TODO: parent? | |||
|
392 | return new QValuesAxis(this); | |||
|
393 | } | |||
|
394 | ||||
381 | #include "moc_qareaseries.cpp" |
|
395 | #include "moc_qareaseries.cpp" | |
382 | #include "moc_qareaseries_p.cpp" |
|
396 | #include "moc_qareaseries_p.cpp" | |
383 |
|
397 | |||
384 | QTCOMMERCIALCHART_END_NAMESPACE |
|
398 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,65 +1,67 | |||||
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 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef QAREASERIES_P_H |
|
30 | #ifndef QAREASERIES_P_H | |
31 | #define QAREASERIES_P_H |
|
31 | #define QAREASERIES_P_H | |
32 |
|
32 | |||
33 | #include "qabstractseries_p.h" |
|
33 | #include "qabstractseries_p.h" | |
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
36 |
|
36 | |||
37 | class QAreaSeries; |
|
37 | class QAreaSeries; | |
38 |
|
38 | |||
39 | class QAreaSeriesPrivate: public QAbstractSeriesPrivate |
|
39 | class QAreaSeriesPrivate: public QAbstractSeriesPrivate | |
40 | { |
|
40 | { | |
41 | Q_OBJECT |
|
41 | Q_OBJECT | |
42 |
|
42 | |||
43 | public: |
|
43 | public: | |
44 | QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries,QAreaSeries* q); |
|
44 | QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries,QAreaSeries* q); | |
45 |
|
45 | |||
46 | void scaleDomain(Domain& domain); |
|
46 | void scaleDomain(Domain& domain); | |
47 | Chart* createGraphics(ChartPresenter* presenter); |
|
47 | Chart* createGraphics(ChartPresenter* presenter); | |
48 | QList<LegendMarker*> createLegendMarker(QLegend* legend); |
|
48 | QList<LegendMarker*> createLegendMarker(QLegend* legend); | |
|
49 | QAbstractAxis* createAxisX(); | |||
|
50 | QAbstractAxis* createAxisY(); | |||
49 |
|
51 | |||
50 | Q_SIGNALS: |
|
52 | Q_SIGNALS: | |
51 | void updated(); |
|
53 | void updated(); | |
52 |
|
54 | |||
53 | protected: |
|
55 | protected: | |
54 | QBrush m_brush; |
|
56 | QBrush m_brush; | |
55 | QPen m_pen; |
|
57 | QPen m_pen; | |
56 | QLineSeries* m_upperSeries; |
|
58 | QLineSeries* m_upperSeries; | |
57 | QLineSeries* m_lowerSeries; |
|
59 | QLineSeries* m_lowerSeries; | |
58 | bool m_pointsVisible; |
|
60 | bool m_pointsVisible; | |
59 | private: |
|
61 | private: | |
60 | Q_DECLARE_PUBLIC(QAreaSeries); |
|
62 | Q_DECLARE_PUBLIC(QAreaSeries); | |
61 | }; |
|
63 | }; | |
62 |
|
64 | |||
63 | QTCOMMERCIALCHART_END_NAMESPACE |
|
65 | QTCOMMERCIALCHART_END_NAMESPACE | |
64 |
|
66 | |||
65 | #endif |
|
67 | #endif |
@@ -1,720 +1,733 | |||||
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 "qbarseries.h" |
|
21 | #include "qbarseries.h" | |
22 | #include "qbarseries_p.h" |
|
22 | #include "qbarseries_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 "chartanimator_p.h" |
|
29 | #include "chartanimator_p.h" | |
|
30 | #include "qvaluesaxis.h" | |||
30 |
|
31 | |||
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
32 |
|
33 | |||
33 | /*! |
|
34 | /*! | |
34 | \class QBarSeries |
|
35 | \class QBarSeries | |
35 | \brief Series for creating a bar chart |
|
36 | \brief Series for creating a bar chart | |
36 | \mainclass |
|
37 | \mainclass | |
37 |
|
38 | |||
38 | QBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to |
|
39 | QBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to | |
39 | 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 | |
40 | 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 | |
41 | shows the x-values. |
|
42 | shows the x-values. | |
42 |
|
43 | |||
43 | 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. | |
44 | \image examples_barchart.png |
|
45 | \image examples_barchart.png | |
45 |
|
46 | |||
46 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries |
|
47 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries | |
47 | */ |
|
48 | */ | |
48 | /*! |
|
49 | /*! | |
49 | \qmlclass BarSeries QBarSeries |
|
50 | \qmlclass BarSeries QBarSeries | |
50 | \inherits AbstractSeries |
|
51 | \inherits AbstractSeries | |
51 |
|
52 | |||
52 | The following QML shows how to create a simple bar chart: |
|
53 | The following QML shows how to create a simple bar chart: | |
53 | \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1 |
|
54 | \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1 | |
54 |
|
55 | |||
55 | \beginfloatleft |
|
56 | \beginfloatleft | |
56 | \image demos_qmlchart6.png |
|
57 | \image demos_qmlchart6.png | |
57 | \endfloat |
|
58 | \endfloat | |
58 | \clearfloat |
|
59 | \clearfloat | |
59 | */ |
|
60 | */ | |
60 |
|
61 | |||
61 | /*! |
|
62 | /*! | |
62 | \property QBarSeries::barWidth |
|
63 | \property QBarSeries::barWidth | |
63 | 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 | |
64 | 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 | |
65 | 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. | |
66 | Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar. |
|
67 | Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar. | |
67 | \sa QGroupedBarSeries |
|
68 | \sa QGroupedBarSeries | |
68 | */ |
|
69 | */ | |
69 | /*! |
|
70 | /*! | |
70 | \qmlproperty real BarSeries::barWidth |
|
71 | \qmlproperty real BarSeries::barWidth | |
71 | 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 | |
72 | 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 | |
73 | 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. | |
74 | Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar. |
|
75 | Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar. | |
75 | */ |
|
76 | */ | |
76 |
|
77 | |||
77 | /*! |
|
78 | /*! | |
78 | \property QBarSeries::count |
|
79 | \property QBarSeries::count | |
79 | Holds the number of sets in series. |
|
80 | Holds the number of sets in series. | |
80 | */ |
|
81 | */ | |
81 | /*! |
|
82 | /*! | |
82 | \qmlproperty int BarSeries::count |
|
83 | \qmlproperty int BarSeries::count | |
83 | Holds the number of sets in series. |
|
84 | Holds the number of sets in series. | |
84 | */ |
|
85 | */ | |
85 |
|
86 | |||
86 | /*! |
|
87 | /*! | |
87 | \property QBarSeries::labelsVisible |
|
88 | \property QBarSeries::labelsVisible | |
88 | Defines the visibility of the labels in series |
|
89 | Defines the visibility of the labels in series | |
89 | */ |
|
90 | */ | |
90 | /*! |
|
91 | /*! | |
91 | \qmlproperty bool BarSeries::labelsVisible |
|
92 | \qmlproperty bool BarSeries::labelsVisible | |
92 | Defines the visibility of the labels in series |
|
93 | Defines the visibility of the labels in series | |
93 | */ |
|
94 | */ | |
94 |
|
95 | |||
95 | /*! |
|
96 | /*! | |
96 | \fn void QBarSeries::clicked(QBarSet *barset, int index) |
|
97 | \fn void QBarSeries::clicked(QBarSet *barset, int index) | |
97 | 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. | |
98 | Clicked bar inside set is indexed by \a index |
|
99 | Clicked bar inside set is indexed by \a index | |
99 | */ |
|
100 | */ | |
100 | /*! |
|
101 | /*! | |
101 | \qmlsignal BarSeries::onClicked(BarSet barset, int index) |
|
102 | \qmlsignal BarSeries::onClicked(BarSet barset, int index) | |
102 | 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. | |
103 | Clicked bar inside set is indexed by \a index |
|
104 | Clicked bar inside set is indexed by \a index | |
104 | */ |
|
105 | */ | |
105 |
|
106 | |||
106 | /*! |
|
107 | /*! | |
107 | \fn void QBarSeries::hovered(QBarSet* barset, bool status) |
|
108 | \fn void QBarSeries::hovered(QBarSet* barset, bool status) | |
108 |
|
109 | |||
109 | 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. | |
110 | Parameter \a barset is the pointer of barset, where hover happened. |
|
111 | Parameter \a barset is the pointer of barset, where hover happened. | |
111 | 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. | |
112 | */ |
|
113 | */ | |
113 | /*! |
|
114 | /*! | |
114 | \qmlsignal BarSeries::onHovered(BarSet barset, bool status) |
|
115 | \qmlsignal BarSeries::onHovered(BarSet barset, bool status) | |
115 |
|
116 | |||
116 | 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. | |
117 | Parameter \a barset is the pointer of barset, where hover happened. |
|
118 | Parameter \a barset is the pointer of barset, where hover happened. | |
118 | 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. | |
119 | */ |
|
120 | */ | |
120 |
|
121 | |||
121 | /*! |
|
122 | /*! | |
122 | \fn void QBarSeries::countChanged() |
|
123 | \fn void QBarSeries::countChanged() | |
123 | 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. | |
124 | */ |
|
125 | */ | |
125 | /*! |
|
126 | /*! | |
126 | \qmlsignal BarSeries::onCountChanged() |
|
127 | \qmlsignal BarSeries::onCountChanged() | |
127 | 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. | |
128 | */ |
|
129 | */ | |
129 |
|
130 | |||
130 | /*! |
|
131 | /*! | |
131 | \fn void QBarSeries::labelsVisibleChanged() |
|
132 | \fn void QBarSeries::labelsVisibleChanged() | |
132 | This signal is emitted when labels visibility have changed. |
|
133 | This signal is emitted when labels visibility have changed. | |
133 | \sa isLabelsVisible(), setLabelsVisible() |
|
134 | \sa isLabelsVisible(), setLabelsVisible() | |
134 | */ |
|
135 | */ | |
135 |
|
136 | |||
136 | /*! |
|
137 | /*! | |
137 | \fn void QBarSeries::barsetsAdded(QList<QBarSet*> sets) |
|
138 | \fn void QBarSeries::barsetsAdded(QList<QBarSet*> sets) | |
138 | 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. | |
139 | \sa append(), insert() |
|
140 | \sa append(), insert() | |
140 | */ |
|
141 | */ | |
141 | /*! |
|
142 | /*! | |
142 | \qmlsignal BarSeries::onAdded(BarSet barset) |
|
143 | \qmlsignal BarSeries::onAdded(BarSet barset) | |
143 | Emitted when \a barset has been added to the series. |
|
144 | Emitted when \a barset has been added to the series. | |
144 | */ |
|
145 | */ | |
145 |
|
146 | |||
146 | /*! |
|
147 | /*! | |
147 | \fn void QBarSeries::barsetsRemoved(QList<QBarSet*> sets) |
|
148 | \fn void QBarSeries::barsetsRemoved(QList<QBarSet*> sets) | |
148 | 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. | |
149 | \sa remove() |
|
150 | \sa remove() | |
150 | */ |
|
151 | */ | |
151 | /*! |
|
152 | /*! | |
152 | \qmlsignal BarSeries::onRemoved(BarSet barset) |
|
153 | \qmlsignal BarSeries::onRemoved(BarSet barset) | |
153 | Emitted when \a barset has been removed from the series. |
|
154 | Emitted when \a barset has been removed from the series. | |
154 | */ |
|
155 | */ | |
155 |
|
156 | |||
156 | /*! |
|
157 | /*! | |
157 | \qmlmethod BarSet BarSeries::at(int index) |
|
158 | \qmlmethod BarSet BarSeries::at(int index) | |
158 | 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. | |
159 | */ |
|
160 | */ | |
160 |
|
161 | |||
161 | /*! |
|
162 | /*! | |
162 | \qmlmethod BarSet BarSeries::append(string label, VariantList values) |
|
163 | \qmlmethod BarSet BarSeries::append(string label, VariantList values) | |
163 | 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. | |
164 | For example: |
|
165 | For example: | |
165 | \code |
|
166 | \code | |
166 | 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]); | |
167 | 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)]); | |
168 | \endcode |
|
169 | \endcode | |
169 | */ |
|
170 | */ | |
170 |
|
171 | |||
171 | /*! |
|
172 | /*! | |
172 | \qmlmethod BarSet BarSeries::insert(int index, string label, VariantList values) |
|
173 | \qmlmethod BarSet BarSeries::insert(int index, string label, VariantList values) | |
173 | 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. | |
174 | 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 | |
175 | appended. |
|
176 | appended. | |
176 | \sa BarSeries::append() |
|
177 | \sa BarSeries::append() | |
177 | */ |
|
178 | */ | |
178 |
|
179 | |||
179 | /*! |
|
180 | /*! | |
180 | \qmlmethod bool BarSeries::remove(BarSet barset) |
|
181 | \qmlmethod bool BarSeries::remove(BarSet barset) | |
181 | Removes the barset from the series. Returns true if successfull, false otherwise. |
|
182 | Removes the barset from the series. Returns true if successfull, false otherwise. | |
182 | */ |
|
183 | */ | |
183 |
|
184 | |||
184 | /*! |
|
185 | /*! | |
185 | \qmlmethod BarSeries::clear() |
|
186 | \qmlmethod BarSeries::clear() | |
186 | Removes all barsets from the series. |
|
187 | Removes all barsets from the series. | |
187 | */ |
|
188 | */ | |
188 |
|
189 | |||
189 | /*! |
|
190 | /*! | |
190 | Constructs empty QBarSeries. |
|
191 | Constructs empty QBarSeries. | |
191 | QBarSeries is QObject which is a child of a \a parent. |
|
192 | QBarSeries is QObject which is a child of a \a parent. | |
192 | */ |
|
193 | */ | |
193 | QBarSeries::QBarSeries(QObject *parent) : |
|
194 | QBarSeries::QBarSeries(QObject *parent) : | |
194 | QAbstractSeries(*new QBarSeriesPrivate(this),parent) |
|
195 | QAbstractSeries(*new QBarSeriesPrivate(this),parent) | |
195 | { |
|
196 | { | |
196 | } |
|
197 | } | |
197 |
|
198 | |||
198 | /*! |
|
199 | /*! | |
199 | Destructs barseries and owned barsets. |
|
200 | Destructs barseries and owned barsets. | |
200 | */ |
|
201 | */ | |
201 | QBarSeries::~QBarSeries() |
|
202 | QBarSeries::~QBarSeries() | |
202 | { |
|
203 | { | |
203 | Q_D(QBarSeries); |
|
204 | Q_D(QBarSeries); | |
204 | if(d->m_dataset){ |
|
205 | if(d->m_dataset){ | |
205 | d->m_dataset->removeSeries(this); |
|
206 | d->m_dataset->removeSeries(this); | |
206 | } |
|
207 | } | |
207 | } |
|
208 | } | |
208 |
|
209 | |||
209 | /*! |
|
210 | /*! | |
210 | \internal |
|
211 | \internal | |
211 | */ |
|
212 | */ | |
212 | QBarSeries::QBarSeries(QBarSeriesPrivate &d, QObject *parent) : |
|
213 | QBarSeries::QBarSeries(QBarSeriesPrivate &d, QObject *parent) : | |
213 | QAbstractSeries(d,parent) |
|
214 | QAbstractSeries(d,parent) | |
214 | { |
|
215 | { | |
215 | } |
|
216 | } | |
216 |
|
217 | |||
217 | /*! |
|
218 | /*! | |
218 | Returns the type of series. Derived classes override this. |
|
219 | Returns the type of series. Derived classes override this. | |
219 | */ |
|
220 | */ | |
220 | QAbstractSeries::SeriesType QBarSeries::type() const |
|
221 | QAbstractSeries::SeriesType QBarSeries::type() const | |
221 | { |
|
222 | { | |
222 | return QAbstractSeries::SeriesTypeBar; |
|
223 | return QAbstractSeries::SeriesTypeBar; | |
223 | } |
|
224 | } | |
224 |
|
225 | |||
225 | /*! |
|
226 | /*! | |
226 | 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 |
|
227 | 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 | |
227 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
228 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen | |
228 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
229 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. | |
229 | Note that with \link QGroupedBarSeries \endlink this value means the width of one group of bars instead of just one bar. |
|
230 | Note that with \link QGroupedBarSeries \endlink this value means the width of one group of bars instead of just one bar. | |
230 | */ |
|
231 | */ | |
231 | void QBarSeries::setBarWidth(qreal width) |
|
232 | void QBarSeries::setBarWidth(qreal width) | |
232 | { |
|
233 | { | |
233 | Q_D(QBarSeries); |
|
234 | Q_D(QBarSeries); | |
234 | d->setBarWidth(width); |
|
235 | d->setBarWidth(width); | |
235 | } |
|
236 | } | |
236 |
|
237 | |||
237 | /*! |
|
238 | /*! | |
238 | Returns the width of the bars of the series. |
|
239 | Returns the width of the bars of the series. | |
239 | \sa setBarWidth() |
|
240 | \sa setBarWidth() | |
240 | */ |
|
241 | */ | |
241 | qreal QBarSeries::barWidth() const |
|
242 | qreal QBarSeries::barWidth() const | |
242 | { |
|
243 | { | |
243 | Q_D(const QBarSeries); |
|
244 | Q_D(const QBarSeries); | |
244 | return d->barWidth(); |
|
245 | return d->barWidth(); | |
245 | } |
|
246 | } | |
246 |
|
247 | |||
247 | /*! |
|
248 | /*! | |
248 | 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. |
|
249 | 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. | |
249 | Returns true, if appending succeeded. |
|
250 | Returns true, if appending succeeded. | |
250 | */ |
|
251 | */ | |
251 | bool QBarSeries::append(QBarSet *set) |
|
252 | bool QBarSeries::append(QBarSet *set) | |
252 | { |
|
253 | { | |
253 | Q_D(QBarSeries); |
|
254 | Q_D(QBarSeries); | |
254 | bool success = d->append(set); |
|
255 | bool success = d->append(set); | |
255 | if (success) { |
|
256 | if (success) { | |
256 | QList<QBarSet*> sets; |
|
257 | QList<QBarSet*> sets; | |
257 | sets.append(set); |
|
258 | sets.append(set); | |
258 | emit barsetsAdded(sets); |
|
259 | emit barsetsAdded(sets); | |
259 | emit countChanged(); |
|
260 | emit countChanged(); | |
260 | } |
|
261 | } | |
261 | return success; |
|
262 | return success; | |
262 | } |
|
263 | } | |
263 |
|
264 | |||
264 | /*! |
|
265 | /*! | |
265 | Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set. |
|
266 | Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set. | |
266 | Returns true, if set was removed. |
|
267 | Returns true, if set was removed. | |
267 | */ |
|
268 | */ | |
268 | bool QBarSeries::remove(QBarSet *set) |
|
269 | bool QBarSeries::remove(QBarSet *set) | |
269 | { |
|
270 | { | |
270 | Q_D(QBarSeries); |
|
271 | Q_D(QBarSeries); | |
271 | bool success = d->remove(set); |
|
272 | bool success = d->remove(set); | |
272 | if (success) { |
|
273 | if (success) { | |
273 | QList<QBarSet*> sets; |
|
274 | QList<QBarSet*> sets; | |
274 | sets.append(set); |
|
275 | sets.append(set); | |
275 | emit barsetsRemoved(sets); |
|
276 | emit barsetsRemoved(sets); | |
276 | emit countChanged(); |
|
277 | emit countChanged(); | |
277 | } |
|
278 | } | |
278 | return success; |
|
279 | return success; | |
279 | } |
|
280 | } | |
280 |
|
281 | |||
281 | /*! |
|
282 | /*! | |
282 | Adds a list of barsets to series. Takes ownership of \a sets. |
|
283 | Adds a list of barsets to series. Takes ownership of \a sets. | |
283 | Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series, |
|
284 | Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series, | |
284 | nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended |
|
285 | nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended | |
285 | and function returns false. |
|
286 | and function returns false. | |
286 | */ |
|
287 | */ | |
287 | bool QBarSeries::append(QList<QBarSet* > sets) |
|
288 | bool QBarSeries::append(QList<QBarSet* > sets) | |
288 | { |
|
289 | { | |
289 | Q_D(QBarSeries); |
|
290 | Q_D(QBarSeries); | |
290 | bool success = d->append(sets); |
|
291 | bool success = d->append(sets); | |
291 | if (success) { |
|
292 | if (success) { | |
292 | emit barsetsAdded(sets); |
|
293 | emit barsetsAdded(sets); | |
293 | emit countChanged(); |
|
294 | emit countChanged(); | |
294 | } |
|
295 | } | |
295 | return success; |
|
296 | return success; | |
296 | } |
|
297 | } | |
297 |
|
298 | |||
298 | /*! |
|
299 | /*! | |
299 | 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. |
|
300 | 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. | |
300 | Returns true, if inserting succeeded. |
|
301 | Returns true, if inserting succeeded. | |
301 |
|
302 | |||
302 | */ |
|
303 | */ | |
303 | bool QBarSeries::insert(int index, QBarSet *set) |
|
304 | bool QBarSeries::insert(int index, QBarSet *set) | |
304 | { |
|
305 | { | |
305 | Q_D(QBarSeries); |
|
306 | Q_D(QBarSeries); | |
306 | bool success = d->insert(index, set); |
|
307 | bool success = d->insert(index, set); | |
307 | if (success) { |
|
308 | if (success) { | |
308 | QList<QBarSet*> sets; |
|
309 | QList<QBarSet*> sets; | |
309 | sets.append(set); |
|
310 | sets.append(set); | |
310 | emit barsetsAdded(sets); |
|
311 | emit barsetsAdded(sets); | |
311 | emit countChanged(); |
|
312 | emit countChanged(); | |
312 | } |
|
313 | } | |
313 | return success; |
|
314 | return success; | |
314 | } |
|
315 | } | |
315 |
|
316 | |||
316 | /*! |
|
317 | /*! | |
317 | Removes all of the bar sets from the series |
|
318 | Removes all of the bar sets from the series | |
318 | */ |
|
319 | */ | |
319 | void QBarSeries::clear() |
|
320 | void QBarSeries::clear() | |
320 | { |
|
321 | { | |
321 | Q_D(QBarSeries); |
|
322 | Q_D(QBarSeries); | |
322 | QList<QBarSet *> sets = barSets(); |
|
323 | QList<QBarSet *> sets = barSets(); | |
323 | bool success = d->remove(sets); |
|
324 | bool success = d->remove(sets); | |
324 | if (success) { |
|
325 | if (success) { | |
325 | emit barsetsRemoved(sets); |
|
326 | emit barsetsRemoved(sets); | |
326 | emit countChanged(); |
|
327 | emit countChanged(); | |
327 | } |
|
328 | } | |
328 | } |
|
329 | } | |
329 |
|
330 | |||
330 | /*! |
|
331 | /*! | |
331 | Returns number of sets in series. |
|
332 | Returns number of sets in series. | |
332 | */ |
|
333 | */ | |
333 | int QBarSeries::count() const |
|
334 | int QBarSeries::count() const | |
334 | { |
|
335 | { | |
335 | Q_D(const QBarSeries); |
|
336 | Q_D(const QBarSeries); | |
336 | return d->m_barSets.count(); |
|
337 | return d->m_barSets.count(); | |
337 | } |
|
338 | } | |
338 |
|
339 | |||
339 | /*! |
|
340 | /*! | |
340 | Returns a list of sets in series. Keeps ownership of sets. |
|
341 | Returns a list of sets in series. Keeps ownership of sets. | |
341 | */ |
|
342 | */ | |
342 | QList<QBarSet*> QBarSeries::barSets() const |
|
343 | QList<QBarSet*> QBarSeries::barSets() const | |
343 | { |
|
344 | { | |
344 | Q_D(const QBarSeries); |
|
345 | Q_D(const QBarSeries); | |
345 | return d->m_barSets; |
|
346 | return d->m_barSets; | |
346 | } |
|
347 | } | |
347 |
|
348 | |||
348 | /*! |
|
349 | /*! | |
349 | Sets the visibility of labels in series to \a visible |
|
350 | Sets the visibility of labels in series to \a visible | |
350 | */ |
|
351 | */ | |
351 | void QBarSeries::setLabelsVisible(bool visible) |
|
352 | void QBarSeries::setLabelsVisible(bool visible) | |
352 | { |
|
353 | { | |
353 | Q_D(QBarSeries); |
|
354 | Q_D(QBarSeries); | |
354 | if (d->m_labelsVisible != visible) { |
|
355 | if (d->m_labelsVisible != visible) { | |
355 | d->setLabelsVisible(visible); |
|
356 | d->setLabelsVisible(visible); | |
356 | emit labelsVisibleChanged(); |
|
357 | emit labelsVisibleChanged(); | |
357 | } |
|
358 | } | |
358 | } |
|
359 | } | |
359 |
|
360 | |||
360 | /*! |
|
361 | /*! | |
361 | Returns the visibility of labels |
|
362 | Returns the visibility of labels | |
362 | */ |
|
363 | */ | |
363 | bool QBarSeries::isLabelsVisible() const |
|
364 | bool QBarSeries::isLabelsVisible() const | |
364 | { |
|
365 | { | |
365 | Q_D(const QBarSeries); |
|
366 | Q_D(const QBarSeries); | |
366 | return d->m_labelsVisible; |
|
367 | return d->m_labelsVisible; | |
367 | } |
|
368 | } | |
368 |
|
369 | |||
369 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
370 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
370 |
|
371 | |||
371 | QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) : |
|
372 | QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) : | |
372 | QAbstractSeriesPrivate(q), |
|
373 | QAbstractSeriesPrivate(q), | |
373 | m_barWidth(0.5), // Default value is 50% of category width |
|
374 | m_barWidth(0.5), // Default value is 50% of category width | |
374 | m_labelsVisible(false), |
|
375 | m_labelsVisible(false), | |
375 | m_visible(true) |
|
376 | m_visible(true) | |
376 | { |
|
377 | { | |
377 | } |
|
378 | } | |
378 |
|
379 | |||
379 | int QBarSeriesPrivate::categoryCount() const |
|
380 | int QBarSeriesPrivate::categoryCount() const | |
380 | { |
|
381 | { | |
381 | // No categories defined. return count of longest set. |
|
382 | // No categories defined. return count of longest set. | |
382 | int count = 0; |
|
383 | int count = 0; | |
383 | for (int i=0; i<m_barSets.count(); i++) { |
|
384 | for (int i=0; i<m_barSets.count(); i++) { | |
384 | if (m_barSets.at(i)->count() > count) { |
|
385 | if (m_barSets.at(i)->count() > count) { | |
385 | count = m_barSets.at(i)->count(); |
|
386 | count = m_barSets.at(i)->count(); | |
386 | } |
|
387 | } | |
387 | } |
|
388 | } | |
388 |
|
389 | |||
389 | return count; |
|
390 | return count; | |
390 | } |
|
391 | } | |
391 |
|
392 | |||
392 | void QBarSeriesPrivate::setBarWidth(qreal width) |
|
393 | void QBarSeriesPrivate::setBarWidth(qreal width) | |
393 | { |
|
394 | { | |
394 | if (width < 0.0) { |
|
395 | if (width < 0.0) { | |
395 | width = 0.0; |
|
396 | width = 0.0; | |
396 | } |
|
397 | } | |
397 | m_barWidth = width; |
|
398 | m_barWidth = width; | |
398 | emit updatedBars(); |
|
399 | emit updatedBars(); | |
399 | } |
|
400 | } | |
400 |
|
401 | |||
401 | qreal QBarSeriesPrivate::barWidth() const |
|
402 | qreal QBarSeriesPrivate::barWidth() const | |
402 | { |
|
403 | { | |
403 | return m_barWidth; |
|
404 | return m_barWidth; | |
404 | } |
|
405 | } | |
405 |
|
406 | |||
406 | QBarSet* QBarSeriesPrivate::barsetAt(int index) |
|
407 | QBarSet* QBarSeriesPrivate::barsetAt(int index) | |
407 | { |
|
408 | { | |
408 | return m_barSets.at(index); |
|
409 | return m_barSets.at(index); | |
409 | } |
|
410 | } | |
410 |
|
411 | |||
411 | void QBarSeriesPrivate::setVisible(bool visible) |
|
412 | void QBarSeriesPrivate::setVisible(bool visible) | |
412 | { |
|
413 | { | |
413 | m_visible = visible; |
|
414 | m_visible = visible; | |
414 | emit updatedBars(); |
|
415 | emit updatedBars(); | |
415 | } |
|
416 | } | |
416 |
|
417 | |||
417 | void QBarSeriesPrivate::setLabelsVisible(bool visible) |
|
418 | void QBarSeriesPrivate::setLabelsVisible(bool visible) | |
418 | { |
|
419 | { | |
419 | m_labelsVisible = visible; |
|
420 | m_labelsVisible = visible; | |
420 | emit labelsVisibleChanged(visible); |
|
421 | emit labelsVisibleChanged(visible); | |
421 | } |
|
422 | } | |
422 |
|
423 | |||
423 | qreal QBarSeriesPrivate::min() |
|
424 | qreal QBarSeriesPrivate::min() | |
424 | { |
|
425 | { | |
425 | if (m_barSets.count() <= 0) { |
|
426 | if (m_barSets.count() <= 0) { | |
426 | return 0; |
|
427 | return 0; | |
427 | } |
|
428 | } | |
428 | qreal min = INT_MAX; |
|
429 | qreal min = INT_MAX; | |
429 |
|
430 | |||
430 | for (int i = 0; i < m_barSets.count(); i++) { |
|
431 | for (int i = 0; i < m_barSets.count(); i++) { | |
431 | int categoryCount = m_barSets.at(i)->count(); |
|
432 | int categoryCount = m_barSets.at(i)->count(); | |
432 | for (int j = 0; j < categoryCount; j++) { |
|
433 | for (int j = 0; j < categoryCount; j++) { | |
433 | qreal temp = m_barSets.at(i)->at(j).y(); |
|
434 | qreal temp = m_barSets.at(i)->at(j).y(); | |
434 | if (temp < min) |
|
435 | if (temp < min) | |
435 | min = temp; |
|
436 | min = temp; | |
436 | } |
|
437 | } | |
437 | } |
|
438 | } | |
438 | return min; |
|
439 | return min; | |
439 | } |
|
440 | } | |
440 |
|
441 | |||
441 | qreal QBarSeriesPrivate::max() |
|
442 | qreal QBarSeriesPrivate::max() | |
442 | { |
|
443 | { | |
443 | if (m_barSets.count() <= 0) { |
|
444 | if (m_barSets.count() <= 0) { | |
444 | return 0; |
|
445 | return 0; | |
445 | } |
|
446 | } | |
446 | qreal max = INT_MIN; |
|
447 | qreal max = INT_MIN; | |
447 |
|
448 | |||
448 | for (int i = 0; i < m_barSets.count(); i++) { |
|
449 | for (int i = 0; i < m_barSets.count(); i++) { | |
449 | int categoryCount = m_barSets.at(i)->count(); |
|
450 | int categoryCount = m_barSets.at(i)->count(); | |
450 | for (int j = 0; j < categoryCount; j++) { |
|
451 | for (int j = 0; j < categoryCount; j++) { | |
451 | qreal temp = m_barSets.at(i)->at(j).y(); |
|
452 | qreal temp = m_barSets.at(i)->at(j).y(); | |
452 | if (temp > max) |
|
453 | if (temp > max) | |
453 | max = temp; |
|
454 | max = temp; | |
454 | } |
|
455 | } | |
455 | } |
|
456 | } | |
456 |
|
457 | |||
457 | return max; |
|
458 | return max; | |
458 | } |
|
459 | } | |
459 |
|
460 | |||
460 | qreal QBarSeriesPrivate::valueAt(int set, int category) |
|
461 | qreal QBarSeriesPrivate::valueAt(int set, int category) | |
461 | { |
|
462 | { | |
462 | if ((set < 0) || (set >= m_barSets.count())) { |
|
463 | if ((set < 0) || (set >= m_barSets.count())) { | |
463 | // No set, no value. |
|
464 | // No set, no value. | |
464 | return 0; |
|
465 | return 0; | |
465 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
466 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { | |
466 | // No category, no value. |
|
467 | // No category, no value. | |
467 | return 0; |
|
468 | return 0; | |
468 | } |
|
469 | } | |
469 |
|
470 | |||
470 | return m_barSets.at(set)->at(category).y(); |
|
471 | return m_barSets.at(set)->at(category).y(); | |
471 | } |
|
472 | } | |
472 |
|
473 | |||
473 | qreal QBarSeriesPrivate::percentageAt(int set, int category) |
|
474 | qreal QBarSeriesPrivate::percentageAt(int set, int category) | |
474 | { |
|
475 | { | |
475 | if ((set < 0) || (set >= m_barSets.count())) { |
|
476 | if ((set < 0) || (set >= m_barSets.count())) { | |
476 | // No set, no value. |
|
477 | // No set, no value. | |
477 | return 0; |
|
478 | return 0; | |
478 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
479 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { | |
479 | // No category, no value. |
|
480 | // No category, no value. | |
480 | return 0; |
|
481 | return 0; | |
481 | } |
|
482 | } | |
482 |
|
483 | |||
483 | qreal value = m_barSets.at(set)->at(category).y(); |
|
484 | qreal value = m_barSets.at(set)->at(category).y(); | |
484 | qreal sum = categorySum(category); |
|
485 | qreal sum = categorySum(category); | |
485 | if ( qFuzzyIsNull(sum) ) { |
|
486 | if ( qFuzzyIsNull(sum) ) { | |
486 | return 0; |
|
487 | return 0; | |
487 | } |
|
488 | } | |
488 |
|
489 | |||
489 | return value / sum; |
|
490 | return value / sum; | |
490 | } |
|
491 | } | |
491 |
|
492 | |||
492 | qreal QBarSeriesPrivate::categorySum(int category) |
|
493 | qreal QBarSeriesPrivate::categorySum(int category) | |
493 | { |
|
494 | { | |
494 | qreal sum(0); |
|
495 | qreal sum(0); | |
495 | int count = m_barSets.count(); // Count sets |
|
496 | int count = m_barSets.count(); // Count sets | |
496 | for (int set = 0; set < count; set++) { |
|
497 | for (int set = 0; set < count; set++) { | |
497 | if (category < m_barSets.at(set)->count()) |
|
498 | if (category < m_barSets.at(set)->count()) | |
498 | sum += m_barSets.at(set)->at(category).y(); |
|
499 | sum += m_barSets.at(set)->at(category).y(); | |
499 | } |
|
500 | } | |
500 | return sum; |
|
501 | return sum; | |
501 | } |
|
502 | } | |
502 |
|
503 | |||
503 | qreal QBarSeriesPrivate::absoluteCategorySum(int category) |
|
504 | qreal QBarSeriesPrivate::absoluteCategorySum(int category) | |
504 | { |
|
505 | { | |
505 | qreal sum(0); |
|
506 | qreal sum(0); | |
506 | int count = m_barSets.count(); // Count sets |
|
507 | int count = m_barSets.count(); // Count sets | |
507 | for (int set = 0; set < count; set++) { |
|
508 | for (int set = 0; set < count; set++) { | |
508 | if (category < m_barSets.at(set)->count()) |
|
509 | if (category < m_barSets.at(set)->count()) | |
509 | sum += qAbs(m_barSets.at(set)->at(category).y()); |
|
510 | sum += qAbs(m_barSets.at(set)->at(category).y()); | |
510 | } |
|
511 | } | |
511 | return sum; |
|
512 | return sum; | |
512 | } |
|
513 | } | |
513 |
|
514 | |||
514 | qreal QBarSeriesPrivate::maxCategorySum() |
|
515 | qreal QBarSeriesPrivate::maxCategorySum() | |
515 | { |
|
516 | { | |
516 | qreal max = INT_MIN; |
|
517 | qreal max = INT_MIN; | |
517 | int count = categoryCount(); |
|
518 | int count = categoryCount(); | |
518 | for (int i = 0; i < count; i++) { |
|
519 | for (int i = 0; i < count; i++) { | |
519 | qreal sum = categorySum(i); |
|
520 | qreal sum = categorySum(i); | |
520 | if (sum > max) |
|
521 | if (sum > max) | |
521 | max = sum; |
|
522 | max = sum; | |
522 | } |
|
523 | } | |
523 | return max; |
|
524 | return max; | |
524 | } |
|
525 | } | |
525 |
|
526 | |||
526 | qreal QBarSeriesPrivate::minX() |
|
527 | qreal QBarSeriesPrivate::minX() | |
527 | { |
|
528 | { | |
528 | if (m_barSets.count() <= 0) { |
|
529 | if (m_barSets.count() <= 0) { | |
529 | return 0; |
|
530 | return 0; | |
530 | } |
|
531 | } | |
531 | qreal min = INT_MAX; |
|
532 | qreal min = INT_MAX; | |
532 |
|
533 | |||
533 | for (int i = 0; i < m_barSets.count(); i++) { |
|
534 | for (int i = 0; i < m_barSets.count(); i++) { | |
534 | int categoryCount = m_barSets.at(i)->count(); |
|
535 | int categoryCount = m_barSets.at(i)->count(); | |
535 | for (int j = 0; j < categoryCount; j++) { |
|
536 | for (int j = 0; j < categoryCount; j++) { | |
536 | qreal temp = m_barSets.at(i)->at(j).x(); |
|
537 | qreal temp = m_barSets.at(i)->at(j).x(); | |
537 | if (temp < min) |
|
538 | if (temp < min) | |
538 | min = temp; |
|
539 | min = temp; | |
539 | } |
|
540 | } | |
540 | } |
|
541 | } | |
541 | return min; |
|
542 | return min; | |
542 | } |
|
543 | } | |
543 |
|
544 | |||
544 | qreal QBarSeriesPrivate::maxX() |
|
545 | qreal QBarSeriesPrivate::maxX() | |
545 | { |
|
546 | { | |
546 | if (m_barSets.count() <= 0) { |
|
547 | if (m_barSets.count() <= 0) { | |
547 | return 0; |
|
548 | return 0; | |
548 | } |
|
549 | } | |
549 | qreal max = INT_MIN; |
|
550 | qreal max = INT_MIN; | |
550 |
|
551 | |||
551 | for (int i = 0; i < m_barSets.count(); i++) { |
|
552 | for (int i = 0; i < m_barSets.count(); i++) { | |
552 | int categoryCount = m_barSets.at(i)->count(); |
|
553 | int categoryCount = m_barSets.at(i)->count(); | |
553 | for (int j = 0; j < categoryCount; j++) { |
|
554 | for (int j = 0; j < categoryCount; j++) { | |
554 | qreal temp = m_barSets.at(i)->at(j).x(); |
|
555 | qreal temp = m_barSets.at(i)->at(j).x(); | |
555 | if (temp > max) |
|
556 | if (temp > max) | |
556 | max = temp; |
|
557 | max = temp; | |
557 | } |
|
558 | } | |
558 | } |
|
559 | } | |
559 |
|
560 | |||
560 | return max; |
|
561 | return max; | |
561 | } |
|
562 | } | |
562 |
|
563 | |||
563 |
|
564 | |||
564 | void QBarSeriesPrivate::scaleDomain(Domain& domain) |
|
565 | void QBarSeriesPrivate::scaleDomain(Domain& domain) | |
565 | { |
|
566 | { | |
566 | qreal minX(domain.minX()); |
|
567 | qreal minX(domain.minX()); | |
567 | qreal minY(domain.minY()); |
|
568 | qreal minY(domain.minY()); | |
568 | qreal maxX(domain.maxX()); |
|
569 | qreal maxX(domain.maxX()); | |
569 | qreal maxY(domain.maxY()); |
|
570 | qreal maxY(domain.maxY()); | |
570 | int tickXCount(domain.tickXCount()); |
|
571 | int tickXCount(domain.tickXCount()); | |
571 | int tickYCount(domain.tickYCount()); |
|
572 | int tickYCount(domain.tickYCount()); | |
572 |
|
573 | |||
573 | qreal seriesMinX = this->minX(); |
|
574 | qreal seriesMinX = this->minX(); | |
574 | qreal seriesMaxX = this->maxX(); |
|
575 | qreal seriesMaxX = this->maxX(); | |
575 | qreal y = max(); |
|
576 | qreal y = max(); | |
576 | minX = qMin(minX, seriesMinX - 0.5); |
|
577 | minX = qMin(minX, seriesMinX - 0.5); | |
577 | minY = qMin(minY, y); |
|
578 | minY = qMin(minY, y); | |
578 | maxX = qMax(maxX, seriesMaxX + 0.5); |
|
579 | maxX = qMax(maxX, seriesMaxX + 0.5); | |
579 | maxY = qMax(maxY, y); |
|
580 | maxY = qMax(maxY, y); | |
580 | tickXCount = categoryCount()+1; |
|
581 | tickXCount = categoryCount()+1; | |
581 |
|
582 | |||
582 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
583 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); | |
583 | } |
|
584 | } | |
584 |
|
585 | |||
585 | Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
586 | Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
586 | { |
|
587 | { | |
587 | Q_Q(QBarSeries); |
|
588 | Q_Q(QBarSeries); | |
588 |
|
589 | |||
589 | BarChartItem* bar = new BarChartItem(q,presenter); |
|
590 | BarChartItem* bar = new BarChartItem(q,presenter); | |
590 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
591 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
591 | presenter->animator()->addAnimation(bar); |
|
592 | presenter->animator()->addAnimation(bar); | |
592 | } |
|
593 | } | |
593 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
594 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
594 | return bar; |
|
595 | return bar; | |
595 |
|
596 | |||
596 | } |
|
597 | } | |
597 |
|
598 | |||
598 | QList<LegendMarker*> QBarSeriesPrivate::createLegendMarker(QLegend* legend) |
|
599 | QList<LegendMarker*> QBarSeriesPrivate::createLegendMarker(QLegend* legend) | |
599 | { |
|
600 | { | |
600 | Q_Q(QBarSeries); |
|
601 | Q_Q(QBarSeries); | |
601 | QList<LegendMarker*> markers; |
|
602 | QList<LegendMarker*> markers; | |
602 | foreach(QBarSet* set, q->barSets()) { |
|
603 | foreach(QBarSet* set, q->barSets()) { | |
603 | BarLegendMarker* marker = new BarLegendMarker(q,set,legend); |
|
604 | BarLegendMarker* marker = new BarLegendMarker(q,set,legend); | |
604 | markers << marker; |
|
605 | markers << marker; | |
605 | } |
|
606 | } | |
606 |
|
607 | |||
607 | return markers; |
|
608 | return markers; | |
608 | } |
|
609 | } | |
609 |
|
610 | |||
|
611 | QAbstractAxis* QBarSeriesPrivate::createAxisX() | |||
|
612 | { | |||
|
613 | // TODO: parent? | |||
|
614 | return new QValuesAxis(this); | |||
|
615 | } | |||
|
616 | ||||
|
617 | QAbstractAxis* QBarSeriesPrivate::createAxisY() | |||
|
618 | { | |||
|
619 | // TODO: parent? | |||
|
620 | return new QValuesAxis(this); | |||
|
621 | } | |||
|
622 | ||||
610 | bool QBarSeriesPrivate::append(QBarSet *set) |
|
623 | bool QBarSeriesPrivate::append(QBarSet *set) | |
611 | { |
|
624 | { | |
612 | Q_Q(QBarSeries); |
|
625 | Q_Q(QBarSeries); | |
613 | if ((m_barSets.contains(set)) || (set == 0)) { |
|
626 | if ((m_barSets.contains(set)) || (set == 0)) { | |
614 | // Fail if set is already in list or set is null. |
|
627 | // Fail if set is already in list or set is null. | |
615 | return false; |
|
628 | return false; | |
616 | } |
|
629 | } | |
617 | m_barSets.append(set); |
|
630 | m_barSets.append(set); | |
618 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
631 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
619 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
632 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
620 | emit restructuredBars(); // this notifies barchartitem |
|
633 | emit restructuredBars(); // this notifies barchartitem | |
621 | if (m_dataset) { |
|
634 | if (m_dataset) { | |
622 | m_dataset->updateSeries(q); // this notifies legend |
|
635 | m_dataset->updateSeries(q); // this notifies legend | |
623 | } |
|
636 | } | |
624 | return true; |
|
637 | return true; | |
625 | } |
|
638 | } | |
626 |
|
639 | |||
627 | bool QBarSeriesPrivate::remove(QBarSet *set) |
|
640 | bool QBarSeriesPrivate::remove(QBarSet *set) | |
628 | { |
|
641 | { | |
629 | Q_Q(QBarSeries); |
|
642 | Q_Q(QBarSeries); | |
630 | if (!m_barSets.contains(set)) { |
|
643 | if (!m_barSets.contains(set)) { | |
631 | // Fail if set is not in list |
|
644 | // Fail if set is not in list | |
632 | return false; |
|
645 | return false; | |
633 | } |
|
646 | } | |
634 | m_barSets.removeOne(set); |
|
647 | m_barSets.removeOne(set); | |
635 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
648 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
636 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
649 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
637 | emit restructuredBars(); // this notifies barchartitem |
|
650 | emit restructuredBars(); // this notifies barchartitem | |
638 | if (m_dataset) { |
|
651 | if (m_dataset) { | |
639 | m_dataset->updateSeries(q); // this notifies legend |
|
652 | m_dataset->updateSeries(q); // this notifies legend | |
640 | } |
|
653 | } | |
641 | return true; |
|
654 | return true; | |
642 | } |
|
655 | } | |
643 |
|
656 | |||
644 | bool QBarSeriesPrivate::append(QList<QBarSet* > sets) |
|
657 | bool QBarSeriesPrivate::append(QList<QBarSet* > sets) | |
645 | { |
|
658 | { | |
646 | Q_Q(QBarSeries); |
|
659 | Q_Q(QBarSeries); | |
647 | foreach (QBarSet* set, sets) { |
|
660 | foreach (QBarSet* set, sets) { | |
648 | if ((set == 0) || (m_barSets.contains(set))) { |
|
661 | if ((set == 0) || (m_barSets.contains(set))) { | |
649 | // Fail if any of the sets is null or is already appended. |
|
662 | // Fail if any of the sets is null or is already appended. | |
650 | return false; |
|
663 | return false; | |
651 | } |
|
664 | } | |
652 | if (sets.count(set) != 1) { |
|
665 | if (sets.count(set) != 1) { | |
653 | // Also fail if same set is more than once in given list. |
|
666 | // Also fail if same set is more than once in given list. | |
654 | return false; |
|
667 | return false; | |
655 | } |
|
668 | } | |
656 | } |
|
669 | } | |
657 |
|
670 | |||
658 | foreach (QBarSet* set, sets) { |
|
671 | foreach (QBarSet* set, sets) { | |
659 | m_barSets.append(set); |
|
672 | m_barSets.append(set); | |
660 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
673 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
661 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
674 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
662 | } |
|
675 | } | |
663 | emit restructuredBars(); // this notifies barchartitem |
|
676 | emit restructuredBars(); // this notifies barchartitem | |
664 | if (m_dataset) { |
|
677 | if (m_dataset) { | |
665 | m_dataset->updateSeries(q); // this notifies legend |
|
678 | m_dataset->updateSeries(q); // this notifies legend | |
666 | } |
|
679 | } | |
667 | return true; |
|
680 | return true; | |
668 | } |
|
681 | } | |
669 |
|
682 | |||
670 | bool QBarSeriesPrivate::remove(QList<QBarSet* > sets) |
|
683 | bool QBarSeriesPrivate::remove(QList<QBarSet* > sets) | |
671 | { |
|
684 | { | |
672 | Q_Q(QBarSeries); |
|
685 | Q_Q(QBarSeries); | |
673 | if (sets.count() == 0) { |
|
686 | if (sets.count() == 0) { | |
674 | return false; |
|
687 | return false; | |
675 | } |
|
688 | } | |
676 | foreach (QBarSet* set, sets) { |
|
689 | foreach (QBarSet* set, sets) { | |
677 | if ((set == 0) || (!m_barSets.contains(set))) { |
|
690 | if ((set == 0) || (!m_barSets.contains(set))) { | |
678 | // Fail if any of the sets is null or is not in series |
|
691 | // Fail if any of the sets is null or is not in series | |
679 | return false; |
|
692 | return false; | |
680 | } |
|
693 | } | |
681 | if (sets.count(set) != 1) { |
|
694 | if (sets.count(set) != 1) { | |
682 | // Also fail if same set is more than once in given list. |
|
695 | // Also fail if same set is more than once in given list. | |
683 | return false; |
|
696 | return false; | |
684 | } |
|
697 | } | |
685 | } |
|
698 | } | |
686 |
|
699 | |||
687 | foreach (QBarSet* set, sets) { |
|
700 | foreach (QBarSet* set, sets) { | |
688 | m_barSets.removeOne(set); |
|
701 | m_barSets.removeOne(set); | |
689 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
702 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
690 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
703 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
691 | } |
|
704 | } | |
692 |
|
705 | |||
693 | emit restructuredBars(); // this notifies barchartitem |
|
706 | emit restructuredBars(); // this notifies barchartitem | |
694 | if (m_dataset) { |
|
707 | if (m_dataset) { | |
695 | m_dataset->updateSeries(q); // this notifies legend |
|
708 | m_dataset->updateSeries(q); // this notifies legend | |
696 | } |
|
709 | } | |
697 | return true; |
|
710 | return true; | |
698 | } |
|
711 | } | |
699 |
|
712 | |||
700 | bool QBarSeriesPrivate::insert(int index, QBarSet *set) |
|
713 | bool QBarSeriesPrivate::insert(int index, QBarSet *set) | |
701 | { |
|
714 | { | |
702 | Q_Q(QBarSeries); |
|
715 | Q_Q(QBarSeries); | |
703 | if ((m_barSets.contains(set)) || (set == 0)) { |
|
716 | if ((m_barSets.contains(set)) || (set == 0)) { | |
704 | // Fail if set is already in list or set is null. |
|
717 | // Fail if set is already in list or set is null. | |
705 | return false; |
|
718 | return false; | |
706 | } |
|
719 | } | |
707 | m_barSets.insert(index, set); |
|
720 | m_barSets.insert(index, set); | |
708 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
721 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
709 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
722 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
710 | emit restructuredBars(); // this notifies barchartitem |
|
723 | emit restructuredBars(); // this notifies barchartitem | |
711 | if (m_dataset) { |
|
724 | if (m_dataset) { | |
712 | m_dataset->updateSeries(q); // this notifies legend |
|
725 | m_dataset->updateSeries(q); // this notifies legend | |
713 | } |
|
726 | } | |
714 | return true; |
|
727 | return true; | |
715 | } |
|
728 | } | |
716 |
|
729 | |||
717 | #include "moc_qbarseries.cpp" |
|
730 | #include "moc_qbarseries.cpp" | |
718 | #include "moc_qbarseries_p.cpp" |
|
731 | #include "moc_qbarseries_p.cpp" | |
719 |
|
732 | |||
720 | QTCOMMERCIALCHART_END_NAMESPACE |
|
733 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,94 +1,97 | |||||
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 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef QBARSERIES_P_H |
|
30 | #ifndef QBARSERIES_P_H | |
31 | #define QBARSERIES_P_H |
|
31 | #define QBARSERIES_P_H | |
32 |
|
32 | |||
33 | #include "qbarseries.h" |
|
33 | #include "qbarseries.h" | |
34 | #include "qabstractseries_p.h" |
|
34 | #include "qabstractseries_p.h" | |
35 | #include <QStringList> |
|
35 | #include <QStringList> | |
36 | #include <QAbstractSeries> |
|
36 | #include <QAbstractSeries> | |
37 |
|
37 | |||
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
39 |
|
39 | |||
40 | class QBarModelMapper; |
|
40 | class QBarModelMapper; | |
41 |
|
41 | |||
42 | class QBarSeriesPrivate : public QAbstractSeriesPrivate |
|
42 | class QBarSeriesPrivate : public QAbstractSeriesPrivate | |
43 | { |
|
43 | { | |
44 | Q_OBJECT |
|
44 | Q_OBJECT | |
45 | public: |
|
45 | public: | |
46 | QBarSeriesPrivate(QBarSeries *parent); |
|
46 | QBarSeriesPrivate(QBarSeries *parent); | |
47 | int categoryCount() const; |
|
47 | int categoryCount() const; | |
48 |
|
48 | |||
49 | void setBarWidth(qreal width); |
|
49 | void setBarWidth(qreal width); | |
50 | qreal barWidth() const; |
|
50 | qreal barWidth() const; | |
51 |
|
51 | |||
52 | void setVisible(bool visible); |
|
52 | void setVisible(bool visible); | |
53 | void setLabelsVisible(bool visible); |
|
53 | void setLabelsVisible(bool visible); | |
54 |
|
54 | |||
55 | void scaleDomain(Domain& domain); |
|
55 | void scaleDomain(Domain& domain); | |
56 | Chart* createGraphics(ChartPresenter* presenter); |
|
56 | Chart* createGraphics(ChartPresenter* presenter); | |
57 | QList<LegendMarker*> createLegendMarker(QLegend* legend); |
|
57 | QList<LegendMarker*> createLegendMarker(QLegend* legend); | |
58 |
|
58 | |||
|
59 | QAbstractAxis* createAxisX(); | |||
|
60 | QAbstractAxis* createAxisY(); | |||
|
61 | ||||
59 | bool append(QBarSet *set); |
|
62 | bool append(QBarSet *set); | |
60 | bool remove(QBarSet *set); |
|
63 | bool remove(QBarSet *set); | |
61 | bool append(QList<QBarSet* > sets); |
|
64 | bool append(QList<QBarSet* > sets); | |
62 | bool remove(QList<QBarSet* > sets); |
|
65 | bool remove(QList<QBarSet* > sets); | |
63 | bool insert(int index, QBarSet *set); |
|
66 | bool insert(int index, QBarSet *set); | |
64 |
|
67 | |||
65 | QBarSet* barsetAt(int index); |
|
68 | QBarSet* barsetAt(int index); | |
66 | qreal min(); |
|
69 | qreal min(); | |
67 | qreal max(); |
|
70 | qreal max(); | |
68 | qreal valueAt(int set, int category); |
|
71 | qreal valueAt(int set, int category); | |
69 | qreal percentageAt(int set, int category); |
|
72 | qreal percentageAt(int set, int category); | |
70 | qreal categorySum(int category); |
|
73 | qreal categorySum(int category); | |
71 | qreal absoluteCategorySum(int category); |
|
74 | qreal absoluteCategorySum(int category); | |
72 | qreal maxCategorySum(); |
|
75 | qreal maxCategorySum(); | |
73 | qreal minX(); |
|
76 | qreal minX(); | |
74 | qreal maxX(); |
|
77 | qreal maxX(); | |
75 |
|
78 | |||
76 | Q_SIGNALS: |
|
79 | Q_SIGNALS: | |
77 | void clicked(QBarSet *barset, int index); |
|
80 | void clicked(QBarSet *barset, int index); | |
78 | void updatedBars(); |
|
81 | void updatedBars(); | |
79 | void restructuredBars(); |
|
82 | void restructuredBars(); | |
80 | void labelsVisibleChanged(bool visible); |
|
83 | void labelsVisibleChanged(bool visible); | |
81 |
|
84 | |||
82 | protected: |
|
85 | protected: | |
83 | QList<QBarSet *> m_barSets; |
|
86 | QList<QBarSet *> m_barSets; | |
84 | qreal m_barWidth; |
|
87 | qreal m_barWidth; | |
85 | bool m_labelsVisible; |
|
88 | bool m_labelsVisible; | |
86 | bool m_visible; |
|
89 | bool m_visible; | |
87 |
|
90 | |||
88 | private: |
|
91 | private: | |
89 | Q_DECLARE_PUBLIC(QBarSeries) |
|
92 | Q_DECLARE_PUBLIC(QBarSeries) | |
90 | }; |
|
93 | }; | |
91 |
|
94 | |||
92 | QTCOMMERCIALCHART_END_NAMESPACE |
|
95 | QTCOMMERCIALCHART_END_NAMESPACE | |
93 |
|
96 | |||
94 | #endif // QBARSERIESPRIVATE_P_H |
|
97 | #endif // QBARSERIESPRIVATE_P_H |
@@ -1,116 +1,130 | |||||
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 "qgroupedbarseries.h" |
|
21 | #include "qgroupedbarseries.h" | |
22 | #include "qgroupedbarseries_p.h" |
|
22 | #include "qgroupedbarseries_p.h" | |
23 | #include "groupedbarchartitem_p.h" |
|
23 | #include "groupedbarchartitem_p.h" | |
24 | #include "chartdataset_p.h" |
|
24 | #include "chartdataset_p.h" | |
25 | #include "charttheme_p.h" |
|
25 | #include "charttheme_p.h" | |
26 | #include "chartanimator_p.h" |
|
26 | #include "chartanimator_p.h" | |
|
27 | #include "qcategoriesaxis.h" | |||
|
28 | #include "qvaluesaxis.h" | |||
27 |
|
29 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
31 | |||
30 | /*! |
|
32 | /*! | |
31 | \class QGroupedBarSeries |
|
33 | \class QGroupedBarSeries | |
32 | \brief Series for creating grouped bar chart |
|
34 | \brief Series for creating grouped bar chart | |
33 | \mainclass |
|
35 | \mainclass | |
34 |
|
36 | |||
35 | QGroupedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars |
|
37 | QGroupedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars | |
36 | as groups, where bars in same category are grouped next to each other. QGroupedBarSeries groups the data |
|
38 | as groups, where bars in same category are grouped next to each other. QGroupedBarSeries groups the data | |
37 | from sets to categories, which are defined by a QStringList. |
|
39 | from sets to categories, which are defined by a QStringList. | |
38 |
|
40 | |||
39 | See the \l {GroupedbarChart Example} {grouped bar chart example} to learn how to create a grouped bar chart. |
|
41 | See the \l {GroupedbarChart Example} {grouped bar chart example} to learn how to create a grouped bar chart. | |
40 | \image examples_groupedbarchart.png |
|
42 | \image examples_groupedbarchart.png | |
41 |
|
43 | |||
42 | \sa QBarSet, QPercentBarSeries, QBarSeries, QStackedBarSeries |
|
44 | \sa QBarSet, QPercentBarSeries, QBarSeries, QStackedBarSeries | |
43 | */ |
|
45 | */ | |
44 | /*! |
|
46 | /*! | |
45 | \qmlclass GroupedBarSeries QGroupedBarSeries |
|
47 | \qmlclass GroupedBarSeries QGroupedBarSeries | |
46 | \inherits BarSeries |
|
48 | \inherits BarSeries | |
47 |
|
49 | |||
48 | The following QML shows how to create a simple grouped bar chart: |
|
50 | The following QML shows how to create a simple grouped bar chart: | |
49 | \snippet ../demos/qmlchart/qml/qmlchart/View8.qml 1 |
|
51 | \snippet ../demos/qmlchart/qml/qmlchart/View8.qml 1 | |
50 | \beginfloatleft |
|
52 | \beginfloatleft | |
51 | \image demos_qmlchart7.png |
|
53 | \image demos_qmlchart7.png | |
52 | \endfloat |
|
54 | \endfloat | |
53 | \clearfloat |
|
55 | \clearfloat | |
54 | */ |
|
56 | */ | |
55 |
|
57 | |||
56 | /*! |
|
58 | /*! | |
57 | Constructs empty QGroupedBarSeries. |
|
59 | Constructs empty QGroupedBarSeries. | |
58 | QGroupedBarSeries is QObject which is a child of a \a parent. |
|
60 | QGroupedBarSeries is QObject which is a child of a \a parent. | |
59 | */ |
|
61 | */ | |
60 | QGroupedBarSeries::QGroupedBarSeries(QObject *parent) |
|
62 | QGroupedBarSeries::QGroupedBarSeries(QObject *parent) | |
61 | : QBarSeries(*new QGroupedBarSeriesPrivate(this), parent) |
|
63 | : QBarSeries(*new QGroupedBarSeriesPrivate(this), parent) | |
62 | { |
|
64 | { | |
63 | } |
|
65 | } | |
64 |
|
66 | |||
65 | /*! |
|
67 | /*! | |
66 | Returns QChartSeries::SeriesTypeGroupedBar. |
|
68 | Returns QChartSeries::SeriesTypeGroupedBar. | |
67 | */ |
|
69 | */ | |
68 | QAbstractSeries::SeriesType QGroupedBarSeries::type() const |
|
70 | QAbstractSeries::SeriesType QGroupedBarSeries::type() const | |
69 | { |
|
71 | { | |
70 | return QAbstractSeries::SeriesTypeGroupedBar; |
|
72 | return QAbstractSeries::SeriesTypeGroupedBar; | |
71 | } |
|
73 | } | |
72 |
|
74 | |||
73 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
75 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
74 |
|
76 | |||
75 | QGroupedBarSeriesPrivate::QGroupedBarSeriesPrivate(QGroupedBarSeries *q) : QBarSeriesPrivate(q) |
|
77 | QGroupedBarSeriesPrivate::QGroupedBarSeriesPrivate(QGroupedBarSeries *q) : QBarSeriesPrivate(q) | |
76 | { |
|
78 | { | |
77 |
|
79 | |||
78 | } |
|
80 | } | |
79 |
|
81 | |||
80 | void QGroupedBarSeriesPrivate::scaleDomain(Domain& domain) |
|
82 | void QGroupedBarSeriesPrivate::scaleDomain(Domain& domain) | |
81 | { |
|
83 | { | |
82 | qreal minX(domain.minX()); |
|
84 | qreal minX(domain.minX()); | |
83 | qreal minY(domain.minY()); |
|
85 | qreal minY(domain.minY()); | |
84 | qreal maxX(domain.maxX()); |
|
86 | qreal maxX(domain.maxX()); | |
85 | qreal maxY(domain.maxY()); |
|
87 | qreal maxY(domain.maxY()); | |
86 | int tickXCount(domain.tickXCount()); |
|
88 | int tickXCount(domain.tickXCount()); | |
87 | int tickYCount(domain.tickYCount()); |
|
89 | int tickYCount(domain.tickYCount()); | |
88 |
|
90 | |||
89 | qreal x = categoryCount(); |
|
91 | qreal x = categoryCount(); | |
90 | qreal y = max(); |
|
92 | qreal y = max(); | |
91 | minX = qMin(minX, -0.5); |
|
93 | minX = qMin(minX, -0.5); | |
92 | minY = qMin(minY, y); |
|
94 | minY = qMin(minY, y); | |
93 | maxX = qMax(maxX, x - 0.5); |
|
95 | maxX = qMax(maxX, x - 0.5); | |
94 | maxY = qMax(maxY, y); |
|
96 | maxY = qMax(maxY, y); | |
95 | tickXCount = x+1; |
|
97 | tickXCount = x+1; | |
96 |
|
98 | |||
97 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
99 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); | |
98 | } |
|
100 | } | |
99 |
|
101 | |||
100 |
|
102 | |||
101 | Chart* QGroupedBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
103 | Chart* QGroupedBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
102 | { |
|
104 | { | |
103 | Q_Q(QGroupedBarSeries); |
|
105 | Q_Q(QGroupedBarSeries); | |
104 |
|
106 | |||
105 | GroupedBarChartItem* bar = new GroupedBarChartItem(q,presenter); |
|
107 | GroupedBarChartItem* bar = new GroupedBarChartItem(q,presenter); | |
106 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
108 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
107 | presenter->animator()->addAnimation(bar); |
|
109 | presenter->animator()->addAnimation(bar); | |
108 | } |
|
110 | } | |
109 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
111 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
110 | return bar; |
|
112 | return bar; | |
111 | } |
|
113 | } | |
112 |
|
114 | |||
|
115 | QAbstractAxis* QGroupedBarSeriesPrivate::createAxisX() | |||
|
116 | { | |||
|
117 | // TODO: parent? | |||
|
118 | return new QCategoriesAxis(this); | |||
|
119 | } | |||
|
120 | ||||
|
121 | QAbstractAxis* QGroupedBarSeriesPrivate::createAxisY() | |||
|
122 | { | |||
|
123 | // TODO: parent? | |||
|
124 | return new QValuesAxis(this); | |||
|
125 | } | |||
|
126 | ||||
113 | #include "moc_qgroupedbarseries.cpp" |
|
127 | #include "moc_qgroupedbarseries.cpp" | |
114 |
|
128 | |||
115 | QTCOMMERCIALCHART_END_NAMESPACE |
|
129 | QTCOMMERCIALCHART_END_NAMESPACE | |
116 |
|
130 |
@@ -1,52 +1,54 | |||||
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 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef QGROUPEDBARSERIES_P_H |
|
30 | #ifndef QGROUPEDBARSERIES_P_H | |
31 | #define QGROUPEDBARSERIES_P_H |
|
31 | #define QGROUPEDBARSERIES_P_H | |
32 |
|
32 | |||
33 | #include "qbarseries_p.h" |
|
33 | #include "qbarseries_p.h" | |
34 | #include "domain_p.h" |
|
34 | #include "domain_p.h" | |
35 |
|
35 | |||
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
37 |
|
37 | |||
38 |
|
38 | |||
39 | class QGroupedBarSeriesPrivate: public QBarSeriesPrivate |
|
39 | class QGroupedBarSeriesPrivate: public QBarSeriesPrivate | |
40 | { |
|
40 | { | |
41 | public: |
|
41 | public: | |
42 | QGroupedBarSeriesPrivate(QGroupedBarSeries* q); |
|
42 | QGroupedBarSeriesPrivate(QGroupedBarSeries* q); | |
43 | Chart* createGraphics(ChartPresenter* presenter); |
|
43 | Chart* createGraphics(ChartPresenter* presenter); | |
44 | void scaleDomain(Domain& domain); |
|
44 | void scaleDomain(Domain& domain); | |
|
45 | QAbstractAxis* createAxisX(); | |||
|
46 | QAbstractAxis* createAxisY(); | |||
45 |
|
47 | |||
46 | private: |
|
48 | private: | |
47 | Q_DECLARE_PUBLIC(QGroupedBarSeries) |
|
49 | Q_DECLARE_PUBLIC(QGroupedBarSeries) | |
48 | }; |
|
50 | }; | |
49 |
|
51 | |||
50 | QTCOMMERCIALCHART_END_NAMESPACE |
|
52 | QTCOMMERCIALCHART_END_NAMESPACE | |
51 |
|
53 | |||
52 | #endif // QGROUPEDBARSERIES_P_H |
|
54 | #endif // QGROUPEDBARSERIES_P_H |
@@ -1,115 +1,129 | |||||
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 "qpercentbarseries.h" |
|
21 | #include "qpercentbarseries.h" | |
22 | #include "qpercentbarseries_p.h" |
|
22 | #include "qpercentbarseries_p.h" | |
23 | #include "percentbarchartitem_p.h" |
|
23 | #include "percentbarchartitem_p.h" | |
24 | #include "chartdataset_p.h" |
|
24 | #include "chartdataset_p.h" | |
25 | #include "charttheme_p.h" |
|
25 | #include "charttheme_p.h" | |
26 | #include "chartanimator_p.h" |
|
26 | #include "chartanimator_p.h" | |
|
27 | #include "qcategoriesaxis.h" | |||
|
28 | #include "qvaluesaxis.h" | |||
27 |
|
29 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
31 | |||
30 | /*! |
|
32 | /*! | |
31 | \class QPercentBarSeries |
|
33 | \class QPercentBarSeries | |
32 | \brief Series for creating percent bar chart |
|
34 | \brief Series for creating percent bar chart | |
33 | \mainclass |
|
35 | \mainclass | |
34 |
|
36 | |||
35 | QPercentBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars |
|
37 | QPercentBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars | |
36 | as stacks, where each bar is shown as percentage of all bars in that category. |
|
38 | as stacks, where each bar is shown as percentage of all bars in that category. | |
37 | QPercentBarSeries groups the data from sets to categories, which are defined by a QStringList. |
|
39 | QPercentBarSeries groups the data from sets to categories, which are defined by a QStringList. | |
38 |
|
40 | |||
39 | See the \l {PercentbarChart Example} {percent bar chart example} to learn how to create a percent bar chart. |
|
41 | See the \l {PercentbarChart Example} {percent bar chart example} to learn how to create a percent bar chart. | |
40 | \image examples_percentbarchart.png |
|
42 | \image examples_percentbarchart.png | |
41 |
|
43 | |||
42 | \sa QBarSet, QStackedBarSeries, QBarSeries |
|
44 | \sa QBarSet, QStackedBarSeries, QBarSeries | |
43 | */ |
|
45 | */ | |
44 | /*! |
|
46 | /*! | |
45 | \qmlclass PercentBarSeries QPercentBarSeries |
|
47 | \qmlclass PercentBarSeries QPercentBarSeries | |
46 | \inherits BarSeries |
|
48 | \inherits BarSeries | |
47 |
|
49 | |||
48 | The following QML shows how to create a simple percent bar chart: |
|
50 | The following QML shows how to create a simple percent bar chart: | |
49 | \snippet ../demos/qmlchart/qml/qmlchart/View9.qml 1 |
|
51 | \snippet ../demos/qmlchart/qml/qmlchart/View9.qml 1 | |
50 | \beginfloatleft |
|
52 | \beginfloatleft | |
51 | \image demos_qmlchart9.png |
|
53 | \image demos_qmlchart9.png | |
52 | \endfloat |
|
54 | \endfloat | |
53 | \clearfloat |
|
55 | \clearfloat | |
54 | */ |
|
56 | */ | |
55 |
|
57 | |||
56 | /*! |
|
58 | /*! | |
57 | Constructs empty QPercentBarSeries. |
|
59 | Constructs empty QPercentBarSeries. | |
58 | QPercentBarSeries is QObject which is a child of a \a parent. |
|
60 | QPercentBarSeries is QObject which is a child of a \a parent. | |
59 | */ |
|
61 | */ | |
60 | QPercentBarSeries::QPercentBarSeries(QObject *parent) |
|
62 | QPercentBarSeries::QPercentBarSeries(QObject *parent) | |
61 | : QBarSeries(*new QPercentBarSeriesPrivate(this), parent) |
|
63 | : QBarSeries(*new QPercentBarSeriesPrivate(this), parent) | |
62 | { |
|
64 | { | |
63 | } |
|
65 | } | |
64 |
|
66 | |||
65 | /*! |
|
67 | /*! | |
66 | Returns QChartSeries::SeriesTypePercentBar. |
|
68 | Returns QChartSeries::SeriesTypePercentBar. | |
67 | */ |
|
69 | */ | |
68 | QAbstractSeries::SeriesType QPercentBarSeries::type() const |
|
70 | QAbstractSeries::SeriesType QPercentBarSeries::type() const | |
69 | { |
|
71 | { | |
70 | return QAbstractSeries::SeriesTypePercentBar; |
|
72 | return QAbstractSeries::SeriesTypePercentBar; | |
71 | } |
|
73 | } | |
72 |
|
74 | |||
73 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
75 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
74 |
|
76 | |||
75 | QPercentBarSeriesPrivate::QPercentBarSeriesPrivate(QPercentBarSeries *q) : QBarSeriesPrivate(q) |
|
77 | QPercentBarSeriesPrivate::QPercentBarSeriesPrivate(QPercentBarSeries *q) : QBarSeriesPrivate(q) | |
76 | { |
|
78 | { | |
77 |
|
79 | |||
78 | } |
|
80 | } | |
79 |
|
81 | |||
80 | void QPercentBarSeriesPrivate::scaleDomain(Domain& domain) |
|
82 | void QPercentBarSeriesPrivate::scaleDomain(Domain& domain) | |
81 | { |
|
83 | { | |
82 | qreal minX(domain.minX()); |
|
84 | qreal minX(domain.minX()); | |
83 | qreal minY(domain.minY()); |
|
85 | qreal minY(domain.minY()); | |
84 | qreal maxX(domain.maxX()); |
|
86 | qreal maxX(domain.maxX()); | |
85 | qreal maxY(domain.maxY()); |
|
87 | qreal maxY(domain.maxY()); | |
86 | int tickXCount(domain.tickXCount()); |
|
88 | int tickXCount(domain.tickXCount()); | |
87 | int tickYCount(domain.tickYCount()); |
|
89 | int tickYCount(domain.tickYCount()); | |
88 |
|
90 | |||
89 | qreal x = categoryCount(); |
|
91 | qreal x = categoryCount(); | |
90 | minX = qMin(minX, -0.5); |
|
92 | minX = qMin(minX, -0.5); | |
91 | maxX = qMax(maxX, x - 0.5); |
|
93 | maxX = qMax(maxX, x - 0.5); | |
92 | minY = 0; |
|
94 | minY = 0; | |
93 | maxY = 100; |
|
95 | maxY = 100; | |
94 | tickXCount = x+1; |
|
96 | tickXCount = x+1; | |
95 |
|
97 | |||
96 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
98 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); | |
97 | } |
|
99 | } | |
98 |
|
100 | |||
99 |
|
101 | |||
100 | Chart* QPercentBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
102 | Chart* QPercentBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
101 | { |
|
103 | { | |
102 | Q_Q(QPercentBarSeries); |
|
104 | Q_Q(QPercentBarSeries); | |
103 |
|
105 | |||
104 | PercentBarChartItem* bar = new PercentBarChartItem(q,presenter); |
|
106 | PercentBarChartItem* bar = new PercentBarChartItem(q,presenter); | |
105 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
107 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
106 | presenter->animator()->addAnimation(bar); |
|
108 | presenter->animator()->addAnimation(bar); | |
107 | } |
|
109 | } | |
108 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
110 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
109 | return bar; |
|
111 | return bar; | |
110 | } |
|
112 | } | |
111 |
|
113 | |||
|
114 | QAbstractAxis* QPercentBarSeriesPrivate::createAxisX() | |||
|
115 | { | |||
|
116 | // TODO: parent? | |||
|
117 | return new QCategoriesAxis(this); | |||
|
118 | } | |||
|
119 | ||||
|
120 | QAbstractAxis* QPercentBarSeriesPrivate::createAxisY() | |||
|
121 | { | |||
|
122 | // TODO: parent? | |||
|
123 | return new QValuesAxis(this); | |||
|
124 | } | |||
|
125 | ||||
112 | #include "moc_qpercentbarseries.cpp" |
|
126 | #include "moc_qpercentbarseries.cpp" | |
113 |
|
127 | |||
114 | QTCOMMERCIALCHART_END_NAMESPACE |
|
128 | QTCOMMERCIALCHART_END_NAMESPACE | |
115 |
|
129 |
@@ -1,52 +1,54 | |||||
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 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef QPERCENTBARSERIES_P_H |
|
30 | #ifndef QPERCENTBARSERIES_P_H | |
31 | #define QPERCENTBARSERIES_P_H |
|
31 | #define QPERCENTBARSERIES_P_H | |
32 |
|
32 | |||
33 | #include "qbarseries_p.h" |
|
33 | #include "qbarseries_p.h" | |
34 | #include "domain_p.h" |
|
34 | #include "domain_p.h" | |
35 |
|
35 | |||
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
37 |
|
37 | |||
38 |
|
38 | |||
39 | class QPercentBarSeriesPrivate: public QBarSeriesPrivate |
|
39 | class QPercentBarSeriesPrivate: public QBarSeriesPrivate | |
40 | { |
|
40 | { | |
41 | public: |
|
41 | public: | |
42 | QPercentBarSeriesPrivate(QPercentBarSeries* q); |
|
42 | QPercentBarSeriesPrivate(QPercentBarSeries* q); | |
43 | void scaleDomain(Domain& domain); |
|
43 | void scaleDomain(Domain& domain); | |
44 | Chart* createGraphics(ChartPresenter* presenter); |
|
44 | Chart* createGraphics(ChartPresenter* presenter); | |
|
45 | QAbstractAxis* createAxisX(); | |||
|
46 | QAbstractAxis* createAxisY(); | |||
45 |
|
47 | |||
46 | private: |
|
48 | private: | |
47 | Q_DECLARE_PUBLIC(QPercentBarSeries) |
|
49 | Q_DECLARE_PUBLIC(QPercentBarSeries) | |
48 | }; |
|
50 | }; | |
49 |
|
51 | |||
50 | QTCOMMERCIALCHART_END_NAMESPACE |
|
52 | QTCOMMERCIALCHART_END_NAMESPACE | |
51 |
|
53 | |||
52 | #endif |
|
54 | #endif |
@@ -1,117 +1,132 | |||||
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 "qstackedbarseries.h" |
|
21 | #include "qstackedbarseries.h" | |
22 | #include "qstackedbarseries_p.h" |
|
22 | #include "qstackedbarseries_p.h" | |
23 | #include "stackedbarchartitem_p.h" |
|
23 | #include "stackedbarchartitem_p.h" | |
24 | #include "chartdataset_p.h" |
|
24 | #include "chartdataset_p.h" | |
25 | #include "charttheme_p.h" |
|
25 | #include "charttheme_p.h" | |
26 | #include "chartanimator_p.h" |
|
26 | #include "chartanimator_p.h" | |
|
27 | #include "qcategoriesaxis.h" | |||
|
28 | #include "qvaluesaxis.h" | |||
27 |
|
29 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
31 | |||
30 | /*! |
|
32 | /*! | |
31 | \class QStackedBarSeries |
|
33 | \class QStackedBarSeries | |
32 | \brief Series for creating stacked bar chart |
|
34 | \brief Series for creating stacked bar chart | |
33 | \mainclass |
|
35 | \mainclass | |
34 |
|
36 | |||
35 | QStackedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars |
|
37 | QStackedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars | |
36 | as stacks, where bars in same category are stacked on top of each other. |
|
38 | as stacks, where bars in same category are stacked on top of each other. | |
37 | QStackedBarSeries groups the data from sets to categories, which are defined by QStringList. |
|
39 | QStackedBarSeries groups the data from sets to categories, which are defined by QStringList. | |
38 |
|
40 | |||
39 | See the \l {StackedbarChart Example} {stacked bar chart example} to learn how to create a stacked bar chart. |
|
41 | See the \l {StackedbarChart Example} {stacked bar chart example} to learn how to create a stacked bar chart. | |
40 | \image examples_stackedbarchart.png |
|
42 | \image examples_stackedbarchart.png | |
41 |
|
43 | |||
42 | \sa QBarSet, QPercentBarSeries, QBarSeries |
|
44 | \sa QBarSet, QPercentBarSeries, QBarSeries | |
43 | */ |
|
45 | */ | |
44 |
|
46 | |||
45 | /*! |
|
47 | /*! | |
46 | \qmlclass StackedBarSeries QStackedBarSeries |
|
48 | \qmlclass StackedBarSeries QStackedBarSeries | |
47 | \inherits BarSeries |
|
49 | \inherits BarSeries | |
48 |
|
50 | |||
49 | The following QML shows how to create a simple stacked bar chart: |
|
51 | The following QML shows how to create a simple stacked bar chart: | |
50 | \snippet ../demos/qmlchart/qml/qmlchart/View8.qml 1 |
|
52 | \snippet ../demos/qmlchart/qml/qmlchart/View8.qml 1 | |
51 | \beginfloatleft |
|
53 | \beginfloatleft | |
52 | \image demos_qmlchart8.png |
|
54 | \image demos_qmlchart8.png | |
53 | \endfloat |
|
55 | \endfloat | |
54 | \clearfloat |
|
56 | \clearfloat | |
55 | */ |
|
57 | */ | |
56 |
|
58 | |||
57 | /*! |
|
59 | /*! | |
58 | Constructs empty QStackedBarSeries. |
|
60 | Constructs empty QStackedBarSeries. | |
59 | QStackedBarSeries is QObject which is a child of a \a parent. |
|
61 | QStackedBarSeries is QObject which is a child of a \a parent. | |
60 | */ |
|
62 | */ | |
61 | QStackedBarSeries::QStackedBarSeries(QObject *parent) |
|
63 | QStackedBarSeries::QStackedBarSeries(QObject *parent) | |
62 | : QBarSeries(*new QStackedBarSeriesPrivate(this), parent) |
|
64 | : QBarSeries(*new QStackedBarSeriesPrivate(this), parent) | |
63 | { |
|
65 | { | |
64 | } |
|
66 | } | |
65 |
|
67 | |||
66 | /*! |
|
68 | /*! | |
67 | Returns QChartSeries::SeriesTypeStackedBar. |
|
69 | Returns QChartSeries::SeriesTypeStackedBar. | |
68 | */ |
|
70 | */ | |
69 | QAbstractSeries::SeriesType QStackedBarSeries::type() const |
|
71 | QAbstractSeries::SeriesType QStackedBarSeries::type() const | |
70 | { |
|
72 | { | |
71 | return QAbstractSeries::SeriesTypeStackedBar; |
|
73 | return QAbstractSeries::SeriesTypeStackedBar; | |
72 | } |
|
74 | } | |
73 |
|
75 | |||
74 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
76 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
75 |
|
77 | |||
76 | QStackedBarSeriesPrivate::QStackedBarSeriesPrivate(QStackedBarSeries *q) : QBarSeriesPrivate(q) |
|
78 | QStackedBarSeriesPrivate::QStackedBarSeriesPrivate(QStackedBarSeries *q) : QBarSeriesPrivate(q) | |
77 | { |
|
79 | { | |
78 |
|
80 | |||
79 | } |
|
81 | } | |
80 |
|
82 | |||
81 | void QStackedBarSeriesPrivate::scaleDomain(Domain& domain) |
|
83 | void QStackedBarSeriesPrivate::scaleDomain(Domain& domain) | |
82 | { |
|
84 | { | |
83 | qreal minX(domain.minX()); |
|
85 | qreal minX(domain.minX()); | |
84 | qreal minY(domain.minY()); |
|
86 | qreal minY(domain.minY()); | |
85 | qreal maxX(domain.maxX()); |
|
87 | qreal maxX(domain.maxX()); | |
86 | qreal maxY(domain.maxY()); |
|
88 | qreal maxY(domain.maxY()); | |
87 | int tickXCount(domain.tickXCount()); |
|
89 | int tickXCount(domain.tickXCount()); | |
88 | int tickYCount(domain.tickYCount()); |
|
90 | int tickYCount(domain.tickYCount()); | |
89 |
|
91 | |||
90 | qreal x = categoryCount(); |
|
92 | qreal x = categoryCount(); | |
91 | qreal y = maxCategorySum(); |
|
93 | qreal y = maxCategorySum(); | |
92 | minX = qMin(minX, -0.5); |
|
94 | minX = qMin(minX, -0.5); | |
93 | minY = qMin(minY, y); |
|
95 | minY = qMin(minY, y); | |
94 | maxX = qMax(maxX, x - 0.5); |
|
96 | maxX = qMax(maxX, x - 0.5); | |
95 | maxY = qMax(maxY, y); |
|
97 | maxY = qMax(maxY, y); | |
96 | tickXCount = x+1; |
|
98 | tickXCount = x+1; | |
97 |
|
99 | |||
98 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
100 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); | |
99 | } |
|
101 | } | |
100 |
|
102 | |||
101 |
|
103 | |||
102 | Chart* QStackedBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
104 | Chart* QStackedBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
103 | { |
|
105 | { | |
104 | Q_Q(QStackedBarSeries); |
|
106 | Q_Q(QStackedBarSeries); | |
105 |
|
107 | |||
106 | StackedBarChartItem* bar = new StackedBarChartItem(q,presenter); |
|
108 | StackedBarChartItem* bar = new StackedBarChartItem(q,presenter); | |
107 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
109 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
108 | presenter->animator()->addAnimation(bar); |
|
110 | presenter->animator()->addAnimation(bar); | |
109 | } |
|
111 | } | |
110 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
112 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
111 | return bar; |
|
113 | return bar; | |
112 | } |
|
114 | } | |
113 |
|
115 | |||
|
116 | QAbstractAxis* QStackedBarSeriesPrivate::createAxisX() | |||
|
117 | { | |||
|
118 | // TODO: parent? | |||
|
119 | return new QCategoriesAxis(this); | |||
|
120 | } | |||
|
121 | ||||
|
122 | QAbstractAxis* QStackedBarSeriesPrivate::createAxisY() | |||
|
123 | { | |||
|
124 | // TODO: parent? | |||
|
125 | return new QValuesAxis(this); | |||
|
126 | } | |||
|
127 | ||||
|
128 | ||||
114 | #include "moc_qstackedbarseries.cpp" |
|
129 | #include "moc_qstackedbarseries.cpp" | |
115 |
|
130 | |||
116 | QTCOMMERCIALCHART_END_NAMESPACE |
|
131 | QTCOMMERCIALCHART_END_NAMESPACE | |
117 |
|
132 |
@@ -1,52 +1,54 | |||||
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 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef QSTACKEDBARSERIES_P_H |
|
30 | #ifndef QSTACKEDBARSERIES_P_H | |
31 | #define QSTACKEDBARSERIES_P_H |
|
31 | #define QSTACKEDBARSERIES_P_H | |
32 |
|
32 | |||
33 | #include "qbarseries_p.h" |
|
33 | #include "qbarseries_p.h" | |
34 | #include "domain_p.h" |
|
34 | #include "domain_p.h" | |
35 |
|
35 | |||
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
37 |
|
37 | |||
38 |
|
38 | |||
39 | class QStackedBarSeriesPrivate: public QBarSeriesPrivate |
|
39 | class QStackedBarSeriesPrivate: public QBarSeriesPrivate | |
40 | { |
|
40 | { | |
41 | public: |
|
41 | public: | |
42 | QStackedBarSeriesPrivate(QStackedBarSeries* q); |
|
42 | QStackedBarSeriesPrivate(QStackedBarSeries* q); | |
43 | Chart* createGraphics(ChartPresenter* presenter); |
|
43 | Chart* createGraphics(ChartPresenter* presenter); | |
44 | void scaleDomain(Domain& domain); |
|
44 | void scaleDomain(Domain& domain); | |
|
45 | QAbstractAxis* createAxisX(); | |||
|
46 | QAbstractAxis* createAxisY(); | |||
45 |
|
47 | |||
46 | private: |
|
48 | private: | |
47 | Q_DECLARE_PUBLIC(QStackedBarSeries) |
|
49 | Q_DECLARE_PUBLIC(QStackedBarSeries) | |
48 | }; |
|
50 | }; | |
49 |
|
51 | |||
50 | QTCOMMERCIALCHART_END_NAMESPACE |
|
52 | QTCOMMERCIALCHART_END_NAMESPACE | |
51 |
|
53 | |||
52 | #endif |
|
54 | #endif |
@@ -1,134 +1,147 | |||||
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 "qlineseries.h" |
|
21 | #include "qlineseries.h" | |
22 | #include "qlineseries_p.h" |
|
22 | #include "qlineseries_p.h" | |
23 | #include "linechartitem_p.h" |
|
23 | #include "linechartitem_p.h" | |
24 | #include "chartdataset_p.h" |
|
24 | #include "chartdataset_p.h" | |
25 | #include "charttheme_p.h" |
|
25 | #include "charttheme_p.h" | |
26 | #include "chartanimator_p.h" |
|
26 | #include "chartanimator_p.h" | |
|
27 | #include "qvaluesaxis.h" | |||
27 |
|
28 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
30 | |||
30 | /*! |
|
31 | /*! | |
31 | \class QLineSeries |
|
32 | \class QLineSeries | |
32 | \brief The QLineSeries class is used for making line charts. |
|
33 | \brief The QLineSeries class is used for making line charts. | |
33 |
|
34 | |||
34 | \mainclass |
|
35 | \mainclass | |
35 |
|
36 | |||
36 | A line chart is used to show information as a series of data points |
|
37 | A line chart is used to show information as a series of data points | |
37 | connected by straight lines. |
|
38 | connected by straight lines. | |
38 |
|
39 | |||
39 | \image examples_linechart.png |
|
40 | \image examples_linechart.png | |
40 |
|
41 | |||
41 | Creating basic line chart is simple: |
|
42 | Creating basic line chart is simple: | |
42 | \code |
|
43 | \code | |
43 | QLineSeries* series = new QLineSeries(); |
|
44 | QLineSeries* series = new QLineSeries(); | |
44 | series->append(0, 6); |
|
45 | series->append(0, 6); | |
45 | series->append(2, 4); |
|
46 | series->append(2, 4); | |
46 | ... |
|
47 | ... | |
47 | chart->addSeries(series); |
|
48 | chart->addSeries(series); | |
48 | \endcode |
|
49 | \endcode | |
49 | */ |
|
50 | */ | |
50 | /*! |
|
51 | /*! | |
51 | \qmlclass LineSeries QLineSeries |
|
52 | \qmlclass LineSeries QLineSeries | |
52 | \inherits XYSeries |
|
53 | \inherits XYSeries | |
53 |
|
54 | |||
54 | The following QML shows how to create a simple line chart: |
|
55 | The following QML shows how to create a simple line chart: | |
55 | \snippet ../demos/qmlchart/qml/qmlchart/View2.qml 1 |
|
56 | \snippet ../demos/qmlchart/qml/qmlchart/View2.qml 1 | |
56 | \beginfloatleft |
|
57 | \beginfloatleft | |
57 | \image demos_qmlchart2.png |
|
58 | \image demos_qmlchart2.png | |
58 | \endfloat |
|
59 | \endfloat | |
59 | \clearfloat |
|
60 | \clearfloat | |
60 | */ |
|
61 | */ | |
61 |
|
62 | |||
62 | /*! |
|
63 | /*! | |
63 | \fn virtual SeriesType QLineSeries::type() const |
|
64 | \fn virtual SeriesType QLineSeries::type() const | |
64 | \brief Returns type of series. |
|
65 | \brief Returns type of series. | |
65 | \sa QAbstractSeries, SeriesType |
|
66 | \sa QAbstractSeries, SeriesType | |
66 | */ |
|
67 | */ | |
67 |
|
68 | |||
68 | /*! |
|
69 | /*! | |
69 | Constructs empty series object which is a child of \a parent. |
|
70 | Constructs empty series object which is a child of \a parent. | |
70 | When series object is added to QChartView or QChart instance ownerships is transferred. |
|
71 | When series object is added to QChartView or QChart instance ownerships is transferred. | |
71 | */ |
|
72 | */ | |
72 | QLineSeries::QLineSeries(QObject *parent) : QXYSeries(*new QLineSeriesPrivate(this),parent) |
|
73 | QLineSeries::QLineSeries(QObject *parent) : QXYSeries(*new QLineSeriesPrivate(this),parent) | |
73 | { |
|
74 | { | |
74 |
|
75 | |||
75 | } |
|
76 | } | |
76 |
|
77 | |||
77 | /*! |
|
78 | /*! | |
78 | \internal |
|
79 | \internal | |
79 | */ |
|
80 | */ | |
80 | QLineSeries::QLineSeries(QLineSeriesPrivate &d,QObject *parent) : QXYSeries (d,parent) |
|
81 | QLineSeries::QLineSeries(QLineSeriesPrivate &d,QObject *parent) : QXYSeries (d,parent) | |
81 | { |
|
82 | { | |
82 |
|
83 | |||
83 | } |
|
84 | } | |
84 | /*! |
|
85 | /*! | |
85 | Destroys the object. Series added to QChartView or QChart instances are owned by those, |
|
86 | Destroys the object. Series added to QChartView or QChart instances are owned by those, | |
86 | and are deleted when mentioned object are destroyed. |
|
87 | and are deleted when mentioned object are destroyed. | |
87 | */ |
|
88 | */ | |
88 | QLineSeries::~QLineSeries() |
|
89 | QLineSeries::~QLineSeries() | |
89 | { |
|
90 | { | |
90 | Q_D(QLineSeries); |
|
91 | Q_D(QLineSeries); | |
91 | if(d->m_dataset){ |
|
92 | if(d->m_dataset){ | |
92 | d->m_dataset->removeSeries(this); |
|
93 | d->m_dataset->removeSeries(this); | |
93 | } |
|
94 | } | |
94 | } |
|
95 | } | |
95 |
|
96 | |||
96 | QAbstractSeries::SeriesType QLineSeries::type() const |
|
97 | QAbstractSeries::SeriesType QLineSeries::type() const | |
97 | { |
|
98 | { | |
98 | return QAbstractSeries::SeriesTypeLine; |
|
99 | return QAbstractSeries::SeriesTypeLine; | |
99 | } |
|
100 | } | |
100 |
|
101 | |||
101 | /* |
|
102 | /* | |
102 | QDebug operator<< (QDebug debug, const QLineSeries series) |
|
103 | QDebug operator<< (QDebug debug, const QLineSeries series) | |
103 | { |
|
104 | { | |
104 | Q_ASSERT(series.d_func()->m_x.size() == series.d_func()->m_y.size()); |
|
105 | Q_ASSERT(series.d_func()->m_x.size() == series.d_func()->m_y.size()); | |
105 | int size = series.d_func()->m_x.size(); |
|
106 | int size = series.d_func()->m_x.size(); | |
106 | for (int i=0; i<size; i++) { |
|
107 | for (int i=0; i<size; i++) { | |
107 | debug.nospace() << "(" << series.d_func()->m_x.at(i) << ','<< series.d_func()->m_y.at(i) << ") "; |
|
108 | debug.nospace() << "(" << series.d_func()->m_x.at(i) << ','<< series.d_func()->m_y.at(i) << ") "; | |
108 | } |
|
109 | } | |
109 | return debug.space(); |
|
110 | return debug.space(); | |
110 | } |
|
111 | } | |
111 | */ |
|
112 | */ | |
112 |
|
113 | |||
113 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
114 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
114 |
|
115 | |||
115 | QLineSeriesPrivate::QLineSeriesPrivate(QLineSeries* q):QXYSeriesPrivate(q) |
|
116 | QLineSeriesPrivate::QLineSeriesPrivate(QLineSeries* q):QXYSeriesPrivate(q) | |
116 | { |
|
117 | { | |
117 |
|
118 | |||
118 | }; |
|
119 | }; | |
119 |
|
120 | |||
120 | Chart* QLineSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
121 | Chart* QLineSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
121 | { |
|
122 | { | |
122 | Q_Q(QLineSeries); |
|
123 | Q_Q(QLineSeries); | |
123 | LineChartItem* line = new LineChartItem(q,presenter); |
|
124 | LineChartItem* line = new LineChartItem(q,presenter); | |
124 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
125 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
125 | line->setAnimator(presenter->animator()); |
|
126 | line->setAnimator(presenter->animator()); | |
126 | line->setAnimation(new XYAnimation(line)); |
|
127 | line->setAnimation(new XYAnimation(line)); | |
127 | } |
|
128 | } | |
128 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
129 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
129 | return line; |
|
130 | return line; | |
130 | } |
|
131 | } | |
131 |
|
132 | |||
|
133 | QAbstractAxis* QLineSeriesPrivate::createAxisX() | |||
|
134 | { | |||
|
135 | // TODO: parent? | |||
|
136 | return new QValuesAxis(this); | |||
|
137 | } | |||
|
138 | ||||
|
139 | QAbstractAxis* QLineSeriesPrivate::createAxisY() | |||
|
140 | { | |||
|
141 | // TODO: parent? | |||
|
142 | return new QValuesAxis(this); | |||
|
143 | } | |||
|
144 | ||||
132 | #include "moc_qlineseries.cpp" |
|
145 | #include "moc_qlineseries.cpp" | |
133 |
|
146 | |||
134 | QTCOMMERCIALCHART_END_NAMESPACE |
|
147 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,50 +1,53 | |||||
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 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef QLINESERIES_P_H |
|
30 | #ifndef QLINESERIES_P_H | |
31 | #define QLINESERIES_P_H |
|
31 | #define QLINESERIES_P_H | |
32 |
|
32 | |||
33 | #include "qxyseries_p.h" |
|
33 | #include "qxyseries_p.h" | |
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
36 |
|
36 | |||
37 |
|
37 | |||
38 | class QLineSeriesPrivate: public QXYSeriesPrivate |
|
38 | class QLineSeriesPrivate: public QXYSeriesPrivate | |
39 | { |
|
39 | { | |
40 | public: |
|
40 | public: | |
41 | QLineSeriesPrivate(QLineSeries* q); |
|
41 | QLineSeriesPrivate(QLineSeries* q); | |
42 | Chart* createGraphics(ChartPresenter* presenter); |
|
42 | Chart* createGraphics(ChartPresenter* presenter); | |
|
43 | QAbstractAxis* createAxisX(); | |||
|
44 | QAbstractAxis* createAxisY(); | |||
|
45 | ||||
43 | private: |
|
46 | private: | |
44 | Q_DECLARE_PUBLIC(QLineSeries); |
|
47 | Q_DECLARE_PUBLIC(QLineSeries); | |
45 |
|
48 | |||
46 | }; |
|
49 | }; | |
47 |
|
50 | |||
48 | QTCOMMERCIALCHART_END_NAMESPACE |
|
51 | QTCOMMERCIALCHART_END_NAMESPACE | |
49 |
|
52 | |||
50 | #endif |
|
53 | #endif |
@@ -1,760 +1,771 | |||||
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 "chartanimator_p.h" |
|
28 | #include "chartanimator_p.h" | |
29 | #include "legendmarker_p.h" |
|
29 | #include "legendmarker_p.h" | |
|
30 | #include "qabstractaxis.h" | |||
30 |
|
31 | |||
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
32 |
|
33 | |||
33 | /*! |
|
34 | /*! | |
34 | \class QPieSeries |
|
35 | \class QPieSeries | |
35 | \brief Pie series API for QtCommercial Charts |
|
36 | \brief Pie series API for QtCommercial Charts | |
36 |
|
37 | |||
37 | 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. | |
38 | 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. | |
39 | The actual slice size is determined by that relative value. |
|
40 | The actual slice size is determined by that relative value. | |
40 |
|
41 | |||
41 | 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 | |
42 | These relate to the actual chart rectangle. |
|
43 | These relate to the actual chart rectangle. | |
43 |
|
44 | |||
44 | 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. | |
45 | 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. | |
46 | 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. | |
47 |
|
48 | |||
48 | See the \l {PieChart Example} {pie chart example} to learn how to create a simple pie chart. |
|
49 | See the \l {PieChart Example} {pie chart example} to learn how to create a simple pie chart. | |
49 | \image examples_piechart.png |
|
50 | \image examples_piechart.png | |
50 | */ |
|
51 | */ | |
51 | /*! |
|
52 | /*! | |
52 | \qmlclass PieSeries QPieSeries |
|
53 | \qmlclass PieSeries QPieSeries | |
53 | \inherits AbstractSeries |
|
54 | \inherits AbstractSeries | |
54 |
|
55 | |||
55 | The following QML shows how to create a simple pie chart. |
|
56 | The following QML shows how to create a simple pie chart. | |
56 |
|
57 | |||
57 | \snippet ../demos/qmlchart/qml/qmlchart/View1.qml 1 |
|
58 | \snippet ../demos/qmlchart/qml/qmlchart/View1.qml 1 | |
58 |
|
59 | |||
59 | \beginfloatleft |
|
60 | \beginfloatleft | |
60 | \image demos_qmlchart1.png |
|
61 | \image demos_qmlchart1.png | |
61 | \endfloat |
|
62 | \endfloat | |
62 | \clearfloat |
|
63 | \clearfloat | |
63 | */ |
|
64 | */ | |
64 |
|
65 | |||
65 | /*! |
|
66 | /*! | |
66 | \property QPieSeries::horizontalPosition |
|
67 | \property QPieSeries::horizontalPosition | |
67 | \brief Defines the horizontal position of the pie. |
|
68 | \brief Defines the horizontal position of the pie. | |
68 |
|
69 | |||
69 | The value is a relative value to the chart rectangle where: |
|
70 | The value is a relative value to the chart rectangle where: | |
70 |
|
71 | |||
71 | \list |
|
72 | \list | |
72 | \o 0.0 is the absolute left. |
|
73 | \o 0.0 is the absolute left. | |
73 | \o 1.0 is the absolute right. |
|
74 | \o 1.0 is the absolute right. | |
74 | \endlist |
|
75 | \endlist | |
75 | Default value is 0.5 (center). |
|
76 | Default value is 0.5 (center). | |
76 | \sa verticalPosition |
|
77 | \sa verticalPosition | |
77 | */ |
|
78 | */ | |
78 |
|
79 | |||
79 | /*! |
|
80 | /*! | |
80 | \qmlproperty real PieSeries::horizontalPosition |
|
81 | \qmlproperty real PieSeries::horizontalPosition | |
81 |
|
82 | |||
82 | Defines the horizontal position of the pie. |
|
83 | Defines the horizontal position of the pie. | |
83 |
|
84 | |||
84 | The value is a relative value to the chart rectangle where: |
|
85 | The value is a relative value to the chart rectangle where: | |
85 |
|
86 | |||
86 | \list |
|
87 | \list | |
87 | \o 0.0 is the absolute left. |
|
88 | \o 0.0 is the absolute left. | |
88 | \o 1.0 is the absolute right. |
|
89 | \o 1.0 is the absolute right. | |
89 | \endlist |
|
90 | \endlist | |
90 | Default value is 0.5 (center). |
|
91 | Default value is 0.5 (center). | |
91 | \sa verticalPosition |
|
92 | \sa verticalPosition | |
92 | */ |
|
93 | */ | |
93 |
|
94 | |||
94 | /*! |
|
95 | /*! | |
95 | \property QPieSeries::verticalPosition |
|
96 | \property QPieSeries::verticalPosition | |
96 | \brief Defines the vertical position of the pie. |
|
97 | \brief Defines the vertical position of the pie. | |
97 |
|
98 | |||
98 | The value is a relative value to the chart rectangle where: |
|
99 | The value is a relative value to the chart rectangle where: | |
99 |
|
100 | |||
100 | \list |
|
101 | \list | |
101 | \o 0.0 is the absolute top. |
|
102 | \o 0.0 is the absolute top. | |
102 | \o 1.0 is the absolute bottom. |
|
103 | \o 1.0 is the absolute bottom. | |
103 | \endlist |
|
104 | \endlist | |
104 | Default value is 0.5 (center). |
|
105 | Default value is 0.5 (center). | |
105 | \sa horizontalPosition |
|
106 | \sa horizontalPosition | |
106 | */ |
|
107 | */ | |
107 |
|
108 | |||
108 | /*! |
|
109 | /*! | |
109 | \qmlproperty real PieSeries::verticalPosition |
|
110 | \qmlproperty real PieSeries::verticalPosition | |
110 |
|
111 | |||
111 | Defines the vertical position of the pie. |
|
112 | Defines the vertical position of the pie. | |
112 |
|
113 | |||
113 | The value is a relative value to the chart rectangle where: |
|
114 | The value is a relative value to the chart rectangle where: | |
114 |
|
115 | |||
115 | \list |
|
116 | \list | |
116 | \o 0.0 is the absolute top. |
|
117 | \o 0.0 is the absolute top. | |
117 | \o 1.0 is the absolute bottom. |
|
118 | \o 1.0 is the absolute bottom. | |
118 | \endlist |
|
119 | \endlist | |
119 | Default value is 0.5 (center). |
|
120 | Default value is 0.5 (center). | |
120 | \sa horizontalPosition |
|
121 | \sa horizontalPosition | |
121 | */ |
|
122 | */ | |
122 |
|
123 | |||
123 | /*! |
|
124 | /*! | |
124 | \property QPieSeries::size |
|
125 | \property QPieSeries::size | |
125 | \brief Defines the pie size. |
|
126 | \brief Defines the pie size. | |
126 |
|
127 | |||
127 | The value is a relative value to the chart rectangle where: |
|
128 | The value is a relative value to the chart rectangle where: | |
128 |
|
129 | |||
129 | \list |
|
130 | \list | |
130 | \o 0.0 is the minimum size (pie not drawn). |
|
131 | \o 0.0 is the minimum size (pie not drawn). | |
131 | \o 1.0 is the maximum size that can fit the chart. |
|
132 | \o 1.0 is the maximum size that can fit the chart. | |
132 | \endlist |
|
133 | \endlist | |
133 |
|
134 | |||
134 | Default value is 0.7. |
|
135 | Default value is 0.7. | |
135 | */ |
|
136 | */ | |
136 |
|
137 | |||
137 | /*! |
|
138 | /*! | |
138 | \qmlproperty real PieSeries::size |
|
139 | \qmlproperty real PieSeries::size | |
139 |
|
140 | |||
140 | Defines the pie size. |
|
141 | Defines the pie size. | |
141 |
|
142 | |||
142 | The value is a relative value to the chart rectangle where: |
|
143 | The value is a relative value to the chart rectangle where: | |
143 |
|
144 | |||
144 | \list |
|
145 | \list | |
145 | \o 0.0 is the minimum size (pie not drawn). |
|
146 | \o 0.0 is the minimum size (pie not drawn). | |
146 | \o 1.0 is the maximum size that can fit the chart. |
|
147 | \o 1.0 is the maximum size that can fit the chart. | |
147 | \endlist |
|
148 | \endlist | |
148 |
|
149 | |||
149 | Default value is 0.7. |
|
150 | Default value is 0.7. | |
150 | */ |
|
151 | */ | |
151 |
|
152 | |||
152 | /*! |
|
153 | /*! | |
153 | \property QPieSeries::startAngle |
|
154 | \property QPieSeries::startAngle | |
154 | \brief Defines the starting angle of the pie. |
|
155 | \brief Defines the starting angle of the pie. | |
155 |
|
156 | |||
156 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
157 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
157 |
|
158 | |||
158 | Default is value is 0. |
|
159 | Default is value is 0. | |
159 | */ |
|
160 | */ | |
160 |
|
161 | |||
161 | /*! |
|
162 | /*! | |
162 | \qmlproperty real PieSeries::startAngle |
|
163 | \qmlproperty real PieSeries::startAngle | |
163 |
|
164 | |||
164 | Defines the starting angle of the pie. |
|
165 | Defines the starting angle of the pie. | |
165 |
|
166 | |||
166 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
167 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
167 |
|
168 | |||
168 | Default is value is 0. |
|
169 | Default is value is 0. | |
169 | */ |
|
170 | */ | |
170 |
|
171 | |||
171 | /*! |
|
172 | /*! | |
172 | \property QPieSeries::endAngle |
|
173 | \property QPieSeries::endAngle | |
173 | \brief Defines the ending angle of the pie. |
|
174 | \brief Defines the ending angle of the pie. | |
174 |
|
175 | |||
175 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
176 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
176 |
|
177 | |||
177 | Default is value is 360. |
|
178 | Default is value is 360. | |
178 | */ |
|
179 | */ | |
179 |
|
180 | |||
180 | /*! |
|
181 | /*! | |
181 | \qmlproperty real PieSeries::endAngle |
|
182 | \qmlproperty real PieSeries::endAngle | |
182 |
|
183 | |||
183 | Defines the ending angle of the pie. |
|
184 | Defines the ending angle of the pie. | |
184 |
|
185 | |||
185 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
186 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
186 |
|
187 | |||
187 | Default is value is 360. |
|
188 | Default is value is 360. | |
188 | */ |
|
189 | */ | |
189 |
|
190 | |||
190 | /*! |
|
191 | /*! | |
191 | \property QPieSeries::count |
|
192 | \property QPieSeries::count | |
192 |
|
193 | |||
193 | Number of slices in the series. |
|
194 | Number of slices in the series. | |
194 | */ |
|
195 | */ | |
195 |
|
196 | |||
196 | /*! |
|
197 | /*! | |
197 | \qmlproperty int PieSeries::count |
|
198 | \qmlproperty int PieSeries::count | |
198 |
|
199 | |||
199 | Number of slices in the series. |
|
200 | Number of slices in the series. | |
200 | */ |
|
201 | */ | |
201 |
|
202 | |||
202 | /*! |
|
203 | /*! | |
203 | \fn void QPieSeries::countChanged() |
|
204 | \fn void QPieSeries::countChanged() | |
204 | Emitted when the slice count has changed. |
|
205 | Emitted when the slice count has changed. | |
205 | \sa count |
|
206 | \sa count | |
206 | */ |
|
207 | */ | |
207 | /*! |
|
208 | /*! | |
208 | \qmlsignal PieSeries::onCountChanged() |
|
209 | \qmlsignal PieSeries::onCountChanged() | |
209 | Emitted when the slice count has changed. |
|
210 | Emitted when the slice count has changed. | |
210 | */ |
|
211 | */ | |
211 |
|
212 | |||
212 | /*! |
|
213 | /*! | |
213 | \property QPieSeries::sum |
|
214 | \property QPieSeries::sum | |
214 |
|
215 | |||
215 | Sum of all slices. |
|
216 | Sum of all slices. | |
216 |
|
217 | |||
217 | The series keeps track of the sum of all slices it holds. |
|
218 | The series keeps track of the sum of all slices it holds. | |
218 | */ |
|
219 | */ | |
219 |
|
220 | |||
220 | /*! |
|
221 | /*! | |
221 | \qmlproperty real PieSeries::sum |
|
222 | \qmlproperty real PieSeries::sum | |
222 |
|
223 | |||
223 | Sum of all slices. |
|
224 | Sum of all slices. | |
224 |
|
225 | |||
225 | The series keeps track of the sum of all slices it holds. |
|
226 | The series keeps track of the sum of all slices it holds. | |
226 | */ |
|
227 | */ | |
227 |
|
228 | |||
228 | /*! |
|
229 | /*! | |
229 | \fn void QPieSeries::sumChanged() |
|
230 | \fn void QPieSeries::sumChanged() | |
230 | Emitted when the sum of all slices has changed. |
|
231 | Emitted when the sum of all slices has changed. | |
231 | \sa sum |
|
232 | \sa sum | |
232 | */ |
|
233 | */ | |
233 | /*! |
|
234 | /*! | |
234 | \qmlsignal PieSeries::onSumChanged() |
|
235 | \qmlsignal PieSeries::onSumChanged() | |
235 | Emitted when the sum of all slices has changed. This may happen for example if you add or remove slices, or if you |
|
236 | Emitted when the sum of all slices has changed. This may happen for example if you add or remove slices, or if you | |
236 | change value of a slice. |
|
237 | change value of a slice. | |
237 | */ |
|
238 | */ | |
238 |
|
239 | |||
239 | /*! |
|
240 | /*! | |
240 | \fn void QPieSeries::added(QList<QPieSlice*> slices) |
|
241 | \fn void QPieSeries::added(QList<QPieSlice*> slices) | |
241 |
|
242 | |||
242 | This signal is emitted when \a slices have been added to the series. |
|
243 | This signal is emitted when \a slices have been added to the series. | |
243 |
|
244 | |||
244 | \sa append(), insert() |
|
245 | \sa append(), insert() | |
245 | */ |
|
246 | */ | |
246 | /*! |
|
247 | /*! | |
247 | \qmlsignal PieSeries::onAdded(PieSlice slice) |
|
248 | \qmlsignal PieSeries::onAdded(PieSlice slice) | |
248 | Emitted when \a slice has been added to the series. |
|
249 | Emitted when \a slice has been added to the series. | |
249 | */ |
|
250 | */ | |
250 |
|
251 | |||
251 | /*! |
|
252 | /*! | |
252 | \fn void QPieSeries::removed(QList<QPieSlice*> slices) |
|
253 | \fn void QPieSeries::removed(QList<QPieSlice*> slices) | |
253 | This signal is emitted when \a slices have been removed from the series. |
|
254 | This signal is emitted when \a slices have been removed from the series. | |
254 | \sa remove() |
|
255 | \sa remove() | |
255 | */ |
|
256 | */ | |
256 | /*! |
|
257 | /*! | |
257 | \qmlsignal PieSeries::onRemoved(PieSlice slice) |
|
258 | \qmlsignal PieSeries::onRemoved(PieSlice slice) | |
258 | Emitted when \a slice has been removed from the series. |
|
259 | Emitted when \a slice has been removed from the series. | |
259 | */ |
|
260 | */ | |
260 |
|
261 | |||
261 | /*! |
|
262 | /*! | |
262 | \fn void QPieSeries::clicked(QPieSlice* slice) |
|
263 | \fn void QPieSeries::clicked(QPieSlice* slice) | |
263 | This signal is emitted when a \a slice has been clicked. |
|
264 | This signal is emitted when a \a slice has been clicked. | |
264 | \sa QPieSlice::clicked() |
|
265 | \sa QPieSlice::clicked() | |
265 | */ |
|
266 | */ | |
266 | /*! |
|
267 | /*! | |
267 | \qmlsignal PieSeries::onClicked(PieSlice slice) |
|
268 | \qmlsignal PieSeries::onClicked(PieSlice slice) | |
268 | This signal is emitted when a \a slice has been clicked. |
|
269 | This signal is emitted when a \a slice has been clicked. | |
269 | */ |
|
270 | */ | |
270 |
|
271 | |||
271 | /*! |
|
272 | /*! | |
272 | \fn void QPieSeries::hovered(QPieSlice* slice, bool state) |
|
273 | \fn void QPieSeries::hovered(QPieSlice* slice, bool state) | |
273 | This signal is emitted when user has hovered over or away from the \a slice. |
|
274 | This signal is emitted when user has hovered over or away from the \a slice. | |
274 | \a state is true when user has hovered over the slice and false when hover has moved away from the slice. |
|
275 | \a state is true when user has hovered over the slice and false when hover has moved away from the slice. | |
275 | \sa QPieSlice::hovered() |
|
276 | \sa QPieSlice::hovered() | |
276 | */ |
|
277 | */ | |
277 | /*! |
|
278 | /*! | |
278 | \qmlsignal PieSeries::onHovered(PieSlice slice, bool state) |
|
279 | \qmlsignal PieSeries::onHovered(PieSlice slice, bool state) | |
279 | This signal is emitted when user has hovered over or away from the \a slice. \a state is true when user has hovered |
|
280 | This signal is emitted when user has hovered over or away from the \a slice. \a state is true when user has hovered | |
280 | over the slice and false when hover has moved away from the slice. |
|
281 | over the slice and false when hover has moved away from the slice. | |
281 | */ |
|
282 | */ | |
282 |
|
283 | |||
283 | /*! |
|
284 | /*! | |
284 | \qmlmethod PieSlice PieSeries::at(int index) |
|
285 | \qmlmethod PieSlice PieSeries::at(int index) | |
285 | Returns slice at \a index. Returns null if the index is not valid. |
|
286 | Returns slice at \a index. Returns null if the index is not valid. | |
286 | */ |
|
287 | */ | |
287 |
|
288 | |||
288 | /*! |
|
289 | /*! | |
289 | \qmlmethod PieSlice PieSeries::find(string label) |
|
290 | \qmlmethod PieSlice PieSeries::find(string label) | |
290 | Returns the first slice with \a label. Returns null if the index is not valid. |
|
291 | Returns the first slice with \a label. Returns null if the index is not valid. | |
291 | */ |
|
292 | */ | |
292 |
|
293 | |||
293 | /*! |
|
294 | /*! | |
294 | \qmlmethod PieSlice PieSeries::append(string label, real value) |
|
295 | \qmlmethod PieSlice PieSeries::append(string label, real value) | |
295 | Adds a new slice with \a label and \a value to the pie. |
|
296 | Adds a new slice with \a label and \a value to the pie. | |
296 | */ |
|
297 | */ | |
297 |
|
298 | |||
298 | /*! |
|
299 | /*! | |
299 | \qmlmethod bool PieSeries::remove(PieSlice slice) |
|
300 | \qmlmethod bool PieSeries::remove(PieSlice slice) | |
300 | Removes the \a slice from the pie. Returns true if the removal was successfull, false otherwise. |
|
301 | Removes the \a slice from the pie. Returns true if the removal was successfull, false otherwise. | |
301 | */ |
|
302 | */ | |
302 |
|
303 | |||
303 | /*! |
|
304 | /*! | |
304 | \qmlmethod PieSeries::clear() |
|
305 | \qmlmethod PieSeries::clear() | |
305 | Removes all slices from the pie. |
|
306 | Removes all slices from the pie. | |
306 | */ |
|
307 | */ | |
307 |
|
308 | |||
308 | /*! |
|
309 | /*! | |
309 | Constructs a series object which is a child of \a parent. |
|
310 | Constructs a series object which is a child of \a parent. | |
310 | */ |
|
311 | */ | |
311 | QPieSeries::QPieSeries(QObject *parent) : |
|
312 | QPieSeries::QPieSeries(QObject *parent) : | |
312 | QAbstractSeries(*new QPieSeriesPrivate(this),parent) |
|
313 | QAbstractSeries(*new QPieSeriesPrivate(this),parent) | |
313 | { |
|
314 | { | |
314 |
|
315 | |||
315 | } |
|
316 | } | |
316 |
|
317 | |||
317 | /*! |
|
318 | /*! | |
318 | Destroys the series and its slices. |
|
319 | Destroys the series and its slices. | |
319 | */ |
|
320 | */ | |
320 | QPieSeries::~QPieSeries() |
|
321 | QPieSeries::~QPieSeries() | |
321 | { |
|
322 | { | |
322 | // NOTE: d_prt destroyed by QObject |
|
323 | // NOTE: d_prt destroyed by QObject | |
323 | } |
|
324 | } | |
324 |
|
325 | |||
325 | /*! |
|
326 | /*! | |
326 | Returns QChartSeries::SeriesTypePie. |
|
327 | Returns QChartSeries::SeriesTypePie. | |
327 | */ |
|
328 | */ | |
328 | QAbstractSeries::SeriesType QPieSeries::type() const |
|
329 | QAbstractSeries::SeriesType QPieSeries::type() const | |
329 | { |
|
330 | { | |
330 | return QAbstractSeries::SeriesTypePie; |
|
331 | return QAbstractSeries::SeriesTypePie; | |
331 | } |
|
332 | } | |
332 |
|
333 | |||
333 | /*! |
|
334 | /*! | |
334 | Appends a single \a slice to the series. |
|
335 | Appends a single \a slice to the series. | |
335 | Slice ownership is passed to the series. |
|
336 | Slice ownership is passed to the series. | |
336 |
|
337 | |||
337 | Returns true if append was succesfull. |
|
338 | Returns true if append was succesfull. | |
338 | */ |
|
339 | */ | |
339 | bool QPieSeries::append(QPieSlice* slice) |
|
340 | bool QPieSeries::append(QPieSlice* slice) | |
340 | { |
|
341 | { | |
341 | return append(QList<QPieSlice*>() << slice); |
|
342 | return append(QList<QPieSlice*>() << slice); | |
342 | } |
|
343 | } | |
343 |
|
344 | |||
344 | /*! |
|
345 | /*! | |
345 | Appends an array of \a slices to the series. |
|
346 | Appends an array of \a slices to the series. | |
346 | Slice ownership is passed to the series. |
|
347 | Slice ownership is passed to the series. | |
347 |
|
348 | |||
348 | Returns true if append was successfull. |
|
349 | Returns true if append was successfull. | |
349 | */ |
|
350 | */ | |
350 | bool QPieSeries::append(QList<QPieSlice*> slices) |
|
351 | bool QPieSeries::append(QList<QPieSlice*> slices) | |
351 | { |
|
352 | { | |
352 | Q_D(QPieSeries); |
|
353 | Q_D(QPieSeries); | |
353 |
|
354 | |||
354 | if (slices.count() == 0) |
|
355 | if (slices.count() == 0) | |
355 | return false; |
|
356 | return false; | |
356 |
|
357 | |||
357 | foreach (QPieSlice* s, slices) { |
|
358 | foreach (QPieSlice* s, slices) { | |
358 | if (!s || d->m_slices.contains(s)) |
|
359 | if (!s || d->m_slices.contains(s)) | |
359 | return false; |
|
360 | return false; | |
360 | if (s->series()) // already added to some series |
|
361 | if (s->series()) // already added to some series | |
361 | return false; |
|
362 | return false; | |
362 | } |
|
363 | } | |
363 |
|
364 | |||
364 | foreach (QPieSlice* s, slices) { |
|
365 | foreach (QPieSlice* s, slices) { | |
365 | s->setParent(this); |
|
366 | s->setParent(this); | |
366 | QPieSlicePrivate::fromSlice(s)->m_series = this; |
|
367 | QPieSlicePrivate::fromSlice(s)->m_series = this; | |
367 | d->m_slices << s; |
|
368 | d->m_slices << s; | |
368 | } |
|
369 | } | |
369 |
|
370 | |||
370 | d->updateDerivativeData(); |
|
371 | d->updateDerivativeData(); | |
371 |
|
372 | |||
372 | foreach (QPieSlice* s, slices) { |
|
373 | foreach (QPieSlice* s, slices) { | |
373 | connect(s, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged())); |
|
374 | connect(s, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged())); | |
374 | connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked())); |
|
375 | connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked())); | |
375 | connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool))); |
|
376 | connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool))); | |
376 | } |
|
377 | } | |
377 |
|
378 | |||
378 | emit added(slices); |
|
379 | emit added(slices); | |
379 | emit countChanged(); |
|
380 | emit countChanged(); | |
380 |
|
381 | |||
381 | return true; |
|
382 | return true; | |
382 | } |
|
383 | } | |
383 |
|
384 | |||
384 | /*! |
|
385 | /*! | |
385 | Appends a single \a slice to the series and returns a reference to the series. |
|
386 | Appends a single \a slice to the series and returns a reference to the series. | |
386 | Slice ownership is passed to the series. |
|
387 | Slice ownership is passed to the series. | |
387 | */ |
|
388 | */ | |
388 | QPieSeries& QPieSeries::operator << (QPieSlice* slice) |
|
389 | QPieSeries& QPieSeries::operator << (QPieSlice* slice) | |
389 | { |
|
390 | { | |
390 | append(slice); |
|
391 | append(slice); | |
391 | return *this; |
|
392 | return *this; | |
392 | } |
|
393 | } | |
393 |
|
394 | |||
394 |
|
395 | |||
395 | /*! |
|
396 | /*! | |
396 | Appends a single slice to the series with give \a value and \a label. |
|
397 | Appends a single slice to the series with give \a value and \a label. | |
397 | Slice ownership is passed to the series. |
|
398 | Slice ownership is passed to the series. | |
398 | */ |
|
399 | */ | |
399 | QPieSlice* QPieSeries::append(QString label, qreal value) |
|
400 | QPieSlice* QPieSeries::append(QString label, qreal value) | |
400 | { |
|
401 | { | |
401 | QPieSlice* slice = new QPieSlice(label, value); |
|
402 | QPieSlice* slice = new QPieSlice(label, value); | |
402 | append(slice); |
|
403 | append(slice); | |
403 | return slice; |
|
404 | return slice; | |
404 | } |
|
405 | } | |
405 |
|
406 | |||
406 | /*! |
|
407 | /*! | |
407 | Inserts a single \a slice to the series before the slice at \a index position. |
|
408 | Inserts a single \a slice to the series before the slice at \a index position. | |
408 | Slice ownership is passed to the series. |
|
409 | Slice ownership is passed to the series. | |
409 |
|
410 | |||
410 | Returns true if insert was successfull. |
|
411 | Returns true if insert was successfull. | |
411 | */ |
|
412 | */ | |
412 | bool QPieSeries::insert(int index, QPieSlice* slice) |
|
413 | bool QPieSeries::insert(int index, QPieSlice* slice) | |
413 | { |
|
414 | { | |
414 | Q_D(QPieSeries); |
|
415 | Q_D(QPieSeries); | |
415 |
|
416 | |||
416 | if (index < 0 || index > d->m_slices.count()) |
|
417 | if (index < 0 || index > d->m_slices.count()) | |
417 | return false; |
|
418 | return false; | |
418 |
|
419 | |||
419 | if (!slice || d->m_slices.contains(slice)) |
|
420 | if (!slice || d->m_slices.contains(slice)) | |
420 | return false; |
|
421 | return false; | |
421 |
|
422 | |||
422 | if (slice->series()) // already added to some series |
|
423 | if (slice->series()) // already added to some series | |
423 | return false; |
|
424 | return false; | |
424 |
|
425 | |||
425 | slice->setParent(this); |
|
426 | slice->setParent(this); | |
426 | QPieSlicePrivate::fromSlice(slice)->m_series = this; |
|
427 | QPieSlicePrivate::fromSlice(slice)->m_series = this; | |
427 | d->m_slices.insert(index, slice); |
|
428 | d->m_slices.insert(index, slice); | |
428 |
|
429 | |||
429 | d->updateDerivativeData(); |
|
430 | d->updateDerivativeData(); | |
430 |
|
431 | |||
431 | connect(slice, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged())); |
|
432 | connect(slice, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged())); | |
432 | connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked())); |
|
433 | connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked())); | |
433 | connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool))); |
|
434 | connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool))); | |
434 |
|
435 | |||
435 | emit added(QList<QPieSlice*>() << slice); |
|
436 | emit added(QList<QPieSlice*>() << slice); | |
436 | emit countChanged(); |
|
437 | emit countChanged(); | |
437 |
|
438 | |||
438 | return true; |
|
439 | return true; | |
439 | } |
|
440 | } | |
440 |
|
441 | |||
441 | /*! |
|
442 | /*! | |
442 | Removes a single \a slice from the series and deletes the slice. |
|
443 | Removes a single \a slice from the series and deletes the slice. | |
443 |
|
444 | |||
444 | Do not reference the pointer after this call. |
|
445 | Do not reference the pointer after this call. | |
445 |
|
446 | |||
446 | Returns true if remove was successfull. |
|
447 | Returns true if remove was successfull. | |
447 | */ |
|
448 | */ | |
448 | bool QPieSeries::remove(QPieSlice* slice) |
|
449 | bool QPieSeries::remove(QPieSlice* slice) | |
449 | { |
|
450 | { | |
450 | Q_D(QPieSeries); |
|
451 | Q_D(QPieSeries); | |
451 |
|
452 | |||
452 | if (!d->m_slices.removeOne(slice)) |
|
453 | if (!d->m_slices.removeOne(slice)) | |
453 | return false; |
|
454 | return false; | |
454 |
|
455 | |||
455 | d->updateDerivativeData(); |
|
456 | d->updateDerivativeData(); | |
456 |
|
457 | |||
457 | emit removed(QList<QPieSlice*>() << slice); |
|
458 | emit removed(QList<QPieSlice*>() << slice); | |
458 | emit countChanged(); |
|
459 | emit countChanged(); | |
459 |
|
460 | |||
460 | delete slice; |
|
461 | delete slice; | |
461 | slice = 0; |
|
462 | slice = 0; | |
462 |
|
463 | |||
463 | return true; |
|
464 | return true; | |
464 | } |
|
465 | } | |
465 |
|
466 | |||
466 | /*! |
|
467 | /*! | |
467 | Clears all slices from the series. |
|
468 | Clears all slices from the series. | |
468 | */ |
|
469 | */ | |
469 | void QPieSeries::clear() |
|
470 | void QPieSeries::clear() | |
470 | { |
|
471 | { | |
471 | Q_D(QPieSeries); |
|
472 | Q_D(QPieSeries); | |
472 | if (d->m_slices.count() == 0) |
|
473 | if (d->m_slices.count() == 0) | |
473 | return; |
|
474 | return; | |
474 |
|
475 | |||
475 | QList<QPieSlice*> slices = d->m_slices; |
|
476 | QList<QPieSlice*> slices = d->m_slices; | |
476 | foreach (QPieSlice* s, d->m_slices) { |
|
477 | foreach (QPieSlice* s, d->m_slices) { | |
477 | d->m_slices.removeOne(s); |
|
478 | d->m_slices.removeOne(s); | |
478 | delete s; |
|
479 | delete s; | |
479 | } |
|
480 | } | |
480 |
|
481 | |||
481 | d->updateDerivativeData(); |
|
482 | d->updateDerivativeData(); | |
482 |
|
483 | |||
483 | emit removed(slices); |
|
484 | emit removed(slices); | |
484 | emit countChanged(); |
|
485 | emit countChanged(); | |
485 | } |
|
486 | } | |
486 |
|
487 | |||
487 | /*! |
|
488 | /*! | |
488 | Returns a list of slices that belong to this series. |
|
489 | Returns a list of slices that belong to this series. | |
489 | */ |
|
490 | */ | |
490 | QList<QPieSlice*> QPieSeries::slices() const |
|
491 | QList<QPieSlice*> QPieSeries::slices() const | |
491 | { |
|
492 | { | |
492 | Q_D(const QPieSeries); |
|
493 | Q_D(const QPieSeries); | |
493 | return d->m_slices; |
|
494 | return d->m_slices; | |
494 | } |
|
495 | } | |
495 |
|
496 | |||
496 | /*! |
|
497 | /*! | |
497 | returns the number of the slices in this series. |
|
498 | returns the number of the slices in this series. | |
498 | */ |
|
499 | */ | |
499 | int QPieSeries::count() const |
|
500 | int QPieSeries::count() const | |
500 | { |
|
501 | { | |
501 | Q_D(const QPieSeries); |
|
502 | Q_D(const QPieSeries); | |
502 | return d->m_slices.count(); |
|
503 | return d->m_slices.count(); | |
503 | } |
|
504 | } | |
504 |
|
505 | |||
505 | /*! |
|
506 | /*! | |
506 | Returns true is the series is empty. |
|
507 | Returns true is the series is empty. | |
507 | */ |
|
508 | */ | |
508 | bool QPieSeries::isEmpty() const |
|
509 | bool QPieSeries::isEmpty() const | |
509 | { |
|
510 | { | |
510 | Q_D(const QPieSeries); |
|
511 | Q_D(const QPieSeries); | |
511 | return d->m_slices.isEmpty(); |
|
512 | return d->m_slices.isEmpty(); | |
512 | } |
|
513 | } | |
513 |
|
514 | |||
514 | /*! |
|
515 | /*! | |
515 | Returns the sum of all slice values in this series. |
|
516 | Returns the sum of all slice values in this series. | |
516 |
|
517 | |||
517 | \sa QPieSlice::value(), QPieSlice::setValue(), QPieSlice::percentage() |
|
518 | \sa QPieSlice::value(), QPieSlice::setValue(), QPieSlice::percentage() | |
518 | */ |
|
519 | */ | |
519 | qreal QPieSeries::sum() const |
|
520 | qreal QPieSeries::sum() const | |
520 | { |
|
521 | { | |
521 | Q_D(const QPieSeries); |
|
522 | Q_D(const QPieSeries); | |
522 | return d->m_sum; |
|
523 | return d->m_sum; | |
523 | } |
|
524 | } | |
524 |
|
525 | |||
525 | void QPieSeries::setHorizontalPosition(qreal relativePosition) |
|
526 | void QPieSeries::setHorizontalPosition(qreal relativePosition) | |
526 | { |
|
527 | { | |
527 | Q_D(QPieSeries); |
|
528 | Q_D(QPieSeries); | |
528 |
|
529 | |||
529 | if (relativePosition < 0.0) |
|
530 | if (relativePosition < 0.0) | |
530 | relativePosition = 0.0; |
|
531 | relativePosition = 0.0; | |
531 | if (relativePosition > 1.0) |
|
532 | if (relativePosition > 1.0) | |
532 | relativePosition = 1.0; |
|
533 | relativePosition = 1.0; | |
533 |
|
534 | |||
534 | if (!qFuzzyIsNull(d->m_pieRelativeHorPos - relativePosition)) { |
|
535 | if (!qFuzzyIsNull(d->m_pieRelativeHorPos - relativePosition)) { | |
535 | d->m_pieRelativeHorPos = relativePosition; |
|
536 | d->m_pieRelativeHorPos = relativePosition; | |
536 | emit d->horizontalPositionChanged(); |
|
537 | emit d->horizontalPositionChanged(); | |
537 | } |
|
538 | } | |
538 | } |
|
539 | } | |
539 |
|
540 | |||
540 | qreal QPieSeries::horizontalPosition() const |
|
541 | qreal QPieSeries::horizontalPosition() const | |
541 | { |
|
542 | { | |
542 | Q_D(const QPieSeries); |
|
543 | Q_D(const QPieSeries); | |
543 | return d->m_pieRelativeHorPos; |
|
544 | return d->m_pieRelativeHorPos; | |
544 | } |
|
545 | } | |
545 |
|
546 | |||
546 | void QPieSeries::setVerticalPosition(qreal relativePosition) |
|
547 | void QPieSeries::setVerticalPosition(qreal relativePosition) | |
547 | { |
|
548 | { | |
548 | Q_D(QPieSeries); |
|
549 | Q_D(QPieSeries); | |
549 |
|
550 | |||
550 | if (relativePosition < 0.0) |
|
551 | if (relativePosition < 0.0) | |
551 | relativePosition = 0.0; |
|
552 | relativePosition = 0.0; | |
552 | if (relativePosition > 1.0) |
|
553 | if (relativePosition > 1.0) | |
553 | relativePosition = 1.0; |
|
554 | relativePosition = 1.0; | |
554 |
|
555 | |||
555 | if (!qFuzzyIsNull(d->m_pieRelativeVerPos - relativePosition)) { |
|
556 | if (!qFuzzyIsNull(d->m_pieRelativeVerPos - relativePosition)) { | |
556 | d->m_pieRelativeVerPos = relativePosition; |
|
557 | d->m_pieRelativeVerPos = relativePosition; | |
557 | emit d->verticalPositionChanged(); |
|
558 | emit d->verticalPositionChanged(); | |
558 | } |
|
559 | } | |
559 | } |
|
560 | } | |
560 |
|
561 | |||
561 | qreal QPieSeries::verticalPosition() const |
|
562 | qreal QPieSeries::verticalPosition() const | |
562 | { |
|
563 | { | |
563 | Q_D(const QPieSeries); |
|
564 | Q_D(const QPieSeries); | |
564 | return d->m_pieRelativeVerPos; |
|
565 | return d->m_pieRelativeVerPos; | |
565 | } |
|
566 | } | |
566 |
|
567 | |||
567 | void QPieSeries::setPieSize(qreal relativeSize) |
|
568 | void QPieSeries::setPieSize(qreal relativeSize) | |
568 | { |
|
569 | { | |
569 | Q_D(QPieSeries); |
|
570 | Q_D(QPieSeries); | |
570 |
|
571 | |||
571 | if (relativeSize < 0.0) |
|
572 | if (relativeSize < 0.0) | |
572 | relativeSize = 0.0; |
|
573 | relativeSize = 0.0; | |
573 | if (relativeSize > 1.0) |
|
574 | if (relativeSize > 1.0) | |
574 | relativeSize = 1.0; |
|
575 | relativeSize = 1.0; | |
575 |
|
576 | |||
576 | if (!qFuzzyIsNull(d->m_pieRelativeSize - relativeSize)) { |
|
577 | if (!qFuzzyIsNull(d->m_pieRelativeSize - relativeSize)) { | |
577 | d->m_pieRelativeSize = relativeSize; |
|
578 | d->m_pieRelativeSize = relativeSize; | |
578 | emit d->pieSizeChanged(); |
|
579 | emit d->pieSizeChanged(); | |
579 | } |
|
580 | } | |
580 | } |
|
581 | } | |
581 |
|
582 | |||
582 | qreal QPieSeries::pieSize() const |
|
583 | qreal QPieSeries::pieSize() const | |
583 | { |
|
584 | { | |
584 | Q_D(const QPieSeries); |
|
585 | Q_D(const QPieSeries); | |
585 | return d->m_pieRelativeSize; |
|
586 | return d->m_pieRelativeSize; | |
586 | } |
|
587 | } | |
587 |
|
588 | |||
588 |
|
589 | |||
589 | void QPieSeries::setPieStartAngle(qreal angle) |
|
590 | void QPieSeries::setPieStartAngle(qreal angle) | |
590 | { |
|
591 | { | |
591 | Q_D(QPieSeries); |
|
592 | Q_D(QPieSeries); | |
592 | if (qFuzzyIsNull(d->m_pieStartAngle - angle)) |
|
593 | if (qFuzzyIsNull(d->m_pieStartAngle - angle)) | |
593 | return; |
|
594 | return; | |
594 | d->m_pieStartAngle = angle; |
|
595 | d->m_pieStartAngle = angle; | |
595 | d->updateDerivativeData(); |
|
596 | d->updateDerivativeData(); | |
596 | emit d->pieStartAngleChanged(); |
|
597 | emit d->pieStartAngleChanged(); | |
597 | } |
|
598 | } | |
598 |
|
599 | |||
599 | qreal QPieSeries::pieStartAngle() const |
|
600 | qreal QPieSeries::pieStartAngle() const | |
600 | { |
|
601 | { | |
601 | Q_D(const QPieSeries); |
|
602 | Q_D(const QPieSeries); | |
602 | return d->m_pieStartAngle; |
|
603 | return d->m_pieStartAngle; | |
603 | } |
|
604 | } | |
604 |
|
605 | |||
605 | /*! |
|
606 | /*! | |
606 | Sets the end angle of the pie. |
|
607 | Sets the end angle of the pie. | |
607 |
|
608 | |||
608 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
609 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
609 |
|
610 | |||
610 | \a angle must be greater than start angle. |
|
611 | \a angle must be greater than start angle. | |
611 |
|
612 | |||
612 | \sa pieEndAngle(), pieStartAngle(), setPieStartAngle() |
|
613 | \sa pieEndAngle(), pieStartAngle(), setPieStartAngle() | |
613 | */ |
|
614 | */ | |
614 | void QPieSeries::setPieEndAngle(qreal angle) |
|
615 | void QPieSeries::setPieEndAngle(qreal angle) | |
615 | { |
|
616 | { | |
616 | Q_D(QPieSeries); |
|
617 | Q_D(QPieSeries); | |
617 | if (qFuzzyIsNull(d->m_pieEndAngle - angle)) |
|
618 | if (qFuzzyIsNull(d->m_pieEndAngle - angle)) | |
618 | return; |
|
619 | return; | |
619 | d->m_pieEndAngle = angle; |
|
620 | d->m_pieEndAngle = angle; | |
620 | d->updateDerivativeData(); |
|
621 | d->updateDerivativeData(); | |
621 | emit d->pieEndAngleChanged(); |
|
622 | emit d->pieEndAngleChanged(); | |
622 | } |
|
623 | } | |
623 |
|
624 | |||
624 | /*! |
|
625 | /*! | |
625 | Returns the end angle of the pie. |
|
626 | Returns the end angle of the pie. | |
626 |
|
627 | |||
627 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
628 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
628 |
|
629 | |||
629 | \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle() |
|
630 | \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle() | |
630 | */ |
|
631 | */ | |
631 | qreal QPieSeries::pieEndAngle() const |
|
632 | qreal QPieSeries::pieEndAngle() const | |
632 | { |
|
633 | { | |
633 | Q_D(const QPieSeries); |
|
634 | Q_D(const QPieSeries); | |
634 | return d->m_pieEndAngle; |
|
635 | return d->m_pieEndAngle; | |
635 | } |
|
636 | } | |
636 |
|
637 | |||
637 | /*! |
|
638 | /*! | |
638 | Sets the all the slice labels \a visible or invisible. |
|
639 | Sets the all the slice labels \a visible or invisible. | |
639 |
|
640 | |||
640 | Note that this affects only the current slices in the series. |
|
641 | Note that this affects only the current slices in the series. | |
641 | If user adds a new slice the default label visibility is false. |
|
642 | If user adds a new slice the default label visibility is false. | |
642 |
|
643 | |||
643 | \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible() |
|
644 | \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible() | |
644 | */ |
|
645 | */ | |
645 | void QPieSeries::setLabelsVisible(bool visible) |
|
646 | void QPieSeries::setLabelsVisible(bool visible) | |
646 | { |
|
647 | { | |
647 | Q_D(QPieSeries); |
|
648 | Q_D(QPieSeries); | |
648 | foreach (QPieSlice* s, d->m_slices) |
|
649 | foreach (QPieSlice* s, d->m_slices) | |
649 | s->setLabelVisible(visible); |
|
650 | s->setLabelVisible(visible); | |
650 | } |
|
651 | } | |
651 |
|
652 | |||
652 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
653 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
653 |
|
654 | |||
654 |
|
655 | |||
655 | QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) : |
|
656 | QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) : | |
656 | QAbstractSeriesPrivate(parent), |
|
657 | QAbstractSeriesPrivate(parent), | |
657 | m_pieRelativeHorPos(0.5), |
|
658 | m_pieRelativeHorPos(0.5), | |
658 | m_pieRelativeVerPos(0.5), |
|
659 | m_pieRelativeVerPos(0.5), | |
659 | m_pieRelativeSize(0.7), |
|
660 | m_pieRelativeSize(0.7), | |
660 | m_pieStartAngle(0), |
|
661 | m_pieStartAngle(0), | |
661 | m_pieEndAngle(360), |
|
662 | m_pieEndAngle(360), | |
662 | m_sum(0) |
|
663 | m_sum(0) | |
663 | { |
|
664 | { | |
664 | } |
|
665 | } | |
665 |
|
666 | |||
666 | QPieSeriesPrivate::~QPieSeriesPrivate() |
|
667 | QPieSeriesPrivate::~QPieSeriesPrivate() | |
667 | { |
|
668 | { | |
668 | } |
|
669 | } | |
669 |
|
670 | |||
670 | void QPieSeriesPrivate::updateDerivativeData() |
|
671 | void QPieSeriesPrivate::updateDerivativeData() | |
671 | { |
|
672 | { | |
672 | // calculate sum of all slices |
|
673 | // calculate sum of all slices | |
673 | qreal sum = 0; |
|
674 | qreal sum = 0; | |
674 | foreach (QPieSlice* s, m_slices) |
|
675 | foreach (QPieSlice* s, m_slices) | |
675 | sum += s->value(); |
|
676 | sum += s->value(); | |
676 |
|
677 | |||
677 | if (!qFuzzyIsNull(m_sum - sum)) { |
|
678 | if (!qFuzzyIsNull(m_sum - sum)) { | |
678 | m_sum = sum; |
|
679 | m_sum = sum; | |
679 | emit q_func()->sumChanged(); |
|
680 | emit q_func()->sumChanged(); | |
680 | } |
|
681 | } | |
681 |
|
682 | |||
682 | // nothing to show.. |
|
683 | // nothing to show.. | |
683 | if (qFuzzyIsNull(m_sum)) |
|
684 | if (qFuzzyIsNull(m_sum)) | |
684 | return; |
|
685 | return; | |
685 |
|
686 | |||
686 | // update slice attributes |
|
687 | // update slice attributes | |
687 | qreal sliceAngle = m_pieStartAngle; |
|
688 | qreal sliceAngle = m_pieStartAngle; | |
688 | qreal pieSpan = m_pieEndAngle - m_pieStartAngle; |
|
689 | qreal pieSpan = m_pieEndAngle - m_pieStartAngle; | |
689 | QVector<QPieSlice*> changed; |
|
690 | QVector<QPieSlice*> changed; | |
690 | foreach (QPieSlice* s, m_slices) { |
|
691 | foreach (QPieSlice* s, m_slices) { | |
691 | QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s); |
|
692 | QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s); | |
692 | d->setPercentage(s->value() / m_sum); |
|
693 | d->setPercentage(s->value() / m_sum); | |
693 | d->setStartAngle(sliceAngle); |
|
694 | d->setStartAngle(sliceAngle); | |
694 | d->setAngleSpan(pieSpan * s->percentage()); |
|
695 | d->setAngleSpan(pieSpan * s->percentage()); | |
695 | sliceAngle += s->angleSpan(); |
|
696 | sliceAngle += s->angleSpan(); | |
696 | } |
|
697 | } | |
697 |
|
698 | |||
698 |
|
699 | |||
699 | emit calculatedDataChanged(); |
|
700 | emit calculatedDataChanged(); | |
700 | } |
|
701 | } | |
701 |
|
702 | |||
702 | QPieSeriesPrivate* QPieSeriesPrivate::fromSeries(QPieSeries *series) |
|
703 | QPieSeriesPrivate* QPieSeriesPrivate::fromSeries(QPieSeries *series) | |
703 | { |
|
704 | { | |
704 | return series->d_func(); |
|
705 | return series->d_func(); | |
705 | } |
|
706 | } | |
706 |
|
707 | |||
707 | void QPieSeriesPrivate::sliceValueChanged() |
|
708 | void QPieSeriesPrivate::sliceValueChanged() | |
708 | { |
|
709 | { | |
709 | Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender()))); |
|
710 | Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender()))); | |
710 | updateDerivativeData(); |
|
711 | updateDerivativeData(); | |
711 | } |
|
712 | } | |
712 |
|
713 | |||
713 | void QPieSeriesPrivate::sliceClicked() |
|
714 | void QPieSeriesPrivate::sliceClicked() | |
714 | { |
|
715 | { | |
715 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); |
|
716 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | |
716 | Q_ASSERT(m_slices.contains(slice)); |
|
717 | Q_ASSERT(m_slices.contains(slice)); | |
717 | Q_Q(QPieSeries); |
|
718 | Q_Q(QPieSeries); | |
718 | emit q->clicked(slice); |
|
719 | emit q->clicked(slice); | |
719 | } |
|
720 | } | |
720 |
|
721 | |||
721 | void QPieSeriesPrivate::sliceHovered(bool state) |
|
722 | void QPieSeriesPrivate::sliceHovered(bool state) | |
722 | { |
|
723 | { | |
723 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); |
|
724 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | |
724 | Q_ASSERT(m_slices.contains(slice)); |
|
725 | Q_ASSERT(m_slices.contains(slice)); | |
725 | Q_Q(QPieSeries); |
|
726 | Q_Q(QPieSeries); | |
726 | emit q->hovered(slice, state); |
|
727 | emit q->hovered(slice, state); | |
727 | } |
|
728 | } | |
728 |
|
729 | |||
729 | void QPieSeriesPrivate::scaleDomain(Domain& domain) |
|
730 | void QPieSeriesPrivate::scaleDomain(Domain& domain) | |
730 | { |
|
731 | { | |
731 | Q_UNUSED(domain); |
|
732 | Q_UNUSED(domain); | |
732 | // does not apply to pie |
|
733 | // does not apply to pie | |
733 | } |
|
734 | } | |
734 |
|
735 | |||
735 | Chart* QPieSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
736 | Chart* QPieSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
736 | { |
|
737 | { | |
737 | Q_Q(QPieSeries); |
|
738 | Q_Q(QPieSeries); | |
738 | PieChartItem* pie = new PieChartItem(q,presenter); |
|
739 | PieChartItem* pie = new PieChartItem(q,presenter); | |
739 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
740 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
740 | presenter->animator()->addAnimation(pie); |
|
741 | presenter->animator()->addAnimation(pie); | |
741 | } |
|
742 | } | |
742 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
743 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
743 | return pie; |
|
744 | return pie; | |
744 | } |
|
745 | } | |
745 |
|
746 | |||
746 | QList<LegendMarker*> QPieSeriesPrivate::createLegendMarker(QLegend* legend) |
|
747 | QList<LegendMarker*> QPieSeriesPrivate::createLegendMarker(QLegend* legend) | |
747 | { |
|
748 | { | |
748 | Q_Q(QPieSeries); |
|
749 | Q_Q(QPieSeries); | |
749 | QList<LegendMarker*> markers; |
|
750 | QList<LegendMarker*> markers; | |
750 | foreach(QPieSlice* slice, q->slices()) { |
|
751 | foreach(QPieSlice* slice, q->slices()) { | |
751 | PieLegendMarker* marker = new PieLegendMarker(q,slice,legend); |
|
752 | PieLegendMarker* marker = new PieLegendMarker(q,slice,legend); | |
752 | markers << marker; |
|
753 | markers << marker; | |
753 | } |
|
754 | } | |
754 | return markers; |
|
755 | return markers; | |
755 | } |
|
756 | } | |
756 |
|
757 | |||
|
758 | QAbstractAxis* QPieSeriesPrivate::createAxisX() | |||
|
759 | { | |||
|
760 | return 0; | |||
|
761 | } | |||
|
762 | ||||
|
763 | QAbstractAxis* QPieSeriesPrivate::createAxisY() | |||
|
764 | { | |||
|
765 | return 0; | |||
|
766 | } | |||
|
767 | ||||
757 | #include "moc_qpieseries.cpp" |
|
768 | #include "moc_qpieseries.cpp" | |
758 | #include "moc_qpieseries_p.cpp" |
|
769 | #include "moc_qpieseries_p.cpp" | |
759 |
|
770 | |||
760 | QTCOMMERCIALCHART_END_NAMESPACE |
|
771 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,84 +1,86 | |||||
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 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef QPIESERIES_P_H |
|
30 | #ifndef QPIESERIES_P_H | |
31 | #define QPIESERIES_P_H |
|
31 | #define QPIESERIES_P_H | |
32 |
|
32 | |||
33 | #include "qpieseries.h" |
|
33 | #include "qpieseries.h" | |
34 | #include "qabstractseries_p.h" |
|
34 | #include "qabstractseries_p.h" | |
35 |
|
35 | |||
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
37 | class QLegendPrivate; |
|
37 | class QLegendPrivate; | |
38 |
|
38 | |||
39 | class QPieSeriesPrivate : public QAbstractSeriesPrivate |
|
39 | class QPieSeriesPrivate : public QAbstractSeriesPrivate | |
40 | { |
|
40 | { | |
41 | Q_OBJECT |
|
41 | Q_OBJECT | |
42 |
|
42 | |||
43 | public: |
|
43 | public: | |
44 | QPieSeriesPrivate(QPieSeries *parent); |
|
44 | QPieSeriesPrivate(QPieSeries *parent); | |
45 | ~QPieSeriesPrivate(); |
|
45 | ~QPieSeriesPrivate(); | |
46 |
|
46 | |||
47 | void scaleDomain(Domain& domain); |
|
47 | void scaleDomain(Domain& domain); | |
48 | Chart* createGraphics(ChartPresenter *presenter); |
|
48 | Chart* createGraphics(ChartPresenter *presenter); | |
49 | QList<LegendMarker*> createLegendMarker(QLegend *legend); |
|
49 | QList<LegendMarker*> createLegendMarker(QLegend *legend); | |
|
50 | QAbstractAxis* createAxisX(); | |||
|
51 | QAbstractAxis* createAxisY(); | |||
50 |
|
52 | |||
51 | void updateDerivativeData(); |
|
53 | void updateDerivativeData(); | |
52 |
|
54 | |||
53 | static QPieSeriesPrivate* fromSeries(QPieSeries *series); |
|
55 | static QPieSeriesPrivate* fromSeries(QPieSeries *series); | |
54 |
|
56 | |||
55 | signals: |
|
57 | signals: | |
56 | void calculatedDataChanged(); |
|
58 | void calculatedDataChanged(); | |
57 | void pieSizeChanged(); |
|
59 | void pieSizeChanged(); | |
58 | void pieStartAngleChanged(); |
|
60 | void pieStartAngleChanged(); | |
59 | void pieEndAngleChanged(); |
|
61 | void pieEndAngleChanged(); | |
60 | void horizontalPositionChanged(); |
|
62 | void horizontalPositionChanged(); | |
61 | void verticalPositionChanged(); |
|
63 | void verticalPositionChanged(); | |
62 |
|
64 | |||
63 | public Q_SLOTS: |
|
65 | public Q_SLOTS: | |
64 | void sliceValueChanged(); |
|
66 | void sliceValueChanged(); | |
65 | void sliceClicked(); |
|
67 | void sliceClicked(); | |
66 | void sliceHovered(bool state); |
|
68 | void sliceHovered(bool state); | |
67 |
|
69 | |||
68 | private: |
|
70 | private: | |
69 | QList<QPieSlice*> m_slices; |
|
71 | QList<QPieSlice*> m_slices; | |
70 | qreal m_pieRelativeHorPos; |
|
72 | qreal m_pieRelativeHorPos; | |
71 | qreal m_pieRelativeVerPos; |
|
73 | qreal m_pieRelativeVerPos; | |
72 | qreal m_pieRelativeSize; |
|
74 | qreal m_pieRelativeSize; | |
73 | qreal m_pieStartAngle; |
|
75 | qreal m_pieStartAngle; | |
74 | qreal m_pieEndAngle; |
|
76 | qreal m_pieEndAngle; | |
75 | qreal m_sum; |
|
77 | qreal m_sum; | |
76 |
|
78 | |||
77 | private: |
|
79 | private: | |
78 | friend class QLegendPrivate; |
|
80 | friend class QLegendPrivate; | |
79 | Q_DECLARE_PUBLIC(QPieSeries) |
|
81 | Q_DECLARE_PUBLIC(QPieSeries) | |
80 | }; |
|
82 | }; | |
81 |
|
83 | |||
82 | QTCOMMERCIALCHART_END_NAMESPACE |
|
84 | QTCOMMERCIALCHART_END_NAMESPACE | |
83 |
|
85 | |||
84 | #endif // QPIESERIES_P_H |
|
86 | #endif // QPIESERIES_P_H |
@@ -1,71 +1,71 | |||||
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 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef QABSTRACTSERIES_P_H |
|
30 | #ifndef QABSTRACTSERIES_P_H | |
31 | #define QABSTRACTSERIES_P_H |
|
31 | #define QABSTRACTSERIES_P_H | |
32 |
|
32 | |||
33 | #include "qabstractseries.h" |
|
33 | #include "qabstractseries.h" | |
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
36 |
|
36 | |||
37 | class Domain; |
|
37 | class Domain; | |
38 | class ChartPresenter; |
|
38 | class ChartPresenter; | |
39 | class Chart; |
|
39 | class Chart; | |
40 | class LegendMarker; |
|
40 | class LegendMarker; | |
41 | class QLegend; |
|
41 | class QLegend; | |
42 | class ChartDataSet; |
|
42 | class ChartDataSet; | |
43 | class QAbstractAxis; |
|
43 | class QAbstractAxis; | |
44 |
|
44 | |||
45 | class QAbstractSeriesPrivate : public QObject |
|
45 | class QAbstractSeriesPrivate : public QObject | |
46 | { |
|
46 | { | |
47 | Q_OBJECT |
|
47 | Q_OBJECT | |
48 | public: |
|
48 | public: | |
49 | QAbstractSeriesPrivate(QAbstractSeries *q); |
|
49 | QAbstractSeriesPrivate(QAbstractSeries *q); | |
50 | ~QAbstractSeriesPrivate(); |
|
50 | ~QAbstractSeriesPrivate(); | |
51 |
|
51 | |||
52 | virtual void scaleDomain(Domain& domain) = 0; |
|
52 | virtual void scaleDomain(Domain& domain) = 0; | |
53 | virtual Chart* createGraphics(ChartPresenter* presenter) = 0; |
|
53 | virtual Chart* createGraphics(ChartPresenter* presenter) = 0; | |
54 | virtual QList<LegendMarker*> createLegendMarker(QLegend* legend) = 0; |
|
54 | virtual QList<LegendMarker*> createLegendMarker(QLegend* legend) = 0; | |
55 |
virtual QAbstractAxis* createAxisX() |
|
55 | virtual QAbstractAxis* createAxisX() = 0; | |
56 |
virtual QAbstractAxis* createAxisY() |
|
56 | virtual QAbstractAxis* createAxisY() = 0; | |
57 |
|
57 | |||
58 | protected: |
|
58 | protected: | |
59 | QAbstractSeries *q_ptr; |
|
59 | QAbstractSeries *q_ptr; | |
60 | QChart *m_chart; |
|
60 | QChart *m_chart; | |
61 | ChartDataSet *m_dataset; |
|
61 | ChartDataSet *m_dataset; | |
62 | QString m_name; |
|
62 | QString m_name; | |
63 | bool m_visible; |
|
63 | bool m_visible; | |
64 |
|
64 | |||
65 | friend class QAbstractSeries; |
|
65 | friend class QAbstractSeries; | |
66 | friend class ChartDataSet; |
|
66 | friend class ChartDataSet; | |
67 | }; |
|
67 | }; | |
68 |
|
68 | |||
69 | QTCOMMERCIALCHART_END_NAMESPACE |
|
69 | QTCOMMERCIALCHART_END_NAMESPACE | |
70 |
|
70 | |||
71 | #endif |
|
71 | #endif |
@@ -1,254 +1,268 | |||||
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 "qscatterseries.h" |
|
21 | #include "qscatterseries.h" | |
22 | #include "qscatterseries_p.h" |
|
22 | #include "qscatterseries_p.h" | |
23 | #include "scatterchartitem_p.h" |
|
23 | #include "scatterchartitem_p.h" | |
24 | #include "chartdataset_p.h" |
|
24 | #include "chartdataset_p.h" | |
25 | #include "charttheme_p.h" |
|
25 | #include "charttheme_p.h" | |
26 | #include "chartanimator_p.h" |
|
26 | #include "chartanimator_p.h" | |
|
27 | #include "qvaluesaxis.h" | |||
27 |
|
28 | |||
28 | /*! |
|
29 | /*! | |
29 | \class QScatterSeries |
|
30 | \class QScatterSeries | |
30 | \brief The QScatterSeries class is used for making scatter charts. |
|
31 | \brief The QScatterSeries class is used for making scatter charts. | |
31 |
|
32 | |||
32 | \mainclass |
|
33 | \mainclass | |
33 |
|
34 | |||
34 | The scatter data is displayed as a collection of points on the chart. Each point determines the position on the horizontal axis |
|
35 | The scatter data is displayed as a collection of points on the chart. Each point determines the position on the horizontal axis | |
35 | and the vertical axis. |
|
36 | and the vertical axis. | |
36 |
|
37 | |||
37 | \image examples_scatterchart.png |
|
38 | \image examples_scatterchart.png | |
38 |
|
39 | |||
39 | Creating basic scatter chart is simple: |
|
40 | Creating basic scatter chart is simple: | |
40 | \code |
|
41 | \code | |
41 | QScatterSeries* series = new QScatterSeries(); |
|
42 | QScatterSeries* series = new QScatterSeries(); | |
42 | series->append(0, 6); |
|
43 | series->append(0, 6); | |
43 | series->append(2, 4); |
|
44 | series->append(2, 4); | |
44 | ... |
|
45 | ... | |
45 | chart->addSeries(series); |
|
46 | chart->addSeries(series); | |
46 | \endcode |
|
47 | \endcode | |
47 | */ |
|
48 | */ | |
48 | /*! |
|
49 | /*! | |
49 | \qmlclass ScatterSeries QScatterSeries |
|
50 | \qmlclass ScatterSeries QScatterSeries | |
50 | \inherits XYSeries |
|
51 | \inherits XYSeries | |
51 |
|
52 | |||
52 | The following QML shows how to create a chart with two simple scatter series: |
|
53 | The following QML shows how to create a chart with two simple scatter series: | |
53 | \snippet ../demos/qmlchart/qml/qmlchart/View5.qml 1 |
|
54 | \snippet ../demos/qmlchart/qml/qmlchart/View5.qml 1 | |
54 | \snippet ../demos/qmlchart/qml/qmlchart/View5.qml 2 |
|
55 | \snippet ../demos/qmlchart/qml/qmlchart/View5.qml 2 | |
55 |
|
56 | |||
56 | \beginfloatleft |
|
57 | \beginfloatleft | |
57 | \image demos_qmlchart5.png |
|
58 | \image demos_qmlchart5.png | |
58 | \endfloat |
|
59 | \endfloat | |
59 | \clearfloat |
|
60 | \clearfloat | |
60 | */ |
|
61 | */ | |
61 |
|
62 | |||
62 | /*! |
|
63 | /*! | |
63 | \enum QScatterSeries::MarkerShape |
|
64 | \enum QScatterSeries::MarkerShape | |
64 |
|
65 | |||
65 | This enum describes the shape used when rendering marker items. |
|
66 | This enum describes the shape used when rendering marker items. | |
66 |
|
67 | |||
67 | \value MarkerShapeCircle |
|
68 | \value MarkerShapeCircle | |
68 | \value MarkerShapeRectangle |
|
69 | \value MarkerShapeRectangle | |
69 | */ |
|
70 | */ | |
70 |
|
71 | |||
71 | /*! |
|
72 | /*! | |
72 | \property QScatterSeries::color |
|
73 | \property QScatterSeries::color | |
73 | Fill (brush) color of the series. This is a convenience property for modifying the color of brush. |
|
74 | Fill (brush) color of the series. This is a convenience property for modifying the color of brush. | |
74 | \sa QScatterSeries::brush() |
|
75 | \sa QScatterSeries::brush() | |
75 | */ |
|
76 | */ | |
76 |
|
77 | |||
77 | /*! |
|
78 | /*! | |
78 | \property QScatterSeries::borderColor |
|
79 | \property QScatterSeries::borderColor | |
79 | Line (pen) color of the series. This is a convenience property for modifying the color of pen. |
|
80 | Line (pen) color of the series. This is a convenience property for modifying the color of pen. | |
80 | \sa QScatterSeries::pen() |
|
81 | \sa QScatterSeries::pen() | |
81 | */ |
|
82 | */ | |
82 |
|
83 | |||
83 | /*! |
|
84 | /*! | |
84 | \property QScatterSeries::markerShape |
|
85 | \property QScatterSeries::markerShape | |
85 | Defines the shape of the marker used to draw the points in the series. The default shape is MarkerShapeCircle. |
|
86 | Defines the shape of the marker used to draw the points in the series. The default shape is MarkerShapeCircle. | |
86 | */ |
|
87 | */ | |
87 | /*! |
|
88 | /*! | |
88 | \qmlproperty MarkerShape ScatterSeries::markerShape |
|
89 | \qmlproperty MarkerShape ScatterSeries::markerShape | |
89 | Defines the shape of the marker used to draw the points in the series. One of ScatterSeries |
|
90 | Defines the shape of the marker used to draw the points in the series. One of ScatterSeries | |
90 | ScatterSeries.MarkerShapeCircle or ScatterSeries.MarkerShapeRectangle. |
|
91 | ScatterSeries.MarkerShapeCircle or ScatterSeries.MarkerShapeRectangle. | |
91 | The default shape is ScatterSeries.MarkerShapeCircle. |
|
92 | The default shape is ScatterSeries.MarkerShapeCircle. | |
92 | */ |
|
93 | */ | |
93 |
|
94 | |||
94 | /*! |
|
95 | /*! | |
95 | \property QScatterSeries::markerSize |
|
96 | \property QScatterSeries::markerSize | |
96 | Defines the size of the marker used to draw the points in the series. The default size is 15.0. |
|
97 | Defines the size of the marker used to draw the points in the series. The default size is 15.0. | |
97 | */ |
|
98 | */ | |
98 | /*! |
|
99 | /*! | |
99 | \qmlproperty real ScatterSeries::markerSize |
|
100 | \qmlproperty real ScatterSeries::markerSize | |
100 | Defines the size of the marker used to draw the points in the series. The default size is 15.0. |
|
101 | Defines the size of the marker used to draw the points in the series. The default size is 15.0. | |
101 | */ |
|
102 | */ | |
102 |
|
103 | |||
103 | /*! |
|
104 | /*! | |
104 | \fn void QScatterSeries::colorChanged(QColor color) |
|
105 | \fn void QScatterSeries::colorChanged(QColor color) | |
105 | Signal is emitted when the fill (brush) color has changed to \a color. |
|
106 | Signal is emitted when the fill (brush) color has changed to \a color. | |
106 | */ |
|
107 | */ | |
107 |
|
108 | |||
108 | /*! |
|
109 | /*! | |
109 | \fn void QScatterSeries::borderColorChanged(QColor color) |
|
110 | \fn void QScatterSeries::borderColorChanged(QColor color) | |
110 | Signal is emitted when the line (pen) color has changed to \a color. |
|
111 | Signal is emitted when the line (pen) color has changed to \a color. | |
111 | */ |
|
112 | */ | |
112 | /*! |
|
113 | /*! | |
113 | \qmlsignal ScatterSeries::borderColorChanged(color color) |
|
114 | \qmlsignal ScatterSeries::borderColorChanged(color color) | |
114 | Signal is emitted when the line (pen) color has changed to \a color. |
|
115 | Signal is emitted when the line (pen) color has changed to \a color. | |
115 | */ |
|
116 | */ | |
116 |
|
117 | |||
117 | /*! |
|
118 | /*! | |
118 | \fn QChartSeriesType QScatterSeries::type() const |
|
119 | \fn QChartSeriesType QScatterSeries::type() const | |
119 | Returns QChartSeries::SeriesTypeScatter. |
|
120 | Returns QChartSeries::SeriesTypeScatter. | |
120 | \sa QAbstractSeries, SeriesType |
|
121 | \sa QAbstractSeries, SeriesType | |
121 | */ |
|
122 | */ | |
122 |
|
123 | |||
123 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
124 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
124 |
|
125 | |||
125 | /*! |
|
126 | /*! | |
126 | Constructs a series object which is a child of \a parent. |
|
127 | Constructs a series object which is a child of \a parent. | |
127 | */ |
|
128 | */ | |
128 | QScatterSeries::QScatterSeries(QObject *parent) : QXYSeries(*new QScatterSeriesPrivate(this),parent) |
|
129 | QScatterSeries::QScatterSeries(QObject *parent) : QXYSeries(*new QScatterSeriesPrivate(this),parent) | |
129 | { |
|
130 | { | |
130 | } |
|
131 | } | |
131 |
|
132 | |||
132 | /*! |
|
133 | /*! | |
133 | Destroys the object. Note that adding series to QChart transfers the ownership to the chart. |
|
134 | Destroys the object. Note that adding series to QChart transfers the ownership to the chart. | |
134 | */ |
|
135 | */ | |
135 | QScatterSeries::~QScatterSeries() |
|
136 | QScatterSeries::~QScatterSeries() | |
136 | { |
|
137 | { | |
137 | Q_D(QScatterSeries); |
|
138 | Q_D(QScatterSeries); | |
138 | if(d->m_dataset) { |
|
139 | if(d->m_dataset) { | |
139 | d->m_dataset->removeSeries(this); |
|
140 | d->m_dataset->removeSeries(this); | |
140 | } |
|
141 | } | |
141 | } |
|
142 | } | |
142 |
|
143 | |||
143 | QAbstractSeries::SeriesType QScatterSeries::type() const |
|
144 | QAbstractSeries::SeriesType QScatterSeries::type() const | |
144 | { |
|
145 | { | |
145 | return QAbstractSeries::SeriesTypeScatter; |
|
146 | return QAbstractSeries::SeriesTypeScatter; | |
146 | } |
|
147 | } | |
147 |
|
148 | |||
148 | void QScatterSeries::setPen(const QPen &pen) |
|
149 | void QScatterSeries::setPen(const QPen &pen) | |
149 | { |
|
150 | { | |
150 | Q_D(QXYSeries); |
|
151 | Q_D(QXYSeries); | |
151 | if (d->m_pen != pen) { |
|
152 | if (d->m_pen != pen) { | |
152 | bool emitColorChanged = d->m_pen.color() != pen.color(); |
|
153 | bool emitColorChanged = d->m_pen.color() != pen.color(); | |
153 | d->m_pen = pen; |
|
154 | d->m_pen = pen; | |
154 | emit d->updated(); |
|
155 | emit d->updated(); | |
155 | if (emitColorChanged) |
|
156 | if (emitColorChanged) | |
156 | emit borderColorChanged(pen.color()); |
|
157 | emit borderColorChanged(pen.color()); | |
157 | } |
|
158 | } | |
158 | } |
|
159 | } | |
159 |
|
160 | |||
160 | void QScatterSeries::setBrush(const QBrush &brush) |
|
161 | void QScatterSeries::setBrush(const QBrush &brush) | |
161 | { |
|
162 | { | |
162 | Q_D(QScatterSeries); |
|
163 | Q_D(QScatterSeries); | |
163 | if (d->m_brush != brush) { |
|
164 | if (d->m_brush != brush) { | |
164 | bool emitColorChanged = d->m_brush.color() != brush.color(); |
|
165 | bool emitColorChanged = d->m_brush.color() != brush.color(); | |
165 | d->m_brush = brush; |
|
166 | d->m_brush = brush; | |
166 | emit d->updated(); |
|
167 | emit d->updated(); | |
167 | if (emitColorChanged) |
|
168 | if (emitColorChanged) | |
168 | emit colorChanged(brush.color()); |
|
169 | emit colorChanged(brush.color()); | |
169 | } |
|
170 | } | |
170 | } |
|
171 | } | |
171 |
|
172 | |||
172 | void QScatterSeries::setColor(const QColor &color) |
|
173 | void QScatterSeries::setColor(const QColor &color) | |
173 | { |
|
174 | { | |
174 | QBrush b = brush(); |
|
175 | QBrush b = brush(); | |
175 | if (b.color() != color) { |
|
176 | if (b.color() != color) { | |
176 | b.setColor(color); |
|
177 | b.setColor(color); | |
177 | setBrush(b); |
|
178 | setBrush(b); | |
178 | } |
|
179 | } | |
179 | } |
|
180 | } | |
180 |
|
181 | |||
181 | QColor QScatterSeries::color() const |
|
182 | QColor QScatterSeries::color() const | |
182 | { |
|
183 | { | |
183 | return brush().color(); |
|
184 | return brush().color(); | |
184 | } |
|
185 | } | |
185 |
|
186 | |||
186 | void QScatterSeries::setBorderColor(const QColor &color) |
|
187 | void QScatterSeries::setBorderColor(const QColor &color) | |
187 | { |
|
188 | { | |
188 | QPen p = pen(); |
|
189 | QPen p = pen(); | |
189 | if (p.color() != color) { |
|
190 | if (p.color() != color) { | |
190 | p.setColor(color); |
|
191 | p.setColor(color); | |
191 | setPen(p); |
|
192 | setPen(p); | |
192 | } |
|
193 | } | |
193 | } |
|
194 | } | |
194 |
|
195 | |||
195 | QColor QScatterSeries::borderColor() const |
|
196 | QColor QScatterSeries::borderColor() const | |
196 | { |
|
197 | { | |
197 | return pen().color(); |
|
198 | return pen().color(); | |
198 | } |
|
199 | } | |
199 |
|
200 | |||
200 | QScatterSeries::MarkerShape QScatterSeries::markerShape() const |
|
201 | QScatterSeries::MarkerShape QScatterSeries::markerShape() const | |
201 | { |
|
202 | { | |
202 | Q_D(const QScatterSeries); |
|
203 | Q_D(const QScatterSeries); | |
203 | return d->m_shape; |
|
204 | return d->m_shape; | |
204 | } |
|
205 | } | |
205 |
|
206 | |||
206 | void QScatterSeries::setMarkerShape(MarkerShape shape) |
|
207 | void QScatterSeries::setMarkerShape(MarkerShape shape) | |
207 | { |
|
208 | { | |
208 | Q_D(QScatterSeries); |
|
209 | Q_D(QScatterSeries); | |
209 | if (d->m_shape != shape) { |
|
210 | if (d->m_shape != shape) { | |
210 | d->m_shape = shape; |
|
211 | d->m_shape = shape; | |
211 | emit d->updated(); |
|
212 | emit d->updated(); | |
212 | } |
|
213 | } | |
213 | } |
|
214 | } | |
214 |
|
215 | |||
215 | qreal QScatterSeries::markerSize() const |
|
216 | qreal QScatterSeries::markerSize() const | |
216 | { |
|
217 | { | |
217 | Q_D(const QScatterSeries); |
|
218 | Q_D(const QScatterSeries); | |
218 | return d->m_size; |
|
219 | return d->m_size; | |
219 | } |
|
220 | } | |
220 |
|
221 | |||
221 | void QScatterSeries::setMarkerSize(qreal size) |
|
222 | void QScatterSeries::setMarkerSize(qreal size) | |
222 | { |
|
223 | { | |
223 | Q_D(QScatterSeries); |
|
224 | Q_D(QScatterSeries); | |
224 |
|
225 | |||
225 | if (!qFuzzyIsNull(d->m_size - size)) { |
|
226 | if (!qFuzzyIsNull(d->m_size - size)) { | |
226 | d->m_size = size; |
|
227 | d->m_size = size; | |
227 | emit d->updated(); |
|
228 | emit d->updated(); | |
228 | } |
|
229 | } | |
229 | } |
|
230 | } | |
230 |
|
231 | |||
231 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
232 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
232 |
|
233 | |||
233 | QScatterSeriesPrivate::QScatterSeriesPrivate(QScatterSeries* q) : |
|
234 | QScatterSeriesPrivate::QScatterSeriesPrivate(QScatterSeries* q) : | |
234 | QXYSeriesPrivate(q), |
|
235 | QXYSeriesPrivate(q), | |
235 | m_shape(QScatterSeries::MarkerShapeCircle), |
|
236 | m_shape(QScatterSeries::MarkerShapeCircle), | |
236 | m_size(15.0) |
|
237 | m_size(15.0) | |
237 | { |
|
238 | { | |
238 | } |
|
239 | } | |
239 |
|
240 | |||
240 | Chart* QScatterSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
241 | Chart* QScatterSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
241 | { |
|
242 | { | |
242 | Q_Q(QScatterSeries); |
|
243 | Q_Q(QScatterSeries); | |
243 | ScatterChartItem *scatter = new ScatterChartItem(q,presenter); |
|
244 | ScatterChartItem *scatter = new ScatterChartItem(q,presenter); | |
244 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
245 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
245 | scatter->setAnimator(presenter->animator()); |
|
246 | scatter->setAnimator(presenter->animator()); | |
246 | scatter->setAnimation(new XYAnimation(scatter)); |
|
247 | scatter->setAnimation(new XYAnimation(scatter)); | |
247 | } |
|
248 | } | |
248 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
249 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
249 | return scatter; |
|
250 | return scatter; | |
250 | } |
|
251 | } | |
251 |
|
252 | |||
|
253 | QAbstractAxis* QScatterSeriesPrivate::createAxisX() | |||
|
254 | { | |||
|
255 | // TODO: parent? | |||
|
256 | return new QValuesAxis(this); | |||
|
257 | } | |||
|
258 | ||||
|
259 | QAbstractAxis* QScatterSeriesPrivate::createAxisY() | |||
|
260 | { | |||
|
261 | // TODO: parent? | |||
|
262 | return new QValuesAxis(this); | |||
|
263 | } | |||
|
264 | ||||
|
265 | ||||
252 | #include "moc_qscatterseries.cpp" |
|
266 | #include "moc_qscatterseries.cpp" | |
253 |
|
267 | |||
254 | QTCOMMERCIALCHART_END_NAMESPACE |
|
268 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,51 +1,53 | |||||
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 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef QSCATTERSERIES_P_H |
|
30 | #ifndef QSCATTERSERIES_P_H | |
31 | #define QSCATTERSERIES_P_H |
|
31 | #define QSCATTERSERIES_P_H | |
32 |
|
32 | |||
33 | #include "qxyseries_p.h" |
|
33 | #include "qxyseries_p.h" | |
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
36 |
|
36 | |||
37 | class QScatterSeriesPrivate: public QXYSeriesPrivate |
|
37 | class QScatterSeriesPrivate: public QXYSeriesPrivate | |
38 | { |
|
38 | { | |
39 | public: |
|
39 | public: | |
40 | QScatterSeriesPrivate(QScatterSeries* q); |
|
40 | QScatterSeriesPrivate(QScatterSeries* q); | |
41 | Chart* createGraphics(ChartPresenter* presenter); |
|
41 | Chart* createGraphics(ChartPresenter* presenter); | |
|
42 | QAbstractAxis* createAxisX(); | |||
|
43 | QAbstractAxis* createAxisY(); | |||
42 |
|
44 | |||
43 | private: |
|
45 | private: | |
44 | QScatterSeries::MarkerShape m_shape; |
|
46 | QScatterSeries::MarkerShape m_shape; | |
45 | qreal m_size; |
|
47 | qreal m_size; | |
46 | Q_DECLARE_PUBLIC(QScatterSeries) |
|
48 | Q_DECLARE_PUBLIC(QScatterSeries) | |
47 | }; |
|
49 | }; | |
48 |
|
50 | |||
49 | QTCOMMERCIALCHART_END_NAMESPACE |
|
51 | QTCOMMERCIALCHART_END_NAMESPACE | |
50 |
|
52 | |||
51 | #endif |
|
53 | #endif |
General Comments 0
You need to be logged in to leave comments.
Login now