##// END OF EJS Templates
Remove debug from piechartdrilldown
Jani Honkonen -
r407:af4c2c854faa
parent child
Show More
@@ -1,126 +1,125
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 qDebug() << "updateLabel" << label;
35 setLabel(label);
34 setLabel(label);
36 }
35 }
37
36
38 private:
37 private:
39 QSeries* m_drilldownSeries;
38 QSeries* m_drilldownSeries;
40 QString m_prefix;
39 QString m_prefix;
41 };
40 };
42
41
43 class DrilldownChart : public QChartView
42 class DrilldownChart : public QChartView
44 {
43 {
45 Q_OBJECT
44 Q_OBJECT
46 public:
45 public:
47 explicit DrilldownChart(QWidget *parent = 0):QChartView(parent), m_currentSeries(0) {}
46 explicit DrilldownChart(QWidget *parent = 0):QChartView(parent), m_currentSeries(0) {}
48
47
49 void changeSeries(QSeries* series)
48 void changeSeries(QSeries* series)
50 {
49 {
51 if (m_currentSeries)
50 if (m_currentSeries)
52 removeSeries(m_currentSeries);
51 removeSeries(m_currentSeries);
53 m_currentSeries = series;
52 m_currentSeries = series;
54 addSeries(series);
53 addSeries(series);
55 setChartTitle(series->title());
54 setChartTitle(series->title());
56 }
55 }
57
56
58 public Q_SLOTS:
57 public Q_SLOTS:
59 void handleSliceClicked(QPieSlice* slice)
58 void handleSliceClicked(QPieSlice* slice)
60 {
59 {
61 DrilldownSlice* drilldownSlice = static_cast<DrilldownSlice*>(slice);
60 DrilldownSlice* drilldownSlice = static_cast<DrilldownSlice*>(slice);
62 changeSeries(drilldownSlice->drilldownSeries());
61 changeSeries(drilldownSlice->drilldownSeries());
63 }
62 }
64
63
65 private:
64 private:
66 QSeries* m_currentSeries;
65 QSeries* m_currentSeries;
67 };
66 };
68
67
69 int main(int argc, char *argv[])
68 int main(int argc, char *argv[])
70 {
69 {
71 QApplication a(argc, argv);
70 QApplication a(argc, argv);
72
71
73 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
72 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
74
73
75 QMainWindow window;
74 QMainWindow window;
76
75
77 DrilldownChart* drilldownChart = new DrilldownChart(&window);
76 DrilldownChart* drilldownChart = new DrilldownChart(&window);
78 drilldownChart->setRenderHint(QPainter::Antialiasing);
77 drilldownChart->setRenderHint(QPainter::Antialiasing);
79 drilldownChart->setChartTheme(QChart::ChartThemeVanilla);
78 drilldownChart->setChartTheme(QChart::ChartThemeVanilla);
80
79
81 QPieSeries* yearSeries = new QPieSeries(drilldownChart);
80 QPieSeries* yearSeries = new QPieSeries(drilldownChart);
82 yearSeries->setTitle("Sales by year - All");
81 yearSeries->setTitle("Sales by year - All");
83 yearSeries->setHoverHighlighting();
82 yearSeries->setHoverHighlighting();
84
83
85 QList<QString> months;
84 QList<QString> months;
86 months << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec";
85 months << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec";
87
86
88 int max = 1000;
87 int max = 1000;
89
88
90 QPieSeries* monthSeriesJane = new QPieSeries(drilldownChart);
89 QPieSeries* monthSeriesJane = new QPieSeries(drilldownChart);
91 monthSeriesJane->setTitle("Sales by month - Jane");
90 monthSeriesJane->setTitle("Sales by month - Jane");
92 monthSeriesJane->setHoverHighlighting();
91 monthSeriesJane->setHoverHighlighting();
93 foreach (QString month, months)
92 foreach (QString month, months)
94 *monthSeriesJane << new DrilldownSlice(qrand() % max, month, yearSeries);
93 *monthSeriesJane << new DrilldownSlice(qrand() % max, month, yearSeries);
95
94
96 QPieSeries* monthSeriesJohn = new QPieSeries(drilldownChart);
95 QPieSeries* monthSeriesJohn = new QPieSeries(drilldownChart);
97 monthSeriesJohn->setTitle("Sales by month - John");
96 monthSeriesJohn->setTitle("Sales by month - John");
98 monthSeriesJohn->setHoverHighlighting();
97 monthSeriesJohn->setHoverHighlighting();
99 foreach (QString month, months)
98 foreach (QString month, months)
100 *monthSeriesJohn << new DrilldownSlice(qrand() % max, month, yearSeries);
99 *monthSeriesJohn << new DrilldownSlice(qrand() % max, month, yearSeries);
101
100
102 QPieSeries* monthSeriesAxel = new QPieSeries(drilldownChart);
101 QPieSeries* monthSeriesAxel = new QPieSeries(drilldownChart);
103 monthSeriesAxel->setTitle("Sales by month - Axel");
102 monthSeriesAxel->setTitle("Sales by month - Axel");
104 monthSeriesAxel->setHoverHighlighting();
103 monthSeriesAxel->setHoverHighlighting();
105 foreach (QString month, months)
104 foreach (QString month, months)
106 *monthSeriesAxel << new DrilldownSlice(qrand() % max, month, yearSeries);
105 *monthSeriesAxel << new DrilldownSlice(qrand() % max, month, yearSeries);
107
106
108 *yearSeries << new DrilldownSlice(monthSeriesJane->total(), "Jane", monthSeriesJane);
107 *yearSeries << new DrilldownSlice(monthSeriesJane->total(), "Jane", monthSeriesJane);
109 *yearSeries << new DrilldownSlice(monthSeriesJohn->total(), "John", monthSeriesJohn);
108 *yearSeries << new DrilldownSlice(monthSeriesJohn->total(), "John", monthSeriesJohn);
110 *yearSeries << new DrilldownSlice(monthSeriesAxel->total(), "Axel", monthSeriesAxel);
109 *yearSeries << new DrilldownSlice(monthSeriesAxel->total(), "Axel", monthSeriesAxel);
111
110
112 QObject::connect(monthSeriesJane, SIGNAL(clicked(QPieSlice*)), drilldownChart, SLOT(handleSliceClicked(QPieSlice*)));
111 QObject::connect(monthSeriesJane, SIGNAL(clicked(QPieSlice*)), drilldownChart, SLOT(handleSliceClicked(QPieSlice*)));
113 QObject::connect(monthSeriesJohn, SIGNAL(clicked(QPieSlice*)), drilldownChart, SLOT(handleSliceClicked(QPieSlice*)));
112 QObject::connect(monthSeriesJohn, SIGNAL(clicked(QPieSlice*)), drilldownChart, SLOT(handleSliceClicked(QPieSlice*)));
114 QObject::connect(monthSeriesAxel, SIGNAL(clicked(QPieSlice*)), drilldownChart, SLOT(handleSliceClicked(QPieSlice*)));
113 QObject::connect(monthSeriesAxel, SIGNAL(clicked(QPieSlice*)), drilldownChart, SLOT(handleSliceClicked(QPieSlice*)));
115 QObject::connect(yearSeries, SIGNAL(clicked(QPieSlice*)), drilldownChart, SLOT(handleSliceClicked(QPieSlice*)));
114 QObject::connect(yearSeries, SIGNAL(clicked(QPieSlice*)), drilldownChart, SLOT(handleSliceClicked(QPieSlice*)));
116
115
117 drilldownChart->changeSeries(yearSeries);
116 drilldownChart->changeSeries(yearSeries);
118
117
119 window.setCentralWidget(drilldownChart);
118 window.setCentralWidget(drilldownChart);
120 window.resize(600, 600);
119 window.resize(600, 600);
121 window.show();
120 window.show();
122
121
123 return a.exec();
122 return a.exec();
124 }
123 }
125
124
126 #include "main.moc"
125 #include "main.moc"
General Comments 0
You need to be logged in to leave comments. Login now