@@ -20,7 +20,7 | |||||
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 | |||
@@ -118,7 +118,6 void LegendLayout::setAttachedGeometry(const QRectF &rect) | |||||
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 | } | |
@@ -135,24 +134,9 void LegendLayout::setAttachedGeometry(const QRectF &rect) | |||||
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(); | |
@@ -162,7 +146,6 void LegendLayout::setAttachedGeometry(const QRectF &rect) | |||||
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 | |
@@ -173,24 +156,9 void LegendLayout::setAttachedGeometry(const QRectF &rect) | |||||
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(); | |
@@ -200,7 +168,6 void LegendLayout::setAttachedGeometry(const QRectF &rect) | |||||
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); | |
@@ -236,7 +203,6 void LegendLayout::setDettachedGeometry(const QRectF &rect) | |||||
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()) | |
@@ -248,31 +214,8 void LegendLayout::setDettachedGeometry(const QRectF &rect) | |||||
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(); | |
@@ -304,28 +247,6 void LegendLayout::setDettachedGeometry(const QRectF &rect) | |||||
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); | |
@@ -346,12 +267,12 void LegendLayout::setDettachedGeometry(const QRectF &rect) | |||||
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: { | |
@@ -360,32 +281,8 void LegendLayout::setDettachedGeometry(const QRectF &rect) | |||||
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(); | |
@@ -405,13 +302,13 void LegendLayout::setDettachedGeometry(const QRectF &rect) | |||||
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: { | |
@@ -420,32 +317,8 void LegendLayout::setDettachedGeometry(const QRectF &rect) | |||||
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(); | |
@@ -465,13 +338,13 void LegendLayout::setDettachedGeometry(const QRectF &rect) | |||||
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: | |
@@ -482,40 +355,6 void LegendLayout::setDettachedGeometry(const QRectF &rect) | |||||
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); | |
@@ -556,7 +395,6 QSizeF LegendLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) cons | |||||
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 |
@@ -176,7 +176,7 QLegend::QLegend(QChart *chart): QGraphicsWidget(chart), | |||||
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); | |
@@ -476,9 +476,10 int QLegendPrivate::roundness(qreal size) | |||||
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 | |||
@@ -490,13 +491,12 void QLegendPrivate::removeSeries(QAbstractSeries* 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); | |
@@ -507,22 +507,7 void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series, Domain *domain) | |||||
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(); | |
@@ -530,7 +515,8 void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series, Domain *domain) | |||||
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); | |
@@ -541,18 +527,8 void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series) | |||||
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 | |||
@@ -561,33 +537,25 void QLegendPrivate::handleSeriesVisibleChanged() | |||||
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" |
@@ -62,7 +62,7 public: | |||||
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(); |
@@ -21,6 +21,7 | |||||
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> | |
@@ -104,8 +105,9 void QLegendMarker::setVisible(bool 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); | |
@@ -113,7 +115,6 QLegendMarkerPrivate::QLegendMarkerPrivate(QLegendMarker *q) : | |||||
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) |
@@ -31,6 +31,7 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 |
@@ -58,9 +58,10 class QLegendMarkerPrivate : public QObject | |||||
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 | |||
@@ -90,14 +91,13 public Q_SLOTS: | |||||
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; |
@@ -25,8 +25,8 | |||||
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, |
|
29 | QLegendMarker(*new QPieLegendMarkerPrivate(this,series,slice,legend), parent) | |
30 | { |
|
30 | { | |
31 | } |
|
31 | } | |
32 |
|
32 | |||
@@ -57,10 +57,11 QPieSlice* QPieLegendMarker::peerObject() | |||||
57 |
|
57 | |||
58 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
58 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
59 |
|
59 | |||
60 |
QPieLegendMarkerPrivate::QPieLegendMarkerPrivate(QPieSeries *series, QPieSlice *slice, 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())); |
@@ -33,7 +33,7 class QTCOMMERCIALCHART_EXPORT QPieLegendMarker : public QLegendMarker | |||||
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(); |
@@ -47,7 +47,7 class QPieLegendMarkerPrivate : public QLegendMarkerPrivate | |||||
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, 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: |
General Comments 0
You need to be logged in to leave comments.
Login now