diff --git a/src/barchart/qabstractbarseries.cpp b/src/barchart/qabstractbarseries.cpp index 06af863..1749389 100644 --- a/src/barchart/qabstractbarseries.cpp +++ b/src/barchart/qabstractbarseries.cpp @@ -743,6 +743,7 @@ bool QAbstractBarSeriesPrivate::remove(QList sets) } emit restructuredBars(); // this notifies barchartitem + return true; } diff --git a/src/legend/legendmarkeritem.cpp b/src/legend/legendmarkeritem.cpp index 2436983..4117ff1 100644 --- a/src/legend/legendmarkeritem.cpp +++ b/src/legend/legendmarkeritem.cpp @@ -28,7 +28,6 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE -//LegendMarkerItem::LegendMarkerItem(QAbstractSeries *series, QGraphicsObject *parent) : LegendMarkerItem::LegendMarkerItem(QLegendMarkerPrivate *marker, QGraphicsObject *parent) : QGraphicsObject(parent), m_marker(marker), @@ -160,7 +159,6 @@ QSizeF LegendMarkerItem::sizeHint(Qt::SizeHint which, const QSizeF& constraint) void LegendMarkerItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { - qDebug() << "LegendMarkerItem::mousePressEvent"; // QGraphicsObject::mousePressEvent(event); //TODO: selected signal removed for now m_marker->handleMousePressEvent(event); diff --git a/src/legend/qlegend.cpp b/src/legend/qlegend.cpp index 8b5104e..413024a 100644 --- a/src/legend/qlegend.cpp +++ b/src/legend/qlegend.cpp @@ -176,7 +176,7 @@ QLegend::QLegend(QChart *chart): QGraphicsWidget(chart), { setZValue(ChartPresenter::LegendZValue); setFlags(QGraphicsItem::ItemClipsChildrenToShape); - QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*)), d_ptr.data(), SLOT(handleSeriesAdded(QAbstractSeries*/*,Domain**/))); + QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*)), d_ptr.data(), SLOT(handleSeriesAdded(QAbstractSeries*))); QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), d_ptr.data(), SLOT(handleSeriesRemoved(QAbstractSeries*))); // QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesUpdated(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesUpdated(QAbstractSeries*))); setLayout(d_ptr->m_layout); @@ -477,25 +477,10 @@ int QLegendPrivate::roundness(qreal size) void QLegendPrivate::appendSeries(QAbstractSeries* series) { // Only allow one instance of series - if (!m_series.contains(series)) { - m_series.append(series); - handleSeriesAdded(series/*,0*/); - } -} - -void QLegendPrivate::removeSeries(QAbstractSeries* series) -{ if (m_series.contains(series)) { - m_series.removeOne(series); - handleSeriesRemoved(series); + qDebug() << "series already added" << series; + return; } -} - -void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series/*, Domain *domain*/) -{ -// Q_UNUSED(domain) - - qDebug() << "QLegendPrivate::handleSeriesAdded" << series; QList newMarkers = series->d_ptr->createLegendMarkers(q_ptr); foreach (QLegendMarker* marker, newMarkers) { @@ -506,16 +491,49 @@ void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series/*, Domain *domain m_legendMarkers << marker; } + // TODO: This is the part I don't like. There should be better solution. + // On the other hand. It is only one switch case for appending and another for removing series + // If countChanged signal were on QAbstractSeries, there would be no need for switch at all. + switch (series->type()) + { + case QAbstractSeries::SeriesTypePie: { + QPieSeries *s = qobject_cast (series); + QObject::connect(s, SIGNAL(countChanged()), this, SLOT(handleSeriesUpdated())); + break; + } + case QAbstractSeries::SeriesTypeBar: + case QAbstractSeries::SeriesTypeStackedBar: + case QAbstractSeries::SeriesTypePercentBar: + case QAbstractSeries::SeriesTypeHorizontalBar: + case QAbstractSeries::SeriesTypeHorizontalStackedBar: + case QAbstractSeries::SeriesTypeHorizontalPercentBar: { + QAbstractBarSeries *s = qobject_cast (series); + QObject::connect(s, SIGNAL(countChanged()), this, SLOT(handleSeriesUpdated())); + break; + } + // TODO: + case QAbstractSeries::SeriesTypeLine: + case QAbstractSeries::SeriesTypeArea: + case QAbstractSeries::SeriesTypeScatter: + case QAbstractSeries::SeriesTypeSpline: + default: { + // No need to connect any series related signals? + qDebug() << "Not yet implemented"; + } + } + QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); -// QObject::connect(series->d_ptr.data(), SIGNAL(legendPropertiesUpdated(QAbstractSeries*)), this, SLOT(handleLegendPropertiesUpdated(QAbstractSeries*))); + m_series.append(series); m_items->setVisible(false); m_layout->invalidate(); } -void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series) +void QLegendPrivate::removeSeries(QAbstractSeries* series) { - qDebug() << "QLegendPrivate::handleSeriesRemoved" << series; + if (m_series.contains(series)) { + m_series.removeOne(series); + } foreach (QLegendMarker *marker, m_legendMarkers) { if (marker->series() == series) { @@ -526,10 +544,54 @@ void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series) } } + switch (series->type()) + { + case QAbstractSeries::SeriesTypePie: { + QPieSeries *s = qobject_cast (series); + QObject::disconnect(s, SIGNAL(countChanged()), this, SLOT(handleSeriesUpdated())); + break; + } + case QAbstractSeries::SeriesTypeBar: + case QAbstractSeries::SeriesTypeStackedBar: + case QAbstractSeries::SeriesTypePercentBar: + case QAbstractSeries::SeriesTypeHorizontalBar: + case QAbstractSeries::SeriesTypeHorizontalStackedBar: + case QAbstractSeries::SeriesTypeHorizontalPercentBar: { + QAbstractBarSeries *s = qobject_cast (series); + QObject::disconnect(s, SIGNAL(countChanged()), this, SLOT(handleSeriesUpdated())); + break; + } + // TODO: + case QAbstractSeries::SeriesTypeLine: + case QAbstractSeries::SeriesTypeArea: + case QAbstractSeries::SeriesTypeScatter: + case QAbstractSeries::SeriesTypeSpline: + default: { + // No need to disconnect any series related signals? + break; + } + } + + QObject::disconnect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); // QObject::disconnect(series->d_ptr.data(), SIGNAL(legendPropertiesUpdated(QAbstractSeries*)), this, SLOT(handleLegendPropertiesUpdated(QAbstractSeries*))); m_layout->invalidate(); +// q_ptr->layout()->activate(); +} + +void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series) +{ + // Moved to appendSeries + // This slot is just to make old code work for now. + appendSeries(series); +} + +void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series) +{ + // Moved to removeSeries + // This slot is just to make old code work for now. + removeSeries(series); } void QLegendPrivate::handleSeriesVisibleChanged() @@ -548,14 +610,15 @@ void QLegendPrivate::handleSeriesVisibleChanged() void QLegendPrivate::handleCountChanged() { // TODO: With new markers, the series should notify markers directly. - // TODO: This is not a good way to handle updates. - qDebug() << "handleLegendPropertiesUpdated" << series; + // TODO: Better way to handle updates + + QAbstractSeries *series = qobject_cast (sender()); + qDebug() << "QLegendPrivate::handleSeriesUpdated" << series; // Handle new or removed markers // Handle changes of marker pen/brush/label. every property that legend is interested handleSeriesRemoved(series); -// Domain domain; - handleSeriesAdded(series/*, &domain*/); + handleSeriesAdded(series); } #include "moc_qlegend.cpp" diff --git a/src/legend/qlegend_p.h b/src/legend/qlegend_p.h index 8131326..577bcd6 100644 --- a/src/legend/qlegend_p.h +++ b/src/legend/qlegend_p.h @@ -62,7 +62,7 @@ public: void removeSeries(QAbstractSeries* series); public Q_SLOTS: - void handleSeriesAdded(QAbstractSeries *series/*, Domain *domain*/); + void handleSeriesAdded(QAbstractSeries *series); void handleSeriesRemoved(QAbstractSeries *series); void handleSeriesVisibleChanged(); void handleCountChanged(); diff --git a/src/legend/qpielegendmarker.cpp b/src/legend/qpielegendmarker.cpp index 6666a00..9c086af 100644 --- a/src/legend/qpielegendmarker.cpp +++ b/src/legend/qpielegendmarker.cpp @@ -61,9 +61,7 @@ QPieLegendMarkerPrivate::QPieLegendMarkerPrivate(QPieLegendMarker *q, QPieSeries QLegendMarkerPrivate(q,legend), m_series(series), m_slice(slice) -// m_legend(legend) { -// qDebug() << "QPieLegendMarkerPrivate created"; QObject::connect(m_slice, SIGNAL(labelChanged()), this, SLOT(updated())); QObject::connect(m_slice, SIGNAL(brushChanged()), this, SLOT(updated())); updated(); @@ -77,7 +75,6 @@ QPieLegendMarkerPrivate::~QPieLegendMarkerPrivate() void QPieLegendMarkerPrivate::updated() { -// qDebug() << "QPieLegendMarkerPrivate::updated"; m_item->setBrush(m_slice->brush()); m_item->setLabel(m_slice->label()); m_item->setPen(m_slice->pen()); diff --git a/src/legend/qpielegendmarker.h b/src/legend/qpielegendmarker.h index df37331..b6ab00b 100644 --- a/src/legend/qpielegendmarker.h +++ b/src/legend/qpielegendmarker.h @@ -28,6 +28,7 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE +// TODO: No export, make this private. QLegendMarker should be enough for user of the api (why expose the details?) class QTCOMMERCIALCHART_EXPORT QPieLegendMarker : public QLegendMarker { Q_OBJECT diff --git a/src/piechart/qpieseries.cpp b/src/piechart/qpieseries.cpp index 3d1ae1a..8137de1 100644 --- a/src/piechart/qpieseries.cpp +++ b/src/piechart/qpieseries.cpp @@ -474,7 +474,6 @@ bool QPieSeries::insert(int index, QPieSlice *slice) connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked())); connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool))); - emit added(QList() << slice); emit countChanged();