##// END OF EJS Templates
Fix explicitly set default pen/brush/font getting overridden by theme...
Miikka Heikkinen -
r2516:567bb8091928
parent child
Show More
@@ -1,452 +1,453
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 return d->m_pen;
256 }
256 }
257
257
258 /*!
258 /*!
259 Sets \a brush used for filling the area.
259 Sets \a brush used for filling the area.
260 */
260 */
261 void QAreaSeries::setBrush(const QBrush &brush)
261 void QAreaSeries::setBrush(const QBrush &brush)
262 {
262 {
263 Q_D(QAreaSeries);
263 Q_D(QAreaSeries);
264 if (d->m_brush != brush) {
264 if (d->m_brush != brush) {
265 bool emitColorChanged = brush.color() != d->m_brush.color();
265 bool emitColorChanged = brush.color() != d->m_brush.color();
266 d->m_brush = brush;
266 d->m_brush = brush;
267 emit d->updated();
267 emit d->updated();
268 if (emitColorChanged)
268 if (emitColorChanged)
269 emit colorChanged(brush.color());
269 emit colorChanged(brush.color());
270 }
270 }
271 }
271 }
272
272
273 QBrush QAreaSeries::brush() const
273 QBrush QAreaSeries::brush() const
274 {
274 {
275 Q_D(const QAreaSeries);
275 Q_D(const QAreaSeries);
276 return d->m_brush;
276 return d->m_brush;
277 }
277 }
278
278
279 void QAreaSeries::setColor(const QColor &color)
279 void QAreaSeries::setColor(const QColor &color)
280 {
280 {
281 QBrush b = brush();
281 QBrush b = brush();
282 if (b == QBrush())
282 if (b == QBrush())
283 b.setStyle(Qt::SolidPattern);
283 b.setStyle(Qt::SolidPattern);
284 b.setColor(color);
284 b.setColor(color);
285 setBrush(b);
285 setBrush(b);
286 }
286 }
287
287
288 QColor QAreaSeries::color() const
288 QColor QAreaSeries::color() const
289 {
289 {
290 return brush().color();
290 return brush().color();
291 }
291 }
292
292
293 void QAreaSeries::setBorderColor(const QColor &color)
293 void QAreaSeries::setBorderColor(const QColor &color)
294 {
294 {
295 QPen p = pen();
295 QPen p = pen();
296 if (p.color() != color) {
296 if (p.color() != color) {
297 p.setColor(color);
297 p.setColor(color);
298 setPen(p);
298 setPen(p);
299 emit borderColorChanged(color);
299 emit borderColorChanged(color);
300 }
300 }
301 }
301 }
302
302
303 QColor QAreaSeries::borderColor() const
303 QColor QAreaSeries::borderColor() const
304 {
304 {
305 return pen().color();
305 return pen().color();
306 }
306 }
307
307
308 /*!
308 /*!
309 Sets if data points are \a visible and should be drawn on line.
309 Sets if data points are \a visible and should be drawn on line.
310 */
310 */
311 void QAreaSeries::setPointsVisible(bool visible)
311 void QAreaSeries::setPointsVisible(bool visible)
312 {
312 {
313 Q_D(QAreaSeries);
313 Q_D(QAreaSeries);
314 if (d->m_pointsVisible != visible) {
314 if (d->m_pointsVisible != visible) {
315 d->m_pointsVisible = visible;
315 d->m_pointsVisible = visible;
316 emit d->updated();
316 emit d->updated();
317 }
317 }
318 }
318 }
319
319
320 /*!
320 /*!
321 Returns if the points are drawn for this series.
321 Returns if the points are drawn for this series.
322 \sa setPointsVisible()
322 \sa setPointsVisible()
323 */
323 */
324 bool QAreaSeries::pointsVisible() const
324 bool QAreaSeries::pointsVisible() const
325 {
325 {
326 Q_D(const QAreaSeries);
326 Q_D(const QAreaSeries);
327 return d->m_pointsVisible;
327 return d->m_pointsVisible;
328 }
328 }
329
329
330 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
330 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
331
331
332 QAreaSeriesPrivate::QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries, QAreaSeries *q)
332 QAreaSeriesPrivate::QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries, QAreaSeries *q)
333 : QAbstractSeriesPrivate(q),
333 : QAbstractSeriesPrivate(q),
334 m_brush(QChartPrivate::defaultBrush()),
335 m_pen(QChartPrivate::defaultPen()),
334 m_upperSeries(upperSeries),
336 m_upperSeries(upperSeries),
335 m_lowerSeries(lowerSeries),
337 m_lowerSeries(lowerSeries),
336 m_pointsVisible(false)
338 m_pointsVisible(false)
337 {
339 {
338 }
340 }
339
341
340 void QAreaSeriesPrivate::initializeDomain()
342 void QAreaSeriesPrivate::initializeDomain()
341 {
343 {
342 Q_Q(QAreaSeries);
344 Q_Q(QAreaSeries);
343
345
344 qreal minX(domain()->minX());
346 qreal minX(domain()->minX());
345 qreal minY(domain()->minY());
347 qreal minY(domain()->minY());
346 qreal maxX(domain()->maxX());
348 qreal maxX(domain()->maxX());
347 qreal maxY(domain()->maxY());
349 qreal maxY(domain()->maxY());
348
350
349 QLineSeries *upperSeries = q->upperSeries();
351 QLineSeries *upperSeries = q->upperSeries();
350 QLineSeries *lowerSeries = q->lowerSeries();
352 QLineSeries *lowerSeries = q->lowerSeries();
351
353
352 const QList<QPointF>& points = upperSeries->points();
354 const QList<QPointF>& points = upperSeries->points();
353
355
354 for (int i = 0; i < points.count(); i++) {
356 for (int i = 0; i < points.count(); i++) {
355 qreal x = points[i].x();
357 qreal x = points[i].x();
356 qreal y = points[i].y();
358 qreal y = points[i].y();
357 minX = qMin(minX, x);
359 minX = qMin(minX, x);
358 minY = qMin(minY, y);
360 minY = qMin(minY, y);
359 maxX = qMax(maxX, x);
361 maxX = qMax(maxX, x);
360 maxY = qMax(maxY, y);
362 maxY = qMax(maxY, y);
361 }
363 }
362 if (lowerSeries) {
364 if (lowerSeries) {
363
365
364 const QList<QPointF>& points = lowerSeries->points();
366 const QList<QPointF>& points = lowerSeries->points();
365
367
366 for (int i = 0; i < points.count(); i++) {
368 for (int i = 0; i < points.count(); i++) {
367 qreal x = points[i].x();
369 qreal x = points[i].x();
368 qreal y = points[i].y();
370 qreal y = points[i].y();
369 minX = qMin(minX, x);
371 minX = qMin(minX, x);
370 minY = qMin(minY, y);
372 minY = qMin(minY, y);
371 maxX = qMax(maxX, x);
373 maxX = qMax(maxX, x);
372 maxY = qMax(maxY, y);
374 maxY = qMax(maxY, y);
373 }
375 }
374 }
376 }
375
377
376 domain()->setRange(minX, maxX, minY, maxY);
378 domain()->setRange(minX, maxX, minY, maxY);
377 }
379 }
378
380
379 void QAreaSeriesPrivate::initializeGraphics(QGraphicsItem* parent)
381 void QAreaSeriesPrivate::initializeGraphics(QGraphicsItem* parent)
380 {
382 {
381 Q_Q(QAreaSeries);
383 Q_Q(QAreaSeries);
382 AreaChartItem *area = new AreaChartItem(q,parent);
384 AreaChartItem *area = new AreaChartItem(q,parent);
383 m_item.reset(area);
385 m_item.reset(area);
384 QAbstractSeriesPrivate::initializeGraphics(parent);
386 QAbstractSeriesPrivate::initializeGraphics(parent);
385 }
387 }
386 void QAreaSeriesPrivate::initializeAnimations(QChart::AnimationOptions options)
388 void QAreaSeriesPrivate::initializeAnimations(QChart::AnimationOptions options)
387 {
389 {
388 Q_Q(QAreaSeries);
390 Q_Q(QAreaSeries);
389 AreaChartItem *area = static_cast<AreaChartItem *>(m_item.data());
391 AreaChartItem *area = static_cast<AreaChartItem *>(m_item.data());
390 if (options.testFlag(QChart::SeriesAnimations)) {
392 if (options.testFlag(QChart::SeriesAnimations)) {
391 area->upperLineItem()->setAnimation(new XYAnimation(area->upperLineItem()));
393 area->upperLineItem()->setAnimation(new XYAnimation(area->upperLineItem()));
392 if (q->lowerSeries())
394 if (q->lowerSeries())
393 area->lowerLineItem()->setAnimation(new XYAnimation(area->lowerLineItem()));
395 area->lowerLineItem()->setAnimation(new XYAnimation(area->lowerLineItem()));
394 }else{
396 }else{
395 area->upperLineItem()->setAnimation(0);
397 area->upperLineItem()->setAnimation(0);
396 if (q->lowerSeries())
398 if (q->lowerSeries())
397 area->lowerLineItem()->setAnimation(0);
399 area->lowerLineItem()->setAnimation(0);
398 }
400 }
399 QAbstractSeriesPrivate::initializeAnimations(options);
401 QAbstractSeriesPrivate::initializeAnimations(options);
400 }
402 }
401
403
402 QList<QLegendMarker*> QAreaSeriesPrivate::createLegendMarkers(QLegend* legend)
404 QList<QLegendMarker*> QAreaSeriesPrivate::createLegendMarkers(QLegend* legend)
403 {
405 {
404 Q_Q(QAreaSeries);
406 Q_Q(QAreaSeries);
405 QList<QLegendMarker*> list;
407 QList<QLegendMarker*> list;
406 return list << new QAreaLegendMarker(q,legend);
408 return list << new QAreaLegendMarker(q,legend);
407 }
409 }
408
410
409
411
410 void QAreaSeriesPrivate::initializeAxes()
412 void QAreaSeriesPrivate::initializeAxes()
411 {
413 {
412
414
413 }
415 }
414
416
415 QAbstractAxis::AxisType QAreaSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
417 QAbstractAxis::AxisType QAreaSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
416 {
418 {
417 Q_UNUSED(orientation);
419 Q_UNUSED(orientation);
418 return QAbstractAxis::AxisTypeValue;
420 return QAbstractAxis::AxisTypeValue;
419 }
421 }
420
422
421 QAbstractAxis* QAreaSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const
423 QAbstractAxis* QAreaSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const
422 {
424 {
423 Q_UNUSED(orientation);
425 Q_UNUSED(orientation);
424 return 0;
426 return 0;
425 }
427 }
426
428
427 void QAreaSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced)
429 void QAreaSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced)
428 {
430 {
429 Q_Q(QAreaSeries);
431 Q_Q(QAreaSeries);
430 QPen pen;
431 QBrush brush;
432
432
433 const QList<QGradient> gradients = theme->seriesGradients();
433 const QList<QGradient> gradients = theme->seriesGradients();
434 const QList<QColor> colors = theme->seriesColors();
434 const QList<QColor> colors = theme->seriesColors();
435
435
436 if (forced || pen == m_pen) {
436 if (forced || QChartPrivate::defaultPen() == m_pen) {
437 QPen pen;
437 pen.setColor(ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.0));
438 pen.setColor(ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.0));
438 pen.setWidthF(2);
439 pen.setWidthF(2);
439 q->setPen(pen);
440 q->setPen(pen);
440 }
441 }
441
442
442 if (forced || brush == m_brush) {
443 if (forced || QChartPrivate::defaultBrush() == m_brush) {
443 QBrush brush(colors.at(index % colors.size()));
444 QBrush brush(colors.at(index % colors.size()));
444 q->setBrush(brush);
445 q->setBrush(brush);
445 }
446 }
446 }
447 }
447
448
448
449
449 #include "moc_qareaseries.cpp"
450 #include "moc_qareaseries.cpp"
450 #include "moc_qareaseries_p.cpp"
451 #include "moc_qareaseries_p.cpp"
451
452
452 QTCOMMERCIALCHART_END_NAMESPACE
453 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,999 +1,990
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
26
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
28
28 /*!
29 /*!
29 \class QAbstractAxis
30 \class QAbstractAxis
30 \brief The QAbstractAxis class is used for manipulating chart's axis.
31 \brief The QAbstractAxis class is used for manipulating chart's axis.
31 \mainclass
32 \mainclass
32
33
33 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
34 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
35 QValueAxis and QLogValueAxis on the same orientation.
36 QValueAxis and QLogValueAxis on the same orientation.
36
37
37 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,
38 and shades can be individually controlled.
39 and shades can be individually controlled.
39 */
40 */
40
41
41 /*!
42 /*!
42 \qmlclass AbstractAxis QAbstractAxis
43 \qmlclass AbstractAxis QAbstractAxis
43 \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
44
45
45 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.
46
47
47 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,
48 and shades can be individually controlled.
49 and shades can be individually controlled.
49 */
50 */
50
51
51 /*!
52 /*!
52 \enum QAbstractAxis::AxisType
53 \enum QAbstractAxis::AxisType
53
54
54 The type of the series object.
55 The type of the series object.
55
56
56 \value AxisTypeNoAxis
57 \value AxisTypeNoAxis
57 \value AxisTypeValue
58 \value AxisTypeValue
58 \value AxisTypeBarCategory
59 \value AxisTypeBarCategory
59 \value AxisTypeCategory
60 \value AxisTypeCategory
60 \value AxisTypeDateTime
61 \value AxisTypeDateTime
61 \value AxisTypeLogValue
62 \value AxisTypeLogValue
62 */
63 */
63
64
64 /*!
65 /*!
65 *\fn void QAbstractAxis::type() const
66 *\fn void QAbstractAxis::type() const
66 Returns the type of the axis
67 Returns the type of the axis
67 */
68 */
68
69
69 /*!
70 /*!
70 \property QAbstractAxis::lineVisible
71 \property QAbstractAxis::lineVisible
71 The visibility of the axis line
72 The visibility of the axis line
72 */
73 */
73 /*!
74 /*!
74 \qmlproperty bool AbstractAxis::lineVisible
75 \qmlproperty bool AbstractAxis::lineVisible
75 The visibility of the axis line
76 The visibility of the axis line
76 */
77 */
77
78
78 /*!
79 /*!
79 \property QAbstractAxis::linePen
80 \property QAbstractAxis::linePen
80 The pen of the line.
81 The pen of the line.
81 */
82 */
82
83
83 /*!
84 /*!
84 \property QAbstractAxis::labelsVisible
85 \property QAbstractAxis::labelsVisible
85 Defines if axis labels are visible.
86 Defines if axis labels are visible.
86 */
87 */
87 /*!
88 /*!
88 \qmlproperty bool AbstractAxis::labelsVisible
89 \qmlproperty bool AbstractAxis::labelsVisible
89 Defines if axis labels are visible.
90 Defines if axis labels are visible.
90 */
91 */
91
92
92 /*!
93 /*!
93 \property QAbstractAxis::labelsPen
94 \property QAbstractAxis::labelsPen
94 The pen of the labels.
95 The pen of the labels.
95 */
96 */
96
97
97 /*!
98 /*!
98 \property QAbstractAxis::labelsBrush
99 \property QAbstractAxis::labelsBrush
99 The brush of the labels.
100 The brush of the labels.
100 */
101 */
101
102
102 /*!
103 /*!
103 \property QAbstractAxis::visible
104 \property QAbstractAxis::visible
104 The visibility of the axis.
105 The visibility of the axis.
105 */
106 */
106 /*!
107 /*!
107 \qmlproperty bool AbstractAxis::visible
108 \qmlproperty bool AbstractAxis::visible
108 The visibility of the axis.
109 The visibility of the axis.
109 */
110 */
110
111
111 /*!
112 /*!
112 \property QAbstractAxis::gridVisible
113 \property QAbstractAxis::gridVisible
113 The visibility of the grid lines.
114 The visibility of the grid lines.
114 */
115 */
115 /*!
116 /*!
116 \qmlproperty bool AbstractAxis::gridVisible
117 \qmlproperty bool AbstractAxis::gridVisible
117 The visibility of the grid lines.
118 The visibility of the grid lines.
118 */
119 */
119
120
120 /*!
121 /*!
121 \property QAbstractAxis::color
122 \property QAbstractAxis::color
122 The color of the axis and ticks.
123 The color of the axis and ticks.
123 */
124 */
124 /*!
125 /*!
125 \qmlproperty color AbstractAxis::color
126 \qmlproperty color AbstractAxis::color
126 The color of the axis and ticks.
127 The color of the axis and ticks.
127 */
128 */
128
129
129 /*!
130 /*!
130 \property QAbstractAxis::gridLinePen
131 \property QAbstractAxis::gridLinePen
131 The pen of the grid line.
132 The pen of the grid line.
132 */
133 */
133
134
134 /*!
135 /*!
135 \property QAbstractAxis::labelsFont
136 \property QAbstractAxis::labelsFont
136 The font of the axis labels.
137 The font of the axis labels.
137 */
138 */
138
139
139 /*!
140 /*!
140 \qmlproperty Font AbstractAxis::labelsFont
141 \qmlproperty Font AbstractAxis::labelsFont
141 The font of the axis labels.
142 The font of the axis labels.
142
143
143 See the \l {Font} {QML Font Element} for detailed documentation.
144 See the \l {Font} {QML Font Element} for detailed documentation.
144 */
145 */
145
146
146 /*!
147 /*!
147 \property QAbstractAxis::labelsColor
148 \property QAbstractAxis::labelsColor
148 The color of the axis labels.
149 The color of the axis labels.
149 */
150 */
150 /*!
151 /*!
151 \qmlproperty color AbstractAxis::labelsColor
152 \qmlproperty color AbstractAxis::labelsColor
152 The color of the axis labels.
153 The color of the axis labels.
153 */
154 */
154
155
155 /*!
156 /*!
156 \property QAbstractAxis::labelsAngle
157 \property QAbstractAxis::labelsAngle
157 The angle of the axis labels in degrees.
158 The angle of the axis labels in degrees.
158 */
159 */
159 /*!
160 /*!
160 \qmlproperty int AbstractAxis::labelsAngle
161 \qmlproperty int AbstractAxis::labelsAngle
161 The angle of the axis labels in degrees.
162 The angle of the axis labels in degrees.
162 */
163 */
163
164
164 /*!
165 /*!
165 \property QAbstractAxis::shadesVisible
166 \property QAbstractAxis::shadesVisible
166 The visibility of the axis shades.
167 The visibility of the axis shades.
167 */
168 */
168 /*!
169 /*!
169 \qmlproperty bool AbstractAxis::shadesVisible
170 \qmlproperty bool AbstractAxis::shadesVisible
170 The visibility of the axis shades.
171 The visibility of the axis shades.
171 */
172 */
172
173
173 /*!
174 /*!
174 \property QAbstractAxis::shadesColor
175 \property QAbstractAxis::shadesColor
175 The fill (brush) color of the axis shades.
176 The fill (brush) color of the axis shades.
176 */
177 */
177 /*!
178 /*!
178 \qmlproperty color AbstractAxis::shadesColor
179 \qmlproperty color AbstractAxis::shadesColor
179 The fill (brush) color of the axis shades.
180 The fill (brush) color of the axis shades.
180 */
181 */
181
182
182 /*!
183 /*!
183 \property QAbstractAxis::shadesBorderColor
184 \property QAbstractAxis::shadesBorderColor
184 The border (pen) color of the axis shades.
185 The border (pen) color of the axis shades.
185 */
186 */
186 /*!
187 /*!
187 \qmlproperty color AbstractAxis::shadesBorderColor
188 \qmlproperty color AbstractAxis::shadesBorderColor
188 The border (pen) color of the axis shades.
189 The border (pen) color of the axis shades.
189 */
190 */
190
191
191 /*!
192 /*!
192 \property QAbstractAxis::shadesPen
193 \property QAbstractAxis::shadesPen
193 The pen of the axis shades (area between grid lines).
194 The pen of the axis shades (area between grid lines).
194 */
195 */
195
196
196 /*!
197 /*!
197 \property QAbstractAxis::shadesBrush
198 \property QAbstractAxis::shadesBrush
198 The brush of the axis shades (area between grid lines).
199 The brush of the axis shades (area between grid lines).
199 */
200 */
200
201
201 /*!
202 /*!
202 \property QAbstractAxis::titleVisible
203 \property QAbstractAxis::titleVisible
203 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.
204 */
205 */
205 /*!
206 /*!
206 \qmlproperty bool AbstractAxis::titleVisible
207 \qmlproperty bool AbstractAxis::titleVisible
207 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.
208 */
209 */
209
210
210 /*!
211 /*!
211 \property QAbstractAxis::titleText
212 \property QAbstractAxis::titleText
212 The title of the axis. Empty by default.
213 The title of the axis. Empty by default.
213 */
214 */
214 /*!
215 /*!
215 \qmlproperty String AbstractAxis::titleText
216 \qmlproperty String AbstractAxis::titleText
216 The title of the axis. Empty by default.
217 The title of the axis. Empty by default.
217 */
218 */
218
219
219 /*!
220 /*!
220 \property QAbstractAxis::titlePen
221 \property QAbstractAxis::titlePen
221 The pen of the title text.
222 The pen of the title text.
222 */
223 */
223
224
224 /*!
225 /*!
225 \property QAbstractAxis::titleBrush
226 \property QAbstractAxis::titleBrush
226 The brush of the title text.
227 The brush of the title text.
227 */
228 */
228
229
229 /*!
230 /*!
230 \property QAbstractAxis::titleFont
231 \property QAbstractAxis::titleFont
231 The font of the title of the axis.
232 The font of the title of the axis.
232 */
233 */
233 /*!
234 /*!
234 \qmlproperty Font AbstractAxis::titleFont
235 \qmlproperty Font AbstractAxis::titleFont
235 The font of the title of the axis.
236 The font of the title of the axis.
236 */
237 */
237
238
238 /*!
239 /*!
239 \property QAbstractAxis::orientation
240 \property QAbstractAxis::orientation
240 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.
241 */
242 */
242 /*!
243 /*!
243 \qmlproperty Qt.Orientation AbstractAxis::orientation
244 \qmlproperty Qt.Orientation AbstractAxis::orientation
244 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.
245 */
246 */
246
247
247 /*!
248 /*!
248 \property QAbstractAxis::alignment
249 \property QAbstractAxis::alignment
249 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.
250 */
251 */
251 /*!
252 /*!
252 \qmlproperty alignment AbstractAxis::alignment
253 \qmlproperty alignment AbstractAxis::alignment
253 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.
254 */
255 */
255
256
256 /*!
257 /*!
257 \fn void QAbstractAxis::visibleChanged(bool visible)
258 \fn void QAbstractAxis::visibleChanged(bool visible)
258 Visibility of the axis has changed to \a visible.
259 Visibility of the axis has changed to \a visible.
259 */
260 */
260 /*!
261 /*!
261 \qmlsignal AbstractAxis::onVisibleChanged(bool visible)
262 \qmlsignal AbstractAxis::onVisibleChanged(bool visible)
262 Visibility of the axis has changed to \a visible.
263 Visibility of the axis has changed to \a visible.
263 */
264 */
264
265
265 /*!
266 /*!
266 \fn void QAbstractAxis::linePenChanged(const QPen& pen)
267 \fn void QAbstractAxis::linePenChanged(const QPen& pen)
267 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.
268 */
269 */
269
270
270 /*!
271 /*!
271 \fn void QAbstractAxis::lineVisibleChanged(bool visible)
272 \fn void QAbstractAxis::lineVisibleChanged(bool visible)
272 Visibility of the axis line has changed to \a visible.
273 Visibility of the axis line has changed to \a visible.
273 */
274 */
274 /*!
275 /*!
275 \qmlsignal AbstractAxis::onLineVisibleChanged(bool visible)
276 \qmlsignal AbstractAxis::onLineVisibleChanged(bool visible)
276 Visibility of the axis line has changed to \a visible.
277 Visibility of the axis line has changed to \a visible.
277 */
278 */
278
279
279 /*!
280 /*!
280 \fn void QAbstractAxis::labelsVisibleChanged(bool visible)
281 \fn void QAbstractAxis::labelsVisibleChanged(bool visible)
281 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.
282 */
283 */
283 /*!
284 /*!
284 \qmlsignal AbstractAxis::onLabelsVisibleChanged(bool visible)
285 \qmlsignal AbstractAxis::onLabelsVisibleChanged(bool visible)
285 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.
286 */
287 */
287
288
288 /*!
289 /*!
289 \fn void QAbstractAxis::labelsFontChanged(const QFont& font)
290 \fn void QAbstractAxis::labelsFontChanged(const QFont& font)
290 The font of the axis labels has changed to \a font.
291 The font of the axis labels has changed to \a font.
291 */
292 */
292 /*!
293 /*!
293 \qmlsignal AbstractAxis::onLabelsFontChanged(Font font)
294 \qmlsignal AbstractAxis::onLabelsFontChanged(Font font)
294 The font of the axis labels has changed to \a font.
295 The font of the axis labels has changed to \a font.
295 */
296 */
296
297
297 /*!
298 /*!
298 \fn void QAbstractAxis::labelsPenChanged(const QPen& pen)
299 \fn void QAbstractAxis::labelsPenChanged(const QPen& pen)
299 The pen of the axis labels has changed to \a pen.
300 The pen of the axis labels has changed to \a pen.
300 */
301 */
301
302
302 /*!
303 /*!
303 \fn void QAbstractAxis::labelsBrushChanged(const QBrush& brush)
304 \fn void QAbstractAxis::labelsBrushChanged(const QBrush& brush)
304 The brush of the axis labels has changed to \a brush.
305 The brush of the axis labels has changed to \a brush.
305 */
306 */
306
307
307 /*!
308 /*!
308 \fn void QAbstractAxis::labelsAngleChanged(int angle)
309 \fn void QAbstractAxis::labelsAngleChanged(int angle)
309 The angle of the axis labels has changed to \a angle.
310 The angle of the axis labels has changed to \a angle.
310 */
311 */
311 /*!
312 /*!
312 \qmlsignal AbstractAxis::onLabelsAngleChanged(int angle)
313 \qmlsignal AbstractAxis::onLabelsAngleChanged(int angle)
313 The angle of the axis labels has changed to \a angle.
314 The angle of the axis labels has changed to \a angle.
314 */
315 */
315
316
316 /*!
317 /*!
317 \fn void QAbstractAxis::gridVisibleChanged(bool visible)
318 \fn void QAbstractAxis::gridVisibleChanged(bool visible)
318 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.
319 */
320 */
320 /*!
321 /*!
321 \qmlsignal AbstractAxis::onGridVisibleChanged(bool visible)
322 \qmlsignal AbstractAxis::onGridVisibleChanged(bool visible)
322 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.
323 */
324 */
324
325
325 /*!
326 /*!
326 \fn void QAbstractAxis::gridLinePenChanged(const QPen& pen)
327 \fn void QAbstractAxis::gridLinePenChanged(const QPen& pen)
327 The pen of the grid line has changed to \a pen.
328 The pen of the grid line has changed to \a pen.
328 */
329 */
329
330
330 /*!
331 /*!
331 \fn void QAbstractAxis::colorChanged(QColor color)
332 \fn void QAbstractAxis::colorChanged(QColor color)
332 Emitted if the \a color of the axis is changed.
333 Emitted if the \a color of the axis is changed.
333 */
334 */
334 /*!
335 /*!
335 \qmlsignal AbstractAxis::onColorChanged(QColor color)
336 \qmlsignal AbstractAxis::onColorChanged(QColor color)
336 Emitted if the \a color of the axis is changed.
337 Emitted if the \a color of the axis is changed.
337 */
338 */
338
339
339 /*!
340 /*!
340 \fn void QAbstractAxis::labelsColorChanged(QColor color)
341 \fn void QAbstractAxis::labelsColorChanged(QColor color)
341 Emitted if the \a color of the axis labels is changed.
342 Emitted if the \a color of the axis labels is changed.
342 */
343 */
343 /*!
344 /*!
344 \qmlsignal AbstractAxis::onLabelsColorChanged(QColor color)
345 \qmlsignal AbstractAxis::onLabelsColorChanged(QColor color)
345 Emitted if the \a color of the axis labels is changed.
346 Emitted if the \a color of the axis labels is changed.
346 */
347 */
347
348
348 /*!
349 /*!
349 \fn void QAbstractAxis::titleVisibleChanged(bool visible)
350 \fn void QAbstractAxis::titleVisibleChanged(bool visible)
350 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.
351 */
352 */
352 /*!
353 /*!
353 \qmlsignal AbstractAxis::onTitleVisibleChanged(bool visible)
354 \qmlsignal AbstractAxis::onTitleVisibleChanged(bool visible)
354 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.
355 */
356 */
356
357
357 /*!
358 /*!
358 \fn void QAbstractAxis::titleTextChanged(const QString& text)
359 \fn void QAbstractAxis::titleTextChanged(const QString& text)
359 The text of the axis title has changed to \a text.
360 The text of the axis title has changed to \a text.
360 */
361 */
361 /*!
362 /*!
362 \qmlsignal AbstractAxis::onTitleTextChanged(String text)
363 \qmlsignal AbstractAxis::onTitleTextChanged(String text)
363 The text of the axis title has changed to \a text.
364 The text of the axis title has changed to \a text.
364 */
365 */
365
366
366 /*!
367 /*!
367 \fn void QAbstractAxis::titlePenChanged(const QPen& pen)
368 \fn void QAbstractAxis::titlePenChanged(const QPen& pen)
368 The pen of the axis shades has changed to \a pen.
369 The pen of the axis shades has changed to \a pen.
369 */
370 */
370
371
371 /*!
372 /*!
372 \fn void QAbstractAxis::titleBrushChanged(const QBrush& brush)
373 \fn void QAbstractAxis::titleBrushChanged(const QBrush& brush)
373 The brush of the axis title has changed to \a brush.
374 The brush of the axis title has changed to \a brush.
374 */
375 */
375
376
376 /*!
377 /*!
377 \fn void QAbstractAxis::titleFontChanged(const QFont& font)
378 \fn void QAbstractAxis::titleFontChanged(const QFont& font)
378 The font of the axis title has changed to \a font.
379 The font of the axis title has changed to \a font.
379 */
380 */
380 /*!
381 /*!
381 \qmlsignal AbstractAxis::onTitleFontChanged(Font font)
382 \qmlsignal AbstractAxis::onTitleFontChanged(Font font)
382 The font of the axis title has changed to \a font.
383 The font of the axis title has changed to \a font.
383 */
384 */
384
385
385 /*!
386 /*!
386 \fn void QAbstractAxis::shadesVisibleChanged(bool)
387 \fn void QAbstractAxis::shadesVisibleChanged(bool)
387 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.
388 */
389 */
389 /*!
390 /*!
390 \qmlsignal AbstractAxis::onShadesVisibleChanged(bool visible)
391 \qmlsignal AbstractAxis::onShadesVisibleChanged(bool visible)
391 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.
392 */
393 */
393
394
394 /*!
395 /*!
395 \fn void QAbstractAxis::shadesColorChanged(QColor color)
396 \fn void QAbstractAxis::shadesColorChanged(QColor color)
396 Emitted if the \a color of the axis shades is changed.
397 Emitted if the \a color of the axis shades is changed.
397 */
398 */
398 /*!
399 /*!
399 \qmlsignal AbstractAxis::onShadesColorChanged(QColor color)
400 \qmlsignal AbstractAxis::onShadesColorChanged(QColor color)
400 Emitted if the \a color of the axis shades is changed.
401 Emitted if the \a color of the axis shades is changed.
401 */
402 */
402
403
403 /*!
404 /*!
404 \fn void QAbstractAxis::shadesBorderColorChanged(QColor)
405 \fn void QAbstractAxis::shadesBorderColorChanged(QColor)
405 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.
406 */
407 */
407 /*!
408 /*!
408 \qmlsignal AbstractAxis::onBorderColorChanged(QColor color)
409 \qmlsignal AbstractAxis::onBorderColorChanged(QColor color)
409 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.
410 */
411 */
411
412
412 /*!
413 /*!
413 \fn void QAbstractAxis::shadesBrushChanged(const QBrush& brush)
414 \fn void QAbstractAxis::shadesBrushChanged(const QBrush& brush)
414 The brush of the axis shades has changed to \a brush.
415 The brush of the axis shades has changed to \a brush.
415 */
416 */
416
417
417 /*!
418 /*!
418 \fn void QAbstractAxis::shadesPenChanged(const QPen& pen)
419 \fn void QAbstractAxis::shadesPenChanged(const QPen& pen)
419 The pen of the axis shades has changed to \a pen.
420 The pen of the axis shades has changed to \a pen.
420 */
421 */
421
422
422 /*!
423 /*!
423 \internal
424 \internal
424 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
425 QChart when axis added.
426 QChart when axis added.
426 */
427 */
427
428
428 QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent)
429 QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent)
429 : QObject(parent),
430 : QObject(parent),
430 d_ptr(&d)
431 d_ptr(&d)
431 {
432 {
432 }
433 }
433
434
434 /*!
435 /*!
435 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.
436 */
437 */
437
438
438 QAbstractAxis::~QAbstractAxis()
439 QAbstractAxis::~QAbstractAxis()
439 {
440 {
440 if (d_ptr->m_chart)
441 if (d_ptr->m_chart)
441 qFatal("Still binded axis detected !");
442 qFatal("Still binded axis detected !");
442 }
443 }
443
444
444 /*!
445 /*!
445 Sets \a pen used to draw axis line and ticks.
446 Sets \a pen used to draw axis line and ticks.
446 */
447 */
447 void QAbstractAxis::setLinePen(const QPen &pen)
448 void QAbstractAxis::setLinePen(const QPen &pen)
448 {
449 {
449 if (d_ptr->m_axisPen != pen) {
450 if (d_ptr->m_axisPen != pen) {
450 d_ptr->m_axisPen = pen;
451 d_ptr->m_axisPen = pen;
451 emit linePenChanged(pen);
452 emit linePenChanged(pen);
452 }
453 }
453 }
454 }
454
455
455 /*!
456 /*!
456 Returns pen used to draw axis and ticks.
457 Returns pen used to draw axis and ticks.
457 */
458 */
458 QPen QAbstractAxis::linePen() const
459 QPen QAbstractAxis::linePen() const
459 {
460 {
460 return d_ptr->m_axisPen;
461 return d_ptr->m_axisPen;
461 }
462 }
462
463
463 //TODO: remove me 2.0
464 //TODO: remove me 2.0
464 void QAbstractAxis::setLinePenColor(QColor color)
465 void QAbstractAxis::setLinePenColor(QColor color)
465 {
466 {
466 QPen p = d_ptr->m_axisPen;
467 QPen p = d_ptr->m_axisPen;
467 if (p.color() != color) {
468 if (p.color() != color) {
468 p.setColor(color);
469 p.setColor(color);
469 setLinePen(p);
470 setLinePen(p);
470 emit colorChanged(color);
471 emit colorChanged(color);
471 }
472 }
472 }
473 }
473
474
474 QColor QAbstractAxis::linePenColor() const
475 QColor QAbstractAxis::linePenColor() const
475 {
476 {
476 return d_ptr->m_axisPen.color();
477 return d_ptr->m_axisPen.color();
477 }
478 }
478
479
479 /*!
480 /*!
480 Sets if axis and ticks are \a visible.
481 Sets if axis and ticks are \a visible.
481 */
482 */
482 void QAbstractAxis::setLineVisible(bool visible)
483 void QAbstractAxis::setLineVisible(bool visible)
483 {
484 {
484 if (d_ptr->m_arrowVisible != visible) {
485 if (d_ptr->m_arrowVisible != visible) {
485 d_ptr->m_arrowVisible = visible;
486 d_ptr->m_arrowVisible = visible;
486 emit lineVisibleChanged(visible);
487 emit lineVisibleChanged(visible);
487 }
488 }
488 }
489 }
489
490
490 bool QAbstractAxis::isLineVisible() const
491 bool QAbstractAxis::isLineVisible() const
491 {
492 {
492 return d_ptr->m_arrowVisible;
493 return d_ptr->m_arrowVisible;
493 }
494 }
494
495
495 void QAbstractAxis::setGridLineVisible(bool visible)
496 void QAbstractAxis::setGridLineVisible(bool visible)
496 {
497 {
497 if (d_ptr->m_gridLineVisible != visible) {
498 if (d_ptr->m_gridLineVisible != visible) {
498 d_ptr->m_gridLineVisible = visible;
499 d_ptr->m_gridLineVisible = visible;
499 emit gridVisibleChanged(visible);
500 emit gridVisibleChanged(visible);
500 }
501 }
501 }
502 }
502
503
503 bool QAbstractAxis::isGridLineVisible() const
504 bool QAbstractAxis::isGridLineVisible() const
504 {
505 {
505 return d_ptr->m_gridLineVisible;
506 return d_ptr->m_gridLineVisible;
506 }
507 }
507
508
508 /*!
509 /*!
509 Sets \a pen used to draw grid line.
510 Sets \a pen used to draw grid line.
510 */
511 */
511 void QAbstractAxis::setGridLinePen(const QPen &pen)
512 void QAbstractAxis::setGridLinePen(const QPen &pen)
512 {
513 {
513 if (d_ptr->m_gridLinePen != pen) {
514 if (d_ptr->m_gridLinePen != pen) {
514 d_ptr->m_gridLinePen = pen;
515 d_ptr->m_gridLinePen = pen;
515 emit gridLinePenChanged(pen);
516 emit gridLinePenChanged(pen);
516 }
517 }
517 }
518 }
518
519
519 /*!
520 /*!
520 Returns pen used to draw grid.
521 Returns pen used to draw grid.
521 */
522 */
522 QPen QAbstractAxis::gridLinePen() const
523 QPen QAbstractAxis::gridLinePen() const
523 {
524 {
524 return d_ptr->m_gridLinePen;
525 return d_ptr->m_gridLinePen;
525 }
526 }
526
527
527 void QAbstractAxis::setLabelsVisible(bool visible)
528 void QAbstractAxis::setLabelsVisible(bool visible)
528 {
529 {
529 if (d_ptr->m_labelsVisible != visible) {
530 if (d_ptr->m_labelsVisible != visible) {
530 d_ptr->m_labelsVisible = visible;
531 d_ptr->m_labelsVisible = visible;
531 emit labelsVisibleChanged(visible);
532 emit labelsVisibleChanged(visible);
532 }
533 }
533 }
534 }
534
535
535 bool QAbstractAxis::labelsVisible() const
536 bool QAbstractAxis::labelsVisible() const
536 {
537 {
537 return d_ptr->m_labelsVisible;
538 return d_ptr->m_labelsVisible;
538 }
539 }
539
540
540 /*!
541 /*!
541 Sets \a pen used to draw labels.
542 Sets \a pen used to draw labels.
542 */
543 */
543 void QAbstractAxis::setLabelsPen(const QPen &pen)
544 void QAbstractAxis::setLabelsPen(const QPen &pen)
544 {
545 {
545 if (d_ptr->m_labelsPen != pen) {
546 if (d_ptr->m_labelsPen != pen) {
546 d_ptr->m_labelsPen = pen;
547 d_ptr->m_labelsPen = pen;
547 emit labelsPenChanged(pen);
548 emit labelsPenChanged(pen);
548 }
549 }
549 }
550 }
550
551
551 /*!
552 /*!
552 Returns the pen used to labels.
553 Returns the pen used to labels.
553 */
554 */
554 QPen QAbstractAxis::labelsPen() const
555 QPen QAbstractAxis::labelsPen() const
555 {
556 {
556 return d_ptr->m_labelsPen;
557 return d_ptr->m_labelsPen;
557 }
558 }
558
559
559 /*!
560 /*!
560 Sets \a brush used to draw labels.
561 Sets \a brush used to draw labels.
561 */
562 */
562 void QAbstractAxis::setLabelsBrush(const QBrush &brush)
563 void QAbstractAxis::setLabelsBrush(const QBrush &brush)
563 {
564 {
564 if (d_ptr->m_labelsBrush != brush) {
565 if (d_ptr->m_labelsBrush != brush) {
565 d_ptr->m_labelsBrush = brush;
566 d_ptr->m_labelsBrush = brush;
566 emit labelsBrushChanged(brush);
567 emit labelsBrushChanged(brush);
567 }
568 }
568 }
569 }
569
570
570 /*!
571 /*!
571 Returns brush used to draw labels.
572 Returns brush used to draw labels.
572 */
573 */
573 QBrush QAbstractAxis::labelsBrush() const
574 QBrush QAbstractAxis::labelsBrush() const
574 {
575 {
575 return d_ptr->m_labelsBrush;
576 return d_ptr->m_labelsBrush;
576 }
577 }
577
578
578 /*!
579 /*!
579 Sets \a font used to draw labels.
580 Sets \a font used to draw labels.
580 */
581 */
581 void QAbstractAxis::setLabelsFont(const QFont &font)
582 void QAbstractAxis::setLabelsFont(const QFont &font)
582 {
583 {
583 if (d_ptr->m_labelsFont != font) {
584 if (d_ptr->m_labelsFont != font) {
584 d_ptr->m_labelsFont = font;
585 d_ptr->m_labelsFont = font;
585 emit labelsFontChanged(font);
586 emit labelsFontChanged(font);
586 }
587 }
587 }
588 }
588
589
589 /*!
590 /*!
590 Returns font used to draw labels.
591 Returns font used to draw labels.
591 */
592 */
592 QFont QAbstractAxis::labelsFont() const
593 QFont QAbstractAxis::labelsFont() const
593 {
594 {
594 return d_ptr->m_labelsFont;
595 return d_ptr->m_labelsFont;
595 }
596 }
596
597
597 void QAbstractAxis::setLabelsAngle(int angle)
598 void QAbstractAxis::setLabelsAngle(int angle)
598 {
599 {
599 if (d_ptr->m_labelsAngle != angle) {
600 if (d_ptr->m_labelsAngle != angle) {
600 d_ptr->m_labelsAngle = angle;
601 d_ptr->m_labelsAngle = angle;
601 emit labelsAngleChanged(angle);
602 emit labelsAngleChanged(angle);
602 }
603 }
603 }
604 }
604
605
605 int QAbstractAxis::labelsAngle() const
606 int QAbstractAxis::labelsAngle() const
606 {
607 {
607 return d_ptr->m_labelsAngle;
608 return d_ptr->m_labelsAngle;
608 }
609 }
609 //TODO: remove me 2.0
610 //TODO: remove me 2.0
610 void QAbstractAxis::setLabelsColor(QColor color)
611 void QAbstractAxis::setLabelsColor(QColor color)
611 {
612 {
612 QBrush b = d_ptr->m_labelsBrush;
613 QBrush b = d_ptr->m_labelsBrush;
613 if (b.color() != color) {
614 if (b.color() != color) {
614 b.setColor(color);
615 b.setColor(color);
615 setLabelsBrush(b);
616 setLabelsBrush(b);
616 emit labelsColorChanged(color);
617 emit labelsColorChanged(color);
617 }
618 }
618 }
619 }
619
620
620 QColor QAbstractAxis::labelsColor() const
621 QColor QAbstractAxis::labelsColor() const
621 {
622 {
622 return d_ptr->m_labelsBrush.color();
623 return d_ptr->m_labelsBrush.color();
623 }
624 }
624
625
625 void QAbstractAxis::setTitleVisible(bool visible)
626 void QAbstractAxis::setTitleVisible(bool visible)
626 {
627 {
627 if (d_ptr->m_titleVisible != visible) {
628 if (d_ptr->m_titleVisible != visible) {
628 d_ptr->m_titleVisible = visible;
629 d_ptr->m_titleVisible = visible;
629 emit titleVisibleChanged(visible);
630 emit titleVisibleChanged(visible);
630 }
631 }
631 }
632 }
632
633
633 bool QAbstractAxis::isTitleVisible() const
634 bool QAbstractAxis::isTitleVisible() const
634 {
635 {
635 return d_ptr->m_titleVisible;
636 return d_ptr->m_titleVisible;
636 }
637 }
637
638
638 /*!
639 /*!
639 Sets \a pen used to draw title.
640 Sets \a pen used to draw title.
640 */
641 */
641 void QAbstractAxis::setTitlePen(const QPen &pen)
642 void QAbstractAxis::setTitlePen(const QPen &pen)
642 {
643 {
643 if (d_ptr->m_titlePen != pen) {
644 if (d_ptr->m_titlePen != pen) {
644 d_ptr->m_titlePen = pen;
645 d_ptr->m_titlePen = pen;
645 emit titlePenChanged(pen);
646 emit titlePenChanged(pen);
646 }
647 }
647 }
648 }
648
649
649 /*!
650 /*!
650 Returns the pen used to title.
651 Returns the pen used to title.
651 */
652 */
652 QPen QAbstractAxis::titlePen() const
653 QPen QAbstractAxis::titlePen() const
653 {
654 {
654 return d_ptr->m_titlePen;
655 return d_ptr->m_titlePen;
655 }
656 }
656
657
657 /*!
658 /*!
658 Sets \a brush used to draw title.
659 Sets \a brush used to draw title.
659 */
660 */
660 void QAbstractAxis::setTitleBrush(const QBrush &brush)
661 void QAbstractAxis::setTitleBrush(const QBrush &brush)
661 {
662 {
662 if (d_ptr->m_titleBrush != brush) {
663 if (d_ptr->m_titleBrush != brush) {
663 d_ptr->m_titleBrush = brush;
664 d_ptr->m_titleBrush = brush;
664 emit titleBrushChanged(brush);
665 emit titleBrushChanged(brush);
665 }
666 }
666 }
667 }
667
668
668 /*!
669 /*!
669 Returns brush used to draw title.
670 Returns brush used to draw title.
670 */
671 */
671 QBrush QAbstractAxis::titleBrush() const
672 QBrush QAbstractAxis::titleBrush() const
672 {
673 {
673 return d_ptr->m_titleBrush;
674 return d_ptr->m_titleBrush;
674 }
675 }
675
676
676 /*!
677 /*!
677 Sets \a font used to draw title.
678 Sets \a font used to draw title.
678 */
679 */
679 void QAbstractAxis::setTitleFont(const QFont &font)
680 void QAbstractAxis::setTitleFont(const QFont &font)
680 {
681 {
681 if (d_ptr->m_titleFont != font) {
682 if (d_ptr->m_titleFont != font) {
682 d_ptr->m_titleFont = font;
683 d_ptr->m_titleFont = font;
683 emit titleFontChanged(font);
684 emit titleFontChanged(font);
684 }
685 }
685 }
686 }
686
687
687 /*!
688 /*!
688 Returns font used to draw title.
689 Returns font used to draw title.
689 */
690 */
690 QFont QAbstractAxis::titleFont() const
691 QFont QAbstractAxis::titleFont() const
691 {
692 {
692 return d_ptr->m_titleFont;
693 return d_ptr->m_titleFont;
693 }
694 }
694
695
695 void QAbstractAxis::setTitleText(const QString &title)
696 void QAbstractAxis::setTitleText(const QString &title)
696 {
697 {
697 if (d_ptr->m_title != title) {
698 if (d_ptr->m_title != title) {
698 d_ptr->m_title = title;
699 d_ptr->m_title = title;
699 emit titleTextChanged(title);
700 emit titleTextChanged(title);
700 }
701 }
701 }
702 }
702
703
703 QString QAbstractAxis::titleText() const
704 QString QAbstractAxis::titleText() const
704 {
705 {
705 return d_ptr->m_title;
706 return d_ptr->m_title;
706 }
707 }
707
708
708
709
709 void QAbstractAxis::setShadesVisible(bool visible)
710 void QAbstractAxis::setShadesVisible(bool visible)
710 {
711 {
711 if (d_ptr->m_shadesVisible != visible) {
712 if (d_ptr->m_shadesVisible != visible) {
712 d_ptr->m_shadesVisible = visible;
713 d_ptr->m_shadesVisible = visible;
713 emit shadesVisibleChanged(visible);
714 emit shadesVisibleChanged(visible);
714 }
715 }
715 }
716 }
716
717
717 bool QAbstractAxis::shadesVisible() const
718 bool QAbstractAxis::shadesVisible() const
718 {
719 {
719 return d_ptr->m_shadesVisible;
720 return d_ptr->m_shadesVisible;
720 }
721 }
721
722
722 /*!
723 /*!
723 Sets \a pen used to draw shades.
724 Sets \a pen used to draw shades.
724 */
725 */
725 void QAbstractAxis::setShadesPen(const QPen &pen)
726 void QAbstractAxis::setShadesPen(const QPen &pen)
726 {
727 {
727 if (d_ptr->m_shadesPen != pen) {
728 if (d_ptr->m_shadesPen != pen) {
728 d_ptr->m_shadesPen = pen;
729 d_ptr->m_shadesPen = pen;
729 emit shadesPenChanged(pen);
730 emit shadesPenChanged(pen);
730 }
731 }
731 }
732 }
732
733
733 /*!
734 /*!
734 Returns pen used to draw shades.
735 Returns pen used to draw shades.
735 */
736 */
736 QPen QAbstractAxis::shadesPen() const
737 QPen QAbstractAxis::shadesPen() const
737 {
738 {
738 return d_ptr->m_shadesPen;
739 return d_ptr->m_shadesPen;
739 }
740 }
740
741
741 /*!
742 /*!
742 Sets \a brush used to draw shades.
743 Sets \a brush used to draw shades.
743 */
744 */
744 void QAbstractAxis::setShadesBrush(const QBrush &brush)
745 void QAbstractAxis::setShadesBrush(const QBrush &brush)
745 {
746 {
746 if (d_ptr->m_shadesBrush != brush) {
747 if (d_ptr->m_shadesBrush != brush) {
747 d_ptr->m_shadesBrush = brush;
748 d_ptr->m_shadesBrush = brush;
748 emit shadesBrushChanged(brush);
749 emit shadesBrushChanged(brush);
749 }
750 }
750 }
751 }
751
752
752 /*!
753 /*!
753 Returns brush used to draw shades.
754 Returns brush used to draw shades.
754 */
755 */
755 QBrush QAbstractAxis::shadesBrush() const
756 QBrush QAbstractAxis::shadesBrush() const
756 {
757 {
757 return d_ptr->m_shadesBrush;
758 return d_ptr->m_shadesBrush;
758 }
759 }
759
760
760 void QAbstractAxis::setShadesColor(QColor color)
761 void QAbstractAxis::setShadesColor(QColor color)
761 {
762 {
762 QBrush b = d_ptr->m_shadesBrush;
763 QBrush b = d_ptr->m_shadesBrush;
763 if (b.color() != color) {
764 if (b.color() != color) {
764 b.setColor(color);
765 b.setColor(color);
765 setShadesBrush(b);
766 setShadesBrush(b);
766 emit shadesColorChanged(color);
767 emit shadesColorChanged(color);
767 }
768 }
768 }
769 }
769
770
770 QColor QAbstractAxis::shadesColor() const
771 QColor QAbstractAxis::shadesColor() const
771 {
772 {
772 return d_ptr->m_shadesBrush.color();
773 return d_ptr->m_shadesBrush.color();
773 }
774 }
774
775
775 void QAbstractAxis::setShadesBorderColor(QColor color)
776 void QAbstractAxis::setShadesBorderColor(QColor color)
776 {
777 {
777 QPen p = d_ptr->m_shadesPen;
778 QPen p = d_ptr->m_shadesPen;
778 if (p.color() != color) {
779 if (p.color() != color) {
779 p.setColor(color);
780 p.setColor(color);
780 setShadesPen(p);
781 setShadesPen(p);
781 emit shadesColorChanged(color);
782 emit shadesColorChanged(color);
782 }
783 }
783 }
784 }
784
785
785 QColor QAbstractAxis::shadesBorderColor() const
786 QColor QAbstractAxis::shadesBorderColor() const
786 {
787 {
787 return d_ptr->m_shadesPen.color();
788 return d_ptr->m_shadesPen.color();
788 }
789 }
789
790
790
791
791 bool QAbstractAxis::isVisible() const
792 bool QAbstractAxis::isVisible() const
792 {
793 {
793 return d_ptr->m_visible;
794 return d_ptr->m_visible;
794 }
795 }
795
796
796 /*!
797 /*!
797 Sets axis, shades, labels and grid lines to be visible.
798 Sets axis, shades, labels and grid lines to be visible.
798 */
799 */
799 void QAbstractAxis::setVisible(bool visible)
800 void QAbstractAxis::setVisible(bool visible)
800 {
801 {
801 if (d_ptr->m_visible != visible) {
802 if (d_ptr->m_visible != visible) {
802 d_ptr->m_visible = visible;
803 d_ptr->m_visible = visible;
803 emit visibleChanged(visible);
804 emit visibleChanged(visible);
804 }
805 }
805 }
806 }
806
807
807
808
808 /*!
809 /*!
809 Sets axis, shades, labels and grid lines to be visible.
810 Sets axis, shades, labels and grid lines to be visible.
810 */
811 */
811 void QAbstractAxis::show()
812 void QAbstractAxis::show()
812 {
813 {
813 setVisible(true);
814 setVisible(true);
814 }
815 }
815
816
816 /*!
817 /*!
817 Sets axis, shades, labels and grid lines to not be visible.
818 Sets axis, shades, labels and grid lines to not be visible.
818 */
819 */
819 void QAbstractAxis::hide()
820 void QAbstractAxis::hide()
820 {
821 {
821 setVisible(false);
822 setVisible(false);
822 }
823 }
823
824
824 /*!
825 /*!
825 Sets the minimum value shown on the axis.
826 Sets the minimum value shown on the axis.
826 Depending on the actual axis type the \a min parameter is converted to appropriate type.
827 Depending on the actual axis type the \a min parameter is converted to appropriate type.
827 If the conversion is impossible then the function call does nothing
828 If the conversion is impossible then the function call does nothing
828 */
829 */
829 void QAbstractAxis::setMin(const QVariant &min)
830 void QAbstractAxis::setMin(const QVariant &min)
830 {
831 {
831 d_ptr->setMin(min);
832 d_ptr->setMin(min);
832 }
833 }
833
834
834 /*!
835 /*!
835 Sets the maximum value shown on the axis.
836 Sets the maximum value shown on the axis.
836 Depending on the actual axis type the \a max parameter is converted to appropriate type.
837 Depending on the actual axis type the \a max parameter is converted to appropriate type.
837 If the conversion is impossible then the function call does nothing
838 If the conversion is impossible then the function call does nothing
838 */
839 */
839 void QAbstractAxis::setMax(const QVariant &max)
840 void QAbstractAxis::setMax(const QVariant &max)
840 {
841 {
841 d_ptr->setMax(max);
842 d_ptr->setMax(max);
842 }
843 }
843
844
844 /*!
845 /*!
845 Sets the range shown on the axis.
846 Sets the range shown on the axis.
846 Depending on the actual axis type the \a min and \a max parameters are converted to appropriate types.
847 Depending on the actual axis type the \a min and \a max parameters are converted to appropriate types.
847 If the conversion is impossible then the function call does nothing.
848 If the conversion is impossible then the function call does nothing.
848 */
849 */
849 void QAbstractAxis::setRange(const QVariant &min, const QVariant &max)
850 void QAbstractAxis::setRange(const QVariant &min, const QVariant &max)
850 {
851 {
851 d_ptr->setRange(min, max);
852 d_ptr->setRange(min, max);
852 }
853 }
853
854
854
855
855 /*!
856 /*!
856 Returns the orientation in which the axis is being used (Vertical or Horizontal)
857 Returns the orientation in which the axis is being used (Vertical or Horizontal)
857 */
858 */
858 // NOTE: should have const but it breaks BC:
859 // NOTE: should have const but it breaks BC:
859 // http://techbase.kde.org/Policies/Binary_Compatibility_Examples#Change_the_CV-qualifiers_of_a_member_function
860 // http://techbase.kde.org/Policies/Binary_Compatibility_Examples#Change_the_CV-qualifiers_of_a_member_function
860 Qt::Orientation QAbstractAxis::orientation()
861 Qt::Orientation QAbstractAxis::orientation()
861 {
862 {
862 return d_ptr->orientation();
863 return d_ptr->orientation();
863 }
864 }
864
865
865 Qt::Alignment QAbstractAxis::alignment() const
866 Qt::Alignment QAbstractAxis::alignment() const
866 {
867 {
867 return d_ptr->alignment();
868 return d_ptr->alignment();
868 }
869 }
869
870
870 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
871 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
871
872
872 QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis *q)
873 QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis *q)
873 : q_ptr(q),
874 : q_ptr(q),
874 m_chart(0),
875 m_chart(0),
875 m_alignment(0),
876 m_alignment(0),
876 m_orientation(Qt::Orientation(0)),
877 m_orientation(Qt::Orientation(0)),
877 m_visible(true),
878 m_visible(true),
878 m_arrowVisible(true),
879 m_arrowVisible(true),
880 m_axisPen(QChartPrivate::defaultPen()),
881 m_axisBrush(QChartPrivate::defaultBrush()),
879 m_gridLineVisible(true),
882 m_gridLineVisible(true),
883 m_gridLinePen(QChartPrivate::defaultPen()),
880 m_labelsVisible(true),
884 m_labelsVisible(true),
885 m_labelsPen(QChartPrivate::defaultPen()),
886 m_labelsBrush(QChartPrivate::defaultBrush()),
887 m_labelsFont(QChartPrivate::defaultFont()),
881 m_labelsAngle(0),
888 m_labelsAngle(0),
882 m_titleVisible(true),
889 m_titleVisible(true),
890 m_titlePen(QChartPrivate::defaultPen()),
891 m_titleBrush(QChartPrivate::defaultBrush()),
892 m_titleFont(QChartPrivate::defaultFont()),
883 m_shadesVisible(false),
893 m_shadesVisible(false),
884 m_shadesBrush(Qt::SolidPattern),
894 m_shadesBrush(QChartPrivate::defaultBrush()),
895 m_shadesPen(QChartPrivate::defaultPen()),
885 m_shadesOpacity(1.0),
896 m_shadesOpacity(1.0),
886 m_dirty(false)
897 m_dirty(false)
887 {
898 {
888
889 }
899 }
890
900
891 QAbstractAxisPrivate::~QAbstractAxisPrivate()
901 QAbstractAxisPrivate::~QAbstractAxisPrivate()
892 {
902 {
893 }
903 }
894
904
895 void QAbstractAxisPrivate::setAlignment( Qt::Alignment alignment)
905 void QAbstractAxisPrivate::setAlignment( Qt::Alignment alignment)
896 {
906 {
897 switch(alignment) {
907 switch(alignment) {
898 case Qt::AlignTop:
908 case Qt::AlignTop:
899 case Qt::AlignBottom:
909 case Qt::AlignBottom:
900 m_orientation = Qt::Horizontal;
910 m_orientation = Qt::Horizontal;
901 break;
911 break;
902 case Qt::AlignLeft:
912 case Qt::AlignLeft:
903 case Qt::AlignRight:
913 case Qt::AlignRight:
904 m_orientation = Qt::Vertical;
914 m_orientation = Qt::Vertical;
905 break;
915 break;
906 default:
916 default:
907 qWarning()<<"No alignment specified !";
917 qWarning()<<"No alignment specified !";
908 break;
918 break;
909 };
919 };
910 m_alignment=alignment;
920 m_alignment=alignment;
911 }
921 }
912
922
913 void QAbstractAxisPrivate::initializeTheme(ChartTheme* theme, bool forced)
923 void QAbstractAxisPrivate::initializeTheme(ChartTheme* theme, bool forced)
914 {
924 {
915 QPen pen;
925 //TODO: introduce axis brush
916 QBrush brush;
926 if (forced || QChartPrivate::defaultPen() == m_axisPen)
917 QFont font;
927 q_ptr->setLinePen(theme->axisLinePen());
928
929 if (forced || QChartPrivate::defaultPen() == m_gridLinePen)
930 q_ptr->setGridLinePen(theme->girdLinePen());
931
932 if (forced || QChartPrivate::defaultBrush() == m_labelsBrush)
933 q_ptr->setLabelsBrush(theme->labelBrush());
934 if (forced || QChartPrivate::defaultPen() == m_labelsPen)
935 q_ptr->setLabelsPen(Qt::NoPen); // NoPen for performance reasons
936 if (forced || QChartPrivate::defaultFont() == m_labelsFont)
937 q_ptr->setLabelsFont(theme->labelFont());
938
939 if (forced || QChartPrivate::defaultBrush() == m_titleBrush)
940 q_ptr->setTitleBrush(theme->labelBrush());
941 if (forced || QChartPrivate::defaultPen() == m_titlePen)
942 q_ptr->setTitlePen(Qt::NoPen); // NoPen for performance reasons
943 if (forced || QChartPrivate::defaultFont() == m_titleFont) {
944 QFont font(m_labelsFont);
945 font.setBold(true);
946 q_ptr->setTitleFont(font);
947 }
918
948
919 bool axisX = m_orientation == Qt::Horizontal;
949 if (forced || QChartPrivate::defaultBrush() == m_shadesBrush)
950 q_ptr->setShadesBrush(theme->backgroundShadesBrush());
951 if (forced || QChartPrivate::defaultPen() == m_shadesPen)
952 q_ptr->setShadesPen(theme->backgroundShadesPen());
920
953
921 //TODO: introduce axis brush
954 bool axisX = m_orientation == Qt::Horizontal;
922 if (m_visible) {
955 if (forced && (theme->backgroundShades() == ChartTheme::BackgroundShadesBoth
923 if (m_arrowVisible) {
956 || (theme->backgroundShades() == ChartTheme::BackgroundShadesVertical && axisX)
924 if (forced || pen == m_axisPen) {
957 || (theme->backgroundShades() == ChartTheme::BackgroundShadesHorizontal && !axisX))) {
925 q_ptr->setLinePen(theme->axisLinePen());
958 q_ptr->setShadesVisible(true);
926 }
959 } else if (forced) {
927 }
960 q_ptr->setShadesVisible(false);
928 if (m_gridLineVisible) {
929 if (forced || pen == m_gridLinePen) {
930 q_ptr->setGridLinePen(theme->girdLinePen());
931 }
932 }
933 if (m_labelsVisible) {
934 if (forced || brush == m_labelsBrush){
935 q_ptr->setLabelsBrush(theme->labelBrush());
936 }
937 if (forced || pen == m_labelsPen){
938 q_ptr->setLabelsPen(Qt::NoPen);// NoPen for performance reasons
939 }
940 if (forced || font == m_labelsFont){
941 q_ptr->setLabelsFont(theme->labelFont());
942 }
943 }
944 if (m_titleVisible) {
945 if (forced || brush == m_titleBrush){
946 q_ptr->setTitleBrush(theme->labelBrush());
947 }
948 if (forced || pen == m_titlePen){
949 q_ptr->setTitlePen(Qt::NoPen);// Noen for performance reasons
950 }
951 if (forced || font == m_titleFont){
952 QFont font(m_labelsFont);
953 font.setBold(true);
954 q_ptr->setTitleFont(font);
955 }
956 }
957 if (forced || m_shadesVisible) {
958 if (forced || brush == m_shadesBrush){
959 q_ptr->setShadesBrush(theme->backgroundShadesBrush());
960 }
961 if (forced || pen == m_shadesPen){
962 q_ptr->setShadesPen(theme->backgroundShadesPen());
963 }
964 if (forced && (theme->backgroundShades() == ChartTheme::BackgroundShadesBoth
965 || (theme->backgroundShades() == ChartTheme::BackgroundShadesVertical && axisX)
966 || (theme->backgroundShades() == ChartTheme::BackgroundShadesHorizontal && !axisX))) {
967 q_ptr->setShadesVisible(true);
968 }
969 }
970 }
961 }
971 }
962 }
972
963
973 void QAbstractAxisPrivate::handleRangeChanged(qreal min, qreal max)
964 void QAbstractAxisPrivate::handleRangeChanged(qreal min, qreal max)
974 {
965 {
975 setRange(min,max);
966 setRange(min,max);
976 }
967 }
977
968
978 void QAbstractAxisPrivate::initializeGraphics(QGraphicsItem* parent)
969 void QAbstractAxisPrivate::initializeGraphics(QGraphicsItem* parent)
979 {
970 {
980 Q_UNUSED(parent);
971 Q_UNUSED(parent);
981 }
972 }
982
973
983 void QAbstractAxisPrivate::initializeAnimations(QChart::AnimationOptions options)
974 void QAbstractAxisPrivate::initializeAnimations(QChart::AnimationOptions options)
984 {
975 {
985 ChartAxisElement *axis = m_item.data();
976 ChartAxisElement *axis = m_item.data();
986 Q_ASSERT(axis);
977 Q_ASSERT(axis);
987 if (options.testFlag(QChart::GridAxisAnimations)) {
978 if (options.testFlag(QChart::GridAxisAnimations)) {
988 axis->setAnimation(new AxisAnimation(axis));
979 axis->setAnimation(new AxisAnimation(axis));
989 } else {
980 } else {
990 axis->setAnimation(0);
981 axis->setAnimation(0);
991 }
982 }
992 }
983 }
993
984
994
985
995
986
996 #include "moc_qabstractaxis.cpp"
987 #include "moc_qabstractaxis.cpp"
997 #include "moc_qabstractaxis_p.cpp"
988 #include "moc_qabstractaxis_p.cpp"
998
989
999 QTCOMMERCIALCHART_END_NAMESPACE
990 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,129 +1,130
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 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef QABSTRACTAXIS_P_H
30 #ifndef QABSTRACTAXIS_P_H
31 #define QABSTRACTAXIS_P_H
31 #define QABSTRACTAXIS_P_H
32
32
33 #include "qabstractaxis.h"
33 #include "qabstractaxis.h"
34 #include "chartaxiselement_p.h"
34 #include "chartaxiselement_p.h"
35 #include "qchart.h"
35 #include "qchart.h"
36 #include <QDebug>
36 #include <QDebug>
37
37
38 class QGraphicsItem;
38 class QGraphicsItem;
39
39
40 QTCOMMERCIALCHART_BEGIN_NAMESPACE
40 QTCOMMERCIALCHART_BEGIN_NAMESPACE
41
41
42 class ChartPresenter;
42 class ChartPresenter;
43 class AbstractDomain;
43 class AbstractDomain;
44 class QChart;
44 class QChart;
45 class QAbstractSeries;
45 class QAbstractSeries;
46 class ChartTheme;
46 class ChartTheme;
47 class ChartElement;
47 class ChartElement;
48
48
49 class QTCOMMERCIALCHART_AUTOTEST_EXPORT QAbstractAxisPrivate : public QObject
49 class QTCOMMERCIALCHART_AUTOTEST_EXPORT QAbstractAxisPrivate : public QObject
50 {
50 {
51 Q_OBJECT
51 Q_OBJECT
52 public:
52 public:
53 QAbstractAxisPrivate(QAbstractAxis *q);
53 QAbstractAxisPrivate(QAbstractAxis *q);
54 ~QAbstractAxisPrivate();
54 ~QAbstractAxisPrivate();
55
55
56 public:
56 public:
57 Qt::Alignment alignment() const { return m_alignment; }
57 Qt::Alignment alignment() const { return m_alignment; }
58 Qt::Orientation orientation() const { return m_orientation; }
58 Qt::Orientation orientation() const { return m_orientation; }
59 void setAlignment( Qt::Alignment alignment);
59 void setAlignment( Qt::Alignment alignment);
60
60
61 virtual void initializeDomain(AbstractDomain *domain) = 0;
61 virtual void initializeDomain(AbstractDomain *domain) = 0;
62 virtual void initializeGraphics(QGraphicsItem *parent) = 0;
62 virtual void initializeGraphics(QGraphicsItem *parent) = 0;
63 virtual void initializeTheme(ChartTheme* theme, bool forced = false);
63 virtual void initializeTheme(ChartTheme* theme, bool forced = false);
64 virtual void initializeAnimations(QChart::AnimationOptions options);
64 virtual void initializeAnimations(QChart::AnimationOptions options);
65
65
66 //interface for manipulating range form base class
66 //interface for manipulating range form base class
67 virtual void setMin(const QVariant &min) = 0;
67 virtual void setMin(const QVariant &min) = 0;
68 virtual void setMax(const QVariant &max) = 0;
68 virtual void setMax(const QVariant &max) = 0;
69 virtual void setRange(const QVariant &min, const QVariant &max) = 0;
69 virtual void setRange(const QVariant &min, const QVariant &max) = 0;
70
70
71 //interface manipulating range form domain
71 //interface manipulating range form domain
72 virtual void setRange(qreal min, qreal max) = 0;
72 virtual void setRange(qreal min, qreal max) = 0;
73 virtual qreal min() = 0;
73 virtual qreal min() = 0;
74 virtual qreal max() = 0;
74 virtual qreal max() = 0;
75
75
76 ChartAxisElement *axisItem() { return m_item.data(); }
76 ChartAxisElement *axisItem() { return m_item.data(); }
77
77
78 public Q_SLOTS:
78 public Q_SLOTS:
79 void handleRangeChanged(qreal min, qreal max);
79 void handleRangeChanged(qreal min, qreal max);
80
80
81 Q_SIGNALS:
81 Q_SIGNALS:
82 void rangeChanged(qreal min, qreal max);
82 void rangeChanged(qreal min, qreal max);
83
83
84 protected:
84 protected:
85 QAbstractAxis *q_ptr;
85 QAbstractAxis *q_ptr;
86 QChart *m_chart;
86 QChart *m_chart;
87 QScopedPointer<ChartAxisElement> m_item;
87 QScopedPointer<ChartAxisElement> m_item;
88
88 private:
89 private:
89 QList<QAbstractSeries*> m_series;
90 QList<QAbstractSeries*> m_series;
90
91
91 Qt::Alignment m_alignment;
92 Qt::Alignment m_alignment;
92 Qt::Orientation m_orientation;
93 Qt::Orientation m_orientation;
93
94
94 bool m_visible;
95 bool m_visible;
95
96
96 bool m_arrowVisible;
97 bool m_arrowVisible;
97 QPen m_axisPen;
98 QPen m_axisPen;
98 QBrush m_axisBrush;
99 QBrush m_axisBrush;
99
100
100 bool m_gridLineVisible;
101 bool m_gridLineVisible;
101 QPen m_gridLinePen;
102 QPen m_gridLinePen;
102
103
103 bool m_labelsVisible;
104 bool m_labelsVisible;
104 QPen m_labelsPen;
105 QPen m_labelsPen;
105 QBrush m_labelsBrush;
106 QBrush m_labelsBrush;
106 QFont m_labelsFont;
107 QFont m_labelsFont;
107 int m_labelsAngle;
108 int m_labelsAngle;
108
109
109 bool m_titleVisible;
110 bool m_titleVisible;
110 QPen m_titlePen;
111 QPen m_titlePen;
111 QBrush m_titleBrush;
112 QBrush m_titleBrush;
112 QFont m_titleFont;
113 QFont m_titleFont;
113 QString m_title;
114 QString m_title;
114
115
115 bool m_shadesVisible;
116 bool m_shadesVisible;
116 QPen m_shadesPen;
117 QPen m_shadesPen;
117 QBrush m_shadesBrush;
118 QBrush m_shadesBrush;
118 qreal m_shadesOpacity;
119 qreal m_shadesOpacity;
119
120
120 bool m_dirty;
121 bool m_dirty;
121
122
122 friend class QAbstractAxis;
123 friend class QAbstractAxis;
123 friend class ChartDataSet;
124 friend class ChartDataSet;
124 friend class ChartPresenter;
125 friend class ChartPresenter;
125 };
126 };
126
127
127 QTCOMMERCIALCHART_END_NAMESPACE
128 QTCOMMERCIALCHART_END_NAMESPACE
128
129
129 #endif
130 #endif
@@ -1,901 +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
34
34 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35
36
36 /*!
37 /*!
37 \class QAbstractBarSeries
38 \class QAbstractBarSeries
38 \brief Series for creating a bar chart
39 \brief Series for creating a bar chart
39 \mainclass
40 \mainclass
40
41
41 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
42 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
43 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
44 shows the x-values.
45 shows the x-values.
45
46
46 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.
47 \image examples_barchart.png
48 \image examples_barchart.png
48
49
49 \sa QBarSet, QStackedBarSeries, QPercentBarSeries
50 \sa QBarSet, QStackedBarSeries, QPercentBarSeries
50 */
51 */
51 /*!
52 /*!
52 \qmlclass AbstractBarSeries QAbstractBarSeries
53 \qmlclass AbstractBarSeries QAbstractBarSeries
53 \inherits QAbstractSeries
54 \inherits QAbstractSeries
54
55
55 The following QML shows how to create a simple bar chart:
56 The following QML shows how to create a simple bar chart:
56 \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1
57 \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1
57
58
58 \beginfloatleft
59 \beginfloatleft
59 \image demos_qmlchart6.png
60 \image demos_qmlchart6.png
60 \endfloat
61 \endfloat
61 \clearfloat
62 \clearfloat
62 */
63 */
63
64
64 /*!
65 /*!
65 \qmlproperty AbstractAxis AbstractBarSeries::axisX
66 \qmlproperty AbstractAxis AbstractBarSeries::axisX
66 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
67 the series.
68 the series.
68 \sa axisXTop
69 \sa axisXTop
69 */
70 */
70
71
71 /*!
72 /*!
72 \qmlproperty AbstractAxis AbstractBarSeries::axisY
73 \qmlproperty AbstractAxis AbstractBarSeries::axisY
73 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
74 the series.
75 the series.
75 \sa axisYRight
76 \sa axisYRight
76 */
77 */
77
78
78 /*!
79 /*!
79 \qmlproperty AbstractAxis AbstractBarSeries::axisXTop
80 \qmlproperty AbstractAxis AbstractBarSeries::axisXTop
80 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
81 axisXTop, but not both.
82 axisXTop, but not both.
82 \sa axisX
83 \sa axisX
83 */
84 */
84
85
85 /*!
86 /*!
86 \qmlproperty AbstractAxis AbstractBarSeries::axisYRight
87 \qmlproperty AbstractAxis AbstractBarSeries::axisYRight
87 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
88 or axisYRight, but not both.
89 or axisYRight, but not both.
89 \sa axisY
90 \sa axisY
90 */
91 */
91
92
92 /*!
93 /*!
93 \property QAbstractBarSeries::barWidth
94 \property QAbstractBarSeries::barWidth
94 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
95 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
96 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.
97 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.
98 \sa QBarSeries
99 \sa QBarSeries
99 */
100 */
100 /*!
101 /*!
101 \qmlproperty real AbstractBarSeries::barWidth
102 \qmlproperty real AbstractBarSeries::barWidth
102 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
103 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
104 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.
105 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.
106 */
107 */
107
108
108 /*!
109 /*!
109 \property QAbstractBarSeries::count
110 \property QAbstractBarSeries::count
110 Holds the number of sets in series.
111 Holds the number of sets in series.
111 */
112 */
112 /*!
113 /*!
113 \qmlproperty int AbstractBarSeries::count
114 \qmlproperty int AbstractBarSeries::count
114 Holds the number of sets in series.
115 Holds the number of sets in series.
115 */
116 */
116
117
117 /*!
118 /*!
118 \property QAbstractBarSeries::labelsVisible
119 \property QAbstractBarSeries::labelsVisible
119 Defines the visibility of the labels in series
120 Defines the visibility of the labels in series
120 */
121 */
121 /*!
122 /*!
122 \qmlproperty bool AbstractBarSeries::labelsVisible
123 \qmlproperty bool AbstractBarSeries::labelsVisible
123 Defines the visibility of the labels in series
124 Defines the visibility of the labels in series
124 */
125 */
125
126
126 /*!
127 /*!
127 \fn void QAbstractBarSeries::clicked(int index, QBarSet *barset)
128 \fn void QAbstractBarSeries::clicked(int index, QBarSet *barset)
128 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.
129 Clicked bar inside set is indexed by \a index
130 Clicked bar inside set is indexed by \a index
130 */
131 */
131 /*!
132 /*!
132 \qmlsignal AbstractBarSeries::onClicked(int index, BarSet barset)
133 \qmlsignal AbstractBarSeries::onClicked(int index, BarSet barset)
133 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.
134 Clicked bar inside set is indexed by \a index
135 Clicked bar inside set is indexed by \a index
135 */
136 */
136
137
137 /*!
138 /*!
138 \fn void QAbstractBarSeries::hovered(bool status, QBarSet* barset)
139 \fn void QAbstractBarSeries::hovered(bool status, QBarSet* barset)
139
140
140 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.
141 Parameter \a barset is the pointer of barset, where hover happened.
142 Parameter \a barset is the pointer of barset, where hover happened.
142 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.
143 */
144 */
144 /*!
145 /*!
145 \qmlsignal AbstractBarSeries::onHovered(bool status, BarSet barset)
146 \qmlsignal AbstractBarSeries::onHovered(bool status, BarSet barset)
146
147
147 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.
148 Parameter \a barset is the pointer of barset, where hover happened.
149 Parameter \a barset is the pointer of barset, where hover happened.
149 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.
150 */
151 */
151
152
152 /*!
153 /*!
153 \fn void QAbstractBarSeries::countChanged()
154 \fn void QAbstractBarSeries::countChanged()
154 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.
155 */
156 */
156 /*!
157 /*!
157 \qmlsignal AbstractBarSeries::onCountChanged()
158 \qmlsignal AbstractBarSeries::onCountChanged()
158 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.
159 */
160 */
160
161
161 /*!
162 /*!
162 \fn void QAbstractBarSeries::labelsVisibleChanged()
163 \fn void QAbstractBarSeries::labelsVisibleChanged()
163 This signal is emitted when labels visibility have changed.
164 This signal is emitted when labels visibility have changed.
164 \sa isLabelsVisible(), setLabelsVisible()
165 \sa isLabelsVisible(), setLabelsVisible()
165 */
166 */
166
167
167 /*!
168 /*!
168 \fn void QAbstractBarSeries::barsetsAdded(QList<QBarSet*> sets)
169 \fn void QAbstractBarSeries::barsetsAdded(QList<QBarSet*> sets)
169 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.
170 \sa append(), insert()
171 \sa append(), insert()
171 */
172 */
172 /*!
173 /*!
173 \qmlsignal AbstractBarSeries::onBarsetsAdded(BarSet barset)
174 \qmlsignal AbstractBarSeries::onBarsetsAdded(BarSet barset)
174 Emitted when \a barset has been added to the series.
175 Emitted when \a barset has been added to the series.
175 */
176 */
176
177
177 /*!
178 /*!
178 \fn void QAbstractBarSeries::barsetsRemoved(QList<QBarSet*> sets)
179 \fn void QAbstractBarSeries::barsetsRemoved(QList<QBarSet*> sets)
179 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.
180 \sa remove()
181 \sa remove()
181 */
182 */
182 /*!
183 /*!
183 \qmlsignal AbstractBarSeries::onBarsetsRemoved(BarSet barset)
184 \qmlsignal AbstractBarSeries::onBarsetsRemoved(BarSet barset)
184 Emitted when \a barset has been removed from the series.
185 Emitted when \a barset has been removed from the series.
185 */
186 */
186
187
187 /*!
188 /*!
188 \qmlmethod BarSet AbstractBarSeries::at(int index)
189 \qmlmethod BarSet AbstractBarSeries::at(int index)
189 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.
190 */
191 */
191
192
192 /*!
193 /*!
193 \qmlmethod BarSet AbstractBarSeries::append(string label, VariantList values)
194 \qmlmethod BarSet AbstractBarSeries::append(string label, VariantList values)
194 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.
195 For example:
196 For example:
196 \code
197 \code
197 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]);
198 \endcode
199 \endcode
199 */
200 */
200
201
201 /*!
202 /*!
202 \qmlmethod BarSet AbstractBarSeries::insert(int index, string label, VariantList values)
203 \qmlmethod BarSet AbstractBarSeries::insert(int index, string label, VariantList values)
203 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.
204 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
205 appended.
206 appended.
206 \sa AbstractBarSeries::append()
207 \sa AbstractBarSeries::append()
207 */
208 */
208
209
209 /*!
210 /*!
210 \qmlmethod bool AbstractBarSeries::remove(BarSet barset)
211 \qmlmethod bool AbstractBarSeries::remove(BarSet barset)
211 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.
212 */
213 */
213
214
214 /*!
215 /*!
215 \qmlmethod AbstractBarSeries::clear()
216 \qmlmethod AbstractBarSeries::clear()
216 Removes all barsets from the series.
217 Removes all barsets from the series.
217 */
218 */
218
219
219 /*!
220 /*!
220 Destructs abstractbarseries and owned barsets.
221 Destructs abstractbarseries and owned barsets.
221 */
222 */
222 QAbstractBarSeries::~QAbstractBarSeries()
223 QAbstractBarSeries::~QAbstractBarSeries()
223 {
224 {
224
225
225 }
226 }
226
227
227 /*!
228 /*!
228 \internal
229 \internal
229 */
230 */
230 QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &o, QObject *parent)
231 QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &o, QObject *parent)
231 : QAbstractSeries(o, parent)
232 : QAbstractSeries(o, parent)
232 {
233 {
233 Q_D(QAbstractSeries);
234 Q_D(QAbstractSeries);
234 QObject::connect(this, SIGNAL(countChanged()), d, SIGNAL(countChanged()));
235 QObject::connect(this, SIGNAL(countChanged()), d, SIGNAL(countChanged()));
235 }
236 }
236
237
237 /*!
238 /*!
238 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
239 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
240 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.
241 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.
242 */
243 */
243 void QAbstractBarSeries::setBarWidth(qreal width)
244 void QAbstractBarSeries::setBarWidth(qreal width)
244 {
245 {
245 Q_D(QAbstractBarSeries);
246 Q_D(QAbstractBarSeries);
246 d->setBarWidth(width);
247 d->setBarWidth(width);
247 }
248 }
248
249
249 /*!
250 /*!
250 Returns the width of the bars of the series.
251 Returns the width of the bars of the series.
251 \sa setBarWidth()
252 \sa setBarWidth()
252 */
253 */
253 qreal QAbstractBarSeries::barWidth() const
254 qreal QAbstractBarSeries::barWidth() const
254 {
255 {
255 Q_D(const QAbstractBarSeries);
256 Q_D(const QAbstractBarSeries);
256 return d->barWidth();
257 return d->barWidth();
257 }
258 }
258
259
259 /*!
260 /*!
260 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.
261 Returns true, if appending succeeded.
262 Returns true, if appending succeeded.
262 */
263 */
263 bool QAbstractBarSeries::append(QBarSet *set)
264 bool QAbstractBarSeries::append(QBarSet *set)
264 {
265 {
265 Q_D(QAbstractBarSeries);
266 Q_D(QAbstractBarSeries);
266 bool success = d->append(set);
267 bool success = d->append(set);
267 if (success) {
268 if (success) {
268 QList<QBarSet *> sets;
269 QList<QBarSet *> sets;
269 sets.append(set);
270 sets.append(set);
270 set->setParent(this);
271 set->setParent(this);
271 emit barsetsAdded(sets);
272 emit barsetsAdded(sets);
272 emit countChanged();
273 emit countChanged();
273 }
274 }
274 return success;
275 return success;
275 }
276 }
276
277
277 /*!
278 /*!
278 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
279 was successful.
280 was successful.
280 Returns true, if set was removed.
281 Returns true, if set was removed.
281 */
282 */
282 bool QAbstractBarSeries::remove(QBarSet *set)
283 bool QAbstractBarSeries::remove(QBarSet *set)
283 {
284 {
284 Q_D(QAbstractBarSeries);
285 Q_D(QAbstractBarSeries);
285 bool success = d->remove(set);
286 bool success = d->remove(set);
286 if (success) {
287 if (success) {
287 QList<QBarSet *> sets;
288 QList<QBarSet *> sets;
288 sets.append(set);
289 sets.append(set);
289 set->setParent(0);
290 set->setParent(0);
290 emit barsetsRemoved(sets);
291 emit barsetsRemoved(sets);
291 emit countChanged();
292 emit countChanged();
292 delete set;
293 delete set;
293 set = 0;
294 set = 0;
294 }
295 }
295 return success;
296 return success;
296 }
297 }
297
298
298 /*!
299 /*!
299 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.
300
301
301 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
302 parent object to take full ownership.
303 parent object to take full ownership.
303
304
304 Returns true if take was successful.
305 Returns true if take was successful.
305 */
306 */
306 bool QAbstractBarSeries::take(QBarSet *set)
307 bool QAbstractBarSeries::take(QBarSet *set)
307 {
308 {
308 Q_D(QAbstractBarSeries);
309 Q_D(QAbstractBarSeries);
309 bool success = d->remove(set);
310 bool success = d->remove(set);
310 if (success) {
311 if (success) {
311 QList<QBarSet *> sets;
312 QList<QBarSet *> sets;
312 sets.append(set);
313 sets.append(set);
313 emit barsetsRemoved(sets);
314 emit barsetsRemoved(sets);
314 emit countChanged();
315 emit countChanged();
315 }
316 }
316 return success;
317 return success;
317 }
318 }
318
319
319 /*!
320 /*!
320 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.
321 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,
322 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
323 and function returns false.
324 and function returns false.
324 */
325 */
325 bool QAbstractBarSeries::append(QList<QBarSet *> sets)
326 bool QAbstractBarSeries::append(QList<QBarSet *> sets)
326 {
327 {
327 Q_D(QAbstractBarSeries);
328 Q_D(QAbstractBarSeries);
328 bool success = d->append(sets);
329 bool success = d->append(sets);
329 if (success) {
330 if (success) {
330 emit barsetsAdded(sets);
331 emit barsetsAdded(sets);
331 emit countChanged();
332 emit countChanged();
332 }
333 }
333 return success;
334 return success;
334 }
335 }
335
336
336 /*!
337 /*!
337 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.
338 Returns true, if inserting succeeded.
339 Returns true, if inserting succeeded.
339
340
340 */
341 */
341 bool QAbstractBarSeries::insert(int index, QBarSet *set)
342 bool QAbstractBarSeries::insert(int index, QBarSet *set)
342 {
343 {
343 Q_D(QAbstractBarSeries);
344 Q_D(QAbstractBarSeries);
344 bool success = d->insert(index, set);
345 bool success = d->insert(index, set);
345 if (success) {
346 if (success) {
346 QList<QBarSet *> sets;
347 QList<QBarSet *> sets;
347 sets.append(set);
348 sets.append(set);
348 emit barsetsAdded(sets);
349 emit barsetsAdded(sets);
349 emit countChanged();
350 emit countChanged();
350 }
351 }
351 return success;
352 return success;
352 }
353 }
353
354
354 /*!
355 /*!
355 Removes all barsets from the series. Deletes removed sets.
356 Removes all barsets from the series. Deletes removed sets.
356 */
357 */
357 void QAbstractBarSeries::clear()
358 void QAbstractBarSeries::clear()
358 {
359 {
359 Q_D(QAbstractBarSeries);
360 Q_D(QAbstractBarSeries);
360 QList<QBarSet *> sets = barSets();
361 QList<QBarSet *> sets = barSets();
361 bool success = d->remove(sets);
362 bool success = d->remove(sets);
362 if (success) {
363 if (success) {
363 emit barsetsRemoved(sets);
364 emit barsetsRemoved(sets);
364 emit countChanged();
365 emit countChanged();
365 foreach (QBarSet *set, sets)
366 foreach (QBarSet *set, sets)
366 delete set;
367 delete set;
367 }
368 }
368 }
369 }
369
370
370 /*!
371 /*!
371 Returns number of sets in series.
372 Returns number of sets in series.
372 */
373 */
373 int QAbstractBarSeries::count() const
374 int QAbstractBarSeries::count() const
374 {
375 {
375 Q_D(const QAbstractBarSeries);
376 Q_D(const QAbstractBarSeries);
376 return d->m_barSets.count();
377 return d->m_barSets.count();
377 }
378 }
378
379
379 /*!
380 /*!
380 Returns a list of sets in series. Keeps ownership of sets.
381 Returns a list of sets in series. Keeps ownership of sets.
381 */
382 */
382 QList<QBarSet *> QAbstractBarSeries::barSets() const
383 QList<QBarSet *> QAbstractBarSeries::barSets() const
383 {
384 {
384 Q_D(const QAbstractBarSeries);
385 Q_D(const QAbstractBarSeries);
385 return d->m_barSets;
386 return d->m_barSets;
386 }
387 }
387
388
388 /*!
389 /*!
389 Sets the visibility of labels in series to \a visible
390 Sets the visibility of labels in series to \a visible
390 */
391 */
391 void QAbstractBarSeries::setLabelsVisible(bool visible)
392 void QAbstractBarSeries::setLabelsVisible(bool visible)
392 {
393 {
393 Q_D(QAbstractBarSeries);
394 Q_D(QAbstractBarSeries);
394 if (d->m_labelsVisible != visible) {
395 if (d->m_labelsVisible != visible) {
395 d->setLabelsVisible(visible);
396 d->setLabelsVisible(visible);
396 emit labelsVisibleChanged();
397 emit labelsVisibleChanged();
397 }
398 }
398 }
399 }
399
400
400 /*!
401 /*!
401 Returns the visibility of labels
402 Returns the visibility of labels
402 */
403 */
403 bool QAbstractBarSeries::isLabelsVisible() const
404 bool QAbstractBarSeries::isLabelsVisible() const
404 {
405 {
405 Q_D(const QAbstractBarSeries);
406 Q_D(const QAbstractBarSeries);
406 return d->m_labelsVisible;
407 return d->m_labelsVisible;
407 }
408 }
408
409
409 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
410 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
410
411
411 QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) :
412 QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) :
412 QAbstractSeriesPrivate(q),
413 QAbstractSeriesPrivate(q),
413 m_barWidth(0.5), // Default value is 50% of category width
414 m_barWidth(0.5), // Default value is 50% of category width
414 m_labelsVisible(false),
415 m_labelsVisible(false),
415 m_visible(true)
416 m_visible(true)
416 {
417 {
417 }
418 }
418
419
419 int QAbstractBarSeriesPrivate::categoryCount() const
420 int QAbstractBarSeriesPrivate::categoryCount() const
420 {
421 {
421 // No categories defined. return count of longest set.
422 // No categories defined. return count of longest set.
422 int count = 0;
423 int count = 0;
423 for (int i = 0; i < m_barSets.count(); i++) {
424 for (int i = 0; i < m_barSets.count(); i++) {
424 if (m_barSets.at(i)->count() > count)
425 if (m_barSets.at(i)->count() > count)
425 count = m_barSets.at(i)->count();
426 count = m_barSets.at(i)->count();
426 }
427 }
427
428
428 return count;
429 return count;
429 }
430 }
430
431
431 void QAbstractBarSeriesPrivate::setBarWidth(qreal width)
432 void QAbstractBarSeriesPrivate::setBarWidth(qreal width)
432 {
433 {
433 if (width < 0.0)
434 if (width < 0.0)
434 width = 0.0;
435 width = 0.0;
435 m_barWidth = width;
436 m_barWidth = width;
436 emit updatedLayout();
437 emit updatedLayout();
437 }
438 }
438
439
439 qreal QAbstractBarSeriesPrivate::barWidth() const
440 qreal QAbstractBarSeriesPrivate::barWidth() const
440 {
441 {
441 return m_barWidth;
442 return m_barWidth;
442 }
443 }
443
444
444 QBarSet *QAbstractBarSeriesPrivate::barsetAt(int index)
445 QBarSet *QAbstractBarSeriesPrivate::barsetAt(int index)
445 {
446 {
446 return m_barSets.at(index);
447 return m_barSets.at(index);
447 }
448 }
448
449
449 void QAbstractBarSeriesPrivate::setVisible(bool visible)
450 void QAbstractBarSeriesPrivate::setVisible(bool visible)
450 {
451 {
451 m_visible = visible;
452 m_visible = visible;
452 emit visibleChanged();
453 emit visibleChanged();
453 }
454 }
454
455
455 void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible)
456 void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible)
456 {
457 {
457 m_labelsVisible = visible;
458 m_labelsVisible = visible;
458 emit labelsVisibleChanged(visible);
459 emit labelsVisibleChanged(visible);
459 }
460 }
460
461
461 qreal QAbstractBarSeriesPrivate::min()
462 qreal QAbstractBarSeriesPrivate::min()
462 {
463 {
463 if (m_barSets.count() <= 0)
464 if (m_barSets.count() <= 0)
464 return 0;
465 return 0;
465
466
466 qreal min = INT_MAX;
467 qreal min = INT_MAX;
467
468
468 for (int i = 0; i < m_barSets.count(); i++) {
469 for (int i = 0; i < m_barSets.count(); i++) {
469 int categoryCount = m_barSets.at(i)->count();
470 int categoryCount = m_barSets.at(i)->count();
470 for (int j = 0; j < categoryCount; j++) {
471 for (int j = 0; j < categoryCount; j++) {
471 qreal temp = m_barSets.at(i)->at(j);
472 qreal temp = m_barSets.at(i)->at(j);
472 if (temp < min)
473 if (temp < min)
473 min = temp;
474 min = temp;
474 }
475 }
475 }
476 }
476 return min;
477 return min;
477 }
478 }
478
479
479 qreal QAbstractBarSeriesPrivate::max()
480 qreal QAbstractBarSeriesPrivate::max()
480 {
481 {
481 if (m_barSets.count() <= 0)
482 if (m_barSets.count() <= 0)
482 return 0;
483 return 0;
483
484
484 qreal max = INT_MIN;
485 qreal max = INT_MIN;
485
486
486 for (int i = 0; i < m_barSets.count(); i++) {
487 for (int i = 0; i < m_barSets.count(); i++) {
487 int categoryCount = m_barSets.at(i)->count();
488 int categoryCount = m_barSets.at(i)->count();
488 for (int j = 0; j < categoryCount; j++) {
489 for (int j = 0; j < categoryCount; j++) {
489 qreal temp = m_barSets.at(i)->at(j);
490 qreal temp = m_barSets.at(i)->at(j);
490 if (temp > max)
491 if (temp > max)
491 max = temp;
492 max = temp;
492 }
493 }
493 }
494 }
494
495
495 return max;
496 return max;
496 }
497 }
497
498
498 qreal QAbstractBarSeriesPrivate::valueAt(int set, int category)
499 qreal QAbstractBarSeriesPrivate::valueAt(int set, int category)
499 {
500 {
500 if ((set < 0) || (set >= m_barSets.count()))
501 if ((set < 0) || (set >= m_barSets.count()))
501 return 0; // No set, no value.
502 return 0; // No set, no value.
502 else if ((category < 0) || (category >= m_barSets.at(set)->count()))
503 else if ((category < 0) || (category >= m_barSets.at(set)->count()))
503 return 0; // No category, no value.
504 return 0; // No category, no value.
504
505
505 return m_barSets.at(set)->at(category);
506 return m_barSets.at(set)->at(category);
506 }
507 }
507
508
508 qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category)
509 qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category)
509 {
510 {
510 if ((set < 0) || (set >= m_barSets.count()))
511 if ((set < 0) || (set >= m_barSets.count()))
511 return 0; // No set, no value.
512 return 0; // No set, no value.
512 else if ((category < 0) || (category >= m_barSets.at(set)->count()))
513 else if ((category < 0) || (category >= m_barSets.at(set)->count()))
513 return 0; // No category, no value.
514 return 0; // No category, no value.
514
515
515 qreal value = m_barSets.at(set)->at(category);
516 qreal value = m_barSets.at(set)->at(category);
516 qreal sum = categorySum(category);
517 qreal sum = categorySum(category);
517 if (qFuzzyCompare(sum, 0))
518 if (qFuzzyCompare(sum, 0))
518 return 0;
519 return 0;
519
520
520 return value / sum;
521 return value / sum;
521 }
522 }
522
523
523 qreal QAbstractBarSeriesPrivate::categorySum(int category)
524 qreal QAbstractBarSeriesPrivate::categorySum(int category)
524 {
525 {
525 qreal sum(0);
526 qreal sum(0);
526 int count = m_barSets.count(); // Count sets
527 int count = m_barSets.count(); // Count sets
527 for (int set = 0; set < count; set++) {
528 for (int set = 0; set < count; set++) {
528 if (category < m_barSets.at(set)->count())
529 if (category < m_barSets.at(set)->count())
529 sum += m_barSets.at(set)->at(category);
530 sum += m_barSets.at(set)->at(category);
530 }
531 }
531 return sum;
532 return sum;
532 }
533 }
533
534
534 qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category)
535 qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category)
535 {
536 {
536 qreal sum(0);
537 qreal sum(0);
537 int count = m_barSets.count(); // Count sets
538 int count = m_barSets.count(); // Count sets
538 for (int set = 0; set < count; set++) {
539 for (int set = 0; set < count; set++) {
539 if (category < m_barSets.at(set)->count())
540 if (category < m_barSets.at(set)->count())
540 sum += qAbs(m_barSets.at(set)->at(category));
541 sum += qAbs(m_barSets.at(set)->at(category));
541 }
542 }
542 return sum;
543 return sum;
543 }
544 }
544
545
545 qreal QAbstractBarSeriesPrivate::maxCategorySum()
546 qreal QAbstractBarSeriesPrivate::maxCategorySum()
546 {
547 {
547 qreal max = INT_MIN;
548 qreal max = INT_MIN;
548 int count = categoryCount();
549 int count = categoryCount();
549 for (int i = 0; i < count; i++) {
550 for (int i = 0; i < count; i++) {
550 qreal sum = categorySum(i);
551 qreal sum = categorySum(i);
551 if (sum > max)
552 if (sum > max)
552 max = sum;
553 max = sum;
553 }
554 }
554 return max;
555 return max;
555 }
556 }
556
557
557 qreal QAbstractBarSeriesPrivate::minX()
558 qreal QAbstractBarSeriesPrivate::minX()
558 {
559 {
559 if (m_barSets.count() <= 0)
560 if (m_barSets.count() <= 0)
560 return 0;
561 return 0;
561
562
562 qreal min = INT_MAX;
563 qreal min = INT_MAX;
563
564
564 for (int i = 0; i < m_barSets.count(); i++) {
565 for (int i = 0; i < m_barSets.count(); i++) {
565 int categoryCount = m_barSets.at(i)->count();
566 int categoryCount = m_barSets.at(i)->count();
566 for (int j = 0; j < categoryCount; j++) {
567 for (int j = 0; j < categoryCount; j++) {
567 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();
568 if (temp < min)
569 if (temp < min)
569 min = temp;
570 min = temp;
570 }
571 }
571 }
572 }
572 return min;
573 return min;
573 }
574 }
574
575
575 qreal QAbstractBarSeriesPrivate::maxX()
576 qreal QAbstractBarSeriesPrivate::maxX()
576 {
577 {
577 if (m_barSets.count() <= 0)
578 if (m_barSets.count() <= 0)
578 return 0;
579 return 0;
579
580
580 qreal max = INT_MIN;
581 qreal max = INT_MIN;
581
582
582 for (int i = 0; i < m_barSets.count(); i++) {
583 for (int i = 0; i < m_barSets.count(); i++) {
583 int categoryCount = m_barSets.at(i)->count();
584 int categoryCount = m_barSets.at(i)->count();
584 for (int j = 0; j < categoryCount; j++) {
585 for (int j = 0; j < categoryCount; j++) {
585 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();
586 if (temp > max)
587 if (temp > max)
587 max = temp;
588 max = temp;
588 }
589 }
589 }
590 }
590
591
591 return max;
592 return max;
592 }
593 }
593
594
594 qreal QAbstractBarSeriesPrivate::categoryTop(int category)
595 qreal QAbstractBarSeriesPrivate::categoryTop(int category)
595 {
596 {
596 // Returns top (sum of all positive values) of category.
597 // Returns top (sum of all positive values) of category.
597 // Returns 0, if all values are negative
598 // Returns 0, if all values are negative
598 qreal top(0);
599 qreal top(0);
599 int count = m_barSets.count();
600 int count = m_barSets.count();
600 for (int set = 0; set < count; set++) {
601 for (int set = 0; set < count; set++) {
601 if (category < m_barSets.at(set)->count()) {
602 if (category < m_barSets.at(set)->count()) {
602 qreal temp = m_barSets.at(set)->at(category);
603 qreal temp = m_barSets.at(set)->at(category);
603 if (temp > 0) {
604 if (temp > 0) {
604 top += temp;
605 top += temp;
605 }
606 }
606 }
607 }
607 }
608 }
608 return top;
609 return top;
609 }
610 }
610
611
611 qreal QAbstractBarSeriesPrivate::categoryBottom(int category)
612 qreal QAbstractBarSeriesPrivate::categoryBottom(int category)
612 {
613 {
613 // Returns bottom (sum of all negative values) of category
614 // Returns bottom (sum of all negative values) of category
614 // Returns 0, if all values are positive
615 // Returns 0, if all values are positive
615 qreal bottom(0);
616 qreal bottom(0);
616 int count = m_barSets.count();
617 int count = m_barSets.count();
617 for (int set = 0; set < count; set++) {
618 for (int set = 0; set < count; set++) {
618 if (category < m_barSets.at(set)->count()) {
619 if (category < m_barSets.at(set)->count()) {
619 qreal temp = m_barSets.at(set)->at(category);
620 qreal temp = m_barSets.at(set)->at(category);
620 if (temp < 0) {
621 if (temp < 0) {
621 bottom += temp;
622 bottom += temp;
622 }
623 }
623 }
624 }
624 }
625 }
625 return bottom;
626 return bottom;
626 }
627 }
627
628
628 qreal QAbstractBarSeriesPrivate::top()
629 qreal QAbstractBarSeriesPrivate::top()
629 {
630 {
630 // Returns top of all categories
631 // Returns top of all categories
631 qreal top(0);
632 qreal top(0);
632 int count = categoryCount();
633 int count = categoryCount();
633 for (int i = 0; i < count; i++) {
634 for (int i = 0; i < count; i++) {
634 qreal temp = categoryTop(i);
635 qreal temp = categoryTop(i);
635 if (temp > top)
636 if (temp > top)
636 top = temp;
637 top = temp;
637 }
638 }
638 return top;
639 return top;
639 }
640 }
640
641
641 qreal QAbstractBarSeriesPrivate::bottom()
642 qreal QAbstractBarSeriesPrivate::bottom()
642 {
643 {
643 // Returns bottom of all categories
644 // Returns bottom of all categories
644 qreal bottom(0);
645 qreal bottom(0);
645 int count = categoryCount();
646 int count = categoryCount();
646 for (int i = 0; i < count; i++) {
647 for (int i = 0; i < count; i++) {
647 qreal temp = categoryBottom(i);
648 qreal temp = categoryBottom(i);
648 if (temp < bottom)
649 if (temp < bottom)
649 bottom = temp;
650 bottom = temp;
650 }
651 }
651 return bottom;
652 return bottom;
652 }
653 }
653
654
654
655
655 void QAbstractBarSeriesPrivate::initializeDomain()
656 void QAbstractBarSeriesPrivate::initializeDomain()
656 {
657 {
657 qreal minX(domain()->minX());
658 qreal minX(domain()->minX());
658 qreal minY(domain()->minY());
659 qreal minY(domain()->minY());
659 qreal maxX(domain()->maxX());
660 qreal maxX(domain()->maxX());
660 qreal maxY(domain()->maxY());
661 qreal maxY(domain()->maxY());
661
662
662 qreal seriesMinX = this->minX();
663 qreal seriesMinX = this->minX();
663 qreal seriesMaxX = this->maxX();
664 qreal seriesMaxX = this->maxX();
664 qreal y = max();
665 qreal y = max();
665 minX = qMin(minX, seriesMinX - (qreal)0.5);
666 minX = qMin(minX, seriesMinX - (qreal)0.5);
666 minY = qMin(minY, y);
667 minY = qMin(minY, y);
667 maxX = qMax(maxX, seriesMaxX + (qreal)0.5);
668 maxX = qMax(maxX, seriesMaxX + (qreal)0.5);
668 maxY = qMax(maxY, y);
669 maxY = qMax(maxY, y);
669
670
670 domain()->setRange(minX, maxX, minY, maxY);
671 domain()->setRange(minX, maxX, minY, maxY);
671 }
672 }
672
673
673 QList<QLegendMarker*> QAbstractBarSeriesPrivate::createLegendMarkers(QLegend* legend)
674 QList<QLegendMarker*> QAbstractBarSeriesPrivate::createLegendMarkers(QLegend* legend)
674 {
675 {
675 Q_Q(QAbstractBarSeries);
676 Q_Q(QAbstractBarSeries);
676 QList<QLegendMarker*> markers;
677 QList<QLegendMarker*> markers;
677
678
678 foreach(QBarSet* set, q->barSets()) {
679 foreach(QBarSet* set, q->barSets()) {
679 QBarLegendMarker* marker = new QBarLegendMarker(q,set,legend);
680 QBarLegendMarker* marker = new QBarLegendMarker(q,set,legend);
680 markers << marker;
681 markers << marker;
681 }
682 }
682 return markers;
683 return markers;
683 }
684 }
684
685
685
686
686 bool QAbstractBarSeriesPrivate::append(QBarSet *set)
687 bool QAbstractBarSeriesPrivate::append(QBarSet *set)
687 {
688 {
688 if ((m_barSets.contains(set)) || (set == 0))
689 if ((m_barSets.contains(set)) || (set == 0))
689 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.
690
691
691 m_barSets.append(set);
692 m_barSets.append(set);
692 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
693 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
693 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
694 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
694 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
695 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
695
696
696 emit restructuredBars(); // this notifies barchartitem
697 emit restructuredBars(); // this notifies barchartitem
697 return true;
698 return true;
698 }
699 }
699
700
700 bool QAbstractBarSeriesPrivate::remove(QBarSet *set)
701 bool QAbstractBarSeriesPrivate::remove(QBarSet *set)
701 {
702 {
702 if (!m_barSets.contains(set))
703 if (!m_barSets.contains(set))
703 return false; // Fail if set is not in list
704 return false; // Fail if set is not in list
704
705
705 m_barSets.removeOne(set);
706 m_barSets.removeOne(set);
706 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
707 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
707 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
708 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
708 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
709 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
709
710
710 emit restructuredBars(); // this notifies barchartitem
711 emit restructuredBars(); // this notifies barchartitem
711 return true;
712 return true;
712 }
713 }
713
714
714 bool QAbstractBarSeriesPrivate::append(QList<QBarSet * > sets)
715 bool QAbstractBarSeriesPrivate::append(QList<QBarSet * > sets)
715 {
716 {
716 foreach (QBarSet *set, sets) {
717 foreach (QBarSet *set, sets) {
717 if ((set == 0) || (m_barSets.contains(set)))
718 if ((set == 0) || (m_barSets.contains(set)))
718 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.
719 if (sets.count(set) != 1)
720 if (sets.count(set) != 1)
720 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.
721 }
722 }
722
723
723 foreach (QBarSet *set, sets) {
724 foreach (QBarSet *set, sets) {
724 m_barSets.append(set);
725 m_barSets.append(set);
725 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
726 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
726 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
727 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
727 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
728 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
728 }
729 }
729
730
730 emit restructuredBars(); // this notifies barchartitem
731 emit restructuredBars(); // this notifies barchartitem
731 return true;
732 return true;
732 }
733 }
733
734
734 bool QAbstractBarSeriesPrivate::remove(QList<QBarSet * > sets)
735 bool QAbstractBarSeriesPrivate::remove(QList<QBarSet * > sets)
735 {
736 {
736 if (sets.count() == 0)
737 if (sets.count() == 0)
737 return false;
738 return false;
738
739
739 foreach (QBarSet *set, sets) {
740 foreach (QBarSet *set, sets) {
740 if ((set == 0) || (!m_barSets.contains(set)))
741 if ((set == 0) || (!m_barSets.contains(set)))
741 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
742 if (sets.count(set) != 1)
743 if (sets.count(set) != 1)
743 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.
744 }
745 }
745
746
746 foreach (QBarSet *set, sets) {
747 foreach (QBarSet *set, sets) {
747 m_barSets.removeOne(set);
748 m_barSets.removeOne(set);
748 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
749 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
749 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
750 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
750 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
751 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
751 }
752 }
752
753
753 emit restructuredBars(); // this notifies barchartitem
754 emit restructuredBars(); // this notifies barchartitem
754
755
755 return true;
756 return true;
756 }
757 }
757
758
758 bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set)
759 bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set)
759 {
760 {
760 if ((m_barSets.contains(set)) || (set == 0))
761 if ((m_barSets.contains(set)) || (set == 0))
761 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.
762
763
763 m_barSets.insert(index, set);
764 m_barSets.insert(index, set);
764 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
765 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
765 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
766 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
766 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
767 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
767
768
768 emit restructuredBars(); // this notifies barchartitem
769 emit restructuredBars(); // this notifies barchartitem
769 return true;
770 return true;
770 }
771 }
771
772
772 void QAbstractBarSeriesPrivate::initializeAxes()
773 void QAbstractBarSeriesPrivate::initializeAxes()
773 {
774 {
774 Q_Q(QAbstractBarSeries);
775 Q_Q(QAbstractBarSeries);
775
776
776 foreach(QAbstractAxis* axis, m_axes) {
777 foreach(QAbstractAxis* axis, m_axes) {
777
778
778 if (axis->type() == QAbstractAxis::AxisTypeBarCategory) {
779 if (axis->type() == QAbstractAxis::AxisTypeBarCategory) {
779 switch (q->type()) {
780 switch (q->type()) {
780 case QAbstractSeries::SeriesTypeHorizontalBar:
781 case QAbstractSeries::SeriesTypeHorizontalBar:
781 case QAbstractSeries::SeriesTypeHorizontalPercentBar:
782 case QAbstractSeries::SeriesTypeHorizontalPercentBar:
782 case QAbstractSeries::SeriesTypeHorizontalStackedBar:
783 case QAbstractSeries::SeriesTypeHorizontalStackedBar:
783 if (axis->orientation() == Qt::Vertical)
784 if (axis->orientation() == Qt::Vertical)
784 populateCategories(qobject_cast<QBarCategoryAxis *>(axis));
785 populateCategories(qobject_cast<QBarCategoryAxis *>(axis));
785 break;
786 break;
786 case QAbstractSeries::SeriesTypeBar:
787 case QAbstractSeries::SeriesTypeBar:
787 case QAbstractSeries::SeriesTypePercentBar:
788 case QAbstractSeries::SeriesTypePercentBar:
788 case QAbstractSeries::SeriesTypeStackedBar:
789 case QAbstractSeries::SeriesTypeStackedBar:
789 if (axis->orientation() == Qt::Horizontal)
790 if (axis->orientation() == Qt::Horizontal)
790 populateCategories(qobject_cast<QBarCategoryAxis *>(axis));
791 populateCategories(qobject_cast<QBarCategoryAxis *>(axis));
791 break;
792 break;
792 default:
793 default:
793 qWarning() << "Unexpected series type";
794 qWarning() << "Unexpected series type";
794 break;
795 break;
795 }
796 }
796 }
797 }
797 }
798 }
798 }
799 }
799
800
800 QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
801 QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
801 {
802 {
802 Q_Q(const QAbstractBarSeries);
803 Q_Q(const QAbstractBarSeries);
803
804
804 switch (q->type()) {
805 switch (q->type()) {
805 case QAbstractSeries::SeriesTypeHorizontalBar:
806 case QAbstractSeries::SeriesTypeHorizontalBar:
806 case QAbstractSeries::SeriesTypeHorizontalPercentBar:
807 case QAbstractSeries::SeriesTypeHorizontalPercentBar:
807 case QAbstractSeries::SeriesTypeHorizontalStackedBar:
808 case QAbstractSeries::SeriesTypeHorizontalStackedBar:
808 if (orientation == Qt::Vertical)
809 if (orientation == Qt::Vertical)
809 return QAbstractAxis::AxisTypeBarCategory;
810 return QAbstractAxis::AxisTypeBarCategory;
810 break;
811 break;
811 case QAbstractSeries::SeriesTypeBar:
812 case QAbstractSeries::SeriesTypeBar:
812 case QAbstractSeries::SeriesTypePercentBar:
813 case QAbstractSeries::SeriesTypePercentBar:
813 case QAbstractSeries::SeriesTypeStackedBar:
814 case QAbstractSeries::SeriesTypeStackedBar:
814 if (orientation == Qt::Horizontal)
815 if (orientation == Qt::Horizontal)
815 return QAbstractAxis::AxisTypeBarCategory;
816 return QAbstractAxis::AxisTypeBarCategory;
816 break;
817 break;
817 default:
818 default:
818 qWarning() << "Unexpected series type";
819 qWarning() << "Unexpected series type";
819 break;
820 break;
820 }
821 }
821 return QAbstractAxis::AxisTypeValue;
822 return QAbstractAxis::AxisTypeValue;
822
823
823 }
824 }
824
825
825 void QAbstractBarSeriesPrivate::populateCategories(QBarCategoryAxis *axis)
826 void QAbstractBarSeriesPrivate::populateCategories(QBarCategoryAxis *axis)
826 {
827 {
827 QStringList categories;
828 QStringList categories;
828 if (axis->categories().isEmpty()) {
829 if (axis->categories().isEmpty()) {
829 for (int i(1); i < categoryCount() + 1; i++)
830 for (int i(1); i < categoryCount() + 1; i++)
830 categories << QString::number(i);
831 categories << QString::number(i);
831 axis->append(categories);
832 axis->append(categories);
832 }
833 }
833 }
834 }
834
835
835 QAbstractAxis* QAbstractBarSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const
836 QAbstractAxis* QAbstractBarSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const
836 {
837 {
837 Q_UNUSED(orientation);
838 Q_UNUSED(orientation);
838 return 0;
839 return 0;
839 }
840 }
840
841
841 void QAbstractBarSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced)
842 void QAbstractBarSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced)
842 {
843 {
843 const QList<QGradient> gradients = theme->seriesGradients();
844 const QList<QGradient> gradients = theme->seriesGradients();
844
845
845 QBrush brush;
846 QPen pen;
847
848 qreal takeAtPos = 0.5;
846 qreal takeAtPos = 0.5;
849 qreal step = 0.2;
847 qreal step = 0.2;
850 if (m_barSets.count() > 1) {
848 if (m_barSets.count() > 1) {
851 step = 1.0 / (qreal) m_barSets.count();
849 step = 1.0 / (qreal) m_barSets.count();
852 if (m_barSets.count() % gradients.count())
850 if (m_barSets.count() % gradients.count())
853 step *= gradients.count();
851 step *= gradients.count();
854 else
852 else
855 step *= (gradients.count() - 1);
853 step *= (gradients.count() - 1);
856 }
854 }
857
855
858 for (int i(0); i < m_barSets.count(); i++) {
856 for (int i(0); i < m_barSets.count(); i++) {
859 int colorIndex = (index + i) % gradients.count();
857 int colorIndex = (index + i) % gradients.count();
860 if (i > 0 && i %gradients.count() == 0) {
858 if (i > 0 && i %gradients.count() == 0) {
861 // 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
862 takeAtPos += step;
860 takeAtPos += step;
863 if (takeAtPos == 1.0)
861 if (takeAtPos == 1.0)
864 takeAtPos += step;
862 takeAtPos += step;
865 takeAtPos -= (int) takeAtPos;
863 takeAtPos -= (int) takeAtPos;
866 }
864 }
867 if (forced || brush == m_barSets.at(i)->brush())
865 if (forced || QChartPrivate::defaultBrush() == m_barSets.at(i)->brush())
868 m_barSets.at(i)->setBrush(ChartThemeManager::colorAt(gradients.at(colorIndex), takeAtPos));
866 m_barSets.at(i)->setBrush(ChartThemeManager::colorAt(gradients.at(colorIndex), takeAtPos));
869
867
870 // Pick label color from the opposite end of the gradient.
868 // Pick label color from the opposite end of the gradient.
871 // 0.3 as a boundary seems to work well.
869 // 0.3 as a boundary seems to work well.
872 if (forced || brush == m_barSets.at(i)->labelBrush()) {
870 if (forced || QChartPrivate::defaultBrush() == m_barSets.at(i)->labelBrush()) {
873 if (takeAtPos < 0.3)
871 if (takeAtPos < 0.3)
874 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));
875 else
873 else
876 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));
877 }
875 }
878
876
879 if (forced || pen == m_barSets.at(i)->pen()) {
877 if (forced || QChartPrivate::defaultPen() == m_barSets.at(i)->pen()) {
880 QColor c = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.0);
878 QColor c = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.0);
881 m_barSets.at(i)->setPen(c);
879 m_barSets.at(i)->setPen(c);
882 }
880 }
883 }
881 }
884 }
882 }
885
883
886 void QAbstractBarSeriesPrivate::initializeAnimations(QChart::AnimationOptions options)
884 void QAbstractBarSeriesPrivate::initializeAnimations(QChart::AnimationOptions options)
887 {
885 {
888 AbstractBarChartItem *bar = static_cast<AbstractBarChartItem *>(m_item.data());
886 AbstractBarChartItem *bar = static_cast<AbstractBarChartItem *>(m_item.data());
889 Q_ASSERT(bar);
887 Q_ASSERT(bar);
890 if (options.testFlag(QChart::SeriesAnimations)) {
888 if (options.testFlag(QChart::SeriesAnimations)) {
891 bar->setAnimation(new BarAnimation(bar));
889 bar->setAnimation(new BarAnimation(bar));
892 }else{
890 }else{
893 bar->setAnimation(0);
891 bar->setAnimation(0);
894 }
892 }
895 QAbstractSeriesPrivate::initializeAnimations(options);
893 QAbstractSeriesPrivate::initializeAnimations(options);
896 }
894 }
897
895
898 #include "moc_qabstractbarseries.cpp"
896 #include "moc_qabstractbarseries.cpp"
899 #include "moc_qabstractbarseries_p.cpp"
897 #include "moc_qabstractbarseries_p.cpp"
900
898
901 QTCOMMERCIALCHART_END_NAMESPACE
899 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,645 +1,649
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
25
25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26
27
27 /*!
28 /*!
28 \class QBarSet
29 \class QBarSet
29 \brief Building block for different bar charts
30 \brief Building block for different bar charts
30
31
31 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.
32 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.
33 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
34 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.
35
36
36 \mainclass
37 \mainclass
37
38
38 \sa QAbstractBarSeries, QBarSeries, QStackedBarSeries, QPercentBarSeries
39 \sa QAbstractBarSeries, QBarSeries, QStackedBarSeries, QPercentBarSeries
39 */
40 */
40 /*!
41 /*!
41 \qmlclass BarSet QBarSet
42 \qmlclass BarSet QBarSet
42
43
43 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.
44 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.
45 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
46 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.
47 \sa AbstractBarSeries, BarSeries, StackedBarSeries, PercentBarSeries
48 \sa AbstractBarSeries, BarSeries, StackedBarSeries, PercentBarSeries
48 */
49 */
49
50
50 /*!
51 /*!
51 \property QBarSet::label
52 \property QBarSet::label
52 Defines the label of the barSet.
53 Defines the label of the barSet.
53 */
54 */
54 /*!
55 /*!
55 \qmlproperty string BarSet::label
56 \qmlproperty string BarSet::label
56 Defines the label of the barSet.
57 Defines the label of the barSet.
57 */
58 */
58
59
59 /*!
60 /*!
60 \property QBarSet::pen
61 \property QBarSet::pen
61 \brief Defines the pen used by the barSet.
62 \brief Defines the pen used by the barSet.
62 */
63 */
63
64
64 /*!
65 /*!
65 \property QBarSet::brush
66 \property QBarSet::brush
66 \brief Defines the brush used by the barSet.
67 \brief Defines the brush used by the barSet.
67 */
68 */
68
69
69 /*!
70 /*!
70 \property QBarSet::labelBrush
71 \property QBarSet::labelBrush
71 \brief Defines the brush used by the barSet's label.
72 \brief Defines the brush used by the barSet's label.
72 */
73 */
73
74
74 /*!
75 /*!
75 \property QBarSet::labelFont
76 \property QBarSet::labelFont
76 \brief Defines the font used by the barSet's label.
77 \brief Defines the font used by the barSet's label.
77 */
78 */
78
79
79 /*!
80 /*!
80 \qmlproperty Font BarSet::labelFont
81 \qmlproperty Font BarSet::labelFont
81 Defines the font used by the barSet's label.
82 Defines the font used by the barSet's label.
82
83
83 See the \l {Font} {QML Font Element} for detailed documentation.
84 See the \l {Font} {QML Font Element} for detailed documentation.
84 */
85 */
85
86
86 /*!
87 /*!
87 \property QBarSet::color
88 \property QBarSet::color
88 The fill (brush) color of the bar set.
89 The fill (brush) color of the bar set.
89 */
90 */
90 /*!
91 /*!
91 \qmlproperty color BarSet::color
92 \qmlproperty color BarSet::color
92 The fill (brush) color of the bar set.
93 The fill (brush) color of the bar set.
93 */
94 */
94
95
95 /*!
96 /*!
96 \property QBarSet::borderColor
97 \property QBarSet::borderColor
97 The line (pen) color of the bar set.
98 The line (pen) color of the bar set.
98 */
99 */
99 /*!
100 /*!
100 \qmlproperty color BarSet::borderColor
101 \qmlproperty color BarSet::borderColor
101 The line (pen) color of the bar set.
102 The line (pen) color of the bar set.
102 */
103 */
103
104
104 /*!
105 /*!
105 \qmlproperty real BarSet::borderWidth
106 \qmlproperty real BarSet::borderWidth
106 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.
107 */
108 */
108
109
109 /*!
110 /*!
110 \property QBarSet::labelColor
111 \property QBarSet::labelColor
111 The text (label) color of the bar set.
112 The text (label) color of the bar set.
112 */
113 */
113 /*!
114 /*!
114 \qmlproperty color BarSet::labelColor
115 \qmlproperty color BarSet::labelColor
115 The text (label) color of the bar set.
116 The text (label) color of the bar set.
116 */
117 */
117
118
118 /*!
119 /*!
119 \fn void QBarSet::clicked(int index)
120 \fn void QBarSet::clicked(int index)
120
121
121 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.
122 Clicked bar inside set is indexed by \a index
123 Clicked bar inside set is indexed by \a index
123 */
124 */
124
125
125 /*!
126 /*!
126 \fn void QBarSet::hovered(bool status)
127 \fn void QBarSet::hovered(bool status)
127
128
128 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.
129 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.
130 */
131 */
131
132
132
133
133 /*!
134 /*!
134 \fn void QBarSet::labelChanged()
135 \fn void QBarSet::labelChanged()
135 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.
136 \sa label
137 \sa label
137 */
138 */
138 /*!
139 /*!
139 \qmlsignal BarSet::onLabelChanged()
140 \qmlsignal BarSet::onLabelChanged()
140 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.
141 */
142 */
142
143
143 /*!
144 /*!
144 \fn void QBarSet::penChanged()
145 \fn void QBarSet::penChanged()
145 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.
146 \sa pen
147 \sa pen
147 */
148 */
148
149
149 /*!
150 /*!
150 \fn void QBarSet::brushChanged()
151 \fn void QBarSet::brushChanged()
151 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.
152 \sa brush
153 \sa brush
153 */
154 */
154
155
155 /*!
156 /*!
156 \fn void QBarSet::labelBrushChanged()
157 \fn void QBarSet::labelBrushChanged()
157 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.
158 \sa labelBrush
159 \sa labelBrush
159 */
160 */
160
161
161 /*!
162 /*!
162 \fn void QBarSet::labelFontChanged()
163 \fn void QBarSet::labelFontChanged()
163 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.
164 \sa labelBrush
165 \sa labelBrush
165 */
166 */
166
167
167 /*!
168 /*!
168 \fn void QBarSet::colorChanged(QColor)
169 \fn void QBarSet::colorChanged(QColor)
169 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.
170 */
171 */
171 /*!
172 /*!
172 \qmlsignal BarSet::onColorChanged(color color)
173 \qmlsignal BarSet::onColorChanged(color color)
173 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.
174 */
175 */
175
176
176 /*!
177 /*!
177 \fn void QBarSet::borderColorChanged(QColor)
178 \fn void QBarSet::borderColorChanged(QColor)
178 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.
179 */
180 */
180 /*!
181 /*!
181 \qmlsignal BarSet::onBorderColorChanged(color color)
182 \qmlsignal BarSet::onBorderColorChanged(color color)
182 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.
183 */
184 */
184
185
185 /*!
186 /*!
186 \fn void QBarSet::labelColorChanged(QColor)
187 \fn void QBarSet::labelColorChanged(QColor)
187 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.
188 */
189 */
189 /*!
190 /*!
190 \qmlsignal BarSet::onLabelColorChanged(color color)
191 \qmlsignal BarSet::onLabelColorChanged(color color)
191 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.
192 */
193 */
193
194
194 /*!
195 /*!
195 \fn void QBarSet::valuesAdded(int index, int count)
196 \fn void QBarSet::valuesAdded(int index, int count)
196 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.
197 Parameter \a index indicates the position of the first inserted value.
198 Parameter \a index indicates the position of the first inserted value.
198 Parameter \a count is the number of inserted values.
199 Parameter \a count is the number of inserted values.
199 \sa append(), insert()
200 \sa append(), insert()
200 */
201 */
201 /*!
202 /*!
202 \qmlsignal BarSet::onValuesAdded(int index, int count)
203 \qmlsignal BarSet::onValuesAdded(int index, int count)
203 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.
204 Parameter \a index indicates the position of the first inserted value.
205 Parameter \a index indicates the position of the first inserted value.
205 Parameter \a count is the number of inserted values.
206 Parameter \a count is the number of inserted values.
206 */
207 */
207
208
208 /*!
209 /*!
209 \fn void QBarSet::valuesRemoved(int index, int count)
210 \fn void QBarSet::valuesRemoved(int index, int count)
210 This signal is emitted values have been removed from the set.
211 This signal is emitted values have been removed from the set.
211 Parameter \a index indicates the position of the first removed value.
212 Parameter \a index indicates the position of the first removed value.
212 Parameter \a count is the number of removed values.
213 Parameter \a count is the number of removed values.
213 \sa remove()
214 \sa remove()
214 */
215 */
215 /*!
216 /*!
216 \qmlsignal BarSet::onValuesRemoved(int index, int count)
217 \qmlsignal BarSet::onValuesRemoved(int index, int count)
217 This signal is emitted values have been removed from the set.
218 This signal is emitted values have been removed from the set.
218 Parameter \a index indicates the position of the first removed value.
219 Parameter \a index indicates the position of the first removed value.
219 Parameter \a count is the number of removed values.
220 Parameter \a count is the number of removed values.
220 */
221 */
221
222
222 /*!
223 /*!
223 \fn void QBarSet::valueChanged(int index)
224 \fn void QBarSet::valueChanged(int index)
224 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.
225 Parameter \a index indicates the position of the modified value.
226 Parameter \a index indicates the position of the modified value.
226 \sa at()
227 \sa at()
227 */
228 */
228 /*!
229 /*!
229 \qmlsignal BarSet::onValueChanged(int index)
230 \qmlsignal BarSet::onValueChanged(int index)
230 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.
231 Parameter \a index indicates the position of the modified value.
232 Parameter \a index indicates the position of the modified value.
232 */
233 */
233
234
234 /*!
235 /*!
235 \qmlproperty int BarSet::count
236 \qmlproperty int BarSet::count
236 The count of values on the barset
237 The count of values on the barset
237 */
238 */
238
239
239 /*!
240 /*!
240 \qmlproperty QVariantList BarSet::values
241 \qmlproperty QVariantList BarSet::values
241 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
242 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
243 x-coordinate. For example:
244 x-coordinate. For example:
244 \code
245 \code
245 myBarSet1.values = [0, 5, 1, 5];
246 myBarSet1.values = [0, 5, 1, 5];
246 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)];
247 \endcode
248 \endcode
248 */
249 */
249
250
250 /*!
251 /*!
251 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.
252 */
253 */
253 QBarSet::QBarSet(const QString label, QObject *parent)
254 QBarSet::QBarSet(const QString label, QObject *parent)
254 : QObject(parent),
255 : QObject(parent),
255 d_ptr(new QBarSetPrivate(label, this))
256 d_ptr(new QBarSetPrivate(label, this))
256 {
257 {
257 }
258 }
258
259
259 /*!
260 /*!
260 Destroys the barset.
261 Destroys the barset.
261 */
262 */
262 QBarSet::~QBarSet()
263 QBarSet::~QBarSet()
263 {
264 {
264 // NOTE: d_ptr destroyed by QObject
265 // NOTE: d_ptr destroyed by QObject
265 }
266 }
266
267
267 /*!
268 /*!
268 Sets new \a label for set.
269 Sets new \a label for set.
269 */
270 */
270 void QBarSet::setLabel(const QString label)
271 void QBarSet::setLabel(const QString label)
271 {
272 {
272 d_ptr->m_label = label;
273 d_ptr->m_label = label;
273 emit labelChanged();
274 emit labelChanged();
274 }
275 }
275
276
276 /*!
277 /*!
277 Returns label of the set.
278 Returns label of the set.
278 */
279 */
279 QString QBarSet::label() const
280 QString QBarSet::label() const
280 {
281 {
281 return d_ptr->m_label;
282 return d_ptr->m_label;
282 }
283 }
283
284
284 /*!
285 /*!
285 Appends new value \a value to the end of set.
286 Appends new value \a value to the end of set.
286 */
287 */
287 void QBarSet::append(const qreal value)
288 void QBarSet::append(const qreal value)
288 {
289 {
289 // Convert to QPointF
290 // Convert to QPointF
290 int index = d_ptr->m_values.count();
291 int index = d_ptr->m_values.count();
291 d_ptr->append(QPointF(d_ptr->m_values.count(), value));
292 d_ptr->append(QPointF(d_ptr->m_values.count(), value));
292 emit valuesAdded(index, 1);
293 emit valuesAdded(index, 1);
293 }
294 }
294
295
295 /*!
296 /*!
296 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
297 are appended to end of barset
298 are appended to end of barset
298 \sa append()
299 \sa append()
299 */
300 */
300 void QBarSet::append(const QList<qreal> &values)
301 void QBarSet::append(const QList<qreal> &values)
301 {
302 {
302 int index = d_ptr->m_values.count();
303 int index = d_ptr->m_values.count();
303 d_ptr->append(values);
304 d_ptr->append(values);
304 emit valuesAdded(index, values.count());
305 emit valuesAdded(index, values.count());
305 }
306 }
306
307
307 /*!
308 /*!
308 Convenience operator. Same as append, with real \a value.
309 Convenience operator. Same as append, with real \a value.
309 \sa append()
310 \sa append()
310 */
311 */
311 QBarSet &QBarSet::operator << (const qreal &value)
312 QBarSet &QBarSet::operator << (const qreal &value)
312 {
313 {
313 append(value);
314 append(value);
314 return *this;
315 return *this;
315 }
316 }
316
317
317 /*!
318 /*!
318 Inserts new \a value on the \a index position.
319 Inserts new \a value on the \a index position.
319 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
320 \sa remove()
321 \sa remove()
321 */
322 */
322 void QBarSet::insert(const int index, const qreal value)
323 void QBarSet::insert(const int index, const qreal value)
323 {
324 {
324 d_ptr->insert(index, value);
325 d_ptr->insert(index, value);
325 emit valuesAdded(index, 1);
326 emit valuesAdded(index, 1);
326 }
327 }
327
328
328 /*!
329 /*!
329 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.
330 \sa insert()
331 \sa insert()
331 */
332 */
332 void QBarSet::remove(const int index, const int count)
333 void QBarSet::remove(const int index, const int count)
333 {
334 {
334 int removedCount = d_ptr->remove(index, count);
335 int removedCount = d_ptr->remove(index, count);
335 if (removedCount > 0)
336 if (removedCount > 0)
336 emit valuesRemoved(index, removedCount);
337 emit valuesRemoved(index, removedCount);
337 return;
338 return;
338 }
339 }
339
340
340 /*!
341 /*!
341 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.
342 */
343 */
343 void QBarSet::replace(const int index, const qreal value)
344 void QBarSet::replace(const int index, const qreal value)
344 {
345 {
345 if (index >= 0 && index < d_ptr->m_values.count()) {
346 if (index >= 0 && index < d_ptr->m_values.count()) {
346 d_ptr->replace(index, value);
347 d_ptr->replace(index, value);
347 emit valueChanged(index);
348 emit valueChanged(index);
348 }
349 }
349 }
350 }
350
351
351
352
352 /*!
353 /*!
353 Returns value of set indexed by \a index.
354 Returns value of set indexed by \a index.
354 If the index is out of bounds 0.0 is returned.
355 If the index is out of bounds 0.0 is returned.
355 */
356 */
356 qreal QBarSet::at(const int index) const
357 qreal QBarSet::at(const int index) const
357 {
358 {
358 if (index < 0 || index >= d_ptr->m_values.count())
359 if (index < 0 || index >= d_ptr->m_values.count())
359 return 0;
360 return 0;
360 return d_ptr->m_values.at(index).y();
361 return d_ptr->m_values.at(index).y();
361 }
362 }
362
363
363 /*!
364 /*!
364 Returns value of set indexed by \a index.
365 Returns value of set indexed by \a index.
365 If the index is out of bounds 0.0 is returned.
366 If the index is out of bounds 0.0 is returned.
366 */
367 */
367 qreal QBarSet::operator [](const int index) const
368 qreal QBarSet::operator [](const int index) const
368 {
369 {
369 return at(index);
370 return at(index);
370 }
371 }
371
372
372 /*!
373 /*!
373 Returns count of values in set.
374 Returns count of values in set.
374 */
375 */
375 int QBarSet::count() const
376 int QBarSet::count() const
376 {
377 {
377 return d_ptr->m_values.count();
378 return d_ptr->m_values.count();
378 }
379 }
379
380
380 /*!
381 /*!
381 Returns sum of all values in barset.
382 Returns sum of all values in barset.
382 */
383 */
383 qreal QBarSet::sum() const
384 qreal QBarSet::sum() const
384 {
385 {
385 qreal total(0);
386 qreal total(0);
386 for (int i = 0; i < d_ptr->m_values.count(); i++)
387 for (int i = 0; i < d_ptr->m_values.count(); i++)
387 total += d_ptr->m_values.at(i).y();
388 total += d_ptr->m_values.at(i).y();
388 return total;
389 return total;
389 }
390 }
390
391
391 /*!
392 /*!
392 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
393 */
394 */
394 void QBarSet::setPen(const QPen &pen)
395 void QBarSet::setPen(const QPen &pen)
395 {
396 {
396 if (d_ptr->m_pen != pen) {
397 if (d_ptr->m_pen != pen) {
397 d_ptr->m_pen = pen;
398 d_ptr->m_pen = pen;
398 emit d_ptr->updatedBars();
399 emit d_ptr->updatedBars();
399 emit penChanged();
400 emit penChanged();
400 }
401 }
401 }
402 }
402
403
403 /*!
404 /*!
404 Returns pen of the set.
405 Returns pen of the set.
405 */
406 */
406 QPen QBarSet::pen() const
407 QPen QBarSet::pen() const
407 {
408 {
408 return d_ptr->m_pen;
409 return d_ptr->m_pen;
409 }
410 }
410
411
411 /*!
412 /*!
412 Sets brush for the set. Bars of this set are drawn using \a brush
413 Sets brush for the set. Bars of this set are drawn using \a brush
413 */
414 */
414 void QBarSet::setBrush(const QBrush &brush)
415 void QBarSet::setBrush(const QBrush &brush)
415 {
416 {
416 if (d_ptr->m_brush != brush) {
417 if (d_ptr->m_brush != brush) {
417 d_ptr->m_brush = brush;
418 d_ptr->m_brush = brush;
418 emit d_ptr->updatedBars();
419 emit d_ptr->updatedBars();
419 emit brushChanged();
420 emit brushChanged();
420 }
421 }
421 }
422 }
422
423
423 /*!
424 /*!
424 Returns brush of the set.
425 Returns brush of the set.
425 */
426 */
426 QBrush QBarSet::brush() const
427 QBrush QBarSet::brush() const
427 {
428 {
428 return d_ptr->m_brush;
429 return d_ptr->m_brush;
429 }
430 }
430
431
431 /*!
432 /*!
432 Sets \a brush of the values that are drawn on top of this barset
433 Sets \a brush of the values that are drawn on top of this barset
433 */
434 */
434 void QBarSet::setLabelBrush(const QBrush &brush)
435 void QBarSet::setLabelBrush(const QBrush &brush)
435 {
436 {
436 if (d_ptr->m_labelBrush != brush) {
437 if (d_ptr->m_labelBrush != brush) {
437 d_ptr->m_labelBrush = brush;
438 d_ptr->m_labelBrush = brush;
438 emit d_ptr->updatedBars();
439 emit d_ptr->updatedBars();
439 emit labelBrushChanged();
440 emit labelBrushChanged();
440 }
441 }
441 }
442 }
442
443
443 /*!
444 /*!
444 Returns brush of the values that are drawn on top of this barset
445 Returns brush of the values that are drawn on top of this barset
445 */
446 */
446 QBrush QBarSet::labelBrush() const
447 QBrush QBarSet::labelBrush() const
447 {
448 {
448 return d_ptr->m_labelBrush;
449 return d_ptr->m_labelBrush;
449 }
450 }
450
451
451 /*!
452 /*!
452 Sets the \a font for values that are drawn on top of this barset
453 Sets the \a font for values that are drawn on top of this barset
453 */
454 */
454 void QBarSet::setLabelFont(const QFont &font)
455 void QBarSet::setLabelFont(const QFont &font)
455 {
456 {
456 if (d_ptr->m_labelFont != font) {
457 if (d_ptr->m_labelFont != font) {
457 d_ptr->m_labelFont = font;
458 d_ptr->m_labelFont = font;
458 emit d_ptr->updatedBars();
459 emit d_ptr->updatedBars();
459 emit labelFontChanged();
460 emit labelFontChanged();
460 }
461 }
461
462
462 }
463 }
463
464
464 /*!
465 /*!
465 Returns the pen for values that are drawn on top of this barset
466 Returns the pen for values that are drawn on top of this barset
466 */
467 */
467 QFont QBarSet::labelFont() const
468 QFont QBarSet::labelFont() const
468 {
469 {
469 return d_ptr->m_labelFont;
470 return d_ptr->m_labelFont;
470 }
471 }
471
472
472 /*!
473 /*!
473 Returns the color of the brush of barset.
474 Returns the color of the brush of barset.
474 */
475 */
475 QColor QBarSet::color()
476 QColor QBarSet::color()
476 {
477 {
477 return brush().color();
478 return brush().color();
478 }
479 }
479
480
480 /*!
481 /*!
481 Sets the \a color of brush for this barset
482 Sets the \a color of brush for this barset
482 */
483 */
483 void QBarSet::setColor(QColor color)
484 void QBarSet::setColor(QColor color)
484 {
485 {
485 QBrush b = brush();
486 QBrush b = brush();
486 if ((b.color() != color) || (b.style() == Qt::NoBrush)) {
487 if ((b.color() != color) || (b.style() == Qt::NoBrush)) {
487 b.setColor(color);
488 b.setColor(color);
488 if (b.style() == Qt::NoBrush) {
489 if (b.style() == Qt::NoBrush) {
489 // Set tyle to Qt::SolidPattern. (Default is Qt::NoBrush)
490 // Set tyle to Qt::SolidPattern. (Default is Qt::NoBrush)
490 // This prevents theme to override color defined in QML side:
491 // This prevents theme to override color defined in QML side:
491 // BarSet { label: "Bob"; color:"red"; values: [1,2,3] }
492 // BarSet { label: "Bob"; color:"red"; values: [1,2,3] }
492 // The color must be obeyed, since user wanted it.
493 // The color must be obeyed, since user wanted it.
493 b.setStyle(Qt::SolidPattern);
494 b.setStyle(Qt::SolidPattern);
494 }
495 }
495 setBrush(b);
496 setBrush(b);
496 emit colorChanged(color);
497 emit colorChanged(color);
497 }
498 }
498 }
499 }
499
500
500 /*!
501 /*!
501 Returns the color of pen of this barset
502 Returns the color of pen of this barset
502 */
503 */
503 QColor QBarSet::borderColor()
504 QColor QBarSet::borderColor()
504 {
505 {
505 return pen().color();
506 return pen().color();
506 }
507 }
507
508
508 /*!
509 /*!
509 Sets the color of pen for this barset
510 Sets the color of pen for this barset
510 */
511 */
511 void QBarSet::setBorderColor(QColor color)
512 void QBarSet::setBorderColor(QColor color)
512 {
513 {
513 QPen p = pen();
514 QPen p = pen();
514 if (p.color() != color) {
515 if (p.color() != color) {
515 p.setColor(color);
516 p.setColor(color);
516 setPen(p);
517 setPen(p);
517 emit borderColorChanged(color);
518 emit borderColorChanged(color);
518 }
519 }
519 }
520 }
520
521
521 /*!
522 /*!
522 Returns the color of labels of this barset
523 Returns the color of labels of this barset
523 */
524 */
524 QColor QBarSet::labelColor()
525 QColor QBarSet::labelColor()
525 {
526 {
526 return labelBrush().color();
527 return labelBrush().color();
527 }
528 }
528
529
529 /*!
530 /*!
530 Sets the color of labels for this barset
531 Sets the color of labels for this barset
531 */
532 */
532 void QBarSet::setLabelColor(QColor color)
533 void QBarSet::setLabelColor(QColor color)
533 {
534 {
534 QBrush b = labelBrush();
535 QBrush b = labelBrush();
535 if (b == QBrush())
536 if (b == QBrush())
536 b.setStyle(Qt::SolidPattern);
537 b.setStyle(Qt::SolidPattern);
537
538
538 if (b.color() != color) {
539 if (b.color() != color) {
539 b.setColor(color);
540 b.setColor(color);
540 setLabelBrush(b);
541 setLabelBrush(b);
541 emit labelColorChanged(color);
542 emit labelColorChanged(color);
542 }
543 }
543 }
544 }
544
545
545 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
546 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
546
547
547 QBarSetPrivate::QBarSetPrivate(const QString label, QBarSet *parent) : QObject(parent),
548 QBarSetPrivate::QBarSetPrivate(const QString label, QBarSet *parent) : QObject(parent),
548 q_ptr(parent),
549 q_ptr(parent),
549 m_label(label)
550 m_label(label),
551 m_pen(QChartPrivate::defaultPen()),
552 m_brush(QChartPrivate::defaultBrush()),
553 m_labelBrush(QChartPrivate::defaultBrush())
550 {
554 {
551 }
555 }
552
556
553 QBarSetPrivate::~QBarSetPrivate()
557 QBarSetPrivate::~QBarSetPrivate()
554 {
558 {
555 }
559 }
556
560
557 void QBarSetPrivate::append(QPointF value)
561 void QBarSetPrivate::append(QPointF value)
558 {
562 {
559 if (isValidValue(value)) {
563 if (isValidValue(value)) {
560 m_values.append(value);
564 m_values.append(value);
561 emit restructuredBars();
565 emit restructuredBars();
562 }
566 }
563 }
567 }
564
568
565 void QBarSetPrivate::append(QList<QPointF> values)
569 void QBarSetPrivate::append(QList<QPointF> values)
566 {
570 {
567 for (int i = 0; i < values.count(); i++) {
571 for (int i = 0; i < values.count(); i++) {
568 if (isValidValue(values.at(i)))
572 if (isValidValue(values.at(i)))
569 m_values.append(values.at(i));
573 m_values.append(values.at(i));
570 }
574 }
571 emit restructuredBars();
575 emit restructuredBars();
572 }
576 }
573
577
574 void QBarSetPrivate::append(QList<qreal> values)
578 void QBarSetPrivate::append(QList<qreal> values)
575 {
579 {
576 int index = m_values.count();
580 int index = m_values.count();
577 for (int i = 0; i < values.count(); i++) {
581 for (int i = 0; i < values.count(); i++) {
578 if (isValidValue(values.at(i))) {
582 if (isValidValue(values.at(i))) {
579 m_values.append(QPointF(index, values.at(i)));
583 m_values.append(QPointF(index, values.at(i)));
580 index++;
584 index++;
581 }
585 }
582 }
586 }
583 emit restructuredBars();
587 emit restructuredBars();
584 }
588 }
585
589
586 void QBarSetPrivate::insert(const int index, const qreal value)
590 void QBarSetPrivate::insert(const int index, const qreal value)
587 {
591 {
588 m_values.insert(index, QPointF(index, value));
592 m_values.insert(index, QPointF(index, value));
589 emit restructuredBars();
593 emit restructuredBars();
590 }
594 }
591
595
592 void QBarSetPrivate::insert(const int index, const QPointF value)
596 void QBarSetPrivate::insert(const int index, const QPointF value)
593 {
597 {
594 m_values.insert(index, value);
598 m_values.insert(index, value);
595 emit restructuredBars();
599 emit restructuredBars();
596 }
600 }
597
601
598 int QBarSetPrivate::remove(const int index, const int count)
602 int QBarSetPrivate::remove(const int index, const int count)
599 {
603 {
600 int removeCount = count;
604 int removeCount = count;
601
605
602 if ((index < 0) || (m_values.count() == 0))
606 if ((index < 0) || (m_values.count() == 0))
603 return 0; // Invalid index or not values in list, remove nothing.
607 return 0; // Invalid index or not values in list, remove nothing.
604 else if ((index + count) > m_values.count())
608 else if ((index + count) > m_values.count())
605 removeCount = m_values.count() - index; // Trying to remove more items than list has. Limit amount to be removed.
609 removeCount = m_values.count() - index; // Trying to remove more items than list has. Limit amount to be removed.
606
610
607 int c = 0;
611 int c = 0;
608 while (c < removeCount) {
612 while (c < removeCount) {
609 m_values.removeAt(index);
613 m_values.removeAt(index);
610 c++;
614 c++;
611 }
615 }
612 emit restructuredBars();
616 emit restructuredBars();
613 return removeCount;
617 return removeCount;
614 }
618 }
615
619
616 void QBarSetPrivate::replace(const int index, const qreal value)
620 void QBarSetPrivate::replace(const int index, const qreal value)
617 {
621 {
618 m_values.replace(index, QPointF(index, value));
622 m_values.replace(index, QPointF(index, value));
619 emit updatedLayout();
623 emit updatedLayout();
620 }
624 }
621
625
622 void QBarSetPrivate::replace(const int index, const QPointF value)
626 void QBarSetPrivate::replace(const int index, const QPointF value)
623 {
627 {
624 m_values.replace(index, value);
628 m_values.replace(index, value);
625 emit updatedLayout();
629 emit updatedLayout();
626 }
630 }
627
631
628 qreal QBarSetPrivate::pos(const int index)
632 qreal QBarSetPrivate::pos(const int index)
629 {
633 {
630 if (index < 0 || index >= m_values.count())
634 if (index < 0 || index >= m_values.count())
631 return 0;
635 return 0;
632 return m_values.at(index).x();
636 return m_values.at(index).x();
633 }
637 }
634
638
635 qreal QBarSetPrivate::value(const int index)
639 qreal QBarSetPrivate::value(const int index)
636 {
640 {
637 if (index < 0 || index >= m_values.count())
641 if (index < 0 || index >= m_values.count())
638 return 0;
642 return 0;
639 return m_values.at(index).y();
643 return m_values.at(index).y();
640 }
644 }
641
645
642 #include "moc_qbarset.cpp"
646 #include "moc_qbarset.cpp"
643 #include "moc_qbarset_p.cpp"
647 #include "moc_qbarset_p.cpp"
644
648
645 QTCOMMERCIALCHART_END_NAMESPACE
649 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,382 +1,383
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 #include "chartpresenter_p.h"
20 #include "chartpresenter_p.h"
21 #include "qchart.h"
21 #include "qchart.h"
22 #include "chartitem_p.h"
22 #include "chartitem_p.h"
23 #include "qchart_p.h"
23 #include "qchart_p.h"
24 #include "qabstractaxis.h"
24 #include "qabstractaxis.h"
25 #include "qabstractaxis_p.h"
25 #include "qabstractaxis_p.h"
26 #include "chartdataset_p.h"
26 #include "chartdataset_p.h"
27 #include "chartanimation_p.h"
27 #include "chartanimation_p.h"
28 #include "qabstractseries_p.h"
28 #include "qabstractseries_p.h"
29 #include "qareaseries.h"
29 #include "qareaseries.h"
30 #include "chartaxiselement_p.h"
30 #include "chartaxiselement_p.h"
31 #include "chartbackground_p.h"
31 #include "chartbackground_p.h"
32 #include "cartesianchartlayout_p.h"
32 #include "cartesianchartlayout_p.h"
33 #include "polarchartlayout_p.h"
33 #include "polarchartlayout_p.h"
34 #include "charttitle_p.h"
34 #include "charttitle_p.h"
35 #include <QTimer>
35 #include <QTimer>
36
36
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38
38
39 ChartPresenter::ChartPresenter(QChart *chart, QChart::ChartType type)
39 ChartPresenter::ChartPresenter(QChart *chart, QChart::ChartType type)
40 : QObject(chart),
40 : QObject(chart),
41 m_chart(chart),
41 m_chart(chart),
42 m_options(QChart::NoAnimation),
42 m_options(QChart::NoAnimation),
43 m_state(ShowState),
43 m_state(ShowState),
44 m_background(0),
44 m_background(0),
45 m_plotAreaBackground(0),
45 m_plotAreaBackground(0),
46 m_title(0)
46 m_title(0)
47 {
47 {
48 if (type == QChart::ChartTypeCartesian)
48 if (type == QChart::ChartTypeCartesian)
49 m_layout = new CartesianChartLayout(this);
49 m_layout = new CartesianChartLayout(this);
50 else if (type == QChart::ChartTypePolar)
50 else if (type == QChart::ChartTypePolar)
51 m_layout = new PolarChartLayout(this);
51 m_layout = new PolarChartLayout(this);
52 Q_ASSERT(m_layout);
52 Q_ASSERT(m_layout);
53 }
53 }
54
54
55 ChartPresenter::~ChartPresenter()
55 ChartPresenter::~ChartPresenter()
56 {
56 {
57
57
58 }
58 }
59
59
60 void ChartPresenter::setGeometry(const QRectF rect)
60 void ChartPresenter::setGeometry(const QRectF rect)
61 {
61 {
62 if (m_rect != rect) {
62 if (m_rect != rect) {
63 m_rect = rect;
63 m_rect = rect;
64 foreach (ChartItem *chart, m_chartItems) {
64 foreach (ChartItem *chart, m_chartItems) {
65 chart->domain()->setSize(rect.size());
65 chart->domain()->setSize(rect.size());
66 chart->setPos(rect.topLeft());
66 chart->setPos(rect.topLeft());
67 }
67 }
68 }
68 }
69 }
69 }
70
70
71 QRectF ChartPresenter::geometry() const
71 QRectF ChartPresenter::geometry() const
72 {
72 {
73 return m_rect;
73 return m_rect;
74 }
74 }
75
75
76 void ChartPresenter::handleAxisAdded(QAbstractAxis *axis)
76 void ChartPresenter::handleAxisAdded(QAbstractAxis *axis)
77 {
77 {
78 axis->d_ptr->initializeGraphics(rootItem());
78 axis->d_ptr->initializeGraphics(rootItem());
79 axis->d_ptr->initializeAnimations(m_options);
79 axis->d_ptr->initializeAnimations(m_options);
80 ChartAxisElement *item = axis->d_ptr->axisItem();
80 ChartAxisElement *item = axis->d_ptr->axisItem();
81 item->setPresenter(this);
81 item->setPresenter(this);
82 item->setThemeManager(m_chart->d_ptr->m_themeManager);
82 item->setThemeManager(m_chart->d_ptr->m_themeManager);
83 m_axisItems<<item;
83 m_axisItems<<item;
84 m_axes<<axis;
84 m_axes<<axis;
85 m_layout->invalidate();
85 m_layout->invalidate();
86 }
86 }
87
87
88 void ChartPresenter::handleAxisRemoved(QAbstractAxis *axis)
88 void ChartPresenter::handleAxisRemoved(QAbstractAxis *axis)
89 {
89 {
90 ChartAxisElement *item = axis->d_ptr->m_item.take();
90 ChartAxisElement *item = axis->d_ptr->m_item.take();
91 item->hide();
91 item->hide();
92 item->disconnect();
92 item->disconnect();
93 item->deleteLater();
93 item->deleteLater();
94 m_axisItems.removeAll(item);
94 m_axisItems.removeAll(item);
95 m_axes.removeAll(axis);
95 m_axes.removeAll(axis);
96 m_layout->invalidate();
96 m_layout->invalidate();
97 }
97 }
98
98
99
99
100 void ChartPresenter::handleSeriesAdded(QAbstractSeries *series)
100 void ChartPresenter::handleSeriesAdded(QAbstractSeries *series)
101 {
101 {
102 series->d_ptr->initializeGraphics(rootItem());
102 series->d_ptr->initializeGraphics(rootItem());
103 series->d_ptr->initializeAnimations(m_options);
103 series->d_ptr->initializeAnimations(m_options);
104 ChartItem *chart = series->d_ptr->chartItem();
104 ChartItem *chart = series->d_ptr->chartItem();
105 chart->setPresenter(this);
105 chart->setPresenter(this);
106 chart->setThemeManager(m_chart->d_ptr->m_themeManager);
106 chart->setThemeManager(m_chart->d_ptr->m_themeManager);
107 chart->domain()->setSize(m_rect.size());
107 chart->domain()->setSize(m_rect.size());
108 chart->setPos(m_rect.topLeft());
108 chart->setPos(m_rect.topLeft());
109 chart->handleDomainUpdated(); //this could be moved to intializeGraphics when animator is refactored
109 chart->handleDomainUpdated(); //this could be moved to intializeGraphics when animator is refactored
110 m_chartItems<<chart;
110 m_chartItems<<chart;
111 m_series<<series;
111 m_series<<series;
112 m_layout->invalidate();
112 m_layout->invalidate();
113 }
113 }
114
114
115 void ChartPresenter::handleSeriesRemoved(QAbstractSeries *series)
115 void ChartPresenter::handleSeriesRemoved(QAbstractSeries *series)
116 {
116 {
117 ChartItem *chart = series->d_ptr->m_item.take();
117 ChartItem *chart = series->d_ptr->m_item.take();
118 chart->hide();
118 chart->hide();
119 chart->disconnect();
119 chart->disconnect();
120 chart->deleteLater();
120 chart->deleteLater();
121 m_chartItems.removeAll(chart);
121 m_chartItems.removeAll(chart);
122 m_series.removeAll(series);
122 m_series.removeAll(series);
123 m_layout->invalidate();
123 m_layout->invalidate();
124 }
124 }
125
125
126 void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options)
126 void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options)
127 {
127 {
128 if (m_options != options) {
128 if (m_options != options) {
129 m_options = options;
129 m_options = options;
130
130
131 foreach(QAbstractSeries* series, m_series){
131 foreach(QAbstractSeries* series, m_series){
132 series->d_ptr->initializeAnimations(m_options);
132 series->d_ptr->initializeAnimations(m_options);
133 }
133 }
134 foreach(QAbstractAxis* axis, m_axes){
134 foreach(QAbstractAxis* axis, m_axes){
135 axis->d_ptr->initializeAnimations(m_options);
135 axis->d_ptr->initializeAnimations(m_options);
136 }
136 }
137 }
137 }
138 }
138 }
139
139
140 void ChartPresenter::setState(State state,QPointF point)
140 void ChartPresenter::setState(State state,QPointF point)
141 {
141 {
142 m_state=state;
142 m_state=state;
143 m_statePoint=point;
143 m_statePoint=point;
144 }
144 }
145
145
146 QChart::AnimationOptions ChartPresenter::animationOptions() const
146 QChart::AnimationOptions ChartPresenter::animationOptions() const
147 {
147 {
148 return m_options;
148 return m_options;
149 }
149 }
150
150
151 void ChartPresenter::createBackgroundItem()
151 void ChartPresenter::createBackgroundItem()
152 {
152 {
153 if (!m_background) {
153 if (!m_background) {
154 m_background = new ChartBackground(rootItem());
154 m_background = new ChartBackground(rootItem());
155 m_background->setPen(Qt::NoPen);
155 m_background->setPen(Qt::NoPen); // Theme doesn't touch pen so don't use default
156 m_background->setBrush(QChartPrivate::defaultBrush());
156 m_background->setZValue(ChartPresenter::BackgroundZValue);
157 m_background->setZValue(ChartPresenter::BackgroundZValue);
157 }
158 }
158 }
159 }
159
160
160 void ChartPresenter::createPlotAreaBackgroundItem()
161 void ChartPresenter::createPlotAreaBackgroundItem()
161 {
162 {
162 if (!m_plotAreaBackground) {
163 if (!m_plotAreaBackground) {
163 if (m_chart->chartType() == QChart::ChartTypeCartesian)
164 if (m_chart->chartType() == QChart::ChartTypeCartesian)
164 m_plotAreaBackground = new QGraphicsRectItem(rootItem());
165 m_plotAreaBackground = new QGraphicsRectItem(rootItem());
165 else
166 else
166 m_plotAreaBackground = new QGraphicsEllipseItem(rootItem());
167 m_plotAreaBackground = new QGraphicsEllipseItem(rootItem());
167 // Use transparent pen instead of Qt::NoPen, as Qt::NoPen causes
168 // Use transparent pen instead of Qt::NoPen, as Qt::NoPen causes
168 // antialising artifacts with axis lines for some reason.
169 // antialising artifacts with axis lines for some reason.
169 m_plotAreaBackground->setPen(QPen(Qt::transparent));
170 m_plotAreaBackground->setPen(QPen(Qt::transparent));
170 m_plotAreaBackground->setBrush(Qt::NoBrush);
171 m_plotAreaBackground->setBrush(Qt::NoBrush);
171 m_plotAreaBackground->setZValue(ChartPresenter::PlotAreaZValue);
172 m_plotAreaBackground->setZValue(ChartPresenter::PlotAreaZValue);
172 m_plotAreaBackground->setVisible(false);
173 m_plotAreaBackground->setVisible(false);
173 }
174 }
174 }
175 }
175
176
176 void ChartPresenter::createTitleItem()
177 void ChartPresenter::createTitleItem()
177 {
178 {
178 if (!m_title) {
179 if (!m_title) {
179 m_title = new ChartTitle(rootItem());
180 m_title = new ChartTitle(rootItem());
180 m_title->setZValue(ChartPresenter::BackgroundZValue);
181 m_title->setZValue(ChartPresenter::BackgroundZValue);
181 }
182 }
182 }
183 }
183
184
184
185
185 void ChartPresenter::handleAnimationFinished()
186 void ChartPresenter::handleAnimationFinished()
186 {
187 {
187 m_animations.removeAll(qobject_cast<ChartAnimation *>(sender()));
188 m_animations.removeAll(qobject_cast<ChartAnimation *>(sender()));
188 if (m_animations.empty())
189 if (m_animations.empty())
189 emit animationsFinished();
190 emit animationsFinished();
190 }
191 }
191
192
192 void ChartPresenter::startAnimation(ChartAnimation *animation)
193 void ChartPresenter::startAnimation(ChartAnimation *animation)
193 {
194 {
194 if (animation->state() != QAbstractAnimation::Stopped) animation->stop();
195 if (animation->state() != QAbstractAnimation::Stopped) animation->stop();
195 QObject::connect(animation, SIGNAL(finished()), this, SLOT(handleAnimationFinished()), Qt::UniqueConnection);
196 QObject::connect(animation, SIGNAL(finished()), this, SLOT(handleAnimationFinished()), Qt::UniqueConnection);
196 if (!m_animations.isEmpty())
197 if (!m_animations.isEmpty())
197 m_animations.append(animation);
198 m_animations.append(animation);
198 QTimer::singleShot(0, animation, SLOT(start()));
199 QTimer::singleShot(0, animation, SLOT(start()));
199 }
200 }
200
201
201 void ChartPresenter::setBackgroundBrush(const QBrush &brush)
202 void ChartPresenter::setBackgroundBrush(const QBrush &brush)
202 {
203 {
203 createBackgroundItem();
204 createBackgroundItem();
204 m_background->setBrush(brush);
205 m_background->setBrush(brush);
205 m_layout->invalidate();
206 m_layout->invalidate();
206 }
207 }
207
208
208 QBrush ChartPresenter::backgroundBrush() const
209 QBrush ChartPresenter::backgroundBrush() const
209 {
210 {
210 if (!m_background)
211 if (!m_background)
211 return QBrush();
212 return QBrush();
212 return m_background->brush();
213 return m_background->brush();
213 }
214 }
214
215
215 void ChartPresenter::setBackgroundPen(const QPen &pen)
216 void ChartPresenter::setBackgroundPen(const QPen &pen)
216 {
217 {
217 createBackgroundItem();
218 createBackgroundItem();
218 m_background->setPen(pen);
219 m_background->setPen(pen);
219 m_layout->invalidate();
220 m_layout->invalidate();
220 }
221 }
221
222
222 QPen ChartPresenter::backgroundPen() const
223 QPen ChartPresenter::backgroundPen() const
223 {
224 {
224 if (!m_background)
225 if (!m_background)
225 return QPen();
226 return QPen();
226 return m_background->pen();
227 return m_background->pen();
227 }
228 }
228
229
229 void ChartPresenter::setPlotAreaBackgroundBrush(const QBrush &brush)
230 void ChartPresenter::setPlotAreaBackgroundBrush(const QBrush &brush)
230 {
231 {
231 createPlotAreaBackgroundItem();
232 createPlotAreaBackgroundItem();
232 m_plotAreaBackground->setBrush(brush);
233 m_plotAreaBackground->setBrush(brush);
233 m_layout->invalidate();
234 m_layout->invalidate();
234 }
235 }
235
236
236 QBrush ChartPresenter::plotAreaBackgroundBrush() const
237 QBrush ChartPresenter::plotAreaBackgroundBrush() const
237 {
238 {
238 if (!m_plotAreaBackground)
239 if (!m_plotAreaBackground)
239 return QBrush();
240 return QBrush();
240 return m_plotAreaBackground->brush();
241 return m_plotAreaBackground->brush();
241 }
242 }
242
243
243 void ChartPresenter::setPlotAreaBackgroundPen(const QPen &pen)
244 void ChartPresenter::setPlotAreaBackgroundPen(const QPen &pen)
244 {
245 {
245 createPlotAreaBackgroundItem();
246 createPlotAreaBackgroundItem();
246 m_plotAreaBackground->setPen(pen);
247 m_plotAreaBackground->setPen(pen);
247 m_layout->invalidate();
248 m_layout->invalidate();
248 }
249 }
249
250
250 QPen ChartPresenter::plotAreaBackgroundPen() const
251 QPen ChartPresenter::plotAreaBackgroundPen() const
251 {
252 {
252 if (!m_plotAreaBackground)
253 if (!m_plotAreaBackground)
253 return QPen();
254 return QPen();
254 return m_plotAreaBackground->pen();
255 return m_plotAreaBackground->pen();
255 }
256 }
256
257
257 void ChartPresenter::setTitle(const QString &title)
258 void ChartPresenter::setTitle(const QString &title)
258 {
259 {
259 createTitleItem();
260 createTitleItem();
260 m_title->setText(title);
261 m_title->setText(title);
261 m_layout->invalidate();
262 m_layout->invalidate();
262 }
263 }
263
264
264 QString ChartPresenter::title() const
265 QString ChartPresenter::title() const
265 {
266 {
266 if (!m_title)
267 if (!m_title)
267 return QString();
268 return QString();
268 return m_title->text();
269 return m_title->text();
269 }
270 }
270
271
271 void ChartPresenter::setTitleFont(const QFont &font)
272 void ChartPresenter::setTitleFont(const QFont &font)
272 {
273 {
273 createTitleItem();
274 createTitleItem();
274 m_title->setFont(font);
275 m_title->setFont(font);
275 m_layout->invalidate();
276 m_layout->invalidate();
276 }
277 }
277
278
278 QFont ChartPresenter::titleFont() const
279 QFont ChartPresenter::titleFont() const
279 {
280 {
280 if (!m_title)
281 if (!m_title)
281 return QFont();
282 return QFont();
282 return m_title->font();
283 return m_title->font();
283 }
284 }
284
285
285 void ChartPresenter::setTitleBrush(const QBrush &brush)
286 void ChartPresenter::setTitleBrush(const QBrush &brush)
286 {
287 {
287 createTitleItem();
288 createTitleItem();
288 m_title->setBrush(brush);
289 m_title->setBrush(brush);
289 m_layout->invalidate();
290 m_layout->invalidate();
290 }
291 }
291
292
292 QBrush ChartPresenter::titleBrush() const
293 QBrush ChartPresenter::titleBrush() const
293 {
294 {
294 if (!m_title)
295 if (!m_title)
295 return QBrush();
296 return QBrush();
296 return m_title->brush();
297 return m_title->brush();
297 }
298 }
298
299
299 void ChartPresenter::setBackgroundVisible(bool visible)
300 void ChartPresenter::setBackgroundVisible(bool visible)
300 {
301 {
301 createBackgroundItem();
302 createBackgroundItem();
302 m_background->setVisible(visible);
303 m_background->setVisible(visible);
303 }
304 }
304
305
305
306
306 bool ChartPresenter::isBackgroundVisible() const
307 bool ChartPresenter::isBackgroundVisible() const
307 {
308 {
308 if (!m_background)
309 if (!m_background)
309 return false;
310 return false;
310 return m_background->isVisible();
311 return m_background->isVisible();
311 }
312 }
312
313
313 void ChartPresenter::setPlotAreaBackgroundVisible(bool visible)
314 void ChartPresenter::setPlotAreaBackgroundVisible(bool visible)
314 {
315 {
315 createPlotAreaBackgroundItem();
316 createPlotAreaBackgroundItem();
316 m_plotAreaBackground->setVisible(visible);
317 m_plotAreaBackground->setVisible(visible);
317 }
318 }
318
319
319 bool ChartPresenter::isPlotAreaBackgroundVisible() const
320 bool ChartPresenter::isPlotAreaBackgroundVisible() const
320 {
321 {
321 if (!m_plotAreaBackground)
322 if (!m_plotAreaBackground)
322 return false;
323 return false;
323 return m_plotAreaBackground->isVisible();
324 return m_plotAreaBackground->isVisible();
324 }
325 }
325
326
326 void ChartPresenter::setBackgroundDropShadowEnabled(bool enabled)
327 void ChartPresenter::setBackgroundDropShadowEnabled(bool enabled)
327 {
328 {
328 createBackgroundItem();
329 createBackgroundItem();
329 m_background->setDropShadowEnabled(enabled);
330 m_background->setDropShadowEnabled(enabled);
330 }
331 }
331
332
332 bool ChartPresenter::isBackgroundDropShadowEnabled() const
333 bool ChartPresenter::isBackgroundDropShadowEnabled() const
333 {
334 {
334 if (!m_background)
335 if (!m_background)
335 return false;
336 return false;
336 return m_background->isDropShadowEnabled();
337 return m_background->isDropShadowEnabled();
337 }
338 }
338
339
339
340
340 AbstractChartLayout *ChartPresenter::layout()
341 AbstractChartLayout *ChartPresenter::layout()
341 {
342 {
342 return m_layout;
343 return m_layout;
343 }
344 }
344
345
345 QLegend *ChartPresenter::legend()
346 QLegend *ChartPresenter::legend()
346 {
347 {
347 return m_chart->legend();
348 return m_chart->legend();
348 }
349 }
349
350
350 void ChartPresenter::setVisible(bool visible)
351 void ChartPresenter::setVisible(bool visible)
351 {
352 {
352 m_chart->setVisible(visible);
353 m_chart->setVisible(visible);
353 }
354 }
354
355
355 ChartBackground *ChartPresenter::backgroundElement()
356 ChartBackground *ChartPresenter::backgroundElement()
356 {
357 {
357 return m_background;
358 return m_background;
358 }
359 }
359
360
360 QAbstractGraphicsShapeItem *ChartPresenter::plotAreaElement()
361 QAbstractGraphicsShapeItem *ChartPresenter::plotAreaElement()
361 {
362 {
362 return m_plotAreaBackground;
363 return m_plotAreaBackground;
363 }
364 }
364
365
365 QList<ChartAxisElement *> ChartPresenter::axisItems() const
366 QList<ChartAxisElement *> ChartPresenter::axisItems() const
366 {
367 {
367 return m_axisItems;
368 return m_axisItems;
368 }
369 }
369
370
370 QList<ChartItem *> ChartPresenter::chartItems() const
371 QList<ChartItem *> ChartPresenter::chartItems() const
371 {
372 {
372 return m_chartItems;
373 return m_chartItems;
373 }
374 }
374
375
375 ChartTitle *ChartPresenter::titleElement()
376 ChartTitle *ChartPresenter::titleElement()
376 {
377 {
377 return m_title;
378 return m_title;
378 }
379 }
379
380
380 #include "moc_chartpresenter_p.cpp"
381 #include "moc_chartpresenter_p.cpp"
381
382
382 QTCOMMERCIALCHART_END_NAMESPACE
383 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,267 +1,248
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 #include "qabstractseries_p.h"
20 #include "qabstractseries_p.h"
21 #include "qabstractaxis_p.h"
21 #include "qabstractaxis_p.h"
22 #include <QTime>
22 #include <QTime>
23 //themes
23 //themes
24 #include "chartthemesystem_p.h"
24 #include "chartthemesystem_p.h"
25 #include "chartthemelight_p.h"
25 #include "chartthemelight_p.h"
26 #include "chartthemebluecerulean_p.h"
26 #include "chartthemebluecerulean_p.h"
27 #include "chartthemedark_p.h"
27 #include "chartthemedark_p.h"
28 #include "chartthemebrownsand_p.h"
28 #include "chartthemebrownsand_p.h"
29 #include "chartthemebluencs_p.h"
29 #include "chartthemebluencs_p.h"
30 #include "chartthemehighcontrast_p.h"
30 #include "chartthemehighcontrast_p.h"
31 #include "chartthemeblueicy_p.h"
31 #include "chartthemeblueicy_p.h"
32
32
33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
34
34
35 ChartThemeManager::ChartThemeManager(QChart* chart) :
35 ChartThemeManager::ChartThemeManager(QChart* chart) :
36 m_chart(chart)
36 m_chart(chart)
37 {
37 {
38 qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
38 qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
39 }
39 }
40
40
41
41
42 void ChartThemeManager::setTheme(QChart::ChartTheme theme)
42 void ChartThemeManager::setTheme(QChart::ChartTheme theme)
43 {
43 {
44 if(m_theme.isNull() || theme != m_theme->id())
44 if (m_theme.isNull() || theme != m_theme->id()) {
45 {
46 switch (theme) {
45 switch (theme) {
47 case QChart::ChartThemeLight:
46 case QChart::ChartThemeLight:
48 m_theme.reset(new ChartThemeLight());
47 m_theme.reset(new ChartThemeLight());
49 break;
48 break;
50 case QChart::ChartThemeBlueCerulean:
49 case QChart::ChartThemeBlueCerulean:
51 m_theme.reset(new ChartThemeBlueCerulean());
50 m_theme.reset(new ChartThemeBlueCerulean());
52 break;
51 break;
53 case QChart::ChartThemeDark:
52 case QChart::ChartThemeDark:
54 m_theme.reset(new ChartThemeDark());
53 m_theme.reset(new ChartThemeDark());
55 break;
54 break;
56 case QChart::ChartThemeBrownSand:
55 case QChart::ChartThemeBrownSand:
57 m_theme.reset(new ChartThemeBrownSand());
56 m_theme.reset(new ChartThemeBrownSand());
58 break;
57 break;
59 case QChart::ChartThemeBlueNcs:
58 case QChart::ChartThemeBlueNcs:
60 m_theme.reset(new ChartThemeBlueNcs());
59 m_theme.reset(new ChartThemeBlueNcs());
61 break;
60 break;
62 case QChart::ChartThemeHighContrast:
61 case QChart::ChartThemeHighContrast:
63 m_theme.reset(new ChartThemeHighContrast());
62 m_theme.reset(new ChartThemeHighContrast());
64 break;
63 break;
65 case QChart::ChartThemeBlueIcy:
64 case QChart::ChartThemeBlueIcy:
66 m_theme.reset(new ChartThemeBlueIcy());
65 m_theme.reset(new ChartThemeBlueIcy());
67 break;
66 break;
68 default:
67 default:
69 m_theme.reset(new ChartThemeSystem());
68 m_theme.reset(new ChartThemeSystem());
70 break;
69 break;
71 }
70 }
72
71
73 if(!m_theme.isNull())
72 if (!m_theme.isNull()) {
74 {
73 decorateChart(m_chart,m_theme.data());
75 decorateChart(m_chart,m_theme.data(),true);
74 decorateLegend(m_chart->legend(),m_theme.data());
76 decorateLegend(m_chart->legend(),m_theme.data(),true);
75 foreach (QAbstractAxis* axis, m_axisList)
77 foreach(QAbstractAxis* axis, m_axisList) {
76 axis->d_ptr->initializeTheme(m_theme.data(), true);
78 axis->d_ptr->initializeTheme(m_theme.data(),true);
77 foreach (QAbstractSeries* series, m_seriesMap.keys())
79 }
78 series->d_ptr->initializeTheme(m_seriesMap[series], m_theme.data(), true);
80 foreach(QAbstractSeries* series, m_seriesMap.keys()) {
81 series->d_ptr->initializeTheme(m_seriesMap[series],m_theme.data(),true);
82 }
83
84 }
79 }
85 }
80 }
86 }
81 }
87
82
88 void ChartThemeManager::decorateChart(QChart *chart,ChartTheme* theme,bool force) const
83 // decorateChart is only called when theme is forcibly initialized
84 void ChartThemeManager::decorateChart(QChart *chart, ChartTheme *theme) const
89 {
85 {
90 QBrush brush;
86 chart->setBackgroundBrush(theme->chartBackgroundGradient());
91
92 if (force || brush == chart->backgroundBrush())
93 chart->setBackgroundBrush(theme->chartBackgroundGradient());
94
87
95 if (force) {
88 QPen pen(Qt::transparent);
96 // Always clear plotArea brush when forced update, do not touch otherwise
89 QBrush brush;
97 QPen pen(Qt::transparent);
90 chart->setPlotAreaBackgroundBrush(brush);
98 chart->setPlotAreaBackgroundBrush(brush);
91 chart->setPlotAreaBackgroundPen(pen);
99 chart->setPlotAreaBackgroundPen(pen);
92 chart->setPlotAreaBackgroundVisible(false);
100 chart->setPlotAreaBackgroundVisible(false);
101 }
102
93
103 chart->setTitleFont(theme->masterFont());
94 chart->setTitleFont(theme->masterFont());
104 chart->setTitleBrush(theme->labelBrush());
95 chart->setTitleBrush(theme->labelBrush());
105 chart->setDropShadowEnabled(theme->isBackgroundDropShadowEnabled());
96 chart->setDropShadowEnabled(theme->isBackgroundDropShadowEnabled());
106 }
97 }
107
98
108 void ChartThemeManager::decorateLegend(QLegend *legend, ChartTheme* theme, bool force) const
99 // decorateLegend is only called when theme is forcibly initialized
100 void ChartThemeManager::decorateLegend(QLegend *legend, ChartTheme *theme) const
109 {
101 {
110 QPen pen;
102 legend->setPen(theme->axisLinePen());
111 QBrush brush;
103 legend->setBrush(theme->chartBackgroundGradient());
112 QFont font;
104 legend->setFont(theme->labelFont());
113
105 legend->setLabelBrush(theme->labelBrush());
114 if (force || pen == legend->pen())
115 legend->setPen(theme->axisLinePen());
116
117 if (force || brush == legend->brush())
118 legend->setBrush(theme->chartBackgroundGradient());
119
120 if (force || font == legend->font())
121 legend->setFont(theme->labelFont());
122
123 if (force || brush == legend->labelBrush())
124 legend->setLabelBrush(theme->labelBrush());
125 }
106 }
126
107
127 int ChartThemeManager::createIndexKey(QList<int> keys) const
108 int ChartThemeManager::createIndexKey(QList<int> keys) const
128 {
109 {
129 qSort(keys);
110 qSort(keys);
130
111
131 int key = 0;
112 int key = 0;
132 QList<int>::iterator i;
113 QList<int>::iterator i;
133 i = keys.begin();
114 i = keys.begin();
134
115
135 while (i != keys.end()) {
116 while (i != keys.end()) {
136 if (*i != key)
117 if (*i != key)
137 break;
118 break;
138 key++;
119 key++;
139 i++;
120 i++;
140 }
121 }
141
122
142 return key;
123 return key;
143 }
124 }
144
125
145 int ChartThemeManager::seriesCount(QAbstractSeries::SeriesType type) const
126 int ChartThemeManager::seriesCount(QAbstractSeries::SeriesType type) const
146 {
127 {
147 int count = 0;
128 int count = 0;
148 QList<QAbstractSeries *> series = m_seriesMap.keys();
129 QList<QAbstractSeries *> series = m_seriesMap.keys();
149 foreach(QAbstractSeries *s, series) {
130 foreach(QAbstractSeries *s, series) {
150 if (s->type() == type)
131 if (s->type() == type)
151 count++;
132 count++;
152 }
133 }
153 return count;
134 return count;
154 }
135 }
155
136
156 void ChartThemeManager::handleSeriesAdded(QAbstractSeries *series)
137 void ChartThemeManager::handleSeriesAdded(QAbstractSeries *series)
157 {
138 {
158 int key = createIndexKey(m_seriesMap.values());
139 int key = createIndexKey(m_seriesMap.values());
159 m_seriesMap.insert(series,key);
140 m_seriesMap.insert(series,key);
160 series->d_ptr->initializeTheme(key,m_theme.data(),false);
141 series->d_ptr->initializeTheme(key,m_theme.data(),false);
161 }
142 }
162
143
163 void ChartThemeManager::handleSeriesRemoved(QAbstractSeries *series)
144 void ChartThemeManager::handleSeriesRemoved(QAbstractSeries *series)
164 {
145 {
165 m_seriesMap.remove(series);
146 m_seriesMap.remove(series);
166 }
147 }
167
148
168 void ChartThemeManager::handleAxisAdded(QAbstractAxis *axis)
149 void ChartThemeManager::handleAxisAdded(QAbstractAxis *axis)
169 {
150 {
170 m_axisList.append(axis);
151 m_axisList.append(axis);
171 axis->d_ptr->initializeTheme(m_theme.data(),false);
152 axis->d_ptr->initializeTheme(m_theme.data(),false);
172 }
153 }
173
154
174 void ChartThemeManager::handleAxisRemoved(QAbstractAxis *axis)
155 void ChartThemeManager::handleAxisRemoved(QAbstractAxis *axis)
175 {
156 {
176 m_axisList.removeAll(axis);
157 m_axisList.removeAll(axis);
177 }
158 }
178
159
179 void ChartThemeManager::updateSeries(QAbstractSeries *series)
160 void ChartThemeManager::updateSeries(QAbstractSeries *series)
180 {
161 {
181 if(m_seriesMap.contains(series)){
162 if(m_seriesMap.contains(series)){
182 series->d_ptr->initializeTheme(m_seriesMap[series],m_theme.data(),false);
163 series->d_ptr->initializeTheme(m_seriesMap[series],m_theme.data(),false);
183 }
164 }
184 }
165 }
185 QList<QGradient> ChartThemeManager::generateSeriesGradients(const QList<QColor>& colors)
166 QList<QGradient> ChartThemeManager::generateSeriesGradients(const QList<QColor>& colors)
186 {
167 {
187 QList<QGradient> result;
168 QList<QGradient> result;
188 // Generate gradients in HSV color space
169 // Generate gradients in HSV color space
189 foreach (const QColor &color, colors) {
170 foreach (const QColor &color, colors) {
190 QLinearGradient g;
171 QLinearGradient g;
191 qreal h = color.hsvHueF();
172 qreal h = color.hsvHueF();
192 qreal s = color.hsvSaturationF();
173 qreal s = color.hsvSaturationF();
193
174
194 // TODO: tune the algorithm to give nice results with most base colors defined in
175 // TODO: tune the algorithm to give nice results with most base colors defined in
195 // most themes. The rest of the gradients we can define manually in theme specific
176 // most themes. The rest of the gradients we can define manually in theme specific
196 // implementation.
177 // implementation.
197 QColor start = color;
178 QColor start = color;
198 start.setHsvF(h, 0.0, 1.0);
179 start.setHsvF(h, 0.0, 1.0);
199 g.setColorAt(0.0, start);
180 g.setColorAt(0.0, start);
200
181
201 g.setColorAt(0.5, color);
182 g.setColorAt(0.5, color);
202
183
203 QColor end = color;
184 QColor end = color;
204 end.setHsvF(h, s, 0.25);
185 end.setHsvF(h, s, 0.25);
205 g.setColorAt(1.0, end);
186 g.setColorAt(1.0, end);
206
187
207 result << g;
188 result << g;
208 }
189 }
209
190
210 return result;
191 return result;
211 }
192 }
212
193
213
194
214 QColor ChartThemeManager::colorAt(const QColor &start, const QColor &end, qreal pos)
195 QColor ChartThemeManager::colorAt(const QColor &start, const QColor &end, qreal pos)
215 {
196 {
216 Q_ASSERT(pos >= 0.0 && pos <= 1.0);
197 Q_ASSERT(pos >= 0.0 && pos <= 1.0);
217 qreal r = start.redF() + ((end.redF() - start.redF()) * pos);
198 qreal r = start.redF() + ((end.redF() - start.redF()) * pos);
218 qreal g = start.greenF() + ((end.greenF() - start.greenF()) * pos);
199 qreal g = start.greenF() + ((end.greenF() - start.greenF()) * pos);
219 qreal b = start.blueF() + ((end.blueF() - start.blueF()) * pos);
200 qreal b = start.blueF() + ((end.blueF() - start.blueF()) * pos);
220 QColor c;
201 QColor c;
221 c.setRgbF(r, g, b);
202 c.setRgbF(r, g, b);
222 return c;
203 return c;
223 }
204 }
224
205
225 QColor ChartThemeManager::colorAt(const QGradient &gradient, qreal pos)
206 QColor ChartThemeManager::colorAt(const QGradient &gradient, qreal pos)
226 {
207 {
227 Q_ASSERT(pos >= 0 && pos <= 1.0);
208 Q_ASSERT(pos >= 0 && pos <= 1.0);
228
209
229 QGradientStops stops = gradient.stops();
210 QGradientStops stops = gradient.stops();
230 int count = stops.count();
211 int count = stops.count();
231
212
232 // find previous stop relative to position
213 // find previous stop relative to position
233 QGradientStop prev = stops.first();
214 QGradientStop prev = stops.first();
234 for (int i = 0; i < count; i++) {
215 for (int i = 0; i < count; i++) {
235 QGradientStop stop = stops.at(i);
216 QGradientStop stop = stops.at(i);
236 if (pos > stop.first)
217 if (pos > stop.first)
237 prev = stop;
218 prev = stop;
238
219
239 // given position is actually a stop position?
220 // given position is actually a stop position?
240 if (pos == stop.first) {
221 if (pos == stop.first) {
241 //qDebug() << "stop color" << pos;
222 //qDebug() << "stop color" << pos;
242 return stop.second;
223 return stop.second;
243 }
224 }
244 }
225 }
245
226
246 // find next stop relative to position
227 // find next stop relative to position
247 QGradientStop next = stops.last();
228 QGradientStop next = stops.last();
248 for (int i = count - 1; i >= 0; i--) {
229 for (int i = count - 1; i >= 0; i--) {
249 QGradientStop stop = stops.at(i);
230 QGradientStop stop = stops.at(i);
250 if (pos < stop.first)
231 if (pos < stop.first)
251 next = stop;
232 next = stop;
252 }
233 }
253
234
254 //qDebug() << "prev" << prev.first << "pos" << pos << "next" << next.first;
235 //qDebug() << "prev" << prev.first << "pos" << pos << "next" << next.first;
255
236
256 qreal range = next.first - prev.first;
237 qreal range = next.first - prev.first;
257 qreal posDelta = pos - prev.first;
238 qreal posDelta = pos - prev.first;
258 qreal relativePos = posDelta / range;
239 qreal relativePos = posDelta / range;
259
240
260 //qDebug() << "range" << range << "posDelta" << posDelta << "relativePos" << relativePos;
241 //qDebug() << "range" << range << "posDelta" << posDelta << "relativePos" << relativePos;
261
242
262 return colorAt(prev.second, next.second, relativePos);
243 return colorAt(prev.second, next.second, relativePos);
263 }
244 }
264
245
265 #include "moc_chartthememanager_p.cpp"
246 #include "moc_chartthememanager_p.cpp"
266
247
267 QTCOMMERCIALCHART_END_NAMESPACE
248 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,84 +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 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef CHARTTHEMEMANAGER_H
30 #ifndef CHARTTHEMEMANAGER_H
31 #define CHARTTHEMEMANAGER_H
31 #define CHARTTHEMEMANAGER_H
32
32
33 #include "qchartglobal.h"
33 #include "qchartglobal.h"
34 #include "qchart.h"
34 #include "qchart.h"
35 #include <QColor>
35 #include <QColor>
36 #include <QGradientStops>
36 #include <QGradientStops>
37
37
38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
39 class ChartTheme;
39 class ChartTheme;
40
40
41 class ChartThemeManager: public QObject
41 class ChartThemeManager: public QObject
42 {
42 {
43 Q_OBJECT
43 Q_OBJECT
44 public:
44 public:
45 enum BackgroundShadesMode {
45 enum BackgroundShadesMode {
46 BackgroundShadesNone = 0,
46 BackgroundShadesNone = 0,
47 BackgroundShadesVertical,
47 BackgroundShadesVertical,
48 BackgroundShadesHorizontal,
48 BackgroundShadesHorizontal,
49 BackgroundShadesBoth
49 BackgroundShadesBoth
50 };
50 };
51
51
52 public:
52 public:
53 explicit ChartThemeManager(QChart* chart);
53 explicit ChartThemeManager(QChart* chart);
54 void setTheme(QChart::ChartTheme theme);
54 void setTheme(QChart::ChartTheme theme);
55 ChartTheme* theme() const { return m_theme.data(); }
55 ChartTheme* theme() const { return m_theme.data(); }
56 void decorateChart(QChart *chart, ChartTheme* theme, bool force = false) const;
56 void decorateChart(QChart *chart, ChartTheme* theme) const;
57 void decorateLegend(QLegend *legend, ChartTheme* theme, bool force = false) const;
57 void decorateLegend(QLegend *legend, ChartTheme* theme) const;
58 void updateSeries(QAbstractSeries *series);
58 void updateSeries(QAbstractSeries *series);
59
59
60 public:
60 public:
61 static QList<QGradient> generateSeriesGradients(const QList<QColor>& colors);
61 static QList<QGradient> generateSeriesGradients(const QList<QColor>& colors);
62 static QColor colorAt(const QColor &start, const QColor &end, qreal pos);
62 static QColor colorAt(const QColor &start, const QColor &end, qreal pos);
63 static QColor colorAt(const QGradient &gradient, qreal pos);
63 static QColor colorAt(const QGradient &gradient, qreal pos);
64
64
65 private:
65 private:
66 int createIndexKey(QList<int> keys) const;
66 int createIndexKey(QList<int> keys) const;
67 int seriesCount(QAbstractSeries::SeriesType type) const;
67 int seriesCount(QAbstractSeries::SeriesType type) const;
68
68
69 public Q_SLOTS:
69 public Q_SLOTS:
70 void handleSeriesAdded(QAbstractSeries *series);
70 void handleSeriesAdded(QAbstractSeries *series);
71 void handleSeriesRemoved(QAbstractSeries *series);
71 void handleSeriesRemoved(QAbstractSeries *series);
72 void handleAxisAdded(QAbstractAxis *axis);
72 void handleAxisAdded(QAbstractAxis *axis);
73 void handleAxisRemoved(QAbstractAxis *axis);
73 void handleAxisRemoved(QAbstractAxis *axis);
74
74
75 protected:
75 protected:
76 QScopedPointer<ChartTheme> m_theme;
76 QScopedPointer<ChartTheme> m_theme;
77 QMap<QAbstractSeries *,int> m_seriesMap;
77 QMap<QAbstractSeries *,int> m_seriesMap;
78 QList<QAbstractAxis *> m_axisList;
78 QList<QAbstractAxis *> m_axisList;
79 QChart* m_chart;
79 QChart* m_chart;
80 };
80 };
81
81
82 QTCOMMERCIALCHART_END_NAMESPACE
82 QTCOMMERCIALCHART_END_NAMESPACE
83
83
84 #endif // CHARTTHEME_H
84 #endif // CHARTTHEME_H
@@ -1,162 +1,162
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 "qlineseries.h"
21 #include "qlineseries.h"
22 #include "qlineseries_p.h"
22 #include "qlineseries_p.h"
23 #include "linechartitem_p.h"
23 #include "linechartitem_p.h"
24 #include "chartdataset_p.h"
24 #include "chartdataset_p.h"
25 #include "charttheme_p.h"
25 #include "charttheme_p.h"
26
26 #include "qchart_p.h"
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
28
29 /*!
29 /*!
30 \class QLineSeries
30 \class QLineSeries
31 \brief The QLineSeries class is used for making line charts.
31 \brief The QLineSeries class is used for making line charts.
32
32
33 \mainclass
33 \mainclass
34
34
35 A line chart is used to show information as a series of data points
35 A line chart is used to show information as a series of data points
36 connected by straight lines.
36 connected by straight lines.
37
37
38 \image examples_linechart.png
38 \image examples_linechart.png
39
39
40 Creating basic line chart is simple:
40 Creating basic line chart is simple:
41 \code
41 \code
42 QLineSeries* series = new QLineSeries();
42 QLineSeries* series = new QLineSeries();
43 series->append(0, 6);
43 series->append(0, 6);
44 series->append(2, 4);
44 series->append(2, 4);
45 ...
45 ...
46 chart->addSeries(series);
46 chart->addSeries(series);
47 \endcode
47 \endcode
48 */
48 */
49 /*!
49 /*!
50 \qmlclass LineSeries QLineSeries
50 \qmlclass LineSeries QLineSeries
51 \inherits XYSeries
51 \inherits XYSeries
52
52
53 The following QML shows how to create a simple line chart:
53 The following QML shows how to create a simple line chart:
54 \snippet ../demos/qmlchart/qml/qmlchart/View2.qml 1
54 \snippet ../demos/qmlchart/qml/qmlchart/View2.qml 1
55 \beginfloatleft
55 \beginfloatleft
56 \image demos_qmlchart2.png
56 \image demos_qmlchart2.png
57 \endfloat
57 \endfloat
58 \clearfloat
58 \clearfloat
59 */
59 */
60
60
61 /*!
61 /*!
62 \fn virtual SeriesType QLineSeries::type() const
62 \fn virtual SeriesType QLineSeries::type() const
63 \brief Returns type of series.
63 \brief Returns type of series.
64 \sa QAbstractSeries, SeriesType
64 \sa QAbstractSeries, SeriesType
65 */
65 */
66
66
67 /*!
67 /*!
68 \qmlproperty real LineSeries::width
68 \qmlproperty real LineSeries::width
69 The width of the line. By default the width is 2.0.
69 The width of the line. By default the width is 2.0.
70 */
70 */
71
71
72 /*!
72 /*!
73 \qmlproperty Qt::PenStyle LineSeries::style
73 \qmlproperty Qt::PenStyle LineSeries::style
74 Controls the style of the line. Set to one of Qt.NoPen, Qt.SolidLine, Qt.DashLine, Qt.DotLine,
74 Controls the style of the line. Set to one of Qt.NoPen, Qt.SolidLine, Qt.DashLine, Qt.DotLine,
75 Qt.DashDotLine or Qt.DashDotDotLine. Using Qt.CustomDashLine is not supported in the QML API.
75 Qt.DashDotLine or Qt.DashDotDotLine. Using Qt.CustomDashLine is not supported in the QML API.
76 By default the style is Qt.SolidLine.
76 By default the style is Qt.SolidLine.
77 */
77 */
78
78
79 /*!
79 /*!
80 \qmlproperty Qt::PenCapStyle LineSeries::capStyle
80 \qmlproperty Qt::PenCapStyle LineSeries::capStyle
81 Controls the cap style of the line. Set to one of Qt.FlatCap, Qt.SquareCap or Qt.RoundCap. By
81 Controls the cap style of the line. Set to one of Qt.FlatCap, Qt.SquareCap or Qt.RoundCap. By
82 default the cap style is Qt.SquareCap.
82 default the cap style is Qt.SquareCap.
83 */
83 */
84
84
85 /*!
85 /*!
86 Constructs empty series object which is a child of \a parent.
86 Constructs empty series object which is a child of \a parent.
87 When series object is added to QChartView or QChart instance ownerships is transferred.
87 When series object is added to QChartView or QChart instance ownerships is transferred.
88 */
88 */
89 QLineSeries::QLineSeries(QObject *parent)
89 QLineSeries::QLineSeries(QObject *parent)
90 : QXYSeries(*new QLineSeriesPrivate(this), parent)
90 : QXYSeries(*new QLineSeriesPrivate(this), parent)
91 {
91 {
92
92
93 }
93 }
94
94
95 /*!
95 /*!
96 \internal
96 \internal
97 */
97 */
98 QLineSeries::QLineSeries(QLineSeriesPrivate &d, QObject *parent)
98 QLineSeries::QLineSeries(QLineSeriesPrivate &d, QObject *parent)
99 : QXYSeries(d, parent)
99 : QXYSeries(d, parent)
100 {
100 {
101
101
102 }
102 }
103 /*!
103 /*!
104 Destroys the object. Series added to QChartView or QChart instances are owned by those,
104 Destroys the object. Series added to QChartView or QChart instances are owned by those,
105 and are deleted when mentioned object are destroyed.
105 and are deleted when mentioned object are destroyed.
106 */
106 */
107 QLineSeries::~QLineSeries()
107 QLineSeries::~QLineSeries()
108 {
108 {
109 Q_D(QLineSeries);
109 Q_D(QLineSeries);
110 if (d->m_chart)
110 if (d->m_chart)
111 d->m_chart->removeSeries(this);
111 d->m_chart->removeSeries(this);
112 }
112 }
113
113
114 QAbstractSeries::SeriesType QLineSeries::type() const
114 QAbstractSeries::SeriesType QLineSeries::type() const
115 {
115 {
116 return QAbstractSeries::SeriesTypeLine;
116 return QAbstractSeries::SeriesTypeLine;
117 }
117 }
118
118
119 /*
119 /*
120 QDebug operator<< (QDebug debug, const QLineSeries series)
120 QDebug operator<< (QDebug debug, const QLineSeries series)
121 {
121 {
122 Q_ASSERT(series.d_func()->m_x.size() == series.d_func()->m_y.size());
122 Q_ASSERT(series.d_func()->m_x.size() == series.d_func()->m_y.size());
123 int size = series.d_func()->m_x.size();
123 int size = series.d_func()->m_x.size();
124 for (int i=0; i<size; i++) {
124 for (int i=0; i<size; i++) {
125 debug.nospace() << "(" << series.d_func()->m_x.at(i) << ','<< series.d_func()->m_y.at(i) << ") ";
125 debug.nospace() << "(" << series.d_func()->m_x.at(i) << ','<< series.d_func()->m_y.at(i) << ") ";
126 }
126 }
127 return debug.space();
127 return debug.space();
128 }
128 }
129 */
129 */
130
130
131 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
131 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
132
132
133 QLineSeriesPrivate::QLineSeriesPrivate(QLineSeries *q)
133 QLineSeriesPrivate::QLineSeriesPrivate(QLineSeries *q)
134 : QXYSeriesPrivate(q)
134 : QXYSeriesPrivate(q)
135 {
135 {
136
136
137 };
137 };
138
138
139 void QLineSeriesPrivate::initializeGraphics(QGraphicsItem *parent)
139 void QLineSeriesPrivate::initializeGraphics(QGraphicsItem *parent)
140 {
140 {
141 Q_Q(QLineSeries);
141 Q_Q(QLineSeries);
142 LineChartItem *line = new LineChartItem(q,parent);
142 LineChartItem *line = new LineChartItem(q,parent);
143 m_item.reset(line);
143 m_item.reset(line);
144 QAbstractSeriesPrivate::initializeGraphics(parent);
144 QAbstractSeriesPrivate::initializeGraphics(parent);
145 }
145 }
146
146
147 void QLineSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced)
147 void QLineSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced)
148 {
148 {
149 Q_Q(QLineSeries);
149 Q_Q(QLineSeries);
150 const QList<QColor> colors = theme->seriesColors();
150 const QList<QColor> colors = theme->seriesColors();
151
151
152 QPen pen;
152 if (forced || QChartPrivate::defaultPen() == m_pen) {
153 if (forced || pen == m_pen) {
153 QPen pen;
154 pen.setColor(colors.at(index % colors.size()));
154 pen.setColor(colors.at(index % colors.size()));
155 pen.setWidthF(2);
155 pen.setWidthF(2);
156 q->setPen(pen);
156 q->setPen(pen);
157 }
157 }
158 }
158 }
159
159
160 #include "moc_qlineseries.cpp"
160 #include "moc_qlineseries.cpp"
161
161
162 QTCOMMERCIALCHART_END_NAMESPACE
162 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,754 +1,784
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 "qchart.h"
21 #include "qchart.h"
22 #include "qchart_p.h"
22 #include "qchart_p.h"
23 #include "legendscroller_p.h"
23 #include "legendscroller_p.h"
24 #include "qlegend_p.h"
24 #include "qlegend_p.h"
25 #include "chartbackground_p.h"
25 #include "chartbackground_p.h"
26 #include "qabstractaxis.h"
26 #include "qabstractaxis.h"
27 #include "abstractchartlayout_p.h"
27 #include "abstractchartlayout_p.h"
28 #include "charttheme_p.h"
28 #include "charttheme_p.h"
29 #include "chartpresenter_p.h"
29 #include "chartpresenter_p.h"
30 #include "chartdataset_p.h"
30 #include "chartdataset_p.h"
31 #include <QGraphicsScene>
31 #include <QGraphicsScene>
32 #include <QGraphicsSceneResizeEvent>
32 #include <QGraphicsSceneResizeEvent>
33
33
34 QTCOMMERCIALCHART_BEGIN_NAMESPACE
34 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35
35
36 /*!
36 /*!
37 \enum QChart::ChartTheme
37 \enum QChart::ChartTheme
38
38
39 This enum describes the theme used by the chart.
39 This enum describes the theme used by the chart.
40
40
41 \value ChartThemeLight The default theme
41 \value ChartThemeLight The default theme
42 \value ChartThemeBlueCerulean
42 \value ChartThemeBlueCerulean
43 \value ChartThemeDark
43 \value ChartThemeDark
44 \value ChartThemeBrownSand
44 \value ChartThemeBrownSand
45 \value ChartThemeBlueNcs
45 \value ChartThemeBlueNcs
46 \value ChartThemeHighContrast
46 \value ChartThemeHighContrast
47 \value ChartThemeBlueIcy
47 \value ChartThemeBlueIcy
48 */
48 */
49
49
50 /*!
50 /*!
51 \enum QChart::AnimationOption
51 \enum QChart::AnimationOption
52
52
53 For enabling/disabling animations. Defaults to NoAnimation.
53 For enabling/disabling animations. Defaults to NoAnimation.
54
54
55 \value NoAnimation
55 \value NoAnimation
56 \value GridAxisAnimations
56 \value GridAxisAnimations
57 \value SeriesAnimations
57 \value SeriesAnimations
58 \value AllAnimations
58 \value AllAnimations
59 */
59 */
60
60
61 /*!
61 /*!
62 \enum QChart::ChartType
62 \enum QChart::ChartType
63
63
64 This enum describes the chart type.
64 This enum describes the chart type.
65
65
66 \value ChartTypeUndefined
66 \value ChartTypeUndefined
67 \value ChartTypeCartesian
67 \value ChartTypeCartesian
68 \value ChartTypePolar
68 \value ChartTypePolar
69 */
69 */
70
70
71 /*!
71 /*!
72 \class QChart
72 \class QChart
73 \brief QtCommercial chart API.
73 \brief QtCommercial chart API.
74
74
75 QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical
75 QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical
76 representation of different types of series and other chart related objects like legend and
76 representation of different types of series and other chart related objects like legend and
77 axes. If you simply want to show a chart in a layout, you can use the
77 axes. If you simply want to show a chart in a layout, you can use the
78 convenience class QChartView instead of QChart.
78 convenience class QChartView instead of QChart.
79 \sa QChartView, QPolarChart
79 \sa QChartView, QPolarChart
80 */
80 */
81
81
82 /*!
82 /*!
83 \property QChart::animationOptions
83 \property QChart::animationOptions
84 The animation \a options for the chart. Animations are enabled/disabled based on this setting.
84 The animation \a options for the chart. Animations are enabled/disabled based on this setting.
85 */
85 */
86
86
87 /*!
87 /*!
88 \property QChart::backgroundVisible
88 \property QChart::backgroundVisible
89 Specifies whether the chart background is visible or not.
89 Specifies whether the chart background is visible or not.
90 \sa setBackgroundBrush(), setBackgroundPen(), plotAreaBackgroundVisible
90 \sa setBackgroundBrush(), setBackgroundPen(), plotAreaBackgroundVisible
91 */
91 */
92
92
93 /*!
93 /*!
94 \property QChart::dropShadowEnabled
94 \property QChart::dropShadowEnabled
95 If set to true, the background drop shadow effect is enabled. If set to false, it is disabled. Note that the drop
95 If set to true, the background drop shadow effect is enabled. If set to false, it is disabled. Note that the drop
96 shadow effect depends on theme, which means the setting may be changed if you switch to another theme.
96 shadow effect depends on theme, which means the setting may be changed if you switch to another theme.
97 */
97 */
98
98
99 /*!
99 /*!
100 \property QChart::minimumMargins
100 \property QChart::minimumMargins
101 Minimum margins between the plot area (axes) and the edge of the chart widget.
101 Minimum margins between the plot area (axes) and the edge of the chart widget.
102 This property is deprecated; use margins property instead.
102 This property is deprecated; use margins property instead.
103
103
104 \sa margins
104 \sa margins
105 */
105 */
106
106
107 /*!
107 /*!
108 \property QChart::margins
108 \property QChart::margins
109 Margins between the plot area (axes) and the edge of the chart widget.
109 Margins between the plot area (axes) and the edge of the chart widget.
110 */
110 */
111
111
112 /*!
112 /*!
113 \property QChart::theme
113 \property QChart::theme
114 Theme is a built-in collection of UI style related settings applied for all visual elements of a chart, like colors,
114 Theme is a built-in collection of UI style related settings applied for all visual elements of a chart, like colors,
115 pens, brushes, and fonts of series, axes, title, and legend. \l {Chart themes demo} shows an example with a few
115 pens, brushes, and fonts of series, axes, title, and legend. \l {Chart themes demo} shows an example with a few
116 different themes.
116 different themes.
117 \note Changing the theme will overwrite all customizations previously applied to the series.
117 \note Changing the theme will overwrite all customizations previously applied to the series.
118 */
118 */
119
119
120 /*!
120 /*!
121 \property QChart::title
121 \property QChart::title
122 Title is the name (label) of a chart. It is shown as a headline on top of the chart.
122 Title is the name (label) of a chart. It is shown as a headline on top of the chart.
123 */
123 */
124
124
125 /*!
125 /*!
126 \property QChart::chartType
126 \property QChart::chartType
127 Chart type indicates if the chart is a cartesian chart or a polar chart.
127 Chart type indicates if the chart is a cartesian chart or a polar chart.
128 This property is set internally and it is read only.
128 This property is set internally and it is read only.
129 \sa QPolarChart
129 \sa QPolarChart
130 */
130 */
131
131
132 /*!
132 /*!
133 \property QChart::plotAreaBackgroundVisible
133 \property QChart::plotAreaBackgroundVisible
134 Specifies whether the chart plot area background is visible or not.
134 Specifies whether the chart plot area background is visible or not.
135 \note By default the plot area background is not visible and the plot area uses
135 \note By default the plot area background is not visible and the plot area uses
136 the general chart background.
136 the general chart background.
137 \sa setPlotAreaBackgroundBrush(), setPlotAreaBackgroundPen(), backgroundVisible
137 \sa setPlotAreaBackgroundBrush(), setPlotAreaBackgroundPen(), backgroundVisible
138 */
138 */
139
139
140 /*!
140 /*!
141 \internal
141 \internal
142 Constructs a chart object of \a type which is a child of a \a parent.
142 Constructs a chart object of \a type which is a child of a \a parent.
143 Parameter \a wFlags is passed to the QGraphicsWidget constructor.
143 Parameter \a wFlags is passed to the QGraphicsWidget constructor.
144 This constructor is called only by subclasses.
144 This constructor is called only by subclasses.
145 */
145 */
146 QChart::QChart(QChart::ChartType type, QGraphicsItem *parent, Qt::WindowFlags wFlags)
146 QChart::QChart(QChart::ChartType type, QGraphicsItem *parent, Qt::WindowFlags wFlags)
147 : QGraphicsWidget(parent, wFlags),
147 : QGraphicsWidget(parent, wFlags),
148 d_ptr(new QChartPrivate(this, type))
148 d_ptr(new QChartPrivate(this, type))
149 {
149 {
150 d_ptr->init();
150 d_ptr->init();
151 }
151 }
152
152
153 /*!
153 /*!
154 Constructs a chart object which is a child of a \a parent.
154 Constructs a chart object which is a child of a \a parent.
155 Parameter \a wFlags is passed to the QGraphicsWidget constructor.
155 Parameter \a wFlags is passed to the QGraphicsWidget constructor.
156 */
156 */
157 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags)
157 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags)
158 : QGraphicsWidget(parent, wFlags),
158 : QGraphicsWidget(parent, wFlags),
159 d_ptr(new QChartPrivate(this, ChartTypeCartesian))
159 d_ptr(new QChartPrivate(this, ChartTypeCartesian))
160 {
160 {
161 d_ptr->init();
161 d_ptr->init();
162 }
162 }
163
163
164 /*!
164 /*!
165 Destroys the chart object and its children, like series and axis objects added to it.
165 Destroys the chart object and its children, like series and axis objects added to it.
166 */
166 */
167 QChart::~QChart()
167 QChart::~QChart()
168 {
168 {
169 //start by deleting dataset, it will remove all series and axes
169 //start by deleting dataset, it will remove all series and axes
170 delete d_ptr->m_dataset;
170 delete d_ptr->m_dataset;
171 d_ptr->m_dataset = 0;
171 d_ptr->m_dataset = 0;
172 }
172 }
173
173
174 /*!
174 /*!
175 Adds the \a series onto the chart and takes the ownership of it.
175 Adds the \a series onto the chart and takes the ownership of it.
176
176
177 \note A newly added series is attached to no axes by default, including any axes that were created for the chart
177 \note A newly added series is attached to no axes by default, including any axes that were created for the chart
178 using createDefaultAxes() before the series was added to the chart. If no axes are attached to
178 using createDefaultAxes() before the series was added to the chart. If no axes are attached to
179 the newly added series before the chart is shown, the series will get drawn as if it had axes with ranges
179 the newly added series before the chart is shown, the series will get drawn as if it had axes with ranges
180 that exactly fit the series to the plot area of the chart. This can be confusing if the same chart also displays other
180 that exactly fit the series to the plot area of the chart. This can be confusing if the same chart also displays other
181 series that have properly attached axes, so always make sure you either call createDefaultAxes() after
181 series that have properly attached axes, so always make sure you either call createDefaultAxes() after
182 a series has been added or explicitly attach axes for the series.
182 a series has been added or explicitly attach axes for the series.
183
183
184 \sa removeSeries(), removeAllSeries(), createDefaultAxes(), QAbstractSeries::attachAxis()
184 \sa removeSeries(), removeAllSeries(), createDefaultAxes(), QAbstractSeries::attachAxis()
185 */
185 */
186 void QChart::addSeries(QAbstractSeries *series)
186 void QChart::addSeries(QAbstractSeries *series)
187 {
187 {
188 Q_ASSERT(series);
188 Q_ASSERT(series);
189 d_ptr->m_dataset->addSeries(series);
189 d_ptr->m_dataset->addSeries(series);
190 }
190 }
191
191
192 /*!
192 /*!
193 Removes the \a series from the chart.
193 Removes the \a series from the chart.
194 The chart releases its ownership of the specified \a series object.
194 The chart releases its ownership of the specified \a series object.
195
195
196 \sa addSeries(), removeAllSeries()
196 \sa addSeries(), removeAllSeries()
197 */
197 */
198 void QChart::removeSeries(QAbstractSeries *series)
198 void QChart::removeSeries(QAbstractSeries *series)
199 {
199 {
200 Q_ASSERT(series);
200 Q_ASSERT(series);
201 d_ptr->m_dataset->removeSeries(series);
201 d_ptr->m_dataset->removeSeries(series);
202 }
202 }
203
203
204 /*!
204 /*!
205 Removes and deletes all series objects that have been added to the chart.
205 Removes and deletes all series objects that have been added to the chart.
206
206
207 \sa addSeries(), removeSeries()
207 \sa addSeries(), removeSeries()
208 */
208 */
209 void QChart::removeAllSeries()
209 void QChart::removeAllSeries()
210 {
210 {
211 foreach (QAbstractSeries *s , d_ptr->m_dataset->series()){
211 foreach (QAbstractSeries *s , d_ptr->m_dataset->series()){
212 removeSeries(s);
212 removeSeries(s);
213 delete s;
213 delete s;
214 }
214 }
215 }
215 }
216
216
217 /*!
217 /*!
218 Sets the \a brush that is used for painting the background of the chart area.
218 Sets the \a brush that is used for painting the background of the chart area.
219 */
219 */
220 void QChart::setBackgroundBrush(const QBrush &brush)
220 void QChart::setBackgroundBrush(const QBrush &brush)
221 {
221 {
222 d_ptr->m_presenter->setBackgroundBrush(brush);
222 d_ptr->m_presenter->setBackgroundBrush(brush);
223 }
223 }
224
224
225 /*!
225 /*!
226 Gets the brush that is used for painting the background of the chart area.
226 Gets the brush that is used for painting the background of the chart area.
227 */
227 */
228 QBrush QChart::backgroundBrush() const
228 QBrush QChart::backgroundBrush() const
229 {
229 {
230 return d_ptr->m_presenter->backgroundBrush();
230 return d_ptr->m_presenter->backgroundBrush();
231 }
231 }
232
232
233 /*!
233 /*!
234 Sets the \a pen that is used for painting the background of the chart area.
234 Sets the \a pen that is used for painting the background of the chart area.
235 */
235 */
236 void QChart::setBackgroundPen(const QPen &pen)
236 void QChart::setBackgroundPen(const QPen &pen)
237 {
237 {
238 d_ptr->m_presenter->setBackgroundPen(pen);
238 d_ptr->m_presenter->setBackgroundPen(pen);
239 }
239 }
240
240
241 /*!
241 /*!
242 Gets the pen that is used for painting the background of the chart area.
242 Gets the pen that is used for painting the background of the chart area.
243 */
243 */
244 QPen QChart::backgroundPen() const
244 QPen QChart::backgroundPen() const
245 {
245 {
246 return d_ptr->m_presenter->backgroundPen();
246 return d_ptr->m_presenter->backgroundPen();
247 }
247 }
248
248
249 void QChart::setTitle(const QString &title)
249 void QChart::setTitle(const QString &title)
250 {
250 {
251 d_ptr->m_presenter->setTitle(title);
251 d_ptr->m_presenter->setTitle(title);
252 }
252 }
253
253
254 QString QChart::title() const
254 QString QChart::title() const
255 {
255 {
256 return d_ptr->m_presenter->title();
256 return d_ptr->m_presenter->title();
257 }
257 }
258
258
259 /*!
259 /*!
260 Sets the \a font that is used for drawing the chart title.
260 Sets the \a font that is used for drawing the chart title.
261 */
261 */
262 void QChart::setTitleFont(const QFont &font)
262 void QChart::setTitleFont(const QFont &font)
263 {
263 {
264 d_ptr->m_presenter->setTitleFont(font);
264 d_ptr->m_presenter->setTitleFont(font);
265 }
265 }
266
266
267 /*!
267 /*!
268 Gets the font that is used for drawing the chart title.
268 Gets the font that is used for drawing the chart title.
269 */
269 */
270 QFont QChart::titleFont() const
270 QFont QChart::titleFont() const
271 {
271 {
272 return d_ptr->m_presenter->titleFont();
272 return d_ptr->m_presenter->titleFont();
273 }
273 }
274
274
275 /*!
275 /*!
276 Sets the \a brush used for drawing the title text.
276 Sets the \a brush used for drawing the title text.
277 */
277 */
278 void QChart::setTitleBrush(const QBrush &brush)
278 void QChart::setTitleBrush(const QBrush &brush)
279 {
279 {
280 d_ptr->m_presenter->setTitleBrush(brush);
280 d_ptr->m_presenter->setTitleBrush(brush);
281 }
281 }
282
282
283 /*!
283 /*!
284 Returns the brush used for drawing the title text.
284 Returns the brush used for drawing the title text.
285 */
285 */
286 QBrush QChart::titleBrush() const
286 QBrush QChart::titleBrush() const
287 {
287 {
288 return d_ptr->m_presenter->titleBrush();
288 return d_ptr->m_presenter->titleBrush();
289 }
289 }
290
290
291 void QChart::setTheme(QChart::ChartTheme theme)
291 void QChart::setTheme(QChart::ChartTheme theme)
292 {
292 {
293 d_ptr->m_themeManager->setTheme(theme);
293 d_ptr->m_themeManager->setTheme(theme);
294 }
294 }
295
295
296 QChart::ChartTheme QChart::theme() const
296 QChart::ChartTheme QChart::theme() const
297 {
297 {
298 return d_ptr->m_themeManager->theme()->id();
298 return d_ptr->m_themeManager->theme()->id();
299 }
299 }
300
300
301 /*!
301 /*!
302 Zooms in the view by a factor of two.
302 Zooms in the view by a factor of two.
303 */
303 */
304 void QChart::zoomIn()
304 void QChart::zoomIn()
305 {
305 {
306 d_ptr->zoomIn(2.0);
306 d_ptr->zoomIn(2.0);
307 }
307 }
308
308
309 /*!
309 /*!
310 Zooms in the view to a maximum level at which \a rect is still fully visible.
310 Zooms in the view to a maximum level at which \a rect is still fully visible.
311 \note This is not supported for polar charts.
311 \note This is not supported for polar charts.
312 */
312 */
313 void QChart::zoomIn(const QRectF &rect)
313 void QChart::zoomIn(const QRectF &rect)
314 {
314 {
315 if (d_ptr->m_type == QChart::ChartTypePolar)
315 if (d_ptr->m_type == QChart::ChartTypePolar)
316 return;
316 return;
317 d_ptr->zoomIn(rect);
317 d_ptr->zoomIn(rect);
318 }
318 }
319
319
320 /*!
320 /*!
321 Zooms out the view by a factor of two.
321 Zooms out the view by a factor of two.
322 */
322 */
323 void QChart::zoomOut()
323 void QChart::zoomOut()
324 {
324 {
325 d_ptr->zoomOut(2.0);
325 d_ptr->zoomOut(2.0);
326 }
326 }
327
327
328 /*!
328 /*!
329 Zooms in the view by a custom \a factor.
329 Zooms in the view by a custom \a factor.
330
330
331 A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out.
331 A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out.
332 */
332 */
333 void QChart::zoom(qreal factor)
333 void QChart::zoom(qreal factor)
334 {
334 {
335 if (qFuzzyCompare(factor, 0))
335 if (qFuzzyCompare(factor, 0))
336 return;
336 return;
337
337
338 if (qFuzzyCompare(factor, (qreal)1.0))
338 if (qFuzzyCompare(factor, (qreal)1.0))
339 return;
339 return;
340
340
341 if (factor < 0)
341 if (factor < 0)
342 return;
342 return;
343
343
344 if (factor > 1.0)
344 if (factor > 1.0)
345 d_ptr->zoomIn(factor);
345 d_ptr->zoomIn(factor);
346 else
346 else
347 d_ptr->zoomOut(1.0 / factor);
347 d_ptr->zoomOut(1.0 / factor);
348 }
348 }
349
349
350 /*!
350 /*!
351 Returns a pointer to the horizontal axis attached to the specified \a series.
351 Returns a pointer to the horizontal axis attached to the specified \a series.
352 If no \a series is specified, the first horizontal axis added to the chart is returned.
352 If no \a series is specified, the first horizontal axis added to the chart is returned.
353
353
354 \sa addAxis(), QAbstractSeries::attachAxis()
354 \sa addAxis(), QAbstractSeries::attachAxis()
355 */
355 */
356 QAbstractAxis *QChart::axisX(QAbstractSeries *series) const
356 QAbstractAxis *QChart::axisX(QAbstractSeries *series) const
357 {
357 {
358 QList<QAbstractAxis *> axisList = axes(Qt::Horizontal, series);
358 QList<QAbstractAxis *> axisList = axes(Qt::Horizontal, series);
359 if (axisList.count())
359 if (axisList.count())
360 return axisList[0];
360 return axisList[0];
361 return 0;
361 return 0;
362 }
362 }
363
363
364 /*!
364 /*!
365 Returns a pointer to the vertical axis attached to the specified \a series.
365 Returns a pointer to the vertical axis attached to the specified \a series.
366 If no \a series is specified, the first vertical axis added to the chart is returned.
366 If no \a series is specified, the first vertical axis added to the chart is returned.
367
367
368 \sa addAxis(), QAbstractSeries::attachAxis()
368 \sa addAxis(), QAbstractSeries::attachAxis()
369 */
369 */
370 QAbstractAxis *QChart::axisY(QAbstractSeries *series) const
370 QAbstractAxis *QChart::axisY(QAbstractSeries *series) const
371 {
371 {
372 QList<QAbstractAxis *> axisList = axes(Qt::Vertical, series);
372 QList<QAbstractAxis *> axisList = axes(Qt::Vertical, series);
373 if (axisList.count())
373 if (axisList.count())
374 return axisList[0];
374 return axisList[0];
375 return 0;
375 return 0;
376 }
376 }
377
377
378 /*!
378 /*!
379 Returns the axes attached to the \a series with \a orientation. If no \a series is provided,
379 Returns the axes attached to the \a series with \a orientation. If no \a series is provided,
380 then all axes added to the chart with the specified orientation are returned.
380 then all axes added to the chart with the specified orientation are returned.
381 \sa addAxis(), createDefaultAxes()
381 \sa addAxis(), createDefaultAxes()
382 */
382 */
383 QList<QAbstractAxis *> QChart::axes(Qt::Orientations orientation, QAbstractSeries *series) const
383 QList<QAbstractAxis *> QChart::axes(Qt::Orientations orientation, QAbstractSeries *series) const
384 {
384 {
385 QList<QAbstractAxis *> result ;
385 QList<QAbstractAxis *> result ;
386
386
387 if (series) {
387 if (series) {
388 foreach (QAbstractAxis *axis, series->attachedAxes()){
388 foreach (QAbstractAxis *axis, series->attachedAxes()){
389 if (orientation.testFlag(axis->orientation()))
389 if (orientation.testFlag(axis->orientation()))
390 result << axis;
390 result << axis;
391 }
391 }
392 } else {
392 } else {
393 foreach (QAbstractAxis *axis, d_ptr->m_dataset->axes()){
393 foreach (QAbstractAxis *axis, d_ptr->m_dataset->axes()){
394 if (orientation.testFlag(axis->orientation()) && !result.contains(axis))
394 if (orientation.testFlag(axis->orientation()) && !result.contains(axis))
395 result << axis;
395 result << axis;
396 }
396 }
397 }
397 }
398
398
399 return result;
399 return result;
400 }
400 }
401
401
402 /*!
402 /*!
403 Creates axes for the chart based on the series that have already been added to the chart. Any axes previously added to
403 Creates axes for the chart based on the series that have already been added to the chart. Any axes previously added to
404 the chart will be deleted.
404 the chart will be deleted.
405
405
406 \note This function has to be called after all series have been added to the chart. The axes created by this function
406 \note This function has to be called after all series have been added to the chart. The axes created by this function
407 will NOT get automatically attached to any series added to the chart after this function has been called.
407 will NOT get automatically attached to any series added to the chart after this function has been called.
408 A series with no axes attached will by default scale to utilize the entire plot area of the chart, which can be confusing
408 A series with no axes attached will by default scale to utilize the entire plot area of the chart, which can be confusing
409 if there are other series with properly attached axes also present.
409 if there are other series with properly attached axes also present.
410
410
411 \table
411 \table
412 \header
412 \header
413 \o Series type
413 \o Series type
414 \o X-axis
414 \o X-axis
415 \o Y-axis
415 \o Y-axis
416 \row
416 \row
417 \o QXYSeries
417 \o QXYSeries
418 \o QValueAxis
418 \o QValueAxis
419 \o QValueAxis
419 \o QValueAxis
420 \row
420 \row
421 \o QBarSeries
421 \o QBarSeries
422 \o QBarCategoryAxis
422 \o QBarCategoryAxis
423 \o QValueAxis
423 \o QValueAxis
424 \row
424 \row
425 \o QPieSeries
425 \o QPieSeries
426 \o None
426 \o None
427 \o None
427 \o None
428 \endtable
428 \endtable
429
429
430 If there are several QXYSeries derived series added to the chart and no series of other types have been added, then only one pair of axes is created.
430 If there are several QXYSeries derived series added to the chart and no series of other types have been added, then only one pair of axes is created.
431 If there are several series of different types added to the chart, then each series gets its own axes pair.
431 If there are several series of different types added to the chart, then each series gets its own axes pair.
432
432
433 The axes specific to the series can be later obtained from the chart by providing the series as the parameter for axes() function call.
433 The axes specific to the series can be later obtained from the chart by providing the series as the parameter for axes() function call.
434 QPieSeries does not create any axes.
434 QPieSeries does not create any axes.
435
435
436 \sa axisX(), axisY(), axes(), setAxisX(), setAxisY(), QAbstractSeries::attachAxis()
436 \sa axisX(), axisY(), axes(), setAxisX(), setAxisY(), QAbstractSeries::attachAxis()
437 */
437 */
438 void QChart::createDefaultAxes()
438 void QChart::createDefaultAxes()
439 {
439 {
440 d_ptr->m_dataset->createDefaultAxes();
440 d_ptr->m_dataset->createDefaultAxes();
441 }
441 }
442
442
443 /*!
443 /*!
444 Returns the legend object of the chart. Ownership stays with the chart.
444 Returns the legend object of the chart. Ownership stays with the chart.
445 */
445 */
446 QLegend *QChart::legend() const
446 QLegend *QChart::legend() const
447 {
447 {
448 return d_ptr->m_legend;
448 return d_ptr->m_legend;
449 }
449 }
450
450
451 void QChart::setMinimumMargins(const QMargins &margins)
451 void QChart::setMinimumMargins(const QMargins &margins)
452 {
452 {
453 qWarning() << "QChart::setMinimumMargins is deprecated. Use QChart::setMargins instead.";
453 qWarning() << "QChart::setMinimumMargins is deprecated. Use QChart::setMargins instead.";
454 d_ptr->m_presenter->layout()->setMargins(margins);
454 d_ptr->m_presenter->layout()->setMargins(margins);
455 }
455 }
456
456
457 QMargins QChart::minimumMargins() const
457 QMargins QChart::minimumMargins() const
458 {
458 {
459 qWarning() << "QChart::minimumMargins is deprecated. Use QChart::margins instead.";
459 qWarning() << "QChart::minimumMargins is deprecated. Use QChart::margins instead.";
460 return d_ptr->m_presenter->layout()->margins();
460 return d_ptr->m_presenter->layout()->margins();
461 }
461 }
462
462
463 void QChart::setMargins(const QMargins &margins)
463 void QChart::setMargins(const QMargins &margins)
464 {
464 {
465 d_ptr->m_presenter->layout()->setMargins(margins);
465 d_ptr->m_presenter->layout()->setMargins(margins);
466 }
466 }
467
467
468 QMargins QChart::margins() const
468 QMargins QChart::margins() const
469 {
469 {
470 return d_ptr->m_presenter->layout()->margins();
470 return d_ptr->m_presenter->layout()->margins();
471 }
471 }
472
472
473 QChart::ChartType QChart::chartType() const
473 QChart::ChartType QChart::chartType() const
474 {
474 {
475 return d_ptr->m_type;
475 return d_ptr->m_type;
476 }
476 }
477
477
478 /*!
478 /*!
479 Returns the the rectangle within which the drawing of the chart is done.
479 Returns the the rectangle within which the drawing of the chart is done.
480 It does not include the area defined by margins.
480 It does not include the area defined by margins.
481 */
481 */
482 QRectF QChart::plotArea() const
482 QRectF QChart::plotArea() const
483 {
483 {
484 return d_ptr->m_presenter->geometry();
484 return d_ptr->m_presenter->geometry();
485 }
485 }
486
486
487 /*!
487 /*!
488 Sets the \a brush for the background of the plot area of the chart.
488 Sets the \a brush for the background of the plot area of the chart.
489
489
490 \sa plotArea(), plotAreaBackgroundVisible, setPlotAreaBackgroundPen(), plotAreaBackgroundBrush()
490 \sa plotArea(), plotAreaBackgroundVisible, setPlotAreaBackgroundPen(), plotAreaBackgroundBrush()
491 */
491 */
492 void QChart::setPlotAreaBackgroundBrush(const QBrush &brush)
492 void QChart::setPlotAreaBackgroundBrush(const QBrush &brush)
493 {
493 {
494 d_ptr->m_presenter->setPlotAreaBackgroundBrush(brush);
494 d_ptr->m_presenter->setPlotAreaBackgroundBrush(brush);
495 }
495 }
496
496
497 /*!
497 /*!
498 Returns the brush for the background of the plot area of the chart.
498 Returns the brush for the background of the plot area of the chart.
499
499
500 \sa plotArea(), plotAreaBackgroundVisible, plotAreaBackgroundPen(), setPlotAreaBackgroundBrush()
500 \sa plotArea(), plotAreaBackgroundVisible, plotAreaBackgroundPen(), setPlotAreaBackgroundBrush()
501 */
501 */
502 QBrush QChart::plotAreaBackgroundBrush() const
502 QBrush QChart::plotAreaBackgroundBrush() const
503 {
503 {
504 return d_ptr->m_presenter->plotAreaBackgroundBrush();
504 return d_ptr->m_presenter->plotAreaBackgroundBrush();
505 }
505 }
506
506
507 /*!
507 /*!
508 Sets the \a pen for the background of the plot area of the chart.
508 Sets the \a pen for the background of the plot area of the chart.
509
509
510 \sa plotArea(), plotAreaBackgroundVisible, setPlotAreaBackgroundBrush(), plotAreaBackgroundPen()
510 \sa plotArea(), plotAreaBackgroundVisible, setPlotAreaBackgroundBrush(), plotAreaBackgroundPen()
511 */
511 */
512 void QChart::setPlotAreaBackgroundPen(const QPen &pen)
512 void QChart::setPlotAreaBackgroundPen(const QPen &pen)
513 {
513 {
514 d_ptr->m_presenter->setPlotAreaBackgroundPen(pen);
514 d_ptr->m_presenter->setPlotAreaBackgroundPen(pen);
515 }
515 }
516
516
517 /*!
517 /*!
518 Returns the pen for the background of the plot area of the chart.
518 Returns the pen for the background of the plot area of the chart.
519
519
520 \sa plotArea(), plotAreaBackgroundVisible, plotAreaBackgroundBrush(), setPlotAreaBackgroundPen()
520 \sa plotArea(), plotAreaBackgroundVisible, plotAreaBackgroundBrush(), setPlotAreaBackgroundPen()
521 */
521 */
522 QPen QChart::plotAreaBackgroundPen() const
522 QPen QChart::plotAreaBackgroundPen() const
523 {
523 {
524 return d_ptr->m_presenter->plotAreaBackgroundPen();
524 return d_ptr->m_presenter->plotAreaBackgroundPen();
525 }
525 }
526
526
527 void QChart::setPlotAreaBackgroundVisible(bool visible)
527 void QChart::setPlotAreaBackgroundVisible(bool visible)
528 {
528 {
529 d_ptr->m_presenter->setPlotAreaBackgroundVisible(visible);
529 d_ptr->m_presenter->setPlotAreaBackgroundVisible(visible);
530 }
530 }
531
531
532 bool QChart::isPlotAreaBackgroundVisible() const
532 bool QChart::isPlotAreaBackgroundVisible() const
533 {
533 {
534 return d_ptr->m_presenter->isPlotAreaBackgroundVisible();
534 return d_ptr->m_presenter->isPlotAreaBackgroundVisible();
535 }
535 }
536
536
537 void QChart::setAnimationOptions(AnimationOptions options)
537 void QChart::setAnimationOptions(AnimationOptions options)
538 {
538 {
539 d_ptr->m_presenter->setAnimationOptions(options);
539 d_ptr->m_presenter->setAnimationOptions(options);
540 }
540 }
541
541
542 QChart::AnimationOptions QChart::animationOptions() const
542 QChart::AnimationOptions QChart::animationOptions() const
543 {
543 {
544 return d_ptr->m_presenter->animationOptions();
544 return d_ptr->m_presenter->animationOptions();
545 }
545 }
546
546
547 /*!
547 /*!
548 Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy.
548 Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy.
549
549
550 For polar charts, \a dx indicates the angle along angular axis instead of distance.
550 For polar charts, \a dx indicates the angle along angular axis instead of distance.
551 */
551 */
552 void QChart::scroll(qreal dx, qreal dy)
552 void QChart::scroll(qreal dx, qreal dy)
553 {
553 {
554 d_ptr->scroll(dx,dy);
554 d_ptr->scroll(dx,dy);
555 }
555 }
556
556
557 void QChart::setBackgroundVisible(bool visible)
557 void QChart::setBackgroundVisible(bool visible)
558 {
558 {
559 d_ptr->m_presenter->setBackgroundVisible(visible);
559 d_ptr->m_presenter->setBackgroundVisible(visible);
560 }
560 }
561
561
562 bool QChart::isBackgroundVisible() const
562 bool QChart::isBackgroundVisible() const
563 {
563 {
564 return d_ptr->m_presenter->isBackgroundVisible();
564 return d_ptr->m_presenter->isBackgroundVisible();
565 }
565 }
566
566
567 void QChart::setDropShadowEnabled(bool enabled)
567 void QChart::setDropShadowEnabled(bool enabled)
568 {
568 {
569 d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled);
569 d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled);
570 }
570 }
571
571
572 bool QChart::isDropShadowEnabled() const
572 bool QChart::isDropShadowEnabled() const
573 {
573 {
574 return d_ptr->m_presenter->isBackgroundDropShadowEnabled();
574 return d_ptr->m_presenter->isBackgroundDropShadowEnabled();
575 }
575 }
576
576
577 /*!
577 /*!
578 Returns all series that are added to the chart.
578 Returns all series that are added to the chart.
579
579
580 \sa addSeries(), removeSeries(), removeAllSeries()
580 \sa addSeries(), removeSeries(), removeAllSeries()
581 */
581 */
582 QList<QAbstractSeries *> QChart::series() const
582 QList<QAbstractSeries *> QChart::series() const
583 {
583 {
584 return d_ptr->m_dataset->series();
584 return d_ptr->m_dataset->series();
585 }
585 }
586
586
587 /*!
587 /*!
588 Adds the \a axis to the chart and attaches it to the \a series as a bottom-aligned horizontal axis.
588 Adds the \a axis to the chart and attaches it to the \a series as a bottom-aligned horizontal axis.
589 The chart takes ownership of both the \a axis and the \a series.
589 The chart takes ownership of both the \a axis and the \a series.
590 Any horizontal axes previously attached to the \a series are deleted.
590 Any horizontal axes previously attached to the \a series are deleted.
591
591
592 \sa axisX(), axisY(), setAxisY(), createDefaultAxes(), QAbstractSeries::attachAxis()
592 \sa axisX(), axisY(), setAxisY(), createDefaultAxes(), QAbstractSeries::attachAxis()
593 */
593 */
594 void QChart::setAxisX(QAbstractAxis *axis ,QAbstractSeries *series)
594 void QChart::setAxisX(QAbstractAxis *axis ,QAbstractSeries *series)
595 {
595 {
596 QList<QAbstractAxis*> list = axes(Qt::Horizontal, series);
596 QList<QAbstractAxis*> list = axes(Qt::Horizontal, series);
597
597
598 foreach (QAbstractAxis* a, list) {
598 foreach (QAbstractAxis* a, list) {
599 d_ptr->m_dataset->removeAxis(a);
599 d_ptr->m_dataset->removeAxis(a);
600 delete a;
600 delete a;
601 }
601 }
602
602
603 if (!d_ptr->m_dataset->axes().contains(axis))
603 if (!d_ptr->m_dataset->axes().contains(axis))
604 d_ptr->m_dataset->addAxis(axis, Qt::AlignBottom);
604 d_ptr->m_dataset->addAxis(axis, Qt::AlignBottom);
605 d_ptr->m_dataset->attachAxis(series, axis);
605 d_ptr->m_dataset->attachAxis(series, axis);
606 }
606 }
607
607
608 /*!
608 /*!
609 Adds the \a axis to the chart and attaches it to the \a series as a left-aligned vertical axis.
609 Adds the \a axis to the chart and attaches it to the \a series as a left-aligned vertical axis.
610 The chart takes ownership of both the \a axis and the \a series.
610 The chart takes ownership of both the \a axis and the \a series.
611 Any vertical axes previously attached to the \a series are deleted.
611 Any vertical axes previously attached to the \a series are deleted.
612
612
613 \sa axisX(), axisY(), setAxisX(), createDefaultAxes(), QAbstractSeries::attachAxis()
613 \sa axisX(), axisY(), setAxisX(), createDefaultAxes(), QAbstractSeries::attachAxis()
614 */
614 */
615 void QChart::setAxisY(QAbstractAxis *axis ,QAbstractSeries *series)
615 void QChart::setAxisY(QAbstractAxis *axis ,QAbstractSeries *series)
616 {
616 {
617 QList<QAbstractAxis*> list = axes(Qt::Vertical, series);
617 QList<QAbstractAxis*> list = axes(Qt::Vertical, series);
618
618
619 foreach (QAbstractAxis* a, list) {
619 foreach (QAbstractAxis* a, list) {
620 d_ptr->m_dataset->removeAxis(a);
620 d_ptr->m_dataset->removeAxis(a);
621 delete a;
621 delete a;
622 }
622 }
623
623
624 if (!d_ptr->m_dataset->axes().contains(axis))
624 if (!d_ptr->m_dataset->axes().contains(axis))
625 d_ptr->m_dataset->addAxis(axis, Qt::AlignLeft);
625 d_ptr->m_dataset->addAxis(axis, Qt::AlignLeft);
626 d_ptr->m_dataset->attachAxis(series, axis);
626 d_ptr->m_dataset->attachAxis(series, axis);
627 }
627 }
628
628
629 /*!
629 /*!
630 Adds the \a axis to the chart with \a alignment. The chart takes the ownership of the axis.
630 Adds the \a axis to the chart with \a alignment. The chart takes the ownership of the axis.
631
631
632 \sa removeAxis(), createDefaultAxes(), QAbstractSeries::attachAxis()
632 \sa removeAxis(), createDefaultAxes(), QAbstractSeries::attachAxis()
633 */
633 */
634 void QChart::addAxis(QAbstractAxis *axis, Qt::Alignment alignment)
634 void QChart::addAxis(QAbstractAxis *axis, Qt::Alignment alignment)
635 {
635 {
636 d_ptr->m_dataset->addAxis(axis, alignment);
636 d_ptr->m_dataset->addAxis(axis, alignment);
637 }
637 }
638
638
639 /*!
639 /*!
640 Removes the \a axis from the chart.
640 Removes the \a axis from the chart.
641 The chart releases its ownership of the specified \a axis object.
641 The chart releases its ownership of the specified \a axis object.
642
642
643 \sa addAxis(), createDefaultAxes(), QAbstractSeries::detachAxis()
643 \sa addAxis(), createDefaultAxes(), QAbstractSeries::detachAxis()
644 */
644 */
645 void QChart::removeAxis(QAbstractAxis *axis)
645 void QChart::removeAxis(QAbstractAxis *axis)
646 {
646 {
647 d_ptr->m_dataset->removeAxis(axis);
647 d_ptr->m_dataset->removeAxis(axis);
648 }
648 }
649
649
650 /*!
650 /*!
651 Returns the value in the \a series domain that corresponds to the \a position relative to chart widget.
651 Returns the value in the \a series domain that corresponds to the \a position relative to chart widget.
652 */
652 */
653 QPointF QChart::mapToValue(const QPointF &position, QAbstractSeries *series)
653 QPointF QChart::mapToValue(const QPointF &position, QAbstractSeries *series)
654 {
654 {
655 return d_ptr->m_dataset->mapToValue(position, series);
655 return d_ptr->m_dataset->mapToValue(position, series);
656 }
656 }
657
657
658 /*!
658 /*!
659 Returns the position on the chart widget that corresponds to the \a value in the \a series domain.
659 Returns the position on the chart widget that corresponds to the \a value in the \a series domain.
660 */
660 */
661 QPointF QChart::mapToPosition(const QPointF &value, QAbstractSeries *series)
661 QPointF QChart::mapToPosition(const QPointF &value, QAbstractSeries *series)
662 {
662 {
663 return d_ptr->m_dataset->mapToPosition(value, series);
663 return d_ptr->m_dataset->mapToPosition(value, series);
664 }
664 }
665
665
666 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
666 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
667
667
668 QChartPrivate::QChartPrivate(QChart *q, QChart::ChartType type):
668 QChartPrivate::QChartPrivate(QChart *q, QChart::ChartType type):
669 q_ptr(q),
669 q_ptr(q),
670 m_legend(0),
670 m_legend(0),
671 m_dataset(new ChartDataSet(q)),
671 m_dataset(new ChartDataSet(q)),
672 m_presenter(new ChartPresenter(q, type)),
672 m_presenter(new ChartPresenter(q, type)),
673 m_themeManager(new ChartThemeManager(q)),
673 m_themeManager(new ChartThemeManager(q)),
674 m_type(type)
674 m_type(type)
675 {
675 {
676 QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_presenter, SLOT(handleSeriesAdded(QAbstractSeries*)));
676 QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_presenter, SLOT(handleSeriesAdded(QAbstractSeries*)));
677 QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_presenter, SLOT(handleSeriesRemoved(QAbstractSeries*)));
677 QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_presenter, SLOT(handleSeriesRemoved(QAbstractSeries*)));
678 QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_presenter, SLOT(handleAxisAdded(QAbstractAxis*)));
678 QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_presenter, SLOT(handleAxisAdded(QAbstractAxis*)));
679 QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_presenter, SLOT(handleAxisRemoved(QAbstractAxis*)));
679 QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_presenter, SLOT(handleAxisRemoved(QAbstractAxis*)));
680 QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesAdded(QAbstractSeries*)));
680 QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesAdded(QAbstractSeries*)));
681 QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesRemoved(QAbstractSeries*)));
681 QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesRemoved(QAbstractSeries*)));
682 QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_themeManager, SLOT(handleAxisAdded(QAbstractAxis*)));
682 QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_themeManager, SLOT(handleAxisAdded(QAbstractAxis*)));
683 QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_themeManager, SLOT(handleAxisRemoved(QAbstractAxis*)));
683 QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_themeManager, SLOT(handleAxisRemoved(QAbstractAxis*)));
684 }
684 }
685
685
686 QChartPrivate::~QChartPrivate()
686 QChartPrivate::~QChartPrivate()
687 {
687 {
688 }
688 }
689
689
690 // Hackish solution to the problem of explicitly assigning the default pen/brush/font
691 // to a series or axis and having theme override it:
692 // Initialize pens, brushes, and fonts to something nobody is likely to ever use,
693 // so that default theme initialization will always set these properly.
694 QPen &QChartPrivate::defaultPen()
695 {
696 static QPen *defaultPen = 0;
697 if (!defaultPen)
698 defaultPen = new QPen(QColor(1, 2, 0), 0.93247536);
699 return *defaultPen;
700 }
701
702 QBrush &QChartPrivate::defaultBrush()
703 {
704 static QBrush *defaultBrush = 0;
705 if (!defaultBrush)
706 defaultBrush = new QBrush(QColor(1, 2, 0), Qt::Dense7Pattern);
707 return *defaultBrush;
708 }
709
710 QFont &QChartPrivate::defaultFont()
711 {
712 static QFont *defaultFont = 0;
713 if (!defaultFont) {
714 defaultFont = new QFont();
715 defaultFont->setPointSizeF(8.34563465);
716 }
717 return *defaultFont;
718 }
719
690 void QChartPrivate::init()
720 void QChartPrivate::init()
691 {
721 {
692 m_legend = new LegendScroller(q_ptr);
722 m_legend = new LegendScroller(q_ptr);
693 q_ptr->setTheme(QChart::ChartThemeLight);
723 q_ptr->setTheme(QChart::ChartThemeLight);
694 q_ptr->setLayout(m_presenter->layout());
724 q_ptr->setLayout(m_presenter->layout());
695 }
725 }
696
726
697 void QChartPrivate::zoomIn(qreal factor)
727 void QChartPrivate::zoomIn(qreal factor)
698 {
728 {
699 QRectF rect = m_presenter->geometry();
729 QRectF rect = m_presenter->geometry();
700 rect.setWidth(rect.width() / factor);
730 rect.setWidth(rect.width() / factor);
701 rect.setHeight(rect.height() / factor);
731 rect.setHeight(rect.height() / factor);
702 rect.moveCenter(m_presenter->geometry().center());
732 rect.moveCenter(m_presenter->geometry().center());
703 zoomIn(rect);
733 zoomIn(rect);
704 }
734 }
705
735
706 void QChartPrivate::zoomIn(const QRectF &rect)
736 void QChartPrivate::zoomIn(const QRectF &rect)
707 {
737 {
708 if (!rect.isValid())
738 if (!rect.isValid())
709 return;
739 return;
710
740
711 QRectF r = rect.normalized();
741 QRectF r = rect.normalized();
712 const QRectF geometry = m_presenter->geometry();
742 const QRectF geometry = m_presenter->geometry();
713 r.translate(-geometry.topLeft());
743 r.translate(-geometry.topLeft());
714
744
715 if (!r.isValid())
745 if (!r.isValid())
716 return;
746 return;
717
747
718 QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height());
748 QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height());
719 m_presenter->setState(ChartPresenter::ZoomInState,zoomPoint);
749 m_presenter->setState(ChartPresenter::ZoomInState,zoomPoint);
720 m_dataset->zoomInDomain(r);
750 m_dataset->zoomInDomain(r);
721 m_presenter->setState(ChartPresenter::ShowState,QPointF());
751 m_presenter->setState(ChartPresenter::ShowState,QPointF());
722
752
723 }
753 }
724
754
725 void QChartPrivate::zoomOut(qreal factor)
755 void QChartPrivate::zoomOut(qreal factor)
726 {
756 {
727 const QRectF geometry = m_presenter->geometry();
757 const QRectF geometry = m_presenter->geometry();
728
758
729 QRectF r;
759 QRectF r;
730 r.setSize(geometry.size() / factor);
760 r.setSize(geometry.size() / factor);
731 r.moveCenter(QPointF(geometry.size().width()/2 ,geometry.size().height()/2));
761 r.moveCenter(QPointF(geometry.size().width()/2 ,geometry.size().height()/2));
732 if (!r.isValid())
762 if (!r.isValid())
733 return;
763 return;
734
764
735 QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height());
765 QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height());
736 m_presenter->setState(ChartPresenter::ZoomOutState,zoomPoint);
766 m_presenter->setState(ChartPresenter::ZoomOutState,zoomPoint);
737 m_dataset->zoomOutDomain(r);
767 m_dataset->zoomOutDomain(r);
738 m_presenter->setState(ChartPresenter::ShowState,QPointF());
768 m_presenter->setState(ChartPresenter::ShowState,QPointF());
739 }
769 }
740
770
741 void QChartPrivate::scroll(qreal dx, qreal dy)
771 void QChartPrivate::scroll(qreal dx, qreal dy)
742 {
772 {
743 if (dx < 0) m_presenter->setState(ChartPresenter::ScrollLeftState,QPointF());
773 if (dx < 0) m_presenter->setState(ChartPresenter::ScrollLeftState,QPointF());
744 if (dx > 0) m_presenter->setState(ChartPresenter::ScrollRightState,QPointF());
774 if (dx > 0) m_presenter->setState(ChartPresenter::ScrollRightState,QPointF());
745 if (dy < 0) m_presenter->setState(ChartPresenter::ScrollUpState,QPointF());
775 if (dy < 0) m_presenter->setState(ChartPresenter::ScrollUpState,QPointF());
746 if (dy > 0) m_presenter->setState(ChartPresenter::ScrollDownState,QPointF());
776 if (dy > 0) m_presenter->setState(ChartPresenter::ScrollDownState,QPointF());
747
777
748 m_dataset->scrollDomain(dx, dy);
778 m_dataset->scrollDomain(dx, dy);
749 m_presenter->setState(ChartPresenter::ShowState,QPointF());
779 m_presenter->setState(ChartPresenter::ShowState,QPointF());
750 }
780 }
751
781
752 #include "moc_qchart.cpp"
782 #include "moc_qchart.cpp"
753
783
754 QTCOMMERCIALCHART_END_NAMESPACE
784 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,64 +1,68
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 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef QCHART_P_H
30 #ifndef QCHART_P_H
31 #define QCHART_P_H
31 #define QCHART_P_H
32
32
33 #include "qchartglobal.h"
33 #include "qchartglobal.h"
34 #include "qchart.h"
34 #include "qchart.h"
35
35
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37
37
38 class ChartThemeManager;
38 class ChartThemeManager;
39 class ChartPresenter;
39 class ChartPresenter;
40 class QLegend;
40 class QLegend;
41 class ChartDataSet;
41 class ChartDataSet;
42
42
43 class QChartPrivate
43 class QChartPrivate
44 {
44 {
45
45
46 public:
46 public:
47 QChartPrivate(QChart *q, QChart::ChartType type);
47 QChartPrivate(QChart *q, QChart::ChartType type);
48 ~QChartPrivate();
48 ~QChartPrivate();
49 QChart *q_ptr;
49 QChart *q_ptr;
50 QLegend *m_legend;
50 QLegend *m_legend;
51 ChartDataSet *m_dataset;
51 ChartDataSet *m_dataset;
52 ChartPresenter *m_presenter;
52 ChartPresenter *m_presenter;
53 ChartThemeManager *m_themeManager;
53 ChartThemeManager *m_themeManager;
54 QChart::ChartType m_type;
54 QChart::ChartType m_type;
55
55
56 static QPen &defaultPen();
57 static QBrush &defaultBrush();
58 static QFont &defaultFont();
59
56 void init();
60 void init();
57 void zoomIn(qreal factor);
61 void zoomIn(qreal factor);
58 void zoomOut(qreal factor);
62 void zoomOut(qreal factor);
59 void zoomIn(const QRectF &rect);
63 void zoomIn(const QRectF &rect);
60 void scroll(qreal dx, qreal dy);
64 void scroll(qreal dx, qreal dy);
61 };
65 };
62
66
63 QTCOMMERCIALCHART_END_NAMESPACE
67 QTCOMMERCIALCHART_END_NAMESPACE
64 #endif
68 #endif
@@ -1,301 +1,301
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 "qscatterseries.h"
21 #include "qscatterseries.h"
22 #include "qscatterseries_p.h"
22 #include "qscatterseries_p.h"
23 #include "scatterchartitem_p.h"
23 #include "scatterchartitem_p.h"
24 #include "chartdataset_p.h"
24 #include "chartdataset_p.h"
25 #include "charttheme_p.h"
25 #include "charttheme_p.h"
26 #include "scatteranimation_p.h"
26 #include "scatteranimation_p.h"
27 #include "qchart_p.h"
27
28
28 /*!
29 /*!
29 \class QScatterSeries
30 \class QScatterSeries
30 \brief The QScatterSeries class is used for making scatter charts.
31 \brief The QScatterSeries class is used for making scatter charts.
31
32
32 \mainclass
33 \mainclass
33
34
34 The scatter data is displayed as a collection of points on the chart. Each point determines the position on the horizontal axis
35 The scatter data is displayed as a collection of points on the chart. Each point determines the position on the horizontal axis
35 and the vertical axis.
36 and the vertical axis.
36
37
37 \image examples_scatterchart.png
38 \image examples_scatterchart.png
38
39
39 Creating basic scatter chart is simple:
40 Creating basic scatter chart is simple:
40 \code
41 \code
41 QScatterSeries* series = new QScatterSeries();
42 QScatterSeries* series = new QScatterSeries();
42 series->append(0, 6);
43 series->append(0, 6);
43 series->append(2, 4);
44 series->append(2, 4);
44 ...
45 ...
45 chart->addSeries(series);
46 chart->addSeries(series);
46 \endcode
47 \endcode
47 */
48 */
48 /*!
49 /*!
49 \qmlclass ScatterSeries QScatterSeries
50 \qmlclass ScatterSeries QScatterSeries
50 \inherits XYSeries
51 \inherits XYSeries
51
52
52 The following QML shows how to create a chart with two simple scatter series:
53 The following QML shows how to create a chart with two simple scatter series:
53 \snippet ../demos/qmlchart/qml/qmlchart/View5.qml 1
54 \snippet ../demos/qmlchart/qml/qmlchart/View5.qml 1
54
55
55 \beginfloatleft
56 \beginfloatleft
56 \image demos_qmlchart5.png
57 \image demos_qmlchart5.png
57 \endfloat
58 \endfloat
58 \clearfloat
59 \clearfloat
59 */
60 */
60
61
61 /*!
62 /*!
62 \enum QScatterSeries::MarkerShape
63 \enum QScatterSeries::MarkerShape
63
64
64 This enum describes the shape used when rendering marker items.
65 This enum describes the shape used when rendering marker items.
65
66
66 \value MarkerShapeCircle
67 \value MarkerShapeCircle
67 \value MarkerShapeRectangle
68 \value MarkerShapeRectangle
68 */
69 */
69
70
70 /*!
71 /*!
71 \property QScatterSeries::color
72 \property QScatterSeries::color
72 Fill (brush) color of the series. This is a convenience property for modifying the color of brush.
73 Fill (brush) color of the series. This is a convenience property for modifying the color of brush.
73 \sa QScatterSeries::brush()
74 \sa QScatterSeries::brush()
74 */
75 */
75
76
76 /*!
77 /*!
77 \property QScatterSeries::borderColor
78 \property QScatterSeries::borderColor
78 Line (pen) color of the series. This is a convenience property for modifying the color of pen.
79 Line (pen) color of the series. This is a convenience property for modifying the color of pen.
79 \sa QScatterSeries::pen()
80 \sa QScatterSeries::pen()
80 */
81 */
81 /*!
82 /*!
82 \qmlproperty color ScatterSeries::borderColor
83 \qmlproperty color ScatterSeries::borderColor
83 Border (pen) color of the series.
84 Border (pen) color of the series.
84 */
85 */
85
86
86 /*!
87 /*!
87 \qmlproperty real ScatterSeries::borderWidth
88 \qmlproperty real ScatterSeries::borderWidth
88 The width of the border line. By default the width is 2.0.
89 The width of the border line. By default the width is 2.0.
89 */
90 */
90
91
91 /*!
92 /*!
92 \property QScatterSeries::markerShape
93 \property QScatterSeries::markerShape
93 Defines the shape of the marker used to draw the points in the series. The default shape is MarkerShapeCircle.
94 Defines the shape of the marker used to draw the points in the series. The default shape is MarkerShapeCircle.
94 */
95 */
95 /*!
96 /*!
96 \qmlproperty MarkerShape ScatterSeries::markerShape
97 \qmlproperty MarkerShape ScatterSeries::markerShape
97 Defines the shape of the marker used to draw the points in the series. One of ScatterSeries
98 Defines the shape of the marker used to draw the points in the series. One of ScatterSeries
98 ScatterSeries.MarkerShapeCircle or ScatterSeries.MarkerShapeRectangle.
99 ScatterSeries.MarkerShapeCircle or ScatterSeries.MarkerShapeRectangle.
99 The default shape is ScatterSeries.MarkerShapeCircle.
100 The default shape is ScatterSeries.MarkerShapeCircle.
100 */
101 */
101
102
102 /*!
103 /*!
103 \property QScatterSeries::markerSize
104 \property QScatterSeries::markerSize
104 Defines the size of the marker used to draw the points in the series. The default size is 15.0.
105 Defines the size of the marker used to draw the points in the series. The default size is 15.0.
105 */
106 */
106 /*!
107 /*!
107 \qmlproperty real ScatterSeries::markerSize
108 \qmlproperty real ScatterSeries::markerSize
108 Defines the size of the marker used to draw the points in the series. The default size is 15.0.
109 Defines the size of the marker used to draw the points in the series. The default size is 15.0.
109 */
110 */
110
111
111 /*!
112 /*!
112 \fn void QScatterSeries::colorChanged(QColor color)
113 \fn void QScatterSeries::colorChanged(QColor color)
113 Signal is emitted when the fill (brush) color has changed to \a color.
114 Signal is emitted when the fill (brush) color has changed to \a color.
114 */
115 */
115
116
116 /*!
117 /*!
117 \fn void QScatterSeries::borderColorChanged(QColor color)
118 \fn void QScatterSeries::borderColorChanged(QColor color)
118 Signal is emitted when the line (pen) color has changed to \a color.
119 Signal is emitted when the line (pen) color has changed to \a color.
119 */
120 */
120 /*!
121 /*!
121 \qmlsignal ScatterSeries::borderColorChanged(color color)
122 \qmlsignal ScatterSeries::borderColorChanged(color color)
122 Signal is emitted when the line (pen) color has changed to \a color.
123 Signal is emitted when the line (pen) color has changed to \a color.
123 */
124 */
124
125
125 /*!
126 /*!
126 \fn QChartSeriesType QScatterSeries::type() const
127 \fn QChartSeriesType QScatterSeries::type() const
127 Returns QChartSeries::SeriesTypeScatter.
128 Returns QChartSeries::SeriesTypeScatter.
128 \sa QAbstractSeries, SeriesType
129 \sa QAbstractSeries, SeriesType
129 */
130 */
130
131
131 QTCOMMERCIALCHART_BEGIN_NAMESPACE
132 QTCOMMERCIALCHART_BEGIN_NAMESPACE
132
133
133 /*!
134 /*!
134 Constructs a series object which is a child of \a parent.
135 Constructs a series object which is a child of \a parent.
135 */
136 */
136 QScatterSeries::QScatterSeries(QObject *parent)
137 QScatterSeries::QScatterSeries(QObject *parent)
137 : QXYSeries(*new QScatterSeriesPrivate(this), parent)
138 : QXYSeries(*new QScatterSeriesPrivate(this), parent)
138 {
139 {
139 }
140 }
140
141
141 /*!
142 /*!
142 Destroys the object. Note that adding series to QChart transfers the ownership to the chart.
143 Destroys the object. Note that adding series to QChart transfers the ownership to the chart.
143 */
144 */
144 QScatterSeries::~QScatterSeries()
145 QScatterSeries::~QScatterSeries()
145 {
146 {
146 Q_D(QScatterSeries);
147 Q_D(QScatterSeries);
147 if (d->m_chart)
148 if (d->m_chart)
148 d->m_chart->removeSeries(this);
149 d->m_chart->removeSeries(this);
149 }
150 }
150
151
151 QAbstractSeries::SeriesType QScatterSeries::type() const
152 QAbstractSeries::SeriesType QScatterSeries::type() const
152 {
153 {
153 return QAbstractSeries::SeriesTypeScatter;
154 return QAbstractSeries::SeriesTypeScatter;
154 }
155 }
155
156
156 /*!
157 /*!
157 Sets \a pen used for drawing points' border on the chart. If the pen is not defined, the
158 Sets \a pen used for drawing points' border on the chart. If the pen is not defined, the
158 pen from chart theme is used.
159 pen from chart theme is used.
159 \sa QChart::setTheme()
160 \sa QChart::setTheme()
160 */
161 */
161 void QScatterSeries::setPen(const QPen &pen)
162 void QScatterSeries::setPen(const QPen &pen)
162 {
163 {
163 Q_D(QXYSeries);
164 Q_D(QXYSeries);
164 if (d->m_pen != pen) {
165 if (d->m_pen != pen) {
165 bool emitColorChanged = d->m_pen.color() != pen.color();
166 bool emitColorChanged = d->m_pen.color() != pen.color();
166 d->m_pen = pen;
167 d->m_pen = pen;
167 emit d->updated();
168 emit d->updated();
168 if (emitColorChanged)
169 if (emitColorChanged)
169 emit borderColorChanged(pen.color());
170 emit borderColorChanged(pen.color());
170 }
171 }
171 }
172 }
172
173
173 /*!
174 /*!
174 Sets \a brush used for drawing points on the chart. If the brush is not defined, brush
175 Sets \a brush used for drawing points on the chart. If the brush is not defined, brush
175 from chart theme setting is used.
176 from chart theme setting is used.
176 \sa QChart::setTheme()
177 \sa QChart::setTheme()
177 */
178 */
178 void QScatterSeries::setBrush(const QBrush &brush)
179 void QScatterSeries::setBrush(const QBrush &brush)
179 {
180 {
180 Q_D(QScatterSeries);
181 Q_D(QScatterSeries);
181 if (d->m_brush != brush) {
182 if (d->m_brush != brush) {
182 bool emitColorChanged = d->m_brush.color() != brush.color();
183 bool emitColorChanged = d->m_brush.color() != brush.color();
183 d->m_brush = brush;
184 d->m_brush = brush;
184 emit d->updated();
185 emit d->updated();
185 if (emitColorChanged)
186 if (emitColorChanged)
186 emit colorChanged(brush.color());
187 emit colorChanged(brush.color());
187 }
188 }
188 }
189 }
189
190
190 void QScatterSeries::setColor(const QColor &color)
191 void QScatterSeries::setColor(const QColor &color)
191 {
192 {
192 QBrush b = brush();
193 QBrush b = brush();
193 if (b == QBrush())
194 if (b == QBrush())
194 b.setStyle(Qt::SolidPattern);
195 b.setStyle(Qt::SolidPattern);
195 b.setColor(color);
196 b.setColor(color);
196 setBrush(b);
197 setBrush(b);
197 }
198 }
198
199
199 QColor QScatterSeries::color() const
200 QColor QScatterSeries::color() const
200 {
201 {
201 return brush().color();
202 return brush().color();
202 }
203 }
203
204
204 void QScatterSeries::setBorderColor(const QColor &color)
205 void QScatterSeries::setBorderColor(const QColor &color)
205 {
206 {
206 QPen p = pen();
207 QPen p = pen();
207 if (p.color() != color) {
208 if (p.color() != color) {
208 p.setColor(color);
209 p.setColor(color);
209 setPen(p);
210 setPen(p);
210 }
211 }
211 }
212 }
212
213
213 QColor QScatterSeries::borderColor() const
214 QColor QScatterSeries::borderColor() const
214 {
215 {
215 return pen().color();
216 return pen().color();
216 }
217 }
217
218
218 QScatterSeries::MarkerShape QScatterSeries::markerShape() const
219 QScatterSeries::MarkerShape QScatterSeries::markerShape() const
219 {
220 {
220 Q_D(const QScatterSeries);
221 Q_D(const QScatterSeries);
221 return d->m_shape;
222 return d->m_shape;
222 }
223 }
223
224
224 void QScatterSeries::setMarkerShape(MarkerShape shape)
225 void QScatterSeries::setMarkerShape(MarkerShape shape)
225 {
226 {
226 Q_D(QScatterSeries);
227 Q_D(QScatterSeries);
227 if (d->m_shape != shape) {
228 if (d->m_shape != shape) {
228 d->m_shape = shape;
229 d->m_shape = shape;
229 emit d->updated();
230 emit d->updated();
230 }
231 }
231 }
232 }
232
233
233 qreal QScatterSeries::markerSize() const
234 qreal QScatterSeries::markerSize() const
234 {
235 {
235 Q_D(const QScatterSeries);
236 Q_D(const QScatterSeries);
236 return d->m_size;
237 return d->m_size;
237 }
238 }
238
239
239 void QScatterSeries::setMarkerSize(qreal size)
240 void QScatterSeries::setMarkerSize(qreal size)
240 {
241 {
241 Q_D(QScatterSeries);
242 Q_D(QScatterSeries);
242
243
243 if (!qFuzzyCompare(d->m_size, size)) {
244 if (!qFuzzyCompare(d->m_size, size)) {
244 d->m_size = size;
245 d->m_size = size;
245 emit d->updated();
246 emit d->updated();
246 }
247 }
247 }
248 }
248
249
249 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
250 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
250
251
251 QScatterSeriesPrivate::QScatterSeriesPrivate(QScatterSeries *q)
252 QScatterSeriesPrivate::QScatterSeriesPrivate(QScatterSeries *q)
252 : QXYSeriesPrivate(q),
253 : QXYSeriesPrivate(q),
253 m_shape(QScatterSeries::MarkerShapeCircle),
254 m_shape(QScatterSeries::MarkerShapeCircle),
254 m_size(15.0)
255 m_size(15.0)
255 {
256 {
256 }
257 }
257
258
258 void QScatterSeriesPrivate::initializeGraphics(QGraphicsItem* parent)
259 void QScatterSeriesPrivate::initializeGraphics(QGraphicsItem* parent)
259 {
260 {
260 Q_Q(QScatterSeries);
261 Q_Q(QScatterSeries);
261 ScatterChartItem *scatter = new ScatterChartItem(q,parent);
262 ScatterChartItem *scatter = new ScatterChartItem(q,parent);
262 m_item.reset(scatter);
263 m_item.reset(scatter);
263 QAbstractSeriesPrivate::initializeGraphics(parent);
264 QAbstractSeriesPrivate::initializeGraphics(parent);
264 }
265 }
265
266
266 void QScatterSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced)
267 void QScatterSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced)
267 {
268 {
268 Q_Q(QScatterSeries);
269 Q_Q(QScatterSeries);
269 QPen pen;
270 QBrush brush;
271 const QList<QColor> colors = theme->seriesColors();
270 const QList<QColor> colors = theme->seriesColors();
272 const QList<QGradient> gradients = theme->seriesGradients();
271 const QList<QGradient> gradients = theme->seriesGradients();
273
272
274 if (forced || pen == m_pen) {
273 if (forced || QChartPrivate::defaultPen() == m_pen) {
274 QPen pen;
275 pen.setColor(ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.0));
275 pen.setColor(ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.0));
276 pen.setWidthF(2);
276 pen.setWidthF(2);
277 q->setPen(pen);
277 q->setPen(pen);
278 }
278 }
279
279
280 if (forced || brush == m_brush) {
280 if (forced || QChartPrivate::defaultBrush() == m_brush) {
281 QBrush brush(colors.at(index % colors.size()));
281 QBrush brush(colors.at(index % colors.size()));
282 q->setBrush(brush);
282 q->setBrush(brush);
283 }
283 }
284 }
284 }
285
285
286 void QScatterSeriesPrivate::initializeAnimations(QChart::AnimationOptions options)
286 void QScatterSeriesPrivate::initializeAnimations(QChart::AnimationOptions options)
287 {
287 {
288 ScatterChartItem *item = static_cast<ScatterChartItem *>(m_item.data());
288 ScatterChartItem *item = static_cast<ScatterChartItem *>(m_item.data());
289 Q_ASSERT(item);
289 Q_ASSERT(item);
290
290
291 if (options.testFlag(QChart::SeriesAnimations))
291 if (options.testFlag(QChart::SeriesAnimations))
292 item->setAnimation(new ScatterAnimation(item));
292 item->setAnimation(new ScatterAnimation(item));
293 else
293 else
294 item->setAnimation(0);
294 item->setAnimation(0);
295
295
296 QAbstractSeriesPrivate::initializeAnimations(options);
296 QAbstractSeriesPrivate::initializeAnimations(options);
297 }
297 }
298
298
299 #include "moc_qscatterseries.cpp"
299 #include "moc_qscatterseries.cpp"
300
300
301 QTCOMMERCIALCHART_END_NAMESPACE
301 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,152 +1,153
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 "qsplineseries.h"
21 #include "qsplineseries.h"
22 #include "qsplineseries_p.h"
22 #include "qsplineseries_p.h"
23 #include "splinechartitem_p.h"
23 #include "splinechartitem_p.h"
24 #include "chartdataset_p.h"
24 #include "chartdataset_p.h"
25 #include "charttheme_p.h"
25 #include "charttheme_p.h"
26 #include "splineanimation_p.h"
26 #include "splineanimation_p.h"
27 #include "qchart_p.h"
27
28
28 /*!
29 /*!
29 \class QSplineSeries
30 \class QSplineSeries
30 \brief Series type used to store data needed to draw a spline.
31 \brief Series type used to store data needed to draw a spline.
31
32
32 QSplineSeries stores the data points along with the segment control points needed by QPainterPath to draw spline
33 QSplineSeries stores the data points along with the segment control points needed by QPainterPath to draw spline
33 Control points are automatically calculated when data changes. The algorithm computes the points so that the normal spline can be drawn.
34 Control points are automatically calculated when data changes. The algorithm computes the points so that the normal spline can be drawn.
34
35
35 \image examples_splinechart.png
36 \image examples_splinechart.png
36
37
37 Creating basic spline chart is simple:
38 Creating basic spline chart is simple:
38 \code
39 \code
39 QSplineSeries* series = new QSplineSeries();
40 QSplineSeries* series = new QSplineSeries();
40 series->append(0, 6);
41 series->append(0, 6);
41 series->append(2, 4);
42 series->append(2, 4);
42 ...
43 ...
43 chart->addSeries(series);
44 chart->addSeries(series);
44 \endcode
45 \endcode
45 */
46 */
46
47
47 /*!
48 /*!
48 \qmlclass SplineSeries QSplineSeries
49 \qmlclass SplineSeries QSplineSeries
49 \inherits XYSeries
50 \inherits XYSeries
50
51
51 The following QML shows how to create a simple spline chart:
52 The following QML shows how to create a simple spline chart:
52 \snippet ../demos/qmlchart/qml/qmlchart/View3.qml 1
53 \snippet ../demos/qmlchart/qml/qmlchart/View3.qml 1
53 \beginfloatleft
54 \beginfloatleft
54 \image demos_qmlchart3.png
55 \image demos_qmlchart3.png
55 \endfloat
56 \endfloat
56 \clearfloat
57 \clearfloat
57 */
58 */
58
59
59 /*!
60 /*!
60 \fn QSeriesType QSplineSeries::type() const
61 \fn QSeriesType QSplineSeries::type() const
61 Returns the type of the series
62 Returns the type of the series
62 */
63 */
63
64
64 /*!
65 /*!
65 \qmlproperty real SplineSeries::width
66 \qmlproperty real SplineSeries::width
66 The width of the line. By default the width is 2.0.
67 The width of the line. By default the width is 2.0.
67 */
68 */
68
69
69 /*!
70 /*!
70 \qmlproperty Qt::PenStyle SplineSeries::style
71 \qmlproperty Qt::PenStyle SplineSeries::style
71 Controls the style of the line. Set to one of Qt.NoPen, Qt.SolidLine, Qt.DashLine, Qt.DotLine,
72 Controls the style of the line. Set to one of Qt.NoPen, Qt.SolidLine, Qt.DashLine, Qt.DotLine,
72 Qt.DashDotLine or Qt.DashDotDotLine. Using Qt.CustomDashLine is not supported in the QML API.
73 Qt.DashDotLine or Qt.DashDotDotLine. Using Qt.CustomDashLine is not supported in the QML API.
73 By default the style is Qt.SolidLine.
74 By default the style is Qt.SolidLine.
74 */
75 */
75
76
76 /*!
77 /*!
77 \qmlproperty Qt::PenCapStyle SplineSeries::capStyle
78 \qmlproperty Qt::PenCapStyle SplineSeries::capStyle
78 Controls the cap style of the line. Set to one of Qt.FlatCap, Qt.SquareCap or Qt.RoundCap. By
79 Controls the cap style of the line. Set to one of Qt.FlatCap, Qt.SquareCap or Qt.RoundCap. By
79 default the cap style is Qt.SquareCap.
80 default the cap style is Qt.SquareCap.
80 */
81 */
81
82
82 QTCOMMERCIALCHART_BEGIN_NAMESPACE
83 QTCOMMERCIALCHART_BEGIN_NAMESPACE
83
84
84 /*!
85 /*!
85 Constructs empty series object which is a child of \a parent.
86 Constructs empty series object which is a child of \a parent.
86 When series object is added to a QChart instance then the ownerships is transferred.
87 When series object is added to a QChart instance then the ownerships is transferred.
87 */
88 */
88
89
89 QSplineSeries::QSplineSeries(QObject *parent)
90 QSplineSeries::QSplineSeries(QObject *parent)
90 : QLineSeries(*new QSplineSeriesPrivate(this), parent)
91 : QLineSeries(*new QSplineSeriesPrivate(this), parent)
91 {
92 {
92 }
93 }
93
94
94 /*!
95 /*!
95 Destroys the object.
96 Destroys the object.
96 */
97 */
97 QSplineSeries::~QSplineSeries()
98 QSplineSeries::~QSplineSeries()
98 {
99 {
99 Q_D(QSplineSeries);
100 Q_D(QSplineSeries);
100 if (d->m_chart)
101 if (d->m_chart)
101 d->m_chart->removeSeries(this);
102 d->m_chart->removeSeries(this);
102 }
103 }
103
104
104 QAbstractSeries::SeriesType QSplineSeries::type() const
105 QAbstractSeries::SeriesType QSplineSeries::type() const
105 {
106 {
106 return QAbstractSeries::SeriesTypeSpline;
107 return QAbstractSeries::SeriesTypeSpline;
107 }
108 }
108
109
109 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
110 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
110
111
111 QSplineSeriesPrivate::QSplineSeriesPrivate(QSplineSeries *q)
112 QSplineSeriesPrivate::QSplineSeriesPrivate(QSplineSeries *q)
112 : QLineSeriesPrivate(q)
113 : QLineSeriesPrivate(q)
113 {
114 {
114 }
115 }
115
116
116 void QSplineSeriesPrivate::initializeGraphics(QGraphicsItem* parent)
117 void QSplineSeriesPrivate::initializeGraphics(QGraphicsItem* parent)
117 {
118 {
118 Q_Q(QSplineSeries);
119 Q_Q(QSplineSeries);
119 SplineChartItem *spline = new SplineChartItem(q,parent);
120 SplineChartItem *spline = new SplineChartItem(q,parent);
120 m_item.reset(spline);
121 m_item.reset(spline);
121 QAbstractSeriesPrivate::initializeGraphics(parent);
122 QAbstractSeriesPrivate::initializeGraphics(parent);
122 }
123 }
123
124
124 void QSplineSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced)
125 void QSplineSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced)
125 {
126 {
126 Q_Q(QSplineSeries);
127 Q_Q(QSplineSeries);
127 const QList<QColor> colors = theme->seriesColors();
128 const QList<QColor> colors = theme->seriesColors();
128
129
129 QPen pen;
130 if (forced || QChartPrivate::defaultPen() == m_pen) {
130 if (forced || pen == m_pen) {
131 QPen pen;
131 pen.setColor(colors.at(index % colors.size()));
132 pen.setColor(colors.at(index % colors.size()));
132 pen.setWidthF(2);
133 pen.setWidthF(2);
133 q->setPen(pen);
134 q->setPen(pen);
134 }
135 }
135 }
136 }
136
137
137 void QSplineSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options)
138 void QSplineSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options)
138 {
139 {
139 SplineChartItem *item = static_cast<SplineChartItem *>(m_item.data());
140 SplineChartItem *item = static_cast<SplineChartItem *>(m_item.data());
140 Q_ASSERT(item);
141 Q_ASSERT(item);
141 if (options.testFlag(QChart::SeriesAnimations)) {
142 if (options.testFlag(QChart::SeriesAnimations)) {
142 item->setAnimation(new SplineAnimation(item));
143 item->setAnimation(new SplineAnimation(item));
143 }else{
144 }else{
144 item->setAnimation(0);
145 item->setAnimation(0);
145 }
146 }
146 QAbstractSeriesPrivate::initializeAnimations(options);
147 QAbstractSeriesPrivate::initializeAnimations(options);
147 }
148 }
148
149
149 #include "moc_qsplineseries.cpp"
150 #include "moc_qsplineseries.cpp"
150 #include "moc_qsplineseries_p.cpp"
151 #include "moc_qsplineseries_p.cpp"
151
152
152 QTCOMMERCIALCHART_END_NAMESPACE
153 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,89 +1,91
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 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef CHARTTHEME_H
30 #ifndef CHARTTHEME_H
31 #define CHARTTHEME_H
31 #define CHARTTHEME_H
32
32
33 #include "chartthememanager_p.h"
33 #include "chartthememanager_p.h"
34 #include <QColor>
34 #include <QColor>
35 #include <QGradientStops>
35 #include <QGradientStops>
36
36
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38
38
39 class ChartTheme
39 class ChartTheme
40 {
40 {
41
41
42 public:
42 public:
43 enum BackgroundShadesMode {
43 enum BackgroundShadesMode {
44 BackgroundShadesNone = 0,
44 BackgroundShadesNone = 0,
45 BackgroundShadesVertical,
45 BackgroundShadesVertical,
46 BackgroundShadesHorizontal,
46 BackgroundShadesHorizontal,
47 BackgroundShadesBoth
47 BackgroundShadesBoth
48 };
48 };
49
49
50 protected:
50 protected:
51 explicit ChartTheme(QChart::ChartTheme id = QChart::ChartThemeLight):m_id(id),
51 explicit ChartTheme(QChart::ChartTheme id = QChart::ChartThemeLight):m_id(id),
52 m_backgroundShades(BackgroundShadesNone),
52 m_backgroundShades(BackgroundShadesNone),
53 m_backgroundDropShadowEnabled(false){};
53 m_backgroundShadesBrush(Qt::SolidPattern),
54 m_backgroundDropShadowEnabled(false)
55 {};
54 public:
56 public:
55 QChart::ChartTheme id() const { return m_id; }
57 QChart::ChartTheme id() const { return m_id; }
56 QList<QGradient> seriesGradients() const { return m_seriesGradients; }
58 QList<QGradient> seriesGradients() const { return m_seriesGradients; }
57 QList<QColor> seriesColors() const { return m_seriesColors; }
59 QList<QColor> seriesColors() const { return m_seriesColors; }
58 QLinearGradient chartBackgroundGradient() const { return m_chartBackgroundGradient; }
60 QLinearGradient chartBackgroundGradient() const { return m_chartBackgroundGradient; }
59 QFont masterFont() const { return m_masterFont; }
61 QFont masterFont() const { return m_masterFont; }
60 QFont labelFont() const { return m_labelFont; }
62 QFont labelFont() const { return m_labelFont; }
61 QBrush labelBrush() const { return m_labelBrush; }
63 QBrush labelBrush() const { return m_labelBrush; }
62 QPen axisLinePen() const { return m_axisLinePen; }
64 QPen axisLinePen() const { return m_axisLinePen; }
63 QPen backgroundShadesPen() const { return m_backgroundShadesPen; }
65 QPen backgroundShadesPen() const { return m_backgroundShadesPen; }
64 QBrush backgroundShadesBrush() const { return m_backgroundShadesBrush; }
66 QBrush backgroundShadesBrush() const { return m_backgroundShadesBrush; }
65 BackgroundShadesMode backgroundShades() const { return m_backgroundShades; }
67 BackgroundShadesMode backgroundShades() const { return m_backgroundShades; }
66 bool isBackgroundDropShadowEnabled() const { return m_backgroundDropShadowEnabled; }
68 bool isBackgroundDropShadowEnabled() const { return m_backgroundDropShadowEnabled; }
67 QPen girdLinePen() const { return m_gridLinePen; }
69 QPen girdLinePen() const { return m_gridLinePen; }
68
70
69 protected:
71 protected:
70 QChart::ChartTheme m_id;
72 QChart::ChartTheme m_id;
71 QList<QColor> m_seriesColors;
73 QList<QColor> m_seriesColors;
72 QList<QGradient> m_seriesGradients;
74 QList<QGradient> m_seriesGradients;
73 QLinearGradient m_chartBackgroundGradient;
75 QLinearGradient m_chartBackgroundGradient;
74
76
75 QFont m_masterFont;
77 QFont m_masterFont;
76 QFont m_labelFont;
78 QFont m_labelFont;
77 QBrush m_labelBrush;
79 QBrush m_labelBrush;
78 QPen m_axisLinePen;
80 QPen m_axisLinePen;
79 QPen m_backgroundShadesPen;
81 QPen m_backgroundShadesPen;
80 QBrush m_backgroundShadesBrush;
82 QBrush m_backgroundShadesBrush;
81 BackgroundShadesMode m_backgroundShades;
83 BackgroundShadesMode m_backgroundShades;
82 bool m_backgroundDropShadowEnabled;
84 bool m_backgroundDropShadowEnabled;
83 QPen m_gridLinePen;
85 QPen m_gridLinePen;
84
86
85 };
87 };
86
88
87 QTCOMMERCIALCHART_END_NAMESPACE
89 QTCOMMERCIALCHART_END_NAMESPACE
88
90
89 #endif // CHARTTHEME_H
91 #endif // CHARTTHEME_H
@@ -1,587 +1,590
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
29
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
31
31 /*!
32 /*!
32 \class QXYSeries
33 \class QXYSeries
33 \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.
34 */
35 */
35 /*!
36 /*!
36 \qmlclass XYSeries
37 \qmlclass XYSeries
37 \inherits AbstractSeries
38 \inherits AbstractSeries
38 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.
39
40
40 The class cannot be instantiated directly.
41 The class cannot be instantiated directly.
41 */
42 */
42
43
43 /*!
44 /*!
44 \qmlproperty AbstractAxis XYSeries::axisX
45 \qmlproperty AbstractAxis XYSeries::axisX
45 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
46 the series.
47 the series.
47 \sa axisXTop
48 \sa axisXTop
48 */
49 */
49
50
50 /*!
51 /*!
51 \qmlproperty AbstractAxis XYSeries::axisY
52 \qmlproperty AbstractAxis XYSeries::axisY
52 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
53 the series.
54 the series.
54 \sa axisYRight
55 \sa axisYRight
55 */
56 */
56
57
57 /*!
58 /*!
58 \qmlproperty AbstractAxis XYSeries::axisXTop
59 \qmlproperty AbstractAxis XYSeries::axisXTop
59 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
60 axisXTop, but not both.
61 axisXTop, but not both.
61 \sa axisX
62 \sa axisX
62 */
63 */
63
64
64 /*!
65 /*!
65 \qmlproperty AbstractAxis XYSeries::axisYRight
66 \qmlproperty AbstractAxis XYSeries::axisYRight
66 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
67 or axisYRight, but not both.
68 or axisYRight, but not both.
68 \sa axisY
69 \sa axisY
69 */
70 */
70
71
71 /*!
72 /*!
72 \qmlproperty AbstractAxis XYSeries::axisAngular
73 \qmlproperty AbstractAxis XYSeries::axisAngular
73 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.
74 \sa axisX
75 \sa axisX
75 */
76 */
76
77
77 /*!
78 /*!
78 \qmlproperty AbstractAxis XYSeries::axisRadial
79 \qmlproperty AbstractAxis XYSeries::axisRadial
79 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.
80 \sa axisY
81 \sa axisY
81 */
82 */
82
83
83 /*!
84 /*!
84 \property QXYSeries::pointsVisible
85 \property QXYSeries::pointsVisible
85 Controls if the data points are visible and should be drawn.
86 Controls if the data points are visible and should be drawn.
86 */
87 */
87 /*!
88 /*!
88 \qmlproperty bool XYSeries::pointsVisible
89 \qmlproperty bool XYSeries::pointsVisible
89 Controls if the data points are visible and should be drawn.
90 Controls if the data points are visible and should be drawn.
90 */
91 */
91
92
92 /*!
93 /*!
93 \fn QPen QXYSeries::pen() const
94 \fn QPen QXYSeries::pen() const
94 \brief Returns pen used to draw points for series.
95 \brief Returns pen used to draw points for series.
95 \sa setPen()
96 \sa setPen()
96 */
97 */
97
98
98 /*!
99 /*!
99 \fn QBrush QXYSeries::brush() const
100 \fn QBrush QXYSeries::brush() const
100 \brief Returns brush used to draw points for series.
101 \brief Returns brush used to draw points for series.
101 \sa setBrush()
102 \sa setBrush()
102 */
103 */
103
104
104 /*!
105 /*!
105 \property QXYSeries::color
106 \property QXYSeries::color
106 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
107 fill (brush) color in case of QScatterSeries or QAreaSeries.
108 fill (brush) color in case of QScatterSeries or QAreaSeries.
108 \sa QXYSeries::pen(), QXYSeries::brush()
109 \sa QXYSeries::pen(), QXYSeries::brush()
109 */
110 */
110 /*!
111 /*!
111 \qmlproperty color XYSeries::color
112 \qmlproperty color XYSeries::color
112 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
113 fill (brush) color in case of ScatterSeries or AreaSeries.
114 fill (brush) color in case of ScatterSeries or AreaSeries.
114 */
115 */
115
116
116 /*!
117 /*!
117 \fn void QXYSeries::clicked(const QPointF& point)
118 \fn void QXYSeries::clicked(const QPointF& point)
118 \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.
119 */
120 */
120 /*!
121 /*!
121 \qmlsignal XYSeries::onClicked(QPointF point)
122 \qmlsignal XYSeries::onClicked(QPointF point)
122 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:
123 \code
124 \code
124 LineSeries {
125 LineSeries {
125 XYPoint { x: 0; y: 0 }
126 XYPoint { x: 0; y: 0 }
126 XYPoint { x: 1.1; y: 2.1 }
127 XYPoint { x: 1.1; y: 2.1 }
127 onClicked: console.log("onClicked: " + point.x + ", " + point.y);
128 onClicked: console.log("onClicked: " + point.x + ", " + point.y);
128 }
129 }
129 \endcode
130 \endcode
130 */
131 */
131
132
132 /*!
133 /*!
133 \fn void QXYSeries::hovered(const QPointF &point, bool state)
134 \fn void QXYSeries::hovered(const QPointF &point, bool state)
134 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)
135 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
136 the series.
137 the series.
137 */
138 */
138 /*!
139 /*!
139 \qmlsignal XYSeries::onHovered(point point, bool state)
140 \qmlsignal XYSeries::onHovered(point point, bool state)
140 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)
141 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
142 the series.
143 the series.
143 */
144 */
144
145
145 /*!
146 /*!
146 \fn void QXYSeries::pointReplaced(int index)
147 \fn void QXYSeries::pointReplaced(int index)
147 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.
148 \sa replace()
149 \sa replace()
149 */
150 */
150 /*!
151 /*!
151 \qmlsignal XYSeries::onPointReplaced(int index)
152 \qmlsignal XYSeries::onPointReplaced(int index)
152 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.
153 */
154 */
154
155
155 /*!
156 /*!
156 \fn void QXYSeries::pointsReplaced()
157 \fn void QXYSeries::pointsReplaced()
157 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.
158 \sa replace()
159 \sa replace()
159 */
160 */
160 /*!
161 /*!
161 \qmlsignal XYSeries::onPointsReplaced()
162 \qmlsignal XYSeries::onPointsReplaced()
162 */
163 */
163
164
164 /*!
165 /*!
165 \fn void QXYSeries::pointAdded(int index)
166 \fn void QXYSeries::pointAdded(int index)
166 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.
167 \sa append(), insert()
168 \sa append(), insert()
168 */
169 */
169 /*!
170 /*!
170 \qmlsignal XYSeries::onPointAdded(int index)
171 \qmlsignal XYSeries::onPointAdded(int index)
171 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.
172 */
173 */
173
174
174 /*!
175 /*!
175 \fn void QXYSeries::pointRemoved(int index)
176 \fn void QXYSeries::pointRemoved(int index)
176 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.
177 \sa remove()
178 \sa remove()
178 */
179 */
179 /*!
180 /*!
180 \qmlsignal XYSeries::onPointRemoved(int index)
181 \qmlsignal XYSeries::onPointRemoved(int index)
181 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.
182 */
183 */
183
184
184 /*!
185 /*!
185 \fn void QXYSeries::colorChanged(QColor color)
186 \fn void QXYSeries::colorChanged(QColor color)
186 \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.
187 */
188 */
188 /*!
189 /*!
189 \qmlsignal XYSeries::onColorChanged(color color)
190 \qmlsignal XYSeries::onColorChanged(color color)
190 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.
191 */
192 */
192
193
193 /*!
194 /*!
194 \fn void QXYSeriesPrivate::updated()
195 \fn void QXYSeriesPrivate::updated()
195 \brief \internal
196 \brief \internal
196 */
197 */
197
198
198 /*!
199 /*!
199 \qmlmethod XYSeries::append(real x, real y)
200 \qmlmethod XYSeries::append(real x, real y)
200 Append point (\a x, \a y) to the series
201 Append point (\a x, \a y) to the series
201 */
202 */
202
203
203 /*!
204 /*!
204 \qmlmethod XYSeries::replace(real oldX, real oldY, real newX, real newY)
205 \qmlmethod XYSeries::replace(real oldX, real oldY, real newX, real newY)
205 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
206 exist.
207 exist.
207 */
208 */
208
209
209 /*!
210 /*!
210 \qmlmethod XYSeries::remove(real x, real y)
211 \qmlmethod XYSeries::remove(real x, real y)
211 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.
212 */
213 */
213
214
214 /*!
215 /*!
215 \qmlmethod XYSeries::insert(int index, real x, real y)
216 \qmlmethod XYSeries::insert(int index, real x, real y)
216 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
217 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.
218 */
219 */
219
220
220 /*!
221 /*!
221 \qmlmethod QPointF XYSeries::at(int index)
222 \qmlmethod QPointF XYSeries::at(int index)
222 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.
223 */
224 */
224
225
225 /*!
226 /*!
226 \internal
227 \internal
227
228
228 Constructs empty series object which is a child of \a parent.
229 Constructs empty series object which is a child of \a parent.
229 When series object is added to QChart instance ownerships is transferred.
230 When series object is added to QChart instance ownerships is transferred.
230 */
231 */
231 QXYSeries::QXYSeries(QXYSeriesPrivate &d, QObject *parent)
232 QXYSeries::QXYSeries(QXYSeriesPrivate &d, QObject *parent)
232 : QAbstractSeries(d, parent)
233 : QAbstractSeries(d, parent)
233 {
234 {
234 }
235 }
235
236
236 /*!
237 /*!
237 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,
238 and are destroyed when QChart instances are destroyed.
239 and are destroyed when QChart instances are destroyed.
239 */
240 */
240 QXYSeries::~QXYSeries()
241 QXYSeries::~QXYSeries()
241 {
242 {
242 }
243 }
243
244
244 /*!
245 /*!
245 Adds data point (\a x, \a y) to the series.
246 Adds data point (\a x, \a y) to the series.
246 */
247 */
247 void QXYSeries::append(qreal x, qreal y)
248 void QXYSeries::append(qreal x, qreal y)
248 {
249 {
249 append(QPointF(x, y));
250 append(QPointF(x, y));
250 }
251 }
251
252
252 /*!
253 /*!
253 This is an overloaded function.
254 This is an overloaded function.
254 Adds data \a point to the series.
255 Adds data \a point to the series.
255 */
256 */
256 void QXYSeries::append(const QPointF &point)
257 void QXYSeries::append(const QPointF &point)
257 {
258 {
258 Q_D(QXYSeries);
259 Q_D(QXYSeries);
259
260
260 if (isValidValue(point)) {
261 if (isValidValue(point)) {
261 d->m_points << point;
262 d->m_points << point;
262 emit pointAdded(d->m_points.count() - 1);
263 emit pointAdded(d->m_points.count() - 1);
263 }
264 }
264 }
265 }
265
266
266 /*!
267 /*!
267 This is an overloaded function.
268 This is an overloaded function.
268 Adds list of data \a points to the series.
269 Adds list of data \a points to the series.
269 */
270 */
270 void QXYSeries::append(const QList<QPointF> &points)
271 void QXYSeries::append(const QList<QPointF> &points)
271 {
272 {
272 foreach (const QPointF &point , points)
273 foreach (const QPointF &point , points)
273 append(point);
274 append(point);
274 }
275 }
275
276
276 /*!
277 /*!
277 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).
278 \sa QXYSeries::pointReplaced()
279 \sa QXYSeries::pointReplaced()
279 */
280 */
280 void QXYSeries::replace(qreal oldX, qreal oldY, qreal newX, qreal newY)
281 void QXYSeries::replace(qreal oldX, qreal oldY, qreal newX, qreal newY)
281 {
282 {
282 replace(QPointF(oldX, oldY), QPointF(newX, newY));
283 replace(QPointF(oldX, oldY), QPointF(newX, newY));
283 }
284 }
284
285
285 /*!
286 /*!
286 Replaces \a oldPoint with \a newPoint.
287 Replaces \a oldPoint with \a newPoint.
287 \sa QXYSeries::pointReplaced()
288 \sa QXYSeries::pointReplaced()
288 */
289 */
289 void QXYSeries::replace(const QPointF &oldPoint, const QPointF &newPoint)
290 void QXYSeries::replace(const QPointF &oldPoint, const QPointF &newPoint)
290 {
291 {
291 Q_D(QXYSeries);
292 Q_D(QXYSeries);
292 int index = d->m_points.indexOf(oldPoint);
293 int index = d->m_points.indexOf(oldPoint);
293 if (index == -1)
294 if (index == -1)
294 return;
295 return;
295 replace(index, newPoint);
296 replace(index, newPoint);
296 }
297 }
297
298
298 /*!
299 /*!
299 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).
300 \sa QXYSeries::pointReplaced()
301 \sa QXYSeries::pointReplaced()
301 */
302 */
302 void QXYSeries::replace(int index, qreal newX, qreal newY)
303 void QXYSeries::replace(int index, qreal newX, qreal newY)
303 {
304 {
304 replace(index, QPointF(newX, newY));
305 replace(index, QPointF(newX, newY));
305 }
306 }
306
307
307 /*!
308 /*!
308 Replaces the point at \a index with \a newPoint.
309 Replaces the point at \a index with \a newPoint.
309 \sa QXYSeries::pointReplaced()
310 \sa QXYSeries::pointReplaced()
310 */
311 */
311 void QXYSeries::replace(int index, const QPointF &newPoint)
312 void QXYSeries::replace(int index, const QPointF &newPoint)
312 {
313 {
313 Q_D(QXYSeries);
314 Q_D(QXYSeries);
314 if (isValidValue(newPoint)) {
315 if (isValidValue(newPoint)) {
315 d->m_points[index] = newPoint;
316 d->m_points[index] = newPoint;
316 emit pointReplaced(index);
317 emit pointReplaced(index);
317 }
318 }
318 }
319 }
319
320
320 /*!
321 /*!
321 Replaces the current points with \a points.
322 Replaces the current points with \a points.
322 \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,
323 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()
324 when the points have been replaced.
325 when the points have been replaced.
325 \sa QXYSeries::pointsReplaced()
326 \sa QXYSeries::pointsReplaced()
326 */
327 */
327 void QXYSeries::replace(QList<QPointF> points)
328 void QXYSeries::replace(QList<QPointF> points)
328 {
329 {
329 Q_D(QXYSeries);
330 Q_D(QXYSeries);
330 d->m_points = points.toVector();
331 d->m_points = points.toVector();
331 emit pointsReplaced();
332 emit pointsReplaced();
332 }
333 }
333
334
334 /*!
335 /*!
335 Removes the point (\a x, \a y) from the series.
336 Removes the point (\a x, \a y) from the series.
336 */
337 */
337 void QXYSeries::remove(qreal x, qreal y)
338 void QXYSeries::remove(qreal x, qreal y)
338 {
339 {
339 remove(QPointF(x, y));
340 remove(QPointF(x, y));
340 }
341 }
341
342
342 /*!
343 /*!
343 Removes the \a point from the series.
344 Removes the \a point from the series.
344 */
345 */
345 void QXYSeries::remove(const QPointF &point)
346 void QXYSeries::remove(const QPointF &point)
346 {
347 {
347 Q_D(QXYSeries);
348 Q_D(QXYSeries);
348 int index = d->m_points.indexOf(point);
349 int index = d->m_points.indexOf(point);
349 if (index == -1)
350 if (index == -1)
350 return;
351 return;
351 remove(index);
352 remove(index);
352 }
353 }
353
354
354 /*!
355 /*!
355 Removes the point at \a index from the series.
356 Removes the point at \a index from the series.
356 */
357 */
357 void QXYSeries::remove(int index)
358 void QXYSeries::remove(int index)
358 {
359 {
359 Q_D(QXYSeries);
360 Q_D(QXYSeries);
360 d->m_points.remove(index);
361 d->m_points.remove(index);
361 emit pointRemoved(index);
362 emit pointRemoved(index);
362 }
363 }
363
364
364 /*!
365 /*!
365 Inserts a \a point in the series at \a index position.
366 Inserts a \a point in the series at \a index position.
366 */
367 */
367 void QXYSeries::insert(int index, const QPointF &point)
368 void QXYSeries::insert(int index, const QPointF &point)
368 {
369 {
369 Q_D(QXYSeries);
370 Q_D(QXYSeries);
370 if (isValidValue(point)) {
371 if (isValidValue(point)) {
371 d->m_points.insert(index, point);
372 d->m_points.insert(index, point);
372 emit pointAdded(index);
373 emit pointAdded(index);
373 }
374 }
374 }
375 }
375
376
376 /*!
377 /*!
377 Removes all points from the series.
378 Removes all points from the series.
378 */
379 */
379 void QXYSeries::clear()
380 void QXYSeries::clear()
380 {
381 {
381 Q_D(QXYSeries);
382 Q_D(QXYSeries);
382 for (int i = d->m_points.size() - 1; i >= 0; i--)
383 for (int i = d->m_points.size() - 1; i >= 0; i--)
383 remove(d->m_points.at(i));
384 remove(d->m_points.at(i));
384 }
385 }
385
386
386 /*!
387 /*!
387 Returns list of points in the series.
388 Returns list of points in the series.
388 */
389 */
389 QList<QPointF> QXYSeries::points() const
390 QList<QPointF> QXYSeries::points() const
390 {
391 {
391 Q_D(const QXYSeries);
392 Q_D(const QXYSeries);
392 return d->m_points.toList();
393 return d->m_points.toList();
393 }
394 }
394
395
395 /*!
396 /*!
396 Returns point at \a index in internal points vector.
397 Returns point at \a index in internal points vector.
397 */
398 */
398 const QPointF &QXYSeries::at(int index) const
399 const QPointF &QXYSeries::at(int index) const
399 {
400 {
400 Q_D(const QXYSeries);
401 Q_D(const QXYSeries);
401 return d->m_points.at(index);
402 return d->m_points.at(index);
402 }
403 }
403
404
404 /*!
405 /*!
405 Returns number of data points within series.
406 Returns number of data points within series.
406 */
407 */
407 int QXYSeries::count() const
408 int QXYSeries::count() const
408 {
409 {
409 Q_D(const QXYSeries);
410 Q_D(const QXYSeries);
410 return d->m_points.count();
411 return d->m_points.count();
411 }
412 }
412
413
413
414
414 /*!
415 /*!
415 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
416 pen from chart theme is used.
417 pen from chart theme is used.
417 \sa QChart::setTheme()
418 \sa QChart::setTheme()
418 */
419 */
419 void QXYSeries::setPen(const QPen &pen)
420 void QXYSeries::setPen(const QPen &pen)
420 {
421 {
421 Q_D(QXYSeries);
422 Q_D(QXYSeries);
422 if (d->m_pen != pen) {
423 if (d->m_pen != pen) {
423 bool emitColorChanged = d->m_pen.color() != pen.color();
424 bool emitColorChanged = d->m_pen.color() != pen.color();
424 d->m_pen = pen;
425 d->m_pen = pen;
425 emit d->updated();
426 emit d->updated();
426 if (emitColorChanged)
427 if (emitColorChanged)
427 emit colorChanged(pen.color());
428 emit colorChanged(pen.color());
428 }
429 }
429 }
430 }
430
431
431 QPen QXYSeries::pen() const
432 QPen QXYSeries::pen() const
432 {
433 {
433 Q_D(const QXYSeries);
434 Q_D(const QXYSeries);
434 return d->m_pen;
435 return d->m_pen;
435 }
436 }
436
437
437 /*!
438 /*!
438 Sets \a brush used for drawing points on the chart. If the brush is not defined, brush
439 Sets \a brush used for drawing points on the chart. If the brush is not defined, brush
439 from chart theme setting is used.
440 from chart theme setting is used.
440 \sa QChart::setTheme()
441 \sa QChart::setTheme()
441 */
442 */
442 void QXYSeries::setBrush(const QBrush &brush)
443 void QXYSeries::setBrush(const QBrush &brush)
443 {
444 {
444 Q_D(QXYSeries);
445 Q_D(QXYSeries);
445 if (d->m_brush != brush) {
446 if (d->m_brush != brush) {
446 d->m_brush = brush;
447 d->m_brush = brush;
447 emit d->updated();
448 emit d->updated();
448 }
449 }
449 }
450 }
450
451
451 QBrush QXYSeries::brush() const
452 QBrush QXYSeries::brush() const
452 {
453 {
453 Q_D(const QXYSeries);
454 Q_D(const QXYSeries);
454 return d->m_brush;
455 return d->m_brush;
455 }
456 }
456
457
457 void QXYSeries::setColor(const QColor &color)
458 void QXYSeries::setColor(const QColor &color)
458 {
459 {
459 QPen p = pen();
460 QPen p = pen();
460 if (p.color() != color) {
461 if (p.color() != color) {
461 p.setColor(color);
462 p.setColor(color);
462 setPen(p);
463 setPen(p);
463 }
464 }
464 }
465 }
465
466
466 QColor QXYSeries::color() const
467 QColor QXYSeries::color() const
467 {
468 {
468 return pen().color();
469 return pen().color();
469 }
470 }
470
471
471 void QXYSeries::setPointsVisible(bool visible)
472 void QXYSeries::setPointsVisible(bool visible)
472 {
473 {
473 Q_D(QXYSeries);
474 Q_D(QXYSeries);
474 if (d->m_pointsVisible != visible) {
475 if (d->m_pointsVisible != visible) {
475 d->m_pointsVisible = visible;
476 d->m_pointsVisible = visible;
476 emit d->updated();
477 emit d->updated();
477 }
478 }
478 }
479 }
479
480
480 bool QXYSeries::pointsVisible() const
481 bool QXYSeries::pointsVisible() const
481 {
482 {
482 Q_D(const QXYSeries);
483 Q_D(const QXYSeries);
483 return d->m_pointsVisible;
484 return d->m_pointsVisible;
484 }
485 }
485
486
486
487
487 /*!
488 /*!
488 Stream operator for adding a data \a point to the series.
489 Stream operator for adding a data \a point to the series.
489 \sa append()
490 \sa append()
490 */
491 */
491 QXYSeries &QXYSeries::operator<< (const QPointF &point)
492 QXYSeries &QXYSeries::operator<< (const QPointF &point)
492 {
493 {
493 append(point);
494 append(point);
494 return *this;
495 return *this;
495 }
496 }
496
497
497
498
498 /*!
499 /*!
499 Stream operator for adding a list of \a points to the series.
500 Stream operator for adding a list of \a points to the series.
500 \sa append()
501 \sa append()
501 */
502 */
502
503
503 QXYSeries &QXYSeries::operator<< (const QList<QPointF>& points)
504 QXYSeries &QXYSeries::operator<< (const QList<QPointF>& points)
504 {
505 {
505 append(points);
506 append(points);
506 return *this;
507 return *this;
507 }
508 }
508
509
509 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
510 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
510
511
511
512
512 QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q)
513 QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q)
513 : QAbstractSeriesPrivate(q),
514 : QAbstractSeriesPrivate(q),
515 m_pen(QChartPrivate::defaultPen()),
516 m_brush(QChartPrivate::defaultBrush()),
514 m_pointsVisible(false)
517 m_pointsVisible(false)
515 {
518 {
516 }
519 }
517
520
518 void QXYSeriesPrivate::initializeDomain()
521 void QXYSeriesPrivate::initializeDomain()
519 {
522 {
520 qreal minX(0);
523 qreal minX(0);
521 qreal minY(0);
524 qreal minY(0);
522 qreal maxX(1);
525 qreal maxX(1);
523 qreal maxY(1);
526 qreal maxY(1);
524
527
525 Q_Q(QXYSeries);
528 Q_Q(QXYSeries);
526
529
527 const QList<QPointF>& points = q->points();
530 const QList<QPointF>& points = q->points();
528
531
529 if (!points.isEmpty()) {
532 if (!points.isEmpty()) {
530 minX = points[0].x();
533 minX = points[0].x();
531 minY = points[0].y();
534 minY = points[0].y();
532 maxX = minX;
535 maxX = minX;
533 maxY = minY;
536 maxY = minY;
534
537
535 for (int i = 0; i < points.count(); i++) {
538 for (int i = 0; i < points.count(); i++) {
536 qreal x = points[i].x();
539 qreal x = points[i].x();
537 qreal y = points[i].y();
540 qreal y = points[i].y();
538 minX = qMin(minX, x);
541 minX = qMin(minX, x);
539 minY = qMin(minY, y);
542 minY = qMin(minY, y);
540 maxX = qMax(maxX, x);
543 maxX = qMax(maxX, x);
541 maxY = qMax(maxY, y);
544 maxY = qMax(maxY, y);
542 }
545 }
543 }
546 }
544
547
545 domain()->setRange(minX, maxX, minY, maxY);
548 domain()->setRange(minX, maxX, minY, maxY);
546 }
549 }
547
550
548 QList<QLegendMarker*> QXYSeriesPrivate::createLegendMarkers(QLegend* legend)
551 QList<QLegendMarker*> QXYSeriesPrivate::createLegendMarkers(QLegend* legend)
549 {
552 {
550 Q_Q(QXYSeries);
553 Q_Q(QXYSeries);
551 QList<QLegendMarker*> list;
554 QList<QLegendMarker*> list;
552 return list << new QXYLegendMarker(q,legend);
555 return list << new QXYLegendMarker(q,legend);
553 }
556 }
554
557
555 void QXYSeriesPrivate::initializeAxes()
558 void QXYSeriesPrivate::initializeAxes()
556 {
559 {
557
560
558 }
561 }
559
562
560 QAbstractAxis::AxisType QXYSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
563 QAbstractAxis::AxisType QXYSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
561 {
564 {
562 Q_UNUSED(orientation);
565 Q_UNUSED(orientation);
563 return QAbstractAxis::AxisTypeValue;
566 return QAbstractAxis::AxisTypeValue;
564 }
567 }
565
568
566 QAbstractAxis* QXYSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const
569 QAbstractAxis* QXYSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const
567 {
570 {
568 Q_UNUSED(orientation);
571 Q_UNUSED(orientation);
569 return 0;
572 return 0;
570 }
573 }
571
574
572 void QXYSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options)
575 void QXYSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options)
573 {
576 {
574 XYChart *item = static_cast<XYChart *>(m_item.data());
577 XYChart *item = static_cast<XYChart *>(m_item.data());
575 Q_ASSERT(item);
578 Q_ASSERT(item);
576 if (options.testFlag(QChart::SeriesAnimations)) {
579 if (options.testFlag(QChart::SeriesAnimations)) {
577 item->setAnimation(new XYAnimation(item));
580 item->setAnimation(new XYAnimation(item));
578 }else{
581 }else{
579 item->setAnimation(0);
582 item->setAnimation(0);
580 }
583 }
581 QAbstractSeriesPrivate::initializeAnimations(options);
584 QAbstractSeriesPrivate::initializeAnimations(options);
582 }
585 }
583
586
584 #include "moc_qxyseries.cpp"
587 #include "moc_qxyseries.cpp"
585 #include "moc_qxyseries_p.cpp"
588 #include "moc_qxyseries_p.cpp"
586
589
587 QTCOMMERCIALCHART_END_NAMESPACE
590 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now