##// END OF EJS Templates
reintroducing clicked and hovered signals to barset. Makes some things easier on QML api
sauimone -
r1490:b134c8a9174e
parent child
Show More
@@ -36,18 +36,21 void Bar::mousePressEvent(QGraphicsSceneMouseEvent *event)
36 36 {
37 37 Q_UNUSED(event)
38 38 emit clicked(m_barset, m_index);
39 emit clicked(m_index);
39 40 }
40 41
41 42 void Bar::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
42 43 {
43 44 Q_UNUSED(event)
44 45 emit hovered(m_barset, true);
46 emit hovered(true);
45 47 }
46 48
47 49 void Bar::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
48 50 {
49 51 Q_UNUSED(event)
50 52 emit hovered(m_barset, false);
53 emit hovered(false);
51 54 }
52 55
53 56 #include "moc_bar_p.cpp"
@@ -52,6 +52,8 public:
52 52 Q_SIGNALS:
53 53 void clicked(QBarSet *barset, int index);
54 54 void hovered(QBarSet *barset, bool status);
55 void clicked(int index);
56 void hovered(bool status);
55 57
56 58 private:
57 59 int m_index;
@@ -196,6 +196,8 void BarChartItem::handleDataStructureChanged()
196 196 m_bars.append(bar);
197 197 connect(bar, SIGNAL(clicked(QBarSet*,int)), m_series, SIGNAL(clicked(QBarSet*,int)));
198 198 connect(bar, SIGNAL(hovered(QBarSet*,bool)), m_series, SIGNAL(hovered(QBarSet*,bool)));
199 connect(bar, SIGNAL(clicked(int)), set, SIGNAL(clicked(int)));
200 connect(bar, SIGNAL(hovered(bool)), set, SIGNAL(hovered(bool)));
199 201 m_layout.append(QRectF(0, 0, 0, 0));
200 202
201 203 // Labels
@@ -103,6 +103,21 QTCOMMERCIALCHART_BEGIN_NAMESPACE
103 103 */
104 104
105 105 /*!
106 \fn void QBarSet::clicked(int index)
107
108 The signal is emitted if the user clicks with a mouse on top of barset.
109 Clicked bar inside set is indexed by \a index
110 */
111
112 /*!
113 \fn void QBarSet::hovered(bool status)
114
115 The signal is emitted if mouse is hovered on top of barset.
116 Parameter \a status is true, if mouse entered on top of barset, false if mouse left from top of barset.
117 */
118
119
120 /*!
106 121 \fn void QBarSet::labelChanged()
107 122 This signal is emitted when the label of the barSet has changed.
108 123 \sa label
@@ -88,6 +88,8 public:
88 88 void setLabelColor(QColor color);
89 89
90 90 Q_SIGNALS:
91 void clicked(int index);
92 void hovered(bool status);
91 93 void penChanged();
92 94 void brushChanged();
93 95 void labelChanged();
@@ -327,6 +327,8 void tst_QBarSeries::mouseclicked()
327 327 series->append(set2);
328 328
329 329 QSignalSpy seriesSpy(series,SIGNAL(clicked(QBarSet*,int)));
330 QSignalSpy setSpy1(set1, SIGNAL(clicked(int)));
331 QSignalSpy setSpy2(set2, SIGNAL(clicked(int)));
330 332
331 333 QChartView view(new QChart());
332 334 view.resize(400,300);
@@ -340,71 +342,107 void tst_QBarSeries::mouseclicked()
340 342 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
341 343
342 344 QCOMPARE(seriesSpy.count(), 1);
345 QCOMPARE(setSpy1.count(), 1);
346 QCOMPARE(setSpy2.count(), 0);
343 347
344 348 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
345 349 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1);
346 350 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
347 351 QVERIFY(seriesSpyArg.at(1).toInt() == 0);
348 352
353 QList<QVariant> setSpyArg = setSpy1.takeFirst();
354 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
355 QVERIFY(setSpyArg.at(0).toInt() == 0);
356
349 357 //====================================================================================
350 358 // barset 1, bar 1
351 359 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(186,142));
352 360 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
353 361
354 362 QCOMPARE(seriesSpy.count(), 1);
363 QCOMPARE(setSpy1.count(), 1);
364 QCOMPARE(setSpy2.count(), 0);
355 365
356 366 seriesSpyArg = seriesSpy.takeFirst();
357 367 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1);
358 368 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
359 369 QVERIFY(seriesSpyArg.at(1).toInt() == 1);
360 370
371 setSpyArg = setSpy1.takeFirst();
372 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
373 QVERIFY(setSpyArg.at(0).toInt() == 1);
374
361 375 //====================================================================================
362 376 // barset 1, bar 2
363 377 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(271,142));
364 378 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
365 379
366 380 QCOMPARE(seriesSpy.count(), 1);
381 QCOMPARE(setSpy1.count(), 1);
382 QCOMPARE(setSpy2.count(), 0);
367 383
368 384 seriesSpyArg = seriesSpy.takeFirst();
369 385 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1);
370 386 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
371 387 QVERIFY(seriesSpyArg.at(1).toInt() == 2);
372 388
389 setSpyArg = setSpy1.takeFirst();
390 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
391 QVERIFY(setSpyArg.at(0).toInt() == 2);
392
373 393 //====================================================================================
374 394 // barset 2, bar 0
375 395 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(127,142));
376 396 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
377 397
378 398 QCOMPARE(seriesSpy.count(), 1);
399 QCOMPARE(setSpy1.count(), 0);
400 QCOMPARE(setSpy2.count(), 1);
379 401
380 402 seriesSpyArg = seriesSpy.takeFirst();
381 403 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2);
382 404 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
383 405 QVERIFY(seriesSpyArg.at(1).toInt() == 0);
384 406
407 setSpyArg = setSpy2.takeFirst();
408 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
409 QVERIFY(setSpyArg.at(0).toInt() == 0);
410
385 411 //====================================================================================
386 412 // barset 2, bar 1
387 413 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(212,142));
388 414 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
389 415
390 416 QCOMPARE(seriesSpy.count(), 1);
417 QCOMPARE(setSpy1.count(), 0);
418 QCOMPARE(setSpy2.count(), 1);
391 419
392 420 seriesSpyArg = seriesSpy.takeFirst();
393 421 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2);
394 422 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
395 423 QVERIFY(seriesSpyArg.at(1).toInt() == 1);
396 424
425 setSpyArg = setSpy2.takeFirst();
426 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
427 QVERIFY(setSpyArg.at(0).toInt() == 1);
428
397 429 //====================================================================================
398 430 // barset 2, bar 2
399 431 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(296,142));
400 432 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
401 433
402 434 QCOMPARE(seriesSpy.count(), 1);
435 QCOMPARE(setSpy1.count(), 0);
436 QCOMPARE(setSpy2.count(), 1);
403 437
404 438 seriesSpyArg = seriesSpy.takeFirst();
405 439 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2);
406 440 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
407 441 QVERIFY(seriesSpyArg.at(1).toInt() == 2);
442
443 setSpyArg = setSpy2.takeFirst();
444 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
445 QVERIFY(setSpyArg.at(0).toInt() == 2);
408 446 }
409 447
410 448 void tst_QBarSeries::mousehovered_data()
@@ -425,6 +463,8 void tst_QBarSeries::mousehovered()
425 463 series->append(set2);
426 464
427 465 QSignalSpy seriesSpy(series,SIGNAL(hovered(QBarSet*,bool)));
466 QSignalSpy setSpy1(set1, SIGNAL(hovered(bool)));
467 QSignalSpy setSpy2(set2, SIGNAL(hovered(bool)));
428 468
429 469 QChartView view(new QChart());
430 470 view.resize(400,300);
@@ -440,21 +480,31 void tst_QBarSeries::mousehovered()
440 480 QTest::mouseMove(view.viewport(), QPoint(0, 142));
441 481 QCoreApplication::processEvents(QEventLoop::AllEvents, 10000);
442 482 TRY_COMPARE(seriesSpy.count(), 0);
483 TRY_COMPARE(setSpy1.count(), 0);
484 TRY_COMPARE(setSpy2.count(), 0);
443 485
444 486 //=======================================================================
445 487 // move mouse on top of set1
446 488 QTest::mouseMove(view.viewport(), QPoint(102,142));
447 489 TRY_COMPARE(seriesSpy.count(), 1);
490 TRY_COMPARE(setSpy1.count(), 1);
491 TRY_COMPARE(setSpy2.count(), 0);
448 492
449 493 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
450 494 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1);
451 495 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool);
452 496 QVERIFY(seriesSpyArg.at(1).toBool() == true);
453 497
498 QList<QVariant> setSpyArg = setSpy1.takeFirst();
499 QVERIFY(setSpyArg.at(0).type() == QVariant::Bool);
500 QVERIFY(setSpyArg.at(0).toBool() == true);
501
454 502 //=======================================================================
455 503 // move mouse from top of set1 to top of set2
456 504 QTest::mouseMove(view.viewport(), QPoint(127,142));
457 505 TRY_COMPARE(seriesSpy.count(), 2);
506 TRY_COMPARE(setSpy1.count(), 1);
507 TRY_COMPARE(setSpy2.count(), 1);
458 508
459 509 // should leave set1
460 510 seriesSpyArg = seriesSpy.takeFirst();
@@ -462,22 +512,36 void tst_QBarSeries::mousehovered()
462 512 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool);
463 513 QVERIFY(seriesSpyArg.at(1).toBool() == false);
464 514
515 setSpyArg = setSpy1.takeFirst();
516 QVERIFY(setSpyArg.at(0).type() == QVariant::Bool);
517 QVERIFY(setSpyArg.at(0).toBool() == false);
518
465 519 // should enter set2
466 520 seriesSpyArg = seriesSpy.takeFirst();
467 521 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2);
468 522 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool);
469 523 QVERIFY(seriesSpyArg.at(1).toBool() == true);
470 524
525 setSpyArg = setSpy2.takeFirst();
526 QVERIFY(setSpyArg.at(0).type() == QVariant::Bool);
527 QVERIFY(setSpyArg.at(0).toBool() == true);
528
471 529 //=======================================================================
472 530 // move mouse from top of set2 to background
473 531 QTest::mouseMove(view.viewport(), QPoint(127,0));
474 532 TRY_COMPARE(seriesSpy.count(), 1);
533 TRY_COMPARE(setSpy1.count(), 0);
534 TRY_COMPARE(setSpy2.count(), 1);
475 535
476 536 // should leave set2
477 537 seriesSpyArg = seriesSpy.takeFirst();
478 538 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2);
479 539 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool);
480 540 QVERIFY(seriesSpyArg.at(1).toBool() == false);
541
542 setSpyArg = setSpy2.takeFirst();
543 QVERIFY(setSpyArg.at(0).type() == QVariant::Bool);
544 QVERIFY(setSpyArg.at(0).toBool() == false);
481 545 }
482 546
483 547 void tst_QBarSeries::clearWithAnimations()
General Comments 0
You need to be logged in to leave comments. Login now