##// END OF EJS Templates
Fixes detach legend layout logic
Michal Klocek -
r1536:b5727e9e0a5c
parent child
Show More
@@ -1,368 +1,372
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 "legendlayout_p.h"
21 #include "legendlayout_p.h"
22 #include "chartpresenter_p.h"
22 #include "chartpresenter_p.h"
23 #include "legendmarker_p.h"
23 #include "legendmarker_p.h"
24 #include "qlegend_p.h"
24 #include "qlegend_p.h"
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 LegendLayout::LegendLayout(QLegend* legend):
28 LegendLayout::LegendLayout(QLegend* legend):
29 m_legend(legend)
29 m_legend(legend)
30 {
30 {
31
31
32 }
32 }
33
33
34 LegendLayout::~LegendLayout()
34 LegendLayout::~LegendLayout()
35 {
35 {
36
36
37 }
37 }
38
38
39 void LegendLayout::setOffset(qreal x, qreal y)
39 void LegendLayout::setOffset(qreal x, qreal y)
40 {
40 {
41 bool scrollHorizontal = true;
41 bool scrollHorizontal = true;
42 switch(m_legend->alignment()) {
42 switch(m_legend->alignment()) {
43 case Qt::AlignTop:
43 case Qt::AlignTop:
44 case Qt::AlignBottom: {
44 case Qt::AlignBottom: {
45 scrollHorizontal = true;
45 scrollHorizontal = true;
46 break;
46 break;
47 }
47 }
48 case Qt::AlignLeft:
48 case Qt::AlignLeft:
49 case Qt::AlignRight: {
49 case Qt::AlignRight: {
50 scrollHorizontal = false;
50 scrollHorizontal = false;
51 break;
51 break;
52 }
52 }
53 }
53 }
54
54
55 // If detached, the scrolling direction is vertical instead of horizontal and vice versa.
55 // If detached, the scrolling direction is vertical instead of horizontal and vice versa.
56 if (!m_legend->isAttachedToChart()) {
56 if (!m_legend->isAttachedToChart()) {
57 scrollHorizontal = !scrollHorizontal;
57 scrollHorizontal = !scrollHorizontal;
58 }
58 }
59
59
60 QRectF boundingRect = geometry();
60 QRectF boundingRect = geometry();
61
61
62 // Limit offset between m_minOffset and m_maxOffset
62 // Limit offset between m_minOffset and m_maxOffset
63 if (scrollHorizontal) {
63 if (scrollHorizontal) {
64 if(m_width<=boundingRect.width()) return;
64 if(m_width<=boundingRect.width()) return;
65
65
66 if (x != m_offsetX) {
66 if (x != m_offsetX) {
67 m_offsetX = qBound(m_minOffsetX, x, m_maxOffsetX);
67 m_offsetX = qBound(m_minOffsetX, x, m_maxOffsetX);
68 m_legend->d_ptr->items()->setPos(-m_offsetX,boundingRect.top());
68 m_legend->d_ptr->items()->setPos(-m_offsetX,boundingRect.top());
69 }
69 }
70 }
70 }
71 else {
71 else {
72 if(m_height<=boundingRect.height()) return;
72 if(m_height<=boundingRect.height()) return;
73
73
74 if (y != m_offsetY) {
74 if (y != m_offsetY) {
75 m_offsetY = qBound(m_minOffsetY, y, m_maxOffsetY);
75 m_offsetY = qBound(m_minOffsetY, y, m_maxOffsetY);
76 m_legend->d_ptr->items()->setPos(boundingRect.left(),-m_offsetY);
76 m_legend->d_ptr->items()->setPos(boundingRect.left(),-m_offsetY);
77 }
77 }
78 }
78 }
79 }
79 }
80
80
81 QPointF LegendLayout::offset() const
81 QPointF LegendLayout::offset() const
82 {
82 {
83 return QPointF(m_offsetX,m_offsetY);
83 return QPointF(m_offsetX,m_offsetY);
84 }
84 }
85
85
86 void LegendLayout::setGeometry(const QRectF& rect)
86 void LegendLayout::setGeometry(const QRectF& rect)
87 {
87 {
88 if (!rect.isValid()) return;
88 if (!rect.isValid()) return;
89
89
90 QGraphicsLayout::setGeometry(rect);
90 QGraphicsLayout::setGeometry(rect);
91
91
92 if(m_legend->isAttachedToChart()) {
92 if(m_legend->isAttachedToChart()) {
93 setAttachedGeometry(rect);
93 setAttachedGeometry(rect);
94 }
94 }
95 else {
95 else {
96 setDettachedGeometry(rect);
96 setDettachedGeometry(rect);
97 }
97 }
98 }
98 }
99
99
100 void LegendLayout::setAttachedGeometry(const QRectF& rect)
100 void LegendLayout::setAttachedGeometry(const QRectF& rect)
101 {
101 {
102
102
103 m_offsetX=0;
103 m_offsetX=0;
104 m_offsetY=0;
104 m_offsetY=0;
105
105
106 QSizeF size(0,0);
106 QSizeF size(0,0);
107
107
108 if( m_legend->d_ptr->markers().isEmpty()) return;
108 if( m_legend->d_ptr->markers().isEmpty()) return;
109
109
110 m_width=0;
110 m_width=0;
111 m_height=0;
111 m_height=0;
112
112
113 switch(m_legend->alignment()) {
113 switch(m_legend->alignment()) {
114
114
115 case Qt::AlignTop:
115 case Qt::AlignTop:
116
116
117 case Qt::AlignBottom: {
117 case Qt::AlignBottom: {
118 QPointF point(0,0);
118 QPointF point(0,0);
119 foreach (LegendMarker* marker, m_legend->d_ptr->markers()) {
119 foreach (LegendMarker* marker, m_legend->d_ptr->markers()) {
120 if (marker->isVisible()) {
120 if (marker->isVisible()) {
121 marker->setGeometry(QRectF(QPoint(0,0),marker->effectiveSizeHint(Qt::PreferredSize)));
121 marker->setGeometry(QRectF(QPoint(0,0),marker->effectiveSizeHint(Qt::PreferredSize)));
122 marker->setPos(point.x(),rect.height()/2 - marker->boundingRect().height()/2);
122 marker->setPos(point.x(),rect.height()/2 - marker->boundingRect().height()/2);
123 const QRectF& rect = marker->boundingRect();
123 const QRectF& rect = marker->boundingRect();
124 size = size.expandedTo(rect.size());
124 size = size.expandedTo(rect.size());
125 qreal w = rect.width();
125 qreal w = rect.width();
126 m_width+=w;
126 m_width+=w;
127 point.setX(point.x() + w);
127 point.setX(point.x() + w);
128 }
128 }
129 }
129 }
130 if(m_width<rect.width()) {
130 if(m_width<rect.width()) {
131 m_legend->d_ptr->items()->setPos(rect.width()/2-m_width/2,rect.top());
131 m_legend->d_ptr->items()->setPos(rect.width()/2-m_width/2,rect.top());
132
132
133 }
133 }
134 else {
134 else {
135 m_legend->d_ptr->items()->setPos(rect.topLeft());
135 m_legend->d_ptr->items()->setPos(rect.topLeft());
136 }
136 }
137 m_height=size.height();
137 m_height=size.height();
138 }
138 }
139 break;
139 break;
140 case Qt::AlignLeft:
140 case Qt::AlignLeft:
141 case Qt::AlignRight: {
141 case Qt::AlignRight: {
142 QPointF point(0,0);
142 QPointF point(0,0);
143 foreach (LegendMarker* marker, m_legend->d_ptr->markers()) {
143 foreach (LegendMarker* marker, m_legend->d_ptr->markers()) {
144 if (marker->isVisible()) {
144 if (marker->isVisible()) {
145 marker->setGeometry(QRectF(QPoint(0,0),marker->effectiveSizeHint(Qt::PreferredSize)));
145 marker->setGeometry(QRectF(QPoint(0,0),marker->effectiveSizeHint(Qt::PreferredSize)));
146 marker->setPos(point);
146 marker->setPos(point);
147 const QRectF& rect = marker->boundingRect();
147 const QRectF& rect = marker->boundingRect();
148 qreal h = rect.height();
148 qreal h = rect.height();
149 size = size.expandedTo(rect.size());
149 size = size.expandedTo(rect.size());
150 m_height+=h;
150 m_height+=h;
151 point.setY(point.y() + h);
151 point.setY(point.y() + h);
152 }
152 }
153 }
153 }
154 if(m_height<rect.height()) {
154 if(m_height<rect.height()) {
155 m_legend->d_ptr->items()->setPos(rect.left(),rect.height()/2-m_height/2);
155 m_legend->d_ptr->items()->setPos(rect.left(),rect.height()/2-m_height/2);
156 }
156 }
157 else {
157 else {
158 m_legend->d_ptr->items()->setPos(rect.topLeft());
158 m_legend->d_ptr->items()->setPos(rect.topLeft());
159 }
159 }
160 m_width=size.width();
160 m_width=size.width();
161 }
161 }
162 break;
162 break;
163 }
163 }
164
164
165 m_minOffsetX = 0;
165 m_minOffsetX = 0;
166 m_minOffsetY = 0;
166 m_minOffsetY = 0;
167 m_maxOffsetX = m_width - rect.width();
167 m_maxOffsetX = m_width - rect.width();
168 m_maxOffsetY = m_height - rect.height();
168 m_maxOffsetY = m_height - rect.height();
169 }
169 }
170
170
171 void LegendLayout::setDettachedGeometry(const QRectF& rect)
171 void LegendLayout::setDettachedGeometry(const QRectF& rect)
172 {
172 {
173 // Detached layout is different.
173 // Detached layout is different.
174 // In detached mode legend may have multiple rows and columns, so layout calculations
174 // In detached mode legend may have multiple rows and columns, so layout calculations
175 // differ a log from attached mode.
175 // differ a log from attached mode.
176 // Also the scrolling logic is bit different.
176 // Also the scrolling logic is bit different.
177
177
178 m_offsetX=0;
178 m_offsetX=0;
179 m_offsetY=0;
179 m_offsetY=0;
180
180
181 QSizeF size(0,0);
181 QSizeF size(0,0);
182
182
183 if( m_legend->d_ptr->markers().isEmpty()) return;
183 QList<LegendMarker *> markers = m_legend->d_ptr->markers();
184
184
185 QList<QGraphicsItem *> items = m_legend->d_ptr->items()->childItems();
185 if(markers.isEmpty()) return;
186
186
187 switch (m_legend->alignment()) {
187 switch (m_legend->alignment()) {
188 case Qt::AlignTop: {
188 case Qt::AlignTop: {
189 QPointF point = rect.topLeft();
189 QPointF point = rect.topLeft();
190 m_width = 0;
190 m_width = 0;
191 m_height = 0;
191 m_height = 0;
192 for (int i=0; i<items.count(); i++) {
192 for (int i=0; i<markers.count(); i++) {
193 QGraphicsItem *item = items.at(i);
193 LegendMarker *marker = markers.at(i);
194 if (item->isVisible()) {
194 if (marker->isVisible()) {
195 const QRectF& boundingRect = item->boundingRect();
195 marker->setGeometry(QRectF(QPoint(0,0),marker->effectiveSizeHint(Qt::PreferredSize)));
196 marker->setPos(point.x(),point.y());
197 const QRectF& boundingRect = marker->boundingRect();
196 qreal w = boundingRect.width();
198 qreal w = boundingRect.width();
197 qreal h = boundingRect.height();
199 qreal h = boundingRect.height();
198 m_width = qMax(m_width,w);
200 m_width = qMax(m_width,w);
199 m_height = qMax(m_height,h);
201 m_height = qMax(m_height,h);
200 item->setPos(point.x(),point.y());
201 point.setX(point.x() + w);
202 point.setX(point.x() + w);
202 if (point.x() + w > rect.topLeft().x() + rect.width()) {
203 if (point.x() + w > rect.topLeft().x() + rect.width()) {
203 // Next item would go off rect.
204 // Next item would go off rect.
204 point.setX(rect.topLeft().x());
205 point.setX(rect.topLeft().x());
205 point.setY(point.y() + h);
206 point.setY(point.y() + h);
206 if (i+1 < items.count()) {
207 if (i+1 < markers.count()) {
207 m_height += h;
208 m_height += h;
208 }
209 }
209 }
210 }
210 }
211 }
211 }
212 }
212 m_legend->d_ptr->items()->setPos(rect.topLeft());
213 m_legend->d_ptr->items()->setPos(rect.topLeft());
213
214
214 m_minOffsetX = 0;
215 m_minOffsetX = 0;
215 m_minOffsetY = 0;
216 m_minOffsetY = 0;
216 m_maxOffsetX = m_width - rect.width();
217 m_maxOffsetX = m_width - rect.width();
217 m_maxOffsetY = m_height - rect.height();
218 m_maxOffsetY = m_height - rect.height();
218 }
219 }
219 break;
220 break;
220 case Qt::AlignBottom: {
221 case Qt::AlignBottom: {
221 QPointF point = rect.bottomLeft();
222 QPointF point = rect.bottomLeft();
222 m_width = 0;
223 m_width = 0;
223 m_height = 0;
224 m_height = 0;
224 for (int i=0; i<items.count(); i++) {
225 for (int i=0; i<markers.count(); i++) {
225 QGraphicsItem *item = items.at(i);
226 LegendMarker *marker = markers.at(i);
226 if (item->isVisible()) {
227 if (marker->isVisible()) {
227 const QRectF& boundingRect = item->boundingRect();
228 marker->setGeometry(QRectF(QPoint(0,0),marker->effectiveSizeHint(Qt::PreferredSize)));
229 const QRectF& boundingRect = marker->boundingRect();
228 qreal w = boundingRect.width();
230 qreal w = boundingRect.width();
229 qreal h = boundingRect.height();
231 qreal h = boundingRect.height();
230 m_width = qMax(m_width,w);
232 m_width = qMax(m_width,w);
231 m_height = qMax(m_height,h);
233 m_height = qMax(m_height,h);
232 item->setPos(point.x(),point.y() - h);
234 marker->setPos(point.x(),point.y() - h);
233 point.setX(point.x() + w);
235 point.setX(point.x() + w);
234 if (point.x() + w > rect.bottomLeft().x() + rect.width()) {
236 if (point.x() + w > rect.bottomLeft().x() + rect.width()) {
235 // Next item would go off rect.
237 // Next item would go off rect.
236 point.setX(rect.bottomLeft().x());
238 point.setX(rect.bottomLeft().x());
237 point.setY(point.y() - h);
239 point.setY(point.y() - h);
238 if (i+1 < items.count()) {
240 if (i+1 < markers.count()) {
239 m_height += h;
241 m_height += h;
240 }
242 }
241 }
243 }
242 }
244 }
243 }
245 }
244 m_legend->d_ptr->items()->setPos(rect.topLeft());
246 m_legend->d_ptr->items()->setPos(rect.topLeft());
245
247
246 m_minOffsetX = 0;
248 m_minOffsetX = 0;
247 m_minOffsetY = qMin(rect.topLeft().y(), rect.topLeft().y() - m_height + rect.height());
249 m_minOffsetY = qMin(rect.topLeft().y(), rect.topLeft().y() - m_height + rect.height());
248 m_maxOffsetX = m_width - rect.width();
250 m_maxOffsetX = m_width - rect.width();
249 m_maxOffsetY = 0;
251 m_maxOffsetY = 0;
250 }
252 }
251 break;
253 break;
252 case Qt::AlignLeft: {
254 case Qt::AlignLeft: {
253 QPointF point = rect.topLeft();
255 QPointF point = rect.topLeft();
254 m_width = 0;
256 m_width = 0;
255 m_height = 0;
257 m_height = 0;
256 qreal maxWidth = 0;
258 qreal maxWidth = 0;
257 for (int i=0; i<items.count(); i++) {
259 for (int i=0; i<markers.count(); i++) {
258 QGraphicsItem *item = items.at(i);
260 LegendMarker *marker = markers.at(i);
259 if (item->isVisible()) {
261 if (marker->isVisible()) {
260 const QRectF& boundingRect = item->boundingRect();
262 marker->setGeometry(QRectF(QPoint(0,0),marker->effectiveSizeHint(Qt::PreferredSize)));
263 const QRectF& boundingRect = marker->boundingRect();
261 qreal w = boundingRect.width();
264 qreal w = boundingRect.width();
262 qreal h = boundingRect.height();
265 qreal h = boundingRect.height();
263 m_height = qMax(m_height,h);
266 m_height = qMax(m_height,h);
264 maxWidth = qMax(maxWidth,w);
267 maxWidth = qMax(maxWidth,w);
265 item->setPos(point.x(),point.y());
268 marker->setPos(point.x(),point.y());
266 point.setY(point.y() + h);
269 point.setY(point.y() + h);
267 if (point.y() + h > rect.topLeft().y() + rect.height()) {
270 if (point.y() + h > rect.topLeft().y() + rect.height()) {
268 // Next item would go off rect.
271 // Next item would go off rect.
269 point.setX(point.x() + maxWidth);
272 point.setX(point.x() + maxWidth);
270 point.setY(rect.topLeft().y());
273 point.setY(rect.topLeft().y());
271 if (i+1 < items.count()) {
274 if (i+1 < markers.count()) {
272 m_width += maxWidth;
275 m_width += maxWidth;
273 maxWidth = 0;
276 maxWidth = 0;
274 }
277 }
275 }
278 }
276 }
279 }
277 }
280 }
278 m_width += maxWidth;
281 m_width += maxWidth;
279 m_legend->d_ptr->items()->setPos(rect.topLeft());
282 m_legend->d_ptr->items()->setPos(rect.topLeft());
280
283
281 m_minOffsetX = 0;
284 m_minOffsetX = 0;
282 m_minOffsetY = 0;
285 m_minOffsetY = 0;
283 m_maxOffsetX = m_width - rect.width();
286 m_maxOffsetX = m_width - rect.width();
284 m_maxOffsetY = m_height - rect.height();
287 m_maxOffsetY = m_height - rect.height();
285 }
288 }
286 break;
289 break;
287 case Qt::AlignRight: {
290 case Qt::AlignRight: {
288 QPointF point = rect.topRight();
291 QPointF point = rect.topRight();
289 m_width = 0;
292 m_width = 0;
290 m_height = 0;
293 m_height = 0;
291 qreal maxWidth = 0;
294 qreal maxWidth = 0;
292 for (int i=0; i<items.count(); i++) {
295 for (int i=0; i<markers.count(); i++) {
293 QGraphicsItem *item = items.at(i);
296 LegendMarker *marker = markers.at(i);
294 if (item->isVisible()) {
297 if (marker->isVisible()) {
295 const QRectF& boundingRect = item->boundingRect();
298 marker->setGeometry(QRectF(QPoint(0,0),marker->effectiveSizeHint(Qt::PreferredSize)));
299 const QRectF& boundingRect = marker->boundingRect();
296 qreal w = boundingRect.width();
300 qreal w = boundingRect.width();
297 qreal h = boundingRect.height();
301 qreal h = boundingRect.height();
298 m_height = qMax(m_height,h);
302 m_height = qMax(m_height,h);
299 maxWidth = qMax(maxWidth,w);
303 maxWidth = qMax(maxWidth,w);
300 item->setPos(point.x() - w,point.y());
304 marker->setPos(point.x() - w,point.y());
301 point.setY(point.y() + h);
305 point.setY(point.y() + h);
302 if (point.y() + h > rect.topLeft().y() + rect.height()) {
306 if (point.y() + h > rect.topLeft().y() + rect.height()) {
303 // Next item would go off rect.
307 // Next item would go off rect.
304 point.setX(point.x() - maxWidth);
308 point.setX(point.x() - maxWidth);
305 point.setY(rect.topLeft().y());
309 point.setY(rect.topLeft().y());
306 if (i+1 < items.count()) {
310 if (i+1 < markers.count()) {
307 m_width += maxWidth;
311 m_width += maxWidth;
308 maxWidth = 0;
312 maxWidth = 0;
309 }
313 }
310 }
314 }
311 }
315 }
312 }
316 }
313 m_width += maxWidth;
317 m_width += maxWidth;
314 m_legend->d_ptr->items()->setPos(rect.topLeft());
318 m_legend->d_ptr->items()->setPos(rect.topLeft());
315
319
316 m_minOffsetX = qMin(rect.topLeft().x(), rect.topLeft().x() - m_width + rect.width());
320 m_minOffsetX = qMin(rect.topLeft().x(), rect.topLeft().x() - m_width + rect.width());
317 m_minOffsetY = 0;
321 m_minOffsetY = 0;
318 m_maxOffsetX = 0;
322 m_maxOffsetX = 0;
319 m_maxOffsetY = m_height - rect.height();
323 m_maxOffsetY = m_height - rect.height();
320 }
324 }
321 break;
325 break;
322 default:
326 default:
323 break;
327 break;
324 }
328 }
325
329
326 }
330 }
327
331
328 QSizeF LegendLayout::sizeHint ( Qt::SizeHint which, const QSizeF & constraint) const
332 QSizeF LegendLayout::sizeHint ( Qt::SizeHint which, const QSizeF & constraint) const
329 {
333 {
330 QSizeF size(0, 0);
334 QSizeF size(0, 0);
331 qreal left, top, right, bottom;
335 qreal left, top, right, bottom;
332 getContentsMargins(&left, &top, &right, &bottom);
336 getContentsMargins(&left, &top, &right, &bottom);
333
337
334 if(constraint.isValid()) {
338 if(constraint.isValid()) {
335 foreach(LegendMarker* marker, m_legend->d_ptr->markers()) {
339 foreach(LegendMarker* marker, m_legend->d_ptr->markers()) {
336 size = size.expandedTo(marker->effectiveSizeHint(which));
340 size = size.expandedTo(marker->effectiveSizeHint(which));
337 }
341 }
338 size = size.boundedTo(constraint);
342 size = size.boundedTo(constraint);
339 }
343 }
340 else if (constraint.width() >= 0) {
344 else if (constraint.width() >= 0) {
341 qreal width = 0;
345 qreal width = 0;
342 qreal height = 0;
346 qreal height = 0;
343 foreach(LegendMarker* marker, m_legend->d_ptr->markers()) {
347 foreach(LegendMarker* marker, m_legend->d_ptr->markers()) {
344 width+=marker->effectiveSizeHint(which).width();
348 width+=marker->effectiveSizeHint(which).width();
345 height=qMax(height,marker->effectiveSizeHint(which).height());
349 height=qMax(height,marker->effectiveSizeHint(which).height());
346 }
350 }
347
351
348 size = QSizeF(qMin(constraint.width(),width), height);
352 size = QSizeF(qMin(constraint.width(),width), height);
349 }
353 }
350 else if (constraint.height() >= 0) {
354 else if (constraint.height() >= 0) {
351 qreal width = 0;
355 qreal width = 0;
352 qreal height = 0;
356 qreal height = 0;
353 foreach(LegendMarker* marker, m_legend->d_ptr->markers()) {
357 foreach(LegendMarker* marker, m_legend->d_ptr->markers()) {
354 width=qMax(width,marker->effectiveSizeHint(which).width());
358 width=qMax(width,marker->effectiveSizeHint(which).width());
355 height+=height,marker->effectiveSizeHint(which).height();
359 height+=height,marker->effectiveSizeHint(which).height();
356 }
360 }
357 size = QSizeF(width,qMin(constraint.height(),height));
361 size = QSizeF(width,qMin(constraint.height(),height));
358 }
362 }
359 else {
363 else {
360 foreach(LegendMarker* marker, m_legend->d_ptr->markers()) {
364 foreach(LegendMarker* marker, m_legend->d_ptr->markers()) {
361 size = size.expandedTo(marker->effectiveSizeHint(which));
365 size = size.expandedTo(marker->effectiveSizeHint(which));
362 }
366 }
363 }
367 }
364 size += QSize(left + right, top + bottom);
368 size += QSize(left + right, top + bottom);
365 return size;
369 return size;
366 }
370 }
367
371
368 QTCOMMERCIALCHART_END_NAMESPACE
372 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,233 +1,234
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 "legendmarker_p.h"
21 #include "legendmarker_p.h"
22 #include "qxyseries.h"
22 #include "qxyseries.h"
23 #include "qxyseries_p.h"
23 #include "qxyseries_p.h"
24 #include "qlegend.h"
24 #include "qlegend.h"
25 #include "qbarseries.h"
25 #include "qbarseries.h"
26 #include "qpieseries.h"
26 #include "qpieseries.h"
27 #include "qpieslice.h"
27 #include "qpieslice.h"
28 #include "qbarset.h"
28 #include "qbarset.h"
29 #include "qbarset_p.h"
29 #include "qbarset_p.h"
30 #include "qareaseries.h"
30 #include "qareaseries.h"
31 #include "qareaseries_p.h"
31 #include "qareaseries_p.h"
32 #include <QPainter>
32 #include <QPainter>
33 #include <QGraphicsSceneEvent>
33 #include <QGraphicsSceneEvent>
34 #include <QGraphicsSimpleTextItem>
34 #include <QGraphicsSimpleTextItem>
35 #include <QDebug>
35 #include <QDebug>
36
36
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38
38
39 LegendMarker::LegendMarker(QAbstractSeries *series, QLegend *legend) :
39 LegendMarker::LegendMarker(QAbstractSeries *series, QLegend *legend) :
40 QGraphicsObject(legend),
40 QGraphicsObject(legend),
41 m_series(series),
41 m_series(series),
42 m_markerRect(0,0,10.0,10.0),
42 m_markerRect(0,0,10.0,10.0),
43 m_boundingRect(0,0,0,0),
43 m_boundingRect(0,0,0,0),
44 m_legend(legend),
44 m_legend(legend),
45 m_textItem(new QGraphicsSimpleTextItem(this)),
45 m_textItem(new QGraphicsSimpleTextItem(this)),
46 m_rectItem(new QGraphicsRectItem(this)),
46 m_rectItem(new QGraphicsRectItem(this)),
47 m_margin(2),
47 m_margin(2),
48 m_space(4)
48 m_space(4)
49 {
49 {
50 //setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton);
50 //setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton);
51 m_rectItem->setRect(m_markerRect);
51 m_rectItem->setRect(m_markerRect);
52 }
52 }
53
53
54 void LegendMarker::setPen(const QPen &pen)
54 void LegendMarker::setPen(const QPen &pen)
55 {
55 {
56 m_rectItem->setPen(pen);
56 m_rectItem->setPen(pen);
57 m_textItem->setPen(pen);
57 m_textItem->setPen(pen);
58 }
58 }
59
59
60 QPen LegendMarker::pen() const
60 QPen LegendMarker::pen() const
61 {
61 {
62 return m_rectItem->pen();
62 return m_rectItem->pen();
63 }
63 }
64
64
65 void LegendMarker::setBrush(const QBrush &brush)
65 void LegendMarker::setBrush(const QBrush &brush)
66 {
66 {
67 m_rectItem->setBrush(brush);
67 m_rectItem->setBrush(brush);
68 }
68 }
69
69
70 QBrush LegendMarker::brush() const
70 QBrush LegendMarker::brush() const
71 {
71 {
72 return m_rectItem->brush();
72 return m_rectItem->brush();
73 }
73 }
74
74
75 void LegendMarker::setFont(const QFont &font)
75 void LegendMarker::setFont(const QFont &font)
76 {
76 {
77 m_textItem->setFont(font);
77 m_textItem->setFont(font);
78 updateGeometry();
78 }
79 }
79
80
80 QFont LegendMarker::font() const
81 QFont LegendMarker::font() const
81 {
82 {
82 return m_textItem->font();
83 return m_textItem->font();
83 }
84 }
84
85
85 void LegendMarker::setLabel(const QString label)
86 void LegendMarker::setLabel(const QString label)
86 {
87 {
87 m_textItem->setText(label);
88 m_textItem->setText(label);
88 }
89 }
89
90
90 QString LegendMarker::label() const
91 QString LegendMarker::label() const
91 {
92 {
92 return m_textItem->text();
93 return m_textItem->text();
93 }
94 }
94
95
95 QRectF LegendMarker::boundingRect() const
96 QRectF LegendMarker::boundingRect() const
96 {
97 {
97 return m_boundingRect;
98 return m_boundingRect;
98 }
99 }
99
100
100 void LegendMarker::setLabelBrush(const QBrush &brush)
101 void LegendMarker::setLabelBrush(const QBrush &brush)
101 {
102 {
102 m_textItem->setBrush(brush);
103 m_textItem->setBrush(brush);
103 }
104 }
104
105
105 QBrush LegendMarker::labelBrush() const
106 QBrush LegendMarker::labelBrush() const
106 {
107 {
107 return m_textItem->brush();
108 return m_textItem->brush();
108 }
109 }
109
110
110
111
111 void LegendMarker::setGeometry(const QRectF& rect)
112 void LegendMarker::setGeometry(const QRectF& rect)
112 {
113 {
113 const QRectF& textRect = m_textItem->boundingRect();
114 const QRectF& textRect = m_textItem->boundingRect();
114
115
115 m_textItem->setPos(m_markerRect.width() + m_space + m_margin,rect.height()/2 - textRect.height()/2);
116 m_textItem->setPos(m_markerRect.width() + m_space + m_margin,rect.height()/2 - textRect.height()/2);
116 m_rectItem->setPos(m_margin,rect.height()/2 - m_markerRect.height()/2);
117 m_rectItem->setPos(m_margin,rect.height()/2 - m_markerRect.height()/2);
117
118
118 prepareGeometryChange();
119 prepareGeometryChange();
119 m_boundingRect = rect;
120 m_boundingRect = rect;
120 }
121 }
121
122
122 void LegendMarker::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
123 void LegendMarker::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
123 {
124 {
124 Q_UNUSED(option)
125 Q_UNUSED(option)
125 Q_UNUSED(widget)
126 Q_UNUSED(widget)
126 Q_UNUSED(painter)
127 Q_UNUSED(painter)
127 }
128 }
128
129
129
130
130 QSizeF LegendMarker::sizeHint(Qt::SizeHint which, const QSizeF& constraint) const
131 QSizeF LegendMarker::sizeHint(Qt::SizeHint which, const QSizeF& constraint) const
131 {
132 {
132 Q_UNUSED(constraint)
133 Q_UNUSED(constraint)
133
134
134 QFontMetrics fn(m_textItem->font());
135 QFontMetrics fn(m_textItem->font());
135 QSizeF sh;
136 QSizeF sh;
136
137
137 switch (which) {
138 switch (which) {
138 case Qt::MinimumSize:
139 case Qt::MinimumSize:
139 sh = QSizeF(fn.boundingRect("...").width(),fn.height());
140 sh = QSizeF(fn.boundingRect("...").width(),fn.height());
140 break;
141 break;
141 case Qt::PreferredSize:
142 case Qt::PreferredSize:
142 sh = QSizeF(fn.boundingRect(m_textItem->text()).width() + 2*m_margin + m_space +m_markerRect.width(),qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin));
143 sh = QSizeF(fn.boundingRect(m_textItem->text()).width() + 2*m_margin + m_space +m_markerRect.width(),qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin));
143 break;
144 break;
144 default:
145 default:
145 break;
146 break;
146 }
147 }
147
148
148 return sh;
149 return sh;
149 }
150 }
150
151
151 void LegendMarker::mousePressEvent(QGraphicsSceneMouseEvent *event)
152 void LegendMarker::mousePressEvent(QGraphicsSceneMouseEvent *event)
152 {
153 {
153 QGraphicsObject::mousePressEvent(event);
154 QGraphicsObject::mousePressEvent(event);
154 qDebug()<<"Not implemented"; //TODO: selected signal removed for now
155 qDebug()<<"Not implemented"; //TODO: selected signal removed for now
155 }
156 }
156
157
157 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
158 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
158
159
159 AreaLegendMarker::AreaLegendMarker(QAreaSeries *series,QLegend *legend) : LegendMarker(series,legend),
160 AreaLegendMarker::AreaLegendMarker(QAreaSeries *series,QLegend *legend) : LegendMarker(series,legend),
160 m_series(series)
161 m_series(series)
161 {
162 {
162 //QObject::connect(this, SIGNAL(selected()), series, SIGNAL(selected()));
163 //QObject::connect(this, SIGNAL(selected()), series, SIGNAL(selected()));
163 QObject::connect(series->d_func(),SIGNAL(updated()), this, SLOT(updated()));
164 QObject::connect(series->d_func(),SIGNAL(updated()), this, SLOT(updated()));
164 QObject::connect(series, SIGNAL(nameChanged()), this, SLOT(updated()));
165 QObject::connect(series, SIGNAL(nameChanged()), this, SLOT(updated()));
165 updated();
166 updated();
166 }
167 }
167
168
168 void AreaLegendMarker::updated()
169 void AreaLegendMarker::updated()
169 {
170 {
170 setBrush(m_series->brush());
171 setBrush(m_series->brush());
171 setLabel(m_series->name());
172 setLabel(m_series->name());
172 }
173 }
173
174
174 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
175 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
175
176
176 BarLegendMarker::BarLegendMarker(QBarSeries *barseries,QBarSet *barset, QLegend *legend) : LegendMarker(barseries,legend),
177 BarLegendMarker::BarLegendMarker(QBarSeries *barseries,QBarSet *barset, QLegend *legend) : LegendMarker(barseries,legend),
177 m_barset(barset)
178 m_barset(barset)
178 {
179 {
179 //QObject::connect(this, SIGNAL(selected()),barset->d_ptr.data(), SIGNAL(selected()));
180 //QObject::connect(this, SIGNAL(selected()),barset->d_ptr.data(), SIGNAL(selected()));
180 QObject::connect(barset->d_ptr.data(), SIGNAL(updatedBars()), this, SLOT(updated()));
181 QObject::connect(barset->d_ptr.data(), SIGNAL(updatedBars()), this, SLOT(updated()));
181 updated();
182 updated();
182 }
183 }
183
184
184 void BarLegendMarker::updated()
185 void BarLegendMarker::updated()
185 {
186 {
186 setBrush(m_barset->brush());
187 setBrush(m_barset->brush());
187 setLabel(m_barset->label());
188 setLabel(m_barset->label());
188 }
189 }
189
190
190 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
191 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
191
192
192 PieLegendMarker::PieLegendMarker(QPieSeries* series,QPieSlice *pieslice, QLegend *legend) : LegendMarker(series,legend),
193 PieLegendMarker::PieLegendMarker(QPieSeries* series,QPieSlice *pieslice, QLegend *legend) : LegendMarker(series,legend),
193 m_pieslice(pieslice)
194 m_pieslice(pieslice)
194 {
195 {
195 QObject::connect(pieslice, SIGNAL(labelChanged()), this, SLOT(updated()));
196 QObject::connect(pieslice, SIGNAL(labelChanged()), this, SLOT(updated()));
196 QObject::connect(pieslice, SIGNAL(brushChanged()), this, SLOT(updated()));
197 QObject::connect(pieslice, SIGNAL(brushChanged()), this, SLOT(updated()));
197 updated();
198 updated();
198 }
199 }
199
200
200 void PieLegendMarker::updated()
201 void PieLegendMarker::updated()
201 {
202 {
202 setBrush(m_pieslice->brush());
203 setBrush(m_pieslice->brush());
203 setLabel(m_pieslice->label());
204 setLabel(m_pieslice->label());
204 }
205 }
205
206
206 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
207 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
207
208
208 XYLegendMarker::XYLegendMarker(QXYSeries *series, QLegend *legend) : LegendMarker(series,legend),
209 XYLegendMarker::XYLegendMarker(QXYSeries *series, QLegend *legend) : LegendMarker(series,legend),
209 m_series(series)
210 m_series(series)
210 {
211 {
211 //QObject::connect(this, SIGNAL(selected()), series, SIGNAL(selected()));
212 //QObject::connect(this, SIGNAL(selected()), series, SIGNAL(selected()));
212 QObject::connect(series->d_func(),SIGNAL(updated()), this, SLOT(updated()));
213 QObject::connect(series->d_func(),SIGNAL(updated()), this, SLOT(updated()));
213 QObject::connect(series, SIGNAL(nameChanged()), this, SLOT(updated()));
214 QObject::connect(series, SIGNAL(nameChanged()), this, SLOT(updated()));
214 updated();
215 updated();
215 }
216 }
216
217
217 void XYLegendMarker::updated()
218 void XYLegendMarker::updated()
218 {
219 {
219 setLabel(m_series->name());
220 setLabel(m_series->name());
220
221
221 if(m_series->type()== QAbstractSeries::SeriesTypeScatter)
222 if(m_series->type()== QAbstractSeries::SeriesTypeScatter)
222 {
223 {
223 setBrush(m_series->brush());
224 setBrush(m_series->brush());
224
225
225 }
226 }
226 else {
227 else {
227 setBrush(QBrush(m_series->pen().color()));
228 setBrush(QBrush(m_series->pen().color()));
228 }
229 }
229 }
230 }
230
231
231 #include "moc_legendmarker_p.cpp"
232 #include "moc_legendmarker_p.cpp"
232
233
233 QTCOMMERCIALCHART_END_NAMESPACE
234 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,549 +1,550
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qlegend.h"
21 #include "qlegend.h"
22 #include "qlegend_p.h"
22 #include "qlegend_p.h"
23 #include "qabstractseries.h"
23 #include "qabstractseries.h"
24 #include "qabstractseries_p.h"
24 #include "qabstractseries_p.h"
25 #include "qchart_p.h"
25 #include "qchart_p.h"
26 #include "legendlayout_p.h"
26 #include "legendlayout_p.h"
27 #include "legendmarker_p.h"
27 #include "legendmarker_p.h"
28 #include "qxyseries.h"
28 #include "qxyseries.h"
29 #include "qlineseries.h"
29 #include "qlineseries.h"
30 #include "qareaseries.h"
30 #include "qareaseries.h"
31 #include "qscatterseries.h"
31 #include "qscatterseries.h"
32 #include "qsplineseries.h"
32 #include "qsplineseries.h"
33 #include "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 #include <QGraphicsLayout>
44 #include <QGraphicsLayout>
45 #include <QGraphicsSceneEvent>
45 #include <QGraphicsSceneEvent>
46
46
47 QTCOMMERCIALCHART_BEGIN_NAMESPACE
47 QTCOMMERCIALCHART_BEGIN_NAMESPACE
48
48
49 /*!
49 /*!
50 \class QLegend
50 \class QLegend
51 \brief Legend object
51 \brief Legend object
52 \mainclass
52 \mainclass
53
53
54 QLegend is a graphical object, whics displays legend of the chart. Legend state is updated by QChart, when
54 QLegend is a graphical object, whics displays legend of the chart. Legend state is updated by QChart, when
55 series have been changed. By default, legend is drawn by QChart, but user can set a new parent to legend and
55 series have been changed. By default, legend is drawn by QChart, but user can set a new parent to legend and
56 handle the drawing manually.
56 handle the drawing manually.
57 User isn't supposed to create or delete legend objects, but can reference it via QChart class.
57 User isn't supposed to create or delete legend objects, but can reference it via QChart class.
58
58
59 \image examples_percentbarchart_legend.png
59 \image examples_percentbarchart_legend.png
60
60
61 \sa QChart
61 \sa QChart
62 */
62 */
63 /*!
63 /*!
64 \qmlclass Legend QLegend
64 \qmlclass Legend QLegend
65 \brief Legend is part of QtCommercial Chart QML API.
65 \brief Legend is part of QtCommercial Chart QML API.
66
66
67 Legend is a graphical object, whics displays legend of the chart. Legend state is updated by ChartView, when
67 Legend is a graphical object, whics displays legend of the chart. Legend state is updated by ChartView, when
68 series have been changed. Legend is used via ChartView class. For example:
68 series have been changed. Legend is used via ChartView class. For example:
69 \code
69 \code
70 ChartView {
70 ChartView {
71 legend.visible: true
71 legend.visible: true
72 legend.alignment: Qt.AlignBottom
72 legend.alignment: Qt.AlignBottom
73 // Add a few series...
73 // Add a few series...
74 }
74 }
75 \endcode
75 \endcode
76
76
77 \image examples_percentbarchart_legend.png
77 \image examples_percentbarchart_legend.png
78 */
78 */
79
79
80 /*!
80 /*!
81 \property QLegend::alignment
81 \property QLegend::alignment
82 \brief The alignment of the legend.
82 \brief The alignment of the legend.
83
83
84 Legend paints on the defined position in the chart. The following alignments are supported:
84 Legend paints on the defined position in the chart. The following alignments are supported:
85 Qt::AlignTop, Qt::AlignBottom, Qt::AlignLeft, Qt::AlignRight. If you set more than one flag the result is undefined.
85 Qt::AlignTop, Qt::AlignBottom, Qt::AlignLeft, Qt::AlignRight. If you set more than one flag the result is undefined.
86 */
86 */
87 /*!
87 /*!
88 \qmlproperty Qt.Alignment Legend::alignment
88 \qmlproperty Qt.Alignment Legend::alignment
89 \brief The alignment of the legend.
89 \brief The alignment of the legend.
90
90
91 Legend paints on the defined position in the chart. The following alignments are supported:
91 Legend paints on the defined position in the chart. The following alignments are supported:
92 Qt.AlignTop, Qt.AlignBottom, Qt.AlignLeft, Qt.AlignRight. If you set more than one flag the result is undefined.
92 Qt.AlignTop, Qt.AlignBottom, Qt.AlignLeft, Qt.AlignRight. If you set more than one flag the result is undefined.
93 */
93 */
94
94
95 /*!
95 /*!
96 \property QLegend::backgroundVisible
96 \property QLegend::backgroundVisible
97 Whether the legend background is visible or not.
97 Whether the legend background is visible or not.
98 */
98 */
99 /*!
99 /*!
100 \qmlproperty bool Legend::backgroundVisible
100 \qmlproperty bool Legend::backgroundVisible
101 Whether the legend background is visible or not.
101 Whether the legend background is visible or not.
102 */
102 */
103
103
104 /*!
104 /*!
105 \property QLegend::color
105 \property QLegend::color
106 The color of the legend, i.e. the background (brush) color. Note that if you change the color
106 The color of the legend, i.e. the background (brush) color. Note that if you change the color
107 of the legend, the style of the legend brush is set to Qt::SolidPattern.
107 of the legend, the style of the legend brush is set to Qt::SolidPattern.
108 */
108 */
109 /*!
109 /*!
110 \qmlproperty color Legend::color
110 \qmlproperty color Legend::color
111 The color of the legend, i.e. the background (brush) color.
111 The color of the legend, i.e. the background (brush) color.
112 */
112 */
113
113
114 /*!
114 /*!
115 \property QLegend::borderColor
115 \property QLegend::borderColor
116 The border color of the legend, i.e. the line color.
116 The border color of the legend, i.e. the line color.
117 */
117 */
118 /*!
118 /*!
119 \qmlproperty color Legend::borderColor
119 \qmlproperty color Legend::borderColor
120 The border color of the legend, i.e. the line color.
120 The border color of the legend, i.e. the line color.
121 */
121 */
122
122
123 /*!
123 /*!
124 \property QLegend::font
124 \property QLegend::font
125 The font of markers used by legend
125 The font of markers used by legend
126 */
126 */
127 /*!
127 /*!
128 \qmlproperty color Legend::font
128 \qmlproperty color Legend::font
129 The font of markers used by legend
129 The font of markers used by legend
130 */
130 */
131
131
132 /*!
132 /*!
133 \property QLegend::labelColor
133 \property QLegend::labelColor
134 The color of brush used to draw labels.
134 The color of brush used to draw labels.
135 */
135 */
136 /*!
136 /*!
137 \qmlproperty color QLegend::labelColor
137 \qmlproperty color QLegend::labelColor
138 The color of brush used to draw labels.
138 The color of brush used to draw labels.
139 */
139 */
140
140
141 /*!
141 /*!
142 \fn void QLegend::backgroundVisibleChanged(bool)
142 \fn void QLegend::backgroundVisibleChanged(bool)
143 The visibility of the legend background changed to \a visible.
143 The visibility of the legend background changed to \a visible.
144 */
144 */
145
145
146 /*!
146 /*!
147 \fn void QLegend::colorChanged(QColor)
147 \fn void QLegend::colorChanged(QColor)
148 The color of the legend background changed to \a color.
148 The color of the legend background changed to \a color.
149 */
149 */
150
150
151 /*!
151 /*!
152 \fn void QLegend::borderColorChanged(QColor)
152 \fn void QLegend::borderColorChanged(QColor)
153 The border color of the legend background changed to \a color.
153 The border color of the legend background changed to \a color.
154 */
154 */
155
155
156 /*!
156 /*!
157 \fn void QLegend::fontChanged(QFont)
157 \fn void QLegend::fontChanged(QFont)
158 The font of markers of the legend changed to \a font.
158 The font of markers of the legend changed to \a font.
159 */
159 */
160
160
161 /*!
161 /*!
162 \fn void QLegend::labelBrushChanged(QBrush brush)
162 \fn void QLegend::labelBrushChanged(QBrush brush)
163 This signal is emitted when the brush used to draw labels has changed to \a brush.
163 This signal is emitted when the brush used to draw labels has changed to \a brush.
164 */
164 */
165
165
166 /*!
166 /*!
167 \fn void QLegend::labelColorChanged(QColor color)
167 \fn void QLegend::labelColorChanged(QColor color)
168 This signal is emitted when the color of brush used to draw labels has changed to \a color.
168 This signal is emitted when the color of brush used to draw labels has changed to \a color.
169 */
169 */
170
170
171 /*!
171 /*!
172 \fn qreal QLegend::minWidth() const
172 \fn qreal QLegend::minWidth() const
173 Returns minimum width of the legend
173 Returns minimum width of the legend
174 */
174 */
175
175
176 /*!
176 /*!
177 \fn qreal QLegend::minHeight() const
177 \fn qreal QLegend::minHeight() const
178 Returns minimum height of the legend
178 Returns minimum height of the legend
179 */
179 */
180
180
181 /*!
181 /*!
182 Constructs the legend object and sets the parent to \a parent
182 Constructs the legend object and sets the parent to \a parent
183 */
183 */
184
184
185 QLegend::QLegend(QChart *chart):QGraphicsWidget(chart),
185 QLegend::QLegend(QChart *chart):QGraphicsWidget(chart),
186 d_ptr(new QLegendPrivate(chart->d_ptr->m_presenter,chart,this))
186 d_ptr(new QLegendPrivate(chart->d_ptr->m_presenter,chart,this))
187 {
187 {
188 setZValue(ChartPresenter::LegendZValue);
188 setZValue(ChartPresenter::LegendZValue);
189 setFlags(QGraphicsItem::ItemClipsChildrenToShape);
189 setFlags(QGraphicsItem::ItemClipsChildrenToShape);
190 QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesAdded(QAbstractSeries*,Domain*)),d_ptr.data(),SLOT(handleSeriesAdded(QAbstractSeries*,Domain*)));
190 QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesAdded(QAbstractSeries*,Domain*)),d_ptr.data(),SLOT(handleSeriesAdded(QAbstractSeries*,Domain*)));
191 QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesRemoved(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesRemoved(QAbstractSeries*)));
191 QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesRemoved(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesRemoved(QAbstractSeries*)));
192 QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesUpdated(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesUpdated(QAbstractSeries*)));
192 QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesUpdated(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesUpdated(QAbstractSeries*)));
193 setLayout(d_ptr->m_layout);
193 setLayout(d_ptr->m_layout);
194 }
194 }
195
195
196 /*!
196 /*!
197 Destroys the legend object. Legend is always owned by a QChart, so an application should never call this.
197 Destroys the legend object. Legend is always owned by a QChart, so an application should never call this.
198 */
198 */
199 QLegend::~QLegend()
199 QLegend::~QLegend()
200 {
200 {
201 }
201 }
202
202
203 /*!
203 /*!
204 \internal
204 \internal
205 */
205 */
206 void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
206 void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
207 {
207 {
208 Q_UNUSED(option)
208 Q_UNUSED(option)
209 Q_UNUSED(widget)
209 Q_UNUSED(widget)
210 if(!d_ptr->m_backgroundVisible) return;
210 if(!d_ptr->m_backgroundVisible) return;
211
211
212 painter->setOpacity(opacity());
212 painter->setOpacity(opacity());
213 painter->setPen(d_ptr->m_pen);
213 painter->setPen(d_ptr->m_pen);
214 painter->setBrush(d_ptr->m_brush);
214 painter->setBrush(d_ptr->m_brush);
215 painter->drawRoundRect(rect(),d_ptr->roundness(rect().width()),d_ptr->roundness(rect().height()));
215 painter->drawRoundRect(rect(),d_ptr->roundness(rect().width()),d_ptr->roundness(rect().height()));
216
216
217 }
217 }
218
218
219
219
220 /*!
220 /*!
221 Sets the \a brush of legend. Brush affects the background of legend.
221 Sets the \a brush of legend. Brush affects the background of legend.
222 */
222 */
223 void QLegend::setBrush(const QBrush &brush)
223 void QLegend::setBrush(const QBrush &brush)
224 {
224 {
225 if (d_ptr->m_brush != brush) {
225 if (d_ptr->m_brush != brush) {
226 d_ptr->m_brush = brush;
226 d_ptr->m_brush = brush;
227 update();
227 update();
228 }
228 }
229 }
229 }
230
230
231 /*!
231 /*!
232 Returns the brush used by legend.
232 Returns the brush used by legend.
233 */
233 */
234 QBrush QLegend::brush() const
234 QBrush QLegend::brush() const
235 {
235 {
236 return d_ptr->m_brush;
236 return d_ptr->m_brush;
237 }
237 }
238
238
239 void QLegend::setColor(QColor color)
239 void QLegend::setColor(QColor color)
240 {
240 {
241 QBrush b = d_ptr->m_brush;
241 QBrush b = d_ptr->m_brush;
242 if (b.style() != Qt::SolidPattern || b.color() != color) {
242 if (b.style() != Qt::SolidPattern || b.color() != color) {
243 b.setStyle(Qt::SolidPattern);
243 b.setStyle(Qt::SolidPattern);
244 b.setColor(color);
244 b.setColor(color);
245 setBrush(b);
245 setBrush(b);
246 emit colorChanged(color);
246 emit colorChanged(color);
247 }
247 }
248 }
248 }
249
249
250 QColor QLegend::color()
250 QColor QLegend::color()
251 {
251 {
252 return d_ptr->m_brush.color();
252 return d_ptr->m_brush.color();
253 }
253 }
254
254
255 /*!
255 /*!
256 Sets the \a pen of legend. Pen affects the legend borders.
256 Sets the \a pen of legend. Pen affects the legend borders.
257 */
257 */
258 void QLegend::setPen(const QPen &pen)
258 void QLegend::setPen(const QPen &pen)
259 {
259 {
260 if (d_ptr->m_pen != pen) {
260 if (d_ptr->m_pen != pen) {
261 d_ptr->m_pen = pen;
261 d_ptr->m_pen = pen;
262 update();
262 update();
263 }
263 }
264 }
264 }
265
265
266 /*!
266 /*!
267 Returns the pen used by legend
267 Returns the pen used by legend
268 */
268 */
269
269
270 QPen QLegend::pen() const
270 QPen QLegend::pen() const
271 {
271 {
272 return d_ptr->m_pen;
272 return d_ptr->m_pen;
273 }
273 }
274
274
275 void QLegend::setFont(const QFont &font)
275 void QLegend::setFont(const QFont &font)
276 {
276 {
277 if (d_ptr->m_font != font) {
277 if (d_ptr->m_font != font) {
278 d_ptr->m_font = font;
278 d_ptr->m_font = font;
279
279
280 foreach (LegendMarker *marker, d_ptr->markers()) {
280 foreach (LegendMarker *marker, d_ptr->markers()) {
281 marker->setFont(d_ptr->m_font);
281 marker->setFont(d_ptr->m_font);
282 }
282 }
283 layout()->invalidate();
283 emit fontChanged(font);
284 emit fontChanged(font);
284 }
285 }
285 }
286 }
286
287
287 QFont QLegend::font() const
288 QFont QLegend::font() const
288 {
289 {
289 return d_ptr->m_font;
290 return d_ptr->m_font;
290 }
291 }
291
292
292 void QLegend::setBorderColor(QColor color)
293 void QLegend::setBorderColor(QColor color)
293 {
294 {
294 QPen p = d_ptr->m_pen;
295 QPen p = d_ptr->m_pen;
295 if (p.color() != color) {
296 if (p.color() != color) {
296 p.setColor(color);
297 p.setColor(color);
297 setPen(p);
298 setPen(p);
298 emit borderColorChanged(color);
299 emit borderColorChanged(color);
299 }
300 }
300 }
301 }
301
302
302 QColor QLegend::borderColor()
303 QColor QLegend::borderColor()
303 {
304 {
304 return d_ptr->m_pen.color();
305 return d_ptr->m_pen.color();
305 }
306 }
306
307
307 /*!
308 /*!
308 Set brush used to draw labels to \a brush.
309 Set brush used to draw labels to \a brush.
309 */
310 */
310 void QLegend::setLabelBrush(const QBrush &brush)
311 void QLegend::setLabelBrush(const QBrush &brush)
311 {
312 {
312 if (d_ptr->m_labelBrush != brush) {
313 if (d_ptr->m_labelBrush != brush) {
313
314
314 d_ptr->m_labelBrush = brush;
315 d_ptr->m_labelBrush = brush;
315
316
316 foreach (LegendMarker *marker, d_ptr->markers()) {
317 foreach (LegendMarker *marker, d_ptr->markers()) {
317 marker->setLabelBrush(d_ptr->m_labelBrush);
318 marker->setLabelBrush(d_ptr->m_labelBrush);
318 }
319 }
319 emit labelBrushChanged(brush);
320 emit labelBrushChanged(brush);
320 }
321 }
321 }
322 }
322
323
323 /*!
324 /*!
324 Brush used to draw labels.
325 Brush used to draw labels.
325 */
326 */
326 QBrush QLegend::labelBrush() const
327 QBrush QLegend::labelBrush() const
327 {
328 {
328 return d_ptr->m_labelBrush;
329 return d_ptr->m_labelBrush;
329 }
330 }
330
331
331 void QLegend::setLabelColor(QColor color)
332 void QLegend::setLabelColor(QColor color)
332 {
333 {
333 QBrush b = d_ptr->m_labelBrush;
334 QBrush b = d_ptr->m_labelBrush;
334 if (b.style() != Qt::SolidPattern || b.color() != color) {
335 if (b.style() != Qt::SolidPattern || b.color() != color) {
335 b.setStyle(Qt::SolidPattern);
336 b.setStyle(Qt::SolidPattern);
336 b.setColor(color);
337 b.setColor(color);
337 setLabelBrush(b);
338 setLabelBrush(b);
338 emit labelColorChanged(color);
339 emit labelColorChanged(color);
339 }
340 }
340 }
341 }
341
342
342 QColor QLegend::labelColor() const
343 QColor QLegend::labelColor() const
343 {
344 {
344 return d_ptr->m_labelBrush.color();
345 return d_ptr->m_labelBrush.color();
345 }
346 }
346
347
347
348
348 void QLegend::setAlignment(Qt::Alignment alignment)
349 void QLegend::setAlignment(Qt::Alignment alignment)
349 {
350 {
350 if(d_ptr->m_alignment!=alignment) {
351 if(d_ptr->m_alignment!=alignment) {
351 d_ptr->m_alignment = alignment;
352 d_ptr->m_alignment = alignment;
352 updateGeometry();
353 updateGeometry();
353 if(isAttachedToChart()){
354 if(isAttachedToChart()){
354 d_ptr->m_presenter->layout()->invalidate();
355 d_ptr->m_presenter->layout()->invalidate();
355 }else{
356 }else{
356 layout()->invalidate();
357 layout()->invalidate();
357 }
358 }
358 }
359 }
359 }
360 }
360
361
361 Qt::Alignment QLegend::alignment() const
362 Qt::Alignment QLegend::alignment() const
362 {
363 {
363 return d_ptr->m_alignment;
364 return d_ptr->m_alignment;
364 }
365 }
365
366
366 /*!
367 /*!
367 Detaches the legend from chart. Chart won't change layout of the legend.
368 Detaches the legend from chart. Chart won't change layout of the legend.
368 */
369 */
369 void QLegend::detachFromChart()
370 void QLegend::detachFromChart()
370 {
371 {
371 d_ptr->m_attachedToChart = false;
372 d_ptr->m_attachedToChart = false;
372 d_ptr->m_layout->invalidate();
373 d_ptr->m_layout->invalidate();
373 setParent(0);
374 setParent(0);
374
375
375 }
376 }
376
377
377 /*!
378 /*!
378 Attaches the legend to chart. Chart may change layout of the legend.
379 Attaches the legend to chart. Chart may change layout of the legend.
379 */
380 */
380 void QLegend::attachToChart()
381 void QLegend::attachToChart()
381 {
382 {
382 d_ptr->m_attachedToChart = true;
383 d_ptr->m_attachedToChart = true;
383 d_ptr->m_layout->invalidate();
384 d_ptr->m_layout->invalidate();
384 setParent(d_ptr->m_chart);
385 setParent(d_ptr->m_chart);
385 }
386 }
386
387
387 /*!
388 /*!
388 Returns true, if legend is attached to chart.
389 Returns true, if legend is attached to chart.
389 */
390 */
390 bool QLegend::isAttachedToChart()
391 bool QLegend::isAttachedToChart()
391 {
392 {
392 return d_ptr->m_attachedToChart;
393 return d_ptr->m_attachedToChart;
393 }
394 }
394
395
395 /*!
396 /*!
396 Sets the visibility of legend background to \a visible
397 Sets the visibility of legend background to \a visible
397 */
398 */
398 void QLegend::setBackgroundVisible(bool visible)
399 void QLegend::setBackgroundVisible(bool visible)
399 {
400 {
400 if(d_ptr->m_backgroundVisible != visible) {
401 if(d_ptr->m_backgroundVisible != visible) {
401 d_ptr->m_backgroundVisible = visible;
402 d_ptr->m_backgroundVisible = visible;
402 update();
403 update();
403 emit backgroundVisibleChanged(visible);
404 emit backgroundVisibleChanged(visible);
404 }
405 }
405 }
406 }
406
407
407 /*!
408 /*!
408 Returns the visibility of legend background
409 Returns the visibility of legend background
409 */
410 */
410 bool QLegend::isBackgroundVisible() const
411 bool QLegend::isBackgroundVisible() const
411 {
412 {
412 return d_ptr->m_backgroundVisible;
413 return d_ptr->m_backgroundVisible;
413 }
414 }
414
415
415 /*!
416 /*!
416 \internal \a event see QGraphicsWidget for details
417 \internal \a event see QGraphicsWidget for details
417 */
418 */
418 void QLegend::hideEvent(QHideEvent *event)
419 void QLegend::hideEvent(QHideEvent *event)
419 {
420 {
420 QGraphicsWidget::hideEvent(event);
421 QGraphicsWidget::hideEvent(event);
421 d_ptr->m_presenter->layout()->invalidate();
422 d_ptr->m_presenter->layout()->invalidate();
422 }
423 }
423
424
424 /*!
425 /*!
425 \internal \a event see QGraphicsWidget for details
426 \internal \a event see QGraphicsWidget for details
426 */
427 */
427 void QLegend::showEvent(QShowEvent *event)
428 void QLegend::showEvent(QShowEvent *event)
428 {
429 {
429 QGraphicsWidget::showEvent(event);
430 QGraphicsWidget::showEvent(event);
430 d_ptr->m_presenter->layout()->invalidate();
431 d_ptr->m_presenter->layout()->invalidate();
431 }
432 }
432
433
433 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
434 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
434
435
435 QLegendPrivate::QLegendPrivate(ChartPresenter* presenter, QChart *chart, QLegend *q):
436 QLegendPrivate::QLegendPrivate(ChartPresenter* presenter, QChart *chart, QLegend *q):
436 q_ptr(q),
437 q_ptr(q),
437 m_presenter(presenter),
438 m_presenter(presenter),
438 m_layout(new LegendLayout(q)),
439 m_layout(new LegendLayout(q)),
439 m_chart(chart),
440 m_chart(chart),
440 m_items(new QGraphicsItemGroup(q)),
441 m_items(new QGraphicsItemGroup(q)),
441 m_alignment(Qt::AlignTop),
442 m_alignment(Qt::AlignTop),
442 m_brush(QBrush()),
443 m_brush(QBrush()),
443 m_pen(QPen()),
444 m_pen(QPen()),
444 m_labelBrush(QBrush()),
445 m_labelBrush(QBrush()),
445 m_diameter(5),
446 m_diameter(5),
446 m_attachedToChart(true),
447 m_attachedToChart(true),
447 m_backgroundVisible(false)
448 m_backgroundVisible(false)
448 {
449 {
449
450
450 }
451 }
451
452
452 QLegendPrivate::~QLegendPrivate()
453 QLegendPrivate::~QLegendPrivate()
453 {
454 {
454
455
455 }
456 }
456
457
457 void QLegendPrivate::setOffset(qreal x, qreal y)
458 void QLegendPrivate::setOffset(qreal x, qreal y)
458 {
459 {
459 m_layout->setOffset(x,y);
460 m_layout->setOffset(x,y);
460 }
461 }
461
462
462 QPointF QLegendPrivate::offset() const
463 QPointF QLegendPrivate::offset() const
463 {
464 {
464 return m_layout->offset();
465 return m_layout->offset();
465 }
466 }
466
467
467 int QLegendPrivate::roundness(qreal size)
468 int QLegendPrivate::roundness(qreal size)
468 {
469 {
469 return 100*m_diameter/int(size);
470 return 100*m_diameter/int(size);
470 }
471 }
471
472
472 void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series, Domain *domain)
473 void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series, Domain *domain)
473 {
474 {
474 Q_UNUSED(domain)
475 Q_UNUSED(domain)
475
476
476 QList<LegendMarker*> markers = series->d_ptr->createLegendMarker(q_ptr);
477 QList<LegendMarker*> markers = series->d_ptr->createLegendMarker(q_ptr);
477
478
478 foreach(LegendMarker* marker, markers) {
479 foreach(LegendMarker* marker, markers) {
479 marker->setFont(m_font);
480 marker->setFont(m_font);
480 marker->setLabelBrush(m_labelBrush);
481 marker->setLabelBrush(m_labelBrush);
481 m_items->addToGroup(marker);
482 m_items->addToGroup(marker);
482 m_markers<<marker;
483 m_markers<<marker;
483 }
484 }
484
485
485 QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
486 QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
486
487
487 if(series->type() == QAbstractSeries::SeriesTypePie) {
488 if(series->type() == QAbstractSeries::SeriesTypePie) {
488 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
489 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
489 QObject::connect(pieSeries, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries()));
490 QObject::connect(pieSeries, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries()));
490 QObject::connect(pieSeries, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries()));
491 QObject::connect(pieSeries, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries()));
491 }
492 }
492
493
493 q_ptr->layout()->invalidate();
494 q_ptr->layout()->invalidate();
494 }
495 }
495
496
496 void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series)
497 void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series)
497 {
498 {
498 foreach (LegendMarker *marker, m_markers) {
499 foreach (LegendMarker *marker, m_markers) {
499 if (marker->series() == series) {
500 if (marker->series() == series) {
500 delete marker;
501 delete marker;
501 m_markers.removeAll(marker);
502 m_markers.removeAll(marker);
502 }
503 }
503 }
504 }
504
505
505 if(series->type() == QAbstractSeries::SeriesTypePie)
506 if(series->type() == QAbstractSeries::SeriesTypePie)
506 {
507 {
507 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
508 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
508 QObject::disconnect(pieSeries, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries()));
509 QObject::disconnect(pieSeries, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries()));
509 QObject::disconnect(pieSeries, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries()));
510 QObject::disconnect(pieSeries, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries()));
510 }
511 }
511
512
512 q_ptr->layout()->invalidate();
513 q_ptr->layout()->invalidate();
513 }
514 }
514
515
515 void QLegendPrivate::handleSeriesUpdated(QAbstractSeries *series)
516 void QLegendPrivate::handleSeriesUpdated(QAbstractSeries *series)
516 {
517 {
517 // TODO: find out which markers are are added or removed. Update them
518 // TODO: find out which markers are are added or removed. Update them
518 // TODO: better implementation
519 // TODO: better implementation
519 handleSeriesRemoved(series);
520 handleSeriesRemoved(series);
520 Domain domain;
521 Domain domain;
521 handleSeriesAdded(series, &domain);
522 handleSeriesAdded(series, &domain);
522 }
523 }
523
524
524 void QLegendPrivate::handleUpdatePieSeries()
525 void QLegendPrivate::handleUpdatePieSeries()
525 {
526 {
526 //TODO: reimplement to be optimal
527 //TODO: reimplement to be optimal
527 QPieSeries* series = qobject_cast<QPieSeries *> (sender());
528 QPieSeries* series = qobject_cast<QPieSeries *> (sender());
528 Q_ASSERT(series);
529 Q_ASSERT(series);
529 handleSeriesRemoved(series);
530 handleSeriesRemoved(series);
530 handleSeriesAdded(series, 0);
531 handleSeriesAdded(series, 0);
531 }
532 }
532
533
533 void QLegendPrivate::handleSeriesVisibleChanged()
534 void QLegendPrivate::handleSeriesVisibleChanged()
534 {
535 {
535 QAbstractSeries* series = qobject_cast<QAbstractSeries *> (sender());
536 QAbstractSeries* series = qobject_cast<QAbstractSeries *> (sender());
536
537
537 foreach (LegendMarker* marker, m_markers) {
538 foreach (LegendMarker* marker, m_markers) {
538 if (marker->series() == series) {
539 if (marker->series() == series) {
539 marker->setVisible(!marker->isVisible());
540 marker->setVisible(!marker->isVisible());
540 }
541 }
541 }
542 }
542
543
543 q_ptr->layout()->invalidate();
544 q_ptr->layout()->invalidate();
544 }
545 }
545
546
546 #include "moc_qlegend.cpp"
547 #include "moc_qlegend.cpp"
547 #include "moc_qlegend_p.cpp"
548 #include "moc_qlegend_p.cpp"
548
549
549 QTCOMMERCIALCHART_END_NAMESPACE
550 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now