@@ -15,37 +15,28 class DrilldownBarSeries : public QStackedBarSeries | |||||
15 | { |
|
15 | { | |
16 | Q_OBJECT |
|
16 | Q_OBJECT | |
17 | public: |
|
17 | public: | |
18 |
DrilldownBarSeries(QStringList categories, QObject* |
|
18 | DrilldownBarSeries(QStringList categories, QObject *parent = 0) : QStackedBarSeries(categories,parent) {} | |
19 |
|
19 | |||
20 |
|
20 | void addDrilldownSeries(QString category, DrilldownBarSeries* drilldownSeries) | ||
21 | public Q_SLOTS: |
|
|||
22 | void handleRightClick(QBarSet *barset, QString category) |
|
|||
23 | { |
|
21 | { | |
24 | qDebug() << "DrilldownBarSeries::handleRightClick" << barset->name() << category; |
|
22 | mDrilldownSeries[category] = drilldownSeries; | |
25 | // mChart->changeSeries(this); |
|
|||
26 | } |
|
23 | } | |
27 |
|
24 | |||
28 | }; |
|
|||
29 | //! [1] |
|
|||
30 |
|
||||
31 | //! [2] |
|
|||
32 | class DrilldownBarSet : public QBarSet |
|
|||
33 | { |
|
|||
34 | Q_OBJECT |
|
|||
35 | public: |
|
|||
36 | DrilldownBarSet(QString name, DrilldownBarSeries* drilldownSeries) : QBarSet(name) , mSeries(drilldownSeries) {} |
|
|||
37 |
|
||||
38 | DrilldownBarSeries* drilldownSeries(QString category) |
|
25 | DrilldownBarSeries* drilldownSeries(QString category) | |
39 |
|
|
26 | { | |
40 | return mSeries; |
|
27 | // qDebug() << "DrilldownBarSeries::drilldownSeries" << category << mDrilldownSeries[category]; | |
41 | } |
|
28 | return mDrilldownSeries[category]; | |
|
29 | } | |||
|
30 | ||||
|
31 | public Q_SLOTS: | |||
42 |
|
32 | |||
43 | private: |
|
33 | private: | |
44 | DrilldownBarSeries* mSeries; |
|
34 | ||
|
35 | QMap<QString, DrilldownBarSeries*> mDrilldownSeries; | |||
45 | }; |
|
36 | }; | |
46 |
//! [ |
|
37 | //! [1] | |
47 |
|
38 | |||
48 |
//! [ |
|
39 | //! [2] | |
49 | class DrilldownChart : public QChartView |
|
40 | class DrilldownChart : public QChartView | |
50 | { |
|
41 | { | |
51 | Q_OBJECT |
|
42 | Q_OBJECT | |
@@ -66,14 +57,14 public Q_SLOTS: | |||||
66 | { |
|
57 | { | |
67 | qDebug() << "DrilldownChart::handleRightClick" << barset->name() << category; |
|
58 | qDebug() << "DrilldownChart::handleRightClick" << barset->name() << category; | |
68 | // TODO: continue from here |
|
59 | // TODO: continue from here | |
69 |
DrilldownBarSe |
|
60 | DrilldownBarSeries* series = static_cast<DrilldownBarSeries*> (sender()); | |
70 |
changeSeries( |
|
61 | changeSeries(series->drilldownSeries(category)); | |
71 | } |
|
62 | } | |
72 |
|
63 | |||
73 | private: |
|
64 | private: | |
74 | QSeries* m_currentSeries; |
|
65 | QSeries* m_currentSeries; | |
75 | }; |
|
66 | }; | |
76 |
//! [ |
|
67 | //! [2] | |
77 |
|
68 | |||
78 | int main(int argc, char *argv[]) |
|
69 | int main(int argc, char *argv[]) | |
79 | { |
|
70 | { | |
@@ -83,7 +74,7 int main(int argc, char *argv[]) | |||||
83 | DrilldownChart* drilldownChart = new DrilldownChart(&window); |
|
74 | DrilldownChart* drilldownChart = new DrilldownChart(&window); | |
84 | drilldownChart->setChartTheme(QChart::ChartThemeIcy); |
|
75 | drilldownChart->setChartTheme(QChart::ChartThemeIcy); | |
85 |
|
76 | |||
86 |
//! [ |
|
77 | //! [3] | |
87 | // Define categories |
|
78 | // Define categories | |
88 | QStringList months; |
|
79 | QStringList months; | |
89 | months << "Jun" << "Jul" << "Aug" << "Sep"; |
|
80 | months << "Jun" << "Jul" << "Aug" << "Sep"; | |
@@ -91,61 +82,62 int main(int argc, char *argv[]) | |||||
91 | weeks << "week 1" << "week 2" << "week 3" << "week 4"; |
|
82 | weeks << "week 1" << "week 2" << "week 3" << "week 4"; | |
92 | QStringList plants; |
|
83 | QStringList plants; | |
93 | plants << "Habanero" << "Lemon Drop" << "Starfish" << "Aji Amarillo"; |
|
84 | plants << "Habanero" << "Lemon Drop" << "Starfish" << "Aji Amarillo"; | |
|
85 | //! [3] | |||
|
86 | ||||
94 | //! [4] |
|
87 | //! [4] | |
|
88 | // Create drilldown structure | |||
|
89 | DrilldownBarSeries* seasonSeries = new DrilldownBarSeries(months, drilldownChart); | |||
|
90 | seasonSeries->setTitle("Crop by month - Season"); | |||
95 |
|
91 | |||
96 | DrilldownBarSeries* monthlySeries = new DrilldownBarSeries(months, drilldownChart); |
|
92 | // Each month in season series has drilldown series for weekly data | |
97 | monthlySeries->setTitle("Crop by month - Season"); |
|
93 | foreach (QString month, months) { | |
98 |
|
94 | |||
99 | foreach (QString plant, plants) { |
|
95 | // Create drilldown series for every week | |
100 | DrilldownBarSeries* weeklySeries = new DrilldownBarSeries(weeks, drilldownChart); |
|
96 | DrilldownBarSeries* weeklySeries = new DrilldownBarSeries(weeks, drilldownChart); | |
101 | DrilldownBarSet* monthlyCrop = new DrilldownBarSet(plant,weeklySeries); |
|
97 | seasonSeries->addDrilldownSeries(month, weeklySeries); | |
102 | weeklySeries->setTitle("Crop by week - Month"); |
|
|||
103 |
|
||||
104 | foreach(QString month, months) { |
|
|||
105 | DrilldownBarSet* weeklyCrop = new DrilldownBarSet(plant,monthlySeries); |
|
|||
106 |
|
||||
107 | foreach (QString week, weeks ) { |
|
|||
108 | *weeklyCrop << (qrand() % 20); |
|
|||
109 | } |
|
|||
110 |
|
98 | |||
111 | weeklySeries->addBarSet(weeklyCrop); |
|
99 | // Drilling down from weekly data brings us back to season data. | |
112 | weeklySeries->setToolTipEnabled(true); |
|
100 | foreach (QString week, weeks) { | |
113 | *monthlyCrop << weeklyCrop->total(); |
|
101 | weeklySeries->addDrilldownSeries(week, seasonSeries); | |
114 |
|
102 | weeklySeries->setTitle(QString("Crop by week - " + month)); | ||
115 | QObject::connect(weeklyCrop,SIGNAL(clicked(QString)),weeklyCrop,SIGNAL(toggleFloatingValues())); |
|
|||
116 | QObject::connect(weeklySeries,SIGNAL(rightClicked(QBarSet*,QString)),drilldownChart,SLOT(handleRightClick(QBarSet*,QString))); |
|
|||
117 | } |
|
103 | } | |
118 |
|
104 | |||
119 | QObject::connect(monthlyCrop,SIGNAL(clicked(QString)),monthlyCrop,SIGNAL(toggleFloatingValues())); |
|
105 | // Use right click signal to implement drilldown | |
120 | monthlySeries->addBarSet(monthlyCrop); |
|
106 | QObject::connect(weeklySeries,SIGNAL(rightClicked(QBarSet*,QString)),drilldownChart,SLOT(handleRightClick(QBarSet*,QString))); | |
121 | } |
|
107 | } | |
|
108 | //! [4] | |||
122 |
|
109 | |||
123 | /* |
|
110 | //! [5] | |
|
111 | // Fill monthly and weekly series with data | |||
124 | foreach (QString plant, plants) { |
|
112 | foreach (QString plant, plants) { | |
125 | DrilldownBarSeries* weeklySeries = new DrilldownBarSeries(weeks, drilldownChart); |
|
113 | QBarSet* monthlyCrop = new QBarSet(plant); | |
126 | DrilldownBarSet* monthlyCrop = new DrilldownBarSet(plant,weeklySeries); |
|
114 | foreach (QString month, months) { | |
127 | weeklySeries->setTitle("Crop by week - Month"); |
|
115 | QBarSet* weeklyCrop = new QBarSet(plant); | |
128 | foreach(QString month, months) { |
|
|||
129 | DrilldownBarSet* weeklyCrop = new DrilldownBarSet(plant,monthlySeries); |
|
|||
130 | foreach (QString week, weeks ) { |
|
116 | foreach (QString week, weeks ) { | |
131 | *weeklyCrop << (qrand() % 20); |
|
117 | *weeklyCrop << (qrand() % 20); | |
132 | } |
|
118 | } | |
133 | weeklySeries->addBarSet(weeklyCrop); |
|
119 | // Get the drilldown series from upper level series and add crop to it. | |
134 | weeklySeries->setToolTipEnabled(true); |
|
120 | seasonSeries->drilldownSeries(month)->addBarSet(weeklyCrop); | |
|
121 | seasonSeries->drilldownSeries(month)->setToolTipEnabled(true); | |||
135 | *monthlyCrop << weeklyCrop->total(); |
|
122 | *monthlyCrop << weeklyCrop->total(); | |
|
123 | ||||
136 | QObject::connect(weeklyCrop,SIGNAL(clicked(QString)),weeklyCrop,SIGNAL(toggleFloatingValues())); |
|
124 | QObject::connect(weeklyCrop,SIGNAL(clicked(QString)),weeklyCrop,SIGNAL(toggleFloatingValues())); | |
137 | QObject::connect(weeklySeries,SIGNAL(rightClicked(QBarSet*,QString)),drilldownChart,SLOT(handleRightClick(QBarSet*,QString))); |
|
|||
138 | } |
|
125 | } | |
|
126 | seasonSeries->addBarSet(monthlyCrop); | |||
139 | QObject::connect(monthlyCrop,SIGNAL(clicked(QString)),monthlyCrop,SIGNAL(toggleFloatingValues())); |
|
127 | QObject::connect(monthlyCrop,SIGNAL(clicked(QString)),monthlyCrop,SIGNAL(toggleFloatingValues())); | |
140 | monthlySeries->addBarSet(monthlyCrop); |
|
|||
141 | } |
|
128 | } | |
142 | */ |
|
129 | //! [5] | |
143 | QObject::connect(monthlySeries,SIGNAL(rightClicked(QBarSet*,QString)),drilldownChart,SLOT(handleRightClick(QBarSet*,QString))); |
|
130 | ||
|
131 | seasonSeries->setToolTipEnabled(true); | |||
|
132 | ||||
|
133 | // Enable drilldown from season series using right click. | |||
|
134 | QObject::connect(seasonSeries,SIGNAL(rightClicked(QBarSet*,QString)),drilldownChart,SLOT(handleRightClick(QBarSet*,QString))); | |||
144 |
|
135 | |||
145 | monthlySeries->setToolTipEnabled(true); |
|
136 | // Show season series in initial view | |
146 |
drilldownChart->changeSeries( |
|
137 | drilldownChart->changeSeries(seasonSeries); | |
147 |
drilldownChart->setChartTitle( |
|
138 | drilldownChart->setChartTitle(seasonSeries->title()); | |
148 |
|
139 | |||
|
140 | // Disable axis, since they don't really apply to bar chart | |||
149 | drilldownChart->axisX()->setAxisVisible(false); |
|
141 | drilldownChart->axisX()->setAxisVisible(false); | |
150 | drilldownChart->axisX()->setGridVisible(false); |
|
142 | drilldownChart->axisX()->setGridVisible(false); | |
151 | drilldownChart->axisX()->setLabelsVisible(false); |
|
143 | drilldownChart->axisX()->setLabelsVisible(false); |
General Comments 0
You need to be logged in to leave comments.
Login now