##// END OF EJS Templates
Refactors core to support mulitpile axis and domains...
Michal Klocek -
r1556:10e43766cad7
parent child
Show More
@@ -1,398 +1,396
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qareaseries.h"
21 #include "qareaseries.h"
22 #include "qareaseries_p.h"
22 #include "qareaseries_p.h"
23 #include "qlineseries.h"
23 #include "qlineseries.h"
24 #include "areachartitem_p.h"
24 #include "areachartitem_p.h"
25 #include "legendmarker_p.h"
25 #include "legendmarker_p.h"
26 #include "domain_p.h"
26 #include "domain_p.h"
27 #include "chartdataset_p.h"
27 #include "chartdataset_p.h"
28 #include "charttheme_p.h"
28 #include "charttheme_p.h"
29 #include "chartanimator_p.h"
29 #include "chartanimator_p.h"
30 #include "qvaluesaxis.h"
30 #include "qvaluesaxis.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 counstucted wihtout a\ lowerSeries this is null.
72 QAreaSeries was counstucted wihtout 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 counstucted wihtout a\ lowerSeries this is null.
77 AreaSeries was counstucted wihtout 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 \fn QPen QAreaSeries::pen() const
101 \fn QPen QAreaSeries::pen() const
102 \brief Returns the pen used to draw line for this series.
102 \brief Returns the pen used to draw line for this series.
103 \sa setPen()
103 \sa setPen()
104 */
104 */
105
105
106 /*!
106 /*!
107 \fn QPen QAreaSeries::brush() const
107 \fn QPen QAreaSeries::brush() const
108 \brief Returns the brush used to draw line for this series.
108 \brief Returns the brush used to draw line for this series.
109 \sa setBrush()
109 \sa setBrush()
110 */
110 */
111
111
112 /*!
112 /*!
113 \fn void QAreaSeries::colorChanged(QColor color)
113 \fn void QAreaSeries::colorChanged(QColor color)
114 \brief Signal is emitted when the fill (brush) color has changed to \a color.
114 \brief Signal is emitted when the fill (brush) color has changed to \a color.
115 */
115 */
116 /*!
116 /*!
117 \qmlsignal AreaSeries::onColorChanged(color color)
117 \qmlsignal AreaSeries::onColorChanged(color color)
118 Signal is emitted when the fill (brush) color has changed to \a color.
118 Signal is emitted when the fill (brush) color has changed to \a color.
119 */
119 */
120
120
121 /*!
121 /*!
122 \fn void QAreaSeries::borderColorChanged(QColor color)
122 \fn void QAreaSeries::borderColorChanged(QColor color)
123 \brief Signal is emitted when the line (pen) color has changed to \a color.
123 \brief Signal is emitted when the line (pen) color has changed to \a color.
124 */
124 */
125 /*!
125 /*!
126 \qmlsignal AreaSeries::onBorderColorChanged(color color)
126 \qmlsignal AreaSeries::onBorderColorChanged(color color)
127 Signal is emitted when the line (pen) color has changed to \a color.
127 Signal is emitted when the line (pen) color has changed to \a color.
128 */
128 */
129
129
130 /*!
130 /*!
131 \fn void QAreaSeries::clicked(const QPointF& point)
131 \fn void QAreaSeries::clicked(const QPointF& point)
132 \brief Signal is emitted when user clicks the \a point on area chart.
132 \brief Signal is emitted when user clicks the \a point on area chart.
133 */
133 */
134 /*!
134 /*!
135 \qmlsignal AreaSeries::onClicked(QPointF point)
135 \qmlsignal AreaSeries::onClicked(QPointF point)
136 Signal is emitted when user clicks the \a point on area chart.
136 Signal is emitted when user clicks the \a point on area chart.
137 */
137 */
138
138
139 /*!
139 /*!
140 \fn void QAreaSeries::selected()
140 \fn void QAreaSeries::selected()
141 The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be
141 The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be
142 implemented by the user of QAreaSeries API.
142 implemented by the user of QAreaSeries API.
143 */
143 */
144 /*!
144 /*!
145 \qmlsignal AreaSeries::onSelected()
145 \qmlsignal AreaSeries::onSelected()
146 The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be
146 The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be
147 implemented by the user of AreaSeries API.
147 implemented by the user of AreaSeries API.
148 */
148 */
149
149
150 /*!
150 /*!
151 \fn void QAreaSeriesPrivate::updated()
151 \fn void QAreaSeriesPrivate::updated()
152 \brief \internal
152 \brief \internal
153 */
153 */
154
154
155 /*!
155 /*!
156 Constructs area series object which is a child of \a upperSeries. Area will be spanned between \a
156 Constructs area series object which is a child of \a upperSeries. Area will be spanned between \a
157 upperSeries line and \a lowerSeries line. If no \a lowerSeries is passed to constructor, area is specified by axis x (y=0) instead.
157 upperSeries line and \a lowerSeries line. If no \a lowerSeries is passed to constructor, area is specified by axis x (y=0) instead.
158 When series object is added to QChartView or QChart instance ownerships is transferred.
158 When series object is added to QChartView or QChart instance ownerships is transferred.
159 */
159 */
160 QAreaSeries::QAreaSeries(QLineSeries *upperSeries, QLineSeries *lowerSeries)
160 QAreaSeries::QAreaSeries(QLineSeries *upperSeries, QLineSeries *lowerSeries)
161 : QAbstractSeries(*new QAreaSeriesPrivate(upperSeries,lowerSeries,this),upperSeries)
161 : QAbstractSeries(*new QAreaSeriesPrivate(upperSeries,lowerSeries,this),upperSeries)
162 {
162 {
163 }
163 }
164
164
165 /*!
165 /*!
166 Constructs area series object without upper or lower series with \a parent object.
166 Constructs area series object without upper or lower series with \a parent object.
167 */
167 */
168 QAreaSeries::QAreaSeries(QObject *parent)
168 QAreaSeries::QAreaSeries(QObject *parent)
169 : QAbstractSeries(*new QAreaSeriesPrivate(0, 0, this), parent)
169 : QAbstractSeries(*new QAreaSeriesPrivate(0, 0, this), parent)
170 {
170 {
171 }
171 }
172
172
173 /*!
173 /*!
174 Destroys the object.
174 Destroys the object.
175 */
175 */
176 QAreaSeries::~QAreaSeries()
176 QAreaSeries::~QAreaSeries()
177 {
177 {
178 }
178 }
179
179
180 /*!
180 /*!
181 Returns QChartSeries::SeriesTypeArea.
181 Returns QChartSeries::SeriesTypeArea.
182 */
182 */
183 QAbstractSeries::SeriesType QAreaSeries::type() const
183 QAbstractSeries::SeriesType QAreaSeries::type() const
184 {
184 {
185 return QAbstractSeries::SeriesTypeArea;
185 return QAbstractSeries::SeriesTypeArea;
186 }
186 }
187
187
188 /*!
188 /*!
189 Sets the \a series that is to be used as the area chart upper series.
189 Sets the \a series that is to be used as the area chart upper series.
190 */
190 */
191 void QAreaSeries::setUpperSeries(QLineSeries* series)
191 void QAreaSeries::setUpperSeries(QLineSeries* series)
192 {
192 {
193 Q_D(QAreaSeries);
193 Q_D(QAreaSeries);
194 d->m_upperSeries = series;
194 d->m_upperSeries = series;
195 }
195 }
196
196
197 QLineSeries* QAreaSeries::upperSeries() const
197 QLineSeries* QAreaSeries::upperSeries() const
198 {
198 {
199 Q_D(const QAreaSeries);
199 Q_D(const QAreaSeries);
200 return d->m_upperSeries;
200 return d->m_upperSeries;
201 }
201 }
202
202
203 /*!
203 /*!
204 Sets the \a series that is to be used as the area chart lower series.
204 Sets the \a series that is to be used as the area chart lower series.
205 */
205 */
206 void QAreaSeries::setLowerSeries(QLineSeries* series)
206 void QAreaSeries::setLowerSeries(QLineSeries* series)
207 {
207 {
208 Q_D(QAreaSeries);
208 Q_D(QAreaSeries);
209 d->m_lowerSeries = series;
209 d->m_lowerSeries = series;
210 }
210 }
211
211
212 QLineSeries* QAreaSeries::lowerSeries() const
212 QLineSeries* QAreaSeries::lowerSeries() const
213 {
213 {
214 Q_D(const QAreaSeries);
214 Q_D(const QAreaSeries);
215 return d->m_lowerSeries;
215 return d->m_lowerSeries;
216 }
216 }
217
217
218 /*!
218 /*!
219 Sets \a pen used for drawing area outline.
219 Sets \a pen used for drawing area outline.
220 */
220 */
221 void QAreaSeries::setPen(const QPen &pen)
221 void QAreaSeries::setPen(const QPen &pen)
222 {
222 {
223 Q_D(QAreaSeries);
223 Q_D(QAreaSeries);
224 if (d->m_pen != pen) {
224 if (d->m_pen != pen) {
225 d->m_pen = pen;
225 d->m_pen = pen;
226 emit d->updated();
226 emit d->updated();
227 }
227 }
228 }
228 }
229
229
230 QPen QAreaSeries::pen() const
230 QPen QAreaSeries::pen() const
231 {
231 {
232 Q_D(const QAreaSeries);
232 Q_D(const QAreaSeries);
233 return d->m_pen;
233 return d->m_pen;
234 }
234 }
235
235
236 /*!
236 /*!
237 Sets \a brush used for filling the area.
237 Sets \a brush used for filling the area.
238 */
238 */
239 void QAreaSeries::setBrush(const QBrush &brush)
239 void QAreaSeries::setBrush(const QBrush &brush)
240 {
240 {
241 Q_D(QAreaSeries);
241 Q_D(QAreaSeries);
242 if (d->m_brush != brush) {
242 if (d->m_brush != brush) {
243 d->m_brush = brush;
243 d->m_brush = brush;
244 emit d->updated();
244 emit d->updated();
245 }
245 }
246 }
246 }
247
247
248 QBrush QAreaSeries::brush() const
248 QBrush QAreaSeries::brush() const
249 {
249 {
250 Q_D(const QAreaSeries);
250 Q_D(const QAreaSeries);
251 return d->m_brush;
251 return d->m_brush;
252 }
252 }
253
253
254 void QAreaSeries::setColor(const QColor &color)
254 void QAreaSeries::setColor(const QColor &color)
255 {
255 {
256 QBrush b = brush();
256 QBrush b = brush();
257 if (b.color() != color) {
257 if (b.color() != color) {
258 b.setColor(color);
258 b.setColor(color);
259 setBrush(b);
259 setBrush(b);
260 emit colorChanged(color);
260 emit colorChanged(color);
261 }
261 }
262 }
262 }
263
263
264 QColor QAreaSeries::color() const
264 QColor QAreaSeries::color() const
265 {
265 {
266 return brush().color();
266 return brush().color();
267 }
267 }
268
268
269 void QAreaSeries::setBorderColor(const QColor &color)
269 void QAreaSeries::setBorderColor(const QColor &color)
270 {
270 {
271 QPen p = pen();
271 QPen p = pen();
272 if (p.color() != color) {
272 if (p.color() != color) {
273 p.setColor(color);
273 p.setColor(color);
274 setPen(p);
274 setPen(p);
275 emit borderColorChanged(color);
275 emit borderColorChanged(color);
276 }
276 }
277 }
277 }
278
278
279 QColor QAreaSeries::borderColor() const
279 QColor QAreaSeries::borderColor() const
280 {
280 {
281 return pen().color();
281 return pen().color();
282 }
282 }
283
283
284 /*!
284 /*!
285 Sets if data points are \a visible and should be drawn on line.
285 Sets if data points are \a visible and should be drawn on line.
286 */
286 */
287 void QAreaSeries::setPointsVisible(bool visible)
287 void QAreaSeries::setPointsVisible(bool visible)
288 {
288 {
289 Q_D(QAreaSeries);
289 Q_D(QAreaSeries);
290 if (d->m_pointsVisible != visible) {
290 if (d->m_pointsVisible != visible) {
291 d->m_pointsVisible = visible;
291 d->m_pointsVisible = visible;
292 emit d->updated();
292 emit d->updated();
293 }
293 }
294 }
294 }
295
295
296 /*!
296 /*!
297 Returns if the points are drawn for this series.
297 Returns if the points are drawn for this series.
298 \sa setPointsVisible()
298 \sa setPointsVisible()
299 */
299 */
300 bool QAreaSeries::pointsVisible() const
300 bool QAreaSeries::pointsVisible() const
301 {
301 {
302 Q_D(const QAreaSeries);
302 Q_D(const QAreaSeries);
303 return d->m_pointsVisible;
303 return d->m_pointsVisible;
304 }
304 }
305
305
306 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
306 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
307
307
308 QAreaSeriesPrivate::QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries,QAreaSeries* q) :
308 QAreaSeriesPrivate::QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries,QAreaSeries* q) :
309 QAbstractSeriesPrivate(q),
309 QAbstractSeriesPrivate(q),
310 m_upperSeries(upperSeries),
310 m_upperSeries(upperSeries),
311 m_lowerSeries(lowerSeries),
311 m_lowerSeries(lowerSeries),
312 m_pointsVisible(false)
312 m_pointsVisible(false)
313 {
313 {
314 }
314 }
315
315
316 void QAreaSeriesPrivate::scaleDomain(Domain& domain)
316 void QAreaSeriesPrivate::scaleDomain(Domain& domain)
317 {
317 {
318 Q_Q(QAreaSeries);
318 Q_Q(QAreaSeries);
319
319
320 qreal minX(domain.minX());
320 qreal minX(domain.minX());
321 qreal minY(domain.minY());
321 qreal minY(domain.minY());
322 qreal maxX(domain.maxX());
322 qreal maxX(domain.maxX());
323 qreal maxY(domain.maxY());
323 qreal maxY(domain.maxY());
324 int tickXCount(domain.tickXCount());
324 int tickXCount(domain.tickXCount());
325 int tickYCount(domain.tickYCount());
325 int tickYCount(domain.tickYCount());
326
326
327 QLineSeries* upperSeries = q->upperSeries();
327 QLineSeries* upperSeries = q->upperSeries();
328 QLineSeries* lowerSeries = q->lowerSeries();
328 QLineSeries* lowerSeries = q->lowerSeries();
329
329
330 const QList<QPointF>& points = upperSeries->points();
330 const QList<QPointF>& points = upperSeries->points();
331
331
332 for (int i = 0; i < points.count(); i++)
332 for (int i = 0; i < points.count(); i++)
333 {
333 {
334 qreal x = points[i].x();
334 qreal x = points[i].x();
335 qreal y = points[i].y();
335 qreal y = points[i].y();
336 minX = qMin(minX, x);
336 minX = qMin(minX, x);
337 minY = qMin(minY, y);
337 minY = qMin(minY, y);
338 maxX = qMax(maxX, x);
338 maxX = qMax(maxX, x);
339 maxY = qMax(maxY, y);
339 maxY = qMax(maxY, y);
340 }
340 }
341 if(lowerSeries) {
341 if(lowerSeries) {
342
342
343 const QList<QPointF>& points = lowerSeries->points();
343 const QList<QPointF>& points = lowerSeries->points();
344
344
345 for (int i = 0; i < points.count(); i++)
345 for (int i = 0; i < points.count(); i++)
346 {
346 {
347 qreal x = points[i].x();
347 qreal x = points[i].x();
348 qreal y = points[i].y();
348 qreal y = points[i].y();
349 minX = qMin(minX, x);
349 minX = qMin(minX, x);
350 minY = qMin(minY, y);
350 minY = qMin(minY, y);
351 maxX = qMax(maxX, x);
351 maxX = qMax(maxX, x);
352 maxY = qMax(maxY, y);
352 maxY = qMax(maxY, y);
353 }}
353 }}
354
354
355 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
355 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
356 }
356 }
357
357
358 Chart* QAreaSeriesPrivate::createGraphics(ChartPresenter* presenter)
358 Chart* QAreaSeriesPrivate::createGraphics(ChartPresenter* presenter)
359 {
359 {
360 Q_Q(QAreaSeries);
360 Q_Q(QAreaSeries);
361
361
362 AreaChartItem* area = new AreaChartItem(q,presenter);
362 AreaChartItem* area = new AreaChartItem(q,presenter);
363 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
363 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
364 area->upperLineItem()->setAnimator(presenter->animator());
364 area->upperLineItem()->setAnimator(presenter->animator());
365 area->upperLineItem()->setAnimation(new XYAnimation(area->upperLineItem()));
365 area->upperLineItem()->setAnimation(new XYAnimation(area->upperLineItem()));
366 if(q->lowerSeries()) {
366 if(q->lowerSeries()) {
367 area->lowerLineItem()->setAnimator(presenter->animator());
367 area->lowerLineItem()->setAnimator(presenter->animator());
368 area->lowerLineItem()->setAnimation(new XYAnimation(area->lowerLineItem()));
368 area->lowerLineItem()->setAnimation(new XYAnimation(area->lowerLineItem()));
369 }
369 }
370 }
370 }
371 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
371 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
372 return area;
372 return area;
373 }
373 }
374
374
375 QList<LegendMarker*> QAreaSeriesPrivate::createLegendMarker(QLegend* legend)
375 QList<LegendMarker*> QAreaSeriesPrivate::createLegendMarker(QLegend* legend)
376 {
376 {
377 Q_Q(QAreaSeries);
377 Q_Q(QAreaSeries);
378 QList<LegendMarker*> list;
378 QList<LegendMarker*> list;
379 return list << new AreaLegendMarker(q,legend);
379 return list << new AreaLegendMarker(q,legend);
380 }
380 }
381
381
382
382
383 QAbstractAxis* QAreaSeriesPrivate::createAxisX()
383 QAbstractAxis* QAreaSeriesPrivate::createAxisX(QObject* parent)
384 {
384 {
385 // TODO: parent?
385 return new QValuesAxis(parent);
386 return new QValuesAxis(this);
387 }
386 }
388
387
389 QAbstractAxis* QAreaSeriesPrivate::createAxisY()
388 QAbstractAxis* QAreaSeriesPrivate::createAxisY(QObject* parent)
390 {
389 {
391 // TODO: parent?
390 return new QValuesAxis(parent);
392 return new QValuesAxis(this);
393 }
391 }
394
392
395 #include "moc_qareaseries.cpp"
393 #include "moc_qareaseries.cpp"
396 #include "moc_qareaseries_p.cpp"
394 #include "moc_qareaseries_p.cpp"
397
395
398 QTCOMMERCIALCHART_END_NAMESPACE
396 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,67 +1,67
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef QAREASERIES_P_H
30 #ifndef QAREASERIES_P_H
31 #define QAREASERIES_P_H
31 #define QAREASERIES_P_H
32
32
33 #include "qabstractseries_p.h"
33 #include "qabstractseries_p.h"
34
34
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36
36
37 class QAreaSeries;
37 class QAreaSeries;
38
38
39 class QAreaSeriesPrivate: public QAbstractSeriesPrivate
39 class QAreaSeriesPrivate: public QAbstractSeriesPrivate
40 {
40 {
41 Q_OBJECT
41 Q_OBJECT
42
42
43 public:
43 public:
44 QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries,QAreaSeries* q);
44 QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries,QAreaSeries* q);
45
45
46 void scaleDomain(Domain& domain);
46 void scaleDomain(Domain& domain);
47 Chart* createGraphics(ChartPresenter* presenter);
47 Chart* createGraphics(ChartPresenter* presenter);
48 QList<LegendMarker*> createLegendMarker(QLegend* legend);
48 QList<LegendMarker*> createLegendMarker(QLegend* legend);
49 QAbstractAxis* createAxisX();
49 QAbstractAxis* createAxisX(QObject* parent = 0);
50 QAbstractAxis* createAxisY();
50 QAbstractAxis* createAxisY(QObject* parent = 0);
51
51
52 Q_SIGNALS:
52 Q_SIGNALS:
53 void updated();
53 void updated();
54
54
55 protected:
55 protected:
56 QBrush m_brush;
56 QBrush m_brush;
57 QPen m_pen;
57 QPen m_pen;
58 QLineSeries* m_upperSeries;
58 QLineSeries* m_upperSeries;
59 QLineSeries* m_lowerSeries;
59 QLineSeries* m_lowerSeries;
60 bool m_pointsVisible;
60 bool m_pointsVisible;
61 private:
61 private:
62 Q_DECLARE_PUBLIC(QAreaSeries);
62 Q_DECLARE_PUBLIC(QAreaSeries);
63 };
63 };
64
64
65 QTCOMMERCIALCHART_END_NAMESPACE
65 QTCOMMERCIALCHART_END_NAMESPACE
66
66
67 #endif
67 #endif
@@ -1,129 +1,130
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef QABSTRACTAXIS_H
21 #ifndef QABSTRACTAXIS_H
22 #define QABSTRACTAXIS_H
22 #define QABSTRACTAXIS_H
23
23
24 #include <qchartglobal.h>
24 #include <qchartglobal.h>
25 #include <QPen>
25 #include <QPen>
26 #include <QFont>
26 #include <QFont>
27 #include <QVariant>
27 #include <QVariant>
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
30
31 class QAbstractAxisPrivate;
31 class QAbstractAxisPrivate;
32
32
33 class QTCOMMERCIALCHART_EXPORT QAbstractAxis : public QObject
33 class QTCOMMERCIALCHART_EXPORT QAbstractAxis : public QObject
34 {
34 {
35 Q_OBJECT
35 Q_OBJECT
36
36
37 Q_PROPERTY(bool visible READ isAxisVisible WRITE setAxisVisible NOTIFY visibleChanged)
37 Q_PROPERTY(bool visible READ isAxisVisible WRITE setAxisVisible NOTIFY visibleChanged)
38 Q_PROPERTY(QColor color READ axisPenColor WRITE setAxisPenColor NOTIFY colorChanged)
38 Q_PROPERTY(QColor color READ axisPenColor WRITE setAxisPenColor NOTIFY colorChanged)
39 Q_PROPERTY(bool labelsVisible READ labelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged)
39 Q_PROPERTY(bool labelsVisible READ labelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged)
40 Q_PROPERTY(int labelsAngle READ labelsAngle WRITE setLabelsAngle)
40 Q_PROPERTY(int labelsAngle READ labelsAngle WRITE setLabelsAngle)
41 Q_PROPERTY(QFont labelsFont READ labelsFont WRITE setLabelsFont)
41 Q_PROPERTY(QFont labelsFont READ labelsFont WRITE setLabelsFont)
42 Q_PROPERTY(QColor labelsColor READ labelsColor WRITE setLabelsColor NOTIFY labelsColorChanged)
42 Q_PROPERTY(QColor labelsColor READ labelsColor WRITE setLabelsColor NOTIFY labelsColorChanged)
43 Q_PROPERTY(bool gridVisible READ isGridLineVisible WRITE setGridLineVisible NOTIFY gridVisibleChanged)
43 Q_PROPERTY(bool gridVisible READ isGridLineVisible WRITE setGridLineVisible NOTIFY gridVisibleChanged)
44 Q_PROPERTY(bool shadesVisible READ shadesVisible WRITE setShadesVisible NOTIFY shadesVisibleChanged)
44 Q_PROPERTY(bool shadesVisible READ shadesVisible WRITE setShadesVisible NOTIFY shadesVisibleChanged)
45 Q_PROPERTY(QColor shadesColor READ shadesColor WRITE setShadesColor NOTIFY shadesColorChanged)
45 Q_PROPERTY(QColor shadesColor READ shadesColor WRITE setShadesColor NOTIFY shadesColorChanged)
46 Q_PROPERTY(QColor shadesBorderColor READ shadesBorderColor WRITE setShadesBorderColor NOTIFY shadesBorderColorChanged)
46 Q_PROPERTY(QColor shadesBorderColor READ shadesBorderColor WRITE setShadesBorderColor NOTIFY shadesBorderColorChanged)
47
47
48 public:
48 public:
49
49
50 enum AxisType {
50 enum AxisType {
51 AxisTypeValues,
51 AxisTypeValues,
52 AxisTypeCategories
52 AxisTypeCategories
53 };
53 };
54
54
55 protected:
55 protected:
56 explicit QAbstractAxis(QAbstractAxisPrivate &d,QObject *parent = 0);
56 explicit QAbstractAxis(QAbstractAxisPrivate &d,QObject *parent = 0);
57
57
58 public:
58 public:
59 ~QAbstractAxis();
59 ~QAbstractAxis();
60
60
61 virtual AxisType type() const = 0;
61 virtual AxisType type() const = 0;
62
62
63 //axis handling
63 //axis handling
64 bool isAxisVisible() const;
64 bool isAxisVisible() const;
65 void setAxisVisible(bool visible = true);
65 void setAxisVisible(bool visible = true);
66 void setAxisPen(const QPen &pen);
66 void setAxisPen(const QPen &pen);
67 QPen axisPen() const;
67 QPen axisPen() const;
68 void setAxisPenColor(QColor color);
68 void setAxisPenColor(QColor color);
69 QColor axisPenColor() const;
69 QColor axisPenColor() const;
70
70
71 //grid handling
71 //grid handling
72 bool isGridLineVisible() const;
72 bool isGridLineVisible() const;
73 void setGridLineVisible(bool visible = true);
73 void setGridLineVisible(bool visible = true);
74 void setGridLinePen(const QPen &pen);
74 void setGridLinePen(const QPen &pen);
75 QPen gridLinePen() const;
75 QPen gridLinePen() const;
76
76
77 //labels handling
77 //labels handling
78 bool labelsVisible() const;
78 bool labelsVisible() const;
79 void setLabelsVisible(bool visible = true);
79 void setLabelsVisible(bool visible = true);
80 void setLabelsPen(const QPen &pen);
80 void setLabelsPen(const QPen &pen);
81 QPen labelsPen() const;
81 QPen labelsPen() const;
82 void setLabelsBrush(const QBrush &brush);
82 void setLabelsBrush(const QBrush &brush);
83 QBrush labelsBrush() const;
83 QBrush labelsBrush() const;
84 void setLabelsFont(const QFont &font);
84 void setLabelsFont(const QFont &font);
85 QFont labelsFont() const;
85 QFont labelsFont() const;
86 void setLabelsAngle(int angle);
86 void setLabelsAngle(int angle);
87 int labelsAngle() const;
87 int labelsAngle() const;
88 void setLabelsColor(QColor color);
88 void setLabelsColor(QColor color);
89 QColor labelsColor() const;
89 QColor labelsColor() const;
90
90
91 //shades handling
91 //shades handling
92 bool shadesVisible() const;
92 bool shadesVisible() const;
93 void setShadesVisible(bool visible = true);
93 void setShadesVisible(bool visible = true);
94 void setShadesPen(const QPen &pen);
94 void setShadesPen(const QPen &pen);
95 QPen shadesPen() const;
95 QPen shadesPen() const;
96 void setShadesBrush(const QBrush &brush);
96 void setShadesBrush(const QBrush &brush);
97 QBrush shadesBrush() const;
97 QBrush shadesBrush() const;
98 void setShadesColor(QColor color);
98 void setShadesColor(QColor color);
99 QColor shadesColor() const;
99 QColor shadesColor() const;
100 void setShadesBorderColor(QColor color);
100 void setShadesBorderColor(QColor color);
101 QColor shadesBorderColor() const;
101 QColor shadesBorderColor() const;
102
102
103 //range handling
103 //range handling
104 void setMin(const QVariant& min);
104 void setMin(const QVariant& min);
105 void setMax(const QVariant& max);
105 void setMax(const QVariant& max);
106 void setRange(const QVariant& min, const QVariant& max);
106 void setRange(const QVariant& min, const QVariant& max);
107
107
108 void show();
108 void show();
109 void hide();
109 void hide();
110
110
111 Q_SIGNALS:
111 Q_SIGNALS:
112 void visibleChanged(bool visible);
112 void visibleChanged(bool visible);
113 void labelsVisibleChanged(bool visible);
113 void labelsVisibleChanged(bool visible);
114 void gridVisibleChanged(bool visible);
114 void gridVisibleChanged(bool visible);
115 void colorChanged(QColor color);
115 void colorChanged(QColor color);
116 void labelsColorChanged(QColor color);
116 void labelsColorChanged(QColor color);
117 void shadesVisibleChanged(bool visible);
117 void shadesVisibleChanged(bool visible);
118 void shadesColorChanged(QColor color);
118 void shadesColorChanged(QColor color);
119 void shadesBorderColorChanged(QColor color);
119 void shadesBorderColorChanged(QColor color);
120
120
121 protected:
121 protected:
122 QScopedPointer<QAbstractAxisPrivate> d_ptr;
122 QScopedPointer<QAbstractAxisPrivate> d_ptr;
123 Q_DISABLE_COPY(QAbstractAxis);
123 Q_DISABLE_COPY(QAbstractAxis);
124 friend class ChartDataSet;
124 friend class ChartDataSet;
125 friend class ChartAxis;
125 friend class ChartAxis;
126 friend class ChartPresenter;
126 };
127 };
127
128
128 QTCOMMERCIALCHART_END_NAMESPACE
129 QTCOMMERCIALCHART_END_NAMESPACE
129 #endif
130 #endif
@@ -1,81 +1,87
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef 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
34
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36
36
37 class ChartPresenter;
38 class ChartAxis;
39
37 class QAbstractAxisPrivate : public QObject
40 class QAbstractAxisPrivate : public QObject
38 {
41 {
39 Q_OBJECT
42 Q_OBJECT
40 public:
43 public:
41 QAbstractAxisPrivate(QAbstractAxis *q);
44 QAbstractAxisPrivate(QAbstractAxis *q);
42 ~QAbstractAxisPrivate();
45 ~QAbstractAxisPrivate();
43
46
44 Q_SIGNALS:
47 Q_SIGNALS:
45 void updated();
48 void updated();
46
49
50 public:
51 virtual ChartAxis* createGraphics(ChartPresenter* presenter) = 0;
52
47 protected:
53 protected:
48 virtual void setMin(const QVariant& min) = 0;
54 virtual void setMin(const QVariant& min) = 0;
49 virtual void setMax(const QVariant& max) = 0;
55 virtual void setMax(const QVariant& max) = 0;
50 virtual void setRange(const QVariant& min, const QVariant& max) = 0;
56 virtual void setRange(const QVariant& min, const QVariant& max) = 0;
51 virtual int ticksCount() const = 0;
57 virtual int ticksCount() const = 0;
52
58
53 protected:
59 public:
54 QAbstractAxis *q_ptr;
60 QAbstractAxis *q_ptr;
55
61
56 bool m_axisVisible;
62 bool m_axisVisible;
57 QPen m_axisPen;
63 QPen m_axisPen;
58 QBrush m_axisBrush;
64 QBrush m_axisBrush;
59
65
60 bool m_gridLineVisible;
66 bool m_gridLineVisible;
61 QPen m_gridLinePen;
67 QPen m_gridLinePen;
62
68
63 bool m_labelsVisible;
69 bool m_labelsVisible;
64 QPen m_labelsPen;
70 QPen m_labelsPen;
65 QBrush m_labelsBrush;
71 QBrush m_labelsBrush;
66 QFont m_labelsFont;
72 QFont m_labelsFont;
67 int m_labelsAngle;
73 int m_labelsAngle;
68
74
69 bool m_shadesVisible;
75 bool m_shadesVisible;
70 QPen m_shadesPen;
76 QPen m_shadesPen;
71 QBrush m_shadesBrush;
77 QBrush m_shadesBrush;
72 qreal m_shadesOpacity;
78 qreal m_shadesOpacity;
73
79
74 Qt::Orientation m_orientation;
80 Qt::Orientation m_orientation;
75
81
76 friend class QAbstractAxis;
82 friend class QAbstractAxis;
77 };
83 };
78
84
79 QTCOMMERCIALCHART_END_NAMESPACE
85 QTCOMMERCIALCHART_END_NAMESPACE
80
86
81 #endif
87 #endif
@@ -1,209 +1,222
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qcategoriesaxis.h"
21 #include "qcategoriesaxis.h"
22 #include "qcategoriesaxis_p.h"
22 #include "qcategoriesaxis_p.h"
23 #include "chartaxisx_p.h"
24 #include "chartaxisy_p.h"
23
25
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25
27
26 QCategoriesAxis::QCategoriesAxis(QObject *parent):
28 QCategoriesAxis::QCategoriesAxis(QObject *parent):
27 QAbstractAxis(*new QCategoriesAxisPrivate(this),parent)
29 QAbstractAxis(*new QCategoriesAxisPrivate(this),parent)
28 {
30 {
29
31
30 }
32 }
31
33
32 QCategoriesAxis::~QCategoriesAxis()
34 QCategoriesAxis::~QCategoriesAxis()
33 {
35 {
34
36
35 }
37 }
36
38
37 QCategoriesAxis::QCategoriesAxis(QCategoriesAxisPrivate &d,QObject *parent):QAbstractAxis(d,parent)
39 QCategoriesAxis::QCategoriesAxis(QCategoriesAxisPrivate &d,QObject *parent):QAbstractAxis(d,parent)
38 {
40 {
39
41
40 }
42 }
41
43
42 /*!
44 /*!
43 Appends \a categories to axis
45 Appends \a categories to axis
44 */
46 */
45 void QCategoriesAxis::append(const QStringList &categories)
47 void QCategoriesAxis::append(const QStringList &categories)
46 {
48 {
47 Q_D(QCategoriesAxis);
49 Q_D(QCategoriesAxis);
48 d->m_categories.append(categories);
50 d->m_categories.append(categories);
49 emit categoriesChanged();
51 emit categoriesChanged();
50 }
52 }
51
53
52 /*!
54 /*!
53 Appends \a category to axis
55 Appends \a category to axis
54 */
56 */
55 void QCategoriesAxis::append(const QString &category)
57 void QCategoriesAxis::append(const QString &category)
56 {
58 {
57 Q_D(QCategoriesAxis);
59 Q_D(QCategoriesAxis);
58 d->m_categories.append(category);
60 d->m_categories.append(category);
59 emit categoriesChanged();
61 emit categoriesChanged();
60 }
62 }
61
63
62 /*!
64 /*!
63 Removes \a category from axis
65 Removes \a category from axis
64 */
66 */
65 void QCategoriesAxis::remove(const QString &category)
67 void QCategoriesAxis::remove(const QString &category)
66 {
68 {
67 Q_D(QCategoriesAxis);
69 Q_D(QCategoriesAxis);
68 if (d->m_categories.contains(category)) {
70 if (d->m_categories.contains(category)) {
69 d->m_categories.removeAt(d->m_categories.indexOf(category));
71 d->m_categories.removeAt(d->m_categories.indexOf(category));
70 emit categoriesChanged();
72 emit categoriesChanged();
71 }
73 }
72 }
74 }
73
75
74 /*!
76 /*!
75 Inserts \a category to axis at \a index
77 Inserts \a category to axis at \a index
76 */
78 */
77 void QCategoriesAxis::insert(int index, const QString &category)
79 void QCategoriesAxis::insert(int index, const QString &category)
78 {
80 {
79 Q_D(QCategoriesAxis);
81 Q_D(QCategoriesAxis);
80 d->m_categories.insert(index,category);
82 d->m_categories.insert(index,category);
81 emit categoriesChanged();
83 emit categoriesChanged();
82 }
84 }
83
85
84 /*!
86 /*!
85 Removes all categories.
87 Removes all categories.
86 */
88 */
87 void QCategoriesAxis::clear()
89 void QCategoriesAxis::clear()
88 {
90 {
89 Q_D(QCategoriesAxis);
91 Q_D(QCategoriesAxis);
90 d->m_categories.clear();
92 d->m_categories.clear();
91 emit categoriesChanged();
93 emit categoriesChanged();
92 }
94 }
93
95
94 void QCategoriesAxis::setCategories(const QStringList &categories)
96 void QCategoriesAxis::setCategories(const QStringList &categories)
95 {
97 {
96 Q_D(QCategoriesAxis);
98 Q_D(QCategoriesAxis);
97 d->m_categories = categories;
99 d->m_categories = categories;
98 emit categoriesChanged();
100 emit categoriesChanged();
99 }
101 }
100
102
101 QStringList QCategoriesAxis::categories()
103 QStringList QCategoriesAxis::categories()
102 {
104 {
103 Q_D(QCategoriesAxis);
105 Q_D(QCategoriesAxis);
104 return d->m_categories;
106 return d->m_categories;
105 }
107 }
106
108
107 /*!
109 /*!
108 Returns number of categories.
110 Returns number of categories.
109 */
111 */
110 int QCategoriesAxis::count() const
112 int QCategoriesAxis::count() const
111 {
113 {
112 Q_D(const QCategoriesAxis);
114 Q_D(const QCategoriesAxis);
113 return d->m_categories.count();
115 return d->m_categories.count();
114 }
116 }
115
117
116 /*!
118 /*!
117 Returns category at \a index. Index must be valid.
119 Returns category at \a index. Index must be valid.
118 */
120 */
119 QString QCategoriesAxis::at(int index) const
121 QString QCategoriesAxis::at(int index) const
120 {
122 {
121 Q_D(const QCategoriesAxis);
123 Q_D(const QCategoriesAxis);
122 return d->m_categories.at(index);
124 return d->m_categories.at(index);
123 }
125 }
124
126
125 /*!
127 /*!
126 Sets minimum category to \a minCategory.
128 Sets minimum category to \a minCategory.
127 */
129 */
128 void QCategoriesAxis::setMin(const QString& minCategory)
130 void QCategoriesAxis::setMin(const QString& minCategory)
129 {
131 {
130 Q_D(QCategoriesAxis);
132 Q_D(QCategoriesAxis);
131 int minIndex = d->m_categories.indexOf(minCategory);
133 int minIndex = d->m_categories.indexOf(minCategory);
132 if (minIndex == -1)
134 if (minIndex == -1)
133 return;
135 return;
134 // else
136 // else
135 // QAbstractAxis::setMin(minIndex);
137 // QAbstractAxis::setMin(minIndex);
136 }
138 }
137
139
138 /*!
140 /*!
139 Sets maximum category to \a maxCategory.
141 Sets maximum category to \a maxCategory.
140 */
142 */
141 void QCategoriesAxis::setMax(const QString& maxCategory)
143 void QCategoriesAxis::setMax(const QString& maxCategory)
142 {
144 {
143 Q_D(QCategoriesAxis);
145 Q_D(QCategoriesAxis);
144 int maxIndex = d->m_categories.indexOf(maxCategory);
146 int maxIndex = d->m_categories.indexOf(maxCategory);
145 if (maxIndex == -1)
147 if (maxIndex == -1)
146 return;
148 return;
147 // else
149 // else
148 // QAbstractAxis::setMax(maxIndex);
150 // QAbstractAxis::setMax(maxIndex);
149 }
151 }
150
152
151 /*!
153 /*!
152 Sets range from \a minCategory to \a maxCategory
154 Sets range from \a minCategory to \a maxCategory
153 */
155 */
154 void QCategoriesAxis::setRange(const QString& minCategory, const QString& maxCategory)
156 void QCategoriesAxis::setRange(const QString& minCategory, const QString& maxCategory)
155 {
157 {
156 // TODO: what if maxCategory < minCategory?
158 // TODO: what if maxCategory < minCategory?
157 setMin(minCategory);
159 setMin(minCategory);
158 setMax(maxCategory);
160 setMax(maxCategory);
159 }
161 }
160
162
161 /*!
163 /*!
162 Returns the type of axis.
164 Returns the type of axis.
163 */
165 */
164 QAbstractAxis::AxisType QCategoriesAxis::type() const
166 QAbstractAxis::AxisType QCategoriesAxis::type() const
165 {
167 {
166 return AxisTypeCategories;
168 return AxisTypeCategories;
167 }
169 }
168
170
169 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
171 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
170
172
171 QCategoriesAxisPrivate::QCategoriesAxisPrivate(QCategoriesAxis* q):
173 QCategoriesAxisPrivate::QCategoriesAxisPrivate(QCategoriesAxis* q):
172 QAbstractAxisPrivate(q)
174 QAbstractAxisPrivate(q)
173 {
175 {
174
176
175 }
177 }
176
178
177 QCategoriesAxisPrivate::~QCategoriesAxisPrivate()
179 QCategoriesAxisPrivate::~QCategoriesAxisPrivate()
178 {
180 {
179
181
180 }
182 }
181
183
182
184
183 void QCategoriesAxisPrivate::setMin(const QVariant& min)
185 void QCategoriesAxisPrivate::setMin(const QVariant& min)
184 {
186 {
185 Q_Q(QCategoriesAxis);
187 Q_Q(QCategoriesAxis);
186 q->setMin(min.toString());
188 q->setMin(min.toString());
187 }
189 }
188
190
189 void QCategoriesAxisPrivate::setMax(const QVariant& max)
191 void QCategoriesAxisPrivate::setMax(const QVariant& max)
190 {
192 {
191 Q_Q(QCategoriesAxis);
193 Q_Q(QCategoriesAxis);
192 q->setMax(max.toString());
194 q->setMax(max.toString());
193 }
195 }
194
196
195 void QCategoriesAxisPrivate::setRange(const QVariant& min, const QVariant& max)
197 void QCategoriesAxisPrivate::setRange(const QVariant& min, const QVariant& max)
196 {
198 {
197 Q_Q(QCategoriesAxis);
199 Q_Q(QCategoriesAxis);
198 q->setRange(min.toString(),max.toString());
200 q->setRange(min.toString(),max.toString());
199 }
201 }
200
202
201 int QCategoriesAxisPrivate::ticksCount() const
203 int QCategoriesAxisPrivate::ticksCount() const
202 {
204 {
203 return m_categories.count()+1;
205 return m_categories.count()+1;
204 }
206 }
205
207
208 ChartAxis* QCategoriesAxisPrivate::createGraphics(ChartPresenter* presenter)
209 {
210 Q_Q( QCategoriesAxis);
211 if(m_orientation == Qt::Vertical){
212 return new ChartAxisY(q,presenter);
213 }else{
214 return new ChartAxisX(q,presenter);
215 }
216
217 }
218
206 #include "moc_qcategoriesaxis.cpp"
219 #include "moc_qcategoriesaxis.cpp"
207 #include "moc_qcategoriesaxis_p.cpp"
220 #include "moc_qcategoriesaxis_p.cpp"
208
221
209 QTCOMMERCIALCHART_END_NAMESPACE
222 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,67 +1,70
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef QCATEGORIESAXIS_P_H
30 #ifndef QCATEGORIESAXIS_P_H
31 #define QCATEGORIESAXIS_P_H
31 #define QCATEGORIESAXIS_P_H
32
32
33 #include "qcategoriesaxis.h"
33 #include "qcategoriesaxis.h"
34 #include "qabstractaxis_p.h"
34 #include "qabstractaxis_p.h"
35
35
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37
37
38 class QCategoriesAxisPrivate : public QAbstractAxisPrivate
38 class QCategoriesAxisPrivate : public QAbstractAxisPrivate
39 {
39 {
40 Q_OBJECT
40 Q_OBJECT
41
41
42 public:
42 public:
43 QCategoriesAxisPrivate(QCategoriesAxis *q);
43 QCategoriesAxisPrivate(QCategoriesAxis *q);
44 ~QCategoriesAxisPrivate();
44 ~QCategoriesAxisPrivate();
45
45
46 public:
47 ChartAxis* createGraphics(ChartPresenter* presenter);
48
46 private:
49 private:
47 //range handling
50 //range handling
48 void setMin(const QVariant& min);
51 void setMin(const QVariant& min);
49 void setMax(const QVariant& max);
52 void setMax(const QVariant& max);
50 void setRange(const QVariant& min, const QVariant& max);
53 void setRange(const QVariant& min, const QVariant& max);
51 int ticksCount() const;
54 int ticksCount() const;
52
55
53 private:
56 private:
54 QStringList m_categories;
57 QStringList m_categories;
55 QString m_minCategory;
58 QString m_minCategory;
56 QString m_maxCategory;
59 QString m_maxCategory;
57
60
58 Q_SIGNALS:
61 Q_SIGNALS:
59 void updated();
62 void updated();
60
63
61 private:
64 private:
62 Q_DECLARE_PUBLIC(QCategoriesAxis)
65 Q_DECLARE_PUBLIC(QCategoriesAxis)
63 };
66 };
64
67
65 QTCOMMERCIALCHART_END_NAMESPACE
68 QTCOMMERCIALCHART_END_NAMESPACE
66
69
67 #endif // QCATEGORIESAXIS_P_H
70 #endif // QCATEGORIESAXIS_P_H
@@ -1,251 +1,265
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qvaluesaxis.h"
21 #include "qvaluesaxis.h"
22 #include "qvaluesaxis_p.h"
22 #include "qvaluesaxis_p.h"
23 #include "chartaxisx_p.h"
24 #include "chartaxisy_p.h"
25 #include <QDebug>
23
26
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25 /*!
28 /*!
26 \class QValuesAxis
29 \class QValuesAxis
27 \brief The QValuesAxis class is used for manipulating chart's axis.
30 \brief The QValuesAxis class is used for manipulating chart's axis.
28 \mainclass
31 \mainclass
29
32
30 Axis can be setup to show axis line with tick marks, grid lines and shades.
33 Axis can be setup to show axis line with tick marks, grid lines and shades.
31 */
34 */
32
35
33 /*!
36 /*!
34 \qmlclass Axis QValuesAxis
37 \qmlclass Axis QValuesAxis
35 \brief The Axis element is used for manipulating chart's axes
38 \brief The Axis element is used for manipulating chart's axes
36
39
37 Axis can be setup to show axis line with tick marks, grid lines and shades.
40 Axis can be setup to show axis line with tick marks, grid lines and shades.
38
41
39 To access Axes you can use ChartView API. For example:
42 To access Axes you can use ChartView API. For example:
40 \code
43 \code
41 ChartView {
44 ChartView {
42 axisX.min: 0
45 axisX.min: 0
43 axisX.max: 3
46 axisX.max: 3
44 axisX.ticksCount: 4
47 axisX.ticksCount: 4
45 axisY.min: 0
48 axisY.min: 0
46 axisY.max: 4
49 axisY.max: 4
47 // Add a few series...
50 // Add a few series...
48 }
51 }
49 \endcode
52 \endcode
50 */
53 */
51
54
52 /*!
55 /*!
53 \property QValuesAxis::min
56 \property QValuesAxis::min
54 Defines the minimum value on the axis.
57 Defines the minimum value on the axis.
55 */
58 */
56 /*!
59 /*!
57 \qmlproperty real Axis::min
60 \qmlproperty real Axis::min
58 Defines the minimum value on the axis.
61 Defines the minimum value on the axis.
59 */
62 */
60
63
61 /*!
64 /*!
62 \property QValuesAxis::max
65 \property QValuesAxis::max
63 Defines the maximum value on the axis.
66 Defines the maximum value on the axis.
64 */
67 */
65 /*!
68 /*!
66 \qmlproperty real Axis::max
69 \qmlproperty real Axis::max
67 Defines the maximum value on the axis.
70 Defines the maximum value on the axis.
68 */
71 */
69
72
70 /*!
73 /*!
71 \fn void QValuesAxis::minChanged(qreal min)
74 \fn void QValuesAxis::minChanged(qreal min)
72 Axis emits signal when \a min of axis has changed.
75 Axis emits signal when \a min of axis has changed.
73 */
76 */
74
77
75 /*!
78 /*!
76 \fn void QValuesAxis::maxChanged(qreal max)
79 \fn void QValuesAxis::maxChanged(qreal max)
77 Axis emits signal when \a max of axis has changed.
80 Axis emits signal when \a max of axis has changed.
78 */
81 */
79
82
80 /*!
83 /*!
81 \fn void QValuesAxis::rangeChanged(qreal min, qreal max)
84 \fn void QValuesAxis::rangeChanged(qreal min, qreal max)
82 Axis emits signal when \a min or \a max of axis has changed.
85 Axis emits signal when \a min or \a max of axis has changed.
83 */
86 */
84
87
85 QValuesAxis::QValuesAxis(QObject *parent) :
88 QValuesAxis::QValuesAxis(QObject *parent) :
86 QAbstractAxis(*new QValuesAxisPrivate(this),parent)
89 QAbstractAxis(*new QValuesAxisPrivate(this),parent)
87 {
90 {
88
91
89 }
92 }
90
93
91 QValuesAxis::QValuesAxis(QValuesAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent)
94 QValuesAxis::QValuesAxis(QValuesAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent)
92 {
95 {
93
96
94 }
97 }
95
98
96 QValuesAxis::~QValuesAxis()
99 QValuesAxis::~QValuesAxis()
97 {
100 {
98
101
99 }
102 }
100
103
101 void QValuesAxis::setMin(qreal min)
104 void QValuesAxis::setMin(qreal min)
102 {
105 {
103 Q_D(QValuesAxis);
106 Q_D(QValuesAxis);
104 setRange(min,d->m_max);
107 setRange(min,d->m_max);
105 }
108 }
106
109
107 qreal QValuesAxis::min() const
110 qreal QValuesAxis::min() const
108 {
111 {
109 Q_D(const QValuesAxis);
112 Q_D(const QValuesAxis);
110 return d->m_min;
113 return d->m_min;
111 }
114 }
112
115
113 void QValuesAxis::setMax(qreal max)
116 void QValuesAxis::setMax(qreal max)
114 {
117 {
115 Q_D(QValuesAxis);
118 Q_D(QValuesAxis);
116 setRange(d->m_min,max);
119 setRange(d->m_min,max);
117 }
120 }
118
121
119 qreal QValuesAxis::max() const
122 qreal QValuesAxis::max() const
120 {
123 {
121 Q_D(const QValuesAxis);
124 Q_D(const QValuesAxis);
122 return d->m_max;
125 return d->m_max;
123 }
126 }
124
127
125 /*!
128 /*!
126 Sets range from \a min to \a max on the axis.
129 Sets range from \a min to \a max on the axis.
127 */
130 */
128 void QValuesAxis::setRange(qreal min, qreal max)
131 void QValuesAxis::setRange(qreal min, qreal max)
129 {
132 {
130 Q_D(QValuesAxis);
133 Q_D(QValuesAxis);
131 bool changed = false;
134 bool changed = false;
132 if (!qFuzzyIsNull(d->m_min - min)) {
135 if (!qFuzzyIsNull(d->m_min - min)) {
133 d->m_min = min;
136 d->m_min = min;
134 changed = true;
137 changed = true;
135 emit minChanged(min);
138 emit minChanged(min);
136 }
139 }
137
140
138 if (!qFuzzyIsNull(d->m_max - max)) {
141 if (!qFuzzyIsNull(d->m_max - max)) {
139 d->m_max = max;
142 d->m_max = max;
140 changed = true;
143 changed = true;
141 emit maxChanged(max);
144 emit maxChanged(max);
142 }
145 }
143
146
144 if (changed) {
147 if (changed) {
145 emit rangeChanged(d->m_min,d->m_max);
148 emit rangeChanged(d->m_min,d->m_max);
146 emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers);
149 emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers);
147 }
150 }
148 }
151 }
149
152
150 /*!
153 /*!
151 Sets \a count for ticks on the axis.
154 Sets \a count for ticks on the axis.
152 */
155 */
153 void QValuesAxis::setTicksCount(int count)
156 void QValuesAxis::setTicksCount(int count)
154 {
157 {
155 Q_D(QValuesAxis);
158 Q_D(QValuesAxis);
156 if (d->m_ticksCount != count) {
159 if (d->m_ticksCount != count) {
157 d->m_ticksCount = count;
160 d->m_ticksCount = count;
158 emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers);
161 emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers);
159 }
162 }
160 }
163 }
161
164
162 /*!
165 /*!
163 \fn int QAbstractAxis::ticksCount() const
166 \fn int QAbstractAxis::ticksCount() const
164 Return number of ticks on the axis
167 Return number of ticks on the axis
165 */
168 */
166 int QValuesAxis::ticksCount() const
169 int QValuesAxis::ticksCount() const
167 {
170 {
168 Q_D(const QValuesAxis);
171 Q_D(const QValuesAxis);
169 return d->m_ticksCount;
172 return d->m_ticksCount;
170 }
173 }
171
174
172 void QValuesAxis::setNiceNumbersEnabled(bool enable)
175 void QValuesAxis::setNiceNumbersEnabled(bool enable)
173 {
176 {
174 Q_D(QValuesAxis);
177 Q_D(QValuesAxis);
175 if (d->m_niceNumbers != enable){
178 if (d->m_niceNumbers != enable){
176 d->m_niceNumbers = enable;
179 d->m_niceNumbers = enable;
177 emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers);
180 emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers);
178 }
181 }
179 }
182 }
180
183
181 bool QValuesAxis::niceNumbersEnabled() const
184 bool QValuesAxis::niceNumbersEnabled() const
182 {
185 {
183 Q_D(const QValuesAxis);
186 Q_D(const QValuesAxis);
184 return d->m_niceNumbers;
187 return d->m_niceNumbers;
185 }
188 }
186
189
187 QAbstractAxis::AxisType QValuesAxis::type() const
190 QAbstractAxis::AxisType QValuesAxis::type() const
188 {
191 {
189 return AxisTypeValues;
192 return AxisTypeValues;
190 }
193 }
191
194
192 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
195 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
193
196
194 QValuesAxisPrivate::QValuesAxisPrivate(QValuesAxis* q):
197 QValuesAxisPrivate::QValuesAxisPrivate(QValuesAxis* q):
195 QAbstractAxisPrivate(q),
198 QAbstractAxisPrivate(q),
196 m_min(0),
199 m_min(0),
197 m_max(0),
200 m_max(0),
198 m_niceNumbers(false),
201 m_niceNumbers(false),
199 m_ticksCount(5)
202 m_ticksCount(5)
200 {
203 {
201
204
202 }
205 }
203
206
204 QValuesAxisPrivate::~QValuesAxisPrivate()
207 QValuesAxisPrivate::~QValuesAxisPrivate()
205 {
208 {
206
209
207 }
210 }
208
211
209 void QValuesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
212 void QValuesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
210 {
213 {
211 Q_Q(QValuesAxis);
214 Q_Q(QValuesAxis);
212 q->setRange(min,max);
215 q->setRange(min,max);
213 q->setTicksCount(count);
216 q->setTicksCount(count);
214 }
217 }
215
218
216
219
217 void QValuesAxisPrivate::setMin(const QVariant& min)
220 void QValuesAxisPrivate::setMin(const QVariant& min)
218 {
221 {
219 Q_Q(QValuesAxis);
222 Q_Q(QValuesAxis);
220 bool ok;
223 bool ok;
221 qreal value = min.toReal(&ok);
224 qreal value = min.toReal(&ok);
222 if(ok) q->setMin(value);
225 if(ok) q->setMin(value);
223 }
226 }
224
227
225 void QValuesAxisPrivate::setMax(const QVariant& max)
228 void QValuesAxisPrivate::setMax(const QVariant& max)
226 {
229 {
227 Q_Q(QValuesAxis);
230 Q_Q(QValuesAxis);
228 bool ok;
231 bool ok;
229 qreal value = max.toReal(&ok);
232 qreal value = max.toReal(&ok);
230 if(ok) q->setMax(value);
233 if(ok) q->setMax(value);
231 }
234 }
232
235
233 void QValuesAxisPrivate::setRange(const QVariant& min, const QVariant& max)
236 void QValuesAxisPrivate::setRange(const QVariant& min, const QVariant& max)
234 {
237 {
235 Q_Q(QValuesAxis);
238 Q_Q(QValuesAxis);
236 bool ok1;
239 bool ok1;
237 bool ok2;
240 bool ok2;
238 qreal value1 = min.toReal(&ok1);
241 qreal value1 = min.toReal(&ok1);
239 qreal value2 = max.toReal(&ok2);
242 qreal value2 = max.toReal(&ok2);
240 if(ok1&&ok2) q->setRange(value1,value2);
243 if(ok1&&ok2) q->setRange(value1,value2);
241 }
244 }
242
245
243 int QValuesAxisPrivate::ticksCount() const
246 int QValuesAxisPrivate::ticksCount() const
244 {
247 {
245 return m_ticksCount;
248 return m_ticksCount;
246 }
249 }
247
250
251 ChartAxis* QValuesAxisPrivate::createGraphics(ChartPresenter* presenter)
252 {
253 Q_Q(QValuesAxis);
254 if(m_orientation == Qt::Vertical){
255 return new ChartAxisY(q,presenter);
256 }else{
257 return new ChartAxisX(q,presenter);
258 }
259
260 }
261
248 #include "moc_qvaluesaxis.cpp"
262 #include "moc_qvaluesaxis.cpp"
249 #include "moc_qvaluesaxis_p.cpp"
263 #include "moc_qvaluesaxis_p.cpp"
250
264
251 QTCOMMERCIALCHART_END_NAMESPACE
265 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,67 +1,70
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef QVALUESAXIS_P_H
30 #ifndef QVALUESAXIS_P_H
31 #define QVALUESAXIS_P_H
31 #define QVALUESAXIS_P_H
32
32
33 #include "qvaluesaxis.h"
33 #include "qvaluesaxis.h"
34 #include "qabstractaxis_p.h"
34 #include "qabstractaxis_p.h"
35
35
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37
37
38 class QValuesAxisPrivate : public QAbstractAxisPrivate
38 class QValuesAxisPrivate : public QAbstractAxisPrivate
39 {
39 {
40 Q_OBJECT
40 Q_OBJECT
41 public:
41 public:
42 QValuesAxisPrivate(QValuesAxis *q);
42 QValuesAxisPrivate(QValuesAxis *q);
43 ~QValuesAxisPrivate();
43 ~QValuesAxisPrivate();
44
44
45 Q_SIGNALS:
45 Q_SIGNALS:
46 void changed(qreal min, qreal max, int tickCount,bool niceNumbers);
46 void changed(qreal min, qreal max, int tickCount,bool niceNumbers);
47
47
48 public Q_SLOTS:
48 public Q_SLOTS:
49 void handleAxisRangeChanged(qreal min, qreal max,int count);
49 void handleAxisRangeChanged(qreal min, qreal max,int count);
50
50
51 public:
52 ChartAxis* createGraphics(ChartPresenter* presenter);
53
51 protected:
54 protected:
52 void setMin(const QVariant& min);
55 void setMin(const QVariant& min);
53 void setMax(const QVariant& max);
56 void setMax(const QVariant& max);
54 void setRange(const QVariant& min, const QVariant& max);
57 void setRange(const QVariant& min, const QVariant& max);
55 int ticksCount() const;
58 int ticksCount() const;
56
59
57 private:
60 private:
58 qreal m_min;
61 qreal m_min;
59 qreal m_max;
62 qreal m_max;
60 bool m_niceNumbers;
63 bool m_niceNumbers;
61 int m_ticksCount;
64 int m_ticksCount;
62 Q_DECLARE_PUBLIC(QValuesAxis)
65 Q_DECLARE_PUBLIC(QValuesAxis)
63 };
66 };
64
67
65 QTCOMMERCIALCHART_END_NAMESPACE
68 QTCOMMERCIALCHART_END_NAMESPACE
66
69
67 #endif // QVALUESAXIS_P_H
70 #endif // QVALUESAXIS_P_H
@@ -1,733 +1,731
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qbarseries.h"
21 #include "qbarseries.h"
22 #include "qbarseries_p.h"
22 #include "qbarseries_p.h"
23 #include "qbarset.h"
23 #include "qbarset.h"
24 #include "qbarset_p.h"
24 #include "qbarset_p.h"
25 #include "domain_p.h"
25 #include "domain_p.h"
26 #include "legendmarker_p.h"
26 #include "legendmarker_p.h"
27 #include "chartdataset_p.h"
27 #include "chartdataset_p.h"
28 #include "charttheme_p.h"
28 #include "charttheme_p.h"
29 #include "chartanimator_p.h"
29 #include "chartanimator_p.h"
30 #include "qvaluesaxis.h"
30 #include "qvaluesaxis.h"
31
31
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33
33
34 /*!
34 /*!
35 \class QBarSeries
35 \class QBarSeries
36 \brief Series for creating a bar chart
36 \brief Series for creating a bar chart
37 \mainclass
37 \mainclass
38
38
39 QBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to
39 QBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to
40 the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar
40 the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar
41 and y-value is the height of the bar. The category names are ignored with this series and x-axis
41 and y-value is the height of the bar. The category names are ignored with this series and x-axis
42 shows the x-values.
42 shows the x-values.
43
43
44 See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart.
44 See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart.
45 \image examples_barchart.png
45 \image examples_barchart.png
46
46
47 \sa QBarSet, QStackedBarSeries, QPercentBarSeries
47 \sa QBarSet, QStackedBarSeries, QPercentBarSeries
48 */
48 */
49 /*!
49 /*!
50 \qmlclass BarSeries QBarSeries
50 \qmlclass BarSeries QBarSeries
51 \inherits AbstractSeries
51 \inherits AbstractSeries
52
52
53 The following QML shows how to create a simple bar chart:
53 The following QML shows how to create a simple bar chart:
54 \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1
54 \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1
55
55
56 \beginfloatleft
56 \beginfloatleft
57 \image demos_qmlchart6.png
57 \image demos_qmlchart6.png
58 \endfloat
58 \endfloat
59 \clearfloat
59 \clearfloat
60 */
60 */
61
61
62 /*!
62 /*!
63 \property QBarSeries::barWidth
63 \property QBarSeries::barWidth
64 The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars
64 The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars
65 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
65 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
66 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
66 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
67 Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar.
67 Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar.
68 \sa QGroupedBarSeries
68 \sa QGroupedBarSeries
69 */
69 */
70 /*!
70 /*!
71 \qmlproperty real BarSeries::barWidth
71 \qmlproperty real BarSeries::barWidth
72 The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars
72 The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars
73 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
73 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
74 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
74 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
75 Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar.
75 Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar.
76 */
76 */
77
77
78 /*!
78 /*!
79 \property QBarSeries::count
79 \property QBarSeries::count
80 Holds the number of sets in series.
80 Holds the number of sets in series.
81 */
81 */
82 /*!
82 /*!
83 \qmlproperty int BarSeries::count
83 \qmlproperty int BarSeries::count
84 Holds the number of sets in series.
84 Holds the number of sets in series.
85 */
85 */
86
86
87 /*!
87 /*!
88 \property QBarSeries::labelsVisible
88 \property QBarSeries::labelsVisible
89 Defines the visibility of the labels in series
89 Defines the visibility of the labels in series
90 */
90 */
91 /*!
91 /*!
92 \qmlproperty bool BarSeries::labelsVisible
92 \qmlproperty bool BarSeries::labelsVisible
93 Defines the visibility of the labels in series
93 Defines the visibility of the labels in series
94 */
94 */
95
95
96 /*!
96 /*!
97 \fn void QBarSeries::clicked(QBarSet *barset, int index)
97 \fn void QBarSeries::clicked(QBarSet *barset, int index)
98 The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset.
98 The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset.
99 Clicked bar inside set is indexed by \a index
99 Clicked bar inside set is indexed by \a index
100 */
100 */
101 /*!
101 /*!
102 \qmlsignal BarSeries::onClicked(BarSet barset, int index)
102 \qmlsignal BarSeries::onClicked(BarSet barset, int index)
103 The signal is emitted if the user clicks with a mouse on top of BarSet.
103 The signal is emitted if the user clicks with a mouse on top of BarSet.
104 Clicked bar inside set is indexed by \a index
104 Clicked bar inside set is indexed by \a index
105 */
105 */
106
106
107 /*!
107 /*!
108 \fn void QBarSeries::hovered(QBarSet* barset, bool status)
108 \fn void QBarSeries::hovered(QBarSet* barset, bool status)
109
109
110 The signal is emitted if mouse is hovered on top of series.
110 The signal is emitted if mouse is hovered on top of series.
111 Parameter \a barset is the pointer of barset, where hover happened.
111 Parameter \a barset is the pointer of barset, where hover happened.
112 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
112 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
113 */
113 */
114 /*!
114 /*!
115 \qmlsignal BarSeries::onHovered(BarSet barset, bool status)
115 \qmlsignal BarSeries::onHovered(BarSet barset, bool status)
116
116
117 The signal is emitted if mouse is hovered on top of series.
117 The signal is emitted if mouse is hovered on top of series.
118 Parameter \a barset is the pointer of barset, where hover happened.
118 Parameter \a barset is the pointer of barset, where hover happened.
119 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
119 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
120 */
120 */
121
121
122 /*!
122 /*!
123 \fn void QBarSeries::countChanged()
123 \fn void QBarSeries::countChanged()
124 This signal is emitted when barset count has been changed, for example by append or remove.
124 This signal is emitted when barset count has been changed, for example by append or remove.
125 */
125 */
126 /*!
126 /*!
127 \qmlsignal BarSeries::onCountChanged()
127 \qmlsignal BarSeries::onCountChanged()
128 This signal is emitted when barset count has been changed, for example by append or remove.
128 This signal is emitted when barset count has been changed, for example by append or remove.
129 */
129 */
130
130
131 /*!
131 /*!
132 \fn void QBarSeries::labelsVisibleChanged()
132 \fn void QBarSeries::labelsVisibleChanged()
133 This signal is emitted when labels visibility have changed.
133 This signal is emitted when labels visibility have changed.
134 \sa isLabelsVisible(), setLabelsVisible()
134 \sa isLabelsVisible(), setLabelsVisible()
135 */
135 */
136
136
137 /*!
137 /*!
138 \fn void QBarSeries::barsetsAdded(QList<QBarSet*> sets)
138 \fn void QBarSeries::barsetsAdded(QList<QBarSet*> sets)
139 This signal is emitted when \a sets have been added to the series.
139 This signal is emitted when \a sets have been added to the series.
140 \sa append(), insert()
140 \sa append(), insert()
141 */
141 */
142 /*!
142 /*!
143 \qmlsignal BarSeries::onAdded(BarSet barset)
143 \qmlsignal BarSeries::onAdded(BarSet barset)
144 Emitted when \a barset has been added to the series.
144 Emitted when \a barset has been added to the series.
145 */
145 */
146
146
147 /*!
147 /*!
148 \fn void QBarSeries::barsetsRemoved(QList<QBarSet*> sets)
148 \fn void QBarSeries::barsetsRemoved(QList<QBarSet*> sets)
149 This signal is emitted when \a sets have been removed from the series.
149 This signal is emitted when \a sets have been removed from the series.
150 \sa remove()
150 \sa remove()
151 */
151 */
152 /*!
152 /*!
153 \qmlsignal BarSeries::onRemoved(BarSet barset)
153 \qmlsignal BarSeries::onRemoved(BarSet barset)
154 Emitted when \a barset has been removed from the series.
154 Emitted when \a barset has been removed from the series.
155 */
155 */
156
156
157 /*!
157 /*!
158 \qmlmethod BarSet BarSeries::at(int index)
158 \qmlmethod BarSet BarSeries::at(int index)
159 Returns bar set at \a index. Returns null if the index is not valid.
159 Returns bar set at \a index. Returns null if the index is not valid.
160 */
160 */
161
161
162 /*!
162 /*!
163 \qmlmethod BarSet BarSeries::append(string label, VariantList values)
163 \qmlmethod BarSet BarSeries::append(string label, VariantList values)
164 Adds a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints.
164 Adds a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints.
165 For example:
165 For example:
166 \code
166 \code
167 myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]);
167 myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]);
168 myBarSeries.append("set 2", [Qt.point(0, 1), Qt.point(2, 2.5), Qt.point(3.5, 2.2)]);
168 myBarSeries.append("set 2", [Qt.point(0, 1), Qt.point(2, 2.5), Qt.point(3.5, 2.2)]);
169 \endcode
169 \endcode
170 */
170 */
171
171
172 /*!
172 /*!
173 \qmlmethod BarSet BarSeries::insert(int index, string label, VariantList values)
173 \qmlmethod BarSet BarSeries::insert(int index, string label, VariantList values)
174 Inserts a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints.
174 Inserts a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints.
175 If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is
175 If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is
176 appended.
176 appended.
177 \sa BarSeries::append()
177 \sa BarSeries::append()
178 */
178 */
179
179
180 /*!
180 /*!
181 \qmlmethod bool BarSeries::remove(BarSet barset)
181 \qmlmethod bool BarSeries::remove(BarSet barset)
182 Removes the barset from the series. Returns true if successfull, false otherwise.
182 Removes the barset from the series. Returns true if successfull, false otherwise.
183 */
183 */
184
184
185 /*!
185 /*!
186 \qmlmethod BarSeries::clear()
186 \qmlmethod BarSeries::clear()
187 Removes all barsets from the series.
187 Removes all barsets from the series.
188 */
188 */
189
189
190 /*!
190 /*!
191 Constructs empty QBarSeries.
191 Constructs empty QBarSeries.
192 QBarSeries is QObject which is a child of a \a parent.
192 QBarSeries is QObject which is a child of a \a parent.
193 */
193 */
194 QBarSeries::QBarSeries(QObject *parent) :
194 QBarSeries::QBarSeries(QObject *parent) :
195 QAbstractSeries(*new QBarSeriesPrivate(this),parent)
195 QAbstractSeries(*new QBarSeriesPrivate(this),parent)
196 {
196 {
197 }
197 }
198
198
199 /*!
199 /*!
200 Destructs barseries and owned barsets.
200 Destructs barseries and owned barsets.
201 */
201 */
202 QBarSeries::~QBarSeries()
202 QBarSeries::~QBarSeries()
203 {
203 {
204 Q_D(QBarSeries);
204 Q_D(QBarSeries);
205 if(d->m_dataset){
205 if(d->m_dataset){
206 d->m_dataset->removeSeries(this);
206 d->m_dataset->removeSeries(this);
207 }
207 }
208 }
208 }
209
209
210 /*!
210 /*!
211 \internal
211 \internal
212 */
212 */
213 QBarSeries::QBarSeries(QBarSeriesPrivate &d, QObject *parent) :
213 QBarSeries::QBarSeries(QBarSeriesPrivate &d, QObject *parent) :
214 QAbstractSeries(d,parent)
214 QAbstractSeries(d,parent)
215 {
215 {
216 }
216 }
217
217
218 /*!
218 /*!
219 Returns the type of series. Derived classes override this.
219 Returns the type of series. Derived classes override this.
220 */
220 */
221 QAbstractSeries::SeriesType QBarSeries::type() const
221 QAbstractSeries::SeriesType QBarSeries::type() const
222 {
222 {
223 return QAbstractSeries::SeriesTypeBar;
223 return QAbstractSeries::SeriesTypeBar;
224 }
224 }
225
225
226 /*!
226 /*!
227 Sets the width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars
227 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
228 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
228 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
229 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
229 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
230 Note that with \link QGroupedBarSeries \endlink this value means the width of one group of bars instead of just one bar.
230 Note that with \link QGroupedBarSeries \endlink this value means the width of one group of bars instead of just one bar.
231 */
231 */
232 void QBarSeries::setBarWidth(qreal width)
232 void QBarSeries::setBarWidth(qreal width)
233 {
233 {
234 Q_D(QBarSeries);
234 Q_D(QBarSeries);
235 d->setBarWidth(width);
235 d->setBarWidth(width);
236 }
236 }
237
237
238 /*!
238 /*!
239 Returns the width of the bars of the series.
239 Returns the width of the bars of the series.
240 \sa setBarWidth()
240 \sa setBarWidth()
241 */
241 */
242 qreal QBarSeries::barWidth() const
242 qreal QBarSeries::barWidth() const
243 {
243 {
244 Q_D(const QBarSeries);
244 Q_D(const QBarSeries);
245 return d->barWidth();
245 return d->barWidth();
246 }
246 }
247
247
248 /*!
248 /*!
249 Adds a set of bars to series. Takes ownership of \a set. If the set is null or is already in series, it won't be appended.
249 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.
250 Returns true, if appending succeeded.
250 Returns true, if appending succeeded.
251 */
251 */
252 bool QBarSeries::append(QBarSet *set)
252 bool QBarSeries::append(QBarSet *set)
253 {
253 {
254 Q_D(QBarSeries);
254 Q_D(QBarSeries);
255 bool success = d->append(set);
255 bool success = d->append(set);
256 if (success) {
256 if (success) {
257 QList<QBarSet*> sets;
257 QList<QBarSet*> sets;
258 sets.append(set);
258 sets.append(set);
259 emit barsetsAdded(sets);
259 emit barsetsAdded(sets);
260 emit countChanged();
260 emit countChanged();
261 }
261 }
262 return success;
262 return success;
263 }
263 }
264
264
265 /*!
265 /*!
266 Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set.
266 Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set.
267 Returns true, if set was removed.
267 Returns true, if set was removed.
268 */
268 */
269 bool QBarSeries::remove(QBarSet *set)
269 bool QBarSeries::remove(QBarSet *set)
270 {
270 {
271 Q_D(QBarSeries);
271 Q_D(QBarSeries);
272 bool success = d->remove(set);
272 bool success = d->remove(set);
273 if (success) {
273 if (success) {
274 QList<QBarSet*> sets;
274 QList<QBarSet*> sets;
275 sets.append(set);
275 sets.append(set);
276 emit barsetsRemoved(sets);
276 emit barsetsRemoved(sets);
277 emit countChanged();
277 emit countChanged();
278 }
278 }
279 return success;
279 return success;
280 }
280 }
281
281
282 /*!
282 /*!
283 Adds a list of barsets to series. Takes ownership of \a sets.
283 Adds a list of barsets to series. Takes ownership of \a sets.
284 Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series,
284 Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series,
285 nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended
285 nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended
286 and function returns false.
286 and function returns false.
287 */
287 */
288 bool QBarSeries::append(QList<QBarSet* > sets)
288 bool QBarSeries::append(QList<QBarSet* > sets)
289 {
289 {
290 Q_D(QBarSeries);
290 Q_D(QBarSeries);
291 bool success = d->append(sets);
291 bool success = d->append(sets);
292 if (success) {
292 if (success) {
293 emit barsetsAdded(sets);
293 emit barsetsAdded(sets);
294 emit countChanged();
294 emit countChanged();
295 }
295 }
296 return success;
296 return success;
297 }
297 }
298
298
299 /*!
299 /*!
300 Insert a set of bars to series at \a index postion. Takes ownership of \a set. If the set is null or is already in series, it won't be appended.
300 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.
301 Returns true, if inserting succeeded.
301 Returns true, if inserting succeeded.
302
302
303 */
303 */
304 bool QBarSeries::insert(int index, QBarSet *set)
304 bool QBarSeries::insert(int index, QBarSet *set)
305 {
305 {
306 Q_D(QBarSeries);
306 Q_D(QBarSeries);
307 bool success = d->insert(index, set);
307 bool success = d->insert(index, set);
308 if (success) {
308 if (success) {
309 QList<QBarSet*> sets;
309 QList<QBarSet*> sets;
310 sets.append(set);
310 sets.append(set);
311 emit barsetsAdded(sets);
311 emit barsetsAdded(sets);
312 emit countChanged();
312 emit countChanged();
313 }
313 }
314 return success;
314 return success;
315 }
315 }
316
316
317 /*!
317 /*!
318 Removes all of the bar sets from the series
318 Removes all of the bar sets from the series
319 */
319 */
320 void QBarSeries::clear()
320 void QBarSeries::clear()
321 {
321 {
322 Q_D(QBarSeries);
322 Q_D(QBarSeries);
323 QList<QBarSet *> sets = barSets();
323 QList<QBarSet *> sets = barSets();
324 bool success = d->remove(sets);
324 bool success = d->remove(sets);
325 if (success) {
325 if (success) {
326 emit barsetsRemoved(sets);
326 emit barsetsRemoved(sets);
327 emit countChanged();
327 emit countChanged();
328 }
328 }
329 }
329 }
330
330
331 /*!
331 /*!
332 Returns number of sets in series.
332 Returns number of sets in series.
333 */
333 */
334 int QBarSeries::count() const
334 int QBarSeries::count() const
335 {
335 {
336 Q_D(const QBarSeries);
336 Q_D(const QBarSeries);
337 return d->m_barSets.count();
337 return d->m_barSets.count();
338 }
338 }
339
339
340 /*!
340 /*!
341 Returns a list of sets in series. Keeps ownership of sets.
341 Returns a list of sets in series. Keeps ownership of sets.
342 */
342 */
343 QList<QBarSet*> QBarSeries::barSets() const
343 QList<QBarSet*> QBarSeries::barSets() const
344 {
344 {
345 Q_D(const QBarSeries);
345 Q_D(const QBarSeries);
346 return d->m_barSets;
346 return d->m_barSets;
347 }
347 }
348
348
349 /*!
349 /*!
350 Sets the visibility of labels in series to \a visible
350 Sets the visibility of labels in series to \a visible
351 */
351 */
352 void QBarSeries::setLabelsVisible(bool visible)
352 void QBarSeries::setLabelsVisible(bool visible)
353 {
353 {
354 Q_D(QBarSeries);
354 Q_D(QBarSeries);
355 if (d->m_labelsVisible != visible) {
355 if (d->m_labelsVisible != visible) {
356 d->setLabelsVisible(visible);
356 d->setLabelsVisible(visible);
357 emit labelsVisibleChanged();
357 emit labelsVisibleChanged();
358 }
358 }
359 }
359 }
360
360
361 /*!
361 /*!
362 Returns the visibility of labels
362 Returns the visibility of labels
363 */
363 */
364 bool QBarSeries::isLabelsVisible() const
364 bool QBarSeries::isLabelsVisible() const
365 {
365 {
366 Q_D(const QBarSeries);
366 Q_D(const QBarSeries);
367 return d->m_labelsVisible;
367 return d->m_labelsVisible;
368 }
368 }
369
369
370 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
370 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
371
371
372 QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) :
372 QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) :
373 QAbstractSeriesPrivate(q),
373 QAbstractSeriesPrivate(q),
374 m_barWidth(0.5), // Default value is 50% of category width
374 m_barWidth(0.5), // Default value is 50% of category width
375 m_labelsVisible(false),
375 m_labelsVisible(false),
376 m_visible(true)
376 m_visible(true)
377 {
377 {
378 }
378 }
379
379
380 int QBarSeriesPrivate::categoryCount() const
380 int QBarSeriesPrivate::categoryCount() const
381 {
381 {
382 // No categories defined. return count of longest set.
382 // No categories defined. return count of longest set.
383 int count = 0;
383 int count = 0;
384 for (int i=0; i<m_barSets.count(); i++) {
384 for (int i=0; i<m_barSets.count(); i++) {
385 if (m_barSets.at(i)->count() > count) {
385 if (m_barSets.at(i)->count() > count) {
386 count = m_barSets.at(i)->count();
386 count = m_barSets.at(i)->count();
387 }
387 }
388 }
388 }
389
389
390 return count;
390 return count;
391 }
391 }
392
392
393 void QBarSeriesPrivate::setBarWidth(qreal width)
393 void QBarSeriesPrivate::setBarWidth(qreal width)
394 {
394 {
395 if (width < 0.0) {
395 if (width < 0.0) {
396 width = 0.0;
396 width = 0.0;
397 }
397 }
398 m_barWidth = width;
398 m_barWidth = width;
399 emit updatedBars();
399 emit updatedBars();
400 }
400 }
401
401
402 qreal QBarSeriesPrivate::barWidth() const
402 qreal QBarSeriesPrivate::barWidth() const
403 {
403 {
404 return m_barWidth;
404 return m_barWidth;
405 }
405 }
406
406
407 QBarSet* QBarSeriesPrivate::barsetAt(int index)
407 QBarSet* QBarSeriesPrivate::barsetAt(int index)
408 {
408 {
409 return m_barSets.at(index);
409 return m_barSets.at(index);
410 }
410 }
411
411
412 void QBarSeriesPrivate::setVisible(bool visible)
412 void QBarSeriesPrivate::setVisible(bool visible)
413 {
413 {
414 m_visible = visible;
414 m_visible = visible;
415 emit updatedBars();
415 emit updatedBars();
416 }
416 }
417
417
418 void QBarSeriesPrivate::setLabelsVisible(bool visible)
418 void QBarSeriesPrivate::setLabelsVisible(bool visible)
419 {
419 {
420 m_labelsVisible = visible;
420 m_labelsVisible = visible;
421 emit labelsVisibleChanged(visible);
421 emit labelsVisibleChanged(visible);
422 }
422 }
423
423
424 qreal QBarSeriesPrivate::min()
424 qreal QBarSeriesPrivate::min()
425 {
425 {
426 if (m_barSets.count() <= 0) {
426 if (m_barSets.count() <= 0) {
427 return 0;
427 return 0;
428 }
428 }
429 qreal min = INT_MAX;
429 qreal min = INT_MAX;
430
430
431 for (int i = 0; i < m_barSets.count(); i++) {
431 for (int i = 0; i < m_barSets.count(); i++) {
432 int categoryCount = m_barSets.at(i)->count();
432 int categoryCount = m_barSets.at(i)->count();
433 for (int j = 0; j < categoryCount; j++) {
433 for (int j = 0; j < categoryCount; j++) {
434 qreal temp = m_barSets.at(i)->at(j).y();
434 qreal temp = m_barSets.at(i)->at(j).y();
435 if (temp < min)
435 if (temp < min)
436 min = temp;
436 min = temp;
437 }
437 }
438 }
438 }
439 return min;
439 return min;
440 }
440 }
441
441
442 qreal QBarSeriesPrivate::max()
442 qreal QBarSeriesPrivate::max()
443 {
443 {
444 if (m_barSets.count() <= 0) {
444 if (m_barSets.count() <= 0) {
445 return 0;
445 return 0;
446 }
446 }
447 qreal max = INT_MIN;
447 qreal max = INT_MIN;
448
448
449 for (int i = 0; i < m_barSets.count(); i++) {
449 for (int i = 0; i < m_barSets.count(); i++) {
450 int categoryCount = m_barSets.at(i)->count();
450 int categoryCount = m_barSets.at(i)->count();
451 for (int j = 0; j < categoryCount; j++) {
451 for (int j = 0; j < categoryCount; j++) {
452 qreal temp = m_barSets.at(i)->at(j).y();
452 qreal temp = m_barSets.at(i)->at(j).y();
453 if (temp > max)
453 if (temp > max)
454 max = temp;
454 max = temp;
455 }
455 }
456 }
456 }
457
457
458 return max;
458 return max;
459 }
459 }
460
460
461 qreal QBarSeriesPrivate::valueAt(int set, int category)
461 qreal QBarSeriesPrivate::valueAt(int set, int category)
462 {
462 {
463 if ((set < 0) || (set >= m_barSets.count())) {
463 if ((set < 0) || (set >= m_barSets.count())) {
464 // No set, no value.
464 // No set, no value.
465 return 0;
465 return 0;
466 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
466 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
467 // No category, no value.
467 // No category, no value.
468 return 0;
468 return 0;
469 }
469 }
470
470
471 return m_barSets.at(set)->at(category).y();
471 return m_barSets.at(set)->at(category).y();
472 }
472 }
473
473
474 qreal QBarSeriesPrivate::percentageAt(int set, int category)
474 qreal QBarSeriesPrivate::percentageAt(int set, int category)
475 {
475 {
476 if ((set < 0) || (set >= m_barSets.count())) {
476 if ((set < 0) || (set >= m_barSets.count())) {
477 // No set, no value.
477 // No set, no value.
478 return 0;
478 return 0;
479 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
479 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
480 // No category, no value.
480 // No category, no value.
481 return 0;
481 return 0;
482 }
482 }
483
483
484 qreal value = m_barSets.at(set)->at(category).y();
484 qreal value = m_barSets.at(set)->at(category).y();
485 qreal sum = categorySum(category);
485 qreal sum = categorySum(category);
486 if ( qFuzzyIsNull(sum) ) {
486 if ( qFuzzyIsNull(sum) ) {
487 return 0;
487 return 0;
488 }
488 }
489
489
490 return value / sum;
490 return value / sum;
491 }
491 }
492
492
493 qreal QBarSeriesPrivate::categorySum(int category)
493 qreal QBarSeriesPrivate::categorySum(int category)
494 {
494 {
495 qreal sum(0);
495 qreal sum(0);
496 int count = m_barSets.count(); // Count sets
496 int count = m_barSets.count(); // Count sets
497 for (int set = 0; set < count; set++) {
497 for (int set = 0; set < count; set++) {
498 if (category < m_barSets.at(set)->count())
498 if (category < m_barSets.at(set)->count())
499 sum += m_barSets.at(set)->at(category).y();
499 sum += m_barSets.at(set)->at(category).y();
500 }
500 }
501 return sum;
501 return sum;
502 }
502 }
503
503
504 qreal QBarSeriesPrivate::absoluteCategorySum(int category)
504 qreal QBarSeriesPrivate::absoluteCategorySum(int category)
505 {
505 {
506 qreal sum(0);
506 qreal sum(0);
507 int count = m_barSets.count(); // Count sets
507 int count = m_barSets.count(); // Count sets
508 for (int set = 0; set < count; set++) {
508 for (int set = 0; set < count; set++) {
509 if (category < m_barSets.at(set)->count())
509 if (category < m_barSets.at(set)->count())
510 sum += qAbs(m_barSets.at(set)->at(category).y());
510 sum += qAbs(m_barSets.at(set)->at(category).y());
511 }
511 }
512 return sum;
512 return sum;
513 }
513 }
514
514
515 qreal QBarSeriesPrivate::maxCategorySum()
515 qreal QBarSeriesPrivate::maxCategorySum()
516 {
516 {
517 qreal max = INT_MIN;
517 qreal max = INT_MIN;
518 int count = categoryCount();
518 int count = categoryCount();
519 for (int i = 0; i < count; i++) {
519 for (int i = 0; i < count; i++) {
520 qreal sum = categorySum(i);
520 qreal sum = categorySum(i);
521 if (sum > max)
521 if (sum > max)
522 max = sum;
522 max = sum;
523 }
523 }
524 return max;
524 return max;
525 }
525 }
526
526
527 qreal QBarSeriesPrivate::minX()
527 qreal QBarSeriesPrivate::minX()
528 {
528 {
529 if (m_barSets.count() <= 0) {
529 if (m_barSets.count() <= 0) {
530 return 0;
530 return 0;
531 }
531 }
532 qreal min = INT_MAX;
532 qreal min = INT_MAX;
533
533
534 for (int i = 0; i < m_barSets.count(); i++) {
534 for (int i = 0; i < m_barSets.count(); i++) {
535 int categoryCount = m_barSets.at(i)->count();
535 int categoryCount = m_barSets.at(i)->count();
536 for (int j = 0; j < categoryCount; j++) {
536 for (int j = 0; j < categoryCount; j++) {
537 qreal temp = m_barSets.at(i)->at(j).x();
537 qreal temp = m_barSets.at(i)->at(j).x();
538 if (temp < min)
538 if (temp < min)
539 min = temp;
539 min = temp;
540 }
540 }
541 }
541 }
542 return min;
542 return min;
543 }
543 }
544
544
545 qreal QBarSeriesPrivate::maxX()
545 qreal QBarSeriesPrivate::maxX()
546 {
546 {
547 if (m_barSets.count() <= 0) {
547 if (m_barSets.count() <= 0) {
548 return 0;
548 return 0;
549 }
549 }
550 qreal max = INT_MIN;
550 qreal max = INT_MIN;
551
551
552 for (int i = 0; i < m_barSets.count(); i++) {
552 for (int i = 0; i < m_barSets.count(); i++) {
553 int categoryCount = m_barSets.at(i)->count();
553 int categoryCount = m_barSets.at(i)->count();
554 for (int j = 0; j < categoryCount; j++) {
554 for (int j = 0; j < categoryCount; j++) {
555 qreal temp = m_barSets.at(i)->at(j).x();
555 qreal temp = m_barSets.at(i)->at(j).x();
556 if (temp > max)
556 if (temp > max)
557 max = temp;
557 max = temp;
558 }
558 }
559 }
559 }
560
560
561 return max;
561 return max;
562 }
562 }
563
563
564
564
565 void QBarSeriesPrivate::scaleDomain(Domain& domain)
565 void QBarSeriesPrivate::scaleDomain(Domain& domain)
566 {
566 {
567 qreal minX(domain.minX());
567 qreal minX(domain.minX());
568 qreal minY(domain.minY());
568 qreal minY(domain.minY());
569 qreal maxX(domain.maxX());
569 qreal maxX(domain.maxX());
570 qreal maxY(domain.maxY());
570 qreal maxY(domain.maxY());
571 int tickXCount(domain.tickXCount());
571 int tickXCount(domain.tickXCount());
572 int tickYCount(domain.tickYCount());
572 int tickYCount(domain.tickYCount());
573
573
574 qreal seriesMinX = this->minX();
574 qreal seriesMinX = this->minX();
575 qreal seriesMaxX = this->maxX();
575 qreal seriesMaxX = this->maxX();
576 qreal y = max();
576 qreal y = max();
577 minX = qMin(minX, seriesMinX - 0.5);
577 minX = qMin(minX, seriesMinX - 0.5);
578 minY = qMin(minY, y);
578 minY = qMin(minY, y);
579 maxX = qMax(maxX, seriesMaxX + 0.5);
579 maxX = qMax(maxX, seriesMaxX + 0.5);
580 maxY = qMax(maxY, y);
580 maxY = qMax(maxY, y);
581 tickXCount = categoryCount()+1;
581 tickXCount = categoryCount()+1;
582
582
583 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
583 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
584 }
584 }
585
585
586 Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
586 Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
587 {
587 {
588 Q_Q(QBarSeries);
588 Q_Q(QBarSeries);
589
589
590 BarChartItem* bar = new BarChartItem(q,presenter);
590 BarChartItem* bar = new BarChartItem(q,presenter);
591 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
591 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
592 presenter->animator()->addAnimation(bar);
592 presenter->animator()->addAnimation(bar);
593 }
593 }
594 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
594 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
595 return bar;
595 return bar;
596
596
597 }
597 }
598
598
599 QList<LegendMarker*> QBarSeriesPrivate::createLegendMarker(QLegend* legend)
599 QList<LegendMarker*> QBarSeriesPrivate::createLegendMarker(QLegend* legend)
600 {
600 {
601 Q_Q(QBarSeries);
601 Q_Q(QBarSeries);
602 QList<LegendMarker*> markers;
602 QList<LegendMarker*> markers;
603 foreach(QBarSet* set, q->barSets()) {
603 foreach(QBarSet* set, q->barSets()) {
604 BarLegendMarker* marker = new BarLegendMarker(q,set,legend);
604 BarLegendMarker* marker = new BarLegendMarker(q,set,legend);
605 markers << marker;
605 markers << marker;
606 }
606 }
607
607
608 return markers;
608 return markers;
609 }
609 }
610
610
611 QAbstractAxis* QBarSeriesPrivate::createAxisX()
611 QAbstractAxis* QBarSeriesPrivate::createAxisX(QObject* parent)
612 {
612 {
613 // TODO: parent?
613 return new QValuesAxis(parent);
614 return new QValuesAxis(this);
615 }
614 }
616
615
617 QAbstractAxis* QBarSeriesPrivate::createAxisY()
616 QAbstractAxis* QBarSeriesPrivate::createAxisY(QObject* parent)
618 {
617 {
619 // TODO: parent?
618 return new QValuesAxis(parent);
620 return new QValuesAxis(this);
621 }
619 }
622
620
623 bool QBarSeriesPrivate::append(QBarSet *set)
621 bool QBarSeriesPrivate::append(QBarSet *set)
624 {
622 {
625 Q_Q(QBarSeries);
623 Q_Q(QBarSeries);
626 if ((m_barSets.contains(set)) || (set == 0)) {
624 if ((m_barSets.contains(set)) || (set == 0)) {
627 // Fail if set is already in list or set is null.
625 // Fail if set is already in list or set is null.
628 return false;
626 return false;
629 }
627 }
630 m_barSets.append(set);
628 m_barSets.append(set);
631 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
629 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
632 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
630 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
633 emit restructuredBars(); // this notifies barchartitem
631 emit restructuredBars(); // this notifies barchartitem
634 if (m_dataset) {
632 if (m_dataset) {
635 m_dataset->updateSeries(q); // this notifies legend
633 m_dataset->updateSeries(q); // this notifies legend
636 }
634 }
637 return true;
635 return true;
638 }
636 }
639
637
640 bool QBarSeriesPrivate::remove(QBarSet *set)
638 bool QBarSeriesPrivate::remove(QBarSet *set)
641 {
639 {
642 Q_Q(QBarSeries);
640 Q_Q(QBarSeries);
643 if (!m_barSets.contains(set)) {
641 if (!m_barSets.contains(set)) {
644 // Fail if set is not in list
642 // Fail if set is not in list
645 return false;
643 return false;
646 }
644 }
647 m_barSets.removeOne(set);
645 m_barSets.removeOne(set);
648 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
646 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
649 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
647 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
650 emit restructuredBars(); // this notifies barchartitem
648 emit restructuredBars(); // this notifies barchartitem
651 if (m_dataset) {
649 if (m_dataset) {
652 m_dataset->updateSeries(q); // this notifies legend
650 m_dataset->updateSeries(q); // this notifies legend
653 }
651 }
654 return true;
652 return true;
655 }
653 }
656
654
657 bool QBarSeriesPrivate::append(QList<QBarSet* > sets)
655 bool QBarSeriesPrivate::append(QList<QBarSet* > sets)
658 {
656 {
659 Q_Q(QBarSeries);
657 Q_Q(QBarSeries);
660 foreach (QBarSet* set, sets) {
658 foreach (QBarSet* set, sets) {
661 if ((set == 0) || (m_barSets.contains(set))) {
659 if ((set == 0) || (m_barSets.contains(set))) {
662 // Fail if any of the sets is null or is already appended.
660 // Fail if any of the sets is null or is already appended.
663 return false;
661 return false;
664 }
662 }
665 if (sets.count(set) != 1) {
663 if (sets.count(set) != 1) {
666 // Also fail if same set is more than once in given list.
664 // Also fail if same set is more than once in given list.
667 return false;
665 return false;
668 }
666 }
669 }
667 }
670
668
671 foreach (QBarSet* set, sets) {
669 foreach (QBarSet* set, sets) {
672 m_barSets.append(set);
670 m_barSets.append(set);
673 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
671 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
674 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
672 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
675 }
673 }
676 emit restructuredBars(); // this notifies barchartitem
674 emit restructuredBars(); // this notifies barchartitem
677 if (m_dataset) {
675 if (m_dataset) {
678 m_dataset->updateSeries(q); // this notifies legend
676 m_dataset->updateSeries(q); // this notifies legend
679 }
677 }
680 return true;
678 return true;
681 }
679 }
682
680
683 bool QBarSeriesPrivate::remove(QList<QBarSet* > sets)
681 bool QBarSeriesPrivate::remove(QList<QBarSet* > sets)
684 {
682 {
685 Q_Q(QBarSeries);
683 Q_Q(QBarSeries);
686 if (sets.count() == 0) {
684 if (sets.count() == 0) {
687 return false;
685 return false;
688 }
686 }
689 foreach (QBarSet* set, sets) {
687 foreach (QBarSet* set, sets) {
690 if ((set == 0) || (!m_barSets.contains(set))) {
688 if ((set == 0) || (!m_barSets.contains(set))) {
691 // Fail if any of the sets is null or is not in series
689 // Fail if any of the sets is null or is not in series
692 return false;
690 return false;
693 }
691 }
694 if (sets.count(set) != 1) {
692 if (sets.count(set) != 1) {
695 // Also fail if same set is more than once in given list.
693 // Also fail if same set is more than once in given list.
696 return false;
694 return false;
697 }
695 }
698 }
696 }
699
697
700 foreach (QBarSet* set, sets) {
698 foreach (QBarSet* set, sets) {
701 m_barSets.removeOne(set);
699 m_barSets.removeOne(set);
702 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
700 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
703 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
701 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
704 }
702 }
705
703
706 emit restructuredBars(); // this notifies barchartitem
704 emit restructuredBars(); // this notifies barchartitem
707 if (m_dataset) {
705 if (m_dataset) {
708 m_dataset->updateSeries(q); // this notifies legend
706 m_dataset->updateSeries(q); // this notifies legend
709 }
707 }
710 return true;
708 return true;
711 }
709 }
712
710
713 bool QBarSeriesPrivate::insert(int index, QBarSet *set)
711 bool QBarSeriesPrivate::insert(int index, QBarSet *set)
714 {
712 {
715 Q_Q(QBarSeries);
713 Q_Q(QBarSeries);
716 if ((m_barSets.contains(set)) || (set == 0)) {
714 if ((m_barSets.contains(set)) || (set == 0)) {
717 // Fail if set is already in list or set is null.
715 // Fail if set is already in list or set is null.
718 return false;
716 return false;
719 }
717 }
720 m_barSets.insert(index, set);
718 m_barSets.insert(index, set);
721 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
719 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
722 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
720 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
723 emit restructuredBars(); // this notifies barchartitem
721 emit restructuredBars(); // this notifies barchartitem
724 if (m_dataset) {
722 if (m_dataset) {
725 m_dataset->updateSeries(q); // this notifies legend
723 m_dataset->updateSeries(q); // this notifies legend
726 }
724 }
727 return true;
725 return true;
728 }
726 }
729
727
730 #include "moc_qbarseries.cpp"
728 #include "moc_qbarseries.cpp"
731 #include "moc_qbarseries_p.cpp"
729 #include "moc_qbarseries_p.cpp"
732
730
733 QTCOMMERCIALCHART_END_NAMESPACE
731 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,97 +1,97
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef QBARSERIES_P_H
30 #ifndef QBARSERIES_P_H
31 #define QBARSERIES_P_H
31 #define QBARSERIES_P_H
32
32
33 #include "qbarseries.h"
33 #include "qbarseries.h"
34 #include "qabstractseries_p.h"
34 #include "qabstractseries_p.h"
35 #include <QStringList>
35 #include <QStringList>
36 #include <QAbstractSeries>
36 #include <QAbstractSeries>
37
37
38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
39
39
40 class QBarModelMapper;
40 class QBarModelMapper;
41
41
42 class QBarSeriesPrivate : public QAbstractSeriesPrivate
42 class QBarSeriesPrivate : public QAbstractSeriesPrivate
43 {
43 {
44 Q_OBJECT
44 Q_OBJECT
45 public:
45 public:
46 QBarSeriesPrivate(QBarSeries *parent);
46 QBarSeriesPrivate(QBarSeries *parent);
47 int categoryCount() const;
47 int categoryCount() const;
48
48
49 void setBarWidth(qreal width);
49 void setBarWidth(qreal width);
50 qreal barWidth() const;
50 qreal barWidth() const;
51
51
52 void setVisible(bool visible);
52 void setVisible(bool visible);
53 void setLabelsVisible(bool visible);
53 void setLabelsVisible(bool visible);
54
54
55 void scaleDomain(Domain& domain);
55 void scaleDomain(Domain& domain);
56 Chart* createGraphics(ChartPresenter* presenter);
56 Chart* createGraphics(ChartPresenter* presenter);
57 QList<LegendMarker*> createLegendMarker(QLegend* legend);
57 QList<LegendMarker*> createLegendMarker(QLegend* legend);
58
58
59 QAbstractAxis* createAxisX();
59 QAbstractAxis* createAxisX(QObject* parent = 0);
60 QAbstractAxis* createAxisY();
60 QAbstractAxis* createAxisY(QObject* parent = 0);
61
61
62 bool append(QBarSet *set);
62 bool append(QBarSet *set);
63 bool remove(QBarSet *set);
63 bool remove(QBarSet *set);
64 bool append(QList<QBarSet* > sets);
64 bool append(QList<QBarSet* > sets);
65 bool remove(QList<QBarSet* > sets);
65 bool remove(QList<QBarSet* > sets);
66 bool insert(int index, QBarSet *set);
66 bool insert(int index, QBarSet *set);
67
67
68 QBarSet* barsetAt(int index);
68 QBarSet* barsetAt(int index);
69 qreal min();
69 qreal min();
70 qreal max();
70 qreal max();
71 qreal valueAt(int set, int category);
71 qreal valueAt(int set, int category);
72 qreal percentageAt(int set, int category);
72 qreal percentageAt(int set, int category);
73 qreal categorySum(int category);
73 qreal categorySum(int category);
74 qreal absoluteCategorySum(int category);
74 qreal absoluteCategorySum(int category);
75 qreal maxCategorySum();
75 qreal maxCategorySum();
76 qreal minX();
76 qreal minX();
77 qreal maxX();
77 qreal maxX();
78
78
79 Q_SIGNALS:
79 Q_SIGNALS:
80 void clicked(QBarSet *barset, int index);
80 void clicked(QBarSet *barset, int index);
81 void updatedBars();
81 void updatedBars();
82 void restructuredBars();
82 void restructuredBars();
83 void labelsVisibleChanged(bool visible);
83 void labelsVisibleChanged(bool visible);
84
84
85 protected:
85 protected:
86 QList<QBarSet *> m_barSets;
86 QList<QBarSet *> m_barSets;
87 qreal m_barWidth;
87 qreal m_barWidth;
88 bool m_labelsVisible;
88 bool m_labelsVisible;
89 bool m_visible;
89 bool m_visible;
90
90
91 private:
91 private:
92 Q_DECLARE_PUBLIC(QBarSeries)
92 Q_DECLARE_PUBLIC(QBarSeries)
93 };
93 };
94
94
95 QTCOMMERCIALCHART_END_NAMESPACE
95 QTCOMMERCIALCHART_END_NAMESPACE
96
96
97 #endif // QBARSERIESPRIVATE_P_H
97 #endif // QBARSERIESPRIVATE_P_H
@@ -1,304 +1,238
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "chartdataset_p.h"
21 #include "chartdataset_p.h"
22 #include "qchart.h"
22 #include "qchart.h"
23 #include "qvaluesaxis.h"
23 #include "qvaluesaxis.h"
24 #include "qvaluesaxis_p.h"
24 #include "qvaluesaxis_p.h"
25 #include "qabstractseries_p.h"
25 #include "qabstractseries_p.h"
26 #include "qbarseries.h"
26 #include "qbarseries.h"
27 #include "qstackedbarseries.h"
27 #include "qstackedbarseries.h"
28 #include "qpercentbarseries.h"
28 #include "qpercentbarseries.h"
29 #include "qpieseries.h"
29 #include "qpieseries.h"
30
30
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32
32
33 ChartDataSet::ChartDataSet(QChart *parent):QObject(parent),
33 ChartDataSet::ChartDataSet(QChart *parent):QObject(parent),
34 m_axisX(new QValuesAxis(this)),
34 m_domainIndex(0)
35 m_axisY(new QValuesAxis(this)),
36 m_domainIndex(0),
37 m_axisXInitialized(false),
38 m_axisYInitialized(false)
39 {
35 {
40 //create main domain
36
41 Domain* domain = new Domain(m_axisY);
42 m_axisDomainMap.insert(m_axisY,domain);
43 QObject::connect(m_axisY->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool)));
44 QObject::connect(m_axisX->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool)));
45 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),m_axisY->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
46 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),m_axisX->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
47 }
37 }
48
38
49 ChartDataSet::~ChartDataSet()
39 ChartDataSet::~ChartDataSet()
50 {
40 {
51 removeAllSeries();
41 removeAllSeries();
52 }
42 }
53
43
54 void ChartDataSet::addSeries(QAbstractSeries* series)
44 void ChartDataSet::addSeries(QAbstractSeries* series)
55 {
45 {
56 QAbstractAxis* axis = m_seriesAxisXMap.value(series);
46 QAbstractAxis* axis = m_seriesAxisXMap.value(series);
57
47
58 if(axis) {
48 if(axis) {
59 qWarning() << "Can not add series. Series already on the chart";
49 qWarning() << "Can not add series. Series already on the chart";
60 return;
50 return;
61 }
51 }
62
52
63 QAbstractAxis* axisX = series->d_ptr->createAxisX();
53 QAbstractAxis* axisX = series->d_ptr->createAxisX(this);
64 QAbstractAxis* axisY = m_axisY ; //series->d_ptr->createAxisY();
54 QAbstractAxis* axisY = series->d_ptr->createAxisY(this);
65
55
66 series->setParent(this); // take ownership
56 series->setParent(this); // take ownership
67 //axisY->setParent(this); // take ownership
68
57
69 Domain* domain = m_axisDomainMap.value(axisY);
58 Domain* domain = new Domain(series);
70
59
71 if(!domain) {
60 if(axisX){
72 domain = new Domain(axisY);
61 QObject::connect(axisX->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool)));
62 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axisX->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
63 axisX->d_ptr->m_orientation=Qt::Horizontal;
64 emit axisAdded(axisX,domain);
65 m_seriesAxisYMap.insert(series,axisX);
66 }
67
68 if(axisY){
73 QObject::connect(axisY->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool)));
69 QObject::connect(axisY->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool)));
74 QObject::connect(axisX->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int)));
75 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axisY->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
70 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axisY->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
76 //initialize
71 axisY->d_ptr->m_orientation=Qt::Vertical;
77 m_axisDomainMap.insert(axisY,domain);
78 emit axisAdded(axisY,domain);
72 emit axisAdded(axisY,domain);
73 m_seriesAxisYMap.insert(series,axisY);
79 }
74 }
80
75
81 if(!m_axisXInitialized){
76 m_seriesDomainMap.insert(series,domain);
82 m_axisXInitialized=true;
83 // emit axisAdded(m_axisX,domain);
84 emit axisAdded(axisX,domain);
85 }
86
87 if(!m_axisYInitialized && axisY==m_axisY){
88 m_axisYInitialized=true;
89 emit axisAdded(m_axisY,domain);
90 }
91
77
92 series->d_ptr->scaleDomain(*domain);
78 series->d_ptr->scaleDomain(*domain);
93
79
94 if (series->type()== QAbstractSeries::SeriesTypePie && m_seriesAxisXMap.count() == 0) {
95 axisX->hide();
96 axisY->hide();
97 }
98
99 m_seriesAxisXMap.insert(series,axisY);
100
101 QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap);
80 QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap);
102
81
103 int key=0;
82 int key=0;
104 while (i.hasNext()) {
83 while (i.hasNext()) {
105 i.next();
84 i.next();
106 if(i.key()!=key) {
85 if(i.key()!=key) {
107 break;
86 break;
108 }
87 }
109 key++;
88 key++;
110 }
89 }
111
90
112 m_indexSeriesMap.insert(key,series);
91 m_indexSeriesMap.insert(key,series);
113
92
114 series->d_ptr->m_chart = qobject_cast<QChart*>(parent());
93 series->d_ptr->m_chart = qobject_cast<QChart*>(parent());
115 series->d_ptr->m_dataset = this;
94 series->d_ptr->m_dataset = this;
116
95
117 emit seriesAdded(series,domain);
96 emit seriesAdded(series,domain);
118
97
119 }
98 }
120
99
121 QAbstractAxis* ChartDataSet::removeSeries(QAbstractSeries* series)
100 void ChartDataSet::removeSeries(QAbstractSeries* series)
122 {
101 {
123 QAbstractAxis* axis = m_seriesAxisXMap.value(series);
102 Domain* domain = m_seriesDomainMap.take(series);
124
103
125 if(!axis){
104 if(!domain) {
126 qWarning()<<"Can not remove series. Series not found on the chart.";
105 qWarning()<<"Can not remove series. Series not found on the chart.";
127 return 0;
106 }
107 else {
108 delete domain;
109 domain =0;
128 }
110 }
129
111
130 emit seriesRemoved(series);
112 emit seriesRemoved(series);
131
113
132 m_seriesAxisXMap.remove(series);
114 QAbstractAxis* axisX = m_seriesAxisXMap.take(series);
115 QAbstractAxis* axisY = m_seriesAxisYMap.take(series);
116
133 int key = seriesIndex(series);
117 int key = seriesIndex(series);
134 Q_ASSERT(key!=-1);
118 Q_ASSERT(key!=-1);
135
119
136 m_indexSeriesMap.remove(key);
120 m_indexSeriesMap.remove(key);
137
121
138 series->setParent(0);
122 series->setParent(0);
139 series->d_ptr->m_chart = 0;
123 series->d_ptr->m_chart = 0;
140 series->d_ptr->m_dataset = 0;
124 series->d_ptr->m_dataset = 0;
141
125
142 QList<QAbstractAxis*> axes = m_seriesAxisXMap.values();
126 QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values();
127 QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values();
143
128
144 int i = axes.indexOf(axis);
129 int x = axesX.indexOf(axisX);
130 int y = axesY.indexOf(axisY);
145
131
146 if(i==-1){
132 if(x==-1) {
147 Domain* domain = m_axisDomainMap.take(axis);
133 emit axisRemoved(axisX);
148 emit axisRemoved(axis);
134 delete axisX;
149 if(axis!=m_axisY){
150 axis->setParent(0);
151 delete domain;
152 }else{
153 m_axisYInitialized=false;
154 m_axisDomainMap.insert(m_axisY,domain);
155 }
156 }
135 }
157
136
158 if(m_seriesAxisXMap.values().size()==0)
137 if(y==-1) {
159 {
138 emit axisRemoved(axisY);
160 m_axisXInitialized=false;
139 delete axisY;
161 emit axisRemoved(m_axisX);
162 }
140 }
163
164 return axis;
165 }
141 }
166
142
167 void ChartDataSet::removeAllSeries()
143 void ChartDataSet::removeAllSeries()
168 {
144 {
169 QList<QAbstractSeries*> series = m_seriesAxisXMap.keys();
145 QList<QAbstractSeries*> series = m_seriesDomainMap.keys();
170 QList<QAbstractAxis*> axes;
171 foreach(QAbstractSeries *s , series) {
146 foreach(QAbstractSeries *s , series) {
172 QAbstractAxis* axis = removeSeries(s);
147 removeSeries(s);
173 if(axis==m_axisY) continue;
174 int i = axes.indexOf(axis);
175 if(i==-1){
176 axes<<axis;
177 }
178 }
148 }
179
149
180 Q_ASSERT(m_seriesAxisXMap.count()==0);
150 Q_ASSERT(m_seriesAxisXMap.count()==0);
181 Q_ASSERT(m_axisDomainMap.count()==1);
151 Q_ASSERT(m_seriesAxisXMap.count()==0);
152 Q_ASSERT(m_seriesDomainMap.count()==0);
182
153
183 qDeleteAll(series);
154 qDeleteAll(series);
184 qDeleteAll(axes);
185 }
155 }
186
156
187 void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size)
157 void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size)
188 {
158 {
189 QMapIterator<QAbstractAxis*, Domain*> i(m_axisDomainMap);
159 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
190 //main domain has to be the last one;
191 Domain *domain = m_axisDomainMap.value(m_axisY);
192 Q_ASSERT(domain);
193 while (i.hasNext()) {
160 while (i.hasNext()) {
194 i.next();
161 i.next();
195 if(i.value()==domain) continue;
196 i.value()->zoomIn(rect,size);
162 i.value()->zoomIn(rect,size);
197 }
163 }
198 domain->zoomIn(rect,size);
199 }
164 }
200
165
201 void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size)
166 void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size)
202 {
167 {
203 QMapIterator<QAbstractAxis*, Domain*> i(m_axisDomainMap);
168 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
204 //main domain has to be the last one;
205 Domain *domain = m_axisDomainMap.value(m_axisY);
206 Q_ASSERT(domain);
207 while (i.hasNext()) {
169 while (i.hasNext()) {
208 i.next();
170 i.next();
209 if(i.value()==domain) continue;
210 i.value()->zoomOut(rect,size);
171 i.value()->zoomOut(rect,size);
211 }
172 }
212 domain->zoomOut(rect,size);
213 }
173 }
214
174
215 int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type)
175 int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type)
216 {
176 {
217 int count=0;
177 int count=0;
218 QMapIterator<QAbstractSeries*, QAbstractAxis*> i(m_seriesAxisXMap);
178 QMapIterator<QAbstractSeries*, QAbstractAxis*> i(m_seriesAxisXMap);
219 while (i.hasNext()) {
179 while (i.hasNext()) {
220 i.next();
180 i.next();
221 if(i.key()->type()==type) count++;
181 if(i.key()->type()==type) count++;
222 }
182 }
223 return count;
183 return count;
224 }
184 }
225
185
226 int ChartDataSet::seriesIndex(QAbstractSeries *series)
186 int ChartDataSet::seriesIndex(QAbstractSeries *series)
227 {
187 {
228 QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap);
188 QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap);
229 while (i.hasNext()) {
189 while (i.hasNext()) {
230 i.next();
190 i.next();
231 if (i.value() == series)
191 if (i.value() == series)
232 return i.key();
192 return i.key();
233 }
193 }
234 return -1;
194 return -1;
235 }
195 }
236
196
237 QAbstractAxis* ChartDataSet::axisX(QAbstractSeries *series) const
197 QAbstractAxis* ChartDataSet::axisX(QAbstractSeries *series) const
238 {
198 {
239 qDebug() << "axisX";
240 if (series == 0) return m_axisX;
241 return m_seriesAxisXMap.value(series);
199 return m_seriesAxisXMap.value(series);
242 }
200 }
243
201
244 QAbstractAxis* ChartDataSet::axisY(QAbstractSeries *series) const
202 QAbstractAxis* ChartDataSet::axisY(QAbstractSeries *series) const
245 {
203 {
246 if(series == 0) return m_axisY;
247 return m_seriesAxisYMap.value(series);
204 return m_seriesAxisYMap.value(series);
248 }
205 }
249
206
250 void ChartDataSet::setAxisX(QAbstractSeries *series, QAbstractAxis *axis)
207 void ChartDataSet::setAxisX(QAbstractSeries *series, QAbstractAxis *axis)
251 {
208 {
252 m_seriesAxisXMap.insert(series,axis);
209 m_seriesAxisXMap.insert(series,axis);
253 }
210 }
254
211
255 void ChartDataSet::setAxisY(QAbstractSeries *series, QAbstractAxis *axis)
212 void ChartDataSet::setAxisY(QAbstractSeries *series, QAbstractAxis *axis)
256 {
213 {
257 m_seriesAxisYMap.insert(series,axis);
214 m_seriesAxisYMap.insert(series,axis);
258 }
215 }
259
216
260 Domain* ChartDataSet::domain(QAbstractSeries *series) const
261 {
262 QAbstractAxis* axis = m_seriesAxisXMap.value(series);
263 if(axis){
264 return m_axisDomainMap.value(axis);
265 }else
266 return 0;
267 }
268
269 Domain* ChartDataSet::domain(QAbstractAxis* axis) const
270 {
271 if(!axis || axis==m_axisX) {
272 return m_axisDomainMap.value(m_axisY);
273 }
274 else {
275 return m_axisDomainMap.value(axis);
276 }
277 }
278
279 void ChartDataSet::scrollDomain(qreal dx,qreal dy,const QSizeF& size)
217 void ChartDataSet::scrollDomain(qreal dx,qreal dy,const QSizeF& size)
280 {
218 {
281 QMapIterator<QAbstractAxis*, Domain*> i( m_axisDomainMap);
219 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
282 //main domain has to be the last one;
283 Domain *domain = m_axisDomainMap.value(m_axisY);
284 while (i.hasNext()) {
220 while (i.hasNext()) {
285 i.next();
221 i.next();
286 if(i.value()==domain) continue;
287 i.value()->move(dx,dy,size);
222 i.value()->move(dx,dy,size);
288 }
223 }
289 domain->move(dx,dy,size);
290 }
224 }
291
225
292 QList<QAbstractSeries*> ChartDataSet::series() const
226 QList<QAbstractSeries*> ChartDataSet::series() const
293 {
227 {
294 return m_seriesAxisXMap.keys();
228 return m_seriesAxisXMap.keys();
295 }
229 }
296
230
297 void ChartDataSet::updateSeries(QAbstractSeries *series)
231 void ChartDataSet::updateSeries(QAbstractSeries *series)
298 {
232 {
299 emit seriesUpdated(series);
233 emit seriesUpdated(series);
300 }
234 }
301
235
302 #include "moc_chartdataset_p.cpp"
236 #include "moc_chartdataset_p.cpp"
303
237
304 QTCOMMERCIALCHART_END_NAMESPACE
238 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,97 +1,90
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef CHARTDATASET_P_H
30 #ifndef CHARTDATASET_P_H
31 #define CHARTDATASET_P_H
31 #define CHARTDATASET_P_H
32
32
33 #include "qabstractseries.h"
33 #include "qabstractseries.h"
34 #include "domain_p.h"
34 #include "domain_p.h"
35 #include <QVector>
35 #include <QVector>
36
36
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38
38
39 class QAbstractAxis;
39 class QAbstractAxis;
40
40
41 class QTCOMMERCIALCHART_AUTOTEST_EXPORT ChartDataSet : public QObject
41 class QTCOMMERCIALCHART_AUTOTEST_EXPORT ChartDataSet : public QObject
42 {
42 {
43 Q_OBJECT
43 Q_OBJECT
44 public:
44 public:
45 ChartDataSet(QChart* parent=0);
45 ChartDataSet(QChart* parent=0);
46 virtual ~ChartDataSet();
46 virtual ~ChartDataSet();
47
47
48 void addSeries(QAbstractSeries* series);
48 void addSeries(QAbstractSeries* series);
49 QAbstractAxis* removeSeries(QAbstractSeries* series);
49 void removeSeries(QAbstractSeries* series);
50 void removeAllSeries();
50 void removeAllSeries();
51 void updateSeries(QAbstractSeries* series);
51 void updateSeries(QAbstractSeries* series);
52
52
53 void zoomInDomain(const QRectF& rect, const QSizeF& size);
53 void zoomInDomain(const QRectF& rect, const QSizeF& size);
54 void zoomOutDomain(const QRectF& rect, const QSizeF& size);
54 void zoomOutDomain(const QRectF& rect, const QSizeF& size);
55 void scrollDomain(qreal dx,qreal dy,const QSizeF& size);
55 void scrollDomain(qreal dx,qreal dy,const QSizeF& size);
56
56
57 int seriesCount(QAbstractSeries::SeriesType type);
57 int seriesCount(QAbstractSeries::SeriesType type);
58 int seriesIndex(QAbstractSeries *series);
58 int seriesIndex(QAbstractSeries *series);
59
59
60 Domain* domain(QAbstractSeries* series) const;
61 Domain* domain(QAbstractAxis* axis) const;
62
63 QAbstractAxis* axisX(QAbstractSeries *series) const;
60 QAbstractAxis* axisX(QAbstractSeries *series) const;
64 QAbstractAxis* axisY(QAbstractSeries *series) const;
61 QAbstractAxis* axisY(QAbstractSeries *series) const;
65
62
66 void setAxisX(QAbstractSeries *series, QAbstractAxis *axis);
63 void setAxisX(QAbstractSeries *series, QAbstractAxis *axis);
67 void setAxisY(QAbstractSeries *series, QAbstractAxis *axis);
64 void setAxisY(QAbstractSeries *series, QAbstractAxis *axis);
68
65
69 QList<QAbstractSeries*> series() const;
66 QList<QAbstractSeries*> series() const;
70
67
71 Q_SIGNALS:
68 Q_SIGNALS:
72 void seriesAdded(QAbstractSeries* series, Domain* domain);
69 void seriesAdded(QAbstractSeries* series, Domain* domain);
73 void seriesRemoved(QAbstractSeries* series);
70 void seriesRemoved(QAbstractSeries* series);
74 void seriesUpdated(QAbstractSeries* series);
71 void seriesUpdated(QAbstractSeries* series);
75 void axisAdded(QAbstractAxis* axis,Domain* domain);
72 void axisAdded(QAbstractAxis* axis,Domain* domain);
76 void axisRemoved(QAbstractAxis* axis);
73 void axisRemoved(QAbstractAxis* axis);
77
74
78 private:
75 private:
79 QStringList createLabels(QAbstractAxis* axis,qreal min, qreal max);
76 QStringList createLabels(QAbstractAxis* axis,qreal min, qreal max);
80 void calculateDomain(QAbstractSeries* series,Domain* domain);
77 void calculateDomain(QAbstractSeries* series,Domain* domain);
81
78
82 private:
79 private:
83 QMap<QAbstractSeries*, QAbstractAxis*> m_seriesAxisXMap;
80 QMap<QAbstractSeries*, QAbstractAxis*> m_seriesAxisXMap;
84 QMap<QAbstractSeries*, QAbstractAxis*> m_seriesAxisYMap;
81 QMap<QAbstractSeries*, QAbstractAxis*> m_seriesAxisYMap;
85 QMap<QAbstractAxis*, Domain*> m_axisDomainMap;
82 QMap<QAbstractSeries*, Domain*> m_seriesDomainMap;
86 QMap<int, QAbstractSeries*> m_indexSeriesMap;
83 QMap<int, QAbstractSeries*> m_indexSeriesMap;
87 QAbstractAxis* m_axisX;
88 QAbstractAxis* m_axisY;
89
90 int m_domainIndex;
84 int m_domainIndex;
91 bool m_axisXInitialized;
85
92 bool m_axisYInitialized;
93 };
86 };
94
87
95 QTCOMMERCIALCHART_END_NAMESPACE
88 QTCOMMERCIALCHART_END_NAMESPACE
96
89
97 #endif /* CHARTENGINE_P_H_ */
90 #endif /* CHARTENGINE_P_H_ */
@@ -1,418 +1,420
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20 #include "chartpresenter_p.h"
20 #include "chartpresenter_p.h"
21 #include "qchart.h"
21 #include "qchart.h"
22 #include "qchart_p.h"
22 #include "qchart_p.h"
23 #include "qabstractaxis.h"
23 #include "qabstractaxis.h"
24 #include "qabstractaxis_p.h"
24 #include "chartdataset_p.h"
25 #include "chartdataset_p.h"
25 #include "charttheme_p.h"
26 #include "charttheme_p.h"
26 #include "chartanimator_p.h"
27 #include "chartanimator_p.h"
27 #include "chartanimation_p.h"
28 #include "chartanimation_p.h"
28 #include "qabstractseries_p.h"
29 #include "qabstractseries_p.h"
29 #include "qareaseries.h"
30 #include "qareaseries.h"
30 #include "chartaxis_p.h"
31 #include "chartaxis_p.h"
31 #include "chartaxisx_p.h"
32 #include "chartaxisx_p.h"
32 #include "chartaxisy_p.h"
33 #include "chartaxisy_p.h"
33 #include "areachartitem_p.h"
34 #include "areachartitem_p.h"
34 #include "chartbackground_p.h"
35 #include "chartbackground_p.h"
35 #include "chartlayout_p.h"
36 #include "chartlayout_p.h"
36 #include <QTimer>
37 #include <QTimer>
37
38
38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
39 QTCOMMERCIALCHART_BEGIN_NAMESPACE
39
40
40 ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart),
41 ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart),
41 m_chart(chart),
42 m_chart(chart),
42 m_animator(0),
43 m_animator(0),
43 m_dataset(dataset),
44 m_dataset(dataset),
44 m_chartTheme(0),
45 m_chartTheme(0),
45 m_options(QChart::NoAnimation),
46 m_options(QChart::NoAnimation),
46 m_state(ShowState),
47 m_state(ShowState),
47 m_layout(new ChartLayout(this)),
48 m_layout(new ChartLayout(this)),
48 m_backgroundItem(0),
49 m_backgroundItem(0),
49 m_titleItem(0)
50 m_titleItem(0)
50 {
51 {
51
52
52 }
53 }
53
54
54 ChartPresenter::~ChartPresenter()
55 ChartPresenter::~ChartPresenter()
55 {
56 {
56 delete m_chartTheme;
57 delete m_chartTheme;
57 }
58 }
58
59
59 void ChartPresenter::setGeometry(const QRectF& rect)
60 void ChartPresenter::setGeometry(const QRectF& rect)
60 {
61 {
61
62
62 Q_ASSERT(rect.isValid());
63 Q_ASSERT(rect.isValid());
63
64
64 if(m_rect!=rect) {
65 if(m_rect!=rect) {
65 m_rect=rect;
66 m_rect=rect;
66 emit geometryChanged(m_rect);
67 emit geometryChanged(m_rect);
67 }
68 }
68 }
69 }
69
70
70 void ChartPresenter::handleAxisAdded(QAbstractAxis* axis,Domain* domain)
71 void ChartPresenter::handleAxisAdded(QAbstractAxis* axis,Domain* domain)
71 {
72 {
72 ChartAxis* item;
73 ChartAxis* item = axis->d_ptr->createGraphics(this);
73
74 item->setDomain(domain);
74 if(axis == m_dataset->axisX(0)){
75 item = new ChartAxisX(axis,this);
76 }else{
77 item = new ChartAxisY(axis,this);
78 }
79
75
80 if(m_options.testFlag(QChart::GridAxisAnimations)){
76 if(m_options.testFlag(QChart::GridAxisAnimations)){
81 item->setAnimator(m_animator);
77 item->setAnimator(m_animator);
82 item->setAnimation(new AxisAnimation(item));
78 item->setAnimation(new AxisAnimation(item));
83 }
79 }
84
80
85 if(axis==m_dataset->axisX(0)){
81 if(item->axisType()==ChartAxis::X_AXIS){
86 m_chartTheme->decorate(axis,true);
82 m_chartTheme->decorate(axis,true);
87 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int)));
83 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int)));
88 //initialize
84 //initialize
89 item->handleRangeChanged(domain->minX(),domain->maxX(),domain->tickXCount());
85 item->handleRangeChanged(domain->minX(),domain->maxX(),domain->tickXCount());
90
86
91 }
87 }
92 else{
88 else{
93 m_chartTheme->decorate(axis,false);
89 m_chartTheme->decorate(axis,false);
94 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int)));
90 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int)));
95 //initialize
91 //initialize
96 item->handleRangeChanged(domain->minY(),domain->maxY(),domain->tickYCount());
92 item->handleRangeChanged(domain->minY(),domain->maxY(),domain->tickYCount());
97 }
93 }
98
94
99 QObject::connect(this,SIGNAL(geometryChanged(QRectF)),item,SLOT(handleGeometryChanged(QRectF)));
95 QObject::connect(this,SIGNAL(geometryChanged(QRectF)),item,SLOT(handleGeometryChanged(QRectF)));
100 //initialize
96 //initialize
101 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
97 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
102 m_axisItems.insert(axis, item);
98 m_axisItems.insert(axis, item);
103 }
99 }
104
100
105 void ChartPresenter::handleAxisRemoved(QAbstractAxis* axis)
101 void ChartPresenter::handleAxisRemoved(QAbstractAxis* axis)
106 {
102 {
107 ChartAxis* item = m_axisItems.take(axis);
103 ChartAxis* item = m_axisItems.take(axis);
108 Q_ASSERT(item);
104 Q_ASSERT(item);
109 if(m_animator) m_animator->removeAnimation(item);
105 if(m_animator) m_animator->removeAnimation(item);
110 delete item;
106 delete item;
111 }
107 }
112
108
113
109
114 void ChartPresenter::handleSeriesAdded(QAbstractSeries* series,Domain* domain)
110 void ChartPresenter::handleSeriesAdded(QAbstractSeries* series,Domain* domain)
115 {
111 {
116 Chart *item = series->d_ptr->createGraphics(this);
112 Chart *item = series->d_ptr->createGraphics(this);
117 Q_ASSERT(item);
113 Q_ASSERT(item);
114 item->setDomain(domain);
115
118 QObject::connect(this,SIGNAL(geometryChanged(QRectF)),item,SLOT(handleGeometryChanged(QRectF)));
116 QObject::connect(this,SIGNAL(geometryChanged(QRectF)),item,SLOT(handleGeometryChanged(QRectF)));
119 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),item,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
117 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),item,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
120 //initialize
118 //initialize
121 item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY());
119 item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY());
122 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
120 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
123 m_chartItems.insert(series,item);
121 m_chartItems.insert(series,item);
124 }
122 }
125
123
126 void ChartPresenter::handleSeriesRemoved(QAbstractSeries* series)
124 void ChartPresenter::handleSeriesRemoved(QAbstractSeries* series)
127 {
125 {
128 Chart* item = m_chartItems.take(series);
126 Chart* item = m_chartItems.take(series);
129 Q_ASSERT(item);
127 Q_ASSERT(item);
130 if(m_animator) {
128 if(m_animator) {
131 //small hack to handle area animations
129 //small hack to handle area animations
132 if(series->type() == QAbstractSeries::SeriesTypeArea){
130 if(series->type() == QAbstractSeries::SeriesTypeArea){
133 QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series);
131 QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series);
134 AreaChartItem* area = static_cast<AreaChartItem*>(item);
132 AreaChartItem* area = static_cast<AreaChartItem*>(item);
135 m_animator->removeAnimation(area->upperLineItem());
133 m_animator->removeAnimation(area->upperLineItem());
136 if(areaSeries->lowerSeries()) m_animator->removeAnimation(area->lowerLineItem());
134 if(areaSeries->lowerSeries()) m_animator->removeAnimation(area->lowerLineItem());
137 }else
135 }else
138 m_animator->removeAnimation(item);
136 m_animator->removeAnimation(item);
139 }
137 }
140 delete item;
138 delete item;
141 }
139 }
142
140
143 void ChartPresenter::setTheme(QChart::ChartTheme theme,bool force)
141 void ChartPresenter::setTheme(QChart::ChartTheme theme,bool force)
144 {
142 {
145 if(m_chartTheme && m_chartTheme->id() == theme) return;
143 if(m_chartTheme && m_chartTheme->id() == theme) return;
146 delete m_chartTheme;
144 delete m_chartTheme;
147 m_chartTheme = ChartTheme::createTheme(theme);
145 m_chartTheme = ChartTheme::createTheme(theme);
148 m_chartTheme->setForced(force);
146 m_chartTheme->setForced(force);
149 m_chartTheme->decorate(m_chart);
147 m_chartTheme->decorate(m_chart);
150 m_chartTheme->decorate(m_chart->legend());
148 m_chartTheme->decorate(m_chart->legend());
151 resetAllElements();
149 resetAllElements();
152
150
153 // We do not want "force" to stay on.
151 // We do not want "force" to stay on.
154 // Bar/pie are calling decorate when adding/removing slices/bars which means
152 // Bar/pie are calling decorate when adding/removing slices/bars which means
155 // that to preserve users colors "force" must not be on.
153 // that to preserve users colors "force" must not be on.
156 m_chartTheme->setForced(false);
154 m_chartTheme->setForced(false);
157 }
155 }
158
156
159 QChart::ChartTheme ChartPresenter::theme()
157 QChart::ChartTheme ChartPresenter::theme()
160 {
158 {
161 return m_chartTheme->id();
159 return m_chartTheme->id();
162 }
160 }
163
161
164 void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options)
162 void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options)
165 {
163 {
166 if(m_options!=options) {
164 if(m_options!=options) {
167
165
168 m_options=options;
166 m_options=options;
169
167
170 if(m_options!=QChart::NoAnimation && !m_animator) {
168 if(m_options!=QChart::NoAnimation && !m_animator) {
171 m_animator= new ChartAnimator(this);
169 m_animator= new ChartAnimator(this);
172 }
170 }
173 resetAllElements();
171 resetAllElements();
174 }
172 }
175
173
176 }
174 }
177
175
178 void ChartPresenter::resetAllElements()
176 void ChartPresenter::resetAllElements()
179 {
177 {
180 QList<QAbstractAxis*> axisList = m_axisItems.uniqueKeys();
178 QMapIterator<QAbstractAxis*, ChartAxis*> i(m_axisItems);
181 QList<QAbstractSeries *> seriesList = m_chartItems.uniqueKeys();
179 while (i.hasNext()) {
182
180 i.next();
183 foreach(QAbstractAxis *axis, axisList) {
181 Domain* domain = i.value()->domain();
184 handleAxisRemoved(axis);
182 QAbstractAxis* axis = i.key();
185 handleAxisAdded(axis,m_dataset->domain(axis));
183 handleAxisRemoved(axis);
186 }
184 handleAxisAdded(axis,domain);
187 foreach(QAbstractSeries *series, seriesList) {
188 handleSeriesRemoved(series);
189 handleSeriesAdded(series,m_dataset->domain(series));
190 // m_dataset->removeSeries(series);
191 // m_dataset->addSeries(series);
192 }
185 }
186
187 QMapIterator<QAbstractSeries*, Chart*> j(m_chartItems);
188 while (j.hasNext()) {
189 j.next();
190 Domain* domain = j.value()->domain();
191 QAbstractSeries* series = j.key();
192 handleSeriesRemoved(series);
193 handleSeriesAdded(series,domain);
194 }
193 }
195 }
194
196
195 void ChartPresenter::zoomIn(qreal factor)
197 void ChartPresenter::zoomIn(qreal factor)
196 {
198 {
197 QRectF rect = geometry();
199 QRectF rect = geometry();
198 rect.setWidth(rect.width()/factor);
200 rect.setWidth(rect.width()/factor);
199 rect.setHeight(rect.height()/factor);
201 rect.setHeight(rect.height()/factor);
200 rect.moveCenter(geometry().center());
202 rect.moveCenter(geometry().center());
201 zoomIn(rect);
203 zoomIn(rect);
202 }
204 }
203
205
204 void ChartPresenter::zoomIn(const QRectF& rect)
206 void ChartPresenter::zoomIn(const QRectF& rect)
205 {
207 {
206 QRectF r = rect.normalized();
208 QRectF r = rect.normalized();
207 r.translate(-geometry().topLeft());
209 r.translate(-geometry().topLeft());
208 if (!r.isValid())
210 if (!r.isValid())
209 return;
211 return;
210
212
211 m_state = ZoomInState;
213 m_state = ZoomInState;
212 m_statePoint = QPointF(r.center().x()/geometry().width(),r.center().y()/geometry().height());
214 m_statePoint = QPointF(r.center().x()/geometry().width(),r.center().y()/geometry().height());
213 m_dataset->zoomInDomain(r,geometry().size());
215 m_dataset->zoomInDomain(r,geometry().size());
214 m_state = ShowState;
216 m_state = ShowState;
215 }
217 }
216
218
217 void ChartPresenter::zoomOut(qreal factor)
219 void ChartPresenter::zoomOut(qreal factor)
218 {
220 {
219 m_state = ZoomOutState;
221 m_state = ZoomOutState;
220
222
221 QRectF chartRect;
223 QRectF chartRect;
222 chartRect.setSize(geometry().size());
224 chartRect.setSize(geometry().size());
223
225
224 QRectF rect;
226 QRectF rect;
225 rect.setSize(chartRect.size()/factor);
227 rect.setSize(chartRect.size()/factor);
226 rect.moveCenter(chartRect.center());
228 rect.moveCenter(chartRect.center());
227 if (!rect.isValid())
229 if (!rect.isValid())
228 return;
230 return;
229 m_statePoint = QPointF(rect.center().x()/geometry().width(),rect.center().y()/geometry().height());
231 m_statePoint = QPointF(rect.center().x()/geometry().width(),rect.center().y()/geometry().height());
230 m_dataset->zoomOutDomain(rect, chartRect.size());
232 m_dataset->zoomOutDomain(rect, chartRect.size());
231 m_state = ShowState;
233 m_state = ShowState;
232 }
234 }
233
235
234 void ChartPresenter::scroll(qreal dx,qreal dy)
236 void ChartPresenter::scroll(qreal dx,qreal dy)
235 {
237 {
236 if(dx<0) m_state=ScrollLeftState;
238 if(dx<0) m_state=ScrollLeftState;
237 if(dx>0) m_state=ScrollRightState;
239 if(dx>0) m_state=ScrollRightState;
238 if(dy<0) m_state=ScrollUpState;
240 if(dy<0) m_state=ScrollUpState;
239 if(dy>0) m_state=ScrollDownState;
241 if(dy>0) m_state=ScrollDownState;
240
242
241 m_dataset->scrollDomain(dx,dy,geometry().size());
243 m_dataset->scrollDomain(dx,dy,geometry().size());
242 m_state = ShowState;
244 m_state = ShowState;
243 }
245 }
244
246
245 QChart::AnimationOptions ChartPresenter::animationOptions() const
247 QChart::AnimationOptions ChartPresenter::animationOptions() const
246 {
248 {
247 return m_options;
249 return m_options;
248 }
250 }
249
251
250 void ChartPresenter::createBackgroundItem()
252 void ChartPresenter::createBackgroundItem()
251 {
253 {
252 if (!m_backgroundItem) {
254 if (!m_backgroundItem) {
253 m_backgroundItem = new ChartBackground(rootItem());
255 m_backgroundItem = new ChartBackground(rootItem());
254 m_backgroundItem->setPen(Qt::NoPen);
256 m_backgroundItem->setPen(Qt::NoPen);
255 m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue);
257 m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue);
256 }
258 }
257 }
259 }
258
260
259 void ChartPresenter::createTitleItem()
261 void ChartPresenter::createTitleItem()
260 {
262 {
261 if (!m_titleItem) {
263 if (!m_titleItem) {
262 m_titleItem = new QGraphicsSimpleTextItem(rootItem());
264 m_titleItem = new QGraphicsSimpleTextItem(rootItem());
263 m_titleItem->setZValue(ChartPresenter::BackgroundZValue);
265 m_titleItem->setZValue(ChartPresenter::BackgroundZValue);
264 }
266 }
265 }
267 }
266
268
267
269
268 void ChartPresenter::handleAnimationFinished()
270 void ChartPresenter::handleAnimationFinished()
269 {
271 {
270 m_animations.removeAll(qobject_cast<ChartAnimation*>(sender()));
272 m_animations.removeAll(qobject_cast<ChartAnimation*>(sender()));
271 if(m_animations.empty()) emit animationsFinished();
273 if(m_animations.empty()) emit animationsFinished();
272 }
274 }
273
275
274 void ChartPresenter::startAnimation(ChartAnimation* animation)
276 void ChartPresenter::startAnimation(ChartAnimation* animation)
275 {
277 {
276 if (animation->state() != QAbstractAnimation::Stopped) animation->stop();
278 if (animation->state() != QAbstractAnimation::Stopped) animation->stop();
277 QObject::connect(animation, SIGNAL(finished()),this,SLOT(handleAnimationFinished()),Qt::UniqueConnection);
279 QObject::connect(animation, SIGNAL(finished()),this,SLOT(handleAnimationFinished()),Qt::UniqueConnection);
278 if(!m_animations.isEmpty()){
280 if(!m_animations.isEmpty()){
279 m_animations.append(animation);
281 m_animations.append(animation);
280 }
282 }
281 QTimer::singleShot(0, animation, SLOT(start()));
283 QTimer::singleShot(0, animation, SLOT(start()));
282 }
284 }
283
285
284 QGraphicsRectItem* ChartPresenter::backgroundItem()
286 QGraphicsRectItem* ChartPresenter::backgroundItem()
285 {
287 {
286 return m_backgroundItem;
288 return m_backgroundItem;
287 }
289 }
288
290
289 void ChartPresenter::setBackgroundBrush(const QBrush& brush)
291 void ChartPresenter::setBackgroundBrush(const QBrush& brush)
290 {
292 {
291 createBackgroundItem();
293 createBackgroundItem();
292 m_backgroundItem->setBrush(brush);
294 m_backgroundItem->setBrush(brush);
293 m_layout->invalidate();
295 m_layout->invalidate();
294 }
296 }
295
297
296 QBrush ChartPresenter::backgroundBrush() const
298 QBrush ChartPresenter::backgroundBrush() const
297 {
299 {
298 if (!m_backgroundItem) return QBrush();
300 if (!m_backgroundItem) return QBrush();
299 return m_backgroundItem->brush();
301 return m_backgroundItem->brush();
300 }
302 }
301
303
302 void ChartPresenter::setBackgroundPen(const QPen& pen)
304 void ChartPresenter::setBackgroundPen(const QPen& pen)
303 {
305 {
304 createBackgroundItem();
306 createBackgroundItem();
305 m_backgroundItem->setPen(pen);
307 m_backgroundItem->setPen(pen);
306 m_layout->invalidate();
308 m_layout->invalidate();
307 }
309 }
308
310
309 QPen ChartPresenter::backgroundPen() const
311 QPen ChartPresenter::backgroundPen() const
310 {
312 {
311 if (!m_backgroundItem) return QPen();
313 if (!m_backgroundItem) return QPen();
312 return m_backgroundItem->pen();
314 return m_backgroundItem->pen();
313 }
315 }
314
316
315 QGraphicsItem* ChartPresenter::titleItem()
317 QGraphicsItem* ChartPresenter::titleItem()
316 {
318 {
317 return m_titleItem;
319 return m_titleItem;
318 }
320 }
319
321
320 void ChartPresenter::setTitle(const QString& title)
322 void ChartPresenter::setTitle(const QString& title)
321 {
323 {
322 createTitleItem();
324 createTitleItem();
323 m_titleItem->setText(title);
325 m_titleItem->setText(title);
324 m_layout->invalidate();
326 m_layout->invalidate();
325 }
327 }
326
328
327 QString ChartPresenter::title() const
329 QString ChartPresenter::title() const
328 {
330 {
329 if (!m_titleItem) return QString();
331 if (!m_titleItem) return QString();
330 return m_titleItem->text();
332 return m_titleItem->text();
331 }
333 }
332
334
333 void ChartPresenter::setTitleFont(const QFont& font)
335 void ChartPresenter::setTitleFont(const QFont& font)
334 {
336 {
335 createTitleItem();
337 createTitleItem();
336 m_titleItem->setFont(font);
338 m_titleItem->setFont(font);
337 m_layout->invalidate();
339 m_layout->invalidate();
338 }
340 }
339
341
340 QFont ChartPresenter::titleFont() const
342 QFont ChartPresenter::titleFont() const
341 {
343 {
342 if (!m_titleItem) return QFont();
344 if (!m_titleItem) return QFont();
343 return m_titleItem->font();
345 return m_titleItem->font();
344 }
346 }
345
347
346 void ChartPresenter::setTitleBrush(const QBrush &brush)
348 void ChartPresenter::setTitleBrush(const QBrush &brush)
347 {
349 {
348 createTitleItem();
350 createTitleItem();
349 m_titleItem->setBrush(brush);
351 m_titleItem->setBrush(brush);
350 m_layout->invalidate();
352 m_layout->invalidate();
351 }
353 }
352
354
353 QBrush ChartPresenter::titleBrush() const
355 QBrush ChartPresenter::titleBrush() const
354 {
356 {
355 if (!m_titleItem) return QBrush();
357 if (!m_titleItem) return QBrush();
356 return m_titleItem->brush();
358 return m_titleItem->brush();
357 }
359 }
358
360
359 void ChartPresenter::setBackgroundVisible(bool visible)
361 void ChartPresenter::setBackgroundVisible(bool visible)
360 {
362 {
361 createBackgroundItem();
363 createBackgroundItem();
362 m_backgroundItem->setVisible(visible);
364 m_backgroundItem->setVisible(visible);
363 }
365 }
364
366
365
367
366 bool ChartPresenter::isBackgroundVisible() const
368 bool ChartPresenter::isBackgroundVisible() const
367 {
369 {
368 if (!m_backgroundItem) return false;
370 if (!m_backgroundItem) return false;
369 return m_backgroundItem->isVisible();
371 return m_backgroundItem->isVisible();
370 }
372 }
371
373
372 void ChartPresenter::setBackgroundDropShadowEnabled(bool enabled)
374 void ChartPresenter::setBackgroundDropShadowEnabled(bool enabled)
373 {
375 {
374 createBackgroundItem();
376 createBackgroundItem();
375 m_backgroundItem->setDropShadowEnabled(enabled);
377 m_backgroundItem->setDropShadowEnabled(enabled);
376 }
378 }
377
379
378 bool ChartPresenter::isBackgroundDropShadowEnabled() const
380 bool ChartPresenter::isBackgroundDropShadowEnabled() const
379 {
381 {
380 if (!m_backgroundItem) return false;
382 if (!m_backgroundItem) return false;
381 return m_backgroundItem->isDropShadowEnabled();
383 return m_backgroundItem->isDropShadowEnabled();
382 }
384 }
383
385
384
386
385 QGraphicsLayout* ChartPresenter::layout()
387 QGraphicsLayout* ChartPresenter::layout()
386 {
388 {
387 return m_layout;
389 return m_layout;
388 }
390 }
389
391
390 void ChartPresenter::setMarginsMinimum(const QRectF& margins)
392 void ChartPresenter::setMarginsMinimum(const QRectF& margins)
391 {
393 {
392 Q_UNUSED(margins);
394 Q_UNUSED(margins);
393 // m_layout->setMarginsMinimum(margins);
395 // m_layout->setMarginsMinimum(margins);
394 }
396 }
395
397
396 QRectF ChartPresenter::margins() const
398 QRectF ChartPresenter::margins() const
397 {
399 {
398 return QRectF();//m_layout->margins();
400 return QRectF();//m_layout->margins();
399 }
401 }
400
402
401 QLegend* ChartPresenter::legend()
403 QLegend* ChartPresenter::legend()
402 {
404 {
403 return m_chart->legend();
405 return m_chart->legend();
404 }
406 }
405
407
406 QList<ChartAxis*> ChartPresenter::axisItems() const
408 QList<ChartAxis*> ChartPresenter::axisItems() const
407 {
409 {
408 return m_axisItems.values();
410 return m_axisItems.values();
409 }
411 }
410
412
411 void ChartPresenter::setVisible(bool visible)
413 void ChartPresenter::setVisible(bool visible)
412 {
414 {
413 m_chart->setVisible(visible);
415 m_chart->setVisible(visible);
414 }
416 }
415
417
416 #include "moc_chartpresenter_p.cpp"
418 #include "moc_chartpresenter_p.cpp"
417
419
418 QTCOMMERCIALCHART_END_NAMESPACE
420 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,147 +1,134
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qlineseries.h"
21 #include "qlineseries.h"
22 #include "qlineseries_p.h"
22 #include "qlineseries_p.h"
23 #include "linechartitem_p.h"
23 #include "linechartitem_p.h"
24 #include "chartdataset_p.h"
24 #include "chartdataset_p.h"
25 #include "charttheme_p.h"
25 #include "charttheme_p.h"
26 #include "chartanimator_p.h"
26 #include "chartanimator_p.h"
27 #include "qvaluesaxis.h"
28
27
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
29
31 /*!
30 /*!
32 \class QLineSeries
31 \class QLineSeries
33 \brief The QLineSeries class is used for making line charts.
32 \brief The QLineSeries class is used for making line charts.
34
33
35 \mainclass
34 \mainclass
36
35
37 A line chart is used to show information as a series of data points
36 A line chart is used to show information as a series of data points
38 connected by straight lines.
37 connected by straight lines.
39
38
40 \image examples_linechart.png
39 \image examples_linechart.png
41
40
42 Creating basic line chart is simple:
41 Creating basic line chart is simple:
43 \code
42 \code
44 QLineSeries* series = new QLineSeries();
43 QLineSeries* series = new QLineSeries();
45 series->append(0, 6);
44 series->append(0, 6);
46 series->append(2, 4);
45 series->append(2, 4);
47 ...
46 ...
48 chart->addSeries(series);
47 chart->addSeries(series);
49 \endcode
48 \endcode
50 */
49 */
51 /*!
50 /*!
52 \qmlclass LineSeries QLineSeries
51 \qmlclass LineSeries QLineSeries
53 \inherits XYSeries
52 \inherits XYSeries
54
53
55 The following QML shows how to create a simple line chart:
54 The following QML shows how to create a simple line chart:
56 \snippet ../demos/qmlchart/qml/qmlchart/View2.qml 1
55 \snippet ../demos/qmlchart/qml/qmlchart/View2.qml 1
57 \beginfloatleft
56 \beginfloatleft
58 \image demos_qmlchart2.png
57 \image demos_qmlchart2.png
59 \endfloat
58 \endfloat
60 \clearfloat
59 \clearfloat
61 */
60 */
62
61
63 /*!
62 /*!
64 \fn virtual SeriesType QLineSeries::type() const
63 \fn virtual SeriesType QLineSeries::type() const
65 \brief Returns type of series.
64 \brief Returns type of series.
66 \sa QAbstractSeries, SeriesType
65 \sa QAbstractSeries, SeriesType
67 */
66 */
68
67
69 /*!
68 /*!
70 Constructs empty series object which is a child of \a parent.
69 Constructs empty series object which is a child of \a parent.
71 When series object is added to QChartView or QChart instance ownerships is transferred.
70 When series object is added to QChartView or QChart instance ownerships is transferred.
72 */
71 */
73 QLineSeries::QLineSeries(QObject *parent) : QXYSeries(*new QLineSeriesPrivate(this),parent)
72 QLineSeries::QLineSeries(QObject *parent) : QXYSeries(*new QLineSeriesPrivate(this),parent)
74 {
73 {
75
74
76 }
75 }
77
76
78 /*!
77 /*!
79 \internal
78 \internal
80 */
79 */
81 QLineSeries::QLineSeries(QLineSeriesPrivate &d,QObject *parent) : QXYSeries (d,parent)
80 QLineSeries::QLineSeries(QLineSeriesPrivate &d,QObject *parent) : QXYSeries (d,parent)
82 {
81 {
83
82
84 }
83 }
85 /*!
84 /*!
86 Destroys the object. Series added to QChartView or QChart instances are owned by those,
85 Destroys the object. Series added to QChartView or QChart instances are owned by those,
87 and are deleted when mentioned object are destroyed.
86 and are deleted when mentioned object are destroyed.
88 */
87 */
89 QLineSeries::~QLineSeries()
88 QLineSeries::~QLineSeries()
90 {
89 {
91 Q_D(QLineSeries);
90 Q_D(QLineSeries);
92 if(d->m_dataset){
91 if(d->m_dataset){
93 d->m_dataset->removeSeries(this);
92 d->m_dataset->removeSeries(this);
94 }
93 }
95 }
94 }
96
95
97 QAbstractSeries::SeriesType QLineSeries::type() const
96 QAbstractSeries::SeriesType QLineSeries::type() const
98 {
97 {
99 return QAbstractSeries::SeriesTypeLine;
98 return QAbstractSeries::SeriesTypeLine;
100 }
99 }
101
100
102 /*
101 /*
103 QDebug operator<< (QDebug debug, const QLineSeries series)
102 QDebug operator<< (QDebug debug, const QLineSeries series)
104 {
103 {
105 Q_ASSERT(series.d_func()->m_x.size() == series.d_func()->m_y.size());
104 Q_ASSERT(series.d_func()->m_x.size() == series.d_func()->m_y.size());
106 int size = series.d_func()->m_x.size();
105 int size = series.d_func()->m_x.size();
107 for (int i=0; i<size; i++) {
106 for (int i=0; i<size; i++) {
108 debug.nospace() << "(" << series.d_func()->m_x.at(i) << ','<< series.d_func()->m_y.at(i) << ") ";
107 debug.nospace() << "(" << series.d_func()->m_x.at(i) << ','<< series.d_func()->m_y.at(i) << ") ";
109 }
108 }
110 return debug.space();
109 return debug.space();
111 }
110 }
112 */
111 */
113
112
114 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
113 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
115
114
116 QLineSeriesPrivate::QLineSeriesPrivate(QLineSeries* q):QXYSeriesPrivate(q)
115 QLineSeriesPrivate::QLineSeriesPrivate(QLineSeries* q):QXYSeriesPrivate(q)
117 {
116 {
118
117
119 };
118 };
120
119
121 Chart* QLineSeriesPrivate::createGraphics(ChartPresenter* presenter)
120 Chart* QLineSeriesPrivate::createGraphics(ChartPresenter* presenter)
122 {
121 {
123 Q_Q(QLineSeries);
122 Q_Q(QLineSeries);
124 LineChartItem* line = new LineChartItem(q,presenter);
123 LineChartItem* line = new LineChartItem(q,presenter);
125 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
124 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
126 line->setAnimator(presenter->animator());
125 line->setAnimator(presenter->animator());
127 line->setAnimation(new XYAnimation(line));
126 line->setAnimation(new XYAnimation(line));
128 }
127 }
129 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
128 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
130 return line;
129 return line;
131 }
130 }
132
131
133 QAbstractAxis* QLineSeriesPrivate::createAxisX()
134 {
135 // TODO: parent?
136 return new QValuesAxis(this);
137 }
138
139 QAbstractAxis* QLineSeriesPrivate::createAxisY()
140 {
141 // TODO: parent?
142 return new QValuesAxis(this);
143 }
144
145 #include "moc_qlineseries.cpp"
132 #include "moc_qlineseries.cpp"
146
133
147 QTCOMMERCIALCHART_END_NAMESPACE
134 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,53 +1,51
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef QLINESERIES_P_H
30 #ifndef QLINESERIES_P_H
31 #define QLINESERIES_P_H
31 #define QLINESERIES_P_H
32
32
33 #include "qxyseries_p.h"
33 #include "qxyseries_p.h"
34
34
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36
36
37
37
38 class QLineSeriesPrivate: public QXYSeriesPrivate
38 class QLineSeriesPrivate: public QXYSeriesPrivate
39 {
39 {
40 public:
40 public:
41 QLineSeriesPrivate(QLineSeries* q);
41 QLineSeriesPrivate(QLineSeries* q);
42 Chart* createGraphics(ChartPresenter* presenter);
42 Chart* createGraphics(ChartPresenter* presenter);
43 QAbstractAxis* createAxisX();
44 QAbstractAxis* createAxisY();
45
43
46 private:
44 private:
47 Q_DECLARE_PUBLIC(QLineSeries);
45 Q_DECLARE_PUBLIC(QLineSeries);
48
46
49 };
47 };
50
48
51 QTCOMMERCIALCHART_END_NAMESPACE
49 QTCOMMERCIALCHART_END_NAMESPACE
52
50
53 #endif
51 #endif
@@ -1,771 +1,773
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qpieseries.h"
21 #include "qpieseries.h"
22 #include "qpieseries_p.h"
22 #include "qpieseries_p.h"
23 #include "qpieslice.h"
23 #include "qpieslice.h"
24 #include "qpieslice_p.h"
24 #include "qpieslice_p.h"
25 #include "pieslicedata_p.h"
25 #include "pieslicedata_p.h"
26 #include "chartdataset_p.h"
26 #include "chartdataset_p.h"
27 #include "charttheme_p.h"
27 #include "charttheme_p.h"
28 #include "chartanimator_p.h"
28 #include "chartanimator_p.h"
29 #include "legendmarker_p.h"
29 #include "legendmarker_p.h"
30 #include "qabstractaxis.h"
30 #include "qabstractaxis.h"
31
31
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33
33
34 /*!
34 /*!
35 \class QPieSeries
35 \class QPieSeries
36 \brief Pie series API for QtCommercial Charts
36 \brief Pie series API for QtCommercial Charts
37
37
38 The pie series defines a pie chart which consists of pie slices which are defined as QPieSlice objects.
38 The pie series defines a pie chart which consists of pie slices which are defined as QPieSlice objects.
39 The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices.
39 The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices.
40 The actual slice size is determined by that relative value.
40 The actual slice size is determined by that relative value.
41
41
42 Pie size and position on the chart is controlled by using relative values which range from 0.0 to 1.0
42 Pie size and position on the chart is controlled by using relative values which range from 0.0 to 1.0
43 These relate to the actual chart rectangle.
43 These relate to the actual chart rectangle.
44
44
45 By default the pie is defined as a full pie but it can also be a partial pie.
45 By default the pie is defined as a full pie but it can also be a partial pie.
46 This can be done by setting a starting angle and angle span to the series.
46 This can be done by setting a starting angle and angle span to the series.
47 Full pie is 360 degrees where 0 is at 12 a'clock.
47 Full pie is 360 degrees where 0 is at 12 a'clock.
48
48
49 See the \l {PieChart Example} {pie chart example} to learn how to create a simple pie chart.
49 See the \l {PieChart Example} {pie chart example} to learn how to create a simple pie chart.
50 \image examples_piechart.png
50 \image examples_piechart.png
51 */
51 */
52 /*!
52 /*!
53 \qmlclass PieSeries QPieSeries
53 \qmlclass PieSeries QPieSeries
54 \inherits AbstractSeries
54 \inherits AbstractSeries
55
55
56 The following QML shows how to create a simple pie chart.
56 The following QML shows how to create a simple pie chart.
57
57
58 \snippet ../demos/qmlchart/qml/qmlchart/View1.qml 1
58 \snippet ../demos/qmlchart/qml/qmlchart/View1.qml 1
59
59
60 \beginfloatleft
60 \beginfloatleft
61 \image demos_qmlchart1.png
61 \image demos_qmlchart1.png
62 \endfloat
62 \endfloat
63 \clearfloat
63 \clearfloat
64 */
64 */
65
65
66 /*!
66 /*!
67 \property QPieSeries::horizontalPosition
67 \property QPieSeries::horizontalPosition
68 \brief Defines the horizontal position of the pie.
68 \brief Defines the horizontal position of the pie.
69
69
70 The value is a relative value to the chart rectangle where:
70 The value is a relative value to the chart rectangle where:
71
71
72 \list
72 \list
73 \o 0.0 is the absolute left.
73 \o 0.0 is the absolute left.
74 \o 1.0 is the absolute right.
74 \o 1.0 is the absolute right.
75 \endlist
75 \endlist
76 Default value is 0.5 (center).
76 Default value is 0.5 (center).
77 \sa verticalPosition
77 \sa verticalPosition
78 */
78 */
79
79
80 /*!
80 /*!
81 \qmlproperty real PieSeries::horizontalPosition
81 \qmlproperty real PieSeries::horizontalPosition
82
82
83 Defines the horizontal position of the pie.
83 Defines the horizontal position of the pie.
84
84
85 The value is a relative value to the chart rectangle where:
85 The value is a relative value to the chart rectangle where:
86
86
87 \list
87 \list
88 \o 0.0 is the absolute left.
88 \o 0.0 is the absolute left.
89 \o 1.0 is the absolute right.
89 \o 1.0 is the absolute right.
90 \endlist
90 \endlist
91 Default value is 0.5 (center).
91 Default value is 0.5 (center).
92 \sa verticalPosition
92 \sa verticalPosition
93 */
93 */
94
94
95 /*!
95 /*!
96 \property QPieSeries::verticalPosition
96 \property QPieSeries::verticalPosition
97 \brief Defines the vertical position of the pie.
97 \brief Defines the vertical position of the pie.
98
98
99 The value is a relative value to the chart rectangle where:
99 The value is a relative value to the chart rectangle where:
100
100
101 \list
101 \list
102 \o 0.0 is the absolute top.
102 \o 0.0 is the absolute top.
103 \o 1.0 is the absolute bottom.
103 \o 1.0 is the absolute bottom.
104 \endlist
104 \endlist
105 Default value is 0.5 (center).
105 Default value is 0.5 (center).
106 \sa horizontalPosition
106 \sa horizontalPosition
107 */
107 */
108
108
109 /*!
109 /*!
110 \qmlproperty real PieSeries::verticalPosition
110 \qmlproperty real PieSeries::verticalPosition
111
111
112 Defines the vertical position of the pie.
112 Defines the vertical position of the pie.
113
113
114 The value is a relative value to the chart rectangle where:
114 The value is a relative value to the chart rectangle where:
115
115
116 \list
116 \list
117 \o 0.0 is the absolute top.
117 \o 0.0 is the absolute top.
118 \o 1.0 is the absolute bottom.
118 \o 1.0 is the absolute bottom.
119 \endlist
119 \endlist
120 Default value is 0.5 (center).
120 Default value is 0.5 (center).
121 \sa horizontalPosition
121 \sa horizontalPosition
122 */
122 */
123
123
124 /*!
124 /*!
125 \property QPieSeries::size
125 \property QPieSeries::size
126 \brief Defines the pie size.
126 \brief Defines the pie size.
127
127
128 The value is a relative value to the chart rectangle where:
128 The value is a relative value to the chart rectangle where:
129
129
130 \list
130 \list
131 \o 0.0 is the minimum size (pie not drawn).
131 \o 0.0 is the minimum size (pie not drawn).
132 \o 1.0 is the maximum size that can fit the chart.
132 \o 1.0 is the maximum size that can fit the chart.
133 \endlist
133 \endlist
134
134
135 Default value is 0.7.
135 Default value is 0.7.
136 */
136 */
137
137
138 /*!
138 /*!
139 \qmlproperty real PieSeries::size
139 \qmlproperty real PieSeries::size
140
140
141 Defines the pie size.
141 Defines the pie size.
142
142
143 The value is a relative value to the chart rectangle where:
143 The value is a relative value to the chart rectangle where:
144
144
145 \list
145 \list
146 \o 0.0 is the minimum size (pie not drawn).
146 \o 0.0 is the minimum size (pie not drawn).
147 \o 1.0 is the maximum size that can fit the chart.
147 \o 1.0 is the maximum size that can fit the chart.
148 \endlist
148 \endlist
149
149
150 Default value is 0.7.
150 Default value is 0.7.
151 */
151 */
152
152
153 /*!
153 /*!
154 \property QPieSeries::startAngle
154 \property QPieSeries::startAngle
155 \brief Defines the starting angle of the pie.
155 \brief Defines the starting angle of the pie.
156
156
157 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
157 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
158
158
159 Default is value is 0.
159 Default is value is 0.
160 */
160 */
161
161
162 /*!
162 /*!
163 \qmlproperty real PieSeries::startAngle
163 \qmlproperty real PieSeries::startAngle
164
164
165 Defines the starting angle of the pie.
165 Defines the starting angle of the pie.
166
166
167 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
167 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
168
168
169 Default is value is 0.
169 Default is value is 0.
170 */
170 */
171
171
172 /*!
172 /*!
173 \property QPieSeries::endAngle
173 \property QPieSeries::endAngle
174 \brief Defines the ending angle of the pie.
174 \brief Defines the ending angle of the pie.
175
175
176 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
176 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
177
177
178 Default is value is 360.
178 Default is value is 360.
179 */
179 */
180
180
181 /*!
181 /*!
182 \qmlproperty real PieSeries::endAngle
182 \qmlproperty real PieSeries::endAngle
183
183
184 Defines the ending angle of the pie.
184 Defines the ending angle of the pie.
185
185
186 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
186 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
187
187
188 Default is value is 360.
188 Default is value is 360.
189 */
189 */
190
190
191 /*!
191 /*!
192 \property QPieSeries::count
192 \property QPieSeries::count
193
193
194 Number of slices in the series.
194 Number of slices in the series.
195 */
195 */
196
196
197 /*!
197 /*!
198 \qmlproperty int PieSeries::count
198 \qmlproperty int PieSeries::count
199
199
200 Number of slices in the series.
200 Number of slices in the series.
201 */
201 */
202
202
203 /*!
203 /*!
204 \fn void QPieSeries::countChanged()
204 \fn void QPieSeries::countChanged()
205 Emitted when the slice count has changed.
205 Emitted when the slice count has changed.
206 \sa count
206 \sa count
207 */
207 */
208 /*!
208 /*!
209 \qmlsignal PieSeries::onCountChanged()
209 \qmlsignal PieSeries::onCountChanged()
210 Emitted when the slice count has changed.
210 Emitted when the slice count has changed.
211 */
211 */
212
212
213 /*!
213 /*!
214 \property QPieSeries::sum
214 \property QPieSeries::sum
215
215
216 Sum of all slices.
216 Sum of all slices.
217
217
218 The series keeps track of the sum of all slices it holds.
218 The series keeps track of the sum of all slices it holds.
219 */
219 */
220
220
221 /*!
221 /*!
222 \qmlproperty real PieSeries::sum
222 \qmlproperty real PieSeries::sum
223
223
224 Sum of all slices.
224 Sum of all slices.
225
225
226 The series keeps track of the sum of all slices it holds.
226 The series keeps track of the sum of all slices it holds.
227 */
227 */
228
228
229 /*!
229 /*!
230 \fn void QPieSeries::sumChanged()
230 \fn void QPieSeries::sumChanged()
231 Emitted when the sum of all slices has changed.
231 Emitted when the sum of all slices has changed.
232 \sa sum
232 \sa sum
233 */
233 */
234 /*!
234 /*!
235 \qmlsignal PieSeries::onSumChanged()
235 \qmlsignal PieSeries::onSumChanged()
236 Emitted when the sum of all slices has changed. This may happen for example if you add or remove slices, or if you
236 Emitted when the sum of all slices has changed. This may happen for example if you add or remove slices, or if you
237 change value of a slice.
237 change value of a slice.
238 */
238 */
239
239
240 /*!
240 /*!
241 \fn void QPieSeries::added(QList<QPieSlice*> slices)
241 \fn void QPieSeries::added(QList<QPieSlice*> slices)
242
242
243 This signal is emitted when \a slices have been added to the series.
243 This signal is emitted when \a slices have been added to the series.
244
244
245 \sa append(), insert()
245 \sa append(), insert()
246 */
246 */
247 /*!
247 /*!
248 \qmlsignal PieSeries::onAdded(PieSlice slice)
248 \qmlsignal PieSeries::onAdded(PieSlice slice)
249 Emitted when \a slice has been added to the series.
249 Emitted when \a slice has been added to the series.
250 */
250 */
251
251
252 /*!
252 /*!
253 \fn void QPieSeries::removed(QList<QPieSlice*> slices)
253 \fn void QPieSeries::removed(QList<QPieSlice*> slices)
254 This signal is emitted when \a slices have been removed from the series.
254 This signal is emitted when \a slices have been removed from the series.
255 \sa remove()
255 \sa remove()
256 */
256 */
257 /*!
257 /*!
258 \qmlsignal PieSeries::onRemoved(PieSlice slice)
258 \qmlsignal PieSeries::onRemoved(PieSlice slice)
259 Emitted when \a slice has been removed from the series.
259 Emitted when \a slice has been removed from the series.
260 */
260 */
261
261
262 /*!
262 /*!
263 \fn void QPieSeries::clicked(QPieSlice* slice)
263 \fn void QPieSeries::clicked(QPieSlice* slice)
264 This signal is emitted when a \a slice has been clicked.
264 This signal is emitted when a \a slice has been clicked.
265 \sa QPieSlice::clicked()
265 \sa QPieSlice::clicked()
266 */
266 */
267 /*!
267 /*!
268 \qmlsignal PieSeries::onClicked(PieSlice slice)
268 \qmlsignal PieSeries::onClicked(PieSlice slice)
269 This signal is emitted when a \a slice has been clicked.
269 This signal is emitted when a \a slice has been clicked.
270 */
270 */
271
271
272 /*!
272 /*!
273 \fn void QPieSeries::hovered(QPieSlice* slice, bool state)
273 \fn void QPieSeries::hovered(QPieSlice* slice, bool state)
274 This signal is emitted when user has hovered over or away from the \a slice.
274 This signal is emitted when user has hovered over or away from the \a slice.
275 \a state is true when user has hovered over the slice and false when hover has moved away from the slice.
275 \a state is true when user has hovered over the slice and false when hover has moved away from the slice.
276 \sa QPieSlice::hovered()
276 \sa QPieSlice::hovered()
277 */
277 */
278 /*!
278 /*!
279 \qmlsignal PieSeries::onHovered(PieSlice slice, bool state)
279 \qmlsignal PieSeries::onHovered(PieSlice slice, bool state)
280 This signal is emitted when user has hovered over or away from the \a slice. \a state is true when user has hovered
280 This signal is emitted when user has hovered over or away from the \a slice. \a state is true when user has hovered
281 over the slice and false when hover has moved away from the slice.
281 over the slice and false when hover has moved away from the slice.
282 */
282 */
283
283
284 /*!
284 /*!
285 \qmlmethod PieSlice PieSeries::at(int index)
285 \qmlmethod PieSlice PieSeries::at(int index)
286 Returns slice at \a index. Returns null if the index is not valid.
286 Returns slice at \a index. Returns null if the index is not valid.
287 */
287 */
288
288
289 /*!
289 /*!
290 \qmlmethod PieSlice PieSeries::find(string label)
290 \qmlmethod PieSlice PieSeries::find(string label)
291 Returns the first slice with \a label. Returns null if the index is not valid.
291 Returns the first slice with \a label. Returns null if the index is not valid.
292 */
292 */
293
293
294 /*!
294 /*!
295 \qmlmethod PieSlice PieSeries::append(string label, real value)
295 \qmlmethod PieSlice PieSeries::append(string label, real value)
296 Adds a new slice with \a label and \a value to the pie.
296 Adds a new slice with \a label and \a value to the pie.
297 */
297 */
298
298
299 /*!
299 /*!
300 \qmlmethod bool PieSeries::remove(PieSlice slice)
300 \qmlmethod bool PieSeries::remove(PieSlice slice)
301 Removes the \a slice from the pie. Returns true if the removal was successfull, false otherwise.
301 Removes the \a slice from the pie. Returns true if the removal was successfull, false otherwise.
302 */
302 */
303
303
304 /*!
304 /*!
305 \qmlmethod PieSeries::clear()
305 \qmlmethod PieSeries::clear()
306 Removes all slices from the pie.
306 Removes all slices from the pie.
307 */
307 */
308
308
309 /*!
309 /*!
310 Constructs a series object which is a child of \a parent.
310 Constructs a series object which is a child of \a parent.
311 */
311 */
312 QPieSeries::QPieSeries(QObject *parent) :
312 QPieSeries::QPieSeries(QObject *parent) :
313 QAbstractSeries(*new QPieSeriesPrivate(this),parent)
313 QAbstractSeries(*new QPieSeriesPrivate(this),parent)
314 {
314 {
315
315
316 }
316 }
317
317
318 /*!
318 /*!
319 Destroys the series and its slices.
319 Destroys the series and its slices.
320 */
320 */
321 QPieSeries::~QPieSeries()
321 QPieSeries::~QPieSeries()
322 {
322 {
323 // NOTE: d_prt destroyed by QObject
323 // NOTE: d_prt destroyed by QObject
324 }
324 }
325
325
326 /*!
326 /*!
327 Returns QChartSeries::SeriesTypePie.
327 Returns QChartSeries::SeriesTypePie.
328 */
328 */
329 QAbstractSeries::SeriesType QPieSeries::type() const
329 QAbstractSeries::SeriesType QPieSeries::type() const
330 {
330 {
331 return QAbstractSeries::SeriesTypePie;
331 return QAbstractSeries::SeriesTypePie;
332 }
332 }
333
333
334 /*!
334 /*!
335 Appends a single \a slice to the series.
335 Appends a single \a slice to the series.
336 Slice ownership is passed to the series.
336 Slice ownership is passed to the series.
337
337
338 Returns true if append was succesfull.
338 Returns true if append was succesfull.
339 */
339 */
340 bool QPieSeries::append(QPieSlice* slice)
340 bool QPieSeries::append(QPieSlice* slice)
341 {
341 {
342 return append(QList<QPieSlice*>() << slice);
342 return append(QList<QPieSlice*>() << slice);
343 }
343 }
344
344
345 /*!
345 /*!
346 Appends an array of \a slices to the series.
346 Appends an array of \a slices to the series.
347 Slice ownership is passed to the series.
347 Slice ownership is passed to the series.
348
348
349 Returns true if append was successfull.
349 Returns true if append was successfull.
350 */
350 */
351 bool QPieSeries::append(QList<QPieSlice*> slices)
351 bool QPieSeries::append(QList<QPieSlice*> slices)
352 {
352 {
353 Q_D(QPieSeries);
353 Q_D(QPieSeries);
354
354
355 if (slices.count() == 0)
355 if (slices.count() == 0)
356 return false;
356 return false;
357
357
358 foreach (QPieSlice* s, slices) {
358 foreach (QPieSlice* s, slices) {
359 if (!s || d->m_slices.contains(s))
359 if (!s || d->m_slices.contains(s))
360 return false;
360 return false;
361 if (s->series()) // already added to some series
361 if (s->series()) // already added to some series
362 return false;
362 return false;
363 }
363 }
364
364
365 foreach (QPieSlice* s, slices) {
365 foreach (QPieSlice* s, slices) {
366 s->setParent(this);
366 s->setParent(this);
367 QPieSlicePrivate::fromSlice(s)->m_series = this;
367 QPieSlicePrivate::fromSlice(s)->m_series = this;
368 d->m_slices << s;
368 d->m_slices << s;
369 }
369 }
370
370
371 d->updateDerivativeData();
371 d->updateDerivativeData();
372
372
373 foreach (QPieSlice* s, slices) {
373 foreach (QPieSlice* s, slices) {
374 connect(s, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged()));
374 connect(s, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged()));
375 connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked()));
375 connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked()));
376 connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
376 connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
377 }
377 }
378
378
379 emit added(slices);
379 emit added(slices);
380 emit countChanged();
380 emit countChanged();
381
381
382 return true;
382 return true;
383 }
383 }
384
384
385 /*!
385 /*!
386 Appends a single \a slice to the series and returns a reference to the series.
386 Appends a single \a slice to the series and returns a reference to the series.
387 Slice ownership is passed to the series.
387 Slice ownership is passed to the series.
388 */
388 */
389 QPieSeries& QPieSeries::operator << (QPieSlice* slice)
389 QPieSeries& QPieSeries::operator << (QPieSlice* slice)
390 {
390 {
391 append(slice);
391 append(slice);
392 return *this;
392 return *this;
393 }
393 }
394
394
395
395
396 /*!
396 /*!
397 Appends a single slice to the series with give \a value and \a label.
397 Appends a single slice to the series with give \a value and \a label.
398 Slice ownership is passed to the series.
398 Slice ownership is passed to the series.
399 */
399 */
400 QPieSlice* QPieSeries::append(QString label, qreal value)
400 QPieSlice* QPieSeries::append(QString label, qreal value)
401 {
401 {
402 QPieSlice* slice = new QPieSlice(label, value);
402 QPieSlice* slice = new QPieSlice(label, value);
403 append(slice);
403 append(slice);
404 return slice;
404 return slice;
405 }
405 }
406
406
407 /*!
407 /*!
408 Inserts a single \a slice to the series before the slice at \a index position.
408 Inserts a single \a slice to the series before the slice at \a index position.
409 Slice ownership is passed to the series.
409 Slice ownership is passed to the series.
410
410
411 Returns true if insert was successfull.
411 Returns true if insert was successfull.
412 */
412 */
413 bool QPieSeries::insert(int index, QPieSlice* slice)
413 bool QPieSeries::insert(int index, QPieSlice* slice)
414 {
414 {
415 Q_D(QPieSeries);
415 Q_D(QPieSeries);
416
416
417 if (index < 0 || index > d->m_slices.count())
417 if (index < 0 || index > d->m_slices.count())
418 return false;
418 return false;
419
419
420 if (!slice || d->m_slices.contains(slice))
420 if (!slice || d->m_slices.contains(slice))
421 return false;
421 return false;
422
422
423 if (slice->series()) // already added to some series
423 if (slice->series()) // already added to some series
424 return false;
424 return false;
425
425
426 slice->setParent(this);
426 slice->setParent(this);
427 QPieSlicePrivate::fromSlice(slice)->m_series = this;
427 QPieSlicePrivate::fromSlice(slice)->m_series = this;
428 d->m_slices.insert(index, slice);
428 d->m_slices.insert(index, slice);
429
429
430 d->updateDerivativeData();
430 d->updateDerivativeData();
431
431
432 connect(slice, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged()));
432 connect(slice, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged()));
433 connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked()));
433 connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked()));
434 connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
434 connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
435
435
436 emit added(QList<QPieSlice*>() << slice);
436 emit added(QList<QPieSlice*>() << slice);
437 emit countChanged();
437 emit countChanged();
438
438
439 return true;
439 return true;
440 }
440 }
441
441
442 /*!
442 /*!
443 Removes a single \a slice from the series and deletes the slice.
443 Removes a single \a slice from the series and deletes the slice.
444
444
445 Do not reference the pointer after this call.
445 Do not reference the pointer after this call.
446
446
447 Returns true if remove was successfull.
447 Returns true if remove was successfull.
448 */
448 */
449 bool QPieSeries::remove(QPieSlice* slice)
449 bool QPieSeries::remove(QPieSlice* slice)
450 {
450 {
451 Q_D(QPieSeries);
451 Q_D(QPieSeries);
452
452
453 if (!d->m_slices.removeOne(slice))
453 if (!d->m_slices.removeOne(slice))
454 return false;
454 return false;
455
455
456 d->updateDerivativeData();
456 d->updateDerivativeData();
457
457
458 emit removed(QList<QPieSlice*>() << slice);
458 emit removed(QList<QPieSlice*>() << slice);
459 emit countChanged();
459 emit countChanged();
460
460
461 delete slice;
461 delete slice;
462 slice = 0;
462 slice = 0;
463
463
464 return true;
464 return true;
465 }
465 }
466
466
467 /*!
467 /*!
468 Clears all slices from the series.
468 Clears all slices from the series.
469 */
469 */
470 void QPieSeries::clear()
470 void QPieSeries::clear()
471 {
471 {
472 Q_D(QPieSeries);
472 Q_D(QPieSeries);
473 if (d->m_slices.count() == 0)
473 if (d->m_slices.count() == 0)
474 return;
474 return;
475
475
476 QList<QPieSlice*> slices = d->m_slices;
476 QList<QPieSlice*> slices = d->m_slices;
477 foreach (QPieSlice* s, d->m_slices) {
477 foreach (QPieSlice* s, d->m_slices) {
478 d->m_slices.removeOne(s);
478 d->m_slices.removeOne(s);
479 delete s;
479 delete s;
480 }
480 }
481
481
482 d->updateDerivativeData();
482 d->updateDerivativeData();
483
483
484 emit removed(slices);
484 emit removed(slices);
485 emit countChanged();
485 emit countChanged();
486 }
486 }
487
487
488 /*!
488 /*!
489 Returns a list of slices that belong to this series.
489 Returns a list of slices that belong to this series.
490 */
490 */
491 QList<QPieSlice*> QPieSeries::slices() const
491 QList<QPieSlice*> QPieSeries::slices() const
492 {
492 {
493 Q_D(const QPieSeries);
493 Q_D(const QPieSeries);
494 return d->m_slices;
494 return d->m_slices;
495 }
495 }
496
496
497 /*!
497 /*!
498 returns the number of the slices in this series.
498 returns the number of the slices in this series.
499 */
499 */
500 int QPieSeries::count() const
500 int QPieSeries::count() const
501 {
501 {
502 Q_D(const QPieSeries);
502 Q_D(const QPieSeries);
503 return d->m_slices.count();
503 return d->m_slices.count();
504 }
504 }
505
505
506 /*!
506 /*!
507 Returns true is the series is empty.
507 Returns true is the series is empty.
508 */
508 */
509 bool QPieSeries::isEmpty() const
509 bool QPieSeries::isEmpty() const
510 {
510 {
511 Q_D(const QPieSeries);
511 Q_D(const QPieSeries);
512 return d->m_slices.isEmpty();
512 return d->m_slices.isEmpty();
513 }
513 }
514
514
515 /*!
515 /*!
516 Returns the sum of all slice values in this series.
516 Returns the sum of all slice values in this series.
517
517
518 \sa QPieSlice::value(), QPieSlice::setValue(), QPieSlice::percentage()
518 \sa QPieSlice::value(), QPieSlice::setValue(), QPieSlice::percentage()
519 */
519 */
520 qreal QPieSeries::sum() const
520 qreal QPieSeries::sum() const
521 {
521 {
522 Q_D(const QPieSeries);
522 Q_D(const QPieSeries);
523 return d->m_sum;
523 return d->m_sum;
524 }
524 }
525
525
526 void QPieSeries::setHorizontalPosition(qreal relativePosition)
526 void QPieSeries::setHorizontalPosition(qreal relativePosition)
527 {
527 {
528 Q_D(QPieSeries);
528 Q_D(QPieSeries);
529
529
530 if (relativePosition < 0.0)
530 if (relativePosition < 0.0)
531 relativePosition = 0.0;
531 relativePosition = 0.0;
532 if (relativePosition > 1.0)
532 if (relativePosition > 1.0)
533 relativePosition = 1.0;
533 relativePosition = 1.0;
534
534
535 if (!qFuzzyIsNull(d->m_pieRelativeHorPos - relativePosition)) {
535 if (!qFuzzyIsNull(d->m_pieRelativeHorPos - relativePosition)) {
536 d->m_pieRelativeHorPos = relativePosition;
536 d->m_pieRelativeHorPos = relativePosition;
537 emit d->horizontalPositionChanged();
537 emit d->horizontalPositionChanged();
538 }
538 }
539 }
539 }
540
540
541 qreal QPieSeries::horizontalPosition() const
541 qreal QPieSeries::horizontalPosition() const
542 {
542 {
543 Q_D(const QPieSeries);
543 Q_D(const QPieSeries);
544 return d->m_pieRelativeHorPos;
544 return d->m_pieRelativeHorPos;
545 }
545 }
546
546
547 void QPieSeries::setVerticalPosition(qreal relativePosition)
547 void QPieSeries::setVerticalPosition(qreal relativePosition)
548 {
548 {
549 Q_D(QPieSeries);
549 Q_D(QPieSeries);
550
550
551 if (relativePosition < 0.0)
551 if (relativePosition < 0.0)
552 relativePosition = 0.0;
552 relativePosition = 0.0;
553 if (relativePosition > 1.0)
553 if (relativePosition > 1.0)
554 relativePosition = 1.0;
554 relativePosition = 1.0;
555
555
556 if (!qFuzzyIsNull(d->m_pieRelativeVerPos - relativePosition)) {
556 if (!qFuzzyIsNull(d->m_pieRelativeVerPos - relativePosition)) {
557 d->m_pieRelativeVerPos = relativePosition;
557 d->m_pieRelativeVerPos = relativePosition;
558 emit d->verticalPositionChanged();
558 emit d->verticalPositionChanged();
559 }
559 }
560 }
560 }
561
561
562 qreal QPieSeries::verticalPosition() const
562 qreal QPieSeries::verticalPosition() const
563 {
563 {
564 Q_D(const QPieSeries);
564 Q_D(const QPieSeries);
565 return d->m_pieRelativeVerPos;
565 return d->m_pieRelativeVerPos;
566 }
566 }
567
567
568 void QPieSeries::setPieSize(qreal relativeSize)
568 void QPieSeries::setPieSize(qreal relativeSize)
569 {
569 {
570 Q_D(QPieSeries);
570 Q_D(QPieSeries);
571
571
572 if (relativeSize < 0.0)
572 if (relativeSize < 0.0)
573 relativeSize = 0.0;
573 relativeSize = 0.0;
574 if (relativeSize > 1.0)
574 if (relativeSize > 1.0)
575 relativeSize = 1.0;
575 relativeSize = 1.0;
576
576
577 if (!qFuzzyIsNull(d->m_pieRelativeSize - relativeSize)) {
577 if (!qFuzzyIsNull(d->m_pieRelativeSize - relativeSize)) {
578 d->m_pieRelativeSize = relativeSize;
578 d->m_pieRelativeSize = relativeSize;
579 emit d->pieSizeChanged();
579 emit d->pieSizeChanged();
580 }
580 }
581 }
581 }
582
582
583 qreal QPieSeries::pieSize() const
583 qreal QPieSeries::pieSize() const
584 {
584 {
585 Q_D(const QPieSeries);
585 Q_D(const QPieSeries);
586 return d->m_pieRelativeSize;
586 return d->m_pieRelativeSize;
587 }
587 }
588
588
589
589
590 void QPieSeries::setPieStartAngle(qreal angle)
590 void QPieSeries::setPieStartAngle(qreal angle)
591 {
591 {
592 Q_D(QPieSeries);
592 Q_D(QPieSeries);
593 if (qFuzzyIsNull(d->m_pieStartAngle - angle))
593 if (qFuzzyIsNull(d->m_pieStartAngle - angle))
594 return;
594 return;
595 d->m_pieStartAngle = angle;
595 d->m_pieStartAngle = angle;
596 d->updateDerivativeData();
596 d->updateDerivativeData();
597 emit d->pieStartAngleChanged();
597 emit d->pieStartAngleChanged();
598 }
598 }
599
599
600 qreal QPieSeries::pieStartAngle() const
600 qreal QPieSeries::pieStartAngle() const
601 {
601 {
602 Q_D(const QPieSeries);
602 Q_D(const QPieSeries);
603 return d->m_pieStartAngle;
603 return d->m_pieStartAngle;
604 }
604 }
605
605
606 /*!
606 /*!
607 Sets the end angle of the pie.
607 Sets the end angle of the pie.
608
608
609 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
609 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
610
610
611 \a angle must be greater than start angle.
611 \a angle must be greater than start angle.
612
612
613 \sa pieEndAngle(), pieStartAngle(), setPieStartAngle()
613 \sa pieEndAngle(), pieStartAngle(), setPieStartAngle()
614 */
614 */
615 void QPieSeries::setPieEndAngle(qreal angle)
615 void QPieSeries::setPieEndAngle(qreal angle)
616 {
616 {
617 Q_D(QPieSeries);
617 Q_D(QPieSeries);
618 if (qFuzzyIsNull(d->m_pieEndAngle - angle))
618 if (qFuzzyIsNull(d->m_pieEndAngle - angle))
619 return;
619 return;
620 d->m_pieEndAngle = angle;
620 d->m_pieEndAngle = angle;
621 d->updateDerivativeData();
621 d->updateDerivativeData();
622 emit d->pieEndAngleChanged();
622 emit d->pieEndAngleChanged();
623 }
623 }
624
624
625 /*!
625 /*!
626 Returns the end angle of the pie.
626 Returns the end angle of the pie.
627
627
628 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
628 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
629
629
630 \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle()
630 \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle()
631 */
631 */
632 qreal QPieSeries::pieEndAngle() const
632 qreal QPieSeries::pieEndAngle() const
633 {
633 {
634 Q_D(const QPieSeries);
634 Q_D(const QPieSeries);
635 return d->m_pieEndAngle;
635 return d->m_pieEndAngle;
636 }
636 }
637
637
638 /*!
638 /*!
639 Sets the all the slice labels \a visible or invisible.
639 Sets the all the slice labels \a visible or invisible.
640
640
641 Note that this affects only the current slices in the series.
641 Note that this affects only the current slices in the series.
642 If user adds a new slice the default label visibility is false.
642 If user adds a new slice the default label visibility is false.
643
643
644 \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible()
644 \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible()
645 */
645 */
646 void QPieSeries::setLabelsVisible(bool visible)
646 void QPieSeries::setLabelsVisible(bool visible)
647 {
647 {
648 Q_D(QPieSeries);
648 Q_D(QPieSeries);
649 foreach (QPieSlice* s, d->m_slices)
649 foreach (QPieSlice* s, d->m_slices)
650 s->setLabelVisible(visible);
650 s->setLabelVisible(visible);
651 }
651 }
652
652
653 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
653 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
654
654
655
655
656 QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) :
656 QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) :
657 QAbstractSeriesPrivate(parent),
657 QAbstractSeriesPrivate(parent),
658 m_pieRelativeHorPos(0.5),
658 m_pieRelativeHorPos(0.5),
659 m_pieRelativeVerPos(0.5),
659 m_pieRelativeVerPos(0.5),
660 m_pieRelativeSize(0.7),
660 m_pieRelativeSize(0.7),
661 m_pieStartAngle(0),
661 m_pieStartAngle(0),
662 m_pieEndAngle(360),
662 m_pieEndAngle(360),
663 m_sum(0)
663 m_sum(0)
664 {
664 {
665 }
665 }
666
666
667 QPieSeriesPrivate::~QPieSeriesPrivate()
667 QPieSeriesPrivate::~QPieSeriesPrivate()
668 {
668 {
669 }
669 }
670
670
671 void QPieSeriesPrivate::updateDerivativeData()
671 void QPieSeriesPrivate::updateDerivativeData()
672 {
672 {
673 // calculate sum of all slices
673 // calculate sum of all slices
674 qreal sum = 0;
674 qreal sum = 0;
675 foreach (QPieSlice* s, m_slices)
675 foreach (QPieSlice* s, m_slices)
676 sum += s->value();
676 sum += s->value();
677
677
678 if (!qFuzzyIsNull(m_sum - sum)) {
678 if (!qFuzzyIsNull(m_sum - sum)) {
679 m_sum = sum;
679 m_sum = sum;
680 emit q_func()->sumChanged();
680 emit q_func()->sumChanged();
681 }
681 }
682
682
683 // nothing to show..
683 // nothing to show..
684 if (qFuzzyIsNull(m_sum))
684 if (qFuzzyIsNull(m_sum))
685 return;
685 return;
686
686
687 // update slice attributes
687 // update slice attributes
688 qreal sliceAngle = m_pieStartAngle;
688 qreal sliceAngle = m_pieStartAngle;
689 qreal pieSpan = m_pieEndAngle - m_pieStartAngle;
689 qreal pieSpan = m_pieEndAngle - m_pieStartAngle;
690 QVector<QPieSlice*> changed;
690 QVector<QPieSlice*> changed;
691 foreach (QPieSlice* s, m_slices) {
691 foreach (QPieSlice* s, m_slices) {
692 QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s);
692 QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s);
693 d->setPercentage(s->value() / m_sum);
693 d->setPercentage(s->value() / m_sum);
694 d->setStartAngle(sliceAngle);
694 d->setStartAngle(sliceAngle);
695 d->setAngleSpan(pieSpan * s->percentage());
695 d->setAngleSpan(pieSpan * s->percentage());
696 sliceAngle += s->angleSpan();
696 sliceAngle += s->angleSpan();
697 }
697 }
698
698
699
699
700 emit calculatedDataChanged();
700 emit calculatedDataChanged();
701 }
701 }
702
702
703 QPieSeriesPrivate* QPieSeriesPrivate::fromSeries(QPieSeries *series)
703 QPieSeriesPrivate* QPieSeriesPrivate::fromSeries(QPieSeries *series)
704 {
704 {
705 return series->d_func();
705 return series->d_func();
706 }
706 }
707
707
708 void QPieSeriesPrivate::sliceValueChanged()
708 void QPieSeriesPrivate::sliceValueChanged()
709 {
709 {
710 Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender())));
710 Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender())));
711 updateDerivativeData();
711 updateDerivativeData();
712 }
712 }
713
713
714 void QPieSeriesPrivate::sliceClicked()
714 void QPieSeriesPrivate::sliceClicked()
715 {
715 {
716 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
716 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
717 Q_ASSERT(m_slices.contains(slice));
717 Q_ASSERT(m_slices.contains(slice));
718 Q_Q(QPieSeries);
718 Q_Q(QPieSeries);
719 emit q->clicked(slice);
719 emit q->clicked(slice);
720 }
720 }
721
721
722 void QPieSeriesPrivate::sliceHovered(bool state)
722 void QPieSeriesPrivate::sliceHovered(bool state)
723 {
723 {
724 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
724 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
725 Q_ASSERT(m_slices.contains(slice));
725 Q_ASSERT(m_slices.contains(slice));
726 Q_Q(QPieSeries);
726 Q_Q(QPieSeries);
727 emit q->hovered(slice, state);
727 emit q->hovered(slice, state);
728 }
728 }
729
729
730 void QPieSeriesPrivate::scaleDomain(Domain& domain)
730 void QPieSeriesPrivate::scaleDomain(Domain& domain)
731 {
731 {
732 Q_UNUSED(domain);
732 Q_UNUSED(domain);
733 // does not apply to pie
733 // does not apply to pie
734 }
734 }
735
735
736 Chart* QPieSeriesPrivate::createGraphics(ChartPresenter* presenter)
736 Chart* QPieSeriesPrivate::createGraphics(ChartPresenter* presenter)
737 {
737 {
738 Q_Q(QPieSeries);
738 Q_Q(QPieSeries);
739 PieChartItem* pie = new PieChartItem(q,presenter);
739 PieChartItem* pie = new PieChartItem(q,presenter);
740 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
740 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
741 presenter->animator()->addAnimation(pie);
741 presenter->animator()->addAnimation(pie);
742 }
742 }
743 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
743 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
744 return pie;
744 return pie;
745 }
745 }
746
746
747 QList<LegendMarker*> QPieSeriesPrivate::createLegendMarker(QLegend* legend)
747 QList<LegendMarker*> QPieSeriesPrivate::createLegendMarker(QLegend* legend)
748 {
748 {
749 Q_Q(QPieSeries);
749 Q_Q(QPieSeries);
750 QList<LegendMarker*> markers;
750 QList<LegendMarker*> markers;
751 foreach(QPieSlice* slice, q->slices()) {
751 foreach(QPieSlice* slice, q->slices()) {
752 PieLegendMarker* marker = new PieLegendMarker(q,slice,legend);
752 PieLegendMarker* marker = new PieLegendMarker(q,slice,legend);
753 markers << marker;
753 markers << marker;
754 }
754 }
755 return markers;
755 return markers;
756 }
756 }
757
757
758 QAbstractAxis* QPieSeriesPrivate::createAxisX()
758 QAbstractAxis* QPieSeriesPrivate::createAxisX(QObject* parent)
759 {
759 {
760 Q_UNUSED(parent);
760 return 0;
761 return 0;
761 }
762 }
762
763
763 QAbstractAxis* QPieSeriesPrivate::createAxisY()
764 QAbstractAxis* QPieSeriesPrivate::createAxisY(QObject* parent)
764 {
765 {
766 Q_UNUSED(parent);
765 return 0;
767 return 0;
766 }
768 }
767
769
768 #include "moc_qpieseries.cpp"
770 #include "moc_qpieseries.cpp"
769 #include "moc_qpieseries_p.cpp"
771 #include "moc_qpieseries_p.cpp"
770
772
771 QTCOMMERCIALCHART_END_NAMESPACE
773 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,86 +1,86
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef QPIESERIES_P_H
30 #ifndef QPIESERIES_P_H
31 #define QPIESERIES_P_H
31 #define QPIESERIES_P_H
32
32
33 #include "qpieseries.h"
33 #include "qpieseries.h"
34 #include "qabstractseries_p.h"
34 #include "qabstractseries_p.h"
35
35
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 class QLegendPrivate;
37 class QLegendPrivate;
38
38
39 class QPieSeriesPrivate : public QAbstractSeriesPrivate
39 class QPieSeriesPrivate : public QAbstractSeriesPrivate
40 {
40 {
41 Q_OBJECT
41 Q_OBJECT
42
42
43 public:
43 public:
44 QPieSeriesPrivate(QPieSeries *parent);
44 QPieSeriesPrivate(QPieSeries *parent);
45 ~QPieSeriesPrivate();
45 ~QPieSeriesPrivate();
46
46
47 void scaleDomain(Domain& domain);
47 void scaleDomain(Domain& domain);
48 Chart* createGraphics(ChartPresenter *presenter);
48 Chart* createGraphics(ChartPresenter *presenter);
49 QList<LegendMarker*> createLegendMarker(QLegend *legend);
49 QList<LegendMarker*> createLegendMarker(QLegend *legend);
50 QAbstractAxis* createAxisX();
50 QAbstractAxis* createAxisX(QObject* parent);
51 QAbstractAxis* createAxisY();
51 QAbstractAxis* createAxisY(QObject* parent);
52
52
53 void updateDerivativeData();
53 void updateDerivativeData();
54
54
55 static QPieSeriesPrivate* fromSeries(QPieSeries *series);
55 static QPieSeriesPrivate* fromSeries(QPieSeries *series);
56
56
57 signals:
57 signals:
58 void calculatedDataChanged();
58 void calculatedDataChanged();
59 void pieSizeChanged();
59 void pieSizeChanged();
60 void pieStartAngleChanged();
60 void pieStartAngleChanged();
61 void pieEndAngleChanged();
61 void pieEndAngleChanged();
62 void horizontalPositionChanged();
62 void horizontalPositionChanged();
63 void verticalPositionChanged();
63 void verticalPositionChanged();
64
64
65 public Q_SLOTS:
65 public Q_SLOTS:
66 void sliceValueChanged();
66 void sliceValueChanged();
67 void sliceClicked();
67 void sliceClicked();
68 void sliceHovered(bool state);
68 void sliceHovered(bool state);
69
69
70 private:
70 private:
71 QList<QPieSlice*> m_slices;
71 QList<QPieSlice*> m_slices;
72 qreal m_pieRelativeHorPos;
72 qreal m_pieRelativeHorPos;
73 qreal m_pieRelativeVerPos;
73 qreal m_pieRelativeVerPos;
74 qreal m_pieRelativeSize;
74 qreal m_pieRelativeSize;
75 qreal m_pieStartAngle;
75 qreal m_pieStartAngle;
76 qreal m_pieEndAngle;
76 qreal m_pieEndAngle;
77 qreal m_sum;
77 qreal m_sum;
78
78
79 private:
79 private:
80 friend class QLegendPrivate;
80 friend class QLegendPrivate;
81 Q_DECLARE_PUBLIC(QPieSeries)
81 Q_DECLARE_PUBLIC(QPieSeries)
82 };
82 };
83
83
84 QTCOMMERCIALCHART_END_NAMESPACE
84 QTCOMMERCIALCHART_END_NAMESPACE
85
85
86 #endif // QPIESERIES_P_H
86 #endif // QPIESERIES_P_H
@@ -1,71 +1,71
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef QABSTRACTSERIES_P_H
30 #ifndef QABSTRACTSERIES_P_H
31 #define QABSTRACTSERIES_P_H
31 #define QABSTRACTSERIES_P_H
32
32
33 #include "qabstractseries.h"
33 #include "qabstractseries.h"
34
34
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36
36
37 class Domain;
37 class Domain;
38 class ChartPresenter;
38 class ChartPresenter;
39 class Chart;
39 class Chart;
40 class LegendMarker;
40 class LegendMarker;
41 class QLegend;
41 class QLegend;
42 class ChartDataSet;
42 class ChartDataSet;
43 class QAbstractAxis;
43 class QAbstractAxis;
44
44
45 class QAbstractSeriesPrivate : public QObject
45 class QAbstractSeriesPrivate : public QObject
46 {
46 {
47 Q_OBJECT
47 Q_OBJECT
48 public:
48 public:
49 QAbstractSeriesPrivate(QAbstractSeries *q);
49 QAbstractSeriesPrivate(QAbstractSeries *q);
50 ~QAbstractSeriesPrivate();
50 ~QAbstractSeriesPrivate();
51
51
52 virtual void scaleDomain(Domain& domain) = 0;
52 virtual void scaleDomain(Domain& domain) = 0;
53 virtual Chart* createGraphics(ChartPresenter* presenter) = 0;
53 virtual Chart* createGraphics(ChartPresenter* presenter) = 0;
54 virtual QList<LegendMarker*> createLegendMarker(QLegend* legend) = 0;
54 virtual QList<LegendMarker*> createLegendMarker(QLegend* legend) = 0;
55 virtual QAbstractAxis* createAxisX() = 0;
55 virtual QAbstractAxis* createAxisX(QObject* parent) = 0;
56 virtual QAbstractAxis* createAxisY() = 0;
56 virtual QAbstractAxis* createAxisY(QObject* parent) = 0;
57
57
58 protected:
58 protected:
59 QAbstractSeries *q_ptr;
59 QAbstractSeries *q_ptr;
60 QChart *m_chart;
60 QChart *m_chart;
61 ChartDataSet *m_dataset;
61 ChartDataSet *m_dataset;
62 QString m_name;
62 QString m_name;
63 bool m_visible;
63 bool m_visible;
64
64
65 friend class QAbstractSeries;
65 friend class QAbstractSeries;
66 friend class ChartDataSet;
66 friend class ChartDataSet;
67 };
67 };
68
68
69 QTCOMMERCIALCHART_END_NAMESPACE
69 QTCOMMERCIALCHART_END_NAMESPACE
70
70
71 #endif
71 #endif
@@ -1,439 +1,435
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "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 <QGraphicsScene>
27 #include <QGraphicsScene>
28 #include <QGraphicsSceneResizeEvent>
28 #include <QGraphicsSceneResizeEvent>
29 #include <QGraphicsLayout>
29 #include <QGraphicsLayout>
30
30
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32
32
33 /*!
33 /*!
34 \enum QChart::ChartTheme
34 \enum QChart::ChartTheme
35
35
36 This enum describes the theme used by the chart.
36 This enum describes the theme used by the chart.
37
37
38 \value ChartThemeLight The default theme
38 \value ChartThemeLight The default theme
39 \value ChartThemeBlueCerulean
39 \value ChartThemeBlueCerulean
40 \value ChartThemeDark
40 \value ChartThemeDark
41 \value ChartThemeBrownSand
41 \value ChartThemeBrownSand
42 \value ChartThemeBlueNcs
42 \value ChartThemeBlueNcs
43 \value ChartThemeHighContrast
43 \value ChartThemeHighContrast
44 \value ChartThemeBlueIcy
44 \value ChartThemeBlueIcy
45 */
45 */
46
46
47 /*!
47 /*!
48 \enum QChart::AnimationOption
48 \enum QChart::AnimationOption
49
49
50 For enabling/disabling animations. Defaults to NoAnimation.
50 For enabling/disabling animations. Defaults to NoAnimation.
51
51
52 \value NoAnimation
52 \value NoAnimation
53 \value GridAxisAnimations
53 \value GridAxisAnimations
54 \value SeriesAnimations
54 \value SeriesAnimations
55 \value AllAnimations
55 \value AllAnimations
56 */
56 */
57
57
58 /*!
58 /*!
59 \class QChart
59 \class QChart
60 \brief QtCommercial chart API.
60 \brief QtCommercial chart API.
61
61
62 QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical
62 QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical
63 representation of different types of series and other chart related objects like
63 representation of different types of series and other chart related objects like
64 QAxis and QLegend. If you simply want to show a chart in a layout, you can use the
64 QAxis and QLegend. If you simply want to show a chart in a layout, you can use the
65 convenience class QChartView instead of QChart.
65 convenience class QChartView instead of QChart.
66 \sa QChartView
66 \sa QChartView
67 */
67 */
68
68
69 /*!
69 /*!
70 \property QChart::animationOptions
70 \property QChart::animationOptions
71 The animation \a options for the chart. Animations are enabled/disabled based on this setting.
71 The animation \a options for the chart. Animations are enabled/disabled based on this setting.
72 */
72 */
73
73
74 /*!
74 /*!
75 \property QChart::backgroundVisible
75 \property QChart::backgroundVisible
76 Whether the chart background is visible or not.
76 Whether the chart background is visible or not.
77 \sa setBackgroundBrush(), setBackgroundPen()
77 \sa setBackgroundBrush(), setBackgroundPen()
78 */
78 */
79
79
80 /*!
80 /*!
81 \property QChart::dropShadowEnabled
81 \property QChart::dropShadowEnabled
82 If set to true, the background drop shadow effect is enabled. If set to false, it is disabled. Note that the drop
82 If set to true, the background drop shadow effect is enabled. If set to false, it is disabled. Note that the drop
83 shadow effect depends on theme, which means the setting may be changed if you switch to another theme.
83 shadow effect depends on theme, which means the setting may be changed if you switch to another theme.
84 */
84 */
85
85
86 /*!
86 /*!
87 \property QChart::margins
87 \property QChart::margins
88 Margins around the plot area. Note that the margin area is used for drawing chart title, legend and axes.
88 Margins around the plot area. Note that the margin area is used for drawing chart title, legend and axes.
89 */
89 */
90
90
91 /*!
91 /*!
92 \property QChart::theme
92 \property QChart::theme
93 Theme is a built-in collection of UI style related settings applied for all visual elements of a chart, like colors,
93 Theme is a built-in collection of UI style related settings applied for all visual elements of a chart, like colors,
94 pens, brushes and fonts of series, axes, title and legend. \l {Chart themes demo} shows an example with a few
94 pens, brushes and fonts of series, axes, title and legend. \l {Chart themes demo} shows an example with a few
95 different themes.
95 different themes.
96 Note: changing the theme will overwrite all customizations previously applied to the series.
96 Note: changing the theme will overwrite all customizations previously applied to the series.
97 */
97 */
98
98
99 /*!
99 /*!
100 \property QChart::title
100 \property QChart::title
101 Title is the name (label) of a chart. It is shown as a headline on top of the chart.
101 Title is the name (label) of a chart. It is shown as a headline on top of the chart.
102 */
102 */
103
103
104 /*!
104 /*!
105 \fn void QChart::marginsChanged(QRectF newMargins)
105 \fn void QChart::marginsChanged(QRectF newMargins)
106 The margins around plot area have changed to \a newMargins. This may happen for example if you change title font size,
106 The margins around plot area have changed to \a newMargins. This may happen for example if you change title font size,
107 modify axes or hide/show legend.
107 modify axes or hide/show legend.
108 */
108 */
109
109
110 /*!
110 /*!
111 Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor.
111 Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor.
112 */
112 */
113 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags),
113 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags),
114 d_ptr(new QChartPrivate())
114 d_ptr(new QChartPrivate())
115 {
115 {
116 d_ptr->m_dataset = new ChartDataSet(this);
116 d_ptr->m_dataset = new ChartDataSet(this);
117 d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset);
117 d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset);
118 d_ptr->createConnections();
118 d_ptr->createConnections();
119 d_ptr->m_legend = new LegendScroller(this);
119 d_ptr->m_legend = new LegendScroller(this);
120 d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false);
120 d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false);
121 //connect(d_ptr->m_presenter, SIGNAL(marginsChanged(QRectF)), this, SIGNAL(marginsChanged(QRectF)));
121 //connect(d_ptr->m_presenter, SIGNAL(marginsChanged(QRectF)), this, SIGNAL(marginsChanged(QRectF)));
122 setLayout(d_ptr->m_presenter->layout());
122 setLayout(d_ptr->m_presenter->layout());
123 }
123 }
124
124
125 /*!
125 /*!
126 Destroys the object and it's children, like series and axis objects added to it.
126 Destroys the object and it's children, like series and axis objects added to it.
127 */
127 */
128 QChart::~QChart()
128 QChart::~QChart()
129 {
129 {
130 //delete first presenter , since this is a root of all the graphical items
130 //delete first presenter , since this is a root of all the graphical items
131 setLayout(0);
131 setLayout(0);
132 delete d_ptr->m_presenter;
132 delete d_ptr->m_presenter;
133 d_ptr->m_presenter=0;
133 d_ptr->m_presenter=0;
134 }
134 }
135
135
136 /*!
136 /*!
137 Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects.
137 Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects.
138 If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and
138 If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and
139 the y axis).
139 the y axis).
140
140
141 \sa removeSeries(), removeAllSeries()
141 \sa removeSeries(), removeAllSeries()
142 */
142 */
143 void QChart::addSeries(QAbstractSeries *series)
143 void QChart::addSeries(QAbstractSeries *series)
144 {
144 {
145 Q_ASSERT(series);
145 Q_ASSERT(series);
146 d_ptr->m_dataset->addSeries(series);
146 d_ptr->m_dataset->addSeries(series);
147 }
147 }
148
148
149 /*!
149 /*!
150 Removes the \a series specified in a perameter from the QChartView.
150 Removes the \a series specified in a perameter from the QChartView.
151 It releses its ownership of the specified QChartSeries object.
151 It releses its ownership of the specified QChartSeries object.
152 It does not delete the pointed QChartSeries data object
152 It does not delete the pointed QChartSeries data object
153 \sa addSeries(), removeAllSeries()
153 \sa addSeries(), removeAllSeries()
154 */
154 */
155 void QChart::removeSeries(QAbstractSeries *series)
155 void QChart::removeSeries(QAbstractSeries *series)
156 {
156 {
157 Q_ASSERT(series);
157 Q_ASSERT(series);
158 d_ptr->m_dataset->removeSeries(series);
158 d_ptr->m_dataset->removeSeries(series);
159 }
159 }
160
160
161 /*!
161 /*!
162 Removes all the QChartSeries that have been added to the QChartView
162 Removes all the QChartSeries that have been added to the QChartView
163 It also deletes the pointed QChartSeries data objects
163 It also deletes the pointed QChartSeries data objects
164 \sa addSeries(), removeSeries()
164 \sa addSeries(), removeSeries()
165 */
165 */
166 void QChart::removeAllSeries()
166 void QChart::removeAllSeries()
167 {
167 {
168 d_ptr->m_dataset->removeAllSeries();
168 d_ptr->m_dataset->removeAllSeries();
169 }
169 }
170
170
171 /*!
171 /*!
172 Sets the \a brush that is used for painting the background of the chart area.
172 Sets the \a brush that is used for painting the background of the chart area.
173 */
173 */
174 void QChart::setBackgroundBrush(const QBrush& brush)
174 void QChart::setBackgroundBrush(const QBrush& brush)
175 {
175 {
176 d_ptr->m_presenter->setBackgroundBrush(brush);
176 d_ptr->m_presenter->setBackgroundBrush(brush);
177 }
177 }
178
178
179 /*!
179 /*!
180 Gets the brush that is used for painting the background of the chart area.
180 Gets the brush that is used for painting the background of the chart area.
181 */
181 */
182 QBrush QChart::backgroundBrush() const
182 QBrush QChart::backgroundBrush() const
183 {
183 {
184 return d_ptr->m_presenter->backgroundBrush();
184 return d_ptr->m_presenter->backgroundBrush();
185 }
185 }
186
186
187 /*!
187 /*!
188 Sets the \a pen that is used for painting the background of the chart area.
188 Sets the \a pen that is used for painting the background of the chart area.
189 */
189 */
190 void QChart::setBackgroundPen(const QPen& pen)
190 void QChart::setBackgroundPen(const QPen& pen)
191 {
191 {
192 d_ptr->m_presenter->setBackgroundPen(pen);
192 d_ptr->m_presenter->setBackgroundPen(pen);
193 }
193 }
194
194
195 /*!
195 /*!
196 Gets the pen that is used for painting the background of the chart area.
196 Gets the pen that is used for painting the background of the chart area.
197 */
197 */
198 QPen QChart::backgroundPen() const
198 QPen QChart::backgroundPen() const
199 {
199 {
200 return d_ptr->m_presenter->backgroundPen();
200 return d_ptr->m_presenter->backgroundPen();
201 }
201 }
202
202
203 /*!
203 /*!
204 Sets the chart \a title. The description text that is drawn above the chart.
204 Sets the chart \a title. The description text that is drawn above the chart.
205 */
205 */
206 void QChart::setTitle(const QString& title)
206 void QChart::setTitle(const QString& title)
207 {
207 {
208 d_ptr->m_presenter->setTitle(title);
208 d_ptr->m_presenter->setTitle(title);
209 }
209 }
210
210
211 /*!
211 /*!
212 Returns the chart title. The description text that is drawn above the chart.
212 Returns the chart title. The description text that is drawn above the chart.
213 */
213 */
214 QString QChart::title() const
214 QString QChart::title() const
215 {
215 {
216 return d_ptr->m_presenter->title();
216 return d_ptr->m_presenter->title();
217 }
217 }
218
218
219 /*!
219 /*!
220 Sets the \a font that is used for drawing the chart description text that is rendered above the chart.
220 Sets the \a font that is used for drawing the chart description text that is rendered above the chart.
221 */
221 */
222 void QChart::setTitleFont(const QFont& font)
222 void QChart::setTitleFont(const QFont& font)
223 {
223 {
224 d_ptr->m_presenter->setTitleFont(font);
224 d_ptr->m_presenter->setTitleFont(font);
225 }
225 }
226
226
227 /*!
227 /*!
228 Gets the font that is used for drawing the chart description text that is rendered above the chart.
228 Gets the font that is used for drawing the chart description text that is rendered above the chart.
229 */
229 */
230 QFont QChart::titleFont() const
230 QFont QChart::titleFont() const
231 {
231 {
232 return d_ptr->m_presenter->titleFont();
232 return d_ptr->m_presenter->titleFont();
233 }
233 }
234
234
235 /*!
235 /*!
236 Sets the \a brush used for rendering the title text.
236 Sets the \a brush used for rendering the title text.
237 */
237 */
238 void QChart::setTitleBrush(const QBrush &brush)
238 void QChart::setTitleBrush(const QBrush &brush)
239 {
239 {
240 d_ptr->m_presenter->setTitleBrush(brush);
240 d_ptr->m_presenter->setTitleBrush(brush);
241 }
241 }
242
242
243 /*!
243 /*!
244 Returns the brush used for rendering the title text.
244 Returns the brush used for rendering the title text.
245 */
245 */
246 QBrush QChart::titleBrush() const
246 QBrush QChart::titleBrush() const
247 {
247 {
248 return d_ptr->m_presenter->titleBrush();
248 return d_ptr->m_presenter->titleBrush();
249 }
249 }
250
250
251 void QChart::setTheme(QChart::ChartTheme theme)
251 void QChart::setTheme(QChart::ChartTheme theme)
252 {
252 {
253 d_ptr->m_presenter->setTheme(theme);
253 d_ptr->m_presenter->setTheme(theme);
254 }
254 }
255
255
256 QChart::ChartTheme QChart::theme() const
256 QChart::ChartTheme QChart::theme() const
257 {
257 {
258 return d_ptr->m_presenter->theme();
258 return d_ptr->m_presenter->theme();
259 }
259 }
260
260
261 /*!
261 /*!
262 Zooms in the view by a factor of 2
262 Zooms in the view by a factor of 2
263 */
263 */
264 void QChart::zoomIn()
264 void QChart::zoomIn()
265 {
265 {
266 d_ptr->m_presenter->zoomIn(2.0);
266 d_ptr->m_presenter->zoomIn(2.0);
267 }
267 }
268
268
269 /*!
269 /*!
270 Zooms in the view to a maximum level at which \a rect is still fully visible.
270 Zooms in the view to a maximum level at which \a rect is still fully visible.
271 */
271 */
272 void QChart::zoomIn(const QRectF& rect)
272 void QChart::zoomIn(const QRectF& rect)
273 {
273 {
274 if (!rect.isValid()) return;
274 if (!rect.isValid()) return;
275 d_ptr->m_presenter->zoomIn(rect);
275 d_ptr->m_presenter->zoomIn(rect);
276 }
276 }
277
277
278 /*!
278 /*!
279 Restores the view zoom level to the previous one.
279 Restores the view zoom level to the previous one.
280 */
280 */
281 void QChart::zoomOut()
281 void QChart::zoomOut()
282 {
282 {
283 d_ptr->m_presenter->zoomOut(2.0);
283 d_ptr->m_presenter->zoomOut(2.0);
284 }
284 }
285
285
286 /*!
286 /*!
287 Zooms in the view by a \a factor.
287 Zooms in the view by a \a factor.
288
288
289 A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out.
289 A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out.
290 */
290 */
291 void QChart::zoom(qreal factor)
291 void QChart::zoom(qreal factor)
292 {
292 {
293 if (qFuzzyIsNull(factor))
293 if (qFuzzyIsNull(factor))
294 return;
294 return;
295
295
296 if (qFuzzyCompare(factor, 1.0))
296 if (qFuzzyCompare(factor, 1.0))
297 return;
297 return;
298
298
299 if (factor < 0)
299 if (factor < 0)
300 return;
300 return;
301
301
302 if (factor > 1.0)
302 if (factor > 1.0)
303 d_ptr->m_presenter->zoomIn(factor);
303 d_ptr->m_presenter->zoomIn(factor);
304 else
304 else
305 d_ptr->m_presenter->zoomOut(1.0 / factor);
305 d_ptr->m_presenter->zoomOut(1.0 / factor);
306 }
306 }
307
307
308 /*!
308 /*!
309 Returns the pointer to the x axis object of the chart
309 Returns the pointer to the x axis object of the chart
310 */
310 */
311 QAbstractAxis* QChart::axisX(QAbstractSeries* series) const
311 QAbstractAxis* QChart::axisX(QAbstractSeries* series) const
312 {
312 {
313 return d_ptr->m_dataset->axisX(series);
313 return d_ptr->m_dataset->axisX(series);
314 }
314 }
315
315
316 /*!
316 /*!
317 Returns the pointer to the y axis object of the \a series
317 Returns the pointer to the y axis object of the \a series
318 If no \a series is provided then default Y axis of the chart is returned.
318 If no \a series is provided then default Y axis of the chart is returned.
319 */
319 */
320 QAbstractAxis* QChart::axisY(QAbstractSeries *series) const
320 QAbstractAxis* QChart::axisY(QAbstractSeries *series) const
321 {
321 {
322 return d_ptr->m_dataset->axisY(series);
322 return d_ptr->m_dataset->axisY(series);
323 }
323 }
324
324
325 /*!
325 /*!
326 Returns the legend object of the chart. Ownership stays in chart.
326 Returns the legend object of the chart. Ownership stays in chart.
327 */
327 */
328 QLegend* QChart::legend() const
328 QLegend* QChart::legend() const
329 {
329 {
330 return d_ptr->m_legend;
330 return d_ptr->m_legend;
331 }
331 }
332
332
333 /*!
333 /*!
334 Returns the rect that contains information about margins (distance between chart widget edge and axes).
334 Returns the rect that contains information about margins (distance between chart widget edge and axes).
335 Individual margins can be obtained by calling left, top, right, bottom on the returned rect.
335 Individual margins can be obtained by calling left, top, right, bottom on the returned rect.
336 */
336 */
337 QRectF QChart::margins() const
337 QRectF QChart::margins() const
338 {
338 {
339 return d_ptr->m_presenter->margins();
339 return d_ptr->m_presenter->margins();
340 }
340 }
341
341
342 /*!
342 /*!
343 Sets animation \a options for the chart
343 Sets animation \a options for the chart
344 */
344 */
345
345
346 void QChart::setAnimationOptions(AnimationOptions options)
346 void QChart::setAnimationOptions(AnimationOptions options)
347 {
347 {
348 d_ptr->m_presenter->setAnimationOptions(options);
348 d_ptr->m_presenter->setAnimationOptions(options);
349 }
349 }
350
350
351 QChart::AnimationOptions QChart::animationOptions() const
351 QChart::AnimationOptions QChart::animationOptions() const
352 {
352 {
353 return d_ptr->m_presenter->animationOptions();
353 return d_ptr->m_presenter->animationOptions();
354 }
354 }
355
355
356 /*!
356 /*!
357 Scrolls the visible area of the chart by the distance defined in the \a delta.
357 Scrolls the visible area of the chart by the distance defined in the \a delta.
358 */
358 */
359 void QChart::scroll(qreal dx, qreal dy)
359 void QChart::scroll(qreal dx, qreal dy)
360 {
360 {
361 d_ptr->m_presenter->scroll(dx, dy);
361 d_ptr->m_presenter->scroll(dx, dy);
362 }
362 }
363
363
364 void QChart::setBackgroundVisible(bool visible)
364 void QChart::setBackgroundVisible(bool visible)
365 {
365 {
366 d_ptr->m_presenter->setBackgroundVisible(visible);
366 d_ptr->m_presenter->setBackgroundVisible(visible);
367 }
367 }
368
368
369 bool QChart::isBackgroundVisible() const
369 bool QChart::isBackgroundVisible() const
370 {
370 {
371 return d_ptr->m_presenter->isBackgroundVisible();
371 return d_ptr->m_presenter->isBackgroundVisible();
372 }
372 }
373
373
374 void QChart::setDropShadowEnabled(bool enabled)
374 void QChart::setDropShadowEnabled(bool enabled)
375 {
375 {
376 d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled);
376 d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled);
377 }
377 }
378
378
379 bool QChart::isDropShadowEnabled() const
379 bool QChart::isDropShadowEnabled() const
380 {
380 {
381 return d_ptr->m_presenter->isBackgroundDropShadowEnabled();
381 return d_ptr->m_presenter->isBackgroundDropShadowEnabled();
382 }
382 }
383
383
384 /*!
384 /*!
385 Returns all the series that are added to the chart.
385 Returns all the series that are added to the chart.
386
386
387 \sa addSeries(), removeSeries(), removeAllSeries()
387 \sa addSeries(), removeSeries(), removeAllSeries()
388 */
388 */
389 QList<QAbstractSeries*> QChart::series() const
389 QList<QAbstractSeries*> QChart::series() const
390 {
390 {
391 return d_ptr->m_dataset->series();
391 return d_ptr->m_dataset->series();
392 }
392 }
393
393
394 void QChart::setMarginsMinimum(const QRectF& margins)
394 void QChart::setMarginsMinimum(const QRectF& margins)
395 {
395 {
396 d_ptr->m_presenter->setMarginsMinimum(margins);
396 d_ptr->m_presenter->setMarginsMinimum(margins);
397 }
397 }
398
398
399 void QChart::setAxisX(QAbstractSeries *series, QAbstractAxis* axis)
399 void QChart::setAxisX(QAbstractSeries *series, QAbstractAxis* axis)
400 {
400 {
401 // Q_UNUSED(series);
402 // Q_UNUSED(axis);
403 d_ptr->m_dataset->setAxisX(series, axis);
401 d_ptr->m_dataset->setAxisX(series, axis);
404 }
402 }
405
403
406 void QChart::setAxisY(QAbstractSeries *series, QAbstractAxis* axis)
404 void QChart::setAxisY(QAbstractSeries *series, QAbstractAxis* axis)
407 {
405 {
408 // Q_UNUSED(series);
409 // Q_UNUSED(axis);
410 d_ptr->m_dataset->setAxisY(series, axis);
406 d_ptr->m_dataset->setAxisY(series, axis);
411 }
407 }
412
408
413 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
409 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
414
410
415 QChartPrivate::QChartPrivate():
411 QChartPrivate::QChartPrivate():
416 m_legend(0),
412 m_legend(0),
417 m_dataset(0),
413 m_dataset(0),
418 m_presenter(0)
414 m_presenter(0)
419 {
415 {
420
416
421 }
417 }
422
418
423 QChartPrivate::~QChartPrivate()
419 QChartPrivate::~QChartPrivate()
424 {
420 {
425
421
426 }
422 }
427
423
428 void QChartPrivate::createConnections()
424 void QChartPrivate::createConnections()
429 {
425 {
430 QObject::connect(m_dataset,SIGNAL(seriesAdded(QAbstractSeries*,Domain*)),m_presenter,SLOT(handleSeriesAdded(QAbstractSeries*,Domain*)));
426 QObject::connect(m_dataset,SIGNAL(seriesAdded(QAbstractSeries*,Domain*)),m_presenter,SLOT(handleSeriesAdded(QAbstractSeries*,Domain*)));
431 QObject::connect(m_dataset,SIGNAL(seriesRemoved(QAbstractSeries*)),m_presenter,SLOT(handleSeriesRemoved(QAbstractSeries*)));
427 QObject::connect(m_dataset,SIGNAL(seriesRemoved(QAbstractSeries*)),m_presenter,SLOT(handleSeriesRemoved(QAbstractSeries*)));
432 QObject::connect(m_dataset,SIGNAL(axisAdded(QAbstractAxis*,Domain*)),m_presenter,SLOT(handleAxisAdded(QAbstractAxis*,Domain*)));
428 QObject::connect(m_dataset,SIGNAL(axisAdded(QAbstractAxis*,Domain*)),m_presenter,SLOT(handleAxisAdded(QAbstractAxis*,Domain*)));
433 QObject::connect(m_dataset,SIGNAL(axisRemoved(QAbstractAxis*)),m_presenter,SLOT(handleAxisRemoved(QAbstractAxis*)));
429 QObject::connect(m_dataset,SIGNAL(axisRemoved(QAbstractAxis*)),m_presenter,SLOT(handleAxisRemoved(QAbstractAxis*)));
434 //QObject::connect(m_presenter, SIGNAL(marginsChanged(QRectF)), q_ptr, SIGNAL(marginsChanged(QRectF)));
430 //QObject::connect(m_presenter, SIGNAL(marginsChanged(QRectF)), q_ptr, SIGNAL(marginsChanged(QRectF)));
435 }
431 }
436
432
437 #include "moc_qchart.cpp"
433 #include "moc_qchart.cpp"
438
434
439 QTCOMMERCIALCHART_END_NAMESPACE
435 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,268 +1,254
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qscatterseries.h"
21 #include "qscatterseries.h"
22 #include "qscatterseries_p.h"
22 #include "qscatterseries_p.h"
23 #include "scatterchartitem_p.h"
23 #include "scatterchartitem_p.h"
24 #include "chartdataset_p.h"
24 #include "chartdataset_p.h"
25 #include "charttheme_p.h"
25 #include "charttheme_p.h"
26 #include "chartanimator_p.h"
26 #include "chartanimator_p.h"
27 #include "qvaluesaxis.h"
28
27
29 /*!
28 /*!
30 \class QScatterSeries
29 \class QScatterSeries
31 \brief The QScatterSeries class is used for making scatter charts.
30 \brief The QScatterSeries class is used for making scatter charts.
32
31
33 \mainclass
32 \mainclass
34
33
35 The scatter data is displayed as a collection of points on the chart. Each point determines the position on the horizontal axis
34 The scatter data is displayed as a collection of points on the chart. Each point determines the position on the horizontal axis
36 and the vertical axis.
35 and the vertical axis.
37
36
38 \image examples_scatterchart.png
37 \image examples_scatterchart.png
39
38
40 Creating basic scatter chart is simple:
39 Creating basic scatter chart is simple:
41 \code
40 \code
42 QScatterSeries* series = new QScatterSeries();
41 QScatterSeries* series = new QScatterSeries();
43 series->append(0, 6);
42 series->append(0, 6);
44 series->append(2, 4);
43 series->append(2, 4);
45 ...
44 ...
46 chart->addSeries(series);
45 chart->addSeries(series);
47 \endcode
46 \endcode
48 */
47 */
49 /*!
48 /*!
50 \qmlclass ScatterSeries QScatterSeries
49 \qmlclass ScatterSeries QScatterSeries
51 \inherits XYSeries
50 \inherits XYSeries
52
51
53 The following QML shows how to create a chart with two simple scatter series:
52 The following QML shows how to create a chart with two simple scatter series:
54 \snippet ../demos/qmlchart/qml/qmlchart/View5.qml 1
53 \snippet ../demos/qmlchart/qml/qmlchart/View5.qml 1
55 \snippet ../demos/qmlchart/qml/qmlchart/View5.qml 2
54 \snippet ../demos/qmlchart/qml/qmlchart/View5.qml 2
56
55
57 \beginfloatleft
56 \beginfloatleft
58 \image demos_qmlchart5.png
57 \image demos_qmlchart5.png
59 \endfloat
58 \endfloat
60 \clearfloat
59 \clearfloat
61 */
60 */
62
61
63 /*!
62 /*!
64 \enum QScatterSeries::MarkerShape
63 \enum QScatterSeries::MarkerShape
65
64
66 This enum describes the shape used when rendering marker items.
65 This enum describes the shape used when rendering marker items.
67
66
68 \value MarkerShapeCircle
67 \value MarkerShapeCircle
69 \value MarkerShapeRectangle
68 \value MarkerShapeRectangle
70 */
69 */
71
70
72 /*!
71 /*!
73 \property QScatterSeries::color
72 \property QScatterSeries::color
74 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.
75 \sa QScatterSeries::brush()
74 \sa QScatterSeries::brush()
76 */
75 */
77
76
78 /*!
77 /*!
79 \property QScatterSeries::borderColor
78 \property QScatterSeries::borderColor
80 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.
81 \sa QScatterSeries::pen()
80 \sa QScatterSeries::pen()
82 */
81 */
83
82
84 /*!
83 /*!
85 \property QScatterSeries::markerShape
84 \property QScatterSeries::markerShape
86 Defines the shape of the marker used to draw the points in the series. The default shape is MarkerShapeCircle.
85 Defines the shape of the marker used to draw the points in the series. The default shape is MarkerShapeCircle.
87 */
86 */
88 /*!
87 /*!
89 \qmlproperty MarkerShape ScatterSeries::markerShape
88 \qmlproperty MarkerShape ScatterSeries::markerShape
90 Defines the shape of the marker used to draw the points in the series. One of ScatterSeries
89 Defines the shape of the marker used to draw the points in the series. One of ScatterSeries
91 ScatterSeries.MarkerShapeCircle or ScatterSeries.MarkerShapeRectangle.
90 ScatterSeries.MarkerShapeCircle or ScatterSeries.MarkerShapeRectangle.
92 The default shape is ScatterSeries.MarkerShapeCircle.
91 The default shape is ScatterSeries.MarkerShapeCircle.
93 */
92 */
94
93
95 /*!
94 /*!
96 \property QScatterSeries::markerSize
95 \property QScatterSeries::markerSize
97 Defines the size of the marker used to draw the points in the series. The default size is 15.0.
96 Defines the size of the marker used to draw the points in the series. The default size is 15.0.
98 */
97 */
99 /*!
98 /*!
100 \qmlproperty real ScatterSeries::markerSize
99 \qmlproperty real ScatterSeries::markerSize
101 Defines the size of the marker used to draw the points in the series. The default size is 15.0.
100 Defines the size of the marker used to draw the points in the series. The default size is 15.0.
102 */
101 */
103
102
104 /*!
103 /*!
105 \fn void QScatterSeries::colorChanged(QColor color)
104 \fn void QScatterSeries::colorChanged(QColor color)
106 Signal is emitted when the fill (brush) color has changed to \a color.
105 Signal is emitted when the fill (brush) color has changed to \a color.
107 */
106 */
108
107
109 /*!
108 /*!
110 \fn void QScatterSeries::borderColorChanged(QColor color)
109 \fn void QScatterSeries::borderColorChanged(QColor color)
111 Signal is emitted when the line (pen) color has changed to \a color.
110 Signal is emitted when the line (pen) color has changed to \a color.
112 */
111 */
113 /*!
112 /*!
114 \qmlsignal ScatterSeries::borderColorChanged(color color)
113 \qmlsignal ScatterSeries::borderColorChanged(color color)
115 Signal is emitted when the line (pen) color has changed to \a color.
114 Signal is emitted when the line (pen) color has changed to \a color.
116 */
115 */
117
116
118 /*!
117 /*!
119 \fn QChartSeriesType QScatterSeries::type() const
118 \fn QChartSeriesType QScatterSeries::type() const
120 Returns QChartSeries::SeriesTypeScatter.
119 Returns QChartSeries::SeriesTypeScatter.
121 \sa QAbstractSeries, SeriesType
120 \sa QAbstractSeries, SeriesType
122 */
121 */
123
122
124 QTCOMMERCIALCHART_BEGIN_NAMESPACE
123 QTCOMMERCIALCHART_BEGIN_NAMESPACE
125
124
126 /*!
125 /*!
127 Constructs a series object which is a child of \a parent.
126 Constructs a series object which is a child of \a parent.
128 */
127 */
129 QScatterSeries::QScatterSeries(QObject *parent) : QXYSeries(*new QScatterSeriesPrivate(this),parent)
128 QScatterSeries::QScatterSeries(QObject *parent) : QXYSeries(*new QScatterSeriesPrivate(this),parent)
130 {
129 {
131 }
130 }
132
131
133 /*!
132 /*!
134 Destroys the object. Note that adding series to QChart transfers the ownership to the chart.
133 Destroys the object. Note that adding series to QChart transfers the ownership to the chart.
135 */
134 */
136 QScatterSeries::~QScatterSeries()
135 QScatterSeries::~QScatterSeries()
137 {
136 {
138 Q_D(QScatterSeries);
137 Q_D(QScatterSeries);
139 if(d->m_dataset) {
138 if(d->m_dataset) {
140 d->m_dataset->removeSeries(this);
139 d->m_dataset->removeSeries(this);
141 }
140 }
142 }
141 }
143
142
144 QAbstractSeries::SeriesType QScatterSeries::type() const
143 QAbstractSeries::SeriesType QScatterSeries::type() const
145 {
144 {
146 return QAbstractSeries::SeriesTypeScatter;
145 return QAbstractSeries::SeriesTypeScatter;
147 }
146 }
148
147
149 void QScatterSeries::setPen(const QPen &pen)
148 void QScatterSeries::setPen(const QPen &pen)
150 {
149 {
151 Q_D(QXYSeries);
150 Q_D(QXYSeries);
152 if (d->m_pen != pen) {
151 if (d->m_pen != pen) {
153 bool emitColorChanged = d->m_pen.color() != pen.color();
152 bool emitColorChanged = d->m_pen.color() != pen.color();
154 d->m_pen = pen;
153 d->m_pen = pen;
155 emit d->updated();
154 emit d->updated();
156 if (emitColorChanged)
155 if (emitColorChanged)
157 emit borderColorChanged(pen.color());
156 emit borderColorChanged(pen.color());
158 }
157 }
159 }
158 }
160
159
161 void QScatterSeries::setBrush(const QBrush &brush)
160 void QScatterSeries::setBrush(const QBrush &brush)
162 {
161 {
163 Q_D(QScatterSeries);
162 Q_D(QScatterSeries);
164 if (d->m_brush != brush) {
163 if (d->m_brush != brush) {
165 bool emitColorChanged = d->m_brush.color() != brush.color();
164 bool emitColorChanged = d->m_brush.color() != brush.color();
166 d->m_brush = brush;
165 d->m_brush = brush;
167 emit d->updated();
166 emit d->updated();
168 if (emitColorChanged)
167 if (emitColorChanged)
169 emit colorChanged(brush.color());
168 emit colorChanged(brush.color());
170 }
169 }
171 }
170 }
172
171
173 void QScatterSeries::setColor(const QColor &color)
172 void QScatterSeries::setColor(const QColor &color)
174 {
173 {
175 QBrush b = brush();
174 QBrush b = brush();
176 if (b.color() != color) {
175 if (b.color() != color) {
177 b.setColor(color);
176 b.setColor(color);
178 setBrush(b);
177 setBrush(b);
179 }
178 }
180 }
179 }
181
180
182 QColor QScatterSeries::color() const
181 QColor QScatterSeries::color() const
183 {
182 {
184 return brush().color();
183 return brush().color();
185 }
184 }
186
185
187 void QScatterSeries::setBorderColor(const QColor &color)
186 void QScatterSeries::setBorderColor(const QColor &color)
188 {
187 {
189 QPen p = pen();
188 QPen p = pen();
190 if (p.color() != color) {
189 if (p.color() != color) {
191 p.setColor(color);
190 p.setColor(color);
192 setPen(p);
191 setPen(p);
193 }
192 }
194 }
193 }
195
194
196 QColor QScatterSeries::borderColor() const
195 QColor QScatterSeries::borderColor() const
197 {
196 {
198 return pen().color();
197 return pen().color();
199 }
198 }
200
199
201 QScatterSeries::MarkerShape QScatterSeries::markerShape() const
200 QScatterSeries::MarkerShape QScatterSeries::markerShape() const
202 {
201 {
203 Q_D(const QScatterSeries);
202 Q_D(const QScatterSeries);
204 return d->m_shape;
203 return d->m_shape;
205 }
204 }
206
205
207 void QScatterSeries::setMarkerShape(MarkerShape shape)
206 void QScatterSeries::setMarkerShape(MarkerShape shape)
208 {
207 {
209 Q_D(QScatterSeries);
208 Q_D(QScatterSeries);
210 if (d->m_shape != shape) {
209 if (d->m_shape != shape) {
211 d->m_shape = shape;
210 d->m_shape = shape;
212 emit d->updated();
211 emit d->updated();
213 }
212 }
214 }
213 }
215
214
216 qreal QScatterSeries::markerSize() const
215 qreal QScatterSeries::markerSize() const
217 {
216 {
218 Q_D(const QScatterSeries);
217 Q_D(const QScatterSeries);
219 return d->m_size;
218 return d->m_size;
220 }
219 }
221
220
222 void QScatterSeries::setMarkerSize(qreal size)
221 void QScatterSeries::setMarkerSize(qreal size)
223 {
222 {
224 Q_D(QScatterSeries);
223 Q_D(QScatterSeries);
225
224
226 if (!qFuzzyIsNull(d->m_size - size)) {
225 if (!qFuzzyIsNull(d->m_size - size)) {
227 d->m_size = size;
226 d->m_size = size;
228 emit d->updated();
227 emit d->updated();
229 }
228 }
230 }
229 }
231
230
232 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
231 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
233
232
234 QScatterSeriesPrivate::QScatterSeriesPrivate(QScatterSeries* q) :
233 QScatterSeriesPrivate::QScatterSeriesPrivate(QScatterSeries* q) :
235 QXYSeriesPrivate(q),
234 QXYSeriesPrivate(q),
236 m_shape(QScatterSeries::MarkerShapeCircle),
235 m_shape(QScatterSeries::MarkerShapeCircle),
237 m_size(15.0)
236 m_size(15.0)
238 {
237 {
239 }
238 }
240
239
241 Chart* QScatterSeriesPrivate::createGraphics(ChartPresenter* presenter)
240 Chart* QScatterSeriesPrivate::createGraphics(ChartPresenter* presenter)
242 {
241 {
243 Q_Q(QScatterSeries);
242 Q_Q(QScatterSeries);
244 ScatterChartItem *scatter = new ScatterChartItem(q,presenter);
243 ScatterChartItem *scatter = new ScatterChartItem(q,presenter);
245 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
244 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
246 scatter->setAnimator(presenter->animator());
245 scatter->setAnimator(presenter->animator());
247 scatter->setAnimation(new XYAnimation(scatter));
246 scatter->setAnimation(new XYAnimation(scatter));
248 }
247 }
249 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
248 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
250 return scatter;
249 return scatter;
251 }
250 }
252
251
253 QAbstractAxis* QScatterSeriesPrivate::createAxisX()
254 {
255 // TODO: parent?
256 return new QValuesAxis(this);
257 }
258
259 QAbstractAxis* QScatterSeriesPrivate::createAxisY()
260 {
261 // TODO: parent?
262 return new QValuesAxis(this);
263 }
264
265
266 #include "moc_qscatterseries.cpp"
252 #include "moc_qscatterseries.cpp"
267
253
268 QTCOMMERCIALCHART_END_NAMESPACE
254 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,53 +1,51
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef QSCATTERSERIES_P_H
30 #ifndef QSCATTERSERIES_P_H
31 #define QSCATTERSERIES_P_H
31 #define QSCATTERSERIES_P_H
32
32
33 #include "qxyseries_p.h"
33 #include "qxyseries_p.h"
34
34
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36
36
37 class QScatterSeriesPrivate: public QXYSeriesPrivate
37 class QScatterSeriesPrivate: public QXYSeriesPrivate
38 {
38 {
39 public:
39 public:
40 QScatterSeriesPrivate(QScatterSeries* q);
40 QScatterSeriesPrivate(QScatterSeries* q);
41 Chart* createGraphics(ChartPresenter* presenter);
41 Chart* createGraphics(ChartPresenter* presenter);
42 QAbstractAxis* createAxisX();
43 QAbstractAxis* createAxisY();
44
42
45 private:
43 private:
46 QScatterSeries::MarkerShape m_shape;
44 QScatterSeries::MarkerShape m_shape;
47 qreal m_size;
45 qreal m_size;
48 Q_DECLARE_PUBLIC(QScatterSeries)
46 Q_DECLARE_PUBLIC(QScatterSeries)
49 };
47 };
50
48
51 QTCOMMERCIALCHART_END_NAMESPACE
49 QTCOMMERCIALCHART_END_NAMESPACE
52
50
53 #endif
51 #endif
@@ -1,440 +1,451
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qxyseries.h"
21 #include "qxyseries.h"
22 #include "qxyseries_p.h"
22 #include "qxyseries_p.h"
23 #include "domain_p.h"
23 #include "domain_p.h"
24 #include "legendmarker_p.h"
24 #include "legendmarker_p.h"
25 #include "qvaluesaxis.h"
25
26
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
28
28 /*!
29 /*!
29 \class QXYSeries
30 \class QXYSeries
30 \brief The QXYSeries class is a base class for line, spline and scatter series.
31 \brief The QXYSeries class is a base class for line, spline and scatter series.
31 */
32 */
32 /*!
33 /*!
33 \qmlclass XYSeries
34 \qmlclass XYSeries
34 \inherits AbstractSeries
35 \inherits AbstractSeries
35 The XYSeries class is a base class for line, spline and scatter series.
36 The XYSeries class is a base class for line, spline and scatter series.
36
37
37 The class cannot be instantiated directly.
38 The class cannot be instantiated directly.
38 */
39 */
39
40
40 /*!
41 /*!
41 \property QXYSeries::pointsVisible
42 \property QXYSeries::pointsVisible
42 Controls if the data points are visible and should be drawn.
43 Controls if the data points are visible and should be drawn.
43 */
44 */
44 /*!
45 /*!
45 \qmlproperty bool XYSeries::pointsVisible
46 \qmlproperty bool XYSeries::pointsVisible
46 Controls if the data points are visible and should be drawn.
47 Controls if the data points are visible and should be drawn.
47 */
48 */
48
49
49 /*!
50 /*!
50 \fn QPen QXYSeries::pen() const
51 \fn QPen QXYSeries::pen() const
51 \brief Returns pen used to draw points for series.
52 \brief Returns pen used to draw points for series.
52 \sa setPen()
53 \sa setPen()
53 */
54 */
54
55
55 /*!
56 /*!
56 \fn QBrush QXYSeries::brush() const
57 \fn QBrush QXYSeries::brush() const
57 \brief Returns brush used to draw points for series.
58 \brief Returns brush used to draw points for series.
58 \sa setBrush()
59 \sa setBrush()
59 */
60 */
60
61
61 /*!
62 /*!
62 \property QXYSeries::color
63 \property QXYSeries::color
63 The color of the series. This is line (pen) color in case of QLineSeries or QSplineSeries and
64 The color of the series. This is line (pen) color in case of QLineSeries or QSplineSeries and
64 fill (brush) color in case of QScatterSeries or QAreaSeries.
65 fill (brush) color in case of QScatterSeries or QAreaSeries.
65 \sa QXYSeries::pen(), QXYSeries::brush()
66 \sa QXYSeries::pen(), QXYSeries::brush()
66 */
67 */
67 /*!
68 /*!
68 \qmlproperty color XYSeries::color
69 \qmlproperty color XYSeries::color
69 The color of the series. This is line (pen) color in case of LineSeries or SplineSeries and
70 The color of the series. This is line (pen) color in case of LineSeries or SplineSeries and
70 fill (brush) color in case of ScatterSeries or AreaSeries.
71 fill (brush) color in case of ScatterSeries or AreaSeries.
71 */
72 */
72
73
73 /*!
74 /*!
74 \fn void QXYSeries::clicked(const QPointF& point)
75 \fn void QXYSeries::clicked(const QPointF& point)
75 \brief Signal is emitted when user clicks the \a point on chart.
76 \brief Signal is emitted when user clicks the \a point on chart.
76 */
77 */
77 /*!
78 /*!
78 \qmlsignal XYSeries::onClicked(QPointF point)
79 \qmlsignal XYSeries::onClicked(QPointF point)
79 Signal is emitted when user clicks the \a point on chart. For example:
80 Signal is emitted when user clicks the \a point on chart. For example:
80 \code
81 \code
81 LineSeries {
82 LineSeries {
82 XYPoint { x: 0; y: 0 }
83 XYPoint { x: 0; y: 0 }
83 XYPoint { x: 1.1; y: 2.1 }
84 XYPoint { x: 1.1; y: 2.1 }
84 onClicked: console.log("onClicked: " + point.x + ", " + point.y);
85 onClicked: console.log("onClicked: " + point.x + ", " + point.y);
85 }
86 }
86 \endcode
87 \endcode
87 */
88 */
88
89
89 /*!
90 /*!
90 \fn void QXYSeries::pointReplaced(int index)
91 \fn void QXYSeries::pointReplaced(int index)
91 Signal is emitted when a point has been replaced at \a index.
92 Signal is emitted when a point has been replaced at \a index.
92 \sa replace()
93 \sa replace()
93 */
94 */
94 /*!
95 /*!
95 \qmlsignal XYSeries::onPointReplaced(int index)
96 \qmlsignal XYSeries::onPointReplaced(int index)
96 Signal is emitted when a point has been replaced at \a index.
97 Signal is emitted when a point has been replaced at \a index.
97 */
98 */
98
99
99 /*!
100 /*!
100 \fn void QXYSeries::pointAdded(int index)
101 \fn void QXYSeries::pointAdded(int index)
101 Signal is emitted when a point has been added at \a index.
102 Signal is emitted when a point has been added at \a index.
102 \sa append(), insert()
103 \sa append(), insert()
103 */
104 */
104 /*!
105 /*!
105 \qmlsignal XYSeries::onPointAdded(int index)
106 \qmlsignal XYSeries::onPointAdded(int index)
106 Signal is emitted when a point has been added at \a index.
107 Signal is emitted when a point has been added at \a index.
107 */
108 */
108
109
109 /*!
110 /*!
110 \fn void QXYSeries::pointRemoved(int index)
111 \fn void QXYSeries::pointRemoved(int index)
111 Signal is emitted when a point has been removed from \a index.
112 Signal is emitted when a point has been removed from \a index.
112 \sa remove()
113 \sa remove()
113 */
114 */
114 /*!
115 /*!
115 \qmlsignal XYSeries::onPointRemoved(int index)
116 \qmlsignal XYSeries::onPointRemoved(int index)
116 Signal is emitted when a point has been removed from \a index.
117 Signal is emitted when a point has been removed from \a index.
117 */
118 */
118
119
119 /*!
120 /*!
120 \fn void QXYSeries::colorChanged(QColor color)
121 \fn void QXYSeries::colorChanged(QColor color)
121 \brief Signal is emitted when the line (pen) color has changed to \a color.
122 \brief Signal is emitted when the line (pen) color has changed to \a color.
122 */
123 */
123 /*!
124 /*!
124 \qmlsignal XYSeries::onColorChanged(color color)
125 \qmlsignal XYSeries::onColorChanged(color color)
125 Signal is emitted when the line (pen) color has changed to \a color.
126 Signal is emitted when the line (pen) color has changed to \a color.
126 */
127 */
127
128
128 /*!
129 /*!
129 \fn void QXYSeriesPrivate::updated()
130 \fn void QXYSeriesPrivate::updated()
130 \brief \internal
131 \brief \internal
131 */
132 */
132
133
133 /*!
134 /*!
134 \qmlmethod XYSeries::append(real x, real y)
135 \qmlmethod XYSeries::append(real x, real y)
135 Append point (\a x, \a y) to the series
136 Append point (\a x, \a y) to the series
136 */
137 */
137
138
138 /*!
139 /*!
139 \qmlmethod XYSeries::replace(real oldX, real oldY, real newX, real newY)
140 \qmlmethod XYSeries::replace(real oldX, real oldY, real newX, real newY)
140 Replaces point (\a oldX, \a oldY) with point (\a newX, \a newY). Does nothing, if point (oldX, oldY) does not
141 Replaces point (\a oldX, \a oldY) with point (\a newX, \a newY). Does nothing, if point (oldX, oldY) does not
141 exist.
142 exist.
142 */
143 */
143
144
144 /*!
145 /*!
145 \qmlmethod XYSeries::remove(real x, real y)
146 \qmlmethod XYSeries::remove(real x, real y)
146 Removes point (\a x, \a y) from the series. Does nothing, if point (x, y) does not exist.
147 Removes point (\a x, \a y) from the series. Does nothing, if point (x, y) does not exist.
147 */
148 */
148
149
149 /*!
150 /*!
150 \qmlmethod XYSeries::insert(int index, real x, real y)
151 \qmlmethod XYSeries::insert(int index, real x, real y)
151 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
152 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
152 points. If index is the same as or bigger than count, the point is appended to the list of points.
153 points. If index is the same as or bigger than count, the point is appended to the list of points.
153 */
154 */
154
155
155 /*!
156 /*!
156 \qmlmethod QPointF XYSeries::at(int index)
157 \qmlmethod QPointF XYSeries::at(int index)
157 Returns point at \a index. Returns (0, 0) if the index is not valid.
158 Returns point at \a index. Returns (0, 0) if the index is not valid.
158 */
159 */
159
160
160 /*!
161 /*!
161 \internal
162 \internal
162
163
163 Constructs empty series object which is a child of \a parent.
164 Constructs empty series object which is a child of \a parent.
164 When series object is added to QChartView or QChart instance ownerships is transferred.
165 When series object is added to QChartView or QChart instance ownerships is transferred.
165 */
166 */
166 QXYSeries::QXYSeries(QXYSeriesPrivate &d,QObject *parent) : QAbstractSeries(d, parent)
167 QXYSeries::QXYSeries(QXYSeriesPrivate &d,QObject *parent) : QAbstractSeries(d, parent)
167 {
168 {
168 }
169 }
169
170
170 /*!
171 /*!
171 Destroys the object. Series added to QChartView or QChart instances are owned by those,
172 Destroys the object. Series added to QChartView or QChart instances are owned by those,
172 and are deleted when mentioned object are destroyed.
173 and are deleted when mentioned object are destroyed.
173 */
174 */
174 QXYSeries::~QXYSeries()
175 QXYSeries::~QXYSeries()
175 {
176 {
176 }
177 }
177
178
178 /*!
179 /*!
179 Adds data point \a x \a y to the series. Points are connected with lines on the chart.
180 Adds data point \a x \a y to the series. Points are connected with lines on the chart.
180 */
181 */
181 void QXYSeries::append(qreal x,qreal y)
182 void QXYSeries::append(qreal x,qreal y)
182 {
183 {
183 append(QPointF(x,y));
184 append(QPointF(x,y));
184 }
185 }
185
186
186 /*!
187 /*!
187 This is an overloaded function.
188 This is an overloaded function.
188 Adds data \a point to the series. Points are connected with lines on the chart.
189 Adds data \a point to the series. Points are connected with lines on the chart.
189 */
190 */
190 void QXYSeries::append(const QPointF &point)
191 void QXYSeries::append(const QPointF &point)
191 {
192 {
192 Q_D(QXYSeries);
193 Q_D(QXYSeries);
193 d->m_points<<point;
194 d->m_points<<point;
194 // emit d->pointAdded(d->m_points.count()-1);
195 // emit d->pointAdded(d->m_points.count()-1);
195 emit pointAdded(d->m_points.count()-1);
196 emit pointAdded(d->m_points.count()-1);
196 }
197 }
197
198
198 /*!
199 /*!
199 This is an overloaded function.
200 This is an overloaded function.
200 Adds list of data \a points to the series. Points are connected with lines on the chart.
201 Adds list of data \a points to the series. Points are connected with lines on the chart.
201 */
202 */
202 void QXYSeries::append(const QList<QPointF> &points)
203 void QXYSeries::append(const QList<QPointF> &points)
203 {
204 {
204 foreach(const QPointF& point , points) {
205 foreach(const QPointF& point , points) {
205 append(point);
206 append(point);
206 }
207 }
207 }
208 }
208
209
209 /*!
210 /*!
210 Replaces data point \a oldX \a oldY with data point \a newX \a newY.
211 Replaces data point \a oldX \a oldY with data point \a newX \a newY.
211 */
212 */
212 void QXYSeries::replace(qreal oldX,qreal oldY,qreal newX,qreal newY)
213 void QXYSeries::replace(qreal oldX,qreal oldY,qreal newX,qreal newY)
213 {
214 {
214 replace(QPointF(oldX,oldY),QPointF(newX,newY));
215 replace(QPointF(oldX,oldY),QPointF(newX,newY));
215 }
216 }
216
217
217 /*!
218 /*!
218 Replaces \a oldPoint with \a newPoint.
219 Replaces \a oldPoint with \a newPoint.
219 */
220 */
220 void QXYSeries::replace(const QPointF &oldPoint,const QPointF &newPoint)
221 void QXYSeries::replace(const QPointF &oldPoint,const QPointF &newPoint)
221 {
222 {
222 Q_D(QXYSeries);
223 Q_D(QXYSeries);
223 int index = d->m_points.indexOf(oldPoint);
224 int index = d->m_points.indexOf(oldPoint);
224 if(index==-1) return;
225 if(index==-1) return;
225 d->m_points[index] = newPoint;
226 d->m_points[index] = newPoint;
226 // emit d->pointReplaced(index);
227 // emit d->pointReplaced(index);
227 emit pointReplaced(index);
228 emit pointReplaced(index);
228 }
229 }
229
230
230 /*!
231 /*!
231 Removes current \a x and \a y value.
232 Removes current \a x and \a y value.
232 */
233 */
233 void QXYSeries::remove(qreal x,qreal y)
234 void QXYSeries::remove(qreal x,qreal y)
234 {
235 {
235 remove(QPointF(x,y));
236 remove(QPointF(x,y));
236 }
237 }
237
238
238 /*!
239 /*!
239 Removes current \a point x value.
240 Removes current \a point x value.
240
241
241 Note: point y value is ignored.
242 Note: point y value is ignored.
242 */
243 */
243 void QXYSeries::remove(const QPointF &point)
244 void QXYSeries::remove(const QPointF &point)
244 {
245 {
245 Q_D(QXYSeries);
246 Q_D(QXYSeries);
246 int index = d->m_points.indexOf(point);
247 int index = d->m_points.indexOf(point);
247 if(index==-1) return;
248 if(index==-1) return;
248 d->m_points.remove(index);
249 d->m_points.remove(index);
249 // emit d->pointRemoved(index);
250 // emit d->pointRemoved(index);
250 emit pointRemoved(index);
251 emit pointRemoved(index);
251 }
252 }
252
253
253 /*!
254 /*!
254 Inserts a \a point in the series at \a index position.
255 Inserts a \a point in the series at \a index position.
255 */
256 */
256 void QXYSeries::insert(int index, const QPointF &point)
257 void QXYSeries::insert(int index, const QPointF &point)
257 {
258 {
258 Q_D(QXYSeries);
259 Q_D(QXYSeries);
259 d->m_points.insert(index, point);
260 d->m_points.insert(index, point);
260 // emit d->pointAdded(index);
261 // emit d->pointAdded(index);
261 emit pointAdded(index);
262 emit pointAdded(index);
262 }
263 }
263
264
264 /*!
265 /*!
265 Removes all points from the series.
266 Removes all points from the series.
266 */
267 */
267 void QXYSeries::clear()
268 void QXYSeries::clear()
268 {
269 {
269 Q_D(QXYSeries);
270 Q_D(QXYSeries);
270 for (int i = d->m_points.size() - 1; i >= 0; i--)
271 for (int i = d->m_points.size() - 1; i >= 0; i--)
271 remove(d->m_points.at(i));
272 remove(d->m_points.at(i));
272 }
273 }
273
274
274 /*!
275 /*!
275 \internal \a pos
276 \internal \a pos
276 */
277 */
277 QList<QPointF> QXYSeries::points() const
278 QList<QPointF> QXYSeries::points() const
278 {
279 {
279 Q_D(const QXYSeries);
280 Q_D(const QXYSeries);
280 return d->m_points.toList();
281 return d->m_points.toList();
281 }
282 }
282
283
283 /*!
284 /*!
284 Returns number of data points within series.
285 Returns number of data points within series.
285 */
286 */
286 int QXYSeries::count() const
287 int QXYSeries::count() const
287 {
288 {
288 Q_D(const QXYSeries);
289 Q_D(const QXYSeries);
289 return d->m_points.count();
290 return d->m_points.count();
290 }
291 }
291
292
292
293
293 /*!
294 /*!
294 Sets \a pen used for drawing points on the chart. If the pen is not defined, the
295 Sets \a pen used for drawing points on the chart. If the pen is not defined, the
295 pen from chart theme is used.
296 pen from chart theme is used.
296 \sa QChart::setTheme()
297 \sa QChart::setTheme()
297 */
298 */
298 void QXYSeries::setPen(const QPen &pen)
299 void QXYSeries::setPen(const QPen &pen)
299 {
300 {
300 Q_D(QXYSeries);
301 Q_D(QXYSeries);
301 if (d->m_pen != pen) {
302 if (d->m_pen != pen) {
302 bool emitColorChanged = d->m_pen.color() != pen.color();
303 bool emitColorChanged = d->m_pen.color() != pen.color();
303 d->m_pen = pen;
304 d->m_pen = pen;
304 emit d->updated();
305 emit d->updated();
305 if (emitColorChanged)
306 if (emitColorChanged)
306 emit colorChanged(pen.color());
307 emit colorChanged(pen.color());
307 }
308 }
308 }
309 }
309
310
310 QPen QXYSeries::pen() const
311 QPen QXYSeries::pen() const
311 {
312 {
312 Q_D(const QXYSeries);
313 Q_D(const QXYSeries);
313 return d->m_pen;
314 return d->m_pen;
314 }
315 }
315
316
316 /*!
317 /*!
317 Sets \a brush used for drawing points on the chart. If the brush is not defined, brush
318 Sets \a brush used for drawing points on the chart. If the brush is not defined, brush
318 from chart theme setting is used.
319 from chart theme setting is used.
319 \sa QChart::setTheme()
320 \sa QChart::setTheme()
320 */
321 */
321 void QXYSeries::setBrush(const QBrush &brush)
322 void QXYSeries::setBrush(const QBrush &brush)
322 {
323 {
323 Q_D(QXYSeries);
324 Q_D(QXYSeries);
324 if (d->m_brush!=brush) {
325 if (d->m_brush!=brush) {
325 d->m_brush = brush;
326 d->m_brush = brush;
326 emit d->updated();
327 emit d->updated();
327 }
328 }
328 }
329 }
329
330
330 QBrush QXYSeries::brush() const
331 QBrush QXYSeries::brush() const
331 {
332 {
332 Q_D(const QXYSeries);
333 Q_D(const QXYSeries);
333 return d->m_brush;
334 return d->m_brush;
334 }
335 }
335
336
336 void QXYSeries::setColor(const QColor &color)
337 void QXYSeries::setColor(const QColor &color)
337 {
338 {
338 QPen p = pen();
339 QPen p = pen();
339 if (p.color() != color) {
340 if (p.color() != color) {
340 p.setColor(color);
341 p.setColor(color);
341 setPen(p);
342 setPen(p);
342 }
343 }
343 }
344 }
344
345
345 QColor QXYSeries::color() const
346 QColor QXYSeries::color() const
346 {
347 {
347 return pen().color();
348 return pen().color();
348 }
349 }
349
350
350 void QXYSeries::setPointsVisible(bool visible)
351 void QXYSeries::setPointsVisible(bool visible)
351 {
352 {
352 Q_D(QXYSeries);
353 Q_D(QXYSeries);
353 if (d->m_pointsVisible != visible){
354 if (d->m_pointsVisible != visible){
354 d->m_pointsVisible = visible;
355 d->m_pointsVisible = visible;
355 emit d->updated();
356 emit d->updated();
356 }
357 }
357 }
358 }
358
359
359 bool QXYSeries::pointsVisible() const
360 bool QXYSeries::pointsVisible() const
360 {
361 {
361 Q_D(const QXYSeries);
362 Q_D(const QXYSeries);
362 return d->m_pointsVisible;
363 return d->m_pointsVisible;
363 }
364 }
364
365
365
366
366 /*!
367 /*!
367 Stream operator for adding a data \a point to the series.
368 Stream operator for adding a data \a point to the series.
368 \sa append()
369 \sa append()
369 */
370 */
370 QXYSeries& QXYSeries::operator<< (const QPointF &point)
371 QXYSeries& QXYSeries::operator<< (const QPointF &point)
371 {
372 {
372 append(point);
373 append(point);
373 return *this;
374 return *this;
374 }
375 }
375
376
376
377
377 /*!
378 /*!
378 Stream operator for adding a list of \a points to the series.
379 Stream operator for adding a list of \a points to the series.
379 \sa append()
380 \sa append()
380 */
381 */
381
382
382 QXYSeries& QXYSeries::operator<< (const QList<QPointF>& points)
383 QXYSeries& QXYSeries::operator<< (const QList<QPointF>& points)
383 {
384 {
384 append(points);
385 append(points);
385 return *this;
386 return *this;
386 }
387 }
387
388
388 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
389 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
389
390
390
391
391 QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q) :
392 QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q) :
392 QAbstractSeriesPrivate(q),
393 QAbstractSeriesPrivate(q),
393 m_pointsVisible(false)
394 m_pointsVisible(false)
394 {
395 {
395 }
396 }
396
397
397 void QXYSeriesPrivate::scaleDomain(Domain& domain)
398 void QXYSeriesPrivate::scaleDomain(Domain& domain)
398 {
399 {
399 qreal minX(domain.minX());
400 qreal minX(domain.minX());
400 qreal minY(domain.minY());
401 qreal minY(domain.minY());
401 qreal maxX(domain.maxX());
402 qreal maxX(domain.maxX());
402 qreal maxY(domain.maxY());
403 qreal maxY(domain.maxY());
403 int tickXCount(domain.tickXCount());
404 int tickXCount(domain.tickXCount());
404 int tickYCount(domain.tickYCount());
405 int tickYCount(domain.tickYCount());
405
406
406 Q_Q(QXYSeries);
407 Q_Q(QXYSeries);
407
408
408 const QList<QPointF>& points = q->points();
409 const QList<QPointF>& points = q->points();
409
410
410
411
411 if (points.isEmpty()){
412 if (points.isEmpty()){
412 minX = qMin(minX, 0.0);
413 minX = qMin(minX, 0.0);
413 minY = qMin(minY, 0.0);
414 minY = qMin(minY, 0.0);
414 maxX = qMax(maxX, 1.0);
415 maxX = qMax(maxX, 1.0);
415 maxY = qMax(maxY, 1.0);
416 maxY = qMax(maxY, 1.0);
416 }
417 }
417
418
418 for (int i = 0; i < points.count(); i++) {
419 for (int i = 0; i < points.count(); i++) {
419 qreal x = points[i].x();
420 qreal x = points[i].x();
420 qreal y = points[i].y();
421 qreal y = points[i].y();
421 minX = qMin(minX, x);
422 minX = qMin(minX, x);
422 minY = qMin(minY, y);
423 minY = qMin(minY, y);
423 maxX = qMax(maxX, x);
424 maxX = qMax(maxX, x);
424 maxY = qMax(maxY, y);
425 maxY = qMax(maxY, y);
425 }
426 }
426
427
427 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
428 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
428 }
429 }
429
430
430 QList<LegendMarker*> QXYSeriesPrivate::createLegendMarker(QLegend* legend)
431 QList<LegendMarker*> QXYSeriesPrivate::createLegendMarker(QLegend* legend)
431 {
432 {
432 Q_Q(QXYSeries);
433 Q_Q(QXYSeries);
433 QList<LegendMarker*> list;
434 QList<LegendMarker*> list;
434 return list << new XYLegendMarker(q,legend);
435 return list << new XYLegendMarker(q,legend);
435 }
436 }
436
437
438 QAbstractAxis* QXYSeriesPrivate::createAxisX(QObject* parent)
439 {
440 return new QValuesAxis(parent);
441 }
442
443 QAbstractAxis* QXYSeriesPrivate::createAxisY(QObject* parent)
444 {
445 return new QValuesAxis(parent);
446 }
447
437 #include "moc_qxyseries.cpp"
448 #include "moc_qxyseries.cpp"
438 #include "moc_qxyseries_p.cpp"
449 #include "moc_qxyseries_p.cpp"
439
450
440 QTCOMMERCIALCHART_END_NAMESPACE
451 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,68 +1,72
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef QXYSERIES_P_H
30 #ifndef QXYSERIES_P_H
31 #define QXYSERIES_P_H
31 #define QXYSERIES_P_H
32
32
33 #include "qabstractseries_p.h"
33 #include "qabstractseries_p.h"
34
34
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36
36
37 class QXYSeries;
37 class QXYSeries;
38 class QAbstractAxis;
38
39
39 class QXYSeriesPrivate: public QAbstractSeriesPrivate
40 class QXYSeriesPrivate: public QAbstractSeriesPrivate
40 {
41 {
41 Q_OBJECT
42 Q_OBJECT
42
43
43 public:
44 public:
44 QXYSeriesPrivate(QXYSeries* q);
45 QXYSeriesPrivate(QXYSeries* q);
45
46
46 void scaleDomain(Domain& domain);
47 void scaleDomain(Domain& domain);
47 QList<LegendMarker*> createLegendMarker(QLegend* legend);
48 QList<LegendMarker*> createLegendMarker(QLegend* legend);
48
49
50 QAbstractAxis* createAxisX(QObject* parent);
51 QAbstractAxis* createAxisY(QObject* parent);
52
49 Q_SIGNALS:
53 Q_SIGNALS:
50 void updated();
54 void updated();
51 // void pointReplaced(int index);
55 // void pointReplaced(int index);
52 // void pointRemoved(int index);
56 // void pointRemoved(int index);
53 // void pointAdded(int index);
57 // void pointAdded(int index);
54
58
55 protected:
59 protected:
56 QVector<QPointF> m_points;
60 QVector<QPointF> m_points;
57 QPen m_pen;
61 QPen m_pen;
58 QBrush m_brush;
62 QBrush m_brush;
59 bool m_pointsVisible;
63 bool m_pointsVisible;
60
64
61 private:
65 private:
62 Q_DECLARE_PUBLIC(QXYSeries)
66 Q_DECLARE_PUBLIC(QXYSeries)
63 friend class QScatterSeries;
67 friend class QScatterSeries;
64 };
68 };
65
69
66 QTCOMMERCIALCHART_END_NAMESPACE
70 QTCOMMERCIALCHART_END_NAMESPACE
67
71
68 #endif
72 #endif
@@ -1,105 +1,106
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef XYCHARTITEM_H
30 #ifndef XYCHARTITEM_H
31 #define XYCHARTITEM_H
31 #define XYCHARTITEM_H
32
32
33 #include "qchartglobal.h"
33 #include "qchartglobal.h"
34 #include "chartitem_p.h"
34 #include "chartitem_p.h"
35 #include "xyanimation_p.h"
35 #include "xyanimation_p.h"
36 #include "qvaluesaxis.h"
36 #include <QPen>
37 #include <QPen>
37
38
38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
39 QTCOMMERCIALCHART_BEGIN_NAMESPACE
39
40
40 class ChartPresenter;
41 class ChartPresenter;
41 class QXYSeries;
42 class QXYSeries;
42
43
43 class XYChart : public Chart
44 class XYChart : public Chart
44 {
45 {
45 Q_OBJECT
46 Q_OBJECT
46 public:
47 public:
47 explicit XYChart(QXYSeries *series, ChartPresenter *presenter);
48 explicit XYChart(QXYSeries *series, ChartPresenter *presenter);
48 ~XYChart(){};
49 ~XYChart(){};
49
50
50 void setGeometryPoints(const QVector<QPointF>& points);
51 void setGeometryPoints(const QVector<QPointF>& points);
51 QVector<QPointF> geometryPoints() const { return m_points; }
52 QVector<QPointF> geometryPoints() const { return m_points; }
52
53
53 void setClipRect(const QRectF &rect);
54 void setClipRect(const QRectF &rect);
54 QRectF clipRect() const { return m_clipRect; }
55 QRectF clipRect() const { return m_clipRect; }
55
56
56 QSizeF size() const { return m_size; }
57 QSizeF size() const { return m_size; }
57 QPointF origin() const { return m_origin; }
58 QPointF origin() const { return m_origin; }
58
59
59 void setAnimation(XYAnimation* animation);
60 void setAnimation(XYAnimation* animation);
60 ChartAnimation* animation() const { return m_animation; }
61 ChartAnimation* animation() const { return m_animation; }
61 virtual void updateGeometry() = 0;
62 virtual void updateGeometry() = 0;
62
63
63 bool isDirty() const { return m_dirty; }
64 bool isDirty() const { return m_dirty; }
64 void setDirty(bool dirty);
65 void setDirty(bool dirty);
65
66
66 public Q_SLOTS:
67 public Q_SLOTS:
67 void handlePointAdded(int index);
68 void handlePointAdded(int index);
68 void handlePointRemoved(int index);
69 void handlePointRemoved(int index);
69 void handlePointReplaced(int index);
70 void handlePointReplaced(int index);
70 void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY);
71 void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY);
71 void handleGeometryChanged(const QRectF &size);
72 void handleGeometryChanged(const QRectF &size);
72
73
73 Q_SIGNALS:
74 Q_SIGNALS:
74 void clicked(const QPointF& point);
75 void clicked(const QPointF& point);
75
76
76 protected:
77 protected:
77 virtual void updateChart(QVector<QPointF> &oldPoints,QVector<QPointF> &newPoints,int index = -1);
78 virtual void updateChart(QVector<QPointF> &oldPoints,QVector<QPointF> &newPoints,int index = -1);
78 QPointF calculateGeometryPoint(const QPointF &point) const;
79 QPointF calculateGeometryPoint(const QPointF &point) const;
79 QPointF calculateGeometryPoint(int index) const;
80 QPointF calculateGeometryPoint(int index) const;
80 QPointF calculateDomainPoint(const QPointF &point) const;
81 QPointF calculateDomainPoint(const QPointF &point) const;
81 QVector<QPointF> calculateGeometryPoints() const;
82 QVector<QPointF> calculateGeometryPoints() const;
82
83
83 private:
84 private:
84 inline bool isEmpty();
85 inline bool isEmpty();
85
86
86 private:
87 private:
87 qreal m_minX;
88 qreal m_minX;
88 qreal m_maxX;
89 qreal m_maxX;
89 qreal m_minY;
90 qreal m_minY;
90 qreal m_maxY;
91 qreal m_maxY;
91 QXYSeries* m_series;
92 QXYSeries* m_series;
92 QSizeF m_size;
93 QSizeF m_size;
93 QPointF m_origin;
94 QPointF m_origin;
94 QRectF m_clipRect;
95 QRectF m_clipRect;
95 QVector<QPointF> m_points;
96 QVector<QPointF> m_points;
96 XYAnimation* m_animation;
97 XYAnimation* m_animation;
97 bool m_dirty;
98 bool m_dirty;
98
99
99 friend class AreaChartItem;
100 friend class AreaChartItem;
100
101
101 };
102 };
102
103
103 QTCOMMERCIALCHART_END_NAMESPACE
104 QTCOMMERCIALCHART_END_NAMESPACE
104
105
105 #endif
106 #endif
General Comments 0
You need to be logged in to leave comments. Login now