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