From 9f133768a877a68d9432c3d189d2d650b3dd29ac 2012-03-28 14:38:19 From: Michal Klocek Date: 2012-03-28 14:38:19 Subject: [PATCH] Updates chartdataset unit test --- diff --git a/src/chartdataset.cpp b/src/chartdataset.cpp index 1ba1dc5..412efb0 100644 --- a/src/chartdataset.cpp +++ b/src/chartdataset.cpp @@ -1,3 +1,23 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the Qt Commercial Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** $QT_END_LICENSE$ +** +****************************************************************************/ + #include "chartdataset_p.h" #include "qchartaxis.h" //series @@ -247,7 +267,7 @@ void ChartDataSet::setupCategories(QBarSeries* series) void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size) { - QMapIterator i( m_axisDomainMap); + QMapIterator i(m_axisDomainMap); while (i.hasNext()) { i.next(); i.value()->zoomIn(rect,size); @@ -256,7 +276,7 @@ void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size) void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size) { - QMapIterator i( m_axisDomainMap); + QMapIterator i(m_axisDomainMap); while (i.hasNext()) { i.next(); i.value()->zoomOut(rect,size); @@ -266,7 +286,7 @@ void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size) int ChartDataSet::seriesCount(QSeries::QSeriesType type) { int count=0; - QMapIterator i( m_seriesAxisMap); + QMapIterator i(m_seriesAxisMap); while (i.hasNext()) { i.next(); if(i.key()->type()==type) count++; @@ -276,7 +296,7 @@ int ChartDataSet::seriesCount(QSeries::QSeriesType type) int ChartDataSet::seriesIndex(QSeries *series) { - int count(-1); + int count=-1; QMapIterator i(m_seriesAxisMap); while (i.hasNext()) { i.next(); @@ -304,7 +324,7 @@ Domain* ChartDataSet::domain(QSeries* series) const Domain* ChartDataSet::domain(QChartAxis* axis) const { - if(axis==axisX()) { + if(!axis || axis==axisX()) { return m_axisDomainMap.value(axisY()); } else { @@ -312,11 +332,6 @@ Domain* ChartDataSet::domain(QChartAxis* axis) const } } -QChartAxis* ChartDataSet::axis(QSeries* series) const -{ - return m_seriesAxisMap.value(series); -} - void ChartDataSet::scrollDomain(int dx,int dy,const QSizeF& size) { QMapIterator i( m_axisDomainMap); diff --git a/src/chartdataset_p.h b/src/chartdataset_p.h index 1e140ef..8a915e4 100644 --- a/src/chartdataset_p.h +++ b/src/chartdataset_p.h @@ -1,3 +1,32 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the Qt Commercial Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// W A R N I N G +// ------------- +// +// This file is not part of the QtCommercial Chart API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. + #ifndef CHARTDATASET_P_H_ #define CHARTDATASET_P_H_ @@ -30,12 +59,11 @@ public: Domain* domain(QSeries* series) const; Domain* domain(QChartAxis* axis) const; - QChartAxis* axis(QSeries* series) const; QChartAxis* axisX() const { return m_axisX; } QChartAxis* axisY(QSeries* series = 0) const; -signals: +Q_SIGNALS: void seriesAdded(QSeries* series,Domain* domain); void seriesRemoved(QSeries* series); void axisAdded(QChartAxis* axis,Domain* domain); diff --git a/src/qchart_p.h b/src/qchart_p.h index 134d9a3..a28a2af 100644 --- a/src/qchart_p.h +++ b/src/qchart_p.h @@ -1,3 +1,23 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the Qt Commercial Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** $QT_END_LICENSE$ +** +****************************************************************************/ + // W A R N I N G // ------------- // diff --git a/src/qchartview_p.h b/src/qchartview_p.h index bc9abea..f1a2bc3 100644 --- a/src/qchartview_p.h +++ b/src/qchartview_p.h @@ -1,3 +1,23 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the Qt Commercial Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** $QT_END_LICENSE$ +** +****************************************************************************/ + // W A R N I N G // ------------- // diff --git a/test/auto/chartdataset/tst_chartdataset.cpp b/test/auto/chartdataset/tst_chartdataset.cpp index c391ed5..15636d8 100644 --- a/test/auto/chartdataset/tst_chartdataset.cpp +++ b/test/auto/chartdataset/tst_chartdataset.cpp @@ -1,3 +1,23 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the Qt Commercial Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** $QT_END_LICENSE$ +** +****************************************************************************/ + #include #include #include @@ -12,18 +32,18 @@ Q_DECLARE_METATYPE(QSeries*) Q_DECLARE_METATYPE(QLineSeries*) class tst_ChartDataSet: public QObject { -Q_OBJECT -public slots: + Q_OBJECT + +public Q_SLOTS: void initTestCase(); void cleanupTestCase(); void init(); void cleanup(); -private slots: +private Q_SLOTS: void chartdataset_data(); void chartdataset(); - void addSeries_data(); void addSeries(); void removeSeries_data(); @@ -32,7 +52,18 @@ private slots: void removeAllSeries(); void axisY_data(); void axisY(); - + void seriesCount_data(); + void seriesCount(); + void seriesIndex_data(); + void seriesIndex(); + void domain_data(); + void domain(); + void zoomInDomain_data(); + void zoomInDomain(); + void zoomOutDomain_data(); + void zoomOutDomain(); + void scrollDomain_data(); + void scrollDomain(); }; void tst_ChartDataSet::initTestCase() @@ -121,28 +152,7 @@ void tst_ChartDataSet::addSeries() void tst_ChartDataSet::removeSeries_data() { - QTest::addColumn("series0"); - QTest::addColumn("axis0"); - QTest::addColumn("series1"); - QTest::addColumn("axis1"); - QTest::addColumn("series2"); - QTest::addColumn("axis2"); - QTest::addColumn("axisCount"); - - QLineSeries* series0 = new QLineSeries(this); - QLineSeries* series1 = new QLineSeries(this); - QLineSeries* series2 = new QLineSeries(this); - - QChartAxis* axis0 = new QChartAxis(this); - QChartAxis* axis1 = new QChartAxis(this); - QChartAxis* axis2 = new QChartAxis(this); - - QTest::newRow("default axis Y: series0,series1,series2") << series0 << (QChartAxis*) 0 - << series1 << (QChartAxis*) 0 << series2 << (QChartAxis*) 0 << 2; - QTest::newRow("default axis Y: series0, axis 0: series1,series2") << series0 << (QChartAxis*) 0 - << series1 << axis0 << series2 << axis0 << 3; - QTest::newRow("axis0: series0, axis1: series1, axis2: series2") << series0 << axis0 << series1 - << axis1 << series2 << axis2 << 4; + addSeries_data(); } void tst_ChartDataSet::removeSeries() @@ -178,28 +188,7 @@ void tst_ChartDataSet::removeSeries() void tst_ChartDataSet::removeAllSeries_data() { - QTest::addColumn("series0"); - QTest::addColumn("axis0"); - QTest::addColumn("series1"); - QTest::addColumn("axis1"); - QTest::addColumn("series2"); - QTest::addColumn("axis2"); - QTest::addColumn("axisCount"); - - QLineSeries* series0 = new QLineSeries(this); - QLineSeries* series1 = new QLineSeries(this); - QLineSeries* series2 = new QLineSeries(this); - - QChartAxis* axis0 = new QChartAxis(this); - QChartAxis* axis1 = new QChartAxis(this); - QChartAxis* axis2 = new QChartAxis(this); - - QTest::newRow("default axis Y: series0,series1,series2") << series0 << (QChartAxis*) 0 - << series1 << (QChartAxis*) 0 << series2 << (QChartAxis*) 0 << 2; - QTest::newRow("default axis Y: series0, axis 0: series1,series2") << series0 << (QChartAxis*) 0 - << series1 << axis0 << series2 << axis0 << 3; - QTest::newRow("axis0: series0, axis1: series1, axis2: series2") << series0 << axis0 << series1 - << axis1 << series2 << axis2 << 4; + addSeries_data(); } void tst_ChartDataSet::removeAllSeries() @@ -272,6 +261,230 @@ void tst_ChartDataSet::axisY() } +void tst_ChartDataSet::seriesCount_data() +{ + addSeries_data(); +} + +void tst_ChartDataSet::seriesCount() +{ + QFETCH(QLineSeries*, series0); + QFETCH(QChartAxis*, axis0); + QFETCH(QLineSeries*, series1); + QFETCH(QChartAxis*, axis1); + QFETCH(QLineSeries*, series2); + QFETCH(QChartAxis*, axis2); + QFETCH(int, axisCount); + Q_UNUSED(axisCount); + + ChartDataSet dataSet; + + dataSet.addSeries(series0, axis0); + dataSet.addSeries(series1, axis1); + dataSet.addSeries(series2, axis2); + + QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*,Domain*))); + QSignalSpy spy1(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); + QSignalSpy spy2(&dataSet, SIGNAL(seriesAdded(QSeries*,Domain*))); + QSignalSpy spy3(&dataSet, SIGNAL(seriesRemoved(QSeries*))); + + QCOMPARE(dataSet.seriesCount(series0->type()),3); + QCOMPARE(spy0.count(), 0); + QCOMPARE(spy1.count(), 0); + QCOMPARE(spy2.count(), 0); + QCOMPARE(spy3.count(), 0); +} + +void tst_ChartDataSet::seriesIndex_data() +{ + addSeries_data(); +} + +void tst_ChartDataSet::seriesIndex() +{ + QFETCH(QLineSeries*, series0); + QFETCH(QChartAxis*, axis0); + QFETCH(QLineSeries*, series1); + QFETCH(QChartAxis*, axis1); + QFETCH(QLineSeries*, series2); + QFETCH(QChartAxis*, axis2); + QFETCH(int, axisCount); + Q_UNUSED(axisCount); + + ChartDataSet dataSet; + + dataSet.addSeries(series0, axis0); + dataSet.addSeries(series1, axis1); + dataSet.addSeries(series2, axis2); + + QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*,Domain*))); + QSignalSpy spy1(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); + QSignalSpy spy2(&dataSet, SIGNAL(seriesAdded(QSeries*,Domain*))); + QSignalSpy spy3(&dataSet, SIGNAL(seriesRemoved(QSeries*))); + + int i0 = dataSet.seriesIndex(series0); + int i1 = dataSet.seriesIndex(series1); + int i2 = dataSet.seriesIndex(series2); + + QVERIFY(i1!=i2); + QVERIFY(i0!=i2); + QVERIFY(i0!=i1); + + QCOMPARE(spy0.count(), 0); + QCOMPARE(spy1.count(), 0); + QCOMPARE(spy2.count(), 0); + QCOMPARE(spy3.count(), 0); +} + +void tst_ChartDataSet::domain_data() +{ + addSeries_data(); +} + +void tst_ChartDataSet::domain() +{ + QFETCH(QLineSeries*, series0); + QFETCH(QChartAxis*, axis0); + QFETCH(QLineSeries*, series1); + QFETCH(QChartAxis*, axis1); + QFETCH(QLineSeries*, series2); + QFETCH(QChartAxis*, axis2); + QFETCH(int, axisCount); + Q_UNUSED(axisCount); + + ChartDataSet dataSet; + + dataSet.addSeries(series0, axis0); + dataSet.addSeries(series1, axis1); + dataSet.addSeries(series2, axis2); + + QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*,Domain*))); + QSignalSpy spy1(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); + QSignalSpy spy2(&dataSet, SIGNAL(seriesAdded(QSeries*,Domain*))); + QSignalSpy spy3(&dataSet, SIGNAL(seriesRemoved(QSeries*))); + + QVERIFY(dataSet.domain(axis0)==dataSet.domain(series0)); + QVERIFY(dataSet.domain(axis1)==dataSet.domain(series1)); + QVERIFY(dataSet.domain(axis2)==dataSet.domain(series2)); + QCOMPARE(spy0.count(), 0); + QCOMPARE(spy1.count(), 0); + QCOMPARE(spy2.count(), 0); + QCOMPARE(spy3.count(), 0); +} + +void tst_ChartDataSet::zoomInDomain_data() +{ + addSeries_data(); +} + +void tst_ChartDataSet::zoomInDomain() +{ + QFETCH(QLineSeries*, series0); + QFETCH(QChartAxis*, axis0); + QFETCH(QLineSeries*, series1); + QFETCH(QChartAxis*, axis1); + QFETCH(QLineSeries*, series2); + QFETCH(QChartAxis*, axis2); + QFETCH(int, axisCount); + + Q_UNUSED(axisCount); + ChartDataSet dataSet; + + dataSet.addSeries(series0, axis0); + dataSet.addSeries(series1, axis1); + dataSet.addSeries(series2, axis2); + + Domain* domain0 = dataSet.domain(series0); + Domain* domain1 = dataSet.domain(series1); + Domain* domain2 = dataSet.domain(series2); + + QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); + QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); + QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); + + dataSet.zoomInDomain(QRect(0,0,100,100),QSize(1000,1000)); + + QCOMPARE(spy0.count(), 1); + QCOMPARE(spy1.count(), 1); + QCOMPARE(spy2.count(), 1); +} + +void tst_ChartDataSet::zoomOutDomain_data() +{ + addSeries_data(); +} + +void tst_ChartDataSet::zoomOutDomain() +{ + QFETCH(QLineSeries*, series0); + QFETCH(QChartAxis*, axis0); + QFETCH(QLineSeries*, series1); + QFETCH(QChartAxis*, axis1); + QFETCH(QLineSeries*, series2); + QFETCH(QChartAxis*, axis2); + QFETCH(int, axisCount); + + Q_UNUSED(axisCount); + + ChartDataSet dataSet; + + dataSet.addSeries(series0, axis0); + dataSet.addSeries(series1, axis1); + dataSet.addSeries(series2, axis2); + + Domain* domain0 = dataSet.domain(series0); + Domain* domain1 = dataSet.domain(series1); + Domain* domain2 = dataSet.domain(series2); + + QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); + QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); + QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); + + dataSet.zoomOutDomain(QRect(0,0,100,100),QSize(1000,1000)); + + QCOMPARE(spy0.count(), 1); + QCOMPARE(spy1.count(), 1); + QCOMPARE(spy2.count(), 1); +} + +void tst_ChartDataSet::scrollDomain_data() +{ + addSeries_data(); +} + +void tst_ChartDataSet::scrollDomain() +{ + QFETCH(QLineSeries*, series0); + QFETCH(QChartAxis*, axis0); + QFETCH(QLineSeries*, series1); + QFETCH(QChartAxis*, axis1); + QFETCH(QLineSeries*, series2); + QFETCH(QChartAxis*, axis2); + QFETCH(int, axisCount); + + Q_UNUSED(axisCount); + + ChartDataSet dataSet; + + dataSet.addSeries(series0, axis0); + dataSet.addSeries(series1, axis1); + dataSet.addSeries(series2, axis2); + + Domain* domain0 = dataSet.domain(series0); + Domain* domain1 = dataSet.domain(series1); + Domain* domain2 = dataSet.domain(series2); + + QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); + QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); + QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); + + dataSet.scrollDomain(10,10,QSize(1000,1000)); + + QCOMPARE(spy0.count(), 1); + QCOMPARE(spy1.count(), 1); + QCOMPARE(spy2.count(), 1); +} + QTEST_MAIN(tst_ChartDataSet) #include "tst_chartdataset.moc"