@@ -0,0 +1,48 | |||||
|
1 | /**************************************************************************** | |||
|
2 | ** | |||
|
3 | ** Copyright (C) 2012 Digia Plc | |||
|
4 | ** All rights reserved. | |||
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |||
|
6 | ** | |||
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |||
|
8 | ** | |||
|
9 | ** $QT_BEGIN_LICENSE$ | |||
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |||
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |||
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |||
|
13 | ** a written agreement between you and Digia. | |||
|
14 | ** | |||
|
15 | ** If you have questions regarding the use of this file, please use | |||
|
16 | ** contact form at http://qt.digia.com | |||
|
17 | ** $QT_END_LICENSE$ | |||
|
18 | ** | |||
|
19 | ****************************************************************************/ | |||
|
20 | ||||
|
21 | #include "drilldownchart.h" | |||
|
22 | #include <QChartAxis> | |||
|
23 | ||||
|
24 | QTCOMMERCIALCHART_USE_NAMESPACE | |||
|
25 | ||||
|
26 | DrilldownChart::DrilldownChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) | |||
|
27 | : QChart(parent, wFlags) | |||
|
28 | ,m_currentSeries(0) | |||
|
29 | { | |||
|
30 | } | |||
|
31 | ||||
|
32 | void DrilldownChart::changeSeries(QSeries* series) | |||
|
33 | { | |||
|
34 | if (m_currentSeries) | |||
|
35 | removeSeries(m_currentSeries); | |||
|
36 | m_currentSeries = series; | |||
|
37 | addSeries(series); | |||
|
38 | setTitle(series->name()); | |||
|
39 | axisY()->setNiceNumbers(true); | |||
|
40 | } | |||
|
41 | ||||
|
42 | void DrilldownChart::handleClicked(QBarSet *barset, QString category, Qt::MouseButtons button) | |||
|
43 | { | |||
|
44 | Q_UNUSED(barset) | |||
|
45 | Q_UNUSED(button) | |||
|
46 | DrilldownBarSeries* series = static_cast<DrilldownBarSeries*> (sender()); | |||
|
47 | changeSeries(series->drilldownSeries(category)); | |||
|
48 | } |
@@ -0,0 +1,46 | |||||
|
1 | /**************************************************************************** | |||
|
2 | ** | |||
|
3 | ** Copyright (C) 2012 Digia Plc | |||
|
4 | ** All rights reserved. | |||
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |||
|
6 | ** | |||
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |||
|
8 | ** | |||
|
9 | ** $QT_BEGIN_LICENSE$ | |||
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |||
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |||
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |||
|
13 | ** a written agreement between you and Digia. | |||
|
14 | ** | |||
|
15 | ** If you have questions regarding the use of this file, please use | |||
|
16 | ** contact form at http://qt.digia.com | |||
|
17 | ** $QT_END_LICENSE$ | |||
|
18 | ** | |||
|
19 | ****************************************************************************/ | |||
|
20 | ||||
|
21 | #ifndef DRILLDOWNCHART_H | |||
|
22 | #define DRILLDOWNCHART_H | |||
|
23 | ||||
|
24 | #include <QChart> | |||
|
25 | #include "drilldownseries.h" | |||
|
26 | ||||
|
27 | QTCOMMERCIALCHART_USE_NAMESPACE | |||
|
28 | ||||
|
29 | //! [2] | |||
|
30 | class DrilldownChart : public QChart | |||
|
31 | { | |||
|
32 | Q_OBJECT | |||
|
33 | public: | |||
|
34 | explicit DrilldownChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); | |||
|
35 | ||||
|
36 | void changeSeries(QSeries* series); | |||
|
37 | ||||
|
38 | public Q_SLOTS: | |||
|
39 | void handleClicked(QBarSet *barset, QString category, Qt::MouseButtons button); | |||
|
40 | ||||
|
41 | private: | |||
|
42 | QSeries* m_currentSeries; | |||
|
43 | }; | |||
|
44 | //! [2] | |||
|
45 | ||||
|
46 | #endif // DRILLDOWNCHART_H |
@@ -0,0 +1,40 | |||||
|
1 | /**************************************************************************** | |||
|
2 | ** | |||
|
3 | ** Copyright (C) 2012 Digia Plc | |||
|
4 | ** All rights reserved. | |||
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |||
|
6 | ** | |||
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |||
|
8 | ** | |||
|
9 | ** $QT_BEGIN_LICENSE$ | |||
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |||
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |||
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |||
|
13 | ** a written agreement between you and Digia. | |||
|
14 | ** | |||
|
15 | ** If you have questions regarding the use of this file, please use | |||
|
16 | ** contact form at http://qt.digia.com | |||
|
17 | ** $QT_END_LICENSE$ | |||
|
18 | ** | |||
|
19 | ****************************************************************************/ | |||
|
20 | ||||
|
21 | #include "drilldownseries.h" | |||
|
22 | ||||
|
23 | QTCOMMERCIALCHART_USE_NAMESPACE | |||
|
24 | ||||
|
25 | DrilldownBarSeries::DrilldownBarSeries(QStringList categories, QObject *parent) | |||
|
26 | : QStackedBarSeries(categories, parent) | |||
|
27 | { | |||
|
28 | } | |||
|
29 | ||||
|
30 | void DrilldownBarSeries::mapDrilldownSeries(QString category, DrilldownBarSeries* drilldownSeries) | |||
|
31 | { | |||
|
32 | mDrilldownSeries[category] = drilldownSeries; | |||
|
33 | } | |||
|
34 | ||||
|
35 | DrilldownBarSeries* DrilldownBarSeries::drilldownSeries(QString category) | |||
|
36 | { | |||
|
37 | return mDrilldownSeries[category]; | |||
|
38 | } | |||
|
39 | ||||
|
40 | #include "moc_drilldownseries.cpp" |
@@ -0,0 +1,45 | |||||
|
1 | /**************************************************************************** | |||
|
2 | ** | |||
|
3 | ** Copyright (C) 2012 Digia Plc | |||
|
4 | ** All rights reserved. | |||
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |||
|
6 | ** | |||
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |||
|
8 | ** | |||
|
9 | ** $QT_BEGIN_LICENSE$ | |||
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |||
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |||
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |||
|
13 | ** a written agreement between you and Digia. | |||
|
14 | ** | |||
|
15 | ** If you have questions regarding the use of this file, please use | |||
|
16 | ** contact form at http://qt.digia.com | |||
|
17 | ** $QT_END_LICENSE$ | |||
|
18 | ** | |||
|
19 | ****************************************************************************/ | |||
|
20 | ||||
|
21 | #ifndef DRILLDOWNSERIES_H | |||
|
22 | #define DRILLDOWNSERIES_H | |||
|
23 | ||||
|
24 | #include <QStackedBarSeries> | |||
|
25 | #include <QMap> | |||
|
26 | ||||
|
27 | QTCOMMERCIALCHART_USE_NAMESPACE | |||
|
28 | ||||
|
29 | //! [1] | |||
|
30 | class DrilldownBarSeries : public QStackedBarSeries | |||
|
31 | { | |||
|
32 | Q_OBJECT | |||
|
33 | public: | |||
|
34 | DrilldownBarSeries(QStringList categories, QObject *parent = 0); | |||
|
35 | ||||
|
36 | void mapDrilldownSeries(QString category, DrilldownBarSeries* drilldownSeries); | |||
|
37 | ||||
|
38 | DrilldownBarSeries* drilldownSeries(QString category); | |||
|
39 | ||||
|
40 | private: | |||
|
41 | QMap<QString, DrilldownBarSeries*> mDrilldownSeries; | |||
|
42 | }; | |||
|
43 | //! [1] | |||
|
44 | ||||
|
45 | #endif // DRILLDOWNSERIES_H |
@@ -21,73 +21,13 | |||||
21 | #include <QtGui/QApplication> |
|
21 | #include <QtGui/QApplication> | |
22 | #include <QMainWindow> |
|
22 | #include <QMainWindow> | |
23 | #include <QChartView> |
|
23 | #include <QChartView> | |
24 | #include <QStackedBarSeries> |
|
|||
25 | #include <QBarSet> |
|
24 | #include <QBarSet> | |
26 | #include <QLegend> |
|
25 | #include <QLegend> | |
|
26 | #include "drilldownseries.h" | |||
|
27 | #include "drilldownchart.h" | |||
27 |
|
28 | |||
28 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
29 | QTCOMMERCIALCHART_USE_NAMESPACE | |
29 |
|
30 | |||
30 | //! [1] |
|
|||
31 | class DrilldownBarSeries : public QStackedBarSeries |
|
|||
32 | { |
|
|||
33 | Q_OBJECT |
|
|||
34 | public: |
|
|||
35 | DrilldownBarSeries(QStringList categories, QObject *parent = 0) |
|
|||
36 | :QStackedBarSeries(categories, parent) |
|
|||
37 | { |
|
|||
38 |
|
||||
39 | } |
|
|||
40 |
|
||||
41 | void mapDrilldownSeries(QString category, DrilldownBarSeries* drilldownSeries) |
|
|||
42 | { |
|
|||
43 | mDrilldownSeries[category] = drilldownSeries; |
|
|||
44 | } |
|
|||
45 |
|
||||
46 | DrilldownBarSeries* drilldownSeries(QString category) |
|
|||
47 | { |
|
|||
48 | return mDrilldownSeries[category]; |
|
|||
49 | } |
|
|||
50 |
|
||||
51 | private: |
|
|||
52 | QMap<QString, DrilldownBarSeries*> mDrilldownSeries; |
|
|||
53 | }; |
|
|||
54 | //! [1] |
|
|||
55 |
|
||||
56 | //! [2] |
|
|||
57 | class DrilldownChart : public QChart |
|
|||
58 | { |
|
|||
59 | Q_OBJECT |
|
|||
60 | public: |
|
|||
61 | explicit DrilldownChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0) |
|
|||
62 | :QChart(parent, wFlags), |
|
|||
63 | m_currentSeries(0) |
|
|||
64 | { |
|
|||
65 |
|
||||
66 | } |
|
|||
67 |
|
||||
68 | void changeSeries(QSeries* series) |
|
|||
69 | { |
|
|||
70 | if (m_currentSeries) |
|
|||
71 | removeSeries(m_currentSeries); |
|
|||
72 | m_currentSeries = series; |
|
|||
73 | addSeries(series); |
|
|||
74 | setTitle(series->name()); |
|
|||
75 | } |
|
|||
76 |
|
||||
77 | public Q_SLOTS: |
|
|||
78 | void handleClicked(QBarSet *barset, QString category, Qt::MouseButtons button) |
|
|||
79 | { |
|
|||
80 | Q_UNUSED(barset) |
|
|||
81 | Q_UNUSED(button) |
|
|||
82 | DrilldownBarSeries* series = static_cast<DrilldownBarSeries*> (sender()); |
|
|||
83 | changeSeries(series->drilldownSeries(category)); |
|
|||
84 | } |
|
|||
85 |
|
||||
86 | private: |
|
|||
87 | QSeries* m_currentSeries; |
|
|||
88 | }; |
|
|||
89 | //! [2] |
|
|||
90 |
|
||||
91 | int main(int argc, char *argv[]) |
|
31 | int main(int argc, char *argv[]) | |
92 | { |
|
32 | { | |
93 | QApplication a(argc, argv); |
|
33 | QApplication a(argc, argv); | |
@@ -97,7 +37,7 int main(int argc, char *argv[]) | |||||
97 | drilldownChart->setTheme(QChart::ChartThemeBlueIcy); |
|
37 | drilldownChart->setTheme(QChart::ChartThemeBlueIcy); | |
98 | drilldownChart->setAnimationOptions(QChart::SeriesAnimations); |
|
38 | drilldownChart->setAnimationOptions(QChart::SeriesAnimations); | |
99 |
|
39 | |||
100 |
|
|
40 | //! [3] | |
101 | // Define categories |
|
41 | // Define categories | |
102 | QStringList months; |
|
42 | QStringList months; | |
103 | months << "May" << "Jun" << "Jul" << "Aug" << "Sep"; |
|
43 | months << "May" << "Jun" << "Jul" << "Aug" << "Sep"; | |
@@ -105,9 +45,9 int main(int argc, char *argv[]) | |||||
105 | weeks << "week 1" << "week 2" << "week 3" << "week 4"; |
|
45 | weeks << "week 1" << "week 2" << "week 3" << "week 4"; | |
106 | QStringList plants; |
|
46 | QStringList plants; | |
107 | plants << "Habanero" << "Lemon Drop" << "Starfish" << "Aji Amarillo"; |
|
47 | plants << "Habanero" << "Lemon Drop" << "Starfish" << "Aji Amarillo"; | |
108 |
|
|
48 | //! [3] | |
109 |
|
49 | |||
110 |
|
|
50 | //! [4] | |
111 | // Create drilldown structure |
|
51 | // Create drilldown structure | |
112 | DrilldownBarSeries* seasonSeries = new DrilldownBarSeries(months, drilldownChart); |
|
52 | DrilldownBarSeries* seasonSeries = new DrilldownBarSeries(months, drilldownChart); | |
113 | seasonSeries->setName("Crop by month - Season"); |
|
53 | seasonSeries->setName("Crop by month - Season"); | |
@@ -131,9 +71,9 int main(int argc, char *argv[]) | |||||
131 |
|
71 | |||
132 | // Enable drilldown from season series using right click. |
|
72 | // Enable drilldown from season series using right click. | |
133 | QObject::connect(seasonSeries, SIGNAL(clicked(QBarSet*,QString,Qt::MouseButtons)), drilldownChart, SLOT(handleClicked(QBarSet*,QString,Qt::MouseButtons))); |
|
73 | QObject::connect(seasonSeries, SIGNAL(clicked(QBarSet*,QString,Qt::MouseButtons)), drilldownChart, SLOT(handleClicked(QBarSet*,QString,Qt::MouseButtons))); | |
134 |
|
|
74 | //! [4] | |
135 |
|
75 | |||
136 |
|
|
76 | //! [5] | |
137 | // Fill monthly and weekly series with data |
|
77 | // Fill monthly and weekly series with data | |
138 | foreach (QString plant, plants) { |
|
78 | foreach (QString plant, plants) { | |
139 | QBarSet* monthlyCrop = new QBarSet(plant); |
|
79 | QBarSet* monthlyCrop = new QBarSet(plant); | |
@@ -148,19 +88,20 int main(int argc, char *argv[]) | |||||
148 | } |
|
88 | } | |
149 | seasonSeries->appendBarSet(monthlyCrop); |
|
89 | seasonSeries->appendBarSet(monthlyCrop); | |
150 | } |
|
90 | } | |
151 |
|
|
91 | //! [5] | |
152 |
|
||||
153 | seasonSeries->setToolTipEnabled(true); |
|
|||
154 |
|
92 | |||
155 |
|
|
93 | //! [6] | |
156 | // Show season series in initial view |
|
94 | // Show season series in initial view | |
157 | drilldownChart->changeSeries(seasonSeries); |
|
95 | drilldownChart->changeSeries(seasonSeries); | |
158 | drilldownChart->setTitle(seasonSeries->name()); |
|
96 | drilldownChart->setTitle(seasonSeries->name()); | |
159 |
|
|
97 | //! [6] | |
160 |
|
98 | |||
|
99 | //! [7] | |||
161 | drilldownChart->axisX()->setGridLineVisible(false); |
|
100 | drilldownChart->axisX()->setGridLineVisible(false); | |
|
101 | drilldownChart->axisY()->setNiceNumbers(true); | |||
162 | drilldownChart->legend()->setVisible(true); |
|
102 | drilldownChart->legend()->setVisible(true); | |
163 | drilldownChart->legend()->setAlignmnent(QLegend::AlignmentBottom); |
|
103 | drilldownChart->legend()->setAlignmnent(QLegend::AlignmentBottom); | |
|
104 | //! [7] | |||
164 |
|
105 | |||
165 | QChartView *chartView = new QChartView(drilldownChart); |
|
106 | QChartView *chartView = new QChartView(drilldownChart); | |
166 | window.setCentralWidget(chartView); |
|
107 | window.setCentralWidget(chartView); | |
@@ -170,4 +111,3 int main(int argc, char *argv[]) | |||||
170 | return a.exec(); |
|
111 | return a.exec(); | |
171 | } |
|
112 | } | |
172 |
|
113 | |||
173 | #include "main.moc" |
|
@@ -2,6 +2,6 | |||||
2 | error( "Couldn't find the examples.pri file!" ) |
|
2 | error( "Couldn't find the examples.pri file!" ) | |
3 | } |
|
3 | } | |
4 | TARGET = stackedbarchartdrilldown |
|
4 | TARGET = stackedbarchartdrilldown | |
5 | SOURCES += main.cpp |
|
5 | SOURCES += main.cpp drilldownseries.cpp drilldownchart.cpp | |
6 | HEADERS += |
|
6 | HEADERS += drilldownseries.h drilldownchart.h | |
7 |
|
7 |
General Comments 0
You need to be logged in to leave comments.
Login now