@@ -48,9 +48,7 void ChartDataSet::addSeries(QSeries* series, QChartAxis *axisY) | |||
|
48 | 48 | { |
|
49 | 49 | if(axisY==0) axisY = m_axisY; |
|
50 | 50 | |
|
51 | QChartAxis* axis = m_seriesAxisMap.value(series); | |
|
52 | ||
|
53 | if(axis) { | |
|
51 | if (seriesIndex(series) > -1) { | |
|
54 | 52 | qWarning() << "Can not add series. Series already on the chart"; |
|
55 | 53 | return; |
|
56 | 54 | } |
@@ -64,8 +62,7 void ChartDataSet::addSeries(QSeries* series, QChartAxis *axisY) | |||
|
64 | 62 | } |
|
65 | 63 | |
|
66 | 64 | Domain* domain = m_axisDomainMap.value(axisY); |
|
67 | ||
|
68 | if(!domain) { | |
|
65 | if (!domain) { | |
|
69 | 66 | domain = new Domain(axisY); |
|
70 | 67 | QObject::connect(axisY,SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool))); |
|
71 | 68 | QObject::connect(axisX(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool))); |
@@ -76,70 +73,75 void ChartDataSet::addSeries(QSeries* series, QChartAxis *axisY) | |||
|
76 | 73 | emit axisAdded(axisY,domain); |
|
77 | 74 | } |
|
78 | 75 | |
|
79 | if(!m_axisXInitialized){ | |
|
80 | emit axisAdded(axisX(),domain); | |
|
81 | m_axisXInitialized=true; | |
|
76 | if (!m_axisXInitialized) { | |
|
77 | emit axisAdded(axisX(), domain); | |
|
78 | m_axisXInitialized = true; | |
|
82 | 79 | } |
|
83 | 80 | |
|
84 | calculateDomain(series,domain); | |
|
81 | calculateDomain(series, domain); | |
|
85 | 82 | |
|
86 |
m_seriesAxis |
|
|
87 | emit seriesAdded(series,domain); | |
|
83 | m_seriesAxisList.append(QPair<QSeries*, QChartAxis*>(series, axisY)); | |
|
88 | 84 | |
|
85 | emit seriesAdded(series, domain); | |
|
89 | 86 | } |
|
90 | 87 | |
|
91 | 88 | void ChartDataSet::removeSeries(QSeries* series) |
|
92 | 89 | { |
|
93 | ||
|
94 | QChartAxis* axis = m_seriesAxisMap.value(series); | |
|
95 | ||
|
96 | if(!axis){ | |
|
97 | qWarning()<<"Can not remove series. Series not found on the chart."; | |
|
90 | int index = seriesIndex(series); | |
|
91 | if (!index < 0) { | |
|
92 | qWarning() << "Can not remove series. Series not found on the chart."; | |
|
98 | 93 | return; |
|
99 | 94 | } |
|
100 | emit seriesRemoved(series); | |
|
101 | m_seriesAxisMap.remove(series); | |
|
102 | 95 | |
|
103 | if(series->parent()==this){ | |
|
96 | // Remove the series and the axis from the container | |
|
97 | QChartAxis* axis = m_seriesAxisList.at(index).second; | |
|
98 | m_seriesAxisList.removeAt(index); | |
|
99 | ||
|
100 | // Delete the series | |
|
101 | emit seriesRemoved(series); | |
|
102 | if (series->parent() == this) { | |
|
104 | 103 | delete series; |
|
105 | series=0; | |
|
104 | series = 0; | |
|
106 | 105 | } |
|
107 | 106 | |
|
108 | QList<QChartAxis*> axes = m_seriesAxisMap.values(); | |
|
109 | ||
|
110 | int i = axes.indexOf(axis); | |
|
107 | // Check if the Y axis is still in use | |
|
108 | bool yAxisInUse(false); | |
|
109 | for (int i(0); i < m_seriesAxisList.count(); i++) { | |
|
110 | QPair<QSeries *, QChartAxis *> pair = m_seriesAxisList.at(i); | |
|
111 | if (pair.second == axis) | |
|
112 | yAxisInUse = true; | |
|
113 | } | |
|
111 | 114 | |
|
112 | if(i==-1){ | |
|
115 | // Remove the Y axis if not in use | |
|
116 | if (!yAxisInUse) { | |
|
113 | 117 | Domain* domain = m_axisDomainMap.take(axis); |
|
114 | 118 | emit axisRemoved(axis); |
|
115 | if(axis!=axisY()){ | |
|
116 | if(axis->parent()==this){ | |
|
119 | if (axis != axisY()) { | |
|
120 | // Delete the Y axis unless it is the default one | |
|
121 | if (axis->parent() == this) { | |
|
117 | 122 | delete axis; |
|
118 | axis=0; | |
|
123 | axis = 0; | |
|
119 | 124 | } |
|
120 | 125 | } |
|
121 | 126 | delete domain; |
|
122 | 127 | } |
|
123 | 128 | |
|
124 | if(m_seriesAxisMap.values().size()==0) | |
|
125 | { | |
|
126 | m_axisXInitialized=false; | |
|
129 | // Remove the x axis in case there are no y-axes left | |
|
130 | if (m_seriesAxisList.count() == 0) { | |
|
131 | m_axisXInitialized = false; | |
|
127 | 132 | emit axisRemoved(axisX()); |
|
128 | 133 | } |
|
129 | 134 | } |
|
130 | 135 | |
|
131 | 136 | void ChartDataSet::removeAllSeries() |
|
132 | 137 | { |
|
133 | ||
|
134 |
|
|
|
135 | ||
|
136 | foreach(QSeries* s , series) { | |
|
137 | removeSeries(s); | |
|
138 | while (m_seriesAxisList.count()) { | |
|
139 | QPair<QSeries *, QChartAxis *> pair = m_seriesAxisList.last(); | |
|
140 | removeSeries(pair.first); | |
|
138 | 141 | } |
|
139 | 142 | |
|
140 |
Q_ASSERT(m_seriesAxis |
|
|
141 | Q_ASSERT(m_axisDomainMap.count()==0); | |
|
142 | ||
|
143 | Q_ASSERT(m_seriesAxisList.count() == 0); | |
|
144 | Q_ASSERT(m_axisDomainMap.count() == 0); | |
|
143 | 145 | } |
|
144 | 146 | |
|
145 | 147 | //to be removed with PIMPL |
@@ -282,43 +284,30 void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size) | |||
|
282 | 284 | } |
|
283 | 285 | } |
|
284 | 286 | |
|
285 |
int ChartDataSet::series |
|
|
286 | { | |
|
287 | int count=0; | |
|
288 | QMapIterator<QSeries*, QChartAxis*> i(m_seriesAxisMap); | |
|
289 | while (i.hasNext()) { | |
|
290 | i.next(); | |
|
291 | if(i.key()->type()==type) count++; | |
|
292 | } | |
|
293 | return count; | |
|
294 | } | |
|
295 | ||
|
296 | int ChartDataSet::seriesIndex(QSeries *series) | |
|
287 | int ChartDataSet::seriesIndex(QSeries *series) const | |
|
297 | 288 | { |
|
298 | int count=-1; | |
|
299 |
|
|
|
300 | while (i.hasNext()) { | |
|
301 | i.next(); | |
|
302 | count++; | |
|
303 | if (i.key() == series) | |
|
304 | return count; | |
|
289 | for (int i(0); i < m_seriesAxisList.count(); i++) { | |
|
290 | QPair<QSeries *, QChartAxis *> pair = m_seriesAxisList.at(i); | |
|
291 | if (pair.first == series) | |
|
292 | return i; | |
|
305 | 293 | } |
|
306 |
return |
|
|
294 | return -1; | |
|
307 | 295 | } |
|
308 | 296 | |
|
309 | 297 | QChartAxis* ChartDataSet::axisY(QSeries* series) const |
|
310 | 298 | { |
|
311 |
if(series == 0) |
|
|
312 | return m_seriesAxisMap.value(series); | |
|
299 | if (series == 0) | |
|
300 | return m_axisY; | |
|
301 | ||
|
302 | return m_seriesAxisList.at(seriesIndex(series)).second; | |
|
313 | 303 | } |
|
314 | 304 | |
|
315 | 305 | Domain* ChartDataSet::domain(QSeries* series) const |
|
316 | 306 | { |
|
317 |
|
|
|
318 |
|
|
|
307 | QChartAxis* axis = m_seriesAxisList.at(seriesIndex(series)).second; | |
|
308 | if (axis) | |
|
319 | 309 | return m_axisDomainMap.value(axis); |
|
320 | }else | |
|
321 | return 0; | |
|
310 | return 0; | |
|
322 | 311 | } |
|
323 | 312 | |
|
324 | 313 | Domain* ChartDataSet::domain(QChartAxis* axis) const |
@@ -54,8 +54,7 public: | |||
|
54 | 54 | void zoomOutDomain(const QRectF& rect, const QSizeF& size); |
|
55 | 55 | void scrollDomain(int dx,int dy,const QSizeF& size); |
|
56 | 56 | |
|
57 |
int series |
|
|
58 | int seriesIndex(QSeries *series); | |
|
57 | int seriesIndex(QSeries *series) const; | |
|
59 | 58 | |
|
60 | 59 | Domain* domain(QSeries* series) const; |
|
61 | 60 | Domain* domain(QChartAxis* axis) const; |
@@ -75,7 +74,7 private: | |||
|
75 | 74 | void setupCategories(QBarSeries* series); |
|
76 | 75 | |
|
77 | 76 | private: |
|
78 |
Q |
|
|
77 | QList<QPair<QSeries*, QChartAxis*> > m_seriesAxisList; | |
|
79 | 78 | QMap<QChartAxis*, Domain*> m_axisDomainMap; |
|
80 | 79 | QChartAxis* m_axisX; |
|
81 | 80 | QChartAxis* m_axisY; |
@@ -52,8 +52,6 private Q_SLOTS: | |||
|
52 | 52 | void removeAllSeries(); |
|
53 | 53 | void axisY_data(); |
|
54 | 54 | void axisY(); |
|
55 | void seriesCount_data(); | |
|
56 | void seriesCount(); | |
|
57 | 55 | void seriesIndex_data(); |
|
58 | 56 | void seriesIndex(); |
|
59 | 57 | void domain_data(); |
@@ -261,40 +259,6 void tst_ChartDataSet::axisY() | |||
|
261 | 259 | |
|
262 | 260 | } |
|
263 | 261 | |
|
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 | 262 | void tst_ChartDataSet::seriesIndex_data() |
|
299 | 263 | { |
|
300 | 264 | addSeries_data(); |
@@ -210,6 +210,7 void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QS | |||
|
210 | 210 | for (int j(0); j < data.count(); j ++) { |
|
211 | 211 | QList<qreal> column = data.at(j); |
|
212 | 212 | QLineSeries *series = new QLineSeries(); |
|
213 | series->setName("line" + QString::number(j)); | |
|
213 | 214 | for (int i(0); i < column.count(); i++) |
|
214 | 215 | series->append(i, column.at(i)); |
|
215 | 216 | m_chart->addSeries(series); |
@@ -222,12 +223,14 void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QS | |||
|
222 | 223 | for (int i(0); i < column.count(); i++) |
|
223 | 224 | lineSeries->append(i, column.at(i)); |
|
224 | 225 | QAreaSeries *areaSeries = new QAreaSeries(lineSeries); |
|
226 | areaSeries->setName("area" + QString::number(j)); | |
|
225 | 227 | m_chart->addSeries(areaSeries); |
|
226 | 228 | } |
|
227 | 229 | } else if (seriesName == "Scatter") { |
|
228 | 230 | for (int j(0); j < data.count(); j++) { |
|
229 | 231 | QList<qreal> column = data.at(j); |
|
230 | 232 | QScatterSeries *series = new QScatterSeries(); |
|
233 | series->setName("scatter" + QString::number(j)); | |
|
231 | 234 | for (int i(0); i < column.count(); i++) |
|
232 | 235 | series->append(i, column.at(i)); |
|
233 | 236 | m_chart->addSeries(series); |
General Comments 0
You need to be logged in to leave comments.
Login now