From 3d497e4d0047483e6c135677bb6f59d57f600a37 2012-10-17 07:46:18 From: sauimone Date: 2012-10-17 07:46:18 Subject: [PATCH] commenting out usage of old marker implementation from legend. Legend now uses new markers. --- diff --git a/src/legend/legendlayout.cpp b/src/legend/legendlayout.cpp index 4319c64..53c9654 100644 --- a/src/legend/legendlayout.cpp +++ b/src/legend/legendlayout.cpp @@ -118,8 +118,10 @@ void LegendLayout::setAttachedGeometry(const QRectF &rect) QSizeF size(0, 0); - if (m_legend->d_ptr->markers().isEmpty()) +// if( m_legend->d_ptr->markers().isEmpty()) return; + if (m_legend->d_ptr->legendMarkers().isEmpty()) { return; + } m_width = 0; m_height = 0; @@ -148,8 +150,9 @@ void LegendLayout::setAttachedGeometry(const QRectF &rect) */ // New markers -->> foreach (QLegendMarker* marker, m_legend->d_ptr->legendMarkers()) { - if (marker->isVisible()) { - LegendMarkerItem* item = marker->d_ptr.data()->item(); + LegendMarkerItem* item = marker->d_ptr->item(); + if (item->isVisible()) { +// LegendMarkerItem* item = marker->d_ptr.data()->item(); item->setGeometry(geometry); item->setPos(point.x(),geometry.height()/2 - item->boundingRect().height()/2); const QRectF& rect = item->boundingRect(); @@ -185,8 +188,9 @@ void LegendLayout::setAttachedGeometry(const QRectF &rect) */ // New markers -->> foreach (QLegendMarker* marker, m_legend->d_ptr->legendMarkers()) { - if (marker->isVisible()) { - LegendMarkerItem* item = marker->d_ptr.data()->item(); + LegendMarkerItem* item = marker->d_ptr->item(); + if (item->isVisible()) { +// LegendMarkerItem* item = marker->d_ptr->item(); item->setGeometry(geometry); item->setPos(point); const QRectF& rect = item->boundingRect(); @@ -232,7 +236,8 @@ void LegendLayout::setDettachedGeometry(const QRectF &rect) QSizeF size(0, 0); - QList markers = m_legend->d_ptr->markers(); +// QList markers = m_legend->d_ptr->markers(); + QList markers = m_legend->d_ptr->legendMarkers(); if (markers.isEmpty()) return; @@ -243,21 +248,44 @@ void LegendLayout::setDettachedGeometry(const QRectF &rect) m_width = 0; m_height = 0; for (int i = 0; i < markers.count(); i++) { + /* LegendMarker *marker = markers.at(i); if (marker->isVisible()) { marker->setGeometry(geometry); - marker->setPos(point.x(), point.y()); - const QRectF &boundingRect = marker->boundingRect(); + marker->setPos(point.x(),point.y()); + const QRectF& boundingRect = marker->boundingRect(); qreal w = boundingRect.width(); qreal h = boundingRect.height(); - m_width = qMax(m_width, w); - m_height = qMax(m_height, h); + m_width = qMax(m_width,w); + m_height = qMax(m_height,h); point.setX(point.x() + w); if (point.x() + w > geometry.left() + geometry.width() - right) { // Next item would go off rect. point.setX(0); point.setY(point.y() + h); - if (i + 1 < markers.count()) { + if (i+1 < markers.count()) { + m_height += h; + } + } + } + */ +// QLegendMarker *marker = markers.at(i); + LegendMarkerItem *item = markers.at(i)->d_ptr->item(); + if (item->isVisible()) { +// LegendMarkerItem *item = marker->d_ptr->item(); + item->setGeometry(geometry); + item->setPos(point.x(),point.y()); + const QRectF& boundingRect = item->boundingRect(); + qreal w = boundingRect.width(); + qreal h = boundingRect.height(); + m_width = qMax(m_width,w); + m_height = qMax(m_height,h); + point.setX(point.x() + w); + if (point.x() + w > geometry.left() + geometry.width() - right) { + // Next item would go off rect. + point.setX(0); + point.setY(point.y() + h); + if (i+1 < markers.count()) { m_height += h; } } @@ -276,32 +304,54 @@ void LegendLayout::setDettachedGeometry(const QRectF &rect) m_width = 0; m_height = 0; for (int i = 0; i < markers.count(); i++) { + /* LegendMarker *marker = markers.at(i); if (marker->isVisible()) { marker->setGeometry(geometry); - const QRectF &boundingRect = marker->boundingRect(); + const QRectF& boundingRect = marker->boundingRect(); qreal w = boundingRect.width(); qreal h = boundingRect.height(); - m_width = qMax(m_width, w); - m_height = qMax(m_height, h); - marker->setPos(point.x(), point.y() - h); + m_width = qMax(m_width,w); + m_height = qMax(m_height,h); + marker->setPos(point.x(),point.y() - h); point.setX(point.x() + w); if (point.x() + w > geometry.left() + geometry.width() - right) { // Next item would go off rect. point.setX(0); point.setY(point.y() - h); - if (i + 1 < markers.count()) { + if (i+1 < markers.count()) { + m_height += h; + } + } + } + */ +// QLegendMarker *marker = markers.at(i); + LegendMarkerItem *item = markers.at(i)->d_ptr->item(); + if (item->isVisible()) { + item->setGeometry(geometry); + const QRectF& boundingRect = item->boundingRect(); + qreal w = boundingRect.width(); + qreal h = boundingRect.height(); + m_width = qMax(m_width,w); + m_height = qMax(m_height,h); + item->setPos(point.x(),point.y() - h); + point.setX(point.x() + w); + if (point.x() + w > geometry.left() + geometry.width() - right) { + // Next item would go off rect. + point.setX(0); + point.setY(point.y() - h); + if (i+1 < markers.count()) { m_height += h; } } } } - m_legend->d_ptr->items()->setPos(geometry.topLeft()); + m_legend->d_ptr->items()->setPos(geometry.topLeft()); - m_minOffsetX = -left; - m_minOffsetY = -m_height + geometry.height() - top; - m_maxOffsetX = m_width - geometry.width() - right; - m_maxOffsetY = -bottom; + m_minOffsetX = -left; + m_minOffsetY = -m_height + geometry.height() - top; + m_maxOffsetX = m_width - geometry.width() - right; + m_maxOffsetY = -bottom; } break; case Qt::AlignLeft: { @@ -310,34 +360,58 @@ void LegendLayout::setDettachedGeometry(const QRectF &rect) m_height = 0; qreal maxWidth = 0; for (int i = 0; i < markers.count(); i++) { + /* LegendMarker *marker = markers.at(i); if (marker->isVisible()) { marker->setGeometry(geometry); - const QRectF &boundingRect = marker->boundingRect(); + const QRectF& boundingRect = marker->boundingRect(); + qreal w = boundingRect.width(); + qreal h = boundingRect.height(); + m_height = qMax(m_height,h); + maxWidth = qMax(maxWidth,w); + marker->setPos(point.x(),point.y()); + point.setY(point.y() + h); + if (point.y() + h > geometry.bottom() - bottom) { + // Next item would go off rect. + point.setX(point.x() + maxWidth); + point.setY(0); + if (i+1 < markers.count()) { + m_width += maxWidth; + maxWidth = 0; + } + } + } + */ +// QLegendMarker *marker = markers.at(i); + LegendMarkerItem *item = markers.at(i)->d_ptr->item(); + if (item->isVisible()) { +// LegendMarkerItem *item = marker->d_ptr->item(); + item->setGeometry(geometry); + const QRectF& boundingRect = item->boundingRect(); qreal w = boundingRect.width(); qreal h = boundingRect.height(); - m_height = qMax(m_height, h); - maxWidth = qMax(maxWidth, w); - marker->setPos(point.x(), point.y()); + m_height = qMax(m_height,h); + maxWidth = qMax(maxWidth,w); + item->setPos(point.x(),point.y()); point.setY(point.y() + h); if (point.y() + h > geometry.bottom() - bottom) { // Next item would go off rect. point.setX(point.x() + maxWidth); point.setY(0); - if (i + 1 < markers.count()) { + if (i+1 < markers.count()) { m_width += maxWidth; maxWidth = 0; } } } } - m_width += maxWidth; - m_legend->d_ptr->items()->setPos(geometry.topLeft()); + m_width += maxWidth; + m_legend->d_ptr->items()->setPos(geometry.topLeft()); - m_minOffsetX = -left; - m_minOffsetY = -top; - m_maxOffsetX = m_width - geometry.width() - right; - m_maxOffsetY = m_height - geometry.height() - bottom; + m_minOffsetX = -left; + m_minOffsetY = -top; + m_maxOffsetX = m_width - geometry.width() - right; + m_maxOffsetY = m_height - geometry.height() - bottom; } break; case Qt::AlignRight: { @@ -346,34 +420,58 @@ void LegendLayout::setDettachedGeometry(const QRectF &rect) m_height = 0; qreal maxWidth = 0; for (int i = 0; i < markers.count(); i++) { + /* LegendMarker *marker = markers.at(i); if (marker->isVisible()) { marker->setGeometry(geometry); - const QRectF &boundingRect = marker->boundingRect(); + const QRectF& boundingRect = marker->boundingRect(); qreal w = boundingRect.width(); qreal h = boundingRect.height(); - m_height = qMax(m_height, h); - maxWidth = qMax(maxWidth, w); - marker->setPos(point.x() - w, point.y()); + m_height = qMax(m_height,h); + maxWidth = qMax(maxWidth,w); + marker->setPos(point.x() - w,point.y()); point.setY(point.y() + h); - if (point.y() + h > geometry.bottom() - bottom) { + if (point.y() + h > geometry.bottom()-bottom) { + // Next item would go off rect. + point.setX(point.x() - maxWidth); + point.setY(0); + if (i+1 < markers.count()) { + m_width += maxWidth; + maxWidth = 0; + } + } + } + */ +// QLegendMarker *marker = markers.at(i); + LegendMarkerItem *item = markers.at(i)->d_ptr->item(); + if (item->isVisible()) { +// LegendMarkerItem *item = marker->d_ptr->item(); + item->setGeometry(geometry); + const QRectF& boundingRect = item->boundingRect(); + qreal w = boundingRect.width(); + qreal h = boundingRect.height(); + m_height = qMax(m_height,h); + maxWidth = qMax(maxWidth,w); + item->setPos(point.x() - w,point.y()); + point.setY(point.y() + h); + if (point.y() + h > geometry.bottom()-bottom) { // Next item would go off rect. point.setX(point.x() - maxWidth); point.setY(0); - if (i + 1 < markers.count()) { + if (i+1 < markers.count()) { m_width += maxWidth; maxWidth = 0; } } } } - m_width += maxWidth; - m_legend->d_ptr->items()->setPos(geometry.topLeft()); + m_width += maxWidth; + m_legend->d_ptr->items()->setPos(geometry.topLeft()); - m_minOffsetX = - m_width + geometry.width() - left; - m_minOffsetY = -top; - m_maxOffsetX = - right; - m_maxOffsetY = m_height - geometry.height() - bottom; + m_minOffsetX = - m_width + geometry.width() - left; + m_minOffsetY = -top; + m_maxOffsetX = - right; + m_maxOffsetY = m_height - geometry.height() - bottom; } break; default: @@ -424,7 +522,7 @@ QSizeF LegendLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) cons if(constraint.isValid()) { foreach(QLegendMarker* marker, m_legend->d_ptr->legendMarkers()) { - LegendMarkerItem *item = marker->d_ptr.data()->item(); + LegendMarkerItem *item = marker->d_ptr->item(); size = size.expandedTo(item->effectiveSizeHint(which)); } size = size.boundedTo(constraint); @@ -433,7 +531,7 @@ QSizeF LegendLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) cons qreal width = 0; qreal height = 0; foreach(QLegendMarker* marker, m_legend->d_ptr->legendMarkers()) { - LegendMarkerItem *item = marker->d_ptr.data()->item(); + LegendMarkerItem *item = marker->d_ptr->item(); width+=item->effectiveSizeHint(which).width(); height=qMax(height,item->effectiveSizeHint(which).height()); } @@ -444,7 +542,7 @@ QSizeF LegendLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) cons qreal width = 0; qreal height = 0; foreach(QLegendMarker* marker, m_legend->d_ptr->legendMarkers()) { - LegendMarkerItem *item = marker->d_ptr.data()->item(); + LegendMarkerItem *item = marker->d_ptr->item(); width=qMax(width,item->effectiveSizeHint(which).width()); height+=height,item->effectiveSizeHint(which).height(); } @@ -452,7 +550,7 @@ QSizeF LegendLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) cons } else { foreach(QLegendMarker* marker, m_legend->d_ptr->legendMarkers()) { - LegendMarkerItem *item = marker->d_ptr.data()->item(); + LegendMarkerItem *item = marker->d_ptr->item(); size = size.expandedTo(item->effectiveSizeHint(which)); } } diff --git a/src/legend/legendmarkeritem.cpp b/src/legend/legendmarkeritem.cpp index 4e281f3..2436983 100644 --- a/src/legend/legendmarkeritem.cpp +++ b/src/legend/legendmarkeritem.cpp @@ -33,17 +33,13 @@ LegendMarkerItem::LegendMarkerItem(QLegendMarkerPrivate *marker, QGraphicsObject QGraphicsObject(parent), m_marker(marker), m_markerRect(0,0,10.0,10.0), - m_boundingRect(0,0,10,10), + m_boundingRect(0,0,0,0), m_textItem(new QGraphicsSimpleTextItem(this)), m_rectItem(new QGraphicsRectItem(this)), m_margin(4), m_space(4) { -// qDebug() << "LegendMarkerItem created for marker:" << m_marker; -// setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton); m_rectItem->setRect(m_markerRect); -// setZValue(zValue() + 20); -// qDebug() << "z:" << this->zValue(); } void LegendMarkerItem::setPen(const QPen &pen) @@ -81,7 +77,6 @@ QFont LegendMarkerItem::font() const void LegendMarkerItem::setLabel(const QString label) { - qDebug() << "LegendMarkerItem::setlabel" << label; m_text = label; updateGeometry(); } diff --git a/src/legend/qlegend.cpp b/src/legend/qlegend.cpp index 0b77e89..d0801ea 100644 --- a/src/legend/qlegend.cpp +++ b/src/legend/qlegend.cpp @@ -476,26 +476,18 @@ int QLegendPrivate::roundness(qreal size) void QLegendPrivate::appendSeries(QAbstractSeries* series) { - Q_UNUSED(series); - // TODO: - /* if (!m_series.contains(series)) { m_series.append(series); - handleSeriesAdded(series,0); // Dummy domain + handleSeriesAdded(series,0); } - */ } void QLegendPrivate::removeSeries(QAbstractSeries* series) { - Q_UNUSED(series); - // TODO: - /* if (m_series.contains(series)) { m_series.removeOne(series); handleSeriesRemoved(series); } - */ } void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series, Domain *domain) @@ -517,6 +509,7 @@ void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series, Domain *domain) QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); // <--- New markers +/* QList markers = series->d_ptr->createLegendMarker(q_ptr); foreach (LegendMarker *marker, markers) { @@ -526,6 +519,7 @@ void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series, Domain *domain) m_items->addToGroup(marker); m_markers << marker; } +*/ QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); QObject::connect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged())); @@ -539,6 +533,8 @@ void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series) // New markers ---> foreach (QLegendMarker *marker, m_legendMarkers) { if (marker->series() == series) { + marker->d_ptr.data()->item()->setVisible(false); + m_items->removeFromGroup(marker->d_ptr.data()->item()); delete marker; m_legendMarkers.removeAll(marker); } @@ -547,13 +543,14 @@ void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series) QObject::disconnect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); // <--- New markers +/* foreach (LegendMarker *marker, m_markers) { if (marker->series() == series) { delete marker; m_markers.removeAll(marker); } } - +*/ QObject::disconnect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); QObject::disconnect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged())); m_layout->invalidate(); @@ -572,17 +569,19 @@ void QLegendPrivate::handleSeriesVisibleChanged() } // <--- New markers - +/* foreach (LegendMarker* marker, m_markers) { if (marker->series() == series) { marker->setVisible(series->isVisible()); } +*/ m_layout->invalidate(); } void QLegendPrivate::handleCountChanged() { // With new markers, the series shoud notify markers directly? + qDebug() << "handleLegendPropertiesUpdated"; // Handle new or removed markers // Handle changes of marker pen/brush/label. every property that legend is interested diff --git a/src/legend/qlegendmarker.cpp b/src/legend/qlegendmarker.cpp index 4c973bf..acab44c 100644 --- a/src/legend/qlegendmarker.cpp +++ b/src/legend/qlegendmarker.cpp @@ -113,6 +113,7 @@ QLegendMarkerPrivate::QLegendMarkerPrivate(QLegendMarker *q) : QLegendMarkerPrivate::~QLegendMarkerPrivate() { +// delete m_item; } void QLegendMarkerPrivate::handleMousePressEvent(QGraphicsSceneEvent *event) diff --git a/src/legend/qpielegendmarker.cpp b/src/legend/qpielegendmarker.cpp index 94671ea..b8cddd9 100644 --- a/src/legend/qpielegendmarker.cpp +++ b/src/legend/qpielegendmarker.cpp @@ -32,6 +32,7 @@ QPieLegendMarker::QPieLegendMarker(QPieSeries* series, QPieSlice* slice, QObject QPieLegendMarker::~QPieLegendMarker() { + qDebug() << "deleting pie marker" << this; } /*! @@ -61,7 +62,7 @@ QPieLegendMarkerPrivate::QPieLegendMarkerPrivate(QPieSeries *series, QPieSlice * m_series(series), m_slice(slice) { - qDebug() << "QPieLegendMarkerPrivate created"; +// qDebug() << "QPieLegendMarkerPrivate created"; QObject::connect(m_slice, SIGNAL(labelChanged()), this, SLOT(updated())); QObject::connect(m_slice, SIGNAL(brushChanged()), this, SLOT(updated())); updated(); @@ -75,7 +76,7 @@ QPieLegendMarkerPrivate::~QPieLegendMarkerPrivate() void QPieLegendMarkerPrivate::updated() { - qDebug() << "QPieLegendMarkerPrivate::updated"; +// qDebug() << "QPieLegendMarkerPrivate::updated"; m_item->setBrush(m_slice->brush()); m_item->setLabel(m_slice->label()); m_item->setPen(m_slice->pen());