@@ -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 | 21 | #include <QtGui/QApplication> |
|
22 | 22 | #include <QMainWindow> |
|
23 | 23 | #include <QChartView> |
|
24 | #include <QStackedBarSeries> | |
|
25 | 24 | #include <QBarSet> |
|
26 | 25 | #include <QLegend> |
|
26 | #include "drilldownseries.h" | |
|
27 | #include "drilldownchart.h" | |
|
27 | 28 | |
|
28 | 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 | 31 | int main(int argc, char *argv[]) |
|
92 | 32 | { |
|
93 | 33 | QApplication a(argc, argv); |
@@ -150,17 +90,18 int main(int argc, char *argv[]) | |||
|
150 | 90 | } |
|
151 | 91 |
|
|
152 | 92 | |
|
153 | seasonSeries->setToolTipEnabled(true); | |
|
154 | ||
|
155 | 93 |
|
|
156 | 94 | // Show season series in initial view |
|
157 | 95 | drilldownChart->changeSeries(seasonSeries); |
|
158 | 96 | drilldownChart->setTitle(seasonSeries->name()); |
|
159 | 97 |
|
|
160 | 98 | |
|
99 | //! [7] | |
|
161 | 100 | drilldownChart->axisX()->setGridLineVisible(false); |
|
101 | drilldownChart->axisY()->setNiceNumbers(true); | |
|
162 | 102 | drilldownChart->legend()->setVisible(true); |
|
163 | 103 | drilldownChart->legend()->setAlignmnent(QLegend::AlignmentBottom); |
|
104 | //! [7] | |
|
164 | 105 | |
|
165 | 106 | QChartView *chartView = new QChartView(drilldownChart); |
|
166 | 107 | window.setCentralWidget(chartView); |
@@ -170,4 +111,3 int main(int argc, char *argv[]) | |||
|
170 | 111 | return a.exec(); |
|
171 | 112 | } |
|
172 | 113 | |
|
173 | #include "main.moc" |
General Comments 0
You need to be logged in to leave comments.
Login now