##// END OF EJS Templates
Fix unit test
Michal Klocek -
r411:2606ead906f4
parent child
Show More
@@ -149,7 +149,7 void ChartDataSet::addSeries(QSeries* series, QChartAxis *axisY)
149 m_domainMap.replace(axisY,domain);
149 m_domainMap.replace(axisY,domain);
150 m_seriesMap.insert(axisY,series);
150 m_seriesMap.insert(axisY,series);
151 emit seriesAdded(series);
151 emit seriesAdded(series);
152 setDomain(m_domainIndex);
152 setDomain(m_domainIndex,axisY);
153
153
154 }
154 }
155
155
@@ -244,6 +244,27 void ChartDataSet::setDomain(int index)
244 emit axisRangeChanged(axisX(),labels);
244 emit axisRangeChanged(axisX(),labels);
245 }
245 }
246
246
247 void ChartDataSet::setDomain(int index,QChartAxis* axis)
248 {
249 int i = m_domainMap.count(axis) - index -1;
250 Q_ASSERT(i>=0);
251 Domain domain = m_domainMap.values(axis).at(i);
252 {
253 QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY);
254 QList<QSeries*> seriesList = m_seriesMap.values(axis);
255 foreach(QSeries* series, seriesList) {
256 emit seriesDomainChanged(series,domain);
257 }
258 axis->updateRange(domain.m_minY,domain.m_maxY);
259 emit axisRangeChanged(axis,labels);
260 }
261
262 QStringList labels = createLabels(axisX(),domain.m_minX,domain.m_maxX);
263 axisX()->updateRange(domain.m_minX,domain.m_maxY);
264 emit axisRangeChanged(axisX(),labels);
265 }
266
267
247 void ChartDataSet::clearDomains(int toIndex)
268 void ChartDataSet::clearDomains(int toIndex)
248 {
269 {
249 Q_ASSERT(toIndex>=0);
270 Q_ASSERT(toIndex>=0);
@@ -342,6 +363,8 void ChartDataSet::handleRangeChanged(QChartAxis* axis)
342 m_domainMap.replace(axis,domain);
363 m_domainMap.replace(axis,domain);
343 }
364 }
344
365
366 setDomain(m_domainIndex);
367
345 }
368 }
346 else {
369 else {
347
370
@@ -356,9 +379,11 void ChartDataSet::handleRangeChanged(QChartAxis* axis)
356
379
357 for(int j=domains.size()-1; j>=0;j--)
380 for(int j=domains.size()-1; j>=0;j--)
358 m_domainMap.insert(axis,domains.at(j));
381 m_domainMap.insert(axis,domains.at(j));
382
383 setDomain(m_domainIndex,axis);
359 }
384 }
360
385
361 setDomain(m_domainIndex);
386
362 }
387 }
363
388
364 void ChartDataSet::handleTickChanged(QChartAxis* axis)
389 void ChartDataSet::handleTickChanged(QChartAxis* axis)
@@ -26,6 +26,7 public:
26 const Domain domain(QChartAxis *axisY) const;
26 const Domain domain(QChartAxis *axisY) const;
27 int domainIndex() const {return m_domainIndex;}
27 int domainIndex() const {return m_domainIndex;}
28 void setDomain(int index);
28 void setDomain(int index);
29 void setDomain(int index,QChartAxis* axis);
29
30
30 QChartAxis* axisX() const { return m_axisX;};
31 QChartAxis* axisX() const { return m_axisX;};
31 QChartAxis* axisY(QSeries* series = 0) const;
32 QChartAxis* axisY(QSeries* series = 0) const;
@@ -135,69 +135,85 void tst_ChartDataSet::addDomain()
135
135
136 void tst_ChartDataSet::addSeries_data()
136 void tst_ChartDataSet::addSeries_data()
137 {
137 {
138 QTest::addColumn<int>("seriesCount");
138 QTest::addColumn<int>("defaultAxisCount");
139 QTest::addColumn<int>("axisYCount");
139 QTest::addColumn<int>("firstAxisCount");
140 QTest::newRow("2 series, default axis") << 2 << 0;
140 QTest::addColumn<int>("secoundAxisCount");
141 QTest::newRow("2 series, 2 new axis") << 2 << 2;
141 QTest::newRow("2 ,1 ,0") << 2 << 1 << 0;
142 QTest::newRow("2 series, 1 new axis") << 2 << 2;
142 QTest::newRow("2 series, 2 new axis") << 2 << 0 << 2;
143 QTest::newRow("3 series, 3 new axis") << 3 << 3;
143 QTest::newRow("2 series, 1 new axis") << 2 << 0 << 2;
144 QTest::newRow("3 series, 2 new axis") << 3 << 2;
144 QTest::newRow("3 series, 3 new axis") << 3 << 0 << 3;
145 QTest::newRow("3 series, 1 new axis") << 3 << 1;
145 QTest::newRow("3 series, 2 new axis") << 3 << 0 << 2;
146 QTest::newRow("3 series, 1 new axis") << 3 << 0 << 1;
147 QTest::newRow("3 series, default + 1 new axis") << 3 << 0 << 1;
146 }
148 }
147
149
148 void tst_ChartDataSet::addSeries()
150 void tst_ChartDataSet::addSeries()
149 {
151 {
150 QFETCH(int, seriesCount);
152 QFETCH(int, defaultAxisCount);
151 QFETCH(int, axisYCount);
153 QFETCH(int, firstAxisCount);
154 QFETCH(int, secoundAxisCount);
152
155
153 ChartDataSet dataSet;
156 ChartDataSet dataSet;
154
157
155 QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*)));
158 QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*)));
156 QSignalSpy spy1(&dataSet,
159 QSignalSpy spy1(&dataSet, SIGNAL(axisRangeChanged(QChartAxis*, QStringList const&)));
157 SIGNAL(axisRangeChanged(QChartAxis*, QStringList const&)));
160 QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*)));
158 QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*)));
161 QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QSeries*)));
159 QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QSeries*)));
162 QSignalSpy spy4(&dataSet, SIGNAL(seriesDomainChanged(QSeries*, Domain const&)));
160 QSignalSpy spy4(&dataSet,
163 QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QSeries*)));
161 SIGNAL(seriesDomainChanged(QSeries*, Domain const&)));
162 QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QSeries*)));
163
164
164 QList<QChartAxis*> axisList;
165 for (int i = 0; i < defaultAxisCount; i++) {
166 QLineSeries* series = new QLineSeries();
167 dataSet.addSeries(series);
168 }
165
169
166 for (int i = 0; i < axisYCount; i++) {
170 QChartAxis* firstAxis = new QChartAxis();
167 QChartAxis* axis = new QChartAxis();
168 axisList << axis;
169 }
170
171
171 QList<QChartAxis*>::iterator iterator = axisList.begin();
172 for (int i = 0; i < firstAxisCount; i++) {
173 QLineSeries* series = new QLineSeries();
174 dataSet.addSeries(series, firstAxis);
175 }
172
176
173 for (int i = 0; i < seriesCount; i++) {
177 QChartAxis* secoundAxis = new QChartAxis();
174 QChartAxis* axisY = 0;
178
175 QLineSeries* series = new QLineSeries();
179 for (int i = 0; i < secoundAxisCount; i++) {
176 if (iterator != axisList.end()) {
180 QLineSeries* series = new QLineSeries();
177 axisY = *iterator;
181 dataSet.addSeries(series, secoundAxis);
178 iterator++;
182 }
179 } else if (axisList.count() > 0) {
180 iterator--;
181 axisY = *iterator;
182 iterator++;
183 }
184 dataSet.addSeries(series, axisY);
185 }
186
183
187 //default axis
184 int axisCount = 1;
188 if (axisYCount == 0)
189 axisYCount+=2;
190 else
191 axisYCount++;
192
185
193 QCOMPARE(spy0.count(), axisYCount);
186 if (defaultAxisCount > 0)
194 QCOMPARE(spy1.count(), seriesCount*2);
187 axisCount++;
195 QCOMPARE(spy2.count(), 0);
188 if (firstAxisCount > 0)
196 QCOMPARE(spy3.count(), seriesCount);
189 axisCount++;
197 QCOMPARE(spy4.count(), seriesCount);
190 if (secoundAxisCount > 0)
198 QCOMPARE(spy5.count(), 0);
191 axisCount++;
199
192
200 QCOMPARE(dataSet.domainIndex(), 0);
193 QCOMPARE(spy0.count(), axisCount);
194 QCOMPARE(spy1.count(), (defaultAxisCount + firstAxisCount + secoundAxisCount)*2);
195 QCOMPARE(spy2.count(), 0);
196 QCOMPARE(spy3.count(), defaultAxisCount + firstAxisCount + secoundAxisCount);
197
198 int i = 0;
199 while (defaultAxisCount) {
200 i+=defaultAxisCount;
201 defaultAxisCount--;
202 }
203 int j = 0;
204 while (firstAxisCount>0) {
205 j += firstAxisCount;
206 firstAxisCount--;
207 }
208 int k = 0;
209 while (secoundAxisCount>0) {
210 k += secoundAxisCount;
211 secoundAxisCount--;
212 }
213 QCOMPARE(spy4.count(),i + j + k);
214 QCOMPARE(spy5.count(), 0);
215
216 QCOMPARE(dataSet.domainIndex(), 0);
201 }
217 }
202
218
203 void tst_ChartDataSet::axisY_data()
219 void tst_ChartDataSet::axisY_data()
@@ -344,7 +360,7 void tst_ChartDataSet::domain()
344 QCOMPARE(spy1.count(), 6);
360 QCOMPARE(spy1.count(), 6);
345 QCOMPARE(spy2.count(), 0);
361 QCOMPARE(spy2.count(), 0);
346 QCOMPARE(spy3.count(), 3);
362 QCOMPARE(spy3.count(), 3);
347 QCOMPARE(spy4.count(), 3);
363 QCOMPARE(spy4.count(), 6);
348 QCOMPARE(spy5.count(), 0);
364 QCOMPARE(spy5.count(), 0);
349 }
365 }
350
366
General Comments 0
You need to be logged in to leave comments. Login now