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