##// END OF EJS Templates
Added remove single box...
Mika Salmela -
r2482:63ca3532f831
parent child
Show More
@@ -35,6 +35,7 BoxPlotChartItem::BoxPlotChartItem(QBoxPlotSeries *series, QGraphicsItem* item)
35 m_animation(0),
35 m_animation(0),
36 m_animate(0)
36 m_animate(0)
37 {
37 {
38 connect(series, SIGNAL(barsetsRemoved(QList<QBarSet*>)), this, SLOT(handleBarsetRemove(QList<QBarSet*>)));
38 connect(series->d_func(), SIGNAL(restructuredBars()), this, SLOT(handleDataStructureChanged()));
39 connect(series->d_func(), SIGNAL(restructuredBars()), this, SLOT(handleDataStructureChanged()));
39 connect(series->d_func(), SIGNAL(updatedLayout()), this, SLOT(handleLayoutChanged()));
40 connect(series->d_func(), SIGNAL(updatedLayout()), this, SLOT(handleLayoutChanged()));
40 connect(series->d_func(), SIGNAL(updatedBars()), this, SLOT(handleUpdatedBars()));
41 connect(series->d_func(), SIGNAL(updatedBars()), this, SLOT(handleUpdatedBars()));
@@ -76,7 +77,8 void BoxPlotChartItem::setAnimation(BoxPlotAnimation *animation)
76
77
77 void BoxPlotChartItem::handleDataStructureChanged()
78 void BoxPlotChartItem::handleDataStructureChanged()
78 {
79 {
79 //qDebug() << "BoxPlotChartItem::handleDataStructureChanged()";
80 qDebug() << "BoxPlotChartItem::handleDataStructureChanged()";
81
80 int setCount = m_series->count();
82 int setCount = m_series->count();
81
83
82 for (int s = 0; s < setCount; s++) {
84 for (int s = 0; s < setCount; s++) {
@@ -105,7 +107,7 void BoxPlotChartItem::handleDataStructureChanged()
105
107
106 void BoxPlotChartItem::handleUpdatedBars()
108 void BoxPlotChartItem::handleUpdatedBars()
107 {
109 {
108 //qDebug() << "BoxPlotChartItem::handleUpdatedBars()";
110 qDebug() << "BoxPlotChartItem::handleUpdatedBars()";
109
111
110 foreach (BoxWhiskers *item, m_boxTable.values()) {
112 foreach (BoxWhiskers *item, m_boxTable.values()) {
111 item->setBrush(m_series->brush());
113 item->setBrush(m_series->brush());
@@ -113,6 +115,19 void BoxPlotChartItem::handleUpdatedBars()
113 }
115 }
114 }
116 }
115
117
118 void BoxPlotChartItem::handleBarsetRemove(QList<QBarSet*> barSets)
119 {
120 //qDebug() << "BoxPlotChartItem::handleBarsetRemove";
121
122 foreach (QBarSet *set, barSets) {
123 BoxWhiskers *boxItem = m_boxTable.value(set);
124 m_boxTable.remove(set);
125 delete boxItem;
126 }
127
128 // We trust that series emits the restructuredBars, which handles restructuring
129 }
130
116 void BoxPlotChartItem::handleDomainUpdated()
131 void BoxPlotChartItem::handleDomainUpdated()
117 {
132 {
118 //qDebug() << "BoxPlotChartItem::handleDomainUpdated() domain()->size() = " << domain()->size();
133 //qDebug() << "BoxPlotChartItem::handleDomainUpdated() domain()->size() = " << domain()->size();
@@ -136,6 +151,8 void BoxPlotChartItem::handleDomainUpdated()
136
151
137 void BoxPlotChartItem::handleLayoutChanged()
152 void BoxPlotChartItem::handleLayoutChanged()
138 {
153 {
154 qDebug() << "BoxPlotChartItem::handleLayoutChanged";
155
139 foreach (BoxWhiskers *item, m_boxTable.values()) {
156 foreach (BoxWhiskers *item, m_boxTable.values()) {
140 if (m_animation)
157 if (m_animation)
141 m_animation->setAnimationStart(item);
158 m_animation->setAnimationStart(item);
@@ -35,6 +35,7
35 #include "qboxplotseries.h"
35 #include "qboxplotseries.h"
36 #include "chartitem_p.h"
36 #include "chartitem_p.h"
37 #include "boxplotanimation_p.h"
37 #include "boxplotanimation_p.h"
38 #include "qbarset.h"
38 #include <QGraphicsItem>
39 #include <QGraphicsItem>
39
40
40 QTCOMMERCIALCHART_BEGIN_NAMESPACE
41 QTCOMMERCIALCHART_BEGIN_NAMESPACE
@@ -58,6 +59,7 public Q_SLOTS:
58 void handleDomainUpdated();
59 void handleDomainUpdated();
59 void handleLayoutChanged();
60 void handleLayoutChanged();
60 void handleUpdatedBars();
61 void handleUpdatedBars();
62 void handleBarsetRemove(QList<QBarSet*> barSets);
61
63
62 private:
64 private:
63 virtual QVector<QRectF> calculateLayout();
65 virtual QVector<QRectF> calculateLayout();
@@ -29,6 +29,7 BoxWhiskers::BoxWhiskers(AbstractDomain *domain, QGraphicsObject *parent) :
29 QGraphicsObject(parent),
29 QGraphicsObject(parent),
30 m_domain(domain)
30 m_domain(domain)
31 {
31 {
32 //qDebug() << "BoxWhiskers::BoxWhiskers()";
32 }
33 }
33
34
34 BoxWhiskers::~BoxWhiskers()
35 BoxWhiskers::~BoxWhiskers()
@@ -71,12 +71,16 MainWidget::MainWidget(QWidget *parent) :
71 connect(removeSeriesButton, SIGNAL(clicked()), this, SLOT(removeSeries()));
71 connect(removeSeriesButton, SIGNAL(clicked()), this, SLOT(removeSeries()));
72 grid->addWidget(removeSeriesButton, rowPos++, 1);
72 grid->addWidget(removeSeriesButton, rowPos++, 1);
73
73
74
75 // Create add a single box button
74 // Create add a single box button
76 QPushButton *addBoxButton = new QPushButton("Add a box");
75 QPushButton *addBoxButton = new QPushButton("Add a box");
77 connect(addBoxButton, SIGNAL(clicked()), this, SLOT(addBox()));
76 connect(addBoxButton, SIGNAL(clicked()), this, SLOT(addBox()));
78 grid->addWidget(addBoxButton, rowPos++, 1);
77 grid->addWidget(addBoxButton, rowPos++, 1);
79
78
79 // Create add a single box button
80 QPushButton *removeBoxButton = new QPushButton("Remove a box");
81 connect(removeBoxButton, SIGNAL(clicked()), this, SLOT(removeBox()));
82 grid->addWidget(removeBoxButton, rowPos++, 1);
83
80 initThemeCombo(grid);
84 initThemeCombo(grid);
81 initCheckboxes(grid);
85 initCheckboxes(grid);
82
86
@@ -208,6 +212,8 void MainWidget::removeSeries()
208 nSeries--;
212 nSeries--;
209 m_chart->removeSeries(m_series[nSeries]);
213 m_chart->removeSeries(m_series[nSeries]);
210 delete m_series[nSeries];
214 delete m_series[nSeries];
215 } else {
216 qDebug() << "Create a series first";
211 }
217 }
212 }
218 }
213
219
@@ -215,14 +221,28 void MainWidget::addBox()
215 {
221 {
216 qDebug() << "BoxPlotTester::MainWidget::addBox()";
222 qDebug() << "BoxPlotTester::MainWidget::addBox()";
217
223
218 QBarSet *newSet = new QBarSet("New");
224 if (nSeries > 0) {
219 *newSet << 5 << 6 << 6.8 << 7 << 8;
225 QBarSet *newSet = new QBarSet("New");
226 *newSet << 5 << 6 << 6.8 << 7 << 8;
220
227
221 m_series[0]->append(newSet);
228 m_series[0]->append(newSet);
222
229
223 m_axis->append(addCategories[nNewBoxes]);
230 m_axis->append(addCategories[nNewBoxes]);
224
231
225 nNewBoxes++;
232 nNewBoxes++;
233 }
234 }
235
236 void MainWidget::removeBox()
237 {
238 qDebug() << "MainWidget::removeBox";
239
240 if (nSeries > 0) {
241 QList<QBarSet *> sets = m_series[0]->barSets();
242 m_series[0]->remove(sets.at(m_series[0]->count() - 3));
243 } else {
244 qDebug() << "Create a series first";
245 }
226 }
246 }
227
247
228 void MainWidget::animationToggled(bool enabled)
248 void MainWidget::animationToggled(bool enabled)
@@ -49,6 +49,7 private slots:
49 void addSeries();
49 void addSeries();
50 void removeSeries();
50 void removeSeries();
51 void addBox();
51 void addBox();
52 void removeBox();
52 void animationToggled(bool enabled);
53 void animationToggled(bool enabled);
53 void legendToggled(bool enabled);
54 void legendToggled(bool enabled);
54 void titleToggled(bool enabled);
55 void titleToggled(bool enabled);
General Comments 0
You need to be logged in to leave comments. Login now