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