##// END OF EJS Templates
fix: series visible now affects legend items also
sauimone -
r1459:e9693669a76b
parent child
Show More
@@ -22,10 +22,6
22 22
23 23 #include <QApplication>
24 24 #include <QMainWindow>
25 #include <QChartView>
26 #include <QBarSeries>
27 #include <QBarSet>
28 #include <QLegend>
29 25
30 26 QTCOMMERCIALCHART_USE_NAMESPACE
31 27
@@ -30,6 +30,7
30 30 #include <QGraphicsGridLayout>
31 31 #include <QDoubleSpinBox>
32 32 #include <QGroupBox>
33 #include <QBarSeries>
33 34
34 35 QTCOMMERCIALCHART_USE_NAMESPACE
35 36
@@ -459,6 +459,7 void QLegendPrivate::updateLayout()
459 459 QPointF point = m_rect.topLeft();
460 460 m_width = 0;
461 461 foreach (QGraphicsItem *item, items) {
462 if (item->isVisible()) {
462 463 item->setPos(point.x(),m_rect.height()/2 -item->boundingRect().height()/2);
463 464 const QRectF& rect = item->boundingRect();
464 465 qreal w = rect.width();
@@ -467,6 +468,7 void QLegendPrivate::updateLayout()
467 468 m_width+=w;
468 469 point.setX(point.x() + w);
469 470 }
471 }
470 472 if(m_width<m_rect.width()) {
471 473 m_markers->setPos(m_rect.width()/2-m_width/2,m_rect.top());
472 474 }
@@ -481,6 +483,7 void QLegendPrivate::updateLayout()
481 483 QPointF point = m_rect.topLeft();
482 484 m_height = 0;
483 485 foreach (QGraphicsItem *item, items) {
486 if (item->isVisible()) {
484 487 item->setPos(point);
485 488 const QRectF& rect = item->boundingRect();
486 489 qreal h = rect.height();
@@ -489,6 +492,7 void QLegendPrivate::updateLayout()
489 492 m_height+=h;
490 493 point.setY(point.y() + h);
491 494 }
495 }
492 496 if(m_height<m_rect.height()) {
493 497 m_markers->setPos(m_rect.left(),m_rect.height()/2-m_height/2);
494 498 }
@@ -530,6 +534,7 void QLegendPrivate::updateDetachedLayout()
530 534 m_height = 0;
531 535 for (int i=0; i<items.count(); i++) {
532 536 QGraphicsItem *item = items.at(i);
537 if (item->isVisible()) {
533 538 const QRectF& rect = item->boundingRect();
534 539 qreal w = rect.width();
535 540 qreal h = rect.height();
@@ -547,6 +552,7 void QLegendPrivate::updateDetachedLayout()
547 552 }
548 553 }
549 554 }
555 }
550 556 m_markers->setPos(m_rect.topLeft());
551 557 m_width = m_minWidth;
552 558
@@ -562,6 +568,7 void QLegendPrivate::updateDetachedLayout()
562 568 m_height = 0;
563 569 for (int i=0; i<items.count(); i++) {
564 570 QGraphicsItem *item = items.at(i);
571 if (item->isVisible()) {
565 572 const QRectF& rect = item->boundingRect();
566 573 qreal w = rect.width();
567 574 qreal h = rect.height();
@@ -579,6 +586,7 void QLegendPrivate::updateDetachedLayout()
579 586 }
580 587 }
581 588 }
589 }
582 590 m_markers->setPos(m_rect.topLeft());
583 591 m_width = m_minWidth;
584 592
@@ -595,6 +603,7 void QLegendPrivate::updateDetachedLayout()
595 603 qreal maxWidth = 0;
596 604 for (int i=0; i<items.count(); i++) {
597 605 QGraphicsItem *item = items.at(i);
606 if (item->isVisible()) {
598 607 const QRectF& rect = item->boundingRect();
599 608 qreal w = rect.width();
600 609 qreal h = rect.height();
@@ -613,6 +622,7 void QLegendPrivate::updateDetachedLayout()
613 622 }
614 623 }
615 624 }
625 }
616 626 m_width += maxWidth;
617 627 m_markers->setPos(m_rect.topLeft());
618 628 m_height = m_minHeight;
@@ -630,6 +640,7 void QLegendPrivate::updateDetachedLayout()
630 640 qreal maxWidth = 0;
631 641 for (int i=0; i<items.count(); i++) {
632 642 QGraphicsItem *item = items.at(i);
643 if (item->isVisible()) {
633 644 const QRectF& rect = item->boundingRect();
634 645 qreal w = rect.width();
635 646 qreal h = rect.height();
@@ -648,6 +659,7 void QLegendPrivate::updateDetachedLayout()
648 659 }
649 660 }
650 661 }
662 }
651 663 m_width += maxWidth;
652 664 m_markers->setPos(m_rect.topLeft());
653 665 m_height = m_minHeight;
@@ -682,6 +694,8 void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series, Domain *domain)
682 694 foreach(LegendMarker* marker, markers)
683 695 m_markers->addToGroup(marker);
684 696
697 QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
698
685 699 if(series->type() == QAbstractSeries::SeriesTypePie) {
686 700 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
687 701 QObject::connect(pieSeries, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries()));
@@ -730,6 +744,21 void QLegendPrivate::handleUpdatePieSeries()
730 744 handleSeriesAdded(series, 0);
731 745 }
732 746
747 void QLegendPrivate::handleSeriesVisibleChanged()
748 {
749 QAbstractSeries* series = qobject_cast<QAbstractSeries *> (sender());
750 QList<QGraphicsItem *> items = m_markers->childItems();
751
752 foreach (QGraphicsItem *markers, items) {
753 LegendMarker *marker = static_cast<LegendMarker*>(markers);
754 if (marker->series() == series) {
755 marker->setVisible(!marker->isVisible());
756 }
757 }
758
759 updateLayout();
760 }
761
733 762
734 763 #include "moc_qlegend.cpp"
735 764 #include "moc_qlegend_p.cpp"
@@ -57,6 +57,7 public Q_SLOTS:
57 57 void handleSeriesRemoved(QAbstractSeries *series);
58 58 void handleSeriesUpdated(QAbstractSeries *series);
59 59 void handleUpdatePieSeries(); //TODO remove this function
60 void handleSeriesVisibleChanged();
60 61
61 62 private:
62 63 QLegend *q_ptr;
General Comments 0
You need to be logged in to leave comments. Login now