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