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