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