##// END OF EJS Templates
removing old commented code. removing domain parameter from handleseriesadded of pimpl. adding QLegend parameter to marker construction
sauimone -
r2171:c0bd0c4881b1
parent child
Show More
@@ -1,562 +1,400
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()) return;
122 if (m_legend->d_ptr->legendMarkers().isEmpty()) {
121 if (m_legend->d_ptr->legendMarkers().isEmpty()) {
123 return;
122 return;
124 }
123 }
125
124
126 m_width = 0;
125 m_width = 0;
127 m_height = 0;
126 m_height = 0;
128
127
129 qreal left, top, right, bottom;
128 qreal left, top, right, bottom;
130 getContentsMargins(&left, &top, &right, &bottom);
129 getContentsMargins(&left, &top, &right, &bottom);
131
130
132 QRectF geometry = rect.adjusted(left, top, -right, -bottom);
131 QRectF geometry = rect.adjusted(left, top, -right, -bottom);
133
132
134 switch(m_legend->alignment()) {
133 switch(m_legend->alignment()) {
135 case Qt::AlignTop:
134 case Qt::AlignTop:
136 case Qt::AlignBottom: {
135 case Qt::AlignBottom: {
137 QPointF point(0,0);
136 QPointF point(0,0);
138 /*
139 foreach (LegendMarker* marker, m_legend->d_ptr->markers()) {
140 if (marker->isVisible()) {
141 marker->setGeometry(geometry);
142 marker->setPos(point.x(),geometry.height()/2 - marker->boundingRect().height()/2);
143 const QRectF& rect = marker->boundingRect();
144 size = size.expandedTo(rect.size());
145 qreal w = rect.width();
146 m_width+=w;
147 point.setX(point.x() + w);
148 }
149 }
150 */
151 // New markers -->>
152 foreach (QLegendMarker* marker, m_legend->d_ptr->legendMarkers()) {
137 foreach (QLegendMarker* marker, m_legend->d_ptr->legendMarkers()) {
153 LegendMarkerItem* item = marker->d_ptr->item();
138 LegendMarkerItem* item = marker->d_ptr->item();
154 if (item->isVisible()) {
139 if (item->isVisible()) {
155 // LegendMarkerItem* item = marker->d_ptr.data()->item();
156 item->setGeometry(geometry);
140 item->setGeometry(geometry);
157 item->setPos(point.x(),geometry.height()/2 - item->boundingRect().height()/2);
141 item->setPos(point.x(),geometry.height()/2 - item->boundingRect().height()/2);
158 const QRectF& rect = item->boundingRect();
142 const QRectF& rect = item->boundingRect();
159 size = size.expandedTo(rect.size());
143 size = size.expandedTo(rect.size());
160 qreal w = rect.width();
144 qreal w = rect.width();
161 m_width+=w;
145 m_width+=w;
162 point.setX(point.x() + w);
146 point.setX(point.x() + w);
163 }
147 }
164 }
148 }
165 // <<-- New markers
166 if (m_width < geometry.width())
149 if (m_width < geometry.width())
167 m_legend->d_ptr->items()->setPos(geometry.width() / 2 - m_width / 2, geometry.top());
150 m_legend->d_ptr->items()->setPos(geometry.width() / 2 - m_width / 2, geometry.top());
168 else
151 else
169 m_legend->d_ptr->items()->setPos(geometry.topLeft());
152 m_legend->d_ptr->items()->setPos(geometry.topLeft());
170 m_height = size.height();
153 m_height = size.height();
171 }
154 }
172 break;
155 break;
173 case Qt::AlignLeft:
156 case Qt::AlignLeft:
174 case Qt::AlignRight: {
157 case Qt::AlignRight: {
175 QPointF point(0,0);
158 QPointF point(0,0);
176 /*
177 foreach (LegendMarker* marker, m_legend->d_ptr->markers()) {
178 if (marker->isVisible()) {
179 marker->setGeometry(geometry);
180 marker->setPos(point);
181 const QRectF& rect = marker->boundingRect();
182 qreal h = rect.height();
183 size = size.expandedTo(rect.size());
184 m_height+=h;
185 point.setY(point.y() + h);
186 }
187 }
188 */
189 // New markers -->>
190 foreach (QLegendMarker* marker, m_legend->d_ptr->legendMarkers()) {
159 foreach (QLegendMarker* marker, m_legend->d_ptr->legendMarkers()) {
191 LegendMarkerItem* item = marker->d_ptr->item();
160 LegendMarkerItem* item = marker->d_ptr->item();
192 if (item->isVisible()) {
161 if (item->isVisible()) {
193 // LegendMarkerItem* item = marker->d_ptr->item();
194 item->setGeometry(geometry);
162 item->setGeometry(geometry);
195 item->setPos(point);
163 item->setPos(point);
196 const QRectF& rect = item->boundingRect();
164 const QRectF& rect = item->boundingRect();
197 qreal h = rect.height();
165 qreal h = rect.height();
198 size = size.expandedTo(rect.size());
166 size = size.expandedTo(rect.size());
199 m_height+=h;
167 m_height+=h;
200 point.setY(point.y() + h);
168 point.setY(point.y() + h);
201 }
169 }
202 }
170 }
203 // <<--- New markers
204
171
205 if (m_height < geometry.height())
172 if (m_height < geometry.height())
206 m_legend->d_ptr->items()->setPos(geometry.left(), geometry.height() / 2 - m_height / 2);
173 m_legend->d_ptr->items()->setPos(geometry.left(), geometry.height() / 2 - m_height / 2);
207 else
174 else
208 m_legend->d_ptr->items()->setPos(geometry.topLeft());
175 m_legend->d_ptr->items()->setPos(geometry.topLeft());
209 m_width = size.width();
176 m_width = size.width();
210 break;
177 break;
211 }
178 }
212 }
179 }
213
180
214 m_minOffsetX = -left;
181 m_minOffsetX = -left;
215 m_minOffsetY = - top;
182 m_minOffsetY = - top;
216 m_maxOffsetX = m_width - geometry.width() - right;
183 m_maxOffsetX = m_width - geometry.width() - right;
217 m_maxOffsetY = m_height - geometry.height() - bottom;
184 m_maxOffsetY = m_height - geometry.height() - bottom;
218 }
185 }
219
186
220 void LegendLayout::setDettachedGeometry(const QRectF &rect)
187 void LegendLayout::setDettachedGeometry(const QRectF &rect)
221 {
188 {
222 if (!rect.isValid())
189 if (!rect.isValid())
223 return;
190 return;
224
191
225 // Detached layout is different.
192 // Detached layout is different.
226 // In detached mode legend may have multiple rows and columns, so layout calculations
193 // In detached mode legend may have multiple rows and columns, so layout calculations
227 // differ a log from attached mode.
194 // differ a log from attached mode.
228 // Also the scrolling logic is bit different.
195 // Also the scrolling logic is bit different.
229
196
230 m_offsetX = 0;
197 m_offsetX = 0;
231 m_offsetY = 0;
198 m_offsetY = 0;
232
199
233 qreal left, top, right, bottom;
200 qreal left, top, right, bottom;
234 getContentsMargins(&left, &top, &right, &bottom);
201 getContentsMargins(&left, &top, &right, &bottom);
235 QRectF geometry = rect.adjusted(left, top, -right, -bottom);
202 QRectF geometry = rect.adjusted(left, top, -right, -bottom);
236
203
237 QSizeF size(0, 0);
204 QSizeF size(0, 0);
238
205
239 // QList<LegendMarker *> markers = m_legend->d_ptr->markers();
240 QList<QLegendMarker *> markers = m_legend->d_ptr->legendMarkers();
206 QList<QLegendMarker *> markers = m_legend->d_ptr->legendMarkers();
241
207
242 if (markers.isEmpty())
208 if (markers.isEmpty())
243 return;
209 return;
244
210
245 switch (m_legend->alignment()) {
211 switch (m_legend->alignment()) {
246 case Qt::AlignTop: {
212 case Qt::AlignTop: {
247 QPointF point(0, 0);
213 QPointF point(0, 0);
248 m_width = 0;
214 m_width = 0;
249 m_height = 0;
215 m_height = 0;
250 for (int i = 0; i < markers.count(); i++) {
216 for (int i = 0; i < markers.count(); i++) {
251 /*
252 LegendMarker *marker = markers.at(i);
253 if (marker->isVisible()) {
254 marker->setGeometry(geometry);
255 marker->setPos(point.x(),point.y());
256 const QRectF& boundingRect = marker->boundingRect();
257 qreal w = boundingRect.width();
258 qreal h = boundingRect.height();
259 m_width = qMax(m_width,w);
260 m_height = qMax(m_height,h);
261 point.setX(point.x() + w);
262 if (point.x() + w > geometry.left() + geometry.width() - right) {
263 // Next item would go off rect.
264 point.setX(0);
265 point.setY(point.y() + h);
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();
217 LegendMarkerItem *item = markers.at(i)->d_ptr->item();
274 if (item->isVisible()) {
218 if (item->isVisible()) {
275 // LegendMarkerItem *item = marker->d_ptr->item();
276 item->setGeometry(geometry);
219 item->setGeometry(geometry);
277 item->setPos(point.x(),point.y());
220 item->setPos(point.x(),point.y());
278 const QRectF& boundingRect = item->boundingRect();
221 const QRectF& boundingRect = item->boundingRect();
279 qreal w = boundingRect.width();
222 qreal w = boundingRect.width();
280 qreal h = boundingRect.height();
223 qreal h = boundingRect.height();
281 m_width = qMax(m_width,w);
224 m_width = qMax(m_width,w);
282 m_height = qMax(m_height,h);
225 m_height = qMax(m_height,h);
283 point.setX(point.x() + w);
226 point.setX(point.x() + w);
284 if (point.x() + w > geometry.left() + geometry.width() - right) {
227 if (point.x() + w > geometry.left() + geometry.width() - right) {
285 // Next item would go off rect.
228 // Next item would go off rect.
286 point.setX(0);
229 point.setX(0);
287 point.setY(point.y() + h);
230 point.setY(point.y() + h);
288 if (i+1 < markers.count()) {
231 if (i+1 < markers.count()) {
289 m_height += h;
232 m_height += h;
290 }
233 }
291 }
234 }
292 }
235 }
293 }
236 }
294 m_legend->d_ptr->items()->setPos(geometry.topLeft());
237 m_legend->d_ptr->items()->setPos(geometry.topLeft());
295
238
296 m_minOffsetX = -left;
239 m_minOffsetX = -left;
297 m_minOffsetY = -top;
240 m_minOffsetY = -top;
298 m_maxOffsetX = m_width - geometry.width() - right;
241 m_maxOffsetX = m_width - geometry.width() - right;
299 m_maxOffsetY = m_height - geometry.height() - bottom;
242 m_maxOffsetY = m_height - geometry.height() - bottom;
300 }
243 }
301 break;
244 break;
302 case Qt::AlignBottom: {
245 case Qt::AlignBottom: {
303 QPointF point(0, geometry.height());
246 QPointF point(0, geometry.height());
304 m_width = 0;
247 m_width = 0;
305 m_height = 0;
248 m_height = 0;
306 for (int i = 0; i < markers.count(); i++) {
249 for (int i = 0; i < markers.count(); i++) {
307 /*
308 LegendMarker *marker = markers.at(i);
309 if (marker->isVisible()) {
310 marker->setGeometry(geometry);
311 const QRectF& boundingRect = marker->boundingRect();
312 qreal w = boundingRect.width();
313 qreal h = boundingRect.height();
314 m_width = qMax(m_width,w);
315 m_height = qMax(m_height,h);
316 marker->setPos(point.x(),point.y() - h);
317 point.setX(point.x() + w);
318 if (point.x() + w > geometry.left() + geometry.width() - right) {
319 // Next item would go off rect.
320 point.setX(0);
321 point.setY(point.y() - h);
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();
250 LegendMarkerItem *item = markers.at(i)->d_ptr->item();
330 if (item->isVisible()) {
251 if (item->isVisible()) {
331 item->setGeometry(geometry);
252 item->setGeometry(geometry);
332 const QRectF& boundingRect = item->boundingRect();
253 const QRectF& boundingRect = item->boundingRect();
333 qreal w = boundingRect.width();
254 qreal w = boundingRect.width();
334 qreal h = boundingRect.height();
255 qreal h = boundingRect.height();
335 m_width = qMax(m_width,w);
256 m_width = qMax(m_width,w);
336 m_height = qMax(m_height,h);
257 m_height = qMax(m_height,h);
337 item->setPos(point.x(),point.y() - h);
258 item->setPos(point.x(),point.y() - h);
338 point.setX(point.x() + w);
259 point.setX(point.x() + w);
339 if (point.x() + w > geometry.left() + geometry.width() - right) {
260 if (point.x() + w > geometry.left() + geometry.width() - right) {
340 // Next item would go off rect.
261 // Next item would go off rect.
341 point.setX(0);
262 point.setX(0);
342 point.setY(point.y() - h);
263 point.setY(point.y() - h);
343 if (i+1 < markers.count()) {
264 if (i+1 < markers.count()) {
344 m_height += h;
265 m_height += h;
345 }
266 }
346 }
267 }
347 }
268 }
348 }
269 }
349 m_legend->d_ptr->items()->setPos(geometry.topLeft());
270 m_legend->d_ptr->items()->setPos(geometry.topLeft());
350
271
351 m_minOffsetX = -left;
272 m_minOffsetX = -left;
352 m_minOffsetY = -m_height + geometry.height() - top;
273 m_minOffsetY = -m_height + geometry.height() - top;
353 m_maxOffsetX = m_width - geometry.width() - right;
274 m_maxOffsetX = m_width - geometry.width() - right;
354 m_maxOffsetY = -bottom;
275 m_maxOffsetY = -bottom;
355 }
276 }
356 break;
277 break;
357 case Qt::AlignLeft: {
278 case Qt::AlignLeft: {
358 QPointF point(0, 0);
279 QPointF point(0, 0);
359 m_width = 0;
280 m_width = 0;
360 m_height = 0;
281 m_height = 0;
361 qreal maxWidth = 0;
282 qreal maxWidth = 0;
362 for (int i = 0; i < markers.count(); i++) {
283 for (int i = 0; i < markers.count(); i++) {
363 /*
364 LegendMarker *marker = markers.at(i);
365 if (marker->isVisible()) {
366 marker->setGeometry(geometry);
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();
284 LegendMarkerItem *item = markers.at(i)->d_ptr->item();
387 if (item->isVisible()) {
285 if (item->isVisible()) {
388 // LegendMarkerItem *item = marker->d_ptr->item();
389 item->setGeometry(geometry);
286 item->setGeometry(geometry);
390 const QRectF& boundingRect = item->boundingRect();
287 const QRectF& boundingRect = item->boundingRect();
391 qreal w = boundingRect.width();
288 qreal w = boundingRect.width();
392 qreal h = boundingRect.height();
289 qreal h = boundingRect.height();
393 m_height = qMax(m_height,h);
290 m_height = qMax(m_height,h);
394 maxWidth = qMax(maxWidth,w);
291 maxWidth = qMax(maxWidth,w);
395 item->setPos(point.x(),point.y());
292 item->setPos(point.x(),point.y());
396 point.setY(point.y() + h);
293 point.setY(point.y() + h);
397 if (point.y() + h > geometry.bottom() - bottom) {
294 if (point.y() + h > geometry.bottom() - bottom) {
398 // Next item would go off rect.
295 // Next item would go off rect.
399 point.setX(point.x() + maxWidth);
296 point.setX(point.x() + maxWidth);
400 point.setY(0);
297 point.setY(0);
401 if (i+1 < markers.count()) {
298 if (i+1 < markers.count()) {
402 m_width += maxWidth;
299 m_width += maxWidth;
403 maxWidth = 0;
300 maxWidth = 0;
404 }
301 }
405 }
302 }
406 }
303 }
407 }
304 }
408 m_width += maxWidth;
305 m_width += maxWidth;
409 m_legend->d_ptr->items()->setPos(geometry.topLeft());
306 m_legend->d_ptr->items()->setPos(geometry.topLeft());
410
307
411 m_minOffsetX = -left;
308 m_minOffsetX = -left;
412 m_minOffsetY = -top;
309 m_minOffsetY = -top;
413 m_maxOffsetX = m_width - geometry.width() - right;
310 m_maxOffsetX = m_width - geometry.width() - right;
414 m_maxOffsetY = m_height - geometry.height() - bottom;
311 m_maxOffsetY = m_height - geometry.height() - bottom;
415 }
312 }
416 break;
313 break;
417 case Qt::AlignRight: {
314 case Qt::AlignRight: {
418 QPointF point(geometry.width(), 0);
315 QPointF point(geometry.width(), 0);
419 m_width = 0;
316 m_width = 0;
420 m_height = 0;
317 m_height = 0;
421 qreal maxWidth = 0;
318 qreal maxWidth = 0;
422 for (int i = 0; i < markers.count(); i++) {
319 for (int i = 0; i < markers.count(); i++) {
423 /*
424 LegendMarker *marker = markers.at(i);
425 if (marker->isVisible()) {
426 marker->setGeometry(geometry);
427 const QRectF& boundingRect = marker->boundingRect();
428 qreal w = boundingRect.width();
429 qreal h = boundingRect.height();
430 m_height = qMax(m_height,h);
431 maxWidth = qMax(maxWidth,w);
432 marker->setPos(point.x() - w,point.y());
433 point.setY(point.y() + h);
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();
320 LegendMarkerItem *item = markers.at(i)->d_ptr->item();
447 if (item->isVisible()) {
321 if (item->isVisible()) {
448 // LegendMarkerItem *item = marker->d_ptr->item();
449 item->setGeometry(geometry);
322 item->setGeometry(geometry);
450 const QRectF& boundingRect = item->boundingRect();
323 const QRectF& boundingRect = item->boundingRect();
451 qreal w = boundingRect.width();
324 qreal w = boundingRect.width();
452 qreal h = boundingRect.height();
325 qreal h = boundingRect.height();
453 m_height = qMax(m_height,h);
326 m_height = qMax(m_height,h);
454 maxWidth = qMax(maxWidth,w);
327 maxWidth = qMax(maxWidth,w);
455 item->setPos(point.x() - w,point.y());
328 item->setPos(point.x() - w,point.y());
456 point.setY(point.y() + h);
329 point.setY(point.y() + h);
457 if (point.y() + h > geometry.bottom()-bottom) {
330 if (point.y() + h > geometry.bottom()-bottom) {
458 // Next item would go off rect.
331 // Next item would go off rect.
459 point.setX(point.x() - maxWidth);
332 point.setX(point.x() - maxWidth);
460 point.setY(0);
333 point.setY(0);
461 if (i+1 < markers.count()) {
334 if (i+1 < markers.count()) {
462 m_width += maxWidth;
335 m_width += maxWidth;
463 maxWidth = 0;
336 maxWidth = 0;
464 }
337 }
465 }
338 }
466 }
339 }
467 }
340 }
468 m_width += maxWidth;
341 m_width += maxWidth;
469 m_legend->d_ptr->items()->setPos(geometry.topLeft());
342 m_legend->d_ptr->items()->setPos(geometry.topLeft());
470
343
471 m_minOffsetX = - m_width + geometry.width() - left;
344 m_minOffsetX = - m_width + geometry.width() - left;
472 m_minOffsetY = -top;
345 m_minOffsetY = -top;
473 m_maxOffsetX = - right;
346 m_maxOffsetX = - right;
474 m_maxOffsetY = m_height - geometry.height() - bottom;
347 m_maxOffsetY = m_height - geometry.height() - bottom;
475 }
348 }
476 break;
349 break;
477 default:
350 default:
478 break;
351 break;
479 }
352 }
480
353
481 }
354 }
482
355
483 QSizeF LegendLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
356 QSizeF LegendLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
484 {
357 {
485 /*
486 QSizeF size(0, 0);
487 qreal left, top, right, bottom;
488 getContentsMargins(&left, &top, &right, &bottom);
489
490 if (constraint.isValid()) {
491 foreach (LegendMarker *marker, m_legend->d_ptr->markers())
492 size = size.expandedTo(marker->effectiveSizeHint(which));
493 size = size.boundedTo(constraint);
494 } else if (constraint.width() >= 0) {
495 qreal width = 0;
496 qreal height = 0;
497 foreach (LegendMarker *marker, m_legend->d_ptr->markers()) {
498 width += marker->effectiveSizeHint(which).width();
499 height = qMax(height, marker->effectiveSizeHint(which).height());
500 }
501
502 size = QSizeF(qMin(constraint.width(), width), height);
503 } else if (constraint.height() >= 0) {
504 qreal width = 0;
505 qreal height = 0;
506 foreach (LegendMarker *marker, m_legend->d_ptr->markers()) {
507 width = qMax(width, marker->effectiveSizeHint(which).width());
508 height += height, marker->effectiveSizeHint(which).height();
509 }
510 size = QSizeF(width, qMin(constraint.height(), height));
511 } else {
512 foreach (LegendMarker *marker, m_legend->d_ptr->markers())
513 size = size.expandedTo(marker->effectiveSizeHint(which));
514 }
515 size += QSize(left + right, top + bottom);
516 return size;
517 */
518 // New markers -->>
519 QSizeF size(0, 0);
358 QSizeF size(0, 0);
520 qreal left, top, right, bottom;
359 qreal left, top, right, bottom;
521 getContentsMargins(&left, &top, &right, &bottom);
360 getContentsMargins(&left, &top, &right, &bottom);
522
361
523 if(constraint.isValid()) {
362 if(constraint.isValid()) {
524 foreach(QLegendMarker* marker, m_legend->d_ptr->legendMarkers()) {
363 foreach(QLegendMarker* marker, m_legend->d_ptr->legendMarkers()) {
525 LegendMarkerItem *item = marker->d_ptr->item();
364 LegendMarkerItem *item = marker->d_ptr->item();
526 size = size.expandedTo(item->effectiveSizeHint(which));
365 size = size.expandedTo(item->effectiveSizeHint(which));
527 }
366 }
528 size = size.boundedTo(constraint);
367 size = size.boundedTo(constraint);
529 }
368 }
530 else if (constraint.width() >= 0) {
369 else if (constraint.width() >= 0) {
531 qreal width = 0;
370 qreal width = 0;
532 qreal height = 0;
371 qreal height = 0;
533 foreach(QLegendMarker* marker, m_legend->d_ptr->legendMarkers()) {
372 foreach(QLegendMarker* marker, m_legend->d_ptr->legendMarkers()) {
534 LegendMarkerItem *item = marker->d_ptr->item();
373 LegendMarkerItem *item = marker->d_ptr->item();
535 width+=item->effectiveSizeHint(which).width();
374 width+=item->effectiveSizeHint(which).width();
536 height=qMax(height,item->effectiveSizeHint(which).height());
375 height=qMax(height,item->effectiveSizeHint(which).height());
537 }
376 }
538
377
539 size = QSizeF(qMin(constraint.width(),width), height);
378 size = QSizeF(qMin(constraint.width(),width), height);
540 }
379 }
541 else if (constraint.height() >= 0) {
380 else if (constraint.height() >= 0) {
542 qreal width = 0;
381 qreal width = 0;
543 qreal height = 0;
382 qreal height = 0;
544 foreach(QLegendMarker* marker, m_legend->d_ptr->legendMarkers()) {
383 foreach(QLegendMarker* marker, m_legend->d_ptr->legendMarkers()) {
545 LegendMarkerItem *item = marker->d_ptr->item();
384 LegendMarkerItem *item = marker->d_ptr->item();
546 width=qMax(width,item->effectiveSizeHint(which).width());
385 width=qMax(width,item->effectiveSizeHint(which).width());
547 height+=height,item->effectiveSizeHint(which).height();
386 height+=height,item->effectiveSizeHint(which).height();
548 }
387 }
549 size = QSizeF(width,qMin(constraint.height(),height));
388 size = QSizeF(width,qMin(constraint.height(),height));
550 }
389 }
551 else {
390 else {
552 foreach(QLegendMarker* marker, m_legend->d_ptr->legendMarkers()) {
391 foreach(QLegendMarker* marker, m_legend->d_ptr->legendMarkers()) {
553 LegendMarkerItem *item = marker->d_ptr->item();
392 LegendMarkerItem *item = marker->d_ptr->item();
554 size = size.expandedTo(item->effectiveSizeHint(which));
393 size = size.expandedTo(item->effectiveSizeHint(which));
555 }
394 }
556 }
395 }
557 size += QSize(left + right, top + bottom);
396 size += QSize(left + right, top + bottom);
558 return size;
397 return size;
559 // <<-- New markers
560 }
398 }
561
399
562 QTCOMMERCIALCHART_END_NAMESPACE
400 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,596 +1,564
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 // Only allow one instance of series
479 if (!m_series.contains(series)) {
480 if (!m_series.contains(series)) {
480 m_series.append(series);
481 m_series.append(series);
481 handleSeriesAdded(series,0);
482 handleSeriesAdded(series/*,0*/);
482 }
483 }
483 }
484 }
484
485
485 void QLegendPrivate::removeSeries(QAbstractSeries* series)
486 void QLegendPrivate::removeSeries(QAbstractSeries* series)
486 {
487 {
487 if (m_series.contains(series)) {
488 if (m_series.contains(series)) {
488 m_series.removeOne(series);
489 m_series.removeOne(series);
489 handleSeriesRemoved(series);
490 handleSeriesRemoved(series);
490 }
491 }
491 }
492 }
492
493
493 void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series, Domain *domain)
494 void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series/*, Domain *domain*/)
494 {
495 {
495 Q_UNUSED(domain)
496 // Q_UNUSED(domain)
496
497
497 qDebug() << "QLegendPrivate::handleSeriesAdded";
498 qDebug() << "QLegendPrivate::handleSeriesAdded" << series;
498
499
499 // New markers --->
500 QList<QLegendMarker*> newMarkers = series->d_ptr->createLegendMarkers(q_ptr);
500 QList<QLegendMarker*> newMarkers = series->d_ptr->createLegendMarkers(q_ptr);
501 foreach (QLegendMarker* marker, newMarkers) {
501 foreach (QLegendMarker* marker, newMarkers) {
502 marker->setFont(m_font);
502 marker->setFont(m_font);
503 marker->setLabelBrush(m_labelBrush);
503 marker->setLabelBrush(m_labelBrush);
504 marker->setVisible(series->isVisible());
504 marker->setVisible(series->isVisible());
505 m_items->addToGroup(marker->d_ptr.data()->item());
505 m_items->addToGroup(marker->d_ptr.data()->item());
506 m_legendMarkers << marker;
506 m_legendMarkers << marker;
507 }
507 }
508
508
509 QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
509 QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
510 // <--- New markers
510 // QObject::connect(series->d_ptr.data(), SIGNAL(legendPropertiesUpdated(QAbstractSeries*)), this, SLOT(handleLegendPropertiesUpdated(QAbstractSeries*)));
511
512 /*
513 QList<LegendMarker*> markers = series->d_ptr->createLegendMarker(q_ptr);
514
515 foreach (LegendMarker *marker, markers) {
516 marker->setFont(m_font);
517 marker->setLabelBrush(m_labelBrush);
518 marker->setVisible(series->isVisible());
519 m_items->addToGroup(marker);
520 m_markers << marker;
521 }
522 */
523
524 QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
525 QObject::connect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged()));
526
511
527 m_items->setVisible(false);
512 m_items->setVisible(false);
528 m_layout->invalidate();
513 m_layout->invalidate();
529 }
514 }
530
515
531 void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series)
516 void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series)
532 {
517 {
533 // New markers --->
518 qDebug() << "QLegendPrivate::handleSeriesRemoved" << series;
519
534 foreach (QLegendMarker *marker, m_legendMarkers) {
520 foreach (QLegendMarker *marker, m_legendMarkers) {
535 if (marker->series() == series) {
521 if (marker->series() == series) {
536 marker->d_ptr.data()->item()->setVisible(false);
522 marker->d_ptr.data()->item()->setVisible(false);
537 m_items->removeFromGroup(marker->d_ptr.data()->item());
523 m_items->removeFromGroup(marker->d_ptr.data()->item());
538 delete marker;
524 delete marker;
539 m_legendMarkers.removeAll(marker);
525 m_legendMarkers.removeAll(marker);
540 }
526 }
541 }
527 }
542
528
543 QObject::disconnect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
529 QObject::disconnect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
544 // <--- New markers
530 // QObject::disconnect(series->d_ptr.data(), SIGNAL(legendPropertiesUpdated(QAbstractSeries*)), this, SLOT(handleLegendPropertiesUpdated(QAbstractSeries*)));
545
531
546 /*
547 foreach (LegendMarker *marker, m_markers) {
548 if (marker->series() == series) {
549 delete marker;
550 m_markers.removeAll(marker);
551 }
552 }
553 */
554 QObject::disconnect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
555 QObject::disconnect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged()));
556 m_layout->invalidate();
532 m_layout->invalidate();
557 }
533 }
558
534
559 void QLegendPrivate::handleSeriesVisibleChanged()
535 void QLegendPrivate::handleSeriesVisibleChanged()
560 {
536 {
561 QAbstractSeries *series = qobject_cast<QAbstractSeries *> (sender());
537 QAbstractSeries *series = qobject_cast<QAbstractSeries *> (sender());
562 Q_ASSERT(series);
538 Q_ASSERT(series);
563
539
564 // New markers --->
565 foreach (QLegendMarker* marker, m_legendMarkers) {
540 foreach (QLegendMarker* marker, m_legendMarkers) {
566 if (marker->series() == series) {
541 if (marker->series() == series) {
567 marker->setVisible(series->isVisible());
542 marker->setVisible(series->isVisible());
568 }
543 }
569 }
544 }
570
571 // <--- New markers
572 /*
573 foreach (LegendMarker* marker, m_markers) {
574 if (marker->series() == series) {
575 marker->setVisible(series->isVisible());
576 }
577 */
578 m_layout->invalidate();
545 m_layout->invalidate();
579 }
546 }
580
547
581 void QLegendPrivate::handleCountChanged()
548 void QLegendPrivate::handleCountChanged()
582 {
549 {
583 // With new markers, the series shoud notify markers directly?
550 // TODO: With new markers, the series should notify markers directly.
584 qDebug() << "handleLegendPropertiesUpdated";
551 // TODO: This is not a good way to handle updates.
552 qDebug() << "handleLegendPropertiesUpdated" << series;
585
553
586 // Handle new or removed markers
554 // Handle new or removed markers
587 // Handle changes of marker pen/brush/label. every property that legend is interested
555 // Handle changes of marker pen/brush/label. every property that legend is interested
588 handleSeriesRemoved(series);
556 handleSeriesRemoved(series);
589 Domain domain;
557 // Domain domain;
590 handleSeriesAdded(series, &domain);
558 handleSeriesAdded(series/*, &domain*/);
591 }
559 }
592
560
593 #include "moc_qlegend.cpp"
561 #include "moc_qlegend.cpp"
594 #include "moc_qlegend_p.cpp"
562 #include "moc_qlegend_p.cpp"
595
563
596 QTCOMMERCIALCHART_END_NAMESPACE
564 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,96 +1,96
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 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef QLEGEND_P_H
30 #ifndef QLEGEND_P_H
31 #define QLEGEND_P_H
31 #define QLEGEND_P_H
32
32
33 #include "qlegend.h"
33 #include "qlegend.h"
34
34
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36
36
37 class QChart;
37 class QChart;
38 class ChartPresenter;
38 class ChartPresenter;
39 class QAbstractSeries;
39 class QAbstractSeries;
40 class LegendLayout;
40 class LegendLayout;
41 class LegendMarker;
41 class LegendMarker;
42 class Domain;
42 class Domain;
43 class QLegendMarker;
43 class QLegendMarker;
44
44
45 class QLegendPrivate : public QObject
45 class QLegendPrivate : public QObject
46 {
46 {
47 Q_OBJECT
47 Q_OBJECT
48 public:
48 public:
49 QLegendPrivate(ChartPresenter *presenter, QChart *chart, QLegend *q);
49 QLegendPrivate(ChartPresenter *presenter, QChart *chart, QLegend *q);
50 ~QLegendPrivate();
50 ~QLegendPrivate();
51
51
52 void setOffset(qreal x, qreal y);
52 void setOffset(qreal x, qreal y);
53 QPointF offset() const;
53 QPointF offset() const;
54 int roundness(qreal size);
54 int roundness(qreal size);
55
55
56 QList<LegendMarker*> markers() { return m_markers; } // TODO: this will be removed
56 QList<LegendMarker*> markers() { return m_markers; } // TODO: this will be removed
57 QGraphicsItemGroup* items() { return m_items; }
57 QGraphicsItemGroup* items() { return m_items; }
58
58
59 // New stuff:
59 // New stuff:
60 QList<QLegendMarker*> legendMarkers() { return m_legendMarkers; } // TODO: function name will change
60 QList<QLegendMarker*> legendMarkers() { return m_legendMarkers; } // TODO: function name will change
61 void appendSeries(QAbstractSeries* series);
61 void appendSeries(QAbstractSeries* series);
62 void removeSeries(QAbstractSeries* series);
62 void removeSeries(QAbstractSeries* series);
63
63
64 public Q_SLOTS:
64 public Q_SLOTS:
65 void handleSeriesAdded(QAbstractSeries *series, Domain *domain);
65 void handleSeriesAdded(QAbstractSeries *series/*, Domain *domain*/);
66 void handleSeriesRemoved(QAbstractSeries *series);
66 void handleSeriesRemoved(QAbstractSeries *series);
67 void handleSeriesVisibleChanged();
67 void handleSeriesVisibleChanged();
68 void handleCountChanged();
68 void handleCountChanged();
69
69
70 private:
70 private:
71 QLegend *q_ptr;
71 QLegend *q_ptr;
72 ChartPresenter *m_presenter;
72 ChartPresenter *m_presenter;
73 LegendLayout *m_layout;
73 LegendLayout *m_layout;
74 QChart* m_chart;
74 QChart* m_chart;
75 QGraphicsItemGroup* m_items;
75 QGraphicsItemGroup* m_items;
76 QList<LegendMarker*> m_markers; // TODO: this will be removed
76 QList<LegendMarker*> m_markers; // TODO: this will be removed
77 Qt::Alignment m_alignment;
77 Qt::Alignment m_alignment;
78 QBrush m_brush;
78 QBrush m_brush;
79 QPen m_pen;
79 QPen m_pen;
80 QFont m_font;
80 QFont m_font;
81 QBrush m_labelBrush;
81 QBrush m_labelBrush;
82
82
83 qreal m_diameter;
83 qreal m_diameter;
84 bool m_attachedToChart;
84 bool m_attachedToChart;
85 bool m_backgroundVisible;
85 bool m_backgroundVisible;
86
86
87 friend class QLegend;
87 friend class QLegend;
88 friend class LegendLayout;
88 friend class LegendLayout;
89 QList<QLegendMarker*> m_legendMarkers; // TODO: rename to m_markers eventually.
89 QList<QLegendMarker*> m_legendMarkers; // TODO: rename to m_markers eventually.
90 QList<QAbstractSeries*> m_series;
90 QList<QAbstractSeries*> m_series;
91
91
92 };
92 };
93
93
94 QTCOMMERCIALCHART_END_NAMESPACE
94 QTCOMMERCIALCHART_END_NAMESPACE
95
95
96 #endif
96 #endif
@@ -1,193 +1,194
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 "qlegend.h"
24 #include <QDebug>
25 #include <QDebug>
25 #include <QFontMetrics>
26 #include <QFontMetrics>
26 #include <QGraphicsSceneEvent>
27 #include <QGraphicsSceneEvent>
27
28
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 /*
30 /*
30 QLegendMarker::QLegendMarker(QAbstractSeries* series, QObject *parent) :
31 QLegendMarker::QLegendMarker(QAbstractSeries* series, QObject *parent) :
31 QObject(parent),
32 QObject(parent),
32 d_ptr(new QLegendMarkerPrivate(series, this))
33 d_ptr(new QLegendMarkerPrivate(series, this))
33 {
34 {
34 }
35 }
35 */
36 */
36 QLegendMarker::QLegendMarker(QLegendMarkerPrivate &d, QObject *parent) :
37 QLegendMarker::QLegendMarker(QLegendMarkerPrivate &d, QObject *parent) :
37 QObject(parent),
38 QObject(parent),
38 d_ptr(&d)
39 d_ptr(&d)
39 {
40 {
40 }
41 }
41
42
42 QLegendMarker::~QLegendMarker()
43 QLegendMarker::~QLegendMarker()
43 {
44 {
44 }
45 }
45
46
46 QString QLegendMarker::label() const
47 QString QLegendMarker::label() const
47 {
48 {
48 return d_ptr->label();
49 return d_ptr->label();
49 }
50 }
50
51
51 void QLegendMarker::setLabel(const QString &label)
52 void QLegendMarker::setLabel(const QString &label)
52 {
53 {
53 d_ptr->setLabel(label);
54 d_ptr->setLabel(label);
54 }
55 }
55
56
56 QBrush QLegendMarker::labelBrush() const
57 QBrush QLegendMarker::labelBrush() const
57 {
58 {
58 return d_ptr->labelBrush();
59 return d_ptr->labelBrush();
59 }
60 }
60
61
61 void QLegendMarker::setLabelBrush(const QBrush &brush)
62 void QLegendMarker::setLabelBrush(const QBrush &brush)
62 {
63 {
63 d_ptr->setLabelBrush(brush);
64 d_ptr->setLabelBrush(brush);
64 }
65 }
65
66
66 QFont QLegendMarker::font() const
67 QFont QLegendMarker::font() const
67 {
68 {
68 return d_ptr->font();
69 return d_ptr->font();
69 }
70 }
70
71
71 void QLegendMarker::setFont(const QFont &font)
72 void QLegendMarker::setFont(const QFont &font)
72 {
73 {
73 d_ptr->setFont(font);
74 d_ptr->setFont(font);
74 }
75 }
75
76
76 QPen QLegendMarker::pen() const
77 QPen QLegendMarker::pen() const
77 {
78 {
78 return d_ptr->pen();
79 return d_ptr->pen();
79 }
80 }
80
81
81 void QLegendMarker::setPen(const QPen &pen)
82 void QLegendMarker::setPen(const QPen &pen)
82 {
83 {
83 d_ptr->setPen(pen);
84 d_ptr->setPen(pen);
84 }
85 }
85
86
86 QBrush QLegendMarker::brush() const
87 QBrush QLegendMarker::brush() const
87 {
88 {
88 return d_ptr->brush();
89 return d_ptr->brush();
89 }
90 }
90
91
91 void QLegendMarker::setBrush(const QBrush &brush)
92 void QLegendMarker::setBrush(const QBrush &brush)
92 {
93 {
93 d_ptr->setBrush(brush);
94 d_ptr->setBrush(brush);
94 }
95 }
95
96
96 bool QLegendMarker::isVisible() const
97 bool QLegendMarker::isVisible() const
97 {
98 {
98 return d_ptr->isVisible();
99 return d_ptr->isVisible();
99 }
100 }
100
101
101 void QLegendMarker::setVisible(bool visible)
102 void QLegendMarker::setVisible(bool visible)
102 {
103 {
103 d_ptr->setVisible(visible);
104 d_ptr->setVisible(visible);
104 }
105 }
105
106
106 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
107 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
107 QLegendMarkerPrivate::QLegendMarkerPrivate(QLegendMarker *q) :
108 QLegendMarkerPrivate::QLegendMarkerPrivate(QLegendMarker *q, QLegend *legend) :
108 q_ptr(q)
109 q_ptr(q),
110 m_legend(legend)
109 {
111 {
110 // qDebug() << "QLegendMarkerPrivate created";
112 // qDebug() << "QLegendMarkerPrivate created";
111 m_item = new LegendMarkerItem(this);
113 m_item = new LegendMarkerItem(this);
112 }
114 }
113
115
114 QLegendMarkerPrivate::~QLegendMarkerPrivate()
116 QLegendMarkerPrivate::~QLegendMarkerPrivate()
115 {
117 {
116 // delete m_item;
117 }
118 }
118
119
119 void QLegendMarkerPrivate::handleMousePressEvent(QGraphicsSceneEvent *event)
120 void QLegendMarkerPrivate::handleMousePressEvent(QGraphicsSceneEvent *event)
120 {
121 {
121 // Just emit clicked signal for now (our default logic for events)
122 // Just emit clicked signal for now (our default logic for events)
122 // This could propably be on the LegendMarkerItem?
123 // This could propably be on the LegendMarkerItem?
123 // TODO: how to handle scrolling vs clicking? drag event?
124 // TODO: how to handle scrolling vs clicking? drag event?
124 event->accept();
125 event->accept();
125 Q_Q(QLegendMarker);
126 Q_Q(QLegendMarker);
126 emit q->clicked();
127 emit q->clicked();
127 }
128 }
128
129
129 void QLegendMarkerPrivate::setPen(const QPen &pen)
130 void QLegendMarkerPrivate::setPen(const QPen &pen)
130 {
131 {
131 m_item->setPen(pen);
132 m_item->setPen(pen);
132 }
133 }
133
134
134 QPen QLegendMarkerPrivate::pen() const
135 QPen QLegendMarkerPrivate::pen() const
135 {
136 {
136 return m_item->pen();
137 return m_item->pen();
137 }
138 }
138
139
139 void QLegendMarkerPrivate::setBrush(const QBrush &brush)
140 void QLegendMarkerPrivate::setBrush(const QBrush &brush)
140 {
141 {
141 m_item->setBrush(brush);
142 m_item->setBrush(brush);
142 }
143 }
143
144
144 QBrush QLegendMarkerPrivate::brush() const
145 QBrush QLegendMarkerPrivate::brush() const
145 {
146 {
146 return m_item->brush();
147 return m_item->brush();
147 }
148 }
148
149
149 void QLegendMarkerPrivate::setFont(const QFont &font)
150 void QLegendMarkerPrivate::setFont(const QFont &font)
150 {
151 {
151 m_item->setFont(font);
152 m_item->setFont(font);
152 }
153 }
153
154
154 QFont QLegendMarkerPrivate::font() const
155 QFont QLegendMarkerPrivate::font() const
155 {
156 {
156 return m_item->font();
157 return m_item->font();
157 }
158 }
158
159
159 void QLegendMarkerPrivate::setLabel(const QString label)
160 void QLegendMarkerPrivate::setLabel(const QString label)
160 {
161 {
161 m_item->setLabel(label);
162 m_item->setLabel(label);
162 }
163 }
163
164
164 QString QLegendMarkerPrivate::label() const
165 QString QLegendMarkerPrivate::label() const
165 {
166 {
166 return m_item->label();
167 return m_item->label();
167 }
168 }
168
169
169 void QLegendMarkerPrivate::setLabelBrush(const QBrush &brush)
170 void QLegendMarkerPrivate::setLabelBrush(const QBrush &brush)
170 {
171 {
171 m_item->setLabelBrush(brush);
172 m_item->setLabelBrush(brush);
172 }
173 }
173
174
174 QBrush QLegendMarkerPrivate::labelBrush() const
175 QBrush QLegendMarkerPrivate::labelBrush() const
175 {
176 {
176 return m_item->labelBrush();
177 return m_item->labelBrush();
177 }
178 }
178
179
179 bool QLegendMarkerPrivate::isVisible() const
180 bool QLegendMarkerPrivate::isVisible() const
180 {
181 {
181 return m_item->isVisible();
182 return m_item->isVisible();
182 }
183 }
183
184
184 void QLegendMarkerPrivate::setVisible(bool visible)
185 void QLegendMarkerPrivate::setVisible(bool visible)
185 {
186 {
186 m_item->setVisible(visible);
187 m_item->setVisible(visible);
187 }
188 }
188
189
189
190
190 #include "moc_qlegendmarker.cpp"
191 #include "moc_qlegendmarker.cpp"
191 #include "moc_qlegendmarker_p.cpp"
192 #include "moc_qlegendmarker_p.cpp"
192
193
193 QTCOMMERCIALCHART_END_NAMESPACE
194 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 #ifndef QLEGENDMARKER_H
21 #ifndef QLEGENDMARKER_H
22 #define QLEGENDMARKER_H
22 #define QLEGENDMARKER_H
23
23
24 #include <QChartGlobal>
24 #include <QChartGlobal>
25 #include <QObject>
25 #include <QObject>
26 #include <QPen>
26 #include <QPen>
27 #include <QBrush>
27 #include <QBrush>
28 #include <QFont>
28 #include <QFont>
29
29
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31
31
32 class QLegendMarkerPrivate;
32 class QLegendMarkerPrivate;
33 class QAbstractSeries;
33 class QAbstractSeries;
34 class QLegend;
34
35
35 // TODO: should this be QAbstractLegendMarker?
36 // TODO: should this be QAbstractLegendMarker?
36 class QTCOMMERCIALCHART_EXPORT QLegendMarker : public QObject
37 class QTCOMMERCIALCHART_EXPORT QLegendMarker : public QObject
37 {
38 {
38 Q_OBJECT
39 Q_OBJECT
39
40
40 // TODO: need for these?
41 // TODO: need for these?
41 // Q_PROPERTY(QString label READ label WRITE setlabel NOTIFY labelChanged);
42 // Q_PROPERTY(QString label READ label WRITE setlabel NOTIFY labelChanged);
42 // Q_PROPERTY(QPen pen READ pen WRITE setPen NOTIFY penChanged);
43 // Q_PROPERTY(QPen pen READ pen WRITE setPen NOTIFY penChanged);
43 // Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged);
44 // Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged);
44
45
45 public:
46 public:
46 // explicit QLegendMarker(QAbstractSeries* series, QObject *parent = 0);
47 // explicit QLegendMarker(QAbstractSeries* series, QObject *parent = 0);
47 virtual ~QLegendMarker();
48 virtual ~QLegendMarker();
48
49
49 QString label() const;
50 QString label() const;
50 void setLabel(const QString &label);
51 void setLabel(const QString &label);
51
52
52 QBrush labelBrush() const;
53 QBrush labelBrush() const;
53 void setLabelBrush(const QBrush &brush);
54 void setLabelBrush(const QBrush &brush);
54
55
55 QFont font() const;
56 QFont font() const;
56 void setFont(const QFont &font);
57 void setFont(const QFont &font);
57
58
58 QPen pen() const;
59 QPen pen() const;
59 void setPen(const QPen &pen);
60 void setPen(const QPen &pen);
60
61
61 QBrush brush() const;
62 QBrush brush() const;
62 void setBrush(const QBrush &brush);
63 void setBrush(const QBrush &brush);
63
64
64 bool isVisible() const;
65 bool isVisible() const;
65 void setVisible(bool visible);
66 void setVisible(bool visible);
66
67
67 // virtual QAbstractSeries::SeriesType type() = 0; // TODO?
68 // virtual QAbstractSeries::SeriesType type() = 0; // TODO?
68 virtual QAbstractSeries* series() = 0;
69 virtual QAbstractSeries* series() = 0;
69 virtual QObject* peerObject() = 0;
70 virtual QObject* peerObject() = 0;
70
71
71 protected:
72 protected:
72 explicit QLegendMarker(QLegendMarkerPrivate &d, QObject *parent = 0);
73 explicit QLegendMarker(QLegendMarkerPrivate &d, QObject *parent = 0);
73
74
74 Q_SIGNALS:
75 Q_SIGNALS:
75 void clicked();
76 void clicked();
76 void hovered(bool status);
77 void hovered(bool status);
77
78
78 protected:
79 protected:
79 QScopedPointer<QLegendMarkerPrivate> d_ptr;
80 QScopedPointer<QLegendMarkerPrivate> d_ptr;
80 Q_DISABLE_COPY(QLegendMarker)
81 Q_DISABLE_COPY(QLegendMarker)
81 friend class QLegendPrivate;
82 friend class QLegendPrivate;
82 friend class QLegendMarkerPrivate;
83 friend class QLegendMarkerPrivate;
83 friend class LegendLayout;
84 friend class LegendLayout;
84 };
85 };
85
86
86 QTCOMMERCIALCHART_END_NAMESPACE
87 QTCOMMERCIALCHART_END_NAMESPACE
87
88
88 #endif // QLEGENDMARKER_H
89 #endif // QLEGENDMARKER_H
@@ -1,115 +1,115
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 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef QLEGENDMARKERPRIVATE_H
30 #ifndef QLEGENDMARKERPRIVATE_H
31 #define QLEGENDMARKERPRIVATE_H
31 #define QLEGENDMARKERPRIVATE_H
32
32
33 #include "qchartglobal.h"
33 #include "qchartglobal.h"
34 #include <QGraphicsObject>
34 #include <QGraphicsObject>
35 #include <QBrush>
35 #include <QBrush>
36 #include <QPen>
36 #include <QPen>
37 #include <QGraphicsSimpleTextItem>
37 #include <QGraphicsSimpleTextItem>
38 #include <QGraphicsLayoutItem>
38 #include <QGraphicsLayoutItem>
39 #include <QDebug>
39 #include <QDebug>
40
40
41 QTCOMMERCIALCHART_BEGIN_NAMESPACE
41 QTCOMMERCIALCHART_BEGIN_NAMESPACE
42
42
43 // TODO: check these
43 // TODO: check these
44 class QAbstractSeries;
44 class QAbstractSeries;
45 class QAreaSeries;
45 class QAreaSeries;
46 class QXYSeries;
46 class QXYSeries;
47 class QBarSet;
47 class QBarSet;
48 class QAbstractBarSeries;
48 class QAbstractBarSeries;
49 class QPieSlice;
49 class QPieSlice;
50 class QLegend;
50 class QLegend;
51 class QPieSeries;
51 class QPieSeries;
52
52
53 class QLegendMarker;
53 class QLegendMarker;
54 class LegendMarkerItem;
54 class LegendMarkerItem;
55
55
56 class QLegendMarkerPrivate : public QObject
56 class QLegendMarkerPrivate : public QObject
57 {
57 {
58 Q_OBJECT
58 Q_OBJECT
59 public:
59 public:
60 // explicit QLegendMarkerPrivate(QAbstractSeries *series, QLegendMarker *q);
60 // explicit QLegendMarkerPrivate(QAbstractSeries *series, QLegendMarker *q);
61 explicit QLegendMarkerPrivate(QLegendMarker *q);
61 explicit QLegendMarkerPrivate(QLegendMarker *q, QLegend *legend);
62 virtual ~QLegendMarkerPrivate();
62 virtual ~QLegendMarkerPrivate();
63
63
64 // TODO: remove temporary setters/getters and use the m_item directly from public class via d_ptr
64 void setPen(const QPen &pen);
65 void setPen(const QPen &pen);
65 QPen pen() const;
66 QPen pen() const;
66
67
67 void setBrush(const QBrush &brush);
68 void setBrush(const QBrush &brush);
68 QBrush brush() const;
69 QBrush brush() const;
69
70
70 void setFont(const QFont &font);
71 void setFont(const QFont &font);
71 QFont font() const;
72 QFont font() const;
72
73
73 void setLabel(const QString label);
74 void setLabel(const QString label);
74 QString label() const;
75 QString label() const;
75
76
76 void setLabelBrush(const QBrush &brush);
77 void setLabelBrush(const QBrush &brush);
77 QBrush labelBrush() const;
78 QBrush labelBrush() const;
78
79
79 bool isVisible() const;
80 bool isVisible() const;
80 void setVisible(bool visible);
81 void setVisible(bool visible);
81
82
82 // Helper for now.
83 // Helper for now.
83 LegendMarkerItem* item() const { return m_item; }
84 LegendMarkerItem* item() const { return m_item; }
84
85
85 // Item gets the event, logic for event is here
86 // Item gets the event, logic for event is here
86 void handleMousePressEvent(QGraphicsSceneEvent *event);
87 void handleMousePressEvent(QGraphicsSceneEvent *event);
87
88
88 public Q_SLOTS:
89 public Q_SLOTS:
89 virtual void updated() {};
90 virtual void updated() {};
90
91
91 protected:
92 protected:
92 LegendMarkerItem *m_item;
93 LegendMarkerItem *m_item;
94 QLegend* m_legend;
93
95
94 private:
96 private:
95 QLegendMarker *q_ptr;
97 QLegendMarker *q_ptr;
96 /*
97 QLegend* m_legend;
98 */
99
98
100 // New legend marker properties
99 // New legend marker properties
100 // Moved to item.
101 /*
101 /*
102 QString m_label;
102 QString m_label;
103 QBrush m_labelBrush;
103 QBrush m_labelBrush;
104 QFont m_font;
104 QFont m_font;
105 QPen m_pen;
105 QPen m_pen;
106 QBrush m_brush;
106 QBrush m_brush;
107 bool m_visible;
107 bool m_visible;
108 */
108 */
109 friend class QLegendPrivate; // TODO: Is this needed?
109 friend class QLegendPrivate; // TODO: Is this needed?
110 Q_DECLARE_PUBLIC(QLegendMarker)
110 Q_DECLARE_PUBLIC(QLegendMarker)
111 };
111 };
112
112
113 QTCOMMERCIALCHART_END_NAMESPACE
113 QTCOMMERCIALCHART_END_NAMESPACE
114
114
115 #endif // QLEGENDMARKERPRIVATE_H
115 #endif // QLEGENDMARKERPRIVATE_H
@@ -1,89 +1,90
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, QLegend *legend, QObject *parent) :
29 QLegendMarker(*new QPieLegendMarkerPrivate(series,slice,this), parent)
29 QLegendMarker(*new QPieLegendMarkerPrivate(this,series,slice,legend), parent)
30 {
30 {
31 }
31 }
32
32
33 QPieLegendMarker::~QPieLegendMarker()
33 QPieLegendMarker::~QPieLegendMarker()
34 {
34 {
35 qDebug() << "deleting pie marker" << this;
35 qDebug() << "deleting pie marker" << this;
36 }
36 }
37
37
38 /*!
38 /*!
39 \internal
39 \internal
40 */
40 */
41 QPieLegendMarker::QPieLegendMarker(QPieLegendMarkerPrivate &d, QObject *parent) :
41 QPieLegendMarker::QPieLegendMarker(QPieLegendMarkerPrivate &d, QObject *parent) :
42 QLegendMarker(d, parent)
42 QLegendMarker(d, parent)
43 {
43 {
44 }
44 }
45
45
46 QAbstractSeries* QPieLegendMarker::series()
46 QAbstractSeries* QPieLegendMarker::series()
47 {
47 {
48 Q_D(QPieLegendMarker);
48 Q_D(QPieLegendMarker);
49 return d->m_series;
49 return d->m_series;
50 }
50 }
51
51
52 QPieSlice* QPieLegendMarker::peerObject()
52 QPieSlice* QPieLegendMarker::peerObject()
53 {
53 {
54 Q_D(QPieLegendMarker);
54 Q_D(QPieLegendMarker);
55 return d->m_slice;
55 return d->m_slice;
56 }
56 }
57
57
58 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
58 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
59
59
60 QPieLegendMarkerPrivate::QPieLegendMarkerPrivate(QPieSeries *series, QPieSlice *slice, QPieLegendMarker *q) :
60 QPieLegendMarkerPrivate::QPieLegendMarkerPrivate(QPieLegendMarker *q, QPieSeries *series, QPieSlice *slice, QLegend *legend) :
61 QLegendMarkerPrivate(q),
61 QLegendMarkerPrivate(q,legend),
62 m_series(series),
62 m_series(series),
63 m_slice(slice)
63 m_slice(slice)
64 // m_legend(legend)
64 {
65 {
65 // qDebug() << "QPieLegendMarkerPrivate created";
66 // qDebug() << "QPieLegendMarkerPrivate created";
66 QObject::connect(m_slice, SIGNAL(labelChanged()), this, SLOT(updated()));
67 QObject::connect(m_slice, SIGNAL(labelChanged()), this, SLOT(updated()));
67 QObject::connect(m_slice, SIGNAL(brushChanged()), this, SLOT(updated()));
68 QObject::connect(m_slice, SIGNAL(brushChanged()), this, SLOT(updated()));
68 updated();
69 updated();
69 }
70 }
70
71
71 QPieLegendMarkerPrivate::~QPieLegendMarkerPrivate()
72 QPieLegendMarkerPrivate::~QPieLegendMarkerPrivate()
72 {
73 {
73 QObject::disconnect(m_slice, SIGNAL(labelChanged()), this, SLOT(updated()));
74 QObject::disconnect(m_slice, SIGNAL(labelChanged()), this, SLOT(updated()));
74 QObject::disconnect(m_slice, SIGNAL(brushChanged()), this, SLOT(updated()));
75 QObject::disconnect(m_slice, SIGNAL(brushChanged()), this, SLOT(updated()));
75 }
76 }
76
77
77 void QPieLegendMarkerPrivate::updated()
78 void QPieLegendMarkerPrivate::updated()
78 {
79 {
79 // qDebug() << "QPieLegendMarkerPrivate::updated";
80 // qDebug() << "QPieLegendMarkerPrivate::updated";
80 m_item->setBrush(m_slice->brush());
81 m_item->setBrush(m_slice->brush());
81 m_item->setLabel(m_slice->label());
82 m_item->setLabel(m_slice->label());
82 m_item->setPen(m_slice->pen());
83 m_item->setPen(m_slice->pen());
83 m_item->setBrush(m_slice->brush());
84 m_item->setBrush(m_slice->brush());
84 }
85 }
85
86
86 #include "moc_qpielegendmarker.cpp"
87 #include "moc_qpielegendmarker.cpp"
87 #include "moc_qpielegendmarker_p.cpp"
88 #include "moc_qpielegendmarker_p.cpp"
88
89
89 QTCOMMERCIALCHART_END_NAMESPACE
90 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,56 +1,56
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 #ifndef QPIELEGENDMARKER_H
21 #ifndef QPIELEGENDMARKER_H
22 #define QPIELEGENDMARKER_H
22 #define QPIELEGENDMARKER_H
23
23
24 #include <QChartGlobal>
24 #include <QChartGlobal>
25 #include <QLegendMarker>
25 #include <QLegendMarker>
26 #include <QPieSlice>
26 #include <QPieSlice>
27 #include "qpielegendmarker_p.h"
27 #include "qpielegendmarker_p.h"
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
30
31 class QTCOMMERCIALCHART_EXPORT QPieLegendMarker : public QLegendMarker
31 class QTCOMMERCIALCHART_EXPORT QPieLegendMarker : public QLegendMarker
32 {
32 {
33 Q_OBJECT
33 Q_OBJECT
34
34
35 public:
35 public:
36 explicit QPieLegendMarker(QPieSeries* series, QPieSlice* slice, QObject *parent = 0);
36 explicit QPieLegendMarker(QPieSeries* series, QPieSlice* slice, QLegend *legend, QObject *parent = 0);
37 virtual ~QPieLegendMarker();
37 virtual ~QPieLegendMarker();
38
38
39 virtual QAbstractSeries* series();
39 virtual QAbstractSeries* series();
40 virtual QPieSlice* peerObject();
40 virtual QPieSlice* peerObject();
41
41
42 protected:
42 protected:
43 QPieLegendMarker(QPieLegendMarkerPrivate &d, QObject *parent = 0);
43 QPieLegendMarker(QPieLegendMarkerPrivate &d, QObject *parent = 0);
44
44
45 //Q_SIGNALS:
45 //Q_SIGNALS:
46
46
47 //public Q_SLOTS:
47 //public Q_SLOTS:
48
48
49 private:
49 private:
50 Q_DECLARE_PRIVATE(QPieLegendMarker)
50 Q_DECLARE_PRIVATE(QPieLegendMarker)
51 Q_DISABLE_COPY(QPieLegendMarker)
51 Q_DISABLE_COPY(QPieLegendMarker)
52
52
53 };
53 };
54
54
55 QTCOMMERCIALCHART_END_NAMESPACE
55 QTCOMMERCIALCHART_END_NAMESPACE
56 #endif // QPIELEGENDMARKER_H
56 #endif // QPIELEGENDMARKER_H
@@ -1,68 +1,68
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 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef QPIELEGENDMARKER_P_H
30 #ifndef QPIELEGENDMARKER_P_H
31 #define QPIELEGENDMARKER_P_H
31 #define QPIELEGENDMARKER_P_H
32
32
33 #include "qchartglobal.h"
33 #include "qchartglobal.h"
34 #include "qlegendmarker_p.h"
34 #include "qlegendmarker_p.h"
35 #include "legendmarkeritem_p.h"
35 #include "legendmarkeritem_p.h"
36 #include <QPieSeries>
36 #include <QPieSeries>
37 #include <QPieSlice>
37 #include <QPieSlice>
38
38
39 #include <QDebug>
39 #include <QDebug>
40
40
41 QTCOMMERCIALCHART_BEGIN_NAMESPACE
41 QTCOMMERCIALCHART_BEGIN_NAMESPACE
42
42
43 class QPieLegendMarker;
43 class QPieLegendMarker;
44
44
45 class QPieLegendMarkerPrivate : public QLegendMarkerPrivate
45 class QPieLegendMarkerPrivate : public QLegendMarkerPrivate
46 {
46 {
47 Q_OBJECT
47 Q_OBJECT
48 public:
48 public:
49 // explicit QPieLegendMarkerPrivate(QAbstractSeries *series, QPieLegendMarker *q);
49 // explicit QPieLegendMarkerPrivate(QAbstractSeries *series, QPieLegendMarker *q);
50 explicit QPieLegendMarkerPrivate(QPieSeries *series, QPieSlice *slice, QPieLegendMarker *q);
50 explicit QPieLegendMarkerPrivate(QPieLegendMarker *q, QPieSeries *series, QPieSlice *slice, QLegend *legend);
51 virtual ~QPieLegendMarkerPrivate();
51 virtual ~QPieLegendMarkerPrivate();
52
52
53 public Q_SLOTS:
53 public Q_SLOTS:
54 virtual void updated();
54 virtual void updated();
55
55
56 private:
56 private:
57 QPieLegendMarker *q_ptr;
57 QPieLegendMarker *q_ptr;
58
58
59 QPieSeries* m_series;
59 QPieSeries* m_series;
60 QPieSlice* m_slice;
60 QPieSlice* m_slice;
61
61
62 friend class QLegendPrivate; // TODO: Is this needed?
62 friend class QLegendPrivate; // TODO: Is this needed?
63 Q_DECLARE_PUBLIC(QPieLegendMarker)
63 Q_DECLARE_PUBLIC(QPieLegendMarker)
64 };
64 };
65
65
66 QTCOMMERCIALCHART_END_NAMESPACE
66 QTCOMMERCIALCHART_END_NAMESPACE
67
67
68 #endif // QPIELEGENDMARKER_P_H
68 #endif // QPIELEGENDMARKER_P_H
General Comments 0
You need to be logged in to leave comments. Login now