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/QAreaLegendMarker>
31#include <private/qarealegendmarker_p.h>
32#include <private/qareaseries_p.h>
33#include <QtCharts/QAreaSeries>
34
35QT_CHARTS_BEGIN_NAMESPACE
36
37/*!
38 \class QAreaLegendMarker
39 \inmodule QtCharts
40 \brief The QAreaLegendMarker class is a legend marker for an area series.
41
42 An area legend marker is related to a QAreaSeries object, so that one area series
43 results in one marker.
44
45 \sa QLegend, QAreaSeries
46*/
47
48/*!
49 \fn virtual LegendMarkerType QAreaLegendMarker::type()
50 \reimp
51*/
52
53/*!
54 \internal
55*/
56QAreaLegendMarker::QAreaLegendMarker(QAreaSeries *series, QLegend *legend, QObject *parent) :
57 QLegendMarker(*new QAreaLegendMarkerPrivate(this,series,legend), parent)
58{
59 d_ptr->updated();
60}
61
62/*!
63 Removes the legend marker for an area series.
64*/
65QAreaLegendMarker::~QAreaLegendMarker()
66{
67}
68
69/*!
70 \internal
71*/
72QAreaLegendMarker::QAreaLegendMarker(QAreaLegendMarkerPrivate &d, QObject *parent) :
73 QLegendMarker(d, parent)
74{
75}
76
77/*!
78 \reimp
79*/
80QAreaSeries* QAreaLegendMarker::series()
81{
82 Q_D(QAreaLegendMarker);
83 return d->m_series;
84}
85
86////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
87
88QAreaLegendMarkerPrivate::QAreaLegendMarkerPrivate(QAreaLegendMarker *q, QAreaSeries *series, QLegend *legend) :
89 QLegendMarkerPrivate(q,legend),
90 q_ptr(q),
91 m_series(series)
92{
93 QObject::connect(sender: m_series->d_func(),SIGNAL(updated()), receiver: this, SLOT(updated()));
94 QObject::connect(sender: m_series, SIGNAL(nameChanged()), receiver: this, SLOT(updated()));
95}
96
97QAreaLegendMarkerPrivate::~QAreaLegendMarkerPrivate()
98{
99}
100
101QAreaSeries* QAreaLegendMarkerPrivate::series()
102{
103 return m_series;
104}
105
106QObject* QAreaLegendMarkerPrivate::relatedObject()
107{
108 return m_series;
109}
110
111void QAreaLegendMarkerPrivate::updated()
112{
113 bool labelChanged = false;
114 bool brushChanged = false;
115
116 if (!m_customBrush && (m_item->brush() != m_series->brush())) {
117 m_item->setBrush(m_series->brush());
118 brushChanged = true;
119 }
120 if (!m_customLabel && (m_item->label() != m_series->name())) {
121 m_item->setLabel(m_series->name());
122 labelChanged = true;
123 }
124 invalidateLegend();
125
126 if (labelChanged)
127 emit q_ptr->labelChanged();
128 if (brushChanged)
129 emit q_ptr->brushChanged();
130}
131
132QT_CHARTS_END_NAMESPACE
133
134#include "moc_qarealegendmarker.cpp"
135#include "moc_qarealegendmarker_p.cpp"
136

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