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 | |
31 | #include "declarativexyseries_p.h" |
32 | #include "declarativexypoint_p.h" |
33 | #include <QtCharts/QVXYModelMapper> |
34 | #include <QtCharts/QHXYModelMapper> |
35 | |
36 | QT_CHARTS_BEGIN_NAMESPACE |
37 | |
38 | DeclarativeXySeries::DeclarativeXySeries() |
39 | { |
40 | } |
41 | |
42 | DeclarativeXySeries::~DeclarativeXySeries() |
43 | { |
44 | } |
45 | |
46 | void DeclarativeXySeries::classBegin() |
47 | { |
48 | } |
49 | |
50 | void DeclarativeXySeries::componentComplete() |
51 | { |
52 | QXYSeries *series = qobject_cast<QXYSeries *>(object: xySeries()); |
53 | Q_ASSERT(series); |
54 | |
55 | foreach (QObject *child, series->children()) { |
56 | if (qobject_cast<DeclarativeXYPoint *>(object: child)) { |
57 | DeclarativeXYPoint *point = qobject_cast<DeclarativeXYPoint *>(object: child); |
58 | series->append(x: point->x(), y: point->y()); |
59 | } else if (qobject_cast<QVXYModelMapper *>(object: child)) { |
60 | QVXYModelMapper *mapper = qobject_cast<QVXYModelMapper *>(object: child); |
61 | mapper->setSeries(series); |
62 | } else if (qobject_cast<QHXYModelMapper *>(object: child)) { |
63 | QHXYModelMapper *mapper = qobject_cast<QHXYModelMapper *>(object: child); |
64 | mapper->setSeries(series); |
65 | } |
66 | } |
67 | } |
68 | |
69 | void DeclarativeXySeries::append(qreal x, qreal y) |
70 | { |
71 | QXYSeries *series = qobject_cast<QXYSeries *>(object: xySeries()); |
72 | Q_ASSERT(series); |
73 | series->append(x, y); |
74 | } |
75 | |
76 | void DeclarativeXySeries::replace(qreal oldX, qreal oldY, qreal newX, qreal newY) |
77 | { |
78 | QXYSeries *series = qobject_cast<QXYSeries *>(object: xySeries()); |
79 | Q_ASSERT(series); |
80 | series->replace(oldX, oldY, newX, newY); |
81 | } |
82 | |
83 | void DeclarativeXySeries::replace(int index, qreal newX, qreal newY) |
84 | { |
85 | QXYSeries *series = qobject_cast<QXYSeries *>(object: xySeries()); |
86 | Q_ASSERT(series); |
87 | series->replace(index, newX, newY); |
88 | } |
89 | |
90 | void DeclarativeXySeries::remove(qreal x, qreal y) |
91 | { |
92 | QXYSeries *series = qobject_cast<QXYSeries *>(object: xySeries()); |
93 | Q_ASSERT(series); |
94 | series->remove(x, y); |
95 | } |
96 | |
97 | void DeclarativeXySeries::remove(int index) |
98 | { |
99 | QXYSeries *series = qobject_cast<QXYSeries *>(object: xySeries()); |
100 | Q_ASSERT(series); |
101 | series->remove(index); |
102 | } |
103 | |
104 | void DeclarativeXySeries::removePoints(int index, int count) |
105 | { |
106 | QXYSeries *series = qobject_cast<QXYSeries *>(object: xySeries()); |
107 | Q_ASSERT(series); |
108 | series->removePoints(index, count); |
109 | } |
110 | |
111 | void DeclarativeXySeries::insert(int index, qreal x, qreal y) |
112 | { |
113 | QXYSeries *series = qobject_cast<QXYSeries *>(object: xySeries()); |
114 | Q_ASSERT(series); |
115 | series->insert(index, point: QPointF(x, y)); |
116 | } |
117 | |
118 | void DeclarativeXySeries::clear() |
119 | { |
120 | QXYSeries *series = qobject_cast<QXYSeries *>(object: xySeries()); |
121 | Q_ASSERT(series); |
122 | series->clear(); |
123 | } |
124 | |
125 | QPointF DeclarativeXySeries::at(int index) |
126 | { |
127 | QXYSeries *series = qobject_cast<QXYSeries *>(object: xySeries()); |
128 | Q_ASSERT(series); |
129 | if (index >= 0 && index < series->count()) |
130 | return series->points().at(i: index); |
131 | return QPointF(0, 0); |
132 | } |
133 | |
134 | QT_CHARTS_END_NAMESPACE |
135 | |