| 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/QPieLegendMarker> |
| 31 | #include <private/qpielegendmarker_p.h> |
| 32 | #include <QtCharts/QPieSeries> |
| 33 | #include <QtCharts/QPieSlice> |
| 34 | |
| 35 | QT_CHARTS_BEGIN_NAMESPACE |
| 36 | |
| 37 | /*! |
| 38 | \class QPieLegendMarker |
| 39 | \inmodule QtCharts |
| 40 | \brief The QPieLegendMarker class is a legend marker for a pie series. |
| 41 | |
| 42 | A pie legend marker is related to QPieSeries. With a pie series, each slice of the pie |
| 43 | is related to one marker in the legend. |
| 44 | |
| 45 | \sa QLegend, QPieSeries, QPieSlice |
| 46 | */ |
| 47 | |
| 48 | /*! |
| 49 | \fn virtual LegendMarkerType QPieLegendMarker::type() |
| 50 | \reimp |
| 51 | */ |
| 52 | |
| 53 | /*! |
| 54 | \internal |
| 55 | */ |
| 56 | QPieLegendMarker::QPieLegendMarker(QPieSeries *series, QPieSlice *slice, QLegend *legend, QObject *parent) : |
| 57 | QLegendMarker(*new QPieLegendMarkerPrivate(this,series,slice,legend), parent) |
| 58 | { |
| 59 | d_ptr->updated(); |
| 60 | } |
| 61 | |
| 62 | /*! |
| 63 | Removes the legend marker for a pie series. |
| 64 | */ |
| 65 | QPieLegendMarker::~QPieLegendMarker() |
| 66 | { |
| 67 | } |
| 68 | |
| 69 | /*! |
| 70 | \internal |
| 71 | */ |
| 72 | QPieLegendMarker::QPieLegendMarker(QPieLegendMarkerPrivate &d, QObject *parent) : |
| 73 | QLegendMarker(d, parent) |
| 74 | { |
| 75 | } |
| 76 | |
| 77 | /*! |
| 78 | \reimp |
| 79 | */ |
| 80 | QPieSeries* QPieLegendMarker::series() |
| 81 | { |
| 82 | Q_D(QPieLegendMarker); |
| 83 | return d->m_series; |
| 84 | } |
| 85 | |
| 86 | /*! |
| 87 | Returns the slice of the pie related to the marker. |
| 88 | */ |
| 89 | QPieSlice* QPieLegendMarker::slice() |
| 90 | { |
| 91 | Q_D(QPieLegendMarker); |
| 92 | return d->m_slice; |
| 93 | } |
| 94 | |
| 95 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 96 | |
| 97 | QPieLegendMarkerPrivate::QPieLegendMarkerPrivate(QPieLegendMarker *q, QPieSeries *series, QPieSlice *slice, QLegend *legend) : |
| 98 | QLegendMarkerPrivate(q,legend), |
| 99 | q_ptr(q), |
| 100 | m_series(series), |
| 101 | m_slice(slice) |
| 102 | { |
| 103 | QObject::connect(sender: m_slice, SIGNAL(labelChanged()), receiver: this, SLOT(updated())); |
| 104 | QObject::connect(sender: m_slice, SIGNAL(brushChanged()), receiver: this, SLOT(updated())); |
| 105 | QObject::connect(sender: m_slice, SIGNAL(penChanged()), receiver: this, SLOT(updated())); |
| 106 | } |
| 107 | |
| 108 | QPieLegendMarkerPrivate::~QPieLegendMarkerPrivate() |
| 109 | { |
| 110 | } |
| 111 | |
| 112 | QPieSeries* QPieLegendMarkerPrivate::series() |
| 113 | { |
| 114 | return m_series; |
| 115 | } |
| 116 | |
| 117 | QObject* QPieLegendMarkerPrivate::relatedObject() |
| 118 | { |
| 119 | return m_slice; |
| 120 | } |
| 121 | |
| 122 | void QPieLegendMarkerPrivate::updated() |
| 123 | { |
| 124 | bool labelChanged = false; |
| 125 | bool brushChanged = false; |
| 126 | bool penChanged = false; |
| 127 | |
| 128 | if (!m_customPen && (m_item->pen() != m_slice->pen())) { |
| 129 | m_item->setPen(m_slice->pen()); |
| 130 | penChanged = true; |
| 131 | } |
| 132 | if (!m_customBrush && (m_item->brush() != m_slice->brush())) { |
| 133 | m_item->setBrush(m_slice->brush()); |
| 134 | brushChanged = true; |
| 135 | } |
| 136 | if (!m_customLabel && (m_item->label() != m_slice->label())) { |
| 137 | m_item->setLabel(m_slice->label()); |
| 138 | labelChanged = true; |
| 139 | } |
| 140 | invalidateLegend(); |
| 141 | |
| 142 | if (labelChanged) |
| 143 | emit q_ptr->labelChanged(); |
| 144 | if (brushChanged) |
| 145 | emit q_ptr->brushChanged(); |
| 146 | if (penChanged) |
| 147 | emit q_ptr->penChanged(); |
| 148 | } |
| 149 | |
| 150 | QT_CHARTS_END_NAMESPACE |
| 151 | |
| 152 | #include "moc_qpielegendmarker.cpp" |
| 153 | #include "moc_qpielegendmarker_p.cpp" |
| 154 | |