| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:GPL$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU |
| 19 | ** General Public License version 3 or (at your option) any later version |
| 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
| 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
| 22 | ** included in the packaging of this file. Please review the following |
| 23 | ** information to ensure the GNU General Public License requirements will |
| 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
| 25 | ** |
| 26 | ** $QT_END_LICENSE$ |
| 27 | ** |
| 28 | ****************************************************************************/ |
| 29 | |
| 30 | #include <QtCharts/QBoxPlotLegendMarker> |
| 31 | #include <private/qboxplotlegendmarker_p.h> |
| 32 | #include <QtCharts/QBoxPlotSeries> |
| 33 | #include <private/qboxplotseries_p.h> |
| 34 | |
| 35 | QT_CHARTS_BEGIN_NAMESPACE |
| 36 | |
| 37 | /*! |
| 38 | \class QBoxPlotLegendMarker |
| 39 | \inmodule QtCharts |
| 40 | \brief The QBoxPlotLegendMarker class is a legend marker for a box plot series. |
| 41 | |
| 42 | A box plot legend marker is related to a QBoxPlotSeries object. |
| 43 | |
| 44 | \sa QLegend, QBoxPlotSeries |
| 45 | */ |
| 46 | |
| 47 | /*! |
| 48 | \fn virtual LegendMarkerType QBoxPlotLegendMarker::type() |
| 49 | \reimp |
| 50 | */ |
| 51 | |
| 52 | /*! |
| 53 | \internal |
| 54 | */ |
| 55 | QBoxPlotLegendMarker::QBoxPlotLegendMarker(QBoxPlotSeries *series, QLegend *legend, QObject *parent) : |
| 56 | QLegendMarker(*new QBoxPlotLegendMarkerPrivate(this,series,legend), parent) |
| 57 | { |
| 58 | d_ptr->updated(); |
| 59 | } |
| 60 | |
| 61 | /*! |
| 62 | Removes the legend marker for a box plot series. |
| 63 | */ |
| 64 | QBoxPlotLegendMarker::~QBoxPlotLegendMarker() |
| 65 | { |
| 66 | } |
| 67 | |
| 68 | /*! |
| 69 | \internal |
| 70 | */ |
| 71 | QBoxPlotLegendMarker::QBoxPlotLegendMarker(QBoxPlotLegendMarkerPrivate &d, QObject *parent) : |
| 72 | QLegendMarker(d, parent) |
| 73 | { |
| 74 | } |
| 75 | |
| 76 | /*! |
| 77 | \reimp |
| 78 | */ |
| 79 | QBoxPlotSeries* QBoxPlotLegendMarker::series() |
| 80 | { |
| 81 | Q_D(QBoxPlotLegendMarker); |
| 82 | return d->m_series; |
| 83 | } |
| 84 | |
| 85 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 86 | |
| 87 | QBoxPlotLegendMarkerPrivate::QBoxPlotLegendMarkerPrivate(QBoxPlotLegendMarker *q, QBoxPlotSeries *series, QLegend *legend) : |
| 88 | QLegendMarkerPrivate(q,legend), |
| 89 | q_ptr(q), |
| 90 | m_series(series) |
| 91 | { |
| 92 | QObject::connect(sender: m_series, SIGNAL(nameChanged()), receiver: this, SLOT(updated())); |
| 93 | QObject::connect(sender: m_series->d_func(), SIGNAL(updated()), receiver: this, SLOT(updated())); |
| 94 | } |
| 95 | |
| 96 | QBoxPlotLegendMarkerPrivate::~QBoxPlotLegendMarkerPrivate() |
| 97 | { |
| 98 | } |
| 99 | |
| 100 | QAbstractSeries* QBoxPlotLegendMarkerPrivate::series() |
| 101 | { |
| 102 | return m_series; |
| 103 | } |
| 104 | |
| 105 | QObject* QBoxPlotLegendMarkerPrivate::relatedObject() |
| 106 | { |
| 107 | return m_series; |
| 108 | } |
| 109 | |
| 110 | void QBoxPlotLegendMarkerPrivate::updated() |
| 111 | { |
| 112 | bool labelChanged = false; |
| 113 | bool brushChanged = false; |
| 114 | |
| 115 | if (!m_customLabel && (m_item->label() != m_series->name())) { |
| 116 | m_item->setLabel(m_series->name()); |
| 117 | labelChanged = true; |
| 118 | } |
| 119 | if (!m_customBrush && (m_item->brush() != m_series->brush())) { |
| 120 | m_item->setBrush(m_series->brush()); |
| 121 | brushChanged = true; |
| 122 | } |
| 123 | invalidateLegend(); |
| 124 | |
| 125 | if (labelChanged) |
| 126 | emit q_ptr->labelChanged(); |
| 127 | if (brushChanged) |
| 128 | emit q_ptr->brushChanged(); |
| 129 | } |
| 130 | |
| 131 | QT_CHARTS_END_NAMESPACE |
| 132 | |
| 133 | #include "moc_qboxplotlegendmarker.cpp" |
| 134 | #include "moc_qboxplotlegendmarker_p.cpp" |
| 135 | |