@@ -1,737 +1,727 | |||||
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 "qchart_p.h" |
|
35 | #include "qchart_p.h" | |
36 |
|
36 | |||
37 | #ifndef QT_ON_ARM |
|
37 | #ifndef QT_ON_ARM | |
38 | #include "qdatetimeaxis.h" |
|
38 | #include "qdatetimeaxis.h" | |
39 | #endif |
|
39 | #endif | |
40 |
|
40 | |||
41 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
41 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
42 |
|
42 | |||
43 | /*! |
|
43 | /*! | |
44 | \qmlclass ChartView DeclarativeChart |
|
44 | \qmlclass ChartView DeclarativeChart | |
45 |
|
45 | |||
46 | ChartView element is the parent that is responsible for showing different chart series types. |
|
46 | ChartView element is the parent that is responsible for showing different chart series types. | |
47 |
|
47 | |||
48 | The following QML shows how to create a simple chart with one pie series: |
|
48 | The following QML shows how to create a simple chart with one pie series: | |
49 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 1 |
|
49 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 1 | |
50 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2 |
|
50 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2 | |
51 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 3 |
|
51 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 3 | |
52 |
|
52 | |||
53 | \beginfloatleft |
|
53 | \beginfloatleft | |
54 | \image examples_qmlpiechart.png |
|
54 | \image examples_qmlpiechart.png | |
55 | \endfloat |
|
55 | \endfloat | |
56 | \clearfloat |
|
56 | \clearfloat | |
57 | */ |
|
57 | */ | |
58 |
|
58 | |||
59 | /*! |
|
59 | /*! | |
60 | \qmlproperty Theme ChartView::theme |
|
60 | \qmlproperty Theme ChartView::theme | |
61 | Theme defines the visual appearance of the chart, including for example colors, fonts, line |
|
61 | Theme defines the visual appearance of the chart, including for example colors, fonts, line | |
62 | widths and chart background. |
|
62 | widths and chart background. | |
63 | */ |
|
63 | */ | |
64 |
|
64 | |||
65 | /*! |
|
65 | /*! | |
66 | \qmlproperty Animation ChartView::animation |
|
66 | \qmlproperty Animation ChartView::animationOptions | |
67 | Animation configuration of the chart. One of ChartView.NoAnimation, ChartView.GridAxisAnimations, |
|
67 | Animation configuration of the chart. One of ChartView.NoAnimation, ChartView.GridAxisAnimations, | |
68 | ChartView.SeriesAnimations or ChartView.AllAnimations. |
|
68 | ChartView.SeriesAnimations or ChartView.AllAnimations. | |
69 | */ |
|
69 | */ | |
70 |
|
70 | |||
71 | /*! |
|
71 | /*! | |
72 | \qmlproperty Font ChartView::titleFont |
|
72 | \qmlproperty Font ChartView::titleFont | |
73 | The title font of the chart |
|
73 | The title font of the chart | |
74 |
|
74 | |||
75 | See the \l {Font} {QML Font Element} for detailed documentation. |
|
75 | See the \l {Font} {QML Font Element} for detailed documentation. | |
76 | */ |
|
76 | */ | |
77 |
|
77 | |||
78 | /*! |
|
78 | /*! | |
79 | \qmlproperty string ChartView::title |
|
79 | \qmlproperty string ChartView::title | |
80 | The title of the chart, shown on top of the chart. |
|
80 | The title of the chart, shown on top of the chart. | |
81 | \sa ChartView::titleColor |
|
81 | \sa ChartView::titleColor | |
82 | */ |
|
82 | */ | |
83 |
|
83 | |||
84 | /*! |
|
84 | /*! | |
85 |
\qmlproperty |
|
85 | \qmlproperty color ChartView::titleColor | |
86 | The color of the title text. |
|
86 | The color of the title text. | |
87 | */ |
|
87 | */ | |
88 |
|
88 | |||
89 | /*! |
|
89 | /*! | |
90 | \qmlproperty Axis ChartView::axisX |
|
|||
91 | The x-axis of the chart. |
|
|||
92 | */ |
|
|||
93 |
|
||||
94 | /*! |
|
|||
95 | \qmlproperty Axis ChartView::axisY |
|
|||
96 | The default y-axis of the chart. |
|
|||
97 | */ |
|
|||
98 |
|
||||
99 | /*! |
|
|||
100 | \qmlproperty Legend ChartView::legend |
|
90 | \qmlproperty Legend ChartView::legend | |
101 | 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. | |
102 | */ |
|
92 | */ | |
103 |
|
93 | |||
104 | /*! |
|
94 | /*! | |
105 | \qmlproperty int ChartView::count |
|
95 | \qmlproperty int ChartView::count | |
106 | The count of series added to the chart. |
|
96 | The count of series added to the chart. | |
107 | */ |
|
97 | */ | |
108 |
|
98 | |||
109 | /*! |
|
99 | /*! | |
110 | \qmlproperty color ChartView::backgroundColor |
|
100 | \qmlproperty color ChartView::backgroundColor | |
111 | 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. | |
112 | \sa ChartView::theme |
|
102 | \sa ChartView::theme | |
113 | */ |
|
103 | */ | |
114 |
|
104 | |||
115 | /*! |
|
105 | /*! | |
116 | \qmlproperty bool ChartView::dropShadowEnabled |
|
106 | \qmlproperty bool ChartView::dropShadowEnabled | |
117 | 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. | |
118 | */ |
|
108 | */ | |
119 |
|
109 | |||
120 | /*! |
|
110 | /*! | |
121 | \qmlproperty real ChartView::topMargin |
|
111 | \qmlproperty real ChartView::topMargin | |
122 | Deprecated. Use minimumMargins and plotArea instead. |
|
112 | Deprecated. Use minimumMargins and plotArea instead. | |
123 | */ |
|
113 | */ | |
124 |
|
114 | |||
125 | /*! |
|
115 | /*! | |
126 | \qmlproperty real ChartView::bottomMargin |
|
116 | \qmlproperty real ChartView::bottomMargin | |
127 | Deprecated. Use minimumMargins and plotArea instead. |
|
117 | Deprecated. Use minimumMargins and plotArea instead. | |
128 | */ |
|
118 | */ | |
129 |
|
119 | |||
130 | /*! |
|
120 | /*! | |
131 | \qmlproperty real ChartView::leftMargin |
|
121 | \qmlproperty real ChartView::leftMargin | |
132 | Deprecated. Use minimumMargins and plotArea instead. |
|
122 | Deprecated. Use minimumMargins and plotArea instead. | |
133 | */ |
|
123 | */ | |
134 |
|
124 | |||
135 | /*! |
|
125 | /*! | |
136 | \qmlproperty real ChartView::rightMargin |
|
126 | \qmlproperty real ChartView::rightMargin | |
137 | Deprecated. Use minimumMargins and plotArea instead. |
|
127 | Deprecated. Use minimumMargins and plotArea instead. | |
138 | */ |
|
128 | */ | |
139 |
|
129 | |||
140 | /*! |
|
130 | /*! | |
141 | \qmlproperty Margins ChartView::minimumMargins |
|
131 | \qmlproperty Margins ChartView::minimumMargins | |
142 | The minimum margins allowed between the outer bounds and the plotArea of the ChartView. Margins |
|
132 | The minimum margins allowed between the outer bounds and the plotArea of the ChartView. Margins | |
143 | area of ChartView is used for drawing title, axes and legend. Please note that setting the |
|
133 | area of ChartView is used for drawing title, axes and legend. Please note that setting the | |
144 | properties of minimumMargins may be bigger than the defined value, depending on other ChartView |
|
134 | properties of minimumMargins may be bigger than the defined value, depending on other ChartView | |
145 | properties that affect it's layout. If you need to know the actual plotting area used at any |
|
135 | properties that affect it's layout. If you need to know the actual plotting area used at any | |
146 | given time, you can check ChartView::plotArea instead. |
|
136 | given time, you can check ChartView::plotArea instead. | |
147 | */ |
|
137 | */ | |
148 |
|
138 | |||
149 | /*! |
|
139 | /*! | |
150 | \qmlproperty rect ChartView::plotArea |
|
140 | \qmlproperty rect ChartView::plotArea | |
151 | The area on the ChartView that is used for drawing series. This is the ChartView rect without the |
|
141 | The area on the ChartView that is used for drawing series. This is the ChartView rect without the | |
152 | margins. |
|
142 | margins. | |
153 | \sa ChartView::minimumMargins |
|
143 | \sa ChartView::minimumMargins | |
154 | */ |
|
144 | */ | |
155 |
|
145 | |||
156 | /*! |
|
146 | /*! | |
157 | \qmlmethod AbstractSeries ChartView::series(int index) |
|
147 | \qmlmethod AbstractSeries ChartView::series(int index) | |
158 | Returns the series with \a index on the chart. This allows you to loop through the series of a chart together with |
|
148 | Returns the series with \a index on the chart. This allows you to loop through the series of a chart together with | |
159 | the count property of the chart. |
|
149 | the count property of the chart. | |
160 | */ |
|
150 | */ | |
161 |
|
151 | |||
162 | /*! |
|
152 | /*! | |
163 | \qmlmethod AbstractSeries ChartView::series(string name) |
|
153 | \qmlmethod AbstractSeries ChartView::series(string name) | |
164 | Returns the first series on the chart with \a name. If there is no series with that name, returns null. |
|
154 | Returns the first series on the chart with \a name. If there is no series with that name, returns null. | |
165 | */ |
|
155 | */ | |
166 |
|
156 | |||
167 | /*! |
|
157 | /*! | |
168 | \qmlmethod AbstractSeries ChartView::createSeries(SeriesType type, string name, AbstractAxis axisX, AbstractAxis axisY) |
|
158 | \qmlmethod AbstractSeries ChartView::createSeries(SeriesType type, string name, AbstractAxis axisX, AbstractAxis axisY) | |
169 | Creates a series object of \a type to the chart with name \a name, optional axis \a axisX and |
|
159 | Creates a series object of \a type to the chart with name \a name, optional axis \a axisX and | |
170 | optional axis \a axisY. For example: |
|
160 | optional axis \a axisY. For example: | |
171 | \code |
|
161 | \code | |
172 | // lineSeries is a LineSeries object that has already been added to the ChartView; re-use it's axes |
|
162 | // lineSeries is a LineSeries object that has already been added to the ChartView; re-use it's axes | |
173 | var myAxisX = chartView.axisX(lineSeries); |
|
163 | var myAxisX = chartView.axisX(lineSeries); | |
174 | var myAxisY = chartView.axisY(lineSeries); |
|
164 | var myAxisY = chartView.axisY(lineSeries); | |
175 | var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter series", myAxisX, myAxisY); |
|
165 | var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter series", myAxisX, myAxisY); | |
176 | \endcode |
|
166 | \endcode | |
177 | */ |
|
167 | */ | |
178 |
|
168 | |||
179 | /*! |
|
169 | /*! | |
180 | \qmlmethod ChartView::removeSeries(AbstractSeries series) |
|
170 | \qmlmethod ChartView::removeSeries(AbstractSeries series) | |
181 | Removes the \a series from the chart. The series object is also destroyed. |
|
171 | Removes the \a series from the chart. The series object is also destroyed. | |
182 | */ |
|
172 | */ | |
183 |
|
173 | |||
184 | /*! |
|
174 | /*! | |
185 | \qmlmethod ChartView::removeAllSeries() |
|
175 | \qmlmethod ChartView::removeAllSeries() | |
186 | Removes all series from the chart. All the series objects are also destroyed. |
|
176 | Removes all series from the chart. All the series objects are also destroyed. | |
187 | */ |
|
177 | */ | |
188 |
|
178 | |||
189 | /*! |
|
179 | /*! | |
190 | \qmlmethod Axis ChartView::axisX(AbstractSeries series) |
|
180 | \qmlmethod Axis ChartView::axisX(AbstractSeries series) | |
191 | The x-axis of the series. |
|
181 | The x-axis of the series. | |
192 | */ |
|
182 | */ | |
193 |
|
183 | |||
194 | /*! |
|
184 | /*! | |
195 | \qmlmethod Axis ChartView::axisY(AbstractSeries series) |
|
185 | \qmlmethod Axis ChartView::axisY(AbstractSeries series) | |
196 | The y-axis of the series. |
|
186 | The y-axis of the series. | |
197 | */ |
|
187 | */ | |
198 |
|
188 | |||
199 | /*! |
|
189 | /*! | |
200 | \qmlmethod ChartView::zoomY(real factor) |
|
190 | \qmlmethod ChartView::zoomY(real factor) | |
201 | Zooms in by \a factor on the center of the chart. |
|
191 | Zooms in by \a factor on the center of the chart. | |
202 | */ |
|
192 | */ | |
203 |
|
193 | |||
204 | /*! |
|
194 | /*! | |
205 | \qmlmethod ChartView::scrollLeft(real pixels) |
|
195 | \qmlmethod ChartView::scrollLeft(real pixels) | |
206 | Scrolls to left by \a pixels. This is a convenience function that suits for example for key navigation. |
|
196 | Scrolls to left by \a pixels. This is a convenience function that suits for example for key navigation. | |
207 | \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max |
|
197 | \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max | |
208 | */ |
|
198 | */ | |
209 |
|
199 | |||
210 | /*! |
|
200 | /*! | |
211 | \qmlmethod ChartView::scrollRight(real pixels) |
|
201 | \qmlmethod ChartView::scrollRight(real pixels) | |
212 | Scrolls to right by \a pixels. This is a convenience function that suits for example for key navigation. |
|
202 | Scrolls to right by \a pixels. This is a convenience function that suits for example for key navigation. | |
213 | \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max |
|
203 | \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max | |
214 | */ |
|
204 | */ | |
215 |
|
205 | |||
216 | /*! |
|
206 | /*! | |
217 | \qmlmethod ChartView::scrollUp(real pixels) |
|
207 | \qmlmethod ChartView::scrollUp(real pixels) | |
218 | Scrolls up by \a pixels. This is a convenience function that suits for example for key navigation. |
|
208 | Scrolls up by \a pixels. This is a convenience function that suits for example for key navigation. | |
219 | \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max |
|
209 | \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max | |
220 | */ |
|
210 | */ | |
221 |
|
211 | |||
222 | /*! |
|
212 | /*! | |
223 | \qmlmethod ChartView::scrollDown(real pixels) |
|
213 | \qmlmethod ChartView::scrollDown(real pixels) | |
224 | Scrolls down by \a pixels. This is a convenience function that suits for example for key navigation. |
|
214 | Scrolls down by \a pixels. This is a convenience function that suits for example for key navigation. | |
225 | \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max |
|
215 | \sa ValueAxis::min, ValueAxis::max, BarCategoryAxis::min, BarCategoryAxis::max | |
226 | */ |
|
216 | */ | |
227 |
|
217 | |||
228 | /*! |
|
218 | /*! | |
229 | \qmlsignal ChartView::onPlotAreaChanged(rect plotArea) |
|
219 | \qmlsignal ChartView::onPlotAreaChanged(rect plotArea) | |
230 | The plot area of the chart has changed. This may happen for example, if you modify minimumMargins |
|
220 | The plot area of the chart has changed. This may happen for example, if you modify minimumMargins | |
231 | or if you resize the chart, or if you modify font size related properties of the legend or chart |
|
221 | or if you resize the chart, or if you modify font size related properties of the legend or chart | |
232 | title. |
|
222 | title. | |
233 | */ |
|
223 | */ | |
234 |
|
224 | |||
235 | /*! |
|
225 | /*! | |
236 | \qmlsignal ChartView::seriesAdded(AbstractSeries series) |
|
226 | \qmlsignal ChartView::seriesAdded(AbstractSeries series) | |
237 | The \a series has been added to the chart. |
|
227 | The \a series has been added to the chart. | |
238 | */ |
|
228 | */ | |
239 |
|
229 | |||
240 | /*! |
|
230 | /*! | |
241 | \qmlsignal ChartView::seriesRemoved(AbstractSeries series) |
|
231 | \qmlsignal ChartView::seriesRemoved(AbstractSeries series) | |
242 | The \a series has been removed from the chart. Please note that \a series is no longer a valid |
|
232 | The \a series has been removed from the chart. Please note that \a series is no longer a valid | |
243 | object after the signal handler has completed. |
|
233 | object after the signal handler has completed. | |
244 | */ |
|
234 | */ | |
245 |
|
235 | |||
246 | DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent) |
|
236 | DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent) | |
247 | : QDeclarativeItem(parent), |
|
237 | : QDeclarativeItem(parent), | |
248 | m_chart(new QChart(this)) |
|
238 | m_chart(new QChart(this)) | |
249 | { |
|
239 | { | |
250 | setFlag(QGraphicsItem::ItemHasNoContents, false); |
|
240 | setFlag(QGraphicsItem::ItemHasNoContents, false); | |
251 | m_margins = new DeclarativeMargins(this); |
|
241 | m_margins = new DeclarativeMargins(this); | |
252 | m_margins->setTop(m_chart->margins().top()); |
|
242 | m_margins->setTop(m_chart->margins().top()); | |
253 | m_margins->setLeft(m_chart->margins().left()); |
|
243 | m_margins->setLeft(m_chart->margins().left()); | |
254 | m_margins->setRight(m_chart->margins().right()); |
|
244 | m_margins->setRight(m_chart->margins().right()); | |
255 | m_margins->setBottom(m_chart->margins().bottom()); |
|
245 | m_margins->setBottom(m_chart->margins().bottom()); | |
256 | connect(m_margins, SIGNAL(topChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int))); |
|
246 | connect(m_margins, SIGNAL(topChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int))); | |
257 | connect(m_margins, SIGNAL(bottomChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int))); |
|
247 | connect(m_margins, SIGNAL(bottomChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int))); | |
258 | connect(m_margins, SIGNAL(leftChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int))); |
|
248 | connect(m_margins, SIGNAL(leftChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int))); | |
259 | connect(m_margins, SIGNAL(rightChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int))); |
|
249 | connect(m_margins, SIGNAL(rightChanged(int,int,int,int)), this, SLOT(changeMinimumMargins(int,int,int,int))); | |
260 | connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*)), this, SLOT(handleSeriesAdded(QAbstractSeries*,Domain*))); |
|
250 | connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*)), this, SLOT(handleSeriesAdded(QAbstractSeries*,Domain*))); | |
261 | connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), this, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
251 | connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), this, SIGNAL(seriesRemoved(QAbstractSeries*))); | |
262 | } |
|
252 | } | |
263 |
|
253 | |||
264 | void DeclarativeChart::handleSeriesAdded(QAbstractSeries *series, Domain *domain) |
|
254 | void DeclarativeChart::handleSeriesAdded(QAbstractSeries *series, Domain *domain) | |
265 | { |
|
255 | { | |
266 | Q_UNUSED(domain) |
|
256 | Q_UNUSED(domain) | |
267 | emit seriesAdded(series); |
|
257 | emit seriesAdded(series); | |
268 | } |
|
258 | } | |
269 |
|
259 | |||
270 | void DeclarativeChart::changeMinimumMargins(int top, int bottom, int left, int right) |
|
260 | void DeclarativeChart::changeMinimumMargins(int top, int bottom, int left, int right) | |
271 | { |
|
261 | { | |
272 | m_chart->setMargins(QMargins(left, top, right, bottom)); |
|
262 | m_chart->setMargins(QMargins(left, top, right, bottom)); | |
273 | emit minimumMarginsChanged(); |
|
263 | emit minimumMarginsChanged(); | |
274 | emit plotAreaChanged(m_chart->plotArea()); |
|
264 | emit plotAreaChanged(m_chart->plotArea()); | |
275 | } |
|
265 | } | |
276 |
|
266 | |||
277 | DeclarativeChart::~DeclarativeChart() |
|
267 | DeclarativeChart::~DeclarativeChart() | |
278 | { |
|
268 | { | |
279 | delete m_chart; |
|
269 | delete m_chart; | |
280 | } |
|
270 | } | |
281 |
|
271 | |||
282 | void DeclarativeChart::childEvent(QChildEvent *event) |
|
272 | void DeclarativeChart::childEvent(QChildEvent *event) | |
283 | { |
|
273 | { | |
284 | if (event->type() == QEvent::ChildAdded) { |
|
274 | if (event->type() == QEvent::ChildAdded) { | |
285 | if (qobject_cast<QAbstractSeries *>(event->child())) { |
|
275 | if (qobject_cast<QAbstractSeries *>(event->child())) { | |
286 | m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child())); |
|
276 | m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child())); | |
287 | } |
|
277 | } | |
288 | } |
|
278 | } | |
289 | } |
|
279 | } | |
290 |
|
280 | |||
291 | void DeclarativeChart::componentComplete() |
|
281 | void DeclarativeChart::componentComplete() | |
292 | { |
|
282 | { | |
293 | foreach (QObject *child, children()) { |
|
283 | foreach (QObject *child, children()) { | |
294 | if (qobject_cast<QAbstractSeries *>(child)) { |
|
284 | if (qobject_cast<QAbstractSeries *>(child)) { | |
295 | // Add series to the chart |
|
285 | // Add series to the chart | |
296 | QAbstractSeries *series = qobject_cast<QAbstractSeries *>(child); |
|
286 | QAbstractSeries *series = qobject_cast<QAbstractSeries *>(child); | |
297 | m_chart->addSeries(series); |
|
287 | m_chart->addSeries(series); | |
298 |
|
288 | |||
299 | // Set optional user defined axes for the series and connect axis related signals |
|
289 | // Set optional user defined axes for the series and connect axis related signals | |
300 | if (qobject_cast<DeclarativeLineSeries *>(child)) { |
|
290 | if (qobject_cast<DeclarativeLineSeries *>(child)) { | |
301 | DeclarativeLineSeries *s = qobject_cast<DeclarativeLineSeries *>(child); |
|
291 | DeclarativeLineSeries *s = qobject_cast<DeclarativeLineSeries *>(child); | |
302 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
292 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); | |
303 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); |
|
293 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); | |
304 | setAxisX(s->axisX(), s); |
|
294 | setAxisX(s->axisX(), s); | |
305 | setAxisY(s->axisY(), s); |
|
295 | setAxisY(s->axisY(), s); | |
306 | } else if (qobject_cast<DeclarativeSplineSeries *>(child)) { |
|
296 | } else if (qobject_cast<DeclarativeSplineSeries *>(child)) { | |
307 | DeclarativeSplineSeries *s = qobject_cast<DeclarativeSplineSeries *>(child); |
|
297 | DeclarativeSplineSeries *s = qobject_cast<DeclarativeSplineSeries *>(child); | |
308 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
298 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); | |
309 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); |
|
299 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); | |
310 | setAxisX(s->axisX(), s); |
|
300 | setAxisX(s->axisX(), s); | |
311 | setAxisY(s->axisY(), s); |
|
301 | setAxisY(s->axisY(), s); | |
312 | } else if (qobject_cast<DeclarativeScatterSeries *>(child)) { |
|
302 | } else if (qobject_cast<DeclarativeScatterSeries *>(child)) { | |
313 | DeclarativeScatterSeries *s = qobject_cast<DeclarativeScatterSeries *>(child); |
|
303 | DeclarativeScatterSeries *s = qobject_cast<DeclarativeScatterSeries *>(child); | |
314 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
304 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); | |
315 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); |
|
305 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); | |
316 | setAxisX(s->axisX(), s); |
|
306 | setAxisX(s->axisX(), s); | |
317 | setAxisY(s->axisY(), s); |
|
307 | setAxisY(s->axisY(), s); | |
318 | } else if (qobject_cast<DeclarativeAreaSeries *>(child)) { |
|
308 | } else if (qobject_cast<DeclarativeAreaSeries *>(child)) { | |
319 | DeclarativeAreaSeries *s = qobject_cast<DeclarativeAreaSeries *>(child); |
|
309 | DeclarativeAreaSeries *s = qobject_cast<DeclarativeAreaSeries *>(child); | |
320 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
310 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); | |
321 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); |
|
311 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); | |
322 | setAxisX(s->axisX(), s); |
|
312 | setAxisX(s->axisX(), s); | |
323 | setAxisY(s->axisY(), s); |
|
313 | setAxisY(s->axisY(), s); | |
324 | } else if (qobject_cast<DeclarativeBarSeries *>(child)) { |
|
314 | } else if (qobject_cast<DeclarativeBarSeries *>(child)) { | |
325 | DeclarativeBarSeries *s = qobject_cast<DeclarativeBarSeries *>(child); |
|
315 | DeclarativeBarSeries *s = qobject_cast<DeclarativeBarSeries *>(child); | |
326 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
316 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); | |
327 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); |
|
317 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); | |
328 | setAxisX(s->axisX(), s); |
|
318 | setAxisX(s->axisX(), s); | |
329 | setAxisY(s->axisY(), s); |
|
319 | setAxisY(s->axisY(), s); | |
330 | } else if (qobject_cast<DeclarativeStackedBarSeries *>(child)) { |
|
320 | } else if (qobject_cast<DeclarativeStackedBarSeries *>(child)) { | |
331 | DeclarativeStackedBarSeries *s = qobject_cast<DeclarativeStackedBarSeries *>(child); |
|
321 | DeclarativeStackedBarSeries *s = qobject_cast<DeclarativeStackedBarSeries *>(child); | |
332 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
322 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); | |
333 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); |
|
323 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); | |
334 | setAxisX(s->axisX(), s); |
|
324 | setAxisX(s->axisX(), s); | |
335 | setAxisY(s->axisY(), s); |
|
325 | setAxisY(s->axisY(), s); | |
336 | } else if (qobject_cast<DeclarativePercentBarSeries *>(child)) { |
|
326 | } else if (qobject_cast<DeclarativePercentBarSeries *>(child)) { | |
337 | DeclarativePercentBarSeries *s = qobject_cast<DeclarativePercentBarSeries *>(child); |
|
327 | DeclarativePercentBarSeries *s = qobject_cast<DeclarativePercentBarSeries *>(child); | |
338 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
328 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); | |
339 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); |
|
329 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); | |
340 | setAxisX(s->axisX(), s); |
|
330 | setAxisX(s->axisX(), s); | |
341 | setAxisY(s->axisY(), s); |
|
331 | setAxisY(s->axisY(), s); | |
342 | } else if (qobject_cast<DeclarativeHorizontalBarSeries *>(child)) { |
|
332 | } else if (qobject_cast<DeclarativeHorizontalBarSeries *>(child)) { | |
343 | DeclarativeHorizontalBarSeries *s = qobject_cast<DeclarativeHorizontalBarSeries *>(child); |
|
333 | DeclarativeHorizontalBarSeries *s = qobject_cast<DeclarativeHorizontalBarSeries *>(child); | |
344 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
334 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); | |
345 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); |
|
335 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); | |
346 | setAxisX(s->axisX(), s); |
|
336 | setAxisX(s->axisX(), s); | |
347 | setAxisY(s->axisY(), s); |
|
337 | setAxisY(s->axisY(), s); | |
348 | } else if (qobject_cast<DeclarativeHorizontalStackedBarSeries *>(child)) { |
|
338 | } else if (qobject_cast<DeclarativeHorizontalStackedBarSeries *>(child)) { | |
349 | DeclarativeHorizontalStackedBarSeries *s = qobject_cast<DeclarativeHorizontalStackedBarSeries *>(child); |
|
339 | DeclarativeHorizontalStackedBarSeries *s = qobject_cast<DeclarativeHorizontalStackedBarSeries *>(child); | |
350 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
340 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); | |
351 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); |
|
341 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); | |
352 | setAxisX(s->axisX(), s); |
|
342 | setAxisX(s->axisX(), s); | |
353 | setAxisY(s->axisY(), s); |
|
343 | setAxisY(s->axisY(), s); | |
354 | } else if (qobject_cast<DeclarativeHorizontalPercentBarSeries *>(child)) { |
|
344 | } else if (qobject_cast<DeclarativeHorizontalPercentBarSeries *>(child)) { | |
355 | DeclarativeHorizontalPercentBarSeries *s = qobject_cast<DeclarativeHorizontalPercentBarSeries *>(child); |
|
345 | DeclarativeHorizontalPercentBarSeries *s = qobject_cast<DeclarativeHorizontalPercentBarSeries *>(child); | |
356 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); |
|
346 | connect(s, SIGNAL(axisXChanged(QAbstractAxis*)), this, SLOT(handleAxisXSet(QAbstractAxis*))); | |
357 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); |
|
347 | connect(s, SIGNAL(axisYChanged(QAbstractAxis*)), this, SLOT(handleAxisYSet(QAbstractAxis*))); | |
358 | setAxisX(s->axisX(), s); |
|
348 | setAxisX(s->axisX(), s); | |
359 | setAxisY(s->axisY(), s); |
|
349 | setAxisY(s->axisY(), s); | |
360 | } |
|
350 | } | |
361 | } |
|
351 | } | |
362 | } |
|
352 | } | |
363 |
|
353 | |||
364 | // Create the missing axes for the series that cannot be painted without axes |
|
354 | // Create the missing axes for the series that cannot be painted without axes | |
365 | foreach (QAbstractSeries *chartSeries, m_chart->series()) |
|
355 | foreach (QAbstractSeries *chartSeries, m_chart->series()) | |
366 | createDefaultAxes(chartSeries); |
|
356 | createDefaultAxes(chartSeries); | |
367 |
|
357 | |||
368 | QDeclarativeItem::componentComplete(); |
|
358 | QDeclarativeItem::componentComplete(); | |
369 | } |
|
359 | } | |
370 |
|
360 | |||
371 | void DeclarativeChart::handleAxisXSet(QAbstractAxis *axis) |
|
361 | void DeclarativeChart::handleAxisXSet(QAbstractAxis *axis) | |
372 | { |
|
362 | { | |
373 | // qDebug() << "DeclarativeChart::handleAxisXSet" << sender() << axis; |
|
363 | // qDebug() << "DeclarativeChart::handleAxisXSet" << sender() << axis; | |
374 | if (axis && qobject_cast<QAbstractSeries *>(sender())) |
|
364 | if (axis && qobject_cast<QAbstractSeries *>(sender())) | |
375 | m_chart->setAxisX(axis, qobject_cast<QAbstractSeries *>(sender())); |
|
365 | m_chart->setAxisX(axis, qobject_cast<QAbstractSeries *>(sender())); | |
376 | else |
|
366 | else | |
377 | qWarning() << "Trying to set axisX to null."; |
|
367 | qWarning() << "Trying to set axisX to null."; | |
378 | } |
|
368 | } | |
379 |
|
369 | |||
380 | void DeclarativeChart::handleAxisYSet(QAbstractAxis *axis) |
|
370 | void DeclarativeChart::handleAxisYSet(QAbstractAxis *axis) | |
381 | { |
|
371 | { | |
382 | // qDebug() << "DeclarativeChart::handleAxisYSet" << sender() << axis; |
|
372 | // qDebug() << "DeclarativeChart::handleAxisYSet" << sender() << axis; | |
383 | if (axis && qobject_cast<QAbstractSeries *>(sender())) |
|
373 | if (axis && qobject_cast<QAbstractSeries *>(sender())) | |
384 | m_chart->setAxisY(axis, qobject_cast<QAbstractSeries *>(sender())); |
|
374 | m_chart->setAxisY(axis, qobject_cast<QAbstractSeries *>(sender())); | |
385 | else |
|
375 | else | |
386 | qWarning() << "Trying to set axisY to null."; |
|
376 | qWarning() << "Trying to set axisY to null."; | |
387 | } |
|
377 | } | |
388 |
|
378 | |||
389 | void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) |
|
379 | void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) | |
390 | { |
|
380 | { | |
391 | // qDebug() << "DeclarativeChart::geometryChanged" << newGeometry.width() << newGeometry.height(); |
|
381 | // qDebug() << "DeclarativeChart::geometryChanged" << newGeometry.width() << newGeometry.height(); | |
392 | if (newGeometry.isValid()) { |
|
382 | if (newGeometry.isValid()) { | |
393 | if (newGeometry.width() > 0 && newGeometry.height() > 0) { |
|
383 | if (newGeometry.width() > 0 && newGeometry.height() > 0) { | |
394 | m_chart->resize(newGeometry.width(), newGeometry.height()); |
|
384 | m_chart->resize(newGeometry.width(), newGeometry.height()); | |
395 | } |
|
385 | } | |
396 | } |
|
386 | } | |
397 | QDeclarativeItem::geometryChanged(newGeometry, oldGeometry); |
|
387 | QDeclarativeItem::geometryChanged(newGeometry, oldGeometry); | |
398 |
|
388 | |||
399 | // It would be better to trigger the plotAreaChanged signal from QChart::plotAreaChanged or |
|
389 | // It would be better to trigger the plotAreaChanged signal from QChart::plotAreaChanged or | |
400 | // similar. Since that kind of a signal is not clearly needed in the C++ API the work-around is |
|
390 | // similar. Since that kind of a signal is not clearly needed in the C++ API the work-around is | |
401 | // to implement it here for the QML API purposes. |
|
391 | // to implement it here for the QML API purposes. | |
402 | emit plotAreaChanged(m_chart->plotArea()); |
|
392 | emit plotAreaChanged(m_chart->plotArea()); | |
403 | } |
|
393 | } | |
404 |
|
394 | |||
405 | void DeclarativeChart::setTheme(DeclarativeChart::Theme theme) |
|
395 | void DeclarativeChart::setTheme(DeclarativeChart::Theme theme) | |
406 | { |
|
396 | { | |
407 | QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme; |
|
397 | QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme; | |
408 | if (chartTheme != m_chart->theme()) |
|
398 | if (chartTheme != m_chart->theme()) | |
409 | m_chart->setTheme(chartTheme); |
|
399 | m_chart->setTheme(chartTheme); | |
410 | } |
|
400 | } | |
411 |
|
401 | |||
412 | DeclarativeChart::Theme DeclarativeChart::theme() |
|
402 | DeclarativeChart::Theme DeclarativeChart::theme() | |
413 | { |
|
403 | { | |
414 | return (DeclarativeChart::Theme) m_chart->theme(); |
|
404 | return (DeclarativeChart::Theme) m_chart->theme(); | |
415 | } |
|
405 | } | |
416 |
|
406 | |||
417 | void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations) |
|
407 | void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations) | |
418 | { |
|
408 | { | |
419 | QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations; |
|
409 | QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations; | |
420 | if (animationOptions != m_chart->animationOptions()) |
|
410 | if (animationOptions != m_chart->animationOptions()) | |
421 | m_chart->setAnimationOptions(animationOptions); |
|
411 | m_chart->setAnimationOptions(animationOptions); | |
422 | } |
|
412 | } | |
423 |
|
413 | |||
424 | DeclarativeChart::Animation DeclarativeChart::animationOptions() |
|
414 | DeclarativeChart::Animation DeclarativeChart::animationOptions() | |
425 | { |
|
415 | { | |
426 | if (m_chart->animationOptions().testFlag(QChart::AllAnimations)) |
|
416 | if (m_chart->animationOptions().testFlag(QChart::AllAnimations)) | |
427 | return DeclarativeChart::AllAnimations; |
|
417 | return DeclarativeChart::AllAnimations; | |
428 | else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations)) |
|
418 | else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations)) | |
429 | return DeclarativeChart::GridAxisAnimations; |
|
419 | return DeclarativeChart::GridAxisAnimations; | |
430 | else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations)) |
|
420 | else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations)) | |
431 | return DeclarativeChart::SeriesAnimations; |
|
421 | return DeclarativeChart::SeriesAnimations; | |
432 | else |
|
422 | else | |
433 | return DeclarativeChart::NoAnimation; |
|
423 | return DeclarativeChart::NoAnimation; | |
434 | } |
|
424 | } | |
435 |
|
425 | |||
436 | void DeclarativeChart::setTitle(QString title) |
|
426 | void DeclarativeChart::setTitle(QString title) | |
437 | { |
|
427 | { | |
438 | if (title != m_chart->title()) |
|
428 | if (title != m_chart->title()) | |
439 | m_chart->setTitle(title); |
|
429 | m_chart->setTitle(title); | |
440 | } |
|
430 | } | |
441 | QString DeclarativeChart::title() |
|
431 | QString DeclarativeChart::title() | |
442 | { |
|
432 | { | |
443 | return m_chart->title(); |
|
433 | return m_chart->title(); | |
444 | } |
|
434 | } | |
445 |
|
435 | |||
446 | QAbstractAxis *DeclarativeChart::axisX(QAbstractSeries *series) |
|
436 | QAbstractAxis *DeclarativeChart::axisX(QAbstractSeries *series) | |
447 | { |
|
437 | { | |
448 | return m_chart->axisX(series); |
|
438 | return m_chart->axisX(series); | |
449 | } |
|
439 | } | |
450 |
|
440 | |||
451 | QAbstractAxis *DeclarativeChart::axisY(QAbstractSeries *series) |
|
441 | QAbstractAxis *DeclarativeChart::axisY(QAbstractSeries *series) | |
452 | { |
|
442 | { | |
453 | return m_chart->axisY(series); |
|
443 | return m_chart->axisY(series); | |
454 | } |
|
444 | } | |
455 |
|
445 | |||
456 | QLegend *DeclarativeChart::legend() |
|
446 | QLegend *DeclarativeChart::legend() | |
457 | { |
|
447 | { | |
458 | return m_chart->legend(); |
|
448 | return m_chart->legend(); | |
459 | } |
|
449 | } | |
460 |
|
450 | |||
461 | void DeclarativeChart::setTitleColor(QColor color) |
|
451 | void DeclarativeChart::setTitleColor(QColor color) | |
462 | { |
|
452 | { | |
463 | QBrush b = m_chart->titleBrush(); |
|
453 | QBrush b = m_chart->titleBrush(); | |
464 | if (color != b.color()) { |
|
454 | if (color != b.color()) { | |
465 | b.setColor(color); |
|
455 | b.setColor(color); | |
466 | m_chart->setTitleBrush(b); |
|
456 | m_chart->setTitleBrush(b); | |
467 | emit titleColorChanged(color); |
|
457 | emit titleColorChanged(color); | |
468 | } |
|
458 | } | |
469 | } |
|
459 | } | |
470 |
|
460 | |||
471 | QFont DeclarativeChart::titleFont() const |
|
461 | QFont DeclarativeChart::titleFont() const | |
472 | { |
|
462 | { | |
473 | return m_chart->titleFont(); |
|
463 | return m_chart->titleFont(); | |
474 | } |
|
464 | } | |
475 |
|
465 | |||
476 | void DeclarativeChart::setTitleFont(const QFont &font) |
|
466 | void DeclarativeChart::setTitleFont(const QFont &font) | |
477 | { |
|
467 | { | |
478 | m_chart->setTitleFont(font); |
|
468 | m_chart->setTitleFont(font); | |
479 | } |
|
469 | } | |
480 |
|
470 | |||
481 | QColor DeclarativeChart::titleColor() |
|
471 | QColor DeclarativeChart::titleColor() | |
482 | { |
|
472 | { | |
483 | return m_chart->titleBrush().color(); |
|
473 | return m_chart->titleBrush().color(); | |
484 | } |
|
474 | } | |
485 |
|
475 | |||
486 | void DeclarativeChart::setBackgroundColor(QColor color) |
|
476 | void DeclarativeChart::setBackgroundColor(QColor color) | |
487 | { |
|
477 | { | |
488 | QBrush b = m_chart->backgroundBrush(); |
|
478 | QBrush b = m_chart->backgroundBrush(); | |
489 | if (b.style() != Qt::SolidPattern || color != b.color()) { |
|
479 | if (b.style() != Qt::SolidPattern || color != b.color()) { | |
490 | b.setStyle(Qt::SolidPattern); |
|
480 | b.setStyle(Qt::SolidPattern); | |
491 | b.setColor(color); |
|
481 | b.setColor(color); | |
492 | m_chart->setBackgroundBrush(b); |
|
482 | m_chart->setBackgroundBrush(b); | |
493 | emit backgroundColorChanged(); |
|
483 | emit backgroundColorChanged(); | |
494 | } |
|
484 | } | |
495 | } |
|
485 | } | |
496 |
|
486 | |||
497 | QColor DeclarativeChart::backgroundColor() |
|
487 | QColor DeclarativeChart::backgroundColor() | |
498 | { |
|
488 | { | |
499 | return m_chart->backgroundBrush().color(); |
|
489 | return m_chart->backgroundBrush().color(); | |
500 | } |
|
490 | } | |
501 |
|
491 | |||
502 | int DeclarativeChart::count() |
|
492 | int DeclarativeChart::count() | |
503 | { |
|
493 | { | |
504 | return m_chart->series().count(); |
|
494 | return m_chart->series().count(); | |
505 | } |
|
495 | } | |
506 |
|
496 | |||
507 | void DeclarativeChart::setDropShadowEnabled(bool enabled) |
|
497 | void DeclarativeChart::setDropShadowEnabled(bool enabled) | |
508 | { |
|
498 | { | |
509 | if (enabled != m_chart->isDropShadowEnabled()) { |
|
499 | if (enabled != m_chart->isDropShadowEnabled()) { | |
510 | m_chart->setDropShadowEnabled(enabled); |
|
500 | m_chart->setDropShadowEnabled(enabled); | |
511 | dropShadowEnabledChanged(enabled); |
|
501 | dropShadowEnabledChanged(enabled); | |
512 | } |
|
502 | } | |
513 | } |
|
503 | } | |
514 |
|
504 | |||
515 | bool DeclarativeChart::dropShadowEnabled() |
|
505 | bool DeclarativeChart::dropShadowEnabled() | |
516 | { |
|
506 | { | |
517 | return m_chart->isDropShadowEnabled(); |
|
507 | return m_chart->isDropShadowEnabled(); | |
518 | } |
|
508 | } | |
519 |
|
509 | |||
520 | qreal DeclarativeChart::topMargin() |
|
510 | qreal DeclarativeChart::topMargin() | |
521 | { |
|
511 | { | |
522 | qWarning() << "ChartView.topMargin is deprecated. Use minimumMargins and plotArea instead."; |
|
512 | qWarning() << "ChartView.topMargin is deprecated. Use minimumMargins and plotArea instead."; | |
523 | return m_chart->plotArea().top(); |
|
513 | return m_chart->plotArea().top(); | |
524 | } |
|
514 | } | |
525 |
|
515 | |||
526 | qreal DeclarativeChart::bottomMargin() |
|
516 | qreal DeclarativeChart::bottomMargin() | |
527 | { |
|
517 | { | |
528 |
|
518 | |||
529 | qWarning() << "ChartView.bottomMargin is deprecated. Use minimumMargins and plotArea instead."; |
|
519 | qWarning() << "ChartView.bottomMargin is deprecated. Use minimumMargins and plotArea instead."; | |
530 | return m_chart->plotArea().bottom(); |
|
520 | return m_chart->plotArea().bottom(); | |
531 | } |
|
521 | } | |
532 |
|
522 | |||
533 | qreal DeclarativeChart::leftMargin() |
|
523 | qreal DeclarativeChart::leftMargin() | |
534 | { |
|
524 | { | |
535 | qWarning() << "ChartView.leftMargin is deprecated. Use minimumMargins and plotArea instead."; |
|
525 | qWarning() << "ChartView.leftMargin is deprecated. Use minimumMargins and plotArea instead."; | |
536 | return m_chart->plotArea().left(); |
|
526 | return m_chart->plotArea().left(); | |
537 | } |
|
527 | } | |
538 |
|
528 | |||
539 | qreal DeclarativeChart::rightMargin() |
|
529 | qreal DeclarativeChart::rightMargin() | |
540 | { |
|
530 | { | |
541 | qWarning() << "ChartView.rightMargin is deprecated. Use minimumMargins and plotArea instead."; |
|
531 | qWarning() << "ChartView.rightMargin is deprecated. Use minimumMargins and plotArea instead."; | |
542 | return m_chart->plotArea().right(); |
|
532 | return m_chart->plotArea().right(); | |
543 | } |
|
533 | } | |
544 |
|
534 | |||
545 | void DeclarativeChart::zoom(qreal factor) |
|
535 | void DeclarativeChart::zoom(qreal factor) | |
546 | { |
|
536 | { | |
547 | m_chart->zoom(factor); |
|
537 | m_chart->zoom(factor); | |
548 | } |
|
538 | } | |
549 |
|
539 | |||
550 | void DeclarativeChart::scrollLeft(qreal pixels) |
|
540 | void DeclarativeChart::scrollLeft(qreal pixels) | |
551 | { |
|
541 | { | |
552 | m_chart->scroll(-pixels, 0); |
|
542 | m_chart->scroll(-pixels, 0); | |
553 | } |
|
543 | } | |
554 |
|
544 | |||
555 | void DeclarativeChart::scrollRight(qreal pixels) |
|
545 | void DeclarativeChart::scrollRight(qreal pixels) | |
556 | { |
|
546 | { | |
557 | m_chart->scroll(pixels, 0); |
|
547 | m_chart->scroll(pixels, 0); | |
558 | } |
|
548 | } | |
559 |
|
549 | |||
560 | void DeclarativeChart::scrollUp(qreal pixels) |
|
550 | void DeclarativeChart::scrollUp(qreal pixels) | |
561 | { |
|
551 | { | |
562 | m_chart->scroll(0, pixels); |
|
552 | m_chart->scroll(0, pixels); | |
563 | } |
|
553 | } | |
564 |
|
554 | |||
565 | void DeclarativeChart::scrollDown(qreal pixels) |
|
555 | void DeclarativeChart::scrollDown(qreal pixels) | |
566 | { |
|
556 | { | |
567 | m_chart->scroll(0, -pixels); |
|
557 | m_chart->scroll(0, -pixels); | |
568 | } |
|
558 | } | |
569 |
|
559 | |||
570 | QAbstractSeries *DeclarativeChart::series(int index) |
|
560 | QAbstractSeries *DeclarativeChart::series(int index) | |
571 | { |
|
561 | { | |
572 | if (index < m_chart->series().count()) { |
|
562 | if (index < m_chart->series().count()) { | |
573 | return m_chart->series().at(index); |
|
563 | return m_chart->series().at(index); | |
574 | } |
|
564 | } | |
575 | return 0; |
|
565 | return 0; | |
576 | } |
|
566 | } | |
577 |
|
567 | |||
578 | QAbstractSeries *DeclarativeChart::series(QString seriesName) |
|
568 | QAbstractSeries *DeclarativeChart::series(QString seriesName) | |
579 | { |
|
569 | { | |
580 | foreach (QAbstractSeries *series, m_chart->series()) { |
|
570 | foreach (QAbstractSeries *series, m_chart->series()) { | |
581 | if (series->name() == seriesName) |
|
571 | if (series->name() == seriesName) | |
582 | return series; |
|
572 | return series; | |
583 | } |
|
573 | } | |
584 | return 0; |
|
574 | return 0; | |
585 | } |
|
575 | } | |
586 |
|
576 | |||
587 | QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name) |
|
577 | QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name) | |
588 | { |
|
578 | { | |
589 | return createSeries(type, name, 0, 0); |
|
579 | return createSeries(type, name, 0, 0); | |
590 | } |
|
580 | } | |
591 |
|
581 | |||
592 | QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name, QAbstractAxis *axisX, QAbstractAxis *axisY) |
|
582 | QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name, QAbstractAxis *axisX, QAbstractAxis *axisY) | |
593 | { |
|
583 | { | |
594 | QAbstractSeries *series = 0; |
|
584 | QAbstractSeries *series = 0; | |
595 |
|
585 | |||
596 | switch (type) { |
|
586 | switch (type) { | |
597 | case DeclarativeChart::SeriesTypeLine: |
|
587 | case DeclarativeChart::SeriesTypeLine: | |
598 | series = new DeclarativeLineSeries(); |
|
588 | series = new DeclarativeLineSeries(); | |
599 | break; |
|
589 | break; | |
600 | case DeclarativeChart::SeriesTypeArea: |
|
590 | case DeclarativeChart::SeriesTypeArea: | |
601 | series = new DeclarativeAreaSeries(); |
|
591 | series = new DeclarativeAreaSeries(); | |
602 | break; |
|
592 | break; | |
603 | case DeclarativeChart::SeriesTypeStackedBar: |
|
593 | case DeclarativeChart::SeriesTypeStackedBar: | |
604 | series = new DeclarativeStackedBarSeries(); |
|
594 | series = new DeclarativeStackedBarSeries(); | |
605 | break; |
|
595 | break; | |
606 | case DeclarativeChart::SeriesTypePercentBar: |
|
596 | case DeclarativeChart::SeriesTypePercentBar: | |
607 | series = new DeclarativePercentBarSeries(); |
|
597 | series = new DeclarativePercentBarSeries(); | |
608 | break; |
|
598 | break; | |
609 | case DeclarativeChart::SeriesTypeBar: |
|
599 | case DeclarativeChart::SeriesTypeBar: | |
610 | series = new DeclarativeBarSeries(); |
|
600 | series = new DeclarativeBarSeries(); | |
611 | break; |
|
601 | break; | |
612 | case DeclarativeChart::SeriesTypeHorizontalBar: |
|
602 | case DeclarativeChart::SeriesTypeHorizontalBar: | |
613 | series = new DeclarativeHorizontalBarSeries(); |
|
603 | series = new DeclarativeHorizontalBarSeries(); | |
614 | break; |
|
604 | break; | |
615 | case DeclarativeChart::SeriesTypeHorizontalPercentBar: |
|
605 | case DeclarativeChart::SeriesTypeHorizontalPercentBar: | |
616 | series = new DeclarativeHorizontalPercentBarSeries(); |
|
606 | series = new DeclarativeHorizontalPercentBarSeries(); | |
617 | break; |
|
607 | break; | |
618 | case DeclarativeChart::SeriesTypeHorizontalStackedBar: |
|
608 | case DeclarativeChart::SeriesTypeHorizontalStackedBar: | |
619 | series = new DeclarativeHorizontalStackedBarSeries(); |
|
609 | series = new DeclarativeHorizontalStackedBarSeries(); | |
620 | break; |
|
610 | break; | |
621 | case DeclarativeChart::SeriesTypePie: |
|
611 | case DeclarativeChart::SeriesTypePie: | |
622 | series = new DeclarativePieSeries(); |
|
612 | series = new DeclarativePieSeries(); | |
623 | break; |
|
613 | break; | |
624 | case DeclarativeChart::SeriesTypeScatter: |
|
614 | case DeclarativeChart::SeriesTypeScatter: | |
625 | series = new DeclarativeScatterSeries(); |
|
615 | series = new DeclarativeScatterSeries(); | |
626 | break; |
|
616 | break; | |
627 | case DeclarativeChart::SeriesTypeSpline: |
|
617 | case DeclarativeChart::SeriesTypeSpline: | |
628 | series = new DeclarativeSplineSeries(); |
|
618 | series = new DeclarativeSplineSeries(); | |
629 | break; |
|
619 | break; | |
630 | default: |
|
620 | default: | |
631 | qWarning() << "Illegal series type"; |
|
621 | qWarning() << "Illegal series type"; | |
632 | } |
|
622 | } | |
633 |
|
623 | |||
634 | if (series) { |
|
624 | if (series) { | |
635 | series->setName(name); |
|
625 | series->setName(name); | |
636 | m_chart->addSeries(series); |
|
626 | m_chart->addSeries(series); | |
637 | // Set possible user defined axes |
|
627 | // Set possible user defined axes | |
638 | setAxisX(axisX, series); |
|
628 | setAxisX(axisX, series); | |
639 | setAxisY(axisY, series); |
|
629 | setAxisY(axisY, series); | |
640 | // Then create the missing axes |
|
630 | // Then create the missing axes | |
641 | createDefaultAxes(series); |
|
631 | createDefaultAxes(series); | |
642 | } |
|
632 | } | |
643 |
|
633 | |||
644 | return series; |
|
634 | return series; | |
645 | } |
|
635 | } | |
646 |
|
636 | |||
647 | void DeclarativeChart::removeSeries(QAbstractSeries *series) |
|
637 | void DeclarativeChart::removeSeries(QAbstractSeries *series) | |
648 | { |
|
638 | { | |
649 | if (series) |
|
639 | if (series) | |
650 | m_chart->removeSeries(series); |
|
640 | m_chart->removeSeries(series); | |
651 | else |
|
641 | else | |
652 | qWarning("removeSeries: cannot remove null"); |
|
642 | qWarning("removeSeries: cannot remove null"); | |
653 | } |
|
643 | } | |
654 |
|
644 | |||
655 | void DeclarativeChart::setAxisX(QAbstractAxis *axis, QAbstractSeries *series) |
|
645 | void DeclarativeChart::setAxisX(QAbstractAxis *axis, QAbstractSeries *series) | |
656 | { |
|
646 | { | |
657 | if (axis) |
|
647 | if (axis) | |
658 | m_chart->setAxisX(axis, series); |
|
648 | m_chart->setAxisX(axis, series); | |
659 | } |
|
649 | } | |
660 |
|
650 | |||
661 | void DeclarativeChart::setAxisY(QAbstractAxis *axis, QAbstractSeries *series) |
|
651 | void DeclarativeChart::setAxisY(QAbstractAxis *axis, QAbstractSeries *series) | |
662 | { |
|
652 | { | |
663 | if (axis) |
|
653 | if (axis) | |
664 | m_chart->setAxisY(axis, series); |
|
654 | m_chart->setAxisY(axis, series); | |
665 | } |
|
655 | } | |
666 |
|
656 | |||
667 | void DeclarativeChart::createDefaultAxes() |
|
657 | void DeclarativeChart::createDefaultAxes() | |
668 | { |
|
658 | { | |
669 | qWarning() << "ChartView.createDefaultAxes() is deprecated. Axes are created automatically."; |
|
659 | qWarning() << "ChartView.createDefaultAxes() is deprecated. Axes are created automatically."; | |
670 | } |
|
660 | } | |
671 |
|
661 | |||
672 | void DeclarativeChart::createDefaultAxes(QAbstractSeries *series) |
|
662 | void DeclarativeChart::createDefaultAxes(QAbstractSeries *series) | |
673 | { |
|
663 | { | |
674 | foreach (QAbstractSeries *s, m_chart->series()) { |
|
664 | foreach (QAbstractSeries *s, m_chart->series()) { | |
675 | // If there is already an x axis of the correct type, re-use it |
|
665 | // If there is already an x axis of the correct type, re-use it | |
676 | if (!m_chart->axisX(series) && s != series && m_chart->axisX(s) |
|
666 | if (!m_chart->axisX(series) && s != series && m_chart->axisX(s) | |
677 | && m_chart->axisX(s)->type() == series->d_ptr->defaultAxisType(Qt::Horizontal)) |
|
667 | && m_chart->axisX(s)->type() == series->d_ptr->defaultAxisType(Qt::Horizontal)) | |
678 | m_chart->setAxisX(m_chart->axisX(s), series); |
|
668 | m_chart->setAxisX(m_chart->axisX(s), series); | |
679 |
|
669 | |||
680 | // If there is already a y axis of the correct type, re-use it |
|
670 | // If there is already a y axis of the correct type, re-use it | |
681 | if (!m_chart->axisY(series) && s != series && m_chart->axisY(s) |
|
671 | if (!m_chart->axisY(series) && s != series && m_chart->axisY(s) | |
682 | && m_chart->axisY(s)->type() == series->d_ptr->defaultAxisType(Qt::Vertical)) |
|
672 | && m_chart->axisY(s)->type() == series->d_ptr->defaultAxisType(Qt::Vertical)) | |
683 | m_chart->setAxisY(m_chart->axisY(s), series); |
|
673 | m_chart->setAxisY(m_chart->axisY(s), series); | |
684 | } |
|
674 | } | |
685 |
|
675 | |||
686 | // If no x axis of correct type was found, create a new x axis based of default axis type |
|
676 | // If no x axis of correct type was found, create a new x axis based of default axis type | |
687 | if (!m_chart->axisX(series)) { |
|
677 | if (!m_chart->axisX(series)) { | |
688 | switch (series->d_ptr->defaultAxisType(Qt::Horizontal)) { |
|
678 | switch (series->d_ptr->defaultAxisType(Qt::Horizontal)) { | |
689 | case QAbstractAxis::AxisTypeValue: |
|
679 | case QAbstractAxis::AxisTypeValue: | |
690 | m_chart->setAxisX(new QValueAxis(this), series); |
|
680 | m_chart->setAxisX(new QValueAxis(this), series); | |
691 | break; |
|
681 | break; | |
692 | case QAbstractAxis::AxisTypeBarCategory: |
|
682 | case QAbstractAxis::AxisTypeBarCategory: | |
693 | m_chart->setAxisX(new QBarCategoryAxis(this), series); |
|
683 | m_chart->setAxisX(new QBarCategoryAxis(this), series); | |
694 | break; |
|
684 | break; | |
695 | case QAbstractAxis::AxisTypeCategory: |
|
685 | case QAbstractAxis::AxisTypeCategory: | |
696 | m_chart->setAxisX(new QCategoryAxis(this), series); |
|
686 | m_chart->setAxisX(new QCategoryAxis(this), series); | |
697 | break; |
|
687 | break; | |
698 | #ifndef QT_ON_ARM |
|
688 | #ifndef QT_ON_ARM | |
699 | case QAbstractAxis::AxisTypeDateTime: |
|
689 | case QAbstractAxis::AxisTypeDateTime: | |
700 | m_chart->setAxisX(new QDateTimeAxis(this), series); |
|
690 | m_chart->setAxisX(new QDateTimeAxis(this), series); | |
701 | break; |
|
691 | break; | |
702 | #endif |
|
692 | #endif | |
703 | default: |
|
693 | default: | |
704 | // Do nothing, assume AxisTypeNoAxis |
|
694 | // Do nothing, assume AxisTypeNoAxis | |
705 | break; |
|
695 | break; | |
706 | } |
|
696 | } | |
707 | } |
|
697 | } | |
708 |
|
698 | |||
709 | // If no y axis of correct type was found, create a new y axis based of default axis type |
|
699 | // If no y axis of correct type was found, create a new y axis based of default axis type | |
710 | if (!m_chart->axisY(series)) { |
|
700 | if (!m_chart->axisY(series)) { | |
711 | switch (series->d_ptr->defaultAxisType(Qt::Vertical)) { |
|
701 | switch (series->d_ptr->defaultAxisType(Qt::Vertical)) { | |
712 | case QAbstractAxis::AxisTypeValue: |
|
702 | case QAbstractAxis::AxisTypeValue: | |
713 | m_chart->setAxisY(new QValueAxis(this), series); |
|
703 | m_chart->setAxisY(new QValueAxis(this), series); | |
714 | break; |
|
704 | break; | |
715 | case QAbstractAxis::AxisTypeBarCategory: |
|
705 | case QAbstractAxis::AxisTypeBarCategory: | |
716 | m_chart->setAxisY(new QBarCategoryAxis(this), series); |
|
706 | m_chart->setAxisY(new QBarCategoryAxis(this), series); | |
717 | break; |
|
707 | break; | |
718 | case QAbstractAxis::AxisTypeCategory: |
|
708 | case QAbstractAxis::AxisTypeCategory: | |
719 | m_chart->setAxisY(new QCategoryAxis(this), series); |
|
709 | m_chart->setAxisY(new QCategoryAxis(this), series); | |
720 | break; |
|
710 | break; | |
721 | #ifndef QT_ON_ARM |
|
711 | #ifndef QT_ON_ARM | |
722 | case QAbstractAxis::AxisTypeDateTime: |
|
712 | case QAbstractAxis::AxisTypeDateTime: | |
723 | m_chart->setAxisY(new QDateTimeAxis(this), series); |
|
713 | m_chart->setAxisY(new QDateTimeAxis(this), series); | |
724 | break; |
|
714 | break; | |
725 | #endif |
|
715 | #endif | |
726 | default: |
|
716 | default: | |
727 | // Do nothing, assume AxisTypeNoAxis |
|
717 | // Do nothing, assume AxisTypeNoAxis | |
728 | break; |
|
718 | break; | |
729 | } |
|
719 | } | |
730 | } |
|
720 | } | |
731 |
|
721 | |||
732 | //qDebug() << "axis for series" << series << "x:" << m_chart->axisX(series) << "y:" << m_chart->axisY(series); |
|
722 | //qDebug() << "axis for series" << series << "x:" << m_chart->axisX(series) << "y:" << m_chart->axisY(series); | |
733 | } |
|
723 | } | |
734 |
|
724 | |||
735 | #include "moc_declarativechart.cpp" |
|
725 | #include "moc_declarativechart.cpp" | |
736 |
|
726 | |||
737 | QTCOMMERCIALCHART_END_NAMESPACE |
|
727 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,514 +1,514 | |||||
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 "qlegend.h" |
|
21 | #include "qlegend.h" | |
22 | #include "qlegend_p.h" |
|
22 | #include "qlegend_p.h" | |
23 | #include "qabstractseries.h" |
|
23 | #include "qabstractseries.h" | |
24 | #include "qabstractseries_p.h" |
|
24 | #include "qabstractseries_p.h" | |
25 | #include "qchart_p.h" |
|
25 | #include "qchart_p.h" | |
26 | #include "legendlayout_p.h" |
|
26 | #include "legendlayout_p.h" | |
27 | #include "legendmarker_p.h" |
|
27 | #include "legendmarker_p.h" | |
28 | #include "qxyseries.h" |
|
28 | #include "qxyseries.h" | |
29 | #include "qlineseries.h" |
|
29 | #include "qlineseries.h" | |
30 | #include "qareaseries.h" |
|
30 | #include "qareaseries.h" | |
31 | #include "qscatterseries.h" |
|
31 | #include "qscatterseries.h" | |
32 | #include "qsplineseries.h" |
|
32 | #include "qsplineseries.h" | |
33 | #include "qabstractbarseries.h" |
|
33 | #include "qabstractbarseries.h" | |
34 | #include "qstackedbarseries.h" |
|
34 | #include "qstackedbarseries.h" | |
35 | #include "qpercentbarseries.h" |
|
35 | #include "qpercentbarseries.h" | |
36 | #include "qbarset.h" |
|
36 | #include "qbarset.h" | |
37 | #include "qpieseries.h" |
|
37 | #include "qpieseries.h" | |
38 | #include "qpieseries_p.h" |
|
38 | #include "qpieseries_p.h" | |
39 | #include "qpieslice.h" |
|
39 | #include "qpieslice.h" | |
40 | #include "chartpresenter_p.h" |
|
40 | #include "chartpresenter_p.h" | |
41 | #include "chartlayout_p.h" |
|
41 | #include "chartlayout_p.h" | |
42 | #include <QPainter> |
|
42 | #include <QPainter> | |
43 | #include <QPen> |
|
43 | #include <QPen> | |
44 | #include <QTimer> |
|
44 | #include <QTimer> | |
45 | #include <QGraphicsSceneEvent> |
|
45 | #include <QGraphicsSceneEvent> | |
46 |
|
46 | |||
47 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
47 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
48 |
|
48 | |||
49 | /*! |
|
49 | /*! | |
50 | \class QLegend |
|
50 | \class QLegend | |
51 | \brief Legend object |
|
51 | \brief Legend object | |
52 | \mainclass |
|
52 | \mainclass | |
53 |
|
53 | |||
54 | QLegend is a graphical object, whics displays legend of the chart. Legend state is updated by QChart, when |
|
54 | QLegend is a graphical object, whics displays legend of the chart. Legend state is updated by QChart, when | |
55 | series have been changed. By default, legend is drawn by QChart, but user can set a new parent to legend and |
|
55 | series have been changed. By default, legend is drawn by QChart, but user can set a new parent to legend and | |
56 | handle the drawing manually. |
|
56 | handle the drawing manually. | |
57 | User isn't supposed to create or delete legend objects, but can reference it via QChart class. |
|
57 | User isn't supposed to create or delete legend objects, but can reference it via QChart class. | |
58 |
|
58 | |||
59 | \image examples_percentbarchart_legend.png |
|
59 | \image examples_percentbarchart_legend.png | |
60 |
|
60 | |||
61 | \sa QChart |
|
61 | \sa QChart | |
62 | */ |
|
62 | */ | |
63 | /*! |
|
63 | /*! | |
64 | \qmlclass Legend QLegend |
|
64 | \qmlclass Legend QLegend | |
65 | \brief Legend is part of QtCommercial Chart QML API. |
|
65 | \brief Legend is part of QtCommercial Chart QML API. | |
66 |
|
66 | |||
67 | Legend is a graphical object, whics displays legend of the chart. Legend state is updated by ChartView, when |
|
67 | Legend is a graphical object, whics displays legend of the chart. Legend state is updated by ChartView, when | |
68 | series have been changed. Legend is used via ChartView class. For example: |
|
68 | series have been changed. Legend is used via ChartView class. For example: | |
69 | \code |
|
69 | \code | |
70 | ChartView { |
|
70 | ChartView { | |
71 | legend.visible: true |
|
71 | legend.visible: true | |
72 | legend.alignment: Qt.AlignBottom |
|
72 | legend.alignment: Qt.AlignBottom | |
73 | // Add a few series... |
|
73 | // Add a few series... | |
74 | } |
|
74 | } | |
75 | \endcode |
|
75 | \endcode | |
76 |
|
76 | |||
77 | \image examples_percentbarchart_legend.png |
|
77 | \image examples_percentbarchart_legend.png | |
78 | */ |
|
78 | */ | |
79 |
|
79 | |||
80 | /*! |
|
80 | /*! | |
81 | \property QLegend::alignment |
|
81 | \property QLegend::alignment | |
82 | \brief The alignment of the legend. |
|
82 | \brief The alignment of the legend. | |
83 |
|
83 | |||
84 | Legend paints on the defined position in the chart. The following alignments are supported: |
|
84 | Legend paints on the defined position in the chart. The following alignments are supported: | |
85 | Qt::AlignTop, Qt::AlignBottom, Qt::AlignLeft, Qt::AlignRight. If you set more than one flag the result is undefined. |
|
85 | Qt::AlignTop, Qt::AlignBottom, Qt::AlignLeft, Qt::AlignRight. If you set more than one flag the result is undefined. | |
86 | */ |
|
86 | */ | |
87 | /*! |
|
87 | /*! | |
88 | \qmlproperty Qt.Alignment Legend::alignment |
|
88 | \qmlproperty Qt.Alignment Legend::alignment | |
89 | \brief The alignment of the legend. |
|
89 | \brief The alignment of the legend. | |
90 |
|
90 | |||
91 | Legend paints on the defined position in the chart. The following alignments are supported: |
|
91 | Legend paints on the defined position in the chart. The following alignments are supported: | |
92 | Qt.AlignTop, Qt.AlignBottom, Qt.AlignLeft, Qt.AlignRight. If you set more than one flag the result is undefined. |
|
92 | Qt.AlignTop, Qt.AlignBottom, Qt.AlignLeft, Qt.AlignRight. If you set more than one flag the result is undefined. | |
93 | */ |
|
93 | */ | |
94 |
|
94 | |||
95 | /*! |
|
95 | /*! | |
96 | \property QLegend::backgroundVisible |
|
96 | \property QLegend::backgroundVisible | |
97 | Whether the legend background is visible or not. |
|
97 | Whether the legend background is visible or not. | |
98 | */ |
|
98 | */ | |
99 | /*! |
|
99 | /*! | |
100 | \qmlproperty bool Legend::backgroundVisible |
|
100 | \qmlproperty bool Legend::backgroundVisible | |
101 | Whether the legend background is visible or not. |
|
101 | Whether the legend background is visible or not. | |
102 | */ |
|
102 | */ | |
103 |
|
103 | |||
104 | /*! |
|
104 | /*! | |
105 | \property QLegend::color |
|
105 | \property QLegend::color | |
106 | The color of the legend, i.e. the background (brush) color. Note that if you change the color |
|
106 | The color of the legend, i.e. the background (brush) color. Note that if you change the color | |
107 | of the legend, the style of the legend brush is set to Qt::SolidPattern. |
|
107 | of the legend, the style of the legend brush is set to Qt::SolidPattern. | |
108 | */ |
|
108 | */ | |
109 | /*! |
|
109 | /*! | |
110 | \qmlproperty color Legend::color |
|
110 | \qmlproperty color Legend::color | |
111 | The color of the legend, i.e. the background (brush) color. |
|
111 | The color of the legend, i.e. the background (brush) color. | |
112 | */ |
|
112 | */ | |
113 |
|
113 | |||
114 | /*! |
|
114 | /*! | |
115 | \property QLegend::borderColor |
|
115 | \property QLegend::borderColor | |
116 | The border color of the legend, i.e. the line color. |
|
116 | The border color of the legend, i.e. the line color. | |
117 | */ |
|
117 | */ | |
118 | /*! |
|
118 | /*! | |
119 | \qmlproperty color Legend::borderColor |
|
119 | \qmlproperty color Legend::borderColor | |
120 | The border color of the legend, i.e. the line color. |
|
120 | The border color of the legend, i.e. the line color. | |
121 | */ |
|
121 | */ | |
122 |
|
122 | |||
123 | /*! |
|
123 | /*! | |
124 | \property QLegend::font |
|
124 | \property QLegend::font | |
125 | The font of markers used by legend |
|
125 | The font of markers used by legend | |
126 | */ |
|
126 | */ | |
127 | /*! |
|
127 | /*! | |
128 |
\qmlproperty |
|
128 | \qmlproperty Font Legend::font | |
129 | The font of markers used by legend |
|
129 | The font of markers used by legend | |
130 | */ |
|
130 | */ | |
131 |
|
131 | |||
132 | /*! |
|
132 | /*! | |
133 | \property QLegend::labelColor |
|
133 | \property QLegend::labelColor | |
134 | The color of brush used to draw labels. |
|
134 | The color of brush used to draw labels. | |
135 | */ |
|
135 | */ | |
136 | /*! |
|
136 | /*! | |
137 | \qmlproperty color QLegend::labelColor |
|
137 | \qmlproperty color QLegend::labelColor | |
138 | The color of brush used to draw labels. |
|
138 | The color of brush used to draw labels. | |
139 | */ |
|
139 | */ | |
140 |
|
140 | |||
141 | /*! |
|
141 | /*! | |
142 | \fn void QLegend::backgroundVisibleChanged(bool) |
|
142 | \fn void QLegend::backgroundVisibleChanged(bool) | |
143 | The visibility of the legend background changed to \a visible. |
|
143 | The visibility of the legend background changed to \a visible. | |
144 | */ |
|
144 | */ | |
145 |
|
145 | |||
146 | /*! |
|
146 | /*! | |
147 | \fn void QLegend::colorChanged(QColor) |
|
147 | \fn void QLegend::colorChanged(QColor) | |
148 | The color of the legend background changed to \a color. |
|
148 | The color of the legend background changed to \a color. | |
149 | */ |
|
149 | */ | |
150 |
|
150 | |||
151 | /*! |
|
151 | /*! | |
152 | \fn void QLegend::borderColorChanged(QColor) |
|
152 | \fn void QLegend::borderColorChanged(QColor) | |
153 | The border color of the legend background changed to \a color. |
|
153 | The border color of the legend background changed to \a color. | |
154 | */ |
|
154 | */ | |
155 |
|
155 | |||
156 | /*! |
|
156 | /*! | |
157 | \fn void QLegend::fontChanged(QFont) |
|
157 | \fn void QLegend::fontChanged(QFont) | |
158 | The font of markers of the legend changed to \a font. |
|
158 | The font of markers of the legend changed to \a font. | |
159 | */ |
|
159 | */ | |
160 |
|
160 | |||
161 | /*! |
|
161 | /*! | |
162 | \fn void QLegend::labelColorChanged(QColor color) |
|
162 | \fn void QLegend::labelColorChanged(QColor color) | |
163 | This signal is emitted when the color of brush used to draw labels has changed to \a color. |
|
163 | This signal is emitted when the color of brush used to draw labels has changed to \a color. | |
164 | */ |
|
164 | */ | |
165 |
|
165 | |||
166 | /*! |
|
166 | /*! | |
167 | Constructs the legend object and sets the parent to \a parent |
|
167 | Constructs the legend object and sets the parent to \a parent | |
168 | */ |
|
168 | */ | |
169 |
|
169 | |||
170 | QLegend::QLegend(QChart *chart): QGraphicsWidget(chart), |
|
170 | QLegend::QLegend(QChart *chart): QGraphicsWidget(chart), | |
171 | d_ptr(new QLegendPrivate(chart->d_ptr->m_presenter, chart, this)) |
|
171 | d_ptr(new QLegendPrivate(chart->d_ptr->m_presenter, chart, this)) | |
172 | { |
|
172 | { | |
173 | setZValue(ChartPresenter::LegendZValue); |
|
173 | setZValue(ChartPresenter::LegendZValue); | |
174 | setFlags(QGraphicsItem::ItemClipsChildrenToShape); |
|
174 | setFlags(QGraphicsItem::ItemClipsChildrenToShape); | |
175 | QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*)), d_ptr.data(), SLOT(handleSeriesAdded(QAbstractSeries*,Domain*))); |
|
175 | QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*)), d_ptr.data(), SLOT(handleSeriesAdded(QAbstractSeries*,Domain*))); | |
176 | QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)),d_ptr.data(), SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
176 | QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)),d_ptr.data(), SLOT(handleSeriesRemoved(QAbstractSeries*))); | |
177 | // QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesUpdated(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesUpdated(QAbstractSeries*))); |
|
177 | // QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesUpdated(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesUpdated(QAbstractSeries*))); | |
178 | setLayout(d_ptr->m_layout); |
|
178 | setLayout(d_ptr->m_layout); | |
179 | } |
|
179 | } | |
180 |
|
180 | |||
181 | /*! |
|
181 | /*! | |
182 | Destroys the legend object. Legend is always owned by a QChart, so an application should never call this. |
|
182 | Destroys the legend object. Legend is always owned by a QChart, so an application should never call this. | |
183 | */ |
|
183 | */ | |
184 | QLegend::~QLegend() |
|
184 | QLegend::~QLegend() | |
185 | { |
|
185 | { | |
186 | } |
|
186 | } | |
187 |
|
187 | |||
188 | /*! |
|
188 | /*! | |
189 | \internal |
|
189 | \internal | |
190 | */ |
|
190 | */ | |
191 | void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
191 | void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
192 | { |
|
192 | { | |
193 | Q_UNUSED(option) |
|
193 | Q_UNUSED(option) | |
194 | Q_UNUSED(widget) |
|
194 | Q_UNUSED(widget) | |
195 |
|
195 | |||
196 | if (!d_ptr->m_backgroundVisible) |
|
196 | if (!d_ptr->m_backgroundVisible) | |
197 | return; |
|
197 | return; | |
198 |
|
198 | |||
199 | painter->setOpacity(opacity()); |
|
199 | painter->setOpacity(opacity()); | |
200 | painter->setPen(d_ptr->m_pen); |
|
200 | painter->setPen(d_ptr->m_pen); | |
201 | painter->setBrush(d_ptr->m_brush); |
|
201 | painter->setBrush(d_ptr->m_brush); | |
202 | painter->drawRoundRect(rect(), d_ptr->roundness(rect().width()), d_ptr->roundness(rect().height())); |
|
202 | painter->drawRoundRect(rect(), d_ptr->roundness(rect().width()), d_ptr->roundness(rect().height())); | |
203 | } |
|
203 | } | |
204 |
|
204 | |||
205 |
|
205 | |||
206 | /*! |
|
206 | /*! | |
207 | Sets the \a brush of legend. Brush affects the background of legend. |
|
207 | Sets the \a brush of legend. Brush affects the background of legend. | |
208 | */ |
|
208 | */ | |
209 | void QLegend::setBrush(const QBrush &brush) |
|
209 | void QLegend::setBrush(const QBrush &brush) | |
210 | { |
|
210 | { | |
211 | if (d_ptr->m_brush != brush) { |
|
211 | if (d_ptr->m_brush != brush) { | |
212 | d_ptr->m_brush = brush; |
|
212 | d_ptr->m_brush = brush; | |
213 | update(); |
|
213 | update(); | |
214 | emit colorChanged(brush.color()); |
|
214 | emit colorChanged(brush.color()); | |
215 | } |
|
215 | } | |
216 | } |
|
216 | } | |
217 |
|
217 | |||
218 | /*! |
|
218 | /*! | |
219 | Returns the brush used by legend. |
|
219 | Returns the brush used by legend. | |
220 | */ |
|
220 | */ | |
221 | QBrush QLegend::brush() const |
|
221 | QBrush QLegend::brush() const | |
222 | { |
|
222 | { | |
223 | return d_ptr->m_brush; |
|
223 | return d_ptr->m_brush; | |
224 | } |
|
224 | } | |
225 |
|
225 | |||
226 | void QLegend::setColor(QColor color) |
|
226 | void QLegend::setColor(QColor color) | |
227 | { |
|
227 | { | |
228 | QBrush b = d_ptr->m_brush; |
|
228 | QBrush b = d_ptr->m_brush; | |
229 | if (b.style() != Qt::SolidPattern || b.color() != color) { |
|
229 | if (b.style() != Qt::SolidPattern || b.color() != color) { | |
230 | b.setStyle(Qt::SolidPattern); |
|
230 | b.setStyle(Qt::SolidPattern); | |
231 | b.setColor(color); |
|
231 | b.setColor(color); | |
232 | setBrush(b); |
|
232 | setBrush(b); | |
233 | } |
|
233 | } | |
234 | } |
|
234 | } | |
235 |
|
235 | |||
236 | QColor QLegend::color() |
|
236 | QColor QLegend::color() | |
237 | { |
|
237 | { | |
238 | return d_ptr->m_brush.color(); |
|
238 | return d_ptr->m_brush.color(); | |
239 | } |
|
239 | } | |
240 |
|
240 | |||
241 | /*! |
|
241 | /*! | |
242 | Sets the \a pen of legend. Pen affects the legend borders. |
|
242 | Sets the \a pen of legend. Pen affects the legend borders. | |
243 | */ |
|
243 | */ | |
244 | void QLegend::setPen(const QPen &pen) |
|
244 | void QLegend::setPen(const QPen &pen) | |
245 | { |
|
245 | { | |
246 | if (d_ptr->m_pen != pen) { |
|
246 | if (d_ptr->m_pen != pen) { | |
247 | d_ptr->m_pen = pen; |
|
247 | d_ptr->m_pen = pen; | |
248 | update(); |
|
248 | update(); | |
249 | emit borderColorChanged(pen.color()); |
|
249 | emit borderColorChanged(pen.color()); | |
250 | } |
|
250 | } | |
251 | } |
|
251 | } | |
252 |
|
252 | |||
253 | /*! |
|
253 | /*! | |
254 | Returns the pen used by legend |
|
254 | Returns the pen used by legend | |
255 | */ |
|
255 | */ | |
256 |
|
256 | |||
257 | QPen QLegend::pen() const |
|
257 | QPen QLegend::pen() const | |
258 | { |
|
258 | { | |
259 | return d_ptr->m_pen; |
|
259 | return d_ptr->m_pen; | |
260 | } |
|
260 | } | |
261 |
|
261 | |||
262 | void QLegend::setFont(const QFont &font) |
|
262 | void QLegend::setFont(const QFont &font) | |
263 | { |
|
263 | { | |
264 | if (d_ptr->m_font != font) { |
|
264 | if (d_ptr->m_font != font) { | |
265 | d_ptr->m_font = font; |
|
265 | d_ptr->m_font = font; | |
266 | foreach (LegendMarker *marker, d_ptr->markers()) |
|
266 | foreach (LegendMarker *marker, d_ptr->markers()) | |
267 | marker->setFont(d_ptr->m_font); |
|
267 | marker->setFont(d_ptr->m_font); | |
268 | layout()->invalidate(); |
|
268 | layout()->invalidate(); | |
269 | emit fontChanged(font); |
|
269 | emit fontChanged(font); | |
270 | } |
|
270 | } | |
271 | } |
|
271 | } | |
272 |
|
272 | |||
273 | QFont QLegend::font() const |
|
273 | QFont QLegend::font() const | |
274 | { |
|
274 | { | |
275 | return d_ptr->m_font; |
|
275 | return d_ptr->m_font; | |
276 | } |
|
276 | } | |
277 |
|
277 | |||
278 | void QLegend::setBorderColor(QColor color) |
|
278 | void QLegend::setBorderColor(QColor color) | |
279 | { |
|
279 | { | |
280 | QPen p = d_ptr->m_pen; |
|
280 | QPen p = d_ptr->m_pen; | |
281 | if (p.color() != color) { |
|
281 | if (p.color() != color) { | |
282 | p.setColor(color); |
|
282 | p.setColor(color); | |
283 | setPen(p); |
|
283 | setPen(p); | |
284 | } |
|
284 | } | |
285 | } |
|
285 | } | |
286 |
|
286 | |||
287 | QColor QLegend::borderColor() |
|
287 | QColor QLegend::borderColor() | |
288 | { |
|
288 | { | |
289 | return d_ptr->m_pen.color(); |
|
289 | return d_ptr->m_pen.color(); | |
290 | } |
|
290 | } | |
291 |
|
291 | |||
292 | /*! |
|
292 | /*! | |
293 | Set brush used to draw labels to \a brush. |
|
293 | Set brush used to draw labels to \a brush. | |
294 | */ |
|
294 | */ | |
295 | void QLegend::setLabelBrush(const QBrush &brush) |
|
295 | void QLegend::setLabelBrush(const QBrush &brush) | |
296 | { |
|
296 | { | |
297 | if (d_ptr->m_labelBrush != brush) { |
|
297 | if (d_ptr->m_labelBrush != brush) { | |
298 | d_ptr->m_labelBrush = brush; |
|
298 | d_ptr->m_labelBrush = brush; | |
299 | foreach (LegendMarker *marker, d_ptr->markers()) { |
|
299 | foreach (LegendMarker *marker, d_ptr->markers()) { | |
300 | marker->setLabelBrush(d_ptr->m_labelBrush); |
|
300 | marker->setLabelBrush(d_ptr->m_labelBrush); | |
301 | // Note: The pen of the marker rectangle could be exposed in the public QLegend API |
|
301 | // Note: The pen of the marker rectangle could be exposed in the public QLegend API | |
302 | // instead of mapping it from label brush color |
|
302 | // instead of mapping it from label brush color | |
303 | marker->setPen(brush.color()); |
|
303 | marker->setPen(brush.color()); | |
304 | } |
|
304 | } | |
305 | emit labelColorChanged(brush.color()); |
|
305 | emit labelColorChanged(brush.color()); | |
306 | } |
|
306 | } | |
307 | } |
|
307 | } | |
308 |
|
308 | |||
309 | /*! |
|
309 | /*! | |
310 | Brush used to draw labels. |
|
310 | Brush used to draw labels. | |
311 | */ |
|
311 | */ | |
312 | QBrush QLegend::labelBrush() const |
|
312 | QBrush QLegend::labelBrush() const | |
313 | { |
|
313 | { | |
314 | return d_ptr->m_labelBrush; |
|
314 | return d_ptr->m_labelBrush; | |
315 | } |
|
315 | } | |
316 |
|
316 | |||
317 | void QLegend::setLabelColor(QColor color) |
|
317 | void QLegend::setLabelColor(QColor color) | |
318 | { |
|
318 | { | |
319 | QBrush b = d_ptr->m_labelBrush; |
|
319 | QBrush b = d_ptr->m_labelBrush; | |
320 | if (b.style() != Qt::SolidPattern || b.color() != color) { |
|
320 | if (b.style() != Qt::SolidPattern || b.color() != color) { | |
321 | b.setStyle(Qt::SolidPattern); |
|
321 | b.setStyle(Qt::SolidPattern); | |
322 | b.setColor(color); |
|
322 | b.setColor(color); | |
323 | setLabelBrush(b); |
|
323 | setLabelBrush(b); | |
324 | } |
|
324 | } | |
325 | } |
|
325 | } | |
326 |
|
326 | |||
327 | QColor QLegend::labelColor() const |
|
327 | QColor QLegend::labelColor() const | |
328 | { |
|
328 | { | |
329 | return d_ptr->m_labelBrush.color(); |
|
329 | return d_ptr->m_labelBrush.color(); | |
330 | } |
|
330 | } | |
331 |
|
331 | |||
332 |
|
332 | |||
333 | void QLegend::setAlignment(Qt::Alignment alignment) |
|
333 | void QLegend::setAlignment(Qt::Alignment alignment) | |
334 | { |
|
334 | { | |
335 | if (d_ptr->m_alignment != alignment) { |
|
335 | if (d_ptr->m_alignment != alignment) { | |
336 | d_ptr->m_alignment = alignment; |
|
336 | d_ptr->m_alignment = alignment; | |
337 | layout()->invalidate(); |
|
337 | layout()->invalidate(); | |
338 | } |
|
338 | } | |
339 | } |
|
339 | } | |
340 |
|
340 | |||
341 | Qt::Alignment QLegend::alignment() const |
|
341 | Qt::Alignment QLegend::alignment() const | |
342 | { |
|
342 | { | |
343 | return d_ptr->m_alignment; |
|
343 | return d_ptr->m_alignment; | |
344 | } |
|
344 | } | |
345 |
|
345 | |||
346 | /*! |
|
346 | /*! | |
347 | Detaches the legend from chart. Chart won't change layout of the legend. |
|
347 | Detaches the legend from chart. Chart won't change layout of the legend. | |
348 | */ |
|
348 | */ | |
349 | void QLegend::detachFromChart() |
|
349 | void QLegend::detachFromChart() | |
350 | { |
|
350 | { | |
351 | d_ptr->m_attachedToChart = false; |
|
351 | d_ptr->m_attachedToChart = false; | |
352 | layout()->invalidate(); |
|
352 | layout()->invalidate(); | |
353 | setParent(0); |
|
353 | setParent(0); | |
354 |
|
354 | |||
355 | } |
|
355 | } | |
356 |
|
356 | |||
357 | /*! |
|
357 | /*! | |
358 | Attaches the legend to chart. Chart may change layout of the legend. |
|
358 | Attaches the legend to chart. Chart may change layout of the legend. | |
359 | */ |
|
359 | */ | |
360 | void QLegend::attachToChart() |
|
360 | void QLegend::attachToChart() | |
361 | { |
|
361 | { | |
362 | d_ptr->m_attachedToChart = true; |
|
362 | d_ptr->m_attachedToChart = true; | |
363 | layout()->invalidate(); |
|
363 | layout()->invalidate(); | |
364 | setParent(d_ptr->m_chart); |
|
364 | setParent(d_ptr->m_chart); | |
365 | } |
|
365 | } | |
366 |
|
366 | |||
367 | /*! |
|
367 | /*! | |
368 | Returns true, if legend is attached to chart. |
|
368 | Returns true, if legend is attached to chart. | |
369 | */ |
|
369 | */ | |
370 | bool QLegend::isAttachedToChart() |
|
370 | bool QLegend::isAttachedToChart() | |
371 | { |
|
371 | { | |
372 | return d_ptr->m_attachedToChart; |
|
372 | return d_ptr->m_attachedToChart; | |
373 | } |
|
373 | } | |
374 |
|
374 | |||
375 | /*! |
|
375 | /*! | |
376 | Sets the visibility of legend background to \a visible |
|
376 | Sets the visibility of legend background to \a visible | |
377 | */ |
|
377 | */ | |
378 | void QLegend::setBackgroundVisible(bool visible) |
|
378 | void QLegend::setBackgroundVisible(bool visible) | |
379 | { |
|
379 | { | |
380 | if (d_ptr->m_backgroundVisible != visible) { |
|
380 | if (d_ptr->m_backgroundVisible != visible) { | |
381 | d_ptr->m_backgroundVisible = visible; |
|
381 | d_ptr->m_backgroundVisible = visible; | |
382 | update(); |
|
382 | update(); | |
383 | emit backgroundVisibleChanged(visible); |
|
383 | emit backgroundVisibleChanged(visible); | |
384 | } |
|
384 | } | |
385 | } |
|
385 | } | |
386 |
|
386 | |||
387 | /*! |
|
387 | /*! | |
388 | Returns the visibility of legend background |
|
388 | Returns the visibility of legend background | |
389 | */ |
|
389 | */ | |
390 | bool QLegend::isBackgroundVisible() const |
|
390 | bool QLegend::isBackgroundVisible() const | |
391 | { |
|
391 | { | |
392 | return d_ptr->m_backgroundVisible; |
|
392 | return d_ptr->m_backgroundVisible; | |
393 | } |
|
393 | } | |
394 |
|
394 | |||
395 | /*! |
|
395 | /*! | |
396 | \internal \a event see QGraphicsWidget for details |
|
396 | \internal \a event see QGraphicsWidget for details | |
397 | */ |
|
397 | */ | |
398 | void QLegend::hideEvent(QHideEvent *event) |
|
398 | void QLegend::hideEvent(QHideEvent *event) | |
399 | { |
|
399 | { | |
400 | if (isAttachedToChart()) |
|
400 | if (isAttachedToChart()) | |
401 | d_ptr->m_presenter->layout()->invalidate(); |
|
401 | d_ptr->m_presenter->layout()->invalidate(); | |
402 | QGraphicsWidget::hideEvent(event); |
|
402 | QGraphicsWidget::hideEvent(event); | |
403 | } |
|
403 | } | |
404 | /*! |
|
404 | /*! | |
405 | \internal \a event see QGraphicsWidget for details |
|
405 | \internal \a event see QGraphicsWidget for details | |
406 | */ |
|
406 | */ | |
407 | void QLegend::showEvent(QShowEvent *event) |
|
407 | void QLegend::showEvent(QShowEvent *event) | |
408 | { |
|
408 | { | |
409 | if (isAttachedToChart()) { |
|
409 | if (isAttachedToChart()) { | |
410 | d_ptr->items()->setVisible(false); |
|
410 | d_ptr->items()->setVisible(false); | |
411 | layout()->invalidate(); |
|
411 | layout()->invalidate(); | |
412 | } |
|
412 | } | |
413 | QGraphicsWidget::showEvent(event); |
|
413 | QGraphicsWidget::showEvent(event); | |
414 | //layout activation will show the items |
|
414 | //layout activation will show the items | |
415 | } |
|
415 | } | |
416 |
|
416 | |||
417 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
417 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
418 |
|
418 | |||
419 | QLegendPrivate::QLegendPrivate(ChartPresenter *presenter, QChart *chart, QLegend *q) |
|
419 | QLegendPrivate::QLegendPrivate(ChartPresenter *presenter, QChart *chart, QLegend *q) | |
420 | : q_ptr(q), |
|
420 | : q_ptr(q), | |
421 | m_presenter(presenter), |
|
421 | m_presenter(presenter), | |
422 | m_layout(new LegendLayout(q)), |
|
422 | m_layout(new LegendLayout(q)), | |
423 | m_chart(chart), |
|
423 | m_chart(chart), | |
424 | m_items(new QGraphicsItemGroup(q)), |
|
424 | m_items(new QGraphicsItemGroup(q)), | |
425 | m_alignment(Qt::AlignTop), |
|
425 | m_alignment(Qt::AlignTop), | |
426 | m_brush(QBrush()), |
|
426 | m_brush(QBrush()), | |
427 | m_pen(QPen()), |
|
427 | m_pen(QPen()), | |
428 | m_labelBrush(QBrush()), |
|
428 | m_labelBrush(QBrush()), | |
429 | m_diameter(5), |
|
429 | m_diameter(5), | |
430 | m_attachedToChart(true), |
|
430 | m_attachedToChart(true), | |
431 | m_backgroundVisible(false) |
|
431 | m_backgroundVisible(false) | |
432 | { |
|
432 | { | |
433 |
|
433 | |||
434 | } |
|
434 | } | |
435 |
|
435 | |||
436 | QLegendPrivate::~QLegendPrivate() |
|
436 | QLegendPrivate::~QLegendPrivate() | |
437 | { |
|
437 | { | |
438 |
|
438 | |||
439 | } |
|
439 | } | |
440 |
|
440 | |||
441 | void QLegendPrivate::setOffset(qreal x, qreal y) |
|
441 | void QLegendPrivate::setOffset(qreal x, qreal y) | |
442 | { |
|
442 | { | |
443 | m_layout->setOffset(x, y); |
|
443 | m_layout->setOffset(x, y); | |
444 | } |
|
444 | } | |
445 |
|
445 | |||
446 | QPointF QLegendPrivate::offset() const |
|
446 | QPointF QLegendPrivate::offset() const | |
447 | { |
|
447 | { | |
448 | return m_layout->offset(); |
|
448 | return m_layout->offset(); | |
449 | } |
|
449 | } | |
450 |
|
450 | |||
451 | int QLegendPrivate::roundness(qreal size) |
|
451 | int QLegendPrivate::roundness(qreal size) | |
452 | { |
|
452 | { | |
453 | return 100 * m_diameter / int(size); |
|
453 | return 100 * m_diameter / int(size); | |
454 | } |
|
454 | } | |
455 |
|
455 | |||
456 | void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series, Domain *domain) |
|
456 | void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series, Domain *domain) | |
457 | { |
|
457 | { | |
458 | Q_UNUSED(domain) |
|
458 | Q_UNUSED(domain) | |
459 |
|
459 | |||
460 | QList<LegendMarker *> markers = series->d_ptr->createLegendMarker(q_ptr); |
|
460 | QList<LegendMarker *> markers = series->d_ptr->createLegendMarker(q_ptr); | |
461 |
|
461 | |||
462 | foreach (LegendMarker *marker, markers) { |
|
462 | foreach (LegendMarker *marker, markers) { | |
463 | marker->setFont(m_font); |
|
463 | marker->setFont(m_font); | |
464 | marker->setLabelBrush(m_labelBrush); |
|
464 | marker->setLabelBrush(m_labelBrush); | |
465 | marker->setVisible(series->isVisible()); |
|
465 | marker->setVisible(series->isVisible()); | |
466 | m_items->addToGroup(marker); |
|
466 | m_items->addToGroup(marker); | |
467 | m_markers << marker; |
|
467 | m_markers << marker; | |
468 | } |
|
468 | } | |
469 |
|
469 | |||
470 | QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); |
|
470 | QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); | |
471 | QObject::connect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged())); |
|
471 | QObject::connect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged())); | |
472 |
|
472 | |||
473 | m_items->setVisible(false); |
|
473 | m_items->setVisible(false); | |
474 | m_layout->invalidate(); |
|
474 | m_layout->invalidate(); | |
475 | } |
|
475 | } | |
476 |
|
476 | |||
477 | void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series) |
|
477 | void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series) | |
478 | { |
|
478 | { | |
479 | foreach (LegendMarker *marker, m_markers) { |
|
479 | foreach (LegendMarker *marker, m_markers) { | |
480 | if (marker->series() == series) { |
|
480 | if (marker->series() == series) { | |
481 | delete marker; |
|
481 | delete marker; | |
482 | m_markers.removeAll(marker); |
|
482 | m_markers.removeAll(marker); | |
483 | } |
|
483 | } | |
484 | } |
|
484 | } | |
485 |
|
485 | |||
486 | QObject::disconnect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); |
|
486 | QObject::disconnect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); | |
487 | QObject::disconnect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged())); |
|
487 | QObject::disconnect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged())); | |
488 | m_layout->invalidate(); |
|
488 | m_layout->invalidate(); | |
489 | } |
|
489 | } | |
490 |
|
490 | |||
491 | void QLegendPrivate::handleSeriesVisibleChanged() |
|
491 | void QLegendPrivate::handleSeriesVisibleChanged() | |
492 | { |
|
492 | { | |
493 | QAbstractSeries *series = qobject_cast<QAbstractSeries *> (sender()); |
|
493 | QAbstractSeries *series = qobject_cast<QAbstractSeries *> (sender()); | |
494 | Q_ASSERT(series); |
|
494 | Q_ASSERT(series); | |
495 |
|
495 | |||
496 | foreach (LegendMarker *marker, m_markers) { |
|
496 | foreach (LegendMarker *marker, m_markers) { | |
497 | if (marker->series() == series) |
|
497 | if (marker->series() == series) | |
498 | marker->setVisible(series->isVisible()); |
|
498 | marker->setVisible(series->isVisible()); | |
499 | } |
|
499 | } | |
500 | m_layout->invalidate(); |
|
500 | m_layout->invalidate(); | |
501 | } |
|
501 | } | |
502 |
|
502 | |||
503 | void QLegendPrivate::handleCountChanged() |
|
503 | void QLegendPrivate::handleCountChanged() | |
504 | { |
|
504 | { | |
505 | QAbstractSeriesPrivate *series = qobject_cast<QAbstractSeriesPrivate *> (sender()); |
|
505 | QAbstractSeriesPrivate *series = qobject_cast<QAbstractSeriesPrivate *> (sender()); | |
506 | Q_ASSERT(series); |
|
506 | Q_ASSERT(series); | |
507 | handleSeriesRemoved(series->q_ptr); |
|
507 | handleSeriesRemoved(series->q_ptr); | |
508 | handleSeriesAdded(series->q_ptr, 0); |
|
508 | handleSeriesAdded(series->q_ptr, 0); | |
509 | } |
|
509 | } | |
510 |
|
510 | |||
511 | #include "moc_qlegend.cpp" |
|
511 | #include "moc_qlegend.cpp" | |
512 | #include "moc_qlegend_p.cpp" |
|
512 | #include "moc_qlegend_p.cpp" | |
513 |
|
513 | |||
514 | QTCOMMERCIALCHART_END_NAMESPACE |
|
514 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now