@@ -1,360 +1,371 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qchart.h" |
|
22 | 22 | #include "qchart_p.h" |
|
23 | 23 | #include <QGraphicsScene> |
|
24 | 24 | #include <QGraphicsSceneResizeEvent> |
|
25 | 25 | |
|
26 | 26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | 27 | |
|
28 | 28 | /*! |
|
29 | 29 | \enum QChart::ChartTheme |
|
30 | 30 | |
|
31 | 31 | This enum describes the theme used by the chart. |
|
32 | 32 | |
|
33 | 33 | \value ChartThemeLight The default theme |
|
34 | 34 | \value ChartThemeBlueCerulean |
|
35 | 35 | \value ChartThemeDark |
|
36 | 36 | \value ChartThemeBrownSand |
|
37 | 37 | \value ChartThemeBlueNcs |
|
38 | 38 | \value ChartThemeHighContrast |
|
39 | 39 | \value ChartThemeBlueIcy |
|
40 | 40 | \value ChartThemeCount Not really a theme; the total count of themes. |
|
41 | 41 | */ |
|
42 | 42 | |
|
43 | 43 | /*! |
|
44 | 44 | \enum QChart::AnimationOption |
|
45 | 45 | |
|
46 | 46 | For enabling/disabling animations. Defaults to NoAnimation. |
|
47 | 47 | |
|
48 | 48 | \value NoAnimation |
|
49 | 49 | \value GridAxisAnimations |
|
50 | 50 | \value SeriesAnimations |
|
51 | 51 | \value AllAnimations |
|
52 | 52 | */ |
|
53 | 53 | |
|
54 | 54 | /*! |
|
55 | 55 | \class QChart |
|
56 | 56 | \brief QtCommercial chart API. |
|
57 | 57 | |
|
58 | 58 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical |
|
59 | 59 | representation of different types of QChartSeries and other chart related objects like |
|
60 | 60 | QChartAxis and QChartLegend. If you simply want to show a chart in a layout, you can use the |
|
61 | 61 | convenience class QChartView instead of QChart. |
|
62 | 62 | \sa QChartView |
|
63 | 63 | */ |
|
64 | 64 | |
|
65 | 65 | /*! |
|
66 | 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 | 68 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), |
|
69 | 69 | d_ptr(new QChartPrivate()) |
|
70 | 70 | { |
|
71 | 71 | d_ptr->m_legend = new ScrolledQLegend(this); |
|
72 | 72 | d_ptr->m_dataset = new ChartDataSet(this); |
|
73 | 73 | d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset); |
|
74 | 74 | d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false); |
|
75 | 75 | d_ptr->createConnections(); |
|
76 | 76 | //TODO:fix me setMinimumSize(d_ptr->m_padding.left() * 3, d_ptr->m_padding.top() * 3); |
|
77 | 77 | } |
|
78 | 78 | |
|
79 | 79 | /*! |
|
80 | 80 | Destroys the object and it's children, like QChartSeries and QChartAxis object added to it. |
|
81 | 81 | */ |
|
82 | 82 | QChart::~QChart() |
|
83 | 83 | { |
|
84 | 84 | //delete first presenter , since this is a root of all the graphical items |
|
85 | 85 | delete d_ptr->m_presenter; |
|
86 | 86 | d_ptr->m_presenter=0; |
|
87 | 87 | } |
|
88 | 88 | |
|
89 | 89 | /*! |
|
90 | 90 | Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects. |
|
91 | 91 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and |
|
92 | 92 | the y axis). |
|
93 | 93 | */ |
|
94 | 94 | void QChart::addSeries(QSeries* series, QChartAxis* axisY) |
|
95 | 95 | { |
|
96 | 96 | d_ptr->m_dataset->addSeries(series, axisY); |
|
97 | 97 | } |
|
98 | 98 | |
|
99 | 99 | /*! |
|
100 | 100 | Removes the \a series specified in a perameter from the QChartView. |
|
101 | 101 | It releses its ownership of the specified QChartSeries object. |
|
102 | 102 | It does not delete the pointed QChartSeries data object |
|
103 | 103 | \sa addSeries(), removeAllSeries() |
|
104 | 104 | */ |
|
105 | 105 | void QChart::removeSeries(QSeries* series) |
|
106 | 106 | { |
|
107 | 107 | d_ptr->m_dataset->removeSeries(series); |
|
108 | 108 | } |
|
109 | 109 | |
|
110 | 110 | /*! |
|
111 | 111 | Removes all the QChartSeries that have been added to the QChartView |
|
112 | 112 | It also deletes the pointed QChartSeries data objects |
|
113 | 113 | \sa addSeries(), removeSeries() |
|
114 | 114 | */ |
|
115 | 115 | void QChart::removeAllSeries() |
|
116 | 116 | { |
|
117 | 117 | d_ptr->m_dataset->removeAllSeries(); |
|
118 | 118 | } |
|
119 | 119 | |
|
120 | 120 | /*! |
|
121 | 121 | Sets the \a brush that is used for painting the background of the chart area. |
|
122 | 122 | */ |
|
123 | 123 | void QChart::setBackgroundBrush(const QBrush& brush) |
|
124 | 124 | { |
|
125 | //TODO: refactor me | |
|
125 | 126 | d_ptr->m_presenter->createChartBackgroundItem(); |
|
126 | 127 | d_ptr->m_presenter->m_backgroundItem->setBrush(brush); |
|
127 | 128 | d_ptr->m_presenter->m_backgroundItem->update(); |
|
128 | 129 | } |
|
129 | 130 | |
|
130 | 131 | QBrush QChart::backgroundBrush() const |
|
131 | 132 | { |
|
133 | //TODO: refactor me | |
|
132 | 134 | if (!d_ptr->m_presenter->m_backgroundItem) return QBrush(); |
|
133 | 135 | return (d_ptr->m_presenter->m_backgroundItem)->brush(); |
|
134 | 136 | } |
|
135 | 137 | |
|
136 | 138 | /*! |
|
137 | 139 | Sets the \a pen that is used for painting the background of the chart area. |
|
138 | 140 | */ |
|
139 | 141 | void QChart::setBackgroundPen(const QPen& pen) |
|
140 | 142 | { |
|
143 | //TODO: refactor me | |
|
141 | 144 | d_ptr->m_presenter->createChartBackgroundItem(); |
|
142 | 145 | d_ptr->m_presenter->m_backgroundItem->setPen(pen); |
|
143 | 146 | d_ptr->m_presenter->m_backgroundItem->update(); |
|
144 | 147 | } |
|
145 | 148 | |
|
146 | 149 | QPen QChart::backgroundPen() const |
|
147 | 150 | { |
|
151 | //TODO: refactor me | |
|
148 | 152 | if (!d_ptr->m_presenter->m_backgroundItem) return QPen(); |
|
149 | 153 | return d_ptr->m_presenter->m_backgroundItem->pen(); |
|
150 | 154 | } |
|
151 | 155 | |
|
152 | 156 | /*! |
|
153 | 157 | Sets the chart \a title. The description text that is drawn above the chart. |
|
154 | 158 | */ |
|
155 | 159 | void QChart::setTitle(const QString& title) |
|
156 | 160 | { |
|
161 | //TODO: refactor me | |
|
157 | 162 | d_ptr->m_presenter->createChartTitleItem(); |
|
158 | 163 | d_ptr->m_presenter->m_titleItem->setText(title); |
|
159 | 164 | d_ptr->m_presenter->updateLayout(); |
|
160 | 165 | } |
|
161 | 166 | |
|
162 | 167 | /*! |
|
163 | 168 | Returns the chart title. The description text that is drawn above the chart. |
|
164 | 169 | */ |
|
165 | 170 | QString QChart::title() const |
|
166 | 171 | { |
|
172 | //TODO: refactor me | |
|
167 | 173 | if (d_ptr->m_presenter->m_titleItem) |
|
168 | 174 | return d_ptr->m_presenter->m_titleItem->text(); |
|
169 | 175 | else |
|
170 | 176 | return QString(); |
|
171 | 177 | } |
|
172 | 178 | |
|
173 | 179 | /*! |
|
174 | 180 | Sets the \a font that is used for rendering the description text that is rendered above the chart. |
|
175 | 181 | */ |
|
176 | 182 | void QChart::setTitleFont(const QFont& font) |
|
177 | 183 | { |
|
184 | //TODO: refactor me | |
|
178 | 185 | d_ptr->m_presenter->createChartTitleItem(); |
|
179 | 186 | d_ptr->m_presenter->m_titleItem->setFont(font); |
|
180 | 187 | d_ptr->m_presenter->updateLayout(); |
|
181 | 188 | } |
|
182 | 189 | |
|
183 | 190 | /*! |
|
184 | 191 | Sets the \a brush used for rendering the title text. |
|
185 | 192 | */ |
|
186 | 193 | void QChart::setTitleBrush(const QBrush &brush) |
|
187 | 194 | { |
|
195 | //TODO: refactor me | |
|
188 | 196 | d_ptr->m_presenter->createChartTitleItem(); |
|
189 | 197 | d_ptr->m_presenter->m_titleItem->setBrush(brush); |
|
190 | 198 | d_ptr->m_presenter->updateLayout(); |
|
191 | 199 | } |
|
192 | 200 | |
|
193 | 201 | /*! |
|
194 | 202 | Returns the brush used for rendering the title text. |
|
195 | 203 | */ |
|
196 | 204 | QBrush QChart::titleBrush() const |
|
197 | 205 | { |
|
206 | //TODO: refactor me | |
|
198 | 207 | if (!d_ptr->m_presenter->m_titleItem) return QBrush(); |
|
199 | 208 | return d_ptr->m_presenter->m_titleItem->brush(); |
|
200 | 209 | } |
|
201 | 210 | |
|
202 | 211 | /*! |
|
203 | 212 | Sets the \a theme used by the chart for rendering the graphical representation of the data |
|
204 | 213 | \sa ChartTheme, chartTheme() |
|
205 | 214 | */ |
|
206 | 215 | void QChart::setTheme(QChart::ChartTheme theme) |
|
207 | 216 | { |
|
208 | 217 | d_ptr->m_presenter->setTheme(theme); |
|
209 | 218 | } |
|
210 | 219 | |
|
211 | 220 | /*! |
|
212 | 221 | Returns the theme enum used by the chart. |
|
213 | 222 | \sa ChartTheme, setChartTheme() |
|
214 | 223 | */ |
|
215 | 224 | QChart::ChartTheme QChart::theme() const |
|
216 | 225 | { |
|
217 | 226 | return d_ptr->m_presenter->theme(); |
|
218 | 227 | } |
|
219 | 228 | |
|
220 | 229 | /*! |
|
221 | 230 | Zooms in the view by a factor of 2 |
|
222 | 231 | */ |
|
223 | 232 | void QChart::zoomIn() |
|
224 | 233 | { |
|
225 | 234 | d_ptr->m_presenter->zoomIn(); |
|
226 | 235 | } |
|
227 | 236 | |
|
228 | 237 | /*! |
|
229 | 238 | Zooms in the view to a maximum level at which \a rect is still fully visible. |
|
230 | 239 | */ |
|
231 | 240 | void QChart::zoomIn(const QRectF& rect) |
|
232 | 241 | { |
|
233 | 242 | if (!rect.isValid()) return; |
|
234 | 243 | d_ptr->m_presenter->zoomIn(rect); |
|
235 | 244 | } |
|
236 | 245 | |
|
237 | 246 | /*! |
|
238 | 247 | Restores the view zoom level to the previous one. |
|
239 | 248 | */ |
|
240 | 249 | void QChart::zoomOut() |
|
241 | 250 | { |
|
242 | 251 | d_ptr->m_presenter->zoomOut(); |
|
243 | 252 | } |
|
244 | 253 | |
|
245 | 254 | /*! |
|
246 | 255 | Returns the pointer to the x axis object of the chart |
|
247 | 256 | */ |
|
248 | 257 | QChartAxis* QChart::axisX() const |
|
249 | 258 | { |
|
250 | 259 | return d_ptr->m_dataset->axisX(); |
|
251 | 260 | } |
|
252 | 261 | |
|
253 | 262 | /*! |
|
254 | 263 | Returns the pointer to the y axis object of the chart |
|
255 | 264 | */ |
|
256 | 265 | QChartAxis* QChart::axisY() const |
|
257 | 266 | { |
|
258 | 267 | return d_ptr->m_dataset->axisY(); |
|
259 | 268 | } |
|
260 | 269 | |
|
261 | 270 | /*! |
|
262 | 271 | Returns the legend object of the chart. Ownership stays in chart. |
|
263 | 272 | */ |
|
264 | 273 | QLegend* QChart::legend() const |
|
265 | 274 | { |
|
266 | 275 | return d_ptr->m_legend; |
|
267 | 276 | } |
|
268 | 277 | |
|
269 | 278 | QRect QChart::margins() const |
|
270 | 279 | { |
|
271 | 280 | return d_ptr->m_presenter->margins(); |
|
272 | 281 | } |
|
273 | 282 | |
|
274 | 283 | |
|
275 | 284 | /*! |
|
276 | 285 | Resizes and updates the chart area using the \a event data |
|
277 | 286 | */ |
|
278 | 287 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) |
|
279 | 288 | { |
|
280 | 289 | d_ptr->m_rect = QRectF(QPoint(0,0),event->newSize()); |
|
281 | 290 | QGraphicsWidget::resizeEvent(event); |
|
282 | 291 | d_ptr->m_presenter->setGeometry(d_ptr->m_rect); |
|
283 | 292 | } |
|
284 | 293 | |
|
285 | 294 | /*! |
|
286 | 295 | Sets animation \a options for the chart |
|
287 | 296 | */ |
|
288 | 297 | void QChart::setAnimationOptions(AnimationOptions options) |
|
289 | 298 | { |
|
290 | 299 | d_ptr->m_presenter->setAnimationOptions(options); |
|
291 | 300 | } |
|
292 | 301 | |
|
293 | 302 | /*! |
|
294 | 303 | Returns animation options for the chart |
|
295 | 304 | */ |
|
296 | 305 | QChart::AnimationOptions QChart::animationOptions() const |
|
297 | 306 | { |
|
298 | 307 | return d_ptr->m_presenter->animationOptions(); |
|
299 | 308 | } |
|
300 | 309 | |
|
301 | 310 | void QChart::scrollLeft() |
|
302 | 311 | { |
|
303 | 312 | d_ptr->m_presenter->scroll(-d_ptr->m_presenter->chartGeometry().width()/(axisX()->ticksCount()-1),0); |
|
304 | 313 | } |
|
305 | 314 | |
|
306 | 315 | void QChart::scrollRight() |
|
307 | 316 | { |
|
308 | 317 | d_ptr->m_presenter->scroll(d_ptr->m_presenter->chartGeometry().width()/(axisX()->ticksCount()-1),0); |
|
309 | 318 | } |
|
310 | 319 | |
|
311 | 320 | void QChart::scrollUp() |
|
312 | 321 | { |
|
313 | 322 | d_ptr->m_presenter->scroll(0,d_ptr->m_presenter->chartGeometry().width()/(axisY()->ticksCount()-1)); |
|
314 | 323 | } |
|
315 | 324 | |
|
316 | 325 | void QChart::scrollDown() |
|
317 | 326 | { |
|
318 | 327 | d_ptr->m_presenter->scroll(0,-d_ptr->m_presenter->chartGeometry().width()/(axisY()->ticksCount()-1)); |
|
319 | 328 | } |
|
320 | 329 | |
|
321 | 330 | void QChart::setBackgroundVisible(bool visible) |
|
322 | 331 | { |
|
332 | //TODO: refactor me | |
|
323 | 333 | d_ptr->m_presenter->createChartBackgroundItem(); |
|
324 | 334 | d_ptr->m_presenter->m_backgroundItem->setVisible(visible); |
|
325 | 335 | } |
|
326 | 336 | |
|
327 | 337 | bool QChart::isBackgroundVisible() const |
|
328 | 338 | { |
|
339 | //TODO: refactor me | |
|
329 | 340 | if (!d_ptr->m_presenter->m_backgroundItem) return false; |
|
330 | 341 | return d_ptr->m_presenter->m_backgroundItem->isVisible(); |
|
331 | 342 | } |
|
332 | 343 | |
|
333 | 344 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
334 | 345 | |
|
335 | 346 | QChartPrivate::QChartPrivate(): |
|
336 | 347 | m_legend(0), |
|
337 | 348 | m_dataset(0), |
|
338 | 349 | m_presenter(0) |
|
339 | 350 | { |
|
340 | 351 | |
|
341 | 352 | } |
|
342 | 353 | |
|
343 | 354 | QChartPrivate::~QChartPrivate() |
|
344 | 355 | { |
|
345 | 356 | |
|
346 | 357 | } |
|
347 | 358 | |
|
348 | 359 | void QChartPrivate::createConnections() |
|
349 | 360 | { |
|
350 | 361 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*))); |
|
351 | 362 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_legend,SLOT(handleSeriesRemoved(QSeries*))); |
|
352 | 363 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),m_presenter,SLOT(handleSeriesAdded(QSeries*,Domain*))); |
|
353 | 364 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),m_presenter,SLOT(handleSeriesRemoved(QSeries*))); |
|
354 | 365 | QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*,Domain*)),m_presenter,SLOT(handleAxisAdded(QChartAxis*,Domain*))); |
|
355 | 366 | QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),m_presenter,SLOT(handleAxisRemoved(QChartAxis*))); |
|
356 | 367 | } |
|
357 | 368 | |
|
358 | 369 | #include "moc_qchart.cpp" |
|
359 | 370 | |
|
360 | 371 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now