diff --git a/src/legend/legend.pri b/src/legend/legend.pri index c7064a7..3e7520a 100644 --- a/src/legend/legend.pri +++ b/src/legend/legend.pri @@ -8,7 +8,8 @@ SOURCES += \ $$PWD/qlegendmarker.cpp \ $$PWD/qpielegendmarker.cpp \ $$PWD/legendmarkeritem.cpp \ - $$PWD/qbarlegendmarker.cpp + $$PWD/qbarlegendmarker.cpp \ + $$PWD/qxylegendmarker.cpp PRIVATE_HEADERS += \ $$PWD/legendmarker_p.h \ @@ -18,11 +19,13 @@ PRIVATE_HEADERS += \ $$PWD/qlegendmarker_p.h \ $$PWD/legendmarkeritem_p.h \ $$PWD/qpielegendmarker_p.h \ - $$PWD/qbarlegendmarker_p.h + $$PWD/qbarlegendmarker_p.h \ + $$PWD/qxylegendmarker_p.h PUBLIC_HEADERS += \ $$PWD/qlegend.h \ $$PWD/qlegendmarker.h \ $$PWD/qpielegendmarker.h \ - $$PWD/qbarlegendmarker.h + $$PWD/qbarlegendmarker.h \ + $$PWD/qxylegendmarker.h diff --git a/src/legend/qxylegendmarker.cpp b/src/legend/qxylegendmarker.cpp new file mode 100644 index 0000000..21115ed --- /dev/null +++ b/src/legend/qxylegendmarker.cpp @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** 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 "qxylegendmarker.h" +#include "qxylegendmarker_p.h" +#include "qxyseries_p.h" +#include +#include + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +QXYLegendMarker::QXYLegendMarker(QXYSeries* series, QLegend *legend, QObject *parent) : + QLegendMarker(*new QXYLegendMarkerPrivate(this,series,legend), parent) +{ +} + +QXYLegendMarker::~QXYLegendMarker() +{ +// qDebug() << "deleting xy marker" << this; +} + +/*! + \internal +*/ +QXYLegendMarker::QXYLegendMarker(QXYLegendMarkerPrivate &d, QObject *parent) : + QLegendMarker(d, parent) +{ +} + +QXYSeries* QXYLegendMarker::series() +{ + Q_D(QXYLegendMarker); + return d->m_series; +} + +QXYSeries* QXYLegendMarker::peerObject() +{ + Q_D(QXYLegendMarker); + return d->m_series; +} + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +QXYLegendMarkerPrivate::QXYLegendMarkerPrivate(QXYLegendMarker *q, QXYSeries *series, QLegend *legend) : + QLegendMarkerPrivate(q,legend), + m_series(series) +{ + QObject::connect(m_series, SIGNAL(nameChanged()), this, SLOT(updated())); + QObject::connect(m_series->d_func(), SIGNAL(updated()), this, SLOT(updated())); + updated(); +} + +QXYLegendMarkerPrivate::~QXYLegendMarkerPrivate() +{ + QObject::disconnect(m_series->d_func(), SIGNAL(updated()), this, SLOT(updated())); + QObject::disconnect(m_series, SIGNAL(nameChanged()), this, SLOT(updated())); +} + +void QXYLegendMarkerPrivate::updated() +{ + m_item->setLabel(m_series->name()); + + if (m_series->type()== QAbstractSeries::SeriesTypeScatter) { + m_item->setBrush(m_series->brush()); + } else { + m_item->setBrush(QBrush(m_series->pen().color())); + } +} + +#include "moc_qxylegendmarker.cpp" +#include "moc_qxylegendmarker_p.cpp" + +QTCOMMERCIALCHART_END_NAMESPACE + diff --git a/src/legend/qxylegendmarker.h b/src/legend/qxylegendmarker.h new file mode 100644 index 0000000..97666f0 --- /dev/null +++ b/src/legend/qxylegendmarker.h @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** 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 QXYLEGENDMARKER_H +#define QXYLEGENDMARKER_H + +#include +#include +#include + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +class QXYLegendMarkerPrivate; + +class QTCOMMERCIALCHART_EXPORT QXYLegendMarker : public QLegendMarker +{ + Q_OBJECT +public: + explicit QXYLegendMarker(QXYSeries* series, QLegend *legend, QObject *parent = 0); + virtual ~QXYLegendMarker(); + + virtual QXYSeries* series(); + virtual QXYSeries* peerObject(); // TODO: rename to slice and remove these virtuals from base class? + +protected: + QXYLegendMarker(QXYLegendMarkerPrivate &d, QObject *parent = 0); + +//Q_SIGNALS: + +//public Q_SLOTS: + +private: + Q_DECLARE_PRIVATE(QXYLegendMarker) + Q_DISABLE_COPY(QXYLegendMarker) + +}; + +QTCOMMERCIALCHART_END_NAMESPACE + +#endif // QXYLEGENDMARKER_H diff --git a/src/legend/qxylegendmarker_p.h b/src/legend/qxylegendmarker_p.h new file mode 100644 index 0000000..c4130c3 --- /dev/null +++ b/src/legend/qxylegendmarker_p.h @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** 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 QXYLEGENDMARKER_P_H +#define QXYLEGENDMARKER_P_H + +#include "qchartglobal.h" +#include "qlegendmarker_p.h" +#include "legendmarkeritem_p.h" +#include + +#include + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +class QXYLegendMarker; + +class QXYLegendMarkerPrivate : public QLegendMarkerPrivate +{ + Q_OBJECT +public: + explicit QXYLegendMarkerPrivate(QXYLegendMarker *q, QXYSeries *series, QLegend *legend); + virtual ~QXYLegendMarkerPrivate(); + +public Q_SLOTS: + virtual void updated(); + +private: + QXYLegendMarker *q_ptr; + + QXYSeries* m_series; + + friend class QLegendPrivate; // TODO: Is this needed? + Q_DECLARE_PUBLIC(QXYLegendMarker) +}; + +QTCOMMERCIALCHART_END_NAMESPACE + +#endif // QXYLEGENDMARKER_P_H diff --git a/src/xychart/qxyseries.cpp b/src/xychart/qxyseries.cpp index f015570..d70f9db 100644 --- a/src/xychart/qxyseries.cpp +++ b/src/xychart/qxyseries.cpp @@ -24,6 +24,8 @@ #include "legendmarker_p.h" #include "qvalueaxis.h" +#include "qxylegendmarker.h" + QTCOMMERCIALCHART_BEGIN_NAMESPACE /*! @@ -456,12 +458,9 @@ QList QXYSeriesPrivate::createLegendMarker(QLegend *legend) QList QXYSeriesPrivate::createLegendMarkers(QLegend* legend) { - Q_UNUSED(legend); -// Q_Q(QXYSeries); + Q_Q(QXYSeries); QList list; -// TODO: -// return list << new QXYLegendMarker(q,legend); - return list; + return list << new QXYLegendMarker(q,legend); } void QXYSeriesPrivate::initializeAxis(QAbstractAxis *axis) diff --git a/src/xychart/qxyseries.h b/src/xychart/qxyseries.h index d5b9884..6146772 100644 --- a/src/xychart/qxyseries.h +++ b/src/xychart/qxyseries.h @@ -85,6 +85,7 @@ Q_SIGNALS: private: Q_DECLARE_PRIVATE(QXYSeries) Q_DISABLE_COPY(QXYSeries) + friend class QXYLegendMarkerPrivate; friend class XYLegendMarker; friend class XYChart; };