##// END OF EJS Templates
QML: Added possibility to define axes when creating series
Tero Ahola -
r1960:bd364d589414
parent child
Show More
@@ -1,103 +1,116
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 //![1]
24 //![1]
25 ChartView {
25 ChartView {
26 id: chartView
26 id: chartView
27 animationOptions: ChartView.NoAnimation
27 animationOptions: ChartView.NoAnimation
28 theme: ChartView.ChartThemeDark
28
29
29 ValueAxis {
30 ValueAxis {
30 id: axisY1
31 id: axisY1
31 min: -1
32 min: -1
32 max: 4
33 max: 4
33 }
34 }
34
35
35 ValueAxis {
36 ValueAxis {
36 id: axisY2
37 id: axisY2
37 min: -10
38 min: -10
38 max: 5
39 max: 5
39 }
40 }
40
41
41 ValueAxis {
42 ValueAxis {
42 id: axisX
43 id: axisX
43 min: 0
44 min: 0
44 max: 1000
45 max: 1000
45 }
46 }
46
47
47 LineSeries {
48 LineSeries {
48 id: lineSeries1
49 id: lineSeries1
49 name: "signal 1"
50 name: "signal 1"
50 axisX: axisX
51 axisX: axisX
51 axisY: axisY1
52 axisY: axisY1
52 }
53 }
53 LineSeries {
54 LineSeries {
54 id: lineSeries2
55 id: lineSeries2
55 name: "signal 2"
56 name: "signal 2"
56 axisX: axisX
57 axisX: axisX
57 axisY: axisY2
58 axisY: axisY2
58 }
59 }
59 // ...
60 // ...
60 //![1]
61 //![1]
61
62
62 //![2]
63 //![2]
63 Timer {
64 Timer {
64 id: refreshTimer
65 id: refreshTimer
65 interval: 1 / 60 * 1000 // 60 Hz
66 interval: 1 / 60 * 1000 // 60 Hz
66 running: true
67 running: true
67 repeat: true
68 repeat: true
68 onTriggered: {
69 onTriggered: {
69 dataSource.update(chartView.series(0));
70 dataSource.update(chartView.series(0));
70 dataSource.update(chartView.series(1));
71 dataSource.update(chartView.series(1));
71 }
72 }
72 }
73 }
73 //![2]
74 //![2]
74
75
76 //![3]
75 function changeSeriesType(type) {
77 function changeSeriesType(type) {
76 chartView.series(1).destroy();
78 chartView.removeAllSeries();
77 chartView.series(0).destroy();
79
78 var seriesCount = 2;
80 // Create two new series of the correct type. Axis x is the same for both of the series,
79 for (var i = 0; i < seriesCount; i++) {
81 // but the series have their own y-axes to make it possible to control the y-offset
80 var series;
82 // of the "signal sources".
81 if (type == "line") {
83 if (type == "line") {
82 series = scopeView.createSeries(ChartView.SeriesTypeLine, "signal " + (i + 1));
84 scopeView.createSeries(ChartView.SeriesTypeLine, "signal 1", createAxis(0, 1000), createAxis(-1, 4));
83 } else if (type == "spline") {
85 scopeView.createSeries(ChartView.SeriesTypeLine, "signal 2", chartView.axisX(), createAxis(-10, 5));
84 series = chartView.createSeries(ChartView.SeriesTypeSpline, "signal " + (i + 1));
86 } else if (type == "spline") {
85 } else {
87 scopeView.createSeries(ChartView.SeriesTypeSpline, "signal 1", createAxis(0, 1000), createAxis(-1, 4));
86 series = chartView.createSeries(ChartView.SeriesTypeScatter, "signal " + (i + 1));
88 scopeView.createSeries(ChartView.SeriesTypeSpline, "signal 2", chartView.axisX(), createAxis(-10, 5));
87 series.markerSize = 3;
89 } else {
88 series.borderColor = "transparent";
90 var series1 = scopeView.createSeries(ChartView.SeriesTypeScatter, "signal 1", createAxis(0, 1000), createAxis(-1, 4));
89 }
91 series1.markerSize = 3;
92 series1.borderColor = "transparent";
93 var series2 = scopeView.createSeries(ChartView.SeriesTypeScatter, "signal 2", chartView.axisX(), createAxis(-10, 5));
94 series2.markerSize = 3;
95 series2.borderColor = "transparent";
90 }
96 }
91 }
97 }
92
98
99 function createAxis(min, max) {
100 // The following creates a ValueAxis object that can be then set as a x or y axis for a series
101 return Qt.createQmlObject("import QtQuick 1.1; import QtCommercial.Chart 1.1; ValueAxis { min: "
102 + min + "; max: " + max + " }", chartView);
103 }
104 //![3]
105
93 function setAnimations(enabled) {
106 function setAnimations(enabled) {
94 if (enabled)
107 if (enabled)
95 scopeView.animationOptions = ChartView.SeriesAnimations;
108 scopeView.animationOptions = ChartView.SeriesAnimations;
96 else
109 else
97 scopeView.animationOptions = ChartView.NoAnimation;
110 scopeView.animationOptions = ChartView.NoAnimation;
98 }
111 }
99
112
100 function changeRefreshRate(rate) {
113 function changeRefreshRate(rate) {
101 refreshTimer.interval = 1 / Number(rate) * 1000;
114 refreshTimer.interval = 1 / Number(rate) * 1000;
102 }
115 }
103 }
116 }
1 NO CONTENT: modified file, binary diff hidden
NO CONTENT: modified file, binary diff hidden
@@ -1,27 +1,31
1 /*!
1 /*!
2 \example demos/qmloscilloscope
2 \example demos/qmloscilloscope
3 \title Oscilloscope
3 \title Oscilloscope
4
4
5 \image demos_qmloscilloscope.png
5 \image demos_qmloscilloscope.png
6
6
7 Oscilloscope application demonstrates how to use QtCommercial Charts QML api to implement an
7 Oscilloscope application demonstrates how to use QtCommercial Charts QML api to implement an
8 application with strict performance requirements. The application uses generated data with
8 application with strict performance requirements. The application uses generated data with
9 configurable characteristics to mimic a simple oscilloscope user interface. To find out the
9 configurable characteristics to mimic a simple oscilloscope user interface. To find out the
10 actual screen refresh performance of the application, you can set QML_SHOW_FRAMERATE = 1 to
10 actual screen refresh performance of the application, you can set QML_SHOW_FRAMERATE = 1 to
11 your run environment settings to get the framerate shown in the application output console.
11 your run environment settings to get the framerate shown in the application output console.
12 I.e. go to Projects - Run - Run environment in Qt Creator and select Add. Then you can
12 I.e. go to Projects - Run - Run environment in Qt Creator and select Add. Then you can
13 experiment with the different configurable options of the demo application to find the
13 experiment with the different configurable options of the demo application to find the
14 configuration that gives you the best performance in your environment.
14 configuration that gives you the best performance in your environment.
15
15
16 The application window is shared by control and scope views:
16 The application window is shared by control and scope views:
17 \snippet ../demos/qmloscilloscope/qml/qmloscilloscope/main.qml 1
17 \snippet ../demos/qmloscilloscope/qml/qmloscilloscope/main.qml 1
18 \snippet ../demos/qmloscilloscope/qml/qmloscilloscope/main.qml 2
18 \snippet ../demos/qmloscilloscope/qml/qmloscilloscope/main.qml 2
19
19
20 ControlView implements the buttons used for configuring. ScopeView uses a ChartView to show
20 ControlView implements the buttons used for configuring. ScopeView uses a ChartView to show
21 a chart with two line series:
21 a chart with two line series:
22 \snippet ../demos/qmloscilloscope/qml/qmloscilloscope/ScopeView.qml 1
22 \snippet ../demos/qmloscilloscope/qml/qmloscilloscope/ScopeView.qml 1
23
23
24 The data of the line series is updated with a QML timer. In a real life application the
24 The data of the line series is updated with a QML timer. In a real life application the
25 updating could triggered with a signal from Qt C++ code.
25 updating could triggered with a signal from Qt C++ code.
26 \snippet ../demos/qmloscilloscope/qml/qmloscilloscope/ScopeView.qml 2
26 \snippet ../demos/qmloscilloscope/qml/qmloscilloscope/ScopeView.qml 2
27
28 The oscilloscope also allows you to switch the type of the series used for visualizing the
29 signal sources. This is implemented by dynamically destroying and creating series:
30 \snippet ../demos/qmloscilloscope/qml/qmloscilloscope/ScopeView.qml 3
27 */
31 */
@@ -1,688 +1,704
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. Margins
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
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
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
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.
145 given time, you can check ChartView::plotArea instead.
146 */
146 */
147
147
148 /*!
148 /*!
149 \qmlproperty rect ChartView::plotArea
149 \qmlproperty rect ChartView::plotArea
150 The area on the ChartView that is used for drawing series. This is the ChartView rect without the
150 The area on the ChartView that is used for drawing series. This is the ChartView rect without the
151 margins.
151 margins.
152 \sa ChartView::minimumMargins
152 \sa ChartView::minimumMargins
153 */
153 */
154
154
155 /*!
155 /*!
156 \qmlmethod AbstractSeries ChartView::series(int index)
156 \qmlmethod AbstractSeries ChartView::series(int index)
157 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
158 the count property of the chart.
158 the count property of the chart.
159 */
159 */
160
160
161 /*!
161 /*!
162 \qmlmethod AbstractSeries ChartView::series(string name)
162 \qmlmethod AbstractSeries ChartView::series(string name)
163 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.
164 */
164 */
165
165
166 /*!
166 /*!
167 \qmlmethod AbstractSeries ChartView::createSeries(SeriesType type, string name)
167 \qmlmethod AbstractSeries ChartView::createSeries(SeriesType type, string name, AbstractAxis axisX, AbstractAxis axisY)
168 Creates a series object of \a type to the chart. For example:
168 Creates a series object of \a type to the chart with name \a name, optional axis \a axisX and
169 optional axis \a axisY. For example:
169 \code
170 \code
170 var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter series");
171 // lineSeries is a LineSeries object that has already been added to the ChartView; re-use it's axes
171 scatter.markerSize = 22;
172 var myAxisX = chartView.axisX(lineSeries);
172 scatter.append(1.1, 2.0);
173 var myAxisY = chartView.axisY(lineSeries);
174 var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter series", myAxisX, myAxisY);
173 \endcode
175 \endcode
174 */
176 */
175
177
176 /*!
178 /*!
177 \qmlmethod ChartView::removeSeries(AbstractSeries series)
179 \qmlmethod ChartView::removeSeries(AbstractSeries series)
178 Removes the \a series from the chart. The series object is also destroyed.
180 Removes the \a series from the chart. The series object is also destroyed.
179 */
181 */
180
182
181 /*!
183 /*!
182 \qmlmethod ChartView::removeAllSeries()
184 \qmlmethod ChartView::removeAllSeries()
183 Removes all series from the chart. All the series objects are also destroyed.
185 Removes all series from the chart. All the series objects are also destroyed.
184 */
186 */
185
187
186 /*!
188 /*!
189 \qmlmethod Axis ChartView::axisX(QAbstractSeries *series)
190 The x-axis of the series.
191 */
192
193 /*!
187 \qmlmethod Axis ChartView::axisY(QAbstractSeries *series)
194 \qmlmethod Axis ChartView::axisY(QAbstractSeries *series)
188 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.
195 The y-axis of the series.
189 */
196 */
190
197
191 /*!
198 /*!
192 \qmlmethod ChartView::zoomY(real factor)
199 \qmlmethod ChartView::zoomY(real factor)
193 Zooms in by \a factor on the center of the chart.
200 Zooms in by \a factor on the center of the chart.
194 */
201 */
195
202
196 /*!
203 /*!
197 \qmlmethod ChartView::scrollLeft(real pixels)
204 \qmlmethod ChartView::scrollLeft(real pixels)
198 Scrolls to left by \a pixels. This is a convenience function that suits for example for key navigation.
205 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
206 \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max
200 */
207 */
201
208
202 /*!
209 /*!
203 \qmlmethod ChartView::scrollRight(real pixels)
210 \qmlmethod ChartView::scrollRight(real pixels)
204 Scrolls to right by \a pixels. This is a convenience function that suits for example for key navigation.
211 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
212 \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max
206 */
213 */
207
214
208 /*!
215 /*!
209 \qmlmethod ChartView::scrollUp(real pixels)
216 \qmlmethod ChartView::scrollUp(real pixels)
210 Scrolls up by \a pixels. This is a convenience function that suits for example for key navigation.
217 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
218 \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max
212 */
219 */
213
220
214 /*!
221 /*!
215 \qmlmethod ChartView::scrollDown(real pixels)
222 \qmlmethod ChartView::scrollDown(real pixels)
216 Scrolls down by \a pixels. This is a convenience function that suits for example for key navigation.
223 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
224 \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max
218 */
225 */
219
226
220 /*!
227 /*!
221 \qmlsignal ChartView::onPlotAreaChanged(rect plotArea)
228 \qmlsignal ChartView::onPlotAreaChanged(rect plotArea)
222 The plot area of the chart has changed. This may happen for example, if you modify minimumMargins
229 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
230 or if you resize the chart, or if you modify font size related properties of the legend or chart
224 title.
231 title.
225 */
232 */
226
233
227 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent)
234 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent)
228 : QDeclarativeItem(parent),
235 : QDeclarativeItem(parent),
229 m_chart(new QChart(this))
236 m_chart(new QChart(this))
230 {
237 {
231 setFlag(QGraphicsItem::ItemHasNoContents, false);
238 setFlag(QGraphicsItem::ItemHasNoContents, false);
232 m_minMargins = new DeclarativeMargins(this);
239 m_minMargins = new DeclarativeMargins(this);
233 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)));
234 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)));
235 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)));
236 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)));
237 }
244 }
238
245
239 void DeclarativeChart::changeMinimumMargins(int top, int bottom, int left, int right)
246 void DeclarativeChart::changeMinimumMargins(int top, int bottom, int left, int right)
240 {
247 {
241 m_chart->setMinimumMargins(QMargins(left, top, right, bottom));
248 m_chart->setMinimumMargins(QMargins(left, top, right, bottom));
242 emit minimumMarginsChanged();
249 emit minimumMarginsChanged();
243 emit plotAreaChanged(m_chart->plotArea());
250 emit plotAreaChanged(m_chart->plotArea());
244 }
251 }
245
252
246 DeclarativeChart::~DeclarativeChart()
253 DeclarativeChart::~DeclarativeChart()
247 {
254 {
248 delete m_chart;
255 delete m_chart;
249 }
256 }
250
257
251 void DeclarativeChart::childEvent(QChildEvent *event)
258 void DeclarativeChart::childEvent(QChildEvent *event)
252 {
259 {
253 if (event->type() == QEvent::ChildAdded) {
260 if (event->type() == QEvent::ChildAdded) {
254 if (qobject_cast<QAbstractSeries *>(event->child())) {
261 if (qobject_cast<QAbstractSeries *>(event->child())) {
255 m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child()));
262 m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child()));
256 }
263 }
257 }
264 }
258 }
265 }
259
266
260 void DeclarativeChart::componentComplete()
267 void DeclarativeChart::componentComplete()
261 {
268 {
262 foreach(QObject *child, children()) {
269 foreach(QObject *child, children()) {
263 if (qobject_cast<QAbstractSeries *>(child)) {
270 if (qobject_cast<QAbstractSeries *>(child)) {
264 // Add series to the chart
271 // Add series to the chart
265 QAbstractSeries *series = qobject_cast<QAbstractSeries *>(child);
272 QAbstractSeries *series = qobject_cast<QAbstractSeries *>(child);
266 m_chart->addSeries(series);
273 m_chart->addSeries(series);
267
274
268 // Set optional user defined axes for the series and connect axis related signals
275 // Set optional user defined axes for the series and connect axis related signals
269 if (qobject_cast<DeclarativeLineSeries *>(child)) {
276 if (qobject_cast<DeclarativeLineSeries *>(child)) {
270 DeclarativeLineSeries *s = qobject_cast<DeclarativeLineSeries *>(child);
277 DeclarativeLineSeries *s = qobject_cast<DeclarativeLineSeries *>(child);
271 connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
278 connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
272 connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*)));
279 connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*)));
273 setAxisX(s->axisX(), s);
280 setAxisX(s->axisX(), s);
274 setAxisY(s->axisY(), s);
281 setAxisY(s->axisY(), s);
275 } else if (qobject_cast<DeclarativeSplineSeries *>(child)) {
282 } else if (qobject_cast<DeclarativeSplineSeries *>(child)) {
276 DeclarativeSplineSeries *s = qobject_cast<DeclarativeSplineSeries *>(child);
283 DeclarativeSplineSeries *s = qobject_cast<DeclarativeSplineSeries *>(child);
277 connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
284 connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
278 connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*)));
285 connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*)));
279 setAxisX(s->axisX(), s);
286 setAxisX(s->axisX(), s);
280 setAxisY(s->axisY(), s);
287 setAxisY(s->axisY(), s);
281 } else if (qobject_cast<DeclarativeScatterSeries *>(child)) {
288 } else if (qobject_cast<DeclarativeScatterSeries *>(child)) {
282 DeclarativeScatterSeries *s = qobject_cast<DeclarativeScatterSeries *>(child);
289 DeclarativeScatterSeries *s = qobject_cast<DeclarativeScatterSeries *>(child);
283 connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
290 connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
284 connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*)));
291 connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*)));
285 setAxisX(s->axisX(), s);
292 setAxisX(s->axisX(), s);
286 setAxisY(s->axisY(), s);
293 setAxisY(s->axisY(), s);
287 } else if (qobject_cast<DeclarativeAreaSeries *>(child)) {
294 } else if (qobject_cast<DeclarativeAreaSeries *>(child)) {
288 DeclarativeAreaSeries *s = qobject_cast<DeclarativeAreaSeries *>(child);
295 DeclarativeAreaSeries *s = qobject_cast<DeclarativeAreaSeries *>(child);
289 connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
296 connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
290 connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*)));
297 connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*)));
291 setAxisX(s->axisX(), s);
298 setAxisX(s->axisX(), s);
292 setAxisY(s->axisY(), s);
299 setAxisY(s->axisY(), s);
293 } else if (qobject_cast<DeclarativeBarSeries *>(child)) {
300 } else if (qobject_cast<DeclarativeBarSeries *>(child)) {
294 DeclarativeBarSeries *s = qobject_cast<DeclarativeBarSeries *>(child);
301 DeclarativeBarSeries *s = qobject_cast<DeclarativeBarSeries *>(child);
295 connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
302 connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
296 connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*)));
303 connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*)));
297 setAxisX(s->axisX(), s);
304 setAxisX(s->axisX(), s);
298 setAxisY(s->axisY(), s);
305 setAxisY(s->axisY(), s);
299 } else if (qobject_cast<DeclarativeStackedBarSeries *>(child)) {
306 } else if (qobject_cast<DeclarativeStackedBarSeries *>(child)) {
300 DeclarativeStackedBarSeries *s = qobject_cast<DeclarativeStackedBarSeries *>(child);
307 DeclarativeStackedBarSeries *s = qobject_cast<DeclarativeStackedBarSeries *>(child);
301 connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
308 connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
302 connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*)));
309 connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*)));
303 setAxisX(s->axisX(), s);
310 setAxisX(s->axisX(), s);
304 setAxisY(s->axisY(), s);
311 setAxisY(s->axisY(), s);
305 } else if (qobject_cast<DeclarativePercentBarSeries *>(child)) {
312 } else if (qobject_cast<DeclarativePercentBarSeries *>(child)) {
306 DeclarativePercentBarSeries *s = qobject_cast<DeclarativePercentBarSeries *>(child);
313 DeclarativePercentBarSeries *s = qobject_cast<DeclarativePercentBarSeries *>(child);
307 connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
314 connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
308 connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*)));
315 connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*)));
309 setAxisX(s->axisX(), s);
316 setAxisX(s->axisX(), s);
310 setAxisY(s->axisY(), s);
317 setAxisY(s->axisY(), s);
311 } else if (qobject_cast<DeclarativeHorizontalBarSeries *>(child)) {
318 } else if (qobject_cast<DeclarativeHorizontalBarSeries *>(child)) {
312 DeclarativeHorizontalBarSeries *s = qobject_cast<DeclarativeHorizontalBarSeries *>(child);
319 DeclarativeHorizontalBarSeries *s = qobject_cast<DeclarativeHorizontalBarSeries *>(child);
313 connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
320 connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
314 connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*)));
321 connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*)));
315 setAxisX(s->axisX(), s);
322 setAxisX(s->axisX(), s);
316 setAxisY(s->axisY(), s);
323 setAxisY(s->axisY(), s);
317 } else if (qobject_cast<DeclarativeHorizontalStackedBarSeries *>(child)) {
324 } else if (qobject_cast<DeclarativeHorizontalStackedBarSeries *>(child)) {
318 DeclarativeHorizontalStackedBarSeries *s = qobject_cast<DeclarativeHorizontalStackedBarSeries *>(child);
325 DeclarativeHorizontalStackedBarSeries *s = qobject_cast<DeclarativeHorizontalStackedBarSeries *>(child);
319 connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
326 connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
320 connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*)));
327 connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*)));
321 setAxisX(s->axisX(), s);
328 setAxisX(s->axisX(), s);
322 setAxisY(s->axisY(), s);
329 setAxisY(s->axisY(), s);
323 } else if (qobject_cast<DeclarativeHorizontalPercentBarSeries *>(child)) {
330 } else if (qobject_cast<DeclarativeHorizontalPercentBarSeries *>(child)) {
324 DeclarativeHorizontalPercentBarSeries *s = qobject_cast<DeclarativeHorizontalPercentBarSeries *>(child);
331 DeclarativeHorizontalPercentBarSeries *s = qobject_cast<DeclarativeHorizontalPercentBarSeries *>(child);
325 connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
332 connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*)));
326 connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*)));
333 connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*)));
327 setAxisX(s->axisX(), s);
334 setAxisX(s->axisX(), s);
328 setAxisY(s->axisY(), s);
335 setAxisY(s->axisY(), s);
329 }
336 }
330 }
337 }
331 }
338 }
332
339
333 // Create the missing axes for the series that cannot be painted without axes
340 // Create the missing axes for the series that cannot be painted without axes
334 foreach (QAbstractSeries *chartSeries, m_chart->series())
341 foreach (QAbstractSeries *chartSeries, m_chart->series())
335 createDefaultAxes(chartSeries);
342 createDefaultAxes(chartSeries);
336
343
337 QDeclarativeItem::componentComplete();
344 QDeclarativeItem::componentComplete();
338 }
345 }
339
346
340 void DeclarativeChart::handleAxisXSet(QAbstractAxis* axis)
347 void DeclarativeChart::handleAxisXSet(QAbstractAxis* axis)
341 {
348 {
342 // qDebug() << "DeclarativeChart::handleAxisXSet" << sender() << axis;
349 // qDebug() << "DeclarativeChart::handleAxisXSet" << sender() << axis;
343 if (axis && qobject_cast<QAbstractSeries *>(sender()))
350 if (axis && qobject_cast<QAbstractSeries *>(sender()))
344 m_chart->setAxisX(axis, qobject_cast<QAbstractSeries *>(sender()));
351 m_chart->setAxisX(axis, qobject_cast<QAbstractSeries *>(sender()));
345 else
352 else
346 qWarning() << "Trying to set axisX to null.";
353 qWarning() << "Trying to set axisX to null.";
347 }
354 }
348
355
349 void DeclarativeChart::handleAxisYSet(QAbstractAxis* axis)
356 void DeclarativeChart::handleAxisYSet(QAbstractAxis* axis)
350 {
357 {
351 // qDebug() << "DeclarativeChart::handleAxisYSet" << sender() << axis;
358 // qDebug() << "DeclarativeChart::handleAxisYSet" << sender() << axis;
352 if (axis && qobject_cast<QAbstractSeries *>(sender()))
359 if (axis && qobject_cast<QAbstractSeries *>(sender()))
353 m_chart->setAxisY(axis, qobject_cast<QAbstractSeries *>(sender()));
360 m_chart->setAxisY(axis, qobject_cast<QAbstractSeries *>(sender()));
354 else
361 else
355 qWarning() << "Trying to set axisY to null.";
362 qWarning() << "Trying to set axisY to null.";
356 }
363 }
357
364
358 void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
365 void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
359 {
366 {
360 // qDebug() << "DeclarativeChart::geometryChanged" << newGeometry.width() << newGeometry.height();
367 // qDebug() << "DeclarativeChart::geometryChanged" << newGeometry.width() << newGeometry.height();
361 if (newGeometry.isValid()) {
368 if (newGeometry.isValid()) {
362 if (newGeometry.width() > 0 && newGeometry.height() > 0) {
369 if (newGeometry.width() > 0 && newGeometry.height() > 0) {
363 m_chart->resize(newGeometry.width(), newGeometry.height());
370 m_chart->resize(newGeometry.width(), newGeometry.height());
364 }
371 }
365 }
372 }
366 QDeclarativeItem::geometryChanged(newGeometry, oldGeometry);
373 QDeclarativeItem::geometryChanged(newGeometry, oldGeometry);
367
374
368 // It would be better to trigger the plotAreaChanged signal from QChart::plotAreaChanged or
375 // It would be better to trigger the plotAreaChanged signal from QChart::plotAreaChanged or
369 // similar. Since that kind of a signal is not clearly needed in the C++ API the work-around is
376 // similar. Since that kind of a signal is not clearly needed in the C++ API the work-around is
370 // to implement it here for the QML API purposes.
377 // to implement it here for the QML API purposes.
371 emit plotAreaChanged(m_chart->plotArea());
378 emit plotAreaChanged(m_chart->plotArea());
372 }
379 }
373
380
374 void DeclarativeChart::setTheme(DeclarativeChart::Theme theme)
381 void DeclarativeChart::setTheme(DeclarativeChart::Theme theme)
375 {
382 {
376 QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme;
383 QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme;
377 if (chartTheme != m_chart->theme())
384 if (chartTheme != m_chart->theme())
378 m_chart->setTheme(chartTheme);
385 m_chart->setTheme(chartTheme);
379 }
386 }
380
387
381 DeclarativeChart::Theme DeclarativeChart::theme()
388 DeclarativeChart::Theme DeclarativeChart::theme()
382 {
389 {
383 return (DeclarativeChart::Theme) m_chart->theme();
390 return (DeclarativeChart::Theme) m_chart->theme();
384 }
391 }
385
392
386 void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations)
393 void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations)
387 {
394 {
388 QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations;
395 QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations;
389 if (animationOptions != m_chart->animationOptions())
396 if (animationOptions != m_chart->animationOptions())
390 m_chart->setAnimationOptions(animationOptions);
397 m_chart->setAnimationOptions(animationOptions);
391 }
398 }
392
399
393 DeclarativeChart::Animation DeclarativeChart::animationOptions()
400 DeclarativeChart::Animation DeclarativeChart::animationOptions()
394 {
401 {
395 if (m_chart->animationOptions().testFlag(QChart::AllAnimations))
402 if (m_chart->animationOptions().testFlag(QChart::AllAnimations))
396 return DeclarativeChart::AllAnimations;
403 return DeclarativeChart::AllAnimations;
397 else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations))
404 else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations))
398 return DeclarativeChart::GridAxisAnimations;
405 return DeclarativeChart::GridAxisAnimations;
399 else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations))
406 else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations))
400 return DeclarativeChart::SeriesAnimations;
407 return DeclarativeChart::SeriesAnimations;
401 else
408 else
402 return DeclarativeChart::NoAnimation;
409 return DeclarativeChart::NoAnimation;
403 }
410 }
404
411
405 void DeclarativeChart::setTitle(QString title)
412 void DeclarativeChart::setTitle(QString title)
406 {
413 {
407 if (title != m_chart->title())
414 if (title != m_chart->title())
408 m_chart->setTitle(title);
415 m_chart->setTitle(title);
409 }
416 }
410 QString DeclarativeChart::title()
417 QString DeclarativeChart::title()
411 {
418 {
412 return m_chart->title();
419 return m_chart->title();
413 }
420 }
414
421
415 QAbstractAxis *DeclarativeChart::axisX(QAbstractSeries *series)
422 QAbstractAxis *DeclarativeChart::axisX(QAbstractSeries *series)
416 {
423 {
417 return m_chart->axisX(series);
424 return m_chart->axisX(series);
418 }
425 }
419
426
420 QAbstractAxis *DeclarativeChart::axisY(QAbstractSeries *series)
427 QAbstractAxis *DeclarativeChart::axisY(QAbstractSeries *series)
421 {
428 {
422 return m_chart->axisY(series);
429 return m_chart->axisY(series);
423 }
430 }
424
431
425 QLegend *DeclarativeChart::legend()
432 QLegend *DeclarativeChart::legend()
426 {
433 {
427 return m_chart->legend();
434 return m_chart->legend();
428 }
435 }
429
436
430 void DeclarativeChart::setTitleColor(QColor color)
437 void DeclarativeChart::setTitleColor(QColor color)
431 {
438 {
432 QBrush b = m_chart->titleBrush();
439 QBrush b = m_chart->titleBrush();
433 if (color != b.color()) {
440 if (color != b.color()) {
434 b.setColor(color);
441 b.setColor(color);
435 m_chart->setTitleBrush(b);
442 m_chart->setTitleBrush(b);
436 emit titleColorChanged(color);
443 emit titleColorChanged(color);
437 }
444 }
438 }
445 }
439
446
440 QFont DeclarativeChart::titleFont() const
447 QFont DeclarativeChart::titleFont() const
441 {
448 {
442 return m_chart->titleFont();
449 return m_chart->titleFont();
443 }
450 }
444
451
445 void DeclarativeChart::setTitleFont(const QFont& font)
452 void DeclarativeChart::setTitleFont(const QFont& font)
446 {
453 {
447 m_chart->setTitleFont(font);
454 m_chart->setTitleFont(font);
448 }
455 }
449
456
450 QColor DeclarativeChart::titleColor()
457 QColor DeclarativeChart::titleColor()
451 {
458 {
452 return m_chart->titleBrush().color();
459 return m_chart->titleBrush().color();
453 }
460 }
454
461
455 void DeclarativeChart::setBackgroundColor(QColor color)
462 void DeclarativeChart::setBackgroundColor(QColor color)
456 {
463 {
457 QBrush b = m_chart->backgroundBrush();
464 QBrush b = m_chart->backgroundBrush();
458 if (b.style() != Qt::SolidPattern || color != b.color()) {
465 if (b.style() != Qt::SolidPattern || color != b.color()) {
459 b.setStyle(Qt::SolidPattern);
466 b.setStyle(Qt::SolidPattern);
460 b.setColor(color);
467 b.setColor(color);
461 m_chart->setBackgroundBrush(b);
468 m_chart->setBackgroundBrush(b);
462 emit backgroundColorChanged();
469 emit backgroundColorChanged();
463 }
470 }
464 }
471 }
465
472
466 QColor DeclarativeChart::backgroundColor()
473 QColor DeclarativeChart::backgroundColor()
467 {
474 {
468 return m_chart->backgroundBrush().color();
475 return m_chart->backgroundBrush().color();
469 }
476 }
470
477
471 int DeclarativeChart::count()
478 int DeclarativeChart::count()
472 {
479 {
473 return m_chart->series().count();
480 return m_chart->series().count();
474 }
481 }
475
482
476 void DeclarativeChart::setDropShadowEnabled(bool enabled)
483 void DeclarativeChart::setDropShadowEnabled(bool enabled)
477 {
484 {
478 if (enabled != m_chart->isDropShadowEnabled()) {
485 if (enabled != m_chart->isDropShadowEnabled()) {
479 m_chart->setDropShadowEnabled(enabled);
486 m_chart->setDropShadowEnabled(enabled);
480 dropShadowEnabledChanged(enabled);
487 dropShadowEnabledChanged(enabled);
481 }
488 }
482 }
489 }
483
490
484 bool DeclarativeChart::dropShadowEnabled()
491 bool DeclarativeChart::dropShadowEnabled()
485 {
492 {
486 return m_chart->isDropShadowEnabled();
493 return m_chart->isDropShadowEnabled();
487 }
494 }
488
495
489 qreal DeclarativeChart::topMargin()
496 qreal DeclarativeChart::topMargin()
490 {
497 {
491 qWarning() << "ChartView.topMargin is deprecated. Use minimumMargins and plotArea instead.";
498 qWarning() << "ChartView.topMargin is deprecated. Use minimumMargins and plotArea instead.";
492 return m_chart->plotArea().top();
499 return m_chart->plotArea().top();
493 }
500 }
494
501
495 qreal DeclarativeChart::bottomMargin()
502 qreal DeclarativeChart::bottomMargin()
496 {
503 {
497 qWarning() << "ChartView.bottomMargin is deprecated. Use minimumMargins and plotArea instead.";
504 qWarning() << "ChartView.bottomMargin is deprecated. Use minimumMargins and plotArea instead.";
498 return m_chart->plotArea().bottom();
505 return m_chart->plotArea().bottom();
499 }
506 }
500
507
501 qreal DeclarativeChart::leftMargin()
508 qreal DeclarativeChart::leftMargin()
502 {
509 {
503 qWarning() << "ChartView.leftMargin is deprecated. Use minimumMargins and plotArea instead.";
510 qWarning() << "ChartView.leftMargin is deprecated. Use minimumMargins and plotArea instead.";
504 return m_chart->plotArea().left();
511 return m_chart->plotArea().left();
505 }
512 }
506
513
507 qreal DeclarativeChart::rightMargin()
514 qreal DeclarativeChart::rightMargin()
508 {
515 {
509 qWarning() << "ChartView.rightMargin is deprecated. Use minimumMargins and plotArea instead.";
516 qWarning() << "ChartView.rightMargin is deprecated. Use minimumMargins and plotArea instead.";
510 return m_chart->plotArea().right();
517 return m_chart->plotArea().right();
511 }
518 }
512
519
513 void DeclarativeChart::zoom(qreal factor)
520 void DeclarativeChart::zoom(qreal factor)
514 {
521 {
515 m_chart->zoom(factor);
522 m_chart->zoom(factor);
516 }
523 }
517
524
518 void DeclarativeChart::scrollLeft(qreal pixels)
525 void DeclarativeChart::scrollLeft(qreal pixels)
519 {
526 {
520 m_chart->scroll(-pixels, 0);
527 m_chart->scroll(-pixels, 0);
521 }
528 }
522
529
523 void DeclarativeChart::scrollRight(qreal pixels)
530 void DeclarativeChart::scrollRight(qreal pixels)
524 {
531 {
525 m_chart->scroll(pixels, 0);
532 m_chart->scroll(pixels, 0);
526 }
533 }
527
534
528 void DeclarativeChart::scrollUp(qreal pixels)
535 void DeclarativeChart::scrollUp(qreal pixels)
529 {
536 {
530 m_chart->scroll(0, pixels);
537 m_chart->scroll(0, pixels);
531 }
538 }
532
539
533 void DeclarativeChart::scrollDown(qreal pixels)
540 void DeclarativeChart::scrollDown(qreal pixels)
534 {
541 {
535 m_chart->scroll(0, -pixels);
542 m_chart->scroll(0, -pixels);
536 }
543 }
537
544
538 QAbstractSeries *DeclarativeChart::series(int index)
545 QAbstractSeries *DeclarativeChart::series(int index)
539 {
546 {
540 if (index < m_chart->series().count()) {
547 if (index < m_chart->series().count()) {
541 return m_chart->series().at(index);
548 return m_chart->series().at(index);
542 }
549 }
543 return 0;
550 return 0;
544 }
551 }
545
552
546 QAbstractSeries *DeclarativeChart::series(QString seriesName)
553 QAbstractSeries *DeclarativeChart::series(QString seriesName)
547 {
554 {
548 foreach(QAbstractSeries *series, m_chart->series()) {
555 foreach(QAbstractSeries *series, m_chart->series()) {
549 if (series->name() == seriesName)
556 if (series->name() == seriesName)
550 return series;
557 return series;
551 }
558 }
552 return 0;
559 return 0;
553 }
560 }
554
561
555 QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name)
562 QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name)
556 {
563 {
564 return createSeries(type, name, 0, 0);
565 }
566
567 QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name, QAbstractAxis *axisX, QAbstractAxis *axisY)
568 {
557 QAbstractSeries *series = 0;
569 QAbstractSeries *series = 0;
558
570
559 switch (type) {
571 switch (type) {
560 case DeclarativeChart::SeriesTypeLine:
572 case DeclarativeChart::SeriesTypeLine:
561 series = new DeclarativeLineSeries();
573 series = new DeclarativeLineSeries();
562 break;
574 break;
563 case DeclarativeChart::SeriesTypeArea:
575 case DeclarativeChart::SeriesTypeArea:
564 series = new DeclarativeAreaSeries();
576 series = new DeclarativeAreaSeries();
565 break;
577 break;
566 case DeclarativeChart::SeriesTypeStackedBar:
578 case DeclarativeChart::SeriesTypeStackedBar:
567 series = new DeclarativeStackedBarSeries();
579 series = new DeclarativeStackedBarSeries();
568 break;
580 break;
569 case DeclarativeChart::SeriesTypePercentBar:
581 case DeclarativeChart::SeriesTypePercentBar:
570 series = new DeclarativePercentBarSeries();
582 series = new DeclarativePercentBarSeries();
571 break;
583 break;
572 case DeclarativeChart::SeriesTypeBar:
584 case DeclarativeChart::SeriesTypeBar:
573 series = new DeclarativeBarSeries();
585 series = new DeclarativeBarSeries();
574 break;
586 break;
575 case DeclarativeChart::SeriesTypeHorizontalBar:
587 case DeclarativeChart::SeriesTypeHorizontalBar:
576 series = new DeclarativeHorizontalBarSeries();
588 series = new DeclarativeHorizontalBarSeries();
577 break;
589 break;
578 case DeclarativeChart::SeriesTypeHorizontalPercentBar:
590 case DeclarativeChart::SeriesTypeHorizontalPercentBar:
579 series = new DeclarativeHorizontalPercentBarSeries();
591 series = new DeclarativeHorizontalPercentBarSeries();
580 break;
592 break;
581 case DeclarativeChart::SeriesTypeHorizontalStackedBar:
593 case DeclarativeChart::SeriesTypeHorizontalStackedBar:
582 series = new DeclarativeHorizontalStackedBarSeries();
594 series = new DeclarativeHorizontalStackedBarSeries();
583 break;
595 break;
584 case DeclarativeChart::SeriesTypePie:
596 case DeclarativeChart::SeriesTypePie:
585 series = new DeclarativePieSeries();
597 series = new DeclarativePieSeries();
586 break;
598 break;
587 case DeclarativeChart::SeriesTypeScatter:
599 case DeclarativeChart::SeriesTypeScatter:
588 series = new DeclarativeScatterSeries();
600 series = new DeclarativeScatterSeries();
589 break;
601 break;
590 case DeclarativeChart::SeriesTypeSpline:
602 case DeclarativeChart::SeriesTypeSpline:
591 series = new DeclarativeSplineSeries();
603 series = new DeclarativeSplineSeries();
592 break;
604 break;
593 default:
605 default:
594 qWarning() << "Illegal series type";
606 qWarning() << "Illegal series type";
595 }
607 }
596
608
597 if (series) {
609 if (series) {
598 series->setName(name);
610 series->setName(name);
599 m_chart->addSeries(series);
611 m_chart->addSeries(series);
612 // Set possible user defined axes
613 setAxisX(axisX, series);
614 setAxisY(axisY, series);
615 // Then create the missing axes
600 createDefaultAxes(series);
616 createDefaultAxes(series);
601 }
617 }
602
618
603 return series;
619 return series;
604 }
620 }
605
621
606 void DeclarativeChart::setAxisX(QAbstractAxis *axis, QAbstractSeries *series)
622 void DeclarativeChart::setAxisX(QAbstractAxis *axis, QAbstractSeries *series)
607 {
623 {
608 if (axis)
624 if (axis)
609 m_chart->setAxisX(axis, series);
625 m_chart->setAxisX(axis, series);
610 }
626 }
611
627
612 void DeclarativeChart::setAxisY(QAbstractAxis *axis, QAbstractSeries *series)
628 void DeclarativeChart::setAxisY(QAbstractAxis *axis, QAbstractSeries *series)
613 {
629 {
614 if (axis)
630 if (axis)
615 m_chart->setAxisY(axis, series);
631 m_chart->setAxisY(axis, series);
616 }
632 }
617
633
618 void DeclarativeChart::createDefaultAxes()
634 void DeclarativeChart::createDefaultAxes()
619 {
635 {
620 qWarning() << "ChartView.createDefaultAxes() is deprecated. Axes are created automatically.";
636 qWarning() << "ChartView.createDefaultAxes() is deprecated. Axes are created automatically.";
621 }
637 }
622
638
623 void DeclarativeChart::createDefaultAxes(QAbstractSeries* series)
639 void DeclarativeChart::createDefaultAxes(QAbstractSeries* series)
624 {
640 {
625 foreach (QAbstractSeries *s, m_chart->series()) {
641 foreach (QAbstractSeries *s, m_chart->series()) {
626 // If there is already an x axis of the correct type, re-use it
642 // If there is already an x axis of the correct type, re-use it
627 if (!m_chart->axisX(series) && s != series && m_chart->axisX(s)
643 if (!m_chart->axisX(series) && s != series && m_chart->axisX(s)
628 && m_chart->axisX(s)->type() == series->d_ptr->defaultAxisType(Qt::Horizontal))
644 && m_chart->axisX(s)->type() == series->d_ptr->defaultAxisType(Qt::Horizontal))
629 m_chart->setAxisX(m_chart->axisX(s), series);
645 m_chart->setAxisX(m_chart->axisX(s), series);
630
646
631 // If there is already a y axis of the correct type, re-use it
647 // If there is already a y axis of the correct type, re-use it
632 if (!m_chart->axisY(series) && s != series && m_chart->axisY(s)
648 if (!m_chart->axisY(series) && s != series && m_chart->axisY(s)
633 && m_chart->axisY(s)->type() == series->d_ptr->defaultAxisType(Qt::Vertical))
649 && m_chart->axisY(s)->type() == series->d_ptr->defaultAxisType(Qt::Vertical))
634 m_chart->setAxisY(m_chart->axisY(s), series);
650 m_chart->setAxisY(m_chart->axisY(s), series);
635 }
651 }
636
652
637 // If no x axis of correct type was found, create a new x axis based of default axis type
653 // If no x axis of correct type was found, create a new x axis based of default axis type
638 if (!m_chart->axisX(series)) {
654 if (!m_chart->axisX(series)) {
639 switch (series->d_ptr->defaultAxisType(Qt::Horizontal)) {
655 switch (series->d_ptr->defaultAxisType(Qt::Horizontal)) {
640 case QAbstractAxis::AxisTypeValue:
656 case QAbstractAxis::AxisTypeValue:
641 m_chart->setAxisX(new QValueAxis(this), series);
657 m_chart->setAxisX(new QValueAxis(this), series);
642 break;
658 break;
643 case QAbstractAxis::AxisTypeBarCategory:
659 case QAbstractAxis::AxisTypeBarCategory:
644 m_chart->setAxisX(new QBarCategoryAxis(this), series);
660 m_chart->setAxisX(new QBarCategoryAxis(this), series);
645 break;
661 break;
646 case QAbstractAxis::AxisTypeCategory:
662 case QAbstractAxis::AxisTypeCategory:
647 m_chart->setAxisX(new QCategoryAxis(this), series);
663 m_chart->setAxisX(new QCategoryAxis(this), series);
648 break;
664 break;
649 #ifndef QT_ON_ARM
665 #ifndef QT_ON_ARM
650 case QAbstractAxis::AxisTypeDateTime:
666 case QAbstractAxis::AxisTypeDateTime:
651 m_chart->setAxisX(new QDateTimeAxis(this), series);
667 m_chart->setAxisX(new QDateTimeAxis(this), series);
652 break;
668 break;
653 #endif
669 #endif
654 default:
670 default:
655 // Do nothing, assume AxisTypeNoAxis
671 // Do nothing, assume AxisTypeNoAxis
656 break;
672 break;
657 }
673 }
658 }
674 }
659
675
660 // If no y axis of correct type was found, create a new y axis based of default axis type
676 // If no y axis of correct type was found, create a new y axis based of default axis type
661 if (!m_chart->axisY(series)) {
677 if (!m_chart->axisY(series)) {
662 switch (series->d_ptr->defaultAxisType(Qt::Vertical)) {
678 switch (series->d_ptr->defaultAxisType(Qt::Vertical)) {
663 case QAbstractAxis::AxisTypeValue:
679 case QAbstractAxis::AxisTypeValue:
664 m_chart->setAxisY(new QValueAxis(this), series);
680 m_chart->setAxisY(new QValueAxis(this), series);
665 break;
681 break;
666 case QAbstractAxis::AxisTypeBarCategory:
682 case QAbstractAxis::AxisTypeBarCategory:
667 m_chart->setAxisY(new QBarCategoryAxis(this), series);
683 m_chart->setAxisY(new QBarCategoryAxis(this), series);
668 break;
684 break;
669 case QAbstractAxis::AxisTypeCategory:
685 case QAbstractAxis::AxisTypeCategory:
670 m_chart->setAxisY(new QCategoryAxis(this), series);
686 m_chart->setAxisY(new QCategoryAxis(this), series);
671 break;
687 break;
672 #ifndef QT_ON_ARM
688 #ifndef QT_ON_ARM
673 case QAbstractAxis::AxisTypeDateTime:
689 case QAbstractAxis::AxisTypeDateTime:
674 m_chart->setAxisY(new QDateTimeAxis(this), series);
690 m_chart->setAxisY(new QDateTimeAxis(this), series);
675 break;
691 break;
676 #endif
692 #endif
677 default:
693 default:
678 // Do nothing, assume AxisTypeNoAxis
694 // Do nothing, assume AxisTypeNoAxis
679 break;
695 break;
680 }
696 }
681 }
697 }
682
698
683 //qDebug() << "axis for series" << series << "x:" << m_chart->axisX(series) << "y:" << m_chart->axisY(series);
699 //qDebug() << "axis for series" << series << "x:" << m_chart->axisX(series) << "y:" << m_chart->axisY(series);
684 }
700 }
685
701
686 #include "moc_declarativechart.cpp"
702 #include "moc_declarativechart.cpp"
687
703
688 QTCOMMERCIALCHART_END_NAMESPACE
704 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,161 +1,162
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)
44 Q_PROPERTY(qreal topMargin READ topMargin)
45 Q_PROPERTY(qreal bottomMargin READ bottomMargin)
45 Q_PROPERTY(qreal bottomMargin READ bottomMargin)
46 Q_PROPERTY(qreal leftMargin READ leftMargin)
46 Q_PROPERTY(qreal leftMargin READ leftMargin)
47 Q_PROPERTY(qreal rightMargin READ rightMargin)
47 Q_PROPERTY(qreal rightMargin READ rightMargin)
48 Q_PROPERTY(DeclarativeMargins *minimumMargins READ minimumMargins NOTIFY minimumMarginsChanged REVISION 1)
48 Q_PROPERTY(DeclarativeMargins *minimumMargins READ minimumMargins NOTIFY minimumMarginsChanged REVISION 1)
49 Q_PROPERTY(QRectF plotArea READ plotArea NOTIFY plotAreaChanged REVISION 1)
49 Q_PROPERTY(QRectF plotArea READ plotArea NOTIFY plotAreaChanged REVISION 1)
50 Q_ENUMS(Animation)
50 Q_ENUMS(Animation)
51 Q_ENUMS(Theme)
51 Q_ENUMS(Theme)
52 Q_ENUMS(SeriesType)
52 Q_ENUMS(SeriesType)
53
53
54 public:
54 public:
55 // 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
56 enum Theme {
56 enum Theme {
57 ChartThemeLight = 0,
57 ChartThemeLight = 0,
58 ChartThemeBlueCerulean,
58 ChartThemeBlueCerulean,
59 ChartThemeDark,
59 ChartThemeDark,
60 ChartThemeBrownSand,
60 ChartThemeBrownSand,
61 ChartThemeBlueNcs,
61 ChartThemeBlueNcs,
62 ChartThemeHighContrast,
62 ChartThemeHighContrast,
63 ChartThemeBlueIcy
63 ChartThemeBlueIcy
64 };
64 };
65
65
66 enum Animation {
66 enum Animation {
67 NoAnimation = 0x0,
67 NoAnimation = 0x0,
68 GridAxisAnimations = 0x1,
68 GridAxisAnimations = 0x1,
69 SeriesAnimations =0x2,
69 SeriesAnimations =0x2,
70 AllAnimations = 0x3
70 AllAnimations = 0x3
71 };
71 };
72
72
73 enum SeriesType {
73 enum SeriesType {
74 SeriesTypeLine,
74 SeriesTypeLine,
75 SeriesTypeArea,
75 SeriesTypeArea,
76 SeriesTypeBar,
76 SeriesTypeBar,
77 SeriesTypeStackedBar,
77 SeriesTypeStackedBar,
78 SeriesTypePercentBar,
78 SeriesTypePercentBar,
79 SeriesTypePie,
79 SeriesTypePie,
80 SeriesTypeScatter,
80 SeriesTypeScatter,
81 SeriesTypeSpline,
81 SeriesTypeSpline,
82 SeriesTypeHorizontalBar,
82 SeriesTypeHorizontalBar,
83 SeriesTypeHorizontalStackedBar,
83 SeriesTypeHorizontalStackedBar,
84 SeriesTypeHorizontalPercentBar
84 SeriesTypeHorizontalPercentBar
85 };
85 };
86
86
87 public:
87 public:
88 DeclarativeChart(QDeclarativeItem *parent = 0);
88 DeclarativeChart(QDeclarativeItem *parent = 0);
89 ~DeclarativeChart();
89 ~DeclarativeChart();
90
90
91 public: // From QDeclarativeItem/QGraphicsItem
91 public: // From QDeclarativeItem/QGraphicsItem
92 void childEvent(QChildEvent *event);
92 void childEvent(QChildEvent *event);
93 void componentComplete();
93 void componentComplete();
94 void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
94 void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
95
95
96 public:
96 public:
97 void setTheme(DeclarativeChart::Theme theme);
97 void setTheme(DeclarativeChart::Theme theme);
98 DeclarativeChart::Theme theme();
98 DeclarativeChart::Theme theme();
99 void setAnimationOptions(DeclarativeChart::Animation animations);
99 void setAnimationOptions(DeclarativeChart::Animation animations);
100 DeclarativeChart::Animation animationOptions();
100 DeclarativeChart::Animation animationOptions();
101 void setTitle(QString title);
101 void setTitle(QString title);
102 QString title();
102 QString title();
103 QLegend *legend();
103 QLegend *legend();
104 QFont titleFont() const;
104 QFont titleFont() const;
105 void setTitleFont(const QFont& font);
105 void setTitleFont(const QFont& font);
106 void setTitleColor(QColor color);
106 void setTitleColor(QColor color);
107 QColor titleColor();
107 QColor titleColor();
108 void setBackgroundColor(QColor color);
108 void setBackgroundColor(QColor color);
109 QColor backgroundColor();
109 QColor backgroundColor();
110 int count();
110 int count();
111 void setDropShadowEnabled(bool enabled);
111 void setDropShadowEnabled(bool enabled);
112 bool dropShadowEnabled();
112 bool dropShadowEnabled();
113 qreal topMargin();
113 qreal topMargin();
114 qreal bottomMargin();
114 qreal bottomMargin();
115 qreal leftMargin();
115 qreal leftMargin();
116 qreal rightMargin();
116 qreal rightMargin();
117 void createDefaultAxes(QAbstractSeries* series);
117 void createDefaultAxes(QAbstractSeries* series);
118 DeclarativeMargins *minimumMargins() { return m_minMargins; }
118 DeclarativeMargins *minimumMargins() { return m_minMargins; }
119 QRectF plotArea() { return m_chart->plotArea(); }
119 QRectF plotArea() { return m_chart->plotArea(); }
120
120
121 public:
121 public:
122 Q_INVOKABLE QAbstractSeries *series(int index);
122 Q_INVOKABLE QAbstractSeries *series(int index);
123 Q_INVOKABLE QAbstractSeries *series(QString seriesName);
123 Q_INVOKABLE QAbstractSeries *series(QString seriesName);
124 Q_INVOKABLE QAbstractSeries *createSeries(DeclarativeChart::SeriesType type, QString name = "");
124 Q_INVOKABLE QAbstractSeries *createSeries(DeclarativeChart::SeriesType type, QString name = "");
125 Q_INVOKABLE QAbstractSeries *createSeries(DeclarativeChart::SeriesType type, QString name, QAbstractAxis *axisX, QAbstractAxis *axisY);
125 Q_INVOKABLE void removeSeries(QAbstractSeries *series) { m_chart->removeSeries(series); }
126 Q_INVOKABLE void removeSeries(QAbstractSeries *series) { m_chart->removeSeries(series); }
126 Q_INVOKABLE void removeAllSeries() { m_chart->removeAllSeries(); }
127 Q_INVOKABLE void removeAllSeries() { m_chart->removeAllSeries(); }
127 Q_INVOKABLE void setAxisX(QAbstractAxis *axis, QAbstractSeries *series = 0);
128 Q_INVOKABLE void setAxisX(QAbstractAxis *axis, QAbstractSeries *series = 0);
128 Q_INVOKABLE void setAxisY(QAbstractAxis *axis, QAbstractSeries *series = 0);
129 Q_INVOKABLE void setAxisY(QAbstractAxis *axis, QAbstractSeries *series = 0);
129 Q_INVOKABLE void createDefaultAxes();
130 Q_INVOKABLE void createDefaultAxes();
130 Q_INVOKABLE QAbstractAxis *axisX(QAbstractSeries *series = 0);
131 Q_INVOKABLE QAbstractAxis *axisX(QAbstractSeries *series = 0);
131 Q_INVOKABLE QAbstractAxis *axisY(QAbstractSeries *series = 0);
132 Q_INVOKABLE QAbstractAxis *axisY(QAbstractSeries *series = 0);
132 Q_INVOKABLE void zoom(qreal factor);
133 Q_INVOKABLE void zoom(qreal factor);
133 Q_INVOKABLE void scrollLeft(qreal pixels);
134 Q_INVOKABLE void scrollLeft(qreal pixels);
134 Q_INVOKABLE void scrollRight(qreal pixels);
135 Q_INVOKABLE void scrollRight(qreal pixels);
135 Q_INVOKABLE void scrollUp(qreal pixels);
136 Q_INVOKABLE void scrollUp(qreal pixels);
136 Q_INVOKABLE void scrollDown(qreal pixels);
137 Q_INVOKABLE void scrollDown(qreal pixels);
137
138
138 Q_SIGNALS:
139 Q_SIGNALS:
139 void axisLabelsChanged();
140 void axisLabelsChanged();
140 void titleColorChanged(QColor color);
141 void titleColorChanged(QColor color);
141 void backgroundColorChanged();
142 void backgroundColorChanged();
142 void dropShadowEnabledChanged(bool enabled);
143 void dropShadowEnabledChanged(bool enabled);
143 void minimumMarginsChanged();
144 void minimumMarginsChanged();
144 void plotAreaChanged(QRectF plotArea);
145 void plotAreaChanged(QRectF plotArea);
145
146
146 public Q_SLOTS:
147 public Q_SLOTS:
147 void changeMinimumMargins(int top, int bottom, int left, int right);
148 void changeMinimumMargins(int top, int bottom, int left, int right);
148 void handleAxisXSet(QAbstractAxis *axis);
149 void handleAxisXSet(QAbstractAxis *axis);
149 void handleAxisYSet(QAbstractAxis *axis);
150 void handleAxisYSet(QAbstractAxis *axis);
150
151
151 private:
152 private:
152 // Extending QChart with DeclarativeChart is not possible because QObject does not support
153 // 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
154 // multi inheritance, so we now have a QChart as a member instead
154 QChart *m_chart;
155 QChart *m_chart;
155 //QMargins m_chartMargins;
156 //QMargins m_chartMargins;
156 DeclarativeMargins *m_minMargins;
157 DeclarativeMargins *m_minMargins;
157 };
158 };
158
159
159 QTCOMMERCIALCHART_END_NAMESPACE
160 QTCOMMERCIALCHART_END_NAMESPACE
160
161
161 #endif // DECLARATIVECHART_H
162 #endif // DECLARATIVECHART_H
General Comments 0
You need to be logged in to leave comments. Login now