##// END OF EJS Templates
Improved handling of different serieses....
Mika Salmela -
r2484:f6ca68eccfda
parent child
Show More
@@ -25,6 +25,7
25 #include <QBarSet>
25 #include <QBarSet>
26 #include <QLegend>
26 #include <QLegend>
27 #include <QBarCategoryAxis>
27 #include <QBarCategoryAxis>
28 #include <QLineSeries>
28
29
29 #include <QBrush>
30 #include <QBrush>
30 #include <QColor>
31 #include <QColor>
@@ -42,6 +43,12 int main(int argc, char *argv[])
42 QBarSet *set3 = new QBarSet("Apr");
43 QBarSet *set3 = new QBarSet("Apr");
43 QBarSet *set4 = new QBarSet("May");
44 QBarSet *set4 = new QBarSet("May");
44 QBarSet *set5 = new QBarSet("Jun");
45 QBarSet *set5 = new QBarSet("Jun");
46 QBarSet *set6 = new QBarSet("Jul");
47 QBarSet *set7 = new QBarSet("Aug");
48 QBarSet *set8 = new QBarSet("Sep");
49 QBarSet *set9 = new QBarSet("Oct");
50 QBarSet *set10 = new QBarSet("Nov");
51 QBarSet *set11 = new QBarSet("Dec");
45
52
46 // low bot med top upp
53 // low bot med top upp
47 *set0 << 3 << 4 << 4.4 << 6 << 7;
54 *set0 << 3 << 4 << 4.4 << 6 << 7;
@@ -50,10 +57,13 int main(int argc, char *argv[])
50 *set3 << 5 << 6 << 6.8 << 7 << 8;
57 *set3 << 5 << 6 << 6.8 << 7 << 8;
51 *set4 << 4 << 5 << 5.2 << 6 << 7;
58 *set4 << 4 << 5 << 5.2 << 6 << 7;
52 *set5 << 4 << 7 << 8.2 << 9 << 10;
59 *set5 << 4 << 7 << 8.2 << 9 << 10;
60 *set6 << 2.5 << 5 << 5.4 << 6 << 7;
61 *set7 << 5 << 6.3 << 7.5 << 8 << 12;
62 *set8 << 2.6 << 5.1 << 5.7 << 8 << 9;
63 *set9 << 3.1 << 5.8 << 6.8 << 7 << 8;
64 *set10 << 4.2 << 5 << 5.8 << 6 << 7;
65 *set11 << 4.7 << 7 << 8.2 << 9 << 10;
53
66
54 set0->setBrush(QBrush(QColor(Qt::yellow)));
55
56 //set0->setColor(QColor(Qt::darkRed));
57 //![1]
67 //![1]
58
68
59 //![2]
69 //![2]
@@ -64,21 +74,41 int main(int argc, char *argv[])
64 series->append(set3);
74 series->append(set3);
65 series->append(set4);
75 series->append(set4);
66 series->append(set5);
76 series->append(set5);
67 series->type();
77 series->append(set6);
78 series->append(set7);
79 series->append(set8);
80 series->append(set9);
81 series->append(set10);
82 series->append(set11);
68 series->setName("Box & Whiskers");
83 series->setName("Box & Whiskers");
69 //series->setBrush(QBrush(QColor(Qt::yellow)));
70 //![2]
84 //![2]
71
85
86 QLineSeries *lineSeries = new QLineSeries();
87 lineSeries->append(0, 4.4);
88 lineSeries->append(1, 7.5);
89 lineSeries->append(2, 5.7);
90 lineSeries->append(3, 6.8);
91 lineSeries->append(4, 5.2);
92 lineSeries->append(5, 8.2);
93 lineSeries->append(6, 5.4);
94 lineSeries->append(7, 7.5);
95 lineSeries->append(8, 5.7);
96 lineSeries->append(9, 6.8);
97 lineSeries->append(10, 5.2);
98 lineSeries->append(11, 8.2);
99 lineSeries->setName("Medians");
100
72 //![3]
101 //![3]
73 QChart *chart = new QChart();
102 QChart *chart = new QChart();
74 chart->addSeries(series);
103 chart->addSeries(series);
104 chart->addSeries(lineSeries);
75 chart->setTitle("Simple boxplotchart example");
105 chart->setTitle("Simple boxplotchart example");
76 chart->setAnimationOptions(QChart::SeriesAnimations);
106 chart->setAnimationOptions(QChart::SeriesAnimations);
77 //![3]
107 //![3]
78
108
79 //![4]
109 //![4]
80 QStringList categories;
110 QStringList categories;
81 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
111 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec";
82 QBarCategoryAxis *axis = new QBarCategoryAxis();
112 QBarCategoryAxis *axis = new QBarCategoryAxis();
83 axis->append(categories);
113 axis->append(categories);
84 chart->createDefaultAxes();
114 chart->createDefaultAxes();
@@ -113,6 +113,13 void BoxPlotChartItem::handleUpdatedBars()
113 item->setBrush(m_series->brush());
113 item->setBrush(m_series->brush());
114 item->setPen(m_series->pen());
114 item->setPen(m_series->pen());
115 }
115 }
116 // Override with QBarSet specific settings
117 foreach (QBarSet *set, m_boxTable.keys()) {
118 if (set->brush().style() != Qt::NoBrush)
119 m_boxTable.value(set)->setBrush(set->brush());
120 if (set->pen().style() != Qt::NoPen)
121 m_boxTable.value(set)->setPen(set->pen());
122 }
116 }
123 }
117
124
118 void BoxPlotChartItem::handleBarsetRemove(QList<QBarSet*> barSets)
125 void BoxPlotChartItem::handleBarsetRemove(QList<QBarSet*> barSets)
@@ -177,6 +184,8 void BoxPlotChartItem::initializeLayout()
177
184
178 QVector<QRectF> BoxPlotChartItem::calculateLayout()
185 QVector<QRectF> BoxPlotChartItem::calculateLayout()
179 {
186 {
187 qDebug() << "ALERT EMPTY: BoxPlotChartItem::calculateLayout()";
188
180 return QVector<QRectF>();
189 return QVector<QRectF>();
181 }
190 }
182
191
@@ -61,11 +61,13 void BoxWhiskers::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
61 void BoxWhiskers::setBrush(const QBrush &brush)
61 void BoxWhiskers::setBrush(const QBrush &brush)
62 {
62 {
63 m_brush = brush;
63 m_brush = brush;
64 update();
64 }
65 }
65
66
66 void BoxWhiskers::setPen(const QPen &pen)
67 void BoxWhiskers::setPen(const QPen &pen)
67 {
68 {
68 m_pen = pen;
69 m_pen = pen;
70 update();
69 }
71 }
70
72
71 void BoxWhiskers::setLayout(const BoxWhiskersData &data)
73 void BoxWhiskers::setLayout(const BoxWhiskersData &data)
@@ -168,11 +168,11 void QBoxPlotSeriesPrivate::initializeGraphics(QGraphicsItem* parent)
168 connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), this, SLOT(handleSeriesRemove(QAbstractSeries*)) );
168 connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), this, SLOT(handleSeriesRemove(QAbstractSeries*)) );
169
169
170 QList<QAbstractSeries *> serieses = m_chart->series();
170 QList<QAbstractSeries *> serieses = m_chart->series();
171 boxPlot->m_seriesCount = serieses.count();
172
171
173 // Tries to find this series from the Chart's list of serieses and deduce the index
172 // Tries to find this series from the Chart's list of serieses and deduce the index
174 int index = 0;
173 int index = 0;
175 foreach (QAbstractSeries *s, serieses) {
174 foreach (QAbstractSeries *s, serieses) {
175 if (s->type() == QAbstractSeries::SeriesTypeBoxPlot) {
176 if (q == static_cast<QBoxPlotSeries *>(s)) {
176 if (q == static_cast<QBoxPlotSeries *>(s)) {
177 boxPlot->m_seriesIndex = index;
177 boxPlot->m_seriesIndex = index;
178 m_index = index;
178 m_index = index;
@@ -180,6 +180,8 void QBoxPlotSeriesPrivate::initializeGraphics(QGraphicsItem* parent)
180 index++;
180 index++;
181 }
181 }
182 }
182 }
183 boxPlot->m_seriesCount = index;
184 }
183
185
184 // Make BoxPlotChartItem to instantiate box & whisker items
186 // Make BoxPlotChartItem to instantiate box & whisker items
185 boxPlot->handleDataStructureChanged();
187 boxPlot->handleDataStructureChanged();
@@ -200,12 +202,6 void QBoxPlotSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool f
200 if (forced || m_pen == QPen(Qt::NoPen)) {
202 if (forced || m_pen == QPen(Qt::NoPen)) {
201 QPen pen = theme->outlinePen();
203 QPen pen = theme->outlinePen();
202 pen.setCosmetic(true);
204 pen.setCosmetic(true);
203
204 // QPen pen;
205 // pen.setColor(ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 1.0));
206 // pen.setWidthF(2.0);
207 // pen.setCosmetic(true);
208
209 q->setPen(pen);
205 q->setPen(pen);
210 }
206 }
211 }
207 }
@@ -262,11 +258,11 void QBoxPlotSeriesPrivate::handleSeriesChange(QAbstractSeries *series)
262
258
263 if (m_chart) {
259 if (m_chart) {
264 QList<QAbstractSeries *> serieses = m_chart->series();
260 QList<QAbstractSeries *> serieses = m_chart->series();
265 boxPlot->m_seriesCount = serieses.count();
266
261
267 // Tries to find this series from the Chart's list of serieses and deduce the index
262 // Tries to find this series from the Chart's list of serieses and deduce the index
268 int index = 0;
263 int index = 0;
269 foreach (QAbstractSeries *s, serieses) {
264 foreach (QAbstractSeries *s, serieses) {
265 if (s->type() == QAbstractSeries::SeriesTypeBoxPlot) {
270 if (q == static_cast<QBoxPlotSeries *>(s)) {
266 if (q == static_cast<QBoxPlotSeries *>(s)) {
271 boxPlot->m_seriesIndex = index;
267 boxPlot->m_seriesIndex = index;
272 m_index = index;
268 m_index = index;
@@ -274,6 +270,8 void QBoxPlotSeriesPrivate::handleSeriesChange(QAbstractSeries *series)
274 index++;
270 index++;
275 }
271 }
276 }
272 }
273 boxPlot->m_seriesCount = index;
274 }
277
275
278 boxPlot->handleDataStructureChanged();
276 boxPlot->handleDataStructureChanged();
279 }
277 }
@@ -76,11 +76,26 MainWidget::MainWidget(QWidget *parent) :
76 connect(addBoxButton, SIGNAL(clicked()), this, SLOT(addBox()));
76 connect(addBoxButton, SIGNAL(clicked()), this, SLOT(addBox()));
77 grid->addWidget(addBoxButton, rowPos++, 1);
77 grid->addWidget(addBoxButton, rowPos++, 1);
78
78
79 // Create insert a box button
80 QPushButton *insertBoxButton = new QPushButton("Insert a box");
81 connect(insertBoxButton, SIGNAL(clicked()), this, SLOT(insertBox()));
82 grid->addWidget(insertBoxButton, rowPos++, 1);
83
79 // Create add a single box button
84 // Create add a single box button
80 QPushButton *removeBoxButton = new QPushButton("Remove a box");
85 QPushButton *removeBoxButton = new QPushButton("Remove a box");
81 connect(removeBoxButton, SIGNAL(clicked()), this, SLOT(removeBox()));
86 connect(removeBoxButton, SIGNAL(clicked()), this, SLOT(removeBox()));
82 grid->addWidget(removeBoxButton, rowPos++, 1);
87 grid->addWidget(removeBoxButton, rowPos++, 1);
83
88
89 // Create clear button
90 QPushButton *clearButton = new QPushButton("Clear");
91 connect(clearButton, SIGNAL(clicked()), this, SLOT(clear()));
92 grid->addWidget(clearButton, rowPos++, 1);
93
94 // Create set brush button
95 QPushButton *setBrushButton = new QPushButton("Set brush");
96 connect(setBrushButton, SIGNAL(clicked()), this, SLOT(setBrush()));
97 grid->addWidget(setBrushButton, rowPos++, 1);
98
84 initThemeCombo(grid);
99 initThemeCombo(grid);
85 initCheckboxes(grid);
100 initCheckboxes(grid);
86
101
@@ -208,6 +223,8 void MainWidget::addSeries()
208
223
209 void MainWidget::removeSeries()
224 void MainWidget::removeSeries()
210 {
225 {
226 qDebug() << "BoxPlotTester::MainWidget::removeSeries()";
227
211 if (nSeries > 0) {
228 if (nSeries > 0) {
212 nSeries--;
229 nSeries--;
213 m_chart->removeSeries(m_series[nSeries]);
230 m_chart->removeSeries(m_series[nSeries]);
@@ -233,9 +250,25 void MainWidget::addBox()
233 }
250 }
234 }
251 }
235
252
253 void MainWidget::insertBox()
254 {
255 qDebug() << "BoxPlotTester::MainWidget::insertBox()";
256
257 if (nSeries > 0) {
258 QBarSet *newSet = new QBarSet("New");
259 *newSet << 2 << 6 << 6.8 << 7 << 10;
260
261 m_series[0]->insert(1, newSet);
262
263 m_axis->append(addCategories[nNewBoxes]);
264
265 nNewBoxes++;
266 }
267 }
268
236 void MainWidget::removeBox()
269 void MainWidget::removeBox()
237 {
270 {
238 qDebug() << "MainWidget::removeBox";
271 qDebug() << "BoxPlotTester::MainWidget::removeBox";
239
272
240 if (nSeries > 0) {
273 if (nSeries > 0) {
241 QList<QBarSet *> sets = m_series[0]->barSets();
274 QList<QBarSet *> sets = m_series[0]->barSets();
@@ -245,6 +278,29 void MainWidget::removeBox()
245 }
278 }
246 }
279 }
247
280
281 void MainWidget::clear()
282 {
283 qDebug() << "BoxPlotTester::MainWidget::clear";
284
285 if (nSeries > 0) {
286 m_series[0]->clear();
287 } else {
288 qDebug() << "Create a series first";
289 }
290 }
291
292 void MainWidget::setBrush()
293 {
294 qDebug() << "BoxPlotTester::MainWidget::setBrush";
295
296 if (nSeries > 0) {
297 QList<QBarSet *> sets = m_series[0]->barSets();
298 sets.at(1)->setBrush(QBrush(QColor(Qt::yellow)));
299 } else {
300 qDebug() << "Create a series first";
301 }
302 }
303
248 void MainWidget::animationToggled(bool enabled)
304 void MainWidget::animationToggled(bool enabled)
249 {
305 {
250 qDebug() << "BoxPlotTester::Animation toggled to " << enabled;
306 qDebug() << "BoxPlotTester::Animation toggled to " << enabled;
@@ -49,7 +49,10 private slots:
49 void addSeries();
49 void addSeries();
50 void removeSeries();
50 void removeSeries();
51 void addBox();
51 void addBox();
52 void insertBox();
52 void removeBox();
53 void removeBox();
54 void clear();
55 void setBrush();
53 void animationToggled(bool enabled);
56 void animationToggled(bool enabled);
54 void legendToggled(bool enabled);
57 void legendToggled(bool enabled);
55 void titleToggled(bool enabled);
58 void titleToggled(bool enabled);
General Comments 0
You need to be logged in to leave comments. Login now