@@ -1,501 +1,501 | |||||
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 ChartThemeDefault Follows the GUI style of the Operating System |
|
33 | \value ChartThemeDefault Follows the GUI style of the Operating System | |
34 | \value ChartThemeLight |
|
34 | \value ChartThemeLight | |
35 | \value ChartThemeBlueCerulean |
|
35 | \value ChartThemeBlueCerulean | |
36 | \value ChartThemeDark |
|
36 | \value ChartThemeDark | |
37 | \value ChartThemeBrownSand |
|
37 | \value ChartThemeBrownSand | |
38 | \value ChartThemeBlueNcs |
|
38 | \value ChartThemeBlueNcs | |
39 | \value ChartThemeHighContrast |
|
39 | \value ChartThemeHighContrast | |
40 | \value ChartThemeBlueIcy |
|
40 | \value ChartThemeBlueIcy | |
41 | \value ChartThemeCount Not really a theme; the total count of themes. |
|
41 | \value ChartThemeCount Not really a theme; the total count of themes. | |
42 | */ |
|
42 | */ | |
43 |
|
43 | |||
44 | /*! |
|
44 | /*! | |
45 | \enum QChart::AnimationOption |
|
45 | \enum QChart::AnimationOption | |
46 |
|
46 | |||
47 | For enabling/disabling animations. Defaults to NoAnimation. |
|
47 | For enabling/disabling animations. Defaults to NoAnimation. | |
48 |
|
48 | |||
49 | \value NoAnimation |
|
49 | \value NoAnimation | |
50 | \value GridAxisAnimations |
|
50 | \value GridAxisAnimations | |
51 | \value SeriesAnimations |
|
51 | \value SeriesAnimations | |
52 | \value AllAnimations |
|
52 | \value AllAnimations | |
53 | */ |
|
53 | */ | |
54 |
|
54 | |||
55 | /*! |
|
55 | /*! | |
56 | \class QChart |
|
56 | \class QChart | |
57 | \brief QtCommercial chart API. |
|
57 | \brief QtCommercial chart API. | |
58 |
|
58 | |||
59 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical |
|
59 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical | |
60 | representation of different types of QChartSeries and other chart related objects like |
|
60 | representation of different types of QChartSeries and other chart related objects like | |
61 | QChartAxis and QChartLegend. If you simply want to show a chart in a layout, you can use the |
|
61 | QChartAxis and QChartLegend. If you simply want to show a chart in a layout, you can use the | |
62 | convenience class QChartView instead of QChart. |
|
62 | convenience class QChartView instead of QChart. | |
63 | \sa QChartView |
|
63 | \sa QChartView | |
64 | */ |
|
64 | */ | |
65 |
|
65 | |||
66 | /*! |
|
66 | /*! | |
67 | Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. |
|
67 | Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. | |
68 | */ |
|
68 | */ | |
69 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), |
|
69 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), | |
70 | d_ptr(new QChartPrivate(this)) |
|
70 | d_ptr(new QChartPrivate(this)) | |
71 | { |
|
71 | { | |
72 | //setMinimumSize(200,200); |
|
72 | //setMinimumSize(200,200); | |
73 | d_ptr->m_legend = new QLegend(this); |
|
73 | d_ptr->m_legend = new QLegend(this); | |
74 | d_ptr->m_dataset = new ChartDataSet(this); |
|
74 | d_ptr->m_dataset = new ChartDataSet(this); | |
75 | d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset); |
|
75 | d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset); | |
76 | setMinimumSize(d_ptr->m_padding.left() * 3, d_ptr->m_padding.top() * 3); |
|
76 | setMinimumSize(d_ptr->m_padding.left() * 3, d_ptr->m_padding.top() * 3); | |
77 | connect(d_ptr->m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),d_ptr->m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*))); |
|
77 | connect(d_ptr->m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),d_ptr->m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*))); | |
78 | connect(d_ptr->m_dataset,SIGNAL(seriesRemoved(QSeries*)),d_ptr->m_legend,SLOT(handleSeriesRemoved(QSeries*))); |
|
78 | connect(d_ptr->m_dataset,SIGNAL(seriesRemoved(QSeries*)),d_ptr->m_legend,SLOT(handleSeriesRemoved(QSeries*))); | |
79 | } |
|
79 | } | |
80 |
|
80 | |||
81 | /*! |
|
81 | /*! | |
82 | Destroys the object and it's children, like QChartSeries and QChartAxis object added to it. |
|
82 | Destroys the object and it's children, like QChartSeries and QChartAxis object added to it. | |
83 | */ |
|
83 | */ | |
84 | QChart::~QChart() |
|
84 | QChart::~QChart() | |
85 | { |
|
85 | { | |
86 | //delete first presenter , since this is a root of all the graphical items |
|
86 | //delete first presenter , since this is a root of all the graphical items | |
87 | delete d_ptr->m_presenter; |
|
87 | delete d_ptr->m_presenter; | |
88 | d_ptr->m_presenter=0; |
|
88 | d_ptr->m_presenter=0; | |
89 | } |
|
89 | } | |
90 |
|
90 | |||
91 | /*! |
|
91 | /*! | |
92 | Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects. |
|
92 | Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects. | |
93 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and |
|
93 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and | |
94 | the y axis). |
|
94 | the y axis). | |
95 | */ |
|
95 | */ | |
96 | void QChart::addSeries(QSeries* series, QChartAxis* axisY) |
|
96 | void QChart::addSeries(QSeries* series, QChartAxis* axisY) | |
97 | { |
|
97 | { | |
98 | d_ptr->m_dataset->addSeries(series, axisY); |
|
98 | d_ptr->m_dataset->addSeries(series, axisY); | |
99 | } |
|
99 | } | |
100 |
|
100 | |||
101 | /*! |
|
101 | /*! | |
102 | Removes the \a series specified in a perameter from the QChartView. |
|
102 | Removes the \a series specified in a perameter from the QChartView. | |
103 | It releses its ownership of the specified QChartSeries object. |
|
103 | It releses its ownership of the specified QChartSeries object. | |
104 | It does not delete the pointed QChartSeries data object |
|
104 | It does not delete the pointed QChartSeries data object | |
105 | \sa addSeries(), removeAllSeries() |
|
105 | \sa addSeries(), removeAllSeries() | |
106 | */ |
|
106 | */ | |
107 | void QChart::removeSeries(QSeries* series) |
|
107 | void QChart::removeSeries(QSeries* series) | |
108 | { |
|
108 | { | |
109 | d_ptr->m_dataset->removeSeries(series); |
|
109 | d_ptr->m_dataset->removeSeries(series); | |
110 | } |
|
110 | } | |
111 |
|
111 | |||
112 | /*! |
|
112 | /*! | |
113 | Removes all the QChartSeries that have been added to the QChartView |
|
113 | Removes all the QChartSeries that have been added to the QChartView | |
114 | It also deletes the pointed QChartSeries data objects |
|
114 | It also deletes the pointed QChartSeries data objects | |
115 | \sa addSeries(), removeSeries() |
|
115 | \sa addSeries(), removeSeries() | |
116 | */ |
|
116 | */ | |
117 | void QChart::removeAllSeries() |
|
117 | void QChart::removeAllSeries() | |
118 | { |
|
118 | { | |
119 | d_ptr->m_dataset->removeAllSeries(); |
|
119 | d_ptr->m_dataset->removeAllSeries(); | |
120 | } |
|
120 | } | |
121 |
|
121 | |||
122 | /*! |
|
122 | /*! | |
123 | Sets the \a brush that is used for painting the background of the chart area. |
|
123 | Sets the \a brush that is used for painting the background of the chart area. | |
124 | */ |
|
124 | */ | |
125 | void QChart::setBackgroundBrush(const QBrush& brush) |
|
125 | void QChart::setBackgroundBrush(const QBrush& brush) | |
126 | { |
|
126 | { | |
127 | d_ptr->createChartBackgroundItem(); |
|
127 | d_ptr->createChartBackgroundItem(); | |
128 | d_ptr->m_backgroundItem->setBrush(brush); |
|
128 | d_ptr->m_backgroundItem->setBrush(brush); | |
129 | d_ptr->m_backgroundItem->update(); |
|
129 | d_ptr->m_backgroundItem->update(); | |
130 | } |
|
130 | } | |
131 |
|
131 | |||
132 | QBrush QChart::backgroundBrush() const |
|
132 | QBrush QChart::backgroundBrush() const | |
133 | { |
|
133 | { | |
134 | if (!d_ptr->m_backgroundItem) return QBrush(); |
|
134 | if (!d_ptr->m_backgroundItem) return QBrush(); | |
135 | return (d_ptr->m_backgroundItem)->brush(); |
|
135 | return (d_ptr->m_backgroundItem)->brush(); | |
136 | } |
|
136 | } | |
137 |
|
137 | |||
138 | /*! |
|
138 | /*! | |
139 | Sets the \a pen that is used for painting the background of the chart area. |
|
139 | Sets the \a pen that is used for painting the background of the chart area. | |
140 | */ |
|
140 | */ | |
141 | void QChart::setBackgroundPen(const QPen& pen) |
|
141 | void QChart::setBackgroundPen(const QPen& pen) | |
142 | { |
|
142 | { | |
143 | d_ptr->createChartBackgroundItem(); |
|
143 | d_ptr->createChartBackgroundItem(); | |
144 | d_ptr->m_backgroundItem->setPen(pen); |
|
144 | d_ptr->m_backgroundItem->setPen(pen); | |
145 | d_ptr->m_backgroundItem->update(); |
|
145 | d_ptr->m_backgroundItem->update(); | |
146 | } |
|
146 | } | |
147 |
|
147 | |||
148 | QPen QChart::backgroundPen() const |
|
148 | QPen QChart::backgroundPen() const | |
149 | { |
|
149 | { | |
150 | if (!d_ptr->m_backgroundItem) return QPen(); |
|
150 | if (!d_ptr->m_backgroundItem) return QPen(); | |
151 | return d_ptr->m_backgroundItem->pen(); |
|
151 | return d_ptr->m_backgroundItem->pen(); | |
152 | } |
|
152 | } | |
153 |
|
153 | |||
154 | /*! |
|
154 | /*! | |
155 | Sets the chart \a title. The description text that is drawn above the chart. |
|
155 | Sets the chart \a title. The description text that is drawn above the chart. | |
156 | */ |
|
156 | */ | |
157 | void QChart::setTitle(const QString& title) |
|
157 | void QChart::setTitle(const QString& title) | |
158 | { |
|
158 | { | |
159 | d_ptr->createChartTitleItem(); |
|
159 | d_ptr->createChartTitleItem(); | |
160 | d_ptr->m_titleItem->setText(title); |
|
160 | d_ptr->m_titleItem->setText(title); | |
161 | d_ptr->updateLayout(); |
|
161 | d_ptr->updateLayout(); | |
162 | } |
|
162 | } | |
163 |
|
163 | |||
164 | /*! |
|
164 | /*! | |
165 | Returns the chart title. The description text that is drawn above the chart. |
|
165 | Returns the chart title. The description text that is drawn above the chart. | |
166 | */ |
|
166 | */ | |
167 | QString QChart::title() const |
|
167 | QString QChart::title() const | |
168 | { |
|
168 | { | |
169 | if (d_ptr->m_titleItem) |
|
169 | if (d_ptr->m_titleItem) | |
170 | return d_ptr->m_titleItem->text(); |
|
170 | return d_ptr->m_titleItem->text(); | |
171 | else |
|
171 | else | |
172 | return QString(); |
|
172 | return QString(); | |
173 | } |
|
173 | } | |
174 |
|
174 | |||
175 | /*! |
|
175 | /*! | |
176 | Sets the \a font that is used for rendering the description text that is rendered above the chart. |
|
176 | Sets the \a font that is used for rendering the description text that is rendered above the chart. | |
177 | */ |
|
177 | */ | |
178 | void QChart::setTitleFont(const QFont& font) |
|
178 | void QChart::setTitleFont(const QFont& font) | |
179 | { |
|
179 | { | |
180 | d_ptr->createChartTitleItem(); |
|
180 | d_ptr->createChartTitleItem(); | |
181 | d_ptr->m_titleItem->setFont(font); |
|
181 | d_ptr->m_titleItem->setFont(font); | |
182 | d_ptr->updateLayout(); |
|
182 | d_ptr->updateLayout(); | |
183 | } |
|
183 | } | |
184 |
|
184 | |||
185 | /*! |
|
185 | /*! | |
186 | Sets the \a brush used for rendering the title text. |
|
186 | Sets the \a brush used for rendering the title text. | |
187 | */ |
|
187 | */ | |
188 | void QChart::setTitleBrush(const QBrush &brush) |
|
188 | void QChart::setTitleBrush(const QBrush &brush) | |
189 | { |
|
189 | { | |
190 | d_ptr->createChartTitleItem(); |
|
190 | d_ptr->createChartTitleItem(); | |
191 | d_ptr->m_titleItem->setBrush(brush); |
|
191 | d_ptr->m_titleItem->setBrush(brush); | |
192 | d_ptr->updateLayout(); |
|
192 | d_ptr->updateLayout(); | |
193 | } |
|
193 | } | |
194 |
|
194 | |||
195 | /*! |
|
195 | /*! | |
196 | Returns the brush used for rendering the title text. |
|
196 | Returns the brush used for rendering the title text. | |
197 | */ |
|
197 | */ | |
198 | QBrush QChart::titleBrush() const |
|
198 | QBrush QChart::titleBrush() const | |
199 | { |
|
199 | { | |
200 | if (!d_ptr->m_titleItem) return QBrush(); |
|
200 | if (!d_ptr->m_titleItem) return QBrush(); | |
201 | return d_ptr->m_titleItem->brush(); |
|
201 | return d_ptr->m_titleItem->brush(); | |
202 | } |
|
202 | } | |
203 |
|
203 | |||
204 | /*! |
|
204 | /*! | |
205 | Sets the \a theme used by the chart for rendering the graphical representation of the data |
|
205 | Sets the \a theme used by the chart for rendering the graphical representation of the data | |
206 | \sa ChartTheme, chartTheme() |
|
206 | \sa ChartTheme, chartTheme() | |
207 | */ |
|
207 | */ | |
208 | void QChart::setTheme(QChart::ChartTheme theme) |
|
208 | void QChart::setTheme(QChart::ChartTheme theme) | |
209 | { |
|
209 | { | |
210 | d_ptr->m_presenter->setTheme(theme); |
|
210 | d_ptr->m_presenter->setTheme(theme); | |
211 | } |
|
211 | } | |
212 |
|
212 | |||
213 | /*! |
|
213 | /*! | |
214 | Returns the theme enum used by the chart. |
|
214 | Returns the theme enum used by the chart. | |
215 | \sa ChartTheme, setChartTheme() |
|
215 | \sa ChartTheme, setChartTheme() | |
216 | */ |
|
216 | */ | |
217 | QChart::ChartTheme QChart::theme() const |
|
217 | QChart::ChartTheme QChart::theme() const | |
218 | { |
|
218 | { | |
219 | return d_ptr->m_presenter->theme(); |
|
219 | return d_ptr->m_presenter->theme(); | |
220 | } |
|
220 | } | |
221 |
|
221 | |||
222 | /*! |
|
222 | /*! | |
223 | Zooms in the view by a factor of 2 |
|
223 | Zooms in the view by a factor of 2 | |
224 | */ |
|
224 | */ | |
225 | void QChart::zoomIn() |
|
225 | void QChart::zoomIn() | |
226 | { |
|
226 | { | |
227 | d_ptr->m_presenter->zoomIn(); |
|
227 | d_ptr->m_presenter->zoomIn(); | |
228 | } |
|
228 | } | |
229 |
|
229 | |||
230 | /*! |
|
230 | /*! | |
231 | Zooms in the view to a maximum level at which \a rect is still fully visible. |
|
231 | Zooms in the view to a maximum level at which \a rect is still fully visible. | |
232 | */ |
|
232 | */ | |
233 | void QChart::zoomIn(const QRectF& rect) |
|
233 | void QChart::zoomIn(const QRectF& rect) | |
234 | { |
|
234 | { | |
235 | if (!rect.isValid()) return; |
|
235 | if (!rect.isValid()) return; | |
236 | d_ptr->m_presenter->zoomIn(rect); |
|
236 | d_ptr->m_presenter->zoomIn(rect); | |
237 | } |
|
237 | } | |
238 |
|
238 | |||
239 | /*! |
|
239 | /*! | |
240 | Restores the view zoom level to the previous one. |
|
240 | Restores the view zoom level to the previous one. | |
241 | */ |
|
241 | */ | |
242 | void QChart::zoomOut() |
|
242 | void QChart::zoomOut() | |
243 | { |
|
243 | { | |
244 | d_ptr->m_presenter->zoomOut(); |
|
244 | d_ptr->m_presenter->zoomOut(); | |
245 | } |
|
245 | } | |
246 |
|
246 | |||
247 | /*! |
|
247 | /*! | |
248 | Returns the pointer to the x axis object of the chart |
|
248 | Returns the pointer to the x axis object of the chart | |
249 | */ |
|
249 | */ | |
250 | QChartAxis* QChart::axisX() const |
|
250 | QChartAxis* QChart::axisX() const | |
251 | { |
|
251 | { | |
252 | return d_ptr->m_dataset->axisX(); |
|
252 | return d_ptr->m_dataset->axisX(); | |
253 | } |
|
253 | } | |
254 |
|
254 | |||
255 | /*! |
|
255 | /*! | |
256 | Returns the pointer to the y axis object of the chart |
|
256 | Returns the pointer to the y axis object of the chart | |
257 | */ |
|
257 | */ | |
258 | QChartAxis* QChart::axisY() const |
|
258 | QChartAxis* QChart::axisY() const | |
259 | { |
|
259 | { | |
260 | return d_ptr->m_dataset->axisY(); |
|
260 | return d_ptr->m_dataset->axisY(); | |
261 | } |
|
261 | } | |
262 |
|
262 | |||
263 | /*! |
|
263 | /*! | |
264 | Returns the legend object of the chart. Ownership stays in chart. |
|
264 | Returns the legend object of the chart. Ownership stays in chart. | |
265 | */ |
|
265 | */ | |
266 | QLegend* QChart::legend() const |
|
266 | QLegend* QChart::legend() const | |
267 | { |
|
267 | { | |
268 | return d_ptr->m_legend; |
|
268 | return d_ptr->m_legend; | |
269 | } |
|
269 | } | |
270 |
|
270 | |||
271 |
QRect |
|
271 | QRect QChart::padding() const | |
272 | { |
|
272 | { | |
273 | return d_ptr->m_padding; |
|
273 | return d_ptr->m_padding; | |
274 | } |
|
274 | } | |
275 |
|
275 | |||
276 |
|
276 | |||
277 | /*! |
|
277 | /*! | |
278 | Resizes and updates the chart area using the \a event data |
|
278 | Resizes and updates the chart area using the \a event data | |
279 | */ |
|
279 | */ | |
280 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) |
|
280 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) | |
281 | { |
|
281 | { | |
282 | d_ptr->m_rect = QRectF(QPoint(0,0),event->newSize()); |
|
282 | d_ptr->m_rect = QRectF(QPoint(0,0),event->newSize()); | |
283 | d_ptr->updateLayout(); |
|
283 | d_ptr->updateLayout(); | |
284 | QGraphicsWidget::resizeEvent(event); |
|
284 | QGraphicsWidget::resizeEvent(event); | |
285 | update(); |
|
285 | update(); | |
286 | } |
|
286 | } | |
287 |
|
287 | |||
288 | /*! |
|
288 | /*! | |
289 | Sets animation \a options for the chart |
|
289 | Sets animation \a options for the chart | |
290 | */ |
|
290 | */ | |
291 | void QChart::setAnimationOptions(AnimationOptions options) |
|
291 | void QChart::setAnimationOptions(AnimationOptions options) | |
292 | { |
|
292 | { | |
293 | d_ptr->m_presenter->setAnimationOptions(options); |
|
293 | d_ptr->m_presenter->setAnimationOptions(options); | |
294 | } |
|
294 | } | |
295 |
|
295 | |||
296 | /*! |
|
296 | /*! | |
297 | Returns animation options for the chart |
|
297 | Returns animation options for the chart | |
298 | */ |
|
298 | */ | |
299 | QChart::AnimationOptions QChart::animationOptions() const |
|
299 | QChart::AnimationOptions QChart::animationOptions() const | |
300 | { |
|
300 | { | |
301 | return d_ptr->m_presenter->animationOptions(); |
|
301 | return d_ptr->m_presenter->animationOptions(); | |
302 | } |
|
302 | } | |
303 |
|
303 | |||
304 | void QChart::scrollLeft() |
|
304 | void QChart::scrollLeft() | |
305 | { |
|
305 | { | |
306 | d_ptr->m_presenter->scroll(-d_ptr->m_presenter->geometry().width()/(axisX()->ticksCount()-1),0); |
|
306 | d_ptr->m_presenter->scroll(-d_ptr->m_presenter->geometry().width()/(axisX()->ticksCount()-1),0); | |
307 | } |
|
307 | } | |
308 |
|
308 | |||
309 | void QChart::scrollRight() |
|
309 | void QChart::scrollRight() | |
310 | { |
|
310 | { | |
311 | d_ptr->m_presenter->scroll(d_ptr->m_presenter->geometry().width()/(axisX()->ticksCount()-1),0); |
|
311 | d_ptr->m_presenter->scroll(d_ptr->m_presenter->geometry().width()/(axisX()->ticksCount()-1),0); | |
312 | } |
|
312 | } | |
313 |
|
313 | |||
314 | void QChart::scrollUp() |
|
314 | void QChart::scrollUp() | |
315 | { |
|
315 | { | |
316 | d_ptr->m_presenter->scroll(0,d_ptr->m_presenter->geometry().width()/(axisY()->ticksCount()-1)); |
|
316 | d_ptr->m_presenter->scroll(0,d_ptr->m_presenter->geometry().width()/(axisY()->ticksCount()-1)); | |
317 | } |
|
317 | } | |
318 |
|
318 | |||
319 | void QChart::scrollDown() |
|
319 | void QChart::scrollDown() | |
320 | { |
|
320 | { | |
321 | d_ptr->m_presenter->scroll(0,-d_ptr->m_presenter->geometry().width()/(axisY()->ticksCount()-1)); |
|
321 | d_ptr->m_presenter->scroll(0,-d_ptr->m_presenter->geometry().width()/(axisY()->ticksCount()-1)); | |
322 | } |
|
322 | } | |
323 |
|
323 | |||
324 | void QChart::setBackgroundVisible(bool visible) |
|
324 | void QChart::setBackgroundVisible(bool visible) | |
325 | { |
|
325 | { | |
326 | d_ptr->createChartBackgroundItem(); |
|
326 | d_ptr->createChartBackgroundItem(); | |
327 | d_ptr->m_backgroundItem->setVisible(visible); |
|
327 | d_ptr->m_backgroundItem->setVisible(visible); | |
328 | } |
|
328 | } | |
329 |
|
329 | |||
330 | bool QChart::isBackgroundVisible() const |
|
330 | bool QChart::isBackgroundVisible() const | |
331 | { |
|
331 | { | |
332 | if (!d_ptr->m_backgroundItem) return false; |
|
332 | if (!d_ptr->m_backgroundItem) return false; | |
333 | return d_ptr->m_backgroundItem->isVisible(); |
|
333 | return d_ptr->m_backgroundItem->isVisible(); | |
334 | } |
|
334 | } | |
335 |
|
335 | |||
336 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
336 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
337 |
|
337 | |||
338 | QChartPrivate::QChartPrivate(QChart *parent): |
|
338 | QChartPrivate::QChartPrivate(QChart *parent): | |
339 | q_ptr(parent), |
|
339 | q_ptr(parent), | |
340 | m_backgroundItem(0), |
|
340 | m_backgroundItem(0), | |
341 | m_titleItem(0), |
|
341 | m_titleItem(0), | |
342 | m_legend(0), |
|
342 | m_legend(0), | |
343 | m_dataset(0), |
|
343 | m_dataset(0), | |
344 | m_presenter(0), |
|
344 | m_presenter(0), | |
345 |
m_padding(QRect |
|
345 | m_padding(QRect(50,50,0,0)) | |
346 | { |
|
346 | { | |
347 |
|
347 | |||
348 | } |
|
348 | } | |
349 |
|
349 | |||
350 | QChartPrivate::~QChartPrivate() |
|
350 | QChartPrivate::~QChartPrivate() | |
351 | { |
|
351 | { | |
352 |
|
352 | |||
353 | } |
|
353 | } | |
354 |
|
354 | |||
355 | void QChartPrivate::createChartBackgroundItem() |
|
355 | void QChartPrivate::createChartBackgroundItem() | |
356 | { |
|
356 | { | |
357 | if (!m_backgroundItem) { |
|
357 | if (!m_backgroundItem) { | |
358 | m_backgroundItem = new ChartBackground(q_ptr); |
|
358 | m_backgroundItem = new ChartBackground(q_ptr); | |
359 | m_backgroundItem->setPen(Qt::NoPen); |
|
359 | m_backgroundItem->setPen(Qt::NoPen); | |
360 | m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue); |
|
360 | m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue); | |
361 | } |
|
361 | } | |
362 | } |
|
362 | } | |
363 |
|
363 | |||
364 | void QChartPrivate::createChartTitleItem() |
|
364 | void QChartPrivate::createChartTitleItem() | |
365 | { |
|
365 | { | |
366 | if (!m_titleItem) { |
|
366 | if (!m_titleItem) { | |
367 | m_titleItem = new QGraphicsSimpleTextItem(q_ptr); |
|
367 | m_titleItem = new QGraphicsSimpleTextItem(q_ptr); | |
368 | m_titleItem->setZValue(ChartPresenter::BackgroundZValue); |
|
368 | m_titleItem->setZValue(ChartPresenter::BackgroundZValue); | |
369 | } |
|
369 | } | |
370 | } |
|
370 | } | |
371 |
|
371 | |||
372 | void QChartPrivate::updateLegendLayout() |
|
372 | void QChartPrivate::updateLegendLayout() | |
373 | { |
|
373 | { | |
374 | //int legendPadding = m_chart->legend()->padding(); |
|
374 | //int legendPadding = m_chart->legend()->padding(); | |
375 | int legendPadding = 30; |
|
375 | int legendPadding = 30; | |
376 | QRectF rect = m_rect; |
|
376 | QRectF rect = m_rect; | |
377 |
|
377 | |||
378 | if ((m_legend->attachedToChart()) && (m_legend->isVisible())) { |
|
378 | if ((m_legend->attachedToChart()) && (m_legend->isVisible())) { | |
379 |
|
379 | |||
380 | // Reserve some space for legend |
|
380 | // Reserve some space for legend | |
381 | switch (m_legend->alignment()) { |
|
381 | switch (m_legend->alignment()) { | |
382 | case QLegend::AlignmentTop: { |
|
382 | case QLegend::AlignmentTop: { | |
383 | rect.adjust(m_padding.left(), |
|
383 | rect.adjust(m_padding.left(), | |
384 | m_padding.top() + legendPadding, |
|
384 | m_padding.top() + legendPadding, | |
385 | -m_padding.right(), |
|
385 | -m_padding.right(), | |
386 | -m_padding.bottom()); |
|
386 | -m_padding.bottom()); | |
387 | break; |
|
387 | break; | |
388 | } |
|
388 | } | |
389 | case QLegend::AlignmentBottom: { |
|
389 | case QLegend::AlignmentBottom: { | |
390 | rect.adjust(m_padding.left(), |
|
390 | rect.adjust(m_padding.left(), | |
391 | m_padding.top(), |
|
391 | m_padding.top(), | |
392 | -m_padding.right(), |
|
392 | -m_padding.right(), | |
393 | -m_padding.bottom() - legendPadding); |
|
393 | -m_padding.bottom() - legendPadding); | |
394 | break; |
|
394 | break; | |
395 | } |
|
395 | } | |
396 | case QLegend::AlignmentLeft: { |
|
396 | case QLegend::AlignmentLeft: { | |
397 | rect.adjust(m_padding.left() + legendPadding, |
|
397 | rect.adjust(m_padding.left() + legendPadding, | |
398 | m_padding.top(), |
|
398 | m_padding.top(), | |
399 | -m_padding.right(), |
|
399 | -m_padding.right(), | |
400 | -m_padding.bottom()); |
|
400 | -m_padding.bottom()); | |
401 | break; |
|
401 | break; | |
402 | } |
|
402 | } | |
403 | case QLegend::AlignmentRight: { |
|
403 | case QLegend::AlignmentRight: { | |
404 | rect.adjust(m_padding.left(), |
|
404 | rect.adjust(m_padding.left(), | |
405 | m_padding.top(), |
|
405 | m_padding.top(), | |
406 | -m_padding.right() - legendPadding, |
|
406 | -m_padding.right() - legendPadding, | |
407 | -m_padding.bottom()); |
|
407 | -m_padding.bottom()); | |
408 | break; |
|
408 | break; | |
409 | } |
|
409 | } | |
410 | default: { |
|
410 | default: { | |
411 | rect.adjust(m_padding.left(), |
|
411 | rect.adjust(m_padding.left(), | |
412 | m_padding.top(), |
|
412 | m_padding.top(), | |
413 | -m_padding.right(), |
|
413 | -m_padding.right(), | |
414 | -m_padding.bottom()); |
|
414 | -m_padding.bottom()); | |
415 | break; |
|
415 | break; | |
416 | } |
|
416 | } | |
417 | } |
|
417 | } | |
418 | } else { |
|
418 | } else { | |
419 |
|
419 | |||
420 | rect.adjust(m_padding.left(), |
|
420 | rect.adjust(m_padding.left(), | |
421 | m_padding.top(), |
|
421 | m_padding.top(), | |
422 | -m_padding.right(), |
|
422 | -m_padding.right(), | |
423 | -m_padding.bottom()); |
|
423 | -m_padding.bottom()); | |
424 | } |
|
424 | } | |
425 |
|
425 | |||
426 | QRectF plotRect = m_rect.adjusted(m_padding.left() |
|
426 | QRectF plotRect = m_rect.adjusted(m_padding.left() | |
427 | ,m_padding.top() |
|
427 | ,m_padding.top() | |
428 | ,-m_padding.right() |
|
428 | ,-m_padding.right() | |
429 | ,-m_padding.bottom()); |
|
429 | ,-m_padding.bottom()); | |
430 | QRectF legendRect; |
|
430 | QRectF legendRect; | |
431 |
|
431 | |||
432 | int padding = 0; // TODO: fix this |
|
432 | int padding = 0; // TODO: fix this | |
433 | switch (m_legend->alignment()) |
|
433 | switch (m_legend->alignment()) | |
434 | { |
|
434 | { | |
435 | case QLegend::AlignmentTop: { |
|
435 | case QLegend::AlignmentTop: { | |
436 | legendRect = m_rect.adjusted(0,padding,0,-padding - plotRect.height()); |
|
436 | legendRect = m_rect.adjusted(0,padding,0,-padding - plotRect.height()); | |
437 | break; |
|
437 | break; | |
438 | } |
|
438 | } | |
439 | case QLegend::AlignmentBottom: { |
|
439 | case QLegend::AlignmentBottom: { | |
440 | legendRect = m_rect.adjusted(padding,padding + plotRect.height(),-padding,0); |
|
440 | legendRect = m_rect.adjusted(padding,padding + plotRect.height(),-padding,0); | |
441 | break; |
|
441 | break; | |
442 | } |
|
442 | } | |
443 | case QLegend::AlignmentLeft: { |
|
443 | case QLegend::AlignmentLeft: { | |
444 | legendRect = m_rect.adjusted(0,padding,-padding - plotRect.width(),-padding); |
|
444 | legendRect = m_rect.adjusted(0,padding,-padding - plotRect.width(),-padding); | |
445 | break; |
|
445 | break; | |
446 | } |
|
446 | } | |
447 | case QLegend::AlignmentRight: { |
|
447 | case QLegend::AlignmentRight: { | |
448 | legendRect = m_rect.adjusted(padding + plotRect.width(),padding,0,-padding); |
|
448 | legendRect = m_rect.adjusted(padding + plotRect.width(),padding,0,-padding); | |
449 | break; |
|
449 | break; | |
450 | } |
|
450 | } | |
451 | default: { |
|
451 | default: { | |
452 | legendRect = plotRect; |
|
452 | legendRect = plotRect; | |
453 | break; |
|
453 | break; | |
454 | } |
|
454 | } | |
455 | } |
|
455 | } | |
456 |
|
456 | |||
457 | m_legend->setMaximumSize(legendRect.size()); |
|
457 | m_legend->setMaximumSize(legendRect.size()); | |
458 |
|
458 | |||
459 | qreal width = legendRect.width() - m_legend->size().width(); |
|
459 | qreal width = legendRect.width() - m_legend->size().width(); | |
460 | qreal height = legendRect.height() - m_legend->size().height(); |
|
460 | qreal height = legendRect.height() - m_legend->size().height(); | |
461 |
|
461 | |||
462 | QPointF pos = legendRect.topLeft(); |
|
462 | QPointF pos = legendRect.topLeft(); | |
463 | if (width > 0) { |
|
463 | if (width > 0) { | |
464 | pos.setX(pos.x() + width/2); |
|
464 | pos.setX(pos.x() + width/2); | |
465 | } |
|
465 | } | |
466 | if (height > 0) { |
|
466 | if (height > 0) { | |
467 | pos.setY(pos.y() + height/2); |
|
467 | pos.setY(pos.y() + height/2); | |
468 | } |
|
468 | } | |
469 |
|
469 | |||
470 | m_legend->setPos(pos); |
|
470 | m_legend->setPos(pos); | |
471 | } |
|
471 | } | |
472 |
|
472 | |||
473 | void QChartPrivate::updateLayout() |
|
473 | void QChartPrivate::updateLayout() | |
474 | { |
|
474 | { | |
475 | if (!m_rect.isValid()) return; |
|
475 | if (!m_rect.isValid()) return; | |
476 |
|
476 | |||
477 | int padding = m_padding.top(); |
|
477 | int padding = m_padding.top(); | |
478 | int backgroundPadding = m_presenter->backgroundPadding(); |
|
478 | int backgroundPadding = m_presenter->backgroundPadding(); | |
479 |
|
479 | |||
480 | // recalculate title position |
|
480 | // recalculate title position | |
481 | if (m_titleItem) { |
|
481 | if (m_titleItem) { | |
482 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); |
|
482 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); | |
483 | m_titleItem->setPos(center.x(),m_rect.top()/2 + padding/2); |
|
483 | m_titleItem->setPos(center.x(),m_rect.top()/2 + padding/2); | |
484 | } |
|
484 | } | |
485 |
|
485 | |||
486 | //recalculate background gradient |
|
486 | //recalculate background gradient | |
487 | if (m_backgroundItem) { |
|
487 | if (m_backgroundItem) { | |
488 | m_backgroundItem->setRect(m_rect.adjusted(backgroundPadding,backgroundPadding, -backgroundPadding, -backgroundPadding)); |
|
488 | m_backgroundItem->setRect(m_rect.adjusted(backgroundPadding,backgroundPadding, -backgroundPadding, -backgroundPadding)); | |
489 | } |
|
489 | } | |
490 |
|
490 | |||
491 | // recalculate legend position |
|
491 | // recalculate legend position | |
492 | if (m_legend) { |
|
492 | if (m_legend) { | |
493 | if ((m_legend->attachedToChart()) && (m_legend->parentObject() == q_ptr)) { |
|
493 | if ((m_legend->attachedToChart()) && (m_legend->parentObject() == q_ptr)) { | |
494 | updateLegendLayout(); |
|
494 | updateLegendLayout(); | |
495 | } |
|
495 | } | |
496 | } |
|
496 | } | |
497 | } |
|
497 | } | |
498 |
|
498 | |||
499 | #include "moc_qchart.cpp" |
|
499 | #include "moc_qchart.cpp" | |
500 |
|
500 | |||
501 | QTCOMMERCIALCHART_END_NAMESPACE |
|
501 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,118 +1,117 | |||||
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 | public: |
|
39 | public: | |
40 | enum ChartTheme { |
|
40 | enum ChartTheme { | |
41 | ChartThemeDefault, |
|
41 | ChartThemeDefault, | |
42 | ChartThemeLight, |
|
42 | ChartThemeLight, | |
43 | ChartThemeBlueCerulean, |
|
43 | ChartThemeBlueCerulean, | |
44 | ChartThemeDark, |
|
44 | ChartThemeDark, | |
45 | ChartThemeBrownSand, |
|
45 | ChartThemeBrownSand, | |
46 | ChartThemeBlueNcs, |
|
46 | ChartThemeBlueNcs, | |
47 | ChartThemeHighContrast, |
|
47 | ChartThemeHighContrast, | |
48 | ChartThemeBlueIcy, |
|
48 | ChartThemeBlueIcy, | |
49 | ChartThemeCount |
|
49 | ChartThemeCount | |
50 | }; |
|
50 | }; | |
51 |
|
51 | |||
52 | enum AnimationOption { |
|
52 | enum AnimationOption { | |
53 | NoAnimation = 0x0, |
|
53 | NoAnimation = 0x0, | |
54 | GridAxisAnimations = 0x1, |
|
54 | GridAxisAnimations = 0x1, | |
55 | SeriesAnimations =0x2, |
|
55 | SeriesAnimations =0x2, | |
56 | AllAnimations = 0x3 |
|
56 | AllAnimations = 0x3 | |
57 | }; |
|
57 | }; | |
58 |
|
58 | |||
59 | Q_DECLARE_FLAGS(AnimationOptions, AnimationOption) |
|
59 | Q_DECLARE_FLAGS(AnimationOptions, AnimationOption) | |
60 |
|
60 | |||
61 | public: |
|
61 | public: | |
62 | explicit QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); |
|
62 | explicit QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); | |
63 | ~QChart(); |
|
63 | ~QChart(); | |
64 |
|
64 | |||
65 | void addSeries(QSeries *series, QChartAxis *axisY = 0); |
|
65 | void addSeries(QSeries *series, QChartAxis *axisY = 0); | |
66 | void removeSeries(QSeries *series); |
|
66 | void removeSeries(QSeries *series); | |
67 | void removeAllSeries(); |
|
67 | void removeAllSeries(); | |
68 |
|
68 | |||
69 | void setTheme(QChart::ChartTheme theme); |
|
69 | void setTheme(QChart::ChartTheme theme); | |
70 | QChart::ChartTheme theme() const; |
|
70 | QChart::ChartTheme theme() const; | |
71 |
|
71 | |||
72 | void setTitle(const QString& title); |
|
72 | void setTitle(const QString& title); | |
73 | QString title() const; |
|
73 | QString title() const; | |
74 | void setTitleFont(const QFont& font); |
|
74 | void setTitleFont(const QFont& font); | |
75 | QFont titleFont() const; |
|
75 | QFont titleFont() const; | |
76 | void setTitleBrush(const QBrush &brush); |
|
76 | void setTitleBrush(const QBrush &brush); | |
77 | QBrush titleBrush() const; |
|
77 | QBrush titleBrush() const; | |
78 | void setBackgroundBrush(const QBrush &brush); |
|
78 | void setBackgroundBrush(const QBrush &brush); | |
79 | QBrush backgroundBrush() const; |
|
79 | QBrush backgroundBrush() const; | |
80 | void setBackgroundPen(const QPen &pen); |
|
80 | void setBackgroundPen(const QPen &pen); | |
81 | QPen backgroundPen() const; |
|
81 | QPen backgroundPen() const; | |
82 |
|
82 | |||
83 | void setBackgroundVisible(bool visible); |
|
83 | void setBackgroundVisible(bool visible); | |
84 | bool isBackgroundVisible() const; |
|
84 | bool isBackgroundVisible() const; | |
85 |
|
85 | |||
86 | void setAnimationOptions(AnimationOptions options); |
|
86 | void setAnimationOptions(AnimationOptions options); | |
87 | AnimationOptions animationOptions() const; |
|
87 | AnimationOptions animationOptions() const; | |
88 |
|
88 | |||
89 | void zoomIn(); |
|
89 | void zoomIn(); | |
90 | void zoomIn(const QRectF &rect); |
|
90 | void zoomIn(const QRectF &rect); | |
91 | void zoomOut(); |
|
91 | void zoomOut(); | |
92 | void scrollLeft(); |
|
92 | void scrollLeft(); | |
93 | void scrollRight(); |
|
93 | void scrollRight(); | |
94 | void scrollUp(); |
|
94 | void scrollUp(); | |
95 | void scrollDown(); |
|
95 | void scrollDown(); | |
96 |
|
96 | |||
97 | QChartAxis* axisX() const; |
|
97 | QChartAxis* axisX() const; | |
98 | QChartAxis* axisY() const; |
|
98 | QChartAxis* axisY() const; | |
99 |
|
99 | |||
100 | QLegend* legend() const; |
|
100 | QLegend* legend() const; | |
101 |
|
101 | |||
102 |
QRect |
|
102 | QRect padding() const; | |
103 |
|
103 | |||
104 | protected: |
|
104 | protected: | |
105 | void resizeEvent(QGraphicsSceneResizeEvent *event); |
|
105 | void resizeEvent(QGraphicsSceneResizeEvent *event); | |
106 |
|
106 | |||
107 | protected: |
|
107 | protected: | |
108 | QScopedPointer<QChartPrivate> d_ptr; |
|
108 | QScopedPointer<QChartPrivate> d_ptr; | |
109 | friend class QChartView; |
|
|||
110 | friend class QLegend; |
|
109 | friend class QLegend; | |
111 | Q_DISABLE_COPY(QChart) |
|
110 | Q_DISABLE_COPY(QChart) | |
112 | }; |
|
111 | }; | |
113 |
|
112 | |||
114 | QTCOMMERCIALCHART_END_NAMESPACE |
|
113 | QTCOMMERCIALCHART_END_NAMESPACE | |
115 |
|
114 | |||
116 | Q_DECLARE_OPERATORS_FOR_FLAGS(QTCOMMERCIALCHART_NAMESPACE::QChart::AnimationOptions) |
|
115 | Q_DECLARE_OPERATORS_FOR_FLAGS(QTCOMMERCIALCHART_NAMESPACE::QChart::AnimationOptions) | |
117 |
|
116 | |||
118 | #endif |
|
117 | #endif |
@@ -1,64 +1,64 | |||||
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" |
|
33 | #include "qchartaxis.h" | |
34 | #include "qlegend.h" |
|
34 | #include "qlegend.h" | |
35 | #include "chartpresenter_p.h" |
|
35 | #include "chartpresenter_p.h" | |
36 | #include "chartdataset_p.h" |
|
36 | #include "chartdataset_p.h" | |
37 | #include "chartbackground_p.h" |
|
37 | #include "chartbackground_p.h" | |
38 |
|
38 | |||
39 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
39 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
40 |
|
40 | |||
41 | class QChart; |
|
41 | class QChart; | |
42 |
|
42 | |||
43 | struct QChartPrivate |
|
43 | struct QChartPrivate | |
44 | { |
|
44 | { | |
45 | QChartPrivate(QChart *parent); |
|
45 | QChartPrivate(QChart *parent); | |
46 | ~QChartPrivate(); |
|
46 | ~QChartPrivate(); | |
47 |
|
47 | |||
48 | void createChartBackgroundItem(); |
|
48 | void createChartBackgroundItem(); | |
49 | void createChartTitleItem(); |
|
49 | void createChartTitleItem(); | |
50 | void updateLayout(); |
|
50 | void updateLayout(); | |
51 | void updateLegendLayout(); |
|
51 | void updateLegendLayout(); | |
52 |
|
52 | |||
53 | QChart *q_ptr; |
|
53 | QChart *q_ptr; | |
54 | ChartBackground* m_backgroundItem; |
|
54 | ChartBackground* m_backgroundItem; | |
55 | QGraphicsSimpleTextItem* m_titleItem; |
|
55 | QGraphicsSimpleTextItem* m_titleItem; | |
56 | QRectF m_rect; |
|
56 | QRectF m_rect; | |
57 | QLegend* m_legend; |
|
57 | QLegend* m_legend; | |
58 | ChartDataSet *m_dataset; |
|
58 | ChartDataSet *m_dataset; | |
59 | ChartPresenter *m_presenter; |
|
59 | ChartPresenter *m_presenter; | |
60 |
QRect |
|
60 | QRect m_padding; | |
61 | }; |
|
61 | }; | |
62 |
|
62 | |||
63 | QTCOMMERCIALCHART_END_NAMESPACE |
|
63 | QTCOMMERCIALCHART_END_NAMESPACE | |
64 | #endif |
|
64 | #endif |
@@ -1,233 +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 | d_ptr->m_presenter = chart->d_ptr->m_presenter; |
|
|||
63 | setFrameShape(QFrame::NoFrame); |
|
62 | setFrameShape(QFrame::NoFrame); | |
64 | setBackgroundRole(QPalette::Window); |
|
63 | setBackgroundRole(QPalette::Window); | |
65 | setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
64 | setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |
66 | setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
65 | setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |
67 | setScene(d_ptr->m_scene); |
|
66 | setScene(d_ptr->m_scene); | |
68 | d_ptr->m_scene->addItem(chart); |
|
67 | d_ptr->m_scene->addItem(chart); | |
69 | setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
|
68 | setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | |
70 | } |
|
69 | } | |
71 |
|
70 | |||
72 |
|
71 | |||
73 | /*! |
|
72 | /*! | |
74 | 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. | |
75 | */ |
|
74 | */ | |
76 | QChartView::~QChartView() |
|
75 | QChartView::~QChartView() | |
77 | { |
|
76 | { | |
78 | } |
|
77 | } | |
79 |
|
78 | |||
80 | QChart* QChartView::chart() const |
|
79 | QChart* QChartView::chart() const | |
81 | { |
|
80 | { | |
82 | return d_ptr->m_chart; |
|
81 | return d_ptr->m_chart; | |
83 | } |
|
82 | } | |
84 |
|
83 | |||
85 | /*! |
|
84 | /*! | |
86 | 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. | |
87 | */ |
|
86 | */ | |
88 | void QChartView::setRubberBand(const RubberBands& rubberBand) |
|
87 | void QChartView::setRubberBand(const RubberBands& rubberBand) | |
89 | { |
|
88 | { | |
90 | d_ptr->m_rubberBandFlags=rubberBand; |
|
89 | d_ptr->m_rubberBandFlags=rubberBand; | |
91 |
|
90 | |||
92 | if (!d_ptr->m_rubberBandFlags) { |
|
91 | if (!d_ptr->m_rubberBandFlags) { | |
93 | delete d_ptr->m_rubberBand; |
|
92 | delete d_ptr->m_rubberBand; | |
94 | d_ptr->m_rubberBand=0; |
|
93 | d_ptr->m_rubberBand=0; | |
95 | return; |
|
94 | return; | |
96 | } |
|
95 | } | |
97 |
|
96 | |||
98 | if (!d_ptr->m_rubberBand) { |
|
97 | if (!d_ptr->m_rubberBand) { | |
99 | d_ptr->m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this); |
|
98 | d_ptr->m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this); | |
100 | d_ptr->m_rubberBand->setEnabled(true); |
|
99 | d_ptr->m_rubberBand->setEnabled(true); | |
101 | } |
|
100 | } | |
102 | } |
|
101 | } | |
103 |
|
102 | |||
104 | /*! |
|
103 | /*! | |
105 | Returns the RubberBandPolicy that is currently being used by the widget. |
|
104 | Returns the RubberBandPolicy that is currently being used by the widget. | |
106 | */ |
|
105 | */ | |
107 | QChartView::RubberBands QChartView::rubberBand() const |
|
106 | QChartView::RubberBands QChartView::rubberBand() const | |
108 | { |
|
107 | { | |
109 | return d_ptr->m_rubberBandFlags; |
|
108 | return d_ptr->m_rubberBandFlags; | |
110 | } |
|
109 | } | |
111 |
|
110 | |||
112 | /*! |
|
111 | /*! | |
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. |
|
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. | |
114 | 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. | |
115 | */ |
|
114 | */ | |
116 | void QChartView::mousePressEvent(QMouseEvent *event) |
|
115 | void QChartView::mousePressEvent(QMouseEvent *event) | |
117 | { |
|
116 | { | |
118 | 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) { | |
119 |
|
118 | |||
120 | int padding = d_ptr->m_chart->padding().top(); |
|
119 | int padding = d_ptr->m_chart->padding().top(); | |
121 | QRect rect(padding, padding, width() - 2 * padding, height() - 2 * padding); |
|
120 | QRect rect(padding, padding, width() - 2 * padding, height() - 2 * padding); | |
122 |
|
121 | |||
123 | if (rect.contains(event->pos())) { |
|
122 | if (rect.contains(event->pos())) { | |
124 | d_ptr->m_rubberBandOrigin = event->pos(); |
|
123 | d_ptr->m_rubberBandOrigin = event->pos(); | |
125 | d_ptr->m_rubberBand->setGeometry(QRect(d_ptr->m_rubberBandOrigin, QSize())); |
|
124 | d_ptr->m_rubberBand->setGeometry(QRect(d_ptr->m_rubberBandOrigin, QSize())); | |
126 | d_ptr->m_rubberBand->show(); |
|
125 | d_ptr->m_rubberBand->show(); | |
127 | event->accept(); |
|
126 | event->accept(); | |
128 | } |
|
127 | } | |
129 | } |
|
128 | } | |
130 | else { |
|
129 | else { | |
131 | QGraphicsView::mousePressEvent(event); |
|
130 | QGraphicsView::mousePressEvent(event); | |
132 | } |
|
131 | } | |
133 | } |
|
132 | } | |
134 |
|
133 | |||
135 | /*! |
|
134 | /*! | |
136 | 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. | |
137 | In other case the defualt QGraphicsView::mouseMoveEvent implementation is called. |
|
136 | In other case the defualt QGraphicsView::mouseMoveEvent implementation is called. | |
138 | */ |
|
137 | */ | |
139 | void QChartView::mouseMoveEvent(QMouseEvent *event) |
|
138 | void QChartView::mouseMoveEvent(QMouseEvent *event) | |
140 | { |
|
139 | { | |
141 | if(d_ptr->m_rubberBand && d_ptr->m_rubberBand->isVisible()) { |
|
140 | if(d_ptr->m_rubberBand && d_ptr->m_rubberBand->isVisible()) { | |
142 | int padding = d_ptr->m_chart->padding().top(); |
|
141 | int padding = d_ptr->m_chart->padding().top(); | |
143 | QRect rect(padding, padding, width() - 2 * padding, height() - 2 * padding); |
|
142 | QRect rect(padding, padding, width() - 2 * padding, height() - 2 * padding); | |
144 | int width = event->pos().x() - d_ptr->m_rubberBandOrigin.x(); |
|
143 | int width = event->pos().x() - d_ptr->m_rubberBandOrigin.x(); | |
145 | int height = event->pos().y() - d_ptr->m_rubberBandOrigin.y(); |
|
144 | int height = event->pos().y() - d_ptr->m_rubberBandOrigin.y(); | |
146 | if (!d_ptr->m_rubberBandFlags.testFlag(VerticalRubberBand)) { |
|
145 | if (!d_ptr->m_rubberBandFlags.testFlag(VerticalRubberBand)) { | |
147 | d_ptr->m_rubberBandOrigin.setY(rect.top()); |
|
146 | d_ptr->m_rubberBandOrigin.setY(rect.top()); | |
148 | height = rect.height(); |
|
147 | height = rect.height(); | |
149 | } |
|
148 | } | |
150 | if (!d_ptr->m_rubberBandFlags.testFlag(HorizonalRubberBand)) { |
|
149 | if (!d_ptr->m_rubberBandFlags.testFlag(HorizonalRubberBand)) { | |
151 | d_ptr->m_rubberBandOrigin.setX(rect.left()); |
|
150 | d_ptr->m_rubberBandOrigin.setX(rect.left()); | |
152 | width= rect.width(); |
|
151 | width= rect.width(); | |
153 | } |
|
152 | } | |
154 | 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()); | |
155 | } |
|
154 | } | |
156 | else { |
|
155 | else { | |
157 | QGraphicsView::mouseMoveEvent(event); |
|
156 | QGraphicsView::mouseMoveEvent(event); | |
158 | } |
|
157 | } | |
159 | } |
|
158 | } | |
160 |
|
159 | |||
161 | /*! |
|
160 | /*! | |
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 |
|
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 | |
163 | 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. | |
164 | */ |
|
163 | */ | |
165 | void QChartView::mouseReleaseEvent(QMouseEvent *event) |
|
164 | void QChartView::mouseReleaseEvent(QMouseEvent *event) | |
166 | { |
|
165 | { | |
167 | if(d_ptr->m_rubberBand) { |
|
166 | if(d_ptr->m_rubberBand) { | |
168 | if (event->button() == Qt::LeftButton && d_ptr->m_rubberBand->isVisible()) { |
|
167 | if (event->button() == Qt::LeftButton && d_ptr->m_rubberBand->isVisible()) { | |
169 | d_ptr->m_rubberBand->hide(); |
|
168 | d_ptr->m_rubberBand->hide(); | |
170 | QRect rect = d_ptr->m_rubberBand->geometry(); |
|
169 | QRect rect = d_ptr->m_rubberBand->geometry(); | |
171 | d_ptr->m_chart->zoomIn(rect); |
|
170 | d_ptr->m_chart->zoomIn(rect); | |
172 | event->accept(); |
|
171 | event->accept(); | |
173 | } |
|
172 | } | |
174 |
|
173 | |||
175 | if(event->button()==Qt::RightButton){ |
|
174 | if(event->button()==Qt::RightButton){ | |
176 | d_ptr->m_chart->zoomOut(); |
|
175 | d_ptr->m_chart->zoomOut(); | |
177 | event->accept(); |
|
176 | event->accept(); | |
178 | } |
|
177 | } | |
179 | } |
|
178 | } | |
180 | else { |
|
179 | else { | |
181 | QGraphicsView::mouseReleaseEvent(event); |
|
180 | QGraphicsView::mouseReleaseEvent(event); | |
182 | } |
|
181 | } | |
183 | } |
|
182 | } | |
184 |
|
183 | |||
185 | /*! |
|
184 | /*! | |
186 | Pressing + and - keys performs zoomIn() and zoomOut() respectivly. |
|
185 | Pressing + and - keys performs zoomIn() and zoomOut() respectivly. | |
187 | In other \a event is passed to the QGraphicsView::keyPressEvent() implementation |
|
186 | In other \a event is passed to the QGraphicsView::keyPressEvent() implementation | |
188 | */ |
|
187 | */ | |
189 | void QChartView::keyPressEvent(QKeyEvent *event) |
|
188 | void QChartView::keyPressEvent(QKeyEvent *event) | |
190 | { |
|
189 | { | |
191 | switch (event->key()) { |
|
190 | switch (event->key()) { | |
192 | case Qt::Key_Plus: |
|
191 | case Qt::Key_Plus: | |
193 | d_ptr->m_chart->zoomIn(); |
|
192 | d_ptr->m_chart->zoomIn(); | |
194 | break; |
|
193 | break; | |
195 | case Qt::Key_Minus: |
|
194 | case Qt::Key_Minus: | |
196 | d_ptr->m_chart->zoomOut(); |
|
195 | d_ptr->m_chart->zoomOut(); | |
197 | break; |
|
196 | break; | |
|
197 | case Qt::Key_Left: | |||
|
198 | d_ptr->m_chart->scrollLeft(); | |||
|
199 | break; | |||
|
200 | case Qt::Key_Right: | |||
|
201 | d_ptr->m_chart->scrollRight(); | |||
|
202 | break; | |||
|
203 | case Qt::Key_Up: | |||
|
204 | d_ptr->m_chart->scrollUp(); | |||
|
205 | break; | |||
|
206 | case Qt::Key_Down: | |||
|
207 | d_ptr->m_chart->scrollDown(); | |||
|
208 | break; | |||
198 | default: |
|
209 | default: | |
199 | QGraphicsView::keyPressEvent(event); |
|
210 | QGraphicsView::keyPressEvent(event); | |
200 | break; |
|
211 | break; | |
201 | } |
|
212 | } | |
202 | } |
|
213 | } | |
203 |
|
214 | |||
204 | /*! |
|
215 | /*! | |
205 | Resizes and updates the chart area using the \a event data |
|
216 | Resizes and updates the chart area using the \a event data | |
206 | */ |
|
217 | */ | |
207 | void QChartView::resizeEvent(QResizeEvent *event) |
|
218 | void QChartView::resizeEvent(QResizeEvent *event) | |
208 | { |
|
219 | { | |
209 | QGraphicsView::resizeEvent(event); |
|
220 | QGraphicsView::resizeEvent(event); | |
210 | d_ptr->m_chart->resize(size()); |
|
221 | d_ptr->m_chart->resize(size()); | |
211 | setSceneRect(d_ptr->m_chart->geometry()); |
|
222 | setSceneRect(d_ptr->m_chart->geometry()); | |
212 | } |
|
223 | } | |
213 |
|
224 | |||
214 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
225 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
215 |
|
226 | |||
216 | QChartViewPrivate::QChartViewPrivate(): |
|
227 | QChartViewPrivate::QChartViewPrivate(): | |
217 | m_scene(0), |
|
228 | m_scene(0), | |
218 | m_chart(0), |
|
229 | m_chart(0), | |
219 | m_presenter(0), |
|
230 | m_presenter(0), | |
220 | m_rubberBand(0), |
|
231 | m_rubberBand(0), | |
221 | m_rubberBandFlags(QChartView::NoRubberBand) |
|
232 | m_rubberBandFlags(QChartView::NoRubberBand) | |
222 | { |
|
233 | { | |
223 |
|
234 | |||
224 | } |
|
235 | } | |
225 |
|
236 | |||
226 | QChartViewPrivate::~QChartViewPrivate() |
|
237 | QChartViewPrivate::~QChartViewPrivate() | |
227 | { |
|
238 | { | |
228 |
|
239 | |||
229 | } |
|
240 | } | |
230 |
|
241 | |||
231 | #include "moc_qchartview.cpp" |
|
242 | #include "moc_qchartview.cpp" | |
232 |
|
243 | |||
233 | QTCOMMERCIALCHART_END_NAMESPACE |
|
244 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,162 +1,216 | |||||
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 |
|
33 | |||
33 | class tst_QChartView : public QObject |
|
34 | class tst_QChartView : public QObject | |
34 | { |
|
35 | { | |
35 | Q_OBJECT |
|
36 | Q_OBJECT | |
36 |
|
37 | |||
37 | public Q_SLOTS: |
|
38 | public Q_SLOTS: | |
38 | void initTestCase(); |
|
39 | void initTestCase(); | |
39 | void cleanupTestCase(); |
|
40 | void cleanupTestCase(); | |
40 | void init(); |
|
41 | void init(); | |
41 | void cleanup(); |
|
42 | void cleanup(); | |
42 |
|
43 | |||
43 | private Q_SLOTS: |
|
44 | private Q_SLOTS: | |
44 | void qchartview_data(); |
|
45 | void qchartview_data(); | |
45 | void qchartview(); |
|
46 | void qchartview(); | |
46 | void chart_data(); |
|
47 | void chart_data(); | |
47 | void chart(); |
|
48 | void chart(); | |
48 | void rubberBand_data(); |
|
49 | void rubberBand_data(); | |
49 | void rubberBand(); |
|
50 | void rubberBand(); | |
|
51 | void keys_data(); | |||
|
52 | void keys(); | |||
50 |
|
53 | |||
51 | private: |
|
54 | private: | |
52 | QChartView* m_view; |
|
55 | QChartView* m_view; | |
53 | }; |
|
56 | }; | |
54 |
|
57 | |||
55 | void tst_QChartView::initTestCase() |
|
58 | void tst_QChartView::initTestCase() | |
56 | { |
|
59 | { | |
|
60 | //test tracks mouse, give a while to user to relese it | |||
|
61 | QTest::qWait(1000); | |||
57 | } |
|
62 | } | |
58 |
|
63 | |||
59 | void tst_QChartView::cleanupTestCase() |
|
64 | void tst_QChartView::cleanupTestCase() | |
60 | { |
|
65 | { | |
61 | } |
|
66 | } | |
62 |
|
67 | |||
63 | void tst_QChartView::init() |
|
68 | void tst_QChartView::init() | |
64 | { |
|
69 | { | |
65 | m_view = new QChartView(new QChart()); |
|
70 | m_view = new QChartView(new QChart()); | |
66 | } |
|
71 | } | |
67 |
|
72 | |||
68 | void tst_QChartView::cleanup() |
|
73 | void tst_QChartView::cleanup() | |
69 | { |
|
74 | { | |
70 | delete m_view; |
|
75 | delete m_view; | |
71 | m_view =0; |
|
76 | m_view =0; | |
72 | } |
|
77 | } | |
73 |
|
78 | |||
74 | void tst_QChartView::qchartview_data() |
|
79 | void tst_QChartView::qchartview_data() | |
75 | { |
|
80 | { | |
76 |
|
81 | |||
77 | } |
|
82 | } | |
78 |
|
83 | |||
79 | void tst_QChartView::qchartview() |
|
84 | void tst_QChartView::qchartview() | |
80 | { |
|
85 | { | |
81 | QVERIFY(m_view->chart()); |
|
86 | QVERIFY(m_view->chart()); | |
82 | QCOMPARE(m_view->rubberBand(), QChartView::NoRubberBand); |
|
87 | QCOMPARE(m_view->rubberBand(), QChartView::NoRubberBand); | |
83 | m_view->show(); |
|
88 | m_view->show(); | |
84 | QTest::qWaitForWindowShown(m_view); |
|
89 | QTest::qWaitForWindowShown(m_view); | |
85 | } |
|
90 | } | |
86 |
|
91 | |||
87 | void tst_QChartView::chart_data() |
|
92 | void tst_QChartView::chart_data() | |
88 | { |
|
93 | { | |
89 |
|
94 | |||
90 | QTest::addColumn<QChart*>("chart"); |
|
95 | QTest::addColumn<QChart*>("chart"); | |
91 | QTest::newRow("qchart") << new QChart(); |
|
96 | QTest::newRow("qchart") << new QChart(); | |
92 | } |
|
97 | } | |
93 |
|
98 | |||
94 | void tst_QChartView::chart() |
|
99 | void tst_QChartView::chart() | |
95 | { |
|
100 | { | |
96 | QFETCH(QChart*, chart); |
|
101 | QFETCH(QChart*, chart); | |
97 | QChartView* view = new QChartView(chart); |
|
102 | QChartView* view = new QChartView(chart); | |
98 | QCOMPARE(view->chart(), chart); |
|
103 | QCOMPARE(view->chart(), chart); | |
99 | delete view; |
|
104 | delete view; | |
100 | } |
|
105 | } | |
101 |
|
106 | |||
102 | void tst_QChartView::rubberBand_data() |
|
107 | void tst_QChartView::rubberBand_data() | |
103 | { |
|
108 | { | |
104 | QTest::addColumn<QChartView::RubberBands>("rubberBand"); |
|
109 | QTest::addColumn<QChartView::RubberBands>("rubberBand"); | |
105 | QTest::addColumn<int>("Xcount"); |
|
110 | QTest::addColumn<int>("Xcount"); | |
106 | QTest::addColumn<int>("Ycount"); |
|
111 | QTest::addColumn<int>("Ycount"); | |
107 |
|
112 | |||
108 | QTest::addColumn<int>("minX"); |
|
113 | QTest::addColumn<int>("minX"); | |
109 | QTest::addColumn<int>("maxX"); |
|
114 | QTest::addColumn<int>("maxX"); | |
110 | QTest::addColumn<int>("minY"); |
|
115 | QTest::addColumn<int>("minY"); | |
111 | QTest::addColumn<int>("maxY"); |
|
116 | QTest::addColumn<int>("maxY"); | |
112 |
|
117 | |||
113 | 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; | |
114 |
QTest::newRow("VerticalRubberBand") << QChartView::RubberBands(QChartView::VerticalRubberBand) << 1 << 0 << |
|
119 | QTest::newRow("VerticalRubberBand") << QChartView::RubberBands(QChartView::VerticalRubberBand) << 1 << 0 << 0 << 100 << 10<< 90; | |
115 |
QTest::newRow("RectangleRubberBand") << QChartView::RubberBands(QChartView::RectangleRubberBand) << 1 << 1 <<10 << 90 << 0<< |
|
120 | QTest::newRow("RectangleRubberBand") << QChartView::RubberBands(QChartView::RectangleRubberBand) << 1 << 1 <<10 << 90 << 10<< 90; | |
116 | } |
|
121 | } | |
117 |
|
122 | |||
118 | void tst_QChartView::rubberBand() |
|
123 | void tst_QChartView::rubberBand() | |
119 | { |
|
124 | { | |
120 | QFETCH(QChartView::RubberBands, rubberBand); |
|
125 | QFETCH(QChartView::RubberBands, rubberBand); | |
121 | QFETCH(int, Xcount); |
|
126 | QFETCH(int, Xcount); | |
122 | QFETCH(int, Ycount); |
|
127 | QFETCH(int, Ycount); | |
123 | QFETCH(int, minX); |
|
128 | QFETCH(int, minX); | |
124 | QFETCH(int, maxX); |
|
129 | QFETCH(int, maxX); | |
125 | QFETCH(int, minY); |
|
130 | QFETCH(int, minY); | |
126 | QFETCH(int, maxY); |
|
131 | QFETCH(int, maxY); | |
127 |
|
132 | |||
128 | m_view->setRubberBand(rubberBand); |
|
133 | m_view->setRubberBand(rubberBand); | |
|
134 | QRect padding = m_view->chart()->padding(); | |||
129 | QCOMPARE(m_view->rubberBand(), rubberBand); |
|
135 | QCOMPARE(m_view->rubberBand(), rubberBand); | |
130 |
|
136 | |||
131 | QLineSeries* line = new QLineSeries(); |
|
137 | QLineSeries* line = new QLineSeries(); | |
132 | *line << QPointF(0, 0) << QPointF(100, 100); |
|
138 | *line << QPointF(0, 0) << QPointF(100, 100); | |
133 |
|
139 | |||
134 | m_view->chart()->addSeries(line); |
|
140 | m_view->chart()->addSeries(line); | |
135 | m_view->resize(1000, 1000); |
|
141 | m_view->resize(100 + padding.left() + padding.right(), 100 + padding.top()+ padding.bottom()); | |
136 | m_view->show(); |
|
142 | m_view->show(); | |
|
143 | ||||
|
144 | //this is hack since view does not get events otherwise | |||
137 | m_view->setMouseTracking(true); |
|
145 | m_view->setMouseTracking(true); | |
138 |
|
146 | |||
139 | QChartAxis* axisY = m_view->chart()->axisY(); |
|
147 | QChartAxis* axisY = m_view->chart()->axisY(); | |
140 | QSignalSpy spy0(axisY, SIGNAL(rangeChanged(qreal, qreal))); |
|
148 | QSignalSpy spy0(axisY, SIGNAL(rangeChanged(qreal, qreal))); | |
141 | QChartAxis* axisX = m_view->chart()->axisX(); |
|
149 | QChartAxis* axisX = m_view->chart()->axisX(); | |
142 | QSignalSpy spy1(axisX, SIGNAL(rangeChanged(qreal, qreal))); |
|
150 | QSignalSpy spy1(axisX, SIGNAL(rangeChanged(qreal, qreal))); | |
143 |
|
151 | |||
|
152 | ||||
144 | QTest::qWaitForWindowShown(m_view); |
|
153 | QTest::qWaitForWindowShown(m_view); | |
145 |
QTest::mouseMove(m_view->viewport(), QPoint( |
|
154 | QTest::mouseMove(m_view->viewport(), QPoint(minX, minY) + padding.topLeft()); | |
146 | QTest::mousePress(m_view->viewport(), Qt::LeftButton, 0, QPoint(250, 250)); |
|
155 | ||
147 |
QTest::mouse |
|
156 | QTest::mousePress(m_view->viewport(), Qt::LeftButton, 0, QPoint(minX, minY) + padding.topLeft()); | |
148 | QTest::qWait(3000); |
|
157 | QTest::mouseMove(m_view->viewport(), QPoint(maxX, maxY) + padding.topLeft()); | |
149 | QTest::mouseRelease(m_view->viewport(), Qt::LeftButton, 0, QPoint(900, 900)); |
|
158 | ||
150 | QTest::qWait(3000); |
|
159 | QTest::mouseRelease(m_view->viewport(), Qt::LeftButton, 0, QPoint(maxX, maxY)+ padding.topLeft()); | |
|
160 | ||||
151 | QCOMPARE(spy0.count(), Xcount); |
|
161 | QCOMPARE(spy0.count(), Xcount); | |
152 | QCOMPARE(spy1.count(), Ycount); |
|
162 | QCOMPARE(spy1.count(), Ycount); | |
153 | qDebug()<<axisX->min(); |
|
163 | ||
154 | QVERIFY(int(ceil(axisX->min())) - minX < 1); |
|
164 | //this is hack since view does not get events otherwise | |
155 | QVERIFY(int(ceil(axisX->max())) - maxX < 1); |
|
165 | m_view->setMouseTracking(false); | |
156 | QVERIFY(int(ceil(axisY->min())) - minY < 1); |
|
166 | ||
157 |
QVERIFY( |
|
167 | QVERIFY(axisX->min() - minX < 1); | |
|
168 | QVERIFY(axisX->max() - maxX < 1); | |||
|
169 | QVERIFY(axisY->min() - minY < 1); | |||
|
170 | QVERIFY(axisY->max() - maxY < 1); | |||
|
171 | } | |||
|
172 | ||||
|
173 | void tst_QChartView::keys_data() | |||
|
174 | { | |||
|
175 | QTest::addColumn<Qt::Key>("key"); | |||
|
176 | QTest::addColumn<int>("Xcount"); | |||
|
177 | QTest::addColumn<int>("Ycount"); | |||
|
178 | QTest::newRow("Qt::Key_Plus") << Qt::Key_Plus << 1 << 1; | |||
|
179 | QTest::newRow("Qt::Key_Minus") << Qt::Key_Minus << 1 << 1; | |||
|
180 | QTest::newRow("Qt::Key_Up") << Qt::Key_Up << 0 << 1; | |||
|
181 | QTest::newRow("Qt::Key_Down") << Qt::Key_Down << 0 << 1; | |||
|
182 | QTest::newRow("Qt::Key_Left") << Qt::Key_Left << 1 << 0; | |||
|
183 | QTest::newRow("Qt::Key_Right") << Qt::Key_Right << 1 << 0; | |||
|
184 | } | |||
|
185 | ||||
|
186 | void tst_QChartView::keys() | |||
|
187 | { | |||
|
188 | QFETCH(Qt::Key,key); | |||
|
189 | QFETCH(int, Xcount); | |||
|
190 | QFETCH(int, Ycount); | |||
|
191 | ||||
|
192 | QRect padding = m_view->chart()->padding(); | |||
|
193 | ||||
|
194 | QLineSeries* line = new QLineSeries(); | |||
|
195 | *line << QPointF(0, 0) << QPointF(100, 100); | |||
|
196 | ||||
|
197 | m_view->chart()->addSeries(line); | |||
|
198 | m_view->resize(100 + padding.left() + padding.right(), 100 + padding.top()+ padding.bottom()); | |||
|
199 | m_view->show(); | |||
|
200 | ||||
|
201 | QChartAxis* axisY = m_view->chart()->axisY(); | |||
|
202 | QSignalSpy spy0(axisY, SIGNAL(rangeChanged(qreal, qreal))); | |||
|
203 | QChartAxis* axisX = m_view->chart()->axisX(); | |||
|
204 | QSignalSpy spy1(axisX, SIGNAL(rangeChanged(qreal, qreal))); | |||
|
205 | ||||
|
206 | QTest::keyPress(m_view, key); | |||
|
207 | QTest::keyRelease(m_view, key); | |||
|
208 | ||||
|
209 | QCOMPARE(spy0.count(), Ycount); | |||
|
210 | QCOMPARE(spy1.count(), Xcount); | |||
|
211 | ||||
158 | } |
|
212 | } | |
159 |
|
213 | |||
160 | QTEST_MAIN(tst_QChartView) |
|
214 | QTEST_MAIN(tst_QChartView) | |
161 | #include "tst_qchartview.moc" |
|
215 | #include "tst_qchartview.moc" | |
162 |
|
216 |
General Comments 0
You need to be logged in to leave comments.
Login now