##// END OF EJS Templates
some cleanup on legend and pie. No need for pie to know too much about legend
sauimone -
r2173:8e5e86b8b162
parent child
Show More
@@ -743,6 +743,7 bool QAbstractBarSeriesPrivate::remove(QList<QBarSet * > sets)
743 }
743 }
744
744
745 emit restructuredBars(); // this notifies barchartitem
745 emit restructuredBars(); // this notifies barchartitem
746
746 return true;
747 return true;
747 }
748 }
748
749
@@ -28,7 +28,6
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
30
31 //LegendMarkerItem::LegendMarkerItem(QAbstractSeries *series, QGraphicsObject *parent) :
32 LegendMarkerItem::LegendMarkerItem(QLegendMarkerPrivate *marker, QGraphicsObject *parent) :
31 LegendMarkerItem::LegendMarkerItem(QLegendMarkerPrivate *marker, QGraphicsObject *parent) :
33 QGraphicsObject(parent),
32 QGraphicsObject(parent),
34 m_marker(marker),
33 m_marker(marker),
@@ -160,7 +159,6 QSizeF LegendMarkerItem::sizeHint(Qt::SizeHint which, const QSizeF& constraint)
160
159
161 void LegendMarkerItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
160 void LegendMarkerItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
162 {
161 {
163 qDebug() << "LegendMarkerItem::mousePressEvent";
164 // QGraphicsObject::mousePressEvent(event);
162 // QGraphicsObject::mousePressEvent(event);
165 //TODO: selected signal removed for now
163 //TODO: selected signal removed for now
166 m_marker->handleMousePressEvent(event);
164 m_marker->handleMousePressEvent(event);
@@ -176,7 +176,7 QLegend::QLegend(QChart *chart): QGraphicsWidget(chart),
176 {
176 {
177 setZValue(ChartPresenter::LegendZValue);
177 setZValue(ChartPresenter::LegendZValue);
178 setFlags(QGraphicsItem::ItemClipsChildrenToShape);
178 setFlags(QGraphicsItem::ItemClipsChildrenToShape);
179 QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*)), d_ptr.data(), SLOT(handleSeriesAdded(QAbstractSeries*/*,Domain**/)));
179 QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*)), d_ptr.data(), SLOT(handleSeriesAdded(QAbstractSeries*)));
180 QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), d_ptr.data(), SLOT(handleSeriesRemoved(QAbstractSeries*)));
180 QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), d_ptr.data(), SLOT(handleSeriesRemoved(QAbstractSeries*)));
181 // QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesUpdated(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesUpdated(QAbstractSeries*)));
181 // QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesUpdated(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesUpdated(QAbstractSeries*)));
182 setLayout(d_ptr->m_layout);
182 setLayout(d_ptr->m_layout);
@@ -477,25 +477,10 int QLegendPrivate::roundness(qreal size)
477 void QLegendPrivate::appendSeries(QAbstractSeries* series)
477 void QLegendPrivate::appendSeries(QAbstractSeries* series)
478 {
478 {
479 // Only allow one instance of series
479 // Only allow one instance of series
480 if (!m_series.contains(series)) {
481 m_series.append(series);
482 handleSeriesAdded(series/*,0*/);
483 }
484 }
485
486 void QLegendPrivate::removeSeries(QAbstractSeries* series)
487 {
488 if (m_series.contains(series)) {
480 if (m_series.contains(series)) {
489 m_series.removeOne(series);
481 qDebug() << "series already added" << series;
490 handleSeriesRemoved(series);
482 return;
491 }
483 }
492 }
493
494 void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series/*, Domain *domain*/)
495 {
496 // Q_UNUSED(domain)
497
498 qDebug() << "QLegendPrivate::handleSeriesAdded" << series;
499
484
500 QList<QLegendMarker*> newMarkers = series->d_ptr->createLegendMarkers(q_ptr);
485 QList<QLegendMarker*> newMarkers = series->d_ptr->createLegendMarkers(q_ptr);
501 foreach (QLegendMarker* marker, newMarkers) {
486 foreach (QLegendMarker* marker, newMarkers) {
@@ -506,16 +491,49 void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series/*, Domain *domain
506 m_legendMarkers << marker;
491 m_legendMarkers << marker;
507 }
492 }
508
493
494 // TODO: This is the part I don't like. There should be better solution.
495 // On the other hand. It is only one switch case for appending and another for removing series
496 // If countChanged signal were on QAbstractSeries, there would be no need for switch at all.
497 switch (series->type())
498 {
499 case QAbstractSeries::SeriesTypePie: {
500 QPieSeries *s = qobject_cast<QPieSeries *> (series);
501 QObject::connect(s, SIGNAL(countChanged()), this, SLOT(handleSeriesUpdated()));
502 break;
503 }
504 case QAbstractSeries::SeriesTypeBar:
505 case QAbstractSeries::SeriesTypeStackedBar:
506 case QAbstractSeries::SeriesTypePercentBar:
507 case QAbstractSeries::SeriesTypeHorizontalBar:
508 case QAbstractSeries::SeriesTypeHorizontalStackedBar:
509 case QAbstractSeries::SeriesTypeHorizontalPercentBar: {
510 QAbstractBarSeries *s = qobject_cast<QAbstractBarSeries *> (series);
511 QObject::connect(s, SIGNAL(countChanged()), this, SLOT(handleSeriesUpdated()));
512 break;
513 }
514 // TODO:
515 case QAbstractSeries::SeriesTypeLine:
516 case QAbstractSeries::SeriesTypeArea:
517 case QAbstractSeries::SeriesTypeScatter:
518 case QAbstractSeries::SeriesTypeSpline:
519 default: {
520 // No need to connect any series related signals?
521 qDebug() << "Not yet implemented";
522 }
523 }
524
509 QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
525 QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
510 // QObject::connect(series->d_ptr.data(), SIGNAL(legendPropertiesUpdated(QAbstractSeries*)), this, SLOT(handleLegendPropertiesUpdated(QAbstractSeries*)));
511
526
527 m_series.append(series);
512 m_items->setVisible(false);
528 m_items->setVisible(false);
513 m_layout->invalidate();
529 m_layout->invalidate();
514 }
530 }
515
531
516 void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series)
532 void QLegendPrivate::removeSeries(QAbstractSeries* series)
517 {
533 {
518 qDebug() << "QLegendPrivate::handleSeriesRemoved" << series;
534 if (m_series.contains(series)) {
535 m_series.removeOne(series);
536 }
519
537
520 foreach (QLegendMarker *marker, m_legendMarkers) {
538 foreach (QLegendMarker *marker, m_legendMarkers) {
521 if (marker->series() == series) {
539 if (marker->series() == series) {
@@ -526,10 +544,54 void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series)
526 }
544 }
527 }
545 }
528
546
547 switch (series->type())
548 {
549 case QAbstractSeries::SeriesTypePie: {
550 QPieSeries *s = qobject_cast<QPieSeries *> (series);
551 QObject::disconnect(s, SIGNAL(countChanged()), this, SLOT(handleSeriesUpdated()));
552 break;
553 }
554 case QAbstractSeries::SeriesTypeBar:
555 case QAbstractSeries::SeriesTypeStackedBar:
556 case QAbstractSeries::SeriesTypePercentBar:
557 case QAbstractSeries::SeriesTypeHorizontalBar:
558 case QAbstractSeries::SeriesTypeHorizontalStackedBar:
559 case QAbstractSeries::SeriesTypeHorizontalPercentBar: {
560 QAbstractBarSeries *s = qobject_cast<QAbstractBarSeries *> (series);
561 QObject::disconnect(s, SIGNAL(countChanged()), this, SLOT(handleSeriesUpdated()));
562 break;
563 }
564 // TODO:
565 case QAbstractSeries::SeriesTypeLine:
566 case QAbstractSeries::SeriesTypeArea:
567 case QAbstractSeries::SeriesTypeScatter:
568 case QAbstractSeries::SeriesTypeSpline:
569 default: {
570 // No need to disconnect any series related signals?
571 break;
572 }
573 }
574
575
529 QObject::disconnect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
576 QObject::disconnect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
530 // QObject::disconnect(series->d_ptr.data(), SIGNAL(legendPropertiesUpdated(QAbstractSeries*)), this, SLOT(handleLegendPropertiesUpdated(QAbstractSeries*)));
577 // QObject::disconnect(series->d_ptr.data(), SIGNAL(legendPropertiesUpdated(QAbstractSeries*)), this, SLOT(handleLegendPropertiesUpdated(QAbstractSeries*)));
531
578
532 m_layout->invalidate();
579 m_layout->invalidate();
580 // q_ptr->layout()->activate();
581 }
582
583 void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series)
584 {
585 // Moved to appendSeries
586 // This slot is just to make old code work for now.
587 appendSeries(series);
588 }
589
590 void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series)
591 {
592 // Moved to removeSeries
593 // This slot is just to make old code work for now.
594 removeSeries(series);
533 }
595 }
534
596
535 void QLegendPrivate::handleSeriesVisibleChanged()
597 void QLegendPrivate::handleSeriesVisibleChanged()
@@ -548,14 +610,15 void QLegendPrivate::handleSeriesVisibleChanged()
548 void QLegendPrivate::handleCountChanged()
610 void QLegendPrivate::handleCountChanged()
549 {
611 {
550 // TODO: With new markers, the series should notify markers directly.
612 // TODO: With new markers, the series should notify markers directly.
551 // TODO: This is not a good way to handle updates.
613 // TODO: Better way to handle updates
552 qDebug() << "handleLegendPropertiesUpdated" << series;
614
615 QAbstractSeries *series = qobject_cast<QAbstractSeries *> (sender());
616 qDebug() << "QLegendPrivate::handleSeriesUpdated" << series;
553
617
554 // Handle new or removed markers
618 // Handle new or removed markers
555 // Handle changes of marker pen/brush/label. every property that legend is interested
619 // Handle changes of marker pen/brush/label. every property that legend is interested
556 handleSeriesRemoved(series);
620 handleSeriesRemoved(series);
557 // Domain domain;
621 handleSeriesAdded(series);
558 handleSeriesAdded(series/*, &domain*/);
559 }
622 }
560
623
561 #include "moc_qlegend.cpp"
624 #include "moc_qlegend.cpp"
@@ -62,7 +62,7 public:
62 void removeSeries(QAbstractSeries* series);
62 void removeSeries(QAbstractSeries* series);
63
63
64 public Q_SLOTS:
64 public Q_SLOTS:
65 void handleSeriesAdded(QAbstractSeries *series/*, Domain *domain*/);
65 void handleSeriesAdded(QAbstractSeries *series);
66 void handleSeriesRemoved(QAbstractSeries *series);
66 void handleSeriesRemoved(QAbstractSeries *series);
67 void handleSeriesVisibleChanged();
67 void handleSeriesVisibleChanged();
68 void handleCountChanged();
68 void handleCountChanged();
@@ -61,9 +61,7 QPieLegendMarkerPrivate::QPieLegendMarkerPrivate(QPieLegendMarker *q, QPieSeries
61 QLegendMarkerPrivate(q,legend),
61 QLegendMarkerPrivate(q,legend),
62 m_series(series),
62 m_series(series),
63 m_slice(slice)
63 m_slice(slice)
64 // m_legend(legend)
65 {
64 {
66 // qDebug() << "QPieLegendMarkerPrivate created";
67 QObject::connect(m_slice, SIGNAL(labelChanged()), this, SLOT(updated()));
65 QObject::connect(m_slice, SIGNAL(labelChanged()), this, SLOT(updated()));
68 QObject::connect(m_slice, SIGNAL(brushChanged()), this, SLOT(updated()));
66 QObject::connect(m_slice, SIGNAL(brushChanged()), this, SLOT(updated()));
69 updated();
67 updated();
@@ -77,7 +75,6 QPieLegendMarkerPrivate::~QPieLegendMarkerPrivate()
77
75
78 void QPieLegendMarkerPrivate::updated()
76 void QPieLegendMarkerPrivate::updated()
79 {
77 {
80 // qDebug() << "QPieLegendMarkerPrivate::updated";
81 m_item->setBrush(m_slice->brush());
78 m_item->setBrush(m_slice->brush());
82 m_item->setLabel(m_slice->label());
79 m_item->setLabel(m_slice->label());
83 m_item->setPen(m_slice->pen());
80 m_item->setPen(m_slice->pen());
@@ -28,6 +28,7
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
30
31 // TODO: No export, make this private. QLegendMarker should be enough for user of the api (why expose the details?)
31 class QTCOMMERCIALCHART_EXPORT QPieLegendMarker : public QLegendMarker
32 class QTCOMMERCIALCHART_EXPORT QPieLegendMarker : public QLegendMarker
32 {
33 {
33 Q_OBJECT
34 Q_OBJECT
@@ -474,7 +474,6 bool QPieSeries::insert(int index, QPieSlice *slice)
474 connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked()));
474 connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked()));
475 connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
475 connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
476
476
477
478 emit added(QList<QPieSlice *>() << slice);
477 emit added(QList<QPieSlice *>() << slice);
479 emit countChanged();
478 emit countChanged();
480
479
General Comments 0
You need to be logged in to leave comments. Login now