@@ -0,0 +1,259 | |||||
|
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 "scroller_p.h" | |||
|
22 | #include "qlegend.h" | |||
|
23 | #include <QGraphicsSceneMouseEvent> | |||
|
24 | ||||
|
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
26 | ||||
|
27 | Scroller::Scroller(QLegend* legend): | |||
|
28 | m_ticker(this), | |||
|
29 | m_state(Idle), | |||
|
30 | m_moveThreshold(10), | |||
|
31 | m_timeTreshold(50), | |||
|
32 | m_legend(legend) | |||
|
33 | { | |||
|
34 | ||||
|
35 | } | |||
|
36 | ||||
|
37 | Scroller::~Scroller() | |||
|
38 | { | |||
|
39 | } | |||
|
40 | ||||
|
41 | void Scroller::mousePressEvent(QGraphicsSceneMouseEvent* event) | |||
|
42 | { | |||
|
43 | if (event->button() == Qt::LeftButton) { | |||
|
44 | ||||
|
45 | switch (m_state) { | |||
|
46 | case Idle: | |||
|
47 | { | |||
|
48 | m_state = Pressed; | |||
|
49 | m_offset = offset(); | |||
|
50 | m_press = event->pos(); | |||
|
51 | m_timeStamp = QTime::currentTime(); | |||
|
52 | event->accept(); | |||
|
53 | break; | |||
|
54 | } | |||
|
55 | case Scroll: | |||
|
56 | { | |||
|
57 | m_state = Stop; | |||
|
58 | m_speed = QPoint(0, 0); | |||
|
59 | m_offset = offset(); | |||
|
60 | m_press = event->pos(); | |||
|
61 | event->accept(); | |||
|
62 | break; | |||
|
63 | } | |||
|
64 | case Pressed: | |||
|
65 | case Move: | |||
|
66 | case Stop: | |||
|
67 | qWarning() << __FUNCTION__<<"Scroller unexpected state" << m_state; | |||
|
68 | event->ignore(); | |||
|
69 | break; | |||
|
70 | } | |||
|
71 | } | |||
|
72 | } | |||
|
73 | ||||
|
74 | void Scroller::mouseMoveEvent(QGraphicsSceneMouseEvent* event) | |||
|
75 | { | |||
|
76 | QPointF delta = event->pos() - m_press; | |||
|
77 | ||||
|
78 | switch (m_state) { | |||
|
79 | case Pressed: | |||
|
80 | case Stop: | |||
|
81 | { | |||
|
82 | if (qAbs(delta.x()) > m_moveThreshold || qAbs(delta.y()) > m_moveThreshold) { | |||
|
83 | m_state = Move; | |||
|
84 | m_timeStamp = QTime::currentTime(); | |||
|
85 | m_distance = QPointF(0, 0); | |||
|
86 | m_press = event->pos(); | |||
|
87 | event->accept(); | |||
|
88 | break; | |||
|
89 | } | |||
|
90 | else { | |||
|
91 | event->ignore(); | |||
|
92 | break; | |||
|
93 | } | |||
|
94 | } | |||
|
95 | case Move: | |||
|
96 | { | |||
|
97 | setOffset(m_offset - delta); | |||
|
98 | calculateSpeed(event->pos()); | |||
|
99 | event->accept(); | |||
|
100 | break; | |||
|
101 | } | |||
|
102 | case Idle: | |||
|
103 | case Scroll: | |||
|
104 | qWarning() << __FUNCTION__<<"Scroller unexpected state" << m_state; | |||
|
105 | event->ignore(); | |||
|
106 | break; | |||
|
107 | } | |||
|
108 | ||||
|
109 | } | |||
|
110 | ||||
|
111 | void Scroller::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) | |||
|
112 | { | |||
|
113 | if (event->button() == Qt::LeftButton) { | |||
|
114 | ||||
|
115 | switch (m_state) { | |||
|
116 | ||||
|
117 | case Scroll: | |||
|
118 | m_state = Stop; | |||
|
119 | m_speed = QPointF(0, 0); | |||
|
120 | m_offset = offset(); | |||
|
121 | event->accept(); | |||
|
122 | break; | |||
|
123 | case Pressed: | |||
|
124 | { | |||
|
125 | m_state = Idle; | |||
|
126 | //if (m_timeStamp.elapsed() < m_clickedPressDelay) { | |||
|
127 | ||||
|
128 | //emit clicked(m_offset.toPoint()); | |||
|
129 | //} | |||
|
130 | event->accept(); | |||
|
131 | break; | |||
|
132 | } | |||
|
133 | case Move: | |||
|
134 | { | |||
|
135 | calculateSpeed(event->pos()); | |||
|
136 | m_offset = offset(); | |||
|
137 | m_press = event->pos(); | |||
|
138 | if (m_speed == QPointF(0, 0)) { | |||
|
139 | m_state = Idle; | |||
|
140 | } | |||
|
141 | else { | |||
|
142 | m_speed /= 4; | |||
|
143 | m_state = Scroll; | |||
|
144 | m_ticker.start(20); | |||
|
145 | } | |||
|
146 | event->accept(); | |||
|
147 | break; | |||
|
148 | } | |||
|
149 | ||||
|
150 | case Stop: | |||
|
151 | case Idle: | |||
|
152 | qWarning() << __FUNCTION__<<"Scroller unexpected state" << m_state; | |||
|
153 | event->ignore(); | |||
|
154 | break; | |||
|
155 | ||||
|
156 | } | |||
|
157 | } | |||
|
158 | } | |||
|
159 | ||||
|
160 | void Scroller::scrollTick() | |||
|
161 | { | |||
|
162 | switch (m_state) { | |||
|
163 | case Scroll: | |||
|
164 | { | |||
|
165 | lowerSpeed(m_speed); | |||
|
166 | setOffset(m_offset - m_speed); | |||
|
167 | m_offset = offset(); | |||
|
168 | if (m_speed == QPointF(0, 0)) { | |||
|
169 | m_state = Idle; | |||
|
170 | m_ticker.stop(); | |||
|
171 | } | |||
|
172 | break; | |||
|
173 | } | |||
|
174 | case Stop: | |||
|
175 | m_ticker.stop(); | |||
|
176 | break; | |||
|
177 | case Idle: | |||
|
178 | case Move: | |||
|
179 | case Pressed: | |||
|
180 | qWarning() << __FUNCTION__<<"Scroller unexpected state" << m_state; | |||
|
181 | m_ticker.stop(); | |||
|
182 | break; | |||
|
183 | ||||
|
184 | } | |||
|
185 | } | |||
|
186 | ||||
|
187 | void Scroller::lowerSpeed(QPointF& speed, qreal maxSpeed) | |||
|
188 | { | |||
|
189 | qreal x = qBound(-maxSpeed, speed.x(), maxSpeed); | |||
|
190 | qreal y = qBound(-maxSpeed, speed.y(), maxSpeed); | |||
|
191 | ||||
|
192 | x = (x == 0) ? x : | |||
|
193 | (x > 0) ? qMax(qreal(0), x - m_fraction.x()) : qMin(qreal(0), x + m_fraction.x()); | |||
|
194 | y = (y == 0) ? y : | |||
|
195 | (y > 0) ? qMax(qreal(0), y - m_fraction.y()) : qMin(qreal(0), y + m_fraction.y()); | |||
|
196 | speed.setX(x); | |||
|
197 | speed.setY(y); | |||
|
198 | } | |||
|
199 | ||||
|
200 | void Scroller::calculateSpeed(const QPointF& position) | |||
|
201 | { | |||
|
202 | if (m_timeStamp.elapsed() > m_timeTreshold) { | |||
|
203 | ||||
|
204 | QPointF distance = position - m_press; | |||
|
205 | ||||
|
206 | m_timeStamp = QTime::currentTime(); | |||
|
207 | m_speed = distance - m_distance; | |||
|
208 | m_distance = distance; | |||
|
209 | ||||
|
210 | qreal fraction = qMax(qAbs(m_speed.x()), qAbs(m_speed.y())); | |||
|
211 | ||||
|
212 | if (fraction != 0) { | |||
|
213 | m_fraction.setX(qAbs(m_speed.x() / fraction)); | |||
|
214 | m_fraction.setY(qAbs(m_speed.y() / fraction)); | |||
|
215 | } | |||
|
216 | else { | |||
|
217 | m_fraction.setX(1); | |||
|
218 | m_fraction.setY(1); | |||
|
219 | } | |||
|
220 | } | |||
|
221 | } | |||
|
222 | ||||
|
223 | void Scroller::setOffset(const QPointF& point) | |||
|
224 | { | |||
|
225 | m_legend->setOffset(point); | |||
|
226 | } | |||
|
227 | ||||
|
228 | QPointF Scroller::offset() const | |||
|
229 | { | |||
|
230 | return m_legend->offset(); | |||
|
231 | } | |||
|
232 | ||||
|
233 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
|
234 | ||||
|
235 | ScrollTicker::ScrollTicker(Scroller *scroller,QObject* parent):QObject(parent), | |||
|
236 | m_scroller(scroller) | |||
|
237 | { | |||
|
238 | ||||
|
239 | } | |||
|
240 | ||||
|
241 | void ScrollTicker::start(int interval) | |||
|
242 | { | |||
|
243 | if (!m_timer.isActive()){ | |||
|
244 | m_timer.start(interval, this); | |||
|
245 | } | |||
|
246 | } | |||
|
247 | ||||
|
248 | void ScrollTicker::stop() | |||
|
249 | { | |||
|
250 | m_timer.stop(); | |||
|
251 | } | |||
|
252 | ||||
|
253 | void ScrollTicker::timerEvent(QTimerEvent *event) | |||
|
254 | { | |||
|
255 | Q_UNUSED(event); | |||
|
256 | m_scroller->scrollTick(); | |||
|
257 | } | |||
|
258 | ||||
|
259 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -0,0 +1,107 | |||||
|
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 | // W A R N I N G | |||
|
22 | // ------------- | |||
|
23 | // | |||
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |||
|
25 | // implementation detail. This header file may change from version to | |||
|
26 | // version without notice, or even be removed. | |||
|
27 | // | |||
|
28 | // We mean it. | |||
|
29 | ||||
|
30 | #ifndef SCROLLER_P_H_ | |||
|
31 | #define SCROLLER_P_H_ | |||
|
32 | ||||
|
33 | #include "qchartglobal.h" | |||
|
34 | #include <QBasicTimer> | |||
|
35 | #include <QTime> | |||
|
36 | #include <QPointF> | |||
|
37 | ||||
|
38 | class QGraphicsSceneMouseEvent; | |||
|
39 | ||||
|
40 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
41 | ||||
|
42 | class Scroller; | |||
|
43 | class QLegend; | |||
|
44 | ||||
|
45 | class ScrollTicker : public QObject | |||
|
46 | { | |||
|
47 | public: | |||
|
48 | ScrollTicker(Scroller *scroller,QObject *parent=0); | |||
|
49 | void start(int interval); | |||
|
50 | void stop(); | |||
|
51 | protected: | |||
|
52 | void timerEvent(QTimerEvent *event); | |||
|
53 | ||||
|
54 | private: | |||
|
55 | QBasicTimer m_timer; | |||
|
56 | Scroller *m_scroller; | |||
|
57 | }; | |||
|
58 | ||||
|
59 | class Scroller | |||
|
60 | { | |||
|
61 | public: | |||
|
62 | enum State { | |||
|
63 | Idle, | |||
|
64 | Pressed, | |||
|
65 | Move, | |||
|
66 | Scroll, | |||
|
67 | Stop | |||
|
68 | }; | |||
|
69 | ||||
|
70 | explicit Scroller(QLegend* legend); | |||
|
71 | virtual ~Scroller(); | |||
|
72 | ||||
|
73 | virtual void setOffset(const QPointF& point); | |||
|
74 | virtual QPointF offset() const; | |||
|
75 | ||||
|
76 | public: | |||
|
77 | void scrollTick(); | |||
|
78 | ||||
|
79 | ||||
|
80 | public: | |||
|
81 | void mousePressEvent(QGraphicsSceneMouseEvent* event); | |||
|
82 | void mouseMoveEvent(QGraphicsSceneMouseEvent* event); | |||
|
83 | void mouseReleaseEvent(QGraphicsSceneMouseEvent* event); | |||
|
84 | ||||
|
85 | private: | |||
|
86 | void calculateSpeed(const QPointF& position); | |||
|
87 | void lowerSpeed(QPointF& speed,qreal maxSpeed=100); | |||
|
88 | ||||
|
89 | private: | |||
|
90 | ScrollTicker m_ticker; | |||
|
91 | State m_state; | |||
|
92 | QTime m_timeStamp; | |||
|
93 | QPointF m_press; | |||
|
94 | QPointF m_offset; | |||
|
95 | QPointF m_speed; | |||
|
96 | QPointF m_distance; | |||
|
97 | QPointF m_fraction; | |||
|
98 | int m_moveThreshold; | |||
|
99 | int m_timeTreshold; | |||
|
100 | QLegend* m_legend; | |||
|
101 | ||||
|
102 | ||||
|
103 | }; | |||
|
104 | ||||
|
105 | QTCOMMERCIALCHART_END_NAMESPACE | |||
|
106 | ||||
|
107 | #endif /* SCROLLER_P_H_ */ |
@@ -1,371 +1,373 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "themewidget.h" |
|
21 | #include "themewidget.h" | |
22 |
|
22 | |||
23 | #include <QChartView> |
|
23 | #include <QChartView> | |
24 | #include <QPieSeries> |
|
24 | #include <QPieSeries> | |
25 | #include <QPieSlice> |
|
25 | #include <QPieSlice> | |
26 | #include <QBarSeries> |
|
26 | #include <QBarSeries> | |
27 | #include <QPercentBarSeries> |
|
27 | #include <QPercentBarSeries> | |
28 | #include <QStackedBarSeries> |
|
28 | #include <QStackedBarSeries> | |
29 | #include <QBarSet> |
|
29 | #include <QBarSet> | |
30 | #include <QLineSeries> |
|
30 | #include <QLineSeries> | |
31 | #include <QSplineSeries> |
|
31 | #include <QSplineSeries> | |
32 | #include <QScatterSeries> |
|
32 | #include <QScatterSeries> | |
33 | #include <QAreaSeries> |
|
33 | #include <QAreaSeries> | |
34 | #include <QLegend> |
|
34 | #include <QLegend> | |
35 | #include <QGridLayout> |
|
35 | #include <QGridLayout> | |
36 | #include <QFormLayout> |
|
36 | #include <QFormLayout> | |
37 | #include <QComboBox> |
|
37 | #include <QComboBox> | |
38 | #include <QSpinBox> |
|
38 | #include <QSpinBox> | |
39 | #include <QCheckBox> |
|
39 | #include <QCheckBox> | |
40 | #include <QGroupBox> |
|
40 | #include <QGroupBox> | |
41 | #include <QLabel> |
|
41 | #include <QLabel> | |
42 | #include <QTime> |
|
42 | #include <QTime> | |
43 |
|
43 | |||
44 | ThemeWidget::ThemeWidget(QWidget* parent) : |
|
44 | ThemeWidget::ThemeWidget(QWidget* parent) : | |
45 | QWidget(parent), |
|
45 | QWidget(parent), | |
46 | m_listCount(3), |
|
46 | m_listCount(3), | |
47 | m_valueMax(10), |
|
47 | m_valueMax(10), | |
48 | m_valueCount(7), |
|
48 | m_valueCount(7), | |
49 | m_dataTable(generateRandomData(m_listCount,m_valueMax,m_valueCount)), |
|
49 | m_dataTable(generateRandomData(m_listCount,m_valueMax,m_valueCount)), | |
50 | m_themeComboBox(createThemeBox()), |
|
50 | m_themeComboBox(createThemeBox()), | |
51 | m_antialiasCheckBox(new QCheckBox("Anti-aliasing")), |
|
51 | m_antialiasCheckBox(new QCheckBox("Anti-aliasing")), | |
52 | m_animatedComboBox(createAnimationBox()), |
|
52 | m_animatedComboBox(createAnimationBox()), | |
53 | m_legendComboBox(createLegendBox()) |
|
53 | m_legendComboBox(createLegendBox()) | |
54 | { |
|
54 | { | |
55 | connectSignals(); |
|
55 | connectSignals(); | |
56 | // create layout |
|
56 | // create layout | |
57 | QGridLayout* baseLayout = new QGridLayout(); |
|
57 | QGridLayout* baseLayout = new QGridLayout(); | |
58 | QHBoxLayout *settingsLayout = new QHBoxLayout(); |
|
58 | QHBoxLayout *settingsLayout = new QHBoxLayout(); | |
59 | settingsLayout->addWidget(new QLabel("Theme:")); |
|
59 | settingsLayout->addWidget(new QLabel("Theme:")); | |
60 | settingsLayout->addWidget(m_themeComboBox); |
|
60 | settingsLayout->addWidget(m_themeComboBox); | |
61 | settingsLayout->addWidget(new QLabel("Animation:")); |
|
61 | settingsLayout->addWidget(new QLabel("Animation:")); | |
62 | settingsLayout->addWidget(m_animatedComboBox); |
|
62 | settingsLayout->addWidget(m_animatedComboBox); | |
|
63 | settingsLayout->addWidget(new QLabel("Legend:")); | |||
63 | settingsLayout->addWidget(m_legendComboBox); |
|
64 | settingsLayout->addWidget(m_legendComboBox); | |
64 | settingsLayout->addWidget(m_antialiasCheckBox); |
|
65 | settingsLayout->addWidget(m_antialiasCheckBox); | |
65 | settingsLayout->addStretch(); |
|
66 | settingsLayout->addStretch(); | |
66 | baseLayout->addLayout(settingsLayout, 0, 0, 1, 3); |
|
67 | baseLayout->addLayout(settingsLayout, 0, 0, 1, 3); | |
67 |
|
68 | |||
68 | //create charts |
|
69 | //create charts | |
69 |
|
70 | |||
70 | QChartView *chartView; |
|
71 | QChartView *chartView; | |
71 |
|
72 | |||
72 | chartView = new QChartView(createAreaChart()); |
|
73 | chartView = new QChartView(createAreaChart()); | |
73 | baseLayout->addWidget(chartView, 1, 0); |
|
74 | baseLayout->addWidget(chartView, 1, 0); | |
74 | m_charts << chartView; |
|
75 | m_charts << chartView; | |
75 |
|
76 | |||
76 | chartView = new QChartView(createBarChart(m_valueCount)); |
|
77 | chartView = new QChartView(createBarChart(m_valueCount)); | |
77 | baseLayout->addWidget(chartView, 1, 1); |
|
78 | baseLayout->addWidget(chartView, 1, 1); | |
78 | m_charts << chartView; |
|
79 | m_charts << chartView; | |
79 |
|
80 | |||
80 | chartView = new QChartView(createLineChart()); |
|
81 | chartView = new QChartView(createLineChart()); | |
81 | baseLayout->addWidget(chartView, 1, 2); |
|
82 | baseLayout->addWidget(chartView, 1, 2); | |
82 | m_charts << chartView; |
|
83 | m_charts << chartView; | |
83 |
|
84 | |||
84 | chartView = new QChartView(createPieChart()); |
|
85 | chartView = new QChartView(createPieChart()); | |
85 | chartView->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); // funny things happen if the pie slice labels no not fit the screen... |
|
86 | chartView->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); // funny things happen if the pie slice labels no not fit the screen... | |
86 | baseLayout->addWidget(chartView, 2, 0); |
|
87 | baseLayout->addWidget(chartView, 2, 0); | |
87 | m_charts << chartView; |
|
88 | m_charts << chartView; | |
88 |
|
89 | |||
89 | chartView = new QChartView(createSplineChart()); |
|
90 | chartView = new QChartView(createSplineChart()); | |
90 | baseLayout->addWidget(chartView, 2, 1); |
|
91 | baseLayout->addWidget(chartView, 2, 1); | |
91 | m_charts << chartView; |
|
92 | m_charts << chartView; | |
92 |
|
93 | |||
93 | chartView = new QChartView(createScatterChart()); |
|
94 | chartView = new QChartView(createScatterChart()); | |
94 | baseLayout->addWidget(chartView, 2, 2); |
|
95 | baseLayout->addWidget(chartView, 2, 2); | |
95 | m_charts << chartView; |
|
96 | m_charts << chartView; | |
96 |
|
97 | |||
97 | setLayout(baseLayout); |
|
98 | setLayout(baseLayout); | |
98 |
|
99 | |||
99 | // Set defaults |
|
100 | // Set defaults | |
100 | m_antialiasCheckBox->setChecked(true); |
|
101 | m_antialiasCheckBox->setChecked(true); | |
|
102 | updateUI(); | |||
101 | } |
|
103 | } | |
102 |
|
104 | |||
103 | ThemeWidget::~ThemeWidget() |
|
105 | ThemeWidget::~ThemeWidget() | |
104 | { |
|
106 | { | |
105 | } |
|
107 | } | |
106 |
|
108 | |||
107 | void ThemeWidget::connectSignals() |
|
109 | void ThemeWidget::connectSignals() | |
108 | { |
|
110 | { | |
109 | connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
111 | connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); | |
110 | connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); |
|
112 | connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); | |
111 | connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
113 | connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); | |
112 | connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
114 | connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); | |
113 | } |
|
115 | } | |
114 |
|
116 | |||
115 | DataTable ThemeWidget::generateRandomData(int listCount,int valueMax,int valueCount) const |
|
117 | DataTable ThemeWidget::generateRandomData(int listCount,int valueMax,int valueCount) const | |
116 | { |
|
118 | { | |
117 | DataTable dataTable; |
|
119 | DataTable dataTable; | |
118 |
|
120 | |||
119 | // set seed for random stuff |
|
121 | // set seed for random stuff | |
120 | qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); |
|
122 | qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); | |
121 |
|
123 | |||
122 | // generate random data |
|
124 | // generate random data | |
123 | for (int i(0); i < listCount; i++) { |
|
125 | for (int i(0); i < listCount; i++) { | |
124 | DataList dataList; |
|
126 | DataList dataList; | |
125 | qreal yValue(0); |
|
127 | qreal yValue(0); | |
126 | for (int j(0); j < valueCount; j++) { |
|
128 | for (int j(0); j < valueCount; j++) { | |
127 | yValue = yValue + (qreal) (qrand() % valueMax) / (qreal) valueCount; |
|
129 | yValue = yValue + (qreal) (qrand() % valueMax) / (qreal) valueCount; | |
128 | QPointF value((j + (qreal) rand() / (qreal) RAND_MAX) * ((qreal) m_valueMax / (qreal) valueCount), |
|
130 | QPointF value((j + (qreal) rand() / (qreal) RAND_MAX) * ((qreal) m_valueMax / (qreal) valueCount), | |
129 | yValue); |
|
131 | yValue); | |
130 | QString label = "Item " + QString::number(i) + ":" + QString::number(j); |
|
132 | QString label = "Item " + QString::number(i) + ":" + QString::number(j); | |
131 | dataList << Data(value, label); |
|
133 | dataList << Data(value, label); | |
132 | } |
|
134 | } | |
133 | dataTable << dataList; |
|
135 | dataTable << dataList; | |
134 | } |
|
136 | } | |
135 |
|
137 | |||
136 | return dataTable; |
|
138 | return dataTable; | |
137 | } |
|
139 | } | |
138 |
|
140 | |||
139 | QComboBox* ThemeWidget::createThemeBox() const |
|
141 | QComboBox* ThemeWidget::createThemeBox() const | |
140 | { |
|
142 | { | |
141 | // settings layout |
|
143 | // settings layout | |
142 | QComboBox* themeComboBox = new QComboBox(); |
|
144 | QComboBox* themeComboBox = new QComboBox(); | |
143 | themeComboBox->addItem("Light", QChart::ChartThemeLight); |
|
145 | themeComboBox->addItem("Light", QChart::ChartThemeLight); | |
144 | themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean); |
|
146 | themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean); | |
145 | themeComboBox->addItem("Dark", QChart::ChartThemeDark); |
|
147 | themeComboBox->addItem("Dark", QChart::ChartThemeDark); | |
146 | themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand); |
|
148 | themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand); | |
147 | themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs); |
|
149 | themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs); | |
148 | themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast); |
|
150 | themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast); | |
149 | themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy); |
|
151 | themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy); | |
150 | return themeComboBox; |
|
152 | return themeComboBox; | |
151 | } |
|
153 | } | |
152 |
|
154 | |||
153 | QComboBox* ThemeWidget::createAnimationBox() const |
|
155 | QComboBox* ThemeWidget::createAnimationBox() const | |
154 | { |
|
156 | { | |
155 | // settings layout |
|
157 | // settings layout | |
156 | QComboBox* animationComboBox = new QComboBox(); |
|
158 | QComboBox* animationComboBox = new QComboBox(); | |
157 | animationComboBox->addItem("No Animations", QChart::NoAnimation); |
|
159 | animationComboBox->addItem("No Animations", QChart::NoAnimation); | |
158 | animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations); |
|
160 | animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations); | |
159 | animationComboBox->addItem("Series Animations", QChart::SeriesAnimations); |
|
161 | animationComboBox->addItem("Series Animations", QChart::SeriesAnimations); | |
160 | animationComboBox->addItem("All Animations", QChart::AllAnimations); |
|
162 | animationComboBox->addItem("All Animations", QChart::AllAnimations); | |
161 | return animationComboBox; |
|
163 | return animationComboBox; | |
162 | } |
|
164 | } | |
163 |
|
165 | |||
164 | QComboBox* ThemeWidget::createLegendBox() const |
|
166 | QComboBox* ThemeWidget::createLegendBox() const | |
165 | { |
|
167 | { | |
166 | QComboBox* legendComboBox = new QComboBox(); |
|
168 | QComboBox* legendComboBox = new QComboBox(); | |
167 |
legendComboBox->addItem("Legend |
|
169 | legendComboBox->addItem("No Legend ", 0); | |
168 | legendComboBox->addItem("Legend Top", QLegend::AlignmentTop); |
|
170 | legendComboBox->addItem("Legend Top", QLegend::AlignmentTop); | |
169 | legendComboBox->addItem("Legend Bottom", QLegend::AlignmentBottom); |
|
171 | legendComboBox->addItem("Legend Bottom", QLegend::AlignmentBottom); | |
170 | legendComboBox->addItem("Legend Left", QLegend::AlignmentLeft); |
|
172 | legendComboBox->addItem("Legend Left", QLegend::AlignmentLeft); | |
171 | legendComboBox->addItem("Legend Right", QLegend::AlignmentRight); |
|
173 | legendComboBox->addItem("Legend Right", QLegend::AlignmentRight); | |
172 | return legendComboBox; |
|
174 | return legendComboBox; | |
173 | } |
|
175 | } | |
174 |
|
176 | |||
175 | QChart* ThemeWidget::createAreaChart() const |
|
177 | QChart* ThemeWidget::createAreaChart() const | |
176 | { |
|
178 | { | |
177 | // area chart |
|
179 | // area chart | |
178 | QChart *chart = new QChart(); |
|
180 | QChart *chart = new QChart(); | |
179 | chart->axisX()->setNiceNumbers(true); |
|
181 | chart->axisX()->setNiceNumbers(true); | |
180 | chart->axisY()->setNiceNumbers(true); |
|
182 | chart->axisY()->setNiceNumbers(true); | |
181 | chart->setTitle("Area chart"); |
|
183 | chart->setTitle("Area chart"); | |
182 | QString name("Series "); |
|
184 | QString name("Series "); | |
183 | int nameIndex = 0; |
|
185 | int nameIndex = 0; | |
184 |
|
186 | |||
185 | // The lower series initialized to zero values |
|
187 | // The lower series initialized to zero values | |
186 | QLineSeries *lowerSeries = 0; |
|
188 | QLineSeries *lowerSeries = 0; | |
187 | for (int i(0); i < m_dataTable.count(); i++) { |
|
189 | for (int i(0); i < m_dataTable.count(); i++) { | |
188 | QLineSeries *upperSeries = new QLineSeries(chart); |
|
190 | QLineSeries *upperSeries = new QLineSeries(chart); | |
189 | for (int j(0); j < m_dataTable[i].count(); j++) { |
|
191 | for (int j(0); j < m_dataTable[i].count(); j++) { | |
190 | Data data = m_dataTable[i].at(j); |
|
192 | Data data = m_dataTable[i].at(j); | |
191 | if (lowerSeries) |
|
193 | if (lowerSeries) | |
192 | upperSeries->append(QPointF(j, lowerSeries->y(i) + data.first.y())); |
|
194 | upperSeries->append(QPointF(j, lowerSeries->y(i) + data.first.y())); | |
193 | else |
|
195 | else | |
194 | upperSeries->append(QPointF(j, data.first.y())); |
|
196 | upperSeries->append(QPointF(j, data.first.y())); | |
195 | } |
|
197 | } | |
196 | QAreaSeries *area = new QAreaSeries(upperSeries, lowerSeries); |
|
198 | QAreaSeries *area = new QAreaSeries(upperSeries, lowerSeries); | |
197 | area->setName(name + QString::number(nameIndex)); |
|
199 | area->setName(name + QString::number(nameIndex)); | |
198 | nameIndex++; |
|
200 | nameIndex++; | |
199 | chart->addSeries(area); |
|
201 | chart->addSeries(area); | |
200 | lowerSeries = upperSeries; |
|
202 | lowerSeries = upperSeries; | |
201 | } |
|
203 | } | |
202 | return chart; |
|
204 | return chart; | |
203 | } |
|
205 | } | |
204 |
|
206 | |||
205 | QChart* ThemeWidget::createBarChart(int valueCount) const |
|
207 | QChart* ThemeWidget::createBarChart(int valueCount) const | |
206 | { |
|
208 | { | |
207 | // bar chart |
|
209 | // bar chart | |
208 | QChart* chart = new QChart(); |
|
210 | QChart* chart = new QChart(); | |
209 | chart->axisX()->setNiceNumbers(true); |
|
211 | chart->axisX()->setNiceNumbers(true); | |
210 | chart->axisY()->setNiceNumbers(true); |
|
212 | chart->axisY()->setNiceNumbers(true); | |
211 | chart->setTitle("Bar chart"); |
|
213 | chart->setTitle("Bar chart"); | |
212 | QBarCategories categories; |
|
214 | QBarCategories categories; | |
213 | // TODO: categories |
|
215 | // TODO: categories | |
214 | for (int i(0); i < valueCount; i++) |
|
216 | for (int i(0); i < valueCount; i++) | |
215 | categories << QString::number(i); |
|
217 | categories << QString::number(i); | |
216 | // QBarSeries* series = new QBarSeries(categories, chart); |
|
218 | // QBarSeries* series = new QBarSeries(categories, chart); | |
217 | // QPercentBarSeries* series = new QPercentBarSeries(categories, chart); |
|
219 | // QPercentBarSeries* series = new QPercentBarSeries(categories, chart); | |
218 | QStackedBarSeries* series = new QStackedBarSeries(categories, chart); |
|
220 | QStackedBarSeries* series = new QStackedBarSeries(categories, chart); | |
219 | for (int i(0); i < m_dataTable.count(); i++) { |
|
221 | for (int i(0); i < m_dataTable.count(); i++) { | |
220 | QBarSet *set = new QBarSet("Set" + QString::number(i)); |
|
222 | QBarSet *set = new QBarSet("Set" + QString::number(i)); | |
221 | foreach (Data data, m_dataTable[i]) |
|
223 | foreach (Data data, m_dataTable[i]) | |
222 | *set << data.first.y(); |
|
224 | *set << data.first.y(); | |
223 | series->appendBarSet(set); |
|
225 | series->appendBarSet(set); | |
224 | } |
|
226 | } | |
225 | chart->addSeries(series); |
|
227 | chart->addSeries(series); | |
226 | return chart; |
|
228 | return chart; | |
227 | } |
|
229 | } | |
228 |
|
230 | |||
229 | QChart* ThemeWidget::createLineChart() const |
|
231 | QChart* ThemeWidget::createLineChart() const | |
230 | { |
|
232 | { | |
231 | // line chart |
|
233 | // line chart | |
232 | QChart* chart = new QChart(); |
|
234 | QChart* chart = new QChart(); | |
233 | chart->axisX()->setNiceNumbers(true); |
|
235 | chart->axisX()->setNiceNumbers(true); | |
234 | chart->axisY()->setNiceNumbers(true); |
|
236 | chart->axisY()->setNiceNumbers(true); | |
235 | chart->setTitle("Line chart"); |
|
237 | chart->setTitle("Line chart"); | |
236 | QString name("Series "); |
|
238 | QString name("Series "); | |
237 | int nameIndex = 0; |
|
239 | int nameIndex = 0; | |
238 | foreach (DataList list, m_dataTable) { |
|
240 | foreach (DataList list, m_dataTable) { | |
239 | QLineSeries *series = new QLineSeries(chart); |
|
241 | QLineSeries *series = new QLineSeries(chart); | |
240 | foreach (Data data, list) |
|
242 | foreach (Data data, list) | |
241 | series->append(data.first); |
|
243 | series->append(data.first); | |
242 | series->setName(name + QString::number(nameIndex)); |
|
244 | series->setName(name + QString::number(nameIndex)); | |
243 | nameIndex++; |
|
245 | nameIndex++; | |
244 | chart->addSeries(series); |
|
246 | chart->addSeries(series); | |
245 | } |
|
247 | } | |
246 | return chart; |
|
248 | return chart; | |
247 | } |
|
249 | } | |
248 |
|
250 | |||
249 | QChart* ThemeWidget::createPieChart() const |
|
251 | QChart* ThemeWidget::createPieChart() const | |
250 | { |
|
252 | { | |
251 | // pie chart |
|
253 | // pie chart | |
252 | QChart* chart = new QChart(); |
|
254 | QChart* chart = new QChart(); | |
253 | chart->setTitle("Pie chart"); |
|
255 | chart->setTitle("Pie chart"); | |
254 | qreal pieSize = 1.0 / m_dataTable.count(); |
|
256 | qreal pieSize = 1.0 / m_dataTable.count(); | |
255 | for (int i = 0; i < m_dataTable.count(); i++) { |
|
257 | for (int i = 0; i < m_dataTable.count(); i++) { | |
256 | QPieSeries *series = new QPieSeries(chart); |
|
258 | QPieSeries *series = new QPieSeries(chart); | |
257 | foreach (Data data, m_dataTable[i]) { |
|
259 | foreach (Data data, m_dataTable[i]) { | |
258 | QPieSlice *slice = series->append(data.first.y(), data.second); |
|
260 | QPieSlice *slice = series->append(data.first.y(), data.second); | |
259 | if (data == m_dataTable[i].first()) { |
|
261 | if (data == m_dataTable[i].first()) { | |
260 | slice->setLabelVisible(); |
|
262 | slice->setLabelVisible(); | |
261 | slice->setExploded(); |
|
263 | slice->setExploded(); | |
262 | } |
|
264 | } | |
263 | } |
|
265 | } | |
264 | qreal hPos = (pieSize / 2) + (i / (qreal) m_dataTable.count()); |
|
266 | qreal hPos = (pieSize / 2) + (i / (qreal) m_dataTable.count()); | |
265 | series->setPieSize(pieSize); |
|
267 | series->setPieSize(pieSize); | |
266 | series->setPiePosition(hPos, 0.5); |
|
268 | series->setPiePosition(hPos, 0.5); | |
267 | chart->addSeries(series); |
|
269 | chart->addSeries(series); | |
268 | } |
|
270 | } | |
269 |
|
271 | |||
270 | return chart; |
|
272 | return chart; | |
271 | } |
|
273 | } | |
272 |
|
274 | |||
273 | QChart* ThemeWidget::createSplineChart() const |
|
275 | QChart* ThemeWidget::createSplineChart() const | |
274 | { // spine chart |
|
276 | { // spine chart | |
275 | QChart* chart = new QChart(); |
|
277 | QChart* chart = new QChart(); | |
276 | chart->axisX()->setNiceNumbers(true); |
|
278 | chart->axisX()->setNiceNumbers(true); | |
277 | chart->axisY()->setNiceNumbers(true); |
|
279 | chart->axisY()->setNiceNumbers(true); | |
278 | chart->setTitle("Spline chart"); |
|
280 | chart->setTitle("Spline chart"); | |
279 | QString name("Series "); |
|
281 | QString name("Series "); | |
280 | int nameIndex = 0; |
|
282 | int nameIndex = 0; | |
281 | foreach (DataList list, m_dataTable) { |
|
283 | foreach (DataList list, m_dataTable) { | |
282 | QSplineSeries *series = new QSplineSeries(chart); |
|
284 | QSplineSeries *series = new QSplineSeries(chart); | |
283 | foreach (Data data, list) |
|
285 | foreach (Data data, list) | |
284 | series->append(data.first); |
|
286 | series->append(data.first); | |
285 | series->setName(name + QString::number(nameIndex)); |
|
287 | series->setName(name + QString::number(nameIndex)); | |
286 | nameIndex++; |
|
288 | nameIndex++; | |
287 | chart->addSeries(series); |
|
289 | chart->addSeries(series); | |
288 | } |
|
290 | } | |
289 | return chart; |
|
291 | return chart; | |
290 | } |
|
292 | } | |
291 |
|
293 | |||
292 | QChart* ThemeWidget::createScatterChart() const |
|
294 | QChart* ThemeWidget::createScatterChart() const | |
293 | { // scatter chart |
|
295 | { // scatter chart | |
294 | QChart* chart = new QChart(); |
|
296 | QChart* chart = new QChart(); | |
295 | chart->axisX()->setNiceNumbers(true); |
|
297 | chart->axisX()->setNiceNumbers(true); | |
296 | chart->axisY()->setNiceNumbers(true); |
|
298 | chart->axisY()->setNiceNumbers(true); | |
297 | chart->setTitle("Scatter chart"); |
|
299 | chart->setTitle("Scatter chart"); | |
298 | QString name("Series "); |
|
300 | QString name("Series "); | |
299 | int nameIndex = 0; |
|
301 | int nameIndex = 0; | |
300 | foreach (DataList list, m_dataTable) { |
|
302 | foreach (DataList list, m_dataTable) { | |
301 | QScatterSeries *series = new QScatterSeries(chart); |
|
303 | QScatterSeries *series = new QScatterSeries(chart); | |
302 | foreach (Data data, list) |
|
304 | foreach (Data data, list) | |
303 | series->append(data.first); |
|
305 | series->append(data.first); | |
304 | series->setName(name + QString::number(nameIndex)); |
|
306 | series->setName(name + QString::number(nameIndex)); | |
305 | nameIndex++; |
|
307 | nameIndex++; | |
306 | chart->addSeries(series); |
|
308 | chart->addSeries(series); | |
307 | } |
|
309 | } | |
308 | return chart; |
|
310 | return chart; | |
309 | } |
|
311 | } | |
310 |
|
312 | |||
311 | void ThemeWidget::updateUI() |
|
313 | void ThemeWidget::updateUI() | |
312 | { |
|
314 | { | |
313 | QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt(); |
|
315 | QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt(); | |
314 |
|
316 | |||
315 | if (m_charts.at(0)->chart()->theme() != theme) { |
|
317 | if (m_charts.at(0)->chart()->theme() != theme) { | |
316 | foreach (QChartView *chartView, m_charts) |
|
318 | foreach (QChartView *chartView, m_charts) | |
317 | chartView->chart()->setTheme(theme); |
|
319 | chartView->chart()->setTheme(theme); | |
318 |
|
320 | |||
319 | QPalette pal = window()->palette(); |
|
321 | QPalette pal = window()->palette(); | |
320 | if (theme == QChart::ChartThemeLight) { |
|
322 | if (theme == QChart::ChartThemeLight) { | |
321 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); |
|
323 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); | |
322 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
324 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
323 | } else if (theme == QChart::ChartThemeDark) { |
|
325 | } else if (theme == QChart::ChartThemeDark) { | |
324 | pal.setColor(QPalette::Window, QRgb(0x121218)); |
|
326 | pal.setColor(QPalette::Window, QRgb(0x121218)); | |
325 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); |
|
327 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); | |
326 | } else if (theme == QChart::ChartThemeBlueCerulean) { |
|
328 | } else if (theme == QChart::ChartThemeBlueCerulean) { | |
327 | pal.setColor(QPalette::Window, QRgb(0x40434a)); |
|
329 | pal.setColor(QPalette::Window, QRgb(0x40434a)); | |
328 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); |
|
330 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); | |
329 | } else if (theme == QChart::ChartThemeBrownSand) { |
|
331 | } else if (theme == QChart::ChartThemeBrownSand) { | |
330 | pal.setColor(QPalette::Window, QRgb(0x9e8965)); |
|
332 | pal.setColor(QPalette::Window, QRgb(0x9e8965)); | |
331 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
333 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
332 | } else if (theme == QChart::ChartThemeBlueNcs) { |
|
334 | } else if (theme == QChart::ChartThemeBlueNcs) { | |
333 | pal.setColor(QPalette::Window, QRgb(0x018bba)); |
|
335 | pal.setColor(QPalette::Window, QRgb(0x018bba)); | |
334 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
336 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
335 | } else if (theme == QChart::ChartThemeHighContrast) { |
|
337 | } else if (theme == QChart::ChartThemeHighContrast) { | |
336 | pal.setColor(QPalette::Window, QRgb(0xffab03)); |
|
338 | pal.setColor(QPalette::Window, QRgb(0xffab03)); | |
337 | pal.setColor(QPalette::WindowText, QRgb(0x181818)); |
|
339 | pal.setColor(QPalette::WindowText, QRgb(0x181818)); | |
338 | } else if (theme == QChart::ChartThemeBlueIcy) { |
|
340 | } else if (theme == QChart::ChartThemeBlueIcy) { | |
339 | pal.setColor(QPalette::Window, QRgb(0xcee7f0)); |
|
341 | pal.setColor(QPalette::Window, QRgb(0xcee7f0)); | |
340 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
342 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
341 | } else { |
|
343 | } else { | |
342 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); |
|
344 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); | |
343 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
345 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
344 | } |
|
346 | } | |
345 | window()->setPalette(pal); |
|
347 | window()->setPalette(pal); | |
346 | } |
|
348 | } | |
347 |
|
349 | |||
348 | bool checked = m_antialiasCheckBox->isChecked(); |
|
350 | bool checked = m_antialiasCheckBox->isChecked(); | |
349 | foreach (QChartView *chart, m_charts) |
|
351 | foreach (QChartView *chart, m_charts) | |
350 | chart->setRenderHint(QPainter::Antialiasing, checked); |
|
352 | chart->setRenderHint(QPainter::Antialiasing, checked); | |
351 |
|
353 | |||
352 | QChart::AnimationOptions options(m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt()); |
|
354 | QChart::AnimationOptions options(m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt()); | |
353 | if (m_charts.at(0)->chart()->animationOptions() != options) { |
|
355 | if (m_charts.at(0)->chart()->animationOptions() != options) { | |
354 | foreach (QChartView *chartView, m_charts) |
|
356 | foreach (QChartView *chartView, m_charts) | |
355 | chartView->chart()->setAnimationOptions(options); |
|
357 | chartView->chart()->setAnimationOptions(options); | |
356 | } |
|
358 | } | |
357 |
|
359 | |||
358 | int alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt()); |
|
360 | QLegend::Alignments alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt()); | |
359 | if (alignment == -1) { |
|
361 | ||
|
362 | if (!alignment) { | |||
360 | foreach (QChartView *chartView, m_charts) { |
|
363 | foreach (QChartView *chartView, m_charts) { | |
361 |
chartView->chart()->legend()-> |
|
364 | chartView->chart()->legend()->hide(); | |
362 | } |
|
365 | } | |
363 | } else { |
|
366 | } | |
364 | QLegend::Alignments legendAlignment(alignment); |
|
367 | else | |
365 | foreach (QChartView *chartView, m_charts) { |
|
368 | foreach (QChartView *chartView, m_charts) { | |
366 |
chartView->chart()->legend()->setAlignmnent( |
|
369 | chartView->chart()->legend()->setAlignmnent(alignment); | |
367 |
chartView->chart()->legend()->s |
|
370 | chartView->chart()->legend()->show(); | |
368 | } |
|
371 | } | |
369 | } |
|
|||
370 | } |
|
372 | } | |
371 |
|
373 |
@@ -1,72 +1,73 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef QAREASERIES_H_ |
|
21 | #ifndef QAREASERIES_H_ | |
22 | #define QAREASERIES_H_ |
|
22 | #define QAREASERIES_H_ | |
23 |
|
23 | |||
24 | #include <qchartglobal.h> |
|
24 | #include <qchartglobal.h> | |
25 | #include <qseries.h> |
|
25 | #include <qseries.h> | |
26 | #include <QPen> |
|
26 | #include <QPen> | |
27 | #include <QBrush> |
|
27 | #include <QBrush> | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 | class QLineSeries; |
|
30 | class QLineSeries; | |
31 |
|
31 | |||
32 | class QTCOMMERCIALCHART_EXPORT QAreaSeries : public QSeries |
|
32 | class QTCOMMERCIALCHART_EXPORT QAreaSeries : public QSeries | |
33 | { |
|
33 | { | |
34 | Q_OBJECT |
|
34 | Q_OBJECT | |
35 | public: |
|
35 | public: | |
36 | QAreaSeries(QLineSeries *upperSeries, QLineSeries *lowerSeries = 0); |
|
36 | QAreaSeries(QLineSeries *upperSeries, QLineSeries *lowerSeries = 0); | |
37 | virtual ~QAreaSeries(); |
|
37 | virtual ~QAreaSeries(); | |
38 |
|
38 | |||
39 | public: // from QChartSeries |
|
39 | public: // from QChartSeries | |
40 | virtual QSeriesType type() const { return QSeries::SeriesTypeArea; } |
|
40 | virtual QSeriesType type() const { return QSeries::SeriesTypeArea; } | |
41 |
|
41 | |||
42 | QLineSeries* upperSeries() const { return m_upperSeries; } |
|
42 | QLineSeries* upperSeries() const { return m_upperSeries; } | |
43 | QLineSeries* lowerSeries() const { return m_lowerSeries; } |
|
43 | QLineSeries* lowerSeries() const { return m_lowerSeries; } | |
44 |
|
44 | |||
45 | void setPen(const QPen &pen); |
|
45 | void setPen(const QPen &pen); | |
46 | QPen pen() const { return m_pen;} |
|
46 | QPen pen() const { return m_pen;} | |
47 |
|
47 | |||
48 | void setBrush(const QBrush &brush); |
|
48 | void setBrush(const QBrush &brush); | |
49 | QBrush brush() const { return m_brush;} |
|
49 | QBrush brush() const { return m_brush;} | |
50 |
|
50 | |||
51 | void setPointsVisible(bool visible); |
|
51 | void setPointsVisible(bool visible); | |
52 | bool pointsVisible() const { return m_pointsVisible; } |
|
52 | bool pointsVisible() const { return m_pointsVisible; } | |
53 |
|
53 | |||
54 | // bool setModel(QAbstractItemModel* model); |
|
54 | // bool setModel(QAbstractItemModel* model); | |
55 | // void setModelMappingUpper(int modelX, int modelY, Qt::Orientation orientation = Qt::Vertical); |
|
55 | // void setModelMappingUpper(int modelX, int modelY, Qt::Orientation orientation = Qt::Vertical); | |
56 | // void setModelMappingLower(int modelX, int modelY, Qt::Orientation orientation = Qt::Vertical); |
|
56 | // void setModelMappingLower(int modelX, int modelY, Qt::Orientation orientation = Qt::Vertical); | |
57 |
|
57 | |||
58 | Q_SIGNALS: |
|
58 | Q_SIGNALS: | |
59 | void updated(); |
|
59 | void updated(); | |
60 | void clicked(const QPointF &point); |
|
60 | void clicked(const QPointF &point); | |
|
61 | void selected(); | |||
61 |
|
62 | |||
62 | private: |
|
63 | private: | |
63 | QBrush m_brush; |
|
64 | QBrush m_brush; | |
64 | QPen m_pen; |
|
65 | QPen m_pen; | |
65 | QLineSeries* m_upperSeries; |
|
66 | QLineSeries* m_upperSeries; | |
66 | QLineSeries* m_lowerSeries; |
|
67 | QLineSeries* m_lowerSeries; | |
67 | bool m_pointsVisible; |
|
68 | bool m_pointsVisible; | |
68 | }; |
|
69 | }; | |
69 |
|
70 | |||
70 | QTCOMMERCIALCHART_END_NAMESPACE |
|
71 | QTCOMMERCIALCHART_END_NAMESPACE | |
71 |
|
72 | |||
72 | #endif |
|
73 | #endif |
@@ -1,442 +1,465 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "axisitem_p.h" |
|
21 | #include "axisitem_p.h" | |
22 | #include "qchartaxis.h" |
|
22 | #include "qchartaxis.h" | |
23 | #include "chartpresenter_p.h" |
|
23 | #include "chartpresenter_p.h" | |
24 | #include "chartanimator_p.h" |
|
24 | #include "chartanimator_p.h" | |
25 | #include <QPainter> |
|
25 | #include <QPainter> | |
26 | #include <QDebug> |
|
26 | #include <QDebug> | |
27 | #include <cmath> |
|
27 | #include <cmath> | |
28 |
|
28 | |||
29 | static int label_padding = 5; |
|
29 | static int label_padding = 5; | |
30 |
|
30 | |||
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
32 |
|
32 | |||
33 | Axis::Axis(QChartAxis *axis,ChartPresenter *presenter,AxisType type) : Chart(presenter), |
|
33 | Axis::Axis(QChartAxis *axis,ChartPresenter *presenter,AxisType type) : Chart(presenter), | |
34 | m_chartAxis(axis), |
|
34 | m_chartAxis(axis), | |
35 | m_type(type), |
|
35 | m_type(type), | |
36 | m_labelsAngle(0), |
|
36 | m_labelsAngle(0), | |
37 | m_grid(new QGraphicsItemGroup(presenter->rootItem())), |
|
37 | m_grid(new QGraphicsItemGroup(presenter->rootItem())), | |
38 | m_shades(new QGraphicsItemGroup(presenter->rootItem())), |
|
38 | m_shades(new QGraphicsItemGroup(presenter->rootItem())), | |
39 | m_labels(new QGraphicsItemGroup(presenter->rootItem())), |
|
39 | m_labels(new QGraphicsItemGroup(presenter->rootItem())), | |
40 | m_axis(new QGraphicsItemGroup(presenter->rootItem())), |
|
40 | m_axis(new QGraphicsItemGroup(presenter->rootItem())), | |
41 | m_min(0), |
|
41 | m_min(0), | |
42 | m_max(0), |
|
42 | m_max(0), | |
43 | m_ticksCount(0) |
|
43 | m_ticksCount(0) | |
44 | { |
|
44 | { | |
45 | //initial initialization |
|
45 | //initial initialization | |
46 | m_axis->setZValue(ChartPresenter::AxisZValue); |
|
46 | m_axis->setZValue(ChartPresenter::AxisZValue); | |
47 | m_axis->setHandlesChildEvents(false); |
|
47 | m_axis->setHandlesChildEvents(false); | |
48 |
|
48 | |||
49 | m_shades->setZValue(ChartPresenter::ShadesZValue); |
|
49 | m_shades->setZValue(ChartPresenter::ShadesZValue); | |
50 | m_grid->setZValue(ChartPresenter::GridZValue); |
|
50 | m_grid->setZValue(ChartPresenter::GridZValue); | |
51 |
|
51 | |||
52 | connect(m_chartAxis,SIGNAL(updated()),this,SLOT(handleAxisUpdated())); |
|
52 | connect(m_chartAxis,SIGNAL(updated()),this,SLOT(handleAxisUpdated())); | |
53 | connect(m_chartAxis->categories(),SIGNAL(updated()),this,SLOT(handleAxisCategoriesUpdated())); |
|
53 | connect(m_chartAxis->categories(),SIGNAL(updated()),this,SLOT(handleAxisCategoriesUpdated())); | |
54 |
|
54 | |||
55 | handleAxisUpdated(); |
|
55 | handleAxisUpdated(); | |
56 | } |
|
56 | } | |
57 |
|
57 | |||
58 | Axis::~Axis() |
|
58 | Axis::~Axis() | |
59 | { |
|
59 | { | |
60 | } |
|
60 | } | |
61 |
|
61 | |||
62 | void Axis::createItems(int count) |
|
62 | void Axis::createItems(int count) | |
63 | { |
|
63 | { | |
64 |
|
64 | |||
65 | if (m_axis->children().size() == 0) |
|
65 | if (m_axis->children().size() == 0) | |
66 | m_axis->addToGroup(new AxisItem(this)); |
|
66 | m_axis->addToGroup(new AxisItem(this)); | |
67 | for (int i = 0; i < count; ++i) { |
|
67 | for (int i = 0; i < count; ++i) { | |
68 | m_grid->addToGroup(new QGraphicsLineItem()); |
|
68 | m_grid->addToGroup(new QGraphicsLineItem()); | |
69 | m_labels->addToGroup(new QGraphicsSimpleTextItem()); |
|
69 | m_labels->addToGroup(new QGraphicsSimpleTextItem()); | |
70 | m_axis->addToGroup(new QGraphicsLineItem()); |
|
70 | m_axis->addToGroup(new QGraphicsLineItem()); | |
71 | if ((m_grid->childItems().size())%2 && m_grid->childItems().size()>2) m_shades->addToGroup(new QGraphicsRectItem()); |
|
71 | if ((m_grid->childItems().size())%2 && m_grid->childItems().size()>2) m_shades->addToGroup(new QGraphicsRectItem()); | |
72 | } |
|
72 | } | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 | void Axis::deleteItems(int count) |
|
75 | void Axis::deleteItems(int count) | |
76 | { |
|
76 | { | |
77 | QList<QGraphicsItem *> lines = m_grid->childItems(); |
|
77 | QList<QGraphicsItem *> lines = m_grid->childItems(); | |
78 | QList<QGraphicsItem *> labels = m_labels->childItems(); |
|
78 | QList<QGraphicsItem *> labels = m_labels->childItems(); | |
79 | QList<QGraphicsItem *> shades = m_shades->childItems(); |
|
79 | QList<QGraphicsItem *> shades = m_shades->childItems(); | |
80 | QList<QGraphicsItem *> axis = m_axis->childItems(); |
|
80 | QList<QGraphicsItem *> axis = m_axis->childItems(); | |
81 |
|
81 | |||
82 | for (int i = 0; i < count; ++i) { |
|
82 | for (int i = 0; i < count; ++i) { | |
83 | if (lines.size()%2 && lines.size() > 1) delete(shades.takeLast()); |
|
83 | if (lines.size()%2 && lines.size() > 1) delete(shades.takeLast()); | |
84 | delete(lines.takeLast()); |
|
84 | delete(lines.takeLast()); | |
85 | delete(labels.takeLast()); |
|
85 | delete(labels.takeLast()); | |
86 | delete(axis.takeLast()); |
|
86 | delete(axis.takeLast()); | |
87 | } |
|
87 | } | |
88 | } |
|
88 | } | |
89 |
|
89 | |||
90 | void Axis::updateLayout(QVector<qreal> &layout) |
|
90 | void Axis::updateLayout(QVector<qreal> &layout) | |
91 | { |
|
91 | { | |
92 | if (animator()) { |
|
92 | if (animator()) { | |
93 | animator()->updateLayout(this,layout); |
|
93 | animator()->updateLayout(this,layout); | |
94 | } else { |
|
94 | } else { | |
95 | setLayout(layout); |
|
95 | setLayout(layout); | |
96 | } |
|
96 | } | |
97 | } |
|
97 | } | |
98 |
|
98 | |||
99 | bool Axis::createLabels(QStringList &labels,qreal min, qreal max,int ticks) const |
|
99 | bool Axis::createLabels(QStringList &labels,qreal min, qreal max,int ticks) const | |
100 | { |
|
100 | { | |
101 | Q_ASSERT(max>=min); |
|
101 | Q_ASSERT(max>=min); | |
102 | Q_ASSERT(ticks>1); |
|
102 | Q_ASSERT(ticks>1); | |
103 |
|
103 | |||
104 | QChartAxisCategories* categories = m_chartAxis->categories(); |
|
104 | QChartAxisCategories* categories = m_chartAxis->categories(); | |
105 |
|
105 | |||
106 | bool category = categories->count()>0; |
|
106 | bool category = categories->count()>0; | |
107 |
|
107 | |||
108 | if (!category) { |
|
108 | if (!category) { | |
109 | int n = qMax(int(-floor(log10((max-min)/(ticks-1)))),0); |
|
109 | int n = qMax(int(-floor(log10((max-min)/(ticks-1)))),0); | |
110 | n++; |
|
110 | n++; | |
111 | for (int i=0; i< ticks; i++) { |
|
111 | for (int i=0; i< ticks; i++) { | |
112 | qreal value = min + (i * (max - min)/ (ticks-1)); |
|
112 | qreal value = min + (i * (max - min)/ (ticks-1)); | |
113 | labels << QString::number(value,'f',n); |
|
113 | labels << QString::number(value,'f',n); | |
114 | } |
|
114 | } | |
115 | } else { |
|
115 | } else { | |
116 | QList<qreal> values = categories->values(); |
|
116 | QList<qreal> values = categories->values(); | |
117 | for (int i=0; i< ticks; i++) { |
|
117 | for (int i=0; i< ticks; i++) { | |
118 | qreal value = (min + (i * (max - min)/ (ticks-1))); |
|
118 | qreal value = (min + (i * (max - min)/ (ticks-1))); | |
119 | int j=0; |
|
119 | int j=0; | |
120 | for (; j<values.count(); j++) { |
|
120 | for (; j<values.count(); j++) { | |
121 | if (values.at(j) > value) break; |
|
121 | if (values.at(j) > value) break; | |
122 | } |
|
122 | } | |
123 | if (j!=0) value=values.at(j-1); |
|
123 | if (j!=0) value=values.at(j-1); | |
124 |
|
124 | |||
125 | QString label = categories->label(value); |
|
125 | QString label = categories->label(value); | |
126 | labels << label; |
|
126 | labels << label; | |
127 | } |
|
127 | } | |
128 | } |
|
128 | } | |
129 |
|
129 | |||
130 | return category; |
|
130 | return category; | |
131 | } |
|
131 | } | |
132 |
|
132 | |||
133 | void Axis::setAxisOpacity(qreal opacity) |
|
133 | void Axis::setAxisOpacity(qreal opacity) | |
134 | { |
|
134 | { | |
135 | m_axis->setOpacity(opacity); |
|
135 | m_axis->setOpacity(opacity); | |
136 | } |
|
136 | } | |
137 |
|
137 | |||
138 | qreal Axis::axisOpacity() const |
|
138 | qreal Axis::axisOpacity() const | |
139 | { |
|
139 | { | |
140 | return m_axis->opacity(); |
|
140 | return m_axis->opacity(); | |
141 | } |
|
141 | } | |
142 |
|
142 | |||
143 | void Axis::setGridOpacity(qreal opacity) |
|
143 | void Axis::setGridOpacity(qreal opacity) | |
144 | { |
|
144 | { | |
145 | m_grid->setOpacity(opacity); |
|
145 | m_grid->setOpacity(opacity); | |
146 | } |
|
146 | } | |
147 |
|
147 | |||
148 | qreal Axis::gridOpacity() const |
|
148 | qreal Axis::gridOpacity() const | |
149 | { |
|
149 | { | |
150 | return m_grid->opacity(); |
|
150 | return m_grid->opacity(); | |
151 | } |
|
151 | } | |
152 |
|
152 | |||
153 | void Axis::setLabelsOpacity(qreal opacity) |
|
153 | void Axis::setLabelsOpacity(qreal opacity) | |
154 | { |
|
154 | { | |
155 | m_labels->setOpacity(opacity); |
|
155 | m_labels->setOpacity(opacity); | |
156 | } |
|
156 | } | |
157 |
|
157 | |||
158 | qreal Axis::labelsOpacity() const |
|
158 | qreal Axis::labelsOpacity() const | |
159 | { |
|
159 | { | |
160 | return m_labels->opacity(); |
|
160 | return m_labels->opacity(); | |
161 | } |
|
161 | } | |
162 |
|
162 | |||
163 | void Axis::setShadesOpacity(qreal opacity) |
|
163 | void Axis::setShadesOpacity(qreal opacity) | |
164 | { |
|
164 | { | |
165 | m_shades->setOpacity(opacity); |
|
165 | m_shades->setOpacity(opacity); | |
166 | } |
|
166 | } | |
167 |
|
167 | |||
168 | qreal Axis::shadesOpacity() const |
|
168 | qreal Axis::shadesOpacity() const | |
169 | { |
|
169 | { | |
170 | return m_shades->opacity(); |
|
170 | return m_shades->opacity(); | |
171 | } |
|
171 | } | |
172 |
|
172 | |||
173 | void Axis::setLabelsAngle(int angle) |
|
173 | void Axis::setLabelsAngle(int angle) | |
174 | { |
|
174 | { | |
175 | foreach(QGraphicsItem* item , m_labels->childItems()) { |
|
175 | foreach(QGraphicsItem* item , m_labels->childItems()) { | |
176 | item->setRotation(angle); |
|
176 | item->setRotation(angle); | |
177 | } |
|
177 | } | |
178 |
|
178 | |||
179 | m_labelsAngle=angle; |
|
179 | m_labelsAngle=angle; | |
180 | } |
|
180 | } | |
181 |
|
181 | |||
182 | void Axis::setLabelsPen(const QPen &pen) |
|
182 | void Axis::setLabelsPen(const QPen &pen) | |
183 | { |
|
183 | { | |
184 | foreach(QGraphicsItem* item , m_labels->childItems()) { |
|
184 | foreach(QGraphicsItem* item , m_labels->childItems()) { | |
185 | static_cast<QGraphicsSimpleTextItem*>(item)->setPen(pen); |
|
185 | static_cast<QGraphicsSimpleTextItem*>(item)->setPen(pen); | |
186 | } |
|
186 | } | |
187 | } |
|
187 | } | |
188 |
|
188 | |||
189 | void Axis::setLabelsBrush(const QBrush &brush) |
|
189 | void Axis::setLabelsBrush(const QBrush &brush) | |
190 | { |
|
190 | { | |
191 | foreach(QGraphicsItem* item , m_labels->childItems()) { |
|
191 | foreach(QGraphicsItem* item , m_labels->childItems()) { | |
192 | static_cast<QGraphicsSimpleTextItem*>(item)->setBrush(brush); |
|
192 | static_cast<QGraphicsSimpleTextItem*>(item)->setBrush(brush); | |
193 | } |
|
193 | } | |
194 | } |
|
194 | } | |
195 |
|
195 | |||
196 | void Axis::setLabelsFont(const QFont &font) |
|
196 | void Axis::setLabelsFont(const QFont &font) | |
197 | { |
|
197 | { | |
198 | foreach(QGraphicsItem* item , m_labels->childItems()) { |
|
198 | foreach(QGraphicsItem* item , m_labels->childItems()) { | |
199 | static_cast<QGraphicsSimpleTextItem*>(item)->setFont(font); |
|
199 | static_cast<QGraphicsSimpleTextItem*>(item)->setFont(font); | |
200 | } |
|
200 | } | |
201 | } |
|
201 | } | |
202 |
|
202 | |||
203 | void Axis::setShadesBrush(const QBrush &brush) |
|
203 | void Axis::setShadesBrush(const QBrush &brush) | |
204 | { |
|
204 | { | |
205 | foreach(QGraphicsItem* item , m_shades->childItems()) { |
|
205 | foreach(QGraphicsItem* item , m_shades->childItems()) { | |
206 | static_cast<QGraphicsRectItem*>(item)->setBrush(brush); |
|
206 | static_cast<QGraphicsRectItem*>(item)->setBrush(brush); | |
207 | } |
|
207 | } | |
208 | } |
|
208 | } | |
209 |
|
209 | |||
210 | void Axis::setShadesPen(const QPen &pen) |
|
210 | void Axis::setShadesPen(const QPen &pen) | |
211 | { |
|
211 | { | |
212 | foreach(QGraphicsItem* item , m_shades->childItems()) { |
|
212 | foreach(QGraphicsItem* item , m_shades->childItems()) { | |
213 | static_cast<QGraphicsRectItem*>(item)->setPen(pen); |
|
213 | static_cast<QGraphicsRectItem*>(item)->setPen(pen); | |
214 | } |
|
214 | } | |
215 | } |
|
215 | } | |
216 |
|
216 | |||
217 | void Axis::setAxisPen(const QPen &pen) |
|
217 | void Axis::setAxisPen(const QPen &pen) | |
218 | { |
|
218 | { | |
219 | foreach(QGraphicsItem* item , m_axis->childItems()) { |
|
219 | foreach(QGraphicsItem* item , m_axis->childItems()) { | |
220 | static_cast<QGraphicsLineItem*>(item)->setPen(pen); |
|
220 | static_cast<QGraphicsLineItem*>(item)->setPen(pen); | |
221 | } |
|
221 | } | |
222 | } |
|
222 | } | |
223 |
|
223 | |||
224 | void Axis::setGridPen(const QPen &pen) |
|
224 | void Axis::setGridPen(const QPen &pen) | |
225 | { |
|
225 | { | |
226 | foreach(QGraphicsItem* item , m_grid->childItems()) { |
|
226 | foreach(QGraphicsItem* item , m_grid->childItems()) { | |
227 | static_cast<QGraphicsLineItem*>(item)->setPen(pen); |
|
227 | static_cast<QGraphicsLineItem*>(item)->setPen(pen); | |
228 | } |
|
228 | } | |
229 | } |
|
229 | } | |
230 |
|
230 | |||
231 | QVector<qreal> Axis::calculateLayout() const |
|
231 | QVector<qreal> Axis::calculateLayout() const | |
232 | { |
|
232 | { | |
233 | Q_ASSERT(m_ticksCount>=2); |
|
233 | Q_ASSERT(m_ticksCount>=2); | |
234 |
|
234 | |||
235 | QVector<qreal> points; |
|
235 | QVector<qreal> points; | |
236 | points.resize(m_ticksCount); |
|
236 | points.resize(m_ticksCount); | |
237 |
|
237 | |||
238 | switch (m_type) |
|
238 | switch (m_type) | |
239 | { |
|
239 | { | |
240 | case X_AXIS: |
|
240 | case X_AXIS: | |
241 | { |
|
241 | { | |
242 | const qreal deltaX = m_rect.width()/(m_ticksCount-1); |
|
242 | const qreal deltaX = m_rect.width()/(m_ticksCount-1); | |
243 | for (int i = 0; i < m_ticksCount; ++i) { |
|
243 | for (int i = 0; i < m_ticksCount; ++i) { | |
244 | int x = i * deltaX + m_rect.left(); |
|
244 | int x = i * deltaX + m_rect.left(); | |
245 | points[i] = x; |
|
245 | points[i] = x; | |
246 | } |
|
246 | } | |
247 | } |
|
247 | } | |
248 | break; |
|
248 | break; | |
249 | case Y_AXIS: |
|
249 | case Y_AXIS: | |
250 | { |
|
250 | { | |
251 | const qreal deltaY = m_rect.height()/(m_ticksCount-1); |
|
251 | const qreal deltaY = m_rect.height()/(m_ticksCount-1); | |
252 | for (int i = 0; i < m_ticksCount; ++i) { |
|
252 | for (int i = 0; i < m_ticksCount; ++i) { | |
253 | int y = i * -deltaY + m_rect.bottom(); |
|
253 | int y = i * -deltaY + m_rect.bottom(); | |
254 | points[i] = y; |
|
254 | points[i] = y; | |
255 | } |
|
255 | } | |
256 | } |
|
256 | } | |
257 | break; |
|
257 | break; | |
258 | } |
|
258 | } | |
259 | return points; |
|
259 | return points; | |
260 | } |
|
260 | } | |
261 |
|
261 | |||
262 | void Axis::setLayout(QVector<qreal> &layout) |
|
262 | void Axis::setLayout(QVector<qreal> &layout) | |
263 | { |
|
263 | { | |
264 | int diff = m_layoutVector.size() - layout.size(); |
|
264 | int diff = m_layoutVector.size() - layout.size(); | |
265 |
|
265 | |||
266 | if (diff>0) { |
|
266 | if (diff>0) { | |
267 | deleteItems(diff); |
|
267 | deleteItems(diff); | |
268 | } else if (diff<0) { |
|
268 | } else if (diff<0) { | |
269 | createItems(-diff); |
|
269 | createItems(-diff); | |
270 | } |
|
270 | } | |
271 |
|
271 | |||
272 | if( diff!=0) handleAxisUpdated(); |
|
272 | if( diff!=0) handleAxisUpdated(); | |
273 |
|
273 | |||
274 | QStringList ticksList; |
|
274 | QStringList ticksList; | |
275 |
|
275 | |||
276 | bool categories = createLabels(ticksList,m_min,m_max,layout.size()); |
|
276 | bool categories = createLabels(ticksList,m_min,m_max,layout.size()); | |
277 |
|
277 | |||
278 | QList<QGraphicsItem *> lines = m_grid->childItems(); |
|
278 | QList<QGraphicsItem *> lines = m_grid->childItems(); | |
279 | QList<QGraphicsItem *> labels = m_labels->childItems(); |
|
279 | QList<QGraphicsItem *> labels = m_labels->childItems(); | |
280 | QList<QGraphicsItem *> shades = m_shades->childItems(); |
|
280 | QList<QGraphicsItem *> shades = m_shades->childItems(); | |
281 | QList<QGraphicsItem *> axis = m_axis->childItems(); |
|
281 | QList<QGraphicsItem *> axis = m_axis->childItems(); | |
282 |
|
282 | |||
283 | Q_ASSERT(labels.size() == ticksList.size()); |
|
283 | Q_ASSERT(labels.size() == ticksList.size()); | |
284 | Q_ASSERT(layout.size() == ticksList.size()); |
|
284 | Q_ASSERT(layout.size() == ticksList.size()); | |
285 |
|
285 | |||
|
286 | qreal minWidth = 0; | |||
|
287 | qreal minHeight = 0; | |||
|
288 | ||||
286 | switch (m_type) |
|
289 | switch (m_type) | |
287 | { |
|
290 | { | |
288 | case X_AXIS: |
|
291 | case X_AXIS: | |
289 | { |
|
292 | { | |
290 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); |
|
293 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); | |
291 | lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom()); |
|
294 | lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom()); | |
292 |
|
295 | |||
293 | for (int i = 0; i < layout.size(); ++i) { |
|
296 | for (int i = 0; i < layout.size(); ++i) { | |
294 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); |
|
297 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); | |
295 | lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom()); |
|
298 | lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom()); | |
296 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); |
|
299 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); | |
297 | if (!categories || i<1) { |
|
300 | if (!categories || i<1) { | |
298 | labelItem->setText(ticksList.at(i)); |
|
301 | labelItem->setText(ticksList.at(i)); | |
299 |
|
|
302 | const QRectF& rect = labelItem->boundingRect(); | |
|
303 | minWidth+=rect.width(); | |||
|
304 | minHeight=qMax(rect.height(),minHeight); | |||
|
305 | QPointF center = rect.center(); | |||
300 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
306 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
301 | labelItem->setPos(layout[i] - center.x(), m_rect.bottom() + label_padding); |
|
307 | labelItem->setPos(layout[i] - center.x(), m_rect.bottom() + label_padding); | |
302 | } else { |
|
308 | } else { | |
303 | labelItem->setText(ticksList.at(i)); |
|
309 | labelItem->setText(ticksList.at(i)); | |
304 |
|
|
310 | const QRectF& rect = labelItem->boundingRect(); | |
|
311 | minWidth+=rect.width(); | |||
|
312 | minHeight=qMax(rect.height()+label_padding,minHeight); | |||
|
313 | QPointF center = rect.center(); | |||
305 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
314 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
306 | labelItem->setPos(layout[i] - (layout[i] - layout[i-1])/2 - center.x(), m_rect.bottom() + label_padding); |
|
315 | labelItem->setPos(layout[i] - (layout[i] - layout[i-1])/2 - center.x(), m_rect.bottom() + label_padding); | |
307 | } |
|
316 | } | |
308 |
|
317 | |||
309 | if ((i+1)%2 && i>1) { |
|
318 | if ((i+1)%2 && i>1) { | |
310 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); |
|
319 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); | |
311 | rectItem->setRect(layout[i-1],m_rect.top(),layout[i]-layout[i-1],m_rect.height()); |
|
320 | rectItem->setRect(layout[i-1],m_rect.top(),layout[i]-layout[i-1],m_rect.height()); | |
312 | } |
|
321 | } | |
313 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); |
|
322 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); | |
314 | lineItem->setLine(layout[i],m_rect.bottom(),layout[i],m_rect.bottom()+5); |
|
323 | lineItem->setLine(layout[i],m_rect.bottom(),layout[i],m_rect.bottom()+5); | |
315 | } |
|
324 | } | |
|
325 | ||||
316 | } |
|
326 | } | |
317 | break; |
|
327 | break; | |
318 |
|
328 | |||
319 | case Y_AXIS: |
|
329 | case Y_AXIS: | |
320 | { |
|
330 | { | |
321 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); |
|
331 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); | |
322 | lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom()); |
|
332 | lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom()); | |
323 |
|
333 | |||
324 | for (int i = 0; i < layout.size(); ++i) { |
|
334 | for (int i = 0; i < layout.size(); ++i) { | |
325 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); |
|
335 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); | |
326 | lineItem->setLine(m_rect.left() , layout[i], m_rect.right(), layout[i]); |
|
336 | lineItem->setLine(m_rect.left() , layout[i], m_rect.right(), layout[i]); | |
327 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); |
|
337 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); | |
328 |
|
338 | |||
329 | if (!categories || i<1) { |
|
339 | if (!categories || i<1) { | |
330 | labelItem->setText(ticksList.at(i)); |
|
340 | labelItem->setText(ticksList.at(i)); | |
331 |
|
|
341 | const QRectF& rect = labelItem->boundingRect(); | |
|
342 | minWidth=qMax(rect.width()+label_padding,minWidth); | |||
|
343 | minHeight+=rect.height(); | |||
|
344 | QPointF center = rect.center(); | |||
332 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
345 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
333 |
labelItem->setPos(m_rect.left() - |
|
346 | labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i]-center.y()); | |
334 | } else { |
|
347 | } else { | |
335 | labelItem->setText(ticksList.at(i)); |
|
348 | labelItem->setText(ticksList.at(i)); | |
336 |
|
|
349 | const QRectF& rect = labelItem->boundingRect(); | |
|
350 | minWidth=qMax(rect.width(),minWidth); | |||
|
351 | minHeight+=rect.height(); | |||
|
352 | QPointF center = rect.center(); | |||
337 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
353 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
338 |
labelItem->setPos(m_rect.left() - |
|
354 | labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i] - (layout[i] - layout[i-1])/2 -center.y()); | |
339 | } |
|
355 | } | |
340 |
|
356 | |||
341 | if ((i+1)%2 && i>1) { |
|
357 | if ((i+1)%2 && i>1) { | |
342 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); |
|
358 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); | |
343 | rectItem->setRect(m_rect.left(),layout[i],m_rect.width(),layout[i-1]-layout[i]); |
|
359 | rectItem->setRect(m_rect.left(),layout[i],m_rect.width(),layout[i-1]-layout[i]); | |
344 | } |
|
360 | } | |
345 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); |
|
361 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); | |
346 | lineItem->setLine(m_rect.left()-5,layout[i],m_rect.left(),layout[i]); |
|
362 | lineItem->setLine(m_rect.left()-5,layout[i],m_rect.left(),layout[i]); | |
347 | } |
|
363 | } | |
348 | } |
|
364 | } | |
349 | break; |
|
365 | break; | |
350 | default: |
|
366 | default: | |
351 | qDebug()<<"Unknown axis type"; |
|
367 | qDebug()<<"Unknown axis type"; | |
352 | break; |
|
368 | break; | |
353 | } |
|
369 | } | |
354 |
|
370 | |||
355 |
|
|
371 | m_layoutVector=layout; | |
|
372 | ||||
|
373 | presenter()->setMinimumMarginWidth(this,minWidth); | |||
|
374 | presenter()->setMinimumMarginHeight(this,minHeight); | |||
|
375 | ||||
356 | } |
|
376 | } | |
357 |
|
377 | |||
358 | bool Axis::isEmpty() |
|
378 | bool Axis::isEmpty() | |
359 | { |
|
379 | { | |
360 | return m_rect.isEmpty() || qFuzzyIsNull(m_min - m_max) || m_ticksCount==0; |
|
380 | return m_rect.isEmpty() || qFuzzyIsNull(m_min - m_max) || m_ticksCount==0; | |
361 | } |
|
381 | } | |
362 |
|
382 | |||
363 | //handlers |
|
383 | //handlers | |
364 |
|
384 | |||
365 | void Axis::handleAxisCategoriesUpdated() |
|
385 | void Axis::handleAxisCategoriesUpdated() | |
366 | { |
|
386 | { | |
367 | if (isEmpty()) return; |
|
387 | if (isEmpty()) return; | |
368 | updateLayout(m_layoutVector); |
|
388 | updateLayout(m_layoutVector); | |
369 | } |
|
389 | } | |
370 |
|
390 | |||
371 | void Axis::handleAxisUpdated() |
|
391 | void Axis::handleAxisUpdated() | |
372 | { |
|
392 | { | |
373 |
|
393 | |||
374 | if (isEmpty()) return; |
|
394 | if (isEmpty()) return; | |
375 |
|
395 | |||
376 | if (m_chartAxis->isAxisVisible()) { |
|
396 | if (m_chartAxis->isAxisVisible()) { | |
377 | setAxisOpacity(100); |
|
397 | setAxisOpacity(100); | |
378 | } else { |
|
398 | } else { | |
379 | setAxisOpacity(0); |
|
399 | setAxisOpacity(0); | |
380 | } |
|
400 | } | |
381 |
|
401 | |||
382 | if (m_chartAxis->isGridLineVisible()) { |
|
402 | if (m_chartAxis->isGridLineVisible()) { | |
383 | setGridOpacity(100); |
|
403 | setGridOpacity(100); | |
384 | } else { |
|
404 | } else { | |
385 | setGridOpacity(0); |
|
405 | setGridOpacity(0); | |
386 | } |
|
406 | } | |
387 |
|
407 | |||
388 | if (m_chartAxis->labelsVisible()) { |
|
408 | if (m_chartAxis->labelsVisible()) { | |
389 | setLabelsOpacity(100); |
|
409 | setLabelsOpacity(100); | |
390 | } else { |
|
410 | } else { | |
391 | setLabelsOpacity(0); |
|
411 | setLabelsOpacity(0); | |
392 | } |
|
412 | } | |
393 |
|
413 | |||
394 | if (m_chartAxis->shadesVisible()) { |
|
414 | if (m_chartAxis->shadesVisible()) { | |
395 | setShadesOpacity(m_chartAxis->shadesOpacity()); |
|
415 | setShadesOpacity(m_chartAxis->shadesOpacity()); | |
396 | } else { |
|
416 | } else { | |
397 | setShadesOpacity(0); |
|
417 | setShadesOpacity(0); | |
398 | } |
|
418 | } | |
399 |
|
419 | |||
400 | setLabelsAngle(m_chartAxis->labelsAngle()); |
|
420 | setLabelsAngle(m_chartAxis->labelsAngle()); | |
401 | setAxisPen(m_chartAxis->axisPen()); |
|
421 | setAxisPen(m_chartAxis->axisPen()); | |
402 | setLabelsPen(m_chartAxis->labelsPen()); |
|
422 | setLabelsPen(m_chartAxis->labelsPen()); | |
403 | setLabelsBrush(m_chartAxis->labelsBrush()); |
|
423 | setLabelsBrush(m_chartAxis->labelsBrush()); | |
404 | setLabelsFont(m_chartAxis->labelsFont()); |
|
424 | setLabelsFont(m_chartAxis->labelsFont()); | |
405 | setGridPen(m_chartAxis->gridLinePen()); |
|
425 | setGridPen(m_chartAxis->gridLinePen()); | |
406 | setShadesPen(m_chartAxis->shadesPen()); |
|
426 | setShadesPen(m_chartAxis->shadesPen()); | |
407 | setShadesBrush(m_chartAxis->shadesBrush()); |
|
427 | setShadesBrush(m_chartAxis->shadesBrush()); | |
408 |
|
428 | |||
409 | } |
|
429 | } | |
410 |
|
430 | |||
411 | void Axis::handleRangeChanged(qreal min, qreal max,int tickCount) |
|
431 | void Axis::handleRangeChanged(qreal min, qreal max,int tickCount) | |
412 | { |
|
432 | { | |
413 | if (qFuzzyIsNull(min - max) || tickCount < 2) |
|
433 | if (qFuzzyIsNull(min - max) || tickCount < 2) | |
414 | return; |
|
434 | return; | |
415 |
|
435 | |||
416 | m_min = min; |
|
436 | m_min = min; | |
417 | m_max = max; |
|
437 | m_max = max; | |
418 | m_ticksCount= tickCount; |
|
438 | m_ticksCount= tickCount; | |
419 |
|
439 | |||
420 | if (isEmpty()) return; |
|
440 | if (isEmpty()) return; | |
421 | QVector<qreal> layout = calculateLayout(); |
|
441 | QVector<qreal> layout = calculateLayout(); | |
422 | updateLayout(layout); |
|
442 | updateLayout(layout); | |
423 |
|
443 | |||
424 | } |
|
444 | } | |
425 |
|
445 | |||
426 | void Axis::handleGeometryChanged(const QRectF &rect) |
|
446 | void Axis::handleGeometryChanged(const QRectF &rect) | |
427 | { |
|
447 | { | |
428 |
m_rect = rect |
|
448 | if(m_rect != rect) | |
429 | if (isEmpty()) return; |
|
449 | { | |
430 | QVector<qreal> layout = calculateLayout(); |
|
450 | m_rect = rect; | |
431 | updateLayout(layout); |
|
451 | if (isEmpty()) return; | |
|
452 | QVector<qreal> layout = calculateLayout(); | |||
|
453 | updateLayout(layout); | |||
|
454 | } | |||
432 | } |
|
455 | } | |
433 |
|
456 | |||
434 | void Axis::axisSelected() |
|
457 | void Axis::axisSelected() | |
435 | { |
|
458 | { | |
436 | qDebug()<<"TODO axis clicked"; |
|
459 | qDebug()<<"TODO axis clicked"; | |
437 | } |
|
460 | } | |
438 |
|
461 | |||
439 | //TODO "nice numbers algorithm" |
|
462 | //TODO "nice numbers algorithm" | |
440 | #include "moc_axisitem_p.cpp" |
|
463 | #include "moc_axisitem_p.cpp" | |
441 |
|
464 | |||
442 | QTCOMMERCIALCHART_END_NAMESPACE |
|
465 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,143 +1,143 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef AXISITEM_H_ |
|
21 | #ifndef AXISITEM_H_ | |
22 | #define AXISITEM_H_ |
|
22 | #define AXISITEM_H_ | |
23 |
|
23 | |||
|
24 | #include "qchartglobal.h" | |||
24 | #include "chart_p.h" |
|
25 | #include "chart_p.h" | |
25 | #include <QGraphicsItem> |
|
26 | #include <QGraphicsItem> | |
26 |
|
27 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
29 | |||
29 | class QChartAxis; |
|
30 | class QChartAxis; | |
30 | class ChartPresenter; |
|
31 | class ChartPresenter; | |
31 |
|
32 | |||
32 | class Axis : public Chart |
|
33 | class Axis : public Chart | |
33 | { |
|
34 | { | |
34 | Q_OBJECT |
|
35 | Q_OBJECT | |
35 | public: |
|
36 | public: | |
36 | enum AxisType{X_AXIS,Y_AXIS}; |
|
37 | enum AxisType{X_AXIS,Y_AXIS}; | |
37 |
|
38 | |||
38 | Axis(QChartAxis *axis, ChartPresenter *presenter, AxisType type = X_AXIS); |
|
39 | Axis(QChartAxis *axis, ChartPresenter *presenter, AxisType type = X_AXIS); | |
39 | ~Axis(); |
|
40 | ~Axis(); | |
40 |
|
41 | |||
41 | AxisType axisType() const { return m_type; } |
|
42 | AxisType axisType() const { return m_type; } | |
42 |
|
43 | |||
43 | void setAxisOpacity(qreal opacity); |
|
44 | void setAxisOpacity(qreal opacity); | |
44 | qreal axisOpacity() const; |
|
45 | qreal axisOpacity() const; | |
45 |
|
46 | |||
46 | void setGridOpacity(qreal opacity); |
|
47 | void setGridOpacity(qreal opacity); | |
47 | qreal gridOpacity() const; |
|
48 | qreal gridOpacity() const; | |
48 |
|
49 | |||
49 | void setLabelsOpacity(qreal opacity); |
|
50 | void setLabelsOpacity(qreal opacity); | |
50 | qreal labelsOpacity() const; |
|
51 | qreal labelsOpacity() const; | |
51 |
|
52 | |||
52 | void setShadesOpacity(qreal opacity); |
|
53 | void setShadesOpacity(qreal opacity); | |
53 | qreal shadesOpacity() const; |
|
54 | qreal shadesOpacity() const; | |
54 |
|
55 | |||
55 | void setLabelsAngle(int angle); |
|
56 | void setLabelsAngle(int angle); | |
56 | int labelsAngle()const { return m_labelsAngle; } |
|
57 | int labelsAngle()const { return m_labelsAngle; } | |
57 |
|
58 | |||
58 | void setShadesBrush(const QBrush &brush); |
|
59 | void setShadesBrush(const QBrush &brush); | |
59 | void setShadesPen(const QPen &pen); |
|
60 | void setShadesPen(const QPen &pen); | |
60 |
|
61 | |||
61 | void setAxisPen(const QPen &pen); |
|
62 | void setAxisPen(const QPen &pen); | |
62 | void setGridPen(const QPen &pen); |
|
63 | void setGridPen(const QPen &pen); | |
63 |
|
64 | |||
64 | void setLabelsPen(const QPen &pen); |
|
65 | void setLabelsPen(const QPen &pen); | |
65 | void setLabelsBrush(const QBrush &brush); |
|
66 | void setLabelsBrush(const QBrush &brush); | |
66 | void setLabelsFont(const QFont &font); |
|
67 | void setLabelsFont(const QFont &font); | |
67 |
|
68 | |||
68 | inline QRectF geometry() const { return m_rect; } |
|
69 | inline QRectF geometry() const { return m_rect; } | |
69 | inline QVector<qreal> layout() { return m_layoutVector; } |
|
70 | inline QVector<qreal> layout() { return m_layoutVector; } | |
70 |
|
71 | |||
71 | public Q_SLOTS: |
|
72 | public Q_SLOTS: | |
72 | void handleAxisUpdated(); |
|
73 | void handleAxisUpdated(); | |
73 | void handleAxisCategoriesUpdated(); |
|
74 | void handleAxisCategoriesUpdated(); | |
74 | void handleRangeChanged(qreal min , qreal max,int tickCount); |
|
75 | void handleRangeChanged(qreal min , qreal max,int tickCount); | |
75 | void handleGeometryChanged(const QRectF &size); |
|
76 | void handleGeometryChanged(const QRectF &size); | |
76 |
|
77 | |||
77 |
|
78 | |||
78 | private: |
|
79 | private: | |
79 | inline bool isEmpty(); |
|
80 | inline bool isEmpty(); | |
80 | void createItems(int count); |
|
81 | void createItems(int count); | |
81 | void deleteItems(int count); |
|
82 | void deleteItems(int count); | |
82 |
|
83 | |||
83 | QVector<qreal> calculateLayout() const; |
|
84 | QVector<qreal> calculateLayout() const; | |
84 | void updateLayout(QVector<qreal> &layout); |
|
85 | void updateLayout(QVector<qreal> &layout); | |
85 | void setLayout(QVector<qreal> &layout); |
|
86 | void setLayout(QVector<qreal> &layout); | |
86 |
|
87 | |||
87 | bool createLabels(QStringList &labels,qreal min, qreal max,int ticks) const; |
|
88 | bool createLabels(QStringList &labels,qreal min, qreal max,int ticks) const; | |
88 | void axisSelected(); |
|
89 | void axisSelected(); | |
89 |
|
90 | |||
90 | private: |
|
91 | private: | |
91 | QChartAxis* m_chartAxis; |
|
92 | QChartAxis* m_chartAxis; | |
92 | AxisType m_type; |
|
93 | AxisType m_type; | |
93 | QRectF m_rect; |
|
94 | QRectF m_rect; | |
94 | int m_labelsAngle; |
|
95 | int m_labelsAngle; | |
95 | QScopedPointer<QGraphicsItemGroup> m_grid; |
|
96 | QScopedPointer<QGraphicsItemGroup> m_grid; | |
96 | QScopedPointer<QGraphicsItemGroup> m_shades; |
|
97 | QScopedPointer<QGraphicsItemGroup> m_shades; | |
97 | QScopedPointer<QGraphicsItemGroup> m_labels; |
|
98 | QScopedPointer<QGraphicsItemGroup> m_labels; | |
98 | QScopedPointer<QGraphicsItemGroup> m_axis; |
|
99 | QScopedPointer<QGraphicsItemGroup> m_axis; | |
99 | QVector<qreal> m_layoutVector; |
|
100 | QVector<qreal> m_layoutVector; | |
100 | qreal m_min; |
|
101 | qreal m_min; | |
101 | qreal m_max; |
|
102 | qreal m_max; | |
102 | int m_ticksCount; |
|
103 | int m_ticksCount; | |
103 | qreal m_zoomFactor; |
|
|||
104 |
|
104 | |||
105 | friend class AxisAnimation; |
|
105 | friend class AxisAnimation; | |
106 | friend class AxisItem; |
|
106 | friend class AxisItem; | |
107 |
|
107 | |||
108 | }; |
|
108 | }; | |
109 |
|
109 | |||
110 | class AxisItem: public QGraphicsLineItem |
|
110 | class AxisItem: public QGraphicsLineItem | |
111 | { |
|
111 | { | |
112 | public: |
|
112 | public: | |
113 |
|
113 | |||
114 | AxisItem(Axis *axis, QGraphicsItem *parent = 0) : QGraphicsLineItem(parent), m_axis(axis) {} |
|
114 | AxisItem(Axis *axis, QGraphicsItem *parent = 0) : QGraphicsLineItem(parent), m_axis(axis) {} | |
115 |
|
115 | |||
116 | protected: |
|
116 | protected: | |
117 | void mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
117 | void mousePressEvent(QGraphicsSceneMouseEvent *event) | |
118 | { |
|
118 | { | |
119 | Q_UNUSED(event) |
|
119 | Q_UNUSED(event) | |
120 | m_axis->axisSelected(); |
|
120 | m_axis->axisSelected(); | |
121 | } |
|
121 | } | |
122 |
|
122 | |||
123 | QRectF boundingRect() const |
|
123 | QRectF boundingRect() const | |
124 | { |
|
124 | { | |
125 | return shape().boundingRect(); |
|
125 | return shape().boundingRect(); | |
126 | } |
|
126 | } | |
127 |
|
127 | |||
128 | QPainterPath shape() const |
|
128 | QPainterPath shape() const | |
129 | { |
|
129 | { | |
130 | QPainterPath path = QGraphicsLineItem::shape(); |
|
130 | QPainterPath path = QGraphicsLineItem::shape(); | |
131 | QRectF rect = path.boundingRect(); |
|
131 | QRectF rect = path.boundingRect(); | |
132 | path.addRect(rect.adjusted(0,0,m_axis->axisType()!=Axis::X_AXIS?8:0,m_axis->axisType()!=Axis::Y_AXIS?8:0)); |
|
132 | path.addRect(rect.adjusted(0,0,m_axis->axisType()!=Axis::X_AXIS?8:0,m_axis->axisType()!=Axis::Y_AXIS?8:0)); | |
133 | return path; |
|
133 | return path; | |
134 | } |
|
134 | } | |
135 |
|
135 | |||
136 | private: |
|
136 | private: | |
137 | Axis* m_axis; |
|
137 | Axis* m_axis; | |
138 |
|
138 | |||
139 | }; |
|
139 | }; | |
140 |
|
140 | |||
141 | QTCOMMERCIALCHART_END_NAMESPACE |
|
141 | QTCOMMERCIALCHART_END_NAMESPACE | |
142 |
|
142 | |||
143 | #endif /* AXISITEM_H_ */ |
|
143 | #endif /* AXISITEM_H_ */ |
@@ -1,119 +1,119 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef BARSERIES_H |
|
21 | #ifndef BARSERIES_H | |
22 | #define BARSERIES_H |
|
22 | #define BARSERIES_H | |
23 |
|
23 | |||
24 | #include <qseries.h> |
|
24 | #include <qseries.h> | |
25 | #include <QStringList> |
|
25 | #include <QStringList> | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | typedef QStringList QBarCategories; |
|
29 | typedef QStringList QBarCategories; | |
30 |
|
30 | |||
31 | class QBarSet; |
|
31 | class QBarSet; | |
32 | class BarChartModel; |
|
32 | class BarChartModel; | |
33 | class BarCategory; |
|
33 | class BarCategory; | |
34 |
|
34 | |||
35 | // Container for series |
|
35 | // Container for series | |
36 | class QTCOMMERCIALCHART_EXPORT QBarSeries : public QSeries |
|
36 | class QTCOMMERCIALCHART_EXPORT QBarSeries : public QSeries | |
37 | { |
|
37 | { | |
38 | Q_OBJECT |
|
38 | Q_OBJECT | |
39 | public: |
|
39 | public: | |
40 | QBarSeries(QStringList categories, QObject *parent = 0); |
|
40 | QBarSeries(QStringList categories, QObject *parent = 0); | |
41 |
|
41 | |||
42 | virtual QSeriesType type() const { return QSeries::SeriesTypeBar; } |
|
42 | virtual QSeriesType type() const { return QSeries::SeriesTypeBar; } | |
43 |
|
43 | |||
44 | void appendBarSet(QBarSet *set); // Takes ownership of set |
|
44 | void appendBarSet(QBarSet *set); // Takes ownership of set | |
45 | void removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set |
|
45 | void removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set | |
46 | void appendBarSets(QList<QBarSet* > sets); |
|
46 | void appendBarSets(QList<QBarSet* > sets); | |
47 | void removeBarSets(QList<QBarSet* > sets); |
|
47 | void removeBarSets(QList<QBarSet* > sets); | |
48 | void insertBarSet(int i, QBarSet *set); |
|
48 | void insertBarSet(int i, QBarSet *set); | |
49 | void insertCategory(int i, QString category); |
|
49 | void insertCategory(int i, QString category); | |
50 | void removeCategory(int i); |
|
50 | void removeCategory(int i); | |
51 | int barsetCount() const; |
|
51 | int barsetCount() const; | |
52 | int categoryCount() const; |
|
52 | int categoryCount() const; | |
53 | QList<QBarSet*> barSets() const; |
|
53 | QList<QBarSet*> barSets() const; | |
54 | QBarCategories categories() const; |
|
54 | QBarCategories categories() const; | |
55 |
|
55 | |||
56 | void setLabelsVisible(bool visible = true); |
|
56 | void setLabelsVisible(bool visible = true); | |
57 |
|
57 | |||
58 | bool setModel(QAbstractItemModel *model); |
|
58 | bool setModel(QAbstractItemModel *model); | |
59 | QAbstractItemModel *modelExt() { return m_model; } |
|
59 | QAbstractItemModel *modelExt() { return m_model; } | |
60 | void setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation = Qt::Vertical); |
|
60 | void setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation = Qt::Vertical); | |
61 | void setModelMappingShift(int first, int count); |
|
61 | void setModelMappingShift(int first, int count); | |
62 |
|
62 | |||
63 | public: |
|
63 | public: | |
64 | // TODO: Functions below this are not part of api and will be moved |
|
64 | // TODO: Functions below this are not part of api and will be moved | |
65 | // to private implementation, when we start using it |
|
65 | // to private implementation, when we start using it | |
66 | // TODO: TO PIMPL ---> |
|
66 | // TODO: TO PIMPL ---> | |
67 | QBarSet* barsetAt(int index); |
|
67 | QBarSet* barsetAt(int index); | |
68 | QString categoryName(int category); |
|
68 | QString categoryName(int category); | |
69 | qreal min(); |
|
69 | qreal min(); | |
70 | qreal max(); |
|
70 | qreal max(); | |
71 | qreal valueAt(int set, int category); |
|
71 | qreal valueAt(int set, int category); | |
72 | qreal percentageAt(int set, int category); |
|
72 | qreal percentageAt(int set, int category); | |
73 | qreal categorySum(int category); |
|
73 | qreal categorySum(int category); | |
74 | qreal absoluteCategorySum(int category); |
|
74 | qreal absoluteCategorySum(int category); | |
75 | qreal maxCategorySum(); |
|
75 | qreal maxCategorySum(); | |
76 | BarChartModel& model(); |
|
76 | BarChartModel& model(); | |
77 | // <--- TO PIMPL |
|
77 | // <--- TO PIMPL | |
78 |
|
78 | |||
79 | Q_SIGNALS: |
|
79 | Q_SIGNALS: | |
80 | void clicked(QBarSet *barset, QString category, Qt::MouseButtons button); // Up to user of api, what to do with these signals |
|
80 | void clicked(QBarSet *barset, QString category, Qt::MouseButtons button); // Up to user of api, what to do with these signals | |
81 |
|
81 | void selected(); | ||
82 | // |
|
82 | // | |
83 | void updatedBars(); |
|
83 | void updatedBars(); | |
84 | void restructuredBars(); |
|
84 | void restructuredBars(); | |
85 |
|
85 | |||
86 | // TODO: internal signals, these to private implementation. |
|
86 | // TODO: internal signals, these to private implementation. | |
87 | // TODO: TO PIMPL ---> |
|
87 | // TODO: TO PIMPL ---> | |
88 | void showToolTip(QPoint pos, QString tip); |
|
88 | void showToolTip(QPoint pos, QString tip); | |
89 | // <--- TO PIMPL |
|
89 | // <--- TO PIMPL | |
90 |
|
90 | |||
91 | public Q_SLOTS: |
|
91 | public Q_SLOTS: | |
92 | void setToolTipEnabled(bool enabled = true); // enables tooltips |
|
92 | void setToolTipEnabled(bool enabled = true); // enables tooltips | |
93 |
|
93 | |||
94 | // TODO: TO PIMPL ---> |
|
94 | // TODO: TO PIMPL ---> | |
95 | void barsetClicked(QString category, Qt::MouseButtons button); |
|
95 | void barsetClicked(QString category, Qt::MouseButtons button); | |
96 | // <--- TO PIMPL |
|
96 | // <--- TO PIMPL | |
97 |
|
97 | |||
98 | private Q_SLOTS: |
|
98 | private Q_SLOTS: | |
99 | // slots for updating bars when data in model changes |
|
99 | // slots for updating bars when data in model changes | |
100 | void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); |
|
100 | void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); | |
101 | void modelDataAdded(QModelIndex parent, int start, int end); |
|
101 | void modelDataAdded(QModelIndex parent, int start, int end); | |
102 | void modelDataRemoved(QModelIndex parent, int start, int end); |
|
102 | void modelDataRemoved(QModelIndex parent, int start, int end); | |
103 | void barsetChanged(); |
|
103 | void barsetChanged(); | |
104 |
|
104 | |||
105 | protected: |
|
105 | protected: | |
106 | BarChartModel *m_internalModel; // TODO: this may change... current "2 models" situation doesn't look good. |
|
106 | BarChartModel *m_internalModel; // TODO: this may change... current "2 models" situation doesn't look good. | |
107 |
|
107 | |||
108 | QAbstractItemModel* m_model; |
|
108 | QAbstractItemModel* m_model; | |
109 | int m_mapCategories; |
|
109 | int m_mapCategories; | |
110 | int m_mapBarBottom; |
|
110 | int m_mapBarBottom; | |
111 | int m_mapBarTop; |
|
111 | int m_mapBarTop; | |
112 | int m_mapFirst; |
|
112 | int m_mapFirst; | |
113 | int m_mapCount; |
|
113 | int m_mapCount; | |
114 | Qt::Orientation m_mapOrientation; |
|
114 | Qt::Orientation m_mapOrientation; | |
115 | }; |
|
115 | }; | |
116 |
|
116 | |||
117 | QTCOMMERCIALCHART_END_NAMESPACE |
|
117 | QTCOMMERCIALCHART_END_NAMESPACE | |
118 |
|
118 | |||
119 | #endif // BARSERIES_H |
|
119 | #endif // BARSERIES_H |
@@ -1,401 +1,533 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qchart.h" |
|
21 | #include "qchart.h" | |
|
22 | #include "qchart_p.h" | |||
22 | #include "qchartaxis.h" |
|
23 | #include "qchartaxis.h" | |
23 | #include "chartpresenter_p.h" |
|
24 | #include "chartpresenter_p.h" | |
24 | #include "chartdataset_p.h" |
|
25 | #include "chartdataset_p.h" | |
25 | #include "charttheme_p.h" |
|
26 | #include "charttheme_p.h" | |
26 | #include "chartanimator_p.h" |
|
27 | #include "chartanimator_p.h" | |
27 | //series |
|
28 | //series | |
28 | #include "qbarseries.h" |
|
29 | #include "qbarseries.h" | |
29 | #include "qstackedbarseries.h" |
|
30 | #include "qstackedbarseries.h" | |
30 | #include "qpercentbarseries.h" |
|
31 | #include "qpercentbarseries.h" | |
31 | #include "qlineseries.h" |
|
32 | #include "qlineseries.h" | |
32 | #include "qareaseries.h" |
|
33 | #include "qareaseries.h" | |
33 | #include "qpieseries.h" |
|
34 | #include "qpieseries.h" | |
34 | #include "qscatterseries.h" |
|
35 | #include "qscatterseries.h" | |
35 | #include "qsplineseries.h" |
|
36 | #include "qsplineseries.h" | |
36 | //items |
|
37 | //items | |
37 | #include "axisitem_p.h" |
|
38 | #include "axisitem_p.h" | |
38 | #include "areachartitem_p.h" |
|
39 | #include "areachartitem_p.h" | |
39 | #include "barchartitem_p.h" |
|
40 | #include "barchartitem_p.h" | |
40 | #include "stackedbarchartitem_p.h" |
|
41 | #include "stackedbarchartitem_p.h" | |
41 | #include "percentbarchartitem_p.h" |
|
42 | #include "percentbarchartitem_p.h" | |
42 | #include "linechartitem_p.h" |
|
43 | #include "linechartitem_p.h" | |
43 | #include "piechartitem_p.h" |
|
44 | #include "piechartitem_p.h" | |
44 | #include "scatterchartitem_p.h" |
|
45 | #include "scatterchartitem_p.h" | |
45 | #include "splinechartitem_p.h" |
|
46 | #include "splinechartitem_p.h" | |
46 |
|
47 | |||
47 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
48 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
48 |
|
49 | |||
49 | ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart), |
|
50 | ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart), | |
50 | m_chart(chart), |
|
51 | m_chart(chart), | |
51 | m_animator(0), |
|
52 | m_animator(0), | |
52 | m_dataset(dataset), |
|
53 | m_dataset(dataset), | |
53 | m_chartTheme(0), |
|
54 | m_chartTheme(0), | |
54 | m_rect(QRectF(QPoint(0,0),m_chart->size())), |
|
55 | m_chartRect(QRectF(QPoint(0,0),m_chart->size())), | |
55 | m_options(QChart::NoAnimation), |
|
56 | m_options(QChart::NoAnimation), | |
56 | m_themeForce(false), |
|
57 | m_themeForce(false), | |
57 | m_backgroundPadding(10) |
|
58 | m_minLeftMargin(0), | |
|
59 | m_minBottomMargin(0), | |||
|
60 | m_backgroundItem(0), | |||
|
61 | m_titleItem(0), | |||
|
62 | m_marginBig(60), | |||
|
63 | m_marginSmall(20), | |||
|
64 | m_marginTiny(10), | |||
|
65 | m_chartMargins(QRect(m_marginBig,m_marginBig,0,0)) | |||
58 | { |
|
66 | { | |
59 | createConnections(); |
|
67 | createConnections(); | |
60 | setTheme(QChart::ChartThemeLight, false); |
|
68 | setTheme(QChart::ChartThemeLight, false); | |
61 | } |
|
69 | } | |
62 |
|
70 | |||
63 | ChartPresenter::~ChartPresenter() |
|
71 | ChartPresenter::~ChartPresenter() | |
64 | { |
|
72 | { | |
65 | delete m_chartTheme; |
|
73 | delete m_chartTheme; | |
66 | } |
|
74 | } | |
67 |
|
75 | |||
68 | void ChartPresenter::createConnections() |
|
76 | void ChartPresenter::createConnections() | |
69 | { |
|
77 | { | |
70 | QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged())); |
|
|||
71 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),this,SLOT(handleSeriesAdded(QSeries*,Domain*))); |
|
78 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),this,SLOT(handleSeriesAdded(QSeries*,Domain*))); | |
72 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),this,SLOT(handleSeriesRemoved(QSeries*))); |
|
79 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),this,SLOT(handleSeriesRemoved(QSeries*))); | |
73 | QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*,Domain*)),this,SLOT(handleAxisAdded(QChartAxis*,Domain*))); |
|
80 | QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*,Domain*)),this,SLOT(handleAxisAdded(QChartAxis*,Domain*))); | |
74 | QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),this,SLOT(handleAxisRemoved(QChartAxis*))); |
|
81 | QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),this,SLOT(handleAxisRemoved(QChartAxis*))); | |
75 | } |
|
82 | } | |
76 |
|
83 | |||
77 |
void ChartPresenter:: |
|
84 | void ChartPresenter::setGeometry(const QRectF& rect) | |
78 | { |
|
85 | { | |
79 | QRectF rect(QPoint(0,0),m_chart->size()); |
|
|||
80 | QRectF padding = m_chart->padding(); |
|
|||
81 | rect.adjust(padding.left(), padding.top(), -padding.right(), -padding.bottom()); |
|
|||
82 |
|
||||
83 | //rewrite zoom stack |
|
|||
84 | /* |
|
|||
85 | for(int i=0;i<m_zoomStack.count();i++){ |
|
|||
86 | QRectF r = m_zoomStack[i]; |
|
|||
87 | qreal w = rect.width()/m_rect.width(); |
|
|||
88 | qreal h = rect.height()/m_rect.height(); |
|
|||
89 | QPointF tl = r.topLeft(); |
|
|||
90 | tl.setX(tl.x()*w); |
|
|||
91 | tl.setY(tl.y()*h); |
|
|||
92 | QPointF br = r.bottomRight(); |
|
|||
93 | br.setX(br.x()*w); |
|
|||
94 | br.setY(br.y()*h); |
|
|||
95 | r.setTopLeft(tl); |
|
|||
96 | r.setBottomRight(br); |
|
|||
97 | m_zoomStack[i]=r; |
|
|||
98 | } |
|
|||
99 | */ |
|
|||
100 | m_rect = rect; |
|
86 | m_rect = rect; | |
101 | Q_ASSERT(m_rect.isValid()); |
|
87 | Q_ASSERT(m_rect.isValid()); | |
102 | emit geometryChanged(m_rect); |
|
88 | updateLayout(); | |
|
89 | } | |||
|
90 | ||||
|
91 | void ChartPresenter::setMinimumMarginWidth(Axis* axis, qreal width) | |||
|
92 | { | |||
|
93 | switch(axis->axisType()){ | |||
|
94 | case Axis::X_AXIS: | |||
|
95 | { | |||
|
96 | if(width>m_chartRect.width()+ m_chartMargins.left()) { | |||
|
97 | m_minLeftMargin= width - m_chartRect.width(); | |||
|
98 | updateLayout(); | |||
|
99 | } | |||
|
100 | break; | |||
|
101 | } | |||
|
102 | case Axis::Y_AXIS: | |||
|
103 | { | |||
|
104 | ||||
|
105 | if(m_minLeftMargin!=width){ | |||
|
106 | m_minLeftMargin= width; | |||
|
107 | updateLayout(); | |||
|
108 | } | |||
|
109 | break; | |||
|
110 | } | |||
|
111 | ||||
|
112 | } | |||
|
113 | } | |||
|
114 | ||||
|
115 | void ChartPresenter::setMinimumMarginHeight(Axis* axis, qreal height) | |||
|
116 | { | |||
|
117 | switch(axis->axisType()){ | |||
|
118 | case Axis::X_AXIS: | |||
|
119 | { | |||
|
120 | if(m_minBottomMargin!=height) { | |||
|
121 | m_minBottomMargin= height; | |||
|
122 | updateLayout(); | |||
|
123 | } | |||
|
124 | break; | |||
|
125 | } | |||
|
126 | case Axis::Y_AXIS: | |||
|
127 | { | |||
|
128 | ||||
|
129 | if(height>m_chartMargins.bottom()+m_chartRect.height()){ | |||
|
130 | m_minBottomMargin= height - m_chartRect.height(); | |||
|
131 | updateLayout(); | |||
|
132 | } | |||
|
133 | break; | |||
|
134 | } | |||
|
135 | ||||
|
136 | } | |||
103 | } |
|
137 | } | |
104 |
|
138 | |||
105 | void ChartPresenter::handleAxisAdded(QChartAxis* axis,Domain* domain) |
|
139 | void ChartPresenter::handleAxisAdded(QChartAxis* axis,Domain* domain) | |
106 | { |
|
140 | { | |
107 | Axis* item = new Axis(axis,this,axis==m_dataset->axisX()?Axis::X_AXIS : Axis::Y_AXIS); |
|
141 | Axis* item = new Axis(axis,this,axis==m_dataset->axisX()?Axis::X_AXIS : Axis::Y_AXIS); | |
108 |
|
142 | |||
109 | if(m_options.testFlag(QChart::GridAxisAnimations)){ |
|
143 | if(m_options.testFlag(QChart::GridAxisAnimations)){ | |
110 | m_animator->addAnimation(item); |
|
144 | m_animator->addAnimation(item); | |
111 | } |
|
145 | } | |
112 |
|
146 | |||
113 | if(axis==m_dataset->axisX()){ |
|
147 | if(axis==m_dataset->axisX()){ | |
114 | m_chartTheme->decorate(axis,true,m_themeForce); |
|
148 | m_chartTheme->decorate(axis,true,m_themeForce); | |
115 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int))); |
|
149 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int))); | |
116 | //initialize |
|
150 | //initialize | |
117 | item->handleRangeChanged(domain->minX(),domain->maxX(),domain->tickXCount()); |
|
151 | item->handleRangeChanged(domain->minX(),domain->maxX(),domain->tickXCount()); | |
118 |
|
152 | |||
119 | } |
|
153 | } | |
120 | else{ |
|
154 | else{ | |
121 | m_chartTheme->decorate(axis,false,m_themeForce); |
|
155 | m_chartTheme->decorate(axis,false,m_themeForce); | |
122 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int))); |
|
156 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int))); | |
123 | //initialize |
|
157 | //initialize | |
124 | item->handleRangeChanged(domain->minY(),domain->maxY(),domain->tickYCount()); |
|
158 | item->handleRangeChanged(domain->minY(),domain->maxY(),domain->tickYCount()); | |
125 | } |
|
159 | } | |
126 |
|
160 | |||
127 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
161 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
128 | //initialize |
|
162 | //initialize | |
129 | item->handleGeometryChanged(m_rect); |
|
163 | item->handleGeometryChanged(m_chartRect); | |
130 | m_axisItems.insert(axis, item); |
|
164 | m_axisItems.insert(axis, item); | |
131 | } |
|
165 | } | |
132 |
|
166 | |||
133 | void ChartPresenter::handleAxisRemoved(QChartAxis* axis) |
|
167 | void ChartPresenter::handleAxisRemoved(QChartAxis* axis) | |
134 | { |
|
168 | { | |
135 | Axis* item = m_axisItems.take(axis); |
|
169 | Axis* item = m_axisItems.take(axis); | |
136 | Q_ASSERT(item); |
|
170 | Q_ASSERT(item); | |
137 | if(m_animator) m_animator->removeAnimation(item); |
|
171 | if(m_animator) m_animator->removeAnimation(item); | |
138 | delete item; |
|
172 | delete item; | |
139 | } |
|
173 | } | |
140 |
|
174 | |||
141 |
|
175 | |||
142 | void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain) |
|
176 | void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain) | |
143 | { |
|
177 | { | |
144 | Chart *item = 0 ; |
|
178 | Chart *item = 0 ; | |
145 |
|
179 | |||
146 | switch(series->type()) |
|
180 | switch(series->type()) | |
147 | { |
|
181 | { | |
148 | case QSeries::SeriesTypeLine: { |
|
182 | case QSeries::SeriesTypeLine: { | |
149 |
|
183 | |||
150 | QLineSeries* lineSeries = static_cast<QLineSeries*>(series); |
|
184 | QLineSeries* lineSeries = static_cast<QLineSeries*>(series); | |
151 | LineChartItem* line = new LineChartItem(lineSeries,this); |
|
185 | LineChartItem* line = new LineChartItem(lineSeries,this); | |
152 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
186 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
153 | m_animator->addAnimation(line); |
|
187 | m_animator->addAnimation(line); | |
154 | } |
|
188 | } | |
155 | m_chartTheme->decorate(lineSeries, m_dataset->seriesIndex(series),m_themeForce); |
|
189 | m_chartTheme->decorate(lineSeries, m_dataset->seriesIndex(series),m_themeForce); | |
156 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),line,SLOT(handleGeometryChanged(const QRectF&))); |
|
190 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),line,SLOT(handleGeometryChanged(const QRectF&))); | |
157 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),line,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
191 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),line,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
158 | item = line; |
|
192 | item = line; | |
159 | break; |
|
193 | break; | |
160 | } |
|
194 | } | |
161 |
|
195 | |||
162 | case QSeries::SeriesTypeArea: { |
|
196 | case QSeries::SeriesTypeArea: { | |
163 |
|
197 | |||
164 | QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series); |
|
198 | QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series); | |
165 | AreaChartItem* area = new AreaChartItem(areaSeries,this); |
|
199 | AreaChartItem* area = new AreaChartItem(areaSeries,this); | |
166 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
200 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
167 | m_animator->addAnimation(area->upperLineItem()); |
|
201 | m_animator->addAnimation(area->upperLineItem()); | |
168 | if(areaSeries->lowerSeries()) m_animator->addAnimation(area->lowerLineItem()); |
|
202 | if(areaSeries->lowerSeries()) m_animator->addAnimation(area->lowerLineItem()); | |
169 | } |
|
203 | } | |
170 | m_chartTheme->decorate(areaSeries, m_dataset->seriesIndex(series),m_themeForce); |
|
204 | m_chartTheme->decorate(areaSeries, m_dataset->seriesIndex(series),m_themeForce); | |
171 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),area,SLOT(handleGeometryChanged(const QRectF&))); |
|
205 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),area,SLOT(handleGeometryChanged(const QRectF&))); | |
172 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),area,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
206 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),area,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
173 | item=area; |
|
207 | item=area; | |
174 | break; |
|
208 | break; | |
175 | } |
|
209 | } | |
176 |
|
210 | |||
177 | case QSeries::SeriesTypeBar: { |
|
211 | case QSeries::SeriesTypeBar: { | |
178 | QBarSeries* barSeries = static_cast<QBarSeries*>(series); |
|
212 | QBarSeries* barSeries = static_cast<QBarSeries*>(series); | |
179 | BarChartItem* bar = new BarChartItem(barSeries,this); |
|
213 | BarChartItem* bar = new BarChartItem(barSeries,this); | |
180 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
214 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
181 | m_animator->addAnimation(bar); |
|
215 | m_animator->addAnimation(bar); | |
182 | } |
|
216 | } | |
183 | m_chartTheme->decorate(barSeries, m_dataset->seriesIndex(barSeries),m_themeForce); |
|
217 | m_chartTheme->decorate(barSeries, m_dataset->seriesIndex(barSeries),m_themeForce); | |
184 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&))); |
|
218 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&))); | |
185 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
219 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
186 | item=bar; |
|
220 | item=bar; | |
187 | break; |
|
221 | break; | |
188 | } |
|
222 | } | |
189 |
|
223 | |||
190 | case QSeries::SeriesTypeStackedBar: { |
|
224 | case QSeries::SeriesTypeStackedBar: { | |
191 | QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series); |
|
225 | QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series); | |
192 | StackedBarChartItem* bar = new StackedBarChartItem(stackedBarSeries,this); |
|
226 | StackedBarChartItem* bar = new StackedBarChartItem(stackedBarSeries,this); | |
193 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
227 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
194 | m_animator->addAnimation(bar); |
|
228 | m_animator->addAnimation(bar); | |
195 | } |
|
229 | } | |
196 | m_chartTheme->decorate(stackedBarSeries, m_dataset->seriesIndex(stackedBarSeries),m_themeForce); |
|
230 | m_chartTheme->decorate(stackedBarSeries, m_dataset->seriesIndex(stackedBarSeries),m_themeForce); | |
197 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&))); |
|
231 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&))); | |
198 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
232 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
199 | item=bar; |
|
233 | item=bar; | |
200 | break; |
|
234 | break; | |
201 | } |
|
235 | } | |
202 |
|
236 | |||
203 | case QSeries::SeriesTypePercentBar: { |
|
237 | case QSeries::SeriesTypePercentBar: { | |
204 | QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series); |
|
238 | QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series); | |
205 | PercentBarChartItem* bar = new PercentBarChartItem(percentBarSeries,this); |
|
239 | PercentBarChartItem* bar = new PercentBarChartItem(percentBarSeries,this); | |
206 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
240 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
207 | m_animator->addAnimation(bar); |
|
241 | m_animator->addAnimation(bar); | |
208 | } |
|
242 | } | |
209 | m_chartTheme->decorate(percentBarSeries, m_dataset->seriesIndex(percentBarSeries),m_themeForce); |
|
243 | m_chartTheme->decorate(percentBarSeries, m_dataset->seriesIndex(percentBarSeries),m_themeForce); | |
210 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&))); |
|
244 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&))); | |
211 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
245 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
212 | item=bar; |
|
246 | item=bar; | |
213 | break; |
|
247 | break; | |
214 | } |
|
248 | } | |
215 |
|
249 | |||
216 | case QSeries::SeriesTypeScatter: { |
|
250 | case QSeries::SeriesTypeScatter: { | |
217 | QScatterSeries *scatterSeries = static_cast<QScatterSeries *>(series); |
|
251 | QScatterSeries *scatterSeries = static_cast<QScatterSeries *>(series); | |
218 | ScatterChartItem *scatter = new ScatterChartItem(scatterSeries,this); |
|
252 | ScatterChartItem *scatter = new ScatterChartItem(scatterSeries,this); | |
219 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
253 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
220 | m_animator->addAnimation(scatter); |
|
254 | m_animator->addAnimation(scatter); | |
221 | } |
|
255 | } | |
222 | m_chartTheme->decorate(scatterSeries, m_dataset->seriesIndex(series),m_themeForce); |
|
256 | m_chartTheme->decorate(scatterSeries, m_dataset->seriesIndex(series),m_themeForce); | |
223 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),scatter,SLOT(handleGeometryChanged(const QRectF&))); |
|
257 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),scatter,SLOT(handleGeometryChanged(const QRectF&))); | |
224 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),scatter,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
258 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),scatter,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
225 | item = scatter; |
|
259 | item = scatter; | |
226 | break; |
|
260 | break; | |
227 | } |
|
261 | } | |
228 |
|
262 | |||
229 | case QSeries::SeriesTypePie: { |
|
263 | case QSeries::SeriesTypePie: { | |
230 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); |
|
264 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); | |
231 | PieChartItem* pie = new PieChartItem(pieSeries, this); |
|
265 | PieChartItem* pie = new PieChartItem(pieSeries, this); | |
232 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
266 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
233 | m_animator->addAnimation(pie); |
|
267 | m_animator->addAnimation(pie); | |
234 | } |
|
268 | } | |
235 | m_chartTheme->decorate(pieSeries, m_dataset->seriesIndex(series),m_themeForce); |
|
269 | m_chartTheme->decorate(pieSeries, m_dataset->seriesIndex(series),m_themeForce); | |
236 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),pie,SLOT(handleGeometryChanged(const QRectF&))); |
|
270 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),pie,SLOT(handleGeometryChanged(const QRectF&))); | |
237 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),pie,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
271 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),pie,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
238 | // Hide all from background when there is only piechart |
|
272 | // Hide all from background when there is only piechart | |
239 | // TODO: refactor this ugly code... should be one setting for this |
|
273 | // TODO: refactor this ugly code... should be one setting for this | |
240 | if (m_chartItems.count() == 0) { |
|
274 | if (m_chartItems.count() == 0) { | |
241 | m_chart->axisX()->hide(); |
|
275 | m_chart->axisX()->hide(); | |
242 | m_chart->axisY()->hide(); |
|
276 | m_chart->axisY()->hide(); | |
243 | } |
|
277 | } | |
244 | item=pie; |
|
278 | item=pie; | |
245 | break; |
|
279 | break; | |
246 | } |
|
280 | } | |
247 |
|
281 | |||
248 | case QSeries::SeriesTypeSpline: { |
|
282 | case QSeries::SeriesTypeSpline: { | |
249 | QSplineSeries* splineSeries = static_cast<QSplineSeries*>(series); |
|
283 | QSplineSeries* splineSeries = static_cast<QSplineSeries*>(series); | |
250 | SplineChartItem* spline = new SplineChartItem(splineSeries, this); |
|
284 | SplineChartItem* spline = new SplineChartItem(splineSeries, this); | |
251 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
285 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
252 | m_animator->addAnimation(spline); |
|
286 | m_animator->addAnimation(spline); | |
253 | } |
|
287 | } | |
254 | m_chartTheme->decorate(splineSeries, m_dataset->seriesIndex(series),m_themeForce); |
|
288 | m_chartTheme->decorate(splineSeries, m_dataset->seriesIndex(series),m_themeForce); | |
255 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),spline,SLOT(handleGeometryChanged(const QRectF&))); |
|
289 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),spline,SLOT(handleGeometryChanged(const QRectF&))); | |
256 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),spline,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); |
|
290 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),spline,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |
257 | item=spline; |
|
291 | item=spline; | |
258 | break; |
|
292 | break; | |
259 | } |
|
293 | } | |
260 | default: { |
|
294 | default: { | |
261 | qDebug()<< "Series type" << series->type() << "not implemented."; |
|
295 | qDebug()<< "Series type" << series->type() << "not implemented."; | |
262 | break; |
|
296 | break; | |
263 | } |
|
297 | } | |
264 | } |
|
298 | } | |
265 |
|
299 | |||
266 | //initialize |
|
300 | //initialize | |
267 | item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY()); |
|
301 | item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY()); | |
268 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); |
|
302 | if(m_chartRect.isValid()) item->handleGeometryChanged(m_chartRect); | |
269 | m_chartItems.insert(series,item); |
|
303 | m_chartItems.insert(series,item); | |
270 | } |
|
304 | } | |
271 |
|
305 | |||
272 | void ChartPresenter::handleSeriesRemoved(QSeries* series) |
|
306 | void ChartPresenter::handleSeriesRemoved(QSeries* series) | |
273 | { |
|
307 | { | |
274 | Chart* item = m_chartItems.take(series); |
|
308 | Chart* item = m_chartItems.take(series); | |
275 | Q_ASSERT(item); |
|
309 | Q_ASSERT(item); | |
276 | if(m_animator) { |
|
310 | if(m_animator) { | |
277 | //small hack to handle area animations |
|
311 | //small hack to handle area animations | |
278 | if(series->type()==QSeries::SeriesTypeArea){ |
|
312 | if(series->type()==QSeries::SeriesTypeArea){ | |
279 | QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series); |
|
313 | QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series); | |
280 | AreaChartItem* area = static_cast<AreaChartItem*>(item); |
|
314 | AreaChartItem* area = static_cast<AreaChartItem*>(item); | |
281 | m_animator->removeAnimation(area->upperLineItem()); |
|
315 | m_animator->removeAnimation(area->upperLineItem()); | |
282 | if(areaSeries->lowerSeries()) m_animator->removeAnimation(area->lowerLineItem()); |
|
316 | if(areaSeries->lowerSeries()) m_animator->removeAnimation(area->lowerLineItem()); | |
283 | }else |
|
317 | }else | |
284 | m_animator->removeAnimation(item); |
|
318 | m_animator->removeAnimation(item); | |
285 | } |
|
319 | } | |
286 | delete item; |
|
320 | delete item; | |
287 | } |
|
321 | } | |
288 |
|
322 | |||
289 | void ChartPresenter::setTheme(QChart::ChartTheme theme,bool force) |
|
323 | void ChartPresenter::setTheme(QChart::ChartTheme theme,bool force) | |
290 | { |
|
324 | { | |
291 | if(m_chartTheme && m_chartTheme->id() == theme) return; |
|
325 | if(m_chartTheme && m_chartTheme->id() == theme) return; | |
292 | delete m_chartTheme; |
|
326 | delete m_chartTheme; | |
293 | m_themeForce = force; |
|
327 | m_themeForce = force; | |
294 | m_chartTheme = ChartTheme::createTheme(theme); |
|
328 | m_chartTheme = ChartTheme::createTheme(theme); | |
295 | m_chartTheme->decorate(m_chart,m_themeForce); |
|
329 | m_chartTheme->decorate(m_chart,m_themeForce); | |
296 | m_chartTheme->decorate(m_chart->legend(),m_themeForce); |
|
330 | m_chartTheme->decorate(m_chart->legend(),m_themeForce); | |
297 | resetAllElements(); |
|
331 | resetAllElements(); | |
298 | } |
|
332 | } | |
299 |
|
333 | |||
300 | QChart::ChartTheme ChartPresenter::theme() |
|
334 | QChart::ChartTheme ChartPresenter::theme() | |
301 | { |
|
335 | { | |
302 | return m_chartTheme->id(); |
|
336 | return m_chartTheme->id(); | |
303 | } |
|
337 | } | |
304 |
|
338 | |||
305 | void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) |
|
339 | void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) | |
306 | { |
|
340 | { | |
307 | if(m_options!=options) { |
|
341 | if(m_options!=options) { | |
308 |
|
342 | |||
309 | m_options=options; |
|
343 | m_options=options; | |
310 |
|
344 | |||
311 | if(m_options!=QChart::NoAnimation && !m_animator) { |
|
345 | if(m_options!=QChart::NoAnimation && !m_animator) { | |
312 | m_animator= new ChartAnimator(this); |
|
346 | m_animator= new ChartAnimator(this); | |
313 |
|
347 | |||
314 | } |
|
348 | } | |
315 | resetAllElements(); |
|
349 | resetAllElements(); | |
316 | } |
|
350 | } | |
317 |
|
351 | |||
318 | } |
|
352 | } | |
319 |
|
353 | |||
320 | void ChartPresenter::resetAllElements() |
|
354 | void ChartPresenter::resetAllElements() | |
321 | { |
|
355 | { | |
322 | QList<QChartAxis*> axisList = m_axisItems.uniqueKeys(); |
|
356 | QList<QChartAxis*> axisList = m_axisItems.uniqueKeys(); | |
323 | QList<QSeries*> seriesList = m_chartItems.uniqueKeys(); |
|
357 | QList<QSeries*> seriesList = m_chartItems.uniqueKeys(); | |
324 |
|
358 | |||
325 | foreach(QChartAxis* axis, axisList) { |
|
359 | foreach(QChartAxis* axis, axisList) { | |
326 | handleAxisRemoved(axis); |
|
360 | handleAxisRemoved(axis); | |
327 | handleAxisAdded(axis,m_dataset->domain(axis)); |
|
361 | handleAxisAdded(axis,m_dataset->domain(axis)); | |
328 | } |
|
362 | } | |
329 | foreach(QSeries* series, seriesList) { |
|
363 | foreach(QSeries* series, seriesList) { | |
330 | handleSeriesRemoved(series); |
|
364 | handleSeriesRemoved(series); | |
331 | handleSeriesAdded(series,m_dataset->domain(series)); |
|
365 | handleSeriesAdded(series,m_dataset->domain(series)); | |
332 | } |
|
366 | } | |
333 | } |
|
367 | } | |
334 |
|
368 | |||
335 | void ChartPresenter::zoomIn() |
|
369 | void ChartPresenter::zoomIn() | |
336 | { |
|
370 | { | |
337 |
QRectF rect = |
|
371 | QRectF rect = chartGeometry(); | |
338 | rect.setWidth(rect.width()/2); |
|
372 | rect.setWidth(rect.width()/2); | |
339 | rect.setHeight(rect.height()/2); |
|
373 | rect.setHeight(rect.height()/2); | |
340 |
rect.moveCenter( |
|
374 | rect.moveCenter(chartGeometry().center()); | |
341 | zoomIn(rect); |
|
375 | zoomIn(rect); | |
342 | } |
|
376 | } | |
343 |
|
377 | |||
344 | void ChartPresenter::zoomIn(const QRectF& rect) |
|
378 | void ChartPresenter::zoomIn(const QRectF& rect) | |
345 | { |
|
379 | { | |
346 | QRectF r = rect.normalized(); |
|
380 | QRectF r = rect.normalized(); | |
347 |
r.translate(-m_chart |
|
381 | r.translate(-m_chartMargins.topLeft()); | |
348 | if(m_animator) { |
|
382 | if(m_animator) { | |
349 |
|
383 | |||
350 |
QPointF point(r.center().x()/ |
|
384 | QPointF point(r.center().x()/chartGeometry().width(),r.center().y()/chartGeometry().height()); | |
351 | m_animator->setState(ChartAnimator::ZoomInState,point); |
|
385 | m_animator->setState(ChartAnimator::ZoomInState,point); | |
352 | } |
|
386 | } | |
353 |
m_dataset->zoomInDomain(r, |
|
387 | m_dataset->zoomInDomain(r,chartGeometry().size()); | |
354 | if(m_animator) { |
|
388 | if(m_animator) { | |
355 | m_animator->setState(ChartAnimator::ShowState); |
|
389 | m_animator->setState(ChartAnimator::ShowState); | |
356 | } |
|
390 | } | |
357 | } |
|
391 | } | |
358 |
|
392 | |||
359 | void ChartPresenter::zoomOut() |
|
393 | void ChartPresenter::zoomOut() | |
360 | { |
|
394 | { | |
361 | if(m_animator) |
|
395 | if(m_animator) | |
362 | { |
|
396 | { | |
363 | m_animator->setState(ChartAnimator::ZoomOutState); |
|
397 | m_animator->setState(ChartAnimator::ZoomOutState); | |
364 | } |
|
398 | } | |
365 |
|
399 | |||
366 |
QSizeF size = |
|
400 | QSizeF size = chartGeometry().size(); | |
367 |
QRectF rect = |
|
401 | QRectF rect = chartGeometry(); | |
368 |
rect.translate(-m_chart |
|
402 | rect.translate(-m_chartMargins.topLeft()); | |
369 | m_dataset->zoomOutDomain(rect.adjusted(size.width()/4,size.height()/4,-size.width()/4,-size.height()/4),size); |
|
403 | m_dataset->zoomOutDomain(rect.adjusted(size.width()/4,size.height()/4,-size.width()/4,-size.height()/4),size); | |
370 | //m_dataset->zoomOutDomain(m_zoomStack[m_zoomIndex-1],geometry().size()); |
|
404 | //m_dataset->zoomOutDomain(m_zoomStack[m_zoomIndex-1],geometry().size()); | |
371 |
|
405 | |||
372 | if(m_animator){ |
|
406 | if(m_animator){ | |
373 | m_animator->setState(ChartAnimator::ShowState); |
|
407 | m_animator->setState(ChartAnimator::ShowState); | |
374 | } |
|
408 | } | |
375 | } |
|
409 | } | |
376 |
|
410 | |||
377 | void ChartPresenter::scroll(int dx,int dy) |
|
411 | void ChartPresenter::scroll(int dx,int dy) | |
378 | { |
|
412 | { | |
379 | if(m_animator){ |
|
413 | if(m_animator){ | |
380 | if(dx<0) m_animator->setState(ChartAnimator::ScrollLeftState,QPointF()); |
|
414 | if(dx<0) m_animator->setState(ChartAnimator::ScrollLeftState,QPointF()); | |
381 | if(dx>0) m_animator->setState(ChartAnimator::ScrollRightState,QPointF()); |
|
415 | if(dx>0) m_animator->setState(ChartAnimator::ScrollRightState,QPointF()); | |
382 | if(dy<0) m_animator->setState(ChartAnimator::ScrollUpState,QPointF()); |
|
416 | if(dy<0) m_animator->setState(ChartAnimator::ScrollUpState,QPointF()); | |
383 | if(dy>0) m_animator->setState(ChartAnimator::ScrollDownState,QPointF()); |
|
417 | if(dy>0) m_animator->setState(ChartAnimator::ScrollDownState,QPointF()); | |
384 | } |
|
418 | } | |
385 |
|
419 | |||
386 |
m_dataset->scrollDomain(dx,dy, |
|
420 | m_dataset->scrollDomain(dx,dy,chartGeometry().size()); | |
387 |
|
421 | |||
388 | if(m_animator){ |
|
422 | if(m_animator){ | |
389 | m_animator->setState(ChartAnimator::ShowState); |
|
423 | m_animator->setState(ChartAnimator::ShowState); | |
390 | } |
|
424 | } | |
391 | } |
|
425 | } | |
392 |
|
426 | |||
393 | QChart::AnimationOptions ChartPresenter::animationOptions() const |
|
427 | QChart::AnimationOptions ChartPresenter::animationOptions() const | |
394 | { |
|
428 | { | |
395 | return m_options; |
|
429 | return m_options; | |
396 | } |
|
430 | } | |
397 |
|
431 | |||
|
432 | void ChartPresenter::updateLayout() | |||
|
433 | { | |||
|
434 | if (!m_rect.isValid()) return; | |||
|
435 | ||||
|
436 | // recalculate title size | |||
|
437 | ||||
|
438 | QSize titleSize; | |||
|
439 | int titlePadding=0; | |||
|
440 | ||||
|
441 | if (m_titleItem) { | |||
|
442 | titleSize= m_titleItem->boundingRect().size().toSize(); | |||
|
443 | } | |||
|
444 | ||||
|
445 | //defaults | |||
|
446 | m_chartMargins = QRect(QPoint(m_minLeftMargin>m_marginBig?m_minLeftMargin:m_marginBig,m_marginBig),QPoint(m_marginBig,m_minBottomMargin>m_marginBig?m_minBottomMargin:m_marginBig)); | |||
|
447 | titlePadding = m_chartMargins.top()/2; | |||
|
448 | ||||
|
449 | QLegend* legend = m_chart->d_ptr->m_legend; | |||
|
450 | ||||
|
451 | // recalculate legend position | |||
|
452 | if (legend->isAttachedToChart() && legend->isEnabled()) { | |||
|
453 | ||||
|
454 | QRect legendRect; | |||
|
455 | ||||
|
456 | // Reserve some space for legend | |||
|
457 | switch (legend->alignment()) { | |||
|
458 | ||||
|
459 | case QLegend::AlignmentTop: { | |||
|
460 | int ledgendSize = legend->minHeight(); | |||
|
461 | int topPadding = 2*m_marginTiny + titleSize.height() + ledgendSize + m_marginTiny; | |||
|
462 | m_chartMargins = QRect(QPoint(m_chartMargins.left(),topPadding),QPoint(m_chartMargins.right(),m_chartMargins.bottom())); | |||
|
463 | m_legendMargins = QRect(QPoint(m_chartMargins.left(),topPadding - (ledgendSize + m_marginTiny)),QPoint(m_chartMargins.right(),m_rect.height()-topPadding + m_marginTiny)); | |||
|
464 | titlePadding = m_marginTiny + m_marginTiny; | |||
|
465 | break; | |||
|
466 | } | |||
|
467 | case QLegend::AlignmentBottom: { | |||
|
468 | int ledgendSize = legend->minHeight(); | |||
|
469 | int bottomPadding = m_marginTiny + m_marginSmall + ledgendSize + m_marginTiny + m_minBottomMargin; | |||
|
470 | m_chartMargins = QRect(QPoint(m_chartMargins.left(),m_chartMargins.top()),QPoint(m_chartMargins.right(),bottomPadding)); | |||
|
471 | m_legendMargins = QRect(QPoint(m_chartMargins.left(),m_rect.height()-bottomPadding + m_marginTiny + m_minBottomMargin),QPoint(m_chartMargins.right(),m_marginTiny + m_marginSmall)); | |||
|
472 | titlePadding = m_chartMargins.top()/2; | |||
|
473 | break; | |||
|
474 | } | |||
|
475 | case QLegend::AlignmentLeft: { | |||
|
476 | int ledgendSize = legend->minWidht(); | |||
|
477 | int leftPadding = m_marginTiny + m_marginSmall + ledgendSize + m_marginTiny + m_minLeftMargin; | |||
|
478 | m_chartMargins = QRect(QPoint(leftPadding,m_chartMargins.top()),QPoint(m_chartMargins.right(),m_chartMargins.bottom())); | |||
|
479 | m_legendMargins = QRect(QPoint(m_marginTiny + m_marginSmall,m_chartMargins.top()),QPoint(m_rect.width()-leftPadding + m_marginTiny + m_minLeftMargin,m_chartMargins.bottom())); | |||
|
480 | titlePadding = m_chartMargins.top()/2; | |||
|
481 | break; | |||
|
482 | } | |||
|
483 | case QLegend::AlignmentRight: { | |||
|
484 | int ledgendSize = legend->minWidht(); | |||
|
485 | int rightPadding = m_marginTiny + m_marginSmall + ledgendSize + m_marginTiny; | |||
|
486 | m_chartMargins = QRect(QPoint(m_chartMargins.left(),m_chartMargins.top()),QPoint(rightPadding,m_chartMargins.bottom())); | |||
|
487 | m_legendMargins = QRect(QPoint(m_rect.width()- rightPadding+ m_marginTiny ,m_chartMargins.top()),QPoint(m_marginTiny + m_marginSmall,m_chartMargins.bottom())); | |||
|
488 | titlePadding = m_chartMargins.top()/2; | |||
|
489 | break; | |||
|
490 | } | |||
|
491 | default: { | |||
|
492 | break; | |||
|
493 | } | |||
|
494 | } | |||
|
495 | } | |||
|
496 | ||||
|
497 | // recalculate title position | |||
|
498 | if (m_titleItem) { | |||
|
499 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); | |||
|
500 | m_titleItem->setPos(center.x(),titlePadding); | |||
|
501 | } | |||
|
502 | ||||
|
503 | //recalculate background gradient | |||
|
504 | if (m_backgroundItem) { | |||
|
505 | m_backgroundItem->setRect(m_rect.adjusted(m_marginTiny,m_marginTiny, -m_marginTiny, -m_marginTiny)); | |||
|
506 | } | |||
|
507 | ||||
|
508 | m_chartRect = m_rect.adjusted(m_chartMargins.left(),m_chartMargins.top(),-m_chartMargins.right(),-m_chartMargins.bottom()); | |||
|
509 | ||||
|
510 | emit geometryChanged(m_chartRect); | |||
|
511 | legend->setGeometry(m_rect.adjusted(m_legendMargins.left(),m_legendMargins.top(),-m_legendMargins.right(),-m_legendMargins.bottom())); | |||
|
512 | } | |||
|
513 | ||||
|
514 | void ChartPresenter::createChartBackgroundItem() | |||
|
515 | { | |||
|
516 | if (!m_backgroundItem) { | |||
|
517 | m_backgroundItem = new ChartBackground(rootItem()); | |||
|
518 | m_backgroundItem->setPen(Qt::NoPen); | |||
|
519 | m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue); | |||
|
520 | } | |||
|
521 | } | |||
|
522 | ||||
|
523 | void ChartPresenter::createChartTitleItem() | |||
|
524 | { | |||
|
525 | if (!m_titleItem) { | |||
|
526 | m_titleItem = new QGraphicsSimpleTextItem(rootItem()); | |||
|
527 | m_titleItem->setZValue(ChartPresenter::BackgroundZValue); | |||
|
528 | } | |||
|
529 | } | |||
398 |
|
530 | |||
399 | #include "moc_chartpresenter_p.cpp" |
|
531 | #include "moc_chartpresenter_p.cpp" | |
400 |
|
532 | |||
401 | QTCOMMERCIALCHART_END_NAMESPACE |
|
533 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,106 +1,127 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef CHARTPRESENTER_H_ |
|
21 | #ifndef CHARTPRESENTER_H_ | |
22 | #define CHARTPRESENTER_H_ |
|
22 | #define CHARTPRESENTER_H_ | |
23 |
|
23 | |||
24 | #include "qchartglobal.h" |
|
24 | #include "qchartglobal.h" | |
|
25 | #include "chartbackground_p.h" //TODO fix me | |||
25 | #include "qchart.h" //becouse of QChart::ChartThemeId //TODO |
|
26 | #include "qchart.h" //becouse of QChart::ChartThemeId //TODO | |
26 | #include "qchartaxis.h" |
|
27 | #include "qchartaxis.h" | |
27 | #include <QRectF> |
|
28 | #include <QRectF> | |
28 |
|
29 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
31 | |||
31 | class Chart; |
|
32 | class Chart; | |
32 | class QSeries; |
|
33 | class QSeries; | |
33 | class ChartDataSet; |
|
34 | class ChartDataSet; | |
34 | class Domain; |
|
35 | class Domain; | |
35 | class Axis; |
|
36 | class Axis; | |
36 | class ChartTheme; |
|
37 | class ChartTheme; | |
37 | class ChartAnimator; |
|
38 | class ChartAnimator; | |
38 |
|
39 | |||
39 | class ChartPresenter: public QObject |
|
40 | class ChartPresenter: public QObject | |
40 | { |
|
41 | { | |
41 | Q_OBJECT |
|
42 | Q_OBJECT | |
42 | public: |
|
43 | public: | |
43 | enum ZValues { |
|
44 | enum ZValues { | |
44 | BackgroundZValue = -1, |
|
45 | BackgroundZValue = -1, | |
45 | ShadesZValue, |
|
46 | ShadesZValue, | |
46 | GridZValue, |
|
47 | GridZValue, | |
47 | LineChartZValue, |
|
48 | LineChartZValue, | |
48 | BarSeriesZValue, |
|
49 | BarSeriesZValue, | |
49 | ScatterSeriesZValue, |
|
50 | ScatterSeriesZValue, | |
50 | PieSeriesZValue, |
|
51 | PieSeriesZValue, | |
51 | AxisZValue, |
|
52 | AxisZValue, | |
52 | LegendZValue |
|
53 | LegendZValue | |
53 | }; |
|
54 | }; | |
54 |
|
55 | |||
55 | ChartPresenter(QChart* chart,ChartDataSet *dataset); |
|
56 | ChartPresenter(QChart* chart,ChartDataSet *dataset); | |
56 | virtual ~ChartPresenter(); |
|
57 | virtual ~ChartPresenter(); | |
57 |
|
58 | |||
58 | int backgroundPadding() const { return m_backgroundPadding; } |
|
|||
59 | QRectF geometry() const { return m_rect; } |
|
|||
60 | ChartAnimator* animator() const { return m_animator; } |
|
59 | ChartAnimator* animator() const { return m_animator; } | |
61 | ChartTheme *chartTheme() const { return m_chartTheme; } |
|
60 | ChartTheme *chartTheme() const { return m_chartTheme; } | |
62 | ChartDataSet *dataSet() const { return m_dataset; } |
|
61 | ChartDataSet *dataSet() const { return m_dataset; } | |
63 | QGraphicsItem* rootItem() const { return m_chart; } |
|
62 | QGraphicsItem* rootItem() const { return m_chart; } | |
64 |
|
63 | |||
65 | void setTheme(QChart::ChartTheme theme,bool force = true); |
|
64 | void setTheme(QChart::ChartTheme theme,bool force = true); | |
66 | QChart::ChartTheme theme(); |
|
65 | QChart::ChartTheme theme(); | |
67 |
|
66 | |||
68 | void setAnimationOptions(QChart::AnimationOptions options); |
|
67 | void setAnimationOptions(QChart::AnimationOptions options); | |
69 | QChart::AnimationOptions animationOptions() const; |
|
68 | QChart::AnimationOptions animationOptions() const; | |
70 |
|
69 | |||
71 | void zoomIn(); |
|
70 | void zoomIn(); | |
72 | void zoomIn(const QRectF& rect); |
|
71 | void zoomIn(const QRectF& rect); | |
73 | void zoomOut(); |
|
72 | void zoomOut(); | |
74 | void scroll(int dx,int dy); |
|
73 | void scroll(int dx,int dy); | |
75 |
|
74 | |||
76 | private: |
|
75 | void setGeometry(const QRectF& rect); | |
|
76 | QRectF chartGeometry() const { return m_chartRect; } | |||
|
77 | ||||
|
78 | void setMinimumMarginHeight(Axis* axis, qreal height); | |||
|
79 | void setMinimumMarginWidth(Axis* axis, qreal width); | |||
|
80 | qreal minimumLeftMargin() const { return m_minLeftMargin; } | |||
|
81 | qreal minimumBottomMargin() const { return m_minBottomMargin; } | |||
|
82 | ||||
|
83 | public: //TODO: fix me | |||
77 | void createConnections(); |
|
84 | void createConnections(); | |
78 | void resetAllElements(); |
|
85 | void resetAllElements(); | |
|
86 | void createChartBackgroundItem(); | |||
|
87 | void createChartTitleItem(); | |||
|
88 | QRect margins() const { return m_chartMargins;} | |||
79 |
|
89 | |||
80 | public Q_SLOTS: |
|
90 | public Q_SLOTS: | |
81 | void handleSeriesAdded(QSeries* series,Domain* domain); |
|
91 | void handleSeriesAdded(QSeries* series,Domain* domain); | |
82 | void handleSeriesRemoved(QSeries* series); |
|
92 | void handleSeriesRemoved(QSeries* series); | |
83 | void handleAxisAdded(QChartAxis* axis,Domain* domain); |
|
93 | void handleAxisAdded(QChartAxis* axis,Domain* domain); | |
84 | void handleAxisRemoved(QChartAxis* axis); |
|
94 | void handleAxisRemoved(QChartAxis* axis); | |
85 | void handleGeometryChanged(); |
|
95 | void updateLayout(); | |
86 |
|
96 | |||
87 | Q_SIGNALS: |
|
97 | Q_SIGNALS: | |
88 | void geometryChanged(const QRectF& rect); |
|
98 | void geometryChanged(const QRectF& rect); | |
89 |
|
99 | |||
|
100 | ||||
90 | private: |
|
101 | private: | |
91 | QChart* m_chart; |
|
102 | QChart* m_chart; | |
92 | ChartAnimator* m_animator; |
|
103 | ChartAnimator* m_animator; | |
93 | ChartDataSet* m_dataset; |
|
104 | ChartDataSet* m_dataset; | |
94 | ChartTheme *m_chartTheme; |
|
105 | ChartTheme *m_chartTheme; | |
95 | QMap<QSeries*,Chart*> m_chartItems; |
|
106 | QMap<QSeries*,Chart*> m_chartItems; | |
96 | QMap<QChartAxis*,Axis*> m_axisItems; |
|
107 | QMap<QChartAxis*,Axis*> m_axisItems; | |
97 | QRectF m_rect; |
|
108 | QRectF m_rect; | |
|
109 | QRectF m_chartRect; | |||
98 | QChart::AnimationOptions m_options; |
|
110 | QChart::AnimationOptions m_options; | |
99 | bool m_themeForce; |
|
111 | bool m_themeForce; | |
100 | int m_backgroundPadding; |
|
112 | qreal m_minLeftMargin; | |
|
113 | qreal m_minBottomMargin; | |||
|
114 | public: //TODO: fixme | |||
|
115 | ChartBackground* m_backgroundItem; | |||
|
116 | QGraphicsSimpleTextItem* m_titleItem; | |||
|
117 | int m_marginBig; | |||
|
118 | int m_marginSmall; | |||
|
119 | int m_marginTiny; | |||
|
120 | QRect m_chartMargins; | |||
|
121 | QRect m_legendMargins; | |||
101 |
|
122 | |||
102 | }; |
|
123 | }; | |
103 |
|
124 | |||
104 | QTCOMMERCIALCHART_END_NAMESPACE |
|
125 | QTCOMMERCIALCHART_END_NAMESPACE | |
105 |
|
126 | |||
106 | #endif /* CHARTPRESENTER_H_ */ |
|
127 | #endif /* CHARTPRESENTER_H_ */ |
@@ -1,393 +1,392 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "charttheme_p.h" |
|
21 | #include "charttheme_p.h" | |
22 | #include "qchart.h" |
|
22 | #include "qchart.h" | |
23 | #include "qchartview.h" |
|
23 | #include "qchartview.h" | |
24 | #include "qlegend.h" |
|
24 | #include "qlegend.h" | |
25 | #include "qchartaxis.h" |
|
25 | #include "qchartaxis.h" | |
26 | #include <QTime> |
|
26 | #include <QTime> | |
27 |
|
27 | |||
28 | //series |
|
28 | //series | |
29 | #include "qbarset.h" |
|
29 | #include "qbarset.h" | |
30 | #include "qbarseries.h" |
|
30 | #include "qbarseries.h" | |
31 | #include "qstackedbarseries.h" |
|
31 | #include "qstackedbarseries.h" | |
32 | #include "qpercentbarseries.h" |
|
32 | #include "qpercentbarseries.h" | |
33 | #include "qlineseries.h" |
|
33 | #include "qlineseries.h" | |
34 | #include "qareaseries.h" |
|
34 | #include "qareaseries.h" | |
35 | #include "qscatterseries.h" |
|
35 | #include "qscatterseries.h" | |
36 | #include "qpieseries.h" |
|
36 | #include "qpieseries.h" | |
37 | #include "qpieslice.h" |
|
37 | #include "qpieslice.h" | |
38 | #include "qsplineseries.h" |
|
38 | #include "qsplineseries.h" | |
39 |
|
39 | |||
40 | //items |
|
40 | //items | |
41 | #include "axisitem_p.h" |
|
41 | #include "axisitem_p.h" | |
42 | #include "barchartitem_p.h" |
|
42 | #include "barchartitem_p.h" | |
43 | #include "stackedbarchartitem_p.h" |
|
43 | #include "stackedbarchartitem_p.h" | |
44 | #include "percentbarchartitem_p.h" |
|
44 | #include "percentbarchartitem_p.h" | |
45 | #include "linechartitem_p.h" |
|
45 | #include "linechartitem_p.h" | |
46 | #include "areachartitem_p.h" |
|
46 | #include "areachartitem_p.h" | |
47 | #include "scatterchartitem_p.h" |
|
47 | #include "scatterchartitem_p.h" | |
48 | #include "piechartitem_p.h" |
|
48 | #include "piechartitem_p.h" | |
49 | #include "splinechartitem_p.h" |
|
49 | #include "splinechartitem_p.h" | |
50 |
|
50 | |||
51 | //themes |
|
51 | //themes | |
52 | #include "chartthemesystem_p.h" |
|
52 | #include "chartthemesystem_p.h" | |
53 | #include "chartthemelight_p.h" |
|
53 | #include "chartthemelight_p.h" | |
54 | #include "chartthemebluecerulean_p.h" |
|
54 | #include "chartthemebluecerulean_p.h" | |
55 | #include "chartthemedark_p.h" |
|
55 | #include "chartthemedark_p.h" | |
56 | #include "chartthemebrownsand_p.h" |
|
56 | #include "chartthemebrownsand_p.h" | |
57 | #include "chartthemebluencs_p.h" |
|
57 | #include "chartthemebluencs_p.h" | |
58 | #include "chartthemehighcontrast_p.h" |
|
58 | #include "chartthemehighcontrast_p.h" | |
59 | #include "chartthemeblueicy_p.h" |
|
59 | #include "chartthemeblueicy_p.h" | |
60 |
|
60 | |||
61 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
61 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
62 |
|
62 | |||
63 | ChartTheme::ChartTheme(QChart::ChartTheme id) : |
|
63 | ChartTheme::ChartTheme(QChart::ChartTheme id) : | |
64 | m_masterFont(QFont("arial", 14)), |
|
64 | m_masterFont(QFont("arial", 14)), | |
65 | m_labelFont(QFont("arial", 10)), |
|
65 | m_labelFont(QFont("arial", 10)), | |
66 | m_titleBrush(QColor(QRgb(0x000000))), |
|
66 | m_titleBrush(QColor(QRgb(0x000000))), | |
67 | m_axisLinePen(QPen(QRgb(0x000000))), |
|
67 | m_axisLinePen(QPen(QRgb(0x000000))), | |
68 | m_axisLabelBrush(QColor(QRgb(0x000000))), |
|
68 | m_axisLabelBrush(QColor(QRgb(0x000000))), | |
69 | m_backgroundShadesPen(Qt::NoPen), |
|
69 | m_backgroundShadesPen(Qt::NoPen), | |
70 | m_backgroundShadesBrush(Qt::NoBrush), |
|
70 | m_backgroundShadesBrush(Qt::NoBrush), | |
71 | m_backgroundShades(BackgroundShadesNone), |
|
71 | m_backgroundShades(BackgroundShadesNone), | |
72 | m_gridLinePen(QPen(QRgb(0x000000))) |
|
72 | m_gridLinePen(QPen(QRgb(0x000000))) | |
73 | { |
|
73 | { | |
74 | m_id = id; |
|
74 | m_id = id; | |
75 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); |
|
75 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); | |
76 | } |
|
76 | } | |
77 |
|
77 | |||
78 |
|
78 | |||
79 | ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme) |
|
79 | ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme) | |
80 | { |
|
80 | { | |
81 | switch(theme) { |
|
81 | switch(theme) { | |
82 | case QChart::ChartThemeLight: |
|
82 | case QChart::ChartThemeLight: | |
83 | return new ChartThemeLight(); |
|
83 | return new ChartThemeLight(); | |
84 | case QChart::ChartThemeBlueCerulean: |
|
84 | case QChart::ChartThemeBlueCerulean: | |
85 | return new ChartThemeBlueCerulean(); |
|
85 | return new ChartThemeBlueCerulean(); | |
86 | case QChart::ChartThemeDark: |
|
86 | case QChart::ChartThemeDark: | |
87 | return new ChartThemeDark(); |
|
87 | return new ChartThemeDark(); | |
88 | case QChart::ChartThemeBrownSand: |
|
88 | case QChart::ChartThemeBrownSand: | |
89 | return new ChartThemeBrownSand(); |
|
89 | return new ChartThemeBrownSand(); | |
90 | case QChart::ChartThemeBlueNcs: |
|
90 | case QChart::ChartThemeBlueNcs: | |
91 | return new ChartThemeBlueNcs(); |
|
91 | return new ChartThemeBlueNcs(); | |
92 | case QChart::ChartThemeHighContrast: |
|
92 | case QChart::ChartThemeHighContrast: | |
93 | return new ChartThemeHighContrast(); |
|
93 | return new ChartThemeHighContrast(); | |
94 | case QChart::ChartThemeBlueIcy: |
|
94 | case QChart::ChartThemeBlueIcy: | |
95 | return new ChartThemeBlueIcy(); |
|
95 | return new ChartThemeBlueIcy(); | |
96 | default: |
|
96 | default: | |
97 | return new ChartThemeSystem(); |
|
97 | return new ChartThemeSystem(); | |
98 | } |
|
98 | } | |
99 | } |
|
99 | } | |
100 |
|
100 | |||
101 | void ChartTheme::decorate(QChart* chart,bool force) |
|
101 | void ChartTheme::decorate(QChart* chart,bool force) | |
102 | { |
|
102 | { | |
103 | QBrush brush; |
|
103 | QBrush brush; | |
104 |
|
104 | |||
105 | if(brush == chart->backgroundBrush() || force) |
|
105 | if(brush == chart->backgroundBrush() || force) | |
106 | chart->setBackgroundBrush(m_chartBackgroundGradient); |
|
106 | chart->setBackgroundBrush(m_chartBackgroundGradient); | |
107 | chart->setTitleFont(m_masterFont); |
|
107 | chart->setTitleFont(m_masterFont); | |
108 | chart->setTitleBrush(m_titleBrush); |
|
108 | chart->setTitleBrush(m_titleBrush); | |
109 | } |
|
109 | } | |
110 |
|
110 | |||
111 | void ChartTheme::decorate(QLegend* legend,bool force) |
|
111 | void ChartTheme::decorate(QLegend* legend,bool force) | |
112 | { |
|
112 | { | |
113 | QPen pen; |
|
113 | QPen pen; | |
114 | QBrush brush; |
|
114 | QBrush brush; | |
115 |
|
115 | |||
116 | if (pen == legend->pen() || force){ |
|
116 | if (pen == legend->pen() || force){ | |
117 | legend->setPen(Qt::NoPen); |
|
117 | legend->setPen(Qt::NoPen); | |
118 | } |
|
118 | } | |
119 |
|
119 | |||
120 |
|
120 | |||
121 | if (brush == legend->brush() || force) { |
|
121 | if (brush == legend->brush() || force) { | |
122 | legend->setBrush(m_chartBackgroundGradient); |
|
122 | legend->setBrush(m_chartBackgroundGradient); | |
123 | } |
|
123 | } | |
124 | } |
|
124 | } | |
125 |
|
125 | |||
126 | void ChartTheme::decorate(QAreaSeries* series, int index,bool force) |
|
126 | void ChartTheme::decorate(QAreaSeries* series, int index,bool force) | |
127 | { |
|
127 | { | |
128 | QPen pen; |
|
128 | QPen pen; | |
129 | QBrush brush; |
|
129 | QBrush brush; | |
130 |
|
130 | |||
131 | if (pen == series->pen() || force){ |
|
131 | if (pen == series->pen() || force){ | |
132 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0)); |
|
132 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0)); | |
133 | pen.setWidthF(2); |
|
133 | pen.setWidthF(2); | |
134 | series->setPen(pen); |
|
134 | series->setPen(pen); | |
135 | } |
|
135 | } | |
136 |
|
136 | |||
137 | if (brush == series->brush() || force) { |
|
137 | if (brush == series->brush() || force) { | |
138 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); |
|
138 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); | |
139 | series->setBrush(brush); |
|
139 | series->setBrush(brush); | |
140 | } |
|
140 | } | |
141 | } |
|
141 | } | |
142 |
|
142 | |||
143 |
|
143 | |||
144 | void ChartTheme::decorate(QLineSeries* series,int index,bool force) |
|
144 | void ChartTheme::decorate(QLineSeries* series,int index,bool force) | |
145 | { |
|
145 | { | |
146 | QPen pen; |
|
146 | QPen pen; | |
147 | if(pen == series->pen() || force ){ |
|
147 | if(pen == series->pen() || force ){ | |
148 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); |
|
148 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); | |
149 | pen.setWidthF(2); |
|
149 | pen.setWidthF(2); | |
150 | series->setPen(pen); |
|
150 | series->setPen(pen); | |
151 | } |
|
151 | } | |
152 | } |
|
152 | } | |
153 |
|
153 | |||
154 | void ChartTheme::decorate(QBarSeries* series, int index, bool force) |
|
154 | void ChartTheme::decorate(QBarSeries* series, int index, bool force) | |
155 | { |
|
155 | { | |
156 | QBrush brush; |
|
156 | QBrush brush; | |
157 | QPen pen; |
|
157 | QPen pen; | |
158 | QList<QBarSet*> sets = series->barSets(); |
|
158 | QList<QBarSet*> sets = series->barSets(); | |
159 |
|
159 | |||
160 | qreal takeAtPos = 0.5; |
|
160 | qreal takeAtPos = 0.5; | |
161 | qreal step = 0.2; |
|
161 | qreal step = 0.2; | |
162 | if (sets.count() > 1 ) { |
|
162 | if (sets.count() > 1 ) { | |
163 | step = 1.0 / (qreal) sets.count(); |
|
163 | step = 1.0 / (qreal) sets.count(); | |
164 | if (sets.count() % m_seriesGradients.count()) |
|
164 | if (sets.count() % m_seriesGradients.count()) | |
165 | step *= m_seriesGradients.count(); |
|
165 | step *= m_seriesGradients.count(); | |
166 | else |
|
166 | else | |
167 | step *= (m_seriesGradients.count() - 1); |
|
167 | step *= (m_seriesGradients.count() - 1); | |
168 | } |
|
168 | } | |
169 |
|
169 | |||
170 | for (int i(0); i < sets.count(); i++) { |
|
170 | for (int i(0); i < sets.count(); i++) { | |
171 | int colorIndex = (index + i) % m_seriesGradients.count(); |
|
171 | int colorIndex = (index + i) % m_seriesGradients.count(); | |
172 | if (i > 0 && i % m_seriesGradients.count() == 0) { |
|
172 | if (i > 0 && i % m_seriesGradients.count() == 0) { | |
173 | // There is no dedicated base color for each sets, generate more colors |
|
173 | // There is no dedicated base color for each sets, generate more colors | |
174 | takeAtPos += step; |
|
174 | takeAtPos += step; | |
175 | if (takeAtPos == 1.0) |
|
175 | if (takeAtPos == 1.0) | |
176 | takeAtPos += step; |
|
176 | takeAtPos += step; | |
177 | takeAtPos -= (int) takeAtPos; |
|
177 | takeAtPos -= (int) takeAtPos; | |
178 | } |
|
178 | } | |
179 | qDebug() << "pos:" << takeAtPos; |
|
|||
180 | if (brush == sets.at(i)->brush() || force ) |
|
179 | if (brush == sets.at(i)->brush() || force ) | |
181 | sets.at(i)->setBrush(colorAt(m_seriesGradients.at(colorIndex), takeAtPos)); |
|
180 | sets.at(i)->setBrush(colorAt(m_seriesGradients.at(colorIndex), takeAtPos)); | |
182 |
|
181 | |||
183 | // Pick label color from the opposite end of the gradient. |
|
182 | // Pick label color from the opposite end of the gradient. | |
184 | // 0.3 as a boundary seems to work well. |
|
183 | // 0.3 as a boundary seems to work well. | |
185 | if (takeAtPos < 0.3) |
|
184 | if (takeAtPos < 0.3) | |
186 | sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1)); |
|
185 | sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1)); | |
187 | else |
|
186 | else | |
188 | sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0)); |
|
187 | sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0)); | |
189 |
|
188 | |||
190 | if (pen == sets.at(i)->pen() || force) { |
|
189 | if (pen == sets.at(i)->pen() || force) { | |
191 | QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0); |
|
190 | QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0); | |
192 | sets.at(i)->setPen(c); |
|
191 | sets.at(i)->setPen(c); | |
193 | } |
|
192 | } | |
194 | } |
|
193 | } | |
195 | } |
|
194 | } | |
196 |
|
195 | |||
197 | void ChartTheme::decorate(QScatterSeries* series, int index,bool force) |
|
196 | void ChartTheme::decorate(QScatterSeries* series, int index,bool force) | |
198 | { |
|
197 | { | |
199 | QPen pen; |
|
198 | QPen pen; | |
200 | QBrush brush; |
|
199 | QBrush brush; | |
201 |
|
200 | |||
202 | if (pen == series->pen() || force) { |
|
201 | if (pen == series->pen() || force) { | |
203 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0)); |
|
202 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0)); | |
204 | pen.setWidthF(2); |
|
203 | pen.setWidthF(2); | |
205 | series->setPen(pen); |
|
204 | series->setPen(pen); | |
206 | } |
|
205 | } | |
207 |
|
206 | |||
208 | if (brush == series->brush() || force) { |
|
207 | if (brush == series->brush() || force) { | |
209 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); |
|
208 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); | |
210 | series->setBrush(brush); |
|
209 | series->setBrush(brush); | |
211 | } |
|
210 | } | |
212 | } |
|
211 | } | |
213 |
|
212 | |||
214 | void ChartTheme::decorate(QPieSeries* series, int index, bool force) |
|
213 | void ChartTheme::decorate(QPieSeries* series, int index, bool force) | |
215 | { |
|
214 | { | |
216 |
|
215 | |||
217 | for (int i(0); i < series->slices().count(); i++) { |
|
216 | for (int i(0); i < series->slices().count(); i++) { | |
218 |
|
217 | |||
219 | QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0); |
|
218 | QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0); | |
220 |
|
219 | |||
221 | // Get color for a slice from a gradient linearly, beginning from the start of the gradient |
|
220 | // Get color for a slice from a gradient linearly, beginning from the start of the gradient | |
222 | qreal pos = (qreal) (i + 1) / (qreal) series->count(); |
|
221 | qreal pos = (qreal) (i + 1) / (qreal) series->count(); | |
223 | QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); |
|
222 | QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); | |
224 |
|
223 | |||
225 | QPieSlice *s = series->slices().at(i); |
|
224 | QPieSlice *s = series->slices().at(i); | |
226 | PieSliceData data = PieSliceData::data(s); |
|
225 | PieSliceData data = PieSliceData::data(s); | |
227 |
|
226 | |||
228 | if (data.m_slicePen.isThemed() || force) { |
|
227 | if (data.m_slicePen.isThemed() || force) { | |
229 | data.m_slicePen = penColor; |
|
228 | data.m_slicePen = penColor; | |
230 | data.m_slicePen.setThemed(true); |
|
229 | data.m_slicePen.setThemed(true); | |
231 | } |
|
230 | } | |
232 |
|
231 | |||
233 | if (data.m_sliceBrush.isThemed() || force) { |
|
232 | if (data.m_sliceBrush.isThemed() || force) { | |
234 | data.m_sliceBrush = brushColor; |
|
233 | data.m_sliceBrush = brushColor; | |
235 | data.m_sliceBrush.setThemed(true); |
|
234 | data.m_sliceBrush.setThemed(true); | |
236 | } |
|
235 | } | |
237 |
|
236 | |||
238 | if (data.m_labelPen.isThemed() || force) { |
|
237 | if (data.m_labelPen.isThemed() || force) { | |
239 | data.m_labelPen = QPen(m_titleBrush.color()); |
|
238 | data.m_labelPen = QPen(m_titleBrush.color()); | |
240 | data.m_labelPen.setThemed(true); |
|
239 | data.m_labelPen.setThemed(true); | |
241 | } |
|
240 | } | |
242 |
|
241 | |||
243 | if (data.m_labelFont.isThemed() || force) { |
|
242 | if (data.m_labelFont.isThemed() || force) { | |
244 | data.m_labelFont = m_labelFont; |
|
243 | data.m_labelFont = m_labelFont; | |
245 | data.m_labelFont.setThemed(true); |
|
244 | data.m_labelFont.setThemed(true); | |
246 | } |
|
245 | } | |
247 |
|
246 | |||
248 | if (PieSliceData::data(s) != data) { |
|
247 | if (PieSliceData::data(s) != data) { | |
249 | PieSliceData::data(s) = data; |
|
248 | PieSliceData::data(s) = data; | |
250 | emit PieSliceData::data(s).emitChangedSignal(s); |
|
249 | emit PieSliceData::data(s).emitChangedSignal(s); | |
251 | } |
|
250 | } | |
252 | } |
|
251 | } | |
253 | } |
|
252 | } | |
254 |
|
253 | |||
255 | void ChartTheme::decorate(QSplineSeries* series, int index, bool force) |
|
254 | void ChartTheme::decorate(QSplineSeries* series, int index, bool force) | |
256 | { |
|
255 | { | |
257 | QPen pen; |
|
256 | QPen pen; | |
258 | if(pen == series->pen() || force){ |
|
257 | if(pen == series->pen() || force){ | |
259 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); |
|
258 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); | |
260 | pen.setWidthF(2); |
|
259 | pen.setWidthF(2); | |
261 | series->setPen(pen); |
|
260 | series->setPen(pen); | |
262 | } |
|
261 | } | |
263 | } |
|
262 | } | |
264 |
|
263 | |||
265 | void ChartTheme::decorate(QChartAxis* axis,bool axisX, bool force) |
|
264 | void ChartTheme::decorate(QChartAxis* axis,bool axisX, bool force) | |
266 | { |
|
265 | { | |
267 | QPen pen; |
|
266 | QPen pen; | |
268 | QBrush brush; |
|
267 | QBrush brush; | |
269 | QFont font; |
|
268 | QFont font; | |
270 |
|
269 | |||
271 | if (axis->isAxisVisible()) { |
|
270 | if (axis->isAxisVisible()) { | |
272 |
|
271 | |||
273 | if(brush == axis->labelsBrush() || force){ |
|
272 | if(brush == axis->labelsBrush() || force){ | |
274 | axis->setLabelsBrush(m_axisLabelBrush); |
|
273 | axis->setLabelsBrush(m_axisLabelBrush); | |
275 | } |
|
274 | } | |
276 | if(pen == axis->labelsPen() || force){ |
|
275 | if(pen == axis->labelsPen() || force){ | |
277 | axis->setLabelsPen(Qt::NoPen); // NoPen for performance reasons |
|
276 | axis->setLabelsPen(Qt::NoPen); // NoPen for performance reasons | |
278 | } |
|
277 | } | |
279 |
|
278 | |||
280 |
|
279 | |||
281 | if (axis->shadesVisible() || force) { |
|
280 | if (axis->shadesVisible() || force) { | |
282 |
|
281 | |||
283 | if(brush == axis->shadesBrush() || force){ |
|
282 | if(brush == axis->shadesBrush() || force){ | |
284 | axis->setShadesBrush(m_backgroundShadesBrush); |
|
283 | axis->setShadesBrush(m_backgroundShadesBrush); | |
285 | } |
|
284 | } | |
286 |
|
285 | |||
287 | if(pen == axis->shadesPen() || force){ |
|
286 | if(pen == axis->shadesPen() || force){ | |
288 | axis->setShadesPen(m_backgroundShadesPen); |
|
287 | axis->setShadesPen(m_backgroundShadesPen); | |
289 | } |
|
288 | } | |
290 |
|
289 | |||
291 | if(force && (m_backgroundShades == BackgroundShadesBoth |
|
290 | if(force && (m_backgroundShades == BackgroundShadesBoth | |
292 | || (m_backgroundShades == BackgroundShadesVertical && axisX) |
|
291 | || (m_backgroundShades == BackgroundShadesVertical && axisX) | |
293 | || (m_backgroundShades == BackgroundShadesHorizontal && !axisX))){ |
|
292 | || (m_backgroundShades == BackgroundShadesHorizontal && !axisX))){ | |
294 | axis->setShadesVisible(true); |
|
293 | axis->setShadesVisible(true); | |
295 |
|
294 | |||
296 | } |
|
295 | } | |
297 | } |
|
296 | } | |
298 |
|
297 | |||
299 | if(pen == axis->axisPen() || force){ |
|
298 | if(pen == axis->axisPen() || force){ | |
300 | axis->setAxisPen(m_axisLinePen); |
|
299 | axis->setAxisPen(m_axisLinePen); | |
301 | } |
|
300 | } | |
302 |
|
301 | |||
303 | if(pen == axis->gridLinePen() || force){ |
|
302 | if(pen == axis->gridLinePen() || force){ | |
304 | axis->setGridLinePen(m_gridLinePen); |
|
303 | axis->setGridLinePen(m_gridLinePen); | |
305 | } |
|
304 | } | |
306 |
|
305 | |||
307 | if(font == axis->labelsFont() || force){ |
|
306 | if(font == axis->labelsFont() || force){ | |
308 | axis->setLabelsFont(m_labelFont); |
|
307 | axis->setLabelsFont(m_labelFont); | |
309 | } |
|
308 | } | |
310 | } |
|
309 | } | |
311 | } |
|
310 | } | |
312 |
|
311 | |||
313 | void ChartTheme::generateSeriesGradients() |
|
312 | void ChartTheme::generateSeriesGradients() | |
314 | { |
|
313 | { | |
315 | // Generate gradients in HSV color space |
|
314 | // Generate gradients in HSV color space | |
316 | foreach (QColor color, m_seriesColors) { |
|
315 | foreach (QColor color, m_seriesColors) { | |
317 | QLinearGradient g; |
|
316 | QLinearGradient g; | |
318 | qreal h = color.hsvHueF(); |
|
317 | qreal h = color.hsvHueF(); | |
319 | qreal s = color.hsvSaturationF(); |
|
318 | qreal s = color.hsvSaturationF(); | |
320 |
|
319 | |||
321 | // TODO: tune the algorithm to give nice results with most base colors defined in |
|
320 | // TODO: tune the algorithm to give nice results with most base colors defined in | |
322 | // most themes. The rest of the gradients we can define manually in theme specific |
|
321 | // most themes. The rest of the gradients we can define manually in theme specific | |
323 | // implementation. |
|
322 | // implementation. | |
324 | QColor start = color; |
|
323 | QColor start = color; | |
325 | start.setHsvF(h, 0.0, 1.0); |
|
324 | start.setHsvF(h, 0.0, 1.0); | |
326 | g.setColorAt(0.0, start); |
|
325 | g.setColorAt(0.0, start); | |
327 |
|
326 | |||
328 | g.setColorAt(0.5, color); |
|
327 | g.setColorAt(0.5, color); | |
329 |
|
328 | |||
330 | QColor end = color; |
|
329 | QColor end = color; | |
331 | end.setHsvF(h, s, 0.25); |
|
330 | end.setHsvF(h, s, 0.25); | |
332 | g.setColorAt(1.0, end); |
|
331 | g.setColorAt(1.0, end); | |
333 |
|
332 | |||
334 | m_seriesGradients << g; |
|
333 | m_seriesGradients << g; | |
335 | } |
|
334 | } | |
336 | } |
|
335 | } | |
337 |
|
336 | |||
338 |
|
337 | |||
339 | QColor ChartTheme::colorAt(const QColor &start, const QColor &end, qreal pos) |
|
338 | QColor ChartTheme::colorAt(const QColor &start, const QColor &end, qreal pos) | |
340 | { |
|
339 | { | |
341 | Q_ASSERT(pos >=0.0 && pos <= 1.0); |
|
340 | Q_ASSERT(pos >=0.0 && pos <= 1.0); | |
342 | qreal r = start.redF() + ((end.redF() - start.redF()) * pos); |
|
341 | qreal r = start.redF() + ((end.redF() - start.redF()) * pos); | |
343 | qreal g = start.greenF() + ((end.greenF() - start.greenF()) * pos); |
|
342 | qreal g = start.greenF() + ((end.greenF() - start.greenF()) * pos); | |
344 | qreal b = start.blueF() + ((end.blueF() - start.blueF()) * pos); |
|
343 | qreal b = start.blueF() + ((end.blueF() - start.blueF()) * pos); | |
345 | QColor c; |
|
344 | QColor c; | |
346 | c.setRgbF(r, g, b); |
|
345 | c.setRgbF(r, g, b); | |
347 | return c; |
|
346 | return c; | |
348 | } |
|
347 | } | |
349 |
|
348 | |||
350 | QColor ChartTheme::colorAt(const QGradient &gradient, qreal pos) |
|
349 | QColor ChartTheme::colorAt(const QGradient &gradient, qreal pos) | |
351 | { |
|
350 | { | |
352 | Q_ASSERT(pos >=0 && pos <= 1.0); |
|
351 | Q_ASSERT(pos >=0 && pos <= 1.0); | |
353 |
|
352 | |||
354 | // another possibility: |
|
353 | // another possibility: | |
355 | // http://stackoverflow.com/questions/3306786/get-intermediate-color-from-a-gradient |
|
354 | // http://stackoverflow.com/questions/3306786/get-intermediate-color-from-a-gradient | |
356 |
|
355 | |||
357 | QGradientStops stops = gradient.stops(); |
|
356 | QGradientStops stops = gradient.stops(); | |
358 | int count = stops.count(); |
|
357 | int count = stops.count(); | |
359 |
|
358 | |||
360 | // find previous stop relative to position |
|
359 | // find previous stop relative to position | |
361 | QGradientStop prev = stops.first(); |
|
360 | QGradientStop prev = stops.first(); | |
362 | for (int i=0; i<count; i++) { |
|
361 | for (int i=0; i<count; i++) { | |
363 | QGradientStop stop = stops.at(i); |
|
362 | QGradientStop stop = stops.at(i); | |
364 | if (pos > stop.first) |
|
363 | if (pos > stop.first) | |
365 | prev = stop; |
|
364 | prev = stop; | |
366 |
|
365 | |||
367 | // given position is actually a stop position? |
|
366 | // given position is actually a stop position? | |
368 | if (pos == stop.first) { |
|
367 | if (pos == stop.first) { | |
369 | //qDebug() << "stop color" << pos; |
|
368 | //qDebug() << "stop color" << pos; | |
370 | return stop.second; |
|
369 | return stop.second; | |
371 | } |
|
370 | } | |
372 | } |
|
371 | } | |
373 |
|
372 | |||
374 | // find next stop relative to position |
|
373 | // find next stop relative to position | |
375 | QGradientStop next = stops.last(); |
|
374 | QGradientStop next = stops.last(); | |
376 | for (int i=count-1; i>=0; i--) { |
|
375 | for (int i=count-1; i>=0; i--) { | |
377 | QGradientStop stop = stops.at(i); |
|
376 | QGradientStop stop = stops.at(i); | |
378 | if (pos < stop.first) |
|
377 | if (pos < stop.first) | |
379 | next = stop; |
|
378 | next = stop; | |
380 | } |
|
379 | } | |
381 |
|
380 | |||
382 | //qDebug() << "prev" << prev.first << "pos" << pos << "next" << next.first; |
|
381 | //qDebug() << "prev" << prev.first << "pos" << pos << "next" << next.first; | |
383 |
|
382 | |||
384 | qreal range = next.first - prev.first; |
|
383 | qreal range = next.first - prev.first; | |
385 | qreal posDelta = pos - prev.first; |
|
384 | qreal posDelta = pos - prev.first; | |
386 | qreal relativePos = posDelta / range; |
|
385 | qreal relativePos = posDelta / range; | |
387 |
|
386 | |||
388 | //qDebug() << "range" << range << "posDelta" << posDelta << "relativePos" << relativePos; |
|
387 | //qDebug() << "range" << range << "posDelta" << posDelta << "relativePos" << relativePos; | |
389 |
|
388 | |||
390 | return colorAt(prev.second, next.second, relativePos); |
|
389 | return colorAt(prev.second, next.second, relativePos); | |
391 | } |
|
390 | } | |
392 |
|
391 | |||
393 | QTCOMMERCIALCHART_END_NAMESPACE |
|
392 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,214 +1,192 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qchartglobal.h" |
|
|||
22 | #include "legendmarker_p.h" |
|
21 | #include "legendmarker_p.h" | |
|
22 | #include "qlegend.h" | |||
|
23 | #include "qbarseries.h" | |||
|
24 | #include "qpieseries.h" | |||
23 | #include <qpieslice.h> |
|
25 | #include <qpieslice.h> | |
24 | #include <qbarset.h> |
|
26 | #include <qbarset.h> | |
25 | #include <qxyseries.h> |
|
27 | #include <qxyseries.h> | |
26 | #include <qareaseries.h> |
|
28 | #include <qareaseries.h> | |
27 | #include <QPainter> |
|
29 | #include <QPainter> | |
28 | #include <QGraphicsSceneEvent> |
|
30 | #include <QGraphicsSceneEvent> | |
29 | #include <QGraphicsSimpleTextItem> |
|
31 | #include <QGraphicsSimpleTextItem> | |
30 |
|
32 | |||
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
32 |
|
34 | |||
33 |
LegendMarker::LegendMarker(QSeries * |
|
35 | LegendMarker::LegendMarker(QSeries* series,QLegend *legend) : QGraphicsObject(legend), | |
34 | m_pos(0,0), |
|
36 | m_series(series), | |
35 | m_size(0,0), |
|
37 | m_markerRect(0,0,10.0,10.0), | |
36 |
|
|
38 | m_boundingRect(0,0,0,0), | |
37 | m_markerBoundingRect(0,0,0,0), |
|
39 | m_legend(legend), | |
38 | m_series(series), |
|
40 | m_textItem(new QGraphicsSimpleTextItem(this)), | |
39 | m_barset(0), |
|
41 | m_rectItem(new QGraphicsRectItem(this)) | |
40 | m_pieslice(0), |
|
|||
41 | m_textItem(new QGraphicsSimpleTextItem(this)) |
|
|||
42 | { |
|
|||
43 | setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton); |
|
|||
44 | } |
|
|||
45 |
|
||||
46 | LegendMarker::LegendMarker(QSeries *series, QBarSet *barset, QGraphicsItem *parent) : QGraphicsObject(parent), |
|
|||
47 | m_pos(0,0), |
|
|||
48 | m_size(0,0), |
|
|||
49 | m_boundingRect(0,0,0,0), |
|
|||
50 | m_markerBoundingRect(0,0,0,0), |
|
|||
51 | m_series(series), |
|
|||
52 | m_barset(barset), |
|
|||
53 | m_pieslice(0), |
|
|||
54 | m_textItem(new QGraphicsSimpleTextItem(this)) |
|
|||
55 | { |
|
42 | { | |
56 | setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton); |
|
43 | //setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton); | |
57 | } |
|
44 | m_rectItem->setRect(m_markerRect); | |
58 |
|
45 | updateLayout(); | ||
59 | LegendMarker::LegendMarker(QSeries *series, QPieSlice *pieslice, QGraphicsItem *parent) : QGraphicsObject(parent), |
|
|||
60 | m_pos(0,0), |
|
|||
61 | m_size(0,0), |
|
|||
62 | m_boundingRect(0,0,0,0), |
|
|||
63 | m_markerBoundingRect(0,0,0,0), |
|
|||
64 | m_series(series), |
|
|||
65 | m_barset(0), |
|
|||
66 | m_pieslice(pieslice), |
|
|||
67 | m_textItem(new QGraphicsSimpleTextItem(this)) |
|
|||
68 | { |
|
|||
69 | setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton); |
|
|||
70 | } |
|
|||
71 |
|
||||
72 | void LegendMarker::setPos(qreal x, qreal y) |
|
|||
73 | { |
|
|||
74 | m_pos = QPointF(x,y); |
|
|||
75 | layoutChanged(); |
|
|||
76 | } |
|
46 | } | |
77 |
|
47 | |||
78 | void LegendMarker::setPen(const QPen &pen) |
|
48 | void LegendMarker::setPen(const QPen &pen) | |
79 | { |
|
49 | { | |
80 | m_pen = pen; |
|
50 | m_textItem->setPen(pen); | |
|
51 | updateLayout(); | |||
81 | } |
|
52 | } | |
82 |
|
53 | |||
83 | QPen LegendMarker::pen() const |
|
54 | QPen LegendMarker::pen() const | |
84 | { |
|
55 | { | |
85 | return m_pen; |
|
56 | return m_textItem->pen(); | |
86 | } |
|
57 | } | |
87 |
|
58 | |||
88 | void LegendMarker::setBrush(const QBrush &brush) |
|
59 | void LegendMarker::setBrush(const QBrush &brush) | |
89 | { |
|
60 | { | |
90 | m_brush = brush; |
|
61 | m_rectItem->setBrush(brush); | |
91 | } |
|
62 | } | |
92 |
|
63 | |||
93 | QBrush LegendMarker::brush() const |
|
64 | QBrush LegendMarker::brush() const | |
94 | { |
|
65 | { | |
95 | return m_brush; |
|
66 | return m_rectItem->brush(); | |
96 | } |
|
67 | } | |
97 |
|
68 | |||
98 |
void LegendMarker::set |
|
69 | void LegendMarker::setLabel(const QString name) | |
99 | { |
|
70 | { | |
100 | m_textItem->setText(name); |
|
71 | m_textItem->setText(name); | |
101 |
|
|
72 | updateLayout(); | |
102 | } |
|
73 | } | |
103 |
|
74 | |||
104 | QString LegendMarker::name() const |
|
75 | void LegendMarker::setSize(const QSize& size) | |
105 | { |
|
76 | { | |
106 | return m_textItem->text(); |
|
77 | m_markerRect = QRectF(0,0,size.width(),size.height()); | |
107 | } |
|
78 | } | |
108 |
|
79 | |||
109 |
QS |
|
80 | QString LegendMarker::label() const | |
110 | { |
|
81 | { | |
111 |
return m_ |
|
82 | return m_textItem->text(); | |
112 | } |
|
83 | } | |
113 |
|
84 | |||
114 | void LegendMarker::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
85 | void LegendMarker::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
115 | { |
|
86 | { | |
116 | Q_UNUSED(option) |
|
87 | Q_UNUSED(option) | |
117 | Q_UNUSED(widget) |
|
88 | Q_UNUSED(widget) | |
118 |
|
89 | Q_UNUSED(painter) | ||
119 | painter->setPen(m_pen); |
|
|||
120 | painter->setBrush(m_brush); |
|
|||
121 | painter->drawRect(m_markerBoundingRect); |
|
|||
122 | } |
|
90 | } | |
123 |
|
91 | |||
124 | QRectF LegendMarker::boundingRect() const |
|
92 | QRectF LegendMarker::boundingRect() const | |
125 | { |
|
93 | { | |
126 | return m_boundingRect; |
|
94 | return m_boundingRect; | |
127 | } |
|
95 | } | |
128 |
|
96 | |||
129 |
void LegendMarker:: |
|
97 | void LegendMarker::updateLayout() | |
130 | { |
|
98 | { | |
131 | QSizeF markerSize(10,10); |
|
|||
132 | qreal margin = 2; |
|
|||
133 |
|
||||
134 | m_size.setHeight(markerSize.height() + 2 * margin); |
|
|||
135 | m_size.setWidth(m_textItem->boundingRect().width() + markerSize.width() + 3 * margin); |
|
|||
136 |
|
99 | |||
137 | m_boundingRect = QRectF(m_pos.x(),m_pos.y(),m_size.width(),m_size.height()); |
|
100 | static const qreal margin = 2; | |
|
101 | static const qreal space = 4; | |||
138 |
|
102 | |||
139 | m_markerBoundingRect = QRectF(m_pos.x() + margin, m_pos.y() + margin, markerSize.width(),markerSize.height()); |
|
103 | const QRectF& textRect = m_textItem->boundingRect(); | |
|
104 | prepareGeometryChange(); | |||
|
105 | m_boundingRect = QRectF(0,0,m_markerRect.width() + 2*margin + space + textRect.width(),qMax(m_markerRect.height()+2*margin,textRect.height()+2*margin)); | |||
|
106 | m_textItem->setPos(m_markerRect.width() + space + margin,m_boundingRect.height()/2 - textRect.height()/2); | |||
|
107 | m_rectItem->setPos(margin,m_boundingRect.height()/2 - m_markerRect.height()/2); | |||
140 |
|
108 | |||
141 | m_textItem->setPos(m_pos.x() + markerSize.width() + 2 * margin, m_pos.y() + margin); |
|
|||
142 | } |
|
109 | } | |
143 |
|
110 | |||
144 | void LegendMarker::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
111 | void LegendMarker::mousePressEvent(QGraphicsSceneMouseEvent *event) | |
145 | { |
|
112 | { | |
146 | switch (m_series->type()) { |
|
113 | QGraphicsObject::mousePressEvent(event); | |
147 | case QSeries::SeriesTypeLine: |
|
114 | emit selected(); | |
148 | case QSeries::SeriesTypeArea: |
|
|||
149 | case QSeries::SeriesTypeScatter: |
|
|||
150 | case QSeries::SeriesTypeSpline: { |
|
|||
151 | emit clicked(m_series,event->button()); |
|
|||
152 | break; |
|
|||
153 | } |
|
|||
154 | case QSeries::SeriesTypeBar: |
|
|||
155 | case QSeries::SeriesTypeStackedBar: |
|
|||
156 | case QSeries::SeriesTypePercentBar: { |
|
|||
157 | emit clicked(m_barset,event->button()); |
|
|||
158 | break; |
|
|||
159 | } |
|
|||
160 | case QSeries::SeriesTypePie: { |
|
|||
161 | emit clicked(m_pieslice,event->button()); |
|
|||
162 | break; |
|
|||
163 | } |
|
|||
164 | default: { |
|
|||
165 | break; |
|
|||
166 | } |
|
|||
167 | } |
|
|||
168 | } |
|
115 | } | |
169 |
|
116 | |||
170 | void LegendMarker::changed() |
|
117 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
|
118 | ||||
|
119 | AreaLegendMarker::AreaLegendMarker(QAreaSeries *series,QLegend *legend) : LegendMarker(series,legend), | |||
|
120 | m_series(series) | |||
171 | { |
|
121 | { | |
172 | setPen(Qt::NoPen); |
|
122 | QObject::connect(this, SIGNAL(selected()), series, SIGNAL(selected())); | |
173 | switch (m_series->type()) { |
|
123 | QObject::connect(series,SIGNAL(updated()), this, SLOT(updated())); | |
174 | case QSeries::SeriesTypeArea: { |
|
124 | updated(); | |
175 | QAreaSeries* s = static_cast<QAreaSeries*> (m_series); |
|
125 | } | |
176 | setBrush(s->brush()); |
|
126 | ||
177 | setName(s->name()); |
|
127 | void AreaLegendMarker::updated() | |
178 | break; |
|
128 | { | |
179 | } |
|
129 | setBrush(m_series->brush()); | |
180 | case QSeries::SeriesTypeLine: |
|
130 | setLabel(m_series->name()); | |
181 | case QSeries::SeriesTypeSpline: { |
|
131 | } | |
182 | QXYSeries* s = static_cast<QXYSeries*> (m_series); |
|
132 | ||
183 | setBrush(QBrush(s->pen().color(),Qt::SolidPattern)); |
|
133 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
184 | setName(s->name()); |
|
134 | ||
185 | break; |
|
135 | BarLegendMarker::BarLegendMarker(QBarSeries *series,QBarSet *barset, QLegend *legend) : LegendMarker(series,legend), | |
186 | } |
|
136 | m_barset(barset) | |
187 | case QSeries::SeriesTypeScatter: { |
|
137 | { | |
188 | QXYSeries* s = static_cast<QXYSeries*> (m_series); |
|
138 | QObject::connect(this, SIGNAL(selected()),series, SIGNAL(selected())); | |
189 | setBrush(s->brush()); |
|
139 | QObject::connect(barset, SIGNAL(valueChanged()), this, SLOT(updated())); | |
190 | setName(s->name()); |
|
140 | updated(); | |
191 | break; |
|
141 | } | |
|
142 | ||||
|
143 | void BarLegendMarker::updated() | |||
|
144 | { | |||
|
145 | setBrush(m_barset->brush()); | |||
|
146 | setLabel(m_barset->name()); | |||
|
147 | } | |||
|
148 | ||||
|
149 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
|
150 | ||||
|
151 | PieLegendMarker::PieLegendMarker(QPieSeries* series,QPieSlice *pieslice, QLegend *legend) : LegendMarker(series,legend), | |||
|
152 | m_pieslice(pieslice) | |||
|
153 | { | |||
|
154 | QObject::connect(this, SIGNAL(selected()),pieslice, SIGNAL(selected())); | |||
|
155 | QObject::connect(pieslice, SIGNAL(changed()), this, SLOT(updated())); | |||
|
156 | QObject::connect(pieslice, SIGNAL(destroyed()), this, SLOT(deleteLater())); //TODO:checkthis | |||
|
157 | updated(); | |||
|
158 | } | |||
|
159 | ||||
|
160 | void PieLegendMarker::updated() | |||
|
161 | { | |||
|
162 | setBrush(m_pieslice->brush()); | |||
|
163 | setLabel(m_pieslice->label()); | |||
|
164 | } | |||
|
165 | ||||
|
166 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
|
167 | ||||
|
168 | XYLegendMarker::XYLegendMarker(QXYSeries *series, QLegend *legend) : LegendMarker(series,legend), | |||
|
169 | m_series(series) | |||
|
170 | { | |||
|
171 | QObject::connect(this, SIGNAL(selected()), series, SIGNAL(selected())); | |||
|
172 | QObject::connect(series,SIGNAL(updated()), this, SLOT(updated())); | |||
|
173 | updated(); | |||
|
174 | } | |||
|
175 | ||||
|
176 | void XYLegendMarker::updated() | |||
|
177 | { | |||
|
178 | setLabel(m_series->name()); | |||
|
179 | ||||
|
180 | if(m_series->type()== QSeries::SeriesTypeScatter) | |||
|
181 | { | |||
|
182 | setBrush(m_series->brush()); | |||
|
183 | ||||
192 | } |
|
184 | } | |
193 | case QSeries::SeriesTypeBar: |
|
185 | else { | |
194 | case QSeries::SeriesTypeStackedBar: |
|
186 | setBrush(QBrush(m_series->pen().color())); | |
195 | case QSeries::SeriesTypePercentBar: { |
|
|||
196 | setBrush(m_barset->brush()); |
|
|||
197 | setName(m_barset->name()); |
|
|||
198 | break; |
|
|||
199 | } |
|
|||
200 | case QSeries::SeriesTypePie: { |
|
|||
201 | setBrush(m_pieslice->brush()); |
|
|||
202 | setName(m_pieslice->label()); |
|
|||
203 | break; |
|
|||
204 | } |
|
|||
205 | default: { |
|
|||
206 | setBrush(Qt::NoBrush); |
|
|||
207 | break; |
|
|||
208 | } |
|
|||
209 | } |
|
187 | } | |
210 | } |
|
188 | } | |
211 |
|
189 | |||
212 | #include "moc_legendmarker_p.cpp" |
|
190 | #include "moc_legendmarker_p.cpp" | |
213 |
|
191 | |||
214 | QTCOMMERCIALCHART_END_NAMESPACE |
|
192 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,94 +1,128 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef LEGENDMARKER_P_H |
|
21 | #ifndef LEGENDMARKER_P_H | |
22 | #define LEGENDMARKER_P_H |
|
22 | #define LEGENDMARKER_P_H | |
23 |
|
23 | |||
24 | #include "qchartglobal.h" |
|
24 | #include "qchartglobal.h" | |
25 | #include <QGraphicsObject> |
|
25 | #include <QGraphicsObject> | |
26 | #include <QBrush> |
|
26 | #include <QBrush> | |
27 | #include <QPen> |
|
27 | #include <QPen> | |
28 | #include <QGraphicsSimpleTextItem> |
|
28 | #include <QGraphicsSimpleTextItem> | |
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 |
|
31 | |||
32 | class QSeries; |
|
32 | class QSeries; | |
|
33 | class QAreaSeries; | |||
|
34 | class QXYSeries; | |||
33 | class QBarSet; |
|
35 | class QBarSet; | |
|
36 | class QBarSeries; | |||
34 | class QPieSlice; |
|
37 | class QPieSlice; | |
|
38 | class QLegend; | |||
|
39 | class QPieSeries; | |||
35 |
|
40 | |||
36 | // TODO: split this to 3 different markers for series, barset and pieslice. Current implementation is easier to misuse... |
|
|||
37 | class LegendMarker : public QGraphicsObject |
|
41 | class LegendMarker : public QGraphicsObject | |
38 | { |
|
42 | { | |
39 | Q_OBJECT |
|
43 | Q_OBJECT | |
40 |
|
44 | |||
41 | public: |
|
45 | public: | |
42 |
LegendMarker(QSeries |
|
46 | explicit LegendMarker(QSeries* m_series,QLegend *parent); | |
43 | LegendMarker(QSeries *series, QBarSet *barset, QGraphicsItem *parent = 0); |
|
|||
44 | LegendMarker(QSeries *series, QPieSlice *pieslice, QGraphicsItem *parent = 0); |
|
|||
45 |
|
||||
46 | void setPos(qreal x, qreal y); |
|
|||
47 |
|
47 | |||
48 | void setPen(const QPen &pen); |
|
48 | void setPen(const QPen &pen); | |
49 | QPen pen() const; |
|
49 | QPen pen() const; | |
50 |
|
||||
51 | void setBrush(const QBrush &brush); |
|
50 | void setBrush(const QBrush &brush); | |
52 | QBrush brush() const; |
|
51 | QBrush brush() const; | |
53 |
|
52 | |||
54 |
void set |
|
53 | void setSize(const QSize& size); | |
55 | QString name() const; |
|
|||
56 |
|
54 | |||
57 | QSeries* series() const; |
|
55 | void setLabel(const QString label); | |
|
56 | QString label() const; | |||
|
57 | ||||
|
58 | QSeries* series() const { return m_series;} | |||
58 |
|
59 | |||
59 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); |
|
60 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); | |
60 |
|
61 | |||
61 | QRectF boundingRect() const; |
|
62 | QRectF boundingRect() const; | |
62 |
|
63 | |||
63 |
void |
|
64 | void updateLayout(); | |
64 |
|
65 | |||
65 | public: |
|
66 | protected: | |
66 | // From QGraphicsObject |
|
67 | // From QGraphicsObject | |
67 | void mousePressEvent(QGraphicsSceneMouseEvent *event); |
|
68 | void mousePressEvent(QGraphicsSceneMouseEvent *event); | |
68 |
|
69 | |||
69 | Q_SIGNALS: |
|
70 | Q_SIGNALS: | |
70 | void clicked(QSeries *series, Qt::MouseButton button); |
|
71 | void selected(); | |
71 | void clicked(QBarSet *barset, Qt::MouseButton button); |
|
|||
72 | void clicked(QPieSlice *pieslice, Qt::MouseButton button); |
|
|||
73 |
|
72 | |||
74 | public Q_SLOTS: |
|
73 | public Q_SLOTS: | |
75 |
void |
|
74 | virtual void updated() = 0; | |
76 |
|
75 | |||
77 | private: |
|
76 | protected: | |
78 | QPointF m_pos; |
|
77 | QSeries* m_series; | |
79 | QSize m_size; |
|
78 | QRectF m_markerRect; | |
80 | QRectF m_boundingRect; |
|
79 | QRectF m_boundingRect; | |
81 | QRectF m_markerBoundingRect; |
|
80 | QLegend* m_legend; | |
82 | QBrush m_brush; |
|
81 | QGraphicsSimpleTextItem *m_textItem; | |
83 | QPen m_pen; |
|
82 | QGraphicsRectItem *m_rectItem; | |
84 |
|
83 | |||
85 | QSeries *m_series; |
|
84 | }; | |
|
85 | ||||
|
86 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
|
87 | class XYLegendMarker : public LegendMarker | |||
|
88 | { | |||
|
89 | public: | |||
|
90 | XYLegendMarker(QXYSeries *series, QLegend *legend); | |||
|
91 | protected: | |||
|
92 | void updated(); | |||
|
93 | private: | |||
|
94 | QXYSeries *m_series; | |||
|
95 | }; | |||
|
96 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
|
97 | class AreaLegendMarker : public LegendMarker | |||
|
98 | { | |||
|
99 | public: | |||
|
100 | AreaLegendMarker(QAreaSeries *series, QLegend *legend); | |||
|
101 | protected: | |||
|
102 | void updated(); | |||
|
103 | private: | |||
|
104 | QAreaSeries *m_series; | |||
|
105 | }; | |||
|
106 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
|
107 | class BarLegendMarker : public LegendMarker | |||
|
108 | { | |||
|
109 | public: | |||
|
110 | BarLegendMarker(QBarSeries *barseires, QBarSet *barset,QLegend *legend); | |||
|
111 | protected: | |||
|
112 | void updated(); | |||
|
113 | private: | |||
86 | QBarSet *m_barset; |
|
114 | QBarSet *m_barset; | |
|
115 | }; | |||
|
116 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
|
117 | class PieLegendMarker : public LegendMarker | |||
|
118 | { | |||
|
119 | public: | |||
|
120 | PieLegendMarker(QPieSeries *pieSeries, QPieSlice *pieslice, QLegend *legend); | |||
|
121 | protected: | |||
|
122 | void updated(); | |||
|
123 | private: | |||
87 | QPieSlice *m_pieslice; |
|
124 | QPieSlice *m_pieslice; | |
88 |
|
||||
89 | QGraphicsSimpleTextItem *m_textItem; |
|
|||
90 |
|
||||
91 | }; |
|
125 | }; | |
92 |
|
126 | |||
93 | QTCOMMERCIALCHART_END_NAMESPACE |
|
127 | QTCOMMERCIALCHART_END_NAMESPACE | |
94 | #endif // LEGENDMARKER_P_H |
|
128 | #endif // LEGENDMARKER_P_H |
@@ -1,48 +1,48 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "legendscrollbutton_p.h" |
|
21 | #include "legendscrollbutton_p.h" | |
22 | #include "qlegend.h" |
|
22 | #include "qlegend.h" | |
23 | #include <QGraphicsSceneEvent> |
|
23 | #include <QGraphicsSceneEvent> | |
24 |
|
24 | |||
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
26 |
|
26 | |||
27 | LegendScrollButton::LegendScrollButton(ScrollButtonId id, QLegend *legend) |
|
27 | LegendScrollButton::LegendScrollButton(ScrollButtonId id, QLegend *legend) | |
28 | : QGraphicsPolygonItem(legend), |
|
28 | : QGraphicsPolygonItem(legend), | |
29 | m_id(id), |
|
29 | m_id(id), | |
30 | m_ledgend(legend) |
|
30 | m_ledgend(legend) | |
31 | { |
|
31 | { | |
32 | setAcceptedMouseButtons(Qt::LeftButton); |
|
32 | setAcceptedMouseButtons(Qt::LeftButton); | |
33 | } |
|
33 | } | |
34 |
|
34 | |||
35 | LegendScrollButton::ScrollButtonId LegendScrollButton::id() |
|
35 | LegendScrollButton::ScrollButtonId LegendScrollButton::id() | |
36 | { |
|
36 | { | |
37 | return m_id; |
|
37 | return m_id; | |
38 | } |
|
38 | } | |
39 |
|
39 | |||
40 | void LegendScrollButton::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
40 | void LegendScrollButton::mousePressEvent(QGraphicsSceneMouseEvent *event) | |
41 | { |
|
41 | { | |
42 | Q_UNUSED(event); |
|
42 | Q_UNUSED(event); | |
43 | m_ledgend->scrollButtonClicked(this); |
|
43 | //m_ledgend->scrollButtonClicked(this); | |
44 | } |
|
44 | } | |
45 |
|
45 | |||
46 |
|
46 | |||
47 | QTCOMMERCIALCHART_END_NAMESPACE |
|
47 | QTCOMMERCIALCHART_END_NAMESPACE | |
48 |
|
48 |
@@ -1,87 +1,88 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef QPIESLICE_H |
|
21 | #ifndef QPIESLICE_H | |
22 | #define QPIESLICE_H |
|
22 | #define QPIESLICE_H | |
23 |
|
23 | |||
24 | #include <qchartglobal.h> |
|
24 | #include <qchartglobal.h> | |
25 | #include <QObject> |
|
25 | #include <QObject> | |
26 | #include <QPen> |
|
26 | #include <QPen> | |
27 | #include <QBrush> |
|
27 | #include <QBrush> | |
28 | #include <QFont> |
|
28 | #include <QFont> | |
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 | class PieSliceData; |
|
31 | class PieSliceData; | |
32 |
|
32 | |||
33 | class QTCOMMERCIALCHART_EXPORT QPieSlice : public QObject |
|
33 | class QTCOMMERCIALCHART_EXPORT QPieSlice : public QObject | |
34 | { |
|
34 | { | |
35 | Q_OBJECT |
|
35 | Q_OBJECT | |
36 | Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY changed) |
|
36 | Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY changed) | |
37 | Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY changed) |
|
37 | Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY changed) | |
38 |
|
38 | |||
39 | public: |
|
39 | public: | |
40 | QPieSlice(QObject *parent = 0); |
|
40 | QPieSlice(QObject *parent = 0); | |
41 | QPieSlice(qreal value, QString label, QObject *parent = 0); |
|
41 | QPieSlice(qreal value, QString label, QObject *parent = 0); | |
42 | virtual ~QPieSlice(); |
|
42 | virtual ~QPieSlice(); | |
43 |
|
43 | |||
44 | // data |
|
44 | // data | |
45 | void setValue(qreal value); |
|
45 | void setValue(qreal value); | |
46 | qreal value() const; |
|
46 | qreal value() const; | |
47 | void setLabel(QString label); |
|
47 | void setLabel(QString label); | |
48 | QString label() const; |
|
48 | QString label() const; | |
49 | void setLabelVisible(bool visible = true); |
|
49 | void setLabelVisible(bool visible = true); | |
50 | bool isLabelVisible() const; |
|
50 | bool isLabelVisible() const; | |
51 | void setExploded(bool exploded = true); |
|
51 | void setExploded(bool exploded = true); | |
52 | bool isExploded() const; |
|
52 | bool isExploded() const; | |
53 |
|
53 | |||
54 | // generated data |
|
54 | // generated data | |
55 | qreal percentage() const; |
|
55 | qreal percentage() const; | |
56 | qreal startAngle() const; |
|
56 | qreal startAngle() const; | |
57 | qreal endAngle() const; |
|
57 | qreal endAngle() const; | |
58 |
|
58 | |||
59 | // customization |
|
59 | // customization | |
60 | void setPen(const QPen &pen); |
|
60 | void setPen(const QPen &pen); | |
61 | QPen pen() const; |
|
61 | QPen pen() const; | |
62 | void setBrush(const QBrush &brush); |
|
62 | void setBrush(const QBrush &brush); | |
63 | QBrush brush() const; |
|
63 | QBrush brush() const; | |
64 | void setLabelPen(const QPen &pen); |
|
64 | void setLabelPen(const QPen &pen); | |
65 | QPen labelPen() const; |
|
65 | QPen labelPen() const; | |
66 | void setLabelFont(const QFont &font); |
|
66 | void setLabelFont(const QFont &font); | |
67 | QFont labelFont() const; |
|
67 | QFont labelFont() const; | |
68 | void setLabelArmLengthFactor(qreal factor); |
|
68 | void setLabelArmLengthFactor(qreal factor); | |
69 | qreal labelArmLengthFactor() const; |
|
69 | qreal labelArmLengthFactor() const; | |
70 | void setExplodeDistanceFactor(qreal factor); |
|
70 | void setExplodeDistanceFactor(qreal factor); | |
71 | qreal explodeDistanceFactor() const; |
|
71 | qreal explodeDistanceFactor() const; | |
72 |
|
72 | |||
73 | Q_SIGNALS: |
|
73 | Q_SIGNALS: | |
74 | void clicked(Qt::MouseButtons buttons); |
|
74 | void clicked(Qt::MouseButtons buttons); | |
75 | void hoverEnter(); |
|
75 | void hoverEnter(); | |
76 | void hoverLeave(); |
|
76 | void hoverLeave(); | |
77 | void changed(); |
|
77 | void changed(); | |
|
78 | void selected(); | |||
78 |
|
79 | |||
79 | private: |
|
80 | private: | |
80 | friend class PieSliceData; |
|
81 | friend class PieSliceData; | |
81 | PieSliceData * const d; |
|
82 | PieSliceData * const d; | |
82 | Q_DISABLE_COPY(QPieSlice) |
|
83 | Q_DISABLE_COPY(QPieSlice) | |
83 | }; |
|
84 | }; | |
84 |
|
85 | |||
85 | QTCOMMERCIALCHART_END_NAMESPACE |
|
86 | QTCOMMERCIALCHART_END_NAMESPACE | |
86 |
|
87 | |||
87 | #endif // QPIESLICE_H |
|
88 | #endif // QPIESLICE_H |
@@ -1,500 +1,351 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qchart.h" |
|
21 | #include "qchart.h" | |
22 | #include "qchart_p.h" |
|
22 | #include "qchart_p.h" | |
23 | #include <QGraphicsScene> |
|
23 | #include <QGraphicsScene> | |
24 | #include <QGraphicsSceneResizeEvent> |
|
24 | #include <QGraphicsSceneResizeEvent> | |
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
27 | |||
28 | /*! |
|
28 | /*! | |
29 | \enum QChart::ChartTheme |
|
29 | \enum QChart::ChartTheme | |
30 |
|
30 | |||
31 | This enum describes the theme used by the chart. |
|
31 | This enum describes the theme used by the chart. | |
32 |
|
32 | |||
33 | \value ChartThemeLight The default theme |
|
33 | \value ChartThemeLight The default theme | |
34 | \value ChartThemeBlueCerulean |
|
34 | \value ChartThemeBlueCerulean | |
35 | \value ChartThemeDark |
|
35 | \value ChartThemeDark | |
36 | \value ChartThemeBrownSand |
|
36 | \value ChartThemeBrownSand | |
37 | \value ChartThemeBlueNcs |
|
37 | \value ChartThemeBlueNcs | |
38 | \value ChartThemeHighContrast |
|
38 | \value ChartThemeHighContrast | |
39 | \value ChartThemeBlueIcy |
|
39 | \value ChartThemeBlueIcy | |
40 | \value ChartThemeCount Not really a theme; the total count of themes. |
|
40 | \value ChartThemeCount Not really a theme; the total count of themes. | |
41 | */ |
|
41 | */ | |
42 |
|
42 | |||
43 | /*! |
|
43 | /*! | |
44 | \enum QChart::AnimationOption |
|
44 | \enum QChart::AnimationOption | |
45 |
|
45 | |||
46 | For enabling/disabling animations. Defaults to NoAnimation. |
|
46 | For enabling/disabling animations. Defaults to NoAnimation. | |
47 |
|
47 | |||
48 | \value NoAnimation |
|
48 | \value NoAnimation | |
49 | \value GridAxisAnimations |
|
49 | \value GridAxisAnimations | |
50 | \value SeriesAnimations |
|
50 | \value SeriesAnimations | |
51 | \value AllAnimations |
|
51 | \value AllAnimations | |
52 | */ |
|
52 | */ | |
53 |
|
53 | |||
54 | /*! |
|
54 | /*! | |
55 | \class QChart |
|
55 | \class QChart | |
56 | \brief QtCommercial chart API. |
|
56 | \brief QtCommercial chart API. | |
57 |
|
57 | |||
58 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical |
|
58 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical | |
59 | representation of different types of QChartSeries and other chart related objects like |
|
59 | representation of different types of QChartSeries and other chart related objects like | |
60 | QChartAxis and QChartLegend. If you simply want to show a chart in a layout, you can use the |
|
60 | QChartAxis and QChartLegend. If you simply want to show a chart in a layout, you can use the | |
61 | convenience class QChartView instead of QChart. |
|
61 | convenience class QChartView instead of QChart. | |
62 | \sa QChartView |
|
62 | \sa QChartView | |
63 | */ |
|
63 | */ | |
64 |
|
64 | |||
65 | /*! |
|
65 | /*! | |
66 | Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. |
|
66 | Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. | |
67 | */ |
|
67 | */ | |
68 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), |
|
68 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), | |
69 |
d_ptr(new QChartPrivate( |
|
69 | d_ptr(new QChartPrivate()) | |
70 | { |
|
70 | { | |
71 | //setMinimumSize(200,200); |
|
|||
72 | d_ptr->m_legend = new QLegend(this); |
|
71 | d_ptr->m_legend = new QLegend(this); | |
73 | d_ptr->m_dataset = new ChartDataSet(this); |
|
72 | d_ptr->m_dataset = new ChartDataSet(this); | |
74 | d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset); |
|
73 | d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset); | |
75 | setMinimumSize(d_ptr->m_padding.left() * 3, d_ptr->m_padding.top() * 3); |
|
74 | d_ptr->m_presenter->setTheme(QChart::ChartThemeDefault,false); | |
|
75 | //TODO:fix me setMinimumSize(d_ptr->m_padding.left() * 3, d_ptr->m_padding.top() * 3); | |||
76 | connect(d_ptr->m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),d_ptr->m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*))); |
|
76 | connect(d_ptr->m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),d_ptr->m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*))); | |
77 | connect(d_ptr->m_dataset,SIGNAL(seriesRemoved(QSeries*)),d_ptr->m_legend,SLOT(handleSeriesRemoved(QSeries*))); |
|
77 | connect(d_ptr->m_dataset,SIGNAL(seriesRemoved(QSeries*)),d_ptr->m_legend,SLOT(handleSeriesRemoved(QSeries*))); | |
78 | } |
|
78 | } | |
79 |
|
79 | |||
80 | /*! |
|
80 | /*! | |
81 | Destroys the object and it's children, like QChartSeries and QChartAxis object added to it. |
|
81 | Destroys the object and it's children, like QChartSeries and QChartAxis object added to it. | |
82 | */ |
|
82 | */ | |
83 | QChart::~QChart() |
|
83 | QChart::~QChart() | |
84 | { |
|
84 | { | |
85 | //delete first presenter , since this is a root of all the graphical items |
|
85 | //delete first presenter , since this is a root of all the graphical items | |
86 | delete d_ptr->m_presenter; |
|
86 | delete d_ptr->m_presenter; | |
87 | d_ptr->m_presenter=0; |
|
87 | d_ptr->m_presenter=0; | |
88 | } |
|
88 | } | |
89 |
|
89 | |||
90 | /*! |
|
90 | /*! | |
91 | Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects. |
|
91 | Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects. | |
92 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and |
|
92 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and | |
93 | the y axis). |
|
93 | the y axis). | |
94 | */ |
|
94 | */ | |
95 | void QChart::addSeries(QSeries* series, QChartAxis* axisY) |
|
95 | void QChart::addSeries(QSeries* series, QChartAxis* axisY) | |
96 | { |
|
96 | { | |
97 | d_ptr->m_dataset->addSeries(series, axisY); |
|
97 | d_ptr->m_dataset->addSeries(series, axisY); | |
98 | } |
|
98 | } | |
99 |
|
99 | |||
100 | /*! |
|
100 | /*! | |
101 | Removes the \a series specified in a perameter from the QChartView. |
|
101 | Removes the \a series specified in a perameter from the QChartView. | |
102 | It releses its ownership of the specified QChartSeries object. |
|
102 | It releses its ownership of the specified QChartSeries object. | |
103 | It does not delete the pointed QChartSeries data object |
|
103 | It does not delete the pointed QChartSeries data object | |
104 | \sa addSeries(), removeAllSeries() |
|
104 | \sa addSeries(), removeAllSeries() | |
105 | */ |
|
105 | */ | |
106 | void QChart::removeSeries(QSeries* series) |
|
106 | void QChart::removeSeries(QSeries* series) | |
107 | { |
|
107 | { | |
108 | d_ptr->m_dataset->removeSeries(series); |
|
108 | d_ptr->m_dataset->removeSeries(series); | |
109 | } |
|
109 | } | |
110 |
|
110 | |||
111 | /*! |
|
111 | /*! | |
112 | Removes all the QChartSeries that have been added to the QChartView |
|
112 | Removes all the QChartSeries that have been added to the QChartView | |
113 | It also deletes the pointed QChartSeries data objects |
|
113 | It also deletes the pointed QChartSeries data objects | |
114 | \sa addSeries(), removeSeries() |
|
114 | \sa addSeries(), removeSeries() | |
115 | */ |
|
115 | */ | |
116 | void QChart::removeAllSeries() |
|
116 | void QChart::removeAllSeries() | |
117 | { |
|
117 | { | |
118 | d_ptr->m_dataset->removeAllSeries(); |
|
118 | d_ptr->m_dataset->removeAllSeries(); | |
119 | } |
|
119 | } | |
120 |
|
120 | |||
121 | /*! |
|
121 | /*! | |
122 | Sets the \a brush that is used for painting the background of the chart area. |
|
122 | Sets the \a brush that is used for painting the background of the chart area. | |
123 | */ |
|
123 | */ | |
124 | void QChart::setBackgroundBrush(const QBrush& brush) |
|
124 | void QChart::setBackgroundBrush(const QBrush& brush) | |
125 | { |
|
125 | { | |
126 | d_ptr->createChartBackgroundItem(); |
|
126 | d_ptr->m_presenter->createChartBackgroundItem(); | |
127 | d_ptr->m_backgroundItem->setBrush(brush); |
|
127 | d_ptr->m_presenter->m_backgroundItem->setBrush(brush); | |
128 | d_ptr->m_backgroundItem->update(); |
|
128 | d_ptr->m_presenter->m_backgroundItem->update(); | |
129 | } |
|
129 | } | |
130 |
|
130 | |||
131 | QBrush QChart::backgroundBrush() const |
|
131 | QBrush QChart::backgroundBrush() const | |
132 | { |
|
132 | { | |
133 | if (!d_ptr->m_backgroundItem) return QBrush(); |
|
133 | if (!d_ptr->m_presenter->m_backgroundItem) return QBrush(); | |
134 | return (d_ptr->m_backgroundItem)->brush(); |
|
134 | return (d_ptr->m_presenter->m_backgroundItem)->brush(); | |
135 | } |
|
135 | } | |
136 |
|
136 | |||
137 | /*! |
|
137 | /*! | |
138 | Sets the \a pen that is used for painting the background of the chart area. |
|
138 | Sets the \a pen that is used for painting the background of the chart area. | |
139 | */ |
|
139 | */ | |
140 | void QChart::setBackgroundPen(const QPen& pen) |
|
140 | void QChart::setBackgroundPen(const QPen& pen) | |
141 | { |
|
141 | { | |
142 | d_ptr->createChartBackgroundItem(); |
|
142 | d_ptr->m_presenter->createChartBackgroundItem(); | |
143 | d_ptr->m_backgroundItem->setPen(pen); |
|
143 | d_ptr->m_presenter->m_backgroundItem->setPen(pen); | |
144 | d_ptr->m_backgroundItem->update(); |
|
144 | d_ptr->m_presenter->m_backgroundItem->update(); | |
145 | } |
|
145 | } | |
146 |
|
146 | |||
147 | QPen QChart::backgroundPen() const |
|
147 | QPen QChart::backgroundPen() const | |
148 | { |
|
148 | { | |
149 | if (!d_ptr->m_backgroundItem) return QPen(); |
|
149 | if (!d_ptr->m_presenter->m_backgroundItem) return QPen(); | |
150 | return d_ptr->m_backgroundItem->pen(); |
|
150 | return d_ptr->m_presenter->m_backgroundItem->pen(); | |
151 | } |
|
151 | } | |
152 |
|
152 | |||
153 | /*! |
|
153 | /*! | |
154 | Sets the chart \a title. The description text that is drawn above the chart. |
|
154 | Sets the chart \a title. The description text that is drawn above the chart. | |
155 | */ |
|
155 | */ | |
156 | void QChart::setTitle(const QString& title) |
|
156 | void QChart::setTitle(const QString& title) | |
157 | { |
|
157 | { | |
158 | d_ptr->createChartTitleItem(); |
|
158 | d_ptr->m_presenter->createChartTitleItem(); | |
159 | d_ptr->m_titleItem->setText(title); |
|
159 | d_ptr->m_presenter->m_titleItem->setText(title); | |
160 | d_ptr->updateLayout(); |
|
160 | d_ptr->m_presenter->updateLayout(); | |
161 | } |
|
161 | } | |
162 |
|
162 | |||
163 | /*! |
|
163 | /*! | |
164 | Returns the chart title. The description text that is drawn above the chart. |
|
164 | Returns the chart title. The description text that is drawn above the chart. | |
165 | */ |
|
165 | */ | |
166 | QString QChart::title() const |
|
166 | QString QChart::title() const | |
167 | { |
|
167 | { | |
168 | if (d_ptr->m_titleItem) |
|
168 | if (d_ptr->m_presenter->m_titleItem) | |
169 | return d_ptr->m_titleItem->text(); |
|
169 | return d_ptr->m_presenter->m_titleItem->text(); | |
170 | else |
|
170 | else | |
171 | return QString(); |
|
171 | return QString(); | |
172 | } |
|
172 | } | |
173 |
|
173 | |||
174 | /*! |
|
174 | /*! | |
175 | Sets the \a font that is used for rendering the description text that is rendered above the chart. |
|
175 | Sets the \a font that is used for rendering the description text that is rendered above the chart. | |
176 | */ |
|
176 | */ | |
177 | void QChart::setTitleFont(const QFont& font) |
|
177 | void QChart::setTitleFont(const QFont& font) | |
178 | { |
|
178 | { | |
179 | d_ptr->createChartTitleItem(); |
|
179 | d_ptr->m_presenter->createChartTitleItem(); | |
180 | d_ptr->m_titleItem->setFont(font); |
|
180 | d_ptr->m_presenter->m_titleItem->setFont(font); | |
181 | d_ptr->updateLayout(); |
|
181 | d_ptr->m_presenter->updateLayout(); | |
182 | } |
|
182 | } | |
183 |
|
183 | |||
184 | /*! |
|
184 | /*! | |
185 | Sets the \a brush used for rendering the title text. |
|
185 | Sets the \a brush used for rendering the title text. | |
186 | */ |
|
186 | */ | |
187 | void QChart::setTitleBrush(const QBrush &brush) |
|
187 | void QChart::setTitleBrush(const QBrush &brush) | |
188 | { |
|
188 | { | |
189 | d_ptr->createChartTitleItem(); |
|
189 | d_ptr->m_presenter->createChartTitleItem(); | |
190 | d_ptr->m_titleItem->setBrush(brush); |
|
190 | d_ptr->m_presenter->m_titleItem->setBrush(brush); | |
191 | d_ptr->updateLayout(); |
|
191 | d_ptr->m_presenter->updateLayout(); | |
192 | } |
|
192 | } | |
193 |
|
193 | |||
194 | /*! |
|
194 | /*! | |
195 | Returns the brush used for rendering the title text. |
|
195 | Returns the brush used for rendering the title text. | |
196 | */ |
|
196 | */ | |
197 | QBrush QChart::titleBrush() const |
|
197 | QBrush QChart::titleBrush() const | |
198 | { |
|
198 | { | |
199 | if (!d_ptr->m_titleItem) return QBrush(); |
|
199 | if (!d_ptr->m_presenter->m_titleItem) return QBrush(); | |
200 | return d_ptr->m_titleItem->brush(); |
|
200 | return d_ptr->m_presenter->m_titleItem->brush(); | |
201 | } |
|
201 | } | |
202 |
|
202 | |||
203 | /*! |
|
203 | /*! | |
204 | Sets the \a theme used by the chart for rendering the graphical representation of the data |
|
204 | Sets the \a theme used by the chart for rendering the graphical representation of the data | |
205 | \sa ChartTheme, chartTheme() |
|
205 | \sa ChartTheme, chartTheme() | |
206 | */ |
|
206 | */ | |
207 | void QChart::setTheme(QChart::ChartTheme theme) |
|
207 | void QChart::setTheme(QChart::ChartTheme theme) | |
208 | { |
|
208 | { | |
209 | d_ptr->m_presenter->setTheme(theme); |
|
209 | d_ptr->m_presenter->setTheme(theme); | |
210 | } |
|
210 | } | |
211 |
|
211 | |||
212 | /*! |
|
212 | /*! | |
213 | Returns the theme enum used by the chart. |
|
213 | Returns the theme enum used by the chart. | |
214 | \sa ChartTheme, setChartTheme() |
|
214 | \sa ChartTheme, setChartTheme() | |
215 | */ |
|
215 | */ | |
216 | QChart::ChartTheme QChart::theme() const |
|
216 | QChart::ChartTheme QChart::theme() const | |
217 | { |
|
217 | { | |
218 | return d_ptr->m_presenter->theme(); |
|
218 | return d_ptr->m_presenter->theme(); | |
219 | } |
|
219 | } | |
220 |
|
220 | |||
221 | /*! |
|
221 | /*! | |
222 | Zooms in the view by a factor of 2 |
|
222 | Zooms in the view by a factor of 2 | |
223 | */ |
|
223 | */ | |
224 | void QChart::zoomIn() |
|
224 | void QChart::zoomIn() | |
225 | { |
|
225 | { | |
226 | d_ptr->m_presenter->zoomIn(); |
|
226 | d_ptr->m_presenter->zoomIn(); | |
227 | } |
|
227 | } | |
228 |
|
228 | |||
229 | /*! |
|
229 | /*! | |
230 | Zooms in the view to a maximum level at which \a rect is still fully visible. |
|
230 | Zooms in the view to a maximum level at which \a rect is still fully visible. | |
231 | */ |
|
231 | */ | |
232 | void QChart::zoomIn(const QRectF& rect) |
|
232 | void QChart::zoomIn(const QRectF& rect) | |
233 | { |
|
233 | { | |
234 | if (!rect.isValid()) return; |
|
234 | if (!rect.isValid()) return; | |
235 | d_ptr->m_presenter->zoomIn(rect); |
|
235 | d_ptr->m_presenter->zoomIn(rect); | |
236 | } |
|
236 | } | |
237 |
|
237 | |||
238 | /*! |
|
238 | /*! | |
239 | Restores the view zoom level to the previous one. |
|
239 | Restores the view zoom level to the previous one. | |
240 | */ |
|
240 | */ | |
241 | void QChart::zoomOut() |
|
241 | void QChart::zoomOut() | |
242 | { |
|
242 | { | |
243 | d_ptr->m_presenter->zoomOut(); |
|
243 | d_ptr->m_presenter->zoomOut(); | |
244 | } |
|
244 | } | |
245 |
|
245 | |||
246 | /*! |
|
246 | /*! | |
247 | Returns the pointer to the x axis object of the chart |
|
247 | Returns the pointer to the x axis object of the chart | |
248 | */ |
|
248 | */ | |
249 | QChartAxis* QChart::axisX() const |
|
249 | QChartAxis* QChart::axisX() const | |
250 | { |
|
250 | { | |
251 | return d_ptr->m_dataset->axisX(); |
|
251 | return d_ptr->m_dataset->axisX(); | |
252 | } |
|
252 | } | |
253 |
|
253 | |||
254 | /*! |
|
254 | /*! | |
255 | Returns the pointer to the y axis object of the chart |
|
255 | Returns the pointer to the y axis object of the chart | |
256 | */ |
|
256 | */ | |
257 | QChartAxis* QChart::axisY() const |
|
257 | QChartAxis* QChart::axisY() const | |
258 | { |
|
258 | { | |
259 | return d_ptr->m_dataset->axisY(); |
|
259 | return d_ptr->m_dataset->axisY(); | |
260 | } |
|
260 | } | |
261 |
|
261 | |||
262 | /*! |
|
262 | /*! | |
263 | Returns the legend object of the chart. Ownership stays in chart. |
|
263 | Returns the legend object of the chart. Ownership stays in chart. | |
264 | */ |
|
264 | */ | |
265 | QLegend* QChart::legend() const |
|
265 | QLegend* QChart::legend() const | |
266 | { |
|
266 | { | |
267 | return d_ptr->m_legend; |
|
267 | return d_ptr->m_legend; | |
268 | } |
|
268 | } | |
269 |
|
269 | |||
270 |
QRect QChart:: |
|
270 | QRect QChart::margins() const | |
271 | { |
|
271 | { | |
272 |
return d_ptr->m_p |
|
272 | return d_ptr->m_presenter->margins(); | |
273 | } |
|
273 | } | |
274 |
|
274 | |||
275 |
|
275 | |||
276 | /*! |
|
276 | /*! | |
277 | Resizes and updates the chart area using the \a event data |
|
277 | Resizes and updates the chart area using the \a event data | |
278 | */ |
|
278 | */ | |
279 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) |
|
279 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) | |
280 | { |
|
280 | { | |
281 | d_ptr->m_rect = QRectF(QPoint(0,0),event->newSize()); |
|
281 | d_ptr->m_rect = QRectF(QPoint(0,0),event->newSize()); | |
282 | d_ptr->updateLayout(); |
|
|||
283 | QGraphicsWidget::resizeEvent(event); |
|
282 | QGraphicsWidget::resizeEvent(event); | |
284 | update(); |
|
283 | d_ptr->m_presenter->setGeometry(d_ptr->m_rect); | |
285 | } |
|
284 | } | |
286 |
|
285 | |||
287 | /*! |
|
286 | /*! | |
288 | Sets animation \a options for the chart |
|
287 | Sets animation \a options for the chart | |
289 | */ |
|
288 | */ | |
290 | void QChart::setAnimationOptions(AnimationOptions options) |
|
289 | void QChart::setAnimationOptions(AnimationOptions options) | |
291 | { |
|
290 | { | |
292 | d_ptr->m_presenter->setAnimationOptions(options); |
|
291 | d_ptr->m_presenter->setAnimationOptions(options); | |
293 | } |
|
292 | } | |
294 |
|
293 | |||
295 | /*! |
|
294 | /*! | |
296 | Returns animation options for the chart |
|
295 | Returns animation options for the chart | |
297 | */ |
|
296 | */ | |
298 | QChart::AnimationOptions QChart::animationOptions() const |
|
297 | QChart::AnimationOptions QChart::animationOptions() const | |
299 | { |
|
298 | { | |
300 | return d_ptr->m_presenter->animationOptions(); |
|
299 | return d_ptr->m_presenter->animationOptions(); | |
301 | } |
|
300 | } | |
302 |
|
301 | |||
303 | void QChart::scrollLeft() |
|
302 | void QChart::scrollLeft() | |
304 | { |
|
303 | { | |
305 |
d_ptr->m_presenter->scroll(-d_ptr->m_presenter-> |
|
304 | d_ptr->m_presenter->scroll(-d_ptr->m_presenter->chartGeometry().width()/(axisX()->ticksCount()-1),0); | |
306 | } |
|
305 | } | |
307 |
|
306 | |||
308 | void QChart::scrollRight() |
|
307 | void QChart::scrollRight() | |
309 | { |
|
308 | { | |
310 |
d_ptr->m_presenter->scroll(d_ptr->m_presenter-> |
|
309 | d_ptr->m_presenter->scroll(d_ptr->m_presenter->chartGeometry().width()/(axisX()->ticksCount()-1),0); | |
311 | } |
|
310 | } | |
312 |
|
311 | |||
313 | void QChart::scrollUp() |
|
312 | void QChart::scrollUp() | |
314 | { |
|
313 | { | |
315 |
d_ptr->m_presenter->scroll(0,d_ptr->m_presenter-> |
|
314 | d_ptr->m_presenter->scroll(0,d_ptr->m_presenter->chartGeometry().width()/(axisY()->ticksCount()-1)); | |
316 | } |
|
315 | } | |
317 |
|
316 | |||
318 | void QChart::scrollDown() |
|
317 | void QChart::scrollDown() | |
319 | { |
|
318 | { | |
320 |
d_ptr->m_presenter->scroll(0,-d_ptr->m_presenter-> |
|
319 | d_ptr->m_presenter->scroll(0,-d_ptr->m_presenter->chartGeometry().width()/(axisY()->ticksCount()-1)); | |
321 | } |
|
320 | } | |
322 |
|
321 | |||
323 | void QChart::setBackgroundVisible(bool visible) |
|
322 | void QChart::setBackgroundVisible(bool visible) | |
324 | { |
|
323 | { | |
325 | d_ptr->createChartBackgroundItem(); |
|
324 | d_ptr->m_presenter->createChartBackgroundItem(); | |
326 | d_ptr->m_backgroundItem->setVisible(visible); |
|
325 | d_ptr->m_presenter->m_backgroundItem->setVisible(visible); | |
327 | } |
|
326 | } | |
328 |
|
327 | |||
329 | bool QChart::isBackgroundVisible() const |
|
328 | bool QChart::isBackgroundVisible() const | |
330 | { |
|
329 | { | |
331 | if (!d_ptr->m_backgroundItem) return false; |
|
330 | if (!d_ptr->m_presenter->m_backgroundItem) return false; | |
332 | return d_ptr->m_backgroundItem->isVisible(); |
|
331 | return d_ptr->m_presenter->m_backgroundItem->isVisible(); | |
333 | } |
|
332 | } | |
334 |
|
333 | |||
335 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
334 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
336 |
|
335 | |||
337 |
QChartPrivate::QChartPrivate( |
|
336 | QChartPrivate::QChartPrivate(): | |
338 | q_ptr(parent), |
|
|||
339 | m_backgroundItem(0), |
|
|||
340 | m_titleItem(0), |
|
|||
341 | m_legend(0), |
|
337 | m_legend(0), | |
342 | m_dataset(0), |
|
338 | m_dataset(0), | |
343 |
m_presenter(0) |
|
339 | m_presenter(0) | |
344 | m_padding(QRect(50,50,0,0)) |
|
|||
345 | { |
|
340 | { | |
346 |
|
341 | |||
347 | } |
|
342 | } | |
348 |
|
343 | |||
349 | QChartPrivate::~QChartPrivate() |
|
344 | QChartPrivate::~QChartPrivate() | |
350 | { |
|
345 | { | |
351 |
|
346 | |||
352 | } |
|
347 | } | |
353 |
|
348 | |||
354 | void QChartPrivate::createChartBackgroundItem() |
|
|||
355 | { |
|
|||
356 | if (!m_backgroundItem) { |
|
|||
357 | m_backgroundItem = new ChartBackground(q_ptr); |
|
|||
358 | m_backgroundItem->setPen(Qt::NoPen); |
|
|||
359 | m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue); |
|
|||
360 | } |
|
|||
361 | } |
|
|||
362 |
|
||||
363 | void QChartPrivate::createChartTitleItem() |
|
|||
364 | { |
|
|||
365 | if (!m_titleItem) { |
|
|||
366 | m_titleItem = new QGraphicsSimpleTextItem(q_ptr); |
|
|||
367 | m_titleItem->setZValue(ChartPresenter::BackgroundZValue); |
|
|||
368 | } |
|
|||
369 | } |
|
|||
370 |
|
||||
371 | void QChartPrivate::updateLegendLayout() |
|
|||
372 | { |
|
|||
373 | //int legendPadding = m_chart->legend()->padding(); |
|
|||
374 | int legendPadding = 30; |
|
|||
375 | QRectF rect = m_rect; |
|
|||
376 |
|
||||
377 | if ((m_legend->attachedToChart()) && (m_legend->isVisible())) { |
|
|||
378 |
|
||||
379 | // Reserve some space for legend |
|
|||
380 | switch (m_legend->alignment()) { |
|
|||
381 | case QLegend::AlignmentTop: { |
|
|||
382 | rect.adjust(m_padding.left(), |
|
|||
383 | m_padding.top() + legendPadding, |
|
|||
384 | -m_padding.right(), |
|
|||
385 | -m_padding.bottom()); |
|
|||
386 | break; |
|
|||
387 | } |
|
|||
388 | case QLegend::AlignmentBottom: { |
|
|||
389 | rect.adjust(m_padding.left(), |
|
|||
390 | m_padding.top(), |
|
|||
391 | -m_padding.right(), |
|
|||
392 | -m_padding.bottom() - legendPadding); |
|
|||
393 | break; |
|
|||
394 | } |
|
|||
395 | case QLegend::AlignmentLeft: { |
|
|||
396 | rect.adjust(m_padding.left() + legendPadding, |
|
|||
397 | m_padding.top(), |
|
|||
398 | -m_padding.right(), |
|
|||
399 | -m_padding.bottom()); |
|
|||
400 | break; |
|
|||
401 | } |
|
|||
402 | case QLegend::AlignmentRight: { |
|
|||
403 | rect.adjust(m_padding.left(), |
|
|||
404 | m_padding.top(), |
|
|||
405 | -m_padding.right() - legendPadding, |
|
|||
406 | -m_padding.bottom()); |
|
|||
407 | break; |
|
|||
408 | } |
|
|||
409 | default: { |
|
|||
410 | rect.adjust(m_padding.left(), |
|
|||
411 | m_padding.top(), |
|
|||
412 | -m_padding.right(), |
|
|||
413 | -m_padding.bottom()); |
|
|||
414 | break; |
|
|||
415 | } |
|
|||
416 | } |
|
|||
417 | } else { |
|
|||
418 |
|
||||
419 | rect.adjust(m_padding.left(), |
|
|||
420 | m_padding.top(), |
|
|||
421 | -m_padding.right(), |
|
|||
422 | -m_padding.bottom()); |
|
|||
423 | } |
|
|||
424 |
|
||||
425 | QRectF plotRect = m_rect.adjusted(m_padding.left() |
|
|||
426 | ,m_padding.top() |
|
|||
427 | ,-m_padding.right() |
|
|||
428 | ,-m_padding.bottom()); |
|
|||
429 | QRectF legendRect; |
|
|||
430 |
|
||||
431 | int padding = 0; // TODO: fix this |
|
|||
432 | switch (m_legend->alignment()) |
|
|||
433 | { |
|
|||
434 | case QLegend::AlignmentTop: { |
|
|||
435 | legendRect = m_rect.adjusted(0,padding,0,-padding - plotRect.height()); |
|
|||
436 | break; |
|
|||
437 | } |
|
|||
438 | case QLegend::AlignmentBottom: { |
|
|||
439 | legendRect = m_rect.adjusted(padding,padding + plotRect.height(),-padding,0); |
|
|||
440 | break; |
|
|||
441 | } |
|
|||
442 | case QLegend::AlignmentLeft: { |
|
|||
443 | legendRect = m_rect.adjusted(0,padding,-padding - plotRect.width(),-padding); |
|
|||
444 | break; |
|
|||
445 | } |
|
|||
446 | case QLegend::AlignmentRight: { |
|
|||
447 | legendRect = m_rect.adjusted(padding + plotRect.width(),padding,0,-padding); |
|
|||
448 | break; |
|
|||
449 | } |
|
|||
450 | default: { |
|
|||
451 | legendRect = plotRect; |
|
|||
452 | break; |
|
|||
453 | } |
|
|||
454 | } |
|
|||
455 |
|
||||
456 | m_legend->setMaximumSize(legendRect.size()); |
|
|||
457 |
|
||||
458 | qreal width = legendRect.width() - m_legend->size().width(); |
|
|||
459 | qreal height = legendRect.height() - m_legend->size().height(); |
|
|||
460 |
|
||||
461 | QPointF pos = legendRect.topLeft(); |
|
|||
462 | if (width > 0) { |
|
|||
463 | pos.setX(pos.x() + width/2); |
|
|||
464 | } |
|
|||
465 | if (height > 0) { |
|
|||
466 | pos.setY(pos.y() + height/2); |
|
|||
467 | } |
|
|||
468 |
|
||||
469 | m_legend->setPos(pos); |
|
|||
470 | } |
|
|||
471 |
|
||||
472 | void QChartPrivate::updateLayout() |
|
|||
473 | { |
|
|||
474 | if (!m_rect.isValid()) return; |
|
|||
475 |
|
||||
476 | int padding = m_padding.top(); |
|
|||
477 | int backgroundPadding = m_presenter->backgroundPadding(); |
|
|||
478 |
|
||||
479 | // recalculate title position |
|
|||
480 | if (m_titleItem) { |
|
|||
481 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); |
|
|||
482 | m_titleItem->setPos(center.x(),m_rect.top()/2 + padding/2); |
|
|||
483 | } |
|
|||
484 |
|
||||
485 | //recalculate background gradient |
|
|||
486 | if (m_backgroundItem) { |
|
|||
487 | m_backgroundItem->setRect(m_rect.adjusted(backgroundPadding,backgroundPadding, -backgroundPadding, -backgroundPadding)); |
|
|||
488 | } |
|
|||
489 |
|
||||
490 | // recalculate legend position |
|
|||
491 | if (m_legend) { |
|
|||
492 | if ((m_legend->attachedToChart()) && (m_legend->parentObject() == q_ptr)) { |
|
|||
493 | updateLegendLayout(); |
|
|||
494 | } |
|
|||
495 | } |
|
|||
496 | } |
|
|||
497 |
|
||||
498 | #include "moc_qchart.cpp" |
|
349 | #include "moc_qchart.cpp" | |
499 |
|
350 | |||
500 | QTCOMMERCIALCHART_END_NAMESPACE |
|
351 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,118 +1,118 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef QCHART_H |
|
21 | #ifndef QCHART_H | |
22 | #define QCHART_H |
|
22 | #define QCHART_H | |
23 |
|
23 | |||
24 | #include <QSeries> |
|
24 | #include <QSeries> | |
25 | #include <QGraphicsWidget> |
|
25 | #include <QGraphicsWidget> | |
26 |
|
26 | |||
27 | class QGraphicsSceneResizeEvent; |
|
27 | class QGraphicsSceneResizeEvent; | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 | class QSeries; |
|
31 | class QSeries; | |
32 | class QChartAxis; |
|
32 | class QChartAxis; | |
33 | class QLegend; |
|
33 | class QLegend; | |
34 | struct QChartPrivate; |
|
34 | struct QChartPrivate; | |
35 |
|
35 | |||
36 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget |
|
36 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget | |
37 | { |
|
37 | { | |
38 | Q_OBJECT |
|
38 | Q_OBJECT | |
39 | Q_ENUMS(ChartTheme) |
|
39 | Q_ENUMS(ChartTheme) | |
40 |
|
40 | |||
41 | public: |
|
41 | public: | |
42 | enum ChartTheme { |
|
42 | enum ChartTheme { | |
43 | ChartThemeLight = 0, |
|
43 | ChartThemeLight = 0, | |
44 | ChartThemeBlueCerulean, |
|
44 | ChartThemeBlueCerulean, | |
45 | ChartThemeDark, |
|
45 | ChartThemeDark, | |
46 | ChartThemeBrownSand, |
|
46 | ChartThemeBrownSand, | |
47 | ChartThemeBlueNcs, |
|
47 | ChartThemeBlueNcs, | |
48 | ChartThemeHighContrast, |
|
48 | ChartThemeHighContrast, | |
49 | ChartThemeBlueIcy, |
|
49 | ChartThemeBlueIcy, | |
50 | ChartThemeCount |
|
50 | ChartThemeCount | |
51 | }; |
|
51 | }; | |
52 |
|
52 | |||
53 | enum AnimationOption { |
|
53 | enum AnimationOption { | |
54 | NoAnimation = 0x0, |
|
54 | NoAnimation = 0x0, | |
55 | GridAxisAnimations = 0x1, |
|
55 | GridAxisAnimations = 0x1, | |
56 | SeriesAnimations =0x2, |
|
56 | SeriesAnimations =0x2, | |
57 | AllAnimations = 0x3 |
|
57 | AllAnimations = 0x3 | |
58 | }; |
|
58 | }; | |
59 |
|
59 | |||
60 | Q_DECLARE_FLAGS(AnimationOptions, AnimationOption) |
|
60 | Q_DECLARE_FLAGS(AnimationOptions, AnimationOption) | |
61 |
|
61 | |||
62 | public: |
|
62 | public: | |
63 | explicit QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); |
|
63 | explicit QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); | |
64 | ~QChart(); |
|
64 | ~QChart(); | |
65 |
|
65 | |||
66 | void addSeries(QSeries *series, QChartAxis *axisY = 0); |
|
66 | void addSeries(QSeries *series, QChartAxis *axisY = 0); | |
67 | void removeSeries(QSeries *series); |
|
67 | void removeSeries(QSeries *series); | |
68 | void removeAllSeries(); |
|
68 | void removeAllSeries(); | |
69 |
|
69 | |||
70 | void setTheme(QChart::ChartTheme theme); |
|
70 | void setTheme(QChart::ChartTheme theme); | |
71 | QChart::ChartTheme theme() const; |
|
71 | QChart::ChartTheme theme() const; | |
72 |
|
72 | |||
73 | void setTitle(const QString& title); |
|
73 | void setTitle(const QString& title); | |
74 | QString title() const; |
|
74 | QString title() const; | |
75 | void setTitleFont(const QFont& font); |
|
75 | void setTitleFont(const QFont& font); | |
76 | QFont titleFont() const; |
|
76 | QFont titleFont() const; | |
77 | void setTitleBrush(const QBrush &brush); |
|
77 | void setTitleBrush(const QBrush &brush); | |
78 | QBrush titleBrush() const; |
|
78 | QBrush titleBrush() const; | |
79 | void setBackgroundBrush(const QBrush &brush); |
|
79 | void setBackgroundBrush(const QBrush &brush); | |
80 | QBrush backgroundBrush() const; |
|
80 | QBrush backgroundBrush() const; | |
81 | void setBackgroundPen(const QPen &pen); |
|
81 | void setBackgroundPen(const QPen &pen); | |
82 | QPen backgroundPen() const; |
|
82 | QPen backgroundPen() const; | |
83 |
|
83 | |||
84 | void setBackgroundVisible(bool visible); |
|
84 | void setBackgroundVisible(bool visible); | |
85 | bool isBackgroundVisible() const; |
|
85 | bool isBackgroundVisible() const; | |
86 |
|
86 | |||
87 | void setAnimationOptions(AnimationOptions options); |
|
87 | void setAnimationOptions(AnimationOptions options); | |
88 | AnimationOptions animationOptions() const; |
|
88 | AnimationOptions animationOptions() const; | |
89 |
|
89 | |||
90 | void zoomIn(); |
|
90 | void zoomIn(); | |
91 | void zoomIn(const QRectF &rect); |
|
91 | void zoomIn(const QRectF &rect); | |
92 | void zoomOut(); |
|
92 | void zoomOut(); | |
93 | void scrollLeft(); |
|
93 | void scrollLeft(); | |
94 | void scrollRight(); |
|
94 | void scrollRight(); | |
95 | void scrollUp(); |
|
95 | void scrollUp(); | |
96 | void scrollDown(); |
|
96 | void scrollDown(); | |
97 |
|
97 | |||
98 | QChartAxis* axisX() const; |
|
98 | QChartAxis* axisX() const; | |
99 | QChartAxis* axisY() const; |
|
99 | QChartAxis* axisY() const; | |
100 |
|
100 | |||
101 | QLegend* legend() const; |
|
101 | QLegend* legend() const; | |
102 |
|
102 | QRect margins() const; | ||
103 | QRect padding() const; |
|
|||
104 |
|
103 | |||
105 | protected: |
|
104 | protected: | |
106 | void resizeEvent(QGraphicsSceneResizeEvent *event); |
|
105 | void resizeEvent(QGraphicsSceneResizeEvent *event); | |
107 |
|
106 | |||
108 | protected: |
|
107 | protected: | |
109 | QScopedPointer<QChartPrivate> d_ptr; |
|
108 | QScopedPointer<QChartPrivate> d_ptr; | |
110 | friend class QLegend; |
|
109 | friend class QLegend; | |
|
110 | friend class ChartPresenter; | |||
111 | Q_DISABLE_COPY(QChart) |
|
111 | Q_DISABLE_COPY(QChart) | |
112 | }; |
|
112 | }; | |
113 |
|
113 | |||
114 | QTCOMMERCIALCHART_END_NAMESPACE |
|
114 | QTCOMMERCIALCHART_END_NAMESPACE | |
115 |
|
115 | |||
116 | Q_DECLARE_OPERATORS_FOR_FLAGS(QTCOMMERCIALCHART_NAMESPACE::QChart::AnimationOptions) |
|
116 | Q_DECLARE_OPERATORS_FOR_FLAGS(QTCOMMERCIALCHART_NAMESPACE::QChart::AnimationOptions) | |
117 |
|
117 | |||
118 | #endif |
|
118 | #endif |
@@ -1,64 +1,53 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef QCHART_P_H |
|
30 | #ifndef QCHART_P_H | |
31 | #define QCHART_P_H |
|
31 | #define QCHART_P_H | |
32 |
|
32 | |||
33 | #include "qchartaxis.h" |
|
|||
34 | #include "qlegend.h" |
|
33 | #include "qlegend.h" | |
35 | #include "chartpresenter_p.h" |
|
34 | #include "chartpresenter_p.h" | |
36 | #include "chartdataset_p.h" |
|
35 | #include "chartdataset_p.h" | |
37 | #include "chartbackground_p.h" |
|
|||
38 |
|
36 | |||
39 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
40 |
|
38 | |||
41 | class QChart; |
|
39 | class QChart; | |
42 |
|
40 | |||
43 | struct QChartPrivate |
|
41 | struct QChartPrivate | |
44 | { |
|
42 | { | |
45 |
QChartPrivate( |
|
43 | QChartPrivate(); | |
46 | ~QChartPrivate(); |
|
44 | ~QChartPrivate(); | |
47 |
|
||||
48 | void createChartBackgroundItem(); |
|
|||
49 | void createChartTitleItem(); |
|
|||
50 | void updateLayout(); |
|
|||
51 | void updateLegendLayout(); |
|
|||
52 |
|
||||
53 | QChart *q_ptr; |
|
|||
54 | ChartBackground* m_backgroundItem; |
|
|||
55 | QGraphicsSimpleTextItem* m_titleItem; |
|
|||
56 | QRectF m_rect; |
|
45 | QRectF m_rect; | |
57 | QLegend* m_legend; |
|
46 | QLegend* m_legend; | |
58 | ChartDataSet *m_dataset; |
|
47 | ChartDataSet *m_dataset; | |
59 | ChartPresenter *m_presenter; |
|
48 | ChartPresenter *m_presenter; | |
60 | QRect m_padding; |
|
49 | ||
61 | }; |
|
50 | }; | |
62 |
|
51 | |||
63 | QTCOMMERCIALCHART_END_NAMESPACE |
|
52 | QTCOMMERCIALCHART_END_NAMESPACE | |
64 | #endif |
|
53 | #endif |
@@ -1,244 +1,244 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qchartview.h" |
|
21 | #include "qchartview.h" | |
22 | #include "qchart_p.h" |
|
22 | #include "qchart_p.h" | |
23 | #include "qchartview_p.h" |
|
23 | #include "qchartview_p.h" | |
24 | #include <QGraphicsScene> |
|
24 | #include <QGraphicsScene> | |
25 | #include <QRubberBand> |
|
25 | #include <QRubberBand> | |
26 |
|
26 | |||
27 |
|
27 | |||
28 | /*! |
|
28 | /*! | |
29 | \enum QChartView::RubberBandPolicy |
|
29 | \enum QChartView::RubberBandPolicy | |
30 |
|
30 | |||
31 | This enum describes the different types of rubber bands that can be used for zoom rect selection |
|
31 | This enum describes the different types of rubber bands that can be used for zoom rect selection | |
32 |
|
32 | |||
33 | \value NoRubberBand |
|
33 | \value NoRubberBand | |
34 | \value VerticalRubberBand |
|
34 | \value VerticalRubberBand | |
35 | \value HorizonalRubberBand |
|
35 | \value HorizonalRubberBand | |
36 | \value RectangleRubberBand |
|
36 | \value RectangleRubberBand | |
37 | */ |
|
37 | */ | |
38 |
|
38 | |||
39 | /*! |
|
39 | /*! | |
40 | \class QChartView |
|
40 | \class QChartView | |
41 | \brief Standalone charting widget. |
|
41 | \brief Standalone charting widget. | |
42 |
|
42 | |||
43 | QChartView is a standalone widget that can display charts. It does not require separate |
|
43 | QChartView is a standalone widget that can display charts. It does not require separate | |
44 | QGraphicsScene to work. It manages the graphical representation of different types of |
|
44 | QGraphicsScene to work. It manages the graphical representation of different types of | |
45 | QChartSeries and other chart related objects like QChartAxis and QChartLegend. If you want to |
|
45 | QChartSeries and other chart related objects like QChartAxis and QChartLegend. If you want to | |
46 | display a chart in your existing QGraphicsScene, you can use the QChart class instead. |
|
46 | display a chart in your existing QGraphicsScene, you can use the QChart class instead. | |
47 |
|
47 | |||
48 | \sa QChart |
|
48 | \sa QChart | |
49 | */ |
|
49 | */ | |
50 |
|
50 | |||
51 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
51 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
52 |
|
52 | |||
53 | /*! |
|
53 | /*! | |
54 | Constructs a chartView object which is a child of a\a parent. |
|
54 | Constructs a chartView object which is a child of a\a parent. | |
55 | */ |
|
55 | */ | |
56 | QChartView::QChartView(QChart *chart,QWidget *parent) : |
|
56 | QChartView::QChartView(QChart *chart,QWidget *parent) : | |
57 | QGraphicsView(parent), |
|
57 | QGraphicsView(parent), | |
58 | d_ptr(new QChartViewPrivate()) |
|
58 | d_ptr(new QChartViewPrivate()) | |
59 | { |
|
59 | { | |
60 | d_ptr->m_scene = new QGraphicsScene(this); |
|
60 | d_ptr->m_scene = new QGraphicsScene(this); | |
61 | d_ptr->m_chart = chart; |
|
61 | d_ptr->m_chart = chart; | |
62 | setFrameShape(QFrame::NoFrame); |
|
62 | setFrameShape(QFrame::NoFrame); | |
63 | setBackgroundRole(QPalette::Window); |
|
63 | setBackgroundRole(QPalette::Window); | |
64 | setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
64 | setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |
65 | setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
65 | setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |
66 | setScene(d_ptr->m_scene); |
|
66 | setScene(d_ptr->m_scene); | |
67 | d_ptr->m_scene->addItem(chart); |
|
67 | d_ptr->m_scene->addItem(chart); | |
68 | setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
|
68 | setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | |
69 | } |
|
69 | } | |
70 |
|
70 | |||
71 |
|
71 | |||
72 | /*! |
|
72 | /*! | |
73 | Destroys the object and it's children, like QChartSeries and QChartAxis object added to it. |
|
73 | Destroys the object and it's children, like QChartSeries and QChartAxis object added to it. | |
74 | */ |
|
74 | */ | |
75 | QChartView::~QChartView() |
|
75 | QChartView::~QChartView() | |
76 | { |
|
76 | { | |
77 | } |
|
77 | } | |
78 |
|
78 | |||
79 | QChart* QChartView::chart() const |
|
79 | QChart* QChartView::chart() const | |
80 | { |
|
80 | { | |
81 | return d_ptr->m_chart; |
|
81 | return d_ptr->m_chart; | |
82 | } |
|
82 | } | |
83 |
|
83 | |||
84 | /*! |
|
84 | /*! | |
85 | Sets the RubberBandPlicy to \a policy. Selected policy determines the way zooming is performed. |
|
85 | Sets the RubberBandPlicy to \a policy. Selected policy determines the way zooming is performed. | |
86 | */ |
|
86 | */ | |
87 | void QChartView::setRubberBand(const RubberBands& rubberBand) |
|
87 | void QChartView::setRubberBand(const RubberBands& rubberBand) | |
88 | { |
|
88 | { | |
89 | d_ptr->m_rubberBandFlags=rubberBand; |
|
89 | d_ptr->m_rubberBandFlags=rubberBand; | |
90 |
|
90 | |||
91 | if (!d_ptr->m_rubberBandFlags) { |
|
91 | if (!d_ptr->m_rubberBandFlags) { | |
92 | delete d_ptr->m_rubberBand; |
|
92 | delete d_ptr->m_rubberBand; | |
93 | d_ptr->m_rubberBand=0; |
|
93 | d_ptr->m_rubberBand=0; | |
94 | return; |
|
94 | return; | |
95 | } |
|
95 | } | |
96 |
|
96 | |||
97 | if (!d_ptr->m_rubberBand) { |
|
97 | if (!d_ptr->m_rubberBand) { | |
98 | d_ptr->m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this); |
|
98 | d_ptr->m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this); | |
99 | d_ptr->m_rubberBand->setEnabled(true); |
|
99 | d_ptr->m_rubberBand->setEnabled(true); | |
100 | } |
|
100 | } | |
101 | } |
|
101 | } | |
102 |
|
102 | |||
103 | /*! |
|
103 | /*! | |
104 | Returns the RubberBandPolicy that is currently being used by the widget. |
|
104 | Returns the RubberBandPolicy that is currently being used by the widget. | |
105 | */ |
|
105 | */ | |
106 | QChartView::RubberBands QChartView::rubberBand() const |
|
106 | QChartView::RubberBands QChartView::rubberBand() const | |
107 | { |
|
107 | { | |
108 | return d_ptr->m_rubberBandFlags; |
|
108 | return d_ptr->m_rubberBandFlags; | |
109 | } |
|
109 | } | |
110 |
|
110 | |||
111 | /*! |
|
111 | /*! | |
112 | If Left mouse button is pressed and the RubberBandPolicy is enabled the \a event is accepted and the rubber band is displayed on the screen allowing the user to select the zoom area. |
|
112 | If Left mouse button is pressed and the RubberBandPolicy is enabled the \a event is accepted and the rubber band is displayed on the screen allowing the user to select the zoom area. | |
113 | If different mouse button is pressed and/or the RubberBandPolicy is disabled then the \a event is passed to QGraphicsView::mousePressEvent() implementation. |
|
113 | If different mouse button is pressed and/or the RubberBandPolicy is disabled then the \a event is passed to QGraphicsView::mousePressEvent() implementation. | |
114 | */ |
|
114 | */ | |
115 | void QChartView::mousePressEvent(QMouseEvent *event) |
|
115 | void QChartView::mousePressEvent(QMouseEvent *event) | |
116 | { |
|
116 | { | |
117 | if(d_ptr->m_rubberBand && d_ptr->m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) { |
|
117 | if(d_ptr->m_rubberBand && d_ptr->m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) { | |
118 |
|
118 | |||
119 |
int padding = d_ptr->m_chart-> |
|
119 | int padding = d_ptr->m_chart->margins().top(); | |
120 | QRect rect(padding, padding, width() - 2 * padding, height() - 2 * padding); |
|
120 | QRect rect(padding, padding, width() - 2 * padding, height() - 2 * padding); | |
121 |
|
121 | |||
122 | if (rect.contains(event->pos())) { |
|
122 | if (rect.contains(event->pos())) { | |
123 | d_ptr->m_rubberBandOrigin = event->pos(); |
|
123 | d_ptr->m_rubberBandOrigin = event->pos(); | |
124 | d_ptr->m_rubberBand->setGeometry(QRect(d_ptr->m_rubberBandOrigin, QSize())); |
|
124 | d_ptr->m_rubberBand->setGeometry(QRect(d_ptr->m_rubberBandOrigin, QSize())); | |
125 | d_ptr->m_rubberBand->show(); |
|
125 | d_ptr->m_rubberBand->show(); | |
126 | event->accept(); |
|
126 | event->accept(); | |
127 | } |
|
127 | } | |
128 | } |
|
128 | } | |
129 | else { |
|
129 | else { | |
130 | QGraphicsView::mousePressEvent(event); |
|
130 | QGraphicsView::mousePressEvent(event); | |
131 | } |
|
131 | } | |
132 | } |
|
132 | } | |
133 |
|
133 | |||
134 | /*! |
|
134 | /*! | |
135 | If RubberBand rectange specification has been initiated in pressEvent then \a event data is used to update RubberBand geometry. |
|
135 | If RubberBand rectange specification has been initiated in pressEvent then \a event data is used to update RubberBand geometry. | |
136 | In other case the defualt QGraphicsView::mouseMoveEvent implementation is called. |
|
136 | In other case the defualt QGraphicsView::mouseMoveEvent implementation is called. | |
137 | */ |
|
137 | */ | |
138 | void QChartView::mouseMoveEvent(QMouseEvent *event) |
|
138 | void QChartView::mouseMoveEvent(QMouseEvent *event) | |
139 | { |
|
139 | { | |
140 | if(d_ptr->m_rubberBand && d_ptr->m_rubberBand->isVisible()) { |
|
140 | if(d_ptr->m_rubberBand && d_ptr->m_rubberBand->isVisible()) { | |
141 |
int padding = d_ptr->m_chart-> |
|
141 | int padding = d_ptr->m_chart->margins().top(); | |
142 | QRect rect(padding, padding, width() - 2 * padding, height() - 2 * padding); |
|
142 | QRect rect(padding, padding, width() - 2 * padding, height() - 2 * padding); | |
143 | int width = event->pos().x() - d_ptr->m_rubberBandOrigin.x(); |
|
143 | int width = event->pos().x() - d_ptr->m_rubberBandOrigin.x(); | |
144 | int height = event->pos().y() - d_ptr->m_rubberBandOrigin.y(); |
|
144 | int height = event->pos().y() - d_ptr->m_rubberBandOrigin.y(); | |
145 | if (!d_ptr->m_rubberBandFlags.testFlag(VerticalRubberBand)) { |
|
145 | if (!d_ptr->m_rubberBandFlags.testFlag(VerticalRubberBand)) { | |
146 | d_ptr->m_rubberBandOrigin.setY(rect.top()); |
|
146 | d_ptr->m_rubberBandOrigin.setY(rect.top()); | |
147 | height = rect.height(); |
|
147 | height = rect.height(); | |
148 | } |
|
148 | } | |
149 | if (!d_ptr->m_rubberBandFlags.testFlag(HorizonalRubberBand)) { |
|
149 | if (!d_ptr->m_rubberBandFlags.testFlag(HorizonalRubberBand)) { | |
150 | d_ptr->m_rubberBandOrigin.setX(rect.left()); |
|
150 | d_ptr->m_rubberBandOrigin.setX(rect.left()); | |
151 | width= rect.width(); |
|
151 | width= rect.width(); | |
152 | } |
|
152 | } | |
153 | d_ptr->m_rubberBand->setGeometry(QRect(d_ptr->m_rubberBandOrigin.x(),d_ptr->m_rubberBandOrigin.y(), width,height).normalized()); |
|
153 | d_ptr->m_rubberBand->setGeometry(QRect(d_ptr->m_rubberBandOrigin.x(),d_ptr->m_rubberBandOrigin.y(), width,height).normalized()); | |
154 | } |
|
154 | } | |
155 | else { |
|
155 | else { | |
156 | QGraphicsView::mouseMoveEvent(event); |
|
156 | QGraphicsView::mouseMoveEvent(event); | |
157 | } |
|
157 | } | |
158 | } |
|
158 | } | |
159 |
|
159 | |||
160 | /*! |
|
160 | /*! | |
161 | If left mouse button is release and RubberBand is enabled then \a event is accepted and the view is zoomed in to rect specified by RubberBand |
|
161 | If left mouse button is release and RubberBand is enabled then \a event is accepted and the view is zoomed in to rect specified by RubberBand | |
162 | If it is the right mouse button \a event then RubberBand is dissmissed and zoom is canceled. |
|
162 | If it is the right mouse button \a event then RubberBand is dissmissed and zoom is canceled. | |
163 | */ |
|
163 | */ | |
164 | void QChartView::mouseReleaseEvent(QMouseEvent *event) |
|
164 | void QChartView::mouseReleaseEvent(QMouseEvent *event) | |
165 | { |
|
165 | { | |
166 | if(d_ptr->m_rubberBand) { |
|
166 | if(d_ptr->m_rubberBand) { | |
167 | if (event->button() == Qt::LeftButton && d_ptr->m_rubberBand->isVisible()) { |
|
167 | if (event->button() == Qt::LeftButton && d_ptr->m_rubberBand->isVisible()) { | |
168 | d_ptr->m_rubberBand->hide(); |
|
168 | d_ptr->m_rubberBand->hide(); | |
169 | QRect rect = d_ptr->m_rubberBand->geometry(); |
|
169 | QRect rect = d_ptr->m_rubberBand->geometry(); | |
170 | d_ptr->m_chart->zoomIn(rect); |
|
170 | d_ptr->m_chart->zoomIn(rect); | |
171 | event->accept(); |
|
171 | event->accept(); | |
172 | } |
|
172 | } | |
173 |
|
173 | |||
174 | if(event->button()==Qt::RightButton){ |
|
174 | if(event->button()==Qt::RightButton){ | |
175 | d_ptr->m_chart->zoomOut(); |
|
175 | d_ptr->m_chart->zoomOut(); | |
176 | event->accept(); |
|
176 | event->accept(); | |
177 | } |
|
177 | } | |
178 | } |
|
178 | } | |
179 | else { |
|
179 | else { | |
180 | QGraphicsView::mouseReleaseEvent(event); |
|
180 | QGraphicsView::mouseReleaseEvent(event); | |
181 | } |
|
181 | } | |
182 | } |
|
182 | } | |
183 |
|
183 | |||
184 | /*! |
|
184 | /*! | |
185 | Pressing + and - keys performs zoomIn() and zoomOut() respectivly. |
|
185 | Pressing + and - keys performs zoomIn() and zoomOut() respectivly. | |
186 | In other \a event is passed to the QGraphicsView::keyPressEvent() implementation |
|
186 | In other \a event is passed to the QGraphicsView::keyPressEvent() implementation | |
187 | */ |
|
187 | */ | |
188 | void QChartView::keyPressEvent(QKeyEvent *event) |
|
188 | void QChartView::keyPressEvent(QKeyEvent *event) | |
189 | { |
|
189 | { | |
190 | switch (event->key()) { |
|
190 | switch (event->key()) { | |
191 | case Qt::Key_Plus: |
|
191 | case Qt::Key_Plus: | |
192 | d_ptr->m_chart->zoomIn(); |
|
192 | d_ptr->m_chart->zoomIn(); | |
193 | break; |
|
193 | break; | |
194 | case Qt::Key_Minus: |
|
194 | case Qt::Key_Minus: | |
195 | d_ptr->m_chart->zoomOut(); |
|
195 | d_ptr->m_chart->zoomOut(); | |
196 | break; |
|
196 | break; | |
197 | case Qt::Key_Left: |
|
197 | case Qt::Key_Left: | |
198 | d_ptr->m_chart->scrollLeft(); |
|
198 | d_ptr->m_chart->scrollLeft(); | |
199 | break; |
|
199 | break; | |
200 | case Qt::Key_Right: |
|
200 | case Qt::Key_Right: | |
201 | d_ptr->m_chart->scrollRight(); |
|
201 | d_ptr->m_chart->scrollRight(); | |
202 | break; |
|
202 | break; | |
203 | case Qt::Key_Up: |
|
203 | case Qt::Key_Up: | |
204 | d_ptr->m_chart->scrollUp(); |
|
204 | d_ptr->m_chart->scrollUp(); | |
205 | break; |
|
205 | break; | |
206 | case Qt::Key_Down: |
|
206 | case Qt::Key_Down: | |
207 | d_ptr->m_chart->scrollDown(); |
|
207 | d_ptr->m_chart->scrollDown(); | |
208 | break; |
|
208 | break; | |
209 | default: |
|
209 | default: | |
210 | QGraphicsView::keyPressEvent(event); |
|
210 | QGraphicsView::keyPressEvent(event); | |
211 | break; |
|
211 | break; | |
212 | } |
|
212 | } | |
213 | } |
|
213 | } | |
214 |
|
214 | |||
215 | /*! |
|
215 | /*! | |
216 | Resizes and updates the chart area using the \a event data |
|
216 | Resizes and updates the chart area using the \a event data | |
217 | */ |
|
217 | */ | |
218 | void QChartView::resizeEvent(QResizeEvent *event) |
|
218 | void QChartView::resizeEvent(QResizeEvent *event) | |
219 | { |
|
219 | { | |
220 | QGraphicsView::resizeEvent(event); |
|
220 | QGraphicsView::resizeEvent(event); | |
221 | d_ptr->m_chart->resize(size()); |
|
221 | d_ptr->m_chart->resize(size()); | |
222 | setSceneRect(d_ptr->m_chart->geometry()); |
|
222 | setSceneRect(d_ptr->m_chart->geometry()); | |
223 | } |
|
223 | } | |
224 |
|
224 | |||
225 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
225 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
226 |
|
226 | |||
227 | QChartViewPrivate::QChartViewPrivate(): |
|
227 | QChartViewPrivate::QChartViewPrivate(): | |
228 | m_scene(0), |
|
228 | m_scene(0), | |
229 | m_chart(0), |
|
229 | m_chart(0), | |
230 | m_presenter(0), |
|
230 | m_presenter(0), | |
231 | m_rubberBand(0), |
|
231 | m_rubberBand(0), | |
232 | m_rubberBandFlags(QChartView::NoRubberBand) |
|
232 | m_rubberBandFlags(QChartView::NoRubberBand) | |
233 | { |
|
233 | { | |
234 |
|
234 | |||
235 | } |
|
235 | } | |
236 |
|
236 | |||
237 | QChartViewPrivate::~QChartViewPrivate() |
|
237 | QChartViewPrivate::~QChartViewPrivate() | |
238 | { |
|
238 | { | |
239 |
|
239 | |||
240 | } |
|
240 | } | |
241 |
|
241 | |||
242 | #include "moc_qchartview.cpp" |
|
242 | #include "moc_qchartview.cpp" | |
243 |
|
243 | |||
244 | QTCOMMERCIALCHART_END_NAMESPACE |
|
244 | QTCOMMERCIALCHART_END_NAMESPACE |
This diff has been collapsed as it changes many lines, (528 lines changed) Show them Hide them | |||||
@@ -1,751 +1,563 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qlegend.h" |
|
21 | #include "qlegend.h" | |
22 | #include "qchart_p.h" |
|
22 | #include "qchart_p.h" | |
23 | #include "qseries.h" |
|
23 | #include "qseries.h" | |
24 | #include "legendmarker_p.h" |
|
24 | #include "legendmarker_p.h" | |
25 | #include "legendscrollbutton_p.h" |
|
|||
26 | #include "qxyseries.h" |
|
25 | #include "qxyseries.h" | |
27 | #include "qlineseries.h" |
|
26 | #include "qlineseries.h" | |
28 | #include "qareaseries.h" |
|
27 | #include "qareaseries.h" | |
29 | #include "qscatterseries.h" |
|
28 | #include "qscatterseries.h" | |
30 | #include "qsplineseries.h" |
|
29 | #include "qsplineseries.h" | |
31 | #include "qbarseries.h" |
|
30 | #include "qbarseries.h" | |
32 | #include "qstackedbarseries.h" |
|
31 | #include "qstackedbarseries.h" | |
33 | #include "qpercentbarseries.h" |
|
32 | #include "qpercentbarseries.h" | |
34 | #include "qbarset.h" |
|
33 | #include "qbarset.h" | |
35 | #include "qpieseries.h" |
|
34 | #include "qpieseries.h" | |
36 | #include "qpieslice.h" |
|
35 | #include "qpieslice.h" | |
37 | #include "chartpresenter_p.h" |
|
36 | #include "chartpresenter_p.h" | |
|
37 | #include "scroller_p.h" | |||
38 | #include <QPainter> |
|
38 | #include <QPainter> | |
39 | #include <QPen> |
|
39 | #include <QPen> | |
|
40 | #include <QTimer> | |||
40 |
|
41 | |||
41 | #include <QGraphicsSceneEvent> |
|
42 | #include <QGraphicsSceneEvent> | |
42 |
|
43 | |||
43 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
44 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
44 |
|
45 | |||
45 | /*! |
|
46 | /*! | |
46 | \class QLegend |
|
47 | \class QLegend | |
47 | \brief part of QtCommercial chart API. |
|
48 | \brief part of QtCommercial chart API. | |
48 |
|
49 | |||
49 | QLegend is a graphical object, whics displays legend of the chart. Legend state is updated by QChart, when |
|
50 | QLegend is a graphical object, whics displays legend of the chart. Legend state is updated by QChart, when | |
50 | series have been changed. By default, legend is drawn by QChart, but user can set a new parent to legend and |
|
51 | series have been changed. By default, legend is drawn by QChart, but user can set a new parent to legend and | |
51 | handle the drawing manually. |
|
52 | handle the drawing manually. | |
52 | User isn't supposed to create or delete legend objects, but can reference it via QChart class. |
|
53 | User isn't supposed to create or delete legend objects, but can reference it via QChart class. | |
53 |
|
54 | |||
54 | \mainclass |
|
55 | \mainclass | |
55 |
|
56 | |||
56 | \sa QChart, QSeries |
|
57 | \sa QChart, QSeries | |
57 | */ |
|
58 | */ | |
58 |
|
59 | |||
59 | /*! |
|
60 | /*! | |
60 | \enum QLegend::Layout |
|
61 | \enum QLegend::Layout | |
61 |
|
62 | |||
62 | This enum describes the possible position for legend inside chart. |
|
63 | This enum describes the possible position for legend inside chart. | |
63 |
|
64 | |||
64 | \value LayoutTop |
|
65 | \value LayoutTop | |
65 | \value LayoutBottom |
|
66 | \value LayoutBottom | |
66 | \value LayoutLeft |
|
67 | \value LayoutLeft | |
67 | \value LayoutRight |
|
68 | \value LayoutRight | |
68 | */ |
|
69 | */ | |
69 |
|
70 | |||
70 |
|
71 | |||
71 | /*! |
|
72 | /*! | |
72 | \fn void QLegend::clicked(QSeries* series, Qt::MouseButton button) |
|
73 | \fn void QLegend::clicked(QSeries* series, Qt::MouseButton button) | |
73 | \brief Notifies when series has been clicked on legend \a series \a button |
|
74 | \brief Notifies when series has been clicked on legend \a series \a button | |
74 | */ |
|
75 | */ | |
75 |
|
76 | |||
76 | /*! |
|
77 | /*! | |
77 | \fn void QLegend::clicked(QBarSet* barset, Qt::MouseButton button) |
|
78 | \fn void QLegend::clicked(QBarSet* barset, Qt::MouseButton button) | |
78 | \brief Notifies when barset has been clicked on legend \a barset \a button |
|
79 | \brief Notifies when barset has been clicked on legend \a barset \a button | |
79 | */ |
|
80 | */ | |
80 |
|
81 | |||
81 | /*! |
|
82 | /*! | |
82 | \fn void QLegend::clicked(QPieSlice* slice, Qt::MouseButton button) |
|
83 | \fn void QLegend::clicked(QPieSlice* slice, Qt::MouseButton button) | |
83 | \brief Notifies when pie slice has been clicked on legend \a slice \a button |
|
84 | \brief Notifies when pie slice has been clicked on legend \a slice \a button | |
84 | */ |
|
85 | */ | |
85 |
|
86 | |||
86 | /*! |
|
87 | /*! | |
87 | Constructs the legend object and sets the parent to \a parent |
|
88 | Constructs the legend object and sets the parent to \a parent | |
88 | */ |
|
89 | */ | |
|
90 | ||||
89 | QLegend::QLegend(QChart *chart):QGraphicsWidget(chart), |
|
91 | QLegend::QLegend(QChart *chart):QGraphicsWidget(chart), | |
90 | m_margin(5), |
|
92 | m_margin(5), | |
91 |
m_ |
|
93 | m_offsetX(0), | |
92 | m_minimumSize(50,20), // TODO: magic numbers |
|
94 | m_offsetY(0), | |
93 | m_maximumSize(150,100), |
|
|||
94 | m_size(m_minimumSize), |
|
|||
95 | m_brush(Qt::darkGray), // TODO: default should come from theme |
|
95 | m_brush(Qt::darkGray), // TODO: default should come from theme | |
96 | m_alignment(QLegend::AlignmentTop), |
|
96 | m_alignment(QLegend::AlignmentTop), | |
97 | mFirstMarker(0), |
|
97 | m_markers(new QGraphicsItemGroup(this)), | |
98 | m_attachedToChart(true), |
|
98 | m_attachedToChart(true), | |
99 | m_chart(chart) |
|
99 | m_chart(chart), | |
|
100 | m_minWidth(0), | |||
|
101 | m_minHeight(0), | |||
|
102 | m_width(0), | |||
|
103 | m_height(0), | |||
|
104 | m_visible(false), | |||
|
105 | m_dirty(false), | |||
|
106 | m_scroller(new Scroller(this)) | |||
100 | { |
|
107 | { | |
101 | m_scrollButtonLeft = new LegendScrollButton(LegendScrollButton::ScrollButtonIdLeft, this); |
|
|||
102 | m_scrollButtonRight = new LegendScrollButton(LegendScrollButton::ScrollButtonIdRight, this); |
|
|||
103 | m_scrollButtonUp = new LegendScrollButton(LegendScrollButton::ScrollButtonIdUp, this); |
|
|||
104 | m_scrollButtonDown = new LegendScrollButton(LegendScrollButton::ScrollButtonIdDown, this); |
|
|||
105 | setZValue(ChartPresenter::LegendZValue); |
|
108 | setZValue(ChartPresenter::LegendZValue); | |
|
109 | setFlags(QGraphicsItem::ItemClipsChildrenToShape); | |||
106 | } |
|
110 | } | |
107 |
|
111 | |||
108 | /*! |
|
112 | /*! | |
109 | Paints the legend to given \a painter. Paremeters \a option and \a widget arent used. |
|
113 | Paints the legend to given \a painter. Paremeters \a option and \a widget arent used. | |
110 | */ |
|
114 | */ | |
|
115 | ||||
111 | void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
116 | void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
112 | { |
|
117 | { | |
113 |
|
|
118 | Q_UNUSED(option) | |
114 |
|
|
119 | Q_UNUSED(widget) | |
|
120 | if(!m_visible) return; | |||
115 |
|
121 | |||
116 | painter->setOpacity(opacity()); |
|
122 | painter->setOpacity(opacity()); | |
117 | painter->setPen(m_pen); |
|
123 | painter->setPen(m_pen); | |
118 | painter->setBrush(m_brush); |
|
124 | painter->setBrush(m_brush); | |
119 |
|
|
125 | painter->drawRect(boundingRect()); | |
120 | } |
|
126 | } | |
121 |
|
127 | |||
122 | /*! |
|
128 | /*! | |
123 | Bounding rect of legend. |
|
129 | Bounding rect of legend. | |
124 | */ |
|
130 | */ | |
|
131 | ||||
125 | QRectF QLegend::boundingRect() const |
|
132 | QRectF QLegend::boundingRect() const | |
126 | { |
|
133 | { | |
127 |
return |
|
134 | return m_rect; | |
128 | } |
|
135 | } | |
129 |
|
136 | |||
130 | /*! |
|
137 | /*! | |
131 | Sets the \a brush of legend. Brush affects the background of legend. |
|
138 | Sets the \a brush of legend. Brush affects the background of legend. | |
132 | */ |
|
139 | */ | |
133 | void QLegend::setBrush(const QBrush &brush) |
|
140 | void QLegend::setBrush(const QBrush &brush) | |
134 | { |
|
141 | { | |
135 | if (m_brush != brush) { |
|
142 | if (m_brush != brush) { | |
136 | m_brush = brush; |
|
143 | m_brush = brush; | |
137 | update(); |
|
144 | update(); | |
138 | } |
|
145 | } | |
139 | } |
|
146 | } | |
140 |
|
147 | |||
141 | /*! |
|
148 | /*! | |
142 | Returns the brush used by legend. |
|
149 | Returns the brush used by legend. | |
143 | */ |
|
150 | */ | |
144 | QBrush QLegend::brush() const |
|
151 | QBrush QLegend::brush() const | |
145 | { |
|
152 | { | |
146 | return m_brush; |
|
153 | return m_brush; | |
147 | } |
|
154 | } | |
148 |
|
155 | |||
149 | /*! |
|
156 | /*! | |
150 | Sets the \a pen of legend. Pen affects the legend borders. |
|
157 | Sets the \a pen of legend. Pen affects the legend borders. | |
151 | */ |
|
158 | */ | |
152 | void QLegend::setPen(const QPen &pen) |
|
159 | void QLegend::setPen(const QPen &pen) | |
153 | { |
|
160 | { | |
154 | if (m_pen != pen) { |
|
161 | if (m_pen != pen) { | |
155 | m_pen = pen; |
|
162 | m_pen = pen; | |
156 | update(); |
|
163 | update(); | |
157 | } |
|
164 | } | |
158 | } |
|
165 | } | |
159 |
|
166 | |||
160 | /*! |
|
167 | /*! | |
161 | Returns the pen used by legend |
|
168 | Returns the pen used by legend | |
162 | */ |
|
169 | */ | |
163 |
|
170 | |||
164 | QPen QLegend::pen() const |
|
171 | QPen QLegend::pen() const | |
165 | { |
|
172 | { | |
166 | return m_pen; |
|
173 | return m_pen; | |
167 | } |
|
174 | } | |
168 |
|
175 | |||
169 | /*! |
|
176 | /*! | |
170 | Sets the \a preferred layout for legend. Legend tries to paint itself on the defined position in chart. |
|
177 | Sets the \a preferred layout for legend. Legend tries to paint itself on the defined position in chart. | |
171 | \sa QLegend::Layout |
|
178 | \sa QLegend::Layout | |
172 | */ |
|
179 | */ | |
173 | void QLegend::setAlignmnent(QLegend::Alignments alignment) |
|
180 | void QLegend::setAlignmnent(QLegend::Alignments alignment) | |
174 | { |
|
181 | { | |
175 |
|
|
182 | if(m_alignment!=alignment && m_attachedToChart) { | |
176 | m_alignment = alignment; |
|
183 | m_alignment = alignment; | |
177 | updateLayout(); |
|
184 | updateLayout(); | |
178 | m_chart->resize(m_chart->size()); |
|
185 | } | |
179 | // } |
|
|||
180 | } |
|
186 | } | |
181 |
|
187 | |||
182 | /*! |
|
188 | /*! | |
183 | Returns the preferred layout for legend |
|
189 | Returns the preferred layout for legend | |
184 | */ |
|
190 | */ | |
185 | QLegend::Alignments QLegend::alignment() const |
|
191 | QLegend::Alignments QLegend::alignment() const | |
186 | { |
|
192 | { | |
187 | return m_alignment; |
|
193 | return m_alignment; | |
188 | } |
|
194 | } | |
189 |
|
195 | |||
190 | /*! |
|
196 | /*! | |
191 | Returns the maximum size of legend. |
|
|||
192 | */ |
|
|||
193 | QSizeF QLegend::maximumSize() const |
|
|||
194 | { |
|
|||
195 | return m_maximumSize; |
|
|||
196 | } |
|
|||
197 |
|
||||
198 | /*! |
|
|||
199 | Sets the maximum \a size for legend. The legend can't grow bigger than this size. If there are |
|
|||
200 | more series than legend can fit to this size, scroll buttons are displayed. |
|
|||
201 | */ |
|
|||
202 | void QLegend::setMaximumSize(const QSizeF size) |
|
|||
203 | { |
|
|||
204 | m_maximumSize = size; |
|
|||
205 | updateLayout(); |
|
|||
206 | } |
|
|||
207 |
|
||||
208 | /*! |
|
|||
209 | Returns the current size of legend. |
|
|||
210 | */ |
|
|||
211 | QSizeF QLegend::size() const |
|
|||
212 | { |
|
|||
213 | return m_size; |
|
|||
214 | } |
|
|||
215 |
|
||||
216 | /*! |
|
|||
217 | Sets the \a size of legend. If size is bigger than maximum size of legend, the legend is resized to the maximum size. |
|
|||
218 | \sa setMmaximumSize() |
|
|||
219 | */ |
|
|||
220 | void QLegend::setSize(const QSizeF size) |
|
|||
221 | { |
|
|||
222 | m_size = size; |
|
|||
223 | if (m_size.width() > m_maximumSize.width()) { |
|
|||
224 | m_size.setWidth(m_maximumSize.width()); |
|
|||
225 | } |
|
|||
226 | if (m_size.height() > m_maximumSize.height()) { |
|
|||
227 | m_size.setHeight(m_maximumSize.height()); |
|
|||
228 | } |
|
|||
229 | } |
|
|||
230 |
|
||||
231 | /*! |
|
|||
232 | Sets position of legend to \a pos |
|
|||
233 | */ |
|
|||
234 | void QLegend::setPos(const QPointF &pos) |
|
|||
235 | { |
|
|||
236 | m_pos = pos; |
|
|||
237 | updateLayout(); |
|
|||
238 | } |
|
|||
239 |
|
||||
240 | /*! |
|
|||
241 | \internal \a series \a domain Should be called when series is added to chart. |
|
197 | \internal \a series \a domain Should be called when series is added to chart. | |
242 | */ |
|
198 | */ | |
243 | void QLegend::handleSeriesAdded(QSeries *series, Domain *domain) |
|
199 | void QLegend::handleSeriesAdded(QSeries *series, Domain *domain) | |
244 | { |
|
200 | { | |
245 | Q_UNUSED(domain) |
|
201 | Q_UNUSED(domain) | |
246 |
|
202 | |||
247 | switch (series->type()) |
|
203 | switch (series->type()) | |
248 | { |
|
204 | { | |
249 | case QSeries::SeriesTypeLine: { |
|
205 | case QSeries::SeriesTypeLine: { | |
250 | QLineSeries *lineSeries = static_cast<QLineSeries *>(series); |
|
206 | QLineSeries *lineSeries = static_cast<QLineSeries *>(series); | |
251 | appendMarkers(lineSeries); |
|
207 | appendMarkers(lineSeries); | |
252 | break; |
|
208 | break; | |
253 | } |
|
209 | } | |
254 | case QSeries::SeriesTypeArea: { |
|
210 | case QSeries::SeriesTypeArea: { | |
255 | QAreaSeries *areaSeries = static_cast<QAreaSeries *>(series); |
|
211 | QAreaSeries *areaSeries = static_cast<QAreaSeries *>(series); | |
256 | appendMarkers(areaSeries); |
|
212 | appendMarkers(areaSeries); | |
257 | break; |
|
213 | break; | |
258 | } |
|
214 | } | |
259 | case QSeries::SeriesTypeBar: { |
|
215 | case QSeries::SeriesTypeBar: { | |
260 | QBarSeries *barSeries = static_cast<QBarSeries *>(series); |
|
216 | QBarSeries *barSeries = static_cast<QBarSeries *>(series); | |
261 | appendMarkers(barSeries); |
|
217 | appendMarkers(barSeries); | |
262 | break; |
|
218 | break; | |
263 | } |
|
219 | } | |
264 | case QSeries::SeriesTypeStackedBar: { |
|
220 | case QSeries::SeriesTypeStackedBar: { | |
265 | QStackedBarSeries *stackedBarSeries = static_cast<QStackedBarSeries *>(series); |
|
221 | QStackedBarSeries *stackedBarSeries = static_cast<QStackedBarSeries *>(series); | |
266 | appendMarkers(stackedBarSeries); |
|
222 | appendMarkers(stackedBarSeries); | |
267 | break; |
|
223 | break; | |
268 | } |
|
224 | } | |
269 | case QSeries::SeriesTypePercentBar: { |
|
225 | case QSeries::SeriesTypePercentBar: { | |
270 | QPercentBarSeries *percentBarSeries = static_cast<QPercentBarSeries *>(series); |
|
226 | QPercentBarSeries *percentBarSeries = static_cast<QPercentBarSeries *>(series); | |
271 | appendMarkers(percentBarSeries); |
|
227 | appendMarkers(percentBarSeries); | |
272 | break; |
|
228 | break; | |
273 | } |
|
229 | } | |
274 | case QSeries::SeriesTypeScatter: { |
|
230 | case QSeries::SeriesTypeScatter: { | |
275 | QScatterSeries *scatterSeries = static_cast<QScatterSeries *>(series); |
|
231 | QScatterSeries *scatterSeries = static_cast<QScatterSeries *>(series); | |
276 | appendMarkers(scatterSeries); |
|
232 | appendMarkers(scatterSeries); | |
277 | break; |
|
233 | break; | |
278 | } |
|
234 | } | |
279 | case QSeries::SeriesTypePie: { |
|
235 | case QSeries::SeriesTypePie: { | |
280 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); |
|
236 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); | |
281 | appendMarkers(pieSeries); |
|
237 | appendMarkers(pieSeries); | |
282 | connect(pieSeries,SIGNAL(added(QList<QPieSlice*>)),this,SLOT(handleAdded(QList<QPieSlice*>))); |
|
238 | connect(pieSeries,SIGNAL(added(QList<QPieSlice*>)),this,SLOT(handleAdded(QList<QPieSlice*>))); | |
283 | break; |
|
239 | break; | |
284 | } |
|
240 | } | |
285 | case QSeries::SeriesTypeSpline: { |
|
241 | case QSeries::SeriesTypeSpline: { | |
286 | QSplineSeries *splineSeries = static_cast<QSplineSeries *>(series); |
|
242 | QSplineSeries *splineSeries = static_cast<QSplineSeries *>(series); | |
287 | appendMarkers(splineSeries); |
|
243 | appendMarkers(splineSeries); | |
288 | break; |
|
244 | break; | |
289 | } |
|
245 | } | |
290 | default: { |
|
246 | default: { | |
291 | qWarning()<< "QLegend::handleSeriesAdded" << series->type() << "unknown series type."; |
|
247 | qWarning()<< "QLegend::handleSeriesAdded" << series->type() << "unknown series type."; | |
292 | break; |
|
248 | break; | |
293 | } |
|
249 | } | |
294 | } |
|
250 | } | |
295 |
|
251 | |||
296 | updateLayout(); |
|
252 | // wait for all series added | |
|
253 | if(!m_dirty){ | |||
|
254 | QTimer::singleShot(0,this,SLOT(updateLayout())); | |||
|
255 | m_dirty=true; | |||
|
256 | } | |||
297 | } |
|
257 | } | |
298 |
|
258 | |||
299 | /*! |
|
259 | /*! | |
300 | \internal \a series Should be called when series is removed from chart. |
|
260 | \internal \a series Should be called when series is removed from chart. | |
301 | */ |
|
261 | */ | |
302 | void QLegend::handleSeriesRemoved(QSeries *series) |
|
262 | void QLegend::handleSeriesRemoved(QSeries *series) | |
303 | { |
|
263 | { | |
304 | switch (series->type()) |
|
264 | switch (series->type()) | |
305 | { |
|
265 | { | |
306 | case QSeries::SeriesTypeArea: { |
|
266 | case QSeries::SeriesTypeArea: { | |
307 | QAreaSeries *areaSeries = static_cast<QAreaSeries *>(series); |
|
267 | QAreaSeries *areaSeries = static_cast<QAreaSeries *>(series); | |
308 | deleteMarkers(areaSeries); |
|
268 | deleteMarkers(areaSeries); | |
309 | break; |
|
269 | break; | |
310 | } |
|
270 | } | |
311 | case QSeries::SeriesTypePie: { |
|
271 | case QSeries::SeriesTypePie: { | |
312 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); |
|
272 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); | |
313 | disconnect(pieSeries, SIGNAL(added(QList<QPieSlice *>)), this, SLOT(handleAdded(QList<QPieSlice *>))); |
|
273 | disconnect(pieSeries, SIGNAL(added(QList<QPieSlice *>)), this, SLOT(handleAdded(QList<QPieSlice *>))); | |
314 | deleteMarkers(series); |
|
274 | deleteMarkers(series); | |
315 | break; |
|
275 | break; | |
316 | } |
|
276 | } | |
317 | default: { |
|
277 | default: { | |
318 | // All other types |
|
278 | // All other types | |
319 | deleteMarkers(series); |
|
279 | deleteMarkers(series); | |
320 | break; |
|
280 | break; | |
321 | } |
|
281 | } | |
322 | } |
|
282 | } | |
323 |
|
283 | |||
324 | updateLayout(); |
|
284 | updateLayout(); | |
325 | } |
|
285 | } | |
326 |
|
286 | |||
327 | /*! |
|
287 | /*! | |
328 | \internal \a slices Should be called when slices are added to pie chart. |
|
288 | \internal \a slices Should be called when slices are added to pie chart. | |
329 | */ |
|
289 | */ | |
330 | void QLegend::handleAdded(QList<QPieSlice *> slices) |
|
290 | void QLegend::handleAdded(QList<QPieSlice *> slices) | |
331 | { |
|
291 | { | |
332 | QPieSeries* series = static_cast<QPieSeries *> (sender()); |
|
292 | QPieSeries* series = static_cast<QPieSeries *> (sender()); | |
333 | foreach(QPieSlice* s, slices) { |
|
293 | foreach(QPieSlice* slice, slices) { | |
334 |
LegendMarker* marker = new LegendMarker(series, |
|
294 | PieLegendMarker* marker = new PieLegendMarker(series,slice, this); | |
335 | marker->setName(s->label()); |
|
|||
336 | marker->setBrush(s->brush()); |
|
|||
337 | connect(marker, SIGNAL(clicked(QPieSlice*,Qt::MouseButton)), |
|
|||
338 | this, SIGNAL(clicked(QPieSlice*,Qt::MouseButton))); |
|
|||
339 | connect(s, SIGNAL(changed()), marker, SLOT(changed())); |
|
|||
340 | connect(s, SIGNAL(destroyed()), marker, SLOT(deleteLater())); |
|
|||
341 | connect(marker, SIGNAL(destroyed()), this, SLOT(handleMarkerDestroyed())); |
|
295 | connect(marker, SIGNAL(destroyed()), this, SLOT(handleMarkerDestroyed())); | |
342 |
m_markers |
|
296 | m_markers->addToGroup(marker); | |
343 | childItems().append(marker); |
|
|||
344 | } |
|
297 | } | |
345 | updateLayout(); |
|
298 | updateLayout(); | |
346 | } |
|
299 | } | |
347 |
|
300 | |||
348 | /*! |
|
301 | /*! | |
349 | \internal \a slices Should be called when slices are removed from pie chart. Currently unused, |
|
302 | \internal \a slices Should be called when slices are removed from pie chart. Currently unused, | |
350 | because removed slices are also deleted and we listen destroyed signal |
|
303 | because removed slices are also deleted and we listen destroyed signal | |
351 | */ |
|
304 | */ | |
352 | void QLegend::handleRemoved(QList<QPieSlice *> slices) |
|
305 | void QLegend::handleRemoved(QList<QPieSlice *> slices) | |
353 | { |
|
306 | { | |
354 | Q_UNUSED(slices) |
|
307 | Q_UNUSED(slices) | |
355 | } |
|
308 | } | |
356 |
|
309 | |||
357 |
|
310 | |||
358 | /*! |
|
311 | /*! | |
359 | \internal Notifies legend that some marker has been removed. Sent by legend markers when destroyed |
|
312 | \internal Notifies legend that some marker has been removed. Sent by legend markers when destroyed | |
360 | */ |
|
313 | */ | |
361 | void QLegend::handleMarkerDestroyed() |
|
314 | void QLegend::handleMarkerDestroyed() | |
362 | { |
|
315 | { | |
363 | LegendMarker* m = static_cast<LegendMarker *> (sender()); |
|
316 | LegendMarker* m = static_cast<LegendMarker *> (sender()); | |
364 | m_markers.removeOne(m); |
|
317 | delete m; | |
365 | updateLayout(); |
|
318 | // updateLayout(); | |
366 | } |
|
|||
367 |
|
||||
368 | /*! |
|
|||
369 | \internal \a event Handles clicked signals from scroll buttons |
|
|||
370 | */ |
|
|||
371 | void QLegend::scrollButtonClicked(LegendScrollButton *scrollButton) |
|
|||
372 | { |
|
|||
373 | Q_ASSERT(scrollButton); |
|
|||
374 |
|
||||
375 | switch (scrollButton->id()) { |
|
|||
376 | case LegendScrollButton::ScrollButtonIdLeft: |
|
|||
377 | case LegendScrollButton::ScrollButtonIdUp: { |
|
|||
378 | // Lower limit is same in these cases |
|
|||
379 | mFirstMarker--; |
|
|||
380 | checkFirstMarkerBounds(); |
|
|||
381 | break; |
|
|||
382 | } |
|
|||
383 | case LegendScrollButton::ScrollButtonIdRight: |
|
|||
384 | case LegendScrollButton::ScrollButtonIdDown: { |
|
|||
385 | mFirstMarker++; |
|
|||
386 | checkFirstMarkerBounds(); |
|
|||
387 | break; |
|
|||
388 | } |
|
|||
389 | default: { |
|
|||
390 | break; |
|
|||
391 | } |
|
|||
392 | } |
|
|||
393 | updateLayout(); |
|
|||
394 | } |
|
319 | } | |
395 |
|
320 | |||
396 | /*! |
|
321 | /*! | |
397 | Detaches the legend from chart. Chart won't change layout of the legend. |
|
322 | Detaches the legend from chart. Chart won't change layout of the legend. | |
398 | */ |
|
323 | */ | |
399 | void QLegend::detachFromChart() |
|
324 | void QLegend::detachFromChart() | |
400 | { |
|
325 | { | |
401 | m_attachedToChart = false; |
|
326 | m_attachedToChart = false; | |
402 | } |
|
327 | } | |
403 |
|
328 | |||
404 | /*! |
|
329 | /*! | |
405 | Attaches the legend to chart. Chart may change layout of the legend. |
|
330 | Attaches the legend to chart. Chart may change layout of the legend. | |
406 | */ |
|
331 | */ | |
407 | void QLegend::attachToChart() |
|
332 | void QLegend::attachToChart() | |
408 | { |
|
333 | { | |
409 | m_attachedToChart = true; |
|
334 | m_attachedToChart = true; | |
410 | } |
|
335 | } | |
411 |
|
336 | |||
412 | /*! |
|
337 | /*! | |
413 | Returns true, if legend is attached to chart. |
|
338 | Returns true, if legend is attached to chart. | |
414 | */ |
|
339 | */ | |
415 |
bool QLegend:: |
|
340 | bool QLegend::isAttachedToChart() | |
416 | { |
|
341 | { | |
417 | return m_attachedToChart; |
|
342 | return m_attachedToChart; | |
418 | } |
|
343 | } | |
419 |
|
344 | |||
420 | /*! |
|
345 | /*! | |
421 | \internal Helper function. Appends markers from \a series to legend. |
|
346 | \internal Helper function. Appends markers from \a series to legend. | |
422 | */ |
|
347 | */ | |
423 | void QLegend::appendMarkers(QAreaSeries* series) |
|
348 | void QLegend::appendMarkers(QAreaSeries* series) | |
424 | { |
|
349 | { | |
425 | LegendMarker* marker = new LegendMarker(series,this); |
|
350 | AreaLegendMarker* marker = new AreaLegendMarker(series,this); | |
426 | connect(marker, SIGNAL(clicked(QSeries *, Qt::MouseButton)), this, SIGNAL(clicked(QSeries *, Qt::MouseButton))); |
|
|||
427 | connect(marker, SIGNAL(destroyed()), this, SLOT(handleMarkerDestroyed())); |
|
351 | connect(marker, SIGNAL(destroyed()), this, SLOT(handleMarkerDestroyed())); | |
428 | connect(series,SIGNAL(updated()),marker,SLOT(changed())); |
|
352 | m_markers->addToGroup(marker); | |
429 | marker->changed(); |
|
|||
430 | m_markers.append(marker); |
|
|||
431 | childItems().append(marker); |
|
|||
432 | } |
|
353 | } | |
433 |
|
354 | |||
434 | /*! |
|
355 | /*! | |
435 | \internal Helper function. Appends markers from \a series to legend. |
|
356 | \internal Helper function. Appends markers from \a series to legend. | |
436 | */ |
|
357 | */ | |
437 | void QLegend::appendMarkers(QXYSeries* series) |
|
358 | void QLegend::appendMarkers(QXYSeries* series) | |
438 | { |
|
359 | { | |
439 | LegendMarker* marker = new LegendMarker(series,this); |
|
360 | XYLegendMarker* marker = new XYLegendMarker(series,this); | |
440 | connect(marker, SIGNAL(clicked(QSeries *, Qt::MouseButton)), this, SIGNAL(clicked(QSeries *, Qt::MouseButton))); |
|
|||
441 | connect(marker, SIGNAL(destroyed()), this, SLOT(handleMarkerDestroyed())); |
|
361 | connect(marker, SIGNAL(destroyed()), this, SLOT(handleMarkerDestroyed())); | |
442 | connect(series,SIGNAL(updated()),marker,SLOT(changed())); |
|
362 | m_markers->addToGroup(marker); | |
443 | marker->changed(); |
|
|||
444 | m_markers.append(marker); |
|
|||
445 | childItems().append(marker); |
|
|||
446 | } |
|
363 | } | |
447 |
|
364 | |||
448 | /*! |
|
365 | /*! | |
449 | \internal Helper function. Appends markers from \a series to legend. |
|
366 | \internal Helper function. Appends markers from \a series to legend. | |
450 | */ |
|
367 | */ | |
451 | void QLegend::appendMarkers(QBarSeries *series) |
|
368 | void QLegend::appendMarkers(QBarSeries *series) | |
452 | { |
|
369 | { | |
453 | foreach(QBarSet* set, series->barSets()) { |
|
370 | foreach(QBarSet* set, series->barSets()) { | |
454 |
LegendMarker* marker = new LegendMarker(series, |
|
371 | BarLegendMarker* marker = new BarLegendMarker(series,set, this); | |
455 | connect(marker, SIGNAL(clicked(QBarSet *, Qt::MouseButton)), |
|
|||
456 | this, SIGNAL(clicked(QBarSet *, Qt::MouseButton))); |
|
|||
457 | connect(set, SIGNAL(valueChanged()), marker, SLOT(changed())); |
|
|||
458 | connect(marker, SIGNAL(destroyed()), this, SLOT(handleMarkerDestroyed())); |
|
372 | connect(marker, SIGNAL(destroyed()), this, SLOT(handleMarkerDestroyed())); | |
459 |
marker-> |
|
373 | m_markers->addToGroup(marker); | |
460 | m_markers.append(marker); |
|
|||
461 | childItems().append(marker); |
|
|||
462 | } |
|
374 | } | |
463 | } |
|
375 | } | |
464 |
|
376 | |||
465 | /*! |
|
377 | /*! | |
466 | \internal Helper function. Appends markers from \a series to legend. |
|
378 | \internal Helper function. Appends markers from \a series to legend. | |
467 | */ |
|
379 | */ | |
468 | void QLegend::appendMarkers(QPieSeries *series) |
|
380 | void QLegend::appendMarkers(QPieSeries *series) | |
469 | { |
|
381 | { | |
470 | foreach(QPieSlice* slice, series->slices()) { |
|
382 | foreach(QPieSlice* slice, series->slices()) { | |
471 |
LegendMarker* marker = new LegendMarker(series, |
|
383 | PieLegendMarker* marker = new PieLegendMarker(series,slice, this); | |
472 | connect(marker, SIGNAL(clicked(QPieSlice *, Qt::MouseButton)), |
|
|||
473 | this, SIGNAL(clicked(QPieSlice *, Qt::MouseButton))); |
|
|||
474 | connect(slice, SIGNAL(changed()), marker, SLOT(changed())); |
|
|||
475 | connect(slice, SIGNAL(destroyed()), marker, SLOT(deleteLater())); |
|
|||
476 | connect(marker, SIGNAL(destroyed()), this, SLOT(handleMarkerDestroyed())); |
|
384 | connect(marker, SIGNAL(destroyed()), this, SLOT(handleMarkerDestroyed())); | |
477 |
marker-> |
|
385 | m_markers->addToGroup(marker); | |
478 | m_markers.append(marker); |
|
|||
479 | childItems().append(marker); |
|
|||
480 | } |
|
386 | } | |
481 | } |
|
387 | } | |
482 |
|
388 | |||
483 | /*! |
|
389 | /*! | |
484 | \internal Deletes all markers that are created from \a series |
|
390 | \internal Deletes all markers that are created from \a series | |
485 | */ |
|
391 | */ | |
486 | void QLegend::deleteMarkers(QSeries *series) |
|
392 | void QLegend::deleteMarkers(QSeries *series) | |
487 | { |
|
393 | { | |
488 | // Search all markers that belong to given series and delete them. |
|
394 | // Search all markers that belong to given series and delete them. | |
489 | foreach (LegendMarker *m, m_markers) { |
|
395 | ||
490 | if (m->series() == series) { |
|
396 | QList<QGraphicsItem *> items = m_markers->childItems(); | |
491 | m_markers.removeOne(m); |
|
397 | ||
492 | delete m; |
|
398 | foreach (QGraphicsItem *m, items) { | |
|
399 | LegendMarker *marker = static_cast<LegendMarker*>(m); | |||
|
400 | if (marker->series() == series) { | |||
|
401 | delete marker; | |||
493 | } |
|
402 | } | |
494 | } |
|
403 | } | |
495 | } |
|
404 | } | |
496 |
|
405 | |||
497 | /*! |
|
406 | /*! | |
498 | \internal Updates layout of legend. Tries to fit as many markers as possible up to the maximum size of legend. |
|
407 | \internal Updates layout of legend. Tries to fit as many markers as possible up to the maximum size of legend. | |
499 | If items don't fit, sets the visibility of scroll buttons accordingly. |
|
408 | If items don't fit, sets the visibility of scroll buttons accordingly. | |
500 | Causes legend to be resized. |
|
409 | Causes legend to be resized. | |
501 | */ |
|
410 | */ | |
502 | void QLegend::updateLayout() |
|
|||
503 | { |
|
|||
504 | // Calculate layout for markers and text |
|
|||
505 | if (m_markers.count() <= 0) { |
|
|||
506 | // Nothing to do |
|
|||
507 | return; |
|
|||
508 | } |
|
|||
509 |
|
411 | |||
510 | checkFirstMarkerBounds(); |
|
412 | void QLegend::setOffset(const QPointF& point) | |
|
413 | { | |||
511 |
|
414 | |||
512 |
switch |
|
415 | switch(m_alignment) { | |
513 | { |
|
|||
514 | // Both cases organise items horizontally |
|
|||
515 | case QLegend::AlignmentBottom: |
|
|||
516 | case QLegend::AlignmentTop: { |
|
|||
517 | layoutHorizontal(); |
|
|||
518 | break; |
|
|||
519 | } |
|
|||
520 | // Both cases organize items vertically |
|
|||
521 | case QLegend::AlignmentLeft: |
|
|||
522 | case QLegend::AlignmentRight: { |
|
|||
523 | layoutVertical(); |
|
|||
524 | break; |
|
|||
525 | } |
|
|||
526 | default: { |
|
|||
527 | break; |
|
|||
528 | } |
|
|||
529 | } |
|
|||
530 |
|
416 | |||
531 | } |
|
417 | case AlignmentTop: | |
|
418 | case AlignmentBottom: { | |||
|
419 | if(m_width<=m_rect.width()) return; | |||
532 |
|
420 | |||
533 | /*! |
|
421 | if (point.x() != m_offsetX) { | |
534 | \internal Organizes markers horizontally. |
|
422 | m_offsetX = qBound(0.0, point.x(), m_width - m_rect.width()); | |
535 | Causes legend to be resized. |
|
423 | m_markers->setPos(-m_offsetX,m_rect.top()); | |
536 | */ |
|
|||
537 | void QLegend::layoutHorizontal() |
|
|||
538 | { |
|
|||
539 | // Find out widest item. |
|
|||
540 | QSizeF markerMaxSize = maximumMarkerSize(); |
|
|||
541 | // Use max height as scroll button size |
|
|||
542 | rescaleScrollButtons(QSize(markerMaxSize.height() ,markerMaxSize.height())); |
|
|||
543 |
|
||||
544 | qreal totalWidth = 0; |
|
|||
545 | qreal totalHeight = 0; |
|
|||
546 |
|
||||
547 | qreal xStep = markerMaxSize.width(); |
|
|||
548 | qreal x = m_pos.x() + m_margin; |
|
|||
549 | qreal y = m_pos.y() + m_margin; |
|
|||
550 | int column = 0; |
|
|||
551 | int maxColumns = 1; |
|
|||
552 | qreal scrollButtonWidth = 0; |
|
|||
553 |
|
||||
554 | // Set correct visibility for scroll scrollbuttons |
|
|||
555 | if (scrollButtonsVisible()) { |
|
|||
556 | m_scrollButtonLeft->setVisible(true); |
|
|||
557 | m_scrollButtonRight->setVisible(true); |
|
|||
558 | // scrollbuttons visible, so add their width to total width |
|
|||
559 | totalWidth += (m_scrollButtonLeft->boundingRect().width() + m_margin) * 2; |
|
|||
560 | scrollButtonWidth = m_scrollButtonLeft->boundingRect().width() + m_margin; |
|
|||
561 | // start position changes by scrollbutton width |
|
|||
562 | x += scrollButtonWidth; |
|
|||
563 | } else { |
|
|||
564 | m_scrollButtonLeft->setVisible(false); |
|
|||
565 | m_scrollButtonRight->setVisible(false); |
|
|||
566 | } |
|
|||
567 | m_scrollButtonUp->setVisible(false); |
|
|||
568 | m_scrollButtonDown->setVisible(false); |
|
|||
569 |
|
||||
570 | for (int i=0; i < m_markers.count(); i++) { |
|
|||
571 | LegendMarker *m = m_markers.at(i); |
|
|||
572 | if (i < mFirstMarker) { |
|
|||
573 | // Markers before first are not visible. |
|
|||
574 | m->setVisible(false); |
|
|||
575 | } else { |
|
|||
576 | if ((x + xStep + scrollButtonWidth + m_margin) > (m_pos.x() + m_maximumSize.width())) { |
|
|||
577 | // This marker would go outside legend rect. |
|
|||
578 | m->setVisible(false); |
|
|||
579 | } else { |
|
|||
580 | // This marker is ok |
|
|||
581 | m->setVisible(true); |
|
|||
582 | m->setPos(x, y); |
|
|||
583 | x += xStep; |
|
|||
584 | column++; |
|
|||
585 | } |
|
424 | } | |
|
425 | break; | |||
586 | } |
|
426 | } | |
587 | maxColumns = column; |
|
427 | case AlignmentLeft: | |
588 | } |
|
428 | case AlignmentRight: { | |
589 |
|
||||
590 | m_scrollButtonLeft->setPos(m_pos.x() + m_margin, y); |
|
|||
591 | m_scrollButtonRight->setPos(x + m_margin, y); |
|
|||
592 |
|
429 | |||
593 | totalWidth += maxColumns * markerMaxSize.width() + m_margin * 2; |
|
430 | if(m_height<=m_rect.height()) return; | |
594 | totalHeight = markerMaxSize.height() + m_margin * 2; |
|
|||
595 |
|
431 | |||
596 | m_size.setWidth(totalWidth); |
|
432 | if (point.y() != m_offsetY) { | |
597 | m_size.setHeight(totalHeight); |
|
433 | m_offsetY = qBound(0.0, point.y(), m_height - m_rect.height()); | |
598 | } |
|
434 | m_markers->setPos(m_rect.left(),-m_offsetY); | |
599 |
|
||||
600 | /*! |
|
|||
601 | \internal Organizes markers vertically. |
|
|||
602 | Causes legend to be resized. |
|
|||
603 | */ |
|
|||
604 | void QLegend::layoutVertical() |
|
|||
605 | { |
|
|||
606 | // Find out widest item. |
|
|||
607 | QSizeF markerMaxSize = maximumMarkerSize(); |
|
|||
608 | // Use max height as scroll button size |
|
|||
609 | rescaleScrollButtons(QSize(markerMaxSize.height() ,markerMaxSize.height())); |
|
|||
610 |
|
||||
611 | qreal totalWidth = 0; |
|
|||
612 | qreal totalHeight = 0; |
|
|||
613 |
|
||||
614 | qreal yStep = markerMaxSize.height(); |
|
|||
615 | qreal x = m_pos.x() + m_margin; |
|
|||
616 | qreal y = m_pos.y() + m_margin; |
|
|||
617 | int row = 1; |
|
|||
618 | int maxRows = 1; |
|
|||
619 | qreal scrollButtonHeight = 0; |
|
|||
620 |
|
||||
621 | // Set correct visibility for scroll scrollbuttons |
|
|||
622 | if (scrollButtonsVisible()) { |
|
|||
623 | m_scrollButtonUp->setVisible(true); |
|
|||
624 | m_scrollButtonDown->setVisible(true); |
|
|||
625 | totalHeight += (m_scrollButtonUp->boundingRect().height() + m_margin) * 2; // scrollbuttons visible, so add their height to total height |
|
|||
626 | scrollButtonHeight = m_scrollButtonUp->boundingRect().height(); |
|
|||
627 | y += scrollButtonHeight + m_margin; // start position changes by scrollbutton height |
|
|||
628 | } else { |
|
|||
629 | m_scrollButtonUp->setVisible(false); |
|
|||
630 | m_scrollButtonDown->setVisible(false); |
|
|||
631 | } |
|
|||
632 | m_scrollButtonLeft->setVisible(false); |
|
|||
633 | m_scrollButtonRight->setVisible(false); |
|
|||
634 |
|
||||
635 | for (int i=0; i < m_markers.count(); i++) { |
|
|||
636 | LegendMarker* m = m_markers.at(i); |
|
|||
637 | if (i < mFirstMarker) { |
|
|||
638 | // Markers before first are not visible. |
|
|||
639 | m->setVisible(false); |
|
|||
640 | } else { |
|
|||
641 | if ((y + yStep + scrollButtonHeight) > (m_pos.y() + m_maximumSize.height())) { |
|
|||
642 | // This marker would go outside legend rect. |
|
|||
643 | m->setVisible(false); |
|
|||
644 | } else { |
|
|||
645 | // This marker is ok |
|
|||
646 | m->setVisible(true); |
|
|||
647 | m->setPos(x, y); |
|
|||
648 | y += yStep; |
|
|||
649 | row++; |
|
|||
650 | } |
|
435 | } | |
|
436 | break; | |||
651 | } |
|
437 | } | |
652 | maxRows = row; |
|
|||
653 | } |
|
438 | } | |
|
439 | } | |||
654 |
|
440 | |||
655 | m_scrollButtonUp->setPos(m_pos.x() + m_margin, m_pos.y() + m_margin); |
|
441 | QPointF QLegend::offset() const | |
656 | m_scrollButtonDown->setPos(m_pos.x() + m_margin, y + m_margin); |
|
442 | { | |
657 |
|
443 | return QPointF(m_offsetX,m_offsetY); | ||
658 | totalWidth += markerMaxSize.width() + m_margin * 2; |
|
|||
659 | totalHeight = maxRows * markerMaxSize.height() + m_margin * 4 + scrollButtonHeight; // TODO: check this |
|
|||
660 |
|
||||
661 | m_size.setWidth(totalWidth); |
|
|||
662 | m_size.setHeight(totalHeight); |
|
|||
663 | } |
|
444 | } | |
664 |
|
445 | |||
665 | /*! |
|
446 | // this function runs first to set min max values | |
666 | \internal Sets the size of scroll buttons to \a size |
|
447 | void QLegend::updateLayout() | |
667 | */ |
|
|||
668 | void QLegend::rescaleScrollButtons(const QSize &size) |
|
|||
669 | { |
|
448 | { | |
670 | QPolygonF left; |
|
449 | m_dirty=false; | |
671 | left << QPointF(size.width(), 0) << QPointF(0, size.height() / 2) << QPointF(size.width(), size.height()); |
|
450 | m_offsetX=0; | |
672 | QPolygonF right; |
|
451 | QList<QGraphicsItem *> items = m_markers->childItems(); | |
673 | right << QPointF(0, 0) << QPointF(size.width(), size.height() / 2) << QPointF(0, size.height()); |
|
452 | ||
674 | QPolygonF up; |
|
453 | if(items.isEmpty()) return; | |
675 | up << QPointF(0, size.height()) << QPointF(size.width() / 2,0) << QPointF(size.width(), size.height()); |
|
454 | ||
676 | QPolygonF down; |
|
455 | m_minWidth=0; | |
677 | down << QPointF(0, 0) << QPointF(size.width() / 2, size.height()) << QPointF(size.width(), 0); |
|
456 | m_minHeight=0; | |
|
457 | ||||
|
458 | switch(m_alignment) { | |||
|
459 | ||||
|
460 | case AlignmentTop: | |||
|
461 | case AlignmentBottom: { | |||
|
462 | QPointF point = m_rect.topLeft(); | |||
|
463 | m_width = 0; | |||
|
464 | foreach (QGraphicsItem *item, items) { | |||
|
465 | item->setPos(point.x(),m_rect.height()/2 -item->boundingRect().height()/2); | |||
|
466 | const QRectF& rect = item->boundingRect(); | |||
|
467 | qreal w = rect.width(); | |||
|
468 | m_minWidth=qMax(m_minWidth,w); | |||
|
469 | m_minHeight=qMax(m_minHeight,rect.height()); | |||
|
470 | m_width+=w; | |||
|
471 | point.setX(point.x() + w); | |||
|
472 | } | |||
|
473 | if(m_width<m_rect.width()){ | |||
|
474 | m_markers->setPos(m_rect.width()/2-m_width/2,m_rect.top()); | |||
|
475 | }else{ | |||
|
476 | m_markers->setPos(m_rect.topLeft()); | |||
|
477 | } | |||
|
478 | m_height=m_minHeight; | |||
|
479 | } | |||
|
480 | break; | |||
|
481 | case AlignmentLeft: | |||
|
482 | case AlignmentRight:{ | |||
|
483 | QPointF point = m_rect.topLeft(); | |||
|
484 | m_height = 0; | |||
|
485 | foreach (QGraphicsItem *item, items) { | |||
|
486 | item->setPos(point); | |||
|
487 | const QRectF& rect = item->boundingRect(); | |||
|
488 | qreal h = rect.height(); | |||
|
489 | m_minWidth=qMax(m_minWidth,rect.width()); | |||
|
490 | m_minHeight=qMax(m_minHeight,h); | |||
|
491 | m_height+=h; | |||
|
492 | point.setY(point.y() + h); | |||
|
493 | } | |||
|
494 | if(m_height<m_rect.height()){ | |||
|
495 | m_markers->setPos(m_rect.left(),m_rect.height()/2-m_height/2); | |||
|
496 | }else{ | |||
|
497 | m_markers->setPos(m_rect.topLeft()); | |||
|
498 | } | |||
|
499 | m_width=m_minWidth; | |||
|
500 | } | |||
|
501 | break; | |||
|
502 | } | |||
678 |
|
503 | |||
679 | m_scrollButtonLeft->setPolygon(left); |
|
504 | m_chart->d_ptr->m_presenter->updateLayout(); //TODO fixme; | |
680 | m_scrollButtonRight->setPolygon(right); |
|
|||
681 | m_scrollButtonUp->setPolygon(up); |
|
|||
682 | m_scrollButtonDown->setPolygon(down); |
|
|||
683 | } |
|
505 | } | |
684 |
|
506 | |||
685 | /*! |
|
507 | void QLegend::setBackgroundVisible(bool visible) | |
686 | \internal Finds out maximum size of single marker. Marker sizes depend on series names. |
|
508 | { | |
687 | */ |
|
509 | if(m_visible!=visible) | |
688 | QSizeF QLegend::maximumMarkerSize() |
|
510 | { | |
689 | { |
|
511 | m_visible=visible; | |
690 | QSizeF max(0,0); |
|
512 | update(); | |
691 | foreach (LegendMarker* m, m_markers) { |
|
|||
692 | if (m->boundingRect().width() > max.width()) |
|
|||
693 | max.setWidth(m->boundingRect().width()); |
|
|||
694 | if (m->boundingRect().height() > max.height()) |
|
|||
695 | max.setHeight(m->boundingRect().height()); |
|
|||
696 | } |
|
513 | } | |
697 | return max; |
|
|||
698 | } |
|
514 | } | |
699 |
|
515 | |||
700 | /*! |
|
516 | bool QLegend::isBackgroundVisible() const | |
701 | \internal Checks that first marker is in acceptable bounds. Bounds range from 0 to (maximum number of markers - visible markers) |
|
517 | { | |
702 | If scrollbuttons are visible, they affect the number of visible markers. |
|
518 | return m_visible; | |
703 | */ |
|
519 | } | |
704 | void QLegend::checkFirstMarkerBounds() |
|
|||
705 | { |
|
|||
706 | if ((m_alignment == QLegend::AlignmentLeft) || (m_alignment == QLegend::AlignmentRight)) { |
|
|||
707 | // Bounds limited by height. |
|
|||
708 | int max; |
|
|||
709 | if (scrollButtonsVisible()) { |
|
|||
710 | max = (m_maximumSize.height() - m_scrollButtonLeft->boundingRect().height() * 2 - m_margin * 4) / maximumMarkerSize().height(); |
|
|||
711 | } else { |
|
|||
712 | max = m_maximumSize.height() / maximumMarkerSize().height(); |
|
|||
713 | } |
|
|||
714 |
|
||||
715 | if (mFirstMarker > m_markers.count() - max) |
|
|||
716 | mFirstMarker = m_markers.count() - max; |
|
|||
717 | } else { |
|
|||
718 | // Bounds limited by width |
|
|||
719 | int max; |
|
|||
720 | if (scrollButtonsVisible()) { |
|
|||
721 | max = (m_maximumSize.width() - m_scrollButtonLeft->boundingRect().width() * 2 - m_margin*4) / maximumMarkerSize().width(); |
|
|||
722 | } else { |
|
|||
723 | max = m_maximumSize.width() / maximumMarkerSize().width(); |
|
|||
724 | } |
|
|||
725 |
|
520 | |||
726 | if (mFirstMarker > m_markers.count() - max) |
|
521 | void QLegend::resizeEvent(QGraphicsSceneResizeEvent *event) | |
727 | mFirstMarker = m_markers.count() - max; |
|
522 | { | |
|
523 | const QRectF& rect = QRectF(QPoint(0,0),event->newSize()); | |||
|
524 | QGraphicsWidget::resizeEvent(event); | |||
|
525 | if(m_rect != rect){ | |||
|
526 | m_rect = rect; | |||
|
527 | updateLayout(); | |||
728 | } |
|
528 | } | |
|
529 | } | |||
729 |
|
530 | |||
730 | if (mFirstMarker < 0) |
|
531 | void QLegend::hideEvent(QHideEvent *event) | |
731 | mFirstMarker = 0; |
|
532 | { | |
|
533 | QGraphicsWidget::hideEvent(event); | |||
|
534 | setEnabled(false); | |||
|
535 | updateLayout(); | |||
732 | } |
|
536 | } | |
733 |
|
537 | |||
734 | /*! |
|
538 | void QLegend::showEvent(QShowEvent *event) | |
735 | \internal Helper function. Visibility of scroll buttons isn't quite obvious, so helper function clarifies the logic. |
|
|||
736 | */ |
|
|||
737 | bool QLegend::scrollButtonsVisible() |
|
|||
738 | { |
|
539 | { | |
739 | // Just a helper to clarify, what the magic below means :) |
|
540 | QGraphicsWidget::showEvent(event); | |
740 | if ((m_alignment == QLegend::AlignmentTop) || (m_alignment == QLegend::AlignmentBottom)) { |
|
541 | setEnabled(true); | |
741 | return (maximumMarkerSize().width() * m_markers.count() + m_margin * 2 > m_maximumSize.width()); |
|
542 | updateLayout(); | |
742 | } else if ((m_alignment == QLegend::AlignmentLeft) || (m_alignment == QLegend::AlignmentRight)) { |
|
543 | } | |
743 | return (maximumMarkerSize().height() * m_markers.count() + m_margin * 2 > m_maximumSize.height()); |
|
|||
744 | } |
|
|||
745 |
|
544 | |||
746 | return (maximumMarkerSize().height() * m_markers.count() + m_margin * 2 > m_maximumSize.height()); |
|
545 | void QLegend::mousePressEvent(QGraphicsSceneMouseEvent* event) | |
|
546 | { | |||
|
547 | //Q_UNUSED(event); | |||
|
548 | m_scroller->mousePressEvent(event); | |||
|
549 | } | |||
|
550 | void QLegend::mouseMoveEvent(QGraphicsSceneMouseEvent* event) | |||
|
551 | { | |||
|
552 | //Q_UNUSED(event); | |||
|
553 | m_scroller->mouseMoveEvent(event); | |||
|
554 | } | |||
|
555 | void QLegend::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) | |||
|
556 | { | |||
|
557 | //Q_UNUSED(event); | |||
|
558 | m_scroller->mouseReleaseEvent(event); | |||
747 | } |
|
559 | } | |
748 |
|
560 | |||
749 | #include "moc_qlegend.cpp" |
|
561 | #include "moc_qlegend.cpp" | |
750 |
|
562 | |||
751 | QTCOMMERCIALCHART_END_NAMESPACE |
|
563 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,147 +1,153 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef QLEGEND_H |
|
21 | #ifndef QLEGEND_H | |
22 | #define QLEGEND_H |
|
22 | #define QLEGEND_H | |
23 |
|
23 | |||
24 | #include <QChartGlobal> |
|
24 | #include <QChartGlobal> | |
25 | #include <QGraphicsWidget> |
|
25 | #include <QGraphicsWidget> | |
26 | #include <QPen> |
|
26 | #include <QPen> | |
27 | #include <QBrush> |
|
27 | #include <QBrush> | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 | class Domain; |
|
31 | class Domain; | |
32 | class LegendMarker; |
|
32 | class LegendMarker; | |
33 | class QPieSlice; |
|
33 | class QPieSlice; | |
34 | class QXYSeries; |
|
34 | class QXYSeries; | |
35 | class QBarSet; |
|
35 | class QBarSet; | |
36 | class QBarSeries; |
|
36 | class QBarSeries; | |
37 | class QPieSeries; |
|
37 | class QPieSeries; | |
38 | class QAreaSeries; |
|
38 | class QAreaSeries; | |
39 | class LegendScrollButton; |
|
39 | class LegendScrollButton; | |
40 | class QSeries; |
|
40 | class QSeries; | |
41 | class QChart; |
|
41 | class QChart; | |
|
42 | class Scroller; | |||
42 |
|
43 | |||
43 | class QTCOMMERCIALCHART_EXPORT QLegend : public QGraphicsWidget |
|
44 | class QTCOMMERCIALCHART_EXPORT QLegend : public QGraphicsWidget | |
44 | { |
|
45 | { | |
45 | Q_OBJECT |
|
46 | Q_OBJECT | |
46 | public: |
|
47 | public: | |
47 |
|
48 | |||
48 | // We only support these alignments (for now) |
|
49 | // We only support these alignments (for now) | |
49 | enum Alignment { |
|
50 | enum Alignment { | |
50 | AlignmentTop = Qt::AlignTop, |
|
51 | AlignmentTop = Qt::AlignTop, | |
51 | AlignmentBottom = Qt::AlignBottom, |
|
52 | AlignmentBottom = Qt::AlignBottom, | |
52 | AlignmentLeft = Qt::AlignLeft, |
|
53 | AlignmentLeft = Qt::AlignLeft, | |
53 | AlignmentRight = Qt::AlignRight |
|
54 | AlignmentRight = Qt::AlignRight | |
54 | }; |
|
55 | }; | |
55 |
|
56 | |||
56 | Q_DECLARE_FLAGS(Alignments, Alignment) |
|
57 | Q_DECLARE_FLAGS(Alignments, Alignment) | |
57 |
|
58 | |||
58 | private: |
|
59 | private: | |
59 | explicit QLegend(QChart *chart); |
|
60 | explicit QLegend(QChart *chart); | |
60 |
|
61 | |||
61 | public: |
|
62 | public: | |
62 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); |
|
63 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); | |
63 | QRectF boundingRect() const; |
|
64 | QRectF boundingRect() const; | |
64 |
|
65 | |||
65 | void setBrush(const QBrush &brush); |
|
66 | void setBrush(const QBrush &brush); | |
66 | QBrush brush() const; |
|
67 | QBrush brush() const; | |
67 |
|
68 | |||
68 | void setPen(const QPen &pen); |
|
69 | void setPen(const QPen &pen); | |
69 | QPen pen() const; |
|
70 | QPen pen() const; | |
70 |
|
71 | |||
71 | void setAlignmnent(QLegend::Alignments alignment); |
|
72 | void setAlignmnent(QLegend::Alignments alignment); | |
72 | QLegend::Alignments alignment() const; |
|
73 | QLegend::Alignments alignment() const; | |
73 |
|
74 | |||
74 | QSizeF maximumSize() const; |
|
|||
75 | void setMaximumSize(const QSizeF size); |
|
|||
76 |
|
||||
77 | QSizeF size() const; |
|
|||
78 | void setSize(const QSizeF size); |
|
|||
79 | void setPos(const QPointF &pos); |
|
|||
80 |
|
||||
81 | void scrollButtonClicked(LegendScrollButton *scrollButton); |
|
|||
82 |
|
75 | |||
83 | void detachFromChart(); |
|
76 | void detachFromChart(); | |
84 | void attachToChart(); |
|
77 | void attachToChart(); | |
85 |
bool |
|
78 | bool isAttachedToChart(); | |
|
79 | ||||
|
80 | qreal minWidht() const { return m_minWidth;} | |||
|
81 | qreal minHeight() const { return m_minHeight;} | |||
86 |
|
82 | |||
87 | Q_SIGNALS: |
|
83 | void setBackgroundVisible(bool visible); | |
88 | // for interactions. |
|
84 | bool isBackgroundVisible() const; | |
89 | void clicked(QSeries *series, Qt::MouseButton button); |
|
85 | ||
90 | void clicked(QBarSet *barset, Qt::MouseButton button); |
|
86 | void setOffset(const QPointF& point); | |
91 | void clicked(QPieSlice *slice, Qt::MouseButton button); |
|
87 | QPointF offset() const; | |
92 | void legendGeometryChanged(); |
|
88 | ||
|
89 | protected: | |||
|
90 | void resizeEvent(QGraphicsSceneResizeEvent *event); | |||
|
91 | void hideEvent(QHideEvent *event); | |||
|
92 | void showEvent(QShowEvent *event); | |||
|
93 | void mousePressEvent(QGraphicsSceneMouseEvent* event); | |||
|
94 | void mouseMoveEvent(QGraphicsSceneMouseEvent* event); | |||
|
95 | void mouseReleaseEvent(QGraphicsSceneMouseEvent* event); | |||
93 |
|
96 | |||
94 | public Q_SLOTS: |
|
97 | public Q_SLOTS: | |
95 | // PIMPL ---> |
|
98 | // PIMPL ---> | |
96 | void handleSeriesAdded(QSeries *series, Domain *domain); |
|
99 | void handleSeriesAdded(QSeries *series, Domain *domain); | |
97 | void handleSeriesRemoved(QSeries *series); |
|
100 | void handleSeriesRemoved(QSeries *series); | |
98 | void handleAdded(QList<QPieSlice *> slices); |
|
101 | void handleAdded(QList<QPieSlice *> slices); | |
99 | void handleRemoved(QList<QPieSlice *> slices); |
|
102 | void handleRemoved(QList<QPieSlice *> slices); | |
100 | void handleMarkerDestroyed(); |
|
103 | void handleMarkerDestroyed(); | |
101 |
|
104 | |||
102 | // PIMPL <--- |
|
105 | // PIMPL <--- | |
103 |
|
106 | |||
104 | private: |
|
107 | private: | |
105 | // PIMPL ---> |
|
108 | // PIMPL ---> | |
106 | void appendMarkers(QAreaSeries *series); |
|
109 | void appendMarkers(QAreaSeries *series); | |
107 | void appendMarkers(QXYSeries *series); |
|
110 | void appendMarkers(QXYSeries *series); | |
108 | void appendMarkers(QBarSeries *series); |
|
111 | void appendMarkers(QBarSeries *series); | |
109 | void appendMarkers(QPieSeries *series); |
|
112 | void appendMarkers(QPieSeries *series); | |
110 | void deleteMarkers(QSeries *series); |
|
113 | void deleteMarkers(QSeries *series); | |
|
114 | ||||
|
115 | ||||
|
116 | ||||
|
117 | ||||
|
118 | private Q_SLOTS: | |||
111 | void updateLayout(); |
|
119 | void updateLayout(); | |
112 |
void |
|
120 | void scroll(); | |
113 | void layoutVertical(); |
|
|||
114 | void rescaleScrollButtons(const QSize &size); |
|
|||
115 | QSizeF maximumMarkerSize(); |
|
|||
116 | void checkFirstMarkerBounds(); |
|
|||
117 | bool scrollButtonsVisible(); |
|
|||
118 |
|
121 | |||
|
122 | private: | |||
119 | qreal m_margin; |
|
123 | qreal m_margin; | |
120 | QPointF m_pos; |
|
|||
121 | QSizeF m_minimumSize; |
|
|||
122 | QSizeF m_maximumSize; |
|
|||
123 | QSizeF m_size; |
|
|||
124 |
|
124 | |||
125 | QList<LegendMarker *> m_markers; |
|
125 | QRectF m_rect; | |
|
126 | qreal m_offsetX; | |||
|
127 | qreal m_offsetY; | |||
|
128 | ||||
|
129 | //QList<LegendMarker *> m_markers; | |||
126 |
|
130 | |||
127 | QBrush m_brush; |
|
131 | QBrush m_brush; | |
128 | QPen m_pen; |
|
132 | QPen m_pen; | |
129 | QLegend::Alignments m_alignment; |
|
133 | QLegend::Alignments m_alignment; | |
|
134 | QGraphicsItemGroup* m_markers; | |||
130 |
|
135 | |||
131 | int mFirstMarker; |
|
|||
132 |
|
||||
133 | LegendScrollButton *m_scrollButtonLeft; |
|
|||
134 | LegendScrollButton *m_scrollButtonRight; |
|
|||
135 | LegendScrollButton *m_scrollButtonUp; |
|
|||
136 | LegendScrollButton *m_scrollButtonDown; |
|
|||
137 |
|
136 | |||
138 | bool m_attachedToChart; |
|
137 | bool m_attachedToChart; | |
139 |
|
138 | |||
140 | QChart *m_chart; |
|
139 | QChart *m_chart; | |
|
140 | qreal m_minWidth; | |||
|
141 | qreal m_minHeight; | |||
|
142 | qreal m_width; | |||
|
143 | qreal m_height; | |||
|
144 | bool m_visible; | |||
|
145 | bool m_dirty; | |||
|
146 | Scroller* m_scroller; | |||
141 | friend class QChart; |
|
147 | friend class QChart; | |
142 | // <--- PIMPL |
|
148 | // <--- PIMPL | |
143 | }; |
|
149 | }; | |
144 |
|
150 | |||
145 | QTCOMMERCIALCHART_END_NAMESPACE |
|
151 | QTCOMMERCIALCHART_END_NAMESPACE | |
146 |
|
152 | |||
147 | #endif // QLEGEND_H |
|
153 | #endif // QLEGEND_H |
@@ -1,170 +1,172 | |||||
1 | !include( ../common.pri ):error( Couldn't find the common.pri file! ) |
|
1 | !include( ../common.pri ):error( Couldn't find the common.pri file! ) | |
2 | TARGET = QtCommercialChart |
|
2 | TARGET = QtCommercialChart | |
3 | DESTDIR = $$CHART_BUILD_LIB_DIR |
|
3 | DESTDIR = $$CHART_BUILD_LIB_DIR | |
4 | TEMPLATE = lib |
|
4 | TEMPLATE = lib | |
5 | QT += core \ |
|
5 | QT += core \ | |
6 | gui |
|
6 | gui | |
7 | win32-msvc*: LIBS += User32.lib |
|
7 | win32-msvc*: LIBS += User32.lib | |
8 | CONFIG += debug_and_release |
|
8 | CONFIG += debug_and_release | |
9 | CONFIG(debug, debug|release):TARGET = QtCommercialChartd |
|
9 | CONFIG(debug, debug|release):TARGET = QtCommercialChartd | |
10 | SOURCES += \ |
|
10 | SOURCES += \ | |
11 | $$PWD/chartdataset.cpp \ |
|
11 | $$PWD/chartdataset.cpp \ | |
12 | $$PWD/chartpresenter.cpp \ |
|
12 | $$PWD/chartpresenter.cpp \ | |
13 | $$PWD/charttheme.cpp \ |
|
13 | $$PWD/charttheme.cpp \ | |
14 | $$PWD/domain.cpp \ |
|
14 | $$PWD/domain.cpp \ | |
15 | $$PWD/qchart.cpp \ |
|
15 | $$PWD/qchart.cpp \ | |
16 | $$PWD/qchartview.cpp \ |
|
16 | $$PWD/qchartview.cpp \ | |
17 | $$PWD/qseries.cpp \ |
|
17 | $$PWD/qseries.cpp \ | |
18 | $$PWD/qlegend.cpp \ |
|
18 | $$PWD/qlegend.cpp \ | |
19 | $$PWD/legendmarker.cpp \ |
|
19 | $$PWD/legendmarker.cpp \ | |
20 | $$PWD/legendscrollbutton.cpp \ |
|
20 | $$PWD/legendscrollbutton.cpp \ | |
21 | $$PWD/chartbackground.cpp \ |
|
21 | $$PWD/chartbackground.cpp \ | |
22 | $$PWD/chart.cpp |
|
22 | $$PWD/chart.cpp \ | |
|
23 | $$PWD/scroller.cpp | |||
23 | PRIVATE_HEADERS += \ |
|
24 | PRIVATE_HEADERS += \ | |
24 | $$PWD/chartdataset_p.h \ |
|
25 | $$PWD/chartdataset_p.h \ | |
25 | $$PWD/chartitem_p.h \ |
|
26 | $$PWD/chartitem_p.h \ | |
26 | $$PWD/chartpresenter_p.h \ |
|
27 | $$PWD/chartpresenter_p.h \ | |
27 | $$PWD/charttheme_p.h \ |
|
28 | $$PWD/charttheme_p.h \ | |
28 | $$PWD/domain_p.h \ |
|
29 | $$PWD/domain_p.h \ | |
29 | $$PWD/legendmarker_p.h \ |
|
30 | $$PWD/legendmarker_p.h \ | |
30 | $$PWD/legendscrollbutton_p.h \ |
|
31 | $$PWD/legendscrollbutton_p.h \ | |
31 | $$PWD/chartbackground_p.h \ |
|
32 | $$PWD/chartbackground_p.h \ | |
32 | $$PWD/chart_p.h \ |
|
33 | $$PWD/chart_p.h \ | |
33 | $$PWD/chartconfig_p.h \ |
|
34 | $$PWD/chartconfig_p.h \ | |
34 | $$PWD/qchart_p.h \ |
|
35 | $$PWD/qchart_p.h \ | |
35 | $$PWD/qchartview_p.h |
|
36 | $$PWD/qchartview_p.h \ | |
|
37 | $$PWD/scroller_p.h | |||
36 | PUBLIC_HEADERS += \ |
|
38 | PUBLIC_HEADERS += \ | |
37 | $$PWD/qchart.h \ |
|
39 | $$PWD/qchart.h \ | |
38 | $$PWD/qchartglobal.h \ |
|
40 | $$PWD/qchartglobal.h \ | |
39 | $$PWD/qseries.h \ |
|
41 | $$PWD/qseries.h \ | |
40 | $$PWD/qchartview.h \ |
|
42 | $$PWD/qchartview.h \ | |
41 | $$PWD/qlegend.h |
|
43 | $$PWD/qlegend.h | |
42 |
|
44 | |||
43 | include(animations/animations.pri) |
|
45 | include(animations/animations.pri) | |
44 | include(axis/axis.pri) |
|
46 | include(axis/axis.pri) | |
45 | include(xychart/xychart.pri) |
|
47 | include(xychart/xychart.pri) | |
46 | include(linechart/linechart.pri) |
|
48 | include(linechart/linechart.pri) | |
47 | include(areachart/areachart.pri) |
|
49 | include(areachart/areachart.pri) | |
48 | include(barchart/barchart.pri) |
|
50 | include(barchart/barchart.pri) | |
49 | include(piechart/piechart.pri) |
|
51 | include(piechart/piechart.pri) | |
50 | include(scatterseries/scatter.pri) |
|
52 | include(scatterseries/scatter.pri) | |
51 | include(splinechart/splinechart.pri) |
|
53 | include(splinechart/splinechart.pri) | |
52 | include(themes/themes.pri) |
|
54 | include(themes/themes.pri) | |
53 |
|
55 | |||
54 |
|
56 | |||
55 | HEADERS += $$PUBLIC_HEADERS |
|
57 | HEADERS += $$PUBLIC_HEADERS | |
56 | HEADERS += $$PRIVATE_HEADERS |
|
58 | HEADERS += $$PRIVATE_HEADERS | |
57 | HEADERS += $$THEMES |
|
59 | HEADERS += $$THEMES | |
58 | INCLUDEPATH += ../include . |
|
60 | INCLUDEPATH += ../include . | |
59 |
|
61 | |||
60 | OBJECTS_DIR = $$CHART_BUILD_DIR/lib |
|
62 | OBJECTS_DIR = $$CHART_BUILD_DIR/lib | |
61 | MOC_DIR = $$CHART_BUILD_DIR/lib |
|
63 | MOC_DIR = $$CHART_BUILD_DIR/lib | |
62 | UI_DIR = $$CHART_BUILD_DIR/lib |
|
64 | UI_DIR = $$CHART_BUILD_DIR/lib | |
63 | RCC_DIR = $$CHART_BUILD_DIR/lib |
|
65 | RCC_DIR = $$CHART_BUILD_DIR/lib | |
64 | DEFINES += QTCOMMERCIALCHART_LIBRARY |
|
66 | DEFINES += QTCOMMERCIALCHART_LIBRARY | |
65 |
|
67 | |||
66 | #qt public headers |
|
68 | #qt public headers | |
67 | #this is very primitive and lame parser , TODO: make perl script insted |
|
69 | #this is very primitive and lame parser , TODO: make perl script insted | |
68 | !exists($$CHART_BUILD_PUBLIC_HEADER_DIR/QChartGlobal) |
|
70 | !exists($$CHART_BUILD_PUBLIC_HEADER_DIR/QChartGlobal) | |
69 | { |
|
71 | { | |
70 | system($$QMAKE_MKDIR $$CHART_BUILD_PUBLIC_HEADER_DIR) |
|
72 | system($$QMAKE_MKDIR $$CHART_BUILD_PUBLIC_HEADER_DIR) | |
71 | win32:{ |
|
73 | win32:{ | |
72 | command = "echo $${LITERAL_HASH}include \"qchartglobal.h\" > $$CHART_BUILD_PUBLIC_HEADER_DIR/QChartGlobal" |
|
74 | command = "echo $${LITERAL_HASH}include \"qchartglobal.h\" > $$CHART_BUILD_PUBLIC_HEADER_DIR/QChartGlobal" | |
73 | }else{ |
|
75 | }else{ | |
74 | command = "echo \"$${LITERAL_HASH}include \\\"qchartglobal.h\\\"\" > $$CHART_BUILD_PUBLIC_HEADER_DIR/QChartGlobal" |
|
76 | command = "echo \"$${LITERAL_HASH}include \\\"qchartglobal.h\\\"\" > $$CHART_BUILD_PUBLIC_HEADER_DIR/QChartGlobal" | |
75 | } |
|
77 | } | |
76 | system($$command) |
|
78 | system($$command) | |
77 | } |
|
79 | } | |
78 |
|
80 | |||
79 | for(file, PUBLIC_HEADERS) { |
|
81 | for(file, PUBLIC_HEADERS) { | |
80 | name = $$split(file,'/') |
|
82 | name = $$split(file,'/') | |
81 | name = $$last(name) |
|
83 | name = $$last(name) | |
82 | class = "$$cat($$file)" |
|
84 | class = "$$cat($$file)" | |
83 | class = $$find(class,class) |
|
85 | class = $$find(class,class) | |
84 | !isEmpty(class){ |
|
86 | !isEmpty(class){ | |
85 | class = $$split(class,QTCOMMERCIALCHART_EXPORT) |
|
87 | class = $$split(class,QTCOMMERCIALCHART_EXPORT) | |
86 | class = $$member(class,1) |
|
88 | class = $$member(class,1) | |
87 | class = $$split(class,' ') |
|
89 | class = $$split(class,' ') | |
88 | class = $$replace(class,' ','') |
|
90 | class = $$replace(class,' ','') | |
89 | class = $$member(class,0) |
|
91 | class = $$member(class,0) | |
90 | win32:{ |
|
92 | win32:{ | |
91 | command = "echo $${LITERAL_HASH}include \"$$name\" > $$CHART_BUILD_PUBLIC_HEADER_DIR/$$class" |
|
93 | command = "echo $${LITERAL_HASH}include \"$$name\" > $$CHART_BUILD_PUBLIC_HEADER_DIR/$$class" | |
92 | }else{ |
|
94 | }else{ | |
93 | command = "echo \"$${LITERAL_HASH}include \\\"$$name\\\"\" > $$CHART_BUILD_PUBLIC_HEADER_DIR/$$class" |
|
95 | command = "echo \"$${LITERAL_HASH}include \\\"$$name\\\"\" > $$CHART_BUILD_PUBLIC_HEADER_DIR/$$class" | |
94 | } |
|
96 | } | |
95 | PUBLIC_QT_HEADERS += $$CHART_BUILD_PUBLIC_HEADER_DIR/$$class |
|
97 | PUBLIC_QT_HEADERS += $$CHART_BUILD_PUBLIC_HEADER_DIR/$$class | |
96 | system($$command) |
|
98 | system($$command) | |
97 | } |
|
99 | } | |
98 | } |
|
100 | } | |
99 |
|
101 | |||
100 | public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart |
|
102 | public_headers.path = $$[QT_INSTALL_HEADERS]/QtCommercialChart | |
101 | public_headers.files = $$PUBLIC_HEADERS $$PUBLIC_QT_HEADERS |
|
103 | public_headers.files = $$PUBLIC_HEADERS $$PUBLIC_QT_HEADERS | |
102 |
|
104 | |||
103 | target.path = $$[QT_INSTALL_LIBS] |
|
105 | target.path = $$[QT_INSTALL_LIBS] | |
104 | INSTALLS += target public_headers |
|
106 | INSTALLS += target public_headers | |
105 |
|
107 | |||
106 | install_build_public_headers.name = build_public_headers |
|
108 | install_build_public_headers.name = build_public_headers | |
107 | install_build_public_headers.output = $$CHART_BUILD_PUBLIC_HEADER_DIR/${QMAKE_FILE_BASE}.h |
|
109 | install_build_public_headers.output = $$CHART_BUILD_PUBLIC_HEADER_DIR/${QMAKE_FILE_BASE}.h | |
108 | install_build_public_headers.input = PUBLIC_HEADERS |
|
110 | install_build_public_headers.input = PUBLIC_HEADERS | |
109 | install_build_public_headers.commands = $$QMAKE_COPY \ |
|
111 | install_build_public_headers.commands = $$QMAKE_COPY \ | |
110 | ${QMAKE_FILE_NAME} \ |
|
112 | ${QMAKE_FILE_NAME} \ | |
111 | $$CHART_BUILD_PUBLIC_HEADER_DIR |
|
113 | $$CHART_BUILD_PUBLIC_HEADER_DIR | |
112 | install_build_public_headers.CONFIG += target_predeps \ |
|
114 | install_build_public_headers.CONFIG += target_predeps \ | |
113 | no_link |
|
115 | no_link | |
114 |
|
116 | |||
115 | install_build_private_headers.name = buld_private_headers |
|
117 | install_build_private_headers.name = buld_private_headers | |
116 | install_build_private_headers.output = $$CHART_BUILD_PRIVATE_HEADER_DIR/${QMAKE_FILE_BASE}.h |
|
118 | install_build_private_headers.output = $$CHART_BUILD_PRIVATE_HEADER_DIR/${QMAKE_FILE_BASE}.h | |
117 | install_build_private_headers.input = PRIVATE_HEADERS |
|
119 | install_build_private_headers.input = PRIVATE_HEADERS | |
118 | install_build_private_headers.commands = $$QMAKE_COPY \ |
|
120 | install_build_private_headers.commands = $$QMAKE_COPY \ | |
119 | ${QMAKE_FILE_NAME} \ |
|
121 | ${QMAKE_FILE_NAME} \ | |
120 | $$CHART_BUILD_PRIVATE_HEADER_DIR |
|
122 | $$CHART_BUILD_PRIVATE_HEADER_DIR | |
121 | install_build_private_headers.CONFIG += target_predeps \ |
|
123 | install_build_private_headers.CONFIG += target_predeps \ | |
122 | no_link |
|
124 | no_link | |
123 |
|
125 | |||
124 | QMAKE_EXTRA_COMPILERS += install_build_public_headers \ |
|
126 | QMAKE_EXTRA_COMPILERS += install_build_public_headers \ | |
125 | install_build_private_headers \ |
|
127 | install_build_private_headers \ | |
126 |
|
128 | |||
127 |
|
129 | |||
128 | !win32-msvc*: { |
|
130 | !win32-msvc*: { | |
129 |
|
131 | |||
130 | # There is a problem with jom.exe currently. It does not seem to understand QMAKE_EXTRA_TARGETS properly. |
|
132 | # There is a problem with jom.exe currently. It does not seem to understand QMAKE_EXTRA_TARGETS properly. | |
131 | # This is the case at least with shadow builds. |
|
133 | # This is the case at least with shadow builds. | |
132 | # http://qt-project.org/wiki/jom |
|
134 | # http://qt-project.org/wiki/jom | |
133 |
|
135 | |||
134 | chartversion.target = $$PWD/qchartversion_p.h |
|
136 | chartversion.target = $$PWD/qchartversion_p.h | |
135 |
|
137 | |||
136 | unix:{ |
|
138 | unix:{ | |
137 | chartversion.commands = @echo \ |
|
139 | chartversion.commands = @echo \ | |
138 | "const char *buildTime = \\\"`date +'%y%m%d%H%M'`\\\" \\; \ |
|
140 | "const char *buildTime = \\\"`date +'%y%m%d%H%M'`\\\" \\; \ | |
139 | const char *gitHead = \\\"`git rev-parse HEAD`\\\" \\; " \ |
|
141 | const char *gitHead = \\\"`git rev-parse HEAD`\\\" \\; " \ | |
140 | > \ |
|
142 | > \ | |
141 | $$chartversion.target; |
|
143 | $$chartversion.target; | |
142 | }else{ |
|
144 | }else{ | |
143 | chartversion.commands = @echo \ |
|
145 | chartversion.commands = @echo \ | |
144 | "const char *buildTime = \"%date%_%time%\" ; \ |
|
146 | "const char *buildTime = \"%date%_%time%\" ; \ | |
145 | const char *gitHead = \"unknown\" ; " \ |
|
147 | const char *gitHead = \"unknown\" ; " \ | |
146 | > \ |
|
148 | > \ | |
147 | $$chartversion.target |
|
149 | $$chartversion.target | |
148 | } |
|
150 | } | |
149 |
|
151 | |||
150 | chartversion.depends = $$HEADERS \ |
|
152 | chartversion.depends = $$HEADERS \ | |
151 | $$SOURCES |
|
153 | $$SOURCES | |
152 |
|
154 | |||
153 | PRE_TARGETDEPS += $$PWD/qchartversion_p.h |
|
155 | PRE_TARGETDEPS += $$PWD/qchartversion_p.h | |
154 | QMAKE_CLEAN += $$PWD/qchartversion_p.h |
|
156 | QMAKE_CLEAN += $$PWD/qchartversion_p.h | |
155 | QMAKE_EXTRA_TARGETS += chartversion |
|
157 | QMAKE_EXTRA_TARGETS += chartversion | |
156 | } |
|
158 | } | |
157 |
|
159 | |||
158 | unix:QMAKE_DISTCLEAN += -r \ |
|
160 | unix:QMAKE_DISTCLEAN += -r \ | |
159 | $$CHART_BUILD_HEADER_DIR \ |
|
161 | $$CHART_BUILD_HEADER_DIR \ | |
160 | $$CHART_BUILD_LIB_DIR |
|
162 | $$CHART_BUILD_LIB_DIR | |
161 | win32:QMAKE_DISTCLEAN += /Q \ |
|
163 | win32:QMAKE_DISTCLEAN += /Q \ | |
162 | $$CHART_BUILD_HEADER_DIR \ |
|
164 | $$CHART_BUILD_HEADER_DIR \ | |
163 | $$CHART_BUILD_LIB_DIR |
|
165 | $$CHART_BUILD_LIB_DIR | |
164 |
|
166 | |||
165 | # treat warnings as errors |
|
167 | # treat warnings as errors | |
166 | win32-msvc*: { |
|
168 | win32-msvc*: { | |
167 | QMAKE_CXXFLAGS += /WX |
|
169 | QMAKE_CXXFLAGS += /WX | |
168 | } else { |
|
170 | } else { | |
169 | QMAKE_CXXFLAGS += -Werror |
|
171 | QMAKE_CXXFLAGS += -Werror | |
170 | } |
|
172 | } |
@@ -1,101 +1,102 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef QXYSERIES_H_ |
|
21 | #ifndef QXYSERIES_H_ | |
22 | #define QXYSERIES_H_ |
|
22 | #define QXYSERIES_H_ | |
23 |
|
23 | |||
24 | #include <qchartglobal.h> |
|
24 | #include <qchartglobal.h> | |
25 | #include <qseries.h> |
|
25 | #include <qseries.h> | |
26 | #include <QPen> |
|
26 | #include <QPen> | |
27 | #include <QBrush> |
|
27 | #include <QBrush> | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 | class QTCOMMERCIALCHART_EXPORT QXYSeries : public QSeries |
|
31 | class QTCOMMERCIALCHART_EXPORT QXYSeries : public QSeries | |
32 | { |
|
32 | { | |
33 | Q_OBJECT |
|
33 | Q_OBJECT | |
34 | protected: |
|
34 | protected: | |
35 | QXYSeries(QObject *parent = 0); |
|
35 | QXYSeries(QObject *parent = 0); | |
36 | virtual ~QXYSeries(); |
|
36 | virtual ~QXYSeries(); | |
37 |
|
37 | |||
38 | public: |
|
38 | public: | |
39 | void append(qreal x, qreal y); |
|
39 | void append(qreal x, qreal y); | |
40 | void append(const QPointF &point); |
|
40 | void append(const QPointF &point); | |
41 | void append(const QList<QPointF> points); |
|
41 | void append(const QList<QPointF> points); | |
42 | void replace(qreal x,qreal y); |
|
42 | void replace(qreal x,qreal y); | |
43 | void replace(const QPointF &point); |
|
43 | void replace(const QPointF &point); | |
44 | void remove(qreal x); |
|
44 | void remove(qreal x); | |
45 | void remove(qreal x, qreal y); |
|
45 | void remove(qreal x, qreal y); | |
46 | void remove(const QPointF &point); |
|
46 | void remove(const QPointF &point); | |
47 | void removeAll(); |
|
47 | void removeAll(); | |
48 |
|
48 | |||
49 | int count() const; |
|
49 | int count() const; | |
50 | qreal x(int pos) const; |
|
50 | qreal x(int pos) const; | |
51 | qreal y(int pos) const; |
|
51 | qreal y(int pos) const; | |
52 | QList<QPointF> data(); |
|
52 | QList<QPointF> data(); | |
53 |
|
53 | |||
54 | QXYSeries& operator << (const QPointF &point); |
|
54 | QXYSeries& operator << (const QPointF &point); | |
55 | QXYSeries& operator << (const QList<QPointF> points); |
|
55 | QXYSeries& operator << (const QList<QPointF> points); | |
56 |
|
56 | |||
57 | void setPen(const QPen &pen); |
|
57 | void setPen(const QPen &pen); | |
58 | QPen pen() const {return m_pen;} |
|
58 | QPen pen() const {return m_pen;} | |
59 | void setBrush(const QBrush &brush); |
|
59 | void setBrush(const QBrush &brush); | |
60 | QBrush brush() const {return m_brush;} |
|
60 | QBrush brush() const {return m_brush;} | |
61 |
|
61 | |||
62 | bool setModel(QAbstractItemModel *model); |
|
62 | bool setModel(QAbstractItemModel *model); | |
63 | QAbstractItemModel* model() const { return m_model; } |
|
63 | QAbstractItemModel* model() const { return m_model; } | |
64 |
|
64 | |||
65 | virtual void setModelMapping(int modelX, int modelY, Qt::Orientation orientation = Qt::Vertical); |
|
65 | virtual void setModelMapping(int modelX, int modelY, Qt::Orientation orientation = Qt::Vertical); | |
66 | virtual void setModelMappingShift(int first, int count = 0); |
|
66 | virtual void setModelMappingShift(int first, int count = 0); | |
67 | int mapFirst() const { return m_mapFirst; } |
|
67 | int mapFirst() const { return m_mapFirst; } | |
68 |
|
68 | |||
69 | private Q_SLOTS: |
|
69 | private Q_SLOTS: | |
70 | void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); |
|
70 | void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); | |
71 | void modelDataAboutToBeAdded(QModelIndex parent, int start, int end); |
|
71 | void modelDataAboutToBeAdded(QModelIndex parent, int start, int end); | |
72 | void modelDataAdded(QModelIndex parent, int start, int end); |
|
72 | void modelDataAdded(QModelIndex parent, int start, int end); | |
73 | void modelDataAboutToBeRemoved(QModelIndex parent, int start, int end); |
|
73 | void modelDataAboutToBeRemoved(QModelIndex parent, int start, int end); | |
74 | void modelDataRemoved(QModelIndex parent, int start, int end); |
|
74 | void modelDataRemoved(QModelIndex parent, int start, int end); | |
75 |
|
75 | |||
76 | Q_SIGNALS: |
|
76 | Q_SIGNALS: | |
77 | void clicked(const QPointF &point); |
|
77 | void clicked(const QPointF &point); | |
|
78 | void selected(); | |||
78 | void updated(); |
|
79 | void updated(); | |
79 | void pointReplaced(int index); |
|
80 | void pointReplaced(int index); | |
80 | void pointRemoved(int index); |
|
81 | void pointRemoved(int index); | |
81 | void pointAdded(int index); |
|
82 | void pointAdded(int index); | |
82 |
|
83 | |||
83 | protected: |
|
84 | protected: | |
84 | QVector<qreal> m_x; |
|
85 | QVector<qreal> m_x; | |
85 | QVector<qreal> m_y; |
|
86 | QVector<qreal> m_y; | |
86 |
|
87 | |||
87 | QPen m_pen; |
|
88 | QPen m_pen; | |
88 | QBrush m_brush; |
|
89 | QBrush m_brush; | |
89 |
|
90 | |||
90 |
int m_mapX; |
|
91 | int m_mapX; | |
91 | int m_mapY; |
|
92 | int m_mapY; | |
92 | int m_mapFirst; |
|
93 | int m_mapFirst; | |
93 | int m_mapCount; |
|
94 | int m_mapCount; | |
94 | bool m_mapLimited; |
|
95 | bool m_mapLimited; | |
95 | Qt::Orientation m_mapOrientation; |
|
96 | Qt::Orientation m_mapOrientation; | |
96 | int tempItemsRemoved; |
|
97 | int tempItemsRemoved; | |
97 | }; |
|
98 | }; | |
98 |
|
99 | |||
99 | QTCOMMERCIALCHART_END_NAMESPACE |
|
100 | QTCOMMERCIALCHART_END_NAMESPACE | |
100 |
|
101 | |||
101 | #endif |
|
102 | #endif |
@@ -1,213 +1,213 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 |
|
21 | |||
22 | #include <QtTest/QtTest> |
|
22 | #include <QtTest/QtTest> | |
23 | #include <qchartview.h> |
|
23 | #include <qchartview.h> | |
24 | #include <qlineseries.h> |
|
24 | #include <qlineseries.h> | |
25 | #include <cmath> |
|
25 | #include <cmath> | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
27 | QTCOMMERCIALCHART_USE_NAMESPACE | |
28 |
|
28 | |||
29 |
|
29 | |||
30 | Q_DECLARE_METATYPE(QChart*) |
|
30 | Q_DECLARE_METATYPE(QChart*) | |
31 | Q_DECLARE_METATYPE(QChartView::RubberBands) |
|
31 | Q_DECLARE_METATYPE(QChartView::RubberBands) | |
32 | Q_DECLARE_METATYPE(Qt::Key) |
|
32 | Q_DECLARE_METATYPE(Qt::Key) | |
33 |
|
33 | |||
34 | class tst_QChartView : public QObject |
|
34 | class tst_QChartView : public QObject | |
35 | { |
|
35 | { | |
36 | Q_OBJECT |
|
36 | Q_OBJECT | |
37 |
|
37 | |||
38 | public Q_SLOTS: |
|
38 | public Q_SLOTS: | |
39 | void initTestCase(); |
|
39 | void initTestCase(); | |
40 | void cleanupTestCase(); |
|
40 | void cleanupTestCase(); | |
41 | void init(); |
|
41 | void init(); | |
42 | void cleanup(); |
|
42 | void cleanup(); | |
43 |
|
43 | |||
44 | private Q_SLOTS: |
|
44 | private Q_SLOTS: | |
45 | void qchartview_data(); |
|
45 | void qchartview_data(); | |
46 | void qchartview(); |
|
46 | void qchartview(); | |
47 | void chart_data(); |
|
47 | void chart_data(); | |
48 | void chart(); |
|
48 | void chart(); | |
49 | void rubberBand_data(); |
|
49 | void rubberBand_data(); | |
50 | void rubberBand(); |
|
50 | void rubberBand(); | |
51 | void keys_data(); |
|
51 | void keys_data(); | |
52 | void keys(); |
|
52 | void keys(); | |
53 |
|
53 | |||
54 | private: |
|
54 | private: | |
55 | QChartView* m_view; |
|
55 | QChartView* m_view; | |
56 | }; |
|
56 | }; | |
57 |
|
57 | |||
58 | void tst_QChartView::initTestCase() |
|
58 | void tst_QChartView::initTestCase() | |
59 | { |
|
59 | { | |
60 | //test tracks mouse, give a while to user to relese it |
|
60 | //test tracks mouse, give a while to user to relese it | |
61 | QTest::qWait(1000); |
|
61 | QTest::qWait(1000); | |
62 | } |
|
62 | } | |
63 |
|
63 | |||
64 | void tst_QChartView::cleanupTestCase() |
|
64 | void tst_QChartView::cleanupTestCase() | |
65 | { |
|
65 | { | |
66 | } |
|
66 | } | |
67 |
|
67 | |||
68 | void tst_QChartView::init() |
|
68 | void tst_QChartView::init() | |
69 | { |
|
69 | { | |
70 | m_view = new QChartView(new QChart()); |
|
70 | m_view = new QChartView(new QChart()); | |
71 | } |
|
71 | } | |
72 |
|
72 | |||
73 | void tst_QChartView::cleanup() |
|
73 | void tst_QChartView::cleanup() | |
74 | { |
|
74 | { | |
75 | delete m_view; |
|
75 | delete m_view; | |
76 | m_view =0; |
|
76 | m_view =0; | |
77 | } |
|
77 | } | |
78 |
|
78 | |||
79 | void tst_QChartView::qchartview_data() |
|
79 | void tst_QChartView::qchartview_data() | |
80 | { |
|
80 | { | |
81 |
|
81 | |||
82 | } |
|
82 | } | |
83 |
|
83 | |||
84 | void tst_QChartView::qchartview() |
|
84 | void tst_QChartView::qchartview() | |
85 | { |
|
85 | { | |
86 | QVERIFY(m_view->chart()); |
|
86 | QVERIFY(m_view->chart()); | |
87 | QCOMPARE(m_view->rubberBand(), QChartView::NoRubberBand); |
|
87 | QCOMPARE(m_view->rubberBand(), QChartView::NoRubberBand); | |
88 | m_view->show(); |
|
88 | m_view->show(); | |
89 | QTest::qWaitForWindowShown(m_view); |
|
89 | QTest::qWaitForWindowShown(m_view); | |
90 | } |
|
90 | } | |
91 |
|
91 | |||
92 | void tst_QChartView::chart_data() |
|
92 | void tst_QChartView::chart_data() | |
93 | { |
|
93 | { | |
94 |
|
94 | |||
95 | QTest::addColumn<QChart*>("chart"); |
|
95 | QTest::addColumn<QChart*>("chart"); | |
96 | QTest::newRow("qchart") << new QChart(); |
|
96 | QTest::newRow("qchart") << new QChart(); | |
97 | } |
|
97 | } | |
98 |
|
98 | |||
99 | void tst_QChartView::chart() |
|
99 | void tst_QChartView::chart() | |
100 | { |
|
100 | { | |
101 | QFETCH(QChart*, chart); |
|
101 | QFETCH(QChart*, chart); | |
102 | QChartView* view = new QChartView(chart); |
|
102 | QChartView* view = new QChartView(chart); | |
103 | QCOMPARE(view->chart(), chart); |
|
103 | QCOMPARE(view->chart(), chart); | |
104 | delete view; |
|
104 | delete view; | |
105 | } |
|
105 | } | |
106 |
|
106 | |||
107 | void tst_QChartView::rubberBand_data() |
|
107 | void tst_QChartView::rubberBand_data() | |
108 | { |
|
108 | { | |
109 | QTest::addColumn<QChartView::RubberBands>("rubberBand"); |
|
109 | QTest::addColumn<QChartView::RubberBands>("rubberBand"); | |
110 | QTest::addColumn<int>("Xcount"); |
|
110 | QTest::addColumn<int>("Xcount"); | |
111 | QTest::addColumn<int>("Ycount"); |
|
111 | QTest::addColumn<int>("Ycount"); | |
112 |
|
112 | |||
113 | QTest::addColumn<int>("minX"); |
|
113 | QTest::addColumn<int>("minX"); | |
114 | QTest::addColumn<int>("maxX"); |
|
114 | QTest::addColumn<int>("maxX"); | |
115 | QTest::addColumn<int>("minY"); |
|
115 | QTest::addColumn<int>("minY"); | |
116 | QTest::addColumn<int>("maxY"); |
|
116 | QTest::addColumn<int>("maxY"); | |
117 |
|
117 | |||
118 | QTest::newRow("HorizonalRubberBand") << QChartView::RubberBands(QChartView::HorizonalRubberBand) << 0 << 1 << 10 << 90 << 0<< 100; |
|
118 | QTest::newRow("HorizonalRubberBand") << QChartView::RubberBands(QChartView::HorizonalRubberBand) << 0 << 1 << 10 << 90 << 0<< 100; | |
119 | QTest::newRow("VerticalRubberBand") << QChartView::RubberBands(QChartView::VerticalRubberBand) << 1 << 0 << 0 << 100 << 10<< 90; |
|
119 | QTest::newRow("VerticalRubberBand") << QChartView::RubberBands(QChartView::VerticalRubberBand) << 1 << 0 << 0 << 100 << 10<< 90; | |
120 | QTest::newRow("RectangleRubberBand") << QChartView::RubberBands(QChartView::RectangleRubberBand) << 1 << 1 <<10 << 90 << 10<< 90; |
|
120 | QTest::newRow("RectangleRubberBand") << QChartView::RubberBands(QChartView::RectangleRubberBand) << 1 << 1 <<10 << 90 << 10<< 90; | |
121 | } |
|
121 | } | |
122 |
|
122 | |||
123 | void tst_QChartView::rubberBand() |
|
123 | void tst_QChartView::rubberBand() | |
124 | { |
|
124 | { | |
125 | QFETCH(QChartView::RubberBands, rubberBand); |
|
125 | QFETCH(QChartView::RubberBands, rubberBand); | |
126 | QFETCH(int, Xcount); |
|
126 | QFETCH(int, Xcount); | |
127 | QFETCH(int, Ycount); |
|
127 | QFETCH(int, Ycount); | |
128 | QFETCH(int, minX); |
|
128 | QFETCH(int, minX); | |
129 | QFETCH(int, maxX); |
|
129 | QFETCH(int, maxX); | |
130 | QFETCH(int, minY); |
|
130 | QFETCH(int, minY); | |
131 | QFETCH(int, maxY); |
|
131 | QFETCH(int, maxY); | |
132 |
|
132 | |||
133 | m_view->setRubberBand(rubberBand); |
|
133 | m_view->setRubberBand(rubberBand); | |
134 |
QRect padding = m_view->chart()-> |
|
134 | QRect padding = m_view->chart()->margins(); | |
135 | QCOMPARE(m_view->rubberBand(), rubberBand); |
|
135 | QCOMPARE(m_view->rubberBand(), rubberBand); | |
136 |
|
136 | |||
137 | QLineSeries* line = new QLineSeries(); |
|
137 | QLineSeries* line = new QLineSeries(); | |
138 | *line << QPointF(0, 0) << QPointF(100, 100); |
|
138 | *line << QPointF(0, 0) << QPointF(100, 100); | |
139 |
|
139 | |||
140 | m_view->chart()->addSeries(line); |
|
140 | m_view->chart()->addSeries(line); | |
141 | m_view->resize(100 + padding.left() + padding.right(), 100 + padding.top()+ padding.bottom()); |
|
141 | m_view->resize(100 + padding.left() + padding.right(), 100 + padding.top()+ padding.bottom()); | |
142 | m_view->show(); |
|
142 | m_view->show(); | |
143 |
|
143 | |||
144 | //this is hack since view does not get events otherwise |
|
144 | //this is hack since view does not get events otherwise | |
145 | m_view->setMouseTracking(true); |
|
145 | m_view->setMouseTracking(true); | |
146 |
|
146 | |||
147 | QChartAxis* axisY = m_view->chart()->axisY(); |
|
147 | QChartAxis* axisY = m_view->chart()->axisY(); | |
148 | QSignalSpy spy0(axisY, SIGNAL(rangeChanged(qreal, qreal))); |
|
148 | QSignalSpy spy0(axisY, SIGNAL(rangeChanged(qreal, qreal))); | |
149 | QChartAxis* axisX = m_view->chart()->axisX(); |
|
149 | QChartAxis* axisX = m_view->chart()->axisX(); | |
150 | QSignalSpy spy1(axisX, SIGNAL(rangeChanged(qreal, qreal))); |
|
150 | QSignalSpy spy1(axisX, SIGNAL(rangeChanged(qreal, qreal))); | |
151 |
|
151 | |||
152 | QTest::qWaitForWindowShown(m_view); |
|
152 | QTest::qWaitForWindowShown(m_view); | |
153 | QTest::mouseMove(m_view->viewport(), QPoint(minX, minY) + padding.topLeft()); |
|
153 | QTest::mouseMove(m_view->viewport(), QPoint(minX, minY) + padding.topLeft()); | |
154 | QTest::mousePress(m_view->viewport(), Qt::LeftButton, 0, QPoint(minX, minY) + padding.topLeft()); |
|
154 | QTest::mousePress(m_view->viewport(), Qt::LeftButton, 0, QPoint(minX, minY) + padding.topLeft()); | |
155 | QTest::mouseMove(m_view->viewport(), QPoint(maxX, maxY) + padding.topLeft()); |
|
155 | QTest::mouseMove(m_view->viewport(), QPoint(maxX, maxY) + padding.topLeft()); | |
156 | QTest::mouseRelease(m_view->viewport(), Qt::LeftButton, 0, QPoint(maxX, maxY)+ padding.topLeft()); |
|
156 | QTest::mouseRelease(m_view->viewport(), Qt::LeftButton, 0, QPoint(maxX, maxY)+ padding.topLeft()); | |
157 |
|
157 | |||
158 | QCOMPARE(spy0.count(), Xcount); |
|
158 | QCOMPARE(spy0.count(), Xcount); | |
159 | QCOMPARE(spy1.count(), Ycount); |
|
159 | QCOMPARE(spy1.count(), Ycount); | |
160 |
|
160 | |||
161 | //this is hack since view does not get events otherwise |
|
161 | //this is hack since view does not get events otherwise | |
162 | m_view->setMouseTracking(false); |
|
162 | m_view->setMouseTracking(false); | |
163 |
|
163 | |||
164 | QVERIFY(axisX->min() - minX < 1); |
|
164 | QVERIFY(axisX->min() - minX < 1); | |
165 | QVERIFY(axisX->max() - maxX < 1); |
|
165 | QVERIFY(axisX->max() - maxX < 1); | |
166 | QVERIFY(axisY->min() - minY < 1); |
|
166 | QVERIFY(axisY->min() - minY < 1); | |
167 | QVERIFY(axisY->max() - maxY < 1); |
|
167 | QVERIFY(axisY->max() - maxY < 1); | |
168 | } |
|
168 | } | |
169 |
|
169 | |||
170 | void tst_QChartView::keys_data() |
|
170 | void tst_QChartView::keys_data() | |
171 | { |
|
171 | { | |
172 | QTest::addColumn<Qt::Key>("key"); |
|
172 | QTest::addColumn<Qt::Key>("key"); | |
173 | QTest::addColumn<int>("Xcount"); |
|
173 | QTest::addColumn<int>("Xcount"); | |
174 | QTest::addColumn<int>("Ycount"); |
|
174 | QTest::addColumn<int>("Ycount"); | |
175 | QTest::newRow("Qt::Key_Plus") << Qt::Key_Plus << 1 << 1; |
|
175 | QTest::newRow("Qt::Key_Plus") << Qt::Key_Plus << 1 << 1; | |
176 | QTest::newRow("Qt::Key_Minus") << Qt::Key_Minus << 1 << 1; |
|
176 | QTest::newRow("Qt::Key_Minus") << Qt::Key_Minus << 1 << 1; | |
177 | QTest::newRow("Qt::Key_Up") << Qt::Key_Up << 0 << 1; |
|
177 | QTest::newRow("Qt::Key_Up") << Qt::Key_Up << 0 << 1; | |
178 | QTest::newRow("Qt::Key_Down") << Qt::Key_Down << 0 << 1; |
|
178 | QTest::newRow("Qt::Key_Down") << Qt::Key_Down << 0 << 1; | |
179 | QTest::newRow("Qt::Key_Left") << Qt::Key_Left << 1 << 0; |
|
179 | QTest::newRow("Qt::Key_Left") << Qt::Key_Left << 1 << 0; | |
180 | QTest::newRow("Qt::Key_Right") << Qt::Key_Right << 1 << 0; |
|
180 | QTest::newRow("Qt::Key_Right") << Qt::Key_Right << 1 << 0; | |
181 | } |
|
181 | } | |
182 |
|
182 | |||
183 | void tst_QChartView::keys() |
|
183 | void tst_QChartView::keys() | |
184 | { |
|
184 | { | |
185 | QFETCH(Qt::Key,key); |
|
185 | QFETCH(Qt::Key,key); | |
186 | QFETCH(int, Xcount); |
|
186 | QFETCH(int, Xcount); | |
187 | QFETCH(int, Ycount); |
|
187 | QFETCH(int, Ycount); | |
188 |
|
188 | |||
189 |
QRect padding = m_view->chart()-> |
|
189 | QRect padding = m_view->chart()->margins(); | |
190 |
|
190 | |||
191 | QLineSeries* line = new QLineSeries(); |
|
191 | QLineSeries* line = new QLineSeries(); | |
192 | *line << QPointF(0, 0) << QPointF(100, 100); |
|
192 | *line << QPointF(0, 0) << QPointF(100, 100); | |
193 |
|
193 | |||
194 | m_view->chart()->addSeries(line); |
|
194 | m_view->chart()->addSeries(line); | |
195 | m_view->resize(100 + padding.left() + padding.right(), 100 + padding.top()+ padding.bottom()); |
|
195 | m_view->resize(100 + padding.left() + padding.right(), 100 + padding.top()+ padding.bottom()); | |
196 | m_view->show(); |
|
196 | m_view->show(); | |
197 |
|
197 | |||
198 | QChartAxis* axisY = m_view->chart()->axisY(); |
|
198 | QChartAxis* axisY = m_view->chart()->axisY(); | |
199 | QSignalSpy spy0(axisY, SIGNAL(rangeChanged(qreal, qreal))); |
|
199 | QSignalSpy spy0(axisY, SIGNAL(rangeChanged(qreal, qreal))); | |
200 | QChartAxis* axisX = m_view->chart()->axisX(); |
|
200 | QChartAxis* axisX = m_view->chart()->axisX(); | |
201 | QSignalSpy spy1(axisX, SIGNAL(rangeChanged(qreal, qreal))); |
|
201 | QSignalSpy spy1(axisX, SIGNAL(rangeChanged(qreal, qreal))); | |
202 |
|
202 | |||
203 | QTest::keyPress(m_view, key); |
|
203 | QTest::keyPress(m_view, key); | |
204 | QTest::keyRelease(m_view, key); |
|
204 | QTest::keyRelease(m_view, key); | |
205 |
|
205 | |||
206 | QCOMPARE(spy0.count(), Ycount); |
|
206 | QCOMPARE(spy0.count(), Ycount); | |
207 | QCOMPARE(spy1.count(), Xcount); |
|
207 | QCOMPARE(spy1.count(), Xcount); | |
208 |
|
208 | |||
209 | } |
|
209 | } | |
210 |
|
210 | |||
211 | QTEST_MAIN(tst_QChartView) |
|
211 | QTEST_MAIN(tst_QChartView) | |
212 | #include "tst_qchartview.moc" |
|
212 | #include "tst_qchartview.moc" | |
213 |
|
213 |
General Comments 0
You need to be logged in to leave comments.
Login now