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/QSplineSeries>
31#include <private/qsplineseries_p.h>
32#include <private/splinechartitem_p.h>
33#include <private/chartdataset_p.h>
34#include <private/charttheme_p.h>
35#include <private/splineanimation_p.h>
36#include <private/qchart_p.h>
37
38/*!
39 \class QSplineSeries
40 \inmodule QtCharts
41 \brief The QSplineSeries class presents data as spline charts.
42
43 A spline series stores the data points and the segment control points needed
44 by QPainterPath to draw a spline. The control points are automatically
45 calculated when the data changes. The algorithm computes the points so that
46 the normal spline can be drawn.
47
48 \image examples_splinechart.png
49
50 The following code snippet illustrates how to create a basic spline chart:
51 \code
52 QSplineSeries* series = new QSplineSeries();
53 series->append(0, 6);
54 series->append(2, 4);
55 ...
56 chart->addSeries(series);
57 \endcode
58*/
59/*!
60 \qmltype SplineSeries
61 \instantiates QSplineSeries
62 \inqmlmodule QtCharts
63
64 \inherits XYSeries
65
66 \brief Presents data as spline charts.
67
68 A spline series stores the data points and the segment control points needed
69 by QPainterPath to draw a spline. The control points are automatically
70 calculated when the data changes. The algorithm computes the points so that
71 the normal spline can be drawn.
72
73 \image examples_qmlchart3.png
74
75 The following QML code shows how to create a simple spline chart:
76 \snippet qmlchart/qml/qmlchart/View3.qml 1
77*/
78
79/*!
80 \qmlproperty real SplineSeries::width
81 The width of the line. By default, the width is 2.0.
82*/
83
84/*!
85 \qmlproperty Qt::PenStyle SplineSeries::style
86 Controls the style of the line. Set to one of \l{Qt::NoPen}{Qt.NoPen},
87 \l{Qt::SolidLine}{Qt.SolidLine}, \l{Qt::DashLine}{Qt.DashLine}, \l{Qt::DotLine}{Qt.DotLine},
88 \l{Qt::DashDotLine}{Qt.DashDotLine}, or \l{Qt::DashDotDotLine}{Qt.DashDotDotLine}.
89 Using \l{Qt::CustomDashLine}{Qt.CustomDashLine} is not supported in the QML API.
90 By default, the style is Qt.SolidLine.
91
92 \sa Qt::PenStyle
93*/
94
95/*!
96 \qmlproperty Qt::PenCapStyle SplineSeries::capStyle
97 Controls the cap style of the line. Set to one of \l{Qt::FlatCap}{Qt.FlatCap},
98 \l{Qt::SquareCap}{Qt.SquareCap} or \l{Qt::RoundCap}{Qt.RoundCap}. By
99 default, the cap style is Qt.SquareCap.
100
101 \sa Qt::PenCapStyle
102*/
103
104/*!
105 \qmlproperty int SplineSeries::count
106 The number of data points in the series.
107*/
108
109QT_CHARTS_BEGIN_NAMESPACE
110
111/*!
112 Constructs an empty series object that is a child of \a parent.
113 When the series object is added to a QChart instance, the ownerships is
114 transferred.
115 */
116
117QSplineSeries::QSplineSeries(QObject *parent)
118 : QLineSeries(*new QSplineSeriesPrivate(this), parent)
119{
120}
121
122/*!
123 Deletes the spline series.
124*/
125QSplineSeries::~QSplineSeries()
126{
127 Q_D(QSplineSeries);
128 if (d->m_chart)
129 d->m_chart->removeSeries(this);
130}
131
132/*!
133 \reimp
134*/
135QAbstractSeries::SeriesType QSplineSeries::type() const
136{
137 return QAbstractSeries::SeriesTypeSpline;
138}
139
140////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
141
142QSplineSeriesPrivate::QSplineSeriesPrivate(QSplineSeries *q)
143 : QLineSeriesPrivate(q)
144{
145}
146
147void QSplineSeriesPrivate::initializeGraphics(QGraphicsItem* parent)
148{
149 Q_Q(QSplineSeries);
150 SplineChartItem *spline = new SplineChartItem(q,parent);
151 m_item.reset(spline);
152 QAbstractSeriesPrivate::initializeGraphics(parent);
153}
154
155void QSplineSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced)
156{
157 Q_Q(QSplineSeries);
158 const QList<QColor> colors = theme->seriesColors();
159
160 if (forced || QChartPrivate::defaultPen() == m_pen) {
161 QPen pen;
162 pen.setColor(colors.at(index % colors.size()));
163 pen.setWidthF(2);
164 q->setPen(pen);
165 }
166
167 if (forced || QChartPrivate::defaultPen().color() == m_pointLabelsColor) {
168 QColor color = theme->labelBrush().color();
169 q->setPointLabelsColor(color);
170 }
171}
172
173void QSplineSeriesPrivate::initializeAnimations(QtCharts::QChart::AnimationOptions options,
174 int duration, QEasingCurve &curve)
175{
176 SplineChartItem *item = static_cast<SplineChartItem *>(m_item.data());
177 Q_ASSERT(item);
178 if (item->animation())
179 item->animation()->stopAndDestroyLater();
180
181 if (options.testFlag(QChart::SeriesAnimations))
182 item->setAnimation(new SplineAnimation(item, duration, curve));
183 else
184 item->setAnimation(0);
185 QAbstractSeriesPrivate::initializeAnimations(options, duration, curve);
186}
187
188QT_CHARTS_END_NAMESPACE
189
190#include "moc_qsplineseries.cpp"
191#include "moc_qsplineseries_p.cpp"
192