diff --git a/src/legend/legend.pri b/src/legend/legend.pri index 9aea390..8859df4 100644 --- a/src/legend/legend.pri +++ b/src/legend/legend.pri @@ -4,7 +4,8 @@ DEPENDPATH += $$PWD SOURCES += \ $$PWD/qlegend.cpp \ $$PWD/legendmarker.cpp \ - $$PWD/legendlayout.cpp + $$PWD/legendlayout.cpp \ + $$PWD/qlegendmarker.cpp PRIVATE_HEADERS += \ $$PWD/legendmarker_p.h \ @@ -14,4 +15,5 @@ PRIVATE_HEADERS += \ PUBLIC_HEADERS += \ - $$PWD/qlegend.h \ No newline at end of file + $$PWD/qlegend.h \ + $$PWD/qlegendmarker.h diff --git a/src/legend/qlegend.cpp b/src/legend/qlegend.cpp index 7434767..a35fdfc 100644 --- a/src/legend/qlegend.cpp +++ b/src/legend/qlegend.cpp @@ -392,6 +392,14 @@ bool QLegend::isBackgroundVisible() const return d_ptr->m_backgroundVisible; } + +QList QLegend::markers() const +{ + // TODO: name of PIMPL method will change. + return d_ptr->legendMarkers(); +} + + /*! \internal \a event see QGraphicsWidget for details */ diff --git a/src/legend/qlegend.h b/src/legend/qlegend.h index 20de5c0..93aa4b9 100644 --- a/src/legend/qlegend.h +++ b/src/legend/qlegend.h @@ -36,6 +36,7 @@ class QPieSeries; class QAreaSeries; class QChart; class QLegendPrivate; +class QLegendMarker; class QTCOMMERCIALCHART_EXPORT QLegend : public QGraphicsWidget { @@ -83,6 +84,9 @@ public: void setBackgroundVisible(bool visible = true); bool isBackgroundVisible() const; + // New stuff: + QList markers() const; + protected: void hideEvent(QHideEvent *event); void showEvent(QShowEvent *event); diff --git a/src/legend/qlegend_p.h b/src/legend/qlegend_p.h index 4250644..35d6893 100644 --- a/src/legend/qlegend_p.h +++ b/src/legend/qlegend_p.h @@ -52,8 +52,11 @@ public: QPointF offset() const; int roundness(qreal size); - QList markers() { return m_markers; } - QGraphicsItemGroup *items() { return m_items; } + QList markers() { return m_markers; } // TODO: this will be removed + QGraphicsItemGroup* items() { return m_items; } + + // New stuff: + QList legendMarkers() { return m_legendMarkers; } // TODO: function name will change public Q_SLOTS: void handleSeriesAdded(QAbstractSeries *series, Domain *domain); @@ -65,9 +68,9 @@ private: QLegend *q_ptr; ChartPresenter *m_presenter; LegendLayout *m_layout; - QChart *m_chart; - QGraphicsItemGroup *m_items; - QList m_markers; + QChart* m_chart; + QGraphicsItemGroup* m_items; + QList m_markers; // TODO: this will be removed Qt::Alignment m_alignment; QBrush m_brush; QPen m_pen; @@ -80,6 +83,8 @@ private: friend class QLegend; friend class LegendLayout; + QList m_legendMarkers; // TODO: rename to m_markers eventually. + }; QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/legend/qlegendmarker.cpp b/src/legend/qlegendmarker.cpp new file mode 100644 index 0000000..d3a9fc1 --- /dev/null +++ b/src/legend/qlegendmarker.cpp @@ -0,0 +1,80 @@ +/**************************************************************************** + ** + ** 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 "qlegendmarker.h" +//#include "qlegendmarker_p.h" +#include + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +QLegendMarker::QLegendMarker(QObject *parent) : + QObject(parent)//, +// d_ptr(new QLegendMarkerPrivate(this)) +{ +} + +QLegendMarker::~QLegendMarker() +{ +} + +QString QLegendMarker::label() const +{ + return m_label; +} + +void QLegendMarker::setLabel(const QString &label) +{ + m_label = label; +} + +QPen QLegendMarker::pen() const +{ + return m_pen; +} + +void QLegendMarker::setPen(const QPen &pen) +{ + m_pen = pen; +} + +QBrush QLegendMarker::brush() const +{ + return m_brush; +} + +void QLegendMarker::setBrush(const QBrush &brush) +{ + m_brush = brush; +} + +bool QLegendMarker::isVisible() const +{ + return m_visible; +} + +void QLegendMarker::setVisible(bool visible) +{ + m_visible = visible; +} + +#include "moc_qlegendmarker.cpp" +//#include "moc_qlegendmarker_p.cpp" + +QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/legend/qlegendmarker.h b/src/legend/qlegendmarker.h new file mode 100644 index 0000000..43d22fe --- /dev/null +++ b/src/legend/qlegendmarker.h @@ -0,0 +1,81 @@ +/**************************************************************************** + ** + ** 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 QLEGENDMARKER_H +#define QLEGENDMARKER_H + +#include +#include +#include +#include + +QTCOMMERCIALCHART_BEGIN_NAMESPACE + +// TODO: +//class QLegendMarkerPrivate; + +// TODO: should this be abstract? +class QTCOMMERCIALCHART_EXPORT QLegendMarker : public QObject +{ + Q_OBJECT + +// TODO: need for these? +// Q_PROPERTY(QString label READ label WRITE setlabel NOTIFY labelChanged); +// Q_PROPERTY(QPen pen READ pen WRITE setPen NOTIFY penChanged); +// Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged); + +public: + explicit QLegendMarker(QObject *parent = 0); + virtual ~QLegendMarker(); + + QString label() const; + void setLabel(const QString &label); + + QPen pen() const; + void setPen(const QPen &pen); + + QBrush brush() const; + void setBrush(const QBrush &brush); + + bool isVisible() const; + void setVisible(bool visible); + +Q_SIGNALS: + void clicked(); + void hovered(bool status); + +public Q_SLOTS: + void markersUpdated(); // TODO: private? Idea is that series signals, when for example pieslices have been added/removed. + +public: +// TODO: +// QScopedPointer d_ptr; + Q_DISABLE_COPY(QLegendMarker) + +// TODO: move to PIMPL + QString m_label; + QPen m_pen; + QBrush m_brush; + bool m_visible; +}; + +QTCOMMERCIALCHART_END_NAMESPACE + +#endif // QLEGENDMARKER_H