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

source code of qtcharts/src/charts/legend/qpielegendmarker.cpp