From e8fbee1fef5508ff099d5a87f02e9454459c5218 2012-06-15 10:24:30 From: sauimone Date: 2012-06-15 10:24:30 Subject: [PATCH] barseries fix: series visibility now affects also label visibility --- diff --git a/src/barchart/barchartitem.cpp b/src/barchart/barchartitem.cpp index 85ed393..fb90aac 100644 --- a/src/barchart/barchartitem.cpp +++ b/src/barchart/barchartitem.cpp @@ -40,7 +40,7 @@ BarChartItem::BarChartItem(QBarSeries *series, ChartPresenter *presenter) : connect(series->d_func(), SIGNAL(updatedBars()), this, SLOT(handleLayoutChanged())); connect(series->d_func(), SIGNAL(labelsVisibleChanged(bool)), this, SLOT(handleLabelsVisibleChanged(bool))); connect(series->d_func(), SIGNAL(restructuredBars()), this, SLOT(handleDataStructureChanged())); - connect(series, SIGNAL(visibleChanged()), this, SLOT(handleLayoutChanged())); + connect(series, SIGNAL(visibleChanged()), this, SLOT(handleVisibleChanged())); setZValue(ChartPresenter::BarSeriesZValue); handleDataStructureChanged(); } @@ -61,42 +61,6 @@ QRectF BarChartItem::boundingRect() const return m_rect; } -void BarChartItem::handleDataStructureChanged() -{ - foreach(QGraphicsItem *item, childItems()) { - delete item; - } - - m_bars.clear(); - m_labels.clear(); - m_layout.clear(); - - bool labelsVisible = m_series->isLabelsVisible(); - - // Create new graphic items for bars - for (int c = 0; c < m_series->d_func()->categoryCount(); c++) { - for (int s = 0; s < m_series->count(); s++) { - QBarSet *set = m_series->d_func()->barsetAt(s); - - // Bars - Bar *bar = new Bar(set,c,this); - m_bars.append(bar); - connect(bar, SIGNAL(clicked(QBarSet*,int)), m_series, SIGNAL(clicked(QBarSet*,int))); - connect(bar, SIGNAL(hovered(QBarSet*,bool)), m_series, SIGNAL(hovered(QBarSet*,bool))); - m_layout.append(QRectF(0, 0, 0, 0)); - - // Labels - QGraphicsSimpleTextItem *label = new QGraphicsSimpleTextItem(this); - label->setVisible(labelsVisible); - m_labels.append(label); - } - } - - // TODO: Is this the right place to call it? - presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series)); - handleLayoutChanged(); -} - QVector BarChartItem::calculateLayout() { QVector layout; @@ -200,6 +164,8 @@ void BarChartItem::handleLayoutChanged() applyLayout(layout); } + + void BarChartItem::handleLabelsVisibleChanged(bool visible) { foreach (QGraphicsSimpleTextItem* label, m_labels) { @@ -208,6 +174,51 @@ void BarChartItem::handleLabelsVisibleChanged(bool visible) update(); } +void BarChartItem::handleDataStructureChanged() +{ + foreach(QGraphicsItem *item, childItems()) { + delete item; + } + + m_bars.clear(); + m_labels.clear(); + m_layout.clear(); + + bool labelsVisible = m_series->isLabelsVisible(); + + // Create new graphic items for bars + for (int c = 0; c < m_series->d_func()->categoryCount(); c++) { + for (int s = 0; s < m_series->count(); s++) { + QBarSet *set = m_series->d_func()->barsetAt(s); + + // Bars + Bar *bar = new Bar(set,c,this); + m_bars.append(bar); + connect(bar, SIGNAL(clicked(QBarSet*,int)), m_series, SIGNAL(clicked(QBarSet*,int))); + connect(bar, SIGNAL(hovered(QBarSet*,bool)), m_series, SIGNAL(hovered(QBarSet*,bool))); + m_layout.append(QRectF(0, 0, 0, 0)); + + // Labels + QGraphicsSimpleTextItem *label = new QGraphicsSimpleTextItem(this); + label->setVisible(labelsVisible); + m_labels.append(label); + } + } + + // TODO: Is this the right place to call it? + presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series)); + handleLayoutChanged(); +} + +void BarChartItem::handleVisibleChanged() +{ + bool visible = m_series->isVisible(); + handleLabelsVisibleChanged(visible); + foreach(QGraphicsItem *item, childItems()) { + item->setVisible(visible); + } +} + #include "moc_barchartitem_p.cpp" QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/barchart/barchartitem_p.h b/src/barchart/barchartitem_p.h index 55f8759..10b685d 100644 --- a/src/barchart/barchartitem_p.h +++ b/src/barchart/barchartitem_p.h @@ -66,6 +66,7 @@ public Q_SLOTS: void handleLayoutChanged(); void handleLabelsVisibleChanged(bool visible); void handleDataStructureChanged(); // structure of of series has changed, recreate graphic items + void handleVisibleChanged(); protected: