##// END OF EJS Templates
Check the index is within the valid range...
Andy Shaw -
r2765:bcd1945731d3
parent child
Show More
@@ -1,116 +1,116
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2014 Digia Plc
3 ** Copyright (C) 2014 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.io
5 ** For any questions to Digia, please use contact form at http://qt.io
6 **
6 **
7 ** This file is part of the Qt Charts module.
7 ** This file is part of the Qt Charts module.
8 **
8 **
9 ** Licensees holding valid commercial license for Qt may use this file in
9 ** Licensees holding valid commercial license for Qt may use this file in
10 ** accordance with the Qt License Agreement provided with the Software
10 ** accordance with the Qt License Agreement provided with the Software
11 ** or, alternatively, in accordance with the terms contained in a written
11 ** or, alternatively, in accordance with the terms contained in a written
12 ** agreement between you and Digia.
12 ** agreement between you and Digia.
13 **
13 **
14 ** If you have questions regarding the use of this file, please use
14 ** If you have questions regarding the use of this file, please use
15 ** contact form at http://qt.io
15 ** contact form at http://qt.io
16 **
16 **
17 ****************************************************************************/
17 ****************************************************************************/
18
18
19
19
20 #include "declarativexyseries.h"
20 #include "declarativexyseries.h"
21 #include "declarativexypoint.h"
21 #include "declarativexypoint.h"
22 #include <QtCharts/QVXYModelMapper>
22 #include <QtCharts/QVXYModelMapper>
23 #include <QtCharts/QHXYModelMapper>
23 #include <QtCharts/QHXYModelMapper>
24
24
25 QT_CHARTS_BEGIN_NAMESPACE
25 QT_CHARTS_BEGIN_NAMESPACE
26
26
27 DeclarativeXySeries::DeclarativeXySeries()
27 DeclarativeXySeries::DeclarativeXySeries()
28 {
28 {
29 }
29 }
30
30
31 DeclarativeXySeries::~DeclarativeXySeries()
31 DeclarativeXySeries::~DeclarativeXySeries()
32 {
32 {
33 }
33 }
34
34
35 void DeclarativeXySeries::classBegin()
35 void DeclarativeXySeries::classBegin()
36 {
36 {
37 }
37 }
38
38
39 void DeclarativeXySeries::componentComplete()
39 void DeclarativeXySeries::componentComplete()
40 {
40 {
41 QXYSeries *series = qobject_cast<QXYSeries *>(xySeries());
41 QXYSeries *series = qobject_cast<QXYSeries *>(xySeries());
42 Q_ASSERT(series);
42 Q_ASSERT(series);
43
43
44 foreach (QObject *child, series->children()) {
44 foreach (QObject *child, series->children()) {
45 if (qobject_cast<DeclarativeXYPoint *>(child)) {
45 if (qobject_cast<DeclarativeXYPoint *>(child)) {
46 DeclarativeXYPoint *point = qobject_cast<DeclarativeXYPoint *>(child);
46 DeclarativeXYPoint *point = qobject_cast<DeclarativeXYPoint *>(child);
47 series->append(point->x(), point->y());
47 series->append(point->x(), point->y());
48 } else if (qobject_cast<QVXYModelMapper *>(child)) {
48 } else if (qobject_cast<QVXYModelMapper *>(child)) {
49 QVXYModelMapper *mapper = qobject_cast<QVXYModelMapper *>(child);
49 QVXYModelMapper *mapper = qobject_cast<QVXYModelMapper *>(child);
50 mapper->setSeries(series);
50 mapper->setSeries(series);
51 } else if (qobject_cast<QHXYModelMapper *>(child)) {
51 } else if (qobject_cast<QHXYModelMapper *>(child)) {
52 QHXYModelMapper *mapper = qobject_cast<QHXYModelMapper *>(child);
52 QHXYModelMapper *mapper = qobject_cast<QHXYModelMapper *>(child);
53 mapper->setSeries(series);
53 mapper->setSeries(series);
54 }
54 }
55 }
55 }
56 }
56 }
57
57
58 void DeclarativeXySeries::append(qreal x, qreal y)
58 void DeclarativeXySeries::append(qreal x, qreal y)
59 {
59 {
60 QXYSeries *series = qobject_cast<QXYSeries *>(xySeries());
60 QXYSeries *series = qobject_cast<QXYSeries *>(xySeries());
61 Q_ASSERT(series);
61 Q_ASSERT(series);
62 series->append(x, y);
62 series->append(x, y);
63 }
63 }
64
64
65 void DeclarativeXySeries::replace(qreal oldX, qreal oldY, qreal newX, qreal newY)
65 void DeclarativeXySeries::replace(qreal oldX, qreal oldY, qreal newX, qreal newY)
66 {
66 {
67 QXYSeries *series = qobject_cast<QXYSeries *>(xySeries());
67 QXYSeries *series = qobject_cast<QXYSeries *>(xySeries());
68 Q_ASSERT(series);
68 Q_ASSERT(series);
69 series->replace(oldX, oldY, newX, newY);
69 series->replace(oldX, oldY, newX, newY);
70 }
70 }
71
71
72 void DeclarativeXySeries::replace(int index, qreal newX, qreal newY)
72 void DeclarativeXySeries::replace(int index, qreal newX, qreal newY)
73 {
73 {
74 QXYSeries *series = qobject_cast<QXYSeries *>(xySeries());
74 QXYSeries *series = qobject_cast<QXYSeries *>(xySeries());
75 Q_ASSERT(series);
75 Q_ASSERT(series);
76 series->replace(index, newX, newY);
76 series->replace(index, newX, newY);
77 }
77 }
78
78
79 void DeclarativeXySeries::remove(qreal x, qreal y)
79 void DeclarativeXySeries::remove(qreal x, qreal y)
80 {
80 {
81 QXYSeries *series = qobject_cast<QXYSeries *>(xySeries());
81 QXYSeries *series = qobject_cast<QXYSeries *>(xySeries());
82 Q_ASSERT(series);
82 Q_ASSERT(series);
83 series->remove(x, y);
83 series->remove(x, y);
84 }
84 }
85
85
86 void DeclarativeXySeries::remove(int index)
86 void DeclarativeXySeries::remove(int index)
87 {
87 {
88 QXYSeries *series = qobject_cast<QXYSeries *>(xySeries());
88 QXYSeries *series = qobject_cast<QXYSeries *>(xySeries());
89 Q_ASSERT(series);
89 Q_ASSERT(series);
90 series->remove(index);
90 series->remove(index);
91 }
91 }
92
92
93 void DeclarativeXySeries::insert(int index, qreal x, qreal y)
93 void DeclarativeXySeries::insert(int index, qreal x, qreal y)
94 {
94 {
95 QXYSeries *series = qobject_cast<QXYSeries *>(xySeries());
95 QXYSeries *series = qobject_cast<QXYSeries *>(xySeries());
96 Q_ASSERT(series);
96 Q_ASSERT(series);
97 series->insert(index, QPointF(x, y));
97 series->insert(index, QPointF(x, y));
98 }
98 }
99
99
100 void DeclarativeXySeries::clear()
100 void DeclarativeXySeries::clear()
101 {
101 {
102 QXYSeries *series = qobject_cast<QXYSeries *>(xySeries());
102 QXYSeries *series = qobject_cast<QXYSeries *>(xySeries());
103 Q_ASSERT(series);
103 Q_ASSERT(series);
104 series->clear();
104 series->clear();
105 }
105 }
106
106
107 QPointF DeclarativeXySeries::at(int index)
107 QPointF DeclarativeXySeries::at(int index)
108 {
108 {
109 QXYSeries *series = qobject_cast<QXYSeries *>(xySeries());
109 QXYSeries *series = qobject_cast<QXYSeries *>(xySeries());
110 Q_ASSERT(series);
110 Q_ASSERT(series);
111 if (index >= 0 || index < series->count())
111 if (index >= 0 && index < series->count())
112 return series->points().at(index);
112 return series->points().at(index);
113 return QPointF(0, 0);
113 return QPointF(0, 0);
114 }
114 }
115
115
116 QT_CHARTS_END_NAMESPACE
116 QT_CHARTS_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now