1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4
5#include "declarativexyseries_p.h"
6#include "declarativexypoint_p.h"
7#include <QtCharts/QVXYModelMapper>
8#include <QtCharts/QHXYModelMapper>
9
10QT_BEGIN_NAMESPACE
11
12DeclarativeXySeries::DeclarativeXySeries()
13{
14}
15
16DeclarativeXySeries::~DeclarativeXySeries()
17{
18}
19
20void DeclarativeXySeries::classBegin()
21{
22}
23
24void DeclarativeXySeries::componentComplete()
25{
26 QXYSeries *series = qobject_cast<QXYSeries *>(object: xySeries());
27 Q_ASSERT(series);
28
29 foreach (QObject *child, series->children()) {
30 if (qobject_cast<DeclarativeXYPoint *>(object: child)) {
31 DeclarativeXYPoint *point = qobject_cast<DeclarativeXYPoint *>(object: child);
32 series->append(x: point->x(), y: point->y());
33 } else if (qobject_cast<QVXYModelMapper *>(object: child)) {
34 QVXYModelMapper *mapper = qobject_cast<QVXYModelMapper *>(object: child);
35 mapper->setSeries(series);
36 } else if (qobject_cast<QHXYModelMapper *>(object: child)) {
37 QHXYModelMapper *mapper = qobject_cast<QHXYModelMapper *>(object: child);
38 mapper->setSeries(series);
39 }
40 }
41}
42
43void DeclarativeXySeries::append(qreal x, qreal y)
44{
45 QXYSeries *series = qobject_cast<QXYSeries *>(object: xySeries());
46 Q_ASSERT(series);
47 series->append(x, y);
48}
49
50void DeclarativeXySeries::replace(qreal oldX, qreal oldY, qreal newX, qreal newY)
51{
52 QXYSeries *series = qobject_cast<QXYSeries *>(object: xySeries());
53 Q_ASSERT(series);
54 series->replace(oldX, oldY, newX, newY);
55}
56
57void DeclarativeXySeries::replace(int index, qreal newX, qreal newY)
58{
59 QXYSeries *series = qobject_cast<QXYSeries *>(object: xySeries());
60 Q_ASSERT(series);
61 series->replace(index, newX, newY);
62}
63
64void DeclarativeXySeries::remove(qreal x, qreal y)
65{
66 QXYSeries *series = qobject_cast<QXYSeries *>(object: xySeries());
67 Q_ASSERT(series);
68 series->remove(x, y);
69}
70
71void DeclarativeXySeries::remove(int index)
72{
73 QXYSeries *series = qobject_cast<QXYSeries *>(object: xySeries());
74 Q_ASSERT(series);
75 series->remove(index);
76}
77
78void DeclarativeXySeries::removePoints(int index, int count)
79{
80 QXYSeries *series = qobject_cast<QXYSeries *>(object: xySeries());
81 Q_ASSERT(series);
82 series->removePoints(index, count);
83}
84
85void DeclarativeXySeries::insert(int index, qreal x, qreal y)
86{
87 QXYSeries *series = qobject_cast<QXYSeries *>(object: xySeries());
88 Q_ASSERT(series);
89 series->insert(index, point: QPointF(x, y));
90}
91
92void DeclarativeXySeries::clear()
93{
94 QXYSeries *series = qobject_cast<QXYSeries *>(object: xySeries());
95 Q_ASSERT(series);
96 series->clear();
97}
98
99QPointF DeclarativeXySeries::at(int index)
100{
101 QXYSeries *series = qobject_cast<QXYSeries *>(object: xySeries());
102 Q_ASSERT(series);
103 if (index >= 0 && index < series->count())
104 return series->points().at(i: index);
105 return QPointF(0, 0);
106}
107
108QT_END_NAMESPACE
109

source code of qtcharts/src/chartsqml2/declarativexyseries.cpp