##// END OF EJS Templates
Added ChartView.plotArea to QML API
Tero Ahola -
r1929:0db37e179fcd
parent child
Show More
@@ -1,677 +1,689
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
35
36 #ifndef QT_ON_ARM
36 #ifndef QT_ON_ARM
37 #include "qdatetimeaxis.h"
37 #include "qdatetimeaxis.h"
38 #endif
38 #endif
39
39
40 QTCOMMERCIALCHART_BEGIN_NAMESPACE
40 QTCOMMERCIALCHART_BEGIN_NAMESPACE
41
41
42 /*!
42 /*!
43 \qmlclass ChartView DeclarativeChart
43 \qmlclass ChartView DeclarativeChart
44
44
45 ChartView element is the parent that is responsible for showing different chart series types.
45 ChartView element is the parent that is responsible for showing different chart series types.
46
46
47 The following QML shows how to create a simple chart with one pie series:
47 The following QML shows how to create a simple chart with one pie series:
48 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 1
48 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 1
49 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2
49 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2
50 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 3
50 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 3
51
51
52 \beginfloatleft
52 \beginfloatleft
53 \image examples_qmlpiechart.png
53 \image examples_qmlpiechart.png
54 \endfloat
54 \endfloat
55 \clearfloat
55 \clearfloat
56 */
56 */
57
57
58 /*!
58 /*!
59 \qmlproperty Theme ChartView::theme
59 \qmlproperty Theme ChartView::theme
60 Theme defines the visual appearance of the chart, including for example colors, fonts, line
60 Theme defines the visual appearance of the chart, including for example colors, fonts, line
61 widths and chart background.
61 widths and chart background.
62 */
62 */
63
63
64 /*!
64 /*!
65 \qmlproperty Animation ChartView::animation
65 \qmlproperty Animation ChartView::animation
66 Animation configuration of the chart. One of ChartView.NoAnimation, ChartView.GridAxisAnimations,
66 Animation configuration of the chart. One of ChartView.NoAnimation, ChartView.GridAxisAnimations,
67 ChartView.SeriesAnimations or ChartView.AllAnimations.
67 ChartView.SeriesAnimations or ChartView.AllAnimations.
68 */
68 */
69
69
70 /*!
70 /*!
71 \qmlproperty Font ChartView::titleFont
71 \qmlproperty Font ChartView::titleFont
72 The title font of the chart
72 The title font of the chart
73
73
74 See the \l {Font} {QML Font Element} for detailed documentation.
74 See the \l {Font} {QML Font Element} for detailed documentation.
75 */
75 */
76
76
77 /*!
77 /*!
78 \qmlproperty string ChartView::title
78 \qmlproperty string ChartView::title
79 The title of the chart, shown on top of the chart.
79 The title of the chart, shown on top of the chart.
80 \sa ChartView::titleColor
80 \sa ChartView::titleColor
81 */
81 */
82
82
83 /*!
83 /*!
84 \qmlproperty string ChartView::titleColor
84 \qmlproperty string ChartView::titleColor
85 The color of the title text.
85 The color of the title text.
86 */
86 */
87
87
88 /*!
88 /*!
89 \qmlproperty Axis ChartView::axisX
89 \qmlproperty Axis ChartView::axisX
90 The x-axis of the chart.
90 The x-axis of the chart.
91 */
91 */
92
92
93 /*!
93 /*!
94 \qmlproperty Axis ChartView::axisY
94 \qmlproperty Axis ChartView::axisY
95 The default y-axis of the chart.
95 The default y-axis of the chart.
96 */
96 */
97
97
98 /*!
98 /*!
99 \qmlproperty Legend ChartView::legend
99 \qmlproperty Legend ChartView::legend
100 The legend of the chart. Legend lists all the series, pie slices and bar sets added on the chart.
100 The legend of the chart. Legend lists all the series, pie slices and bar sets added on the chart.
101 */
101 */
102
102
103 /*!
103 /*!
104 \qmlproperty int ChartView::count
104 \qmlproperty int ChartView::count
105 The count of series added to the chart.
105 The count of series added to the chart.
106 */
106 */
107
107
108 /*!
108 /*!
109 \qmlproperty color ChartView::backgroundColor
109 \qmlproperty color ChartView::backgroundColor
110 The color of the chart's background. By default background color is defined by chart theme.
110 The color of the chart's background. By default background color is defined by chart theme.
111 \sa ChartView::theme
111 \sa ChartView::theme
112 */
112 */
113
113
114 /*!
114 /*!
115 \qmlproperty bool ChartView::dropShadowEnabled
115 \qmlproperty bool ChartView::dropShadowEnabled
116 The chart's border drop shadow. Set to true to enable drop shadow.
116 The chart's border drop shadow. Set to true to enable drop shadow.
117 */
117 */
118
118
119 /*!
119 /*!
120 \qmlproperty real ChartView::topMargin
120 \qmlproperty real ChartView::topMargin
121 Deprecated. Use minimumMargins and plotArea instead.
121 Deprecated. Use minimumMargins and plotArea instead.
122 */
122 */
123
123
124 /*!
124 /*!
125 \qmlproperty real ChartView::bottomMargin
125 \qmlproperty real ChartView::bottomMargin
126 Deprecated. Use minimumMargins and plotArea instead.
126 Deprecated. Use minimumMargins and plotArea instead.
127 */
127 */
128
128
129 /*!
129 /*!
130 \qmlproperty real ChartView::leftMargin
130 \qmlproperty real ChartView::leftMargin
131 Deprecated. Use minimumMargins and plotArea instead.
131 Deprecated. Use minimumMargins and plotArea instead.
132 */
132 */
133
133
134 /*!
134 /*!
135 \qmlproperty real ChartView::rightMargin
135 \qmlproperty real ChartView::rightMargin
136 Deprecated. Use minimumMargins and plotArea instead.
136 Deprecated. Use minimumMargins and plotArea instead.
137 */
137 */
138
138
139 /*!
139 /*!
140 \qmlproperty Margins ChartView::minimumMargins
140 \qmlproperty Margins ChartView::minimumMargins
141 The minimum margins allowed between the outer bounds and the plotArea of the ChartView.
141 The minimum margins allowed between the outer bounds and the plotArea of the ChartView. Margins
142 area of ChartView is used for drawing title, axes and legend. Please note that setting the
143 properties of minimumMargins may be bigger than the defined value, depending on other ChartView
144 properties that affect it's layout. If you need to know the actual plotting area used at any
145 given time, you can check ChartView::plotArea instead.
146 */
147
148 /*!
149 \qmlproperty rect ChartView::plotArea
150 The area on the ChartView that is used for drawing series. This is the ChartView rect without the
151 margins.
152 \sa ChartView::minimumMargins
142 */
153 */
143
154
144 /*!
155 /*!
145 \qmlmethod AbstractSeries ChartView::series(int index)
156 \qmlmethod AbstractSeries ChartView::series(int index)
146 Returns the series with \a index on the chart. This allows you to loop through the series of a chart together with
157 Returns the series with \a index on the chart. This allows you to loop through the series of a chart together with
147 the count property of the chart.
158 the count property of the chart.
148 */
159 */
149
160
150 /*!
161 /*!
151 \qmlmethod AbstractSeries ChartView::series(string name)
162 \qmlmethod AbstractSeries ChartView::series(string name)
152 Returns the first series on the chart with \a name. If there is no series with that name, returns null.
163 Returns the first series on the chart with \a name. If there is no series with that name, returns null.
153 */
164 */
154
165
155 /*!
166 /*!
156 \qmlmethod AbstractSeries ChartView::createSeries(SeriesType type, string name)
167 \qmlmethod AbstractSeries ChartView::createSeries(SeriesType type, string name)
157 Creates a series object of \a type to the chart. For example:
168 Creates a series object of \a type to the chart. For example:
158 \code
169 \code
159 var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter series");
170 var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter series");
160 scatter.markerSize = 22;
171 scatter.markerSize = 22;
161 scatter.append(1.1, 2.0);
172 scatter.append(1.1, 2.0);
162 \endcode
173 \endcode
163 */
174 */
164
175
165 /*!
176 /*!
166 \qmlmethod Axis ChartView::axisY(QAbstractSeries *series)
177 \qmlmethod Axis ChartView::axisY(QAbstractSeries *series)
167 The y-axis of the series. This is the same as the default y-axis of the chart as multiple y-axes are not yet supported.
178 The y-axis of the series. This is the same as the default y-axis of the chart as multiple y-axes are not yet supported.
168 */
179 */
169
180
170 /*!
181 /*!
171 \qmlmethod ChartView::zoomY(real factor)
182 \qmlmethod ChartView::zoomY(real factor)
172 Zooms in by \a factor on the center of the chart.
183 Zooms in by \a factor on the center of the chart.
173 */
184 */
174
185
175 /*!
186 /*!
176 \qmlmethod ChartView::scrollLeft(real pixels)
187 \qmlmethod ChartView::scrollLeft(real pixels)
177 Scrolls to left by \a pixels. This is a convenience function that suits for example for key navigation.
188 Scrolls to left by \a pixels. This is a convenience function that suits for example for key navigation.
178 \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max
189 \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max
179 */
190 */
180
191
181 /*!
192 /*!
182 \qmlmethod ChartView::scrollRight(real pixels)
193 \qmlmethod ChartView::scrollRight(real pixels)
183 Scrolls to right by \a pixels. This is a convenience function that suits for example for key navigation.
194 Scrolls to right by \a pixels. This is a convenience function that suits for example for key navigation.
184 \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max
195 \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max
185 */
196 */
186
197
187 /*!
198 /*!
188 \qmlmethod ChartView::scrollUp(real pixels)
199 \qmlmethod ChartView::scrollUp(real pixels)
189 Scrolls up by \a pixels. This is a convenience function that suits for example for key navigation.
200 Scrolls up by \a pixels. This is a convenience function that suits for example for key navigation.
190 \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max
201 \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max
191 */
202 */
192
203
193 /*!
204 /*!
194 \qmlmethod ChartView::scrollDown(real pixels)
205 \qmlmethod ChartView::scrollDown(real pixels)
195 Scrolls down by \a pixels. This is a convenience function that suits for example for key navigation.
206 Scrolls down by \a pixels. This is a convenience function that suits for example for key navigation.
196 \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max
207 \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max
197 */
208 */
198
209
199 /*!
210 /*!
200 \qmlsignal ChartView::onTopMarginChanged(real margin)
211 \qmlsignal ChartView::onTopMarginChanged(real margin)
201 The top margin of the chart view has changed to \a margin. This may happen for example if you modify font size
212 The top margin of the chart view has changed to \a margin. This may happen for example if you modify font size
202 related properties of the legend or chart title.
213 related properties of the legend or chart title.
203 */
214 */
204
215
205 /*!
216 /*!
206 \qmlsignal ChartView::onBottomMarginChanged(real margin)
217 \qmlsignal ChartView::onBottomMarginChanged(real margin)
207 The bottom margin of the chart view has changed to \a margin. This may happen for example if you modify font size
218 The bottom margin of the chart view has changed to \a margin. This may happen for example if you modify font size
208 related properties of the legend or chart title.
219 related properties of the legend or chart title.
209 */
220 */
210
221
211 /*!
222 /*!
212 \qmlsignal ChartView::onLeftMarginChanged(real margin)
223 \qmlsignal ChartView::onLeftMarginChanged(real margin)
213 The left margin of the chart view has changed to \a margin. This may happen for example if you modify font size
224 The left margin of the chart view has changed to \a margin. This may happen for example if you modify font size
214 related properties of the legend or chart title.
225 related properties of the legend or chart title.
215 */
226 */
216
227
217 /*!
228 /*!
218 \qmlsignal ChartView::onRightMarginChanged(real margin)
229 \qmlsignal ChartView::onRightMarginChanged(real margin)
219 The right margin of the chart view has changed to \a margin. This may happen for example if you modify font size
230 The right margin of the chart view has changed to \a margin. This may happen for example if you modify font size
220 related properties of the legend or chart title.
231 related properties of the legend or chart title.
221 */
232 */
222
233
223 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent)
234 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent)
224 : QDeclarativeItem(parent),
235 : QDeclarativeItem(parent),
225 m_chart(new QChart(this))
236 m_chart(new QChart(this))
226 {
237 {
227 setFlag(QGraphicsItem::ItemHasNoContents, false);
238 setFlag(QGraphicsItem::ItemHasNoContents, false);
228 m_minMargins = new DeclarativeMargins(this);
239 m_minMargins = new DeclarativeMargins(this);
229 connect(m_minMargins, SIGNAL(topChanged(int, int, int, int)), this, SLOT(changeMinimumMargins(int, int, int, int)));
240 connect(m_minMargins, SIGNAL(topChanged(int, int, int, int)), this, SLOT(changeMinimumMargins(int, int, int, int)));
230 connect(m_minMargins, SIGNAL(bottomChanged(int, int, int, int)), this, SLOT(changeMinimumMargins(int, int, int, int)));
241 connect(m_minMargins, SIGNAL(bottomChanged(int, int, int, int)), this, SLOT(changeMinimumMargins(int, int, int, int)));
231 connect(m_minMargins, SIGNAL(leftChanged(int, int, int, int)), this, SLOT(changeMinimumMargins(int, int, int, int)));
242 connect(m_minMargins, SIGNAL(leftChanged(int, int, int, int)), this, SLOT(changeMinimumMargins(int, int, int, int)));
232 connect(m_minMargins, SIGNAL(rightChanged(int, int, int, int)), this, SLOT(changeMinimumMargins(int, int, int, int)));
243 connect(m_minMargins, SIGNAL(rightChanged(int, int, int, int)), this, SLOT(changeMinimumMargins(int, int, int, int)));
233 // TODO: connect to plotAreaChanged signal from m_chart
244 // TODO: connect to plotAreaChanged signal from m_chart
234 }
245 }
235
246
236 void DeclarativeChart::changeMinimumMargins(int top, int bottom, int left, int right)
247 void DeclarativeChart::changeMinimumMargins(int top, int bottom, int left, int right)
237 {
248 {
238 m_chart->setMinimumMargins(QMargins(left, top, right, bottom));
249 m_chart->setMinimumMargins(QMargins(left, top, right, bottom));
250 plotAreaChanged(m_chart->plotArea());
239 }
251 }
240
252
241 DeclarativeChart::~DeclarativeChart()
253 DeclarativeChart::~DeclarativeChart()
242 {
254 {
243 delete m_chart;
255 delete m_chart;
244 }
256 }
245
257
246 void DeclarativeChart::childEvent(QChildEvent *event)
258 void DeclarativeChart::childEvent(QChildEvent *event)
247 {
259 {
248 if (event->type() == QEvent::ChildAdded) {
260 if (event->type() == QEvent::ChildAdded) {
249 if (qobject_cast<QAbstractSeries *>(event->child())) {
261 if (qobject_cast<QAbstractSeries *>(event->child())) {
250 m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child()));
262 m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child()));
251 }
263 }
252 }
264 }
253 }
265 }
254
266
255 void DeclarativeChart::componentComplete()
267 void DeclarativeChart::componentComplete()
256 {
268 {
257 foreach(QObject *child, children()) {
269 foreach(QObject *child, children()) {
258 if (qobject_cast<QAbstractSeries *>(child)) {
270 if (qobject_cast<QAbstractSeries *>(child)) {
259 // Add series to the chart
271 // Add series to the chart
260 QAbstractSeries *series = qobject_cast<QAbstractSeries *>(child);
272 QAbstractSeries *series = qobject_cast<QAbstractSeries *>(child);
261 m_chart->addSeries(series);
273 m_chart->addSeries(series);
262
274
263 // Set optional user defined axes and connect axis related signals
275 // Set optional user defined axes and connect axis related signals
264 if (qobject_cast<DeclarativeLineSeries *>(child)) {
276 if (qobject_cast<DeclarativeLineSeries *>(child)) {
265 DeclarativeLineSeries *s = qobject_cast<DeclarativeLineSeries *>(child);
277 DeclarativeLineSeries *s = qobject_cast<DeclarativeLineSeries *>(child);
266 connect(s, SIGNAL(axisXChanged(QAbstractAxis *)), this, SLOT(handleAxisXSet(QAbstractAxis *)));
278 connect(s, SIGNAL(axisXChanged(QAbstractAxis *)), this, SLOT(handleAxisXSet(QAbstractAxis *)));
267 connect(s, SIGNAL(axisYChanged(QAbstractAxis *)), this, SLOT(handleAxisYSet(QAbstractAxis *)));
279 connect(s, SIGNAL(axisYChanged(QAbstractAxis *)), this, SLOT(handleAxisYSet(QAbstractAxis *)));
268 setAxisX(s->axisX(), s);
280 setAxisX(s->axisX(), s);
269 setAxisY(s->axisY(), s);
281 setAxisY(s->axisY(), s);
270 } else if (qobject_cast<DeclarativeSplineSeries *>(child)) {
282 } else if (qobject_cast<DeclarativeSplineSeries *>(child)) {
271 DeclarativeSplineSeries *s = qobject_cast<DeclarativeSplineSeries *>(child);
283 DeclarativeSplineSeries *s = qobject_cast<DeclarativeSplineSeries *>(child);
272 connect(s, SIGNAL(axisXChanged(QAbstractAxis *)), this, SLOT(handleAxisXSet(QAbstractAxis *)));
284 connect(s, SIGNAL(axisXChanged(QAbstractAxis *)), this, SLOT(handleAxisXSet(QAbstractAxis *)));
273 connect(s, SIGNAL(axisYChanged(QAbstractAxis *)), this, SLOT(handleAxisYSet(QAbstractAxis *)));
285 connect(s, SIGNAL(axisYChanged(QAbstractAxis *)), this, SLOT(handleAxisYSet(QAbstractAxis *)));
274 setAxisX(s->axisX(), s);
286 setAxisX(s->axisX(), s);
275 setAxisY(s->axisY(), s);
287 setAxisY(s->axisY(), s);
276 } else if (qobject_cast<DeclarativeScatterSeries *>(child)) {
288 } else if (qobject_cast<DeclarativeScatterSeries *>(child)) {
277 DeclarativeScatterSeries *s = qobject_cast<DeclarativeScatterSeries *>(child);
289 DeclarativeScatterSeries *s = qobject_cast<DeclarativeScatterSeries *>(child);
278 connect(s, SIGNAL(axisXChanged(QAbstractAxis *)), this, SLOT(handleAxisXSet(QAbstractAxis *)));
290 connect(s, SIGNAL(axisXChanged(QAbstractAxis *)), this, SLOT(handleAxisXSet(QAbstractAxis *)));
279 connect(s, SIGNAL(axisYChanged(QAbstractAxis *)), this, SLOT(handleAxisYSet(QAbstractAxis *)));
291 connect(s, SIGNAL(axisYChanged(QAbstractAxis *)), this, SLOT(handleAxisYSet(QAbstractAxis *)));
280 setAxisX(s->axisX(), s);
292 setAxisX(s->axisX(), s);
281 setAxisY(s->axisY(), s);
293 setAxisY(s->axisY(), s);
282 } else if (qobject_cast<DeclarativeAreaSeries *>(child)) {
294 } else if (qobject_cast<DeclarativeAreaSeries *>(child)) {
283 DeclarativeAreaSeries *s = qobject_cast<DeclarativeAreaSeries *>(child);
295 DeclarativeAreaSeries *s = qobject_cast<DeclarativeAreaSeries *>(child);
284 connect(s, SIGNAL(axisXChanged(QAbstractAxis *)), this, SLOT(handleAxisXSet(QAbstractAxis *)));
296 connect(s, SIGNAL(axisXChanged(QAbstractAxis *)), this, SLOT(handleAxisXSet(QAbstractAxis *)));
285 connect(s, SIGNAL(axisYChanged(QAbstractAxis *)), this, SLOT(handleAxisYSet(QAbstractAxis *)));
297 connect(s, SIGNAL(axisYChanged(QAbstractAxis *)), this, SLOT(handleAxisYSet(QAbstractAxis *)));
286 setAxisX(s->axisX(), s);
298 setAxisX(s->axisX(), s);
287 setAxisY(s->axisY(), s);
299 setAxisY(s->axisY(), s);
288 } else if (qobject_cast<DeclarativeBarSeries *>(child)) {
300 } else if (qobject_cast<DeclarativeBarSeries *>(child)) {
289 DeclarativeBarSeries *s = qobject_cast<DeclarativeBarSeries *>(child);
301 DeclarativeBarSeries *s = qobject_cast<DeclarativeBarSeries *>(child);
290 connect(s, SIGNAL(axisXChanged(QAbstractAxis *)), this, SLOT(handleAxisXSet(QAbstractAxis *)));
302 connect(s, SIGNAL(axisXChanged(QAbstractAxis *)), this, SLOT(handleAxisXSet(QAbstractAxis *)));
291 connect(s, SIGNAL(axisYChanged(QAbstractAxis *)), this, SLOT(handleAxisYSet(QAbstractAxis *)));
303 connect(s, SIGNAL(axisYChanged(QAbstractAxis *)), this, SLOT(handleAxisYSet(QAbstractAxis *)));
292 setAxisX(s->axisX(), s);
304 setAxisX(s->axisX(), s);
293 setAxisY(s->axisY(), s);
305 setAxisY(s->axisY(), s);
294 } else if (qobject_cast<DeclarativeStackedBarSeries *>(child)) {
306 } else if (qobject_cast<DeclarativeStackedBarSeries *>(child)) {
295 DeclarativeStackedBarSeries *s = qobject_cast<DeclarativeStackedBarSeries *>(child);
307 DeclarativeStackedBarSeries *s = qobject_cast<DeclarativeStackedBarSeries *>(child);
296 connect(s, SIGNAL(axisXChanged(QAbstractAxis *)), this, SLOT(handleAxisXSet(QAbstractAxis *)));
308 connect(s, SIGNAL(axisXChanged(QAbstractAxis *)), this, SLOT(handleAxisXSet(QAbstractAxis *)));
297 connect(s, SIGNAL(axisYChanged(QAbstractAxis *)), this, SLOT(handleAxisYSet(QAbstractAxis *)));
309 connect(s, SIGNAL(axisYChanged(QAbstractAxis *)), this, SLOT(handleAxisYSet(QAbstractAxis *)));
298 setAxisX(s->axisX(), s);
310 setAxisX(s->axisX(), s);
299 setAxisY(s->axisY(), s);
311 setAxisY(s->axisY(), s);
300 } else if (qobject_cast<DeclarativePercentBarSeries *>(child)) {
312 } else if (qobject_cast<DeclarativePercentBarSeries *>(child)) {
301 DeclarativePercentBarSeries *s = qobject_cast<DeclarativePercentBarSeries *>(child);
313 DeclarativePercentBarSeries *s = qobject_cast<DeclarativePercentBarSeries *>(child);
302 connect(s, SIGNAL(axisXChanged(QAbstractAxis *)), this, SLOT(handleAxisXSet(QAbstractAxis *)));
314 connect(s, SIGNAL(axisXChanged(QAbstractAxis *)), this, SLOT(handleAxisXSet(QAbstractAxis *)));
303 connect(s, SIGNAL(axisYChanged(QAbstractAxis *)), this, SLOT(handleAxisYSet(QAbstractAxis *)));
315 connect(s, SIGNAL(axisYChanged(QAbstractAxis *)), this, SLOT(handleAxisYSet(QAbstractAxis *)));
304 setAxisX(s->axisX(), s);
316 setAxisX(s->axisX(), s);
305 setAxisY(s->axisY(), s);
317 setAxisY(s->axisY(), s);
306 } else if (qobject_cast<DeclarativeHorizontalBarSeries *>(child)) {
318 } else if (qobject_cast<DeclarativeHorizontalBarSeries *>(child)) {
307 DeclarativeHorizontalBarSeries *s = qobject_cast<DeclarativeHorizontalBarSeries *>(child);
319 DeclarativeHorizontalBarSeries *s = qobject_cast<DeclarativeHorizontalBarSeries *>(child);
308 connect(s, SIGNAL(axisXChanged(QAbstractAxis *)), this, SLOT(handleAxisXSet(QAbstractAxis *)));
320 connect(s, SIGNAL(axisXChanged(QAbstractAxis *)), this, SLOT(handleAxisXSet(QAbstractAxis *)));
309 connect(s, SIGNAL(axisYChanged(QAbstractAxis *)), this, SLOT(handleAxisYSet(QAbstractAxis *)));
321 connect(s, SIGNAL(axisYChanged(QAbstractAxis *)), this, SLOT(handleAxisYSet(QAbstractAxis *)));
310 setAxisX(s->axisX(), s);
322 setAxisX(s->axisX(), s);
311 setAxisY(s->axisY(), s);
323 setAxisY(s->axisY(), s);
312 } else if (qobject_cast<DeclarativeHorizontalStackedBarSeries *>(child)) {
324 } else if (qobject_cast<DeclarativeHorizontalStackedBarSeries *>(child)) {
313 DeclarativeHorizontalStackedBarSeries *s = qobject_cast<DeclarativeHorizontalStackedBarSeries *>(child);
325 DeclarativeHorizontalStackedBarSeries *s = qobject_cast<DeclarativeHorizontalStackedBarSeries *>(child);
314 connect(s, SIGNAL(axisXChanged(QAbstractAxis *)), this, SLOT(handleAxisXSet(QAbstractAxis *)));
326 connect(s, SIGNAL(axisXChanged(QAbstractAxis *)), this, SLOT(handleAxisXSet(QAbstractAxis *)));
315 connect(s, SIGNAL(axisYChanged(QAbstractAxis *)), this, SLOT(handleAxisYSet(QAbstractAxis *)));
327 connect(s, SIGNAL(axisYChanged(QAbstractAxis *)), this, SLOT(handleAxisYSet(QAbstractAxis *)));
316 setAxisX(s->axisX(), s);
328 setAxisX(s->axisX(), s);
317 setAxisY(s->axisY(), s);
329 setAxisY(s->axisY(), s);
318 } else if (qobject_cast<DeclarativeHorizontalPercentBarSeries *>(child)) {
330 } else if (qobject_cast<DeclarativeHorizontalPercentBarSeries *>(child)) {
319 DeclarativeHorizontalPercentBarSeries *s = qobject_cast<DeclarativeHorizontalPercentBarSeries *>(child);
331 DeclarativeHorizontalPercentBarSeries *s = qobject_cast<DeclarativeHorizontalPercentBarSeries *>(child);
320 connect(s, SIGNAL(axisXChanged(QAbstractAxis *)), this, SLOT(handleAxisXSet(QAbstractAxis *)));
332 connect(s, SIGNAL(axisXChanged(QAbstractAxis *)), this, SLOT(handleAxisXSet(QAbstractAxis *)));
321 connect(s, SIGNAL(axisYChanged(QAbstractAxis *)), this, SLOT(handleAxisYSet(QAbstractAxis *)));
333 connect(s, SIGNAL(axisYChanged(QAbstractAxis *)), this, SLOT(handleAxisYSet(QAbstractAxis *)));
322 setAxisX(s->axisX(), s);
334 setAxisX(s->axisX(), s);
323 setAxisY(s->axisY(), s);
335 setAxisY(s->axisY(), s);
324 }
336 }
325
337
326 // Create the missing axes for the series that cannot be painted without axes
338 // Create the missing axes for the series that cannot be painted without axes
327 createDefaultAxes(series);
339 createDefaultAxes(series);
328 } else if(qobject_cast<QAbstractAxis *>(child)) {
340 } else if(qobject_cast<QAbstractAxis *>(child)) {
329 // Do nothing, axes are set for the chart in the context of series
341 // Do nothing, axes are set for the chart in the context of series
330 }
342 }
331 }
343 }
332
344
333 QDeclarativeItem::componentComplete();
345 QDeclarativeItem::componentComplete();
334 }
346 }
335
347
336 void DeclarativeChart::handleAxisXSet(QAbstractAxis* axis)
348 void DeclarativeChart::handleAxisXSet(QAbstractAxis* axis)
337 {
349 {
338 // qDebug() << "DeclarativeChart::handleAxisXSet" << sender() << axis;
350 // qDebug() << "DeclarativeChart::handleAxisXSet" << sender() << axis;
339 if (axis && qobject_cast<DeclarativeLineSeries *>(sender())) {
351 if (axis && qobject_cast<DeclarativeLineSeries *>(sender())) {
340 m_chart->setAxisX(axis, qobject_cast<DeclarativeLineSeries *>(sender()));
352 m_chart->setAxisX(axis, qobject_cast<DeclarativeLineSeries *>(sender()));
341 }
353 }
342 }
354 }
343
355
344 void DeclarativeChart::handleAxisYSet(QAbstractAxis* axis)
356 void DeclarativeChart::handleAxisYSet(QAbstractAxis* axis)
345 {
357 {
346 // qDebug() << "DeclarativeChart::handleAxisYSet" << sender() << axis;
358 // qDebug() << "DeclarativeChart::handleAxisYSet" << sender() << axis;
347 if (axis && qobject_cast<DeclarativeLineSeries *>(sender())) {
359 if (axis && qobject_cast<DeclarativeLineSeries *>(sender())) {
348 m_chart->setAxisY(axis, qobject_cast<DeclarativeLineSeries *>(sender()));
360 m_chart->setAxisY(axis, qobject_cast<DeclarativeLineSeries *>(sender()));
349 }
361 }
350 }
362 }
351
363
352 void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
364 void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
353 {
365 {
354 // qDebug() << "DeclarativeChart::geometryChanged" << newGeometry.width() << newGeometry.height();
366 // qDebug() << "DeclarativeChart::geometryChanged" << newGeometry.width() << newGeometry.height();
355 if (newGeometry.isValid()) {
367 if (newGeometry.isValid()) {
356 if (newGeometry.width() > 0 && newGeometry.height() > 0) {
368 if (newGeometry.width() > 0 && newGeometry.height() > 0) {
357 m_chart->resize(newGeometry.width(), newGeometry.height());
369 m_chart->resize(newGeometry.width(), newGeometry.height());
358 }
370 }
359 }
371 }
360 QDeclarativeItem::geometryChanged(newGeometry, oldGeometry);
372 QDeclarativeItem::geometryChanged(newGeometry, oldGeometry);
361 }
373 }
362
374
363 void DeclarativeChart::setTheme(DeclarativeChart::Theme theme)
375 void DeclarativeChart::setTheme(DeclarativeChart::Theme theme)
364 {
376 {
365 QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme;
377 QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme;
366 if (chartTheme != m_chart->theme())
378 if (chartTheme != m_chart->theme())
367 m_chart->setTheme(chartTheme);
379 m_chart->setTheme(chartTheme);
368 }
380 }
369
381
370 DeclarativeChart::Theme DeclarativeChart::theme()
382 DeclarativeChart::Theme DeclarativeChart::theme()
371 {
383 {
372 return (DeclarativeChart::Theme) m_chart->theme();
384 return (DeclarativeChart::Theme) m_chart->theme();
373 }
385 }
374
386
375 void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations)
387 void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations)
376 {
388 {
377 QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations;
389 QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations;
378 if (animationOptions != m_chart->animationOptions())
390 if (animationOptions != m_chart->animationOptions())
379 m_chart->setAnimationOptions(animationOptions);
391 m_chart->setAnimationOptions(animationOptions);
380 }
392 }
381
393
382 DeclarativeChart::Animation DeclarativeChart::animationOptions()
394 DeclarativeChart::Animation DeclarativeChart::animationOptions()
383 {
395 {
384 if (m_chart->animationOptions().testFlag(QChart::AllAnimations))
396 if (m_chart->animationOptions().testFlag(QChart::AllAnimations))
385 return DeclarativeChart::AllAnimations;
397 return DeclarativeChart::AllAnimations;
386 else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations))
398 else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations))
387 return DeclarativeChart::GridAxisAnimations;
399 return DeclarativeChart::GridAxisAnimations;
388 else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations))
400 else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations))
389 return DeclarativeChart::SeriesAnimations;
401 return DeclarativeChart::SeriesAnimations;
390 else
402 else
391 return DeclarativeChart::NoAnimation;
403 return DeclarativeChart::NoAnimation;
392 }
404 }
393
405
394 void DeclarativeChart::setTitle(QString title)
406 void DeclarativeChart::setTitle(QString title)
395 {
407 {
396 if (title != m_chart->title())
408 if (title != m_chart->title())
397 m_chart->setTitle(title);
409 m_chart->setTitle(title);
398 }
410 }
399 QString DeclarativeChart::title()
411 QString DeclarativeChart::title()
400 {
412 {
401 return m_chart->title();
413 return m_chart->title();
402 }
414 }
403
415
404 QAbstractAxis *DeclarativeChart::axisX(QAbstractSeries *series)
416 QAbstractAxis *DeclarativeChart::axisX(QAbstractSeries *series)
405 {
417 {
406 return m_chart->axisX(series);
418 return m_chart->axisX(series);
407 }
419 }
408
420
409 QAbstractAxis *DeclarativeChart::axisY(QAbstractSeries *series)
421 QAbstractAxis *DeclarativeChart::axisY(QAbstractSeries *series)
410 {
422 {
411 return m_chart->axisY(series);
423 return m_chart->axisY(series);
412 }
424 }
413
425
414 QLegend *DeclarativeChart::legend()
426 QLegend *DeclarativeChart::legend()
415 {
427 {
416 return m_chart->legend();
428 return m_chart->legend();
417 }
429 }
418
430
419 void DeclarativeChart::setTitleColor(QColor color)
431 void DeclarativeChart::setTitleColor(QColor color)
420 {
432 {
421 QBrush b = m_chart->titleBrush();
433 QBrush b = m_chart->titleBrush();
422 if (color != b.color()) {
434 if (color != b.color()) {
423 b.setColor(color);
435 b.setColor(color);
424 m_chart->setTitleBrush(b);
436 m_chart->setTitleBrush(b);
425 emit titleColorChanged(color);
437 emit titleColorChanged(color);
426 }
438 }
427 }
439 }
428
440
429 QFont DeclarativeChart::titleFont() const
441 QFont DeclarativeChart::titleFont() const
430 {
442 {
431 return m_chart->titleFont();
443 return m_chart->titleFont();
432 }
444 }
433
445
434 void DeclarativeChart::setTitleFont(const QFont& font)
446 void DeclarativeChart::setTitleFont(const QFont& font)
435 {
447 {
436 m_chart->setTitleFont(font);
448 m_chart->setTitleFont(font);
437 }
449 }
438
450
439 QColor DeclarativeChart::titleColor()
451 QColor DeclarativeChart::titleColor()
440 {
452 {
441 return m_chart->titleBrush().color();
453 return m_chart->titleBrush().color();
442 }
454 }
443
455
444 void DeclarativeChart::setBackgroundColor(QColor color)
456 void DeclarativeChart::setBackgroundColor(QColor color)
445 {
457 {
446 QBrush b = m_chart->backgroundBrush();
458 QBrush b = m_chart->backgroundBrush();
447 if (b.style() != Qt::SolidPattern || color != b.color()) {
459 if (b.style() != Qt::SolidPattern || color != b.color()) {
448 b.setStyle(Qt::SolidPattern);
460 b.setStyle(Qt::SolidPattern);
449 b.setColor(color);
461 b.setColor(color);
450 m_chart->setBackgroundBrush(b);
462 m_chart->setBackgroundBrush(b);
451 emit backgroundColorChanged();
463 emit backgroundColorChanged();
452 }
464 }
453 }
465 }
454
466
455 QColor DeclarativeChart::backgroundColor()
467 QColor DeclarativeChart::backgroundColor()
456 {
468 {
457 return m_chart->backgroundBrush().color();
469 return m_chart->backgroundBrush().color();
458 }
470 }
459
471
460 int DeclarativeChart::count()
472 int DeclarativeChart::count()
461 {
473 {
462 return m_chart->series().count();
474 return m_chart->series().count();
463 }
475 }
464
476
465 void DeclarativeChart::setDropShadowEnabled(bool enabled)
477 void DeclarativeChart::setDropShadowEnabled(bool enabled)
466 {
478 {
467 if (enabled != m_chart->isDropShadowEnabled()) {
479 if (enabled != m_chart->isDropShadowEnabled()) {
468 m_chart->setDropShadowEnabled(enabled);
480 m_chart->setDropShadowEnabled(enabled);
469 dropShadowEnabledChanged(enabled);
481 dropShadowEnabledChanged(enabled);
470 }
482 }
471 }
483 }
472
484
473 bool DeclarativeChart::dropShadowEnabled()
485 bool DeclarativeChart::dropShadowEnabled()
474 {
486 {
475 return m_chart->isDropShadowEnabled();
487 return m_chart->isDropShadowEnabled();
476 }
488 }
477
489
478 qreal DeclarativeChart::topMargin()
490 qreal DeclarativeChart::topMargin()
479 {
491 {
480 qWarning() << "ChartView.topMargin is deprecated. Use minimumMargins and plotArea instead.";
492 qWarning() << "ChartView.topMargin is deprecated. Use minimumMargins and plotArea instead.";
481 return m_chart->plotArea().top();
493 return m_chart->plotArea().top();
482 }
494 }
483
495
484 qreal DeclarativeChart::bottomMargin()
496 qreal DeclarativeChart::bottomMargin()
485 {
497 {
486 qWarning() << "ChartView.bottomMargin is deprecated. Use minimumMargins and plotArea instead.";
498 qWarning() << "ChartView.bottomMargin is deprecated. Use minimumMargins and plotArea instead.";
487 return m_chart->plotArea().bottom();
499 return m_chart->plotArea().bottom();
488 }
500 }
489
501
490 qreal DeclarativeChart::leftMargin()
502 qreal DeclarativeChart::leftMargin()
491 {
503 {
492 qWarning() << "ChartView.leftMargin is deprecated. Use minimumMargins and plotArea instead.";
504 qWarning() << "ChartView.leftMargin is deprecated. Use minimumMargins and plotArea instead.";
493 return m_chart->plotArea().left();
505 return m_chart->plotArea().left();
494 }
506 }
495
507
496 qreal DeclarativeChart::rightMargin()
508 qreal DeclarativeChart::rightMargin()
497 {
509 {
498 qWarning() << "ChartView.rightMargin is deprecated. Use minimumMargins and plotArea instead.";
510 qWarning() << "ChartView.rightMargin is deprecated. Use minimumMargins and plotArea instead.";
499 return m_chart->plotArea().right();
511 return m_chart->plotArea().right();
500 }
512 }
501
513
502 void DeclarativeChart::zoom(qreal factor)
514 void DeclarativeChart::zoom(qreal factor)
503 {
515 {
504 m_chart->zoom(factor);
516 m_chart->zoom(factor);
505 }
517 }
506
518
507 void DeclarativeChart::scrollLeft(qreal pixels)
519 void DeclarativeChart::scrollLeft(qreal pixels)
508 {
520 {
509 m_chart->scroll(pixels, 0);
521 m_chart->scroll(pixels, 0);
510 }
522 }
511
523
512 void DeclarativeChart::scrollRight(qreal pixels)
524 void DeclarativeChart::scrollRight(qreal pixels)
513 {
525 {
514 m_chart->scroll(-pixels, 0);
526 m_chart->scroll(-pixels, 0);
515 }
527 }
516
528
517 void DeclarativeChart::scrollUp(qreal pixels)
529 void DeclarativeChart::scrollUp(qreal pixels)
518 {
530 {
519 m_chart->scroll(0, pixels);
531 m_chart->scroll(0, pixels);
520 }
532 }
521
533
522 void DeclarativeChart::scrollDown(qreal pixels)
534 void DeclarativeChart::scrollDown(qreal pixels)
523 {
535 {
524 m_chart->scroll(0, -pixels);
536 m_chart->scroll(0, -pixels);
525 }
537 }
526
538
527 QAbstractSeries *DeclarativeChart::series(int index)
539 QAbstractSeries *DeclarativeChart::series(int index)
528 {
540 {
529 if (index < m_chart->series().count()) {
541 if (index < m_chart->series().count()) {
530 return m_chart->series().at(index);
542 return m_chart->series().at(index);
531 }
543 }
532 return 0;
544 return 0;
533 }
545 }
534
546
535 QAbstractSeries *DeclarativeChart::series(QString seriesName)
547 QAbstractSeries *DeclarativeChart::series(QString seriesName)
536 {
548 {
537 foreach(QAbstractSeries *series, m_chart->series()) {
549 foreach(QAbstractSeries *series, m_chart->series()) {
538 if (series->name() == seriesName)
550 if (series->name() == seriesName)
539 return series;
551 return series;
540 }
552 }
541 return 0;
553 return 0;
542 }
554 }
543
555
544 QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name)
556 QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name)
545 {
557 {
546 QAbstractSeries *series = 0;
558 QAbstractSeries *series = 0;
547
559
548 switch (type) {
560 switch (type) {
549 case DeclarativeChart::SeriesTypeLine:
561 case DeclarativeChart::SeriesTypeLine:
550 series = new DeclarativeLineSeries();
562 series = new DeclarativeLineSeries();
551 break;
563 break;
552 case DeclarativeChart::SeriesTypeArea:
564 case DeclarativeChart::SeriesTypeArea:
553 series = new DeclarativeAreaSeries();
565 series = new DeclarativeAreaSeries();
554 break;
566 break;
555 case DeclarativeChart::SeriesTypeStackedBar:
567 case DeclarativeChart::SeriesTypeStackedBar:
556 series = new DeclarativeStackedBarSeries();
568 series = new DeclarativeStackedBarSeries();
557 break;
569 break;
558 case DeclarativeChart::SeriesTypePercentBar:
570 case DeclarativeChart::SeriesTypePercentBar:
559 series = new DeclarativePercentBarSeries();
571 series = new DeclarativePercentBarSeries();
560 break;
572 break;
561 case DeclarativeChart::SeriesTypeBar:
573 case DeclarativeChart::SeriesTypeBar:
562 series = new DeclarativeBarSeries();
574 series = new DeclarativeBarSeries();
563 break;
575 break;
564 case DeclarativeChart::SeriesTypeHorizontalBar:
576 case DeclarativeChart::SeriesTypeHorizontalBar:
565 series = new DeclarativeHorizontalBarSeries();
577 series = new DeclarativeHorizontalBarSeries();
566 break;
578 break;
567 case DeclarativeChart::SeriesTypeHorizontalPercentBar:
579 case DeclarativeChart::SeriesTypeHorizontalPercentBar:
568 series = new DeclarativeHorizontalPercentBarSeries();
580 series = new DeclarativeHorizontalPercentBarSeries();
569 break;
581 break;
570 case DeclarativeChart::SeriesTypeHorizontalStackedBar:
582 case DeclarativeChart::SeriesTypeHorizontalStackedBar:
571 series = new DeclarativeHorizontalStackedBarSeries();
583 series = new DeclarativeHorizontalStackedBarSeries();
572 break;
584 break;
573 case DeclarativeChart::SeriesTypePie:
585 case DeclarativeChart::SeriesTypePie:
574 series = new DeclarativePieSeries();
586 series = new DeclarativePieSeries();
575 break;
587 break;
576 case DeclarativeChart::SeriesTypeScatter:
588 case DeclarativeChart::SeriesTypeScatter:
577 series = new DeclarativeScatterSeries();
589 series = new DeclarativeScatterSeries();
578 break;
590 break;
579 case DeclarativeChart::SeriesTypeSpline:
591 case DeclarativeChart::SeriesTypeSpline:
580 series = new DeclarativeSplineSeries();
592 series = new DeclarativeSplineSeries();
581 break;
593 break;
582 default:
594 default:
583 qWarning() << "Illegal series type";
595 qWarning() << "Illegal series type";
584 }
596 }
585
597
586 if (series) {
598 if (series) {
587 series->setName(name);
599 series->setName(name);
588 m_chart->addSeries(series);
600 m_chart->addSeries(series);
589 createDefaultAxes(series);
601 createDefaultAxes(series);
590 }
602 }
591
603
592 return series;
604 return series;
593 }
605 }
594
606
595 void DeclarativeChart::setAxisX(QAbstractAxis *axis, QAbstractSeries *series)
607 void DeclarativeChart::setAxisX(QAbstractAxis *axis, QAbstractSeries *series)
596 {
608 {
597 if (axis)
609 if (axis)
598 m_chart->setAxisX(axis, series);
610 m_chart->setAxisX(axis, series);
599 }
611 }
600
612
601 void DeclarativeChart::setAxisY(QAbstractAxis *axis, QAbstractSeries *series)
613 void DeclarativeChart::setAxisY(QAbstractAxis *axis, QAbstractSeries *series)
602 {
614 {
603 if (axis)
615 if (axis)
604 m_chart->setAxisY(axis, series);
616 m_chart->setAxisY(axis, series);
605 }
617 }
606
618
607 void DeclarativeChart::createDefaultAxes()
619 void DeclarativeChart::createDefaultAxes()
608 {
620 {
609 qWarning() << "ChartView.createDefaultAxes() is deprecated. Axes are created automatically.";
621 qWarning() << "ChartView.createDefaultAxes() is deprecated. Axes are created automatically.";
610 }
622 }
611
623
612 void DeclarativeChart::createDefaultAxes(QAbstractSeries* series)
624 void DeclarativeChart::createDefaultAxes(QAbstractSeries* series)
613 {
625 {
614 foreach (QAbstractSeries *s, m_chart->series()) {
626 foreach (QAbstractSeries *s, m_chart->series()) {
615 // If there is already an x axis of the correct type, re-use it
627 // If there is already an x axis of the correct type, re-use it
616 if (!m_chart->axisX(series) && s != series && m_chart->axisX(s)
628 if (!m_chart->axisX(series) && s != series && m_chart->axisX(s)
617 && m_chart->axisX(s)->type() == series->d_ptr->defaultAxisType(Qt::Horizontal))
629 && m_chart->axisX(s)->type() == series->d_ptr->defaultAxisType(Qt::Horizontal))
618 m_chart->setAxisX(m_chart->axisX(s), series);
630 m_chart->setAxisX(m_chart->axisX(s), series);
619
631
620 // If there is already a y axis of the correct type, re-use it
632 // If there is already a y axis of the correct type, re-use it
621 if (!m_chart->axisY(series) && s != series && m_chart->axisY(s)
633 if (!m_chart->axisY(series) && s != series && m_chart->axisY(s)
622 && m_chart->axisY(s)->type() == series->d_ptr->defaultAxisType(Qt::Vertical))
634 && m_chart->axisY(s)->type() == series->d_ptr->defaultAxisType(Qt::Vertical))
623 m_chart->setAxisY(m_chart->axisY(s), series);
635 m_chart->setAxisY(m_chart->axisY(s), series);
624 }
636 }
625
637
626 // If no x axis of correct type was found, create a new x axis based of default axis type
638 // If no x axis of correct type was found, create a new x axis based of default axis type
627 if (!m_chart->axisX(series)) {
639 if (!m_chart->axisX(series)) {
628 switch (series->d_ptr->defaultAxisType(Qt::Horizontal)) {
640 switch (series->d_ptr->defaultAxisType(Qt::Horizontal)) {
629 case QAbstractAxis::AxisTypeValue:
641 case QAbstractAxis::AxisTypeValue:
630 m_chart->setAxisX(new QValueAxis(this), series);
642 m_chart->setAxisX(new QValueAxis(this), series);
631 break;
643 break;
632 case QAbstractAxis::AxisTypeBarCategory:
644 case QAbstractAxis::AxisTypeBarCategory:
633 m_chart->setAxisX(new QBarCategoryAxis(this), series);
645 m_chart->setAxisX(new QBarCategoryAxis(this), series);
634 break;
646 break;
635 case QAbstractAxis::AxisTypeCategory:
647 case QAbstractAxis::AxisTypeCategory:
636 m_chart->setAxisX(new QCategoryAxis(this), series);
648 m_chart->setAxisX(new QCategoryAxis(this), series);
637 break;
649 break;
638 #ifndef QT_ON_ARM
650 #ifndef QT_ON_ARM
639 case QAbstractAxis::AxisTypeDateTime:
651 case QAbstractAxis::AxisTypeDateTime:
640 m_chart->setAxisX(new QDateTimeAxis(this), series);
652 m_chart->setAxisX(new QDateTimeAxis(this), series);
641 break;
653 break;
642 #endif
654 #endif
643 default:
655 default:
644 // Do nothing, assume AxisTypeNoAxis
656 // Do nothing, assume AxisTypeNoAxis
645 break;
657 break;
646 }
658 }
647 }
659 }
648
660
649 // If no y axis of correct type was found, create a new y axis based of default axis type
661 // If no y axis of correct type was found, create a new y axis based of default axis type
650 if (!m_chart->axisY(series)) {
662 if (!m_chart->axisY(series)) {
651 switch (series->d_ptr->defaultAxisType(Qt::Vertical)) {
663 switch (series->d_ptr->defaultAxisType(Qt::Vertical)) {
652 case QAbstractAxis::AxisTypeValue:
664 case QAbstractAxis::AxisTypeValue:
653 m_chart->setAxisY(new QValueAxis(this), series);
665 m_chart->setAxisY(new QValueAxis(this), series);
654 break;
666 break;
655 case QAbstractAxis::AxisTypeBarCategory:
667 case QAbstractAxis::AxisTypeBarCategory:
656 m_chart->setAxisY(new QBarCategoryAxis(this), series);
668 m_chart->setAxisY(new QBarCategoryAxis(this), series);
657 break;
669 break;
658 case QAbstractAxis::AxisTypeCategory:
670 case QAbstractAxis::AxisTypeCategory:
659 m_chart->setAxisY(new QCategoryAxis(this), series);
671 m_chart->setAxisY(new QCategoryAxis(this), series);
660 break;
672 break;
661 #ifndef QT_ON_ARM
673 #ifndef QT_ON_ARM
662 case QAbstractAxis::AxisTypeDateTime:
674 case QAbstractAxis::AxisTypeDateTime:
663 m_chart->setAxisY(new QDateTimeAxis(this), series);
675 m_chart->setAxisY(new QDateTimeAxis(this), series);
664 break;
676 break;
665 #endif
677 #endif
666 default:
678 default:
667 // Do nothing, assume AxisTypeNoAxis
679 // Do nothing, assume AxisTypeNoAxis
668 break;
680 break;
669 }
681 }
670 }
682 }
671
683
672 //qDebug() << "axis for series" << series << "x:" << m_chart->axisX(series) << "y:" << m_chart->axisY(series);
684 //qDebug() << "axis for series" << series << "x:" << m_chart->axisX(series) << "y:" << m_chart->axisY(series);
673 }
685 }
674
686
675 #include "moc_declarativechart.cpp"
687 #include "moc_declarativechart.cpp"
676
688
677 QTCOMMERCIALCHART_END_NAMESPACE
689 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,161 +1,164
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 <QDeclarativeItem>
25 #include <QDeclarativeItem>
26 #include "qchart.h"
26 #include "qchart.h"
27
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
29
30 class DeclarativeMargins;
30 class DeclarativeMargins;
31
31
32 class DeclarativeChart : public QDeclarativeItem
32 class DeclarativeChart : public QDeclarativeItem
33 {
33 {
34 Q_OBJECT
34 Q_OBJECT
35 Q_PROPERTY(Theme theme READ theme WRITE setTheme)
35 Q_PROPERTY(Theme theme READ theme WRITE setTheme)
36 Q_PROPERTY(Animation animationOptions READ animationOptions WRITE setAnimationOptions)
36 Q_PROPERTY(Animation animationOptions READ animationOptions WRITE setAnimationOptions)
37 Q_PROPERTY(QString title READ title WRITE setTitle)
37 Q_PROPERTY(QString title READ title WRITE setTitle)
38 Q_PROPERTY(QFont titleFont READ titleFont WRITE setTitleFont)
38 Q_PROPERTY(QFont titleFont READ titleFont WRITE setTitleFont)
39 Q_PROPERTY(QColor titleColor READ titleColor WRITE setTitleColor NOTIFY titleColorChanged)
39 Q_PROPERTY(QColor titleColor READ titleColor WRITE setTitleColor NOTIFY titleColorChanged)
40 Q_PROPERTY(QLegend *legend READ legend)
40 Q_PROPERTY(QLegend *legend READ legend)
41 Q_PROPERTY(int count READ count)
41 Q_PROPERTY(int count READ count)
42 Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged)
42 Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged)
43 Q_PROPERTY(bool dropShadowEnabled READ dropShadowEnabled WRITE setDropShadowEnabled NOTIFY dropShadowEnabledChanged)
43 Q_PROPERTY(bool dropShadowEnabled READ dropShadowEnabled WRITE setDropShadowEnabled NOTIFY dropShadowEnabledChanged)
44 Q_PROPERTY(qreal topMargin READ topMargin NOTIFY topMarginChanged)
44 Q_PROPERTY(qreal topMargin READ topMargin NOTIFY topMarginChanged)
45 Q_PROPERTY(qreal bottomMargin READ bottomMargin NOTIFY bottomMarginChanged)
45 Q_PROPERTY(qreal bottomMargin READ bottomMargin NOTIFY bottomMarginChanged)
46 Q_PROPERTY(qreal leftMargin READ leftMargin NOTIFY leftMarginChanged)
46 Q_PROPERTY(qreal leftMargin READ leftMargin NOTIFY leftMarginChanged)
47 Q_PROPERTY(qreal rightMargin READ rightMargin NOTIFY rightMarginChanged)
47 Q_PROPERTY(qreal rightMargin READ rightMargin NOTIFY rightMarginChanged)
48 Q_PROPERTY(DeclarativeMargins *minimumMargins READ minimumMargins REVISION 1)
48 Q_PROPERTY(DeclarativeMargins *minimumMargins READ minimumMargins REVISION 1)
49 Q_PROPERTY(QRectF plotArea READ plotArea NOTIFY plotAreaChanged REVISION 1)
49 Q_ENUMS(Animation)
50 Q_ENUMS(Animation)
50 Q_ENUMS(Theme)
51 Q_ENUMS(Theme)
51 Q_ENUMS(SeriesType)
52 Q_ENUMS(SeriesType)
52
53
53 public:
54 public:
54 // duplicating enums from QChart to make the QML api namings 1-to-1 with the C++ api
55 // duplicating enums from QChart to make the QML api namings 1-to-1 with the C++ api
55 enum Theme {
56 enum Theme {
56 ChartThemeLight = 0,
57 ChartThemeLight = 0,
57 ChartThemeBlueCerulean,
58 ChartThemeBlueCerulean,
58 ChartThemeDark,
59 ChartThemeDark,
59 ChartThemeBrownSand,
60 ChartThemeBrownSand,
60 ChartThemeBlueNcs,
61 ChartThemeBlueNcs,
61 ChartThemeHighContrast,
62 ChartThemeHighContrast,
62 ChartThemeBlueIcy
63 ChartThemeBlueIcy
63 };
64 };
64
65
65 enum Animation {
66 enum Animation {
66 NoAnimation = 0x0,
67 NoAnimation = 0x0,
67 GridAxisAnimations = 0x1,
68 GridAxisAnimations = 0x1,
68 SeriesAnimations =0x2,
69 SeriesAnimations =0x2,
69 AllAnimations = 0x3
70 AllAnimations = 0x3
70 };
71 };
71
72
72 enum SeriesType {
73 enum SeriesType {
73 SeriesTypeLine,
74 SeriesTypeLine,
74 SeriesTypeArea,
75 SeriesTypeArea,
75 SeriesTypeBar,
76 SeriesTypeBar,
76 SeriesTypeStackedBar,
77 SeriesTypeStackedBar,
77 SeriesTypePercentBar,
78 SeriesTypePercentBar,
78 SeriesTypePie,
79 SeriesTypePie,
79 SeriesTypeScatter,
80 SeriesTypeScatter,
80 SeriesTypeSpline,
81 SeriesTypeSpline,
81 SeriesTypeHorizontalBar,
82 SeriesTypeHorizontalBar,
82 SeriesTypeHorizontalStackedBar,
83 SeriesTypeHorizontalStackedBar,
83 SeriesTypeHorizontalPercentBar
84 SeriesTypeHorizontalPercentBar
84 };
85 };
85
86
86 public:
87 public:
87 DeclarativeChart(QDeclarativeItem *parent = 0);
88 DeclarativeChart(QDeclarativeItem *parent = 0);
88 ~DeclarativeChart();
89 ~DeclarativeChart();
89
90
90 public: // From QDeclarativeItem/QGraphicsItem
91 public: // From QDeclarativeItem/QGraphicsItem
91 void childEvent(QChildEvent *event);
92 void childEvent(QChildEvent *event);
92 void componentComplete();
93 void componentComplete();
93 void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
94 void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
94
95
95 public:
96 public:
96 void setTheme(DeclarativeChart::Theme theme);
97 void setTheme(DeclarativeChart::Theme theme);
97 DeclarativeChart::Theme theme();
98 DeclarativeChart::Theme theme();
98 void setAnimationOptions(DeclarativeChart::Animation animations);
99 void setAnimationOptions(DeclarativeChart::Animation animations);
99 DeclarativeChart::Animation animationOptions();
100 DeclarativeChart::Animation animationOptions();
100 void setTitle(QString title);
101 void setTitle(QString title);
101 QString title();
102 QString title();
102 QLegend *legend();
103 QLegend *legend();
103 QFont titleFont() const;
104 QFont titleFont() const;
104 void setTitleFont(const QFont& font);
105 void setTitleFont(const QFont& font);
105 void setTitleColor(QColor color);
106 void setTitleColor(QColor color);
106 QColor titleColor();
107 QColor titleColor();
107 void setBackgroundColor(QColor color);
108 void setBackgroundColor(QColor color);
108 QColor backgroundColor();
109 QColor backgroundColor();
109 int count();
110 int count();
110 void setDropShadowEnabled(bool enabled);
111 void setDropShadowEnabled(bool enabled);
111 bool dropShadowEnabled();
112 bool dropShadowEnabled();
112 qreal topMargin();
113 qreal topMargin();
113 qreal bottomMargin();
114 qreal bottomMargin();
114 qreal leftMargin();
115 qreal leftMargin();
115 qreal rightMargin();
116 qreal rightMargin();
116 void createDefaultAxes(QAbstractSeries* series);
117 void createDefaultAxes(QAbstractSeries* series);
117 DeclarativeMargins *minimumMargins() { return m_minMargins; }
118 DeclarativeMargins *minimumMargins() { return m_minMargins; }
119 QRectF plotArea() { return m_chart->plotArea(); }
118
120
119 public:
121 public:
120 Q_INVOKABLE QAbstractSeries *series(int index);
122 Q_INVOKABLE QAbstractSeries *series(int index);
121 Q_INVOKABLE QAbstractSeries *series(QString seriesName);
123 Q_INVOKABLE QAbstractSeries *series(QString seriesName);
122 Q_INVOKABLE QAbstractSeries *createSeries(DeclarativeChart::SeriesType type, QString name = "");
124 Q_INVOKABLE QAbstractSeries *createSeries(DeclarativeChart::SeriesType type, QString name = "");
123 Q_INVOKABLE void setAxisX(QAbstractAxis *axis, QAbstractSeries *series = 0);
125 Q_INVOKABLE void setAxisX(QAbstractAxis *axis, QAbstractSeries *series = 0);
124 Q_INVOKABLE void setAxisY(QAbstractAxis *axis, QAbstractSeries *series = 0);
126 Q_INVOKABLE void setAxisY(QAbstractAxis *axis, QAbstractSeries *series = 0);
125 Q_INVOKABLE void createDefaultAxes();
127 Q_INVOKABLE void createDefaultAxes();
126 Q_INVOKABLE QAbstractAxis *axisX(QAbstractSeries *series = 0);
128 Q_INVOKABLE QAbstractAxis *axisX(QAbstractSeries *series = 0);
127 Q_INVOKABLE QAbstractAxis *axisY(QAbstractSeries *series = 0);
129 Q_INVOKABLE QAbstractAxis *axisY(QAbstractSeries *series = 0);
128
130
129 Q_INVOKABLE void zoom(qreal factor);
131 Q_INVOKABLE void zoom(qreal factor);
130 Q_INVOKABLE void scrollLeft(qreal pixels);
132 Q_INVOKABLE void scrollLeft(qreal pixels);
131 Q_INVOKABLE void scrollRight(qreal pixels);
133 Q_INVOKABLE void scrollRight(qreal pixels);
132 Q_INVOKABLE void scrollUp(qreal pixels);
134 Q_INVOKABLE void scrollUp(qreal pixels);
133 Q_INVOKABLE void scrollDown(qreal pixels);
135 Q_INVOKABLE void scrollDown(qreal pixels);
134
136
135 Q_SIGNALS:
137 Q_SIGNALS:
136 void axisLabelsChanged();
138 void axisLabelsChanged();
137 void titleColorChanged(QColor color);
139 void titleColorChanged(QColor color);
138 void backgroundColorChanged();
140 void backgroundColorChanged();
139 void dropShadowEnabledChanged(bool enabled);
141 void dropShadowEnabledChanged(bool enabled);
140 void topMarginChanged(qreal margin);
142 void topMarginChanged(qreal margin);
141 void bottomMarginChanged(qreal margin);
143 void bottomMarginChanged(qreal margin);
142 void leftMarginChanged(qreal margin);
144 void leftMarginChanged(qreal margin);
143 void rightMarginChanged(qreal margin);
145 void rightMarginChanged(qreal margin);
146 void plotAreaChanged(QRectF plotArea);
144
147
145 public Q_SLOTS:
148 public Q_SLOTS:
146 // void handleMarginsChanged(QRectF newMargins);
149 // void handleMarginsChanged(QRectF newMargins);
147 void changeMinimumMargins(int top, int bottom, int left, int right);
150 void changeMinimumMargins(int top, int bottom, int left, int right);
148 void handleAxisXSet(QAbstractAxis *axis);
151 void handleAxisXSet(QAbstractAxis *axis);
149 void handleAxisYSet(QAbstractAxis *axis);
152 void handleAxisYSet(QAbstractAxis *axis);
150
153
151 private:
154 private:
152 // Extending QChart with DeclarativeChart is not possible because QObject does not support
155 // Extending QChart with DeclarativeChart is not possible because QObject does not support
153 // multi inheritance, so we now have a QChart as a member instead
156 // multi inheritance, so we now have a QChart as a member instead
154 QChart *m_chart;
157 QChart *m_chart;
155 //QMargins m_chartMargins;
158 //QMargins m_chartMargins;
156 DeclarativeMargins *m_minMargins;
159 DeclarativeMargins *m_minMargins;
157 };
160 };
158
161
159 QTCOMMERCIALCHART_END_NAMESPACE
162 QTCOMMERCIALCHART_END_NAMESPACE
160
163
161 #endif // DECLARATIVECHART_H
164 #endif // DECLARATIVECHART_H
@@ -1,113 +1,114
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 QtCommercial.Chart 1.1
22 import QtCommercial.Chart 1.1
23
23
24 ChartView {
24 ChartView {
25 id: chartView
25 id: chartView
26 title: "Chart Title"
26 title: "Chart Title"
27 anchors.fill: parent
27 anchors.fill: parent
28 property variant series: chartView
28 property variant series: chartView
29
29
30 LineSeries {
30 LineSeries {
31 name: "line"
31 name: "line"
32 XYPoint { x: 0; y: 0 }
32 XYPoint { x: 0; y: 0 }
33 XYPoint { x: 1.1; y: 2.1 }
33 XYPoint { x: 1.1; y: 2.1 }
34 XYPoint { x: 1.9; y: 3.3 }
34 XYPoint { x: 1.9; y: 3.3 }
35 XYPoint { x: 2.1; y: 2.1 }
35 XYPoint { x: 2.1; y: 2.1 }
36 XYPoint { x: 2.9; y: 4.9 }
36 XYPoint { x: 2.9; y: 4.9 }
37 XYPoint { x: 3.4; y: 3.0 }
37 XYPoint { x: 3.4; y: 3.0 }
38 XYPoint { x: 4.1; y: 3.3 }
38 XYPoint { x: 4.1; y: 3.3 }
39 }
39 }
40
40
41 onVisibleChanged: console.log("chart.onVisibleChanged: " + visible);
41 onVisibleChanged: console.log("chart.onVisibleChanged: " + visible);
42 onTitleColorChanged: console.log("chart.onTitleColorChanged: " + color);
42 onTitleColorChanged: console.log("chart.onTitleColorChanged: " + color);
43 onBackgroundColorChanged: console.log("chart.onBackgroundColorChanged: " + series.backgroundColor);
43 onBackgroundColorChanged: console.log("chart.onBackgroundColorChanged: " + series.backgroundColor);
44 onDropShadowEnabledChanged: console.log("chart.onDropShadowEnabledChanged: " + enabled);
44 onDropShadowEnabledChanged: console.log("chart.onDropShadowEnabledChanged: " + enabled);
45 onTopMarginChanged: {
45 onTopMarginChanged: {
46 console.log("chart.onTopMarginChanged: " + margin);
46 console.log("chart.onTopMarginChanged: " + margin);
47 marginVisualizer.opacity = 1.0;
47 marginVisualizer.opacity = 1.0;
48 }
48 }
49 onBottomMarginChanged: {
49 onBottomMarginChanged: {
50 console.log("chart.onBottomMarginChanged: " + margin);
50 console.log("chart.onBottomMarginChanged: " + margin);
51 marginVisualizer.opacity = 1.0;
51 marginVisualizer.opacity = 1.0;
52 }
52 }
53 onLeftMarginChanged: {
53 onLeftMarginChanged: {
54 console.log("chart.onLeftMarginChanged: " + margin);
54 console.log("chart.onLeftMarginChanged: " + margin);
55 marginVisualizer.opacity = 1.0;
55 marginVisualizer.opacity = 1.0;
56 }
56 }
57 onRightMarginChanged: {
57 onRightMarginChanged: {
58 console.log("chart.onRightMarginChanged: " + margin);
58 console.log("chart.onRightMarginChanged: " + margin);
59 marginVisualizer.opacity = 1.0;
59 marginVisualizer.opacity = 1.0;
60 }
60 }
61
61
62 legend.onVisibleChanged: console.log("legend.onVisibleChanged: " + series.legend.visible);
62 legend.onVisibleChanged: console.log("legend.onVisibleChanged: " + series.legend.visible);
63 legend.onBackgroundVisibleChanged: console.log("legend.onBackgroundVisibleChanged: " + visible);
63 legend.onBackgroundVisibleChanged: console.log("legend.onBackgroundVisibleChanged: " + visible);
64 legend.onColorChanged: console.log("legend.onColorChanged: " + color);
64 legend.onColorChanged: console.log("legend.onColorChanged: " + color);
65 legend.onBorderColorChanged: console.log("legend.onBorderColorChanged: " + color);
65 legend.onBorderColorChanged: console.log("legend.onBorderColorChanged: " + color);
66 legend.onLabelColorChanged: console.log("legend.onLabelColorChanged: " + color);
66 legend.onLabelColorChanged: console.log("legend.onLabelColorChanged: " + color);
67 minimumMargins.onTopChanged: console.log("chart.minimumMargins.onTopChanged: " + top);
67 minimumMargins.onTopChanged: console.log("chart.minimumMargins.onTopChanged: " + top );
68 minimumMargins.onBottomChanged: console.log("chart.minimumMargins.onBottomChanged: " + bottom);
68 minimumMargins.onBottomChanged: console.log("chart.minimumMargins.onBottomChanged: " + bottom + " " + chartView.plotArea.height);
69 minimumMargins.onLeftChanged: console.log("chart.minimumMargins.onLeftChanged: " + left);
69 minimumMargins.onLeftChanged: console.log("chart.minimumMargins.onLeftChanged: " + left + " " + chartView.plotArea.left);
70 minimumMargins.onRightChanged: console.log("chart.minimumMargins.onRightChanged: " + right);
70 minimumMargins.onRightChanged: console.log("chart.minimumMargins.onRightChanged: " + right + " " + chartView.plotArea.right);
71 onPlotAreaChanged: console.log("chart.onPlotAreaChanged, width:" + chartView.plotArea.width + " height: " + chartView.plotArea.height + " y: " + chartView.plotArea.y + " x: " + chartView.plotArea.x);
71
72
72 ValueAxis{
73 ValueAxis{
73 onColorChanged: console.log("axisX.onColorChanged: " + color);
74 onColorChanged: console.log("axisX.onColorChanged: " + color);
74 onLabelsVisibleChanged: console.log("axisX.onLabelsVisibleChanged: " + visible);
75 onLabelsVisibleChanged: console.log("axisX.onLabelsVisibleChanged: " + visible);
75 onLabelsColorChanged: console.log("axisX.onLabelsColorChanged: " + color);
76 onLabelsColorChanged: console.log("axisX.onLabelsColorChanged: " + color);
76 onVisibleChanged: console.log("axisX.onVisibleChanged: " + visible);
77 onVisibleChanged: console.log("axisX.onVisibleChanged: " + visible);
77 onGridVisibleChanged: console.log("axisX.onGridVisibleChanged: " + visible);
78 onGridVisibleChanged: console.log("axisX.onGridVisibleChanged: " + visible);
78 onShadesVisibleChanged: console.log("axisX.onShadesVisibleChanged: " + visible);
79 onShadesVisibleChanged: console.log("axisX.onShadesVisibleChanged: " + visible);
79 onShadesColorChanged: console.log("axisX.onShadesColorChanged: " + color);
80 onShadesColorChanged: console.log("axisX.onShadesColorChanged: " + color);
80 onShadesBorderColorChanged: console.log("axisX.onShadesBorderColorChanged: " + color);
81 onShadesBorderColorChanged: console.log("axisX.onShadesBorderColorChanged: " + color);
81 onMinChanged: console.log("axisX.onMinChanged: " + min);
82 onMinChanged: console.log("axisX.onMinChanged: " + min);
82 onMaxChanged: console.log("axisX.onMaxChanged: " + max);
83 onMaxChanged: console.log("axisX.onMaxChanged: " + max);
83 }
84 }
84
85
85 ValueAxis{
86 ValueAxis{
86 onColorChanged: console.log("axisY.onColorChanged: " + color);
87 onColorChanged: console.log("axisY.onColorChanged: " + color);
87 onLabelsVisibleChanged: console.log("axisY.onLabelsVisibleChanged: " + visible);
88 onLabelsVisibleChanged: console.log("axisY.onLabelsVisibleChanged: " + visible);
88 onLabelsColorChanged: console.log("axisY.onLabelsColorChanged: " + color);
89 onLabelsColorChanged: console.log("axisY.onLabelsColorChanged: " + color);
89 onVisibleChanged: console.log("axisY.onVisibleChanged: " + visible);
90 onVisibleChanged: console.log("axisY.onVisibleChanged: " + visible);
90 onGridVisibleChanged: console.log("axisY.onGridVisibleChanged: " + visible);
91 onGridVisibleChanged: console.log("axisY.onGridVisibleChanged: " + visible);
91 onShadesVisibleChanged: console.log("axisY.onShadesVisibleChanged: " + visible);
92 onShadesVisibleChanged: console.log("axisY.onShadesVisibleChanged: " + visible);
92 onShadesColorChanged: console.log("axisY.onShadesColorChanged: " + color);
93 onShadesColorChanged: console.log("axisY.onShadesColorChanged: " + color);
93 onShadesBorderColorChanged: console.log("axisY.onShadesBorderColorChanged: " + color);
94 onShadesBorderColorChanged: console.log("axisY.onShadesBorderColorChanged: " + color);
94 onMinChanged: console.log("axisY.onMinChanged: " + min);
95 onMinChanged: console.log("axisY.onMinChanged: " + min);
95 onMaxChanged: console.log("axisY.onMaxChanged: " + max);
96 onMaxChanged: console.log("axisY.onMaxChanged: " + max);
96 }
97 }
97
98
98 Rectangle {
99 Rectangle {
99 id: marginVisualizer
100 id: marginVisualizer
100 color: "transparent"
101 color: "transparent"
101 border.color: "red"
102 border.color: "red"
102 anchors.fill: parent
103 anchors.fill: parent
103 anchors.topMargin: parent.topMargin
104 anchors.topMargin: parent.topMargin
104 anchors.bottomMargin: parent.bottomMargin
105 anchors.bottomMargin: parent.bottomMargin
105 anchors.leftMargin: parent.leftMargin
106 anchors.leftMargin: parent.leftMargin
106 anchors.rightMargin: parent.rightMargin
107 anchors.rightMargin: parent.rightMargin
107 opacity: 0.0
108 opacity: 0.0
108 onOpacityChanged: if (opacity > 0.9) opacity = 0.0;
109 onOpacityChanged: if (opacity > 0.9) opacity = 0.0;
109 Behavior on opacity {
110 Behavior on opacity {
110 NumberAnimation { duration: 800 }
111 NumberAnimation { duration: 800 }
111 }
112 }
112 }
113 }
113 }
114 }
General Comments 0
You need to be logged in to leave comments. Login now