##// 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 Q_UNUSED(event)
37 Q_UNUSED(event)
38 emit clicked(m_barset, m_index);
38 emit clicked(m_barset, m_index);
39 emit clicked(m_index);
39 }
40 }
40
41
41 void Bar::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
42 void Bar::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
42 {
43 {
43 Q_UNUSED(event)
44 Q_UNUSED(event)
44 emit hovered(m_barset, true);
45 emit hovered(m_barset, true);
46 emit hovered(true);
45 }
47 }
46
48
47 void Bar::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
49 void Bar::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
48 {
50 {
49 Q_UNUSED(event)
51 Q_UNUSED(event)
50 emit hovered(m_barset, false);
52 emit hovered(m_barset, false);
53 emit hovered(false);
51 }
54 }
52
55
53 #include "moc_bar_p.cpp"
56 #include "moc_bar_p.cpp"
@@ -52,6 +52,8 public:
52 Q_SIGNALS:
52 Q_SIGNALS:
53 void clicked(QBarSet *barset, int index);
53 void clicked(QBarSet *barset, int index);
54 void hovered(QBarSet *barset, bool status);
54 void hovered(QBarSet *barset, bool status);
55 void clicked(int index);
56 void hovered(bool status);
55
57
56 private:
58 private:
57 int m_index;
59 int m_index;
@@ -196,6 +196,8 void BarChartItem::handleDataStructureChanged()
196 m_bars.append(bar);
196 m_bars.append(bar);
197 connect(bar, SIGNAL(clicked(QBarSet*,int)), m_series, SIGNAL(clicked(QBarSet*,int)));
197 connect(bar, SIGNAL(clicked(QBarSet*,int)), m_series, SIGNAL(clicked(QBarSet*,int)));
198 connect(bar, SIGNAL(hovered(QBarSet*,bool)), m_series, SIGNAL(hovered(QBarSet*,bool)));
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 m_layout.append(QRectF(0, 0, 0, 0));
201 m_layout.append(QRectF(0, 0, 0, 0));
200
202
201 // Labels
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 \fn void QBarSet::labelChanged()
121 \fn void QBarSet::labelChanged()
107 This signal is emitted when the label of the barSet has changed.
122 This signal is emitted when the label of the barSet has changed.
108 \sa label
123 \sa label
@@ -88,6 +88,8 public:
88 void setLabelColor(QColor color);
88 void setLabelColor(QColor color);
89
89
90 Q_SIGNALS:
90 Q_SIGNALS:
91 void clicked(int index);
92 void hovered(bool status);
91 void penChanged();
93 void penChanged();
92 void brushChanged();
94 void brushChanged();
93 void labelChanged();
95 void labelChanged();
@@ -327,6 +327,8 void tst_QBarSeries::mouseclicked()
327 series->append(set2);
327 series->append(set2);
328
328
329 QSignalSpy seriesSpy(series,SIGNAL(clicked(QBarSet*,int)));
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 QChartView view(new QChart());
333 QChartView view(new QChart());
332 view.resize(400,300);
334 view.resize(400,300);
@@ -340,71 +342,107 void tst_QBarSeries::mouseclicked()
340 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
342 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
341
343
342 QCOMPARE(seriesSpy.count(), 1);
344 QCOMPARE(seriesSpy.count(), 1);
345 QCOMPARE(setSpy1.count(), 1);
346 QCOMPARE(setSpy2.count(), 0);
343
347
344 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
348 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
345 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1);
349 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1);
346 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
350 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
347 QVERIFY(seriesSpyArg.at(1).toInt() == 0);
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 // barset 1, bar 1
358 // barset 1, bar 1
351 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(186,142));
359 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(186,142));
352 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
360 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
353
361
354 QCOMPARE(seriesSpy.count(), 1);
362 QCOMPARE(seriesSpy.count(), 1);
363 QCOMPARE(setSpy1.count(), 1);
364 QCOMPARE(setSpy2.count(), 0);
355
365
356 seriesSpyArg = seriesSpy.takeFirst();
366 seriesSpyArg = seriesSpy.takeFirst();
357 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1);
367 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1);
358 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
368 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
359 QVERIFY(seriesSpyArg.at(1).toInt() == 1);
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 // barset 1, bar 2
376 // barset 1, bar 2
363 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(271,142));
377 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(271,142));
364 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
378 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
365
379
366 QCOMPARE(seriesSpy.count(), 1);
380 QCOMPARE(seriesSpy.count(), 1);
381 QCOMPARE(setSpy1.count(), 1);
382 QCOMPARE(setSpy2.count(), 0);
367
383
368 seriesSpyArg = seriesSpy.takeFirst();
384 seriesSpyArg = seriesSpy.takeFirst();
369 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1);
385 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1);
370 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
386 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
371 QVERIFY(seriesSpyArg.at(1).toInt() == 2);
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 // barset 2, bar 0
394 // barset 2, bar 0
375 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(127,142));
395 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(127,142));
376 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
396 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
377
397
378 QCOMPARE(seriesSpy.count(), 1);
398 QCOMPARE(seriesSpy.count(), 1);
399 QCOMPARE(setSpy1.count(), 0);
400 QCOMPARE(setSpy2.count(), 1);
379
401
380 seriesSpyArg = seriesSpy.takeFirst();
402 seriesSpyArg = seriesSpy.takeFirst();
381 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2);
403 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2);
382 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
404 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
383 QVERIFY(seriesSpyArg.at(1).toInt() == 0);
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 // barset 2, bar 1
412 // barset 2, bar 1
387 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(212,142));
413 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(212,142));
388 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
414 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
389
415
390 QCOMPARE(seriesSpy.count(), 1);
416 QCOMPARE(seriesSpy.count(), 1);
417 QCOMPARE(setSpy1.count(), 0);
418 QCOMPARE(setSpy2.count(), 1);
391
419
392 seriesSpyArg = seriesSpy.takeFirst();
420 seriesSpyArg = seriesSpy.takeFirst();
393 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2);
421 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2);
394 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
422 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
395 QVERIFY(seriesSpyArg.at(1).toInt() == 1);
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 // barset 2, bar 2
430 // barset 2, bar 2
399 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(296,142));
431 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(296,142));
400 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
432 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
401
433
402 QCOMPARE(seriesSpy.count(), 1);
434 QCOMPARE(seriesSpy.count(), 1);
435 QCOMPARE(setSpy1.count(), 0);
436 QCOMPARE(setSpy2.count(), 1);
403
437
404 seriesSpyArg = seriesSpy.takeFirst();
438 seriesSpyArg = seriesSpy.takeFirst();
405 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2);
439 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2);
406 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
440 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int);
407 QVERIFY(seriesSpyArg.at(1).toInt() == 2);
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 void tst_QBarSeries::mousehovered_data()
448 void tst_QBarSeries::mousehovered_data()
@@ -425,6 +463,8 void tst_QBarSeries::mousehovered()
425 series->append(set2);
463 series->append(set2);
426
464
427 QSignalSpy seriesSpy(series,SIGNAL(hovered(QBarSet*,bool)));
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 QChartView view(new QChart());
469 QChartView view(new QChart());
430 view.resize(400,300);
470 view.resize(400,300);
@@ -440,21 +480,31 void tst_QBarSeries::mousehovered()
440 QTest::mouseMove(view.viewport(), QPoint(0, 142));
480 QTest::mouseMove(view.viewport(), QPoint(0, 142));
441 QCoreApplication::processEvents(QEventLoop::AllEvents, 10000);
481 QCoreApplication::processEvents(QEventLoop::AllEvents, 10000);
442 TRY_COMPARE(seriesSpy.count(), 0);
482 TRY_COMPARE(seriesSpy.count(), 0);
483 TRY_COMPARE(setSpy1.count(), 0);
484 TRY_COMPARE(setSpy2.count(), 0);
443
485
444 //=======================================================================
486 //=======================================================================
445 // move mouse on top of set1
487 // move mouse on top of set1
446 QTest::mouseMove(view.viewport(), QPoint(102,142));
488 QTest::mouseMove(view.viewport(), QPoint(102,142));
447 TRY_COMPARE(seriesSpy.count(), 1);
489 TRY_COMPARE(seriesSpy.count(), 1);
490 TRY_COMPARE(setSpy1.count(), 1);
491 TRY_COMPARE(setSpy2.count(), 0);
448
492
449 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
493 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
450 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1);
494 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1);
451 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool);
495 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool);
452 QVERIFY(seriesSpyArg.at(1).toBool() == true);
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 // move mouse from top of set1 to top of set2
503 // move mouse from top of set1 to top of set2
456 QTest::mouseMove(view.viewport(), QPoint(127,142));
504 QTest::mouseMove(view.viewport(), QPoint(127,142));
457 TRY_COMPARE(seriesSpy.count(), 2);
505 TRY_COMPARE(seriesSpy.count(), 2);
506 TRY_COMPARE(setSpy1.count(), 1);
507 TRY_COMPARE(setSpy2.count(), 1);
458
508
459 // should leave set1
509 // should leave set1
460 seriesSpyArg = seriesSpy.takeFirst();
510 seriesSpyArg = seriesSpy.takeFirst();
@@ -462,22 +512,36 void tst_QBarSeries::mousehovered()
462 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool);
512 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool);
463 QVERIFY(seriesSpyArg.at(1).toBool() == false);
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 // should enter set2
519 // should enter set2
466 seriesSpyArg = seriesSpy.takeFirst();
520 seriesSpyArg = seriesSpy.takeFirst();
467 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2);
521 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2);
468 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool);
522 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool);
469 QVERIFY(seriesSpyArg.at(1).toBool() == true);
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 // move mouse from top of set2 to background
530 // move mouse from top of set2 to background
473 QTest::mouseMove(view.viewport(), QPoint(127,0));
531 QTest::mouseMove(view.viewport(), QPoint(127,0));
474 TRY_COMPARE(seriesSpy.count(), 1);
532 TRY_COMPARE(seriesSpy.count(), 1);
533 TRY_COMPARE(setSpy1.count(), 0);
534 TRY_COMPARE(setSpy2.count(), 1);
475
535
476 // should leave set2
536 // should leave set2
477 seriesSpyArg = seriesSpy.takeFirst();
537 seriesSpyArg = seriesSpy.takeFirst();
478 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2);
538 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2);
479 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool);
539 QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool);
480 QVERIFY(seriesSpyArg.at(1).toBool() == false);
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 void tst_QBarSeries::clearWithAnimations()
547 void tst_QBarSeries::clearWithAnimations()
General Comments 0
You need to be logged in to leave comments. Login now