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