##// END OF EJS Templates
Adds test case for pen for qlineseries
Michal Klocek -
r1110:467942b69d1a
parent child
Show More
@@ -1,632 +1,636
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 <qchartview.h>
23 #include <qchartview.h>
24 #include <QStandardItemModel>
24 #include <QStandardItemModel>
25
25
26 Q_DECLARE_METATYPE(QList<QPointF>)
26 Q_DECLARE_METATYPE(QList<QPointF>)
27
27
28 QTCOMMERCIALCHART_USE_NAMESPACE
28 QTCOMMERCIALCHART_USE_NAMESPACE
29
29
30 class tst_QLineSeries : public QObject
30 class tst_QLineSeries : public QObject
31 {
31 {
32 Q_OBJECT
32 Q_OBJECT
33
33
34 public slots:
34 public slots:
35 void initTestCase();
35 void initTestCase();
36 void cleanupTestCase();
36 void cleanupTestCase();
37 void init();
37 void init();
38 void cleanup();
38 void cleanup();
39
39
40 private slots:
40 private slots:
41 void qlineseries_data();
41 void qlineseries_data();
42 void qlineseries();
42 void qlineseries();
43 void append_raw_data();
43 void append_raw_data();
44 void append_raw();
44 void append_raw();
45 void append_chart_data();
45 void append_chart_data();
46 void append_chart();
46 void append_chart();
47 void append_chart_animation_data();
47 void append_chart_animation_data();
48 void append_chart_animation();
48 void append_chart_animation();
49 void chart_append_data();
49 void chart_append_data();
50 void chart_append();
50 void chart_append();
51 void count_raw_data();
51 void count_raw_data();
52 void count_raw();
52 void count_raw();
53 void oper_data();
53 void oper_data();
54 void oper();
54 void oper();
55 void pen_data();
55 void pen_data();
56 void pen();
56 void pen();
57 void pointsVisible_raw_data();
57 void pointsVisible_raw_data();
58 void pointsVisible_raw();
58 void pointsVisible_raw();
59 void remove_raw_data();
59 void remove_raw_data();
60 void remove_raw();
60 void remove_raw();
61 void remove_chart_data();
61 void remove_chart_data();
62 void remove_chart();
62 void remove_chart();
63 void remove_chart_animation_data();
63 void remove_chart_animation_data();
64 void remove_chart_animation();
64 void remove_chart_animation();
65 void removeAll_raw_data();
65 void removeAll_raw_data();
66 void removeAll_raw();
66 void removeAll_raw();
67 void removeAll_chart_data();
67 void removeAll_chart_data();
68 void removeAll_chart();
68 void removeAll_chart();
69 void removeAll_chart_animation_data();
69 void removeAll_chart_animation_data();
70 void removeAll_chart_animation();
70 void removeAll_chart_animation();
71 void replace_raw_data();
71 void replace_raw_data();
72 void replace_raw();
72 void replace_raw();
73 void replace_chart_data();
73 void replace_chart_data();
74 void replace_chart();
74 void replace_chart();
75 void replace_chart_animation_data();
75 void replace_chart_animation_data();
76 void replace_chart_animation();
76 void replace_chart_animation();
77 void setModel_data();
77 void setModel_data();
78 void setModel();
78 void setModel();
79 void setModelMapping_data();
79 void setModelMapping_data();
80 void setModelMapping();
80 void setModelMapping();
81 void setModelMappingRange_data();
81 void setModelMappingRange_data();
82 void setModelMappingRange();
82 void setModelMappingRange();
83 void modelUpdated();
83 void modelUpdated();
84 void modelUpdatedCustomMapping();
84 void modelUpdatedCustomMapping();
85 private:
85 private:
86 void append_data();
86 void append_data();
87 void count_data();
87 void count_data();
88 void pointsVisible_data();
88 void pointsVisible_data();
89
89
90 private:
90 private:
91 QChartView* m_view;
91 QChartView* m_view;
92 QChart* m_chart;
92 QChart* m_chart;
93 QLineSeries* m_series;
93 QLineSeries* m_series;
94 };
94 };
95
95
96 void tst_QLineSeries::initTestCase()
96 void tst_QLineSeries::initTestCase()
97 {
97 {
98 }
98 }
99
99
100 void tst_QLineSeries::cleanupTestCase()
100 void tst_QLineSeries::cleanupTestCase()
101 {
101 {
102 }
102 }
103
103
104 void tst_QLineSeries::init()
104 void tst_QLineSeries::init()
105 {
105 {
106 m_view = new QChartView(new QChart());
106 m_view = new QChartView(new QChart());
107 m_chart = m_view->chart();
107 m_chart = m_view->chart();
108 m_series = new QLineSeries();
108 m_series = new QLineSeries();
109 }
109 }
110
110
111 void tst_QLineSeries::cleanup()
111 void tst_QLineSeries::cleanup()
112 {
112 {
113 delete m_series;
113 delete m_series;
114 delete m_view;
114 delete m_view;
115 m_view = 0;
115 m_view = 0;
116 m_chart = 0;
116 m_chart = 0;
117 m_series = 0;
117 m_series = 0;
118 }
118 }
119
119
120 void tst_QLineSeries::qlineseries_data()
120 void tst_QLineSeries::qlineseries_data()
121 {
121 {
122
122
123 }
123 }
124
124
125 void tst_QLineSeries::qlineseries()
125 void tst_QLineSeries::qlineseries()
126 {
126 {
127 QLineSeries series;
127 QLineSeries series;
128
128
129 QCOMPARE(series.count(),0);
129 QCOMPARE(series.count(),0);
130 QCOMPARE(series.brush(), QBrush());
130 QCOMPARE(series.brush(), QBrush());
131 QCOMPARE(series.points(), QList<QPointF>());
131 QCOMPARE(series.points(), QList<QPointF>());
132 QCOMPARE(series.pen(), QPen());
132 QCOMPARE(series.pen(), QPen());
133 QCOMPARE(series.pointsVisible(), false);
133 QCOMPARE(series.pointsVisible(), false);
134
134
135 series.append(QList<QPointF>());
135 series.append(QList<QPointF>());
136 series.append(0.0,0.0);
136 series.append(0.0,0.0);
137 series.append(QPointF());
137 series.append(QPointF());
138
138
139 series.remove(0.0,0.0);
139 series.remove(0.0,0.0);
140 series.remove(QPointF());
140 series.remove(QPointF());
141 series.removeAll();
141 series.removeAll();
142
142
143 series.replace(QPointF(),QPointF());
143 series.replace(QPointF(),QPointF());
144 series.replace(0,0,0,0);
144 series.replace(0,0,0,0);
145 series.setBrush(QBrush());
145 series.setBrush(QBrush());
146
146
147 QCOMPARE(series.setModel((QAbstractItemModel*)0), false);
147 QCOMPARE(series.setModel((QAbstractItemModel*)0), false);
148
148
149 series.setModelMapping(-1, -1, Qt::Orientation(0));
149 series.setModelMapping(-1, -1, Qt::Orientation(0));
150
150
151 series.setPen(QPen());
151 series.setPen(QPen());
152 series.setPointsVisible(false);
152 series.setPointsVisible(false);
153
153
154 m_chart->addSeries(&series);
154 m_chart->addSeries(&series);
155 m_view->show();
155 m_view->show();
156 QTest::qWaitForWindowShown(m_view);
156 QTest::qWaitForWindowShown(m_view);
157 }
157 }
158
158
159 void tst_QLineSeries::append_data()
159 void tst_QLineSeries::append_data()
160 {
160 {
161 QTest::addColumn< QList<QPointF> >("points");
161 QTest::addColumn< QList<QPointF> >("points");
162 QTest::newRow("0,0 1,1 2,2 3,3") << (QList<QPointF>() << QPointF(0,0) << QPointF(1,1) << QPointF(2,2) << QPointF(3,3));
162 QTest::newRow("0,0 1,1 2,2 3,3") << (QList<QPointF>() << QPointF(0,0) << QPointF(1,1) << QPointF(2,2) << QPointF(3,3));
163 QTest::newRow("0,0 -1,-1 -2,-2 -3,-3") << (QList<QPointF>() << QPointF(0,0) << QPointF(-1,-1) << QPointF(-2,-2) << QPointF(-3,-3));
163 QTest::newRow("0,0 -1,-1 -2,-2 -3,-3") << (QList<QPointF>() << QPointF(0,0) << QPointF(-1,-1) << QPointF(-2,-2) << QPointF(-3,-3));
164 }
164 }
165
165
166
166
167 void tst_QLineSeries::append_raw_data()
167 void tst_QLineSeries::append_raw_data()
168 {
168 {
169 append_data();
169 append_data();
170 }
170 }
171
171
172 void tst_QLineSeries::append_raw()
172 void tst_QLineSeries::append_raw()
173 {
173 {
174 QFETCH(QList<QPointF>, points);
174 QFETCH(QList<QPointF>, points);
175 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
175 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
176 QTest::qWait(200);
176 QTest::qWait(200);
177 m_series->append(points);
177 m_series->append(points);
178 QTest::qWait(200);
178 QTest::qWait(200);
179 QCOMPARE(spy0.count(), 0);
179 QCOMPARE(spy0.count(), 0);
180 QCOMPARE(m_series->points(), points);
180 QCOMPARE(m_series->points(), points);
181 }
181 }
182
182
183 void tst_QLineSeries::chart_append_data()
183 void tst_QLineSeries::chart_append_data()
184 {
184 {
185 append_data();
185 append_data();
186 }
186 }
187
187
188 void tst_QLineSeries::chart_append()
188 void tst_QLineSeries::chart_append()
189 {
189 {
190 append_raw();
190 append_raw();
191 m_chart->addSeries(m_series);
191 m_chart->addSeries(m_series);
192 m_view->show();
192 m_view->show();
193 QTest::qWaitForWindowShown(m_view);
193 QTest::qWaitForWindowShown(m_view);
194 }
194 }
195
195
196 void tst_QLineSeries::append_chart_data()
196 void tst_QLineSeries::append_chart_data()
197 {
197 {
198 append_data();
198 append_data();
199 }
199 }
200
200
201 void tst_QLineSeries::append_chart()
201 void tst_QLineSeries::append_chart()
202 {
202 {
203 m_view->show();
203 m_view->show();
204 m_chart->addSeries(m_series);
204 m_chart->addSeries(m_series);
205 QTest::qWaitForWindowShown(m_view);
205 QTest::qWaitForWindowShown(m_view);
206 append_raw();
206 append_raw();
207
207
208 }
208 }
209
209
210 void tst_QLineSeries::append_chart_animation_data()
210 void tst_QLineSeries::append_chart_animation_data()
211 {
211 {
212 append_data();
212 append_data();
213 }
213 }
214
214
215 void tst_QLineSeries::append_chart_animation()
215 void tst_QLineSeries::append_chart_animation()
216 {
216 {
217 m_chart->setAnimationOptions(QChart::AllAnimations);
217 m_chart->setAnimationOptions(QChart::AllAnimations);
218 append_chart();
218 append_chart();
219 }
219 }
220
220
221 void tst_QLineSeries::count_data()
221 void tst_QLineSeries::count_data()
222 {
222 {
223 QTest::addColumn<int>("count");
223 QTest::addColumn<int>("count");
224 QTest::newRow("0") << 0;
224 QTest::newRow("0") << 0;
225 QTest::newRow("5") << 5;
225 QTest::newRow("5") << 5;
226 QTest::newRow("10") << 5;
226 QTest::newRow("10") << 5;
227 }
227 }
228
228
229 void tst_QLineSeries::count_raw_data()
229 void tst_QLineSeries::count_raw_data()
230 {
230 {
231 count_data();
231 count_data();
232 }
232 }
233
233
234 void tst_QLineSeries::count_raw()
234 void tst_QLineSeries::count_raw()
235 {
235 {
236 QFETCH(int, count);
236 QFETCH(int, count);
237
237
238 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
238 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
239
239
240 for(int i=0 ; i< count; ++i)
240 for(int i=0 ; i< count; ++i)
241 m_series->append(i,i);
241 m_series->append(i,i);
242
242
243 QCOMPARE(spy0.count(), 0);
243 QCOMPARE(spy0.count(), 0);
244 QCOMPARE(m_series->count(), count);
244 QCOMPARE(m_series->count(), count);
245 }
245 }
246
246
247 void tst_QLineSeries::oper_data()
247 void tst_QLineSeries::oper_data()
248 {
248 {
249 append_data();
249 append_data();
250 }
250 }
251
251
252 void tst_QLineSeries::oper()
252 void tst_QLineSeries::oper()
253 {
253 {
254 QFETCH(QList<QPointF>, points);
254 QFETCH(QList<QPointF>, points);
255 QLineSeries series;
255 QLineSeries series;
256
256
257 QSignalSpy spy0(&series, SIGNAL(clicked(QPointF const&)));
257 QSignalSpy spy0(&series, SIGNAL(clicked(QPointF const&)));
258
258
259 foreach(const QPointF& point,points)
259 foreach(const QPointF& point,points)
260 {
260 {
261 series<<point;
261 series<<point;
262 }
262 }
263
263
264 QCOMPARE(series.points(), points);
264 QCOMPARE(series.points(), points);
265 QCOMPARE(spy0.count(), 0);
265 QCOMPARE(spy0.count(), 0);
266 }
266 }
267
267
268
268
269 void tst_QLineSeries::pen_data()
269 void tst_QLineSeries::pen_data()
270 {
270 {
271 QTest::addColumn<QPen>("pen");
271 QTest::addColumn<QPen>("pen");
272 QTest::newRow("null") << QPen();
272 QTest::newRow("null") << QPen();
273 QTest::newRow("blue") << QPen(Qt::blue);
273 QTest::newRow("blue") << QPen(Qt::blue);
274 QTest::newRow("black") << QPen(Qt::black);
274 QTest::newRow("black") << QPen(Qt::black);
275 QTest::newRow("red") << QPen(Qt::red);
275 QTest::newRow("red") << QPen(Qt::red);
276 }
276 }
277
277
278 void tst_QLineSeries::pen()
278 void tst_QLineSeries::pen()
279 {
279 {
280 QFETCH(QPen, pen);
280 QFETCH(QPen, pen);
281 QLineSeries series;
281 QLineSeries series;
282
282
283 QSignalSpy spy0(&series, SIGNAL(clicked(QPointF const&)));
283 QSignalSpy spy0(&series, SIGNAL(clicked(QPointF const&)));
284 series.setPen(pen);
284 series.setPen(pen);
285
285
286 QCOMPARE(spy0.count(), 0);
286 QCOMPARE(spy0.count(), 0);
287 QCOMPARE(series.pen(), pen);
287 QCOMPARE(series.pen(), pen);
288
288
289 m_chart->addSeries(&series);
289 m_chart->addSeries(&series);
290
290
291 if(pen!=QPen()) QCOMPARE(series.pen(), pen);
291 if(pen!=QPen()) QCOMPARE(series.pen(), pen);
292
293 m_chart->setTheme(QChart::ChartThemeDark);
294
295 if(pen!=QPen()) QCOMPARE(series.pen(), pen);
292 }
296 }
293
297
294 void tst_QLineSeries::pointsVisible_data()
298 void tst_QLineSeries::pointsVisible_data()
295 {
299 {
296 QTest::addColumn<bool>("pointsVisible");
300 QTest::addColumn<bool>("pointsVisible");
297 QTest::newRow("true") << true;
301 QTest::newRow("true") << true;
298 QTest::newRow("false") << false;
302 QTest::newRow("false") << false;
299 }
303 }
300
304
301 void tst_QLineSeries::pointsVisible_raw_data()
305 void tst_QLineSeries::pointsVisible_raw_data()
302 {
306 {
303 pointsVisible_data();
307 pointsVisible_data();
304 }
308 }
305
309
306 void tst_QLineSeries::pointsVisible_raw()
310 void tst_QLineSeries::pointsVisible_raw()
307 {
311 {
308 QFETCH(bool, pointsVisible);
312 QFETCH(bool, pointsVisible);
309 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
313 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
310 m_series->setPointsVisible(pointsVisible);
314 m_series->setPointsVisible(pointsVisible);
311 QCOMPARE(spy0.count(), 0);
315 QCOMPARE(spy0.count(), 0);
312 QCOMPARE(m_series->pointsVisible(), pointsVisible);
316 QCOMPARE(m_series->pointsVisible(), pointsVisible);
313 }
317 }
314
318
315 void tst_QLineSeries::remove_raw_data()
319 void tst_QLineSeries::remove_raw_data()
316 {
320 {
317 append_data();
321 append_data();
318 }
322 }
319
323
320 void tst_QLineSeries::remove_raw()
324 void tst_QLineSeries::remove_raw()
321 {
325 {
322 QFETCH(QList<QPointF>, points);
326 QFETCH(QList<QPointF>, points);
323 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
327 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
324 m_series->append(points);
328 m_series->append(points);
325 QTest::qWait(200);
329 QTest::qWait(200);
326 QCOMPARE(spy0.count(), 0);
330 QCOMPARE(spy0.count(), 0);
327 QCOMPARE(m_series->points(), points);
331 QCOMPARE(m_series->points(), points);
328
332
329 foreach(const QPointF& point,points)
333 foreach(const QPointF& point,points)
330 {
334 {
331 m_series->remove(point);
335 m_series->remove(point);
332 QTest::qWait(200);
336 QTest::qWait(200);
333 }
337 }
334
338
335 QCOMPARE(spy0.count(), 0);
339 QCOMPARE(spy0.count(), 0);
336 QCOMPARE(m_series->points().count(), 0);
340 QCOMPARE(m_series->points().count(), 0);
337 }
341 }
338
342
339 void tst_QLineSeries::remove_chart_data()
343 void tst_QLineSeries::remove_chart_data()
340 {
344 {
341 append_data();
345 append_data();
342 }
346 }
343
347
344 void tst_QLineSeries::remove_chart()
348 void tst_QLineSeries::remove_chart()
345 {
349 {
346 m_view->show();
350 m_view->show();
347 m_chart->addSeries(m_series);
351 m_chart->addSeries(m_series);
348 QTest::qWaitForWindowShown(m_view);
352 QTest::qWaitForWindowShown(m_view);
349 remove_raw();
353 remove_raw();
350 }
354 }
351
355
352 void tst_QLineSeries::remove_chart_animation_data()
356 void tst_QLineSeries::remove_chart_animation_data()
353 {
357 {
354 append_data();
358 append_data();
355 }
359 }
356
360
357 void tst_QLineSeries::remove_chart_animation()
361 void tst_QLineSeries::remove_chart_animation()
358 {
362 {
359 m_chart->setAnimationOptions(QChart::AllAnimations);
363 m_chart->setAnimationOptions(QChart::AllAnimations);
360 remove_chart();
364 remove_chart();
361 }
365 }
362
366
363
367
364 void tst_QLineSeries::removeAll_raw_data()
368 void tst_QLineSeries::removeAll_raw_data()
365 {
369 {
366 append_data();
370 append_data();
367 }
371 }
368
372
369 void tst_QLineSeries::removeAll_raw()
373 void tst_QLineSeries::removeAll_raw()
370 {
374 {
371 QFETCH(QList<QPointF>, points);
375 QFETCH(QList<QPointF>, points);
372 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
376 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
373 m_series->append(points);
377 m_series->append(points);
374 QCOMPARE(spy0.count(), 0);
378 QCOMPARE(spy0.count(), 0);
375 QCOMPARE(m_series->points(), points);
379 QCOMPARE(m_series->points(), points);
376 QTest::qWait(200);
380 QTest::qWait(200);
377 m_series->removeAll();
381 m_series->removeAll();
378 QTest::qWait(200);
382 QTest::qWait(200);
379 QCOMPARE(spy0.count(), 0);
383 QCOMPARE(spy0.count(), 0);
380 QCOMPARE(m_series->points().count(), 0);
384 QCOMPARE(m_series->points().count(), 0);
381 }
385 }
382
386
383 void tst_QLineSeries::removeAll_chart_data()
387 void tst_QLineSeries::removeAll_chart_data()
384 {
388 {
385 append_data();
389 append_data();
386 }
390 }
387
391
388 void tst_QLineSeries::removeAll_chart()
392 void tst_QLineSeries::removeAll_chart()
389 {
393 {
390 m_view->show();
394 m_view->show();
391 m_chart->addSeries(m_series);
395 m_chart->addSeries(m_series);
392 QTest::qWaitForWindowShown(m_view);
396 QTest::qWaitForWindowShown(m_view);
393 removeAll_raw();
397 removeAll_raw();
394 }
398 }
395
399
396 void tst_QLineSeries::removeAll_chart_animation_data()
400 void tst_QLineSeries::removeAll_chart_animation_data()
397 {
401 {
398 append_data();
402 append_data();
399 }
403 }
400
404
401 void tst_QLineSeries::removeAll_chart_animation()
405 void tst_QLineSeries::removeAll_chart_animation()
402 {
406 {
403 m_chart->setAnimationOptions(QChart::AllAnimations);
407 m_chart->setAnimationOptions(QChart::AllAnimations);
404 removeAll_chart();
408 removeAll_chart();
405 }
409 }
406
410
407 void tst_QLineSeries::replace_raw_data()
411 void tst_QLineSeries::replace_raw_data()
408 {
412 {
409 append_data();
413 append_data();
410 }
414 }
411
415
412 void tst_QLineSeries::replace_raw()
416 void tst_QLineSeries::replace_raw()
413 {
417 {
414 QFETCH(QList<QPointF>, points);
418 QFETCH(QList<QPointF>, points);
415 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
419 QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&)));
416 m_series->append(points);
420 m_series->append(points);
417 QCOMPARE(spy0.count(), 0);
421 QCOMPARE(spy0.count(), 0);
418 QCOMPARE(m_series->points(), points);
422 QCOMPARE(m_series->points(), points);
419 QTest::qWait(200);
423 QTest::qWait(200);
420
424
421 foreach(const QPointF& point,points)
425 foreach(const QPointF& point,points)
422 {
426 {
423 m_series->replace(point.x(),point.y(),point.x(),0);
427 m_series->replace(point.x(),point.y(),point.x(),0);
424 QTest::qWait(200);
428 QTest::qWait(200);
425 }
429 }
426
430
427 QList<QPointF> newPoints = m_series->points();
431 QList<QPointF> newPoints = m_series->points();
428
432
429 QCOMPARE(newPoints.count(), points.count());
433 QCOMPARE(newPoints.count(), points.count());
430
434
431 for(int i =0 ; i<points.count() ; ++i) {
435 for(int i =0 ; i<points.count() ; ++i) {
432 QCOMPARE(points[i].x(), newPoints[i].x());
436 QCOMPARE(points[i].x(), newPoints[i].x());
433 QCOMPARE(newPoints[i].y(), 0.0);
437 QCOMPARE(newPoints[i].y(), 0.0);
434 }
438 }
435 }
439 }
436
440
437
441
438 void tst_QLineSeries::replace_chart_data()
442 void tst_QLineSeries::replace_chart_data()
439 {
443 {
440 append_data();
444 append_data();
441 }
445 }
442
446
443 void tst_QLineSeries::replace_chart()
447 void tst_QLineSeries::replace_chart()
444 {
448 {
445 m_view->show();
449 m_view->show();
446 m_chart->addSeries(m_series);
450 m_chart->addSeries(m_series);
447 QTest::qWaitForWindowShown(m_view);
451 QTest::qWaitForWindowShown(m_view);
448 replace_raw();
452 replace_raw();
449 }
453 }
450
454
451 void tst_QLineSeries::replace_chart_animation_data()
455 void tst_QLineSeries::replace_chart_animation_data()
452 {
456 {
453 append_data();
457 append_data();
454 }
458 }
455
459
456 void tst_QLineSeries::replace_chart_animation()
460 void tst_QLineSeries::replace_chart_animation()
457 {
461 {
458 m_chart->setAnimationOptions(QChart::AllAnimations);
462 m_chart->setAnimationOptions(QChart::AllAnimations);
459 replace_chart();
463 replace_chart();
460 }
464 }
461
465
462 void tst_QLineSeries::setModel_data()
466 void tst_QLineSeries::setModel_data()
463 {
467 {
464
468
465 }
469 }
466
470
467 void tst_QLineSeries::setModel()
471 void tst_QLineSeries::setModel()
468 {
472 {
469 QLineSeries series;
473 QLineSeries series;
470 series.setModel(0);
474 series.setModel(0);
471 QVERIFY2(series.model() == 0, "Model should be unset");
475 QVERIFY2(series.model() == 0, "Model should be unset");
472
476
473 QStandardItemModel *stdModel = new QStandardItemModel();
477 QStandardItemModel *stdModel = new QStandardItemModel();
474 series.setModel(stdModel);
478 series.setModel(stdModel);
475 QVERIFY2((series.model()) == stdModel, "Model should be stdModel");
479 QVERIFY2((series.model()) == stdModel, "Model should be stdModel");
476
480
477 // unset the model
481 // unset the model
478 series.setModel(0);
482 series.setModel(0);
479 QVERIFY2(series.model() == 0, "Model should be unset");
483 QVERIFY2(series.model() == 0, "Model should be unset");
480
484
481 }
485 }
482
486
483 Q_DECLARE_METATYPE(Qt::Orientation)
487 Q_DECLARE_METATYPE(Qt::Orientation)
484 void tst_QLineSeries::setModelMapping_data()
488 void tst_QLineSeries::setModelMapping_data()
485 {
489 {
486 QTest::addColumn<int>("modelX");
490 QTest::addColumn<int>("modelX");
487 QTest::addColumn<int>("modelY");
491 QTest::addColumn<int>("modelY");
488 QTest::addColumn<Qt::Orientation>("orientation");
492 QTest::addColumn<Qt::Orientation>("orientation");
489 QTest::newRow("different x and y, vertical") << 0 << 1 << Qt::Vertical;
493 QTest::newRow("different x and y, vertical") << 0 << 1 << Qt::Vertical;
490 QTest::newRow("same x and y, vertical") << 0 << 0 << Qt::Vertical;
494 QTest::newRow("same x and y, vertical") << 0 << 0 << Qt::Vertical;
491 QTest::newRow("invalid x, corrent y, vertical") << -1 << 1 << Qt::Vertical;
495 QTest::newRow("invalid x, corrent y, vertical") << -1 << 1 << Qt::Vertical;
492
496
493 QTest::newRow("different x and y, horizontal") << 0 << 1 << Qt::Horizontal;
497 QTest::newRow("different x and y, horizontal") << 0 << 1 << Qt::Horizontal;
494 QTest::newRow("same x and y, horizontal") << 0 << 0 << Qt::Horizontal;
498 QTest::newRow("same x and y, horizontal") << 0 << 0 << Qt::Horizontal;
495 QTest::newRow("invalid x, corrent y, horizontal") << -1 << 1 << Qt::Horizontal;
499 QTest::newRow("invalid x, corrent y, horizontal") << -1 << 1 << Qt::Horizontal;
496 }
500 }
497
501
498 void tst_QLineSeries::setModelMapping()
502 void tst_QLineSeries::setModelMapping()
499 {
503 {
500 QFETCH(int, modelX);
504 QFETCH(int, modelX);
501 QFETCH(int, modelY);
505 QFETCH(int, modelY);
502 QFETCH(Qt::Orientation, orientation);
506 QFETCH(Qt::Orientation, orientation);
503
507
504 QLineSeries series;
508 QLineSeries series;
505
509
506 // model has not been set so setting mapping should do nothing
510 // model has not been set so setting mapping should do nothing
507 series.setModelMapping(modelX, modelY, orientation);
511 series.setModelMapping(modelX, modelY, orientation);
508 QCOMPARE(series.mapX(), -1);
512 QCOMPARE(series.mapX(), -1);
509 QCOMPARE(series.mapY(), -1);
513 QCOMPARE(series.mapY(), -1);
510 QVERIFY2(series.mapOrientation() == Qt::Vertical, "The orientation by default should be Qt::Vertical");
514 QVERIFY2(series.mapOrientation() == Qt::Vertical, "The orientation by default should be Qt::Vertical");
511
515
512 // now let us set the model
516 // now let us set the model
513 series.setModel(new QStandardItemModel());
517 series.setModel(new QStandardItemModel());
514 series.setModelMapping(modelX, modelY, orientation);
518 series.setModelMapping(modelX, modelY, orientation);
515 QCOMPARE(series.mapX(), modelX);
519 QCOMPARE(series.mapX(), modelX);
516 QCOMPARE(series.mapY(), modelY);
520 QCOMPARE(series.mapY(), modelY);
517 QVERIFY2(series.mapOrientation() == orientation, "not good");
521 QVERIFY2(series.mapOrientation() == orientation, "not good");
518
522
519 // now let us remove the model, the values should go back to default ones.
523 // now let us remove the model, the values should go back to default ones.
520 series.setModel(0);
524 series.setModel(0);
521 QCOMPARE(series.mapX(), -1);
525 QCOMPARE(series.mapX(), -1);
522 QCOMPARE(series.mapY(), -1);
526 QCOMPARE(series.mapY(), -1);
523 QVERIFY2(series.mapOrientation() == Qt::Vertical, "The orientation by default should be Qt::Vertical");
527 QVERIFY2(series.mapOrientation() == Qt::Vertical, "The orientation by default should be Qt::Vertical");
524 }
528 }
525
529
526 void tst_QLineSeries::setModelMappingRange_data()
530 void tst_QLineSeries::setModelMappingRange_data()
527 {
531 {
528 QTest::addColumn<int>("first");
532 QTest::addColumn<int>("first");
529 QTest::addColumn<int>("count");
533 QTest::addColumn<int>("count");
530 QTest::newRow("first: 0, count: unlimited") << 0 << -1;
534 QTest::newRow("first: 0, count: unlimited") << 0 << -1;
531 QTest::newRow("first: 0, count: 5") << 0 << 5;
535 QTest::newRow("first: 0, count: 5") << 0 << 5;
532 QTest::newRow("first: 3, count: unlimited") << 3 << -1;
536 QTest::newRow("first: 3, count: unlimited") << 3 << -1;
533 QTest::newRow("first: 3, count: 5") << 3 << 5;
537 QTest::newRow("first: 3, count: 5") << 3 << 5;
534 QTest::newRow("first: -3, count: 5") << -3 << 5;
538 QTest::newRow("first: -3, count: 5") << -3 << 5;
535 QTest::newRow("first: 3, count: -5") << 3 << -5;
539 QTest::newRow("first: 3, count: -5") << 3 << -5;
536 QTest::newRow("first: -3, count: -5") << 3 << -5;
540 QTest::newRow("first: -3, count: -5") << 3 << -5;
537 QTest::newRow("first: -3, count: 0") << -3 << 0;
541 QTest::newRow("first: -3, count: 0") << -3 << 0;
538 QTest::newRow("first: 0, count: -5") << 0 << -5;
542 QTest::newRow("first: 0, count: -5") << 0 << -5;
539 QTest::newRow("first: 0, count: 0") << 0 << 0;
543 QTest::newRow("first: 0, count: 0") << 0 << 0;
540 }
544 }
541
545
542 void tst_QLineSeries::setModelMappingRange()
546 void tst_QLineSeries::setModelMappingRange()
543 {
547 {
544 QFETCH(int, first);
548 QFETCH(int, first);
545 QFETCH(int, count);
549 QFETCH(int, count);
546 QLineSeries series;
550 QLineSeries series;
547
551
548 QStandardItemModel *model = new QStandardItemModel(0, 2);
552 QStandardItemModel *model = new QStandardItemModel(0, 2);
549 series.setModel(model);
553 series.setModel(model);
550 series.setModelMapping(0, 1);
554 series.setModelMapping(0, 1);
551 series.setModelMappingRange(first, count);
555 series.setModelMappingRange(first, count);
552
556
553 QCOMPARE(series.mapFirst(), qMax(first, 0)); // regardles of what value was used to set the range, first should not be less than 0
557 QCOMPARE(series.mapFirst(), qMax(first, 0)); // regardles of what value was used to set the range, first should not be less than 0
554 QCOMPARE(series.mapCount(), qMax(count, -1)); // regardles of what value was used to set the range, first should not be less than 0
558 QCOMPARE(series.mapCount(), qMax(count, -1)); // regardles of what value was used to set the range, first should not be less than 0
555 QVERIFY2(series.count() == 0, "No rows in the model, count should be 0");
559 QVERIFY2(series.count() == 0, "No rows in the model, count should be 0");
556
560
557 for (int row = 0; row < 3; ++row) {
561 for (int row = 0; row < 3; ++row) {
558 for (int column = 0; column < 2; column++) {
562 for (int column = 0; column < 2; column++) {
559 QStandardItem *item = new QStandardItem(row * column);
563 QStandardItem *item = new QStandardItem(row * column);
560 model->setItem(row, column, item);
564 model->setItem(row, column, item);
561 }
565 }
562 }
566 }
563 if (qMax(count, -1) != -1)
567 if (qMax(count, -1) != -1)
564 QVERIFY2(series.count() == qMin(model->rowCount() - qMax(first, 0), qMax(count, -1)), "Count should be the number of items in a model after first item, but not more than count and not less than 0");
568 QVERIFY2(series.count() == qMin(model->rowCount() - qMax(first, 0), qMax(count, -1)), "Count should be the number of items in a model after first item, but not more than count and not less than 0");
565 else
569 else
566 QVERIFY2(series.count() == model->rowCount() - qMax(first, 0), "Count should be the number of items in a model after first item, but not less then 0");
570 QVERIFY2(series.count() == model->rowCount() - qMax(first, 0), "Count should be the number of items in a model after first item, but not less then 0");
567
571
568 // let's add few more rows to the model
572 // let's add few more rows to the model
569 for (int row = 0; row < 10; ++row) {
573 for (int row = 0; row < 10; ++row) {
570 QList<QStandardItem *> newRow;
574 QList<QStandardItem *> newRow;
571 for (int column = 0; column < 2; column++) {
575 for (int column = 0; column < 2; column++) {
572 newRow.append(new QStandardItem(row * column));
576 newRow.append(new QStandardItem(row * column));
573 }
577 }
574 model->appendRow(newRow);
578 model->appendRow(newRow);
575 }
579 }
576 if (qMax(count, -1) != -1)
580 if (qMax(count, -1) != -1)
577 QVERIFY2(series.count() == qMin(model->rowCount() - qMax(first, 0), qMax(count, -1)), "Count should be the number of items in a model after first item, but not more than count, but not more than count and not less than 0");
581 QVERIFY2(series.count() == qMin(model->rowCount() - qMax(first, 0), qMax(count, -1)), "Count should be the number of items in a model after first item, but not more than count, but not more than count and not less than 0");
578 else
582 else
579 QVERIFY2(series.count() == model->rowCount() - qMax(first, 0), "Count should be the number of items in a model after first item, but not less then 0");
583 QVERIFY2(series.count() == model->rowCount() - qMax(first, 0), "Count should be the number of items in a model after first item, but not less then 0");
580
584
581 // unset the model, values should be default
585 // unset the model, values should be default
582 series.setModel(0);
586 series.setModel(0);
583 QCOMPARE(series.mapFirst(), 0);
587 QCOMPARE(series.mapFirst(), 0);
584 QCOMPARE(series.mapCount(), -1);
588 QCOMPARE(series.mapCount(), -1);
585 QVERIFY2(series.count() == 0, "No rows in the model, count should be 0");
589 QVERIFY2(series.count() == 0, "No rows in the model, count should be 0");
586 }
590 }
587
591
588 void tst_QLineSeries::modelUpdated()
592 void tst_QLineSeries::modelUpdated()
589 {
593 {
590 QStandardItemModel *model = new QStandardItemModel;
594 QStandardItemModel *model = new QStandardItemModel;
591 for (int row = 0; row < 10; ++row) {
595 for (int row = 0; row < 10; ++row) {
592 QList<QStandardItem *> newRow;
596 QList<QStandardItem *> newRow;
593 for (int column = 0; column < 2; column++) {
597 for (int column = 0; column < 2; column++) {
594 newRow.append(new QStandardItem(row * column));
598 newRow.append(new QStandardItem(row * column));
595 }
599 }
596 model->appendRow(newRow);
600 model->appendRow(newRow);
597 }
601 }
598
602
599 QLineSeries series;
603 QLineSeries series;
600 series.setModel(model);
604 series.setModel(model);
601 series.setModelMapping(0, 1);
605 series.setModelMapping(0, 1);
602
606
603 model->setData(model->index(3, 1), 34);
607 model->setData(model->index(3, 1), 34);
604 // check that the update data is correctly taken from the model
608 // check that the update data is correctly taken from the model
605 QVERIFY(qFuzzyCompare(series.points().at(3).y(), 34));
609 QVERIFY(qFuzzyCompare(series.points().at(3).y(), 34));
606 }
610 }
607
611
608 void tst_QLineSeries::modelUpdatedCustomMapping()
612 void tst_QLineSeries::modelUpdatedCustomMapping()
609 {
613 {
610
614
611 QStandardItemModel *model = new QStandardItemModel;
615 QStandardItemModel *model = new QStandardItemModel;
612 for (int row = 0; row < 10; ++row) {
616 for (int row = 0; row < 10; ++row) {
613 QList<QStandardItem *> newRow;
617 QList<QStandardItem *> newRow;
614 for (int column = 0; column < 2; column++) {
618 for (int column = 0; column < 2; column++) {
615 newRow.append(new QStandardItem(row * column));
619 newRow.append(new QStandardItem(row * column));
616 }
620 }
617 model->appendRow(newRow);
621 model->appendRow(newRow);
618 }
622 }
619
623
620 QLineSeries series;
624 QLineSeries series;
621 series.setModel(model);
625 series.setModel(model);
622 series.setModelMapping(0, 1);
626 series.setModelMapping(0, 1);
623 series.setModelMappingRange(3, 4);
627 series.setModelMappingRange(3, 4);
624
628
625 model->setData(model->index(3, 1), 34);
629 model->setData(model->index(3, 1), 34);
626 QVERIFY(qFuzzyCompare(series.points().at(0).y(), 34));
630 QVERIFY(qFuzzyCompare(series.points().at(0).y(), 34));
627 }
631 }
628
632
629 QTEST_MAIN(tst_QLineSeries)
633 QTEST_MAIN(tst_QLineSeries)
630
634
631 #include "tst_qlineseries.moc"
635 #include "tst_qlineseries.moc"
632
636
General Comments 0
You need to be logged in to leave comments. Login now