From 2606ead906f44d7288d137ea9f1759ce3ffcaf14 2012-02-29 14:48:04 From: Michal Klocek Date: 2012-02-29 14:48:04 Subject: [PATCH] Fix unit test --- diff --git a/src/chartdataset.cpp b/src/chartdataset.cpp index 93218b1..dcc3515 100644 --- a/src/chartdataset.cpp +++ b/src/chartdataset.cpp @@ -149,7 +149,7 @@ void ChartDataSet::addSeries(QSeries* series, QChartAxis *axisY) m_domainMap.replace(axisY,domain); m_seriesMap.insert(axisY,series); emit seriesAdded(series); - setDomain(m_domainIndex); + setDomain(m_domainIndex,axisY); } @@ -244,6 +244,27 @@ void ChartDataSet::setDomain(int index) emit axisRangeChanged(axisX(),labels); } +void ChartDataSet::setDomain(int index,QChartAxis* axis) +{ + int i = m_domainMap.count(axis) - index -1; + Q_ASSERT(i>=0); + Domain domain = m_domainMap.values(axis).at(i); + { + QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY); + QList seriesList = m_seriesMap.values(axis); + foreach(QSeries* series, seriesList) { + emit seriesDomainChanged(series,domain); + } + axis->updateRange(domain.m_minY,domain.m_maxY); + emit axisRangeChanged(axis,labels); + } + + QStringList labels = createLabels(axisX(),domain.m_minX,domain.m_maxX); + axisX()->updateRange(domain.m_minX,domain.m_maxY); + emit axisRangeChanged(axisX(),labels); +} + + void ChartDataSet::clearDomains(int toIndex) { Q_ASSERT(toIndex>=0); @@ -342,6 +363,8 @@ void ChartDataSet::handleRangeChanged(QChartAxis* axis) m_domainMap.replace(axis,domain); } + setDomain(m_domainIndex); + } else { @@ -356,9 +379,11 @@ void ChartDataSet::handleRangeChanged(QChartAxis* axis) for(int j=domains.size()-1; j>=0;j--) m_domainMap.insert(axis,domains.at(j)); + + setDomain(m_domainIndex,axis); } - setDomain(m_domainIndex); + } void ChartDataSet::handleTickChanged(QChartAxis* axis) diff --git a/src/chartdataset_p.h b/src/chartdataset_p.h index 8116e67..f8e449b 100644 --- a/src/chartdataset_p.h +++ b/src/chartdataset_p.h @@ -26,6 +26,7 @@ public: const Domain domain(QChartAxis *axisY) const; int domainIndex() const {return m_domainIndex;} void setDomain(int index); + void setDomain(int index,QChartAxis* axis); QChartAxis* axisX() const { return m_axisX;}; QChartAxis* axisY(QSeries* series = 0) const; diff --git a/test/auto/chartdataset/tst_chartdataset.cpp b/test/auto/chartdataset/tst_chartdataset.cpp index 92581e3..66543a7 100644 --- a/test/auto/chartdataset/tst_chartdataset.cpp +++ b/test/auto/chartdataset/tst_chartdataset.cpp @@ -135,69 +135,85 @@ void tst_ChartDataSet::addDomain() void tst_ChartDataSet::addSeries_data() { - QTest::addColumn("seriesCount"); - QTest::addColumn("axisYCount"); - QTest::newRow("2 series, default axis") << 2 << 0; - QTest::newRow("2 series, 2 new axis") << 2 << 2; - QTest::newRow("2 series, 1 new axis") << 2 << 2; - QTest::newRow("3 series, 3 new axis") << 3 << 3; - QTest::newRow("3 series, 2 new axis") << 3 << 2; - QTest::newRow("3 series, 1 new axis") << 3 << 1; + QTest::addColumn("defaultAxisCount"); + QTest::addColumn("firstAxisCount"); + QTest::addColumn("secoundAxisCount"); + QTest::newRow("2 ,1 ,0") << 2 << 1 << 0; + QTest::newRow("2 series, 2 new axis") << 2 << 0 << 2; + QTest::newRow("2 series, 1 new axis") << 2 << 0 << 2; + QTest::newRow("3 series, 3 new axis") << 3 << 0 << 3; + QTest::newRow("3 series, 2 new axis") << 3 << 0 << 2; + QTest::newRow("3 series, 1 new axis") << 3 << 0 << 1; + QTest::newRow("3 series, default + 1 new axis") << 3 << 0 << 1; } void tst_ChartDataSet::addSeries() { - QFETCH(int, seriesCount); - QFETCH(int, axisYCount); + QFETCH(int, defaultAxisCount); + QFETCH(int, firstAxisCount); + QFETCH(int, secoundAxisCount); - ChartDataSet dataSet; + ChartDataSet dataSet; - QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*))); - QSignalSpy spy1(&dataSet, - SIGNAL(axisRangeChanged(QChartAxis*, QStringList const&))); - QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); - QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QSeries*))); - QSignalSpy spy4(&dataSet, - SIGNAL(seriesDomainChanged(QSeries*, Domain const&))); - QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QSeries*))); + QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*))); + QSignalSpy spy1(&dataSet, SIGNAL(axisRangeChanged(QChartAxis*, QStringList const&))); + QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); + QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QSeries*))); + QSignalSpy spy4(&dataSet, SIGNAL(seriesDomainChanged(QSeries*, Domain const&))); + QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QSeries*))); - QList axisList; + for (int i = 0; i < defaultAxisCount; i++) { + QLineSeries* series = new QLineSeries(); + dataSet.addSeries(series); + } - for (int i = 0; i < axisYCount; i++) { - QChartAxis* axis = new QChartAxis(); - axisList << axis; - } + QChartAxis* firstAxis = new QChartAxis(); - QList::iterator iterator = axisList.begin(); + for (int i = 0; i < firstAxisCount; i++) { + QLineSeries* series = new QLineSeries(); + dataSet.addSeries(series, firstAxis); + } - for (int i = 0; i < seriesCount; i++) { - QChartAxis* axisY = 0; - QLineSeries* series = new QLineSeries(); - if (iterator != axisList.end()) { - axisY = *iterator; - iterator++; - } else if (axisList.count() > 0) { - iterator--; - axisY = *iterator; - iterator++; - } - dataSet.addSeries(series, axisY); - } + QChartAxis* secoundAxis = new QChartAxis(); + + for (int i = 0; i < secoundAxisCount; i++) { + QLineSeries* series = new QLineSeries(); + dataSet.addSeries(series, secoundAxis); + } - //default axis - if (axisYCount == 0) - axisYCount+=2; - else - axisYCount++; + int axisCount = 1; - QCOMPARE(spy0.count(), axisYCount); - QCOMPARE(spy1.count(), seriesCount*2); - QCOMPARE(spy2.count(), 0); - QCOMPARE(spy3.count(), seriesCount); - QCOMPARE(spy4.count(), seriesCount); - QCOMPARE(spy5.count(), 0); + if (defaultAxisCount > 0) + axisCount++; + if (firstAxisCount > 0) + axisCount++; + if (secoundAxisCount > 0) + axisCount++; - QCOMPARE(dataSet.domainIndex(), 0); + QCOMPARE(spy0.count(), axisCount); + QCOMPARE(spy1.count(), (defaultAxisCount + firstAxisCount + secoundAxisCount)*2); + QCOMPARE(spy2.count(), 0); + QCOMPARE(spy3.count(), defaultAxisCount + firstAxisCount + secoundAxisCount); + + int i = 0; + while (defaultAxisCount) { + i+=defaultAxisCount; + defaultAxisCount--; + } + int j = 0; + while (firstAxisCount>0) { + j += firstAxisCount; + firstAxisCount--; + } + int k = 0; + while (secoundAxisCount>0) { + k += secoundAxisCount; + secoundAxisCount--; + } + QCOMPARE(spy4.count(),i + j + k); + QCOMPARE(spy5.count(), 0); + + QCOMPARE(dataSet.domainIndex(), 0); } void tst_ChartDataSet::axisY_data() @@ -344,7 +360,7 @@ void tst_ChartDataSet::domain() QCOMPARE(spy1.count(), 6); QCOMPARE(spy2.count(), 0); QCOMPARE(spy3.count(), 3); - QCOMPARE(spy4.count(), 3); + QCOMPARE(spy4.count(), 6); QCOMPARE(spy5.count(), 0); }