##// END OF EJS Templates
made qabstractbarseries constructor protected. Updated tests
sauimone -
r1587:60ca912b003e
parent child
Show More
@@ -1,501 +1,498
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "declarativechart.h"
21 #include "declarativechart.h"
22 #include <QPainter>
22 #include <QPainter>
23 #include "declarativelineseries.h"
23 #include "declarativelineseries.h"
24 #include "declarativeareaseries.h"
24 #include "declarativeareaseries.h"
25 #include "declarativebarseries.h"
25 #include "declarativebarseries.h"
26 #include "declarativepieseries.h"
26 #include "declarativepieseries.h"
27 #include "declarativesplineseries.h"
27 #include "declarativesplineseries.h"
28 #include "declarativescatterseries.h"
28 #include "declarativescatterseries.h"
29 #include "qcategoriesaxis.h"
29 #include "qcategoriesaxis.h"
30
30
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32
32
33 /*!
33 /*!
34 \qmlclass ChartView DeclarativeChart
34 \qmlclass ChartView DeclarativeChart
35
35
36 ChartView element is the parent that is responsible for showing different chart series types.
36 ChartView element is the parent that is responsible for showing different chart series types.
37
37
38 The following QML shows how to create a simple chart with one pie series:
38 The following QML shows how to create a simple chart with one pie series:
39 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 1
39 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 1
40 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2
40 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2
41 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 3
41 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 3
42
42
43 \beginfloatleft
43 \beginfloatleft
44 \image examples_qmlpiechart.png
44 \image examples_qmlpiechart.png
45 \endfloat
45 \endfloat
46 \clearfloat
46 \clearfloat
47 */
47 */
48
48
49 /*!
49 /*!
50 \qmlproperty Theme ChartView::theme
50 \qmlproperty Theme ChartView::theme
51 Theme defines the visual appearance of the chart, including for example colors, fonts, line
51 Theme defines the visual appearance of the chart, including for example colors, fonts, line
52 widths and chart background.
52 widths and chart background.
53 */
53 */
54
54
55 /*!
55 /*!
56 \qmlproperty Animation ChartView::animation
56 \qmlproperty Animation ChartView::animation
57 Animation configuration of the chart. One of ChartView.NoAnimation, ChartView.GridAxisAnimations,
57 Animation configuration of the chart. One of ChartView.NoAnimation, ChartView.GridAxisAnimations,
58 ChartView.SeriesAnimations or ChartView.AllAnimations.
58 ChartView.SeriesAnimations or ChartView.AllAnimations.
59 */
59 */
60
60
61 /*!
61 /*!
62 \qmlproperty Font ChartView::titleFont
62 \qmlproperty Font ChartView::titleFont
63 The title font of the chart
63 The title font of the chart
64
64
65 See the \l {Font} {QML Font Element} for detailed documentation.
65 See the \l {Font} {QML Font Element} for detailed documentation.
66 */
66 */
67
67
68 /*!
68 /*!
69 \qmlproperty string ChartView::title
69 \qmlproperty string ChartView::title
70 The title of the chart, shown on top of the chart.
70 The title of the chart, shown on top of the chart.
71 \sa ChartView::titleColor
71 \sa ChartView::titleColor
72 */
72 */
73
73
74 /*!
74 /*!
75 \qmlproperty string ChartView::titleColor
75 \qmlproperty string ChartView::titleColor
76 The color of the title text.
76 The color of the title text.
77 */
77 */
78
78
79 /*!
79 /*!
80 \qmlproperty Axis ChartView::axisX
80 \qmlproperty Axis ChartView::axisX
81 The x-axis of the chart.
81 The x-axis of the chart.
82 */
82 */
83
83
84 /*!
84 /*!
85 \qmlproperty Axis ChartView::axisY
85 \qmlproperty Axis ChartView::axisY
86 The default y-axis of the chart.
86 The default y-axis of the chart.
87 */
87 */
88
88
89 /*!
89 /*!
90 \qmlproperty Legend ChartView::legend
90 \qmlproperty Legend ChartView::legend
91 The legend of the chart. Legend lists all the series, pie slices and bar sets added on the chart.
91 The legend of the chart. Legend lists all the series, pie slices and bar sets added on the chart.
92 */
92 */
93
93
94 /*!
94 /*!
95 \qmlproperty int ChartView::count
95 \qmlproperty int ChartView::count
96 The count of series added to the chart.
96 The count of series added to the chart.
97 */
97 */
98
98
99 /*!
99 /*!
100 \qmlproperty color ChartView::backgroundColor
100 \qmlproperty color ChartView::backgroundColor
101 The color of the chart's background. By default background color is defined by chart theme.
101 The color of the chart's background. By default background color is defined by chart theme.
102 \sa ChartView::theme
102 \sa ChartView::theme
103 */
103 */
104
104
105 /*!
105 /*!
106 \qmlproperty bool ChartView::dropShadowEnabled
106 \qmlproperty bool ChartView::dropShadowEnabled
107 The chart's border drop shadow. Set to true to enable drop shadow.
107 The chart's border drop shadow. Set to true to enable drop shadow.
108 */
108 */
109
109
110 /*!
110 /*!
111 \qmlproperty real ChartView::topMargin
111 \qmlproperty real ChartView::topMargin
112 The space between the top of chart view and the top of the plot area. The title (if non-empty) is drawn on top margin
112 The space between the top of chart view and the top of the plot area. The title (if non-empty) is drawn on top margin
113 area of the chart view. Top margin area is also used by legend, if aligned to top.
113 area of the chart view. Top margin area is also used by legend, if aligned to top.
114 */
114 */
115
115
116 /*!
116 /*!
117 \qmlproperty real ChartView::bottomMargin
117 \qmlproperty real ChartView::bottomMargin
118 The space between the bottom of chart view and the bottom of the plot area. The bottom margin area may be used by
118 The space between the bottom of chart view and the bottom of the plot area. The bottom margin area may be used by
119 legend (if aligned to bottom), x-axis, x-axis labels and x-axis tick marks.
119 legend (if aligned to bottom), x-axis, x-axis labels and x-axis tick marks.
120 */
120 */
121
121
122 /*!
122 /*!
123 \qmlproperty real ChartView::leftMargin
123 \qmlproperty real ChartView::leftMargin
124 The space between the left side of chart view and the left side of the plot area. The left margin area may be used by
124 The space between the left side of chart view and the left side of the plot area. The left margin area may be used by
125 legend (if aligned to left), y-axis, y-axis labels and y-axis tick marks.
125 legend (if aligned to left), y-axis, y-axis labels and y-axis tick marks.
126 */
126 */
127
127
128 /*!
128 /*!
129 \qmlproperty real ChartView::rightMargin
129 \qmlproperty real ChartView::rightMargin
130 The space between the right side of chart view and the right side of the plot area. The right margin area may be used
130 The space between the right side of chart view and the right side of the plot area. The right margin area may be used
131 by legend (if aligned to right).
131 by legend (if aligned to right).
132 */
132 */
133
133
134 /*!
134 /*!
135 \qmlmethod AbstractSeries ChartView::series(int index)
135 \qmlmethod AbstractSeries ChartView::series(int index)
136 Returns the series with \a index on the chart. This allows you to loop through the series of a chart together with
136 Returns the series with \a index on the chart. This allows you to loop through the series of a chart together with
137 the count property of the chart.
137 the count property of the chart.
138 */
138 */
139
139
140 /*!
140 /*!
141 \qmlmethod AbstractSeries ChartView::series(string name)
141 \qmlmethod AbstractSeries ChartView::series(string name)
142 Returns the first series on the chart with \a name. If there is no series with that name, returns null.
142 Returns the first series on the chart with \a name. If there is no series with that name, returns null.
143 */
143 */
144
144
145 /*!
145 /*!
146 \qmlmethod AbstractSeries ChartView::createSeries(SeriesType type, string name)
146 \qmlmethod AbstractSeries ChartView::createSeries(SeriesType type, string name)
147 Creates a series object of \a type to the chart. For example:
147 Creates a series object of \a type to the chart. For example:
148 \code
148 \code
149 var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter series");
149 var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter series");
150 scatter.markerSize = 22;
150 scatter.markerSize = 22;
151 scatter.append(1.1, 2.0);
151 scatter.append(1.1, 2.0);
152 \endcode
152 \endcode
153 */
153 */
154
154
155 /*!
155 /*!
156 \qmlmethod Axis ChartView::axisY(QAbstractSeries *series)
156 \qmlmethod Axis ChartView::axisY(QAbstractSeries *series)
157 The y-axis of the series. This is the same as the default y-axis of the chart as multiple y-axes are not yet supported.
157 The y-axis of the series. This is the same as the default y-axis of the chart as multiple y-axes are not yet supported.
158 */
158 */
159
159
160 /*!
160 /*!
161 \qmlmethod ChartView::zoomY(real factor)
161 \qmlmethod ChartView::zoomY(real factor)
162 Zooms in by \a factor on the center of the chart.
162 Zooms in by \a factor on the center of the chart.
163 */
163 */
164
164
165 /*!
165 /*!
166 \qmlmethod ChartView::scrollLeft(real pixels)
166 \qmlmethod ChartView::scrollLeft(real pixels)
167 Scrolls to left by \a pixels. This is a convenience function that suits for example for key navigation.
167 Scrolls to left by \a pixels. This is a convenience function that suits for example for key navigation.
168 \sa Axis::min, Axis::max
168 \sa Axis::min, Axis::max
169 */
169 */
170
170
171 /*!
171 /*!
172 \qmlmethod ChartView::scrollRight(real pixels)
172 \qmlmethod ChartView::scrollRight(real pixels)
173 Scrolls to right by \a pixels. This is a convenience function that suits for example for key navigation.
173 Scrolls to right by \a pixels. This is a convenience function that suits for example for key navigation.
174 \sa Axis::min, Axis::max
174 \sa Axis::min, Axis::max
175 */
175 */
176
176
177 /*!
177 /*!
178 \qmlmethod ChartView::scrollUp(real pixels)
178 \qmlmethod ChartView::scrollUp(real pixels)
179 Scrolls up by \a pixels. This is a convenience function that suits for example for key navigation.
179 Scrolls up by \a pixels. This is a convenience function that suits for example for key navigation.
180 \sa Axis::min, Axis::max
180 \sa Axis::min, Axis::max
181 */
181 */
182
182
183 /*!
183 /*!
184 \qmlmethod ChartView::scrollDown(real pixels)
184 \qmlmethod ChartView::scrollDown(real pixels)
185 Scrolls down by \a pixels. This is a convenience function that suits for example for key navigation.
185 Scrolls down by \a pixels. This is a convenience function that suits for example for key navigation.
186 \sa Axis::min, Axis::max
186 \sa Axis::min, Axis::max
187 */
187 */
188
188
189 /*!
189 /*!
190 \qmlsignal ChartView::onTopMarginChanged(real margin)
190 \qmlsignal ChartView::onTopMarginChanged(real margin)
191 The top margin of the chart view has changed to \a margin. This may happen for example if you modify font size
191 The top margin of the chart view has changed to \a margin. This may happen for example if you modify font size
192 related properties of the legend or chart title.
192 related properties of the legend or chart title.
193 */
193 */
194
194
195 /*!
195 /*!
196 \qmlsignal ChartView::onBottomMarginChanged(real margin)
196 \qmlsignal ChartView::onBottomMarginChanged(real margin)
197 The bottom margin of the chart view has changed to \a margin. This may happen for example if you modify font size
197 The bottom margin of the chart view has changed to \a margin. This may happen for example if you modify font size
198 related properties of the legend or chart title.
198 related properties of the legend or chart title.
199 */
199 */
200
200
201 /*!
201 /*!
202 \qmlsignal ChartView::onLeftMarginChanged(real margin)
202 \qmlsignal ChartView::onLeftMarginChanged(real margin)
203 The left margin of the chart view has changed to \a margin. This may happen for example if you modify font size
203 The left margin of the chart view has changed to \a margin. This may happen for example if you modify font size
204 related properties of the legend or chart title.
204 related properties of the legend or chart title.
205 */
205 */
206
206
207 /*!
207 /*!
208 \qmlsignal ChartView::onRightMarginChanged(real margin)
208 \qmlsignal ChartView::onRightMarginChanged(real margin)
209 The right margin of the chart view has changed to \a margin. This may happen for example if you modify font size
209 The right margin of the chart view has changed to \a margin. This may happen for example if you modify font size
210 related properties of the legend or chart title.
210 related properties of the legend or chart title.
211 */
211 */
212
212
213 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent)
213 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent)
214 : QDeclarativeItem(parent),
214 : QDeclarativeItem(parent),
215 m_chart(new QChart(this))
215 m_chart(new QChart(this))
216 {
216 {
217 setFlag(QGraphicsItem::ItemHasNoContents, false);
217 setFlag(QGraphicsItem::ItemHasNoContents, false);
218 // m_chart->axisX()->setNiceNumbersEnabled(false);
218 // m_chart->axisX()->setNiceNumbersEnabled(false);
219 m_chartMargins = m_chart->margins();
219 m_chartMargins = m_chart->margins();
220 connect(m_chart, SIGNAL(marginsChanged(QRectF)), this, SLOT(handleMarginsChanged(QRectF)));
220 connect(m_chart, SIGNAL(marginsChanged(QRectF)), this, SLOT(handleMarginsChanged(QRectF)));
221 }
221 }
222
222
223 void DeclarativeChart::handleMarginsChanged(QRectF newMargins)
223 void DeclarativeChart::handleMarginsChanged(QRectF newMargins)
224 {
224 {
225 if (m_chartMargins.top() != newMargins.top())
225 if (m_chartMargins.top() != newMargins.top())
226 topMarginChanged(m_chart->margins().top());
226 topMarginChanged(m_chart->margins().top());
227 if (m_chartMargins.bottom() != newMargins.bottom())
227 if (m_chartMargins.bottom() != newMargins.bottom())
228 bottomMarginChanged(m_chart->margins().bottom());
228 bottomMarginChanged(m_chart->margins().bottom());
229 if (m_chartMargins.left() != newMargins.left())
229 if (m_chartMargins.left() != newMargins.left())
230 leftMarginChanged(m_chart->margins().left());
230 leftMarginChanged(m_chart->margins().left());
231 if (m_chartMargins.right() != newMargins.right())
231 if (m_chartMargins.right() != newMargins.right())
232 rightMarginChanged(m_chart->margins().right());
232 rightMarginChanged(m_chart->margins().right());
233
233
234 m_chartMargins = m_chart->margins();
234 m_chartMargins = m_chart->margins();
235 }
235 }
236
236
237 DeclarativeChart::~DeclarativeChart()
237 DeclarativeChart::~DeclarativeChart()
238 {
238 {
239 delete m_chart;
239 delete m_chart;
240 }
240 }
241
241
242 void DeclarativeChart::childEvent(QChildEvent *event)
242 void DeclarativeChart::childEvent(QChildEvent *event)
243 {
243 {
244 if (event->type() == QEvent::ChildAdded) {
244 if (event->type() == QEvent::ChildAdded) {
245 if (qobject_cast<QAbstractSeries *>(event->child())) {
245 if (qobject_cast<QAbstractSeries *>(event->child())) {
246 m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child()));
246 m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child()));
247 }
247 }
248 }
248 }
249 }
249 }
250
250
251 void DeclarativeChart::componentComplete()
251 void DeclarativeChart::componentComplete()
252 {
252 {
253 foreach(QObject *child, children()) {
253 foreach(QObject *child, children()) {
254 if (qobject_cast<QAbstractSeries *>(child)) {
254 if (qobject_cast<QAbstractSeries *>(child)) {
255 // qDebug() << "DeclarativeChart::componentComplete(), add: " << child;
255 // qDebug() << "DeclarativeChart::componentComplete(), add: " << child;
256 // TODO: how about optional y-axis?
256 // TODO: how about optional y-axis?
257 m_chart->addSeries(qobject_cast<QAbstractSeries *>(child));
257 m_chart->addSeries(qobject_cast<QAbstractSeries *>(child));
258 }
258 }
259 }
259 }
260 QDeclarativeItem::componentComplete();
260 QDeclarativeItem::componentComplete();
261 }
261 }
262
262
263 void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
263 void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
264 {
264 {
265 // qDebug() << "DeclarativeChart::geometryChanged" << newGeometry.width() << newGeometry.height();
265 // qDebug() << "DeclarativeChart::geometryChanged" << newGeometry.width() << newGeometry.height();
266 if (newGeometry.isValid()) {
266 if (newGeometry.isValid()) {
267 if (newGeometry.width() > 0 && newGeometry.height() > 0) {
267 if (newGeometry.width() > 0 && newGeometry.height() > 0) {
268 m_chart->resize(newGeometry.width(), newGeometry.height());
268 m_chart->resize(newGeometry.width(), newGeometry.height());
269 }
269 }
270 }
270 }
271 QDeclarativeItem::geometryChanged(newGeometry, oldGeometry);
271 QDeclarativeItem::geometryChanged(newGeometry, oldGeometry);
272 }
272 }
273
273
274 void DeclarativeChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
274 void DeclarativeChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
275 {
275 {
276 Q_UNUSED(option)
276 Q_UNUSED(option)
277 Q_UNUSED(widget)
277 Q_UNUSED(widget)
278
278
279 // TODO: optimized?
279 // TODO: optimized?
280 painter->setRenderHint(QPainter::Antialiasing, true);
280 painter->setRenderHint(QPainter::Antialiasing, true);
281 }
281 }
282
282
283 void DeclarativeChart::setTheme(DeclarativeChart::Theme theme)
283 void DeclarativeChart::setTheme(DeclarativeChart::Theme theme)
284 {
284 {
285 QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme;
285 QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme;
286 if (chartTheme != m_chart->theme())
286 if (chartTheme != m_chart->theme())
287 m_chart->setTheme(chartTheme);
287 m_chart->setTheme(chartTheme);
288 }
288 }
289
289
290 DeclarativeChart::Theme DeclarativeChart::theme()
290 DeclarativeChart::Theme DeclarativeChart::theme()
291 {
291 {
292 return (DeclarativeChart::Theme) m_chart->theme();
292 return (DeclarativeChart::Theme) m_chart->theme();
293 }
293 }
294
294
295 void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations)
295 void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations)
296 {
296 {
297 QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations;
297 QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations;
298 if (animationOptions != m_chart->animationOptions())
298 if (animationOptions != m_chart->animationOptions())
299 m_chart->setAnimationOptions(animationOptions);
299 m_chart->setAnimationOptions(animationOptions);
300 }
300 }
301
301
302 DeclarativeChart::Animation DeclarativeChart::animationOptions()
302 DeclarativeChart::Animation DeclarativeChart::animationOptions()
303 {
303 {
304 if (m_chart->animationOptions().testFlag(QChart::AllAnimations))
304 if (m_chart->animationOptions().testFlag(QChart::AllAnimations))
305 return DeclarativeChart::AllAnimations;
305 return DeclarativeChart::AllAnimations;
306 else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations))
306 else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations))
307 return DeclarativeChart::GridAxisAnimations;
307 return DeclarativeChart::GridAxisAnimations;
308 else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations))
308 else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations))
309 return DeclarativeChart::SeriesAnimations;
309 return DeclarativeChart::SeriesAnimations;
310 else
310 else
311 return DeclarativeChart::NoAnimation;
311 return DeclarativeChart::NoAnimation;
312 }
312 }
313
313
314 void DeclarativeChart::setTitle(QString title)
314 void DeclarativeChart::setTitle(QString title)
315 {
315 {
316 if (title != m_chart->title())
316 if (title != m_chart->title())
317 m_chart->setTitle(title);
317 m_chart->setTitle(title);
318 }
318 }
319 QString DeclarativeChart::title()
319 QString DeclarativeChart::title()
320 {
320 {
321 return m_chart->title();
321 return m_chart->title();
322 }
322 }
323
323
324 QAbstractAxis *DeclarativeChart::axisX(QAbstractSeries *series)
324 QAbstractAxis *DeclarativeChart::axisX(QAbstractSeries *series)
325 {
325 {
326 return m_chart->axisX(series);
326 return m_chart->axisX(series);
327 }
327 }
328
328
329 QAbstractAxis *DeclarativeChart::axisY(QAbstractSeries *series)
329 QAbstractAxis *DeclarativeChart::axisY(QAbstractSeries *series)
330 {
330 {
331 return m_chart->axisY(series);
331 return m_chart->axisY(series);
332 }
332 }
333
333
334 QLegend *DeclarativeChart::legend()
334 QLegend *DeclarativeChart::legend()
335 {
335 {
336 return m_chart->legend();
336 return m_chart->legend();
337 }
337 }
338
338
339 void DeclarativeChart::setTitleColor(QColor color)
339 void DeclarativeChart::setTitleColor(QColor color)
340 {
340 {
341 QBrush b = m_chart->titleBrush();
341 QBrush b = m_chart->titleBrush();
342 if (color != b.color()) {
342 if (color != b.color()) {
343 b.setColor(color);
343 b.setColor(color);
344 m_chart->setTitleBrush(b);
344 m_chart->setTitleBrush(b);
345 emit titleColorChanged(color);
345 emit titleColorChanged(color);
346 }
346 }
347 }
347 }
348
348
349 QFont DeclarativeChart::titleFont() const
349 QFont DeclarativeChart::titleFont() const
350 {
350 {
351 return m_chart->titleFont();
351 return m_chart->titleFont();
352 }
352 }
353
353
354 void DeclarativeChart::setTitleFont(const QFont& font)
354 void DeclarativeChart::setTitleFont(const QFont& font)
355 {
355 {
356 m_chart->setTitleFont(font);
356 m_chart->setTitleFont(font);
357 }
357 }
358
358
359 QColor DeclarativeChart::titleColor()
359 QColor DeclarativeChart::titleColor()
360 {
360 {
361 return m_chart->titleBrush().color();
361 return m_chart->titleBrush().color();
362 }
362 }
363
363
364 void DeclarativeChart::setBackgroundColor(QColor color)
364 void DeclarativeChart::setBackgroundColor(QColor color)
365 {
365 {
366 QBrush b = m_chart->backgroundBrush();
366 QBrush b = m_chart->backgroundBrush();
367 if (b.style() != Qt::SolidPattern || color != b.color()) {
367 if (b.style() != Qt::SolidPattern || color != b.color()) {
368 b.setStyle(Qt::SolidPattern);
368 b.setStyle(Qt::SolidPattern);
369 b.setColor(color);
369 b.setColor(color);
370 m_chart->setBackgroundBrush(b);
370 m_chart->setBackgroundBrush(b);
371 emit backgroundColorChanged();
371 emit backgroundColorChanged();
372 }
372 }
373 }
373 }
374
374
375 QColor DeclarativeChart::backgroundColor()
375 QColor DeclarativeChart::backgroundColor()
376 {
376 {
377 return m_chart->backgroundBrush().color();
377 return m_chart->backgroundBrush().color();
378 }
378 }
379
379
380 int DeclarativeChart::count()
380 int DeclarativeChart::count()
381 {
381 {
382 return m_chart->series().count();
382 return m_chart->series().count();
383 }
383 }
384
384
385 void DeclarativeChart::setDropShadowEnabled(bool enabled)
385 void DeclarativeChart::setDropShadowEnabled(bool enabled)
386 {
386 {
387 if (enabled != m_chart->isDropShadowEnabled()) {
387 if (enabled != m_chart->isDropShadowEnabled()) {
388 m_chart->setDropShadowEnabled(enabled);
388 m_chart->setDropShadowEnabled(enabled);
389 dropShadowEnabledChanged(enabled);
389 dropShadowEnabledChanged(enabled);
390 }
390 }
391 }
391 }
392
392
393 bool DeclarativeChart::dropShadowEnabled()
393 bool DeclarativeChart::dropShadowEnabled()
394 {
394 {
395 return m_chart->isDropShadowEnabled();
395 return m_chart->isDropShadowEnabled();
396 }
396 }
397
397
398 qreal DeclarativeChart::topMargin()
398 qreal DeclarativeChart::topMargin()
399 {
399 {
400 return m_chart->margins().top();
400 return m_chart->margins().top();
401 }
401 }
402
402
403 qreal DeclarativeChart::bottomMargin()
403 qreal DeclarativeChart::bottomMargin()
404 {
404 {
405 return m_chart->margins().bottom();
405 return m_chart->margins().bottom();
406 }
406 }
407
407
408 qreal DeclarativeChart::leftMargin()
408 qreal DeclarativeChart::leftMargin()
409 {
409 {
410 return m_chart->margins().left();
410 return m_chart->margins().left();
411 }
411 }
412
412
413 qreal DeclarativeChart::rightMargin()
413 qreal DeclarativeChart::rightMargin()
414 {
414 {
415 return m_chart->margins().right();
415 return m_chart->margins().right();
416 }
416 }
417
417
418 void DeclarativeChart::zoom(qreal factor)
418 void DeclarativeChart::zoom(qreal factor)
419 {
419 {
420 m_chart->zoom(factor);
420 m_chart->zoom(factor);
421 }
421 }
422
422
423 void DeclarativeChart::scrollLeft(qreal pixels)
423 void DeclarativeChart::scrollLeft(qreal pixels)
424 {
424 {
425 m_chart->scroll(pixels, 0);
425 m_chart->scroll(pixels, 0);
426 }
426 }
427
427
428 void DeclarativeChart::scrollRight(qreal pixels)
428 void DeclarativeChart::scrollRight(qreal pixels)
429 {
429 {
430 m_chart->scroll(-pixels, 0);
430 m_chart->scroll(-pixels, 0);
431 }
431 }
432
432
433 void DeclarativeChart::scrollUp(qreal pixels)
433 void DeclarativeChart::scrollUp(qreal pixels)
434 {
434 {
435 m_chart->scroll(0, pixels);
435 m_chart->scroll(0, pixels);
436 }
436 }
437
437
438 void DeclarativeChart::scrollDown(qreal pixels)
438 void DeclarativeChart::scrollDown(qreal pixels)
439 {
439 {
440 m_chart->scroll(0, -pixels);
440 m_chart->scroll(0, -pixels);
441 }
441 }
442
442
443 QAbstractSeries *DeclarativeChart::series(int index)
443 QAbstractSeries *DeclarativeChart::series(int index)
444 {
444 {
445 if (index < m_chart->series().count()) {
445 if (index < m_chart->series().count()) {
446 return m_chart->series().at(index);
446 return m_chart->series().at(index);
447 }
447 }
448 return 0;
448 return 0;
449 }
449 }
450
450
451 QAbstractSeries *DeclarativeChart::series(QString seriesName)
451 QAbstractSeries *DeclarativeChart::series(QString seriesName)
452 {
452 {
453 foreach(QAbstractSeries *series, m_chart->series()) {
453 foreach(QAbstractSeries *series, m_chart->series()) {
454 if (series->name() == seriesName)
454 if (series->name() == seriesName)
455 return series;
455 return series;
456 }
456 }
457 return 0;
457 return 0;
458 }
458 }
459
459
460 QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name)
460 QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name)
461 {
461 {
462 QAbstractSeries *series = 0;
462 QAbstractSeries *series = 0;
463 switch (type) {
463 switch (type) {
464 case DeclarativeChart::SeriesTypeLine:
464 case DeclarativeChart::SeriesTypeLine:
465 series = new DeclarativeLineSeries();
465 series = new DeclarativeLineSeries();
466 break;
466 break;
467 case DeclarativeChart::SeriesTypeArea:
467 case DeclarativeChart::SeriesTypeArea:
468 series = new DeclarativeAreaSeries();
468 series = new DeclarativeAreaSeries();
469 break;
469 break;
470 case DeclarativeChart::SeriesTypeBar:
471 series = new DeclarativeBarSeries();
472 break;
473 case DeclarativeChart::SeriesTypeStackedBar:
470 case DeclarativeChart::SeriesTypeStackedBar:
474 // TODO
471 // TODO
475 break;
472 break;
476 case DeclarativeChart::SeriesTypePercentBar:
473 case DeclarativeChart::SeriesTypePercentBar:
477 // TODO
474 // TODO
478 break;
475 break;
479 case DeclarativeChart::SeriesTypeGroupedBar:
476 case DeclarativeChart::SeriesTypeGroupedBar:
480 series = new DeclarativeGroupedBarSeries();
477 series = new DeclarativeGroupedBarSeries();
481 break;
478 break;
482 case DeclarativeChart::SeriesTypePie:
479 case DeclarativeChart::SeriesTypePie:
483 series = new DeclarativePieSeries();
480 series = new DeclarativePieSeries();
484 break;
481 break;
485 case DeclarativeChart::SeriesTypeScatter:
482 case DeclarativeChart::SeriesTypeScatter:
486 series = new DeclarativeScatterSeries();
483 series = new DeclarativeScatterSeries();
487 break;
484 break;
488 case DeclarativeChart::SeriesTypeSpline:
485 case DeclarativeChart::SeriesTypeSpline:
489 series = new DeclarativeSplineSeries();
486 series = new DeclarativeSplineSeries();
490 break;
487 break;
491 default:
488 default:
492 qWarning() << "Illegal series type";
489 qWarning() << "Illegal series type";
493 }
490 }
494 series->setName(name);
491 series->setName(name);
495 m_chart->addSeries(series);
492 m_chart->addSeries(series);
496 return series;
493 return series;
497 }
494 }
498
495
499 #include "moc_declarativechart.cpp"
496 #include "moc_declarativechart.cpp"
500
497
501 QTCOMMERCIALCHART_END_NAMESPACE
498 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,109 +1,108
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include <QtDeclarative/qdeclarativeextensionplugin.h>
21 #include <QtDeclarative/qdeclarativeextensionplugin.h>
22 #include <QtDeclarative/qdeclarative.h>
22 #include <QtDeclarative/qdeclarative.h>
23 #include "qchart.h"
23 #include "qchart.h"
24 #include "qabstractaxis.h"
24 #include "qabstractaxis.h"
25 #include "qvaluesaxis.h"
25 #include "qvaluesaxis.h"
26 #include "qcategoriesaxis.h"
26 #include "qcategoriesaxis.h"
27 #include "declarativechart.h"
27 #include "declarativechart.h"
28 #include "declarativexypoint.h"
28 #include "declarativexypoint.h"
29 #include "declarativelineseries.h"
29 #include "declarativelineseries.h"
30 #include "declarativesplineseries.h"
30 #include "declarativesplineseries.h"
31 #include "declarativeareaseries.h"
31 #include "declarativeareaseries.h"
32 #include "declarativescatterseries.h"
32 #include "declarativescatterseries.h"
33 #include "declarativebarseries.h"
33 #include "declarativebarseries.h"
34 #include "declarativepieseries.h"
34 #include "declarativepieseries.h"
35 #include <QVXYModelMapper>
35 #include <QVXYModelMapper>
36 #include <QHXYModelMapper>
36 #include <QHXYModelMapper>
37 #include <QHPieModelMapper>
37 #include <QHPieModelMapper>
38 #include <QVPieModelMapper>
38 #include <QVPieModelMapper>
39 #include <QHBarModelMapper>
39 #include <QHBarModelMapper>
40 #include <QVBarModelMapper>
40 #include <QVBarModelMapper>
41
41
42 QTCOMMERCIALCHART_BEGIN_NAMESPACE
42 QTCOMMERCIALCHART_BEGIN_NAMESPACE
43
43
44 class ChartQmlPlugin : public QDeclarativeExtensionPlugin
44 class ChartQmlPlugin : public QDeclarativeExtensionPlugin
45 {
45 {
46 Q_OBJECT
46 Q_OBJECT
47 public:
47 public:
48 virtual void registerTypes(const char *uri)
48 virtual void registerTypes(const char *uri)
49 {
49 {
50 Q_ASSERT(QLatin1String(uri) == QLatin1String("QtCommercial.Chart"));
50 Q_ASSERT(QLatin1String(uri) == QLatin1String("QtCommercial.Chart"));
51
51
52 qmlRegisterType<DeclarativeChart>(uri, 1, 0, "ChartView");
52 qmlRegisterType<DeclarativeChart>(uri, 1, 0, "ChartView");
53 qmlRegisterType<DeclarativeXYPoint>(uri, 1, 0, "XYPoint");
53 qmlRegisterType<DeclarativeXYPoint>(uri, 1, 0, "XYPoint");
54 qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries");
54 qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries");
55 qmlRegisterType<DeclarativeLineSeries>(uri, 1, 0, "LineSeries");
55 qmlRegisterType<DeclarativeLineSeries>(uri, 1, 0, "LineSeries");
56 qmlRegisterType<DeclarativeSplineSeries>(uri, 1, 0, "SplineSeries");
56 qmlRegisterType<DeclarativeSplineSeries>(uri, 1, 0, "SplineSeries");
57 qmlRegisterType<DeclarativeAreaSeries>(uri, 1, 0, "AreaSeries");
57 qmlRegisterType<DeclarativeAreaSeries>(uri, 1, 0, "AreaSeries");
58 qmlRegisterType<DeclarativeBarSeries>(uri, 1, 0, "BarSeries");
59 qmlRegisterType<DeclarativeGroupedBarSeries>(uri, 1, 0, "GroupedBarSeries");
58 qmlRegisterType<DeclarativeGroupedBarSeries>(uri, 1, 0, "GroupedBarSeries");
60 qmlRegisterType<DeclarativeStackedBarSeries>(uri, 1, 0, "StackedBarSeries");
59 qmlRegisterType<DeclarativeStackedBarSeries>(uri, 1, 0, "StackedBarSeries");
61 qmlRegisterType<DeclarativePercentBarSeries>(uri, 1, 0, "PercentBarSeries");
60 qmlRegisterType<DeclarativePercentBarSeries>(uri, 1, 0, "PercentBarSeries");
62 qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries");
61 qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries");
63 qmlRegisterType<QPieSlice>(uri, 1, 0, "PieSlice");
62 qmlRegisterType<QPieSlice>(uri, 1, 0, "PieSlice");
64 qmlRegisterType<DeclarativeBarSet>(uri, 1, 0, "BarSet");
63 qmlRegisterType<DeclarativeBarSet>(uri, 1, 0, "BarSet");
65 qmlRegisterType<QHXYModelMapper>(uri, 1, 0, "HXYModelMapper");
64 qmlRegisterType<QHXYModelMapper>(uri, 1, 0, "HXYModelMapper");
66 qmlRegisterType<QVXYModelMapper>(uri, 1, 0, "VXYModelMapper");
65 qmlRegisterType<QVXYModelMapper>(uri, 1, 0, "VXYModelMapper");
67 qmlRegisterType<QHPieModelMapper>(uri, 1, 0, "HPieModelMapper");
66 qmlRegisterType<QHPieModelMapper>(uri, 1, 0, "HPieModelMapper");
68 qmlRegisterType<QVPieModelMapper>(uri, 1, 0, "VPieModelMapper");
67 qmlRegisterType<QVPieModelMapper>(uri, 1, 0, "VPieModelMapper");
69 qmlRegisterType<QHBarModelMapper>(uri, 1, 0, "HBarModelMapper");
68 qmlRegisterType<QHBarModelMapper>(uri, 1, 0, "HBarModelMapper");
70 qmlRegisterType<QVBarModelMapper>(uri, 1, 0, "VBarModelMapper");
69 qmlRegisterType<QVBarModelMapper>(uri, 1, 0, "VBarModelMapper");
71 qmlRegisterType<QValuesAxis>(uri, 1, 0, "ValuesAxis");
70 qmlRegisterType<QValuesAxis>(uri, 1, 0, "ValuesAxis");
72 qmlRegisterType<QCategoriesAxis>(uri, 1, 0, "CategoriesAxis");
71 qmlRegisterType<QCategoriesAxis>(uri, 1, 0, "CategoriesAxis");
73
72
74 qmlRegisterUncreatableType<QLegend>(uri, 1, 0, "Legend",
73 qmlRegisterUncreatableType<QLegend>(uri, 1, 0, "Legend",
75 QLatin1String("Trying to create uncreatable: Legend."));
74 QLatin1String("Trying to create uncreatable: Legend."));
76 qmlRegisterUncreatableType<QXYSeries>(uri, 1, 0, "XYSeries",
75 qmlRegisterUncreatableType<QXYSeries>(uri, 1, 0, "XYSeries",
77 QLatin1String("Trying to create uncreatable: XYSeries."));
76 QLatin1String("Trying to create uncreatable: XYSeries."));
78 qmlRegisterUncreatableType<QScatterSeries>(uri, 1, 0, "QScatterSeries",
77 qmlRegisterUncreatableType<QScatterSeries>(uri, 1, 0, "QScatterSeries",
79 QLatin1String("Trying to create uncreatable: QScatterSeries."));
78 QLatin1String("Trying to create uncreatable: QScatterSeries."));
80 qmlRegisterUncreatableType<QPieSeries>(uri, 1, 0, "QPieSeries",
79 qmlRegisterUncreatableType<QPieSeries>(uri, 1, 0, "QPieSeries",
81 QLatin1String("Trying to create uncreatable: QPieSeries."));
80 QLatin1String("Trying to create uncreatable: QPieSeries."));
82 qmlRegisterUncreatableType<QBarSet>(uri, 1, 0, "QBarSet",
81 qmlRegisterUncreatableType<QBarSet>(uri, 1, 0, "QBarSet",
83 QLatin1String("Trying to create uncreatable: QBarSet."));
82 QLatin1String("Trying to create uncreatable: QBarSet."));
84 qmlRegisterUncreatableType<QAbstractItemModel>(uri, 1, 0, "AbstractItemModel",
83 qmlRegisterUncreatableType<QAbstractItemModel>(uri, 1, 0, "AbstractItemModel",
85 QLatin1String("Trying to create uncreatable: AbstractItemModel."));
84 QLatin1String("Trying to create uncreatable: AbstractItemModel."));
86 qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper",
85 qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper",
87 QLatin1String("Trying to create uncreatable: XYModelMapper."));
86 QLatin1String("Trying to create uncreatable: XYModelMapper."));
88 qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper",
87 qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper",
89 QLatin1String("Trying to create uncreatable: PieModelMapper."));
88 QLatin1String("Trying to create uncreatable: PieModelMapper."));
90 qmlRegisterUncreatableType<QBarModelMapper>(uri, 1, 0, "BarModelMapper",
89 qmlRegisterUncreatableType<QBarModelMapper>(uri, 1, 0, "BarModelMapper",
91 QLatin1String("Trying to create uncreatable: BarModelMapper."));
90 QLatin1String("Trying to create uncreatable: BarModelMapper."));
92 qmlRegisterUncreatableType<QAbstractSeries>(uri, 1, 0, "AbstractSeries",
91 qmlRegisterUncreatableType<QAbstractSeries>(uri, 1, 0, "AbstractSeries",
93 QLatin1String("Trying to create uncreatable: AbstractSeries."));
92 QLatin1String("Trying to create uncreatable: AbstractSeries."));
94 qmlRegisterUncreatableType<QAbstractAxis>(uri, 1, 0, "AbstractAxis",
93 qmlRegisterUncreatableType<QAbstractAxis>(uri, 1, 0, "AbstractAxis",
95 QLatin1String("Trying to create uncreatable: AbstractAxis."));
94 QLatin1String("Trying to create uncreatable: AbstractAxis."));
96 qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper",
95 qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper",
97 QLatin1String("Trying to create uncreatable: PieModelMapper."));
96 QLatin1String("Trying to create uncreatable: PieModelMapper."));
98 qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper",
97 qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper",
99 QLatin1String("Trying to create uncreatable: XYModelMapper."));
98 QLatin1String("Trying to create uncreatable: XYModelMapper."));
100 }
99 }
101 };
100 };
102
101
103 #include "plugin.moc"
102 #include "plugin.moc"
104
103
105 QTCOMMERCIALCHART_END_NAMESPACE
104 QTCOMMERCIALCHART_END_NAMESPACE
106
105
107 QTCOMMERCIALCHART_USE_NAMESPACE
106 QTCOMMERCIALCHART_USE_NAMESPACE
108
107
109 Q_EXPORT_PLUGIN2(qtcommercialchartqml, QT_PREPEND_NAMESPACE(ChartQmlPlugin))
108 Q_EXPORT_PLUGIN2(qtcommercialchartqml, QT_PREPEND_NAMESPACE(ChartQmlPlugin))
@@ -1,732 +1,724
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "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 "domain_p.h"
25 #include "domain_p.h"
26 #include "legendmarker_p.h"
26 #include "legendmarker_p.h"
27 #include "chartdataset_p.h"
27 #include "chartdataset_p.h"
28 #include "charttheme_p.h"
28 #include "charttheme_p.h"
29 #include "chartanimator_p.h"
29 #include "chartanimator_p.h"
30 #include "qvaluesaxis.h"
30 #include "qvaluesaxis.h"
31 #include "qcategoriesaxis.h"
31 #include "qcategoriesaxis.h"
32
32
33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
34
34
35 /*!
35 /*!
36 \class QAbstractBarSeries
36 \class QAbstractBarSeries
37 \brief Series for creating a bar chart
37 \brief Series for creating a bar chart
38 \mainclass
38 \mainclass
39
39
40 QAbstractBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to
40 QAbstractBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to
41 the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar
41 the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar
42 and y-value is the height of the bar. The category names are ignored with this series and x-axis
42 and y-value is the height of the bar. The category names are ignored with this series and x-axis
43 shows the x-values.
43 shows the x-values.
44
44
45 See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart.
45 See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart.
46 \image examples_barchart.png
46 \image examples_barchart.png
47
47
48 \sa QBarSet, QStackedBarSeries, QPercentBarSeries
48 \sa QBarSet, QStackedBarSeries, QPercentBarSeries
49 */
49 */
50 /*!
50 /*!
51 \qmlclass BarSeries QAbstractBarSeries
51 \qmlclass BarSeries QAbstractBarSeries
52 \inherits AbstractSeries
52 \inherits AbstractSeries
53
53
54 The following QML shows how to create a simple bar chart:
54 The following QML shows how to create a simple bar chart:
55 \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1
55 \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1
56
56
57 \beginfloatleft
57 \beginfloatleft
58 \image demos_qmlchart6.png
58 \image demos_qmlchart6.png
59 \endfloat
59 \endfloat
60 \clearfloat
60 \clearfloat
61 */
61 */
62
62
63 /*!
63 /*!
64 \property QAbstractBarSeries::barWidth
64 \property QAbstractBarSeries::barWidth
65 The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars
65 The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars
66 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
66 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
67 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
67 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
68 Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar.
68 Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar.
69 \sa QGroupedBarSeries
69 \sa QGroupedBarSeries
70 */
70 */
71 /*!
71 /*!
72 \qmlproperty real BarSeries::barWidth
72 \qmlproperty real BarSeries::barWidth
73 The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars
73 The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars
74 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
74 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
75 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
75 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
76 Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar.
76 Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar.
77 */
77 */
78
78
79 /*!
79 /*!
80 \property QAbstractBarSeries::count
80 \property QAbstractBarSeries::count
81 Holds the number of sets in series.
81 Holds the number of sets in series.
82 */
82 */
83 /*!
83 /*!
84 \qmlproperty int BarSeries::count
84 \qmlproperty int BarSeries::count
85 Holds the number of sets in series.
85 Holds the number of sets in series.
86 */
86 */
87
87
88 /*!
88 /*!
89 \property QAbstractBarSeries::labelsVisible
89 \property QAbstractBarSeries::labelsVisible
90 Defines the visibility of the labels in series
90 Defines the visibility of the labels in series
91 */
91 */
92 /*!
92 /*!
93 \qmlproperty bool BarSeries::labelsVisible
93 \qmlproperty bool BarSeries::labelsVisible
94 Defines the visibility of the labels in series
94 Defines the visibility of the labels in series
95 */
95 */
96
96
97 /*!
97 /*!
98 \fn void QAbstractBarSeries::clicked(int index, QBarSet *barset)
98 \fn void QAbstractBarSeries::clicked(int index, QBarSet *barset)
99 The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset.
99 The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset.
100 Clicked bar inside set is indexed by \a index
100 Clicked bar inside set is indexed by \a index
101 */
101 */
102 /*!
102 /*!
103 \qmlsignal BarSeries::onClicked(int index, BarSet barset)
103 \qmlsignal BarSeries::onClicked(int index, BarSet barset)
104 The signal is emitted if the user clicks with a mouse on top of BarSet.
104 The signal is emitted if the user clicks with a mouse on top of BarSet.
105 Clicked bar inside set is indexed by \a index
105 Clicked bar inside set is indexed by \a index
106 */
106 */
107
107
108 /*!
108 /*!
109 \fn void QAbstractBarSeries::hovered(bool status, QBarSet* barset)
109 \fn void QAbstractBarSeries::hovered(bool status, QBarSet* barset)
110
110
111 The signal is emitted if mouse is hovered on top of series.
111 The signal is emitted if mouse is hovered on top of series.
112 Parameter \a barset is the pointer of barset, where hover happened.
112 Parameter \a barset is the pointer of barset, where hover happened.
113 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
113 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
114 */
114 */
115 /*!
115 /*!
116 \qmlsignal BarSeries::onHovered(bool status, BarSet barset)
116 \qmlsignal BarSeries::onHovered(bool status, BarSet barset)
117
117
118 The signal is emitted if mouse is hovered on top of series.
118 The signal is emitted if mouse is hovered on top of series.
119 Parameter \a barset is the pointer of barset, where hover happened.
119 Parameter \a barset is the pointer of barset, where hover happened.
120 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
120 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
121 */
121 */
122
122
123 /*!
123 /*!
124 \fn void QAbstractBarSeries::countChanged()
124 \fn void QAbstractBarSeries::countChanged()
125 This signal is emitted when barset count has been changed, for example by append or remove.
125 This signal is emitted when barset count has been changed, for example by append or remove.
126 */
126 */
127 /*!
127 /*!
128 \qmlsignal BarSeries::onCountChanged()
128 \qmlsignal BarSeries::onCountChanged()
129 This signal is emitted when barset count has been changed, for example by append or remove.
129 This signal is emitted when barset count has been changed, for example by append or remove.
130 */
130 */
131
131
132 /*!
132 /*!
133 \fn void QAbstractBarSeries::labelsVisibleChanged()
133 \fn void QAbstractBarSeries::labelsVisibleChanged()
134 This signal is emitted when labels visibility have changed.
134 This signal is emitted when labels visibility have changed.
135 \sa isLabelsVisible(), setLabelsVisible()
135 \sa isLabelsVisible(), setLabelsVisible()
136 */
136 */
137
137
138 /*!
138 /*!
139 \fn void QAbstractBarSeries::barsetsAdded(QList<QBarSet*> sets)
139 \fn void QAbstractBarSeries::barsetsAdded(QList<QBarSet*> sets)
140 This signal is emitted when \a sets have been added to the series.
140 This signal is emitted when \a sets have been added to the series.
141 \sa append(), insert()
141 \sa append(), insert()
142 */
142 */
143 /*!
143 /*!
144 \qmlsignal BarSeries::onAdded(BarSet barset)
144 \qmlsignal BarSeries::onAdded(BarSet barset)
145 Emitted when \a barset has been added to the series.
145 Emitted when \a barset has been added to the series.
146 */
146 */
147
147
148 /*!
148 /*!
149 \fn void QAbstractBarSeries::barsetsRemoved(QList<QBarSet*> sets)
149 \fn void QAbstractBarSeries::barsetsRemoved(QList<QBarSet*> sets)
150 This signal is emitted when \a sets have been removed from the series.
150 This signal is emitted when \a sets have been removed from the series.
151 \sa remove()
151 \sa remove()
152 */
152 */
153 /*!
153 /*!
154 \qmlsignal BarSeries::onRemoved(BarSet barset)
154 \qmlsignal BarSeries::onRemoved(BarSet barset)
155 Emitted when \a barset has been removed from the series.
155 Emitted when \a barset has been removed from the series.
156 */
156 */
157
157
158 /*!
158 /*!
159 \qmlmethod BarSet BarSeries::at(int index)
159 \qmlmethod BarSet BarSeries::at(int index)
160 Returns bar set at \a index. Returns null if the index is not valid.
160 Returns bar set at \a index. Returns null if the index is not valid.
161 */
161 */
162
162
163 /*!
163 /*!
164 \qmlmethod BarSet BarSeries::append(string label, VariantList values)
164 \qmlmethod BarSet BarSeries::append(string label, VariantList values)
165 Adds a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints.
165 Adds a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints.
166 For example:
166 For example:
167 \code
167 \code
168 myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]);
168 myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]);
169 myBarSeries.append("set 2", [Qt.point(0, 1), Qt.point(2, 2.5), Qt.point(3.5, 2.2)]);
169 myBarSeries.append("set 2", [Qt.point(0, 1), Qt.point(2, 2.5), Qt.point(3.5, 2.2)]);
170 \endcode
170 \endcode
171 */
171 */
172
172
173 /*!
173 /*!
174 \qmlmethod BarSet BarSeries::insert(int index, string label, VariantList values)
174 \qmlmethod BarSet BarSeries::insert(int index, string label, VariantList values)
175 Inserts a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints.
175 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.
176 If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is
176 If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is
177 appended.
177 appended.
178 \sa BarSeries::append()
178 \sa BarSeries::append()
179 */
179 */
180
180
181 /*!
181 /*!
182 \qmlmethod bool BarSeries::remove(BarSet barset)
182 \qmlmethod bool BarSeries::remove(BarSet barset)
183 Removes the barset from the series. Returns true if successfull, false otherwise.
183 Removes the barset from the series. Returns true if successfull, false otherwise.
184 */
184 */
185
185
186 /*!
186 /*!
187 \qmlmethod BarSeries::clear()
187 \qmlmethod BarSeries::clear()
188 Removes all barsets from the series.
188 Removes all barsets from the series.
189 */
189 */
190
190
191 /*!
191 /*!
192 Constructs empty QAbstractBarSeries.
192 Constructs empty QAbstractBarSeries.
193 QAbstractBarSeries is QObject which is a child of a \a parent.
193 QAbstractBarSeries is QObject which is a child of a \a parent.
194 */
194 */
195 QAbstractBarSeries::QAbstractBarSeries(QObject *parent) :
195 QAbstractBarSeries::QAbstractBarSeries(QObject *parent) :
196 QAbstractSeries(*new QAbstractBarSeriesPrivate(this),parent)
196 QAbstractSeries(*new QAbstractBarSeriesPrivate(this),parent)
197 {
197 {
198 }
198 }
199
199
200 /*!
200 /*!
201 Destructs barseries and owned barsets.
201 Destructs barseries and owned barsets.
202 */
202 */
203 QAbstractBarSeries::~QAbstractBarSeries()
203 QAbstractBarSeries::~QAbstractBarSeries()
204 {
204 {
205 Q_D(QAbstractBarSeries);
205 Q_D(QAbstractBarSeries);
206 if(d->m_dataset){
206 if(d->m_dataset){
207 d->m_dataset->removeSeries(this);
207 d->m_dataset->removeSeries(this);
208 }
208 }
209 }
209 }
210
210
211 /*!
211 /*!
212 \internal
212 \internal
213 */
213 */
214 QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &d, QObject *parent) :
214 QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &d, QObject *parent) :
215 QAbstractSeries(d,parent)
215 QAbstractSeries(d,parent)
216 {
216 {
217 }
217 }
218
218
219 /*!
219 /*!
220 Returns the type of series. Derived classes override this.
221 */
222 QAbstractSeries::SeriesType QAbstractBarSeries::type() const
223 {
224 return QAbstractSeries::SeriesTypeBar;
225 }
226
227 /*!
228 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
220 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
229 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
221 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
230 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
222 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
231 Note that with \link QGroupedBarSeries \endlink this value means the width of one group of bars instead of just one bar.
223 Note that with \link QGroupedBarSeries \endlink this value means the width of one group of bars instead of just one bar.
232 */
224 */
233 void QAbstractBarSeries::setBarWidth(qreal width)
225 void QAbstractBarSeries::setBarWidth(qreal width)
234 {
226 {
235 Q_D(QAbstractBarSeries);
227 Q_D(QAbstractBarSeries);
236 d->setBarWidth(width);
228 d->setBarWidth(width);
237 }
229 }
238
230
239 /*!
231 /*!
240 Returns the width of the bars of the series.
232 Returns the width of the bars of the series.
241 \sa setBarWidth()
233 \sa setBarWidth()
242 */
234 */
243 qreal QAbstractBarSeries::barWidth() const
235 qreal QAbstractBarSeries::barWidth() const
244 {
236 {
245 Q_D(const QAbstractBarSeries);
237 Q_D(const QAbstractBarSeries);
246 return d->barWidth();
238 return d->barWidth();
247 }
239 }
248
240
249 /*!
241 /*!
250 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.
242 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.
251 Returns true, if appending succeeded.
243 Returns true, if appending succeeded.
252 */
244 */
253 bool QAbstractBarSeries::append(QBarSet *set)
245 bool QAbstractBarSeries::append(QBarSet *set)
254 {
246 {
255 Q_D(QAbstractBarSeries);
247 Q_D(QAbstractBarSeries);
256 bool success = d->append(set);
248 bool success = d->append(set);
257 if (success) {
249 if (success) {
258 QList<QBarSet*> sets;
250 QList<QBarSet*> sets;
259 sets.append(set);
251 sets.append(set);
260 emit barsetsAdded(sets);
252 emit barsetsAdded(sets);
261 emit countChanged();
253 emit countChanged();
262 }
254 }
263 return success;
255 return success;
264 }
256 }
265
257
266 /*!
258 /*!
267 Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set.
259 Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set.
268 Returns true, if set was removed.
260 Returns true, if set was removed.
269 */
261 */
270 bool QAbstractBarSeries::remove(QBarSet *set)
262 bool QAbstractBarSeries::remove(QBarSet *set)
271 {
263 {
272 Q_D(QAbstractBarSeries);
264 Q_D(QAbstractBarSeries);
273 bool success = d->remove(set);
265 bool success = d->remove(set);
274 if (success) {
266 if (success) {
275 QList<QBarSet*> sets;
267 QList<QBarSet*> sets;
276 sets.append(set);
268 sets.append(set);
277 emit barsetsRemoved(sets);
269 emit barsetsRemoved(sets);
278 emit countChanged();
270 emit countChanged();
279 }
271 }
280 return success;
272 return success;
281 }
273 }
282
274
283 /*!
275 /*!
284 Adds a list of barsets to series. Takes ownership of \a sets.
276 Adds a list of barsets to series. Takes ownership of \a sets.
285 Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series,
277 Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series,
286 nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended
278 nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended
287 and function returns false.
279 and function returns false.
288 */
280 */
289 bool QAbstractBarSeries::append(QList<QBarSet* > sets)
281 bool QAbstractBarSeries::append(QList<QBarSet* > sets)
290 {
282 {
291 Q_D(QAbstractBarSeries);
283 Q_D(QAbstractBarSeries);
292 bool success = d->append(sets);
284 bool success = d->append(sets);
293 if (success) {
285 if (success) {
294 emit barsetsAdded(sets);
286 emit barsetsAdded(sets);
295 emit countChanged();
287 emit countChanged();
296 }
288 }
297 return success;
289 return success;
298 }
290 }
299
291
300 /*!
292 /*!
301 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.
293 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.
302 Returns true, if inserting succeeded.
294 Returns true, if inserting succeeded.
303
295
304 */
296 */
305 bool QAbstractBarSeries::insert(int index, QBarSet *set)
297 bool QAbstractBarSeries::insert(int index, QBarSet *set)
306 {
298 {
307 Q_D(QAbstractBarSeries);
299 Q_D(QAbstractBarSeries);
308 bool success = d->insert(index, set);
300 bool success = d->insert(index, set);
309 if (success) {
301 if (success) {
310 QList<QBarSet*> sets;
302 QList<QBarSet*> sets;
311 sets.append(set);
303 sets.append(set);
312 emit barsetsAdded(sets);
304 emit barsetsAdded(sets);
313 emit countChanged();
305 emit countChanged();
314 }
306 }
315 return success;
307 return success;
316 }
308 }
317
309
318 /*!
310 /*!
319 Removes all of the bar sets from the series
311 Removes all of the bar sets from the series
320 */
312 */
321 void QAbstractBarSeries::clear()
313 void QAbstractBarSeries::clear()
322 {
314 {
323 Q_D(QAbstractBarSeries);
315 Q_D(QAbstractBarSeries);
324 QList<QBarSet *> sets = barSets();
316 QList<QBarSet *> sets = barSets();
325 bool success = d->remove(sets);
317 bool success = d->remove(sets);
326 if (success) {
318 if (success) {
327 emit barsetsRemoved(sets);
319 emit barsetsRemoved(sets);
328 emit countChanged();
320 emit countChanged();
329 }
321 }
330 }
322 }
331
323
332 /*!
324 /*!
333 Returns number of sets in series.
325 Returns number of sets in series.
334 */
326 */
335 int QAbstractBarSeries::count() const
327 int QAbstractBarSeries::count() const
336 {
328 {
337 Q_D(const QAbstractBarSeries);
329 Q_D(const QAbstractBarSeries);
338 return d->m_barSets.count();
330 return d->m_barSets.count();
339 }
331 }
340
332
341 /*!
333 /*!
342 Returns a list of sets in series. Keeps ownership of sets.
334 Returns a list of sets in series. Keeps ownership of sets.
343 */
335 */
344 QList<QBarSet*> QAbstractBarSeries::barSets() const
336 QList<QBarSet*> QAbstractBarSeries::barSets() const
345 {
337 {
346 Q_D(const QAbstractBarSeries);
338 Q_D(const QAbstractBarSeries);
347 return d->m_barSets;
339 return d->m_barSets;
348 }
340 }
349
341
350 /*!
342 /*!
351 Sets the visibility of labels in series to \a visible
343 Sets the visibility of labels in series to \a visible
352 */
344 */
353 void QAbstractBarSeries::setLabelsVisible(bool visible)
345 void QAbstractBarSeries::setLabelsVisible(bool visible)
354 {
346 {
355 Q_D(QAbstractBarSeries);
347 Q_D(QAbstractBarSeries);
356 if (d->m_labelsVisible != visible) {
348 if (d->m_labelsVisible != visible) {
357 d->setLabelsVisible(visible);
349 d->setLabelsVisible(visible);
358 emit labelsVisibleChanged();
350 emit labelsVisibleChanged();
359 }
351 }
360 }
352 }
361
353
362 /*!
354 /*!
363 Returns the visibility of labels
355 Returns the visibility of labels
364 */
356 */
365 bool QAbstractBarSeries::isLabelsVisible() const
357 bool QAbstractBarSeries::isLabelsVisible() const
366 {
358 {
367 Q_D(const QAbstractBarSeries);
359 Q_D(const QAbstractBarSeries);
368 return d->m_labelsVisible;
360 return d->m_labelsVisible;
369 }
361 }
370
362
371 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
363 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
372
364
373 QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) :
365 QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) :
374 QAbstractSeriesPrivate(q),
366 QAbstractSeriesPrivate(q),
375 m_barWidth(0.5), // Default value is 50% of category width
367 m_barWidth(0.5), // Default value is 50% of category width
376 m_labelsVisible(false),
368 m_labelsVisible(false),
377 m_visible(true)
369 m_visible(true)
378 {
370 {
379 }
371 }
380
372
381 int QAbstractBarSeriesPrivate::categoryCount() const
373 int QAbstractBarSeriesPrivate::categoryCount() const
382 {
374 {
383 // No categories defined. return count of longest set.
375 // No categories defined. return count of longest set.
384 int count = 0;
376 int count = 0;
385 for (int i=0; i<m_barSets.count(); i++) {
377 for (int i=0; i<m_barSets.count(); i++) {
386 if (m_barSets.at(i)->count() > count) {
378 if (m_barSets.at(i)->count() > count) {
387 count = m_barSets.at(i)->count();
379 count = m_barSets.at(i)->count();
388 }
380 }
389 }
381 }
390
382
391 return count;
383 return count;
392 }
384 }
393
385
394 void QAbstractBarSeriesPrivate::setBarWidth(qreal width)
386 void QAbstractBarSeriesPrivate::setBarWidth(qreal width)
395 {
387 {
396 if (width < 0.0) {
388 if (width < 0.0) {
397 width = 0.0;
389 width = 0.0;
398 }
390 }
399 m_barWidth = width;
391 m_barWidth = width;
400 emit updatedBars();
392 emit updatedBars();
401 }
393 }
402
394
403 qreal QAbstractBarSeriesPrivate::barWidth() const
395 qreal QAbstractBarSeriesPrivate::barWidth() const
404 {
396 {
405 return m_barWidth;
397 return m_barWidth;
406 }
398 }
407
399
408 QBarSet* QAbstractBarSeriesPrivate::barsetAt(int index)
400 QBarSet* QAbstractBarSeriesPrivate::barsetAt(int index)
409 {
401 {
410 return m_barSets.at(index);
402 return m_barSets.at(index);
411 }
403 }
412
404
413 void QAbstractBarSeriesPrivate::setVisible(bool visible)
405 void QAbstractBarSeriesPrivate::setVisible(bool visible)
414 {
406 {
415 m_visible = visible;
407 m_visible = visible;
416 emit updatedBars();
408 emit updatedBars();
417 }
409 }
418
410
419 void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible)
411 void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible)
420 {
412 {
421 m_labelsVisible = visible;
413 m_labelsVisible = visible;
422 emit labelsVisibleChanged(visible);
414 emit labelsVisibleChanged(visible);
423 }
415 }
424
416
425 qreal QAbstractBarSeriesPrivate::min()
417 qreal QAbstractBarSeriesPrivate::min()
426 {
418 {
427 if (m_barSets.count() <= 0) {
419 if (m_barSets.count() <= 0) {
428 return 0;
420 return 0;
429 }
421 }
430 qreal min = INT_MAX;
422 qreal min = INT_MAX;
431
423
432 for (int i = 0; i < m_barSets.count(); i++) {
424 for (int i = 0; i < m_barSets.count(); i++) {
433 int categoryCount = m_barSets.at(i)->count();
425 int categoryCount = m_barSets.at(i)->count();
434 for (int j = 0; j < categoryCount; j++) {
426 for (int j = 0; j < categoryCount; j++) {
435 qreal temp = m_barSets.at(i)->at(j);
427 qreal temp = m_barSets.at(i)->at(j);
436 if (temp < min)
428 if (temp < min)
437 min = temp;
429 min = temp;
438 }
430 }
439 }
431 }
440 return min;
432 return min;
441 }
433 }
442
434
443 qreal QAbstractBarSeriesPrivate::max()
435 qreal QAbstractBarSeriesPrivate::max()
444 {
436 {
445 if (m_barSets.count() <= 0) {
437 if (m_barSets.count() <= 0) {
446 return 0;
438 return 0;
447 }
439 }
448 qreal max = INT_MIN;
440 qreal max = INT_MIN;
449
441
450 for (int i = 0; i < m_barSets.count(); i++) {
442 for (int i = 0; i < m_barSets.count(); i++) {
451 int categoryCount = m_barSets.at(i)->count();
443 int categoryCount = m_barSets.at(i)->count();
452 for (int j = 0; j < categoryCount; j++) {
444 for (int j = 0; j < categoryCount; j++) {
453 qreal temp = m_barSets.at(i)->at(j);
445 qreal temp = m_barSets.at(i)->at(j);
454 if (temp > max)
446 if (temp > max)
455 max = temp;
447 max = temp;
456 }
448 }
457 }
449 }
458
450
459 return max;
451 return max;
460 }
452 }
461
453
462 qreal QAbstractBarSeriesPrivate::valueAt(int set, int category)
454 qreal QAbstractBarSeriesPrivate::valueAt(int set, int category)
463 {
455 {
464 if ((set < 0) || (set >= m_barSets.count())) {
456 if ((set < 0) || (set >= m_barSets.count())) {
465 // No set, no value.
457 // No set, no value.
466 return 0;
458 return 0;
467 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
459 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
468 // No category, no value.
460 // No category, no value.
469 return 0;
461 return 0;
470 }
462 }
471
463
472 return m_barSets.at(set)->at(category);
464 return m_barSets.at(set)->at(category);
473 }
465 }
474
466
475 qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category)
467 qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category)
476 {
468 {
477 if ((set < 0) || (set >= m_barSets.count())) {
469 if ((set < 0) || (set >= m_barSets.count())) {
478 // No set, no value.
470 // No set, no value.
479 return 0;
471 return 0;
480 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
472 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
481 // No category, no value.
473 // No category, no value.
482 return 0;
474 return 0;
483 }
475 }
484
476
485 qreal value = m_barSets.at(set)->at(category);
477 qreal value = m_barSets.at(set)->at(category);
486 qreal sum = categorySum(category);
478 qreal sum = categorySum(category);
487 if ( qFuzzyIsNull(sum) ) {
479 if ( qFuzzyIsNull(sum) ) {
488 return 0;
480 return 0;
489 }
481 }
490
482
491 return value / sum;
483 return value / sum;
492 }
484 }
493
485
494 qreal QAbstractBarSeriesPrivate::categorySum(int category)
486 qreal QAbstractBarSeriesPrivate::categorySum(int category)
495 {
487 {
496 qreal sum(0);
488 qreal sum(0);
497 int count = m_barSets.count(); // Count sets
489 int count = m_barSets.count(); // Count sets
498 for (int set = 0; set < count; set++) {
490 for (int set = 0; set < count; set++) {
499 if (category < m_barSets.at(set)->count())
491 if (category < m_barSets.at(set)->count())
500 sum += m_barSets.at(set)->at(category);
492 sum += m_barSets.at(set)->at(category);
501 }
493 }
502 return sum;
494 return sum;
503 }
495 }
504
496
505 qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category)
497 qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category)
506 {
498 {
507 qreal sum(0);
499 qreal sum(0);
508 int count = m_barSets.count(); // Count sets
500 int count = m_barSets.count(); // Count sets
509 for (int set = 0; set < count; set++) {
501 for (int set = 0; set < count; set++) {
510 if (category < m_barSets.at(set)->count())
502 if (category < m_barSets.at(set)->count())
511 sum += qAbs(m_barSets.at(set)->at(category));
503 sum += qAbs(m_barSets.at(set)->at(category));
512 }
504 }
513 return sum;
505 return sum;
514 }
506 }
515
507
516 qreal QAbstractBarSeriesPrivate::maxCategorySum()
508 qreal QAbstractBarSeriesPrivate::maxCategorySum()
517 {
509 {
518 qreal max = INT_MIN;
510 qreal max = INT_MIN;
519 int count = categoryCount();
511 int count = categoryCount();
520 for (int i = 0; i < count; i++) {
512 for (int i = 0; i < count; i++) {
521 qreal sum = categorySum(i);
513 qreal sum = categorySum(i);
522 if (sum > max)
514 if (sum > max)
523 max = sum;
515 max = sum;
524 }
516 }
525 return max;
517 return max;
526 }
518 }
527
519
528 qreal QAbstractBarSeriesPrivate::minX()
520 qreal QAbstractBarSeriesPrivate::minX()
529 {
521 {
530 if (m_barSets.count() <= 0) {
522 if (m_barSets.count() <= 0) {
531 return 0;
523 return 0;
532 }
524 }
533 qreal min = INT_MAX;
525 qreal min = INT_MAX;
534
526
535 for (int i = 0; i < m_barSets.count(); i++) {
527 for (int i = 0; i < m_barSets.count(); i++) {
536 int categoryCount = m_barSets.at(i)->count();
528 int categoryCount = m_barSets.at(i)->count();
537 for (int j = 0; j < categoryCount; j++) {
529 for (int j = 0; j < categoryCount; j++) {
538 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
530 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
539 if (temp < min)
531 if (temp < min)
540 min = temp;
532 min = temp;
541 }
533 }
542 }
534 }
543 return min;
535 return min;
544 }
536 }
545
537
546 qreal QAbstractBarSeriesPrivate::maxX()
538 qreal QAbstractBarSeriesPrivate::maxX()
547 {
539 {
548 if (m_barSets.count() <= 0) {
540 if (m_barSets.count() <= 0) {
549 return 0;
541 return 0;
550 }
542 }
551 qreal max = INT_MIN;
543 qreal max = INT_MIN;
552
544
553 for (int i = 0; i < m_barSets.count(); i++) {
545 for (int i = 0; i < m_barSets.count(); i++) {
554 int categoryCount = m_barSets.at(i)->count();
546 int categoryCount = m_barSets.at(i)->count();
555 for (int j = 0; j < categoryCount; j++) {
547 for (int j = 0; j < categoryCount; j++) {
556 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
548 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
557 if (temp > max)
549 if (temp > max)
558 max = temp;
550 max = temp;
559 }
551 }
560 }
552 }
561
553
562 return max;
554 return max;
563 }
555 }
564
556
565
557
566 void QAbstractBarSeriesPrivate::scaleDomain(Domain& domain)
558 void QAbstractBarSeriesPrivate::scaleDomain(Domain& domain)
567 {
559 {
568 qreal minX(domain.minX());
560 qreal minX(domain.minX());
569 qreal minY(domain.minY());
561 qreal minY(domain.minY());
570 qreal maxX(domain.maxX());
562 qreal maxX(domain.maxX());
571 qreal maxY(domain.maxY());
563 qreal maxY(domain.maxY());
572 int tickXCount(domain.tickXCount());
564 int tickXCount(domain.tickXCount());
573 int tickYCount(domain.tickYCount());
565 int tickYCount(domain.tickYCount());
574
566
575 qreal seriesMinX = this->minX();
567 qreal seriesMinX = this->minX();
576 qreal seriesMaxX = this->maxX();
568 qreal seriesMaxX = this->maxX();
577 qreal y = max();
569 qreal y = max();
578 minX = qMin(minX, seriesMinX - 0.5);
570 minX = qMin(minX, seriesMinX - 0.5);
579 minY = qMin(minY, y);
571 minY = qMin(minY, y);
580 maxX = qMax(maxX, seriesMaxX + 0.5);
572 maxX = qMax(maxX, seriesMaxX + 0.5);
581 maxY = qMax(maxY, y);
573 maxY = qMax(maxY, y);
582 tickXCount = categoryCount()+1;
574 tickXCount = categoryCount()+1;
583
575
584 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
576 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
585 }
577 }
586
578
587 Chart* QAbstractBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
579 Chart* QAbstractBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
588 {
580 {
589 Q_Q(QAbstractBarSeries);
581 Q_Q(QAbstractBarSeries);
590
582
591 BarChartItem* bar = new BarChartItem(q,presenter);
583 BarChartItem* bar = new BarChartItem(q,presenter);
592 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
584 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
593 presenter->animator()->addAnimation(bar);
585 presenter->animator()->addAnimation(bar);
594 }
586 }
595 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
587 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
596 return bar;
588 return bar;
597
589
598 }
590 }
599
591
600 QList<LegendMarker*> QAbstractBarSeriesPrivate::createLegendMarker(QLegend* legend)
592 QList<LegendMarker*> QAbstractBarSeriesPrivate::createLegendMarker(QLegend* legend)
601 {
593 {
602 Q_Q(QAbstractBarSeries);
594 Q_Q(QAbstractBarSeries);
603 QList<LegendMarker*> markers;
595 QList<LegendMarker*> markers;
604 foreach(QBarSet* set, q->barSets()) {
596 foreach(QBarSet* set, q->barSets()) {
605 BarLegendMarker* marker = new BarLegendMarker(q,set,legend);
597 BarLegendMarker* marker = new BarLegendMarker(q,set,legend);
606 markers << marker;
598 markers << marker;
607 }
599 }
608
600
609 return markers;
601 return markers;
610 }
602 }
611
603
612 QAbstractAxis* QAbstractBarSeriesPrivate::createAxisX(QObject* parent)
604 QAbstractAxis* QAbstractBarSeriesPrivate::createAxisX(QObject* parent)
613 {
605 {
614 return new QCategoriesAxis(parent);
606 return new QCategoriesAxis(parent);
615 }
607 }
616
608
617 QAbstractAxis* QAbstractBarSeriesPrivate::createAxisY(QObject* parent)
609 QAbstractAxis* QAbstractBarSeriesPrivate::createAxisY(QObject* parent)
618 {
610 {
619 return new QValuesAxis(parent);
611 return new QValuesAxis(parent);
620 }
612 }
621
613
622 bool QAbstractBarSeriesPrivate::append(QBarSet *set)
614 bool QAbstractBarSeriesPrivate::append(QBarSet *set)
623 {
615 {
624 Q_Q(QAbstractBarSeries);
616 Q_Q(QAbstractBarSeries);
625 if ((m_barSets.contains(set)) || (set == 0)) {
617 if ((m_barSets.contains(set)) || (set == 0)) {
626 // Fail if set is already in list or set is null.
618 // Fail if set is already in list or set is null.
627 return false;
619 return false;
628 }
620 }
629 m_barSets.append(set);
621 m_barSets.append(set);
630 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
622 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
631 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
623 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
632 emit restructuredBars(); // this notifies barchartitem
624 emit restructuredBars(); // this notifies barchartitem
633 if (m_dataset) {
625 if (m_dataset) {
634 m_dataset->updateSeries(q); // this notifies legend
626 m_dataset->updateSeries(q); // this notifies legend
635 }
627 }
636 return true;
628 return true;
637 }
629 }
638
630
639 bool QAbstractBarSeriesPrivate::remove(QBarSet *set)
631 bool QAbstractBarSeriesPrivate::remove(QBarSet *set)
640 {
632 {
641 Q_Q(QAbstractBarSeries);
633 Q_Q(QAbstractBarSeries);
642 if (!m_barSets.contains(set)) {
634 if (!m_barSets.contains(set)) {
643 // Fail if set is not in list
635 // Fail if set is not in list
644 return false;
636 return false;
645 }
637 }
646 m_barSets.removeOne(set);
638 m_barSets.removeOne(set);
647 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
639 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
648 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
640 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
649 emit restructuredBars(); // this notifies barchartitem
641 emit restructuredBars(); // this notifies barchartitem
650 if (m_dataset) {
642 if (m_dataset) {
651 m_dataset->updateSeries(q); // this notifies legend
643 m_dataset->updateSeries(q); // this notifies legend
652 }
644 }
653 return true;
645 return true;
654 }
646 }
655
647
656 bool QAbstractBarSeriesPrivate::append(QList<QBarSet* > sets)
648 bool QAbstractBarSeriesPrivate::append(QList<QBarSet* > sets)
657 {
649 {
658 Q_Q(QAbstractBarSeries);
650 Q_Q(QAbstractBarSeries);
659 foreach (QBarSet* set, sets) {
651 foreach (QBarSet* set, sets) {
660 if ((set == 0) || (m_barSets.contains(set))) {
652 if ((set == 0) || (m_barSets.contains(set))) {
661 // Fail if any of the sets is null or is already appended.
653 // Fail if any of the sets is null or is already appended.
662 return false;
654 return false;
663 }
655 }
664 if (sets.count(set) != 1) {
656 if (sets.count(set) != 1) {
665 // Also fail if same set is more than once in given list.
657 // Also fail if same set is more than once in given list.
666 return false;
658 return false;
667 }
659 }
668 }
660 }
669
661
670 foreach (QBarSet* set, sets) {
662 foreach (QBarSet* set, sets) {
671 m_barSets.append(set);
663 m_barSets.append(set);
672 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
664 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
673 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
665 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
674 }
666 }
675 emit restructuredBars(); // this notifies barchartitem
667 emit restructuredBars(); // this notifies barchartitem
676 if (m_dataset) {
668 if (m_dataset) {
677 m_dataset->updateSeries(q); // this notifies legend
669 m_dataset->updateSeries(q); // this notifies legend
678 }
670 }
679 return true;
671 return true;
680 }
672 }
681
673
682 bool QAbstractBarSeriesPrivate::remove(QList<QBarSet* > sets)
674 bool QAbstractBarSeriesPrivate::remove(QList<QBarSet* > sets)
683 {
675 {
684 Q_Q(QAbstractBarSeries);
676 Q_Q(QAbstractBarSeries);
685 if (sets.count() == 0) {
677 if (sets.count() == 0) {
686 return false;
678 return false;
687 }
679 }
688 foreach (QBarSet* set, sets) {
680 foreach (QBarSet* set, sets) {
689 if ((set == 0) || (!m_barSets.contains(set))) {
681 if ((set == 0) || (!m_barSets.contains(set))) {
690 // Fail if any of the sets is null or is not in series
682 // Fail if any of the sets is null or is not in series
691 return false;
683 return false;
692 }
684 }
693 if (sets.count(set) != 1) {
685 if (sets.count(set) != 1) {
694 // Also fail if same set is more than once in given list.
686 // Also fail if same set is more than once in given list.
695 return false;
687 return false;
696 }
688 }
697 }
689 }
698
690
699 foreach (QBarSet* set, sets) {
691 foreach (QBarSet* set, sets) {
700 m_barSets.removeOne(set);
692 m_barSets.removeOne(set);
701 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
693 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
702 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
694 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
703 }
695 }
704
696
705 emit restructuredBars(); // this notifies barchartitem
697 emit restructuredBars(); // this notifies barchartitem
706 if (m_dataset) {
698 if (m_dataset) {
707 m_dataset->updateSeries(q); // this notifies legend
699 m_dataset->updateSeries(q); // this notifies legend
708 }
700 }
709 return true;
701 return true;
710 }
702 }
711
703
712 bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set)
704 bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set)
713 {
705 {
714 Q_Q(QAbstractBarSeries);
706 Q_Q(QAbstractBarSeries);
715 if ((m_barSets.contains(set)) || (set == 0)) {
707 if ((m_barSets.contains(set)) || (set == 0)) {
716 // Fail if set is already in list or set is null.
708 // Fail if set is already in list or set is null.
717 return false;
709 return false;
718 }
710 }
719 m_barSets.insert(index, set);
711 m_barSets.insert(index, set);
720 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
712 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
721 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
713 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
722 emit restructuredBars(); // this notifies barchartitem
714 emit restructuredBars(); // this notifies barchartitem
723 if (m_dataset) {
715 if (m_dataset) {
724 m_dataset->updateSeries(q); // this notifies legend
716 m_dataset->updateSeries(q); // this notifies legend
725 }
717 }
726 return true;
718 return true;
727 }
719 }
728
720
729 #include "moc_qabstractbarseries.cpp"
721 #include "moc_qabstractbarseries.cpp"
730 #include "moc_qabstractbarseries_p.cpp"
722 #include "moc_qabstractbarseries_p.cpp"
731
723
732 QTCOMMERCIALCHART_END_NAMESPACE
724 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,82 +1,84
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef BARSERIES_H
21 #ifndef BARSERIES_H
22 #define BARSERIES_H
22 #define BARSERIES_H
23
23
24 #include <qabstractseries.h>
24 #include <qabstractseries.h>
25 #include <QStringList>
25 #include <QStringList>
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
28
29 class QBarSet;
29 class QBarSet;
30 class QAbstractBarSeriesPrivate;
30 class QAbstractBarSeriesPrivate;
31
31
32 // Container for series
32 // Container for series
33 class QTCOMMERCIALCHART_EXPORT QAbstractBarSeries : public QAbstractSeries
33 class QTCOMMERCIALCHART_EXPORT QAbstractBarSeries : public QAbstractSeries
34 {
34 {
35 Q_OBJECT
35 Q_OBJECT
36 Q_PROPERTY(qreal barWidth READ barWidth WRITE setBarWidth)
36 Q_PROPERTY(qreal barWidth READ barWidth WRITE setBarWidth)
37 Q_PROPERTY(int count READ count NOTIFY countChanged)
37 Q_PROPERTY(int count READ count NOTIFY countChanged)
38 Q_PROPERTY(bool labelsVisible READ isLabelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged)
38 Q_PROPERTY(bool labelsVisible READ isLabelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged)
39
39
40 public:
40 protected:
41 explicit QAbstractBarSeries(QObject *parent = 0);
41 explicit QAbstractBarSeries(QObject *parent = 0);
42
43 public:
42 virtual ~QAbstractBarSeries();
44 virtual ~QAbstractBarSeries();
43
45
44 QAbstractSeries::SeriesType type() const;
46 virtual QAbstractSeries::SeriesType type() const = 0;
45
47
46 void setBarWidth(qreal width);
48 void setBarWidth(qreal width);
47 qreal barWidth() const;
49 qreal barWidth() const;
48
50
49 bool append(QBarSet *set);
51 bool append(QBarSet *set);
50 bool remove(QBarSet *set);
52 bool remove(QBarSet *set);
51 bool append(QList<QBarSet* > sets);
53 bool append(QList<QBarSet* > sets);
52 bool insert(int index, QBarSet *set);
54 bool insert(int index, QBarSet *set);
53 int count() const;
55 int count() const;
54 QList<QBarSet*> barSets() const;
56 QList<QBarSet*> barSets() const;
55 void clear();
57 void clear();
56
58
57 void setLabelsVisible(bool visible = true);
59 void setLabelsVisible(bool visible = true);
58 bool isLabelsVisible() const;
60 bool isLabelsVisible() const;
59
61
60 protected:
62 protected:
61 explicit QAbstractBarSeries(QAbstractBarSeriesPrivate &d,QObject *parent = 0);
63 explicit QAbstractBarSeries(QAbstractBarSeriesPrivate &d,QObject *parent = 0);
62
64
63 Q_SIGNALS:
65 Q_SIGNALS:
64 void clicked(int index, QBarSet *barset);
66 void clicked(int index, QBarSet *barset);
65 void hovered(bool status, QBarSet *barset);
67 void hovered(bool status, QBarSet *barset);
66 void countChanged();
68 void countChanged();
67 void labelsVisibleChanged();
69 void labelsVisibleChanged();
68
70
69 void barsetsAdded(QList<QBarSet*> sets);
71 void barsetsAdded(QList<QBarSet*> sets);
70 void barsetsRemoved(QList<QBarSet*> sets);
72 void barsetsRemoved(QList<QBarSet*> sets);
71
73
72 protected:
74 protected:
73 Q_DECLARE_PRIVATE(QAbstractBarSeries)
75 Q_DECLARE_PRIVATE(QAbstractBarSeries)
74 friend class BarChartItem;
76 friend class BarChartItem;
75 friend class PercentBarChartItem;
77 friend class PercentBarChartItem;
76 friend class StackedBarChartItem;
78 friend class StackedBarChartItem;
77 friend class GroupedBarChartItem;
79 friend class GroupedBarChartItem;
78 };
80 };
79
81
80 QTCOMMERCIALCHART_END_NAMESPACE
82 QTCOMMERCIALCHART_END_NAMESPACE
81
83
82 #endif // BARSERIES_H
84 #endif // BARSERIES_H
@@ -1,634 +1,634
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include <QtTest/QtTest>
21 #include <QtTest/QtTest>
22 #include <qabstractaxis.h>
22 #include <qabstractaxis.h>
23 #include <qvaluesaxis.h>
23 #include <qvaluesaxis.h>
24 #include <qcategoriesaxis.h>
24 #include <qcategoriesaxis.h>
25 #include <qlineseries.h>
25 #include <qlineseries.h>
26 #include <qareaseries.h>
26 #include <qareaseries.h>
27 #include <qscatterseries.h>
27 #include <qscatterseries.h>
28 #include <qsplineseries.h>
28 #include <qsplineseries.h>
29 #include <qpieseries.h>
29 #include <qpieseries.h>
30 #include <qabstractbarseries.h>
30 #include <qgroupedbarseries.h>
31 #include <qpercentbarseries.h>
31 #include <qpercentbarseries.h>
32 #include <qstackedbarseries.h>
32 #include <qstackedbarseries.h>
33 #include <private/chartdataset_p.h>
33 #include <private/chartdataset_p.h>
34 #include <private/domain_p.h>
34 #include <private/domain_p.h>
35 #include <tst_definitions.h>
35 #include <tst_definitions.h>
36
36
37 QTCOMMERCIALCHART_USE_NAMESPACE
37 QTCOMMERCIALCHART_USE_NAMESPACE
38
38
39 Q_DECLARE_METATYPE(Domain *)
39 Q_DECLARE_METATYPE(Domain *)
40 Q_DECLARE_METATYPE(QAbstractAxis *)
40 Q_DECLARE_METATYPE(QAbstractAxis *)
41 Q_DECLARE_METATYPE(QAbstractSeries *)
41 Q_DECLARE_METATYPE(QAbstractSeries *)
42 Q_DECLARE_METATYPE(QList<QAbstractSeries *>)
42 Q_DECLARE_METATYPE(QList<QAbstractSeries *>)
43 Q_DECLARE_METATYPE(QList<QAbstractAxis *>)
43 Q_DECLARE_METATYPE(QList<QAbstractAxis *>)
44 Q_DECLARE_METATYPE(QLineSeries *)
44 Q_DECLARE_METATYPE(QLineSeries *)
45
45
46 class tst_ChartDataSet: public QObject {
46 class tst_ChartDataSet: public QObject {
47
47
48 Q_OBJECT
48 Q_OBJECT
49
49
50 public Q_SLOTS:
50 public Q_SLOTS:
51 void initTestCase();
51 void initTestCase();
52 void cleanupTestCase();
52 void cleanupTestCase();
53 void init();
53 void init();
54 void cleanup();
54 void cleanup();
55
55
56 private Q_SLOTS:
56 private Q_SLOTS:
57 void chartdataset_data();
57 void chartdataset_data();
58 void chartdataset();
58 void chartdataset();
59 void addSeries_data();
59 void addSeries_data();
60 void addSeries();
60 void addSeries();
61 void setAxisX_data();
61 void setAxisX_data();
62 void setAxisX();
62 void setAxisX();
63 void setAxisY_data();
63 void setAxisY_data();
64 void setAxisY();
64 void setAxisY();
65 void removeSeries_data();
65 void removeSeries_data();
66 void removeSeries();
66 void removeSeries();
67 void removeAllSeries_data();
67 void removeAllSeries_data();
68 void removeAllSeries();
68 void removeAllSeries();
69 void seriesCount_data();
69 void seriesCount_data();
70 void seriesCount();
70 void seriesCount();
71 void seriesIndex_data();
71 void seriesIndex_data();
72 void seriesIndex();
72 void seriesIndex();
73 void domain_data();
73 void domain_data();
74 void domain();
74 void domain();
75 void zoomInDomain_data();
75 void zoomInDomain_data();
76 void zoomInDomain();
76 void zoomInDomain();
77 /*
77 /*
78 void zoomOutDomain_data();
78 void zoomOutDomain_data();
79 void zoomOutDomain();
79 void zoomOutDomain();
80 void scrollDomain_data();
80 void scrollDomain_data();
81 void scrollDomain();
81 void scrollDomain();
82 */
82 */
83 private:
83 private:
84 ChartDataSet* m_dataset;
84 ChartDataSet* m_dataset;
85 };
85 };
86
86
87 void tst_ChartDataSet::initTestCase()
87 void tst_ChartDataSet::initTestCase()
88 {
88 {
89 qRegisterMetaType<Domain*>();
89 qRegisterMetaType<Domain*>();
90 qRegisterMetaType<QAbstractAxis*>();
90 qRegisterMetaType<QAbstractAxis*>();
91 qRegisterMetaType<QAbstractSeries*>();
91 qRegisterMetaType<QAbstractSeries*>();
92 }
92 }
93
93
94 void tst_ChartDataSet::cleanupTestCase()
94 void tst_ChartDataSet::cleanupTestCase()
95 {
95 {
96 }
96 }
97
97
98 void tst_ChartDataSet::init()
98 void tst_ChartDataSet::init()
99 {
99 {
100 m_dataset = new ChartDataSet();
100 m_dataset = new ChartDataSet();
101 }
101 }
102
102
103
103
104 void tst_ChartDataSet::cleanup()
104 void tst_ChartDataSet::cleanup()
105 {
105 {
106 QList<QAbstractSeries*> series = m_dataset->series();
106 QList<QAbstractSeries*> series = m_dataset->series();
107 foreach(QAbstractSeries* serie, series)
107 foreach(QAbstractSeries* serie, series)
108 {
108 {
109 m_dataset->removeSeries(serie);
109 m_dataset->removeSeries(serie);
110 }
110 }
111 }
111 }
112
112
113 void tst_ChartDataSet::chartdataset_data()
113 void tst_ChartDataSet::chartdataset_data()
114 {
114 {
115 }
115 }
116
116
117 void tst_ChartDataSet::chartdataset()
117 void tst_ChartDataSet::chartdataset()
118 {
118 {
119 QVERIFY(m_dataset->axisX(0) == 0);
119 QVERIFY(m_dataset->axisX(0) == 0);
120 QVERIFY(m_dataset->axisY(0) == 0);
120 QVERIFY(m_dataset->axisY(0) == 0);
121 QLineSeries* series = new QLineSeries(this);
121 QLineSeries* series = new QLineSeries(this);
122 QCOMPARE(m_dataset->seriesIndex(series),-1);
122 QCOMPARE(m_dataset->seriesIndex(series),-1);
123 QVERIFY(m_dataset->domain(series) == 0);
123 QVERIFY(m_dataset->domain(series) == 0);
124 QVERIFY(m_dataset->axisX(series) == 0);
124 QVERIFY(m_dataset->axisX(series) == 0);
125 QVERIFY(m_dataset->axisY(series) == 0);
125 QVERIFY(m_dataset->axisY(series) == 0);
126 m_dataset->createDefaultAxes();
126 m_dataset->createDefaultAxes();
127 }
127 }
128
128
129
129
130 void tst_ChartDataSet::addSeries_data()
130 void tst_ChartDataSet::addSeries_data()
131 {
131 {
132 QTest::addColumn<QAbstractSeries*>("series");
132 QTest::addColumn<QAbstractSeries*>("series");
133
133
134 QAbstractSeries* line = new QLineSeries(this);
134 QAbstractSeries* line = new QLineSeries(this);
135 QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line));
135 QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line));
136 QAbstractSeries* scatter = new QScatterSeries(this);
136 QAbstractSeries* scatter = new QScatterSeries(this);
137 QAbstractSeries* spline = new QSplineSeries(this);
137 QAbstractSeries* spline = new QSplineSeries(this);
138 QAbstractSeries* pie = new QPieSeries(this);
138 QAbstractSeries* pie = new QPieSeries(this);
139 QAbstractSeries* bar = new QAbstractBarSeries(this);
139 QAbstractSeries* bar = new QGroupedBarSeries(this);
140 QAbstractSeries* percent = new QPercentBarSeries(this);
140 QAbstractSeries* percent = new QPercentBarSeries(this);
141 QAbstractSeries* stacked = new QStackedBarSeries(this);
141 QAbstractSeries* stacked = new QStackedBarSeries(this);
142
142
143 QTest::newRow("line") << line;
143 QTest::newRow("line") << line;
144 QTest::newRow("area") << area;
144 QTest::newRow("area") << area;
145 QTest::newRow("scatter") << scatter;
145 QTest::newRow("scatter") << scatter;
146 QTest::newRow("spline") << spline;
146 QTest::newRow("spline") << spline;
147 QTest::newRow("pie") << pie;
147 QTest::newRow("pie") << pie;
148 QTest::newRow("bar") << bar;
148 QTest::newRow("bar") << bar;
149 QTest::newRow("percent") << percent;
149 QTest::newRow("percent") << percent;
150 QTest::newRow("stacked") << stacked;
150 QTest::newRow("stacked") << stacked;
151 }
151 }
152
152
153 void tst_ChartDataSet::addSeries()
153 void tst_ChartDataSet::addSeries()
154 {
154 {
155
155
156 QFETCH(QAbstractSeries*, series);
156 QFETCH(QAbstractSeries*, series);
157
157
158 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*, Domain *)));
158 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*, Domain *)));
159 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
159 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
160 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
160 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
161 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
161 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
162
162
163 m_dataset->addSeries(series);
163 m_dataset->addSeries(series);
164 m_dataset->createDefaultAxes();
164 m_dataset->createDefaultAxes();
165 if(series->type()==QAbstractSeries::SeriesTypePie){
165 if(series->type()==QAbstractSeries::SeriesTypePie){
166 TRY_COMPARE(spy0.count(), 0);
166 TRY_COMPARE(spy0.count(), 0);
167 }else{
167 }else{
168 TRY_COMPARE(spy0.count(), 2);
168 TRY_COMPARE(spy0.count(), 2);
169 }
169 }
170 TRY_COMPARE(spy1.count(), 0);
170 TRY_COMPARE(spy1.count(), 0);
171 TRY_COMPARE(spy2.count(), 1);
171 TRY_COMPARE(spy2.count(), 1);
172 TRY_COMPARE(spy3.count(), 0);
172 TRY_COMPARE(spy3.count(), 0);
173 }
173 }
174
174
175
175
176 void tst_ChartDataSet::setAxisX_data()
176 void tst_ChartDataSet::setAxisX_data()
177 {
177 {
178
178
179 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
179 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
180 QTest::addColumn<QList<QAbstractAxis*> >("axisList");
180 QTest::addColumn<QList<QAbstractAxis*> >("axisList");
181 QTest::addColumn<int>("axisCount");
181 QTest::addColumn<int>("axisCount");
182
182
183 QAbstractSeries* line = new QLineSeries(this);
183 QAbstractSeries* line = new QLineSeries(this);
184 QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line));
184 QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line));
185 QAbstractSeries* scatter = new QScatterSeries(this);
185 QAbstractSeries* scatter = new QScatterSeries(this);
186 QAbstractSeries* spline = new QSplineSeries(this);
186 QAbstractSeries* spline = new QSplineSeries(this);
187 QAbstractSeries* pie = new QPieSeries(this);
187 QAbstractSeries* pie = new QPieSeries(this);
188 QAbstractSeries* bar = new QAbstractBarSeries(this);
188 QAbstractSeries* bar = new QGroupedBarSeries(this);
189 QAbstractSeries* percent = new QPercentBarSeries(this);
189 QAbstractSeries* percent = new QPercentBarSeries(this);
190 QAbstractSeries* stacked = new QStackedBarSeries(this);
190 QAbstractSeries* stacked = new QStackedBarSeries(this);
191
191
192 QTest::newRow("line,spline,scatter: axis 0 axis1 axis 2")
192 QTest::newRow("line,spline,scatter: axis 0 axis1 axis 2")
193 << (QList<QAbstractSeries*>() << line << spline << scatter)
193 << (QList<QAbstractSeries*>() << line << spline << scatter)
194 << (QList<QAbstractAxis*>() << new QValuesAxis(this) << new QValuesAxis(this) << new QValuesAxis(this)) << 3;
194 << (QList<QAbstractAxis*>() << new QValuesAxis(this) << new QValuesAxis(this) << new QValuesAxis(this)) << 3;
195
195
196 QTest::newRow("area: axis 0") << (QList<QAbstractSeries*>() << area)
196 QTest::newRow("area: axis 0") << (QList<QAbstractSeries*>() << area)
197 << (QList<QAbstractAxis*>() << new QValuesAxis(this)) << 1;
197 << (QList<QAbstractAxis*>() << new QValuesAxis(this)) << 1;
198
198
199 QList<QAbstractAxis*> axes0;
199 QList<QAbstractAxis*> axes0;
200 axes0 << new QValuesAxis(this) << new QValuesAxis(this);
200 axes0 << new QValuesAxis(this) << new QValuesAxis(this);
201 axes0 << axes0.last();
201 axes0 << axes0.last();
202 QTest::newRow("line,spline,scatter: axis 0 axis1 axis 1")
202 QTest::newRow("line,spline,scatter: axis 0 axis1 axis 1")
203 << (QList<QAbstractSeries*>() << line << spline << scatter)
203 << (QList<QAbstractSeries*>() << line << spline << scatter)
204 << axes0 << 2;
204 << axes0 << 2;
205 //TODO: add more test cases
205 //TODO: add more test cases
206 }
206 }
207
207
208 void tst_ChartDataSet::setAxisX()
208 void tst_ChartDataSet::setAxisX()
209 {
209 {
210 QFETCH(QList<QAbstractSeries*>, seriesList);
210 QFETCH(QList<QAbstractSeries*>, seriesList);
211 QFETCH(QList<QAbstractAxis*>, axisList);
211 QFETCH(QList<QAbstractAxis*>, axisList);
212 QFETCH(int, axisCount);
212 QFETCH(int, axisCount);
213
213
214 Q_ASSERT(seriesList.count() == axisList.count());
214 Q_ASSERT(seriesList.count() == axisList.count());
215
215
216 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *,Domain*)));
216 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *,Domain*)));
217 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
217 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
218 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*)));
218 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*)));
219 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
219 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
220
220
221 foreach(QAbstractSeries* series, seriesList){
221 foreach(QAbstractSeries* series, seriesList){
222 m_dataset->addSeries(series);
222 m_dataset->addSeries(series);
223 }
223 }
224
224
225 TRY_COMPARE(spy0.count(), 0);
225 TRY_COMPARE(spy0.count(), 0);
226 TRY_COMPARE(spy1.count(), 0);
226 TRY_COMPARE(spy1.count(), 0);
227 TRY_COMPARE(spy2.count(), seriesList.count());
227 TRY_COMPARE(spy2.count(), seriesList.count());
228 TRY_COMPARE(spy3.count(), 0);
228 TRY_COMPARE(spy3.count(), 0);
229
229
230 QSignalSpy spy4(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*)));
230 QSignalSpy spy4(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*)));
231 QSignalSpy spy5(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
231 QSignalSpy spy5(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
232 QSignalSpy spy6(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*)));
232 QSignalSpy spy6(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*)));
233 QSignalSpy spy7(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
233 QSignalSpy spy7(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
234
234
235 for(int i=0 ; i < seriesList.count(); i++){
235 for(int i=0 ; i < seriesList.count(); i++){
236 m_dataset->setAxisX(seriesList.at(i),axisList.at(i));
236 m_dataset->setAxisX(seriesList.at(i),axisList.at(i));
237 }
237 }
238
238
239 TRY_COMPARE(spy4.count(), axisCount);
239 TRY_COMPARE(spy4.count(), axisCount);
240 TRY_COMPARE(spy5.count(), 0);
240 TRY_COMPARE(spy5.count(), 0);
241 TRY_COMPARE(spy6.count(), 0);
241 TRY_COMPARE(spy6.count(), 0);
242 TRY_COMPARE(spy7.count(), 0);
242 TRY_COMPARE(spy7.count(), 0);
243
243
244 for(int i=0 ; i < seriesList.count(); i++){
244 for(int i=0 ; i < seriesList.count(); i++){
245 QVERIFY(m_dataset->axisX(seriesList.at(i)) == axisList.at(i));
245 QVERIFY(m_dataset->axisX(seriesList.at(i)) == axisList.at(i));
246 }
246 }
247 }
247 }
248
248
249 void tst_ChartDataSet::setAxisY_data()
249 void tst_ChartDataSet::setAxisY_data()
250 {
250 {
251 setAxisX_data();
251 setAxisX_data();
252 }
252 }
253
253
254 void tst_ChartDataSet::setAxisY()
254 void tst_ChartDataSet::setAxisY()
255 {
255 {
256 QFETCH(QList<QAbstractSeries*>, seriesList);
256 QFETCH(QList<QAbstractSeries*>, seriesList);
257 QFETCH(QList<QAbstractAxis*>, axisList);
257 QFETCH(QList<QAbstractAxis*>, axisList);
258 QFETCH(int, axisCount);
258 QFETCH(int, axisCount);
259
259
260 Q_ASSERT(seriesList.count() == axisList.count());
260 Q_ASSERT(seriesList.count() == axisList.count());
261
261
262 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*)));
262 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*)));
263 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
263 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
264 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*)));
264 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*)));
265 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
265 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
266
266
267 foreach(QAbstractSeries* series, seriesList){
267 foreach(QAbstractSeries* series, seriesList){
268 m_dataset->addSeries(series);
268 m_dataset->addSeries(series);
269 }
269 }
270
270
271 TRY_COMPARE(spy0.count(), 0);
271 TRY_COMPARE(spy0.count(), 0);
272 TRY_COMPARE(spy1.count(), 0);
272 TRY_COMPARE(spy1.count(), 0);
273 TRY_COMPARE(spy2.count(), seriesList.count());
273 TRY_COMPARE(spy2.count(), seriesList.count());
274 TRY_COMPARE(spy3.count(), 0);
274 TRY_COMPARE(spy3.count(), 0);
275
275
276 QSignalSpy spy4(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*)));
276 QSignalSpy spy4(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*)));
277 QSignalSpy spy5(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
277 QSignalSpy spy5(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
278 QSignalSpy spy6(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*)));
278 QSignalSpy spy6(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*)));
279 QSignalSpy spy7(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
279 QSignalSpy spy7(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
280
280
281 for(int i=0 ; i < seriesList.count(); i++){
281 for(int i=0 ; i < seriesList.count(); i++){
282 m_dataset->setAxisY(seriesList.at(i),axisList.at(i));
282 m_dataset->setAxisY(seriesList.at(i),axisList.at(i));
283 }
283 }
284
284
285 TRY_COMPARE(spy4.count(), axisCount);
285 TRY_COMPARE(spy4.count(), axisCount);
286 TRY_COMPARE(spy5.count(), 0);
286 TRY_COMPARE(spy5.count(), 0);
287 TRY_COMPARE(spy6.count(), 0);
287 TRY_COMPARE(spy6.count(), 0);
288 TRY_COMPARE(spy7.count(), 0);
288 TRY_COMPARE(spy7.count(), 0);
289
289
290 for(int i=0 ; i < seriesList.count(); i++){
290 for(int i=0 ; i < seriesList.count(); i++){
291 QVERIFY(m_dataset->axisY(seriesList.at(i)) == axisList.at(i));
291 QVERIFY(m_dataset->axisY(seriesList.at(i)) == axisList.at(i));
292 }
292 }
293 }
293 }
294
294
295 void tst_ChartDataSet::removeSeries_data()
295 void tst_ChartDataSet::removeSeries_data()
296 {
296 {
297 addSeries_data();
297 addSeries_data();
298 }
298 }
299
299
300 void tst_ChartDataSet::removeSeries()
300 void tst_ChartDataSet::removeSeries()
301 {
301 {
302 QFETCH(QAbstractSeries*, series);
302 QFETCH(QAbstractSeries*, series);
303
303
304 m_dataset->addSeries(series);
304 m_dataset->addSeries(series);
305 m_dataset->createDefaultAxes();
305 m_dataset->createDefaultAxes();
306
306
307 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*, Domain *)));
307 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*, Domain *)));
308 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
308 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
309 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
309 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
310 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
310 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
311
311
312 m_dataset->removeSeries(series);
312 m_dataset->removeSeries(series);
313
313
314 TRY_COMPARE(spy0.count(), 0);
314 TRY_COMPARE(spy0.count(), 0);
315 if (series->type() == QAbstractSeries::SeriesTypePie) {
315 if (series->type() == QAbstractSeries::SeriesTypePie) {
316 TRY_COMPARE(spy1.count(), 0);
316 TRY_COMPARE(spy1.count(), 0);
317 }
317 }
318 else {
318 else {
319 TRY_COMPARE(spy1.count(), 2);
319 TRY_COMPARE(spy1.count(), 2);
320 }
320 }
321 TRY_COMPARE(spy2.count(), 0);
321 TRY_COMPARE(spy2.count(), 0);
322 TRY_COMPARE(spy3.count(), 1);
322 TRY_COMPARE(spy3.count(), 1);
323 }
323 }
324
324
325 void tst_ChartDataSet::removeAllSeries_data()
325 void tst_ChartDataSet::removeAllSeries_data()
326 {
326 {
327 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
327 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
328 QTest::addColumn<QList<QAbstractAxis*> >("axisList");
328 QTest::addColumn<QList<QAbstractAxis*> >("axisList");
329 QTest::addColumn<int>("axisCount");
329 QTest::addColumn<int>("axisCount");
330
330
331 QTest::newRow("line,spline,scatter: axis 0 axis1 axis 2")
331 QTest::newRow("line,spline,scatter: axis 0 axis1 axis 2")
332 << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QSplineSeries(this)
332 << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QSplineSeries(this)
333 << new QScatterSeries(this))
333 << new QScatterSeries(this))
334 << (QList<QAbstractAxis*>() << new QValuesAxis(this) << new QValuesAxis(this)
334 << (QList<QAbstractAxis*>() << new QValuesAxis(this) << new QValuesAxis(this)
335 << new QValuesAxis(this)) << 3;
335 << new QValuesAxis(this)) << 3;
336 //TODO:
336 //TODO:
337 }
337 }
338
338
339 void tst_ChartDataSet::removeAllSeries()
339 void tst_ChartDataSet::removeAllSeries()
340 {
340 {
341 QFETCH(QList<QAbstractSeries*>, seriesList);
341 QFETCH(QList<QAbstractSeries*>, seriesList);
342 QFETCH(QList<QAbstractAxis*>, axisList);
342 QFETCH(QList<QAbstractAxis*>, axisList);
343 QFETCH(int, axisCount);
343 QFETCH(int, axisCount);
344
344
345 foreach(QAbstractSeries* series, seriesList) {
345 foreach(QAbstractSeries* series, seriesList) {
346 m_dataset->addSeries(series);
346 m_dataset->addSeries(series);
347 }
347 }
348
348
349 for (int i = 0; i < seriesList.count(); i++) {
349 for (int i = 0; i < seriesList.count(); i++) {
350 m_dataset->setAxisX(seriesList.at(i), axisList.at(i));
350 m_dataset->setAxisX(seriesList.at(i), axisList.at(i));
351 }
351 }
352
352
353 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *)));
353 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *)));
354 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
354 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
355 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
355 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
356 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
356 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
357
357
358 m_dataset->removeAllSeries();
358 m_dataset->removeAllSeries();
359
359
360 TRY_COMPARE(spy0.count(), 0);
360 TRY_COMPARE(spy0.count(), 0);
361 TRY_COMPARE(spy1.count(), axisCount);
361 TRY_COMPARE(spy1.count(), axisCount);
362 TRY_COMPARE(spy2.count(), 0);
362 TRY_COMPARE(spy2.count(), 0);
363 TRY_COMPARE(spy3.count(), seriesList.count());
363 TRY_COMPARE(spy3.count(), seriesList.count());
364 }
364 }
365
365
366
366
367 void tst_ChartDataSet::seriesCount_data()
367 void tst_ChartDataSet::seriesCount_data()
368 {
368 {
369 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
369 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
370 QTest::addColumn<int>("seriesCount");
370 QTest::addColumn<int>("seriesCount");
371
371
372 QTest::newRow("line,line, line, spline 3") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ) << 3;
372 QTest::newRow("line,line, line, spline 3") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ) << 3;
373 QTest::newRow("scatter,scatter, line, line 2") << (QList<QAbstractSeries*>() << new QScatterSeries(this) << new QScatterSeries(this) << new QLineSeries(this) << new QLineSeries(this) ) << 2;
373 QTest::newRow("scatter,scatter, line, line 2") << (QList<QAbstractSeries*>() << new QScatterSeries(this) << new QScatterSeries(this) << new QLineSeries(this) << new QLineSeries(this) ) << 2;
374 }
374 }
375
375
376 void tst_ChartDataSet::seriesCount()
376 void tst_ChartDataSet::seriesCount()
377 {
377 {
378 QFETCH(QList<QAbstractSeries*>, seriesList);
378 QFETCH(QList<QAbstractSeries*>, seriesList);
379 QFETCH(int, seriesCount);
379 QFETCH(int, seriesCount);
380
380
381 foreach(QAbstractSeries* series, seriesList){
381 foreach(QAbstractSeries* series, seriesList){
382 m_dataset->addSeries(series);
382 m_dataset->addSeries(series);
383 }
383 }
384
384
385 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *)));
385 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *)));
386 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
386 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
387 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
387 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
388 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
388 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
389
389
390 QCOMPARE(m_dataset->seriesCount(seriesList.at(0)->type()),seriesCount);
390 QCOMPARE(m_dataset->seriesCount(seriesList.at(0)->type()),seriesCount);
391 TRY_COMPARE(spy0.count(), 0);
391 TRY_COMPARE(spy0.count(), 0);
392 TRY_COMPARE(spy1.count(), 0);
392 TRY_COMPARE(spy1.count(), 0);
393 TRY_COMPARE(spy2.count(), 0);
393 TRY_COMPARE(spy2.count(), 0);
394 TRY_COMPARE(spy3.count(), 0);
394 TRY_COMPARE(spy3.count(), 0);
395 }
395 }
396
396
397 void tst_ChartDataSet::seriesIndex_data()
397 void tst_ChartDataSet::seriesIndex_data()
398 {
398 {
399 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
399 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
400
400
401 QTest::newRow("line,line, line, spline") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) );
401 QTest::newRow("line,line, line, spline") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) );
402 QTest::newRow("scatter,scatter, line, line") << (QList<QAbstractSeries*>() << new QScatterSeries(this) << new QScatterSeries(this) << new QLineSeries(this) << new QLineSeries(this) );
402 QTest::newRow("scatter,scatter, line, line") << (QList<QAbstractSeries*>() << new QScatterSeries(this) << new QScatterSeries(this) << new QLineSeries(this) << new QLineSeries(this) );
403 }
403 }
404
404
405 void tst_ChartDataSet::seriesIndex()
405 void tst_ChartDataSet::seriesIndex()
406 {
406 {
407
407
408 QFETCH(QList<QAbstractSeries*>, seriesList);
408 QFETCH(QList<QAbstractSeries*>, seriesList);
409
409
410 foreach(QAbstractSeries* series, seriesList) {
410 foreach(QAbstractSeries* series, seriesList) {
411 m_dataset->addSeries(series);
411 m_dataset->addSeries(series);
412 }
412 }
413
413
414 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *,Domain*)));
414 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *,Domain*)));
415 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
415 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
416 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*)));
416 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*)));
417 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)));
417 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)));
418
418
419 for (int i = 0; i < seriesList.count(); i++) {
419 for (int i = 0; i < seriesList.count(); i++) {
420 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
420 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
421 }
421 }
422
422
423 TRY_COMPARE(spy0.count(), 0);
423 TRY_COMPARE(spy0.count(), 0);
424 TRY_COMPARE(spy1.count(), 0);
424 TRY_COMPARE(spy1.count(), 0);
425 TRY_COMPARE(spy2.count(), 0);
425 TRY_COMPARE(spy2.count(), 0);
426 TRY_COMPARE(spy3.count(), 0);
426 TRY_COMPARE(spy3.count(), 0);
427
427
428 foreach(QAbstractSeries* series, seriesList) {
428 foreach(QAbstractSeries* series, seriesList) {
429 m_dataset->removeSeries(series);
429 m_dataset->removeSeries(series);
430 }
430 }
431
431
432 for (int i = 0; i < seriesList.count(); i++) {
432 for (int i = 0; i < seriesList.count(); i++) {
433 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1);
433 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1);
434 }
434 }
435
435
436 foreach(QAbstractSeries* series, seriesList) {
436 foreach(QAbstractSeries* series, seriesList) {
437 m_dataset->addSeries(series);
437 m_dataset->addSeries(series);
438 }
438 }
439
439
440 for (int i = 0; i < seriesList.count(); i++) {
440 for (int i = 0; i < seriesList.count(); i++) {
441 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
441 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
442 }
442 }
443
443
444 m_dataset->removeSeries(seriesList.at(1));
444 m_dataset->removeSeries(seriesList.at(1));
445
445
446 for (int i = 0; i < seriesList.count(); i++) {
446 for (int i = 0; i < seriesList.count(); i++) {
447 if (i != 1)
447 if (i != 1)
448 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
448 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
449 else
449 else
450 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1);
450 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1);
451 }
451 }
452
452
453 m_dataset->addSeries(seriesList.at(1));
453 m_dataset->addSeries(seriesList.at(1));
454
454
455 for (int i = 0; i < seriesList.count(); i++) {
455 for (int i = 0; i < seriesList.count(); i++) {
456 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
456 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
457 }
457 }
458
458
459 m_dataset->removeSeries(seriesList.at(2));
459 m_dataset->removeSeries(seriesList.at(2));
460
460
461 for (int i = 0; i < seriesList.count(); i++) {
461 for (int i = 0; i < seriesList.count(); i++) {
462 if (i != 2)
462 if (i != 2)
463 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
463 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
464 else
464 else
465 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1);
465 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1);
466 }
466 }
467
467
468 m_dataset->removeSeries(seriesList.at(0));
468 m_dataset->removeSeries(seriesList.at(0));
469
469
470 for (int i = 0; i < seriesList.count(); i++) {
470 for (int i = 0; i < seriesList.count(); i++) {
471 if (i != 2 && i != 0)
471 if (i != 2 && i != 0)
472 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
472 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
473 else
473 else
474 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1);
474 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1);
475 }
475 }
476
476
477 m_dataset->addSeries(seriesList.at(2));
477 m_dataset->addSeries(seriesList.at(2));
478 m_dataset->addSeries(seriesList.at(0));
478 m_dataset->addSeries(seriesList.at(0));
479
479
480 for (int i = 0; i < seriesList.count(); i++) {
480 for (int i = 0; i < seriesList.count(); i++) {
481 if (i == 2)
481 if (i == 2)
482 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), 0);
482 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), 0);
483 else if (i == 0)
483 else if (i == 0)
484 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), 2);
484 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), 2);
485 else
485 else
486 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
486 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
487 }
487 }
488
488
489 }
489 }
490
490
491 void tst_ChartDataSet::domain_data()
491 void tst_ChartDataSet::domain_data()
492 {
492 {
493 addSeries_data();
493 addSeries_data();
494 }
494 }
495
495
496 void tst_ChartDataSet::domain()
496 void tst_ChartDataSet::domain()
497 {
497 {
498 QFETCH(QAbstractSeries*, series);
498 QFETCH(QAbstractSeries*, series);
499
499
500 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *)));
500 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *)));
501 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
501 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
502 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
502 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
503 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
503 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
504
504
505 m_dataset->addSeries(series);
505 m_dataset->addSeries(series);
506 QVERIFY(m_dataset->domain(series));
506 QVERIFY(m_dataset->domain(series));
507
507
508
508
509 TRY_COMPARE(spy0.count(), 0);
509 TRY_COMPARE(spy0.count(), 0);
510 TRY_COMPARE(spy1.count(), 0);
510 TRY_COMPARE(spy1.count(), 0);
511 TRY_COMPARE(spy2.count(), 1);
511 TRY_COMPARE(spy2.count(), 1);
512
512
513 QList<QVariant> arguments = spy2.takeFirst();
513 QList<QVariant> arguments = spy2.takeFirst();
514 Domain *domain = (Domain *) arguments.at(1).value<Domain *>();
514 Domain *domain = (Domain *) arguments.at(1).value<Domain *>();
515 QVERIFY(m_dataset->domain(series) == domain);
515 QVERIFY(m_dataset->domain(series) == domain);
516
516
517 TRY_COMPARE(spy3.count(), 0);
517 TRY_COMPARE(spy3.count(), 0);
518
518
519 }
519 }
520
520
521 void tst_ChartDataSet::zoomInDomain_data()
521 void tst_ChartDataSet::zoomInDomain_data()
522 {
522 {
523 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
523 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
524 QTest::newRow("line,line, line, spline") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) );
524 QTest::newRow("line,line, line, spline") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) );
525 }
525 }
526
526
527 void tst_ChartDataSet::zoomInDomain()
527 void tst_ChartDataSet::zoomInDomain()
528 {
528 {
529 QFETCH(QList<QAbstractSeries*>, seriesList);
529 QFETCH(QList<QAbstractSeries*>, seriesList);
530
530
531 foreach(QAbstractSeries* series, seriesList) {
531 foreach(QAbstractSeries* series, seriesList) {
532 m_dataset->addSeries(series);
532 m_dataset->addSeries(series);
533 }
533 }
534
534
535 /*
535 /*
536 QValuesAxis* axis = new QValuesAxis();
536 QValuesAxis* axis = new QValuesAxis();
537
537
538 for (int i = 0; i < seriesList.count(); i++) {
538 for (int i = 0; i < seriesList.count(); i++) {
539 m_dataset->setAxisX(seriesList.at(i), axis);
539 m_dataset->setAxisX(seriesList.at(i), axis);
540 }
540 }
541 */
541 */
542 m_dataset->createDefaultAxes();
542 m_dataset->createDefaultAxes();
543
543
544 QList<QSignalSpy*> spyList;
544 QList<QSignalSpy*> spyList;
545
545
546 foreach(QAbstractSeries* series, seriesList) {
546 foreach(QAbstractSeries* series, seriesList) {
547 spyList << new QSignalSpy(m_dataset->domain(series),SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
547 spyList << new QSignalSpy(m_dataset->domain(series),SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
548 }
548 }
549
549
550 m_dataset->zoomInDomain(QRect(0, 0, 100, 100), QSize(1000, 1000));
550 m_dataset->zoomInDomain(QRect(0, 0, 100, 100), QSize(1000, 1000));
551
551
552 foreach(QSignalSpy* spy, spyList) {
552 foreach(QSignalSpy* spy, spyList) {
553 TRY_COMPARE(spy->count(), 1);
553 TRY_COMPARE(spy->count(), 1);
554 }
554 }
555
555
556 qDeleteAll(spyList);
556 qDeleteAll(spyList);
557 }
557 }
558
558
559 /*
559 /*
560 void tst_ChartDataSet::zoomOutDomain_data()
560 void tst_ChartDataSet::zoomOutDomain_data()
561 {
561 {
562 addSeries_data();
562 addSeries_data();
563 }
563 }
564
564
565 void tst_ChartDataSet::zoomOutDomain()
565 void tst_ChartDataSet::zoomOutDomain()
566 {
566 {
567 QFETCH(QLineSeries*, series0);
567 QFETCH(QLineSeries*, series0);
568 QFETCH(QAxis*, axis0);
568 QFETCH(QAxis*, axis0);
569 QFETCH(QLineSeries*, series1);
569 QFETCH(QLineSeries*, series1);
570 QFETCH(QAxis*, axis1);
570 QFETCH(QAxis*, axis1);
571 QFETCH(QLineSeries*, series2);
571 QFETCH(QLineSeries*, series2);
572 QFETCH(QAxis*, axis2);
572 QFETCH(QAxis*, axis2);
573 QFETCH(int, axisCount);
573 QFETCH(int, axisCount);
574
574
575 Q_UNUSED(axisCount);
575 Q_UNUSED(axisCount);
576
576
577 m_dataset->addSeries(series0, axis0);
577 m_dataset->addSeries(series0, axis0);
578 m_dataset->addSeries(series1, axis1);
578 m_dataset->addSeries(series1, axis1);
579 m_dataset->addSeries(series2, axis2);
579 m_dataset->addSeries(series2, axis2);
580
580
581 Domain* domain0 = m_dataset->domain(series0);
581 Domain* domain0 = m_dataset->domain(series0);
582 Domain* domain1 = m_dataset->domain(series1);
582 Domain* domain1 = m_dataset->domain(series1);
583 Domain* domain2 = m_dataset->domain(series2);
583 Domain* domain2 = m_dataset->domain(series2);
584
584
585 QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
585 QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
586 QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
586 QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
587 QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
587 QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
588
588
589 m_dataset->zoomOutDomain(QRect(0,0,100,100),QSize(1000,1000));
589 m_dataset->zoomOutDomain(QRect(0,0,100,100),QSize(1000,1000));
590
590
591 TRY_COMPARE(spy0.count(), 1);
591 TRY_COMPARE(spy0.count(), 1);
592 TRY_COMPARE(spy1.count(), 1);
592 TRY_COMPARE(spy1.count(), 1);
593 TRY_COMPARE(spy2.count(), 1);
593 TRY_COMPARE(spy2.count(), 1);
594 }
594 }
595
595
596 void tst_ChartDataSet::scrollDomain_data()
596 void tst_ChartDataSet::scrollDomain_data()
597 {
597 {
598 addSeries_data();
598 addSeries_data();
599 }
599 }
600
600
601 void tst_ChartDataSet::scrollDomain()
601 void tst_ChartDataSet::scrollDomain()
602 {
602 {
603 QFETCH(QLineSeries*, series0);
603 QFETCH(QLineSeries*, series0);
604 QFETCH(QAxis*, axis0);
604 QFETCH(QAxis*, axis0);
605 QFETCH(QLineSeries*, series1);
605 QFETCH(QLineSeries*, series1);
606 QFETCH(QAxis*, axis1);
606 QFETCH(QAxis*, axis1);
607 QFETCH(QLineSeries*, series2);
607 QFETCH(QLineSeries*, series2);
608 QFETCH(QAxis*, axis2);
608 QFETCH(QAxis*, axis2);
609 QFETCH(int, axisCount);
609 QFETCH(int, axisCount);
610
610
611 Q_UNUSED(axisCount);
611 Q_UNUSED(axisCount);
612
612
613 m_dataset->addSeries(series0, axis0);
613 m_dataset->addSeries(series0, axis0);
614 m_dataset->addSeries(series1, axis1);
614 m_dataset->addSeries(series1, axis1);
615 m_dataset->addSeries(series2, axis2);
615 m_dataset->addSeries(series2, axis2);
616
616
617 Domain* domain0 = m_dataset->domain(series0);
617 Domain* domain0 = m_dataset->domain(series0);
618 Domain* domain1 = m_dataset->domain(series1);
618 Domain* domain1 = m_dataset->domain(series1);
619 Domain* domain2 = m_dataset->domain(series2);
619 Domain* domain2 = m_dataset->domain(series2);
620
620
621 QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
621 QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
622 QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
622 QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
623 QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
623 QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
624
624
625 m_dataset->scrollDomain(10,10,QSize(1000,1000));
625 m_dataset->scrollDomain(10,10,QSize(1000,1000));
626
626
627 TRY_COMPARE(spy0.count(), 1);
627 TRY_COMPARE(spy0.count(), 1);
628 TRY_COMPARE(spy1.count(), 1);
628 TRY_COMPARE(spy1.count(), 1);
629 TRY_COMPARE(spy2.count(), 1);
629 TRY_COMPARE(spy2.count(), 1);
630 }
630 }
631 */
631 */
632 QTEST_MAIN(tst_ChartDataSet)
632 QTEST_MAIN(tst_ChartDataSet)
633 #include "tst_chartdataset.moc"
633 #include "tst_chartdataset.moc"
634
634
@@ -1,577 +1,571
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include <QtTest/QtTest>
21 #include <QtTest/QtTest>
22 #include <qabstractbarseries.h>
22 #include <qgroupedbarseries.h>
23 #include <qbarset.h>
23 #include <qbarset.h>
24 #include <qchartview.h>
24 #include <qchartview.h>
25 #include <qchart.h>
25 #include <qchart.h>
26 #include "tst_definitions.h"
26 #include "tst_definitions.h"
27
27
28 QTCOMMERCIALCHART_USE_NAMESPACE
28 QTCOMMERCIALCHART_USE_NAMESPACE
29
29
30 Q_DECLARE_METATYPE(QBarSet*)
30 Q_DECLARE_METATYPE(QBarSet*)
31
31
32 class tst_QBarSeries : public QObject
32 class tst_QBarSeries : public QObject
33 {
33 {
34 Q_OBJECT
34 Q_OBJECT
35
35
36 public slots:
36 public slots:
37 void initTestCase();
37 void initTestCase();
38 void cleanupTestCase();
38 void cleanupTestCase();
39 void init();
39 void init();
40 void cleanup();
40 void cleanup();
41
41
42 private slots:
42 private slots:
43 void qbarseries_data();
43 void qbarseries_data();
44 void qbarseries();
44 void qbarseries();
45 void type_data();
45 void type_data();
46 void type();
46 void type();
47 void append_data();
47 void append_data();
48 void append();
48 void append();
49 void remove_data();
49 void remove_data();
50 void remove();
50 void remove();
51 void appendList_data();
51 void appendList_data();
52 void appendList();
52 void appendList();
53 void count_data();
53 void count_data();
54 void count();
54 void count();
55 void barSets_data();
55 void barSets_data();
56 void barSets();
56 void barSets();
57 void setLabelsVisible_data();
57 void setLabelsVisible_data();
58 void setLabelsVisible();
58 void setLabelsVisible();
59 void mouseclicked_data();
59 void mouseclicked_data();
60 void mouseclicked();
60 void mouseclicked();
61 void mousehovered_data();
61 void mousehovered_data();
62 void mousehovered();
62 void mousehovered();
63 void clearWithAnimations();
63 void clearWithAnimations();
64
64
65 private:
65 private:
66 QAbstractBarSeries* m_barseries;
66 QGroupedBarSeries* m_barseries;
67 QAbstractBarSeries* m_barseries_with_sets;
67 QGroupedBarSeries* m_barseries_with_sets;
68
68
69 QList<QBarSet*> m_testSets;
69 QList<QBarSet*> m_testSets;
70
70
71 };
71 };
72
72
73 void tst_QBarSeries::initTestCase()
73 void tst_QBarSeries::initTestCase()
74 {
74 {
75 qRegisterMetaType<QBarSet*>("QBarSet*");
75 qRegisterMetaType<QBarSet*>("QBarSet*");
76 }
76 }
77
77
78 void tst_QBarSeries::cleanupTestCase()
78 void tst_QBarSeries::cleanupTestCase()
79 {
79 {
80 }
80 }
81
81
82 void tst_QBarSeries::init()
82 void tst_QBarSeries::init()
83 {
83 {
84 m_barseries = new QAbstractBarSeries();
84 m_barseries = new QGroupedBarSeries();
85 m_barseries_with_sets = new QAbstractBarSeries();
85 m_barseries_with_sets = new QGroupedBarSeries();
86
86
87 for (int i=0; i<5; i++) {
87 for (int i=0; i<5; i++) {
88 m_testSets.append(new QBarSet("testset"));
88 m_testSets.append(new QBarSet("testset"));
89 m_barseries_with_sets->append(m_testSets.at(i));
89 m_barseries_with_sets->append(m_testSets.at(i));
90 }
90 }
91 }
91 }
92
92
93 void tst_QBarSeries::cleanup()
93 void tst_QBarSeries::cleanup()
94 {
94 {
95 foreach(QBarSet* s, m_testSets) {
95 foreach(QBarSet* s, m_testSets) {
96 m_barseries_with_sets->remove(s);
96 m_barseries_with_sets->remove(s);
97 delete s;
97 delete s;
98 }
98 }
99 m_testSets.clear();
99 m_testSets.clear();
100
100
101 delete m_barseries;
101 delete m_barseries;
102 m_barseries = 0;
102 m_barseries = 0;
103 delete m_barseries_with_sets;
103 delete m_barseries_with_sets;
104 m_barseries_with_sets = 0;
104 m_barseries_with_sets = 0;
105 }
105 }
106
106
107 void tst_QBarSeries::qbarseries_data()
107 void tst_QBarSeries::qbarseries_data()
108 {
108 {
109 }
109 }
110
110
111 void tst_QBarSeries::qbarseries()
111 void tst_QBarSeries::qbarseries()
112 {
112 {
113 QAbstractBarSeries *barseries = new QAbstractBarSeries();
113 QGroupedBarSeries *barseries = new QGroupedBarSeries();
114 QVERIFY(barseries != 0);
114 QVERIFY(barseries != 0);
115 }
115 }
116
116
117 void tst_QBarSeries::type_data()
117 void tst_QBarSeries::type_data()
118 {
118 {
119
119
120 }
120 }
121
121
122 void tst_QBarSeries::type()
122 void tst_QBarSeries::type()
123 {
123 {
124 QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeBar);
124 QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeBar);
125 }
125 }
126
126
127 void tst_QBarSeries::append_data()
127 void tst_QBarSeries::append_data()
128 {
128 {
129 }
129 }
130
130
131 void tst_QBarSeries::append()
131 void tst_QBarSeries::append()
132 {
132 {
133 QVERIFY(m_barseries->count() == 0);
133 QVERIFY(m_barseries->count() == 0);
134
134
135 bool ret = false;
135 bool ret = false;
136
136
137 // Try adding barset
137 // Try adding barset
138 QBarSet *barset = new QBarSet("testset");
138 QBarSet *barset = new QBarSet("testset");
139 ret = m_barseries->append(barset);
139 ret = m_barseries->append(barset);
140
140
141 QVERIFY(ret == true);
141 QVERIFY(ret == true);
142 QVERIFY(m_barseries->count() == 1);
142 QVERIFY(m_barseries->count() == 1);
143
143
144 // Try adding another set
144 // Try adding another set
145 QBarSet *barset2 = new QBarSet("testset2");
145 QBarSet *barset2 = new QBarSet("testset2");
146 ret = m_barseries->append(barset2);
146 ret = m_barseries->append(barset2);
147
147
148 QVERIFY(ret == true);
148 QVERIFY(ret == true);
149 QVERIFY(m_barseries->count() == 2);
149 QVERIFY(m_barseries->count() == 2);
150
150
151 // Try adding same set again
151 // Try adding same set again
152 ret = m_barseries->append(barset2);
152 ret = m_barseries->append(barset2);
153 QVERIFY(ret == false);
153 QVERIFY(ret == false);
154 QVERIFY(m_barseries->count() == 2);
154 QVERIFY(m_barseries->count() == 2);
155
155
156 // Try adding null set
156 // Try adding null set
157 ret = m_barseries->append(0);
157 ret = m_barseries->append(0);
158 QVERIFY(ret == false);
158 QVERIFY(ret == false);
159 QVERIFY(m_barseries->count() == 2);
159 QVERIFY(m_barseries->count() == 2);
160
160
161 }
161 }
162
162
163 void tst_QBarSeries::remove_data()
163 void tst_QBarSeries::remove_data()
164 {
164 {
165 }
165 }
166
166
167 void tst_QBarSeries::remove()
167 void tst_QBarSeries::remove()
168 {
168 {
169 int count = m_testSets.count();
169 int count = m_testSets.count();
170 QVERIFY(m_barseries_with_sets->count() == count);
170 QVERIFY(m_barseries_with_sets->count() == count);
171
171
172 // Try to remove null pointer (should not remove, should not crash)
172 // Try to remove null pointer (should not remove, should not crash)
173 bool ret = false;
173 bool ret = false;
174 ret = m_barseries_with_sets->remove(0);
174 ret = m_barseries_with_sets->remove(0);
175 QVERIFY(ret == false);
175 QVERIFY(ret == false);
176 QVERIFY(m_barseries_with_sets->count() == count);
176 QVERIFY(m_barseries_with_sets->count() == count);
177
177
178 // Try to remove invalid pointer (should not remove, should not crash)
178 // Try to remove invalid pointer (should not remove, should not crash)
179 ret = m_barseries_with_sets->remove((QBarSet*) (m_testSets.at(0) + 1) );
179 ret = m_barseries_with_sets->remove((QBarSet*) (m_testSets.at(0) + 1) );
180 QVERIFY(ret == false);
180 QVERIFY(ret == false);
181 QVERIFY(m_barseries_with_sets->count() == count);
181 QVERIFY(m_barseries_with_sets->count() == count);
182
182
183 // remove some sets
183 // remove some sets
184 ret = m_barseries_with_sets->remove(m_testSets.at(2));
184 ret = m_barseries_with_sets->remove(m_testSets.at(2));
185 QVERIFY(ret == true);
185 QVERIFY(ret == true);
186 ret = m_barseries_with_sets->remove(m_testSets.at(3));
186 ret = m_barseries_with_sets->remove(m_testSets.at(3));
187 QVERIFY(ret == true);
187 QVERIFY(ret == true);
188 ret = m_barseries_with_sets->remove(m_testSets.at(4));
188 ret = m_barseries_with_sets->remove(m_testSets.at(4));
189 QVERIFY(ret == true);
189 QVERIFY(ret == true);
190
190
191 QVERIFY(m_barseries_with_sets->count() == 2);
191 QVERIFY(m_barseries_with_sets->count() == 2);
192
192
193 QList<QBarSet*> verifysets = m_barseries_with_sets->barSets();
193 QList<QBarSet*> verifysets = m_barseries_with_sets->barSets();
194
194
195 QVERIFY(verifysets.at(0) == m_testSets.at(0));
195 QVERIFY(verifysets.at(0) == m_testSets.at(0));
196 QVERIFY(verifysets.at(1) == m_testSets.at(1));
196 QVERIFY(verifysets.at(1) == m_testSets.at(1));
197
197
198 // Try removing all sets again (should be ok, even if some sets have already been removed)
198 // Try removing all sets again (should be ok, even if some sets have already been removed)
199 ret = false;
199 ret = false;
200 for (int i=0; i<count; i++) {
200 for (int i=0; i<count; i++) {
201 ret |= m_barseries_with_sets->remove(m_testSets.at(i));
201 ret |= m_barseries_with_sets->remove(m_testSets.at(i));
202 }
202 }
203
203
204 QVERIFY(ret == true);
204 QVERIFY(ret == true);
205 QVERIFY(m_barseries_with_sets->count() == 0);
205 QVERIFY(m_barseries_with_sets->count() == 0);
206 }
206 }
207
207
208 void tst_QBarSeries::appendList_data()
208 void tst_QBarSeries::appendList_data()
209 {
209 {
210
210
211 }
211 }
212
212
213 void tst_QBarSeries::appendList()
213 void tst_QBarSeries::appendList()
214 {
214 {
215 int count = 5;
215 int count = 5;
216 QVERIFY(m_barseries->count() == 0);
216 QVERIFY(m_barseries->count() == 0);
217
217
218 QList<QBarSet*> sets;
218 QList<QBarSet*> sets;
219 for (int i=0; i<count; i++) {
219 for (int i=0; i<count; i++) {
220 sets.append(new QBarSet("testset"));
220 sets.append(new QBarSet("testset"));
221 }
221 }
222
222
223 // Append new sets (should succeed, count should match the count of sets)
223 // Append new sets (should succeed, count should match the count of sets)
224 bool ret = false;
224 bool ret = false;
225 ret = m_barseries->append(sets);
225 ret = m_barseries->append(sets);
226 QVERIFY(ret == true);
226 QVERIFY(ret == true);
227 QVERIFY(m_barseries->count() == count);
227 QVERIFY(m_barseries->count() == count);
228
228
229 // Append same sets again (should fail, count should remain same)
229 // Append same sets again (should fail, count should remain same)
230 ret = m_barseries->append(sets);
230 ret = m_barseries->append(sets);
231 QVERIFY(ret == false);
231 QVERIFY(ret == false);
232 QVERIFY(m_barseries->count() == count);
232 QVERIFY(m_barseries->count() == count);
233
233
234 // Try append empty list (should succeed, but count should remain same)
234 // Try append empty list (should succeed, but count should remain same)
235 QList<QBarSet*> invalidList;
235 QList<QBarSet*> invalidList;
236 ret = m_barseries->append(invalidList);
236 ret = m_barseries->append(invalidList);
237 QVERIFY(ret == true);
237 QVERIFY(ret == true);
238 QVERIFY(m_barseries->count() == count);
238 QVERIFY(m_barseries->count() == count);
239
239
240 // Try append list with one new and one existing set (should fail, count remains same)
240 // Try append list with one new and one existing set (should fail, count remains same)
241 invalidList.append(new QBarSet("ok set"));
241 invalidList.append(new QBarSet("ok set"));
242 invalidList.append(sets.at(0));
242 invalidList.append(sets.at(0));
243 ret = m_barseries->append(invalidList);
243 ret = m_barseries->append(invalidList);
244 QVERIFY(ret == false);
244 QVERIFY(ret == false);
245 QVERIFY(m_barseries->count() == count);
245 QVERIFY(m_barseries->count() == count);
246
246
247 // Try append list with null pointers (should fail, count remains same)
247 // Try append list with null pointers (should fail, count remains same)
248 QList<QBarSet*> invalidList2;
248 QList<QBarSet*> invalidList2;
249 invalidList2.append(0);
249 invalidList2.append(0);
250 invalidList2.append(0);
250 invalidList2.append(0);
251 invalidList2.append(0);
251 invalidList2.append(0);
252 ret = m_barseries->append(invalidList2);
252 ret = m_barseries->append(invalidList2);
253 QVERIFY(ret == false);
253 QVERIFY(ret == false);
254 QVERIFY(m_barseries->count() == count);
254 QVERIFY(m_barseries->count() == count);
255 }
255 }
256
256
257 void tst_QBarSeries::count_data()
257 void tst_QBarSeries::count_data()
258 {
258 {
259
259
260 }
260 }
261
261
262 void tst_QBarSeries::count()
262 void tst_QBarSeries::count()
263 {
263 {
264 QVERIFY(m_barseries->count() == 0);
264 QVERIFY(m_barseries->count() == 0);
265 QVERIFY(m_barseries_with_sets->count() == m_testSets.count());
265 QVERIFY(m_barseries_with_sets->count() == m_testSets.count());
266 }
266 }
267
267
268 void tst_QBarSeries::barSets_data()
268 void tst_QBarSeries::barSets_data()
269 {
269 {
270
270
271 }
271 }
272
272
273 void tst_QBarSeries::barSets()
273 void tst_QBarSeries::barSets()
274 {
274 {
275 QVERIFY(m_barseries->barSets().count() == 0);
275 QVERIFY(m_barseries->barSets().count() == 0);
276
276
277 QList<QBarSet*> sets = m_barseries_with_sets->barSets();
277 QList<QBarSet*> sets = m_barseries_with_sets->barSets();
278 QVERIFY(sets.count() == m_testSets.count());
278 QVERIFY(sets.count() == m_testSets.count());
279
279
280 for (int i=0; i<m_testSets.count(); i++) {
280 for (int i=0; i<m_testSets.count(); i++) {
281 QVERIFY(sets.at(i) == m_testSets.at(i));
281 QVERIFY(sets.at(i) == m_testSets.at(i));
282 }
282 }
283 }
283 }
284
284
285 void tst_QBarSeries::setLabelsVisible_data()
285 void tst_QBarSeries::setLabelsVisible_data()
286 {
286 {
287
287
288 }
288 }
289
289
290 void tst_QBarSeries::setLabelsVisible()
290 void tst_QBarSeries::setLabelsVisible()
291 {
291 {
292 // labels should be invisible by default
292 // labels should be invisible by default
293 QVERIFY(m_barseries->isLabelsVisible() == false);
293 QVERIFY(m_barseries->isLabelsVisible() == false);
294 QVERIFY(m_barseries_with_sets->isLabelsVisible() == false);
294 QVERIFY(m_barseries_with_sets->isLabelsVisible() == false);
295
295
296 // turn labels to visible
296 // turn labels to visible
297 m_barseries_with_sets->setLabelsVisible(true);
297 m_barseries_with_sets->setLabelsVisible(true);
298 // TODO: test the signal
298 // TODO: test the signal
299 QVERIFY(m_barseries_with_sets->isLabelsVisible() == true);
299 QVERIFY(m_barseries_with_sets->isLabelsVisible() == true);
300
300
301 // turn labels to invisible
301 // turn labels to invisible
302 m_barseries_with_sets->setLabelsVisible(false);
302 m_barseries_with_sets->setLabelsVisible(false);
303 // TODO: test the signal
303 // TODO: test the signal
304 QVERIFY(m_barseries_with_sets->isLabelsVisible() == false);
304 QVERIFY(m_barseries_with_sets->isLabelsVisible() == false);
305
305
306 // without parameter, should turn labels to visible
306 // without parameter, should turn labels to visible
307 m_barseries_with_sets->setLabelsVisible();
307 m_barseries_with_sets->setLabelsVisible();
308 // TODO: test the signal
308 // TODO: test the signal
309 QVERIFY(m_barseries_with_sets->isLabelsVisible() == true);
309 QVERIFY(m_barseries_with_sets->isLabelsVisible() == true);
310 }
310 }
311
311
312 void tst_QBarSeries::mouseclicked_data()
312 void tst_QBarSeries::mouseclicked_data()
313 {
313 {
314
314
315 }
315 }
316
316
317 void tst_QBarSeries::mouseclicked()
317 void tst_QBarSeries::mouseclicked()
318 {
318 {
319 QAbstractBarSeries* series = new QAbstractBarSeries();
319 QGroupedBarSeries* series = new QGroupedBarSeries();
320
320
321 QBarSet* set1 = new QBarSet(QString("set 1"));
321 QBarSet* set1 = new QBarSet(QString("set 1"));
322 // *set1 << QPointF(0,10) << QPointF(1,10) << QPointF(2,10);
323 *set1 << 10 << 10 << 10;
322 *set1 << 10 << 10 << 10;
324 series->append(set1);
323 series->append(set1);
325
324
326 QBarSet* set2 = new QBarSet(QString("set 2"));
325 QBarSet* set2 = new QBarSet(QString("set 2"));
327 // *set2 << QPointF(0.3,10) << QPointF(1.3,10) << QPointF(2.3,10);
328 *set2 << 10 << 10 << 10;
326 *set2 << 10 << 10 << 10;
329 series->append(set2);
327 series->append(set2);
330
328
331 QSignalSpy seriesSpy(series,SIGNAL(clicked(int,QBarSet*)));
329 QSignalSpy seriesSpy(series,SIGNAL(clicked(int,QBarSet*)));
332 QSignalSpy setSpy1(set1, SIGNAL(clicked(int)));
330 QSignalSpy setSpy1(set1, SIGNAL(clicked(int)));
333 QSignalSpy setSpy2(set2, SIGNAL(clicked(int)));
331 QSignalSpy setSpy2(set2, SIGNAL(clicked(int)));
334
332
335 QChartView view(new QChart());
333 QChartView view(new QChart());
336 view.resize(400,300);
334 view.resize(400,300);
337 view.chart()->addSeries(series);
335 view.chart()->addSeries(series);
338 view.show();
336 view.show();
339 QTest::qWaitForWindowShown(&view);
337 QTest::qWaitForWindowShown(&view);
340
338
341 //====================================================================================
339 //====================================================================================
342 // barset 1, bar 0
340 // barset 1, bar 0
343 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(102,142));
341 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(102,142));
344 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
342 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
345
343
346 QCOMPARE(seriesSpy.count(), 1);
344 QCOMPARE(seriesSpy.count(), 1);
347 QCOMPARE(setSpy1.count(), 1);
345 QCOMPARE(setSpy1.count(), 1);
348 QCOMPARE(setSpy2.count(), 0);
346 QCOMPARE(setSpy2.count(), 0);
349
347
350 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
348 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
351 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
349 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
352 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
350 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
353 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
351 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
354
352
355 QList<QVariant> setSpyArg = setSpy1.takeFirst();
353 QList<QVariant> setSpyArg = setSpy1.takeFirst();
356 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
354 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
357 QVERIFY(setSpyArg.at(0).toInt() == 0);
355 QVERIFY(setSpyArg.at(0).toInt() == 0);
358
356
359 //====================================================================================
357 //====================================================================================
360 // barset 1, bar 1
358 // barset 1, bar 1
361 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(186,142));
359 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(186,142));
362 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
360 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
363
361
364 QCOMPARE(seriesSpy.count(), 1);
362 QCOMPARE(seriesSpy.count(), 1);
365 QCOMPARE(setSpy1.count(), 1);
363 QCOMPARE(setSpy1.count(), 1);
366 QCOMPARE(setSpy2.count(), 0);
364 QCOMPARE(setSpy2.count(), 0);
367
365
368 seriesSpyArg = seriesSpy.takeFirst();
366 seriesSpyArg = seriesSpy.takeFirst();
369 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
367 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
370 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
368 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
371 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
369 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
372
370
373 setSpyArg = setSpy1.takeFirst();
371 setSpyArg = setSpy1.takeFirst();
374 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
372 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
375 QVERIFY(setSpyArg.at(0).toInt() == 1);
373 QVERIFY(setSpyArg.at(0).toInt() == 1);
376
374
377 //====================================================================================
375 //====================================================================================
378 // barset 1, bar 2
376 // barset 1, bar 2
379 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(271,142));
377 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(271,142));
380 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
378 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
381
379
382 QCOMPARE(seriesSpy.count(), 1);
380 QCOMPARE(seriesSpy.count(), 1);
383 QCOMPARE(setSpy1.count(), 1);
381 QCOMPARE(setSpy1.count(), 1);
384 QCOMPARE(setSpy2.count(), 0);
382 QCOMPARE(setSpy2.count(), 0);
385
383
386 seriesSpyArg = seriesSpy.takeFirst();
384 seriesSpyArg = seriesSpy.takeFirst();
387 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
385 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
388 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
386 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
389 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
387 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
390
388
391 setSpyArg = setSpy1.takeFirst();
389 setSpyArg = setSpy1.takeFirst();
392 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
390 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
393 QVERIFY(setSpyArg.at(0).toInt() == 2);
391 QVERIFY(setSpyArg.at(0).toInt() == 2);
394
392
395 //====================================================================================
393 //====================================================================================
396 // barset 2, bar 0
394 // barset 2, bar 0
397 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(127,142));
395 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(127,142));
398 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
396 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
399
397
400 QCOMPARE(seriesSpy.count(), 1);
398 QCOMPARE(seriesSpy.count(), 1);
401 QCOMPARE(setSpy1.count(), 0);
399 QCOMPARE(setSpy1.count(), 0);
402 QCOMPARE(setSpy2.count(), 1);
400 QCOMPARE(setSpy2.count(), 1);
403
401
404 seriesSpyArg = seriesSpy.takeFirst();
402 seriesSpyArg = seriesSpy.takeFirst();
405 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
403 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
406 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
404 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
407 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
405 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
408
406
409 setSpyArg = setSpy2.takeFirst();
407 setSpyArg = setSpy2.takeFirst();
410 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
408 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
411 QVERIFY(setSpyArg.at(0).toInt() == 0);
409 QVERIFY(setSpyArg.at(0).toInt() == 0);
412
410
413 //====================================================================================
411 //====================================================================================
414 // barset 2, bar 1
412 // barset 2, bar 1
415 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(212,142));
413 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(212,142));
416 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
414 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
417
415
418 QCOMPARE(seriesSpy.count(), 1);
416 QCOMPARE(seriesSpy.count(), 1);
419 QCOMPARE(setSpy1.count(), 0);
417 QCOMPARE(setSpy1.count(), 0);
420 QCOMPARE(setSpy2.count(), 1);
418 QCOMPARE(setSpy2.count(), 1);
421
419
422 seriesSpyArg = seriesSpy.takeFirst();
420 seriesSpyArg = seriesSpy.takeFirst();
423 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
421 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
424 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
422 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
425 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
423 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
426
424
427 setSpyArg = setSpy2.takeFirst();
425 setSpyArg = setSpy2.takeFirst();
428 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
426 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
429 QVERIFY(setSpyArg.at(0).toInt() == 1);
427 QVERIFY(setSpyArg.at(0).toInt() == 1);
430
428
431 //====================================================================================
429 //====================================================================================
432 // barset 2, bar 2
430 // barset 2, bar 2
433 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(296,142));
431 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(296,142));
434 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
432 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
435
433
436 QCOMPARE(seriesSpy.count(), 1);
434 QCOMPARE(seriesSpy.count(), 1);
437 QCOMPARE(setSpy1.count(), 0);
435 QCOMPARE(setSpy1.count(), 0);
438 QCOMPARE(setSpy2.count(), 1);
436 QCOMPARE(setSpy2.count(), 1);
439
437
440 seriesSpyArg = seriesSpy.takeFirst();
438 seriesSpyArg = seriesSpy.takeFirst();
441 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
439 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
442 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
440 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
443 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
441 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
444
442
445 setSpyArg = setSpy2.takeFirst();
443 setSpyArg = setSpy2.takeFirst();
446 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
444 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
447 QVERIFY(setSpyArg.at(0).toInt() == 2);
445 QVERIFY(setSpyArg.at(0).toInt() == 2);
448 }
446 }
449
447
450 void tst_QBarSeries::mousehovered_data()
448 void tst_QBarSeries::mousehovered_data()
451 {
449 {
452
450
453 }
451 }
454
452
455 void tst_QBarSeries::mousehovered()
453 void tst_QBarSeries::mousehovered()
456 {
454 {
457 QAbstractBarSeries* series = new QAbstractBarSeries();
455 QGroupedBarSeries* series = new QGroupedBarSeries();
458
456
459 QBarSet* set1 = new QBarSet(QString("set 1"));
457 QBarSet* set1 = new QBarSet(QString("set 1"));
460 // *set1 << QPointF(0,10) << QPointF(1,10) << QPointF(2,10);
461 *set1 << 10 << 10 << 10;
458 *set1 << 10 << 10 << 10;
462 series->append(set1);
459 series->append(set1);
463
460
464 QBarSet* set2 = new QBarSet(QString("set 2"));
461 QBarSet* set2 = new QBarSet(QString("set 2"));
465 // *set2 << QPointF(0.3,10) << QPointF(1.3,10) << QPointF(2.3,10);
466 *set2 << 10 << 10 << 10;
462 *set2 << 10 << 10 << 10;
467 series->append(set2);
463 series->append(set2);
468
464
469 QSignalSpy seriesSpy(series,SIGNAL(hovered(bool,QBarSet*)));
465 QSignalSpy seriesSpy(series,SIGNAL(hovered(bool,QBarSet*)));
470 QSignalSpy setSpy1(set1, SIGNAL(hovered(bool)));
466 QSignalSpy setSpy1(set1, SIGNAL(hovered(bool)));
471 QSignalSpy setSpy2(set2, SIGNAL(hovered(bool)));
467 QSignalSpy setSpy2(set2, SIGNAL(hovered(bool)));
472
468
473 QChartView view(new QChart());
469 QChartView view(new QChart());
474 view.resize(400,300);
470 view.resize(400,300);
475 view.chart()->addSeries(series);
471 view.chart()->addSeries(series);
476 view.show();
472 view.show();
477 QTest::qWaitForWindowShown(&view);
473 QTest::qWaitForWindowShown(&view);
478
474
479 //this is hack since view does not get events otherwise
475 //this is hack since view does not get events otherwise
480 view.setMouseTracking(true);
476 view.setMouseTracking(true);
481
477
482 //=======================================================================
478 //=======================================================================
483 // move mouse to left border
479 // move mouse to left border
484 QTest::mouseMove(view.viewport(), QPoint(0, 142));
480 QTest::mouseMove(view.viewport(), QPoint(0, 142));
485 QCoreApplication::processEvents(QEventLoop::AllEvents, 10000);
481 QCoreApplication::processEvents(QEventLoop::AllEvents, 10000);
486 TRY_COMPARE(seriesSpy.count(), 0);
482 TRY_COMPARE(seriesSpy.count(), 0);
487 TRY_COMPARE(setSpy1.count(), 0);
483 TRY_COMPARE(setSpy1.count(), 0);
488 TRY_COMPARE(setSpy2.count(), 0);
484 TRY_COMPARE(setSpy2.count(), 0);
489
485
490 //=======================================================================
486 //=======================================================================
491 // move mouse on top of set1
487 // move mouse on top of set1
492 QTest::mouseMove(view.viewport(), QPoint(102,142));
488 QTest::mouseMove(view.viewport(), QPoint(102,142));
493 TRY_COMPARE(seriesSpy.count(), 1);
489 TRY_COMPARE(seriesSpy.count(), 1);
494 TRY_COMPARE(setSpy1.count(), 1);
490 TRY_COMPARE(setSpy1.count(), 1);
495 TRY_COMPARE(setSpy2.count(), 0);
491 TRY_COMPARE(setSpy2.count(), 0);
496
492
497 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
493 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
498 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
494 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
499 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
495 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
500 QVERIFY(seriesSpyArg.at(0).toBool() == true);
496 QVERIFY(seriesSpyArg.at(0).toBool() == true);
501
497
502 QList<QVariant> setSpyArg = setSpy1.takeFirst();
498 QList<QVariant> setSpyArg = setSpy1.takeFirst();
503 QVERIFY(setSpyArg.at(0).type() == QVariant::Bool);
499 QVERIFY(setSpyArg.at(0).type() == QVariant::Bool);
504 QVERIFY(setSpyArg.at(0).toBool() == true);
500 QVERIFY(setSpyArg.at(0).toBool() == true);
505
501
506 //=======================================================================
502 //=======================================================================
507 // move mouse from top of set1 to top of set2
503 // move mouse from top of set1 to top of set2
508 QTest::mouseMove(view.viewport(), QPoint(127,142));
504 QTest::mouseMove(view.viewport(), QPoint(127,142));
509 TRY_COMPARE(seriesSpy.count(), 2);
505 TRY_COMPARE(seriesSpy.count(), 2);
510 TRY_COMPARE(setSpy1.count(), 1);
506 TRY_COMPARE(setSpy1.count(), 1);
511 TRY_COMPARE(setSpy2.count(), 1);
507 TRY_COMPARE(setSpy2.count(), 1);
512
508
513 // should leave set1
509 // should leave set1
514 seriesSpyArg = seriesSpy.takeFirst();
510 seriesSpyArg = seriesSpy.takeFirst();
515 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
511 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
516 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
512 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
517 QVERIFY(seriesSpyArg.at(0).toBool() == false);
513 QVERIFY(seriesSpyArg.at(0).toBool() == false);
518
514
519 setSpyArg = setSpy1.takeFirst();
515 setSpyArg = setSpy1.takeFirst();
520 QVERIFY(setSpyArg.at(0).type() == QVariant::Bool);
516 QVERIFY(setSpyArg.at(0).type() == QVariant::Bool);
521 QVERIFY(setSpyArg.at(0).toBool() == false);
517 QVERIFY(setSpyArg.at(0).toBool() == false);
522
518
523 // should enter set2
519 // should enter set2
524 seriesSpyArg = seriesSpy.takeFirst();
520 seriesSpyArg = seriesSpy.takeFirst();
525 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
521 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
526 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
522 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
527 QVERIFY(seriesSpyArg.at(0).toBool() == true);
523 QVERIFY(seriesSpyArg.at(0).toBool() == true);
528
524
529 setSpyArg = setSpy2.takeFirst();
525 setSpyArg = setSpy2.takeFirst();
530 QVERIFY(setSpyArg.at(0).type() == QVariant::Bool);
526 QVERIFY(setSpyArg.at(0).type() == QVariant::Bool);
531 QVERIFY(setSpyArg.at(0).toBool() == true);
527 QVERIFY(setSpyArg.at(0).toBool() == true);
532
528
533 //=======================================================================
529 //=======================================================================
534 // move mouse from top of set2 to background
530 // move mouse from top of set2 to background
535 QTest::mouseMove(view.viewport(), QPoint(127,0));
531 QTest::mouseMove(view.viewport(), QPoint(127,0));
536 TRY_COMPARE(seriesSpy.count(), 1);
532 TRY_COMPARE(seriesSpy.count(), 1);
537 TRY_COMPARE(setSpy1.count(), 0);
533 TRY_COMPARE(setSpy1.count(), 0);
538 TRY_COMPARE(setSpy2.count(), 1);
534 TRY_COMPARE(setSpy2.count(), 1);
539
535
540 // should leave set2
536 // should leave set2
541 seriesSpyArg = seriesSpy.takeFirst();
537 seriesSpyArg = seriesSpy.takeFirst();
542 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
538 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
543 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
539 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
544 QVERIFY(seriesSpyArg.at(0).toBool() == false);
540 QVERIFY(seriesSpyArg.at(0).toBool() == false);
545
541
546 setSpyArg = setSpy2.takeFirst();
542 setSpyArg = setSpy2.takeFirst();
547 QVERIFY(setSpyArg.at(0).type() == QVariant::Bool);
543 QVERIFY(setSpyArg.at(0).type() == QVariant::Bool);
548 QVERIFY(setSpyArg.at(0).toBool() == false);
544 QVERIFY(setSpyArg.at(0).toBool() == false);
549 }
545 }
550
546
551 void tst_QBarSeries::clearWithAnimations()
547 void tst_QBarSeries::clearWithAnimations()
552 {
548 {
553 QAbstractBarSeries* series = new QAbstractBarSeries();
549 QGroupedBarSeries* series = new QGroupedBarSeries();
554
550
555 QBarSet* set1 = new QBarSet(QString("set 1"));
551 QBarSet* set1 = new QBarSet(QString("set 1"));
556 // *set1 << QPointF(0,10) << QPointF(1,10) << QPointF(2,10);
557 *set1 << 10 << 10 << 10;
552 *set1 << 10 << 10 << 10;
558 series->append(set1);
553 series->append(set1);
559
554
560 QBarSet* set2 = new QBarSet(QString("set 2"));
555 QBarSet* set2 = new QBarSet(QString("set 2"));
561 // *set2 << QPointF(0.3,10) << QPointF(1.3,10) << QPointF(2.3,10);
562 *set2 << 10 << 10 << 10;
556 *set2 << 10 << 10 << 10;
563 series->append(set2);
557 series->append(set2);
564
558
565 QChartView view(new QChart());
559 QChartView view(new QChart());
566 view.resize(400,300);
560 view.resize(400,300);
567 view.chart()->setAnimationOptions(QChart::SeriesAnimations);
561 view.chart()->setAnimationOptions(QChart::SeriesAnimations);
568 view.chart()->addSeries(series);
562 view.chart()->addSeries(series);
569 view.show();
563 view.show();
570
564
571 series->clear();
565 series->clear();
572 }
566 }
573
567
574 QTEST_MAIN(tst_QBarSeries)
568 QTEST_MAIN(tst_QBarSeries)
575
569
576 #include "tst_qbarseries.moc"
570 #include "tst_qbarseries.moc"
577
571
@@ -1,614 +1,615
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include <QtTest/QtTest>
21 #include <QtTest/QtTest>
22 #include <qchartview.h>
22 #include <qchartview.h>
23 #include <qlineseries.h>
23 #include <qlineseries.h>
24 #include <qareaseries.h>
24 #include <qareaseries.h>
25 #include <qscatterseries.h>
25 #include <qscatterseries.h>
26 #include <qsplineseries.h>
26 #include <qsplineseries.h>
27 #include <qpieseries.h>
27 #include <qpieseries.h>
28 #include <qabstractbarseries.h>
28 #include <qabstractbarseries.h>
29 #include <qgroupedbarseries.h>
29 #include <qpercentbarseries.h>
30 #include <qpercentbarseries.h>
30 #include <qstackedbarseries.h>
31 #include <qstackedbarseries.h>
31 #include <qvaluesaxis.h>
32 #include <qvaluesaxis.h>
32
33
33 QTCOMMERCIALCHART_USE_NAMESPACE
34 QTCOMMERCIALCHART_USE_NAMESPACE
34
35
35 Q_DECLARE_METATYPE(QAbstractAxis *)
36 Q_DECLARE_METATYPE(QAbstractAxis *)
36 Q_DECLARE_METATYPE(QValuesAxis *)
37 Q_DECLARE_METATYPE(QValuesAxis *)
37 Q_DECLARE_METATYPE(QAbstractSeries *)
38 Q_DECLARE_METATYPE(QAbstractSeries *)
38 Q_DECLARE_METATYPE(QChart::AnimationOption)
39 Q_DECLARE_METATYPE(QChart::AnimationOption)
39 Q_DECLARE_METATYPE(QBrush)
40 Q_DECLARE_METATYPE(QBrush)
40 Q_DECLARE_METATYPE(QPen)
41 Q_DECLARE_METATYPE(QPen)
41 Q_DECLARE_METATYPE(QChart::ChartTheme)
42 Q_DECLARE_METATYPE(QChart::ChartTheme)
42
43
43 class tst_QChart : public QObject
44 class tst_QChart : public QObject
44 {
45 {
45 Q_OBJECT
46 Q_OBJECT
46
47
47 public slots:
48 public slots:
48 void initTestCase();
49 void initTestCase();
49 void cleanupTestCase();
50 void cleanupTestCase();
50 void init();
51 void init();
51 void cleanup();
52 void cleanup();
52
53
53 private slots:
54 private slots:
54 void qchart_data();
55 void qchart_data();
55 void qchart();
56 void qchart();
56
57
57 void addSeries_data();
58 void addSeries_data();
58 void addSeries();
59 void addSeries();
59 void animationOptions_data();
60 void animationOptions_data();
60 void animationOptions();
61 void animationOptions();
61 void axisX_data();
62 void axisX_data();
62 void axisX();
63 void axisX();
63 void axisY_data();
64 void axisY_data();
64 void axisY();
65 void axisY();
65 void backgroundBrush_data();
66 void backgroundBrush_data();
66 void backgroundBrush();
67 void backgroundBrush();
67 void backgroundPen_data();
68 void backgroundPen_data();
68 void backgroundPen();
69 void backgroundPen();
69 void isBackgroundVisible_data();
70 void isBackgroundVisible_data();
70 void isBackgroundVisible();
71 void isBackgroundVisible();
71 void legend_data();
72 void legend_data();
72 void legend();
73 void legend();
73 void margins_data();
74 void margins_data();
74 void margins();
75 void margins();
75 void removeAllSeries_data();
76 void removeAllSeries_data();
76 void removeAllSeries();
77 void removeAllSeries();
77 void removeSeries_data();
78 void removeSeries_data();
78 void removeSeries();
79 void removeSeries();
79 void scroll_data();
80 void scroll_data();
80 void scroll();
81 void scroll();
81 void theme_data();
82 void theme_data();
82 void theme();
83 void theme();
83 void title_data();
84 void title_data();
84 void title();
85 void title();
85 void titleBrush_data();
86 void titleBrush_data();
86 void titleBrush();
87 void titleBrush();
87 void titleFont_data();
88 void titleFont_data();
88 void titleFont();
89 void titleFont();
89 void zoomIn_data();
90 void zoomIn_data();
90 void zoomIn();
91 void zoomIn();
91 void zoomOut_data();
92 void zoomOut_data();
92 void zoomOut();
93 void zoomOut();
93
94
94 private:
95 private:
95 void createTestData();
96 void createTestData();
96
97
97 private:
98 private:
98 QChartView* m_view;
99 QChartView* m_view;
99 QChart* m_chart;
100 QChart* m_chart;
100 };
101 };
101
102
102 void tst_QChart::initTestCase()
103 void tst_QChart::initTestCase()
103 {
104 {
104
105
105 }
106 }
106
107
107 void tst_QChart::cleanupTestCase()
108 void tst_QChart::cleanupTestCase()
108 {
109 {
109
110
110 }
111 }
111
112
112 void tst_QChart::init()
113 void tst_QChart::init()
113 {
114 {
114 m_view = new QChartView(new QChart());
115 m_view = new QChartView(new QChart());
115 m_chart = m_view->chart();
116 m_chart = m_view->chart();
116 }
117 }
117
118
118 void tst_QChart::createTestData()
119 void tst_QChart::createTestData()
119 {
120 {
120 QLineSeries* series0 = new QLineSeries(this);
121 QLineSeries* series0 = new QLineSeries(this);
121 *series0 << QPointF(0, 0) << QPointF(100, 100);
122 *series0 << QPointF(0, 0) << QPointF(100, 100);
122 m_chart->addSeries(series0);
123 m_chart->addSeries(series0);
123 m_view->show();
124 m_view->show();
124 QTest::qWaitForWindowShown(m_view);
125 QTest::qWaitForWindowShown(m_view);
125 }
126 }
126
127
127 void tst_QChart::cleanup()
128 void tst_QChart::cleanup()
128 {
129 {
129 delete m_view;
130 delete m_view;
130 m_view = 0;
131 m_view = 0;
131 m_chart = 0;
132 m_chart = 0;
132 }
133 }
133
134
134 void tst_QChart::qchart_data()
135 void tst_QChart::qchart_data()
135 {
136 {
136 }
137 }
137
138
138 void tst_QChart::qchart()
139 void tst_QChart::qchart()
139 {
140 {
140 QVERIFY(m_chart);
141 QVERIFY(m_chart);
141 QVERIFY(m_chart->legend());
142 QVERIFY(m_chart->legend());
142 QVERIFY(m_chart->legend()->isVisible());
143 QVERIFY(m_chart->legend()->isVisible());
143
144
144 QCOMPARE(m_chart->animationOptions(), QChart::NoAnimation);
145 QCOMPARE(m_chart->animationOptions(), QChart::NoAnimation);
145 QVERIFY(m_chart->axisX());
146 QVERIFY(m_chart->axisX());
146 QVERIFY(m_chart->axisY());
147 QVERIFY(m_chart->axisY());
147 QVERIFY(m_chart->backgroundBrush()!=QBrush());
148 QVERIFY(m_chart->backgroundBrush()!=QBrush());
148 QVERIFY(m_chart->backgroundPen()!=QPen());
149 QVERIFY(m_chart->backgroundPen()!=QPen());
149 QCOMPARE(m_chart->isBackgroundVisible(), true);
150 QCOMPARE(m_chart->isBackgroundVisible(), true);
150
151
151 QVERIFY(m_chart->margins().top()>0);
152 QVERIFY(m_chart->margins().top()>0);
152 QVERIFY(m_chart->margins().left()>0);
153 QVERIFY(m_chart->margins().left()>0);
153 QVERIFY(m_chart->margins().right()>0);
154 QVERIFY(m_chart->margins().right()>0);
154 QVERIFY(m_chart->margins().bottom()>0);
155 QVERIFY(m_chart->margins().bottom()>0);
155
156
156 QCOMPARE(m_chart->theme(), QChart::ChartThemeLight);
157 QCOMPARE(m_chart->theme(), QChart::ChartThemeLight);
157 QCOMPARE(m_chart->title(), QString());
158 QCOMPARE(m_chart->title(), QString());
158
159
159 //QCOMPARE(m_chart->titleBrush(),QBrush());
160 //QCOMPARE(m_chart->titleBrush(),QBrush());
160 //QCOMPARE(m_chart->titleFont(),QFont());
161 //QCOMPARE(m_chart->titleFont(),QFont());
161
162
162 m_chart->removeAllSeries();
163 m_chart->removeAllSeries();
163 m_chart->scroll(0,0);
164 m_chart->scroll(0,0);
164
165
165 m_chart->zoomIn();
166 m_chart->zoomIn();
166 m_chart->zoomIn(QRectF());
167 m_chart->zoomIn(QRectF());
167 m_chart->zoomOut();
168 m_chart->zoomOut();
168 }
169 }
169
170
170 void tst_QChart::addSeries_data()
171 void tst_QChart::addSeries_data()
171 {
172 {
172 QTest::addColumn<QAbstractSeries *>("series");
173 QTest::addColumn<QAbstractSeries *>("series");
173 QTest::addColumn<QAbstractAxis *>("axis");
174 QTest::addColumn<QAbstractAxis *>("axis");
174
175
175 QAbstractSeries* series0 = new QLineSeries(this);
176 QAbstractSeries* series0 = new QLineSeries(this);
176 QAbstractSeries* series1 = new QAreaSeries(static_cast<QLineSeries*>(series0));
177 QAbstractSeries* series1 = new QAreaSeries(static_cast<QLineSeries*>(series0));
177 QAbstractSeries* series2 = new QScatterSeries(this);
178 QAbstractSeries* series2 = new QScatterSeries(this);
178 QAbstractSeries* series3 = new QSplineSeries(this);
179 QAbstractSeries* series3 = new QSplineSeries(this);
179 QAbstractSeries* series4 = new QPieSeries(this);
180 QAbstractSeries* series4 = new QPieSeries(this);
180 QAbstractSeries* series5 = new QAbstractBarSeries(this);
181 QAbstractSeries* series5 = new QGroupedBarSeries(this);
181 QAbstractSeries* series6 = new QPercentBarSeries(this);
182 QAbstractSeries* series6 = new QPercentBarSeries(this);
182 QAbstractSeries* series7 = new QStackedBarSeries(this);
183 QAbstractSeries* series7 = new QStackedBarSeries(this);
183
184
184 QValuesAxis* axis = new QValuesAxis(this);
185 QValuesAxis* axis = new QValuesAxis(this);
185
186
186 QTest::newRow("default axis: lineSeries") << series0 << (QAbstractAxis*) 0;
187 QTest::newRow("default axis: lineSeries") << series0 << (QAbstractAxis*) 0;
187 QTest::newRow("axis0: lineSeries") << series0 << axis;
188 QTest::newRow("axis0: lineSeries") << series0 << axis;
188 QTest::newRow("default axis: areaSeries") << series1 << (QAbstractAxis*) 0;
189 QTest::newRow("default axis: areaSeries") << series1 << (QAbstractAxis*) 0;
189 QTest::newRow("axis: areaSeries") << series1 << axis;
190 QTest::newRow("axis: areaSeries") << series1 << axis;
190 QTest::newRow("default axis: scatterSeries") << series2 << (QAbstractAxis*) 0;
191 QTest::newRow("default axis: scatterSeries") << series2 << (QAbstractAxis*) 0;
191 QTest::newRow("axis1: scatterSeries") << series2 << axis;
192 QTest::newRow("axis1: scatterSeries") << series2 << axis;
192 QTest::newRow("default axis: splineSeries") << series3 << (QAbstractAxis*) 0;
193 QTest::newRow("default axis: splineSeries") << series3 << (QAbstractAxis*) 0;
193 QTest::newRow("axis: splineSeries") << series3 << axis;
194 QTest::newRow("axis: splineSeries") << series3 << axis;
194 QTest::newRow("default axis: pieSeries") << series4 << (QAbstractAxis*) 0;
195 QTest::newRow("default axis: pieSeries") << series4 << (QAbstractAxis*) 0;
195 QTest::newRow("axis: pieSeries") << series4 << axis;
196 QTest::newRow("axis: pieSeries") << series4 << axis;
196 QTest::newRow("default axis: barSeries") << series5 << (QAbstractAxis*) 0;
197 QTest::newRow("default axis: barSeries") << series5 << (QAbstractAxis*) 0;
197 QTest::newRow("axis: barSeries") << series5 << axis;
198 QTest::newRow("axis: barSeries") << series5 << axis;
198 QTest::newRow("default axis: percentBarSeries") << series6 << (QAbstractAxis*) 0;
199 QTest::newRow("default axis: percentBarSeries") << series6 << (QAbstractAxis*) 0;
199 QTest::newRow("axis: barSeries") << series6 << axis;
200 QTest::newRow("axis: barSeries") << series6 << axis;
200 QTest::newRow("default axis: stackedBarSeries") << series7 << (QAbstractAxis*) 0;
201 QTest::newRow("default axis: stackedBarSeries") << series7 << (QAbstractAxis*) 0;
201 QTest::newRow("axis: barSeries") << series7 << axis;
202 QTest::newRow("axis: barSeries") << series7 << axis;
202
203
203 }
204 }
204
205
205 void tst_QChart::addSeries()
206 void tst_QChart::addSeries()
206 {
207 {
207 QFETCH(QAbstractSeries *, series);
208 QFETCH(QAbstractSeries *, series);
208 QFETCH(QAbstractAxis *, axis);
209 QFETCH(QAbstractAxis *, axis);
209 m_view->show();
210 m_view->show();
210 QTest::qWaitForWindowShown(m_view);
211 QTest::qWaitForWindowShown(m_view);
211 if(!axis) axis = m_chart->axisY();
212 if(!axis) axis = m_chart->axisY();
212 QVERIFY(!series->chart());
213 QVERIFY(!series->chart());
213 QCOMPARE(m_chart->series().count(), 0);
214 QCOMPARE(m_chart->series().count(), 0);
214 m_chart->addSeries(series);
215 m_chart->addSeries(series);
215 m_chart->setAxisY(axis,series);
216 m_chart->setAxisY(axis,series);
216 QCOMPARE(m_chart->series().count(), 1);
217 QCOMPARE(m_chart->series().count(), 1);
217 QCOMPARE(m_chart->series().first(), series);
218 QCOMPARE(m_chart->series().first(), series);
218 QVERIFY(series->chart() == m_chart);
219 QVERIFY(series->chart() == m_chart);
219 QCOMPARE(m_chart->axisY(series),axis);
220 QCOMPARE(m_chart->axisY(series),axis);
220 m_chart->removeSeries(series);
221 m_chart->removeSeries(series);
221 QVERIFY(!series->chart());
222 QVERIFY(!series->chart());
222 QCOMPARE(m_chart->series().count(), 0);
223 QCOMPARE(m_chart->series().count(), 0);
223 }
224 }
224
225
225 void tst_QChart::animationOptions_data()
226 void tst_QChart::animationOptions_data()
226 {
227 {
227 QTest::addColumn<QChart::AnimationOption>("animationOptions");
228 QTest::addColumn<QChart::AnimationOption>("animationOptions");
228 QTest::newRow("AllAnimations") << QChart::AllAnimations;
229 QTest::newRow("AllAnimations") << QChart::AllAnimations;
229 QTest::newRow("NoAnimation") << QChart::NoAnimation;
230 QTest::newRow("NoAnimation") << QChart::NoAnimation;
230 QTest::newRow("GridAxisAnimations") << QChart::GridAxisAnimations;
231 QTest::newRow("GridAxisAnimations") << QChart::GridAxisAnimations;
231 QTest::newRow("SeriesAnimations") << QChart::SeriesAnimations;
232 QTest::newRow("SeriesAnimations") << QChart::SeriesAnimations;
232 }
233 }
233
234
234 void tst_QChart::animationOptions()
235 void tst_QChart::animationOptions()
235 {
236 {
236 createTestData();
237 createTestData();
237 QFETCH(QChart::AnimationOption, animationOptions);
238 QFETCH(QChart::AnimationOption, animationOptions);
238 m_chart->setAnimationOptions(animationOptions);
239 m_chart->setAnimationOptions(animationOptions);
239 QCOMPARE(m_chart->animationOptions(), animationOptions);
240 QCOMPARE(m_chart->animationOptions(), animationOptions);
240 }
241 }
241
242
242 void tst_QChart::axisX_data()
243 void tst_QChart::axisX_data()
243 {
244 {
244
245
245 }
246 }
246
247
247 void tst_QChart::axisX()
248 void tst_QChart::axisX()
248 {
249 {
249 QVERIFY(m_chart->axisX());
250 QVERIFY(m_chart->axisX());
250 QAbstractAxis* axis = m_chart->axisX();
251 QAbstractAxis* axis = m_chart->axisX();
251 createTestData();
252 createTestData();
252 //it should be the same axis
253 //it should be the same axis
253 QCOMPARE(axis,m_chart->axisX());
254 QCOMPARE(axis,m_chart->axisX());
254 }
255 }
255
256
256 void tst_QChart::axisY_data()
257 void tst_QChart::axisY_data()
257 {
258 {
258 QTest::addColumn<QAbstractAxis*>("axis0");
259 QTest::addColumn<QAbstractAxis*>("axis0");
259 QTest::addColumn<QAbstractAxis*>("axis1");
260 QTest::addColumn<QAbstractAxis*>("axis1");
260 QTest::addColumn<QAbstractAxis*>("axis2");
261 QTest::addColumn<QAbstractAxis*>("axis2");
261 QTest::newRow("1 defualt, 2 optional") << (QAbstractAxis*)0 << new QValuesAxis() << new QValuesAxis();
262 QTest::newRow("1 defualt, 2 optional") << (QAbstractAxis*)0 << new QValuesAxis() << new QValuesAxis();
262 QTest::newRow("3 optional") << new QValuesAxis() << new QValuesAxis() << new QValuesAxis();
263 QTest::newRow("3 optional") << new QValuesAxis() << new QValuesAxis() << new QValuesAxis();
263 }
264 }
264
265
265
266
266 void tst_QChart::axisY()
267 void tst_QChart::axisY()
267 {
268 {
268 QFETCH(QAbstractAxis*, axis0);
269 QFETCH(QAbstractAxis*, axis0);
269 QFETCH(QAbstractAxis*, axis1);
270 QFETCH(QAbstractAxis*, axis1);
270 QFETCH(QAbstractAxis*, axis2);
271 QFETCH(QAbstractAxis*, axis2);
271
272
272 QAbstractAxis* defaultAxisY = m_chart->axisY();
273 QAbstractAxis* defaultAxisY = m_chart->axisY();
273
274
274 QVERIFY2(defaultAxisY, "Missing axisY.");
275 QVERIFY2(defaultAxisY, "Missing axisY.");
275
276
276 QLineSeries* series0 = new QLineSeries();
277 QLineSeries* series0 = new QLineSeries();
277 m_chart->addSeries(series0);
278 m_chart->addSeries(series0);
278 m_chart->setAxisY(axis0,series0);
279 m_chart->setAxisY(axis0,series0);
279
280
280 QLineSeries* series1 = new QLineSeries();
281 QLineSeries* series1 = new QLineSeries();
281 m_chart->addSeries(series1);
282 m_chart->addSeries(series1);
282 m_chart->setAxisY(axis1,series1);
283 m_chart->setAxisY(axis1,series1);
283
284
284 QLineSeries* series2 = new QLineSeries();
285 QLineSeries* series2 = new QLineSeries();
285 m_chart->addSeries(series2);
286 m_chart->addSeries(series2);
286 m_chart->setAxisY(axis2,series2);
287 m_chart->setAxisY(axis2,series2);
287
288
288 if (!axis0)
289 if (!axis0)
289 axis0 = defaultAxisY;
290 axis0 = defaultAxisY;
290 if (!axis1)
291 if (!axis1)
291 axis1 = defaultAxisY;
292 axis1 = defaultAxisY;
292 if (!axis2)
293 if (!axis2)
293 axis2 = defaultAxisY;
294 axis2 = defaultAxisY;
294
295
295 QVERIFY(m_chart->axisY(series0) == axis0);
296 QVERIFY(m_chart->axisY(series0) == axis0);
296 QVERIFY(m_chart->axisY(series1) == axis1);
297 QVERIFY(m_chart->axisY(series1) == axis1);
297 QVERIFY(m_chart->axisY(series2) == axis2);
298 QVERIFY(m_chart->axisY(series2) == axis2);
298 }
299 }
299
300
300 void tst_QChart::backgroundBrush_data()
301 void tst_QChart::backgroundBrush_data()
301 {
302 {
302 QTest::addColumn<QBrush>("backgroundBrush");
303 QTest::addColumn<QBrush>("backgroundBrush");
303 QTest::newRow("null") << QBrush();
304 QTest::newRow("null") << QBrush();
304 QTest::newRow("blue") << QBrush(Qt::blue);
305 QTest::newRow("blue") << QBrush(Qt::blue);
305 QTest::newRow("white") << QBrush(Qt::white);
306 QTest::newRow("white") << QBrush(Qt::white);
306 QTest::newRow("black") << QBrush(Qt::black);
307 QTest::newRow("black") << QBrush(Qt::black);
307 }
308 }
308
309
309 void tst_QChart::backgroundBrush()
310 void tst_QChart::backgroundBrush()
310 {
311 {
311 QFETCH(QBrush, backgroundBrush);
312 QFETCH(QBrush, backgroundBrush);
312 m_chart->setBackgroundBrush(backgroundBrush);
313 m_chart->setBackgroundBrush(backgroundBrush);
313 QCOMPARE(m_chart->backgroundBrush(), backgroundBrush);
314 QCOMPARE(m_chart->backgroundBrush(), backgroundBrush);
314 }
315 }
315
316
316 void tst_QChart::backgroundPen_data()
317 void tst_QChart::backgroundPen_data()
317 {
318 {
318 QTest::addColumn<QPen>("backgroundPen");
319 QTest::addColumn<QPen>("backgroundPen");
319 QTest::newRow("null") << QPen();
320 QTest::newRow("null") << QPen();
320 QTest::newRow("blue") << QPen(Qt::blue);
321 QTest::newRow("blue") << QPen(Qt::blue);
321 QTest::newRow("white") << QPen(Qt::white);
322 QTest::newRow("white") << QPen(Qt::white);
322 QTest::newRow("black") << QPen(Qt::black);
323 QTest::newRow("black") << QPen(Qt::black);
323 }
324 }
324
325
325
326
326 void tst_QChart::backgroundPen()
327 void tst_QChart::backgroundPen()
327 {
328 {
328 QFETCH(QPen, backgroundPen);
329 QFETCH(QPen, backgroundPen);
329 m_chart->setBackgroundPen(backgroundPen);
330 m_chart->setBackgroundPen(backgroundPen);
330 QCOMPARE(m_chart->backgroundPen(), backgroundPen);
331 QCOMPARE(m_chart->backgroundPen(), backgroundPen);
331 }
332 }
332
333
333 void tst_QChart::isBackgroundVisible_data()
334 void tst_QChart::isBackgroundVisible_data()
334 {
335 {
335 QTest::addColumn<bool>("isBackgroundVisible");
336 QTest::addColumn<bool>("isBackgroundVisible");
336 QTest::newRow("true") << true;
337 QTest::newRow("true") << true;
337 QTest::newRow("false") << false;
338 QTest::newRow("false") << false;
338 }
339 }
339
340
340 void tst_QChart::isBackgroundVisible()
341 void tst_QChart::isBackgroundVisible()
341 {
342 {
342 QFETCH(bool, isBackgroundVisible);
343 QFETCH(bool, isBackgroundVisible);
343 m_chart->setBackgroundVisible(isBackgroundVisible);
344 m_chart->setBackgroundVisible(isBackgroundVisible);
344 QCOMPARE(m_chart->isBackgroundVisible(), isBackgroundVisible);
345 QCOMPARE(m_chart->isBackgroundVisible(), isBackgroundVisible);
345 }
346 }
346
347
347 void tst_QChart::legend_data()
348 void tst_QChart::legend_data()
348 {
349 {
349
350
350 }
351 }
351
352
352 void tst_QChart::legend()
353 void tst_QChart::legend()
353 {
354 {
354 QLegend *legend = m_chart->legend();
355 QLegend *legend = m_chart->legend();
355 QVERIFY(legend);
356 QVERIFY(legend);
356
357
357 // Colors related signals
358 // Colors related signals
358 QSignalSpy colorSpy(legend, SIGNAL(colorChanged(QColor)));
359 QSignalSpy colorSpy(legend, SIGNAL(colorChanged(QColor)));
359 QSignalSpy borderColorSpy(legend, SIGNAL(borderColorChanged(QColor)));
360 QSignalSpy borderColorSpy(legend, SIGNAL(borderColorChanged(QColor)));
360 QSignalSpy labelColorSpy(legend, SIGNAL(labelColorChanged(QColor)));
361 QSignalSpy labelColorSpy(legend, SIGNAL(labelColorChanged(QColor)));
361
362
362 // colorChanged
363 // colorChanged
363 legend->setColor(QColor("aliceblue"));
364 legend->setColor(QColor("aliceblue"));
364 QCOMPARE(colorSpy.count(), 1);
365 QCOMPARE(colorSpy.count(), 1);
365 QBrush b = legend->brush();
366 QBrush b = legend->brush();
366 b.setColor(QColor("aqua"));
367 b.setColor(QColor("aqua"));
367 legend->setBrush(b);
368 legend->setBrush(b);
368 QCOMPARE(colorSpy.count(), 2);
369 QCOMPARE(colorSpy.count(), 2);
369
370
370 // borderColorChanged
371 // borderColorChanged
371 legend->setBorderColor(QColor("aliceblue"));
372 legend->setBorderColor(QColor("aliceblue"));
372 QCOMPARE(borderColorSpy.count(), 1);
373 QCOMPARE(borderColorSpy.count(), 1);
373 QPen p = legend->pen();
374 QPen p = legend->pen();
374 p.setColor(QColor("aqua"));
375 p.setColor(QColor("aqua"));
375 legend->setPen(p);
376 legend->setPen(p);
376 QCOMPARE(borderColorSpy.count(), 2);
377 QCOMPARE(borderColorSpy.count(), 2);
377
378
378 // labelColorChanged
379 // labelColorChanged
379 legend->setLabelColor(QColor("lightsalmon"));
380 legend->setLabelColor(QColor("lightsalmon"));
380 QCOMPARE(labelColorSpy.count(), 1);
381 QCOMPARE(labelColorSpy.count(), 1);
381 b = legend->labelBrush();
382 b = legend->labelBrush();
382 b.setColor(QColor("lightseagreen"));
383 b.setColor(QColor("lightseagreen"));
383 legend->setLabelBrush(b);
384 legend->setLabelBrush(b);
384 QCOMPARE(labelColorSpy.count(), 2);
385 QCOMPARE(labelColorSpy.count(), 2);
385
386
386 // fontChanged
387 // fontChanged
387 QSignalSpy fontSpy(legend, SIGNAL(fontChanged(QFont)));
388 QSignalSpy fontSpy(legend, SIGNAL(fontChanged(QFont)));
388 QFont f = legend->font();
389 QFont f = legend->font();
389 f.setBold(!f.bold());
390 f.setBold(!f.bold());
390 legend->setFont(f);
391 legend->setFont(f);
391 QCOMPARE(fontSpy.count(), 1);
392 QCOMPARE(fontSpy.count(), 1);
392 }
393 }
393
394
394 void tst_QChart::margins_data()
395 void tst_QChart::margins_data()
395 {
396 {
396
397
397 }
398 }
398
399
399 void tst_QChart::margins()
400 void tst_QChart::margins()
400 {
401 {
401 createTestData();
402 createTestData();
402 QRectF rect = m_chart->geometry();
403 QRectF rect = m_chart->geometry();
403
404
404 QVERIFY(m_chart->margins().top()+m_chart->margins().bottom() < rect.height());
405 QVERIFY(m_chart->margins().top()+m_chart->margins().bottom() < rect.height());
405 QVERIFY(m_chart->margins().left()+m_chart->margins().right() < rect.width());
406 QVERIFY(m_chart->margins().left()+m_chart->margins().right() < rect.width());
406 }
407 }
407
408
408 void tst_QChart::removeAllSeries_data()
409 void tst_QChart::removeAllSeries_data()
409 {
410 {
410
411
411 }
412 }
412
413
413 void tst_QChart::removeAllSeries()
414 void tst_QChart::removeAllSeries()
414 {
415 {
415 QLineSeries* series0 = new QLineSeries(this);
416 QLineSeries* series0 = new QLineSeries(this);
416 QLineSeries* series1 = new QLineSeries(this);
417 QLineSeries* series1 = new QLineSeries(this);
417 QLineSeries* series2 = new QLineSeries(this);
418 QLineSeries* series2 = new QLineSeries(this);
418 QSignalSpy deleteSpy1(series0, SIGNAL(destroyed()));
419 QSignalSpy deleteSpy1(series0, SIGNAL(destroyed()));
419 QSignalSpy deleteSpy2(series1, SIGNAL(destroyed()));
420 QSignalSpy deleteSpy2(series1, SIGNAL(destroyed()));
420 QSignalSpy deleteSpy3(series2, SIGNAL(destroyed()));
421 QSignalSpy deleteSpy3(series2, SIGNAL(destroyed()));
421
422
422 m_chart->addSeries(series0);
423 m_chart->addSeries(series0);
423 m_chart->addSeries(series1);
424 m_chart->addSeries(series1);
424 m_chart->addSeries(series2);
425 m_chart->addSeries(series2);
425 m_view->show();
426 m_view->show();
426 QTest::qWaitForWindowShown(m_view);
427 QTest::qWaitForWindowShown(m_view);
427
428
428 QVERIFY(m_chart->axisY(series0)!=0);
429 QVERIFY(m_chart->axisY(series0)!=0);
429 QVERIFY(m_chart->axisY(series1)!=0);
430 QVERIFY(m_chart->axisY(series1)!=0);
430 QVERIFY(m_chart->axisY(series2)!=0);
431 QVERIFY(m_chart->axisY(series2)!=0);
431
432
432 m_chart->removeAllSeries();
433 m_chart->removeAllSeries();
433 QVERIFY(m_chart->axisY(series0)==0);
434 QVERIFY(m_chart->axisY(series0)==0);
434 QVERIFY(m_chart->axisY(series1)==0);
435 QVERIFY(m_chart->axisY(series1)==0);
435 QVERIFY(m_chart->axisY(series2)==0);
436 QVERIFY(m_chart->axisY(series2)==0);
436 QCOMPARE(deleteSpy1.count(), 1);
437 QCOMPARE(deleteSpy1.count(), 1);
437 QCOMPARE(deleteSpy2.count(), 1);
438 QCOMPARE(deleteSpy2.count(), 1);
438 QCOMPARE(deleteSpy3.count(), 1);
439 QCOMPARE(deleteSpy3.count(), 1);
439 }
440 }
440
441
441 void tst_QChart::removeSeries_data()
442 void tst_QChart::removeSeries_data()
442 {
443 {
443 addSeries_data();
444 addSeries_data();
444 }
445 }
445
446
446 void tst_QChart::removeSeries()
447 void tst_QChart::removeSeries()
447 {
448 {
448 QFETCH(QAbstractSeries *, series);
449 QFETCH(QAbstractSeries *, series);
449 QFETCH(QAbstractAxis *, axis);
450 QFETCH(QAbstractAxis *, axis);
450 QSignalSpy deleteSpy(series, SIGNAL(destroyed()));
451 QSignalSpy deleteSpy(series, SIGNAL(destroyed()));
451 m_view->show();
452 m_view->show();
452 QTest::qWaitForWindowShown(m_view);
453 QTest::qWaitForWindowShown(m_view);
453 if(!axis) axis = m_chart->axisY();
454 if(!axis) axis = m_chart->axisY();
454 m_chart->addSeries(series);
455 m_chart->addSeries(series);
455 m_chart->setAxisY(axis,series);
456 m_chart->setAxisY(axis,series);
456 QCOMPARE(m_chart->axisY(series),axis);
457 QCOMPARE(m_chart->axisY(series),axis);
457 m_chart->removeSeries(series);
458 m_chart->removeSeries(series);
458 QVERIFY(m_chart->axisY(series)==0);
459 QVERIFY(m_chart->axisY(series)==0);
459 QCOMPARE(deleteSpy.count(), 0);
460 QCOMPARE(deleteSpy.count(), 0);
460 }
461 }
461
462
462 void tst_QChart::scroll_data()
463 void tst_QChart::scroll_data()
463 {
464 {
464
465
465 }
466 }
466
467
467 void tst_QChart::scroll()
468 void tst_QChart::scroll()
468 {
469 {
469 qFatal("implement me");
470 qFatal("implement me");
470 createTestData();
471 createTestData();
471 //TODO qreal min = m_chart->axisY()->min();
472 //TODO qreal min = m_chart->axisY()->min();
472 m_chart->scroll(0,0);
473 m_chart->scroll(0,0);
473 //TODO QVERIFY(m_chart->axisY()->min()<min);
474 //TODO QVERIFY(m_chart->axisY()->min()<min);
474 }
475 }
475
476
476 void tst_QChart::theme_data()
477 void tst_QChart::theme_data()
477 {
478 {
478 QTest::addColumn<QChart::ChartTheme>("theme");
479 QTest::addColumn<QChart::ChartTheme>("theme");
479 QTest::newRow("ChartThemeBlueCerulean") << QChart::ChartThemeBlueCerulean;
480 QTest::newRow("ChartThemeBlueCerulean") << QChart::ChartThemeBlueCerulean;
480 QTest::newRow("ChartThemeBlueIcy") << QChart::ChartThemeBlueIcy;
481 QTest::newRow("ChartThemeBlueIcy") << QChart::ChartThemeBlueIcy;
481 QTest::newRow("ChartThemeBlueNcs") << QChart::ChartThemeBlueNcs;
482 QTest::newRow("ChartThemeBlueNcs") << QChart::ChartThemeBlueNcs;
482 QTest::newRow("ChartThemeBrownSand") << QChart::ChartThemeBrownSand;
483 QTest::newRow("ChartThemeBrownSand") << QChart::ChartThemeBrownSand;
483 QTest::newRow("ChartThemeDark") << QChart::ChartThemeDark;
484 QTest::newRow("ChartThemeDark") << QChart::ChartThemeDark;
484 QTest::newRow("hartThemeHighContrast") << QChart::ChartThemeHighContrast;
485 QTest::newRow("hartThemeHighContrast") << QChart::ChartThemeHighContrast;
485 QTest::newRow("ChartThemeLight") << QChart::ChartThemeLight;
486 QTest::newRow("ChartThemeLight") << QChart::ChartThemeLight;
486 }
487 }
487
488
488 void tst_QChart::theme()
489 void tst_QChart::theme()
489 {
490 {
490 QFETCH(QChart::ChartTheme, theme);
491 QFETCH(QChart::ChartTheme, theme);
491 createTestData();
492 createTestData();
492 m_chart->setTheme(theme);
493 m_chart->setTheme(theme);
493 QVERIFY(m_chart->theme()==theme);
494 QVERIFY(m_chart->theme()==theme);
494 }
495 }
495
496
496 void tst_QChart::title_data()
497 void tst_QChart::title_data()
497 {
498 {
498 QTest::addColumn<QString>("title");
499 QTest::addColumn<QString>("title");
499 QTest::newRow("null") << QString();
500 QTest::newRow("null") << QString();
500 QTest::newRow("foo") << QString("foo");
501 QTest::newRow("foo") << QString("foo");
501 }
502 }
502
503
503 void tst_QChart::title()
504 void tst_QChart::title()
504 {
505 {
505 QFETCH(QString, title);
506 QFETCH(QString, title);
506 m_chart->setTitle(title);
507 m_chart->setTitle(title);
507 QCOMPARE(m_chart->title(), title);
508 QCOMPARE(m_chart->title(), title);
508 }
509 }
509
510
510 void tst_QChart::titleBrush_data()
511 void tst_QChart::titleBrush_data()
511 {
512 {
512 QTest::addColumn<QBrush>("titleBrush");
513 QTest::addColumn<QBrush>("titleBrush");
513 QTest::newRow("null") << QBrush();
514 QTest::newRow("null") << QBrush();
514 QTest::newRow("blue") << QBrush(Qt::blue);
515 QTest::newRow("blue") << QBrush(Qt::blue);
515 QTest::newRow("white") << QBrush(Qt::white);
516 QTest::newRow("white") << QBrush(Qt::white);
516 QTest::newRow("black") << QBrush(Qt::black);
517 QTest::newRow("black") << QBrush(Qt::black);
517 }
518 }
518
519
519 void tst_QChart::titleBrush()
520 void tst_QChart::titleBrush()
520 {
521 {
521 QFETCH(QBrush, titleBrush);
522 QFETCH(QBrush, titleBrush);
522 m_chart->setTitleBrush(titleBrush);
523 m_chart->setTitleBrush(titleBrush);
523 QCOMPARE(m_chart->titleBrush(), titleBrush);
524 QCOMPARE(m_chart->titleBrush(), titleBrush);
524 }
525 }
525
526
526 void tst_QChart::titleFont_data()
527 void tst_QChart::titleFont_data()
527 {
528 {
528 QTest::addColumn<QFont>("titleFont");
529 QTest::addColumn<QFont>("titleFont");
529 QTest::newRow("null") << QFont();
530 QTest::newRow("null") << QFont();
530 QTest::newRow("courier") << QFont("Courier", 8, QFont::Bold, true);
531 QTest::newRow("courier") << QFont("Courier", 8, QFont::Bold, true);
531 }
532 }
532
533
533 void tst_QChart::titleFont()
534 void tst_QChart::titleFont()
534 {
535 {
535 QFETCH(QFont, titleFont);
536 QFETCH(QFont, titleFont);
536 m_chart->setTitleFont(titleFont);
537 m_chart->setTitleFont(titleFont);
537 QCOMPARE(m_chart->titleFont(), titleFont);
538 QCOMPARE(m_chart->titleFont(), titleFont);
538 }
539 }
539
540
540 void tst_QChart::zoomIn_data()
541 void tst_QChart::zoomIn_data()
541 {
542 {
542 QTest::addColumn<QRectF>("rect");
543 QTest::addColumn<QRectF>("rect");
543 QTest::newRow("null") << QRectF();
544 QTest::newRow("null") << QRectF();
544 QTest::newRow("100x100") << QRectF(10,10,100,100);
545 QTest::newRow("100x100") << QRectF(10,10,100,100);
545 QTest::newRow("200x200") << QRectF(10,10,200,200);
546 QTest::newRow("200x200") << QRectF(10,10,200,200);
546 }
547 }
547
548
548
549
549 void tst_QChart::zoomIn()
550 void tst_QChart::zoomIn()
550 {
551 {
551 qFatal("implement me");
552 qFatal("implement me");
552 /*
553 /*
553 QFETCH(QRectF, rect);
554 QFETCH(QRectF, rect);
554 createTestData();
555 createTestData();
555 QRectF marigns = m_chart->margins();
556 QRectF marigns = m_chart->margins();
556 rect.adjust(marigns.left(),marigns.top(),-marigns.right(),-marigns.bottom());
557 rect.adjust(marigns.left(),marigns.top(),-marigns.right(),-marigns.bottom());
557 qreal minX = m_chart->axisX()->min();
558 qreal minX = m_chart->axisX()->min();
558 qreal minY = m_chart->axisY()->min();
559 qreal minY = m_chart->axisY()->min();
559 qreal maxX = m_chart->axisX()->max();
560 qreal maxX = m_chart->axisX()->max();
560 qreal maxY = m_chart->axisY()->max();
561 qreal maxY = m_chart->axisY()->max();
561 m_chart->zoomIn(rect);
562 m_chart->zoomIn(rect);
562 if(rect.isValid()){
563 if(rect.isValid()){
563 QVERIFY(minX<m_chart->axisX()->min());
564 QVERIFY(minX<m_chart->axisX()->min());
564 QVERIFY(maxX>m_chart->axisX()->max());
565 QVERIFY(maxX>m_chart->axisX()->max());
565 QVERIFY(minY<m_chart->axisY()->min());
566 QVERIFY(minY<m_chart->axisY()->min());
566 QVERIFY(maxY>m_chart->axisY()->max());
567 QVERIFY(maxY>m_chart->axisY()->max());
567 }
568 }
568 */
569 */
569 }
570 }
570
571
571 void tst_QChart::zoomOut_data()
572 void tst_QChart::zoomOut_data()
572 {
573 {
573
574
574 }
575 }
575
576
576 void tst_QChart::zoomOut()
577 void tst_QChart::zoomOut()
577 {
578 {
578 qFatal("implement me");
579 qFatal("implement me");
579 createTestData();
580 createTestData();
580 /*
581 /*
581 qreal minX = m_chart->axisX()->min();
582 qreal minX = m_chart->axisX()->min();
582 qreal minY = m_chart->axisY()->min();
583 qreal minY = m_chart->axisY()->min();
583 qreal maxX = m_chart->axisX()->max();
584 qreal maxX = m_chart->axisX()->max();
584 qreal maxY = m_chart->axisY()->max();
585 qreal maxY = m_chart->axisY()->max();
585
586
586 m_chart->zoomIn();
587 m_chart->zoomIn();
587
588
588 QVERIFY(minX < m_chart->axisX()->min());
589 QVERIFY(minX < m_chart->axisX()->min());
589 QVERIFY(maxX > m_chart->axisX()->max());
590 QVERIFY(maxX > m_chart->axisX()->max());
590 QVERIFY(minY < m_chart->axisY()->min());
591 QVERIFY(minY < m_chart->axisY()->min());
591 QVERIFY(maxY > m_chart->axisY()->max());
592 QVERIFY(maxY > m_chart->axisY()->max());
592
593
593 m_chart->zoomOut();
594 m_chart->zoomOut();
594
595
595 // min x may be a zero value
596 // min x may be a zero value
596 if (qFuzzyIsNull(minX))
597 if (qFuzzyIsNull(minX))
597 QVERIFY(qFuzzyIsNull(m_chart->axisX()->min()));
598 QVERIFY(qFuzzyIsNull(m_chart->axisX()->min()));
598 else
599 else
599 QCOMPARE(minX, m_chart->axisX()->min());
600 QCOMPARE(minX, m_chart->axisX()->min());
600
601
601 // min y may be a zero value
602 // min y may be a zero value
602 if (qFuzzyIsNull(minY))
603 if (qFuzzyIsNull(minY))
603 QVERIFY(qFuzzyIsNull(m_chart->axisY()->min()));
604 QVERIFY(qFuzzyIsNull(m_chart->axisY()->min()));
604 else
605 else
605 QCOMPARE(minY, m_chart->axisY()->min());
606 QCOMPARE(minY, m_chart->axisY()->min());
606
607
607 QVERIFY(maxX == m_chart->axisX()->max());
608 QVERIFY(maxX == m_chart->axisX()->max());
608 QVERIFY(maxY == m_chart->axisY()->max());
609 QVERIFY(maxY == m_chart->axisY()->max());
609 */
610 */
610 }
611 }
611
612
612 QTEST_MAIN(tst_QChart)
613 QTEST_MAIN(tst_QChart)
613 #include "tst_qchart.moc"
614 #include "tst_qchart.moc"
614
615
@@ -1,190 +1,189
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "dataseriedialog.h"
21 #include "dataseriedialog.h"
22 #include <QDialogButtonBox>
22 #include <QDialogButtonBox>
23 #include <QGridLayout>
23 #include <QGridLayout>
24 #include <QCheckBox>
24 #include <QCheckBox>
25 #include <QPushButton>
25 #include <QPushButton>
26 #include <QGroupBox>
26 #include <QGroupBox>
27 #include <QRadioButton>
27 #include <QRadioButton>
28 #include <QLabel>
28 #include <QLabel>
29 #include <QDebug>
29 #include <QDebug>
30
30
31 DataSerieDialog::DataSerieDialog(QWidget *parent) :
31 DataSerieDialog::DataSerieDialog(QWidget *parent) :
32 QDialog(parent)
32 QDialog(parent)
33 {
33 {
34 QDialogButtonBox *addSeriesBox = new QDialogButtonBox(Qt::Horizontal);
34 QDialogButtonBox *addSeriesBox = new QDialogButtonBox(Qt::Horizontal);
35 QPushButton *b = addSeriesBox->addButton(QDialogButtonBox::Ok);
35 QPushButton *b = addSeriesBox->addButton(QDialogButtonBox::Ok);
36 connect(b, SIGNAL(clicked()), this, SLOT(accept()));
36 connect(b, SIGNAL(clicked()), this, SLOT(accept()));
37 b = addSeriesBox->addButton(QDialogButtonBox::Cancel);
37 b = addSeriesBox->addButton(QDialogButtonBox::Cancel);
38 connect(b, SIGNAL(clicked()), this, SLOT(reject()));
38 connect(b, SIGNAL(clicked()), this, SLOT(reject()));
39
39
40 QGridLayout *grid = new QGridLayout();
40 QGridLayout *grid = new QGridLayout();
41
41
42 m_seriesTypeSelector = seriesTypeSelector();
42 m_seriesTypeSelector = seriesTypeSelector();
43 m_columnCountSelector = columnCountSelector();
43 m_columnCountSelector = columnCountSelector();
44 m_rowCountSelector = rowCountSelector();
44 m_rowCountSelector = rowCountSelector();
45 m_dataCharacteristicsSelector = dataCharacteristicsSelector();
45 m_dataCharacteristicsSelector = dataCharacteristicsSelector();
46
46
47 grid->addWidget(m_seriesTypeSelector, 0, 0);
47 grid->addWidget(m_seriesTypeSelector, 0, 0);
48 grid->addWidget(m_columnCountSelector, 0, 1);
48 grid->addWidget(m_columnCountSelector, 0, 1);
49 grid->addWidget(m_rowCountSelector, 1, 1);
49 grid->addWidget(m_rowCountSelector, 1, 1);
50 grid->addWidget(m_dataCharacteristicsSelector, 1, 0);
50 grid->addWidget(m_dataCharacteristicsSelector, 1, 0);
51 m_labelsSelector = new QCheckBox("Labels defined");
51 m_labelsSelector = new QCheckBox("Labels defined");
52 m_labelsSelector->setChecked(true);
52 m_labelsSelector->setChecked(true);
53 grid->addWidget(m_labelsSelector, 2, 0);
53 grid->addWidget(m_labelsSelector, 2, 0);
54 grid->addWidget(addSeriesBox, 3, 1);
54 grid->addWidget(addSeriesBox, 3, 1);
55
55
56 setLayout(grid);
56 setLayout(grid);
57 }
57 }
58
58
59 QGroupBox *DataSerieDialog::seriesTypeSelector()
59 QGroupBox *DataSerieDialog::seriesTypeSelector()
60 {
60 {
61 QVBoxLayout *layout = new QVBoxLayout();
61 QVBoxLayout *layout = new QVBoxLayout();
62
62
63 QRadioButton *line = new QRadioButton("Line");
63 QRadioButton *line = new QRadioButton("Line");
64 line->setChecked(true);
64 line->setChecked(true);
65 layout->addWidget(line);
65 layout->addWidget(line);
66 layout->addWidget(new QRadioButton("Area"));
66 layout->addWidget(new QRadioButton("Area"));
67 layout->addWidget(new QRadioButton("Pie"));
67 layout->addWidget(new QRadioButton("Pie"));
68 layout->addWidget(new QRadioButton("Bar"));
69 layout->addWidget(new QRadioButton("Grouped bar"));
68 layout->addWidget(new QRadioButton("Grouped bar"));
70 layout->addWidget(new QRadioButton("Stacked bar"));
69 layout->addWidget(new QRadioButton("Stacked bar"));
71 layout->addWidget(new QRadioButton("Percent bar"));
70 layout->addWidget(new QRadioButton("Percent bar"));
72 layout->addWidget(new QRadioButton("Scatter"));
71 layout->addWidget(new QRadioButton("Scatter"));
73 layout->addWidget(new QRadioButton("Spline"));
72 layout->addWidget(new QRadioButton("Spline"));
74
73
75 QGroupBox *groupBox = new QGroupBox("Series type");
74 QGroupBox *groupBox = new QGroupBox("Series type");
76 groupBox->setLayout(layout);
75 groupBox->setLayout(layout);
77 selectRadio(groupBox, 0);
76 selectRadio(groupBox, 0);
78
77
79 return groupBox;
78 return groupBox;
80 }
79 }
81
80
82 QGroupBox *DataSerieDialog::columnCountSelector()
81 QGroupBox *DataSerieDialog::columnCountSelector()
83 {
82 {
84 QVBoxLayout *layout = new QVBoxLayout();
83 QVBoxLayout *layout = new QVBoxLayout();
85
84
86 QRadioButton *radio = new QRadioButton("1");
85 QRadioButton *radio = new QRadioButton("1");
87 radio->setChecked(true);
86 radio->setChecked(true);
88 layout->addWidget(radio);
87 layout->addWidget(radio);
89 layout->addWidget(new QRadioButton("2"));
88 layout->addWidget(new QRadioButton("2"));
90 layout->addWidget(new QRadioButton("3"));
89 layout->addWidget(new QRadioButton("3"));
91 layout->addWidget(new QRadioButton("4"));
90 layout->addWidget(new QRadioButton("4"));
92 layout->addWidget(new QRadioButton("5"));
91 layout->addWidget(new QRadioButton("5"));
93 layout->addWidget(new QRadioButton("8"));
92 layout->addWidget(new QRadioButton("8"));
94 layout->addWidget(new QRadioButton("10"));
93 layout->addWidget(new QRadioButton("10"));
95 layout->addWidget(new QRadioButton("100"));
94 layout->addWidget(new QRadioButton("100"));
96
95
97 QGroupBox *groupBox = new QGroupBox("Column count");
96 QGroupBox *groupBox = new QGroupBox("Column count");
98 groupBox->setLayout(layout);
97 groupBox->setLayout(layout);
99 selectRadio(groupBox, 0);
98 selectRadio(groupBox, 0);
100
99
101 return groupBox;
100 return groupBox;
102 }
101 }
103
102
104 QGroupBox *DataSerieDialog::rowCountSelector()
103 QGroupBox *DataSerieDialog::rowCountSelector()
105 {
104 {
106 QVBoxLayout *layout = new QVBoxLayout();
105 QVBoxLayout *layout = new QVBoxLayout();
107
106
108 layout->addWidget(new QRadioButton("1"));
107 layout->addWidget(new QRadioButton("1"));
109 QRadioButton *radio = new QRadioButton("10");
108 QRadioButton *radio = new QRadioButton("10");
110 radio->setChecked(true);
109 radio->setChecked(true);
111 layout->addWidget(radio);
110 layout->addWidget(radio);
112 layout->addWidget(new QRadioButton("50"));
111 layout->addWidget(new QRadioButton("50"));
113 layout->addWidget(new QRadioButton("100"));
112 layout->addWidget(new QRadioButton("100"));
114 layout->addWidget(new QRadioButton("1000"));
113 layout->addWidget(new QRadioButton("1000"));
115 layout->addWidget(new QRadioButton("10000"));
114 layout->addWidget(new QRadioButton("10000"));
116 layout->addWidget(new QRadioButton("100000"));
115 layout->addWidget(new QRadioButton("100000"));
117 layout->addWidget(new QRadioButton("1000000"));
116 layout->addWidget(new QRadioButton("1000000"));
118
117
119 QGroupBox *groupBox = new QGroupBox("Row count");
118 QGroupBox *groupBox = new QGroupBox("Row count");
120 groupBox->setLayout(layout);
119 groupBox->setLayout(layout);
121 selectRadio(groupBox, 0);
120 selectRadio(groupBox, 0);
122
121
123 return groupBox;
122 return groupBox;
124 }
123 }
125
124
126 QGroupBox *DataSerieDialog::dataCharacteristicsSelector()
125 QGroupBox *DataSerieDialog::dataCharacteristicsSelector()
127 {
126 {
128 QVBoxLayout *layout = new QVBoxLayout();
127 QVBoxLayout *layout = new QVBoxLayout();
129
128
130 layout->addWidget(new QRadioButton("Linear"));
129 layout->addWidget(new QRadioButton("Linear"));
131 layout->addWidget(new QRadioButton("Constant"));
130 layout->addWidget(new QRadioButton("Constant"));
132 layout->addWidget(new QRadioButton("Random"));
131 layout->addWidget(new QRadioButton("Random"));
133 layout->addWidget(new QRadioButton("Sin"));
132 layout->addWidget(new QRadioButton("Sin"));
134 layout->addWidget(new QRadioButton("Sin + random"));
133 layout->addWidget(new QRadioButton("Sin + random"));
135
134
136 QGroupBox *groupBox = new QGroupBox("Data Characteristics");
135 QGroupBox *groupBox = new QGroupBox("Data Characteristics");
137 groupBox->setLayout(layout);
136 groupBox->setLayout(layout);
138 selectRadio(groupBox, 0);
137 selectRadio(groupBox, 0);
139
138
140 return groupBox;
139 return groupBox;
141 }
140 }
142
141
143 void DataSerieDialog::accept()
142 void DataSerieDialog::accept()
144 {
143 {
145 accepted(radioSelection(m_seriesTypeSelector),
144 accepted(radioSelection(m_seriesTypeSelector),
146 radioSelection(m_columnCountSelector).toInt(),
145 radioSelection(m_columnCountSelector).toInt(),
147 radioSelection(m_rowCountSelector).toInt(),
146 radioSelection(m_rowCountSelector).toInt(),
148 radioSelection(m_dataCharacteristicsSelector),
147 radioSelection(m_dataCharacteristicsSelector),
149 m_labelsSelector->isChecked());
148 m_labelsSelector->isChecked());
150 QDialog::accept();
149 QDialog::accept();
151 }
150 }
152
151
153 void DataSerieDialog::selectRadio(QGroupBox *groupBox, int defaultSelection)
152 void DataSerieDialog::selectRadio(QGroupBox *groupBox, int defaultSelection)
154 {
153 {
155 QVBoxLayout *layout = qobject_cast<QVBoxLayout *>(groupBox->layout());
154 QVBoxLayout *layout = qobject_cast<QVBoxLayout *>(groupBox->layout());
156 Q_ASSERT(layout);
155 Q_ASSERT(layout);
157 Q_ASSERT(layout->count());
156 Q_ASSERT(layout->count());
158
157
159 QLayoutItem *item = 0;
158 QLayoutItem *item = 0;
160 if (defaultSelection == -1) {
159 if (defaultSelection == -1) {
161 item = layout->itemAt(0);
160 item = layout->itemAt(0);
162 } else if (layout->count() > defaultSelection) {
161 } else if (layout->count() > defaultSelection) {
163 item = layout->itemAt(defaultSelection);
162 item = layout->itemAt(defaultSelection);
164 }
163 }
165 Q_ASSERT(item);
164 Q_ASSERT(item);
166 QRadioButton *radio = qobject_cast<QRadioButton *>(item->widget());
165 QRadioButton *radio = qobject_cast<QRadioButton *>(item->widget());
167 Q_ASSERT(radio);
166 Q_ASSERT(radio);
168 radio->setChecked(true);
167 radio->setChecked(true);
169 }
168 }
170
169
171 QString DataSerieDialog::radioSelection(QGroupBox *groupBox)
170 QString DataSerieDialog::radioSelection(QGroupBox *groupBox)
172 {
171 {
173 QString selection;
172 QString selection;
174 QVBoxLayout *layout = qobject_cast<QVBoxLayout *>(groupBox->layout());
173 QVBoxLayout *layout = qobject_cast<QVBoxLayout *>(groupBox->layout());
175 Q_ASSERT(layout);
174 Q_ASSERT(layout);
176
175
177 for (int i(0); i < layout->count(); i++) {
176 for (int i(0); i < layout->count(); i++) {
178 QLayoutItem *item = layout->itemAt(i);
177 QLayoutItem *item = layout->itemAt(i);
179 Q_ASSERT(item);
178 Q_ASSERT(item);
180 QRadioButton *radio = qobject_cast<QRadioButton *>(item->widget());
179 QRadioButton *radio = qobject_cast<QRadioButton *>(item->widget());
181 Q_ASSERT(radio);
180 Q_ASSERT(radio);
182 if (radio->isChecked()) {
181 if (radio->isChecked()) {
183 selection = radio->text();
182 selection = radio->text();
184 break;
183 break;
185 }
184 }
186 }
185 }
187
186
188 qDebug() << "radioSelection: " << selection;
187 qDebug() << "radioSelection: " << selection;
189 return selection;
188 return selection;
190 }
189 }
@@ -1,364 +1,357
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "mainwidget.h"
21 #include "mainwidget.h"
22 #include "dataseriedialog.h"
22 #include "dataseriedialog.h"
23 #include "qchartview.h"
23 #include "qchartview.h"
24 #include "qpieseries.h"
24 #include "qpieseries.h"
25 #include "qscatterseries.h"
25 #include "qscatterseries.h"
26 #include "qlineseries.h"
26 #include "qlineseries.h"
27 #include <qareaseries.h>
27 #include <qareaseries.h>
28 #include <qsplineseries.h>
28 #include <qsplineseries.h>
29 #include <qbarset.h>
29 #include <qbarset.h>
30 #include <qabstractbarseries.h>
31 #include <qgroupedbarseries.h>
30 #include <qgroupedbarseries.h>
32 #include <qstackedbarseries.h>
31 #include <qstackedbarseries.h>
33 #include <qpercentbarseries.h>
32 #include <qpercentbarseries.h>
34 #include <QPushButton>
33 #include <QPushButton>
35 #include <QComboBox>
34 #include <QComboBox>
36 #include <QSpinBox>
35 #include <QSpinBox>
37 #include <QCheckBox>
36 #include <QCheckBox>
38 #include <QGridLayout>
37 #include <QGridLayout>
39 #include <QHBoxLayout>
38 #include <QHBoxLayout>
40 #include <QLabel>
39 #include <QLabel>
41 #include <QSpacerItem>
40 #include <QSpacerItem>
42 #include <QMessageBox>
41 #include <QMessageBox>
43 #include <cmath>
42 #include <cmath>
44 #include <QDebug>
43 #include <QDebug>
45 #include <QStandardItemModel>
44 #include <QStandardItemModel>
46 #include <QCategoriesAxis>
45 #include <QCategoriesAxis>
47
46
48
47
49 QTCOMMERCIALCHART_USE_NAMESPACE
48 QTCOMMERCIALCHART_USE_NAMESPACE
50
49
51 MainWidget::MainWidget(QWidget *parent) :
50 MainWidget::MainWidget(QWidget *parent) :
52 QWidget(parent),
51 QWidget(parent),
53 m_addSerieDialog(0),
52 m_addSerieDialog(0),
54 m_chart(0)
53 m_chart(0)
55 {
54 {
56 m_chart = new QChart();
55 m_chart = new QChart();
57
56
58 // Grid layout for the controls for configuring the chart widget
57 // Grid layout for the controls for configuring the chart widget
59 QGridLayout *grid = new QGridLayout();
58 QGridLayout *grid = new QGridLayout();
60 QPushButton *addSeriesButton = new QPushButton("Add series");
59 QPushButton *addSeriesButton = new QPushButton("Add series");
61 connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries()));
60 connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries()));
62 grid->addWidget(addSeriesButton, 0, 1);
61 grid->addWidget(addSeriesButton, 0, 1);
63 initBackroundCombo(grid);
62 initBackroundCombo(grid);
64 initScaleControls(grid);
63 initScaleControls(grid);
65 initThemeCombo(grid);
64 initThemeCombo(grid);
66 initCheckboxes(grid);
65 initCheckboxes(grid);
67
66
68 // add row with empty label to make all the other rows static
67 // add row with empty label to make all the other rows static
69 grid->addWidget(new QLabel(""), grid->rowCount(), 0);
68 grid->addWidget(new QLabel(""), grid->rowCount(), 0);
70 grid->setRowStretch(grid->rowCount() - 1, 1);
69 grid->setRowStretch(grid->rowCount() - 1, 1);
71
70
72 // Create chart view with the chart
71 // Create chart view with the chart
73 m_chartView = new QChartView(m_chart, this);
72 m_chartView = new QChartView(m_chart, this);
74 m_chartView->setRubberBand(QChartView::HorizonalRubberBand);
73 m_chartView->setRubberBand(QChartView::HorizonalRubberBand);
75
74
76 // Another grid layout as a main layout
75 // Another grid layout as a main layout
77 QGridLayout *mainLayout = new QGridLayout();
76 QGridLayout *mainLayout = new QGridLayout();
78 mainLayout->addLayout(grid, 0, 0);
77 mainLayout->addLayout(grid, 0, 0);
79 mainLayout->addWidget(m_chartView, 0, 1, 3, 1);
78 mainLayout->addWidget(m_chartView, 0, 1, 3, 1);
80 setLayout(mainLayout);
79 setLayout(mainLayout);
81 }
80 }
82
81
83 // Combo box for selecting the chart's background
82 // Combo box for selecting the chart's background
84 void MainWidget::initBackroundCombo(QGridLayout *grid)
83 void MainWidget::initBackroundCombo(QGridLayout *grid)
85 {
84 {
86 QComboBox *backgroundCombo = new QComboBox(this);
85 QComboBox *backgroundCombo = new QComboBox(this);
87 backgroundCombo->addItem("Color");
86 backgroundCombo->addItem("Color");
88 backgroundCombo->addItem("Gradient");
87 backgroundCombo->addItem("Gradient");
89 backgroundCombo->addItem("Image");
88 backgroundCombo->addItem("Image");
90 connect(backgroundCombo, SIGNAL(currentIndexChanged(int)),
89 connect(backgroundCombo, SIGNAL(currentIndexChanged(int)),
91 this, SLOT(backgroundChanged(int)));
90 this, SLOT(backgroundChanged(int)));
92
91
93 grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0);
92 grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0);
94 grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1);
93 grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1);
95 }
94 }
96
95
97 // Scale related controls (auto-scale vs. manual min-max values)
96 // Scale related controls (auto-scale vs. manual min-max values)
98 void MainWidget::initScaleControls(QGridLayout *grid)
97 void MainWidget::initScaleControls(QGridLayout *grid)
99 {
98 {
100 m_autoScaleCheck = new QCheckBox("Automatic scaling");
99 m_autoScaleCheck = new QCheckBox("Automatic scaling");
101 connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int)));
100 connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int)));
102 // Allow setting also non-sense values (like -2147483648 and 2147483647)
101 // Allow setting also non-sense values (like -2147483648 and 2147483647)
103 m_xMinSpin = new QSpinBox();
102 m_xMinSpin = new QSpinBox();
104 m_xMinSpin->setMinimum(INT_MIN);
103 m_xMinSpin->setMinimum(INT_MIN);
105 m_xMinSpin->setMaximum(INT_MAX);
104 m_xMinSpin->setMaximum(INT_MAX);
106 m_xMinSpin->setValue(0);
105 m_xMinSpin->setValue(0);
107 connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int)));
106 connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int)));
108 m_xMaxSpin = new QSpinBox();
107 m_xMaxSpin = new QSpinBox();
109 m_xMaxSpin->setMinimum(INT_MIN);
108 m_xMaxSpin->setMinimum(INT_MIN);
110 m_xMaxSpin->setMaximum(INT_MAX);
109 m_xMaxSpin->setMaximum(INT_MAX);
111 m_xMaxSpin->setValue(10);
110 m_xMaxSpin->setValue(10);
112 connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int)));
111 connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int)));
113 m_yMinSpin = new QSpinBox();
112 m_yMinSpin = new QSpinBox();
114 m_yMinSpin->setMinimum(INT_MIN);
113 m_yMinSpin->setMinimum(INT_MIN);
115 m_yMinSpin->setMaximum(INT_MAX);
114 m_yMinSpin->setMaximum(INT_MAX);
116 m_yMinSpin->setValue(0);
115 m_yMinSpin->setValue(0);
117 connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int)));
116 connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int)));
118 m_yMaxSpin = new QSpinBox();
117 m_yMaxSpin = new QSpinBox();
119 m_yMaxSpin->setMinimum(INT_MIN);
118 m_yMaxSpin->setMinimum(INT_MIN);
120 m_yMaxSpin->setMaximum(INT_MAX);
119 m_yMaxSpin->setMaximum(INT_MAX);
121 m_yMaxSpin->setValue(10);
120 m_yMaxSpin->setValue(10);
122 connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int)));
121 connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int)));
123
122
124 grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0);
123 grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0);
125 grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0);
124 grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0);
126 grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1);
125 grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1);
127 grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0);
126 grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0);
128 grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1);
127 grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1);
129 grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0);
128 grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0);
130 grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1);
129 grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1);
131 grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0);
130 grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0);
132 grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1);
131 grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1);
133
132
134 m_autoScaleCheck->setChecked(true);
133 m_autoScaleCheck->setChecked(true);
135 }
134 }
136
135
137 // Combo box for selecting theme
136 // Combo box for selecting theme
138 void MainWidget::initThemeCombo(QGridLayout *grid)
137 void MainWidget::initThemeCombo(QGridLayout *grid)
139 {
138 {
140 QComboBox *chartTheme = new QComboBox();
139 QComboBox *chartTheme = new QComboBox();
141 chartTheme->addItem("Default");
140 chartTheme->addItem("Default");
142 chartTheme->addItem("Light");
141 chartTheme->addItem("Light");
143 chartTheme->addItem("Blue Cerulean");
142 chartTheme->addItem("Blue Cerulean");
144 chartTheme->addItem("Dark");
143 chartTheme->addItem("Dark");
145 chartTheme->addItem("Brown Sand");
144 chartTheme->addItem("Brown Sand");
146 chartTheme->addItem("Blue NCS");
145 chartTheme->addItem("Blue NCS");
147 chartTheme->addItem("High Contrast");
146 chartTheme->addItem("High Contrast");
148 chartTheme->addItem("Blue Icy");
147 chartTheme->addItem("Blue Icy");
149 connect(chartTheme, SIGNAL(currentIndexChanged(int)),
148 connect(chartTheme, SIGNAL(currentIndexChanged(int)),
150 this, SLOT(changeChartTheme(int)));
149 this, SLOT(changeChartTheme(int)));
151 grid->addWidget(new QLabel("Chart theme:"), 8, 0);
150 grid->addWidget(new QLabel("Chart theme:"), 8, 0);
152 grid->addWidget(chartTheme, 8, 1);
151 grid->addWidget(chartTheme, 8, 1);
153 }
152 }
154
153
155 // Different check boxes for customizing chart
154 // Different check boxes for customizing chart
156 void MainWidget::initCheckboxes(QGridLayout *grid)
155 void MainWidget::initCheckboxes(QGridLayout *grid)
157 {
156 {
158 // TODO: setZoomEnabled slot has been removed from QChartView -> Re-implement zoom on/off
157 // TODO: setZoomEnabled slot has been removed from QChartView -> Re-implement zoom on/off
159 QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom");
158 QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom");
160 // connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartView, SLOT(setZoomEnabled(bool)));
159 // connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartView, SLOT(setZoomEnabled(bool)));
161 zoomCheckBox->setChecked(true);
160 zoomCheckBox->setChecked(true);
162 grid->addWidget(zoomCheckBox, grid->rowCount(), 0);
161 grid->addWidget(zoomCheckBox, grid->rowCount(), 0);
163
162
164 QCheckBox *aliasCheckBox = new QCheckBox("Anti-alias");
163 QCheckBox *aliasCheckBox = new QCheckBox("Anti-alias");
165 connect(aliasCheckBox, SIGNAL(toggled(bool)), this, SLOT(antiAliasToggled(bool)));
164 connect(aliasCheckBox, SIGNAL(toggled(bool)), this, SLOT(antiAliasToggled(bool)));
166 aliasCheckBox->setChecked(false);
165 aliasCheckBox->setChecked(false);
167 grid->addWidget(aliasCheckBox, grid->rowCount(), 0);
166 grid->addWidget(aliasCheckBox, grid->rowCount(), 0);
168 }
167 }
169
168
170 void MainWidget::antiAliasToggled(bool enabled)
169 void MainWidget::antiAliasToggled(bool enabled)
171 {
170 {
172 m_chartView->setRenderHint(QPainter::Antialiasing, enabled);
171 m_chartView->setRenderHint(QPainter::Antialiasing, enabled);
173 }
172 }
174
173
175 void MainWidget::addSeries()
174 void MainWidget::addSeries()
176 {
175 {
177 if (!m_addSerieDialog) {
176 if (!m_addSerieDialog) {
178 m_addSerieDialog = new DataSerieDialog(this);
177 m_addSerieDialog = new DataSerieDialog(this);
179 connect(m_addSerieDialog, SIGNAL(accepted(QString,int,int,QString,bool)),
178 connect(m_addSerieDialog, SIGNAL(accepted(QString,int,int,QString,bool)),
180 this, SLOT(addSeries(QString,int,int,QString,bool)));
179 this, SLOT(addSeries(QString,int,int,QString,bool)));
181 }
180 }
182 m_addSerieDialog->exec();
181 m_addSerieDialog->exec();
183 }
182 }
184
183
185 QList<RealList> MainWidget::generateTestData(int columnCount, int rowCount, QString dataCharacteristics)
184 QList<RealList> MainWidget::generateTestData(int columnCount, int rowCount, QString dataCharacteristics)
186 {
185 {
187 // TODO: dataCharacteristics
186 // TODO: dataCharacteristics
188 QList<RealList> testData;
187 QList<RealList> testData;
189 for (int j(0); j < columnCount; j++) {
188 for (int j(0); j < columnCount; j++) {
190 QList <qreal> newColumn;
189 QList <qreal> newColumn;
191 for (int i(0); i < rowCount; i++) {
190 for (int i(0); i < rowCount; i++) {
192 if (dataCharacteristics == "Sin") {
191 if (dataCharacteristics == "Sin") {
193 newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100));
192 newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100));
194 } else if (dataCharacteristics == "Sin + random") {
193 } else if (dataCharacteristics == "Sin + random") {
195 newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5));
194 newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5));
196 } else if (dataCharacteristics == "Random") {
195 } else if (dataCharacteristics == "Random") {
197 newColumn.append(rand() % 10 + (qreal) rand() / (qreal) RAND_MAX);
196 newColumn.append(rand() % 10 + (qreal) rand() / (qreal) RAND_MAX);
198 } else if (dataCharacteristics == "Linear") {
197 } else if (dataCharacteristics == "Linear") {
199 //newColumn.append(i * (j + 1.0));
198 //newColumn.append(i * (j + 1.0));
200 // TODO: temporary hack to make pie work; prevent zero values:
199 // TODO: temporary hack to make pie work; prevent zero values:
201 newColumn.append(i * (j + 1.0) + 0.1);
200 newColumn.append(i * (j + 1.0) + 0.1);
202 } else { // "constant"
201 } else { // "constant"
203 newColumn.append((j + 1.0));
202 newColumn.append((j + 1.0));
204 }
203 }
205 }
204 }
206 testData.append(newColumn);
205 testData.append(newColumn);
207 }
206 }
208 return testData;
207 return testData;
209 }
208 }
210
209
211 QStringList MainWidget::generateLabels(int count)
210 QStringList MainWidget::generateLabels(int count)
212 {
211 {
213 QStringList result;
212 QStringList result;
214 for (int i(0); i < count; i++)
213 for (int i(0); i < count; i++)
215 result.append("label" + QString::number(i));
214 result.append("label" + QString::number(i));
216 return result;
215 return result;
217 }
216 }
218
217
219 void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QString dataCharacteristics, bool labelsEnabled)
218 void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QString dataCharacteristics, bool labelsEnabled)
220 {
219 {
221 qDebug() << "addSeries: " << seriesName
220 qDebug() << "addSeries: " << seriesName
222 << " columnCount: " << columnCount
221 << " columnCount: " << columnCount
223 << " rowCount: " << rowCount
222 << " rowCount: " << rowCount
224 << " dataCharacteristics: " << dataCharacteristics
223 << " dataCharacteristics: " << dataCharacteristics
225 << " labels enabled: " << labelsEnabled;
224 << " labels enabled: " << labelsEnabled;
226 m_defaultSeriesName = seriesName;
225 m_defaultSeriesName = seriesName;
227
226
228 QList<RealList> data = generateTestData(columnCount, rowCount, dataCharacteristics);
227 QList<RealList> data = generateTestData(columnCount, rowCount, dataCharacteristics);
229
228
230 // Line series and scatter series use similar data
229 // Line series and scatter series use similar data
231 if (seriesName == "Line") {
230 if (seriesName == "Line") {
232 for (int j(0); j < data.count(); j ++) {
231 for (int j(0); j < data.count(); j ++) {
233 QList<qreal> column = data.at(j);
232 QList<qreal> column = data.at(j);
234 QLineSeries *series = new QLineSeries();
233 QLineSeries *series = new QLineSeries();
235 series->setName("line" + QString::number(j));
234 series->setName("line" + QString::number(j));
236 for (int i(0); i < column.count(); i++)
235 for (int i(0); i < column.count(); i++)
237 series->append(i, column.at(i));
236 series->append(i, column.at(i));
238 m_chart->addSeries(series);
237 m_chart->addSeries(series);
239 }
238 }
240 } else if (seriesName == "Area") {
239 } else if (seriesName == "Area") {
241 // TODO: lower series for the area?
240 // TODO: lower series for the area?
242 for (int j(0); j < data.count(); j ++) {
241 for (int j(0); j < data.count(); j ++) {
243 QList<qreal> column = data.at(j);
242 QList<qreal> column = data.at(j);
244 QLineSeries *lineSeries = new QLineSeries();
243 QLineSeries *lineSeries = new QLineSeries();
245 for (int i(0); i < column.count(); i++)
244 for (int i(0); i < column.count(); i++)
246 lineSeries->append(i, column.at(i));
245 lineSeries->append(i, column.at(i));
247 QAreaSeries *areaSeries = new QAreaSeries(lineSeries);
246 QAreaSeries *areaSeries = new QAreaSeries(lineSeries);
248 areaSeries->setName("area" + QString::number(j));
247 areaSeries->setName("area" + QString::number(j));
249 m_chart->addSeries(areaSeries);
248 m_chart->addSeries(areaSeries);
250 }
249 }
251 } else if (seriesName == "Scatter") {
250 } else if (seriesName == "Scatter") {
252 for (int j(0); j < data.count(); j++) {
251 for (int j(0); j < data.count(); j++) {
253 QList<qreal> column = data.at(j);
252 QList<qreal> column = data.at(j);
254 QScatterSeries *series = new QScatterSeries();
253 QScatterSeries *series = new QScatterSeries();
255 series->setName("scatter" + QString::number(j));
254 series->setName("scatter" + QString::number(j));
256 for (int i(0); i < column.count(); i++)
255 for (int i(0); i < column.count(); i++)
257 series->append(i, column.at(i));
256 series->append(i, column.at(i));
258 m_chart->addSeries(series);
257 m_chart->addSeries(series);
259 }
258 }
260 } else if (seriesName == "Pie") {
259 } else if (seriesName == "Pie") {
261 QStringList labels = generateLabels(rowCount);
260 QStringList labels = generateLabels(rowCount);
262 for (int j(0); j < data.count(); j++) {
261 for (int j(0); j < data.count(); j++) {
263 QPieSeries *series = new QPieSeries();
262 QPieSeries *series = new QPieSeries();
264 QList<qreal> column = data.at(j);
263 QList<qreal> column = data.at(j);
265 for (int i(0); i < column.count(); i++)
264 for (int i(0); i < column.count(); i++)
266 series->append(labels.at(i), column.at(i));
265 series->append(labels.at(i), column.at(i));
267 m_chart->addSeries(series);
266 m_chart->addSeries(series);
268 }
267 }
269 } else if (seriesName == "Bar"
268 } else if (seriesName == "Grouped bar"
270 || seriesName == "Grouped bar"
271 || seriesName == "Stacked bar"
269 || seriesName == "Stacked bar"
272 || seriesName == "Percent bar") {
270 || seriesName == "Percent bar") {
273 QStringList category;
271 QStringList category;
274 QStringList labels = generateLabels(rowCount);
272 QStringList labels = generateLabels(rowCount);
275 foreach(QString label, labels)
273 foreach(QString label, labels)
276 category << label;
274 category << label;
277 QAbstractBarSeries* series = 0;
275 QAbstractBarSeries* series = 0;
278 if (seriesName == "Bar") {
276 if (seriesName == "Grouped bar") {
279 series = new QAbstractBarSeries(this);
280 QCategoriesAxis* axis = new QCategoriesAxis();
281 axis->append(category);
282 m_chart->setAxisX(axis,series);
283 } else if (seriesName == "Grouped bar") {
284 series = new QGroupedBarSeries(this);
277 series = new QGroupedBarSeries(this);
285 QCategoriesAxis* axis = new QCategoriesAxis();
278 QCategoriesAxis* axis = new QCategoriesAxis();
286 axis->append(category);
279 axis->append(category);
287 m_chart->setAxisX(axis,series);
280 m_chart->setAxisX(axis,series);
288 } else if (seriesName == "Stacked bar") {
281 } else if (seriesName == "Stacked bar") {
289 series = new QStackedBarSeries(this);
282 series = new QStackedBarSeries(this);
290 QCategoriesAxis* axis = new QCategoriesAxis();
283 QCategoriesAxis* axis = new QCategoriesAxis();
291 axis->append(category);
284 axis->append(category);
292 m_chart->setAxisX(axis,series);
285 m_chart->setAxisX(axis,series);
293 } else {
286 } else {
294 series = new QPercentBarSeries(this);
287 series = new QPercentBarSeries(this);
295 QCategoriesAxis* axis = new QCategoriesAxis();
288 QCategoriesAxis* axis = new QCategoriesAxis();
296 axis->append(category);
289 axis->append(category);
297 m_chart->setAxisX(axis,series);
290 m_chart->setAxisX(axis,series);
298 }
291 }
299
292
300 for (int j(0); j < data.count(); j++) {
293 for (int j(0); j < data.count(); j++) {
301 QList<qreal> column = data.at(j);
294 QList<qreal> column = data.at(j);
302 QBarSet *set = new QBarSet("set" + QString::number(j));
295 QBarSet *set = new QBarSet("set" + QString::number(j));
303 for (int i(0); i < column.count(); i++)
296 for (int i(0); i < column.count(); i++)
304 *set << column.at(i);
297 *set << column.at(i);
305 series->append(set);
298 series->append(set);
306 }
299 }
307
300
308 m_chart->addSeries(series);
301 m_chart->addSeries(series);
309 } else if (seriesName == "Spline") {
302 } else if (seriesName == "Spline") {
310 for (int j(0); j < data.count(); j ++) {
303 for (int j(0); j < data.count(); j ++) {
311 QList<qreal> column = data.at(j);
304 QList<qreal> column = data.at(j);
312 QSplineSeries *series = new QSplineSeries();
305 QSplineSeries *series = new QSplineSeries();
313 for (int i(0); i < column.count(); i++)
306 for (int i(0); i < column.count(); i++)
314 series->append(i, column.at(i));
307 series->append(i, column.at(i));
315 m_chart->addSeries(series);
308 m_chart->addSeries(series);
316 }
309 }
317 }
310 }
318 m_chart->createDefaultAxes();
311 m_chart->createDefaultAxes();
319 }
312 }
320
313
321 void MainWidget::backgroundChanged(int itemIndex)
314 void MainWidget::backgroundChanged(int itemIndex)
322 {
315 {
323 qDebug() << "backgroundChanged: " << itemIndex;
316 qDebug() << "backgroundChanged: " << itemIndex;
324 }
317 }
325
318
326 void MainWidget::autoScaleChanged(int value)
319 void MainWidget::autoScaleChanged(int value)
327 {
320 {
328 if (value) {
321 if (value) {
329 // TODO: enable auto scaling
322 // TODO: enable auto scaling
330 } else {
323 } else {
331 // TODO: set scaling manually (and disable auto scaling)
324 // TODO: set scaling manually (and disable auto scaling)
332 }
325 }
333
326
334 m_xMinSpin->setEnabled(!value);
327 m_xMinSpin->setEnabled(!value);
335 m_xMaxSpin->setEnabled(!value);
328 m_xMaxSpin->setEnabled(!value);
336 m_yMinSpin->setEnabled(!value);
329 m_yMinSpin->setEnabled(!value);
337 m_yMaxSpin->setEnabled(!value);
330 m_yMaxSpin->setEnabled(!value);
338 }
331 }
339
332
340 void MainWidget::xMinChanged(int value)
333 void MainWidget::xMinChanged(int value)
341 {
334 {
342 qDebug() << "xMinChanged: " << value;
335 qDebug() << "xMinChanged: " << value;
343 }
336 }
344
337
345 void MainWidget::xMaxChanged(int value)
338 void MainWidget::xMaxChanged(int value)
346 {
339 {
347 qDebug() << "xMaxChanged: " << value;
340 qDebug() << "xMaxChanged: " << value;
348 }
341 }
349
342
350 void MainWidget::yMinChanged(int value)
343 void MainWidget::yMinChanged(int value)
351 {
344 {
352 qDebug() << "yMinChanged: " << value;
345 qDebug() << "yMinChanged: " << value;
353 }
346 }
354
347
355 void MainWidget::yMaxChanged(int value)
348 void MainWidget::yMaxChanged(int value)
356 {
349 {
357 qDebug() << "yMaxChanged: " << value;
350 qDebug() << "yMaxChanged: " << value;
358 }
351 }
359
352
360 void MainWidget::changeChartTheme(int themeIndex)
353 void MainWidget::changeChartTheme(int themeIndex)
361 {
354 {
362 qDebug() << "changeChartTheme: " << themeIndex;
355 qDebug() << "changeChartTheme: " << themeIndex;
363 m_chart->setTheme((QChart::ChartTheme) themeIndex);
356 m_chart->setTheme((QChart::ChartTheme) themeIndex);
364 }
357 }
General Comments 0
You need to be logged in to leave comments. Login now