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