summaryrefslogtreecommitdiffstats
path: root/src/charts/legend
diff options
context:
space:
mode:
authorAlexander Mishin <apmishin@yandex.com>2016-02-09 21:49:53 +0300
committerMiikka Heikkinen <miikka.heikkinen@qt.io>2016-05-25 11:47:43 +0000
commitfacc2941efbfb8c9f40e363f0ea881653f6b4393 (patch)
treeae5ef712e4abbe47d60704fd0978f7533c7edbdd /src/charts/legend
parente9a2e2a5e9c023c872e39e39fb2a8b0a31820577 (diff)
Added candlestick chart type
- added QCandlestickSeries - added QCandlestickSet - added QCandlestickLegendMarker - added model mappers - added Candlestick, CandlestickChartItem, CandlestickData - added SeriesTypeCandlestick to SeriesType enum - added LegendMarkerTypeCandlestick to LegendMarkerType enum - added candlestick chart example - added QML candlestick chart example - added candlestick tester - added autotests - added documentation [ChangeLog][CandlestickChart] Added new chart type: Candlestick Chart. Task-number: QTBUG-50544 Change-Id: I17d18dfa23e0ea209bf51ab1e349585b9cb50a8f Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Diffstat (limited to 'src/charts/legend')
-rw-r--r--src/charts/legend/legend.pri14
-rw-r--r--src/charts/legend/legendmarkeritem.cpp13
-rw-r--r--src/charts/legend/legendmarkeritem_p.h9
-rw-r--r--src/charts/legend/qcandlesticklegendmarker.cpp125
-rw-r--r--src/charts/legend/qcandlesticklegendmarker.h61
-rw-r--r--src/charts/legend/qcandlesticklegendmarker_p.h72
-rw-r--r--src/charts/legend/qlegendmarker.cpp1
-rw-r--r--src/charts/legend/qlegendmarker.h3
8 files changed, 288 insertions, 10 deletions
diff --git a/src/charts/legend/legend.pri b/src/charts/legend/legend.pri
index c14cf6b0..5fcb53c7 100644
--- a/src/charts/legend/legend.pri
+++ b/src/charts/legend/legend.pri
@@ -11,8 +11,9 @@ SOURCES += \
$$PWD/qxylegendmarker.cpp \
$$PWD/qarealegendmarker.cpp \
$$PWD/legendscroller.cpp \
- $$PWD/qboxplotlegendmarker.cpp
-
+ $$PWD/qboxplotlegendmarker.cpp \
+ $$PWD/qcandlesticklegendmarker.cpp
+
PRIVATE_HEADERS += \
$$PWD/legendscroller_p.h \
$$PWD/qlegend_p.h \
@@ -23,9 +24,9 @@ PRIVATE_HEADERS += \
$$PWD/qbarlegendmarker_p.h \
$$PWD/qxylegendmarker_p.h \
$$PWD/qarealegendmarker_p.h \
- $$PWD/qboxplotlegendmarker_p.h
-
-
+ $$PWD/qboxplotlegendmarker_p.h \
+ $$PWD/qcandlesticklegendmarker_p.h
+
PUBLIC_HEADERS += \
$$PWD/qlegend.h \
$$PWD/qlegendmarker.h \
@@ -33,4 +34,5 @@ PUBLIC_HEADERS += \
$$PWD/qbarlegendmarker.h \
$$PWD/qxylegendmarker.h \
$$PWD/qarealegendmarker.h \
- $$PWD/qboxplotlegendmarker.h
+ $$PWD/qboxplotlegendmarker.h \
+ $$PWD/qcandlesticklegendmarker.h
diff --git a/src/charts/legend/legendmarkeritem.cpp b/src/charts/legend/legendmarkeritem.cpp
index 125199ea..1c0b5901 100644
--- a/src/charts/legend/legendmarkeritem.cpp
+++ b/src/charts/legend/legendmarkeritem.cpp
@@ -88,8 +88,14 @@ QBrush LegendMarkerItem::brush() const
void LegendMarkerItem::setFont(const QFont &font)
{
m_textItem->setFont(font);
+
QFontMetrics fn(font);
- m_markerRect = QRectF(0,0,fn.height()/2,fn.height()/2);
+ QRectF markerRect = QRectF(0, 0, fn.height() / 2, fn.height() / 2);
+ if (m_markerRect != markerRect) {
+ m_markerRect = markerRect;
+ emit markerRectChanged();
+ }
+
updateGeometry();
}
@@ -152,6 +158,11 @@ QRectF LegendMarkerItem::boundingRect() const
return m_boundingRect;
}
+QRectF LegendMarkerItem::markerRect() const
+{
+ return m_markerRect;
+}
+
void LegendMarkerItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(option)
diff --git a/src/charts/legend/legendmarkeritem_p.h b/src/charts/legend/legendmarkeritem_p.h
index 870cfb2e..c3371742 100644
--- a/src/charts/legend/legendmarkeritem_p.h
+++ b/src/charts/legend/legendmarkeritem_p.h
@@ -56,7 +56,7 @@ class LegendMarkerItem : public QGraphicsObject, public QGraphicsLayoutItem
Q_OBJECT
Q_INTERFACES(QGraphicsLayoutItem)
public:
- explicit LegendMarkerItem(QLegendMarkerPrivate *marker, QGraphicsObject *parent = 0);
+ explicit LegendMarkerItem(QLegendMarkerPrivate *marker, QGraphicsObject *parent = nullptr);
~LegendMarkerItem();
void setPen(const QPen &pen);
@@ -76,8 +76,9 @@ public:
void setGeometry(const QRectF &rect);
QRectF boundingRect() const;
+ QRectF markerRect() const;
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,QWidget *widget = nullptr);
QSizeF sizeHint (Qt::SizeHint which, const QSizeF &constraint) const;
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
@@ -85,6 +86,10 @@ public:
QString displayedLabel() const;
void setToolTip(const QString &tooltip);
+
+Q_SIGNALS:
+ void markerRectChanged();
+
protected:
QLegendMarkerPrivate *m_marker; // Knows
QRectF m_markerRect;
diff --git a/src/charts/legend/qcandlesticklegendmarker.cpp b/src/charts/legend/qcandlesticklegendmarker.cpp
new file mode 100644
index 00000000..97208e3c
--- /dev/null
+++ b/src/charts/legend/qcandlesticklegendmarker.cpp
@@ -0,0 +1,125 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt Charts module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 or (at your option) any later version
+** approved by the KDE Free Qt Foundation. The licenses are as published by
+** the Free Software Foundation and appearing in the file LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtCharts/QCandlestickLegendMarker>
+#include <private/legendmarkeritem_p.h>
+#include <private/qcandlesticklegendmarker_p.h>
+#include <private/qcandlestickseries_p.h>
+
+QT_CHARTS_BEGIN_NAMESPACE
+
+QCandlestickLegendMarker::QCandlestickLegendMarker(QCandlestickSeries *series, QLegend *legend,
+ QObject *parent)
+ : QLegendMarker(*new QCandlestickLegendMarkerPrivate(this, series, legend), parent)
+{
+ Q_D(QCandlestickLegendMarker);
+
+ d->updated();
+}
+
+QCandlestickLegendMarker::~QCandlestickLegendMarker()
+{
+}
+
+QLegendMarker::LegendMarkerType QCandlestickLegendMarker::type()
+{
+ return LegendMarkerTypeCandlestick;
+}
+
+QCandlestickSeries* QCandlestickLegendMarker::series()
+{
+ Q_D(QCandlestickLegendMarker);
+
+ return d->m_series;
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+
+QCandlestickLegendMarkerPrivate::QCandlestickLegendMarkerPrivate(QCandlestickLegendMarker *q,
+ QCandlestickSeries *series,
+ QLegend *legend)
+ : QLegendMarkerPrivate(q, legend),
+ q_ptr(q),
+ m_series(series)
+{
+ QObject::connect(m_item, SIGNAL(markerRectChanged()), this, SLOT(updated()));
+ QObject::connect(m_series, SIGNAL(nameChanged()), this, SLOT(updated()));
+ QObject::connect(m_series->d_func(), SIGNAL(updated()), this, SLOT(updated()));
+}
+
+QCandlestickLegendMarkerPrivate::~QCandlestickLegendMarkerPrivate()
+{
+}
+
+QAbstractSeries* QCandlestickLegendMarkerPrivate::series()
+{
+ return m_series;
+}
+
+QObject* QCandlestickLegendMarkerPrivate::relatedObject()
+{
+ return m_series;
+}
+
+void QCandlestickLegendMarkerPrivate::updated()
+{
+ bool labelChanged = false;
+ bool brushChanged = false;
+
+ if (!m_customLabel && (m_item->label() != m_series->name())) {
+ m_item->setLabel(m_series->name());
+ labelChanged = true;
+ }
+ if (!m_customBrush) {
+ QLinearGradient gradient;
+ gradient.setStart(0.0, 0.0);
+ gradient.setFinalStop(m_item->markerRect().width(), m_item->markerRect().height());
+ gradient.setColorAt(0.0, m_series->increasingColor());
+ gradient.setColorAt(0.49, m_series->increasingColor());
+ gradient.setColorAt(0.50, m_series->decreasingColor());
+ gradient.setColorAt(1.0, m_series->decreasingColor());
+
+ QBrush brush(gradient);
+ if (m_item->brush() != brush) {
+ m_item->setBrush(brush);
+ brushChanged = true;
+ }
+ }
+ invalidateLegend();
+
+ if (labelChanged)
+ emit q_ptr->labelChanged();
+ if (brushChanged)
+ emit q_ptr->brushChanged();
+}
+
+#include "moc_qcandlesticklegendmarker.cpp"
+#include "moc_qcandlesticklegendmarker_p.cpp"
+
+QT_CHARTS_END_NAMESPACE
diff --git a/src/charts/legend/qcandlesticklegendmarker.h b/src/charts/legend/qcandlesticklegendmarker.h
new file mode 100644
index 00000000..dad57c4f
--- /dev/null
+++ b/src/charts/legend/qcandlesticklegendmarker.h
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt Charts module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 or (at your option) any later version
+** approved by the KDE Free Qt Foundation. The licenses are as published by
+** the Free Software Foundation and appearing in the file LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QCANDLESTICKLEGENDMARKER_H
+#define QCANDLESTICKLEGENDMARKER_H
+
+#include <QtCharts/QCandlestickSeries>
+#include <QtCharts/QLegendMarker>
+
+QT_CHARTS_BEGIN_NAMESPACE
+
+class QCandlestickLegendMarkerPrivate;
+
+class QT_CHARTS_EXPORT QCandlestickLegendMarker : public QLegendMarker
+{
+ Q_OBJECT
+
+public:
+ explicit QCandlestickLegendMarker(QCandlestickSeries *series, QLegend *legend,
+ QObject *parent = nullptr);
+ virtual ~QCandlestickLegendMarker();
+
+ virtual LegendMarkerType type();
+
+ // Related series
+ virtual QCandlestickSeries* series();
+
+private:
+ Q_DECLARE_PRIVATE(QCandlestickLegendMarker)
+ Q_DISABLE_COPY(QCandlestickLegendMarker)
+};
+
+QT_CHARTS_END_NAMESPACE
+
+#endif // QCANDLESTICKLEGENDMARKER_H
diff --git a/src/charts/legend/qcandlesticklegendmarker_p.h b/src/charts/legend/qcandlesticklegendmarker_p.h
new file mode 100644
index 00000000..1c786b3a
--- /dev/null
+++ b/src/charts/legend/qcandlesticklegendmarker_p.h
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt Charts module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 or (at your option) any later version
+** approved by the KDE Free Qt Foundation. The licenses are as published by
+** the Free Software Foundation and appearing in the file LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt Chart API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+
+#ifndef QCANDLESTICKLEGENDMARKER_P_H
+#define QCANDLESTICKLEGENDMARKER_P_H
+
+#include <private/qlegendmarker_p.h>
+
+QT_CHARTS_BEGIN_NAMESPACE
+
+class QCandlestickLegendMarker;
+class QCandlestickSeries;
+
+class QCandlestickLegendMarkerPrivate : public QLegendMarkerPrivate
+{
+ Q_OBJECT
+public:
+ explicit QCandlestickLegendMarkerPrivate(QCandlestickLegendMarker *q,
+ QCandlestickSeries *series, QLegend *legend);
+ virtual ~QCandlestickLegendMarkerPrivate();
+
+ virtual QAbstractSeries *series();
+ virtual QObject *relatedObject();
+
+public Q_SLOTS:
+ virtual void updated();
+
+private:
+ QCandlestickLegendMarker *q_ptr;
+ QCandlestickSeries *m_series;
+
+ Q_DECLARE_PUBLIC(QCandlestickLegendMarker)
+};
+
+QT_CHARTS_END_NAMESPACE
+
+#endif // QCANDLESTICKLEGENDMARKER_P_H
diff --git a/src/charts/legend/qlegendmarker.cpp b/src/charts/legend/qlegendmarker.cpp
index 8d240876..b9da4852 100644
--- a/src/charts/legend/qlegendmarker.cpp
+++ b/src/charts/legend/qlegendmarker.cpp
@@ -63,6 +63,7 @@ QT_CHARTS_BEGIN_NAMESPACE
\value LegendMarkerTypePie
\value LegendMarkerTypeXY
\value LegendMarkerTypeBoxPlot
+ \value LegendMarkerTypeCandlestick
*/
/*!
diff --git a/src/charts/legend/qlegendmarker.h b/src/charts/legend/qlegendmarker.h
index 142b7e45..86721440 100644
--- a/src/charts/legend/qlegendmarker.h
+++ b/src/charts/legend/qlegendmarker.h
@@ -52,7 +52,8 @@ public:
LegendMarkerTypeBar,
LegendMarkerTypePie,
LegendMarkerTypeXY,
- LegendMarkerTypeBoxPlot
+ LegendMarkerTypeBoxPlot,
+ LegendMarkerTypeCandlestick
};
Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY labelChanged)