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