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