| 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/QCandlestickLegendMarker> |
| 31 | #include <private/legendmarkeritem_p.h> |
| 32 | #include <private/qcandlesticklegendmarker_p.h> |
| 33 | #include <private/qcandlestickseries_p.h> |
| 34 | |
| 35 | QT_CHARTS_BEGIN_NAMESPACE |
| 36 | |
| 37 | /*! |
| 38 | \class QCandlestickLegendMarker |
| 39 | \inmodule QtCharts |
| 40 | \since 5.8 |
| 41 | \brief The QCandlestickLegendMarker class is a legend marker for a candlestick series. |
| 42 | |
| 43 | QCandlestickLegendMarker is related to QCandlestickSeries, so that one candlestick series |
| 44 | results in one marker. |
| 45 | |
| 46 | \sa QLegend, QCandlestickSeries |
| 47 | */ |
| 48 | |
| 49 | /*! |
| 50 | \internal |
| 51 | */ |
| 52 | QCandlestickLegendMarker::QCandlestickLegendMarker(QCandlestickSeries *series, QLegend *legend, |
| 53 | QObject *parent) |
| 54 | : QLegendMarker(*new QCandlestickLegendMarkerPrivate(this, series, legend), parent) |
| 55 | { |
| 56 | Q_D(QCandlestickLegendMarker); |
| 57 | |
| 58 | d->updated(); |
| 59 | } |
| 60 | |
| 61 | QCandlestickLegendMarker::~QCandlestickLegendMarker() |
| 62 | { |
| 63 | } |
| 64 | |
| 65 | /*! |
| 66 | \reimp |
| 67 | */ |
| 68 | QLegendMarker::LegendMarkerType QCandlestickLegendMarker::type() |
| 69 | { |
| 70 | return LegendMarkerTypeCandlestick; |
| 71 | } |
| 72 | |
| 73 | /*! |
| 74 | \reimp |
| 75 | */ |
| 76 | QCandlestickSeries* QCandlestickLegendMarker::series() |
| 77 | { |
| 78 | Q_D(QCandlestickLegendMarker); |
| 79 | |
| 80 | return d->m_series; |
| 81 | } |
| 82 | |
| 83 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 84 | |
| 85 | QCandlestickLegendMarkerPrivate::QCandlestickLegendMarkerPrivate(QCandlestickLegendMarker *q, |
| 86 | QCandlestickSeries *series, |
| 87 | QLegend *legend) |
| 88 | : QLegendMarkerPrivate(q, legend), |
| 89 | q_ptr(q), |
| 90 | m_series(series) |
| 91 | { |
| 92 | QObject::connect(sender: m_item, SIGNAL(markerRectChanged()), receiver: this, SLOT(updated())); |
| 93 | QObject::connect(sender: m_series, SIGNAL(nameChanged()), receiver: this, SLOT(updated())); |
| 94 | QObject::connect(sender: m_series->d_func(), SIGNAL(updated()), receiver: this, SLOT(updated())); |
| 95 | } |
| 96 | |
| 97 | QCandlestickLegendMarkerPrivate::~QCandlestickLegendMarkerPrivate() |
| 98 | { |
| 99 | } |
| 100 | |
| 101 | QAbstractSeries* QCandlestickLegendMarkerPrivate::series() |
| 102 | { |
| 103 | return m_series; |
| 104 | } |
| 105 | |
| 106 | QObject* QCandlestickLegendMarkerPrivate::relatedObject() |
| 107 | { |
| 108 | return m_series; |
| 109 | } |
| 110 | |
| 111 | void QCandlestickLegendMarkerPrivate::updated() |
| 112 | { |
| 113 | bool labelChanged = false; |
| 114 | bool brushChanged = false; |
| 115 | |
| 116 | if (!m_customLabel && (m_item->label() != m_series->name())) { |
| 117 | m_item->setLabel(m_series->name()); |
| 118 | labelChanged = true; |
| 119 | } |
| 120 | if (!m_customBrush) { |
| 121 | QLinearGradient gradient; |
| 122 | gradient.setStart(x: 0.0, y: 0.0); |
| 123 | gradient.setFinalStop(x: m_item->markerRect().width(), y: m_item->markerRect().height()); |
| 124 | gradient.setColorAt(pos: 0.0, color: m_series->increasingColor()); |
| 125 | gradient.setColorAt(pos: 0.49, color: m_series->increasingColor()); |
| 126 | gradient.setColorAt(pos: 0.50, color: m_series->decreasingColor()); |
| 127 | gradient.setColorAt(pos: 1.0, color: m_series->decreasingColor()); |
| 128 | |
| 129 | QBrush brush(gradient); |
| 130 | if (m_item->brush() != brush) { |
| 131 | m_item->setBrush(brush); |
| 132 | brushChanged = true; |
| 133 | } |
| 134 | } |
| 135 | invalidateLegend(); |
| 136 | |
| 137 | if (labelChanged) |
| 138 | emit q_ptr->labelChanged(); |
| 139 | if (brushChanged) |
| 140 | emit q_ptr->brushChanged(); |
| 141 | } |
| 142 | |
| 143 | QT_CHARTS_END_NAMESPACE |
| 144 | |
| 145 | #include "moc_qcandlesticklegendmarker.cpp" |
| 146 | #include "moc_qcandlesticklegendmarker_p.cpp" |
| 147 | |