| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #include <QtCharts/QCandlestickLegendMarker> |
| 5 | #include <private/legendmarkeritem_p.h> |
| 6 | #include <private/qcandlesticklegendmarker_p.h> |
| 7 | #include <private/qcandlestickseries_p.h> |
| 8 | |
| 9 | QT_BEGIN_NAMESPACE |
| 10 | |
| 11 | /*! |
| 12 | \class QCandlestickLegendMarker |
| 13 | \inmodule QtCharts |
| 14 | \since 5.8 |
| 15 | \brief The QCandlestickLegendMarker class is a legend marker for a candlestick series. |
| 16 | |
| 17 | QCandlestickLegendMarker is related to QCandlestickSeries, so that one candlestick series |
| 18 | results in one marker. |
| 19 | |
| 20 | \sa QLegend, QCandlestickSeries |
| 21 | */ |
| 22 | |
| 23 | /*! |
| 24 | \internal |
| 25 | */ |
| 26 | QCandlestickLegendMarker::QCandlestickLegendMarker(QCandlestickSeries *series, QLegend *legend, |
| 27 | QObject *parent) |
| 28 | : QLegendMarker(*new QCandlestickLegendMarkerPrivate(this, series, legend), parent) |
| 29 | { |
| 30 | Q_D(QCandlestickLegendMarker); |
| 31 | |
| 32 | d->updated(); |
| 33 | } |
| 34 | |
| 35 | QCandlestickLegendMarker::~QCandlestickLegendMarker() |
| 36 | { |
| 37 | } |
| 38 | |
| 39 | /*! |
| 40 | \reimp |
| 41 | */ |
| 42 | QLegendMarker::LegendMarkerType QCandlestickLegendMarker::type() |
| 43 | { |
| 44 | return LegendMarkerTypeCandlestick; |
| 45 | } |
| 46 | |
| 47 | /*! |
| 48 | \reimp |
| 49 | */ |
| 50 | QCandlestickSeries* QCandlestickLegendMarker::series() |
| 51 | { |
| 52 | Q_D(QCandlestickLegendMarker); |
| 53 | |
| 54 | return d->m_series; |
| 55 | } |
| 56 | |
| 57 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 58 | |
| 59 | QCandlestickLegendMarkerPrivate::QCandlestickLegendMarkerPrivate(QCandlestickLegendMarker *q, |
| 60 | QCandlestickSeries *series, |
| 61 | QLegend *legend) |
| 62 | : QLegendMarkerPrivate(q, legend), |
| 63 | q_ptr(q), |
| 64 | m_series(series) |
| 65 | { |
| 66 | QObject::connect(sender: m_item, SIGNAL(markerRectChanged()), receiver: this, SLOT(updated())); |
| 67 | QObject::connect(sender: m_series, SIGNAL(nameChanged()), receiver: this, SLOT(updated())); |
| 68 | QObject::connect(sender: m_series->d_func(), SIGNAL(updated()), receiver: this, SLOT(updated())); |
| 69 | } |
| 70 | |
| 71 | QCandlestickLegendMarkerPrivate::~QCandlestickLegendMarkerPrivate() |
| 72 | { |
| 73 | } |
| 74 | |
| 75 | QAbstractSeries* QCandlestickLegendMarkerPrivate::series() |
| 76 | { |
| 77 | return m_series; |
| 78 | } |
| 79 | |
| 80 | QObject* QCandlestickLegendMarkerPrivate::relatedObject() |
| 81 | { |
| 82 | return m_series; |
| 83 | } |
| 84 | |
| 85 | void QCandlestickLegendMarkerPrivate::updated() |
| 86 | { |
| 87 | bool labelChanged = false; |
| 88 | bool brushChanged = false; |
| 89 | |
| 90 | if (!m_customLabel && (m_item->label() != m_series->name())) { |
| 91 | m_item->setLabel(m_series->name()); |
| 92 | labelChanged = true; |
| 93 | } |
| 94 | if (!m_customBrush) { |
| 95 | QLinearGradient gradient; |
| 96 | gradient.setStart(x: 0.0, y: 0.0); |
| 97 | gradient.setFinalStop(x: m_item->markerRect().width(), y: m_item->markerRect().height()); |
| 98 | gradient.setColorAt(pos: 0.0, color: m_series->increasingColor()); |
| 99 | gradient.setColorAt(pos: 0.49, color: m_series->increasingColor()); |
| 100 | gradient.setColorAt(pos: 0.50, color: m_series->decreasingColor()); |
| 101 | gradient.setColorAt(pos: 1.0, color: m_series->decreasingColor()); |
| 102 | |
| 103 | QBrush brush(gradient); |
| 104 | if (m_item->brush() != brush) { |
| 105 | m_item->setBrush(brush); |
| 106 | brushChanged = true; |
| 107 | } |
| 108 | } |
| 109 | invalidateLegend(); |
| 110 | |
| 111 | if (labelChanged) |
| 112 | emit q_ptr->labelChanged(); |
| 113 | if (brushChanged) |
| 114 | emit q_ptr->brushChanged(); |
| 115 | } |
| 116 | |
| 117 | QT_END_NAMESPACE |
| 118 | |
| 119 | #include "moc_qcandlesticklegendmarker.cpp" |
| 120 | #include "moc_qcandlesticklegendmarker_p.cpp" |
| 121 | |