summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMika Salmela <mika.salmela@digia.com>2013-04-16 12:05:44 +0300
committerMika Salmela <mika.salmela@digia.com>2013-04-16 12:06:20 +0300
commit63ca3532f8319e94bd04bc9efbbe055b3eb24279 (patch)
tree1894e7baf0a7a4696d7cdac82905199aa991af64
parent20a93e498d73f2647131e1663e54ecf7b17be4bb (diff)
Added remove single box
Change-Id: Ie0294150cef9831c28c60004b5a07f890faca74a Reviewed-by: Mika Salmela <mika.salmela@digia.com>
-rw-r--r--src/boxplotchart/boxplotchartitem.cpp21
-rw-r--r--src/boxplotchart/boxplotchartitem_p.h2
-rw-r--r--src/boxplotchart/boxwhiskers.cpp1
-rw-r--r--tests/boxplottester/mainwidget.cpp32
-rw-r--r--tests/boxplottester/mainwidget.h1
5 files changed, 49 insertions, 8 deletions
diff --git a/src/boxplotchart/boxplotchartitem.cpp b/src/boxplotchart/boxplotchartitem.cpp
index 9af4e0b7..48cd2b81 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<QBarSet*>)), this, SLOT(handleBarsetRemove(QList<QBarSet*>)));
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<QBarSet*> 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 342221e6..1c79ec11 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 <QGraphicsItem>
QTCOMMERCIALCHART_BEGIN_NAMESPACE
@@ -58,6 +59,7 @@ public Q_SLOTS:
void handleDomainUpdated();
void handleLayoutChanged();
void handleUpdatedBars();
+ void handleBarsetRemove(QList<QBarSet*> barSets);
private:
virtual QVector<QRectF> calculateLayout();
diff --git a/src/boxplotchart/boxwhiskers.cpp b/src/boxplotchart/boxwhiskers.cpp
index aed2fcfe..0ed71ffc 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 eb3d3b15..0252272e 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<QBarSet *> 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 dc57991f..b7071c11 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);