@@ -1,409 +1,408 | |||||
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 "qareaseries.h" |
|
21 | #include "qareaseries.h" | |
22 | #include "qareaseries_p.h" |
|
22 | #include "qareaseries_p.h" | |
23 | #include "qlineseries.h" |
|
23 | #include "qlineseries.h" | |
24 | #include "areachartitem_p.h" |
|
24 | #include "areachartitem_p.h" | |
25 | #include "legendmarker_p.h" |
|
25 | #include "legendmarker_p.h" | |
26 | #include "domain_p.h" |
|
26 | #include "domain_p.h" | |
27 | #include "chartdataset_p.h" |
|
27 | #include "chartdataset_p.h" | |
28 | #include "charttheme_p.h" |
|
28 | #include "charttheme_p.h" | |
29 | #include "qvalueaxis.h" |
|
29 | #include "qvalueaxis.h" | |
30 |
|
30 | |||
|
31 | #include "qarealegendmarker.h" | |||
|
32 | ||||
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
32 |
|
34 | |||
33 | /*! |
|
35 | /*! | |
34 | \class QAreaSeries |
|
36 | \class QAreaSeries | |
35 | \brief The QAreaSeries class is used for making area charts. |
|
37 | \brief The QAreaSeries class is used for making area charts. | |
36 |
|
38 | |||
37 | \mainclass |
|
39 | \mainclass | |
38 |
|
40 | |||
39 | An area chart is used to show quantitative data. It is based on line chart, in the way that area between axis and the line |
|
41 | An area chart is used to show quantitative data. It is based on line chart, in the way that area between axis and the line | |
40 | is emphasized with color. Since the area chart is based on line chart, QAreaSeries constructor needs QLineSeries instance, |
|
42 | is emphasized with color. Since the area chart is based on line chart, QAreaSeries constructor needs QLineSeries instance, | |
41 | which defines "upper" boundary of the area. "Lower" boundary is defined by default by axis X. Instead of axis X "lower" boundary can be specified by other line. |
|
43 | which defines "upper" boundary of the area. "Lower" boundary is defined by default by axis X. Instead of axis X "lower" boundary can be specified by other line. | |
42 | In that case QAreaSeries should be initiated with two QLineSeries instances. Please note terms "upper" and "lower" boundary can be misleading in cases |
|
44 | In that case QAreaSeries should be initiated with two QLineSeries instances. Please note terms "upper" and "lower" boundary can be misleading in cases | |
43 | where "lower" boundary had bigger values than the "upper" one, however the main point that area between these two boundary lines will be filled. |
|
45 | where "lower" boundary had bigger values than the "upper" one, however the main point that area between these two boundary lines will be filled. | |
44 |
|
46 | |||
45 | See the \l {AreaChart Example} {area chart example} to learn how to create a simple area chart. |
|
47 | See the \l {AreaChart Example} {area chart example} to learn how to create a simple area chart. | |
46 | \image examples_areachart.png |
|
48 | \image examples_areachart.png | |
47 | */ |
|
49 | */ | |
48 | /*! |
|
50 | /*! | |
49 | \qmlclass AreaSeries QAreaSeries |
|
51 | \qmlclass AreaSeries QAreaSeries | |
50 |
|
52 | |||
51 | The following QML shows how to create a simple area chart: |
|
53 | The following QML shows how to create a simple area chart: | |
52 | \snippet ../demos/qmlchart/qml/qmlchart/View4.qml 1 |
|
54 | \snippet ../demos/qmlchart/qml/qmlchart/View4.qml 1 | |
53 | \beginfloatleft |
|
55 | \beginfloatleft | |
54 | \image demos_qmlchart4.png |
|
56 | \image demos_qmlchart4.png | |
55 | \endfloat |
|
57 | \endfloat | |
56 | \clearfloat |
|
58 | \clearfloat | |
57 | */ |
|
59 | */ | |
58 |
|
60 | |||
59 | /*! |
|
61 | /*! | |
60 | \property QAreaSeries::upperSeries |
|
62 | \property QAreaSeries::upperSeries | |
61 | \brief The upper one of the two line series used to define area series boundaries. |
|
63 | \brief The upper one of the two line series used to define area series boundaries. | |
62 | */ |
|
64 | */ | |
63 | /*! |
|
65 | /*! | |
64 | \qmlproperty LineSeries AreaSeries::upperSeries |
|
66 | \qmlproperty LineSeries AreaSeries::upperSeries | |
65 | The upper one of the two line series used to define area series boundaries. |
|
67 | The upper one of the two line series used to define area series boundaries. | |
66 | */ |
|
68 | */ | |
67 |
|
69 | |||
68 | /*! |
|
70 | /*! | |
69 | \property QAreaSeries::lowerSeries |
|
71 | \property QAreaSeries::lowerSeries | |
70 | The lower one of the two line series used to define are series boundaries. Note if |
|
72 | The lower one of the two line series used to define are series boundaries. Note if | |
71 | QAreaSeries was counstucted wihtout a\ lowerSeries this is null. |
|
73 | QAreaSeries was counstucted wihtout a\ lowerSeries this is null. | |
72 | */ |
|
74 | */ | |
73 | /*! |
|
75 | /*! | |
74 | \qmlproperty LineSeries AreaSeries::lowerSeries |
|
76 | \qmlproperty LineSeries AreaSeries::lowerSeries | |
75 | The lower one of the two line series used to define are series boundaries. Note if |
|
77 | The lower one of the two line series used to define are series boundaries. Note if | |
76 | AreaSeries was counstucted wihtout a\ lowerSeries this is null. |
|
78 | AreaSeries was counstucted wihtout a\ lowerSeries this is null. | |
77 | */ |
|
79 | */ | |
78 |
|
80 | |||
79 | /*! |
|
81 | /*! | |
80 | \property QAreaSeries::color |
|
82 | \property QAreaSeries::color | |
81 | Fill (brush) color of the series. This is a convenience property for modifying the color of brush. |
|
83 | Fill (brush) color of the series. This is a convenience property for modifying the color of brush. | |
82 | \sa QAreaSeries::brush() |
|
84 | \sa QAreaSeries::brush() | |
83 | */ |
|
85 | */ | |
84 | /*! |
|
86 | /*! | |
85 | \qmlproperty color AreaSeries::color |
|
87 | \qmlproperty color AreaSeries::color | |
86 | Fill (brush) color of the series. |
|
88 | Fill (brush) color of the series. | |
87 | */ |
|
89 | */ | |
88 |
|
90 | |||
89 | /*! |
|
91 | /*! | |
90 | \property QAreaSeries::borderColor |
|
92 | \property QAreaSeries::borderColor | |
91 | Line (pen) color of the series. This is a convenience property for modifying the color of pen. |
|
93 | Line (pen) color of the series. This is a convenience property for modifying the color of pen. | |
92 | \sa QAreaSeries::pen() |
|
94 | \sa QAreaSeries::pen() | |
93 | */ |
|
95 | */ | |
94 | /*! |
|
96 | /*! | |
95 | \qmlproperty color AreaSeries::borderColor |
|
97 | \qmlproperty color AreaSeries::borderColor | |
96 | Line (pen) color of the series. |
|
98 | Line (pen) color of the series. | |
97 | */ |
|
99 | */ | |
98 |
|
100 | |||
99 | /*! |
|
101 | /*! | |
100 | \qmlproperty real AreaSeries::borderWidth |
|
102 | \qmlproperty real AreaSeries::borderWidth | |
101 | The width of the border line. By default the width is 2.0. |
|
103 | The width of the border line. By default the width is 2.0. | |
102 | */ |
|
104 | */ | |
103 |
|
105 | |||
104 | /*! |
|
106 | /*! | |
105 | \fn QPen QAreaSeries::pen() const |
|
107 | \fn QPen QAreaSeries::pen() const | |
106 | \brief Returns the pen used to draw line for this series. |
|
108 | \brief Returns the pen used to draw line for this series. | |
107 | \sa setPen() |
|
109 | \sa setPen() | |
108 | */ |
|
110 | */ | |
109 |
|
111 | |||
110 | /*! |
|
112 | /*! | |
111 | \fn QPen QAreaSeries::brush() const |
|
113 | \fn QPen QAreaSeries::brush() const | |
112 | \brief Returns the brush used to draw line for this series. |
|
114 | \brief Returns the brush used to draw line for this series. | |
113 | \sa setBrush() |
|
115 | \sa setBrush() | |
114 | */ |
|
116 | */ | |
115 |
|
117 | |||
116 | /*! |
|
118 | /*! | |
117 | \fn void QAreaSeries::colorChanged(QColor color) |
|
119 | \fn void QAreaSeries::colorChanged(QColor color) | |
118 | \brief Signal is emitted when the fill (brush) color has changed to \a color. |
|
120 | \brief Signal is emitted when the fill (brush) color has changed to \a color. | |
119 | */ |
|
121 | */ | |
120 | /*! |
|
122 | /*! | |
121 | \qmlsignal AreaSeries::onColorChanged(color color) |
|
123 | \qmlsignal AreaSeries::onColorChanged(color color) | |
122 | Signal is emitted when the fill (brush) color has changed to \a color. |
|
124 | Signal is emitted when the fill (brush) color has changed to \a color. | |
123 | */ |
|
125 | */ | |
124 |
|
126 | |||
125 | /*! |
|
127 | /*! | |
126 | \fn void QAreaSeries::borderColorChanged(QColor color) |
|
128 | \fn void QAreaSeries::borderColorChanged(QColor color) | |
127 | \brief Signal is emitted when the line (pen) color has changed to \a color. |
|
129 | \brief Signal is emitted when the line (pen) color has changed to \a color. | |
128 | */ |
|
130 | */ | |
129 | /*! |
|
131 | /*! | |
130 | \qmlsignal AreaSeries::onBorderColorChanged(color color) |
|
132 | \qmlsignal AreaSeries::onBorderColorChanged(color color) | |
131 | Signal is emitted when the line (pen) color has changed to \a color. |
|
133 | Signal is emitted when the line (pen) color has changed to \a color. | |
132 | */ |
|
134 | */ | |
133 |
|
135 | |||
134 | /*! |
|
136 | /*! | |
135 | \fn void QAreaSeries::clicked(const QPointF& point) |
|
137 | \fn void QAreaSeries::clicked(const QPointF& point) | |
136 | \brief Signal is emitted when user clicks the \a point on area chart. |
|
138 | \brief Signal is emitted when user clicks the \a point on area chart. | |
137 | */ |
|
139 | */ | |
138 | /*! |
|
140 | /*! | |
139 | \qmlsignal AreaSeries::onClicked(QPointF point) |
|
141 | \qmlsignal AreaSeries::onClicked(QPointF point) | |
140 | Signal is emitted when user clicks the \a point on area chart. |
|
142 | Signal is emitted when user clicks the \a point on area chart. | |
141 | */ |
|
143 | */ | |
142 |
|
144 | |||
143 | /*! |
|
145 | /*! | |
144 | \fn void QAreaSeries::selected() |
|
146 | \fn void QAreaSeries::selected() | |
145 | The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be |
|
147 | The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be | |
146 | implemented by the user of QAreaSeries API. |
|
148 | implemented by the user of QAreaSeries API. | |
147 | */ |
|
149 | */ | |
148 | /*! |
|
150 | /*! | |
149 | \qmlsignal AreaSeries::onSelected() |
|
151 | \qmlsignal AreaSeries::onSelected() | |
150 | The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be |
|
152 | The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be | |
151 | implemented by the user of AreaSeries API. |
|
153 | implemented by the user of AreaSeries API. | |
152 | */ |
|
154 | */ | |
153 |
|
155 | |||
154 | /*! |
|
156 | /*! | |
155 | \fn void QAreaSeriesPrivate::updated() |
|
157 | \fn void QAreaSeriesPrivate::updated() | |
156 | \brief \internal |
|
158 | \brief \internal | |
157 | */ |
|
159 | */ | |
158 |
|
160 | |||
159 | /*! |
|
161 | /*! | |
160 | Constructs area series object which is a child of \a upperSeries. Area will be spanned between \a |
|
162 | Constructs area series object which is a child of \a upperSeries. Area will be spanned between \a | |
161 | upperSeries line and \a lowerSeries line. If no \a lowerSeries is passed to constructor, area is specified by axis x (y=0) instead. |
|
163 | upperSeries line and \a lowerSeries line. If no \a lowerSeries is passed to constructor, area is specified by axis x (y=0) instead. | |
162 | When series object is added to QChartView or QChart instance ownerships is transferred. |
|
164 | When series object is added to QChartView or QChart instance ownerships is transferred. | |
163 | */ |
|
165 | */ | |
164 | QAreaSeries::QAreaSeries(QLineSeries *upperSeries, QLineSeries *lowerSeries) |
|
166 | QAreaSeries::QAreaSeries(QLineSeries *upperSeries, QLineSeries *lowerSeries) | |
165 | : QAbstractSeries(*new QAreaSeriesPrivate(upperSeries, lowerSeries, this), upperSeries) |
|
167 | : QAbstractSeries(*new QAreaSeriesPrivate(upperSeries, lowerSeries, this), upperSeries) | |
166 | { |
|
168 | { | |
167 | } |
|
169 | } | |
168 |
|
170 | |||
169 | /*! |
|
171 | /*! | |
170 | Constructs area series object without upper or lower series with \a parent object. |
|
172 | Constructs area series object without upper or lower series with \a parent object. | |
171 | */ |
|
173 | */ | |
172 | QAreaSeries::QAreaSeries(QObject *parent) |
|
174 | QAreaSeries::QAreaSeries(QObject *parent) | |
173 | : QAbstractSeries(*new QAreaSeriesPrivate(0, 0, this), parent) |
|
175 | : QAbstractSeries(*new QAreaSeriesPrivate(0, 0, this), parent) | |
174 | { |
|
176 | { | |
175 | } |
|
177 | } | |
176 |
|
178 | |||
177 | /*! |
|
179 | /*! | |
178 | Destroys the object. |
|
180 | Destroys the object. | |
179 | */ |
|
181 | */ | |
180 | QAreaSeries::~QAreaSeries() |
|
182 | QAreaSeries::~QAreaSeries() | |
181 | { |
|
183 | { | |
182 | Q_D(QAreaSeries); |
|
184 | Q_D(QAreaSeries); | |
183 | if (d->m_dataset) |
|
185 | if (d->m_dataset) | |
184 | d->m_dataset->removeSeries(this); |
|
186 | d->m_dataset->removeSeries(this); | |
185 | } |
|
187 | } | |
186 |
|
188 | |||
187 | /*! |
|
189 | /*! | |
188 | Returns QChartSeries::SeriesTypeArea. |
|
190 | Returns QChartSeries::SeriesTypeArea. | |
189 | */ |
|
191 | */ | |
190 | QAbstractSeries::SeriesType QAreaSeries::type() const |
|
192 | QAbstractSeries::SeriesType QAreaSeries::type() const | |
191 | { |
|
193 | { | |
192 | return QAbstractSeries::SeriesTypeArea; |
|
194 | return QAbstractSeries::SeriesTypeArea; | |
193 | } |
|
195 | } | |
194 |
|
196 | |||
195 | /*! |
|
197 | /*! | |
196 | Sets the \a series that is to be used as the area chart upper series. |
|
198 | Sets the \a series that is to be used as the area chart upper series. | |
197 | */ |
|
199 | */ | |
198 | void QAreaSeries::setUpperSeries(QLineSeries *series) |
|
200 | void QAreaSeries::setUpperSeries(QLineSeries *series) | |
199 | { |
|
201 | { | |
200 | Q_D(QAreaSeries); |
|
202 | Q_D(QAreaSeries); | |
201 | d->m_upperSeries = series; |
|
203 | d->m_upperSeries = series; | |
202 | } |
|
204 | } | |
203 |
|
205 | |||
204 | QLineSeries *QAreaSeries::upperSeries() const |
|
206 | QLineSeries *QAreaSeries::upperSeries() const | |
205 | { |
|
207 | { | |
206 | Q_D(const QAreaSeries); |
|
208 | Q_D(const QAreaSeries); | |
207 | return d->m_upperSeries; |
|
209 | return d->m_upperSeries; | |
208 | } |
|
210 | } | |
209 |
|
211 | |||
210 | /*! |
|
212 | /*! | |
211 | Sets the \a series that is to be used as the area chart lower series. |
|
213 | Sets the \a series that is to be used as the area chart lower series. | |
212 | */ |
|
214 | */ | |
213 | void QAreaSeries::setLowerSeries(QLineSeries *series) |
|
215 | void QAreaSeries::setLowerSeries(QLineSeries *series) | |
214 | { |
|
216 | { | |
215 | Q_D(QAreaSeries); |
|
217 | Q_D(QAreaSeries); | |
216 | d->m_lowerSeries = series; |
|
218 | d->m_lowerSeries = series; | |
217 | } |
|
219 | } | |
218 |
|
220 | |||
219 | QLineSeries *QAreaSeries::lowerSeries() const |
|
221 | QLineSeries *QAreaSeries::lowerSeries() const | |
220 | { |
|
222 | { | |
221 | Q_D(const QAreaSeries); |
|
223 | Q_D(const QAreaSeries); | |
222 | return d->m_lowerSeries; |
|
224 | return d->m_lowerSeries; | |
223 | } |
|
225 | } | |
224 |
|
226 | |||
225 | /*! |
|
227 | /*! | |
226 | Sets \a pen used for drawing area outline. |
|
228 | Sets \a pen used for drawing area outline. | |
227 | */ |
|
229 | */ | |
228 | void QAreaSeries::setPen(const QPen &pen) |
|
230 | void QAreaSeries::setPen(const QPen &pen) | |
229 | { |
|
231 | { | |
230 | Q_D(QAreaSeries); |
|
232 | Q_D(QAreaSeries); | |
231 | if (d->m_pen != pen) { |
|
233 | if (d->m_pen != pen) { | |
232 | d->m_pen = pen; |
|
234 | d->m_pen = pen; | |
233 | emit d->updated(); |
|
235 | emit d->updated(); | |
234 | } |
|
236 | } | |
235 | } |
|
237 | } | |
236 |
|
238 | |||
237 | QPen QAreaSeries::pen() const |
|
239 | QPen QAreaSeries::pen() const | |
238 | { |
|
240 | { | |
239 | Q_D(const QAreaSeries); |
|
241 | Q_D(const QAreaSeries); | |
240 | return d->m_pen; |
|
242 | return d->m_pen; | |
241 | } |
|
243 | } | |
242 |
|
244 | |||
243 | /*! |
|
245 | /*! | |
244 | Sets \a brush used for filling the area. |
|
246 | Sets \a brush used for filling the area. | |
245 | */ |
|
247 | */ | |
246 | void QAreaSeries::setBrush(const QBrush &brush) |
|
248 | void QAreaSeries::setBrush(const QBrush &brush) | |
247 | { |
|
249 | { | |
248 | Q_D(QAreaSeries); |
|
250 | Q_D(QAreaSeries); | |
249 | if (d->m_brush != brush) { |
|
251 | if (d->m_brush != brush) { | |
250 | bool emitColorChanged = brush.color() != d->m_brush.color(); |
|
252 | bool emitColorChanged = brush.color() != d->m_brush.color(); | |
251 | d->m_brush = brush; |
|
253 | d->m_brush = brush; | |
252 | emit d->updated(); |
|
254 | emit d->updated(); | |
253 | if (emitColorChanged) |
|
255 | if (emitColorChanged) | |
254 | emit colorChanged(brush.color()); |
|
256 | emit colorChanged(brush.color()); | |
255 | } |
|
257 | } | |
256 | } |
|
258 | } | |
257 |
|
259 | |||
258 | QBrush QAreaSeries::brush() const |
|
260 | QBrush QAreaSeries::brush() const | |
259 | { |
|
261 | { | |
260 | Q_D(const QAreaSeries); |
|
262 | Q_D(const QAreaSeries); | |
261 | return d->m_brush; |
|
263 | return d->m_brush; | |
262 | } |
|
264 | } | |
263 |
|
265 | |||
264 | void QAreaSeries::setColor(const QColor &color) |
|
266 | void QAreaSeries::setColor(const QColor &color) | |
265 | { |
|
267 | { | |
266 | QBrush b = brush(); |
|
268 | QBrush b = brush(); | |
267 | if (b == QBrush()) |
|
269 | if (b == QBrush()) | |
268 | b.setStyle(Qt::SolidPattern); |
|
270 | b.setStyle(Qt::SolidPattern); | |
269 | b.setColor(color); |
|
271 | b.setColor(color); | |
270 | setBrush(b); |
|
272 | setBrush(b); | |
271 | } |
|
273 | } | |
272 |
|
274 | |||
273 | QColor QAreaSeries::color() const |
|
275 | QColor QAreaSeries::color() const | |
274 | { |
|
276 | { | |
275 | return brush().color(); |
|
277 | return brush().color(); | |
276 | } |
|
278 | } | |
277 |
|
279 | |||
278 | void QAreaSeries::setBorderColor(const QColor &color) |
|
280 | void QAreaSeries::setBorderColor(const QColor &color) | |
279 | { |
|
281 | { | |
280 | QPen p = pen(); |
|
282 | QPen p = pen(); | |
281 | if (p.color() != color) { |
|
283 | if (p.color() != color) { | |
282 | p.setColor(color); |
|
284 | p.setColor(color); | |
283 | setPen(p); |
|
285 | setPen(p); | |
284 | emit borderColorChanged(color); |
|
286 | emit borderColorChanged(color); | |
285 | } |
|
287 | } | |
286 | } |
|
288 | } | |
287 |
|
289 | |||
288 | QColor QAreaSeries::borderColor() const |
|
290 | QColor QAreaSeries::borderColor() const | |
289 | { |
|
291 | { | |
290 | return pen().color(); |
|
292 | return pen().color(); | |
291 | } |
|
293 | } | |
292 |
|
294 | |||
293 | /*! |
|
295 | /*! | |
294 | Sets if data points are \a visible and should be drawn on line. |
|
296 | Sets if data points are \a visible and should be drawn on line. | |
295 | */ |
|
297 | */ | |
296 | void QAreaSeries::setPointsVisible(bool visible) |
|
298 | void QAreaSeries::setPointsVisible(bool visible) | |
297 | { |
|
299 | { | |
298 | Q_D(QAreaSeries); |
|
300 | Q_D(QAreaSeries); | |
299 | if (d->m_pointsVisible != visible) { |
|
301 | if (d->m_pointsVisible != visible) { | |
300 | d->m_pointsVisible = visible; |
|
302 | d->m_pointsVisible = visible; | |
301 | emit d->updated(); |
|
303 | emit d->updated(); | |
302 | } |
|
304 | } | |
303 | } |
|
305 | } | |
304 |
|
306 | |||
305 | /*! |
|
307 | /*! | |
306 | Returns if the points are drawn for this series. |
|
308 | Returns if the points are drawn for this series. | |
307 | \sa setPointsVisible() |
|
309 | \sa setPointsVisible() | |
308 | */ |
|
310 | */ | |
309 | bool QAreaSeries::pointsVisible() const |
|
311 | bool QAreaSeries::pointsVisible() const | |
310 | { |
|
312 | { | |
311 | Q_D(const QAreaSeries); |
|
313 | Q_D(const QAreaSeries); | |
312 | return d->m_pointsVisible; |
|
314 | return d->m_pointsVisible; | |
313 | } |
|
315 | } | |
314 |
|
316 | |||
315 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
317 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
316 |
|
318 | |||
317 | QAreaSeriesPrivate::QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries, QAreaSeries *q) |
|
319 | QAreaSeriesPrivate::QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries, QAreaSeries *q) | |
318 | : QAbstractSeriesPrivate(q), |
|
320 | : QAbstractSeriesPrivate(q), | |
319 | m_upperSeries(upperSeries), |
|
321 | m_upperSeries(upperSeries), | |
320 | m_lowerSeries(lowerSeries), |
|
322 | m_lowerSeries(lowerSeries), | |
321 | m_pointsVisible(false) |
|
323 | m_pointsVisible(false) | |
322 | { |
|
324 | { | |
323 | } |
|
325 | } | |
324 |
|
326 | |||
325 | void QAreaSeriesPrivate::scaleDomain(Domain &domain) |
|
327 | void QAreaSeriesPrivate::scaleDomain(Domain &domain) | |
326 | { |
|
328 | { | |
327 | Q_Q(QAreaSeries); |
|
329 | Q_Q(QAreaSeries); | |
328 |
|
330 | |||
329 | qreal minX(domain.minX()); |
|
331 | qreal minX(domain.minX()); | |
330 | qreal minY(domain.minY()); |
|
332 | qreal minY(domain.minY()); | |
331 | qreal maxX(domain.maxX()); |
|
333 | qreal maxX(domain.maxX()); | |
332 | qreal maxY(domain.maxY()); |
|
334 | qreal maxY(domain.maxY()); | |
333 |
|
335 | |||
334 | QLineSeries *upperSeries = q->upperSeries(); |
|
336 | QLineSeries *upperSeries = q->upperSeries(); | |
335 | QLineSeries *lowerSeries = q->lowerSeries(); |
|
337 | QLineSeries *lowerSeries = q->lowerSeries(); | |
336 |
|
338 | |||
337 | const QList<QPointF>& points = upperSeries->points(); |
|
339 | const QList<QPointF>& points = upperSeries->points(); | |
338 |
|
340 | |||
339 | for (int i = 0; i < points.count(); i++) { |
|
341 | for (int i = 0; i < points.count(); i++) { | |
340 | qreal x = points[i].x(); |
|
342 | qreal x = points[i].x(); | |
341 | qreal y = points[i].y(); |
|
343 | qreal y = points[i].y(); | |
342 | minX = qMin(minX, x); |
|
344 | minX = qMin(minX, x); | |
343 | minY = qMin(minY, y); |
|
345 | minY = qMin(minY, y); | |
344 | maxX = qMax(maxX, x); |
|
346 | maxX = qMax(maxX, x); | |
345 | maxY = qMax(maxY, y); |
|
347 | maxY = qMax(maxY, y); | |
346 | } |
|
348 | } | |
347 | if (lowerSeries) { |
|
349 | if (lowerSeries) { | |
348 |
|
350 | |||
349 | const QList<QPointF>& points = lowerSeries->points(); |
|
351 | const QList<QPointF>& points = lowerSeries->points(); | |
350 |
|
352 | |||
351 | for (int i = 0; i < points.count(); i++) { |
|
353 | for (int i = 0; i < points.count(); i++) { | |
352 | qreal x = points[i].x(); |
|
354 | qreal x = points[i].x(); | |
353 | qreal y = points[i].y(); |
|
355 | qreal y = points[i].y(); | |
354 | minX = qMin(minX, x); |
|
356 | minX = qMin(minX, x); | |
355 | minY = qMin(minY, y); |
|
357 | minY = qMin(minY, y); | |
356 | maxX = qMax(maxX, x); |
|
358 | maxX = qMax(maxX, x); | |
357 | maxY = qMax(maxY, y); |
|
359 | maxY = qMax(maxY, y); | |
358 | } |
|
360 | } | |
359 | } |
|
361 | } | |
360 |
|
362 | |||
361 | domain.setRange(minX, maxX, minY, maxY); |
|
363 | domain.setRange(minX, maxX, minY, maxY); | |
362 | } |
|
364 | } | |
363 |
|
365 | |||
364 | ChartElement *QAreaSeriesPrivate::createGraphics(ChartPresenter *presenter) |
|
366 | ChartElement *QAreaSeriesPrivate::createGraphics(ChartPresenter *presenter) | |
365 | { |
|
367 | { | |
366 | Q_Q(QAreaSeries); |
|
368 | Q_Q(QAreaSeries); | |
367 |
|
369 | |||
368 | AreaChartItem *area = new AreaChartItem(q, presenter); |
|
370 | AreaChartItem *area = new AreaChartItem(q, presenter); | |
369 | if (presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
371 | if (presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
370 | area->upperLineItem()->setAnimation(new XYAnimation(area->upperLineItem())); |
|
372 | area->upperLineItem()->setAnimation(new XYAnimation(area->upperLineItem())); | |
371 | if (q->lowerSeries()) |
|
373 | if (q->lowerSeries()) | |
372 | area->lowerLineItem()->setAnimation(new XYAnimation(area->lowerLineItem())); |
|
374 | area->lowerLineItem()->setAnimation(new XYAnimation(area->lowerLineItem())); | |
373 | } |
|
375 | } | |
374 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
376 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
375 | return area; |
|
377 | return area; | |
376 | } |
|
378 | } | |
377 |
|
379 | |||
378 | QList<LegendMarker *> QAreaSeriesPrivate::createLegendMarker(QLegend *legend) |
|
380 | QList<LegendMarker *> QAreaSeriesPrivate::createLegendMarker(QLegend *legend) | |
379 | { |
|
381 | { | |
380 | Q_Q(QAreaSeries); |
|
382 | Q_Q(QAreaSeries); | |
381 | QList<LegendMarker *> list; |
|
383 | QList<LegendMarker *> list; | |
382 | return list << new AreaLegendMarker(q, legend); |
|
384 | return list << new AreaLegendMarker(q, legend); | |
383 | } |
|
385 | } | |
384 |
|
386 | |||
385 | QList<QLegendMarker*> QAreaSeriesPrivate::createLegendMarkers(QLegend* legend) |
|
387 | QList<QLegendMarker*> QAreaSeriesPrivate::createLegendMarkers(QLegend* legend) | |
386 | { |
|
388 | { | |
387 | Q_UNUSED(legend); |
|
389 | Q_Q(QAreaSeries); | |
388 | // Q_Q(QAreaSeries); |
|
|||
389 | QList<QLegendMarker*> list; |
|
390 | QList<QLegendMarker*> list; | |
390 | // TODO: |
|
391 | return list << new QAreaLegendMarker(q,legend); | |
391 | // return list << new AreaLegendMarker(q,legend); |
|
|||
392 | return list; |
|
|||
393 | } |
|
392 | } | |
394 |
|
393 | |||
395 | void QAreaSeriesPrivate::initializeAxis(QAbstractAxis *axis) |
|
394 | void QAreaSeriesPrivate::initializeAxis(QAbstractAxis *axis) | |
396 | { |
|
395 | { | |
397 | Q_UNUSED(axis); |
|
396 | Q_UNUSED(axis); | |
398 | } |
|
397 | } | |
399 |
|
398 | |||
400 | QAbstractAxis::AxisType QAreaSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const |
|
399 | QAbstractAxis::AxisType QAreaSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const | |
401 | { |
|
400 | { | |
402 | Q_UNUSED(orientation); |
|
401 | Q_UNUSED(orientation); | |
403 | return QAbstractAxis::AxisTypeValue; |
|
402 | return QAbstractAxis::AxisTypeValue; | |
404 | } |
|
403 | } | |
405 |
|
404 | |||
406 | #include "moc_qareaseries.cpp" |
|
405 | #include "moc_qareaseries.cpp" | |
407 | #include "moc_qareaseries_p.cpp" |
|
406 | #include "moc_qareaseries_p.cpp" | |
408 |
|
407 | |||
409 | QTCOMMERCIALCHART_END_NAMESPACE |
|
408 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,85 +1,87 | |||||
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 "qarealegendmarker.h" |
|
21 | #include "qarealegendmarker.h" | |
22 | #include "qarealegendmarker_p.h" |
|
22 | #include "qarealegendmarker_p.h" | |
23 | #include "qareaseries_p.h" |
|
23 | #include "qareaseries_p.h" | |
24 | #include <QAreaSeries> |
|
24 | #include <QAreaSeries> | |
25 | #include <QDebug> |
|
25 | #include <QDebug> | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | QAreaLegendMarker::QAreaLegendMarker(QAreaSeries* series, QLegend *legend, QObject *parent) : |
|
29 | QAreaLegendMarker::QAreaLegendMarker(QAreaSeries* series, QLegend *legend, QObject *parent) : | |
30 | QLegendMarker(*new QAreaLegendMarkerPrivate(this,series,legend), parent) |
|
30 | QLegendMarker(*new QAreaLegendMarkerPrivate(this,series,legend), parent) | |
31 | { |
|
31 | { | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
34 | QAreaLegendMarker::~QAreaLegendMarker() |
|
34 | QAreaLegendMarker::~QAreaLegendMarker() | |
35 | { |
|
35 | { | |
36 | // qDebug() << "deleting Area marker" << this; |
|
36 | // qDebug() << "deleting Area marker" << this; | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | /*! |
|
39 | /*! | |
40 | \internal |
|
40 | \internal | |
41 | */ |
|
41 | */ | |
42 | QAreaLegendMarker::QAreaLegendMarker(QAreaLegendMarkerPrivate &d, QObject *parent) : |
|
42 | QAreaLegendMarker::QAreaLegendMarker(QAreaLegendMarkerPrivate &d, QObject *parent) : | |
43 | QLegendMarker(d, parent) |
|
43 | QLegendMarker(d, parent) | |
44 | { |
|
44 | { | |
45 | } |
|
45 | } | |
46 |
|
46 | |||
47 | QAreaSeries* QAreaLegendMarker::series() |
|
47 | QAreaSeries* QAreaLegendMarker::series() | |
48 | { |
|
48 | { | |
49 | Q_D(QAreaLegendMarker); |
|
49 | Q_D(QAreaLegendMarker); | |
50 | return d->m_series; |
|
50 | return d->m_series; | |
51 | } |
|
51 | } | |
52 |
|
52 | |||
53 | QAreaSeries* QAreaLegendMarker::peerObject() |
|
53 | QAreaSeries* QAreaLegendMarker::peerObject() | |
54 | { |
|
54 | { | |
55 | Q_D(QAreaLegendMarker); |
|
55 | Q_D(QAreaLegendMarker); | |
56 | return d->m_series; |
|
56 | return d->m_series; | |
57 | } |
|
57 | } | |
58 |
|
58 | |||
59 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
59 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
60 |
|
60 | |||
61 | QAreaLegendMarkerPrivate::QAreaLegendMarkerPrivate(QAreaLegendMarker *q, QAreaSeries *series, QLegend *legend) : |
|
61 | QAreaLegendMarkerPrivate::QAreaLegendMarkerPrivate(QAreaLegendMarker *q, QAreaSeries *series, QLegend *legend) : | |
62 | QLegendMarkerPrivate(q,legend), |
|
62 | QLegendMarkerPrivate(q,legend), | |
63 | m_series(series) |
|
63 | m_series(series) | |
64 | { |
|
64 | { | |
|
65 | qDebug() << "QAreaLegendMarkerPrivate created"; | |||
65 | QObject::connect(m_series->d_func(),SIGNAL(updated()), this, SLOT(updated())); |
|
66 | QObject::connect(m_series->d_func(),SIGNAL(updated()), this, SLOT(updated())); | |
66 | QObject::connect(m_series, SIGNAL(nameChanged()), this, SLOT(updated())); |
|
67 | QObject::connect(m_series, SIGNAL(nameChanged()), this, SLOT(updated())); | |
67 | updated(); |
|
68 | updated(); | |
68 | } |
|
69 | } | |
69 |
|
70 | |||
70 | QAreaLegendMarkerPrivate::~QAreaLegendMarkerPrivate() |
|
71 | QAreaLegendMarkerPrivate::~QAreaLegendMarkerPrivate() | |
71 | { |
|
72 | { | |
72 | QObject::disconnect(m_series->d_func(),SIGNAL(updated()), this, SLOT(updated())); |
|
73 | QObject::disconnect(m_series->d_func(),SIGNAL(updated()), this, SLOT(updated())); | |
73 | QObject::disconnect(m_series, SIGNAL(nameChanged()), this, SLOT(updated())); |
|
74 | QObject::disconnect(m_series, SIGNAL(nameChanged()), this, SLOT(updated())); | |
74 | } |
|
75 | } | |
75 |
|
76 | |||
76 | void QAreaLegendMarkerPrivate::updated() |
|
77 | void QAreaLegendMarkerPrivate::updated() | |
77 | { |
|
78 | { | |
|
79 | qDebug() << "QAreaLegendMarkerPrivate::updated"; | |||
78 | m_item->setBrush(m_series->brush()); |
|
80 | m_item->setBrush(m_series->brush()); | |
79 | m_item->setLabel(m_series->name()); |
|
81 | m_item->setLabel(m_series->name()); | |
80 | } |
|
82 | } | |
81 |
|
83 | |||
82 | #include "moc_qarealegendmarker.cpp" |
|
84 | #include "moc_qarealegendmarker.cpp" | |
83 | #include "moc_qarealegendmarker_p.cpp" |
|
85 | #include "moc_qarealegendmarker_p.cpp" | |
84 |
|
86 | |||
85 | QTCOMMERCIALCHART_END_NAMESPACE |
|
87 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,627 +1,626 | |||||
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" // TODO: deprecated |
|
27 | #include "legendmarker_p.h" // TODO: deprecated | |
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 | #include <QLegendMarker> |
|
47 | #include <QLegendMarker> | |
48 | #include "qlegendmarker_p.h" |
|
48 | #include "qlegendmarker_p.h" | |
49 | #include "legendmarkeritem_p.h" |
|
49 | #include "legendmarkeritem_p.h" | |
50 |
|
50 | |||
51 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
51 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
52 |
|
52 | |||
53 | /*! |
|
53 | /*! | |
54 | \class QLegend |
|
54 | \class QLegend | |
55 | \brief Legend object |
|
55 | \brief Legend object | |
56 | \mainclass |
|
56 | \mainclass | |
57 |
|
57 | |||
58 | QLegend is a graphical object, whics displays legend of the chart. Legend state is updated by QChart, when |
|
58 | QLegend is a graphical object, whics displays legend of the chart. Legend state is updated by QChart, when | |
59 | series have been changed. By default, legend is drawn by QChart, but user can set a new parent to legend and |
|
59 | series have been changed. By default, legend is drawn by QChart, but user can set a new parent to legend and | |
60 | handle the drawing manually. |
|
60 | handle the drawing manually. | |
61 | User isn't supposed to create or delete legend objects, but can reference it via QChart class. |
|
61 | User isn't supposed to create or delete legend objects, but can reference it via QChart class. | |
62 |
|
62 | |||
63 | \image examples_percentbarchart_legend.png |
|
63 | \image examples_percentbarchart_legend.png | |
64 |
|
64 | |||
65 | \sa QChart |
|
65 | \sa QChart | |
66 | */ |
|
66 | */ | |
67 | /*! |
|
67 | /*! | |
68 | \qmlclass Legend QLegend |
|
68 | \qmlclass Legend QLegend | |
69 | \brief Legend is part of QtCommercial Chart QML API. |
|
69 | \brief Legend is part of QtCommercial Chart QML API. | |
70 |
|
70 | |||
71 | Legend is a graphical object, whics displays legend of the chart. Legend state is updated by ChartView, when |
|
71 | Legend is a graphical object, whics displays legend of the chart. Legend state is updated by ChartView, when | |
72 | series have been changed. Legend is used via ChartView class. For example: |
|
72 | series have been changed. Legend is used via ChartView class. For example: | |
73 | \code |
|
73 | \code | |
74 | ChartView { |
|
74 | ChartView { | |
75 | legend.visible: true |
|
75 | legend.visible: true | |
76 | legend.alignment: Qt.AlignBottom |
|
76 | legend.alignment: Qt.AlignBottom | |
77 | // Add a few series... |
|
77 | // Add a few series... | |
78 | } |
|
78 | } | |
79 | \endcode |
|
79 | \endcode | |
80 |
|
80 | |||
81 | \image examples_percentbarchart_legend.png |
|
81 | \image examples_percentbarchart_legend.png | |
82 | */ |
|
82 | */ | |
83 |
|
83 | |||
84 | /*! |
|
84 | /*! | |
85 | \property QLegend::alignment |
|
85 | \property QLegend::alignment | |
86 | \brief The alignment of the legend. |
|
86 | \brief The alignment of the legend. | |
87 |
|
87 | |||
88 | Legend paints on the defined position in the chart. The following alignments are supported: |
|
88 | Legend paints on the defined position in the chart. The following alignments are supported: | |
89 | Qt::AlignTop, Qt::AlignBottom, Qt::AlignLeft, Qt::AlignRight. If you set more than one flag the result is undefined. |
|
89 | Qt::AlignTop, Qt::AlignBottom, Qt::AlignLeft, Qt::AlignRight. If you set more than one flag the result is undefined. | |
90 | */ |
|
90 | */ | |
91 | /*! |
|
91 | /*! | |
92 | \qmlproperty Qt.Alignment Legend::alignment |
|
92 | \qmlproperty Qt.Alignment Legend::alignment | |
93 | \brief The alignment of the legend. |
|
93 | \brief The alignment of the legend. | |
94 |
|
94 | |||
95 | Legend paints on the defined position in the chart. The following alignments are supported: |
|
95 | Legend paints on the defined position in the chart. The following alignments are supported: | |
96 | Qt.AlignTop, Qt.AlignBottom, Qt.AlignLeft, Qt.AlignRight. If you set more than one flag the result is undefined. |
|
96 | Qt.AlignTop, Qt.AlignBottom, Qt.AlignLeft, Qt.AlignRight. If you set more than one flag the result is undefined. | |
97 | */ |
|
97 | */ | |
98 |
|
98 | |||
99 | /*! |
|
99 | /*! | |
100 | \property QLegend::backgroundVisible |
|
100 | \property QLegend::backgroundVisible | |
101 | Whether the legend background is visible or not. |
|
101 | Whether the legend background is visible or not. | |
102 | */ |
|
102 | */ | |
103 | /*! |
|
103 | /*! | |
104 | \qmlproperty bool Legend::backgroundVisible |
|
104 | \qmlproperty bool Legend::backgroundVisible | |
105 | Whether the legend background is visible or not. |
|
105 | Whether the legend background is visible or not. | |
106 | */ |
|
106 | */ | |
107 |
|
107 | |||
108 | /*! |
|
108 | /*! | |
109 | \property QLegend::color |
|
109 | \property QLegend::color | |
110 | The color of the legend, i.e. the background (brush) color. Note that if you change the color |
|
110 | The color of the legend, i.e. the background (brush) color. Note that if you change the color | |
111 | of the legend, the style of the legend brush is set to Qt::SolidPattern. |
|
111 | of the legend, the style of the legend brush is set to Qt::SolidPattern. | |
112 | */ |
|
112 | */ | |
113 | /*! |
|
113 | /*! | |
114 | \qmlproperty color Legend::color |
|
114 | \qmlproperty color Legend::color | |
115 | The color of the legend, i.e. the background (brush) color. |
|
115 | The color of the legend, i.e. the background (brush) color. | |
116 | */ |
|
116 | */ | |
117 |
|
117 | |||
118 | /*! |
|
118 | /*! | |
119 | \property QLegend::borderColor |
|
119 | \property QLegend::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 | \qmlproperty color Legend::borderColor |
|
123 | \qmlproperty color Legend::borderColor | |
124 | The border color of the legend, i.e. the line color. |
|
124 | The border color of the legend, i.e. the line color. | |
125 | */ |
|
125 | */ | |
126 |
|
126 | |||
127 | /*! |
|
127 | /*! | |
128 | \property QLegend::font |
|
128 | \property QLegend::font | |
129 | The font of markers used by legend |
|
129 | The font of markers used by legend | |
130 | */ |
|
130 | */ | |
131 | /*! |
|
131 | /*! | |
132 | \qmlproperty Font Legend::font |
|
132 | \qmlproperty Font Legend::font | |
133 | The font of markers used by legend |
|
133 | The font of markers used by legend | |
134 | */ |
|
134 | */ | |
135 |
|
135 | |||
136 | /*! |
|
136 | /*! | |
137 | \property QLegend::labelColor |
|
137 | \property 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 | \qmlproperty color QLegend::labelColor |
|
141 | \qmlproperty color QLegend::labelColor | |
142 | The color of brush used to draw labels. |
|
142 | The color of brush used to draw labels. | |
143 | */ |
|
143 | */ | |
144 |
|
144 | |||
145 | /*! |
|
145 | /*! | |
146 | \fn void QLegend::backgroundVisibleChanged(bool) |
|
146 | \fn void QLegend::backgroundVisibleChanged(bool) | |
147 | The visibility of the legend background changed to \a visible. |
|
147 | The visibility of the legend background changed to \a visible. | |
148 | */ |
|
148 | */ | |
149 |
|
149 | |||
150 | /*! |
|
150 | /*! | |
151 | \fn void QLegend::colorChanged(QColor) |
|
151 | \fn void QLegend::colorChanged(QColor) | |
152 | The color of the legend background changed to \a color. |
|
152 | The color of the legend background changed to \a color. | |
153 | */ |
|
153 | */ | |
154 |
|
154 | |||
155 | /*! |
|
155 | /*! | |
156 | \fn void QLegend::borderColorChanged(QColor) |
|
156 | \fn void QLegend::borderColorChanged(QColor) | |
157 | The border color of the legend background changed to \a color. |
|
157 | The border color of the legend background changed to \a color. | |
158 | */ |
|
158 | */ | |
159 |
|
159 | |||
160 | /*! |
|
160 | /*! | |
161 | \fn void QLegend::fontChanged(QFont) |
|
161 | \fn void QLegend::fontChanged(QFont) | |
162 | The font of markers of the legend changed to \a font. |
|
162 | The font of markers of the legend changed to \a font. | |
163 | */ |
|
163 | */ | |
164 |
|
164 | |||
165 | /*! |
|
165 | /*! | |
166 | \fn void QLegend::labelColorChanged(QColor color) |
|
166 | \fn void QLegend::labelColorChanged(QColor color) | |
167 | This signal is emitted when the color of brush used to draw labels has changed to \a color. |
|
167 | This signal is emitted when the color of brush used to draw labels has changed to \a color. | |
168 | */ |
|
168 | */ | |
169 |
|
169 | |||
170 | /*! |
|
170 | /*! | |
171 | Constructs the legend object and sets the parent to \a parent |
|
171 | Constructs the legend object and sets the parent to \a parent | |
172 | */ |
|
172 | */ | |
173 |
|
173 | |||
174 | QLegend::QLegend(QChart *chart): QGraphicsWidget(chart), |
|
174 | QLegend::QLegend(QChart *chart): QGraphicsWidget(chart), | |
175 | d_ptr(new QLegendPrivate(chart->d_ptr->m_presenter, chart, this)) |
|
175 | d_ptr(new QLegendPrivate(chart->d_ptr->m_presenter, chart, this)) | |
176 | { |
|
176 | { | |
177 | setZValue(ChartPresenter::LegendZValue); |
|
177 | setZValue(ChartPresenter::LegendZValue); | |
178 | setFlags(QGraphicsItem::ItemClipsChildrenToShape); |
|
178 | setFlags(QGraphicsItem::ItemClipsChildrenToShape); | |
179 | QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*)), d_ptr.data(), SLOT(handleSeriesAdded(QAbstractSeries*))); |
|
179 | QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*)), d_ptr.data(), SLOT(handleSeriesAdded(QAbstractSeries*))); | |
180 | QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), d_ptr.data(), SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
180 | QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), d_ptr.data(), SLOT(handleSeriesRemoved(QAbstractSeries*))); | |
181 | // QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesUpdated(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesUpdated(QAbstractSeries*))); |
|
181 | // QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesUpdated(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesUpdated(QAbstractSeries*))); | |
182 | setLayout(d_ptr->m_layout); |
|
182 | setLayout(d_ptr->m_layout); | |
183 | } |
|
183 | } | |
184 |
|
184 | |||
185 | /*! |
|
185 | /*! | |
186 | Destroys the legend object. Legend is always owned by a QChart, so an application should never call this. |
|
186 | Destroys the legend object. Legend is always owned by a QChart, so an application should never call this. | |
187 | */ |
|
187 | */ | |
188 | QLegend::~QLegend() |
|
188 | QLegend::~QLegend() | |
189 | { |
|
189 | { | |
190 | } |
|
190 | } | |
191 |
|
191 | |||
192 | /*! |
|
192 | /*! | |
193 | \internal |
|
193 | \internal | |
194 | */ |
|
194 | */ | |
195 | void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
195 | void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
196 | { |
|
196 | { | |
197 | Q_UNUSED(option) |
|
197 | Q_UNUSED(option) | |
198 | Q_UNUSED(widget) |
|
198 | Q_UNUSED(widget) | |
199 |
|
199 | |||
200 | if (!d_ptr->m_backgroundVisible) |
|
200 | if (!d_ptr->m_backgroundVisible) | |
201 | return; |
|
201 | return; | |
202 |
|
202 | |||
203 | painter->setOpacity(opacity()); |
|
203 | painter->setOpacity(opacity()); | |
204 | painter->setPen(d_ptr->m_pen); |
|
204 | painter->setPen(d_ptr->m_pen); | |
205 | painter->setBrush(d_ptr->m_brush); |
|
205 | painter->setBrush(d_ptr->m_brush); | |
206 | painter->drawRoundRect(rect(), d_ptr->roundness(rect().width()), d_ptr->roundness(rect().height())); |
|
206 | painter->drawRoundRect(rect(), d_ptr->roundness(rect().width()), d_ptr->roundness(rect().height())); | |
207 | } |
|
207 | } | |
208 |
|
208 | |||
209 |
|
209 | |||
210 | /*! |
|
210 | /*! | |
211 | Sets the \a brush of legend. Brush affects the background of legend. |
|
211 | Sets the \a brush of legend. Brush affects the background of legend. | |
212 | */ |
|
212 | */ | |
213 | void QLegend::setBrush(const QBrush &brush) |
|
213 | void QLegend::setBrush(const QBrush &brush) | |
214 | { |
|
214 | { | |
215 | if (d_ptr->m_brush != brush) { |
|
215 | if (d_ptr->m_brush != brush) { | |
216 | d_ptr->m_brush = brush; |
|
216 | d_ptr->m_brush = brush; | |
217 | update(); |
|
217 | update(); | |
218 | emit colorChanged(brush.color()); |
|
218 | emit colorChanged(brush.color()); | |
219 | } |
|
219 | } | |
220 | } |
|
220 | } | |
221 |
|
221 | |||
222 | /*! |
|
222 | /*! | |
223 | Returns the brush used by legend. |
|
223 | Returns the brush used by legend. | |
224 | */ |
|
224 | */ | |
225 | QBrush QLegend::brush() const |
|
225 | QBrush QLegend::brush() const | |
226 | { |
|
226 | { | |
227 | return d_ptr->m_brush; |
|
227 | return d_ptr->m_brush; | |
228 | } |
|
228 | } | |
229 |
|
229 | |||
230 | void QLegend::setColor(QColor color) |
|
230 | void QLegend::setColor(QColor color) | |
231 | { |
|
231 | { | |
232 | QBrush b = d_ptr->m_brush; |
|
232 | QBrush b = d_ptr->m_brush; | |
233 | if (b.style() != Qt::SolidPattern || b.color() != color) { |
|
233 | if (b.style() != Qt::SolidPattern || b.color() != color) { | |
234 | b.setStyle(Qt::SolidPattern); |
|
234 | b.setStyle(Qt::SolidPattern); | |
235 | b.setColor(color); |
|
235 | b.setColor(color); | |
236 | setBrush(b); |
|
236 | setBrush(b); | |
237 | } |
|
237 | } | |
238 | } |
|
238 | } | |
239 |
|
239 | |||
240 | QColor QLegend::color() |
|
240 | QColor QLegend::color() | |
241 | { |
|
241 | { | |
242 | return d_ptr->m_brush.color(); |
|
242 | return d_ptr->m_brush.color(); | |
243 | } |
|
243 | } | |
244 |
|
244 | |||
245 | /*! |
|
245 | /*! | |
246 | Sets the \a pen of legend. Pen affects the legend borders. |
|
246 | Sets the \a pen of legend. Pen affects the legend borders. | |
247 | */ |
|
247 | */ | |
248 | void QLegend::setPen(const QPen &pen) |
|
248 | void QLegend::setPen(const QPen &pen) | |
249 | { |
|
249 | { | |
250 | if (d_ptr->m_pen != pen) { |
|
250 | if (d_ptr->m_pen != pen) { | |
251 | d_ptr->m_pen = pen; |
|
251 | d_ptr->m_pen = pen; | |
252 | update(); |
|
252 | update(); | |
253 | emit borderColorChanged(pen.color()); |
|
253 | emit borderColorChanged(pen.color()); | |
254 | } |
|
254 | } | |
255 | } |
|
255 | } | |
256 |
|
256 | |||
257 | /*! |
|
257 | /*! | |
258 | Returns the pen used by legend |
|
258 | Returns the pen used by legend | |
259 | */ |
|
259 | */ | |
260 |
|
260 | |||
261 | QPen QLegend::pen() const |
|
261 | QPen QLegend::pen() const | |
262 | { |
|
262 | { | |
263 | return d_ptr->m_pen; |
|
263 | return d_ptr->m_pen; | |
264 | } |
|
264 | } | |
265 |
|
265 | |||
266 | void QLegend::setFont(const QFont &font) |
|
266 | void QLegend::setFont(const QFont &font) | |
267 | { |
|
267 | { | |
268 | if (d_ptr->m_font != font) { |
|
268 | if (d_ptr->m_font != font) { | |
269 | d_ptr->m_font = font; |
|
269 | d_ptr->m_font = font; | |
270 | foreach (LegendMarker *marker, d_ptr->markers()) |
|
270 | foreach (LegendMarker *marker, d_ptr->markers()) | |
271 | marker->setFont(d_ptr->m_font); |
|
271 | marker->setFont(d_ptr->m_font); | |
272 | layout()->invalidate(); |
|
272 | layout()->invalidate(); | |
273 | emit fontChanged(font); |
|
273 | emit fontChanged(font); | |
274 | } |
|
274 | } | |
275 | } |
|
275 | } | |
276 |
|
276 | |||
277 | QFont QLegend::font() const |
|
277 | QFont QLegend::font() const | |
278 | { |
|
278 | { | |
279 | return d_ptr->m_font; |
|
279 | return d_ptr->m_font; | |
280 | } |
|
280 | } | |
281 |
|
281 | |||
282 | void QLegend::setBorderColor(QColor color) |
|
282 | void QLegend::setBorderColor(QColor color) | |
283 | { |
|
283 | { | |
284 | QPen p = d_ptr->m_pen; |
|
284 | QPen p = d_ptr->m_pen; | |
285 | if (p.color() != color) { |
|
285 | if (p.color() != color) { | |
286 | p.setColor(color); |
|
286 | p.setColor(color); | |
287 | setPen(p); |
|
287 | setPen(p); | |
288 | } |
|
288 | } | |
289 | } |
|
289 | } | |
290 |
|
290 | |||
291 | QColor QLegend::borderColor() |
|
291 | QColor QLegend::borderColor() | |
292 | { |
|
292 | { | |
293 | return d_ptr->m_pen.color(); |
|
293 | return d_ptr->m_pen.color(); | |
294 | } |
|
294 | } | |
295 |
|
295 | |||
296 | /*! |
|
296 | /*! | |
297 | Set brush used to draw labels to \a brush. |
|
297 | Set brush used to draw labels to \a brush. | |
298 | */ |
|
298 | */ | |
299 | void QLegend::setLabelBrush(const QBrush &brush) |
|
299 | void QLegend::setLabelBrush(const QBrush &brush) | |
300 | { |
|
300 | { | |
301 | if (d_ptr->m_labelBrush != brush) { |
|
301 | if (d_ptr->m_labelBrush != brush) { | |
302 | d_ptr->m_labelBrush = brush; |
|
302 | d_ptr->m_labelBrush = brush; | |
303 | foreach (LegendMarker *marker, d_ptr->markers()) { |
|
303 | foreach (LegendMarker *marker, d_ptr->markers()) { | |
304 | marker->setLabelBrush(d_ptr->m_labelBrush); |
|
304 | marker->setLabelBrush(d_ptr->m_labelBrush); | |
305 | // Note: The pen of the marker rectangle could be exposed in the public QLegend API |
|
305 | // Note: The pen of the marker rectangle could be exposed in the public QLegend API | |
306 | // instead of mapping it from label brush color |
|
306 | // instead of mapping it from label brush color | |
307 | marker->setPen(brush.color()); |
|
307 | marker->setPen(brush.color()); | |
308 | } |
|
308 | } | |
309 | emit labelColorChanged(brush.color()); |
|
309 | emit labelColorChanged(brush.color()); | |
310 | } |
|
310 | } | |
311 | } |
|
311 | } | |
312 |
|
312 | |||
313 | /*! |
|
313 | /*! | |
314 | Brush used to draw labels. |
|
314 | Brush used to draw labels. | |
315 | */ |
|
315 | */ | |
316 | QBrush QLegend::labelBrush() const |
|
316 | QBrush QLegend::labelBrush() const | |
317 | { |
|
317 | { | |
318 | return d_ptr->m_labelBrush; |
|
318 | return d_ptr->m_labelBrush; | |
319 | } |
|
319 | } | |
320 |
|
320 | |||
321 | void QLegend::setLabelColor(QColor color) |
|
321 | void QLegend::setLabelColor(QColor color) | |
322 | { |
|
322 | { | |
323 | QBrush b = d_ptr->m_labelBrush; |
|
323 | QBrush b = d_ptr->m_labelBrush; | |
324 | if (b.style() != Qt::SolidPattern || b.color() != color) { |
|
324 | if (b.style() != Qt::SolidPattern || b.color() != color) { | |
325 | b.setStyle(Qt::SolidPattern); |
|
325 | b.setStyle(Qt::SolidPattern); | |
326 | b.setColor(color); |
|
326 | b.setColor(color); | |
327 | setLabelBrush(b); |
|
327 | setLabelBrush(b); | |
328 | } |
|
328 | } | |
329 | } |
|
329 | } | |
330 |
|
330 | |||
331 | QColor QLegend::labelColor() const |
|
331 | QColor QLegend::labelColor() const | |
332 | { |
|
332 | { | |
333 | return d_ptr->m_labelBrush.color(); |
|
333 | return d_ptr->m_labelBrush.color(); | |
334 | } |
|
334 | } | |
335 |
|
335 | |||
336 |
|
336 | |||
337 | void QLegend::setAlignment(Qt::Alignment alignment) |
|
337 | void QLegend::setAlignment(Qt::Alignment alignment) | |
338 | { |
|
338 | { | |
339 | if (d_ptr->m_alignment != alignment) { |
|
339 | if (d_ptr->m_alignment != alignment) { | |
340 | d_ptr->m_alignment = alignment; |
|
340 | d_ptr->m_alignment = alignment; | |
341 | layout()->invalidate(); |
|
341 | layout()->invalidate(); | |
342 | } |
|
342 | } | |
343 | } |
|
343 | } | |
344 |
|
344 | |||
345 | Qt::Alignment QLegend::alignment() const |
|
345 | Qt::Alignment QLegend::alignment() const | |
346 | { |
|
346 | { | |
347 | return d_ptr->m_alignment; |
|
347 | return d_ptr->m_alignment; | |
348 | } |
|
348 | } | |
349 |
|
349 | |||
350 | /*! |
|
350 | /*! | |
351 | Detaches the legend from chart. Chart won't change layout of the legend. |
|
351 | Detaches the legend from chart. Chart won't change layout of the legend. | |
352 | */ |
|
352 | */ | |
353 | void QLegend::detachFromChart() |
|
353 | void QLegend::detachFromChart() | |
354 | { |
|
354 | { | |
355 | d_ptr->m_attachedToChart = false; |
|
355 | d_ptr->m_attachedToChart = false; | |
356 | layout()->invalidate(); |
|
356 | layout()->invalidate(); | |
357 | setParent(0); |
|
357 | setParent(0); | |
358 |
|
358 | |||
359 | } |
|
359 | } | |
360 |
|
360 | |||
361 | /*! |
|
361 | /*! | |
362 | Attaches the legend to chart. Chart may change layout of the legend. |
|
362 | Attaches the legend to chart. Chart may change layout of the legend. | |
363 | */ |
|
363 | */ | |
364 | void QLegend::attachToChart() |
|
364 | void QLegend::attachToChart() | |
365 | { |
|
365 | { | |
366 | d_ptr->m_attachedToChart = true; |
|
366 | d_ptr->m_attachedToChart = true; | |
367 | layout()->invalidate(); |
|
367 | layout()->invalidate(); | |
368 | setParent(d_ptr->m_chart); |
|
368 | setParent(d_ptr->m_chart); | |
369 | } |
|
369 | } | |
370 |
|
370 | |||
371 | /*! |
|
371 | /*! | |
372 | Returns true, if legend is attached to chart. |
|
372 | Returns true, if legend is attached to chart. | |
373 | */ |
|
373 | */ | |
374 | bool QLegend::isAttachedToChart() |
|
374 | bool QLegend::isAttachedToChart() | |
375 | { |
|
375 | { | |
376 | return d_ptr->m_attachedToChart; |
|
376 | return d_ptr->m_attachedToChart; | |
377 | } |
|
377 | } | |
378 |
|
378 | |||
379 | /*! |
|
379 | /*! | |
380 | Sets the visibility of legend background to \a visible |
|
380 | Sets the visibility of legend background to \a visible | |
381 | */ |
|
381 | */ | |
382 | void QLegend::setBackgroundVisible(bool visible) |
|
382 | void QLegend::setBackgroundVisible(bool visible) | |
383 | { |
|
383 | { | |
384 | if (d_ptr->m_backgroundVisible != visible) { |
|
384 | if (d_ptr->m_backgroundVisible != visible) { | |
385 | d_ptr->m_backgroundVisible = visible; |
|
385 | d_ptr->m_backgroundVisible = visible; | |
386 | update(); |
|
386 | update(); | |
387 | emit backgroundVisibleChanged(visible); |
|
387 | emit backgroundVisibleChanged(visible); | |
388 | } |
|
388 | } | |
389 | } |
|
389 | } | |
390 |
|
390 | |||
391 | /*! |
|
391 | /*! | |
392 | Returns the visibility of legend background |
|
392 | Returns the visibility of legend background | |
393 | */ |
|
393 | */ | |
394 | bool QLegend::isBackgroundVisible() const |
|
394 | bool QLegend::isBackgroundVisible() const | |
395 | { |
|
395 | { | |
396 | return d_ptr->m_backgroundVisible; |
|
396 | return d_ptr->m_backgroundVisible; | |
397 | } |
|
397 | } | |
398 |
|
398 | |||
399 |
|
399 | |||
400 | QList<QLegendMarker*> QLegend::markers() const |
|
400 | QList<QLegendMarker*> QLegend::markers() const | |
401 | { |
|
401 | { | |
402 | // TODO: name of PIMPL method will change. |
|
402 | // TODO: name of PIMPL method will change. | |
403 | return d_ptr->legendMarkers(); |
|
403 | return d_ptr->legendMarkers(); | |
404 | } |
|
404 | } | |
405 |
|
405 | |||
406 | void QLegend::appendSeries(QAbstractSeries* series) |
|
406 | void QLegend::appendSeries(QAbstractSeries* series) | |
407 | { |
|
407 | { | |
408 | d_ptr->appendSeries(series); |
|
408 | d_ptr->appendSeries(series); | |
409 | } |
|
409 | } | |
410 |
|
410 | |||
411 | void QLegend::removeSeries(QAbstractSeries* series) |
|
411 | void QLegend::removeSeries(QAbstractSeries* series) | |
412 | { |
|
412 | { | |
413 | d_ptr->removeSeries(series); |
|
413 | d_ptr->removeSeries(series); | |
414 | } |
|
414 | } | |
415 |
|
415 | |||
416 | /*! |
|
416 | /*! | |
417 | \internal \a event see QGraphicsWidget for details |
|
417 | \internal \a event see QGraphicsWidget for details | |
418 | */ |
|
418 | */ | |
419 | void QLegend::hideEvent(QHideEvent *event) |
|
419 | void QLegend::hideEvent(QHideEvent *event) | |
420 | { |
|
420 | { | |
421 | if (isAttachedToChart()) |
|
421 | if (isAttachedToChart()) | |
422 | d_ptr->m_presenter->layout()->invalidate(); |
|
422 | d_ptr->m_presenter->layout()->invalidate(); | |
423 | QGraphicsWidget::hideEvent(event); |
|
423 | QGraphicsWidget::hideEvent(event); | |
424 | } |
|
424 | } | |
425 | /*! |
|
425 | /*! | |
426 | \internal \a event see QGraphicsWidget for details |
|
426 | \internal \a event see QGraphicsWidget for details | |
427 | */ |
|
427 | */ | |
428 | void QLegend::showEvent(QShowEvent *event) |
|
428 | void QLegend::showEvent(QShowEvent *event) | |
429 | { |
|
429 | { | |
430 | if (isAttachedToChart()) { |
|
430 | if (isAttachedToChart()) { | |
431 | d_ptr->items()->setVisible(false); |
|
431 | d_ptr->items()->setVisible(false); | |
432 | layout()->invalidate(); |
|
432 | layout()->invalidate(); | |
433 | } |
|
433 | } | |
434 | QGraphicsWidget::showEvent(event); |
|
434 | QGraphicsWidget::showEvent(event); | |
435 | //layout activation will show the items |
|
435 | //layout activation will show the items | |
436 | } |
|
436 | } | |
437 |
|
437 | |||
438 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
438 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
439 |
|
439 | |||
440 | QLegendPrivate::QLegendPrivate(ChartPresenter *presenter, QChart *chart, QLegend *q) |
|
440 | QLegendPrivate::QLegendPrivate(ChartPresenter *presenter, QChart *chart, QLegend *q) | |
441 | : q_ptr(q), |
|
441 | : q_ptr(q), | |
442 | m_presenter(presenter), |
|
442 | m_presenter(presenter), | |
443 | m_layout(new LegendLayout(q)), |
|
443 | m_layout(new LegendLayout(q)), | |
444 | m_chart(chart), |
|
444 | m_chart(chart), | |
445 | m_items(new QGraphicsItemGroup(q)), |
|
445 | m_items(new QGraphicsItemGroup(q)), | |
446 | m_alignment(Qt::AlignTop), |
|
446 | m_alignment(Qt::AlignTop), | |
447 | m_brush(QBrush()), |
|
447 | m_brush(QBrush()), | |
448 | m_pen(QPen()), |
|
448 | m_pen(QPen()), | |
449 | m_labelBrush(QBrush()), |
|
449 | m_labelBrush(QBrush()), | |
450 | m_diameter(5), |
|
450 | m_diameter(5), | |
451 | m_attachedToChart(true), |
|
451 | m_attachedToChart(true), | |
452 | m_backgroundVisible(false) |
|
452 | m_backgroundVisible(false) | |
453 | { |
|
453 | { | |
454 | m_items->setHandlesChildEvents(false); |
|
454 | m_items->setHandlesChildEvents(false); | |
455 | } |
|
455 | } | |
456 |
|
456 | |||
457 | QLegendPrivate::~QLegendPrivate() |
|
457 | QLegendPrivate::~QLegendPrivate() | |
458 | { |
|
458 | { | |
459 |
|
459 | |||
460 | } |
|
460 | } | |
461 |
|
461 | |||
462 | void QLegendPrivate::setOffset(qreal x, qreal y) |
|
462 | void QLegendPrivate::setOffset(qreal x, qreal y) | |
463 | { |
|
463 | { | |
464 | m_layout->setOffset(x, y); |
|
464 | m_layout->setOffset(x, y); | |
465 | } |
|
465 | } | |
466 |
|
466 | |||
467 | QPointF QLegendPrivate::offset() const |
|
467 | QPointF QLegendPrivate::offset() const | |
468 | { |
|
468 | { | |
469 | return m_layout->offset(); |
|
469 | return m_layout->offset(); | |
470 | } |
|
470 | } | |
471 |
|
471 | |||
472 | int QLegendPrivate::roundness(qreal size) |
|
472 | int QLegendPrivate::roundness(qreal size) | |
473 | { |
|
473 | { | |
474 | return 100 * m_diameter / int(size); |
|
474 | return 100 * m_diameter / int(size); | |
475 | } |
|
475 | } | |
476 |
|
476 | |||
477 | void QLegendPrivate::appendSeries(QAbstractSeries* series) |
|
477 | void QLegendPrivate::appendSeries(QAbstractSeries* series) | |
478 | { |
|
478 | { | |
479 | // Only allow one instance of series |
|
479 | // Only allow one instance of series | |
480 | if (m_series.contains(series)) { |
|
480 | if (m_series.contains(series)) { | |
481 | qDebug() << "series already added" << series; |
|
481 | qDebug() << "series already added" << series; | |
482 | return; |
|
482 | return; | |
483 | } |
|
483 | } | |
484 |
|
484 | |||
485 | QList<QLegendMarker*> newMarkers = series->d_ptr->createLegendMarkers(q_ptr); |
|
485 | QList<QLegendMarker*> newMarkers = series->d_ptr->createLegendMarkers(q_ptr); | |
486 | foreach (QLegendMarker* marker, newMarkers) { |
|
486 | foreach (QLegendMarker* marker, newMarkers) { | |
487 | marker->setFont(m_font); |
|
487 | marker->setFont(m_font); | |
488 | marker->setLabelBrush(m_labelBrush); |
|
488 | marker->setLabelBrush(m_labelBrush); | |
489 | marker->setVisible(series->isVisible()); |
|
489 | marker->setVisible(series->isVisible()); | |
490 | m_items->addToGroup(marker->d_ptr.data()->item()); |
|
490 | m_items->addToGroup(marker->d_ptr.data()->item()); | |
491 | m_legendMarkers << marker; |
|
491 | m_legendMarkers << marker; | |
492 | } |
|
492 | } | |
493 |
|
493 | |||
494 | // TODO: This is the part I don't like. There should be better solution. |
|
494 | // TODO: This is the part I don't like. There should be better solution. | |
495 | // On the other hand. It is only one switch case for appending and another for removing series |
|
495 | // On the other hand. It is only one switch case for appending and another for removing series | |
496 | // If countChanged signal were on QAbstractSeries, there would be no need for switch at all. |
|
496 | // If countChanged signal were on QAbstractSeries, there would be no need for switch at all. | |
497 | switch (series->type()) |
|
497 | switch (series->type()) | |
498 | { |
|
498 | { | |
499 | case QAbstractSeries::SeriesTypePie: { |
|
499 | case QAbstractSeries::SeriesTypePie: { | |
500 | QPieSeries *s = qobject_cast<QPieSeries *> (series); |
|
500 | QPieSeries *s = qobject_cast<QPieSeries *> (series); | |
501 | QObject::connect(s, SIGNAL(countChanged()), this, SLOT(handleSeriesUpdated())); |
|
501 | QObject::connect(s, SIGNAL(countChanged()), this, SLOT(handleSeriesUpdated())); | |
502 | break; |
|
502 | break; | |
503 | } |
|
503 | } | |
504 | case QAbstractSeries::SeriesTypeBar: |
|
504 | case QAbstractSeries::SeriesTypeBar: | |
505 | case QAbstractSeries::SeriesTypeStackedBar: |
|
505 | case QAbstractSeries::SeriesTypeStackedBar: | |
506 | case QAbstractSeries::SeriesTypePercentBar: |
|
506 | case QAbstractSeries::SeriesTypePercentBar: | |
507 | case QAbstractSeries::SeriesTypeHorizontalBar: |
|
507 | case QAbstractSeries::SeriesTypeHorizontalBar: | |
508 | case QAbstractSeries::SeriesTypeHorizontalStackedBar: |
|
508 | case QAbstractSeries::SeriesTypeHorizontalStackedBar: | |
509 | case QAbstractSeries::SeriesTypeHorizontalPercentBar: { |
|
509 | case QAbstractSeries::SeriesTypeHorizontalPercentBar: { | |
510 | QAbstractBarSeries *s = qobject_cast<QAbstractBarSeries *> (series); |
|
510 | QAbstractBarSeries *s = qobject_cast<QAbstractBarSeries *> (series); | |
511 | QObject::connect(s, SIGNAL(countChanged()), this, SLOT(handleSeriesUpdated())); |
|
511 | QObject::connect(s, SIGNAL(countChanged()), this, SLOT(handleSeriesUpdated())); | |
512 | break; |
|
512 | break; | |
513 | } |
|
513 | } | |
514 | // TODO: |
|
|||
515 | case QAbstractSeries::SeriesTypeLine: |
|
514 | case QAbstractSeries::SeriesTypeLine: | |
516 | case QAbstractSeries::SeriesTypeArea: |
|
515 | case QAbstractSeries::SeriesTypeArea: | |
517 | case QAbstractSeries::SeriesTypeScatter: |
|
516 | case QAbstractSeries::SeriesTypeScatter: | |
518 | case QAbstractSeries::SeriesTypeSpline: |
|
517 | case QAbstractSeries::SeriesTypeSpline: | |
519 | default: { |
|
518 | default: { | |
520 |
// No need to connect any series related signals |
|
519 | // No need to connect any series related signals. We have no series level | |
521 | qDebug() << "Not yet implemented"; |
|
520 | // changes, that would generate or delete markers | |
522 | } |
|
521 | } | |
523 | } |
|
522 | } | |
524 |
|
523 | |||
525 | QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); |
|
524 | QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); | |
526 |
|
525 | |||
527 | m_series.append(series); |
|
526 | m_series.append(series); | |
528 | m_items->setVisible(false); |
|
527 | m_items->setVisible(false); | |
529 | m_layout->invalidate(); |
|
528 | m_layout->invalidate(); | |
530 | } |
|
529 | } | |
531 |
|
530 | |||
532 | void QLegendPrivate::removeSeries(QAbstractSeries* series) |
|
531 | void QLegendPrivate::removeSeries(QAbstractSeries* series) | |
533 | { |
|
532 | { | |
534 | if (m_series.contains(series)) { |
|
533 | if (m_series.contains(series)) { | |
535 | m_series.removeOne(series); |
|
534 | m_series.removeOne(series); | |
536 | } |
|
535 | } | |
537 |
|
536 | |||
538 | foreach (QLegendMarker *marker, m_legendMarkers) { |
|
537 | foreach (QLegendMarker *marker, m_legendMarkers) { | |
539 | if (marker->series() == series) { |
|
538 | if (marker->series() == series) { | |
540 | marker->d_ptr.data()->item()->setVisible(false); |
|
539 | marker->d_ptr.data()->item()->setVisible(false); | |
541 | m_items->removeFromGroup(marker->d_ptr.data()->item()); |
|
540 | m_items->removeFromGroup(marker->d_ptr.data()->item()); | |
542 | delete marker; |
|
541 | delete marker; | |
543 | m_legendMarkers.removeAll(marker); |
|
542 | m_legendMarkers.removeAll(marker); | |
544 | } |
|
543 | } | |
545 | } |
|
544 | } | |
546 |
|
545 | |||
547 | switch (series->type()) |
|
546 | switch (series->type()) | |
548 | { |
|
547 | { | |
549 | case QAbstractSeries::SeriesTypePie: { |
|
548 | case QAbstractSeries::SeriesTypePie: { | |
550 | QPieSeries *s = qobject_cast<QPieSeries *> (series); |
|
549 | QPieSeries *s = qobject_cast<QPieSeries *> (series); | |
551 | QObject::disconnect(s, SIGNAL(countChanged()), this, SLOT(handleSeriesUpdated())); |
|
550 | QObject::disconnect(s, SIGNAL(countChanged()), this, SLOT(handleSeriesUpdated())); | |
552 | break; |
|
551 | break; | |
553 | } |
|
552 | } | |
554 | case QAbstractSeries::SeriesTypeBar: |
|
553 | case QAbstractSeries::SeriesTypeBar: | |
555 | case QAbstractSeries::SeriesTypeStackedBar: |
|
554 | case QAbstractSeries::SeriesTypeStackedBar: | |
556 | case QAbstractSeries::SeriesTypePercentBar: |
|
555 | case QAbstractSeries::SeriesTypePercentBar: | |
557 | case QAbstractSeries::SeriesTypeHorizontalBar: |
|
556 | case QAbstractSeries::SeriesTypeHorizontalBar: | |
558 | case QAbstractSeries::SeriesTypeHorizontalStackedBar: |
|
557 | case QAbstractSeries::SeriesTypeHorizontalStackedBar: | |
559 | case QAbstractSeries::SeriesTypeHorizontalPercentBar: { |
|
558 | case QAbstractSeries::SeriesTypeHorizontalPercentBar: { | |
560 | QAbstractBarSeries *s = qobject_cast<QAbstractBarSeries *> (series); |
|
559 | QAbstractBarSeries *s = qobject_cast<QAbstractBarSeries *> (series); | |
561 | QObject::disconnect(s, SIGNAL(countChanged()), this, SLOT(handleSeriesUpdated())); |
|
560 | QObject::disconnect(s, SIGNAL(countChanged()), this, SLOT(handleSeriesUpdated())); | |
562 | break; |
|
561 | break; | |
563 | } |
|
562 | } | |
564 | // TODO: |
|
563 | // TODO: | |
565 | case QAbstractSeries::SeriesTypeLine: |
|
564 | case QAbstractSeries::SeriesTypeLine: | |
566 | case QAbstractSeries::SeriesTypeArea: |
|
565 | case QAbstractSeries::SeriesTypeArea: | |
567 | case QAbstractSeries::SeriesTypeScatter: |
|
566 | case QAbstractSeries::SeriesTypeScatter: | |
568 | case QAbstractSeries::SeriesTypeSpline: |
|
567 | case QAbstractSeries::SeriesTypeSpline: | |
569 | default: { |
|
568 | default: { | |
570 |
// No need to disconnect any series related signals |
|
569 | // No need to disconnect any series related signals | |
571 | break; |
|
570 | break; | |
572 | } |
|
571 | } | |
573 | } |
|
572 | } | |
574 |
|
573 | |||
575 |
|
574 | |||
576 | QObject::disconnect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); |
|
575 | QObject::disconnect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); | |
577 | // QObject::disconnect(series->d_ptr.data(), SIGNAL(legendPropertiesUpdated(QAbstractSeries*)), this, SLOT(handleLegendPropertiesUpdated(QAbstractSeries*))); |
|
576 | // QObject::disconnect(series->d_ptr.data(), SIGNAL(legendPropertiesUpdated(QAbstractSeries*)), this, SLOT(handleLegendPropertiesUpdated(QAbstractSeries*))); | |
578 |
|
577 | |||
579 | m_layout->invalidate(); |
|
578 | m_layout->invalidate(); | |
580 | // q_ptr->layout()->activate(); |
|
579 | // q_ptr->layout()->activate(); | |
581 | } |
|
580 | } | |
582 |
|
581 | |||
583 | void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series) |
|
582 | void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series) | |
584 | { |
|
583 | { | |
585 | // Moved to appendSeries |
|
584 | // Moved to appendSeries | |
586 | // This slot is just to make old code work for now. |
|
585 | // This slot is just to make old code work for now. | |
587 | appendSeries(series); |
|
586 | appendSeries(series); | |
588 | } |
|
587 | } | |
589 |
|
588 | |||
590 | void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series) |
|
589 | void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series) | |
591 | { |
|
590 | { | |
592 | // Moved to removeSeries |
|
591 | // Moved to removeSeries | |
593 | // This slot is just to make old code work for now. |
|
592 | // This slot is just to make old code work for now. | |
594 | removeSeries(series); |
|
593 | removeSeries(series); | |
595 | } |
|
594 | } | |
596 |
|
595 | |||
597 | void QLegendPrivate::handleSeriesVisibleChanged() |
|
596 | void QLegendPrivate::handleSeriesVisibleChanged() | |
598 | { |
|
597 | { | |
599 | QAbstractSeries *series = qobject_cast<QAbstractSeries *> (sender()); |
|
598 | QAbstractSeries *series = qobject_cast<QAbstractSeries *> (sender()); | |
600 | Q_ASSERT(series); |
|
599 | Q_ASSERT(series); | |
601 |
|
600 | |||
602 | foreach (QLegendMarker* marker, m_legendMarkers) { |
|
601 | foreach (QLegendMarker* marker, m_legendMarkers) { | |
603 | if (marker->series() == series) { |
|
602 | if (marker->series() == series) { | |
604 | marker->setVisible(series->isVisible()); |
|
603 | marker->setVisible(series->isVisible()); | |
605 | } |
|
604 | } | |
606 | } |
|
605 | } | |
607 | m_layout->invalidate(); |
|
606 | m_layout->invalidate(); | |
608 | } |
|
607 | } | |
609 |
|
608 | |||
610 | void QLegendPrivate::handleCountChanged() |
|
609 | void QLegendPrivate::handleCountChanged() | |
611 | { |
|
610 | { | |
612 | // TODO: With new markers, the series should notify markers directly. |
|
611 | // TODO: With new markers, the series should notify markers directly. | |
613 | // TODO: Better way to handle updates |
|
612 | // TODO: Better way to handle updates. Remove/Add series again seems like overkill. | |
614 |
|
613 | |||
615 | QAbstractSeries *series = qobject_cast<QAbstractSeries *> (sender()); |
|
614 | QAbstractSeries *series = qobject_cast<QAbstractSeries *> (sender()); | |
616 | qDebug() << "QLegendPrivate::handleSeriesUpdated" << series; |
|
615 | qDebug() << "QLegendPrivate::handleSeriesUpdated" << series; | |
617 |
|
616 | |||
618 | // Handle new or removed markers |
|
617 | // Handle new or removed markers | |
619 | // Handle changes of marker pen/brush/label. every property that legend is interested |
|
618 | // Handle changes of marker pen/brush/label. every property that legend is interested | |
620 | handleSeriesRemoved(series); |
|
619 | handleSeriesRemoved(series); | |
621 | handleSeriesAdded(series); |
|
620 | handleSeriesAdded(series); | |
622 | } |
|
621 | } | |
623 |
|
622 | |||
624 | #include "moc_qlegend.cpp" |
|
623 | #include "moc_qlegend.cpp" | |
625 | #include "moc_qlegend_p.cpp" |
|
624 | #include "moc_qlegend_p.cpp" | |
626 |
|
625 | |||
627 | QTCOMMERCIALCHART_END_NAMESPACE |
|
626 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now