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