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