##// END OF EJS Templates
make piechartdrilldown compile again
Jani Honkonen -
r798:2c85b9e659bd
parent child
Show More
@@ -1,30 +1,30
1 1 TEMPLATE = subdirs
2 2 SUBDIRS += \
3 3 areachart \
4 4 barchart \
5 5 #chartview \
6 6 customchart \
7 7 #dynamiclinechart \
8 8 #ekgchart \
9 9 #gdpbarchart \
10 10 linechart \
11 11 #multichart \
12 12 percentbarchart \
13 13 piechart \
14 #piechartdrilldown \
14 piechartdrilldown \
15 15 #presenterchart \
16 16 scatterchart \
17 17 #scatterinteractions \
18 18 #splinechart \
19 19 stackedbarchart \
20 20 #stackedbarchartdrilldown \
21 21 #tablemodelchart \
22 22 zoomlinechart
23 23
24 24
25 25
26 26
27 27
28 28
29 29
30 30
@@ -1,114 +1,115
1 1 #include <QtGui/QApplication>
2 2 #include <QMainWindow>
3 3 #include <qchartglobal.h>
4 4 #include <qchartview.h>
5 5 #include <qpieseries.h>
6 6 #include <qpieslice.h>
7 7 #include <QTime>
8 8
9 9 QTCOMMERCIALCHART_USE_NAMESPACE
10 10
11 11 class DrilldownSlice : public QPieSlice
12 12 {
13 13 Q_OBJECT
14 14
15 15 public:
16 16 DrilldownSlice(qreal value, QString prefix, QSeries* drilldownSeries)
17 17 :m_drilldownSeries(drilldownSeries),
18 18 m_prefix(prefix)
19 19 {
20 20 setValue(value);
21 21 setLabelVisible(true);
22 22 updateLabel();
23 23 connect(this, SIGNAL(changed()), this, SLOT(updateLabel()));
24 24 }
25 25
26 26 QSeries* drilldownSeries() const { return m_drilldownSeries; }
27 27
28 28 public Q_SLOTS:
29 29 void updateLabel()
30 30 {
31 31 QString label = m_prefix;
32 32 label += " " + QString::number(this->value())+ "e (";
33 33 label += QString::number(this->percentage()*100, 'f', 1) + "%)";
34 34 setLabel(label);
35 35 }
36 36
37 37 private:
38 38 QSeries* m_drilldownSeries;
39 39 QString m_prefix;
40 40 };
41 41
42 class DrilldownChart : public QChartView
42 class DrilldownChart : public QChart
43 43 {
44 44 Q_OBJECT
45 45 public:
46 explicit DrilldownChart(QWidget *parent = 0):QChartView(parent), m_currentSeries(0) {}
46 explicit DrilldownChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0):QChart(parent, wFlags), m_currentSeries(0) {}
47 47
48 48 void changeSeries(QSeries* series)
49 49 {
50 50 // NOTE: if the series is owned by the chart it will be deleted
51 51 // here the "window" owns the series...
52 52 if (m_currentSeries)
53 53 removeSeries(m_currentSeries);
54 54 m_currentSeries = series;
55 55 addSeries(series);
56 setChartTitle(series->name());
56 setTitle(series->name());
57 57 }
58 58
59 59 public Q_SLOTS:
60 60 void handleSliceClicked(QPieSlice* slice)
61 61 {
62 62 DrilldownSlice* drilldownSlice = static_cast<DrilldownSlice*>(slice);
63 63 changeSeries(drilldownSlice->drilldownSeries());
64 64 }
65 65
66 66 private:
67 67 QSeries* m_currentSeries;
68 68 };
69 69
70 70 int main(int argc, char *argv[])
71 71 {
72 72 QApplication a(argc, argv);
73 73
74 74 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
75 75
76 76 QMainWindow window;
77 77
78 DrilldownChart* drilldownChart = new DrilldownChart(&window);
79 drilldownChart->setRenderHint(QPainter::Antialiasing);
80 drilldownChart->setChartTheme(QChart::ChartThemeLight);
78 DrilldownChart* drilldownChart = new DrilldownChart();
79 drilldownChart->setTheme(QChart::ChartThemeLight);
81 80 drilldownChart->setAnimationOptions(QChart::AllAnimations);
82 81
83 82 QPieSeries* yearSeries = new QPieSeries(&window);
84 83 yearSeries->setName("Sales by year - All");
85 84
86 85 QList<QString> months;
87 86 months << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec";
88 87 QList<QString> names;
89 88 names << "Jane" << "John" << "Axel" << "Mary" << "Samantha" << "Bob";
90 89
91 90 foreach (QString name, names) {
92 91 QPieSeries* series = new QPieSeries(&window);
93 92 series->setName("Sales by month - " + name);
94 93
95 94 foreach (QString month, months)
96 95 *series << new DrilldownSlice(qrand() % 1000, month, yearSeries);
97 96
98 97 QObject::connect(series, SIGNAL(clicked(QPieSlice*, Qt::MouseButtons)), drilldownChart, SLOT(handleSliceClicked(QPieSlice*)));
99 98
100 99 *yearSeries << new DrilldownSlice(series->total(), name, series);
101 100 }
102 101
103 102 QObject::connect(yearSeries, SIGNAL(clicked(QPieSlice*, Qt::MouseButtons)), drilldownChart, SLOT(handleSliceClicked(QPieSlice*)));
104 103
105 104 drilldownChart->changeSeries(yearSeries);
106 105
107 window.setCentralWidget(drilldownChart);
106 QChartView* chartView = new QChartView(drilldownChart);
107 chartView->setRenderHint(QPainter::Antialiasing);
108 window.setCentralWidget(chartView);
108 109 window.resize(800, 600);
109 110 window.show();
110 111
111 112 return a.exec();
112 113 }
113 114
114 115 #include "main.moc"
General Comments 0
You need to be logged in to leave comments. Login now