From 63ca3532f8319e94bd04bc9efbbe055b3eb24279 2013-04-16 09:06:20 From: Mika Salmela Date: 2013-04-16 09:06:20 Subject: [PATCH] Added remove single box Change-Id: Ie0294150cef9831c28c60004b5a07f890faca74a Reviewed-by: Mika Salmela --- diff --git a/src/boxplotchart/boxplotchartitem.cpp b/src/boxplotchart/boxplotchartitem.cpp index 9af4e0b..48cd2b8 100644 --- a/src/boxplotchart/boxplotchartitem.cpp +++ b/src/boxplotchart/boxplotchartitem.cpp @@ -35,6 +35,7 @@ BoxPlotChartItem::BoxPlotChartItem(QBoxPlotSeries *series, QGraphicsItem* item) m_animation(0), m_animate(0) { + connect(series, SIGNAL(barsetsRemoved(QList)), this, SLOT(handleBarsetRemove(QList))); connect(series->d_func(), SIGNAL(restructuredBars()), this, SLOT(handleDataStructureChanged())); connect(series->d_func(), SIGNAL(updatedLayout()), this, SLOT(handleLayoutChanged())); connect(series->d_func(), SIGNAL(updatedBars()), this, SLOT(handleUpdatedBars())); @@ -76,7 +77,8 @@ void BoxPlotChartItem::setAnimation(BoxPlotAnimation *animation) void BoxPlotChartItem::handleDataStructureChanged() { - //qDebug() << "BoxPlotChartItem::handleDataStructureChanged()"; + qDebug() << "BoxPlotChartItem::handleDataStructureChanged()"; + int setCount = m_series->count(); for (int s = 0; s < setCount; s++) { @@ -105,7 +107,7 @@ void BoxPlotChartItem::handleDataStructureChanged() void BoxPlotChartItem::handleUpdatedBars() { - //qDebug() << "BoxPlotChartItem::handleUpdatedBars()"; + qDebug() << "BoxPlotChartItem::handleUpdatedBars()"; foreach (BoxWhiskers *item, m_boxTable.values()) { item->setBrush(m_series->brush()); @@ -113,6 +115,19 @@ void BoxPlotChartItem::handleUpdatedBars() } } +void BoxPlotChartItem::handleBarsetRemove(QList barSets) +{ + //qDebug() << "BoxPlotChartItem::handleBarsetRemove"; + + foreach (QBarSet *set, barSets) { + BoxWhiskers *boxItem = m_boxTable.value(set); + m_boxTable.remove(set); + delete boxItem; + } + + // We trust that series emits the restructuredBars, which handles restructuring +} + void BoxPlotChartItem::handleDomainUpdated() { //qDebug() << "BoxPlotChartItem::handleDomainUpdated() domain()->size() = " << domain()->size(); @@ -136,6 +151,8 @@ void BoxPlotChartItem::handleDomainUpdated() void BoxPlotChartItem::handleLayoutChanged() { + qDebug() << "BoxPlotChartItem::handleLayoutChanged"; + foreach (BoxWhiskers *item, m_boxTable.values()) { if (m_animation) m_animation->setAnimationStart(item); diff --git a/src/boxplotchart/boxplotchartitem_p.h b/src/boxplotchart/boxplotchartitem_p.h index 342221e..1c79ec1 100644 --- a/src/boxplotchart/boxplotchartitem_p.h +++ b/src/boxplotchart/boxplotchartitem_p.h @@ -35,6 +35,7 @@ #include "qboxplotseries.h" #include "chartitem_p.h" #include "boxplotanimation_p.h" +#include "qbarset.h" #include QTCOMMERCIALCHART_BEGIN_NAMESPACE @@ -58,6 +59,7 @@ public Q_SLOTS: void handleDomainUpdated(); void handleLayoutChanged(); void handleUpdatedBars(); + void handleBarsetRemove(QList barSets); private: virtual QVector calculateLayout(); diff --git a/src/boxplotchart/boxwhiskers.cpp b/src/boxplotchart/boxwhiskers.cpp index aed2fcf..0ed71ff 100644 --- a/src/boxplotchart/boxwhiskers.cpp +++ b/src/boxplotchart/boxwhiskers.cpp @@ -29,6 +29,7 @@ BoxWhiskers::BoxWhiskers(AbstractDomain *domain, QGraphicsObject *parent) : QGraphicsObject(parent), m_domain(domain) { + //qDebug() << "BoxWhiskers::BoxWhiskers()"; } BoxWhiskers::~BoxWhiskers() diff --git a/tests/boxplottester/mainwidget.cpp b/tests/boxplottester/mainwidget.cpp index eb3d3b1..0252272 100644 --- a/tests/boxplottester/mainwidget.cpp +++ b/tests/boxplottester/mainwidget.cpp @@ -71,12 +71,16 @@ MainWidget::MainWidget(QWidget *parent) : connect(removeSeriesButton, SIGNAL(clicked()), this, SLOT(removeSeries())); grid->addWidget(removeSeriesButton, rowPos++, 1); - // Create add a single box button QPushButton *addBoxButton = new QPushButton("Add a box"); connect(addBoxButton, SIGNAL(clicked()), this, SLOT(addBox())); grid->addWidget(addBoxButton, rowPos++, 1); + // Create add a single box button + QPushButton *removeBoxButton = new QPushButton("Remove a box"); + connect(removeBoxButton, SIGNAL(clicked()), this, SLOT(removeBox())); + grid->addWidget(removeBoxButton, rowPos++, 1); + initThemeCombo(grid); initCheckboxes(grid); @@ -208,6 +212,8 @@ void MainWidget::removeSeries() nSeries--; m_chart->removeSeries(m_series[nSeries]); delete m_series[nSeries]; + } else { + qDebug() << "Create a series first"; } } @@ -215,14 +221,28 @@ void MainWidget::addBox() { qDebug() << "BoxPlotTester::MainWidget::addBox()"; - QBarSet *newSet = new QBarSet("New"); - *newSet << 5 << 6 << 6.8 << 7 << 8; + if (nSeries > 0) { + QBarSet *newSet = new QBarSet("New"); + *newSet << 5 << 6 << 6.8 << 7 << 8; - m_series[0]->append(newSet); + m_series[0]->append(newSet); - m_axis->append(addCategories[nNewBoxes]); + m_axis->append(addCategories[nNewBoxes]); - nNewBoxes++; + nNewBoxes++; + } +} + +void MainWidget::removeBox() +{ + qDebug() << "MainWidget::removeBox"; + + if (nSeries > 0) { + QList sets = m_series[0]->barSets(); + m_series[0]->remove(sets.at(m_series[0]->count() - 3)); + } else { + qDebug() << "Create a series first"; + } } void MainWidget::animationToggled(bool enabled) diff --git a/tests/boxplottester/mainwidget.h b/tests/boxplottester/mainwidget.h index dc57991..b7071c1 100644 --- a/tests/boxplottester/mainwidget.h +++ b/tests/boxplottester/mainwidget.h @@ -49,6 +49,7 @@ private slots: void addSeries(); void removeSeries(); void addBox(); + void removeBox(); void animationToggled(bool enabled); void legendToggled(bool enabled); void titleToggled(bool enabled);