@@ -1,516 +1,516 | |||||
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 "declarativelineseries.h" |
|
23 | #include "declarativelineseries.h" | |
24 | #include "declarativeareaseries.h" |
|
24 | #include "declarativeareaseries.h" | |
25 | #include "declarativebarseries.h" |
|
25 | #include "declarativebarseries.h" | |
26 | #include "declarativepieseries.h" |
|
26 | #include "declarativepieseries.h" | |
27 | #include "declarativesplineseries.h" |
|
27 | #include "declarativesplineseries.h" | |
28 | #include "declarativescatterseries.h" |
|
28 | #include "declarativescatterseries.h" | |
29 | #include "qbarcategoriesaxis.h" |
|
29 | #include "qbarcategoriesaxis.h" | |
30 |
|
30 | |||
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
32 |
|
32 | |||
33 | /*! |
|
33 | /*! | |
34 | \qmlclass ChartView DeclarativeChart |
|
34 | \qmlclass ChartView DeclarativeChart | |
35 |
|
35 | |||
36 | ChartView element is the parent that is responsible for showing different chart series types. |
|
36 | ChartView element is the parent that is responsible for showing different chart series types. | |
37 |
|
37 | |||
38 | The following QML shows how to create a simple chart with one pie series: |
|
38 | The following QML shows how to create a simple chart with one pie series: | |
39 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 1 |
|
39 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 1 | |
40 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2 |
|
40 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2 | |
41 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 3 |
|
41 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 3 | |
42 |
|
42 | |||
43 | \beginfloatleft |
|
43 | \beginfloatleft | |
44 | \image examples_qmlpiechart.png |
|
44 | \image examples_qmlpiechart.png | |
45 | \endfloat |
|
45 | \endfloat | |
46 | \clearfloat |
|
46 | \clearfloat | |
47 | */ |
|
47 | */ | |
48 |
|
48 | |||
49 | /*! |
|
49 | /*! | |
50 | \qmlproperty Theme ChartView::theme |
|
50 | \qmlproperty Theme ChartView::theme | |
51 | Theme defines the visual appearance of the chart, including for example colors, fonts, line |
|
51 | Theme defines the visual appearance of the chart, including for example colors, fonts, line | |
52 | widths and chart background. |
|
52 | widths and chart background. | |
53 | */ |
|
53 | */ | |
54 |
|
54 | |||
55 | /*! |
|
55 | /*! | |
56 | \qmlproperty Animation ChartView::animation |
|
56 | \qmlproperty Animation ChartView::animation | |
57 | Animation configuration of the chart. One of ChartView.NoAnimation, ChartView.GridAxisAnimations, |
|
57 | Animation configuration of the chart. One of ChartView.NoAnimation, ChartView.GridAxisAnimations, | |
58 | ChartView.SeriesAnimations or ChartView.AllAnimations. |
|
58 | ChartView.SeriesAnimations or ChartView.AllAnimations. | |
59 | */ |
|
59 | */ | |
60 |
|
60 | |||
61 | /*! |
|
61 | /*! | |
62 | \qmlproperty Font ChartView::titleFont |
|
62 | \qmlproperty Font ChartView::titleFont | |
63 | The title font of the chart |
|
63 | The title font of the chart | |
64 |
|
64 | |||
65 | See the \l {Font} {QML Font Element} for detailed documentation. |
|
65 | See the \l {Font} {QML Font Element} for detailed documentation. | |
66 | */ |
|
66 | */ | |
67 |
|
67 | |||
68 | /*! |
|
68 | /*! | |
69 | \qmlproperty string ChartView::title |
|
69 | \qmlproperty string ChartView::title | |
70 | The title of the chart, shown on top of the chart. |
|
70 | The title of the chart, shown on top of the chart. | |
71 | \sa ChartView::titleColor |
|
71 | \sa ChartView::titleColor | |
72 | */ |
|
72 | */ | |
73 |
|
73 | |||
74 | /*! |
|
74 | /*! | |
75 | \qmlproperty string ChartView::titleColor |
|
75 | \qmlproperty string ChartView::titleColor | |
76 | The color of the title text. |
|
76 | The color of the title text. | |
77 | */ |
|
77 | */ | |
78 |
|
78 | |||
79 | /*! |
|
79 | /*! | |
80 | \qmlproperty Axis ChartView::axisX |
|
80 | \qmlproperty Axis ChartView::axisX | |
81 | The x-axis of the chart. |
|
81 | The x-axis of the chart. | |
82 | */ |
|
82 | */ | |
83 |
|
83 | |||
84 | /*! |
|
84 | /*! | |
85 | \qmlproperty Axis ChartView::axisY |
|
85 | \qmlproperty Axis ChartView::axisY | |
86 | The default y-axis of the chart. |
|
86 | The default y-axis of the chart. | |
87 | */ |
|
87 | */ | |
88 |
|
88 | |||
89 | /*! |
|
89 | /*! | |
90 | \qmlproperty Legend ChartView::legend |
|
90 | \qmlproperty Legend ChartView::legend | |
91 | The legend of the chart. Legend lists all the series, pie slices and bar sets added on the chart. |
|
91 | The legend of the chart. Legend lists all the series, pie slices and bar sets added on the chart. | |
92 | */ |
|
92 | */ | |
93 |
|
93 | |||
94 | /*! |
|
94 | /*! | |
95 | \qmlproperty int ChartView::count |
|
95 | \qmlproperty int ChartView::count | |
96 | The count of series added to the chart. |
|
96 | The count of series added to the chart. | |
97 | */ |
|
97 | */ | |
98 |
|
98 | |||
99 | /*! |
|
99 | /*! | |
100 | \qmlproperty color ChartView::backgroundColor |
|
100 | \qmlproperty color ChartView::backgroundColor | |
101 | The color of the chart's background. By default background color is defined by chart theme. |
|
101 | The color of the chart's background. By default background color is defined by chart theme. | |
102 | \sa ChartView::theme |
|
102 | \sa ChartView::theme | |
103 | */ |
|
103 | */ | |
104 |
|
104 | |||
105 | /*! |
|
105 | /*! | |
106 | \qmlproperty bool ChartView::dropShadowEnabled |
|
106 | \qmlproperty bool ChartView::dropShadowEnabled | |
107 | The chart's border drop shadow. Set to true to enable drop shadow. |
|
107 | The chart's border drop shadow. Set to true to enable drop shadow. | |
108 | */ |
|
108 | */ | |
109 |
|
109 | |||
110 | /*! |
|
110 | /*! | |
111 | \qmlproperty real ChartView::topMargin |
|
111 | \qmlproperty real ChartView::topMargin | |
112 | The space between the top of chart view and the top of the plot area. The title (if non-empty) is drawn on top margin |
|
112 | The space between the top of chart view and the top of the plot area. The title (if non-empty) is drawn on top margin | |
113 | area of the chart view. Top margin area is also used by legend, if aligned to top. |
|
113 | area of the chart view. Top margin area is also used by legend, if aligned to top. | |
114 | */ |
|
114 | */ | |
115 |
|
115 | |||
116 | /*! |
|
116 | /*! | |
117 | \qmlproperty real ChartView::bottomMargin |
|
117 | \qmlproperty real ChartView::bottomMargin | |
118 | The space between the bottom of chart view and the bottom of the plot area. The bottom margin area may be used by |
|
118 | The space between the bottom of chart view and the bottom of the plot area. The bottom margin area may be used by | |
119 | legend (if aligned to bottom), x-axis, x-axis labels and x-axis tick marks. |
|
119 | legend (if aligned to bottom), x-axis, x-axis labels and x-axis tick marks. | |
120 | */ |
|
120 | */ | |
121 |
|
121 | |||
122 | /*! |
|
122 | /*! | |
123 | \qmlproperty real ChartView::leftMargin |
|
123 | \qmlproperty real ChartView::leftMargin | |
124 | The space between the left side of chart view and the left side of the plot area. The left margin area may be used by |
|
124 | The space between the left side of chart view and the left side of the plot area. The left margin area may be used by | |
125 | legend (if aligned to left), y-axis, y-axis labels and y-axis tick marks. |
|
125 | legend (if aligned to left), y-axis, y-axis labels and y-axis tick marks. | |
126 | */ |
|
126 | */ | |
127 |
|
127 | |||
128 | /*! |
|
128 | /*! | |
129 | \qmlproperty real ChartView::rightMargin |
|
129 | \qmlproperty real ChartView::rightMargin | |
130 | The space between the right side of chart view and the right side of the plot area. The right margin area may be used |
|
130 | The space between the right side of chart view and the right side of the plot area. The right margin area may be used | |
131 | by legend (if aligned to right). |
|
131 | by legend (if aligned to right). | |
132 | */ |
|
132 | */ | |
133 |
|
133 | |||
134 | /*! |
|
134 | /*! | |
135 | \qmlmethod AbstractSeries ChartView::series(int index) |
|
135 | \qmlmethod AbstractSeries ChartView::series(int index) | |
136 | Returns the series with \a index on the chart. This allows you to loop through the series of a chart together with |
|
136 | Returns the series with \a index on the chart. This allows you to loop through the series of a chart together with | |
137 | the count property of the chart. |
|
137 | the count property of the chart. | |
138 | */ |
|
138 | */ | |
139 |
|
139 | |||
140 | /*! |
|
140 | /*! | |
141 | \qmlmethod AbstractSeries ChartView::series(string name) |
|
141 | \qmlmethod AbstractSeries ChartView::series(string name) | |
142 | Returns the first series on the chart with \a name. If there is no series with that name, returns null. |
|
142 | Returns the first series on the chart with \a name. If there is no series with that name, returns null. | |
143 | */ |
|
143 | */ | |
144 |
|
144 | |||
145 | /*! |
|
145 | /*! | |
146 | \qmlmethod AbstractSeries ChartView::createSeries(SeriesType type, string name) |
|
146 | \qmlmethod AbstractSeries ChartView::createSeries(SeriesType type, string name) | |
147 | Creates a series object of \a type to the chart. For example: |
|
147 | Creates a series object of \a type to the chart. For example: | |
148 | \code |
|
148 | \code | |
149 | var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter series"); |
|
149 | var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter series"); | |
150 | scatter.markerSize = 22; |
|
150 | scatter.markerSize = 22; | |
151 | scatter.append(1.1, 2.0); |
|
151 | scatter.append(1.1, 2.0); | |
152 | \endcode |
|
152 | \endcode | |
153 | */ |
|
153 | */ | |
154 |
|
154 | |||
155 | /*! |
|
155 | /*! | |
156 | \qmlmethod Axis ChartView::axisY(QAbstractSeries *series) |
|
156 | \qmlmethod Axis ChartView::axisY(QAbstractSeries *series) | |
157 | 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. |
|
157 | 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. | |
158 | */ |
|
158 | */ | |
159 |
|
159 | |||
160 | /*! |
|
160 | /*! | |
161 | \qmlmethod ChartView::zoomY(real factor) |
|
161 | \qmlmethod ChartView::zoomY(real factor) | |
162 | Zooms in by \a factor on the center of the chart. |
|
162 | Zooms in by \a factor on the center of the chart. | |
163 | */ |
|
163 | */ | |
164 |
|
164 | |||
165 | /*! |
|
165 | /*! | |
166 | \qmlmethod ChartView::scrollLeft(real pixels) |
|
166 | \qmlmethod ChartView::scrollLeft(real pixels) | |
167 | Scrolls to left by \a pixels. This is a convenience function that suits for example for key navigation. |
|
167 | Scrolls to left by \a pixels. This is a convenience function that suits for example for key navigation. | |
168 | \sa AbstractAxis::min, AbstractAxis::max |
|
168 | \sa ValuesAxis::min, ValuesAxis::max, BarCategoriesAxis::min, BarCategoriesAxis::max | |
169 | */ |
|
169 | */ | |
170 |
|
170 | |||
171 | /*! |
|
171 | /*! | |
172 | \qmlmethod ChartView::scrollRight(real pixels) |
|
172 | \qmlmethod ChartView::scrollRight(real pixels) | |
173 | Scrolls to right by \a pixels. This is a convenience function that suits for example for key navigation. |
|
173 | Scrolls to right by \a pixels. This is a convenience function that suits for example for key navigation. | |
174 | \sa AbstractAxis::min, AbstractAxis::max |
|
174 | \sa ValuesAxis::min, ValuesAxis::max, BarCategoriesAxis::min, BarCategoriesAxis::max | |
175 | */ |
|
175 | */ | |
176 |
|
176 | |||
177 | /*! |
|
177 | /*! | |
178 | \qmlmethod ChartView::scrollUp(real pixels) |
|
178 | \qmlmethod ChartView::scrollUp(real pixels) | |
179 | Scrolls up by \a pixels. This is a convenience function that suits for example for key navigation. |
|
179 | Scrolls up by \a pixels. This is a convenience function that suits for example for key navigation. | |
180 | \sa AbstractAxis::min, AbstractAxis::max |
|
180 | \sa ValuesAxis::min, ValuesAxis::max, BarCategoriesAxis::min, BarCategoriesAxis::max | |
181 | */ |
|
181 | */ | |
182 |
|
182 | |||
183 | /*! |
|
183 | /*! | |
184 | \qmlmethod ChartView::scrollDown(real pixels) |
|
184 | \qmlmethod ChartView::scrollDown(real pixels) | |
185 | Scrolls down by \a pixels. This is a convenience function that suits for example for key navigation. |
|
185 | Scrolls down by \a pixels. This is a convenience function that suits for example for key navigation. | |
186 | \sa AbstractAxis::min, AbstractAxis::max |
|
186 | \sa ValuesAxis::min, ValuesAxis::max, BarCategoriesAxis::min, BarCategoriesAxis::max | |
187 | */ |
|
187 | */ | |
188 |
|
188 | |||
189 | /*! |
|
189 | /*! | |
190 | \qmlsignal ChartView::onTopMarginChanged(real margin) |
|
190 | \qmlsignal ChartView::onTopMarginChanged(real margin) | |
191 | The top margin of the chart view has changed to \a margin. This may happen for example if you modify font size |
|
191 | The top margin of the chart view has changed to \a margin. This may happen for example if you modify font size | |
192 | related properties of the legend or chart title. |
|
192 | related properties of the legend or chart title. | |
193 | */ |
|
193 | */ | |
194 |
|
194 | |||
195 | /*! |
|
195 | /*! | |
196 | \qmlsignal ChartView::onBottomMarginChanged(real margin) |
|
196 | \qmlsignal ChartView::onBottomMarginChanged(real margin) | |
197 | The bottom margin of the chart view has changed to \a margin. This may happen for example if you modify font size |
|
197 | The bottom margin of the chart view has changed to \a margin. This may happen for example if you modify font size | |
198 | related properties of the legend or chart title. |
|
198 | related properties of the legend or chart title. | |
199 | */ |
|
199 | */ | |
200 |
|
200 | |||
201 | /*! |
|
201 | /*! | |
202 | \qmlsignal ChartView::onLeftMarginChanged(real margin) |
|
202 | \qmlsignal ChartView::onLeftMarginChanged(real margin) | |
203 | The left margin of the chart view has changed to \a margin. This may happen for example if you modify font size |
|
203 | The left margin of the chart view has changed to \a margin. This may happen for example if you modify font size | |
204 | related properties of the legend or chart title. |
|
204 | related properties of the legend or chart title. | |
205 | */ |
|
205 | */ | |
206 |
|
206 | |||
207 | /*! |
|
207 | /*! | |
208 | \qmlsignal ChartView::onRightMarginChanged(real margin) |
|
208 | \qmlsignal ChartView::onRightMarginChanged(real margin) | |
209 | The right margin of the chart view has changed to \a margin. This may happen for example if you modify font size |
|
209 | The right margin of the chart view has changed to \a margin. This may happen for example if you modify font size | |
210 | related properties of the legend or chart title. |
|
210 | related properties of the legend or chart title. | |
211 | */ |
|
211 | */ | |
212 |
|
212 | |||
213 | DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent) |
|
213 | DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent) | |
214 | : QDeclarativeItem(parent), |
|
214 | : QDeclarativeItem(parent), | |
215 | m_chart(new QChart(this)) |
|
215 | m_chart(new QChart(this)) | |
216 | { |
|
216 | { | |
217 | setFlag(QGraphicsItem::ItemHasNoContents, false); |
|
217 | setFlag(QGraphicsItem::ItemHasNoContents, false); | |
218 | // m_chart->axisX()->setNiceNumbersEnabled(false); |
|
218 | // m_chart->axisX()->setNiceNumbersEnabled(false); | |
219 | m_chartMargins = m_chart->margins(); |
|
219 | m_chartMargins = m_chart->margins(); | |
220 | connect(m_chart, SIGNAL(marginsChanged(QRectF)), this, SLOT(handleMarginsChanged(QRectF))); |
|
220 | connect(m_chart, SIGNAL(marginsChanged(QRectF)), this, SLOT(handleMarginsChanged(QRectF))); | |
221 | } |
|
221 | } | |
222 |
|
222 | |||
223 | void DeclarativeChart::handleMarginsChanged(QRectF newMargins) |
|
223 | void DeclarativeChart::handleMarginsChanged(QRectF newMargins) | |
224 | { |
|
224 | { | |
225 | if (m_chartMargins.top() != newMargins.top()) |
|
225 | if (m_chartMargins.top() != newMargins.top()) | |
226 | topMarginChanged(m_chart->margins().top()); |
|
226 | topMarginChanged(m_chart->margins().top()); | |
227 | if (m_chartMargins.bottom() != newMargins.bottom()) |
|
227 | if (m_chartMargins.bottom() != newMargins.bottom()) | |
228 | bottomMarginChanged(m_chart->margins().bottom()); |
|
228 | bottomMarginChanged(m_chart->margins().bottom()); | |
229 | if (m_chartMargins.left() != newMargins.left()) |
|
229 | if (m_chartMargins.left() != newMargins.left()) | |
230 | leftMarginChanged(m_chart->margins().left()); |
|
230 | leftMarginChanged(m_chart->margins().left()); | |
231 | if (m_chartMargins.right() != newMargins.right()) |
|
231 | if (m_chartMargins.right() != newMargins.right()) | |
232 | rightMarginChanged(m_chart->margins().right()); |
|
232 | rightMarginChanged(m_chart->margins().right()); | |
233 |
|
233 | |||
234 | m_chartMargins = m_chart->margins(); |
|
234 | m_chartMargins = m_chart->margins(); | |
235 | } |
|
235 | } | |
236 |
|
236 | |||
237 | DeclarativeChart::~DeclarativeChart() |
|
237 | DeclarativeChart::~DeclarativeChart() | |
238 | { |
|
238 | { | |
239 | delete m_chart; |
|
239 | delete m_chart; | |
240 | } |
|
240 | } | |
241 |
|
241 | |||
242 | void DeclarativeChart::childEvent(QChildEvent *event) |
|
242 | void DeclarativeChart::childEvent(QChildEvent *event) | |
243 | { |
|
243 | { | |
244 | if (event->type() == QEvent::ChildAdded) { |
|
244 | if (event->type() == QEvent::ChildAdded) { | |
245 | if (qobject_cast<QAbstractSeries *>(event->child())) { |
|
245 | if (qobject_cast<QAbstractSeries *>(event->child())) { | |
246 | m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child())); |
|
246 | m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child())); | |
247 | } |
|
247 | } | |
248 | } |
|
248 | } | |
249 | } |
|
249 | } | |
250 |
|
250 | |||
251 | void DeclarativeChart::componentComplete() |
|
251 | void DeclarativeChart::componentComplete() | |
252 | { |
|
252 | { | |
253 | foreach(QObject *child, children()) { |
|
253 | foreach(QObject *child, children()) { | |
254 | if (qobject_cast<QAbstractSeries *>(child)) { |
|
254 | if (qobject_cast<QAbstractSeries *>(child)) { | |
255 | // qDebug() << "DeclarativeChart::componentComplete(), add: " << child; |
|
255 | // qDebug() << "DeclarativeChart::componentComplete(), add: " << child; | |
256 | // TODO: how about optional y-axis? |
|
256 | // TODO: how about optional y-axis? | |
257 | m_chart->addSeries(qobject_cast<QAbstractSeries *>(child)); |
|
257 | m_chart->addSeries(qobject_cast<QAbstractSeries *>(child)); | |
258 | }else if(qobject_cast<QAbstractAxis *>(child)){ |
|
258 | }else if(qobject_cast<QAbstractAxis *>(child)){ | |
259 |
|
259 | |||
260 | } |
|
260 | } | |
261 | } |
|
261 | } | |
262 | QDeclarativeItem::componentComplete(); |
|
262 | QDeclarativeItem::componentComplete(); | |
263 | } |
|
263 | } | |
264 |
|
264 | |||
265 | void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) |
|
265 | void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) | |
266 | { |
|
266 | { | |
267 | // qDebug() << "DeclarativeChart::geometryChanged" << newGeometry.width() << newGeometry.height(); |
|
267 | // qDebug() << "DeclarativeChart::geometryChanged" << newGeometry.width() << newGeometry.height(); | |
268 | if (newGeometry.isValid()) { |
|
268 | if (newGeometry.isValid()) { | |
269 | if (newGeometry.width() > 0 && newGeometry.height() > 0) { |
|
269 | if (newGeometry.width() > 0 && newGeometry.height() > 0) { | |
270 | m_chart->resize(newGeometry.width(), newGeometry.height()); |
|
270 | m_chart->resize(newGeometry.width(), newGeometry.height()); | |
271 | } |
|
271 | } | |
272 | } |
|
272 | } | |
273 | QDeclarativeItem::geometryChanged(newGeometry, oldGeometry); |
|
273 | QDeclarativeItem::geometryChanged(newGeometry, oldGeometry); | |
274 | } |
|
274 | } | |
275 |
|
275 | |||
276 | void DeclarativeChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
276 | void DeclarativeChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
277 | { |
|
277 | { | |
278 | Q_UNUSED(option) |
|
278 | Q_UNUSED(option) | |
279 | Q_UNUSED(widget) |
|
279 | Q_UNUSED(widget) | |
280 |
|
280 | |||
281 | // TODO: optimized? |
|
281 | // TODO: optimized? | |
282 | painter->setRenderHint(QPainter::Antialiasing, true); |
|
282 | painter->setRenderHint(QPainter::Antialiasing, true); | |
283 | } |
|
283 | } | |
284 |
|
284 | |||
285 | void DeclarativeChart::setTheme(DeclarativeChart::Theme theme) |
|
285 | void DeclarativeChart::setTheme(DeclarativeChart::Theme theme) | |
286 | { |
|
286 | { | |
287 | QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme; |
|
287 | QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme; | |
288 | if (chartTheme != m_chart->theme()) |
|
288 | if (chartTheme != m_chart->theme()) | |
289 | m_chart->setTheme(chartTheme); |
|
289 | m_chart->setTheme(chartTheme); | |
290 | } |
|
290 | } | |
291 |
|
291 | |||
292 | DeclarativeChart::Theme DeclarativeChart::theme() |
|
292 | DeclarativeChart::Theme DeclarativeChart::theme() | |
293 | { |
|
293 | { | |
294 | return (DeclarativeChart::Theme) m_chart->theme(); |
|
294 | return (DeclarativeChart::Theme) m_chart->theme(); | |
295 | } |
|
295 | } | |
296 |
|
296 | |||
297 | void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations) |
|
297 | void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations) | |
298 | { |
|
298 | { | |
299 | QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations; |
|
299 | QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations; | |
300 | if (animationOptions != m_chart->animationOptions()) |
|
300 | if (animationOptions != m_chart->animationOptions()) | |
301 | m_chart->setAnimationOptions(animationOptions); |
|
301 | m_chart->setAnimationOptions(animationOptions); | |
302 | } |
|
302 | } | |
303 |
|
303 | |||
304 | DeclarativeChart::Animation DeclarativeChart::animationOptions() |
|
304 | DeclarativeChart::Animation DeclarativeChart::animationOptions() | |
305 | { |
|
305 | { | |
306 | if (m_chart->animationOptions().testFlag(QChart::AllAnimations)) |
|
306 | if (m_chart->animationOptions().testFlag(QChart::AllAnimations)) | |
307 | return DeclarativeChart::AllAnimations; |
|
307 | return DeclarativeChart::AllAnimations; | |
308 | else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations)) |
|
308 | else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations)) | |
309 | return DeclarativeChart::GridAxisAnimations; |
|
309 | return DeclarativeChart::GridAxisAnimations; | |
310 | else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations)) |
|
310 | else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations)) | |
311 | return DeclarativeChart::SeriesAnimations; |
|
311 | return DeclarativeChart::SeriesAnimations; | |
312 | else |
|
312 | else | |
313 | return DeclarativeChart::NoAnimation; |
|
313 | return DeclarativeChart::NoAnimation; | |
314 | } |
|
314 | } | |
315 |
|
315 | |||
316 | void DeclarativeChart::setTitle(QString title) |
|
316 | void DeclarativeChart::setTitle(QString title) | |
317 | { |
|
317 | { | |
318 | if (title != m_chart->title()) |
|
318 | if (title != m_chart->title()) | |
319 | m_chart->setTitle(title); |
|
319 | m_chart->setTitle(title); | |
320 | } |
|
320 | } | |
321 | QString DeclarativeChart::title() |
|
321 | QString DeclarativeChart::title() | |
322 | { |
|
322 | { | |
323 | return m_chart->title(); |
|
323 | return m_chart->title(); | |
324 | } |
|
324 | } | |
325 |
|
325 | |||
326 | QAbstractAxis *DeclarativeChart::axisX(QAbstractSeries *series) |
|
326 | QAbstractAxis *DeclarativeChart::axisX(QAbstractSeries *series) | |
327 | { |
|
327 | { | |
328 | return m_chart->axisX(series); |
|
328 | return m_chart->axisX(series); | |
329 | } |
|
329 | } | |
330 |
|
330 | |||
331 | QAbstractAxis *DeclarativeChart::axisY(QAbstractSeries *series) |
|
331 | QAbstractAxis *DeclarativeChart::axisY(QAbstractSeries *series) | |
332 | { |
|
332 | { | |
333 | return m_chart->axisY(series); |
|
333 | return m_chart->axisY(series); | |
334 | } |
|
334 | } | |
335 |
|
335 | |||
336 | QLegend *DeclarativeChart::legend() |
|
336 | QLegend *DeclarativeChart::legend() | |
337 | { |
|
337 | { | |
338 | return m_chart->legend(); |
|
338 | return m_chart->legend(); | |
339 | } |
|
339 | } | |
340 |
|
340 | |||
341 | void DeclarativeChart::setTitleColor(QColor color) |
|
341 | void DeclarativeChart::setTitleColor(QColor color) | |
342 | { |
|
342 | { | |
343 | QBrush b = m_chart->titleBrush(); |
|
343 | QBrush b = m_chart->titleBrush(); | |
344 | if (color != b.color()) { |
|
344 | if (color != b.color()) { | |
345 | b.setColor(color); |
|
345 | b.setColor(color); | |
346 | m_chart->setTitleBrush(b); |
|
346 | m_chart->setTitleBrush(b); | |
347 | emit titleColorChanged(color); |
|
347 | emit titleColorChanged(color); | |
348 | } |
|
348 | } | |
349 | } |
|
349 | } | |
350 |
|
350 | |||
351 | QFont DeclarativeChart::titleFont() const |
|
351 | QFont DeclarativeChart::titleFont() const | |
352 | { |
|
352 | { | |
353 | return m_chart->titleFont(); |
|
353 | return m_chart->titleFont(); | |
354 | } |
|
354 | } | |
355 |
|
355 | |||
356 | void DeclarativeChart::setTitleFont(const QFont& font) |
|
356 | void DeclarativeChart::setTitleFont(const QFont& font) | |
357 | { |
|
357 | { | |
358 | m_chart->setTitleFont(font); |
|
358 | m_chart->setTitleFont(font); | |
359 | } |
|
359 | } | |
360 |
|
360 | |||
361 | QColor DeclarativeChart::titleColor() |
|
361 | QColor DeclarativeChart::titleColor() | |
362 | { |
|
362 | { | |
363 | return m_chart->titleBrush().color(); |
|
363 | return m_chart->titleBrush().color(); | |
364 | } |
|
364 | } | |
365 |
|
365 | |||
366 | void DeclarativeChart::setBackgroundColor(QColor color) |
|
366 | void DeclarativeChart::setBackgroundColor(QColor color) | |
367 | { |
|
367 | { | |
368 | QBrush b = m_chart->backgroundBrush(); |
|
368 | QBrush b = m_chart->backgroundBrush(); | |
369 | if (b.style() != Qt::SolidPattern || color != b.color()) { |
|
369 | if (b.style() != Qt::SolidPattern || color != b.color()) { | |
370 | b.setStyle(Qt::SolidPattern); |
|
370 | b.setStyle(Qt::SolidPattern); | |
371 | b.setColor(color); |
|
371 | b.setColor(color); | |
372 | m_chart->setBackgroundBrush(b); |
|
372 | m_chart->setBackgroundBrush(b); | |
373 | emit backgroundColorChanged(); |
|
373 | emit backgroundColorChanged(); | |
374 | } |
|
374 | } | |
375 | } |
|
375 | } | |
376 |
|
376 | |||
377 | QColor DeclarativeChart::backgroundColor() |
|
377 | QColor DeclarativeChart::backgroundColor() | |
378 | { |
|
378 | { | |
379 | return m_chart->backgroundBrush().color(); |
|
379 | return m_chart->backgroundBrush().color(); | |
380 | } |
|
380 | } | |
381 |
|
381 | |||
382 | int DeclarativeChart::count() |
|
382 | int DeclarativeChart::count() | |
383 | { |
|
383 | { | |
384 | return m_chart->series().count(); |
|
384 | return m_chart->series().count(); | |
385 | } |
|
385 | } | |
386 |
|
386 | |||
387 | void DeclarativeChart::setDropShadowEnabled(bool enabled) |
|
387 | void DeclarativeChart::setDropShadowEnabled(bool enabled) | |
388 | { |
|
388 | { | |
389 | if (enabled != m_chart->isDropShadowEnabled()) { |
|
389 | if (enabled != m_chart->isDropShadowEnabled()) { | |
390 | m_chart->setDropShadowEnabled(enabled); |
|
390 | m_chart->setDropShadowEnabled(enabled); | |
391 | dropShadowEnabledChanged(enabled); |
|
391 | dropShadowEnabledChanged(enabled); | |
392 | } |
|
392 | } | |
393 | } |
|
393 | } | |
394 |
|
394 | |||
395 | bool DeclarativeChart::dropShadowEnabled() |
|
395 | bool DeclarativeChart::dropShadowEnabled() | |
396 | { |
|
396 | { | |
397 | return m_chart->isDropShadowEnabled(); |
|
397 | return m_chart->isDropShadowEnabled(); | |
398 | } |
|
398 | } | |
399 |
|
399 | |||
400 | qreal DeclarativeChart::topMargin() |
|
400 | qreal DeclarativeChart::topMargin() | |
401 | { |
|
401 | { | |
402 | return m_chart->margins().top(); |
|
402 | return m_chart->margins().top(); | |
403 | } |
|
403 | } | |
404 |
|
404 | |||
405 | qreal DeclarativeChart::bottomMargin() |
|
405 | qreal DeclarativeChart::bottomMargin() | |
406 | { |
|
406 | { | |
407 | return m_chart->margins().bottom(); |
|
407 | return m_chart->margins().bottom(); | |
408 | } |
|
408 | } | |
409 |
|
409 | |||
410 | qreal DeclarativeChart::leftMargin() |
|
410 | qreal DeclarativeChart::leftMargin() | |
411 | { |
|
411 | { | |
412 | return m_chart->margins().left(); |
|
412 | return m_chart->margins().left(); | |
413 | } |
|
413 | } | |
414 |
|
414 | |||
415 | qreal DeclarativeChart::rightMargin() |
|
415 | qreal DeclarativeChart::rightMargin() | |
416 | { |
|
416 | { | |
417 | return m_chart->margins().right(); |
|
417 | return m_chart->margins().right(); | |
418 | } |
|
418 | } | |
419 |
|
419 | |||
420 | void DeclarativeChart::zoom(qreal factor) |
|
420 | void DeclarativeChart::zoom(qreal factor) | |
421 | { |
|
421 | { | |
422 | m_chart->zoom(factor); |
|
422 | m_chart->zoom(factor); | |
423 | } |
|
423 | } | |
424 |
|
424 | |||
425 | void DeclarativeChart::scrollLeft(qreal pixels) |
|
425 | void DeclarativeChart::scrollLeft(qreal pixels) | |
426 | { |
|
426 | { | |
427 | m_chart->scroll(pixels, 0); |
|
427 | m_chart->scroll(pixels, 0); | |
428 | } |
|
428 | } | |
429 |
|
429 | |||
430 | void DeclarativeChart::scrollRight(qreal pixels) |
|
430 | void DeclarativeChart::scrollRight(qreal pixels) | |
431 | { |
|
431 | { | |
432 | m_chart->scroll(-pixels, 0); |
|
432 | m_chart->scroll(-pixels, 0); | |
433 | } |
|
433 | } | |
434 |
|
434 | |||
435 | void DeclarativeChart::scrollUp(qreal pixels) |
|
435 | void DeclarativeChart::scrollUp(qreal pixels) | |
436 | { |
|
436 | { | |
437 | m_chart->scroll(0, pixels); |
|
437 | m_chart->scroll(0, pixels); | |
438 | } |
|
438 | } | |
439 |
|
439 | |||
440 | void DeclarativeChart::scrollDown(qreal pixels) |
|
440 | void DeclarativeChart::scrollDown(qreal pixels) | |
441 | { |
|
441 | { | |
442 | m_chart->scroll(0, -pixels); |
|
442 | m_chart->scroll(0, -pixels); | |
443 | } |
|
443 | } | |
444 |
|
444 | |||
445 | QAbstractSeries *DeclarativeChart::series(int index) |
|
445 | QAbstractSeries *DeclarativeChart::series(int index) | |
446 | { |
|
446 | { | |
447 | if (index < m_chart->series().count()) { |
|
447 | if (index < m_chart->series().count()) { | |
448 | return m_chart->series().at(index); |
|
448 | return m_chart->series().at(index); | |
449 | } |
|
449 | } | |
450 | return 0; |
|
450 | return 0; | |
451 | } |
|
451 | } | |
452 |
|
452 | |||
453 | QAbstractSeries *DeclarativeChart::series(QString seriesName) |
|
453 | QAbstractSeries *DeclarativeChart::series(QString seriesName) | |
454 | { |
|
454 | { | |
455 | foreach(QAbstractSeries *series, m_chart->series()) { |
|
455 | foreach(QAbstractSeries *series, m_chart->series()) { | |
456 | if (series->name() == seriesName) |
|
456 | if (series->name() == seriesName) | |
457 | return series; |
|
457 | return series; | |
458 | } |
|
458 | } | |
459 | return 0; |
|
459 | return 0; | |
460 | } |
|
460 | } | |
461 |
|
461 | |||
462 | QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name) |
|
462 | QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name) | |
463 | { |
|
463 | { | |
464 | QAbstractSeries *series = 0; |
|
464 | QAbstractSeries *series = 0; | |
465 | switch (type) { |
|
465 | switch (type) { | |
466 | case DeclarativeChart::SeriesTypeLine: |
|
466 | case DeclarativeChart::SeriesTypeLine: | |
467 | series = new DeclarativeLineSeries(); |
|
467 | series = new DeclarativeLineSeries(); | |
468 | break; |
|
468 | break; | |
469 | case DeclarativeChart::SeriesTypeArea: |
|
469 | case DeclarativeChart::SeriesTypeArea: | |
470 | series = new DeclarativeAreaSeries(); |
|
470 | series = new DeclarativeAreaSeries(); | |
471 | break; |
|
471 | break; | |
472 | case DeclarativeChart::SeriesTypeStackedBar: |
|
472 | case DeclarativeChart::SeriesTypeStackedBar: | |
473 | // TODO |
|
473 | // TODO | |
474 | break; |
|
474 | break; | |
475 | case DeclarativeChart::SeriesTypePercentBar: |
|
475 | case DeclarativeChart::SeriesTypePercentBar: | |
476 | // TODO |
|
476 | // TODO | |
477 | break; |
|
477 | break; | |
478 | case DeclarativeChart::SeriesTypeBar: |
|
478 | case DeclarativeChart::SeriesTypeBar: | |
479 | series = new DeclarativeBarSeries(); |
|
479 | series = new DeclarativeBarSeries(); | |
480 | break; |
|
480 | break; | |
481 | case DeclarativeChart::SeriesTypePie: |
|
481 | case DeclarativeChart::SeriesTypePie: | |
482 | series = new DeclarativePieSeries(); |
|
482 | series = new DeclarativePieSeries(); | |
483 | break; |
|
483 | break; | |
484 | case DeclarativeChart::SeriesTypeScatter: |
|
484 | case DeclarativeChart::SeriesTypeScatter: | |
485 | series = new DeclarativeScatterSeries(); |
|
485 | series = new DeclarativeScatterSeries(); | |
486 | break; |
|
486 | break; | |
487 | case DeclarativeChart::SeriesTypeSpline: |
|
487 | case DeclarativeChart::SeriesTypeSpline: | |
488 | series = new DeclarativeSplineSeries(); |
|
488 | series = new DeclarativeSplineSeries(); | |
489 | break; |
|
489 | break; | |
490 | default: |
|
490 | default: | |
491 | qWarning() << "Illegal series type"; |
|
491 | qWarning() << "Illegal series type"; | |
492 | } |
|
492 | } | |
493 | series->setName(name); |
|
493 | series->setName(name); | |
494 | m_chart->addSeries(series); |
|
494 | m_chart->addSeries(series); | |
495 | m_chart->createDefaultAxes(); |
|
495 | m_chart->createDefaultAxes(); | |
496 | return series; |
|
496 | return series; | |
497 | } |
|
497 | } | |
498 |
|
498 | |||
499 | void DeclarativeChart::setAxisX(QAbstractAxis* axis, QAbstractSeries *series) |
|
499 | void DeclarativeChart::setAxisX(QAbstractAxis* axis, QAbstractSeries *series) | |
500 | { |
|
500 | { | |
501 | m_chart->setAxisX(axis,series); |
|
501 | m_chart->setAxisX(axis,series); | |
502 | } |
|
502 | } | |
503 |
|
503 | |||
504 | void DeclarativeChart::setAxisY(QAbstractAxis* axis, QAbstractSeries *series) |
|
504 | void DeclarativeChart::setAxisY(QAbstractAxis* axis, QAbstractSeries *series) | |
505 | { |
|
505 | { | |
506 | m_chart->setAxisY(axis,series); |
|
506 | m_chart->setAxisY(axis,series); | |
507 | } |
|
507 | } | |
508 |
|
508 | |||
509 | void DeclarativeChart::createDefaultAxes() |
|
509 | void DeclarativeChart::createDefaultAxes() | |
510 | { |
|
510 | { | |
511 | m_chart->createDefaultAxes(); |
|
511 | m_chart->createDefaultAxes(); | |
512 | } |
|
512 | } | |
513 |
|
513 | |||
514 | #include "moc_declarativechart.cpp" |
|
514 | #include "moc_declarativechart.cpp" | |
515 |
|
515 | |||
516 | QTCOMMERCIALCHART_END_NAMESPACE |
|
516 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now