@@ -1,498 +1,504 | |||||
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 "qcategoriesaxis.h" |
|
29 | #include "qcategoriesaxis.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 Axis::min, Axis::max |
|
168 | \sa Axis::min, Axis::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 Axis::min, Axis::max |
|
174 | \sa Axis::min, Axis::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 Axis::min, Axis::max |
|
180 | \sa Axis::min, Axis::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 Axis::min, Axis::max |
|
186 | \sa Axis::min, Axis::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 | bool createAxis = true; | |||
253 | foreach(QObject *child, children()) { |
|
254 | foreach(QObject *child, children()) { | |
254 | if (qobject_cast<QAbstractSeries *>(child)) { |
|
255 | if (qobject_cast<QAbstractSeries *>(child)) { | |
255 | // qDebug() << "DeclarativeChart::componentComplete(), add: " << child; |
|
256 | // qDebug() << "DeclarativeChart::componentComplete(), add: " << child; | |
256 | // TODO: how about optional y-axis? |
|
257 | // TODO: how about optional y-axis? | |
257 | m_chart->addSeries(qobject_cast<QAbstractSeries *>(child)); |
|
258 | m_chart->addSeries(qobject_cast<QAbstractSeries *>(child)); | |
|
259 | }else if(qobject_cast<QAbstractAxis *>(child)){ | |||
|
260 | createAxis = false; | |||
258 | } |
|
261 | } | |
259 | } |
|
262 | } | |
|
263 | ||||
|
264 | if(createAxis) m_chart->createDefaultAxes(); | |||
|
265 | ||||
260 | QDeclarativeItem::componentComplete(); |
|
266 | QDeclarativeItem::componentComplete(); | |
261 | } |
|
267 | } | |
262 |
|
268 | |||
263 | void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) |
|
269 | void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) | |
264 | { |
|
270 | { | |
265 | // qDebug() << "DeclarativeChart::geometryChanged" << newGeometry.width() << newGeometry.height(); |
|
271 | // qDebug() << "DeclarativeChart::geometryChanged" << newGeometry.width() << newGeometry.height(); | |
266 | if (newGeometry.isValid()) { |
|
272 | if (newGeometry.isValid()) { | |
267 | if (newGeometry.width() > 0 && newGeometry.height() > 0) { |
|
273 | if (newGeometry.width() > 0 && newGeometry.height() > 0) { | |
268 | m_chart->resize(newGeometry.width(), newGeometry.height()); |
|
274 | m_chart->resize(newGeometry.width(), newGeometry.height()); | |
269 | } |
|
275 | } | |
270 | } |
|
276 | } | |
271 | QDeclarativeItem::geometryChanged(newGeometry, oldGeometry); |
|
277 | QDeclarativeItem::geometryChanged(newGeometry, oldGeometry); | |
272 | } |
|
278 | } | |
273 |
|
279 | |||
274 | void DeclarativeChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
280 | void DeclarativeChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
275 | { |
|
281 | { | |
276 | Q_UNUSED(option) |
|
282 | Q_UNUSED(option) | |
277 | Q_UNUSED(widget) |
|
283 | Q_UNUSED(widget) | |
278 |
|
284 | |||
279 | // TODO: optimized? |
|
285 | // TODO: optimized? | |
280 | painter->setRenderHint(QPainter::Antialiasing, true); |
|
286 | painter->setRenderHint(QPainter::Antialiasing, true); | |
281 | } |
|
287 | } | |
282 |
|
288 | |||
283 | void DeclarativeChart::setTheme(DeclarativeChart::Theme theme) |
|
289 | void DeclarativeChart::setTheme(DeclarativeChart::Theme theme) | |
284 | { |
|
290 | { | |
285 | QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme; |
|
291 | QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme; | |
286 | if (chartTheme != m_chart->theme()) |
|
292 | if (chartTheme != m_chart->theme()) | |
287 | m_chart->setTheme(chartTheme); |
|
293 | m_chart->setTheme(chartTheme); | |
288 | } |
|
294 | } | |
289 |
|
295 | |||
290 | DeclarativeChart::Theme DeclarativeChart::theme() |
|
296 | DeclarativeChart::Theme DeclarativeChart::theme() | |
291 | { |
|
297 | { | |
292 | return (DeclarativeChart::Theme) m_chart->theme(); |
|
298 | return (DeclarativeChart::Theme) m_chart->theme(); | |
293 | } |
|
299 | } | |
294 |
|
300 | |||
295 | void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations) |
|
301 | void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations) | |
296 | { |
|
302 | { | |
297 | QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations; |
|
303 | QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations; | |
298 | if (animationOptions != m_chart->animationOptions()) |
|
304 | if (animationOptions != m_chart->animationOptions()) | |
299 | m_chart->setAnimationOptions(animationOptions); |
|
305 | m_chart->setAnimationOptions(animationOptions); | |
300 | } |
|
306 | } | |
301 |
|
307 | |||
302 | DeclarativeChart::Animation DeclarativeChart::animationOptions() |
|
308 | DeclarativeChart::Animation DeclarativeChart::animationOptions() | |
303 | { |
|
309 | { | |
304 | if (m_chart->animationOptions().testFlag(QChart::AllAnimations)) |
|
310 | if (m_chart->animationOptions().testFlag(QChart::AllAnimations)) | |
305 | return DeclarativeChart::AllAnimations; |
|
311 | return DeclarativeChart::AllAnimations; | |
306 | else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations)) |
|
312 | else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations)) | |
307 | return DeclarativeChart::GridAxisAnimations; |
|
313 | return DeclarativeChart::GridAxisAnimations; | |
308 | else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations)) |
|
314 | else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations)) | |
309 | return DeclarativeChart::SeriesAnimations; |
|
315 | return DeclarativeChart::SeriesAnimations; | |
310 | else |
|
316 | else | |
311 | return DeclarativeChart::NoAnimation; |
|
317 | return DeclarativeChart::NoAnimation; | |
312 | } |
|
318 | } | |
313 |
|
319 | |||
314 | void DeclarativeChart::setTitle(QString title) |
|
320 | void DeclarativeChart::setTitle(QString title) | |
315 | { |
|
321 | { | |
316 | if (title != m_chart->title()) |
|
322 | if (title != m_chart->title()) | |
317 | m_chart->setTitle(title); |
|
323 | m_chart->setTitle(title); | |
318 | } |
|
324 | } | |
319 | QString DeclarativeChart::title() |
|
325 | QString DeclarativeChart::title() | |
320 | { |
|
326 | { | |
321 | return m_chart->title(); |
|
327 | return m_chart->title(); | |
322 | } |
|
328 | } | |
323 |
|
329 | |||
324 | QAbstractAxis *DeclarativeChart::axisX(QAbstractSeries *series) |
|
330 | QAbstractAxis *DeclarativeChart::axisX(QAbstractSeries *series) | |
325 | { |
|
331 | { | |
326 | return m_chart->axisX(series); |
|
332 | return m_chart->axisX(series); | |
327 | } |
|
333 | } | |
328 |
|
334 | |||
329 | QAbstractAxis *DeclarativeChart::axisY(QAbstractSeries *series) |
|
335 | QAbstractAxis *DeclarativeChart::axisY(QAbstractSeries *series) | |
330 | { |
|
336 | { | |
331 | return m_chart->axisY(series); |
|
337 | return m_chart->axisY(series); | |
332 | } |
|
338 | } | |
333 |
|
339 | |||
334 | QLegend *DeclarativeChart::legend() |
|
340 | QLegend *DeclarativeChart::legend() | |
335 | { |
|
341 | { | |
336 | return m_chart->legend(); |
|
342 | return m_chart->legend(); | |
337 | } |
|
343 | } | |
338 |
|
344 | |||
339 | void DeclarativeChart::setTitleColor(QColor color) |
|
345 | void DeclarativeChart::setTitleColor(QColor color) | |
340 | { |
|
346 | { | |
341 | QBrush b = m_chart->titleBrush(); |
|
347 | QBrush b = m_chart->titleBrush(); | |
342 | if (color != b.color()) { |
|
348 | if (color != b.color()) { | |
343 | b.setColor(color); |
|
349 | b.setColor(color); | |
344 | m_chart->setTitleBrush(b); |
|
350 | m_chart->setTitleBrush(b); | |
345 | emit titleColorChanged(color); |
|
351 | emit titleColorChanged(color); | |
346 | } |
|
352 | } | |
347 | } |
|
353 | } | |
348 |
|
354 | |||
349 | QFont DeclarativeChart::titleFont() const |
|
355 | QFont DeclarativeChart::titleFont() const | |
350 | { |
|
356 | { | |
351 | return m_chart->titleFont(); |
|
357 | return m_chart->titleFont(); | |
352 | } |
|
358 | } | |
353 |
|
359 | |||
354 | void DeclarativeChart::setTitleFont(const QFont& font) |
|
360 | void DeclarativeChart::setTitleFont(const QFont& font) | |
355 | { |
|
361 | { | |
356 | m_chart->setTitleFont(font); |
|
362 | m_chart->setTitleFont(font); | |
357 | } |
|
363 | } | |
358 |
|
364 | |||
359 | QColor DeclarativeChart::titleColor() |
|
365 | QColor DeclarativeChart::titleColor() | |
360 | { |
|
366 | { | |
361 | return m_chart->titleBrush().color(); |
|
367 | return m_chart->titleBrush().color(); | |
362 | } |
|
368 | } | |
363 |
|
369 | |||
364 | void DeclarativeChart::setBackgroundColor(QColor color) |
|
370 | void DeclarativeChart::setBackgroundColor(QColor color) | |
365 | { |
|
371 | { | |
366 | QBrush b = m_chart->backgroundBrush(); |
|
372 | QBrush b = m_chart->backgroundBrush(); | |
367 | if (b.style() != Qt::SolidPattern || color != b.color()) { |
|
373 | if (b.style() != Qt::SolidPattern || color != b.color()) { | |
368 | b.setStyle(Qt::SolidPattern); |
|
374 | b.setStyle(Qt::SolidPattern); | |
369 | b.setColor(color); |
|
375 | b.setColor(color); | |
370 | m_chart->setBackgroundBrush(b); |
|
376 | m_chart->setBackgroundBrush(b); | |
371 | emit backgroundColorChanged(); |
|
377 | emit backgroundColorChanged(); | |
372 | } |
|
378 | } | |
373 | } |
|
379 | } | |
374 |
|
380 | |||
375 | QColor DeclarativeChart::backgroundColor() |
|
381 | QColor DeclarativeChart::backgroundColor() | |
376 | { |
|
382 | { | |
377 | return m_chart->backgroundBrush().color(); |
|
383 | return m_chart->backgroundBrush().color(); | |
378 | } |
|
384 | } | |
379 |
|
385 | |||
380 | int DeclarativeChart::count() |
|
386 | int DeclarativeChart::count() | |
381 | { |
|
387 | { | |
382 | return m_chart->series().count(); |
|
388 | return m_chart->series().count(); | |
383 | } |
|
389 | } | |
384 |
|
390 | |||
385 | void DeclarativeChart::setDropShadowEnabled(bool enabled) |
|
391 | void DeclarativeChart::setDropShadowEnabled(bool enabled) | |
386 | { |
|
392 | { | |
387 | if (enabled != m_chart->isDropShadowEnabled()) { |
|
393 | if (enabled != m_chart->isDropShadowEnabled()) { | |
388 | m_chart->setDropShadowEnabled(enabled); |
|
394 | m_chart->setDropShadowEnabled(enabled); | |
389 | dropShadowEnabledChanged(enabled); |
|
395 | dropShadowEnabledChanged(enabled); | |
390 | } |
|
396 | } | |
391 | } |
|
397 | } | |
392 |
|
398 | |||
393 | bool DeclarativeChart::dropShadowEnabled() |
|
399 | bool DeclarativeChart::dropShadowEnabled() | |
394 | { |
|
400 | { | |
395 | return m_chart->isDropShadowEnabled(); |
|
401 | return m_chart->isDropShadowEnabled(); | |
396 | } |
|
402 | } | |
397 |
|
403 | |||
398 | qreal DeclarativeChart::topMargin() |
|
404 | qreal DeclarativeChart::topMargin() | |
399 | { |
|
405 | { | |
400 | return m_chart->margins().top(); |
|
406 | return m_chart->margins().top(); | |
401 | } |
|
407 | } | |
402 |
|
408 | |||
403 | qreal DeclarativeChart::bottomMargin() |
|
409 | qreal DeclarativeChart::bottomMargin() | |
404 | { |
|
410 | { | |
405 | return m_chart->margins().bottom(); |
|
411 | return m_chart->margins().bottom(); | |
406 | } |
|
412 | } | |
407 |
|
413 | |||
408 | qreal DeclarativeChart::leftMargin() |
|
414 | qreal DeclarativeChart::leftMargin() | |
409 | { |
|
415 | { | |
410 | return m_chart->margins().left(); |
|
416 | return m_chart->margins().left(); | |
411 | } |
|
417 | } | |
412 |
|
418 | |||
413 | qreal DeclarativeChart::rightMargin() |
|
419 | qreal DeclarativeChart::rightMargin() | |
414 | { |
|
420 | { | |
415 | return m_chart->margins().right(); |
|
421 | return m_chart->margins().right(); | |
416 | } |
|
422 | } | |
417 |
|
423 | |||
418 | void DeclarativeChart::zoom(qreal factor) |
|
424 | void DeclarativeChart::zoom(qreal factor) | |
419 | { |
|
425 | { | |
420 | m_chart->zoom(factor); |
|
426 | m_chart->zoom(factor); | |
421 | } |
|
427 | } | |
422 |
|
428 | |||
423 | void DeclarativeChart::scrollLeft(qreal pixels) |
|
429 | void DeclarativeChart::scrollLeft(qreal pixels) | |
424 | { |
|
430 | { | |
425 | m_chart->scroll(pixels, 0); |
|
431 | m_chart->scroll(pixels, 0); | |
426 | } |
|
432 | } | |
427 |
|
433 | |||
428 | void DeclarativeChart::scrollRight(qreal pixels) |
|
434 | void DeclarativeChart::scrollRight(qreal pixels) | |
429 | { |
|
435 | { | |
430 | m_chart->scroll(-pixels, 0); |
|
436 | m_chart->scroll(-pixels, 0); | |
431 | } |
|
437 | } | |
432 |
|
438 | |||
433 | void DeclarativeChart::scrollUp(qreal pixels) |
|
439 | void DeclarativeChart::scrollUp(qreal pixels) | |
434 | { |
|
440 | { | |
435 | m_chart->scroll(0, pixels); |
|
441 | m_chart->scroll(0, pixels); | |
436 | } |
|
442 | } | |
437 |
|
443 | |||
438 | void DeclarativeChart::scrollDown(qreal pixels) |
|
444 | void DeclarativeChart::scrollDown(qreal pixels) | |
439 | { |
|
445 | { | |
440 | m_chart->scroll(0, -pixels); |
|
446 | m_chart->scroll(0, -pixels); | |
441 | } |
|
447 | } | |
442 |
|
448 | |||
443 | QAbstractSeries *DeclarativeChart::series(int index) |
|
449 | QAbstractSeries *DeclarativeChart::series(int index) | |
444 | { |
|
450 | { | |
445 | if (index < m_chart->series().count()) { |
|
451 | if (index < m_chart->series().count()) { | |
446 | return m_chart->series().at(index); |
|
452 | return m_chart->series().at(index); | |
447 | } |
|
453 | } | |
448 | return 0; |
|
454 | return 0; | |
449 | } |
|
455 | } | |
450 |
|
456 | |||
451 | QAbstractSeries *DeclarativeChart::series(QString seriesName) |
|
457 | QAbstractSeries *DeclarativeChart::series(QString seriesName) | |
452 | { |
|
458 | { | |
453 | foreach(QAbstractSeries *series, m_chart->series()) { |
|
459 | foreach(QAbstractSeries *series, m_chart->series()) { | |
454 | if (series->name() == seriesName) |
|
460 | if (series->name() == seriesName) | |
455 | return series; |
|
461 | return series; | |
456 | } |
|
462 | } | |
457 | return 0; |
|
463 | return 0; | |
458 | } |
|
464 | } | |
459 |
|
465 | |||
460 | QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name) |
|
466 | QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name) | |
461 | { |
|
467 | { | |
462 | QAbstractSeries *series = 0; |
|
468 | QAbstractSeries *series = 0; | |
463 | switch (type) { |
|
469 | switch (type) { | |
464 | case DeclarativeChart::SeriesTypeLine: |
|
470 | case DeclarativeChart::SeriesTypeLine: | |
465 | series = new DeclarativeLineSeries(); |
|
471 | series = new DeclarativeLineSeries(); | |
466 | break; |
|
472 | break; | |
467 | case DeclarativeChart::SeriesTypeArea: |
|
473 | case DeclarativeChart::SeriesTypeArea: | |
468 | series = new DeclarativeAreaSeries(); |
|
474 | series = new DeclarativeAreaSeries(); | |
469 | break; |
|
475 | break; | |
470 | case DeclarativeChart::SeriesTypeStackedBar: |
|
476 | case DeclarativeChart::SeriesTypeStackedBar: | |
471 | // TODO |
|
477 | // TODO | |
472 | break; |
|
478 | break; | |
473 | case DeclarativeChart::SeriesTypePercentBar: |
|
479 | case DeclarativeChart::SeriesTypePercentBar: | |
474 | // TODO |
|
480 | // TODO | |
475 | break; |
|
481 | break; | |
476 | case DeclarativeChart::SeriesTypeBar: |
|
482 | case DeclarativeChart::SeriesTypeBar: | |
477 | series = new DeclarativeBarSeries(); |
|
483 | series = new DeclarativeBarSeries(); | |
478 | break; |
|
484 | break; | |
479 | case DeclarativeChart::SeriesTypePie: |
|
485 | case DeclarativeChart::SeriesTypePie: | |
480 | series = new DeclarativePieSeries(); |
|
486 | series = new DeclarativePieSeries(); | |
481 | break; |
|
487 | break; | |
482 | case DeclarativeChart::SeriesTypeScatter: |
|
488 | case DeclarativeChart::SeriesTypeScatter: | |
483 | series = new DeclarativeScatterSeries(); |
|
489 | series = new DeclarativeScatterSeries(); | |
484 | break; |
|
490 | break; | |
485 | case DeclarativeChart::SeriesTypeSpline: |
|
491 | case DeclarativeChart::SeriesTypeSpline: | |
486 | series = new DeclarativeSplineSeries(); |
|
492 | series = new DeclarativeSplineSeries(); | |
487 | break; |
|
493 | break; | |
488 | default: |
|
494 | default: | |
489 | qWarning() << "Illegal series type"; |
|
495 | qWarning() << "Illegal series type"; | |
490 | } |
|
496 | } | |
491 | series->setName(name); |
|
497 | series->setName(name); | |
492 | m_chart->addSeries(series); |
|
498 | m_chart->addSeries(series); | |
493 | return series; |
|
499 | return series; | |
494 | } |
|
500 | } | |
495 |
|
501 | |||
496 | #include "moc_declarativechart.cpp" |
|
502 | #include "moc_declarativechart.cpp" | |
497 |
|
503 | |||
498 | QTCOMMERCIALCHART_END_NAMESPACE |
|
504 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now