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/QLineSeries>
31#include <private/qlineseries_p.h>
32#include <private/linechartitem_p.h>
33#include <private/chartdataset_p.h>
34#include <private/charttheme_p.h>
35#include <private/qchart_p.h>
36QT_CHARTS_BEGIN_NAMESPACE
37
38/*!
39 \class QLineSeries
40 \inmodule QtCharts
41 \brief The QLineSeries class presents data in line charts.
42
43 A line chart is used to show information as a series of data points
44 connected by straight lines.
45
46 \image examples_linechart.png
47
48 Creating a basic line chart is simple:
49 \code
50 QLineSeries* series = new QLineSeries();
51 series->append(0, 6);
52 series->append(2, 4);
53 ...
54 chart->addSeries(series);
55 \endcode
56*/
57/*!
58 \qmltype LineSeries
59 \instantiates QLineSeries
60 \inqmlmodule QtCharts
61
62 \inherits XYSeries
63
64 \brief Presents data in line charts.
65
66 A line chart is used to show information as a series of data points
67 connected by straight lines.
68
69 The following QML example shows how to create a simple line chart:
70 \snippet qmlchart/qml/qmlchart/View2.qml 1
71 \beginfloatleft
72 \image examples_qmlchart2.png
73 \endfloat
74 \clearfloat
75*/
76
77/*!
78 \qmlproperty int LineSeries::count
79 The number of data points in the series.
80*/
81
82/*!
83 \qmlproperty real LineSeries::width
84 The width of the line. By default, the width is 2.0.
85*/
86
87/*!
88 \qmlproperty Qt::PenStyle LineSeries::style
89 Controls the style of the line. Set to one of \l{Qt::NoPen}{Qt.NoPen},
90 \l{Qt::SolidLine}{Qt.SolidLine}, \l{Qt::DashLine}{Qt.DashLine}, \l{Qt::DotLine}{Qt.DotLine},
91 \l{Qt::DashDotLine}{Qt.DashDotLine}, or \l{Qt::DashDotDotLine}{Qt.DashDotDotLine}.
92 Using \l{Qt::CustomDashLine}{Qt.CustomDashLine} is not supported in the QML API.
93 By default, the style is Qt.SolidLine.
94
95 \sa Qt::PenStyle
96*/
97
98/*!
99 \qmlproperty Qt::PenCapStyle LineSeries::capStyle
100 Controls the cap style of the line. Set to one of \l{Qt::FlatCap}{Qt.FlatCap},
101 \l{Qt::SquareCap}{Qt.SquareCap} or \l{Qt::RoundCap}{Qt.RoundCap}. By
102 default the cap style is Qt.SquareCap.
103
104 \sa Qt::PenCapStyle
105*/
106
107/*!
108 Constructs an empty series object that is a child of \a parent.
109 When the series object is added to a QChartView or QChart instance, the ownership
110 is transferred.
111*/
112QLineSeries::QLineSeries(QObject *parent)
113 : QXYSeries(*new QLineSeriesPrivate(this), parent)
114{
115
116}
117
118/*!
119 \internal
120*/
121QLineSeries::QLineSeries(QLineSeriesPrivate &d, QObject *parent)
122 : QXYSeries(d, parent)
123{
124
125}
126/*!
127 Destroys the object. Series added to QChartView or QChart instances are owned by the
128 instances and deleted when the instances are destroyed.
129*/
130QLineSeries::~QLineSeries()
131{
132 Q_D(QLineSeries);
133 if (d->m_chart)
134 d->m_chart->removeSeries(series: this);
135}
136
137/*!
138 \reimp
139*/
140QAbstractSeries::SeriesType QLineSeries::type() const
141{
142 return QAbstractSeries::SeriesTypeLine;
143}
144
145/*
146QDebug operator<< (QDebug debug, const QLineSeries series)
147{
148 Q_ASSERT(series.d_func()->m_x.size() == series.d_func()->m_y.size());
149 int size = series.d_func()->m_x.size();
150 for (int i=0; i<size; i++) {
151 debug.nospace() << "(" << series.d_func()->m_x.at(i) << ','<< series.d_func()->m_y.at(i) << ") ";
152 }
153 return debug.space();
154}
155*/
156
157////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
158
159QLineSeriesPrivate::QLineSeriesPrivate(QLineSeries *q)
160 : QXYSeriesPrivate(q)
161{
162
163}
164
165void QLineSeriesPrivate::initializeGraphics(QGraphicsItem *parent)
166{
167 Q_Q(QLineSeries);
168 LineChartItem *line = new LineChartItem(q,parent);
169 m_item.reset(other: line);
170 QAbstractSeriesPrivate::initializeGraphics(parent);
171}
172
173void QLineSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced)
174{
175 Q_Q(QLineSeries);
176 const QList<QColor> colors = theme->seriesColors();
177
178 if (forced || QChartPrivate::defaultPen() == m_pen) {
179 QPen pen;
180 pen.setColor(colors.at(i: index % colors.size()));
181 pen.setWidthF(2);
182 q->setPen(pen);
183 }
184
185 if (forced || QChartPrivate::defaultPen().color() == m_pointLabelsColor) {
186 QColor color = theme->labelBrush().color();
187 q->setPointLabelsColor(color);
188 }
189}
190
191QT_CHARTS_END_NAMESPACE
192
193#include "moc_qlineseries.cpp"
194

source code of qtcharts/src/charts/linechart/qlineseries.cpp