diff --git a/src/barchart/qabstractbarseries.cpp b/src/barchart/qabstractbarseries.cpp index 1749389..bb32ca2 100644 --- a/src/barchart/qabstractbarseries.cpp +++ b/src/barchart/qabstractbarseries.cpp @@ -29,6 +29,8 @@ #include "qvalueaxis.h" #include "qbarcategoryaxis.h" +#include "qbarlegendmarker.h" + QTCOMMERCIALCHART_BEGIN_NAMESPACE /*! @@ -661,16 +663,13 @@ QList QAbstractBarSeriesPrivate::createLegendMarker(QLegend *leg QList QAbstractBarSeriesPrivate::createLegendMarkers(QLegend* legend) { - Q_UNUSED(legend); -// Q_Q(QAbstractBarSeries); + Q_Q(QAbstractBarSeries); QList markers; -// TODO: when QBarLegendMarker is implemented -/* + foreach(QBarSet* set, q->barSets()) { - BarLegendMarker* marker = new BarLegendMarker(q,set,legend); + QBarLegendMarker* marker = new QBarLegendMarker(q,set,legend); markers << marker; } -*/ return markers; } diff --git a/src/legend/legend.pri b/src/legend/legend.pri index c3e3c72..c7064a7 100644 --- a/src/legend/legend.pri +++ b/src/legend/legend.pri @@ -7,7 +7,8 @@ SOURCES += \ $$PWD/legendlayout.cpp \ $$PWD/qlegendmarker.cpp \ $$PWD/qpielegendmarker.cpp \ - $$PWD/legendmarkeritem.cpp + $$PWD/legendmarkeritem.cpp \ + $$PWD/qbarlegendmarker.cpp PRIVATE_HEADERS += \ $$PWD/legendmarker_p.h \ @@ -16,10 +17,12 @@ PRIVATE_HEADERS += \ $$PWD/legendlayout_p.h \ $$PWD/qlegendmarker_p.h \ $$PWD/legendmarkeritem_p.h \ - $$PWD/qpielegendmarker_p.h + $$PWD/qpielegendmarker_p.h \ + $$PWD/qbarlegendmarker_p.h PUBLIC_HEADERS += \ $$PWD/qlegend.h \ $$PWD/qlegendmarker.h \ - $$PWD/qpielegendmarker.h + $$PWD/qpielegendmarker.h \ + $$PWD/qbarlegendmarker.h diff --git a/src/legend/legendmarkeritem.cpp b/src/legend/legendmarkeritem.cpp index 4117ff1..bd9e3dc 100644 --- a/src/legend/legendmarkeritem.cpp +++ b/src/legend/legendmarkeritem.cpp @@ -76,13 +76,13 @@ QFont LegendMarkerItem::font() const void LegendMarkerItem::setLabel(const QString label) { - m_text = label; + m_label = label; updateGeometry(); } QString LegendMarkerItem::label() const { - return m_text; + return m_label; } void LegendMarkerItem::setLabelBrush(const QBrush &brush) @@ -103,15 +103,15 @@ void LegendMarkerItem::setGeometry(const QRectF& rect) 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_text).width() + x > width) + if (fn.boundingRect(m_label).width() + x > width) { - QString string = m_text + "..."; + 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_text); + m_textItem->setText(m_label); const QRectF& textRect = m_textItem->boundingRect(); @@ -148,7 +148,7 @@ QSizeF LegendMarkerItem::sizeHint(Qt::SizeHint which, const QSizeF& constraint) 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_text).width() + 2*m_margin + m_space +m_markerRect.width(),qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin)); + 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; diff --git a/src/legend/legendmarkeritem_p.h b/src/legend/legendmarkeritem_p.h index 65c319f..ad0347b 100644 --- a/src/legend/legendmarkeritem_p.h +++ b/src/legend/legendmarkeritem_p.h @@ -84,15 +84,15 @@ protected: QGraphicsRectItem *m_rectItem; qreal m_margin; qreal m_space; - QString m_text; - QString m_label; + QBrush m_labelBrush; QFont m_font; QPen m_pen; QBrush m_brush; bool m_visible; + friend class QLegendMarker; friend class QLegendMarkerPrivate; friend class LegendLayout; }; diff --git a/src/legend/qbarlegendmarker.cpp b/src/legend/qbarlegendmarker.cpp new file mode 100644 index 0000000..da7b95d --- /dev/null +++ b/src/legend/qbarlegendmarker.cpp @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the Qt Commercial Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qbarlegendmarker.h" +#include "qbarlegendmarker_p.h" +#include +#include +#include + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +QBarLegendMarker::QBarLegendMarker(QAbstractBarSeries* series, QBarSet* barset, QLegend *legend, QObject *parent) : + QLegendMarker(*new QBarLegendMarkerPrivate(this,series,barset,legend), parent) +{ +} + +QBarLegendMarker::~QBarLegendMarker() +{ +// qDebug() << "deleting bar marker" << this; +} + +/*! + \internal +*/ +QBarLegendMarker::QBarLegendMarker(QBarLegendMarkerPrivate &d, QObject *parent) : + QLegendMarker(d, parent) +{ +} + +QAbstractBarSeries *QBarLegendMarker::series() +{ + Q_D(QBarLegendMarker); + return d->m_series; +} + +QBarSet* QBarLegendMarker::peerObject() +{ + Q_D(QBarLegendMarker); + return d->m_barset; +} + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +QBarLegendMarkerPrivate::QBarLegendMarkerPrivate(QBarLegendMarker *q, QAbstractBarSeries *series, QBarSet *barset, QLegend *legend) : + QLegendMarkerPrivate(q,legend), + m_series(series), + m_barset(barset) +{ + QObject::connect(m_barset, SIGNAL(penChanged()), this, SLOT(updated())); + QObject::connect(m_barset, SIGNAL(labelChanged()), this, SLOT(updated())); + QObject::connect(m_barset, SIGNAL(brushChanged()), this, SLOT(updated())); + updated(); +} + +QBarLegendMarkerPrivate::~QBarLegendMarkerPrivate() +{ + QObject::disconnect(m_barset, SIGNAL(labelChanged()), this, SLOT(updated())); + QObject::disconnect(m_barset, SIGNAL(brushChanged()), this, SLOT(updated())); + QObject::disconnect(m_barset, SIGNAL(penChanged()), this, SLOT(updated())); +} + +void QBarLegendMarkerPrivate::updated() +{ + m_item->setPen(m_barset->pen()); + m_item->setBrush(m_barset->brush()); + m_item->setLabel(m_barset->label()); +} + +#include "moc_qbarlegendmarker.cpp" +#include "moc_qbarlegendmarker_p.cpp" + +QTCOMMERCIALCHART_END_NAMESPACE + diff --git a/src/legend/qbarlegendmarker.h b/src/legend/qbarlegendmarker.h new file mode 100644 index 0000000..9541332 --- /dev/null +++ b/src/legend/qbarlegendmarker.h @@ -0,0 +1,59 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the Qt Commercial Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QBARLEGENDMARKER_H +#define QBARLEGENDMARKER_H + +#include +#include +#include +#include +//#include "qbarlegendmarker_p.h" + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +class QLegend; +class QBarLegendMarkerPrivate; + +class QTCOMMERCIALCHART_EXPORT QBarLegendMarker : public QLegendMarker +{ + Q_OBJECT +public: + explicit QBarLegendMarker(QAbstractBarSeries* series, QBarSet* barset, QLegend *legend, QObject *parent = 0); + virtual ~QBarLegendMarker(); + + virtual QAbstractBarSeries* series(); + virtual QBarSet* peerObject(); // TODO: rename to slice and remove these virtuals from base class? + +protected: + QBarLegendMarker(QBarLegendMarkerPrivate &d, QObject *parent = 0); + +//Q_SIGNALS: + +//public Q_SLOTS: + +private: + Q_DECLARE_PRIVATE(QBarLegendMarker) + Q_DISABLE_COPY(QBarLegendMarker) + +}; + +QTCOMMERCIALCHART_END_NAMESPACE + +#endif // QBARLEGENDMARKER_H diff --git a/src/legend/qbarlegendmarker_p.h b/src/legend/qbarlegendmarker_p.h new file mode 100644 index 0000000..5981397 --- /dev/null +++ b/src/legend/qbarlegendmarker_p.h @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the Qt Commercial Charts Add-on. +** +** $QT_BEGIN_LICENSE$ +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// W A R N I N G +// ------------- +// +// This file is not part of the QtCommercial Chart API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. + +#ifndef QBARLEGENDMARKER_P_H +#define QBARLEGENDMARKER_P_H + +#include "qchartglobal.h" +#include "qlegendmarker_p.h" +#include "legendmarkeritem_p.h" +#include +#include + +#include + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +class QBarLegendMarker; + +class QBarLegendMarkerPrivate : public QLegendMarkerPrivate +{ + Q_OBJECT +public: + explicit QBarLegendMarkerPrivate(QBarLegendMarker *q, QAbstractBarSeries *series, QBarSet *barset, QLegend *legend); + virtual ~QBarLegendMarkerPrivate(); + +public Q_SLOTS: + virtual void updated(); + +private: + QBarLegendMarker *q_ptr; + + QAbstractBarSeries* m_series; + QBarSet* m_barset; + + friend class QLegendPrivate; // TODO: Is this needed? + Q_DECLARE_PUBLIC(QBarLegendMarker) +}; + +QTCOMMERCIALCHART_END_NAMESPACE + +#endif // QBARLEGENDMARKER_P_H diff --git a/src/legend/qlegendmarker.cpp b/src/legend/qlegendmarker.cpp index 5570745..6932852 100644 --- a/src/legend/qlegendmarker.cpp +++ b/src/legend/qlegendmarker.cpp @@ -27,13 +27,7 @@ #include QTCOMMERCIALCHART_BEGIN_NAMESPACE -/* -QLegendMarker::QLegendMarker(QAbstractSeries* series, QObject *parent) : - QObject(parent), - d_ptr(new QLegendMarkerPrivate(series, this)) -{ -} -*/ + QLegendMarker::QLegendMarker(QLegendMarkerPrivate &d, QObject *parent) : QObject(parent), d_ptr(&d) @@ -46,62 +40,62 @@ QLegendMarker::~QLegendMarker() QString QLegendMarker::label() const { - return d_ptr->label(); + return d_ptr->m_item->label(); } void QLegendMarker::setLabel(const QString &label) { - d_ptr->setLabel(label); + d_ptr->m_item->setLabel(label); } QBrush QLegendMarker::labelBrush() const { - return d_ptr->labelBrush(); + return d_ptr->m_item->brush(); } void QLegendMarker::setLabelBrush(const QBrush &brush) { - d_ptr->setLabelBrush(brush); + d_ptr->m_item->setLabelBrush(brush); } QFont QLegendMarker::font() const { - return d_ptr->font(); + return d_ptr->m_item->font(); } void QLegendMarker::setFont(const QFont &font) { - d_ptr->setFont(font); + d_ptr->m_item->setFont(font); } QPen QLegendMarker::pen() const { - return d_ptr->pen(); + return d_ptr->m_item->pen(); } void QLegendMarker::setPen(const QPen &pen) { - d_ptr->setPen(pen); + d_ptr->m_item->setPen(pen); } QBrush QLegendMarker::brush() const { - return d_ptr->brush(); + return d_ptr->m_item->brush(); } void QLegendMarker::setBrush(const QBrush &brush) { - d_ptr->setBrush(brush); + d_ptr->m_item->setBrush(brush); } bool QLegendMarker::isVisible() const { - return d_ptr->isVisible(); + return d_ptr->m_item->isVisible(); } void QLegendMarker::setVisible(bool visible) { - d_ptr->setVisible(visible); + d_ptr->m_item->setVisible(visible); } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -109,7 +103,6 @@ QLegendMarkerPrivate::QLegendMarkerPrivate(QLegendMarker *q, QLegend *legend) : q_ptr(q), m_legend(legend) { -// qDebug() << "QLegendMarkerPrivate created"; m_item = new LegendMarkerItem(this); } @@ -127,67 +120,6 @@ void QLegendMarkerPrivate::handleMousePressEvent(QGraphicsSceneEvent *event) emit q->clicked(); } -void QLegendMarkerPrivate::setPen(const QPen &pen) -{ - m_item->setPen(pen); -} - -QPen QLegendMarkerPrivate::pen() const -{ - return m_item->pen(); -} - -void QLegendMarkerPrivate::setBrush(const QBrush &brush) -{ - m_item->setBrush(brush); -} - -QBrush QLegendMarkerPrivate::brush() const -{ - return m_item->brush(); -} - -void QLegendMarkerPrivate::setFont(const QFont &font) -{ - m_item->setFont(font); -} - -QFont QLegendMarkerPrivate::font() const -{ - return m_item->font(); -} - -void QLegendMarkerPrivate::setLabel(const QString label) -{ - m_item->setLabel(label); -} - -QString QLegendMarkerPrivate::label() const -{ - return m_item->label(); -} - -void QLegendMarkerPrivate::setLabelBrush(const QBrush &brush) -{ - m_item->setLabelBrush(brush); -} - -QBrush QLegendMarkerPrivate::labelBrush() const -{ - return m_item->labelBrush(); -} - -bool QLegendMarkerPrivate::isVisible() const -{ - return m_item->isVisible(); -} - -void QLegendMarkerPrivate::setVisible(bool visible) -{ - m_item->setVisible(visible); -} - - #include "moc_qlegendmarker.cpp" #include "moc_qlegendmarker_p.cpp" diff --git a/src/legend/qlegendmarker.h b/src/legend/qlegendmarker.h index 0d5f340..1a97ba4 100644 --- a/src/legend/qlegendmarker.h +++ b/src/legend/qlegendmarker.h @@ -65,8 +65,8 @@ public: bool isVisible() const; void setVisible(bool visible); -// virtual QAbstractSeries::SeriesType type() = 0; // TODO? - virtual QAbstractSeries* series() = 0; +// virtual QAbstractSeries::SeriesType type() = 0; // TODO? Or use LegendMarker type enum? + virtual QAbstractSeries* series() = 0; // TODO: remove these and use specialised functions on derived classes? virtual QObject* peerObject() = 0; protected: diff --git a/src/legend/qlegendmarker_p.h b/src/legend/qlegendmarker_p.h index 8b8bd79..85bdf6a 100644 --- a/src/legend/qlegendmarker_p.h +++ b/src/legend/qlegendmarker_p.h @@ -57,30 +57,10 @@ class QLegendMarkerPrivate : public QObject { Q_OBJECT public: -// explicit QLegendMarkerPrivate(QAbstractSeries *series, QLegendMarker *q); explicit QLegendMarkerPrivate(QLegendMarker *q, QLegend *legend); virtual ~QLegendMarkerPrivate(); - // TODO: remove temporary setters/getters and use the m_item directly from public class via d_ptr - void setPen(const QPen &pen); - QPen pen() const; - - void setBrush(const QBrush &brush); - QBrush brush() const; - - void setFont(const QFont &font); - QFont font() const; - - void setLabel(const QString label); - QString label() const; - - void setLabelBrush(const QBrush &brush); - QBrush labelBrush() const; - - bool isVisible() const; - void setVisible(bool visible); - - // Helper for now. + // Helper for now. (or deckare LegendLayout as friend) LegendMarkerItem* item() const { return m_item; } // Item gets the event, logic for event is here @@ -96,16 +76,6 @@ protected: private: QLegendMarker *q_ptr; -// New legend marker properties -// Moved to item. -/* - QString m_label; - QBrush m_labelBrush; - QFont m_font; - QPen m_pen; - QBrush m_brush; - bool m_visible; -*/ friend class QLegendPrivate; // TODO: Is this needed? Q_DECLARE_PUBLIC(QLegendMarker) }; diff --git a/src/legend/qpielegendmarker.cpp b/src/legend/qpielegendmarker.cpp index 9c086af..d4bd769 100644 --- a/src/legend/qpielegendmarker.cpp +++ b/src/legend/qpielegendmarker.cpp @@ -21,6 +21,7 @@ #include "qpielegendmarker.h" #include "qpielegendmarker_p.h" #include +#include #include QTCOMMERCIALCHART_BEGIN_NAMESPACE @@ -32,7 +33,7 @@ QPieLegendMarker::QPieLegendMarker(QPieSeries* series, QPieSlice* slice, QLegend QPieLegendMarker::~QPieLegendMarker() { - qDebug() << "deleting pie marker" << this; +// qDebug() << "deleting pie marker" << this; } /*! @@ -43,7 +44,7 @@ QPieLegendMarker::QPieLegendMarker(QPieLegendMarkerPrivate &d, QObject *parent) { } -QAbstractSeries* QPieLegendMarker::series() +QPieSeries* QPieLegendMarker::series() { Q_D(QPieLegendMarker); return d->m_series; @@ -64,6 +65,7 @@ QPieLegendMarkerPrivate::QPieLegendMarkerPrivate(QPieLegendMarker *q, QPieSeries { QObject::connect(m_slice, SIGNAL(labelChanged()), this, SLOT(updated())); QObject::connect(m_slice, SIGNAL(brushChanged()), this, SLOT(updated())); + QObject::connect(m_slice, SIGNAL(penChanged()), this, SLOT(updated())); updated(); } @@ -71,14 +73,14 @@ QPieLegendMarkerPrivate::~QPieLegendMarkerPrivate() { QObject::disconnect(m_slice, SIGNAL(labelChanged()), this, SLOT(updated())); QObject::disconnect(m_slice, SIGNAL(brushChanged()), this, SLOT(updated())); + QObject::disconnect(m_slice, SIGNAL(penChanged()), this, SLOT(updated())); } void QPieLegendMarkerPrivate::updated() { - m_item->setBrush(m_slice->brush()); - m_item->setLabel(m_slice->label()); m_item->setPen(m_slice->pen()); m_item->setBrush(m_slice->brush()); + m_item->setLabel(m_slice->label()); } #include "moc_qpielegendmarker.cpp" diff --git a/src/legend/qpielegendmarker.h b/src/legend/qpielegendmarker.h index b6ab00b..fc50e4e 100644 --- a/src/legend/qpielegendmarker.h +++ b/src/legend/qpielegendmarker.h @@ -23,12 +23,15 @@ #include #include +#include #include -#include "qpielegendmarker_p.h" +//#include "qpielegendmarker_p.h" QTCOMMERCIALCHART_BEGIN_NAMESPACE -// TODO: No export, make this private. QLegendMarker should be enough for user of the api (why expose the details?) +class QPieLegendMarkerPrivate; + +// TODO: No export? make this private. QLegendMarker should be enough for user of the api (why expose the details?) class QTCOMMERCIALCHART_EXPORT QPieLegendMarker : public QLegendMarker { Q_OBJECT @@ -37,8 +40,8 @@ public: explicit QPieLegendMarker(QPieSeries* series, QPieSlice* slice, QLegend *legend, QObject *parent = 0); virtual ~QPieLegendMarker(); - virtual QAbstractSeries* series(); - virtual QPieSlice* peerObject(); + virtual QPieSeries* series(); + virtual QPieSlice* peerObject(); // TODO: rename to slice and remove these virtuals from base class? protected: QPieLegendMarker(QPieLegendMarkerPrivate &d, QObject *parent = 0); diff --git a/src/legend/qpielegendmarker_p.h b/src/legend/qpielegendmarker_p.h index 327b836..f662be8 100644 --- a/src/legend/qpielegendmarker_p.h +++ b/src/legend/qpielegendmarker_p.h @@ -46,7 +46,6 @@ class QPieLegendMarkerPrivate : public QLegendMarkerPrivate { Q_OBJECT public: -// explicit QPieLegendMarkerPrivate(QAbstractSeries *series, QPieLegendMarker *q); explicit QPieLegendMarkerPrivate(QPieLegendMarker *q, QPieSeries *series, QPieSlice *slice, QLegend *legend); virtual ~QPieLegendMarkerPrivate();