##// END OF EJS Templates
Updates chartdataset unit test
Michal Klocek -
r771:9f133768a877
parent child
Show More
@@ -1,3 +1,23
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
1 21 #include "chartdataset_p.h"
2 22 #include "qchartaxis.h"
3 23 //series
@@ -247,7 +267,7 void ChartDataSet::setupCategories(QBarSeries* series)
247 267
248 268 void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size)
249 269 {
250 QMapIterator<QChartAxis*, Domain*> i( m_axisDomainMap);
270 QMapIterator<QChartAxis*, Domain*> i(m_axisDomainMap);
251 271 while (i.hasNext()) {
252 272 i.next();
253 273 i.value()->zoomIn(rect,size);
@@ -256,7 +276,7 void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size)
256 276
257 277 void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size)
258 278 {
259 QMapIterator<QChartAxis*, Domain*> i( m_axisDomainMap);
279 QMapIterator<QChartAxis*, Domain*> i(m_axisDomainMap);
260 280 while (i.hasNext()) {
261 281 i.next();
262 282 i.value()->zoomOut(rect,size);
@@ -266,7 +286,7 void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size)
266 286 int ChartDataSet::seriesCount(QSeries::QSeriesType type)
267 287 {
268 288 int count=0;
269 QMapIterator<QSeries*, QChartAxis*> i( m_seriesAxisMap);
289 QMapIterator<QSeries*, QChartAxis*> i(m_seriesAxisMap);
270 290 while (i.hasNext()) {
271 291 i.next();
272 292 if(i.key()->type()==type) count++;
@@ -276,7 +296,7 int ChartDataSet::seriesCount(QSeries::QSeriesType type)
276 296
277 297 int ChartDataSet::seriesIndex(QSeries *series)
278 298 {
279 int count(-1);
299 int count=-1;
280 300 QMapIterator<QSeries*, QChartAxis*> i(m_seriesAxisMap);
281 301 while (i.hasNext()) {
282 302 i.next();
@@ -304,7 +324,7 Domain* ChartDataSet::domain(QSeries* series) const
304 324
305 325 Domain* ChartDataSet::domain(QChartAxis* axis) const
306 326 {
307 if(axis==axisX()) {
327 if(!axis || axis==axisX()) {
308 328 return m_axisDomainMap.value(axisY());
309 329 }
310 330 else {
@@ -312,11 +332,6 Domain* ChartDataSet::domain(QChartAxis* axis) const
312 332 }
313 333 }
314 334
315 QChartAxis* ChartDataSet::axis(QSeries* series) const
316 {
317 return m_seriesAxisMap.value(series);
318 }
319
320 335 void ChartDataSet::scrollDomain(int dx,int dy,const QSizeF& size)
321 336 {
322 337 QMapIterator<QChartAxis*, Domain*> i( m_axisDomainMap);
@@ -1,3 +1,32
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 // W A R N I N G
22 // -------------
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
27 //
28 // We mean it.
29
1 30 #ifndef CHARTDATASET_P_H_
2 31 #define CHARTDATASET_P_H_
3 32
@@ -30,12 +59,11 public:
30 59
31 60 Domain* domain(QSeries* series) const;
32 61 Domain* domain(QChartAxis* axis) const;
33 QChartAxis* axis(QSeries* series) const;
34 62
35 63 QChartAxis* axisX() const { return m_axisX; }
36 64 QChartAxis* axisY(QSeries* series = 0) const;
37 65
38 signals:
66 Q_SIGNALS:
39 67 void seriesAdded(QSeries* series,Domain* domain);
40 68 void seriesRemoved(QSeries* series);
41 69 void axisAdded(QChartAxis* axis,Domain* domain);
@@ -1,3 +1,23
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
1 21 // W A R N I N G
2 22 // -------------
3 23 //
@@ -1,3 +1,23
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
1 21 // W A R N I N G
2 22 // -------------
3 23 //
@@ -1,3 +1,23
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
1 21 #include <QtTest/QtTest>
2 22 #include <qchartaxis.h>
3 23 #include <qlineseries.h>
@@ -12,18 +32,18 Q_DECLARE_METATYPE(QSeries*)
12 32 Q_DECLARE_METATYPE(QLineSeries*)
13 33
14 34 class tst_ChartDataSet: public QObject {
15 Q_OBJECT
16 35
17 public slots:
36 Q_OBJECT
37
38 public Q_SLOTS:
18 39 void initTestCase();
19 40 void cleanupTestCase();
20 41 void init();
21 42 void cleanup();
22 43
23 private slots:
44 private Q_SLOTS:
24 45 void chartdataset_data();
25 46 void chartdataset();
26
27 47 void addSeries_data();
28 48 void addSeries();
29 49 void removeSeries_data();
@@ -32,7 +52,18 private slots:
32 52 void removeAllSeries();
33 53 void axisY_data();
34 54 void axisY();
35
55 void seriesCount_data();
56 void seriesCount();
57 void seriesIndex_data();
58 void seriesIndex();
59 void domain_data();
60 void domain();
61 void zoomInDomain_data();
62 void zoomInDomain();
63 void zoomOutDomain_data();
64 void zoomOutDomain();
65 void scrollDomain_data();
66 void scrollDomain();
36 67 };
37 68
38 69 void tst_ChartDataSet::initTestCase()
@@ -121,28 +152,7 void tst_ChartDataSet::addSeries()
121 152
122 153 void tst_ChartDataSet::removeSeries_data()
123 154 {
124 QTest::addColumn<QLineSeries*>("series0");
125 QTest::addColumn<QChartAxis*>("axis0");
126 QTest::addColumn<QLineSeries*>("series1");
127 QTest::addColumn<QChartAxis*>("axis1");
128 QTest::addColumn<QLineSeries*>("series2");
129 QTest::addColumn<QChartAxis*>("axis2");
130 QTest::addColumn<int>("axisCount");
131
132 QLineSeries* series0 = new QLineSeries(this);
133 QLineSeries* series1 = new QLineSeries(this);
134 QLineSeries* series2 = new QLineSeries(this);
135
136 QChartAxis* axis0 = new QChartAxis(this);
137 QChartAxis* axis1 = new QChartAxis(this);
138 QChartAxis* axis2 = new QChartAxis(this);
139
140 QTest::newRow("default axis Y: series0,series1,series2") << series0 << (QChartAxis*) 0
141 << series1 << (QChartAxis*) 0 << series2 << (QChartAxis*) 0 << 2;
142 QTest::newRow("default axis Y: series0, axis 0: series1,series2") << series0 << (QChartAxis*) 0
143 << series1 << axis0 << series2 << axis0 << 3;
144 QTest::newRow("axis0: series0, axis1: series1, axis2: series2") << series0 << axis0 << series1
145 << axis1 << series2 << axis2 << 4;
155 addSeries_data();
146 156 }
147 157
148 158 void tst_ChartDataSet::removeSeries()
@@ -178,28 +188,7 void tst_ChartDataSet::removeSeries()
178 188
179 189 void tst_ChartDataSet::removeAllSeries_data()
180 190 {
181 QTest::addColumn<QLineSeries*>("series0");
182 QTest::addColumn<QChartAxis*>("axis0");
183 QTest::addColumn<QLineSeries*>("series1");
184 QTest::addColumn<QChartAxis*>("axis1");
185 QTest::addColumn<QLineSeries*>("series2");
186 QTest::addColumn<QChartAxis*>("axis2");
187 QTest::addColumn<int>("axisCount");
188
189 QLineSeries* series0 = new QLineSeries(this);
190 QLineSeries* series1 = new QLineSeries(this);
191 QLineSeries* series2 = new QLineSeries(this);
192
193 QChartAxis* axis0 = new QChartAxis(this);
194 QChartAxis* axis1 = new QChartAxis(this);
195 QChartAxis* axis2 = new QChartAxis(this);
196
197 QTest::newRow("default axis Y: series0,series1,series2") << series0 << (QChartAxis*) 0
198 << series1 << (QChartAxis*) 0 << series2 << (QChartAxis*) 0 << 2;
199 QTest::newRow("default axis Y: series0, axis 0: series1,series2") << series0 << (QChartAxis*) 0
200 << series1 << axis0 << series2 << axis0 << 3;
201 QTest::newRow("axis0: series0, axis1: series1, axis2: series2") << series0 << axis0 << series1
202 << axis1 << series2 << axis2 << 4;
191 addSeries_data();
203 192 }
204 193
205 194 void tst_ChartDataSet::removeAllSeries()
@@ -272,6 +261,230 void tst_ChartDataSet::axisY()
272 261
273 262 }
274 263
264 void tst_ChartDataSet::seriesCount_data()
265 {
266 addSeries_data();
267 }
268
269 void tst_ChartDataSet::seriesCount()
270 {
271 QFETCH(QLineSeries*, series0);
272 QFETCH(QChartAxis*, axis0);
273 QFETCH(QLineSeries*, series1);
274 QFETCH(QChartAxis*, axis1);
275 QFETCH(QLineSeries*, series2);
276 QFETCH(QChartAxis*, axis2);
277 QFETCH(int, axisCount);
278 Q_UNUSED(axisCount);
279
280 ChartDataSet dataSet;
281
282 dataSet.addSeries(series0, axis0);
283 dataSet.addSeries(series1, axis1);
284 dataSet.addSeries(series2, axis2);
285
286 QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*,Domain*)));
287 QSignalSpy spy1(&dataSet, SIGNAL(axisRemoved(QChartAxis*)));
288 QSignalSpy spy2(&dataSet, SIGNAL(seriesAdded(QSeries*,Domain*)));
289 QSignalSpy spy3(&dataSet, SIGNAL(seriesRemoved(QSeries*)));
290
291 QCOMPARE(dataSet.seriesCount(series0->type()),3);
292 QCOMPARE(spy0.count(), 0);
293 QCOMPARE(spy1.count(), 0);
294 QCOMPARE(spy2.count(), 0);
295 QCOMPARE(spy3.count(), 0);
296 }
297
298 void tst_ChartDataSet::seriesIndex_data()
299 {
300 addSeries_data();
301 }
302
303 void tst_ChartDataSet::seriesIndex()
304 {
305 QFETCH(QLineSeries*, series0);
306 QFETCH(QChartAxis*, axis0);
307 QFETCH(QLineSeries*, series1);
308 QFETCH(QChartAxis*, axis1);
309 QFETCH(QLineSeries*, series2);
310 QFETCH(QChartAxis*, axis2);
311 QFETCH(int, axisCount);
312 Q_UNUSED(axisCount);
313
314 ChartDataSet dataSet;
315
316 dataSet.addSeries(series0, axis0);
317 dataSet.addSeries(series1, axis1);
318 dataSet.addSeries(series2, axis2);
319
320 QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*,Domain*)));
321 QSignalSpy spy1(&dataSet, SIGNAL(axisRemoved(QChartAxis*)));
322 QSignalSpy spy2(&dataSet, SIGNAL(seriesAdded(QSeries*,Domain*)));
323 QSignalSpy spy3(&dataSet, SIGNAL(seriesRemoved(QSeries*)));
324
325 int i0 = dataSet.seriesIndex(series0);
326 int i1 = dataSet.seriesIndex(series1);
327 int i2 = dataSet.seriesIndex(series2);
328
329 QVERIFY(i1!=i2);
330 QVERIFY(i0!=i2);
331 QVERIFY(i0!=i1);
332
333 QCOMPARE(spy0.count(), 0);
334 QCOMPARE(spy1.count(), 0);
335 QCOMPARE(spy2.count(), 0);
336 QCOMPARE(spy3.count(), 0);
337 }
338
339 void tst_ChartDataSet::domain_data()
340 {
341 addSeries_data();
342 }
343
344 void tst_ChartDataSet::domain()
345 {
346 QFETCH(QLineSeries*, series0);
347 QFETCH(QChartAxis*, axis0);
348 QFETCH(QLineSeries*, series1);
349 QFETCH(QChartAxis*, axis1);
350 QFETCH(QLineSeries*, series2);
351 QFETCH(QChartAxis*, axis2);
352 QFETCH(int, axisCount);
353 Q_UNUSED(axisCount);
354
355 ChartDataSet dataSet;
356
357 dataSet.addSeries(series0, axis0);
358 dataSet.addSeries(series1, axis1);
359 dataSet.addSeries(series2, axis2);
360
361 QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*,Domain*)));
362 QSignalSpy spy1(&dataSet, SIGNAL(axisRemoved(QChartAxis*)));
363 QSignalSpy spy2(&dataSet, SIGNAL(seriesAdded(QSeries*,Domain*)));
364 QSignalSpy spy3(&dataSet, SIGNAL(seriesRemoved(QSeries*)));
365
366 QVERIFY(dataSet.domain(axis0)==dataSet.domain(series0));
367 QVERIFY(dataSet.domain(axis1)==dataSet.domain(series1));
368 QVERIFY(dataSet.domain(axis2)==dataSet.domain(series2));
369 QCOMPARE(spy0.count(), 0);
370 QCOMPARE(spy1.count(), 0);
371 QCOMPARE(spy2.count(), 0);
372 QCOMPARE(spy3.count(), 0);
373 }
374
375 void tst_ChartDataSet::zoomInDomain_data()
376 {
377 addSeries_data();
378 }
379
380 void tst_ChartDataSet::zoomInDomain()
381 {
382 QFETCH(QLineSeries*, series0);
383 QFETCH(QChartAxis*, axis0);
384 QFETCH(QLineSeries*, series1);
385 QFETCH(QChartAxis*, axis1);
386 QFETCH(QLineSeries*, series2);
387 QFETCH(QChartAxis*, axis2);
388 QFETCH(int, axisCount);
389
390 Q_UNUSED(axisCount);
391 ChartDataSet dataSet;
392
393 dataSet.addSeries(series0, axis0);
394 dataSet.addSeries(series1, axis1);
395 dataSet.addSeries(series2, axis2);
396
397 Domain* domain0 = dataSet.domain(series0);
398 Domain* domain1 = dataSet.domain(series1);
399 Domain* domain2 = dataSet.domain(series2);
400
401 QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
402 QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
403 QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
404
405 dataSet.zoomInDomain(QRect(0,0,100,100),QSize(1000,1000));
406
407 QCOMPARE(spy0.count(), 1);
408 QCOMPARE(spy1.count(), 1);
409 QCOMPARE(spy2.count(), 1);
410 }
411
412 void tst_ChartDataSet::zoomOutDomain_data()
413 {
414 addSeries_data();
415 }
416
417 void tst_ChartDataSet::zoomOutDomain()
418 {
419 QFETCH(QLineSeries*, series0);
420 QFETCH(QChartAxis*, axis0);
421 QFETCH(QLineSeries*, series1);
422 QFETCH(QChartAxis*, axis1);
423 QFETCH(QLineSeries*, series2);
424 QFETCH(QChartAxis*, axis2);
425 QFETCH(int, axisCount);
426
427 Q_UNUSED(axisCount);
428
429 ChartDataSet dataSet;
430
431 dataSet.addSeries(series0, axis0);
432 dataSet.addSeries(series1, axis1);
433 dataSet.addSeries(series2, axis2);
434
435 Domain* domain0 = dataSet.domain(series0);
436 Domain* domain1 = dataSet.domain(series1);
437 Domain* domain2 = dataSet.domain(series2);
438
439 QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
440 QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
441 QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
442
443 dataSet.zoomOutDomain(QRect(0,0,100,100),QSize(1000,1000));
444
445 QCOMPARE(spy0.count(), 1);
446 QCOMPARE(spy1.count(), 1);
447 QCOMPARE(spy2.count(), 1);
448 }
449
450 void tst_ChartDataSet::scrollDomain_data()
451 {
452 addSeries_data();
453 }
454
455 void tst_ChartDataSet::scrollDomain()
456 {
457 QFETCH(QLineSeries*, series0);
458 QFETCH(QChartAxis*, axis0);
459 QFETCH(QLineSeries*, series1);
460 QFETCH(QChartAxis*, axis1);
461 QFETCH(QLineSeries*, series2);
462 QFETCH(QChartAxis*, axis2);
463 QFETCH(int, axisCount);
464
465 Q_UNUSED(axisCount);
466
467 ChartDataSet dataSet;
468
469 dataSet.addSeries(series0, axis0);
470 dataSet.addSeries(series1, axis1);
471 dataSet.addSeries(series2, axis2);
472
473 Domain* domain0 = dataSet.domain(series0);
474 Domain* domain1 = dataSet.domain(series1);
475 Domain* domain2 = dataSet.domain(series2);
476
477 QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
478 QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
479 QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
480
481 dataSet.scrollDomain(10,10,QSize(1000,1000));
482
483 QCOMPARE(spy0.count(), 1);
484 QCOMPARE(spy1.count(), 1);
485 QCOMPARE(spy2.count(), 1);
486 }
487
275 488 QTEST_MAIN(tst_ChartDataSet)
276 489 #include "tst_chartdataset.moc"
277 490
General Comments 0
You need to be logged in to leave comments. Login now