##// END OF EJS Templates
Fix setTheme() docs and lineseries test
Jani Honkonen -
r1250:7fae50a1e446
parent child
Show More
@@ -1,470 +1,472
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qchart.h"
21 #include "qchart.h"
22 #include "qchart_p.h"
22 #include "qchart_p.h"
23 #include "legendscroller_p.h"
23 #include "legendscroller_p.h"
24 #include "qlegend_p.h"
24 #include "qlegend_p.h"
25 #include "chartbackground_p.h"
25 #include "chartbackground_p.h"
26 #include "qaxis.h"
26 #include "qaxis.h"
27 #include <QGraphicsScene>
27 #include <QGraphicsScene>
28 #include <QGraphicsSceneResizeEvent>
28 #include <QGraphicsSceneResizeEvent>
29
29
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31
31
32 /*!
32 /*!
33 \enum QChart::ChartTheme
33 \enum QChart::ChartTheme
34
34
35 This enum describes the theme used by the chart.
35 This enum describes the theme used by the chart.
36
36
37 \value ChartThemeLight The default theme
37 \value ChartThemeLight The default theme
38 \value ChartThemeBlueCerulean
38 \value ChartThemeBlueCerulean
39 \value ChartThemeDark
39 \value ChartThemeDark
40 \value ChartThemeBrownSand
40 \value ChartThemeBrownSand
41 \value ChartThemeBlueNcs
41 \value ChartThemeBlueNcs
42 \value ChartThemeHighContrast
42 \value ChartThemeHighContrast
43 \value ChartThemeBlueIcy
43 \value ChartThemeBlueIcy
44 */
44 */
45
45
46 /*!
46 /*!
47 \enum QChart::AnimationOption
47 \enum QChart::AnimationOption
48
48
49 For enabling/disabling animations. Defaults to NoAnimation.
49 For enabling/disabling animations. Defaults to NoAnimation.
50
50
51 \value NoAnimation
51 \value NoAnimation
52 \value GridAxisAnimations
52 \value GridAxisAnimations
53 \value SeriesAnimations
53 \value SeriesAnimations
54 \value AllAnimations
54 \value AllAnimations
55 */
55 */
56
56
57 /*!
57 /*!
58 \class QChart
58 \class QChart
59 \brief QtCommercial chart API.
59 \brief QtCommercial chart API.
60
60
61 QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical
61 QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical
62 representation of different types of series and other chart related objects like
62 representation of different types of series and other chart related objects like
63 QAxis and QLegend. If you simply want to show a chart in a layout, you can use the
63 QAxis and QLegend. If you simply want to show a chart in a layout, you can use the
64 convenience class QChartView instead of QChart.
64 convenience class QChartView instead of QChart.
65 \sa QChartView
65 \sa QChartView
66 */
66 */
67
67
68 /*!
68 /*!
69 Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor.
69 Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor.
70 */
70 */
71 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags),
71 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags),
72 d_ptr(new QChartPrivate())
72 d_ptr(new QChartPrivate())
73 {
73 {
74 d_ptr->m_dataset = new ChartDataSet(this);
74 d_ptr->m_dataset = new ChartDataSet(this);
75 d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset);
75 d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset);
76 d_ptr->createConnections();
76 d_ptr->createConnections();
77 d_ptr->m_legend = new LegendScroller(this);
77 d_ptr->m_legend = new LegendScroller(this);
78 d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false);
78 d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false);
79 }
79 }
80
80
81 /*!
81 /*!
82 Destroys the object and it's children, like series and axis objects added to it.
82 Destroys the object and it's children, like series and axis objects added to it.
83 */
83 */
84 QChart::~QChart()
84 QChart::~QChart()
85 {
85 {
86 //delete first presenter , since this is a root of all the graphical items
86 //delete first presenter , since this is a root of all the graphical items
87 delete d_ptr->m_presenter;
87 delete d_ptr->m_presenter;
88 d_ptr->m_presenter=0;
88 d_ptr->m_presenter=0;
89 }
89 }
90
90
91 /*!
91 /*!
92 Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects.
92 Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects.
93 If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and
93 If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and
94 the y axis).
94 the y axis).
95 */
95 */
96 void QChart::addSeries(QAbstractSeries *series, QAxis *axisY)
96 void QChart::addSeries(QAbstractSeries *series, QAxis *axisY)
97 {
97 {
98 Q_ASSERT(series);
98 Q_ASSERT(series);
99 d_ptr->m_dataset->addSeries(series, axisY);
99 d_ptr->m_dataset->addSeries(series, axisY);
100 }
100 }
101
101
102 /*!
102 /*!
103 Removes the \a series specified in a perameter from the QChartView.
103 Removes the \a series specified in a perameter from the QChartView.
104 It releses its ownership of the specified QChartSeries object.
104 It releses its ownership of the specified QChartSeries object.
105 It does not delete the pointed QChartSeries data object
105 It does not delete the pointed QChartSeries data object
106 \sa addSeries(), removeAllSeries()
106 \sa addSeries(), removeAllSeries()
107 */
107 */
108 void QChart::removeSeries(QAbstractSeries *series)
108 void QChart::removeSeries(QAbstractSeries *series)
109 {
109 {
110 Q_ASSERT(series);
110 Q_ASSERT(series);
111 d_ptr->m_dataset->removeSeries(series);
111 d_ptr->m_dataset->removeSeries(series);
112 }
112 }
113
113
114 /*!
114 /*!
115 Removes all the QChartSeries that have been added to the QChartView
115 Removes all the QChartSeries that have been added to the QChartView
116 It also deletes the pointed QChartSeries data objects
116 It also deletes the pointed QChartSeries data objects
117 \sa addSeries(), removeSeries()
117 \sa addSeries(), removeSeries()
118 */
118 */
119 void QChart::removeAllSeries()
119 void QChart::removeAllSeries()
120 {
120 {
121 d_ptr->m_dataset->removeAllSeries();
121 d_ptr->m_dataset->removeAllSeries();
122 }
122 }
123
123
124 /*!
124 /*!
125 Sets the \a brush that is used for painting the background of the chart area.
125 Sets the \a brush that is used for painting the background of the chart area.
126 */
126 */
127 void QChart::setBackgroundBrush(const QBrush& brush)
127 void QChart::setBackgroundBrush(const QBrush& brush)
128 {
128 {
129 //TODO: refactor me
129 //TODO: refactor me
130 d_ptr->m_presenter->createChartBackgroundItem();
130 d_ptr->m_presenter->createChartBackgroundItem();
131 d_ptr->m_presenter->m_backgroundItem->setBrush(brush);
131 d_ptr->m_presenter->m_backgroundItem->setBrush(brush);
132 d_ptr->m_presenter->m_backgroundItem->update();
132 d_ptr->m_presenter->m_backgroundItem->update();
133 }
133 }
134
134
135 /*!
135 /*!
136 Gets the brush that is used for painting the background of the chart area.
136 Gets the brush that is used for painting the background of the chart area.
137 */
137 */
138 QBrush QChart::backgroundBrush() const
138 QBrush QChart::backgroundBrush() const
139 {
139 {
140 //TODO: refactor me
140 //TODO: refactor me
141 if (!d_ptr->m_presenter->m_backgroundItem) return QBrush();
141 if (!d_ptr->m_presenter->m_backgroundItem) return QBrush();
142 return (d_ptr->m_presenter->m_backgroundItem)->brush();
142 return (d_ptr->m_presenter->m_backgroundItem)->brush();
143 }
143 }
144
144
145 /*!
145 /*!
146 Sets the \a pen that is used for painting the background of the chart area.
146 Sets the \a pen that is used for painting the background of the chart area.
147 */
147 */
148 void QChart::setBackgroundPen(const QPen& pen)
148 void QChart::setBackgroundPen(const QPen& pen)
149 {
149 {
150 //TODO: refactor me
150 //TODO: refactor me
151 d_ptr->m_presenter->createChartBackgroundItem();
151 d_ptr->m_presenter->createChartBackgroundItem();
152 d_ptr->m_presenter->m_backgroundItem->setPen(pen);
152 d_ptr->m_presenter->m_backgroundItem->setPen(pen);
153 d_ptr->m_presenter->m_backgroundItem->update();
153 d_ptr->m_presenter->m_backgroundItem->update();
154 }
154 }
155
155
156 /*!
156 /*!
157 Gets the pen that is used for painting the background of the chart area.
157 Gets the pen that is used for painting the background of the chart area.
158 */
158 */
159 QPen QChart::backgroundPen() const
159 QPen QChart::backgroundPen() const
160 {
160 {
161 //TODO: refactor me
161 //TODO: refactor me
162 if (!d_ptr->m_presenter->m_backgroundItem) return QPen();
162 if (!d_ptr->m_presenter->m_backgroundItem) return QPen();
163 return d_ptr->m_presenter->m_backgroundItem->pen();
163 return d_ptr->m_presenter->m_backgroundItem->pen();
164 }
164 }
165
165
166 /*!
166 /*!
167 Sets the chart \a title. The description text that is drawn above the chart.
167 Sets the chart \a title. The description text that is drawn above the chart.
168 */
168 */
169 void QChart::setTitle(const QString& title)
169 void QChart::setTitle(const QString& title)
170 {
170 {
171 //TODO: refactor me
171 //TODO: refactor me
172 d_ptr->m_presenter->createChartTitleItem();
172 d_ptr->m_presenter->createChartTitleItem();
173 d_ptr->m_presenter->m_titleItem->setText(title);
173 d_ptr->m_presenter->m_titleItem->setText(title);
174 d_ptr->m_presenter->updateLayout();
174 d_ptr->m_presenter->updateLayout();
175 }
175 }
176
176
177 /*!
177 /*!
178 Returns the chart title. The description text that is drawn above the chart.
178 Returns the chart title. The description text that is drawn above the chart.
179 */
179 */
180 QString QChart::title() const
180 QString QChart::title() const
181 {
181 {
182 //TODO: refactor me
182 //TODO: refactor me
183 if (d_ptr->m_presenter->m_titleItem)
183 if (d_ptr->m_presenter->m_titleItem)
184 return d_ptr->m_presenter->m_titleItem->text();
184 return d_ptr->m_presenter->m_titleItem->text();
185 else
185 else
186 return QString();
186 return QString();
187 }
187 }
188
188
189 /*!
189 /*!
190 Sets the \a font that is used for drawing the chart description text that is rendered above the chart.
190 Sets the \a font that is used for drawing the chart description text that is rendered above the chart.
191 */
191 */
192 void QChart::setTitleFont(const QFont& font)
192 void QChart::setTitleFont(const QFont& font)
193 {
193 {
194 //TODO: refactor me
194 //TODO: refactor me
195 d_ptr->m_presenter->createChartTitleItem();
195 d_ptr->m_presenter->createChartTitleItem();
196 d_ptr->m_presenter->m_titleItem->setFont(font);
196 d_ptr->m_presenter->m_titleItem->setFont(font);
197 d_ptr->m_presenter->updateLayout();
197 d_ptr->m_presenter->updateLayout();
198 }
198 }
199
199
200 /*!
200 /*!
201 Gets the font that is used for drawing the chart description text that is rendered above the chart.
201 Gets the font that is used for drawing the chart description text that is rendered above the chart.
202 */
202 */
203 QFont QChart::titleFont() const
203 QFont QChart::titleFont() const
204 {
204 {
205 if (d_ptr->m_presenter->m_titleItem)
205 if (d_ptr->m_presenter->m_titleItem)
206 return d_ptr->m_presenter->m_titleItem->font();
206 return d_ptr->m_presenter->m_titleItem->font();
207 else
207 else
208 return QFont();
208 return QFont();
209 }
209 }
210
210
211 /*!
211 /*!
212 Sets the \a brush used for rendering the title text.
212 Sets the \a brush used for rendering the title text.
213 */
213 */
214 void QChart::setTitleBrush(const QBrush &brush)
214 void QChart::setTitleBrush(const QBrush &brush)
215 {
215 {
216 //TODO: refactor me
216 //TODO: refactor me
217 d_ptr->m_presenter->createChartTitleItem();
217 d_ptr->m_presenter->createChartTitleItem();
218 d_ptr->m_presenter->m_titleItem->setBrush(brush);
218 d_ptr->m_presenter->m_titleItem->setBrush(brush);
219 d_ptr->m_presenter->updateLayout();
219 d_ptr->m_presenter->updateLayout();
220 }
220 }
221
221
222 /*!
222 /*!
223 Returns the brush used for rendering the title text.
223 Returns the brush used for rendering the title text.
224 */
224 */
225 QBrush QChart::titleBrush() const
225 QBrush QChart::titleBrush() const
226 {
226 {
227 //TODO: refactor me
227 //TODO: refactor me
228 if (!d_ptr->m_presenter->m_titleItem) return QBrush();
228 if (!d_ptr->m_presenter->m_titleItem) return QBrush();
229 return d_ptr->m_presenter->m_titleItem->brush();
229 return d_ptr->m_presenter->m_titleItem->brush();
230 }
230 }
231
231
232 /*!
232 /*!
233 Sets the \a theme used by the chart for rendering the graphical representation of the data
233 Sets the \a theme used by the chart for rendering the graphical representation of the data.
234
235 Note: changing the theme will overwrite all customizations (pen, brush, font, ect.) done to the series.
234 \sa theme()
236 \sa theme()
235 */
237 */
236 void QChart::setTheme(QChart::ChartTheme theme)
238 void QChart::setTheme(QChart::ChartTheme theme)
237 {
239 {
238 d_ptr->m_presenter->setTheme(theme);
240 d_ptr->m_presenter->setTheme(theme);
239 }
241 }
240
242
241 /*!
243 /*!
242 Returns the theme enum used by the chart.
244 Returns the theme enum used by the chart.
243 \sa ChartTheme, setTheme()
245 \sa ChartTheme, setTheme()
244 */
246 */
245 QChart::ChartTheme QChart::theme() const
247 QChart::ChartTheme QChart::theme() const
246 {
248 {
247 return d_ptr->m_presenter->theme();
249 return d_ptr->m_presenter->theme();
248 }
250 }
249
251
250 /*!
252 /*!
251 Zooms in the view by a factor of 2
253 Zooms in the view by a factor of 2
252 */
254 */
253 void QChart::zoomIn()
255 void QChart::zoomIn()
254 {
256 {
255 d_ptr->m_presenter->zoomIn(2.0);
257 d_ptr->m_presenter->zoomIn(2.0);
256 }
258 }
257
259
258 /*!
260 /*!
259 Zooms in the view to a maximum level at which \a rect is still fully visible.
261 Zooms in the view to a maximum level at which \a rect is still fully visible.
260 */
262 */
261 void QChart::zoomIn(const QRectF& rect)
263 void QChart::zoomIn(const QRectF& rect)
262 {
264 {
263 if (!rect.isValid()) return;
265 if (!rect.isValid()) return;
264 d_ptr->m_presenter->zoomIn(rect);
266 d_ptr->m_presenter->zoomIn(rect);
265 }
267 }
266
268
267 /*!
269 /*!
268 Restores the view zoom level to the previous one.
270 Restores the view zoom level to the previous one.
269 */
271 */
270 void QChart::zoomOut()
272 void QChart::zoomOut()
271 {
273 {
272 d_ptr->m_presenter->zoomOut(2.0);
274 d_ptr->m_presenter->zoomOut(2.0);
273 }
275 }
274
276
275 /*!
277 /*!
276 Zooms in the view by a \a factor.
278 Zooms in the view by a \a factor.
277
279
278 A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out.
280 A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out.
279 */
281 */
280 void QChart::zoom(qreal factor)
282 void QChart::zoom(qreal factor)
281 {
283 {
282 if (qFuzzyIsNull(factor))
284 if (qFuzzyIsNull(factor))
283 return;
285 return;
284
286
285 if (qFuzzyCompare(factor, 1.0))
287 if (qFuzzyCompare(factor, 1.0))
286 return;
288 return;
287
289
288 if (factor < 0)
290 if (factor < 0)
289 return;
291 return;
290
292
291 if (factor > 1.0)
293 if (factor > 1.0)
292 d_ptr->m_presenter->zoomIn(factor);
294 d_ptr->m_presenter->zoomIn(factor);
293 else
295 else
294 d_ptr->m_presenter->zoomOut(1.0 / factor);
296 d_ptr->m_presenter->zoomOut(1.0 / factor);
295 }
297 }
296
298
297 /*!
299 /*!
298 Returns the pointer to the x axis object of the chart
300 Returns the pointer to the x axis object of the chart
299 */
301 */
300 QAxis* QChart::axisX() const
302 QAxis* QChart::axisX() const
301 {
303 {
302 return d_ptr->m_dataset->axisX();
304 return d_ptr->m_dataset->axisX();
303 }
305 }
304
306
305 /*!
307 /*!
306 Returns the pointer to the y axis object of the \a series
308 Returns the pointer to the y axis object of the \a series
307 If no \a series is provided then default Y axis of the chart is returned.
309 If no \a series is provided then default Y axis of the chart is returned.
308 */
310 */
309 QAxis* QChart::axisY(QAbstractSeries *series) const
311 QAxis* QChart::axisY(QAbstractSeries *series) const
310 {
312 {
311 return d_ptr->m_dataset->axisY(series);
313 return d_ptr->m_dataset->axisY(series);
312 }
314 }
313
315
314 /*!
316 /*!
315 Returns the legend object of the chart. Ownership stays in chart.
317 Returns the legend object of the chart. Ownership stays in chart.
316 */
318 */
317 QLegend* QChart::legend() const
319 QLegend* QChart::legend() const
318 {
320 {
319 return d_ptr->m_legend;
321 return d_ptr->m_legend;
320 }
322 }
321
323
322 /*!
324 /*!
323 Returns the rect that contains information about margins (distance between chart widget edge and axes).
325 Returns the rect that contains information about margins (distance between chart widget edge and axes).
324 Individual margins can be obtained by calling left, top, right, bottom on the returned rect.
326 Individual margins can be obtained by calling left, top, right, bottom on the returned rect.
325 */
327 */
326 QRectF QChart::margins() const
328 QRectF QChart::margins() const
327 {
329 {
328 return d_ptr->m_presenter->margins();
330 return d_ptr->m_presenter->margins();
329 }
331 }
330
332
331
333
332 /*!
334 /*!
333 Resizes and updates the chart area using the \a event data
335 Resizes and updates the chart area using the \a event data
334 */
336 */
335 void QChart::resizeEvent(QGraphicsSceneResizeEvent *event)
337 void QChart::resizeEvent(QGraphicsSceneResizeEvent *event)
336 {
338 {
337 d_ptr->m_rect = QRectF(QPoint(0,0),event->newSize());
339 d_ptr->m_rect = QRectF(QPoint(0,0),event->newSize());
338 QGraphicsWidget::resizeEvent(event);
340 QGraphicsWidget::resizeEvent(event);
339 d_ptr->m_presenter->setGeometry(d_ptr->m_rect);
341 d_ptr->m_presenter->setGeometry(d_ptr->m_rect);
340 }
342 }
341
343
342 /*!
344 /*!
343 Sets animation \a options for the chart
345 Sets animation \a options for the chart
344 */
346 */
345 void QChart::setAnimationOptions(AnimationOptions options)
347 void QChart::setAnimationOptions(AnimationOptions options)
346 {
348 {
347 d_ptr->m_presenter->setAnimationOptions(options);
349 d_ptr->m_presenter->setAnimationOptions(options);
348 }
350 }
349
351
350 /*!
352 /*!
351 Returns animation options for the chart
353 Returns animation options for the chart
352 */
354 */
353 QChart::AnimationOptions QChart::animationOptions() const
355 QChart::AnimationOptions QChart::animationOptions() const
354 {
356 {
355 return d_ptr->m_presenter->animationOptions();
357 return d_ptr->m_presenter->animationOptions();
356 }
358 }
357
359
358 /*!
360 /*!
359 Scrolls the visible area of the chart to the left by the distance between two x axis ticks
361 Scrolls the visible area of the chart to the left by the distance between two x axis ticks
360 */
362 */
361 void QChart::scrollLeft()
363 void QChart::scrollLeft()
362 {
364 {
363 d_ptr->m_presenter->scroll(-d_ptr->m_presenter->chartGeometry().width()/(axisX()->ticksCount()-1),0);
365 d_ptr->m_presenter->scroll(-d_ptr->m_presenter->chartGeometry().width()/(axisX()->ticksCount()-1),0);
364 }
366 }
365
367
366 /*!
368 /*!
367 Scrolls the visible area of the chart to the right by the distance between two x axis ticks
369 Scrolls the visible area of the chart to the right by the distance between two x axis ticks
368 */
370 */
369 void QChart::scrollRight()
371 void QChart::scrollRight()
370 {
372 {
371 d_ptr->m_presenter->scroll(d_ptr->m_presenter->chartGeometry().width()/(axisX()->ticksCount()-1),0);
373 d_ptr->m_presenter->scroll(d_ptr->m_presenter->chartGeometry().width()/(axisX()->ticksCount()-1),0);
372 }
374 }
373
375
374 /*!
376 /*!
375 Scrolls the visible area of the chart up by the distance between two y axis ticks
377 Scrolls the visible area of the chart up by the distance between two y axis ticks
376 */
378 */
377 void QChart::scrollUp()
379 void QChart::scrollUp()
378 {
380 {
379 d_ptr->m_presenter->scroll(0,d_ptr->m_presenter->chartGeometry().width()/(axisY()->ticksCount()-1));
381 d_ptr->m_presenter->scroll(0,d_ptr->m_presenter->chartGeometry().width()/(axisY()->ticksCount()-1));
380 }
382 }
381
383
382 /*!
384 /*!
383 Scrolls the visible area of the chart down by the distance between two y axis ticks
385 Scrolls the visible area of the chart down by the distance between two y axis ticks
384 */
386 */
385 void QChart::scrollDown()
387 void QChart::scrollDown()
386 {
388 {
387 d_ptr->m_presenter->scroll(0,-d_ptr->m_presenter->chartGeometry().width()/(axisY()->ticksCount()-1));
389 d_ptr->m_presenter->scroll(0,-d_ptr->m_presenter->chartGeometry().width()/(axisY()->ticksCount()-1));
388 }
390 }
389
391
390 /*!
392 /*!
391 Scrolls the visible area of the chart by the distance defined in the \a delta.
393 Scrolls the visible area of the chart by the distance defined in the \a delta.
392 */
394 */
393 void QChart::scroll(const QPointF &delta)
395 void QChart::scroll(const QPointF &delta)
394 {
396 {
395 d_ptr->m_presenter->scroll(-delta.x(), delta.y());
397 d_ptr->m_presenter->scroll(-delta.x(), delta.y());
396 }
398 }
397
399
398 /*!
400 /*!
399 Sets the chart background visibility state to \a visible
401 Sets the chart background visibility state to \a visible
400 */
402 */
401 void QChart::setBackgroundVisible(bool visible)
403 void QChart::setBackgroundVisible(bool visible)
402 {
404 {
403 //TODO: refactor me
405 //TODO: refactor me
404 d_ptr->m_presenter->createChartBackgroundItem();
406 d_ptr->m_presenter->createChartBackgroundItem();
405 d_ptr->m_presenter->m_backgroundItem->setVisible(visible);
407 d_ptr->m_presenter->m_backgroundItem->setVisible(visible);
406 }
408 }
407
409
408 /*!
410 /*!
409 Returns the chart's background visibility state
411 Returns the chart's background visibility state
410 */
412 */
411 bool QChart::isBackgroundVisible() const
413 bool QChart::isBackgroundVisible() const
412 {
414 {
413 //TODO: refactor me
415 //TODO: refactor me
414 if (!d_ptr->m_presenter->m_backgroundItem)
416 if (!d_ptr->m_presenter->m_backgroundItem)
415 return false;
417 return false;
416
418
417 return d_ptr->m_presenter->m_backgroundItem->isVisible();
419 return d_ptr->m_presenter->m_backgroundItem->isVisible();
418 }
420 }
419
421
420 /*!
422 /*!
421 Sets the background drop shadow effect state to \a enabled.
423 Sets the background drop shadow effect state to \a enabled.
422 */
424 */
423 void QChart::setBackgroundDropShadowEnabled(bool enabled)
425 void QChart::setBackgroundDropShadowEnabled(bool enabled)
424 {
426 {
425 d_ptr->m_presenter->createChartBackgroundItem();
427 d_ptr->m_presenter->createChartBackgroundItem();
426 d_ptr->m_presenter->m_backgroundItem->setDropShadowEnabled(enabled);
428 d_ptr->m_presenter->m_backgroundItem->setDropShadowEnabled(enabled);
427 }
429 }
428
430
429 /*!
431 /*!
430 Returns true if the drop shadow effect is enabled for the chart background.
432 Returns true if the drop shadow effect is enabled for the chart background.
431 */
433 */
432 bool QChart::isBackgroundDropShadowEnabled() const
434 bool QChart::isBackgroundDropShadowEnabled() const
433 {
435 {
434 if (!d_ptr->m_presenter->m_backgroundItem)
436 if (!d_ptr->m_presenter->m_backgroundItem)
435 return false;
437 return false;
436
438
437 return d_ptr->m_presenter->m_backgroundItem->isDropShadowEnabled();
439 return d_ptr->m_presenter->m_backgroundItem->isDropShadowEnabled();
438 }
440 }
439
441
440 QList<QAbstractSeries*> QChart::series() const
442 QList<QAbstractSeries*> QChart::series() const
441 {
443 {
442 return d_ptr->m_dataset->series();
444 return d_ptr->m_dataset->series();
443 }
445 }
444
446
445 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
447 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
446
448
447 QChartPrivate::QChartPrivate():
449 QChartPrivate::QChartPrivate():
448 m_legend(0),
450 m_legend(0),
449 m_dataset(0),
451 m_dataset(0),
450 m_presenter(0)
452 m_presenter(0)
451 {
453 {
452
454
453 }
455 }
454
456
455 QChartPrivate::~QChartPrivate()
457 QChartPrivate::~QChartPrivate()
456 {
458 {
457
459
458 }
460 }
459
461
460 void QChartPrivate::createConnections()
462 void QChartPrivate::createConnections()
461 {
463 {
462 QObject::connect(m_dataset,SIGNAL(seriesAdded(QAbstractSeries*,Domain*)),m_presenter,SLOT(handleSeriesAdded(QAbstractSeries*,Domain*)));
464 QObject::connect(m_dataset,SIGNAL(seriesAdded(QAbstractSeries*,Domain*)),m_presenter,SLOT(handleSeriesAdded(QAbstractSeries*,Domain*)));
463 QObject::connect(m_dataset,SIGNAL(seriesRemoved(QAbstractSeries*)),m_presenter,SLOT(handleSeriesRemoved(QAbstractSeries*)));
465 QObject::connect(m_dataset,SIGNAL(seriesRemoved(QAbstractSeries*)),m_presenter,SLOT(handleSeriesRemoved(QAbstractSeries*)));
464 QObject::connect(m_dataset,SIGNAL(axisAdded(QAxis*,Domain*)),m_presenter,SLOT(handleAxisAdded(QAxis*,Domain*)));
466 QObject::connect(m_dataset,SIGNAL(axisAdded(QAxis*,Domain*)),m_presenter,SLOT(handleAxisAdded(QAxis*,Domain*)));
465 QObject::connect(m_dataset,SIGNAL(axisRemoved(QAxis*)),m_presenter,SLOT(handleAxisRemoved(QAxis*)));
467 QObject::connect(m_dataset,SIGNAL(axisRemoved(QAxis*)),m_presenter,SLOT(handleAxisRemoved(QAxis*)));
466 }
468 }
467
469
468 #include "moc_qchart.cpp"
470 #include "moc_qchart.cpp"
469
471
470 QTCOMMERCIALCHART_END_NAMESPACE
472 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,451 +1,451
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include <QtTest/QtTest>
21 #include <QtTest/QtTest>
22 #include <qlineseries.h>
22 #include <qlineseries.h>
23 #include <qxymodelmapper.h>
23 #include <qxymodelmapper.h>
24 #include <qchartview.h>
24 #include <qchartview.h>
25 #include <QStandardItemModel>
25 #include <QStandardItemModel>
26 #include <tst_definitions.h>
26 #include <tst_definitions.h>
27
27
28 Q_DECLARE_METATYPE(QList<QPointF>)
28 Q_DECLARE_METATYPE(QList<QPointF>)
29
29
30 QTCOMMERCIALCHART_USE_NAMESPACE
30 QTCOMMERCIALCHART_USE_NAMESPACE
31
31
32 class tst_QLineSeries : public QObject
32 class tst_QLineSeries : 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 qlineseries_data();
43 void qlineseries_data();
44 void qlineseries();
44 void qlineseries();
45 void append_raw_data();
45 void append_raw_data();
46 void append_raw();
46 void append_raw();
47 void append_chart_data();
47 void append_chart_data();
48 void append_chart();
48 void append_chart();
49 void append_chart_animation_data();
49 void append_chart_animation_data();
50 void append_chart_animation();
50 void append_chart_animation();
51 void chart_append_data();
51 void chart_append_data();
52 void chart_append();
52 void chart_append();
53 void count_raw_data();
53 void count_raw_data();
54 void count_raw();
54 void count_raw();
55 void oper_data();
55 void oper_data();
56 void oper();
56 void oper();
57 void pen_data();
57 void pen_data();
58 void pen();
58 void pen();
59 void pointsVisible_raw_data();
59 void pointsVisible_raw_data();
60 void pointsVisible_raw();
60 void pointsVisible_raw();
61 void remove_raw_data();
61 void remove_raw_data();
62 void remove_raw();
62 void remove_raw();
63 void remove_chart_data();
63 void remove_chart_data();
64 void remove_chart();
64 void remove_chart();
65 void remove_chart_animation_data();
65 void remove_chart_animation_data();
66 void remove_chart_animation();
66 void remove_chart_animation();
67 void removeAll_raw_data();
67 void removeAll_raw_data();
68 void removeAll_raw();
68 void removeAll_raw();
69 void removeAll_chart_data();
69 void removeAll_chart_data();
70 void removeAll_chart();
70 void removeAll_chart();
71 void removeAll_chart_animation_data();
71 void removeAll_chart_animation_data();
72 void removeAll_chart_animation();
72 void removeAll_chart_animation();
73 void replace_raw_data();
73 void replace_raw_data();
74 void replace_raw();
74 void replace_raw();
75 void replace_chart_data();
75 void replace_chart_data();
76 void replace_chart();
76 void replace_chart();
77 void replace_chart_animation_data();
77 void replace_chart_animation_data();
78 void replace_chart_animation();
78 void replace_chart_animation();
79 private:
79 private:
80 void append_data();
80 void append_data();
81 void count_data();
81 void count_data();
82 void pointsVisible_data();
82 void pointsVisible_data();
83
83
84 private:
84 private:
85 QChartView* m_view;
85 QChartView* m_view;
86 QChart* m_chart;
86 QChart* m_chart;
87 QLineSeries* m_series;
87 QLineSeries* m_series;
88 };
88 };
89
89
90 void tst_QLineSeries::initTestCase()
90 void tst_QLineSeries::initTestCase()
91 {
91 {
92 }
92 }
93
93
94 void tst_QLineSeries::cleanupTestCase()
94 void tst_QLineSeries::cleanupTestCase()
95 {
95 {
96 }
96 }
97
97
98 void tst_QLineSeries::init()
98 void tst_QLineSeries::init()
99 {
99 {
100 m_view = new QChartView(new QChart());
100 m_view = new QChartView(new QChart());
101 m_chart = m_view->chart();
101 m_chart = m_view->chart();
102 m_series = new QLineSeries();
102 m_series = new QLineSeries();
103 }
103 }
104
104
105 void tst_QLineSeries::cleanup()
105 void tst_QLineSeries::cleanup()
106 {
106 {
107 delete m_series;
107 delete m_series;
108 delete m_view;
108 delete m_view;
109 m_view = 0;
109 m_view = 0;
110 m_chart = 0;
110 m_chart = 0;
111 m_series = 0;
111 m_series = 0;
112 }
112 }
113
113
114 void tst_QLineSeries::qlineseries_data()
114 void tst_QLineSeries::qlineseries_data()
115 {
115 {
116
116
117 }
117 }
118
118
119 void tst_QLineSeries::qlineseries()
119 void tst_QLineSeries::qlineseries()
120 {
120 {
121 QLineSeries series;
121 QLineSeries series;
122
122
123 QCOMPARE(series.count(),0);
123 QCOMPARE(series.count(),0);
124 QCOMPARE(series.brush(), QBrush());
124 QCOMPARE(series.brush(), QBrush());
125 QCOMPARE(series.points(), QList<QPointF>());
125 QCOMPARE(series.points(), QList<QPointF>());
126 QCOMPARE(series.pen(), QPen());
126 QCOMPARE(series.pen(), QPen());
127 QCOMPARE(series.pointsVisible(), false);
127 QCOMPARE(series.pointsVisible(), false);
128
128
129 series.append(QList<QPointF>());
129 series.append(QList<QPointF>());
130 series.append(0.0,0.0);
130 series.append(0.0,0.0);
131 series.append(QPointF());
131 series.append(QPointF());
132
132
133 series.remove(0.0,0.0);
133 series.remove(0.0,0.0);
134 series.remove(QPointF());
134 series.remove(QPointF());
135 series.removeAll();
135 series.removeAll();
136
136
137 series.replace(QPointF(),QPointF());
137 series.replace(QPointF(),QPointF());
138 series.replace(0,0,0,0);
138 series.replace(0,0,0,0);
139 series.setBrush(QBrush());
139 series.setBrush(QBrush());
140
140
141 // QCOMPARE(series.setModel((QAbstractItemModel*)0), false);
141 // QCOMPARE(series.setModel((QAbstractItemModel*)0), false);
142
142
143 // series.setModelMapping(-1, -1, Qt::Orientation(0));
143 // series.setModelMapping(-1, -1, Qt::Orientation(0));
144
144
145 series.setPen(QPen());
145 series.setPen(QPen());
146 series.setPointsVisible(false);
146 series.setPointsVisible(false);
147
147
148 m_chart->addSeries(&series);
148 m_chart->addSeries(&series);
149 m_view->show();
149 m_view->show();
150 QTest::qWaitForWindowShown(m_view);
150 QTest::qWaitForWindowShown(m_view);
151 }
151 }
152
152
153 void tst_QLineSeries::append_data()
153 void tst_QLineSeries::append_data()
154 {
154 {
155 QTest::addColumn< QList<QPointF> >("points");
155 QTest::addColumn< QList<QPointF> >("points");
156 QTest::newRow("0,0 1,1 2,2 3,3") << (QList<QPointF>() << QPointF(0,0) << QPointF(1,1) << QPointF(2,2) << QPointF(3,3));
156 QTest::newRow("0,0 1,1 2,2 3,3") << (QList<QPointF>() << QPointF(0,0) << QPointF(1,1) << QPointF(2,2) << QPointF(3,3));
157 QTest::newRow("0,0 -1,-1 -2,-2 -3,-3") << (QList<QPointF>() << QPointF(0,0) << QPointF(-1,-1) << QPointF(-2,-2) << QPointF(-3,-3));
157 QTest::newRow("0,0 -1,-1 -2,-2 -3,-3") << (QList<QPointF>() << QPointF(0,0) << QPointF(-1,-1) << QPointF(-2,-2) << QPointF(-3,-3));
158 }
158 }
159
159
160
160
161 void tst_QLineSeries::append_raw_data()
161 void tst_QLineSeries::append_raw_data()
162 {
162 {
163 append_data();
163 append_data();
164 }
164 }
165
165
166 void tst_QLineSeries::append_raw()
166 void tst_QLineSeries::append_raw()
167 {
167 {
168 QFETCH(QList<QPointF>, points);
168 QFETCH(QList<QPointF>, points);
169 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
169 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
170 m_series->append(points);
170 m_series->append(points);
171 TRY_COMPARE(spy0.count(), 0);
171 TRY_COMPARE(spy0.count(), 0);
172 QCOMPARE(m_series->points(), points);
172 QCOMPARE(m_series->points(), points);
173 }
173 }
174
174
175 void tst_QLineSeries::chart_append_data()
175 void tst_QLineSeries::chart_append_data()
176 {
176 {
177 append_data();
177 append_data();
178 }
178 }
179
179
180 void tst_QLineSeries::chart_append()
180 void tst_QLineSeries::chart_append()
181 {
181 {
182 append_raw();
182 append_raw();
183 m_chart->addSeries(m_series);
183 m_chart->addSeries(m_series);
184 m_view->show();
184 m_view->show();
185 QTest::qWaitForWindowShown(m_view);
185 QTest::qWaitForWindowShown(m_view);
186 }
186 }
187
187
188 void tst_QLineSeries::append_chart_data()
188 void tst_QLineSeries::append_chart_data()
189 {
189 {
190 append_data();
190 append_data();
191 }
191 }
192
192
193 void tst_QLineSeries::append_chart()
193 void tst_QLineSeries::append_chart()
194 {
194 {
195 m_view->show();
195 m_view->show();
196 m_chart->addSeries(m_series);
196 m_chart->addSeries(m_series);
197 QTest::qWaitForWindowShown(m_view);
197 QTest::qWaitForWindowShown(m_view);
198 append_raw();
198 append_raw();
199
199
200 }
200 }
201
201
202 void tst_QLineSeries::append_chart_animation_data()
202 void tst_QLineSeries::append_chart_animation_data()
203 {
203 {
204 append_data();
204 append_data();
205 }
205 }
206
206
207 void tst_QLineSeries::append_chart_animation()
207 void tst_QLineSeries::append_chart_animation()
208 {
208 {
209 m_chart->setAnimationOptions(QChart::AllAnimations);
209 m_chart->setAnimationOptions(QChart::AllAnimations);
210 append_chart();
210 append_chart();
211 }
211 }
212
212
213 void tst_QLineSeries::count_data()
213 void tst_QLineSeries::count_data()
214 {
214 {
215 QTest::addColumn<int>("count");
215 QTest::addColumn<int>("count");
216 QTest::newRow("0") << 0;
216 QTest::newRow("0") << 0;
217 QTest::newRow("5") << 5;
217 QTest::newRow("5") << 5;
218 QTest::newRow("10") << 5;
218 QTest::newRow("10") << 5;
219 }
219 }
220
220
221 void tst_QLineSeries::count_raw_data()
221 void tst_QLineSeries::count_raw_data()
222 {
222 {
223 count_data();
223 count_data();
224 }
224 }
225
225
226 void tst_QLineSeries::count_raw()
226 void tst_QLineSeries::count_raw()
227 {
227 {
228 QFETCH(int, count);
228 QFETCH(int, count);
229
229
230 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
230 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
231
231
232 for(int i=0 ; i< count; ++i)
232 for(int i=0 ; i< count; ++i)
233 m_series->append(i,i);
233 m_series->append(i,i);
234
234
235 TRY_COMPARE(spy0.count(), 0);
235 TRY_COMPARE(spy0.count(), 0);
236 QCOMPARE(m_series->count(), count);
236 QCOMPARE(m_series->count(), count);
237 }
237 }
238
238
239 void tst_QLineSeries::oper_data()
239 void tst_QLineSeries::oper_data()
240 {
240 {
241 append_data();
241 append_data();
242 }
242 }
243
243
244 void tst_QLineSeries::oper()
244 void tst_QLineSeries::oper()
245 {
245 {
246 QFETCH(QList<QPointF>, points);
246 QFETCH(QList<QPointF>, points);
247 QLineSeries series;
247 QLineSeries series;
248
248
249 QSignalSpy spy0(&series, SIGNAL(clicked(QPointF const&)));
249 QSignalSpy spy0(&series, SIGNAL(clicked(QPointF const&)));
250
250
251 foreach(const QPointF& point,points)
251 foreach(const QPointF& point,points)
252 {
252 {
253 series<<point;
253 series<<point;
254 }
254 }
255
255
256 QCOMPARE(series.points(), points);
256 QCOMPARE(series.points(), points);
257 TRY_COMPARE(spy0.count(), 0);
257 TRY_COMPARE(spy0.count(), 0);
258 }
258 }
259
259
260
260
261 void tst_QLineSeries::pen_data()
261 void tst_QLineSeries::pen_data()
262 {
262 {
263 QTest::addColumn<QPen>("pen");
263 QTest::addColumn<QPen>("pen");
264 QTest::newRow("null") << QPen();
264 QTest::newRow("null") << QPen();
265 QTest::newRow("blue") << QPen(Qt::blue);
265 QTest::newRow("blue") << QPen(Qt::blue);
266 QTest::newRow("black") << QPen(Qt::black);
266 QTest::newRow("black") << QPen(Qt::black);
267 QTest::newRow("red") << QPen(Qt::red);
267 QTest::newRow("red") << QPen(Qt::red);
268 }
268 }
269
269
270 void tst_QLineSeries::pen()
270 void tst_QLineSeries::pen()
271 {
271 {
272 QFETCH(QPen, pen);
272 QFETCH(QPen, pen);
273 QLineSeries series;
273 QLineSeries series;
274
274
275 QSignalSpy spy0(&series, SIGNAL(clicked(QPointF const&)));
275 QSignalSpy spy0(&series, SIGNAL(clicked(QPointF const&)));
276 series.setPen(pen);
276 series.setPen(pen);
277
277
278 TRY_COMPARE(spy0.count(), 0);
278 TRY_COMPARE(spy0.count(), 0);
279 QCOMPARE(series.pen(), pen);
279 QCOMPARE(series.pen(), pen);
280
280
281 m_chart->addSeries(&series);
281 m_chart->addSeries(&series);
282
282
283 if(pen!=QPen()) QCOMPARE(series.pen(), pen);
283 if(pen!=QPen()) QCOMPARE(series.pen(), pen);
284
284
285 m_chart->setTheme(QChart::ChartThemeDark);
285 m_chart->setTheme(QChart::ChartThemeDark);
286
286
287 if(pen!=QPen()) QCOMPARE(series.pen(), pen);
287 QVERIFY(series.pen() != pen);
288 }
288 }
289
289
290 void tst_QLineSeries::pointsVisible_data()
290 void tst_QLineSeries::pointsVisible_data()
291 {
291 {
292 QTest::addColumn<bool>("pointsVisible");
292 QTest::addColumn<bool>("pointsVisible");
293 QTest::newRow("true") << true;
293 QTest::newRow("true") << true;
294 QTest::newRow("false") << false;
294 QTest::newRow("false") << false;
295 }
295 }
296
296
297 void tst_QLineSeries::pointsVisible_raw_data()
297 void tst_QLineSeries::pointsVisible_raw_data()
298 {
298 {
299 pointsVisible_data();
299 pointsVisible_data();
300 }
300 }
301
301
302 void tst_QLineSeries::pointsVisible_raw()
302 void tst_QLineSeries::pointsVisible_raw()
303 {
303 {
304 QFETCH(bool, pointsVisible);
304 QFETCH(bool, pointsVisible);
305 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
305 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
306 m_series->setPointsVisible(pointsVisible);
306 m_series->setPointsVisible(pointsVisible);
307 TRY_COMPARE(spy0.count(), 0);
307 TRY_COMPARE(spy0.count(), 0);
308 QCOMPARE(m_series->pointsVisible(), pointsVisible);
308 QCOMPARE(m_series->pointsVisible(), pointsVisible);
309 }
309 }
310
310
311 void tst_QLineSeries::remove_raw_data()
311 void tst_QLineSeries::remove_raw_data()
312 {
312 {
313 append_data();
313 append_data();
314 }
314 }
315
315
316 void tst_QLineSeries::remove_raw()
316 void tst_QLineSeries::remove_raw()
317 {
317 {
318 QFETCH(QList<QPointF>, points);
318 QFETCH(QList<QPointF>, points);
319 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
319 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
320 m_series->append(points);
320 m_series->append(points);
321 TRY_COMPARE(spy0.count(), 0);
321 TRY_COMPARE(spy0.count(), 0);
322 QCOMPARE(m_series->points(), points);
322 QCOMPARE(m_series->points(), points);
323
323
324 foreach(const QPointF& point,points)
324 foreach(const QPointF& point,points)
325 m_series->remove(point);
325 m_series->remove(point);
326
326
327 TRY_COMPARE(spy0.count(), 0);
327 TRY_COMPARE(spy0.count(), 0);
328 QCOMPARE(m_series->points().count(), 0);
328 QCOMPARE(m_series->points().count(), 0);
329 }
329 }
330
330
331 void tst_QLineSeries::remove_chart_data()
331 void tst_QLineSeries::remove_chart_data()
332 {
332 {
333 append_data();
333 append_data();
334 }
334 }
335
335
336 void tst_QLineSeries::remove_chart()
336 void tst_QLineSeries::remove_chart()
337 {
337 {
338 m_view->show();
338 m_view->show();
339 m_chart->addSeries(m_series);
339 m_chart->addSeries(m_series);
340 QTest::qWaitForWindowShown(m_view);
340 QTest::qWaitForWindowShown(m_view);
341 remove_raw();
341 remove_raw();
342 }
342 }
343
343
344 void tst_QLineSeries::remove_chart_animation_data()
344 void tst_QLineSeries::remove_chart_animation_data()
345 {
345 {
346 append_data();
346 append_data();
347 }
347 }
348
348
349 void tst_QLineSeries::remove_chart_animation()
349 void tst_QLineSeries::remove_chart_animation()
350 {
350 {
351 m_chart->setAnimationOptions(QChart::AllAnimations);
351 m_chart->setAnimationOptions(QChart::AllAnimations);
352 remove_chart();
352 remove_chart();
353 }
353 }
354
354
355
355
356 void tst_QLineSeries::removeAll_raw_data()
356 void tst_QLineSeries::removeAll_raw_data()
357 {
357 {
358 append_data();
358 append_data();
359 }
359 }
360
360
361 void tst_QLineSeries::removeAll_raw()
361 void tst_QLineSeries::removeAll_raw()
362 {
362 {
363 QFETCH(QList<QPointF>, points);
363 QFETCH(QList<QPointF>, points);
364 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
364 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
365 m_series->append(points);
365 m_series->append(points);
366 TRY_COMPARE(spy0.count(), 0);
366 TRY_COMPARE(spy0.count(), 0);
367 QCOMPARE(m_series->points(), points);
367 QCOMPARE(m_series->points(), points);
368 m_series->removeAll();
368 m_series->removeAll();
369 TRY_COMPARE(spy0.count(), 0);
369 TRY_COMPARE(spy0.count(), 0);
370 QCOMPARE(m_series->points().count(), 0);
370 QCOMPARE(m_series->points().count(), 0);
371 }
371 }
372
372
373 void tst_QLineSeries::removeAll_chart_data()
373 void tst_QLineSeries::removeAll_chart_data()
374 {
374 {
375 append_data();
375 append_data();
376 }
376 }
377
377
378 void tst_QLineSeries::removeAll_chart()
378 void tst_QLineSeries::removeAll_chart()
379 {
379 {
380 m_view->show();
380 m_view->show();
381 m_chart->addSeries(m_series);
381 m_chart->addSeries(m_series);
382 QTest::qWaitForWindowShown(m_view);
382 QTest::qWaitForWindowShown(m_view);
383 removeAll_raw();
383 removeAll_raw();
384 }
384 }
385
385
386 void tst_QLineSeries::removeAll_chart_animation_data()
386 void tst_QLineSeries::removeAll_chart_animation_data()
387 {
387 {
388 append_data();
388 append_data();
389 }
389 }
390
390
391 void tst_QLineSeries::removeAll_chart_animation()
391 void tst_QLineSeries::removeAll_chart_animation()
392 {
392 {
393 m_chart->setAnimationOptions(QChart::AllAnimations);
393 m_chart->setAnimationOptions(QChart::AllAnimations);
394 removeAll_chart();
394 removeAll_chart();
395 }
395 }
396
396
397 void tst_QLineSeries::replace_raw_data()
397 void tst_QLineSeries::replace_raw_data()
398 {
398 {
399 append_data();
399 append_data();
400 }
400 }
401
401
402 void tst_QLineSeries::replace_raw()
402 void tst_QLineSeries::replace_raw()
403 {
403 {
404 QFETCH(QList<QPointF>, points);
404 QFETCH(QList<QPointF>, points);
405 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
405 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
406 m_series->append(points);
406 m_series->append(points);
407 TRY_COMPARE(spy0.count(), 0);
407 TRY_COMPARE(spy0.count(), 0);
408 QCOMPARE(m_series->points(), points);
408 QCOMPARE(m_series->points(), points);
409
409
410 foreach(const QPointF& point,points)
410 foreach(const QPointF& point,points)
411 m_series->replace(point.x(),point.y(),point.x(),0);
411 m_series->replace(point.x(),point.y(),point.x(),0);
412
412
413 QList<QPointF> newPoints = m_series->points();
413 QList<QPointF> newPoints = m_series->points();
414
414
415 QCOMPARE(newPoints.count(), points.count());
415 QCOMPARE(newPoints.count(), points.count());
416
416
417 for(int i =0 ; i<points.count() ; ++i) {
417 for(int i =0 ; i<points.count() ; ++i) {
418 QCOMPARE(points[i].x(), newPoints[i].x());
418 QCOMPARE(points[i].x(), newPoints[i].x());
419 QCOMPARE(newPoints[i].y(), 0.0);
419 QCOMPARE(newPoints[i].y(), 0.0);
420 }
420 }
421 }
421 }
422
422
423
423
424 void tst_QLineSeries::replace_chart_data()
424 void tst_QLineSeries::replace_chart_data()
425 {
425 {
426 append_data();
426 append_data();
427 }
427 }
428
428
429 void tst_QLineSeries::replace_chart()
429 void tst_QLineSeries::replace_chart()
430 {
430 {
431 m_view->show();
431 m_view->show();
432 m_chart->addSeries(m_series);
432 m_chart->addSeries(m_series);
433 QTest::qWaitForWindowShown(m_view);
433 QTest::qWaitForWindowShown(m_view);
434 replace_raw();
434 replace_raw();
435 }
435 }
436
436
437 void tst_QLineSeries::replace_chart_animation_data()
437 void tst_QLineSeries::replace_chart_animation_data()
438 {
438 {
439 append_data();
439 append_data();
440 }
440 }
441
441
442 void tst_QLineSeries::replace_chart_animation()
442 void tst_QLineSeries::replace_chart_animation()
443 {
443 {
444 m_chart->setAnimationOptions(QChart::AllAnimations);
444 m_chart->setAnimationOptions(QChart::AllAnimations);
445 replace_chart();
445 replace_chart();
446 }
446 }
447
447
448 QTEST_MAIN(tst_QLineSeries)
448 QTEST_MAIN(tst_QLineSeries)
449
449
450 #include "tst_qlineseries.moc"
450 #include "tst_qlineseries.moc"
451
451
General Comments 0
You need to be logged in to leave comments. Login now