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