| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #include <QtCharts/QBarLegendMarker> |
| 5 | #include <private/qbarlegendmarker_p.h> |
| 6 | #include <QtCharts/QAbstractBarSeries> |
| 7 | #include <QtCharts/QBarSet> |
| 8 | |
| 9 | QT_BEGIN_NAMESPACE |
| 10 | |
| 11 | /*! |
| 12 | \class QBarLegendMarker |
| 13 | \inmodule QtCharts |
| 14 | \brief The QBarLegendMarker class is a legend marker for a bar series. |
| 15 | |
| 16 | A bar legend marker is related to QAbstractBarSeries derived classes. With a bar series, |
| 17 | each marker is related to one QBarSet. |
| 18 | |
| 19 | \sa QLegend, QAbstractBarSeries, QBarSet |
| 20 | */ |
| 21 | |
| 22 | /*! |
| 23 | \fn virtual LegendMarkerType QBarLegendMarker::type() |
| 24 | \reimp |
| 25 | */ |
| 26 | |
| 27 | /*! |
| 28 | \internal |
| 29 | Constructor |
| 30 | */ |
| 31 | QBarLegendMarker::QBarLegendMarker(QAbstractBarSeries *series, QBarSet *barset, QLegend *legend, QObject *parent) : |
| 32 | QLegendMarker(*new QBarLegendMarkerPrivate(this,series,barset,legend), parent) |
| 33 | { |
| 34 | d_ptr->updated(); |
| 35 | } |
| 36 | |
| 37 | /*! |
| 38 | Removes the legend marker for a bar set. |
| 39 | */ |
| 40 | QBarLegendMarker::~QBarLegendMarker() |
| 41 | { |
| 42 | } |
| 43 | |
| 44 | /*! |
| 45 | \internal |
| 46 | */ |
| 47 | QBarLegendMarker::QBarLegendMarker(QBarLegendMarkerPrivate &d, QObject *parent) : |
| 48 | QLegendMarker(d, parent) |
| 49 | { |
| 50 | } |
| 51 | |
| 52 | /*! |
| 53 | \reimp |
| 54 | */ |
| 55 | QAbstractBarSeries *QBarLegendMarker::series() |
| 56 | { |
| 57 | Q_D(QBarLegendMarker); |
| 58 | return d->m_series; |
| 59 | } |
| 60 | |
| 61 | /*! |
| 62 | Returns the bar set related to the marker. |
| 63 | */ |
| 64 | QBarSet* QBarLegendMarker::barset() |
| 65 | { |
| 66 | Q_D(QBarLegendMarker); |
| 67 | return d->m_barset; |
| 68 | } |
| 69 | |
| 70 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 71 | |
| 72 | QBarLegendMarkerPrivate::QBarLegendMarkerPrivate(QBarLegendMarker *q, QAbstractBarSeries *series, QBarSet *barset, QLegend *legend) : |
| 73 | QLegendMarkerPrivate(q,legend), |
| 74 | q_ptr(q), |
| 75 | m_series(series), |
| 76 | m_barset(barset) |
| 77 | { |
| 78 | QObject::connect(sender: m_barset, SIGNAL(penChanged()), receiver: this, SLOT(updated())); |
| 79 | QObject::connect(sender: m_barset, SIGNAL(labelChanged()), receiver: this, SLOT(updated())); |
| 80 | QObject::connect(sender: m_barset, SIGNAL(brushChanged()), receiver: this, SLOT(updated())); |
| 81 | } |
| 82 | |
| 83 | QBarLegendMarkerPrivate::~QBarLegendMarkerPrivate() |
| 84 | { |
| 85 | } |
| 86 | |
| 87 | QAbstractBarSeries* QBarLegendMarkerPrivate::series() |
| 88 | { |
| 89 | return m_series; |
| 90 | } |
| 91 | |
| 92 | QObject* QBarLegendMarkerPrivate::relatedObject() |
| 93 | { |
| 94 | return m_barset; |
| 95 | } |
| 96 | |
| 97 | void QBarLegendMarkerPrivate::updated() |
| 98 | { |
| 99 | bool labelChanged = false; |
| 100 | bool brushChanged = false; |
| 101 | bool penChanged = false; |
| 102 | |
| 103 | if (!m_customPen && (m_item->pen() != m_barset->pen())) { |
| 104 | m_item->setPen(m_barset->pen()); |
| 105 | penChanged = true; |
| 106 | } |
| 107 | if (!m_customBrush && (m_item->brush() != m_barset->brush())) { |
| 108 | m_item->setBrush(m_barset->brush()); |
| 109 | brushChanged = true; |
| 110 | } |
| 111 | if (!m_customLabel && (m_item->label() != m_barset->label())) { |
| 112 | m_item->setLabel(m_barset->label()); |
| 113 | labelChanged = true; |
| 114 | } |
| 115 | invalidateLegend(); |
| 116 | |
| 117 | if (labelChanged) |
| 118 | emit q_ptr->labelChanged(); |
| 119 | if (brushChanged) |
| 120 | emit q_ptr->brushChanged(); |
| 121 | if (penChanged) |
| 122 | emit q_ptr->penChanged(); |
| 123 | } |
| 124 | |
| 125 | QT_END_NAMESPACE |
| 126 | |
| 127 | #include "moc_qbarlegendmarker.cpp" |
| 128 | #include "moc_qbarlegendmarker_p.cpp" |
| 129 | |