##// END OF EJS Templates
Added plotAreaChanged signal to chart....
Miikka Heikkinen -
r2716:bf30bed1cefb
parent child
Show More
@@ -1,508 +1,509
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2014 Digia Plc
3 ** Copyright (C) 2014 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 Enterprise Charts Add-on.
7 ** This file is part of the Qt Enterprise Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
11 ** accordance with the Qt Enterprise License Agreement provided with the
11 ** accordance with the Qt Enterprise 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 #include <private/chartpresenter_p.h>
20 #include <private/chartpresenter_p.h>
21 #include <QtCharts/QChart>
21 #include <QtCharts/QChart>
22 #include <private/chartitem_p.h>
22 #include <private/chartitem_p.h>
23 #include <private/qchart_p.h>
23 #include <private/qchart_p.h>
24 #include <QtCharts/QAbstractAxis>
24 #include <QtCharts/QAbstractAxis>
25 #include <private/qabstractaxis_p.h>
25 #include <private/qabstractaxis_p.h>
26 #include <private/chartdataset_p.h>
26 #include <private/chartdataset_p.h>
27 #include <private/chartanimation_p.h>
27 #include <private/chartanimation_p.h>
28 #include <private/qabstractseries_p.h>
28 #include <private/qabstractseries_p.h>
29 #include <QtCharts/QAreaSeries>
29 #include <QtCharts/QAreaSeries>
30 #include <private/chartaxiselement_p.h>
30 #include <private/chartaxiselement_p.h>
31 #include <private/chartbackground_p.h>
31 #include <private/chartbackground_p.h>
32 #include <private/cartesianchartlayout_p.h>
32 #include <private/cartesianchartlayout_p.h>
33 #include <private/polarchartlayout_p.h>
33 #include <private/polarchartlayout_p.h>
34 #include <private/charttitle_p.h>
34 #include <private/charttitle_p.h>
35 #include <QtCore/QTimer>
35 #include <QtCore/QTimer>
36 #include <QtGui/QTextDocument>
36 #include <QtGui/QTextDocument>
37
37
38 QT_CHARTS_BEGIN_NAMESPACE
38 QT_CHARTS_BEGIN_NAMESPACE
39
39
40 ChartPresenter::ChartPresenter(QChart *chart, QChart::ChartType type)
40 ChartPresenter::ChartPresenter(QChart *chart, QChart::ChartType type)
41 : QObject(chart),
41 : QObject(chart),
42 m_chart(chart),
42 m_chart(chart),
43 m_options(QChart::NoAnimation),
43 m_options(QChart::NoAnimation),
44 m_state(ShowState),
44 m_state(ShowState),
45 m_background(0),
45 m_background(0),
46 m_plotAreaBackground(0),
46 m_plotAreaBackground(0),
47 m_title(0),
47 m_title(0),
48 m_localizeNumbers(false)
48 m_localizeNumbers(false)
49 {
49 {
50 if (type == QChart::ChartTypeCartesian)
50 if (type == QChart::ChartTypeCartesian)
51 m_layout = new CartesianChartLayout(this);
51 m_layout = new CartesianChartLayout(this);
52 else if (type == QChart::ChartTypePolar)
52 else if (type == QChart::ChartTypePolar)
53 m_layout = new PolarChartLayout(this);
53 m_layout = new PolarChartLayout(this);
54 Q_ASSERT(m_layout);
54 Q_ASSERT(m_layout);
55 }
55 }
56
56
57 ChartPresenter::~ChartPresenter()
57 ChartPresenter::~ChartPresenter()
58 {
58 {
59
59
60 }
60 }
61
61
62 void ChartPresenter::setGeometry(const QRectF rect)
62 void ChartPresenter::setGeometry(const QRectF rect)
63 {
63 {
64 if (m_rect != rect) {
64 if (m_rect != rect) {
65 m_rect = rect;
65 m_rect = rect;
66 foreach (ChartItem *chart, m_chartItems) {
66 foreach (ChartItem *chart, m_chartItems) {
67 chart->domain()->setSize(rect.size());
67 chart->domain()->setSize(rect.size());
68 chart->setPos(rect.topLeft());
68 chart->setPos(rect.topLeft());
69 }
69 }
70 emit plotAreaChanged(m_rect);
70 }
71 }
71 }
72 }
72
73
73 QRectF ChartPresenter::geometry() const
74 QRectF ChartPresenter::geometry() const
74 {
75 {
75 return m_rect;
76 return m_rect;
76 }
77 }
77
78
78 void ChartPresenter::handleAxisAdded(QAbstractAxis *axis)
79 void ChartPresenter::handleAxisAdded(QAbstractAxis *axis)
79 {
80 {
80 axis->d_ptr->initializeGraphics(rootItem());
81 axis->d_ptr->initializeGraphics(rootItem());
81 axis->d_ptr->initializeAnimations(m_options);
82 axis->d_ptr->initializeAnimations(m_options);
82 ChartAxisElement *item = axis->d_ptr->axisItem();
83 ChartAxisElement *item = axis->d_ptr->axisItem();
83 item->setPresenter(this);
84 item->setPresenter(this);
84 item->setThemeManager(m_chart->d_ptr->m_themeManager);
85 item->setThemeManager(m_chart->d_ptr->m_themeManager);
85 m_axisItems<<item;
86 m_axisItems<<item;
86 m_axes<<axis;
87 m_axes<<axis;
87 m_layout->invalidate();
88 m_layout->invalidate();
88 }
89 }
89
90
90 void ChartPresenter::handleAxisRemoved(QAbstractAxis *axis)
91 void ChartPresenter::handleAxisRemoved(QAbstractAxis *axis)
91 {
92 {
92 ChartAxisElement *item = axis->d_ptr->m_item.take();
93 ChartAxisElement *item = axis->d_ptr->m_item.take();
93 item->hide();
94 item->hide();
94 item->disconnect();
95 item->disconnect();
95 item->deleteLater();
96 item->deleteLater();
96 m_axisItems.removeAll(item);
97 m_axisItems.removeAll(item);
97 m_axes.removeAll(axis);
98 m_axes.removeAll(axis);
98 m_layout->invalidate();
99 m_layout->invalidate();
99 }
100 }
100
101
101
102
102 void ChartPresenter::handleSeriesAdded(QAbstractSeries *series)
103 void ChartPresenter::handleSeriesAdded(QAbstractSeries *series)
103 {
104 {
104 series->d_ptr->initializeGraphics(rootItem());
105 series->d_ptr->initializeGraphics(rootItem());
105 series->d_ptr->initializeAnimations(m_options);
106 series->d_ptr->initializeAnimations(m_options);
106 series->d_ptr->setPresenter(this);
107 series->d_ptr->setPresenter(this);
107 ChartItem *chart = series->d_ptr->chartItem();
108 ChartItem *chart = series->d_ptr->chartItem();
108 chart->setPresenter(this);
109 chart->setPresenter(this);
109 chart->setThemeManager(m_chart->d_ptr->m_themeManager);
110 chart->setThemeManager(m_chart->d_ptr->m_themeManager);
110 chart->domain()->setSize(m_rect.size());
111 chart->domain()->setSize(m_rect.size());
111 chart->setPos(m_rect.topLeft());
112 chart->setPos(m_rect.topLeft());
112 chart->handleDomainUpdated(); //this could be moved to intializeGraphics when animator is refactored
113 chart->handleDomainUpdated(); //this could be moved to intializeGraphics when animator is refactored
113 m_chartItems<<chart;
114 m_chartItems<<chart;
114 m_series<<series;
115 m_series<<series;
115 m_layout->invalidate();
116 m_layout->invalidate();
116 }
117 }
117
118
118 void ChartPresenter::handleSeriesRemoved(QAbstractSeries *series)
119 void ChartPresenter::handleSeriesRemoved(QAbstractSeries *series)
119 {
120 {
120 ChartItem *chart = series->d_ptr->m_item.take();
121 ChartItem *chart = series->d_ptr->m_item.take();
121 chart->hide();
122 chart->hide();
122 chart->disconnect();
123 chart->disconnect();
123 chart->deleteLater();
124 chart->deleteLater();
124 m_chartItems.removeAll(chart);
125 m_chartItems.removeAll(chart);
125 m_series.removeAll(series);
126 m_series.removeAll(series);
126 m_layout->invalidate();
127 m_layout->invalidate();
127 }
128 }
128
129
129 void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options)
130 void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options)
130 {
131 {
131 if (m_options != options) {
132 if (m_options != options) {
132 QChart::AnimationOptions oldOptions = m_options;
133 QChart::AnimationOptions oldOptions = m_options;
133 m_options = options;
134 m_options = options;
134 if (options.testFlag(QChart::SeriesAnimations) != oldOptions.testFlag(QChart::SeriesAnimations)) {
135 if (options.testFlag(QChart::SeriesAnimations) != oldOptions.testFlag(QChart::SeriesAnimations)) {
135 foreach (QAbstractSeries *series, m_series)
136 foreach (QAbstractSeries *series, m_series)
136 series->d_ptr->initializeAnimations(m_options);
137 series->d_ptr->initializeAnimations(m_options);
137 }
138 }
138 if (options.testFlag(QChart::GridAxisAnimations) != oldOptions.testFlag(QChart::GridAxisAnimations)) {
139 if (options.testFlag(QChart::GridAxisAnimations) != oldOptions.testFlag(QChart::GridAxisAnimations)) {
139 foreach (QAbstractAxis *axis, m_axes)
140 foreach (QAbstractAxis *axis, m_axes)
140 axis->d_ptr->initializeAnimations(m_options);
141 axis->d_ptr->initializeAnimations(m_options);
141 }
142 }
142 m_layout->invalidate(); // So that existing animations don't just stop halfway
143 m_layout->invalidate(); // So that existing animations don't just stop halfway
143 }
144 }
144 }
145 }
145
146
146 void ChartPresenter::setState(State state,QPointF point)
147 void ChartPresenter::setState(State state,QPointF point)
147 {
148 {
148 m_state=state;
149 m_state=state;
149 m_statePoint=point;
150 m_statePoint=point;
150 }
151 }
151
152
152 QChart::AnimationOptions ChartPresenter::animationOptions() const
153 QChart::AnimationOptions ChartPresenter::animationOptions() const
153 {
154 {
154 return m_options;
155 return m_options;
155 }
156 }
156
157
157 void ChartPresenter::createBackgroundItem()
158 void ChartPresenter::createBackgroundItem()
158 {
159 {
159 if (!m_background) {
160 if (!m_background) {
160 m_background = new ChartBackground(rootItem());
161 m_background = new ChartBackground(rootItem());
161 m_background->setPen(Qt::NoPen); // Theme doesn't touch pen so don't use default
162 m_background->setPen(Qt::NoPen); // Theme doesn't touch pen so don't use default
162 m_background->setBrush(QChartPrivate::defaultBrush());
163 m_background->setBrush(QChartPrivate::defaultBrush());
163 m_background->setZValue(ChartPresenter::BackgroundZValue);
164 m_background->setZValue(ChartPresenter::BackgroundZValue);
164 }
165 }
165 }
166 }
166
167
167 void ChartPresenter::createPlotAreaBackgroundItem()
168 void ChartPresenter::createPlotAreaBackgroundItem()
168 {
169 {
169 if (!m_plotAreaBackground) {
170 if (!m_plotAreaBackground) {
170 if (m_chart->chartType() == QChart::ChartTypeCartesian)
171 if (m_chart->chartType() == QChart::ChartTypeCartesian)
171 m_plotAreaBackground = new QGraphicsRectItem(rootItem());
172 m_plotAreaBackground = new QGraphicsRectItem(rootItem());
172 else
173 else
173 m_plotAreaBackground = new QGraphicsEllipseItem(rootItem());
174 m_plotAreaBackground = new QGraphicsEllipseItem(rootItem());
174 // Use transparent pen instead of Qt::NoPen, as Qt::NoPen causes
175 // Use transparent pen instead of Qt::NoPen, as Qt::NoPen causes
175 // antialising artifacts with axis lines for some reason.
176 // antialising artifacts with axis lines for some reason.
176 m_plotAreaBackground->setPen(QPen(Qt::transparent));
177 m_plotAreaBackground->setPen(QPen(Qt::transparent));
177 m_plotAreaBackground->setBrush(Qt::NoBrush);
178 m_plotAreaBackground->setBrush(Qt::NoBrush);
178 m_plotAreaBackground->setZValue(ChartPresenter::PlotAreaZValue);
179 m_plotAreaBackground->setZValue(ChartPresenter::PlotAreaZValue);
179 m_plotAreaBackground->setVisible(false);
180 m_plotAreaBackground->setVisible(false);
180 }
181 }
181 }
182 }
182
183
183 void ChartPresenter::createTitleItem()
184 void ChartPresenter::createTitleItem()
184 {
185 {
185 if (!m_title) {
186 if (!m_title) {
186 m_title = new ChartTitle(rootItem());
187 m_title = new ChartTitle(rootItem());
187 m_title->setZValue(ChartPresenter::BackgroundZValue);
188 m_title->setZValue(ChartPresenter::BackgroundZValue);
188 }
189 }
189 }
190 }
190
191
191 void ChartPresenter::startAnimation(ChartAnimation *animation)
192 void ChartPresenter::startAnimation(ChartAnimation *animation)
192 {
193 {
193 animation->stop();
194 animation->stop();
194 QTimer::singleShot(0, animation, SLOT(startChartAnimation()));
195 QTimer::singleShot(0, animation, SLOT(startChartAnimation()));
195 }
196 }
196
197
197 void ChartPresenter::setBackgroundBrush(const QBrush &brush)
198 void ChartPresenter::setBackgroundBrush(const QBrush &brush)
198 {
199 {
199 createBackgroundItem();
200 createBackgroundItem();
200 m_background->setBrush(brush);
201 m_background->setBrush(brush);
201 m_layout->invalidate();
202 m_layout->invalidate();
202 }
203 }
203
204
204 QBrush ChartPresenter::backgroundBrush() const
205 QBrush ChartPresenter::backgroundBrush() const
205 {
206 {
206 if (!m_background)
207 if (!m_background)
207 return QBrush();
208 return QBrush();
208 return m_background->brush();
209 return m_background->brush();
209 }
210 }
210
211
211 void ChartPresenter::setBackgroundPen(const QPen &pen)
212 void ChartPresenter::setBackgroundPen(const QPen &pen)
212 {
213 {
213 createBackgroundItem();
214 createBackgroundItem();
214 m_background->setPen(pen);
215 m_background->setPen(pen);
215 m_layout->invalidate();
216 m_layout->invalidate();
216 }
217 }
217
218
218 QPen ChartPresenter::backgroundPen() const
219 QPen ChartPresenter::backgroundPen() const
219 {
220 {
220 if (!m_background)
221 if (!m_background)
221 return QPen();
222 return QPen();
222 return m_background->pen();
223 return m_background->pen();
223 }
224 }
224
225
225 void ChartPresenter::setBackgroundRoundness(qreal diameter)
226 void ChartPresenter::setBackgroundRoundness(qreal diameter)
226 {
227 {
227 createBackgroundItem();
228 createBackgroundItem();
228 m_background->setDiameter(diameter);
229 m_background->setDiameter(diameter);
229 m_layout->invalidate();
230 m_layout->invalidate();
230 }
231 }
231
232
232 qreal ChartPresenter::backgroundRoundness() const
233 qreal ChartPresenter::backgroundRoundness() const
233 {
234 {
234 if (!m_background)
235 if (!m_background)
235 return 0;
236 return 0;
236 return m_background->diameter();
237 return m_background->diameter();
237 }
238 }
238
239
239 void ChartPresenter::setPlotAreaBackgroundBrush(const QBrush &brush)
240 void ChartPresenter::setPlotAreaBackgroundBrush(const QBrush &brush)
240 {
241 {
241 createPlotAreaBackgroundItem();
242 createPlotAreaBackgroundItem();
242 m_plotAreaBackground->setBrush(brush);
243 m_plotAreaBackground->setBrush(brush);
243 m_layout->invalidate();
244 m_layout->invalidate();
244 }
245 }
245
246
246 QBrush ChartPresenter::plotAreaBackgroundBrush() const
247 QBrush ChartPresenter::plotAreaBackgroundBrush() const
247 {
248 {
248 if (!m_plotAreaBackground)
249 if (!m_plotAreaBackground)
249 return QBrush();
250 return QBrush();
250 return m_plotAreaBackground->brush();
251 return m_plotAreaBackground->brush();
251 }
252 }
252
253
253 void ChartPresenter::setPlotAreaBackgroundPen(const QPen &pen)
254 void ChartPresenter::setPlotAreaBackgroundPen(const QPen &pen)
254 {
255 {
255 createPlotAreaBackgroundItem();
256 createPlotAreaBackgroundItem();
256 m_plotAreaBackground->setPen(pen);
257 m_plotAreaBackground->setPen(pen);
257 m_layout->invalidate();
258 m_layout->invalidate();
258 }
259 }
259
260
260 QPen ChartPresenter::plotAreaBackgroundPen() const
261 QPen ChartPresenter::plotAreaBackgroundPen() const
261 {
262 {
262 if (!m_plotAreaBackground)
263 if (!m_plotAreaBackground)
263 return QPen();
264 return QPen();
264 return m_plotAreaBackground->pen();
265 return m_plotAreaBackground->pen();
265 }
266 }
266
267
267 void ChartPresenter::setTitle(const QString &title)
268 void ChartPresenter::setTitle(const QString &title)
268 {
269 {
269 createTitleItem();
270 createTitleItem();
270 m_title->setText(title);
271 m_title->setText(title);
271 m_layout->invalidate();
272 m_layout->invalidate();
272 }
273 }
273
274
274 QString ChartPresenter::title() const
275 QString ChartPresenter::title() const
275 {
276 {
276 if (!m_title)
277 if (!m_title)
277 return QString();
278 return QString();
278 return m_title->text();
279 return m_title->text();
279 }
280 }
280
281
281 void ChartPresenter::setTitleFont(const QFont &font)
282 void ChartPresenter::setTitleFont(const QFont &font)
282 {
283 {
283 createTitleItem();
284 createTitleItem();
284 m_title->setFont(font);
285 m_title->setFont(font);
285 m_layout->invalidate();
286 m_layout->invalidate();
286 }
287 }
287
288
288 QFont ChartPresenter::titleFont() const
289 QFont ChartPresenter::titleFont() const
289 {
290 {
290 if (!m_title)
291 if (!m_title)
291 return QFont();
292 return QFont();
292 return m_title->font();
293 return m_title->font();
293 }
294 }
294
295
295 void ChartPresenter::setTitleBrush(const QBrush &brush)
296 void ChartPresenter::setTitleBrush(const QBrush &brush)
296 {
297 {
297 createTitleItem();
298 createTitleItem();
298 m_title->setDefaultTextColor(brush.color());
299 m_title->setDefaultTextColor(brush.color());
299 m_layout->invalidate();
300 m_layout->invalidate();
300 }
301 }
301
302
302 QBrush ChartPresenter::titleBrush() const
303 QBrush ChartPresenter::titleBrush() const
303 {
304 {
304 if (!m_title)
305 if (!m_title)
305 return QBrush();
306 return QBrush();
306 return QBrush(m_title->defaultTextColor());
307 return QBrush(m_title->defaultTextColor());
307 }
308 }
308
309
309 void ChartPresenter::setBackgroundVisible(bool visible)
310 void ChartPresenter::setBackgroundVisible(bool visible)
310 {
311 {
311 createBackgroundItem();
312 createBackgroundItem();
312 m_background->setVisible(visible);
313 m_background->setVisible(visible);
313 }
314 }
314
315
315
316
316 bool ChartPresenter::isBackgroundVisible() const
317 bool ChartPresenter::isBackgroundVisible() const
317 {
318 {
318 if (!m_background)
319 if (!m_background)
319 return false;
320 return false;
320 return m_background->isVisible();
321 return m_background->isVisible();
321 }
322 }
322
323
323 void ChartPresenter::setPlotAreaBackgroundVisible(bool visible)
324 void ChartPresenter::setPlotAreaBackgroundVisible(bool visible)
324 {
325 {
325 createPlotAreaBackgroundItem();
326 createPlotAreaBackgroundItem();
326 m_plotAreaBackground->setVisible(visible);
327 m_plotAreaBackground->setVisible(visible);
327 }
328 }
328
329
329 bool ChartPresenter::isPlotAreaBackgroundVisible() const
330 bool ChartPresenter::isPlotAreaBackgroundVisible() const
330 {
331 {
331 if (!m_plotAreaBackground)
332 if (!m_plotAreaBackground)
332 return false;
333 return false;
333 return m_plotAreaBackground->isVisible();
334 return m_plotAreaBackground->isVisible();
334 }
335 }
335
336
336 void ChartPresenter::setBackgroundDropShadowEnabled(bool enabled)
337 void ChartPresenter::setBackgroundDropShadowEnabled(bool enabled)
337 {
338 {
338 createBackgroundItem();
339 createBackgroundItem();
339 m_background->setDropShadowEnabled(enabled);
340 m_background->setDropShadowEnabled(enabled);
340 }
341 }
341
342
342 bool ChartPresenter::isBackgroundDropShadowEnabled() const
343 bool ChartPresenter::isBackgroundDropShadowEnabled() const
343 {
344 {
344 if (!m_background)
345 if (!m_background)
345 return false;
346 return false;
346 return m_background->isDropShadowEnabled();
347 return m_background->isDropShadowEnabled();
347 }
348 }
348
349
349 void ChartPresenter::setLocalizeNumbers(bool localize)
350 void ChartPresenter::setLocalizeNumbers(bool localize)
350 {
351 {
351 m_localizeNumbers = localize;
352 m_localizeNumbers = localize;
352 m_layout->invalidate();
353 m_layout->invalidate();
353 }
354 }
354
355
355 void ChartPresenter::setLocale(const QLocale &locale)
356 void ChartPresenter::setLocale(const QLocale &locale)
356 {
357 {
357 m_locale = locale;
358 m_locale = locale;
358 m_layout->invalidate();
359 m_layout->invalidate();
359 }
360 }
360
361
361 AbstractChartLayout *ChartPresenter::layout()
362 AbstractChartLayout *ChartPresenter::layout()
362 {
363 {
363 return m_layout;
364 return m_layout;
364 }
365 }
365
366
366 QLegend *ChartPresenter::legend()
367 QLegend *ChartPresenter::legend()
367 {
368 {
368 return m_chart->legend();
369 return m_chart->legend();
369 }
370 }
370
371
371 void ChartPresenter::setVisible(bool visible)
372 void ChartPresenter::setVisible(bool visible)
372 {
373 {
373 m_chart->setVisible(visible);
374 m_chart->setVisible(visible);
374 }
375 }
375
376
376 ChartBackground *ChartPresenter::backgroundElement()
377 ChartBackground *ChartPresenter::backgroundElement()
377 {
378 {
378 return m_background;
379 return m_background;
379 }
380 }
380
381
381 QAbstractGraphicsShapeItem *ChartPresenter::plotAreaElement()
382 QAbstractGraphicsShapeItem *ChartPresenter::plotAreaElement()
382 {
383 {
383 return m_plotAreaBackground;
384 return m_plotAreaBackground;
384 }
385 }
385
386
386 QList<ChartAxisElement *> ChartPresenter::axisItems() const
387 QList<ChartAxisElement *> ChartPresenter::axisItems() const
387 {
388 {
388 return m_axisItems;
389 return m_axisItems;
389 }
390 }
390
391
391 QList<ChartItem *> ChartPresenter::chartItems() const
392 QList<ChartItem *> ChartPresenter::chartItems() const
392 {
393 {
393 return m_chartItems;
394 return m_chartItems;
394 }
395 }
395
396
396 ChartTitle *ChartPresenter::titleElement()
397 ChartTitle *ChartPresenter::titleElement()
397 {
398 {
398 return m_title;
399 return m_title;
399 }
400 }
400
401
401 QRectF ChartPresenter::textBoundingRect(const QFont &font, const QString &text, qreal angle)
402 QRectF ChartPresenter::textBoundingRect(const QFont &font, const QString &text, qreal angle)
402 {
403 {
403 static QGraphicsTextItem dummyTextItem;
404 static QGraphicsTextItem dummyTextItem;
404 static bool initMargin = true;
405 static bool initMargin = true;
405 if (initMargin) {
406 if (initMargin) {
406 dummyTextItem.document()->setDocumentMargin(textMargin());
407 dummyTextItem.document()->setDocumentMargin(textMargin());
407 initMargin = false;
408 initMargin = false;
408 }
409 }
409
410
410 dummyTextItem.setFont(font);
411 dummyTextItem.setFont(font);
411 dummyTextItem.setHtml(text);
412 dummyTextItem.setHtml(text);
412 QRectF boundingRect = dummyTextItem.boundingRect();
413 QRectF boundingRect = dummyTextItem.boundingRect();
413
414
414 // Take rotation into account
415 // Take rotation into account
415 if (angle) {
416 if (angle) {
416 QTransform transform;
417 QTransform transform;
417 transform.rotate(angle);
418 transform.rotate(angle);
418 boundingRect = transform.mapRect(boundingRect);
419 boundingRect = transform.mapRect(boundingRect);
419 }
420 }
420
421
421 return boundingRect;
422 return boundingRect;
422 }
423 }
423
424
424 // boundingRect parameter returns the rotated bounding rect of the text
425 // boundingRect parameter returns the rotated bounding rect of the text
425 QString ChartPresenter::truncatedText(const QFont &font, const QString &text, qreal angle,
426 QString ChartPresenter::truncatedText(const QFont &font, const QString &text, qreal angle,
426 qreal maxWidth, qreal maxHeight, QRectF &boundingRect)
427 qreal maxWidth, qreal maxHeight, QRectF &boundingRect)
427 {
428 {
428 QString truncatedString(text);
429 QString truncatedString(text);
429 boundingRect = textBoundingRect(font, truncatedString, angle);
430 boundingRect = textBoundingRect(font, truncatedString, angle);
430 if (boundingRect.width() > maxWidth || boundingRect.height() > maxHeight) {
431 if (boundingRect.width() > maxWidth || boundingRect.height() > maxHeight) {
431 // It can be assumed that almost any amount of string manipulation is faster
432 // It can be assumed that almost any amount of string manipulation is faster
432 // than calculating one bounding rectangle, so first prepare a list of truncated strings
433 // than calculating one bounding rectangle, so first prepare a list of truncated strings
433 // to try.
434 // to try.
434 static QRegExp truncateMatcher(QStringLiteral("&#?[0-9a-zA-Z]*;$"));
435 static QRegExp truncateMatcher(QStringLiteral("&#?[0-9a-zA-Z]*;$"));
435
436
436 QVector<QString> testStrings(text.length());
437 QVector<QString> testStrings(text.length());
437 int count(0);
438 int count(0);
438 static QLatin1Char closeTag('>');
439 static QLatin1Char closeTag('>');
439 static QLatin1Char openTag('<');
440 static QLatin1Char openTag('<');
440 static QLatin1Char semiColon(';');
441 static QLatin1Char semiColon(';');
441 static QLatin1String ellipsis("...");
442 static QLatin1String ellipsis("...");
442 while (truncatedString.length() > 1) {
443 while (truncatedString.length() > 1) {
443 int chopIndex(-1);
444 int chopIndex(-1);
444 int chopCount(1);
445 int chopCount(1);
445 QChar lastChar(truncatedString.at(truncatedString.length() - 1));
446 QChar lastChar(truncatedString.at(truncatedString.length() - 1));
446
447
447 if (lastChar == closeTag)
448 if (lastChar == closeTag)
448 chopIndex = truncatedString.lastIndexOf(openTag);
449 chopIndex = truncatedString.lastIndexOf(openTag);
449 else if (lastChar == semiColon)
450 else if (lastChar == semiColon)
450 chopIndex = truncateMatcher.indexIn(truncatedString, 0);
451 chopIndex = truncateMatcher.indexIn(truncatedString, 0);
451
452
452 if (chopIndex != -1)
453 if (chopIndex != -1)
453 chopCount = truncatedString.length() - chopIndex;
454 chopCount = truncatedString.length() - chopIndex;
454 truncatedString.chop(chopCount);
455 truncatedString.chop(chopCount);
455 testStrings[count] = truncatedString + ellipsis;
456 testStrings[count] = truncatedString + ellipsis;
456 count++;
457 count++;
457 }
458 }
458
459
459 // Binary search for best fit
460 // Binary search for best fit
460 int minIndex(0);
461 int minIndex(0);
461 int maxIndex(count - 1);
462 int maxIndex(count - 1);
462 int bestIndex(count);
463 int bestIndex(count);
463 QRectF checkRect;
464 QRectF checkRect;
464
465
465 while (maxIndex >= minIndex) {
466 while (maxIndex >= minIndex) {
466 int mid = (maxIndex + minIndex) / 2;
467 int mid = (maxIndex + minIndex) / 2;
467 checkRect = textBoundingRect(font, testStrings.at(mid), angle);
468 checkRect = textBoundingRect(font, testStrings.at(mid), angle);
468 if (checkRect.width() > maxWidth || checkRect.height() > maxHeight) {
469 if (checkRect.width() > maxWidth || checkRect.height() > maxHeight) {
469 // Checked index too large, all under this are also too large
470 // Checked index too large, all under this are also too large
470 minIndex = mid + 1;
471 minIndex = mid + 1;
471 } else {
472 } else {
472 // Checked index fits, all over this also fit
473 // Checked index fits, all over this also fit
473 maxIndex = mid - 1;
474 maxIndex = mid - 1;
474 bestIndex = mid;
475 bestIndex = mid;
475 boundingRect = checkRect;
476 boundingRect = checkRect;
476 }
477 }
477 }
478 }
478 // Default to "..." if nothing fits
479 // Default to "..." if nothing fits
479 if (bestIndex == count) {
480 if (bestIndex == count) {
480 boundingRect = textBoundingRect(font, ellipsis, angle);
481 boundingRect = textBoundingRect(font, ellipsis, angle);
481 truncatedString = ellipsis;
482 truncatedString = ellipsis;
482 } else {
483 } else {
483 truncatedString = testStrings.at(bestIndex);
484 truncatedString = testStrings.at(bestIndex);
484 }
485 }
485 }
486 }
486
487
487 return truncatedString;
488 return truncatedString;
488 }
489 }
489
490
490 QString ChartPresenter::numberToString(double value, char f, int prec)
491 QString ChartPresenter::numberToString(double value, char f, int prec)
491 {
492 {
492 if (m_localizeNumbers)
493 if (m_localizeNumbers)
493 return m_locale.toString(value, f, prec);
494 return m_locale.toString(value, f, prec);
494 else
495 else
495 return QString::number(value, f, prec);
496 return QString::number(value, f, prec);
496 }
497 }
497
498
498 QString ChartPresenter::numberToString(int value)
499 QString ChartPresenter::numberToString(int value)
499 {
500 {
500 if (m_localizeNumbers)
501 if (m_localizeNumbers)
501 return m_locale.toString(value);
502 return m_locale.toString(value);
502 else
503 else
503 return QString::number(value);
504 return QString::number(value);
504 }
505 }
505
506
506 #include "moc_chartpresenter_p.cpp"
507 #include "moc_chartpresenter_p.cpp"
507
508
508 QT_CHARTS_END_NAMESPACE
509 QT_CHARTS_END_NAMESPACE
@@ -1,192 +1,195
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2014 Digia Plc
3 ** Copyright (C) 2014 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 Enterprise Charts Add-on.
7 ** This file is part of the Qt Enterprise Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
11 ** accordance with the Qt Enterprise License Agreement provided with the
11 ** accordance with the Qt Enterprise 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 Qt Enterprise Chart API. It exists purely as an
24 // This file is not part of the Qt Enterprise 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 CHARTPRESENTER_H
30 #ifndef CHARTPRESENTER_H
31 #define CHARTPRESENTER_H
31 #define CHARTPRESENTER_H
32
32
33 #include <QtCharts/QChartGlobal>
33 #include <QtCharts/QChartGlobal>
34 #include <QtCharts/QChart> //because of QChart::ChartThemeId
34 #include <QtCharts/QChart> //because of QChart::ChartThemeId
35 #include <QtCore/QRectF>
35 #include <QtCore/QRectF>
36 #include <QtCore/QMargins>
36 #include <QtCore/QMargins>
37 #include <QtCore/QLocale>
37 #include <QtCore/QLocale>
38
38
39 QT_CHARTS_BEGIN_NAMESPACE
39 QT_CHARTS_BEGIN_NAMESPACE
40
40
41 class ChartItem;
41 class ChartItem;
42 class AxisItem;
42 class AxisItem;
43 class QAbstractSeries;
43 class QAbstractSeries;
44 class ChartDataSet;
44 class ChartDataSet;
45 class AbstractDomain;
45 class AbstractDomain;
46 class ChartAxisElement;
46 class ChartAxisElement;
47 class ChartAnimator;
47 class ChartAnimator;
48 class ChartBackground;
48 class ChartBackground;
49 class ChartTitle;
49 class ChartTitle;
50 class ChartAnimation;
50 class ChartAnimation;
51 class AbstractChartLayout;
51 class AbstractChartLayout;
52
52
53 class ChartPresenter: public QObject
53 class ChartPresenter: public QObject
54 {
54 {
55 Q_OBJECT
55 Q_OBJECT
56 public:
56 public:
57 enum ZValues {
57 enum ZValues {
58 BackgroundZValue = -1,
58 BackgroundZValue = -1,
59 PlotAreaZValue,
59 PlotAreaZValue,
60 ShadesZValue,
60 ShadesZValue,
61 GridZValue,
61 GridZValue,
62 AxisZValue,
62 AxisZValue,
63 SeriesZValue,
63 SeriesZValue,
64 LineChartZValue = SeriesZValue,
64 LineChartZValue = SeriesZValue,
65 SplineChartZValue = SeriesZValue,
65 SplineChartZValue = SeriesZValue,
66 BarSeriesZValue = SeriesZValue,
66 BarSeriesZValue = SeriesZValue,
67 ScatterSeriesZValue = SeriesZValue,
67 ScatterSeriesZValue = SeriesZValue,
68 PieSeriesZValue = SeriesZValue,
68 PieSeriesZValue = SeriesZValue,
69 BoxPlotSeriesZValue = SeriesZValue,
69 BoxPlotSeriesZValue = SeriesZValue,
70 LegendZValue,
70 LegendZValue,
71 TopMostZValue
71 TopMostZValue
72 };
72 };
73
73
74 enum State {
74 enum State {
75 ShowState,
75 ShowState,
76 ScrollUpState,
76 ScrollUpState,
77 ScrollDownState,
77 ScrollDownState,
78 ScrollLeftState,
78 ScrollLeftState,
79 ScrollRightState,
79 ScrollRightState,
80 ZoomInState,
80 ZoomInState,
81 ZoomOutState
81 ZoomOutState
82 };
82 };
83
83
84 ChartPresenter(QChart *chart, QChart::ChartType type);
84 ChartPresenter(QChart *chart, QChart::ChartType type);
85 virtual ~ChartPresenter();
85 virtual ~ChartPresenter();
86
86
87
87
88 void setGeometry(QRectF rect);
88 void setGeometry(QRectF rect);
89 QRectF geometry() const;
89 QRectF geometry() const;
90
90
91 QGraphicsItem *rootItem(){ return m_chart; }
91 QGraphicsItem *rootItem(){ return m_chart; }
92 ChartBackground *backgroundElement();
92 ChartBackground *backgroundElement();
93 QAbstractGraphicsShapeItem *plotAreaElement();
93 QAbstractGraphicsShapeItem *plotAreaElement();
94 ChartTitle *titleElement();
94 ChartTitle *titleElement();
95 QList<ChartAxisElement *> axisItems() const;
95 QList<ChartAxisElement *> axisItems() const;
96 QList<ChartItem *> chartItems() const;
96 QList<ChartItem *> chartItems() const;
97
97
98 QLegend *legend();
98 QLegend *legend();
99
99
100 void setBackgroundBrush(const QBrush &brush);
100 void setBackgroundBrush(const QBrush &brush);
101 QBrush backgroundBrush() const;
101 QBrush backgroundBrush() const;
102
102
103 void setBackgroundPen(const QPen &pen);
103 void setBackgroundPen(const QPen &pen);
104 QPen backgroundPen() const;
104 QPen backgroundPen() const;
105
105
106 void setBackgroundRoundness(qreal diameter);
106 void setBackgroundRoundness(qreal diameter);
107 qreal backgroundRoundness() const;
107 qreal backgroundRoundness() const;
108
108
109 void setPlotAreaBackgroundBrush(const QBrush &brush);
109 void setPlotAreaBackgroundBrush(const QBrush &brush);
110 QBrush plotAreaBackgroundBrush() const;
110 QBrush plotAreaBackgroundBrush() const;
111
111
112 void setPlotAreaBackgroundPen(const QPen &pen);
112 void setPlotAreaBackgroundPen(const QPen &pen);
113 QPen plotAreaBackgroundPen() const;
113 QPen plotAreaBackgroundPen() const;
114
114
115 void setTitle(const QString &title);
115 void setTitle(const QString &title);
116 QString title() const;
116 QString title() const;
117
117
118 void setTitleFont(const QFont &font);
118 void setTitleFont(const QFont &font);
119 QFont titleFont() const;
119 QFont titleFont() const;
120
120
121 void setTitleBrush(const QBrush &brush);
121 void setTitleBrush(const QBrush &brush);
122 QBrush titleBrush() const;
122 QBrush titleBrush() const;
123
123
124 void setBackgroundVisible(bool visible);
124 void setBackgroundVisible(bool visible);
125 bool isBackgroundVisible() const;
125 bool isBackgroundVisible() const;
126
126
127 void setPlotAreaBackgroundVisible(bool visible);
127 void setPlotAreaBackgroundVisible(bool visible);
128 bool isPlotAreaBackgroundVisible() const;
128 bool isPlotAreaBackgroundVisible() const;
129
129
130 void setBackgroundDropShadowEnabled(bool enabled);
130 void setBackgroundDropShadowEnabled(bool enabled);
131 bool isBackgroundDropShadowEnabled() const;
131 bool isBackgroundDropShadowEnabled() const;
132
132
133 void setLocalizeNumbers(bool localize);
133 void setLocalizeNumbers(bool localize);
134 inline bool localizeNumbers() const { return m_localizeNumbers; }
134 inline bool localizeNumbers() const { return m_localizeNumbers; }
135 void setLocale(const QLocale &locale);
135 void setLocale(const QLocale &locale);
136 inline const QLocale &locale() const { return m_locale; }
136 inline const QLocale &locale() const { return m_locale; }
137
137
138 void setVisible(bool visible);
138 void setVisible(bool visible);
139
139
140 void setAnimationOptions(QChart::AnimationOptions options);
140 void setAnimationOptions(QChart::AnimationOptions options);
141 QChart::AnimationOptions animationOptions() const;
141 QChart::AnimationOptions animationOptions() const;
142
142
143 void startAnimation(ChartAnimation *animation);
143 void startAnimation(ChartAnimation *animation);
144
144
145 void setState(State state,QPointF point);
145 void setState(State state,QPointF point);
146 State state() const { return m_state; }
146 State state() const { return m_state; }
147 QPointF statePoint() const { return m_statePoint; }
147 QPointF statePoint() const { return m_statePoint; }
148 AbstractChartLayout *layout();
148 AbstractChartLayout *layout();
149
149
150 QChart::ChartType chartType() const { return m_chart->chartType(); }
150 QChart::ChartType chartType() const { return m_chart->chartType(); }
151 QChart *chart() { return m_chart; }
151 QChart *chart() { return m_chart; }
152
152
153 static QRectF textBoundingRect(const QFont &font, const QString &text, qreal angle = 0.0);
153 static QRectF textBoundingRect(const QFont &font, const QString &text, qreal angle = 0.0);
154 static QString truncatedText(const QFont &font, const QString &text, qreal angle,
154 static QString truncatedText(const QFont &font, const QString &text, qreal angle,
155 qreal maxWidth, qreal maxHeight, QRectF &boundingRect);
155 qreal maxWidth, qreal maxHeight, QRectF &boundingRect);
156 inline static qreal textMargin() { return qreal(0.5); }
156 inline static qreal textMargin() { return qreal(0.5); }
157
157
158 QString numberToString(double value, char f = 'g', int prec = 6);
158 QString numberToString(double value, char f = 'g', int prec = 6);
159 QString numberToString(int value);
159 QString numberToString(int value);
160
160
161 private:
161 private:
162 void createBackgroundItem();
162 void createBackgroundItem();
163 void createPlotAreaBackgroundItem();
163 void createPlotAreaBackgroundItem();
164 void createTitleItem();
164 void createTitleItem();
165
165
166 public Q_SLOTS:
166 public Q_SLOTS:
167 void handleSeriesAdded(QAbstractSeries *series);
167 void handleSeriesAdded(QAbstractSeries *series);
168 void handleSeriesRemoved(QAbstractSeries *series);
168 void handleSeriesRemoved(QAbstractSeries *series);
169 void handleAxisAdded(QAbstractAxis *axis);
169 void handleAxisAdded(QAbstractAxis *axis);
170 void handleAxisRemoved(QAbstractAxis *axis);
170 void handleAxisRemoved(QAbstractAxis *axis);
171
171
172 signals:
173 void plotAreaChanged(const QRectF &plotArea);
174
172 private:
175 private:
173 QChart *m_chart;
176 QChart *m_chart;
174 QList<ChartItem *> m_chartItems;
177 QList<ChartItem *> m_chartItems;
175 QList<ChartAxisElement *> m_axisItems;
178 QList<ChartAxisElement *> m_axisItems;
176 QList<QAbstractSeries *> m_series;
179 QList<QAbstractSeries *> m_series;
177 QList<QAbstractAxis *> m_axes;
180 QList<QAbstractAxis *> m_axes;
178 QChart::AnimationOptions m_options;
181 QChart::AnimationOptions m_options;
179 State m_state;
182 State m_state;
180 QPointF m_statePoint;
183 QPointF m_statePoint;
181 AbstractChartLayout *m_layout;
184 AbstractChartLayout *m_layout;
182 ChartBackground *m_background;
185 ChartBackground *m_background;
183 QAbstractGraphicsShapeItem *m_plotAreaBackground;
186 QAbstractGraphicsShapeItem *m_plotAreaBackground;
184 ChartTitle *m_title;
187 ChartTitle *m_title;
185 QRectF m_rect;
188 QRectF m_rect;
186 bool m_localizeNumbers;
189 bool m_localizeNumbers;
187 QLocale m_locale;
190 QLocale m_locale;
188 };
191 };
189
192
190 QT_CHARTS_END_NAMESPACE
193 QT_CHARTS_END_NAMESPACE
191
194
192 #endif /* CHARTPRESENTER_H */
195 #endif /* CHARTPRESENTER_H */
@@ -1,872 +1,875
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2014 Digia Plc
3 ** Copyright (C) 2014 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 Enterprise Charts Add-on.
7 ** This file is part of the Qt Enterprise Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
11 ** accordance with the Qt Enterprise License Agreement provided with the
11 ** accordance with the Qt Enterprise 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 <QtCharts/QChart>
21 #include <QtCharts/QChart>
22 #include <private/qchart_p.h>
22 #include <private/qchart_p.h>
23 #include <private/legendscroller_p.h>
23 #include <private/legendscroller_p.h>
24 #include <private/qlegend_p.h>
24 #include <private/qlegend_p.h>
25 #include <private/chartbackground_p.h>
25 #include <private/chartbackground_p.h>
26 #include <QtCharts/QAbstractAxis>
26 #include <QtCharts/QAbstractAxis>
27 #include <private/abstractchartlayout_p.h>
27 #include <private/abstractchartlayout_p.h>
28 #include <private/charttheme_p.h>
28 #include <private/charttheme_p.h>
29 #include <private/chartpresenter_p.h>
29 #include <private/chartpresenter_p.h>
30 #include <private/chartdataset_p.h>
30 #include <private/chartdataset_p.h>
31 #include <QtWidgets/QGraphicsScene>
31 #include <QtWidgets/QGraphicsScene>
32 #include <QGraphicsSceneResizeEvent>
32 #include <QGraphicsSceneResizeEvent>
33
33
34 QT_CHARTS_BEGIN_NAMESPACE
34 QT_CHARTS_BEGIN_NAMESPACE
35
35
36 /*!
36 /*!
37 \enum QChart::ChartTheme
37 \enum QChart::ChartTheme
38
38
39 This enum describes the theme used by the chart.
39 This enum describes the theme used by the chart.
40
40
41 \value ChartThemeLight The default theme
41 \value ChartThemeLight The default theme
42 \value ChartThemeBlueCerulean
42 \value ChartThemeBlueCerulean
43 \value ChartThemeDark
43 \value ChartThemeDark
44 \value ChartThemeBrownSand
44 \value ChartThemeBrownSand
45 \value ChartThemeBlueNcs
45 \value ChartThemeBlueNcs
46 \value ChartThemeHighContrast
46 \value ChartThemeHighContrast
47 \value ChartThemeBlueIcy
47 \value ChartThemeBlueIcy
48 \value ChartThemeQt
48 \value ChartThemeQt
49 */
49 */
50
50
51 /*!
51 /*!
52 \enum QChart::AnimationOption
52 \enum QChart::AnimationOption
53
53
54 For enabling/disabling animations. Defaults to NoAnimation.
54 For enabling/disabling animations. Defaults to NoAnimation.
55
55
56 \value NoAnimation
56 \value NoAnimation
57 \value GridAxisAnimations
57 \value GridAxisAnimations
58 \value SeriesAnimations
58 \value SeriesAnimations
59 \value AllAnimations
59 \value AllAnimations
60 */
60 */
61
61
62 /*!
62 /*!
63 \enum QChart::ChartType
63 \enum QChart::ChartType
64
64
65 This enum describes the chart type.
65 This enum describes the chart type.
66
66
67 \value ChartTypeUndefined
67 \value ChartTypeUndefined
68 \value ChartTypeCartesian
68 \value ChartTypeCartesian
69 \value ChartTypePolar
69 \value ChartTypePolar
70 */
70 */
71
71
72 /*!
72 /*!
73 \class QChart
73 \class QChart
74 \inmodule Qt Charts
74 \inmodule Qt Charts
75 \brief Main chart API for Qt Charts.
75 \brief Main chart API for Qt Charts.
76
76
77 QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical
77 QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical
78 representation of different types of series and other chart related objects like legend and
78 representation of different types of series and other chart related objects like legend and
79 axes. If you simply want to show a chart in a layout, you can use the
79 axes. If you simply want to show a chart in a layout, you can use the
80 convenience class QChartView instead of QChart.
80 convenience class QChartView instead of QChart.
81 \sa QChartView, QPolarChart
81 \sa QChartView, QPolarChart
82 */
82 */
83
83
84 /*!
84 /*!
85 \property QChart::animationOptions
85 \property QChart::animationOptions
86 The animation \a options for the chart. Animations are enabled/disabled based on this setting.
86 The animation \a options for the chart. Animations are enabled/disabled based on this setting.
87 */
87 */
88
88
89 /*!
89 /*!
90 \property QChart::backgroundVisible
90 \property QChart::backgroundVisible
91 Specifies whether the chart background is visible or not.
91 Specifies whether the chart background is visible or not.
92 \sa setBackgroundBrush(), setBackgroundPen(), plotAreaBackgroundVisible
92 \sa setBackgroundBrush(), setBackgroundPen(), plotAreaBackgroundVisible
93 */
93 */
94
94
95 /*!
95 /*!
96 \property QChart::dropShadowEnabled
96 \property QChart::dropShadowEnabled
97 If set to true, the background drop shadow effect is enabled. If set to false, it is disabled. Note that the drop
97 If set to true, the background drop shadow effect is enabled. If set to false, it is disabled. Note that the drop
98 shadow effect depends on theme, which means the setting may be changed if you switch to another theme.
98 shadow effect depends on theme, which means the setting may be changed if you switch to another theme.
99 */
99 */
100
100
101 /*!
101 /*!
102 \property QChart::backgroundRoundness
102 \property QChart::backgroundRoundness
103 The diameter of the rounding cirle at the corners of the chart background.
103 The diameter of the rounding cirle at the corners of the chart background.
104 */
104 */
105
105
106 /*!
106 /*!
107 \property QChart::minimumMargins
107 \property QChart::minimumMargins
108 Minimum margins between the plot area (axes) and the edge of the chart widget.
108 Minimum margins between the plot area (axes) and the edge of the chart widget.
109 This property is deprecated; use margins property instead.
109 This property is deprecated; use margins property instead.
110
110
111 \sa margins
111 \sa margins
112 */
112 */
113
113
114 /*!
114 /*!
115 \property QChart::margins
115 \property QChart::margins
116 Margins between the plot area (axes) and the edge of the chart widget.
116 Margins between the plot area (axes) and the edge of the chart widget.
117 */
117 */
118
118
119 /*!
119 /*!
120 \property QChart::theme
120 \property QChart::theme
121 Theme is a built-in collection of UI style related settings applied for all visual elements of a chart, like colors,
121 Theme is a built-in collection of UI style related settings applied for all visual elements of a chart, like colors,
122 pens, brushes, and fonts of series, axes, title, and legend. \l {Chart themes example} shows an example with a few
122 pens, brushes, and fonts of series, axes, title, and legend. \l {Chart themes example} shows an example with a few
123 different themes.
123 different themes.
124 \note Changing the theme will overwrite all customizations previously applied to the series.
124 \note Changing the theme will overwrite all customizations previously applied to the series.
125 */
125 */
126
126
127 /*!
127 /*!
128 \property QChart::title
128 \property QChart::title
129 Title is the name (label) of a chart. It is shown as a headline on top of the chart. Chart title supports html formatting.
129 Title is the name (label) of a chart. It is shown as a headline on top of the chart. Chart title supports html formatting.
130 */
130 */
131
131
132 /*!
132 /*!
133 \property QChart::chartType
133 \property QChart::chartType
134 Chart type indicates if the chart is a cartesian chart or a polar chart.
134 Chart type indicates if the chart is a cartesian chart or a polar chart.
135 This property is set internally and it is read only.
135 This property is set internally and it is read only.
136 \sa QPolarChart
136 \sa QPolarChart
137 */
137 */
138
138
139 /*!
139 /*!
140 \property QChart::plotAreaBackgroundVisible
140 \property QChart::plotAreaBackgroundVisible
141 Specifies whether the chart plot area background is visible or not.
141 Specifies whether the chart plot area background is visible or not.
142 \note By default the plot area background is not visible and the plot area uses
142 \note By default the plot area background is not visible and the plot area uses
143 the general chart background.
143 the general chart background.
144 \sa setPlotAreaBackgroundBrush(), setPlotAreaBackgroundPen(), backgroundVisible
144 \sa setPlotAreaBackgroundBrush(), setPlotAreaBackgroundPen(), backgroundVisible
145 */
145 */
146
146
147 /*!
147 /*!
148 \property QChart::localizeNumbers
148 \property QChart::localizeNumbers
149 \since QtCharts 2.0
149 \since QtCharts 2.0
150 When \c{true}, all generated numbers appearing in various series and axis labels will be
150 When \c{true}, all generated numbers appearing in various series and axis labels will be
151 localized using the QLocale set with the locale property.
151 localized using the QLocale set with the locale property.
152 When \c{false}, the "C" locale is always used.
152 When \c{false}, the "C" locale is always used.
153 Defaults to \c{false}.
153 Defaults to \c{false}.
154 \note This property doesn't affect QDateTimeAxis labels, which always use the QLocale set with
154 \note This property doesn't affect QDateTimeAxis labels, which always use the QLocale set with
155 the locale property.
155 the locale property.
156
156
157 \sa locale
157 \sa locale
158 */
158 */
159
159
160 /*!
160 /*!
161 \property QChart::locale
161 \property QChart::locale
162 \since QtCharts 2.0
162 \since QtCharts 2.0
163 Sets the locale used to format various chart labels when localizeNumbers is \c{true}.
163 Sets the locale used to format various chart labels when localizeNumbers is \c{true}.
164 This also determines the locale used to format QDateTimeAxis labels regardless of
164 This also determines the locale used to format QDateTimeAxis labels regardless of
165 localizeNumbers property.
165 localizeNumbers property.
166 Defaults to application default locale at the time the chart is constructed.
166 Defaults to application default locale at the time the chart is constructed.
167
167
168 \sa localizeNumbers
168 \sa localizeNumbers
169 */
169 */
170
170
171 /*!
171 /*!
172 \property QChart::plotArea
173 Holds the rectangle within which the drawing of the chart is done.
174 It does not include the area defined by margins.
175 */
176
177 /*!
172 \internal
178 \internal
173 Constructs a chart object of \a type which is a child of a \a parent.
179 Constructs a chart object of \a type which is a child of a \a parent.
174 Parameter \a wFlags is passed to the QGraphicsWidget constructor.
180 Parameter \a wFlags is passed to the QGraphicsWidget constructor.
175 This constructor is called only by subclasses.
181 This constructor is called only by subclasses.
176 */
182 */
177 QChart::QChart(QChart::ChartType type, QGraphicsItem *parent, Qt::WindowFlags wFlags)
183 QChart::QChart(QChart::ChartType type, QGraphicsItem *parent, Qt::WindowFlags wFlags)
178 : QGraphicsWidget(parent, wFlags),
184 : QGraphicsWidget(parent, wFlags),
179 d_ptr(new QChartPrivate(this, type))
185 d_ptr(new QChartPrivate(this, type))
180 {
186 {
181 d_ptr->init();
187 d_ptr->init();
182 }
188 }
183
189
184 /*!
190 /*!
185 Constructs a chart object which is a child of a \a parent.
191 Constructs a chart object which is a child of a \a parent.
186 Parameter \a wFlags is passed to the QGraphicsWidget constructor.
192 Parameter \a wFlags is passed to the QGraphicsWidget constructor.
187 */
193 */
188 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags)
194 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags)
189 : QGraphicsWidget(parent, wFlags),
195 : QGraphicsWidget(parent, wFlags),
190 d_ptr(new QChartPrivate(this, ChartTypeCartesian))
196 d_ptr(new QChartPrivate(this, ChartTypeCartesian))
191 {
197 {
192 d_ptr->init();
198 d_ptr->init();
193 }
199 }
194
200
195 /*!
201 /*!
196 Destroys the chart object and its children, like series and axis objects added to it.
202 Destroys the chart object and its children, like series and axis objects added to it.
197 */
203 */
198 QChart::~QChart()
204 QChart::~QChart()
199 {
205 {
200 //start by deleting dataset, it will remove all series and axes
206 //start by deleting dataset, it will remove all series and axes
201 delete d_ptr->m_dataset;
207 delete d_ptr->m_dataset;
202 d_ptr->m_dataset = 0;
208 d_ptr->m_dataset = 0;
203 }
209 }
204
210
205 /*!
211 /*!
206 Adds the \a series onto the chart and takes the ownership of it.
212 Adds the \a series onto the chart and takes the ownership of it.
207
213
208 \note A newly added series is attached to no axes by default, including any axes that were created for the chart
214 \note A newly added series is attached to no axes by default, including any axes that were created for the chart
209 using createDefaultAxes() before the series was added to the chart. If no axes are attached to
215 using createDefaultAxes() before the series was added to the chart. If no axes are attached to
210 the newly added series before the chart is shown, the series will get drawn as if it had axes with ranges
216 the newly added series before the chart is shown, the series will get drawn as if it had axes with ranges
211 that exactly fit the series to the plot area of the chart. This can be confusing if the same chart also displays other
217 that exactly fit the series to the plot area of the chart. This can be confusing if the same chart also displays other
212 series that have properly attached axes, so always make sure you either call createDefaultAxes() after
218 series that have properly attached axes, so always make sure you either call createDefaultAxes() after
213 a series has been added or explicitly attach axes for the series.
219 a series has been added or explicitly attach axes for the series.
214
220
215 \sa removeSeries(), removeAllSeries(), createDefaultAxes(), QAbstractSeries::attachAxis()
221 \sa removeSeries(), removeAllSeries(), createDefaultAxes(), QAbstractSeries::attachAxis()
216 */
222 */
217 void QChart::addSeries(QAbstractSeries *series)
223 void QChart::addSeries(QAbstractSeries *series)
218 {
224 {
219 Q_ASSERT(series);
225 Q_ASSERT(series);
220 d_ptr->m_dataset->addSeries(series);
226 d_ptr->m_dataset->addSeries(series);
221 }
227 }
222
228
223 /*!
229 /*!
224 Removes the \a series from the chart.
230 Removes the \a series from the chart.
225 The chart releases its ownership of the specified \a series object.
231 The chart releases its ownership of the specified \a series object.
226
232
227 \sa addSeries(), removeAllSeries()
233 \sa addSeries(), removeAllSeries()
228 */
234 */
229 void QChart::removeSeries(QAbstractSeries *series)
235 void QChart::removeSeries(QAbstractSeries *series)
230 {
236 {
231 Q_ASSERT(series);
237 Q_ASSERT(series);
232 d_ptr->m_dataset->removeSeries(series);
238 d_ptr->m_dataset->removeSeries(series);
233 }
239 }
234
240
235 /*!
241 /*!
236 Removes and deletes all series objects that have been added to the chart.
242 Removes and deletes all series objects that have been added to the chart.
237
243
238 \sa addSeries(), removeSeries()
244 \sa addSeries(), removeSeries()
239 */
245 */
240 void QChart::removeAllSeries()
246 void QChart::removeAllSeries()
241 {
247 {
242 foreach (QAbstractSeries *s , d_ptr->m_dataset->series()){
248 foreach (QAbstractSeries *s , d_ptr->m_dataset->series()){
243 removeSeries(s);
249 removeSeries(s);
244 delete s;
250 delete s;
245 }
251 }
246 }
252 }
247
253
248 /*!
254 /*!
249 Sets the \a brush that is used for painting the background of the chart area.
255 Sets the \a brush that is used for painting the background of the chart area.
250 */
256 */
251 void QChart::setBackgroundBrush(const QBrush &brush)
257 void QChart::setBackgroundBrush(const QBrush &brush)
252 {
258 {
253 d_ptr->m_presenter->setBackgroundBrush(brush);
259 d_ptr->m_presenter->setBackgroundBrush(brush);
254 }
260 }
255
261
256 /*!
262 /*!
257 Gets the brush that is used for painting the background of the chart area.
263 Gets the brush that is used for painting the background of the chart area.
258 */
264 */
259 QBrush QChart::backgroundBrush() const
265 QBrush QChart::backgroundBrush() const
260 {
266 {
261 return d_ptr->m_presenter->backgroundBrush();
267 return d_ptr->m_presenter->backgroundBrush();
262 }
268 }
263
269
264 /*!
270 /*!
265 Sets the \a pen that is used for painting the background of the chart area.
271 Sets the \a pen that is used for painting the background of the chart area.
266 */
272 */
267 void QChart::setBackgroundPen(const QPen &pen)
273 void QChart::setBackgroundPen(const QPen &pen)
268 {
274 {
269 d_ptr->m_presenter->setBackgroundPen(pen);
275 d_ptr->m_presenter->setBackgroundPen(pen);
270 }
276 }
271
277
272 /*!
278 /*!
273 Gets the pen that is used for painting the background of the chart area.
279 Gets the pen that is used for painting the background of the chart area.
274 */
280 */
275 QPen QChart::backgroundPen() const
281 QPen QChart::backgroundPen() const
276 {
282 {
277 return d_ptr->m_presenter->backgroundPen();
283 return d_ptr->m_presenter->backgroundPen();
278 }
284 }
279
285
280 void QChart::setTitle(const QString &title)
286 void QChart::setTitle(const QString &title)
281 {
287 {
282 d_ptr->m_presenter->setTitle(title);
288 d_ptr->m_presenter->setTitle(title);
283 }
289 }
284
290
285 QString QChart::title() const
291 QString QChart::title() const
286 {
292 {
287 return d_ptr->m_presenter->title();
293 return d_ptr->m_presenter->title();
288 }
294 }
289
295
290 /*!
296 /*!
291 Sets the \a font that is used for drawing the chart title.
297 Sets the \a font that is used for drawing the chart title.
292 */
298 */
293 void QChart::setTitleFont(const QFont &font)
299 void QChart::setTitleFont(const QFont &font)
294 {
300 {
295 d_ptr->m_presenter->setTitleFont(font);
301 d_ptr->m_presenter->setTitleFont(font);
296 }
302 }
297
303
298 /*!
304 /*!
299 Gets the font that is used for drawing the chart title.
305 Gets the font that is used for drawing the chart title.
300 */
306 */
301 QFont QChart::titleFont() const
307 QFont QChart::titleFont() const
302 {
308 {
303 return d_ptr->m_presenter->titleFont();
309 return d_ptr->m_presenter->titleFont();
304 }
310 }
305
311
306 /*!
312 /*!
307 Sets the \a brush used for drawing the title text.
313 Sets the \a brush used for drawing the title text.
308 */
314 */
309 void QChart::setTitleBrush(const QBrush &brush)
315 void QChart::setTitleBrush(const QBrush &brush)
310 {
316 {
311 d_ptr->m_presenter->setTitleBrush(brush);
317 d_ptr->m_presenter->setTitleBrush(brush);
312 }
318 }
313
319
314 /*!
320 /*!
315 Returns the brush used for drawing the title text.
321 Returns the brush used for drawing the title text.
316 */
322 */
317 QBrush QChart::titleBrush() const
323 QBrush QChart::titleBrush() const
318 {
324 {
319 return d_ptr->m_presenter->titleBrush();
325 return d_ptr->m_presenter->titleBrush();
320 }
326 }
321
327
322 void QChart::setTheme(QChart::ChartTheme theme)
328 void QChart::setTheme(QChart::ChartTheme theme)
323 {
329 {
324 d_ptr->m_themeManager->setTheme(theme);
330 d_ptr->m_themeManager->setTheme(theme);
325 }
331 }
326
332
327 QChart::ChartTheme QChart::theme() const
333 QChart::ChartTheme QChart::theme() const
328 {
334 {
329 return d_ptr->m_themeManager->theme()->id();
335 return d_ptr->m_themeManager->theme()->id();
330 }
336 }
331
337
332 /*!
338 /*!
333 Zooms in the view by a factor of two.
339 Zooms in the view by a factor of two.
334 */
340 */
335 void QChart::zoomIn()
341 void QChart::zoomIn()
336 {
342 {
337 d_ptr->zoomIn(2.0);
343 d_ptr->zoomIn(2.0);
338 }
344 }
339
345
340 /*!
346 /*!
341 Zooms in the view to a maximum level at which \a rect is still fully visible.
347 Zooms in the view to a maximum level at which \a rect is still fully visible.
342 \note This is not supported for polar charts.
348 \note This is not supported for polar charts.
343 */
349 */
344 void QChart::zoomIn(const QRectF &rect)
350 void QChart::zoomIn(const QRectF &rect)
345 {
351 {
346 if (d_ptr->m_type == QChart::ChartTypePolar)
352 if (d_ptr->m_type == QChart::ChartTypePolar)
347 return;
353 return;
348 d_ptr->zoomIn(rect);
354 d_ptr->zoomIn(rect);
349 }
355 }
350
356
351 /*!
357 /*!
352 Zooms out the view by a factor of two.
358 Zooms out the view by a factor of two.
353 */
359 */
354 void QChart::zoomOut()
360 void QChart::zoomOut()
355 {
361 {
356 d_ptr->zoomOut(2.0);
362 d_ptr->zoomOut(2.0);
357 }
363 }
358
364
359 /*!
365 /*!
360 Zooms in the view by a custom \a factor.
366 Zooms in the view by a custom \a factor.
361
367
362 A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out.
368 A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out.
363 */
369 */
364 void QChart::zoom(qreal factor)
370 void QChart::zoom(qreal factor)
365 {
371 {
366 if (qFuzzyCompare(factor, 0))
372 if (qFuzzyCompare(factor, 0))
367 return;
373 return;
368
374
369 if (qFuzzyCompare(factor, (qreal)1.0))
375 if (qFuzzyCompare(factor, (qreal)1.0))
370 return;
376 return;
371
377
372 if (factor < 0)
378 if (factor < 0)
373 return;
379 return;
374
380
375 if (factor > 1.0)
381 if (factor > 1.0)
376 d_ptr->zoomIn(factor);
382 d_ptr->zoomIn(factor);
377 else
383 else
378 d_ptr->zoomOut(1.0 / factor);
384 d_ptr->zoomOut(1.0 / factor);
379 }
385 }
380
386
381
387
382 /*!
388 /*!
383 Resets the series domains to what they were before any zoom method was called.
389 Resets the series domains to what they were before any zoom method was called.
384 Note that this will also reset any scrolls and explicit axis range settings done between
390 Note that this will also reset any scrolls and explicit axis range settings done between
385 the first zoom operation and calling this method. If no zoom operation has been
391 the first zoom operation and calling this method. If no zoom operation has been
386 done, this method does nothing.
392 done, this method does nothing.
387 */
393 */
388 void QChart::zoomReset()
394 void QChart::zoomReset()
389 {
395 {
390 d_ptr->zoomReset();
396 d_ptr->zoomReset();
391 }
397 }
392
398
393 /*!
399 /*!
394 Returns true if any series has a zoomed domain.
400 Returns true if any series has a zoomed domain.
395 */
401 */
396 bool QChart::isZoomed()
402 bool QChart::isZoomed()
397 {
403 {
398 return d_ptr->isZoomed();
404 return d_ptr->isZoomed();
399 }
405 }
400
406
401 /*!
407 /*!
402 Returns a pointer to the horizontal axis attached to the specified \a series.
408 Returns a pointer to the horizontal axis attached to the specified \a series.
403 If no \a series is specified, the first horizontal axis added to the chart is returned.
409 If no \a series is specified, the first horizontal axis added to the chart is returned.
404
410
405 \sa addAxis(), QAbstractSeries::attachAxis()
411 \sa addAxis(), QAbstractSeries::attachAxis()
406 */
412 */
407 QAbstractAxis *QChart::axisX(QAbstractSeries *series) const
413 QAbstractAxis *QChart::axisX(QAbstractSeries *series) const
408 {
414 {
409 QList<QAbstractAxis *> axisList = axes(Qt::Horizontal, series);
415 QList<QAbstractAxis *> axisList = axes(Qt::Horizontal, series);
410 if (axisList.count())
416 if (axisList.count())
411 return axisList[0];
417 return axisList[0];
412 return 0;
418 return 0;
413 }
419 }
414
420
415 /*!
421 /*!
416 Returns a pointer to the vertical axis attached to the specified \a series.
422 Returns a pointer to the vertical axis attached to the specified \a series.
417 If no \a series is specified, the first vertical axis added to the chart is returned.
423 If no \a series is specified, the first vertical axis added to the chart is returned.
418
424
419 \sa addAxis(), QAbstractSeries::attachAxis()
425 \sa addAxis(), QAbstractSeries::attachAxis()
420 */
426 */
421 QAbstractAxis *QChart::axisY(QAbstractSeries *series) const
427 QAbstractAxis *QChart::axisY(QAbstractSeries *series) const
422 {
428 {
423 QList<QAbstractAxis *> axisList = axes(Qt::Vertical, series);
429 QList<QAbstractAxis *> axisList = axes(Qt::Vertical, series);
424 if (axisList.count())
430 if (axisList.count())
425 return axisList[0];
431 return axisList[0];
426 return 0;
432 return 0;
427 }
433 }
428
434
429 /*!
435 /*!
430 Returns the axes attached to the \a series with \a orientation. If no \a series is provided,
436 Returns the axes attached to the \a series with \a orientation. If no \a series is provided,
431 then all axes added to the chart with the specified orientation are returned.
437 then all axes added to the chart with the specified orientation are returned.
432 \sa addAxis(), createDefaultAxes()
438 \sa addAxis(), createDefaultAxes()
433 */
439 */
434 QList<QAbstractAxis *> QChart::axes(Qt::Orientations orientation, QAbstractSeries *series) const
440 QList<QAbstractAxis *> QChart::axes(Qt::Orientations orientation, QAbstractSeries *series) const
435 {
441 {
436 QList<QAbstractAxis *> result ;
442 QList<QAbstractAxis *> result ;
437
443
438 if (series) {
444 if (series) {
439 foreach (QAbstractAxis *axis, series->attachedAxes()){
445 foreach (QAbstractAxis *axis, series->attachedAxes()){
440 if (orientation.testFlag(axis->orientation()))
446 if (orientation.testFlag(axis->orientation()))
441 result << axis;
447 result << axis;
442 }
448 }
443 } else {
449 } else {
444 foreach (QAbstractAxis *axis, d_ptr->m_dataset->axes()){
450 foreach (QAbstractAxis *axis, d_ptr->m_dataset->axes()){
445 if (orientation.testFlag(axis->orientation()) && !result.contains(axis))
451 if (orientation.testFlag(axis->orientation()) && !result.contains(axis))
446 result << axis;
452 result << axis;
447 }
453 }
448 }
454 }
449
455
450 return result;
456 return result;
451 }
457 }
452
458
453 /*!
459 /*!
454 Creates axes for the chart based on the series that have already been added to the chart. Any axes previously added to
460 Creates axes for the chart based on the series that have already been added to the chart. Any axes previously added to
455 the chart will be deleted.
461 the chart will be deleted.
456
462
457 \note This function has to be called after all series have been added to the chart. The axes created by this function
463 \note This function has to be called after all series have been added to the chart. The axes created by this function
458 will NOT get automatically attached to any series added to the chart after this function has been called.
464 will NOT get automatically attached to any series added to the chart after this function has been called.
459 A series with no axes attached will by default scale to utilize the entire plot area of the chart, which can be confusing
465 A series with no axes attached will by default scale to utilize the entire plot area of the chart, which can be confusing
460 if there are other series with properly attached axes also present.
466 if there are other series with properly attached axes also present.
461
467
462 \table
468 \table
463 \header
469 \header
464 \li Series type
470 \li Series type
465 \li X-axis
471 \li X-axis
466 \li Y-axis
472 \li Y-axis
467 \row
473 \row
468 \li QXYSeries
474 \li QXYSeries
469 \li QValueAxis
475 \li QValueAxis
470 \li QValueAxis
476 \li QValueAxis
471 \row
477 \row
472 \li QBarSeries
478 \li QBarSeries
473 \li QBarCategoryAxis
479 \li QBarCategoryAxis
474 \li QValueAxis
480 \li QValueAxis
475 \row
481 \row
476 \li QPieSeries
482 \li QPieSeries
477 \li None
483 \li None
478 \li None
484 \li None
479 \endtable
485 \endtable
480
486
481 If there are several QXYSeries derived series added to the chart and no series of other types have been added, then only one pair of axes is created.
487 If there are several QXYSeries derived series added to the chart and no series of other types have been added, then only one pair of axes is created.
482 If there are several series of different types added to the chart, then each series gets its own axes pair.
488 If there are several series of different types added to the chart, then each series gets its own axes pair.
483
489
484 The axes specific to the series can be later obtained from the chart by providing the series as the parameter for axes() function call.
490 The axes specific to the series can be later obtained from the chart by providing the series as the parameter for axes() function call.
485 QPieSeries does not create any axes.
491 QPieSeries does not create any axes.
486
492
487 \sa axisX(), axisY(), axes(), setAxisX(), setAxisY(), QAbstractSeries::attachAxis()
493 \sa axisX(), axisY(), axes(), setAxisX(), setAxisY(), QAbstractSeries::attachAxis()
488 */
494 */
489 void QChart::createDefaultAxes()
495 void QChart::createDefaultAxes()
490 {
496 {
491 d_ptr->m_dataset->createDefaultAxes();
497 d_ptr->m_dataset->createDefaultAxes();
492 }
498 }
493
499
494 /*!
500 /*!
495 Returns the legend object of the chart. Ownership stays with the chart.
501 Returns the legend object of the chart. Ownership stays with the chart.
496 */
502 */
497 QLegend *QChart::legend() const
503 QLegend *QChart::legend() const
498 {
504 {
499 return d_ptr->m_legend;
505 return d_ptr->m_legend;
500 }
506 }
501
507
502 void QChart::setMinimumMargins(const QMargins &margins)
508 void QChart::setMinimumMargins(const QMargins &margins)
503 {
509 {
504 qWarning() << "QChart::setMinimumMargins is deprecated. Use QChart::setMargins instead.";
510 qWarning() << "QChart::setMinimumMargins is deprecated. Use QChart::setMargins instead.";
505 d_ptr->m_presenter->layout()->setMargins(margins);
511 d_ptr->m_presenter->layout()->setMargins(margins);
506 }
512 }
507
513
508 QMargins QChart::minimumMargins() const
514 QMargins QChart::minimumMargins() const
509 {
515 {
510 qWarning() << "QChart::minimumMargins is deprecated. Use QChart::margins instead.";
516 qWarning() << "QChart::minimumMargins is deprecated. Use QChart::margins instead.";
511 return d_ptr->m_presenter->layout()->margins();
517 return d_ptr->m_presenter->layout()->margins();
512 }
518 }
513
519
514 void QChart::setMargins(const QMargins &margins)
520 void QChart::setMargins(const QMargins &margins)
515 {
521 {
516 d_ptr->m_presenter->layout()->setMargins(margins);
522 d_ptr->m_presenter->layout()->setMargins(margins);
517 }
523 }
518
524
519 QMargins QChart::margins() const
525 QMargins QChart::margins() const
520 {
526 {
521 return d_ptr->m_presenter->layout()->margins();
527 return d_ptr->m_presenter->layout()->margins();
522 }
528 }
523
529
524 QChart::ChartType QChart::chartType() const
530 QChart::ChartType QChart::chartType() const
525 {
531 {
526 return d_ptr->m_type;
532 return d_ptr->m_type;
527 }
533 }
528
534
529 /*!
530 Returns the the rectangle within which the drawing of the chart is done.
531 It does not include the area defined by margins.
532 */
533 QRectF QChart::plotArea() const
535 QRectF QChart::plotArea() const
534 {
536 {
535 return d_ptr->m_presenter->geometry();
537 return d_ptr->m_presenter->geometry();
536 }
538 }
537
539
538 /*!
540 /*!
539 Sets the \a brush for the background of the plot area of the chart.
541 Sets the \a brush for the background of the plot area of the chart.
540
542
541 \sa plotArea(), plotAreaBackgroundVisible, setPlotAreaBackgroundPen(), plotAreaBackgroundBrush()
543 \sa plotArea(), plotAreaBackgroundVisible, setPlotAreaBackgroundPen(), plotAreaBackgroundBrush()
542 */
544 */
543 void QChart::setPlotAreaBackgroundBrush(const QBrush &brush)
545 void QChart::setPlotAreaBackgroundBrush(const QBrush &brush)
544 {
546 {
545 d_ptr->m_presenter->setPlotAreaBackgroundBrush(brush);
547 d_ptr->m_presenter->setPlotAreaBackgroundBrush(brush);
546 }
548 }
547
549
548 /*!
550 /*!
549 Returns the brush for the background of the plot area of the chart.
551 Returns the brush for the background of the plot area of the chart.
550
552
551 \sa plotArea(), plotAreaBackgroundVisible, plotAreaBackgroundPen(), setPlotAreaBackgroundBrush()
553 \sa plotArea(), plotAreaBackgroundVisible, plotAreaBackgroundPen(), setPlotAreaBackgroundBrush()
552 */
554 */
553 QBrush QChart::plotAreaBackgroundBrush() const
555 QBrush QChart::plotAreaBackgroundBrush() const
554 {
556 {
555 return d_ptr->m_presenter->plotAreaBackgroundBrush();
557 return d_ptr->m_presenter->plotAreaBackgroundBrush();
556 }
558 }
557
559
558 /*!
560 /*!
559 Sets the \a pen for the background of the plot area of the chart.
561 Sets the \a pen for the background of the plot area of the chart.
560
562
561 \sa plotArea(), plotAreaBackgroundVisible, setPlotAreaBackgroundBrush(), plotAreaBackgroundPen()
563 \sa plotArea(), plotAreaBackgroundVisible, setPlotAreaBackgroundBrush(), plotAreaBackgroundPen()
562 */
564 */
563 void QChart::setPlotAreaBackgroundPen(const QPen &pen)
565 void QChart::setPlotAreaBackgroundPen(const QPen &pen)
564 {
566 {
565 d_ptr->m_presenter->setPlotAreaBackgroundPen(pen);
567 d_ptr->m_presenter->setPlotAreaBackgroundPen(pen);
566 }
568 }
567
569
568 /*!
570 /*!
569 Returns the pen for the background of the plot area of the chart.
571 Returns the pen for the background of the plot area of the chart.
570
572
571 \sa plotArea(), plotAreaBackgroundVisible, plotAreaBackgroundBrush(), setPlotAreaBackgroundPen()
573 \sa plotArea(), plotAreaBackgroundVisible, plotAreaBackgroundBrush(), setPlotAreaBackgroundPen()
572 */
574 */
573 QPen QChart::plotAreaBackgroundPen() const
575 QPen QChart::plotAreaBackgroundPen() const
574 {
576 {
575 return d_ptr->m_presenter->plotAreaBackgroundPen();
577 return d_ptr->m_presenter->plotAreaBackgroundPen();
576 }
578 }
577
579
578 void QChart::setPlotAreaBackgroundVisible(bool visible)
580 void QChart::setPlotAreaBackgroundVisible(bool visible)
579 {
581 {
580 d_ptr->m_presenter->setPlotAreaBackgroundVisible(visible);
582 d_ptr->m_presenter->setPlotAreaBackgroundVisible(visible);
581 }
583 }
582
584
583 bool QChart::isPlotAreaBackgroundVisible() const
585 bool QChart::isPlotAreaBackgroundVisible() const
584 {
586 {
585 return d_ptr->m_presenter->isPlotAreaBackgroundVisible();
587 return d_ptr->m_presenter->isPlotAreaBackgroundVisible();
586 }
588 }
587
589
588 void QChart::setLocalizeNumbers(bool localize)
590 void QChart::setLocalizeNumbers(bool localize)
589 {
591 {
590 d_ptr->m_presenter->setLocalizeNumbers(localize);
592 d_ptr->m_presenter->setLocalizeNumbers(localize);
591 }
593 }
592
594
593 bool QChart::localizeNumbers() const
595 bool QChart::localizeNumbers() const
594 {
596 {
595 return d_ptr->m_presenter->localizeNumbers();
597 return d_ptr->m_presenter->localizeNumbers();
596 }
598 }
597
599
598 void QChart::setLocale(const QLocale &locale)
600 void QChart::setLocale(const QLocale &locale)
599 {
601 {
600 d_ptr->m_presenter->setLocale(locale);
602 d_ptr->m_presenter->setLocale(locale);
601 }
603 }
602
604
603 QLocale QChart::locale() const
605 QLocale QChart::locale() const
604 {
606 {
605 return d_ptr->m_presenter->locale();
607 return d_ptr->m_presenter->locale();
606 }
608 }
607
609
608 void QChart::setAnimationOptions(AnimationOptions options)
610 void QChart::setAnimationOptions(AnimationOptions options)
609 {
611 {
610 d_ptr->m_presenter->setAnimationOptions(options);
612 d_ptr->m_presenter->setAnimationOptions(options);
611 }
613 }
612
614
613 QChart::AnimationOptions QChart::animationOptions() const
615 QChart::AnimationOptions QChart::animationOptions() const
614 {
616 {
615 return d_ptr->m_presenter->animationOptions();
617 return d_ptr->m_presenter->animationOptions();
616 }
618 }
617
619
618 /*!
620 /*!
619 Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy.
621 Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy.
620
622
621 For polar charts, \a dx indicates the angle along angular axis instead of distance.
623 For polar charts, \a dx indicates the angle along angular axis instead of distance.
622 */
624 */
623 void QChart::scroll(qreal dx, qreal dy)
625 void QChart::scroll(qreal dx, qreal dy)
624 {
626 {
625 d_ptr->scroll(dx,dy);
627 d_ptr->scroll(dx,dy);
626 }
628 }
627
629
628 void QChart::setBackgroundVisible(bool visible)
630 void QChart::setBackgroundVisible(bool visible)
629 {
631 {
630 d_ptr->m_presenter->setBackgroundVisible(visible);
632 d_ptr->m_presenter->setBackgroundVisible(visible);
631 }
633 }
632
634
633 bool QChart::isBackgroundVisible() const
635 bool QChart::isBackgroundVisible() const
634 {
636 {
635 return d_ptr->m_presenter->isBackgroundVisible();
637 return d_ptr->m_presenter->isBackgroundVisible();
636 }
638 }
637
639
638 void QChart::setDropShadowEnabled(bool enabled)
640 void QChart::setDropShadowEnabled(bool enabled)
639 {
641 {
640 d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled);
642 d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled);
641 }
643 }
642
644
643 bool QChart::isDropShadowEnabled() const
645 bool QChart::isDropShadowEnabled() const
644 {
646 {
645 return d_ptr->m_presenter->isBackgroundDropShadowEnabled();
647 return d_ptr->m_presenter->isBackgroundDropShadowEnabled();
646 }
648 }
647
649
648 void QChart::setBackgroundRoundness(qreal diameter)
650 void QChart::setBackgroundRoundness(qreal diameter)
649 {
651 {
650 d_ptr->m_presenter->setBackgroundRoundness(diameter);
652 d_ptr->m_presenter->setBackgroundRoundness(diameter);
651 }
653 }
652
654
653 qreal QChart::backgroundRoundness() const
655 qreal QChart::backgroundRoundness() const
654 {
656 {
655 return d_ptr->m_presenter->backgroundRoundness();
657 return d_ptr->m_presenter->backgroundRoundness();
656 }
658 }
657
659
658 /*!
660 /*!
659 Returns all series that are added to the chart.
661 Returns all series that are added to the chart.
660
662
661 \sa addSeries(), removeSeries(), removeAllSeries()
663 \sa addSeries(), removeSeries(), removeAllSeries()
662 */
664 */
663 QList<QAbstractSeries *> QChart::series() const
665 QList<QAbstractSeries *> QChart::series() const
664 {
666 {
665 return d_ptr->m_dataset->series();
667 return d_ptr->m_dataset->series();
666 }
668 }
667
669
668 /*!
670 /*!
669 Adds the \a axis to the chart and attaches it to the \a series as a bottom-aligned horizontal axis.
671 Adds the \a axis to the chart and attaches it to the \a series as a bottom-aligned horizontal axis.
670 The chart takes ownership of both the \a axis and the \a series.
672 The chart takes ownership of both the \a axis and the \a series.
671 Any horizontal axes previously attached to the \a series are deleted.
673 Any horizontal axes previously attached to the \a series are deleted.
672
674
673 \sa axisX(), axisY(), setAxisY(), createDefaultAxes(), QAbstractSeries::attachAxis()
675 \sa axisX(), axisY(), setAxisY(), createDefaultAxes(), QAbstractSeries::attachAxis()
674 */
676 */
675 void QChart::setAxisX(QAbstractAxis *axis ,QAbstractSeries *series)
677 void QChart::setAxisX(QAbstractAxis *axis ,QAbstractSeries *series)
676 {
678 {
677 QList<QAbstractAxis*> list = axes(Qt::Horizontal, series);
679 QList<QAbstractAxis*> list = axes(Qt::Horizontal, series);
678
680
679 foreach (QAbstractAxis* a, list) {
681 foreach (QAbstractAxis* a, list) {
680 d_ptr->m_dataset->removeAxis(a);
682 d_ptr->m_dataset->removeAxis(a);
681 delete a;
683 delete a;
682 }
684 }
683
685
684 if (!d_ptr->m_dataset->axes().contains(axis))
686 if (!d_ptr->m_dataset->axes().contains(axis))
685 d_ptr->m_dataset->addAxis(axis, Qt::AlignBottom);
687 d_ptr->m_dataset->addAxis(axis, Qt::AlignBottom);
686 d_ptr->m_dataset->attachAxis(series, axis);
688 d_ptr->m_dataset->attachAxis(series, axis);
687 }
689 }
688
690
689 /*!
691 /*!
690 Adds the \a axis to the chart and attaches it to the \a series as a left-aligned vertical axis.
692 Adds the \a axis to the chart and attaches it to the \a series as a left-aligned vertical axis.
691 The chart takes ownership of both the \a axis and the \a series.
693 The chart takes ownership of both the \a axis and the \a series.
692 Any vertical axes previously attached to the \a series are deleted.
694 Any vertical axes previously attached to the \a series are deleted.
693
695
694 \sa axisX(), axisY(), setAxisX(), createDefaultAxes(), QAbstractSeries::attachAxis()
696 \sa axisX(), axisY(), setAxisX(), createDefaultAxes(), QAbstractSeries::attachAxis()
695 */
697 */
696 void QChart::setAxisY(QAbstractAxis *axis ,QAbstractSeries *series)
698 void QChart::setAxisY(QAbstractAxis *axis ,QAbstractSeries *series)
697 {
699 {
698 QList<QAbstractAxis*> list = axes(Qt::Vertical, series);
700 QList<QAbstractAxis*> list = axes(Qt::Vertical, series);
699
701
700 foreach (QAbstractAxis* a, list) {
702 foreach (QAbstractAxis* a, list) {
701 d_ptr->m_dataset->removeAxis(a);
703 d_ptr->m_dataset->removeAxis(a);
702 delete a;
704 delete a;
703 }
705 }
704
706
705 if (!d_ptr->m_dataset->axes().contains(axis))
707 if (!d_ptr->m_dataset->axes().contains(axis))
706 d_ptr->m_dataset->addAxis(axis, Qt::AlignLeft);
708 d_ptr->m_dataset->addAxis(axis, Qt::AlignLeft);
707 d_ptr->m_dataset->attachAxis(series, axis);
709 d_ptr->m_dataset->attachAxis(series, axis);
708 }
710 }
709
711
710 /*!
712 /*!
711 Adds the \a axis to the chart with \a alignment. The chart takes the ownership of the axis.
713 Adds the \a axis to the chart with \a alignment. The chart takes the ownership of the axis.
712
714
713 \sa removeAxis(), createDefaultAxes(), QAbstractSeries::attachAxis()
715 \sa removeAxis(), createDefaultAxes(), QAbstractSeries::attachAxis()
714 */
716 */
715 void QChart::addAxis(QAbstractAxis *axis, Qt::Alignment alignment)
717 void QChart::addAxis(QAbstractAxis *axis, Qt::Alignment alignment)
716 {
718 {
717 d_ptr->m_dataset->addAxis(axis, alignment);
719 d_ptr->m_dataset->addAxis(axis, alignment);
718 }
720 }
719
721
720 /*!
722 /*!
721 Removes the \a axis from the chart.
723 Removes the \a axis from the chart.
722 The chart releases its ownership of the specified \a axis object.
724 The chart releases its ownership of the specified \a axis object.
723
725
724 \sa addAxis(), createDefaultAxes(), QAbstractSeries::detachAxis()
726 \sa addAxis(), createDefaultAxes(), QAbstractSeries::detachAxis()
725 */
727 */
726 void QChart::removeAxis(QAbstractAxis *axis)
728 void QChart::removeAxis(QAbstractAxis *axis)
727 {
729 {
728 d_ptr->m_dataset->removeAxis(axis);
730 d_ptr->m_dataset->removeAxis(axis);
729 }
731 }
730
732
731 /*!
733 /*!
732 Returns the value in the \a series domain that corresponds to the \a position relative to chart widget.
734 Returns the value in the \a series domain that corresponds to the \a position relative to chart widget.
733 */
735 */
734 QPointF QChart::mapToValue(const QPointF &position, QAbstractSeries *series)
736 QPointF QChart::mapToValue(const QPointF &position, QAbstractSeries *series)
735 {
737 {
736 return d_ptr->m_dataset->mapToValue(position, series);
738 return d_ptr->m_dataset->mapToValue(position, series);
737 }
739 }
738
740
739 /*!
741 /*!
740 Returns the position on the chart widget that corresponds to the \a value in the \a series domain.
742 Returns the position on the chart widget that corresponds to the \a value in the \a series domain.
741 */
743 */
742 QPointF QChart::mapToPosition(const QPointF &value, QAbstractSeries *series)
744 QPointF QChart::mapToPosition(const QPointF &value, QAbstractSeries *series)
743 {
745 {
744 return d_ptr->m_dataset->mapToPosition(value, series);
746 return d_ptr->m_dataset->mapToPosition(value, series);
745 }
747 }
746
748
747 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
749 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
748
750
749 QChartPrivate::QChartPrivate(QChart *q, QChart::ChartType type):
751 QChartPrivate::QChartPrivate(QChart *q, QChart::ChartType type):
750 q_ptr(q),
752 q_ptr(q),
751 m_legend(0),
753 m_legend(0),
752 m_dataset(new ChartDataSet(q)),
754 m_dataset(new ChartDataSet(q)),
753 m_presenter(new ChartPresenter(q, type)),
755 m_presenter(new ChartPresenter(q, type)),
754 m_themeManager(new ChartThemeManager(q)),
756 m_themeManager(new ChartThemeManager(q)),
755 m_type(type)
757 m_type(type)
756 {
758 {
757 QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_presenter, SLOT(handleSeriesAdded(QAbstractSeries*)));
759 QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_presenter, SLOT(handleSeriesAdded(QAbstractSeries*)));
758 QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_presenter, SLOT(handleSeriesRemoved(QAbstractSeries*)));
760 QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_presenter, SLOT(handleSeriesRemoved(QAbstractSeries*)));
759 QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_presenter, SLOT(handleAxisAdded(QAbstractAxis*)));
761 QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_presenter, SLOT(handleAxisAdded(QAbstractAxis*)));
760 QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_presenter, SLOT(handleAxisRemoved(QAbstractAxis*)));
762 QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_presenter, SLOT(handleAxisRemoved(QAbstractAxis*)));
761 QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesAdded(QAbstractSeries*)));
763 QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesAdded(QAbstractSeries*)));
762 QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesRemoved(QAbstractSeries*)));
764 QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesRemoved(QAbstractSeries*)));
763 QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_themeManager, SLOT(handleAxisAdded(QAbstractAxis*)));
765 QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_themeManager, SLOT(handleAxisAdded(QAbstractAxis*)));
764 QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_themeManager, SLOT(handleAxisRemoved(QAbstractAxis*)));
766 QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_themeManager, SLOT(handleAxisRemoved(QAbstractAxis*)));
767 QObject::connect(m_presenter, &ChartPresenter::plotAreaChanged, q, &QChart::plotAreaChanged);
765 }
768 }
766
769
767 QChartPrivate::~QChartPrivate()
770 QChartPrivate::~QChartPrivate()
768 {
771 {
769 }
772 }
770
773
771 // Hackish solution to the problem of explicitly assigning the default pen/brush/font
774 // Hackish solution to the problem of explicitly assigning the default pen/brush/font
772 // to a series or axis and having theme override it:
775 // to a series or axis and having theme override it:
773 // Initialize pens, brushes, and fonts to something nobody is likely to ever use,
776 // Initialize pens, brushes, and fonts to something nobody is likely to ever use,
774 // so that default theme initialization will always set these properly.
777 // so that default theme initialization will always set these properly.
775 QPen &QChartPrivate::defaultPen()
778 QPen &QChartPrivate::defaultPen()
776 {
779 {
777 static QPen defaultPen(QColor(1, 2, 0), 0.93247536);
780 static QPen defaultPen(QColor(1, 2, 0), 0.93247536);
778 return defaultPen;
781 return defaultPen;
779 }
782 }
780
783
781 QBrush &QChartPrivate::defaultBrush()
784 QBrush &QChartPrivate::defaultBrush()
782 {
785 {
783 static QBrush defaultBrush(QColor(1, 2, 0), Qt::Dense7Pattern);
786 static QBrush defaultBrush(QColor(1, 2, 0), Qt::Dense7Pattern);
784 return defaultBrush;
787 return defaultBrush;
785 }
788 }
786
789
787 QFont &QChartPrivate::defaultFont()
790 QFont &QChartPrivate::defaultFont()
788 {
791 {
789 static bool defaultFontInitialized(false);
792 static bool defaultFontInitialized(false);
790 static QFont defaultFont;
793 static QFont defaultFont;
791 if (!defaultFontInitialized) {
794 if (!defaultFontInitialized) {
792 defaultFont.setPointSizeF(8.34563465);
795 defaultFont.setPointSizeF(8.34563465);
793 defaultFontInitialized = true;
796 defaultFontInitialized = true;
794 }
797 }
795 return defaultFont;
798 return defaultFont;
796 }
799 }
797
800
798 void QChartPrivate::init()
801 void QChartPrivate::init()
799 {
802 {
800 m_legend = new LegendScroller(q_ptr);
803 m_legend = new LegendScroller(q_ptr);
801 q_ptr->setTheme(QChart::ChartThemeLight);
804 q_ptr->setTheme(QChart::ChartThemeLight);
802 q_ptr->setLayout(m_presenter->layout());
805 q_ptr->setLayout(m_presenter->layout());
803 }
806 }
804
807
805 void QChartPrivate::zoomIn(qreal factor)
808 void QChartPrivate::zoomIn(qreal factor)
806 {
809 {
807 QRectF rect = m_presenter->geometry();
810 QRectF rect = m_presenter->geometry();
808 rect.setWidth(rect.width() / factor);
811 rect.setWidth(rect.width() / factor);
809 rect.setHeight(rect.height() / factor);
812 rect.setHeight(rect.height() / factor);
810 rect.moveCenter(m_presenter->geometry().center());
813 rect.moveCenter(m_presenter->geometry().center());
811 zoomIn(rect);
814 zoomIn(rect);
812 }
815 }
813
816
814 void QChartPrivate::zoomIn(const QRectF &rect)
817 void QChartPrivate::zoomIn(const QRectF &rect)
815 {
818 {
816 if (!rect.isValid())
819 if (!rect.isValid())
817 return;
820 return;
818
821
819 QRectF r = rect.normalized();
822 QRectF r = rect.normalized();
820 const QRectF geometry = m_presenter->geometry();
823 const QRectF geometry = m_presenter->geometry();
821 r.translate(-geometry.topLeft());
824 r.translate(-geometry.topLeft());
822
825
823 if (!r.isValid())
826 if (!r.isValid())
824 return;
827 return;
825
828
826 QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height());
829 QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height());
827 m_presenter->setState(ChartPresenter::ZoomInState,zoomPoint);
830 m_presenter->setState(ChartPresenter::ZoomInState,zoomPoint);
828 m_dataset->zoomInDomain(r);
831 m_dataset->zoomInDomain(r);
829 m_presenter->setState(ChartPresenter::ShowState,QPointF());
832 m_presenter->setState(ChartPresenter::ShowState,QPointF());
830
833
831 }
834 }
832
835
833 void QChartPrivate::zoomReset()
836 void QChartPrivate::zoomReset()
834 {
837 {
835 m_dataset->zoomResetDomain();
838 m_dataset->zoomResetDomain();
836 }
839 }
837
840
838 bool QChartPrivate::isZoomed()
841 bool QChartPrivate::isZoomed()
839 {
842 {
840 return m_dataset->isZoomedDomain();
843 return m_dataset->isZoomedDomain();
841 }
844 }
842
845
843 void QChartPrivate::zoomOut(qreal factor)
846 void QChartPrivate::zoomOut(qreal factor)
844 {
847 {
845 const QRectF geometry = m_presenter->geometry();
848 const QRectF geometry = m_presenter->geometry();
846
849
847 QRectF r;
850 QRectF r;
848 r.setSize(geometry.size() / factor);
851 r.setSize(geometry.size() / factor);
849 r.moveCenter(QPointF(geometry.size().width()/2 ,geometry.size().height()/2));
852 r.moveCenter(QPointF(geometry.size().width()/2 ,geometry.size().height()/2));
850 if (!r.isValid())
853 if (!r.isValid())
851 return;
854 return;
852
855
853 QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height());
856 QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height());
854 m_presenter->setState(ChartPresenter::ZoomOutState,zoomPoint);
857 m_presenter->setState(ChartPresenter::ZoomOutState,zoomPoint);
855 m_dataset->zoomOutDomain(r);
858 m_dataset->zoomOutDomain(r);
856 m_presenter->setState(ChartPresenter::ShowState,QPointF());
859 m_presenter->setState(ChartPresenter::ShowState,QPointF());
857 }
860 }
858
861
859 void QChartPrivate::scroll(qreal dx, qreal dy)
862 void QChartPrivate::scroll(qreal dx, qreal dy)
860 {
863 {
861 if (dx < 0) m_presenter->setState(ChartPresenter::ScrollLeftState,QPointF());
864 if (dx < 0) m_presenter->setState(ChartPresenter::ScrollLeftState,QPointF());
862 if (dx > 0) m_presenter->setState(ChartPresenter::ScrollRightState,QPointF());
865 if (dx > 0) m_presenter->setState(ChartPresenter::ScrollRightState,QPointF());
863 if (dy < 0) m_presenter->setState(ChartPresenter::ScrollUpState,QPointF());
866 if (dy < 0) m_presenter->setState(ChartPresenter::ScrollUpState,QPointF());
864 if (dy > 0) m_presenter->setState(ChartPresenter::ScrollDownState,QPointF());
867 if (dy > 0) m_presenter->setState(ChartPresenter::ScrollDownState,QPointF());
865
868
866 m_dataset->scrollDomain(dx, dy);
869 m_dataset->scrollDomain(dx, dy);
867 m_presenter->setState(ChartPresenter::ShowState,QPointF());
870 m_presenter->setState(ChartPresenter::ShowState,QPointF());
868 }
871 }
869
872
870 #include "moc_qchart.cpp"
873 #include "moc_qchart.cpp"
871
874
872 QT_CHARTS_END_NAMESPACE
875 QT_CHARTS_END_NAMESPACE
@@ -1,183 +1,187
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2014 Digia Plc
3 ** Copyright (C) 2014 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 Enterprise Charts Add-on.
7 ** This file is part of the Qt Enterprise Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
11 ** accordance with the Qt Enterprise License Agreement provided with the
11 ** accordance with the Qt Enterprise 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 <QtCharts/QAbstractSeries>
24 #include <QtCharts/QAbstractSeries>
25 #include <QtCharts/QLegend>
25 #include <QtCharts/QLegend>
26 #include <QtWidgets/QGraphicsWidget>
26 #include <QtWidgets/QGraphicsWidget>
27 #include <QtCore/QMargins>
27 #include <QtCore/QMargins>
28
28
29 class QGraphicsSceneResizeEvent;
29 class QGraphicsSceneResizeEvent;
30
30
31 QT_CHARTS_BEGIN_NAMESPACE
31 QT_CHARTS_BEGIN_NAMESPACE
32
32
33 class QAbstractSeries;
33 class QAbstractSeries;
34 class QAbstractAxis;
34 class QAbstractAxis;
35 class QLegend;
35 class QLegend;
36 class QChartPrivate;
36 class QChartPrivate;
37 class QBoxPlotSeries;
37 class QBoxPlotSeries;
38
38
39 class QT_CHARTS_EXPORT QChart : public QGraphicsWidget
39 class QT_CHARTS_EXPORT QChart : public QGraphicsWidget
40 {
40 {
41 Q_OBJECT
41 Q_OBJECT
42 Q_PROPERTY(QChart::ChartTheme theme READ theme WRITE setTheme)
42 Q_PROPERTY(QChart::ChartTheme theme READ theme WRITE setTheme)
43 Q_PROPERTY(QString title READ title WRITE setTitle)
43 Q_PROPERTY(QString title READ title WRITE setTitle)
44 Q_PROPERTY(bool backgroundVisible READ isBackgroundVisible WRITE setBackgroundVisible)
44 Q_PROPERTY(bool backgroundVisible READ isBackgroundVisible WRITE setBackgroundVisible)
45 Q_PROPERTY(bool dropShadowEnabled READ isDropShadowEnabled WRITE setDropShadowEnabled)
45 Q_PROPERTY(bool dropShadowEnabled READ isDropShadowEnabled WRITE setDropShadowEnabled)
46 Q_PROPERTY(qreal backgroundRoundness READ backgroundRoundness WRITE setBackgroundRoundness)
46 Q_PROPERTY(qreal backgroundRoundness READ backgroundRoundness WRITE setBackgroundRoundness)
47 Q_PROPERTY(QChart::AnimationOptions animationOptions READ animationOptions WRITE setAnimationOptions)
47 Q_PROPERTY(QChart::AnimationOptions animationOptions READ animationOptions WRITE setAnimationOptions)
48 Q_PROPERTY(QMargins minimumMargins READ minimumMargins WRITE setMinimumMargins)
48 Q_PROPERTY(QMargins minimumMargins READ minimumMargins WRITE setMinimumMargins)
49 Q_PROPERTY(QMargins margins READ margins WRITE setMargins)
49 Q_PROPERTY(QMargins margins READ margins WRITE setMargins)
50 Q_PROPERTY(QChart::ChartType chartType READ chartType)
50 Q_PROPERTY(QChart::ChartType chartType READ chartType)
51 Q_PROPERTY(bool plotAreaBackgroundVisible READ isPlotAreaBackgroundVisible WRITE setPlotAreaBackgroundVisible)
51 Q_PROPERTY(bool plotAreaBackgroundVisible READ isPlotAreaBackgroundVisible WRITE setPlotAreaBackgroundVisible)
52 Q_PROPERTY(bool localizeNumbers READ localizeNumbers WRITE setLocalizeNumbers)
52 Q_PROPERTY(bool localizeNumbers READ localizeNumbers WRITE setLocalizeNumbers)
53 Q_PROPERTY(QLocale locale READ locale WRITE setLocale)
53 Q_PROPERTY(QLocale locale READ locale WRITE setLocale)
54 Q_PROPERTY(QRectF plotArea READ plotArea NOTIFY plotAreaChanged)
54 Q_ENUMS(ChartTheme)
55 Q_ENUMS(ChartTheme)
55 Q_ENUMS(AnimationOption)
56 Q_ENUMS(AnimationOption)
56 Q_ENUMS(ChartType)
57 Q_ENUMS(ChartType)
57
58
58 public:
59 public:
59 enum ChartType {
60 enum ChartType {
60 ChartTypeUndefined = 0,
61 ChartTypeUndefined = 0,
61 ChartTypeCartesian,
62 ChartTypeCartesian,
62 ChartTypePolar
63 ChartTypePolar
63 };
64 };
64
65
65 enum ChartTheme {
66 enum ChartTheme {
66 ChartThemeLight = 0,
67 ChartThemeLight = 0,
67 ChartThemeBlueCerulean,
68 ChartThemeBlueCerulean,
68 ChartThemeDark,
69 ChartThemeDark,
69 ChartThemeBrownSand,
70 ChartThemeBrownSand,
70 ChartThemeBlueNcs,
71 ChartThemeBlueNcs,
71 ChartThemeHighContrast,
72 ChartThemeHighContrast,
72 ChartThemeBlueIcy,
73 ChartThemeBlueIcy,
73 ChartThemeQt
74 ChartThemeQt
74 };
75 };
75
76
76 enum AnimationOption {
77 enum AnimationOption {
77 NoAnimation = 0x0,
78 NoAnimation = 0x0,
78 GridAxisAnimations = 0x1,
79 GridAxisAnimations = 0x1,
79 SeriesAnimations = 0x2,
80 SeriesAnimations = 0x2,
80 AllAnimations = 0x3
81 AllAnimations = 0x3
81 };
82 };
82
83
83 Q_DECLARE_FLAGS(AnimationOptions, AnimationOption)
84 Q_DECLARE_FLAGS(AnimationOptions, AnimationOption)
84
85
85 public:
86 public:
86 explicit QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
87 explicit QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
87 ~QChart();
88 ~QChart();
88
89
89 void addSeries(QAbstractSeries *series);
90 void addSeries(QAbstractSeries *series);
90 void removeSeries(QAbstractSeries *series);
91 void removeSeries(QAbstractSeries *series);
91 void removeAllSeries();
92 void removeAllSeries();
92 QList<QAbstractSeries *> series() const;
93 QList<QAbstractSeries *> series() const;
93
94
94 // *** deprecated ***
95 // *** deprecated ***
95 void setAxisX(QAbstractAxis *axis, QAbstractSeries *series = 0);
96 void setAxisX(QAbstractAxis *axis, QAbstractSeries *series = 0);
96 void setAxisY(QAbstractAxis *axis, QAbstractSeries *series = 0);
97 void setAxisY(QAbstractAxis *axis, QAbstractSeries *series = 0);
97 QAbstractAxis *axisX(QAbstractSeries *series = 0) const;
98 QAbstractAxis *axisX(QAbstractSeries *series = 0) const;
98 QAbstractAxis *axisY(QAbstractSeries *series = 0) const;
99 QAbstractAxis *axisY(QAbstractSeries *series = 0) const;
99 // ******************
100 // ******************
100
101
101 void addAxis(QAbstractAxis *axis, Qt::Alignment alignment);
102 void addAxis(QAbstractAxis *axis, Qt::Alignment alignment);
102 void removeAxis(QAbstractAxis *axis);
103 void removeAxis(QAbstractAxis *axis);
103 QList<QAbstractAxis*> axes(Qt::Orientations orientation = Qt::Horizontal|Qt::Vertical, QAbstractSeries *series = 0) const;
104 QList<QAbstractAxis*> axes(Qt::Orientations orientation = Qt::Horizontal|Qt::Vertical, QAbstractSeries *series = 0) const;
104
105
105 void createDefaultAxes();
106 void createDefaultAxes();
106
107
107 void setTheme(QChart::ChartTheme theme);
108 void setTheme(QChart::ChartTheme theme);
108 QChart::ChartTheme theme() const;
109 QChart::ChartTheme theme() const;
109
110
110 void setTitle(const QString &title);
111 void setTitle(const QString &title);
111 QString title() const;
112 QString title() const;
112 void setTitleFont(const QFont &font);
113 void setTitleFont(const QFont &font);
113 QFont titleFont() const;
114 QFont titleFont() const;
114 void setTitleBrush(const QBrush &brush);
115 void setTitleBrush(const QBrush &brush);
115 QBrush titleBrush() const;
116 QBrush titleBrush() const;
116
117
117 void setBackgroundBrush(const QBrush &brush);
118 void setBackgroundBrush(const QBrush &brush);
118 QBrush backgroundBrush() const;
119 QBrush backgroundBrush() const;
119 void setBackgroundPen(const QPen &pen);
120 void setBackgroundPen(const QPen &pen);
120 QPen backgroundPen() const;
121 QPen backgroundPen() const;
121 void setBackgroundVisible(bool visible = true);
122 void setBackgroundVisible(bool visible = true);
122 bool isBackgroundVisible() const;
123 bool isBackgroundVisible() const;
123
124
124 void setDropShadowEnabled(bool enabled = true);
125 void setDropShadowEnabled(bool enabled = true);
125 bool isDropShadowEnabled() const;
126 bool isDropShadowEnabled() const;
126 void setBackgroundRoundness(qreal diameter);
127 void setBackgroundRoundness(qreal diameter);
127 qreal backgroundRoundness() const;
128 qreal backgroundRoundness() const;
128 void setAnimationOptions(AnimationOptions options);
129 void setAnimationOptions(AnimationOptions options);
129 AnimationOptions animationOptions() const;
130 AnimationOptions animationOptions() const;
130
131
131 void zoomIn();
132 void zoomIn();
132 void zoomOut();
133 void zoomOut();
133
134
134 void zoomIn(const QRectF &rect);
135 void zoomIn(const QRectF &rect);
135 void zoom(qreal factor);
136 void zoom(qreal factor);
136 void zoomReset();
137 void zoomReset();
137 bool isZoomed();
138 bool isZoomed();
138
139
139 void scroll(qreal dx, qreal dy);
140 void scroll(qreal dx, qreal dy);
140
141
141 QLegend *legend() const;
142 QLegend *legend() const;
142
143
143 void setMinimumMargins(const QMargins& margins);
144 void setMinimumMargins(const QMargins& margins);
144 QMargins minimumMargins() const;
145 QMargins minimumMargins() const;
145
146
146 void setMargins(const QMargins &margins);
147 void setMargins(const QMargins &margins);
147 QMargins margins() const;
148 QMargins margins() const;
148
149
149 QRectF plotArea() const;
150 QRectF plotArea() const;
150 void setPlotAreaBackgroundBrush(const QBrush &brush);
151 void setPlotAreaBackgroundBrush(const QBrush &brush);
151 QBrush plotAreaBackgroundBrush() const;
152 QBrush plotAreaBackgroundBrush() const;
152 void setPlotAreaBackgroundPen(const QPen &pen);
153 void setPlotAreaBackgroundPen(const QPen &pen);
153 QPen plotAreaBackgroundPen() const;
154 QPen plotAreaBackgroundPen() const;
154 void setPlotAreaBackgroundVisible(bool visible = true);
155 void setPlotAreaBackgroundVisible(bool visible = true);
155 bool isPlotAreaBackgroundVisible() const;
156 bool isPlotAreaBackgroundVisible() const;
156 void setLocalizeNumbers(bool localize);
157 void setLocalizeNumbers(bool localize);
157 bool localizeNumbers() const;
158 bool localizeNumbers() const;
158 void setLocale(const QLocale &locale);
159 void setLocale(const QLocale &locale);
159 QLocale locale() const;
160 QLocale locale() const;
160
161
161 QPointF mapToValue(const QPointF &position, QAbstractSeries *series = 0);
162 QPointF mapToValue(const QPointF &position, QAbstractSeries *series = 0);
162 QPointF mapToPosition(const QPointF &value, QAbstractSeries *series = 0);
163 QPointF mapToPosition(const QPointF &value, QAbstractSeries *series = 0);
163
164
164 ChartType chartType() const;
165 ChartType chartType() const;
165
166
167 signals:
168 void plotAreaChanged(const QRectF &plotArea);
169
166 protected:
170 protected:
167 explicit QChart(QChart::ChartType type, QGraphicsItem *parent, Qt::WindowFlags wFlags);
171 explicit QChart(QChart::ChartType type, QGraphicsItem *parent, Qt::WindowFlags wFlags);
168 QScopedPointer<QChartPrivate> d_ptr;
172 QScopedPointer<QChartPrivate> d_ptr;
169 friend class QLegend;
173 friend class QLegend;
170 friend class DeclarativeChart;
174 friend class DeclarativeChart;
171 friend class ChartDataSet;
175 friend class ChartDataSet;
172 friend class ChartPresenter;
176 friend class ChartPresenter;
173 friend class ChartThemeManager;
177 friend class ChartThemeManager;
174 friend class QAbstractSeries;
178 friend class QAbstractSeries;
175 friend class QBoxPlotSeriesPrivate;
179 friend class QBoxPlotSeriesPrivate;
176 Q_DISABLE_COPY(QChart)
180 Q_DISABLE_COPY(QChart)
177 };
181 };
178
182
179 QT_CHARTS_END_NAMESPACE
183 QT_CHARTS_END_NAMESPACE
180
184
181 Q_DECLARE_OPERATORS_FOR_FLAGS(QT_CHARTS_NAMESPACE::QChart::AnimationOptions)
185 Q_DECLARE_OPERATORS_FOR_FLAGS(QT_CHARTS_NAMESPACE::QChart::AnimationOptions)
182
186
183 #endif // QCHART_H
187 #endif // QCHART_H
@@ -1,1063 +1,1051
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2014 Digia Plc
3 ** Copyright (C) 2014 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 Enterprise Charts Add-on.
7 ** This file is part of the Qt Enterprise Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
11 ** accordance with the Qt Enterprise License Agreement provided with the
11 ** accordance with the Qt Enterprise 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 "declarativechart.h"
21 #include "declarativechart.h"
22 #include <QtGui/QPainter>
22 #include <QtGui/QPainter>
23 #include "declarativelineseries.h"
23 #include "declarativelineseries.h"
24 #include "declarativeareaseries.h"
24 #include "declarativeareaseries.h"
25 #include "declarativebarseries.h"
25 #include "declarativebarseries.h"
26 #include "declarativepieseries.h"
26 #include "declarativepieseries.h"
27 #include "declarativesplineseries.h"
27 #include "declarativesplineseries.h"
28 #include "declarativeboxplotseries.h"
28 #include "declarativeboxplotseries.h"
29 #include "declarativescatterseries.h"
29 #include "declarativescatterseries.h"
30 #include <QtCharts/QBarCategoryAxis>
30 #include <QtCharts/QBarCategoryAxis>
31 #include <QtCharts/QValueAxis>
31 #include <QtCharts/QValueAxis>
32 #include <QtCharts/QLogValueAxis>
32 #include <QtCharts/QLogValueAxis>
33 #include <QtCharts/QCategoryAxis>
33 #include <QtCharts/QCategoryAxis>
34 #include <private/qabstractseries_p.h>
34 #include <private/qabstractseries_p.h>
35 #include "declarativemargins.h"
35 #include "declarativemargins.h"
36 #include <private/chartdataset_p.h>
36 #include <private/chartdataset_p.h>
37 #include "declarativeaxes.h"
37 #include "declarativeaxes.h"
38 #include <private/qchart_p.h>
38 #include <private/qchart_p.h>
39 #include <QtCharts/QPolarChart>
39 #include <QtCharts/QPolarChart>
40
40
41 #ifndef QT_ON_ARM
41 #ifndef QT_ON_ARM
42 #include <QtCharts/QDateTimeAxis>
42 #include <QtCharts/QDateTimeAxis>
43 #endif
43 #endif
44
44
45 #include <QtWidgets/QGraphicsSceneMouseEvent>
45 #include <QtWidgets/QGraphicsSceneMouseEvent>
46 #include <QtWidgets/QGraphicsSceneHoverEvent>
46 #include <QtWidgets/QGraphicsSceneHoverEvent>
47 #include <QtWidgets/QApplication>
47 #include <QtWidgets/QApplication>
48 #include <QtCore/QTimer>
48 #include <QtCore/QTimer>
49 #include <QtCore/QThread>
49 #include <QtCore/QThread>
50
50
51 QT_CHARTS_BEGIN_NAMESPACE
51 QT_CHARTS_BEGIN_NAMESPACE
52
52
53 /*!
53 /*!
54 \qmltype ChartView
54 \qmltype ChartView
55 \instantiates DeclarativeChart
55 \instantiates DeclarativeChart
56 \inqmlmodule QtCharts
56 \inqmlmodule QtCharts
57
57
58 ChartView element is the parent that is responsible for showing different chart series types.
58 ChartView element is the parent that is responsible for showing different chart series types.
59
59
60 The following QML shows how to create a simple chart with one pie series:
60 The following QML shows how to create a simple chart with one pie series:
61 \snippet qmlpiechart/qml/qmlpiechart/main.qml 1
61 \snippet qmlpiechart/qml/qmlpiechart/main.qml 1
62 \snippet qmlpiechart/qml/qmlpiechart/main.qml 2
62 \snippet qmlpiechart/qml/qmlpiechart/main.qml 2
63 \snippet qmlpiechart/qml/qmlpiechart/main.qml 3
63 \snippet qmlpiechart/qml/qmlpiechart/main.qml 3
64
64
65 \beginfloatleft
65 \beginfloatleft
66 \image examples_qmlpiechart.png
66 \image examples_qmlpiechart.png
67 \endfloat
67 \endfloat
68 \clearfloat
68 \clearfloat
69 */
69 */
70
70
71 /*!
71 /*!
72 \qmlproperty Theme ChartView::theme
72 \qmlproperty Theme ChartView::theme
73 Theme defines the visual appearance of the chart, including for example colors, fonts, line
73 Theme defines the visual appearance of the chart, including for example colors, fonts, line
74 widths and chart background.
74 widths and chart background.
75 */
75 */
76
76
77 /*!
77 /*!
78 \qmlproperty Animation ChartView::animationOptions
78 \qmlproperty Animation ChartView::animationOptions
79 Animation configuration of the chart. One of ChartView.NoAnimation, ChartView.GridAxisAnimations,
79 Animation configuration of the chart. One of ChartView.NoAnimation, ChartView.GridAxisAnimations,
80 ChartView.SeriesAnimations or ChartView.AllAnimations.
80 ChartView.SeriesAnimations or ChartView.AllAnimations.
81 */
81 */
82
82
83 /*!
83 /*!
84 \qmlproperty Font ChartView::titleFont
84 \qmlproperty Font ChartView::titleFont
85 The title font of the chart.
85 The title font of the chart.
86
86
87 See the Qt documentation for more details of Font.
87 See the Qt documentation for more details of Font.
88 */
88 */
89
89
90 /*!
90 /*!
91 \qmlproperty string ChartView::title
91 \qmlproperty string ChartView::title
92 The title of the chart, shown on top of the chart.
92 The title of the chart, shown on top of the chart.
93 \sa ChartView::titleColor
93 \sa ChartView::titleColor
94 */
94 */
95
95
96 /*!
96 /*!
97 \qmlproperty color ChartView::titleColor
97 \qmlproperty color ChartView::titleColor
98 The color of the title text.
98 The color of the title text.
99 */
99 */
100
100
101 /*!
101 /*!
102 \qmlproperty Legend ChartView::legend
102 \qmlproperty Legend ChartView::legend
103 The legend of the chart. Legend lists all the series, pie slices and bar sets added on the chart.
103 The legend of the chart. Legend lists all the series, pie slices and bar sets added on the chart.
104 */
104 */
105
105
106 /*!
106 /*!
107 \qmlproperty int ChartView::count
107 \qmlproperty int ChartView::count
108 The count of series added to the chart.
108 The count of series added to the chart.
109 */
109 */
110
110
111 /*!
111 /*!
112 \qmlproperty color ChartView::backgroundColor
112 \qmlproperty color ChartView::backgroundColor
113 The color of the chart's background. By default background color is defined by chart theme.
113 The color of the chart's background. By default background color is defined by chart theme.
114 \sa ChartView::theme
114 \sa ChartView::theme
115 */
115 */
116
116
117 /*!
117 /*!
118 \qmlproperty real ChartView::backgroundRoundness
118 \qmlproperty real ChartView::backgroundRoundness
119 The diameter of the rounding cirle at the corners of the chart background.
119 The diameter of the rounding cirle at the corners of the chart background.
120 */
120 */
121
121
122 /*!
122 /*!
123 \qmlproperty color ChartView::plotAreaColor
123 \qmlproperty color ChartView::plotAreaColor
124 The color of the background of the chart's plot area. By default plot area background uses chart's
124 The color of the background of the chart's plot area. By default plot area background uses chart's
125 background color.
125 background color.
126 \sa ChartView::backgroundColor
126 \sa ChartView::backgroundColor
127 */
127 */
128
128
129 /*!
129 /*!
130 \qmlproperty bool ChartView::dropShadowEnabled
130 \qmlproperty bool ChartView::dropShadowEnabled
131 The chart's border drop shadow. Set to true to enable drop shadow.
131 The chart's border drop shadow. Set to true to enable drop shadow.
132 */
132 */
133
133
134 /*!
134 /*!
135 \qmlproperty real ChartView::topMargin
135 \qmlproperty real ChartView::topMargin
136 Deprecated; use margins instead.
136 Deprecated; use margins instead.
137 */
137 */
138
138
139 /*!
139 /*!
140 \qmlproperty real ChartView::bottomMargin
140 \qmlproperty real ChartView::bottomMargin
141 Deprecated; use margins instead.
141 Deprecated; use margins instead.
142 */
142 */
143
143
144 /*!
144 /*!
145 \qmlproperty real ChartView::leftMargin
145 \qmlproperty real ChartView::leftMargin
146 Deprecated; use margins instead.
146 Deprecated; use margins instead.
147 */
147 */
148
148
149 /*!
149 /*!
150 \qmlproperty real ChartView::rightMargin
150 \qmlproperty real ChartView::rightMargin
151 Deprecated; use margins instead.
151 Deprecated; use margins instead.
152 */
152 */
153
153
154 /*!
154 /*!
155 \qmlproperty Margins ChartView::minimumMargins
155 \qmlproperty Margins ChartView::minimumMargins
156 Deprecated; use margins instead.
156 Deprecated; use margins instead.
157 The minimum margins allowed between the outer bounds and the plotArea of the ChartView. Margins
157 The minimum margins allowed between the outer bounds and the plotArea of the ChartView. Margins
158 area of ChartView is used for drawing title, axes and legend. Please note that setting the
158 area of ChartView is used for drawing title, axes and legend. Please note that setting the
159 properties of minimumMargins may be bigger than the defined value, depending on other ChartView
159 properties of minimumMargins may be bigger than the defined value, depending on other ChartView
160 properties that affect it's layout. If you need to know the actual plotting area used at any
160 properties that affect it's layout. If you need to know the actual plotting area used at any
161 given time, you can check ChartView::plotArea instead.
161 given time, you can check ChartView::plotArea instead.
162 */
162 */
163
163
164 /*!
164 /*!
165 \qmlproperty rect ChartView::plotArea
165 \qmlproperty rect ChartView::plotArea
166 The area on the ChartView that is used for drawing series. This is the ChartView rect without the
166 The area on the ChartView that is used for drawing series. This is the ChartView rect without the
167 margins.
167 margins.
168 \sa ChartView::minimumMargins
168 \sa ChartView::minimumMargins
169 */
169 */
170
170
171 /*!
171 /*!
172 \qmlproperty Margins ChartView::margins
172 \qmlproperty Margins ChartView::margins
173 The minimum margins allowed between the outer bounds and the plotArea of the ChartView. Margins
173 The minimum margins allowed between the outer bounds and the plotArea of the ChartView. Margins
174 area of ChartView is used for drawing title, axes and legend.
174 area of ChartView is used for drawing title, axes and legend.
175 */
175 */
176
176
177 /*!
177 /*!
178 \qmlproperty bool ChartView::localizeNumbers
178 \qmlproperty bool ChartView::localizeNumbers
179 \since QtCharts 2.0
179 \since QtCharts 2.0
180 When \c{true}, all generated numbers appearing in various series and axis labels will be
180 When \c{true}, all generated numbers appearing in various series and axis labels will be
181 localized using the default QLocale of the application, which defaults to the system locale.
181 localized using the default QLocale of the application, which defaults to the system locale.
182 When \c{false}, the "C" locale is always used.
182 When \c{false}, the "C" locale is always used.
183 Defaults to \c{false}.
183 Defaults to \c{false}.
184
184
185 \sa locale
185 \sa locale
186 */
186 */
187
187
188 /*!
188 /*!
189 \qmlproperty locale ChartView::locale
189 \qmlproperty locale ChartView::locale
190 \since QtCharts 2.0
190 \since QtCharts 2.0
191 Sets the locale used to format various chart labels when localizeNumbers is \c{true}.
191 Sets the locale used to format various chart labels when localizeNumbers is \c{true}.
192 This also determines the locale used to format DateTimeAxis labels regardless of
192 This also determines the locale used to format DateTimeAxis labels regardless of
193 localizeNumbers property.
193 localizeNumbers property.
194 Defaults to application default locale at the time the chart is constructed.
194 Defaults to application default locale at the time the chart is constructed.
195
195
196 \sa localizeNumbers
196 \sa localizeNumbers
197 */
197 */
198
198
199 /*!
199 /*!
200 \qmlmethod AbstractSeries ChartView::series(int index)
200 \qmlmethod AbstractSeries ChartView::series(int index)
201 Returns the series with \a index on the chart. This allows you to loop through the series of a chart together with
201 Returns the series with \a index on the chart. This allows you to loop through the series of a chart together with
202 the count property of the chart.
202 the count property of the chart.
203 */
203 */
204
204
205 /*!
205 /*!
206 \qmlmethod AbstractSeries ChartView::series(string name)
206 \qmlmethod AbstractSeries ChartView::series(string name)
207 Returns the first series on the chart with \a name. If there is no series with that name, returns null.
207 Returns the first series on the chart with \a name. If there is no series with that name, returns null.
208 */
208 */
209
209
210 /*!
210 /*!
211 \qmlmethod AbstractSeries ChartView::createSeries(SeriesType type, string name, AbstractAxis axisX, AbstractAxis axisY)
211 \qmlmethod AbstractSeries ChartView::createSeries(SeriesType type, string name, AbstractAxis axisX, AbstractAxis axisY)
212 Creates a series object of \a type to the chart with name \a name, optional axis \a axisX and
212 Creates a series object of \a type to the chart with name \a name, optional axis \a axisX and
213 optional axis \a axisY. For example:
213 optional axis \a axisY. For example:
214 \code
214 \code
215 // lineSeries is a LineSeries object that has already been added to the ChartView; re-use it's axes
215 // lineSeries is a LineSeries object that has already been added to the ChartView; re-use it's axes
216 var myAxisX = chartView.axisX(lineSeries);
216 var myAxisX = chartView.axisX(lineSeries);
217 var myAxisY = chartView.axisY(lineSeries);
217 var myAxisY = chartView.axisY(lineSeries);
218 var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter series", myAxisX, myAxisY);
218 var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter series", myAxisX, myAxisY);
219 \endcode
219 \endcode
220 */
220 */
221
221
222 /*!
222 /*!
223 \qmlmethod ChartView::removeSeries(AbstractSeries series)
223 \qmlmethod ChartView::removeSeries(AbstractSeries series)
224 Removes the \a series from the chart. The series object is also destroyed.
224 Removes the \a series from the chart. The series object is also destroyed.
225 */
225 */
226
226
227 /*!
227 /*!
228 \qmlmethod ChartView::removeAllSeries()
228 \qmlmethod ChartView::removeAllSeries()
229 Removes all series from the chart. All the series objects are also destroyed.
229 Removes all series from the chart. All the series objects are also destroyed.
230 */
230 */
231
231
232 /*!
232 /*!
233 \qmlmethod Axis ChartView::axisX(AbstractSeries series)
233 \qmlmethod Axis ChartView::axisX(AbstractSeries series)
234 The x-axis of the series.
234 The x-axis of the series.
235 */
235 */
236
236
237 /*!
237 /*!
238 \qmlmethod Axis ChartView::axisY(AbstractSeries series)
238 \qmlmethod Axis ChartView::axisY(AbstractSeries series)
239 The y-axis of the series.
239 The y-axis of the series.
240 */
240 */
241
241
242 /*!
242 /*!
243 \qmlmethod ChartView::zoomY(real factor)
243 \qmlmethod ChartView::zoomY(real factor)
244 Zooms in by \a factor on the center of the chart.
244 Zooms in by \a factor on the center of the chart.
245 */
245 */
246
246
247 /*!
247 /*!
248 \qmlmethod ChartView::scrollLeft(real pixels)
248 \qmlmethod ChartView::scrollLeft(real pixels)
249 Scrolls to left by \a pixels. This is a convenience function that suits for example for key navigation.
249 Scrolls to left by \a pixels. This is a convenience function that suits for example for key navigation.
250 */
250 */
251
251
252 /*!
252 /*!
253 \qmlmethod ChartView::scrollRight(real pixels)
253 \qmlmethod ChartView::scrollRight(real pixels)
254 Scrolls to right by \a pixels. This is a convenience function that suits for example for key navigation.
254 Scrolls to right by \a pixels. This is a convenience function that suits for example for key navigation.
255 */
255 */
256
256
257 /*!
257 /*!
258 \qmlmethod ChartView::scrollUp(real pixels)
258 \qmlmethod ChartView::scrollUp(real pixels)
259 Scrolls up by \a pixels. This is a convenience function that suits for example for key navigation.
259 Scrolls up by \a pixels. This is a convenience function that suits for example for key navigation.
260 */
260 */
261
261
262 /*!
262 /*!
263 \qmlmethod ChartView::scrollDown(real pixels)
263 \qmlmethod ChartView::scrollDown(real pixels)
264 Scrolls down by \a pixels. This is a convenience function that suits for example for key navigation.
264 Scrolls down by \a pixels. This is a convenience function that suits for example for key navigation.
265 */
265 */
266
266
267 /*!
267 /*!
268 \qmlsignal ChartView::onPlotAreaChanged(rect plotArea)
269 The plot area of the chart has changed. This may happen for example, if you modify minimumMargins
270 or if you resize the chart, or if you modify font size related properties of the legend or chart
271 title.
272 */
273
274 /*!
275 \qmlsignal ChartView::seriesAdded(AbstractSeries series)
268 \qmlsignal ChartView::seriesAdded(AbstractSeries series)
276 The \a series has been added to the chart.
269 The \a series has been added to the chart.
277 */
270 */
278
271
279 /*!
272 /*!
280 \qmlsignal ChartView::seriesRemoved(AbstractSeries series)
273 \qmlsignal ChartView::seriesRemoved(AbstractSeries series)
281 The \a series has been removed from the chart. Please note that \a series is no longer a valid
274 The \a series has been removed from the chart. Please note that \a series is no longer a valid
282 object after the signal handler has completed.
275 object after the signal handler has completed.
283 */
276 */
284
277
285 DeclarativeChart::DeclarativeChart(QQuickItem *parent)
278 DeclarativeChart::DeclarativeChart(QQuickItem *parent)
286 : QQuickPaintedItem(parent)
279 : QQuickPaintedItem(parent)
287 {
280 {
288 initChart(QChart::ChartTypeCartesian);
281 initChart(QChart::ChartTypeCartesian);
289 }
282 }
290
283
291 DeclarativeChart::DeclarativeChart(QChart::ChartType type, QQuickItem *parent)
284 DeclarativeChart::DeclarativeChart(QChart::ChartType type, QQuickItem *parent)
292 : QQuickPaintedItem(parent)
285 : QQuickPaintedItem(parent)
293 {
286 {
294 initChart(type);
287 initChart(type);
295 }
288 }
296
289
297 void DeclarativeChart::initChart(QChart::ChartType type)
290 void DeclarativeChart::initChart(QChart::ChartType type)
298 {
291 {
299 m_currentSceneImage = 0;
292 m_currentSceneImage = 0;
300 m_guiThreadId = QThread::currentThreadId();
293 m_guiThreadId = QThread::currentThreadId();
301 m_paintThreadId = 0;
294 m_paintThreadId = 0;
302 m_updatePending = false;
295 m_updatePending = false;
303
296
304 if (type == QChart::ChartTypePolar)
297 if (type == QChart::ChartTypePolar)
305 m_chart = new QPolarChart();
298 m_chart = new QPolarChart();
306 else
299 else
307 m_chart = new QChart();
300 m_chart = new QChart();
308
301
309 m_scene = new QGraphicsScene(this);
302 m_scene = new QGraphicsScene(this);
310 m_scene->addItem(m_chart);
303 m_scene->addItem(m_chart);
311
304
312 setAntialiasing(QQuickItem::antialiasing());
305 setAntialiasing(QQuickItem::antialiasing());
313 connect(m_scene, SIGNAL(changed(QList<QRectF>)), this, SLOT(sceneChanged(QList<QRectF>)));
306 connect(m_scene, SIGNAL(changed(QList<QRectF>)), this, SLOT(sceneChanged(QList<QRectF>)));
314 connect(this, SIGNAL(antialiasingChanged(bool)), this, SLOT(handleAntialiasingChanged(bool)));
307 connect(this, SIGNAL(antialiasingChanged(bool)), this, SLOT(handleAntialiasingChanged(bool)));
315
308
316 setAcceptedMouseButtons(Qt::AllButtons);
309 setAcceptedMouseButtons(Qt::AllButtons);
317 setAcceptHoverEvents(true);
310 setAcceptHoverEvents(true);
318
311
319 m_margins = new DeclarativeMargins(this);
312 m_margins = new DeclarativeMargins(this);
320 m_margins->setTop(m_chart->margins().top());
313 m_margins->setTop(m_chart->margins().top());
321 m_margins->setLeft(m_chart->margins().left());
314 m_margins->setLeft(m_chart->margins().left());
322 m_margins->setRight(m_chart->margins().right());
315 m_margins->setRight(m_chart->margins().right());
323 m_margins->setBottom(m_chart->margins().bottom());
316 m_margins->setBottom(m_chart->margins().bottom());
324 connect(m_margins, SIGNAL(topChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int)));
317 connect(m_margins, SIGNAL(topChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int)));
325 connect(m_margins, SIGNAL(bottomChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int)));
318 connect(m_margins, SIGNAL(bottomChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int)));
326 connect(m_margins, SIGNAL(leftChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int)));
319 connect(m_margins, SIGNAL(leftChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int)));
327 connect(m_margins, SIGNAL(rightChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int)));
320 connect(m_margins, SIGNAL(rightChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int)));
328 connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), this, SLOT(handleSeriesAdded(QAbstractSeries*)));
321 connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), this, SLOT(handleSeriesAdded(QAbstractSeries*)));
329 connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), this, SIGNAL(seriesRemoved(QAbstractSeries*)));
322 connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), this, SIGNAL(seriesRemoved(QAbstractSeries*)));
323 connect(m_chart, &QChart::plotAreaChanged, this, &DeclarativeChart::plotAreaChanged);
330 }
324 }
331
325
332 void DeclarativeChart::handleSeriesAdded(QAbstractSeries *series)
326 void DeclarativeChart::handleSeriesAdded(QAbstractSeries *series)
333 {
327 {
334 emit seriesAdded(series);
328 emit seriesAdded(series);
335 }
329 }
336
330
337 void DeclarativeChart::changeMinimumMargins(int top, int bottom, int left, int right)
331 void DeclarativeChart::changeMinimumMargins(int top, int bottom, int left, int right)
338 {
332 {
339 m_chart->setMargins(QMargins(left, top, right, bottom));
333 m_chart->setMargins(QMargins(left, top, right, bottom));
340 emit minimumMarginsChanged();
334 emit minimumMarginsChanged();
341 emit plotAreaChanged(m_chart->plotArea());
342 }
335 }
343
336
344 DeclarativeChart::~DeclarativeChart()
337 DeclarativeChart::~DeclarativeChart()
345 {
338 {
346 delete m_chart;
339 delete m_chart;
347 m_sceneImageLock.lock();
340 m_sceneImageLock.lock();
348 delete m_currentSceneImage;
341 delete m_currentSceneImage;
349 m_currentSceneImage = 0;
342 m_currentSceneImage = 0;
350 m_sceneImageLock.unlock();
343 m_sceneImageLock.unlock();
351 }
344 }
352
345
353 void DeclarativeChart::childEvent(QChildEvent *event)
346 void DeclarativeChart::childEvent(QChildEvent *event)
354 {
347 {
355 if (event->type() == QEvent::ChildAdded) {
348 if (event->type() == QEvent::ChildAdded) {
356 if (qobject_cast<QAbstractSeries *>(event->child())) {
349 if (qobject_cast<QAbstractSeries *>(event->child())) {
357 m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child()));
350 m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child()));
358 }
351 }
359 }
352 }
360 }
353 }
361
354
362 void DeclarativeChart::componentComplete()
355 void DeclarativeChart::componentComplete()
363 {
356 {
364 foreach (QObject *child, children()) {
357 foreach (QObject *child, children()) {
365 if (qobject_cast<QAbstractSeries *>(child)) {
358 if (qobject_cast<QAbstractSeries *>(child)) {
366 // Add series to the chart
359 // Add series to the chart
367 QAbstractSeries *series = qobject_cast<QAbstractSeries *>(child);
360 QAbstractSeries *series = qobject_cast<QAbstractSeries *>(child);
368 m_chart->addSeries(series);
361 m_chart->addSeries(series);
369
362
370 // Connect to axis changed signals (unless this is a pie series)
363 // Connect to axis changed signals (unless this is a pie series)
371 if (!qobject_cast<DeclarativePieSeries *>(series)) {
364 if (!qobject_cast<DeclarativePieSeries *>(series)) {
372 connect(series, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
365 connect(series, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
373 connect(series, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SLOT(handleAxisXTopSet(QAbstractAxis*)));
366 connect(series, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SLOT(handleAxisXTopSet(QAbstractAxis*)));
374 connect(series, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*)));
367 connect(series, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*)));
375 connect(series, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SLOT(handleAxisYRightSet(QAbstractAxis*)));
368 connect(series, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SLOT(handleAxisYRightSet(QAbstractAxis*)));
376 }
369 }
377
370
378 initializeAxes(series);
371 initializeAxes(series);
379 }
372 }
380 }
373 }
381
374
382 QQuickItem::componentComplete();
375 QQuickItem::componentComplete();
383 }
376 }
384
377
385 void DeclarativeChart::handleAxisXSet(QAbstractAxis *axis)
378 void DeclarativeChart::handleAxisXSet(QAbstractAxis *axis)
386 {
379 {
387 QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender());
380 QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender());
388 if (axis && s) {
381 if (axis && s) {
389 if (!m_chart->axes(Qt::Horizontal).contains(axis))
382 if (!m_chart->axes(Qt::Horizontal).contains(axis))
390 m_chart->setAxisX(axis, s);
383 m_chart->setAxisX(axis, s);
391 if (!s->attachedAxes().contains(axis))
384 if (!s->attachedAxes().contains(axis))
392 s->attachAxis(axis);
385 s->attachAxis(axis);
393 } else {
386 } else {
394 qWarning() << "Trying to set axisX to null.";
387 qWarning() << "Trying to set axisX to null.";
395 }
388 }
396 }
389 }
397
390
398 void DeclarativeChart::handleAxisXTopSet(QAbstractAxis *axis)
391 void DeclarativeChart::handleAxisXTopSet(QAbstractAxis *axis)
399 {
392 {
400 QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender());
393 QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender());
401 if (axis && s) {
394 if (axis && s) {
402 if (!m_chart->axes(Qt::Horizontal).contains(axis)) {
395 if (!m_chart->axes(Qt::Horizontal).contains(axis)) {
403 QList<QAbstractAxis *> oldAxes = m_chart->axes(Qt::Horizontal, s);
396 QList<QAbstractAxis *> oldAxes = m_chart->axes(Qt::Horizontal, s);
404 foreach (QAbstractAxis* a, oldAxes) {
397 foreach (QAbstractAxis* a, oldAxes) {
405 m_chart->removeAxis(a);
398 m_chart->removeAxis(a);
406 delete a;
399 delete a;
407 }
400 }
408 m_chart->addAxis(axis, Qt::AlignTop);
401 m_chart->addAxis(axis, Qt::AlignTop);
409 }
402 }
410 if (!s->attachedAxes().contains(axis))
403 if (!s->attachedAxes().contains(axis))
411 s->attachAxis(axis);
404 s->attachAxis(axis);
412 } else {
405 } else {
413 qWarning() << "Trying to set axisXTop to null.";
406 qWarning() << "Trying to set axisXTop to null.";
414 }
407 }
415 }
408 }
416
409
417 void DeclarativeChart::handleAxisYSet(QAbstractAxis *axis)
410 void DeclarativeChart::handleAxisYSet(QAbstractAxis *axis)
418 {
411 {
419 QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender());
412 QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender());
420 if (axis && s) {
413 if (axis && s) {
421 if (!m_chart->axes(Qt::Vertical).contains(axis))
414 if (!m_chart->axes(Qt::Vertical).contains(axis))
422 m_chart->setAxisY(axis, s);
415 m_chart->setAxisY(axis, s);
423 if (!s->attachedAxes().contains(axis))
416 if (!s->attachedAxes().contains(axis))
424 s->attachAxis(axis);
417 s->attachAxis(axis);
425 } else {
418 } else {
426 qWarning() << "Trying to set axisY to null.";
419 qWarning() << "Trying to set axisY to null.";
427 }
420 }
428 }
421 }
429
422
430 void DeclarativeChart::handleAxisYRightSet(QAbstractAxis *axis)
423 void DeclarativeChart::handleAxisYRightSet(QAbstractAxis *axis)
431 {
424 {
432 QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender());
425 QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender());
433 if (axis && s) {
426 if (axis && s) {
434 if (!m_chart->axes(Qt::Vertical).contains(axis)) {
427 if (!m_chart->axes(Qt::Vertical).contains(axis)) {
435 QList<QAbstractAxis *> oldAxes = m_chart->axes((Qt::Vertical), s);
428 QList<QAbstractAxis *> oldAxes = m_chart->axes((Qt::Vertical), s);
436 foreach (QAbstractAxis* a, oldAxes) {
429 foreach (QAbstractAxis* a, oldAxes) {
437 m_chart->removeAxis(a);
430 m_chart->removeAxis(a);
438 delete a;
431 delete a;
439 }
432 }
440 m_chart->addAxis(axis, Qt::AlignRight);
433 m_chart->addAxis(axis, Qt::AlignRight);
441 }
434 }
442 if (!s->attachedAxes().contains(axis))
435 if (!s->attachedAxes().contains(axis))
443 s->attachAxis(axis);
436 s->attachAxis(axis);
444 } else {
437 } else {
445 qWarning() << "Trying to set axisYRight to null.";
438 qWarning() << "Trying to set axisYRight to null.";
446 }
439 }
447 }
440 }
448
441
449 void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
442 void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
450 {
443 {
451 if (newGeometry.isValid()) {
444 if (newGeometry.isValid()) {
452 if (newGeometry.width() > 0 && newGeometry.height() > 0) {
445 if (newGeometry.width() > 0 && newGeometry.height() > 0) {
453 m_chart->resize(newGeometry.width(), newGeometry.height());
446 m_chart->resize(newGeometry.width(), newGeometry.height());
454 }
447 }
455 }
448 }
456 QQuickItem::geometryChanged(newGeometry, oldGeometry);
449 QQuickItem::geometryChanged(newGeometry, oldGeometry);
457
458 // It would be better to trigger the plotAreaChanged signal from QChart::plotAreaChanged or
459 // similar. Since that kind of a signal is not clearly needed in the C++ API the work-around is
460 // to implement it here for the QML API purposes.
461 emit plotAreaChanged(m_chart->plotArea());
462 }
450 }
463
451
464 void DeclarativeChart::sceneChanged(QList<QRectF> region)
452 void DeclarativeChart::sceneChanged(QList<QRectF> region)
465 {
453 {
466 Q_UNUSED(region);
454 Q_UNUSED(region);
467
455
468 if (m_guiThreadId == m_paintThreadId) {
456 if (m_guiThreadId == m_paintThreadId) {
469 // Rendering in gui thread, no need for shenannigans, just update
457 // Rendering in gui thread, no need for shenannigans, just update
470 update();
458 update();
471 } else {
459 } else {
472 // Multi-threaded rendering, need to ensure scene is actually rendered in gui thread
460 // Multi-threaded rendering, need to ensure scene is actually rendered in gui thread
473 if (!m_updatePending) {
461 if (!m_updatePending) {
474 m_updatePending = true;
462 m_updatePending = true;
475 // Do async render to avoid some unnecessary renders.
463 // Do async render to avoid some unnecessary renders.
476 QTimer::singleShot(0, this, SLOT(renderScene()));
464 QTimer::singleShot(0, this, SLOT(renderScene()));
477 }
465 }
478 }
466 }
479 }
467 }
480
468
481 void DeclarativeChart::renderScene()
469 void DeclarativeChart::renderScene()
482 {
470 {
483 m_updatePending = false;
471 m_updatePending = false;
484 m_sceneImageLock.lock();
472 m_sceneImageLock.lock();
485 delete m_currentSceneImage;
473 delete m_currentSceneImage;
486 m_currentSceneImage = new QImage(m_chart->size().toSize(), QImage::Format_ARGB32);
474 m_currentSceneImage = new QImage(m_chart->size().toSize(), QImage::Format_ARGB32);
487 m_currentSceneImage->fill(Qt::transparent);
475 m_currentSceneImage->fill(Qt::transparent);
488 QPainter painter(m_currentSceneImage);
476 QPainter painter(m_currentSceneImage);
489 if (antialiasing())
477 if (antialiasing())
490 painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform);
478 painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform);
491 QRect renderRect(QPoint(0, 0), m_chart->size().toSize());
479 QRect renderRect(QPoint(0, 0), m_chart->size().toSize());
492 m_scene->render(&painter, renderRect, renderRect);
480 m_scene->render(&painter, renderRect, renderRect);
493 m_sceneImageLock.unlock();
481 m_sceneImageLock.unlock();
494
482
495 update();
483 update();
496 }
484 }
497
485
498 void DeclarativeChart::paint(QPainter *painter)
486 void DeclarativeChart::paint(QPainter *painter)
499 {
487 {
500 if (!m_paintThreadId) {
488 if (!m_paintThreadId) {
501 m_paintThreadId = QThread::currentThreadId();
489 m_paintThreadId = QThread::currentThreadId();
502 if (m_guiThreadId == m_paintThreadId) {
490 if (m_guiThreadId == m_paintThreadId) {
503 // No need for scene image in single threaded rendering, so delete
491 // No need for scene image in single threaded rendering, so delete
504 // the one that got made by default before the rendering type was
492 // the one that got made by default before the rendering type was
505 // detected.
493 // detected.
506 delete m_currentSceneImage;
494 delete m_currentSceneImage;
507 m_currentSceneImage = 0;
495 m_currentSceneImage = 0;
508 }
496 }
509 }
497 }
510
498
511 if (m_guiThreadId == m_paintThreadId) {
499 if (m_guiThreadId == m_paintThreadId) {
512 QRectF renderRect(QPointF(0, 0), m_chart->size());
500 QRectF renderRect(QPointF(0, 0), m_chart->size());
513 m_scene->render(painter, renderRect, renderRect);
501 m_scene->render(painter, renderRect, renderRect);
514 } else {
502 } else {
515 m_sceneImageLock.lock();
503 m_sceneImageLock.lock();
516 if (m_currentSceneImage) {
504 if (m_currentSceneImage) {
517 QRect imageRect(QPoint(0, 0), m_currentSceneImage->size());
505 QRect imageRect(QPoint(0, 0), m_currentSceneImage->size());
518 QRect itemRect(QPoint(0, 0), QSize(width(), height()));
506 QRect itemRect(QPoint(0, 0), QSize(width(), height()));
519 painter->drawImage(itemRect, *m_currentSceneImage, imageRect);
507 painter->drawImage(itemRect, *m_currentSceneImage, imageRect);
520 }
508 }
521 m_sceneImageLock.unlock();
509 m_sceneImageLock.unlock();
522 }
510 }
523 }
511 }
524
512
525 void DeclarativeChart::mousePressEvent(QMouseEvent *event)
513 void DeclarativeChart::mousePressEvent(QMouseEvent *event)
526 {
514 {
527 m_mousePressScenePoint = event->pos();
515 m_mousePressScenePoint = event->pos();
528 m_mousePressScreenPoint = event->globalPos();
516 m_mousePressScreenPoint = event->globalPos();
529 m_lastMouseMoveScenePoint = m_mousePressScenePoint;
517 m_lastMouseMoveScenePoint = m_mousePressScenePoint;
530 m_lastMouseMoveScreenPoint = m_mousePressScreenPoint;
518 m_lastMouseMoveScreenPoint = m_mousePressScreenPoint;
531 m_mousePressButton = event->button();
519 m_mousePressButton = event->button();
532 m_mousePressButtons = event->buttons();
520 m_mousePressButtons = event->buttons();
533
521
534 QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMousePress);
522 QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMousePress);
535 mouseEvent.setWidget(0);
523 mouseEvent.setWidget(0);
536 mouseEvent.setButtonDownScenePos(m_mousePressButton, m_mousePressScenePoint);
524 mouseEvent.setButtonDownScenePos(m_mousePressButton, m_mousePressScenePoint);
537 mouseEvent.setButtonDownScreenPos(m_mousePressButton, m_mousePressScreenPoint);
525 mouseEvent.setButtonDownScreenPos(m_mousePressButton, m_mousePressScreenPoint);
538 mouseEvent.setScenePos(m_mousePressScenePoint);
526 mouseEvent.setScenePos(m_mousePressScenePoint);
539 mouseEvent.setScreenPos(m_mousePressScreenPoint);
527 mouseEvent.setScreenPos(m_mousePressScreenPoint);
540 mouseEvent.setLastScenePos(m_lastMouseMoveScenePoint);
528 mouseEvent.setLastScenePos(m_lastMouseMoveScenePoint);
541 mouseEvent.setLastScreenPos(m_lastMouseMoveScreenPoint);
529 mouseEvent.setLastScreenPos(m_lastMouseMoveScreenPoint);
542 mouseEvent.setButtons(m_mousePressButtons);
530 mouseEvent.setButtons(m_mousePressButtons);
543 mouseEvent.setButton(m_mousePressButton);
531 mouseEvent.setButton(m_mousePressButton);
544 mouseEvent.setModifiers(event->modifiers());
532 mouseEvent.setModifiers(event->modifiers());
545 mouseEvent.setAccepted(false);
533 mouseEvent.setAccepted(false);
546
534
547 QApplication::sendEvent(m_scene, &mouseEvent);
535 QApplication::sendEvent(m_scene, &mouseEvent);
548 }
536 }
549
537
550 void DeclarativeChart::mouseReleaseEvent(QMouseEvent *event)
538 void DeclarativeChart::mouseReleaseEvent(QMouseEvent *event)
551 {
539 {
552 QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMouseRelease);
540 QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMouseRelease);
553 mouseEvent.setWidget(0);
541 mouseEvent.setWidget(0);
554 mouseEvent.setButtonDownScenePos(m_mousePressButton, m_mousePressScenePoint);
542 mouseEvent.setButtonDownScenePos(m_mousePressButton, m_mousePressScenePoint);
555 mouseEvent.setButtonDownScreenPos(m_mousePressButton, m_mousePressScreenPoint);
543 mouseEvent.setButtonDownScreenPos(m_mousePressButton, m_mousePressScreenPoint);
556 mouseEvent.setScenePos(event->pos());
544 mouseEvent.setScenePos(event->pos());
557 mouseEvent.setScreenPos(event->globalPos());
545 mouseEvent.setScreenPos(event->globalPos());
558 mouseEvent.setLastScenePos(m_lastMouseMoveScenePoint);
546 mouseEvent.setLastScenePos(m_lastMouseMoveScenePoint);
559 mouseEvent.setLastScreenPos(m_lastMouseMoveScreenPoint);
547 mouseEvent.setLastScreenPos(m_lastMouseMoveScreenPoint);
560 mouseEvent.setButtons(event->buttons());
548 mouseEvent.setButtons(event->buttons());
561 mouseEvent.setButton(event->button());
549 mouseEvent.setButton(event->button());
562 mouseEvent.setModifiers(event->modifiers());
550 mouseEvent.setModifiers(event->modifiers());
563 mouseEvent.setAccepted(false);
551 mouseEvent.setAccepted(false);
564
552
565 QApplication::sendEvent(m_scene, &mouseEvent);
553 QApplication::sendEvent(m_scene, &mouseEvent);
566
554
567 m_mousePressButtons = event->buttons();
555 m_mousePressButtons = event->buttons();
568 m_mousePressButton = Qt::NoButton;
556 m_mousePressButton = Qt::NoButton;
569 }
557 }
570
558
571 void DeclarativeChart::hoverMoveEvent(QHoverEvent *event)
559 void DeclarativeChart::hoverMoveEvent(QHoverEvent *event)
572 {
560 {
573 // Convert hover move to mouse move, since we don't seem to get actual mouse move events.
561 // Convert hover move to mouse move, since we don't seem to get actual mouse move events.
574 // QGraphicsScene generates hover events from mouse move events, so we don't need
562 // QGraphicsScene generates hover events from mouse move events, so we don't need
575 // to pass hover events there.
563 // to pass hover events there.
576 QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMouseMove);
564 QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMouseMove);
577 mouseEvent.setWidget(0);
565 mouseEvent.setWidget(0);
578 mouseEvent.setButtonDownScenePos(m_mousePressButton, m_mousePressScenePoint);
566 mouseEvent.setButtonDownScenePos(m_mousePressButton, m_mousePressScenePoint);
579 mouseEvent.setButtonDownScreenPos(m_mousePressButton, m_mousePressScreenPoint);
567 mouseEvent.setButtonDownScreenPos(m_mousePressButton, m_mousePressScreenPoint);
580 mouseEvent.setScenePos(event->pos());
568 mouseEvent.setScenePos(event->pos());
581 // Hover events do not have global pos in them, and the screen position doesn't seem to
569 // Hover events do not have global pos in them, and the screen position doesn't seem to
582 // matter anyway in this use case, so just pass event pos instead of trying to
570 // matter anyway in this use case, so just pass event pos instead of trying to
583 // calculate the real screen position.
571 // calculate the real screen position.
584 mouseEvent.setScreenPos(event->pos());
572 mouseEvent.setScreenPos(event->pos());
585 mouseEvent.setLastScenePos(m_lastMouseMoveScenePoint);
573 mouseEvent.setLastScenePos(m_lastMouseMoveScenePoint);
586 mouseEvent.setLastScreenPos(m_lastMouseMoveScreenPoint);
574 mouseEvent.setLastScreenPos(m_lastMouseMoveScreenPoint);
587 mouseEvent.setButtons(m_mousePressButtons);
575 mouseEvent.setButtons(m_mousePressButtons);
588 mouseEvent.setButton(m_mousePressButton);
576 mouseEvent.setButton(m_mousePressButton);
589 mouseEvent.setModifiers(event->modifiers());
577 mouseEvent.setModifiers(event->modifiers());
590 m_lastMouseMoveScenePoint = mouseEvent.scenePos();
578 m_lastMouseMoveScenePoint = mouseEvent.scenePos();
591 m_lastMouseMoveScreenPoint = mouseEvent.screenPos();
579 m_lastMouseMoveScreenPoint = mouseEvent.screenPos();
592 mouseEvent.setAccepted(false);
580 mouseEvent.setAccepted(false);
593
581
594 QApplication::sendEvent(m_scene, &mouseEvent);
582 QApplication::sendEvent(m_scene, &mouseEvent);
595 }
583 }
596
584
597 void DeclarativeChart::handleAntialiasingChanged(bool enable)
585 void DeclarativeChart::handleAntialiasingChanged(bool enable)
598 {
586 {
599 setAntialiasing(enable);
587 setAntialiasing(enable);
600 }
588 }
601
589
602 void DeclarativeChart::setTheme(DeclarativeChart::Theme theme)
590 void DeclarativeChart::setTheme(DeclarativeChart::Theme theme)
603 {
591 {
604 QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme;
592 QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme;
605 if (chartTheme != m_chart->theme())
593 if (chartTheme != m_chart->theme())
606 m_chart->setTheme(chartTheme);
594 m_chart->setTheme(chartTheme);
607 }
595 }
608
596
609 DeclarativeChart::Theme DeclarativeChart::theme()
597 DeclarativeChart::Theme DeclarativeChart::theme()
610 {
598 {
611 return (DeclarativeChart::Theme) m_chart->theme();
599 return (DeclarativeChart::Theme) m_chart->theme();
612 }
600 }
613
601
614 void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations)
602 void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations)
615 {
603 {
616 QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations;
604 QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations;
617 if (animationOptions != m_chart->animationOptions())
605 if (animationOptions != m_chart->animationOptions())
618 m_chart->setAnimationOptions(animationOptions);
606 m_chart->setAnimationOptions(animationOptions);
619 }
607 }
620
608
621 DeclarativeChart::Animation DeclarativeChart::animationOptions()
609 DeclarativeChart::Animation DeclarativeChart::animationOptions()
622 {
610 {
623 if (m_chart->animationOptions().testFlag(QChart::AllAnimations))
611 if (m_chart->animationOptions().testFlag(QChart::AllAnimations))
624 return DeclarativeChart::AllAnimations;
612 return DeclarativeChart::AllAnimations;
625 else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations))
613 else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations))
626 return DeclarativeChart::GridAxisAnimations;
614 return DeclarativeChart::GridAxisAnimations;
627 else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations))
615 else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations))
628 return DeclarativeChart::SeriesAnimations;
616 return DeclarativeChart::SeriesAnimations;
629 else
617 else
630 return DeclarativeChart::NoAnimation;
618 return DeclarativeChart::NoAnimation;
631 }
619 }
632
620
633 void DeclarativeChart::setTitle(QString title)
621 void DeclarativeChart::setTitle(QString title)
634 {
622 {
635 if (title != m_chart->title())
623 if (title != m_chart->title())
636 m_chart->setTitle(title);
624 m_chart->setTitle(title);
637 }
625 }
638 QString DeclarativeChart::title()
626 QString DeclarativeChart::title()
639 {
627 {
640 return m_chart->title();
628 return m_chart->title();
641 }
629 }
642
630
643 QAbstractAxis *DeclarativeChart::axisX(QAbstractSeries *series)
631 QAbstractAxis *DeclarativeChart::axisX(QAbstractSeries *series)
644 {
632 {
645 QList<QAbstractAxis *> axes = m_chart->axes(Qt::Horizontal, series);
633 QList<QAbstractAxis *> axes = m_chart->axes(Qt::Horizontal, series);
646 if (axes.count())
634 if (axes.count())
647 return axes[0];
635 return axes[0];
648 return 0;
636 return 0;
649 }
637 }
650
638
651 QAbstractAxis *DeclarativeChart::axisY(QAbstractSeries *series)
639 QAbstractAxis *DeclarativeChart::axisY(QAbstractSeries *series)
652 {
640 {
653 QList<QAbstractAxis *> axes = m_chart->axes(Qt::Vertical, series);
641 QList<QAbstractAxis *> axes = m_chart->axes(Qt::Vertical, series);
654 if (axes.count())
642 if (axes.count())
655 return axes[0];
643 return axes[0];
656 return 0;
644 return 0;
657 }
645 }
658
646
659 QLegend *DeclarativeChart::legend()
647 QLegend *DeclarativeChart::legend()
660 {
648 {
661 return m_chart->legend();
649 return m_chart->legend();
662 }
650 }
663
651
664 void DeclarativeChart::setTitleColor(QColor color)
652 void DeclarativeChart::setTitleColor(QColor color)
665 {
653 {
666 QBrush b = m_chart->titleBrush();
654 QBrush b = m_chart->titleBrush();
667 if (color != b.color()) {
655 if (color != b.color()) {
668 b.setColor(color);
656 b.setColor(color);
669 m_chart->setTitleBrush(b);
657 m_chart->setTitleBrush(b);
670 emit titleColorChanged(color);
658 emit titleColorChanged(color);
671 }
659 }
672 }
660 }
673
661
674 QFont DeclarativeChart::titleFont() const
662 QFont DeclarativeChart::titleFont() const
675 {
663 {
676 return m_chart->titleFont();
664 return m_chart->titleFont();
677 }
665 }
678
666
679 void DeclarativeChart::setTitleFont(const QFont &font)
667 void DeclarativeChart::setTitleFont(const QFont &font)
680 {
668 {
681 m_chart->setTitleFont(font);
669 m_chart->setTitleFont(font);
682 }
670 }
683
671
684 QColor DeclarativeChart::titleColor()
672 QColor DeclarativeChart::titleColor()
685 {
673 {
686 return m_chart->titleBrush().color();
674 return m_chart->titleBrush().color();
687 }
675 }
688
676
689 void DeclarativeChart::setBackgroundColor(QColor color)
677 void DeclarativeChart::setBackgroundColor(QColor color)
690 {
678 {
691 QBrush b = m_chart->backgroundBrush();
679 QBrush b = m_chart->backgroundBrush();
692 if (b.style() != Qt::SolidPattern || color != b.color()) {
680 if (b.style() != Qt::SolidPattern || color != b.color()) {
693 b.setStyle(Qt::SolidPattern);
681 b.setStyle(Qt::SolidPattern);
694 b.setColor(color);
682 b.setColor(color);
695 m_chart->setBackgroundBrush(b);
683 m_chart->setBackgroundBrush(b);
696 emit backgroundColorChanged();
684 emit backgroundColorChanged();
697 }
685 }
698 }
686 }
699
687
700 QColor DeclarativeChart::backgroundColor()
688 QColor DeclarativeChart::backgroundColor()
701 {
689 {
702 return m_chart->backgroundBrush().color();
690 return m_chart->backgroundBrush().color();
703 }
691 }
704
692
705 void QtCharts::DeclarativeChart::setPlotAreaColor(QColor color)
693 void QtCharts::DeclarativeChart::setPlotAreaColor(QColor color)
706 {
694 {
707 QBrush b = m_chart->plotAreaBackgroundBrush();
695 QBrush b = m_chart->plotAreaBackgroundBrush();
708 if (b.style() != Qt::SolidPattern || color != b.color()) {
696 if (b.style() != Qt::SolidPattern || color != b.color()) {
709 b.setStyle(Qt::SolidPattern);
697 b.setStyle(Qt::SolidPattern);
710 b.setColor(color);
698 b.setColor(color);
711 m_chart->setPlotAreaBackgroundBrush(b);
699 m_chart->setPlotAreaBackgroundBrush(b);
712 m_chart->setPlotAreaBackgroundVisible(true);
700 m_chart->setPlotAreaBackgroundVisible(true);
713 emit plotAreaColorChanged();
701 emit plotAreaColorChanged();
714 }
702 }
715 }
703 }
716
704
717 QColor QtCharts::DeclarativeChart::plotAreaColor()
705 QColor QtCharts::DeclarativeChart::plotAreaColor()
718 {
706 {
719 return m_chart->plotAreaBackgroundBrush().color();
707 return m_chart->plotAreaBackgroundBrush().color();
720 }
708 }
721
709
722 void DeclarativeChart::setLocalizeNumbers(bool localize)
710 void DeclarativeChart::setLocalizeNumbers(bool localize)
723 {
711 {
724 if (m_chart->localizeNumbers() != localize) {
712 if (m_chart->localizeNumbers() != localize) {
725 m_chart->setLocalizeNumbers(localize);
713 m_chart->setLocalizeNumbers(localize);
726 emit localizeNumbersChanged();
714 emit localizeNumbersChanged();
727 }
715 }
728 }
716 }
729
717
730 bool DeclarativeChart::localizeNumbers() const
718 bool DeclarativeChart::localizeNumbers() const
731 {
719 {
732 return m_chart->localizeNumbers();
720 return m_chart->localizeNumbers();
733 }
721 }
734
722
735 void QtCharts::DeclarativeChart::setLocale(const QLocale &locale)
723 void QtCharts::DeclarativeChart::setLocale(const QLocale &locale)
736 {
724 {
737 if (m_chart->locale() != locale) {
725 if (m_chart->locale() != locale) {
738 m_chart->setLocale(locale);
726 m_chart->setLocale(locale);
739 emit localeChanged();
727 emit localeChanged();
740 }
728 }
741 }
729 }
742
730
743 QLocale QtCharts::DeclarativeChart::locale() const
731 QLocale QtCharts::DeclarativeChart::locale() const
744 {
732 {
745 return m_chart->locale();
733 return m_chart->locale();
746 }
734 }
747
735
748 int DeclarativeChart::count()
736 int DeclarativeChart::count()
749 {
737 {
750 return m_chart->series().count();
738 return m_chart->series().count();
751 }
739 }
752
740
753 void DeclarativeChart::setDropShadowEnabled(bool enabled)
741 void DeclarativeChart::setDropShadowEnabled(bool enabled)
754 {
742 {
755 if (enabled != m_chart->isDropShadowEnabled()) {
743 if (enabled != m_chart->isDropShadowEnabled()) {
756 m_chart->setDropShadowEnabled(enabled);
744 m_chart->setDropShadowEnabled(enabled);
757 dropShadowEnabledChanged(enabled);
745 dropShadowEnabledChanged(enabled);
758 }
746 }
759 }
747 }
760
748
761 bool DeclarativeChart::dropShadowEnabled()
749 bool DeclarativeChart::dropShadowEnabled()
762 {
750 {
763 return m_chart->isDropShadowEnabled();
751 return m_chart->isDropShadowEnabled();
764 }
752 }
765
753
766 qreal DeclarativeChart::backgroundRoundness() const
754 qreal DeclarativeChart::backgroundRoundness() const
767 {
755 {
768 return m_chart->backgroundRoundness();
756 return m_chart->backgroundRoundness();
769 }
757 }
770
758
771 void DeclarativeChart::setBackgroundRoundness(qreal diameter)
759 void DeclarativeChart::setBackgroundRoundness(qreal diameter)
772 {
760 {
773 if (m_chart->backgroundRoundness() != diameter) {
761 if (m_chart->backgroundRoundness() != diameter) {
774 m_chart->setBackgroundRoundness(diameter);
762 m_chart->setBackgroundRoundness(diameter);
775 emit backgroundRoundnessChanged(diameter);
763 emit backgroundRoundnessChanged(diameter);
776 }
764 }
777 }
765 }
778
766
779 qreal DeclarativeChart::topMargin()
767 qreal DeclarativeChart::topMargin()
780 {
768 {
781 qWarning() << "ChartView.topMargin is deprecated. Use margins instead.";
769 qWarning() << "ChartView.topMargin is deprecated. Use margins instead.";
782 return m_chart->margins().top();
770 return m_chart->margins().top();
783 }
771 }
784
772
785 qreal DeclarativeChart::bottomMargin()
773 qreal DeclarativeChart::bottomMargin()
786 {
774 {
787 qWarning() << "ChartView.bottomMargin is deprecated. Use margins instead.";
775 qWarning() << "ChartView.bottomMargin is deprecated. Use margins instead.";
788 return m_chart->margins().bottom();
776 return m_chart->margins().bottom();
789 }
777 }
790
778
791 qreal DeclarativeChart::leftMargin()
779 qreal DeclarativeChart::leftMargin()
792 {
780 {
793 qWarning() << "ChartView.leftMargin is deprecated. Use margins instead.";
781 qWarning() << "ChartView.leftMargin is deprecated. Use margins instead.";
794 return m_chart->margins().left();
782 return m_chart->margins().left();
795 }
783 }
796
784
797 qreal DeclarativeChart::rightMargin()
785 qreal DeclarativeChart::rightMargin()
798 {
786 {
799 qWarning() << "ChartView.rightMargin is deprecated. Use margins instead.";
787 qWarning() << "ChartView.rightMargin is deprecated. Use margins instead.";
800 return m_chart->margins().right();
788 return m_chart->margins().right();
801 }
789 }
802
790
803 void DeclarativeChart::zoom(qreal factor)
791 void DeclarativeChart::zoom(qreal factor)
804 {
792 {
805 m_chart->zoom(factor);
793 m_chart->zoom(factor);
806 }
794 }
807
795
808 void DeclarativeChart::scrollLeft(qreal pixels)
796 void DeclarativeChart::scrollLeft(qreal pixels)
809 {
797 {
810 m_chart->scroll(-pixels, 0);
798 m_chart->scroll(-pixels, 0);
811 }
799 }
812
800
813 void DeclarativeChart::scrollRight(qreal pixels)
801 void DeclarativeChart::scrollRight(qreal pixels)
814 {
802 {
815 m_chart->scroll(pixels, 0);
803 m_chart->scroll(pixels, 0);
816 }
804 }
817
805
818 void DeclarativeChart::scrollUp(qreal pixels)
806 void DeclarativeChart::scrollUp(qreal pixels)
819 {
807 {
820 m_chart->scroll(0, pixels);
808 m_chart->scroll(0, pixels);
821 }
809 }
822
810
823 void DeclarativeChart::scrollDown(qreal pixels)
811 void DeclarativeChart::scrollDown(qreal pixels)
824 {
812 {
825 m_chart->scroll(0, -pixels);
813 m_chart->scroll(0, -pixels);
826 }
814 }
827
815
828 QQmlListProperty<QAbstractAxis> DeclarativeChart::axes()
816 QQmlListProperty<QAbstractAxis> DeclarativeChart::axes()
829 {
817 {
830 return QQmlListProperty<QAbstractAxis>(this, 0,
818 return QQmlListProperty<QAbstractAxis>(this, 0,
831 &DeclarativeChart::axesAppendFunc,
819 &DeclarativeChart::axesAppendFunc,
832 &DeclarativeChart::axesCountFunc,
820 &DeclarativeChart::axesCountFunc,
833 &DeclarativeChart::axesAtFunc,
821 &DeclarativeChart::axesAtFunc,
834 &DeclarativeChart::axesClearFunc);
822 &DeclarativeChart::axesClearFunc);
835 }
823 }
836
824
837 void DeclarativeChart::axesAppendFunc(QQmlListProperty<QAbstractAxis> *list, QAbstractAxis *element)
825 void DeclarativeChart::axesAppendFunc(QQmlListProperty<QAbstractAxis> *list, QAbstractAxis *element)
838 {
826 {
839 // Empty implementation
827 // Empty implementation
840 Q_UNUSED(list);
828 Q_UNUSED(list);
841 Q_UNUSED(element);
829 Q_UNUSED(element);
842 }
830 }
843
831
844 int DeclarativeChart::axesCountFunc(QQmlListProperty<QAbstractAxis> *list)
832 int DeclarativeChart::axesCountFunc(QQmlListProperty<QAbstractAxis> *list)
845 {
833 {
846 if (qobject_cast<DeclarativeChart *>(list->object)) {
834 if (qobject_cast<DeclarativeChart *>(list->object)) {
847 DeclarativeChart *chart = qobject_cast<DeclarativeChart *>(list->object);
835 DeclarativeChart *chart = qobject_cast<DeclarativeChart *>(list->object);
848 return chart->m_chart->axes(Qt::Horizontal | Qt::Vertical).count();
836 return chart->m_chart->axes(Qt::Horizontal | Qt::Vertical).count();
849 }
837 }
850 return 0;
838 return 0;
851 }
839 }
852
840
853 QAbstractAxis *DeclarativeChart::axesAtFunc(QQmlListProperty<QAbstractAxis> *list, int index)
841 QAbstractAxis *DeclarativeChart::axesAtFunc(QQmlListProperty<QAbstractAxis> *list, int index)
854 {
842 {
855 if (qobject_cast<DeclarativeChart *>(list->object)) {
843 if (qobject_cast<DeclarativeChart *>(list->object)) {
856 DeclarativeChart *chart = qobject_cast<DeclarativeChart *>(list->object);
844 DeclarativeChart *chart = qobject_cast<DeclarativeChart *>(list->object);
857 QList<QAbstractAxis *> axes = chart->m_chart->axes(Qt::Horizontal | Qt::Vertical, chart->m_chart->series()[0]);
845 QList<QAbstractAxis *> axes = chart->m_chart->axes(Qt::Horizontal | Qt::Vertical, chart->m_chart->series()[0]);
858 return axes.at(index);
846 return axes.at(index);
859 }
847 }
860 return 0;
848 return 0;
861 }
849 }
862
850
863 void DeclarativeChart::axesClearFunc(QQmlListProperty<QAbstractAxis> *list)
851 void DeclarativeChart::axesClearFunc(QQmlListProperty<QAbstractAxis> *list)
864 {
852 {
865 // Empty implementation
853 // Empty implementation
866 Q_UNUSED(list);
854 Q_UNUSED(list);
867 }
855 }
868
856
869
857
870 QAbstractSeries *DeclarativeChart::series(int index)
858 QAbstractSeries *DeclarativeChart::series(int index)
871 {
859 {
872 if (index < m_chart->series().count()) {
860 if (index < m_chart->series().count()) {
873 return m_chart->series().at(index);
861 return m_chart->series().at(index);
874 }
862 }
875 return 0;
863 return 0;
876 }
864 }
877
865
878 QAbstractSeries *DeclarativeChart::series(QString seriesName)
866 QAbstractSeries *DeclarativeChart::series(QString seriesName)
879 {
867 {
880 foreach (QAbstractSeries *series, m_chart->series()) {
868 foreach (QAbstractSeries *series, m_chart->series()) {
881 if (series->name() == seriesName)
869 if (series->name() == seriesName)
882 return series;
870 return series;
883 }
871 }
884 return 0;
872 return 0;
885 }
873 }
886
874
887 QAbstractSeries *DeclarativeChart::createSeries(int type, QString name, QAbstractAxis *axisX, QAbstractAxis *axisY)
875 QAbstractSeries *DeclarativeChart::createSeries(int type, QString name, QAbstractAxis *axisX, QAbstractAxis *axisY)
888 {
876 {
889 QAbstractSeries *series = 0;
877 QAbstractSeries *series = 0;
890
878
891 switch (type) {
879 switch (type) {
892 case DeclarativeChart::SeriesTypeLine:
880 case DeclarativeChart::SeriesTypeLine:
893 series = new DeclarativeLineSeries();
881 series = new DeclarativeLineSeries();
894 break;
882 break;
895 case DeclarativeChart::SeriesTypeArea: {
883 case DeclarativeChart::SeriesTypeArea: {
896 DeclarativeAreaSeries *area = new DeclarativeAreaSeries();
884 DeclarativeAreaSeries *area = new DeclarativeAreaSeries();
897 area->setUpperSeries(new DeclarativeLineSeries());
885 area->setUpperSeries(new DeclarativeLineSeries());
898 series = area;
886 series = area;
899 break;
887 break;
900 }
888 }
901 case DeclarativeChart::SeriesTypeStackedBar:
889 case DeclarativeChart::SeriesTypeStackedBar:
902 series = new DeclarativeStackedBarSeries();
890 series = new DeclarativeStackedBarSeries();
903 break;
891 break;
904 case DeclarativeChart::SeriesTypePercentBar:
892 case DeclarativeChart::SeriesTypePercentBar:
905 series = new DeclarativePercentBarSeries();
893 series = new DeclarativePercentBarSeries();
906 break;
894 break;
907 case DeclarativeChart::SeriesTypeBar:
895 case DeclarativeChart::SeriesTypeBar:
908 series = new DeclarativeBarSeries();
896 series = new DeclarativeBarSeries();
909 break;
897 break;
910 case DeclarativeChart::SeriesTypeHorizontalBar:
898 case DeclarativeChart::SeriesTypeHorizontalBar:
911 series = new DeclarativeHorizontalBarSeries();
899 series = new DeclarativeHorizontalBarSeries();
912 break;
900 break;
913 case DeclarativeChart::SeriesTypeHorizontalPercentBar:
901 case DeclarativeChart::SeriesTypeHorizontalPercentBar:
914 series = new DeclarativeHorizontalPercentBarSeries();
902 series = new DeclarativeHorizontalPercentBarSeries();
915 break;
903 break;
916 case DeclarativeChart::SeriesTypeHorizontalStackedBar:
904 case DeclarativeChart::SeriesTypeHorizontalStackedBar:
917 series = new DeclarativeHorizontalStackedBarSeries();
905 series = new DeclarativeHorizontalStackedBarSeries();
918 break;
906 break;
919 case DeclarativeChart::SeriesTypeBoxPlot:
907 case DeclarativeChart::SeriesTypeBoxPlot:
920 series = new DeclarativeBoxPlotSeries();
908 series = new DeclarativeBoxPlotSeries();
921 break;
909 break;
922 case DeclarativeChart::SeriesTypePie:
910 case DeclarativeChart::SeriesTypePie:
923 series = new DeclarativePieSeries();
911 series = new DeclarativePieSeries();
924 break;
912 break;
925 case DeclarativeChart::SeriesTypeScatter:
913 case DeclarativeChart::SeriesTypeScatter:
926 series = new DeclarativeScatterSeries();
914 series = new DeclarativeScatterSeries();
927 break;
915 break;
928 case DeclarativeChart::SeriesTypeSpline:
916 case DeclarativeChart::SeriesTypeSpline:
929 series = new DeclarativeSplineSeries();
917 series = new DeclarativeSplineSeries();
930 break;
918 break;
931 default:
919 default:
932 qWarning() << "Illegal series type";
920 qWarning() << "Illegal series type";
933 }
921 }
934
922
935 if (series) {
923 if (series) {
936 // Connect to axis changed signals (unless this is a pie series)
924 // Connect to axis changed signals (unless this is a pie series)
937 if (!qobject_cast<DeclarativePieSeries *>(series)) {
925 if (!qobject_cast<DeclarativePieSeries *>(series)) {
938 connect(series, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
926 connect(series, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
939 connect(series, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
927 connect(series, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
940 connect(series, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*)));
928 connect(series, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*)));
941 connect(series, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SLOT(handleAxisYRightSet(QAbstractAxis*)));
929 connect(series, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SLOT(handleAxisYRightSet(QAbstractAxis*)));
942 }
930 }
943
931
944 series->setName(name);
932 series->setName(name);
945 m_chart->addSeries(series);
933 m_chart->addSeries(series);
946
934
947 if (axisX)
935 if (axisX)
948 setAxisX(axisX, series);
936 setAxisX(axisX, series);
949 if (axisY)
937 if (axisY)
950 setAxisY(axisY, series);
938 setAxisY(axisY, series);
951
939
952 if (series->attachedAxes().count() < 2)
940 if (series->attachedAxes().count() < 2)
953 initializeAxes(series);
941 initializeAxes(series);
954 }
942 }
955
943
956 return series;
944 return series;
957 }
945 }
958
946
959 void DeclarativeChart::removeSeries(QAbstractSeries *series)
947 void DeclarativeChart::removeSeries(QAbstractSeries *series)
960 {
948 {
961 if (series)
949 if (series)
962 m_chart->removeSeries(series);
950 m_chart->removeSeries(series);
963 else
951 else
964 qWarning("removeSeries: cannot remove null");
952 qWarning("removeSeries: cannot remove null");
965 }
953 }
966
954
967 void DeclarativeChart::setAxisX(QAbstractAxis *axis, QAbstractSeries *series)
955 void DeclarativeChart::setAxisX(QAbstractAxis *axis, QAbstractSeries *series)
968 {
956 {
969 if (axis)
957 if (axis)
970 m_chart->setAxisX(axis, series);
958 m_chart->setAxisX(axis, series);
971 }
959 }
972
960
973 void DeclarativeChart::setAxisY(QAbstractAxis *axis, QAbstractSeries *series)
961 void DeclarativeChart::setAxisY(QAbstractAxis *axis, QAbstractSeries *series)
974 {
962 {
975 if (axis)
963 if (axis)
976 m_chart->setAxisY(axis, series);
964 m_chart->setAxisY(axis, series);
977 }
965 }
978
966
979 void DeclarativeChart::createDefaultAxes()
967 void DeclarativeChart::createDefaultAxes()
980 {
968 {
981 qWarning() << "ChartView.createDefaultAxes() is deprecated. Axes are created automatically.";
969 qWarning() << "ChartView.createDefaultAxes() is deprecated. Axes are created automatically.";
982 }
970 }
983
971
984 QAbstractAxis *DeclarativeChart::defaultAxis(Qt::Orientation orientation, QAbstractSeries *series)
972 QAbstractAxis *DeclarativeChart::defaultAxis(Qt::Orientation orientation, QAbstractSeries *series)
985 {
973 {
986 if (!series) {
974 if (!series) {
987 qWarning() << "No axis type defined for null series";
975 qWarning() << "No axis type defined for null series";
988 return 0;
976 return 0;
989 }
977 }
990
978
991 foreach (QAbstractAxis *existingAxis, m_chart->axes(orientation)) {
979 foreach (QAbstractAxis *existingAxis, m_chart->axes(orientation)) {
992 if (existingAxis->type() == series->d_ptr->defaultAxisType(orientation))
980 if (existingAxis->type() == series->d_ptr->defaultAxisType(orientation))
993 return existingAxis;
981 return existingAxis;
994 }
982 }
995
983
996 switch (series->d_ptr->defaultAxisType(orientation)) {
984 switch (series->d_ptr->defaultAxisType(orientation)) {
997 case QAbstractAxis::AxisTypeValue:
985 case QAbstractAxis::AxisTypeValue:
998 return new QValueAxis(this);
986 return new QValueAxis(this);
999 case QAbstractAxis::AxisTypeBarCategory:
987 case QAbstractAxis::AxisTypeBarCategory:
1000 return new QBarCategoryAxis(this);
988 return new QBarCategoryAxis(this);
1001 case QAbstractAxis::AxisTypeCategory:
989 case QAbstractAxis::AxisTypeCategory:
1002 return new QCategoryAxis(this);
990 return new QCategoryAxis(this);
1003 #ifndef QT_ON_ARM
991 #ifndef QT_ON_ARM
1004 case QAbstractAxis::AxisTypeDateTime:
992 case QAbstractAxis::AxisTypeDateTime:
1005 return new QDateTimeAxis(this);
993 return new QDateTimeAxis(this);
1006 #endif
994 #endif
1007 case QAbstractAxis::AxisTypeLogValue:
995 case QAbstractAxis::AxisTypeLogValue:
1008 return new QLogValueAxis(this);
996 return new QLogValueAxis(this);
1009 default:
997 default:
1010 // assume AxisTypeNoAxis
998 // assume AxisTypeNoAxis
1011 return 0;
999 return 0;
1012 }
1000 }
1013 }
1001 }
1014
1002
1015 void DeclarativeChart::initializeAxes(QAbstractSeries *series)
1003 void DeclarativeChart::initializeAxes(QAbstractSeries *series)
1016 {
1004 {
1017 if (qobject_cast<DeclarativeLineSeries *>(series))
1005 if (qobject_cast<DeclarativeLineSeries *>(series))
1018 doInitializeAxes(series, qobject_cast<DeclarativeLineSeries *>(series)->m_axes);
1006 doInitializeAxes(series, qobject_cast<DeclarativeLineSeries *>(series)->m_axes);
1019 else if (qobject_cast<DeclarativeScatterSeries *>(series))
1007 else if (qobject_cast<DeclarativeScatterSeries *>(series))
1020 doInitializeAxes(series, qobject_cast<DeclarativeScatterSeries *>(series)->m_axes);
1008 doInitializeAxes(series, qobject_cast<DeclarativeScatterSeries *>(series)->m_axes);
1021 else if (qobject_cast<DeclarativeSplineSeries *>(series))
1009 else if (qobject_cast<DeclarativeSplineSeries *>(series))
1022 doInitializeAxes(series, qobject_cast<DeclarativeSplineSeries *>(series)->m_axes);
1010 doInitializeAxes(series, qobject_cast<DeclarativeSplineSeries *>(series)->m_axes);
1023 else if (qobject_cast<DeclarativeAreaSeries *>(series))
1011 else if (qobject_cast<DeclarativeAreaSeries *>(series))
1024 doInitializeAxes(series, qobject_cast<DeclarativeAreaSeries *>(series)->m_axes);
1012 doInitializeAxes(series, qobject_cast<DeclarativeAreaSeries *>(series)->m_axes);
1025 else if (qobject_cast<DeclarativeBarSeries *>(series))
1013 else if (qobject_cast<DeclarativeBarSeries *>(series))
1026 doInitializeAxes(series, qobject_cast<DeclarativeBarSeries *>(series)->m_axes);
1014 doInitializeAxes(series, qobject_cast<DeclarativeBarSeries *>(series)->m_axes);
1027 else if (qobject_cast<DeclarativeStackedBarSeries *>(series))
1015 else if (qobject_cast<DeclarativeStackedBarSeries *>(series))
1028 doInitializeAxes(series, qobject_cast<DeclarativeStackedBarSeries *>(series)->m_axes);
1016 doInitializeAxes(series, qobject_cast<DeclarativeStackedBarSeries *>(series)->m_axes);
1029 else if (qobject_cast<DeclarativePercentBarSeries *>(series))
1017 else if (qobject_cast<DeclarativePercentBarSeries *>(series))
1030 doInitializeAxes(series, qobject_cast<DeclarativePercentBarSeries *>(series)->m_axes);
1018 doInitializeAxes(series, qobject_cast<DeclarativePercentBarSeries *>(series)->m_axes);
1031 else if (qobject_cast<DeclarativeHorizontalBarSeries *>(series))
1019 else if (qobject_cast<DeclarativeHorizontalBarSeries *>(series))
1032 doInitializeAxes(series, qobject_cast<DeclarativeHorizontalBarSeries *>(series)->m_axes);
1020 doInitializeAxes(series, qobject_cast<DeclarativeHorizontalBarSeries *>(series)->m_axes);
1033 else if (qobject_cast<DeclarativeHorizontalStackedBarSeries *>(series))
1021 else if (qobject_cast<DeclarativeHorizontalStackedBarSeries *>(series))
1034 doInitializeAxes(series, qobject_cast<DeclarativeHorizontalStackedBarSeries *>(series)->m_axes);
1022 doInitializeAxes(series, qobject_cast<DeclarativeHorizontalStackedBarSeries *>(series)->m_axes);
1035 else if (qobject_cast<DeclarativeHorizontalPercentBarSeries *>(series))
1023 else if (qobject_cast<DeclarativeHorizontalPercentBarSeries *>(series))
1036 doInitializeAxes(series, qobject_cast<DeclarativeHorizontalPercentBarSeries *>(series)->m_axes);
1024 doInitializeAxes(series, qobject_cast<DeclarativeHorizontalPercentBarSeries *>(series)->m_axes);
1037 else if (qobject_cast<DeclarativeBoxPlotSeries *>(series))
1025 else if (qobject_cast<DeclarativeBoxPlotSeries *>(series))
1038 doInitializeAxes(series, qobject_cast<DeclarativeBoxPlotSeries *>(series)->m_axes);
1026 doInitializeAxes(series, qobject_cast<DeclarativeBoxPlotSeries *>(series)->m_axes);
1039 // else: do nothing
1027 // else: do nothing
1040 }
1028 }
1041
1029
1042 void DeclarativeChart::doInitializeAxes(QAbstractSeries *series, DeclarativeAxes *axes)
1030 void DeclarativeChart::doInitializeAxes(QAbstractSeries *series, DeclarativeAxes *axes)
1043 {
1031 {
1044 // Initialize axis X
1032 // Initialize axis X
1045 if (axes->axisX())
1033 if (axes->axisX())
1046 axes->emitAxisXChanged();
1034 axes->emitAxisXChanged();
1047 else if (axes->axisXTop())
1035 else if (axes->axisXTop())
1048 axes->emitAxisXTopChanged();
1036 axes->emitAxisXTopChanged();
1049 else
1037 else
1050 axes->setAxisX(defaultAxis(Qt::Horizontal, series));
1038 axes->setAxisX(defaultAxis(Qt::Horizontal, series));
1051
1039
1052 // Initialize axis Y
1040 // Initialize axis Y
1053 if (axes->axisY())
1041 if (axes->axisY())
1054 axes->emitAxisYChanged();
1042 axes->emitAxisYChanged();
1055 else if (axes->axisYRight())
1043 else if (axes->axisYRight())
1056 axes->emitAxisYRightChanged();
1044 axes->emitAxisYRightChanged();
1057 else
1045 else
1058 axes->setAxisY(defaultAxis(Qt::Vertical, series));
1046 axes->setAxisY(defaultAxis(Qt::Vertical, series));
1059 }
1047 }
1060
1048
1061 #include "moc_declarativechart.cpp"
1049 #include "moc_declarativechart.cpp"
1062
1050
1063 QT_CHARTS_END_NAMESPACE
1051 QT_CHARTS_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now