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