@@ -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,66 +135,82 void tst_ChartDataSet::addDomain() | |||||
135 |
|
135 | |||
136 | void tst_ChartDataSet::addSeries_data() |
|
136 | void tst_ChartDataSet::addSeries_data() | |
137 | { |
|
137 | { | |
138 |
QTest::addColumn<int>(" |
|
138 | QTest::addColumn<int>("defaultAxisCount"); | |
139 |
|
|
139 | QTest::addColumn<int>("firstAxisCount"); | |
140 | QTest::newRow("2 series, default axis") << 2 << 0; |
|
140 | QTest::addColumn<int>("secoundAxisCount"); | |
141 |
QTest::newRow("2 |
|
141 | QTest::newRow("2 ,1 ,0") << 2 << 1 << 0; | |
142 |
QTest::newRow("2 series, |
|
142 | QTest::newRow("2 series, 2 new axis") << 2 << 0 << 2; | |
143 |
QTest::newRow(" |
|
143 | QTest::newRow("2 series, 1 new axis") << 2 << 0 << 2; | |
144 |
QTest::newRow("3 series, |
|
144 | QTest::newRow("3 series, 3 new axis") << 3 << 0 << 3; | |
145 |
QTest::newRow("3 series, |
|
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 |
|
|
152 | QFETCH(int, defaultAxisCount); | |
151 |
|
|
153 | QFETCH(int, firstAxisCount); | |
|
154 | QFETCH(int, secoundAxisCount); | |||
152 |
|
155 | |||
153 |
|
|
156 | ChartDataSet dataSet; | |
154 |
|
157 | |||
155 |
|
|
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&))); |
|
|||
158 |
|
|
160 | QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); | |
159 |
|
|
161 | QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QSeries*))); | |
160 | QSignalSpy spy4(&dataSet, |
|
162 | QSignalSpy spy4(&dataSet, SIGNAL(seriesDomainChanged(QSeries*, Domain const&))); | |
161 | SIGNAL(seriesDomainChanged(QSeries*, Domain const&))); |
|
|||
162 |
|
|
163 | QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QSeries*))); | |
163 |
|
164 | |||
164 | QList<QChartAxis*> axisList; |
|
165 | for (int i = 0; i < defaultAxisCount; i++) { | |
165 |
|
166 | QLineSeries* series = new QLineSeries(); | ||
166 | for (int i = 0; i < axisYCount; i++) { |
|
167 | dataSet.addSeries(series); | |
167 | QChartAxis* axis = new QChartAxis(); |
|
|||
168 | axisList << axis; |
|
|||
169 | } |
|
168 | } | |
170 |
|
169 | |||
171 | QList<QChartAxis*>::iterator iterator = axisList.begin(); |
|
170 | QChartAxis* firstAxis = new QChartAxis(); | |
172 |
|
171 | |||
173 |
|
|
172 | for (int i = 0; i < firstAxisCount; i++) { | |
174 | QChartAxis* axisY = 0; |
|
|||
175 |
|
|
173 | QLineSeries* series = new QLineSeries(); | |
176 | if (iterator != axisList.end()) { |
|
174 | dataSet.addSeries(series, firstAxis); | |
177 | axisY = *iterator; |
|
|||
178 | iterator++; |
|
|||
179 | } else if (axisList.count() > 0) { |
|
|||
180 | iterator--; |
|
|||
181 | axisY = *iterator; |
|
|||
182 | iterator++; |
|
|||
183 | } |
|
175 | } | |
184 | dataSet.addSeries(series, axisY); |
|
176 | ||
|
177 | QChartAxis* secoundAxis = new QChartAxis(); | |||
|
178 | ||||
|
179 | for (int i = 0; i < secoundAxisCount; i++) { | |||
|
180 | QLineSeries* series = new QLineSeries(); | |||
|
181 | dataSet.addSeries(series, secoundAxis); | |||
185 | } |
|
182 | } | |
186 |
|
183 | |||
187 | //default axis |
|
184 | int axisCount = 1; | |
188 | if (axisYCount == 0) |
|
185 | ||
189 | axisYCount+=2; |
|
186 | if (defaultAxisCount > 0) | |
190 | else |
|
187 | axisCount++; | |
191 | axisYCount++; |
|
188 | if (firstAxisCount > 0) | |
|
189 | axisCount++; | |||
|
190 | if (secoundAxisCount > 0) | |||
|
191 | axisCount++; | |||
192 |
|
192 | |||
193 |
|
|
193 | QCOMPARE(spy0.count(), axisCount); | |
194 | QCOMPARE(spy1.count(), seriesCount*2); |
|
194 | QCOMPARE(spy1.count(), (defaultAxisCount + firstAxisCount + secoundAxisCount)*2); | |
195 |
|
|
195 | QCOMPARE(spy2.count(), 0); | |
196 | QCOMPARE(spy3.count(), seriesCount); |
|
196 | QCOMPARE(spy3.count(), defaultAxisCount + firstAxisCount + secoundAxisCount); | |
197 | QCOMPARE(spy4.count(), seriesCount); |
|
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); | |||
198 |
|
|
214 | QCOMPARE(spy5.count(), 0); | |
199 |
|
215 | |||
200 |
|
|
216 | QCOMPARE(dataSet.domainIndex(), 0); | |
@@ -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(), |
|
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