@@ -60,6 +60,7 private slots: | |||
|
60 | 60 | |
|
61 | 61 | private: |
|
62 | 62 | void verifyCalculatedData(const QPieSeries &series, bool *ok); |
|
63 | QList<QPoint> slicePoints(QRectF rect); | |
|
63 | 64 | |
|
64 | 65 | private: |
|
65 | 66 | QChartView *m_view; |
@@ -477,9 +478,12 void tst_qpieseries::verifyCalculatedData(const QPieSeries &series, bool *ok) | |||
|
477 | 478 | *ok = true; |
|
478 | 479 | } |
|
479 | 480 | |
|
480 | ||
|
481 | 481 | void tst_qpieseries::clickedSignal() |
|
482 | 482 | { |
|
483 | // NOTE: | |
|
484 | // This test is the same as tst_qpieslice::clickedSignal() | |
|
485 | // Just for different signals. | |
|
486 | ||
|
483 | 487 | SKIP_IF_CANNOT_TEST_MOUSE_EVENTS(); |
|
484 | 488 | |
|
485 | 489 | // add some slices |
@@ -491,109 +495,85 void tst_qpieseries::clickedSignal() | |||
|
491 | 495 | |
|
492 | 496 | // add series to the chart |
|
493 | 497 | m_view->chart()->legend()->setVisible(false); |
|
494 | m_view->resize(200, 200); | |
|
495 | 498 | m_view->chart()->addSeries(m_series); |
|
496 | 499 | m_view->show(); |
|
497 | 500 | QTest::qWaitForWindowShown(m_view); |
|
498 | 501 | |
|
499 | // if you divide the chart in four equal tiles these | |
|
500 | // are the center points of those tiles | |
|
501 | QPoint p1(90.25, 90); | |
|
502 | QPoint p2(150, 90); | |
|
503 | QPoint p3(90, 150); | |
|
504 | QPoint p4(150, 150); | |
|
505 | ||
|
506 | QPoint center(120, 120); | |
|
507 | ||
|
502 | // test maximum size | |
|
508 | 503 | m_series->setPieSize(1.0); |
|
509 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p1); | |
|
510 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p2); | |
|
511 |
QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p |
|
|
512 |
QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p |
|
|
513 |
QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, |
|
|
514 | TRY_COMPARE(clickSpy.count(), 5); // all hit | |
|
515 | QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(0).at(0)), s4); | |
|
516 |
QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at( |
|
|
504 | QRectF pieRect = m_view->chart()->plotArea(); | |
|
505 | QList<QPoint> points = slicePoints(pieRect); | |
|
506 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, points.at(0)); | |
|
507 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, points.at(1)); | |
|
508 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, points.at(2)); | |
|
509 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, points.at(3)); | |
|
510 | TRY_COMPARE(clickSpy.count(), 4); | |
|
511 | QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(0).at(0)), s1); | |
|
512 | QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(1).at(0)), s2); | |
|
517 | 513 | QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(2).at(0)), s3); |
|
518 |
QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(3).at(0)), s |
|
|
514 | QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(3).at(0)), s4); | |
|
519 | 515 | clickSpy.clear(); |
|
520 | 516 | |
|
517 | // test half size | |
|
521 | 518 | m_series->setPieSize(0.5); |
|
522 | 519 | m_series->setVerticalPosition(0.25); |
|
523 | 520 | m_series->setHorizontalPosition(0.25); |
|
524 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p1); // hits | |
|
525 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p2); | |
|
526 |
QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p |
|
|
527 |
QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p |
|
|
528 |
QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, |
|
|
529 | TRY_COMPARE(clickSpy.count(), 1); | |
|
530 | clickSpy.clear(); | |
|
531 | ||
|
532 | m_series->setVerticalPosition(0.25); | |
|
533 | m_series->setHorizontalPosition(0.75); | |
|
534 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p1); | |
|
535 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p2); // hits | |
|
536 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p3); | |
|
537 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p4); | |
|
538 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, center); | |
|
539 | TRY_COMPARE(clickSpy.count(), 1); | |
|
540 | clickSpy.clear(); | |
|
541 | ||
|
542 | m_series->setVerticalPosition(0.75); | |
|
543 | m_series->setHorizontalPosition(0.25); | |
|
544 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p1); | |
|
545 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p2); | |
|
546 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p3); // hits | |
|
547 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p4); | |
|
548 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, center); | |
|
549 | TRY_COMPARE(clickSpy.count(), 1); | |
|
550 | clickSpy.clear(); | |
|
551 | ||
|
552 | m_series->setVerticalPosition(0.75); | |
|
553 | m_series->setHorizontalPosition(0.75); | |
|
554 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p1); | |
|
555 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p2); | |
|
556 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p3); | |
|
557 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, p4); // hits | |
|
558 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, center); | |
|
559 | TRY_COMPARE(clickSpy.count(), 1); | |
|
560 | clickSpy.clear(); | |
|
521 | pieRect = QRectF(m_view->chart()->plotArea().topLeft(), m_view->chart()->plotArea().center()); | |
|
522 | points = slicePoints(pieRect); | |
|
523 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, points.at(0)); | |
|
524 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, points.at(1)); | |
|
525 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, points.at(2)); | |
|
526 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, points.at(3)); | |
|
527 | TRY_COMPARE(clickSpy.count(), 4); | |
|
528 | QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(0).at(0)), s1); | |
|
529 | QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(1).at(0)), s2); | |
|
530 | QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(2).at(0)), s3); | |
|
531 | QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(3).at(0)), s4); | |
|
561 | 532 | } |
|
562 | 533 | |
|
563 | 534 | void tst_qpieseries::hoverSignal() |
|
564 | 535 | { |
|
536 | // NOTE: | |
|
537 | // This test is the same as tst_qpieslice::hoverSignal() | |
|
538 | // Just for different signals. | |
|
539 | ||
|
565 | 540 | SKIP_IF_CANNOT_TEST_MOUSE_EVENTS(); |
|
566 | 541 | |
|
567 | 542 | // add some slices |
|
568 | m_series->setPieSize(1.0); | |
|
569 | 543 | QPieSlice *s1 = m_series->append("slice 1", 1); |
|
570 |
m_series->append("slice 2", |
|
|
571 |
m_series->append("slice 3", |
|
|
544 | QPieSlice *s2 = m_series->append("slice 2", 1); | |
|
545 | QPieSlice *s3 = m_series->append("slice 3", 1); | |
|
546 | QPieSlice *s4 = m_series->append("slice 4", 1); | |
|
572 | 547 | |
|
573 | 548 | // add series to the chart |
|
574 | 549 | m_view->chart()->legend()->setVisible(false); |
|
575 | m_view->resize(200, 200); | |
|
576 | 550 | m_view->chart()->addSeries(m_series); |
|
577 | 551 | m_view->show(); |
|
578 | 552 | QTest::qWaitForWindowShown(m_view); |
|
579 | 553 | |
|
580 | // first move to right top corner | |
|
581 | QTest::mouseMove(m_view->viewport(), QPoint(200, 0)); | |
|
582 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
|
583 | ||
|
584 | // move inside the slice | |
|
585 | // pie rectangle: QRectF(60,60 121x121) | |
|
554 | // move inside the slices | |
|
555 | m_series->setPieSize(1.0); | |
|
556 | QRectF pieRect = m_view->chart()->plotArea(); | |
|
557 | QList<QPoint> points = slicePoints(pieRect); | |
|
558 | QTest::mouseMove(m_view->viewport(), pieRect.topRight().toPoint()); | |
|
586 | 559 | QSignalSpy hoverSpy(m_series, SIGNAL(hovered(QPieSlice*,bool))); |
|
587 |
QTest::mouseMove(m_view->viewport(), |
|
|
588 | TRY_COMPARE(hoverSpy.count(), 1); | |
|
589 | QCOMPARE(qvariant_cast<QPieSlice*>(hoverSpy.at(0).at(0)), s1); | |
|
590 | QCOMPARE(qvariant_cast<bool>(hoverSpy.at(0).at(1)), true); | |
|
591 | ||
|
592 | // move outside the slice | |
|
593 | QTest::mouseMove(m_view->viewport(), QPoint(200, 0)); | |
|
594 |
|
|
|
595 | QCOMPARE(qvariant_cast<QPieSlice*>(hoverSpy.at(1).at(0)), s1); | |
|
596 | QCOMPARE(qvariant_cast<bool>(hoverSpy.at(1).at(1)), false); | |
|
560 | QTest::mouseMove(m_view->viewport(), points.at(0)); | |
|
561 | QTest::mouseMove(m_view->viewport(), points.at(1)); | |
|
562 | QTest::mouseMove(m_view->viewport(), points.at(2)); | |
|
563 | QTest::mouseMove(m_view->viewport(), points.at(3)); | |
|
564 | QTest::mouseMove(m_view->viewport(), pieRect.topLeft().toPoint()); | |
|
565 | ||
|
566 | // check | |
|
567 | QCOMPARE(hoverSpy.count(), 8); | |
|
568 | int i = 0; | |
|
569 | foreach (QPieSlice *s, m_series->slices()) { | |
|
570 | QCOMPARE(qvariant_cast<QPieSlice*>(hoverSpy.at(i).at(0)), s); | |
|
571 | QCOMPARE(qvariant_cast<bool>(hoverSpy.at(i).at(1)), true); | |
|
572 | i++; | |
|
573 | QCOMPARE(qvariant_cast<QPieSlice*>(hoverSpy.at(i).at(0)), s); | |
|
574 | QCOMPARE(qvariant_cast<bool>(hoverSpy.at(i).at(1)), false); | |
|
575 | i++; | |
|
576 | } | |
|
597 | 577 | } |
|
598 | 578 | |
|
599 | 579 | void tst_qpieseries::sliceSeries() |
@@ -636,6 +616,20 void tst_qpieseries::destruction() | |||
|
636 | 616 | QCOMPARE(spy3.count(), 1); |
|
637 | 617 | } |
|
638 | 618 | |
|
619 | QList<QPoint> tst_qpieseries::slicePoints(QRectF rect) | |
|
620 | { | |
|
621 | qreal x1 = rect.topLeft().x() + (rect.width() / 4); | |
|
622 | qreal x2 = rect.topLeft().x() + (rect.width() / 4) * 3; | |
|
623 | qreal y1 = rect.topLeft().y() + (rect.height() / 4); | |
|
624 | qreal y2 = rect.topLeft().y() + (rect.height() / 4) * 3; | |
|
625 | QList<QPoint> points; | |
|
626 | points << QPoint(x2, y1); | |
|
627 | points << QPoint(x2, y2); | |
|
628 | points << QPoint(x1, y2); | |
|
629 | points << QPoint(x1, y1); | |
|
630 | return points; | |
|
631 | } | |
|
632 | ||
|
639 | 633 | QTEST_MAIN(tst_qpieseries) |
|
640 | 634 | |
|
641 | 635 | #include "tst_qpieseries.moc" |
@@ -41,11 +41,11 private slots: | |||
|
41 | 41 | void construction(); |
|
42 | 42 | void changedSignals(); |
|
43 | 43 | void customize(); |
|
44 |
void |
|
|
45 |
void |
|
|
44 | void clickedSignal(); | |
|
45 | void hoverSignal(); | |
|
46 | 46 | |
|
47 | 47 | private: |
|
48 | ||
|
48 | QList<QPoint> slicePoints(QRectF rect); | |
|
49 | 49 | |
|
50 | 50 | private: |
|
51 | 51 | |
@@ -219,75 +219,110 void tst_qpieslice::customize() | |||
|
219 | 219 | QVERIFY(s1->labelFont() != f1); |
|
220 | 220 | } |
|
221 | 221 | |
|
222 |
void tst_qpieslice:: |
|
|
222 | void tst_qpieslice::clickedSignal() | |
|
223 | 223 | { |
|
224 | // NOTE: | |
|
225 | // This test is the same as tst_qpieseries::clickedSignal() | |
|
226 | // Just for different signals. | |
|
227 | ||
|
228 | SKIP_IF_CANNOT_TEST_MOUSE_EVENTS(); | |
|
229 | ||
|
224 | 230 | // create a pie series |
|
225 | 231 | QPieSeries *series = new QPieSeries(); |
|
226 | series->setPieSize(1.0); | |
|
227 | 232 | QPieSlice *s1 = series->append("slice 1", 1); |
|
228 |
QPieSlice *s2 = series->append("slice 2", |
|
|
229 |
QPieSlice *s3 = series->append("slice 3", |
|
|
233 | QPieSlice *s2 = series->append("slice 2", 1); | |
|
234 | QPieSlice *s3 = series->append("slice 3", 1); | |
|
235 | QPieSlice *s4 = series->append("slice 4", 1); | |
|
230 | 236 | QSignalSpy clickSpy1(s1, SIGNAL(clicked())); |
|
231 | 237 | QSignalSpy clickSpy2(s2, SIGNAL(clicked())); |
|
232 | 238 | QSignalSpy clickSpy3(s3, SIGNAL(clicked())); |
|
239 | QSignalSpy clickSpy4(s4, SIGNAL(clicked())); | |
|
233 | 240 | |
|
234 | 241 | // add series to the chart |
|
235 |
QChartView view |
|
|
242 | QChartView view; | |
|
236 | 243 | view.chart()->legend()->setVisible(false); |
|
237 | view.resize(200, 200); | |
|
238 | 244 | view.chart()->addSeries(series); |
|
239 | 245 | view.show(); |
|
240 | 246 | QTest::qWaitForWindowShown(&view); |
|
241 | 247 | |
|
242 | 248 | // simulate clicks |
|
243 | // pie rectangle: QRectF(60,60 121x121) | |
|
244 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(139, 85)); // inside slice 1 | |
|
245 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(146, 136)); // inside slice 2 | |
|
246 |
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, |
|
|
247 |
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, |
|
|
248 |
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, |
|
|
249 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
|
249 | series->setPieSize(1.0); | |
|
250 | QRectF pieRect = view.chart()->plotArea(); | |
|
251 | QList<QPoint> points = slicePoints(pieRect); | |
|
252 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, points.at(0)); | |
|
253 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, points.at(1)); | |
|
254 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, points.at(2)); | |
|
255 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, points.at(3)); | |
|
250 | 256 | QCOMPARE(clickSpy1.count(), 1); |
|
251 | 257 | QCOMPARE(clickSpy2.count(), 1); |
|
252 | 258 | QCOMPARE(clickSpy3.count(), 1); |
|
259 | QCOMPARE(clickSpy4.count(), 1); | |
|
253 | 260 | } |
|
254 | 261 | |
|
255 |
void tst_qpieslice:: |
|
|
262 | void tst_qpieslice::hoverSignal() | |
|
256 | 263 | { |
|
257 | // create a pie series | |
|
264 | // NOTE: | |
|
265 | // This test is the same as tst_qpieseries::hoverSignal() | |
|
266 | // Just for different signals. | |
|
267 | ||
|
268 | SKIP_IF_CANNOT_TEST_MOUSE_EVENTS(); | |
|
269 | ||
|
270 | // add some slices | |
|
258 | 271 | QPieSeries *series = new QPieSeries(); |
|
259 | series->setPieSize(1.0); | |
|
260 | 272 | QPieSlice *s1 = series->append("slice 1", 1); |
|
261 |
series->append("slice 2", |
|
|
262 |
series->append("slice 3", |
|
|
273 | QPieSlice *s2 = series->append("slice 2", 1); | |
|
274 | QPieSlice *s3 = series->append("slice 3", 1); | |
|
275 | QPieSlice *s4 = series->append("slice 4", 1); | |
|
263 | 276 | |
|
264 | 277 | // add series to the chart |
|
265 |
QChartView view |
|
|
278 | QChartView view; | |
|
266 | 279 | view.chart()->legend()->setVisible(false); |
|
267 | view.resize(200, 200); | |
|
268 | 280 | view.chart()->addSeries(series); |
|
269 | 281 | view.show(); |
|
270 | 282 | QTest::qWaitForWindowShown(&view); |
|
271 | 283 | |
|
272 | // first move to right top corner | |
|
273 | QTest::mouseMove(view.viewport(), QPoint(200, 0)); | |
|
274 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
|
275 | ||
|
276 | // move inside slice rectangle but NOT the actual slice | |
|
277 | // pie rectangle: QRectF(60,60 121x121) | |
|
278 |
QSignalSpy hoverSpy(s |
|
|
279 | QTest::mouseMove(view.viewport(), QPoint(170, 70)); | |
|
280 | TRY_COMPARE(hoverSpy.count(), 0); | |
|
281 | ||
|
282 | // move inside the slice | |
|
283 |
QTest::mouseMove(view.viewport(), |
|
|
284 | TRY_COMPARE(hoverSpy.count(), 1); | |
|
285 | QCOMPARE(qvariant_cast<bool>(hoverSpy.at(0).at(0)), true); | |
|
286 | ||
|
287 | // move outside the slice | |
|
288 | QTest::mouseMove(view.viewport(), QPoint(200, 0)); | |
|
289 | TRY_COMPARE(hoverSpy.count(), 2); | |
|
290 | QCOMPARE(qvariant_cast<bool>(hoverSpy.at(1).at(0)), false); | |
|
284 | // move inside the slices | |
|
285 | series->setPieSize(1.0); | |
|
286 | QRectF pieRect = view.chart()->plotArea(); | |
|
287 | QList<QPoint> points = slicePoints(pieRect); | |
|
288 | QTest::mouseMove(view.viewport(), pieRect.topRight().toPoint()); | |
|
289 | QSignalSpy hoverSpy1(s1, SIGNAL(hovered(bool))); | |
|
290 | QSignalSpy hoverSpy2(s2, SIGNAL(hovered(bool))); | |
|
291 | QSignalSpy hoverSpy3(s3, SIGNAL(hovered(bool))); | |
|
292 | QSignalSpy hoverSpy4(s4, SIGNAL(hovered(bool))); | |
|
293 | QTest::mouseMove(view.viewport(), points.at(0)); | |
|
294 | QTest::mouseMove(view.viewport(), points.at(1)); | |
|
295 | QTest::mouseMove(view.viewport(), points.at(2)); | |
|
296 | QTest::mouseMove(view.viewport(), points.at(3)); | |
|
297 | QTest::mouseMove(view.viewport(), pieRect.topLeft().toPoint()); | |
|
298 | ||
|
299 | // check | |
|
300 | QCOMPARE(hoverSpy1.count(), 2); | |
|
301 | QCOMPARE(qvariant_cast<bool>(hoverSpy1.at(0).at(0)), true); | |
|
302 | QCOMPARE(qvariant_cast<bool>(hoverSpy1.at(1).at(0)), false); | |
|
303 | QCOMPARE(hoverSpy2.count(), 2); | |
|
304 | QCOMPARE(qvariant_cast<bool>(hoverSpy2.at(0).at(0)), true); | |
|
305 | QCOMPARE(qvariant_cast<bool>(hoverSpy2.at(1).at(0)), false); | |
|
306 | QCOMPARE(hoverSpy3.count(), 2); | |
|
307 | QCOMPARE(qvariant_cast<bool>(hoverSpy3.at(0).at(0)), true); | |
|
308 | QCOMPARE(qvariant_cast<bool>(hoverSpy3.at(1).at(0)), false); | |
|
309 | QCOMPARE(hoverSpy4.count(), 2); | |
|
310 | QCOMPARE(qvariant_cast<bool>(hoverSpy4.at(0).at(0)), true); | |
|
311 | QCOMPARE(qvariant_cast<bool>(hoverSpy4.at(1).at(0)), false); | |
|
312 | } | |
|
313 | ||
|
314 | QList<QPoint> tst_qpieslice::slicePoints(QRectF rect) | |
|
315 | { | |
|
316 | qreal x1 = rect.topLeft().x() + (rect.width() / 4); | |
|
317 | qreal x2 = rect.topLeft().x() + (rect.width() / 4) * 3; | |
|
318 | qreal y1 = rect.topLeft().y() + (rect.height() / 4); | |
|
319 | qreal y2 = rect.topLeft().y() + (rect.height() / 4) * 3; | |
|
320 | QList<QPoint> points; | |
|
321 | points << QPoint(x2, y1); | |
|
322 | points << QPoint(x2, y2); | |
|
323 | points << QPoint(x1, y2); | |
|
324 | points << QPoint(x1, y1); | |
|
325 | return points; | |
|
291 | 326 | } |
|
292 | 327 | |
|
293 | 328 | QTEST_MAIN(tst_qpieslice) |
General Comments 0
You need to be logged in to leave comments.
Login now