@@ -1,314 +1,314 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "chartdataset_p.h" |
|
21 | #include "chartdataset_p.h" | |
22 | #include "qchart.h" |
|
22 | #include "qchart.h" | |
23 | #include "qvaluesaxis.h" |
|
23 | #include "qvaluesaxis.h" | |
24 | #include "qvaluesaxis_p.h" |
|
24 | #include "qvaluesaxis_p.h" | |
25 | #include "qabstractseries_p.h" |
|
25 | #include "qabstractseries_p.h" | |
26 | #include "qbarseries.h" |
|
26 | #include "qbarseries.h" | |
27 | #include "qstackedbarseries.h" |
|
27 | #include "qstackedbarseries.h" | |
28 | #include "qpercentbarseries.h" |
|
28 | #include "qpercentbarseries.h" | |
29 | #include "qpieseries.h" |
|
29 | #include "qpieseries.h" | |
30 |
|
30 | |||
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
32 |
|
32 | |||
33 | ChartDataSet::ChartDataSet(QChart *parent):QObject(parent), |
|
33 | ChartDataSet::ChartDataSet(QChart *parent):QObject(parent), | |
34 | m_domainIndex(0) |
|
34 | m_domainIndex(0) | |
35 | { |
|
35 | { | |
36 |
|
36 | |||
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | ChartDataSet::~ChartDataSet() |
|
39 | ChartDataSet::~ChartDataSet() | |
40 | { |
|
40 | { | |
41 | removeAllSeries(); |
|
41 | removeAllSeries(); | |
42 | } |
|
42 | } | |
43 |
|
43 | |||
44 | void ChartDataSet::addSeries(QAbstractSeries* series) |
|
44 | void ChartDataSet::addSeries(QAbstractSeries* series) | |
45 | { |
|
45 | { | |
46 | QAbstractAxis* axis = m_seriesAxisXMap.value(series); |
|
46 | QAbstractAxis* axis = m_seriesAxisXMap.value(series); | |
47 |
|
47 | |||
48 | if(axis) { |
|
48 | if(axis) { | |
49 | qWarning() << "Can not add series. Series already on the chart"; |
|
49 | qWarning() << "Can not add series. Series already on the chart"; | |
50 | return; |
|
50 | return; | |
51 | } |
|
51 | } | |
52 |
|
52 | |||
53 | QAbstractAxis* axisX = series->d_ptr->createAxisX(this); |
|
53 | QAbstractAxis* axisX = series->d_ptr->createAxisX(this); | |
54 | QAbstractAxis* axisY = series->d_ptr->createAxisY(this); |
|
54 | QAbstractAxis* axisY = series->d_ptr->createAxisY(this); | |
55 |
|
55 | |||
56 | series->setParent(this); // take ownership |
|
56 | series->setParent(this); // take ownership | |
57 |
|
57 | |||
58 | Domain* domain = new Domain(series); |
|
58 | Domain* domain = new Domain(series); | |
59 |
|
59 | |||
60 | if(axisX){ |
|
60 | if(axisX){ | |
61 | QObject::connect(axisX->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool))); |
|
61 | QObject::connect(axisX->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool))); | |
62 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axisX->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); |
|
62 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axisX->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); | |
63 | axisX->d_ptr->m_orientation=Qt::Horizontal; |
|
63 | axisX->d_ptr->m_orientation=Qt::Horizontal; | |
64 | emit axisAdded(axisX,domain); |
|
64 | emit axisAdded(axisX,domain); | |
65 | m_seriesAxisXMap.insert(series,axisX); |
|
65 | m_seriesAxisXMap.insert(series,axisX); | |
66 | } |
|
66 | } | |
67 |
|
67 | |||
68 | if(axisY){ |
|
68 | if(axisY){ | |
69 | QObject::connect(axisY->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool))); |
|
69 | QObject::connect(axisY->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool))); | |
70 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axisY->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); |
|
70 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axisY->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); | |
71 | axisY->d_ptr->m_orientation=Qt::Vertical; |
|
71 | axisY->d_ptr->m_orientation=Qt::Vertical; | |
72 | emit axisAdded(axisY,domain); |
|
72 | emit axisAdded(axisY,domain); | |
73 | m_seriesAxisYMap.insert(series,axisY); |
|
73 | m_seriesAxisYMap.insert(series,axisY); | |
74 | } |
|
74 | } | |
75 |
|
75 | |||
76 | m_seriesDomainMap.insert(series,domain); |
|
76 | m_seriesDomainMap.insert(series,domain); | |
77 |
|
77 | |||
78 | series->d_ptr->scaleDomain(*domain); |
|
78 | series->d_ptr->scaleDomain(*domain); | |
79 |
|
79 | |||
80 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); |
|
80 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); | |
81 |
|
81 | |||
82 | int key=0; |
|
82 | int key=0; | |
83 | while (i.hasNext()) { |
|
83 | while (i.hasNext()) { | |
84 | i.next(); |
|
84 | i.next(); | |
85 | if(i.key()!=key) { |
|
85 | if(i.key()!=key) { | |
86 | break; |
|
86 | break; | |
87 | } |
|
87 | } | |
88 | key++; |
|
88 | key++; | |
89 | } |
|
89 | } | |
90 |
|
90 | |||
91 | m_indexSeriesMap.insert(key,series); |
|
91 | m_indexSeriesMap.insert(key,series); | |
92 |
|
92 | |||
93 | series->d_ptr->m_chart = qobject_cast<QChart*>(parent()); |
|
93 | series->d_ptr->m_chart = qobject_cast<QChart*>(parent()); | |
94 | series->d_ptr->m_dataset = this; |
|
94 | series->d_ptr->m_dataset = this; | |
95 |
|
95 | |||
96 | emit seriesAdded(series,domain); |
|
96 | emit seriesAdded(series,domain); | |
97 |
|
97 | |||
98 | } |
|
98 | } | |
99 |
|
99 | |||
100 | void ChartDataSet::removeSeries(QAbstractSeries* series) |
|
100 | void ChartDataSet::removeSeries(QAbstractSeries* series) | |
101 | { |
|
101 | { | |
102 | Domain* domain = m_seriesDomainMap.take(series); |
|
102 | Domain* domain = m_seriesDomainMap.take(series); | |
103 |
|
103 | |||
104 | if(!domain) { |
|
104 | if(!domain) { | |
105 | qWarning()<<"Can not remove series. Series not found on the chart."; |
|
105 | qWarning()<<"Can not remove series. Series not found on the chart."; | |
106 | } |
|
106 | } | |
107 |
|
107 | |||
108 | emit seriesRemoved(series); |
|
108 | emit seriesRemoved(series); | |
109 |
|
109 | |||
110 | delete domain; |
|
110 | delete domain; | |
111 | domain = 0; |
|
111 | domain = 0; | |
112 |
|
112 | |||
113 | int key = seriesIndex(series); |
|
113 | int key = seriesIndex(series); | |
114 | Q_ASSERT(key!=-1); |
|
114 | Q_ASSERT(key!=-1); | |
115 |
|
115 | |||
116 | m_indexSeriesMap.remove(key); |
|
116 | m_indexSeriesMap.remove(key); | |
117 |
|
117 | |||
118 | series->setParent(0); |
|
118 | series->setParent(0); | |
119 | series->d_ptr->m_chart = 0; |
|
119 | series->d_ptr->m_chart = 0; | |
120 | series->d_ptr->m_dataset = 0; |
|
120 | series->d_ptr->m_dataset = 0; | |
121 |
|
121 | |||
122 | QAbstractAxis* axisX = m_seriesAxisXMap.take(series); |
|
122 | QAbstractAxis* axisX = m_seriesAxisXMap.take(series); | |
123 |
|
123 | |||
124 | if(axisX) { |
|
124 | if(axisX) { | |
125 | QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values(); |
|
125 | QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values(); | |
126 | int x = axesX.indexOf(axisX); |
|
126 | int x = axesX.indexOf(axisX); | |
127 |
|
127 | |||
128 | if(x==-1) { |
|
128 | if(x==-1) { | |
129 | emit axisRemoved(axisX); |
|
129 | emit axisRemoved(axisX); | |
130 |
axisX |
|
130 | delete axisX; | |
131 | } |
|
131 | } | |
132 | } |
|
132 | } | |
133 |
|
133 | |||
134 | QAbstractAxis* axisY = m_seriesAxisYMap.take(series); |
|
134 | QAbstractAxis* axisY = m_seriesAxisYMap.take(series); | |
135 |
|
135 | |||
136 | if(axisY) { |
|
136 | if(axisY) { | |
137 | QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values(); |
|
137 | QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values(); | |
138 |
|
138 | |||
139 | int y = axesY.indexOf(axisY); |
|
139 | int y = axesY.indexOf(axisY); | |
140 |
|
140 | |||
141 | if(y==-1) { |
|
141 | if(y==-1) { | |
142 | emit axisRemoved(axisY); |
|
142 | emit axisRemoved(axisY); | |
143 |
axisY |
|
143 | delete axisY; | |
144 | } |
|
144 | } | |
145 | } |
|
145 | } | |
146 | } |
|
146 | } | |
147 |
|
147 | |||
148 | void ChartDataSet::removeAllSeries() |
|
148 | void ChartDataSet::removeAllSeries() | |
149 | { |
|
149 | { | |
150 | QList<QAbstractSeries*> series = m_seriesDomainMap.keys(); |
|
150 | QList<QAbstractSeries*> series = m_seriesDomainMap.keys(); | |
151 | foreach(QAbstractSeries *s , series) { |
|
151 | foreach(QAbstractSeries *s , series) { | |
152 | removeSeries(s); |
|
152 | removeSeries(s); | |
153 | } |
|
153 | } | |
154 |
|
154 | |||
155 | Q_ASSERT(m_seriesAxisXMap.count()==0); |
|
155 | Q_ASSERT(m_seriesAxisXMap.count()==0); | |
156 | Q_ASSERT(m_seriesAxisXMap.count()==0); |
|
156 | Q_ASSERT(m_seriesAxisXMap.count()==0); | |
157 | Q_ASSERT(m_seriesDomainMap.count()==0); |
|
157 | Q_ASSERT(m_seriesDomainMap.count()==0); | |
158 |
|
158 | |||
159 | qDeleteAll(series); |
|
159 | qDeleteAll(series); | |
160 | } |
|
160 | } | |
161 |
|
161 | |||
162 | void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size) |
|
162 | void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size) | |
163 | { |
|
163 | { | |
164 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
164 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | |
165 | while (i.hasNext()) { |
|
165 | while (i.hasNext()) { | |
166 | i.next(); |
|
166 | i.next(); | |
167 | i.value()->zoomIn(rect,size); |
|
167 | i.value()->zoomIn(rect,size); | |
168 | } |
|
168 | } | |
169 | } |
|
169 | } | |
170 |
|
170 | |||
171 | void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size) |
|
171 | void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size) | |
172 | { |
|
172 | { | |
173 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
173 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | |
174 | while (i.hasNext()) { |
|
174 | while (i.hasNext()) { | |
175 | i.next(); |
|
175 | i.next(); | |
176 | i.value()->zoomOut(rect,size); |
|
176 | i.value()->zoomOut(rect,size); | |
177 | } |
|
177 | } | |
178 | } |
|
178 | } | |
179 |
|
179 | |||
180 | int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type) |
|
180 | int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type) | |
181 | { |
|
181 | { | |
182 | int count=0; |
|
182 | int count=0; | |
183 | QMapIterator<QAbstractSeries*, QAbstractAxis*> i(m_seriesAxisXMap); |
|
183 | QMapIterator<QAbstractSeries*, QAbstractAxis*> i(m_seriesAxisXMap); | |
184 | while (i.hasNext()) { |
|
184 | while (i.hasNext()) { | |
185 | i.next(); |
|
185 | i.next(); | |
186 | if(i.key()->type()==type) count++; |
|
186 | if(i.key()->type()==type) count++; | |
187 | } |
|
187 | } | |
188 | return count; |
|
188 | return count; | |
189 | } |
|
189 | } | |
190 |
|
190 | |||
191 | int ChartDataSet::seriesIndex(QAbstractSeries *series) |
|
191 | int ChartDataSet::seriesIndex(QAbstractSeries *series) | |
192 | { |
|
192 | { | |
193 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); |
|
193 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); | |
194 | while (i.hasNext()) { |
|
194 | while (i.hasNext()) { | |
195 | i.next(); |
|
195 | i.next(); | |
196 | if (i.value() == series) |
|
196 | if (i.value() == series) | |
197 | return i.key(); |
|
197 | return i.key(); | |
198 | } |
|
198 | } | |
199 | return -1; |
|
199 | return -1; | |
200 | } |
|
200 | } | |
201 |
|
201 | |||
202 | QAbstractAxis* ChartDataSet::axisX(QAbstractSeries *series) const |
|
202 | QAbstractAxis* ChartDataSet::axisX(QAbstractSeries *series) const | |
203 | { |
|
203 | { | |
204 | if(series == 0) return m_seriesAxisXMap.begin().value(); |
|
204 | if(series == 0) return m_seriesAxisXMap.begin().value(); | |
205 | return m_seriesAxisXMap.value(series); |
|
205 | return m_seriesAxisXMap.value(series); | |
206 | } |
|
206 | } | |
207 |
|
207 | |||
208 | QAbstractAxis* ChartDataSet::axisY(QAbstractSeries *series) const |
|
208 | QAbstractAxis* ChartDataSet::axisY(QAbstractSeries *series) const | |
209 | { |
|
209 | { | |
210 | if(series == 0) return m_seriesAxisYMap.begin().value(); |
|
210 | if(series == 0) return m_seriesAxisYMap.begin().value(); | |
211 | return m_seriesAxisYMap.value(series); |
|
211 | return m_seriesAxisYMap.value(series); | |
212 | } |
|
212 | } | |
213 |
|
213 | |||
214 | void ChartDataSet::setAxisX(QAbstractSeries *series, QAbstractAxis *axis) |
|
214 | void ChartDataSet::setAxisX(QAbstractSeries *series, QAbstractAxis *axis) | |
215 | { |
|
215 | { | |
216 | Q_ASSERT(axis); |
|
216 | Q_ASSERT(axis); | |
217 | QAbstractAxis *oldAxis = m_seriesAxisXMap.take(series); |
|
217 | QAbstractAxis *oldAxis = m_seriesAxisXMap.take(series); | |
218 |
|
218 | |||
219 | if(!oldAxis) { |
|
219 | if(!oldAxis) { | |
220 | qWarning()<<"Series not found on the chart."; |
|
220 | qWarning()<<"Series not found on the chart."; | |
221 | return; |
|
221 | return; | |
222 | } |
|
222 | } | |
223 |
|
223 | |||
224 | if(axis->d_ptr->m_orientation==Qt::Vertical) { |
|
224 | if(axis->d_ptr->m_orientation==Qt::Vertical) { | |
225 | qWarning()<<"Axis already defined as axis Y"; |
|
225 | qWarning()<<"Axis already defined as axis Y"; | |
226 | return; |
|
226 | return; | |
227 | } |
|
227 | } | |
228 |
|
228 | |||
229 | QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values(); |
|
229 | QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values(); | |
230 | int x = axesX.indexOf(oldAxis); |
|
230 | int x = axesX.indexOf(oldAxis); | |
231 | if(x==-1) { |
|
231 | if(x==-1) { | |
232 | emit axisRemoved(oldAxis); |
|
232 | emit axisRemoved(oldAxis); | |
233 | delete oldAxis; |
|
233 | delete oldAxis; | |
234 | } |
|
234 | } | |
235 |
|
235 | |||
236 | Domain* domain = m_seriesDomainMap.value(series); |
|
236 | Domain* domain = m_seriesDomainMap.value(series); | |
237 | Q_ASSERT(domain); |
|
237 | Q_ASSERT(domain); | |
238 |
|
238 | |||
239 | QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool))); |
|
239 | QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool))); | |
240 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); |
|
240 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); | |
241 |
|
241 | |||
242 | x = axesX.indexOf(axis); |
|
242 | x = axesX.indexOf(axis); | |
243 | if(x==-1) { |
|
243 | if(x==-1) { | |
244 | axis->d_ptr->m_orientation=Qt::Horizontal; |
|
244 | axis->d_ptr->m_orientation=Qt::Horizontal; | |
245 | emit axisAdded(axis,domain); |
|
245 | emit axisAdded(axis,domain); | |
246 | } |
|
246 | } | |
247 |
|
247 | |||
248 | m_seriesAxisXMap.insert(series,axis); |
|
248 | m_seriesAxisXMap.insert(series,axis); | |
249 | } |
|
249 | } | |
250 |
|
250 | |||
251 | void ChartDataSet::setAxisY(QAbstractSeries *series, QAbstractAxis *axis) |
|
251 | void ChartDataSet::setAxisY(QAbstractSeries *series, QAbstractAxis *axis) | |
252 | { |
|
252 | { | |
253 | Q_ASSERT(axis); |
|
253 | Q_ASSERT(axis); | |
254 | QAbstractAxis *oldAxis = m_seriesAxisYMap.take(series); |
|
254 | QAbstractAxis *oldAxis = m_seriesAxisYMap.take(series); | |
255 |
|
255 | |||
256 | if(!oldAxis) { |
|
256 | if(!oldAxis) { | |
257 | qWarning()<<"Series not found on the chart or axis is unsupported for given series type"; |
|
257 | qWarning()<<"Series not found on the chart or axis is unsupported for given series type"; | |
258 | return; |
|
258 | return; | |
259 | } |
|
259 | } | |
260 |
|
260 | |||
261 | if(axis->d_ptr->m_orientation==Qt::Horizontal) { |
|
261 | if(axis->d_ptr->m_orientation==Qt::Horizontal) { | |
262 | qWarning()<<"Axis already defined as axis X"; |
|
262 | qWarning()<<"Axis already defined as axis X"; | |
263 | return; |
|
263 | return; | |
264 | } |
|
264 | } | |
265 |
|
265 | |||
266 | QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values(); |
|
266 | QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values(); | |
267 | int y = axesY.indexOf(oldAxis); |
|
267 | int y = axesY.indexOf(oldAxis); | |
268 | if(y==-1) { |
|
268 | if(y==-1) { | |
269 | emit axisRemoved(oldAxis); |
|
269 | emit axisRemoved(oldAxis); | |
270 | delete oldAxis; |
|
270 | delete oldAxis; | |
271 | } |
|
271 | } | |
272 |
|
272 | |||
273 | Domain* domain = m_seriesDomainMap.value(series); |
|
273 | Domain* domain = m_seriesDomainMap.value(series); | |
274 | Q_ASSERT(domain); |
|
274 | Q_ASSERT(domain); | |
275 |
|
275 | |||
276 | QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool))); |
|
276 | QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool))); | |
277 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); |
|
277 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); | |
278 |
|
278 | |||
279 | y = axesY.indexOf(axis); |
|
279 | y = axesY.indexOf(axis); | |
280 | if(y==-1) { |
|
280 | if(y==-1) { | |
281 | axis->d_ptr->m_orientation=Qt::Vertical; |
|
281 | axis->d_ptr->m_orientation=Qt::Vertical; | |
282 | emit axisAdded(axis,domain); |
|
282 | emit axisAdded(axis,domain); | |
283 | } |
|
283 | } | |
284 |
|
284 | |||
285 | m_seriesAxisYMap.insert(series,axis); |
|
285 | m_seriesAxisYMap.insert(series,axis); | |
286 | } |
|
286 | } | |
287 |
|
287 | |||
288 | Domain* ChartDataSet::domain(QAbstractSeries *series) const |
|
288 | Domain* ChartDataSet::domain(QAbstractSeries *series) const | |
289 | { |
|
289 | { | |
290 | return m_seriesDomainMap.value(series); |
|
290 | return m_seriesDomainMap.value(series); | |
291 | } |
|
291 | } | |
292 |
|
292 | |||
293 | void ChartDataSet::scrollDomain(qreal dx,qreal dy,const QSizeF& size) |
|
293 | void ChartDataSet::scrollDomain(qreal dx,qreal dy,const QSizeF& size) | |
294 | { |
|
294 | { | |
295 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
295 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | |
296 | while (i.hasNext()) { |
|
296 | while (i.hasNext()) { | |
297 | i.next(); |
|
297 | i.next(); | |
298 | i.value()->move(dx,dy,size); |
|
298 | i.value()->move(dx,dy,size); | |
299 | } |
|
299 | } | |
300 | } |
|
300 | } | |
301 |
|
301 | |||
302 | QList<QAbstractSeries*> ChartDataSet::series() const |
|
302 | QList<QAbstractSeries*> ChartDataSet::series() const | |
303 | { |
|
303 | { | |
304 | return m_seriesAxisXMap.keys(); |
|
304 | return m_seriesAxisXMap.keys(); | |
305 | } |
|
305 | } | |
306 |
|
306 | |||
307 | void ChartDataSet::updateSeries(QAbstractSeries *series) |
|
307 | void ChartDataSet::updateSeries(QAbstractSeries *series) | |
308 | { |
|
308 | { | |
309 | emit seriesUpdated(series); |
|
309 | emit seriesUpdated(series); | |
310 | } |
|
310 | } | |
311 |
|
311 | |||
312 | #include "moc_chartdataset_p.cpp" |
|
312 | #include "moc_chartdataset_p.cpp" | |
313 |
|
313 | |||
314 | QTCOMMERCIALCHART_END_NAMESPACE |
|
314 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,639 +1,632 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include <QtTest/QtTest> |
|
21 | #include <QtTest/QtTest> | |
22 | #include <qabstractaxis.h> |
|
22 | #include <qabstractaxis.h> | |
23 | #include <qvaluesaxis.h> |
|
23 | #include <qvaluesaxis.h> | |
24 | #include <qcategoriesaxis.h> |
|
24 | #include <qcategoriesaxis.h> | |
25 | #include <qlineseries.h> |
|
25 | #include <qlineseries.h> | |
26 | #include <qareaseries.h> |
|
26 | #include <qareaseries.h> | |
27 | #include <qscatterseries.h> |
|
27 | #include <qscatterseries.h> | |
28 | #include <qsplineseries.h> |
|
28 | #include <qsplineseries.h> | |
29 | #include <qpieseries.h> |
|
29 | #include <qpieseries.h> | |
30 | #include <qbarseries.h> |
|
30 | #include <qbarseries.h> | |
31 | #include <qpercentbarseries.h> |
|
31 | #include <qpercentbarseries.h> | |
32 | #include <qstackedbarseries.h> |
|
32 | #include <qstackedbarseries.h> | |
33 | #include <private/chartdataset_p.h> |
|
33 | #include <private/chartdataset_p.h> | |
34 | #include <private/domain_p.h> |
|
34 | #include <private/domain_p.h> | |
35 | #include <tst_definitions.h> |
|
35 | #include <tst_definitions.h> | |
36 |
|
36 | |||
37 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
37 | QTCOMMERCIALCHART_USE_NAMESPACE | |
38 |
|
38 | |||
39 | Q_DECLARE_METATYPE(Domain *) |
|
39 | Q_DECLARE_METATYPE(Domain *) | |
40 | Q_DECLARE_METATYPE(QAbstractAxis *) |
|
40 | Q_DECLARE_METATYPE(QAbstractAxis *) | |
41 | Q_DECLARE_METATYPE(QAbstractSeries *) |
|
41 | Q_DECLARE_METATYPE(QAbstractSeries *) | |
42 | Q_DECLARE_METATYPE(QList<QAbstractSeries *>) |
|
42 | Q_DECLARE_METATYPE(QList<QAbstractSeries *>) | |
43 | Q_DECLARE_METATYPE(QList<QAbstractAxis *>) |
|
43 | Q_DECLARE_METATYPE(QList<QAbstractAxis *>) | |
44 | Q_DECLARE_METATYPE(QLineSeries *) |
|
44 | Q_DECLARE_METATYPE(QLineSeries *) | |
45 |
|
45 | |||
46 | class tst_ChartDataSet: public QObject { |
|
46 | class tst_ChartDataSet: public QObject { | |
47 |
|
47 | |||
48 | Q_OBJECT |
|
48 | Q_OBJECT | |
49 |
|
49 | |||
50 | public Q_SLOTS: |
|
50 | public Q_SLOTS: | |
51 | void initTestCase(); |
|
51 | void initTestCase(); | |
52 | void cleanupTestCase(); |
|
52 | void cleanupTestCase(); | |
53 | void init(); |
|
53 | void init(); | |
54 | void cleanup(); |
|
54 | void cleanup(); | |
55 |
|
55 | |||
56 | private Q_SLOTS: |
|
56 | private Q_SLOTS: | |
57 | void chartdataset_data(); |
|
57 | void chartdataset_data(); | |
58 | void chartdataset(); |
|
58 | void chartdataset(); | |
59 | void addSeries_data(); |
|
59 | void addSeries_data(); | |
60 | void addSeries(); |
|
60 | void addSeries(); | |
61 | void setAxisX_data(); |
|
61 | void setAxisX_data(); | |
62 | void setAxisX(); |
|
62 | void setAxisX(); | |
63 | void setAxisY_data(); |
|
63 | void setAxisY_data(); | |
64 | void setAxisY(); |
|
64 | void setAxisY(); | |
65 | void removeSeries_data(); |
|
65 | void removeSeries_data(); | |
66 | void removeSeries(); |
|
66 | void removeSeries(); | |
67 | void removeAllSeries_data(); |
|
67 | void removeAllSeries_data(); | |
68 | void removeAllSeries(); |
|
68 | void removeAllSeries(); | |
69 | void seriesCount_data(); |
|
69 | void seriesCount_data(); | |
70 | void seriesCount(); |
|
70 | void seriesCount(); | |
71 | void seriesIndex_data(); |
|
71 | void seriesIndex_data(); | |
72 | void seriesIndex(); |
|
72 | void seriesIndex(); | |
73 | /* |
|
73 | /* | |
74 | void domain_data(); |
|
74 | void domain_data(); | |
75 | void domain(); |
|
75 | void domain(); | |
76 | void zoomInDomain_data(); |
|
76 | void zoomInDomain_data(); | |
77 | void zoomInDomain(); |
|
77 | void zoomInDomain(); | |
78 | void zoomOutDomain_data(); |
|
78 | void zoomOutDomain_data(); | |
79 | void zoomOutDomain(); |
|
79 | void zoomOutDomain(); | |
80 | void scrollDomain_data(); |
|
80 | void scrollDomain_data(); | |
81 | void scrollDomain(); |
|
81 | void scrollDomain(); | |
82 | */ |
|
82 | */ | |
83 | private: |
|
83 | private: | |
84 | ChartDataSet* m_dataset; |
|
84 | ChartDataSet* m_dataset; | |
85 | }; |
|
85 | }; | |
86 |
|
86 | |||
87 | void tst_ChartDataSet::initTestCase() |
|
87 | void tst_ChartDataSet::initTestCase() | |
88 | { |
|
88 | { | |
89 | qRegisterMetaType<Domain*>(); |
|
89 | qRegisterMetaType<Domain*>(); | |
90 | qRegisterMetaType<QAbstractAxis*>(); |
|
90 | qRegisterMetaType<QAbstractAxis*>(); | |
91 | qRegisterMetaType<QAbstractSeries*>(); |
|
91 | qRegisterMetaType<QAbstractSeries*>(); | |
92 | } |
|
92 | } | |
93 |
|
93 | |||
94 | void tst_ChartDataSet::cleanupTestCase() |
|
94 | void tst_ChartDataSet::cleanupTestCase() | |
95 | { |
|
95 | { | |
96 | } |
|
96 | } | |
97 |
|
97 | |||
98 | void tst_ChartDataSet::init() |
|
98 | void tst_ChartDataSet::init() | |
99 | { |
|
99 | { | |
100 | m_dataset = new ChartDataSet(); |
|
100 | m_dataset = new ChartDataSet(); | |
101 | } |
|
101 | } | |
102 |
|
102 | |||
103 |
|
103 | |||
104 | void tst_ChartDataSet::cleanup() |
|
104 | void tst_ChartDataSet::cleanup() | |
105 | { |
|
105 | { | |
106 | QList<QAbstractSeries*> series = m_dataset->series(); |
|
106 | QList<QAbstractSeries*> series = m_dataset->series(); | |
107 | foreach(QAbstractSeries* serie, series) |
|
107 | foreach(QAbstractSeries* serie, series) | |
108 | { |
|
108 | { | |
109 | m_dataset->removeSeries(serie); |
|
109 | m_dataset->removeSeries(serie); | |
110 | } |
|
110 | } | |
111 | } |
|
111 | } | |
112 |
|
112 | |||
113 | void tst_ChartDataSet::chartdataset_data() |
|
113 | void tst_ChartDataSet::chartdataset_data() | |
114 | { |
|
114 | { | |
115 | } |
|
115 | } | |
116 |
|
116 | |||
117 | void tst_ChartDataSet::chartdataset() |
|
117 | void tst_ChartDataSet::chartdataset() | |
118 | { |
|
118 | { | |
119 | QVERIFY(m_dataset->axisX(0) == 0); |
|
119 | QVERIFY(m_dataset->axisX(0) == 0); | |
120 | QVERIFY(m_dataset->axisY(0) == 0); |
|
120 | QVERIFY(m_dataset->axisY(0) == 0); | |
121 | QLineSeries* series = new QLineSeries(this); |
|
121 | QLineSeries* series = new QLineSeries(this); | |
122 | QCOMPARE(m_dataset->seriesIndex(series),-1); |
|
122 | QCOMPARE(m_dataset->seriesIndex(series),-1); | |
123 | QVERIFY(m_dataset->domain(series) == 0); |
|
123 | QVERIFY(m_dataset->domain(series) == 0); | |
124 | QVERIFY(m_dataset->axisX(series) == 0); |
|
124 | QVERIFY(m_dataset->axisX(series) == 0); | |
125 | QVERIFY(m_dataset->axisY(series) == 0); |
|
125 | QVERIFY(m_dataset->axisY(series) == 0); | |
126 | } |
|
126 | } | |
127 |
|
127 | |||
128 |
|
128 | |||
129 | void tst_ChartDataSet::addSeries_data() |
|
129 | void tst_ChartDataSet::addSeries_data() | |
130 | { |
|
130 | { | |
131 | QTest::addColumn<QAbstractSeries*>("series"); |
|
131 | QTest::addColumn<QAbstractSeries*>("series"); | |
132 |
|
132 | |||
133 | QAbstractSeries* line = new QLineSeries(this); |
|
133 | QAbstractSeries* line = new QLineSeries(this); | |
134 | QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line)); |
|
134 | QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line)); | |
135 | QAbstractSeries* scatter = new QScatterSeries(this); |
|
135 | QAbstractSeries* scatter = new QScatterSeries(this); | |
136 | QAbstractSeries* spline = new QSplineSeries(this); |
|
136 | QAbstractSeries* spline = new QSplineSeries(this); | |
137 | QAbstractSeries* pie = new QPieSeries(this); |
|
137 | QAbstractSeries* pie = new QPieSeries(this); | |
138 | QAbstractSeries* bar = new QBarSeries(this); |
|
138 | QAbstractSeries* bar = new QBarSeries(this); | |
139 | QAbstractSeries* percent = new QPercentBarSeries(this); |
|
139 | QAbstractSeries* percent = new QPercentBarSeries(this); | |
140 | QAbstractSeries* stacked = new QStackedBarSeries(this); |
|
140 | QAbstractSeries* stacked = new QStackedBarSeries(this); | |
141 |
|
141 | |||
142 | QTest::newRow("line") << line; |
|
142 | QTest::newRow("line") << line; | |
143 | QTest::newRow("area") << area; |
|
143 | QTest::newRow("area") << area; | |
144 | QTest::newRow("scatter") << scatter; |
|
144 | QTest::newRow("scatter") << scatter; | |
145 | QTest::newRow("spline") << spline; |
|
145 | QTest::newRow("spline") << spline; | |
146 | QTest::newRow("pie") << pie; |
|
146 | QTest::newRow("pie") << pie; | |
147 | QTest::newRow("bar") << bar; |
|
147 | QTest::newRow("bar") << bar; | |
148 | QTest::newRow("percent") << percent; |
|
148 | QTest::newRow("percent") << percent; | |
149 | QTest::newRow("stacked") << stacked; |
|
149 | QTest::newRow("stacked") << stacked; | |
150 | } |
|
150 | } | |
151 |
|
151 | |||
152 | void tst_ChartDataSet::addSeries() |
|
152 | void tst_ChartDataSet::addSeries() | |
153 | { |
|
153 | { | |
154 |
|
154 | |||
155 | QFETCH(QAbstractSeries*, series); |
|
155 | QFETCH(QAbstractSeries*, series); | |
156 |
|
156 | |||
157 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*, Domain *))); |
|
157 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*, Domain *))); | |
158 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
158 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); | |
159 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); |
|
159 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); | |
160 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
160 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); | |
161 |
|
161 | |||
162 | m_dataset->addSeries(series); |
|
162 | m_dataset->addSeries(series); | |
163 |
|
163 | |||
164 | if(series->type()==QAbstractSeries::SeriesTypePie){ |
|
164 | if(series->type()==QAbstractSeries::SeriesTypePie){ | |
165 | TRY_COMPARE(spy0.count(), 0); |
|
165 | TRY_COMPARE(spy0.count(), 0); | |
166 | }else{ |
|
166 | }else{ | |
167 | TRY_COMPARE(spy0.count(), 2); |
|
167 | TRY_COMPARE(spy0.count(), 2); | |
168 | } |
|
168 | } | |
169 | TRY_COMPARE(spy1.count(), 0); |
|
169 | TRY_COMPARE(spy1.count(), 0); | |
170 | TRY_COMPARE(spy2.count(), 1); |
|
170 | TRY_COMPARE(spy2.count(), 1); | |
171 | TRY_COMPARE(spy3.count(), 0); |
|
171 | TRY_COMPARE(spy3.count(), 0); | |
172 | } |
|
172 | } | |
173 |
|
173 | |||
174 |
|
174 | |||
175 | void tst_ChartDataSet::setAxisX_data() |
|
175 | void tst_ChartDataSet::setAxisX_data() | |
176 | { |
|
176 | { | |
177 |
|
177 | |||
178 |
|
|
178 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); | |
179 |
QTest::addColumn<QList<QAbstractAxis*> > |
|
179 | QTest::addColumn<QList<QAbstractAxis*> >("axisList"); | |
180 |
QTest::addColumn<int |
|
180 | QTest::addColumn<int>("axisCount"); | |
181 |
|
181 | |||
182 | QAbstractSeries* line = new QLineSeries(this); |
|
182 | QAbstractSeries* line = new QLineSeries(this); | |
183 | QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line)); |
|
183 | QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line)); | |
184 | QAbstractSeries* scatter = new QScatterSeries(this); |
|
184 | QAbstractSeries* scatter = new QScatterSeries(this); | |
185 | QAbstractSeries* spline = new QSplineSeries(this); |
|
185 | QAbstractSeries* spline = new QSplineSeries(this); | |
186 | QAbstractSeries* pie = new QPieSeries(this); |
|
186 | QAbstractSeries* pie = new QPieSeries(this); | |
187 | QAbstractSeries* bar = new QBarSeries(this); |
|
187 | QAbstractSeries* bar = new QBarSeries(this); | |
188 | QAbstractSeries* percent = new QPercentBarSeries(this); |
|
188 | QAbstractSeries* percent = new QPercentBarSeries(this); | |
189 | QAbstractSeries* stacked = new QStackedBarSeries(this); |
|
189 | QAbstractSeries* stacked = new QStackedBarSeries(this); | |
190 |
|
190 | |||
191 | QValuesAxis* valueaxis0 = new QValuesAxis(this); |
|
191 | QTest::newRow("line,spline,scatter: axis 0 axis1 axis 2") | |
192 | QValuesAxis* valueaxis1 = new QValuesAxis(this); |
|
192 | << (QList<QAbstractSeries*>() << line << spline << scatter) | |
193 | QValuesAxis* valueaxis2 = new QValuesAxis(this); |
|
193 | << (QList<QAbstractAxis*>() << new QValuesAxis(this) << new QValuesAxis(this) << new QValuesAxis(this)) << 3; | |
194 | QCategoriesAxis* categoriesaxis = new QCategoriesAxis(this); |
|
194 | ||
195 |
|
195 | QTest::newRow("area: axis 0") << (QList<QAbstractSeries*>() << area) | ||
196 | QTest::newRow("line,spline,scatter: axis 0 axis1 axis 2") << ( QList<QAbstractSeries*>() << line << spline << scatter) << ( QList<QAbstractAxis*>() << valueaxis0 << valueaxis1 << valueaxis2) << 3; |
|
196 | << (QList<QAbstractAxis*>() << new QValuesAxis(this)) << 1; | |
197 | QTest::newRow("area: axis 0") << ( QList<QAbstractSeries*>() << area) << ( QList<QAbstractAxis*>() << valueaxis0) << 1; |
|
197 | ||
198 | QTest::newRow("area, spline, scatter: axis 0 axis1 axis 1") << ( QList<QAbstractSeries*>() << area << spline << scatter) << ( QList<QAbstractAxis*>() << valueaxis0 << valueaxis1 << valueaxis1) << 2; |
|
198 | QList<QAbstractAxis*> axes0; | |
|
199 | axes0 << new QValuesAxis(this) << new QValuesAxis(this); | |||
|
200 | axes0 << axes0.last(); | |||
|
201 | QTest::newRow("line,spline,scatter: axis 0 axis1 axis 1") | |||
|
202 | << (QList<QAbstractSeries*>() << line << spline << scatter) | |||
|
203 | << axes0 << 2; | |||
199 |
|
|
204 | //TODO: add more test cases | |
200 | } |
|
205 | } | |
201 |
|
206 | |||
202 | void tst_ChartDataSet::setAxisX() |
|
207 | void tst_ChartDataSet::setAxisX() | |
203 | { |
|
208 | { | |
204 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
209 | QFETCH(QList<QAbstractSeries*>, seriesList); | |
205 | QFETCH(QList<QAbstractAxis*>, axisList); |
|
210 | QFETCH(QList<QAbstractAxis*>, axisList); | |
206 | QFETCH(int, axisCount); |
|
211 | QFETCH(int, axisCount); | |
207 |
|
212 | |||
208 | Q_ASSERT(seriesList.count() == axisList.count()); |
|
213 | Q_ASSERT(seriesList.count() == axisList.count()); | |
209 |
|
214 | |||
210 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *,Domain*))); |
|
215 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *,Domain*))); | |
211 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *))); |
|
216 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *))); | |
212 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*))); |
|
217 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*))); | |
213 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
218 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); | |
214 |
|
219 | |||
215 | foreach(QAbstractSeries* series, seriesList){ |
|
220 | foreach(QAbstractSeries* series, seriesList){ | |
216 | m_dataset->addSeries(series); |
|
221 | m_dataset->addSeries(series); | |
217 | } |
|
222 | } | |
218 |
|
223 | |||
219 | TRY_COMPARE(spy0.count(), seriesList.count()*2); |
|
224 | TRY_COMPARE(spy0.count(), seriesList.count()*2); | |
220 | TRY_COMPARE(spy1.count(), 0); |
|
225 | TRY_COMPARE(spy1.count(), 0); | |
221 | TRY_COMPARE(spy2.count(), seriesList.count()); |
|
226 | TRY_COMPARE(spy2.count(), seriesList.count()); | |
222 | TRY_COMPARE(spy3.count(), 0); |
|
227 | TRY_COMPARE(spy3.count(), 0); | |
223 |
|
228 | |||
224 | QSignalSpy spy4(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*))); |
|
229 | QSignalSpy spy4(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*))); | |
225 | QSignalSpy spy5(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
230 | QSignalSpy spy5(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); | |
226 | QSignalSpy spy6(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*))); |
|
231 | QSignalSpy spy6(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*))); | |
227 | QSignalSpy spy7(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
232 | QSignalSpy spy7(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); | |
228 |
|
233 | |||
229 | for(int i=0 ; i < seriesList.count(); i++){ |
|
234 | for(int i=0 ; i < seriesList.count(); i++){ | |
230 | m_dataset->setAxisX(seriesList.at(i),axisList.at(i)); |
|
235 | m_dataset->setAxisX(seriesList.at(i),axisList.at(i)); | |
231 | } |
|
236 | } | |
232 |
|
237 | |||
233 | TRY_COMPARE(spy4.count(), axisCount); |
|
238 | TRY_COMPARE(spy4.count(), axisCount); | |
234 | TRY_COMPARE(spy5.count(), seriesList.count()); |
|
239 | TRY_COMPARE(spy5.count(), seriesList.count()); | |
235 | TRY_COMPARE(spy6.count(), 0); |
|
240 | TRY_COMPARE(spy6.count(), 0); | |
236 | TRY_COMPARE(spy7.count(), 0); |
|
241 | TRY_COMPARE(spy7.count(), 0); | |
237 |
|
242 | |||
238 | for(int i=0 ; i < seriesList.count(); i++){ |
|
243 | for(int i=0 ; i < seriesList.count(); i++){ | |
239 | QVERIFY(m_dataset->axisX(seriesList.at(i)) == axisList.at(i)); |
|
244 | QVERIFY(m_dataset->axisX(seriesList.at(i)) == axisList.at(i)); | |
240 | } |
|
245 | } | |
241 | } |
|
246 | } | |
242 |
|
247 | |||
243 | void tst_ChartDataSet::setAxisY_data() |
|
248 | void tst_ChartDataSet::setAxisY_data() | |
244 | { |
|
249 | { | |
245 | setAxisX_data(); |
|
250 | setAxisX_data(); | |
246 | } |
|
251 | } | |
247 |
|
252 | |||
248 | void tst_ChartDataSet::setAxisY() |
|
253 | void tst_ChartDataSet::setAxisY() | |
249 | { |
|
254 | { | |
250 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
255 | QFETCH(QList<QAbstractSeries*>, seriesList); | |
251 | QFETCH(QList<QAbstractAxis*>, axisList); |
|
256 | QFETCH(QList<QAbstractAxis*>, axisList); | |
252 | QFETCH(int, axisCount); |
|
257 | QFETCH(int, axisCount); | |
253 |
|
258 | |||
254 | Q_ASSERT(seriesList.count() == axisList.count()); |
|
259 | Q_ASSERT(seriesList.count() == axisList.count()); | |
255 |
|
260 | |||
256 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*))); |
|
261 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*))); | |
257 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
262 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); | |
258 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*))); |
|
263 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*))); | |
259 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
264 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); | |
260 |
|
265 | |||
261 | foreach(QAbstractSeries* series, seriesList){ |
|
266 | foreach(QAbstractSeries* series, seriesList){ | |
262 | m_dataset->addSeries(series); |
|
267 | m_dataset->addSeries(series); | |
263 | } |
|
268 | } | |
264 |
|
269 | |||
265 | TRY_COMPARE(spy0.count(), seriesList.count()*2); |
|
270 | TRY_COMPARE(spy0.count(), seriesList.count()*2); | |
266 | TRY_COMPARE(spy1.count(), 0); |
|
271 | TRY_COMPARE(spy1.count(), 0); | |
267 | TRY_COMPARE(spy2.count(), seriesList.count()); |
|
272 | TRY_COMPARE(spy2.count(), seriesList.count()); | |
268 | TRY_COMPARE(spy3.count(), 0); |
|
273 | TRY_COMPARE(spy3.count(), 0); | |
269 |
|
274 | |||
270 | QSignalSpy spy4(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*))); |
|
275 | QSignalSpy spy4(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*))); | |
271 | QSignalSpy spy5(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
276 | QSignalSpy spy5(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); | |
272 | QSignalSpy spy6(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*))); |
|
277 | QSignalSpy spy6(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*))); | |
273 | QSignalSpy spy7(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
278 | QSignalSpy spy7(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); | |
274 |
|
279 | |||
275 | for(int i=0 ; i < seriesList.count(); i++){ |
|
280 | for(int i=0 ; i < seriesList.count(); i++){ | |
276 | m_dataset->setAxisY(seriesList.at(i),axisList.at(i)); |
|
281 | m_dataset->setAxisY(seriesList.at(i),axisList.at(i)); | |
277 | } |
|
282 | } | |
278 |
|
283 | |||
279 | TRY_COMPARE(spy4.count(), axisCount); |
|
284 | TRY_COMPARE(spy4.count(), axisCount); | |
280 | TRY_COMPARE(spy5.count(), seriesList.count()); |
|
285 | TRY_COMPARE(spy5.count(), seriesList.count()); | |
281 | TRY_COMPARE(spy6.count(), 0); |
|
286 | TRY_COMPARE(spy6.count(), 0); | |
282 | TRY_COMPARE(spy7.count(), 0); |
|
287 | TRY_COMPARE(spy7.count(), 0); | |
283 |
|
288 | |||
284 | for(int i=0 ; i < seriesList.count(); i++){ |
|
289 | for(int i=0 ; i < seriesList.count(); i++){ | |
285 | QVERIFY(m_dataset->axisY(seriesList.at(i)) == axisList.at(i)); |
|
290 | QVERIFY(m_dataset->axisY(seriesList.at(i)) == axisList.at(i)); | |
286 | } |
|
291 | } | |
287 | } |
|
292 | } | |
288 |
|
293 | |||
289 | void tst_ChartDataSet::removeSeries_data() |
|
294 | void tst_ChartDataSet::removeSeries_data() | |
290 | { |
|
295 | { | |
291 | addSeries_data(); |
|
296 | addSeries_data(); | |
292 | } |
|
297 | } | |
293 |
|
298 | |||
294 | void tst_ChartDataSet::removeSeries() |
|
299 | void tst_ChartDataSet::removeSeries() | |
295 | { |
|
300 | { | |
296 | QFETCH(QAbstractSeries*, series); |
|
301 | QFETCH(QAbstractSeries*, series); | |
297 |
|
302 | |||
298 | m_dataset->addSeries(series); |
|
303 | m_dataset->addSeries(series); | |
299 |
|
304 | |||
300 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*, Domain *))); |
|
305 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*, Domain *))); | |
301 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
306 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); | |
302 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); |
|
307 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); | |
303 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
308 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); | |
304 |
|
309 | |||
305 | m_dataset->removeSeries(series); |
|
310 | m_dataset->removeSeries(series); | |
306 |
|
311 | |||
307 | TRY_COMPARE(spy0.count(), 0); |
|
312 | TRY_COMPARE(spy0.count(), 0); | |
308 | if (series->type() == QAbstractSeries::SeriesTypePie) { |
|
313 | if (series->type() == QAbstractSeries::SeriesTypePie) { | |
309 | TRY_COMPARE(spy1.count(), 0); |
|
314 | TRY_COMPARE(spy1.count(), 0); | |
310 | } |
|
315 | } | |
311 | else { |
|
316 | else { | |
312 | TRY_COMPARE(spy1.count(), 2); |
|
317 | TRY_COMPARE(spy1.count(), 2); | |
313 | } |
|
318 | } | |
314 | TRY_COMPARE(spy2.count(), 0); |
|
319 | TRY_COMPARE(spy2.count(), 0); | |
315 | TRY_COMPARE(spy3.count(), 1); |
|
320 | TRY_COMPARE(spy3.count(), 1); | |
316 | } |
|
321 | } | |
317 |
|
322 | |||
318 | void tst_ChartDataSet::removeAllSeries_data() |
|
323 | void tst_ChartDataSet::removeAllSeries_data() | |
319 | { |
|
324 | { | |
320 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); |
|
325 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); | |
321 | QTest::addColumn<QList<QAbstractAxis*> >("axisList"); |
|
326 | QTest::addColumn<QList<QAbstractAxis*> >("axisList"); | |
322 | QTest::addColumn<int>("axisCount"); |
|
327 | QTest::addColumn<int>("axisCount"); | |
323 |
|
328 | |||
324 | QAbstractSeries* line = new QLineSeries(this); |
|
|||
325 | QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line)); |
|
|||
326 | QAbstractSeries* scatter = new QScatterSeries(this); |
|
|||
327 | QAbstractSeries* spline = new QSplineSeries(this); |
|
|||
328 | QAbstractSeries* pie = new QPieSeries(this); |
|
|||
329 | QAbstractSeries* bar = new QBarSeries(this); |
|
|||
330 | QAbstractSeries* percent = new QPercentBarSeries(this); |
|
|||
331 | QAbstractSeries* stacked = new QStackedBarSeries(this); |
|
|||
332 |
|
||||
333 | QValuesAxis* valueaxis0 = new QValuesAxis(this); |
|
|||
334 | QValuesAxis* valueaxis1 = new QValuesAxis(this); |
|
|||
335 | QValuesAxis* valueaxis2 = new QValuesAxis(this); |
|
|||
336 |
|
||||
337 | QTest::newRow("line,spline,scatter: axis 0 axis1 axis 2") |
|
329 | QTest::newRow("line,spline,scatter: axis 0 axis1 axis 2") | |
338 |
<< (QList<QAbstractSeries*>() << |
|
330 | << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QSplineSeries(this) | |
339 | << (QList<QAbstractAxis*>() << valueaxis0 << valueaxis1 << valueaxis2) << 3; |
|
331 | << new QScatterSeries(this)) | |
|
332 | << (QList<QAbstractAxis*>() << new QValuesAxis(this) << new QValuesAxis(this) | |||
|
333 | << new QValuesAxis(this)) << 3; | |||
340 | //TODO: |
|
334 | //TODO: | |
341 |
|
||||
342 | } |
|
335 | } | |
343 |
|
336 | |||
344 | void tst_ChartDataSet::removeAllSeries() |
|
337 | void tst_ChartDataSet::removeAllSeries() | |
345 | { |
|
338 | { | |
346 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
339 | QFETCH(QList<QAbstractSeries*>, seriesList); | |
347 | QFETCH(QList<QAbstractAxis*>, axisList); |
|
340 | QFETCH(QList<QAbstractAxis*>, axisList); | |
348 | QFETCH(int, axisCount); |
|
341 | QFETCH(int, axisCount); | |
349 |
|
342 | |||
350 | foreach(QAbstractSeries* series, seriesList) { |
|
343 | foreach(QAbstractSeries* series, seriesList) { | |
351 | m_dataset->addSeries(series); |
|
344 | m_dataset->addSeries(series); | |
352 | } |
|
345 | } | |
353 |
|
346 | |||
354 | for (int i = 0; i < seriesList.count(); i++) { |
|
347 | for (int i = 0; i < seriesList.count(); i++) { | |
355 | m_dataset->setAxisX(seriesList.at(i), axisList.at(i)); |
|
348 | m_dataset->setAxisX(seriesList.at(i), axisList.at(i)); | |
356 | } |
|
349 | } | |
357 |
|
350 | |||
358 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *))); |
|
351 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *))); | |
359 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *))); |
|
352 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *))); | |
360 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); |
|
353 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); | |
361 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
354 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); | |
362 |
|
355 | |||
363 | m_dataset->removeAllSeries(); |
|
356 | m_dataset->removeAllSeries(); | |
364 |
|
357 | |||
365 | TRY_COMPARE(spy0.count(), 0); |
|
358 | TRY_COMPARE(spy0.count(), 0); | |
366 | TRY_COMPARE(spy1.count(), axisCount + seriesList.count()); |
|
359 | TRY_COMPARE(spy1.count(), axisCount + seriesList.count()); | |
367 | TRY_COMPARE(spy2.count(), 0); |
|
360 | TRY_COMPARE(spy2.count(), 0); | |
368 | TRY_COMPARE(spy3.count(), seriesList.count()); |
|
361 | TRY_COMPARE(spy3.count(), seriesList.count()); | |
369 | } |
|
362 | } | |
370 |
|
363 | |||
371 |
|
364 | |||
372 | void tst_ChartDataSet::seriesCount_data() |
|
365 | void tst_ChartDataSet::seriesCount_data() | |
373 | { |
|
366 | { | |
374 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); |
|
367 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); | |
375 | QTest::addColumn<int>("seriesCount"); |
|
368 | QTest::addColumn<int>("seriesCount"); | |
376 |
|
369 | |||
377 | QTest::newRow("line,line, line, spline 3") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ) << 3; |
|
370 | QTest::newRow("line,line, line, spline 3") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ) << 3; | |
378 | QTest::newRow("scatter,scatter, line, line 2") << (QList<QAbstractSeries*>() << new QScatterSeries(this) << new QScatterSeries(this) << new QLineSeries(this) << new QLineSeries(this) ) << 2; |
|
371 | QTest::newRow("scatter,scatter, line, line 2") << (QList<QAbstractSeries*>() << new QScatterSeries(this) << new QScatterSeries(this) << new QLineSeries(this) << new QLineSeries(this) ) << 2; | |
379 | } |
|
372 | } | |
380 |
|
373 | |||
381 | void tst_ChartDataSet::seriesCount() |
|
374 | void tst_ChartDataSet::seriesCount() | |
382 | { |
|
375 | { | |
383 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
376 | QFETCH(QList<QAbstractSeries*>, seriesList); | |
384 | QFETCH(int, seriesCount); |
|
377 | QFETCH(int, seriesCount); | |
385 |
|
378 | |||
386 | foreach(QAbstractSeries* series, seriesList){ |
|
379 | foreach(QAbstractSeries* series, seriesList){ | |
387 | m_dataset->addSeries(series); |
|
380 | m_dataset->addSeries(series); | |
388 | } |
|
381 | } | |
389 |
|
382 | |||
390 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *))); |
|
383 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *))); | |
391 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *))); |
|
384 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *))); | |
392 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); |
|
385 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); | |
393 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
386 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); | |
394 |
|
387 | |||
395 | QCOMPARE(m_dataset->seriesCount(seriesList.at(0)->type()),seriesCount); |
|
388 | QCOMPARE(m_dataset->seriesCount(seriesList.at(0)->type()),seriesCount); | |
396 | TRY_COMPARE(spy0.count(), 0); |
|
389 | TRY_COMPARE(spy0.count(), 0); | |
397 | TRY_COMPARE(spy1.count(), 0); |
|
390 | TRY_COMPARE(spy1.count(), 0); | |
398 | TRY_COMPARE(spy2.count(), 0); |
|
391 | TRY_COMPARE(spy2.count(), 0); | |
399 | TRY_COMPARE(spy3.count(), 0); |
|
392 | TRY_COMPARE(spy3.count(), 0); | |
400 | } |
|
393 | } | |
401 |
|
394 | |||
402 | void tst_ChartDataSet::seriesIndex_data() |
|
395 | void tst_ChartDataSet::seriesIndex_data() | |
403 | { |
|
396 | { | |
404 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); |
|
397 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); | |
405 |
|
398 | |||
406 | QTest::newRow("line,line, line, spline") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ); |
|
399 | QTest::newRow("line,line, line, spline") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ); | |
407 | QTest::newRow("scatter,scatter, line, line") << (QList<QAbstractSeries*>() << new QScatterSeries(this) << new QScatterSeries(this) << new QLineSeries(this) << new QLineSeries(this) ); |
|
400 | QTest::newRow("scatter,scatter, line, line") << (QList<QAbstractSeries*>() << new QScatterSeries(this) << new QScatterSeries(this) << new QLineSeries(this) << new QLineSeries(this) ); | |
408 | } |
|
401 | } | |
409 |
|
402 | |||
410 | void tst_ChartDataSet::seriesIndex() |
|
403 | void tst_ChartDataSet::seriesIndex() | |
411 | { |
|
404 | { | |
412 |
|
405 | |||
413 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
406 | QFETCH(QList<QAbstractSeries*>, seriesList); | |
414 |
|
407 | |||
415 | foreach(QAbstractSeries* series, seriesList) { |
|
408 | foreach(QAbstractSeries* series, seriesList) { | |
416 | m_dataset->addSeries(series); |
|
409 | m_dataset->addSeries(series); | |
417 | } |
|
410 | } | |
418 |
|
411 | |||
419 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *,Domain*))); |
|
412 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *,Domain*))); | |
420 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *))); |
|
413 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *))); | |
421 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*))); |
|
414 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*))); | |
422 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
415 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); | |
423 |
|
416 | |||
424 | for (int i = 0; i < seriesList.count(); i++) { |
|
417 | for (int i = 0; i < seriesList.count(); i++) { | |
425 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
418 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); | |
426 | } |
|
419 | } | |
427 |
|
420 | |||
428 | TRY_COMPARE(spy0.count(), 0); |
|
421 | TRY_COMPARE(spy0.count(), 0); | |
429 | TRY_COMPARE(spy1.count(), 0); |
|
422 | TRY_COMPARE(spy1.count(), 0); | |
430 | TRY_COMPARE(spy2.count(), 0); |
|
423 | TRY_COMPARE(spy2.count(), 0); | |
431 | TRY_COMPARE(spy3.count(), 0); |
|
424 | TRY_COMPARE(spy3.count(), 0); | |
432 |
|
425 | |||
433 | foreach(QAbstractSeries* series, seriesList) { |
|
426 | foreach(QAbstractSeries* series, seriesList) { | |
434 | m_dataset->removeSeries(series); |
|
427 | m_dataset->removeSeries(series); | |
435 | } |
|
428 | } | |
436 |
|
429 | |||
437 | for (int i = 0; i < seriesList.count(); i++) { |
|
430 | for (int i = 0; i < seriesList.count(); i++) { | |
438 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1); |
|
431 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1); | |
439 | } |
|
432 | } | |
440 |
|
433 | |||
441 | foreach(QAbstractSeries* series, seriesList) { |
|
434 | foreach(QAbstractSeries* series, seriesList) { | |
442 | m_dataset->addSeries(series); |
|
435 | m_dataset->addSeries(series); | |
443 | } |
|
436 | } | |
444 |
|
437 | |||
445 | for (int i = 0; i < seriesList.count(); i++) { |
|
438 | for (int i = 0; i < seriesList.count(); i++) { | |
446 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
439 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); | |
447 | } |
|
440 | } | |
448 |
|
441 | |||
449 | m_dataset->removeSeries(seriesList.at(1)); |
|
442 | m_dataset->removeSeries(seriesList.at(1)); | |
450 |
|
443 | |||
451 | for (int i = 0; i < seriesList.count(); i++) { |
|
444 | for (int i = 0; i < seriesList.count(); i++) { | |
452 | if (i != 1) |
|
445 | if (i != 1) | |
453 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
446 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); | |
454 | else |
|
447 | else | |
455 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1); |
|
448 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1); | |
456 | } |
|
449 | } | |
457 |
|
450 | |||
458 | m_dataset->addSeries(seriesList.at(1)); |
|
451 | m_dataset->addSeries(seriesList.at(1)); | |
459 |
|
452 | |||
460 | for (int i = 0; i < seriesList.count(); i++) { |
|
453 | for (int i = 0; i < seriesList.count(); i++) { | |
461 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
454 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); | |
462 | } |
|
455 | } | |
463 |
|
456 | |||
464 | m_dataset->removeSeries(seriesList.at(2)); |
|
457 | m_dataset->removeSeries(seriesList.at(2)); | |
465 |
|
458 | |||
466 | for (int i = 0; i < seriesList.count(); i++) { |
|
459 | for (int i = 0; i < seriesList.count(); i++) { | |
467 | if (i != 2) |
|
460 | if (i != 2) | |
468 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
461 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); | |
469 | else |
|
462 | else | |
470 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1); |
|
463 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1); | |
471 | } |
|
464 | } | |
472 |
|
465 | |||
473 | m_dataset->removeSeries(seriesList.at(0)); |
|
466 | m_dataset->removeSeries(seriesList.at(0)); | |
474 |
|
467 | |||
475 | for (int i = 0; i < seriesList.count(); i++) { |
|
468 | for (int i = 0; i < seriesList.count(); i++) { | |
476 | if (i != 2 && i != 0) |
|
469 | if (i != 2 && i != 0) | |
477 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
470 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); | |
478 | else |
|
471 | else | |
479 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1); |
|
472 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1); | |
480 | } |
|
473 | } | |
481 |
|
474 | |||
482 | m_dataset->addSeries(seriesList.at(2)); |
|
475 | m_dataset->addSeries(seriesList.at(2)); | |
483 | m_dataset->addSeries(seriesList.at(0)); |
|
476 | m_dataset->addSeries(seriesList.at(0)); | |
484 |
|
477 | |||
485 | for (int i = 0; i < seriesList.count(); i++) { |
|
478 | for (int i = 0; i < seriesList.count(); i++) { | |
486 | if (i == 2) |
|
479 | if (i == 2) | |
487 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), 0); |
|
480 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), 0); | |
488 | else if (i == 0) |
|
481 | else if (i == 0) | |
489 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), 2); |
|
482 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), 2); | |
490 | else |
|
483 | else | |
491 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
484 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); | |
492 | } |
|
485 | } | |
493 |
|
486 | |||
494 | } |
|
487 | } | |
495 | /* |
|
488 | /* | |
496 | void tst_ChartDataSet::domain_data() |
|
489 | void tst_ChartDataSet::domain_data() | |
497 | { |
|
490 | { | |
498 | addSeries_data(); |
|
491 | addSeries_data(); | |
499 | } |
|
492 | } | |
500 |
|
493 | |||
501 | void tst_ChartDataSet::domain() |
|
494 | void tst_ChartDataSet::domain() | |
502 | { |
|
495 | { | |
503 | QFETCH(QLineSeries*, series0); |
|
496 | QFETCH(QLineSeries*, series0); | |
504 | QFETCH(QAxis*, axis0); |
|
497 | QFETCH(QAxis*, axis0); | |
505 | QFETCH(QLineSeries*, series1); |
|
498 | QFETCH(QLineSeries*, series1); | |
506 | QFETCH(QAxis*, axis1); |
|
499 | QFETCH(QAxis*, axis1); | |
507 | QFETCH(QLineSeries*, series2); |
|
500 | QFETCH(QLineSeries*, series2); | |
508 | QFETCH(QAxis*, axis2); |
|
501 | QFETCH(QAxis*, axis2); | |
509 | QFETCH(int, axisCount); |
|
502 | QFETCH(int, axisCount); | |
510 | Q_UNUSED(axisCount); |
|
503 | Q_UNUSED(axisCount); | |
511 |
|
504 | |||
512 | m_dataset->addSeries(series0, axis0); |
|
505 | m_dataset->addSeries(series0, axis0); | |
513 | m_dataset->addSeries(series1, axis1); |
|
506 | m_dataset->addSeries(series1, axis1); | |
514 | m_dataset->addSeries(series2, axis2); |
|
507 | m_dataset->addSeries(series2, axis2); | |
515 |
|
508 | |||
516 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAxis *, Domain *))); |
|
509 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAxis *, Domain *))); | |
517 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAxis *))); |
|
510 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAxis *))); | |
518 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); |
|
511 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); | |
519 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
512 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); | |
520 |
|
513 | |||
521 | QVERIFY(m_dataset->domain(axis0)==m_dataset->domain(series0)); |
|
514 | QVERIFY(m_dataset->domain(axis0)==m_dataset->domain(series0)); | |
522 | QVERIFY(m_dataset->domain(axis1)==m_dataset->domain(series1)); |
|
515 | QVERIFY(m_dataset->domain(axis1)==m_dataset->domain(series1)); | |
523 | QVERIFY(m_dataset->domain(axis2)==m_dataset->domain(series2)); |
|
516 | QVERIFY(m_dataset->domain(axis2)==m_dataset->domain(series2)); | |
524 | TRY_COMPARE(spy0.count(), 0); |
|
517 | TRY_COMPARE(spy0.count(), 0); | |
525 | TRY_COMPARE(spy1.count(), 0); |
|
518 | TRY_COMPARE(spy1.count(), 0); | |
526 | TRY_COMPARE(spy2.count(), 0); |
|
519 | TRY_COMPARE(spy2.count(), 0); | |
527 | TRY_COMPARE(spy3.count(), 0); |
|
520 | TRY_COMPARE(spy3.count(), 0); | |
528 | } |
|
521 | } | |
529 |
|
522 | |||
530 | void tst_ChartDataSet::zoomInDomain_data() |
|
523 | void tst_ChartDataSet::zoomInDomain_data() | |
531 | { |
|
524 | { | |
532 | addSeries_data(); |
|
525 | addSeries_data(); | |
533 | } |
|
526 | } | |
534 |
|
527 | |||
535 | void tst_ChartDataSet::zoomInDomain() |
|
528 | void tst_ChartDataSet::zoomInDomain() | |
536 | { |
|
529 | { | |
537 | QFETCH(QLineSeries*, series0); |
|
530 | QFETCH(QLineSeries*, series0); | |
538 | QFETCH(QAxis*, axis0); |
|
531 | QFETCH(QAxis*, axis0); | |
539 | QFETCH(QLineSeries*, series1); |
|
532 | QFETCH(QLineSeries*, series1); | |
540 | QFETCH(QAxis*, axis1); |
|
533 | QFETCH(QAxis*, axis1); | |
541 | QFETCH(QLineSeries*, series2); |
|
534 | QFETCH(QLineSeries*, series2); | |
542 | QFETCH(QAxis*, axis2); |
|
535 | QFETCH(QAxis*, axis2); | |
543 | QFETCH(int, axisCount); |
|
536 | QFETCH(int, axisCount); | |
544 | Q_UNUSED(axisCount); |
|
537 | Q_UNUSED(axisCount); | |
545 |
|
538 | |||
546 | m_dataset->addSeries(series0, axis0); |
|
539 | m_dataset->addSeries(series0, axis0); | |
547 | m_dataset->addSeries(series1, axis1); |
|
540 | m_dataset->addSeries(series1, axis1); | |
548 | m_dataset->addSeries(series2, axis2); |
|
541 | m_dataset->addSeries(series2, axis2); | |
549 |
|
542 | |||
550 | Domain* domain0 = m_dataset->domain(series0); |
|
543 | Domain* domain0 = m_dataset->domain(series0); | |
551 | Domain* domain1 = m_dataset->domain(series1); |
|
544 | Domain* domain1 = m_dataset->domain(series1); | |
552 | Domain* domain2 = m_dataset->domain(series2); |
|
545 | Domain* domain2 = m_dataset->domain(series2); | |
553 |
|
546 | |||
554 | QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
547 | QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
555 | QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
548 | QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
556 | QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
549 | QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
557 |
|
550 | |||
558 | m_dataset->zoomInDomain(QRect(0,0,100,100),QSize(1000,1000)); |
|
551 | m_dataset->zoomInDomain(QRect(0,0,100,100),QSize(1000,1000)); | |
559 |
|
552 | |||
560 | TRY_COMPARE(spy0.count(), 1); |
|
553 | TRY_COMPARE(spy0.count(), 1); | |
561 | TRY_COMPARE(spy1.count(), 1); |
|
554 | TRY_COMPARE(spy1.count(), 1); | |
562 | TRY_COMPARE(spy2.count(), 1); |
|
555 | TRY_COMPARE(spy2.count(), 1); | |
563 | } |
|
556 | } | |
564 |
|
557 | |||
565 | void tst_ChartDataSet::zoomOutDomain_data() |
|
558 | void tst_ChartDataSet::zoomOutDomain_data() | |
566 | { |
|
559 | { | |
567 | addSeries_data(); |
|
560 | addSeries_data(); | |
568 | } |
|
561 | } | |
569 |
|
562 | |||
570 | void tst_ChartDataSet::zoomOutDomain() |
|
563 | void tst_ChartDataSet::zoomOutDomain() | |
571 | { |
|
564 | { | |
572 | QFETCH(QLineSeries*, series0); |
|
565 | QFETCH(QLineSeries*, series0); | |
573 | QFETCH(QAxis*, axis0); |
|
566 | QFETCH(QAxis*, axis0); | |
574 | QFETCH(QLineSeries*, series1); |
|
567 | QFETCH(QLineSeries*, series1); | |
575 | QFETCH(QAxis*, axis1); |
|
568 | QFETCH(QAxis*, axis1); | |
576 | QFETCH(QLineSeries*, series2); |
|
569 | QFETCH(QLineSeries*, series2); | |
577 | QFETCH(QAxis*, axis2); |
|
570 | QFETCH(QAxis*, axis2); | |
578 | QFETCH(int, axisCount); |
|
571 | QFETCH(int, axisCount); | |
579 |
|
572 | |||
580 | Q_UNUSED(axisCount); |
|
573 | Q_UNUSED(axisCount); | |
581 |
|
574 | |||
582 | m_dataset->addSeries(series0, axis0); |
|
575 | m_dataset->addSeries(series0, axis0); | |
583 | m_dataset->addSeries(series1, axis1); |
|
576 | m_dataset->addSeries(series1, axis1); | |
584 | m_dataset->addSeries(series2, axis2); |
|
577 | m_dataset->addSeries(series2, axis2); | |
585 |
|
578 | |||
586 | Domain* domain0 = m_dataset->domain(series0); |
|
579 | Domain* domain0 = m_dataset->domain(series0); | |
587 | Domain* domain1 = m_dataset->domain(series1); |
|
580 | Domain* domain1 = m_dataset->domain(series1); | |
588 | Domain* domain2 = m_dataset->domain(series2); |
|
581 | Domain* domain2 = m_dataset->domain(series2); | |
589 |
|
582 | |||
590 | QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
583 | QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
591 | QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
584 | QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
592 | QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
585 | QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
593 |
|
586 | |||
594 | m_dataset->zoomOutDomain(QRect(0,0,100,100),QSize(1000,1000)); |
|
587 | m_dataset->zoomOutDomain(QRect(0,0,100,100),QSize(1000,1000)); | |
595 |
|
588 | |||
596 | TRY_COMPARE(spy0.count(), 1); |
|
589 | TRY_COMPARE(spy0.count(), 1); | |
597 | TRY_COMPARE(spy1.count(), 1); |
|
590 | TRY_COMPARE(spy1.count(), 1); | |
598 | TRY_COMPARE(spy2.count(), 1); |
|
591 | TRY_COMPARE(spy2.count(), 1); | |
599 | } |
|
592 | } | |
600 |
|
593 | |||
601 | void tst_ChartDataSet::scrollDomain_data() |
|
594 | void tst_ChartDataSet::scrollDomain_data() | |
602 | { |
|
595 | { | |
603 | addSeries_data(); |
|
596 | addSeries_data(); | |
604 | } |
|
597 | } | |
605 |
|
598 | |||
606 | void tst_ChartDataSet::scrollDomain() |
|
599 | void tst_ChartDataSet::scrollDomain() | |
607 | { |
|
600 | { | |
608 | QFETCH(QLineSeries*, series0); |
|
601 | QFETCH(QLineSeries*, series0); | |
609 | QFETCH(QAxis*, axis0); |
|
602 | QFETCH(QAxis*, axis0); | |
610 | QFETCH(QLineSeries*, series1); |
|
603 | QFETCH(QLineSeries*, series1); | |
611 | QFETCH(QAxis*, axis1); |
|
604 | QFETCH(QAxis*, axis1); | |
612 | QFETCH(QLineSeries*, series2); |
|
605 | QFETCH(QLineSeries*, series2); | |
613 | QFETCH(QAxis*, axis2); |
|
606 | QFETCH(QAxis*, axis2); | |
614 | QFETCH(int, axisCount); |
|
607 | QFETCH(int, axisCount); | |
615 |
|
608 | |||
616 | Q_UNUSED(axisCount); |
|
609 | Q_UNUSED(axisCount); | |
617 |
|
610 | |||
618 | m_dataset->addSeries(series0, axis0); |
|
611 | m_dataset->addSeries(series0, axis0); | |
619 | m_dataset->addSeries(series1, axis1); |
|
612 | m_dataset->addSeries(series1, axis1); | |
620 | m_dataset->addSeries(series2, axis2); |
|
613 | m_dataset->addSeries(series2, axis2); | |
621 |
|
614 | |||
622 | Domain* domain0 = m_dataset->domain(series0); |
|
615 | Domain* domain0 = m_dataset->domain(series0); | |
623 | Domain* domain1 = m_dataset->domain(series1); |
|
616 | Domain* domain1 = m_dataset->domain(series1); | |
624 | Domain* domain2 = m_dataset->domain(series2); |
|
617 | Domain* domain2 = m_dataset->domain(series2); | |
625 |
|
618 | |||
626 | QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
619 | QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
627 | QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
620 | QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
628 | QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
621 | QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
629 |
|
622 | |||
630 | m_dataset->scrollDomain(10,10,QSize(1000,1000)); |
|
623 | m_dataset->scrollDomain(10,10,QSize(1000,1000)); | |
631 |
|
624 | |||
632 | TRY_COMPARE(spy0.count(), 1); |
|
625 | TRY_COMPARE(spy0.count(), 1); | |
633 | TRY_COMPARE(spy1.count(), 1); |
|
626 | TRY_COMPARE(spy1.count(), 1); | |
634 | TRY_COMPARE(spy2.count(), 1); |
|
627 | TRY_COMPARE(spy2.count(), 1); | |
635 | } |
|
628 | } | |
636 | */ |
|
629 | */ | |
637 | QTEST_MAIN(tst_ChartDataSet) |
|
630 | QTEST_MAIN(tst_ChartDataSet) | |
638 | #include "tst_chartdataset.moc" |
|
631 | #include "tst_chartdataset.moc" | |
639 |
|
632 |
General Comments 0
You need to be logged in to leave comments.
Login now