@@ -17,12 +17,14 class DrilldownBarSeries : public QStackedBarSeries | |||
|
17 | 17 | public: |
|
18 | 18 | DrilldownBarSeries(QStringList categories, QObject* parent=0) : QStackedBarSeries(categories,parent) {} |
|
19 | 19 | |
|
20 | /* | |
|
20 | ||
|
21 | 21 | public Q_SLOTS: |
|
22 | 22 | void handleRightClick(QBarSet *barset, QString category) |
|
23 | 23 | { |
|
24 | qDebug() << "DrilldownBarSeries::handleRightClick" << barset->name() << category; | |
|
25 | // mChart->changeSeries(this); | |
|
24 | 26 | } |
|
25 | */ | |
|
27 | ||
|
26 | 28 | }; |
|
27 | 29 | //! [1] |
|
28 | 30 | |
@@ -31,9 +33,12 class DrilldownBarSet : public QBarSet | |||
|
31 | 33 | { |
|
32 | 34 | Q_OBJECT |
|
33 | 35 | public: |
|
34 |
DrilldownBarSet(QString name, DrilldownBarSeries |
|
|
36 | DrilldownBarSet(QString name, DrilldownBarSeries* drilldownSeries) : QBarSet(name) , mSeries(drilldownSeries) {} | |
|
35 | 37 | |
|
36 |
DrilldownBarSeries* drilldownSeries() |
|
|
38 | DrilldownBarSeries* drilldownSeries(QString category) | |
|
39 | { | |
|
40 | return mSeries; | |
|
41 | } | |
|
37 | 42 | |
|
38 | 43 | private: |
|
39 | 44 | DrilldownBarSeries* mSeries; |
@@ -61,8 +66,8 public Q_SLOTS: | |||
|
61 | 66 | { |
|
62 | 67 | qDebug() << "DrilldownChart::handleRightClick" << barset->name() << category; |
|
63 | 68 | // TODO: continue from here |
|
64 |
|
|
|
65 |
|
|
|
69 | DrilldownBarSet* drilldownBarSet = static_cast<DrilldownBarSet*>(barset); | |
|
70 | changeSeries(drilldownBarSet->drilldownSeries(category)); | |
|
66 | 71 | } |
|
67 | 72 | |
|
68 | 73 | private: |
@@ -70,7 +75,6 private: | |||
|
70 | 75 | }; |
|
71 | 76 | //! [3] |
|
72 | 77 | |
|
73 | ||
|
74 | 78 | int main(int argc, char *argv[]) |
|
75 | 79 | { |
|
76 | 80 | QApplication a(argc, argv); |
@@ -79,41 +83,68 int main(int argc, char *argv[]) | |||
|
79 | 83 | DrilldownChart* drilldownChart = new DrilldownChart(&window); |
|
80 | 84 | drilldownChart->setChartTheme(QChart::ChartThemeIcy); |
|
81 | 85 | |
|
82 |
//! [ |
|
|
86 | //! [4] | |
|
83 | 87 | // Define categories |
|
84 | 88 | QStringList months; |
|
85 |
months << "Jun" << "Jul" << "Aug" << " |
|
|
89 | months << "Jun" << "Jul" << "Aug" << "Sep"; | |
|
86 | 90 | QStringList weeks; |
|
87 | 91 | weeks << "week 1" << "week 2" << "week 3" << "week 4"; |
|
88 | 92 | QStringList plants; |
|
89 | 93 | plants << "Habanero" << "Lemon Drop" << "Starfish" << "Aji Amarillo"; |
|
90 |
//! [ |
|
|
94 | //! [4] | |
|
91 | 95 | |
|
92 |
DrilldownBarSeries* |
|
|
93 |
|
|
|
96 | DrilldownBarSeries* monthlySeries = new DrilldownBarSeries(months, drilldownChart); | |
|
97 | monthlySeries->setTitle("Crop by month - Season"); | |
|
94 | 98 | |
|
95 | 99 | foreach (QString plant, plants) { |
|
96 |
DrilldownBarSe |
|
|
100 | DrilldownBarSeries* weeklySeries = new DrilldownBarSeries(weeks, drilldownChart); | |
|
101 | DrilldownBarSet* monthlyCrop = new DrilldownBarSet(plant,weeklySeries); | |
|
102 | weeklySeries->setTitle("Crop by week - Month"); | |
|
103 | ||
|
97 | 104 | foreach(QString month, months) { |
|
98 |
DrilldownBarSe |
|
|
99 | DrilldownBarSet *monthCrop = new DrilldownBarSet(plant, monthSeries); | |
|
105 | DrilldownBarSet* weeklyCrop = new DrilldownBarSet(plant,monthlySeries); | |
|
106 | ||
|
100 | 107 | foreach(QString week, weeks) { |
|
101 |
* |
|
|
102 | } | |
|
103 | monthSeries->addBarSet(monthCrop); | |
|
104 | *seasonCrop << monthCrop->valueAt(plants.indexOf(plant)); | |
|
108 | *weeklyCrop << (qrand() % 20); | |
|
105 | 109 | } |
|
106 | 110 | |
|
107 | // We want floating values! | |
|
108 | QObject::connect(seasonCrop,SIGNAL(clicked(QString)),seasonCrop,SIGNAL(toggleFloatingValues())); | |
|
109 | seasonSeries->addBarSet(seasonCrop); | |
|
111 | weeklySeries->addBarSet(weeklyCrop); | |
|
112 | weeklySeries->setToolTipEnabled(true); | |
|
113 | *monthlyCrop << weeklyCrop->total(); | |
|
114 | ||
|
115 | QObject::connect(weeklyCrop,SIGNAL(clicked(QString)),weeklyCrop,SIGNAL(toggleFloatingValues())); | |
|
116 | QObject::connect(weeklySeries,SIGNAL(rightClicked(QBarSet*,QString)),drilldownChart,SLOT(handleRightClick(QBarSet*,QString))); | |
|
110 | 117 | } |
|
111 | 118 | |
|
112 | QObject::connect(seasonSeries,SIGNAL(rightClicked(QBarSet*,QString)),drilldownChart,SLOT(handleRightClick(QBarSet*,QString))); | |
|
119 | QObject::connect(monthlyCrop,SIGNAL(clicked(QString)),monthlyCrop,SIGNAL(toggleFloatingValues())); | |
|
120 | monthlySeries->addBarSet(monthlyCrop); | |
|
121 | } | |
|
113 | 122 | |
|
114 | seasonSeries->setToolTipEnabled(true); | |
|
123 | /* | |
|
124 | 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"); | |
|
128 | foreach(QString month, months) { | |
|
129 | DrilldownBarSet* weeklyCrop = new DrilldownBarSet(plant,monthlySeries); | |
|
130 | foreach (QString week, weeks ) { | |
|
131 | *weeklyCrop << (qrand() % 20); | |
|
132 | } | |
|
133 | weeklySeries->addBarSet(weeklyCrop); | |
|
134 | weeklySeries->setToolTipEnabled(true); | |
|
135 | *monthlyCrop << weeklyCrop->total(); | |
|
136 | QObject::connect(weeklyCrop,SIGNAL(clicked(QString)),weeklyCrop,SIGNAL(toggleFloatingValues())); | |
|
137 | QObject::connect(weeklySeries,SIGNAL(rightClicked(QBarSet*,QString)),drilldownChart,SLOT(handleRightClick(QBarSet*,QString))); | |
|
138 | } | |
|
139 | QObject::connect(monthlyCrop,SIGNAL(clicked(QString)),monthlyCrop,SIGNAL(toggleFloatingValues())); | |
|
140 | monthlySeries->addBarSet(monthlyCrop); | |
|
141 | } | |
|
142 | */ | |
|
143 | QObject::connect(monthlySeries,SIGNAL(rightClicked(QBarSet*,QString)),drilldownChart,SLOT(handleRightClick(QBarSet*,QString))); | |
|
115 | 144 | |
|
116 | drilldownChart->addSeries(seasonSeries); | |
|
145 | monthlySeries->setToolTipEnabled(true); | |
|
146 | drilldownChart->changeSeries(monthlySeries); | |
|
147 | drilldownChart->setChartTitle(monthlySeries->title()); | |
|
117 | 148 | |
|
118 | 149 | drilldownChart->axisX()->setAxisVisible(false); |
|
119 | 150 | drilldownChart->axisX()->setGridVisible(false); |
@@ -26,7 +26,6 BarPresenterBase::BarPresenterBase(QBarSeries *series, QGraphicsItem *parent) | |||
|
26 | 26 | BarPresenterBase::~BarPresenterBase() |
|
27 | 27 | { |
|
28 | 28 | disconnect(this,SLOT(showToolTip(QPoint,QString))); |
|
29 | delete mSeries; | |
|
30 | 29 | } |
|
31 | 30 | |
|
32 | 31 | void BarPresenterBase::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
@@ -21,7 +21,7 class BarPresenterBase : public QObject, public ChartItem | |||
|
21 | 21 | Q_OBJECT |
|
22 | 22 | public: |
|
23 | 23 | BarPresenterBase(QBarSeries *series, QGraphicsItem *parent = 0); |
|
24 | ~BarPresenterBase(); | |
|
24 | virtual ~BarPresenterBase(); | |
|
25 | 25 | |
|
26 | 26 | public: |
|
27 | 27 | // From QGraphicsItem |
@@ -109,6 +109,16 void QBarSet::setValue(int index, qreal value) | |||
|
109 | 109 | mValues.replace(index,value); |
|
110 | 110 | } |
|
111 | 111 | |
|
112 | qreal QBarSet::total() | |
|
113 | { | |
|
114 | qreal total(0); | |
|
115 | for (int i=0; i<mValues.count(); i++) { | |
|
116 | total += mValues.at(i); | |
|
117 | } | |
|
118 | return total; | |
|
119 | } | |
|
120 | ||
|
121 | ||
|
112 | 122 | /*! |
|
113 | 123 | Sets pen for set. Bars of this set are drawn using \a pen |
|
114 | 124 | */ |
@@ -21,6 +21,7 public: | |||
|
21 | 21 | int count(); // count of values in set |
|
22 | 22 | qreal valueAt(int index); // for modifying individual values |
|
23 | 23 | void setValue(int index, qreal value); // setter for individual value |
|
24 | qreal total(); // total values in the set | |
|
24 | 25 | |
|
25 | 26 | // TODO: |
|
26 | 27 | //qreal value(QString category); |
@@ -13,6 +13,12 StackedBarPresenter::StackedBarPresenter(QBarSeries *series, QGraphicsItem *pare | |||
|
13 | 13 | { |
|
14 | 14 | } |
|
15 | 15 | |
|
16 | StackedBarPresenter::~StackedBarPresenter() | |
|
17 | { | |
|
18 | qDebug() << "StackedBarPresenter deleted"; | |
|
19 | } | |
|
20 | ||
|
21 | ||
|
16 | 22 | void StackedBarPresenter::layoutChanged() |
|
17 | 23 | { |
|
18 | 24 | // Scale bars to new layout |
General Comments 0
You need to be logged in to leave comments.
Login now