@@ -1,372 +1,382 | |||||
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 | d_ptr->m_legend = new ScrolledQLegend(this); |
|
71 | d_ptr->m_legend = new ScrolledQLegend(this); | |
72 | d_ptr->m_legend->setVisible(false); |
|
72 | d_ptr->m_legend->setVisible(false); | |
73 | d_ptr->m_dataset = new ChartDataSet(this); |
|
73 | d_ptr->m_dataset = new ChartDataSet(this); | |
74 | d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset); |
|
74 | d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset); | |
75 | d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false); |
|
75 | d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false); | |
76 | d_ptr->createConnections(); |
|
76 | d_ptr->createConnections(); | |
77 | //TODO:fix me setMinimumSize(d_ptr->m_padding.left() * 3, d_ptr->m_padding.top() * 3); |
|
77 | //TODO:fix me setMinimumSize(d_ptr->m_padding.left() * 3, d_ptr->m_padding.top() * 3); | |
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 | Q_ASSERT(series); | |||
97 | d_ptr->m_dataset->addSeries(series, axisY); |
|
98 | d_ptr->m_dataset->addSeries(series, axisY); | |
98 | } |
|
99 | } | |
99 |
|
100 | |||
100 | /*! |
|
101 | /*! | |
101 | Removes the \a series specified in a perameter from the QChartView. |
|
102 | Removes the \a series specified in a perameter from the QChartView. | |
102 | It releses its ownership of the specified QChartSeries object. |
|
103 | It releses its ownership of the specified QChartSeries object. | |
103 | It does not delete the pointed QChartSeries data object |
|
104 | It does not delete the pointed QChartSeries data object | |
104 | \sa addSeries(), removeAllSeries() |
|
105 | \sa addSeries(), removeAllSeries() | |
105 | */ |
|
106 | */ | |
106 | void QChart::removeSeries(QSeries* series) |
|
107 | void QChart::removeSeries(QSeries* series) | |
107 | { |
|
108 | { | |
|
109 | Q_ASSERT(series); | |||
108 | d_ptr->m_dataset->removeSeries(series); |
|
110 | d_ptr->m_dataset->removeSeries(series); | |
109 | } |
|
111 | } | |
110 |
|
112 | |||
111 | /*! |
|
113 | /*! | |
112 | Removes all the QChartSeries that have been added to the QChartView |
|
114 | Removes all the QChartSeries that have been added to the QChartView | |
113 | It also deletes the pointed QChartSeries data objects |
|
115 | It also deletes the pointed QChartSeries data objects | |
114 | \sa addSeries(), removeSeries() |
|
116 | \sa addSeries(), removeSeries() | |
115 | */ |
|
117 | */ | |
116 | void QChart::removeAllSeries() |
|
118 | void QChart::removeAllSeries() | |
117 | { |
|
119 | { | |
118 | d_ptr->m_dataset->removeAllSeries(); |
|
120 | d_ptr->m_dataset->removeAllSeries(); | |
119 | } |
|
121 | } | |
120 |
|
122 | |||
121 | /*! |
|
123 | /*! | |
122 | Sets the \a brush that is used for painting the background of the chart area. |
|
124 | Sets the \a brush that is used for painting the background of the chart area. | |
123 | */ |
|
125 | */ | |
124 | void QChart::setBackgroundBrush(const QBrush& brush) |
|
126 | void QChart::setBackgroundBrush(const QBrush& brush) | |
125 | { |
|
127 | { | |
126 | //TODO: refactor me |
|
128 | //TODO: refactor me | |
127 | d_ptr->m_presenter->createChartBackgroundItem(); |
|
129 | d_ptr->m_presenter->createChartBackgroundItem(); | |
128 | d_ptr->m_presenter->m_backgroundItem->setBrush(brush); |
|
130 | d_ptr->m_presenter->m_backgroundItem->setBrush(brush); | |
129 | d_ptr->m_presenter->m_backgroundItem->update(); |
|
131 | d_ptr->m_presenter->m_backgroundItem->update(); | |
130 | } |
|
132 | } | |
131 |
|
133 | |||
132 | QBrush QChart::backgroundBrush() const |
|
134 | QBrush QChart::backgroundBrush() const | |
133 | { |
|
135 | { | |
134 | //TODO: refactor me |
|
136 | //TODO: refactor me | |
135 | if (!d_ptr->m_presenter->m_backgroundItem) return QBrush(); |
|
137 | if (!d_ptr->m_presenter->m_backgroundItem) return QBrush(); | |
136 | return (d_ptr->m_presenter->m_backgroundItem)->brush(); |
|
138 | return (d_ptr->m_presenter->m_backgroundItem)->brush(); | |
137 | } |
|
139 | } | |
138 |
|
140 | |||
139 | /*! |
|
141 | /*! | |
140 | Sets the \a pen that is used for painting the background of the chart area. |
|
142 | Sets the \a pen that is used for painting the background of the chart area. | |
141 | */ |
|
143 | */ | |
142 | void QChart::setBackgroundPen(const QPen& pen) |
|
144 | void QChart::setBackgroundPen(const QPen& pen) | |
143 | { |
|
145 | { | |
144 | //TODO: refactor me |
|
146 | //TODO: refactor me | |
145 | d_ptr->m_presenter->createChartBackgroundItem(); |
|
147 | d_ptr->m_presenter->createChartBackgroundItem(); | |
146 | d_ptr->m_presenter->m_backgroundItem->setPen(pen); |
|
148 | d_ptr->m_presenter->m_backgroundItem->setPen(pen); | |
147 | d_ptr->m_presenter->m_backgroundItem->update(); |
|
149 | d_ptr->m_presenter->m_backgroundItem->update(); | |
148 | } |
|
150 | } | |
149 |
|
151 | |||
150 | QPen QChart::backgroundPen() const |
|
152 | QPen QChart::backgroundPen() const | |
151 | { |
|
153 | { | |
152 | //TODO: refactor me |
|
154 | //TODO: refactor me | |
153 | if (!d_ptr->m_presenter->m_backgroundItem) return QPen(); |
|
155 | if (!d_ptr->m_presenter->m_backgroundItem) return QPen(); | |
154 | return d_ptr->m_presenter->m_backgroundItem->pen(); |
|
156 | return d_ptr->m_presenter->m_backgroundItem->pen(); | |
155 | } |
|
157 | } | |
156 |
|
158 | |||
157 | /*! |
|
159 | /*! | |
158 | Sets the chart \a title. The description text that is drawn above the chart. |
|
160 | Sets the chart \a title. The description text that is drawn above the chart. | |
159 | */ |
|
161 | */ | |
160 | void QChart::setTitle(const QString& title) |
|
162 | void QChart::setTitle(const QString& title) | |
161 | { |
|
163 | { | |
162 | //TODO: refactor me |
|
164 | //TODO: refactor me | |
163 | d_ptr->m_presenter->createChartTitleItem(); |
|
165 | d_ptr->m_presenter->createChartTitleItem(); | |
164 | d_ptr->m_presenter->m_titleItem->setText(title); |
|
166 | d_ptr->m_presenter->m_titleItem->setText(title); | |
165 | d_ptr->m_presenter->updateLayout(); |
|
167 | d_ptr->m_presenter->updateLayout(); | |
166 | } |
|
168 | } | |
167 |
|
169 | |||
168 | /*! |
|
170 | /*! | |
169 | Returns the chart title. The description text that is drawn above the chart. |
|
171 | Returns the chart title. The description text that is drawn above the chart. | |
170 | */ |
|
172 | */ | |
171 | QString QChart::title() const |
|
173 | QString QChart::title() const | |
172 | { |
|
174 | { | |
173 | //TODO: refactor me |
|
175 | //TODO: refactor me | |
174 | if (d_ptr->m_presenter->m_titleItem) |
|
176 | if (d_ptr->m_presenter->m_titleItem) | |
175 | return d_ptr->m_presenter->m_titleItem->text(); |
|
177 | return d_ptr->m_presenter->m_titleItem->text(); | |
176 | else |
|
178 | else | |
177 | return QString(); |
|
179 | return QString(); | |
178 | } |
|
180 | } | |
179 |
|
181 | |||
180 | /*! |
|
182 | /*! | |
181 | Sets the \a font that is used for rendering the description text that is rendered above the chart. |
|
183 | Sets the \a font that is used for rendering the description text that is rendered above the chart. | |
182 | */ |
|
184 | */ | |
183 | void QChart::setTitleFont(const QFont& font) |
|
185 | void QChart::setTitleFont(const QFont& font) | |
184 | { |
|
186 | { | |
185 | //TODO: refactor me |
|
187 | //TODO: refactor me | |
186 | d_ptr->m_presenter->createChartTitleItem(); |
|
188 | d_ptr->m_presenter->createChartTitleItem(); | |
187 | d_ptr->m_presenter->m_titleItem->setFont(font); |
|
189 | d_ptr->m_presenter->m_titleItem->setFont(font); | |
188 | d_ptr->m_presenter->updateLayout(); |
|
190 | d_ptr->m_presenter->updateLayout(); | |
189 | } |
|
191 | } | |
190 |
|
192 | |||
|
193 | QFont QChart::titleFont() const | |||
|
194 | { | |||
|
195 | if (d_ptr->m_presenter->m_titleItem) | |||
|
196 | return d_ptr->m_presenter->m_titleItem->font(); | |||
|
197 | else | |||
|
198 | return QFont(); | |||
|
199 | } | |||
|
200 | ||||
191 | /*! |
|
201 | /*! | |
192 | Sets the \a brush used for rendering the title text. |
|
202 | Sets the \a brush used for rendering the title text. | |
193 | */ |
|
203 | */ | |
194 | void QChart::setTitleBrush(const QBrush &brush) |
|
204 | void QChart::setTitleBrush(const QBrush &brush) | |
195 | { |
|
205 | { | |
196 | //TODO: refactor me |
|
206 | //TODO: refactor me | |
197 | d_ptr->m_presenter->createChartTitleItem(); |
|
207 | d_ptr->m_presenter->createChartTitleItem(); | |
198 | d_ptr->m_presenter->m_titleItem->setBrush(brush); |
|
208 | d_ptr->m_presenter->m_titleItem->setBrush(brush); | |
199 | d_ptr->m_presenter->updateLayout(); |
|
209 | d_ptr->m_presenter->updateLayout(); | |
200 | } |
|
210 | } | |
201 |
|
211 | |||
202 | /*! |
|
212 | /*! | |
203 | Returns the brush used for rendering the title text. |
|
213 | Returns the brush used for rendering the title text. | |
204 | */ |
|
214 | */ | |
205 | QBrush QChart::titleBrush() const |
|
215 | QBrush QChart::titleBrush() const | |
206 | { |
|
216 | { | |
207 | //TODO: refactor me |
|
217 | //TODO: refactor me | |
208 | if (!d_ptr->m_presenter->m_titleItem) return QBrush(); |
|
218 | if (!d_ptr->m_presenter->m_titleItem) return QBrush(); | |
209 | return d_ptr->m_presenter->m_titleItem->brush(); |
|
219 | return d_ptr->m_presenter->m_titleItem->brush(); | |
210 | } |
|
220 | } | |
211 |
|
221 | |||
212 | /*! |
|
222 | /*! | |
213 | Sets the \a theme used by the chart for rendering the graphical representation of the data |
|
223 | Sets the \a theme used by the chart for rendering the graphical representation of the data | |
214 | \sa ChartTheme, chartTheme() |
|
224 | \sa ChartTheme, chartTheme() | |
215 | */ |
|
225 | */ | |
216 | void QChart::setTheme(QChart::ChartTheme theme) |
|
226 | void QChart::setTheme(QChart::ChartTheme theme) | |
217 | { |
|
227 | { | |
218 | d_ptr->m_presenter->setTheme(theme); |
|
228 | d_ptr->m_presenter->setTheme(theme); | |
219 | } |
|
229 | } | |
220 |
|
230 | |||
221 | /*! |
|
231 | /*! | |
222 | Returns the theme enum used by the chart. |
|
232 | Returns the theme enum used by the chart. | |
223 | \sa ChartTheme, setChartTheme() |
|
233 | \sa ChartTheme, setChartTheme() | |
224 | */ |
|
234 | */ | |
225 | QChart::ChartTheme QChart::theme() const |
|
235 | QChart::ChartTheme QChart::theme() const | |
226 | { |
|
236 | { | |
227 | return d_ptr->m_presenter->theme(); |
|
237 | return d_ptr->m_presenter->theme(); | |
228 | } |
|
238 | } | |
229 |
|
239 | |||
230 | /*! |
|
240 | /*! | |
231 | Zooms in the view by a factor of 2 |
|
241 | Zooms in the view by a factor of 2 | |
232 | */ |
|
242 | */ | |
233 | void QChart::zoomIn() |
|
243 | void QChart::zoomIn() | |
234 | { |
|
244 | { | |
235 | d_ptr->m_presenter->zoomIn(); |
|
245 | d_ptr->m_presenter->zoomIn(); | |
236 | } |
|
246 | } | |
237 |
|
247 | |||
238 | /*! |
|
248 | /*! | |
239 | Zooms in the view to a maximum level at which \a rect is still fully visible. |
|
249 | Zooms in the view to a maximum level at which \a rect is still fully visible. | |
240 | */ |
|
250 | */ | |
241 | void QChart::zoomIn(const QRectF& rect) |
|
251 | void QChart::zoomIn(const QRectF& rect) | |
242 | { |
|
252 | { | |
243 | if (!rect.isValid()) return; |
|
253 | if (!rect.isValid()) return; | |
244 | d_ptr->m_presenter->zoomIn(rect); |
|
254 | d_ptr->m_presenter->zoomIn(rect); | |
245 | } |
|
255 | } | |
246 |
|
256 | |||
247 | /*! |
|
257 | /*! | |
248 | Restores the view zoom level to the previous one. |
|
258 | Restores the view zoom level to the previous one. | |
249 | */ |
|
259 | */ | |
250 | void QChart::zoomOut() |
|
260 | void QChart::zoomOut() | |
251 | { |
|
261 | { | |
252 | d_ptr->m_presenter->zoomOut(); |
|
262 | d_ptr->m_presenter->zoomOut(); | |
253 | } |
|
263 | } | |
254 |
|
264 | |||
255 | /*! |
|
265 | /*! | |
256 | Returns the pointer to the x axis object of the chart |
|
266 | Returns the pointer to the x axis object of the chart | |
257 | */ |
|
267 | */ | |
258 | QChartAxis* QChart::axisX() const |
|
268 | QChartAxis* QChart::axisX() const | |
259 | { |
|
269 | { | |
260 | return d_ptr->m_dataset->axisX(); |
|
270 | return d_ptr->m_dataset->axisX(); | |
261 | } |
|
271 | } | |
262 |
|
272 | |||
263 | /*! |
|
273 | /*! | |
264 | Returns the pointer to the y axis object of the chart |
|
274 | Returns the pointer to the y axis object of the chart | |
265 | */ |
|
275 | */ | |
266 | QChartAxis* QChart::axisY() const |
|
276 | QChartAxis* QChart::axisY() const | |
267 | { |
|
277 | { | |
268 | return d_ptr->m_dataset->axisY(); |
|
278 | return d_ptr->m_dataset->axisY(); | |
269 | } |
|
279 | } | |
270 |
|
280 | |||
271 | /*! |
|
281 | /*! | |
272 | Returns the legend object of the chart. Ownership stays in chart. |
|
282 | Returns the legend object of the chart. Ownership stays in chart. | |
273 | */ |
|
283 | */ | |
274 | QLegend* QChart::legend() const |
|
284 | QLegend* QChart::legend() const | |
275 | { |
|
285 | { | |
276 | return d_ptr->m_legend; |
|
286 | return d_ptr->m_legend; | |
277 | } |
|
287 | } | |
278 |
|
288 | |||
279 | QRectF QChart::margins() const |
|
289 | QRectF QChart::margins() const | |
280 | { |
|
290 | { | |
281 | return d_ptr->m_presenter->margins(); |
|
291 | return d_ptr->m_presenter->margins(); | |
282 | } |
|
292 | } | |
283 |
|
293 | |||
284 |
|
294 | |||
285 | /*! |
|
295 | /*! | |
286 | Resizes and updates the chart area using the \a event data |
|
296 | Resizes and updates the chart area using the \a event data | |
287 | */ |
|
297 | */ | |
288 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) |
|
298 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) | |
289 | { |
|
299 | { | |
290 | d_ptr->m_rect = QRectF(QPoint(0,0),event->newSize()); |
|
300 | d_ptr->m_rect = QRectF(QPoint(0,0),event->newSize()); | |
291 | QGraphicsWidget::resizeEvent(event); |
|
301 | QGraphicsWidget::resizeEvent(event); | |
292 | d_ptr->m_presenter->setGeometry(d_ptr->m_rect); |
|
302 | d_ptr->m_presenter->setGeometry(d_ptr->m_rect); | |
293 | } |
|
303 | } | |
294 |
|
304 | |||
295 | /*! |
|
305 | /*! | |
296 | Sets animation \a options for the chart |
|
306 | Sets animation \a options for the chart | |
297 | */ |
|
307 | */ | |
298 | void QChart::setAnimationOptions(AnimationOptions options) |
|
308 | void QChart::setAnimationOptions(AnimationOptions options) | |
299 | { |
|
309 | { | |
300 | d_ptr->m_presenter->setAnimationOptions(options); |
|
310 | d_ptr->m_presenter->setAnimationOptions(options); | |
301 | } |
|
311 | } | |
302 |
|
312 | |||
303 | /*! |
|
313 | /*! | |
304 | Returns animation options for the chart |
|
314 | Returns animation options for the chart | |
305 | */ |
|
315 | */ | |
306 | QChart::AnimationOptions QChart::animationOptions() const |
|
316 | QChart::AnimationOptions QChart::animationOptions() const | |
307 | { |
|
317 | { | |
308 | return d_ptr->m_presenter->animationOptions(); |
|
318 | return d_ptr->m_presenter->animationOptions(); | |
309 | } |
|
319 | } | |
310 |
|
320 | |||
311 | void QChart::scrollLeft() |
|
321 | void QChart::scrollLeft() | |
312 | { |
|
322 | { | |
313 | d_ptr->m_presenter->scroll(-d_ptr->m_presenter->chartGeometry().width()/(axisX()->ticksCount()-1),0); |
|
323 | d_ptr->m_presenter->scroll(-d_ptr->m_presenter->chartGeometry().width()/(axisX()->ticksCount()-1),0); | |
314 | } |
|
324 | } | |
315 |
|
325 | |||
316 | void QChart::scrollRight() |
|
326 | void QChart::scrollRight() | |
317 | { |
|
327 | { | |
318 | d_ptr->m_presenter->scroll(d_ptr->m_presenter->chartGeometry().width()/(axisX()->ticksCount()-1),0); |
|
328 | d_ptr->m_presenter->scroll(d_ptr->m_presenter->chartGeometry().width()/(axisX()->ticksCount()-1),0); | |
319 | } |
|
329 | } | |
320 |
|
330 | |||
321 | void QChart::scrollUp() |
|
331 | void QChart::scrollUp() | |
322 | { |
|
332 | { | |
323 | d_ptr->m_presenter->scroll(0,d_ptr->m_presenter->chartGeometry().width()/(axisY()->ticksCount()-1)); |
|
333 | d_ptr->m_presenter->scroll(0,d_ptr->m_presenter->chartGeometry().width()/(axisY()->ticksCount()-1)); | |
324 | } |
|
334 | } | |
325 |
|
335 | |||
326 | void QChart::scrollDown() |
|
336 | void QChart::scrollDown() | |
327 | { |
|
337 | { | |
328 | d_ptr->m_presenter->scroll(0,-d_ptr->m_presenter->chartGeometry().width()/(axisY()->ticksCount()-1)); |
|
338 | d_ptr->m_presenter->scroll(0,-d_ptr->m_presenter->chartGeometry().width()/(axisY()->ticksCount()-1)); | |
329 | } |
|
339 | } | |
330 |
|
340 | |||
331 | void QChart::setBackgroundVisible(bool visible) |
|
341 | void QChart::setBackgroundVisible(bool visible) | |
332 | { |
|
342 | { | |
333 | //TODO: refactor me |
|
343 | //TODO: refactor me | |
334 | d_ptr->m_presenter->createChartBackgroundItem(); |
|
344 | d_ptr->m_presenter->createChartBackgroundItem(); | |
335 | d_ptr->m_presenter->m_backgroundItem->setVisible(visible); |
|
345 | d_ptr->m_presenter->m_backgroundItem->setVisible(visible); | |
336 | } |
|
346 | } | |
337 |
|
347 | |||
338 | bool QChart::isBackgroundVisible() const |
|
348 | bool QChart::isBackgroundVisible() const | |
339 | { |
|
349 | { | |
340 | //TODO: refactor me |
|
350 | //TODO: refactor me | |
341 | if (!d_ptr->m_presenter->m_backgroundItem) return false; |
|
351 | if (!d_ptr->m_presenter->m_backgroundItem) return false; | |
342 | return d_ptr->m_presenter->m_backgroundItem->isVisible(); |
|
352 | return d_ptr->m_presenter->m_backgroundItem->isVisible(); | |
343 | } |
|
353 | } | |
344 |
|
354 | |||
345 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
355 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
346 |
|
356 | |||
347 | QChartPrivate::QChartPrivate(): |
|
357 | QChartPrivate::QChartPrivate(): | |
348 | m_legend(0), |
|
358 | m_legend(0), | |
349 | m_dataset(0), |
|
359 | m_dataset(0), | |
350 | m_presenter(0) |
|
360 | m_presenter(0) | |
351 | { |
|
361 | { | |
352 |
|
362 | |||
353 | } |
|
363 | } | |
354 |
|
364 | |||
355 | QChartPrivate::~QChartPrivate() |
|
365 | QChartPrivate::~QChartPrivate() | |
356 | { |
|
366 | { | |
357 |
|
367 | |||
358 | } |
|
368 | } | |
359 |
|
369 | |||
360 | void QChartPrivate::createConnections() |
|
370 | void QChartPrivate::createConnections() | |
361 | { |
|
371 | { | |
362 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*))); |
|
372 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*))); | |
363 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_legend,SLOT(handleSeriesRemoved(QSeries*))); |
|
373 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_legend,SLOT(handleSeriesRemoved(QSeries*))); | |
364 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_presenter,SLOT(handleSeriesAdded(QSeries*,Domain*))); |
|
374 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_presenter,SLOT(handleSeriesAdded(QSeries*,Domain*))); | |
365 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_presenter,SLOT(handleSeriesRemoved(QSeries*))); |
|
375 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_presenter,SLOT(handleSeriesRemoved(QSeries*))); | |
366 | QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*,Domain*)),m_presenter,SLOT(handleAxisAdded(QChartAxis*,Domain*))); |
|
376 | QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*,Domain*)),m_presenter,SLOT(handleAxisAdded(QChartAxis*,Domain*))); | |
367 | QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),m_presenter,SLOT(handleAxisRemoved(QChartAxis*))); |
|
377 | QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),m_presenter,SLOT(handleAxisRemoved(QChartAxis*))); | |
368 | } |
|
378 | } | |
369 |
|
379 | |||
370 | #include "moc_qchart.cpp" |
|
380 | #include "moc_qchart.cpp" | |
371 |
|
381 | |||
372 | QTCOMMERCIALCHART_END_NAMESPACE |
|
382 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,245 +1,246 | |||||
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 | Q_ASSERT(chart); | |||
60 | d_ptr->m_scene = new QGraphicsScene(this); |
|
61 | d_ptr->m_scene = new QGraphicsScene(this); | |
61 | d_ptr->m_chart = chart; |
|
62 | d_ptr->m_chart = chart; | |
62 | setFrameShape(QFrame::NoFrame); |
|
63 | setFrameShape(QFrame::NoFrame); | |
63 | setBackgroundRole(QPalette::Window); |
|
64 | setBackgroundRole(QPalette::Window); | |
64 | setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
65 | setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |
65 | setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
66 | setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |
66 | setScene(d_ptr->m_scene); |
|
67 | setScene(d_ptr->m_scene); | |
67 | d_ptr->m_scene->addItem(chart); |
|
68 | d_ptr->m_scene->addItem(chart); | |
68 | setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
|
69 | setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | |
69 | } |
|
70 | } | |
70 |
|
71 | |||
71 |
|
72 | |||
72 | /*! |
|
73 | /*! | |
73 | Destroys the object and it's children, like QChartSeries and QChartAxis object added to it. |
|
74 | Destroys the object and it's children, like QChartSeries and QChartAxis object added to it. | |
74 | */ |
|
75 | */ | |
75 | QChartView::~QChartView() |
|
76 | QChartView::~QChartView() | |
76 | { |
|
77 | { | |
77 | } |
|
78 | } | |
78 |
|
79 | |||
79 | QChart* QChartView::chart() const |
|
80 | QChart* QChartView::chart() const | |
80 | { |
|
81 | { | |
81 | return d_ptr->m_chart; |
|
82 | return d_ptr->m_chart; | |
82 | } |
|
83 | } | |
83 |
|
84 | |||
84 | /*! |
|
85 | /*! | |
85 | Sets the RubberBandPlicy to \a policy. Selected policy determines the way zooming is performed. |
|
86 | Sets the RubberBandPlicy to \a policy. Selected policy determines the way zooming is performed. | |
86 | */ |
|
87 | */ | |
87 | void QChartView::setRubberBand(const RubberBands& rubberBand) |
|
88 | void QChartView::setRubberBand(const RubberBands& rubberBand) | |
88 | { |
|
89 | { | |
89 | d_ptr->m_rubberBandFlags=rubberBand; |
|
90 | d_ptr->m_rubberBandFlags=rubberBand; | |
90 |
|
91 | |||
91 | if (!d_ptr->m_rubberBandFlags) { |
|
92 | if (!d_ptr->m_rubberBandFlags) { | |
92 | delete d_ptr->m_rubberBand; |
|
93 | delete d_ptr->m_rubberBand; | |
93 | d_ptr->m_rubberBand=0; |
|
94 | d_ptr->m_rubberBand=0; | |
94 | return; |
|
95 | return; | |
95 | } |
|
96 | } | |
96 |
|
97 | |||
97 | if (!d_ptr->m_rubberBand) { |
|
98 | if (!d_ptr->m_rubberBand) { | |
98 | d_ptr->m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this); |
|
99 | d_ptr->m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this); | |
99 | d_ptr->m_rubberBand->setEnabled(true); |
|
100 | d_ptr->m_rubberBand->setEnabled(true); | |
100 | } |
|
101 | } | |
101 | } |
|
102 | } | |
102 |
|
103 | |||
103 | /*! |
|
104 | /*! | |
104 | Returns the RubberBandPolicy that is currently being used by the widget. |
|
105 | Returns the RubberBandPolicy that is currently being used by the widget. | |
105 | */ |
|
106 | */ | |
106 | QChartView::RubberBands QChartView::rubberBand() const |
|
107 | QChartView::RubberBands QChartView::rubberBand() const | |
107 | { |
|
108 | { | |
108 | return d_ptr->m_rubberBandFlags; |
|
109 | return d_ptr->m_rubberBandFlags; | |
109 | } |
|
110 | } | |
110 |
|
111 | |||
111 | /*! |
|
112 | /*! | |
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 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. |
|
114 | If different mouse button is pressed and/or the RubberBandPolicy is disabled then the \a event is passed to QGraphicsView::mousePressEvent() implementation. | |
114 | */ |
|
115 | */ | |
115 | void QChartView::mousePressEvent(QMouseEvent *event) |
|
116 | void QChartView::mousePressEvent(QMouseEvent *event) | |
116 | { |
|
117 | { | |
117 | if(d_ptr->m_rubberBand && d_ptr->m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) { |
|
118 | if(d_ptr->m_rubberBand && d_ptr->m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) { | |
118 |
|
119 | |||
119 | int padding = d_ptr->m_chart->margins().top(); |
|
120 | int padding = d_ptr->m_chart->margins().top(); | |
120 | QRect rect(padding, padding, width() - 2 * padding, height() - 2 * padding); |
|
121 | QRect rect(padding, padding, width() - 2 * padding, height() - 2 * padding); | |
121 |
|
122 | |||
122 | if (rect.contains(event->pos())) { |
|
123 | if (rect.contains(event->pos())) { | |
123 | d_ptr->m_rubberBandOrigin = event->pos(); |
|
124 | d_ptr->m_rubberBandOrigin = event->pos(); | |
124 | d_ptr->m_rubberBand->setGeometry(QRect(d_ptr->m_rubberBandOrigin, QSize())); |
|
125 | d_ptr->m_rubberBand->setGeometry(QRect(d_ptr->m_rubberBandOrigin, QSize())); | |
125 | d_ptr->m_rubberBand->show(); |
|
126 | d_ptr->m_rubberBand->show(); | |
126 | event->accept(); |
|
127 | event->accept(); | |
127 | } |
|
128 | } | |
128 | } |
|
129 | } | |
129 | else { |
|
130 | else { | |
130 | QGraphicsView::mousePressEvent(event); |
|
131 | QGraphicsView::mousePressEvent(event); | |
131 | } |
|
132 | } | |
132 | } |
|
133 | } | |
133 |
|
134 | |||
134 | /*! |
|
135 | /*! | |
135 | If RubberBand rectange specification has been initiated in pressEvent then \a event data is used to update RubberBand geometry. |
|
136 | 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. |
|
137 | In other case the defualt QGraphicsView::mouseMoveEvent implementation is called. | |
137 | */ |
|
138 | */ | |
138 | void QChartView::mouseMoveEvent(QMouseEvent *event) |
|
139 | void QChartView::mouseMoveEvent(QMouseEvent *event) | |
139 | { |
|
140 | { | |
140 | if(d_ptr->m_rubberBand && d_ptr->m_rubberBand->isVisible()) { |
|
141 | if(d_ptr->m_rubberBand && d_ptr->m_rubberBand->isVisible()) { | |
141 | QRectF margins = d_ptr->m_chart->margins(); |
|
142 | QRectF margins = d_ptr->m_chart->margins(); | |
142 | QRectF geometry = d_ptr->m_chart->geometry(); |
|
143 | QRectF geometry = d_ptr->m_chart->geometry(); | |
143 | QRectF rect =geometry.adjusted(margins.left(),margins.top(),-margins.right(),-margins.bottom()); |
|
144 | QRectF rect =geometry.adjusted(margins.left(),margins.top(),-margins.right(),-margins.bottom()); | |
144 | int width = event->pos().x() - d_ptr->m_rubberBandOrigin.x(); |
|
145 | int width = event->pos().x() - d_ptr->m_rubberBandOrigin.x(); | |
145 | int height = event->pos().y() - d_ptr->m_rubberBandOrigin.y(); |
|
146 | int height = event->pos().y() - d_ptr->m_rubberBandOrigin.y(); | |
146 | if (!d_ptr->m_rubberBandFlags.testFlag(VerticalRubberBand)) { |
|
147 | if (!d_ptr->m_rubberBandFlags.testFlag(VerticalRubberBand)) { | |
147 | d_ptr->m_rubberBandOrigin.setY(rect.top()); |
|
148 | d_ptr->m_rubberBandOrigin.setY(rect.top()); | |
148 | height = rect.height(); |
|
149 | height = rect.height(); | |
149 | } |
|
150 | } | |
150 | if (!d_ptr->m_rubberBandFlags.testFlag(HorizonalRubberBand)) { |
|
151 | if (!d_ptr->m_rubberBandFlags.testFlag(HorizonalRubberBand)) { | |
151 | d_ptr->m_rubberBandOrigin.setX(rect.left()); |
|
152 | d_ptr->m_rubberBandOrigin.setX(rect.left()); | |
152 | width= rect.width(); |
|
153 | width= rect.width(); | |
153 | } |
|
154 | } | |
154 | d_ptr->m_rubberBand->setGeometry(QRect(d_ptr->m_rubberBandOrigin.x(),d_ptr->m_rubberBandOrigin.y(), width,height).normalized()); |
|
155 | d_ptr->m_rubberBand->setGeometry(QRect(d_ptr->m_rubberBandOrigin.x(),d_ptr->m_rubberBandOrigin.y(), width,height).normalized()); | |
155 | } |
|
156 | } | |
156 | else { |
|
157 | else { | |
157 | QGraphicsView::mouseMoveEvent(event); |
|
158 | QGraphicsView::mouseMoveEvent(event); | |
158 | } |
|
159 | } | |
159 | } |
|
160 | } | |
160 |
|
161 | |||
161 | /*! |
|
162 | /*! | |
162 | 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 |
|
163 | 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 | |
163 | If it is the right mouse button \a event then RubberBand is dissmissed and zoom is canceled. |
|
164 | If it is the right mouse button \a event then RubberBand is dissmissed and zoom is canceled. | |
164 | */ |
|
165 | */ | |
165 | void QChartView::mouseReleaseEvent(QMouseEvent *event) |
|
166 | void QChartView::mouseReleaseEvent(QMouseEvent *event) | |
166 | { |
|
167 | { | |
167 | if(d_ptr->m_rubberBand) { |
|
168 | if(d_ptr->m_rubberBand) { | |
168 | if (event->button() == Qt::LeftButton && d_ptr->m_rubberBand->isVisible()) { |
|
169 | if (event->button() == Qt::LeftButton && d_ptr->m_rubberBand->isVisible()) { | |
169 | d_ptr->m_rubberBand->hide(); |
|
170 | d_ptr->m_rubberBand->hide(); | |
170 | QRect rect = d_ptr->m_rubberBand->geometry(); |
|
171 | QRect rect = d_ptr->m_rubberBand->geometry(); | |
171 | d_ptr->m_chart->zoomIn(rect); |
|
172 | d_ptr->m_chart->zoomIn(rect); | |
172 | event->accept(); |
|
173 | event->accept(); | |
173 | } |
|
174 | } | |
174 |
|
175 | |||
175 | if(event->button()==Qt::RightButton){ |
|
176 | if(event->button()==Qt::RightButton){ | |
176 | d_ptr->m_chart->zoomOut(); |
|
177 | d_ptr->m_chart->zoomOut(); | |
177 | event->accept(); |
|
178 | event->accept(); | |
178 | } |
|
179 | } | |
179 | } |
|
180 | } | |
180 | else { |
|
181 | else { | |
181 | QGraphicsView::mouseReleaseEvent(event); |
|
182 | QGraphicsView::mouseReleaseEvent(event); | |
182 | } |
|
183 | } | |
183 | } |
|
184 | } | |
184 |
|
185 | |||
185 | /*! |
|
186 | /*! | |
186 | Pressing + and - keys performs zoomIn() and zoomOut() respectivly. |
|
187 | Pressing + and - keys performs zoomIn() and zoomOut() respectivly. | |
187 | In other \a event is passed to the QGraphicsView::keyPressEvent() implementation |
|
188 | In other \a event is passed to the QGraphicsView::keyPressEvent() implementation | |
188 | */ |
|
189 | */ | |
189 | void QChartView::keyPressEvent(QKeyEvent *event) |
|
190 | void QChartView::keyPressEvent(QKeyEvent *event) | |
190 | { |
|
191 | { | |
191 | switch (event->key()) { |
|
192 | switch (event->key()) { | |
192 | case Qt::Key_Plus: |
|
193 | case Qt::Key_Plus: | |
193 | d_ptr->m_chart->zoomIn(); |
|
194 | d_ptr->m_chart->zoomIn(); | |
194 | break; |
|
195 | break; | |
195 | case Qt::Key_Minus: |
|
196 | case Qt::Key_Minus: | |
196 | d_ptr->m_chart->zoomOut(); |
|
197 | d_ptr->m_chart->zoomOut(); | |
197 | break; |
|
198 | break; | |
198 | case Qt::Key_Left: |
|
199 | case Qt::Key_Left: | |
199 | d_ptr->m_chart->scrollLeft(); |
|
200 | d_ptr->m_chart->scrollLeft(); | |
200 | break; |
|
201 | break; | |
201 | case Qt::Key_Right: |
|
202 | case Qt::Key_Right: | |
202 | d_ptr->m_chart->scrollRight(); |
|
203 | d_ptr->m_chart->scrollRight(); | |
203 | break; |
|
204 | break; | |
204 | case Qt::Key_Up: |
|
205 | case Qt::Key_Up: | |
205 | d_ptr->m_chart->scrollUp(); |
|
206 | d_ptr->m_chart->scrollUp(); | |
206 | break; |
|
207 | break; | |
207 | case Qt::Key_Down: |
|
208 | case Qt::Key_Down: | |
208 | d_ptr->m_chart->scrollDown(); |
|
209 | d_ptr->m_chart->scrollDown(); | |
209 | break; |
|
210 | break; | |
210 | default: |
|
211 | default: | |
211 | QGraphicsView::keyPressEvent(event); |
|
212 | QGraphicsView::keyPressEvent(event); | |
212 | break; |
|
213 | break; | |
213 | } |
|
214 | } | |
214 | } |
|
215 | } | |
215 |
|
216 | |||
216 | /*! |
|
217 | /*! | |
217 | Resizes and updates the chart area using the \a event data |
|
218 | Resizes and updates the chart area using the \a event data | |
218 | */ |
|
219 | */ | |
219 | void QChartView::resizeEvent(QResizeEvent *event) |
|
220 | void QChartView::resizeEvent(QResizeEvent *event) | |
220 | { |
|
221 | { | |
221 | QGraphicsView::resizeEvent(event); |
|
222 | QGraphicsView::resizeEvent(event); | |
222 | d_ptr->m_chart->resize(size()); |
|
223 | d_ptr->m_chart->resize(size()); | |
223 | setSceneRect(d_ptr->m_chart->geometry()); |
|
224 | setSceneRect(d_ptr->m_chart->geometry()); | |
224 | } |
|
225 | } | |
225 |
|
226 | |||
226 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
227 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
227 |
|
228 | |||
228 | QChartViewPrivate::QChartViewPrivate(): |
|
229 | QChartViewPrivate::QChartViewPrivate(): | |
229 | m_scene(0), |
|
230 | m_scene(0), | |
230 | m_chart(0), |
|
231 | m_chart(0), | |
231 | m_presenter(0), |
|
232 | m_presenter(0), | |
232 | m_rubberBand(0), |
|
233 | m_rubberBand(0), | |
233 | m_rubberBandFlags(QChartView::NoRubberBand) |
|
234 | m_rubberBandFlags(QChartView::NoRubberBand) | |
234 | { |
|
235 | { | |
235 |
|
236 | |||
236 | } |
|
237 | } | |
237 |
|
238 | |||
238 | QChartViewPrivate::~QChartViewPrivate() |
|
239 | QChartViewPrivate::~QChartViewPrivate() | |
239 | { |
|
240 | { | |
240 |
|
241 | |||
241 | } |
|
242 | } | |
242 |
|
243 | |||
243 | #include "moc_qchartview.cpp" |
|
244 | #include "moc_qchartview.cpp" | |
244 |
|
245 | |||
245 | QTCOMMERCIALCHART_END_NAMESPACE |
|
246 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now