1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #include <QtCharts/QAreaLegendMarker> |
5 | #include <private/qarealegendmarker_p.h> |
6 | #include <private/qareaseries_p.h> |
7 | #include <QtCharts/QAreaSeries> |
8 | |
9 | QT_BEGIN_NAMESPACE |
10 | |
11 | /*! |
12 | \class QAreaLegendMarker |
13 | \inmodule QtCharts |
14 | \brief The QAreaLegendMarker class is a legend marker for an area series. |
15 | |
16 | An area legend marker is related to a QAreaSeries object, so that one area series |
17 | results in one marker. |
18 | |
19 | \sa QLegend, QAreaSeries |
20 | */ |
21 | |
22 | /*! |
23 | \fn virtual LegendMarkerType QAreaLegendMarker::type() |
24 | \reimp |
25 | */ |
26 | |
27 | /*! |
28 | \internal |
29 | */ |
30 | QAreaLegendMarker::QAreaLegendMarker(QAreaSeries *series, QLegend *legend, QObject *parent) : |
31 | QLegendMarker(*new QAreaLegendMarkerPrivate(this,series,legend), parent) |
32 | { |
33 | d_ptr->updated(); |
34 | } |
35 | |
36 | /*! |
37 | Removes the legend marker for an area series. |
38 | */ |
39 | QAreaLegendMarker::~QAreaLegendMarker() |
40 | { |
41 | } |
42 | |
43 | /*! |
44 | \internal |
45 | */ |
46 | QAreaLegendMarker::QAreaLegendMarker(QAreaLegendMarkerPrivate &d, QObject *parent) : |
47 | QLegendMarker(d, parent) |
48 | { |
49 | } |
50 | |
51 | /*! |
52 | \reimp |
53 | */ |
54 | QAreaSeries* QAreaLegendMarker::series() |
55 | { |
56 | Q_D(QAreaLegendMarker); |
57 | return d->m_series; |
58 | } |
59 | |
60 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
61 | |
62 | QAreaLegendMarkerPrivate::QAreaLegendMarkerPrivate(QAreaLegendMarker *q, QAreaSeries *series, QLegend *legend) : |
63 | QLegendMarkerPrivate(q,legend), |
64 | q_ptr(q), |
65 | m_series(series) |
66 | { |
67 | QObject::connect(sender: m_series->d_func(),SIGNAL(updated()), receiver: this, SLOT(updated())); |
68 | QObject::connect(sender: m_series, SIGNAL(nameChanged()), receiver: this, SLOT(updated())); |
69 | } |
70 | |
71 | QAreaLegendMarkerPrivate::~QAreaLegendMarkerPrivate() |
72 | { |
73 | } |
74 | |
75 | QAreaSeries* QAreaLegendMarkerPrivate::series() |
76 | { |
77 | return m_series; |
78 | } |
79 | |
80 | QObject* QAreaLegendMarkerPrivate::relatedObject() |
81 | { |
82 | return m_series; |
83 | } |
84 | |
85 | void QAreaLegendMarkerPrivate::updated() |
86 | { |
87 | bool labelChanged = false; |
88 | bool brushChanged = false; |
89 | |
90 | if (!m_customBrush && (m_item->brush() != m_series->brush())) { |
91 | m_item->setBrush(m_series->brush()); |
92 | brushChanged = true; |
93 | } |
94 | if (!m_customLabel && (m_item->label() != m_series->name())) { |
95 | m_item->setLabel(m_series->name()); |
96 | labelChanged = true; |
97 | } |
98 | invalidateLegend(); |
99 | |
100 | if (labelChanged) |
101 | emit q_ptr->labelChanged(); |
102 | if (brushChanged) |
103 | emit q_ptr->brushChanged(); |
104 | } |
105 | |
106 | QT_END_NAMESPACE |
107 | |
108 | #include "moc_qarealegendmarker.cpp" |
109 | #include "moc_qarealegendmarker_p.cpp" |
110 | |