From fbeefa353bab5efa44202fa722cc92caadc748a7 2012-10-17 07:46:15 From: sauimone Date: 2012-10-17 07:46:15 Subject: [PATCH] legendmarker private is just QObject --- diff --git a/src/legend/legendmarkeritem_p.h b/src/legend/legendmarkeritem_p.h index 37bfdb7..3c5db80 100644 --- a/src/legend/legendmarkeritem_p.h +++ b/src/legend/legendmarkeritem_p.h @@ -53,7 +53,7 @@ class LegendMarkerItem : public QGraphicsObject, public QGraphicsLayoutItem Q_OBJECT Q_INTERFACES(QGraphicsLayoutItem) public: - explicit LegendMarkerItem(QAbstractSeries *m_series, QGraphicsObject *parent); + explicit LegendMarkerItem(QAbstractSeries *m_series, QGraphicsObject *parent = 0); void setPen(const QPen &pen); QPen pen() const; diff --git a/src/legend/qlegendmarker.cpp b/src/legend/qlegendmarker.cpp index 7b73043..e2be6e3 100644 --- a/src/legend/qlegendmarker.cpp +++ b/src/legend/qlegendmarker.cpp @@ -107,80 +107,9 @@ QLegendMarkerPrivate::QLegendMarkerPrivate(QAbstractSeries *series, QLegendMarke q_ptr(q), m_series(series) { - m_item = new LegendMarkerItem(m_series,this); + m_item = new LegendMarkerItem(m_series); } -void QLegendMarkerPrivate::setGeometry(const QRectF& rect) -{ - QFontMetrics fn (m_font); - - - int width = rect.width(); - qreal x = m_margin + m_markerRect.width() + m_space + m_margin; - qreal y = qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin); - - if (fn.boundingRect(m_label).width() + x > width) - { - QString string = m_label + "..."; - while(fn.boundingRect(string).width() + x > width && string.length() > 3) - string.remove(string.length() - 4, 1); - m_textItem->setText(string); - } - else - m_textItem->setText(m_label); - - const QRectF& textRect = m_textItem->boundingRect(); - - - m_textItem->setPos(x-m_margin,y/2 - textRect.height()/2); - m_rectItem->setRect(m_markerRect); - m_rectItem->setPos(m_margin,y/2 - m_markerRect.height()/2); - - prepareGeometryChange(); - m_boundingRect = QRectF(0,0,x+textRect.width()+m_margin,y); -} - -QRectF QLegendMarkerPrivate::boundingRect() const -{ - return m_boundingRect; -} - -void QLegendMarkerPrivate::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - Q_UNUSED(option) - Q_UNUSED(widget) - Q_UNUSED(painter) -} - -QSizeF QLegendMarkerPrivate::sizeHint(Qt::SizeHint which, const QSizeF& constraint) const -{ - Q_UNUSED(constraint) - - QFontMetrics fn(m_textItem->font()); - QSizeF sh; - - switch (which) { - case Qt::MinimumSize: - sh = QSizeF(fn.boundingRect("...").width() + 2*m_margin + m_space +m_markerRect.width(),qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin)); - break; - case Qt::PreferredSize: - sh = QSizeF(fn.boundingRect(m_label).width() + 2*m_margin + m_space +m_markerRect.width(),qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin)); - break; - default: - break; - } - - return sh; -} - -void QLegendMarkerPrivate::mousePressEvent(QGraphicsSceneMouseEvent *event) -{ - qDebug() << "QLegendMarkerPrivate::mousePressEvent" << event; - QGraphicsObject::mousePressEvent(event); - //TODO: selected signal removed for now -} - - #include "moc_qlegendmarker.cpp" #include "moc_qlegendmarker_p.cpp" diff --git a/src/legend/qlegendmarker_p.h b/src/legend/qlegendmarker_p.h index 04c788f..2db9f69 100644 --- a/src/legend/qlegendmarker_p.h +++ b/src/legend/qlegendmarker_p.h @@ -52,10 +52,9 @@ class QPieSeries; class QLegendMarker; class LegendMarkerItem; -class QLegendMarkerPrivate : public QGraphicsObject, public QGraphicsLayoutItem +class QLegendMarkerPrivate : public QObject { Q_OBJECT - Q_INTERFACES(QGraphicsLayoutItem) public: explicit QLegendMarkerPrivate(QAbstractSeries *series, QLegendMarker *q); /* @@ -74,17 +73,6 @@ public: void setLabelBrush(const QBrush &brush); QBrush labelBrush() const; */ - void setGeometry(const QRectF& rect); - - QRectF boundingRect() const; - - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); - - QSizeF sizeHint (Qt::SizeHint which, const QSizeF& constraint) const; - -protected: - // From QGraphicsObject - void mousePressEvent(QGraphicsSceneMouseEvent *event); public Q_SLOTS: virtual void updated() {};