##// END OF EJS Templates
commenting out usage of old marker implementation from legend. Legend now uses new markers.
sauimone -
r2170:3d497e4d0047
parent child
Show More
@@ -118,8 +118,10 void LegendLayout::setAttachedGeometry(const QRectF &rect)
118 118
119 119 QSizeF size(0, 0);
120 120
121 if (m_legend->d_ptr->markers().isEmpty())
121 // if( m_legend->d_ptr->markers().isEmpty()) return;
122 if (m_legend->d_ptr->legendMarkers().isEmpty()) {
122 123 return;
124 }
123 125
124 126 m_width = 0;
125 127 m_height = 0;
@@ -148,8 +150,9 void LegendLayout::setAttachedGeometry(const QRectF &rect)
148 150 */
149 151 // New markers -->>
150 152 foreach (QLegendMarker* marker, m_legend->d_ptr->legendMarkers()) {
151 if (marker->isVisible()) {
152 LegendMarkerItem* item = marker->d_ptr.data()->item();
153 LegendMarkerItem* item = marker->d_ptr->item();
154 if (item->isVisible()) {
155 // LegendMarkerItem* item = marker->d_ptr.data()->item();
153 156 item->setGeometry(geometry);
154 157 item->setPos(point.x(),geometry.height()/2 - item->boundingRect().height()/2);
155 158 const QRectF& rect = item->boundingRect();
@@ -185,8 +188,9 void LegendLayout::setAttachedGeometry(const QRectF &rect)
185 188 */
186 189 // New markers -->>
187 190 foreach (QLegendMarker* marker, m_legend->d_ptr->legendMarkers()) {
188 if (marker->isVisible()) {
189 LegendMarkerItem* item = marker->d_ptr.data()->item();
191 LegendMarkerItem* item = marker->d_ptr->item();
192 if (item->isVisible()) {
193 // LegendMarkerItem* item = marker->d_ptr->item();
190 194 item->setGeometry(geometry);
191 195 item->setPos(point);
192 196 const QRectF& rect = item->boundingRect();
@@ -232,7 +236,8 void LegendLayout::setDettachedGeometry(const QRectF &rect)
232 236
233 237 QSizeF size(0, 0);
234 238
235 QList<LegendMarker *> markers = m_legend->d_ptr->markers();
239 // QList<LegendMarker *> markers = m_legend->d_ptr->markers();
240 QList<QLegendMarker *> markers = m_legend->d_ptr->legendMarkers();
236 241
237 242 if (markers.isEmpty())
238 243 return;
@@ -243,6 +248,7 void LegendLayout::setDettachedGeometry(const QRectF &rect)
243 248 m_width = 0;
244 249 m_height = 0;
245 250 for (int i = 0; i < markers.count(); i++) {
251 /*
246 252 LegendMarker *marker = markers.at(i);
247 253 if (marker->isVisible()) {
248 254 marker->setGeometry(geometry);
@@ -262,6 +268,28 void LegendLayout::setDettachedGeometry(const QRectF &rect)
262 268 }
263 269 }
264 270 }
271 */
272 // QLegendMarker *marker = markers.at(i);
273 LegendMarkerItem *item = markers.at(i)->d_ptr->item();
274 if (item->isVisible()) {
275 // LegendMarkerItem *item = marker->d_ptr->item();
276 item->setGeometry(geometry);
277 item->setPos(point.x(),point.y());
278 const QRectF& boundingRect = item->boundingRect();
279 qreal w = boundingRect.width();
280 qreal h = boundingRect.height();
281 m_width = qMax(m_width,w);
282 m_height = qMax(m_height,h);
283 point.setX(point.x() + w);
284 if (point.x() + w > geometry.left() + geometry.width() - right) {
285 // Next item would go off rect.
286 point.setX(0);
287 point.setY(point.y() + h);
288 if (i+1 < markers.count()) {
289 m_height += h;
290 }
291 }
292 }
265 293 }
266 294 m_legend->d_ptr->items()->setPos(geometry.topLeft());
267 295
@@ -276,6 +304,7 void LegendLayout::setDettachedGeometry(const QRectF &rect)
276 304 m_width = 0;
277 305 m_height = 0;
278 306 for (int i = 0; i < markers.count(); i++) {
307 /*
279 308 LegendMarker *marker = markers.at(i);
280 309 if (marker->isVisible()) {
281 310 marker->setGeometry(geometry);
@@ -295,6 +324,27 void LegendLayout::setDettachedGeometry(const QRectF &rect)
295 324 }
296 325 }
297 326 }
327 */
328 // QLegendMarker *marker = markers.at(i);
329 LegendMarkerItem *item = markers.at(i)->d_ptr->item();
330 if (item->isVisible()) {
331 item->setGeometry(geometry);
332 const QRectF& boundingRect = item->boundingRect();
333 qreal w = boundingRect.width();
334 qreal h = boundingRect.height();
335 m_width = qMax(m_width,w);
336 m_height = qMax(m_height,h);
337 item->setPos(point.x(),point.y() - h);
338 point.setX(point.x() + w);
339 if (point.x() + w > geometry.left() + geometry.width() - right) {
340 // Next item would go off rect.
341 point.setX(0);
342 point.setY(point.y() - h);
343 if (i+1 < markers.count()) {
344 m_height += h;
345 }
346 }
347 }
298 348 }
299 349 m_legend->d_ptr->items()->setPos(geometry.topLeft());
300 350
@@ -310,6 +360,7 void LegendLayout::setDettachedGeometry(const QRectF &rect)
310 360 m_height = 0;
311 361 qreal maxWidth = 0;
312 362 for (int i = 0; i < markers.count(); i++) {
363 /*
313 364 LegendMarker *marker = markers.at(i);
314 365 if (marker->isVisible()) {
315 366 marker->setGeometry(geometry);
@@ -330,6 +381,29 void LegendLayout::setDettachedGeometry(const QRectF &rect)
330 381 }
331 382 }
332 383 }
384 */
385 // QLegendMarker *marker = markers.at(i);
386 LegendMarkerItem *item = markers.at(i)->d_ptr->item();
387 if (item->isVisible()) {
388 // LegendMarkerItem *item = marker->d_ptr->item();
389 item->setGeometry(geometry);
390 const QRectF& boundingRect = item->boundingRect();
391 qreal w = boundingRect.width();
392 qreal h = boundingRect.height();
393 m_height = qMax(m_height,h);
394 maxWidth = qMax(maxWidth,w);
395 item->setPos(point.x(),point.y());
396 point.setY(point.y() + h);
397 if (point.y() + h > geometry.bottom() - bottom) {
398 // Next item would go off rect.
399 point.setX(point.x() + maxWidth);
400 point.setY(0);
401 if (i+1 < markers.count()) {
402 m_width += maxWidth;
403 maxWidth = 0;
404 }
405 }
406 }
333 407 }
334 408 m_width += maxWidth;
335 409 m_legend->d_ptr->items()->setPos(geometry.topLeft());
@@ -346,6 +420,7 void LegendLayout::setDettachedGeometry(const QRectF &rect)
346 420 m_height = 0;
347 421 qreal maxWidth = 0;
348 422 for (int i = 0; i < markers.count(); i++) {
423 /*
349 424 LegendMarker *marker = markers.at(i);
350 425 if (marker->isVisible()) {
351 426 marker->setGeometry(geometry);
@@ -366,6 +441,29 void LegendLayout::setDettachedGeometry(const QRectF &rect)
366 441 }
367 442 }
368 443 }
444 */
445 // QLegendMarker *marker = markers.at(i);
446 LegendMarkerItem *item = markers.at(i)->d_ptr->item();
447 if (item->isVisible()) {
448 // LegendMarkerItem *item = marker->d_ptr->item();
449 item->setGeometry(geometry);
450 const QRectF& boundingRect = item->boundingRect();
451 qreal w = boundingRect.width();
452 qreal h = boundingRect.height();
453 m_height = qMax(m_height,h);
454 maxWidth = qMax(maxWidth,w);
455 item->setPos(point.x() - w,point.y());
456 point.setY(point.y() + h);
457 if (point.y() + h > geometry.bottom()-bottom) {
458 // Next item would go off rect.
459 point.setX(point.x() - maxWidth);
460 point.setY(0);
461 if (i+1 < markers.count()) {
462 m_width += maxWidth;
463 maxWidth = 0;
464 }
465 }
466 }
369 467 }
370 468 m_width += maxWidth;
371 469 m_legend->d_ptr->items()->setPos(geometry.topLeft());
@@ -424,7 +522,7 QSizeF LegendLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) cons
424 522
425 523 if(constraint.isValid()) {
426 524 foreach(QLegendMarker* marker, m_legend->d_ptr->legendMarkers()) {
427 LegendMarkerItem *item = marker->d_ptr.data()->item();
525 LegendMarkerItem *item = marker->d_ptr->item();
428 526 size = size.expandedTo(item->effectiveSizeHint(which));
429 527 }
430 528 size = size.boundedTo(constraint);
@@ -433,7 +531,7 QSizeF LegendLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) cons
433 531 qreal width = 0;
434 532 qreal height = 0;
435 533 foreach(QLegendMarker* marker, m_legend->d_ptr->legendMarkers()) {
436 LegendMarkerItem *item = marker->d_ptr.data()->item();
534 LegendMarkerItem *item = marker->d_ptr->item();
437 535 width+=item->effectiveSizeHint(which).width();
438 536 height=qMax(height,item->effectiveSizeHint(which).height());
439 537 }
@@ -444,7 +542,7 QSizeF LegendLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) cons
444 542 qreal width = 0;
445 543 qreal height = 0;
446 544 foreach(QLegendMarker* marker, m_legend->d_ptr->legendMarkers()) {
447 LegendMarkerItem *item = marker->d_ptr.data()->item();
545 LegendMarkerItem *item = marker->d_ptr->item();
448 546 width=qMax(width,item->effectiveSizeHint(which).width());
449 547 height+=height,item->effectiveSizeHint(which).height();
450 548 }
@@ -452,7 +550,7 QSizeF LegendLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) cons
452 550 }
453 551 else {
454 552 foreach(QLegendMarker* marker, m_legend->d_ptr->legendMarkers()) {
455 LegendMarkerItem *item = marker->d_ptr.data()->item();
553 LegendMarkerItem *item = marker->d_ptr->item();
456 554 size = size.expandedTo(item->effectiveSizeHint(which));
457 555 }
458 556 }
@@ -33,17 +33,13 LegendMarkerItem::LegendMarkerItem(QLegendMarkerPrivate *marker, QGraphicsObject
33 33 QGraphicsObject(parent),
34 34 m_marker(marker),
35 35 m_markerRect(0,0,10.0,10.0),
36 m_boundingRect(0,0,10,10),
36 m_boundingRect(0,0,0,0),
37 37 m_textItem(new QGraphicsSimpleTextItem(this)),
38 38 m_rectItem(new QGraphicsRectItem(this)),
39 39 m_margin(4),
40 40 m_space(4)
41 41 {
42 // qDebug() << "LegendMarkerItem created for marker:" << m_marker;
43 // setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton);
44 42 m_rectItem->setRect(m_markerRect);
45 // setZValue(zValue() + 20);
46 // qDebug() << "z:" << this->zValue();
47 43 }
48 44
49 45 void LegendMarkerItem::setPen(const QPen &pen)
@@ -81,7 +77,6 QFont LegendMarkerItem::font() const
81 77
82 78 void LegendMarkerItem::setLabel(const QString label)
83 79 {
84 qDebug() << "LegendMarkerItem::setlabel" << label;
85 80 m_text = label;
86 81 updateGeometry();
87 82 }
@@ -476,26 +476,18 int QLegendPrivate::roundness(qreal size)
476 476
477 477 void QLegendPrivate::appendSeries(QAbstractSeries* series)
478 478 {
479 Q_UNUSED(series);
480 // TODO:
481 /*
482 479 if (!m_series.contains(series)) {
483 480 m_series.append(series);
484 handleSeriesAdded(series,0); // Dummy domain
481 handleSeriesAdded(series,0);
485 482 }
486 */
487 483 }
488 484
489 485 void QLegendPrivate::removeSeries(QAbstractSeries* series)
490 486 {
491 Q_UNUSED(series);
492 // TODO:
493 /*
494 487 if (m_series.contains(series)) {
495 488 m_series.removeOne(series);
496 489 handleSeriesRemoved(series);
497 490 }
498 */
499 491 }
500 492
501 493 void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series, Domain *domain)
@@ -517,6 +509,7 void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series, Domain *domain)
517 509 QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
518 510 // <--- New markers
519 511
512 /*
520 513 QList<LegendMarker*> markers = series->d_ptr->createLegendMarker(q_ptr);
521 514
522 515 foreach (LegendMarker *marker, markers) {
@@ -526,6 +519,7 void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series, Domain *domain)
526 519 m_items->addToGroup(marker);
527 520 m_markers << marker;
528 521 }
522 */
529 523
530 524 QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
531 525 QObject::connect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged()));
@@ -539,6 +533,8 void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series)
539 533 // New markers --->
540 534 foreach (QLegendMarker *marker, m_legendMarkers) {
541 535 if (marker->series() == series) {
536 marker->d_ptr.data()->item()->setVisible(false);
537 m_items->removeFromGroup(marker->d_ptr.data()->item());
542 538 delete marker;
543 539 m_legendMarkers.removeAll(marker);
544 540 }
@@ -547,13 +543,14 void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series)
547 543 QObject::disconnect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
548 544 // <--- New markers
549 545
546 /*
550 547 foreach (LegendMarker *marker, m_markers) {
551 548 if (marker->series() == series) {
552 549 delete marker;
553 550 m_markers.removeAll(marker);
554 551 }
555 552 }
556
553 */
557 554 QObject::disconnect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged()));
558 555 QObject::disconnect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged()));
559 556 m_layout->invalidate();
@@ -572,17 +569,19 void QLegendPrivate::handleSeriesVisibleChanged()
572 569 }
573 570
574 571 // <--- New markers
575
572 /*
576 573 foreach (LegendMarker* marker, m_markers) {
577 574 if (marker->series() == series) {
578 575 marker->setVisible(series->isVisible());
579 576 }
577 */
580 578 m_layout->invalidate();
581 579 }
582 580
583 581 void QLegendPrivate::handleCountChanged()
584 582 {
585 583 // With new markers, the series shoud notify markers directly?
584 qDebug() << "handleLegendPropertiesUpdated";
586 585
587 586 // Handle new or removed markers
588 587 // Handle changes of marker pen/brush/label. every property that legend is interested
@@ -113,6 +113,7 QLegendMarkerPrivate::QLegendMarkerPrivate(QLegendMarker *q) :
113 113
114 114 QLegendMarkerPrivate::~QLegendMarkerPrivate()
115 115 {
116 // delete m_item;
116 117 }
117 118
118 119 void QLegendMarkerPrivate::handleMousePressEvent(QGraphicsSceneEvent *event)
@@ -32,6 +32,7 QPieLegendMarker::QPieLegendMarker(QPieSeries* series, QPieSlice* slice, QObject
32 32
33 33 QPieLegendMarker::~QPieLegendMarker()
34 34 {
35 qDebug() << "deleting pie marker" << this;
35 36 }
36 37
37 38 /*!
@@ -61,7 +62,7 QPieLegendMarkerPrivate::QPieLegendMarkerPrivate(QPieSeries *series, QPieSlice *
61 62 m_series(series),
62 63 m_slice(slice)
63 64 {
64 qDebug() << "QPieLegendMarkerPrivate created";
65 // qDebug() << "QPieLegendMarkerPrivate created";
65 66 QObject::connect(m_slice, SIGNAL(labelChanged()), this, SLOT(updated()));
66 67 QObject::connect(m_slice, SIGNAL(brushChanged()), this, SLOT(updated()));
67 68 updated();
@@ -75,7 +76,7 QPieLegendMarkerPrivate::~QPieLegendMarkerPrivate()
75 76
76 77 void QPieLegendMarkerPrivate::updated()
77 78 {
78 qDebug() << "QPieLegendMarkerPrivate::updated";
79 // qDebug() << "QPieLegendMarkerPrivate::updated";
79 80 m_item->setBrush(m_slice->brush());
80 81 m_item->setLabel(m_slice->label());
81 82 m_item->setPen(m_slice->pen());
General Comments 0
You need to be logged in to leave comments. Login now