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