##// END OF EJS Templates
Fix some documentation issues...
Miikka Heikkinen -
r2520:73d53b3b614a
parent child
Show More
@@ -1,459 +1,459
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qareaseries.h"
21 #include "qareaseries.h"
22 #include "qareaseries_p.h"
22 #include "qareaseries_p.h"
23 #include "qlineseries.h"
23 #include "qlineseries.h"
24 #include "areachartitem_p.h"
24 #include "areachartitem_p.h"
25 #include "abstractdomain_p.h"
25 #include "abstractdomain_p.h"
26 #include "chartdataset_p.h"
26 #include "chartdataset_p.h"
27 #include "charttheme_p.h"
27 #include "charttheme_p.h"
28 #include "qvalueaxis.h"
28 #include "qvalueaxis.h"
29 #include "qarealegendmarker.h"
29 #include "qarealegendmarker.h"
30 #include "qchart_p.h"
30 #include "qchart_p.h"
31
31
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33
33
34 /*!
34 /*!
35 \class QAreaSeries
35 \class QAreaSeries
36 \brief The QAreaSeries class is used for making area charts.
36 \brief The QAreaSeries class is used for making area charts.
37
37
38 \mainclass
38 \mainclass
39
39
40 An area chart is used to show quantitative data. It is based on line chart, in the way that area between axis and the line
40 An area chart is used to show quantitative data. It is based on line chart, in the way that area between axis and the line
41 is emphasized with color. Since the area chart is based on line chart, QAreaSeries constructor needs QLineSeries instance,
41 is emphasized with color. Since the area chart is based on line chart, QAreaSeries constructor needs QLineSeries instance,
42 which defines "upper" boundary of the area. "Lower" boundary is defined by default by axis X. Instead of axis X "lower" boundary can be specified by other line.
42 which defines "upper" boundary of the area. "Lower" boundary is defined by default by axis X. Instead of axis X "lower" boundary can be specified by other line.
43 In that case QAreaSeries should be initiated with two QLineSeries instances. Please note terms "upper" and "lower" boundary can be misleading in cases
43 In that case QAreaSeries should be initiated with two QLineSeries instances. Please note terms "upper" and "lower" boundary can be misleading in cases
44 where "lower" boundary had bigger values than the "upper" one, however the main point that area between these two boundary lines will be filled.
44 where "lower" boundary had bigger values than the "upper" one, however the main point that area between these two boundary lines will be filled.
45
45
46 See the \l {AreaChart Example} {area chart example} to learn how to create a simple area chart.
46 See the \l {AreaChart Example} {area chart example} to learn how to create a simple area chart.
47 \image examples_areachart.png
47 \image examples_areachart.png
48 */
48 */
49 /*!
49 /*!
50 \qmlclass AreaSeries QAreaSeries
50 \qmlclass AreaSeries QAreaSeries
51
51
52 The following QML shows how to create a simple area chart:
52 The following QML shows how to create a simple area chart:
53 \snippet ../demos/qmlchart/qml/qmlchart/View4.qml 1
53 \snippet ../demos/qmlchart/qml/qmlchart/View4.qml 1
54 \beginfloatleft
54 \beginfloatleft
55 \image demos_qmlchart4.png
55 \image demos_qmlchart4.png
56 \endfloat
56 \endfloat
57 \clearfloat
57 \clearfloat
58 */
58 */
59
59
60 /*!
60 /*!
61 \property QAreaSeries::upperSeries
61 \property QAreaSeries::upperSeries
62 \brief The upper one of the two line series used to define area series boundaries.
62 \brief The upper one of the two line series used to define area series boundaries.
63 */
63 */
64 /*!
64 /*!
65 \qmlproperty LineSeries AreaSeries::upperSeries
65 \qmlproperty LineSeries AreaSeries::upperSeries
66 The upper one of the two line series used to define area series boundaries.
66 The upper one of the two line series used to define area series boundaries.
67 */
67 */
68
68
69 /*!
69 /*!
70 \property QAreaSeries::lowerSeries
70 \property QAreaSeries::lowerSeries
71 The lower one of the two line series used to define are series boundaries. Note if
71 The lower one of the two line series used to define are series boundaries. Note if
72 QAreaSeries was constructed without a\ lowerSeries this is null.
72 QAreaSeries was constructed without a\ lowerSeries this is null.
73 */
73 */
74 /*!
74 /*!
75 \qmlproperty LineSeries AreaSeries::lowerSeries
75 \qmlproperty LineSeries AreaSeries::lowerSeries
76 The lower one of the two line series used to define are series boundaries. Note if
76 The lower one of the two line series used to define are series boundaries. Note if
77 AreaSeries was constructed without a\ lowerSeries this is null.
77 AreaSeries was constructed without a\ lowerSeries this is null.
78 */
78 */
79
79
80 /*!
80 /*!
81 \property QAreaSeries::color
81 \property QAreaSeries::color
82 Fill (brush) color of the series. This is a convenience property for modifying the color of brush.
82 Fill (brush) color of the series. This is a convenience property for modifying the color of brush.
83 \sa QAreaSeries::brush()
83 \sa QAreaSeries::brush()
84 */
84 */
85 /*!
85 /*!
86 \qmlproperty color AreaSeries::color
86 \qmlproperty color AreaSeries::color
87 Fill (brush) color of the series.
87 Fill (brush) color of the series.
88 */
88 */
89
89
90 /*!
90 /*!
91 \property QAreaSeries::borderColor
91 \property QAreaSeries::borderColor
92 Line (pen) color of the series. This is a convenience property for modifying the color of pen.
92 Line (pen) color of the series. This is a convenience property for modifying the color of pen.
93 \sa QAreaSeries::pen()
93 \sa QAreaSeries::pen()
94 */
94 */
95 /*!
95 /*!
96 \qmlproperty color AreaSeries::borderColor
96 \qmlproperty color AreaSeries::borderColor
97 Line (pen) color of the series.
97 Line (pen) color of the series.
98 */
98 */
99
99
100 /*!
100 /*!
101 \qmlproperty real AreaSeries::borderWidth
101 \qmlproperty real AreaSeries::borderWidth
102 The width of the border line. By default the width is 2.0.
102 The width of the border line. By default the width is 2.0.
103 */
103 */
104
104
105 /*!
105 /*!
106 \fn QPen QAreaSeries::pen() const
106 \fn QPen QAreaSeries::pen() const
107 \brief Returns the pen used to draw line for this series.
107 \brief Returns the pen used to draw line for this series.
108 \sa setPen()
108 \sa setPen()
109 */
109 */
110
110
111 /*!
111 /*!
112 \fn QPen QAreaSeries::brush() const
112 \fn QPen QAreaSeries::brush() const
113 \brief Returns the brush used to draw line for this series.
113 \brief Returns the brush used to draw line for this series.
114 \sa setBrush()
114 \sa setBrush()
115 */
115 */
116
116
117 /*!
117 /*!
118 \fn void QAreaSeries::colorChanged(QColor color)
118 \fn void QAreaSeries::colorChanged(QColor color)
119 \brief Signal is emitted when the fill (brush) color has changed to \a color.
119 \brief Signal is emitted when the fill (brush) color has changed to \a color.
120 */
120 */
121 /*!
121 /*!
122 \qmlsignal AreaSeries::onColorChanged(color color)
122 \qmlsignal AreaSeries::onColorChanged(color color)
123 Signal is emitted when the fill (brush) color has changed to \a color.
123 Signal is emitted when the fill (brush) color has changed to \a color.
124 */
124 */
125
125
126 /*!
126 /*!
127 \fn void QAreaSeries::borderColorChanged(QColor color)
127 \fn void QAreaSeries::borderColorChanged(QColor color)
128 \brief Signal is emitted when the line (pen) color has changed to \a color.
128 \brief Signal is emitted when the line (pen) color has changed to \a color.
129 */
129 */
130 /*!
130 /*!
131 \qmlsignal AreaSeries::onBorderColorChanged(color color)
131 \qmlsignal AreaSeries::onBorderColorChanged(color color)
132 Signal is emitted when the line (pen) color has changed to \a color.
132 Signal is emitted when the line (pen) color has changed to \a color.
133 */
133 */
134
134
135 /*!
135 /*!
136 \fn void QAreaSeries::clicked(const QPointF& point)
136 \fn void QAreaSeries::clicked(const QPointF& point)
137 \brief Signal is emitted when user clicks the \a point on area chart.
137 \brief Signal is emitted when user clicks the \a point on area chart.
138 */
138 */
139 /*!
139 /*!
140 \qmlsignal AreaSeries::onClicked(QPointF point)
140 \qmlsignal AreaSeries::onClicked(QPointF point)
141 Signal is emitted when user clicks the \a point on area chart.
141 Signal is emitted when user clicks the \a point on area chart.
142 */
142 */
143
143
144 /*!
144 /*!
145 \fn void QAreaSeries::hovered(const QPointF &point, bool state)
145 \fn void QAreaSeries::hovered(const QPointF &point, bool state)
146 This signal is emitted when user has hovered over or away from the series. \a point shows the origin (coordinate)
146 This signal is emitted when user has hovered over or away from the series. \a point shows the origin (coordinate)
147 of the hover event. \a state is true when user has hovered over the series and false when hover has moved away from
147 of the hover event. \a state is true when user has hovered over the series and false when hover has moved away from
148 the series.
148 the series.
149 */
149 */
150 /*!
150 /*!
151 \qmlsignal AreaSeries::onHovered(point point, bool state)
151 \qmlsignal AreaSeries::onHovered(point point, bool state)
152 This signal is emitted when user has hovered over or away from the series. \a point shows the origin (coordinate)
152 This signal is emitted when user has hovered over or away from the series. \a point shows the origin (coordinate)
153 of the hover event. \a state is true when user has hovered over the series and false when hover has moved away from
153 of the hover event. \a state is true when user has hovered over the series and false when hover has moved away from
154 the series.
154 the series.
155 */
155 */
156
156
157 /*!
157 /*!
158 \fn void QAreaSeries::selected()
158 \fn void QAreaSeries::selected()
159 The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be
159 The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be
160 implemented by the user of QAreaSeries API.
160 implemented by the user of QAreaSeries API.
161 */
161 */
162 /*!
162 /*!
163 \qmlsignal AreaSeries::onSelected()
163 \qmlsignal AreaSeries::onSelected()
164 The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be
164 The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be
165 implemented by the user of AreaSeries API.
165 implemented by the user of AreaSeries API.
166 */
166 */
167
167
168 /*!
168 /*!
169 \fn void QAreaSeriesPrivate::updated()
169 \fn void QAreaSeriesPrivate::updated()
170 \brief \internal
170 \brief \internal
171 */
171 */
172
172
173 /*!
173 /*!
174 Constructs area series object which is a child of \a upperSeries. Area will be spanned between \a
174 Constructs area series object which is a child of \a upperSeries. Area will be spanned between \a
175 upperSeries line and \a lowerSeries line. If no \a lowerSeries is passed to constructor, area is specified by axis x (y=0) instead.
175 upperSeries line and \a lowerSeries line. If no \a lowerSeries is passed to constructor, area is specified by axis x (y=0) instead.
176 When series object is added to QChartView or QChart instance ownerships is transferred.
176 When series object is added to QChartView or QChart instance ownerships is transferred.
177 */
177 */
178 QAreaSeries::QAreaSeries(QLineSeries *upperSeries, QLineSeries *lowerSeries)
178 QAreaSeries::QAreaSeries(QLineSeries *upperSeries, QLineSeries *lowerSeries)
179 : QAbstractSeries(*new QAreaSeriesPrivate(upperSeries, lowerSeries, this), upperSeries)
179 : QAbstractSeries(*new QAreaSeriesPrivate(upperSeries, lowerSeries, this), upperSeries)
180 {
180 {
181 }
181 }
182
182
183 /*!
183 /*!
184 Constructs area series object without upper or lower series with \a parent object.
184 Constructs area series object without upper or lower series with \a parent object.
185 */
185 */
186 QAreaSeries::QAreaSeries(QObject *parent)
186 QAreaSeries::QAreaSeries(QObject *parent)
187 : QAbstractSeries(*new QAreaSeriesPrivate(0, 0, this), parent)
187 : QAbstractSeries(*new QAreaSeriesPrivate(0, 0, this), parent)
188 {
188 {
189 }
189 }
190
190
191 /*!
191 /*!
192 Destroys the object.
192 Destroys the object.
193 */
193 */
194 QAreaSeries::~QAreaSeries()
194 QAreaSeries::~QAreaSeries()
195 {
195 {
196 Q_D(QAreaSeries);
196 Q_D(QAreaSeries);
197 if (d->m_chart)
197 if (d->m_chart)
198 d->m_chart->removeSeries(this);
198 d->m_chart->removeSeries(this);
199 }
199 }
200
200
201 /*!
201 /*!
202 Returns QChartSeries::SeriesTypeArea.
202 Returns QAbstractSeries::SeriesTypeArea.
203 */
203 */
204 QAbstractSeries::SeriesType QAreaSeries::type() const
204 QAbstractSeries::SeriesType QAreaSeries::type() const
205 {
205 {
206 return QAbstractSeries::SeriesTypeArea;
206 return QAbstractSeries::SeriesTypeArea;
207 }
207 }
208
208
209 /*!
209 /*!
210 Sets the \a series that is to be used as the area chart upper series.
210 Sets the \a series that is to be used as the area chart upper series.
211 */
211 */
212 void QAreaSeries::setUpperSeries(QLineSeries *series)
212 void QAreaSeries::setUpperSeries(QLineSeries *series)
213 {
213 {
214 Q_D(QAreaSeries);
214 Q_D(QAreaSeries);
215 if (d->m_upperSeries != series)
215 if (d->m_upperSeries != series)
216 d->m_upperSeries = series;
216 d->m_upperSeries = series;
217 }
217 }
218
218
219 QLineSeries *QAreaSeries::upperSeries() const
219 QLineSeries *QAreaSeries::upperSeries() const
220 {
220 {
221 Q_D(const QAreaSeries);
221 Q_D(const QAreaSeries);
222 return d->m_upperSeries;
222 return d->m_upperSeries;
223 }
223 }
224
224
225 /*!
225 /*!
226 Sets the \a series that is to be used as the area chart lower series.
226 Sets the \a series that is to be used as the area chart lower series.
227 */
227 */
228 void QAreaSeries::setLowerSeries(QLineSeries *series)
228 void QAreaSeries::setLowerSeries(QLineSeries *series)
229 {
229 {
230 Q_D(QAreaSeries);
230 Q_D(QAreaSeries);
231 d->m_lowerSeries = series;
231 d->m_lowerSeries = series;
232 }
232 }
233
233
234 QLineSeries *QAreaSeries::lowerSeries() const
234 QLineSeries *QAreaSeries::lowerSeries() const
235 {
235 {
236 Q_D(const QAreaSeries);
236 Q_D(const QAreaSeries);
237 return d->m_lowerSeries;
237 return d->m_lowerSeries;
238 }
238 }
239
239
240 /*!
240 /*!
241 Sets \a pen used for drawing area outline.
241 Sets \a pen used for drawing area outline.
242 */
242 */
243 void QAreaSeries::setPen(const QPen &pen)
243 void QAreaSeries::setPen(const QPen &pen)
244 {
244 {
245 Q_D(QAreaSeries);
245 Q_D(QAreaSeries);
246 if (d->m_pen != pen) {
246 if (d->m_pen != pen) {
247 d->m_pen = pen;
247 d->m_pen = pen;
248 emit d->updated();
248 emit d->updated();
249 }
249 }
250 }
250 }
251
251
252 QPen QAreaSeries::pen() const
252 QPen QAreaSeries::pen() const
253 {
253 {
254 Q_D(const QAreaSeries);
254 Q_D(const QAreaSeries);
255 if (d->m_pen == QChartPrivate::defaultPen())
255 if (d->m_pen == QChartPrivate::defaultPen())
256 return QPen();
256 return QPen();
257 else
257 else
258 return d->m_pen;
258 return d->m_pen;
259 }
259 }
260
260
261 /*!
261 /*!
262 Sets \a brush used for filling the area.
262 Sets \a brush used for filling the area.
263 */
263 */
264 void QAreaSeries::setBrush(const QBrush &brush)
264 void QAreaSeries::setBrush(const QBrush &brush)
265 {
265 {
266 Q_D(QAreaSeries);
266 Q_D(QAreaSeries);
267 if (d->m_brush != brush) {
267 if (d->m_brush != brush) {
268 bool emitColorChanged = brush.color() != d->m_brush.color();
268 bool emitColorChanged = brush.color() != d->m_brush.color();
269 d->m_brush = brush;
269 d->m_brush = brush;
270 emit d->updated();
270 emit d->updated();
271 if (emitColorChanged)
271 if (emitColorChanged)
272 emit colorChanged(brush.color());
272 emit colorChanged(brush.color());
273 }
273 }
274 }
274 }
275
275
276 QBrush QAreaSeries::brush() const
276 QBrush QAreaSeries::brush() const
277 {
277 {
278 Q_D(const QAreaSeries);
278 Q_D(const QAreaSeries);
279 if (d->m_brush == QChartPrivate::defaultBrush())
279 if (d->m_brush == QChartPrivate::defaultBrush())
280 return QBrush();
280 return QBrush();
281 else
281 else
282 return d->m_brush;
282 return d->m_brush;
283 }
283 }
284
284
285 void QAreaSeries::setColor(const QColor &color)
285 void QAreaSeries::setColor(const QColor &color)
286 {
286 {
287 QBrush b = brush();
287 QBrush b = brush();
288 if (b == QBrush())
288 if (b == QBrush())
289 b.setStyle(Qt::SolidPattern);
289 b.setStyle(Qt::SolidPattern);
290 b.setColor(color);
290 b.setColor(color);
291 setBrush(b);
291 setBrush(b);
292 }
292 }
293
293
294 QColor QAreaSeries::color() const
294 QColor QAreaSeries::color() const
295 {
295 {
296 return brush().color();
296 return brush().color();
297 }
297 }
298
298
299 void QAreaSeries::setBorderColor(const QColor &color)
299 void QAreaSeries::setBorderColor(const QColor &color)
300 {
300 {
301 QPen p = pen();
301 QPen p = pen();
302 if (p.color() != color) {
302 if (p.color() != color) {
303 p.setColor(color);
303 p.setColor(color);
304 setPen(p);
304 setPen(p);
305 emit borderColorChanged(color);
305 emit borderColorChanged(color);
306 }
306 }
307 }
307 }
308
308
309 QColor QAreaSeries::borderColor() const
309 QColor QAreaSeries::borderColor() const
310 {
310 {
311 return pen().color();
311 return pen().color();
312 }
312 }
313
313
314 /*!
314 /*!
315 Sets if data points are \a visible and should be drawn on line.
315 Sets if data points are \a visible and should be drawn on line.
316 */
316 */
317 void QAreaSeries::setPointsVisible(bool visible)
317 void QAreaSeries::setPointsVisible(bool visible)
318 {
318 {
319 Q_D(QAreaSeries);
319 Q_D(QAreaSeries);
320 if (d->m_pointsVisible != visible) {
320 if (d->m_pointsVisible != visible) {
321 d->m_pointsVisible = visible;
321 d->m_pointsVisible = visible;
322 emit d->updated();
322 emit d->updated();
323 }
323 }
324 }
324 }
325
325
326 /*!
326 /*!
327 Returns if the points are drawn for this series.
327 Returns if the points are drawn for this series.
328 \sa setPointsVisible()
328 \sa setPointsVisible()
329 */
329 */
330 bool QAreaSeries::pointsVisible() const
330 bool QAreaSeries::pointsVisible() const
331 {
331 {
332 Q_D(const QAreaSeries);
332 Q_D(const QAreaSeries);
333 return d->m_pointsVisible;
333 return d->m_pointsVisible;
334 }
334 }
335
335
336 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
336 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
337
337
338 QAreaSeriesPrivate::QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries, QAreaSeries *q)
338 QAreaSeriesPrivate::QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries, QAreaSeries *q)
339 : QAbstractSeriesPrivate(q),
339 : QAbstractSeriesPrivate(q),
340 m_brush(QChartPrivate::defaultBrush()),
340 m_brush(QChartPrivate::defaultBrush()),
341 m_pen(QChartPrivate::defaultPen()),
341 m_pen(QChartPrivate::defaultPen()),
342 m_upperSeries(upperSeries),
342 m_upperSeries(upperSeries),
343 m_lowerSeries(lowerSeries),
343 m_lowerSeries(lowerSeries),
344 m_pointsVisible(false)
344 m_pointsVisible(false)
345 {
345 {
346 }
346 }
347
347
348 void QAreaSeriesPrivate::initializeDomain()
348 void QAreaSeriesPrivate::initializeDomain()
349 {
349 {
350 Q_Q(QAreaSeries);
350 Q_Q(QAreaSeries);
351
351
352 qreal minX(domain()->minX());
352 qreal minX(domain()->minX());
353 qreal minY(domain()->minY());
353 qreal minY(domain()->minY());
354 qreal maxX(domain()->maxX());
354 qreal maxX(domain()->maxX());
355 qreal maxY(domain()->maxY());
355 qreal maxY(domain()->maxY());
356
356
357 QLineSeries *upperSeries = q->upperSeries();
357 QLineSeries *upperSeries = q->upperSeries();
358 QLineSeries *lowerSeries = q->lowerSeries();
358 QLineSeries *lowerSeries = q->lowerSeries();
359
359
360 const QList<QPointF>& points = upperSeries->points();
360 const QList<QPointF>& points = upperSeries->points();
361
361
362 for (int i = 0; i < points.count(); i++) {
362 for (int i = 0; i < points.count(); i++) {
363 qreal x = points[i].x();
363 qreal x = points[i].x();
364 qreal y = points[i].y();
364 qreal y = points[i].y();
365 minX = qMin(minX, x);
365 minX = qMin(minX, x);
366 minY = qMin(minY, y);
366 minY = qMin(minY, y);
367 maxX = qMax(maxX, x);
367 maxX = qMax(maxX, x);
368 maxY = qMax(maxY, y);
368 maxY = qMax(maxY, y);
369 }
369 }
370 if (lowerSeries) {
370 if (lowerSeries) {
371
371
372 const QList<QPointF>& points = lowerSeries->points();
372 const QList<QPointF>& points = lowerSeries->points();
373
373
374 for (int i = 0; i < points.count(); i++) {
374 for (int i = 0; i < points.count(); i++) {
375 qreal x = points[i].x();
375 qreal x = points[i].x();
376 qreal y = points[i].y();
376 qreal y = points[i].y();
377 minX = qMin(minX, x);
377 minX = qMin(minX, x);
378 minY = qMin(minY, y);
378 minY = qMin(minY, y);
379 maxX = qMax(maxX, x);
379 maxX = qMax(maxX, x);
380 maxY = qMax(maxY, y);
380 maxY = qMax(maxY, y);
381 }
381 }
382 }
382 }
383
383
384 domain()->setRange(minX, maxX, minY, maxY);
384 domain()->setRange(minX, maxX, minY, maxY);
385 }
385 }
386
386
387 void QAreaSeriesPrivate::initializeGraphics(QGraphicsItem* parent)
387 void QAreaSeriesPrivate::initializeGraphics(QGraphicsItem* parent)
388 {
388 {
389 Q_Q(QAreaSeries);
389 Q_Q(QAreaSeries);
390 AreaChartItem *area = new AreaChartItem(q,parent);
390 AreaChartItem *area = new AreaChartItem(q,parent);
391 m_item.reset(area);
391 m_item.reset(area);
392 QAbstractSeriesPrivate::initializeGraphics(parent);
392 QAbstractSeriesPrivate::initializeGraphics(parent);
393 }
393 }
394 void QAreaSeriesPrivate::initializeAnimations(QChart::AnimationOptions options)
394 void QAreaSeriesPrivate::initializeAnimations(QChart::AnimationOptions options)
395 {
395 {
396 Q_Q(QAreaSeries);
396 Q_Q(QAreaSeries);
397 AreaChartItem *area = static_cast<AreaChartItem *>(m_item.data());
397 AreaChartItem *area = static_cast<AreaChartItem *>(m_item.data());
398 if (options.testFlag(QChart::SeriesAnimations)) {
398 if (options.testFlag(QChart::SeriesAnimations)) {
399 area->upperLineItem()->setAnimation(new XYAnimation(area->upperLineItem()));
399 area->upperLineItem()->setAnimation(new XYAnimation(area->upperLineItem()));
400 if (q->lowerSeries())
400 if (q->lowerSeries())
401 area->lowerLineItem()->setAnimation(new XYAnimation(area->lowerLineItem()));
401 area->lowerLineItem()->setAnimation(new XYAnimation(area->lowerLineItem()));
402 }else{
402 }else{
403 area->upperLineItem()->setAnimation(0);
403 area->upperLineItem()->setAnimation(0);
404 if (q->lowerSeries())
404 if (q->lowerSeries())
405 area->lowerLineItem()->setAnimation(0);
405 area->lowerLineItem()->setAnimation(0);
406 }
406 }
407 QAbstractSeriesPrivate::initializeAnimations(options);
407 QAbstractSeriesPrivate::initializeAnimations(options);
408 }
408 }
409
409
410 QList<QLegendMarker*> QAreaSeriesPrivate::createLegendMarkers(QLegend* legend)
410 QList<QLegendMarker*> QAreaSeriesPrivate::createLegendMarkers(QLegend* legend)
411 {
411 {
412 Q_Q(QAreaSeries);
412 Q_Q(QAreaSeries);
413 QList<QLegendMarker*> list;
413 QList<QLegendMarker*> list;
414 return list << new QAreaLegendMarker(q,legend);
414 return list << new QAreaLegendMarker(q,legend);
415 }
415 }
416
416
417
417
418 void QAreaSeriesPrivate::initializeAxes()
418 void QAreaSeriesPrivate::initializeAxes()
419 {
419 {
420
420
421 }
421 }
422
422
423 QAbstractAxis::AxisType QAreaSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
423 QAbstractAxis::AxisType QAreaSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
424 {
424 {
425 Q_UNUSED(orientation);
425 Q_UNUSED(orientation);
426 return QAbstractAxis::AxisTypeValue;
426 return QAbstractAxis::AxisTypeValue;
427 }
427 }
428
428
429 QAbstractAxis* QAreaSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const
429 QAbstractAxis* QAreaSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const
430 {
430 {
431 Q_UNUSED(orientation);
431 Q_UNUSED(orientation);
432 return 0;
432 return 0;
433 }
433 }
434
434
435 void QAreaSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced)
435 void QAreaSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced)
436 {
436 {
437 Q_Q(QAreaSeries);
437 Q_Q(QAreaSeries);
438
438
439 const QList<QGradient> gradients = theme->seriesGradients();
439 const QList<QGradient> gradients = theme->seriesGradients();
440 const QList<QColor> colors = theme->seriesColors();
440 const QList<QColor> colors = theme->seriesColors();
441
441
442 if (forced || QChartPrivate::defaultPen() == m_pen) {
442 if (forced || QChartPrivate::defaultPen() == m_pen) {
443 QPen pen;
443 QPen pen;
444 pen.setColor(ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.0));
444 pen.setColor(ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.0));
445 pen.setWidthF(2);
445 pen.setWidthF(2);
446 q->setPen(pen);
446 q->setPen(pen);
447 }
447 }
448
448
449 if (forced || QChartPrivate::defaultBrush() == m_brush) {
449 if (forced || QChartPrivate::defaultBrush() == m_brush) {
450 QBrush brush(colors.at(index % colors.size()));
450 QBrush brush(colors.at(index % colors.size()));
451 q->setBrush(brush);
451 q->setBrush(brush);
452 }
452 }
453 }
453 }
454
454
455
455
456 #include "moc_qareaseries.cpp"
456 #include "moc_qareaseries.cpp"
457 #include "moc_qareaseries_p.cpp"
457 #include "moc_qareaseries_p.cpp"
458
458
459 QTCOMMERCIALCHART_END_NAMESPACE
459 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,384 +1,384
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qdatetimeaxis.h"
21 #include "qdatetimeaxis.h"
22 #include "qdatetimeaxis_p.h"
22 #include "qdatetimeaxis_p.h"
23 #include "chartdatetimeaxisx_p.h"
23 #include "chartdatetimeaxisx_p.h"
24 #include "chartdatetimeaxisy_p.h"
24 #include "chartdatetimeaxisy_p.h"
25 #include "polarchartdatetimeaxisangular_p.h"
25 #include "polarchartdatetimeaxisangular_p.h"
26 #include "polarchartdatetimeaxisradial_p.h"
26 #include "polarchartdatetimeaxisradial_p.h"
27 #include "abstractdomain_p.h"
27 #include "abstractdomain_p.h"
28 #include "qchart.h"
28 #include "qchart.h"
29 #include <float.h>
29 #include <float.h>
30 #include <cmath>
30 #include <cmath>
31
31
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33 /*!
33 /*!
34 \class QDateTimeAxis
34 \class QDateTimeAxis
35 \brief The QDateTimeAxis class is used for manipulating chart's axis.
35 \brief The QDateTimeAxis class is used for manipulating chart's axis.
36 \mainclass
36 \mainclass
37
37
38 The labels can be configured by setting an appropriate DateTime format.
38 The labels can be configured by setting an appropriate DateTime format.
39 QDateTimeAxis works correctly with dates from 4714 BCE to 287396 CE.
39 QDateTimeAxis works correctly with dates from 4714 BCE to 287396 CE.
40 There are also other limitiation related to QDateTime. Please refer to QDateTime documentation.
40 There are also other limitiation related to QDateTime. Please refer to QDateTime documentation.
41 QDateTimeAxis can be setup to show axis line with tick marks, grid lines and shades.
41 QDateTimeAxis can be setup to show axis line with tick marks, grid lines and shades.
42
42
43 Note: QDateTimeAxis is disabled on ARM architecture.
43 Note: QDateTimeAxis is disabled on ARM architecture.
44
44
45 \image api_datatime_axis.png
45 \image api_datatime_axis.png
46
46
47 QDateTimeAxis can be used with any QXYSeries.
47 QDateTimeAxis can be used with any QXYSeries.
48 To add a data point to the series QDateTime::toMSecsSinceEpoch() is used.
48 To add a data point to the series QDateTime::toMSecsSinceEpoch() is used.
49 \code
49 \code
50 QLineSeries *series = new QLineSeries;
50 QLineSeries *series = new QLineSeries;
51
51
52 QDateTime xValue;
52 QDateTime xValue;
53 xValue.setDate(QDate(2012, 1 , 18));
53 xValue.setDate(QDate(2012, 1 , 18));
54 xValue.setTime(QTime(9, 34));
54 xValue.setTime(QTime(9, 34));
55 qreal yValue = 12;
55 qreal yValue = 12;
56 series->append(xValue.toMSecsSinceEpoch(), yValue);
56 series->append(xValue.toMSecsSinceEpoch(), yValue);
57
57
58 xValue.setDate(QDate(2013, 5 , 11));
58 xValue.setDate(QDate(2013, 5 , 11));
59 xValue.setTime(QTime(11, 14));
59 xValue.setTime(QTime(11, 14));
60 qreal yValue = 22;
60 qreal yValue = 22;
61 series->append(xValue.toMSecsSinceEpoch(), yValue);
61 series->append(xValue.toMSecsSinceEpoch(), yValue);
62 \endcode
62 \endcode
63
63
64 Adding the series to the chart and setting up the QDateTimeAxis.
64 Adding the series to the chart and setting up the QDateTimeAxis.
65 \code
65 \code
66 QChartView *chartView = new QChartView;
66 QChartView *chartView = new QChartView;
67 chartView->chart()->addSeries(series);
67 chartView->chart()->addSeries(series);
68
68
69 // ...
69 // ...
70 QDateTimeAxis *axisX = new QDateTimeAxis;
70 QDateTimeAxis *axisX = new QDateTimeAxis;
71 axisX->setFormat("dd-MM-yyyy h:mm");
71 axisX->setFormat("dd-MM-yyyy h:mm");
72 chartView->chart()->setAxisX(axisX, series);
72 chartView->chart()->setAxisX(axisX, series);
73 \endcode
73 \endcode
74 */
74 */
75
75
76 /*!
76 /*!
77 \qmlclass DateTimeAxis QDateTimeAxis
77 \qmlclass DateTimeAxis QDateTimeAxis
78 \brief The DateTimeAxis element is used for manipulating chart's axes
78 \brief The DateTimeAxis element is used for manipulating chart's axes.
79 \inherits AbstractAxis
79 \inherits AbstractAxis
80
80
81 The labels can be configured by setting an appropriate DateTime format.
81 The labels can be configured by setting an appropriate DateTime format.
82 Note that any date before 4714 BCE or after about 1.4 million CE may not be accurately stored.
82 Note that any date before 4714 BCE or after about 1.4 million CE may not be accurately stored.
83 DateTimeAxis can be setup to show axis line with tick marks, grid lines and shades.
83 DateTimeAxis can be setup to show axis line with tick marks, grid lines and shades.
84 */
84 */
85
85
86 /*!
86 /*!
87 \property QDateTimeAxis::min
87 \property QDateTimeAxis::min
88 Defines the minimum value on the axis.
88 Defines the minimum value on the axis.
89 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
89 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
90 */
90 */
91 /*!
91 /*!
92 \qmlproperty real ValuesAxis::min
92 \qmlproperty real ValuesAxis::min
93 Defines the minimum value on the axis.
93 Defines the minimum value on the axis.
94 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
94 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
95 */
95 */
96
96
97 /*!
97 /*!
98 \property QDateTimeAxis::max
98 \property QDateTimeAxis::max
99 Defines the maximum value on the axis.
99 Defines the maximum value on the axis.
100 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
100 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
101 */
101 */
102 /*!
102 /*!
103 \qmlproperty real ValuesAxis::max
103 \qmlproperty real ValuesAxis::max
104 Defines the maximum value on the axis.
104 Defines the maximum value on the axis.
105 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
105 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
106 */
106 */
107
107
108 /*!
108 /*!
109 \fn void QDateTimeAxis::minChanged(QDateTime min)
109 \fn void QDateTimeAxis::minChanged(QDateTime min)
110 Axis emits signal when \a min of axis has changed.
110 Axis emits signal when \a min of axis has changed.
111 */
111 */
112 /*!
112 /*!
113 \qmlsignal ValuesAxis::onMinChanged(QDateTime min)
113 \qmlsignal ValuesAxis::onMinChanged(QDateTime min)
114 Axis emits signal when \a min of axis has changed.
114 Axis emits signal when \a min of axis has changed.
115 */
115 */
116
116
117 /*!
117 /*!
118 \fn void QDateTimeAxis::maxChanged(QDateTime max)
118 \fn void QDateTimeAxis::maxChanged(QDateTime max)
119 Axis emits signal when \a max of axis has changed.
119 Axis emits signal when \a max of axis has changed.
120 */
120 */
121 /*!
121 /*!
122 \qmlsignal ValuesAxis::onMaxChanged(QDateTime max)
122 \qmlsignal ValuesAxis::onMaxChanged(QDateTime max)
123 Axis emits signal when \a max of axis has changed.
123 Axis emits signal when \a max of axis has changed.
124 */
124 */
125
125
126 /*!
126 /*!
127 \fn void QDateTimeAxis::rangeChanged(QDateTime min, QDateTime max)
127 \fn void QDateTimeAxis::rangeChanged(QDateTime min, QDateTime max)
128 Axis emits signal when \a min or \a max of axis has changed.
128 Axis emits signal when \a min or \a max of axis has changed.
129 */
129 */
130
130
131 /*!
131 /*!
132 \property QDateTimeAxis::tickCount
132 \property QDateTimeAxis::tickCount
133 The number of tick marks for the axis.
133 The number of tick marks for the axis.
134 */
134 */
135
135
136 /*!
136 /*!
137 \qmlproperty int DateTimeAxis::tickCount
137 \qmlproperty int DateTimeAxis::tickCount
138 The number of tick marks for the axis.
138 The number of tick marks for the axis.
139 */
139 */
140
140
141 /*!
141 /*!
142 \property QDateTimeAxis::format
142 \property QDateTimeAxis::format
143 The format string that is used when creating label for the axis out of a QDateTime object.
143 The format string that is used when creating label for the axis out of a QDateTime object.
144 Check QDateTime documentation for information on how the string should be defined.
144 Check QDateTime documentation for information on how the string should be defined.
145 */
145 */
146 /*!
146 /*!
147 \qmlproperty string DateTimeAxis::format
147 \qmlproperty string DateTimeAxis::format
148 The format string that is used when creating label for the axis out of a QDateTime object.
148 The format string that is used when creating label for the axis out of a QDateTime object.
149 Check QDateTime documentation for information on how the string should be defined.
149 Check QDateTime documentation for information on how the string should be defined.
150 */
150 */
151
151
152 /*!
152 /*!
153 \fn void QDateTimeAxis::tickCountChanged(int tickCount)
153 \fn void QDateTimeAxis::tickCountChanged(int tickCount)
154 Axis emits signal when \a tickCount number on axis have changed.
154 Axis emits signal when \a tickCount number on axis have changed.
155 */
155 */
156 /*!
156 /*!
157 \qmlsignal DateTimeAxis::tickCountChanged(int tickCount)
157 \qmlsignal DateTimeAxis::tickCountChanged(int tickCount)
158 Axis emits signal when \a tickCount number on axis have changed.
158 Axis emits signal when \a tickCount number on axis have changed.
159 */
159 */
160
160
161 /*!
161 /*!
162 \fn void QDateTimeAxis::formatChanged(QString format)
162 \fn void QDateTimeAxis::formatChanged(QString format)
163 Axis emits signal when \a format of the axis has changed.
163 Axis emits signal when \a format of the axis has changed.
164 */
164 */
165 /*!
165 /*!
166 \qmlsignal DateTimeAxis::onFormatChanged(string format)
166 \qmlsignal DateTimeAxis::onFormatChanged(string format)
167 Axis emits signal when \a format of the axis has changed.
167 Axis emits signal when \a format of the axis has changed.
168 */
168 */
169
169
170 /*!
170 /*!
171 Constructs an axis object which is a child of \a parent.
171 Constructs an axis object which is a child of \a parent.
172 */
172 */
173 QDateTimeAxis::QDateTimeAxis(QObject *parent) :
173 QDateTimeAxis::QDateTimeAxis(QObject *parent) :
174 QAbstractAxis(*new QDateTimeAxisPrivate(this), parent)
174 QAbstractAxis(*new QDateTimeAxisPrivate(this), parent)
175 {
175 {
176
176
177 }
177 }
178
178
179 /*!
179 /*!
180 \internal
180 \internal
181 */
181 */
182 QDateTimeAxis::QDateTimeAxis(QDateTimeAxisPrivate &d, QObject *parent) : QAbstractAxis(d, parent)
182 QDateTimeAxis::QDateTimeAxis(QDateTimeAxisPrivate &d, QObject *parent) : QAbstractAxis(d, parent)
183 {
183 {
184
184
185 }
185 }
186
186
187 /*!
187 /*!
188 Destroys the object
188 Destroys the object
189 */
189 */
190 QDateTimeAxis::~QDateTimeAxis()
190 QDateTimeAxis::~QDateTimeAxis()
191 {
191 {
192 Q_D(QDateTimeAxis);
192 Q_D(QDateTimeAxis);
193 if (d->m_chart)
193 if (d->m_chart)
194 d->m_chart->removeAxis(this);
194 d->m_chart->removeAxis(this);
195 }
195 }
196
196
197 void QDateTimeAxis::setMin(QDateTime min)
197 void QDateTimeAxis::setMin(QDateTime min)
198 {
198 {
199 Q_D(QDateTimeAxis);
199 Q_D(QDateTimeAxis);
200 if (min.isValid())
200 if (min.isValid())
201 d->setRange(min.toMSecsSinceEpoch(), qMax(d->m_max, qreal(min.toMSecsSinceEpoch())));
201 d->setRange(min.toMSecsSinceEpoch(), qMax(d->m_max, qreal(min.toMSecsSinceEpoch())));
202 }
202 }
203
203
204 QDateTime QDateTimeAxis::min() const
204 QDateTime QDateTimeAxis::min() const
205 {
205 {
206 Q_D(const QDateTimeAxis);
206 Q_D(const QDateTimeAxis);
207 return QDateTime::fromMSecsSinceEpoch(d->m_min);
207 return QDateTime::fromMSecsSinceEpoch(d->m_min);
208 }
208 }
209
209
210 void QDateTimeAxis::setMax(QDateTime max)
210 void QDateTimeAxis::setMax(QDateTime max)
211 {
211 {
212 Q_D(QDateTimeAxis);
212 Q_D(QDateTimeAxis);
213 if (max.isValid())
213 if (max.isValid())
214 d->setRange(qMin(d->m_min, qreal(max.toMSecsSinceEpoch())), max.toMSecsSinceEpoch());
214 d->setRange(qMin(d->m_min, qreal(max.toMSecsSinceEpoch())), max.toMSecsSinceEpoch());
215 }
215 }
216
216
217 QDateTime QDateTimeAxis::max() const
217 QDateTime QDateTimeAxis::max() const
218 {
218 {
219 Q_D(const QDateTimeAxis);
219 Q_D(const QDateTimeAxis);
220 return QDateTime::fromMSecsSinceEpoch(d->m_max);
220 return QDateTime::fromMSecsSinceEpoch(d->m_max);
221 }
221 }
222
222
223 /*!
223 /*!
224 Sets range from \a min to \a max on the axis.
224 Sets range from \a min to \a max on the axis.
225 If min is greater than max then this function returns without making any changes.
225 If min is greater than max then this function returns without making any changes.
226 */
226 */
227 void QDateTimeAxis::setRange(QDateTime min, QDateTime max)
227 void QDateTimeAxis::setRange(QDateTime min, QDateTime max)
228 {
228 {
229 Q_D(QDateTimeAxis);
229 Q_D(QDateTimeAxis);
230 if (!min.isValid() || !max.isValid() || min > max)
230 if (!min.isValid() || !max.isValid() || min > max)
231 return;
231 return;
232
232
233 d->setRange(min.toMSecsSinceEpoch(),max.toMSecsSinceEpoch());
233 d->setRange(min.toMSecsSinceEpoch(),max.toMSecsSinceEpoch());
234 }
234 }
235
235
236 void QDateTimeAxis::setFormat(QString format)
236 void QDateTimeAxis::setFormat(QString format)
237 {
237 {
238 Q_D(QDateTimeAxis);
238 Q_D(QDateTimeAxis);
239 if (d->m_format != format) {
239 if (d->m_format != format) {
240 d->m_format = format;
240 d->m_format = format;
241 emit formatChanged(format);
241 emit formatChanged(format);
242 }
242 }
243 }
243 }
244
244
245 QString QDateTimeAxis::format() const
245 QString QDateTimeAxis::format() const
246 {
246 {
247 Q_D(const QDateTimeAxis);
247 Q_D(const QDateTimeAxis);
248 return d->m_format;
248 return d->m_format;
249 }
249 }
250
250
251 /*!
251 /*!
252 Sets \a count for ticks on the axis.
252 Sets \a count for ticks on the axis.
253 */
253 */
254 void QDateTimeAxis::setTickCount(int count)
254 void QDateTimeAxis::setTickCount(int count)
255 {
255 {
256 Q_D(QDateTimeAxis);
256 Q_D(QDateTimeAxis);
257 if (d->m_tickCount != count && count >= 2) {
257 if (d->m_tickCount != count && count >= 2) {
258 d->m_tickCount = count;
258 d->m_tickCount = count;
259 emit tickCountChanged(count);
259 emit tickCountChanged(count);
260 }
260 }
261 }
261 }
262
262
263 /*!
263 /*!
264 \fn int QDateTimeAxis::tickCount() const
264 \fn int QDateTimeAxis::tickCount() const
265 Return number of ticks on the axis
265 Return number of ticks on the axis
266 */
266 */
267 int QDateTimeAxis::tickCount() const
267 int QDateTimeAxis::tickCount() const
268 {
268 {
269 Q_D(const QDateTimeAxis);
269 Q_D(const QDateTimeAxis);
270 return d->m_tickCount;
270 return d->m_tickCount;
271 }
271 }
272
272
273 /*!
273 /*!
274 Returns the type of the axis
274 Returns the type of the axis
275 */
275 */
276 QAbstractAxis::AxisType QDateTimeAxis::type() const
276 QAbstractAxis::AxisType QDateTimeAxis::type() const
277 {
277 {
278 return AxisTypeDateTime;
278 return AxisTypeDateTime;
279 }
279 }
280
280
281 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
281 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
282
282
283 QDateTimeAxisPrivate::QDateTimeAxisPrivate(QDateTimeAxis *q)
283 QDateTimeAxisPrivate::QDateTimeAxisPrivate(QDateTimeAxis *q)
284 : QAbstractAxisPrivate(q),
284 : QAbstractAxisPrivate(q),
285 m_min(0),
285 m_min(0),
286 m_max(0),
286 m_max(0),
287 m_tickCount(5)
287 m_tickCount(5)
288 {
288 {
289 m_format = "dd-MM-yyyy\nh:mm";
289 m_format = "dd-MM-yyyy\nh:mm";
290 }
290 }
291
291
292 QDateTimeAxisPrivate::~QDateTimeAxisPrivate()
292 QDateTimeAxisPrivate::~QDateTimeAxisPrivate()
293 {
293 {
294
294
295 }
295 }
296
296
297 void QDateTimeAxisPrivate::setRange(qreal min,qreal max)
297 void QDateTimeAxisPrivate::setRange(qreal min,qreal max)
298 {
298 {
299 Q_Q(QDateTimeAxis);
299 Q_Q(QDateTimeAxis);
300
300
301 bool changed = false;
301 bool changed = false;
302
302
303 if (m_min != min) {
303 if (m_min != min) {
304 m_min = min;
304 m_min = min;
305 changed = true;
305 changed = true;
306 emit q->minChanged(QDateTime::fromMSecsSinceEpoch(min));
306 emit q->minChanged(QDateTime::fromMSecsSinceEpoch(min));
307 }
307 }
308
308
309 if (m_max != max) {
309 if (m_max != max) {
310 m_max = max;
310 m_max = max;
311 changed = true;
311 changed = true;
312 emit q->maxChanged(QDateTime::fromMSecsSinceEpoch(max));
312 emit q->maxChanged(QDateTime::fromMSecsSinceEpoch(max));
313 }
313 }
314
314
315 if (changed) {
315 if (changed) {
316 emit q->rangeChanged(QDateTime::fromMSecsSinceEpoch(min), QDateTime::fromMSecsSinceEpoch(max));
316 emit q->rangeChanged(QDateTime::fromMSecsSinceEpoch(min), QDateTime::fromMSecsSinceEpoch(max));
317 emit rangeChanged(m_min,m_max);
317 emit rangeChanged(m_min,m_max);
318 }
318 }
319 }
319 }
320
320
321
321
322 void QDateTimeAxisPrivate::setMin(const QVariant &min)
322 void QDateTimeAxisPrivate::setMin(const QVariant &min)
323 {
323 {
324 Q_Q(QDateTimeAxis);
324 Q_Q(QDateTimeAxis);
325 if (min.canConvert(QVariant::DateTime))
325 if (min.canConvert(QVariant::DateTime))
326 q->setMin(min.toDateTime());
326 q->setMin(min.toDateTime());
327 }
327 }
328
328
329 void QDateTimeAxisPrivate::setMax(const QVariant &max)
329 void QDateTimeAxisPrivate::setMax(const QVariant &max)
330 {
330 {
331
331
332 Q_Q(QDateTimeAxis);
332 Q_Q(QDateTimeAxis);
333 if (max.canConvert(QVariant::DateTime))
333 if (max.canConvert(QVariant::DateTime))
334 q->setMax(max.toDateTime());
334 q->setMax(max.toDateTime());
335 }
335 }
336
336
337 void QDateTimeAxisPrivate::setRange(const QVariant &min, const QVariant &max)
337 void QDateTimeAxisPrivate::setRange(const QVariant &min, const QVariant &max)
338 {
338 {
339 Q_Q(QDateTimeAxis);
339 Q_Q(QDateTimeAxis);
340 if (min.canConvert(QVariant::DateTime) && max.canConvert(QVariant::DateTime))
340 if (min.canConvert(QVariant::DateTime) && max.canConvert(QVariant::DateTime))
341 q->setRange(min.toDateTime(), max.toDateTime());
341 q->setRange(min.toDateTime(), max.toDateTime());
342 }
342 }
343
343
344 void QDateTimeAxisPrivate::initializeGraphics(QGraphicsItem* parent)
344 void QDateTimeAxisPrivate::initializeGraphics(QGraphicsItem* parent)
345 {
345 {
346 Q_Q(QDateTimeAxis);
346 Q_Q(QDateTimeAxis);
347 ChartAxisElement *axis(0);
347 ChartAxisElement *axis(0);
348 if (m_chart->chartType() == QChart::ChartTypeCartesian) {
348 if (m_chart->chartType() == QChart::ChartTypeCartesian) {
349 if (orientation() == Qt::Vertical)
349 if (orientation() == Qt::Vertical)
350 axis = new ChartDateTimeAxisY(q,parent);
350 axis = new ChartDateTimeAxisY(q,parent);
351 if (orientation() == Qt::Horizontal)
351 if (orientation() == Qt::Horizontal)
352 axis = new ChartDateTimeAxisX(q,parent);
352 axis = new ChartDateTimeAxisX(q,parent);
353 }
353 }
354
354
355 if (m_chart->chartType() == QChart::ChartTypePolar) {
355 if (m_chart->chartType() == QChart::ChartTypePolar) {
356 if (orientation() == Qt::Vertical)
356 if (orientation() == Qt::Vertical)
357 axis = new PolarChartDateTimeAxisRadial(q, parent);
357 axis = new PolarChartDateTimeAxisRadial(q, parent);
358 if (orientation() == Qt::Horizontal)
358 if (orientation() == Qt::Horizontal)
359 axis = new PolarChartDateTimeAxisAngular(q, parent);
359 axis = new PolarChartDateTimeAxisAngular(q, parent);
360 }
360 }
361
361
362 m_item.reset(axis);
362 m_item.reset(axis);
363 QAbstractAxisPrivate::initializeGraphics(parent);
363 QAbstractAxisPrivate::initializeGraphics(parent);
364 }
364 }
365
365
366 void QDateTimeAxisPrivate::initializeDomain(AbstractDomain *domain)
366 void QDateTimeAxisPrivate::initializeDomain(AbstractDomain *domain)
367 {
367 {
368 if (m_max == m_min) {
368 if (m_max == m_min) {
369 if (orientation() == Qt::Vertical)
369 if (orientation() == Qt::Vertical)
370 setRange(domain->minY(), domain->maxY());
370 setRange(domain->minY(), domain->maxY());
371 else
371 else
372 setRange(domain->minX(), domain->maxX());
372 setRange(domain->minX(), domain->maxX());
373 } else {
373 } else {
374 if (orientation() == Qt::Vertical)
374 if (orientation() == Qt::Vertical)
375 domain->setRangeY(m_min, m_max);
375 domain->setRangeY(m_min, m_max);
376 else
376 else
377 domain->setRangeX(m_min, m_max);
377 domain->setRangeX(m_min, m_max);
378 }
378 }
379 }
379 }
380
380
381 #include "moc_qdatetimeaxis.cpp"
381 #include "moc_qdatetimeaxis.cpp"
382 #include "moc_qdatetimeaxis_p.cpp"
382 #include "moc_qdatetimeaxis_p.cpp"
383
383
384 QTCOMMERCIALCHART_END_NAMESPACE
384 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,396 +1,396
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qlogvalueaxis.h"
21 #include "qlogvalueaxis.h"
22 #include "qlogvalueaxis_p.h"
22 #include "qlogvalueaxis_p.h"
23 #include "chartlogvalueaxisx_p.h"
23 #include "chartlogvalueaxisx_p.h"
24 #include "chartlogvalueaxisy_p.h"
24 #include "chartlogvalueaxisy_p.h"
25 #include "polarchartlogvalueaxisangular_p.h"
25 #include "polarchartlogvalueaxisangular_p.h"
26 #include "polarchartlogvalueaxisradial_p.h"
26 #include "polarchartlogvalueaxisradial_p.h"
27 #include "abstractdomain_p.h"
27 #include "abstractdomain_p.h"
28 #include <float.h>
28 #include <float.h>
29 #include <cmath>
29 #include <cmath>
30
30
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 /*!
32 /*!
33 \class QLogValueAxis
33 \class QLogValueAxis
34 \brief The QLogValueAxis class is used for manipulating chart's axis.
34 \brief The QLogValueAxis class is used for manipulating chart's axis.
35 \mainclass
35 \mainclass
36
36
37 \note If a QLogValueAxis is attached to a series with one or more points with
37 \note If a QLogValueAxis is attached to a series with one or more points with
38 negative or zero values on the associated dimension, the series will not be
38 negative or zero values on the associated dimension, the series will not be
39 plotted at all. This is particularly relevant when XYModelMappers are used,
39 plotted at all. This is particularly relevant when XYModelMappers are used,
40 since empty cells in models typically contain zero values.
40 since empty cells in models typically contain zero values.
41 */
41 */
42
42
43 /*!
43 /*!
44 \qmlclass LogValueAxis QLogValueAxis
44 \qmlclass LogValueAxis QLogValueAxis
45 \brief The LogValueAxis element is used for manipulating chart's axes
45 \brief The LogValueAxis element is used for manipulating chart's axes.
46 \inherits AbstractAxis
46 \inherits AbstractAxis
47
47
48 \note If a LogValueAxis is attached to a series with one or more points with
48 \note If a LogValueAxis is attached to a series with one or more points with
49 negative or zero values on the associated dimension, the series will not be
49 negative or zero values on the associated dimension, the series will not be
50 plotted at all. This is particularly relevant when XYModelMappers are used,
50 plotted at all. This is particularly relevant when XYModelMappers are used,
51 since empty cells in models typically contain zero values.
51 since empty cells in models typically contain zero values.
52 */
52 */
53
53
54 /*!
54 /*!
55 \property QLogValueAxis::min
55 \property QLogValueAxis::min
56 Defines the minimum value on the axis.
56 Defines the minimum value on the axis.
57 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
57 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
58 Value has to be greater than 0.
58 Value has to be greater than 0.
59 */
59 */
60 /*!
60 /*!
61 \qmlproperty real LogValueAxis::min
61 \qmlproperty real LogValueAxis::min
62 Defines the minimum value on the axis.
62 Defines the minimum value on the axis.
63 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
63 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
64 Value has to be greater than 0.
64 Value has to be greater than 0.
65 */
65 */
66
66
67 /*!
67 /*!
68 \property QLogValueAxis::max
68 \property QLogValueAxis::max
69 Defines the maximum value on the axis.
69 Defines the maximum value on the axis.
70 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
70 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
71 Value has to be greater than 0.
71 Value has to be greater than 0.
72 */
72 */
73 /*!
73 /*!
74 \qmlproperty real LogValueAxis::max
74 \qmlproperty real LogValueAxis::max
75 Defines the maximum value on the axis.
75 Defines the maximum value on the axis.
76 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
76 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
77 Value has to be greater than 0.
77 Value has to be greater than 0.
78 */
78 */
79
79
80 /*!
80 /*!
81 \property QLogValueAxis::base
81 \property QLogValueAxis::base
82 Defines the base of the logarithm.
82 Defines the base of the logarithm.
83 Value has to be greater than 0 and not equal 1
83 Value has to be greater than 0 and not equal 1
84 */
84 */
85 /*!
85 /*!
86 \qmlproperty real LogValueAxis::base
86 \qmlproperty real LogValueAxis::base
87 Defines the maximum value on the axis.
87 Defines the maximum value on the axis.
88 Defines the base of the logarithm.
88 Defines the base of the logarithm.
89 Value has to be greater than 0 and not equal 1
89 Value has to be greater than 0 and not equal 1
90 */
90 */
91
91
92 /*!
92 /*!
93 \property QLogValueAxis::labelFormat
93 \property QLogValueAxis::labelFormat
94 Defines the label format of the axis.
94 Defines the label format of the axis.
95 Supported specifiers are: d, i, o, x, X, f, F, e, E, g, G, c
95 Supported specifiers are: d, i, o, x, X, f, F, e, E, g, G, c
96 See QString::sprintf() for additional details.
96 See QString::sprintf() for additional details.
97 */
97 */
98 /*!
98 /*!
99 \qmlproperty real LogValueAxis::labelFormat
99 \qmlproperty real LogValueAxis::labelFormat
100 Defines the label format of the axis.
100 Defines the label format of the axis.
101 Supported specifiers are: d, i, o, x, X, f, F, e, E, g, G, c
101 Supported specifiers are: d, i, o, x, X, f, F, e, E, g, G, c
102 See QString::sprintf() for additional details.
102 See QString::sprintf() for additional details.
103 */
103 */
104
104
105 /*!
105 /*!
106 \fn void QLogValueAxis::minChanged(qreal min)
106 \fn void QLogValueAxis::minChanged(qreal min)
107 Axis emits signal when \a min of axis has changed.
107 Axis emits signal when \a min of axis has changed.
108 */
108 */
109 /*!
109 /*!
110 \qmlsignal LogValueAxis::onMinChanged(qreal min)
110 \qmlsignal LogValueAxis::onMinChanged(qreal min)
111 Axis emits signal when \a min of axis has changed.
111 Axis emits signal when \a min of axis has changed.
112 */
112 */
113
113
114 /*!
114 /*!
115 \fn void QLogValueAxis::maxChanged(qreal max)
115 \fn void QLogValueAxis::maxChanged(qreal max)
116 Axis emits signal when \a max of axis has changed.
116 Axis emits signal when \a max of axis has changed.
117 */
117 */
118 /*!
118 /*!
119 \qmlsignal LogValueAxis::onMaxChanged(qreal max)
119 \qmlsignal LogValueAxis::onMaxChanged(qreal max)
120 Axis emits signal when \a max of axis has changed.
120 Axis emits signal when \a max of axis has changed.
121 */
121 */
122
122
123 /*!
123 /*!
124 \fn void QLogValueAxis::rangeChanged(qreal min, qreal max)
124 \fn void QLogValueAxis::rangeChanged(qreal min, qreal max)
125 Axis emits signal when \a min or \a max of axis has changed.
125 Axis emits signal when \a min or \a max of axis has changed.
126 */
126 */
127
127
128 /*!
128 /*!
129 \fn void QLogValueAxis::labelFormatChanged(const QString &format)
129 \fn void QLogValueAxis::labelFormatChanged(const QString &format)
130 Axis emits signal when \a format of axis labels has changed.
130 Axis emits signal when \a format of axis labels has changed.
131 */
131 */
132 /*!
132 /*!
133 \qmlsignal LogValueAxis::labelFormatChanged(const QString &format)
133 \qmlsignal LogValueAxis::labelFormatChanged(const QString &format)
134 Axis emits signal when \a format of axis labels has changed.
134 Axis emits signal when \a format of axis labels has changed.
135 */
135 */
136
136
137 /*!
137 /*!
138 \fn void QLogValueAxis::baseChanged(qreal base)
138 \fn void QLogValueAxis::baseChanged(qreal base)
139 Axis emits signal when \a base of logarithm of the axis has changed.
139 Axis emits signal when \a base of logarithm of the axis has changed.
140 */
140 */
141 /*!
141 /*!
142 \qmlsignal LogValueAxis::baseChanged(qreal base)
142 \qmlsignal LogValueAxis::baseChanged(qreal base)
143 Axis emits signal when \a base of logarithm of the axis has changed.
143 Axis emits signal when \a base of logarithm of the axis has changed.
144 */
144 */
145
145
146 /*!
146 /*!
147 Constructs an axis object which is a child of \a parent.
147 Constructs an axis object which is a child of \a parent.
148 */
148 */
149 QLogValueAxis::QLogValueAxis(QObject *parent) :
149 QLogValueAxis::QLogValueAxis(QObject *parent) :
150 QAbstractAxis(*new QLogValueAxisPrivate(this), parent)
150 QAbstractAxis(*new QLogValueAxisPrivate(this), parent)
151 {
151 {
152
152
153 }
153 }
154
154
155 /*!
155 /*!
156 \internal
156 \internal
157 */
157 */
158 QLogValueAxis::QLogValueAxis(QLogValueAxisPrivate &d, QObject *parent) : QAbstractAxis(d, parent)
158 QLogValueAxis::QLogValueAxis(QLogValueAxisPrivate &d, QObject *parent) : QAbstractAxis(d, parent)
159 {
159 {
160
160
161 }
161 }
162
162
163 /*!
163 /*!
164 Destroys the object
164 Destroys the object
165 */
165 */
166 QLogValueAxis::~QLogValueAxis()
166 QLogValueAxis::~QLogValueAxis()
167 {
167 {
168 Q_D(QLogValueAxis);
168 Q_D(QLogValueAxis);
169 if (d->m_chart)
169 if (d->m_chart)
170 d->m_chart->removeAxis(this);
170 d->m_chart->removeAxis(this);
171 }
171 }
172
172
173 void QLogValueAxis::setMin(qreal min)
173 void QLogValueAxis::setMin(qreal min)
174 {
174 {
175 Q_D(QLogValueAxis);
175 Q_D(QLogValueAxis);
176 setRange(min, qMax(d->m_max, min));
176 setRange(min, qMax(d->m_max, min));
177 }
177 }
178
178
179 qreal QLogValueAxis::min() const
179 qreal QLogValueAxis::min() const
180 {
180 {
181 Q_D(const QLogValueAxis);
181 Q_D(const QLogValueAxis);
182 return d->m_min;
182 return d->m_min;
183 }
183 }
184
184
185 void QLogValueAxis::setMax(qreal max)
185 void QLogValueAxis::setMax(qreal max)
186 {
186 {
187 Q_D(QLogValueAxis);
187 Q_D(QLogValueAxis);
188 setRange(qMin(d->m_min, max), max);
188 setRange(qMin(d->m_min, max), max);
189 }
189 }
190
190
191 qreal QLogValueAxis::max() const
191 qreal QLogValueAxis::max() const
192 {
192 {
193 Q_D(const QLogValueAxis);
193 Q_D(const QLogValueAxis);
194 return d->m_max;
194 return d->m_max;
195 }
195 }
196
196
197 /*!
197 /*!
198 Sets range from \a min to \a max on the axis.
198 Sets range from \a min to \a max on the axis.
199 If min is greater than max then this function returns without making any changes.
199 If min is greater than max then this function returns without making any changes.
200 */
200 */
201 void QLogValueAxis::setRange(qreal min, qreal max)
201 void QLogValueAxis::setRange(qreal min, qreal max)
202 {
202 {
203 Q_D(QLogValueAxis);
203 Q_D(QLogValueAxis);
204 bool changed = false;
204 bool changed = false;
205
205
206 if (min > max)
206 if (min > max)
207 return;
207 return;
208
208
209 if (min > 0) {
209 if (min > 0) {
210 if (!qFuzzyCompare(d->m_min, min)) {
210 if (!qFuzzyCompare(d->m_min, min)) {
211 d->m_min = min;
211 d->m_min = min;
212 changed = true;
212 changed = true;
213 emit minChanged(min);
213 emit minChanged(min);
214 }
214 }
215
215
216 if (!qFuzzyCompare(d->m_max, max)) {
216 if (!qFuzzyCompare(d->m_max, max)) {
217 d->m_max = max;
217 d->m_max = max;
218 changed = true;
218 changed = true;
219 emit maxChanged(max);
219 emit maxChanged(max);
220 }
220 }
221
221
222 if (changed) {
222 if (changed) {
223 emit rangeChanged(min, max);
223 emit rangeChanged(min, max);
224 emit d->rangeChanged(min,max);
224 emit d->rangeChanged(min,max);
225 }
225 }
226 }
226 }
227 }
227 }
228
228
229 void QLogValueAxis::setLabelFormat(const QString &format)
229 void QLogValueAxis::setLabelFormat(const QString &format)
230 {
230 {
231 Q_D(QLogValueAxis);
231 Q_D(QLogValueAxis);
232 d->m_format = format;
232 d->m_format = format;
233 emit labelFormatChanged(format);
233 emit labelFormatChanged(format);
234 }
234 }
235
235
236 QString QLogValueAxis::labelFormat() const
236 QString QLogValueAxis::labelFormat() const
237 {
237 {
238 Q_D(const QLogValueAxis);
238 Q_D(const QLogValueAxis);
239 return d->m_format;
239 return d->m_format;
240 }
240 }
241
241
242 void QLogValueAxis::setBase(qreal base)
242 void QLogValueAxis::setBase(qreal base)
243 {
243 {
244 // check if base is correct
244 // check if base is correct
245 if (qFuzzyCompare(base, 1))
245 if (qFuzzyCompare(base, 1))
246 return;
246 return;
247
247
248 if (base > 0) {
248 if (base > 0) {
249 Q_D(QLogValueAxis);
249 Q_D(QLogValueAxis);
250 d->m_base = base;
250 d->m_base = base;
251 emit baseChanged(base);
251 emit baseChanged(base);
252 }
252 }
253 }
253 }
254
254
255 qreal QLogValueAxis::base() const
255 qreal QLogValueAxis::base() const
256 {
256 {
257 Q_D(const QLogValueAxis);
257 Q_D(const QLogValueAxis);
258 return d->m_base;
258 return d->m_base;
259 }
259 }
260
260
261 /*!
261 /*!
262 Returns the type of the axis
262 Returns the type of the axis
263 */
263 */
264 QAbstractAxis::AxisType QLogValueAxis::type() const
264 QAbstractAxis::AxisType QLogValueAxis::type() const
265 {
265 {
266 return AxisTypeLogValue;
266 return AxisTypeLogValue;
267 }
267 }
268
268
269 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
269 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
270
270
271 QLogValueAxisPrivate::QLogValueAxisPrivate(QLogValueAxis *q)
271 QLogValueAxisPrivate::QLogValueAxisPrivate(QLogValueAxis *q)
272 : QAbstractAxisPrivate(q),
272 : QAbstractAxisPrivate(q),
273 m_min(1),
273 m_min(1),
274 m_max(1),
274 m_max(1),
275 m_base(10),
275 m_base(10),
276 m_format(QString::null)
276 m_format(QString::null)
277 {
277 {
278 }
278 }
279
279
280 QLogValueAxisPrivate::~QLogValueAxisPrivate()
280 QLogValueAxisPrivate::~QLogValueAxisPrivate()
281 {
281 {
282
282
283 }
283 }
284
284
285 void QLogValueAxisPrivate::setMin(const QVariant &min)
285 void QLogValueAxisPrivate::setMin(const QVariant &min)
286 {
286 {
287 Q_Q(QLogValueAxis);
287 Q_Q(QLogValueAxis);
288 bool ok;
288 bool ok;
289 qreal value = min.toReal(&ok);
289 qreal value = min.toReal(&ok);
290 if (ok)
290 if (ok)
291 q->setMin(value);
291 q->setMin(value);
292 }
292 }
293
293
294 void QLogValueAxisPrivate::setMax(const QVariant &max)
294 void QLogValueAxisPrivate::setMax(const QVariant &max)
295 {
295 {
296
296
297 Q_Q(QLogValueAxis);
297 Q_Q(QLogValueAxis);
298 bool ok;
298 bool ok;
299 qreal value = max.toReal(&ok);
299 qreal value = max.toReal(&ok);
300 if (ok)
300 if (ok)
301 q->setMax(value);
301 q->setMax(value);
302 }
302 }
303
303
304 void QLogValueAxisPrivate::setRange(const QVariant &min, const QVariant &max)
304 void QLogValueAxisPrivate::setRange(const QVariant &min, const QVariant &max)
305 {
305 {
306 Q_Q(QLogValueAxis);
306 Q_Q(QLogValueAxis);
307 bool ok1;
307 bool ok1;
308 bool ok2;
308 bool ok2;
309 qreal value1 = min.toReal(&ok1);
309 qreal value1 = min.toReal(&ok1);
310 qreal value2 = max.toReal(&ok2);
310 qreal value2 = max.toReal(&ok2);
311 if (ok1 && ok2)
311 if (ok1 && ok2)
312 q->setRange(value1, value2);
312 q->setRange(value1, value2);
313 }
313 }
314
314
315 void QLogValueAxisPrivate::setRange(qreal min, qreal max)
315 void QLogValueAxisPrivate::setRange(qreal min, qreal max)
316 {
316 {
317 Q_Q(QLogValueAxis);
317 Q_Q(QLogValueAxis);
318 bool changed = false;
318 bool changed = false;
319
319
320 if (min > max)
320 if (min > max)
321 return;
321 return;
322
322
323 if (min > 0) {
323 if (min > 0) {
324 if (!qFuzzyCompare(m_min, min)) {
324 if (!qFuzzyCompare(m_min, min)) {
325 m_min = min;
325 m_min = min;
326 changed = true;
326 changed = true;
327 emit q->minChanged(min);
327 emit q->minChanged(min);
328 }
328 }
329
329
330 if (!qFuzzyCompare(m_max, max)) {
330 if (!qFuzzyCompare(m_max, max)) {
331 m_max = max;
331 m_max = max;
332 changed = true;
332 changed = true;
333 emit q->maxChanged(max);
333 emit q->maxChanged(max);
334 }
334 }
335
335
336 if (changed) {
336 if (changed) {
337 emit rangeChanged(min,max);
337 emit rangeChanged(min,max);
338 emit q->rangeChanged(min, max);
338 emit q->rangeChanged(min, max);
339 }
339 }
340 }
340 }
341 }
341 }
342
342
343 void QLogValueAxisPrivate::initializeGraphics(QGraphicsItem *parent)
343 void QLogValueAxisPrivate::initializeGraphics(QGraphicsItem *parent)
344 {
344 {
345 Q_Q(QLogValueAxis);
345 Q_Q(QLogValueAxis);
346 ChartAxisElement *axis(0);
346 ChartAxisElement *axis(0);
347
347
348 if (m_chart->chartType() == QChart::ChartTypeCartesian) {
348 if (m_chart->chartType() == QChart::ChartTypeCartesian) {
349 if (orientation() == Qt::Vertical)
349 if (orientation() == Qt::Vertical)
350 axis = new ChartLogValueAxisY(q,parent);
350 axis = new ChartLogValueAxisY(q,parent);
351 if (orientation() == Qt::Horizontal)
351 if (orientation() == Qt::Horizontal)
352 axis = new ChartLogValueAxisX(q,parent);
352 axis = new ChartLogValueAxisX(q,parent);
353 }
353 }
354
354
355 if (m_chart->chartType() == QChart::ChartTypePolar) {
355 if (m_chart->chartType() == QChart::ChartTypePolar) {
356 if (orientation() == Qt::Vertical)
356 if (orientation() == Qt::Vertical)
357 axis = new PolarChartLogValueAxisRadial(q, parent);
357 axis = new PolarChartLogValueAxisRadial(q, parent);
358 if (orientation() == Qt::Horizontal)
358 if (orientation() == Qt::Horizontal)
359 axis = new PolarChartLogValueAxisAngular(q, parent);
359 axis = new PolarChartLogValueAxisAngular(q, parent);
360 }
360 }
361
361
362 m_item.reset(axis);
362 m_item.reset(axis);
363 QAbstractAxisPrivate::initializeGraphics(parent);
363 QAbstractAxisPrivate::initializeGraphics(parent);
364 }
364 }
365
365
366
366
367 void QLogValueAxisPrivate::initializeDomain(AbstractDomain *domain)
367 void QLogValueAxisPrivate::initializeDomain(AbstractDomain *domain)
368 {
368 {
369 if (orientation() == Qt::Vertical) {
369 if (orientation() == Qt::Vertical) {
370 if (!qFuzzyCompare(m_max, m_min)) {
370 if (!qFuzzyCompare(m_max, m_min)) {
371 domain->setRangeY(m_min, m_max);
371 domain->setRangeY(m_min, m_max);
372 } else if ( domain->minY() > 0) {
372 } else if ( domain->minY() > 0) {
373 setRange(domain->minY(), domain->maxY());
373 setRange(domain->minY(), domain->maxY());
374 } else if (domain->maxY() > 0) {
374 } else if (domain->maxY() > 0) {
375 domain->setRangeY(m_min, domain->maxY());
375 domain->setRangeY(m_min, domain->maxY());
376 } else {
376 } else {
377 domain->setRangeY(1, 10);
377 domain->setRangeY(1, 10);
378 }
378 }
379 }
379 }
380 if (orientation() == Qt::Horizontal) {
380 if (orientation() == Qt::Horizontal) {
381 if (!qFuzzyCompare(m_max, m_min)) {
381 if (!qFuzzyCompare(m_max, m_min)) {
382 domain->setRangeX(m_min, m_max);
382 domain->setRangeX(m_min, m_max);
383 } else if (domain->minX() > 0){
383 } else if (domain->minX() > 0){
384 setRange(domain->minX(), domain->maxX());
384 setRange(domain->minX(), domain->maxX());
385 } else if (domain->maxX() > 0) {
385 } else if (domain->maxX() > 0) {
386 domain->setRangeX(m_min, domain->maxX());
386 domain->setRangeX(m_min, domain->maxX());
387 } else {
387 } else {
388 domain->setRangeX(1, 10);
388 domain->setRangeX(1, 10);
389 }
389 }
390 }
390 }
391 }
391 }
392
392
393 #include "moc_qlogvalueaxis.cpp"
393 #include "moc_qlogvalueaxis.cpp"
394 #include "moc_qlogvalueaxis_p.cpp"
394 #include "moc_qlogvalueaxis_p.cpp"
395
395
396 QTCOMMERCIALCHART_END_NAMESPACE
396 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,1020 +1,1020
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qabstractaxis.h"
21 #include "qabstractaxis.h"
22 #include "qabstractaxis_p.h"
22 #include "qabstractaxis_p.h"
23 #include "chartdataset_p.h"
23 #include "chartdataset_p.h"
24 #include "charttheme_p.h"
24 #include "charttheme_p.h"
25 #include "qchart_p.h"
25 #include "qchart_p.h"
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
28
29 /*!
29 /*!
30 \class QAbstractAxis
30 \class QAbstractAxis
31 \brief The QAbstractAxis class is used for manipulating chart's axis.
31 \brief The QAbstractAxis class is used for manipulating chart's axis.
32 \mainclass
32 \mainclass
33
33
34 Each series can be bound to one or more horizontal and vertical axes, but mixing axis types
34 Each series can be bound to one or more horizontal and vertical axes, but mixing axis types
35 that would result in different domains is not supported, such as specifying
35 that would result in different domains is not supported, such as specifying
36 QValueAxis and QLogValueAxis on the same orientation.
36 QValueAxis and QLogValueAxis on the same orientation.
37
37
38 Properties and visibility of various axis elements such as axis line, title, labels, grid lines,
38 Properties and visibility of various axis elements such as axis line, title, labels, grid lines,
39 and shades can be individually controlled.
39 and shades can be individually controlled.
40 */
40 */
41
41
42 /*!
42 /*!
43 \qmlclass AbstractAxis QAbstractAxis
43 \qmlclass AbstractAxis QAbstractAxis
44 \brief The AbstractAxis is a base element used for specialized axis elements
44 \brief The AbstractAxis is a base element used for specialized axis elements.
45
45
46 Each series can be bound to only one horizontal and vertical axis.
46 Each series can be bound to only one horizontal and vertical axis.
47
47
48 Properties and visibility of various axis elements such as axis line, title, labels, grid lines,
48 Properties and visibility of various axis elements such as axis line, title, labels, grid lines,
49 and shades can be individually controlled.
49 and shades can be individually controlled.
50 */
50 */
51
51
52 /*!
52 /*!
53 \enum QAbstractAxis::AxisType
53 \enum QAbstractAxis::AxisType
54
54
55 The type of the series object.
55 The type of the series object.
56
56
57 \value AxisTypeNoAxis
57 \value AxisTypeNoAxis
58 \value AxisTypeValue
58 \value AxisTypeValue
59 \value AxisTypeBarCategory
59 \value AxisTypeBarCategory
60 \value AxisTypeCategory
60 \value AxisTypeCategory
61 \value AxisTypeDateTime
61 \value AxisTypeDateTime
62 \value AxisTypeLogValue
62 \value AxisTypeLogValue
63 */
63 */
64
64
65 /*!
65 /*!
66 *\fn void QAbstractAxis::type() const
66 *\fn void QAbstractAxis::type() const
67 Returns the type of the axis
67 Returns the type of the axis
68 */
68 */
69
69
70 /*!
70 /*!
71 \property QAbstractAxis::lineVisible
71 \property QAbstractAxis::lineVisible
72 The visibility of the axis line
72 The visibility of the axis line
73 */
73 */
74 /*!
74 /*!
75 \qmlproperty bool AbstractAxis::lineVisible
75 \qmlproperty bool AbstractAxis::lineVisible
76 The visibility of the axis line
76 The visibility of the axis line
77 */
77 */
78
78
79 /*!
79 /*!
80 \property QAbstractAxis::linePen
80 \property QAbstractAxis::linePen
81 The pen of the line.
81 The pen of the line.
82 */
82 */
83
83
84 /*!
84 /*!
85 \property QAbstractAxis::labelsVisible
85 \property QAbstractAxis::labelsVisible
86 Defines if axis labels are visible.
86 Defines if axis labels are visible.
87 */
87 */
88 /*!
88 /*!
89 \qmlproperty bool AbstractAxis::labelsVisible
89 \qmlproperty bool AbstractAxis::labelsVisible
90 Defines if axis labels are visible.
90 Defines if axis labels are visible.
91 */
91 */
92
92
93 /*!
93 /*!
94 \property QAbstractAxis::labelsPen
94 \property QAbstractAxis::labelsPen
95 The pen of the labels.
95 The pen of the labels.
96 */
96 */
97
97
98 /*!
98 /*!
99 \property QAbstractAxis::labelsBrush
99 \property QAbstractAxis::labelsBrush
100 The brush of the labels.
100 The brush of the labels.
101 */
101 */
102
102
103 /*!
103 /*!
104 \property QAbstractAxis::visible
104 \property QAbstractAxis::visible
105 The visibility of the axis.
105 The visibility of the axis.
106 */
106 */
107 /*!
107 /*!
108 \qmlproperty bool AbstractAxis::visible
108 \qmlproperty bool AbstractAxis::visible
109 The visibility of the axis.
109 The visibility of the axis.
110 */
110 */
111
111
112 /*!
112 /*!
113 \property QAbstractAxis::gridVisible
113 \property QAbstractAxis::gridVisible
114 The visibility of the grid lines.
114 The visibility of the grid lines.
115 */
115 */
116 /*!
116 /*!
117 \qmlproperty bool AbstractAxis::gridVisible
117 \qmlproperty bool AbstractAxis::gridVisible
118 The visibility of the grid lines.
118 The visibility of the grid lines.
119 */
119 */
120
120
121 /*!
121 /*!
122 \property QAbstractAxis::color
122 \property QAbstractAxis::color
123 The color of the axis and ticks.
123 The color of the axis and ticks.
124 */
124 */
125 /*!
125 /*!
126 \qmlproperty color AbstractAxis::color
126 \qmlproperty color AbstractAxis::color
127 The color of the axis and ticks.
127 The color of the axis and ticks.
128 */
128 */
129
129
130 /*!
130 /*!
131 \property QAbstractAxis::gridLinePen
131 \property QAbstractAxis::gridLinePen
132 The pen of the grid line.
132 The pen of the grid line.
133 */
133 */
134
134
135 /*!
135 /*!
136 \property QAbstractAxis::labelsFont
136 \property QAbstractAxis::labelsFont
137 The font of the axis labels.
137 The font of the axis labels.
138 */
138 */
139
139
140 /*!
140 /*!
141 \qmlproperty Font AbstractAxis::labelsFont
141 \qmlproperty Font AbstractAxis::labelsFont
142 The font of the axis labels.
142 The font of the axis labels.
143
143
144 See the \l {Font} {QML Font Element} for detailed documentation.
144 See the \l {Font} {QML Font Element} for detailed documentation.
145 */
145 */
146
146
147 /*!
147 /*!
148 \property QAbstractAxis::labelsColor
148 \property QAbstractAxis::labelsColor
149 The color of the axis labels.
149 The color of the axis labels.
150 */
150 */
151 /*!
151 /*!
152 \qmlproperty color AbstractAxis::labelsColor
152 \qmlproperty color AbstractAxis::labelsColor
153 The color of the axis labels.
153 The color of the axis labels.
154 */
154 */
155
155
156 /*!
156 /*!
157 \property QAbstractAxis::labelsAngle
157 \property QAbstractAxis::labelsAngle
158 The angle of the axis labels in degrees.
158 The angle of the axis labels in degrees.
159 */
159 */
160 /*!
160 /*!
161 \qmlproperty int AbstractAxis::labelsAngle
161 \qmlproperty int AbstractAxis::labelsAngle
162 The angle of the axis labels in degrees.
162 The angle of the axis labels in degrees.
163 */
163 */
164
164
165 /*!
165 /*!
166 \property QAbstractAxis::shadesVisible
166 \property QAbstractAxis::shadesVisible
167 The visibility of the axis shades.
167 The visibility of the axis shades.
168 */
168 */
169 /*!
169 /*!
170 \qmlproperty bool AbstractAxis::shadesVisible
170 \qmlproperty bool AbstractAxis::shadesVisible
171 The visibility of the axis shades.
171 The visibility of the axis shades.
172 */
172 */
173
173
174 /*!
174 /*!
175 \property QAbstractAxis::shadesColor
175 \property QAbstractAxis::shadesColor
176 The fill (brush) color of the axis shades.
176 The fill (brush) color of the axis shades.
177 */
177 */
178 /*!
178 /*!
179 \qmlproperty color AbstractAxis::shadesColor
179 \qmlproperty color AbstractAxis::shadesColor
180 The fill (brush) color of the axis shades.
180 The fill (brush) color of the axis shades.
181 */
181 */
182
182
183 /*!
183 /*!
184 \property QAbstractAxis::shadesBorderColor
184 \property QAbstractAxis::shadesBorderColor
185 The border (pen) color of the axis shades.
185 The border (pen) color of the axis shades.
186 */
186 */
187 /*!
187 /*!
188 \qmlproperty color AbstractAxis::shadesBorderColor
188 \qmlproperty color AbstractAxis::shadesBorderColor
189 The border (pen) color of the axis shades.
189 The border (pen) color of the axis shades.
190 */
190 */
191
191
192 /*!
192 /*!
193 \property QAbstractAxis::shadesPen
193 \property QAbstractAxis::shadesPen
194 The pen of the axis shades (area between grid lines).
194 The pen of the axis shades (area between grid lines).
195 */
195 */
196
196
197 /*!
197 /*!
198 \property QAbstractAxis::shadesBrush
198 \property QAbstractAxis::shadesBrush
199 The brush of the axis shades (area between grid lines).
199 The brush of the axis shades (area between grid lines).
200 */
200 */
201
201
202 /*!
202 /*!
203 \property QAbstractAxis::titleVisible
203 \property QAbstractAxis::titleVisible
204 The visibility of the axis title. By default the value is true.
204 The visibility of the axis title. By default the value is true.
205 */
205 */
206 /*!
206 /*!
207 \qmlproperty bool AbstractAxis::titleVisible
207 \qmlproperty bool AbstractAxis::titleVisible
208 The visibility of the axis title. By default the value is true.
208 The visibility of the axis title. By default the value is true.
209 */
209 */
210
210
211 /*!
211 /*!
212 \property QAbstractAxis::titleText
212 \property QAbstractAxis::titleText
213 The title of the axis. Empty by default.
213 The title of the axis. Empty by default.
214 */
214 */
215 /*!
215 /*!
216 \qmlproperty String AbstractAxis::titleText
216 \qmlproperty String AbstractAxis::titleText
217 The title of the axis. Empty by default.
217 The title of the axis. Empty by default.
218 */
218 */
219
219
220 /*!
220 /*!
221 \property QAbstractAxis::titlePen
221 \property QAbstractAxis::titlePen
222 The pen of the title text.
222 The pen of the title text.
223 */
223 */
224
224
225 /*!
225 /*!
226 \property QAbstractAxis::titleBrush
226 \property QAbstractAxis::titleBrush
227 The brush of the title text.
227 The brush of the title text.
228 */
228 */
229
229
230 /*!
230 /*!
231 \property QAbstractAxis::titleFont
231 \property QAbstractAxis::titleFont
232 The font of the title of the axis.
232 The font of the title of the axis.
233 */
233 */
234 /*!
234 /*!
235 \qmlproperty Font AbstractAxis::titleFont
235 \qmlproperty Font AbstractAxis::titleFont
236 The font of the title of the axis.
236 The font of the title of the axis.
237 */
237 */
238
238
239 /*!
239 /*!
240 \property QAbstractAxis::orientation
240 \property QAbstractAxis::orientation
241 The orientation of the axis. Fixed to either Qt::Horizontal or Qt::Vertical when you add the axis to a chart.
241 The orientation of the axis. Fixed to either Qt::Horizontal or Qt::Vertical when you add the axis to a chart.
242 */
242 */
243 /*!
243 /*!
244 \qmlproperty Qt.Orientation AbstractAxis::orientation
244 \qmlproperty Qt.Orientation AbstractAxis::orientation
245 The orientation of the axis. Fixed to either Qt.Horizontal or Qt.Vertical when the axis is set to a series.
245 The orientation of the axis. Fixed to either Qt.Horizontal or Qt.Vertical when the axis is set to a series.
246 */
246 */
247
247
248 /*!
248 /*!
249 \property QAbstractAxis::alignment
249 \property QAbstractAxis::alignment
250 The alignment of the axis. Can be Qt::AlignLeft, Qt::AlignRight, Qt::AlignBottom, or Qt::AlignTop.
250 The alignment of the axis. Can be Qt::AlignLeft, Qt::AlignRight, Qt::AlignBottom, or Qt::AlignTop.
251 */
251 */
252 /*!
252 /*!
253 \qmlproperty alignment AbstractAxis::alignment
253 \qmlproperty alignment AbstractAxis::alignment
254 The alignment of the axis. Can be Qt.AlignLeft, Qt.AlignRight, Qt.AlignBottom, or Qt.AlignTop.
254 The alignment of the axis. Can be Qt.AlignLeft, Qt.AlignRight, Qt.AlignBottom, or Qt.AlignTop.
255 */
255 */
256
256
257 /*!
257 /*!
258 \fn void QAbstractAxis::visibleChanged(bool visible)
258 \fn void QAbstractAxis::visibleChanged(bool visible)
259 Visibility of the axis has changed to \a visible.
259 Visibility of the axis has changed to \a visible.
260 */
260 */
261 /*!
261 /*!
262 \qmlsignal AbstractAxis::onVisibleChanged(bool visible)
262 \qmlsignal AbstractAxis::onVisibleChanged(bool visible)
263 Visibility of the axis has changed to \a visible.
263 Visibility of the axis has changed to \a visible.
264 */
264 */
265
265
266 /*!
266 /*!
267 \fn void QAbstractAxis::linePenChanged(const QPen& pen)
267 \fn void QAbstractAxis::linePenChanged(const QPen& pen)
268 The pen of the line of the axis has changed to \a pen.
268 The pen of the line of the axis has changed to \a pen.
269 */
269 */
270
270
271 /*!
271 /*!
272 \fn void QAbstractAxis::lineVisibleChanged(bool visible)
272 \fn void QAbstractAxis::lineVisibleChanged(bool visible)
273 Visibility of the axis line has changed to \a visible.
273 Visibility of the axis line has changed to \a visible.
274 */
274 */
275 /*!
275 /*!
276 \qmlsignal AbstractAxis::onLineVisibleChanged(bool visible)
276 \qmlsignal AbstractAxis::onLineVisibleChanged(bool visible)
277 Visibility of the axis line has changed to \a visible.
277 Visibility of the axis line has changed to \a visible.
278 */
278 */
279
279
280 /*!
280 /*!
281 \fn void QAbstractAxis::labelsVisibleChanged(bool visible)
281 \fn void QAbstractAxis::labelsVisibleChanged(bool visible)
282 Visibility of the labels of the axis has changed to \a visible.
282 Visibility of the labels of the axis has changed to \a visible.
283 */
283 */
284 /*!
284 /*!
285 \qmlsignal AbstractAxis::onLabelsVisibleChanged(bool visible)
285 \qmlsignal AbstractAxis::onLabelsVisibleChanged(bool visible)
286 Visibility of the labels of the axis has changed to \a visible.
286 Visibility of the labels of the axis has changed to \a visible.
287 */
287 */
288
288
289 /*!
289 /*!
290 \fn void QAbstractAxis::labelsFontChanged(const QFont& font)
290 \fn void QAbstractAxis::labelsFontChanged(const QFont& font)
291 The font of the axis labels has changed to \a font.
291 The font of the axis labels has changed to \a font.
292 */
292 */
293 /*!
293 /*!
294 \qmlsignal AbstractAxis::onLabelsFontChanged(Font font)
294 \qmlsignal AbstractAxis::onLabelsFontChanged(Font font)
295 The font of the axis labels has changed to \a font.
295 The font of the axis labels has changed to \a font.
296 */
296 */
297
297
298 /*!
298 /*!
299 \fn void QAbstractAxis::labelsPenChanged(const QPen& pen)
299 \fn void QAbstractAxis::labelsPenChanged(const QPen& pen)
300 The pen of the axis labels has changed to \a pen.
300 The pen of the axis labels has changed to \a pen.
301 */
301 */
302
302
303 /*!
303 /*!
304 \fn void QAbstractAxis::labelsBrushChanged(const QBrush& brush)
304 \fn void QAbstractAxis::labelsBrushChanged(const QBrush& brush)
305 The brush of the axis labels has changed to \a brush.
305 The brush of the axis labels has changed to \a brush.
306 */
306 */
307
307
308 /*!
308 /*!
309 \fn void QAbstractAxis::labelsAngleChanged(int angle)
309 \fn void QAbstractAxis::labelsAngleChanged(int angle)
310 The angle of the axis labels has changed to \a angle.
310 The angle of the axis labels has changed to \a angle.
311 */
311 */
312 /*!
312 /*!
313 \qmlsignal AbstractAxis::onLabelsAngleChanged(int angle)
313 \qmlsignal AbstractAxis::onLabelsAngleChanged(int angle)
314 The angle of the axis labels has changed to \a angle.
314 The angle of the axis labels has changed to \a angle.
315 */
315 */
316
316
317 /*!
317 /*!
318 \fn void QAbstractAxis::gridVisibleChanged(bool visible)
318 \fn void QAbstractAxis::gridVisibleChanged(bool visible)
319 Visibility of the grid lines of the axis has changed to \a visible.
319 Visibility of the grid lines of the axis has changed to \a visible.
320 */
320 */
321 /*!
321 /*!
322 \qmlsignal AbstractAxis::onGridVisibleChanged(bool visible)
322 \qmlsignal AbstractAxis::onGridVisibleChanged(bool visible)
323 Visibility of the grid lines of the axis has changed to \a visible.
323 Visibility of the grid lines of the axis has changed to \a visible.
324 */
324 */
325
325
326 /*!
326 /*!
327 \fn void QAbstractAxis::gridLinePenChanged(const QPen& pen)
327 \fn void QAbstractAxis::gridLinePenChanged(const QPen& pen)
328 The pen of the grid line has changed to \a pen.
328 The pen of the grid line has changed to \a pen.
329 */
329 */
330
330
331 /*!
331 /*!
332 \fn void QAbstractAxis::colorChanged(QColor color)
332 \fn void QAbstractAxis::colorChanged(QColor color)
333 Emitted if the \a color of the axis is changed.
333 Emitted if the \a color of the axis is changed.
334 */
334 */
335 /*!
335 /*!
336 \qmlsignal AbstractAxis::onColorChanged(QColor color)
336 \qmlsignal AbstractAxis::onColorChanged(QColor color)
337 Emitted if the \a color of the axis is changed.
337 Emitted if the \a color of the axis is changed.
338 */
338 */
339
339
340 /*!
340 /*!
341 \fn void QAbstractAxis::labelsColorChanged(QColor color)
341 \fn void QAbstractAxis::labelsColorChanged(QColor color)
342 Emitted if the \a color of the axis labels is changed.
342 Emitted if the \a color of the axis labels is changed.
343 */
343 */
344 /*!
344 /*!
345 \qmlsignal AbstractAxis::onLabelsColorChanged(QColor color)
345 \qmlsignal AbstractAxis::onLabelsColorChanged(QColor color)
346 Emitted if the \a color of the axis labels is changed.
346 Emitted if the \a color of the axis labels is changed.
347 */
347 */
348
348
349 /*!
349 /*!
350 \fn void QAbstractAxis::titleVisibleChanged(bool visible)
350 \fn void QAbstractAxis::titleVisibleChanged(bool visible)
351 Visibility of the title text of the axis has changed to \a visible.
351 Visibility of the title text of the axis has changed to \a visible.
352 */
352 */
353 /*!
353 /*!
354 \qmlsignal AbstractAxis::onTitleVisibleChanged(bool visible)
354 \qmlsignal AbstractAxis::onTitleVisibleChanged(bool visible)
355 Visibility of the title text of the axis has changed to \a visible.
355 Visibility of the title text of the axis has changed to \a visible.
356 */
356 */
357
357
358 /*!
358 /*!
359 \fn void QAbstractAxis::titleTextChanged(const QString& text)
359 \fn void QAbstractAxis::titleTextChanged(const QString& text)
360 The text of the axis title has changed to \a text.
360 The text of the axis title has changed to \a text.
361 */
361 */
362 /*!
362 /*!
363 \qmlsignal AbstractAxis::onTitleTextChanged(String text)
363 \qmlsignal AbstractAxis::onTitleTextChanged(String text)
364 The text of the axis title has changed to \a text.
364 The text of the axis title has changed to \a text.
365 */
365 */
366
366
367 /*!
367 /*!
368 \fn void QAbstractAxis::titlePenChanged(const QPen& pen)
368 \fn void QAbstractAxis::titlePenChanged(const QPen& pen)
369 The pen of the axis shades has changed to \a pen.
369 The pen of the axis shades has changed to \a pen.
370 */
370 */
371
371
372 /*!
372 /*!
373 \fn void QAbstractAxis::titleBrushChanged(const QBrush& brush)
373 \fn void QAbstractAxis::titleBrushChanged(const QBrush& brush)
374 The brush of the axis title has changed to \a brush.
374 The brush of the axis title has changed to \a brush.
375 */
375 */
376
376
377 /*!
377 /*!
378 \fn void QAbstractAxis::titleFontChanged(const QFont& font)
378 \fn void QAbstractAxis::titleFontChanged(const QFont& font)
379 The font of the axis title has changed to \a font.
379 The font of the axis title has changed to \a font.
380 */
380 */
381 /*!
381 /*!
382 \qmlsignal AbstractAxis::onTitleFontChanged(Font font)
382 \qmlsignal AbstractAxis::onTitleFontChanged(Font font)
383 The font of the axis title has changed to \a font.
383 The font of the axis title has changed to \a font.
384 */
384 */
385
385
386 /*!
386 /*!
387 \fn void QAbstractAxis::shadesVisibleChanged(bool)
387 \fn void QAbstractAxis::shadesVisibleChanged(bool)
388 Emitted if the visibility of the axis shades is changed to \a visible.
388 Emitted if the visibility of the axis shades is changed to \a visible.
389 */
389 */
390 /*!
390 /*!
391 \qmlsignal AbstractAxis::onShadesVisibleChanged(bool visible)
391 \qmlsignal AbstractAxis::onShadesVisibleChanged(bool visible)
392 Emitted if the visibility of the axis shades is changed to \a visible.
392 Emitted if the visibility of the axis shades is changed to \a visible.
393 */
393 */
394
394
395 /*!
395 /*!
396 \fn void QAbstractAxis::shadesColorChanged(QColor color)
396 \fn void QAbstractAxis::shadesColorChanged(QColor color)
397 Emitted if the \a color of the axis shades is changed.
397 Emitted if the \a color of the axis shades is changed.
398 */
398 */
399 /*!
399 /*!
400 \qmlsignal AbstractAxis::onShadesColorChanged(QColor color)
400 \qmlsignal AbstractAxis::onShadesColorChanged(QColor color)
401 Emitted if the \a color of the axis shades is changed.
401 Emitted if the \a color of the axis shades is changed.
402 */
402 */
403
403
404 /*!
404 /*!
405 \fn void QAbstractAxis::shadesBorderColorChanged(QColor)
405 \fn void QAbstractAxis::shadesBorderColorChanged(QColor)
406 Emitted if the border \a color of the axis shades is changed.
406 Emitted if the border \a color of the axis shades is changed.
407 */
407 */
408 /*!
408 /*!
409 \qmlsignal AbstractAxis::onBorderColorChanged(QColor color)
409 \qmlsignal AbstractAxis::onBorderColorChanged(QColor color)
410 Emitted if the border \a color of the axis shades is changed.
410 Emitted if the border \a color of the axis shades is changed.
411 */
411 */
412
412
413 /*!
413 /*!
414 \fn void QAbstractAxis::shadesBrushChanged(const QBrush& brush)
414 \fn void QAbstractAxis::shadesBrushChanged(const QBrush& brush)
415 The brush of the axis shades has changed to \a brush.
415 The brush of the axis shades has changed to \a brush.
416 */
416 */
417
417
418 /*!
418 /*!
419 \fn void QAbstractAxis::shadesPenChanged(const QPen& pen)
419 \fn void QAbstractAxis::shadesPenChanged(const QPen& pen)
420 The pen of the axis shades has changed to \a pen.
420 The pen of the axis shades has changed to \a pen.
421 */
421 */
422
422
423 /*!
423 /*!
424 \internal
424 \internal
425 Constructs new axis object which is a child of \a parent. Ownership is taken by
425 Constructs new axis object which is a child of \a parent. Ownership is taken by
426 QChart when axis added.
426 QChart when axis added.
427 */
427 */
428
428
429 QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent)
429 QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent)
430 : QObject(parent),
430 : QObject(parent),
431 d_ptr(&d)
431 d_ptr(&d)
432 {
432 {
433 }
433 }
434
434
435 /*!
435 /*!
436 Destructor of the axis object. When axis is added to chart, chart object takes ownership.
436 Destructor of the axis object. When axis is added to chart, chart object takes ownership.
437 */
437 */
438
438
439 QAbstractAxis::~QAbstractAxis()
439 QAbstractAxis::~QAbstractAxis()
440 {
440 {
441 if (d_ptr->m_chart)
441 if (d_ptr->m_chart)
442 qFatal("Still binded axis detected !");
442 qFatal("Still binded axis detected !");
443 }
443 }
444
444
445 /*!
445 /*!
446 Sets \a pen used to draw axis line and ticks.
446 Sets \a pen used to draw axis line and ticks.
447 */
447 */
448 void QAbstractAxis::setLinePen(const QPen &pen)
448 void QAbstractAxis::setLinePen(const QPen &pen)
449 {
449 {
450 if (d_ptr->m_axisPen != pen) {
450 if (d_ptr->m_axisPen != pen) {
451 d_ptr->m_axisPen = pen;
451 d_ptr->m_axisPen = pen;
452 emit linePenChanged(pen);
452 emit linePenChanged(pen);
453 }
453 }
454 }
454 }
455
455
456 /*!
456 /*!
457 Returns pen used to draw axis and ticks.
457 Returns pen used to draw axis and ticks.
458 */
458 */
459 QPen QAbstractAxis::linePen() const
459 QPen QAbstractAxis::linePen() const
460 {
460 {
461 if (d_ptr->m_axisPen == QChartPrivate::defaultPen())
461 if (d_ptr->m_axisPen == QChartPrivate::defaultPen())
462 return QPen();
462 return QPen();
463 else
463 else
464 return d_ptr->m_axisPen;
464 return d_ptr->m_axisPen;
465 }
465 }
466
466
467 //TODO: remove me 2.0
467 //TODO: remove me 2.0
468 void QAbstractAxis::setLinePenColor(QColor color)
468 void QAbstractAxis::setLinePenColor(QColor color)
469 {
469 {
470 QPen p = d_ptr->m_axisPen;
470 QPen p = d_ptr->m_axisPen;
471 if (p.color() != color) {
471 if (p.color() != color) {
472 p.setColor(color);
472 p.setColor(color);
473 setLinePen(p);
473 setLinePen(p);
474 emit colorChanged(color);
474 emit colorChanged(color);
475 }
475 }
476 }
476 }
477
477
478 QColor QAbstractAxis::linePenColor() const
478 QColor QAbstractAxis::linePenColor() const
479 {
479 {
480 return linePen().color();
480 return linePen().color();
481 }
481 }
482
482
483 /*!
483 /*!
484 Sets if axis and ticks are \a visible.
484 Sets if axis and ticks are \a visible.
485 */
485 */
486 void QAbstractAxis::setLineVisible(bool visible)
486 void QAbstractAxis::setLineVisible(bool visible)
487 {
487 {
488 if (d_ptr->m_arrowVisible != visible) {
488 if (d_ptr->m_arrowVisible != visible) {
489 d_ptr->m_arrowVisible = visible;
489 d_ptr->m_arrowVisible = visible;
490 emit lineVisibleChanged(visible);
490 emit lineVisibleChanged(visible);
491 }
491 }
492 }
492 }
493
493
494 bool QAbstractAxis::isLineVisible() const
494 bool QAbstractAxis::isLineVisible() const
495 {
495 {
496 return d_ptr->m_arrowVisible;
496 return d_ptr->m_arrowVisible;
497 }
497 }
498
498
499 void QAbstractAxis::setGridLineVisible(bool visible)
499 void QAbstractAxis::setGridLineVisible(bool visible)
500 {
500 {
501 if (d_ptr->m_gridLineVisible != visible) {
501 if (d_ptr->m_gridLineVisible != visible) {
502 d_ptr->m_gridLineVisible = visible;
502 d_ptr->m_gridLineVisible = visible;
503 emit gridVisibleChanged(visible);
503 emit gridVisibleChanged(visible);
504 }
504 }
505 }
505 }
506
506
507 bool QAbstractAxis::isGridLineVisible() const
507 bool QAbstractAxis::isGridLineVisible() const
508 {
508 {
509 return d_ptr->m_gridLineVisible;
509 return d_ptr->m_gridLineVisible;
510 }
510 }
511
511
512 /*!
512 /*!
513 Sets \a pen used to draw grid line.
513 Sets \a pen used to draw grid line.
514 */
514 */
515 void QAbstractAxis::setGridLinePen(const QPen &pen)
515 void QAbstractAxis::setGridLinePen(const QPen &pen)
516 {
516 {
517 if (d_ptr->m_gridLinePen != pen) {
517 if (d_ptr->m_gridLinePen != pen) {
518 d_ptr->m_gridLinePen = pen;
518 d_ptr->m_gridLinePen = pen;
519 emit gridLinePenChanged(pen);
519 emit gridLinePenChanged(pen);
520 }
520 }
521 }
521 }
522
522
523 /*!
523 /*!
524 Returns pen used to draw grid.
524 Returns pen used to draw grid.
525 */
525 */
526 QPen QAbstractAxis::gridLinePen() const
526 QPen QAbstractAxis::gridLinePen() const
527 {
527 {
528 if (d_ptr->m_gridLinePen == QChartPrivate::defaultPen())
528 if (d_ptr->m_gridLinePen == QChartPrivate::defaultPen())
529 return QPen();
529 return QPen();
530 else
530 else
531 return d_ptr->m_gridLinePen;
531 return d_ptr->m_gridLinePen;
532 }
532 }
533
533
534 void QAbstractAxis::setLabelsVisible(bool visible)
534 void QAbstractAxis::setLabelsVisible(bool visible)
535 {
535 {
536 if (d_ptr->m_labelsVisible != visible) {
536 if (d_ptr->m_labelsVisible != visible) {
537 d_ptr->m_labelsVisible = visible;
537 d_ptr->m_labelsVisible = visible;
538 emit labelsVisibleChanged(visible);
538 emit labelsVisibleChanged(visible);
539 }
539 }
540 }
540 }
541
541
542 bool QAbstractAxis::labelsVisible() const
542 bool QAbstractAxis::labelsVisible() const
543 {
543 {
544 return d_ptr->m_labelsVisible;
544 return d_ptr->m_labelsVisible;
545 }
545 }
546
546
547 /*!
547 /*!
548 Sets \a pen used to draw labels.
548 Sets \a pen used to draw labels.
549 */
549 */
550 void QAbstractAxis::setLabelsPen(const QPen &pen)
550 void QAbstractAxis::setLabelsPen(const QPen &pen)
551 {
551 {
552 if (d_ptr->m_labelsPen != pen) {
552 if (d_ptr->m_labelsPen != pen) {
553 d_ptr->m_labelsPen = pen;
553 d_ptr->m_labelsPen = pen;
554 emit labelsPenChanged(pen);
554 emit labelsPenChanged(pen);
555 }
555 }
556 }
556 }
557
557
558 /*!
558 /*!
559 Returns the pen used to labels.
559 Returns the pen used to labels.
560 */
560 */
561 QPen QAbstractAxis::labelsPen() const
561 QPen QAbstractAxis::labelsPen() const
562 {
562 {
563 if (d_ptr->m_labelsPen == QChartPrivate::defaultPen())
563 if (d_ptr->m_labelsPen == QChartPrivate::defaultPen())
564 return QPen();
564 return QPen();
565 else
565 else
566 return d_ptr->m_labelsPen;
566 return d_ptr->m_labelsPen;
567 }
567 }
568
568
569 /*!
569 /*!
570 Sets \a brush used to draw labels.
570 Sets \a brush used to draw labels.
571 */
571 */
572 void QAbstractAxis::setLabelsBrush(const QBrush &brush)
572 void QAbstractAxis::setLabelsBrush(const QBrush &brush)
573 {
573 {
574 if (d_ptr->m_labelsBrush != brush) {
574 if (d_ptr->m_labelsBrush != brush) {
575 d_ptr->m_labelsBrush = brush;
575 d_ptr->m_labelsBrush = brush;
576 emit labelsBrushChanged(brush);
576 emit labelsBrushChanged(brush);
577 }
577 }
578 }
578 }
579
579
580 /*!
580 /*!
581 Returns brush used to draw labels.
581 Returns brush used to draw labels.
582 */
582 */
583 QBrush QAbstractAxis::labelsBrush() const
583 QBrush QAbstractAxis::labelsBrush() const
584 {
584 {
585 if (d_ptr->m_labelsBrush == QChartPrivate::defaultBrush())
585 if (d_ptr->m_labelsBrush == QChartPrivate::defaultBrush())
586 return QBrush();
586 return QBrush();
587 else
587 else
588 return d_ptr->m_labelsBrush;
588 return d_ptr->m_labelsBrush;
589 }
589 }
590
590
591 /*!
591 /*!
592 Sets \a font used to draw labels.
592 Sets \a font used to draw labels.
593 */
593 */
594 void QAbstractAxis::setLabelsFont(const QFont &font)
594 void QAbstractAxis::setLabelsFont(const QFont &font)
595 {
595 {
596 if (d_ptr->m_labelsFont != font) {
596 if (d_ptr->m_labelsFont != font) {
597 d_ptr->m_labelsFont = font;
597 d_ptr->m_labelsFont = font;
598 emit labelsFontChanged(font);
598 emit labelsFontChanged(font);
599 }
599 }
600 }
600 }
601
601
602 /*!
602 /*!
603 Returns font used to draw labels.
603 Returns font used to draw labels.
604 */
604 */
605 QFont QAbstractAxis::labelsFont() const
605 QFont QAbstractAxis::labelsFont() const
606 {
606 {
607 if (d_ptr->m_labelsFont == QChartPrivate::defaultFont())
607 if (d_ptr->m_labelsFont == QChartPrivate::defaultFont())
608 return QFont();
608 return QFont();
609 else
609 else
610 return d_ptr->m_labelsFont;
610 return d_ptr->m_labelsFont;
611 }
611 }
612
612
613 void QAbstractAxis::setLabelsAngle(int angle)
613 void QAbstractAxis::setLabelsAngle(int angle)
614 {
614 {
615 if (d_ptr->m_labelsAngle != angle) {
615 if (d_ptr->m_labelsAngle != angle) {
616 d_ptr->m_labelsAngle = angle;
616 d_ptr->m_labelsAngle = angle;
617 emit labelsAngleChanged(angle);
617 emit labelsAngleChanged(angle);
618 }
618 }
619 }
619 }
620
620
621 int QAbstractAxis::labelsAngle() const
621 int QAbstractAxis::labelsAngle() const
622 {
622 {
623 return d_ptr->m_labelsAngle;
623 return d_ptr->m_labelsAngle;
624 }
624 }
625 //TODO: remove me 2.0
625 //TODO: remove me 2.0
626 void QAbstractAxis::setLabelsColor(QColor color)
626 void QAbstractAxis::setLabelsColor(QColor color)
627 {
627 {
628 QBrush b = d_ptr->m_labelsBrush;
628 QBrush b = d_ptr->m_labelsBrush;
629 if (b.color() != color) {
629 if (b.color() != color) {
630 b.setColor(color);
630 b.setColor(color);
631 setLabelsBrush(b);
631 setLabelsBrush(b);
632 emit labelsColorChanged(color);
632 emit labelsColorChanged(color);
633 }
633 }
634 }
634 }
635
635
636 QColor QAbstractAxis::labelsColor() const
636 QColor QAbstractAxis::labelsColor() const
637 {
637 {
638 return labelsBrush().color();
638 return labelsBrush().color();
639 }
639 }
640
640
641 void QAbstractAxis::setTitleVisible(bool visible)
641 void QAbstractAxis::setTitleVisible(bool visible)
642 {
642 {
643 if (d_ptr->m_titleVisible != visible) {
643 if (d_ptr->m_titleVisible != visible) {
644 d_ptr->m_titleVisible = visible;
644 d_ptr->m_titleVisible = visible;
645 emit titleVisibleChanged(visible);
645 emit titleVisibleChanged(visible);
646 }
646 }
647 }
647 }
648
648
649 bool QAbstractAxis::isTitleVisible() const
649 bool QAbstractAxis::isTitleVisible() const
650 {
650 {
651 return d_ptr->m_titleVisible;
651 return d_ptr->m_titleVisible;
652 }
652 }
653
653
654 /*!
654 /*!
655 Sets \a pen used to draw title.
655 Sets \a pen used to draw title.
656 */
656 */
657 void QAbstractAxis::setTitlePen(const QPen &pen)
657 void QAbstractAxis::setTitlePen(const QPen &pen)
658 {
658 {
659 if (d_ptr->m_titlePen != pen) {
659 if (d_ptr->m_titlePen != pen) {
660 d_ptr->m_titlePen = pen;
660 d_ptr->m_titlePen = pen;
661 emit titlePenChanged(pen);
661 emit titlePenChanged(pen);
662 }
662 }
663 }
663 }
664
664
665 /*!
665 /*!
666 Returns the pen used to title.
666 Returns the pen used to title.
667 */
667 */
668 QPen QAbstractAxis::titlePen() const
668 QPen QAbstractAxis::titlePen() const
669 {
669 {
670 if (d_ptr->m_titlePen == QChartPrivate::defaultPen())
670 if (d_ptr->m_titlePen == QChartPrivate::defaultPen())
671 return QPen();
671 return QPen();
672 else
672 else
673 return d_ptr->m_titlePen;
673 return d_ptr->m_titlePen;
674 }
674 }
675
675
676 /*!
676 /*!
677 Sets \a brush used to draw title.
677 Sets \a brush used to draw title.
678 */
678 */
679 void QAbstractAxis::setTitleBrush(const QBrush &brush)
679 void QAbstractAxis::setTitleBrush(const QBrush &brush)
680 {
680 {
681 if (d_ptr->m_titleBrush != brush) {
681 if (d_ptr->m_titleBrush != brush) {
682 d_ptr->m_titleBrush = brush;
682 d_ptr->m_titleBrush = brush;
683 emit titleBrushChanged(brush);
683 emit titleBrushChanged(brush);
684 }
684 }
685 }
685 }
686
686
687 /*!
687 /*!
688 Returns brush used to draw title.
688 Returns brush used to draw title.
689 */
689 */
690 QBrush QAbstractAxis::titleBrush() const
690 QBrush QAbstractAxis::titleBrush() const
691 {
691 {
692 if (d_ptr->m_titleBrush == QChartPrivate::defaultBrush())
692 if (d_ptr->m_titleBrush == QChartPrivate::defaultBrush())
693 return QBrush();
693 return QBrush();
694 else
694 else
695 return d_ptr->m_titleBrush;
695 return d_ptr->m_titleBrush;
696 }
696 }
697
697
698 /*!
698 /*!
699 Sets \a font used to draw title.
699 Sets \a font used to draw title.
700 */
700 */
701 void QAbstractAxis::setTitleFont(const QFont &font)
701 void QAbstractAxis::setTitleFont(const QFont &font)
702 {
702 {
703 if (d_ptr->m_titleFont != font) {
703 if (d_ptr->m_titleFont != font) {
704 d_ptr->m_titleFont = font;
704 d_ptr->m_titleFont = font;
705 emit titleFontChanged(font);
705 emit titleFontChanged(font);
706 }
706 }
707 }
707 }
708
708
709 /*!
709 /*!
710 Returns font used to draw title.
710 Returns font used to draw title.
711 */
711 */
712 QFont QAbstractAxis::titleFont() const
712 QFont QAbstractAxis::titleFont() const
713 {
713 {
714 if (d_ptr->m_titleFont == QChartPrivate::defaultFont())
714 if (d_ptr->m_titleFont == QChartPrivate::defaultFont())
715 return QFont();
715 return QFont();
716 else
716 else
717 return d_ptr->m_titleFont;
717 return d_ptr->m_titleFont;
718 }
718 }
719
719
720 void QAbstractAxis::setTitleText(const QString &title)
720 void QAbstractAxis::setTitleText(const QString &title)
721 {
721 {
722 if (d_ptr->m_title != title) {
722 if (d_ptr->m_title != title) {
723 d_ptr->m_title = title;
723 d_ptr->m_title = title;
724 emit titleTextChanged(title);
724 emit titleTextChanged(title);
725 }
725 }
726 }
726 }
727
727
728 QString QAbstractAxis::titleText() const
728 QString QAbstractAxis::titleText() const
729 {
729 {
730 return d_ptr->m_title;
730 return d_ptr->m_title;
731 }
731 }
732
732
733
733
734 void QAbstractAxis::setShadesVisible(bool visible)
734 void QAbstractAxis::setShadesVisible(bool visible)
735 {
735 {
736 if (d_ptr->m_shadesVisible != visible) {
736 if (d_ptr->m_shadesVisible != visible) {
737 d_ptr->m_shadesVisible = visible;
737 d_ptr->m_shadesVisible = visible;
738 emit shadesVisibleChanged(visible);
738 emit shadesVisibleChanged(visible);
739 }
739 }
740 }
740 }
741
741
742 bool QAbstractAxis::shadesVisible() const
742 bool QAbstractAxis::shadesVisible() const
743 {
743 {
744 return d_ptr->m_shadesVisible;
744 return d_ptr->m_shadesVisible;
745 }
745 }
746
746
747 /*!
747 /*!
748 Sets \a pen used to draw shades.
748 Sets \a pen used to draw shades.
749 */
749 */
750 void QAbstractAxis::setShadesPen(const QPen &pen)
750 void QAbstractAxis::setShadesPen(const QPen &pen)
751 {
751 {
752 if (d_ptr->m_shadesPen != pen) {
752 if (d_ptr->m_shadesPen != pen) {
753 d_ptr->m_shadesPen = pen;
753 d_ptr->m_shadesPen = pen;
754 emit shadesPenChanged(pen);
754 emit shadesPenChanged(pen);
755 }
755 }
756 }
756 }
757
757
758 /*!
758 /*!
759 Returns pen used to draw shades.
759 Returns pen used to draw shades.
760 */
760 */
761 QPen QAbstractAxis::shadesPen() const
761 QPen QAbstractAxis::shadesPen() const
762 {
762 {
763 if (d_ptr->m_shadesPen == QChartPrivate::defaultPen())
763 if (d_ptr->m_shadesPen == QChartPrivate::defaultPen())
764 return QPen();
764 return QPen();
765 else
765 else
766 return d_ptr->m_shadesPen;
766 return d_ptr->m_shadesPen;
767 }
767 }
768
768
769 /*!
769 /*!
770 Sets \a brush used to draw shades.
770 Sets \a brush used to draw shades.
771 */
771 */
772 void QAbstractAxis::setShadesBrush(const QBrush &brush)
772 void QAbstractAxis::setShadesBrush(const QBrush &brush)
773 {
773 {
774 if (d_ptr->m_shadesBrush != brush) {
774 if (d_ptr->m_shadesBrush != brush) {
775 d_ptr->m_shadesBrush = brush;
775 d_ptr->m_shadesBrush = brush;
776 emit shadesBrushChanged(brush);
776 emit shadesBrushChanged(brush);
777 }
777 }
778 }
778 }
779
779
780 /*!
780 /*!
781 Returns brush used to draw shades.
781 Returns brush used to draw shades.
782 */
782 */
783 QBrush QAbstractAxis::shadesBrush() const
783 QBrush QAbstractAxis::shadesBrush() const
784 {
784 {
785 if (d_ptr->m_shadesBrush == QChartPrivate::defaultBrush())
785 if (d_ptr->m_shadesBrush == QChartPrivate::defaultBrush())
786 return QBrush(Qt::SolidPattern);
786 return QBrush(Qt::SolidPattern);
787 else
787 else
788 return d_ptr->m_shadesBrush;
788 return d_ptr->m_shadesBrush;
789 }
789 }
790
790
791 void QAbstractAxis::setShadesColor(QColor color)
791 void QAbstractAxis::setShadesColor(QColor color)
792 {
792 {
793 QBrush b = d_ptr->m_shadesBrush;
793 QBrush b = d_ptr->m_shadesBrush;
794 if (b.color() != color) {
794 if (b.color() != color) {
795 b.setColor(color);
795 b.setColor(color);
796 setShadesBrush(b);
796 setShadesBrush(b);
797 emit shadesColorChanged(color);
797 emit shadesColorChanged(color);
798 }
798 }
799 }
799 }
800
800
801 QColor QAbstractAxis::shadesColor() const
801 QColor QAbstractAxis::shadesColor() const
802 {
802 {
803 return shadesBrush().color();
803 return shadesBrush().color();
804 }
804 }
805
805
806 void QAbstractAxis::setShadesBorderColor(QColor color)
806 void QAbstractAxis::setShadesBorderColor(QColor color)
807 {
807 {
808 QPen p = d_ptr->m_shadesPen;
808 QPen p = d_ptr->m_shadesPen;
809 if (p.color() != color) {
809 if (p.color() != color) {
810 p.setColor(color);
810 p.setColor(color);
811 setShadesPen(p);
811 setShadesPen(p);
812 emit shadesColorChanged(color);
812 emit shadesColorChanged(color);
813 }
813 }
814 }
814 }
815
815
816 QColor QAbstractAxis::shadesBorderColor() const
816 QColor QAbstractAxis::shadesBorderColor() const
817 {
817 {
818 return shadesPen().color();
818 return shadesPen().color();
819 }
819 }
820
820
821
821
822 bool QAbstractAxis::isVisible() const
822 bool QAbstractAxis::isVisible() const
823 {
823 {
824 return d_ptr->m_visible;
824 return d_ptr->m_visible;
825 }
825 }
826
826
827 /*!
827 /*!
828 Sets axis, shades, labels and grid lines to be visible.
828 Sets axis, shades, labels and grid lines to be visible.
829 */
829 */
830 void QAbstractAxis::setVisible(bool visible)
830 void QAbstractAxis::setVisible(bool visible)
831 {
831 {
832 if (d_ptr->m_visible != visible) {
832 if (d_ptr->m_visible != visible) {
833 d_ptr->m_visible = visible;
833 d_ptr->m_visible = visible;
834 emit visibleChanged(visible);
834 emit visibleChanged(visible);
835 }
835 }
836 }
836 }
837
837
838
838
839 /*!
839 /*!
840 Sets axis, shades, labels and grid lines to be visible.
840 Sets axis, shades, labels and grid lines to be visible.
841 */
841 */
842 void QAbstractAxis::show()
842 void QAbstractAxis::show()
843 {
843 {
844 setVisible(true);
844 setVisible(true);
845 }
845 }
846
846
847 /*!
847 /*!
848 Sets axis, shades, labels and grid lines to not be visible.
848 Sets axis, shades, labels and grid lines to not be visible.
849 */
849 */
850 void QAbstractAxis::hide()
850 void QAbstractAxis::hide()
851 {
851 {
852 setVisible(false);
852 setVisible(false);
853 }
853 }
854
854
855 /*!
855 /*!
856 Sets the minimum value shown on the axis.
856 Sets the minimum value shown on the axis.
857 Depending on the actual axis type the \a min parameter is converted to appropriate type.
857 Depending on the actual axis type the \a min parameter is converted to appropriate type.
858 If the conversion is impossible then the function call does nothing
858 If the conversion is impossible then the function call does nothing
859 */
859 */
860 void QAbstractAxis::setMin(const QVariant &min)
860 void QAbstractAxis::setMin(const QVariant &min)
861 {
861 {
862 d_ptr->setMin(min);
862 d_ptr->setMin(min);
863 }
863 }
864
864
865 /*!
865 /*!
866 Sets the maximum value shown on the axis.
866 Sets the maximum value shown on the axis.
867 Depending on the actual axis type the \a max parameter is converted to appropriate type.
867 Depending on the actual axis type the \a max parameter is converted to appropriate type.
868 If the conversion is impossible then the function call does nothing
868 If the conversion is impossible then the function call does nothing
869 */
869 */
870 void QAbstractAxis::setMax(const QVariant &max)
870 void QAbstractAxis::setMax(const QVariant &max)
871 {
871 {
872 d_ptr->setMax(max);
872 d_ptr->setMax(max);
873 }
873 }
874
874
875 /*!
875 /*!
876 Sets the range shown on the axis.
876 Sets the range shown on the axis.
877 Depending on the actual axis type the \a min and \a max parameters are converted to appropriate types.
877 Depending on the actual axis type the \a min and \a max parameters are converted to appropriate types.
878 If the conversion is impossible then the function call does nothing.
878 If the conversion is impossible then the function call does nothing.
879 */
879 */
880 void QAbstractAxis::setRange(const QVariant &min, const QVariant &max)
880 void QAbstractAxis::setRange(const QVariant &min, const QVariant &max)
881 {
881 {
882 d_ptr->setRange(min, max);
882 d_ptr->setRange(min, max);
883 }
883 }
884
884
885
885
886 /*!
886 /*!
887 Returns the orientation in which the axis is being used (Vertical or Horizontal)
887 Returns the orientation in which the axis is being used (Vertical or Horizontal)
888 */
888 */
889 // NOTE: should have const but it breaks BC:
889 // NOTE: should have const but it breaks BC:
890 // http://techbase.kde.org/Policies/Binary_Compatibility_Examples#Change_the_CV-qualifiers_of_a_member_function
890 // http://techbase.kde.org/Policies/Binary_Compatibility_Examples#Change_the_CV-qualifiers_of_a_member_function
891 Qt::Orientation QAbstractAxis::orientation()
891 Qt::Orientation QAbstractAxis::orientation()
892 {
892 {
893 return d_ptr->orientation();
893 return d_ptr->orientation();
894 }
894 }
895
895
896 Qt::Alignment QAbstractAxis::alignment() const
896 Qt::Alignment QAbstractAxis::alignment() const
897 {
897 {
898 return d_ptr->alignment();
898 return d_ptr->alignment();
899 }
899 }
900
900
901 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
901 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
902
902
903 QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis *q)
903 QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis *q)
904 : q_ptr(q),
904 : q_ptr(q),
905 m_chart(0),
905 m_chart(0),
906 m_alignment(0),
906 m_alignment(0),
907 m_orientation(Qt::Orientation(0)),
907 m_orientation(Qt::Orientation(0)),
908 m_visible(true),
908 m_visible(true),
909 m_arrowVisible(true),
909 m_arrowVisible(true),
910 m_axisPen(QChartPrivate::defaultPen()),
910 m_axisPen(QChartPrivate::defaultPen()),
911 m_axisBrush(QChartPrivate::defaultBrush()),
911 m_axisBrush(QChartPrivate::defaultBrush()),
912 m_gridLineVisible(true),
912 m_gridLineVisible(true),
913 m_gridLinePen(QChartPrivate::defaultPen()),
913 m_gridLinePen(QChartPrivate::defaultPen()),
914 m_labelsVisible(true),
914 m_labelsVisible(true),
915 m_labelsPen(QChartPrivate::defaultPen()),
915 m_labelsPen(QChartPrivate::defaultPen()),
916 m_labelsBrush(QChartPrivate::defaultBrush()),
916 m_labelsBrush(QChartPrivate::defaultBrush()),
917 m_labelsFont(QChartPrivate::defaultFont()),
917 m_labelsFont(QChartPrivate::defaultFont()),
918 m_labelsAngle(0),
918 m_labelsAngle(0),
919 m_titleVisible(true),
919 m_titleVisible(true),
920 m_titlePen(QChartPrivate::defaultPen()),
920 m_titlePen(QChartPrivate::defaultPen()),
921 m_titleBrush(QChartPrivate::defaultBrush()),
921 m_titleBrush(QChartPrivate::defaultBrush()),
922 m_titleFont(QChartPrivate::defaultFont()),
922 m_titleFont(QChartPrivate::defaultFont()),
923 m_shadesVisible(false),
923 m_shadesVisible(false),
924 m_shadesBrush(QChartPrivate::defaultBrush()),
924 m_shadesBrush(QChartPrivate::defaultBrush()),
925 m_shadesPen(QChartPrivate::defaultPen()),
925 m_shadesPen(QChartPrivate::defaultPen()),
926 m_shadesOpacity(1.0),
926 m_shadesOpacity(1.0),
927 m_dirty(false)
927 m_dirty(false)
928 {
928 {
929 }
929 }
930
930
931 QAbstractAxisPrivate::~QAbstractAxisPrivate()
931 QAbstractAxisPrivate::~QAbstractAxisPrivate()
932 {
932 {
933 }
933 }
934
934
935 void QAbstractAxisPrivate::setAlignment( Qt::Alignment alignment)
935 void QAbstractAxisPrivate::setAlignment( Qt::Alignment alignment)
936 {
936 {
937 switch(alignment) {
937 switch(alignment) {
938 case Qt::AlignTop:
938 case Qt::AlignTop:
939 case Qt::AlignBottom:
939 case Qt::AlignBottom:
940 m_orientation = Qt::Horizontal;
940 m_orientation = Qt::Horizontal;
941 break;
941 break;
942 case Qt::AlignLeft:
942 case Qt::AlignLeft:
943 case Qt::AlignRight:
943 case Qt::AlignRight:
944 m_orientation = Qt::Vertical;
944 m_orientation = Qt::Vertical;
945 break;
945 break;
946 default:
946 default:
947 qWarning()<<"No alignment specified !";
947 qWarning()<<"No alignment specified !";
948 break;
948 break;
949 };
949 };
950 m_alignment=alignment;
950 m_alignment=alignment;
951 }
951 }
952
952
953 void QAbstractAxisPrivate::initializeTheme(ChartTheme* theme, bool forced)
953 void QAbstractAxisPrivate::initializeTheme(ChartTheme* theme, bool forced)
954 {
954 {
955 //TODO: introduce axis brush
955 //TODO: introduce axis brush
956 if (forced || QChartPrivate::defaultPen() == m_axisPen)
956 if (forced || QChartPrivate::defaultPen() == m_axisPen)
957 q_ptr->setLinePen(theme->axisLinePen());
957 q_ptr->setLinePen(theme->axisLinePen());
958
958
959 if (forced || QChartPrivate::defaultPen() == m_gridLinePen)
959 if (forced || QChartPrivate::defaultPen() == m_gridLinePen)
960 q_ptr->setGridLinePen(theme->girdLinePen());
960 q_ptr->setGridLinePen(theme->girdLinePen());
961
961
962 if (forced || QChartPrivate::defaultBrush() == m_labelsBrush)
962 if (forced || QChartPrivate::defaultBrush() == m_labelsBrush)
963 q_ptr->setLabelsBrush(theme->labelBrush());
963 q_ptr->setLabelsBrush(theme->labelBrush());
964 if (forced || QChartPrivate::defaultPen() == m_labelsPen)
964 if (forced || QChartPrivate::defaultPen() == m_labelsPen)
965 q_ptr->setLabelsPen(Qt::NoPen); // NoPen for performance reasons
965 q_ptr->setLabelsPen(Qt::NoPen); // NoPen for performance reasons
966 if (forced || QChartPrivate::defaultFont() == m_labelsFont)
966 if (forced || QChartPrivate::defaultFont() == m_labelsFont)
967 q_ptr->setLabelsFont(theme->labelFont());
967 q_ptr->setLabelsFont(theme->labelFont());
968
968
969 if (forced || QChartPrivate::defaultBrush() == m_titleBrush)
969 if (forced || QChartPrivate::defaultBrush() == m_titleBrush)
970 q_ptr->setTitleBrush(theme->labelBrush());
970 q_ptr->setTitleBrush(theme->labelBrush());
971 if (forced || QChartPrivate::defaultPen() == m_titlePen)
971 if (forced || QChartPrivate::defaultPen() == m_titlePen)
972 q_ptr->setTitlePen(Qt::NoPen); // NoPen for performance reasons
972 q_ptr->setTitlePen(Qt::NoPen); // NoPen for performance reasons
973 if (forced || QChartPrivate::defaultFont() == m_titleFont) {
973 if (forced || QChartPrivate::defaultFont() == m_titleFont) {
974 QFont font(m_labelsFont);
974 QFont font(m_labelsFont);
975 font.setBold(true);
975 font.setBold(true);
976 q_ptr->setTitleFont(font);
976 q_ptr->setTitleFont(font);
977 }
977 }
978
978
979 if (forced || QChartPrivate::defaultBrush() == m_shadesBrush)
979 if (forced || QChartPrivate::defaultBrush() == m_shadesBrush)
980 q_ptr->setShadesBrush(theme->backgroundShadesBrush());
980 q_ptr->setShadesBrush(theme->backgroundShadesBrush());
981 if (forced || QChartPrivate::defaultPen() == m_shadesPen)
981 if (forced || QChartPrivate::defaultPen() == m_shadesPen)
982 q_ptr->setShadesPen(theme->backgroundShadesPen());
982 q_ptr->setShadesPen(theme->backgroundShadesPen());
983
983
984 bool axisX = m_orientation == Qt::Horizontal;
984 bool axisX = m_orientation == Qt::Horizontal;
985 if (forced && (theme->backgroundShades() == ChartTheme::BackgroundShadesBoth
985 if (forced && (theme->backgroundShades() == ChartTheme::BackgroundShadesBoth
986 || (theme->backgroundShades() == ChartTheme::BackgroundShadesVertical && axisX)
986 || (theme->backgroundShades() == ChartTheme::BackgroundShadesVertical && axisX)
987 || (theme->backgroundShades() == ChartTheme::BackgroundShadesHorizontal && !axisX))) {
987 || (theme->backgroundShades() == ChartTheme::BackgroundShadesHorizontal && !axisX))) {
988 q_ptr->setShadesVisible(true);
988 q_ptr->setShadesVisible(true);
989 } else if (forced) {
989 } else if (forced) {
990 q_ptr->setShadesVisible(false);
990 q_ptr->setShadesVisible(false);
991 }
991 }
992 }
992 }
993
993
994 void QAbstractAxisPrivate::handleRangeChanged(qreal min, qreal max)
994 void QAbstractAxisPrivate::handleRangeChanged(qreal min, qreal max)
995 {
995 {
996 setRange(min,max);
996 setRange(min,max);
997 }
997 }
998
998
999 void QAbstractAxisPrivate::initializeGraphics(QGraphicsItem* parent)
999 void QAbstractAxisPrivate::initializeGraphics(QGraphicsItem* parent)
1000 {
1000 {
1001 Q_UNUSED(parent);
1001 Q_UNUSED(parent);
1002 }
1002 }
1003
1003
1004 void QAbstractAxisPrivate::initializeAnimations(QChart::AnimationOptions options)
1004 void QAbstractAxisPrivate::initializeAnimations(QChart::AnimationOptions options)
1005 {
1005 {
1006 ChartAxisElement *axis = m_item.data();
1006 ChartAxisElement *axis = m_item.data();
1007 Q_ASSERT(axis);
1007 Q_ASSERT(axis);
1008 if (options.testFlag(QChart::GridAxisAnimations)) {
1008 if (options.testFlag(QChart::GridAxisAnimations)) {
1009 axis->setAnimation(new AxisAnimation(axis));
1009 axis->setAnimation(new AxisAnimation(axis));
1010 } else {
1010 } else {
1011 axis->setAnimation(0);
1011 axis->setAnimation(0);
1012 }
1012 }
1013 }
1013 }
1014
1014
1015
1015
1016
1016
1017 #include "moc_qabstractaxis.cpp"
1017 #include "moc_qabstractaxis.cpp"
1018 #include "moc_qabstractaxis_p.cpp"
1018 #include "moc_qabstractaxis_p.cpp"
1019
1019
1020 QTCOMMERCIALCHART_END_NAMESPACE
1020 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,120 +1,120
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qhorizontalbarseries.h"
21 #include "qhorizontalbarseries.h"
22 #include "qhorizontalbarseries_p.h"
22 #include "qhorizontalbarseries_p.h"
23 #include "horizontalbarchartitem_p.h"
23 #include "horizontalbarchartitem_p.h"
24 #include "qbarcategoryaxis.h"
24 #include "qbarcategoryaxis.h"
25
25
26 #include "chartdataset_p.h"
26 #include "chartdataset_p.h"
27 #include "charttheme_p.h"
27 #include "charttheme_p.h"
28
28
29
29
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31
31
32 /*!
32 /*!
33 \class QHorizontalBarSeries
33 \class QHorizontalBarSeries
34 \brief Series for creating horizontal bar chart
34 \brief Series for creating horizontal bar chart.
35 \mainclass
35 \mainclass
36
36
37 QHorizontalBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars
37 QHorizontalBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars
38 as groups, where bars in same category are grouped next to each other. QHorizontalBarSeries groups the data
38 as groups, where bars in same category are grouped next to each other. QHorizontalBarSeries groups the data
39 from sets to categories, which are defined by a QStringList.
39 from sets to categories, which are defined by a QStringList.
40
40
41 See the \l {HorizontalBarChart Example} {horizontal bar chart example} to learn how to create a horizontal bar chart.
41 See the \l {HorizontalBarChart Example} {horizontal bar chart example} to learn how to create a horizontal bar chart.
42 \image examples_horizontalbarchart.png
42 \image examples_horizontalbarchart.png
43
43
44 \sa QBarSet, QBarSeries, QPercentBarSeries, QAbstractBarSeries, QStackedBarSeries, QHorizontalStackedBarSeries, QHorizontalPercentBarSeries
44 \sa QBarSet, QBarSeries, QPercentBarSeries, QAbstractBarSeries, QStackedBarSeries, QHorizontalStackedBarSeries, QHorizontalPercentBarSeries
45 */
45 */
46 /*!
46 /*!
47 \qmlclass HorizontalBarSeries QHorizontalBarSeries
47 \qmlclass HorizontalBarSeries QHorizontalBarSeries
48 \inherits AbstractBarSeries
48 \inherits AbstractBarSeries
49
49
50 The following QML shows how to create a simple horizontal bar chart:
50 The following QML shows how to create a simple horizontal bar chart:
51 \snippet ../demos/qmlchart/qml/qmlchart/View9.qml 1
51 \snippet ../demos/qmlchart/qml/qmlchart/View9.qml 1
52 \beginfloatleft
52 \beginfloatleft
53 \image demos_qmlchart9.png
53 \image demos_qmlchart9.png
54 \endfloat
54 \endfloat
55 \clearfloat
55 \clearfloat
56 */
56 */
57
57
58 /*!
58 /*!
59 Constructs empty QHorizontalBarSeries.
59 Constructs empty QHorizontalBarSeries.
60 QHorizontalBarSeries is QObject which is a child of a \a parent.
60 QHorizontalBarSeries is QObject which is a child of a \a parent.
61 */
61 */
62 QHorizontalBarSeries::QHorizontalBarSeries(QObject *parent)
62 QHorizontalBarSeries::QHorizontalBarSeries(QObject *parent)
63 : QAbstractBarSeries(*new QHorizontalBarSeriesPrivate(this), parent)
63 : QAbstractBarSeries(*new QHorizontalBarSeriesPrivate(this), parent)
64 {
64 {
65 }
65 }
66
66
67 /*!
67 /*!
68 Destructor.
68 Destructor.
69 Removes series from chart.
69 Removes series from chart.
70 */
70 */
71 QHorizontalBarSeries::~QHorizontalBarSeries()
71 QHorizontalBarSeries::~QHorizontalBarSeries()
72 {
72 {
73 Q_D(QHorizontalBarSeries);
73 Q_D(QHorizontalBarSeries);
74 if (d->m_chart)
74 if (d->m_chart)
75 d->m_chart->removeSeries(this);
75 d->m_chart->removeSeries(this);
76 }
76 }
77
77
78 /*!
78 /*!
79 Returns QChartSeries::SeriesTypeHorizontalBar.
79 Returns QChartSeries::SeriesTypeHorizontalBar.
80 */
80 */
81 QAbstractSeries::SeriesType QHorizontalBarSeries::type() const
81 QAbstractSeries::SeriesType QHorizontalBarSeries::type() const
82 {
82 {
83 return QAbstractSeries::SeriesTypeHorizontalBar;
83 return QAbstractSeries::SeriesTypeHorizontalBar;
84 }
84 }
85
85
86 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
86 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
87
87
88 QHorizontalBarSeriesPrivate::QHorizontalBarSeriesPrivate(QHorizontalBarSeries *q)
88 QHorizontalBarSeriesPrivate::QHorizontalBarSeriesPrivate(QHorizontalBarSeries *q)
89 : QAbstractBarSeriesPrivate(q)
89 : QAbstractBarSeriesPrivate(q)
90 {
90 {
91
91
92 }
92 }
93
93
94 void QHorizontalBarSeriesPrivate::initializeDomain()
94 void QHorizontalBarSeriesPrivate::initializeDomain()
95 {
95 {
96 qreal minX(domain()->minX());
96 qreal minX(domain()->minX());
97 qreal minY(domain()->minY());
97 qreal minY(domain()->minY());
98 qreal maxX(domain()->maxX());
98 qreal maxX(domain()->maxX());
99 qreal maxY(domain()->maxY());
99 qreal maxY(domain()->maxY());
100
100
101 qreal y = categoryCount();
101 qreal y = categoryCount();
102 minX = qMin(minX, min());
102 minX = qMin(minX, min());
103 minY = qMin(minY, - (qreal)0.5);
103 minY = qMin(minY, - (qreal)0.5);
104 maxX = qMax(maxX, max());
104 maxX = qMax(maxX, max());
105 maxY = qMax(maxY, y - (qreal)0.5);
105 maxY = qMax(maxY, y - (qreal)0.5);
106
106
107 domain()->setRange(minX, maxX, minY, maxY);
107 domain()->setRange(minX, maxX, minY, maxY);
108 }
108 }
109
109
110 void QHorizontalBarSeriesPrivate::initializeGraphics(QGraphicsItem* parent)
110 void QHorizontalBarSeriesPrivate::initializeGraphics(QGraphicsItem* parent)
111 {
111 {
112 Q_Q(QHorizontalBarSeries);
112 Q_Q(QHorizontalBarSeries);
113 HorizontalBarChartItem *bar = new HorizontalBarChartItem(q,parent);
113 HorizontalBarChartItem *bar = new HorizontalBarChartItem(q,parent);
114 m_item.reset(bar);
114 m_item.reset(bar);
115 QAbstractSeriesPrivate::initializeGraphics(parent);
115 QAbstractSeriesPrivate::initializeGraphics(parent);
116 }
116 }
117
117
118 #include "moc_qhorizontalbarseries.cpp"
118 #include "moc_qhorizontalbarseries.cpp"
119
119
120 QTCOMMERCIALCHART_END_NAMESPACE
120 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,116 +1,116
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20 #include "qhorizontalpercentbarseries.h"
20 #include "qhorizontalpercentbarseries.h"
21 #include "qhorizontalpercentbarseries_p.h"
21 #include "qhorizontalpercentbarseries_p.h"
22 #include "horizontalpercentbarchartitem_p.h"
22 #include "horizontalpercentbarchartitem_p.h"
23
23
24 #include "chartdataset_p.h"
24 #include "chartdataset_p.h"
25 #include "charttheme_p.h"
25 #include "charttheme_p.h"
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
28
29 /*!
29 /*!
30 \class QHorizontalPercentBarSeries
30 \class QHorizontalPercentBarSeries
31 \brief Series for creating horizontal percent bar chart
31 \brief Series for creating horizontal percent bar chart.
32 \mainclass
32 \mainclass
33
33
34 QHorizontalPercentBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars
34 QHorizontalPercentBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars
35 as groups, where bars in same category are grouped next to each other. QHorizontalPercentBarSeries groups the data
35 as groups, where bars in same category are grouped next to each other. QHorizontalPercentBarSeries groups the data
36 from sets to categories, which are defined by a QStringList.
36 from sets to categories, which are defined by a QStringList.
37
37
38 See the \l {HorizontalPercentBarChart Example} {horizontal percent bar chart example} to learn how to create a horizontal percent bar chart.
38 See the \l {HorizontalPercentBarChart Example} {horizontal percent bar chart example} to learn how to create a horizontal percent bar chart.
39 \image examples_horizontalpercentbarchart.png
39 \image examples_horizontalpercentbarchart.png
40
40
41 \sa QBarSet, QBarSeries, QPercentBarSeries, QAbstractBarSeries, QStackedBarSeries, QHorizontalStackedBarSeries, QHorizontalBarSeries
41 \sa QBarSet, QBarSeries, QPercentBarSeries, QAbstractBarSeries, QStackedBarSeries, QHorizontalStackedBarSeries, QHorizontalBarSeries
42 */
42 */
43 /*!
43 /*!
44 \qmlclass HorizontalPercentBarSeries QHorizontalPercentBarSeries
44 \qmlclass HorizontalPercentBarSeries QHorizontalPercentBarSeries
45 \inherits QAbstractBarSeries
45 \inherits QAbstractBarSeries
46
46
47 The following QML shows how to create a simple horizontal percent bar chart:
47 The following QML shows how to create a simple horizontal percent bar chart:
48 \snippet ../demos/qmlchart/qml/qmlchart/View11.qml 1
48 \snippet ../demos/qmlchart/qml/qmlchart/View11.qml 1
49 \beginfloatleft
49 \beginfloatleft
50 \image demos_qmlchart11.png
50 \image demos_qmlchart11.png
51 \endfloat
51 \endfloat
52 \clearfloat
52 \clearfloat
53 */
53 */
54
54
55 /*!
55 /*!
56 Constructs empty QHorizontalPercentBarSeries.
56 Constructs empty QHorizontalPercentBarSeries.
57 QHorizontalPercentBarSeries is QObject which is a child of a \a parent.
57 QHorizontalPercentBarSeries is QObject which is a child of a \a parent.
58 */
58 */
59 QHorizontalPercentBarSeries::QHorizontalPercentBarSeries(QObject *parent) :
59 QHorizontalPercentBarSeries::QHorizontalPercentBarSeries(QObject *parent) :
60 QAbstractBarSeries(*new QHorizontalPercentBarSeriesPrivate(this), parent)
60 QAbstractBarSeries(*new QHorizontalPercentBarSeriesPrivate(this), parent)
61 {
61 {
62 }
62 }
63
63
64 /*!
64 /*!
65 Returns QChartSeries::SeriesTypeHorizontalPercentBar.
65 Returns QAbstractSeries::SeriesTypeHorizontalPercentBar.
66 */
66 */
67 QAbstractSeries::SeriesType QHorizontalPercentBarSeries::type() const
67 QAbstractSeries::SeriesType QHorizontalPercentBarSeries::type() const
68 {
68 {
69 return QAbstractSeries::SeriesTypeHorizontalPercentBar;
69 return QAbstractSeries::SeriesTypeHorizontalPercentBar;
70 }
70 }
71
71
72 /*!
72 /*!
73 Destructor.
73 Destructor.
74 Removes series from chart.
74 Removes series from chart.
75 */
75 */
76 QHorizontalPercentBarSeries::~QHorizontalPercentBarSeries()
76 QHorizontalPercentBarSeries::~QHorizontalPercentBarSeries()
77 {
77 {
78 Q_D(QHorizontalPercentBarSeries);
78 Q_D(QHorizontalPercentBarSeries);
79 if (d->m_chart)
79 if (d->m_chart)
80 d->m_chart->removeSeries(this);
80 d->m_chart->removeSeries(this);
81 }
81 }
82
82
83 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
83 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
84
84
85 QHorizontalPercentBarSeriesPrivate::QHorizontalPercentBarSeriesPrivate(QHorizontalPercentBarSeries *q) : QAbstractBarSeriesPrivate(q)
85 QHorizontalPercentBarSeriesPrivate::QHorizontalPercentBarSeriesPrivate(QHorizontalPercentBarSeries *q) : QAbstractBarSeriesPrivate(q)
86 {
86 {
87
87
88 }
88 }
89
89
90 void QHorizontalPercentBarSeriesPrivate::initializeDomain()
90 void QHorizontalPercentBarSeriesPrivate::initializeDomain()
91 {
91 {
92 qreal minX(domain()->minX());
92 qreal minX(domain()->minX());
93 qreal minY(domain()->minY());
93 qreal minY(domain()->minY());
94 qreal maxX(domain()->maxX());
94 qreal maxX(domain()->maxX());
95 qreal maxY(domain()->maxY());
95 qreal maxY(domain()->maxY());
96
96
97 qreal y = categoryCount();
97 qreal y = categoryCount();
98 minX = 0;
98 minX = 0;
99 maxX = 100;
99 maxX = 100;
100 minY = qMin(minY, - (qreal)0.5);
100 minY = qMin(minY, - (qreal)0.5);
101 maxY = qMax(maxY, y - (qreal)0.5);
101 maxY = qMax(maxY, y - (qreal)0.5);
102
102
103 domain()->setRange(minX, maxX, minY, maxY);
103 domain()->setRange(minX, maxX, minY, maxY);
104 }
104 }
105
105
106 void QHorizontalPercentBarSeriesPrivate::initializeGraphics(QGraphicsItem* parent)
106 void QHorizontalPercentBarSeriesPrivate::initializeGraphics(QGraphicsItem* parent)
107 {
107 {
108 Q_Q(QHorizontalPercentBarSeries);
108 Q_Q(QHorizontalPercentBarSeries);
109 HorizontalPercentBarChartItem *bar = new HorizontalPercentBarChartItem(q,parent);
109 HorizontalPercentBarChartItem *bar = new HorizontalPercentBarChartItem(q,parent);
110 m_item.reset(bar);
110 m_item.reset(bar);
111 QAbstractSeriesPrivate::initializeGraphics(parent);
111 QAbstractSeriesPrivate::initializeGraphics(parent);
112 }
112 }
113
113
114 #include "moc_qhorizontalpercentbarseries.cpp"
114 #include "moc_qhorizontalpercentbarseries.cpp"
115
115
116 QTCOMMERCIALCHART_END_NAMESPACE
116 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,115 +1,115
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20 #include "qhorizontalstackedbarseries.h"
20 #include "qhorizontalstackedbarseries.h"
21 #include "qhorizontalstackedbarseries_p.h"
21 #include "qhorizontalstackedbarseries_p.h"
22 #include "horizontalstackedbarchartitem_p.h"
22 #include "horizontalstackedbarchartitem_p.h"
23
23
24 #include "chartdataset_p.h"
24 #include "chartdataset_p.h"
25 #include "charttheme_p.h"
25 #include "charttheme_p.h"
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 /*!
28 /*!
29 \class QHorizontalStackedBarSeries
29 \class QHorizontalStackedBarSeries
30 \brief Series for creating horizontal stacked bar chart
30 \brief Series for creating horizontal stacked bar chart.
31 \mainclass
31 \mainclass
32
32
33 QHorizontalStackedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars
33 QHorizontalStackedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars
34 as groups, where bars in same category are grouped next to each other. QHorizontalStackedBarSeries groups the data
34 as groups, where bars in same category are grouped next to each other. QHorizontalStackedBarSeries groups the data
35 from sets to categories, which are defined by a QStringList.
35 from sets to categories, which are defined by a QStringList.
36
36
37 See the \l {HorizontalStackedBarChart Example} {horizontal stacked bar chart example} to learn how to create a horizontal stacked bar chart.
37 See the \l {HorizontalStackedBarChart Example} {horizontal stacked bar chart example} to learn how to create a horizontal stacked bar chart.
38 \image examples_horizontalstackedbarchart.png
38 \image examples_horizontalstackedbarchart.png
39
39
40 \sa QBarSet, QBarSeries, QPercentBarSeries, QAbstractBarSeries, QStackedBarSeries, QHorizontalPercentBarSeries, QHorizontalBarSeries
40 \sa QBarSet, QBarSeries, QPercentBarSeries, QAbstractBarSeries, QStackedBarSeries, QHorizontalPercentBarSeries, QHorizontalBarSeries
41 */
41 */
42 /*!
42 /*!
43 \qmlclass HorizontalStackedBarSeries QHorizontalStackedBarSeries
43 \qmlclass HorizontalStackedBarSeries QHorizontalStackedBarSeries
44 \inherits QAbstractBarSeries
44 \inherits QAbstractBarSeries
45
45
46 The following QML shows how to create a simple horizontal stacked bar chart:
46 The following QML shows how to create a simple horizontal stacked bar chart:
47 \snippet ../demos/qmlchart/qml/qmlchart/View10.qml 1
47 \snippet ../demos/qmlchart/qml/qmlchart/View10.qml 1
48 \beginfloatleft
48 \beginfloatleft
49 \image demos_qmlchart10.png
49 \image demos_qmlchart10.png
50 \endfloat
50 \endfloat
51 \clearfloat
51 \clearfloat
52 */
52 */
53
53
54 /*!
54 /*!
55 Constructs empty QHorizontalStackedBarSeries.
55 Constructs empty QHorizontalStackedBarSeries.
56 QHorizontalStackedBarSeries is QObject which is a child of a \a parent.
56 QHorizontalStackedBarSeries is QObject which is a child of a \a parent.
57 */
57 */
58 QHorizontalStackedBarSeries::QHorizontalStackedBarSeries(QObject *parent)
58 QHorizontalStackedBarSeries::QHorizontalStackedBarSeries(QObject *parent)
59 : QAbstractBarSeries(*new QHorizontalStackedBarSeriesPrivate(this), parent)
59 : QAbstractBarSeries(*new QHorizontalStackedBarSeriesPrivate(this), parent)
60 {
60 {
61 }
61 }
62
62
63 /*!
63 /*!
64 Destructor.
64 Destructor.
65 Removes series from chart.
65 Removes series from chart.
66 */
66 */
67 QHorizontalStackedBarSeries::~QHorizontalStackedBarSeries()
67 QHorizontalStackedBarSeries::~QHorizontalStackedBarSeries()
68 {
68 {
69 Q_D(QHorizontalStackedBarSeries);
69 Q_D(QHorizontalStackedBarSeries);
70 if (d->m_chart)
70 if (d->m_chart)
71 d->m_chart->removeSeries(this);
71 d->m_chart->removeSeries(this);
72 }
72 }
73
73
74 /*!
74 /*!
75 Returns QChartSeries::SeriesTypeHorizontalStackedBar.
75 Returns QAbstractSeries::SeriesTypeHorizontalStackedBar.
76 */
76 */
77 QAbstractSeries::SeriesType QHorizontalStackedBarSeries::type() const
77 QAbstractSeries::SeriesType QHorizontalStackedBarSeries::type() const
78 {
78 {
79 return QAbstractSeries::SeriesTypeHorizontalStackedBar;
79 return QAbstractSeries::SeriesTypeHorizontalStackedBar;
80 }
80 }
81
81
82 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
82 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
83
83
84 QHorizontalStackedBarSeriesPrivate::QHorizontalStackedBarSeriesPrivate(QHorizontalStackedBarSeries *q) : QAbstractBarSeriesPrivate(q)
84 QHorizontalStackedBarSeriesPrivate::QHorizontalStackedBarSeriesPrivate(QHorizontalStackedBarSeries *q) : QAbstractBarSeriesPrivate(q)
85 {
85 {
86
86
87 }
87 }
88
88
89 void QHorizontalStackedBarSeriesPrivate::initializeDomain()
89 void QHorizontalStackedBarSeriesPrivate::initializeDomain()
90 {
90 {
91 qreal minX(domain()->minX());
91 qreal minX(domain()->minX());
92 qreal minY(domain()->minY());
92 qreal minY(domain()->minY());
93 qreal maxX(domain()->maxX());
93 qreal maxX(domain()->maxX());
94 qreal maxY(domain()->maxY());
94 qreal maxY(domain()->maxY());
95
95
96 qreal y = categoryCount();
96 qreal y = categoryCount();
97 minX = qMin(minX, bottom());
97 minX = qMin(minX, bottom());
98 minY = qMin(minY, - (qreal)0.5);
98 minY = qMin(minY, - (qreal)0.5);
99 maxX = qMax(maxX, top());
99 maxX = qMax(maxX, top());
100 maxY = qMax(maxY, y - (qreal)0.5);
100 maxY = qMax(maxY, y - (qreal)0.5);
101
101
102 domain()->setRange(minX, maxX, minY, maxY);
102 domain()->setRange(minX, maxX, minY, maxY);
103 }
103 }
104
104
105 void QHorizontalStackedBarSeriesPrivate::initializeGraphics(QGraphicsItem *parent)
105 void QHorizontalStackedBarSeriesPrivate::initializeGraphics(QGraphicsItem *parent)
106 {
106 {
107 Q_Q(QHorizontalStackedBarSeries);
107 Q_Q(QHorizontalStackedBarSeries);
108 HorizontalStackedBarChartItem *bar = new HorizontalStackedBarChartItem(q,parent);
108 HorizontalStackedBarChartItem *bar = new HorizontalStackedBarChartItem(q,parent);
109 m_item.reset(bar);
109 m_item.reset(bar);
110 QAbstractSeriesPrivate::initializeGraphics(parent);
110 QAbstractSeriesPrivate::initializeGraphics(parent);
111 }
111 }
112
112
113 #include "moc_qhorizontalstackedbarseries.cpp"
113 #include "moc_qhorizontalstackedbarseries.cpp"
114
114
115 QTCOMMERCIALCHART_END_NAMESPACE
115 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,899 +1,899
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qabstractbarseries.h"
21 #include "qabstractbarseries.h"
22 #include "qabstractbarseries_p.h"
22 #include "qabstractbarseries_p.h"
23 #include "qbarset.h"
23 #include "qbarset.h"
24 #include "qbarset_p.h"
24 #include "qbarset_p.h"
25 #include "abstractdomain_p.h"
25 #include "abstractdomain_p.h"
26 #include "chartdataset_p.h"
26 #include "chartdataset_p.h"
27 #include "charttheme_p.h"
27 #include "charttheme_p.h"
28 #include "qvalueaxis.h"
28 #include "qvalueaxis.h"
29 #include "qbarcategoryaxis.h"
29 #include "qbarcategoryaxis.h"
30 #include "qbarlegendmarker.h"
30 #include "qbarlegendmarker.h"
31 #include "baranimation_p.h"
31 #include "baranimation_p.h"
32 #include "abstractbarchartitem_p.h"
32 #include "abstractbarchartitem_p.h"
33 #include "qchart_p.h"
33 #include "qchart_p.h"
34
34
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36
36
37 /*!
37 /*!
38 \class QAbstractBarSeries
38 \class QAbstractBarSeries
39 \brief Series for creating a bar chart
39 \brief Series for creating a bar chart.
40 \mainclass
40 \mainclass
41
41
42 QAbstractBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to
42 QAbstractBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to
43 the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar
43 the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar
44 and y-value is the height of the bar. The category names are ignored with this series and x-axis
44 and y-value is the height of the bar. The category names are ignored with this series and x-axis
45 shows the x-values.
45 shows the x-values.
46
46
47 See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart.
47 See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart.
48 \image examples_barchart.png
48 \image examples_barchart.png
49
49
50 \sa QBarSet, QStackedBarSeries, QPercentBarSeries
50 \sa QBarSet, QStackedBarSeries, QPercentBarSeries
51 */
51 */
52 /*!
52 /*!
53 \qmlclass AbstractBarSeries QAbstractBarSeries
53 \qmlclass AbstractBarSeries QAbstractBarSeries
54 \inherits QAbstractSeries
54 \inherits QAbstractSeries
55
55
56 The following QML shows how to create a simple bar chart:
56 The following QML shows how to create a simple bar chart:
57 \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1
57 \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1
58
58
59 \beginfloatleft
59 \beginfloatleft
60 \image demos_qmlchart6.png
60 \image demos_qmlchart6.png
61 \endfloat
61 \endfloat
62 \clearfloat
62 \clearfloat
63 */
63 */
64
64
65 /*!
65 /*!
66 \qmlproperty AbstractAxis AbstractBarSeries::axisX
66 \qmlproperty AbstractAxis AbstractBarSeries::axisX
67 The x axis used for the series. If you leave both axisX and axisXTop undefined, a BarCategoriesAxis is created for
67 The x axis used for the series. If you leave both axisX and axisXTop undefined, a BarCategoriesAxis is created for
68 the series.
68 the series.
69 \sa axisXTop
69 \sa axisXTop
70 */
70 */
71
71
72 /*!
72 /*!
73 \qmlproperty AbstractAxis AbstractBarSeries::axisY
73 \qmlproperty AbstractAxis AbstractBarSeries::axisY
74 The y axis used for the series. If you leave both axisY and axisYRight undefined, a ValueAxis is created for
74 The y axis used for the series. If you leave both axisY and axisYRight undefined, a ValueAxis is created for
75 the series.
75 the series.
76 \sa axisYRight
76 \sa axisYRight
77 */
77 */
78
78
79 /*!
79 /*!
80 \qmlproperty AbstractAxis AbstractBarSeries::axisXTop
80 \qmlproperty AbstractAxis AbstractBarSeries::axisXTop
81 The x axis used for the series, drawn on top of the chart view. Note that you can only provide either axisX or
81 The x axis used for the series, drawn on top of the chart view. Note that you can only provide either axisX or
82 axisXTop, but not both.
82 axisXTop, but not both.
83 \sa axisX
83 \sa axisX
84 */
84 */
85
85
86 /*!
86 /*!
87 \qmlproperty AbstractAxis AbstractBarSeries::axisYRight
87 \qmlproperty AbstractAxis AbstractBarSeries::axisYRight
88 The y axis used for the series, drawn to the right on the chart view. Note that you can only provide either axisY
88 The y axis used for the series, drawn to the right on the chart view. Note that you can only provide either axisY
89 or axisYRight, but not both.
89 or axisYRight, but not both.
90 \sa axisY
90 \sa axisY
91 */
91 */
92
92
93 /*!
93 /*!
94 \property QAbstractBarSeries::barWidth
94 \property QAbstractBarSeries::barWidth
95 The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars
95 The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars
96 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
96 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
97 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
97 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
98 Note that with QBarSeries this value means the width of one group of bars instead of just one bar.
98 Note that with QBarSeries this value means the width of one group of bars instead of just one bar.
99 \sa QBarSeries
99 \sa QBarSeries
100 */
100 */
101 /*!
101 /*!
102 \qmlproperty real AbstractBarSeries::barWidth
102 \qmlproperty real AbstractBarSeries::barWidth
103 The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars
103 The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars
104 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
104 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
105 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
105 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
106 Note that with QBarSeries this value means the width of one group of bars instead of just one bar.
106 Note that with QBarSeries this value means the width of one group of bars instead of just one bar.
107 */
107 */
108
108
109 /*!
109 /*!
110 \property QAbstractBarSeries::count
110 \property QAbstractBarSeries::count
111 Holds the number of sets in series.
111 Holds the number of sets in series.
112 */
112 */
113 /*!
113 /*!
114 \qmlproperty int AbstractBarSeries::count
114 \qmlproperty int AbstractBarSeries::count
115 Holds the number of sets in series.
115 Holds the number of sets in series.
116 */
116 */
117
117
118 /*!
118 /*!
119 \property QAbstractBarSeries::labelsVisible
119 \property QAbstractBarSeries::labelsVisible
120 Defines the visibility of the labels in series
120 Defines the visibility of the labels in series
121 */
121 */
122 /*!
122 /*!
123 \qmlproperty bool AbstractBarSeries::labelsVisible
123 \qmlproperty bool AbstractBarSeries::labelsVisible
124 Defines the visibility of the labels in series
124 Defines the visibility of the labels in series
125 */
125 */
126
126
127 /*!
127 /*!
128 \fn void QAbstractBarSeries::clicked(int index, QBarSet *barset)
128 \fn void QAbstractBarSeries::clicked(int index, QBarSet *barset)
129 The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset.
129 The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset.
130 Clicked bar inside set is indexed by \a index
130 Clicked bar inside set is indexed by \a index
131 */
131 */
132 /*!
132 /*!
133 \qmlsignal AbstractBarSeries::onClicked(int index, BarSet barset)
133 \qmlsignal AbstractBarSeries::onClicked(int index, BarSet barset)
134 The signal is emitted if the user clicks with a mouse on top of BarSet.
134 The signal is emitted if the user clicks with a mouse on top of BarSet.
135 Clicked bar inside set is indexed by \a index
135 Clicked bar inside set is indexed by \a index
136 */
136 */
137
137
138 /*!
138 /*!
139 \fn void QAbstractBarSeries::hovered(bool status, QBarSet* barset)
139 \fn void QAbstractBarSeries::hovered(bool status, QBarSet* barset)
140
140
141 The signal is emitted if mouse is hovered on top of series.
141 The signal is emitted if mouse is hovered on top of series.
142 Parameter \a barset is the pointer of barset, where hover happened.
142 Parameter \a barset is the pointer of barset, where hover happened.
143 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
143 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
144 */
144 */
145 /*!
145 /*!
146 \qmlsignal AbstractBarSeries::onHovered(bool status, BarSet barset)
146 \qmlsignal AbstractBarSeries::onHovered(bool status, BarSet barset)
147
147
148 The signal is emitted if mouse is hovered on top of series.
148 The signal is emitted if mouse is hovered on top of series.
149 Parameter \a barset is the pointer of barset, where hover happened.
149 Parameter \a barset is the pointer of barset, where hover happened.
150 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
150 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
151 */
151 */
152
152
153 /*!
153 /*!
154 \fn void QAbstractBarSeries::countChanged()
154 \fn void QAbstractBarSeries::countChanged()
155 This signal is emitted when barset count has been changed, for example by append or remove.
155 This signal is emitted when barset count has been changed, for example by append or remove.
156 */
156 */
157 /*!
157 /*!
158 \qmlsignal AbstractBarSeries::onCountChanged()
158 \qmlsignal AbstractBarSeries::onCountChanged()
159 This signal is emitted when barset count has been changed, for example by append or remove.
159 This signal is emitted when barset count has been changed, for example by append or remove.
160 */
160 */
161
161
162 /*!
162 /*!
163 \fn void QAbstractBarSeries::labelsVisibleChanged()
163 \fn void QAbstractBarSeries::labelsVisibleChanged()
164 This signal is emitted when labels visibility have changed.
164 This signal is emitted when labels visibility have changed.
165 \sa isLabelsVisible(), setLabelsVisible()
165 \sa isLabelsVisible(), setLabelsVisible()
166 */
166 */
167
167
168 /*!
168 /*!
169 \fn void QAbstractBarSeries::barsetsAdded(QList<QBarSet*> sets)
169 \fn void QAbstractBarSeries::barsetsAdded(QList<QBarSet*> sets)
170 This signal is emitted when \a sets have been added to the series.
170 This signal is emitted when \a sets have been added to the series.
171 \sa append(), insert()
171 \sa append(), insert()
172 */
172 */
173 /*!
173 /*!
174 \qmlsignal AbstractBarSeries::onBarsetsAdded(BarSet barset)
174 \qmlsignal AbstractBarSeries::onBarsetsAdded(BarSet barset)
175 Emitted when \a barset has been added to the series.
175 Emitted when \a barset has been added to the series.
176 */
176 */
177
177
178 /*!
178 /*!
179 \fn void QAbstractBarSeries::barsetsRemoved(QList<QBarSet*> sets)
179 \fn void QAbstractBarSeries::barsetsRemoved(QList<QBarSet*> sets)
180 This signal is emitted when \a sets have been removed from the series.
180 This signal is emitted when \a sets have been removed from the series.
181 \sa remove()
181 \sa remove()
182 */
182 */
183 /*!
183 /*!
184 \qmlsignal AbstractBarSeries::onBarsetsRemoved(BarSet barset)
184 \qmlsignal AbstractBarSeries::onBarsetsRemoved(BarSet barset)
185 Emitted when \a barset has been removed from the series.
185 Emitted when \a barset has been removed from the series.
186 */
186 */
187
187
188 /*!
188 /*!
189 \qmlmethod BarSet AbstractBarSeries::at(int index)
189 \qmlmethod BarSet AbstractBarSeries::at(int index)
190 Returns bar set at \a index. Returns null if the index is not valid.
190 Returns bar set at \a index. Returns null if the index is not valid.
191 */
191 */
192
192
193 /*!
193 /*!
194 \qmlmethod BarSet AbstractBarSeries::append(string label, VariantList values)
194 \qmlmethod BarSet AbstractBarSeries::append(string label, VariantList values)
195 Adds a new bar set with \a label and \a values to \a index. Values is a list of reals.
195 Adds a new bar set with \a label and \a values to \a index. Values is a list of reals.
196 For example:
196 For example:
197 \code
197 \code
198 myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]);
198 myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]);
199 \endcode
199 \endcode
200 */
200 */
201
201
202 /*!
202 /*!
203 \qmlmethod BarSet AbstractBarSeries::insert(int index, string label, VariantList values)
203 \qmlmethod BarSet AbstractBarSeries::insert(int index, string label, VariantList values)
204 Inserts a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints.
204 Inserts a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints.
205 If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is
205 If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is
206 appended.
206 appended.
207 \sa AbstractBarSeries::append()
207 \sa AbstractBarSeries::append()
208 */
208 */
209
209
210 /*!
210 /*!
211 \qmlmethod bool AbstractBarSeries::remove(BarSet barset)
211 \qmlmethod bool AbstractBarSeries::remove(BarSet barset)
212 Removes the barset from the series. Returns true if successful, false otherwise.
212 Removes the barset from the series. Returns true if successful, false otherwise.
213 */
213 */
214
214
215 /*!
215 /*!
216 \qmlmethod AbstractBarSeries::clear()
216 \qmlmethod AbstractBarSeries::clear()
217 Removes all barsets from the series.
217 Removes all barsets from the series.
218 */
218 */
219
219
220 /*!
220 /*!
221 Destructs abstractbarseries and owned barsets.
221 Destructs abstractbarseries and owned barsets.
222 */
222 */
223 QAbstractBarSeries::~QAbstractBarSeries()
223 QAbstractBarSeries::~QAbstractBarSeries()
224 {
224 {
225
225
226 }
226 }
227
227
228 /*!
228 /*!
229 \internal
229 \internal
230 */
230 */
231 QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &o, QObject *parent)
231 QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &o, QObject *parent)
232 : QAbstractSeries(o, parent)
232 : QAbstractSeries(o, parent)
233 {
233 {
234 Q_D(QAbstractSeries);
234 Q_D(QAbstractSeries);
235 QObject::connect(this, SIGNAL(countChanged()), d, SIGNAL(countChanged()));
235 QObject::connect(this, SIGNAL(countChanged()), d, SIGNAL(countChanged()));
236 }
236 }
237
237
238 /*!
238 /*!
239 Sets the width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars
239 Sets the width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars
240 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
240 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
241 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
241 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
242 Note that with \link QBarSeries \endlink this value means the width of one group of bars instead of just one bar.
242 Note that with \link QBarSeries \endlink this value means the width of one group of bars instead of just one bar.
243 */
243 */
244 void QAbstractBarSeries::setBarWidth(qreal width)
244 void QAbstractBarSeries::setBarWidth(qreal width)
245 {
245 {
246 Q_D(QAbstractBarSeries);
246 Q_D(QAbstractBarSeries);
247 d->setBarWidth(width);
247 d->setBarWidth(width);
248 }
248 }
249
249
250 /*!
250 /*!
251 Returns the width of the bars of the series.
251 Returns the width of the bars of the series.
252 \sa setBarWidth()
252 \sa setBarWidth()
253 */
253 */
254 qreal QAbstractBarSeries::barWidth() const
254 qreal QAbstractBarSeries::barWidth() const
255 {
255 {
256 Q_D(const QAbstractBarSeries);
256 Q_D(const QAbstractBarSeries);
257 return d->barWidth();
257 return d->barWidth();
258 }
258 }
259
259
260 /*!
260 /*!
261 Adds a set of bars to series. Takes ownership of \a set. If the set is null or is already in series, it won't be appended.
261 Adds a set of bars to series. Takes ownership of \a set. If the set is null or is already in series, it won't be appended.
262 Returns true, if appending succeeded.
262 Returns true, if appending succeeded.
263 */
263 */
264 bool QAbstractBarSeries::append(QBarSet *set)
264 bool QAbstractBarSeries::append(QBarSet *set)
265 {
265 {
266 Q_D(QAbstractBarSeries);
266 Q_D(QAbstractBarSeries);
267 bool success = d->append(set);
267 bool success = d->append(set);
268 if (success) {
268 if (success) {
269 QList<QBarSet *> sets;
269 QList<QBarSet *> sets;
270 sets.append(set);
270 sets.append(set);
271 set->setParent(this);
271 set->setParent(this);
272 emit barsetsAdded(sets);
272 emit barsetsAdded(sets);
273 emit countChanged();
273 emit countChanged();
274 }
274 }
275 return success;
275 return success;
276 }
276 }
277
277
278 /*!
278 /*!
279 Removes barset from series. Releases ownership of \a set. Deletes the set, if remove
279 Removes barset from series. Releases ownership of \a set. Deletes the set, if remove
280 was successful.
280 was successful.
281 Returns true, if set was removed.
281 Returns true, if set was removed.
282 */
282 */
283 bool QAbstractBarSeries::remove(QBarSet *set)
283 bool QAbstractBarSeries::remove(QBarSet *set)
284 {
284 {
285 Q_D(QAbstractBarSeries);
285 Q_D(QAbstractBarSeries);
286 bool success = d->remove(set);
286 bool success = d->remove(set);
287 if (success) {
287 if (success) {
288 QList<QBarSet *> sets;
288 QList<QBarSet *> sets;
289 sets.append(set);
289 sets.append(set);
290 set->setParent(0);
290 set->setParent(0);
291 emit barsetsRemoved(sets);
291 emit barsetsRemoved(sets);
292 emit countChanged();
292 emit countChanged();
293 delete set;
293 delete set;
294 set = 0;
294 set = 0;
295 }
295 }
296 return success;
296 return success;
297 }
297 }
298
298
299 /*!
299 /*!
300 Takes a single \a set from the series. Does not delete the barset object.
300 Takes a single \a set from the series. Does not delete the barset object.
301
301
302 NOTE: The series remains as the barset's parent object. You must set the
302 NOTE: The series remains as the barset's parent object. You must set the
303 parent object to take full ownership.
303 parent object to take full ownership.
304
304
305 Returns true if take was successful.
305 Returns true if take was successful.
306 */
306 */
307 bool QAbstractBarSeries::take(QBarSet *set)
307 bool QAbstractBarSeries::take(QBarSet *set)
308 {
308 {
309 Q_D(QAbstractBarSeries);
309 Q_D(QAbstractBarSeries);
310 bool success = d->remove(set);
310 bool success = d->remove(set);
311 if (success) {
311 if (success) {
312 QList<QBarSet *> sets;
312 QList<QBarSet *> sets;
313 sets.append(set);
313 sets.append(set);
314 emit barsetsRemoved(sets);
314 emit barsetsRemoved(sets);
315 emit countChanged();
315 emit countChanged();
316 }
316 }
317 return success;
317 return success;
318 }
318 }
319
319
320 /*!
320 /*!
321 Adds a list of barsets to series. Takes ownership of \a sets.
321 Adds a list of barsets to series. Takes ownership of \a sets.
322 Returns true, if all sets were appended successfully. If any of the sets is null or is already appended to series,
322 Returns true, if all sets were appended successfully. If any of the sets is null or is already appended to series,
323 nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended
323 nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended
324 and function returns false.
324 and function returns false.
325 */
325 */
326 bool QAbstractBarSeries::append(QList<QBarSet *> sets)
326 bool QAbstractBarSeries::append(QList<QBarSet *> sets)
327 {
327 {
328 Q_D(QAbstractBarSeries);
328 Q_D(QAbstractBarSeries);
329 bool success = d->append(sets);
329 bool success = d->append(sets);
330 if (success) {
330 if (success) {
331 emit barsetsAdded(sets);
331 emit barsetsAdded(sets);
332 emit countChanged();
332 emit countChanged();
333 }
333 }
334 return success;
334 return success;
335 }
335 }
336
336
337 /*!
337 /*!
338 Insert a set of bars to series at \a index postion. Takes ownership of \a set. If the set is null or is already in series, it won't be appended.
338 Insert a set of bars to series at \a index postion. Takes ownership of \a set. If the set is null or is already in series, it won't be appended.
339 Returns true, if inserting succeeded.
339 Returns true, if inserting succeeded.
340
340
341 */
341 */
342 bool QAbstractBarSeries::insert(int index, QBarSet *set)
342 bool QAbstractBarSeries::insert(int index, QBarSet *set)
343 {
343 {
344 Q_D(QAbstractBarSeries);
344 Q_D(QAbstractBarSeries);
345 bool success = d->insert(index, set);
345 bool success = d->insert(index, set);
346 if (success) {
346 if (success) {
347 QList<QBarSet *> sets;
347 QList<QBarSet *> sets;
348 sets.append(set);
348 sets.append(set);
349 emit barsetsAdded(sets);
349 emit barsetsAdded(sets);
350 emit countChanged();
350 emit countChanged();
351 }
351 }
352 return success;
352 return success;
353 }
353 }
354
354
355 /*!
355 /*!
356 Removes all barsets from the series. Deletes removed sets.
356 Removes all barsets from the series. Deletes removed sets.
357 */
357 */
358 void QAbstractBarSeries::clear()
358 void QAbstractBarSeries::clear()
359 {
359 {
360 Q_D(QAbstractBarSeries);
360 Q_D(QAbstractBarSeries);
361 QList<QBarSet *> sets = barSets();
361 QList<QBarSet *> sets = barSets();
362 bool success = d->remove(sets);
362 bool success = d->remove(sets);
363 if (success) {
363 if (success) {
364 emit barsetsRemoved(sets);
364 emit barsetsRemoved(sets);
365 emit countChanged();
365 emit countChanged();
366 foreach (QBarSet *set, sets)
366 foreach (QBarSet *set, sets)
367 delete set;
367 delete set;
368 }
368 }
369 }
369 }
370
370
371 /*!
371 /*!
372 Returns number of sets in series.
372 Returns number of sets in series.
373 */
373 */
374 int QAbstractBarSeries::count() const
374 int QAbstractBarSeries::count() const
375 {
375 {
376 Q_D(const QAbstractBarSeries);
376 Q_D(const QAbstractBarSeries);
377 return d->m_barSets.count();
377 return d->m_barSets.count();
378 }
378 }
379
379
380 /*!
380 /*!
381 Returns a list of sets in series. Keeps ownership of sets.
381 Returns a list of sets in series. Keeps ownership of sets.
382 */
382 */
383 QList<QBarSet *> QAbstractBarSeries::barSets() const
383 QList<QBarSet *> QAbstractBarSeries::barSets() const
384 {
384 {
385 Q_D(const QAbstractBarSeries);
385 Q_D(const QAbstractBarSeries);
386 return d->m_barSets;
386 return d->m_barSets;
387 }
387 }
388
388
389 /*!
389 /*!
390 Sets the visibility of labels in series to \a visible
390 Sets the visibility of labels in series to \a visible
391 */
391 */
392 void QAbstractBarSeries::setLabelsVisible(bool visible)
392 void QAbstractBarSeries::setLabelsVisible(bool visible)
393 {
393 {
394 Q_D(QAbstractBarSeries);
394 Q_D(QAbstractBarSeries);
395 if (d->m_labelsVisible != visible) {
395 if (d->m_labelsVisible != visible) {
396 d->setLabelsVisible(visible);
396 d->setLabelsVisible(visible);
397 emit labelsVisibleChanged();
397 emit labelsVisibleChanged();
398 }
398 }
399 }
399 }
400
400
401 /*!
401 /*!
402 Returns the visibility of labels
402 Returns the visibility of labels
403 */
403 */
404 bool QAbstractBarSeries::isLabelsVisible() const
404 bool QAbstractBarSeries::isLabelsVisible() const
405 {
405 {
406 Q_D(const QAbstractBarSeries);
406 Q_D(const QAbstractBarSeries);
407 return d->m_labelsVisible;
407 return d->m_labelsVisible;
408 }
408 }
409
409
410 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
410 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
411
411
412 QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) :
412 QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) :
413 QAbstractSeriesPrivate(q),
413 QAbstractSeriesPrivate(q),
414 m_barWidth(0.5), // Default value is 50% of category width
414 m_barWidth(0.5), // Default value is 50% of category width
415 m_labelsVisible(false),
415 m_labelsVisible(false),
416 m_visible(true)
416 m_visible(true)
417 {
417 {
418 }
418 }
419
419
420 int QAbstractBarSeriesPrivate::categoryCount() const
420 int QAbstractBarSeriesPrivate::categoryCount() const
421 {
421 {
422 // No categories defined. return count of longest set.
422 // No categories defined. return count of longest set.
423 int count = 0;
423 int count = 0;
424 for (int i = 0; i < m_barSets.count(); i++) {
424 for (int i = 0; i < m_barSets.count(); i++) {
425 if (m_barSets.at(i)->count() > count)
425 if (m_barSets.at(i)->count() > count)
426 count = m_barSets.at(i)->count();
426 count = m_barSets.at(i)->count();
427 }
427 }
428
428
429 return count;
429 return count;
430 }
430 }
431
431
432 void QAbstractBarSeriesPrivate::setBarWidth(qreal width)
432 void QAbstractBarSeriesPrivate::setBarWidth(qreal width)
433 {
433 {
434 if (width < 0.0)
434 if (width < 0.0)
435 width = 0.0;
435 width = 0.0;
436 m_barWidth = width;
436 m_barWidth = width;
437 emit updatedLayout();
437 emit updatedLayout();
438 }
438 }
439
439
440 qreal QAbstractBarSeriesPrivate::barWidth() const
440 qreal QAbstractBarSeriesPrivate::barWidth() const
441 {
441 {
442 return m_barWidth;
442 return m_barWidth;
443 }
443 }
444
444
445 QBarSet *QAbstractBarSeriesPrivate::barsetAt(int index)
445 QBarSet *QAbstractBarSeriesPrivate::barsetAt(int index)
446 {
446 {
447 return m_barSets.at(index);
447 return m_barSets.at(index);
448 }
448 }
449
449
450 void QAbstractBarSeriesPrivate::setVisible(bool visible)
450 void QAbstractBarSeriesPrivate::setVisible(bool visible)
451 {
451 {
452 m_visible = visible;
452 m_visible = visible;
453 emit visibleChanged();
453 emit visibleChanged();
454 }
454 }
455
455
456 void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible)
456 void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible)
457 {
457 {
458 m_labelsVisible = visible;
458 m_labelsVisible = visible;
459 emit labelsVisibleChanged(visible);
459 emit labelsVisibleChanged(visible);
460 }
460 }
461
461
462 qreal QAbstractBarSeriesPrivate::min()
462 qreal QAbstractBarSeriesPrivate::min()
463 {
463 {
464 if (m_barSets.count() <= 0)
464 if (m_barSets.count() <= 0)
465 return 0;
465 return 0;
466
466
467 qreal min = INT_MAX;
467 qreal min = INT_MAX;
468
468
469 for (int i = 0; i < m_barSets.count(); i++) {
469 for (int i = 0; i < m_barSets.count(); i++) {
470 int categoryCount = m_barSets.at(i)->count();
470 int categoryCount = m_barSets.at(i)->count();
471 for (int j = 0; j < categoryCount; j++) {
471 for (int j = 0; j < categoryCount; j++) {
472 qreal temp = m_barSets.at(i)->at(j);
472 qreal temp = m_barSets.at(i)->at(j);
473 if (temp < min)
473 if (temp < min)
474 min = temp;
474 min = temp;
475 }
475 }
476 }
476 }
477 return min;
477 return min;
478 }
478 }
479
479
480 qreal QAbstractBarSeriesPrivate::max()
480 qreal QAbstractBarSeriesPrivate::max()
481 {
481 {
482 if (m_barSets.count() <= 0)
482 if (m_barSets.count() <= 0)
483 return 0;
483 return 0;
484
484
485 qreal max = INT_MIN;
485 qreal max = INT_MIN;
486
486
487 for (int i = 0; i < m_barSets.count(); i++) {
487 for (int i = 0; i < m_barSets.count(); i++) {
488 int categoryCount = m_barSets.at(i)->count();
488 int categoryCount = m_barSets.at(i)->count();
489 for (int j = 0; j < categoryCount; j++) {
489 for (int j = 0; j < categoryCount; j++) {
490 qreal temp = m_barSets.at(i)->at(j);
490 qreal temp = m_barSets.at(i)->at(j);
491 if (temp > max)
491 if (temp > max)
492 max = temp;
492 max = temp;
493 }
493 }
494 }
494 }
495
495
496 return max;
496 return max;
497 }
497 }
498
498
499 qreal QAbstractBarSeriesPrivate::valueAt(int set, int category)
499 qreal QAbstractBarSeriesPrivate::valueAt(int set, int category)
500 {
500 {
501 if ((set < 0) || (set >= m_barSets.count()))
501 if ((set < 0) || (set >= m_barSets.count()))
502 return 0; // No set, no value.
502 return 0; // No set, no value.
503 else if ((category < 0) || (category >= m_barSets.at(set)->count()))
503 else if ((category < 0) || (category >= m_barSets.at(set)->count()))
504 return 0; // No category, no value.
504 return 0; // No category, no value.
505
505
506 return m_barSets.at(set)->at(category);
506 return m_barSets.at(set)->at(category);
507 }
507 }
508
508
509 qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category)
509 qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category)
510 {
510 {
511 if ((set < 0) || (set >= m_barSets.count()))
511 if ((set < 0) || (set >= m_barSets.count()))
512 return 0; // No set, no value.
512 return 0; // No set, no value.
513 else if ((category < 0) || (category >= m_barSets.at(set)->count()))
513 else if ((category < 0) || (category >= m_barSets.at(set)->count()))
514 return 0; // No category, no value.
514 return 0; // No category, no value.
515
515
516 qreal value = m_barSets.at(set)->at(category);
516 qreal value = m_barSets.at(set)->at(category);
517 qreal sum = categorySum(category);
517 qreal sum = categorySum(category);
518 if (qFuzzyCompare(sum, 0))
518 if (qFuzzyCompare(sum, 0))
519 return 0;
519 return 0;
520
520
521 return value / sum;
521 return value / sum;
522 }
522 }
523
523
524 qreal QAbstractBarSeriesPrivate::categorySum(int category)
524 qreal QAbstractBarSeriesPrivate::categorySum(int category)
525 {
525 {
526 qreal sum(0);
526 qreal sum(0);
527 int count = m_barSets.count(); // Count sets
527 int count = m_barSets.count(); // Count sets
528 for (int set = 0; set < count; set++) {
528 for (int set = 0; set < count; set++) {
529 if (category < m_barSets.at(set)->count())
529 if (category < m_barSets.at(set)->count())
530 sum += m_barSets.at(set)->at(category);
530 sum += m_barSets.at(set)->at(category);
531 }
531 }
532 return sum;
532 return sum;
533 }
533 }
534
534
535 qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category)
535 qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category)
536 {
536 {
537 qreal sum(0);
537 qreal sum(0);
538 int count = m_barSets.count(); // Count sets
538 int count = m_barSets.count(); // Count sets
539 for (int set = 0; set < count; set++) {
539 for (int set = 0; set < count; set++) {
540 if (category < m_barSets.at(set)->count())
540 if (category < m_barSets.at(set)->count())
541 sum += qAbs(m_barSets.at(set)->at(category));
541 sum += qAbs(m_barSets.at(set)->at(category));
542 }
542 }
543 return sum;
543 return sum;
544 }
544 }
545
545
546 qreal QAbstractBarSeriesPrivate::maxCategorySum()
546 qreal QAbstractBarSeriesPrivate::maxCategorySum()
547 {
547 {
548 qreal max = INT_MIN;
548 qreal max = INT_MIN;
549 int count = categoryCount();
549 int count = categoryCount();
550 for (int i = 0; i < count; i++) {
550 for (int i = 0; i < count; i++) {
551 qreal sum = categorySum(i);
551 qreal sum = categorySum(i);
552 if (sum > max)
552 if (sum > max)
553 max = sum;
553 max = sum;
554 }
554 }
555 return max;
555 return max;
556 }
556 }
557
557
558 qreal QAbstractBarSeriesPrivate::minX()
558 qreal QAbstractBarSeriesPrivate::minX()
559 {
559 {
560 if (m_barSets.count() <= 0)
560 if (m_barSets.count() <= 0)
561 return 0;
561 return 0;
562
562
563 qreal min = INT_MAX;
563 qreal min = INT_MAX;
564
564
565 for (int i = 0; i < m_barSets.count(); i++) {
565 for (int i = 0; i < m_barSets.count(); i++) {
566 int categoryCount = m_barSets.at(i)->count();
566 int categoryCount = m_barSets.at(i)->count();
567 for (int j = 0; j < categoryCount; j++) {
567 for (int j = 0; j < categoryCount; j++) {
568 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
568 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
569 if (temp < min)
569 if (temp < min)
570 min = temp;
570 min = temp;
571 }
571 }
572 }
572 }
573 return min;
573 return min;
574 }
574 }
575
575
576 qreal QAbstractBarSeriesPrivate::maxX()
576 qreal QAbstractBarSeriesPrivate::maxX()
577 {
577 {
578 if (m_barSets.count() <= 0)
578 if (m_barSets.count() <= 0)
579 return 0;
579 return 0;
580
580
581 qreal max = INT_MIN;
581 qreal max = INT_MIN;
582
582
583 for (int i = 0; i < m_barSets.count(); i++) {
583 for (int i = 0; i < m_barSets.count(); i++) {
584 int categoryCount = m_barSets.at(i)->count();
584 int categoryCount = m_barSets.at(i)->count();
585 for (int j = 0; j < categoryCount; j++) {
585 for (int j = 0; j < categoryCount; j++) {
586 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
586 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
587 if (temp > max)
587 if (temp > max)
588 max = temp;
588 max = temp;
589 }
589 }
590 }
590 }
591
591
592 return max;
592 return max;
593 }
593 }
594
594
595 qreal QAbstractBarSeriesPrivate::categoryTop(int category)
595 qreal QAbstractBarSeriesPrivate::categoryTop(int category)
596 {
596 {
597 // Returns top (sum of all positive values) of category.
597 // Returns top (sum of all positive values) of category.
598 // Returns 0, if all values are negative
598 // Returns 0, if all values are negative
599 qreal top(0);
599 qreal top(0);
600 int count = m_barSets.count();
600 int count = m_barSets.count();
601 for (int set = 0; set < count; set++) {
601 for (int set = 0; set < count; set++) {
602 if (category < m_barSets.at(set)->count()) {
602 if (category < m_barSets.at(set)->count()) {
603 qreal temp = m_barSets.at(set)->at(category);
603 qreal temp = m_barSets.at(set)->at(category);
604 if (temp > 0) {
604 if (temp > 0) {
605 top += temp;
605 top += temp;
606 }
606 }
607 }
607 }
608 }
608 }
609 return top;
609 return top;
610 }
610 }
611
611
612 qreal QAbstractBarSeriesPrivate::categoryBottom(int category)
612 qreal QAbstractBarSeriesPrivate::categoryBottom(int category)
613 {
613 {
614 // Returns bottom (sum of all negative values) of category
614 // Returns bottom (sum of all negative values) of category
615 // Returns 0, if all values are positive
615 // Returns 0, if all values are positive
616 qreal bottom(0);
616 qreal bottom(0);
617 int count = m_barSets.count();
617 int count = m_barSets.count();
618 for (int set = 0; set < count; set++) {
618 for (int set = 0; set < count; set++) {
619 if (category < m_barSets.at(set)->count()) {
619 if (category < m_barSets.at(set)->count()) {
620 qreal temp = m_barSets.at(set)->at(category);
620 qreal temp = m_barSets.at(set)->at(category);
621 if (temp < 0) {
621 if (temp < 0) {
622 bottom += temp;
622 bottom += temp;
623 }
623 }
624 }
624 }
625 }
625 }
626 return bottom;
626 return bottom;
627 }
627 }
628
628
629 qreal QAbstractBarSeriesPrivate::top()
629 qreal QAbstractBarSeriesPrivate::top()
630 {
630 {
631 // Returns top of all categories
631 // Returns top of all categories
632 qreal top(0);
632 qreal top(0);
633 int count = categoryCount();
633 int count = categoryCount();
634 for (int i = 0; i < count; i++) {
634 for (int i = 0; i < count; i++) {
635 qreal temp = categoryTop(i);
635 qreal temp = categoryTop(i);
636 if (temp > top)
636 if (temp > top)
637 top = temp;
637 top = temp;
638 }
638 }
639 return top;
639 return top;
640 }
640 }
641
641
642 qreal QAbstractBarSeriesPrivate::bottom()
642 qreal QAbstractBarSeriesPrivate::bottom()
643 {
643 {
644 // Returns bottom of all categories
644 // Returns bottom of all categories
645 qreal bottom(0);
645 qreal bottom(0);
646 int count = categoryCount();
646 int count = categoryCount();
647 for (int i = 0; i < count; i++) {
647 for (int i = 0; i < count; i++) {
648 qreal temp = categoryBottom(i);
648 qreal temp = categoryBottom(i);
649 if (temp < bottom)
649 if (temp < bottom)
650 bottom = temp;
650 bottom = temp;
651 }
651 }
652 return bottom;
652 return bottom;
653 }
653 }
654
654
655
655
656 void QAbstractBarSeriesPrivate::initializeDomain()
656 void QAbstractBarSeriesPrivate::initializeDomain()
657 {
657 {
658 qreal minX(domain()->minX());
658 qreal minX(domain()->minX());
659 qreal minY(domain()->minY());
659 qreal minY(domain()->minY());
660 qreal maxX(domain()->maxX());
660 qreal maxX(domain()->maxX());
661 qreal maxY(domain()->maxY());
661 qreal maxY(domain()->maxY());
662
662
663 qreal seriesMinX = this->minX();
663 qreal seriesMinX = this->minX();
664 qreal seriesMaxX = this->maxX();
664 qreal seriesMaxX = this->maxX();
665 qreal y = max();
665 qreal y = max();
666 minX = qMin(minX, seriesMinX - (qreal)0.5);
666 minX = qMin(minX, seriesMinX - (qreal)0.5);
667 minY = qMin(minY, y);
667 minY = qMin(minY, y);
668 maxX = qMax(maxX, seriesMaxX + (qreal)0.5);
668 maxX = qMax(maxX, seriesMaxX + (qreal)0.5);
669 maxY = qMax(maxY, y);
669 maxY = qMax(maxY, y);
670
670
671 domain()->setRange(minX, maxX, minY, maxY);
671 domain()->setRange(minX, maxX, minY, maxY);
672 }
672 }
673
673
674 QList<QLegendMarker*> QAbstractBarSeriesPrivate::createLegendMarkers(QLegend* legend)
674 QList<QLegendMarker*> QAbstractBarSeriesPrivate::createLegendMarkers(QLegend* legend)
675 {
675 {
676 Q_Q(QAbstractBarSeries);
676 Q_Q(QAbstractBarSeries);
677 QList<QLegendMarker*> markers;
677 QList<QLegendMarker*> markers;
678
678
679 foreach(QBarSet* set, q->barSets()) {
679 foreach(QBarSet* set, q->barSets()) {
680 QBarLegendMarker* marker = new QBarLegendMarker(q,set,legend);
680 QBarLegendMarker* marker = new QBarLegendMarker(q,set,legend);
681 markers << marker;
681 markers << marker;
682 }
682 }
683 return markers;
683 return markers;
684 }
684 }
685
685
686
686
687 bool QAbstractBarSeriesPrivate::append(QBarSet *set)
687 bool QAbstractBarSeriesPrivate::append(QBarSet *set)
688 {
688 {
689 if ((m_barSets.contains(set)) || (set == 0))
689 if ((m_barSets.contains(set)) || (set == 0))
690 return false; // Fail if set is already in list or set is null.
690 return false; // Fail if set is already in list or set is null.
691
691
692 m_barSets.append(set);
692 m_barSets.append(set);
693 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
693 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
694 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
694 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
695 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
695 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
696
696
697 emit restructuredBars(); // this notifies barchartitem
697 emit restructuredBars(); // this notifies barchartitem
698 return true;
698 return true;
699 }
699 }
700
700
701 bool QAbstractBarSeriesPrivate::remove(QBarSet *set)
701 bool QAbstractBarSeriesPrivate::remove(QBarSet *set)
702 {
702 {
703 if (!m_barSets.contains(set))
703 if (!m_barSets.contains(set))
704 return false; // Fail if set is not in list
704 return false; // Fail if set is not in list
705
705
706 m_barSets.removeOne(set);
706 m_barSets.removeOne(set);
707 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
707 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
708 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
708 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
709 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
709 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
710
710
711 emit restructuredBars(); // this notifies barchartitem
711 emit restructuredBars(); // this notifies barchartitem
712 return true;
712 return true;
713 }
713 }
714
714
715 bool QAbstractBarSeriesPrivate::append(QList<QBarSet * > sets)
715 bool QAbstractBarSeriesPrivate::append(QList<QBarSet * > sets)
716 {
716 {
717 foreach (QBarSet *set, sets) {
717 foreach (QBarSet *set, sets) {
718 if ((set == 0) || (m_barSets.contains(set)))
718 if ((set == 0) || (m_barSets.contains(set)))
719 return false; // Fail if any of the sets is null or is already appended.
719 return false; // Fail if any of the sets is null or is already appended.
720 if (sets.count(set) != 1)
720 if (sets.count(set) != 1)
721 return false; // Also fail if same set is more than once in given list.
721 return false; // Also fail if same set is more than once in given list.
722 }
722 }
723
723
724 foreach (QBarSet *set, sets) {
724 foreach (QBarSet *set, sets) {
725 m_barSets.append(set);
725 m_barSets.append(set);
726 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
726 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
727 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
727 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
728 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
728 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
729 }
729 }
730
730
731 emit restructuredBars(); // this notifies barchartitem
731 emit restructuredBars(); // this notifies barchartitem
732 return true;
732 return true;
733 }
733 }
734
734
735 bool QAbstractBarSeriesPrivate::remove(QList<QBarSet * > sets)
735 bool QAbstractBarSeriesPrivate::remove(QList<QBarSet * > sets)
736 {
736 {
737 if (sets.count() == 0)
737 if (sets.count() == 0)
738 return false;
738 return false;
739
739
740 foreach (QBarSet *set, sets) {
740 foreach (QBarSet *set, sets) {
741 if ((set == 0) || (!m_barSets.contains(set)))
741 if ((set == 0) || (!m_barSets.contains(set)))
742 return false; // Fail if any of the sets is null or is not in series
742 return false; // Fail if any of the sets is null or is not in series
743 if (sets.count(set) != 1)
743 if (sets.count(set) != 1)
744 return false; // Also fail if same set is more than once in given list.
744 return false; // Also fail if same set is more than once in given list.
745 }
745 }
746
746
747 foreach (QBarSet *set, sets) {
747 foreach (QBarSet *set, sets) {
748 m_barSets.removeOne(set);
748 m_barSets.removeOne(set);
749 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
749 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
750 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
750 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
751 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
751 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
752 }
752 }
753
753
754 emit restructuredBars(); // this notifies barchartitem
754 emit restructuredBars(); // this notifies barchartitem
755
755
756 return true;
756 return true;
757 }
757 }
758
758
759 bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set)
759 bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set)
760 {
760 {
761 if ((m_barSets.contains(set)) || (set == 0))
761 if ((m_barSets.contains(set)) || (set == 0))
762 return false; // Fail if set is already in list or set is null.
762 return false; // Fail if set is already in list or set is null.
763
763
764 m_barSets.insert(index, set);
764 m_barSets.insert(index, set);
765 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
765 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
766 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
766 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
767 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
767 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
768
768
769 emit restructuredBars(); // this notifies barchartitem
769 emit restructuredBars(); // this notifies barchartitem
770 return true;
770 return true;
771 }
771 }
772
772
773 void QAbstractBarSeriesPrivate::initializeAxes()
773 void QAbstractBarSeriesPrivate::initializeAxes()
774 {
774 {
775 Q_Q(QAbstractBarSeries);
775 Q_Q(QAbstractBarSeries);
776
776
777 foreach(QAbstractAxis* axis, m_axes) {
777 foreach(QAbstractAxis* axis, m_axes) {
778
778
779 if (axis->type() == QAbstractAxis::AxisTypeBarCategory) {
779 if (axis->type() == QAbstractAxis::AxisTypeBarCategory) {
780 switch (q->type()) {
780 switch (q->type()) {
781 case QAbstractSeries::SeriesTypeHorizontalBar:
781 case QAbstractSeries::SeriesTypeHorizontalBar:
782 case QAbstractSeries::SeriesTypeHorizontalPercentBar:
782 case QAbstractSeries::SeriesTypeHorizontalPercentBar:
783 case QAbstractSeries::SeriesTypeHorizontalStackedBar:
783 case QAbstractSeries::SeriesTypeHorizontalStackedBar:
784 if (axis->orientation() == Qt::Vertical)
784 if (axis->orientation() == Qt::Vertical)
785 populateCategories(qobject_cast<QBarCategoryAxis *>(axis));
785 populateCategories(qobject_cast<QBarCategoryAxis *>(axis));
786 break;
786 break;
787 case QAbstractSeries::SeriesTypeBar:
787 case QAbstractSeries::SeriesTypeBar:
788 case QAbstractSeries::SeriesTypePercentBar:
788 case QAbstractSeries::SeriesTypePercentBar:
789 case QAbstractSeries::SeriesTypeStackedBar:
789 case QAbstractSeries::SeriesTypeStackedBar:
790 if (axis->orientation() == Qt::Horizontal)
790 if (axis->orientation() == Qt::Horizontal)
791 populateCategories(qobject_cast<QBarCategoryAxis *>(axis));
791 populateCategories(qobject_cast<QBarCategoryAxis *>(axis));
792 break;
792 break;
793 default:
793 default:
794 qWarning() << "Unexpected series type";
794 qWarning() << "Unexpected series type";
795 break;
795 break;
796 }
796 }
797 }
797 }
798 }
798 }
799 }
799 }
800
800
801 QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
801 QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
802 {
802 {
803 Q_Q(const QAbstractBarSeries);
803 Q_Q(const QAbstractBarSeries);
804
804
805 switch (q->type()) {
805 switch (q->type()) {
806 case QAbstractSeries::SeriesTypeHorizontalBar:
806 case QAbstractSeries::SeriesTypeHorizontalBar:
807 case QAbstractSeries::SeriesTypeHorizontalPercentBar:
807 case QAbstractSeries::SeriesTypeHorizontalPercentBar:
808 case QAbstractSeries::SeriesTypeHorizontalStackedBar:
808 case QAbstractSeries::SeriesTypeHorizontalStackedBar:
809 if (orientation == Qt::Vertical)
809 if (orientation == Qt::Vertical)
810 return QAbstractAxis::AxisTypeBarCategory;
810 return QAbstractAxis::AxisTypeBarCategory;
811 break;
811 break;
812 case QAbstractSeries::SeriesTypeBar:
812 case QAbstractSeries::SeriesTypeBar:
813 case QAbstractSeries::SeriesTypePercentBar:
813 case QAbstractSeries::SeriesTypePercentBar:
814 case QAbstractSeries::SeriesTypeStackedBar:
814 case QAbstractSeries::SeriesTypeStackedBar:
815 if (orientation == Qt::Horizontal)
815 if (orientation == Qt::Horizontal)
816 return QAbstractAxis::AxisTypeBarCategory;
816 return QAbstractAxis::AxisTypeBarCategory;
817 break;
817 break;
818 default:
818 default:
819 qWarning() << "Unexpected series type";
819 qWarning() << "Unexpected series type";
820 break;
820 break;
821 }
821 }
822 return QAbstractAxis::AxisTypeValue;
822 return QAbstractAxis::AxisTypeValue;
823
823
824 }
824 }
825
825
826 void QAbstractBarSeriesPrivate::populateCategories(QBarCategoryAxis *axis)
826 void QAbstractBarSeriesPrivate::populateCategories(QBarCategoryAxis *axis)
827 {
827 {
828 QStringList categories;
828 QStringList categories;
829 if (axis->categories().isEmpty()) {
829 if (axis->categories().isEmpty()) {
830 for (int i(1); i < categoryCount() + 1; i++)
830 for (int i(1); i < categoryCount() + 1; i++)
831 categories << QString::number(i);
831 categories << QString::number(i);
832 axis->append(categories);
832 axis->append(categories);
833 }
833 }
834 }
834 }
835
835
836 QAbstractAxis* QAbstractBarSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const
836 QAbstractAxis* QAbstractBarSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const
837 {
837 {
838 Q_UNUSED(orientation);
838 Q_UNUSED(orientation);
839 return 0;
839 return 0;
840 }
840 }
841
841
842 void QAbstractBarSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced)
842 void QAbstractBarSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced)
843 {
843 {
844 const QList<QGradient> gradients = theme->seriesGradients();
844 const QList<QGradient> gradients = theme->seriesGradients();
845
845
846 qreal takeAtPos = 0.5;
846 qreal takeAtPos = 0.5;
847 qreal step = 0.2;
847 qreal step = 0.2;
848 if (m_barSets.count() > 1) {
848 if (m_barSets.count() > 1) {
849 step = 1.0 / (qreal) m_barSets.count();
849 step = 1.0 / (qreal) m_barSets.count();
850 if (m_barSets.count() % gradients.count())
850 if (m_barSets.count() % gradients.count())
851 step *= gradients.count();
851 step *= gradients.count();
852 else
852 else
853 step *= (gradients.count() - 1);
853 step *= (gradients.count() - 1);
854 }
854 }
855
855
856 for (int i(0); i < m_barSets.count(); i++) {
856 for (int i(0); i < m_barSets.count(); i++) {
857 int colorIndex = (index + i) % gradients.count();
857 int colorIndex = (index + i) % gradients.count();
858 if (i > 0 && i %gradients.count() == 0) {
858 if (i > 0 && i %gradients.count() == 0) {
859 // There is no dedicated base color for each sets, generate more colors
859 // There is no dedicated base color for each sets, generate more colors
860 takeAtPos += step;
860 takeAtPos += step;
861 if (takeAtPos == 1.0)
861 if (takeAtPos == 1.0)
862 takeAtPos += step;
862 takeAtPos += step;
863 takeAtPos -= (int) takeAtPos;
863 takeAtPos -= (int) takeAtPos;
864 }
864 }
865 if (forced || QChartPrivate::defaultBrush() == m_barSets.at(i)->d_ptr->m_brush)
865 if (forced || QChartPrivate::defaultBrush() == m_barSets.at(i)->d_ptr->m_brush)
866 m_barSets.at(i)->setBrush(ChartThemeManager::colorAt(gradients.at(colorIndex), takeAtPos));
866 m_barSets.at(i)->setBrush(ChartThemeManager::colorAt(gradients.at(colorIndex), takeAtPos));
867
867
868 // Pick label color from the opposite end of the gradient.
868 // Pick label color from the opposite end of the gradient.
869 // 0.3 as a boundary seems to work well.
869 // 0.3 as a boundary seems to work well.
870 if (forced || QChartPrivate::defaultBrush() == m_barSets.at(i)->d_ptr->m_labelBrush) {
870 if (forced || QChartPrivate::defaultBrush() == m_barSets.at(i)->d_ptr->m_labelBrush) {
871 if (takeAtPos < 0.3)
871 if (takeAtPos < 0.3)
872 m_barSets.at(i)->setLabelBrush(ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 1));
872 m_barSets.at(i)->setLabelBrush(ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 1));
873 else
873 else
874 m_barSets.at(i)->setLabelBrush(ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0));
874 m_barSets.at(i)->setLabelBrush(ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0));
875 }
875 }
876
876
877 if (forced || QChartPrivate::defaultPen() == m_barSets.at(i)->d_ptr->m_pen) {
877 if (forced || QChartPrivate::defaultPen() == m_barSets.at(i)->d_ptr->m_pen) {
878 QColor c = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.0);
878 QColor c = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.0);
879 m_barSets.at(i)->setPen(c);
879 m_barSets.at(i)->setPen(c);
880 }
880 }
881 }
881 }
882 }
882 }
883
883
884 void QAbstractBarSeriesPrivate::initializeAnimations(QChart::AnimationOptions options)
884 void QAbstractBarSeriesPrivate::initializeAnimations(QChart::AnimationOptions options)
885 {
885 {
886 AbstractBarChartItem *bar = static_cast<AbstractBarChartItem *>(m_item.data());
886 AbstractBarChartItem *bar = static_cast<AbstractBarChartItem *>(m_item.data());
887 Q_ASSERT(bar);
887 Q_ASSERT(bar);
888 if (options.testFlag(QChart::SeriesAnimations)) {
888 if (options.testFlag(QChart::SeriesAnimations)) {
889 bar->setAnimation(new BarAnimation(bar));
889 bar->setAnimation(new BarAnimation(bar));
890 }else{
890 }else{
891 bar->setAnimation(0);
891 bar->setAnimation(0);
892 }
892 }
893 QAbstractSeriesPrivate::initializeAnimations(options);
893 QAbstractSeriesPrivate::initializeAnimations(options);
894 }
894 }
895
895
896 #include "moc_qabstractbarseries.cpp"
896 #include "moc_qabstractbarseries.cpp"
897 #include "moc_qabstractbarseries_p.cpp"
897 #include "moc_qabstractbarseries_p.cpp"
898
898
899 QTCOMMERCIALCHART_END_NAMESPACE
899 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,658 +1,658
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qbarset.h"
21 #include "qbarset.h"
22 #include "qbarset_p.h"
22 #include "qbarset_p.h"
23 #include "charthelpers_p.h"
23 #include "charthelpers_p.h"
24 #include "qchart_p.h"
24 #include "qchart_p.h"
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 /*!
28 /*!
29 \class QBarSet
29 \class QBarSet
30 \brief Building block for different bar charts
30 \brief Building block for different bar charts.
31
31
32 QBarSet represents one set of bars. Set of bars contains one data value for each category.
32 QBarSet represents one set of bars. Set of bars contains one data value for each category.
33 First value of set is assumed to belong to first category, second to second category and so on.
33 First value of set is assumed to belong to first category, second to second category and so on.
34 If set has fewer values than there are categories, then the missing values are assumed to be
34 If set has fewer values than there are categories, then the missing values are assumed to be
35 at the end of set. For missing values in middle of a set, numerical value of zero is used.
35 at the end of set. For missing values in middle of a set, numerical value of zero is used.
36
36
37 \mainclass
37 \mainclass
38
38
39 \sa QAbstractBarSeries, QBarSeries, QStackedBarSeries, QPercentBarSeries
39 \sa QAbstractBarSeries, QBarSeries, QStackedBarSeries, QPercentBarSeries
40 */
40 */
41 /*!
41 /*!
42 \qmlclass BarSet QBarSet
42 \qmlclass BarSet QBarSet
43
43
44 BarSet represents one set of bars. Set of bars contains one data value for each category.
44 BarSet represents one set of bars. Set of bars contains one data value for each category.
45 First value of set is assumed to belong to first category, second to second category and so on.
45 First value of set is assumed to belong to first category, second to second category and so on.
46 If set has fewer values than there are categories, then the missing values are assumed to be
46 If set has fewer values than there are categories, then the missing values are assumed to be
47 at the end of set. For missing values in middle of a set, numerical value of zero is used.
47 at the end of set. For missing values in middle of a set, numerical value of zero is used.
48 \sa AbstractBarSeries, BarSeries, StackedBarSeries, PercentBarSeries
48 \sa AbstractBarSeries, BarSeries, StackedBarSeries, PercentBarSeries
49 */
49 */
50
50
51 /*!
51 /*!
52 \property QBarSet::label
52 \property QBarSet::label
53 Defines the label of the barSet.
53 Defines the label of the bar set.
54 */
54 */
55 /*!
55 /*!
56 \qmlproperty string BarSet::label
56 \qmlproperty string BarSet::label
57 Defines the label of the barSet.
57 Defines the label of the bar set.
58 */
58 */
59
59
60 /*!
60 /*!
61 \property QBarSet::pen
61 \property QBarSet::pen
62 \brief Defines the pen used by the barSet.
62 \brief Defines the pen used by the bar set.
63 */
63 */
64
64
65 /*!
65 /*!
66 \property QBarSet::brush
66 \property QBarSet::brush
67 \brief Defines the brush used by the barSet.
67 \brief Defines the brush used by the bar set.
68 */
68 */
69
69
70 /*!
70 /*!
71 \property QBarSet::labelBrush
71 \property QBarSet::labelBrush
72 \brief Defines the brush used by the barSet's label.
72 \brief Defines the brush used by the bar set's label.
73 */
73 */
74
74
75 /*!
75 /*!
76 \property QBarSet::labelFont
76 \property QBarSet::labelFont
77 \brief Defines the font used by the barSet's label.
77 \brief Defines the font used by the bar set's label.
78 */
78 */
79
79
80 /*!
80 /*!
81 \qmlproperty Font BarSet::labelFont
81 \qmlproperty Font BarSet::labelFont
82 Defines the font used by the barSet's label.
82 Defines the font used by the bar set's label.
83
83
84 See the \l {Font} {QML Font Element} for detailed documentation.
84 See the \l {Font} {QML Font Element} for detailed documentation.
85 */
85 */
86
86
87 /*!
87 /*!
88 \property QBarSet::color
88 \property QBarSet::color
89 The fill (brush) color of the bar set.
89 The fill (brush) color of the bar set.
90 */
90 */
91 /*!
91 /*!
92 \qmlproperty color BarSet::color
92 \qmlproperty color BarSet::color
93 The fill (brush) color of the bar set.
93 The fill (brush) color of the bar set.
94 */
94 */
95
95
96 /*!
96 /*!
97 \property QBarSet::borderColor
97 \property QBarSet::borderColor
98 The line (pen) color of the bar set.
98 The line (pen) color of the bar set.
99 */
99 */
100 /*!
100 /*!
101 \qmlproperty color BarSet::borderColor
101 \qmlproperty color BarSet::borderColor
102 The line (pen) color of the bar set.
102 The line (pen) color of the bar set.
103 */
103 */
104
104
105 /*!
105 /*!
106 \qmlproperty real BarSet::borderWidth
106 \qmlproperty real BarSet::borderWidth
107 The width of the border line. By default the width is 2.0.
107 The width of the border line. By default the width is 2.0.
108 */
108 */
109
109
110 /*!
110 /*!
111 \property QBarSet::labelColor
111 \property QBarSet::labelColor
112 The text (label) color of the bar set.
112 The text (label) color of the bar set.
113 */
113 */
114 /*!
114 /*!
115 \qmlproperty color BarSet::labelColor
115 \qmlproperty color BarSet::labelColor
116 The text (label) color of the bar set.
116 The text (label) color of the bar set.
117 */
117 */
118
118
119 /*!
119 /*!
120 \fn void QBarSet::clicked(int index)
120 \fn void QBarSet::clicked(int index)
121
121
122 The signal is emitted if the user clicks with a mouse on top of barset.
122 The signal is emitted if the user clicks with a mouse on top of bar set.
123 Clicked bar inside set is indexed by \a index
123 Clicked bar inside set is indexed by \a index
124 */
124 */
125
125
126 /*!
126 /*!
127 \fn void QBarSet::hovered(bool status)
127 \fn void QBarSet::hovered(bool status)
128
128
129 The signal is emitted if mouse is hovered on top of barset.
129 The signal is emitted if mouse is hovered on top of bar set.
130 Parameter \a status is true, if mouse entered on top of barset, false if mouse left from top of barset.
130 Parameter \a status is true, if mouse entered on top of bar set, false if mouse left from top of bar set.
131 */
131 */
132
132
133
133
134 /*!
134 /*!
135 \fn void QBarSet::labelChanged()
135 \fn void QBarSet::labelChanged()
136 This signal is emitted when the label of the barSet has changed.
136 This signal is emitted when the label of the bar set has changed.
137 \sa label
137 \sa label
138 */
138 */
139 /*!
139 /*!
140 \qmlsignal BarSet::onLabelChanged()
140 \qmlsignal BarSet::onLabelChanged()
141 This signal is emitted when the label of the barSet has changed.
141 This signal is emitted when the label of the bar set has changed.
142 */
142 */
143
143
144 /*!
144 /*!
145 \fn void QBarSet::penChanged()
145 \fn void QBarSet::penChanged()
146 This signal is emitted when the pen of the barSet has changed.
146 This signal is emitted when the pen of the bar set has changed.
147 \sa pen
147 \sa pen
148 */
148 */
149
149
150 /*!
150 /*!
151 \fn void QBarSet::brushChanged()
151 \fn void QBarSet::brushChanged()
152 This signal is emitted when the brush of the barSet has changed.
152 This signal is emitted when the brush of the bar set has changed.
153 \sa brush
153 \sa brush
154 */
154 */
155
155
156 /*!
156 /*!
157 \fn void QBarSet::labelBrushChanged()
157 \fn void QBarSet::labelBrushChanged()
158 This signal is emitted when the brush of the barSet's label has changed.
158 This signal is emitted when the brush of the bar set's label has changed.
159 \sa labelBrush
159 \sa labelBrush
160 */
160 */
161
161
162 /*!
162 /*!
163 \fn void QBarSet::labelFontChanged()
163 \fn void QBarSet::labelFontChanged()
164 This signal is emitted when the font of the barSet's label has changed.
164 This signal is emitted when the font of the bar set's label has changed.
165 \sa labelBrush
165 \sa labelBrush
166 */
166 */
167
167
168 /*!
168 /*!
169 \fn void QBarSet::colorChanged(QColor)
169 \fn void QBarSet::colorChanged(QColor)
170 This signal is emitted when the fill (brush) color of the set has changed to \a color.
170 This signal is emitted when the fill (brush) color of the set has changed to \a color.
171 */
171 */
172 /*!
172 /*!
173 \qmlsignal BarSet::onColorChanged(color color)
173 \qmlsignal BarSet::onColorChanged(color color)
174 This signal is emitted when the fill (brush) color of the set has changed to \a color.
174 This signal is emitted when the fill (brush) color of the set has changed to \a color.
175 */
175 */
176
176
177 /*!
177 /*!
178 \fn void QBarSet::borderColorChanged(QColor)
178 \fn void QBarSet::borderColorChanged(QColor)
179 This signal is emitted when the line (pen) color of the set has changed to \a color.
179 This signal is emitted when the line (pen) color of the set has changed to \a color.
180 */
180 */
181 /*!
181 /*!
182 \qmlsignal BarSet::onBorderColorChanged(color color)
182 \qmlsignal BarSet::onBorderColorChanged(color color)
183 This signal is emitted when the line (pen) color of the set has changed to \a color.
183 This signal is emitted when the line (pen) color of the set has changed to \a color.
184 */
184 */
185
185
186 /*!
186 /*!
187 \fn void QBarSet::labelColorChanged(QColor)
187 \fn void QBarSet::labelColorChanged(QColor)
188 This signal is emitted when the text (label) color of the set has changed to \a color.
188 This signal is emitted when the text (label) color of the set has changed to \a color.
189 */
189 */
190 /*!
190 /*!
191 \qmlsignal BarSet::onLabelColorChanged(color color)
191 \qmlsignal BarSet::onLabelColorChanged(color color)
192 This signal is emitted when the text (label) color of the set has changed to \a color.
192 This signal is emitted when the text (label) color of the set has changed to \a color.
193 */
193 */
194
194
195 /*!
195 /*!
196 \fn void QBarSet::valuesAdded(int index, int count)
196 \fn void QBarSet::valuesAdded(int index, int count)
197 This signal is emitted when new values have been added to the set.
197 This signal is emitted when new values have been added to the set.
198 Parameter \a index indicates the position of the first inserted value.
198 Parameter \a index indicates the position of the first inserted value.
199 Parameter \a count is the number of inserted values.
199 Parameter \a count is the number of inserted values.
200 \sa append(), insert()
200 \sa append(), insert()
201 */
201 */
202 /*!
202 /*!
203 \qmlsignal BarSet::onValuesAdded(int index, int count)
203 \qmlsignal BarSet::onValuesAdded(int index, int count)
204 This signal is emitted when new values have been added to the set.
204 This signal is emitted when new values have been added to the set.
205 Parameter \a index indicates the position of the first inserted value.
205 Parameter \a index indicates the position of the first inserted value.
206 Parameter \a count is the number of inserted values.
206 Parameter \a count is the number of inserted values.
207 */
207 */
208
208
209 /*!
209 /*!
210 \fn void QBarSet::valuesRemoved(int index, int count)
210 \fn void QBarSet::valuesRemoved(int index, int count)
211 This signal is emitted values have been removed from the set.
211 This signal is emitted values have been removed from the set.
212 Parameter \a index indicates the position of the first removed value.
212 Parameter \a index indicates the position of the first removed value.
213 Parameter \a count is the number of removed values.
213 Parameter \a count is the number of removed values.
214 \sa remove()
214 \sa remove()
215 */
215 */
216 /*!
216 /*!
217 \qmlsignal BarSet::onValuesRemoved(int index, int count)
217 \qmlsignal BarSet::onValuesRemoved(int index, int count)
218 This signal is emitted values have been removed from the set.
218 This signal is emitted values have been removed from the set.
219 Parameter \a index indicates the position of the first removed value.
219 Parameter \a index indicates the position of the first removed value.
220 Parameter \a count is the number of removed values.
220 Parameter \a count is the number of removed values.
221 */
221 */
222
222
223 /*!
223 /*!
224 \fn void QBarSet::valueChanged(int index)
224 \fn void QBarSet::valueChanged(int index)
225 This signal is emitted values the value in the set has been modified.
225 This signal is emitted values the value in the set has been modified.
226 Parameter \a index indicates the position of the modified value.
226 Parameter \a index indicates the position of the modified value.
227 \sa at()
227 \sa at()
228 */
228 */
229 /*!
229 /*!
230 \qmlsignal BarSet::onValueChanged(int index)
230 \qmlsignal BarSet::onValueChanged(int index)
231 This signal is emitted values the value in the set has been modified.
231 This signal is emitted values the value in the set has been modified.
232 Parameter \a index indicates the position of the modified value.
232 Parameter \a index indicates the position of the modified value.
233 */
233 */
234
234
235 /*!
235 /*!
236 \qmlproperty int BarSet::count
236 \qmlproperty int BarSet::count
237 The count of values on the barset
237 The count of values on the bar set
238 */
238 */
239
239
240 /*!
240 /*!
241 \qmlproperty QVariantList BarSet::values
241 \qmlproperty QVariantList BarSet::values
242 The values of the barset. You can set either a list of reals or a list of points as values. If you set a list of
242 The values of the bar set. You can set either a list of reals or a list of points as values. If you set a list of
243 reals as values, the values are automatically completed to points by using the index of a value as it's
243 reals as values, the values are automatically completed to points by using the index of a value as it's
244 x-coordinate. For example:
244 x-coordinate. For example:
245 \code
245 \code
246 myBarSet1.values = [0, 5, 1, 5];
246 myBarSet1.values = [0, 5, 1, 5];
247 myBarSet2.values = [Qt.point(0, 1), Qt.point(1, 5), Qt.point(2.2, 4.3)];
247 myBarSet2.values = [Qt.point(0, 1), Qt.point(1, 5), Qt.point(2.2, 4.3)];
248 \endcode
248 \endcode
249 */
249 */
250
250
251 /*!
251 /*!
252 Constructs QBarSet with a label of \a label and with parent of \a parent.
252 Constructs QBarSet with a label of \a label and with parent of \a parent.
253 */
253 */
254 QBarSet::QBarSet(const QString label, QObject *parent)
254 QBarSet::QBarSet(const QString label, QObject *parent)
255 : QObject(parent),
255 : QObject(parent),
256 d_ptr(new QBarSetPrivate(label, this))
256 d_ptr(new QBarSetPrivate(label, this))
257 {
257 {
258 }
258 }
259
259
260 /*!
260 /*!
261 Destroys the barset.
261 Destroys the bar set.
262 */
262 */
263 QBarSet::~QBarSet()
263 QBarSet::~QBarSet()
264 {
264 {
265 // NOTE: d_ptr destroyed by QObject
265 // NOTE: d_ptr destroyed by QObject
266 }
266 }
267
267
268 /*!
268 /*!
269 Sets new \a label for set.
269 Sets new \a label for set.
270 */
270 */
271 void QBarSet::setLabel(const QString label)
271 void QBarSet::setLabel(const QString label)
272 {
272 {
273 d_ptr->m_label = label;
273 d_ptr->m_label = label;
274 emit labelChanged();
274 emit labelChanged();
275 }
275 }
276
276
277 /*!
277 /*!
278 Returns label of the set.
278 Returns label of the set.
279 */
279 */
280 QString QBarSet::label() const
280 QString QBarSet::label() const
281 {
281 {
282 return d_ptr->m_label;
282 return d_ptr->m_label;
283 }
283 }
284
284
285 /*!
285 /*!
286 Appends new value \a value to the end of set.
286 Appends new value \a value to the end of set.
287 */
287 */
288 void QBarSet::append(const qreal value)
288 void QBarSet::append(const qreal value)
289 {
289 {
290 // Convert to QPointF
290 // Convert to QPointF
291 int index = d_ptr->m_values.count();
291 int index = d_ptr->m_values.count();
292 d_ptr->append(QPointF(d_ptr->m_values.count(), value));
292 d_ptr->append(QPointF(d_ptr->m_values.count(), value));
293 emit valuesAdded(index, 1);
293 emit valuesAdded(index, 1);
294 }
294 }
295
295
296 /*!
296 /*!
297 Appends a list of reals to set. Works like append with single real value. The \a values in list
297 Appends a list of reals to set. Works like append with single real value. The \a values in list
298 are appended to end of barset
298 are appended to end of bar set.
299 \sa append()
299 \sa append()
300 */
300 */
301 void QBarSet::append(const QList<qreal> &values)
301 void QBarSet::append(const QList<qreal> &values)
302 {
302 {
303 int index = d_ptr->m_values.count();
303 int index = d_ptr->m_values.count();
304 d_ptr->append(values);
304 d_ptr->append(values);
305 emit valuesAdded(index, values.count());
305 emit valuesAdded(index, values.count());
306 }
306 }
307
307
308 /*!
308 /*!
309 Convenience operator. Same as append, with real \a value.
309 Convenience operator. Same as append, with real \a value.
310 \sa append()
310 \sa append()
311 */
311 */
312 QBarSet &QBarSet::operator << (const qreal &value)
312 QBarSet &QBarSet::operator << (const qreal &value)
313 {
313 {
314 append(value);
314 append(value);
315 return *this;
315 return *this;
316 }
316 }
317
317
318 /*!
318 /*!
319 Inserts new \a value on the \a index position.
319 Inserts new \a value on the \a index position.
320 The value that is currently at this postion is moved to position index + 1
320 The value that is currently at this postion is moved to position index + 1
321 \sa remove()
321 \sa remove()
322 */
322 */
323 void QBarSet::insert(const int index, const qreal value)
323 void QBarSet::insert(const int index, const qreal value)
324 {
324 {
325 d_ptr->insert(index, value);
325 d_ptr->insert(index, value);
326 emit valuesAdded(index, 1);
326 emit valuesAdded(index, 1);
327 }
327 }
328
328
329 /*!
329 /*!
330 Removes \a count number of values from the set starting at \a index.
330 Removes \a count number of values from the set starting at \a index.
331 \sa insert()
331 \sa insert()
332 */
332 */
333 void QBarSet::remove(const int index, const int count)
333 void QBarSet::remove(const int index, const int count)
334 {
334 {
335 int removedCount = d_ptr->remove(index, count);
335 int removedCount = d_ptr->remove(index, count);
336 if (removedCount > 0)
336 if (removedCount > 0)
337 emit valuesRemoved(index, removedCount);
337 emit valuesRemoved(index, removedCount);
338 return;
338 return;
339 }
339 }
340
340
341 /*!
341 /*!
342 Sets a new value \a value to set, indexed by \a index.
342 Sets a new value \a value to set, indexed by \a index.
343 */
343 */
344 void QBarSet::replace(const int index, const qreal value)
344 void QBarSet::replace(const int index, const qreal value)
345 {
345 {
346 if (index >= 0 && index < d_ptr->m_values.count()) {
346 if (index >= 0 && index < d_ptr->m_values.count()) {
347 d_ptr->replace(index, value);
347 d_ptr->replace(index, value);
348 emit valueChanged(index);
348 emit valueChanged(index);
349 }
349 }
350 }
350 }
351
351
352
352
353 /*!
353 /*!
354 Returns value of set indexed by \a index.
354 Returns value of set indexed by \a index.
355 If the index is out of bounds 0.0 is returned.
355 If the index is out of bounds 0.0 is returned.
356 */
356 */
357 qreal QBarSet::at(const int index) const
357 qreal QBarSet::at(const int index) const
358 {
358 {
359 if (index < 0 || index >= d_ptr->m_values.count())
359 if (index < 0 || index >= d_ptr->m_values.count())
360 return 0;
360 return 0;
361 return d_ptr->m_values.at(index).y();
361 return d_ptr->m_values.at(index).y();
362 }
362 }
363
363
364 /*!
364 /*!
365 Returns value of set indexed by \a index.
365 Returns value of set indexed by \a index.
366 If the index is out of bounds 0.0 is returned.
366 If the index is out of bounds 0.0 is returned.
367 */
367 */
368 qreal QBarSet::operator [](const int index) const
368 qreal QBarSet::operator [](const int index) const
369 {
369 {
370 return at(index);
370 return at(index);
371 }
371 }
372
372
373 /*!
373 /*!
374 Returns count of values in set.
374 Returns count of values in set.
375 */
375 */
376 int QBarSet::count() const
376 int QBarSet::count() const
377 {
377 {
378 return d_ptr->m_values.count();
378 return d_ptr->m_values.count();
379 }
379 }
380
380
381 /*!
381 /*!
382 Returns sum of all values in barset.
382 Returns sum of all values in the bar set.
383 */
383 */
384 qreal QBarSet::sum() const
384 qreal QBarSet::sum() const
385 {
385 {
386 qreal total(0);
386 qreal total(0);
387 for (int i = 0; i < d_ptr->m_values.count(); i++)
387 for (int i = 0; i < d_ptr->m_values.count(); i++)
388 total += d_ptr->m_values.at(i).y();
388 total += d_ptr->m_values.at(i).y();
389 return total;
389 return total;
390 }
390 }
391
391
392 /*!
392 /*!
393 Sets pen for set. Bars of this set are drawn using \a pen
393 Sets pen for set. Bars of this set are drawn using \a pen
394 */
394 */
395 void QBarSet::setPen(const QPen &pen)
395 void QBarSet::setPen(const QPen &pen)
396 {
396 {
397 if (d_ptr->m_pen != pen) {
397 if (d_ptr->m_pen != pen) {
398 d_ptr->m_pen = pen;
398 d_ptr->m_pen = pen;
399 emit d_ptr->updatedBars();
399 emit d_ptr->updatedBars();
400 emit penChanged();
400 emit penChanged();
401 }
401 }
402 }
402 }
403
403
404 /*!
404 /*!
405 Returns pen of the set.
405 Returns pen of the set.
406 */
406 */
407 QPen QBarSet::pen() const
407 QPen QBarSet::pen() const
408 {
408 {
409 if (d_ptr->m_pen == QChartPrivate::defaultPen())
409 if (d_ptr->m_pen == QChartPrivate::defaultPen())
410 return QPen();
410 return QPen();
411 else
411 else
412 return d_ptr->m_pen;
412 return d_ptr->m_pen;
413 }
413 }
414
414
415 /*!
415 /*!
416 Sets brush for the set. Bars of this set are drawn using \a brush
416 Sets brush for the set. Bars of this set are drawn using \a brush.
417 */
417 */
418 void QBarSet::setBrush(const QBrush &brush)
418 void QBarSet::setBrush(const QBrush &brush)
419 {
419 {
420 if (d_ptr->m_brush != brush) {
420 if (d_ptr->m_brush != brush) {
421 d_ptr->m_brush = brush;
421 d_ptr->m_brush = brush;
422 emit d_ptr->updatedBars();
422 emit d_ptr->updatedBars();
423 emit brushChanged();
423 emit brushChanged();
424 }
424 }
425 }
425 }
426
426
427 /*!
427 /*!
428 Returns brush of the set.
428 Returns brush of the set.
429 */
429 */
430 QBrush QBarSet::brush() const
430 QBrush QBarSet::brush() const
431 {
431 {
432 if (d_ptr->m_brush == QChartPrivate::defaultBrush())
432 if (d_ptr->m_brush == QChartPrivate::defaultBrush())
433 return QBrush();
433 return QBrush();
434 else
434 else
435 return d_ptr->m_brush;
435 return d_ptr->m_brush;
436 }
436 }
437
437
438 /*!
438 /*!
439 Sets \a brush of the values that are drawn on top of this barset
439 Sets \a brush of the values that are drawn on top of this bar set.
440 */
440 */
441 void QBarSet::setLabelBrush(const QBrush &brush)
441 void QBarSet::setLabelBrush(const QBrush &brush)
442 {
442 {
443 if (d_ptr->m_labelBrush != brush) {
443 if (d_ptr->m_labelBrush != brush) {
444 d_ptr->m_labelBrush = brush;
444 d_ptr->m_labelBrush = brush;
445 emit d_ptr->updatedBars();
445 emit d_ptr->updatedBars();
446 emit labelBrushChanged();
446 emit labelBrushChanged();
447 }
447 }
448 }
448 }
449
449
450 /*!
450 /*!
451 Returns brush of the values that are drawn on top of this barset
451 Returns brush of the values that are drawn on top of this bar set.
452 */
452 */
453 QBrush QBarSet::labelBrush() const
453 QBrush QBarSet::labelBrush() const
454 {
454 {
455 if (d_ptr->m_labelBrush == QChartPrivate::defaultBrush())
455 if (d_ptr->m_labelBrush == QChartPrivate::defaultBrush())
456 return QBrush();
456 return QBrush();
457 else
457 else
458 return d_ptr->m_labelBrush;
458 return d_ptr->m_labelBrush;
459 }
459 }
460
460
461 /*!
461 /*!
462 Sets the \a font for values that are drawn on top of this barset
462 Sets the \a font for values that are drawn on top of this bar set.
463 */
463 */
464 void QBarSet::setLabelFont(const QFont &font)
464 void QBarSet::setLabelFont(const QFont &font)
465 {
465 {
466 if (d_ptr->m_labelFont != font) {
466 if (d_ptr->m_labelFont != font) {
467 d_ptr->m_labelFont = font;
467 d_ptr->m_labelFont = font;
468 emit d_ptr->updatedBars();
468 emit d_ptr->updatedBars();
469 emit labelFontChanged();
469 emit labelFontChanged();
470 }
470 }
471
471
472 }
472 }
473
473
474 /*!
474 /*!
475 Returns the pen for values that are drawn on top of this barset
475 Returns the pen for values that are drawn on top of this bar set.
476 */
476 */
477 QFont QBarSet::labelFont() const
477 QFont QBarSet::labelFont() const
478 {
478 {
479 return d_ptr->m_labelFont;
479 return d_ptr->m_labelFont;
480 }
480 }
481
481
482 /*!
482 /*!
483 Returns the color of the brush of barset.
483 Returns the color of the brush of bar set.
484 */
484 */
485 QColor QBarSet::color()
485 QColor QBarSet::color()
486 {
486 {
487 return brush().color();
487 return brush().color();
488 }
488 }
489
489
490 /*!
490 /*!
491 Sets the \a color of brush for this barset
491 Sets the \a color of brush for this bar set.
492 */
492 */
493 void QBarSet::setColor(QColor color)
493 void QBarSet::setColor(QColor color)
494 {
494 {
495 QBrush b = brush();
495 QBrush b = brush();
496 if ((b.color() != color) || (b.style() == Qt::NoBrush)) {
496 if ((b.color() != color) || (b.style() == Qt::NoBrush)) {
497 b.setColor(color);
497 b.setColor(color);
498 if (b.style() == Qt::NoBrush) {
498 if (b.style() == Qt::NoBrush) {
499 // Set tyle to Qt::SolidPattern. (Default is Qt::NoBrush)
499 // Set tyle to Qt::SolidPattern. (Default is Qt::NoBrush)
500 // This prevents theme to override color defined in QML side:
500 // This prevents theme to override color defined in QML side:
501 // BarSet { label: "Bob"; color:"red"; values: [1,2,3] }
501 // BarSet { label: "Bob"; color:"red"; values: [1,2,3] }
502 // The color must be obeyed, since user wanted it.
502 // The color must be obeyed, since user wanted it.
503 b.setStyle(Qt::SolidPattern);
503 b.setStyle(Qt::SolidPattern);
504 }
504 }
505 setBrush(b);
505 setBrush(b);
506 emit colorChanged(color);
506 emit colorChanged(color);
507 }
507 }
508 }
508 }
509
509
510 /*!
510 /*!
511 Returns the color of pen of this barset
511 Returns the color of pen of this bar set.
512 */
512 */
513 QColor QBarSet::borderColor()
513 QColor QBarSet::borderColor()
514 {
514 {
515 return pen().color();
515 return pen().color();
516 }
516 }
517
517
518 /*!
518 /*!
519 Sets the color of pen for this barset
519 Sets the color of pen for this bar set.
520 */
520 */
521 void QBarSet::setBorderColor(QColor color)
521 void QBarSet::setBorderColor(QColor color)
522 {
522 {
523 QPen p = pen();
523 QPen p = pen();
524 if (p.color() != color) {
524 if (p.color() != color) {
525 p.setColor(color);
525 p.setColor(color);
526 setPen(p);
526 setPen(p);
527 emit borderColorChanged(color);
527 emit borderColorChanged(color);
528 }
528 }
529 }
529 }
530
530
531 /*!
531 /*!
532 Returns the color of labels of this barset
532 Returns the color of labels of this bar set.
533 */
533 */
534 QColor QBarSet::labelColor()
534 QColor QBarSet::labelColor()
535 {
535 {
536 return labelBrush().color();
536 return labelBrush().color();
537 }
537 }
538
538
539 /*!
539 /*!
540 Sets the color of labels for this barset
540 Sets the color of labels for this bar set.
541 */
541 */
542 void QBarSet::setLabelColor(QColor color)
542 void QBarSet::setLabelColor(QColor color)
543 {
543 {
544 QBrush b = labelBrush();
544 QBrush b = labelBrush();
545 if (b == QBrush())
545 if (b == QBrush())
546 b.setStyle(Qt::SolidPattern);
546 b.setStyle(Qt::SolidPattern);
547
547
548 if (b.color() != color) {
548 if (b.color() != color) {
549 b.setColor(color);
549 b.setColor(color);
550 setLabelBrush(b);
550 setLabelBrush(b);
551 emit labelColorChanged(color);
551 emit labelColorChanged(color);
552 }
552 }
553 }
553 }
554
554
555 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
555 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
556
556
557 QBarSetPrivate::QBarSetPrivate(const QString label, QBarSet *parent) : QObject(parent),
557 QBarSetPrivate::QBarSetPrivate(const QString label, QBarSet *parent) : QObject(parent),
558 q_ptr(parent),
558 q_ptr(parent),
559 m_label(label),
559 m_label(label),
560 m_pen(QChartPrivate::defaultPen()),
560 m_pen(QChartPrivate::defaultPen()),
561 m_brush(QChartPrivate::defaultBrush()),
561 m_brush(QChartPrivate::defaultBrush()),
562 m_labelBrush(QChartPrivate::defaultBrush())
562 m_labelBrush(QChartPrivate::defaultBrush())
563 {
563 {
564 }
564 }
565
565
566 QBarSetPrivate::~QBarSetPrivate()
566 QBarSetPrivate::~QBarSetPrivate()
567 {
567 {
568 }
568 }
569
569
570 void QBarSetPrivate::append(QPointF value)
570 void QBarSetPrivate::append(QPointF value)
571 {
571 {
572 if (isValidValue(value)) {
572 if (isValidValue(value)) {
573 m_values.append(value);
573 m_values.append(value);
574 emit restructuredBars();
574 emit restructuredBars();
575 }
575 }
576 }
576 }
577
577
578 void QBarSetPrivate::append(QList<QPointF> values)
578 void QBarSetPrivate::append(QList<QPointF> values)
579 {
579 {
580 for (int i = 0; i < values.count(); i++) {
580 for (int i = 0; i < values.count(); i++) {
581 if (isValidValue(values.at(i)))
581 if (isValidValue(values.at(i)))
582 m_values.append(values.at(i));
582 m_values.append(values.at(i));
583 }
583 }
584 emit restructuredBars();
584 emit restructuredBars();
585 }
585 }
586
586
587 void QBarSetPrivate::append(QList<qreal> values)
587 void QBarSetPrivate::append(QList<qreal> values)
588 {
588 {
589 int index = m_values.count();
589 int index = m_values.count();
590 for (int i = 0; i < values.count(); i++) {
590 for (int i = 0; i < values.count(); i++) {
591 if (isValidValue(values.at(i))) {
591 if (isValidValue(values.at(i))) {
592 m_values.append(QPointF(index, values.at(i)));
592 m_values.append(QPointF(index, values.at(i)));
593 index++;
593 index++;
594 }
594 }
595 }
595 }
596 emit restructuredBars();
596 emit restructuredBars();
597 }
597 }
598
598
599 void QBarSetPrivate::insert(const int index, const qreal value)
599 void QBarSetPrivate::insert(const int index, const qreal value)
600 {
600 {
601 m_values.insert(index, QPointF(index, value));
601 m_values.insert(index, QPointF(index, value));
602 emit restructuredBars();
602 emit restructuredBars();
603 }
603 }
604
604
605 void QBarSetPrivate::insert(const int index, const QPointF value)
605 void QBarSetPrivate::insert(const int index, const QPointF value)
606 {
606 {
607 m_values.insert(index, value);
607 m_values.insert(index, value);
608 emit restructuredBars();
608 emit restructuredBars();
609 }
609 }
610
610
611 int QBarSetPrivate::remove(const int index, const int count)
611 int QBarSetPrivate::remove(const int index, const int count)
612 {
612 {
613 int removeCount = count;
613 int removeCount = count;
614
614
615 if ((index < 0) || (m_values.count() == 0))
615 if ((index < 0) || (m_values.count() == 0))
616 return 0; // Invalid index or not values in list, remove nothing.
616 return 0; // Invalid index or not values in list, remove nothing.
617 else if ((index + count) > m_values.count())
617 else if ((index + count) > m_values.count())
618 removeCount = m_values.count() - index; // Trying to remove more items than list has. Limit amount to be removed.
618 removeCount = m_values.count() - index; // Trying to remove more items than list has. Limit amount to be removed.
619
619
620 int c = 0;
620 int c = 0;
621 while (c < removeCount) {
621 while (c < removeCount) {
622 m_values.removeAt(index);
622 m_values.removeAt(index);
623 c++;
623 c++;
624 }
624 }
625 emit restructuredBars();
625 emit restructuredBars();
626 return removeCount;
626 return removeCount;
627 }
627 }
628
628
629 void QBarSetPrivate::replace(const int index, const qreal value)
629 void QBarSetPrivate::replace(const int index, const qreal value)
630 {
630 {
631 m_values.replace(index, QPointF(index, value));
631 m_values.replace(index, QPointF(index, value));
632 emit updatedLayout();
632 emit updatedLayout();
633 }
633 }
634
634
635 void QBarSetPrivate::replace(const int index, const QPointF value)
635 void QBarSetPrivate::replace(const int index, const QPointF value)
636 {
636 {
637 m_values.replace(index, value);
637 m_values.replace(index, value);
638 emit updatedLayout();
638 emit updatedLayout();
639 }
639 }
640
640
641 qreal QBarSetPrivate::pos(const int index)
641 qreal QBarSetPrivate::pos(const int index)
642 {
642 {
643 if (index < 0 || index >= m_values.count())
643 if (index < 0 || index >= m_values.count())
644 return 0;
644 return 0;
645 return m_values.at(index).x();
645 return m_values.at(index).x();
646 }
646 }
647
647
648 qreal QBarSetPrivate::value(const int index)
648 qreal QBarSetPrivate::value(const int index)
649 {
649 {
650 if (index < 0 || index >= m_values.count())
650 if (index < 0 || index >= m_values.count())
651 return 0;
651 return 0;
652 return m_values.at(index).y();
652 return m_values.at(index).y();
653 }
653 }
654
654
655 #include "moc_qbarset.cpp"
655 #include "moc_qbarset.cpp"
656 #include "moc_qbarset_p.cpp"
656 #include "moc_qbarset_p.cpp"
657
657
658 QTCOMMERCIALCHART_END_NAMESPACE
658 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,249 +1,253
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qhbarmodelmapper.h"
21 #include "qhbarmodelmapper.h"
22
22
23 QTCOMMERCIALCHART_BEGIN_NAMESPACE
23 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24
24
25 /*!
25 /*!
26 \class QHBarModelMapper
26 \class QHBarModelMapper
27 \brief Horizontal model mapper for bar series
27 \brief Horizontal model mapper for bar series.
28 \mainclass
28 \mainclass
29
29
30 Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series.
30 Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series.
31 Horizontal model mapper is used to create a connection between QAbstractBarSeries and QAbstractItemModel derived model object.
31 Horizontal model mapper is used to create a connection between QAbstractBarSeries and QAbstractItemModel derived model object.
32 Model mapper maintains equal size of all the BarSets.
32 Model mapper maintains equal size of all the BarSets.
33 Adding/removing value from the BarSet causes the the same change in the rest of the BarSets added to the same series.
33 Adding/removing value from the BarSet causes the the same change in the rest of the BarSets added to the same series.
34 \note Used model has to support adding/removing rows/columns and modifying the data of the cells.
34 \note Used model has to support adding/removing rows/columns and modifying the data of the cells.
35 */
35 */
36 /*!
36 /*!
37 \qmlclass HBarModelMapper QHBarModelMapper
37 \qmlclass HBarModelMapper QHBarModelMapper
38
38
39 HBarModelMapper allows you to use your own QAbstractItemModel derived model with data in rows as a data source
39 HBarModelMapper allows you to use your own QAbstractItemModel derived model with data in rows as a data source
40 for any bar series. It is possible to use both QAbstractItemModel and bar series data API to manipulate data.
40 for any bar series. It is possible to use both QAbstractItemModel and bar series data API to manipulate data.
41 HBarModelMapper keeps the series and the model in sync.
41 HBarModelMapper keeps the series and the model in sync.
42
42
43 The following QML example would create a bar series with three bar sets (assuming the model has
43 The following QML example would create a bar series with three bar sets (assuming the model has
44 at least four rows). Each bar set would contain data starting from column 1. The name of a set would be defined by
44 at least four rows). Each bar set would contain data starting from column 1. The name of a set would be defined by
45 the vertical header (of the row).
45 the vertical header (of the row).
46 \code
46 \code
47 BarSeries {
47 BarSeries {
48 HBarModelMapper {
48 HBarModelMapper {
49 model: myCustomModel // QAbstractItemModel derived implementation
49 model: myCustomModel // QAbstractItemModel derived implementation
50 firstBarSetRow: 1
50 firstBarSetRow: 1
51 lastBarSetRow: 3
51 lastBarSetRow: 3
52 firstColumn: 1
52 firstColumn: 1
53 }
53 }
54 }
54 }
55 \endcode
55 \endcode
56 */
56 */
57
57
58 /*!
58 /*!
59 \property QHBarModelMapper::series
59 \property QHBarModelMapper::series
60 \brief Defines the QPieSeries object that is used by the mapper.
60 \brief Defines the QPieSeries object that is used by the mapper.
61
61
62 All the data in the series is discarded when it is set to the mapper.
62 All the data in the series is discarded when it is set to the mapper.
63 When new series is specified the old series is disconnected (it preserves its data)
63 When new series is specified the old series is disconnected (it preserves its data)
64 */
64 */
65 /*!
65 /*!
66 \qmlproperty AbstractBarSeries HBarModelMapper::series
66 \qmlproperty AbstractBarSeries HBarModelMapper::series
67 Defines the AbstractBarSeries based object that is used by the mapper. All the data in the series is discarded when it is
67 Defines the AbstractBarSeries based object that is used by the mapper. All the data in the series is discarded when it is
68 set to the mapper. When new series is specified the old series is disconnected (it preserves its data).
68 set to the mapper. When new series is specified the old series is disconnected (it preserves its data).
69 */
69 */
70
70
71 /*!
71 /*!
72 \property QHBarModelMapper::model
72 \property QHBarModelMapper::model
73 \brief Defines the model that is used by the mapper.
73 \brief Defines the model that is used by the mapper.
74 */
74 */
75 /*!
75 /*!
76 \qmlproperty SomeModel HBarModelMapper::model
76 \qmlproperty SomeModel HBarModelMapper::model
77 The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to
77 The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to
78 QML as shown in \l {QML Custom Model} demo application. Note: the model has to support adding/removing rows/columns
78 QML as shown in \l {QML Custom Model} demo application. Note: the model has to support adding/removing rows/columns
79 and modifying the data of the cells.
79 and modifying the data of the cells.
80 */
80 */
81
81
82 /*!
82 /*!
83 \property QHBarModelMapper::firstBarSetRow
83 \property QHBarModelMapper::firstBarSetRow
84 \brief Defines which column of the model is used as the data source for the first bar set
84 \brief Defines which column of the model is used as the data source for the first bar set.
85
85 Default value is: -1 (invalid mapping)
86 Default value is: -1 (invalid mapping)
86 */
87 */
87 /*!
88 /*!
88 \qmlproperty int HBarModelMapper::firstBarSetRow
89 \qmlproperty int HBarModelMapper::firstBarSetRow
89 Defines which column of the model is used as the data source for the first bar set. The default value is -1
90 Defines which column of the model is used as the data source for the first bar set. The default value is -1
90 (invalid mapping).
91 (invalid mapping).
91 */
92 */
92
93
93 /*!
94 /*!
94 \property QHBarModelMapper::lastBarSetRow
95 \property QHBarModelMapper::lastBarSetRow
95 \brief Defines which column of the model is used as the data source for the last bar set
96 \brief Defines which column of the model is used as the data source for the last bar set.
97
96 Default value is: -1 (invalid mapping)
98 Default value is: -1 (invalid mapping)
97 */
99 */
98 /*!
100 /*!
99 \qmlproperty int HBarModelMapper::lastBarSetRow
101 \qmlproperty int HBarModelMapper::lastBarSetRow
100 Defines which column of the model is used as the data source for the last bar set. The default value is -1
102 Defines which column of the model is used as the data source for the last bar set. The default value is -1
101 (invalid mapping).
103 (invalid mapping).
102 */
104 */
103
105
104 /*!
106 /*!
105 \property QHBarModelMapper::firstColumn
107 \property QHBarModelMapper::firstColumn
106 \brief Defines which column of the model contains the first values of the QBarSets in the series.
108 \brief Defines which column of the model contains the first values of the QBarSets in the series.
109
107 Minimal and default value is: 0
110 Minimal and default value is: 0
108 */
111 */
109 /*!
112 /*!
110 \qmlproperty int HBarModelMapper::firstColumn
113 \qmlproperty int HBarModelMapper::firstColumn
111 Defines which column of the model contains the first values of the QBarSets in the series.
114 Defines which column of the model contains the first values of the QBarSets in the series.
112 The default value is 0.
115 The default value is 0.
113 */
116 */
114
117
115 /*!
118 /*!
116 \property QHBarModelMapper::columnCount
119 \property QHBarModelMapper::columnCount
117 \brief Defines the number of columns of the model that are mapped as the data for QAbstractBarSeries
120 \brief Defines the number of columns of the model that are mapped as the data for QAbstractBarSeries.
121
118 Minimal and default value is: -1 (count limited by the number of columns in the model)
122 Minimal and default value is: -1 (count limited by the number of columns in the model)
119 */
123 */
120 /*!
124 /*!
121 \qmlproperty int HBarModelMapper::columnCount
125 \qmlproperty int HBarModelMapper::columnCount
122 Defines the number of columns of the model that are mapped as the data for QAbstractBarSeries. The default value is
126 Defines the number of columns of the model that are mapped as the data for QAbstractBarSeries. The default value is
123 -1 (count limited by the number of columns in the model)
127 -1 (count limited by the number of columns in the model)
124 */
128 */
125
129
126 /*!
130 /*!
127 \fn void QHBarModelMapper::seriesReplaced()
131 \fn void QHBarModelMapper::seriesReplaced()
128
132
129 Emitted when the series to which mapper is connected to has changed.
133 Emitted when the series to which mapper is connected to has changed.
130 */
134 */
131
135
132 /*!
136 /*!
133 \fn void QHBarModelMapper::modelReplaced()
137 \fn void QHBarModelMapper::modelReplaced()
134
138
135 Emitted when the model to which mapper is connected to has changed.
139 Emitted when the model to which mapper is connected to has changed.
136 */
140 */
137
141
138 /*!
142 /*!
139 \fn void QHBarModelMapper::firstBarSetRowChanged()
143 \fn void QHBarModelMapper::firstBarSetRowChanged()
140
144
141 Emitted when the firstBarSetRow has changed.
145 Emitted when the firstBarSetRow has changed.
142 */
146 */
143
147
144 /*!
148 /*!
145 \fn void QHBarModelMapper::lastBarSetRowChanged()
149 \fn void QHBarModelMapper::lastBarSetRowChanged()
146
150
147 Emitted when the lastBarSetRow has changed.
151 Emitted when the lastBarSetRow has changed.
148 */
152 */
149
153
150 /*!
154 /*!
151 \fn void QHBarModelMapper::firstColumnChanged()
155 \fn void QHBarModelMapper::firstColumnChanged()
152 Emitted when the firstColumn has changed.
156 Emitted when the firstColumn has changed.
153 */
157 */
154
158
155 /*!
159 /*!
156 \fn void QHBarModelMapper::columnCountChanged()
160 \fn void QHBarModelMapper::columnCountChanged()
157 Emitted when the columnCount has changed.
161 Emitted when the columnCount has changed.
158 */
162 */
159
163
160 /*!
164 /*!
161 Constructs a mapper object which is a child of \a parent.
165 Constructs a mapper object which is a child of \a parent.
162 */
166 */
163 QHBarModelMapper::QHBarModelMapper(QObject *parent) :
167 QHBarModelMapper::QHBarModelMapper(QObject *parent) :
164 QBarModelMapper(parent)
168 QBarModelMapper(parent)
165 {
169 {
166 QBarModelMapper::setOrientation(Qt::Horizontal);
170 QBarModelMapper::setOrientation(Qt::Horizontal);
167 }
171 }
168
172
169 QAbstractItemModel *QHBarModelMapper::model() const
173 QAbstractItemModel *QHBarModelMapper::model() const
170 {
174 {
171 return QBarModelMapper::model();
175 return QBarModelMapper::model();
172 }
176 }
173
177
174 void QHBarModelMapper::setModel(QAbstractItemModel *model)
178 void QHBarModelMapper::setModel(QAbstractItemModel *model)
175 {
179 {
176 if (model != QBarModelMapper::model()) {
180 if (model != QBarModelMapper::model()) {
177 QBarModelMapper::setModel(model);
181 QBarModelMapper::setModel(model);
178 emit modelReplaced();
182 emit modelReplaced();
179 }
183 }
180 }
184 }
181
185
182 QAbstractBarSeries *QHBarModelMapper::series() const
186 QAbstractBarSeries *QHBarModelMapper::series() const
183 {
187 {
184 return QBarModelMapper::series();
188 return QBarModelMapper::series();
185 }
189 }
186
190
187 void QHBarModelMapper::setSeries(QAbstractBarSeries *series)
191 void QHBarModelMapper::setSeries(QAbstractBarSeries *series)
188 {
192 {
189 if (series != QBarModelMapper::series()) {
193 if (series != QBarModelMapper::series()) {
190 QBarModelMapper::setSeries(series);
194 QBarModelMapper::setSeries(series);
191 emit seriesReplaced();
195 emit seriesReplaced();
192 }
196 }
193 }
197 }
194
198
195 int QHBarModelMapper::firstBarSetRow() const
199 int QHBarModelMapper::firstBarSetRow() const
196 {
200 {
197 return QBarModelMapper::firstBarSetSection();
201 return QBarModelMapper::firstBarSetSection();
198 }
202 }
199
203
200 void QHBarModelMapper::setFirstBarSetRow(int firstBarSetRow)
204 void QHBarModelMapper::setFirstBarSetRow(int firstBarSetRow)
201 {
205 {
202 if (firstBarSetRow != firstBarSetSection()) {
206 if (firstBarSetRow != firstBarSetSection()) {
203 QBarModelMapper::setFirstBarSetSection(firstBarSetRow);
207 QBarModelMapper::setFirstBarSetSection(firstBarSetRow);
204 emit firstBarSetRowChanged();
208 emit firstBarSetRowChanged();
205 }
209 }
206 }
210 }
207
211
208 int QHBarModelMapper::lastBarSetRow() const
212 int QHBarModelMapper::lastBarSetRow() const
209 {
213 {
210 return QBarModelMapper::lastBarSetSection();
214 return QBarModelMapper::lastBarSetSection();
211 }
215 }
212
216
213 void QHBarModelMapper::setLastBarSetRow(int lastBarSetRow)
217 void QHBarModelMapper::setLastBarSetRow(int lastBarSetRow)
214 {
218 {
215 if (lastBarSetRow != lastBarSetSection()) {
219 if (lastBarSetRow != lastBarSetSection()) {
216 QBarModelMapper::setLastBarSetSection(lastBarSetRow);
220 QBarModelMapper::setLastBarSetSection(lastBarSetRow);
217 emit lastBarSetRowChanged();
221 emit lastBarSetRowChanged();
218 }
222 }
219 }
223 }
220
224
221 int QHBarModelMapper::firstColumn() const
225 int QHBarModelMapper::firstColumn() const
222 {
226 {
223 return QBarModelMapper::first();
227 return QBarModelMapper::first();
224 }
228 }
225
229
226 void QHBarModelMapper::setFirstColumn(int firstColumn)
230 void QHBarModelMapper::setFirstColumn(int firstColumn)
227 {
231 {
228 if (firstColumn != first()) {
232 if (firstColumn != first()) {
229 QBarModelMapper::setFirst(firstColumn);
233 QBarModelMapper::setFirst(firstColumn);
230 emit firstColumnChanged();
234 emit firstColumnChanged();
231 }
235 }
232 }
236 }
233
237
234 int QHBarModelMapper::columnCount() const
238 int QHBarModelMapper::columnCount() const
235 {
239 {
236 return QBarModelMapper::count();
240 return QBarModelMapper::count();
237 }
241 }
238
242
239 void QHBarModelMapper::setColumnCount(int columnCount)
243 void QHBarModelMapper::setColumnCount(int columnCount)
240 {
244 {
241 if (columnCount != count()) {
245 if (columnCount != count()) {
242 QBarModelMapper::setCount(columnCount);
246 QBarModelMapper::setCount(columnCount);
243 emit columnCountChanged();
247 emit columnCountChanged();
244 }
248 }
245 }
249 }
246
250
247 #include "moc_qhbarmodelmapper.cpp"
251 #include "moc_qhbarmodelmapper.cpp"
248
252
249 QTCOMMERCIALCHART_END_NAMESPACE
253 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,248 +1,252
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qvbarmodelmapper.h"
21 #include "qvbarmodelmapper.h"
22
22
23 QTCOMMERCIALCHART_BEGIN_NAMESPACE
23 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24
24
25 /*!
25 /*!
26 \class QVBarModelMapper
26 \class QVBarModelMapper
27 \brief Vertical model mapper for bar series
27 \brief Vertical model mapper for bar series.
28 \mainclass
28 \mainclass
29
29
30 Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series.
30 Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series.
31 Vertical model mapper is used to create a connection between QAbstractBarSeries and QAbstractItemModel derived model object.
31 Vertical model mapper is used to create a connection between QAbstractBarSeries and QAbstractItemModel derived model object.
32 Model mapper maintains equal size of all the BarSets.
32 Model mapper maintains equal size of all the BarSets.
33 Adding/removing value from the BarSet causes the the same change in the rest of the BarSets added to the same series.
33 Adding/removing value from the BarSet causes the the same change in the rest of the BarSets added to the same series.
34 \note Used model has to support adding/removing rows/columns and modifying the data of the cells.
34 \note Used model has to support adding/removing rows/columns and modifying the data of the cells.
35 */
35 */
36 /*!
36 /*!
37 \qmlclass VBarModelMapper
37 \qmlclass VBarModelMapper
38 \mainclass
38 \mainclass
39
39
40 VBarModelMapper allows you to use your own QAbstractItemModel derived model with data in columns as a data source
40 VBarModelMapper allows you to use your own QAbstractItemModel derived model with data in columns as a data source
41 for any bar series. It is possible to use both QAbstractItemModel and bar series data API to manipulate data.
41 for any bar series. It is possible to use both QAbstractItemModel and bar series data API to manipulate data.
42 VBarModelMapper keeps the series and the model in sync.
42 VBarModelMapper keeps the series and the model in sync.
43
43
44 The following QML example would create a bar series with three bar sets (assuming the
44 The following QML example would create a bar series with three bar sets (assuming the
45 model has at least four columns). Each bar set would contain data starting from row 1. The name of a set would be
45 model has at least four columns). Each bar set would contain data starting from row 1. The name of a set would be
46 defined by the horizontal header (of the column).
46 defined by the horizontal header (of the column).
47 \code
47 \code
48 BarSeries {
48 BarSeries {
49 VBarModelMapper {
49 VBarModelMapper {
50 model: myCustomModel // QAbstractItemModel derived implementation
50 model: myCustomModel // QAbstractItemModel derived implementation
51 firstBarSetColumn: 1
51 firstBarSetColumn: 1
52 lastBarSetColumn: 3
52 lastBarSetColumn: 3
53 firstRow: 1
53 firstRow: 1
54 }
54 }
55 }
55 }
56 \endcode
56 \endcode
57 */
57 */
58
58
59 /*!
59 /*!
60 \property QVBarModelMapper::series
60 \property QVBarModelMapper::series
61 \brief Defines the QPieSeries object that is used by the mapper.
61 \brief Defines the QPieSeries object that is used by the mapper.
62
62
63 All the data in the series is discarded when it is set to the mapper.
63 All the data in the series is discarded when it is set to the mapper.
64 When new series is specified the old series is disconnected (it preserves its data)
64 When new series is specified the old series is disconnected (it preserves its data)
65 */
65 */
66 /*!
66 /*!
67 \qmlproperty AbstractBarSeries VBarModelMapper::series
67 \qmlproperty AbstractBarSeries VBarModelMapper::series
68 Defines the AbstractBarSeries based object that is used by the mapper. All the data in the series is discarded when it is
68 Defines the AbstractBarSeries based object that is used by the mapper. All the data in the series is discarded when it is
69 set to the mapper. When new series is specified the old series is disconnected (it preserves its data).
69 set to the mapper. When new series is specified the old series is disconnected (it preserves its data).
70 */
70 */
71
71
72 /*!
72 /*!
73 \property QVBarModelMapper::model
73 \property QVBarModelMapper::model
74 \brief Defines the model that is used by the mapper.
74 \brief Defines the model that is used by the mapper.
75 */
75 */
76 /*!
76 /*!
77 \qmlproperty SomeModel VBarModelMapper::model
77 \qmlproperty SomeModel VBarModelMapper::model
78 The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to
78 The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to
79 QML as shown in \l {QML Custom Model} demo application. Note: the model has to support adding/removing rows/columns
79 QML as shown in \l {QML Custom Model} demo application. Note: the model has to support adding/removing rows/columns
80 and modifying the data of the cells.
80 and modifying the data of the cells.
81 */
81 */
82
82
83 /*!
83 /*!
84 \property QVBarModelMapper::firstBarSetColumn
84 \property QVBarModelMapper::firstBarSetColumn
85 \brief Defines which column of the model is used as the data source for the first bar set
85 \brief Defines which column of the model is used as the data source for the first bar set.
86
86 Default value is: -1 (invalid mapping)
87 Default value is: -1 (invalid mapping)
87 */
88 */
88 /*!
89 /*!
89 \qmlproperty int VBarModelMapper::firstBarSetColumn
90 \qmlproperty int VBarModelMapper::firstBarSetColumn
90 Defines which column of the model is used as the data source for the first bar set. Default value
91 Defines which column of the model is used as the data source for the first bar set. Default value
91 is: -1 (invalid mapping).
92 is: -1 (invalid mapping).
92 */
93 */
93
94
94 /*!
95 /*!
95 \property QVBarModelMapper::lastBarSetColumn
96 \property QVBarModelMapper::lastBarSetColumn
96 \brief Defines which column of the model is used as the data source for the last bar set
97 \brief Defines which column of the model is used as the data source for the last bar set.
98
97 Default value is: -1 (invalid mapping)
99 Default value is: -1 (invalid mapping)
98 */
100 */
99 /*!
101 /*!
100 \qmlproperty int VBarModelMapper::lastBarSetColumn
102 \qmlproperty int VBarModelMapper::lastBarSetColumn
101 Defines which column of the model is used as the data source for the last bar set. Default
103 Defines which column of the model is used as the data source for the last bar set. Default
102 value is: -1 (invalid mapping).
104 value is: -1 (invalid mapping).
103 */
105 */
104
106
105 /*!
107 /*!
106 \property QVBarModelMapper::firstRow
108 \property QVBarModelMapper::firstRow
107 \brief Defines which row of the model contains the first values of the QBarSets in the series.
109 \brief Defines which row of the model contains the first values of the QBarSets in the series.
110
108 Minimal and default value is: 0
111 Minimal and default value is: 0
109 */
112 */
110 /*!
113 /*!
111 \qmlproperty int VBarModelMapper::firstRow
114 \qmlproperty int VBarModelMapper::firstRow
112 Defines which row of the model contains the first values of the QBarSets in the series.
115 Defines which row of the model contains the first values of the QBarSets in the series.
113 The default value is 0.
116 The default value is 0.
114 */
117 */
115
118
116 /*!
119 /*!
117 \property QVBarModelMapper::rowCount
120 \property QVBarModelMapper::rowCount
118 \brief Defines the number of rows of the model that are mapped as the data for QAbstractBarSeries
121 \brief Defines the number of rows of the model that are mapped as the data for QAbstractBarSeries.
122
119 Minimal and default value is: -1 (count limited by the number of rows in the model)
123 Minimal and default value is: -1 (count limited by the number of rows in the model)
120 */
124 */
121 /*!
125 /*!
122 \qmlproperty int VBarModelMapper::rowCount
126 \qmlproperty int VBarModelMapper::rowCount
123 Defines the number of rows of the model that are mapped as the data for QAbstractBarSeries. The default value is
127 Defines the number of rows of the model that are mapped as the data for QAbstractBarSeries. The default value is
124 -1 (count limited by the number of rows in the model)
128 -1 (count limited by the number of rows in the model)
125 */
129 */
126
130
127 /*!
131 /*!
128 \fn void QVBarModelMapper::seriesReplaced()
132 \fn void QVBarModelMapper::seriesReplaced()
129
133
130 Emitted when the series to which mapper is connected to has changed.
134 Emitted when the series to which mapper is connected to has changed.
131 */
135 */
132
136
133 /*!
137 /*!
134 \fn void QVBarModelMapper::modelReplaced()
138 \fn void QVBarModelMapper::modelReplaced()
135
139
136 Emitted when the model to which mapper is connected to has changed.
140 Emitted when the model to which mapper is connected to has changed.
137 */
141 */
138
142
139 /*!
143 /*!
140 \fn void QVBarModelMapper::firstBarSetColumnChanged()
144 \fn void QVBarModelMapper::firstBarSetColumnChanged()
141 Emitted when the firstBarSetColumn has changed.
145 Emitted when the firstBarSetColumn has changed.
142 */
146 */
143
147
144 /*!
148 /*!
145 \fn void QVBarModelMapper::lastBarSetColumnChanged()
149 \fn void QVBarModelMapper::lastBarSetColumnChanged()
146 Emitted when the lastBarSetColumn has changed.
150 Emitted when the lastBarSetColumn has changed.
147 */
151 */
148
152
149 /*!
153 /*!
150 \fn void QVBarModelMapper::firstRowChanged()
154 \fn void QVBarModelMapper::firstRowChanged()
151 Emitted when the firstRow has changed.
155 Emitted when the firstRow has changed.
152 */
156 */
153
157
154 /*!
158 /*!
155 \fn void QVBarModelMapper::rowCountChanged()
159 \fn void QVBarModelMapper::rowCountChanged()
156 Emitted when the rowCount has changed.
160 Emitted when the rowCount has changed.
157 */
161 */
158
162
159 /*!
163 /*!
160 Constructs a mapper object which is a child of \a parent.
164 Constructs a mapper object which is a child of \a parent.
161 */
165 */
162 QVBarModelMapper::QVBarModelMapper(QObject *parent) :
166 QVBarModelMapper::QVBarModelMapper(QObject *parent) :
163 QBarModelMapper(parent)
167 QBarModelMapper(parent)
164 {
168 {
165 QBarModelMapper::setOrientation(Qt::Vertical);
169 QBarModelMapper::setOrientation(Qt::Vertical);
166 }
170 }
167
171
168 QAbstractItemModel *QVBarModelMapper::model() const
172 QAbstractItemModel *QVBarModelMapper::model() const
169 {
173 {
170 return QBarModelMapper::model();
174 return QBarModelMapper::model();
171 }
175 }
172
176
173 void QVBarModelMapper::setModel(QAbstractItemModel *model)
177 void QVBarModelMapper::setModel(QAbstractItemModel *model)
174 {
178 {
175 if (model != QBarModelMapper::model()) {
179 if (model != QBarModelMapper::model()) {
176 QBarModelMapper::setModel(model);
180 QBarModelMapper::setModel(model);
177 emit modelReplaced();
181 emit modelReplaced();
178 }
182 }
179 }
183 }
180
184
181 QAbstractBarSeries *QVBarModelMapper::series() const
185 QAbstractBarSeries *QVBarModelMapper::series() const
182 {
186 {
183 return QBarModelMapper::series();
187 return QBarModelMapper::series();
184 }
188 }
185
189
186 void QVBarModelMapper::setSeries(QAbstractBarSeries *series)
190 void QVBarModelMapper::setSeries(QAbstractBarSeries *series)
187 {
191 {
188 if (series != QBarModelMapper::series()) {
192 if (series != QBarModelMapper::series()) {
189 QBarModelMapper::setSeries(series);
193 QBarModelMapper::setSeries(series);
190 emit seriesReplaced();
194 emit seriesReplaced();
191 }
195 }
192 }
196 }
193
197
194 int QVBarModelMapper::firstBarSetColumn() const
198 int QVBarModelMapper::firstBarSetColumn() const
195 {
199 {
196 return QBarModelMapper::firstBarSetSection();
200 return QBarModelMapper::firstBarSetSection();
197 }
201 }
198
202
199 void QVBarModelMapper::setFirstBarSetColumn(int firstBarSetColumn)
203 void QVBarModelMapper::setFirstBarSetColumn(int firstBarSetColumn)
200 {
204 {
201 if (firstBarSetColumn != firstBarSetSection()) {
205 if (firstBarSetColumn != firstBarSetSection()) {
202 QBarModelMapper::setFirstBarSetSection(firstBarSetColumn);
206 QBarModelMapper::setFirstBarSetSection(firstBarSetColumn);
203 emit firstBarSetColumnChanged();
207 emit firstBarSetColumnChanged();
204 }
208 }
205 }
209 }
206
210
207 int QVBarModelMapper::lastBarSetColumn() const
211 int QVBarModelMapper::lastBarSetColumn() const
208 {
212 {
209 return QBarModelMapper::lastBarSetSection();
213 return QBarModelMapper::lastBarSetSection();
210 }
214 }
211
215
212 void QVBarModelMapper::setLastBarSetColumn(int lastBarSetColumn)
216 void QVBarModelMapper::setLastBarSetColumn(int lastBarSetColumn)
213 {
217 {
214 if (lastBarSetColumn != lastBarSetSection()) {
218 if (lastBarSetColumn != lastBarSetSection()) {
215 QBarModelMapper::setLastBarSetSection(lastBarSetColumn);
219 QBarModelMapper::setLastBarSetSection(lastBarSetColumn);
216 emit lastBarSetColumnChanged();
220 emit lastBarSetColumnChanged();
217 }
221 }
218 }
222 }
219
223
220 int QVBarModelMapper::firstRow() const
224 int QVBarModelMapper::firstRow() const
221 {
225 {
222 return QBarModelMapper::first();
226 return QBarModelMapper::first();
223 }
227 }
224
228
225 void QVBarModelMapper::setFirstRow(int firstRow)
229 void QVBarModelMapper::setFirstRow(int firstRow)
226 {
230 {
227 if (firstRow != first()) {
231 if (firstRow != first()) {
228 QBarModelMapper::setFirst(firstRow);
232 QBarModelMapper::setFirst(firstRow);
229 emit firstRowChanged();
233 emit firstRowChanged();
230 }
234 }
231 }
235 }
232
236
233 int QVBarModelMapper::rowCount() const
237 int QVBarModelMapper::rowCount() const
234 {
238 {
235 return QBarModelMapper::count();
239 return QBarModelMapper::count();
236 }
240 }
237
241
238 void QVBarModelMapper::setRowCount(int rowCount)
242 void QVBarModelMapper::setRowCount(int rowCount)
239 {
243 {
240 if (rowCount != count()) {
244 if (rowCount != count()) {
241 QBarModelMapper::setCount(rowCount);
245 QBarModelMapper::setCount(rowCount);
242 emit rowCountChanged();
246 emit rowCountChanged();
243 }
247 }
244 }
248 }
245
249
246 #include "moc_qvbarmodelmapper.cpp"
250 #include "moc_qvbarmodelmapper.cpp"
247
251
248 QTCOMMERCIALCHART_END_NAMESPACE
252 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,119 +1,119
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qbarseries.h"
21 #include "qbarseries.h"
22 #include "qbarseries_p.h"
22 #include "qbarseries_p.h"
23 #include "barchartitem_p.h"
23 #include "barchartitem_p.h"
24 #include "chartdataset_p.h"
24 #include "chartdataset_p.h"
25 #include "charttheme_p.h"
25 #include "charttheme_p.h"
26 #include "qvalueaxis.h"
26 #include "qvalueaxis.h"
27 #include "qbarcategoryaxis.h"
27 #include "qbarcategoryaxis.h"
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
30
31 /*!
31 /*!
32 \class QBarSeries
32 \class QBarSeries
33 \brief Series for creating bar chart
33 \brief Series for creating bar chart.
34 \mainclass
34 \mainclass
35
35
36 QBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars
36 QBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars
37 as groups, where bars in same category are grouped next to each other. QBarSeries groups the data
37 as groups, where bars in same category are grouped next to each other. QBarSeries groups the data
38 from sets to categories, which are defined by a QStringList.
38 from sets to categories, which are defined by a QStringList.
39
39
40 See the \l {BarChart Example} {bar chart example} to learn how to create a grouped bar chart.
40 See the \l {BarChart Example} {bar chart example} to learn how to create a grouped bar chart.
41 \image examples_barchart.png
41 \image examples_barchart.png
42
42
43 \sa QBarSet, QPercentBarSeries, QAbstractBarSeries, QStackedBarSeries
43 \sa QBarSet, QPercentBarSeries, QAbstractBarSeries, QStackedBarSeries
44 */
44 */
45 /*!
45 /*!
46 \qmlclass BarSeries QBarSeries
46 \qmlclass BarSeries QBarSeries
47 \inherits AbstractBarSeries
47 \inherits AbstractBarSeries
48
48
49 The following QML shows how to create a simple grouped bar chart:
49 The following QML shows how to create a simple grouped bar chart:
50 \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1
50 \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1
51 \beginfloatleft
51 \beginfloatleft
52 \image demos_qmlchart6.png
52 \image demos_qmlchart6.png
53 \endfloat
53 \endfloat
54 \clearfloat
54 \clearfloat
55 */
55 */
56
56
57 /*!
57 /*!
58 Constructs empty QBarSeries.
58 Constructs empty QBarSeries.
59 QBarSeries is QObject which is a child of a \a parent.
59 QBarSeries is QObject which is a child of a \a parent.
60 */
60 */
61 QBarSeries::QBarSeries(QObject *parent)
61 QBarSeries::QBarSeries(QObject *parent)
62 : QAbstractBarSeries(*new QBarSeriesPrivate(this), parent)
62 : QAbstractBarSeries(*new QBarSeriesPrivate(this), parent)
63 {
63 {
64
64
65 }
65 }
66
66
67 /*!
67 /*!
68 Returns QChartSeries::SeriesTypeBar.
68 Returns QAbstractSeries::SeriesTypeBar.
69 */
69 */
70 QAbstractSeries::SeriesType QBarSeries::type() const
70 QAbstractSeries::SeriesType QBarSeries::type() const
71 {
71 {
72 return QAbstractSeries::SeriesTypeBar;
72 return QAbstractSeries::SeriesTypeBar;
73 }
73 }
74
74
75 /*!
75 /*!
76 Destructor. Removes series from chart.
76 Destructor. Removes series from chart.
77 */
77 */
78 QBarSeries::~QBarSeries()
78 QBarSeries::~QBarSeries()
79 {
79 {
80 Q_D(QBarSeries);
80 Q_D(QBarSeries);
81 if (d->m_chart)
81 if (d->m_chart)
82 d->m_chart->removeSeries(this);
82 d->m_chart->removeSeries(this);
83 }
83 }
84 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
84 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
85
85
86 QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) : QAbstractBarSeriesPrivate(q)
86 QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) : QAbstractBarSeriesPrivate(q)
87 {
87 {
88
88
89 }
89 }
90
90
91 void QBarSeriesPrivate::initializeDomain()
91 void QBarSeriesPrivate::initializeDomain()
92 {
92 {
93 qreal minX(domain()->minX());
93 qreal minX(domain()->minX());
94 qreal minY(domain()->minY());
94 qreal minY(domain()->minY());
95 qreal maxX(domain()->maxX());
95 qreal maxX(domain()->maxX());
96 qreal maxY(domain()->maxY());
96 qreal maxY(domain()->maxY());
97
97
98 qreal x = categoryCount();
98 qreal x = categoryCount();
99 minX = qMin(minX, - (qreal)0.5);
99 minX = qMin(minX, - (qreal)0.5);
100 minY = qMin(minY, min());
100 minY = qMin(minY, min());
101 maxX = qMax(maxX, x - (qreal)0.5);
101 maxX = qMax(maxX, x - (qreal)0.5);
102 maxY = qMax(maxY, max());
102 maxY = qMax(maxY, max());
103
103
104 domain()->setRange(minX, maxX, minY, maxY);
104 domain()->setRange(minX, maxX, minY, maxY);
105 }
105 }
106
106
107
107
108 void QBarSeriesPrivate::initializeGraphics(QGraphicsItem* parent)
108 void QBarSeriesPrivate::initializeGraphics(QGraphicsItem* parent)
109 {
109 {
110 Q_Q(QBarSeries);
110 Q_Q(QBarSeries);
111 BarChartItem *bar = new BarChartItem(q,parent);
111 BarChartItem *bar = new BarChartItem(q,parent);
112 m_item.reset(bar);
112 m_item.reset(bar);
113 QAbstractSeriesPrivate::initializeGraphics(parent);
113 QAbstractSeriesPrivate::initializeGraphics(parent);
114 }
114 }
115
115
116 #include "moc_qbarseries.cpp"
116 #include "moc_qbarseries.cpp"
117
117
118 QTCOMMERCIALCHART_END_NAMESPACE
118 QTCOMMERCIALCHART_END_NAMESPACE
119
119
@@ -1,118 +1,118
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qpercentbarseries.h"
21 #include "qpercentbarseries.h"
22 #include "qpercentbarseries_p.h"
22 #include "qpercentbarseries_p.h"
23 #include "percentbarchartitem_p.h"
23 #include "percentbarchartitem_p.h"
24 #include "chartdataset_p.h"
24 #include "chartdataset_p.h"
25 #include "charttheme_p.h"
25 #include "charttheme_p.h"
26 #include "qvalueaxis.h"
26 #include "qvalueaxis.h"
27
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
29
30 /*!
30 /*!
31 \class QPercentBarSeries
31 \class QPercentBarSeries
32 \brief Series for creating percent bar chart
32 \brief Series for creating percent bar chart.
33 \mainclass
33 \mainclass
34
34
35 QPercentBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars
35 QPercentBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars
36 as stacks, where each bar is shown as percentage of all bars in that category.
36 as stacks, where each bar is shown as percentage of all bars in that category.
37 QPercentBarSeries groups the data from sets to categories, which are defined by a QStringList.
37 QPercentBarSeries groups the data from sets to categories, which are defined by a QStringList.
38
38
39 See the \l {PercentbarChart Example} {percent bar chart example} to learn how to create a percent bar chart.
39 See the \l {PercentbarChart Example} {percent bar chart example} to learn how to create a percent bar chart.
40 \image examples_percentbarchart.png
40 \image examples_percentbarchart.png
41
41
42 \sa QBarSet, QStackedBarSeries, QAbstractBarSeries
42 \sa QBarSet, QStackedBarSeries, QAbstractBarSeries
43 */
43 */
44 /*!
44 /*!
45 \qmlclass PercentBarSeries QPercentBarSeries
45 \qmlclass PercentBarSeries QPercentBarSeries
46 \inherits QAbstractBarSeries
46 \inherits QAbstractBarSeries
47
47
48 The following QML shows how to create a simple percent bar chart:
48 The following QML shows how to create a simple percent bar chart:
49 \snippet ../demos/qmlchart/qml/qmlchart/View8.qml 1
49 \snippet ../demos/qmlchart/qml/qmlchart/View8.qml 1
50 \beginfloatleft
50 \beginfloatleft
51 \image demos_qmlchart8.png
51 \image demos_qmlchart8.png
52 \endfloat
52 \endfloat
53 \clearfloat
53 \clearfloat
54 */
54 */
55
55
56 /*!
56 /*!
57 Constructs empty QPercentBarSeries.
57 Constructs empty QPercentBarSeries.
58 QPercentBarSeries is QObject which is a child of a \a parent.
58 QPercentBarSeries is QObject which is a child of a \a parent.
59 */
59 */
60 QPercentBarSeries::QPercentBarSeries(QObject *parent)
60 QPercentBarSeries::QPercentBarSeries(QObject *parent)
61 : QAbstractBarSeries(*new QPercentBarSeriesPrivate(this), parent)
61 : QAbstractBarSeries(*new QPercentBarSeriesPrivate(this), parent)
62 {
62 {
63 }
63 }
64
64
65 /*!
65 /*!
66 Destructor. Removes series from chart.
66 Destructor. Removes series from chart.
67 */
67 */
68 QPercentBarSeries::~QPercentBarSeries()
68 QPercentBarSeries::~QPercentBarSeries()
69 {
69 {
70 Q_D(QPercentBarSeries);
70 Q_D(QPercentBarSeries);
71 if (d->m_chart)
71 if (d->m_chart)
72 d->m_chart->removeSeries(this);
72 d->m_chart->removeSeries(this);
73 }
73 }
74
74
75 /*!
75 /*!
76 Returns QChartSeries::SeriesTypePercentBar.
76 Returns QAbstractSeries::SeriesTypePercentBar.
77 */
77 */
78 QAbstractSeries::SeriesType QPercentBarSeries::type() const
78 QAbstractSeries::SeriesType QPercentBarSeries::type() const
79 {
79 {
80 return QAbstractSeries::SeriesTypePercentBar;
80 return QAbstractSeries::SeriesTypePercentBar;
81 }
81 }
82
82
83 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
83 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
84
84
85 QPercentBarSeriesPrivate::QPercentBarSeriesPrivate(QPercentBarSeries *q) : QAbstractBarSeriesPrivate(q)
85 QPercentBarSeriesPrivate::QPercentBarSeriesPrivate(QPercentBarSeries *q) : QAbstractBarSeriesPrivate(q)
86 {
86 {
87
87
88 }
88 }
89
89
90 void QPercentBarSeriesPrivate::initializeDomain()
90 void QPercentBarSeriesPrivate::initializeDomain()
91 {
91 {
92 qreal minX(domain()->minX());
92 qreal minX(domain()->minX());
93 qreal minY(domain()->minY());
93 qreal minY(domain()->minY());
94 qreal maxX(domain()->maxX());
94 qreal maxX(domain()->maxX());
95 qreal maxY(domain()->maxY());
95 qreal maxY(domain()->maxY());
96
96
97 qreal x = categoryCount();
97 qreal x = categoryCount();
98 minX = qMin(minX, - (qreal)0.5);
98 minX = qMin(minX, - (qreal)0.5);
99 maxX = qMax(maxX, x - (qreal)0.5);
99 maxX = qMax(maxX, x - (qreal)0.5);
100 minY = 0;
100 minY = 0;
101 maxY = 100;
101 maxY = 100;
102
102
103 domain()->setRange(minX, maxX, minY, maxY);
103 domain()->setRange(minX, maxX, minY, maxY);
104 }
104 }
105
105
106
106
107 void QPercentBarSeriesPrivate::initializeGraphics(QGraphicsItem* parent)
107 void QPercentBarSeriesPrivate::initializeGraphics(QGraphicsItem* parent)
108 {
108 {
109 Q_Q(QPercentBarSeries);
109 Q_Q(QPercentBarSeries);
110 PercentBarChartItem *bar = new PercentBarChartItem(q,parent);
110 PercentBarChartItem *bar = new PercentBarChartItem(q,parent);
111 m_item.reset(bar);
111 m_item.reset(bar);
112 QAbstractSeriesPrivate::initializeGraphics(parent);
112 QAbstractSeriesPrivate::initializeGraphics(parent);
113 }
113 }
114
114
115 #include "moc_qpercentbarseries.cpp"
115 #include "moc_qpercentbarseries.cpp"
116
116
117 QTCOMMERCIALCHART_END_NAMESPACE
117 QTCOMMERCIALCHART_END_NAMESPACE
118
118
@@ -1,117 +1,117
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qstackedbarseries.h"
21 #include "qstackedbarseries.h"
22 #include "qstackedbarseries_p.h"
22 #include "qstackedbarseries_p.h"
23 #include "stackedbarchartitem_p.h"
23 #include "stackedbarchartitem_p.h"
24 #include "chartdataset_p.h"
24 #include "chartdataset_p.h"
25 #include "charttheme_p.h"
25 #include "charttheme_p.h"
26 #include "qvalueaxis.h"
26 #include "qvalueaxis.h"
27
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
29
30 /*!
30 /*!
31 \class QStackedBarSeries
31 \class QStackedBarSeries
32 \brief Series for creating stacked bar chart
32 \brief Series for creating stacked bar chart.
33 \mainclass
33 \mainclass
34
34
35 QStackedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars
35 QStackedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars
36 as stacks, where bars in same category are stacked on top of each other.
36 as stacks, where bars in same category are stacked on top of each other.
37 QStackedBarSeries groups the data from sets to categories, which are defined by QStringList.
37 QStackedBarSeries groups the data from sets to categories, which are defined by QStringList.
38
38
39 See the \l {StackedbarChart Example} {stacked bar chart example} to learn how to create a stacked bar chart.
39 See the \l {StackedbarChart Example} {stacked bar chart example} to learn how to create a stacked bar chart.
40 \image examples_stackedbarchart.png
40 \image examples_stackedbarchart.png
41
41
42 \sa QBarSet, QPercentBarSeries, QAbstractBarSeries
42 \sa QBarSet, QPercentBarSeries, QAbstractBarSeries
43 */
43 */
44
44
45 /*!
45 /*!
46 \qmlclass StackedBarSeries QStackedBarSeries
46 \qmlclass StackedBarSeries QStackedBarSeries
47 \inherits AbstractBarSeries
47 \inherits AbstractBarSeries
48
48
49 The following QML shows how to create a simple stacked bar chart:
49 The following QML shows how to create a simple stacked bar chart:
50 \snippet ../demos/qmlchart/qml/qmlchart/View7.qml 1
50 \snippet ../demos/qmlchart/qml/qmlchart/View7.qml 1
51 \beginfloatleft
51 \beginfloatleft
52 \image demos_qmlchart7.png
52 \image demos_qmlchart7.png
53 \endfloat
53 \endfloat
54 \clearfloat
54 \clearfloat
55 */
55 */
56
56
57 /*!
57 /*!
58 Constructs empty QStackedBarSeries.
58 Constructs empty QStackedBarSeries.
59 QStackedBarSeries is QObject which is a child of a \a parent.
59 QStackedBarSeries is QObject which is a child of a \a parent.
60 */
60 */
61 QStackedBarSeries::QStackedBarSeries(QObject *parent)
61 QStackedBarSeries::QStackedBarSeries(QObject *parent)
62 : QAbstractBarSeries(*new QStackedBarSeriesPrivate(this), parent)
62 : QAbstractBarSeries(*new QStackedBarSeriesPrivate(this), parent)
63 {
63 {
64 }
64 }
65
65
66 /*!
66 /*!
67 Destructor. Removes series from chart.
67 Destructor. Removes series from chart.
68 */
68 */
69 QStackedBarSeries::~QStackedBarSeries()
69 QStackedBarSeries::~QStackedBarSeries()
70 {
70 {
71 Q_D(QStackedBarSeries);
71 Q_D(QStackedBarSeries);
72 if (d->m_chart)
72 if (d->m_chart)
73 d->m_chart->removeSeries(this);
73 d->m_chart->removeSeries(this);
74 }
74 }
75 /*!
75 /*!
76 Returns QChartSeries::SeriesTypeStackedBar.
76 Returns QAbstractSeries::SeriesTypeStackedBar.
77 */
77 */
78 QAbstractSeries::SeriesType QStackedBarSeries::type() const
78 QAbstractSeries::SeriesType QStackedBarSeries::type() const
79 {
79 {
80 return QAbstractSeries::SeriesTypeStackedBar;
80 return QAbstractSeries::SeriesTypeStackedBar;
81 }
81 }
82
82
83 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
83 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
84
84
85 QStackedBarSeriesPrivate::QStackedBarSeriesPrivate(QStackedBarSeries *q) : QAbstractBarSeriesPrivate(q)
85 QStackedBarSeriesPrivate::QStackedBarSeriesPrivate(QStackedBarSeries *q) : QAbstractBarSeriesPrivate(q)
86 {
86 {
87
87
88 }
88 }
89
89
90 void QStackedBarSeriesPrivate::initializeDomain()
90 void QStackedBarSeriesPrivate::initializeDomain()
91 {
91 {
92 qreal minX(domain()->minX());
92 qreal minX(domain()->minX());
93 qreal minY(domain()->minY());
93 qreal minY(domain()->minY());
94 qreal maxX(domain()->maxX());
94 qreal maxX(domain()->maxX());
95 qreal maxY(domain()->maxY());
95 qreal maxY(domain()->maxY());
96
96
97 qreal x = categoryCount();
97 qreal x = categoryCount();
98 minX = qMin(minX, - (qreal)0.5);
98 minX = qMin(minX, - (qreal)0.5);
99 minY = qMin(minY, bottom());
99 minY = qMin(minY, bottom());
100 maxX = qMax(maxX, x - (qreal)0.5);
100 maxX = qMax(maxX, x - (qreal)0.5);
101 maxY = qMax(maxY, top());
101 maxY = qMax(maxY, top());
102
102
103 domain()->setRange(minX, maxX, minY, maxY);
103 domain()->setRange(minX, maxX, minY, maxY);
104 }
104 }
105
105
106 void QStackedBarSeriesPrivate::initializeGraphics(QGraphicsItem* parent)
106 void QStackedBarSeriesPrivate::initializeGraphics(QGraphicsItem* parent)
107 {
107 {
108 Q_Q(QStackedBarSeries);
108 Q_Q(QStackedBarSeries);
109 StackedBarChartItem *bar = new StackedBarChartItem(q,parent);
109 StackedBarChartItem *bar = new StackedBarChartItem(q,parent);
110 m_item.reset(bar);
110 m_item.reset(bar);
111 QAbstractSeriesPrivate::initializeGraphics(parent);
111 QAbstractSeriesPrivate::initializeGraphics(parent);
112 }
112 }
113
113
114 #include "moc_qstackedbarseries.cpp"
114 #include "moc_qstackedbarseries.cpp"
115
115
116 QTCOMMERCIALCHART_END_NAMESPACE
116 QTCOMMERCIALCHART_END_NAMESPACE
117
117
@@ -1,125 +1,125
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qarealegendmarker.h"
21 #include "qarealegendmarker.h"
22 #include "qarealegendmarker_p.h"
22 #include "qarealegendmarker_p.h"
23 #include "qareaseries_p.h"
23 #include "qareaseries_p.h"
24 #include <QAreaSeries>
24 #include <QAreaSeries>
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 /*!
28 /*!
29 \class QAreaLegendMarker
29 \class QAreaLegendMarker
30 \brief QAreaLegendMarker object
30 \brief QAreaLegendMarker object.
31 \mainclass
31 \mainclass
32
32
33 QAreaLegendMarker is related to QAreaSeries. One QAreaSeries results in one marker.
33 QAreaLegendMarker is related to QAreaSeries. One QAreaSeries results in one marker.
34
34
35 \sa QLegend QAreaSeries
35 \sa QLegend QAreaSeries
36 */
36 */
37
37
38 /*!
38 /*!
39 \fn virtual LegendMarkerType QAreaLegendMarker::type()
39 \fn virtual LegendMarkerType QAreaLegendMarker::type()
40 Returns QLegendMarker::LegendMarkerTypeArea
40 Returns QLegendMarker::LegendMarkerTypeArea
41 */
41 */
42
42
43 /*!
43 /*!
44 \internal
44 \internal
45 */
45 */
46 QAreaLegendMarker::QAreaLegendMarker(QAreaSeries *series, QLegend *legend, QObject *parent) :
46 QAreaLegendMarker::QAreaLegendMarker(QAreaSeries *series, QLegend *legend, QObject *parent) :
47 QLegendMarker(*new QAreaLegendMarkerPrivate(this,series,legend), parent)
47 QLegendMarker(*new QAreaLegendMarkerPrivate(this,series,legend), parent)
48 {
48 {
49 d_ptr->updated();
49 d_ptr->updated();
50 }
50 }
51
51
52 /*!
52 /*!
53 Destructor
53 Destructor
54 */
54 */
55 QAreaLegendMarker::~QAreaLegendMarker()
55 QAreaLegendMarker::~QAreaLegendMarker()
56 {
56 {
57 }
57 }
58
58
59 /*!
59 /*!
60 \internal
60 \internal
61 */
61 */
62 QAreaLegendMarker::QAreaLegendMarker(QAreaLegendMarkerPrivate &d, QObject *parent) :
62 QAreaLegendMarker::QAreaLegendMarker(QAreaLegendMarkerPrivate &d, QObject *parent) :
63 QLegendMarker(d, parent)
63 QLegendMarker(d, parent)
64 {
64 {
65 }
65 }
66
66
67 /*!
67 /*!
68 Returns related series of marker
68 Returns related series of marker
69 */
69 */
70 QAreaSeries* QAreaLegendMarker::series()
70 QAreaSeries* QAreaLegendMarker::series()
71 {
71 {
72 Q_D(QAreaLegendMarker);
72 Q_D(QAreaLegendMarker);
73 return d->m_series;
73 return d->m_series;
74 }
74 }
75
75
76 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
76 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
77
77
78 QAreaLegendMarkerPrivate::QAreaLegendMarkerPrivate(QAreaLegendMarker *q, QAreaSeries *series, QLegend *legend) :
78 QAreaLegendMarkerPrivate::QAreaLegendMarkerPrivate(QAreaLegendMarker *q, QAreaSeries *series, QLegend *legend) :
79 QLegendMarkerPrivate(q,legend),
79 QLegendMarkerPrivate(q,legend),
80 q_ptr(q),
80 q_ptr(q),
81 m_series(series)
81 m_series(series)
82 {
82 {
83 QObject::connect(m_series->d_func(),SIGNAL(updated()), this, SLOT(updated()));
83 QObject::connect(m_series->d_func(),SIGNAL(updated()), this, SLOT(updated()));
84 QObject::connect(m_series, SIGNAL(nameChanged()), this, SLOT(updated()));
84 QObject::connect(m_series, SIGNAL(nameChanged()), this, SLOT(updated()));
85 }
85 }
86
86
87 QAreaLegendMarkerPrivate::~QAreaLegendMarkerPrivate()
87 QAreaLegendMarkerPrivate::~QAreaLegendMarkerPrivate()
88 {
88 {
89 }
89 }
90
90
91 QAreaSeries* QAreaLegendMarkerPrivate::series()
91 QAreaSeries* QAreaLegendMarkerPrivate::series()
92 {
92 {
93 return m_series;
93 return m_series;
94 }
94 }
95
95
96 QObject* QAreaLegendMarkerPrivate::relatedObject()
96 QObject* QAreaLegendMarkerPrivate::relatedObject()
97 {
97 {
98 return m_series;
98 return m_series;
99 }
99 }
100
100
101 void QAreaLegendMarkerPrivate::updated()
101 void QAreaLegendMarkerPrivate::updated()
102 {
102 {
103 bool labelChanged = false;
103 bool labelChanged = false;
104 bool brushChanged = false;
104 bool brushChanged = false;
105
105
106 if (!m_customBrush && (m_item->brush() != m_series->brush())) {
106 if (!m_customBrush && (m_item->brush() != m_series->brush())) {
107 m_item->setBrush(m_series->brush());
107 m_item->setBrush(m_series->brush());
108 brushChanged = true;
108 brushChanged = true;
109 }
109 }
110 if (!m_customLabel && (m_item->label() != m_series->name())) {
110 if (!m_customLabel && (m_item->label() != m_series->name())) {
111 m_item->setLabel(m_series->name());
111 m_item->setLabel(m_series->name());
112 labelChanged = true;
112 labelChanged = true;
113 }
113 }
114 invalidateLegend();
114 invalidateLegend();
115
115
116 if (labelChanged)
116 if (labelChanged)
117 emit q_ptr->labelChanged();
117 emit q_ptr->labelChanged();
118 if (brushChanged)
118 if (brushChanged)
119 emit q_ptr->brushChanged();
119 emit q_ptr->brushChanged();
120 }
120 }
121
121
122 #include "moc_qarealegendmarker.cpp"
122 #include "moc_qarealegendmarker.cpp"
123 #include "moc_qarealegendmarker_p.cpp"
123 #include "moc_qarealegendmarker_p.cpp"
124
124
125 QTCOMMERCIALCHART_END_NAMESPACE
125 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,145 +1,145
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qbarlegendmarker.h"
21 #include "qbarlegendmarker.h"
22 #include "qbarlegendmarker_p.h"
22 #include "qbarlegendmarker_p.h"
23 #include <QAbstractBarSeries>
23 #include <QAbstractBarSeries>
24 #include <QBarSet>
24 #include <QBarSet>
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 /*!
28 /*!
29 \class QBarLegendMarker
29 \class QBarLegendMarker
30 \brief QBarLegendMarker object
30 \brief QBarLegendMarker object.
31 \mainclass
31 \mainclass
32
32
33 QBarLegendMarker is related to QAbstractBarSeries derived classes. With bar series, each marker is related to one QBarSet.
33 QBarLegendMarker is related to QAbstractBarSeries derived classes. With bar series, each marker is related to one QBarSet.
34
34
35 \sa QLegend QAbstractBarSeries QBarSet
35 \sa QLegend QAbstractBarSeries QBarSet
36 */
36 */
37
37
38 /*!
38 /*!
39 \fn virtual LegendMarkerType QBarLegendMarker::type()
39 \fn virtual LegendMarkerType QBarLegendMarker::type()
40 Returns QLegendMarker::LegendMarkerTypeBar
40 Returns QLegendMarker::LegendMarkerTypeBar
41 */
41 */
42
42
43 /*!
43 /*!
44 \internal
44 \internal
45 Constructor
45 Constructor
46 */
46 */
47 QBarLegendMarker::QBarLegendMarker(QAbstractBarSeries *series, QBarSet *barset, QLegend *legend, QObject *parent) :
47 QBarLegendMarker::QBarLegendMarker(QAbstractBarSeries *series, QBarSet *barset, QLegend *legend, QObject *parent) :
48 QLegendMarker(*new QBarLegendMarkerPrivate(this,series,barset,legend), parent)
48 QLegendMarker(*new QBarLegendMarkerPrivate(this,series,barset,legend), parent)
49 {
49 {
50 d_ptr->updated();
50 d_ptr->updated();
51 }
51 }
52
52
53 /*!
53 /*!
54 Desturctor
54 Desturctor
55 */
55 */
56 QBarLegendMarker::~QBarLegendMarker()
56 QBarLegendMarker::~QBarLegendMarker()
57 {
57 {
58 }
58 }
59
59
60 /*!
60 /*!
61 \internal
61 \internal
62 */
62 */
63 QBarLegendMarker::QBarLegendMarker(QBarLegendMarkerPrivate &d, QObject *parent) :
63 QBarLegendMarker::QBarLegendMarker(QBarLegendMarkerPrivate &d, QObject *parent) :
64 QLegendMarker(d, parent)
64 QLegendMarker(d, parent)
65 {
65 {
66 }
66 }
67
67
68 /*!
68 /*!
69 Returns the related series of marker
69 Returns the related series of marker
70 */
70 */
71 QAbstractBarSeries *QBarLegendMarker::series()
71 QAbstractBarSeries *QBarLegendMarker::series()
72 {
72 {
73 Q_D(QBarLegendMarker);
73 Q_D(QBarLegendMarker);
74 return d->m_series;
74 return d->m_series;
75 }
75 }
76
76
77 /*!
77 /*!
78 Returns the related barset of marker
78 Returns the related barset of marker
79 */
79 */
80 QBarSet* QBarLegendMarker::barset()
80 QBarSet* QBarLegendMarker::barset()
81 {
81 {
82 Q_D(QBarLegendMarker);
82 Q_D(QBarLegendMarker);
83 return d->m_barset;
83 return d->m_barset;
84 }
84 }
85
85
86 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
86 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
87
87
88 QBarLegendMarkerPrivate::QBarLegendMarkerPrivate(QBarLegendMarker *q, QAbstractBarSeries *series, QBarSet *barset, QLegend *legend) :
88 QBarLegendMarkerPrivate::QBarLegendMarkerPrivate(QBarLegendMarker *q, QAbstractBarSeries *series, QBarSet *barset, QLegend *legend) :
89 QLegendMarkerPrivate(q,legend),
89 QLegendMarkerPrivate(q,legend),
90 q_ptr(q),
90 q_ptr(q),
91 m_series(series),
91 m_series(series),
92 m_barset(barset)
92 m_barset(barset)
93 {
93 {
94 QObject::connect(m_barset, SIGNAL(penChanged()), this, SLOT(updated()));
94 QObject::connect(m_barset, SIGNAL(penChanged()), this, SLOT(updated()));
95 QObject::connect(m_barset, SIGNAL(labelChanged()), this, SLOT(updated()));
95 QObject::connect(m_barset, SIGNAL(labelChanged()), this, SLOT(updated()));
96 QObject::connect(m_barset, SIGNAL(brushChanged()), this, SLOT(updated()));
96 QObject::connect(m_barset, SIGNAL(brushChanged()), this, SLOT(updated()));
97 }
97 }
98
98
99 QBarLegendMarkerPrivate::~QBarLegendMarkerPrivate()
99 QBarLegendMarkerPrivate::~QBarLegendMarkerPrivate()
100 {
100 {
101 }
101 }
102
102
103 QAbstractBarSeries* QBarLegendMarkerPrivate::series()
103 QAbstractBarSeries* QBarLegendMarkerPrivate::series()
104 {
104 {
105 return m_series;
105 return m_series;
106 }
106 }
107
107
108 QObject* QBarLegendMarkerPrivate::relatedObject()
108 QObject* QBarLegendMarkerPrivate::relatedObject()
109 {
109 {
110 return m_barset;
110 return m_barset;
111 }
111 }
112
112
113 void QBarLegendMarkerPrivate::updated()
113 void QBarLegendMarkerPrivate::updated()
114 {
114 {
115 bool labelChanged = false;
115 bool labelChanged = false;
116 bool brushChanged = false;
116 bool brushChanged = false;
117 bool penChanged = false;
117 bool penChanged = false;
118
118
119 if (!m_customPen && (m_item->pen() != m_barset->pen())) {
119 if (!m_customPen && (m_item->pen() != m_barset->pen())) {
120 m_item->setPen(m_barset->pen());
120 m_item->setPen(m_barset->pen());
121 penChanged = true;
121 penChanged = true;
122 }
122 }
123 if (!m_customBrush && (m_item->brush() != m_barset->brush())) {
123 if (!m_customBrush && (m_item->brush() != m_barset->brush())) {
124 m_item->setBrush(m_barset->brush());
124 m_item->setBrush(m_barset->brush());
125 brushChanged = true;
125 brushChanged = true;
126 }
126 }
127 if (!m_customLabel && (m_item->label() != m_barset->label())) {
127 if (!m_customLabel && (m_item->label() != m_barset->label())) {
128 m_item->setLabel(m_barset->label());
128 m_item->setLabel(m_barset->label());
129 labelChanged = true;
129 labelChanged = true;
130 }
130 }
131 invalidateLegend();
131 invalidateLegend();
132
132
133 if (labelChanged)
133 if (labelChanged)
134 emit q_ptr->labelChanged();
134 emit q_ptr->labelChanged();
135 if (brushChanged)
135 if (brushChanged)
136 emit q_ptr->brushChanged();
136 emit q_ptr->brushChanged();
137 if (penChanged)
137 if (penChanged)
138 emit q_ptr->penChanged();
138 emit q_ptr->penChanged();
139 }
139 }
140
140
141 #include "moc_qbarlegendmarker.cpp"
141 #include "moc_qbarlegendmarker.cpp"
142 #include "moc_qbarlegendmarker_p.cpp"
142 #include "moc_qbarlegendmarker_p.cpp"
143
143
144 QTCOMMERCIALCHART_END_NAMESPACE
144 QTCOMMERCIALCHART_END_NAMESPACE
145
145
@@ -1,596 +1,596
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qlegend.h"
21 #include "qlegend.h"
22 #include "qlegend_p.h"
22 #include "qlegend_p.h"
23 #include "qabstractseries.h"
23 #include "qabstractseries.h"
24 #include "qabstractseries_p.h"
24 #include "qabstractseries_p.h"
25 #include "qchart_p.h"
25 #include "qchart_p.h"
26 #include "legendlayout_p.h"
26 #include "legendlayout_p.h"
27 #include "chartpresenter_p.h"
27 #include "chartpresenter_p.h"
28 #include "abstractchartlayout_p.h"
28 #include "abstractchartlayout_p.h"
29 #include "qlegendmarker.h"
29 #include "qlegendmarker.h"
30 #include "qlegendmarker_p.h"
30 #include "qlegendmarker_p.h"
31 #include "legendmarkeritem_p.h"
31 #include "legendmarkeritem_p.h"
32 #include "chartdataset_p.h"
32 #include "chartdataset_p.h"
33 #include <QPainter>
33 #include <QPainter>
34 #include <QPen>
34 #include <QPen>
35 #include <QGraphicsItemGroup>
35 #include <QGraphicsItemGroup>
36
36
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38
38
39 /*!
39 /*!
40 \class QLegend
40 \class QLegend
41 \brief Legend object
41 \brief Legend object.
42 \mainclass
42 \mainclass
43
43
44 QLegend is a graphical object for displaying the legend of the chart. Legend state is updated by QChart, when
44 QLegend is a graphical object for displaying the legend of the chart. Legend state is updated by QChart, when
45 series have been changed. By default, legend is drawn by QChart, but user can set a new parent to legend and
45 series have been changed. By default, legend is drawn by QChart, but user can set a new parent to legend and
46 handle the drawing manually.
46 handle the drawing manually.
47 User isn't supposed to create or delete legend objects, but can reference it via QChart class.
47 User isn't supposed to create or delete legend objects, but can reference it via QChart class.
48
48
49 \image examples_percentbarchart_legend.png
49 \image examples_percentbarchart_legend.png
50
50
51 \sa QChart
51 \sa QChart
52 */
52 */
53 /*!
53 /*!
54 \qmlclass Legend QLegend
54 \qmlclass Legend QLegend
55 \brief Legend is part of QtCommercial Chart QML API.
55 \brief Legend is part of QtCommercial Chart QML API.
56
56
57 Legend is a graphical object, whics displays legend of the chart. Legend state is updated by ChartView, when
57 Legend is a graphical object, whics displays legend of the chart. Legend state is updated by ChartView, when
58 series have been changed. Legend is used via ChartView class. For example:
58 series have been changed. Legend is used via ChartView class. For example:
59 \code
59 \code
60 ChartView {
60 ChartView {
61 legend.visible: true
61 legend.visible: true
62 legend.alignment: Qt.AlignBottom
62 legend.alignment: Qt.AlignBottom
63 // Add a few series...
63 // Add a few series...
64 }
64 }
65 \endcode
65 \endcode
66
66
67 \image examples_percentbarchart_legend.png
67 \image examples_percentbarchart_legend.png
68
68
69 Please note that there is no QML API available for modifying legend markers, unlike in the Qt API of Charts.
69 Please note that there is no QML API available for modifying legend markers, unlike in the Qt API of Charts.
70 The use case of modifying markers can be implemented for example by creating your own custom legend. For an example
70 The use case of modifying markers can be implemented for example by creating your own custom legend. For an example
71 on how to do this, see \l {demos/qmlcustomlegend}{Qml Custom Demo} application.
71 on how to do this, see \l {demos/qmlcustomlegend}{Qml Custom Demo} application.
72 */
72 */
73
73
74 /*!
74 /*!
75 \property QLegend::alignment
75 \property QLegend::alignment
76 \brief The alignment of the legend.
76 \brief The alignment of the legend.
77
77
78 Legend paints on the defined position in the chart. The following alignments are supported:
78 Legend paints on the defined position in the chart. The following alignments are supported:
79 Qt::AlignTop, Qt::AlignBottom, Qt::AlignLeft, Qt::AlignRight. If you set more than one flag the result is undefined.
79 Qt::AlignTop, Qt::AlignBottom, Qt::AlignLeft, Qt::AlignRight. If you set more than one flag the result is undefined.
80 */
80 */
81 /*!
81 /*!
82 \qmlproperty Qt.Alignment Legend::alignment
82 \qmlproperty Qt.Alignment Legend::alignment
83 \brief The alignment of the legend.
83 \brief The alignment of the legend.
84
84
85 Legend paints on the defined position in the chart. The following alignments are supported:
85 Legend paints on the defined position in the chart. The following alignments are supported:
86 Qt.AlignTop, Qt.AlignBottom, Qt.AlignLeft, Qt.AlignRight. If you set more than one flag the result is undefined.
86 Qt.AlignTop, Qt.AlignBottom, Qt.AlignLeft, Qt.AlignRight. If you set more than one flag the result is undefined.
87 */
87 */
88
88
89 /*!
89 /*!
90 \property QLegend::backgroundVisible
90 \property QLegend::backgroundVisible
91 Whether the legend background is visible or not.
91 Whether the legend background is visible or not.
92 */
92 */
93 /*!
93 /*!
94 \qmlproperty bool Legend::backgroundVisible
94 \qmlproperty bool Legend::backgroundVisible
95 Whether the legend background is visible or not.
95 Whether the legend background is visible or not.
96 */
96 */
97
97
98 /*!
98 /*!
99 \property QLegend::color
99 \property QLegend::color
100 The color of the legend, i.e. the background (brush) color. Note that if you change the color
100 The color of the legend, i.e. the background (brush) color. Note that if you change the color
101 of the legend, the style of the legend brush is set to Qt::SolidPattern.
101 of the legend, the style of the legend brush is set to Qt::SolidPattern.
102 */
102 */
103 /*!
103 /*!
104 \qmlproperty color Legend::color
104 \qmlproperty color Legend::color
105 The color of the legend, i.e. the background (brush) color.
105 The color of the legend, i.e. the background (brush) color.
106 */
106 */
107
107
108 /*!
108 /*!
109 \property QLegend::borderColor
109 \property QLegend::borderColor
110 The border color of the legend, i.e. the line color.
110 The border color of the legend, i.e. the line color.
111 */
111 */
112 /*!
112 /*!
113 \qmlproperty color Legend::borderColor
113 \qmlproperty color Legend::borderColor
114 The border color of the legend, i.e. the line color.
114 The border color of the legend, i.e. the line color.
115 */
115 */
116
116
117 /*!
117 /*!
118 \property QLegend::font
118 \property QLegend::font
119 The font of markers used by legend
119 The font of markers used by legend
120 */
120 */
121 /*!
121 /*!
122 \qmlproperty Font Legend::font
122 \qmlproperty Font Legend::font
123 The font of markers used by legend
123 The font of markers used by legend
124 */
124 */
125
125
126 /*!
126 /*!
127 \property QLegend::labelColor
127 \property QLegend::labelColor
128 The color of brush used to draw labels.
128 The color of brush used to draw labels.
129 */
129 */
130 /*!
130 /*!
131 \qmlproperty color QLegend::labelColor
131 \qmlproperty color QLegend::labelColor
132 The color of brush used to draw labels.
132 The color of brush used to draw labels.
133 */
133 */
134
134
135 /*!
135 /*!
136 \fn void QLegend::backgroundVisibleChanged(bool)
136 \fn void QLegend::backgroundVisibleChanged(bool)
137 The visibility of the legend background changed to \a visible.
137 The visibility of the legend background changed to \a visible.
138 */
138 */
139
139
140 /*!
140 /*!
141 \fn void QLegend::colorChanged(QColor)
141 \fn void QLegend::colorChanged(QColor)
142 The color of the legend background changed to \a color.
142 The color of the legend background changed to \a color.
143 */
143 */
144
144
145 /*!
145 /*!
146 \fn void QLegend::borderColorChanged(QColor)
146 \fn void QLegend::borderColorChanged(QColor)
147 The border color of the legend background changed to \a color.
147 The border color of the legend background changed to \a color.
148 */
148 */
149
149
150 /*!
150 /*!
151 \fn void QLegend::fontChanged(QFont)
151 \fn void QLegend::fontChanged(QFont)
152 The font of markers of the legend changed to \a font.
152 The font of markers of the legend changed to \a font.
153 */
153 */
154
154
155 /*!
155 /*!
156 \fn void QLegend::labelColorChanged(QColor color)
156 \fn void QLegend::labelColorChanged(QColor color)
157 This signal is emitted when the color of brush used to draw labels has changed to \a color.
157 This signal is emitted when the color of brush used to draw labels has changed to \a color.
158 */
158 */
159
159
160 QLegend::QLegend(QChart *chart): QGraphicsWidget(chart),
160 QLegend::QLegend(QChart *chart): QGraphicsWidget(chart),
161 d_ptr(new QLegendPrivate(chart->d_ptr->m_presenter, chart, this))
161 d_ptr(new QLegendPrivate(chart->d_ptr->m_presenter, chart, this))
162 {
162 {
163 setZValue(ChartPresenter::LegendZValue);
163 setZValue(ChartPresenter::LegendZValue);
164 setFlags(QGraphicsItem::ItemClipsChildrenToShape);
164 setFlags(QGraphicsItem::ItemClipsChildrenToShape);
165 QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), d_ptr.data(), SLOT(handleSeriesAdded(QAbstractSeries*)));
165 QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), d_ptr.data(), SLOT(handleSeriesAdded(QAbstractSeries*)));
166 QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), d_ptr.data(), SLOT(handleSeriesRemoved(QAbstractSeries*)));
166 QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), d_ptr.data(), SLOT(handleSeriesRemoved(QAbstractSeries*)));
167 setLayout(d_ptr->m_layout);
167 setLayout(d_ptr->m_layout);
168 }
168 }
169
169
170 /*!
170 /*!
171 Destroys the legend object. Legend is always owned by a QChart, so an application should never call this.
171 Destroys the legend object. Legend is always owned by a QChart, so an application should never call this.
172 */
172 */
173 QLegend::~QLegend()
173 QLegend::~QLegend()
174 {
174 {
175 }
175 }
176
176
177 /*!
177 /*!
178 \internal
178 \internal
179 */
179 */
180 void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
180 void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
181 {
181 {
182 Q_UNUSED(option)
182 Q_UNUSED(option)
183 Q_UNUSED(widget)
183 Q_UNUSED(widget)
184
184
185 if (!d_ptr->m_backgroundVisible)
185 if (!d_ptr->m_backgroundVisible)
186 return;
186 return;
187
187
188 painter->setOpacity(opacity());
188 painter->setOpacity(opacity());
189 painter->setPen(d_ptr->m_pen);
189 painter->setPen(d_ptr->m_pen);
190 painter->setBrush(d_ptr->m_brush);
190 painter->setBrush(d_ptr->m_brush);
191 painter->drawRoundRect(rect(), d_ptr->roundness(rect().width()), d_ptr->roundness(rect().height()));
191 painter->drawRoundRect(rect(), d_ptr->roundness(rect().width()), d_ptr->roundness(rect().height()));
192 }
192 }
193
193
194
194
195 /*!
195 /*!
196 Sets the \a brush of legend. Brush affects the background of legend.
196 Sets the \a brush of legend. Brush affects the background of legend.
197 */
197 */
198 void QLegend::setBrush(const QBrush &brush)
198 void QLegend::setBrush(const QBrush &brush)
199 {
199 {
200 if (d_ptr->m_brush != brush) {
200 if (d_ptr->m_brush != brush) {
201 d_ptr->m_brush = brush;
201 d_ptr->m_brush = brush;
202 update();
202 update();
203 emit colorChanged(brush.color());
203 emit colorChanged(brush.color());
204 }
204 }
205 }
205 }
206
206
207 /*!
207 /*!
208 Returns the brush used by legend.
208 Returns the brush used by legend.
209 */
209 */
210 QBrush QLegend::brush() const
210 QBrush QLegend::brush() const
211 {
211 {
212 return d_ptr->m_brush;
212 return d_ptr->m_brush;
213 }
213 }
214
214
215 void QLegend::setColor(QColor color)
215 void QLegend::setColor(QColor color)
216 {
216 {
217 QBrush b = d_ptr->m_brush;
217 QBrush b = d_ptr->m_brush;
218 if (b.style() != Qt::SolidPattern || b.color() != color) {
218 if (b.style() != Qt::SolidPattern || b.color() != color) {
219 b.setStyle(Qt::SolidPattern);
219 b.setStyle(Qt::SolidPattern);
220 b.setColor(color);
220 b.setColor(color);
221 setBrush(b);
221 setBrush(b);
222 }
222 }
223 }
223 }
224
224
225 QColor QLegend::color()
225 QColor QLegend::color()
226 {
226 {
227 return d_ptr->m_brush.color();
227 return d_ptr->m_brush.color();
228 }
228 }
229
229
230 /*!
230 /*!
231 Sets the \a pen of legend. Pen affects the legend borders.
231 Sets the \a pen of legend. Pen affects the legend borders.
232 */
232 */
233 void QLegend::setPen(const QPen &pen)
233 void QLegend::setPen(const QPen &pen)
234 {
234 {
235 if (d_ptr->m_pen != pen) {
235 if (d_ptr->m_pen != pen) {
236 d_ptr->m_pen = pen;
236 d_ptr->m_pen = pen;
237 update();
237 update();
238 emit borderColorChanged(pen.color());
238 emit borderColorChanged(pen.color());
239 }
239 }
240 }
240 }
241
241
242 /*!
242 /*!
243 Returns the pen used by legend
243 Returns the pen used by legend
244 */
244 */
245
245
246 QPen QLegend::pen() const
246 QPen QLegend::pen() const
247 {
247 {
248 return d_ptr->m_pen;
248 return d_ptr->m_pen;
249 }
249 }
250
250
251 void QLegend::setFont(const QFont &font)
251 void QLegend::setFont(const QFont &font)
252 {
252 {
253 if (d_ptr->m_font != font) {
253 if (d_ptr->m_font != font) {
254 d_ptr->m_font = font;
254 d_ptr->m_font = font;
255 foreach (QLegendMarker *marker, d_ptr->markers()) {
255 foreach (QLegendMarker *marker, d_ptr->markers()) {
256 marker->setFont(d_ptr->m_font);
256 marker->setFont(d_ptr->m_font);
257 }
257 }
258 layout()->invalidate();
258 layout()->invalidate();
259 emit fontChanged(font);
259 emit fontChanged(font);
260 }
260 }
261 }
261 }
262
262
263 QFont QLegend::font() const
263 QFont QLegend::font() const
264 {
264 {
265 return d_ptr->m_font;
265 return d_ptr->m_font;
266 }
266 }
267
267
268 void QLegend::setBorderColor(QColor color)
268 void QLegend::setBorderColor(QColor color)
269 {
269 {
270 QPen p = d_ptr->m_pen;
270 QPen p = d_ptr->m_pen;
271 if (p.color() != color) {
271 if (p.color() != color) {
272 p.setColor(color);
272 p.setColor(color);
273 setPen(p);
273 setPen(p);
274 }
274 }
275 }
275 }
276
276
277 QColor QLegend::borderColor()
277 QColor QLegend::borderColor()
278 {
278 {
279 return d_ptr->m_pen.color();
279 return d_ptr->m_pen.color();
280 }
280 }
281
281
282 /*!
282 /*!
283 Set brush used to draw labels to \a brush.
283 Set brush used to draw labels to \a brush.
284 */
284 */
285 void QLegend::setLabelBrush(const QBrush &brush)
285 void QLegend::setLabelBrush(const QBrush &brush)
286 {
286 {
287 if (d_ptr->m_labelBrush != brush) {
287 if (d_ptr->m_labelBrush != brush) {
288 d_ptr->m_labelBrush = brush;
288 d_ptr->m_labelBrush = brush;
289 foreach (QLegendMarker *marker, d_ptr->markers()) {
289 foreach (QLegendMarker *marker, d_ptr->markers()) {
290 marker->setLabelBrush(d_ptr->m_labelBrush);
290 marker->setLabelBrush(d_ptr->m_labelBrush);
291 // Note: The pen of the marker rectangle could be exposed in the public QLegend API
291 // Note: The pen of the marker rectangle could be exposed in the public QLegend API
292 // instead of mapping it from label brush color
292 // instead of mapping it from label brush color
293 marker->setPen(brush.color());
293 marker->setPen(brush.color());
294 }
294 }
295 emit labelColorChanged(brush.color());
295 emit labelColorChanged(brush.color());
296 }
296 }
297 }
297 }
298
298
299 /*!
299 /*!
300 Brush used to draw labels.
300 Brush used to draw labels.
301 */
301 */
302 QBrush QLegend::labelBrush() const
302 QBrush QLegend::labelBrush() const
303 {
303 {
304 return d_ptr->m_labelBrush;
304 return d_ptr->m_labelBrush;
305 }
305 }
306
306
307 void QLegend::setLabelColor(QColor color)
307 void QLegend::setLabelColor(QColor color)
308 {
308 {
309 QBrush b = d_ptr->m_labelBrush;
309 QBrush b = d_ptr->m_labelBrush;
310 if (b.style() != Qt::SolidPattern || b.color() != color) {
310 if (b.style() != Qt::SolidPattern || b.color() != color) {
311 b.setStyle(Qt::SolidPattern);
311 b.setStyle(Qt::SolidPattern);
312 b.setColor(color);
312 b.setColor(color);
313 setLabelBrush(b);
313 setLabelBrush(b);
314 }
314 }
315 }
315 }
316
316
317 QColor QLegend::labelColor() const
317 QColor QLegend::labelColor() const
318 {
318 {
319 return d_ptr->m_labelBrush.color();
319 return d_ptr->m_labelBrush.color();
320 }
320 }
321
321
322
322
323 void QLegend::setAlignment(Qt::Alignment alignment)
323 void QLegend::setAlignment(Qt::Alignment alignment)
324 {
324 {
325 if (d_ptr->m_alignment != alignment) {
325 if (d_ptr->m_alignment != alignment) {
326 d_ptr->m_alignment = alignment;
326 d_ptr->m_alignment = alignment;
327 layout()->invalidate();
327 layout()->invalidate();
328 }
328 }
329 }
329 }
330
330
331 Qt::Alignment QLegend::alignment() const
331 Qt::Alignment QLegend::alignment() const
332 {
332 {
333 return d_ptr->m_alignment;
333 return d_ptr->m_alignment;
334 }
334 }
335
335
336 /*!
336 /*!
337 Detaches the legend from chart. Chart won't change layout of the legend.
337 Detaches the legend from chart. Chart won't change layout of the legend.
338 */
338 */
339 void QLegend::detachFromChart()
339 void QLegend::detachFromChart()
340 {
340 {
341 d_ptr->m_attachedToChart = false;
341 d_ptr->m_attachedToChart = false;
342 // layout()->invalidate();
342 // layout()->invalidate();
343 d_ptr->m_chart->layout()->invalidate();
343 d_ptr->m_chart->layout()->invalidate();
344 setParent(0);
344 setParent(0);
345
345
346 }
346 }
347
347
348 /*!
348 /*!
349 Attaches the legend to chart. Chart may change layout of the legend.
349 Attaches the legend to chart. Chart may change layout of the legend.
350 */
350 */
351 void QLegend::attachToChart()
351 void QLegend::attachToChart()
352 {
352 {
353 d_ptr->m_attachedToChart = true;
353 d_ptr->m_attachedToChart = true;
354 // layout()->invalidate();
354 // layout()->invalidate();
355 d_ptr->m_chart->layout()->invalidate();
355 d_ptr->m_chart->layout()->invalidate();
356 setParent(d_ptr->m_chart);
356 setParent(d_ptr->m_chart);
357 }
357 }
358
358
359 /*!
359 /*!
360 Returns true, if legend is attached to chart.
360 Returns true, if legend is attached to chart.
361 */
361 */
362 bool QLegend::isAttachedToChart()
362 bool QLegend::isAttachedToChart()
363 {
363 {
364 return d_ptr->m_attachedToChart;
364 return d_ptr->m_attachedToChart;
365 }
365 }
366
366
367 /*!
367 /*!
368 Sets the visibility of legend background to \a visible
368 Sets the visibility of legend background to \a visible
369 */
369 */
370 void QLegend::setBackgroundVisible(bool visible)
370 void QLegend::setBackgroundVisible(bool visible)
371 {
371 {
372 if (d_ptr->m_backgroundVisible != visible) {
372 if (d_ptr->m_backgroundVisible != visible) {
373 d_ptr->m_backgroundVisible = visible;
373 d_ptr->m_backgroundVisible = visible;
374 update();
374 update();
375 emit backgroundVisibleChanged(visible);
375 emit backgroundVisibleChanged(visible);
376 }
376 }
377 }
377 }
378
378
379 /*!
379 /*!
380 Returns the visibility of legend background
380 Returns the visibility of legend background
381 */
381 */
382 bool QLegend::isBackgroundVisible() const
382 bool QLegend::isBackgroundVisible() const
383 {
383 {
384 return d_ptr->m_backgroundVisible;
384 return d_ptr->m_backgroundVisible;
385 }
385 }
386
386
387 /*!
387 /*!
388 Returns the list of markers in legend. The list can be filtered with \a series parameter.
388 Returns the list of markers in legend. The list can be filtered with \a series parameter.
389 If \a series is given, only markers related to that series are returned.
389 If \a series is given, only markers related to that series are returned.
390 */
390 */
391 QList<QLegendMarker*> QLegend::markers(QAbstractSeries *series) const
391 QList<QLegendMarker*> QLegend::markers(QAbstractSeries *series) const
392 {
392 {
393 return d_ptr->markers(series);
393 return d_ptr->markers(series);
394 }
394 }
395
395
396 /*!
396 /*!
397 \internal \a event see QGraphicsWidget for details
397 \internal \a event see QGraphicsWidget for details
398 */
398 */
399 void QLegend::hideEvent(QHideEvent *event)
399 void QLegend::hideEvent(QHideEvent *event)
400 {
400 {
401 if (isAttachedToChart())
401 if (isAttachedToChart())
402 d_ptr->m_presenter->layout()->invalidate();
402 d_ptr->m_presenter->layout()->invalidate();
403 QGraphicsWidget::hideEvent(event);
403 QGraphicsWidget::hideEvent(event);
404 }
404 }
405 /*!
405 /*!
406 \internal \a event see QGraphicsWidget for details
406 \internal \a event see QGraphicsWidget for details
407 */
407 */
408 void QLegend::showEvent(QShowEvent *event)
408 void QLegend::showEvent(QShowEvent *event)
409 {
409 {
410 if (isAttachedToChart()) {
410 if (isAttachedToChart()) {
411 d_ptr->items()->setVisible(false);
411 d_ptr->items()->setVisible(false);
412 layout()->invalidate();
412 layout()->invalidate();
413 }
413 }
414 QGraphicsWidget::showEvent(event);
414 QGraphicsWidget::showEvent(event);
415 //layout activation will show the items
415 //layout activation will show the items
416 }
416 }
417
417
418 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
418 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
419
419
420 QLegendPrivate::QLegendPrivate(ChartPresenter *presenter, QChart *chart, QLegend *q)
420 QLegendPrivate::QLegendPrivate(ChartPresenter *presenter, QChart *chart, QLegend *q)
421 : q_ptr(q),
421 : q_ptr(q),
422 m_presenter(presenter),
422 m_presenter(presenter),
423 m_layout(new LegendLayout(q)),
423 m_layout(new LegendLayout(q)),
424 m_chart(chart),
424 m_chart(chart),
425 m_items(new QGraphicsItemGroup(q)),
425 m_items(new QGraphicsItemGroup(q)),
426 m_alignment(Qt::AlignTop),
426 m_alignment(Qt::AlignTop),
427 m_brush(QBrush()),
427 m_brush(QBrush()),
428 m_pen(QPen()),
428 m_pen(QPen()),
429 m_labelBrush(QBrush()),
429 m_labelBrush(QBrush()),
430 m_diameter(5),
430 m_diameter(5),
431 m_attachedToChart(true),
431 m_attachedToChart(true),
432 m_backgroundVisible(false)
432 m_backgroundVisible(false)
433 {
433 {
434 m_items->setHandlesChildEvents(false);
434 m_items->setHandlesChildEvents(false);
435 }
435 }
436
436
437 QLegendPrivate::~QLegendPrivate()
437 QLegendPrivate::~QLegendPrivate()
438 {
438 {
439
439
440 }
440 }
441
441
442 void QLegendPrivate::setOffset(const QPointF &offset)
442 void QLegendPrivate::setOffset(const QPointF &offset)
443 {
443 {
444 m_layout->setOffset(offset.x(), offset.y());
444 m_layout->setOffset(offset.x(), offset.y());
445 }
445 }
446
446
447 QPointF QLegendPrivate::offset() const
447 QPointF QLegendPrivate::offset() const
448 {
448 {
449 return m_layout->offset();
449 return m_layout->offset();
450 }
450 }
451
451
452 int QLegendPrivate::roundness(qreal size)
452 int QLegendPrivate::roundness(qreal size)
453 {
453 {
454 return 100 * m_diameter / int(size);
454 return 100 * m_diameter / int(size);
455 }
455 }
456
456
457 QList<QLegendMarker*> QLegendPrivate::markers(QAbstractSeries *series)
457 QList<QLegendMarker*> QLegendPrivate::markers(QAbstractSeries *series)
458 {
458 {
459 // Return all markers
459 // Return all markers
460 if (!series) {
460 if (!series) {
461 return m_markers;
461 return m_markers;
462 }
462 }
463
463
464 // Create filtered list
464 // Create filtered list
465 QList<QLegendMarker *> markers;
465 QList<QLegendMarker *> markers;
466 foreach (QLegendMarker *marker, m_markers) {
466 foreach (QLegendMarker *marker, m_markers) {
467 if (marker->series() == series) {
467 if (marker->series() == series) {
468 markers.append(marker);
468 markers.append(marker);
469 }
469 }
470 }
470 }
471 return markers;
471 return markers;
472 }
472 }
473
473
474 void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series)
474 void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series)
475 {
475 {
476 if (m_series.contains(series)) {
476 if (m_series.contains(series)) {
477 return;
477 return;
478 }
478 }
479
479
480 QList<QLegendMarker*> newMarkers = series->d_ptr->createLegendMarkers(q_ptr);
480 QList<QLegendMarker*> newMarkers = series->d_ptr->createLegendMarkers(q_ptr);
481 decorateMarkers(newMarkers);
481 decorateMarkers(newMarkers);
482 addMarkers(newMarkers);
482 addMarkers(newMarkers);
483
483
484 QObject::connect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged()));
484 QObject::connect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged()));
485 QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
485 QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
486
486
487 m_series.append(series);
487 m_series.append(series);
488 m_items->setVisible(false);
488 m_items->setVisible(false);
489 m_layout->invalidate();
489 m_layout->invalidate();
490 }
490 }
491
491
492 void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series)
492 void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series)
493 {
493 {
494 if (m_series.contains(series)) {
494 if (m_series.contains(series)) {
495 m_series.removeOne(series);
495 m_series.removeOne(series);
496 }
496 }
497
497
498 // Find out, which markers to remove
498 // Find out, which markers to remove
499 QList<QLegendMarker *> removed;
499 QList<QLegendMarker *> removed;
500 foreach (QLegendMarker *m, m_markers) {
500 foreach (QLegendMarker *m, m_markers) {
501 if (m->series() == series) {
501 if (m->series() == series) {
502 removed << m;
502 removed << m;
503 }
503 }
504 }
504 }
505 removeMarkers(removed);
505 removeMarkers(removed);
506
506
507 QObject::disconnect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged()));
507 QObject::disconnect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged()));
508 QObject::disconnect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
508 QObject::disconnect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
509
509
510 m_layout->invalidate();
510 m_layout->invalidate();
511 }
511 }
512
512
513 void QLegendPrivate::handleSeriesVisibleChanged()
513 void QLegendPrivate::handleSeriesVisibleChanged()
514 {
514 {
515 QAbstractSeries *series = qobject_cast<QAbstractSeries *> (sender());
515 QAbstractSeries *series = qobject_cast<QAbstractSeries *> (sender());
516 Q_ASSERT(series);
516 Q_ASSERT(series);
517
517
518 foreach (QLegendMarker *marker, m_markers) {
518 foreach (QLegendMarker *marker, m_markers) {
519 if (marker->series() == series) {
519 if (marker->series() == series) {
520 marker->setVisible(series->isVisible());
520 marker->setVisible(series->isVisible());
521 }
521 }
522 }
522 }
523 m_layout->invalidate();
523 m_layout->invalidate();
524 }
524 }
525
525
526 void QLegendPrivate::handleCountChanged()
526 void QLegendPrivate::handleCountChanged()
527 {
527 {
528 // Here we handle the changes in marker count.
528 // Here we handle the changes in marker count.
529 // Can happen for example when pieslice(s) have been added to or removed from pieseries.
529 // Can happen for example when pieslice(s) have been added to or removed from pieseries.
530
530
531 QAbstractSeriesPrivate *series = qobject_cast<QAbstractSeriesPrivate *> (sender());
531 QAbstractSeriesPrivate *series = qobject_cast<QAbstractSeriesPrivate *> (sender());
532 QList<QLegendMarker *> createdMarkers = series->createLegendMarkers(q_ptr);
532 QList<QLegendMarker *> createdMarkers = series->createLegendMarkers(q_ptr);
533
533
534 // Find out removed markers and created markers
534 // Find out removed markers and created markers
535 QList<QLegendMarker *> removedMarkers;
535 QList<QLegendMarker *> removedMarkers;
536 foreach (QLegendMarker *oldMarker, m_markers) {
536 foreach (QLegendMarker *oldMarker, m_markers) {
537 // we have marker, which is related to sender.
537 // we have marker, which is related to sender.
538 if (oldMarker->series() == series->q_ptr) {
538 if (oldMarker->series() == series->q_ptr) {
539 bool found = false;
539 bool found = false;
540 foreach(QLegendMarker *newMarker, createdMarkers) {
540 foreach(QLegendMarker *newMarker, createdMarkers) {
541 // New marker considered existing if:
541 // New marker considered existing if:
542 // - d_ptr->relatedObject() is same for both markers.
542 // - d_ptr->relatedObject() is same for both markers.
543 if (newMarker->d_ptr->relatedObject() == oldMarker->d_ptr->relatedObject()) {
543 if (newMarker->d_ptr->relatedObject() == oldMarker->d_ptr->relatedObject()) {
544 // Delete the new marker, since we already have existing marker, that might be connected on user side.
544 // Delete the new marker, since we already have existing marker, that might be connected on user side.
545 found = true;
545 found = true;
546 createdMarkers.removeOne(newMarker);
546 createdMarkers.removeOne(newMarker);
547 delete newMarker;
547 delete newMarker;
548 }
548 }
549 }
549 }
550 if (!found) {
550 if (!found) {
551 // No related object found for marker, add to removedMarkers list
551 // No related object found for marker, add to removedMarkers list
552 removedMarkers << oldMarker;
552 removedMarkers << oldMarker;
553 }
553 }
554 }
554 }
555 }
555 }
556
556
557 removeMarkers(removedMarkers);
557 removeMarkers(removedMarkers);
558 decorateMarkers(createdMarkers);
558 decorateMarkers(createdMarkers);
559 addMarkers(createdMarkers);
559 addMarkers(createdMarkers);
560
560
561 q_ptr->layout()->invalidate();
561 q_ptr->layout()->invalidate();
562 }
562 }
563
563
564 void QLegendPrivate::addMarkers(QList<QLegendMarker *> markers)
564 void QLegendPrivate::addMarkers(QList<QLegendMarker *> markers)
565 {
565 {
566 foreach (QLegendMarker *marker, markers) {
566 foreach (QLegendMarker *marker, markers) {
567 m_items->addToGroup(marker->d_ptr.data()->item());
567 m_items->addToGroup(marker->d_ptr.data()->item());
568 m_markers << marker;
568 m_markers << marker;
569 m_markerHash.insert(marker->d_ptr->item(), marker);
569 m_markerHash.insert(marker->d_ptr->item(), marker);
570 }
570 }
571 }
571 }
572
572
573 void QLegendPrivate::removeMarkers(QList<QLegendMarker *> markers)
573 void QLegendPrivate::removeMarkers(QList<QLegendMarker *> markers)
574 {
574 {
575 foreach (QLegendMarker *marker, markers) {
575 foreach (QLegendMarker *marker, markers) {
576 marker->d_ptr->item()->setVisible(false);
576 marker->d_ptr->item()->setVisible(false);
577 m_items->removeFromGroup(marker->d_ptr->item());
577 m_items->removeFromGroup(marker->d_ptr->item());
578 m_markers.removeOne(marker);
578 m_markers.removeOne(marker);
579 m_markerHash.remove(marker->d_ptr->item());
579 m_markerHash.remove(marker->d_ptr->item());
580 delete marker;
580 delete marker;
581 }
581 }
582 }
582 }
583
583
584 void QLegendPrivate::decorateMarkers(QList<QLegendMarker *> markers)
584 void QLegendPrivate::decorateMarkers(QList<QLegendMarker *> markers)
585 {
585 {
586 foreach (QLegendMarker *marker, markers) {
586 foreach (QLegendMarker *marker, markers) {
587 marker->setFont(m_font);
587 marker->setFont(m_font);
588 marker->setLabelBrush(m_labelBrush);
588 marker->setLabelBrush(m_labelBrush);
589 }
589 }
590 }
590 }
591
591
592
592
593 #include "moc_qlegend.cpp"
593 #include "moc_qlegend.cpp"
594 #include "moc_qlegend_p.cpp"
594 #include "moc_qlegend_p.cpp"
595
595
596 QTCOMMERCIALCHART_END_NAMESPACE
596 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,292 +1,292
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qlegendmarker.h"
21 #include "qlegendmarker.h"
22 #include "qlegendmarker_p.h"
22 #include "qlegendmarker_p.h"
23 #include "legendmarkeritem_p.h"
23 #include "legendmarkeritem_p.h"
24 #include "qlegend.h"
24 #include "qlegend.h"
25 #include "qlegend_p.h"
25 #include "qlegend_p.h"
26 #include "legendlayout_p.h"
26 #include "legendlayout_p.h"
27 #include <QFontMetrics>
27 #include <QFontMetrics>
28 #include <QGraphicsSceneEvent>
28 #include <QGraphicsSceneEvent>
29 #include <QAbstractSeries>
29 #include <QAbstractSeries>
30
30
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32
32
33 /*!
33 /*!
34 \class QLegendMarker
34 \class QLegendMarker
35 \brief LegendMarker object
35 \brief LegendMarker object.
36 \mainclass
36 \mainclass
37
37
38 QLegendMarker is abstract object that can be used to access markers inside QLegend. Legend marker consists of two
38 QLegendMarker is abstract object that can be used to access markers inside QLegend. Legend marker consists of two
39 items: The colored box, which reflects the color of series and label, which is the name of series (or label of slice/barset
39 items: The colored box, which reflects the color of series and label, which is the name of series (or label of slice/barset
40 in case of pie or bar series)
40 in case of pie or bar series)
41 The QLegendMarker is always related to one series.
41 The QLegendMarker is always related to one series.
42
42
43 \image examples_percentbarchart_legend.png
43 \image examples_percentbarchart_legend.png
44
44
45 \sa QLegend
45 \sa QLegend
46 */
46 */
47 /*!
47 /*!
48 \enum QLegendMarker::LegendMarkerType
48 \enum QLegendMarker::LegendMarkerType
49
49
50 The type of the legendmarker object.
50 The type of the legendmarker object.
51
51
52 \value LegendMarkerTypeArea
52 \value LegendMarkerTypeArea
53 \value LegendMarkerTypeBar
53 \value LegendMarkerTypeBar
54 \value LegendMarkerTypePie
54 \value LegendMarkerTypePie
55 \value LegendMarkerTypeXY
55 \value LegendMarkerTypeXY
56 */
56 */
57
57
58 /*!
58 /*!
59 \fn virtual LegendMarkerType QLegendMarker::type() = 0;
59 \fn virtual LegendMarkerType QLegendMarker::type() = 0;
60 Returns the type of legendmarker. Type depends of the related series. LegendMarkerTypeXY is used for all QXYSeries derived
60 Returns the type of legendmarker. Type depends of the related series. LegendMarkerTypeXY is used for all QXYSeries derived
61 classes.
61 classes.
62 */
62 */
63
63
64 /*!
64 /*!
65 \fn virtual QAbstractSeries* QLegendMarker::series() = 0;
65 \fn virtual QAbstractSeries* QLegendMarker::series() = 0;
66 Returns pointer to series, which is related to this marker. Marker is always related to some series.
66 Returns pointer to series, which is related to this marker. Marker is always related to some series.
67 */
67 */
68
68
69 /*!
69 /*!
70 \fn void QLegendMarker::clicked();
70 \fn void QLegendMarker::clicked();
71 This signal is emitted, when marker is clicked with mouse.
71 This signal is emitted, when marker is clicked with mouse.
72 */
72 */
73
73
74 /*!
74 /*!
75 \fn void QLegendMarker::hovered(bool status);
75 \fn void QLegendMarker::hovered(bool status);
76 This signal is emitted, when mouse is hovered over marker. \a status is true, when mouse enters the marker
76 This signal is emitted, when mouse is hovered over marker. \a status is true, when mouse enters the marker
77 and false when it leaves the marker.
77 and false when it leaves the marker.
78 */
78 */
79
79
80 /*!
80 /*!
81 \fn void QLegendMarker::labelChanged()
81 \fn void QLegendMarker::labelChanged()
82 This signal is emitted when the label of the legend marker has changed.
82 This signal is emitted when the label of the legend marker has changed.
83 */
83 */
84
84
85 /*!
85 /*!
86 \fn void QLegendMarker::labelBrushChanged()
86 \fn void QLegendMarker::labelBrushChanged()
87 This signal is emitted when the label brush of the legend marker has changed.
87 This signal is emitted when the label brush of the legend marker has changed.
88 */
88 */
89
89
90 /*!
90 /*!
91 \fn void QLegendMarker::fontChanged()
91 \fn void QLegendMarker::fontChanged()
92 This signal is emitted when the (label) font of the legend marker has changed.
92 This signal is emitted when the (label) font of the legend marker has changed.
93 */
93 */
94
94
95 /*!
95 /*!
96 \fn void QLegendMarker::penChanged()
96 \fn void QLegendMarker::penChanged()
97 This signal is emitted when the pen of the legend marker has changed.
97 This signal is emitted when the pen of the legend marker has changed.
98 */
98 */
99
99
100 /*!
100 /*!
101 \fn void QLegendMarker::brushChanged()
101 \fn void QLegendMarker::brushChanged()
102 This signal is emitted when the brush of the legend marker has changed.
102 This signal is emitted when the brush of the legend marker has changed.
103 */
103 */
104
104
105 /*!
105 /*!
106 \fn void QLegendMarker::visibleChanged()
106 \fn void QLegendMarker::visibleChanged()
107 This signal is emitted when the visibility of the legend marker has changed.
107 This signal is emitted when the visibility of the legend marker has changed.
108 */
108 */
109
109
110 /*!
110 /*!
111 \property QLegendMarker::label
111 \property QLegendMarker::label
112 Label of the marker. This is the text that is shown in legend.
112 Label of the marker. This is the text that is shown in legend.
113 */
113 */
114
114
115 /*!
115 /*!
116 \property QLegendMarker::labelBrush
116 \property QLegendMarker::labelBrush
117 Brush of the label
117 Brush of the label
118 */
118 */
119
119
120 /*!
120 /*!
121 \property QLegendMarker::font
121 \property QLegendMarker::font
122 Font of the label
122 Font of the label
123 */
123 */
124
124
125 /*!
125 /*!
126 \property QLegendMarker::pen
126 \property QLegendMarker::pen
127 Pen of the marker. This is the outline of the colored square.
127 Pen of the marker. This is the outline of the colored square.
128 */
128 */
129
129
130 /*!
130 /*!
131 \property QLegendMarker::brush
131 \property QLegendMarker::brush
132 Brush of the marker. This is the inside of the colored square.
132 Brush of the marker. This is the inside of the colored square.
133 */
133 */
134
134
135 /*!
135 /*!
136 \property QLegendMarker::visible
136 \property QLegendMarker::visible
137 Visibility of the legend marker. Affects label and the colored square.
137 Visibility of the legend marker. Affects label and the colored square.
138 */
138 */
139
139
140
140
141 /*!
141 /*!
142 \internal
142 \internal
143 */
143 */
144 QLegendMarker::QLegendMarker(QLegendMarkerPrivate &d, QObject *parent) :
144 QLegendMarker::QLegendMarker(QLegendMarkerPrivate &d, QObject *parent) :
145 QObject(parent),
145 QObject(parent),
146 d_ptr(&d)
146 d_ptr(&d)
147 {
147 {
148 d_ptr->m_item->setVisible(d_ptr->series()->isVisible());
148 d_ptr->m_item->setVisible(d_ptr->series()->isVisible());
149 }
149 }
150
150
151 /*!
151 /*!
152 Destructor of marker
152 Destructor of marker
153 */
153 */
154 QLegendMarker::~QLegendMarker()
154 QLegendMarker::~QLegendMarker()
155 {
155 {
156 }
156 }
157
157
158 /*!
158 /*!
159 Returns the label of the marker.
159 Returns the label of the marker.
160 */
160 */
161 QString QLegendMarker::label() const
161 QString QLegendMarker::label() const
162 {
162 {
163 return d_ptr->m_item->label();
163 return d_ptr->m_item->label();
164 }
164 }
165
165
166 /*!
166 /*!
167 Sets the \a label of marker. Note that changing name of series will also change label of its marker.
167 Sets the \a label of marker. Note that changing name of series will also change label of its marker.
168 */
168 */
169 void QLegendMarker::setLabel(const QString &label)
169 void QLegendMarker::setLabel(const QString &label)
170 {
170 {
171 if (label.isEmpty()) {
171 if (label.isEmpty()) {
172 d_ptr->m_customLabel = false;
172 d_ptr->m_customLabel = false;
173 } else {
173 } else {
174 d_ptr->m_customLabel = true;
174 d_ptr->m_customLabel = true;
175 d_ptr->m_item->setLabel(label);
175 d_ptr->m_item->setLabel(label);
176 }
176 }
177 }
177 }
178 /*!
178 /*!
179 Returns the brush which is used to draw label.
179 Returns the brush which is used to draw label.
180 */
180 */
181 QBrush QLegendMarker::labelBrush() const
181 QBrush QLegendMarker::labelBrush() const
182 {
182 {
183 return d_ptr->m_item->labelBrush();
183 return d_ptr->m_item->labelBrush();
184 }
184 }
185
185
186 /*!
186 /*!
187 Sets the \a brush of label
187 Sets the \a brush of label
188 */
188 */
189 void QLegendMarker::setLabelBrush(const QBrush &brush)
189 void QLegendMarker::setLabelBrush(const QBrush &brush)
190 {
190 {
191 d_ptr->m_item->setLabelBrush(brush);
191 d_ptr->m_item->setLabelBrush(brush);
192 }
192 }
193
193
194 /*!
194 /*!
195 Retuns the font of label
195 Retuns the font of label
196 */
196 */
197 QFont QLegendMarker::font() const
197 QFont QLegendMarker::font() const
198 {
198 {
199 return d_ptr->m_item->font();
199 return d_ptr->m_item->font();
200 }
200 }
201
201
202 /*!
202 /*!
203 Sets the \a font of label
203 Sets the \a font of label
204 */
204 */
205 void QLegendMarker::setFont(const QFont &font)
205 void QLegendMarker::setFont(const QFont &font)
206 {
206 {
207 d_ptr->m_item->setFont(font);
207 d_ptr->m_item->setFont(font);
208 }
208 }
209
209
210 /*!
210 /*!
211 Returns the pen of marker item
211 Returns the pen of marker item
212 */
212 */
213 QPen QLegendMarker::pen() const
213 QPen QLegendMarker::pen() const
214 {
214 {
215 return d_ptr->m_item->pen();
215 return d_ptr->m_item->pen();
216 }
216 }
217
217
218 /*!
218 /*!
219 Sets the \a pen of marker item
219 Sets the \a pen of marker item
220 */
220 */
221 void QLegendMarker::setPen(const QPen &pen)
221 void QLegendMarker::setPen(const QPen &pen)
222 {
222 {
223 if (pen == QPen(Qt::NoPen)) {
223 if (pen == QPen(Qt::NoPen)) {
224 d_ptr->m_customPen = false;
224 d_ptr->m_customPen = false;
225 } else {
225 } else {
226 d_ptr->m_customPen = true;
226 d_ptr->m_customPen = true;
227 d_ptr->m_item->setPen(pen);
227 d_ptr->m_item->setPen(pen);
228 }
228 }
229 }
229 }
230
230
231 /*!
231 /*!
232 Returns the brush of marker item
232 Returns the brush of marker item
233 */
233 */
234 QBrush QLegendMarker::brush() const
234 QBrush QLegendMarker::brush() const
235 {
235 {
236 return d_ptr->m_item->brush();
236 return d_ptr->m_item->brush();
237 }
237 }
238
238
239 /*!
239 /*!
240 Sets the \a brush of marker item. Note that changing color of the series also changes this.
240 Sets the \a brush of marker item. Note that changing color of the series also changes this.
241 */
241 */
242 void QLegendMarker::setBrush(const QBrush &brush)
242 void QLegendMarker::setBrush(const QBrush &brush)
243 {
243 {
244 if (brush == QBrush(Qt::NoBrush)) {
244 if (brush == QBrush(Qt::NoBrush)) {
245 d_ptr->m_customBrush = false;
245 d_ptr->m_customBrush = false;
246 } else {
246 } else {
247 d_ptr->m_customBrush = true;
247 d_ptr->m_customBrush = true;
248 d_ptr->m_item->setBrush(brush);
248 d_ptr->m_item->setBrush(brush);
249 }
249 }
250 }
250 }
251
251
252 /*!
252 /*!
253 Returns visibility of the marker
253 Returns visibility of the marker
254 */
254 */
255 bool QLegendMarker::isVisible() const
255 bool QLegendMarker::isVisible() const
256 {
256 {
257 return d_ptr->m_item->isVisible();
257 return d_ptr->m_item->isVisible();
258 }
258 }
259
259
260 /*!
260 /*!
261 Sets markers visibility to \a visible
261 Sets markers visibility to \a visible
262 */
262 */
263 void QLegendMarker::setVisible(bool visible)
263 void QLegendMarker::setVisible(bool visible)
264 {
264 {
265 d_ptr->m_item->setVisible(visible);
265 d_ptr->m_item->setVisible(visible);
266 }
266 }
267
267
268 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
268 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
269 QLegendMarkerPrivate::QLegendMarkerPrivate(QLegendMarker *q, QLegend *legend) :
269 QLegendMarkerPrivate::QLegendMarkerPrivate(QLegendMarker *q, QLegend *legend) :
270 m_legend(legend),
270 m_legend(legend),
271 m_customLabel(false),
271 m_customLabel(false),
272 m_customBrush(false),
272 m_customBrush(false),
273 m_customPen(false),
273 m_customPen(false),
274 q_ptr(q)
274 q_ptr(q)
275 {
275 {
276 m_item = new LegendMarkerItem(this);
276 m_item = new LegendMarkerItem(this);
277 }
277 }
278
278
279 QLegendMarkerPrivate::~QLegendMarkerPrivate()
279 QLegendMarkerPrivate::~QLegendMarkerPrivate()
280 {
280 {
281 delete m_item;
281 delete m_item;
282 }
282 }
283
283
284 void QLegendMarkerPrivate::invalidateLegend()
284 void QLegendMarkerPrivate::invalidateLegend()
285 {
285 {
286 m_legend->d_ptr->m_layout->invalidate();
286 m_legend->d_ptr->m_layout->invalidate();
287 }
287 }
288
288
289 #include "moc_qlegendmarker.cpp"
289 #include "moc_qlegendmarker.cpp"
290 #include "moc_qlegendmarker_p.cpp"
290 #include "moc_qlegendmarker_p.cpp"
291
291
292 QTCOMMERCIALCHART_END_NAMESPACE
292 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,143 +1,143
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qpielegendmarker.h"
21 #include "qpielegendmarker.h"
22 #include "qpielegendmarker_p.h"
22 #include "qpielegendmarker_p.h"
23 #include <QPieSeries>
23 #include <QPieSeries>
24 #include <QPieSlice>
24 #include <QPieSlice>
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 /*!
28 /*!
29 \class QPieLegendMarker
29 \class QPieLegendMarker
30 \brief LegendMarker object
30 \brief LegendMarker object.
31 \mainclass
31 \mainclass
32
32
33 QPieLegendMarker is related to QPieSeries. With QPieSeries, each slice of pie is related to one marker in QLegend.
33 QPieLegendMarker is related to QPieSeries. With QPieSeries, each slice of pie is related to one marker in QLegend.
34
34
35 \sa QLegend QPieSeries QPieSlice
35 \sa QLegend QPieSeries QPieSlice
36 */
36 */
37
37
38 /*!
38 /*!
39 \fn virtual LegendMarkerType QPieLegendMarker::type()
39 \fn virtual LegendMarkerType QPieLegendMarker::type()
40 Returns QLegendMarker::LegendMarkerTypePie
40 Returns QLegendMarker::LegendMarkerTypePie
41 */
41 */
42
42
43 /*!
43 /*!
44 \internal
44 \internal
45 */
45 */
46 QPieLegendMarker::QPieLegendMarker(QPieSeries *series, QPieSlice *slice, QLegend *legend, QObject *parent) :
46 QPieLegendMarker::QPieLegendMarker(QPieSeries *series, QPieSlice *slice, QLegend *legend, QObject *parent) :
47 QLegendMarker(*new QPieLegendMarkerPrivate(this,series,slice,legend), parent)
47 QLegendMarker(*new QPieLegendMarkerPrivate(this,series,slice,legend), parent)
48 {
48 {
49 d_ptr->updated();
49 d_ptr->updated();
50 }
50 }
51
51
52 /*!
52 /*!
53 Destructor
53 Destructor
54 */
54 */
55 QPieLegendMarker::~QPieLegendMarker()
55 QPieLegendMarker::~QPieLegendMarker()
56 {
56 {
57 }
57 }
58
58
59 /*!
59 /*!
60 \internal
60 \internal
61 */
61 */
62 QPieLegendMarker::QPieLegendMarker(QPieLegendMarkerPrivate &d, QObject *parent) :
62 QPieLegendMarker::QPieLegendMarker(QPieLegendMarkerPrivate &d, QObject *parent) :
63 QLegendMarker(d, parent)
63 QLegendMarker(d, parent)
64 {
64 {
65 }
65 }
66
66
67 /*!
67 /*!
68 Returns the related series of marker.
68 Returns the related series of marker.
69 */
69 */
70 QPieSeries* QPieLegendMarker::series()
70 QPieSeries* QPieLegendMarker::series()
71 {
71 {
72 Q_D(QPieLegendMarker);
72 Q_D(QPieLegendMarker);
73 return d->m_series;
73 return d->m_series;
74 }
74 }
75
75
76 /*!
76 /*!
77 Returns the related slice of marker.
77 Returns the related slice of marker.
78 */
78 */
79 QPieSlice* QPieLegendMarker::slice()
79 QPieSlice* QPieLegendMarker::slice()
80 {
80 {
81 Q_D(QPieLegendMarker);
81 Q_D(QPieLegendMarker);
82 return d->m_slice;
82 return d->m_slice;
83 }
83 }
84
84
85 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
85 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
86
86
87 QPieLegendMarkerPrivate::QPieLegendMarkerPrivate(QPieLegendMarker *q, QPieSeries *series, QPieSlice *slice, QLegend *legend) :
87 QPieLegendMarkerPrivate::QPieLegendMarkerPrivate(QPieLegendMarker *q, QPieSeries *series, QPieSlice *slice, QLegend *legend) :
88 QLegendMarkerPrivate(q,legend),
88 QLegendMarkerPrivate(q,legend),
89 q_ptr(q),
89 q_ptr(q),
90 m_series(series),
90 m_series(series),
91 m_slice(slice)
91 m_slice(slice)
92 {
92 {
93 QObject::connect(m_slice, SIGNAL(labelChanged()), this, SLOT(updated()));
93 QObject::connect(m_slice, SIGNAL(labelChanged()), this, SLOT(updated()));
94 QObject::connect(m_slice, SIGNAL(brushChanged()), this, SLOT(updated()));
94 QObject::connect(m_slice, SIGNAL(brushChanged()), this, SLOT(updated()));
95 QObject::connect(m_slice, SIGNAL(penChanged()), this, SLOT(updated()));
95 QObject::connect(m_slice, SIGNAL(penChanged()), this, SLOT(updated()));
96 }
96 }
97
97
98 QPieLegendMarkerPrivate::~QPieLegendMarkerPrivate()
98 QPieLegendMarkerPrivate::~QPieLegendMarkerPrivate()
99 {
99 {
100 }
100 }
101
101
102 QPieSeries* QPieLegendMarkerPrivate::series()
102 QPieSeries* QPieLegendMarkerPrivate::series()
103 {
103 {
104 return m_series;
104 return m_series;
105 }
105 }
106
106
107 QObject* QPieLegendMarkerPrivate::relatedObject()
107 QObject* QPieLegendMarkerPrivate::relatedObject()
108 {
108 {
109 return m_slice;
109 return m_slice;
110 }
110 }
111
111
112 void QPieLegendMarkerPrivate::updated()
112 void QPieLegendMarkerPrivate::updated()
113 {
113 {
114 bool labelChanged = false;
114 bool labelChanged = false;
115 bool brushChanged = false;
115 bool brushChanged = false;
116 bool penChanged = false;
116 bool penChanged = false;
117
117
118 if (!m_customPen && (m_item->pen() != m_slice->pen())) {
118 if (!m_customPen && (m_item->pen() != m_slice->pen())) {
119 m_item->setPen(m_slice->pen());
119 m_item->setPen(m_slice->pen());
120 penChanged = true;
120 penChanged = true;
121 }
121 }
122 if (!m_customBrush && (m_item->brush() != m_slice->brush())) {
122 if (!m_customBrush && (m_item->brush() != m_slice->brush())) {
123 m_item->setBrush(m_slice->brush());
123 m_item->setBrush(m_slice->brush());
124 brushChanged = true;
124 brushChanged = true;
125 }
125 }
126 if (!m_customLabel && (m_item->label() != m_slice->label())) {
126 if (!m_customLabel && (m_item->label() != m_slice->label())) {
127 m_item->setLabel(m_slice->label());
127 m_item->setLabel(m_slice->label());
128 labelChanged = true;
128 labelChanged = true;
129 }
129 }
130 invalidateLegend();
130 invalidateLegend();
131
131
132 if (labelChanged)
132 if (labelChanged)
133 emit q_ptr->labelChanged();
133 emit q_ptr->labelChanged();
134 if (brushChanged)
134 if (brushChanged)
135 emit q_ptr->brushChanged();
135 emit q_ptr->brushChanged();
136 if (penChanged)
136 if (penChanged)
137 emit q_ptr->penChanged();
137 emit q_ptr->penChanged();
138 }
138 }
139
139
140 #include "moc_qpielegendmarker.cpp"
140 #include "moc_qpielegendmarker.cpp"
141 #include "moc_qpielegendmarker_p.cpp"
141 #include "moc_qpielegendmarker_p.cpp"
142
142
143 QTCOMMERCIALCHART_END_NAMESPACE
143 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,137 +1,137
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qxylegendmarker.h"
21 #include "qxylegendmarker.h"
22 #include "qxylegendmarker_p.h"
22 #include "qxylegendmarker_p.h"
23 #include "qxyseries_p.h"
23 #include "qxyseries_p.h"
24 #include <QXYSeries>
24 #include <QXYSeries>
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 /*!
28 /*!
29 \class QXYLegendMarker
29 \class QXYLegendMarker
30 \brief QXYLegendMarker object
30 \brief QXYLegendMarker object.
31 \mainclass
31 \mainclass
32
32
33 QXYLegendMarker is related to QXYSeries derived classes. Each marker is related to one series.
33 QXYLegendMarker is related to QXYSeries derived classes. Each marker is related to one series.
34
34
35 \sa QLegend QXYSeries QSplineSeries QScatterSeries QLineSeries
35 \sa QLegend QXYSeries QSplineSeries QScatterSeries QLineSeries
36 */
36 */
37
37
38 /*!
38 /*!
39 \fn virtual LegendMarkerType QXYLegendMarker::type()
39 \fn virtual LegendMarkerType QXYLegendMarker::type()
40 Returns QLegendMarker::LegendMarkerTypeXY
40 Returns QLegendMarker::LegendMarkerTypeXY
41 */
41 */
42
42
43 /*!
43 /*!
44 \internal
44 \internal
45 */
45 */
46 QXYLegendMarker::QXYLegendMarker(QXYSeries *series, QLegend *legend, QObject *parent) :
46 QXYLegendMarker::QXYLegendMarker(QXYSeries *series, QLegend *legend, QObject *parent) :
47 QLegendMarker(*new QXYLegendMarkerPrivate(this,series,legend), parent)
47 QLegendMarker(*new QXYLegendMarkerPrivate(this,series,legend), parent)
48 {
48 {
49 d_ptr->updated();
49 d_ptr->updated();
50 }
50 }
51
51
52 /*!
52 /*!
53 Destructor
53 Destructor
54 */
54 */
55 QXYLegendMarker::~QXYLegendMarker()
55 QXYLegendMarker::~QXYLegendMarker()
56 {
56 {
57 }
57 }
58
58
59 /*!
59 /*!
60 \internal
60 \internal
61 */
61 */
62 QXYLegendMarker::QXYLegendMarker(QXYLegendMarkerPrivate &d, QObject *parent) :
62 QXYLegendMarker::QXYLegendMarker(QXYLegendMarkerPrivate &d, QObject *parent) :
63 QLegendMarker(d, parent)
63 QLegendMarker(d, parent)
64 {
64 {
65 }
65 }
66
66
67 /*!
67 /*!
68 Returns the related series
68 Returns the related series
69 */
69 */
70 QXYSeries* QXYLegendMarker::series()
70 QXYSeries* QXYLegendMarker::series()
71 {
71 {
72 Q_D(QXYLegendMarker);
72 Q_D(QXYLegendMarker);
73 return d->m_series;
73 return d->m_series;
74 }
74 }
75
75
76 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
76 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
77
77
78 QXYLegendMarkerPrivate::QXYLegendMarkerPrivate(QXYLegendMarker *q, QXYSeries *series, QLegend *legend) :
78 QXYLegendMarkerPrivate::QXYLegendMarkerPrivate(QXYLegendMarker *q, QXYSeries *series, QLegend *legend) :
79 QLegendMarkerPrivate(q,legend),
79 QLegendMarkerPrivate(q,legend),
80 q_ptr(q),
80 q_ptr(q),
81 m_series(series)
81 m_series(series)
82 {
82 {
83 QObject::connect(m_series, SIGNAL(nameChanged()), this, SLOT(updated()));
83 QObject::connect(m_series, SIGNAL(nameChanged()), this, SLOT(updated()));
84 QObject::connect(m_series->d_func(), SIGNAL(updated()), this, SLOT(updated()));
84 QObject::connect(m_series->d_func(), SIGNAL(updated()), this, SLOT(updated()));
85 }
85 }
86
86
87 QXYLegendMarkerPrivate::~QXYLegendMarkerPrivate()
87 QXYLegendMarkerPrivate::~QXYLegendMarkerPrivate()
88 {
88 {
89 }
89 }
90
90
91 QAbstractSeries* QXYLegendMarkerPrivate::series()
91 QAbstractSeries* QXYLegendMarkerPrivate::series()
92 {
92 {
93 return m_series;
93 return m_series;
94 }
94 }
95
95
96 QObject* QXYLegendMarkerPrivate::relatedObject()
96 QObject* QXYLegendMarkerPrivate::relatedObject()
97 {
97 {
98 return m_series;
98 return m_series;
99 }
99 }
100
100
101 void QXYLegendMarkerPrivate::updated()
101 void QXYLegendMarkerPrivate::updated()
102 {
102 {
103 bool labelChanged = false;
103 bool labelChanged = false;
104 bool brushChanged = false;
104 bool brushChanged = false;
105
105
106 if (!m_customLabel && (m_item->label() != m_series->name())) {
106 if (!m_customLabel && (m_item->label() != m_series->name())) {
107 m_item->setLabel(m_series->name());
107 m_item->setLabel(m_series->name());
108 labelChanged = true;
108 labelChanged = true;
109 }
109 }
110
110
111 if (m_series->type()== QAbstractSeries::SeriesTypeScatter) {
111 if (m_series->type()== QAbstractSeries::SeriesTypeScatter) {
112 if (!m_customBrush && (m_item->brush() != m_series->brush())) {
112 if (!m_customBrush && (m_item->brush() != m_series->brush())) {
113 m_item->setBrush(m_series->brush());
113 m_item->setBrush(m_series->brush());
114 brushChanged = true;
114 brushChanged = true;
115 }
115 }
116 } else {
116 } else {
117 QBrush emptyBrush;
117 QBrush emptyBrush;
118 if (!m_customBrush
118 if (!m_customBrush
119 && (m_item->brush() == emptyBrush
119 && (m_item->brush() == emptyBrush
120 || m_item->brush().color() != m_series->pen().color())) {
120 || m_item->brush().color() != m_series->pen().color())) {
121 m_item->setBrush(QBrush(m_series->pen().color()));
121 m_item->setBrush(QBrush(m_series->pen().color()));
122 brushChanged = true;
122 brushChanged = true;
123 }
123 }
124 }
124 }
125 invalidateLegend();
125 invalidateLegend();
126
126
127 if (labelChanged)
127 if (labelChanged)
128 emit q_ptr->labelChanged();
128 emit q_ptr->labelChanged();
129 if (brushChanged)
129 if (brushChanged)
130 emit q_ptr->brushChanged();
130 emit q_ptr->brushChanged();
131 }
131 }
132
132
133 #include "moc_qxylegendmarker.cpp"
133 #include "moc_qxylegendmarker.cpp"
134 #include "moc_qxylegendmarker_p.cpp"
134 #include "moc_qxylegendmarker_p.cpp"
135
135
136 QTCOMMERCIALCHART_END_NAMESPACE
136 QTCOMMERCIALCHART_END_NAMESPACE
137
137
@@ -1,257 +1,261
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qhpiemodelmapper.h"
21 #include "qhpiemodelmapper.h"
22
22
23 QTCOMMERCIALCHART_BEGIN_NAMESPACE
23 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24
24
25 /*!
25 /*!
26 \class QHPieModelMapper
26 \class QHPieModelMapper
27 \mainclass
27 \mainclass
28
28
29 Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series.
29 Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series.
30 Horizontal model mapper is used to create a connection between QPieSeries and QAbstractItemModel derived model object that keeps the consecutive pie slices data in rows.
30 Horizontal model mapper is used to create a connection between QPieSeries and QAbstractItemModel derived model object that keeps the consecutive pie slices data in rows.
31 It is possible to use both QAbstractItemModel and QPieSeries model API. QHPieModelMapper makes sure that Pie and the model are kept in sync.
31 It is possible to use both QAbstractItemModel and QPieSeries model API. QHPieModelMapper makes sure that Pie and the model are kept in sync.
32 \note Used model has to support adding/removing rows/columns and modifying the data of the cells.
32 \note Used model has to support adding/removing rows/columns and modifying the data of the cells.
33 */
33 */
34 /*!
34 /*!
35 \qmlclass HPieModelMapper QHPieModelMapper
35 \qmlclass HPieModelMapper QHPieModelMapper
36
36
37 HPieModelMapper allows you to use your own QAbstractItemModel derived model with data in rows as a data source
37 HPieModelMapper allows you to use your own QAbstractItemModel derived model with data in rows as a data source
38 for a pie series. It is possible to use both QAbstractItemModel and PieSeries data API to manipulate data.
38 for a pie series. It is possible to use both QAbstractItemModel and PieSeries data API to manipulate data.
39 HPieModelMapper keeps the Pie and the model in sync.
39 HPieModelMapper keeps the Pie and the model in sync.
40
40
41 The following QML example would create a pie series with four slices (assuming the model has
41 The following QML example would create a pie series with four slices (assuming the model has
42 at least five columns). Each slice would contain a label from row 1 and a value from row 2.
42 at least five columns). Each slice would contain a label from row 1 and a value from row 2.
43 \code
43 \code
44 HPieModelMapper {
44 HPieModelMapper {
45 series: pieSeries
45 series: pieSeries
46 model: customModel
46 model: customModel
47 labelsRow: 1
47 labelsRow: 1
48 valuesRow: 2
48 valuesRow: 2
49 firstColumn: 1
49 firstColumn: 1
50 columnCount: 4
50 columnCount: 4
51 }
51 }
52 \endcode
52 \endcode
53 */
53 */
54
54
55 /*!
55 /*!
56 \property QHPieModelMapper::series
56 \property QHPieModelMapper::series
57 \brief Defines the QPieSeries object that is used by the mapper.
57 \brief Defines the QPieSeries object that is used by the mapper.
58
58
59 All the data in the series is discarded when it is set to the mapper.
59 All the data in the series is discarded when it is set to the mapper.
60 When new series is specified the old series is disconnected (it preserves its data)
60 When new series is specified the old series is disconnected (it preserves its data)
61 */
61 */
62 /*!
62 /*!
63 \qmlproperty PieSeries HPieModelMapper::series
63 \qmlproperty PieSeries HPieModelMapper::series
64 Defines the PieSeries object that is used by the mapper. If you define the mapper element as a child for a
64 Defines the PieSeries object that is used by the mapper. If you define the mapper element as a child for a
65 PieSeries, leave this property undefined. All the data in the series is discarded when it is set to the mapper.
65 PieSeries, leave this property undefined. All the data in the series is discarded when it is set to the mapper.
66 When new series is specified the old series is disconnected (it preserves its data).
66 When new series is specified the old series is disconnected (it preserves its data).
67 */
67 */
68
68
69 /*!
69 /*!
70 \property QHPieModelMapper::model
70 \property QHPieModelMapper::model
71 \brief Defines the model that is used by the mapper.
71 \brief Defines the model that is used by the mapper.
72 */
72 */
73 /*!
73 /*!
74 \qmlproperty SomeModel HPieModelMapper::model
74 \qmlproperty SomeModel HPieModelMapper::model
75 The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to
75 The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to
76 QML as shown in \l {QML Custom Model} demo application. Note: the model has to support adding/removing rows/columns
76 QML as shown in \l {QML Custom Model} demo application. Note: the model has to support adding/removing rows/columns
77 and modifying the data of the cells.
77 and modifying the data of the cells.
78 */
78 */
79
79
80 /*!
80 /*!
81 \property QHPieModelMapper::valuesRow
81 \property QHPieModelMapper::valuesRow
82 \brief Defines which row of the model is kept in sync with the values of the pie's slices
82 \brief Defines which row of the model is kept in sync with the values of the pie's slices.
83
83 Default value is: -1 (invalid mapping)
84 Default value is: -1 (invalid mapping)
84 */
85 */
85 /*!
86 /*!
86 \qmlproperty int HPieModelMapper::valuesRow
87 \qmlproperty int HPieModelMapper::valuesRow
87 Defines which row of the model is kept in sync with the values of the pie's slices. Default value is: -1 (invalid
88 Defines which row of the model is kept in sync with the values of the pie's slices. Default value is: -1 (invalid
88 mapping).
89 mapping).
89 */
90 */
90
91
91 /*!
92 /*!
92 \property QHPieModelMapper::labelsRow
93 \property QHPieModelMapper::labelsRow
93 \brief Defines which row of the model is kept in sync with the labels of the pie's slices
94 \brief Defines which row of the model is kept in sync with the labels of the pie's slices.
95
94 Default value is: -1 (invalid mapping)
96 Default value is: -1 (invalid mapping)
95 */
97 */
96 /*!
98 /*!
97 \qmlproperty int HPieModelMapper::labelsRow
99 \qmlproperty int HPieModelMapper::labelsRow
98 Defines which row of the model is kept in sync with the labels of the pie's slices
100 Defines which row of the model is kept in sync with the labels of the pie's slices
99 Default value is: -1 (invalid mapping)
101 Default value is: -1 (invalid mapping)
100 */
102 */
101
103
102 /*!
104 /*!
103 \property QHPieModelMapper::firstColumn
105 \property QHPieModelMapper::firstColumn
104 \brief Defines which column of the model contains the first slice value.
106 \brief Defines which column of the model contains the first slice value.
107
105 Minimal and default value is: 0
108 Minimal and default value is: 0
106 */
109 */
107 /*!
110 /*!
108 \qmlproperty int HPieModelMapper::firstColumn
111 \qmlproperty int HPieModelMapper::firstColumn
109 Defines which column of the model contains the first slice value.
112 Defines which column of the model contains the first slice value.
110 The default value is 0.
113 The default value is 0.
111 */
114 */
112
115
113 /*!
116 /*!
114 \property QHPieModelMapper::columnCount
117 \property QHPieModelMapper::columnCount
115 \brief Defines the number of columns of the model that are mapped as the data for QPieSeries
118 \brief Defines the number of columns of the model that are mapped as the data for QPieSeries.
119
116 Minimal and default value is: -1 (count limited by the number of columns in the model)
120 Minimal and default value is: -1 (count limited by the number of columns in the model)
117 */
121 */
118 /*!
122 /*!
119 \qmlproperty int HPieModelMapper::columnCount
123 \qmlproperty int HPieModelMapper::columnCount
120 Defines the number of columns of the model that are mapped as the data for QPieSeries. The default value is
124 Defines the number of columns of the model that are mapped as the data for QPieSeries. The default value is
121 -1 (count limited by the number of columns in the model)
125 -1 (count limited by the number of columns in the model)
122 */
126 */
123
127
124 /*!
128 /*!
125 \fn void QHPieModelMapper::seriesReplaced()
129 \fn void QHPieModelMapper::seriesReplaced()
126 Emitted when the series to which mapper is connected to has changed.
130 Emitted when the series to which mapper is connected to has changed.
127 */
131 */
128
132
129 /*!
133 /*!
130 \fn void QHPieModelMapper::modelReplaced()
134 \fn void QHPieModelMapper::modelReplaced()
131 Emitted when the model to which mapper is connected to has changed.
135 Emitted when the model to which mapper is connected to has changed.
132 */
136 */
133
137
134 /*!
138 /*!
135 \fn void QHPieModelMapper::valuesRowChanged()
139 \fn void QHPieModelMapper::valuesRowChanged()
136 Emitted when the valuesRow has changed.
140 Emitted when the valuesRow has changed.
137 */
141 */
138
142
139 /*!
143 /*!
140 \fn void QHPieModelMapper::labelsRowChanged()
144 \fn void QHPieModelMapper::labelsRowChanged()
141 Emitted when the labelsRow has changed.
145 Emitted when the labelsRow has changed.
142 */
146 */
143
147
144 /*!
148 /*!
145 \fn void QHPieModelMapper::firstColumnChanged()
149 \fn void QHPieModelMapper::firstColumnChanged()
146 Emitted when the firstColumn has changed.
150 Emitted when the firstColumn has changed.
147 */
151 */
148
152
149 /*!
153 /*!
150 \fn void QHPieModelMapper::columnCountChanged()
154 \fn void QHPieModelMapper::columnCountChanged()
151 Emitted when the columnCount has changed.
155 Emitted when the columnCount has changed.
152 */
156 */
153
157
154 /*!
158 /*!
155 Constructs a mapper object which is a child of \a parent.
159 Constructs a mapper object which is a child of \a parent.
156 */
160 */
157 QHPieModelMapper::QHPieModelMapper(QObject *parent) :
161 QHPieModelMapper::QHPieModelMapper(QObject *parent) :
158 QPieModelMapper(parent)
162 QPieModelMapper(parent)
159 {
163 {
160 setOrientation(Qt::Horizontal);
164 setOrientation(Qt::Horizontal);
161 }
165 }
162
166
163 QAbstractItemModel *QHPieModelMapper::model() const
167 QAbstractItemModel *QHPieModelMapper::model() const
164 {
168 {
165 return QPieModelMapper::model();
169 return QPieModelMapper::model();
166 }
170 }
167
171
168 void QHPieModelMapper::setModel(QAbstractItemModel *model)
172 void QHPieModelMapper::setModel(QAbstractItemModel *model)
169 {
173 {
170 if (model != QPieModelMapper::model()) {
174 if (model != QPieModelMapper::model()) {
171 QPieModelMapper::setModel(model);
175 QPieModelMapper::setModel(model);
172 emit modelReplaced();
176 emit modelReplaced();
173 }
177 }
174 }
178 }
175
179
176 QPieSeries *QHPieModelMapper::series() const
180 QPieSeries *QHPieModelMapper::series() const
177 {
181 {
178 return QPieModelMapper::series();
182 return QPieModelMapper::series();
179 }
183 }
180
184
181 void QHPieModelMapper::setSeries(QPieSeries *series)
185 void QHPieModelMapper::setSeries(QPieSeries *series)
182 {
186 {
183 if (series != QPieModelMapper::series()) {
187 if (series != QPieModelMapper::series()) {
184 QPieModelMapper::setSeries(series);
188 QPieModelMapper::setSeries(series);
185 emit seriesReplaced();
189 emit seriesReplaced();
186 }
190 }
187 }
191 }
188
192
189 /*!
193 /*!
190 Returns which row of the model is kept in sync with the values of the pie's slices
194 Returns which row of the model is kept in sync with the values of the pie's slices
191 */
195 */
192 int QHPieModelMapper::valuesRow() const
196 int QHPieModelMapper::valuesRow() const
193 {
197 {
194 return valuesSection();
198 return valuesSection();
195 }
199 }
196
200
197 /*!
201 /*!
198 Sets the model row that is kept in sync with the pie slices values.
202 Sets the model row that is kept in sync with the pie slices values.
199 Parameter \a valuesRow specifies the row of the model.
203 Parameter \a valuesRow specifies the row of the model.
200 */
204 */
201 void QHPieModelMapper::setValuesRow(int valuesRow)
205 void QHPieModelMapper::setValuesRow(int valuesRow)
202 {
206 {
203 if (valuesRow != valuesSection()) {
207 if (valuesRow != valuesSection()) {
204 setValuesSection(valuesRow);
208 setValuesSection(valuesRow);
205 emit valuesRowChanged();
209 emit valuesRowChanged();
206 }
210 }
207 }
211 }
208
212
209 /*!
213 /*!
210 Returns which row of the model is kept in sync with the labels of the pie's slices
214 Returns which row of the model is kept in sync with the labels of the pie's slices
211 */
215 */
212 int QHPieModelMapper::labelsRow() const
216 int QHPieModelMapper::labelsRow() const
213 {
217 {
214 return labelsSection();
218 return labelsSection();
215 }
219 }
216
220
217 /*!
221 /*!
218 Sets the model row that is kept in sync with the pie's slices labels.
222 Sets the model row that is kept in sync with the pie's slices labels.
219 Parameter \a labelsRow specifies the row of the model.
223 Parameter \a labelsRow specifies the row of the model.
220 */
224 */
221 void QHPieModelMapper::setLabelsRow(int labelsRow)
225 void QHPieModelMapper::setLabelsRow(int labelsRow)
222 {
226 {
223 if (labelsRow != labelsSection()) {
227 if (labelsRow != labelsSection()) {
224 setLabelsSection(labelsRow);
228 setLabelsSection(labelsRow);
225 emit labelsRowChanged();
229 emit labelsRowChanged();
226 }
230 }
227 }
231 }
228
232
229 int QHPieModelMapper::firstColumn() const
233 int QHPieModelMapper::firstColumn() const
230 {
234 {
231 return first();
235 return first();
232 }
236 }
233
237
234 void QHPieModelMapper::setFirstColumn(int firstColumn)
238 void QHPieModelMapper::setFirstColumn(int firstColumn)
235 {
239 {
236 if (firstColumn != first()) {
240 if (firstColumn != first()) {
237 setFirst(firstColumn);
241 setFirst(firstColumn);
238 emit firstColumnChanged();
242 emit firstColumnChanged();
239 }
243 }
240 }
244 }
241
245
242 int QHPieModelMapper::columnCount() const
246 int QHPieModelMapper::columnCount() const
243 {
247 {
244 return count();
248 return count();
245 }
249 }
246
250
247 void QHPieModelMapper::setColumnCount(int columnCount)
251 void QHPieModelMapper::setColumnCount(int columnCount)
248 {
252 {
249 if (columnCount != count()) {
253 if (columnCount != count()) {
250 setCount(columnCount);
254 setCount(columnCount);
251 emit columnCountChanged();
255 emit columnCountChanged();
252 }
256 }
253 }
257 }
254
258
255 #include "moc_qhpiemodelmapper.cpp"
259 #include "moc_qhpiemodelmapper.cpp"
256
260
257 QTCOMMERCIALCHART_END_NAMESPACE
261 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,937 +1,937
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "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 "qabstractaxis.h"
28 #include "qabstractaxis.h"
29 #include "pieanimation_p.h"
29 #include "pieanimation_p.h"
30 #include "charthelpers_p.h"
30 #include "charthelpers_p.h"
31
31
32 #include "qpielegendmarker.h"
32 #include "qpielegendmarker.h"
33
33
34 QTCOMMERCIALCHART_BEGIN_NAMESPACE
34 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35
35
36 /*!
36 /*!
37 \class QPieSeries
37 \class QPieSeries
38 \brief Pie series API for QtCommercial Charts
38 \brief Pie series API for QtCommercial Charts.
39
39
40 The pie series defines a pie chart which consists of pie slices which are defined as QPieSlice objects.
40 The pie series defines a pie chart which consists of pie slices which are defined as QPieSlice objects.
41 The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices.
41 The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices.
42 The actual slice size is determined by that relative value.
42 The actual slice size is determined by that relative value.
43
43
44 Pie size and position on the chart is controlled by using relative values which range from 0.0 to 1.0.
44 Pie size and position on the chart is controlled by using relative values which range from 0.0 to 1.0.
45 These relate to the actual chart rectangle.
45 These relate to the actual chart rectangle.
46
46
47 By default the pie is defined as a full pie but it can also be a partial pie.
47 By default the pie is defined as a full pie but it can also be a partial pie.
48 This can be done by setting a starting angle and angle span to the series.
48 This can be done by setting a starting angle and angle span to the series.
49 Full pie is 360 degrees where 0 is at 12 a'clock.
49 Full pie is 360 degrees where 0 is at 12 a'clock.
50
50
51 See the \l {PieChart Example} {pie chart example} or \l {DonutChart Example} {donut chart example} to learn how to use QPieSeries.
51 See the \l {PieChart Example} {pie chart example} or \l {DonutChart Example} {donut chart example} to learn how to use QPieSeries.
52 \table 100%
52 \table 100%
53 \row
53 \row
54 \o \image examples_piechart.png
54 \o \image examples_piechart.png
55 \o \image examples_donutchart.png
55 \o \image examples_donutchart.png
56 \endtable
56 \endtable
57 */
57 */
58 /*!
58 /*!
59 \qmlclass PieSeries QPieSeries
59 \qmlclass PieSeries QPieSeries
60 \inherits AbstractSeries
60 \inherits AbstractSeries
61
61
62 The following QML shows how to create a simple pie chart.
62 The following QML shows how to create a simple pie chart.
63
63
64 \snippet ../demos/qmlchart/qml/qmlchart/View1.qml 1
64 \snippet ../demos/qmlchart/qml/qmlchart/View1.qml 1
65
65
66 \beginfloatleft
66 \beginfloatleft
67 \image demos_qmlchart1.png
67 \image demos_qmlchart1.png
68 \endfloat
68 \endfloat
69 \clearfloat
69 \clearfloat
70 */
70 */
71
71
72 /*!
72 /*!
73 \property QPieSeries::horizontalPosition
73 \property QPieSeries::horizontalPosition
74 \brief Defines the horizontal position of the pie.
74 \brief Defines the horizontal position of the pie.
75
75
76 The value is a relative value to the chart rectangle where:
76 The value is a relative value to the chart rectangle where:
77
77
78 \list
78 \list
79 \o 0.0 is the absolute left.
79 \o 0.0 is the absolute left.
80 \o 1.0 is the absolute right.
80 \o 1.0 is the absolute right.
81 \endlist
81 \endlist
82 Default value is 0.5 (center).
82 Default value is 0.5 (center).
83 \sa verticalPosition
83 \sa verticalPosition
84 */
84 */
85
85
86 /*!
86 /*!
87 \qmlproperty real PieSeries::horizontalPosition
87 \qmlproperty real PieSeries::horizontalPosition
88
88
89 Defines the horizontal position of the pie.
89 Defines the horizontal position of the pie.
90
90
91 The value is a relative value to the chart rectangle where:
91 The value is a relative value to the chart rectangle where:
92
92
93 \list
93 \list
94 \o 0.0 is the absolute left.
94 \o 0.0 is the absolute left.
95 \o 1.0 is the absolute right.
95 \o 1.0 is the absolute right.
96 \endlist
96 \endlist
97 Default value is 0.5 (center).
97 Default value is 0.5 (center).
98 \sa verticalPosition
98 \sa verticalPosition
99 */
99 */
100
100
101 /*!
101 /*!
102 \property QPieSeries::verticalPosition
102 \property QPieSeries::verticalPosition
103 \brief Defines the vertical position of the pie.
103 \brief Defines the vertical position of the pie.
104
104
105 The value is a relative value to the chart rectangle where:
105 The value is a relative value to the chart rectangle where:
106
106
107 \list
107 \list
108 \o 0.0 is the absolute top.
108 \o 0.0 is the absolute top.
109 \o 1.0 is the absolute bottom.
109 \o 1.0 is the absolute bottom.
110 \endlist
110 \endlist
111 Default value is 0.5 (center).
111 Default value is 0.5 (center).
112 \sa horizontalPosition
112 \sa horizontalPosition
113 */
113 */
114
114
115 /*!
115 /*!
116 \qmlproperty real PieSeries::verticalPosition
116 \qmlproperty real PieSeries::verticalPosition
117
117
118 Defines the vertical position of the pie.
118 Defines the vertical position of the pie.
119
119
120 The value is a relative value to the chart rectangle where:
120 The value is a relative value to the chart rectangle where:
121
121
122 \list
122 \list
123 \o 0.0 is the absolute top.
123 \o 0.0 is the absolute top.
124 \o 1.0 is the absolute bottom.
124 \o 1.0 is the absolute bottom.
125 \endlist
125 \endlist
126 Default value is 0.5 (center).
126 Default value is 0.5 (center).
127 \sa horizontalPosition
127 \sa horizontalPosition
128 */
128 */
129
129
130 /*!
130 /*!
131 \property QPieSeries::size
131 \property QPieSeries::size
132 \brief Defines the pie size.
132 \brief Defines the pie size.
133
133
134 The value is a relative value to the chart rectangle where:
134 The value is a relative value to the chart rectangle where:
135
135
136 \list
136 \list
137 \o 0.0 is the minimum size (pie not drawn).
137 \o 0.0 is the minimum size (pie not drawn).
138 \o 1.0 is the maximum size that can fit the chart.
138 \o 1.0 is the maximum size that can fit the chart.
139 \endlist
139 \endlist
140
140
141 When setting this property the holeSize property is adjusted if necessary, to ensure that the hole size is not greater than the outer size.
141 When setting this property the holeSize property is adjusted if necessary, to ensure that the hole size is not greater than the outer size.
142
142
143 Default value is 0.7.
143 Default value is 0.7.
144 */
144 */
145
145
146 /*!
146 /*!
147 \qmlproperty real PieSeries::size
147 \qmlproperty real PieSeries::size
148
148
149 Defines the pie size.
149 Defines the pie size.
150
150
151 The value is a relative value to the chart rectangle where:
151 The value is a relative value to the chart rectangle where:
152
152
153 \list
153 \list
154 \o 0.0 is the minimum size (pie not drawn).
154 \o 0.0 is the minimum size (pie not drawn).
155 \o 1.0 is the maximum size that can fit the chart.
155 \o 1.0 is the maximum size that can fit the chart.
156 \endlist
156 \endlist
157
157
158 Default value is 0.7.
158 Default value is 0.7.
159 */
159 */
160
160
161 /*!
161 /*!
162 \property QPieSeries::holeSize
162 \property QPieSeries::holeSize
163 \brief Defines the donut hole size.
163 \brief Defines the donut hole size.
164
164
165 The value is a relative value to the chart rectangle where:
165 The value is a relative value to the chart rectangle where:
166
166
167 \list
167 \list
168 \o 0.0 is the minimum size (full pie drawn, without any hole inside).
168 \o 0.0 is the minimum size (full pie drawn, without any hole inside).
169 \o 1.0 is the maximum size that can fit the chart. (donut has no width)
169 \o 1.0 is the maximum size that can fit the chart. (donut has no width)
170 \endlist
170 \endlist
171
171
172 The value is never greater then size property.
172 The value is never greater then size property.
173 Default value is 0.0.
173 Default value is 0.0.
174 */
174 */
175
175
176 /*!
176 /*!
177 \qmlproperty real PieSeries::holeSize
177 \qmlproperty real PieSeries::holeSize
178
178
179 Defines the donut hole size.
179 Defines the donut hole size.
180
180
181 The value is a relative value to the chart rectangle where:
181 The value is a relative value to the chart rectangle where:
182
182
183 \list
183 \list
184 \o 0.0 is the minimum size (full pie drawn, without any hole inside).
184 \o 0.0 is the minimum size (full pie drawn, without any hole inside).
185 \o 1.0 is the maximum size that can fit the chart. (donut has no width)
185 \o 1.0 is the maximum size that can fit the chart. (donut has no width)
186 \endlist
186 \endlist
187
187
188 When setting this property the size property is adjusted if necessary, to ensure that the inner size is not greater than the outer size.
188 When setting this property the size property is adjusted if necessary, to ensure that the inner size is not greater than the outer size.
189
189
190 Default value is 0.0.
190 Default value is 0.0.
191 */
191 */
192
192
193 /*!
193 /*!
194 \property QPieSeries::startAngle
194 \property QPieSeries::startAngle
195 \brief Defines the starting angle of the pie.
195 \brief Defines the starting angle of the pie.
196
196
197 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
197 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
198
198
199 Default is value is 0.
199 Default is value is 0.
200 */
200 */
201
201
202 /*!
202 /*!
203 \qmlproperty real PieSeries::startAngle
203 \qmlproperty real PieSeries::startAngle
204
204
205 Defines the starting angle of the pie.
205 Defines the starting angle of the pie.
206
206
207 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
207 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
208
208
209 Default is value is 0.
209 Default is value is 0.
210 */
210 */
211
211
212 /*!
212 /*!
213 \property QPieSeries::endAngle
213 \property QPieSeries::endAngle
214 \brief Defines the ending angle of the pie.
214 \brief Defines the ending angle of the pie.
215
215
216 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
216 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
217
217
218 Default is value is 360.
218 Default is value is 360.
219 */
219 */
220
220
221 /*!
221 /*!
222 \qmlproperty real PieSeries::endAngle
222 \qmlproperty real PieSeries::endAngle
223
223
224 Defines the ending angle of the pie.
224 Defines the ending angle of the pie.
225
225
226 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
226 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
227
227
228 Default is value is 360.
228 Default is value is 360.
229 */
229 */
230
230
231 /*!
231 /*!
232 \property QPieSeries::count
232 \property QPieSeries::count
233
233
234 Number of slices in the series.
234 Number of slices in the series.
235 */
235 */
236
236
237 /*!
237 /*!
238 \qmlproperty int PieSeries::count
238 \qmlproperty int PieSeries::count
239
239
240 Number of slices in the series.
240 Number of slices in the series.
241 */
241 */
242
242
243 /*!
243 /*!
244 \fn void QPieSeries::countChanged()
244 \fn void QPieSeries::countChanged()
245 Emitted when the slice count has changed.
245 Emitted when the slice count has changed.
246 \sa count
246 \sa count
247 */
247 */
248 /*!
248 /*!
249 \qmlsignal PieSeries::onCountChanged()
249 \qmlsignal PieSeries::onCountChanged()
250 Emitted when the slice count has changed.
250 Emitted when the slice count has changed.
251 */
251 */
252
252
253 /*!
253 /*!
254 \property QPieSeries::sum
254 \property QPieSeries::sum
255
255
256 Sum of all slices.
256 Sum of all slices.
257
257
258 The series keeps track of the sum of all slices it holds.
258 The series keeps track of the sum of all slices it holds.
259 */
259 */
260
260
261 /*!
261 /*!
262 \qmlproperty real PieSeries::sum
262 \qmlproperty real PieSeries::sum
263
263
264 Sum of all slices.
264 Sum of all slices.
265
265
266 The series keeps track of the sum of all slices it holds.
266 The series keeps track of the sum of all slices it holds.
267 */
267 */
268
268
269 /*!
269 /*!
270 \fn void QPieSeries::sumChanged()
270 \fn void QPieSeries::sumChanged()
271 Emitted when the sum of all slices has changed.
271 Emitted when the sum of all slices has changed.
272 \sa sum
272 \sa sum
273 */
273 */
274 /*!
274 /*!
275 \qmlsignal PieSeries::onSumChanged()
275 \qmlsignal PieSeries::onSumChanged()
276 Emitted when the sum of all slices has changed. This may happen for example if you add or remove slices, or if you
276 Emitted when the sum of all slices has changed. This may happen for example if you add or remove slices, or if you
277 change value of a slice.
277 change value of a slice.
278 */
278 */
279
279
280 /*!
280 /*!
281 \fn void QPieSeries::added(QList<QPieSlice*> slices)
281 \fn void QPieSeries::added(QList<QPieSlice*> slices)
282
282
283 This signal is emitted when \a slices have been added to the series.
283 This signal is emitted when \a slices have been added to the series.
284
284
285 \sa append(), insert()
285 \sa append(), insert()
286 */
286 */
287 /*!
287 /*!
288 \qmlsignal PieSeries::onAdded(PieSlice slice)
288 \qmlsignal PieSeries::onAdded(PieSlice slice)
289 Emitted when \a slice has been added to the series.
289 Emitted when \a slice has been added to the series.
290 */
290 */
291
291
292 /*!
292 /*!
293 \fn void QPieSeries::removed(QList<QPieSlice*> slices)
293 \fn void QPieSeries::removed(QList<QPieSlice*> slices)
294 This signal is emitted when \a slices have been removed from the series.
294 This signal is emitted when \a slices have been removed from the series.
295 \sa remove()
295 \sa remove()
296 */
296 */
297 /*!
297 /*!
298 \qmlsignal PieSeries::onRemoved(PieSlice slice)
298 \qmlsignal PieSeries::onRemoved(PieSlice slice)
299 Emitted when \a slice has been removed from the series.
299 Emitted when \a slice has been removed from the series.
300 */
300 */
301
301
302 /*!
302 /*!
303 \fn void QPieSeries::clicked(QPieSlice* slice)
303 \fn void QPieSeries::clicked(QPieSlice* slice)
304 This signal is emitted when a \a slice has been clicked.
304 This signal is emitted when a \a slice has been clicked.
305 \sa QPieSlice::clicked()
305 \sa QPieSlice::clicked()
306 */
306 */
307 /*!
307 /*!
308 \qmlsignal PieSeries::onClicked(PieSlice slice)
308 \qmlsignal PieSeries::onClicked(PieSlice slice)
309 This signal is emitted when a \a slice has been clicked.
309 This signal is emitted when a \a slice has been clicked.
310 */
310 */
311
311
312 /*!
312 /*!
313 \fn void QPieSeries::hovered(QPieSlice* slice, bool state)
313 \fn void QPieSeries::hovered(QPieSlice* slice, bool state)
314 This signal is emitted when user has hovered over or away from the \a slice.
314 This signal is emitted when user has hovered over or away from the \a slice.
315 \a state is true when user has hovered over the slice and false when hover has moved away from the slice.
315 \a state is true when user has hovered over the slice and false when hover has moved away from the slice.
316 \sa QPieSlice::hovered()
316 \sa QPieSlice::hovered()
317 */
317 */
318 /*!
318 /*!
319 \qmlsignal PieSeries::onHovered(PieSlice slice, bool state)
319 \qmlsignal PieSeries::onHovered(PieSlice slice, bool state)
320 This signal is emitted when user has hovered over or away from the \a slice. \a state is true when user has hovered
320 This signal is emitted when user has hovered over or away from the \a slice. \a state is true when user has hovered
321 over the slice and false when hover has moved away from the slice.
321 over the slice and false when hover has moved away from the slice.
322 */
322 */
323
323
324 /*!
324 /*!
325 \qmlmethod PieSlice PieSeries::at(int index)
325 \qmlmethod PieSlice PieSeries::at(int index)
326 Returns slice at \a index. Returns null if the index is not valid.
326 Returns slice at \a index. Returns null if the index is not valid.
327 */
327 */
328
328
329 /*!
329 /*!
330 \qmlmethod PieSlice PieSeries::find(string label)
330 \qmlmethod PieSlice PieSeries::find(string label)
331 Returns the first slice with \a label. Returns null if the index is not valid.
331 Returns the first slice with \a label. Returns null if the index is not valid.
332 */
332 */
333
333
334 /*!
334 /*!
335 \qmlmethod PieSlice PieSeries::append(string label, real value)
335 \qmlmethod PieSlice PieSeries::append(string label, real value)
336 Adds a new slice with \a label and \a value to the pie.
336 Adds a new slice with \a label and \a value to the pie.
337 */
337 */
338
338
339 /*!
339 /*!
340 \qmlmethod bool PieSeries::remove(PieSlice slice)
340 \qmlmethod bool PieSeries::remove(PieSlice slice)
341 Removes the \a slice from the pie. Returns true if the removal was successful, false otherwise.
341 Removes the \a slice from the pie. Returns true if the removal was successful, false otherwise.
342 */
342 */
343
343
344 /*!
344 /*!
345 \qmlmethod PieSeries::clear()
345 \qmlmethod PieSeries::clear()
346 Removes all slices from the pie.
346 Removes all slices from the pie.
347 */
347 */
348
348
349 /*!
349 /*!
350 Constructs a series object which is a child of \a parent.
350 Constructs a series object which is a child of \a parent.
351 */
351 */
352 QPieSeries::QPieSeries(QObject *parent)
352 QPieSeries::QPieSeries(QObject *parent)
353 : QAbstractSeries(*new QPieSeriesPrivate(this), parent)
353 : QAbstractSeries(*new QPieSeriesPrivate(this), parent)
354 {
354 {
355 Q_D(QPieSeries);
355 Q_D(QPieSeries);
356 QObject::connect(this, SIGNAL(countChanged()), d, SIGNAL(countChanged()));
356 QObject::connect(this, SIGNAL(countChanged()), d, SIGNAL(countChanged()));
357 }
357 }
358
358
359 /*!
359 /*!
360 Destroys the series and its slices.
360 Destroys the series and its slices.
361 */
361 */
362 QPieSeries::~QPieSeries()
362 QPieSeries::~QPieSeries()
363 {
363 {
364 // NOTE: d_prt destroyed by QObject
364 // NOTE: d_prt destroyed by QObject
365 clear();
365 clear();
366 }
366 }
367
367
368 /*!
368 /*!
369 Returns QChartSeries::SeriesTypePie.
369 Returns QAbstractSeries::SeriesTypePie.
370 */
370 */
371 QAbstractSeries::SeriesType QPieSeries::type() const
371 QAbstractSeries::SeriesType QPieSeries::type() const
372 {
372 {
373 return QAbstractSeries::SeriesTypePie;
373 return QAbstractSeries::SeriesTypePie;
374 }
374 }
375
375
376 /*!
376 /*!
377 Appends a single \a slice to the series.
377 Appends a single \a slice to the series.
378 Slice ownership is passed to the series.
378 Slice ownership is passed to the series.
379
379
380 Returns true if append was succesfull.
380 Returns true if append was succesfull.
381 */
381 */
382 bool QPieSeries::append(QPieSlice *slice)
382 bool QPieSeries::append(QPieSlice *slice)
383 {
383 {
384 return append(QList<QPieSlice *>() << slice);
384 return append(QList<QPieSlice *>() << slice);
385 }
385 }
386
386
387 /*!
387 /*!
388 Appends an array of \a slices to the series.
388 Appends an array of \a slices to the series.
389 Slice ownership is passed to the series.
389 Slice ownership is passed to the series.
390
390
391 Returns true if append was successful.
391 Returns true if append was successful.
392 */
392 */
393 bool QPieSeries::append(QList<QPieSlice *> slices)
393 bool QPieSeries::append(QList<QPieSlice *> slices)
394 {
394 {
395 Q_D(QPieSeries);
395 Q_D(QPieSeries);
396
396
397 if (slices.count() == 0)
397 if (slices.count() == 0)
398 return false;
398 return false;
399
399
400 foreach (QPieSlice *s, slices) {
400 foreach (QPieSlice *s, slices) {
401 if (!s || d->m_slices.contains(s))
401 if (!s || d->m_slices.contains(s))
402 return false;
402 return false;
403 if (s->series()) // already added to some series
403 if (s->series()) // already added to some series
404 return false;
404 return false;
405 if (!isValidValue(s->value()))
405 if (!isValidValue(s->value()))
406 return false;
406 return false;
407 }
407 }
408
408
409 foreach (QPieSlice *s, slices) {
409 foreach (QPieSlice *s, slices) {
410 s->setParent(this);
410 s->setParent(this);
411 QPieSlicePrivate::fromSlice(s)->m_series = this;
411 QPieSlicePrivate::fromSlice(s)->m_series = this;
412 d->m_slices << s;
412 d->m_slices << s;
413 }
413 }
414
414
415 d->updateDerivativeData();
415 d->updateDerivativeData();
416
416
417 foreach(QPieSlice * s, slices) {
417 foreach(QPieSlice * s, slices) {
418 connect(s, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged()));
418 connect(s, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged()));
419 connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked()));
419 connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked()));
420 connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
420 connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
421 }
421 }
422
422
423 emit added(slices);
423 emit added(slices);
424 emit countChanged();
424 emit countChanged();
425
425
426 return true;
426 return true;
427 }
427 }
428
428
429 /*!
429 /*!
430 Appends a single \a slice to the series and returns a reference to the series.
430 Appends a single \a slice to the series and returns a reference to the series.
431 Slice ownership is passed to the series.
431 Slice ownership is passed to the series.
432 */
432 */
433 QPieSeries &QPieSeries::operator << (QPieSlice *slice)
433 QPieSeries &QPieSeries::operator << (QPieSlice *slice)
434 {
434 {
435 append(slice);
435 append(slice);
436 return *this;
436 return *this;
437 }
437 }
438
438
439
439
440 /*!
440 /*!
441 Appends a single slice to the series with give \a value and \a label.
441 Appends a single slice to the series with give \a value and \a label.
442 Slice ownership is passed to the series.
442 Slice ownership is passed to the series.
443 Returns NULL if value is NaN, Inf or -Inf and no slice is added to the series.
443 Returns NULL if value is NaN, Inf or -Inf and no slice is added to the series.
444 */
444 */
445 QPieSlice *QPieSeries::append(QString label, qreal value)
445 QPieSlice *QPieSeries::append(QString label, qreal value)
446 {
446 {
447 if (isValidValue(value)) {
447 if (isValidValue(value)) {
448 QPieSlice *slice = new QPieSlice(label, value);
448 QPieSlice *slice = new QPieSlice(label, value);
449 append(slice);
449 append(slice);
450 return slice;
450 return slice;
451 } else {
451 } else {
452 return 0;
452 return 0;
453 }
453 }
454 }
454 }
455
455
456 /*!
456 /*!
457 Inserts a single \a slice to the series before the slice at \a index position.
457 Inserts a single \a slice to the series before the slice at \a index position.
458 Slice ownership is passed to the series.
458 Slice ownership is passed to the series.
459
459
460 Returns true if insert was successful.
460 Returns true if insert was successful.
461 */
461 */
462 bool QPieSeries::insert(int index, QPieSlice *slice)
462 bool QPieSeries::insert(int index, QPieSlice *slice)
463 {
463 {
464 Q_D(QPieSeries);
464 Q_D(QPieSeries);
465
465
466 if (index < 0 || index > d->m_slices.count())
466 if (index < 0 || index > d->m_slices.count())
467 return false;
467 return false;
468
468
469 if (!slice || d->m_slices.contains(slice))
469 if (!slice || d->m_slices.contains(slice))
470 return false;
470 return false;
471
471
472 if (slice->series()) // already added to some series
472 if (slice->series()) // already added to some series
473 return false;
473 return false;
474
474
475 if (!isValidValue(slice->value()))
475 if (!isValidValue(slice->value()))
476 return false;
476 return false;
477
477
478 slice->setParent(this);
478 slice->setParent(this);
479 QPieSlicePrivate::fromSlice(slice)->m_series = this;
479 QPieSlicePrivate::fromSlice(slice)->m_series = this;
480 d->m_slices.insert(index, slice);
480 d->m_slices.insert(index, slice);
481
481
482 d->updateDerivativeData();
482 d->updateDerivativeData();
483
483
484 connect(slice, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged()));
484 connect(slice, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged()));
485 connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked()));
485 connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked()));
486 connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
486 connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
487
487
488 emit added(QList<QPieSlice *>() << slice);
488 emit added(QList<QPieSlice *>() << slice);
489 emit countChanged();
489 emit countChanged();
490
490
491 return true;
491 return true;
492 }
492 }
493
493
494 /*!
494 /*!
495 Removes a single \a slice from the series and deletes the slice.
495 Removes a single \a slice from the series and deletes the slice.
496
496
497 Do not reference the pointer after this call.
497 Do not reference the pointer after this call.
498
498
499 Returns true if remove was successful.
499 Returns true if remove was successful.
500 */
500 */
501 bool QPieSeries::remove(QPieSlice *slice)
501 bool QPieSeries::remove(QPieSlice *slice)
502 {
502 {
503 Q_D(QPieSeries);
503 Q_D(QPieSeries);
504
504
505 if (!d->m_slices.removeOne(slice))
505 if (!d->m_slices.removeOne(slice))
506 return false;
506 return false;
507
507
508 d->updateDerivativeData();
508 d->updateDerivativeData();
509
509
510 emit removed(QList<QPieSlice *>() << slice);
510 emit removed(QList<QPieSlice *>() << slice);
511 emit countChanged();
511 emit countChanged();
512
512
513 delete slice;
513 delete slice;
514 slice = 0;
514 slice = 0;
515
515
516 return true;
516 return true;
517 }
517 }
518
518
519 /*!
519 /*!
520 Takes a single \a slice from the series. Does not destroy the slice object.
520 Takes a single \a slice from the series. Does not destroy the slice object.
521
521
522 \note The series remains as the slice's parent object. You must set the
522 \note The series remains as the slice's parent object. You must set the
523 parent object to take full ownership.
523 parent object to take full ownership.
524
524
525 Returns true if take was successful.
525 Returns true if take was successful.
526 */
526 */
527 bool QPieSeries::take(QPieSlice *slice)
527 bool QPieSeries::take(QPieSlice *slice)
528 {
528 {
529 Q_D(QPieSeries);
529 Q_D(QPieSeries);
530
530
531 if (!d->m_slices.removeOne(slice))
531 if (!d->m_slices.removeOne(slice))
532 return false;
532 return false;
533
533
534 QPieSlicePrivate::fromSlice(slice)->m_series = 0;
534 QPieSlicePrivate::fromSlice(slice)->m_series = 0;
535 slice->disconnect(d);
535 slice->disconnect(d);
536
536
537 d->updateDerivativeData();
537 d->updateDerivativeData();
538
538
539 emit removed(QList<QPieSlice *>() << slice);
539 emit removed(QList<QPieSlice *>() << slice);
540 emit countChanged();
540 emit countChanged();
541
541
542 return true;
542 return true;
543 }
543 }
544
544
545 /*!
545 /*!
546 Clears all slices from the series.
546 Clears all slices from the series.
547 */
547 */
548 void QPieSeries::clear()
548 void QPieSeries::clear()
549 {
549 {
550 Q_D(QPieSeries);
550 Q_D(QPieSeries);
551 if (d->m_slices.count() == 0)
551 if (d->m_slices.count() == 0)
552 return;
552 return;
553
553
554 QList<QPieSlice *> slices = d->m_slices;
554 QList<QPieSlice *> slices = d->m_slices;
555 foreach (QPieSlice *s, d->m_slices)
555 foreach (QPieSlice *s, d->m_slices)
556 d->m_slices.removeOne(s);
556 d->m_slices.removeOne(s);
557
557
558 d->updateDerivativeData();
558 d->updateDerivativeData();
559
559
560 emit removed(slices);
560 emit removed(slices);
561 emit countChanged();
561 emit countChanged();
562
562
563 foreach (QPieSlice *s, slices)
563 foreach (QPieSlice *s, slices)
564 delete s;
564 delete s;
565 }
565 }
566
566
567 /*!
567 /*!
568 Returns a list of slices that belong to this series.
568 Returns a list of slices that belong to this series.
569 */
569 */
570 QList<QPieSlice *> QPieSeries::slices() const
570 QList<QPieSlice *> QPieSeries::slices() const
571 {
571 {
572 Q_D(const QPieSeries);
572 Q_D(const QPieSeries);
573 return d->m_slices;
573 return d->m_slices;
574 }
574 }
575
575
576 /*!
576 /*!
577 returns the number of the slices in this series.
577 returns the number of the slices in this series.
578 */
578 */
579 int QPieSeries::count() const
579 int QPieSeries::count() const
580 {
580 {
581 Q_D(const QPieSeries);
581 Q_D(const QPieSeries);
582 return d->m_slices.count();
582 return d->m_slices.count();
583 }
583 }
584
584
585 /*!
585 /*!
586 Returns true is the series is empty.
586 Returns true is the series is empty.
587 */
587 */
588 bool QPieSeries::isEmpty() const
588 bool QPieSeries::isEmpty() const
589 {
589 {
590 Q_D(const QPieSeries);
590 Q_D(const QPieSeries);
591 return d->m_slices.isEmpty();
591 return d->m_slices.isEmpty();
592 }
592 }
593
593
594 /*!
594 /*!
595 Returns the sum of all slice values in this series.
595 Returns the sum of all slice values in this series.
596
596
597 \sa QPieSlice::value(), QPieSlice::setValue(), QPieSlice::percentage()
597 \sa QPieSlice::value(), QPieSlice::setValue(), QPieSlice::percentage()
598 */
598 */
599 qreal QPieSeries::sum() const
599 qreal QPieSeries::sum() const
600 {
600 {
601 Q_D(const QPieSeries);
601 Q_D(const QPieSeries);
602 return d->m_sum;
602 return d->m_sum;
603 }
603 }
604
604
605 void QPieSeries::setHoleSize(qreal holeSize)
605 void QPieSeries::setHoleSize(qreal holeSize)
606 {
606 {
607 Q_D(QPieSeries);
607 Q_D(QPieSeries);
608 holeSize = qBound((qreal)0.0, holeSize, (qreal)1.0);
608 holeSize = qBound((qreal)0.0, holeSize, (qreal)1.0);
609 d->setSizes(holeSize, qMax(d->m_pieRelativeSize, holeSize));
609 d->setSizes(holeSize, qMax(d->m_pieRelativeSize, holeSize));
610 }
610 }
611
611
612 qreal QPieSeries::holeSize() const
612 qreal QPieSeries::holeSize() const
613 {
613 {
614 Q_D(const QPieSeries);
614 Q_D(const QPieSeries);
615 return d->m_holeRelativeSize;
615 return d->m_holeRelativeSize;
616 }
616 }
617
617
618 void QPieSeries::setHorizontalPosition(qreal relativePosition)
618 void QPieSeries::setHorizontalPosition(qreal relativePosition)
619 {
619 {
620 Q_D(QPieSeries);
620 Q_D(QPieSeries);
621
621
622 if (relativePosition < 0.0)
622 if (relativePosition < 0.0)
623 relativePosition = 0.0;
623 relativePosition = 0.0;
624 if (relativePosition > 1.0)
624 if (relativePosition > 1.0)
625 relativePosition = 1.0;
625 relativePosition = 1.0;
626
626
627 if (!qFuzzyCompare(d->m_pieRelativeHorPos, relativePosition)) {
627 if (!qFuzzyCompare(d->m_pieRelativeHorPos, relativePosition)) {
628 d->m_pieRelativeHorPos = relativePosition;
628 d->m_pieRelativeHorPos = relativePosition;
629 emit d->horizontalPositionChanged();
629 emit d->horizontalPositionChanged();
630 }
630 }
631 }
631 }
632
632
633 qreal QPieSeries::horizontalPosition() const
633 qreal QPieSeries::horizontalPosition() const
634 {
634 {
635 Q_D(const QPieSeries);
635 Q_D(const QPieSeries);
636 return d->m_pieRelativeHorPos;
636 return d->m_pieRelativeHorPos;
637 }
637 }
638
638
639 void QPieSeries::setVerticalPosition(qreal relativePosition)
639 void QPieSeries::setVerticalPosition(qreal relativePosition)
640 {
640 {
641 Q_D(QPieSeries);
641 Q_D(QPieSeries);
642
642
643 if (relativePosition < 0.0)
643 if (relativePosition < 0.0)
644 relativePosition = 0.0;
644 relativePosition = 0.0;
645 if (relativePosition > 1.0)
645 if (relativePosition > 1.0)
646 relativePosition = 1.0;
646 relativePosition = 1.0;
647
647
648 if (!qFuzzyCompare(d->m_pieRelativeVerPos, relativePosition)) {
648 if (!qFuzzyCompare(d->m_pieRelativeVerPos, relativePosition)) {
649 d->m_pieRelativeVerPos = relativePosition;
649 d->m_pieRelativeVerPos = relativePosition;
650 emit d->verticalPositionChanged();
650 emit d->verticalPositionChanged();
651 }
651 }
652 }
652 }
653
653
654 qreal QPieSeries::verticalPosition() const
654 qreal QPieSeries::verticalPosition() const
655 {
655 {
656 Q_D(const QPieSeries);
656 Q_D(const QPieSeries);
657 return d->m_pieRelativeVerPos;
657 return d->m_pieRelativeVerPos;
658 }
658 }
659
659
660 void QPieSeries::setPieSize(qreal relativeSize)
660 void QPieSeries::setPieSize(qreal relativeSize)
661 {
661 {
662 Q_D(QPieSeries);
662 Q_D(QPieSeries);
663 relativeSize = qBound((qreal)0.0, relativeSize, (qreal)1.0);
663 relativeSize = qBound((qreal)0.0, relativeSize, (qreal)1.0);
664 d->setSizes(qMin(d->m_holeRelativeSize, relativeSize), relativeSize);
664 d->setSizes(qMin(d->m_holeRelativeSize, relativeSize), relativeSize);
665
665
666 }
666 }
667
667
668 qreal QPieSeries::pieSize() const
668 qreal QPieSeries::pieSize() const
669 {
669 {
670 Q_D(const QPieSeries);
670 Q_D(const QPieSeries);
671 return d->m_pieRelativeSize;
671 return d->m_pieRelativeSize;
672 }
672 }
673
673
674
674
675 void QPieSeries::setPieStartAngle(qreal angle)
675 void QPieSeries::setPieStartAngle(qreal angle)
676 {
676 {
677 Q_D(QPieSeries);
677 Q_D(QPieSeries);
678 if (qFuzzyCompare(d->m_pieStartAngle, angle))
678 if (qFuzzyCompare(d->m_pieStartAngle, angle))
679 return;
679 return;
680 d->m_pieStartAngle = angle;
680 d->m_pieStartAngle = angle;
681 d->updateDerivativeData();
681 d->updateDerivativeData();
682 emit d->pieStartAngleChanged();
682 emit d->pieStartAngleChanged();
683 }
683 }
684
684
685 qreal QPieSeries::pieStartAngle() const
685 qreal QPieSeries::pieStartAngle() const
686 {
686 {
687 Q_D(const QPieSeries);
687 Q_D(const QPieSeries);
688 return d->m_pieStartAngle;
688 return d->m_pieStartAngle;
689 }
689 }
690
690
691 /*!
691 /*!
692 Sets the end angle of the pie.
692 Sets the end angle of the pie.
693
693
694 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
694 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
695
695
696 \a angle must be greater than start angle.
696 \a angle must be greater than start angle.
697
697
698 \sa pieEndAngle(), pieStartAngle(), setPieStartAngle()
698 \sa pieEndAngle(), pieStartAngle(), setPieStartAngle()
699 */
699 */
700 void QPieSeries::setPieEndAngle(qreal angle)
700 void QPieSeries::setPieEndAngle(qreal angle)
701 {
701 {
702 Q_D(QPieSeries);
702 Q_D(QPieSeries);
703 if (qFuzzyCompare(d->m_pieEndAngle, angle))
703 if (qFuzzyCompare(d->m_pieEndAngle, angle))
704 return;
704 return;
705 d->m_pieEndAngle = angle;
705 d->m_pieEndAngle = angle;
706 d->updateDerivativeData();
706 d->updateDerivativeData();
707 emit d->pieEndAngleChanged();
707 emit d->pieEndAngleChanged();
708 }
708 }
709
709
710 /*!
710 /*!
711 Returns the end angle of the pie.
711 Returns the end angle of the pie.
712
712
713 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
713 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
714
714
715 \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle()
715 \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle()
716 */
716 */
717 qreal QPieSeries::pieEndAngle() const
717 qreal QPieSeries::pieEndAngle() const
718 {
718 {
719 Q_D(const QPieSeries);
719 Q_D(const QPieSeries);
720 return d->m_pieEndAngle;
720 return d->m_pieEndAngle;
721 }
721 }
722
722
723 /*!
723 /*!
724 Sets the all the slice labels \a visible or invisible.
724 Sets the all the slice labels \a visible or invisible.
725
725
726 Note that this affects only the current slices in the series.
726 Note that this affects only the current slices in the series.
727 If user adds a new slice the default label visibility is false.
727 If user adds a new slice the default label visibility is false.
728
728
729 \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible()
729 \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible()
730 */
730 */
731 void QPieSeries::setLabelsVisible(bool visible)
731 void QPieSeries::setLabelsVisible(bool visible)
732 {
732 {
733 Q_D(QPieSeries);
733 Q_D(QPieSeries);
734 foreach (QPieSlice *s, d->m_slices)
734 foreach (QPieSlice *s, d->m_slices)
735 s->setLabelVisible(visible);
735 s->setLabelVisible(visible);
736 }
736 }
737
737
738 /*!
738 /*!
739 Sets the all the slice labels \a position
739 Sets the all the slice labels \a position
740
740
741 Note that this affects only the current slices in the series.
741 Note that this affects only the current slices in the series.
742 If user adds a new slice the default label position is LabelOutside
742 If user adds a new slice the default label position is LabelOutside
743
743
744 \sa QPieSlice::labelPosition(), QPieSlice::setLabelPosition()
744 \sa QPieSlice::labelPosition(), QPieSlice::setLabelPosition()
745 */
745 */
746 void QPieSeries::setLabelsPosition(QPieSlice::LabelPosition position)
746 void QPieSeries::setLabelsPosition(QPieSlice::LabelPosition position)
747 {
747 {
748 Q_D(QPieSeries);
748 Q_D(QPieSeries);
749 foreach (QPieSlice *s, d->m_slices)
749 foreach (QPieSlice *s, d->m_slices)
750 s->setLabelPosition(position);
750 s->setLabelPosition(position);
751 }
751 }
752
752
753 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
753 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
754
754
755
755
756 QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) :
756 QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) :
757 QAbstractSeriesPrivate(parent),
757 QAbstractSeriesPrivate(parent),
758 m_pieRelativeHorPos(0.5),
758 m_pieRelativeHorPos(0.5),
759 m_pieRelativeVerPos(0.5),
759 m_pieRelativeVerPos(0.5),
760 m_pieRelativeSize(0.7),
760 m_pieRelativeSize(0.7),
761 m_pieStartAngle(0),
761 m_pieStartAngle(0),
762 m_pieEndAngle(360),
762 m_pieEndAngle(360),
763 m_sum(0),
763 m_sum(0),
764 m_holeRelativeSize(0.0)
764 m_holeRelativeSize(0.0)
765 {
765 {
766 }
766 }
767
767
768 QPieSeriesPrivate::~QPieSeriesPrivate()
768 QPieSeriesPrivate::~QPieSeriesPrivate()
769 {
769 {
770 }
770 }
771
771
772 void QPieSeriesPrivate::updateDerivativeData()
772 void QPieSeriesPrivate::updateDerivativeData()
773 {
773 {
774 // calculate sum of all slices
774 // calculate sum of all slices
775 qreal sum = 0;
775 qreal sum = 0;
776 foreach (QPieSlice *s, m_slices)
776 foreach (QPieSlice *s, m_slices)
777 sum += s->value();
777 sum += s->value();
778
778
779 if (!qFuzzyCompare(m_sum, sum)) {
779 if (!qFuzzyCompare(m_sum, sum)) {
780 m_sum = sum;
780 m_sum = sum;
781 emit q_func()->sumChanged();
781 emit q_func()->sumChanged();
782 }
782 }
783
783
784 // nothing to show..
784 // nothing to show..
785 if (qFuzzyCompare(m_sum, 0))
785 if (qFuzzyCompare(m_sum, 0))
786 return;
786 return;
787
787
788 // update slice attributes
788 // update slice attributes
789 qreal sliceAngle = m_pieStartAngle;
789 qreal sliceAngle = m_pieStartAngle;
790 qreal pieSpan = m_pieEndAngle - m_pieStartAngle;
790 qreal pieSpan = m_pieEndAngle - m_pieStartAngle;
791 QVector<QPieSlice *> changed;
791 QVector<QPieSlice *> changed;
792 foreach (QPieSlice *s, m_slices) {
792 foreach (QPieSlice *s, m_slices) {
793 QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s);
793 QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s);
794 d->setPercentage(s->value() / m_sum);
794 d->setPercentage(s->value() / m_sum);
795 d->setStartAngle(sliceAngle);
795 d->setStartAngle(sliceAngle);
796 d->setAngleSpan(pieSpan * s->percentage());
796 d->setAngleSpan(pieSpan * s->percentage());
797 sliceAngle += s->angleSpan();
797 sliceAngle += s->angleSpan();
798 }
798 }
799
799
800
800
801 emit calculatedDataChanged();
801 emit calculatedDataChanged();
802 }
802 }
803
803
804 void QPieSeriesPrivate::setSizes(qreal innerSize, qreal outerSize)
804 void QPieSeriesPrivate::setSizes(qreal innerSize, qreal outerSize)
805 {
805 {
806 bool changed = false;
806 bool changed = false;
807
807
808 if (!qFuzzyCompare(m_holeRelativeSize, innerSize)) {
808 if (!qFuzzyCompare(m_holeRelativeSize, innerSize)) {
809 m_holeRelativeSize = innerSize;
809 m_holeRelativeSize = innerSize;
810 changed = true;
810 changed = true;
811 }
811 }
812
812
813 if (!qFuzzyCompare(m_pieRelativeSize, outerSize)) {
813 if (!qFuzzyCompare(m_pieRelativeSize, outerSize)) {
814 m_pieRelativeSize = outerSize;
814 m_pieRelativeSize = outerSize;
815 changed = true;
815 changed = true;
816 }
816 }
817
817
818 if (changed)
818 if (changed)
819 emit pieSizeChanged();
819 emit pieSizeChanged();
820 }
820 }
821
821
822 QPieSeriesPrivate *QPieSeriesPrivate::fromSeries(QPieSeries *series)
822 QPieSeriesPrivate *QPieSeriesPrivate::fromSeries(QPieSeries *series)
823 {
823 {
824 return series->d_func();
824 return series->d_func();
825 }
825 }
826
826
827 void QPieSeriesPrivate::sliceValueChanged()
827 void QPieSeriesPrivate::sliceValueChanged()
828 {
828 {
829 Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender())));
829 Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender())));
830 updateDerivativeData();
830 updateDerivativeData();
831 }
831 }
832
832
833 void QPieSeriesPrivate::sliceClicked()
833 void QPieSeriesPrivate::sliceClicked()
834 {
834 {
835 QPieSlice *slice = qobject_cast<QPieSlice *>(sender());
835 QPieSlice *slice = qobject_cast<QPieSlice *>(sender());
836 Q_ASSERT(m_slices.contains(slice));
836 Q_ASSERT(m_slices.contains(slice));
837 Q_Q(QPieSeries);
837 Q_Q(QPieSeries);
838 emit q->clicked(slice);
838 emit q->clicked(slice);
839 }
839 }
840
840
841 void QPieSeriesPrivate::sliceHovered(bool state)
841 void QPieSeriesPrivate::sliceHovered(bool state)
842 {
842 {
843 QPieSlice *slice = qobject_cast<QPieSlice *>(sender());
843 QPieSlice *slice = qobject_cast<QPieSlice *>(sender());
844 Q_ASSERT(m_slices.contains(slice));
844 Q_ASSERT(m_slices.contains(slice));
845 Q_Q(QPieSeries);
845 Q_Q(QPieSeries);
846 emit q->hovered(slice, state);
846 emit q->hovered(slice, state);
847 }
847 }
848
848
849 void QPieSeriesPrivate::initializeDomain()
849 void QPieSeriesPrivate::initializeDomain()
850 {
850 {
851 // does not apply to pie
851 // does not apply to pie
852 }
852 }
853
853
854 void QPieSeriesPrivate::initializeGraphics(QGraphicsItem* parent)
854 void QPieSeriesPrivate::initializeGraphics(QGraphicsItem* parent)
855 {
855 {
856 Q_Q(QPieSeries);
856 Q_Q(QPieSeries);
857 PieChartItem *pie = new PieChartItem(q,parent);
857 PieChartItem *pie = new PieChartItem(q,parent);
858 m_item.reset(pie);
858 m_item.reset(pie);
859 QAbstractSeriesPrivate::initializeGraphics(parent);
859 QAbstractSeriesPrivate::initializeGraphics(parent);
860 }
860 }
861
861
862 void QPieSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options)
862 void QPieSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options)
863 {
863 {
864 PieChartItem *item = static_cast<PieChartItem *>(m_item.data());
864 PieChartItem *item = static_cast<PieChartItem *>(m_item.data());
865 Q_ASSERT(item);
865 Q_ASSERT(item);
866 if (options.testFlag(QChart::SeriesAnimations)) {
866 if (options.testFlag(QChart::SeriesAnimations)) {
867 item->setAnimation(new PieAnimation(item));
867 item->setAnimation(new PieAnimation(item));
868 }else{
868 }else{
869 item->setAnimation(0);
869 item->setAnimation(0);
870 }
870 }
871 QAbstractSeriesPrivate::initializeAnimations(options);
871 QAbstractSeriesPrivate::initializeAnimations(options);
872 }
872 }
873
873
874 QList<QLegendMarker*> QPieSeriesPrivate::createLegendMarkers(QLegend* legend)
874 QList<QLegendMarker*> QPieSeriesPrivate::createLegendMarkers(QLegend* legend)
875 {
875 {
876 Q_Q(QPieSeries);
876 Q_Q(QPieSeries);
877 QList<QLegendMarker*> markers;
877 QList<QLegendMarker*> markers;
878 foreach(QPieSlice* slice, q->slices()) {
878 foreach(QPieSlice* slice, q->slices()) {
879 QPieLegendMarker* marker = new QPieLegendMarker(q,slice,legend);
879 QPieLegendMarker* marker = new QPieLegendMarker(q,slice,legend);
880 markers << marker;
880 markers << marker;
881 }
881 }
882 return markers;
882 return markers;
883 }
883 }
884
884
885 void QPieSeriesPrivate::initializeAxes()
885 void QPieSeriesPrivate::initializeAxes()
886 {
886 {
887
887
888 }
888 }
889
889
890 QAbstractAxis::AxisType QPieSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
890 QAbstractAxis::AxisType QPieSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
891 {
891 {
892 Q_UNUSED(orientation);
892 Q_UNUSED(orientation);
893 return QAbstractAxis::AxisTypeNoAxis;
893 return QAbstractAxis::AxisTypeNoAxis;
894 }
894 }
895
895
896 QAbstractAxis* QPieSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const
896 QAbstractAxis* QPieSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const
897 {
897 {
898 Q_UNUSED(orientation);
898 Q_UNUSED(orientation);
899 return 0;
899 return 0;
900 }
900 }
901
901
902 void QPieSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced)
902 void QPieSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced)
903 {
903 {
904 //Q_Q(QPieSeries);
904 //Q_Q(QPieSeries);
905 //const QList<QColor>& colors = theme->seriesColors();
905 //const QList<QColor>& colors = theme->seriesColors();
906 const QList<QGradient>& gradients = theme->seriesGradients();
906 const QList<QGradient>& gradients = theme->seriesGradients();
907
907
908 for (int i(0); i < m_slices.count(); i++) {
908 for (int i(0); i < m_slices.count(); i++) {
909
909
910 QColor penColor = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.0);
910 QColor penColor = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.0);
911
911
912 // Get color for a slice from a gradient linearly, beginning from the start of the gradient
912 // Get color for a slice from a gradient linearly, beginning from the start of the gradient
913 qreal pos = (qreal)(i + 1) / (qreal) m_slices.count();
913 qreal pos = (qreal)(i + 1) / (qreal) m_slices.count();
914 QColor brushColor = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), pos);
914 QColor brushColor = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), pos);
915
915
916 QPieSlice *s = m_slices.at(i);
916 QPieSlice *s = m_slices.at(i);
917 QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s);
917 QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s);
918
918
919 if (forced || d->m_data.m_slicePen.isThemed())
919 if (forced || d->m_data.m_slicePen.isThemed())
920 d->setPen(penColor, true);
920 d->setPen(penColor, true);
921
921
922 if (forced || d->m_data.m_sliceBrush.isThemed())
922 if (forced || d->m_data.m_sliceBrush.isThemed())
923 d->setBrush(brushColor, true);
923 d->setBrush(brushColor, true);
924
924
925 if (forced || d->m_data.m_labelBrush.isThemed())
925 if (forced || d->m_data.m_labelBrush.isThemed())
926 d->setLabelBrush(theme->labelBrush().color(), true);
926 d->setLabelBrush(theme->labelBrush().color(), true);
927
927
928 if (forced || d->m_data.m_labelFont.isThemed())
928 if (forced || d->m_data.m_labelFont.isThemed())
929 d->setLabelFont(theme->labelFont(), true);
929 d->setLabelFont(theme->labelFont(), true);
930 }
930 }
931 }
931 }
932
932
933
933
934 #include "moc_qpieseries.cpp"
934 #include "moc_qpieseries.cpp"
935 #include "moc_qpieseries_p.cpp"
935 #include "moc_qpieseries_p.cpp"
936
936
937 QTCOMMERCIALCHART_END_NAMESPACE
937 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,260 +1,264
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qvpiemodelmapper.h"
21 #include "qvpiemodelmapper.h"
22
22
23 QTCOMMERCIALCHART_BEGIN_NAMESPACE
23 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24
24
25 /*!
25 /*!
26 \class QVPieModelMapper
26 \class QVPieModelMapper
27 \mainclass
27 \mainclass
28
28
29 Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series.
29 Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series.
30 Vertical model mapper is used to create a connection between QPieSeries and QAbstractItemModel derived model object that keeps the consecutive pie slices data in columns.
30 Vertical model mapper is used to create a connection between QPieSeries and QAbstractItemModel derived model object that keeps the consecutive pie slices data in columns.
31 It is possible to use both QAbstractItemModel and QPieSeries model API. QVPieModelMapper makes sure that Pie and the model are kept in sync.
31 It is possible to use both QAbstractItemModel and QPieSeries model API. QVPieModelMapper makes sure that Pie and the model are kept in sync.
32 \note Used model has to support adding/removing rows/columns and modifying the data of the cells.
32 \note Used model has to support adding/removing rows/columns and modifying the data of the cells.
33 */
33 */
34 /*!
34 /*!
35 \qmlclass VPieModelMapper QVPieModelMapper
35 \qmlclass VPieModelMapper QVPieModelMapper
36
36
37 VPieModelMapper allows you to use your own QAbstractItemModel derived model with data in columns as a data source
37 VPieModelMapper allows you to use your own QAbstractItemModel derived model with data in columns as a data source
38 for a pie series. It is possible to use both QAbstractItemModel and PieSeries data API to manipulate data.
38 for a pie series. It is possible to use both QAbstractItemModel and PieSeries data API to manipulate data.
39 VPieModelMapper keeps the Pie and the model in sync.
39 VPieModelMapper keeps the Pie and the model in sync.
40
40
41 The following QML example would create a pie series with four slices (assuming the model has at least five rows).
41 The following QML example would create a pie series with four slices (assuming the model has at least five rows).
42 Each slice would contain a label from column 1 and a value from column 2.
42 Each slice would contain a label from column 1 and a value from column 2.
43 \code
43 \code
44 VPieModelMapper {
44 VPieModelMapper {
45 series: pieSeries
45 series: pieSeries
46 model: customModel
46 model: customModel
47 labelsColumn: 1
47 labelsColumn: 1
48 valuesColumn: 2
48 valuesColumn: 2
49 firstRow: 1
49 firstRow: 1
50 rowCount: 4
50 rowCount: 4
51 }
51 }
52 \endcode
52 \endcode
53 */
53 */
54
54
55 /*!
55 /*!
56 \property QVPieModelMapper::series
56 \property QVPieModelMapper::series
57 \brief Defines the QPieSeries object that is used by the mapper.
57 \brief Defines the QPieSeries object that is used by the mapper.
58 All the data in the series is discarded when it is set to the mapper.
58 All the data in the series is discarded when it is set to the mapper.
59 When new series is specified the old series is disconnected (it preserves its data)
59 When new series is specified the old series is disconnected (it preserves its data)
60 */
60 */
61 /*!
61 /*!
62 \qmlproperty PieSeries VPieModelMapper::series
62 \qmlproperty PieSeries VPieModelMapper::series
63 Defines the PieSeries object that is used by the mapper. If you define the mapper element as a child for a
63 Defines the PieSeries object that is used by the mapper. If you define the mapper element as a child for a
64 PieSeries, leave this property undefined. All the data in the series is discarded when it is set to the mapper.
64 PieSeries, leave this property undefined. All the data in the series is discarded when it is set to the mapper.
65 When new series is specified the old series is disconnected (it preserves its data).
65 When new series is specified the old series is disconnected (it preserves its data).
66 */
66 */
67
67
68 /*!
68 /*!
69 \property QVPieModelMapper::model
69 \property QVPieModelMapper::model
70 \brief Defines the model that is used by the mapper.
70 \brief Defines the model that is used by the mapper.
71 */
71 */
72 /*!
72 /*!
73 \qmlproperty SomeModel VPieModelMapper::model
73 \qmlproperty SomeModel VPieModelMapper::model
74 The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to
74 The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to
75 QML as shown in \l {QML Custom Model} demo application. Note: the model has to support adding/removing rows/columns
75 QML as shown in \l {QML Custom Model} demo application. Note: the model has to support adding/removing rows/columns
76 and modifying the data of the cells.
76 and modifying the data of the cells.
77 */
77 */
78
78
79 /*!
79 /*!
80 \property QVPieModelMapper::valuesColumn
80 \property QVPieModelMapper::valuesColumn
81 \brief Defines which column of the model is kept in sync with the values of the pie's slices
81 \brief Defines which column of the model is kept in sync with the values of the pie's slices.
82
82 Default value is: -1 (invalid mapping)
83 Default value is: -1 (invalid mapping)
83 */
84 */
84 /*!
85 /*!
85 \qmlproperty int VPieModelMapper::valuesColumn
86 \qmlproperty int VPieModelMapper::valuesColumn
86 Defines which column of the model is kept in sync with the values of the pie's slices. Default value is -1 (invalid
87 Defines which column of the model is kept in sync with the values of the pie's slices. Default value is -1 (invalid
87 mapping).
88 mapping).
88 */
89 */
89
90
90 /*!
91 /*!
91 \property QVPieModelMapper::labelsColumn
92 \property QVPieModelMapper::labelsColumn
92 \brief Defines which column of the model is kept in sync with the labels of the pie's slices
93 \brief Defines which column of the model is kept in sync with the labels of the pie's slices.
94
93 Default value is: -1 (invalid mapping)
95 Default value is: -1 (invalid mapping)
94 */
96 */
95 /*!
97 /*!
96 \qmlproperty int VPieModelMapper::labelsColumn
98 \qmlproperty int VPieModelMapper::labelsColumn
97 Defines which column of the model is kept in sync with the labels of the pie's slices. Default value is -1 (invalid
99 Defines which column of the model is kept in sync with the labels of the pie's slices. Default value is -1 (invalid
98 mapping).
100 mapping).
99 */
101 */
100
102
101 /*!
103 /*!
102 \property QVPieModelMapper::firstRow
104 \property QVPieModelMapper::firstRow
103 \brief Defines which row of the model contains the first slice value.
105 \brief Defines which row of the model contains the first slice value.
106
104 Minimal and default value is: 0
107 Minimal and default value is: 0
105 */
108 */
106 /*!
109 /*!
107 \qmlproperty int VPieModelMapper::firstRow
110 \qmlproperty int VPieModelMapper::firstRow
108 Defines which row of the model contains the first slice value.
111 Defines which row of the model contains the first slice value.
109 The default value is 0.
112 The default value is 0.
110 */
113 */
111
114
112 /*!
115 /*!
113 \property QVPieModelMapper::rowCount
116 \property QVPieModelMapper::rowCount
114 \brief Defines the number of rows of the model that are mapped as the data for QPieSeries
117 \brief Defines the number of rows of the model that are mapped as the data for QPieSeries.
118
115 Minimal and default value is: -1 (count limited by the number of rows in the model)
119 Minimal and default value is: -1 (count limited by the number of rows in the model)
116 */
120 */
117 /*!
121 /*!
118 \qmlproperty int VPieModelMapper::columnCount
122 \qmlproperty int VPieModelMapper::columnCount
119 Defines the number of rows of the model that are mapped as the data for QPieSeries. The default value is
123 Defines the number of rows of the model that are mapped as the data for QPieSeries. The default value is
120 -1 (count limited by the number of rows in the model)
124 -1 (count limited by the number of rows in the model)
121 */
125 */
122
126
123 /*!
127 /*!
124 \fn void QVPieModelMapper::seriesReplaced()
128 \fn void QVPieModelMapper::seriesReplaced()
125
129
126 Emitted when the series to which mapper is connected to has changed.
130 Emitted when the series to which mapper is connected to has changed.
127 */
131 */
128
132
129 /*!
133 /*!
130 \fn void QVPieModelMapper::modelReplaced()
134 \fn void QVPieModelMapper::modelReplaced()
131
135
132 Emitted when the model to which mapper is connected to has changed.
136 Emitted when the model to which mapper is connected to has changed.
133 */
137 */
134
138
135 /*!
139 /*!
136 \fn void QVPieModelMapper::valuesColumnChanged()
140 \fn void QVPieModelMapper::valuesColumnChanged()
137
141
138 Emitted when the valuesColumn has changed.
142 Emitted when the valuesColumn has changed.
139 */
143 */
140
144
141 /*!
145 /*!
142 \fn void QVPieModelMapper::labelsColumnChanged()
146 \fn void QVPieModelMapper::labelsColumnChanged()
143
147
144 Emitted when the labelsColumn has changed.
148 Emitted when the labelsColumn has changed.
145 */
149 */
146
150
147 /*!
151 /*!
148 \fn void QVPieModelMapper::firstRowChanged()
152 \fn void QVPieModelMapper::firstRowChanged()
149 Emitted when the firstRow has changed.
153 Emitted when the firstRow has changed.
150 */
154 */
151
155
152 /*!
156 /*!
153 \fn void QVPieModelMapper::rowCountChanged()
157 \fn void QVPieModelMapper::rowCountChanged()
154 Emitted when the rowCount has changed.
158 Emitted when the rowCount has changed.
155 */
159 */
156
160
157 /*!
161 /*!
158 Constructs a mapper object which is a child of \a parent.
162 Constructs a mapper object which is a child of \a parent.
159 */
163 */
160 QVPieModelMapper::QVPieModelMapper(QObject *parent) :
164 QVPieModelMapper::QVPieModelMapper(QObject *parent) :
161 QPieModelMapper(parent)
165 QPieModelMapper(parent)
162 {
166 {
163 QPieModelMapper::setOrientation(Qt::Vertical);
167 QPieModelMapper::setOrientation(Qt::Vertical);
164 }
168 }
165
169
166 QAbstractItemModel *QVPieModelMapper::model() const
170 QAbstractItemModel *QVPieModelMapper::model() const
167 {
171 {
168 return QPieModelMapper::model();
172 return QPieModelMapper::model();
169 }
173 }
170
174
171 void QVPieModelMapper::setModel(QAbstractItemModel *model)
175 void QVPieModelMapper::setModel(QAbstractItemModel *model)
172 {
176 {
173 if (model != QPieModelMapper::model()) {
177 if (model != QPieModelMapper::model()) {
174 QPieModelMapper::setModel(model);
178 QPieModelMapper::setModel(model);
175 emit modelReplaced();
179 emit modelReplaced();
176 }
180 }
177 }
181 }
178
182
179 QPieSeries *QVPieModelMapper::series() const
183 QPieSeries *QVPieModelMapper::series() const
180 {
184 {
181 return QPieModelMapper::series();
185 return QPieModelMapper::series();
182 }
186 }
183
187
184 void QVPieModelMapper::setSeries(QPieSeries *series)
188 void QVPieModelMapper::setSeries(QPieSeries *series)
185 {
189 {
186 if (series != QPieModelMapper::series()) {
190 if (series != QPieModelMapper::series()) {
187 QPieModelMapper::setSeries(series);
191 QPieModelMapper::setSeries(series);
188 emit seriesReplaced();
192 emit seriesReplaced();
189 }
193 }
190 }
194 }
191
195
192 /*!
196 /*!
193 Returns which column of the model is kept in sync with the values of the pie's slices
197 Returns which column of the model is kept in sync with the values of the pie's slices
194 */
198 */
195 int QVPieModelMapper::valuesColumn() const
199 int QVPieModelMapper::valuesColumn() const
196 {
200 {
197 return QPieModelMapper::valuesSection();
201 return QPieModelMapper::valuesSection();
198 }
202 }
199
203
200 /*!
204 /*!
201 Sets the model column that is kept in sync with the pie slices values.
205 Sets the model column that is kept in sync with the pie slices values.
202 Parameter \a valuesColumn specifies the row of the model.
206 Parameter \a valuesColumn specifies the row of the model.
203 */
207 */
204 void QVPieModelMapper::setValuesColumn(int valuesColumn)
208 void QVPieModelMapper::setValuesColumn(int valuesColumn)
205 {
209 {
206 if (valuesColumn != valuesSection()) {
210 if (valuesColumn != valuesSection()) {
207 QPieModelMapper::setValuesSection(valuesColumn);
211 QPieModelMapper::setValuesSection(valuesColumn);
208 emit valuesColumnChanged();
212 emit valuesColumnChanged();
209 }
213 }
210 }
214 }
211
215
212 /*!
216 /*!
213 Returns which column of the model is kept in sync with the labels of the pie's slices
217 Returns which column of the model is kept in sync with the labels of the pie's slices
214 */
218 */
215 int QVPieModelMapper::labelsColumn() const
219 int QVPieModelMapper::labelsColumn() const
216 {
220 {
217 return QPieModelMapper::labelsSection();
221 return QPieModelMapper::labelsSection();
218 }
222 }
219
223
220 /*!
224 /*!
221 Sets the model column that is kept in sync with the pie's slices labels.
225 Sets the model column that is kept in sync with the pie's slices labels.
222 Parameter \a labelsColumn specifies the row of the model.
226 Parameter \a labelsColumn specifies the row of the model.
223 */
227 */
224 void QVPieModelMapper::setLabelsColumn(int labelsColumn)
228 void QVPieModelMapper::setLabelsColumn(int labelsColumn)
225 {
229 {
226 if (labelsColumn != labelsSection()) {
230 if (labelsColumn != labelsSection()) {
227 QPieModelMapper::setLabelsSection(labelsColumn);
231 QPieModelMapper::setLabelsSection(labelsColumn);
228 emit labelsColumnChanged();
232 emit labelsColumnChanged();
229 }
233 }
230 }
234 }
231
235
232 int QVPieModelMapper::firstRow() const
236 int QVPieModelMapper::firstRow() const
233 {
237 {
234 return first();
238 return first();
235 }
239 }
236
240
237 void QVPieModelMapper::setFirstRow(int firstRow)
241 void QVPieModelMapper::setFirstRow(int firstRow)
238 {
242 {
239 if (firstRow != first()) {
243 if (firstRow != first()) {
240 setFirst(firstRow);
244 setFirst(firstRow);
241 emit firstRowChanged();
245 emit firstRowChanged();
242 }
246 }
243 }
247 }
244
248
245 int QVPieModelMapper::rowCount() const
249 int QVPieModelMapper::rowCount() const
246 {
250 {
247 return count();
251 return count();
248 }
252 }
249
253
250 void QVPieModelMapper::setRowCount(int rowCount)
254 void QVPieModelMapper::setRowCount(int rowCount)
251 {
255 {
252 if (rowCount != count()) {
256 if (rowCount != count()) {
253 setCount(rowCount);
257 setCount(rowCount);
254 emit rowCountChanged();
258 emit rowCountChanged();
255 }
259 }
256 }
260 }
257
261
258 #include "moc_qvpiemodelmapper.cpp"
262 #include "moc_qvpiemodelmapper.cpp"
259
263
260 QTCOMMERCIALCHART_END_NAMESPACE
264 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,308 +1,309
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qabstractseries.h"
21 #include "qabstractseries.h"
22 #include "qabstractseries_p.h"
22 #include "qabstractseries_p.h"
23 #include "chartdataset_p.h"
23 #include "chartdataset_p.h"
24 #include "qchart.h"
24 #include "qchart.h"
25 #include "qchart_p.h"
25 #include "qchart_p.h"
26 #include "chartitem_p.h"
26 #include "chartitem_p.h"
27 #include "xydomain_p.h"
27 #include "xydomain_p.h"
28 #include "xlogydomain_p.h"
28 #include "xlogydomain_p.h"
29 #include "logxydomain_p.h"
29 #include "logxydomain_p.h"
30 #include "logxlogydomain_p.h"
30 #include "logxlogydomain_p.h"
31
31
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33
33
34 /*!
34 /*!
35 \class QAbstractSeries
35 \class QAbstractSeries
36 \brief Base class for all QtCommercial Chart series.
36 \brief Base class for all QtCommercial Chart series.
37 \mainclass
37 \mainclass
38
38
39 Usually you use the series type specific inherited classes instead of the base class.
39 Usually you use the series type specific inherited classes instead of the base class.
40 \sa QXYSeries, QLineSeries, QSplineSeries, QScatterSeries, QAreaSeries, QAbstractBarSeries, QStackedBarSeries,
40 \sa QXYSeries, QLineSeries, QSplineSeries, QScatterSeries, QAreaSeries, QAbstractBarSeries, QStackedBarSeries,
41 QPercentBarSeries, QPieSeries
41 QPercentBarSeries, QPieSeries
42 */
42 */
43 /*!
43 /*!
44 \qmlclass AbstractSeries
44 \qmlclass AbstractSeries
45 AbstractSeries is the base class for all series.
45 AbstractSeries is the base class for all series.
46 The class cannot be instantiated by the user.
46 The class cannot be instantiated by the user.
47 */
47 */
48
48
49 /*!
49 /*!
50 \enum QAbstractSeries::SeriesType
50 \enum QAbstractSeries::SeriesType
51
51
52 The type of the series object.
52 The type of the series object.
53
53
54 \value SeriesTypeLine
54 \value SeriesTypeLine
55 \value SeriesTypeArea
55 \value SeriesTypeArea
56 \value SeriesTypeBar
56 \value SeriesTypeBar
57 \value SeriesTypeStackedBar
57 \value SeriesTypeStackedBar
58 \value SeriesTypePercentBar
58 \value SeriesTypePercentBar
59 \value SeriesTypePie
59 \value SeriesTypePie
60 \value SeriesTypeScatter
60 \value SeriesTypeScatter
61 \value SeriesTypeSpline
61 \value SeriesTypeSpline
62 \value SeriesTypeHorizontalBar
62 \value SeriesTypeHorizontalBar
63 \value SeriesTypeHorizontalStackedBar
63 \value SeriesTypeHorizontalStackedBar
64 \value SeriesTypeHorizontalPercentBar
64 \value SeriesTypeHorizontalPercentBar
65 */
65 */
66
66
67 /*!
67 /*!
68 \property QAbstractSeries::type
68 \property QAbstractSeries::type
69 The type of the series.
69 The type of the series.
70 */
70 */
71 /*!
71 /*!
72 \qmlproperty ChartView.SeriesType AbstractSeries::type
72 \qmlproperty ChartView.SeriesType AbstractSeries::type
73 The type of the series.
73 The type of the series.
74 */
74 */
75
75
76 /*!
76 /*!
77 \property QAbstractSeries::name
77 \property QAbstractSeries::name
78 \brief name of the series property. The name is shown in legend for QXYSeries.
78 \brief name of the series property. The name is shown in legend for QXYSeries.
79 */
79 */
80 /*!
80 /*!
81 \qmlproperty string AbstractSeries::name
81 \qmlproperty string AbstractSeries::name
82 Name of the series. The name is shown in legend for QXYSeries.
82 Name of the series. The name is shown in legend for QXYSeries.
83 */
83 */
84
84
85 /*!
85 /*!
86 \fn void QAbstractSeries::nameChanged()
86 \fn void QAbstractSeries::nameChanged()
87 This signal is emitted when the series name changes.
87 This signal is emitted when the series name changes.
88 */
88 */
89 /*!
89 /*!
90 \qmlsignal AbstractSeries::onNameChanged()
90 \qmlsignal AbstractSeries::onNameChanged()
91 This signal is emitted when the series name changes.
91 This signal is emitted when the series name changes.
92 */
92 */
93
93
94 /*!
94 /*!
95 \property QAbstractSeries::visible
95 \property QAbstractSeries::visible
96 \brief whether the series is visible or not; true by default.
96 \brief whether the series is visible or not; true by default.
97 */
97 */
98 /*!
98 /*!
99 \qmlproperty bool AbstractSeries::visible
99 \qmlproperty bool AbstractSeries::visible
100 Visibility of the series. True by default.
100 Visibility of the series. True by default.
101 */
101 */
102
102
103 /*!
103 /*!
104 \fn void QAbstractSeries::visibleChanged()
104 \fn void QAbstractSeries::visibleChanged()
105 Emitted when the series visibility changes.
105 Emitted when the series visibility changes.
106 */
106 */
107 /*!
107 /*!
108 \qmlsignal AbstractSeries::onVisibleChanged()
108 \qmlsignal AbstractSeries::onVisibleChanged()
109 Emitted when the series visibility changes.
109 Emitted when the series visibility changes.
110 */
110 */
111
111
112 /*!
112 /*!
113 \property QAbstractSeries::opacity
113 \property QAbstractSeries::opacity
114 \brief The opacity of the series.
114 \brief The opacity of the series.
115
115 By default the opacity is 1.0. The valid values range from 0.0 (transparent) to 1.0 (opaque).
116 By default the opacity is 1.0. The valid values range from 0.0 (transparent) to 1.0 (opaque).
116 */
117 */
117 /*!
118 /*!
118 \qmlproperty real AbstractSeries::opacity
119 \qmlproperty real AbstractSeries::opacity
119 The opacity of the series. By default the opacity is 1.0.
120 The opacity of the series. By default the opacity is 1.0.
120 The valid values range from 0.0 (transparent) to 1.0 (opaque).
121 The valid values range from 0.0 (transparent) to 1.0 (opaque).
121 */
122 */
122
123
123 /*!
124 /*!
124 \fn void QAbstractSeries::opacityChanged()
125 \fn void QAbstractSeries::opacityChanged()
125 Emitted when the opacity of the series changes.
126 Emitted when the opacity of the series changes.
126 */
127 */
127 /*!
128 /*!
128 \qmlsignal AbstractSeries::onOpacityChanged()
129 \qmlsignal AbstractSeries::onOpacityChanged()
129 Emitted when the opacity of the series changes.
130 Emitted when the opacity of the series changes.
130 */
131 */
131
132
132 /*!
133 /*!
133 \internal
134 \internal
134 \brief Constructs QAbstractSeries object with \a parent.
135 \brief Constructs QAbstractSeries object with \a parent.
135 */
136 */
136 QAbstractSeries::QAbstractSeries(QAbstractSeriesPrivate &d, QObject *parent) :
137 QAbstractSeries::QAbstractSeries(QAbstractSeriesPrivate &d, QObject *parent) :
137 QObject(parent),
138 QObject(parent),
138 d_ptr(&d)
139 d_ptr(&d)
139 {
140 {
140 }
141 }
141
142
142 /*!
143 /*!
143 \brief Virtual destructor for the chart series.
144 \brief Virtual destructor for the chart series.
144 */
145 */
145 QAbstractSeries::~QAbstractSeries()
146 QAbstractSeries::~QAbstractSeries()
146 {
147 {
147 if (d_ptr->m_chart)
148 if (d_ptr->m_chart)
148 qFatal("Series still bound to a chart when destroyed!");
149 qFatal("Series still bound to a chart when destroyed!");
149 }
150 }
150
151
151 void QAbstractSeries::setName(const QString &name)
152 void QAbstractSeries::setName(const QString &name)
152 {
153 {
153 if (name != d_ptr->m_name) {
154 if (name != d_ptr->m_name) {
154 d_ptr->m_name = name;
155 d_ptr->m_name = name;
155 emit nameChanged();
156 emit nameChanged();
156 }
157 }
157 }
158 }
158
159
159 QString QAbstractSeries::name() const
160 QString QAbstractSeries::name() const
160 {
161 {
161 return d_ptr->m_name;
162 return d_ptr->m_name;
162 }
163 }
163
164
164 void QAbstractSeries::setVisible(bool visible)
165 void QAbstractSeries::setVisible(bool visible)
165 {
166 {
166 if (visible != d_ptr->m_visible) {
167 if (visible != d_ptr->m_visible) {
167 d_ptr->m_visible = visible;
168 d_ptr->m_visible = visible;
168 emit visibleChanged();
169 emit visibleChanged();
169 }
170 }
170 }
171 }
171
172
172 bool QAbstractSeries::isVisible() const
173 bool QAbstractSeries::isVisible() const
173 {
174 {
174 return d_ptr->m_visible;
175 return d_ptr->m_visible;
175 }
176 }
176
177
177 qreal QAbstractSeries::opacity() const
178 qreal QAbstractSeries::opacity() const
178 {
179 {
179 return d_ptr->m_opacity;
180 return d_ptr->m_opacity;
180 }
181 }
181
182
182 void QAbstractSeries::setOpacity(qreal opacity)
183 void QAbstractSeries::setOpacity(qreal opacity)
183 {
184 {
184 if (opacity != d_ptr->m_opacity) {
185 if (opacity != d_ptr->m_opacity) {
185 d_ptr->m_opacity = opacity;
186 d_ptr->m_opacity = opacity;
186 emit opacityChanged();
187 emit opacityChanged();
187 }
188 }
188 }
189 }
189
190
190 /*!
191 /*!
191 \brief Returns the chart where series belongs to.
192 \brief Returns the chart where series belongs to.
192
193
193 Set automatically when the series is added to the chart
194 Set automatically when the series is added to the chart
194 and unset when the series is removed from the chart.
195 and unset when the series is removed from the chart.
195 */
196 */
196 QChart *QAbstractSeries::chart() const
197 QChart *QAbstractSeries::chart() const
197 {
198 {
198 return d_ptr->m_chart;
199 return d_ptr->m_chart;
199 }
200 }
200
201
201 /*!
202 /*!
202 \brief Sets the visibility of the series to true
203 \brief Sets the visibility of the series to true.
203
204
204 \sa setVisible(), isVisible()
205 \sa setVisible(), isVisible()
205 */
206 */
206 void QAbstractSeries::show()
207 void QAbstractSeries::show()
207 {
208 {
208 setVisible(true);
209 setVisible(true);
209 }
210 }
210
211
211 /*!
212 /*!
212 \brief Sets the visibility of the series to false
213 \brief Sets the visibility of the series to false.
213
214
214 \sa setVisible(), isVisible()
215 \sa setVisible(), isVisible()
215 */
216 */
216 void QAbstractSeries::hide()
217 void QAbstractSeries::hide()
217 {
218 {
218 setVisible(false);
219 setVisible(false);
219 }
220 }
220
221
221 /*!
222 /*!
222 Attach \a axis to the series.
223 Attach \a axis to the series.
223 \return true if the axis was attached successfully, false otherwise.
224 \return true if the axis was attached successfully, false otherwise.
224 \sa QChart::addAxis(), QChart::createDefaultAxes()
225 \sa QChart::addAxis(), QChart::createDefaultAxes()
225 */
226 */
226 bool QAbstractSeries::attachAxis(QAbstractAxis* axis)
227 bool QAbstractSeries::attachAxis(QAbstractAxis* axis)
227 {
228 {
228 if(d_ptr->m_chart) {
229 if(d_ptr->m_chart) {
229 return d_ptr->m_chart->d_ptr->m_dataset->attachAxis(this, axis);
230 return d_ptr->m_chart->d_ptr->m_dataset->attachAxis(this, axis);
230 } else {
231 } else {
231 qWarning()<<"Series not in the chart. Please addSeries to chart first.";
232 qWarning()<<"Series not in the chart. Please addSeries to chart first.";
232 return false;
233 return false;
233 }
234 }
234 }
235 }
235
236
236 /*!
237 /*!
237 Detach \a axis from the series.
238 Detach \a axis from the series.
238 \return true if the axis was detached successfully, false otherwise.
239 \return true if the axis was detached successfully, false otherwise.
239 \sa QChart::removeAxis()
240 \sa QChart::removeAxis()
240 */
241 */
241 bool QAbstractSeries::detachAxis(QAbstractAxis* axis)
242 bool QAbstractSeries::detachAxis(QAbstractAxis* axis)
242 {
243 {
243 if(d_ptr->m_chart) {
244 if(d_ptr->m_chart) {
244 return d_ptr->m_chart->d_ptr->m_dataset->detachAxis(this, axis);
245 return d_ptr->m_chart->d_ptr->m_dataset->detachAxis(this, axis);
245 }
246 }
246 else {
247 else {
247 qWarning()<<"Series not in the chart. Please addSeries to chart first.";
248 qWarning()<<"Series not in the chart. Please addSeries to chart first.";
248 return false;
249 return false;
249 }
250 }
250 }
251 }
251
252
252 /*!
253 /*!
253 Returns the list of axes attached to the series. Usually there is an x-axis and a y-axis attached to a series, except
254 Returns the list of axes attached to the series. Usually there is an x-axis and a y-axis attached to a series, except
254 in case of a QPieSeries, which does not have any axes attached.
255 in case of a QPieSeries, which does not have any axes attached.
255 \sa attachAxis(), detachAxis()
256 \sa attachAxis(), detachAxis()
256 */
257 */
257 QList<QAbstractAxis*> QAbstractSeries::attachedAxes()
258 QList<QAbstractAxis*> QAbstractSeries::attachedAxes()
258 {
259 {
259 return d_ptr->m_axes;
260 return d_ptr->m_axes;
260 }
261 }
261
262
262 ///////////////////////////////////////////////////////////////////////////////////////////////////
263 ///////////////////////////////////////////////////////////////////////////////////////////////////
263
264
264 QAbstractSeriesPrivate::QAbstractSeriesPrivate(QAbstractSeries *q)
265 QAbstractSeriesPrivate::QAbstractSeriesPrivate(QAbstractSeries *q)
265 : q_ptr(q),
266 : q_ptr(q),
266 m_chart(0),
267 m_chart(0),
267 m_item(0),
268 m_item(0),
268 m_domain(new XYDomain()),
269 m_domain(new XYDomain()),
269 m_visible(true),
270 m_visible(true),
270 m_opacity(1.0)
271 m_opacity(1.0)
271 {
272 {
272 }
273 }
273
274
274 QAbstractSeriesPrivate::~QAbstractSeriesPrivate()
275 QAbstractSeriesPrivate::~QAbstractSeriesPrivate()
275 {
276 {
276 }
277 }
277
278
278 void QAbstractSeriesPrivate::setDomain(AbstractDomain* domain)
279 void QAbstractSeriesPrivate::setDomain(AbstractDomain* domain)
279 {
280 {
280 Q_ASSERT(domain);
281 Q_ASSERT(domain);
281 if(m_domain.data()!=domain) {
282 if(m_domain.data()!=domain) {
282 if(!m_item.isNull()) QObject::disconnect(m_domain.data(), SIGNAL(updated()), m_item.data(), SLOT(handleDomainUpdated()));
283 if(!m_item.isNull()) QObject::disconnect(m_domain.data(), SIGNAL(updated()), m_item.data(), SLOT(handleDomainUpdated()));
283 m_domain.reset(domain);
284 m_domain.reset(domain);
284 if(!m_item.isNull()) {
285 if(!m_item.isNull()) {
285 QObject::connect(m_domain.data(), SIGNAL(updated()),m_item.data(), SLOT(handleDomainUpdated()));
286 QObject::connect(m_domain.data(), SIGNAL(updated()),m_item.data(), SLOT(handleDomainUpdated()));
286 m_item->handleDomainUpdated();
287 m_item->handleDomainUpdated();
287 }
288 }
288 }
289 }
289 }
290 }
290
291
291 void QAbstractSeriesPrivate::initializeGraphics(QGraphicsItem* parent)
292 void QAbstractSeriesPrivate::initializeGraphics(QGraphicsItem* parent)
292 {
293 {
293 Q_ASSERT(!m_item.isNull());
294 Q_ASSERT(!m_item.isNull());
294 Q_UNUSED(parent);
295 Q_UNUSED(parent);
295 QObject::connect(m_domain.data(), SIGNAL(updated()),m_item.data(), SLOT(handleDomainUpdated()));
296 QObject::connect(m_domain.data(), SIGNAL(updated()),m_item.data(), SLOT(handleDomainUpdated()));
296 }
297 }
297
298
298 void QAbstractSeriesPrivate::initializeAnimations(QChart::AnimationOptions options)
299 void QAbstractSeriesPrivate::initializeAnimations(QChart::AnimationOptions options)
299 {
300 {
300 Q_UNUSED(options);
301 Q_UNUSED(options);
301 }
302 }
302
303
303 #include "moc_qabstractseries.cpp"
304 #include "moc_qabstractseries.cpp"
304 #include "moc_qabstractseries_p.cpp"
305 #include "moc_qabstractseries_p.cpp"
305
306
306 QTCOMMERCIALCHART_END_NAMESPACE
307 QTCOMMERCIALCHART_END_NAMESPACE
307
308
308
309
@@ -1,301 +1,301
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qscatterseries.h"
21 #include "qscatterseries.h"
22 #include "qscatterseries_p.h"
22 #include "qscatterseries_p.h"
23 #include "scatterchartitem_p.h"
23 #include "scatterchartitem_p.h"
24 #include "chartdataset_p.h"
24 #include "chartdataset_p.h"
25 #include "charttheme_p.h"
25 #include "charttheme_p.h"
26 #include "scatteranimation_p.h"
26 #include "scatteranimation_p.h"
27 #include "qchart_p.h"
27 #include "qchart_p.h"
28
28
29 /*!
29 /*!
30 \class QScatterSeries
30 \class QScatterSeries
31 \brief The QScatterSeries class is used for making scatter charts.
31 \brief The QScatterSeries class is used for making scatter charts.
32
32
33 \mainclass
33 \mainclass
34
34
35 The scatter data is displayed as a collection of points on the chart. Each point determines the position on the horizontal axis
35 The scatter data is displayed as a collection of points on the chart. Each point determines the position on the horizontal axis
36 and the vertical axis.
36 and the vertical axis.
37
37
38 \image examples_scatterchart.png
38 \image examples_scatterchart.png
39
39
40 Creating basic scatter chart is simple:
40 Creating basic scatter chart is simple:
41 \code
41 \code
42 QScatterSeries* series = new QScatterSeries();
42 QScatterSeries* series = new QScatterSeries();
43 series->append(0, 6);
43 series->append(0, 6);
44 series->append(2, 4);
44 series->append(2, 4);
45 ...
45 ...
46 chart->addSeries(series);
46 chart->addSeries(series);
47 \endcode
47 \endcode
48 */
48 */
49 /*!
49 /*!
50 \qmlclass ScatterSeries QScatterSeries
50 \qmlclass ScatterSeries QScatterSeries
51 \inherits XYSeries
51 \inherits XYSeries
52
52
53 The following QML shows how to create a chart with two simple scatter series:
53 The following QML shows how to create a chart with two simple scatter series:
54 \snippet ../demos/qmlchart/qml/qmlchart/View5.qml 1
54 \snippet ../demos/qmlchart/qml/qmlchart/View5.qml 1
55
55
56 \beginfloatleft
56 \beginfloatleft
57 \image demos_qmlchart5.png
57 \image demos_qmlchart5.png
58 \endfloat
58 \endfloat
59 \clearfloat
59 \clearfloat
60 */
60 */
61
61
62 /*!
62 /*!
63 \enum QScatterSeries::MarkerShape
63 \enum QScatterSeries::MarkerShape
64
64
65 This enum describes the shape used when rendering marker items.
65 This enum describes the shape used when rendering marker items.
66
66
67 \value MarkerShapeCircle
67 \value MarkerShapeCircle
68 \value MarkerShapeRectangle
68 \value MarkerShapeRectangle
69 */
69 */
70
70
71 /*!
71 /*!
72 \property QScatterSeries::color
72 \property QScatterSeries::color
73 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.
74 \sa QScatterSeries::brush()
74 \sa QScatterSeries::brush()
75 */
75 */
76
76
77 /*!
77 /*!
78 \property QScatterSeries::borderColor
78 \property QScatterSeries::borderColor
79 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.
80 \sa QScatterSeries::pen()
80 \sa QScatterSeries::pen()
81 */
81 */
82 /*!
82 /*!
83 \qmlproperty color ScatterSeries::borderColor
83 \qmlproperty color ScatterSeries::borderColor
84 Border (pen) color of the series.
84 Border (pen) color of the series.
85 */
85 */
86
86
87 /*!
87 /*!
88 \qmlproperty real ScatterSeries::borderWidth
88 \qmlproperty real ScatterSeries::borderWidth
89 The width of the border line. By default the width is 2.0.
89 The width of the border line. By default the width is 2.0.
90 */
90 */
91
91
92 /*!
92 /*!
93 \property QScatterSeries::markerShape
93 \property QScatterSeries::markerShape
94 Defines the shape of the marker used to draw the points in the series. The default shape is MarkerShapeCircle.
94 Defines the shape of the marker used to draw the points in the series. The default shape is MarkerShapeCircle.
95 */
95 */
96 /*!
96 /*!
97 \qmlproperty MarkerShape ScatterSeries::markerShape
97 \qmlproperty MarkerShape ScatterSeries::markerShape
98 Defines the shape of the marker used to draw the points in the series. One of ScatterSeries
98 Defines the shape of the marker used to draw the points in the series. One of ScatterSeries
99 ScatterSeries.MarkerShapeCircle or ScatterSeries.MarkerShapeRectangle.
99 ScatterSeries.MarkerShapeCircle or ScatterSeries.MarkerShapeRectangle.
100 The default shape is ScatterSeries.MarkerShapeCircle.
100 The default shape is ScatterSeries.MarkerShapeCircle.
101 */
101 */
102
102
103 /*!
103 /*!
104 \property QScatterSeries::markerSize
104 \property QScatterSeries::markerSize
105 Defines the size of the marker used to draw the points in the series. The default size is 15.0.
105 Defines the size of the marker used to draw the points in the series. The default size is 15.0.
106 */
106 */
107 /*!
107 /*!
108 \qmlproperty real ScatterSeries::markerSize
108 \qmlproperty real ScatterSeries::markerSize
109 Defines the size of the marker used to draw the points in the series. The default size is 15.0.
109 Defines the size of the marker used to draw the points in the series. The default size is 15.0.
110 */
110 */
111
111
112 /*!
112 /*!
113 \fn void QScatterSeries::colorChanged(QColor color)
113 \fn void QScatterSeries::colorChanged(QColor color)
114 Signal is emitted when the fill (brush) color has changed to \a color.
114 Signal is emitted when the fill (brush) color has changed to \a color.
115 */
115 */
116
116
117 /*!
117 /*!
118 \fn void QScatterSeries::borderColorChanged(QColor color)
118 \fn void QScatterSeries::borderColorChanged(QColor color)
119 Signal is emitted when the line (pen) color has changed to \a color.
119 Signal is emitted when the line (pen) color has changed to \a color.
120 */
120 */
121 /*!
121 /*!
122 \qmlsignal ScatterSeries::borderColorChanged(color color)
122 \qmlsignal ScatterSeries::borderColorChanged(color color)
123 Signal is emitted when the line (pen) color has changed to \a color.
123 Signal is emitted when the line (pen) color has changed to \a color.
124 */
124 */
125
125
126 /*!
126 /*!
127 \fn QChartSeriesType QScatterSeries::type() const
127 \fn QAbstractSeries::SeriesType QScatterSeries::type() const
128 Returns QChartSeries::SeriesTypeScatter.
128 Returns QAbstractSeries::SeriesTypeScatter.
129 \sa QAbstractSeries, SeriesType
129 \sa QAbstractSeries, SeriesType
130 */
130 */
131
131
132 QTCOMMERCIALCHART_BEGIN_NAMESPACE
132 QTCOMMERCIALCHART_BEGIN_NAMESPACE
133
133
134 /*!
134 /*!
135 Constructs a series object which is a child of \a parent.
135 Constructs a series object which is a child of \a parent.
136 */
136 */
137 QScatterSeries::QScatterSeries(QObject *parent)
137 QScatterSeries::QScatterSeries(QObject *parent)
138 : QXYSeries(*new QScatterSeriesPrivate(this), parent)
138 : QXYSeries(*new QScatterSeriesPrivate(this), parent)
139 {
139 {
140 }
140 }
141
141
142 /*!
142 /*!
143 Destroys the object. Note that adding series to QChart transfers the ownership to the chart.
143 Destroys the object. Note that adding series to QChart transfers the ownership to the chart.
144 */
144 */
145 QScatterSeries::~QScatterSeries()
145 QScatterSeries::~QScatterSeries()
146 {
146 {
147 Q_D(QScatterSeries);
147 Q_D(QScatterSeries);
148 if (d->m_chart)
148 if (d->m_chart)
149 d->m_chart->removeSeries(this);
149 d->m_chart->removeSeries(this);
150 }
150 }
151
151
152 QAbstractSeries::SeriesType QScatterSeries::type() const
152 QAbstractSeries::SeriesType QScatterSeries::type() const
153 {
153 {
154 return QAbstractSeries::SeriesTypeScatter;
154 return QAbstractSeries::SeriesTypeScatter;
155 }
155 }
156
156
157 /*!
157 /*!
158 Sets \a pen used for drawing points' border on the chart. If the pen is not defined, the
158 Sets \a pen used for drawing points' border on the chart. If the pen is not defined, the
159 pen from chart theme is used.
159 pen from chart theme is used.
160 \sa QChart::setTheme()
160 \sa QChart::setTheme()
161 */
161 */
162 void QScatterSeries::setPen(const QPen &pen)
162 void QScatterSeries::setPen(const QPen &pen)
163 {
163 {
164 Q_D(QXYSeries);
164 Q_D(QXYSeries);
165 if (d->m_pen != pen) {
165 if (d->m_pen != pen) {
166 bool emitColorChanged = d->m_pen.color() != pen.color();
166 bool emitColorChanged = d->m_pen.color() != pen.color();
167 d->m_pen = pen;
167 d->m_pen = pen;
168 emit d->updated();
168 emit d->updated();
169 if (emitColorChanged)
169 if (emitColorChanged)
170 emit borderColorChanged(pen.color());
170 emit borderColorChanged(pen.color());
171 }
171 }
172 }
172 }
173
173
174 /*!
174 /*!
175 Sets \a brush used for drawing points on the chart. If the brush is not defined, brush
175 Sets \a brush used for drawing points on the chart. If the brush is not defined, brush
176 from chart theme setting is used.
176 from chart theme setting is used.
177 \sa QChart::setTheme()
177 \sa QChart::setTheme()
178 */
178 */
179 void QScatterSeries::setBrush(const QBrush &brush)
179 void QScatterSeries::setBrush(const QBrush &brush)
180 {
180 {
181 Q_D(QScatterSeries);
181 Q_D(QScatterSeries);
182 if (d->m_brush != brush) {
182 if (d->m_brush != brush) {
183 bool emitColorChanged = d->m_brush.color() != brush.color();
183 bool emitColorChanged = d->m_brush.color() != brush.color();
184 d->m_brush = brush;
184 d->m_brush = brush;
185 emit d->updated();
185 emit d->updated();
186 if (emitColorChanged)
186 if (emitColorChanged)
187 emit colorChanged(brush.color());
187 emit colorChanged(brush.color());
188 }
188 }
189 }
189 }
190
190
191 void QScatterSeries::setColor(const QColor &color)
191 void QScatterSeries::setColor(const QColor &color)
192 {
192 {
193 QBrush b = brush();
193 QBrush b = brush();
194 if (b == QBrush())
194 if (b == QBrush())
195 b.setStyle(Qt::SolidPattern);
195 b.setStyle(Qt::SolidPattern);
196 b.setColor(color);
196 b.setColor(color);
197 setBrush(b);
197 setBrush(b);
198 }
198 }
199
199
200 QColor QScatterSeries::color() const
200 QColor QScatterSeries::color() const
201 {
201 {
202 return brush().color();
202 return brush().color();
203 }
203 }
204
204
205 void QScatterSeries::setBorderColor(const QColor &color)
205 void QScatterSeries::setBorderColor(const QColor &color)
206 {
206 {
207 QPen p = pen();
207 QPen p = pen();
208 if (p.color() != color) {
208 if (p.color() != color) {
209 p.setColor(color);
209 p.setColor(color);
210 setPen(p);
210 setPen(p);
211 }
211 }
212 }
212 }
213
213
214 QColor QScatterSeries::borderColor() const
214 QColor QScatterSeries::borderColor() const
215 {
215 {
216 return pen().color();
216 return pen().color();
217 }
217 }
218
218
219 QScatterSeries::MarkerShape QScatterSeries::markerShape() const
219 QScatterSeries::MarkerShape QScatterSeries::markerShape() const
220 {
220 {
221 Q_D(const QScatterSeries);
221 Q_D(const QScatterSeries);
222 return d->m_shape;
222 return d->m_shape;
223 }
223 }
224
224
225 void QScatterSeries::setMarkerShape(MarkerShape shape)
225 void QScatterSeries::setMarkerShape(MarkerShape shape)
226 {
226 {
227 Q_D(QScatterSeries);
227 Q_D(QScatterSeries);
228 if (d->m_shape != shape) {
228 if (d->m_shape != shape) {
229 d->m_shape = shape;
229 d->m_shape = shape;
230 emit d->updated();
230 emit d->updated();
231 }
231 }
232 }
232 }
233
233
234 qreal QScatterSeries::markerSize() const
234 qreal QScatterSeries::markerSize() const
235 {
235 {
236 Q_D(const QScatterSeries);
236 Q_D(const QScatterSeries);
237 return d->m_size;
237 return d->m_size;
238 }
238 }
239
239
240 void QScatterSeries::setMarkerSize(qreal size)
240 void QScatterSeries::setMarkerSize(qreal size)
241 {
241 {
242 Q_D(QScatterSeries);
242 Q_D(QScatterSeries);
243
243
244 if (!qFuzzyCompare(d->m_size, size)) {
244 if (!qFuzzyCompare(d->m_size, size)) {
245 d->m_size = size;
245 d->m_size = size;
246 emit d->updated();
246 emit d->updated();
247 }
247 }
248 }
248 }
249
249
250 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
250 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
251
251
252 QScatterSeriesPrivate::QScatterSeriesPrivate(QScatterSeries *q)
252 QScatterSeriesPrivate::QScatterSeriesPrivate(QScatterSeries *q)
253 : QXYSeriesPrivate(q),
253 : QXYSeriesPrivate(q),
254 m_shape(QScatterSeries::MarkerShapeCircle),
254 m_shape(QScatterSeries::MarkerShapeCircle),
255 m_size(15.0)
255 m_size(15.0)
256 {
256 {
257 }
257 }
258
258
259 void QScatterSeriesPrivate::initializeGraphics(QGraphicsItem* parent)
259 void QScatterSeriesPrivate::initializeGraphics(QGraphicsItem* parent)
260 {
260 {
261 Q_Q(QScatterSeries);
261 Q_Q(QScatterSeries);
262 ScatterChartItem *scatter = new ScatterChartItem(q,parent);
262 ScatterChartItem *scatter = new ScatterChartItem(q,parent);
263 m_item.reset(scatter);
263 m_item.reset(scatter);
264 QAbstractSeriesPrivate::initializeGraphics(parent);
264 QAbstractSeriesPrivate::initializeGraphics(parent);
265 }
265 }
266
266
267 void QScatterSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced)
267 void QScatterSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced)
268 {
268 {
269 Q_Q(QScatterSeries);
269 Q_Q(QScatterSeries);
270 const QList<QColor> colors = theme->seriesColors();
270 const QList<QColor> colors = theme->seriesColors();
271 const QList<QGradient> gradients = theme->seriesGradients();
271 const QList<QGradient> gradients = theme->seriesGradients();
272
272
273 if (forced || QChartPrivate::defaultPen() == m_pen) {
273 if (forced || QChartPrivate::defaultPen() == m_pen) {
274 QPen pen;
274 QPen pen;
275 pen.setColor(ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.0));
275 pen.setColor(ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.0));
276 pen.setWidthF(2);
276 pen.setWidthF(2);
277 q->setPen(pen);
277 q->setPen(pen);
278 }
278 }
279
279
280 if (forced || QChartPrivate::defaultBrush() == m_brush) {
280 if (forced || QChartPrivate::defaultBrush() == m_brush) {
281 QBrush brush(colors.at(index % colors.size()));
281 QBrush brush(colors.at(index % colors.size()));
282 q->setBrush(brush);
282 q->setBrush(brush);
283 }
283 }
284 }
284 }
285
285
286 void QScatterSeriesPrivate::initializeAnimations(QChart::AnimationOptions options)
286 void QScatterSeriesPrivate::initializeAnimations(QChart::AnimationOptions options)
287 {
287 {
288 ScatterChartItem *item = static_cast<ScatterChartItem *>(m_item.data());
288 ScatterChartItem *item = static_cast<ScatterChartItem *>(m_item.data());
289 Q_ASSERT(item);
289 Q_ASSERT(item);
290
290
291 if (options.testFlag(QChart::SeriesAnimations))
291 if (options.testFlag(QChart::SeriesAnimations))
292 item->setAnimation(new ScatterAnimation(item));
292 item->setAnimation(new ScatterAnimation(item));
293 else
293 else
294 item->setAnimation(0);
294 item->setAnimation(0);
295
295
296 QAbstractSeriesPrivate::initializeAnimations(options);
296 QAbstractSeriesPrivate::initializeAnimations(options);
297 }
297 }
298
298
299 #include "moc_qscatterseries.cpp"
299 #include "moc_qscatterseries.cpp"
300
300
301 QTCOMMERCIALCHART_END_NAMESPACE
301 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,232 +1,237
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qhxymodelmapper.h"
21 #include "qhxymodelmapper.h"
22
22
23 QTCOMMERCIALCHART_BEGIN_NAMESPACE
23 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24
24
25 /*!
25 /*!
26 \class QHXYModelMapper
26 \class QHXYModelMapper
27 \mainclass
27 \mainclass
28
28
29 Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series.
29 Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series.
30 Horizontal model mapper is used to create a connection between QXYSeries and QAbstractItemModel derived model object.
30 Horizontal model mapper is used to create a connection between QXYSeries and QAbstractItemModel derived model object.
31 It is possible to use both QAbstractItemModel and QXYSeries model API. QXYModelMapper makes sure that QXYSeries and the model are kept in sync.
31 It is possible to use both QAbstractItemModel and QXYSeries model API. QXYModelMapper makes sure that QXYSeries and the model are kept in sync.
32 Note: used model has to support adding/removing rows/columns and modifying the data of the cells.
32 Note: used model has to support adding/removing rows/columns and modifying the data of the cells.
33 */
33 */
34 /*!
34 /*!
35 \qmlclass HXYModelMapper QHXYModelMapper
35 \qmlclass HXYModelMapper QHXYModelMapper
36
36
37 HXYModelMapper allows you to use your own QAbstractItemModel derived model with data in rows as a data source
37 HXYModelMapper allows you to use your own QAbstractItemModel derived model with data in rows as a data source
38 for XYSeries based series. It is possible to use both QAbstractItemModel and XYSeries data API to manipulate data.
38 for XYSeries based series. It is possible to use both QAbstractItemModel and XYSeries data API to manipulate data.
39 HXYModelMapper keeps the series and the model in sync.
39 HXYModelMapper keeps the series and the model in sync.
40 */
40 */
41
41
42 /*!
42 /*!
43 \property QHXYModelMapper::series
43 \property QHXYModelMapper::series
44 \brief Defines the QXYSeries object that is used by the mapper.
44 \brief Defines the QXYSeries object that is used by the mapper.
45
45 All the data in the series is discarded when it is set to the mapper.
46 All the data in the series is discarded when it is set to the mapper.
46 When new series is specified the old series is disconnected (it preserves its data)
47 When new series is specified the old series is disconnected (it preserves its data)
47 */
48 */
48 /*!
49 /*!
49 \qmlproperty XYSeries HXYModelMapper::series
50 \qmlproperty XYSeries HXYModelMapper::series
50 Defines the XYSeries object that is used by the mapper. All the data in the series is discarded when it is set to
51 Defines the XYSeries object that is used by the mapper. All the data in the series is discarded when it is set to
51 the mapper. When new series is specified the old series is disconnected (it preserves its data).
52 the mapper. When new series is specified the old series is disconnected (it preserves its data).
52 */
53 */
53
54
54 /*!
55 /*!
55 \property QHXYModelMapper::model
56 \property QHXYModelMapper::model
56 \brief Defines the model that is used by the mapper.
57 \brief Defines the model that is used by the mapper.
57 */
58 */
58 /*!
59 /*!
59 \qmlproperty SomeModel HXYModelMapper::model
60 \qmlproperty SomeModel HXYModelMapper::model
60 The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to
61 The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to
61 QML as shown in \l {QML Custom Model} demo application. Note: the model has to support adding/removing rows/columns
62 QML as shown in \l {QML Custom Model} demo application. Note: the model has to support adding/removing rows/columns
62 and modifying the data of the cells.
63 and modifying the data of the cells.
63 */
64 */
64
65
65 /*!
66 /*!
66 \property QHXYModelMapper::xRow
67 \property QHXYModelMapper::xRow
67 \brief Defines which row of the model is kept in sync with the x values of the QXYSeries
68 \brief Defines which row of the model is kept in sync with the x values of the QXYSeries.
69
68 Default value is: -1 (invalid mapping)
70 Default value is: -1 (invalid mapping)
69 */
71 */
70 /*!
72 /*!
71 \qmlproperty int HXYModelMapper::xRow
73 \qmlproperty int HXYModelMapper::xRow
72 Defines which row of the model is kept in sync with the x values of the series. Default value is -1 (invalid
74 Defines which row of the model is kept in sync with the x values of the series. Default value is -1 (invalid
73 mapping).
75 mapping).
74 */
76 */
75
77
76 /*!
78 /*!
77 \property QHXYModelMapper::yRow
79 \property QHXYModelMapper::yRow
78 \brief Defines which row of the model is kept in sync with the y values of the QXYSeries
80 \brief Defines which row of the model is kept in sync with the y values of the QXYSeries.
81
79 Default value is: -1 (invalid mapping)
82 Default value is: -1 (invalid mapping)
80 */
83 */
81 /*!
84 /*!
82 \qmlproperty int HXYModelMapper::yRow
85 \qmlproperty int HXYModelMapper::yRow
83 Defines which row of the model is kept in sync with the y values of the series. Default value is -1
86 Defines which row of the model is kept in sync with the y values of the series. Default value is -1
84 (invalid mapping).
87 (invalid mapping).
85 */
88 */
86
89
87 /*!
90 /*!
88 \property QHXYModelMapper::firstColumn
91 \property QHXYModelMapper::firstColumn
89 \brief Defines which column of the model contains the data for the first point of the series.
92 \brief Defines which column of the model contains the data for the first point of the series.
93
90 Minimal and default value is: 0
94 Minimal and default value is: 0
91 */
95 */
92 /*!
96 /*!
93 \qmlproperty int HXYModelMapper::firstColumn
97 \qmlproperty int HXYModelMapper::firstColumn
94 Defines which column of the model contains the data for the first point of the series.
98 Defines which column of the model contains the data for the first point of the series.
95 The default value is 0.
99 The default value is 0.
96 */
100 */
97
101
98 /*!
102 /*!
99 \property QHXYModelMapper::columnCount
103 \property QHXYModelMapper::columnCount
100 \brief Defines the number of columns of the model that are mapped as the data for series
104 \brief Defines the number of columns of the model that are mapped as the data for series.
105
101 Minimal and default value is: -1 (count limited by the number of columns in the model)
106 Minimal and default value is: -1 (count limited by the number of columns in the model)
102 */
107 */
103 /*!
108 /*!
104 \qmlproperty int HXYModelMapper::columnCount
109 \qmlproperty int HXYModelMapper::columnCount
105 Defines the number of columns of the model that are mapped as the data for series. The default value is
110 Defines the number of columns of the model that are mapped as the data for series. The default value is
106 -1 (count limited by the number of columns in the model)
111 -1 (count limited by the number of columns in the model)
107 */
112 */
108
113
109 /*!
114 /*!
110 \fn void QHXYModelMapper::seriesReplaced()
115 \fn void QHXYModelMapper::seriesReplaced()
111
116
112 Emitted when the series to which mapper is connected to has changed.
117 Emitted when the series to which mapper is connected to has changed.
113 */
118 */
114
119
115 /*!
120 /*!
116 \fn void QHXYModelMapper::modelReplaced()
121 \fn void QHXYModelMapper::modelReplaced()
117
122
118 Emitted when the model to which mapper is connected to has changed.
123 Emitted when the model to which mapper is connected to has changed.
119 */
124 */
120
125
121 /*!
126 /*!
122 \fn void QHXYModelMapper::xRowChanged()
127 \fn void QHXYModelMapper::xRowChanged()
123
128
124 Emitted when the xRow has changed.
129 Emitted when the xRow has changed.
125 */
130 */
126
131
127 /*!
132 /*!
128 \fn void QHXYModelMapper::yRowChanged()
133 \fn void QHXYModelMapper::yRowChanged()
129
134
130 Emitted when the yRow has changed.
135 Emitted when the yRow has changed.
131 */
136 */
132
137
133 /*!
138 /*!
134 \fn void QHXYModelMapper::firstColumnChanged()
139 \fn void QHXYModelMapper::firstColumnChanged()
135 Emitted when the firstColumn has changed.
140 Emitted when the firstColumn has changed.
136 */
141 */
137
142
138 /*!
143 /*!
139 \fn void QHXYModelMapper::columnCountChanged()
144 \fn void QHXYModelMapper::columnCountChanged()
140 Emitted when the columnCount has changed.
145 Emitted when the columnCount has changed.
141 */
146 */
142
147
143 /*!
148 /*!
144 Constructs a mapper object which is a child of \a parent.
149 Constructs a mapper object which is a child of \a parent.
145 */
150 */
146 QHXYModelMapper::QHXYModelMapper(QObject *parent) :
151 QHXYModelMapper::QHXYModelMapper(QObject *parent) :
147 QXYModelMapper(parent)
152 QXYModelMapper(parent)
148 {
153 {
149 QXYModelMapper::setOrientation(Qt::Horizontal);
154 QXYModelMapper::setOrientation(Qt::Horizontal);
150 }
155 }
151
156
152 QAbstractItemModel *QHXYModelMapper::model() const
157 QAbstractItemModel *QHXYModelMapper::model() const
153 {
158 {
154 return QXYModelMapper::model();
159 return QXYModelMapper::model();
155 }
160 }
156
161
157 void QHXYModelMapper::setModel(QAbstractItemModel *model)
162 void QHXYModelMapper::setModel(QAbstractItemModel *model)
158 {
163 {
159 if (model != QXYModelMapper::model()) {
164 if (model != QXYModelMapper::model()) {
160 QXYModelMapper::setModel(model);
165 QXYModelMapper::setModel(model);
161 emit modelReplaced();
166 emit modelReplaced();
162 }
167 }
163 }
168 }
164
169
165 QXYSeries *QHXYModelMapper::series() const
170 QXYSeries *QHXYModelMapper::series() const
166 {
171 {
167 return QXYModelMapper::series();
172 return QXYModelMapper::series();
168 }
173 }
169
174
170 void QHXYModelMapper::setSeries(QXYSeries *series)
175 void QHXYModelMapper::setSeries(QXYSeries *series)
171 {
176 {
172 if (series != QXYModelMapper::series()) {
177 if (series != QXYModelMapper::series()) {
173 QXYModelMapper::setSeries(series);
178 QXYModelMapper::setSeries(series);
174 emit seriesReplaced();
179 emit seriesReplaced();
175 }
180 }
176 }
181 }
177
182
178 int QHXYModelMapper::xRow() const
183 int QHXYModelMapper::xRow() const
179 {
184 {
180 return QXYModelMapper::xSection();
185 return QXYModelMapper::xSection();
181 }
186 }
182
187
183 void QHXYModelMapper::setXRow(int xRow)
188 void QHXYModelMapper::setXRow(int xRow)
184 {
189 {
185 if (xRow != xSection()) {
190 if (xRow != xSection()) {
186 QXYModelMapper::setXSection(xRow);
191 QXYModelMapper::setXSection(xRow);
187 emit xRowChanged();
192 emit xRowChanged();
188 }
193 }
189 }
194 }
190
195
191 int QHXYModelMapper::yRow() const
196 int QHXYModelMapper::yRow() const
192 {
197 {
193 return QXYModelMapper::ySection();
198 return QXYModelMapper::ySection();
194 }
199 }
195
200
196 void QHXYModelMapper::setYRow(int yRow)
201 void QHXYModelMapper::setYRow(int yRow)
197 {
202 {
198 if (yRow != ySection()) {
203 if (yRow != ySection()) {
199 QXYModelMapper::setYSection(yRow);
204 QXYModelMapper::setYSection(yRow);
200 emit yRowChanged();
205 emit yRowChanged();
201 }
206 }
202 }
207 }
203
208
204 int QHXYModelMapper::firstColumn() const
209 int QHXYModelMapper::firstColumn() const
205 {
210 {
206 return first();
211 return first();
207 }
212 }
208
213
209 void QHXYModelMapper::setFirstColumn(int firstColumn)
214 void QHXYModelMapper::setFirstColumn(int firstColumn)
210 {
215 {
211 if (firstColumn != first()) {
216 if (firstColumn != first()) {
212 setFirst(firstColumn);
217 setFirst(firstColumn);
213 emit firstColumnChanged();
218 emit firstColumnChanged();
214 }
219 }
215 }
220 }
216
221
217 int QHXYModelMapper::columnCount() const
222 int QHXYModelMapper::columnCount() const
218 {
223 {
219 return count();
224 return count();
220 }
225 }
221
226
222 void QHXYModelMapper::setColumnCount(int columnCount)
227 void QHXYModelMapper::setColumnCount(int columnCount)
223 {
228 {
224 if (columnCount != count()) {
229 if (columnCount != count()) {
225 setCount(columnCount);
230 setCount(columnCount);
226 emit columnCountChanged();
231 emit columnCountChanged();
227 }
232 }
228 }
233 }
229
234
230 #include "moc_qhxymodelmapper.cpp"
235 #include "moc_qhxymodelmapper.cpp"
231
236
232 QTCOMMERCIALCHART_END_NAMESPACE
237 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,232 +1,237
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qvxymodelmapper.h"
21 #include "qvxymodelmapper.h"
22
22
23 QTCOMMERCIALCHART_BEGIN_NAMESPACE
23 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24
24
25 /*!
25 /*!
26 \class QVXYModelMapper
26 \class QVXYModelMapper
27 \mainclass
27 \mainclass
28
28
29 Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series.
29 Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series.
30 Vertical model mapper is used to create a connection between QXYSeries and QAbstractItemModel derived model object.
30 Vertical model mapper is used to create a connection between QXYSeries and QAbstractItemModel derived model object.
31 It is possible to use both QAbstractItemModel and QXYSeries model API. QXYModelMapper makes sure that QXYSeries and the model are kept in sync.
31 It is possible to use both QAbstractItemModel and QXYSeries model API. QXYModelMapper makes sure that QXYSeries and the model are kept in sync.
32 Note: used model has to support adding/removing rows/columns and modifying the data of the cells.
32 Note: used model has to support adding/removing rows/columns and modifying the data of the cells.
33 */
33 */
34 /*!
34 /*!
35 \qmlclass VXYModelMapper QHXYModelMapper
35 \qmlclass VXYModelMapper QHXYModelMapper
36
36
37 VXYModelMapper allows you to use your own QAbstractItemModel derived model with data in columns as a data source
37 VXYModelMapper allows you to use your own QAbstractItemModel derived model with data in columns as a data source
38 for XYSeries based series. It is possible to use both QAbstractItemModel and XYSeries data API to manipulate data.
38 for XYSeries based series. It is possible to use both QAbstractItemModel and XYSeries data API to manipulate data.
39 VYModelMapper keeps the series and the model in sync.
39 VYModelMapper keeps the series and the model in sync.
40 */
40 */
41
41
42 /*!
42 /*!
43 \property QVXYModelMapper::series
43 \property QVXYModelMapper::series
44 \brief Defines the QXYSeries object that is used by the mapper.
44 \brief Defines the QXYSeries object that is used by the mapper.
45
45 All the data in the series is discarded when it is set to the mapper.
46 All the data in the series is discarded when it is set to the mapper.
46 When new series is specified the old series is disconnected (it preserves its data)
47 When new series is specified the old series is disconnected (it preserves its data)
47 */
48 */
48 /*!
49 /*!
49 \qmlproperty XYSeries VXYModelMapper::series
50 \qmlproperty XYSeries VXYModelMapper::series
50 Defines the XYSeries object that is used by the mapper. All the data in the series is discarded when it is set to
51 Defines the XYSeries object that is used by the mapper. All the data in the series is discarded when it is set to
51 the mapper. When new series is specified the old series is disconnected (it preserves its data).
52 the mapper. When new series is specified the old series is disconnected (it preserves its data).
52 */
53 */
53
54
54 /*!
55 /*!
55 \property QVXYModelMapper::model
56 \property QVXYModelMapper::model
56 \brief Defines the model that is used by the mapper.
57 \brief Defines the model that is used by the mapper.
57 */
58 */
58 /*!
59 /*!
59 \qmlproperty SomeModel VXYModelMapper::model
60 \qmlproperty SomeModel VXYModelMapper::model
60 The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to
61 The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to
61 QML as shown in \l {QML Custom Model} demo application. Note: the model has to support adding/removing rows/columns
62 QML as shown in \l {QML Custom Model} demo application. Note: the model has to support adding/removing rows/columns
62 and modifying the data of the cells.
63 and modifying the data of the cells.
63 */
64 */
64
65
65 /*!
66 /*!
66 \property QVXYModelMapper::xColumn
67 \property QVXYModelMapper::xColumn
67 \brief Defines which column of the model is kept in sync with the x values of QXYSeries
68 \brief Defines which column of the model is kept in sync with the x values of QXYSeries.
69
68 Default value is: -1 (invalid mapping)
70 Default value is: -1 (invalid mapping)
69 */
71 */
70 /*!
72 /*!
71 \qmlproperty int VXYModelMapper::xColumn
73 \qmlproperty int VXYModelMapper::xColumn
72 Defines which column of the model is kept in sync with the x values of the series. Default value is -1 (invalid
74 Defines which column of the model is kept in sync with the x values of the series. Default value is -1 (invalid
73 mapping).
75 mapping).
74 */
76 */
75
77
76 /*!
78 /*!
77 \property QVXYModelMapper::yColumn
79 \property QVXYModelMapper::yColumn
78 \brief Defines which column of the model is kept in sync with the y values of QXYSeries
80 \brief Defines which column of the model is kept in sync with the y values of QXYSeries.
81
79 Default value is: -1 (invalid mapping)
82 Default value is: -1 (invalid mapping)
80 */
83 */
81 /*!
84 /*!
82 \qmlproperty int VXYModelMapper::yColumn
85 \qmlproperty int VXYModelMapper::yColumn
83 Defines which column of the model is kept in sync with the y values of the series. Default value is -1 (invalid
86 Defines which column of the model is kept in sync with the y values of the series. Default value is -1 (invalid
84 mapping).
87 mapping).
85 */
88 */
86
89
87 /*!
90 /*!
88 \property QVXYModelMapper::firstRow
91 \property QVXYModelMapper::firstRow
89 \brief Defines which row of the model contains the data for the first point of the series.
92 \brief Defines which row of the model contains the data for the first point of the series.
93
90 Minimal and default value is: 0
94 Minimal and default value is: 0
91 */
95 */
92 /*!
96 /*!
93 \qmlproperty int VXYModelMapper::firstRow
97 \qmlproperty int VXYModelMapper::firstRow
94 Defines which row of the model contains the data for the first point of the series.
98 Defines which row of the model contains the data for the first point of the series.
95 The default value is 0.
99 The default value is 0.
96 */
100 */
97
101
98 /*!
102 /*!
99 \property QVXYModelMapper::rowCount
103 \property QVXYModelMapper::rowCount
100 \brief Defines the number of rows of the model that are mapped as the data for series
104 \brief Defines the number of rows of the model that are mapped as the data for series.
105
101 Minimal and default value is: -1 (count limited by the number of rows in the model)
106 Minimal and default value is: -1 (count limited by the number of rows in the model)
102 */
107 */
103 /*!
108 /*!
104 \qmlproperty int VXYModelMapper::columnCount
109 \qmlproperty int VXYModelMapper::columnCount
105 Defines the number of rows of the model that are mapped as the data for series. The default value is
110 Defines the number of rows of the model that are mapped as the data for series. The default value is
106 -1 (count limited by the number of rows in the model).
111 -1 (count limited by the number of rows in the model).
107 */
112 */
108
113
109 /*!
114 /*!
110 \fn void QVXYModelMapper::seriesReplaced()
115 \fn void QVXYModelMapper::seriesReplaced()
111
116
112 Emitted when the series to which mapper is connected to has changed.
117 Emitted when the series to which mapper is connected to has changed.
113 */
118 */
114
119
115 /*!
120 /*!
116 \fn void QVXYModelMapper::modelReplaced()
121 \fn void QVXYModelMapper::modelReplaced()
117
122
118 Emitted when the model to which mapper is connected to has changed.
123 Emitted when the model to which mapper is connected to has changed.
119 */
124 */
120
125
121 /*!
126 /*!
122 \fn void QVXYModelMapper::xColumnChanged()
127 \fn void QVXYModelMapper::xColumnChanged()
123
128
124 Emitted when the xColumn has changed.
129 Emitted when the xColumn has changed.
125 */
130 */
126
131
127 /*!
132 /*!
128 \fn void QVXYModelMapper::yColumnChanged()
133 \fn void QVXYModelMapper::yColumnChanged()
129
134
130 Emitted when the yColumn has changed.
135 Emitted when the yColumn has changed.
131 */
136 */
132
137
133 /*!
138 /*!
134 \fn void QVXYModelMapper::firstRowChanged()
139 \fn void QVXYModelMapper::firstRowChanged()
135 Emitted when the firstRow has changed.
140 Emitted when the firstRow has changed.
136 */
141 */
137
142
138 /*!
143 /*!
139 \fn void QVXYModelMapper::rowCountChanged()
144 \fn void QVXYModelMapper::rowCountChanged()
140 Emitted when the rowCount has changed.
145 Emitted when the rowCount has changed.
141 */
146 */
142
147
143 /*!
148 /*!
144 Constructs a mapper object which is a child of \a parent.
149 Constructs a mapper object which is a child of \a parent.
145 */
150 */
146 QVXYModelMapper::QVXYModelMapper(QObject *parent) :
151 QVXYModelMapper::QVXYModelMapper(QObject *parent) :
147 QXYModelMapper(parent)
152 QXYModelMapper(parent)
148 {
153 {
149 QXYModelMapper::setOrientation(Qt::Vertical);
154 QXYModelMapper::setOrientation(Qt::Vertical);
150 }
155 }
151
156
152 QAbstractItemModel *QVXYModelMapper::model() const
157 QAbstractItemModel *QVXYModelMapper::model() const
153 {
158 {
154 return QXYModelMapper::model();
159 return QXYModelMapper::model();
155 }
160 }
156
161
157 void QVXYModelMapper::setModel(QAbstractItemModel *model)
162 void QVXYModelMapper::setModel(QAbstractItemModel *model)
158 {
163 {
159 if (model != QXYModelMapper::model()) {
164 if (model != QXYModelMapper::model()) {
160 QXYModelMapper::setModel(model);
165 QXYModelMapper::setModel(model);
161 emit modelReplaced();
166 emit modelReplaced();
162 }
167 }
163 }
168 }
164
169
165 QXYSeries *QVXYModelMapper::series() const
170 QXYSeries *QVXYModelMapper::series() const
166 {
171 {
167 return QXYModelMapper::series();
172 return QXYModelMapper::series();
168 }
173 }
169
174
170 void QVXYModelMapper::setSeries(QXYSeries *series)
175 void QVXYModelMapper::setSeries(QXYSeries *series)
171 {
176 {
172 if (series != QXYModelMapper::series()) {
177 if (series != QXYModelMapper::series()) {
173 QXYModelMapper::setSeries(series);
178 QXYModelMapper::setSeries(series);
174 emit seriesReplaced();
179 emit seriesReplaced();
175 }
180 }
176 }
181 }
177
182
178 int QVXYModelMapper::xColumn() const
183 int QVXYModelMapper::xColumn() const
179 {
184 {
180 return QXYModelMapper::xSection();
185 return QXYModelMapper::xSection();
181 }
186 }
182
187
183 void QVXYModelMapper::setXColumn(int xColumn)
188 void QVXYModelMapper::setXColumn(int xColumn)
184 {
189 {
185 if (xColumn != xSection()) {
190 if (xColumn != xSection()) {
186 QXYModelMapper::setXSection(xColumn);
191 QXYModelMapper::setXSection(xColumn);
187 emit xColumnChanged();
192 emit xColumnChanged();
188 }
193 }
189 }
194 }
190
195
191 int QVXYModelMapper::yColumn() const
196 int QVXYModelMapper::yColumn() const
192 {
197 {
193 return QXYModelMapper::ySection();
198 return QXYModelMapper::ySection();
194 }
199 }
195
200
196 void QVXYModelMapper::setYColumn(int yColumn)
201 void QVXYModelMapper::setYColumn(int yColumn)
197 {
202 {
198 if (yColumn != ySection()) {
203 if (yColumn != ySection()) {
199 QXYModelMapper::setYSection(yColumn);
204 QXYModelMapper::setYSection(yColumn);
200 emit yColumnChanged();
205 emit yColumnChanged();
201 }
206 }
202 }
207 }
203
208
204 int QVXYModelMapper::firstRow() const
209 int QVXYModelMapper::firstRow() const
205 {
210 {
206 return first();
211 return first();
207 }
212 }
208
213
209 void QVXYModelMapper::setFirstRow(int firstRow)
214 void QVXYModelMapper::setFirstRow(int firstRow)
210 {
215 {
211 if (firstRow != first()) {
216 if (firstRow != first()) {
212 setFirst(firstRow);
217 setFirst(firstRow);
213 emit firstRowChanged();
218 emit firstRowChanged();
214 }
219 }
215 }
220 }
216
221
217 int QVXYModelMapper::rowCount() const
222 int QVXYModelMapper::rowCount() const
218 {
223 {
219 return count();
224 return count();
220 }
225 }
221
226
222 void QVXYModelMapper::setRowCount(int rowCount)
227 void QVXYModelMapper::setRowCount(int rowCount)
223 {
228 {
224 if (rowCount != count()) {
229 if (rowCount != count()) {
225 setCount(rowCount);
230 setCount(rowCount);
226 emit rowCountChanged();
231 emit rowCountChanged();
227 }
232 }
228 }
233 }
229
234
230 #include "moc_qvxymodelmapper.cpp"
235 #include "moc_qvxymodelmapper.cpp"
231
236
232 QTCOMMERCIALCHART_END_NAMESPACE
237 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now