|
@@
-36,11
+36,11
private:
|
|
36
|
36
|
//! [1]
|
|
37
|
37
|
|
|
38
|
38
|
//! [2]
|
|
39
|
|
class DrilldownChart : public QChartView
|
|
|
39
|
class DrilldownChart : public QChart
|
|
40
|
40
|
{
|
|
41
|
41
|
Q_OBJECT
|
|
42
|
42
|
public:
|
|
43
|
|
explicit DrilldownChart(QWidget *parent = 0) : QChartView(parent), m_currentSeries(0) {}
|
|
|
43
|
explicit DrilldownChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0) : QChart(parent, wFlags), m_currentSeries(0) {}
|
|
44
|
44
|
|
|
45
|
45
|
void changeSeries(QSeries* series)
|
|
46
|
46
|
{
|
|
@@
-48,11
+48,11
public:
|
|
48
|
48
|
removeSeries(m_currentSeries);
|
|
49
|
49
|
m_currentSeries = series;
|
|
50
|
50
|
addSeries(series);
|
|
51
|
|
setChartTitle(series->name());
|
|
|
51
|
setTitle(series->name());
|
|
52
|
52
|
}
|
|
53
|
53
|
|
|
54
|
54
|
public Q_SLOTS:
|
|
55
|
|
void handleRightClick(QBarSet *barset, QString category)
|
|
|
55
|
void handleClicked(QBarSet *barset, QString category, Qt::MouseButtons button)
|
|
56
|
56
|
{
|
|
57
|
57
|
Q_UNUSED(barset)
|
|
58
|
58
|
DrilldownBarSeries* series = static_cast<DrilldownBarSeries*> (sender());
|
|
@@
-69,8
+69,9
int main(int argc, char *argv[])
|
|
69
|
69
|
QApplication a(argc, argv);
|
|
70
|
70
|
QMainWindow window;
|
|
71
|
71
|
|
|
72
|
|
DrilldownChart* drilldownChart = new DrilldownChart(&window);
|
|
73
|
|
drilldownChart->setChartTheme(QChart::ChartThemeBlueIcy);
|
|
|
72
|
DrilldownChart* drilldownChart = new DrilldownChart();
|
|
|
73
|
drilldownChart->setTheme(QChart::ChartThemeBlueIcy);
|
|
|
74
|
drilldownChart->setAnimationOptions(QChart::SeriesAnimations);
|
|
74
|
75
|
|
|
75
|
76
|
//! [3]
|
|
76
|
77
|
// Define categories
|
|
@@
-101,11
+102,11
int main(int argc, char *argv[])
|
|
101
|
102
|
}
|
|
102
|
103
|
|
|
103
|
104
|
// Use right click signal to implement drilldown
|
|
104
|
|
QObject::connect(weeklySeries,SIGNAL(rightClicked(QBarSet*,QString)),drilldownChart,SLOT(handleRightClick(QBarSet*,QString)));
|
|
|
105
|
QObject::connect(weeklySeries, SIGNAL(clicked(QBarSet*,QString,Qt::MouseButtons)), drilldownChart, SLOT(handleClicked(QBarSet*,QString,Qt::MouseButtons)));
|
|
105
|
106
|
}
|
|
106
|
107
|
|
|
107
|
108
|
// Enable drilldown from season series using right click.
|
|
108
|
|
QObject::connect(seasonSeries,SIGNAL(rightClicked(QBarSet*,QString)),drilldownChart,SLOT(handleRightClick(QBarSet*,QString)));
|
|
|
109
|
QObject::connect(seasonSeries, SIGNAL(clicked(QBarSet*,QString,Qt::MouseButtons)), drilldownChart, SLOT(handleClicked(QBarSet*,QString,Qt::MouseButtons)));
|
|
109
|
110
|
//! [4]
|
|
110
|
111
|
|
|
111
|
112
|
//! [5]
|
|
@@
-114,18
+115,14
int main(int argc, char *argv[])
|
|
114
|
115
|
QBarSet* monthlyCrop = new QBarSet(plant);
|
|
115
|
116
|
foreach (QString month, months) {
|
|
116
|
117
|
QBarSet* weeklyCrop = new QBarSet(plant);
|
|
117
|
|
foreach (QString week, weeks ) {
|
|
|
118
|
foreach (QString week, weeks )
|
|
118
|
119
|
*weeklyCrop << (qrand() % 20);
|
|
119
|
|
}
|
|
120
|
120
|
// Get the drilldown series from season series and add crop to it.
|
|
121
|
|
seasonSeries->drilldownSeries(month)->addBarSet(weeklyCrop);
|
|
|
121
|
seasonSeries->drilldownSeries(month)->appendBarSet(weeklyCrop);
|
|
122
|
122
|
seasonSeries->drilldownSeries(month)->setToolTipEnabled(true);
|
|
123
|
123
|
*monthlyCrop << weeklyCrop->total();
|
|
124
|
|
|
|
125
|
|
QObject::connect(weeklyCrop,SIGNAL(clicked(QString)),weeklyCrop,SIGNAL(toggleFloatingValues()));
|
|
126
|
124
|
}
|
|
127
|
|
seasonSeries->addBarSet(monthlyCrop);
|
|
128
|
|
QObject::connect(monthlyCrop,SIGNAL(clicked(QString)),monthlyCrop,SIGNAL(toggleFloatingValues()));
|
|
|
125
|
seasonSeries->appendBarSet(monthlyCrop);
|
|
129
|
126
|
}
|
|
130
|
127
|
//! [5]
|
|
131
|
128
|
|
|
@@
-134,12
+131,13
int main(int argc, char *argv[])
|
|
134
|
131
|
//! [6]
|
|
135
|
132
|
// Show season series in initial view
|
|
136
|
133
|
drilldownChart->changeSeries(seasonSeries);
|
|
137
|
|
drilldownChart->setChartTitle(seasonSeries->name());
|
|
|
134
|
drilldownChart->setTitle(seasonSeries->name());
|
|
138
|
135
|
//! [6]
|
|
139
|
136
|
|
|
140
|
137
|
drilldownChart->axisX()->setGridLineVisible(false);
|
|
141
|
138
|
|
|
142
|
|
window.setCentralWidget(drilldownChart);
|
|
|
139
|
QChartView *chartView = new QChartView(drilldownChart);
|
|
|
140
|
window.setCentralWidget(chartView);
|
|
143
|
141
|
window.resize(400, 300);
|
|
144
|
142
|
window.show();
|
|
145
|
143
|
|