##// END OF EJS Templates
Updated donut screen shots
Tero Ahola -
r1900:5bb5cf100c56
parent child
Show More
1 NO CONTENT: modified file, binary diff hidden
1 NO CONTENT: modified file, binary diff hidden
@@ -1,76 +1,76
1 1 #include "donutbreakdownchart.h"
2 2 #include <QPieSlice>
3 3
4 4 QTCOMMERCIALCHART_USE_NAMESPACE
5 5
6 6 //![1]
7 7 DonutBreakdownChart::DonutBreakdownChart(QGraphicsItem *parent, Qt::WindowFlags wFlags)
8 8 :QChart(parent, wFlags)
9 9 {
10 10 // create the series for main center pie
11 11 mainSeries = new QPieSeries();
12 12 mainSeries->setPieSize(0.7);
13 13 QChart::addSeries(mainSeries);
14 14 }
15 15 //![1]
16 16
17 17 //![2]
18 18 void DonutBreakdownChart::addBreakdownSeries(QPieSeries *breakdownSeries, QColor color)
19 19 {
20 20 // add breakdown series as a slice to center pie
21 21 QPieSlice *slice = mainSeries->append(breakdownSeries->name(), breakdownSeries->sum());
22 22
23 23 // customize the slice
24 24 slice->setBrush(color);
25 25 slice->setLabelVisible();
26 26 slice->setLabelColor(Qt::white);
27 27 slice->setLabelPosition(QPieSlice::LabelInsideHorizontal);
28 28
29 29 // position and customize the breakdown series
30 30 breakdownSeries->setPieSize(0.8);
31 31 breakdownSeries->setHoleSize(0.7);
32 32 breakdownSeries->setLabelsVisible();
33 33 foreach (QPieSlice *slice, breakdownSeries->slices()) {
34 34 color = color.lighter(110);
35 35 slice->setBrush(color);
36 slice->setLabelFont(QFont("Arial", 7));
36 slice->setLabelFont(QFont("Arial", 8));
37 37 slice->setLabelArmLengthFactor(0.05);
38 38 }
39 39
40 40 // add the series to the chart
41 41 QChart::addSeries(breakdownSeries);
42 42
43 43 // recalculate breakdown donut segments
44 44 recalculateAngles();
45 45 }
46 46 //![2]
47 47
48 48 //![3]
49 49 void DonutBreakdownChart::recalculateAngles()
50 50 {
51 51 qreal angle = 0;
52 52 foreach (QPieSlice *slice, mainSeries->slices()) {
53 53 QPieSeries *s = find(slice->label());
54 54 if (s) {
55 55 s->setPieStartAngle(angle);
56 56 angle += slice->percentage() * 360.0; // full pie is 360.0
57 57 s->setPieEndAngle(angle);
58 58 }
59 59 }
60 60 }
61 61 //![3]
62 62
63 63 //![4]
64 64 QPieSeries *DonutBreakdownChart::find(QString seriesName) const
65 65 {
66 66 // find pieseries by name
67 67 foreach (QAbstractSeries *series, QChart::series()) {
68 68 QPieSeries *s = qobject_cast<QPieSeries*>(series);
69 69 if (!s)
70 70 continue;
71 71 if (s->name() == seriesName)
72 72 return s;
73 73 }
74 74 return 0;
75 75 }
76 76 //![4]
General Comments 0
You need to be logged in to leave comments. Login now