##// END OF EJS Templates
Return empty brush/pen/font via API rather than the weird default one...
Miikka Heikkinen -
r2519:9ea7d7fe3500
parent child
Show More
@@ -1,453 +1,459
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 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 "abstractdomain_p.h"
25 #include "abstractdomain_p.h"
26 #include "chartdataset_p.h"
26 #include "chartdataset_p.h"
27 #include "charttheme_p.h"
27 #include "charttheme_p.h"
28 #include "qvalueaxis.h"
28 #include "qvalueaxis.h"
29 #include "qarealegendmarker.h"
29 #include "qarealegendmarker.h"
30 #include "qchart_p.h"
30 #include "qchart_p.h"
31
31
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33
33
34 /*!
34 /*!
35 \class QAreaSeries
35 \class QAreaSeries
36 \brief The QAreaSeries class is used for making area charts.
36 \brief The QAreaSeries class is used for making area charts.
37
37
38 \mainclass
38 \mainclass
39
39
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 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
41 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,
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 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.
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 In that case QAreaSeries should be initiated with two QLineSeries instances. Please note terms "upper" and "lower" boundary can be misleading in cases
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 where "lower" boundary had bigger values than the "upper" one, however the main point that area between these two boundary lines will be filled.
45
45
46 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.
47 \image examples_areachart.png
47 \image examples_areachart.png
48 */
48 */
49 /*!
49 /*!
50 \qmlclass AreaSeries QAreaSeries
50 \qmlclass AreaSeries QAreaSeries
51
51
52 The following QML shows how to create a simple area chart:
52 The following QML shows how to create a simple area chart:
53 \snippet ../demos/qmlchart/qml/qmlchart/View4.qml 1
53 \snippet ../demos/qmlchart/qml/qmlchart/View4.qml 1
54 \beginfloatleft
54 \beginfloatleft
55 \image demos_qmlchart4.png
55 \image demos_qmlchart4.png
56 \endfloat
56 \endfloat
57 \clearfloat
57 \clearfloat
58 */
58 */
59
59
60 /*!
60 /*!
61 \property QAreaSeries::upperSeries
61 \property QAreaSeries::upperSeries
62 \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.
63 */
63 */
64 /*!
64 /*!
65 \qmlproperty LineSeries AreaSeries::upperSeries
65 \qmlproperty LineSeries AreaSeries::upperSeries
66 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.
67 */
67 */
68
68
69 /*!
69 /*!
70 \property QAreaSeries::lowerSeries
70 \property QAreaSeries::lowerSeries
71 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
72 QAreaSeries was constructed without a\ lowerSeries this is null.
72 QAreaSeries was constructed without a\ lowerSeries this is null.
73 */
73 */
74 /*!
74 /*!
75 \qmlproperty LineSeries AreaSeries::lowerSeries
75 \qmlproperty LineSeries AreaSeries::lowerSeries
76 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
77 AreaSeries was constructed without a\ lowerSeries this is null.
77 AreaSeries was constructed without a\ lowerSeries this is null.
78 */
78 */
79
79
80 /*!
80 /*!
81 \property QAreaSeries::color
81 \property QAreaSeries::color
82 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.
83 \sa QAreaSeries::brush()
83 \sa QAreaSeries::brush()
84 */
84 */
85 /*!
85 /*!
86 \qmlproperty color AreaSeries::color
86 \qmlproperty color AreaSeries::color
87 Fill (brush) color of the series.
87 Fill (brush) color of the series.
88 */
88 */
89
89
90 /*!
90 /*!
91 \property QAreaSeries::borderColor
91 \property QAreaSeries::borderColor
92 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.
93 \sa QAreaSeries::pen()
93 \sa QAreaSeries::pen()
94 */
94 */
95 /*!
95 /*!
96 \qmlproperty color AreaSeries::borderColor
96 \qmlproperty color AreaSeries::borderColor
97 Line (pen) color of the series.
97 Line (pen) color of the series.
98 */
98 */
99
99
100 /*!
100 /*!
101 \qmlproperty real AreaSeries::borderWidth
101 \qmlproperty real AreaSeries::borderWidth
102 The width of the border line. By default the width is 2.0.
102 The width of the border line. By default the width is 2.0.
103 */
103 */
104
104
105 /*!
105 /*!
106 \fn QPen QAreaSeries::pen() const
106 \fn QPen QAreaSeries::pen() const
107 \brief Returns the pen used to draw line for this series.
107 \brief Returns the pen used to draw line for this series.
108 \sa setPen()
108 \sa setPen()
109 */
109 */
110
110
111 /*!
111 /*!
112 \fn QPen QAreaSeries::brush() const
112 \fn QPen QAreaSeries::brush() const
113 \brief Returns the brush used to draw line for this series.
113 \brief Returns the brush used to draw line for this series.
114 \sa setBrush()
114 \sa setBrush()
115 */
115 */
116
116
117 /*!
117 /*!
118 \fn void QAreaSeries::colorChanged(QColor color)
118 \fn void QAreaSeries::colorChanged(QColor color)
119 \brief Signal is emitted when the fill (brush) color has changed to \a color.
119 \brief Signal is emitted when the fill (brush) color has changed to \a color.
120 */
120 */
121 /*!
121 /*!
122 \qmlsignal AreaSeries::onColorChanged(color color)
122 \qmlsignal AreaSeries::onColorChanged(color color)
123 Signal is emitted when the fill (brush) color has changed to \a color.
123 Signal is emitted when the fill (brush) color has changed to \a color.
124 */
124 */
125
125
126 /*!
126 /*!
127 \fn void QAreaSeries::borderColorChanged(QColor color)
127 \fn void QAreaSeries::borderColorChanged(QColor color)
128 \brief Signal is emitted when the line (pen) color has changed to \a color.
128 \brief Signal is emitted when the line (pen) color has changed to \a color.
129 */
129 */
130 /*!
130 /*!
131 \qmlsignal AreaSeries::onBorderColorChanged(color color)
131 \qmlsignal AreaSeries::onBorderColorChanged(color color)
132 Signal is emitted when the line (pen) color has changed to \a color.
132 Signal is emitted when the line (pen) color has changed to \a color.
133 */
133 */
134
134
135 /*!
135 /*!
136 \fn void QAreaSeries::clicked(const QPointF& point)
136 \fn void QAreaSeries::clicked(const QPointF& point)
137 \brief Signal is emitted when user clicks the \a point on area chart.
137 \brief Signal is emitted when user clicks the \a point on area chart.
138 */
138 */
139 /*!
139 /*!
140 \qmlsignal AreaSeries::onClicked(QPointF point)
140 \qmlsignal AreaSeries::onClicked(QPointF point)
141 Signal is emitted when user clicks the \a point on area chart.
141 Signal is emitted when user clicks the \a point on area chart.
142 */
142 */
143
143
144 /*!
144 /*!
145 \fn void QAreaSeries::hovered(const QPointF &point, bool state)
145 \fn void QAreaSeries::hovered(const QPointF &point, bool state)
146 This signal is emitted when user has hovered over or away from the series. \a point shows the origin (coordinate)
146 This signal is emitted when user has hovered over or away from the series. \a point shows the origin (coordinate)
147 of the hover event. \a state is true when user has hovered over the series and false when hover has moved away from
147 of the hover event. \a state is true when user has hovered over the series and false when hover has moved away from
148 the series.
148 the series.
149 */
149 */
150 /*!
150 /*!
151 \qmlsignal AreaSeries::onHovered(point point, bool state)
151 \qmlsignal AreaSeries::onHovered(point point, bool state)
152 This signal is emitted when user has hovered over or away from the series. \a point shows the origin (coordinate)
152 This signal is emitted when user has hovered over or away from the series. \a point shows the origin (coordinate)
153 of the hover event. \a state is true when user has hovered over the series and false when hover has moved away from
153 of the hover event. \a state is true when user has hovered over the series and false when hover has moved away from
154 the series.
154 the series.
155 */
155 */
156
156
157 /*!
157 /*!
158 \fn void QAreaSeries::selected()
158 \fn void QAreaSeries::selected()
159 The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be
159 The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be
160 implemented by the user of QAreaSeries API.
160 implemented by the user of QAreaSeries API.
161 */
161 */
162 /*!
162 /*!
163 \qmlsignal AreaSeries::onSelected()
163 \qmlsignal AreaSeries::onSelected()
164 The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be
164 The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be
165 implemented by the user of AreaSeries API.
165 implemented by the user of AreaSeries API.
166 */
166 */
167
167
168 /*!
168 /*!
169 \fn void QAreaSeriesPrivate::updated()
169 \fn void QAreaSeriesPrivate::updated()
170 \brief \internal
170 \brief \internal
171 */
171 */
172
172
173 /*!
173 /*!
174 Constructs area series object which is a child of \a upperSeries. Area will be spanned between \a
174 Constructs area series object which is a child of \a upperSeries. Area will be spanned between \a
175 upperSeries line and \a lowerSeries line. If no \a lowerSeries is passed to constructor, area is specified by axis x (y=0) instead.
175 upperSeries line and \a lowerSeries line. If no \a lowerSeries is passed to constructor, area is specified by axis x (y=0) instead.
176 When series object is added to QChartView or QChart instance ownerships is transferred.
176 When series object is added to QChartView or QChart instance ownerships is transferred.
177 */
177 */
178 QAreaSeries::QAreaSeries(QLineSeries *upperSeries, QLineSeries *lowerSeries)
178 QAreaSeries::QAreaSeries(QLineSeries *upperSeries, QLineSeries *lowerSeries)
179 : QAbstractSeries(*new QAreaSeriesPrivate(upperSeries, lowerSeries, this), upperSeries)
179 : QAbstractSeries(*new QAreaSeriesPrivate(upperSeries, lowerSeries, this), upperSeries)
180 {
180 {
181 }
181 }
182
182
183 /*!
183 /*!
184 Constructs area series object without upper or lower series with \a parent object.
184 Constructs area series object without upper or lower series with \a parent object.
185 */
185 */
186 QAreaSeries::QAreaSeries(QObject *parent)
186 QAreaSeries::QAreaSeries(QObject *parent)
187 : QAbstractSeries(*new QAreaSeriesPrivate(0, 0, this), parent)
187 : QAbstractSeries(*new QAreaSeriesPrivate(0, 0, this), parent)
188 {
188 {
189 }
189 }
190
190
191 /*!
191 /*!
192 Destroys the object.
192 Destroys the object.
193 */
193 */
194 QAreaSeries::~QAreaSeries()
194 QAreaSeries::~QAreaSeries()
195 {
195 {
196 Q_D(QAreaSeries);
196 Q_D(QAreaSeries);
197 if (d->m_chart)
197 if (d->m_chart)
198 d->m_chart->removeSeries(this);
198 d->m_chart->removeSeries(this);
199 }
199 }
200
200
201 /*!
201 /*!
202 Returns QChartSeries::SeriesTypeArea.
202 Returns QChartSeries::SeriesTypeArea.
203 */
203 */
204 QAbstractSeries::SeriesType QAreaSeries::type() const
204 QAbstractSeries::SeriesType QAreaSeries::type() const
205 {
205 {
206 return QAbstractSeries::SeriesTypeArea;
206 return QAbstractSeries::SeriesTypeArea;
207 }
207 }
208
208
209 /*!
209 /*!
210 Sets the \a series that is to be used as the area chart upper series.
210 Sets the \a series that is to be used as the area chart upper series.
211 */
211 */
212 void QAreaSeries::setUpperSeries(QLineSeries *series)
212 void QAreaSeries::setUpperSeries(QLineSeries *series)
213 {
213 {
214 Q_D(QAreaSeries);
214 Q_D(QAreaSeries);
215 if (d->m_upperSeries != series)
215 if (d->m_upperSeries != series)
216 d->m_upperSeries = series;
216 d->m_upperSeries = series;
217 }
217 }
218
218
219 QLineSeries *QAreaSeries::upperSeries() const
219 QLineSeries *QAreaSeries::upperSeries() const
220 {
220 {
221 Q_D(const QAreaSeries);
221 Q_D(const QAreaSeries);
222 return d->m_upperSeries;
222 return d->m_upperSeries;
223 }
223 }
224
224
225 /*!
225 /*!
226 Sets the \a series that is to be used as the area chart lower series.
226 Sets the \a series that is to be used as the area chart lower series.
227 */
227 */
228 void QAreaSeries::setLowerSeries(QLineSeries *series)
228 void QAreaSeries::setLowerSeries(QLineSeries *series)
229 {
229 {
230 Q_D(QAreaSeries);
230 Q_D(QAreaSeries);
231 d->m_lowerSeries = series;
231 d->m_lowerSeries = series;
232 }
232 }
233
233
234 QLineSeries *QAreaSeries::lowerSeries() const
234 QLineSeries *QAreaSeries::lowerSeries() const
235 {
235 {
236 Q_D(const QAreaSeries);
236 Q_D(const QAreaSeries);
237 return d->m_lowerSeries;
237 return d->m_lowerSeries;
238 }
238 }
239
239
240 /*!
240 /*!
241 Sets \a pen used for drawing area outline.
241 Sets \a pen used for drawing area outline.
242 */
242 */
243 void QAreaSeries::setPen(const QPen &pen)
243 void QAreaSeries::setPen(const QPen &pen)
244 {
244 {
245 Q_D(QAreaSeries);
245 Q_D(QAreaSeries);
246 if (d->m_pen != pen) {
246 if (d->m_pen != pen) {
247 d->m_pen = pen;
247 d->m_pen = pen;
248 emit d->updated();
248 emit d->updated();
249 }
249 }
250 }
250 }
251
251
252 QPen QAreaSeries::pen() const
252 QPen QAreaSeries::pen() const
253 {
253 {
254 Q_D(const QAreaSeries);
254 Q_D(const QAreaSeries);
255 return d->m_pen;
255 if (d->m_pen == QChartPrivate::defaultPen())
256 return QPen();
257 else
258 return d->m_pen;
256 }
259 }
257
260
258 /*!
261 /*!
259 Sets \a brush used for filling the area.
262 Sets \a brush used for filling the area.
260 */
263 */
261 void QAreaSeries::setBrush(const QBrush &brush)
264 void QAreaSeries::setBrush(const QBrush &brush)
262 {
265 {
263 Q_D(QAreaSeries);
266 Q_D(QAreaSeries);
264 if (d->m_brush != brush) {
267 if (d->m_brush != brush) {
265 bool emitColorChanged = brush.color() != d->m_brush.color();
268 bool emitColorChanged = brush.color() != d->m_brush.color();
266 d->m_brush = brush;
269 d->m_brush = brush;
267 emit d->updated();
270 emit d->updated();
268 if (emitColorChanged)
271 if (emitColorChanged)
269 emit colorChanged(brush.color());
272 emit colorChanged(brush.color());
270 }
273 }
271 }
274 }
272
275
273 QBrush QAreaSeries::brush() const
276 QBrush QAreaSeries::brush() const
274 {
277 {
275 Q_D(const QAreaSeries);
278 Q_D(const QAreaSeries);
276 return d->m_brush;
279 if (d->m_brush == QChartPrivate::defaultBrush())
280 return QBrush();
281 else
282 return d->m_brush;
277 }
283 }
278
284
279 void QAreaSeries::setColor(const QColor &color)
285 void QAreaSeries::setColor(const QColor &color)
280 {
286 {
281 QBrush b = brush();
287 QBrush b = brush();
282 if (b == QBrush())
288 if (b == QBrush())
283 b.setStyle(Qt::SolidPattern);
289 b.setStyle(Qt::SolidPattern);
284 b.setColor(color);
290 b.setColor(color);
285 setBrush(b);
291 setBrush(b);
286 }
292 }
287
293
288 QColor QAreaSeries::color() const
294 QColor QAreaSeries::color() const
289 {
295 {
290 return brush().color();
296 return brush().color();
291 }
297 }
292
298
293 void QAreaSeries::setBorderColor(const QColor &color)
299 void QAreaSeries::setBorderColor(const QColor &color)
294 {
300 {
295 QPen p = pen();
301 QPen p = pen();
296 if (p.color() != color) {
302 if (p.color() != color) {
297 p.setColor(color);
303 p.setColor(color);
298 setPen(p);
304 setPen(p);
299 emit borderColorChanged(color);
305 emit borderColorChanged(color);
300 }
306 }
301 }
307 }
302
308
303 QColor QAreaSeries::borderColor() const
309 QColor QAreaSeries::borderColor() const
304 {
310 {
305 return pen().color();
311 return pen().color();
306 }
312 }
307
313
308 /*!
314 /*!
309 Sets if data points are \a visible and should be drawn on line.
315 Sets if data points are \a visible and should be drawn on line.
310 */
316 */
311 void QAreaSeries::setPointsVisible(bool visible)
317 void QAreaSeries::setPointsVisible(bool visible)
312 {
318 {
313 Q_D(QAreaSeries);
319 Q_D(QAreaSeries);
314 if (d->m_pointsVisible != visible) {
320 if (d->m_pointsVisible != visible) {
315 d->m_pointsVisible = visible;
321 d->m_pointsVisible = visible;
316 emit d->updated();
322 emit d->updated();
317 }
323 }
318 }
324 }
319
325
320 /*!
326 /*!
321 Returns if the points are drawn for this series.
327 Returns if the points are drawn for this series.
322 \sa setPointsVisible()
328 \sa setPointsVisible()
323 */
329 */
324 bool QAreaSeries::pointsVisible() const
330 bool QAreaSeries::pointsVisible() const
325 {
331 {
326 Q_D(const QAreaSeries);
332 Q_D(const QAreaSeries);
327 return d->m_pointsVisible;
333 return d->m_pointsVisible;
328 }
334 }
329
335
330 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
336 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
331
337
332 QAreaSeriesPrivate::QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries, QAreaSeries *q)
338 QAreaSeriesPrivate::QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries, QAreaSeries *q)
333 : QAbstractSeriesPrivate(q),
339 : QAbstractSeriesPrivate(q),
334 m_brush(QChartPrivate::defaultBrush()),
340 m_brush(QChartPrivate::defaultBrush()),
335 m_pen(QChartPrivate::defaultPen()),
341 m_pen(QChartPrivate::defaultPen()),
336 m_upperSeries(upperSeries),
342 m_upperSeries(upperSeries),
337 m_lowerSeries(lowerSeries),
343 m_lowerSeries(lowerSeries),
338 m_pointsVisible(false)
344 m_pointsVisible(false)
339 {
345 {
340 }
346 }
341
347
342 void QAreaSeriesPrivate::initializeDomain()
348 void QAreaSeriesPrivate::initializeDomain()
343 {
349 {
344 Q_Q(QAreaSeries);
350 Q_Q(QAreaSeries);
345
351
346 qreal minX(domain()->minX());
352 qreal minX(domain()->minX());
347 qreal minY(domain()->minY());
353 qreal minY(domain()->minY());
348 qreal maxX(domain()->maxX());
354 qreal maxX(domain()->maxX());
349 qreal maxY(domain()->maxY());
355 qreal maxY(domain()->maxY());
350
356
351 QLineSeries *upperSeries = q->upperSeries();
357 QLineSeries *upperSeries = q->upperSeries();
352 QLineSeries *lowerSeries = q->lowerSeries();
358 QLineSeries *lowerSeries = q->lowerSeries();
353
359
354 const QList<QPointF>& points = upperSeries->points();
360 const QList<QPointF>& points = upperSeries->points();
355
361
356 for (int i = 0; i < points.count(); i++) {
362 for (int i = 0; i < points.count(); i++) {
357 qreal x = points[i].x();
363 qreal x = points[i].x();
358 qreal y = points[i].y();
364 qreal y = points[i].y();
359 minX = qMin(minX, x);
365 minX = qMin(minX, x);
360 minY = qMin(minY, y);
366 minY = qMin(minY, y);
361 maxX = qMax(maxX, x);
367 maxX = qMax(maxX, x);
362 maxY = qMax(maxY, y);
368 maxY = qMax(maxY, y);
363 }
369 }
364 if (lowerSeries) {
370 if (lowerSeries) {
365
371
366 const QList<QPointF>& points = lowerSeries->points();
372 const QList<QPointF>& points = lowerSeries->points();
367
373
368 for (int i = 0; i < points.count(); i++) {
374 for (int i = 0; i < points.count(); i++) {
369 qreal x = points[i].x();
375 qreal x = points[i].x();
370 qreal y = points[i].y();
376 qreal y = points[i].y();
371 minX = qMin(minX, x);
377 minX = qMin(minX, x);
372 minY = qMin(minY, y);
378 minY = qMin(minY, y);
373 maxX = qMax(maxX, x);
379 maxX = qMax(maxX, x);
374 maxY = qMax(maxY, y);
380 maxY = qMax(maxY, y);
375 }
381 }
376 }
382 }
377
383
378 domain()->setRange(minX, maxX, minY, maxY);
384 domain()->setRange(minX, maxX, minY, maxY);
379 }
385 }
380
386
381 void QAreaSeriesPrivate::initializeGraphics(QGraphicsItem* parent)
387 void QAreaSeriesPrivate::initializeGraphics(QGraphicsItem* parent)
382 {
388 {
383 Q_Q(QAreaSeries);
389 Q_Q(QAreaSeries);
384 AreaChartItem *area = new AreaChartItem(q,parent);
390 AreaChartItem *area = new AreaChartItem(q,parent);
385 m_item.reset(area);
391 m_item.reset(area);
386 QAbstractSeriesPrivate::initializeGraphics(parent);
392 QAbstractSeriesPrivate::initializeGraphics(parent);
387 }
393 }
388 void QAreaSeriesPrivate::initializeAnimations(QChart::AnimationOptions options)
394 void QAreaSeriesPrivate::initializeAnimations(QChart::AnimationOptions options)
389 {
395 {
390 Q_Q(QAreaSeries);
396 Q_Q(QAreaSeries);
391 AreaChartItem *area = static_cast<AreaChartItem *>(m_item.data());
397 AreaChartItem *area = static_cast<AreaChartItem *>(m_item.data());
392 if (options.testFlag(QChart::SeriesAnimations)) {
398 if (options.testFlag(QChart::SeriesAnimations)) {
393 area->upperLineItem()->setAnimation(new XYAnimation(area->upperLineItem()));
399 area->upperLineItem()->setAnimation(new XYAnimation(area->upperLineItem()));
394 if (q->lowerSeries())
400 if (q->lowerSeries())
395 area->lowerLineItem()->setAnimation(new XYAnimation(area->lowerLineItem()));
401 area->lowerLineItem()->setAnimation(new XYAnimation(area->lowerLineItem()));
396 }else{
402 }else{
397 area->upperLineItem()->setAnimation(0);
403 area->upperLineItem()->setAnimation(0);
398 if (q->lowerSeries())
404 if (q->lowerSeries())
399 area->lowerLineItem()->setAnimation(0);
405 area->lowerLineItem()->setAnimation(0);
400 }
406 }
401 QAbstractSeriesPrivate::initializeAnimations(options);
407 QAbstractSeriesPrivate::initializeAnimations(options);
402 }
408 }
403
409
404 QList<QLegendMarker*> QAreaSeriesPrivate::createLegendMarkers(QLegend* legend)
410 QList<QLegendMarker*> QAreaSeriesPrivate::createLegendMarkers(QLegend* legend)
405 {
411 {
406 Q_Q(QAreaSeries);
412 Q_Q(QAreaSeries);
407 QList<QLegendMarker*> list;
413 QList<QLegendMarker*> list;
408 return list << new QAreaLegendMarker(q,legend);
414 return list << new QAreaLegendMarker(q,legend);
409 }
415 }
410
416
411
417
412 void QAreaSeriesPrivate::initializeAxes()
418 void QAreaSeriesPrivate::initializeAxes()
413 {
419 {
414
420
415 }
421 }
416
422
417 QAbstractAxis::AxisType QAreaSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
423 QAbstractAxis::AxisType QAreaSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
418 {
424 {
419 Q_UNUSED(orientation);
425 Q_UNUSED(orientation);
420 return QAbstractAxis::AxisTypeValue;
426 return QAbstractAxis::AxisTypeValue;
421 }
427 }
422
428
423 QAbstractAxis* QAreaSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const
429 QAbstractAxis* QAreaSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const
424 {
430 {
425 Q_UNUSED(orientation);
431 Q_UNUSED(orientation);
426 return 0;
432 return 0;
427 }
433 }
428
434
429 void QAreaSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced)
435 void QAreaSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced)
430 {
436 {
431 Q_Q(QAreaSeries);
437 Q_Q(QAreaSeries);
432
438
433 const QList<QGradient> gradients = theme->seriesGradients();
439 const QList<QGradient> gradients = theme->seriesGradients();
434 const QList<QColor> colors = theme->seriesColors();
440 const QList<QColor> colors = theme->seriesColors();
435
441
436 if (forced || QChartPrivate::defaultPen() == m_pen) {
442 if (forced || QChartPrivate::defaultPen() == m_pen) {
437 QPen pen;
443 QPen pen;
438 pen.setColor(ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.0));
444 pen.setColor(ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.0));
439 pen.setWidthF(2);
445 pen.setWidthF(2);
440 q->setPen(pen);
446 q->setPen(pen);
441 }
447 }
442
448
443 if (forced || QChartPrivate::defaultBrush() == m_brush) {
449 if (forced || QChartPrivate::defaultBrush() == m_brush) {
444 QBrush brush(colors.at(index % colors.size()));
450 QBrush brush(colors.at(index % colors.size()));
445 q->setBrush(brush);
451 q->setBrush(brush);
446 }
452 }
447 }
453 }
448
454
449
455
450 #include "moc_qareaseries.cpp"
456 #include "moc_qareaseries.cpp"
451 #include "moc_qareaseries_p.cpp"
457 #include "moc_qareaseries_p.cpp"
452
458
453 QTCOMMERCIALCHART_END_NAMESPACE
459 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,990 +1,1020
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qabstractaxis.h"
21 #include "qabstractaxis.h"
22 #include "qabstractaxis_p.h"
22 #include "qabstractaxis_p.h"
23 #include "chartdataset_p.h"
23 #include "chartdataset_p.h"
24 #include "charttheme_p.h"
24 #include "charttheme_p.h"
25 #include "qchart_p.h"
25 #include "qchart_p.h"
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
28
29 /*!
29 /*!
30 \class QAbstractAxis
30 \class QAbstractAxis
31 \brief The QAbstractAxis class is used for manipulating chart's axis.
31 \brief The QAbstractAxis class is used for manipulating chart's axis.
32 \mainclass
32 \mainclass
33
33
34 Each series can be bound to one or more horizontal and vertical axes, but mixing axis types
34 Each series can be bound to one or more horizontal and vertical axes, but mixing axis types
35 that would result in different domains is not supported, such as specifying
35 that would result in different domains is not supported, such as specifying
36 QValueAxis and QLogValueAxis on the same orientation.
36 QValueAxis and QLogValueAxis on the same orientation.
37
37
38 Properties and visibility of various axis elements such as axis line, title, labels, grid lines,
38 Properties and visibility of various axis elements such as axis line, title, labels, grid lines,
39 and shades can be individually controlled.
39 and shades can be individually controlled.
40 */
40 */
41
41
42 /*!
42 /*!
43 \qmlclass AbstractAxis QAbstractAxis
43 \qmlclass AbstractAxis QAbstractAxis
44 \brief The AbstractAxis is a base element used for specialized axis elements
44 \brief The AbstractAxis is a base element used for specialized axis elements
45
45
46 Each series can be bound to only one horizontal and vertical axis.
46 Each series can be bound to only one horizontal and vertical axis.
47
47
48 Properties and visibility of various axis elements such as axis line, title, labels, grid lines,
48 Properties and visibility of various axis elements such as axis line, title, labels, grid lines,
49 and shades can be individually controlled.
49 and shades can be individually controlled.
50 */
50 */
51
51
52 /*!
52 /*!
53 \enum QAbstractAxis::AxisType
53 \enum QAbstractAxis::AxisType
54
54
55 The type of the series object.
55 The type of the series object.
56
56
57 \value AxisTypeNoAxis
57 \value AxisTypeNoAxis
58 \value AxisTypeValue
58 \value AxisTypeValue
59 \value AxisTypeBarCategory
59 \value AxisTypeBarCategory
60 \value AxisTypeCategory
60 \value AxisTypeCategory
61 \value AxisTypeDateTime
61 \value AxisTypeDateTime
62 \value AxisTypeLogValue
62 \value AxisTypeLogValue
63 */
63 */
64
64
65 /*!
65 /*!
66 *\fn void QAbstractAxis::type() const
66 *\fn void QAbstractAxis::type() const
67 Returns the type of the axis
67 Returns the type of the axis
68 */
68 */
69
69
70 /*!
70 /*!
71 \property QAbstractAxis::lineVisible
71 \property QAbstractAxis::lineVisible
72 The visibility of the axis line
72 The visibility of the axis line
73 */
73 */
74 /*!
74 /*!
75 \qmlproperty bool AbstractAxis::lineVisible
75 \qmlproperty bool AbstractAxis::lineVisible
76 The visibility of the axis line
76 The visibility of the axis line
77 */
77 */
78
78
79 /*!
79 /*!
80 \property QAbstractAxis::linePen
80 \property QAbstractAxis::linePen
81 The pen of the line.
81 The pen of the line.
82 */
82 */
83
83
84 /*!
84 /*!
85 \property QAbstractAxis::labelsVisible
85 \property QAbstractAxis::labelsVisible
86 Defines if axis labels are visible.
86 Defines if axis labels are visible.
87 */
87 */
88 /*!
88 /*!
89 \qmlproperty bool AbstractAxis::labelsVisible
89 \qmlproperty bool AbstractAxis::labelsVisible
90 Defines if axis labels are visible.
90 Defines if axis labels are visible.
91 */
91 */
92
92
93 /*!
93 /*!
94 \property QAbstractAxis::labelsPen
94 \property QAbstractAxis::labelsPen
95 The pen of the labels.
95 The pen of the labels.
96 */
96 */
97
97
98 /*!
98 /*!
99 \property QAbstractAxis::labelsBrush
99 \property QAbstractAxis::labelsBrush
100 The brush of the labels.
100 The brush of the labels.
101 */
101 */
102
102
103 /*!
103 /*!
104 \property QAbstractAxis::visible
104 \property QAbstractAxis::visible
105 The visibility of the axis.
105 The visibility of the axis.
106 */
106 */
107 /*!
107 /*!
108 \qmlproperty bool AbstractAxis::visible
108 \qmlproperty bool AbstractAxis::visible
109 The visibility of the axis.
109 The visibility of the axis.
110 */
110 */
111
111
112 /*!
112 /*!
113 \property QAbstractAxis::gridVisible
113 \property QAbstractAxis::gridVisible
114 The visibility of the grid lines.
114 The visibility of the grid lines.
115 */
115 */
116 /*!
116 /*!
117 \qmlproperty bool AbstractAxis::gridVisible
117 \qmlproperty bool AbstractAxis::gridVisible
118 The visibility of the grid lines.
118 The visibility of the grid lines.
119 */
119 */
120
120
121 /*!
121 /*!
122 \property QAbstractAxis::color
122 \property QAbstractAxis::color
123 The color of the axis and ticks.
123 The color of the axis and ticks.
124 */
124 */
125 /*!
125 /*!
126 \qmlproperty color AbstractAxis::color
126 \qmlproperty color AbstractAxis::color
127 The color of the axis and ticks.
127 The color of the axis and ticks.
128 */
128 */
129
129
130 /*!
130 /*!
131 \property QAbstractAxis::gridLinePen
131 \property QAbstractAxis::gridLinePen
132 The pen of the grid line.
132 The pen of the grid line.
133 */
133 */
134
134
135 /*!
135 /*!
136 \property QAbstractAxis::labelsFont
136 \property QAbstractAxis::labelsFont
137 The font of the axis labels.
137 The font of the axis labels.
138 */
138 */
139
139
140 /*!
140 /*!
141 \qmlproperty Font AbstractAxis::labelsFont
141 \qmlproperty Font AbstractAxis::labelsFont
142 The font of the axis labels.
142 The font of the axis labels.
143
143
144 See the \l {Font} {QML Font Element} for detailed documentation.
144 See the \l {Font} {QML Font Element} for detailed documentation.
145 */
145 */
146
146
147 /*!
147 /*!
148 \property QAbstractAxis::labelsColor
148 \property QAbstractAxis::labelsColor
149 The color of the axis labels.
149 The color of the axis labels.
150 */
150 */
151 /*!
151 /*!
152 \qmlproperty color AbstractAxis::labelsColor
152 \qmlproperty color AbstractAxis::labelsColor
153 The color of the axis labels.
153 The color of the axis labels.
154 */
154 */
155
155
156 /*!
156 /*!
157 \property QAbstractAxis::labelsAngle
157 \property QAbstractAxis::labelsAngle
158 The angle of the axis labels in degrees.
158 The angle of the axis labels in degrees.
159 */
159 */
160 /*!
160 /*!
161 \qmlproperty int AbstractAxis::labelsAngle
161 \qmlproperty int AbstractAxis::labelsAngle
162 The angle of the axis labels in degrees.
162 The angle of the axis labels in degrees.
163 */
163 */
164
164
165 /*!
165 /*!
166 \property QAbstractAxis::shadesVisible
166 \property QAbstractAxis::shadesVisible
167 The visibility of the axis shades.
167 The visibility of the axis shades.
168 */
168 */
169 /*!
169 /*!
170 \qmlproperty bool AbstractAxis::shadesVisible
170 \qmlproperty bool AbstractAxis::shadesVisible
171 The visibility of the axis shades.
171 The visibility of the axis shades.
172 */
172 */
173
173
174 /*!
174 /*!
175 \property QAbstractAxis::shadesColor
175 \property QAbstractAxis::shadesColor
176 The fill (brush) color of the axis shades.
176 The fill (brush) color of the axis shades.
177 */
177 */
178 /*!
178 /*!
179 \qmlproperty color AbstractAxis::shadesColor
179 \qmlproperty color AbstractAxis::shadesColor
180 The fill (brush) color of the axis shades.
180 The fill (brush) color of the axis shades.
181 */
181 */
182
182
183 /*!
183 /*!
184 \property QAbstractAxis::shadesBorderColor
184 \property QAbstractAxis::shadesBorderColor
185 The border (pen) color of the axis shades.
185 The border (pen) color of the axis shades.
186 */
186 */
187 /*!
187 /*!
188 \qmlproperty color AbstractAxis::shadesBorderColor
188 \qmlproperty color AbstractAxis::shadesBorderColor
189 The border (pen) color of the axis shades.
189 The border (pen) color of the axis shades.
190 */
190 */
191
191
192 /*!
192 /*!
193 \property QAbstractAxis::shadesPen
193 \property QAbstractAxis::shadesPen
194 The pen of the axis shades (area between grid lines).
194 The pen of the axis shades (area between grid lines).
195 */
195 */
196
196
197 /*!
197 /*!
198 \property QAbstractAxis::shadesBrush
198 \property QAbstractAxis::shadesBrush
199 The brush of the axis shades (area between grid lines).
199 The brush of the axis shades (area between grid lines).
200 */
200 */
201
201
202 /*!
202 /*!
203 \property QAbstractAxis::titleVisible
203 \property QAbstractAxis::titleVisible
204 The visibility of the axis title. By default the value is true.
204 The visibility of the axis title. By default the value is true.
205 */
205 */
206 /*!
206 /*!
207 \qmlproperty bool AbstractAxis::titleVisible
207 \qmlproperty bool AbstractAxis::titleVisible
208 The visibility of the axis title. By default the value is true.
208 The visibility of the axis title. By default the value is true.
209 */
209 */
210
210
211 /*!
211 /*!
212 \property QAbstractAxis::titleText
212 \property QAbstractAxis::titleText
213 The title of the axis. Empty by default.
213 The title of the axis. Empty by default.
214 */
214 */
215 /*!
215 /*!
216 \qmlproperty String AbstractAxis::titleText
216 \qmlproperty String AbstractAxis::titleText
217 The title of the axis. Empty by default.
217 The title of the axis. Empty by default.
218 */
218 */
219
219
220 /*!
220 /*!
221 \property QAbstractAxis::titlePen
221 \property QAbstractAxis::titlePen
222 The pen of the title text.
222 The pen of the title text.
223 */
223 */
224
224
225 /*!
225 /*!
226 \property QAbstractAxis::titleBrush
226 \property QAbstractAxis::titleBrush
227 The brush of the title text.
227 The brush of the title text.
228 */
228 */
229
229
230 /*!
230 /*!
231 \property QAbstractAxis::titleFont
231 \property QAbstractAxis::titleFont
232 The font of the title of the axis.
232 The font of the title of the axis.
233 */
233 */
234 /*!
234 /*!
235 \qmlproperty Font AbstractAxis::titleFont
235 \qmlproperty Font AbstractAxis::titleFont
236 The font of the title of the axis.
236 The font of the title of the axis.
237 */
237 */
238
238
239 /*!
239 /*!
240 \property QAbstractAxis::orientation
240 \property QAbstractAxis::orientation
241 The orientation of the axis. Fixed to either Qt::Horizontal or Qt::Vertical when you add the axis to a chart.
241 The orientation of the axis. Fixed to either Qt::Horizontal or Qt::Vertical when you add the axis to a chart.
242 */
242 */
243 /*!
243 /*!
244 \qmlproperty Qt.Orientation AbstractAxis::orientation
244 \qmlproperty Qt.Orientation AbstractAxis::orientation
245 The orientation of the axis. Fixed to either Qt.Horizontal or Qt.Vertical when the axis is set to a series.
245 The orientation of the axis. Fixed to either Qt.Horizontal or Qt.Vertical when the axis is set to a series.
246 */
246 */
247
247
248 /*!
248 /*!
249 \property QAbstractAxis::alignment
249 \property QAbstractAxis::alignment
250 The alignment of the axis. Can be Qt::AlignLeft, Qt::AlignRight, Qt::AlignBottom, or Qt::AlignTop.
250 The alignment of the axis. Can be Qt::AlignLeft, Qt::AlignRight, Qt::AlignBottom, or Qt::AlignTop.
251 */
251 */
252 /*!
252 /*!
253 \qmlproperty alignment AbstractAxis::alignment
253 \qmlproperty alignment AbstractAxis::alignment
254 The alignment of the axis. Can be Qt.AlignLeft, Qt.AlignRight, Qt.AlignBottom, or Qt.AlignTop.
254 The alignment of the axis. Can be Qt.AlignLeft, Qt.AlignRight, Qt.AlignBottom, or Qt.AlignTop.
255 */
255 */
256
256
257 /*!
257 /*!
258 \fn void QAbstractAxis::visibleChanged(bool visible)
258 \fn void QAbstractAxis::visibleChanged(bool visible)
259 Visibility of the axis has changed to \a visible.
259 Visibility of the axis has changed to \a visible.
260 */
260 */
261 /*!
261 /*!
262 \qmlsignal AbstractAxis::onVisibleChanged(bool visible)
262 \qmlsignal AbstractAxis::onVisibleChanged(bool visible)
263 Visibility of the axis has changed to \a visible.
263 Visibility of the axis has changed to \a visible.
264 */
264 */
265
265
266 /*!
266 /*!
267 \fn void QAbstractAxis::linePenChanged(const QPen& pen)
267 \fn void QAbstractAxis::linePenChanged(const QPen& pen)
268 The pen of the line of the axis has changed to \a pen.
268 The pen of the line of the axis has changed to \a pen.
269 */
269 */
270
270
271 /*!
271 /*!
272 \fn void QAbstractAxis::lineVisibleChanged(bool visible)
272 \fn void QAbstractAxis::lineVisibleChanged(bool visible)
273 Visibility of the axis line has changed to \a visible.
273 Visibility of the axis line has changed to \a visible.
274 */
274 */
275 /*!
275 /*!
276 \qmlsignal AbstractAxis::onLineVisibleChanged(bool visible)
276 \qmlsignal AbstractAxis::onLineVisibleChanged(bool visible)
277 Visibility of the axis line has changed to \a visible.
277 Visibility of the axis line has changed to \a visible.
278 */
278 */
279
279
280 /*!
280 /*!
281 \fn void QAbstractAxis::labelsVisibleChanged(bool visible)
281 \fn void QAbstractAxis::labelsVisibleChanged(bool visible)
282 Visibility of the labels of the axis has changed to \a visible.
282 Visibility of the labels of the axis has changed to \a visible.
283 */
283 */
284 /*!
284 /*!
285 \qmlsignal AbstractAxis::onLabelsVisibleChanged(bool visible)
285 \qmlsignal AbstractAxis::onLabelsVisibleChanged(bool visible)
286 Visibility of the labels of the axis has changed to \a visible.
286 Visibility of the labels of the axis has changed to \a visible.
287 */
287 */
288
288
289 /*!
289 /*!
290 \fn void QAbstractAxis::labelsFontChanged(const QFont& font)
290 \fn void QAbstractAxis::labelsFontChanged(const QFont& font)
291 The font of the axis labels has changed to \a font.
291 The font of the axis labels has changed to \a font.
292 */
292 */
293 /*!
293 /*!
294 \qmlsignal AbstractAxis::onLabelsFontChanged(Font font)
294 \qmlsignal AbstractAxis::onLabelsFontChanged(Font font)
295 The font of the axis labels has changed to \a font.
295 The font of the axis labels has changed to \a font.
296 */
296 */
297
297
298 /*!
298 /*!
299 \fn void QAbstractAxis::labelsPenChanged(const QPen& pen)
299 \fn void QAbstractAxis::labelsPenChanged(const QPen& pen)
300 The pen of the axis labels has changed to \a pen.
300 The pen of the axis labels has changed to \a pen.
301 */
301 */
302
302
303 /*!
303 /*!
304 \fn void QAbstractAxis::labelsBrushChanged(const QBrush& brush)
304 \fn void QAbstractAxis::labelsBrushChanged(const QBrush& brush)
305 The brush of the axis labels has changed to \a brush.
305 The brush of the axis labels has changed to \a brush.
306 */
306 */
307
307
308 /*!
308 /*!
309 \fn void QAbstractAxis::labelsAngleChanged(int angle)
309 \fn void QAbstractAxis::labelsAngleChanged(int angle)
310 The angle of the axis labels has changed to \a angle.
310 The angle of the axis labels has changed to \a angle.
311 */
311 */
312 /*!
312 /*!
313 \qmlsignal AbstractAxis::onLabelsAngleChanged(int angle)
313 \qmlsignal AbstractAxis::onLabelsAngleChanged(int angle)
314 The angle of the axis labels has changed to \a angle.
314 The angle of the axis labels has changed to \a angle.
315 */
315 */
316
316
317 /*!
317 /*!
318 \fn void QAbstractAxis::gridVisibleChanged(bool visible)
318 \fn void QAbstractAxis::gridVisibleChanged(bool visible)
319 Visibility of the grid lines of the axis has changed to \a visible.
319 Visibility of the grid lines of the axis has changed to \a visible.
320 */
320 */
321 /*!
321 /*!
322 \qmlsignal AbstractAxis::onGridVisibleChanged(bool visible)
322 \qmlsignal AbstractAxis::onGridVisibleChanged(bool visible)
323 Visibility of the grid lines of the axis has changed to \a visible.
323 Visibility of the grid lines of the axis has changed to \a visible.
324 */
324 */
325
325
326 /*!
326 /*!
327 \fn void QAbstractAxis::gridLinePenChanged(const QPen& pen)
327 \fn void QAbstractAxis::gridLinePenChanged(const QPen& pen)
328 The pen of the grid line has changed to \a pen.
328 The pen of the grid line has changed to \a pen.
329 */
329 */
330
330
331 /*!
331 /*!
332 \fn void QAbstractAxis::colorChanged(QColor color)
332 \fn void QAbstractAxis::colorChanged(QColor color)
333 Emitted if the \a color of the axis is changed.
333 Emitted if the \a color of the axis is changed.
334 */
334 */
335 /*!
335 /*!
336 \qmlsignal AbstractAxis::onColorChanged(QColor color)
336 \qmlsignal AbstractAxis::onColorChanged(QColor color)
337 Emitted if the \a color of the axis is changed.
337 Emitted if the \a color of the axis is changed.
338 */
338 */
339
339
340 /*!
340 /*!
341 \fn void QAbstractAxis::labelsColorChanged(QColor color)
341 \fn void QAbstractAxis::labelsColorChanged(QColor color)
342 Emitted if the \a color of the axis labels is changed.
342 Emitted if the \a color of the axis labels is changed.
343 */
343 */
344 /*!
344 /*!
345 \qmlsignal AbstractAxis::onLabelsColorChanged(QColor color)
345 \qmlsignal AbstractAxis::onLabelsColorChanged(QColor color)
346 Emitted if the \a color of the axis labels is changed.
346 Emitted if the \a color of the axis labels is changed.
347 */
347 */
348
348
349 /*!
349 /*!
350 \fn void QAbstractAxis::titleVisibleChanged(bool visible)
350 \fn void QAbstractAxis::titleVisibleChanged(bool visible)
351 Visibility of the title text of the axis has changed to \a visible.
351 Visibility of the title text of the axis has changed to \a visible.
352 */
352 */
353 /*!
353 /*!
354 \qmlsignal AbstractAxis::onTitleVisibleChanged(bool visible)
354 \qmlsignal AbstractAxis::onTitleVisibleChanged(bool visible)
355 Visibility of the title text of the axis has changed to \a visible.
355 Visibility of the title text of the axis has changed to \a visible.
356 */
356 */
357
357
358 /*!
358 /*!
359 \fn void QAbstractAxis::titleTextChanged(const QString& text)
359 \fn void QAbstractAxis::titleTextChanged(const QString& text)
360 The text of the axis title has changed to \a text.
360 The text of the axis title has changed to \a text.
361 */
361 */
362 /*!
362 /*!
363 \qmlsignal AbstractAxis::onTitleTextChanged(String text)
363 \qmlsignal AbstractAxis::onTitleTextChanged(String text)
364 The text of the axis title has changed to \a text.
364 The text of the axis title has changed to \a text.
365 */
365 */
366
366
367 /*!
367 /*!
368 \fn void QAbstractAxis::titlePenChanged(const QPen& pen)
368 \fn void QAbstractAxis::titlePenChanged(const QPen& pen)
369 The pen of the axis shades has changed to \a pen.
369 The pen of the axis shades has changed to \a pen.
370 */
370 */
371
371
372 /*!
372 /*!
373 \fn void QAbstractAxis::titleBrushChanged(const QBrush& brush)
373 \fn void QAbstractAxis::titleBrushChanged(const QBrush& brush)
374 The brush of the axis title has changed to \a brush.
374 The brush of the axis title has changed to \a brush.
375 */
375 */
376
376
377 /*!
377 /*!
378 \fn void QAbstractAxis::titleFontChanged(const QFont& font)
378 \fn void QAbstractAxis::titleFontChanged(const QFont& font)
379 The font of the axis title has changed to \a font.
379 The font of the axis title has changed to \a font.
380 */
380 */
381 /*!
381 /*!
382 \qmlsignal AbstractAxis::onTitleFontChanged(Font font)
382 \qmlsignal AbstractAxis::onTitleFontChanged(Font font)
383 The font of the axis title has changed to \a font.
383 The font of the axis title has changed to \a font.
384 */
384 */
385
385
386 /*!
386 /*!
387 \fn void QAbstractAxis::shadesVisibleChanged(bool)
387 \fn void QAbstractAxis::shadesVisibleChanged(bool)
388 Emitted if the visibility of the axis shades is changed to \a visible.
388 Emitted if the visibility of the axis shades is changed to \a visible.
389 */
389 */
390 /*!
390 /*!
391 \qmlsignal AbstractAxis::onShadesVisibleChanged(bool visible)
391 \qmlsignal AbstractAxis::onShadesVisibleChanged(bool visible)
392 Emitted if the visibility of the axis shades is changed to \a visible.
392 Emitted if the visibility of the axis shades is changed to \a visible.
393 */
393 */
394
394
395 /*!
395 /*!
396 \fn void QAbstractAxis::shadesColorChanged(QColor color)
396 \fn void QAbstractAxis::shadesColorChanged(QColor color)
397 Emitted if the \a color of the axis shades is changed.
397 Emitted if the \a color of the axis shades is changed.
398 */
398 */
399 /*!
399 /*!
400 \qmlsignal AbstractAxis::onShadesColorChanged(QColor color)
400 \qmlsignal AbstractAxis::onShadesColorChanged(QColor color)
401 Emitted if the \a color of the axis shades is changed.
401 Emitted if the \a color of the axis shades is changed.
402 */
402 */
403
403
404 /*!
404 /*!
405 \fn void QAbstractAxis::shadesBorderColorChanged(QColor)
405 \fn void QAbstractAxis::shadesBorderColorChanged(QColor)
406 Emitted if the border \a color of the axis shades is changed.
406 Emitted if the border \a color of the axis shades is changed.
407 */
407 */
408 /*!
408 /*!
409 \qmlsignal AbstractAxis::onBorderColorChanged(QColor color)
409 \qmlsignal AbstractAxis::onBorderColorChanged(QColor color)
410 Emitted if the border \a color of the axis shades is changed.
410 Emitted if the border \a color of the axis shades is changed.
411 */
411 */
412
412
413 /*!
413 /*!
414 \fn void QAbstractAxis::shadesBrushChanged(const QBrush& brush)
414 \fn void QAbstractAxis::shadesBrushChanged(const QBrush& brush)
415 The brush of the axis shades has changed to \a brush.
415 The brush of the axis shades has changed to \a brush.
416 */
416 */
417
417
418 /*!
418 /*!
419 \fn void QAbstractAxis::shadesPenChanged(const QPen& pen)
419 \fn void QAbstractAxis::shadesPenChanged(const QPen& pen)
420 The pen of the axis shades has changed to \a pen.
420 The pen of the axis shades has changed to \a pen.
421 */
421 */
422
422
423 /*!
423 /*!
424 \internal
424 \internal
425 Constructs new axis object which is a child of \a parent. Ownership is taken by
425 Constructs new axis object which is a child of \a parent. Ownership is taken by
426 QChart when axis added.
426 QChart when axis added.
427 */
427 */
428
428
429 QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent)
429 QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent)
430 : QObject(parent),
430 : QObject(parent),
431 d_ptr(&d)
431 d_ptr(&d)
432 {
432 {
433 }
433 }
434
434
435 /*!
435 /*!
436 Destructor of the axis object. When axis is added to chart, chart object takes ownership.
436 Destructor of the axis object. When axis is added to chart, chart object takes ownership.
437 */
437 */
438
438
439 QAbstractAxis::~QAbstractAxis()
439 QAbstractAxis::~QAbstractAxis()
440 {
440 {
441 if (d_ptr->m_chart)
441 if (d_ptr->m_chart)
442 qFatal("Still binded axis detected !");
442 qFatal("Still binded axis detected !");
443 }
443 }
444
444
445 /*!
445 /*!
446 Sets \a pen used to draw axis line and ticks.
446 Sets \a pen used to draw axis line and ticks.
447 */
447 */
448 void QAbstractAxis::setLinePen(const QPen &pen)
448 void QAbstractAxis::setLinePen(const QPen &pen)
449 {
449 {
450 if (d_ptr->m_axisPen != pen) {
450 if (d_ptr->m_axisPen != pen) {
451 d_ptr->m_axisPen = pen;
451 d_ptr->m_axisPen = pen;
452 emit linePenChanged(pen);
452 emit linePenChanged(pen);
453 }
453 }
454 }
454 }
455
455
456 /*!
456 /*!
457 Returns pen used to draw axis and ticks.
457 Returns pen used to draw axis and ticks.
458 */
458 */
459 QPen QAbstractAxis::linePen() const
459 QPen QAbstractAxis::linePen() const
460 {
460 {
461 return d_ptr->m_axisPen;
461 if (d_ptr->m_axisPen == QChartPrivate::defaultPen())
462 return QPen();
463 else
464 return d_ptr->m_axisPen;
462 }
465 }
463
466
464 //TODO: remove me 2.0
467 //TODO: remove me 2.0
465 void QAbstractAxis::setLinePenColor(QColor color)
468 void QAbstractAxis::setLinePenColor(QColor color)
466 {
469 {
467 QPen p = d_ptr->m_axisPen;
470 QPen p = d_ptr->m_axisPen;
468 if (p.color() != color) {
471 if (p.color() != color) {
469 p.setColor(color);
472 p.setColor(color);
470 setLinePen(p);
473 setLinePen(p);
471 emit colorChanged(color);
474 emit colorChanged(color);
472 }
475 }
473 }
476 }
474
477
475 QColor QAbstractAxis::linePenColor() const
478 QColor QAbstractAxis::linePenColor() const
476 {
479 {
477 return d_ptr->m_axisPen.color();
480 return linePen().color();
478 }
481 }
479
482
480 /*!
483 /*!
481 Sets if axis and ticks are \a visible.
484 Sets if axis and ticks are \a visible.
482 */
485 */
483 void QAbstractAxis::setLineVisible(bool visible)
486 void QAbstractAxis::setLineVisible(bool visible)
484 {
487 {
485 if (d_ptr->m_arrowVisible != visible) {
488 if (d_ptr->m_arrowVisible != visible) {
486 d_ptr->m_arrowVisible = visible;
489 d_ptr->m_arrowVisible = visible;
487 emit lineVisibleChanged(visible);
490 emit lineVisibleChanged(visible);
488 }
491 }
489 }
492 }
490
493
491 bool QAbstractAxis::isLineVisible() const
494 bool QAbstractAxis::isLineVisible() const
492 {
495 {
493 return d_ptr->m_arrowVisible;
496 return d_ptr->m_arrowVisible;
494 }
497 }
495
498
496 void QAbstractAxis::setGridLineVisible(bool visible)
499 void QAbstractAxis::setGridLineVisible(bool visible)
497 {
500 {
498 if (d_ptr->m_gridLineVisible != visible) {
501 if (d_ptr->m_gridLineVisible != visible) {
499 d_ptr->m_gridLineVisible = visible;
502 d_ptr->m_gridLineVisible = visible;
500 emit gridVisibleChanged(visible);
503 emit gridVisibleChanged(visible);
501 }
504 }
502 }
505 }
503
506
504 bool QAbstractAxis::isGridLineVisible() const
507 bool QAbstractAxis::isGridLineVisible() const
505 {
508 {
506 return d_ptr->m_gridLineVisible;
509 return d_ptr->m_gridLineVisible;
507 }
510 }
508
511
509 /*!
512 /*!
510 Sets \a pen used to draw grid line.
513 Sets \a pen used to draw grid line.
511 */
514 */
512 void QAbstractAxis::setGridLinePen(const QPen &pen)
515 void QAbstractAxis::setGridLinePen(const QPen &pen)
513 {
516 {
514 if (d_ptr->m_gridLinePen != pen) {
517 if (d_ptr->m_gridLinePen != pen) {
515 d_ptr->m_gridLinePen = pen;
518 d_ptr->m_gridLinePen = pen;
516 emit gridLinePenChanged(pen);
519 emit gridLinePenChanged(pen);
517 }
520 }
518 }
521 }
519
522
520 /*!
523 /*!
521 Returns pen used to draw grid.
524 Returns pen used to draw grid.
522 */
525 */
523 QPen QAbstractAxis::gridLinePen() const
526 QPen QAbstractAxis::gridLinePen() const
524 {
527 {
525 return d_ptr->m_gridLinePen;
528 if (d_ptr->m_gridLinePen == QChartPrivate::defaultPen())
529 return QPen();
530 else
531 return d_ptr->m_gridLinePen;
526 }
532 }
527
533
528 void QAbstractAxis::setLabelsVisible(bool visible)
534 void QAbstractAxis::setLabelsVisible(bool visible)
529 {
535 {
530 if (d_ptr->m_labelsVisible != visible) {
536 if (d_ptr->m_labelsVisible != visible) {
531 d_ptr->m_labelsVisible = visible;
537 d_ptr->m_labelsVisible = visible;
532 emit labelsVisibleChanged(visible);
538 emit labelsVisibleChanged(visible);
533 }
539 }
534 }
540 }
535
541
536 bool QAbstractAxis::labelsVisible() const
542 bool QAbstractAxis::labelsVisible() const
537 {
543 {
538 return d_ptr->m_labelsVisible;
544 return d_ptr->m_labelsVisible;
539 }
545 }
540
546
541 /*!
547 /*!
542 Sets \a pen used to draw labels.
548 Sets \a pen used to draw labels.
543 */
549 */
544 void QAbstractAxis::setLabelsPen(const QPen &pen)
550 void QAbstractAxis::setLabelsPen(const QPen &pen)
545 {
551 {
546 if (d_ptr->m_labelsPen != pen) {
552 if (d_ptr->m_labelsPen != pen) {
547 d_ptr->m_labelsPen = pen;
553 d_ptr->m_labelsPen = pen;
548 emit labelsPenChanged(pen);
554 emit labelsPenChanged(pen);
549 }
555 }
550 }
556 }
551
557
552 /*!
558 /*!
553 Returns the pen used to labels.
559 Returns the pen used to labels.
554 */
560 */
555 QPen QAbstractAxis::labelsPen() const
561 QPen QAbstractAxis::labelsPen() const
556 {
562 {
557 return d_ptr->m_labelsPen;
563 if (d_ptr->m_labelsPen == QChartPrivate::defaultPen())
564 return QPen();
565 else
566 return d_ptr->m_labelsPen;
558 }
567 }
559
568
560 /*!
569 /*!
561 Sets \a brush used to draw labels.
570 Sets \a brush used to draw labels.
562 */
571 */
563 void QAbstractAxis::setLabelsBrush(const QBrush &brush)
572 void QAbstractAxis::setLabelsBrush(const QBrush &brush)
564 {
573 {
565 if (d_ptr->m_labelsBrush != brush) {
574 if (d_ptr->m_labelsBrush != brush) {
566 d_ptr->m_labelsBrush = brush;
575 d_ptr->m_labelsBrush = brush;
567 emit labelsBrushChanged(brush);
576 emit labelsBrushChanged(brush);
568 }
577 }
569 }
578 }
570
579
571 /*!
580 /*!
572 Returns brush used to draw labels.
581 Returns brush used to draw labels.
573 */
582 */
574 QBrush QAbstractAxis::labelsBrush() const
583 QBrush QAbstractAxis::labelsBrush() const
575 {
584 {
576 return d_ptr->m_labelsBrush;
585 if (d_ptr->m_labelsBrush == QChartPrivate::defaultBrush())
586 return QBrush();
587 else
588 return d_ptr->m_labelsBrush;
577 }
589 }
578
590
579 /*!
591 /*!
580 Sets \a font used to draw labels.
592 Sets \a font used to draw labels.
581 */
593 */
582 void QAbstractAxis::setLabelsFont(const QFont &font)
594 void QAbstractAxis::setLabelsFont(const QFont &font)
583 {
595 {
584 if (d_ptr->m_labelsFont != font) {
596 if (d_ptr->m_labelsFont != font) {
585 d_ptr->m_labelsFont = font;
597 d_ptr->m_labelsFont = font;
586 emit labelsFontChanged(font);
598 emit labelsFontChanged(font);
587 }
599 }
588 }
600 }
589
601
590 /*!
602 /*!
591 Returns font used to draw labels.
603 Returns font used to draw labels.
592 */
604 */
593 QFont QAbstractAxis::labelsFont() const
605 QFont QAbstractAxis::labelsFont() const
594 {
606 {
595 return d_ptr->m_labelsFont;
607 if (d_ptr->m_labelsFont == QChartPrivate::defaultFont())
608 return QFont();
609 else
610 return d_ptr->m_labelsFont;
596 }
611 }
597
612
598 void QAbstractAxis::setLabelsAngle(int angle)
613 void QAbstractAxis::setLabelsAngle(int angle)
599 {
614 {
600 if (d_ptr->m_labelsAngle != angle) {
615 if (d_ptr->m_labelsAngle != angle) {
601 d_ptr->m_labelsAngle = angle;
616 d_ptr->m_labelsAngle = angle;
602 emit labelsAngleChanged(angle);
617 emit labelsAngleChanged(angle);
603 }
618 }
604 }
619 }
605
620
606 int QAbstractAxis::labelsAngle() const
621 int QAbstractAxis::labelsAngle() const
607 {
622 {
608 return d_ptr->m_labelsAngle;
623 return d_ptr->m_labelsAngle;
609 }
624 }
610 //TODO: remove me 2.0
625 //TODO: remove me 2.0
611 void QAbstractAxis::setLabelsColor(QColor color)
626 void QAbstractAxis::setLabelsColor(QColor color)
612 {
627 {
613 QBrush b = d_ptr->m_labelsBrush;
628 QBrush b = d_ptr->m_labelsBrush;
614 if (b.color() != color) {
629 if (b.color() != color) {
615 b.setColor(color);
630 b.setColor(color);
616 setLabelsBrush(b);
631 setLabelsBrush(b);
617 emit labelsColorChanged(color);
632 emit labelsColorChanged(color);
618 }
633 }
619 }
634 }
620
635
621 QColor QAbstractAxis::labelsColor() const
636 QColor QAbstractAxis::labelsColor() const
622 {
637 {
623 return d_ptr->m_labelsBrush.color();
638 return labelsBrush().color();
624 }
639 }
625
640
626 void QAbstractAxis::setTitleVisible(bool visible)
641 void QAbstractAxis::setTitleVisible(bool visible)
627 {
642 {
628 if (d_ptr->m_titleVisible != visible) {
643 if (d_ptr->m_titleVisible != visible) {
629 d_ptr->m_titleVisible = visible;
644 d_ptr->m_titleVisible = visible;
630 emit titleVisibleChanged(visible);
645 emit titleVisibleChanged(visible);
631 }
646 }
632 }
647 }
633
648
634 bool QAbstractAxis::isTitleVisible() const
649 bool QAbstractAxis::isTitleVisible() const
635 {
650 {
636 return d_ptr->m_titleVisible;
651 return d_ptr->m_titleVisible;
637 }
652 }
638
653
639 /*!
654 /*!
640 Sets \a pen used to draw title.
655 Sets \a pen used to draw title.
641 */
656 */
642 void QAbstractAxis::setTitlePen(const QPen &pen)
657 void QAbstractAxis::setTitlePen(const QPen &pen)
643 {
658 {
644 if (d_ptr->m_titlePen != pen) {
659 if (d_ptr->m_titlePen != pen) {
645 d_ptr->m_titlePen = pen;
660 d_ptr->m_titlePen = pen;
646 emit titlePenChanged(pen);
661 emit titlePenChanged(pen);
647 }
662 }
648 }
663 }
649
664
650 /*!
665 /*!
651 Returns the pen used to title.
666 Returns the pen used to title.
652 */
667 */
653 QPen QAbstractAxis::titlePen() const
668 QPen QAbstractAxis::titlePen() const
654 {
669 {
655 return d_ptr->m_titlePen;
670 if (d_ptr->m_titlePen == QChartPrivate::defaultPen())
671 return QPen();
672 else
673 return d_ptr->m_titlePen;
656 }
674 }
657
675
658 /*!
676 /*!
659 Sets \a brush used to draw title.
677 Sets \a brush used to draw title.
660 */
678 */
661 void QAbstractAxis::setTitleBrush(const QBrush &brush)
679 void QAbstractAxis::setTitleBrush(const QBrush &brush)
662 {
680 {
663 if (d_ptr->m_titleBrush != brush) {
681 if (d_ptr->m_titleBrush != brush) {
664 d_ptr->m_titleBrush = brush;
682 d_ptr->m_titleBrush = brush;
665 emit titleBrushChanged(brush);
683 emit titleBrushChanged(brush);
666 }
684 }
667 }
685 }
668
686
669 /*!
687 /*!
670 Returns brush used to draw title.
688 Returns brush used to draw title.
671 */
689 */
672 QBrush QAbstractAxis::titleBrush() const
690 QBrush QAbstractAxis::titleBrush() const
673 {
691 {
674 return d_ptr->m_titleBrush;
692 if (d_ptr->m_titleBrush == QChartPrivate::defaultBrush())
693 return QBrush();
694 else
695 return d_ptr->m_titleBrush;
675 }
696 }
676
697
677 /*!
698 /*!
678 Sets \a font used to draw title.
699 Sets \a font used to draw title.
679 */
700 */
680 void QAbstractAxis::setTitleFont(const QFont &font)
701 void QAbstractAxis::setTitleFont(const QFont &font)
681 {
702 {
682 if (d_ptr->m_titleFont != font) {
703 if (d_ptr->m_titleFont != font) {
683 d_ptr->m_titleFont = font;
704 d_ptr->m_titleFont = font;
684 emit titleFontChanged(font);
705 emit titleFontChanged(font);
685 }
706 }
686 }
707 }
687
708
688 /*!
709 /*!
689 Returns font used to draw title.
710 Returns font used to draw title.
690 */
711 */
691 QFont QAbstractAxis::titleFont() const
712 QFont QAbstractAxis::titleFont() const
692 {
713 {
693 return d_ptr->m_titleFont;
714 if (d_ptr->m_titleFont == QChartPrivate::defaultFont())
715 return QFont();
716 else
717 return d_ptr->m_titleFont;
694 }
718 }
695
719
696 void QAbstractAxis::setTitleText(const QString &title)
720 void QAbstractAxis::setTitleText(const QString &title)
697 {
721 {
698 if (d_ptr->m_title != title) {
722 if (d_ptr->m_title != title) {
699 d_ptr->m_title = title;
723 d_ptr->m_title = title;
700 emit titleTextChanged(title);
724 emit titleTextChanged(title);
701 }
725 }
702 }
726 }
703
727
704 QString QAbstractAxis::titleText() const
728 QString QAbstractAxis::titleText() const
705 {
729 {
706 return d_ptr->m_title;
730 return d_ptr->m_title;
707 }
731 }
708
732
709
733
710 void QAbstractAxis::setShadesVisible(bool visible)
734 void QAbstractAxis::setShadesVisible(bool visible)
711 {
735 {
712 if (d_ptr->m_shadesVisible != visible) {
736 if (d_ptr->m_shadesVisible != visible) {
713 d_ptr->m_shadesVisible = visible;
737 d_ptr->m_shadesVisible = visible;
714 emit shadesVisibleChanged(visible);
738 emit shadesVisibleChanged(visible);
715 }
739 }
716 }
740 }
717
741
718 bool QAbstractAxis::shadesVisible() const
742 bool QAbstractAxis::shadesVisible() const
719 {
743 {
720 return d_ptr->m_shadesVisible;
744 return d_ptr->m_shadesVisible;
721 }
745 }
722
746
723 /*!
747 /*!
724 Sets \a pen used to draw shades.
748 Sets \a pen used to draw shades.
725 */
749 */
726 void QAbstractAxis::setShadesPen(const QPen &pen)
750 void QAbstractAxis::setShadesPen(const QPen &pen)
727 {
751 {
728 if (d_ptr->m_shadesPen != pen) {
752 if (d_ptr->m_shadesPen != pen) {
729 d_ptr->m_shadesPen = pen;
753 d_ptr->m_shadesPen = pen;
730 emit shadesPenChanged(pen);
754 emit shadesPenChanged(pen);
731 }
755 }
732 }
756 }
733
757
734 /*!
758 /*!
735 Returns pen used to draw shades.
759 Returns pen used to draw shades.
736 */
760 */
737 QPen QAbstractAxis::shadesPen() const
761 QPen QAbstractAxis::shadesPen() const
738 {
762 {
739 return d_ptr->m_shadesPen;
763 if (d_ptr->m_shadesPen == QChartPrivate::defaultPen())
764 return QPen();
765 else
766 return d_ptr->m_shadesPen;
740 }
767 }
741
768
742 /*!
769 /*!
743 Sets \a brush used to draw shades.
770 Sets \a brush used to draw shades.
744 */
771 */
745 void QAbstractAxis::setShadesBrush(const QBrush &brush)
772 void QAbstractAxis::setShadesBrush(const QBrush &brush)
746 {
773 {
747 if (d_ptr->m_shadesBrush != brush) {
774 if (d_ptr->m_shadesBrush != brush) {
748 d_ptr->m_shadesBrush = brush;
775 d_ptr->m_shadesBrush = brush;
749 emit shadesBrushChanged(brush);
776 emit shadesBrushChanged(brush);
750 }
777 }
751 }
778 }
752
779
753 /*!
780 /*!
754 Returns brush used to draw shades.
781 Returns brush used to draw shades.
755 */
782 */
756 QBrush QAbstractAxis::shadesBrush() const
783 QBrush QAbstractAxis::shadesBrush() const
757 {
784 {
758 return d_ptr->m_shadesBrush;
785 if (d_ptr->m_shadesBrush == QChartPrivate::defaultBrush())
786 return QBrush(Qt::SolidPattern);
787 else
788 return d_ptr->m_shadesBrush;
759 }
789 }
760
790
761 void QAbstractAxis::setShadesColor(QColor color)
791 void QAbstractAxis::setShadesColor(QColor color)
762 {
792 {
763 QBrush b = d_ptr->m_shadesBrush;
793 QBrush b = d_ptr->m_shadesBrush;
764 if (b.color() != color) {
794 if (b.color() != color) {
765 b.setColor(color);
795 b.setColor(color);
766 setShadesBrush(b);
796 setShadesBrush(b);
767 emit shadesColorChanged(color);
797 emit shadesColorChanged(color);
768 }
798 }
769 }
799 }
770
800
771 QColor QAbstractAxis::shadesColor() const
801 QColor QAbstractAxis::shadesColor() const
772 {
802 {
773 return d_ptr->m_shadesBrush.color();
803 return shadesBrush().color();
774 }
804 }
775
805
776 void QAbstractAxis::setShadesBorderColor(QColor color)
806 void QAbstractAxis::setShadesBorderColor(QColor color)
777 {
807 {
778 QPen p = d_ptr->m_shadesPen;
808 QPen p = d_ptr->m_shadesPen;
779 if (p.color() != color) {
809 if (p.color() != color) {
780 p.setColor(color);
810 p.setColor(color);
781 setShadesPen(p);
811 setShadesPen(p);
782 emit shadesColorChanged(color);
812 emit shadesColorChanged(color);
783 }
813 }
784 }
814 }
785
815
786 QColor QAbstractAxis::shadesBorderColor() const
816 QColor QAbstractAxis::shadesBorderColor() const
787 {
817 {
788 return d_ptr->m_shadesPen.color();
818 return shadesPen().color();
789 }
819 }
790
820
791
821
792 bool QAbstractAxis::isVisible() const
822 bool QAbstractAxis::isVisible() const
793 {
823 {
794 return d_ptr->m_visible;
824 return d_ptr->m_visible;
795 }
825 }
796
826
797 /*!
827 /*!
798 Sets axis, shades, labels and grid lines to be visible.
828 Sets axis, shades, labels and grid lines to be visible.
799 */
829 */
800 void QAbstractAxis::setVisible(bool visible)
830 void QAbstractAxis::setVisible(bool visible)
801 {
831 {
802 if (d_ptr->m_visible != visible) {
832 if (d_ptr->m_visible != visible) {
803 d_ptr->m_visible = visible;
833 d_ptr->m_visible = visible;
804 emit visibleChanged(visible);
834 emit visibleChanged(visible);
805 }
835 }
806 }
836 }
807
837
808
838
809 /*!
839 /*!
810 Sets axis, shades, labels and grid lines to be visible.
840 Sets axis, shades, labels and grid lines to be visible.
811 */
841 */
812 void QAbstractAxis::show()
842 void QAbstractAxis::show()
813 {
843 {
814 setVisible(true);
844 setVisible(true);
815 }
845 }
816
846
817 /*!
847 /*!
818 Sets axis, shades, labels and grid lines to not be visible.
848 Sets axis, shades, labels and grid lines to not be visible.
819 */
849 */
820 void QAbstractAxis::hide()
850 void QAbstractAxis::hide()
821 {
851 {
822 setVisible(false);
852 setVisible(false);
823 }
853 }
824
854
825 /*!
855 /*!
826 Sets the minimum value shown on the axis.
856 Sets the minimum value shown on the axis.
827 Depending on the actual axis type the \a min parameter is converted to appropriate type.
857 Depending on the actual axis type the \a min parameter is converted to appropriate type.
828 If the conversion is impossible then the function call does nothing
858 If the conversion is impossible then the function call does nothing
829 */
859 */
830 void QAbstractAxis::setMin(const QVariant &min)
860 void QAbstractAxis::setMin(const QVariant &min)
831 {
861 {
832 d_ptr->setMin(min);
862 d_ptr->setMin(min);
833 }
863 }
834
864
835 /*!
865 /*!
836 Sets the maximum value shown on the axis.
866 Sets the maximum value shown on the axis.
837 Depending on the actual axis type the \a max parameter is converted to appropriate type.
867 Depending on the actual axis type the \a max parameter is converted to appropriate type.
838 If the conversion is impossible then the function call does nothing
868 If the conversion is impossible then the function call does nothing
839 */
869 */
840 void QAbstractAxis::setMax(const QVariant &max)
870 void QAbstractAxis::setMax(const QVariant &max)
841 {
871 {
842 d_ptr->setMax(max);
872 d_ptr->setMax(max);
843 }
873 }
844
874
845 /*!
875 /*!
846 Sets the range shown on the axis.
876 Sets the range shown on the axis.
847 Depending on the actual axis type the \a min and \a max parameters are converted to appropriate types.
877 Depending on the actual axis type the \a min and \a max parameters are converted to appropriate types.
848 If the conversion is impossible then the function call does nothing.
878 If the conversion is impossible then the function call does nothing.
849 */
879 */
850 void QAbstractAxis::setRange(const QVariant &min, const QVariant &max)
880 void QAbstractAxis::setRange(const QVariant &min, const QVariant &max)
851 {
881 {
852 d_ptr->setRange(min, max);
882 d_ptr->setRange(min, max);
853 }
883 }
854
884
855
885
856 /*!
886 /*!
857 Returns the orientation in which the axis is being used (Vertical or Horizontal)
887 Returns the orientation in which the axis is being used (Vertical or Horizontal)
858 */
888 */
859 // NOTE: should have const but it breaks BC:
889 // NOTE: should have const but it breaks BC:
860 // http://techbase.kde.org/Policies/Binary_Compatibility_Examples#Change_the_CV-qualifiers_of_a_member_function
890 // http://techbase.kde.org/Policies/Binary_Compatibility_Examples#Change_the_CV-qualifiers_of_a_member_function
861 Qt::Orientation QAbstractAxis::orientation()
891 Qt::Orientation QAbstractAxis::orientation()
862 {
892 {
863 return d_ptr->orientation();
893 return d_ptr->orientation();
864 }
894 }
865
895
866 Qt::Alignment QAbstractAxis::alignment() const
896 Qt::Alignment QAbstractAxis::alignment() const
867 {
897 {
868 return d_ptr->alignment();
898 return d_ptr->alignment();
869 }
899 }
870
900
871 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
901 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
872
902
873 QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis *q)
903 QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis *q)
874 : q_ptr(q),
904 : q_ptr(q),
875 m_chart(0),
905 m_chart(0),
876 m_alignment(0),
906 m_alignment(0),
877 m_orientation(Qt::Orientation(0)),
907 m_orientation(Qt::Orientation(0)),
878 m_visible(true),
908 m_visible(true),
879 m_arrowVisible(true),
909 m_arrowVisible(true),
880 m_axisPen(QChartPrivate::defaultPen()),
910 m_axisPen(QChartPrivate::defaultPen()),
881 m_axisBrush(QChartPrivate::defaultBrush()),
911 m_axisBrush(QChartPrivate::defaultBrush()),
882 m_gridLineVisible(true),
912 m_gridLineVisible(true),
883 m_gridLinePen(QChartPrivate::defaultPen()),
913 m_gridLinePen(QChartPrivate::defaultPen()),
884 m_labelsVisible(true),
914 m_labelsVisible(true),
885 m_labelsPen(QChartPrivate::defaultPen()),
915 m_labelsPen(QChartPrivate::defaultPen()),
886 m_labelsBrush(QChartPrivate::defaultBrush()),
916 m_labelsBrush(QChartPrivate::defaultBrush()),
887 m_labelsFont(QChartPrivate::defaultFont()),
917 m_labelsFont(QChartPrivate::defaultFont()),
888 m_labelsAngle(0),
918 m_labelsAngle(0),
889 m_titleVisible(true),
919 m_titleVisible(true),
890 m_titlePen(QChartPrivate::defaultPen()),
920 m_titlePen(QChartPrivate::defaultPen()),
891 m_titleBrush(QChartPrivate::defaultBrush()),
921 m_titleBrush(QChartPrivate::defaultBrush()),
892 m_titleFont(QChartPrivate::defaultFont()),
922 m_titleFont(QChartPrivate::defaultFont()),
893 m_shadesVisible(false),
923 m_shadesVisible(false),
894 m_shadesBrush(QChartPrivate::defaultBrush()),
924 m_shadesBrush(QChartPrivate::defaultBrush()),
895 m_shadesPen(QChartPrivate::defaultPen()),
925 m_shadesPen(QChartPrivate::defaultPen()),
896 m_shadesOpacity(1.0),
926 m_shadesOpacity(1.0),
897 m_dirty(false)
927 m_dirty(false)
898 {
928 {
899 }
929 }
900
930
901 QAbstractAxisPrivate::~QAbstractAxisPrivate()
931 QAbstractAxisPrivate::~QAbstractAxisPrivate()
902 {
932 {
903 }
933 }
904
934
905 void QAbstractAxisPrivate::setAlignment( Qt::Alignment alignment)
935 void QAbstractAxisPrivate::setAlignment( Qt::Alignment alignment)
906 {
936 {
907 switch(alignment) {
937 switch(alignment) {
908 case Qt::AlignTop:
938 case Qt::AlignTop:
909 case Qt::AlignBottom:
939 case Qt::AlignBottom:
910 m_orientation = Qt::Horizontal;
940 m_orientation = Qt::Horizontal;
911 break;
941 break;
912 case Qt::AlignLeft:
942 case Qt::AlignLeft:
913 case Qt::AlignRight:
943 case Qt::AlignRight:
914 m_orientation = Qt::Vertical;
944 m_orientation = Qt::Vertical;
915 break;
945 break;
916 default:
946 default:
917 qWarning()<<"No alignment specified !";
947 qWarning()<<"No alignment specified !";
918 break;
948 break;
919 };
949 };
920 m_alignment=alignment;
950 m_alignment=alignment;
921 }
951 }
922
952
923 void QAbstractAxisPrivate::initializeTheme(ChartTheme* theme, bool forced)
953 void QAbstractAxisPrivate::initializeTheme(ChartTheme* theme, bool forced)
924 {
954 {
925 //TODO: introduce axis brush
955 //TODO: introduce axis brush
926 if (forced || QChartPrivate::defaultPen() == m_axisPen)
956 if (forced || QChartPrivate::defaultPen() == m_axisPen)
927 q_ptr->setLinePen(theme->axisLinePen());
957 q_ptr->setLinePen(theme->axisLinePen());
928
958
929 if (forced || QChartPrivate::defaultPen() == m_gridLinePen)
959 if (forced || QChartPrivate::defaultPen() == m_gridLinePen)
930 q_ptr->setGridLinePen(theme->girdLinePen());
960 q_ptr->setGridLinePen(theme->girdLinePen());
931
961
932 if (forced || QChartPrivate::defaultBrush() == m_labelsBrush)
962 if (forced || QChartPrivate::defaultBrush() == m_labelsBrush)
933 q_ptr->setLabelsBrush(theme->labelBrush());
963 q_ptr->setLabelsBrush(theme->labelBrush());
934 if (forced || QChartPrivate::defaultPen() == m_labelsPen)
964 if (forced || QChartPrivate::defaultPen() == m_labelsPen)
935 q_ptr->setLabelsPen(Qt::NoPen); // NoPen for performance reasons
965 q_ptr->setLabelsPen(Qt::NoPen); // NoPen for performance reasons
936 if (forced || QChartPrivate::defaultFont() == m_labelsFont)
966 if (forced || QChartPrivate::defaultFont() == m_labelsFont)
937 q_ptr->setLabelsFont(theme->labelFont());
967 q_ptr->setLabelsFont(theme->labelFont());
938
968
939 if (forced || QChartPrivate::defaultBrush() == m_titleBrush)
969 if (forced || QChartPrivate::defaultBrush() == m_titleBrush)
940 q_ptr->setTitleBrush(theme->labelBrush());
970 q_ptr->setTitleBrush(theme->labelBrush());
941 if (forced || QChartPrivate::defaultPen() == m_titlePen)
971 if (forced || QChartPrivate::defaultPen() == m_titlePen)
942 q_ptr->setTitlePen(Qt::NoPen); // NoPen for performance reasons
972 q_ptr->setTitlePen(Qt::NoPen); // NoPen for performance reasons
943 if (forced || QChartPrivate::defaultFont() == m_titleFont) {
973 if (forced || QChartPrivate::defaultFont() == m_titleFont) {
944 QFont font(m_labelsFont);
974 QFont font(m_labelsFont);
945 font.setBold(true);
975 font.setBold(true);
946 q_ptr->setTitleFont(font);
976 q_ptr->setTitleFont(font);
947 }
977 }
948
978
949 if (forced || QChartPrivate::defaultBrush() == m_shadesBrush)
979 if (forced || QChartPrivate::defaultBrush() == m_shadesBrush)
950 q_ptr->setShadesBrush(theme->backgroundShadesBrush());
980 q_ptr->setShadesBrush(theme->backgroundShadesBrush());
951 if (forced || QChartPrivate::defaultPen() == m_shadesPen)
981 if (forced || QChartPrivate::defaultPen() == m_shadesPen)
952 q_ptr->setShadesPen(theme->backgroundShadesPen());
982 q_ptr->setShadesPen(theme->backgroundShadesPen());
953
983
954 bool axisX = m_orientation == Qt::Horizontal;
984 bool axisX = m_orientation == Qt::Horizontal;
955 if (forced && (theme->backgroundShades() == ChartTheme::BackgroundShadesBoth
985 if (forced && (theme->backgroundShades() == ChartTheme::BackgroundShadesBoth
956 || (theme->backgroundShades() == ChartTheme::BackgroundShadesVertical && axisX)
986 || (theme->backgroundShades() == ChartTheme::BackgroundShadesVertical && axisX)
957 || (theme->backgroundShades() == ChartTheme::BackgroundShadesHorizontal && !axisX))) {
987 || (theme->backgroundShades() == ChartTheme::BackgroundShadesHorizontal && !axisX))) {
958 q_ptr->setShadesVisible(true);
988 q_ptr->setShadesVisible(true);
959 } else if (forced) {
989 } else if (forced) {
960 q_ptr->setShadesVisible(false);
990 q_ptr->setShadesVisible(false);
961 }
991 }
962 }
992 }
963
993
964 void QAbstractAxisPrivate::handleRangeChanged(qreal min, qreal max)
994 void QAbstractAxisPrivate::handleRangeChanged(qreal min, qreal max)
965 {
995 {
966 setRange(min,max);
996 setRange(min,max);
967 }
997 }
968
998
969 void QAbstractAxisPrivate::initializeGraphics(QGraphicsItem* parent)
999 void QAbstractAxisPrivate::initializeGraphics(QGraphicsItem* parent)
970 {
1000 {
971 Q_UNUSED(parent);
1001 Q_UNUSED(parent);
972 }
1002 }
973
1003
974 void QAbstractAxisPrivate::initializeAnimations(QChart::AnimationOptions options)
1004 void QAbstractAxisPrivate::initializeAnimations(QChart::AnimationOptions options)
975 {
1005 {
976 ChartAxisElement *axis = m_item.data();
1006 ChartAxisElement *axis = m_item.data();
977 Q_ASSERT(axis);
1007 Q_ASSERT(axis);
978 if (options.testFlag(QChart::GridAxisAnimations)) {
1008 if (options.testFlag(QChart::GridAxisAnimations)) {
979 axis->setAnimation(new AxisAnimation(axis));
1009 axis->setAnimation(new AxisAnimation(axis));
980 } else {
1010 } else {
981 axis->setAnimation(0);
1011 axis->setAnimation(0);
982 }
1012 }
983 }
1013 }
984
1014
985
1015
986
1016
987 #include "moc_qabstractaxis.cpp"
1017 #include "moc_qabstractaxis.cpp"
988 #include "moc_qabstractaxis_p.cpp"
1018 #include "moc_qabstractaxis_p.cpp"
989
1019
990 QTCOMMERCIALCHART_END_NAMESPACE
1020 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,899 +1,899
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qabstractbarseries.h"
21 #include "qabstractbarseries.h"
22 #include "qabstractbarseries_p.h"
22 #include "qabstractbarseries_p.h"
23 #include "qbarset.h"
23 #include "qbarset.h"
24 #include "qbarset_p.h"
24 #include "qbarset_p.h"
25 #include "abstractdomain_p.h"
25 #include "abstractdomain_p.h"
26 #include "chartdataset_p.h"
26 #include "chartdataset_p.h"
27 #include "charttheme_p.h"
27 #include "charttheme_p.h"
28 #include "qvalueaxis.h"
28 #include "qvalueaxis.h"
29 #include "qbarcategoryaxis.h"
29 #include "qbarcategoryaxis.h"
30 #include "qbarlegendmarker.h"
30 #include "qbarlegendmarker.h"
31 #include "baranimation_p.h"
31 #include "baranimation_p.h"
32 #include "abstractbarchartitem_p.h"
32 #include "abstractbarchartitem_p.h"
33 #include "qchart_p.h"
33 #include "qchart_p.h"
34
34
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36
36
37 /*!
37 /*!
38 \class QAbstractBarSeries
38 \class QAbstractBarSeries
39 \brief Series for creating a bar chart
39 \brief Series for creating a bar chart
40 \mainclass
40 \mainclass
41
41
42 QAbstractBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to
42 QAbstractBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to
43 the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar
43 the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar
44 and y-value is the height of the bar. The category names are ignored with this series and x-axis
44 and y-value is the height of the bar. The category names are ignored with this series and x-axis
45 shows the x-values.
45 shows the x-values.
46
46
47 See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart.
47 See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart.
48 \image examples_barchart.png
48 \image examples_barchart.png
49
49
50 \sa QBarSet, QStackedBarSeries, QPercentBarSeries
50 \sa QBarSet, QStackedBarSeries, QPercentBarSeries
51 */
51 */
52 /*!
52 /*!
53 \qmlclass AbstractBarSeries QAbstractBarSeries
53 \qmlclass AbstractBarSeries QAbstractBarSeries
54 \inherits QAbstractSeries
54 \inherits QAbstractSeries
55
55
56 The following QML shows how to create a simple bar chart:
56 The following QML shows how to create a simple bar chart:
57 \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1
57 \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1
58
58
59 \beginfloatleft
59 \beginfloatleft
60 \image demos_qmlchart6.png
60 \image demos_qmlchart6.png
61 \endfloat
61 \endfloat
62 \clearfloat
62 \clearfloat
63 */
63 */
64
64
65 /*!
65 /*!
66 \qmlproperty AbstractAxis AbstractBarSeries::axisX
66 \qmlproperty AbstractAxis AbstractBarSeries::axisX
67 The x axis used for the series. If you leave both axisX and axisXTop undefined, a BarCategoriesAxis is created for
67 The x axis used for the series. If you leave both axisX and axisXTop undefined, a BarCategoriesAxis is created for
68 the series.
68 the series.
69 \sa axisXTop
69 \sa axisXTop
70 */
70 */
71
71
72 /*!
72 /*!
73 \qmlproperty AbstractAxis AbstractBarSeries::axisY
73 \qmlproperty AbstractAxis AbstractBarSeries::axisY
74 The y axis used for the series. If you leave both axisY and axisYRight undefined, a ValueAxis is created for
74 The y axis used for the series. If you leave both axisY and axisYRight undefined, a ValueAxis is created for
75 the series.
75 the series.
76 \sa axisYRight
76 \sa axisYRight
77 */
77 */
78
78
79 /*!
79 /*!
80 \qmlproperty AbstractAxis AbstractBarSeries::axisXTop
80 \qmlproperty AbstractAxis AbstractBarSeries::axisXTop
81 The x axis used for the series, drawn on top of the chart view. Note that you can only provide either axisX or
81 The x axis used for the series, drawn on top of the chart view. Note that you can only provide either axisX or
82 axisXTop, but not both.
82 axisXTop, but not both.
83 \sa axisX
83 \sa axisX
84 */
84 */
85
85
86 /*!
86 /*!
87 \qmlproperty AbstractAxis AbstractBarSeries::axisYRight
87 \qmlproperty AbstractAxis AbstractBarSeries::axisYRight
88 The y axis used for the series, drawn to the right on the chart view. Note that you can only provide either axisY
88 The y axis used for the series, drawn to the right on the chart view. Note that you can only provide either axisY
89 or axisYRight, but not both.
89 or axisYRight, but not both.
90 \sa axisY
90 \sa axisY
91 */
91 */
92
92
93 /*!
93 /*!
94 \property QAbstractBarSeries::barWidth
94 \property QAbstractBarSeries::barWidth
95 The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars
95 The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars
96 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
96 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
97 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
97 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
98 Note that with QBarSeries this value means the width of one group of bars instead of just one bar.
98 Note that with QBarSeries this value means the width of one group of bars instead of just one bar.
99 \sa QBarSeries
99 \sa QBarSeries
100 */
100 */
101 /*!
101 /*!
102 \qmlproperty real AbstractBarSeries::barWidth
102 \qmlproperty real AbstractBarSeries::barWidth
103 The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars
103 The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars
104 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
104 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
105 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
105 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
106 Note that with QBarSeries this value means the width of one group of bars instead of just one bar.
106 Note that with QBarSeries this value means the width of one group of bars instead of just one bar.
107 */
107 */
108
108
109 /*!
109 /*!
110 \property QAbstractBarSeries::count
110 \property QAbstractBarSeries::count
111 Holds the number of sets in series.
111 Holds the number of sets in series.
112 */
112 */
113 /*!
113 /*!
114 \qmlproperty int AbstractBarSeries::count
114 \qmlproperty int AbstractBarSeries::count
115 Holds the number of sets in series.
115 Holds the number of sets in series.
116 */
116 */
117
117
118 /*!
118 /*!
119 \property QAbstractBarSeries::labelsVisible
119 \property QAbstractBarSeries::labelsVisible
120 Defines the visibility of the labels in series
120 Defines the visibility of the labels in series
121 */
121 */
122 /*!
122 /*!
123 \qmlproperty bool AbstractBarSeries::labelsVisible
123 \qmlproperty bool AbstractBarSeries::labelsVisible
124 Defines the visibility of the labels in series
124 Defines the visibility of the labels in series
125 */
125 */
126
126
127 /*!
127 /*!
128 \fn void QAbstractBarSeries::clicked(int index, QBarSet *barset)
128 \fn void QAbstractBarSeries::clicked(int index, QBarSet *barset)
129 The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset.
129 The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset.
130 Clicked bar inside set is indexed by \a index
130 Clicked bar inside set is indexed by \a index
131 */
131 */
132 /*!
132 /*!
133 \qmlsignal AbstractBarSeries::onClicked(int index, BarSet barset)
133 \qmlsignal AbstractBarSeries::onClicked(int index, BarSet barset)
134 The signal is emitted if the user clicks with a mouse on top of BarSet.
134 The signal is emitted if the user clicks with a mouse on top of BarSet.
135 Clicked bar inside set is indexed by \a index
135 Clicked bar inside set is indexed by \a index
136 */
136 */
137
137
138 /*!
138 /*!
139 \fn void QAbstractBarSeries::hovered(bool status, QBarSet* barset)
139 \fn void QAbstractBarSeries::hovered(bool status, QBarSet* barset)
140
140
141 The signal is emitted if mouse is hovered on top of series.
141 The signal is emitted if mouse is hovered on top of series.
142 Parameter \a barset is the pointer of barset, where hover happened.
142 Parameter \a barset is the pointer of barset, where hover happened.
143 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
143 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
144 */
144 */
145 /*!
145 /*!
146 \qmlsignal AbstractBarSeries::onHovered(bool status, BarSet barset)
146 \qmlsignal AbstractBarSeries::onHovered(bool status, BarSet barset)
147
147
148 The signal is emitted if mouse is hovered on top of series.
148 The signal is emitted if mouse is hovered on top of series.
149 Parameter \a barset is the pointer of barset, where hover happened.
149 Parameter \a barset is the pointer of barset, where hover happened.
150 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
150 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
151 */
151 */
152
152
153 /*!
153 /*!
154 \fn void QAbstractBarSeries::countChanged()
154 \fn void QAbstractBarSeries::countChanged()
155 This signal is emitted when barset count has been changed, for example by append or remove.
155 This signal is emitted when barset count has been changed, for example by append or remove.
156 */
156 */
157 /*!
157 /*!
158 \qmlsignal AbstractBarSeries::onCountChanged()
158 \qmlsignal AbstractBarSeries::onCountChanged()
159 This signal is emitted when barset count has been changed, for example by append or remove.
159 This signal is emitted when barset count has been changed, for example by append or remove.
160 */
160 */
161
161
162 /*!
162 /*!
163 \fn void QAbstractBarSeries::labelsVisibleChanged()
163 \fn void QAbstractBarSeries::labelsVisibleChanged()
164 This signal is emitted when labels visibility have changed.
164 This signal is emitted when labels visibility have changed.
165 \sa isLabelsVisible(), setLabelsVisible()
165 \sa isLabelsVisible(), setLabelsVisible()
166 */
166 */
167
167
168 /*!
168 /*!
169 \fn void QAbstractBarSeries::barsetsAdded(QList<QBarSet*> sets)
169 \fn void QAbstractBarSeries::barsetsAdded(QList<QBarSet*> sets)
170 This signal is emitted when \a sets have been added to the series.
170 This signal is emitted when \a sets have been added to the series.
171 \sa append(), insert()
171 \sa append(), insert()
172 */
172 */
173 /*!
173 /*!
174 \qmlsignal AbstractBarSeries::onBarsetsAdded(BarSet barset)
174 \qmlsignal AbstractBarSeries::onBarsetsAdded(BarSet barset)
175 Emitted when \a barset has been added to the series.
175 Emitted when \a barset has been added to the series.
176 */
176 */
177
177
178 /*!
178 /*!
179 \fn void QAbstractBarSeries::barsetsRemoved(QList<QBarSet*> sets)
179 \fn void QAbstractBarSeries::barsetsRemoved(QList<QBarSet*> sets)
180 This signal is emitted when \a sets have been removed from the series.
180 This signal is emitted when \a sets have been removed from the series.
181 \sa remove()
181 \sa remove()
182 */
182 */
183 /*!
183 /*!
184 \qmlsignal AbstractBarSeries::onBarsetsRemoved(BarSet barset)
184 \qmlsignal AbstractBarSeries::onBarsetsRemoved(BarSet barset)
185 Emitted when \a barset has been removed from the series.
185 Emitted when \a barset has been removed from the series.
186 */
186 */
187
187
188 /*!
188 /*!
189 \qmlmethod BarSet AbstractBarSeries::at(int index)
189 \qmlmethod BarSet AbstractBarSeries::at(int index)
190 Returns bar set at \a index. Returns null if the index is not valid.
190 Returns bar set at \a index. Returns null if the index is not valid.
191 */
191 */
192
192
193 /*!
193 /*!
194 \qmlmethod BarSet AbstractBarSeries::append(string label, VariantList values)
194 \qmlmethod BarSet AbstractBarSeries::append(string label, VariantList values)
195 Adds a new bar set with \a label and \a values to \a index. Values is a list of reals.
195 Adds a new bar set with \a label and \a values to \a index. Values is a list of reals.
196 For example:
196 For example:
197 \code
197 \code
198 myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]);
198 myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]);
199 \endcode
199 \endcode
200 */
200 */
201
201
202 /*!
202 /*!
203 \qmlmethod BarSet AbstractBarSeries::insert(int index, string label, VariantList values)
203 \qmlmethod BarSet AbstractBarSeries::insert(int index, string label, VariantList values)
204 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.
204 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.
205 If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is
205 If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is
206 appended.
206 appended.
207 \sa AbstractBarSeries::append()
207 \sa AbstractBarSeries::append()
208 */
208 */
209
209
210 /*!
210 /*!
211 \qmlmethod bool AbstractBarSeries::remove(BarSet barset)
211 \qmlmethod bool AbstractBarSeries::remove(BarSet barset)
212 Removes the barset from the series. Returns true if successful, false otherwise.
212 Removes the barset from the series. Returns true if successful, false otherwise.
213 */
213 */
214
214
215 /*!
215 /*!
216 \qmlmethod AbstractBarSeries::clear()
216 \qmlmethod AbstractBarSeries::clear()
217 Removes all barsets from the series.
217 Removes all barsets from the series.
218 */
218 */
219
219
220 /*!
220 /*!
221 Destructs abstractbarseries and owned barsets.
221 Destructs abstractbarseries and owned barsets.
222 */
222 */
223 QAbstractBarSeries::~QAbstractBarSeries()
223 QAbstractBarSeries::~QAbstractBarSeries()
224 {
224 {
225
225
226 }
226 }
227
227
228 /*!
228 /*!
229 \internal
229 \internal
230 */
230 */
231 QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &o, QObject *parent)
231 QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &o, QObject *parent)
232 : QAbstractSeries(o, parent)
232 : QAbstractSeries(o, parent)
233 {
233 {
234 Q_D(QAbstractSeries);
234 Q_D(QAbstractSeries);
235 QObject::connect(this, SIGNAL(countChanged()), d, SIGNAL(countChanged()));
235 QObject::connect(this, SIGNAL(countChanged()), d, SIGNAL(countChanged()));
236 }
236 }
237
237
238 /*!
238 /*!
239 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
239 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
240 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
240 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
241 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
241 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
242 Note that with \link QBarSeries \endlink this value means the width of one group of bars instead of just one bar.
242 Note that with \link QBarSeries \endlink this value means the width of one group of bars instead of just one bar.
243 */
243 */
244 void QAbstractBarSeries::setBarWidth(qreal width)
244 void QAbstractBarSeries::setBarWidth(qreal width)
245 {
245 {
246 Q_D(QAbstractBarSeries);
246 Q_D(QAbstractBarSeries);
247 d->setBarWidth(width);
247 d->setBarWidth(width);
248 }
248 }
249
249
250 /*!
250 /*!
251 Returns the width of the bars of the series.
251 Returns the width of the bars of the series.
252 \sa setBarWidth()
252 \sa setBarWidth()
253 */
253 */
254 qreal QAbstractBarSeries::barWidth() const
254 qreal QAbstractBarSeries::barWidth() const
255 {
255 {
256 Q_D(const QAbstractBarSeries);
256 Q_D(const QAbstractBarSeries);
257 return d->barWidth();
257 return d->barWidth();
258 }
258 }
259
259
260 /*!
260 /*!
261 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.
261 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.
262 Returns true, if appending succeeded.
262 Returns true, if appending succeeded.
263 */
263 */
264 bool QAbstractBarSeries::append(QBarSet *set)
264 bool QAbstractBarSeries::append(QBarSet *set)
265 {
265 {
266 Q_D(QAbstractBarSeries);
266 Q_D(QAbstractBarSeries);
267 bool success = d->append(set);
267 bool success = d->append(set);
268 if (success) {
268 if (success) {
269 QList<QBarSet *> sets;
269 QList<QBarSet *> sets;
270 sets.append(set);
270 sets.append(set);
271 set->setParent(this);
271 set->setParent(this);
272 emit barsetsAdded(sets);
272 emit barsetsAdded(sets);
273 emit countChanged();
273 emit countChanged();
274 }
274 }
275 return success;
275 return success;
276 }
276 }
277
277
278 /*!
278 /*!
279 Removes barset from series. Releases ownership of \a set. Deletes the set, if remove
279 Removes barset from series. Releases ownership of \a set. Deletes the set, if remove
280 was successful.
280 was successful.
281 Returns true, if set was removed.
281 Returns true, if set was removed.
282 */
282 */
283 bool QAbstractBarSeries::remove(QBarSet *set)
283 bool QAbstractBarSeries::remove(QBarSet *set)
284 {
284 {
285 Q_D(QAbstractBarSeries);
285 Q_D(QAbstractBarSeries);
286 bool success = d->remove(set);
286 bool success = d->remove(set);
287 if (success) {
287 if (success) {
288 QList<QBarSet *> sets;
288 QList<QBarSet *> sets;
289 sets.append(set);
289 sets.append(set);
290 set->setParent(0);
290 set->setParent(0);
291 emit barsetsRemoved(sets);
291 emit barsetsRemoved(sets);
292 emit countChanged();
292 emit countChanged();
293 delete set;
293 delete set;
294 set = 0;
294 set = 0;
295 }
295 }
296 return success;
296 return success;
297 }
297 }
298
298
299 /*!
299 /*!
300 Takes a single \a set from the series. Does not delete the barset object.
300 Takes a single \a set from the series. Does not delete the barset object.
301
301
302 NOTE: The series remains as the barset's parent object. You must set the
302 NOTE: The series remains as the barset's parent object. You must set the
303 parent object to take full ownership.
303 parent object to take full ownership.
304
304
305 Returns true if take was successful.
305 Returns true if take was successful.
306 */
306 */
307 bool QAbstractBarSeries::take(QBarSet *set)
307 bool QAbstractBarSeries::take(QBarSet *set)
308 {
308 {
309 Q_D(QAbstractBarSeries);
309 Q_D(QAbstractBarSeries);
310 bool success = d->remove(set);
310 bool success = d->remove(set);
311 if (success) {
311 if (success) {
312 QList<QBarSet *> sets;
312 QList<QBarSet *> sets;
313 sets.append(set);
313 sets.append(set);
314 emit barsetsRemoved(sets);
314 emit barsetsRemoved(sets);
315 emit countChanged();
315 emit countChanged();
316 }
316 }
317 return success;
317 return success;
318 }
318 }
319
319
320 /*!
320 /*!
321 Adds a list of barsets to series. Takes ownership of \a sets.
321 Adds a list of barsets to series. Takes ownership of \a sets.
322 Returns true, if all sets were appended successfully. If any of the sets is null or is already appended to series,
322 Returns true, if all sets were appended successfully. If any of the sets is null or is already appended to series,
323 nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended
323 nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended
324 and function returns false.
324 and function returns false.
325 */
325 */
326 bool QAbstractBarSeries::append(QList<QBarSet *> sets)
326 bool QAbstractBarSeries::append(QList<QBarSet *> sets)
327 {
327 {
328 Q_D(QAbstractBarSeries);
328 Q_D(QAbstractBarSeries);
329 bool success = d->append(sets);
329 bool success = d->append(sets);
330 if (success) {
330 if (success) {
331 emit barsetsAdded(sets);
331 emit barsetsAdded(sets);
332 emit countChanged();
332 emit countChanged();
333 }
333 }
334 return success;
334 return success;
335 }
335 }
336
336
337 /*!
337 /*!
338 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.
338 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.
339 Returns true, if inserting succeeded.
339 Returns true, if inserting succeeded.
340
340
341 */
341 */
342 bool QAbstractBarSeries::insert(int index, QBarSet *set)
342 bool QAbstractBarSeries::insert(int index, QBarSet *set)
343 {
343 {
344 Q_D(QAbstractBarSeries);
344 Q_D(QAbstractBarSeries);
345 bool success = d->insert(index, set);
345 bool success = d->insert(index, set);
346 if (success) {
346 if (success) {
347 QList<QBarSet *> sets;
347 QList<QBarSet *> sets;
348 sets.append(set);
348 sets.append(set);
349 emit barsetsAdded(sets);
349 emit barsetsAdded(sets);
350 emit countChanged();
350 emit countChanged();
351 }
351 }
352 return success;
352 return success;
353 }
353 }
354
354
355 /*!
355 /*!
356 Removes all barsets from the series. Deletes removed sets.
356 Removes all barsets from the series. Deletes removed sets.
357 */
357 */
358 void QAbstractBarSeries::clear()
358 void QAbstractBarSeries::clear()
359 {
359 {
360 Q_D(QAbstractBarSeries);
360 Q_D(QAbstractBarSeries);
361 QList<QBarSet *> sets = barSets();
361 QList<QBarSet *> sets = barSets();
362 bool success = d->remove(sets);
362 bool success = d->remove(sets);
363 if (success) {
363 if (success) {
364 emit barsetsRemoved(sets);
364 emit barsetsRemoved(sets);
365 emit countChanged();
365 emit countChanged();
366 foreach (QBarSet *set, sets)
366 foreach (QBarSet *set, sets)
367 delete set;
367 delete set;
368 }
368 }
369 }
369 }
370
370
371 /*!
371 /*!
372 Returns number of sets in series.
372 Returns number of sets in series.
373 */
373 */
374 int QAbstractBarSeries::count() const
374 int QAbstractBarSeries::count() const
375 {
375 {
376 Q_D(const QAbstractBarSeries);
376 Q_D(const QAbstractBarSeries);
377 return d->m_barSets.count();
377 return d->m_barSets.count();
378 }
378 }
379
379
380 /*!
380 /*!
381 Returns a list of sets in series. Keeps ownership of sets.
381 Returns a list of sets in series. Keeps ownership of sets.
382 */
382 */
383 QList<QBarSet *> QAbstractBarSeries::barSets() const
383 QList<QBarSet *> QAbstractBarSeries::barSets() const
384 {
384 {
385 Q_D(const QAbstractBarSeries);
385 Q_D(const QAbstractBarSeries);
386 return d->m_barSets;
386 return d->m_barSets;
387 }
387 }
388
388
389 /*!
389 /*!
390 Sets the visibility of labels in series to \a visible
390 Sets the visibility of labels in series to \a visible
391 */
391 */
392 void QAbstractBarSeries::setLabelsVisible(bool visible)
392 void QAbstractBarSeries::setLabelsVisible(bool visible)
393 {
393 {
394 Q_D(QAbstractBarSeries);
394 Q_D(QAbstractBarSeries);
395 if (d->m_labelsVisible != visible) {
395 if (d->m_labelsVisible != visible) {
396 d->setLabelsVisible(visible);
396 d->setLabelsVisible(visible);
397 emit labelsVisibleChanged();
397 emit labelsVisibleChanged();
398 }
398 }
399 }
399 }
400
400
401 /*!
401 /*!
402 Returns the visibility of labels
402 Returns the visibility of labels
403 */
403 */
404 bool QAbstractBarSeries::isLabelsVisible() const
404 bool QAbstractBarSeries::isLabelsVisible() const
405 {
405 {
406 Q_D(const QAbstractBarSeries);
406 Q_D(const QAbstractBarSeries);
407 return d->m_labelsVisible;
407 return d->m_labelsVisible;
408 }
408 }
409
409
410 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
410 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
411
411
412 QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) :
412 QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) :
413 QAbstractSeriesPrivate(q),
413 QAbstractSeriesPrivate(q),
414 m_barWidth(0.5), // Default value is 50% of category width
414 m_barWidth(0.5), // Default value is 50% of category width
415 m_labelsVisible(false),
415 m_labelsVisible(false),
416 m_visible(true)
416 m_visible(true)
417 {
417 {
418 }
418 }
419
419
420 int QAbstractBarSeriesPrivate::categoryCount() const
420 int QAbstractBarSeriesPrivate::categoryCount() const
421 {
421 {
422 // No categories defined. return count of longest set.
422 // No categories defined. return count of longest set.
423 int count = 0;
423 int count = 0;
424 for (int i = 0; i < m_barSets.count(); i++) {
424 for (int i = 0; i < m_barSets.count(); i++) {
425 if (m_barSets.at(i)->count() > count)
425 if (m_barSets.at(i)->count() > count)
426 count = m_barSets.at(i)->count();
426 count = m_barSets.at(i)->count();
427 }
427 }
428
428
429 return count;
429 return count;
430 }
430 }
431
431
432 void QAbstractBarSeriesPrivate::setBarWidth(qreal width)
432 void QAbstractBarSeriesPrivate::setBarWidth(qreal width)
433 {
433 {
434 if (width < 0.0)
434 if (width < 0.0)
435 width = 0.0;
435 width = 0.0;
436 m_barWidth = width;
436 m_barWidth = width;
437 emit updatedLayout();
437 emit updatedLayout();
438 }
438 }
439
439
440 qreal QAbstractBarSeriesPrivate::barWidth() const
440 qreal QAbstractBarSeriesPrivate::barWidth() const
441 {
441 {
442 return m_barWidth;
442 return m_barWidth;
443 }
443 }
444
444
445 QBarSet *QAbstractBarSeriesPrivate::barsetAt(int index)
445 QBarSet *QAbstractBarSeriesPrivate::barsetAt(int index)
446 {
446 {
447 return m_barSets.at(index);
447 return m_barSets.at(index);
448 }
448 }
449
449
450 void QAbstractBarSeriesPrivate::setVisible(bool visible)
450 void QAbstractBarSeriesPrivate::setVisible(bool visible)
451 {
451 {
452 m_visible = visible;
452 m_visible = visible;
453 emit visibleChanged();
453 emit visibleChanged();
454 }
454 }
455
455
456 void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible)
456 void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible)
457 {
457 {
458 m_labelsVisible = visible;
458 m_labelsVisible = visible;
459 emit labelsVisibleChanged(visible);
459 emit labelsVisibleChanged(visible);
460 }
460 }
461
461
462 qreal QAbstractBarSeriesPrivate::min()
462 qreal QAbstractBarSeriesPrivate::min()
463 {
463 {
464 if (m_barSets.count() <= 0)
464 if (m_barSets.count() <= 0)
465 return 0;
465 return 0;
466
466
467 qreal min = INT_MAX;
467 qreal min = INT_MAX;
468
468
469 for (int i = 0; i < m_barSets.count(); i++) {
469 for (int i = 0; i < m_barSets.count(); i++) {
470 int categoryCount = m_barSets.at(i)->count();
470 int categoryCount = m_barSets.at(i)->count();
471 for (int j = 0; j < categoryCount; j++) {
471 for (int j = 0; j < categoryCount; j++) {
472 qreal temp = m_barSets.at(i)->at(j);
472 qreal temp = m_barSets.at(i)->at(j);
473 if (temp < min)
473 if (temp < min)
474 min = temp;
474 min = temp;
475 }
475 }
476 }
476 }
477 return min;
477 return min;
478 }
478 }
479
479
480 qreal QAbstractBarSeriesPrivate::max()
480 qreal QAbstractBarSeriesPrivate::max()
481 {
481 {
482 if (m_barSets.count() <= 0)
482 if (m_barSets.count() <= 0)
483 return 0;
483 return 0;
484
484
485 qreal max = INT_MIN;
485 qreal max = INT_MIN;
486
486
487 for (int i = 0; i < m_barSets.count(); i++) {
487 for (int i = 0; i < m_barSets.count(); i++) {
488 int categoryCount = m_barSets.at(i)->count();
488 int categoryCount = m_barSets.at(i)->count();
489 for (int j = 0; j < categoryCount; j++) {
489 for (int j = 0; j < categoryCount; j++) {
490 qreal temp = m_barSets.at(i)->at(j);
490 qreal temp = m_barSets.at(i)->at(j);
491 if (temp > max)
491 if (temp > max)
492 max = temp;
492 max = temp;
493 }
493 }
494 }
494 }
495
495
496 return max;
496 return max;
497 }
497 }
498
498
499 qreal QAbstractBarSeriesPrivate::valueAt(int set, int category)
499 qreal QAbstractBarSeriesPrivate::valueAt(int set, int category)
500 {
500 {
501 if ((set < 0) || (set >= m_barSets.count()))
501 if ((set < 0) || (set >= m_barSets.count()))
502 return 0; // No set, no value.
502 return 0; // No set, no value.
503 else if ((category < 0) || (category >= m_barSets.at(set)->count()))
503 else if ((category < 0) || (category >= m_barSets.at(set)->count()))
504 return 0; // No category, no value.
504 return 0; // No category, no value.
505
505
506 return m_barSets.at(set)->at(category);
506 return m_barSets.at(set)->at(category);
507 }
507 }
508
508
509 qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category)
509 qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category)
510 {
510 {
511 if ((set < 0) || (set >= m_barSets.count()))
511 if ((set < 0) || (set >= m_barSets.count()))
512 return 0; // No set, no value.
512 return 0; // No set, no value.
513 else if ((category < 0) || (category >= m_barSets.at(set)->count()))
513 else if ((category < 0) || (category >= m_barSets.at(set)->count()))
514 return 0; // No category, no value.
514 return 0; // No category, no value.
515
515
516 qreal value = m_barSets.at(set)->at(category);
516 qreal value = m_barSets.at(set)->at(category);
517 qreal sum = categorySum(category);
517 qreal sum = categorySum(category);
518 if (qFuzzyCompare(sum, 0))
518 if (qFuzzyCompare(sum, 0))
519 return 0;
519 return 0;
520
520
521 return value / sum;
521 return value / sum;
522 }
522 }
523
523
524 qreal QAbstractBarSeriesPrivate::categorySum(int category)
524 qreal QAbstractBarSeriesPrivate::categorySum(int category)
525 {
525 {
526 qreal sum(0);
526 qreal sum(0);
527 int count = m_barSets.count(); // Count sets
527 int count = m_barSets.count(); // Count sets
528 for (int set = 0; set < count; set++) {
528 for (int set = 0; set < count; set++) {
529 if (category < m_barSets.at(set)->count())
529 if (category < m_barSets.at(set)->count())
530 sum += m_barSets.at(set)->at(category);
530 sum += m_barSets.at(set)->at(category);
531 }
531 }
532 return sum;
532 return sum;
533 }
533 }
534
534
535 qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category)
535 qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category)
536 {
536 {
537 qreal sum(0);
537 qreal sum(0);
538 int count = m_barSets.count(); // Count sets
538 int count = m_barSets.count(); // Count sets
539 for (int set = 0; set < count; set++) {
539 for (int set = 0; set < count; set++) {
540 if (category < m_barSets.at(set)->count())
540 if (category < m_barSets.at(set)->count())
541 sum += qAbs(m_barSets.at(set)->at(category));
541 sum += qAbs(m_barSets.at(set)->at(category));
542 }
542 }
543 return sum;
543 return sum;
544 }
544 }
545
545
546 qreal QAbstractBarSeriesPrivate::maxCategorySum()
546 qreal QAbstractBarSeriesPrivate::maxCategorySum()
547 {
547 {
548 qreal max = INT_MIN;
548 qreal max = INT_MIN;
549 int count = categoryCount();
549 int count = categoryCount();
550 for (int i = 0; i < count; i++) {
550 for (int i = 0; i < count; i++) {
551 qreal sum = categorySum(i);
551 qreal sum = categorySum(i);
552 if (sum > max)
552 if (sum > max)
553 max = sum;
553 max = sum;
554 }
554 }
555 return max;
555 return max;
556 }
556 }
557
557
558 qreal QAbstractBarSeriesPrivate::minX()
558 qreal QAbstractBarSeriesPrivate::minX()
559 {
559 {
560 if (m_barSets.count() <= 0)
560 if (m_barSets.count() <= 0)
561 return 0;
561 return 0;
562
562
563 qreal min = INT_MAX;
563 qreal min = INT_MAX;
564
564
565 for (int i = 0; i < m_barSets.count(); i++) {
565 for (int i = 0; i < m_barSets.count(); i++) {
566 int categoryCount = m_barSets.at(i)->count();
566 int categoryCount = m_barSets.at(i)->count();
567 for (int j = 0; j < categoryCount; j++) {
567 for (int j = 0; j < categoryCount; j++) {
568 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
568 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
569 if (temp < min)
569 if (temp < min)
570 min = temp;
570 min = temp;
571 }
571 }
572 }
572 }
573 return min;
573 return min;
574 }
574 }
575
575
576 qreal QAbstractBarSeriesPrivate::maxX()
576 qreal QAbstractBarSeriesPrivate::maxX()
577 {
577 {
578 if (m_barSets.count() <= 0)
578 if (m_barSets.count() <= 0)
579 return 0;
579 return 0;
580
580
581 qreal max = INT_MIN;
581 qreal max = INT_MIN;
582
582
583 for (int i = 0; i < m_barSets.count(); i++) {
583 for (int i = 0; i < m_barSets.count(); i++) {
584 int categoryCount = m_barSets.at(i)->count();
584 int categoryCount = m_barSets.at(i)->count();
585 for (int j = 0; j < categoryCount; j++) {
585 for (int j = 0; j < categoryCount; j++) {
586 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
586 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
587 if (temp > max)
587 if (temp > max)
588 max = temp;
588 max = temp;
589 }
589 }
590 }
590 }
591
591
592 return max;
592 return max;
593 }
593 }
594
594
595 qreal QAbstractBarSeriesPrivate::categoryTop(int category)
595 qreal QAbstractBarSeriesPrivate::categoryTop(int category)
596 {
596 {
597 // Returns top (sum of all positive values) of category.
597 // Returns top (sum of all positive values) of category.
598 // Returns 0, if all values are negative
598 // Returns 0, if all values are negative
599 qreal top(0);
599 qreal top(0);
600 int count = m_barSets.count();
600 int count = m_barSets.count();
601 for (int set = 0; set < count; set++) {
601 for (int set = 0; set < count; set++) {
602 if (category < m_barSets.at(set)->count()) {
602 if (category < m_barSets.at(set)->count()) {
603 qreal temp = m_barSets.at(set)->at(category);
603 qreal temp = m_barSets.at(set)->at(category);
604 if (temp > 0) {
604 if (temp > 0) {
605 top += temp;
605 top += temp;
606 }
606 }
607 }
607 }
608 }
608 }
609 return top;
609 return top;
610 }
610 }
611
611
612 qreal QAbstractBarSeriesPrivate::categoryBottom(int category)
612 qreal QAbstractBarSeriesPrivate::categoryBottom(int category)
613 {
613 {
614 // Returns bottom (sum of all negative values) of category
614 // Returns bottom (sum of all negative values) of category
615 // Returns 0, if all values are positive
615 // Returns 0, if all values are positive
616 qreal bottom(0);
616 qreal bottom(0);
617 int count = m_barSets.count();
617 int count = m_barSets.count();
618 for (int set = 0; set < count; set++) {
618 for (int set = 0; set < count; set++) {
619 if (category < m_barSets.at(set)->count()) {
619 if (category < m_barSets.at(set)->count()) {
620 qreal temp = m_barSets.at(set)->at(category);
620 qreal temp = m_barSets.at(set)->at(category);
621 if (temp < 0) {
621 if (temp < 0) {
622 bottom += temp;
622 bottom += temp;
623 }
623 }
624 }
624 }
625 }
625 }
626 return bottom;
626 return bottom;
627 }
627 }
628
628
629 qreal QAbstractBarSeriesPrivate::top()
629 qreal QAbstractBarSeriesPrivate::top()
630 {
630 {
631 // Returns top of all categories
631 // Returns top of all categories
632 qreal top(0);
632 qreal top(0);
633 int count = categoryCount();
633 int count = categoryCount();
634 for (int i = 0; i < count; i++) {
634 for (int i = 0; i < count; i++) {
635 qreal temp = categoryTop(i);
635 qreal temp = categoryTop(i);
636 if (temp > top)
636 if (temp > top)
637 top = temp;
637 top = temp;
638 }
638 }
639 return top;
639 return top;
640 }
640 }
641
641
642 qreal QAbstractBarSeriesPrivate::bottom()
642 qreal QAbstractBarSeriesPrivate::bottom()
643 {
643 {
644 // Returns bottom of all categories
644 // Returns bottom of all categories
645 qreal bottom(0);
645 qreal bottom(0);
646 int count = categoryCount();
646 int count = categoryCount();
647 for (int i = 0; i < count; i++) {
647 for (int i = 0; i < count; i++) {
648 qreal temp = categoryBottom(i);
648 qreal temp = categoryBottom(i);
649 if (temp < bottom)
649 if (temp < bottom)
650 bottom = temp;
650 bottom = temp;
651 }
651 }
652 return bottom;
652 return bottom;
653 }
653 }
654
654
655
655
656 void QAbstractBarSeriesPrivate::initializeDomain()
656 void QAbstractBarSeriesPrivate::initializeDomain()
657 {
657 {
658 qreal minX(domain()->minX());
658 qreal minX(domain()->minX());
659 qreal minY(domain()->minY());
659 qreal minY(domain()->minY());
660 qreal maxX(domain()->maxX());
660 qreal maxX(domain()->maxX());
661 qreal maxY(domain()->maxY());
661 qreal maxY(domain()->maxY());
662
662
663 qreal seriesMinX = this->minX();
663 qreal seriesMinX = this->minX();
664 qreal seriesMaxX = this->maxX();
664 qreal seriesMaxX = this->maxX();
665 qreal y = max();
665 qreal y = max();
666 minX = qMin(minX, seriesMinX - (qreal)0.5);
666 minX = qMin(minX, seriesMinX - (qreal)0.5);
667 minY = qMin(minY, y);
667 minY = qMin(minY, y);
668 maxX = qMax(maxX, seriesMaxX + (qreal)0.5);
668 maxX = qMax(maxX, seriesMaxX + (qreal)0.5);
669 maxY = qMax(maxY, y);
669 maxY = qMax(maxY, y);
670
670
671 domain()->setRange(minX, maxX, minY, maxY);
671 domain()->setRange(minX, maxX, minY, maxY);
672 }
672 }
673
673
674 QList<QLegendMarker*> QAbstractBarSeriesPrivate::createLegendMarkers(QLegend* legend)
674 QList<QLegendMarker*> QAbstractBarSeriesPrivate::createLegendMarkers(QLegend* legend)
675 {
675 {
676 Q_Q(QAbstractBarSeries);
676 Q_Q(QAbstractBarSeries);
677 QList<QLegendMarker*> markers;
677 QList<QLegendMarker*> markers;
678
678
679 foreach(QBarSet* set, q->barSets()) {
679 foreach(QBarSet* set, q->barSets()) {
680 QBarLegendMarker* marker = new QBarLegendMarker(q,set,legend);
680 QBarLegendMarker* marker = new QBarLegendMarker(q,set,legend);
681 markers << marker;
681 markers << marker;
682 }
682 }
683 return markers;
683 return markers;
684 }
684 }
685
685
686
686
687 bool QAbstractBarSeriesPrivate::append(QBarSet *set)
687 bool QAbstractBarSeriesPrivate::append(QBarSet *set)
688 {
688 {
689 if ((m_barSets.contains(set)) || (set == 0))
689 if ((m_barSets.contains(set)) || (set == 0))
690 return false; // Fail if set is already in list or set is null.
690 return false; // Fail if set is already in list or set is null.
691
691
692 m_barSets.append(set);
692 m_barSets.append(set);
693 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
693 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
694 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
694 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
695 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
695 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
696
696
697 emit restructuredBars(); // this notifies barchartitem
697 emit restructuredBars(); // this notifies barchartitem
698 return true;
698 return true;
699 }
699 }
700
700
701 bool QAbstractBarSeriesPrivate::remove(QBarSet *set)
701 bool QAbstractBarSeriesPrivate::remove(QBarSet *set)
702 {
702 {
703 if (!m_barSets.contains(set))
703 if (!m_barSets.contains(set))
704 return false; // Fail if set is not in list
704 return false; // Fail if set is not in list
705
705
706 m_barSets.removeOne(set);
706 m_barSets.removeOne(set);
707 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
707 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
708 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
708 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
709 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
709 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
710
710
711 emit restructuredBars(); // this notifies barchartitem
711 emit restructuredBars(); // this notifies barchartitem
712 return true;
712 return true;
713 }
713 }
714
714
715 bool QAbstractBarSeriesPrivate::append(QList<QBarSet * > sets)
715 bool QAbstractBarSeriesPrivate::append(QList<QBarSet * > sets)
716 {
716 {
717 foreach (QBarSet *set, sets) {
717 foreach (QBarSet *set, sets) {
718 if ((set == 0) || (m_barSets.contains(set)))
718 if ((set == 0) || (m_barSets.contains(set)))
719 return false; // Fail if any of the sets is null or is already appended.
719 return false; // Fail if any of the sets is null or is already appended.
720 if (sets.count(set) != 1)
720 if (sets.count(set) != 1)
721 return false; // Also fail if same set is more than once in given list.
721 return false; // Also fail if same set is more than once in given list.
722 }
722 }
723
723
724 foreach (QBarSet *set, sets) {
724 foreach (QBarSet *set, sets) {
725 m_barSets.append(set);
725 m_barSets.append(set);
726 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
726 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
727 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
727 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
728 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
728 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
729 }
729 }
730
730
731 emit restructuredBars(); // this notifies barchartitem
731 emit restructuredBars(); // this notifies barchartitem
732 return true;
732 return true;
733 }
733 }
734
734
735 bool QAbstractBarSeriesPrivate::remove(QList<QBarSet * > sets)
735 bool QAbstractBarSeriesPrivate::remove(QList<QBarSet * > sets)
736 {
736 {
737 if (sets.count() == 0)
737 if (sets.count() == 0)
738 return false;
738 return false;
739
739
740 foreach (QBarSet *set, sets) {
740 foreach (QBarSet *set, sets) {
741 if ((set == 0) || (!m_barSets.contains(set)))
741 if ((set == 0) || (!m_barSets.contains(set)))
742 return false; // Fail if any of the sets is null or is not in series
742 return false; // Fail if any of the sets is null or is not in series
743 if (sets.count(set) != 1)
743 if (sets.count(set) != 1)
744 return false; // Also fail if same set is more than once in given list.
744 return false; // Also fail if same set is more than once in given list.
745 }
745 }
746
746
747 foreach (QBarSet *set, sets) {
747 foreach (QBarSet *set, sets) {
748 m_barSets.removeOne(set);
748 m_barSets.removeOne(set);
749 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
749 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
750 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
750 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
751 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
751 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
752 }
752 }
753
753
754 emit restructuredBars(); // this notifies barchartitem
754 emit restructuredBars(); // this notifies barchartitem
755
755
756 return true;
756 return true;
757 }
757 }
758
758
759 bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set)
759 bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set)
760 {
760 {
761 if ((m_barSets.contains(set)) || (set == 0))
761 if ((m_barSets.contains(set)) || (set == 0))
762 return false; // Fail if set is already in list or set is null.
762 return false; // Fail if set is already in list or set is null.
763
763
764 m_barSets.insert(index, set);
764 m_barSets.insert(index, set);
765 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
765 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
766 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
766 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
767 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
767 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
768
768
769 emit restructuredBars(); // this notifies barchartitem
769 emit restructuredBars(); // this notifies barchartitem
770 return true;
770 return true;
771 }
771 }
772
772
773 void QAbstractBarSeriesPrivate::initializeAxes()
773 void QAbstractBarSeriesPrivate::initializeAxes()
774 {
774 {
775 Q_Q(QAbstractBarSeries);
775 Q_Q(QAbstractBarSeries);
776
776
777 foreach(QAbstractAxis* axis, m_axes) {
777 foreach(QAbstractAxis* axis, m_axes) {
778
778
779 if (axis->type() == QAbstractAxis::AxisTypeBarCategory) {
779 if (axis->type() == QAbstractAxis::AxisTypeBarCategory) {
780 switch (q->type()) {
780 switch (q->type()) {
781 case QAbstractSeries::SeriesTypeHorizontalBar:
781 case QAbstractSeries::SeriesTypeHorizontalBar:
782 case QAbstractSeries::SeriesTypeHorizontalPercentBar:
782 case QAbstractSeries::SeriesTypeHorizontalPercentBar:
783 case QAbstractSeries::SeriesTypeHorizontalStackedBar:
783 case QAbstractSeries::SeriesTypeHorizontalStackedBar:
784 if (axis->orientation() == Qt::Vertical)
784 if (axis->orientation() == Qt::Vertical)
785 populateCategories(qobject_cast<QBarCategoryAxis *>(axis));
785 populateCategories(qobject_cast<QBarCategoryAxis *>(axis));
786 break;
786 break;
787 case QAbstractSeries::SeriesTypeBar:
787 case QAbstractSeries::SeriesTypeBar:
788 case QAbstractSeries::SeriesTypePercentBar:
788 case QAbstractSeries::SeriesTypePercentBar:
789 case QAbstractSeries::SeriesTypeStackedBar:
789 case QAbstractSeries::SeriesTypeStackedBar:
790 if (axis->orientation() == Qt::Horizontal)
790 if (axis->orientation() == Qt::Horizontal)
791 populateCategories(qobject_cast<QBarCategoryAxis *>(axis));
791 populateCategories(qobject_cast<QBarCategoryAxis *>(axis));
792 break;
792 break;
793 default:
793 default:
794 qWarning() << "Unexpected series type";
794 qWarning() << "Unexpected series type";
795 break;
795 break;
796 }
796 }
797 }
797 }
798 }
798 }
799 }
799 }
800
800
801 QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
801 QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
802 {
802 {
803 Q_Q(const QAbstractBarSeries);
803 Q_Q(const QAbstractBarSeries);
804
804
805 switch (q->type()) {
805 switch (q->type()) {
806 case QAbstractSeries::SeriesTypeHorizontalBar:
806 case QAbstractSeries::SeriesTypeHorizontalBar:
807 case QAbstractSeries::SeriesTypeHorizontalPercentBar:
807 case QAbstractSeries::SeriesTypeHorizontalPercentBar:
808 case QAbstractSeries::SeriesTypeHorizontalStackedBar:
808 case QAbstractSeries::SeriesTypeHorizontalStackedBar:
809 if (orientation == Qt::Vertical)
809 if (orientation == Qt::Vertical)
810 return QAbstractAxis::AxisTypeBarCategory;
810 return QAbstractAxis::AxisTypeBarCategory;
811 break;
811 break;
812 case QAbstractSeries::SeriesTypeBar:
812 case QAbstractSeries::SeriesTypeBar:
813 case QAbstractSeries::SeriesTypePercentBar:
813 case QAbstractSeries::SeriesTypePercentBar:
814 case QAbstractSeries::SeriesTypeStackedBar:
814 case QAbstractSeries::SeriesTypeStackedBar:
815 if (orientation == Qt::Horizontal)
815 if (orientation == Qt::Horizontal)
816 return QAbstractAxis::AxisTypeBarCategory;
816 return QAbstractAxis::AxisTypeBarCategory;
817 break;
817 break;
818 default:
818 default:
819 qWarning() << "Unexpected series type";
819 qWarning() << "Unexpected series type";
820 break;
820 break;
821 }
821 }
822 return QAbstractAxis::AxisTypeValue;
822 return QAbstractAxis::AxisTypeValue;
823
823
824 }
824 }
825
825
826 void QAbstractBarSeriesPrivate::populateCategories(QBarCategoryAxis *axis)
826 void QAbstractBarSeriesPrivate::populateCategories(QBarCategoryAxis *axis)
827 {
827 {
828 QStringList categories;
828 QStringList categories;
829 if (axis->categories().isEmpty()) {
829 if (axis->categories().isEmpty()) {
830 for (int i(1); i < categoryCount() + 1; i++)
830 for (int i(1); i < categoryCount() + 1; i++)
831 categories << QString::number(i);
831 categories << QString::number(i);
832 axis->append(categories);
832 axis->append(categories);
833 }
833 }
834 }
834 }
835
835
836 QAbstractAxis* QAbstractBarSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const
836 QAbstractAxis* QAbstractBarSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const
837 {
837 {
838 Q_UNUSED(orientation);
838 Q_UNUSED(orientation);
839 return 0;
839 return 0;
840 }
840 }
841
841
842 void QAbstractBarSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced)
842 void QAbstractBarSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced)
843 {
843 {
844 const QList<QGradient> gradients = theme->seriesGradients();
844 const QList<QGradient> gradients = theme->seriesGradients();
845
845
846 qreal takeAtPos = 0.5;
846 qreal takeAtPos = 0.5;
847 qreal step = 0.2;
847 qreal step = 0.2;
848 if (m_barSets.count() > 1) {
848 if (m_barSets.count() > 1) {
849 step = 1.0 / (qreal) m_barSets.count();
849 step = 1.0 / (qreal) m_barSets.count();
850 if (m_barSets.count() % gradients.count())
850 if (m_barSets.count() % gradients.count())
851 step *= gradients.count();
851 step *= gradients.count();
852 else
852 else
853 step *= (gradients.count() - 1);
853 step *= (gradients.count() - 1);
854 }
854 }
855
855
856 for (int i(0); i < m_barSets.count(); i++) {
856 for (int i(0); i < m_barSets.count(); i++) {
857 int colorIndex = (index + i) % gradients.count();
857 int colorIndex = (index + i) % gradients.count();
858 if (i > 0 && i %gradients.count() == 0) {
858 if (i > 0 && i %gradients.count() == 0) {
859 // There is no dedicated base color for each sets, generate more colors
859 // There is no dedicated base color for each sets, generate more colors
860 takeAtPos += step;
860 takeAtPos += step;
861 if (takeAtPos == 1.0)
861 if (takeAtPos == 1.0)
862 takeAtPos += step;
862 takeAtPos += step;
863 takeAtPos -= (int) takeAtPos;
863 takeAtPos -= (int) takeAtPos;
864 }
864 }
865 if (forced || QChartPrivate::defaultBrush() == m_barSets.at(i)->brush())
865 if (forced || QChartPrivate::defaultBrush() == m_barSets.at(i)->d_ptr->m_brush)
866 m_barSets.at(i)->setBrush(ChartThemeManager::colorAt(gradients.at(colorIndex), takeAtPos));
866 m_barSets.at(i)->setBrush(ChartThemeManager::colorAt(gradients.at(colorIndex), takeAtPos));
867
867
868 // Pick label color from the opposite end of the gradient.
868 // Pick label color from the opposite end of the gradient.
869 // 0.3 as a boundary seems to work well.
869 // 0.3 as a boundary seems to work well.
870 if (forced || QChartPrivate::defaultBrush() == m_barSets.at(i)->labelBrush()) {
870 if (forced || QChartPrivate::defaultBrush() == m_barSets.at(i)->d_ptr->m_labelBrush) {
871 if (takeAtPos < 0.3)
871 if (takeAtPos < 0.3)
872 m_barSets.at(i)->setLabelBrush(ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 1));
872 m_barSets.at(i)->setLabelBrush(ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 1));
873 else
873 else
874 m_barSets.at(i)->setLabelBrush(ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0));
874 m_barSets.at(i)->setLabelBrush(ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0));
875 }
875 }
876
876
877 if (forced || QChartPrivate::defaultPen() == m_barSets.at(i)->pen()) {
877 if (forced || QChartPrivate::defaultPen() == m_barSets.at(i)->d_ptr->m_pen) {
878 QColor c = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.0);
878 QColor c = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.0);
879 m_barSets.at(i)->setPen(c);
879 m_barSets.at(i)->setPen(c);
880 }
880 }
881 }
881 }
882 }
882 }
883
883
884 void QAbstractBarSeriesPrivate::initializeAnimations(QChart::AnimationOptions options)
884 void QAbstractBarSeriesPrivate::initializeAnimations(QChart::AnimationOptions options)
885 {
885 {
886 AbstractBarChartItem *bar = static_cast<AbstractBarChartItem *>(m_item.data());
886 AbstractBarChartItem *bar = static_cast<AbstractBarChartItem *>(m_item.data());
887 Q_ASSERT(bar);
887 Q_ASSERT(bar);
888 if (options.testFlag(QChart::SeriesAnimations)) {
888 if (options.testFlag(QChart::SeriesAnimations)) {
889 bar->setAnimation(new BarAnimation(bar));
889 bar->setAnimation(new BarAnimation(bar));
890 }else{
890 }else{
891 bar->setAnimation(0);
891 bar->setAnimation(0);
892 }
892 }
893 QAbstractSeriesPrivate::initializeAnimations(options);
893 QAbstractSeriesPrivate::initializeAnimations(options);
894 }
894 }
895
895
896 #include "moc_qabstractbarseries.cpp"
896 #include "moc_qabstractbarseries.cpp"
897 #include "moc_qabstractbarseries_p.cpp"
897 #include "moc_qabstractbarseries_p.cpp"
898
898
899 QTCOMMERCIALCHART_END_NAMESPACE
899 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,83 +1,84
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 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 #ifndef QABSTRACTBARSERIES_H
21 #ifndef QABSTRACTBARSERIES_H
22 #define QABSTRACTBARSERIES_H
22 #define QABSTRACTBARSERIES_H
23
23
24 #include <qabstractseries.h>
24 #include <qabstractseries.h>
25 #include <QStringList>
25 #include <QStringList>
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
28
29 class QBarSet;
29 class QBarSet;
30 class QAbstractBarSeriesPrivate;
30 class QAbstractBarSeriesPrivate;
31
31
32 // Container for series
32 // Container for series
33 class QTCOMMERCIALCHART_EXPORT QAbstractBarSeries : public QAbstractSeries
33 class QTCOMMERCIALCHART_EXPORT QAbstractBarSeries : public QAbstractSeries
34 {
34 {
35 Q_OBJECT
35 Q_OBJECT
36 Q_PROPERTY(qreal barWidth READ barWidth WRITE setBarWidth)
36 Q_PROPERTY(qreal barWidth READ barWidth WRITE setBarWidth)
37 Q_PROPERTY(int count READ count NOTIFY countChanged)
37 Q_PROPERTY(int count READ count NOTIFY countChanged)
38 Q_PROPERTY(bool labelsVisible READ isLabelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged)
38 Q_PROPERTY(bool labelsVisible READ isLabelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged)
39
39
40 public:
40 public:
41 virtual ~QAbstractBarSeries();
41 virtual ~QAbstractBarSeries();
42
42
43 void setBarWidth(qreal width);
43 void setBarWidth(qreal width);
44 qreal barWidth() const;
44 qreal barWidth() const;
45
45
46 bool append(QBarSet *set);
46 bool append(QBarSet *set);
47 bool remove(QBarSet *set);
47 bool remove(QBarSet *set);
48 bool take(QBarSet *set);
48 bool take(QBarSet *set);
49 bool append(QList<QBarSet *> sets);
49 bool append(QList<QBarSet *> sets);
50 bool insert(int index, QBarSet *set);
50 bool insert(int index, QBarSet *set);
51 int count() const;
51 int count() const;
52 QList<QBarSet *> barSets() const;
52 QList<QBarSet *> barSets() const;
53 void clear();
53 void clear();
54
54
55 void setLabelsVisible(bool visible = true);
55 void setLabelsVisible(bool visible = true);
56 bool isLabelsVisible() const;
56 bool isLabelsVisible() const;
57
57
58 protected:
58 protected:
59 explicit QAbstractBarSeries(QAbstractBarSeriesPrivate &d, QObject *parent = 0);
59 explicit QAbstractBarSeries(QAbstractBarSeriesPrivate &d, QObject *parent = 0);
60
60
61 Q_SIGNALS:
61 Q_SIGNALS:
62 void clicked(int index, QBarSet *barset);
62 void clicked(int index, QBarSet *barset);
63 void hovered(bool status, QBarSet *barset);
63 void hovered(bool status, QBarSet *barset);
64 void countChanged();
64 void countChanged();
65 void labelsVisibleChanged();
65 void labelsVisibleChanged();
66
66
67 void barsetsAdded(QList<QBarSet *> sets);
67 void barsetsAdded(QList<QBarSet *> sets);
68 void barsetsRemoved(QList<QBarSet *> sets);
68 void barsetsRemoved(QList<QBarSet *> sets);
69
69
70 protected:
70 protected:
71 Q_DECLARE_PRIVATE(QAbstractBarSeries)
71 Q_DECLARE_PRIVATE(QAbstractBarSeries)
72 friend class AbstractBarChartItem;
72 friend class AbstractBarChartItem;
73 friend class PercentBarChartItem;
73 friend class PercentBarChartItem;
74 friend class StackedBarChartItem;
74 friend class StackedBarChartItem;
75 friend class BarChartItem;
75 friend class BarChartItem;
76 friend class HorizontalBarChartItem;
76 friend class HorizontalBarChartItem;
77 friend class HorizontalStackedBarChartItem;
77 friend class HorizontalStackedBarChartItem;
78 friend class HorizontalPercentBarChartItem;
78 friend class HorizontalPercentBarChartItem;
79 friend class BarSet;
79 };
80 };
80
81
81 QTCOMMERCIALCHART_END_NAMESPACE
82 QTCOMMERCIALCHART_END_NAMESPACE
82
83
83 #endif // QABSTRACTBARSERIES_H
84 #endif // QABSTRACTBARSERIES_H
@@ -1,649 +1,658
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qbarset.h"
21 #include "qbarset.h"
22 #include "qbarset_p.h"
22 #include "qbarset_p.h"
23 #include "charthelpers_p.h"
23 #include "charthelpers_p.h"
24 #include "qchart_p.h"
24 #include "qchart_p.h"
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 /*!
28 /*!
29 \class QBarSet
29 \class QBarSet
30 \brief Building block for different bar charts
30 \brief Building block for different bar charts
31
31
32 QBarSet represents one set of bars. Set of bars contains one data value for each category.
32 QBarSet represents one set of bars. Set of bars contains one data value for each category.
33 First value of set is assumed to belong to first category, second to second category and so on.
33 First value of set is assumed to belong to first category, second to second category and so on.
34 If set has fewer values than there are categories, then the missing values are assumed to be
34 If set has fewer values than there are categories, then the missing values are assumed to be
35 at the end of set. For missing values in middle of a set, numerical value of zero is used.
35 at the end of set. For missing values in middle of a set, numerical value of zero is used.
36
36
37 \mainclass
37 \mainclass
38
38
39 \sa QAbstractBarSeries, QBarSeries, QStackedBarSeries, QPercentBarSeries
39 \sa QAbstractBarSeries, QBarSeries, QStackedBarSeries, QPercentBarSeries
40 */
40 */
41 /*!
41 /*!
42 \qmlclass BarSet QBarSet
42 \qmlclass BarSet QBarSet
43
43
44 BarSet represents one set of bars. Set of bars contains one data value for each category.
44 BarSet represents one set of bars. Set of bars contains one data value for each category.
45 First value of set is assumed to belong to first category, second to second category and so on.
45 First value of set is assumed to belong to first category, second to second category and so on.
46 If set has fewer values than there are categories, then the missing values are assumed to be
46 If set has fewer values than there are categories, then the missing values are assumed to be
47 at the end of set. For missing values in middle of a set, numerical value of zero is used.
47 at the end of set. For missing values in middle of a set, numerical value of zero is used.
48 \sa AbstractBarSeries, BarSeries, StackedBarSeries, PercentBarSeries
48 \sa AbstractBarSeries, BarSeries, StackedBarSeries, PercentBarSeries
49 */
49 */
50
50
51 /*!
51 /*!
52 \property QBarSet::label
52 \property QBarSet::label
53 Defines the label of the barSet.
53 Defines the label of the barSet.
54 */
54 */
55 /*!
55 /*!
56 \qmlproperty string BarSet::label
56 \qmlproperty string BarSet::label
57 Defines the label of the barSet.
57 Defines the label of the barSet.
58 */
58 */
59
59
60 /*!
60 /*!
61 \property QBarSet::pen
61 \property QBarSet::pen
62 \brief Defines the pen used by the barSet.
62 \brief Defines the pen used by the barSet.
63 */
63 */
64
64
65 /*!
65 /*!
66 \property QBarSet::brush
66 \property QBarSet::brush
67 \brief Defines the brush used by the barSet.
67 \brief Defines the brush used by the barSet.
68 */
68 */
69
69
70 /*!
70 /*!
71 \property QBarSet::labelBrush
71 \property QBarSet::labelBrush
72 \brief Defines the brush used by the barSet's label.
72 \brief Defines the brush used by the barSet's label.
73 */
73 */
74
74
75 /*!
75 /*!
76 \property QBarSet::labelFont
76 \property QBarSet::labelFont
77 \brief Defines the font used by the barSet's label.
77 \brief Defines the font used by the barSet's label.
78 */
78 */
79
79
80 /*!
80 /*!
81 \qmlproperty Font BarSet::labelFont
81 \qmlproperty Font BarSet::labelFont
82 Defines the font used by the barSet's label.
82 Defines the font used by the barSet's label.
83
83
84 See the \l {Font} {QML Font Element} for detailed documentation.
84 See the \l {Font} {QML Font Element} for detailed documentation.
85 */
85 */
86
86
87 /*!
87 /*!
88 \property QBarSet::color
88 \property QBarSet::color
89 The fill (brush) color of the bar set.
89 The fill (brush) color of the bar set.
90 */
90 */
91 /*!
91 /*!
92 \qmlproperty color BarSet::color
92 \qmlproperty color BarSet::color
93 The fill (brush) color of the bar set.
93 The fill (brush) color of the bar set.
94 */
94 */
95
95
96 /*!
96 /*!
97 \property QBarSet::borderColor
97 \property QBarSet::borderColor
98 The line (pen) color of the bar set.
98 The line (pen) color of the bar set.
99 */
99 */
100 /*!
100 /*!
101 \qmlproperty color BarSet::borderColor
101 \qmlproperty color BarSet::borderColor
102 The line (pen) color of the bar set.
102 The line (pen) color of the bar set.
103 */
103 */
104
104
105 /*!
105 /*!
106 \qmlproperty real BarSet::borderWidth
106 \qmlproperty real BarSet::borderWidth
107 The width of the border line. By default the width is 2.0.
107 The width of the border line. By default the width is 2.0.
108 */
108 */
109
109
110 /*!
110 /*!
111 \property QBarSet::labelColor
111 \property QBarSet::labelColor
112 The text (label) color of the bar set.
112 The text (label) color of the bar set.
113 */
113 */
114 /*!
114 /*!
115 \qmlproperty color BarSet::labelColor
115 \qmlproperty color BarSet::labelColor
116 The text (label) color of the bar set.
116 The text (label) color of the bar set.
117 */
117 */
118
118
119 /*!
119 /*!
120 \fn void QBarSet::clicked(int index)
120 \fn void QBarSet::clicked(int index)
121
121
122 The signal is emitted if the user clicks with a mouse on top of barset.
122 The signal is emitted if the user clicks with a mouse on top of barset.
123 Clicked bar inside set is indexed by \a index
123 Clicked bar inside set is indexed by \a index
124 */
124 */
125
125
126 /*!
126 /*!
127 \fn void QBarSet::hovered(bool status)
127 \fn void QBarSet::hovered(bool status)
128
128
129 The signal is emitted if mouse is hovered on top of barset.
129 The signal is emitted if mouse is hovered on top of barset.
130 Parameter \a status is true, if mouse entered on top of barset, false if mouse left from top of barset.
130 Parameter \a status is true, if mouse entered on top of barset, false if mouse left from top of barset.
131 */
131 */
132
132
133
133
134 /*!
134 /*!
135 \fn void QBarSet::labelChanged()
135 \fn void QBarSet::labelChanged()
136 This signal is emitted when the label of the barSet has changed.
136 This signal is emitted when the label of the barSet has changed.
137 \sa label
137 \sa label
138 */
138 */
139 /*!
139 /*!
140 \qmlsignal BarSet::onLabelChanged()
140 \qmlsignal BarSet::onLabelChanged()
141 This signal is emitted when the label of the barSet has changed.
141 This signal is emitted when the label of the barSet has changed.
142 */
142 */
143
143
144 /*!
144 /*!
145 \fn void QBarSet::penChanged()
145 \fn void QBarSet::penChanged()
146 This signal is emitted when the pen of the barSet has changed.
146 This signal is emitted when the pen of the barSet has changed.
147 \sa pen
147 \sa pen
148 */
148 */
149
149
150 /*!
150 /*!
151 \fn void QBarSet::brushChanged()
151 \fn void QBarSet::brushChanged()
152 This signal is emitted when the brush of the barSet has changed.
152 This signal is emitted when the brush of the barSet has changed.
153 \sa brush
153 \sa brush
154 */
154 */
155
155
156 /*!
156 /*!
157 \fn void QBarSet::labelBrushChanged()
157 \fn void QBarSet::labelBrushChanged()
158 This signal is emitted when the brush of the barSet's label has changed.
158 This signal is emitted when the brush of the barSet's label has changed.
159 \sa labelBrush
159 \sa labelBrush
160 */
160 */
161
161
162 /*!
162 /*!
163 \fn void QBarSet::labelFontChanged()
163 \fn void QBarSet::labelFontChanged()
164 This signal is emitted when the font of the barSet's label has changed.
164 This signal is emitted when the font of the barSet's label has changed.
165 \sa labelBrush
165 \sa labelBrush
166 */
166 */
167
167
168 /*!
168 /*!
169 \fn void QBarSet::colorChanged(QColor)
169 \fn void QBarSet::colorChanged(QColor)
170 This signal is emitted when the fill (brush) color of the set has changed to \a color.
170 This signal is emitted when the fill (brush) color of the set has changed to \a color.
171 */
171 */
172 /*!
172 /*!
173 \qmlsignal BarSet::onColorChanged(color color)
173 \qmlsignal BarSet::onColorChanged(color color)
174 This signal is emitted when the fill (brush) color of the set has changed to \a color.
174 This signal is emitted when the fill (brush) color of the set has changed to \a color.
175 */
175 */
176
176
177 /*!
177 /*!
178 \fn void QBarSet::borderColorChanged(QColor)
178 \fn void QBarSet::borderColorChanged(QColor)
179 This signal is emitted when the line (pen) color of the set has changed to \a color.
179 This signal is emitted when the line (pen) color of the set has changed to \a color.
180 */
180 */
181 /*!
181 /*!
182 \qmlsignal BarSet::onBorderColorChanged(color color)
182 \qmlsignal BarSet::onBorderColorChanged(color color)
183 This signal is emitted when the line (pen) color of the set has changed to \a color.
183 This signal is emitted when the line (pen) color of the set has changed to \a color.
184 */
184 */
185
185
186 /*!
186 /*!
187 \fn void QBarSet::labelColorChanged(QColor)
187 \fn void QBarSet::labelColorChanged(QColor)
188 This signal is emitted when the text (label) color of the set has changed to \a color.
188 This signal is emitted when the text (label) color of the set has changed to \a color.
189 */
189 */
190 /*!
190 /*!
191 \qmlsignal BarSet::onLabelColorChanged(color color)
191 \qmlsignal BarSet::onLabelColorChanged(color color)
192 This signal is emitted when the text (label) color of the set has changed to \a color.
192 This signal is emitted when the text (label) color of the set has changed to \a color.
193 */
193 */
194
194
195 /*!
195 /*!
196 \fn void QBarSet::valuesAdded(int index, int count)
196 \fn void QBarSet::valuesAdded(int index, int count)
197 This signal is emitted when new values have been added to the set.
197 This signal is emitted when new values have been added to the set.
198 Parameter \a index indicates the position of the first inserted value.
198 Parameter \a index indicates the position of the first inserted value.
199 Parameter \a count is the number of inserted values.
199 Parameter \a count is the number of inserted values.
200 \sa append(), insert()
200 \sa append(), insert()
201 */
201 */
202 /*!
202 /*!
203 \qmlsignal BarSet::onValuesAdded(int index, int count)
203 \qmlsignal BarSet::onValuesAdded(int index, int count)
204 This signal is emitted when new values have been added to the set.
204 This signal is emitted when new values have been added to the set.
205 Parameter \a index indicates the position of the first inserted value.
205 Parameter \a index indicates the position of the first inserted value.
206 Parameter \a count is the number of inserted values.
206 Parameter \a count is the number of inserted values.
207 */
207 */
208
208
209 /*!
209 /*!
210 \fn void QBarSet::valuesRemoved(int index, int count)
210 \fn void QBarSet::valuesRemoved(int index, int count)
211 This signal is emitted values have been removed from the set.
211 This signal is emitted values have been removed from the set.
212 Parameter \a index indicates the position of the first removed value.
212 Parameter \a index indicates the position of the first removed value.
213 Parameter \a count is the number of removed values.
213 Parameter \a count is the number of removed values.
214 \sa remove()
214 \sa remove()
215 */
215 */
216 /*!
216 /*!
217 \qmlsignal BarSet::onValuesRemoved(int index, int count)
217 \qmlsignal BarSet::onValuesRemoved(int index, int count)
218 This signal is emitted values have been removed from the set.
218 This signal is emitted values have been removed from the set.
219 Parameter \a index indicates the position of the first removed value.
219 Parameter \a index indicates the position of the first removed value.
220 Parameter \a count is the number of removed values.
220 Parameter \a count is the number of removed values.
221 */
221 */
222
222
223 /*!
223 /*!
224 \fn void QBarSet::valueChanged(int index)
224 \fn void QBarSet::valueChanged(int index)
225 This signal is emitted values the value in the set has been modified.
225 This signal is emitted values the value in the set has been modified.
226 Parameter \a index indicates the position of the modified value.
226 Parameter \a index indicates the position of the modified value.
227 \sa at()
227 \sa at()
228 */
228 */
229 /*!
229 /*!
230 \qmlsignal BarSet::onValueChanged(int index)
230 \qmlsignal BarSet::onValueChanged(int index)
231 This signal is emitted values the value in the set has been modified.
231 This signal is emitted values the value in the set has been modified.
232 Parameter \a index indicates the position of the modified value.
232 Parameter \a index indicates the position of the modified value.
233 */
233 */
234
234
235 /*!
235 /*!
236 \qmlproperty int BarSet::count
236 \qmlproperty int BarSet::count
237 The count of values on the barset
237 The count of values on the barset
238 */
238 */
239
239
240 /*!
240 /*!
241 \qmlproperty QVariantList BarSet::values
241 \qmlproperty QVariantList BarSet::values
242 The values of the barset. You can set either a list of reals or a list of points as values. If you set a list of
242 The values of the barset. You can set either a list of reals or a list of points as values. If you set a list of
243 reals as values, the values are automatically completed to points by using the index of a value as it's
243 reals as values, the values are automatically completed to points by using the index of a value as it's
244 x-coordinate. For example:
244 x-coordinate. For example:
245 \code
245 \code
246 myBarSet1.values = [0, 5, 1, 5];
246 myBarSet1.values = [0, 5, 1, 5];
247 myBarSet2.values = [Qt.point(0, 1), Qt.point(1, 5), Qt.point(2.2, 4.3)];
247 myBarSet2.values = [Qt.point(0, 1), Qt.point(1, 5), Qt.point(2.2, 4.3)];
248 \endcode
248 \endcode
249 */
249 */
250
250
251 /*!
251 /*!
252 Constructs QBarSet with a label of \a label and with parent of \a parent.
252 Constructs QBarSet with a label of \a label and with parent of \a parent.
253 */
253 */
254 QBarSet::QBarSet(const QString label, QObject *parent)
254 QBarSet::QBarSet(const QString label, QObject *parent)
255 : QObject(parent),
255 : QObject(parent),
256 d_ptr(new QBarSetPrivate(label, this))
256 d_ptr(new QBarSetPrivate(label, this))
257 {
257 {
258 }
258 }
259
259
260 /*!
260 /*!
261 Destroys the barset.
261 Destroys the barset.
262 */
262 */
263 QBarSet::~QBarSet()
263 QBarSet::~QBarSet()
264 {
264 {
265 // NOTE: d_ptr destroyed by QObject
265 // NOTE: d_ptr destroyed by QObject
266 }
266 }
267
267
268 /*!
268 /*!
269 Sets new \a label for set.
269 Sets new \a label for set.
270 */
270 */
271 void QBarSet::setLabel(const QString label)
271 void QBarSet::setLabel(const QString label)
272 {
272 {
273 d_ptr->m_label = label;
273 d_ptr->m_label = label;
274 emit labelChanged();
274 emit labelChanged();
275 }
275 }
276
276
277 /*!
277 /*!
278 Returns label of the set.
278 Returns label of the set.
279 */
279 */
280 QString QBarSet::label() const
280 QString QBarSet::label() const
281 {
281 {
282 return d_ptr->m_label;
282 return d_ptr->m_label;
283 }
283 }
284
284
285 /*!
285 /*!
286 Appends new value \a value to the end of set.
286 Appends new value \a value to the end of set.
287 */
287 */
288 void QBarSet::append(const qreal value)
288 void QBarSet::append(const qreal value)
289 {
289 {
290 // Convert to QPointF
290 // Convert to QPointF
291 int index = d_ptr->m_values.count();
291 int index = d_ptr->m_values.count();
292 d_ptr->append(QPointF(d_ptr->m_values.count(), value));
292 d_ptr->append(QPointF(d_ptr->m_values.count(), value));
293 emit valuesAdded(index, 1);
293 emit valuesAdded(index, 1);
294 }
294 }
295
295
296 /*!
296 /*!
297 Appends a list of reals to set. Works like append with single real value. The \a values in list
297 Appends a list of reals to set. Works like append with single real value. The \a values in list
298 are appended to end of barset
298 are appended to end of barset
299 \sa append()
299 \sa append()
300 */
300 */
301 void QBarSet::append(const QList<qreal> &values)
301 void QBarSet::append(const QList<qreal> &values)
302 {
302 {
303 int index = d_ptr->m_values.count();
303 int index = d_ptr->m_values.count();
304 d_ptr->append(values);
304 d_ptr->append(values);
305 emit valuesAdded(index, values.count());
305 emit valuesAdded(index, values.count());
306 }
306 }
307
307
308 /*!
308 /*!
309 Convenience operator. Same as append, with real \a value.
309 Convenience operator. Same as append, with real \a value.
310 \sa append()
310 \sa append()
311 */
311 */
312 QBarSet &QBarSet::operator << (const qreal &value)
312 QBarSet &QBarSet::operator << (const qreal &value)
313 {
313 {
314 append(value);
314 append(value);
315 return *this;
315 return *this;
316 }
316 }
317
317
318 /*!
318 /*!
319 Inserts new \a value on the \a index position.
319 Inserts new \a value on the \a index position.
320 The value that is currently at this postion is moved to position index + 1
320 The value that is currently at this postion is moved to position index + 1
321 \sa remove()
321 \sa remove()
322 */
322 */
323 void QBarSet::insert(const int index, const qreal value)
323 void QBarSet::insert(const int index, const qreal value)
324 {
324 {
325 d_ptr->insert(index, value);
325 d_ptr->insert(index, value);
326 emit valuesAdded(index, 1);
326 emit valuesAdded(index, 1);
327 }
327 }
328
328
329 /*!
329 /*!
330 Removes \a count number of values from the set starting at \a index.
330 Removes \a count number of values from the set starting at \a index.
331 \sa insert()
331 \sa insert()
332 */
332 */
333 void QBarSet::remove(const int index, const int count)
333 void QBarSet::remove(const int index, const int count)
334 {
334 {
335 int removedCount = d_ptr->remove(index, count);
335 int removedCount = d_ptr->remove(index, count);
336 if (removedCount > 0)
336 if (removedCount > 0)
337 emit valuesRemoved(index, removedCount);
337 emit valuesRemoved(index, removedCount);
338 return;
338 return;
339 }
339 }
340
340
341 /*!
341 /*!
342 Sets a new value \a value to set, indexed by \a index.
342 Sets a new value \a value to set, indexed by \a index.
343 */
343 */
344 void QBarSet::replace(const int index, const qreal value)
344 void QBarSet::replace(const int index, const qreal value)
345 {
345 {
346 if (index >= 0 && index < d_ptr->m_values.count()) {
346 if (index >= 0 && index < d_ptr->m_values.count()) {
347 d_ptr->replace(index, value);
347 d_ptr->replace(index, value);
348 emit valueChanged(index);
348 emit valueChanged(index);
349 }
349 }
350 }
350 }
351
351
352
352
353 /*!
353 /*!
354 Returns value of set indexed by \a index.
354 Returns value of set indexed by \a index.
355 If the index is out of bounds 0.0 is returned.
355 If the index is out of bounds 0.0 is returned.
356 */
356 */
357 qreal QBarSet::at(const int index) const
357 qreal QBarSet::at(const int index) const
358 {
358 {
359 if (index < 0 || index >= d_ptr->m_values.count())
359 if (index < 0 || index >= d_ptr->m_values.count())
360 return 0;
360 return 0;
361 return d_ptr->m_values.at(index).y();
361 return d_ptr->m_values.at(index).y();
362 }
362 }
363
363
364 /*!
364 /*!
365 Returns value of set indexed by \a index.
365 Returns value of set indexed by \a index.
366 If the index is out of bounds 0.0 is returned.
366 If the index is out of bounds 0.0 is returned.
367 */
367 */
368 qreal QBarSet::operator [](const int index) const
368 qreal QBarSet::operator [](const int index) const
369 {
369 {
370 return at(index);
370 return at(index);
371 }
371 }
372
372
373 /*!
373 /*!
374 Returns count of values in set.
374 Returns count of values in set.
375 */
375 */
376 int QBarSet::count() const
376 int QBarSet::count() const
377 {
377 {
378 return d_ptr->m_values.count();
378 return d_ptr->m_values.count();
379 }
379 }
380
380
381 /*!
381 /*!
382 Returns sum of all values in barset.
382 Returns sum of all values in barset.
383 */
383 */
384 qreal QBarSet::sum() const
384 qreal QBarSet::sum() const
385 {
385 {
386 qreal total(0);
386 qreal total(0);
387 for (int i = 0; i < d_ptr->m_values.count(); i++)
387 for (int i = 0; i < d_ptr->m_values.count(); i++)
388 total += d_ptr->m_values.at(i).y();
388 total += d_ptr->m_values.at(i).y();
389 return total;
389 return total;
390 }
390 }
391
391
392 /*!
392 /*!
393 Sets pen for set. Bars of this set are drawn using \a pen
393 Sets pen for set. Bars of this set are drawn using \a pen
394 */
394 */
395 void QBarSet::setPen(const QPen &pen)
395 void QBarSet::setPen(const QPen &pen)
396 {
396 {
397 if (d_ptr->m_pen != pen) {
397 if (d_ptr->m_pen != pen) {
398 d_ptr->m_pen = pen;
398 d_ptr->m_pen = pen;
399 emit d_ptr->updatedBars();
399 emit d_ptr->updatedBars();
400 emit penChanged();
400 emit penChanged();
401 }
401 }
402 }
402 }
403
403
404 /*!
404 /*!
405 Returns pen of the set.
405 Returns pen of the set.
406 */
406 */
407 QPen QBarSet::pen() const
407 QPen QBarSet::pen() const
408 {
408 {
409 return d_ptr->m_pen;
409 if (d_ptr->m_pen == QChartPrivate::defaultPen())
410 return QPen();
411 else
412 return d_ptr->m_pen;
410 }
413 }
411
414
412 /*!
415 /*!
413 Sets brush for the set. Bars of this set are drawn using \a brush
416 Sets brush for the set. Bars of this set are drawn using \a brush
414 */
417 */
415 void QBarSet::setBrush(const QBrush &brush)
418 void QBarSet::setBrush(const QBrush &brush)
416 {
419 {
417 if (d_ptr->m_brush != brush) {
420 if (d_ptr->m_brush != brush) {
418 d_ptr->m_brush = brush;
421 d_ptr->m_brush = brush;
419 emit d_ptr->updatedBars();
422 emit d_ptr->updatedBars();
420 emit brushChanged();
423 emit brushChanged();
421 }
424 }
422 }
425 }
423
426
424 /*!
427 /*!
425 Returns brush of the set.
428 Returns brush of the set.
426 */
429 */
427 QBrush QBarSet::brush() const
430 QBrush QBarSet::brush() const
428 {
431 {
429 return d_ptr->m_brush;
432 if (d_ptr->m_brush == QChartPrivate::defaultBrush())
433 return QBrush();
434 else
435 return d_ptr->m_brush;
430 }
436 }
431
437
432 /*!
438 /*!
433 Sets \a brush of the values that are drawn on top of this barset
439 Sets \a brush of the values that are drawn on top of this barset
434 */
440 */
435 void QBarSet::setLabelBrush(const QBrush &brush)
441 void QBarSet::setLabelBrush(const QBrush &brush)
436 {
442 {
437 if (d_ptr->m_labelBrush != brush) {
443 if (d_ptr->m_labelBrush != brush) {
438 d_ptr->m_labelBrush = brush;
444 d_ptr->m_labelBrush = brush;
439 emit d_ptr->updatedBars();
445 emit d_ptr->updatedBars();
440 emit labelBrushChanged();
446 emit labelBrushChanged();
441 }
447 }
442 }
448 }
443
449
444 /*!
450 /*!
445 Returns brush of the values that are drawn on top of this barset
451 Returns brush of the values that are drawn on top of this barset
446 */
452 */
447 QBrush QBarSet::labelBrush() const
453 QBrush QBarSet::labelBrush() const
448 {
454 {
449 return d_ptr->m_labelBrush;
455 if (d_ptr->m_labelBrush == QChartPrivate::defaultBrush())
456 return QBrush();
457 else
458 return d_ptr->m_labelBrush;
450 }
459 }
451
460
452 /*!
461 /*!
453 Sets the \a font for values that are drawn on top of this barset
462 Sets the \a font for values that are drawn on top of this barset
454 */
463 */
455 void QBarSet::setLabelFont(const QFont &font)
464 void QBarSet::setLabelFont(const QFont &font)
456 {
465 {
457 if (d_ptr->m_labelFont != font) {
466 if (d_ptr->m_labelFont != font) {
458 d_ptr->m_labelFont = font;
467 d_ptr->m_labelFont = font;
459 emit d_ptr->updatedBars();
468 emit d_ptr->updatedBars();
460 emit labelFontChanged();
469 emit labelFontChanged();
461 }
470 }
462
471
463 }
472 }
464
473
465 /*!
474 /*!
466 Returns the pen for values that are drawn on top of this barset
475 Returns the pen for values that are drawn on top of this barset
467 */
476 */
468 QFont QBarSet::labelFont() const
477 QFont QBarSet::labelFont() const
469 {
478 {
470 return d_ptr->m_labelFont;
479 return d_ptr->m_labelFont;
471 }
480 }
472
481
473 /*!
482 /*!
474 Returns the color of the brush of barset.
483 Returns the color of the brush of barset.
475 */
484 */
476 QColor QBarSet::color()
485 QColor QBarSet::color()
477 {
486 {
478 return brush().color();
487 return brush().color();
479 }
488 }
480
489
481 /*!
490 /*!
482 Sets the \a color of brush for this barset
491 Sets the \a color of brush for this barset
483 */
492 */
484 void QBarSet::setColor(QColor color)
493 void QBarSet::setColor(QColor color)
485 {
494 {
486 QBrush b = brush();
495 QBrush b = brush();
487 if ((b.color() != color) || (b.style() == Qt::NoBrush)) {
496 if ((b.color() != color) || (b.style() == Qt::NoBrush)) {
488 b.setColor(color);
497 b.setColor(color);
489 if (b.style() == Qt::NoBrush) {
498 if (b.style() == Qt::NoBrush) {
490 // Set tyle to Qt::SolidPattern. (Default is Qt::NoBrush)
499 // Set tyle to Qt::SolidPattern. (Default is Qt::NoBrush)
491 // This prevents theme to override color defined in QML side:
500 // This prevents theme to override color defined in QML side:
492 // BarSet { label: "Bob"; color:"red"; values: [1,2,3] }
501 // BarSet { label: "Bob"; color:"red"; values: [1,2,3] }
493 // The color must be obeyed, since user wanted it.
502 // The color must be obeyed, since user wanted it.
494 b.setStyle(Qt::SolidPattern);
503 b.setStyle(Qt::SolidPattern);
495 }
504 }
496 setBrush(b);
505 setBrush(b);
497 emit colorChanged(color);
506 emit colorChanged(color);
498 }
507 }
499 }
508 }
500
509
501 /*!
510 /*!
502 Returns the color of pen of this barset
511 Returns the color of pen of this barset
503 */
512 */
504 QColor QBarSet::borderColor()
513 QColor QBarSet::borderColor()
505 {
514 {
506 return pen().color();
515 return pen().color();
507 }
516 }
508
517
509 /*!
518 /*!
510 Sets the color of pen for this barset
519 Sets the color of pen for this barset
511 */
520 */
512 void QBarSet::setBorderColor(QColor color)
521 void QBarSet::setBorderColor(QColor color)
513 {
522 {
514 QPen p = pen();
523 QPen p = pen();
515 if (p.color() != color) {
524 if (p.color() != color) {
516 p.setColor(color);
525 p.setColor(color);
517 setPen(p);
526 setPen(p);
518 emit borderColorChanged(color);
527 emit borderColorChanged(color);
519 }
528 }
520 }
529 }
521
530
522 /*!
531 /*!
523 Returns the color of labels of this barset
532 Returns the color of labels of this barset
524 */
533 */
525 QColor QBarSet::labelColor()
534 QColor QBarSet::labelColor()
526 {
535 {
527 return labelBrush().color();
536 return labelBrush().color();
528 }
537 }
529
538
530 /*!
539 /*!
531 Sets the color of labels for this barset
540 Sets the color of labels for this barset
532 */
541 */
533 void QBarSet::setLabelColor(QColor color)
542 void QBarSet::setLabelColor(QColor color)
534 {
543 {
535 QBrush b = labelBrush();
544 QBrush b = labelBrush();
536 if (b == QBrush())
545 if (b == QBrush())
537 b.setStyle(Qt::SolidPattern);
546 b.setStyle(Qt::SolidPattern);
538
547
539 if (b.color() != color) {
548 if (b.color() != color) {
540 b.setColor(color);
549 b.setColor(color);
541 setLabelBrush(b);
550 setLabelBrush(b);
542 emit labelColorChanged(color);
551 emit labelColorChanged(color);
543 }
552 }
544 }
553 }
545
554
546 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
555 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
547
556
548 QBarSetPrivate::QBarSetPrivate(const QString label, QBarSet *parent) : QObject(parent),
557 QBarSetPrivate::QBarSetPrivate(const QString label, QBarSet *parent) : QObject(parent),
549 q_ptr(parent),
558 q_ptr(parent),
550 m_label(label),
559 m_label(label),
551 m_pen(QChartPrivate::defaultPen()),
560 m_pen(QChartPrivate::defaultPen()),
552 m_brush(QChartPrivate::defaultBrush()),
561 m_brush(QChartPrivate::defaultBrush()),
553 m_labelBrush(QChartPrivate::defaultBrush())
562 m_labelBrush(QChartPrivate::defaultBrush())
554 {
563 {
555 }
564 }
556
565
557 QBarSetPrivate::~QBarSetPrivate()
566 QBarSetPrivate::~QBarSetPrivate()
558 {
567 {
559 }
568 }
560
569
561 void QBarSetPrivate::append(QPointF value)
570 void QBarSetPrivate::append(QPointF value)
562 {
571 {
563 if (isValidValue(value)) {
572 if (isValidValue(value)) {
564 m_values.append(value);
573 m_values.append(value);
565 emit restructuredBars();
574 emit restructuredBars();
566 }
575 }
567 }
576 }
568
577
569 void QBarSetPrivate::append(QList<QPointF> values)
578 void QBarSetPrivate::append(QList<QPointF> values)
570 {
579 {
571 for (int i = 0; i < values.count(); i++) {
580 for (int i = 0; i < values.count(); i++) {
572 if (isValidValue(values.at(i)))
581 if (isValidValue(values.at(i)))
573 m_values.append(values.at(i));
582 m_values.append(values.at(i));
574 }
583 }
575 emit restructuredBars();
584 emit restructuredBars();
576 }
585 }
577
586
578 void QBarSetPrivate::append(QList<qreal> values)
587 void QBarSetPrivate::append(QList<qreal> values)
579 {
588 {
580 int index = m_values.count();
589 int index = m_values.count();
581 for (int i = 0; i < values.count(); i++) {
590 for (int i = 0; i < values.count(); i++) {
582 if (isValidValue(values.at(i))) {
591 if (isValidValue(values.at(i))) {
583 m_values.append(QPointF(index, values.at(i)));
592 m_values.append(QPointF(index, values.at(i)));
584 index++;
593 index++;
585 }
594 }
586 }
595 }
587 emit restructuredBars();
596 emit restructuredBars();
588 }
597 }
589
598
590 void QBarSetPrivate::insert(const int index, const qreal value)
599 void QBarSetPrivate::insert(const int index, const qreal value)
591 {
600 {
592 m_values.insert(index, QPointF(index, value));
601 m_values.insert(index, QPointF(index, value));
593 emit restructuredBars();
602 emit restructuredBars();
594 }
603 }
595
604
596 void QBarSetPrivate::insert(const int index, const QPointF value)
605 void QBarSetPrivate::insert(const int index, const QPointF value)
597 {
606 {
598 m_values.insert(index, value);
607 m_values.insert(index, value);
599 emit restructuredBars();
608 emit restructuredBars();
600 }
609 }
601
610
602 int QBarSetPrivate::remove(const int index, const int count)
611 int QBarSetPrivate::remove(const int index, const int count)
603 {
612 {
604 int removeCount = count;
613 int removeCount = count;
605
614
606 if ((index < 0) || (m_values.count() == 0))
615 if ((index < 0) || (m_values.count() == 0))
607 return 0; // Invalid index or not values in list, remove nothing.
616 return 0; // Invalid index or not values in list, remove nothing.
608 else if ((index + count) > m_values.count())
617 else if ((index + count) > m_values.count())
609 removeCount = m_values.count() - index; // Trying to remove more items than list has. Limit amount to be removed.
618 removeCount = m_values.count() - index; // Trying to remove more items than list has. Limit amount to be removed.
610
619
611 int c = 0;
620 int c = 0;
612 while (c < removeCount) {
621 while (c < removeCount) {
613 m_values.removeAt(index);
622 m_values.removeAt(index);
614 c++;
623 c++;
615 }
624 }
616 emit restructuredBars();
625 emit restructuredBars();
617 return removeCount;
626 return removeCount;
618 }
627 }
619
628
620 void QBarSetPrivate::replace(const int index, const qreal value)
629 void QBarSetPrivate::replace(const int index, const qreal value)
621 {
630 {
622 m_values.replace(index, QPointF(index, value));
631 m_values.replace(index, QPointF(index, value));
623 emit updatedLayout();
632 emit updatedLayout();
624 }
633 }
625
634
626 void QBarSetPrivate::replace(const int index, const QPointF value)
635 void QBarSetPrivate::replace(const int index, const QPointF value)
627 {
636 {
628 m_values.replace(index, value);
637 m_values.replace(index, value);
629 emit updatedLayout();
638 emit updatedLayout();
630 }
639 }
631
640
632 qreal QBarSetPrivate::pos(const int index)
641 qreal QBarSetPrivate::pos(const int index)
633 {
642 {
634 if (index < 0 || index >= m_values.count())
643 if (index < 0 || index >= m_values.count())
635 return 0;
644 return 0;
636 return m_values.at(index).x();
645 return m_values.at(index).x();
637 }
646 }
638
647
639 qreal QBarSetPrivate::value(const int index)
648 qreal QBarSetPrivate::value(const int index)
640 {
649 {
641 if (index < 0 || index >= m_values.count())
650 if (index < 0 || index >= m_values.count())
642 return 0;
651 return 0;
643 return m_values.at(index).y();
652 return m_values.at(index).y();
644 }
653 }
645
654
646 #include "moc_qbarset.cpp"
655 #include "moc_qbarset.cpp"
647 #include "moc_qbarset_p.cpp"
656 #include "moc_qbarset_p.cpp"
648
657
649 QTCOMMERCIALCHART_END_NAMESPACE
658 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,590 +1,596
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 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 "qxyseries.h"
21 #include "qxyseries.h"
22 #include "qxyseries_p.h"
22 #include "qxyseries_p.h"
23 #include "abstractdomain_p.h"
23 #include "abstractdomain_p.h"
24 #include "qvalueaxis.h"
24 #include "qvalueaxis.h"
25 #include "xychart_p.h"
25 #include "xychart_p.h"
26 #include "qxylegendmarker.h"
26 #include "qxylegendmarker.h"
27 #include "charthelpers_p.h"
27 #include "charthelpers_p.h"
28 #include "qchart_p.h"
28 #include "qchart_p.h"
29
29
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31
31
32 /*!
32 /*!
33 \class QXYSeries
33 \class QXYSeries
34 \brief The QXYSeries class is a base class for line, spline and scatter series.
34 \brief The QXYSeries class is a base class for line, spline and scatter series.
35 */
35 */
36 /*!
36 /*!
37 \qmlclass XYSeries
37 \qmlclass XYSeries
38 \inherits AbstractSeries
38 \inherits AbstractSeries
39 The XYSeries class is a base class for line, spline and scatter series.
39 The XYSeries class is a base class for line, spline and scatter series.
40
40
41 The class cannot be instantiated directly.
41 The class cannot be instantiated directly.
42 */
42 */
43
43
44 /*!
44 /*!
45 \qmlproperty AbstractAxis XYSeries::axisX
45 \qmlproperty AbstractAxis XYSeries::axisX
46 The x axis used for the series. If you leave both axisX and axisXTop undefined, a ValueAxis is created for
46 The x axis used for the series. If you leave both axisX and axisXTop undefined, a ValueAxis is created for
47 the series.
47 the series.
48 \sa axisXTop
48 \sa axisXTop
49 */
49 */
50
50
51 /*!
51 /*!
52 \qmlproperty AbstractAxis XYSeries::axisY
52 \qmlproperty AbstractAxis XYSeries::axisY
53 The y axis used for the series. If you leave both axisY and axisYRight undefined, a ValueAxis is created for
53 The y axis used for the series. If you leave both axisY and axisYRight undefined, a ValueAxis is created for
54 the series.
54 the series.
55 \sa axisYRight
55 \sa axisYRight
56 */
56 */
57
57
58 /*!
58 /*!
59 \qmlproperty AbstractAxis XYSeries::axisXTop
59 \qmlproperty AbstractAxis XYSeries::axisXTop
60 The x axis used for the series, drawn on top of the chart view. Note that you can only provide either axisX or
60 The x axis used for the series, drawn on top of the chart view. Note that you can only provide either axisX or
61 axisXTop, but not both.
61 axisXTop, but not both.
62 \sa axisX
62 \sa axisX
63 */
63 */
64
64
65 /*!
65 /*!
66 \qmlproperty AbstractAxis XYSeries::axisYRight
66 \qmlproperty AbstractAxis XYSeries::axisYRight
67 The y axis used for the series, drawn to the right on the chart view. Note that you can only provide either axisY
67 The y axis used for the series, drawn to the right on the chart view. Note that you can only provide either axisY
68 or axisYRight, but not both.
68 or axisYRight, but not both.
69 \sa axisY
69 \sa axisY
70 */
70 */
71
71
72 /*!
72 /*!
73 \qmlproperty AbstractAxis XYSeries::axisAngular
73 \qmlproperty AbstractAxis XYSeries::axisAngular
74 The angular axis used for the series, drawn around the polar chart view.
74 The angular axis used for the series, drawn around the polar chart view.
75 \sa axisX
75 \sa axisX
76 */
76 */
77
77
78 /*!
78 /*!
79 \qmlproperty AbstractAxis XYSeries::axisRadial
79 \qmlproperty AbstractAxis XYSeries::axisRadial
80 The radial axis used for the series, drawn inside the polar chart view.
80 The radial axis used for the series, drawn inside the polar chart view.
81 \sa axisY
81 \sa axisY
82 */
82 */
83
83
84 /*!
84 /*!
85 \property QXYSeries::pointsVisible
85 \property QXYSeries::pointsVisible
86 Controls if the data points are visible and should be drawn.
86 Controls if the data points are visible and should be drawn.
87 */
87 */
88 /*!
88 /*!
89 \qmlproperty bool XYSeries::pointsVisible
89 \qmlproperty bool XYSeries::pointsVisible
90 Controls if the data points are visible and should be drawn.
90 Controls if the data points are visible and should be drawn.
91 */
91 */
92
92
93 /*!
93 /*!
94 \fn QPen QXYSeries::pen() const
94 \fn QPen QXYSeries::pen() const
95 \brief Returns pen used to draw points for series.
95 \brief Returns pen used to draw points for series.
96 \sa setPen()
96 \sa setPen()
97 */
97 */
98
98
99 /*!
99 /*!
100 \fn QBrush QXYSeries::brush() const
100 \fn QBrush QXYSeries::brush() const
101 \brief Returns brush used to draw points for series.
101 \brief Returns brush used to draw points for series.
102 \sa setBrush()
102 \sa setBrush()
103 */
103 */
104
104
105 /*!
105 /*!
106 \property QXYSeries::color
106 \property QXYSeries::color
107 The color of the series. This is line (pen) color in case of QLineSeries or QSplineSeries and
107 The color of the series. This is line (pen) color in case of QLineSeries or QSplineSeries and
108 fill (brush) color in case of QScatterSeries or QAreaSeries.
108 fill (brush) color in case of QScatterSeries or QAreaSeries.
109 \sa QXYSeries::pen(), QXYSeries::brush()
109 \sa QXYSeries::pen(), QXYSeries::brush()
110 */
110 */
111 /*!
111 /*!
112 \qmlproperty color XYSeries::color
112 \qmlproperty color XYSeries::color
113 The color of the series. This is line (pen) color in case of LineSeries or SplineSeries and
113 The color of the series. This is line (pen) color in case of LineSeries or SplineSeries and
114 fill (brush) color in case of ScatterSeries or AreaSeries.
114 fill (brush) color in case of ScatterSeries or AreaSeries.
115 */
115 */
116
116
117 /*!
117 /*!
118 \fn void QXYSeries::clicked(const QPointF& point)
118 \fn void QXYSeries::clicked(const QPointF& point)
119 \brief Signal is emitted when user clicks the \a point on chart.
119 \brief Signal is emitted when user clicks the \a point on chart.
120 */
120 */
121 /*!
121 /*!
122 \qmlsignal XYSeries::onClicked(QPointF point)
122 \qmlsignal XYSeries::onClicked(QPointF point)
123 Signal is emitted when user clicks the \a point on chart. For example:
123 Signal is emitted when user clicks the \a point on chart. For example:
124 \code
124 \code
125 LineSeries {
125 LineSeries {
126 XYPoint { x: 0; y: 0 }
126 XYPoint { x: 0; y: 0 }
127 XYPoint { x: 1.1; y: 2.1 }
127 XYPoint { x: 1.1; y: 2.1 }
128 onClicked: console.log("onClicked: " + point.x + ", " + point.y);
128 onClicked: console.log("onClicked: " + point.x + ", " + point.y);
129 }
129 }
130 \endcode
130 \endcode
131 */
131 */
132
132
133 /*!
133 /*!
134 \fn void QXYSeries::hovered(const QPointF &point, bool state)
134 \fn void QXYSeries::hovered(const QPointF &point, bool state)
135 This signal is emitted when user has hovered over or away from the series. \a point shows the origin (coordinate)
135 This signal is emitted when user has hovered over or away from the series. \a point shows the origin (coordinate)
136 of the hover event. \a state is true when user has hovered over the series and false when hover has moved away from
136 of the hover event. \a state is true when user has hovered over the series and false when hover has moved away from
137 the series.
137 the series.
138 */
138 */
139 /*!
139 /*!
140 \qmlsignal XYSeries::onHovered(point point, bool state)
140 \qmlsignal XYSeries::onHovered(point point, bool state)
141 This signal is emitted when user has hovered over or away from the series. \a point shows the origin (coordinate)
141 This signal is emitted when user has hovered over or away from the series. \a point shows the origin (coordinate)
142 of the hover event. \a state is true when user has hovered over the series and false when hover has moved away from
142 of the hover event. \a state is true when user has hovered over the series and false when hover has moved away from
143 the series.
143 the series.
144 */
144 */
145
145
146 /*!
146 /*!
147 \fn void QXYSeries::pointReplaced(int index)
147 \fn void QXYSeries::pointReplaced(int index)
148 Signal is emitted when a point has been replaced at \a index.
148 Signal is emitted when a point has been replaced at \a index.
149 \sa replace()
149 \sa replace()
150 */
150 */
151 /*!
151 /*!
152 \qmlsignal XYSeries::onPointReplaced(int index)
152 \qmlsignal XYSeries::onPointReplaced(int index)
153 Signal is emitted when a point has been replaced at \a index.
153 Signal is emitted when a point has been replaced at \a index.
154 */
154 */
155
155
156 /*!
156 /*!
157 \fn void QXYSeries::pointsReplaced()
157 \fn void QXYSeries::pointsReplaced()
158 Signal is emitted when all points have been replaced with other points.
158 Signal is emitted when all points have been replaced with other points.
159 \sa replace()
159 \sa replace()
160 */
160 */
161 /*!
161 /*!
162 \qmlsignal XYSeries::onPointsReplaced()
162 \qmlsignal XYSeries::onPointsReplaced()
163 */
163 */
164
164
165 /*!
165 /*!
166 \fn void QXYSeries::pointAdded(int index)
166 \fn void QXYSeries::pointAdded(int index)
167 Signal is emitted when a point has been added at \a index.
167 Signal is emitted when a point has been added at \a index.
168 \sa append(), insert()
168 \sa append(), insert()
169 */
169 */
170 /*!
170 /*!
171 \qmlsignal XYSeries::onPointAdded(int index)
171 \qmlsignal XYSeries::onPointAdded(int index)
172 Signal is emitted when a point has been added at \a index.
172 Signal is emitted when a point has been added at \a index.
173 */
173 */
174
174
175 /*!
175 /*!
176 \fn void QXYSeries::pointRemoved(int index)
176 \fn void QXYSeries::pointRemoved(int index)
177 Signal is emitted when a point has been removed from \a index.
177 Signal is emitted when a point has been removed from \a index.
178 \sa remove()
178 \sa remove()
179 */
179 */
180 /*!
180 /*!
181 \qmlsignal XYSeries::onPointRemoved(int index)
181 \qmlsignal XYSeries::onPointRemoved(int index)
182 Signal is emitted when a point has been removed from \a index.
182 Signal is emitted when a point has been removed from \a index.
183 */
183 */
184
184
185 /*!
185 /*!
186 \fn void QXYSeries::colorChanged(QColor color)
186 \fn void QXYSeries::colorChanged(QColor color)
187 \brief Signal is emitted when the line (pen) color has changed to \a color.
187 \brief Signal is emitted when the line (pen) color has changed to \a color.
188 */
188 */
189 /*!
189 /*!
190 \qmlsignal XYSeries::onColorChanged(color color)
190 \qmlsignal XYSeries::onColorChanged(color color)
191 Signal is emitted when the line (pen) color has changed to \a color.
191 Signal is emitted when the line (pen) color has changed to \a color.
192 */
192 */
193
193
194 /*!
194 /*!
195 \fn void QXYSeriesPrivate::updated()
195 \fn void QXYSeriesPrivate::updated()
196 \brief \internal
196 \brief \internal
197 */
197 */
198
198
199 /*!
199 /*!
200 \qmlmethod XYSeries::append(real x, real y)
200 \qmlmethod XYSeries::append(real x, real y)
201 Append point (\a x, \a y) to the series
201 Append point (\a x, \a y) to the series
202 */
202 */
203
203
204 /*!
204 /*!
205 \qmlmethod XYSeries::replace(real oldX, real oldY, real newX, real newY)
205 \qmlmethod XYSeries::replace(real oldX, real oldY, real newX, real newY)
206 Replaces point (\a oldX, \a oldY) with point (\a newX, \a newY). Does nothing, if point (oldX, oldY) does not
206 Replaces point (\a oldX, \a oldY) with point (\a newX, \a newY). Does nothing, if point (oldX, oldY) does not
207 exist.
207 exist.
208 */
208 */
209
209
210 /*!
210 /*!
211 \qmlmethod XYSeries::remove(real x, real y)
211 \qmlmethod XYSeries::remove(real x, real y)
212 Removes point (\a x, \a y) from the series. Does nothing, if point (x, y) does not exist.
212 Removes point (\a x, \a y) from the series. Does nothing, if point (x, y) does not exist.
213 */
213 */
214
214
215 /*!
215 /*!
216 \qmlmethod XYSeries::insert(int index, real x, real y)
216 \qmlmethod XYSeries::insert(int index, real x, real y)
217 Inserts point (\a x, \a y) to the \a index. If index is 0 or smaller than 0 the point is prepended to the list of
217 Inserts point (\a x, \a y) to the \a index. If index is 0 or smaller than 0 the point is prepended to the list of
218 points. If index is the same as or bigger than count, the point is appended to the list of points.
218 points. If index is the same as or bigger than count, the point is appended to the list of points.
219 */
219 */
220
220
221 /*!
221 /*!
222 \qmlmethod QPointF XYSeries::at(int index)
222 \qmlmethod QPointF XYSeries::at(int index)
223 Returns point at \a index. Returns (0, 0) if the index is not valid.
223 Returns point at \a index. Returns (0, 0) if the index is not valid.
224 */
224 */
225
225
226 /*!
226 /*!
227 \internal
227 \internal
228
228
229 Constructs empty series object which is a child of \a parent.
229 Constructs empty series object which is a child of \a parent.
230 When series object is added to QChart instance ownerships is transferred.
230 When series object is added to QChart instance ownerships is transferred.
231 */
231 */
232 QXYSeries::QXYSeries(QXYSeriesPrivate &d, QObject *parent)
232 QXYSeries::QXYSeries(QXYSeriesPrivate &d, QObject *parent)
233 : QAbstractSeries(d, parent)
233 : QAbstractSeries(d, parent)
234 {
234 {
235 }
235 }
236
236
237 /*!
237 /*!
238 Destroys the object. Series added to QChart instances are owned by those,
238 Destroys the object. Series added to QChart instances are owned by those,
239 and are destroyed when QChart instances are destroyed.
239 and are destroyed when QChart instances are destroyed.
240 */
240 */
241 QXYSeries::~QXYSeries()
241 QXYSeries::~QXYSeries()
242 {
242 {
243 }
243 }
244
244
245 /*!
245 /*!
246 Adds data point (\a x, \a y) to the series.
246 Adds data point (\a x, \a y) to the series.
247 */
247 */
248 void QXYSeries::append(qreal x, qreal y)
248 void QXYSeries::append(qreal x, qreal y)
249 {
249 {
250 append(QPointF(x, y));
250 append(QPointF(x, y));
251 }
251 }
252
252
253 /*!
253 /*!
254 This is an overloaded function.
254 This is an overloaded function.
255 Adds data \a point to the series.
255 Adds data \a point to the series.
256 */
256 */
257 void QXYSeries::append(const QPointF &point)
257 void QXYSeries::append(const QPointF &point)
258 {
258 {
259 Q_D(QXYSeries);
259 Q_D(QXYSeries);
260
260
261 if (isValidValue(point)) {
261 if (isValidValue(point)) {
262 d->m_points << point;
262 d->m_points << point;
263 emit pointAdded(d->m_points.count() - 1);
263 emit pointAdded(d->m_points.count() - 1);
264 }
264 }
265 }
265 }
266
266
267 /*!
267 /*!
268 This is an overloaded function.
268 This is an overloaded function.
269 Adds list of data \a points to the series.
269 Adds list of data \a points to the series.
270 */
270 */
271 void QXYSeries::append(const QList<QPointF> &points)
271 void QXYSeries::append(const QList<QPointF> &points)
272 {
272 {
273 foreach (const QPointF &point , points)
273 foreach (const QPointF &point , points)
274 append(point);
274 append(point);
275 }
275 }
276
276
277 /*!
277 /*!
278 Replaces data point (\a oldX, \a oldY) with data point (\a newX, \a newY).
278 Replaces data point (\a oldX, \a oldY) with data point (\a newX, \a newY).
279 \sa QXYSeries::pointReplaced()
279 \sa QXYSeries::pointReplaced()
280 */
280 */
281 void QXYSeries::replace(qreal oldX, qreal oldY, qreal newX, qreal newY)
281 void QXYSeries::replace(qreal oldX, qreal oldY, qreal newX, qreal newY)
282 {
282 {
283 replace(QPointF(oldX, oldY), QPointF(newX, newY));
283 replace(QPointF(oldX, oldY), QPointF(newX, newY));
284 }
284 }
285
285
286 /*!
286 /*!
287 Replaces \a oldPoint with \a newPoint.
287 Replaces \a oldPoint with \a newPoint.
288 \sa QXYSeries::pointReplaced()
288 \sa QXYSeries::pointReplaced()
289 */
289 */
290 void QXYSeries::replace(const QPointF &oldPoint, const QPointF &newPoint)
290 void QXYSeries::replace(const QPointF &oldPoint, const QPointF &newPoint)
291 {
291 {
292 Q_D(QXYSeries);
292 Q_D(QXYSeries);
293 int index = d->m_points.indexOf(oldPoint);
293 int index = d->m_points.indexOf(oldPoint);
294 if (index == -1)
294 if (index == -1)
295 return;
295 return;
296 replace(index, newPoint);
296 replace(index, newPoint);
297 }
297 }
298
298
299 /*!
299 /*!
300 Replaces the point at \a index with data point (\a newX, \a newY).
300 Replaces the point at \a index with data point (\a newX, \a newY).
301 \sa QXYSeries::pointReplaced()
301 \sa QXYSeries::pointReplaced()
302 */
302 */
303 void QXYSeries::replace(int index, qreal newX, qreal newY)
303 void QXYSeries::replace(int index, qreal newX, qreal newY)
304 {
304 {
305 replace(index, QPointF(newX, newY));
305 replace(index, QPointF(newX, newY));
306 }
306 }
307
307
308 /*!
308 /*!
309 Replaces the point at \a index with \a newPoint.
309 Replaces the point at \a index with \a newPoint.
310 \sa QXYSeries::pointReplaced()
310 \sa QXYSeries::pointReplaced()
311 */
311 */
312 void QXYSeries::replace(int index, const QPointF &newPoint)
312 void QXYSeries::replace(int index, const QPointF &newPoint)
313 {
313 {
314 Q_D(QXYSeries);
314 Q_D(QXYSeries);
315 if (isValidValue(newPoint)) {
315 if (isValidValue(newPoint)) {
316 d->m_points[index] = newPoint;
316 d->m_points[index] = newPoint;
317 emit pointReplaced(index);
317 emit pointReplaced(index);
318 }
318 }
319 }
319 }
320
320
321 /*!
321 /*!
322 Replaces the current points with \a points.
322 Replaces the current points with \a points.
323 \note This is much faster than replacing data points one by one,
323 \note This is much faster than replacing data points one by one,
324 or first clearing all data, and then appending the new data. Emits QXYSeries::pointsReplaced()
324 or first clearing all data, and then appending the new data. Emits QXYSeries::pointsReplaced()
325 when the points have been replaced.
325 when the points have been replaced.
326 \sa QXYSeries::pointsReplaced()
326 \sa QXYSeries::pointsReplaced()
327 */
327 */
328 void QXYSeries::replace(QList<QPointF> points)
328 void QXYSeries::replace(QList<QPointF> points)
329 {
329 {
330 Q_D(QXYSeries);
330 Q_D(QXYSeries);
331 d->m_points = points.toVector();
331 d->m_points = points.toVector();
332 emit pointsReplaced();
332 emit pointsReplaced();
333 }
333 }
334
334
335 /*!
335 /*!
336 Removes the point (\a x, \a y) from the series.
336 Removes the point (\a x, \a y) from the series.
337 */
337 */
338 void QXYSeries::remove(qreal x, qreal y)
338 void QXYSeries::remove(qreal x, qreal y)
339 {
339 {
340 remove(QPointF(x, y));
340 remove(QPointF(x, y));
341 }
341 }
342
342
343 /*!
343 /*!
344 Removes the \a point from the series.
344 Removes the \a point from the series.
345 */
345 */
346 void QXYSeries::remove(const QPointF &point)
346 void QXYSeries::remove(const QPointF &point)
347 {
347 {
348 Q_D(QXYSeries);
348 Q_D(QXYSeries);
349 int index = d->m_points.indexOf(point);
349 int index = d->m_points.indexOf(point);
350 if (index == -1)
350 if (index == -1)
351 return;
351 return;
352 remove(index);
352 remove(index);
353 }
353 }
354
354
355 /*!
355 /*!
356 Removes the point at \a index from the series.
356 Removes the point at \a index from the series.
357 */
357 */
358 void QXYSeries::remove(int index)
358 void QXYSeries::remove(int index)
359 {
359 {
360 Q_D(QXYSeries);
360 Q_D(QXYSeries);
361 d->m_points.remove(index);
361 d->m_points.remove(index);
362 emit pointRemoved(index);
362 emit pointRemoved(index);
363 }
363 }
364
364
365 /*!
365 /*!
366 Inserts a \a point in the series at \a index position.
366 Inserts a \a point in the series at \a index position.
367 */
367 */
368 void QXYSeries::insert(int index, const QPointF &point)
368 void QXYSeries::insert(int index, const QPointF &point)
369 {
369 {
370 Q_D(QXYSeries);
370 Q_D(QXYSeries);
371 if (isValidValue(point)) {
371 if (isValidValue(point)) {
372 d->m_points.insert(index, point);
372 d->m_points.insert(index, point);
373 emit pointAdded(index);
373 emit pointAdded(index);
374 }
374 }
375 }
375 }
376
376
377 /*!
377 /*!
378 Removes all points from the series.
378 Removes all points from the series.
379 */
379 */
380 void QXYSeries::clear()
380 void QXYSeries::clear()
381 {
381 {
382 Q_D(QXYSeries);
382 Q_D(QXYSeries);
383 for (int i = d->m_points.size() - 1; i >= 0; i--)
383 for (int i = d->m_points.size() - 1; i >= 0; i--)
384 remove(d->m_points.at(i));
384 remove(d->m_points.at(i));
385 }
385 }
386
386
387 /*!
387 /*!
388 Returns list of points in the series.
388 Returns list of points in the series.
389 */
389 */
390 QList<QPointF> QXYSeries::points() const
390 QList<QPointF> QXYSeries::points() const
391 {
391 {
392 Q_D(const QXYSeries);
392 Q_D(const QXYSeries);
393 return d->m_points.toList();
393 return d->m_points.toList();
394 }
394 }
395
395
396 /*!
396 /*!
397 Returns point at \a index in internal points vector.
397 Returns point at \a index in internal points vector.
398 */
398 */
399 const QPointF &QXYSeries::at(int index) const
399 const QPointF &QXYSeries::at(int index) const
400 {
400 {
401 Q_D(const QXYSeries);
401 Q_D(const QXYSeries);
402 return d->m_points.at(index);
402 return d->m_points.at(index);
403 }
403 }
404
404
405 /*!
405 /*!
406 Returns number of data points within series.
406 Returns number of data points within series.
407 */
407 */
408 int QXYSeries::count() const
408 int QXYSeries::count() const
409 {
409 {
410 Q_D(const QXYSeries);
410 Q_D(const QXYSeries);
411 return d->m_points.count();
411 return d->m_points.count();
412 }
412 }
413
413
414
414
415 /*!
415 /*!
416 Sets \a pen used for drawing points on the chart. If the pen is not defined, the
416 Sets \a pen used for drawing points on the chart. If the pen is not defined, the
417 pen from chart theme is used.
417 pen from chart theme is used.
418 \sa QChart::setTheme()
418 \sa QChart::setTheme()
419 */
419 */
420 void QXYSeries::setPen(const QPen &pen)
420 void QXYSeries::setPen(const QPen &pen)
421 {
421 {
422 Q_D(QXYSeries);
422 Q_D(QXYSeries);
423 if (d->m_pen != pen) {
423 if (d->m_pen != pen) {
424 bool emitColorChanged = d->m_pen.color() != pen.color();
424 bool emitColorChanged = d->m_pen.color() != pen.color();
425 d->m_pen = pen;
425 d->m_pen = pen;
426 emit d->updated();
426 emit d->updated();
427 if (emitColorChanged)
427 if (emitColorChanged)
428 emit colorChanged(pen.color());
428 emit colorChanged(pen.color());
429 }
429 }
430 }
430 }
431
431
432 QPen QXYSeries::pen() const
432 QPen QXYSeries::pen() const
433 {
433 {
434 Q_D(const QXYSeries);
434 Q_D(const QXYSeries);
435 return d->m_pen;
435 if (d->m_pen == QChartPrivate::defaultPen())
436 return QPen();
437 else
438 return d->m_pen;
436 }
439 }
437
440
438 /*!
441 /*!
439 Sets \a brush used for drawing points on the chart. If the brush is not defined, brush
442 Sets \a brush used for drawing points on the chart. If the brush is not defined, brush
440 from chart theme setting is used.
443 from chart theme setting is used.
441 \sa QChart::setTheme()
444 \sa QChart::setTheme()
442 */
445 */
443 void QXYSeries::setBrush(const QBrush &brush)
446 void QXYSeries::setBrush(const QBrush &brush)
444 {
447 {
445 Q_D(QXYSeries);
448 Q_D(QXYSeries);
446 if (d->m_brush != brush) {
449 if (d->m_brush != brush) {
447 d->m_brush = brush;
450 d->m_brush = brush;
448 emit d->updated();
451 emit d->updated();
449 }
452 }
450 }
453 }
451
454
452 QBrush QXYSeries::brush() const
455 QBrush QXYSeries::brush() const
453 {
456 {
454 Q_D(const QXYSeries);
457 Q_D(const QXYSeries);
455 return d->m_brush;
458 if (d->m_brush == QChartPrivate::defaultBrush())
459 return QBrush();
460 else
461 return d->m_brush;
456 }
462 }
457
463
458 void QXYSeries::setColor(const QColor &color)
464 void QXYSeries::setColor(const QColor &color)
459 {
465 {
460 QPen p = pen();
466 QPen p = pen();
461 if (p.color() != color) {
467 if (p.color() != color) {
462 p.setColor(color);
468 p.setColor(color);
463 setPen(p);
469 setPen(p);
464 }
470 }
465 }
471 }
466
472
467 QColor QXYSeries::color() const
473 QColor QXYSeries::color() const
468 {
474 {
469 return pen().color();
475 return pen().color();
470 }
476 }
471
477
472 void QXYSeries::setPointsVisible(bool visible)
478 void QXYSeries::setPointsVisible(bool visible)
473 {
479 {
474 Q_D(QXYSeries);
480 Q_D(QXYSeries);
475 if (d->m_pointsVisible != visible) {
481 if (d->m_pointsVisible != visible) {
476 d->m_pointsVisible = visible;
482 d->m_pointsVisible = visible;
477 emit d->updated();
483 emit d->updated();
478 }
484 }
479 }
485 }
480
486
481 bool QXYSeries::pointsVisible() const
487 bool QXYSeries::pointsVisible() const
482 {
488 {
483 Q_D(const QXYSeries);
489 Q_D(const QXYSeries);
484 return d->m_pointsVisible;
490 return d->m_pointsVisible;
485 }
491 }
486
492
487
493
488 /*!
494 /*!
489 Stream operator for adding a data \a point to the series.
495 Stream operator for adding a data \a point to the series.
490 \sa append()
496 \sa append()
491 */
497 */
492 QXYSeries &QXYSeries::operator<< (const QPointF &point)
498 QXYSeries &QXYSeries::operator<< (const QPointF &point)
493 {
499 {
494 append(point);
500 append(point);
495 return *this;
501 return *this;
496 }
502 }
497
503
498
504
499 /*!
505 /*!
500 Stream operator for adding a list of \a points to the series.
506 Stream operator for adding a list of \a points to the series.
501 \sa append()
507 \sa append()
502 */
508 */
503
509
504 QXYSeries &QXYSeries::operator<< (const QList<QPointF>& points)
510 QXYSeries &QXYSeries::operator<< (const QList<QPointF>& points)
505 {
511 {
506 append(points);
512 append(points);
507 return *this;
513 return *this;
508 }
514 }
509
515
510 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
516 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
511
517
512
518
513 QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q)
519 QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q)
514 : QAbstractSeriesPrivate(q),
520 : QAbstractSeriesPrivate(q),
515 m_pen(QChartPrivate::defaultPen()),
521 m_pen(QChartPrivate::defaultPen()),
516 m_brush(QChartPrivate::defaultBrush()),
522 m_brush(QChartPrivate::defaultBrush()),
517 m_pointsVisible(false)
523 m_pointsVisible(false)
518 {
524 {
519 }
525 }
520
526
521 void QXYSeriesPrivate::initializeDomain()
527 void QXYSeriesPrivate::initializeDomain()
522 {
528 {
523 qreal minX(0);
529 qreal minX(0);
524 qreal minY(0);
530 qreal minY(0);
525 qreal maxX(1);
531 qreal maxX(1);
526 qreal maxY(1);
532 qreal maxY(1);
527
533
528 Q_Q(QXYSeries);
534 Q_Q(QXYSeries);
529
535
530 const QList<QPointF>& points = q->points();
536 const QList<QPointF>& points = q->points();
531
537
532 if (!points.isEmpty()) {
538 if (!points.isEmpty()) {
533 minX = points[0].x();
539 minX = points[0].x();
534 minY = points[0].y();
540 minY = points[0].y();
535 maxX = minX;
541 maxX = minX;
536 maxY = minY;
542 maxY = minY;
537
543
538 for (int i = 0; i < points.count(); i++) {
544 for (int i = 0; i < points.count(); i++) {
539 qreal x = points[i].x();
545 qreal x = points[i].x();
540 qreal y = points[i].y();
546 qreal y = points[i].y();
541 minX = qMin(minX, x);
547 minX = qMin(minX, x);
542 minY = qMin(minY, y);
548 minY = qMin(minY, y);
543 maxX = qMax(maxX, x);
549 maxX = qMax(maxX, x);
544 maxY = qMax(maxY, y);
550 maxY = qMax(maxY, y);
545 }
551 }
546 }
552 }
547
553
548 domain()->setRange(minX, maxX, minY, maxY);
554 domain()->setRange(minX, maxX, minY, maxY);
549 }
555 }
550
556
551 QList<QLegendMarker*> QXYSeriesPrivate::createLegendMarkers(QLegend* legend)
557 QList<QLegendMarker*> QXYSeriesPrivate::createLegendMarkers(QLegend* legend)
552 {
558 {
553 Q_Q(QXYSeries);
559 Q_Q(QXYSeries);
554 QList<QLegendMarker*> list;
560 QList<QLegendMarker*> list;
555 return list << new QXYLegendMarker(q,legend);
561 return list << new QXYLegendMarker(q,legend);
556 }
562 }
557
563
558 void QXYSeriesPrivate::initializeAxes()
564 void QXYSeriesPrivate::initializeAxes()
559 {
565 {
560
566
561 }
567 }
562
568
563 QAbstractAxis::AxisType QXYSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
569 QAbstractAxis::AxisType QXYSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
564 {
570 {
565 Q_UNUSED(orientation);
571 Q_UNUSED(orientation);
566 return QAbstractAxis::AxisTypeValue;
572 return QAbstractAxis::AxisTypeValue;
567 }
573 }
568
574
569 QAbstractAxis* QXYSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const
575 QAbstractAxis* QXYSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const
570 {
576 {
571 Q_UNUSED(orientation);
577 Q_UNUSED(orientation);
572 return 0;
578 return 0;
573 }
579 }
574
580
575 void QXYSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options)
581 void QXYSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options)
576 {
582 {
577 XYChart *item = static_cast<XYChart *>(m_item.data());
583 XYChart *item = static_cast<XYChart *>(m_item.data());
578 Q_ASSERT(item);
584 Q_ASSERT(item);
579 if (options.testFlag(QChart::SeriesAnimations)) {
585 if (options.testFlag(QChart::SeriesAnimations)) {
580 item->setAnimation(new XYAnimation(item));
586 item->setAnimation(new XYAnimation(item));
581 }else{
587 }else{
582 item->setAnimation(0);
588 item->setAnimation(0);
583 }
589 }
584 QAbstractSeriesPrivate::initializeAnimations(options);
590 QAbstractSeriesPrivate::initializeAnimations(options);
585 }
591 }
586
592
587 #include "moc_qxyseries.cpp"
593 #include "moc_qxyseries.cpp"
588 #include "moc_qxyseries_p.cpp"
594 #include "moc_qxyseries_p.cpp"
589
595
590 QTCOMMERCIALCHART_END_NAMESPACE
596 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,520 +1,520
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 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 <QtTest/QtTest>
21 #include <QtTest/QtTest>
22 #include <qbarset.h>
22 #include <qbarset.h>
23 #include <qbarseries.h>
23 #include <qbarseries.h>
24 #include <qchartview.h>
24 #include <qchartview.h>
25 #include "tst_definitions.h"
25 #include "tst_definitions.h"
26
26
27 QTCOMMERCIALCHART_USE_NAMESPACE
27 QTCOMMERCIALCHART_USE_NAMESPACE
28
28
29 class tst_QBarSet : public QObject
29 class tst_QBarSet : public QObject
30 {
30 {
31 Q_OBJECT
31 Q_OBJECT
32
32
33 public slots:
33 public slots:
34 void initTestCase();
34 void initTestCase();
35 void cleanupTestCase();
35 void cleanupTestCase();
36 void init();
36 void init();
37 void cleanup();
37 void cleanup();
38
38
39 private slots:
39 private slots:
40 void qbarset_data();
40 void qbarset_data();
41 void qbarset();
41 void qbarset();
42 void label_data();
42 void label_data();
43 void label();
43 void label();
44 void append_data();
44 void append_data();
45 void append();
45 void append();
46 void appendOperator_data();
46 void appendOperator_data();
47 void appendOperator();
47 void appendOperator();
48 void insert_data();
48 void insert_data();
49 void insert();
49 void insert();
50 void remove_data();
50 void remove_data();
51 void remove();
51 void remove();
52 void replace_data();
52 void replace_data();
53 void replace();
53 void replace();
54 void at_data();
54 void at_data();
55 void at();
55 void at();
56 void atOperator_data();
56 void atOperator_data();
57 void atOperator();
57 void atOperator();
58 void count_data();
58 void count_data();
59 void count();
59 void count();
60 void sum_data();
60 void sum_data();
61 void sum();
61 void sum();
62 void customize();
62 void customize();
63
63
64 private:
64 private:
65 QBarSet* m_barset;
65 QBarSet* m_barset;
66 };
66 };
67
67
68 void tst_QBarSet::initTestCase()
68 void tst_QBarSet::initTestCase()
69 {
69 {
70 }
70 }
71
71
72 void tst_QBarSet::cleanupTestCase()
72 void tst_QBarSet::cleanupTestCase()
73 {
73 {
74 }
74 }
75
75
76 void tst_QBarSet::init()
76 void tst_QBarSet::init()
77 {
77 {
78 m_barset = new QBarSet(QString("label"));
78 m_barset = new QBarSet(QString("label"));
79 }
79 }
80
80
81 void tst_QBarSet::cleanup()
81 void tst_QBarSet::cleanup()
82 {
82 {
83 delete m_barset;
83 delete m_barset;
84 m_barset = 0;
84 m_barset = 0;
85 }
85 }
86
86
87 void tst_QBarSet::qbarset_data()
87 void tst_QBarSet::qbarset_data()
88 {
88 {
89 }
89 }
90
90
91 void tst_QBarSet::qbarset()
91 void tst_QBarSet::qbarset()
92 {
92 {
93 QBarSet barset(QString("label"));
93 QBarSet barset(QString("label"));
94 QCOMPARE(barset.label(), QString("label"));
94 QCOMPARE(barset.label(), QString("label"));
95 QCOMPARE(barset.count(), 0);
95 QCOMPARE(barset.count(), 0);
96 QVERIFY(qFuzzyCompare(barset.sum(), 0));
96 QVERIFY(qFuzzyCompare(barset.sum(), 0));
97 }
97 }
98
98
99 void tst_QBarSet::label_data()
99 void tst_QBarSet::label_data()
100 {
100 {
101 QTest::addColumn<QString> ("label");
101 QTest::addColumn<QString> ("label");
102 QTest::addColumn<QString> ("result");
102 QTest::addColumn<QString> ("result");
103 QTest::newRow("label0") << QString("label0") << QString("label0");
103 QTest::newRow("label0") << QString("label0") << QString("label0");
104 QTest::newRow("label1") << QString("label1") << QString("label1");
104 QTest::newRow("label1") << QString("label1") << QString("label1");
105 }
105 }
106
106
107 void tst_QBarSet::label()
107 void tst_QBarSet::label()
108 {
108 {
109 QFETCH(QString, label);
109 QFETCH(QString, label);
110 QFETCH(QString, result);
110 QFETCH(QString, result);
111
111
112 QSignalSpy labelSpy(m_barset,SIGNAL(labelChanged()));
112 QSignalSpy labelSpy(m_barset,SIGNAL(labelChanged()));
113 m_barset->setLabel(label);
113 m_barset->setLabel(label);
114 QCOMPARE(m_barset->label(), result);
114 QCOMPARE(m_barset->label(), result);
115 QVERIFY(labelSpy.count() == 1);
115 QVERIFY(labelSpy.count() == 1);
116 }
116 }
117
117
118 void tst_QBarSet::append_data()
118 void tst_QBarSet::append_data()
119 {
119 {
120 QTest::addColumn<int> ("count");
120 QTest::addColumn<int> ("count");
121 QTest::newRow("0") << 0;
121 QTest::newRow("0") << 0;
122 QTest::newRow("5") << 5;
122 QTest::newRow("5") << 5;
123 QTest::newRow("100") << 100;
123 QTest::newRow("100") << 100;
124 QTest::newRow("1000") << 1000;
124 QTest::newRow("1000") << 1000;
125 }
125 }
126
126
127 void tst_QBarSet::append()
127 void tst_QBarSet::append()
128 {
128 {
129 QFETCH(int, count);
129 QFETCH(int, count);
130
130
131 QCOMPARE(m_barset->count(), 0);
131 QCOMPARE(m_barset->count(), 0);
132 QVERIFY(qFuzzyCompare(m_barset->sum(), 0));
132 QVERIFY(qFuzzyCompare(m_barset->sum(), 0));
133
133
134 QSignalSpy valueSpy(m_barset, SIGNAL(valuesAdded(int,int)));
134 QSignalSpy valueSpy(m_barset, SIGNAL(valuesAdded(int,int)));
135
135
136 qreal sum(0.0);
136 qreal sum(0.0);
137 qreal value(0.0);
137 qreal value(0.0);
138
138
139 for (int i=0; i<count; i++) {
139 for (int i=0; i<count; i++) {
140 m_barset->append(value);
140 m_barset->append(value);
141 QCOMPARE(m_barset->at(i), value);
141 QCOMPARE(m_barset->at(i), value);
142 sum += value;
142 sum += value;
143 value += 1.0;
143 value += 1.0;
144 }
144 }
145
145
146 QCOMPARE(m_barset->count(), count);
146 QCOMPARE(m_barset->count(), count);
147 QVERIFY(qFuzzyCompare(m_barset->sum(), sum));
147 QVERIFY(qFuzzyCompare(m_barset->sum(), sum));
148
148
149 QCOMPARE(valueSpy.count(), count);
149 QCOMPARE(valueSpy.count(), count);
150 }
150 }
151
151
152 void tst_QBarSet::appendOperator_data()
152 void tst_QBarSet::appendOperator_data()
153 {
153 {
154 append_data();
154 append_data();
155 }
155 }
156
156
157 void tst_QBarSet::appendOperator()
157 void tst_QBarSet::appendOperator()
158 {
158 {
159 QFETCH(int, count);
159 QFETCH(int, count);
160
160
161 QCOMPARE(m_barset->count(), 0);
161 QCOMPARE(m_barset->count(), 0);
162 QVERIFY(qFuzzyCompare(m_barset->sum(), 0));
162 QVERIFY(qFuzzyCompare(m_barset->sum(), 0));
163
163
164 QSignalSpy valueSpy(m_barset,SIGNAL(valuesAdded(int,int)));
164 QSignalSpy valueSpy(m_barset,SIGNAL(valuesAdded(int,int)));
165
165
166 qreal sum(0.0);
166 qreal sum(0.0);
167 qreal value(0.0);
167 qreal value(0.0);
168
168
169 for (int i=0; i<count; i++) {
169 for (int i=0; i<count; i++) {
170 *m_barset << value;
170 *m_barset << value;
171 QCOMPARE(m_barset->at(i), value);
171 QCOMPARE(m_barset->at(i), value);
172 sum += value;
172 sum += value;
173 value += 1.0;
173 value += 1.0;
174 }
174 }
175
175
176 QCOMPARE(m_barset->count(), count);
176 QCOMPARE(m_barset->count(), count);
177 QVERIFY(qFuzzyCompare(m_barset->sum(), sum));
177 QVERIFY(qFuzzyCompare(m_barset->sum(), sum));
178 QCOMPARE(valueSpy.count(), count);
178 QCOMPARE(valueSpy.count(), count);
179 }
179 }
180
180
181 void tst_QBarSet::insert_data()
181 void tst_QBarSet::insert_data()
182 {
182 {
183 }
183 }
184
184
185 void tst_QBarSet::insert()
185 void tst_QBarSet::insert()
186 {
186 {
187 QCOMPARE(m_barset->count(), 0);
187 QCOMPARE(m_barset->count(), 0);
188 QVERIFY(qFuzzyCompare(m_barset->sum(), 0));
188 QVERIFY(qFuzzyCompare(m_barset->sum(), 0));
189 QSignalSpy valueSpy(m_barset,SIGNAL(valuesAdded(int,int)));
189 QSignalSpy valueSpy(m_barset,SIGNAL(valuesAdded(int,int)));
190
190
191 m_barset->insert(0, 1.0); // 1.0
191 m_barset->insert(0, 1.0); // 1.0
192 QCOMPARE(m_barset->at(0), 1.0);
192 QCOMPARE(m_barset->at(0), 1.0);
193 QCOMPARE(m_barset->count(), 1);
193 QCOMPARE(m_barset->count(), 1);
194 QVERIFY(qFuzzyCompare(m_barset->sum(), (qreal)1.0));
194 QVERIFY(qFuzzyCompare(m_barset->sum(), (qreal)1.0));
195
195
196 m_barset->insert(0, 2.0); // 2.0 1.0
196 m_barset->insert(0, 2.0); // 2.0 1.0
197 QCOMPARE(m_barset->at(0), 2.0);
197 QCOMPARE(m_barset->at(0), 2.0);
198 QCOMPARE(m_barset->at(1), 1.0);
198 QCOMPARE(m_barset->at(1), 1.0);
199 QCOMPARE(m_barset->count(), 2);
199 QCOMPARE(m_barset->count(), 2);
200 QVERIFY(qFuzzyCompare(m_barset->sum(), (qreal)3.0));
200 QVERIFY(qFuzzyCompare(m_barset->sum(), (qreal)3.0));
201
201
202 m_barset->insert(1, 3.0); // 2.0 3.0 1.0
202 m_barset->insert(1, 3.0); // 2.0 3.0 1.0
203 QCOMPARE(m_barset->at(1), 3.0);
203 QCOMPARE(m_barset->at(1), 3.0);
204 QCOMPARE(m_barset->at(0), 2.0);
204 QCOMPARE(m_barset->at(0), 2.0);
205 QCOMPARE(m_barset->at(2), 1.0);
205 QCOMPARE(m_barset->at(2), 1.0);
206 QCOMPARE(m_barset->count(), 3);
206 QCOMPARE(m_barset->count(), 3);
207 QVERIFY(qFuzzyCompare(m_barset->sum(), (qreal)6.0));
207 QVERIFY(qFuzzyCompare(m_barset->sum(), (qreal)6.0));
208 QCOMPARE(valueSpy.count(), 3);
208 QCOMPARE(valueSpy.count(), 3);
209 }
209 }
210
210
211 void tst_QBarSet::remove_data()
211 void tst_QBarSet::remove_data()
212 {
212 {
213 }
213 }
214
214
215 void tst_QBarSet::remove()
215 void tst_QBarSet::remove()
216 {
216 {
217 QCOMPARE(m_barset->count(), 0);
217 QCOMPARE(m_barset->count(), 0);
218 QVERIFY(qFuzzyCompare(m_barset->sum(), 0));
218 QVERIFY(qFuzzyCompare(m_barset->sum(), 0));
219
219
220 QSignalSpy valueSpy(m_barset,SIGNAL(valuesRemoved(int,int)));
220 QSignalSpy valueSpy(m_barset,SIGNAL(valuesRemoved(int,int)));
221
221
222 m_barset->append(1.0);
222 m_barset->append(1.0);
223 m_barset->append(2.0);
223 m_barset->append(2.0);
224 m_barset->append(3.0);
224 m_barset->append(3.0);
225 m_barset->append(4.0);
225 m_barset->append(4.0);
226
226
227 QCOMPARE(m_barset->count(), 4);
227 QCOMPARE(m_barset->count(), 4);
228 QCOMPARE(m_barset->sum(), 10.0);
228 QCOMPARE(m_barset->sum(), 10.0);
229
229
230 // Remove middle
230 // Remove middle
231 m_barset->remove(2); // 1.0 2.0 4.0
231 m_barset->remove(2); // 1.0 2.0 4.0
232 QCOMPARE(m_barset->at(0), 1.0);
232 QCOMPARE(m_barset->at(0), 1.0);
233 QCOMPARE(m_barset->at(1), 2.0);
233 QCOMPARE(m_barset->at(1), 2.0);
234 QCOMPARE(m_barset->at(2), 4.0);
234 QCOMPARE(m_barset->at(2), 4.0);
235 QCOMPARE(m_barset->count(), 3);
235 QCOMPARE(m_barset->count(), 3);
236 QCOMPARE(m_barset->sum(), 7.0);
236 QCOMPARE(m_barset->sum(), 7.0);
237 QCOMPARE(valueSpy.count(), 1);
237 QCOMPARE(valueSpy.count(), 1);
238
238
239 QList<QVariant> valueSpyArg = valueSpy.takeFirst();
239 QList<QVariant> valueSpyArg = valueSpy.takeFirst();
240 // Verify index of removed signal
240 // Verify index of removed signal
241 QVERIFY(valueSpyArg.at(0).type() == QVariant::Int);
241 QVERIFY(valueSpyArg.at(0).type() == QVariant::Int);
242 QVERIFY(valueSpyArg.at(0).toInt() == 2);
242 QVERIFY(valueSpyArg.at(0).toInt() == 2);
243 // Verify count of removed signal
243 // Verify count of removed signal
244 QVERIFY(valueSpyArg.at(1).type() == QVariant::Int);
244 QVERIFY(valueSpyArg.at(1).type() == QVariant::Int);
245 QVERIFY(valueSpyArg.at(1).toInt() == 1);
245 QVERIFY(valueSpyArg.at(1).toInt() == 1);
246
246
247 // Remove first
247 // Remove first
248 m_barset->remove(0); // 2.0 4.0
248 m_barset->remove(0); // 2.0 4.0
249 QCOMPARE(m_barset->at(0), 2.0);
249 QCOMPARE(m_barset->at(0), 2.0);
250 QCOMPARE(m_barset->at(1), 4.0);
250 QCOMPARE(m_barset->at(1), 4.0);
251 QCOMPARE(m_barset->count(), 2);
251 QCOMPARE(m_barset->count(), 2);
252 QCOMPARE(m_barset->sum(), 6.0);
252 QCOMPARE(m_barset->sum(), 6.0);
253
253
254 QCOMPARE(valueSpy.count(), 1);
254 QCOMPARE(valueSpy.count(), 1);
255 valueSpyArg = valueSpy.takeFirst();
255 valueSpyArg = valueSpy.takeFirst();
256 // Verify index of removed signal
256 // Verify index of removed signal
257 QVERIFY(valueSpyArg.at(0).type() == QVariant::Int);
257 QVERIFY(valueSpyArg.at(0).type() == QVariant::Int);
258 QVERIFY(valueSpyArg.at(0).toInt() == 0);
258 QVERIFY(valueSpyArg.at(0).toInt() == 0);
259 // Verify count of removed signal
259 // Verify count of removed signal
260 QVERIFY(valueSpyArg.at(1).type() == QVariant::Int);
260 QVERIFY(valueSpyArg.at(1).type() == QVariant::Int);
261 QVERIFY(valueSpyArg.at(1).toInt() == 1);
261 QVERIFY(valueSpyArg.at(1).toInt() == 1);
262
262
263
263
264 // Illegal indexes
264 // Illegal indexes
265 m_barset->remove(4);
265 m_barset->remove(4);
266 QCOMPARE(m_barset->count(), 2);
266 QCOMPARE(m_barset->count(), 2);
267 QCOMPARE(m_barset->sum(), 6.0);
267 QCOMPARE(m_barset->sum(), 6.0);
268 m_barset->remove(-1);
268 m_barset->remove(-1);
269 QCOMPARE(m_barset->count(), 2);
269 QCOMPARE(m_barset->count(), 2);
270 QCOMPARE(m_barset->sum(), 6.0);
270 QCOMPARE(m_barset->sum(), 6.0);
271
271
272 // nothing removed, no signals should be emitted
272 // nothing removed, no signals should be emitted
273 QCOMPARE(valueSpy.count(), 0);
273 QCOMPARE(valueSpy.count(), 0);
274
274
275 // Remove more items than list has
275 // Remove more items than list has
276 m_barset->remove(0,312);
276 m_barset->remove(0,312);
277 QCOMPARE(m_barset->count(), 0);
277 QCOMPARE(m_barset->count(), 0);
278 QVERIFY(qFuzzyCompare(m_barset->sum(), 0));
278 QVERIFY(qFuzzyCompare(m_barset->sum(), 0));
279
279
280 QCOMPARE(valueSpy.count(), 1);
280 QCOMPARE(valueSpy.count(), 1);
281 valueSpyArg = valueSpy.takeFirst();
281 valueSpyArg = valueSpy.takeFirst();
282
282
283 // Verify index of removed signal
283 // Verify index of removed signal
284 QVERIFY(valueSpyArg.at(0).type() == QVariant::Int);
284 QVERIFY(valueSpyArg.at(0).type() == QVariant::Int);
285 QVERIFY(valueSpyArg.at(0).toInt() == 0);
285 QVERIFY(valueSpyArg.at(0).toInt() == 0);
286 // Verify count of removed signal (expect 2 values removed, because list had only 2 items)
286 // Verify count of removed signal (expect 2 values removed, because list had only 2 items)
287 QVERIFY(valueSpyArg.at(1).type() == QVariant::Int);
287 QVERIFY(valueSpyArg.at(1).type() == QVariant::Int);
288 QVERIFY(valueSpyArg.at(1).toInt() == 2);
288 QVERIFY(valueSpyArg.at(1).toInt() == 2);
289 }
289 }
290
290
291 void tst_QBarSet::replace_data()
291 void tst_QBarSet::replace_data()
292 {
292 {
293
293
294 }
294 }
295
295
296 void tst_QBarSet::replace()
296 void tst_QBarSet::replace()
297 {
297 {
298 QCOMPARE(m_barset->count(), 0);
298 QCOMPARE(m_barset->count(), 0);
299 QVERIFY(qFuzzyCompare(m_barset->sum(), 0));
299 QVERIFY(qFuzzyCompare(m_barset->sum(), 0));
300 QSignalSpy valueSpy(m_barset,SIGNAL(valueChanged(int)));
300 QSignalSpy valueSpy(m_barset,SIGNAL(valueChanged(int)));
301
301
302 m_barset->append(1.0);
302 m_barset->append(1.0);
303 m_barset->append(2.0);
303 m_barset->append(2.0);
304 m_barset->append(3.0);
304 m_barset->append(3.0);
305 m_barset->append(4.0);
305 m_barset->append(4.0);
306
306
307 QCOMPARE(m_barset->count(), 4);
307 QCOMPARE(m_barset->count(), 4);
308 QCOMPARE(m_barset->sum(), 10.0);
308 QCOMPARE(m_barset->sum(), 10.0);
309
309
310 // Replace first
310 // Replace first
311 m_barset->replace(0, 5.0); // 5.0 2.0 3.0 4.0
311 m_barset->replace(0, 5.0); // 5.0 2.0 3.0 4.0
312 QCOMPARE(m_barset->count(), 4);
312 QCOMPARE(m_barset->count(), 4);
313 QCOMPARE(m_barset->sum(), 14.0);
313 QCOMPARE(m_barset->sum(), 14.0);
314 QCOMPARE(m_barset->at(0), 5.0);
314 QCOMPARE(m_barset->at(0), 5.0);
315
315
316 // Replace last
316 // Replace last
317 m_barset->replace(3, 6.0);
317 m_barset->replace(3, 6.0);
318 QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0
318 QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0
319 QCOMPARE(m_barset->sum(), 16.0);
319 QCOMPARE(m_barset->sum(), 16.0);
320 QCOMPARE(m_barset->at(0), 5.0);
320 QCOMPARE(m_barset->at(0), 5.0);
321 QCOMPARE(m_barset->at(1), 2.0);
321 QCOMPARE(m_barset->at(1), 2.0);
322 QCOMPARE(m_barset->at(2), 3.0);
322 QCOMPARE(m_barset->at(2), 3.0);
323 QCOMPARE(m_barset->at(3), 6.0);
323 QCOMPARE(m_barset->at(3), 6.0);
324
324
325 // Illegal indexes
325 // Illegal indexes
326 m_barset->replace(4, 6.0);
326 m_barset->replace(4, 6.0);
327 QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0
327 QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0
328 QCOMPARE(m_barset->sum(), 16.0);
328 QCOMPARE(m_barset->sum(), 16.0);
329 m_barset->replace(-1, 6.0);
329 m_barset->replace(-1, 6.0);
330 QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0
330 QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0
331 QCOMPARE(m_barset->sum(), 16.0);
331 QCOMPARE(m_barset->sum(), 16.0);
332 m_barset->replace(4, 1.0);
332 m_barset->replace(4, 1.0);
333 QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0
333 QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0
334 QCOMPARE(m_barset->sum(), 16.0);
334 QCOMPARE(m_barset->sum(), 16.0);
335 m_barset->replace(-1, 1.0);
335 m_barset->replace(-1, 1.0);
336 QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0
336 QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0
337 QCOMPARE(m_barset->sum(), 16.0);
337 QCOMPARE(m_barset->sum(), 16.0);
338
338
339 QVERIFY(valueSpy.count() == 2);
339 QVERIFY(valueSpy.count() == 2);
340 }
340 }
341
341
342 void tst_QBarSet::at_data()
342 void tst_QBarSet::at_data()
343 {
343 {
344
344
345 }
345 }
346
346
347 void tst_QBarSet::at()
347 void tst_QBarSet::at()
348 {
348 {
349 QCOMPARE(m_barset->count(), 0);
349 QCOMPARE(m_barset->count(), 0);
350 QVERIFY(qFuzzyCompare(m_barset->sum(), 0));
350 QVERIFY(qFuzzyCompare(m_barset->sum(), 0));
351
351
352 m_barset->append(1.0);
352 m_barset->append(1.0);
353 m_barset->append(2.0);
353 m_barset->append(2.0);
354 m_barset->append(3.0);
354 m_barset->append(3.0);
355 m_barset->append(4.0);
355 m_barset->append(4.0);
356
356
357 QCOMPARE(m_barset->at(0), 1.0);
357 QCOMPARE(m_barset->at(0), 1.0);
358 QCOMPARE(m_barset->at(1), 2.0);
358 QCOMPARE(m_barset->at(1), 2.0);
359 QCOMPARE(m_barset->at(2), 3.0);
359 QCOMPARE(m_barset->at(2), 3.0);
360 QCOMPARE(m_barset->at(3), 4.0);
360 QCOMPARE(m_barset->at(3), 4.0);
361 }
361 }
362
362
363 void tst_QBarSet::atOperator_data()
363 void tst_QBarSet::atOperator_data()
364 {
364 {
365
365
366 }
366 }
367
367
368 void tst_QBarSet::atOperator()
368 void tst_QBarSet::atOperator()
369 {
369 {
370 QCOMPARE(m_barset->count(), 0);
370 QCOMPARE(m_barset->count(), 0);
371 QVERIFY(qFuzzyCompare(m_barset->sum(), 0));
371 QVERIFY(qFuzzyCompare(m_barset->sum(), 0));
372
372
373 m_barset->append(1.0);
373 m_barset->append(1.0);
374 m_barset->append(2.0);
374 m_barset->append(2.0);
375 m_barset->append(3.0);
375 m_barset->append(3.0);
376 m_barset->append(4.0);
376 m_barset->append(4.0);
377
377
378 QCOMPARE(m_barset->operator [](0), 1.0);
378 QCOMPARE(m_barset->operator [](0), 1.0);
379 QCOMPARE(m_barset->operator [](1), 2.0);
379 QCOMPARE(m_barset->operator [](1), 2.0);
380 QCOMPARE(m_barset->operator [](2), 3.0);
380 QCOMPARE(m_barset->operator [](2), 3.0);
381 QCOMPARE(m_barset->operator [](3), 4.0);
381 QCOMPARE(m_barset->operator [](3), 4.0);
382 }
382 }
383
383
384 void tst_QBarSet::count_data()
384 void tst_QBarSet::count_data()
385 {
385 {
386
386
387 }
387 }
388
388
389 void tst_QBarSet::count()
389 void tst_QBarSet::count()
390 {
390 {
391 QCOMPARE(m_barset->count(), 0);
391 QCOMPARE(m_barset->count(), 0);
392 QVERIFY(qFuzzyCompare(m_barset->sum(), 0));
392 QVERIFY(qFuzzyCompare(m_barset->sum(), 0));
393
393
394 m_barset->append(1.0);
394 m_barset->append(1.0);
395 QCOMPARE(m_barset->count(),1);
395 QCOMPARE(m_barset->count(),1);
396 m_barset->append(2.0);
396 m_barset->append(2.0);
397 QCOMPARE(m_barset->count(),2);
397 QCOMPARE(m_barset->count(),2);
398 m_barset->append(3.0);
398 m_barset->append(3.0);
399 QCOMPARE(m_barset->count(),3);
399 QCOMPARE(m_barset->count(),3);
400 m_barset->append(4.0);
400 m_barset->append(4.0);
401 QCOMPARE(m_barset->count(),4);
401 QCOMPARE(m_barset->count(),4);
402 }
402 }
403
403
404 void tst_QBarSet::sum_data()
404 void tst_QBarSet::sum_data()
405 {
405 {
406
406
407 }
407 }
408
408
409 void tst_QBarSet::sum()
409 void tst_QBarSet::sum()
410 {
410 {
411 QCOMPARE(m_barset->count(), 0);
411 QCOMPARE(m_barset->count(), 0);
412 QVERIFY(qFuzzyCompare(m_barset->sum(), 0));
412 QVERIFY(qFuzzyCompare(m_barset->sum(), 0));
413
413
414 m_barset->append(1.0);
414 m_barset->append(1.0);
415 QVERIFY(qFuzzyCompare(m_barset->sum(), (qreal)1.0));
415 QVERIFY(qFuzzyCompare(m_barset->sum(), (qreal)1.0));
416 m_barset->append(2.0);
416 m_barset->append(2.0);
417 QVERIFY(qFuzzyCompare(m_barset->sum(), (qreal)3.0));
417 QVERIFY(qFuzzyCompare(m_barset->sum(), (qreal)3.0));
418 m_barset->append(3.0);
418 m_barset->append(3.0);
419 QVERIFY(qFuzzyCompare(m_barset->sum(), (qreal)6.0));
419 QVERIFY(qFuzzyCompare(m_barset->sum(), (qreal)6.0));
420 m_barset->append(4.0);
420 m_barset->append(4.0);
421 QVERIFY(qFuzzyCompare(m_barset->sum(), (qreal)10.0));
421 QVERIFY(qFuzzyCompare(m_barset->sum(), (qreal)10.0));
422 }
422 }
423
423
424 void tst_QBarSet::customize()
424 void tst_QBarSet::customize()
425 {
425 {
426 // Create sets
426 // Create sets
427 QBarSet *set1 = new QBarSet("set1");
427 QBarSet *set1 = new QBarSet("set1");
428 QBarSet *set2 = new QBarSet("set2");
428 QBarSet *set2 = new QBarSet("set2");
429
429
430 // Append set1 to series
430 // Append set1 to series
431 QBarSeries *series = new QBarSeries();
431 QBarSeries *series = new QBarSeries();
432 bool success = series->append(set1);
432 bool success = series->append(set1);
433 QVERIFY(success);
433 QVERIFY(success);
434
434
435 // Add series to the chart
435 // Add series to the chart
436 QChartView view(new QChart());
436 QChartView view(new QChart());
437 view.resize(200, 200);
437 view.resize(200, 200);
438 view.chart()->addSeries(series);
438 view.chart()->addSeries(series);
439 view.show();
439 view.show();
440 QTest::qWaitForWindowShown(&view);
440 QTest::qWaitForWindowShown(&view);
441
441
442 // Test adding data to the sets
442 // Test adding data to the sets
443 *set1 << 1 << 2 << 1 << 3;
443 *set1 << 1 << 2 << 1 << 3;
444 *set2 << 2 << 1 << 3 << 1;
444 *set2 << 2 << 1 << 3 << 1;
445
445
446 // Remove sets from series
446 // Remove sets from series
447 series->take(set1);
447 series->take(set1);
448 series->take(set2);
448 series->take(set2);
449
449
450 // Test pen
450 // Test pen
451 QVERIFY(set1->pen() != QPen());
451 QVERIFY(set1->pen() != QPen());
452 QVERIFY(set2->pen() == QPen());
452 QVERIFY(set2->pen() == QPen());
453 QPen pen(QColor(128,128,128,128));
453 QPen pen(QColor(128,128,128,128));
454 set1->setPen(pen);
454 set1->setPen(pen);
455
455
456 // Add sets back to series
456 // Add sets back to series
457 series->append(set1);
457 series->append(set1);
458 series->append(set2);
458 series->append(set2);
459
459
460 QVERIFY(set1->pen() == pen); // Should be customized
460 QVERIFY(set1->pen() == pen); // Should be customized
461 QVERIFY(set2->pen() != QPen()); // Should be decorated by theme
461 QVERIFY(set2->pen() != QPen()); // Should be decorated by theme
462
462
463 // Remove sets from series
463 // Remove sets from series
464 series->take(set1);
464 series->take(set1);
465 series->take(set2);
465 series->take(set2);
466
466
467 // Test brush
467 // Test brush
468 set2->setBrush(QBrush());
468 set2->setBrush(QBrush());
469 QVERIFY(set1->brush() != QBrush());
469 QVERIFY(set1->brush() != QBrush());
470 QVERIFY(set2->brush() == QBrush());
470 QVERIFY(set2->brush() == QBrush());
471 QBrush brush(QColor(128,128,128,128));
471 QBrush brush(QColor(128,128,128,128));
472 set1->setBrush(brush);
472 set1->setBrush(brush);
473
473
474 // Add sets back to series
474 // Add sets back to series
475 series->append(set1);
475 series->append(set1);
476 series->append(set2);
476 series->append(set2);
477
477
478 QVERIFY(set1->brush() == brush); // Should be customized
478 QVERIFY(set1->brush() == brush); // Should be customized
479 QVERIFY(set2->brush() != QBrush()); // Should be decorated by theme
479 QVERIFY(set2->brush() == QBrush()); // Setting empty brush doesn't reset to theme brush
480
480
481 // Remove sets from series
481 // Remove sets from series
482 series->take(set1);
482 series->take(set1);
483 series->take(set2);
483 series->take(set2);
484
484
485 // Test label brush
485 // Test label brush
486 set2->setLabelBrush(QBrush());
486 set2->setLabelBrush(QBrush());
487 QVERIFY(set1->labelBrush() != QBrush());
487 QVERIFY(set1->labelBrush() != QBrush());
488 QVERIFY(set2->labelBrush() == QBrush());
488 QVERIFY(set2->labelBrush() == QBrush());
489 set1->setLabelBrush(brush);
489 set1->setLabelBrush(brush);
490
490
491 series->append(set1);
491 series->append(set1);
492 series->append(set2);
492 series->append(set2);
493 QVERIFY(set1->labelBrush() == brush); // Should be customized
493 QVERIFY(set1->labelBrush() == brush); // Should be customized
494 QVERIFY(set2->labelBrush() != QBrush()); // Should be decorated by theme
494 QVERIFY(set2->labelBrush() == QBrush()); // Setting empty brush doesn't reset to theme brush
495
495
496 // Test label font
496 // Test label font
497 // Note: QFont empty constructor creates font with application's default font, so the font may or may not be the
497 // Note: QFont empty constructor creates font with application's default font, so the font may or may not be the
498 // same for the set added to the series (depending on the QChart's theme configuration)
498 // same for the set added to the series (depending on the QChart's theme configuration)
499 QVERIFY(set1->labelFont() != QFont() || set1->labelFont() == QFont());
499 QVERIFY(set1->labelFont() != QFont() || set1->labelFont() == QFont());
500 QVERIFY(set2->labelFont() == QFont());
500 QVERIFY(set2->labelFont() == QFont());
501 QFont font;
501 QFont font;
502 font.setBold(true);
502 font.setBold(true);
503 font.setItalic(true);
503 font.setItalic(true);
504 set1->setLabelFont(font);
504 set1->setLabelFont(font);
505 QVERIFY(set1->labelFont() == font);
505 QVERIFY(set1->labelFont() == font);
506 QVERIFY(set2->labelFont() == QFont());
506 QVERIFY(set2->labelFont() == QFont());
507
507
508 // Test adding data to the sets
508 // Test adding data to the sets
509 *set1 << 1 << 2 << 1 << 3;
509 *set1 << 1 << 2 << 1 << 3;
510 *set2 << 2 << 1 << 3 << 1;
510 *set2 << 2 << 1 << 3 << 1;
511
511
512 }
512 }
513
513
514
514
515
515
516
516
517 QTEST_MAIN(tst_QBarSet)
517 QTEST_MAIN(tst_QBarSet)
518
518
519 #include "tst_qbarset.moc"
519 #include "tst_qbarset.moc"
520
520
General Comments 0
You need to be logged in to leave comments. Login now