##// END OF EJS Templates
tst_qpieseries: added XXXanimated tests...
Jani Honkonen -
r1301:87c96c12fb23
parent child
Show More
@@ -164,8 +164,13 void PieChartItem::handleSlicesRemoved(QList<QPieSlice*> slices)
164 presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series));
164 presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series));
165
165
166 foreach (QPieSlice *slice, slices) {
166 foreach (QPieSlice *slice, slices) {
167
167 PieSliceItem *sliceItem = m_sliceItems.value(slice);
168 PieSliceItem *sliceItem = m_sliceItems.value(slice);
168 Q_ASSERT(sliceItem);
169
170 // this can happen if you call append() & remove() in a row so that PieSliceItem is not even created
171 if (!sliceItem)
172 continue;
173
169 m_sliceItems.remove(slice);
174 m_sliceItems.remove(slice);
170
175
171 if (animator())
176 if (animator())
@@ -45,8 +45,11 public slots:
45 private slots:
45 private slots:
46 void properties();
46 void properties();
47 void append();
47 void append();
48 void appendAnimated();
48 void insert();
49 void insert();
50 void insertAnimated();
49 void remove();
51 void remove();
52 void removeAnimated();
50 void calculatedValues();
53 void calculatedValues();
51 void clickedSignal();
54 void clickedSignal();
52 void hoverSignal();
55 void hoverSignal();
@@ -55,7 +58,8 private:
55 void verifyCalculatedData(const QPieSeries &series, bool *ok);
58 void verifyCalculatedData(const QPieSeries &series, bool *ok);
56
59
57 private:
60 private:
58
61 QChartView *m_view;
62 QPieSeries *m_series;
59 };
63 };
60
64
61 void tst_qpieseries::initTestCase()
65 void tst_qpieseries::initTestCase()
@@ -70,96 +74,97 void tst_qpieseries::cleanupTestCase()
70
74
71 void tst_qpieseries::init()
75 void tst_qpieseries::init()
72 {
76 {
73
77 m_view = new QChartView();
78 m_series = new QPieSeries(m_view);
74 }
79 }
75
80
76 void tst_qpieseries::cleanup()
81 void tst_qpieseries::cleanup()
77 {
82 {
78
83 delete m_view;
84 m_view = 0;
85 m_series = 0;
79 }
86 }
80
87
81 void tst_qpieseries::properties()
88 void tst_qpieseries::properties()
82 {
89 {
83 QPieSeries s;
90 QSignalSpy countSpy(m_series, SIGNAL(countChanged()));
84
91 QSignalSpy sumSpy(m_series, SIGNAL(sumChanged()));
85 QSignalSpy countSpy(&s, SIGNAL(countChanged()));
92 QSignalSpy sizeSpy(m_series, SIGNAL(pieSizeChanged()));
86 QSignalSpy sumSpy(&s, SIGNAL(sumChanged()));
93 QSignalSpy startAngleSpy(m_series, SIGNAL(pieStartAngleChanged()));
87 QSignalSpy sizeSpy(&s, SIGNAL(pieSizeChanged()));
94 QSignalSpy endAngleSpy(m_series, SIGNAL(pieEndAngleChanged()));
88 QSignalSpy startAngleSpy(&s, SIGNAL(pieStartAngleChanged()));
95 QSignalSpy horPosSpy(m_series, SIGNAL(horizontalPositionChanged()));
89 QSignalSpy endAngleSpy(&s, SIGNAL(pieEndAngleChanged()));
96 QSignalSpy verPosSpy(m_series, SIGNAL(verticalPositionChanged()));
90 QSignalSpy horPosSpy(&s, SIGNAL(horizontalPositionChanged()));
97
91 QSignalSpy verPosSpy(&s, SIGNAL(verticalPositionChanged()));
98 QVERIFY(m_series->type() == QAbstractSeries::SeriesTypePie);
92
99 QVERIFY(m_series->count() == 0);
93 QVERIFY(s.type() == QAbstractSeries::SeriesTypePie);
100 QVERIFY(m_series->isEmpty());
94 QVERIFY(s.count() == 0);
101 QCOMPARE(m_series->sum(), 0.0);
95 QVERIFY(s.isEmpty());
102 QCOMPARE(m_series->horizontalPosition(), 0.5);
96 QCOMPARE(s.sum(), 0.0);
103 QCOMPARE(m_series->verticalPosition(), 0.5);
97 QCOMPARE(s.horizontalPosition(), 0.5);
104 QCOMPARE(m_series->pieSize(), 0.7);
98 QCOMPARE(s.verticalPosition(), 0.5);
105 QCOMPARE(m_series->pieStartAngle(), 0.0);
99 QCOMPARE(s.pieSize(), 0.7);
106 QCOMPARE(m_series->pieEndAngle(), 360.0);
100 QCOMPARE(s.pieStartAngle(), 0.0);
107
101 QCOMPARE(s.pieEndAngle(), 360.0);
108 m_series->append("s1", 1);
102
109 m_series->append("s2", 1);
103 s.append("s1", 1);
110 m_series->append("s3", 1);
104 s.append("s2", 1);
111 m_series->insert(1, new QPieSlice("s4", 1));
105 s.append("s3", 1);
112 m_series->remove(m_series->slices().first());
106 s.insert(1, new QPieSlice("s4", 1));
113 QCOMPARE(m_series->count(), 3);
107 s.remove(s.slices().first());
114 QCOMPARE(m_series->sum(), 3.0);
108 QCOMPARE(s.count(), 3);
115 m_series->clear();
109 QCOMPARE(s.sum(), 3.0);
116 QCOMPARE(m_series->count(), 0);
110 s.clear();
117 QCOMPARE(m_series->sum(), 0.0);
111 QCOMPARE(s.count(), 0);
112 QCOMPARE(s.sum(), 0.0);
113 QCOMPARE(countSpy.count(), 6);
118 QCOMPARE(countSpy.count(), 6);
114 QCOMPARE(sumSpy.count(), 6);
119 QCOMPARE(sumSpy.count(), 6);
115
120
116 s.setPieSize(-1.0);
121 m_series->setPieSize(-1.0);
117 QCOMPARE(s.pieSize(), 0.0);
122 QCOMPARE(m_series->pieSize(), 0.0);
118 s.setPieSize(0.0);
123 m_series->setPieSize(0.0);
119 s.setPieSize(0.9);
124 m_series->setPieSize(0.9);
120 s.setPieSize(2.0);
125 m_series->setPieSize(2.0);
121 QCOMPARE(s.pieSize(), 1.0);
126 QCOMPARE(m_series->pieSize(), 1.0);
122 QCOMPARE(sizeSpy.count(), 3);
127 QCOMPARE(sizeSpy.count(), 3);
123
128
124 s.setPieStartAngle(0);
129 m_series->setPieStartAngle(0);
125 s.setPieStartAngle(-180);
130 m_series->setPieStartAngle(-180);
126 s.setPieStartAngle(180);
131 m_series->setPieStartAngle(180);
127 QCOMPARE(startAngleSpy.count(), 2);
132 QCOMPARE(startAngleSpy.count(), 2);
128
133
129 s.setPieEndAngle(360);
134 m_series->setPieEndAngle(360);
130 s.setPieEndAngle(-180);
135 m_series->setPieEndAngle(-180);
131 s.setPieEndAngle(180);
136 m_series->setPieEndAngle(180);
132 QCOMPARE(endAngleSpy.count(), 2);
137 QCOMPARE(endAngleSpy.count(), 2);
133
138
134 s.setHorizontalPosition(0.5);
139 m_series->setHorizontalPosition(0.5);
135 s.setHorizontalPosition(-1.0);
140 m_series->setHorizontalPosition(-1.0);
136 QCOMPARE(s.horizontalPosition(), 0.0);
141 QCOMPARE(m_series->horizontalPosition(), 0.0);
137 s.setHorizontalPosition(1.0);
142 m_series->setHorizontalPosition(1.0);
138 s.setHorizontalPosition(2.0);
143 m_series->setHorizontalPosition(2.0);
139 QCOMPARE(s.horizontalPosition(), 1.0);
144 QCOMPARE(m_series->horizontalPosition(), 1.0);
140 QCOMPARE(horPosSpy.count(), 2);
145 QCOMPARE(horPosSpy.count(), 2);
141
146
142 s.setVerticalPosition(0.5);
147 m_series->setVerticalPosition(0.5);
143 s.setVerticalPosition(-1.0);
148 m_series->setVerticalPosition(-1.0);
144 QCOMPARE(s.verticalPosition(), 0.0);
149 QCOMPARE(m_series->verticalPosition(), 0.0);
145 s.setVerticalPosition(1.0);
150 m_series->setVerticalPosition(1.0);
146 s.setVerticalPosition(2.0);
151 m_series->setVerticalPosition(2.0);
147 QCOMPARE(s.verticalPosition(), 1.0);
152 QCOMPARE(m_series->verticalPosition(), 1.0);
148 QCOMPARE(verPosSpy.count(), 2);
153 QCOMPARE(verPosSpy.count(), 2);
149 }
154 }
150
155
151 void tst_qpieseries::append()
156 void tst_qpieseries::append()
152 {
157 {
153 QPieSeries s;
158 m_view->chart()->addSeries(m_series);
154 QSignalSpy addedSpy(&s, SIGNAL(added(QList<QPieSlice*>)));
159 QSignalSpy addedSpy(m_series, SIGNAL(added(QList<QPieSlice*>)));
155
160
156 // append pointer
161 // append pointer
157 QPieSlice *slice1 = 0;
162 QPieSlice *slice1 = 0;
158 QVERIFY(!s.append(slice1));
163 QVERIFY(!m_series->append(slice1));
159 slice1 = new QPieSlice("slice 1", 1);
164 slice1 = new QPieSlice("slice 1", 1);
160 QVERIFY(s.append(slice1));
165 QVERIFY(m_series->append(slice1));
161 QVERIFY(!s.append(slice1));
166 QVERIFY(!m_series->append(slice1));
162 QCOMPARE(s.count(), 1);
167 QCOMPARE(m_series->count(), 1);
163 QCOMPARE(addedSpy.count(), 1);
168 QCOMPARE(addedSpy.count(), 1);
164 QList<QPieSlice*> added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(0).at(0));
169 QList<QPieSlice*> added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(0).at(0));
165 QCOMPARE(added.count(), 1);
170 QCOMPARE(added.count(), 1);
@@ -167,15 +172,15 void tst_qpieseries::append()
167
172
168 // append pointer list
173 // append pointer list
169 QList<QPieSlice *> list;
174 QList<QPieSlice *> list;
170 QVERIFY(!s.append(list));
175 QVERIFY(!m_series->append(list));
171 list << (QPieSlice *) 0;
176 list << (QPieSlice *) 0;
172 QVERIFY(!s.append(list));
177 QVERIFY(!m_series->append(list));
173 list.clear();
178 list.clear();
174 list << new QPieSlice("slice 2", 2);
179 list << new QPieSlice("slice 2", 2);
175 list << new QPieSlice("slice 3", 3);
180 list << new QPieSlice("slice 3", 3);
176 QVERIFY(s.append(list));
181 QVERIFY(m_series->append(list));
177 QVERIFY(!s.append(list));
182 QVERIFY(!m_series->append(list));
178 QCOMPARE(s.count(), 3);
183 QCOMPARE(m_series->count(), 3);
179 QCOMPARE(addedSpy.count(), 2);
184 QCOMPARE(addedSpy.count(), 2);
180 added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(1).at(0));
185 added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(1).at(0));
181 QCOMPARE(added.count(), 2);
186 QCOMPARE(added.count(), 2);
@@ -183,56 +188,61 void tst_qpieseries::append()
183
188
184 // append operator
189 // append operator
185 QPieSlice *slice4 = new QPieSlice("slice 4", 4);
190 QPieSlice *slice4 = new QPieSlice("slice 4", 4);
186 s << slice4;
191 *m_series << slice4;
187 s << slice1; // fails because already added
192 *m_series << slice1; // fails because already added
188 QCOMPARE(s.count(), 4);
193 QCOMPARE(m_series->count(), 4);
189 QCOMPARE(addedSpy.count(), 3);
194 QCOMPARE(addedSpy.count(), 3);
190 added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(2).at(0));
195 added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(2).at(0));
191 QCOMPARE(added.count(), 1);
196 QCOMPARE(added.count(), 1);
192 QCOMPARE(added.first(), slice4);
197 QCOMPARE(added.first(), slice4);
193
198
194 // append with params
199 // append with params
195 QPieSlice *slice5 = s.append("slice 5", 5);
200 QPieSlice *slice5 = m_series->append("slice 5", 5);
196 QVERIFY(slice5 != 0);
201 QVERIFY(slice5 != 0);
197 QCOMPARE(slice5->value(), 5.0);
202 QCOMPARE(slice5->value(), 5.0);
198 QCOMPARE(slice5->label(), QString("slice 5"));
203 QCOMPARE(slice5->label(), QString("slice 5"));
199 QCOMPARE(s.count(), 5);
204 QCOMPARE(m_series->count(), 5);
200 QCOMPARE(addedSpy.count(), 4);
205 QCOMPARE(addedSpy.count(), 4);
201 added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(3).at(0));
206 added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(3).at(0));
202 QCOMPARE(added.count(), 1);
207 QCOMPARE(added.count(), 1);
203 QCOMPARE(added.first(), slice5);
208 QCOMPARE(added.first(), slice5);
204
209
205 // check slices
210 // check slices
206 QVERIFY(!s.isEmpty());
211 QVERIFY(!m_series->isEmpty());
207 for (int i=0; i<s.count(); i++) {
212 for (int i=0; i<m_series->count(); i++) {
208 QCOMPARE(s.slices().at(i)->value(), (qreal) i+1);
213 QCOMPARE(m_series->slices().at(i)->value(), (qreal) i+1);
209 QCOMPARE(s.slices().at(i)->label(), QString("slice ") + QString::number(i+1));
214 QCOMPARE(m_series->slices().at(i)->label(), QString("slice ") + QString::number(i+1));
210 }
215 }
211 }
216 }
212
217
218 void tst_qpieseries::appendAnimated()
219 {
220 m_view->chart()->setAnimationOptions(QChart::AllAnimations);
221 }
222
213 void tst_qpieseries::insert()
223 void tst_qpieseries::insert()
214 {
224 {
215 QPieSeries s;
225 m_view->chart()->addSeries(m_series);
216 QSignalSpy addedSpy(&s, SIGNAL(added(QList<QPieSlice*>)));
226 QSignalSpy addedSpy(m_series, SIGNAL(added(QList<QPieSlice*>)));
217
227
218 // insert one slice
228 // insert one slice
219 QPieSlice *slice1 = 0;
229 QPieSlice *slice1 = 0;
220 QVERIFY(!s.insert(0, slice1));
230 QVERIFY(!m_series->insert(0, slice1));
221 slice1 = new QPieSlice("slice 1", 1);
231 slice1 = new QPieSlice("slice 1", 1);
222 QVERIFY(!s.insert(-1, slice1));
232 QVERIFY(!m_series->insert(-1, slice1));
223 QVERIFY(!s.insert(5, slice1));
233 QVERIFY(!m_series->insert(5, slice1));
224 QVERIFY(s.insert(0, slice1));
234 QVERIFY(m_series->insert(0, slice1));
225 QVERIFY(!s.insert(0, slice1));
235 QVERIFY(!m_series->insert(0, slice1));
226 QCOMPARE(s.count(), 1);
236 QCOMPARE(m_series->count(), 1);
227 QCOMPARE(addedSpy.count(), 1);
237 QCOMPARE(addedSpy.count(), 1);
228 QList<QPieSlice*> added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(0).at(0));
238 QList<QPieSlice*> added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(0).at(0));
229 QCOMPARE(added.count(), 1);
239 QCOMPARE(added.count(), 1);
230 QCOMPARE(added.first(), slice1);
240 QCOMPARE(added.first(), slice1);
231
241
232 // add some more slices
242 // add some more slices
233 QPieSlice *slice2 = s.append("slice 2", 2);
243 QPieSlice *slice2 = m_series->append("slice 2", 2);
234 QPieSlice *slice4 = s.append("slice 4", 4);
244 QPieSlice *slice4 = m_series->append("slice 4", 4);
235 QCOMPARE(s.count(), 3);
245 QCOMPARE(m_series->count(), 3);
236 QCOMPARE(addedSpy.count(), 3);
246 QCOMPARE(addedSpy.count(), 3);
237 added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(1).at(0));
247 added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(1).at(0));
238 QCOMPARE(added.count(), 1);
248 QCOMPARE(added.count(), 1);
@@ -243,52 +253,57 void tst_qpieseries::insert()
243
253
244 // insert between slices
254 // insert between slices
245 QPieSlice *slice3 = new QPieSlice("slice 3", 3);
255 QPieSlice *slice3 = new QPieSlice("slice 3", 3);
246 s.insert(2, slice3);
256 m_series->insert(2, slice3);
247 QCOMPARE(s.count(), 4);
257 QCOMPARE(m_series->count(), 4);
248 QCOMPARE(addedSpy.count(), 4);
258 QCOMPARE(addedSpy.count(), 4);
249 added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(3).at(0));
259 added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(3).at(0));
250 QCOMPARE(added.count(), 1);
260 QCOMPARE(added.count(), 1);
251 QCOMPARE(added.first(), slice3);
261 QCOMPARE(added.first(), slice3);
252
262
253 // check slices
263 // check slices
254 for (int i=0; i<s.count(); i++) {
264 for (int i=0; i<m_series->count(); i++) {
255 QCOMPARE(s.slices().at(i)->value(), (qreal) i+1);
265 QCOMPARE(m_series->slices().at(i)->value(), (qreal) i+1);
256 QCOMPARE(s.slices().at(i)->label(), QString("slice ") + QString::number(i+1));
266 QCOMPARE(m_series->slices().at(i)->label(), QString("slice ") + QString::number(i+1));
257 }
267 }
258 }
268 }
259
269
270 void tst_qpieseries::insertAnimated()
271 {
272 m_view->chart()->setAnimationOptions(QChart::AllAnimations);
273 }
274
260 void tst_qpieseries::remove()
275 void tst_qpieseries::remove()
261 {
276 {
262 QPieSeries s;
277 m_view->chart()->addSeries(m_series);
263 QSignalSpy removedSpy(&s, SIGNAL(removed(QList<QPieSlice*>)));
278 QSignalSpy removedSpy(m_series, SIGNAL(removed(QList<QPieSlice*>)));
264
279
265 // add some slices
280 // add some slices
266 QPieSlice *slice1 = s.append("slice 1", 1);
281 QPieSlice *slice1 = m_series->append("slice 1", 1);
267 QPieSlice *slice2 = s.append("slice 2", 2);
282 QPieSlice *slice2 = m_series->append("slice 2", 2);
268 QPieSlice *slice3 = s.append("slice 3", 3);
283 QPieSlice *slice3 = m_series->append("slice 3", 3);
269 QSignalSpy spy1(slice1, SIGNAL(destroyed()));
284 QSignalSpy spy1(slice1, SIGNAL(destroyed()));
270 QSignalSpy spy2(slice2, SIGNAL(destroyed()));
285 QSignalSpy spy2(slice2, SIGNAL(destroyed()));
271 QSignalSpy spy3(slice3, SIGNAL(destroyed()));
286 QSignalSpy spy3(slice3, SIGNAL(destroyed()));
272 QCOMPARE(s.count(), 3);
287 QCOMPARE(m_series->count(), 3);
273
288
274 // null pointer remove
289 // null pointer remove
275 QVERIFY(!s.remove(0));
290 QVERIFY(!m_series->remove(0));
276
291
277 // remove first
292 // remove first
278 QVERIFY(s.remove(slice1));
293 QVERIFY(m_series->remove(slice1));
279 QVERIFY(!s.remove(slice1));
294 QVERIFY(!m_series->remove(slice1));
280 QCOMPARE(s.count(), 2);
295 QCOMPARE(m_series->count(), 2);
281 QCOMPARE(s.slices().at(0)->label(), slice2->label());
296 QCOMPARE(m_series->slices().at(0)->label(), slice2->label());
282 QCOMPARE(removedSpy.count(), 1);
297 QCOMPARE(removedSpy.count(), 1);
283 QList<QPieSlice*> removed = qvariant_cast<QList<QPieSlice*> >(removedSpy.at(0).at(0));
298 QList<QPieSlice*> removed = qvariant_cast<QList<QPieSlice*> >(removedSpy.at(0).at(0));
284 QCOMPARE(removed.count(), 1);
299 QCOMPARE(removed.count(), 1);
285 QCOMPARE(removed.first(), slice1);
300 QCOMPARE(removed.first(), slice1);
286
301
287 // remove all
302 // remove all
288 s.clear();
303 m_series->clear();
289 QVERIFY(s.isEmpty());
304 QVERIFY(m_series->isEmpty());
290 QVERIFY(s.slices().isEmpty());
305 QVERIFY(m_series->slices().isEmpty());
291 QCOMPARE(s.count(), 0);
306 QCOMPARE(m_series->count(), 0);
292 QCOMPARE(removedSpy.count(), 2);
307 QCOMPARE(removedSpy.count(), 2);
293 removed = qvariant_cast<QList<QPieSlice*> >(removedSpy.at(1).at(0));
308 removed = qvariant_cast<QList<QPieSlice*> >(removedSpy.at(1).at(0));
294 QCOMPARE(removed.count(), 2);
309 QCOMPARE(removed.count(), 2);
@@ -301,10 +316,14 void tst_qpieseries::remove()
301 TRY_COMPARE(spy3.count(), 1);
316 TRY_COMPARE(spy3.count(), 1);
302 }
317 }
303
318
319 void tst_qpieseries::removeAnimated()
320 {
321 m_view->chart()->setAnimationOptions(QChart::AllAnimations);
322 }
323
304 void tst_qpieseries::calculatedValues()
324 void tst_qpieseries::calculatedValues()
305 {
325 {
306 bool ok;
326 m_view->chart()->addSeries(m_series);
307 QPieSeries s;
308
327
309 QPieSlice *slice1 = new QPieSlice("slice 1", 1);
328 QPieSlice *slice1 = new QPieSlice("slice 1", 1);
310 QSignalSpy percentageSpy(slice1, SIGNAL(percentageChanged()));
329 QSignalSpy percentageSpy(slice1, SIGNAL(percentageChanged()));
@@ -312,8 +331,9 void tst_qpieseries::calculatedValues()
312 QSignalSpy angleSpanSpy(slice1, SIGNAL(angleSpanChanged()));
331 QSignalSpy angleSpanSpy(slice1, SIGNAL(angleSpanChanged()));
313
332
314 // add a slice
333 // add a slice
315 s.append(slice1);
334 m_series->append(slice1);
316 verifyCalculatedData(s, &ok);
335 bool ok;
336 verifyCalculatedData(*m_series, &ok);
317 if (!ok)
337 if (!ok)
318 return;
338 return;
319 QCOMPARE(percentageSpy.count(), 1);
339 QCOMPARE(percentageSpy.count(), 1);
@@ -324,8 +344,8 void tst_qpieseries::calculatedValues()
324 QList<QPieSlice *> list;
344 QList<QPieSlice *> list;
325 list << new QPieSlice("slice 2", 2);
345 list << new QPieSlice("slice 2", 2);
326 list << new QPieSlice("slice 3", 3);
346 list << new QPieSlice("slice 3", 3);
327 s.append(list);
347 m_series->append(list);
328 verifyCalculatedData(s, &ok);
348 verifyCalculatedData(*m_series, &ok);
329 if (!ok)
349 if (!ok)
330 return;
350 return;
331 QCOMPARE(percentageSpy.count(), 2);
351 QCOMPARE(percentageSpy.count(), 2);
@@ -333,8 +353,8 void tst_qpieseries::calculatedValues()
333 QCOMPARE(angleSpanSpy.count(), 2);
353 QCOMPARE(angleSpanSpy.count(), 2);
334
354
335 // remove a slice
355 // remove a slice
336 s.remove(list.first()); // remove slice 2
356 m_series->remove(list.first()); // remove slice 2
337 verifyCalculatedData(s, &ok);
357 verifyCalculatedData(*m_series, &ok);
338 if (!ok)
358 if (!ok)
339 return;
359 return;
340 QCOMPARE(percentageSpy.count(), 3);
360 QCOMPARE(percentageSpy.count(), 3);
@@ -342,8 +362,8 void tst_qpieseries::calculatedValues()
342 QCOMPARE(angleSpanSpy.count(), 3);
362 QCOMPARE(angleSpanSpy.count(), 3);
343
363
344 // insert a slice
364 // insert a slice
345 s.insert(0, new QPieSlice("Slice 4", 4));
365 m_series->insert(0, new QPieSlice("Slice 4", 4));
346 verifyCalculatedData(s, &ok);
366 verifyCalculatedData(*m_series, &ok);
347 if (!ok)
367 if (!ok)
348 return;
368 return;
349 QCOMPARE(percentageSpy.count(), 4);
369 QCOMPARE(percentageSpy.count(), 4);
@@ -351,9 +371,9 void tst_qpieseries::calculatedValues()
351 QCOMPARE(angleSpanSpy.count(), 4);
371 QCOMPARE(angleSpanSpy.count(), 4);
352
372
353 // modify pie angles
373 // modify pie angles
354 s.setPieStartAngle(-90);
374 m_series->setPieStartAngle(-90);
355 s.setPieEndAngle(90);
375 m_series->setPieEndAngle(90);
356 verifyCalculatedData(s, &ok);
376 verifyCalculatedData(*m_series, &ok);
357 if (!ok)
377 if (!ok)
358 return;
378 return;
359 QCOMPARE(percentageSpy.count(), 4);
379 QCOMPARE(percentageSpy.count(), 4);
@@ -361,8 +381,10 void tst_qpieseries::calculatedValues()
361 QCOMPARE(angleSpanSpy.count(), 6);
381 QCOMPARE(angleSpanSpy.count(), 6);
362
382
363 // clear all
383 // clear all
364 s.clear();
384 m_series->clear();
365 verifyCalculatedData(s, &ok);
385 verifyCalculatedData(*m_series, &ok);
386 if (!ok)
387 return;
366 QCOMPARE(percentageSpy.count(), 4);
388 QCOMPARE(percentageSpy.count(), 4);
367 QCOMPARE(startAngleSpy.count(), 3);
389 QCOMPARE(startAngleSpy.count(), 3);
368 QCOMPARE(angleSpanSpy.count(), 6);
390 QCOMPARE(angleSpanSpy.count(), 6);
@@ -397,21 +419,19 void tst_qpieseries::verifyCalculatedData(const QPieSeries &series, bool *ok)
397
419
398 void tst_qpieseries::clickedSignal()
420 void tst_qpieseries::clickedSignal()
399 {
421 {
400 // create a pie series
422 // add some slices
401 QPieSeries *series = new QPieSeries();
423 QPieSlice *s1 = m_series->append("slice 1", 1);
402 QPieSlice *s1 = series->append("slice 1", 1);
424 QPieSlice *s2 = m_series->append("slice 2", 1);
403 QPieSlice *s2 = series->append("slice 2", 1);
425 QPieSlice *s3 = m_series->append("slice 3", 1);
404 QPieSlice *s3 = series->append("slice 3", 1);
426 QPieSlice *s4 = m_series->append("slice 4", 1);
405 QPieSlice *s4 = series->append("slice 4", 1);
427 QSignalSpy clickSpy(m_series, SIGNAL(clicked(QPieSlice*)));
406 QSignalSpy clickSpy(series, SIGNAL(clicked(QPieSlice*)));
407
428
408 // add series to the chart
429 // add series to the chart
409 QChartView view(new QChart());
430 m_view->chart()->legend()->setVisible(false);
410 view.chart()->legend()->setVisible(false);
431 m_view->resize(200, 200);
411 view.resize(200, 200);
432 m_view->chart()->addSeries(m_series);
412 view.chart()->addSeries(series);
433 m_view->show();
413 view.show();
434 QTest::qWaitForWindowShown(m_view);
414 QTest::qWaitForWindowShown(&view);
415
435
416 // if you devide the chart in four equal tiles these
436 // if you devide the chart in four equal tiles these
417 // are the center points of those tiles
437 // are the center points of those tiles
@@ -422,12 +442,12 void tst_qpieseries::clickedSignal()
422
442
423 QPoint center(120, 120);
443 QPoint center(120, 120);
424
444
425 series->setPieSize(1.0);
445 m_series->setPieSize(1.0);
426 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, p1);
446 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p1);
427 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, p2);
447 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p2);
428 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, p3);
448 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p3);
429 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, p4);
449 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p4);
430 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, center);
450 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, center);
431 TRY_COMPARE(clickSpy.count(), 5); // all hit
451 TRY_COMPARE(clickSpy.count(), 5); // all hit
432 QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(0).at(0)), s4);
452 QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(0).at(0)), s4);
433 QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(1).at(0)), s1);
453 QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(1).at(0)), s1);
@@ -435,79 +455,77 void tst_qpieseries::clickedSignal()
435 QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(3).at(0)), s2);
455 QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(3).at(0)), s2);
436 clickSpy.clear();
456 clickSpy.clear();
437
457
438 series->setPieSize(0.5);
458 m_series->setPieSize(0.5);
439 series->setVerticalPosition(0.25);
459 m_series->setVerticalPosition(0.25);
440 series->setHorizontalPosition(0.25);
460 m_series->setHorizontalPosition(0.25);
441 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, p1); // hits
461 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p1); // hits
442 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, p2);
462 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p2);
443 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, p3);
463 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p3);
444 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, p4);
464 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p4);
445 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, center);
465 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, center);
446 TRY_COMPARE(clickSpy.count(), 1);
466 TRY_COMPARE(clickSpy.count(), 1);
447 clickSpy.clear();
467 clickSpy.clear();
448
468
449 series->setVerticalPosition(0.25);
469 m_series->setVerticalPosition(0.25);
450 series->setHorizontalPosition(0.75);
470 m_series->setHorizontalPosition(0.75);
451 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, p1);
471 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p1);
452 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, p2); // hits
472 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p2); // hits
453 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, p3);
473 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p3);
454 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, p4);
474 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p4);
455 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, center);
475 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, center);
456 TRY_COMPARE(clickSpy.count(), 1);
476 TRY_COMPARE(clickSpy.count(), 1);
457 clickSpy.clear();
477 clickSpy.clear();
458
478
459 series->setVerticalPosition(0.75);
479 m_series->setVerticalPosition(0.75);
460 series->setHorizontalPosition(0.25);
480 m_series->setHorizontalPosition(0.25);
461 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, p1);
481 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p1);
462 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, p2);
482 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p2);
463 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, p3); // hits
483 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p3); // hits
464 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, p4);
484 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p4);
465 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, center);
485 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, center);
466 TRY_COMPARE(clickSpy.count(), 1);
486 TRY_COMPARE(clickSpy.count(), 1);
467 clickSpy.clear();
487 clickSpy.clear();
468
488
469 series->setVerticalPosition(0.75);
489 m_series->setVerticalPosition(0.75);
470 series->setHorizontalPosition(0.75);
490 m_series->setHorizontalPosition(0.75);
471 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, p1);
491 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p1);
472 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, p2);
492 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p2);
473 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, p3);
493 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p3);
474 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, p4); // hits
494 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p4); // hits
475 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, center);
495 QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, center);
476 TRY_COMPARE(clickSpy.count(), 1);
496 TRY_COMPARE(clickSpy.count(), 1);
477 clickSpy.clear();
497 clickSpy.clear();
478 }
498 }
479
499
480 void tst_qpieseries::hoverSignal()
500 void tst_qpieseries::hoverSignal()
481 {
501 {
482 // create a pie series
502 // add some slices
483 QPieSeries *series = new QPieSeries();
503 m_series->setPieSize(1.0);
484 series->setPieSize(1.0);
504 QPieSlice *s1 = m_series->append("slice 1", 1);
485 QPieSlice *s1 = series->append("slice 1", 1);
505 m_series->append("slice 2", 2);
486 series->append("slice 2", 2);
506 m_series->append("slice 3", 3);
487 series->append("slice 3", 3);
488
507
489 // add series to the chart
508 // add series to the chart
490 QChartView view(new QChart());
509 m_view->chart()->legend()->setVisible(false);
491 view.chart()->legend()->setVisible(false);
510 m_view->resize(200, 200);
492 view.resize(200, 200);
511 m_view->chart()->addSeries(m_series);
493 view.chart()->addSeries(series);
512 m_view->show();
494 view.show();
513 QTest::qWaitForWindowShown(m_view);
495 QTest::qWaitForWindowShown(&view);
496
514
497 // first move to right top corner
515 // first move to right top corner
498 QTest::mouseMove(view.viewport(), QPoint(200, 0));
516 QTest::mouseMove(m_view->viewport(), QPoint(200, 0));
499 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
517 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
500
518
501 // move inside the slice
519 // move inside the slice
502 // pie rectangle: QRectF(60,60 121x121)
520 // pie rectangle: QRectF(60,60 121x121)
503 QSignalSpy hoverSpy(series, SIGNAL(hovered(QPieSlice*,bool)));
521 QSignalSpy hoverSpy(m_series, SIGNAL(hovered(QPieSlice*,bool)));
504 QTest::mouseMove(view.viewport(), QPoint(139, 85));
522 QTest::mouseMove(m_view->viewport(), QPoint(139, 85));
505 TRY_COMPARE(hoverSpy.count(), 1);
523 TRY_COMPARE(hoverSpy.count(), 1);
506 QCOMPARE(qvariant_cast<QPieSlice*>(hoverSpy.at(0).at(0)), s1);
524 QCOMPARE(qvariant_cast<QPieSlice*>(hoverSpy.at(0).at(0)), s1);
507 QCOMPARE(qvariant_cast<bool>(hoverSpy.at(0).at(1)), true);
525 QCOMPARE(qvariant_cast<bool>(hoverSpy.at(0).at(1)), true);
508
526
509 // move outside the slice
527 // move outside the slice
510 QTest::mouseMove(view.viewport(), QPoint(200, 0));
528 QTest::mouseMove(m_view->viewport(), QPoint(200, 0));
511 TRY_COMPARE(hoverSpy.count(), 2);
529 TRY_COMPARE(hoverSpy.count(), 2);
512 QCOMPARE(qvariant_cast<QPieSlice*>(hoverSpy.at(1).at(0)), s1);
530 QCOMPARE(qvariant_cast<QPieSlice*>(hoverSpy.at(1).at(0)), s1);
513 QCOMPARE(qvariant_cast<bool>(hoverSpy.at(1).at(1)), false);
531 QCOMPARE(qvariant_cast<bool>(hoverSpy.at(1).at(1)), false);
General Comments 0
You need to be logged in to leave comments. Login now