##// END OF EJS Templates
Fixed a bug in ChartView.axes property when no series added
Tero Ahola -
r2300:20fb6c76ccf2
parent child
Show More
@@ -1,769 +1,769
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "declarativechart.h"
21 #include "declarativechart.h"
22 #include <QPainter>
22 #include <QPainter>
23 #include <QDeclarativeEngine>
23 #include <QDeclarativeEngine>
24 #include "declarativelineseries.h"
24 #include "declarativelineseries.h"
25 #include "declarativeareaseries.h"
25 #include "declarativeareaseries.h"
26 #include "declarativebarseries.h"
26 #include "declarativebarseries.h"
27 #include "declarativepieseries.h"
27 #include "declarativepieseries.h"
28 #include "declarativesplineseries.h"
28 #include "declarativesplineseries.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 "qcategoryaxis.h"
32 #include "qcategoryaxis.h"
33 #include "qabstractseries_p.h"
33 #include "qabstractseries_p.h"
34 #include "declarativemargins.h"
34 #include "declarativemargins.h"
35 #include "chartdataset_p.h"
35 #include "chartdataset_p.h"
36 #include "declarativeaxes.h"
36 #include "declarativeaxes.h"
37 #include "qchart_p.h"
37 #include "qchart_p.h"
38
38
39 #ifndef QT_ON_ARM
39 #ifndef QT_ON_ARM
40 #include "qdatetimeaxis.h"
40 #include "qdatetimeaxis.h"
41 #endif
41 #endif
42
42
43 QTCOMMERCIALCHART_BEGIN_NAMESPACE
43 QTCOMMERCIALCHART_BEGIN_NAMESPACE
44
44
45 /*!
45 /*!
46 \qmlclass ChartView DeclarativeChart
46 \qmlclass ChartView DeclarativeChart
47
47
48 ChartView element is the parent that is responsible for showing different chart series types.
48 ChartView element is the parent that is responsible for showing different chart series types.
49
49
50 The following QML shows how to create a simple chart with one pie series:
50 The following QML shows how to create a simple chart with one pie series:
51 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 1
51 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 1
52 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2
52 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2
53 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 3
53 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 3
54
54
55 \beginfloatleft
55 \beginfloatleft
56 \image examples_qmlpiechart.png
56 \image examples_qmlpiechart.png
57 \endfloat
57 \endfloat
58 \clearfloat
58 \clearfloat
59 */
59 */
60
60
61 /*!
61 /*!
62 \qmlproperty Theme ChartView::theme
62 \qmlproperty Theme ChartView::theme
63 Theme defines the visual appearance of the chart, including for example colors, fonts, line
63 Theme defines the visual appearance of the chart, including for example colors, fonts, line
64 widths and chart background.
64 widths and chart background.
65 */
65 */
66
66
67 /*!
67 /*!
68 \qmlproperty Animation ChartView::animationOptions
68 \qmlproperty Animation ChartView::animationOptions
69 Animation configuration of the chart. One of ChartView.NoAnimation, ChartView.GridAxisAnimations,
69 Animation configuration of the chart. One of ChartView.NoAnimation, ChartView.GridAxisAnimations,
70 ChartView.SeriesAnimations or ChartView.AllAnimations.
70 ChartView.SeriesAnimations or ChartView.AllAnimations.
71 */
71 */
72
72
73 /*!
73 /*!
74 \qmlproperty Font ChartView::titleFont
74 \qmlproperty Font ChartView::titleFont
75 The title font of the chart
75 The title font of the chart
76
76
77 See the \l {Font} {QML Font Element} for detailed documentation.
77 See the \l {Font} {QML Font Element} for detailed documentation.
78 */
78 */
79
79
80 /*!
80 /*!
81 \qmlproperty string ChartView::title
81 \qmlproperty string ChartView::title
82 The title of the chart, shown on top of the chart.
82 The title of the chart, shown on top of the chart.
83 \sa ChartView::titleColor
83 \sa ChartView::titleColor
84 */
84 */
85
85
86 /*!
86 /*!
87 \qmlproperty color ChartView::titleColor
87 \qmlproperty color ChartView::titleColor
88 The color of the title text.
88 The color of the title text.
89 */
89 */
90
90
91 /*!
91 /*!
92 \qmlproperty Legend ChartView::legend
92 \qmlproperty Legend ChartView::legend
93 The legend of the chart. Legend lists all the series, pie slices and bar sets added on the chart.
93 The legend of the chart. Legend lists all the series, pie slices and bar sets added on the chart.
94 */
94 */
95
95
96 /*!
96 /*!
97 \qmlproperty int ChartView::count
97 \qmlproperty int ChartView::count
98 The count of series added to the chart.
98 The count of series added to the chart.
99 */
99 */
100
100
101 /*!
101 /*!
102 \qmlproperty color ChartView::backgroundColor
102 \qmlproperty color ChartView::backgroundColor
103 The color of the chart's background. By default background color is defined by chart theme.
103 The color of the chart's background. By default background color is defined by chart theme.
104 \sa ChartView::theme
104 \sa ChartView::theme
105 */
105 */
106
106
107 /*!
107 /*!
108 \qmlproperty bool ChartView::dropShadowEnabled
108 \qmlproperty bool ChartView::dropShadowEnabled
109 The chart's border drop shadow. Set to true to enable drop shadow.
109 The chart's border drop shadow. Set to true to enable drop shadow.
110 */
110 */
111
111
112 /*!
112 /*!
113 \qmlproperty real ChartView::topMargin
113 \qmlproperty real ChartView::topMargin
114 Deprecated. Use minimumMargins and plotArea instead.
114 Deprecated. Use minimumMargins and plotArea instead.
115 */
115 */
116
116
117 /*!
117 /*!
118 \qmlproperty real ChartView::bottomMargin
118 \qmlproperty real ChartView::bottomMargin
119 Deprecated. Use minimumMargins and plotArea instead.
119 Deprecated. Use minimumMargins and plotArea instead.
120 */
120 */
121
121
122 /*!
122 /*!
123 \qmlproperty real ChartView::leftMargin
123 \qmlproperty real ChartView::leftMargin
124 Deprecated. Use minimumMargins and plotArea instead.
124 Deprecated. Use minimumMargins and plotArea instead.
125 */
125 */
126
126
127 /*!
127 /*!
128 \qmlproperty real ChartView::rightMargin
128 \qmlproperty real ChartView::rightMargin
129 Deprecated. Use minimumMargins and plotArea instead.
129 Deprecated. Use minimumMargins and plotArea instead.
130 */
130 */
131
131
132 /*!
132 /*!
133 \qmlproperty Margins ChartView::minimumMargins
133 \qmlproperty Margins ChartView::minimumMargins
134 The minimum margins allowed between the outer bounds and the plotArea of the ChartView. Margins
134 The minimum margins allowed between the outer bounds and the plotArea of the ChartView. Margins
135 area of ChartView is used for drawing title, axes and legend. Please note that setting the
135 area of ChartView is used for drawing title, axes and legend. Please note that setting the
136 properties of minimumMargins may be bigger than the defined value, depending on other ChartView
136 properties of minimumMargins may be bigger than the defined value, depending on other ChartView
137 properties that affect it's layout. If you need to know the actual plotting area used at any
137 properties that affect it's layout. If you need to know the actual plotting area used at any
138 given time, you can check ChartView::plotArea instead.
138 given time, you can check ChartView::plotArea instead.
139 */
139 */
140
140
141 /*!
141 /*!
142 \qmlproperty rect ChartView::plotArea
142 \qmlproperty rect ChartView::plotArea
143 The area on the ChartView that is used for drawing series. This is the ChartView rect without the
143 The area on the ChartView that is used for drawing series. This is the ChartView rect without the
144 margins.
144 margins.
145 \sa ChartView::minimumMargins
145 \sa ChartView::minimumMargins
146 */
146 */
147
147
148 /*!
148 /*!
149 \qmlmethod AbstractSeries ChartView::series(int index)
149 \qmlmethod AbstractSeries ChartView::series(int index)
150 Returns the series with \a index on the chart. This allows you to loop through the series of a chart together with
150 Returns the series with \a index on the chart. This allows you to loop through the series of a chart together with
151 the count property of the chart.
151 the count property of the chart.
152 */
152 */
153
153
154 /*!
154 /*!
155 \qmlmethod AbstractSeries ChartView::series(string name)
155 \qmlmethod AbstractSeries ChartView::series(string name)
156 Returns the first series on the chart with \a name. If there is no series with that name, returns null.
156 Returns the first series on the chart with \a name. If there is no series with that name, returns null.
157 */
157 */
158
158
159 /*!
159 /*!
160 \qmlmethod AbstractSeries ChartView::createSeries(SeriesType type, string name, AbstractAxis axisX, AbstractAxis axisY)
160 \qmlmethod AbstractSeries ChartView::createSeries(SeriesType type, string name, AbstractAxis axisX, AbstractAxis axisY)
161 Creates a series object of \a type to the chart with name \a name, optional axis \a axisX and
161 Creates a series object of \a type to the chart with name \a name, optional axis \a axisX and
162 optional axis \a axisY. For example:
162 optional axis \a axisY. For example:
163 \code
163 \code
164 // lineSeries is a LineSeries object that has already been added to the ChartView; re-use it's axes
164 // lineSeries is a LineSeries object that has already been added to the ChartView; re-use it's axes
165 var myAxisX = chartView.axisX(lineSeries);
165 var myAxisX = chartView.axisX(lineSeries);
166 var myAxisY = chartView.axisY(lineSeries);
166 var myAxisY = chartView.axisY(lineSeries);
167 var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter series", myAxisX, myAxisY);
167 var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter series", myAxisX, myAxisY);
168 \endcode
168 \endcode
169 */
169 */
170
170
171 /*!
171 /*!
172 \qmlmethod ChartView::removeSeries(AbstractSeries series)
172 \qmlmethod ChartView::removeSeries(AbstractSeries series)
173 Removes the \a series from the chart. The series object is also destroyed.
173 Removes the \a series from the chart. The series object is also destroyed.
174 */
174 */
175
175
176 /*!
176 /*!
177 \qmlmethod ChartView::removeAllSeries()
177 \qmlmethod ChartView::removeAllSeries()
178 Removes all series from the chart. All the series objects are also destroyed.
178 Removes all series from the chart. All the series objects are also destroyed.
179 */
179 */
180
180
181 /*!
181 /*!
182 \qmlmethod Axis ChartView::axisX(AbstractSeries series)
182 \qmlmethod Axis ChartView::axisX(AbstractSeries series)
183 The x-axis of the series.
183 The x-axis of the series.
184 */
184 */
185
185
186 /*!
186 /*!
187 \qmlmethod Axis ChartView::axisY(AbstractSeries series)
187 \qmlmethod Axis ChartView::axisY(AbstractSeries series)
188 The y-axis of the series.
188 The y-axis of the series.
189 */
189 */
190
190
191 /*!
191 /*!
192 \qmlmethod ChartView::zoomY(real factor)
192 \qmlmethod ChartView::zoomY(real factor)
193 Zooms in by \a factor on the center of the chart.
193 Zooms in by \a factor on the center of the chart.
194 */
194 */
195
195
196 /*!
196 /*!
197 \qmlmethod ChartView::scrollLeft(real pixels)
197 \qmlmethod ChartView::scrollLeft(real pixels)
198 Scrolls to left by \a pixels. This is a convenience function that suits for example for key navigation.
198 Scrolls to left by \a pixels. This is a convenience function that suits for example for key navigation.
199 \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max
199 \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max
200 */
200 */
201
201
202 /*!
202 /*!
203 \qmlmethod ChartView::scrollRight(real pixels)
203 \qmlmethod ChartView::scrollRight(real pixels)
204 Scrolls to right by \a pixels. This is a convenience function that suits for example for key navigation.
204 Scrolls to right by \a pixels. This is a convenience function that suits for example for key navigation.
205 \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max
205 \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max
206 */
206 */
207
207
208 /*!
208 /*!
209 \qmlmethod ChartView::scrollUp(real pixels)
209 \qmlmethod ChartView::scrollUp(real pixels)
210 Scrolls up by \a pixels. This is a convenience function that suits for example for key navigation.
210 Scrolls up by \a pixels. This is a convenience function that suits for example for key navigation.
211 \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max
211 \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max
212 */
212 */
213
213
214 /*!
214 /*!
215 \qmlmethod ChartView::scrollDown(real pixels)
215 \qmlmethod ChartView::scrollDown(real pixels)
216 Scrolls down by \a pixels. This is a convenience function that suits for example for key navigation.
216 Scrolls down by \a pixels. This is a convenience function that suits for example for key navigation.
217 \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max
217 \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max
218 */
218 */
219
219
220 /*!
220 /*!
221 \qmlsignal ChartView::onPlotAreaChanged(rect plotArea)
221 \qmlsignal ChartView::onPlotAreaChanged(rect plotArea)
222 The plot area of the chart has changed. This may happen for example, if you modify minimumMargins
222 The plot area of the chart has changed. This may happen for example, if you modify minimumMargins
223 or if you resize the chart, or if you modify font size related properties of the legend or chart
223 or if you resize the chart, or if you modify font size related properties of the legend or chart
224 title.
224 title.
225 */
225 */
226
226
227 /*!
227 /*!
228 \qmlsignal ChartView::seriesAdded(AbstractSeries series)
228 \qmlsignal ChartView::seriesAdded(AbstractSeries series)
229 The \a series has been added to the chart.
229 The \a series has been added to the chart.
230 */
230 */
231
231
232 /*!
232 /*!
233 \qmlsignal ChartView::seriesRemoved(AbstractSeries series)
233 \qmlsignal ChartView::seriesRemoved(AbstractSeries series)
234 The \a series has been removed from the chart. Please note that \a series is no longer a valid
234 The \a series has been removed from the chart. Please note that \a series is no longer a valid
235 object after the signal handler has completed.
235 object after the signal handler has completed.
236 */
236 */
237
237
238 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent)
238 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent)
239 : QDeclarativeItem(parent),
239 : QDeclarativeItem(parent),
240 m_chart(new QChart(this))
240 m_chart(new QChart(this))
241 {
241 {
242 setFlag(QGraphicsItem::ItemHasNoContents, false);
242 setFlag(QGraphicsItem::ItemHasNoContents, false);
243 m_margins = new DeclarativeMargins(this);
243 m_margins = new DeclarativeMargins(this);
244 m_margins->setTop(m_chart->margins().top());
244 m_margins->setTop(m_chart->margins().top());
245 m_margins->setLeft(m_chart->margins().left());
245 m_margins->setLeft(m_chart->margins().left());
246 m_margins->setRight(m_chart->margins().right());
246 m_margins->setRight(m_chart->margins().right());
247 m_margins->setBottom(m_chart->margins().bottom());
247 m_margins->setBottom(m_chart->margins().bottom());
248 connect(m_margins, SIGNAL(topChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int)));
248 connect(m_margins, SIGNAL(topChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int)));
249 connect(m_margins, SIGNAL(bottomChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int)));
249 connect(m_margins, SIGNAL(bottomChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int)));
250 connect(m_margins, SIGNAL(leftChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int)));
250 connect(m_margins, SIGNAL(leftChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int)));
251 connect(m_margins, SIGNAL(rightChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int)));
251 connect(m_margins, SIGNAL(rightChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int)));
252 connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), this, SLOT(handleSeriesAdded(QAbstractSeries*)));
252 connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), this, SLOT(handleSeriesAdded(QAbstractSeries*)));
253 connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), this, SIGNAL(seriesRemoved(QAbstractSeries*)));
253 connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), this, SIGNAL(seriesRemoved(QAbstractSeries*)));
254 }
254 }
255
255
256 void DeclarativeChart::handleSeriesAdded(QAbstractSeries *series)
256 void DeclarativeChart::handleSeriesAdded(QAbstractSeries *series)
257 {
257 {
258 emit seriesAdded(series);
258 emit seriesAdded(series);
259 }
259 }
260
260
261 void DeclarativeChart::changeMinimumMargins(int top, int bottom, int left, int right)
261 void DeclarativeChart::changeMinimumMargins(int top, int bottom, int left, int right)
262 {
262 {
263 m_chart->setMargins(QMargins(left, top, right, bottom));
263 m_chart->setMargins(QMargins(left, top, right, bottom));
264 emit minimumMarginsChanged();
264 emit minimumMarginsChanged();
265 emit plotAreaChanged(m_chart->plotArea());
265 emit plotAreaChanged(m_chart->plotArea());
266 }
266 }
267
267
268 DeclarativeChart::~DeclarativeChart()
268 DeclarativeChart::~DeclarativeChart()
269 {
269 {
270 delete m_chart;
270 delete m_chart;
271 }
271 }
272
272
273 void DeclarativeChart::childEvent(QChildEvent *event)
273 void DeclarativeChart::childEvent(QChildEvent *event)
274 {
274 {
275 if (event->type() == QEvent::ChildAdded) {
275 if (event->type() == QEvent::ChildAdded) {
276 if (qobject_cast<QAbstractSeries *>(event->child())) {
276 if (qobject_cast<QAbstractSeries *>(event->child())) {
277 m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child()));
277 m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child()));
278 }
278 }
279 }
279 }
280 }
280 }
281
281
282 void DeclarativeChart::componentComplete()
282 void DeclarativeChart::componentComplete()
283 {
283 {
284 foreach (QObject *child, children()) {
284 foreach (QObject *child, children()) {
285 if (qobject_cast<QAbstractSeries *>(child)) {
285 if (qobject_cast<QAbstractSeries *>(child)) {
286 // Add series to the chart
286 // Add series to the chart
287 QAbstractSeries *series = qobject_cast<QAbstractSeries *>(child);
287 QAbstractSeries *series = qobject_cast<QAbstractSeries *>(child);
288 m_chart->addSeries(series);
288 m_chart->addSeries(series);
289
289
290 // Connect to axis changed signals (unless this is a pie series)
290 // Connect to axis changed signals (unless this is a pie series)
291 if (!qobject_cast<DeclarativePieSeries *>(series)) {
291 if (!qobject_cast<DeclarativePieSeries *>(series)) {
292 connect(series, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
292 connect(series, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
293 connect(series, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
293 connect(series, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
294 connect(series, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*)));
294 connect(series, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*)));
295 connect(series, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SLOT(handleAxisYRightSet(QAbstractAxis*)));
295 connect(series, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SLOT(handleAxisYRightSet(QAbstractAxis*)));
296 }
296 }
297
297
298 initializeAxes(series);
298 initializeAxes(series);
299 }
299 }
300 }
300 }
301
301
302 QDeclarativeItem::componentComplete();
302 QDeclarativeItem::componentComplete();
303 }
303 }
304
304
305 void DeclarativeChart::handleAxisXSet(QAbstractAxis *axis)
305 void DeclarativeChart::handleAxisXSet(QAbstractAxis *axis)
306 {
306 {
307 QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender());
307 QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender());
308 if (axis && s) {
308 if (axis && s) {
309 if (!m_chart->axes(Qt::Horizontal).contains(axis))
309 if (!m_chart->axes(Qt::Horizontal).contains(axis))
310 m_chart->addAxis(axis, Qt::AlignBottom);
310 m_chart->addAxis(axis, Qt::AlignBottom);
311 if (!s->attachedAxes().contains(axis))
311 if (!s->attachedAxes().contains(axis))
312 s->attachAxis(axis);
312 s->attachAxis(axis);
313 } else {
313 } else {
314 qWarning() << "Trying to set axisX to null.";
314 qWarning() << "Trying to set axisX to null.";
315 }
315 }
316 }
316 }
317
317
318 void DeclarativeChart::handleAxisXTopSet(QAbstractAxis *axis)
318 void DeclarativeChart::handleAxisXTopSet(QAbstractAxis *axis)
319 {
319 {
320 QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender());
320 QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender());
321 if (axis && s) {
321 if (axis && s) {
322 if (!m_chart->axes(Qt::Horizontal).contains(axis))
322 if (!m_chart->axes(Qt::Horizontal).contains(axis))
323 m_chart->addAxis(axis, Qt::AlignTop);
323 m_chart->addAxis(axis, Qt::AlignTop);
324 if (!s->attachedAxes().contains(axis))
324 if (!s->attachedAxes().contains(axis))
325 s->attachAxis(axis);
325 s->attachAxis(axis);
326 } else {
326 } else {
327 qWarning() << "Trying to set axisXTop to null.";
327 qWarning() << "Trying to set axisXTop to null.";
328 }
328 }
329 }
329 }
330
330
331 void DeclarativeChart::handleAxisYSet(QAbstractAxis *axis)
331 void DeclarativeChart::handleAxisYSet(QAbstractAxis *axis)
332 {
332 {
333 QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender());
333 QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender());
334 if (axis && s) {
334 if (axis && s) {
335 if (!m_chart->axes(Qt::Vertical).contains(axis))
335 if (!m_chart->axes(Qt::Vertical).contains(axis))
336 m_chart->addAxis(axis, Qt::AlignLeft);
336 m_chart->addAxis(axis, Qt::AlignLeft);
337 if (!s->attachedAxes().contains(axis))
337 if (!s->attachedAxes().contains(axis))
338 s->attachAxis(axis);
338 s->attachAxis(axis);
339 } else {
339 } else {
340 qWarning() << "Trying to set axisY to null.";
340 qWarning() << "Trying to set axisY to null.";
341 }
341 }
342 }
342 }
343
343
344 void DeclarativeChart::handleAxisYRightSet(QAbstractAxis *axis)
344 void DeclarativeChart::handleAxisYRightSet(QAbstractAxis *axis)
345 {
345 {
346 QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender());
346 QAbstractSeries *s = qobject_cast<QAbstractSeries *>(sender());
347 if (axis && s) {
347 if (axis && s) {
348 if (!m_chart->axes(Qt::Vertical).contains(axis))
348 if (!m_chart->axes(Qt::Vertical).contains(axis))
349 m_chart->addAxis(axis, Qt::AlignRight);
349 m_chart->addAxis(axis, Qt::AlignRight);
350 if (!s->attachedAxes().contains(axis))
350 if (!s->attachedAxes().contains(axis))
351 s->attachAxis(axis);
351 s->attachAxis(axis);
352 } else {
352 } else {
353 qWarning() << "Trying to set axisYRight to null.";
353 qWarning() << "Trying to set axisYRight to null.";
354 }
354 }
355 }
355 }
356
356
357 void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
357 void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
358 {
358 {
359 // qDebug() << "DeclarativeChart::geometryChanged" << newGeometry.width() << newGeometry.height();
359 // qDebug() << "DeclarativeChart::geometryChanged" << newGeometry.width() << newGeometry.height();
360 if (newGeometry.isValid()) {
360 if (newGeometry.isValid()) {
361 if (newGeometry.width() > 0 && newGeometry.height() > 0) {
361 if (newGeometry.width() > 0 && newGeometry.height() > 0) {
362 m_chart->resize(newGeometry.width(), newGeometry.height());
362 m_chart->resize(newGeometry.width(), newGeometry.height());
363 }
363 }
364 }
364 }
365 QDeclarativeItem::geometryChanged(newGeometry, oldGeometry);
365 QDeclarativeItem::geometryChanged(newGeometry, oldGeometry);
366
366
367 // It would be better to trigger the plotAreaChanged signal from QChart::plotAreaChanged or
367 // It would be better to trigger the plotAreaChanged signal from QChart::plotAreaChanged or
368 // similar. Since that kind of a signal is not clearly needed in the C++ API the work-around is
368 // similar. Since that kind of a signal is not clearly needed in the C++ API the work-around is
369 // to implement it here for the QML API purposes.
369 // to implement it here for the QML API purposes.
370 emit plotAreaChanged(m_chart->plotArea());
370 emit plotAreaChanged(m_chart->plotArea());
371 }
371 }
372
372
373 void DeclarativeChart::setTheme(DeclarativeChart::Theme theme)
373 void DeclarativeChart::setTheme(DeclarativeChart::Theme theme)
374 {
374 {
375 QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme;
375 QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme;
376 if (chartTheme != m_chart->theme())
376 if (chartTheme != m_chart->theme())
377 m_chart->setTheme(chartTheme);
377 m_chart->setTheme(chartTheme);
378 }
378 }
379
379
380 DeclarativeChart::Theme DeclarativeChart::theme()
380 DeclarativeChart::Theme DeclarativeChart::theme()
381 {
381 {
382 return (DeclarativeChart::Theme) m_chart->theme();
382 return (DeclarativeChart::Theme) m_chart->theme();
383 }
383 }
384
384
385 void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations)
385 void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations)
386 {
386 {
387 QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations;
387 QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations;
388 if (animationOptions != m_chart->animationOptions())
388 if (animationOptions != m_chart->animationOptions())
389 m_chart->setAnimationOptions(animationOptions);
389 m_chart->setAnimationOptions(animationOptions);
390 }
390 }
391
391
392 DeclarativeChart::Animation DeclarativeChart::animationOptions()
392 DeclarativeChart::Animation DeclarativeChart::animationOptions()
393 {
393 {
394 if (m_chart->animationOptions().testFlag(QChart::AllAnimations))
394 if (m_chart->animationOptions().testFlag(QChart::AllAnimations))
395 return DeclarativeChart::AllAnimations;
395 return DeclarativeChart::AllAnimations;
396 else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations))
396 else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations))
397 return DeclarativeChart::GridAxisAnimations;
397 return DeclarativeChart::GridAxisAnimations;
398 else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations))
398 else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations))
399 return DeclarativeChart::SeriesAnimations;
399 return DeclarativeChart::SeriesAnimations;
400 else
400 else
401 return DeclarativeChart::NoAnimation;
401 return DeclarativeChart::NoAnimation;
402 }
402 }
403
403
404 void DeclarativeChart::setTitle(QString title)
404 void DeclarativeChart::setTitle(QString title)
405 {
405 {
406 if (title != m_chart->title())
406 if (title != m_chart->title())
407 m_chart->setTitle(title);
407 m_chart->setTitle(title);
408 }
408 }
409 QString DeclarativeChart::title()
409 QString DeclarativeChart::title()
410 {
410 {
411 return m_chart->title();
411 return m_chart->title();
412 }
412 }
413
413
414 QAbstractAxis *DeclarativeChart::axisX(QAbstractSeries *series)
414 QAbstractAxis *DeclarativeChart::axisX(QAbstractSeries *series)
415 {
415 {
416 QList<QAbstractAxis *> axes = m_chart->axes(Qt::Horizontal, series);
416 QList<QAbstractAxis *> axes = m_chart->axes(Qt::Horizontal, series);
417 if (axes.count())
417 if (axes.count())
418 return axes[0];
418 return axes[0];
419 return 0;
419 return 0;
420 }
420 }
421
421
422 QAbstractAxis *DeclarativeChart::axisY(QAbstractSeries *series)
422 QAbstractAxis *DeclarativeChart::axisY(QAbstractSeries *series)
423 {
423 {
424 QList<QAbstractAxis *> axes = m_chart->axes(Qt::Vertical, series);
424 QList<QAbstractAxis *> axes = m_chart->axes(Qt::Vertical, series);
425 if (axes.count())
425 if (axes.count())
426 return axes[0];
426 return axes[0];
427 return 0;
427 return 0;
428 }
428 }
429
429
430 QLegend *DeclarativeChart::legend()
430 QLegend *DeclarativeChart::legend()
431 {
431 {
432 return m_chart->legend();
432 return m_chart->legend();
433 }
433 }
434
434
435 void DeclarativeChart::setTitleColor(QColor color)
435 void DeclarativeChart::setTitleColor(QColor color)
436 {
436 {
437 QBrush b = m_chart->titleBrush();
437 QBrush b = m_chart->titleBrush();
438 if (color != b.color()) {
438 if (color != b.color()) {
439 b.setColor(color);
439 b.setColor(color);
440 m_chart->setTitleBrush(b);
440 m_chart->setTitleBrush(b);
441 emit titleColorChanged(color);
441 emit titleColorChanged(color);
442 }
442 }
443 }
443 }
444
444
445 QFont DeclarativeChart::titleFont() const
445 QFont DeclarativeChart::titleFont() const
446 {
446 {
447 return m_chart->titleFont();
447 return m_chart->titleFont();
448 }
448 }
449
449
450 void DeclarativeChart::setTitleFont(const QFont &font)
450 void DeclarativeChart::setTitleFont(const QFont &font)
451 {
451 {
452 m_chart->setTitleFont(font);
452 m_chart->setTitleFont(font);
453 }
453 }
454
454
455 QColor DeclarativeChart::titleColor()
455 QColor DeclarativeChart::titleColor()
456 {
456 {
457 return m_chart->titleBrush().color();
457 return m_chart->titleBrush().color();
458 }
458 }
459
459
460 void DeclarativeChart::setBackgroundColor(QColor color)
460 void DeclarativeChart::setBackgroundColor(QColor color)
461 {
461 {
462 QBrush b = m_chart->backgroundBrush();
462 QBrush b = m_chart->backgroundBrush();
463 if (b.style() != Qt::SolidPattern || color != b.color()) {
463 if (b.style() != Qt::SolidPattern || color != b.color()) {
464 b.setStyle(Qt::SolidPattern);
464 b.setStyle(Qt::SolidPattern);
465 b.setColor(color);
465 b.setColor(color);
466 m_chart->setBackgroundBrush(b);
466 m_chart->setBackgroundBrush(b);
467 emit backgroundColorChanged();
467 emit backgroundColorChanged();
468 }
468 }
469 }
469 }
470
470
471 QColor DeclarativeChart::backgroundColor()
471 QColor DeclarativeChart::backgroundColor()
472 {
472 {
473 return m_chart->backgroundBrush().color();
473 return m_chart->backgroundBrush().color();
474 }
474 }
475
475
476 int DeclarativeChart::count()
476 int DeclarativeChart::count()
477 {
477 {
478 return m_chart->series().count();
478 return m_chart->series().count();
479 }
479 }
480
480
481 void DeclarativeChart::setDropShadowEnabled(bool enabled)
481 void DeclarativeChart::setDropShadowEnabled(bool enabled)
482 {
482 {
483 if (enabled != m_chart->isDropShadowEnabled()) {
483 if (enabled != m_chart->isDropShadowEnabled()) {
484 m_chart->setDropShadowEnabled(enabled);
484 m_chart->setDropShadowEnabled(enabled);
485 dropShadowEnabledChanged(enabled);
485 dropShadowEnabledChanged(enabled);
486 }
486 }
487 }
487 }
488
488
489 bool DeclarativeChart::dropShadowEnabled()
489 bool DeclarativeChart::dropShadowEnabled()
490 {
490 {
491 return m_chart->isDropShadowEnabled();
491 return m_chart->isDropShadowEnabled();
492 }
492 }
493
493
494 qreal DeclarativeChart::topMargin()
494 qreal DeclarativeChart::topMargin()
495 {
495 {
496 qWarning() << "ChartView.topMargin is deprecated. Use minimumMargins and plotArea instead.";
496 qWarning() << "ChartView.topMargin is deprecated. Use minimumMargins and plotArea instead.";
497 return m_chart->plotArea().top();
497 return m_chart->plotArea().top();
498 }
498 }
499
499
500 qreal DeclarativeChart::bottomMargin()
500 qreal DeclarativeChart::bottomMargin()
501 {
501 {
502
502
503 qWarning() << "ChartView.bottomMargin is deprecated. Use minimumMargins and plotArea instead.";
503 qWarning() << "ChartView.bottomMargin is deprecated. Use minimumMargins and plotArea instead.";
504 return m_chart->plotArea().bottom();
504 return m_chart->plotArea().bottom();
505 }
505 }
506
506
507 qreal DeclarativeChart::leftMargin()
507 qreal DeclarativeChart::leftMargin()
508 {
508 {
509 qWarning() << "ChartView.leftMargin is deprecated. Use minimumMargins and plotArea instead.";
509 qWarning() << "ChartView.leftMargin is deprecated. Use minimumMargins and plotArea instead.";
510 return m_chart->plotArea().left();
510 return m_chart->plotArea().left();
511 }
511 }
512
512
513 qreal DeclarativeChart::rightMargin()
513 qreal DeclarativeChart::rightMargin()
514 {
514 {
515 qWarning() << "ChartView.rightMargin is deprecated. Use minimumMargins and plotArea instead.";
515 qWarning() << "ChartView.rightMargin is deprecated. Use minimumMargins and plotArea instead.";
516 return m_chart->plotArea().right();
516 return m_chart->plotArea().right();
517 }
517 }
518
518
519 void DeclarativeChart::zoom(qreal factor)
519 void DeclarativeChart::zoom(qreal factor)
520 {
520 {
521 m_chart->zoom(factor);
521 m_chart->zoom(factor);
522 }
522 }
523
523
524 void DeclarativeChart::scrollLeft(qreal pixels)
524 void DeclarativeChart::scrollLeft(qreal pixels)
525 {
525 {
526 m_chart->scroll(-pixels, 0);
526 m_chart->scroll(-pixels, 0);
527 }
527 }
528
528
529 void DeclarativeChart::scrollRight(qreal pixels)
529 void DeclarativeChart::scrollRight(qreal pixels)
530 {
530 {
531 m_chart->scroll(pixels, 0);
531 m_chart->scroll(pixels, 0);
532 }
532 }
533
533
534 void DeclarativeChart::scrollUp(qreal pixels)
534 void DeclarativeChart::scrollUp(qreal pixels)
535 {
535 {
536 m_chart->scroll(0, pixels);
536 m_chart->scroll(0, pixels);
537 }
537 }
538
538
539 void DeclarativeChart::scrollDown(qreal pixels)
539 void DeclarativeChart::scrollDown(qreal pixels)
540 {
540 {
541 m_chart->scroll(0, -pixels);
541 m_chart->scroll(0, -pixels);
542 }
542 }
543
543
544 QDeclarativeListProperty<QAbstractAxis> DeclarativeChart::axes()
544 QDeclarativeListProperty<QAbstractAxis> DeclarativeChart::axes()
545 {
545 {
546 return QDeclarativeListProperty<QAbstractAxis>(this, 0,
546 return QDeclarativeListProperty<QAbstractAxis>(this, 0,
547 &DeclarativeChart::axesAppendFunc,
547 &DeclarativeChart::axesAppendFunc,
548 &DeclarativeChart::axesCountFunc,
548 &DeclarativeChart::axesCountFunc,
549 &DeclarativeChart::axesAtFunc);
549 &DeclarativeChart::axesAtFunc);
550 }
550 }
551
551
552 void DeclarativeChart::axesAppendFunc(QDeclarativeListProperty<QAbstractAxis> *list, QAbstractAxis *element)
552 void DeclarativeChart::axesAppendFunc(QDeclarativeListProperty<QAbstractAxis> *list, QAbstractAxis *element)
553 {
553 {
554 // Empty implementation
554 // Empty implementation
555 Q_UNUSED(list);
555 Q_UNUSED(list);
556 Q_UNUSED(element);
556 Q_UNUSED(element);
557 }
557 }
558
558
559 int DeclarativeChart::axesCountFunc(QDeclarativeListProperty<QAbstractAxis> *list)
559 int DeclarativeChart::axesCountFunc(QDeclarativeListProperty<QAbstractAxis> *list)
560 {
560 {
561 if (qobject_cast<DeclarativeChart *>(list->object)) {
561 if (qobject_cast<DeclarativeChart *>(list->object)) {
562 DeclarativeChart *chart = qobject_cast<DeclarativeChart *>(list->object);
562 DeclarativeChart *chart = qobject_cast<DeclarativeChart *>(list->object);
563 return chart->m_chart->axes(Qt::Horizontal | Qt::Vertical, chart->m_chart->series()[0]).count();
563 return chart->m_chart->axes(Qt::Horizontal | Qt::Vertical).count();
564 }
564 }
565 return 0;
565 return 0;
566 }
566 }
567
567
568 QAbstractAxis *DeclarativeChart::axesAtFunc(QDeclarativeListProperty<QAbstractAxis> *list, int index)
568 QAbstractAxis *DeclarativeChart::axesAtFunc(QDeclarativeListProperty<QAbstractAxis> *list, int index)
569 {
569 {
570 if (qobject_cast<DeclarativeChart *>(list->object)) {
570 if (qobject_cast<DeclarativeChart *>(list->object)) {
571 DeclarativeChart *chart = qobject_cast<DeclarativeChart *>(list->object);
571 DeclarativeChart *chart = qobject_cast<DeclarativeChart *>(list->object);
572 QList<QAbstractAxis *> axes = chart->m_chart->axes(Qt::Horizontal | Qt::Vertical, chart->m_chart->series()[0]);
572 QList<QAbstractAxis *> axes = chart->m_chart->axes(Qt::Horizontal | Qt::Vertical, chart->m_chart->series()[0]);
573 return axes.at(index);
573 return axes.at(index);
574 }
574 }
575 return 0;
575 return 0;
576 }
576 }
577
577
578 QAbstractSeries *DeclarativeChart::series(int index)
578 QAbstractSeries *DeclarativeChart::series(int index)
579 {
579 {
580 if (index < m_chart->series().count()) {
580 if (index < m_chart->series().count()) {
581 return m_chart->series().at(index);
581 return m_chart->series().at(index);
582 }
582 }
583 return 0;
583 return 0;
584 }
584 }
585
585
586 QAbstractSeries *DeclarativeChart::series(QString seriesName)
586 QAbstractSeries *DeclarativeChart::series(QString seriesName)
587 {
587 {
588 foreach (QAbstractSeries *series, m_chart->series()) {
588 foreach (QAbstractSeries *series, m_chart->series()) {
589 if (series->name() == seriesName)
589 if (series->name() == seriesName)
590 return series;
590 return series;
591 }
591 }
592 return 0;
592 return 0;
593 }
593 }
594
594
595 QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name)
595 QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name)
596 {
596 {
597 return createSeries(type, name, 0, 0);
597 return createSeries(type, name, 0, 0);
598 }
598 }
599
599
600 QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name, QAbstractAxis *axisX, QAbstractAxis *axisY)
600 QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name, QAbstractAxis *axisX, QAbstractAxis *axisY)
601 {
601 {
602 QAbstractSeries *series = 0;
602 QAbstractSeries *series = 0;
603
603
604 switch (type) {
604 switch (type) {
605 case DeclarativeChart::SeriesTypeLine:
605 case DeclarativeChart::SeriesTypeLine:
606 series = new DeclarativeLineSeries();
606 series = new DeclarativeLineSeries();
607 break;
607 break;
608 case DeclarativeChart::SeriesTypeArea: {
608 case DeclarativeChart::SeriesTypeArea: {
609 DeclarativeAreaSeries *area = new DeclarativeAreaSeries();
609 DeclarativeAreaSeries *area = new DeclarativeAreaSeries();
610 area->setUpperSeries(new DeclarativeLineSeries());
610 area->setUpperSeries(new DeclarativeLineSeries());
611 series = area;
611 series = area;
612 break;
612 break;
613 }
613 }
614 case DeclarativeChart::SeriesTypeStackedBar:
614 case DeclarativeChart::SeriesTypeStackedBar:
615 series = new DeclarativeStackedBarSeries();
615 series = new DeclarativeStackedBarSeries();
616 break;
616 break;
617 case DeclarativeChart::SeriesTypePercentBar:
617 case DeclarativeChart::SeriesTypePercentBar:
618 series = new DeclarativePercentBarSeries();
618 series = new DeclarativePercentBarSeries();
619 break;
619 break;
620 case DeclarativeChart::SeriesTypeBar:
620 case DeclarativeChart::SeriesTypeBar:
621 series = new DeclarativeBarSeries();
621 series = new DeclarativeBarSeries();
622 break;
622 break;
623 case DeclarativeChart::SeriesTypeHorizontalBar:
623 case DeclarativeChart::SeriesTypeHorizontalBar:
624 series = new DeclarativeHorizontalBarSeries();
624 series = new DeclarativeHorizontalBarSeries();
625 break;
625 break;
626 case DeclarativeChart::SeriesTypeHorizontalPercentBar:
626 case DeclarativeChart::SeriesTypeHorizontalPercentBar:
627 series = new DeclarativeHorizontalPercentBarSeries();
627 series = new DeclarativeHorizontalPercentBarSeries();
628 break;
628 break;
629 case DeclarativeChart::SeriesTypeHorizontalStackedBar:
629 case DeclarativeChart::SeriesTypeHorizontalStackedBar:
630 series = new DeclarativeHorizontalStackedBarSeries();
630 series = new DeclarativeHorizontalStackedBarSeries();
631 break;
631 break;
632 case DeclarativeChart::SeriesTypePie:
632 case DeclarativeChart::SeriesTypePie:
633 series = new DeclarativePieSeries();
633 series = new DeclarativePieSeries();
634 break;
634 break;
635 case DeclarativeChart::SeriesTypeScatter:
635 case DeclarativeChart::SeriesTypeScatter:
636 series = new DeclarativeScatterSeries();
636 series = new DeclarativeScatterSeries();
637 break;
637 break;
638 case DeclarativeChart::SeriesTypeSpline:
638 case DeclarativeChart::SeriesTypeSpline:
639 series = new DeclarativeSplineSeries();
639 series = new DeclarativeSplineSeries();
640 break;
640 break;
641 default:
641 default:
642 qWarning() << "Illegal series type";
642 qWarning() << "Illegal series type";
643 }
643 }
644
644
645 if (series) {
645 if (series) {
646 // Connect to axis changed signals (unless this is a pie series)
646 // Connect to axis changed signals (unless this is a pie series)
647 if (!qobject_cast<DeclarativePieSeries *>(series)) {
647 if (!qobject_cast<DeclarativePieSeries *>(series)) {
648 connect(series, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
648 connect(series, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
649 connect(series, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
649 connect(series, SIGNAL(axisXTopChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
650 connect(series, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*)));
650 connect(series, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*)));
651 connect(series, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SLOT(handleAxisYRightSet(QAbstractAxis*)));
651 connect(series, SIGNAL(axisYRightChanged(QAbstractAxis*)), this, SLOT(handleAxisYRightSet(QAbstractAxis*)));
652 }
652 }
653
653
654 series->setName(name);
654 series->setName(name);
655 m_chart->addSeries(series);
655 m_chart->addSeries(series);
656
656
657 if (axisX)
657 if (axisX)
658 setAxisX(axisX, series);
658 setAxisX(axisX, series);
659 if (axisY)
659 if (axisY)
660 setAxisY(axisY, series);
660 setAxisY(axisY, series);
661
661
662 if (series->attachedAxes().count() < 2)
662 if (series->attachedAxes().count() < 2)
663 initializeAxes(series);
663 initializeAxes(series);
664 }
664 }
665
665
666 return series;
666 return series;
667 }
667 }
668
668
669 void DeclarativeChart::removeSeries(QAbstractSeries *series)
669 void DeclarativeChart::removeSeries(QAbstractSeries *series)
670 {
670 {
671 if (series)
671 if (series)
672 m_chart->removeSeries(series);
672 m_chart->removeSeries(series);
673 else
673 else
674 qWarning("removeSeries: cannot remove null");
674 qWarning("removeSeries: cannot remove null");
675 }
675 }
676
676
677 void DeclarativeChart::setAxisX(QAbstractAxis *axis, QAbstractSeries *series)
677 void DeclarativeChart::setAxisX(QAbstractAxis *axis, QAbstractSeries *series)
678 {
678 {
679 if (axis)
679 if (axis)
680 m_chart->setAxisX(axis, series);
680 m_chart->setAxisX(axis, series);
681 }
681 }
682
682
683 void DeclarativeChart::setAxisY(QAbstractAxis *axis, QAbstractSeries *series)
683 void DeclarativeChart::setAxisY(QAbstractAxis *axis, QAbstractSeries *series)
684 {
684 {
685 if (axis)
685 if (axis)
686 m_chart->setAxisY(axis, series);
686 m_chart->setAxisY(axis, series);
687 }
687 }
688
688
689 void DeclarativeChart::createDefaultAxes()
689 void DeclarativeChart::createDefaultAxes()
690 {
690 {
691 qWarning() << "ChartView.createDefaultAxes() is deprecated. Axes are created automatically.";
691 qWarning() << "ChartView.createDefaultAxes() is deprecated. Axes are created automatically.";
692 }
692 }
693
693
694 QAbstractAxis *DeclarativeChart::defaultAxis(Qt::Orientation orientation, QAbstractSeries *series)
694 QAbstractAxis *DeclarativeChart::defaultAxis(Qt::Orientation orientation, QAbstractSeries *series)
695 {
695 {
696 if (!series) {
696 if (!series) {
697 qWarning() << "No axis type defined for null series";
697 qWarning() << "No axis type defined for null series";
698 return 0;
698 return 0;
699 }
699 }
700
700
701 foreach (QAbstractAxis *existingAxis, m_chart->axes(orientation)) {
701 foreach (QAbstractAxis *existingAxis, m_chart->axes(orientation)) {
702 if (existingAxis->type() == series->d_ptr->defaultAxisType(orientation))
702 if (existingAxis->type() == series->d_ptr->defaultAxisType(orientation))
703 return existingAxis;
703 return existingAxis;
704 }
704 }
705
705
706 switch (series->d_ptr->defaultAxisType(orientation)) {
706 switch (series->d_ptr->defaultAxisType(orientation)) {
707 case QAbstractAxis::AxisTypeValue:
707 case QAbstractAxis::AxisTypeValue:
708 return new QValueAxis(this);
708 return new QValueAxis(this);
709 case QAbstractAxis::AxisTypeBarCategory:
709 case QAbstractAxis::AxisTypeBarCategory:
710 return new QBarCategoryAxis(this);
710 return new QBarCategoryAxis(this);
711 case QAbstractAxis::AxisTypeCategory:
711 case QAbstractAxis::AxisTypeCategory:
712 return new QCategoryAxis(this);
712 return new QCategoryAxis(this);
713 #ifndef QT_ON_ARM
713 #ifndef QT_ON_ARM
714 case QAbstractAxis::AxisTypeDateTime:
714 case QAbstractAxis::AxisTypeDateTime:
715 return new QDateTimeAxis(this);
715 return new QDateTimeAxis(this);
716 #endif
716 #endif
717 default:
717 default:
718 // assume AxisTypeNoAxis
718 // assume AxisTypeNoAxis
719 return 0;
719 return 0;
720 }
720 }
721 }
721 }
722
722
723 void DeclarativeChart::initializeAxes(QAbstractSeries *series)
723 void DeclarativeChart::initializeAxes(QAbstractSeries *series)
724 {
724 {
725 if (qobject_cast<DeclarativeLineSeries *>(series))
725 if (qobject_cast<DeclarativeLineSeries *>(series))
726 doInitializeAxes(series, qobject_cast<DeclarativeLineSeries *>(series)->m_axes);
726 doInitializeAxes(series, qobject_cast<DeclarativeLineSeries *>(series)->m_axes);
727 else if (qobject_cast<DeclarativeScatterSeries *>(series))
727 else if (qobject_cast<DeclarativeScatterSeries *>(series))
728 doInitializeAxes(series, qobject_cast<DeclarativeScatterSeries *>(series)->m_axes);
728 doInitializeAxes(series, qobject_cast<DeclarativeScatterSeries *>(series)->m_axes);
729 else if (qobject_cast<DeclarativeSplineSeries *>(series))
729 else if (qobject_cast<DeclarativeSplineSeries *>(series))
730 doInitializeAxes(series, qobject_cast<DeclarativeSplineSeries *>(series)->m_axes);
730 doInitializeAxes(series, qobject_cast<DeclarativeSplineSeries *>(series)->m_axes);
731 else if (qobject_cast<DeclarativeAreaSeries *>(series))
731 else if (qobject_cast<DeclarativeAreaSeries *>(series))
732 doInitializeAxes(series, qobject_cast<DeclarativeAreaSeries *>(series)->m_axes);
732 doInitializeAxes(series, qobject_cast<DeclarativeAreaSeries *>(series)->m_axes);
733 else if (qobject_cast<DeclarativeBarSeries *>(series))
733 else if (qobject_cast<DeclarativeBarSeries *>(series))
734 doInitializeAxes(series, qobject_cast<DeclarativeBarSeries *>(series)->m_axes);
734 doInitializeAxes(series, qobject_cast<DeclarativeBarSeries *>(series)->m_axes);
735 else if (qobject_cast<DeclarativeStackedBarSeries *>(series))
735 else if (qobject_cast<DeclarativeStackedBarSeries *>(series))
736 doInitializeAxes(series, qobject_cast<DeclarativeStackedBarSeries *>(series)->m_axes);
736 doInitializeAxes(series, qobject_cast<DeclarativeStackedBarSeries *>(series)->m_axes);
737 else if (qobject_cast<DeclarativePercentBarSeries *>(series))
737 else if (qobject_cast<DeclarativePercentBarSeries *>(series))
738 doInitializeAxes(series, qobject_cast<DeclarativePercentBarSeries *>(series)->m_axes);
738 doInitializeAxes(series, qobject_cast<DeclarativePercentBarSeries *>(series)->m_axes);
739 else if (qobject_cast<DeclarativeHorizontalBarSeries *>(series))
739 else if (qobject_cast<DeclarativeHorizontalBarSeries *>(series))
740 doInitializeAxes(series, qobject_cast<DeclarativeHorizontalBarSeries *>(series)->m_axes);
740 doInitializeAxes(series, qobject_cast<DeclarativeHorizontalBarSeries *>(series)->m_axes);
741 else if (qobject_cast<DeclarativeHorizontalStackedBarSeries *>(series))
741 else if (qobject_cast<DeclarativeHorizontalStackedBarSeries *>(series))
742 doInitializeAxes(series, qobject_cast<DeclarativeHorizontalStackedBarSeries *>(series)->m_axes);
742 doInitializeAxes(series, qobject_cast<DeclarativeHorizontalStackedBarSeries *>(series)->m_axes);
743 else if (qobject_cast<DeclarativeHorizontalPercentBarSeries *>(series))
743 else if (qobject_cast<DeclarativeHorizontalPercentBarSeries *>(series))
744 doInitializeAxes(series, qobject_cast<DeclarativeHorizontalPercentBarSeries *>(series)->m_axes);
744 doInitializeAxes(series, qobject_cast<DeclarativeHorizontalPercentBarSeries *>(series)->m_axes);
745 // else: do nothing
745 // else: do nothing
746 }
746 }
747
747
748 void DeclarativeChart::doInitializeAxes(QAbstractSeries *series, DeclarativeAxes *axes)
748 void DeclarativeChart::doInitializeAxes(QAbstractSeries *series, DeclarativeAxes *axes)
749 {
749 {
750 // Initialize axis X
750 // Initialize axis X
751 if (axes->axisX())
751 if (axes->axisX())
752 axes->emitAxisXChanged();
752 axes->emitAxisXChanged();
753 else if (axes->axisXTop())
753 else if (axes->axisXTop())
754 axes->emitAxisXTopChanged();
754 axes->emitAxisXTopChanged();
755 else
755 else
756 axes->setAxisX(defaultAxis(Qt::Horizontal, series));
756 axes->setAxisX(defaultAxis(Qt::Horizontal, series));
757
757
758 // Initialize axis Y
758 // Initialize axis Y
759 if (axes->axisY())
759 if (axes->axisY())
760 axes->emitAxisYChanged();
760 axes->emitAxisYChanged();
761 else if (axes->axisYRight())
761 else if (axes->axisYRight())
762 axes->emitAxisYRightChanged();
762 axes->emitAxisYRightChanged();
763 else
763 else
764 axes->setAxisY(defaultAxis(Qt::Vertical, series));
764 axes->setAxisY(defaultAxis(Qt::Vertical, series));
765 }
765 }
766
766
767 #include "moc_declarativechart.cpp"
767 #include "moc_declarativechart.cpp"
768
768
769 QTCOMMERCIALCHART_END_NAMESPACE
769 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,184 +1,184
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef 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 <QtDeclarative/QDeclarativeItem>
25 #include <QtDeclarative/QDeclarativeItem>
26
26
27 #include "qchart.h"
27 #include "qchart.h"
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
30
31 class DeclarativeMargins;
31 class DeclarativeMargins;
32 class Domain;
32 class Domain;
33 class DeclarativeAxes;
33 class DeclarativeAxes;
34
34
35 class DeclarativeChart : public QDeclarativeItem
35 class DeclarativeChart : public QDeclarativeItem
36 {
36 {
37 Q_OBJECT
37 Q_OBJECT
38 Q_PROPERTY(Theme theme READ theme WRITE setTheme)
38 Q_PROPERTY(Theme theme READ theme WRITE setTheme)
39 Q_PROPERTY(Animation animationOptions READ animationOptions WRITE setAnimationOptions)
39 Q_PROPERTY(Animation animationOptions READ animationOptions WRITE setAnimationOptions)
40 Q_PROPERTY(QString title READ title WRITE setTitle)
40 Q_PROPERTY(QString title READ title WRITE setTitle)
41 Q_PROPERTY(QFont titleFont READ titleFont WRITE setTitleFont)
41 Q_PROPERTY(QFont titleFont READ titleFont WRITE setTitleFont)
42 Q_PROPERTY(QColor titleColor READ titleColor WRITE setTitleColor NOTIFY titleColorChanged)
42 Q_PROPERTY(QColor titleColor READ titleColor WRITE setTitleColor NOTIFY titleColorChanged)
43 Q_PROPERTY(QLegend *legend READ legend)
43 Q_PROPERTY(QLegend *legend READ legend)
44 Q_PROPERTY(int count READ count)
44 Q_PROPERTY(int count READ count)
45 Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged)
45 Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged)
46 Q_PROPERTY(bool dropShadowEnabled READ dropShadowEnabled WRITE setDropShadowEnabled NOTIFY dropShadowEnabledChanged)
46 Q_PROPERTY(bool dropShadowEnabled READ dropShadowEnabled WRITE setDropShadowEnabled NOTIFY dropShadowEnabledChanged)
47 Q_PROPERTY(qreal topMargin READ topMargin)
47 Q_PROPERTY(qreal topMargin READ topMargin)
48 Q_PROPERTY(qreal bottomMargin READ bottomMargin)
48 Q_PROPERTY(qreal bottomMargin READ bottomMargin)
49 Q_PROPERTY(qreal leftMargin READ leftMargin)
49 Q_PROPERTY(qreal leftMargin READ leftMargin)
50 Q_PROPERTY(qreal rightMargin READ rightMargin)
50 Q_PROPERTY(qreal rightMargin READ rightMargin)
51 Q_PROPERTY(DeclarativeMargins *minimumMargins READ minimumMargins NOTIFY minimumMarginsChanged REVISION 1)
51 Q_PROPERTY(DeclarativeMargins *minimumMargins READ minimumMargins NOTIFY minimumMarginsChanged REVISION 1)
52 Q_PROPERTY(DeclarativeMargins *margins READ margins NOTIFY marginsChanged REVISION 2)
52 Q_PROPERTY(DeclarativeMargins *margins READ margins NOTIFY marginsChanged REVISION 2)
53 Q_PROPERTY(QRectF plotArea READ plotArea NOTIFY plotAreaChanged REVISION 1)
53 Q_PROPERTY(QRectF plotArea READ plotArea NOTIFY plotAreaChanged REVISION 1)
54 Q_PROPERTY(QDeclarativeListProperty<QAbstractAxis> axes READ axes REVISION 2)
54 Q_PROPERTY(QDeclarativeListProperty<QAbstractAxis> axes READ axes REVISION 2)
55 Q_ENUMS(Animation)
55 Q_ENUMS(Animation)
56 Q_ENUMS(Theme)
56 Q_ENUMS(Theme)
57 Q_ENUMS(SeriesType)
57 Q_ENUMS(SeriesType)
58
58
59 public:
59 public:
60 // duplicating enums from QChart to make the QML api namings 1-to-1 with the C++ api
60 // duplicating enums from QChart to make the QML api namings 1-to-1 with the C++ api
61 enum Theme {
61 enum Theme {
62 ChartThemeLight = 0,
62 ChartThemeLight = 0,
63 ChartThemeBlueCerulean,
63 ChartThemeBlueCerulean,
64 ChartThemeDark,
64 ChartThemeDark,
65 ChartThemeBrownSand,
65 ChartThemeBrownSand,
66 ChartThemeBlueNcs,
66 ChartThemeBlueNcs,
67 ChartThemeHighContrast,
67 ChartThemeHighContrast,
68 ChartThemeBlueIcy
68 ChartThemeBlueIcy
69 };
69 };
70
70
71 enum Animation {
71 enum Animation {
72 NoAnimation = 0x0,
72 NoAnimation = 0x0,
73 GridAxisAnimations = 0x1,
73 GridAxisAnimations = 0x1,
74 SeriesAnimations = 0x2,
74 SeriesAnimations = 0x2,
75 AllAnimations = 0x3
75 AllAnimations = 0x3
76 };
76 };
77
77
78 enum SeriesType {
78 enum SeriesType {
79 SeriesTypeLine,
79 SeriesTypeLine,
80 SeriesTypeArea,
80 SeriesTypeArea,
81 SeriesTypeBar,
81 SeriesTypeBar,
82 SeriesTypeStackedBar,
82 SeriesTypeStackedBar,
83 SeriesTypePercentBar,
83 SeriesTypePercentBar,
84 SeriesTypePie,
84 SeriesTypePie,
85 SeriesTypeScatter,
85 SeriesTypeScatter,
86 SeriesTypeSpline,
86 SeriesTypeSpline,
87 SeriesTypeHorizontalBar,
87 SeriesTypeHorizontalBar,
88 SeriesTypeHorizontalStackedBar,
88 SeriesTypeHorizontalStackedBar,
89 SeriesTypeHorizontalPercentBar
89 SeriesTypeHorizontalPercentBar
90 };
90 };
91
91
92 public:
92 public:
93 DeclarativeChart(QDeclarativeItem *parent = 0);
93 DeclarativeChart(QDeclarativeItem *parent = 0);
94 ~DeclarativeChart();
94 ~DeclarativeChart();
95
95
96 public: // From QDeclarativeItem/QGraphicsItem
96 public: // From QDeclarativeItem/QGraphicsItem
97 void childEvent(QChildEvent *event);
97 void childEvent(QChildEvent *event);
98 void componentComplete();
98 void componentComplete();
99 void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
99 void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
100
100
101 public:
101 public:
102 void setTheme(DeclarativeChart::Theme theme);
102 void setTheme(DeclarativeChart::Theme theme);
103 DeclarativeChart::Theme theme();
103 DeclarativeChart::Theme theme();
104 void setAnimationOptions(DeclarativeChart::Animation animations);
104 void setAnimationOptions(DeclarativeChart::Animation animations);
105 DeclarativeChart::Animation animationOptions();
105 DeclarativeChart::Animation animationOptions();
106 void setTitle(QString title);
106 void setTitle(QString title);
107 QString title();
107 QString title();
108 QLegend *legend();
108 QLegend *legend();
109 QFont titleFont() const;
109 QFont titleFont() const;
110 void setTitleFont(const QFont &font);
110 void setTitleFont(const QFont &font);
111 void setTitleColor(QColor color);
111 void setTitleColor(QColor color);
112 QColor titleColor();
112 QColor titleColor();
113 void setBackgroundColor(QColor color);
113 void setBackgroundColor(QColor color);
114 QColor backgroundColor();
114 QColor backgroundColor();
115 int count();
115 int count();
116 void setDropShadowEnabled(bool enabled);
116 void setDropShadowEnabled(bool enabled);
117 bool dropShadowEnabled();
117 bool dropShadowEnabled();
118
119 // Margins & plotArea
118 qreal topMargin();
120 qreal topMargin();
119 qreal bottomMargin();
121 qreal bottomMargin();
120 qreal leftMargin();
122 qreal leftMargin();
121 qreal rightMargin();
123 qreal rightMargin();
122 QAbstractAxis *defaultAxis(Qt::Orientation orientation, QAbstractSeries *series);
123 void initializeAxes(QAbstractSeries *series);
124 void doInitializeAxes(QAbstractSeries *series, DeclarativeAxes *axes);
125 //TODO this is deprecated:
126 DeclarativeMargins *minimumMargins() { return m_margins; }
124 DeclarativeMargins *minimumMargins() { return m_margins; }
127
128 Q_REVISION(2) DeclarativeMargins *margins() { return m_margins; }
125 Q_REVISION(2) DeclarativeMargins *margins() { return m_margins; }
129 QRectF plotArea() { return m_chart->plotArea(); }
126 QRectF plotArea() { return m_chart->plotArea(); }
130
127
131 // Axis list property methods
128 // Axis handling
129 QAbstractAxis *defaultAxis(Qt::Orientation orientation, QAbstractSeries *series);
130 void initializeAxes(QAbstractSeries *series);
131 void doInitializeAxes(QAbstractSeries *series, DeclarativeAxes *axes);
132 QDeclarativeListProperty<QAbstractAxis> axes();
132 QDeclarativeListProperty<QAbstractAxis> axes();
133 static void axesAppendFunc(QDeclarativeListProperty<QAbstractAxis> *list, QAbstractAxis *element);
133 static void axesAppendFunc(QDeclarativeListProperty<QAbstractAxis> *list, QAbstractAxis *element);
134 static int axesCountFunc(QDeclarativeListProperty<QAbstractAxis> *list);
134 static int axesCountFunc(QDeclarativeListProperty<QAbstractAxis> *list);
135 static QAbstractAxis *axesAtFunc(QDeclarativeListProperty<QAbstractAxis> *list, int index);
135 static QAbstractAxis *axesAtFunc(QDeclarativeListProperty<QAbstractAxis> *list, int index);
136
136
137 public:
137 public:
138 Q_INVOKABLE QAbstractSeries *series(int index);
138 Q_INVOKABLE QAbstractSeries *series(int index);
139 Q_INVOKABLE QAbstractSeries *series(QString seriesName);
139 Q_INVOKABLE QAbstractSeries *series(QString seriesName);
140 Q_INVOKABLE QAbstractSeries *createSeries(DeclarativeChart::SeriesType type, QString name = "");
140 Q_INVOKABLE QAbstractSeries *createSeries(DeclarativeChart::SeriesType type, QString name = "");
141 Q_INVOKABLE QAbstractSeries *createSeries(DeclarativeChart::SeriesType type, QString name, QAbstractAxis *axisX, QAbstractAxis *axisY);
141 Q_INVOKABLE QAbstractSeries *createSeries(DeclarativeChart::SeriesType type, QString name, QAbstractAxis *axisX, QAbstractAxis *axisY);
142 Q_INVOKABLE void removeSeries(QAbstractSeries *series);
142 Q_INVOKABLE void removeSeries(QAbstractSeries *series);
143 Q_INVOKABLE void removeAllSeries() { m_chart->removeAllSeries(); }
143 Q_INVOKABLE void removeAllSeries() { m_chart->removeAllSeries(); }
144 Q_INVOKABLE void setAxisX(QAbstractAxis *axis, QAbstractSeries *series = 0);
144 Q_INVOKABLE void setAxisX(QAbstractAxis *axis, QAbstractSeries *series = 0);
145 Q_INVOKABLE void setAxisY(QAbstractAxis *axis, QAbstractSeries *series = 0);
145 Q_INVOKABLE void setAxisY(QAbstractAxis *axis, QAbstractSeries *series = 0);
146 Q_INVOKABLE void createDefaultAxes();
146 Q_INVOKABLE void createDefaultAxes();
147 Q_INVOKABLE QAbstractAxis *axisX(QAbstractSeries *series = 0);
147 Q_INVOKABLE QAbstractAxis *axisX(QAbstractSeries *series = 0);
148 Q_INVOKABLE QAbstractAxis *axisY(QAbstractSeries *series = 0);
148 Q_INVOKABLE QAbstractAxis *axisY(QAbstractSeries *series = 0);
149 Q_INVOKABLE void zoom(qreal factor);
149 Q_INVOKABLE void zoom(qreal factor);
150 Q_INVOKABLE void scrollLeft(qreal pixels);
150 Q_INVOKABLE void scrollLeft(qreal pixels);
151 Q_INVOKABLE void scrollRight(qreal pixels);
151 Q_INVOKABLE void scrollRight(qreal pixels);
152 Q_INVOKABLE void scrollUp(qreal pixels);
152 Q_INVOKABLE void scrollUp(qreal pixels);
153 Q_INVOKABLE void scrollDown(qreal pixels);
153 Q_INVOKABLE void scrollDown(qreal pixels);
154
154
155 Q_SIGNALS:
155 Q_SIGNALS:
156 void axisLabelsChanged();
156 void axisLabelsChanged();
157 void titleColorChanged(QColor color);
157 void titleColorChanged(QColor color);
158 void backgroundColorChanged();
158 void backgroundColorChanged();
159 void dropShadowEnabledChanged(bool enabled);
159 void dropShadowEnabledChanged(bool enabled);
160 void minimumMarginsChanged();
160 void minimumMarginsChanged();
161 Q_REVISION(2) void marginsChanged();
161 Q_REVISION(2) void marginsChanged();
162 void plotAreaChanged(QRectF plotArea);
162 void plotAreaChanged(QRectF plotArea);
163 void seriesAdded(QAbstractSeries *series);
163 void seriesAdded(QAbstractSeries *series);
164 void seriesRemoved(QAbstractSeries *series);
164 void seriesRemoved(QAbstractSeries *series);
165
165
166 private Q_SLOTS:
166 private Q_SLOTS:
167 void changeMinimumMargins(int top, int bottom, int left, int right);
167 void changeMinimumMargins(int top, int bottom, int left, int right);
168 void handleAxisXSet(QAbstractAxis *axis);
168 void handleAxisXSet(QAbstractAxis *axis);
169 void handleAxisYSet(QAbstractAxis *axis);
169 void handleAxisYSet(QAbstractAxis *axis);
170 void handleAxisXTopSet(QAbstractAxis *axis);
170 void handleAxisXTopSet(QAbstractAxis *axis);
171 void handleAxisYRightSet(QAbstractAxis *axis);
171 void handleAxisYRightSet(QAbstractAxis *axis);
172 void handleSeriesAdded(QAbstractSeries *series);
172 void handleSeriesAdded(QAbstractSeries *series);
173
173
174 private:
174 private:
175 // Extending QChart with DeclarativeChart is not possible because QObject does not support
175 // Extending QChart with DeclarativeChart is not possible because QObject does not support
176 // multi inheritance, so we now have a QChart as a member instead
176 // multi inheritance, so we now have a QChart as a member instead
177 QChart *m_chart;
177 QChart *m_chart;
178 //QMargins m_chartMargins;
178 //QMargins m_chartMargins;
179 DeclarativeMargins *m_margins;
179 DeclarativeMargins *m_margins;
180 };
180 };
181
181
182 QTCOMMERCIALCHART_END_NAMESPACE
182 QTCOMMERCIALCHART_END_NAMESPACE
183
183
184 #endif // DECLARATIVECHART_H
184 #endif // DECLARATIVECHART_H
@@ -1,83 +1,84
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 import QtQuick 1.0
21 import QtQuick 1.0
22 import QtQuickTest 1.0
22 import QtQuickTest 1.0
23 import QtCommercial.Chart 1.2
23 import QtCommercial.Chart 1.2
24
24
25 Rectangle {
25 Rectangle {
26 width: 400
26 width: 400
27 height: 300
27 height: 300
28
28
29 TestCase {
29 TestCase {
30 id: tc1
30 id: tc1
31 name: "tst_qml-qtquicktest ChartView Properties"
31 name: "tst_qml-qtquicktest ChartView Properties"
32 when: windowShown
32 when: windowShown
33
33
34 function test_chartViewProperties() {
34 function test_chartViewProperties() {
35 compare(chartView.animationOptions, ChartView.NoAnimation, "ChartView.animationOptions");
35 compare(chartView.animationOptions, ChartView.NoAnimation, "ChartView.animationOptions");
36 verify(chartView.backgroundColor != undefined);
36 verify(chartView.backgroundColor != undefined);
37 verify(chartView.bottomMargin > 0, "ChartView.bottomMargin");
37 verify(chartView.bottomMargin > 0, "ChartView.bottomMargin");
38 verify(chartView.topMargin > 0, "ChartView.topMargin");
38 verify(chartView.topMargin > 0, "ChartView.topMargin");
39 verify(chartView.leftMargin > 0, "ChartView.leftMargin");
39 verify(chartView.leftMargin > 0, "ChartView.leftMargin");
40 verify(chartView.rightMargin > 0, "ChartView.rightMargin");
40 verify(chartView.rightMargin > 0, "ChartView.rightMargin");
41 verify(chartView.margins.bottom > 0, "ChartView.margins.bottom");
41 verify(chartView.margins.bottom > 0, "ChartView.margins.bottom");
42 verify(chartView.margins.top > 0, "ChartView.margins.top");
42 verify(chartView.margins.top > 0, "ChartView.margins.top");
43 verify(chartView.margins.left > 0, "ChartView.margins.left");
43 verify(chartView.margins.left > 0, "ChartView.margins.left");
44 verify(chartView.margins.right > 0, "ChartView.margins.right");
44 verify(chartView.margins.right > 0, "ChartView.margins.right");
45 compare(chartView.count, 0, "ChartView.count");
45 compare(chartView.count, 0, "ChartView.count");
46 compare(chartView.dropShadowEnabled, false, "ChartView.dropShadowEnabled");
46 compare(chartView.dropShadowEnabled, false, "ChartView.dropShadowEnabled");
47 verify(chartView.plotArea.height > 0, "ChartView.plotArea.height");
47 verify(chartView.plotArea.height > 0, "ChartView.plotArea.height");
48 verify(chartView.plotArea.width > 0, "ChartView.plotArea.width");
48 verify(chartView.plotArea.width > 0, "ChartView.plotArea.width");
49 verify(chartView.plotArea.x > 0, "ChartView.plotArea.x");
49 verify(chartView.plotArea.x > 0, "ChartView.plotArea.x");
50 verify(chartView.plotArea.y > 0, "ChartView.plotArea.y");
50 verify(chartView.plotArea.y > 0, "ChartView.plotArea.y");
51 compare(chartView.theme, ChartView.ChartThemeLight, "ChartView.theme");
51 compare(chartView.theme, ChartView.ChartThemeLight, "ChartView.theme");
52 compare(chartView.title, "", "ChartView.title");
52 compare(chartView.title, "", "ChartView.title");
53 compare(chartView.title, "", "ChartView.title");
53 compare(chartView.title, "", "ChartView.title");
54 verify(chartView.titleColor != undefined, "ChartView.titleColor");
54 verify(chartView.titleColor != undefined, "ChartView.titleColor");
55 compare(chartView.titleFont.bold, false, "ChartView.titleFont.bold");
55 compare(chartView.titleFont.bold, false, "ChartView.titleFont.bold");
56 // Legend
56 // Legend
57 compare(chartView.legend.visible, true, "ChartView.legend.visible");
57 compare(chartView.legend.visible, true, "ChartView.legend.visible");
58 compare(chartView.legend.alignment, Qt.AlignTop, "ChartView.legend.alignment");
58 compare(chartView.legend.alignment, Qt.AlignTop, "ChartView.legend.alignment");
59 compare(chartView.legend.backgroundVisible, false, "ChartView.legend.backgroundVisible");
59 compare(chartView.legend.backgroundVisible, false, "ChartView.legend.backgroundVisible");
60 verify(chartView.legend.borderColor != undefined, "ChartView.legend.borderColor");
60 verify(chartView.legend.borderColor != undefined, "ChartView.legend.borderColor");
61 verify(chartView.legend.color != undefined, "ChartView.legend.color");
61 verify(chartView.legend.color != undefined, "ChartView.legend.color");
62 // Legend font
62 // Legend font
63 compare(chartView.legend.font.bold, false, "ChartView.legend.font.bold");
63 compare(chartView.legend.font.bold, false, "ChartView.legend.font.bold");
64 compare(chartView.legend.font.capitalization, Font.MixedCase, "ChartView.legend.font.capitalization");
64 compare(chartView.legend.font.capitalization, Font.MixedCase, "ChartView.legend.font.capitalization");
65 compare(chartView.legend.font.family, "arial", "ChartView.legend.font.family");
65 verify(chartView.legend.font.family != "", "ChartView.legend.font.family");
66 compare(chartView.legend.font.italic, false, "ChartView.legend.font.italic");
66 compare(chartView.legend.font.italic, false, "ChartView.legend.font.italic");
67 compare(chartView.legend.font.letterSpacing, 0.0, "ChartView.legend.font.letterSpacing");
67 compare(chartView.legend.font.letterSpacing, 0.0, "ChartView.legend.font.letterSpacing");
68 verify(chartView.legend.font.pixelSize > 0
68 verify(chartView.legend.font.pixelSize > 0
69 && chartView.legend.font.pixelSize < 50, "ChartView.legend.font.pixelSize");
69 && chartView.legend.font.pixelSize < 50, "ChartView.legend.font.pixelSize");
70 verify(chartView.legend.font.pointSize > 0
70 verify(chartView.legend.font.pointSize > 0
71 && chartView.legend.font.pointSize < 50, "ChartView.legend.font.pointSize");
71 && chartView.legend.font.pointSize < 50, "ChartView.legend.font.pointSize");
72 compare(chartView.legend.font.strikeout, false, "ChartView.legend.font.strikeout");
72 compare(chartView.legend.font.strikeout, false, "ChartView.legend.font.strikeout");
73 compare(chartView.legend.font.underline, false, "ChartView.legend.font.underline");
73 compare(chartView.legend.font.underline, false, "ChartView.legend.font.underline");
74 compare(chartView.legend.font.weight, Font.Normal, "ChartView.legend.font.weight");
74 compare(chartView.legend.font.weight, Font.Normal, "ChartView.legend.font.weight");
75 compare(chartView.legend.font.wordSpacing, 0.0, "ChartView.legend.font.wordSpacing");
75 compare(chartView.legend.font.wordSpacing, 0.0, "ChartView.legend.font.wordSpacing");
76 compare(chartView.axes.length, 0, "ChartView.axes.length");
76 }
77 }
77 }
78 }
78
79
79 ChartView {
80 ChartView {
80 id: chartView
81 id: chartView
81 anchors.fill: parent
82 anchors.fill: parent
82 }
83 }
83 }
84 }
@@ -1,79 +1,79
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 import QtQuick 1.0
21 import QtQuick 1.0
22 import QtQuickTest 1.0
22 import QtQuickTest 1.0
23 import QtCommercial.Chart 1.1
23 import QtCommercial.Chart 1.1
24
24
25 Rectangle {
25 Rectangle {
26 width: 400
26 width: 400
27 height: 300
27 height: 300
28
28
29 TestCase {
29 TestCase {
30 id: tc1
30 id: tc1
31 name: "tst_qml-qtquicktest ChartView Properties 1.1"
31 name: "tst_qml-qtquicktest ChartView Properties 1.1"
32 when: windowShown
32 when: windowShown
33
33
34 function test_chartViewProperties() {
34 function test_chartViewProperties() {
35 compare(chartView.animationOptions, ChartView.NoAnimation, "ChartView.animationOptions");
35 compare(chartView.animationOptions, ChartView.NoAnimation, "ChartView.animationOptions");
36 verify(chartView.backgroundColor != undefined);
36 verify(chartView.backgroundColor != undefined);
37 verify(chartView.bottomMargin > 0, "ChartView.bottomMargin");
37 verify(chartView.bottomMargin > 0, "ChartView.bottomMargin");
38 verify(chartView.topMargin > 0, "ChartView.topMargin");
38 verify(chartView.topMargin > 0, "ChartView.topMargin");
39 verify(chartView.leftMargin > 0, "ChartView.leftMargin");
39 verify(chartView.leftMargin > 0, "ChartView.leftMargin");
40 verify(chartView.rightMargin > 0, "ChartView.rightMargin");
40 verify(chartView.rightMargin > 0, "ChartView.rightMargin");
41 compare(chartView.count, 0, "ChartView.count");
41 compare(chartView.count, 0, "ChartView.count");
42 compare(chartView.dropShadowEnabled, false, "ChartView.dropShadowEnabled");
42 compare(chartView.dropShadowEnabled, false, "ChartView.dropShadowEnabled");
43 verify(chartView.plotArea.height > 0, "ChartView.plotArea.height");
43 verify(chartView.plotArea.height > 0, "ChartView.plotArea.height");
44 verify(chartView.plotArea.width > 0, "ChartView.plotArea.width");
44 verify(chartView.plotArea.width > 0, "ChartView.plotArea.width");
45 verify(chartView.plotArea.x > 0, "ChartView.plotArea.x");
45 verify(chartView.plotArea.x > 0, "ChartView.plotArea.x");
46 verify(chartView.plotArea.y > 0, "ChartView.plotArea.y");
46 verify(chartView.plotArea.y > 0, "ChartView.plotArea.y");
47 compare(chartView.theme, ChartView.ChartThemeLight, "ChartView.theme");
47 compare(chartView.theme, ChartView.ChartThemeLight, "ChartView.theme");
48 compare(chartView.title, "", "ChartView.title");
48 compare(chartView.title, "", "ChartView.title");
49 compare(chartView.title, "", "ChartView.title");
49 compare(chartView.title, "", "ChartView.title");
50 verify(chartView.titleColor != undefined, "ChartView.titleColor");
50 verify(chartView.titleColor != undefined, "ChartView.titleColor");
51 compare(chartView.titleFont.bold, false, "ChartView.titleFont.bold");
51 compare(chartView.titleFont.bold, false, "ChartView.titleFont.bold");
52 // Legend
52 // Legend
53 compare(chartView.legend.visible, true, "ChartView.legend.visible");
53 compare(chartView.legend.visible, true, "ChartView.legend.visible");
54 compare(chartView.legend.alignment, Qt.AlignTop, "ChartView.legend.alignment");
54 compare(chartView.legend.alignment, Qt.AlignTop, "ChartView.legend.alignment");
55 compare(chartView.legend.backgroundVisible, false, "ChartView.legend.backgroundVisible");
55 compare(chartView.legend.backgroundVisible, false, "ChartView.legend.backgroundVisible");
56 verify(chartView.legend.borderColor != undefined, "ChartView.legend.borderColor");
56 verify(chartView.legend.borderColor != undefined, "ChartView.legend.borderColor");
57 verify(chartView.legend.color != undefined, "ChartView.legend.color");
57 verify(chartView.legend.color != undefined, "ChartView.legend.color");
58 // Legend font
58 // Legend font
59 compare(chartView.legend.font.bold, false, "ChartView.legend.font.bold");
59 compare(chartView.legend.font.bold, false, "ChartView.legend.font.bold");
60 compare(chartView.legend.font.capitalization, Font.MixedCase, "ChartView.legend.font.capitalization");
60 compare(chartView.legend.font.capitalization, Font.MixedCase, "ChartView.legend.font.capitalization");
61 compare(chartView.legend.font.family, "arial", "ChartView.legend.font.family");
61 verify(chartView.legend.font.family != "", "ChartView.legend.font.family");
62 compare(chartView.legend.font.italic, false, "ChartView.legend.font.italic");
62 compare(chartView.legend.font.italic, false, "ChartView.legend.font.italic");
63 compare(chartView.legend.font.letterSpacing, 0.0, "ChartView.legend.font.letterSpacing");
63 compare(chartView.legend.font.letterSpacing, 0.0, "ChartView.legend.font.letterSpacing");
64 verify(chartView.legend.font.pixelSize > 0
64 verify(chartView.legend.font.pixelSize > 0
65 && chartView.legend.font.pixelSize < 50, "ChartView.legend.font.pixelSize");
65 && chartView.legend.font.pixelSize < 50, "ChartView.legend.font.pixelSize");
66 verify(chartView.legend.font.pointSize > 0
66 verify(chartView.legend.font.pointSize > 0
67 && chartView.legend.font.pointSize < 50, "ChartView.legend.font.pointSize");
67 && chartView.legend.font.pointSize < 50, "ChartView.legend.font.pointSize");
68 compare(chartView.legend.font.strikeout, false, "ChartView.legend.font.strikeout");
68 compare(chartView.legend.font.strikeout, false, "ChartView.legend.font.strikeout");
69 compare(chartView.legend.font.underline, false, "ChartView.legend.font.underline");
69 compare(chartView.legend.font.underline, false, "ChartView.legend.font.underline");
70 compare(chartView.legend.font.weight, Font.Normal, "ChartView.legend.font.weight");
70 compare(chartView.legend.font.weight, Font.Normal, "ChartView.legend.font.weight");
71 compare(chartView.legend.font.wordSpacing, 0.0, "ChartView.legend.font.wordSpacing");
71 compare(chartView.legend.font.wordSpacing, 0.0, "ChartView.legend.font.wordSpacing");
72 }
72 }
73 }
73 }
74
74
75 ChartView {
75 ChartView {
76 id: chartView
76 id: chartView
77 anchors.fill: parent
77 anchors.fill: parent
78 }
78 }
79 }
79 }
@@ -1,102 +1,100
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 import QtQuick 1.0
21 import QtQuick 1.0
22 import QtQuickTest 1.0
22 import QtQuickTest 1.0
23 import QtCommercial.Chart 1.2
23 import QtCommercial.Chart 1.2
24
24
25 Rectangle {
25 Rectangle {
26 width: 400
26 width: 400
27 height: 300
27 height: 300
28
28
29 TestCase {
29 TestCase {
30 id: tc1
30 id: tc1
31 name: "tst_qml-qtquicktest ValueAxis"
31 name: "tst_qml-qtquicktest ValueAxis"
32 when: windowShown
32 when: windowShown
33
33
34 function test_defaultPropertyValues() {
34 function test_defaultPropertyValues() {
35 compare(lineSeries1.axisX.min, 0, "AxisX min");
35 verify(axisX.min < 0, "AxisX min");
36 compare(lineSeries1.axisX.max, 10, "AxisX max");
36 verify(axisX.max > 0, "AxisX max");
37 compare(lineSeries1.axisY.min, 0, "AxisY min");
37 verify(axisY.min < 0, "AxisY min");
38 compare(lineSeries1.axisY.max, 10, "AxisY max");
38 verify(axisY.max > 0, "AxisY max");
39 verify(axisX.tickCount > 0, "AxisX tick count");
39 verify(axisX.tickCount > 0, "AxisX tick count");
40 verify(axisY.tickCount > 0, "AxisX tick count");
40 verify(axisY.tickCount > 0, "AxisX tick count");
41 compare(axisX.niceNumbersEnabled, false, "nice numbers");
41 compare(axisX.niceNumbersEnabled, false, "nice numbers");
42 compare(axisX.labelFormat, "", "label format");
42 compare(axisX.labelFormat, "", "label format");
43 }
43 }
44
44
45 function test_modifyProperties() {
45 function test_modifyProperties() {
46 lineSeries1.axisX.tickCount = 3;
46 axisX.tickCount = 3;
47 compare(lineSeries1.axisX.tickCount, 3, "set tick count");
47 compare(axisX.tickCount, 3, "set tick count");
48
48
49 lineSeries1.axisX.niceNumbersEnabled = true;
49 axisX.niceNumbersEnabled = true;
50 compare(axisX.niceNumbersEnabled, true, "nice numbers");
50 compare(axisX.niceNumbersEnabled, true, "nice numbers");
51 }
51 }
52
52
53 function test_signals() {
53 function test_signals() {
54 minChangedSpy.clear();
55 maxChangedSpy.clear();
54 axisX.min = 2;
56 axisX.min = 2;
55 compare(minChangedSpy.count, 1, "onMinChanged");
57 compare(minChangedSpy.count, 1, "onMinChanged");
56 compare(maxChangedSpy.count, 0, "onMaxChanged");
58 compare(maxChangedSpy.count, 0, "onMaxChanged");
57
59
58 axisX.max = 8;
60 axisX.max = 8;
59 compare(minChangedSpy.count, 1, "onMinChanged");
61 compare(minChangedSpy.count, 1, "onMinChanged");
60 compare(maxChangedSpy.count, 1, "onMaxChanged");
62 compare(maxChangedSpy.count, 1, "onMaxChanged");
61
63
62 // restore original values
64 // restore original values
63 axisX.min = 0;
65 axisX.min = 0;
64 axisX.max = 10;
66 axisX.max = 10;
65 compare(minChangedSpy.count, 2, "onMinChanged");
67 compare(minChangedSpy.count, 2, "onMinChanged");
66 compare(maxChangedSpy.count, 2, "onMaxChanged");
68 compare(maxChangedSpy.count, 2, "onMaxChanged");
67 }
69 }
68 }
70 }
69
71
70 ChartView {
72 ChartView {
71 id: chartView
73 id: chartView
72 anchors.fill: parent
74 anchors.fill: parent
73
75
74 LineSeries {
76 LineSeries {
75 id: lineSeries1
77 id: lineSeries1
76 axisX: ValueAxis {
78 axisX: ValueAxis {
77 id: axisX
79 id: axisX
78 min: 0
79 max: 10
80 }
80 }
81 axisY: ValueAxis {
81 axisY: ValueAxis {
82 id: axisY
82 id: axisY
83 min: 0
84 max: 10
85 }
83 }
86 XYPoint { x: -1; y: -1 }
84 XYPoint { x: -1; y: -1 }
87 XYPoint { x: 0; y: 0 }
85 XYPoint { x: 0; y: 0 }
88 XYPoint { x: 5; y: 5 }
86 XYPoint { x: 5; y: 5 }
89 }
87 }
90
88
91 SignalSpy {
89 SignalSpy {
92 id: minChangedSpy
90 id: minChangedSpy
93 target: axisX
91 target: axisX
94 signalName: "minChanged"
92 signalName: "minChanged"
95 }
93 }
96 SignalSpy {
94 SignalSpy {
97 id: maxChangedSpy
95 id: maxChangedSpy
98 target: axisX
96 target: axisX
99 signalName: "maxChanged"
97 signalName: "maxChanged"
100 }
98 }
101 }
99 }
102 }
100 }
@@ -1,264 +1,260
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 import QtQuick 1.0
21 import QtQuick 1.0
22 import QtQuickTest 1.0
22 import QtQuickTest 1.0
23 import QtCommercial.Chart 1.2
23 import QtCommercial.Chart 1.2
24
24
25 Rectangle {
25 Rectangle {
26 width: 400
26 width: 400
27 height: 300
27 height: 300
28
28
29 TestCase {
29 TestCase {
30 id: tc1
30 id: tc1
31 name: "tst_qml-qtquicktest XY Series"
31 name: "tst_qml-qtquicktest XY Series"
32 when: windowShown
32 when: windowShown
33
33
34 function test_properties() {
34 function test_properties() {
35 verify(lineSeries.color != undefined);
35 verify(lineSeries.color != undefined);
36 compare(lineSeries.pointsVisible, false);
36 compare(lineSeries.pointsVisible, false);
37 compare(lineSeries.capStyle, Qt.SquareCap);
37 compare(lineSeries.capStyle, Qt.SquareCap);
38 compare(lineSeries.style, Qt.SolidLine);
38 compare(lineSeries.style, Qt.SolidLine);
39 compare(lineSeries.width, 2.0);
39 compare(lineSeries.width, 2.0);
40
40
41 verify(splineSeries.color != undefined);
41 verify(splineSeries.color != undefined);
42 compare(splineSeries.pointsVisible, false);
42 compare(splineSeries.pointsVisible, false);
43 compare(splineSeries.capStyle, Qt.SquareCap);
43 compare(splineSeries.capStyle, Qt.SquareCap);
44 compare(splineSeries.style, Qt.SolidLine);
44 compare(splineSeries.style, Qt.SolidLine);
45 compare(splineSeries.width, 2.0);
45 compare(splineSeries.width, 2.0);
46
46
47 verify(scatterSeries.color != undefined);
47 verify(scatterSeries.color != undefined);
48 verify(scatterSeries.borderColor != undefined);
48 verify(scatterSeries.borderColor != undefined);
49 compare(scatterSeries.borderWidth, 2.0);
49 compare(scatterSeries.borderWidth, 2.0);
50 compare(scatterSeries.markerShape, ScatterSeries.MarkerShapeCircle);
50 compare(scatterSeries.markerShape, ScatterSeries.MarkerShapeCircle);
51 compare(scatterSeries.markerSize, 15.0);
51 compare(scatterSeries.markerSize, 15.0);
52
52
53 verify(areaSeries.color != undefined);
53 verify(areaSeries.color != undefined);
54 verify(areaSeries.borderColor != undefined);
54 verify(areaSeries.borderColor != undefined);
55 compare(areaSeries.borderWidth, 2.0);
55 compare(areaSeries.borderWidth, 2.0);
56 }
56 }
57
57
58 function test_axes() {
58 function test_axes() {
59 compare(chartView.axes.length, 2);
59 compare(chartView.axes.length, 2);
60 console.log("chart.axes[0] " + chartView.axes[0]);
61 console.log("chart.axes[1] " + chartView.axes[1]);
62 console.log("lineSeries.axisX " + lineSeries.axisX);
63 console.log("lineSeries.axisY " + lineSeries.axisY);
64 verify(chartView.axes[0] == lineSeries.axisX || chartView.axes[1] == lineSeries.axisX);
60 verify(chartView.axes[0] == lineSeries.axisX || chartView.axes[1] == lineSeries.axisX);
65 verify(chartView.axes[0] == lineSeries.axisY || chartView.axes[1] == lineSeries.axisY);
61 verify(chartView.axes[0] == lineSeries.axisY || chartView.axes[1] == lineSeries.axisY);
66 verify(lineSeries.axisX == splineSeries.axisX);
62 verify(lineSeries.axisX == splineSeries.axisX);
67 verify(lineSeries.axisY == splineSeries.axisY);
63 verify(lineSeries.axisY == splineSeries.axisY);
68 verify(lineSeries.axisX == areaSeries.axisX);
64 verify(lineSeries.axisX == areaSeries.axisX);
69 verify(lineSeries.axisY == areaSeries.axisY);
65 verify(lineSeries.axisY == areaSeries.axisY);
70 }
66 }
71
67
72 function test_append() {
68 function test_append() {
73 lineSeriesPointAddedSpy.clear();
69 lineSeriesPointAddedSpy.clear();
74 splineSeriesPointAddedSpy.clear();
70 splineSeriesPointAddedSpy.clear();
75 scatterSeriesPointAddedSpy.clear();
71 scatterSeriesPointAddedSpy.clear();
76 var count = append();
72 var count = append();
77 compare(lineSeries.count, count);
73 compare(lineSeries.count, count);
78 compare(splineSeries.count, count);
74 compare(splineSeries.count, count);
79 compare(scatterSeries.count, count);
75 compare(scatterSeries.count, count);
80 tryCompare(lineSeriesPointAddedSpy.count, count);
76 tryCompare(lineSeriesPointAddedSpy.count, count);
81 tryCompare(splineSeriesPointAddedSpy.count, count);
77 tryCompare(splineSeriesPointAddedSpy.count, count);
82 tryCompare(scatterSeriesPointAddedSpy.count, count);
78 tryCompare(scatterSeriesPointAddedSpy.count, count);
83 clear();
79 clear();
84 compare(lineSeries.count, 0);
80 compare(lineSeries.count, 0);
85 compare(splineSeries.count, 0);
81 compare(splineSeries.count, 0);
86 compare(scatterSeries.count, 0);
82 compare(scatterSeries.count, 0);
87 }
83 }
88
84
89 function test_replace() {
85 function test_replace() {
90 var count = append();
86 var count = append();
91 for (var i = 0; i < count; i++) {
87 for (var i = 0; i < count; i++) {
92 lineSeries.replace(lineSeries.at(i).x, lineSeries.at(i).y, i, Math.random());
88 lineSeries.replace(lineSeries.at(i).x, lineSeries.at(i).y, i, Math.random());
93 splineSeries.replace(splineSeries.at(i).x, splineSeries.at(i).y, i, Math.random());
89 splineSeries.replace(splineSeries.at(i).x, splineSeries.at(i).y, i, Math.random());
94 scatterSeries.replace(scatterSeries.at(i).x, scatterSeries.at(i).y, i, Math.random());
90 scatterSeries.replace(scatterSeries.at(i).x, scatterSeries.at(i).y, i, Math.random());
95 }
91 }
96 compare(lineSeries.count, count);
92 compare(lineSeries.count, count);
97 compare(splineSeries.count, count);
93 compare(splineSeries.count, count);
98 compare(scatterSeries.count, count);
94 compare(scatterSeries.count, count);
99 tryCompare(lineSeriesPointReplacedSpy.count, count);
95 tryCompare(lineSeriesPointReplacedSpy.count, count);
100 tryCompare(splineSeriesPointReplacedSpy.count, count);
96 tryCompare(splineSeriesPointReplacedSpy.count, count);
101 tryCompare(scatterSeriesPointReplacedSpy.count, count);
97 tryCompare(scatterSeriesPointReplacedSpy.count, count);
102 clear();
98 clear();
103 }
99 }
104
100
105 function test_insert() {
101 function test_insert() {
106 var count = append();
102 var count = append();
107 lineSeriesPointAddedSpy.clear();
103 lineSeriesPointAddedSpy.clear();
108 splineSeriesPointAddedSpy.clear();
104 splineSeriesPointAddedSpy.clear();
109 scatterSeriesPointAddedSpy.clear();
105 scatterSeriesPointAddedSpy.clear();
110 for (var i = 0; i < count; i++) {
106 for (var i = 0; i < count; i++) {
111 lineSeries.insert(i * 2, i, Math.random());
107 lineSeries.insert(i * 2, i, Math.random());
112 splineSeries.insert(i * 2, i, Math.random());
108 splineSeries.insert(i * 2, i, Math.random());
113 scatterSeries.insert(i * 2, i, Math.random());
109 scatterSeries.insert(i * 2, i, Math.random());
114 }
110 }
115 compare(lineSeries.count, count * 2);
111 compare(lineSeries.count, count * 2);
116 compare(splineSeries.count, count * 2);
112 compare(splineSeries.count, count * 2);
117 compare(scatterSeries.count, count * 2);
113 compare(scatterSeries.count, count * 2);
118 tryCompare(lineSeriesPointAddedSpy.count, count);
114 tryCompare(lineSeriesPointAddedSpy.count, count);
119 tryCompare(splineSeriesPointAddedSpy.count, count);
115 tryCompare(splineSeriesPointAddedSpy.count, count);
120 tryCompare(scatterSeriesPointAddedSpy.count, count);
116 tryCompare(scatterSeriesPointAddedSpy.count, count);
121 clear();
117 clear();
122 }
118 }
123
119
124 function test_remove() {
120 function test_remove() {
125 lineSeriesPointRemovedSpy.clear();
121 lineSeriesPointRemovedSpy.clear();
126 splineSeriesPointRemovedSpy.clear();
122 splineSeriesPointRemovedSpy.clear();
127 scatterSeriesPointRemovedSpy.clear();
123 scatterSeriesPointRemovedSpy.clear();
128 var count = append();
124 var count = append();
129 for (var i = 0; i < count; i++) {
125 for (var i = 0; i < count; i++) {
130 lineSeries.remove(lineSeries.at(0).x, lineSeries.at(0).y);
126 lineSeries.remove(lineSeries.at(0).x, lineSeries.at(0).y);
131 splineSeries.remove(splineSeries.at(0).x, splineSeries.at(0).y);
127 splineSeries.remove(splineSeries.at(0).x, splineSeries.at(0).y);
132 scatterSeries.remove(scatterSeries.at(0).x, scatterSeries.at(0).y);
128 scatterSeries.remove(scatterSeries.at(0).x, scatterSeries.at(0).y);
133 }
129 }
134 compare(lineSeries.count, 0);
130 compare(lineSeries.count, 0);
135 compare(splineSeries.count, 0);
131 compare(splineSeries.count, 0);
136 compare(scatterSeries.count, 0);
132 compare(scatterSeries.count, 0);
137 tryCompare(lineSeriesPointRemovedSpy.count, count);
133 tryCompare(lineSeriesPointRemovedSpy.count, count);
138 tryCompare(splineSeriesPointRemovedSpy.count, count);
134 tryCompare(splineSeriesPointRemovedSpy.count, count);
139 tryCompare(scatterSeriesPointRemovedSpy.count, count);
135 tryCompare(scatterSeriesPointRemovedSpy.count, count);
140 }
136 }
141
137
142 // Not a test function, called from test functions
138 // Not a test function, called from test functions
143 function append() {
139 function append() {
144 var count = 100;
140 var count = 100;
145 chartView.axisX().min = 0;
141 chartView.axisX().min = 0;
146 chartView.axisX().max = 100;
142 chartView.axisX().max = 100;
147 chartView.axisY().min = 0;
143 chartView.axisY().min = 0;
148 chartView.axisY().max = 1;
144 chartView.axisY().max = 1;
149
145
150 for (var i = 0; i < count; i++) {
146 for (var i = 0; i < count; i++) {
151 lineSeries.append(i, Math.random());
147 lineSeries.append(i, Math.random());
152 splineSeries.append(i, Math.random());
148 splineSeries.append(i, Math.random());
153 scatterSeries.append(i, Math.random());
149 scatterSeries.append(i, Math.random());
154 }
150 }
155
151
156 return count;
152 return count;
157 }
153 }
158
154
159 // Not a test function, called from test functions
155 // Not a test function, called from test functions
160 function clear() {
156 function clear() {
161 lineSeries.clear();
157 lineSeries.clear();
162 splineSeries.clear();
158 splineSeries.clear();
163 scatterSeries.clear();
159 scatterSeries.clear();
164 }
160 }
165 }
161 }
166
162
167 ChartView {
163 ChartView {
168 id: chartView
164 id: chartView
169 anchors.fill: parent
165 anchors.fill: parent
170
166
171 LineSeries {
167 LineSeries {
172 id: lineSeries
168 id: lineSeries
173 name: "line"
169 name: "line"
174
170
175 SignalSpy {
171 SignalSpy {
176 id: lineSeriesPointAddedSpy
172 id: lineSeriesPointAddedSpy
177 target: lineSeries
173 target: lineSeries
178 signalName: "pointAdded"
174 signalName: "pointAdded"
179 }
175 }
180
176
181 SignalSpy {
177 SignalSpy {
182 id: lineSeriesPointReplacedSpy
178 id: lineSeriesPointReplacedSpy
183 target: lineSeries
179 target: lineSeries
184 signalName: "pointReplaced"
180 signalName: "pointReplaced"
185 }
181 }
186
182
187 SignalSpy {
183 SignalSpy {
188 id: lineSeriesPointsReplacedSpy
184 id: lineSeriesPointsReplacedSpy
189 target: lineSeries
185 target: lineSeries
190 signalName: "pointsReplaced"
186 signalName: "pointsReplaced"
191 }
187 }
192
188
193 SignalSpy {
189 SignalSpy {
194 id: lineSeriesPointRemovedSpy
190 id: lineSeriesPointRemovedSpy
195 target: lineSeries
191 target: lineSeries
196 signalName: "pointRemoved"
192 signalName: "pointRemoved"
197 }
193 }
198 }
194 }
199
195
200 AreaSeries {
196 AreaSeries {
201 id: areaSeries
197 id: areaSeries
202 name: "area"
198 name: "area"
203 upperSeries: lineSeries
199 upperSeries: lineSeries
204 }
200 }
205
201
206 SplineSeries {
202 SplineSeries {
207 id: splineSeries
203 id: splineSeries
208 name: "spline"
204 name: "spline"
209
205
210 SignalSpy {
206 SignalSpy {
211 id: splineSeriesPointAddedSpy
207 id: splineSeriesPointAddedSpy
212 target: splineSeries
208 target: splineSeries
213 signalName: "pointAdded"
209 signalName: "pointAdded"
214 }
210 }
215
211
216 SignalSpy {
212 SignalSpy {
217 id: splineSeriesPointReplacedSpy
213 id: splineSeriesPointReplacedSpy
218 target: splineSeries
214 target: splineSeries
219 signalName: "pointReplaced"
215 signalName: "pointReplaced"
220 }
216 }
221
217
222 SignalSpy {
218 SignalSpy {
223 id: splineSeriesPointsReplacedSpy
219 id: splineSeriesPointsReplacedSpy
224 target: splineSeries
220 target: splineSeries
225 signalName: "pointsReplaced"
221 signalName: "pointsReplaced"
226 }
222 }
227
223
228 SignalSpy {
224 SignalSpy {
229 id: splineSeriesPointRemovedSpy
225 id: splineSeriesPointRemovedSpy
230 target: splineSeries
226 target: splineSeries
231 signalName: "pointRemoved"
227 signalName: "pointRemoved"
232 }
228 }
233 }
229 }
234
230
235 ScatterSeries {
231 ScatterSeries {
236 id: scatterSeries
232 id: scatterSeries
237 name: "scatter"
233 name: "scatter"
238
234
239 SignalSpy {
235 SignalSpy {
240 id: scatterSeriesPointAddedSpy
236 id: scatterSeriesPointAddedSpy
241 target: scatterSeries
237 target: scatterSeries
242 signalName: "pointAdded"
238 signalName: "pointAdded"
243 }
239 }
244
240
245 SignalSpy {
241 SignalSpy {
246 id: scatterSeriesPointReplacedSpy
242 id: scatterSeriesPointReplacedSpy
247 target: scatterSeries
243 target: scatterSeries
248 signalName: "pointReplaced"
244 signalName: "pointReplaced"
249 }
245 }
250
246
251 SignalSpy {
247 SignalSpy {
252 id: scatterSeriesPointsReplacedSpy
248 id: scatterSeriesPointsReplacedSpy
253 target: scatterSeries
249 target: scatterSeries
254 signalName: "pointsReplaced"
250 signalName: "pointsReplaced"
255 }
251 }
256
252
257 SignalSpy {
253 SignalSpy {
258 id: scatterSeriesPointRemovedSpy
254 id: scatterSeriesPointRemovedSpy
259 target: scatterSeries
255 target: scatterSeries
260 signalName: "pointRemoved"
256 signalName: "pointRemoved"
261 }
257 }
262 }
258 }
263 }
259 }
264 }
260 }
General Comments 0
You need to be logged in to leave comments. Login now