##// END OF EJS Templates
Fixed decoration of QLegend
Tero Ahola -
r1455:ed7ab8a85450
parent child
Show More
@@ -1,385 +1,383
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 "charttheme_p.h"
21 #include "charttheme_p.h"
22 #include "qchart.h"
22 #include "qchart.h"
23 #include "qchart_p.h"
23 #include "qchart_p.h"
24 #include "qchartview.h"
24 #include "qchartview.h"
25 #include "qlegend.h"
25 #include "qlegend.h"
26 #include "qaxis.h"
26 #include "qaxis.h"
27 #include <QTime>
27 #include <QTime>
28
28
29 //series
29 //series
30 #include "qbarset.h"
30 #include "qbarset.h"
31 #include "qbarseries.h"
31 #include "qbarseries.h"
32 #include "qstackedbarseries.h"
32 #include "qstackedbarseries.h"
33 #include "qpercentbarseries.h"
33 #include "qpercentbarseries.h"
34 #include "qlineseries.h"
34 #include "qlineseries.h"
35 #include "qareaseries.h"
35 #include "qareaseries.h"
36 #include "qscatterseries.h"
36 #include "qscatterseries.h"
37 #include "qpieseries.h"
37 #include "qpieseries.h"
38 #include "qpieslice.h"
38 #include "qpieslice.h"
39 #include "qpieslice_p.h"
39 #include "qpieslice_p.h"
40 #include "qsplineseries.h"
40 #include "qsplineseries.h"
41
41
42 //items
42 //items
43 #include "chartaxis_p.h"
43 #include "chartaxis_p.h"
44 #include "barchartitem_p.h"
44 #include "barchartitem_p.h"
45 #include "stackedbarchartitem_p.h"
45 #include "stackedbarchartitem_p.h"
46 #include "percentbarchartitem_p.h"
46 #include "percentbarchartitem_p.h"
47 #include "linechartitem_p.h"
47 #include "linechartitem_p.h"
48 #include "areachartitem_p.h"
48 #include "areachartitem_p.h"
49 #include "scatterchartitem_p.h"
49 #include "scatterchartitem_p.h"
50 #include "piechartitem_p.h"
50 #include "piechartitem_p.h"
51 #include "splinechartitem_p.h"
51 #include "splinechartitem_p.h"
52
52
53 //themes
53 //themes
54 #include "chartthemesystem_p.h"
54 #include "chartthemesystem_p.h"
55 #include "chartthemelight_p.h"
55 #include "chartthemelight_p.h"
56 #include "chartthemebluecerulean_p.h"
56 #include "chartthemebluecerulean_p.h"
57 #include "chartthemedark_p.h"
57 #include "chartthemedark_p.h"
58 #include "chartthemebrownsand_p.h"
58 #include "chartthemebrownsand_p.h"
59 #include "chartthemebluencs_p.h"
59 #include "chartthemebluencs_p.h"
60 #include "chartthemehighcontrast_p.h"
60 #include "chartthemehighcontrast_p.h"
61 #include "chartthemeblueicy_p.h"
61 #include "chartthemeblueicy_p.h"
62
62
63 QTCOMMERCIALCHART_BEGIN_NAMESPACE
63 QTCOMMERCIALCHART_BEGIN_NAMESPACE
64
64
65 ChartTheme::ChartTheme(QChart::ChartTheme id) :
65 ChartTheme::ChartTheme(QChart::ChartTheme id) :
66 m_masterFont(QFont("arial", 14)),
66 m_masterFont(QFont("arial", 14)),
67 m_labelFont(QFont("arial", 10)),
67 m_labelFont(QFont("arial", 10)),
68 m_titleBrush(QColor(QRgb(0x000000))),
68 m_titleBrush(QColor(QRgb(0x000000))),
69 m_axisLinePen(QPen(QRgb(0x000000))),
69 m_axisLinePen(QPen(QRgb(0x000000))),
70 m_axisLabelBrush(QColor(QRgb(0x000000))),
70 m_axisLabelBrush(QColor(QRgb(0x000000))),
71 m_backgroundShadesPen(Qt::NoPen),
71 m_backgroundShadesPen(Qt::NoPen),
72 m_backgroundShadesBrush(Qt::NoBrush),
72 m_backgroundShadesBrush(Qt::NoBrush),
73 m_backgroundShades(BackgroundShadesNone),
73 m_backgroundShades(BackgroundShadesNone),
74 m_backgroundDropShadowEnabled(false),
74 m_backgroundDropShadowEnabled(false),
75 m_gridLinePen(QPen(QRgb(0x000000))),
75 m_gridLinePen(QPen(QRgb(0x000000))),
76 m_force(false)
76 m_force(false)
77 {
77 {
78 m_id = id;
78 m_id = id;
79 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
79 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
80 }
80 }
81
81
82
82
83 ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme)
83 ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme)
84 {
84 {
85 switch(theme) {
85 switch(theme) {
86 case QChart::ChartThemeLight:
86 case QChart::ChartThemeLight:
87 return new ChartThemeLight();
87 return new ChartThemeLight();
88 case QChart::ChartThemeBlueCerulean:
88 case QChart::ChartThemeBlueCerulean:
89 return new ChartThemeBlueCerulean();
89 return new ChartThemeBlueCerulean();
90 case QChart::ChartThemeDark:
90 case QChart::ChartThemeDark:
91 return new ChartThemeDark();
91 return new ChartThemeDark();
92 case QChart::ChartThemeBrownSand:
92 case QChart::ChartThemeBrownSand:
93 return new ChartThemeBrownSand();
93 return new ChartThemeBrownSand();
94 case QChart::ChartThemeBlueNcs:
94 case QChart::ChartThemeBlueNcs:
95 return new ChartThemeBlueNcs();
95 return new ChartThemeBlueNcs();
96 case QChart::ChartThemeHighContrast:
96 case QChart::ChartThemeHighContrast:
97 return new ChartThemeHighContrast();
97 return new ChartThemeHighContrast();
98 case QChart::ChartThemeBlueIcy:
98 case QChart::ChartThemeBlueIcy:
99 return new ChartThemeBlueIcy();
99 return new ChartThemeBlueIcy();
100 default:
100 default:
101 return new ChartThemeSystem();
101 return new ChartThemeSystem();
102 }
102 }
103 }
103 }
104
104
105 void ChartTheme::decorate(QChart *chart)
105 void ChartTheme::decorate(QChart *chart)
106 {
106 {
107 QBrush brush;
107 QBrush brush;
108
108
109 if(brush == chart->backgroundBrush() || m_force)
109 if(brush == chart->backgroundBrush() || m_force)
110 chart->setBackgroundBrush(m_chartBackgroundGradient);
110 chart->setBackgroundBrush(m_chartBackgroundGradient);
111 chart->setTitleFont(m_masterFont);
111 chart->setTitleFont(m_masterFont);
112 chart->setTitleBrush(m_titleBrush);
112 chart->setTitleBrush(m_titleBrush);
113 chart->setBackgroundDropShadowEnabled(m_backgroundDropShadowEnabled);
113 chart->setBackgroundDropShadowEnabled(m_backgroundDropShadowEnabled);
114 }
114 }
115
115
116 void ChartTheme::decorate(QLegend *legend)
116 void ChartTheme::decorate(QLegend *legend)
117 {
117 {
118 QPen pen;
118 QPen pen;
119 QBrush brush;
119 QBrush brush;
120
120
121 if (pen == legend->pen() || m_force){
121 if (pen == legend->pen() || m_force)
122 legend->setPen(Qt::NoPen);
122 legend->setPen(m_axisLinePen);
123 }
124
123
125 if (brush == legend->brush() || m_force) {
124 if (brush == legend->brush() || m_force)
126 legend->setBrush(m_chartBackgroundGradient);
125 legend->setBrush(m_chartBackgroundGradient);
127 }
128 }
126 }
129
127
130 void ChartTheme::decorate(QAreaSeries *series, int index)
128 void ChartTheme::decorate(QAreaSeries *series, int index)
131 {
129 {
132 QPen pen;
130 QPen pen;
133 QBrush brush;
131 QBrush brush;
134
132
135 if (pen == series->pen() || m_force){
133 if (pen == series->pen() || m_force){
136 pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0));
134 pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0));
137 pen.setWidthF(2);
135 pen.setWidthF(2);
138 series->setPen(pen);
136 series->setPen(pen);
139 }
137 }
140
138
141 if (brush == series->brush() || m_force) {
139 if (brush == series->brush() || m_force) {
142 QBrush brush(m_seriesColors.at(index % m_seriesColors.size()));
140 QBrush brush(m_seriesColors.at(index % m_seriesColors.size()));
143 series->setBrush(brush);
141 series->setBrush(brush);
144 }
142 }
145 }
143 }
146
144
147
145
148 void ChartTheme::decorate(QLineSeries *series,int index)
146 void ChartTheme::decorate(QLineSeries *series,int index)
149 {
147 {
150 QPen pen;
148 QPen pen;
151 if(pen == series->pen() || m_force ){
149 if(pen == series->pen() || m_force ){
152 pen.setColor(m_seriesColors.at(index%m_seriesColors.size()));
150 pen.setColor(m_seriesColors.at(index%m_seriesColors.size()));
153 pen.setWidthF(2);
151 pen.setWidthF(2);
154 series->setPen(pen);
152 series->setPen(pen);
155 }
153 }
156 }
154 }
157
155
158 void ChartTheme::decorate(QBarSeries *series, int index)
156 void ChartTheme::decorate(QBarSeries *series, int index)
159 {
157 {
160 QBrush brush;
158 QBrush brush;
161 QPen pen;
159 QPen pen;
162 QList<QBarSet *> sets = series->barSets();
160 QList<QBarSet *> sets = series->barSets();
163
161
164 qreal takeAtPos = 0.5;
162 qreal takeAtPos = 0.5;
165 qreal step = 0.2;
163 qreal step = 0.2;
166 if (sets.count() > 1 ) {
164 if (sets.count() > 1 ) {
167 step = 1.0 / (qreal) sets.count();
165 step = 1.0 / (qreal) sets.count();
168 if (sets.count() % m_seriesGradients.count())
166 if (sets.count() % m_seriesGradients.count())
169 step *= m_seriesGradients.count();
167 step *= m_seriesGradients.count();
170 else
168 else
171 step *= (m_seriesGradients.count() - 1);
169 step *= (m_seriesGradients.count() - 1);
172 }
170 }
173
171
174 for (int i(0); i < sets.count(); i++) {
172 for (int i(0); i < sets.count(); i++) {
175 int colorIndex = (index + i) % m_seriesGradients.count();
173 int colorIndex = (index + i) % m_seriesGradients.count();
176 if (i > 0 && i % m_seriesGradients.count() == 0) {
174 if (i > 0 && i % m_seriesGradients.count() == 0) {
177 // There is no dedicated base color for each sets, generate more colors
175 // There is no dedicated base color for each sets, generate more colors
178 takeAtPos += step;
176 takeAtPos += step;
179 if (takeAtPos == 1.0)
177 if (takeAtPos == 1.0)
180 takeAtPos += step;
178 takeAtPos += step;
181 takeAtPos -= (int) takeAtPos;
179 takeAtPos -= (int) takeAtPos;
182 }
180 }
183 if (brush == sets.at(i)->brush() || m_force )
181 if (brush == sets.at(i)->brush() || m_force )
184 sets.at(i)->setBrush(colorAt(m_seriesGradients.at(colorIndex), takeAtPos));
182 sets.at(i)->setBrush(colorAt(m_seriesGradients.at(colorIndex), takeAtPos));
185
183
186 // Pick label color from the opposite end of the gradient.
184 // Pick label color from the opposite end of the gradient.
187 // 0.3 as a boundary seems to work well.
185 // 0.3 as a boundary seems to work well.
188 if (takeAtPos < 0.3)
186 if (takeAtPos < 0.3)
189 sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1));
187 sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1));
190 else
188 else
191 sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0));
189 sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0));
192
190
193 if (pen == sets.at(i)->pen() || m_force) {
191 if (pen == sets.at(i)->pen() || m_force) {
194 QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0);
192 QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0);
195 sets.at(i)->setPen(c);
193 sets.at(i)->setPen(c);
196 }
194 }
197 }
195 }
198 }
196 }
199
197
200 void ChartTheme::decorate(QScatterSeries *series, int index)
198 void ChartTheme::decorate(QScatterSeries *series, int index)
201 {
199 {
202 QPen pen;
200 QPen pen;
203 QBrush brush;
201 QBrush brush;
204
202
205 if (pen == series->pen() || m_force) {
203 if (pen == series->pen() || m_force) {
206 pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0));
204 pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0));
207 pen.setWidthF(2);
205 pen.setWidthF(2);
208 series->setPen(pen);
206 series->setPen(pen);
209 }
207 }
210
208
211 if (brush == series->brush() || m_force) {
209 if (brush == series->brush() || m_force) {
212 QBrush brush(m_seriesColors.at(index % m_seriesColors.size()));
210 QBrush brush(m_seriesColors.at(index % m_seriesColors.size()));
213 series->setBrush(brush);
211 series->setBrush(brush);
214 }
212 }
215 }
213 }
216
214
217 void ChartTheme::decorate(QPieSeries *series, int index)
215 void ChartTheme::decorate(QPieSeries *series, int index)
218 {
216 {
219
217
220 for (int i(0); i < series->slices().count(); i++) {
218 for (int i(0); i < series->slices().count(); i++) {
221
219
222 QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0);
220 QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0);
223
221
224 // Get color for a slice from a gradient linearly, beginning from the start of the gradient
222 // Get color for a slice from a gradient linearly, beginning from the start of the gradient
225 qreal pos = (qreal) (i + 1) / (qreal) series->count();
223 qreal pos = (qreal) (i + 1) / (qreal) series->count();
226 QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos);
224 QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos);
227
225
228 QPieSlice *s = series->slices().at(i);
226 QPieSlice *s = series->slices().at(i);
229 QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s);
227 QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s);
230
228
231 if (d->m_data.m_slicePen.isThemed() || m_force)
229 if (d->m_data.m_slicePen.isThemed() || m_force)
232 d->setPen(penColor, true);
230 d->setPen(penColor, true);
233
231
234 if (d->m_data.m_sliceBrush.isThemed() || m_force)
232 if (d->m_data.m_sliceBrush.isThemed() || m_force)
235 d->setBrush(brushColor, true);
233 d->setBrush(brushColor, true);
236
234
237 if (d->m_data.m_labelBrush.isThemed() || m_force)
235 if (d->m_data.m_labelBrush.isThemed() || m_force)
238 d->setLabelBrush(QBrush(m_titleBrush.color()), true);
236 d->setLabelBrush(QBrush(m_titleBrush.color()), true);
239
237
240 if (d->m_data.m_labelFont.isThemed() || m_force)
238 if (d->m_data.m_labelFont.isThemed() || m_force)
241 d->setLabelFont(m_labelFont, true);
239 d->setLabelFont(m_labelFont, true);
242 }
240 }
243 }
241 }
244
242
245 void ChartTheme::decorate(QSplineSeries *series, int index)
243 void ChartTheme::decorate(QSplineSeries *series, int index)
246 {
244 {
247 QPen pen;
245 QPen pen;
248 if(pen == series->pen() || m_force){
246 if(pen == series->pen() || m_force){
249 pen.setColor(m_seriesColors.at(index%m_seriesColors.size()));
247 pen.setColor(m_seriesColors.at(index%m_seriesColors.size()));
250 pen.setWidthF(2);
248 pen.setWidthF(2);
251 series->setPen(pen);
249 series->setPen(pen);
252 }
250 }
253 }
251 }
254
252
255 void ChartTheme::decorate(QAxis *axis,bool axisX)
253 void ChartTheme::decorate(QAxis *axis,bool axisX)
256 {
254 {
257 QPen pen;
255 QPen pen;
258 QBrush brush;
256 QBrush brush;
259 QFont font;
257 QFont font;
260
258
261 if (axis->isAxisVisible()) {
259 if (axis->isAxisVisible()) {
262
260
263 if(brush == axis->labelsBrush() || m_force){
261 if(brush == axis->labelsBrush() || m_force){
264 axis->setLabelsBrush(m_axisLabelBrush);
262 axis->setLabelsBrush(m_axisLabelBrush);
265 }
263 }
266 if(pen == axis->labelsPen() || m_force){
264 if(pen == axis->labelsPen() || m_force){
267 axis->setLabelsPen(Qt::NoPen); // NoPen for performance reasons
265 axis->setLabelsPen(Qt::NoPen); // NoPen for performance reasons
268 }
266 }
269
267
270
268
271 if (axis->shadesVisible() || m_force) {
269 if (axis->shadesVisible() || m_force) {
272
270
273 if(brush == axis->shadesBrush() || m_force){
271 if(brush == axis->shadesBrush() || m_force){
274 axis->setShadesBrush(m_backgroundShadesBrush);
272 axis->setShadesBrush(m_backgroundShadesBrush);
275 }
273 }
276
274
277 if(pen == axis->shadesPen() || m_force){
275 if(pen == axis->shadesPen() || m_force){
278 axis->setShadesPen(m_backgroundShadesPen);
276 axis->setShadesPen(m_backgroundShadesPen);
279 }
277 }
280
278
281 if( m_force && (m_backgroundShades == BackgroundShadesBoth
279 if( m_force && (m_backgroundShades == BackgroundShadesBoth
282 || (m_backgroundShades == BackgroundShadesVertical && axisX)
280 || (m_backgroundShades == BackgroundShadesVertical && axisX)
283 || (m_backgroundShades == BackgroundShadesHorizontal && !axisX))){
281 || (m_backgroundShades == BackgroundShadesHorizontal && !axisX))){
284 axis->setShadesVisible(true);
282 axis->setShadesVisible(true);
285
283
286 }
284 }
287 }
285 }
288
286
289 if(pen == axis->axisPen() || m_force){
287 if(pen == axis->axisPen() || m_force){
290 axis->setAxisPen(m_axisLinePen);
288 axis->setAxisPen(m_axisLinePen);
291 }
289 }
292
290
293 if(pen == axis->gridLinePen() || m_force){
291 if(pen == axis->gridLinePen() || m_force){
294 axis->setGridLinePen(m_gridLinePen);
292 axis->setGridLinePen(m_gridLinePen);
295 }
293 }
296
294
297 if(font == axis->labelsFont() || m_force){
295 if(font == axis->labelsFont() || m_force){
298 axis->setLabelsFont(m_labelFont);
296 axis->setLabelsFont(m_labelFont);
299 }
297 }
300 }
298 }
301 }
299 }
302
300
303 void ChartTheme::generateSeriesGradients()
301 void ChartTheme::generateSeriesGradients()
304 {
302 {
305 // Generate gradients in HSV color space
303 // Generate gradients in HSV color space
306 foreach (const QColor& color, m_seriesColors) {
304 foreach (const QColor& color, m_seriesColors) {
307 QLinearGradient g;
305 QLinearGradient g;
308 qreal h = color.hsvHueF();
306 qreal h = color.hsvHueF();
309 qreal s = color.hsvSaturationF();
307 qreal s = color.hsvSaturationF();
310
308
311 // TODO: tune the algorithm to give nice results with most base colors defined in
309 // TODO: tune the algorithm to give nice results with most base colors defined in
312 // most themes. The rest of the gradients we can define manually in theme specific
310 // most themes. The rest of the gradients we can define manually in theme specific
313 // implementation.
311 // implementation.
314 QColor start = color;
312 QColor start = color;
315 start.setHsvF(h, 0.0, 1.0);
313 start.setHsvF(h, 0.0, 1.0);
316 g.setColorAt(0.0, start);
314 g.setColorAt(0.0, start);
317
315
318 g.setColorAt(0.5, color);
316 g.setColorAt(0.5, color);
319
317
320 QColor end = color;
318 QColor end = color;
321 end.setHsvF(h, s, 0.25);
319 end.setHsvF(h, s, 0.25);
322 g.setColorAt(1.0, end);
320 g.setColorAt(1.0, end);
323
321
324 m_seriesGradients << g;
322 m_seriesGradients << g;
325 }
323 }
326 }
324 }
327
325
328
326
329 QColor ChartTheme::colorAt(const QColor &start, const QColor &end, qreal pos)
327 QColor ChartTheme::colorAt(const QColor &start, const QColor &end, qreal pos)
330 {
328 {
331 Q_ASSERT(pos >= 0.0 && pos <= 1.0);
329 Q_ASSERT(pos >= 0.0 && pos <= 1.0);
332 qreal r = start.redF() + ((end.redF() - start.redF()) * pos);
330 qreal r = start.redF() + ((end.redF() - start.redF()) * pos);
333 qreal g = start.greenF() + ((end.greenF() - start.greenF()) * pos);
331 qreal g = start.greenF() + ((end.greenF() - start.greenF()) * pos);
334 qreal b = start.blueF() + ((end.blueF() - start.blueF()) * pos);
332 qreal b = start.blueF() + ((end.blueF() - start.blueF()) * pos);
335 QColor c;
333 QColor c;
336 c.setRgbF(r, g, b);
334 c.setRgbF(r, g, b);
337 return c;
335 return c;
338 }
336 }
339
337
340 QColor ChartTheme::colorAt(const QGradient &gradient, qreal pos)
338 QColor ChartTheme::colorAt(const QGradient &gradient, qreal pos)
341 {
339 {
342 Q_ASSERT(pos >= 0 && pos <= 1.0);
340 Q_ASSERT(pos >= 0 && pos <= 1.0);
343
341
344 QGradientStops stops = gradient.stops();
342 QGradientStops stops = gradient.stops();
345 int count = stops.count();
343 int count = stops.count();
346
344
347 // find previous stop relative to position
345 // find previous stop relative to position
348 QGradientStop prev = stops.first();
346 QGradientStop prev = stops.first();
349 for (int i = 0; i < count; i++) {
347 for (int i = 0; i < count; i++) {
350 QGradientStop stop = stops.at(i);
348 QGradientStop stop = stops.at(i);
351 if (pos > stop.first)
349 if (pos > stop.first)
352 prev = stop;
350 prev = stop;
353
351
354 // given position is actually a stop position?
352 // given position is actually a stop position?
355 if (pos == stop.first) {
353 if (pos == stop.first) {
356 //qDebug() << "stop color" << pos;
354 //qDebug() << "stop color" << pos;
357 return stop.second;
355 return stop.second;
358 }
356 }
359 }
357 }
360
358
361 // find next stop relative to position
359 // find next stop relative to position
362 QGradientStop next = stops.last();
360 QGradientStop next = stops.last();
363 for (int i = count - 1; i >= 0; i--) {
361 for (int i = count - 1; i >= 0; i--) {
364 QGradientStop stop = stops.at(i);
362 QGradientStop stop = stops.at(i);
365 if (pos < stop.first)
363 if (pos < stop.first)
366 next = stop;
364 next = stop;
367 }
365 }
368
366
369 //qDebug() << "prev" << prev.first << "pos" << pos << "next" << next.first;
367 //qDebug() << "prev" << prev.first << "pos" << pos << "next" << next.first;
370
368
371 qreal range = next.first - prev.first;
369 qreal range = next.first - prev.first;
372 qreal posDelta = pos - prev.first;
370 qreal posDelta = pos - prev.first;
373 qreal relativePos = posDelta / range;
371 qreal relativePos = posDelta / range;
374
372
375 //qDebug() << "range" << range << "posDelta" << posDelta << "relativePos" << relativePos;
373 //qDebug() << "range" << range << "posDelta" << posDelta << "relativePos" << relativePos;
376
374
377 return colorAt(prev.second, next.second, relativePos);
375 return colorAt(prev.second, next.second, relativePos);
378 }
376 }
379
377
380 void ChartTheme::setForced(bool enabled)
378 void ChartTheme::setForced(bool enabled)
381 {
379 {
382 m_force=enabled;
380 m_force=enabled;
383 }
381 }
384
382
385 QTCOMMERCIALCHART_END_NAMESPACE
383 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,748 +1,748
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
26
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 "qbarseries.h"
33 #include "qbarseries.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 <QPainter>
41 #include <QPainter>
42 #include <QPen>
42 #include <QPen>
43 #include <QTimer>
43 #include <QTimer>
44
44
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 part of QtCommercial chart API.
51 \brief part of QtCommercial chart API.
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 referenced via ChartView class. For example:
68 series have been changed. Legend is referenced 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 color.
106 The color of the legend, i.e. the background color.
107 */
107 */
108 /*!
108 /*!
109 \qmlproperty color Legend::color
109 \qmlproperty color Legend::color
110 The color of the legend, i.e. the background color.
110 The color of the legend, i.e. the background color.
111 */
111 */
112
112
113 /*!
113 /*!
114 \property QLegend::borderColor
114 \property QLegend::borderColor
115 The border color of the legend, i.e. the line color.
115 The border color of the legend, i.e. the line color.
116 */
116 */
117 /*!
117 /*!
118 \qmlproperty color Legend::borderColor
118 \qmlproperty color Legend::borderColor
119 The border color of the legend, i.e. the line color.
119 The border color of the legend, i.e. the line color.
120 */
120 */
121
121
122 /*!
122 /*!
123 \fn void QLegend::alignmentChanged(Qt::Alignment)
123 \fn void QLegend::alignmentChanged(Qt::Alignment)
124 Emitted when the \a alignment of the legend changes.
124 Emitted when the \a alignment of the legend changes.
125 */
125 */
126
126
127 /*!
127 /*!
128 \fn void QLegend::backgroundVisibleChanged(bool)
128 \fn void QLegend::backgroundVisibleChanged(bool)
129 The visibility of the legend background changed to \a visible.
129 The visibility of the legend background changed to \a visible.
130 */
130 */
131
131
132 /*!
132 /*!
133 \fn void QLegend::colorChanged(QColor)
133 \fn void QLegend::colorChanged(QColor)
134 The color of the legend background changed to \a color.
134 The color of the legend background changed to \a color.
135 */
135 */
136
136
137 /*!
137 /*!
138 \fn void QLegend::borderColorChanged(QColor)
138 \fn void QLegend::borderColorChanged(QColor)
139 The border color of the legend background changed to \a color.
139 The border color of the legend background changed to \a color.
140 */
140 */
141
141
142 /*!
142 /*!
143 \fn qreal QLegend::minWidth() const
143 \fn qreal QLegend::minWidth() const
144 Returns minimum width of the legend
144 Returns minimum width of the legend
145 */
145 */
146
146
147 /*!
147 /*!
148 \fn qreal QLegend::minHeight() const
148 \fn qreal QLegend::minHeight() const
149 Returns minimum height of the legend
149 Returns minimum height of the legend
150 */
150 */
151
151
152 /*!
152 /*!
153 Constructs the legend object and sets the parent to \a parent
153 Constructs the legend object and sets the parent to \a parent
154 */
154 */
155
155
156 QLegend::QLegend(QChart *chart):QGraphicsWidget(chart),
156 QLegend::QLegend(QChart *chart):QGraphicsWidget(chart),
157 d_ptr(new QLegendPrivate(chart->d_ptr->m_presenter,chart,this))
157 d_ptr(new QLegendPrivate(chart->d_ptr->m_presenter,chart,this))
158 {
158 {
159 setZValue(ChartPresenter::LegendZValue);
159 setZValue(ChartPresenter::LegendZValue);
160 setFlags(QGraphicsItem::ItemClipsChildrenToShape);
160 setFlags(QGraphicsItem::ItemClipsChildrenToShape);
161 QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesAdded(QAbstractSeries*,Domain*)),d_ptr.data(),SLOT(handleSeriesAdded(QAbstractSeries*,Domain*)));
161 QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesAdded(QAbstractSeries*,Domain*)),d_ptr.data(),SLOT(handleSeriesAdded(QAbstractSeries*,Domain*)));
162 QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesRemoved(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesRemoved(QAbstractSeries*)));
162 QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesRemoved(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesRemoved(QAbstractSeries*)));
163 QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesUpdated(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesUpdated(QAbstractSeries*)));
163 QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesUpdated(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesUpdated(QAbstractSeries*)));
164 }
164 }
165
165
166 /*!
166 /*!
167 Destroys the legend object. Legend is always owned by a QChart, so an application should never call this.
167 Destroys the legend object. Legend is always owned by a QChart, so an application should never call this.
168 */
168 */
169 QLegend::~QLegend()
169 QLegend::~QLegend()
170 {
170 {
171 }
171 }
172
172
173 /*!
173 /*!
174 Paints the legend to given \a painter. Paremeters \a option and \a widget arent used.
174 Paints the legend to given \a painter. Paremeters \a option and \a widget arent used.
175 */
175 */
176
176
177 void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
177 void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
178 {
178 {
179 Q_UNUSED(option)
179 Q_UNUSED(option)
180 Q_UNUSED(widget)
180 Q_UNUSED(widget)
181 if(!d_ptr->m_backgroundVisible) return;
181 if(!d_ptr->m_backgroundVisible) return;
182
182
183 painter->setOpacity(opacity());
183 painter->setOpacity(opacity());
184 painter->setPen(d_ptr->m_pen);
184 painter->setPen(d_ptr->m_pen);
185 painter->setBrush(d_ptr->m_brush);
185 painter->setBrush(d_ptr->m_brush);
186 painter->drawRoundRect(rect(),d_ptr->roundness(rect().width()),d_ptr->roundness(rect().height()));
186 painter->drawRoundRect(rect(),d_ptr->roundness(rect().width()),d_ptr->roundness(rect().height()));
187 }
187 }
188
188
189 /*!
189 /*!
190 Bounding rect of legend.
190 Bounding rect of legend.
191 */
191 */
192
192
193 QRectF QLegend::boundingRect() const
193 QRectF QLegend::boundingRect() const
194 {
194 {
195 return d_ptr->m_rect;
195 return d_ptr->m_rect;
196 }
196 }
197
197
198 /*!
198 /*!
199 Sets the \a brush of legend. Brush affects the background of legend.
199 Sets the \a brush of legend. Brush affects the background of legend.
200 */
200 */
201 void QLegend::setBrush(const QBrush &brush)
201 void QLegend::setBrush(const QBrush &brush)
202 {
202 {
203 if (d_ptr->m_brush != brush) {
203 if (d_ptr->m_brush != brush) {
204 d_ptr->m_brush = brush;
204 d_ptr->m_brush = brush;
205 update();
205 update();
206 }
206 }
207 }
207 }
208
208
209 /*!
209 /*!
210 Returns the brush used by legend.
210 Returns the brush used by legend.
211 */
211 */
212 QBrush QLegend::brush() const
212 QBrush QLegend::brush() const
213 {
213 {
214 return d_ptr->m_brush;
214 return d_ptr->m_brush;
215 }
215 }
216
216
217 void QLegend::setColor(QColor color)
217 void QLegend::setColor(QColor color)
218 {
218 {
219 QBrush b = d_ptr->m_brush;
219 QBrush b = d_ptr->m_brush;
220 if (b.color() != color) {
220 if (b.color() != color) {
221 b.setColor(color);
221 b.setColor(color);
222 setBrush(b);
222 setBrush(b);
223 emit colorChanged(color);
223 emit colorChanged(color);
224 }
224 }
225 }
225 }
226
226
227 QColor QLegend::color()
227 QColor QLegend::color()
228 {
228 {
229 return d_ptr->m_brush.color();
229 return d_ptr->m_brush.color();
230 }
230 }
231
231
232 /*!
232 /*!
233 Sets the \a pen of legend. Pen affects the legend borders.
233 Sets the \a pen of legend. Pen affects the legend borders.
234 */
234 */
235 void QLegend::setPen(const QPen &pen)
235 void QLegend::setPen(const QPen &pen)
236 {
236 {
237 if (d_ptr->m_pen != pen) {
237 if (d_ptr->m_pen != pen) {
238 d_ptr->m_pen = pen;
238 d_ptr->m_pen = pen;
239 update();
239 update();
240 }
240 }
241 }
241 }
242
242
243 /*!
243 /*!
244 Returns the pen used by legend
244 Returns the pen used by legend
245 */
245 */
246
246
247 QPen QLegend::pen() const
247 QPen QLegend::pen() const
248 {
248 {
249 return d_ptr->m_pen;
249 return d_ptr->m_pen;
250 }
250 }
251
251
252 void QLegend::setBorderColor(QColor color)
252 void QLegend::setBorderColor(QColor color)
253 {
253 {
254 QPen p = d_ptr->m_pen;
254 QPen p = d_ptr->m_pen;
255 if (p.color() != color) {
255 if (p.color() != color) {
256 p.setColor(color);
256 p.setColor(color);
257 setPen(p);
257 setPen(p);
258 emit borderColorChanged(color);
258 emit borderColorChanged(color);
259 }
259 }
260 }
260 }
261
261
262 QColor QLegend::borderColor()
262 QColor QLegend::borderColor()
263 {
263 {
264 return d_ptr->m_pen.color();
264 return d_ptr->m_pen.color();
265 }
265 }
266
266
267 void QLegend::setAlignment(Qt::Alignment alignment)
267 void QLegend::setAlignment(Qt::Alignment alignment)
268 {
268 {
269 if(d_ptr->m_alignment!=alignment) {
269 if(d_ptr->m_alignment!=alignment) {
270 d_ptr->m_alignment = alignment;
270 d_ptr->m_alignment = alignment;
271 d_ptr->updateLayout();
271 d_ptr->updateLayout();
272 alignmentChanged(alignment);
272 alignmentChanged(alignment);
273 }
273 }
274 }
274 }
275
275
276 Qt::Alignment QLegend::alignment() const
276 Qt::Alignment QLegend::alignment() const
277 {
277 {
278 return d_ptr->m_alignment;
278 return d_ptr->m_alignment;
279 }
279 }
280
280
281 /*!
281 /*!
282 Detaches the legend from chart. Chart won't change layout of the legend.
282 Detaches the legend from chart. Chart won't change layout of the legend.
283 */
283 */
284 void QLegend::detachFromChart()
284 void QLegend::detachFromChart()
285 {
285 {
286 d_ptr->m_attachedToChart = false;
286 d_ptr->m_attachedToChart = false;
287 }
287 }
288
288
289 /*!
289 /*!
290 Attaches the legend to chart. Chart may change layout of the legend.
290 Attaches the legend to chart. Chart may change layout of the legend.
291 */
291 */
292 void QLegend::attachToChart()
292 void QLegend::attachToChart()
293 {
293 {
294 d_ptr->attachToChart();
294 d_ptr->attachToChart();
295 }
295 }
296
296
297 /*!
297 /*!
298 Returns true, if legend is attached to chart.
298 Returns true, if legend is attached to chart.
299 */
299 */
300 bool QLegend::isAttachedToChart()
300 bool QLegend::isAttachedToChart()
301 {
301 {
302 return d_ptr->m_attachedToChart;
302 return d_ptr->m_attachedToChart;
303 }
303 }
304
304
305 /*!
305 /*!
306 Sets the legend's scrolling offset to value defined by \a point.
306 Sets the legend's scrolling offset to value defined by \a point.
307 */
307 */
308 void QLegend::setOffset(const QPointF& point)
308 void QLegend::setOffset(const QPointF& point)
309 {
309 {
310 d_ptr->setOffset(point.x(),point.y());
310 d_ptr->setOffset(point.x(),point.y());
311 }
311 }
312
312
313 /*!
313 /*!
314 Returns the legend's scrolling offset.
314 Returns the legend's scrolling offset.
315 */
315 */
316 QPointF QLegend::offset() const
316 QPointF QLegend::offset() const
317 {
317 {
318 return QPointF(d_ptr->m_offsetX,d_ptr->m_offsetY);
318 return QPointF(d_ptr->m_offsetX,d_ptr->m_offsetY);
319 }
319 }
320
320
321 /*!
321 /*!
322 Sets the visibility of legend background to \a visible
322 Sets the visibility of legend background to \a visible
323 */
323 */
324 void QLegend::setBackgroundVisible(bool visible)
324 void QLegend::setBackgroundVisible(bool visible)
325 {
325 {
326 if(d_ptr->m_backgroundVisible != visible) {
326 if(d_ptr->m_backgroundVisible != visible) {
327 d_ptr->m_backgroundVisible = visible;
327 d_ptr->m_backgroundVisible = visible;
328 update();
328 update();
329 emit backgroundVisibleChanged(visible);
329 emit backgroundVisibleChanged(visible);
330 }
330 }
331 }
331 }
332
332
333 /*!
333 /*!
334 Returns the visibility of legend background
334 Returns the visibility of legend background
335 */
335 */
336 bool QLegend::isBackgroundVisible() const
336 bool QLegend::isBackgroundVisible() const
337 {
337 {
338 return d_ptr->m_backgroundVisible;
338 return d_ptr->m_backgroundVisible;
339 }
339 }
340
340
341 /*!
341 /*!
342 \internal \a event see QGraphicsWidget for details
342 \internal \a event see QGraphicsWidget for details
343 */
343 */
344 void QLegend::resizeEvent(QGraphicsSceneResizeEvent *event)
344 void QLegend::resizeEvent(QGraphicsSceneResizeEvent *event)
345 {
345 {
346 const QRectF& rect = QRectF(QPoint(0,0),event->newSize());
346 const QRectF& rect = QRectF(QPoint(0,0),event->newSize());
347 QGraphicsWidget::resizeEvent(event);
347 QGraphicsWidget::resizeEvent(event);
348 if(d_ptr->m_rect != rect) {
348 if(d_ptr->m_rect != rect) {
349 d_ptr->m_rect = rect;
349 d_ptr->m_rect = rect;
350 d_ptr->updateLayout();
350 d_ptr->updateLayout();
351 }
351 }
352 }
352 }
353
353
354 /*!
354 /*!
355 \internal \a event see QGraphicsWidget for details
355 \internal \a event see QGraphicsWidget for details
356 */
356 */
357 void QLegend::hideEvent(QHideEvent *event)
357 void QLegend::hideEvent(QHideEvent *event)
358 {
358 {
359 QGraphicsWidget::hideEvent(event);
359 QGraphicsWidget::hideEvent(event);
360 setEnabled(false);
360 setEnabled(false);
361 d_ptr->updateLayout();
361 d_ptr->updateLayout();
362 }
362 }
363
363
364 /*!
364 /*!
365 \internal \a event see QGraphicsWidget for details
365 \internal \a event see QGraphicsWidget for details
366 */
366 */
367 void QLegend::showEvent(QShowEvent *event)
367 void QLegend::showEvent(QShowEvent *event)
368 {
368 {
369 QGraphicsWidget::showEvent(event);
369 QGraphicsWidget::showEvent(event);
370 setEnabled(true);
370 setEnabled(true);
371 d_ptr->updateLayout();
371 d_ptr->updateLayout();
372 }
372 }
373
373
374 qreal QLegend::minWidth() const
374 qreal QLegend::minWidth() const
375 {
375 {
376 return d_ptr->m_minWidth;
376 return d_ptr->m_minWidth;
377 }
377 }
378
378
379 qreal QLegend::minHeight() const
379 qreal QLegend::minHeight() const
380 {
380 {
381 return d_ptr->m_minHeight;
381 return d_ptr->m_minHeight;
382 }
382 }
383
383
384 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
384 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
385
385
386 QLegendPrivate::QLegendPrivate(ChartPresenter* presenter, QChart *chart, QLegend *q):
386 QLegendPrivate::QLegendPrivate(ChartPresenter* presenter, QChart *chart, QLegend *q):
387 q_ptr(q),
387 q_ptr(q),
388 m_presenter(presenter),
388 m_presenter(presenter),
389 m_chart(chart),
389 m_chart(chart),
390 m_markers(new QGraphicsItemGroup(q)),
390 m_markers(new QGraphicsItemGroup(q)),
391 m_alignment(Qt::AlignTop),
391 m_alignment(Qt::AlignTop),
392 m_brush(Qt::SolidPattern),
392 m_brush(QBrush()),
393 m_pen(Qt::SolidLine),
393 m_pen(QPen()),
394 m_offsetX(0),
394 m_offsetX(0),
395 m_offsetY(0),
395 m_offsetY(0),
396 m_minWidth(0),
396 m_minWidth(0),
397 m_minHeight(0),
397 m_minHeight(0),
398 m_width(0),
398 m_width(0),
399 m_height(0),
399 m_height(0),
400 m_diameter(5),
400 m_diameter(5),
401 m_attachedToChart(true),
401 m_attachedToChart(true),
402 m_backgroundVisible(false)
402 m_backgroundVisible(false)
403 {
403 {
404
404
405 }
405 }
406
406
407 QLegendPrivate::~QLegendPrivate()
407 QLegendPrivate::~QLegendPrivate()
408 {
408 {
409
409
410 }
410 }
411
411
412 void QLegendPrivate::setOffset(qreal x, qreal y)
412 void QLegendPrivate::setOffset(qreal x, qreal y)
413 {
413 {
414 bool scrollHorizontal = true;
414 bool scrollHorizontal = true;
415 switch(m_alignment) {
415 switch(m_alignment) {
416 case Qt::AlignTop:
416 case Qt::AlignTop:
417 case Qt::AlignBottom: {
417 case Qt::AlignBottom: {
418 scrollHorizontal = true;
418 scrollHorizontal = true;
419 break;
419 break;
420 }
420 }
421 case Qt::AlignLeft:
421 case Qt::AlignLeft:
422 case Qt::AlignRight: {
422 case Qt::AlignRight: {
423 scrollHorizontal = false;
423 scrollHorizontal = false;
424 break;
424 break;
425 }
425 }
426 }
426 }
427
427
428 // If detached, the scrolling direction is vertical instead of horizontal and vice versa.
428 // If detached, the scrolling direction is vertical instead of horizontal and vice versa.
429 if (!m_attachedToChart) {
429 if (!m_attachedToChart) {
430 scrollHorizontal = !scrollHorizontal;
430 scrollHorizontal = !scrollHorizontal;
431 }
431 }
432
432
433 // Limit offset between m_minOffset and m_maxOffset
433 // Limit offset between m_minOffset and m_maxOffset
434 if (scrollHorizontal) {
434 if (scrollHorizontal) {
435 if(m_width<=m_rect.width()) return;
435 if(m_width<=m_rect.width()) return;
436
436
437 if (x != m_offsetX) {
437 if (x != m_offsetX) {
438 m_offsetX = qBound(m_minOffsetX, x, m_maxOffsetX);
438 m_offsetX = qBound(m_minOffsetX, x, m_maxOffsetX);
439 m_markers->setPos(-m_offsetX,m_rect.top());
439 m_markers->setPos(-m_offsetX,m_rect.top());
440 }
440 }
441 } else {
441 } else {
442 if(m_height<=m_rect.height()) return;
442 if(m_height<=m_rect.height()) return;
443
443
444 if (y != m_offsetY) {
444 if (y != m_offsetY) {
445 m_offsetY = qBound(m_minOffsetY, y, m_maxOffsetY);
445 m_offsetY = qBound(m_minOffsetY, y, m_maxOffsetY);
446 m_markers->setPos(m_rect.left(),-m_offsetY);
446 m_markers->setPos(m_rect.left(),-m_offsetY);
447 }
447 }
448 }
448 }
449 }
449 }
450
450
451
451
452 void QLegendPrivate::updateLayout()
452 void QLegendPrivate::updateLayout()
453 {
453 {
454 if (!m_attachedToChart) {
454 if (!m_attachedToChart) {
455 updateDetachedLayout();
455 updateDetachedLayout();
456 return;
456 return;
457 }
457 }
458
458
459 m_offsetX=0;
459 m_offsetX=0;
460 QList<QGraphicsItem *> items = m_markers->childItems();
460 QList<QGraphicsItem *> items = m_markers->childItems();
461
461
462 if(items.isEmpty()) return;
462 if(items.isEmpty()) return;
463
463
464 m_minWidth=0;
464 m_minWidth=0;
465 m_minHeight=0;
465 m_minHeight=0;
466
466
467 switch(m_alignment) {
467 switch(m_alignment) {
468
468
469 case Qt::AlignTop:
469 case Qt::AlignTop:
470 case Qt::AlignBottom: {
470 case Qt::AlignBottom: {
471 QPointF point = m_rect.topLeft();
471 QPointF point = m_rect.topLeft();
472 m_width = 0;
472 m_width = 0;
473 foreach (QGraphicsItem *item, items) {
473 foreach (QGraphicsItem *item, items) {
474 item->setPos(point.x(),m_rect.height()/2 -item->boundingRect().height()/2);
474 item->setPos(point.x(),m_rect.height()/2 -item->boundingRect().height()/2);
475 const QRectF& rect = item->boundingRect();
475 const QRectF& rect = item->boundingRect();
476 qreal w = rect.width();
476 qreal w = rect.width();
477 m_minWidth=qMax(m_minWidth,w);
477 m_minWidth=qMax(m_minWidth,w);
478 m_minHeight=qMax(m_minHeight,rect.height());
478 m_minHeight=qMax(m_minHeight,rect.height());
479 m_width+=w;
479 m_width+=w;
480 point.setX(point.x() + w);
480 point.setX(point.x() + w);
481 }
481 }
482 if(m_width<m_rect.width()) {
482 if(m_width<m_rect.width()) {
483 m_markers->setPos(m_rect.width()/2-m_width/2,m_rect.top());
483 m_markers->setPos(m_rect.width()/2-m_width/2,m_rect.top());
484 }
484 }
485 else {
485 else {
486 m_markers->setPos(m_rect.topLeft());
486 m_markers->setPos(m_rect.topLeft());
487 }
487 }
488 m_height=m_minHeight;
488 m_height=m_minHeight;
489 }
489 }
490 break;
490 break;
491 case Qt::AlignLeft:
491 case Qt::AlignLeft:
492 case Qt::AlignRight: {
492 case Qt::AlignRight: {
493 QPointF point = m_rect.topLeft();
493 QPointF point = m_rect.topLeft();
494 m_height = 0;
494 m_height = 0;
495 foreach (QGraphicsItem *item, items) {
495 foreach (QGraphicsItem *item, items) {
496 item->setPos(point);
496 item->setPos(point);
497 const QRectF& rect = item->boundingRect();
497 const QRectF& rect = item->boundingRect();
498 qreal h = rect.height();
498 qreal h = rect.height();
499 m_minWidth=qMax(m_minWidth,rect.width());
499 m_minWidth=qMax(m_minWidth,rect.width());
500 m_minHeight=qMax(m_minHeight,h);
500 m_minHeight=qMax(m_minHeight,h);
501 m_height+=h;
501 m_height+=h;
502 point.setY(point.y() + h);
502 point.setY(point.y() + h);
503 }
503 }
504 if(m_height<m_rect.height()) {
504 if(m_height<m_rect.height()) {
505 m_markers->setPos(m_rect.left(),m_rect.height()/2-m_height/2);
505 m_markers->setPos(m_rect.left(),m_rect.height()/2-m_height/2);
506 }
506 }
507 else {
507 else {
508 m_markers->setPos(m_rect.topLeft());
508 m_markers->setPos(m_rect.topLeft());
509 }
509 }
510 m_width=m_minWidth;
510 m_width=m_minWidth;
511 }
511 }
512 break;
512 break;
513 }
513 }
514
514
515 m_minOffsetX = 0;
515 m_minOffsetX = 0;
516 m_minOffsetY = 0;
516 m_minOffsetY = 0;
517 m_maxOffsetX = m_width - m_rect.width();
517 m_maxOffsetX = m_width - m_rect.width();
518 m_maxOffsetY = m_height - m_rect.height();
518 m_maxOffsetY = m_height - m_rect.height();
519
519
520 m_presenter->updateLayout();
520 m_presenter->updateLayout();
521 }
521 }
522
522
523 void QLegendPrivate::updateDetachedLayout()
523 void QLegendPrivate::updateDetachedLayout()
524 {
524 {
525 // Detached layout is different.
525 // Detached layout is different.
526 // In detached mode legend may have multiple rows and columns, so layout calculations
526 // In detached mode legend may have multiple rows and columns, so layout calculations
527 // differ a log from attached mode.
527 // differ a log from attached mode.
528 // Also the scrolling logic is bit different.
528 // Also the scrolling logic is bit different.
529 m_offsetX=0;
529 m_offsetX=0;
530 m_offsetY=0;
530 m_offsetY=0;
531 QList<QGraphicsItem *> items = m_markers->childItems();
531 QList<QGraphicsItem *> items = m_markers->childItems();
532
532
533 if(items.isEmpty()) return;
533 if(items.isEmpty()) return;
534
534
535 m_minWidth = 0;
535 m_minWidth = 0;
536 m_minHeight = 0;
536 m_minHeight = 0;
537
537
538 switch (m_alignment) {
538 switch (m_alignment) {
539 case Qt::AlignTop: {
539 case Qt::AlignTop: {
540 QPointF point = m_rect.topLeft();
540 QPointF point = m_rect.topLeft();
541 m_width = 0;
541 m_width = 0;
542 m_height = 0;
542 m_height = 0;
543 for (int i=0; i<items.count(); i++) {
543 for (int i=0; i<items.count(); i++) {
544 QGraphicsItem *item = items.at(i);
544 QGraphicsItem *item = items.at(i);
545 const QRectF& rect = item->boundingRect();
545 const QRectF& rect = item->boundingRect();
546 qreal w = rect.width();
546 qreal w = rect.width();
547 qreal h = rect.height();
547 qreal h = rect.height();
548 m_minWidth = qMax(m_minWidth,w);
548 m_minWidth = qMax(m_minWidth,w);
549 m_minHeight = qMax(m_minHeight,rect.height());
549 m_minHeight = qMax(m_minHeight,rect.height());
550 m_height = qMax(m_height,h);
550 m_height = qMax(m_height,h);
551 item->setPos(point.x(),point.y());
551 item->setPos(point.x(),point.y());
552 point.setX(point.x() + w);
552 point.setX(point.x() + w);
553 if (point.x() + w > m_rect.topLeft().x() + m_rect.width()) {
553 if (point.x() + w > m_rect.topLeft().x() + m_rect.width()) {
554 // Next item would go off rect.
554 // Next item would go off rect.
555 point.setX(m_rect.topLeft().x());
555 point.setX(m_rect.topLeft().x());
556 point.setY(point.y() + h);
556 point.setY(point.y() + h);
557 if (i+1 < items.count()) {
557 if (i+1 < items.count()) {
558 m_height += h;
558 m_height += h;
559 }
559 }
560 }
560 }
561 }
561 }
562 m_markers->setPos(m_rect.topLeft());
562 m_markers->setPos(m_rect.topLeft());
563 m_width = m_minWidth;
563 m_width = m_minWidth;
564
564
565 m_minOffsetX = 0;
565 m_minOffsetX = 0;
566 m_minOffsetY = 0;
566 m_minOffsetY = 0;
567 m_maxOffsetX = m_width - m_rect.width();
567 m_maxOffsetX = m_width - m_rect.width();
568 m_maxOffsetY = m_height - m_rect.height();
568 m_maxOffsetY = m_height - m_rect.height();
569 }
569 }
570 break;
570 break;
571 case Qt::AlignBottom: {
571 case Qt::AlignBottom: {
572 QPointF point = m_rect.bottomLeft();
572 QPointF point = m_rect.bottomLeft();
573 m_width = 0;
573 m_width = 0;
574 m_height = 0;
574 m_height = 0;
575 for (int i=0; i<items.count(); i++) {
575 for (int i=0; i<items.count(); i++) {
576 QGraphicsItem *item = items.at(i);
576 QGraphicsItem *item = items.at(i);
577 const QRectF& rect = item->boundingRect();
577 const QRectF& rect = item->boundingRect();
578 qreal w = rect.width();
578 qreal w = rect.width();
579 qreal h = rect.height();
579 qreal h = rect.height();
580 m_minWidth = qMax(m_minWidth,w);
580 m_minWidth = qMax(m_minWidth,w);
581 m_minHeight = qMax(m_minHeight,rect.height());
581 m_minHeight = qMax(m_minHeight,rect.height());
582 m_height = qMax(m_height,h);
582 m_height = qMax(m_height,h);
583 item->setPos(point.x(),point.y() - h);
583 item->setPos(point.x(),point.y() - h);
584 point.setX(point.x() + w);
584 point.setX(point.x() + w);
585 if (point.x() + w > m_rect.bottomLeft().x() + m_rect.width()) {
585 if (point.x() + w > m_rect.bottomLeft().x() + m_rect.width()) {
586 // Next item would go off rect.
586 // Next item would go off rect.
587 point.setX(m_rect.bottomLeft().x());
587 point.setX(m_rect.bottomLeft().x());
588 point.setY(point.y() - h);
588 point.setY(point.y() - h);
589 if (i+1 < items.count()) {
589 if (i+1 < items.count()) {
590 m_height += h;
590 m_height += h;
591 }
591 }
592 }
592 }
593 }
593 }
594 m_markers->setPos(m_rect.topLeft());
594 m_markers->setPos(m_rect.topLeft());
595 m_width = m_minWidth;
595 m_width = m_minWidth;
596
596
597 m_minOffsetX = 0;
597 m_minOffsetX = 0;
598 m_minOffsetY = qMin(m_rect.topLeft().y(), m_rect.topLeft().y() - m_height + m_rect.height());
598 m_minOffsetY = qMin(m_rect.topLeft().y(), m_rect.topLeft().y() - m_height + m_rect.height());
599 m_maxOffsetX = m_width - m_rect.width();
599 m_maxOffsetX = m_width - m_rect.width();
600 m_maxOffsetY = 0;
600 m_maxOffsetY = 0;
601 }
601 }
602 break;
602 break;
603 case Qt::AlignLeft: {
603 case Qt::AlignLeft: {
604 QPointF point = m_rect.topLeft();
604 QPointF point = m_rect.topLeft();
605 m_width = 0;
605 m_width = 0;
606 m_height = 0;
606 m_height = 0;
607 qreal maxWidth = 0;
607 qreal maxWidth = 0;
608 for (int i=0; i<items.count(); i++) {
608 for (int i=0; i<items.count(); i++) {
609 QGraphicsItem *item = items.at(i);
609 QGraphicsItem *item = items.at(i);
610 const QRectF& rect = item->boundingRect();
610 const QRectF& rect = item->boundingRect();
611 qreal w = rect.width();
611 qreal w = rect.width();
612 qreal h = rect.height();
612 qreal h = rect.height();
613 m_minWidth = qMax(m_minWidth,rect.width());
613 m_minWidth = qMax(m_minWidth,rect.width());
614 m_minHeight = qMax(m_minHeight,h);
614 m_minHeight = qMax(m_minHeight,h);
615 maxWidth = qMax(maxWidth,w);
615 maxWidth = qMax(maxWidth,w);
616 item->setPos(point.x(),point.y());
616 item->setPos(point.x(),point.y());
617 point.setY(point.y() + h);
617 point.setY(point.y() + h);
618 if (point.y() + h > m_rect.topLeft().y() + m_rect.height()) {
618 if (point.y() + h > m_rect.topLeft().y() + m_rect.height()) {
619 // Next item would go off rect.
619 // Next item would go off rect.
620 point.setX(point.x() + maxWidth);
620 point.setX(point.x() + maxWidth);
621 point.setY(m_rect.topLeft().y());
621 point.setY(m_rect.topLeft().y());
622 if (i+1 < items.count()) {
622 if (i+1 < items.count()) {
623 m_width += maxWidth;
623 m_width += maxWidth;
624 maxWidth = 0;
624 maxWidth = 0;
625 }
625 }
626 }
626 }
627 }
627 }
628 m_width += maxWidth;
628 m_width += maxWidth;
629 m_markers->setPos(m_rect.topLeft());
629 m_markers->setPos(m_rect.topLeft());
630 m_height = m_minHeight;
630 m_height = m_minHeight;
631
631
632 m_minOffsetX = 0;
632 m_minOffsetX = 0;
633 m_minOffsetY = 0;
633 m_minOffsetY = 0;
634 m_maxOffsetX = m_width - m_rect.width();
634 m_maxOffsetX = m_width - m_rect.width();
635 m_maxOffsetY = m_height - m_rect.height();
635 m_maxOffsetY = m_height - m_rect.height();
636 }
636 }
637 break;
637 break;
638 case Qt::AlignRight: {
638 case Qt::AlignRight: {
639 QPointF point = m_rect.topRight();
639 QPointF point = m_rect.topRight();
640 m_width = 0;
640 m_width = 0;
641 m_height = 0;
641 m_height = 0;
642 qreal maxWidth = 0;
642 qreal maxWidth = 0;
643 for (int i=0; i<items.count(); i++) {
643 for (int i=0; i<items.count(); i++) {
644 QGraphicsItem *item = items.at(i);
644 QGraphicsItem *item = items.at(i);
645 const QRectF& rect = item->boundingRect();
645 const QRectF& rect = item->boundingRect();
646 qreal w = rect.width();
646 qreal w = rect.width();
647 qreal h = rect.height();
647 qreal h = rect.height();
648 m_minWidth = qMax(m_minWidth,rect.width());
648 m_minWidth = qMax(m_minWidth,rect.width());
649 m_minHeight = qMax(m_minHeight,h);
649 m_minHeight = qMax(m_minHeight,h);
650 maxWidth = qMax(maxWidth,w);
650 maxWidth = qMax(maxWidth,w);
651 item->setPos(point.x() - w,point.y());
651 item->setPos(point.x() - w,point.y());
652 point.setY(point.y() + h);
652 point.setY(point.y() + h);
653 if (point.y() + h > m_rect.topLeft().y() + m_rect.height()) {
653 if (point.y() + h > m_rect.topLeft().y() + m_rect.height()) {
654 // Next item would go off rect.
654 // Next item would go off rect.
655 point.setX(point.x() - maxWidth);
655 point.setX(point.x() - maxWidth);
656 point.setY(m_rect.topLeft().y());
656 point.setY(m_rect.topLeft().y());
657 if (i+1 < items.count()) {
657 if (i+1 < items.count()) {
658 m_width += maxWidth;
658 m_width += maxWidth;
659 maxWidth = 0;
659 maxWidth = 0;
660 }
660 }
661 }
661 }
662 }
662 }
663 m_width += maxWidth;
663 m_width += maxWidth;
664 m_markers->setPos(m_rect.topLeft());
664 m_markers->setPos(m_rect.topLeft());
665 m_height = m_minHeight;
665 m_height = m_minHeight;
666
666
667 m_minOffsetX = qMin(m_rect.topLeft().x(), m_rect.topLeft().x() - m_width + m_rect.width());
667 m_minOffsetX = qMin(m_rect.topLeft().x(), m_rect.topLeft().x() - m_width + m_rect.width());
668 m_minOffsetY = 0;
668 m_minOffsetY = 0;
669 m_maxOffsetX = 0;
669 m_maxOffsetX = 0;
670 m_maxOffsetY = m_height - m_rect.height();
670 m_maxOffsetY = m_height - m_rect.height();
671 }
671 }
672 break;
672 break;
673 default:
673 default:
674 break;
674 break;
675 }
675 }
676 }
676 }
677
677
678 void QLegendPrivate::attachToChart()
678 void QLegendPrivate::attachToChart()
679 {
679 {
680 m_attachedToChart = true;
680 m_attachedToChart = true;
681 q_ptr->setParent(m_chart);
681 q_ptr->setParent(m_chart);
682 }
682 }
683
683
684 int QLegendPrivate::roundness(qreal size)
684 int QLegendPrivate::roundness(qreal size)
685 {
685 {
686 return 100*m_diameter/int(size);
686 return 100*m_diameter/int(size);
687 }
687 }
688
688
689 void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series, Domain *domain)
689 void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series, Domain *domain)
690 {
690 {
691 Q_UNUSED(domain)
691 Q_UNUSED(domain)
692
692
693 QList<LegendMarker*> markers = series->d_ptr->createLegendMarker(q_ptr);
693 QList<LegendMarker*> markers = series->d_ptr->createLegendMarker(q_ptr);
694 foreach(LegendMarker* marker, markers)
694 foreach(LegendMarker* marker, markers)
695 m_markers->addToGroup(marker);
695 m_markers->addToGroup(marker);
696
696
697 if(series->type() == QAbstractSeries::SeriesTypePie) {
697 if(series->type() == QAbstractSeries::SeriesTypePie) {
698 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
698 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
699 QObject::connect(pieSeries, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries()));
699 QObject::connect(pieSeries, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries()));
700 QObject::connect(pieSeries, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries()));
700 QObject::connect(pieSeries, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries()));
701 }
701 }
702
702
703 updateLayout();
703 updateLayout();
704 }
704 }
705
705
706 void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series)
706 void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series)
707 {
707 {
708 QList<QGraphicsItem *> items = m_markers->childItems();
708 QList<QGraphicsItem *> items = m_markers->childItems();
709
709
710 foreach (QGraphicsItem *markers, items) {
710 foreach (QGraphicsItem *markers, items) {
711 LegendMarker *marker = static_cast<LegendMarker*>(markers);
711 LegendMarker *marker = static_cast<LegendMarker*>(markers);
712 if (marker->series() == series) {
712 if (marker->series() == series) {
713 delete marker;
713 delete marker;
714 }
714 }
715 }
715 }
716
716
717 if(series->type() == QAbstractSeries::SeriesTypePie)
717 if(series->type() == QAbstractSeries::SeriesTypePie)
718 {
718 {
719 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
719 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
720 QObject::disconnect(pieSeries, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries()));
720 QObject::disconnect(pieSeries, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries()));
721 QObject::disconnect(pieSeries, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries()));
721 QObject::disconnect(pieSeries, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries()));
722 }
722 }
723
723
724 updateLayout();
724 updateLayout();
725 }
725 }
726
726
727 void QLegendPrivate::handleSeriesUpdated(QAbstractSeries *series)
727 void QLegendPrivate::handleSeriesUpdated(QAbstractSeries *series)
728 {
728 {
729 // TODO: find out which markers are are added or removed. Update them
729 // TODO: find out which markers are are added or removed. Update them
730 // TODO: better implementation
730 // TODO: better implementation
731 handleSeriesRemoved(series);
731 handleSeriesRemoved(series);
732 Domain domain;
732 Domain domain;
733 handleSeriesAdded(series, &domain);
733 handleSeriesAdded(series, &domain);
734 }
734 }
735
735
736 void QLegendPrivate::handleUpdatePieSeries()
736 void QLegendPrivate::handleUpdatePieSeries()
737 {
737 {
738 //TODO: reimplement to be optimal
738 //TODO: reimplement to be optimal
739 QPieSeries* series = qobject_cast<QPieSeries *> (sender());
739 QPieSeries* series = qobject_cast<QPieSeries *> (sender());
740 Q_ASSERT(series);
740 Q_ASSERT(series);
741 handleSeriesRemoved(series);
741 handleSeriesRemoved(series);
742 handleSeriesAdded(series, 0);
742 handleSeriesAdded(series, 0);
743 }
743 }
744
744
745 #include "moc_qlegend.cpp"
745 #include "moc_qlegend.cpp"
746 #include "moc_qlegend_p.cpp"
746 #include "moc_qlegend_p.cpp"
747
747
748 QTCOMMERCIALCHART_END_NAMESPACE
748 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now