@@ -1,195 +1,191 | |||
|
1 | 1 | #include "qlineseries.h" |
|
2 | 2 | |
|
3 | 3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
4 | 4 | |
|
5 | 5 | /*! |
|
6 | 6 | \class QLineSeries |
|
7 | 7 | \brief The QLineSeries class is used for making line charts. |
|
8 | 8 | |
|
9 | 9 | \mainclass |
|
10 | 10 | |
|
11 | 11 | A line chart is used to show information as a series of data points |
|
12 | 12 | connected by straight lines. |
|
13 | 13 | |
|
14 | 14 | \image linechart.png |
|
15 | 15 | |
|
16 | To create line charts, users need to first QLineSeries object. | |
|
17 | ||
|
18 | \snippet ../example/linechart/main.cpp 1 | |
|
19 | ||
|
20 | Populate with the data | |
|
21 | ||
|
22 | \snippet ../example/linechart/main.cpp 2 | |
|
23 | ||
|
24 | Add created series objects to QChartView or QChart instance. | |
|
25 | ||
|
26 | \snippet ../example/linechart/main.cpp 3 | |
|
27 | ||
|
16 | Creating basic line chart is simple: | |
|
17 | \code | |
|
18 | QLineSeries* series = new QLineSeries(); | |
|
19 | series->add(0, 6); | |
|
20 | series->add(2, 4); | |
|
21 | ... | |
|
22 | chartView->addSeries(series); | |
|
23 | \endcode | |
|
28 | 24 | */ |
|
29 | 25 | |
|
30 | 26 | /*! |
|
31 | 27 | \fn virtual QSeriesType QLineSeries::type() const |
|
32 | 28 | \brief Returns type of series. |
|
33 | 29 | \sa QSeries, QSeriesType |
|
34 | 30 | */ |
|
35 | 31 | |
|
36 | 32 | /*! |
|
37 | 33 | \fn QPen QLineSeries::pen() const |
|
38 | 34 | \brief Returns the pen used to draw line for this series. |
|
39 | 35 | \sa setPen() |
|
40 | 36 | */ |
|
41 | 37 | |
|
42 | 38 | /*! |
|
43 | 39 | \fn bool QLineSeries::pointsVisible() const |
|
44 | 40 | \brief Returns if the points are drawn for this series. |
|
45 | 41 | \sa setPointsVisible() |
|
46 | 42 | */ |
|
47 | 43 | |
|
48 | 44 | |
|
49 | 45 | /*! |
|
50 | 46 | \fn void QLineSeries::changed(int index) |
|
51 | 47 | \brief \internal \a index |
|
52 | 48 | */ |
|
53 | 49 | |
|
54 | 50 | /*! |
|
55 | 51 | Constructs empty series object which is a child of \a parent. |
|
56 | 52 | When series object is added to QChartView or QChart instance ownerships is transfered. |
|
57 | 53 | */ |
|
58 | 54 | QLineSeries::QLineSeries(QObject* parent):QSeries(parent), |
|
59 | 55 | m_pointsVisible(false) |
|
60 | 56 | { |
|
61 | 57 | } |
|
62 | 58 | /*! |
|
63 | 59 | Destroys the object. Series added to QChartView or QChart instances are owned by those, |
|
64 | 60 | and are deleted when mentioned object are destroyed. |
|
65 | 61 | */ |
|
66 | 62 | QLineSeries::~QLineSeries() |
|
67 | 63 | { |
|
68 | 64 | } |
|
69 | 65 | |
|
70 | 66 | /*! |
|
71 | 67 | Adds data point \a x \a y to the series. Points are connected with lines on the chart. |
|
72 | 68 | */ |
|
73 | 69 | void QLineSeries::add(qreal x,qreal y) |
|
74 | 70 | { |
|
75 | 71 | m_x<<x; |
|
76 | 72 | m_y<<y; |
|
77 | 73 | } |
|
78 | 74 | |
|
79 | 75 | /*! |
|
80 | 76 | This is an overloaded function. |
|
81 | 77 | Adds data \a point to the series. Points are connected with lines on the chart. |
|
82 | 78 | */ |
|
83 | 79 | void QLineSeries::add(const QPointF& point) |
|
84 | 80 | { |
|
85 | 81 | m_x<<point.x(); |
|
86 | 82 | m_y<<point.y(); |
|
87 | 83 | } |
|
88 | 84 | |
|
89 | 85 | /*! |
|
90 | 86 | Modifies \a y value for given \a x a value. |
|
91 | 87 | */ |
|
92 | 88 | void QLineSeries::replace(qreal x,qreal y) |
|
93 | 89 | { |
|
94 | 90 | int index = m_x.indexOf(x); |
|
95 | 91 | m_x[index]=x; |
|
96 | 92 | m_y[index]=y; |
|
97 | 93 | emit changed(index); |
|
98 | 94 | } |
|
99 | 95 | |
|
100 | 96 | /*! |
|
101 | 97 | This is an overloaded function. |
|
102 | 98 | Replaces current y value of for given \a point x value with \a point y value. |
|
103 | 99 | */ |
|
104 | 100 | void QLineSeries::replace(const QPointF& point) |
|
105 | 101 | { |
|
106 | 102 | int index = m_x.indexOf(point.x()); |
|
107 | 103 | m_x[index]=point.x(); |
|
108 | 104 | m_y[index]=point.y(); |
|
109 | 105 | emit changed(index); |
|
110 | 106 | } |
|
111 | 107 | |
|
112 | 108 | /*! |
|
113 | 109 | Removes current \a x and y value. |
|
114 | 110 | */ |
|
115 | 111 | void QLineSeries::remove(qreal x) |
|
116 | 112 | { |
|
117 | 113 | |
|
118 | 114 | } |
|
119 | 115 | |
|
120 | 116 | /*! |
|
121 | 117 | Removes current \a point x value. Note \a point y value is ignored. |
|
122 | 118 | */ |
|
123 | 119 | void QLineSeries::remove(const QPointF& point) |
|
124 | 120 | { |
|
125 | 121 | |
|
126 | 122 | } |
|
127 | 123 | |
|
128 | 124 | /*! |
|
129 | 125 | Clears all the data. |
|
130 | 126 | */ |
|
131 | 127 | void QLineSeries::clear() |
|
132 | 128 | { |
|
133 | 129 | m_x.clear(); |
|
134 | 130 | m_y.clear(); |
|
135 | 131 | } |
|
136 | 132 | |
|
137 | 133 | /*! |
|
138 | 134 | \internal \a pos |
|
139 | 135 | */ |
|
140 | 136 | qreal QLineSeries::x(int pos) const |
|
141 | 137 | { |
|
142 | 138 | return m_x.at(pos); |
|
143 | 139 | } |
|
144 | 140 | |
|
145 | 141 | /*! |
|
146 | 142 | \internal \a pos |
|
147 | 143 | */ |
|
148 | 144 | qreal QLineSeries::y(int pos) const |
|
149 | 145 | { |
|
150 | 146 | return m_y.at(pos); |
|
151 | 147 | } |
|
152 | 148 | |
|
153 | 149 | /*! |
|
154 | 150 | Returns number of data points within series. |
|
155 | 151 | */ |
|
156 | 152 | int QLineSeries::count() const |
|
157 | 153 | { |
|
158 | 154 | Q_ASSERT(m_x.size() == m_y.size()); |
|
159 | 155 | |
|
160 | 156 | return m_x.size(); |
|
161 | 157 | |
|
162 | 158 | } |
|
163 | 159 | |
|
164 | 160 | /*! |
|
165 | 161 | Sets \a pen used for drawing given series.. |
|
166 | 162 | */ |
|
167 | 163 | void QLineSeries::setPen(const QPen& pen) |
|
168 | 164 | { |
|
169 | 165 | m_pen=pen; |
|
170 | 166 | } |
|
171 | 167 | |
|
172 | 168 | /*! |
|
173 | 169 | Sets if data points are \a visible and should be drawn on line. |
|
174 | 170 | */ |
|
175 | 171 | void QLineSeries::setPointsVisible(bool visible) |
|
176 | 172 | { |
|
177 | 173 | m_pointsVisible=visible; |
|
178 | 174 | } |
|
179 | 175 | |
|
180 | 176 | QDebug operator<< (QDebug debug, const QLineSeries series) |
|
181 | 177 | { |
|
182 | 178 | Q_ASSERT(series.m_x.size() == series.m_y.size()); |
|
183 | 179 | |
|
184 | 180 | int size = series.m_x.size(); |
|
185 | 181 | |
|
186 | 182 | for (int i=0;i<size;i++) { |
|
187 | 183 | debug.nospace() << "(" << series.m_x.at(i) << ','<< series.m_y.at(i) << ") "; |
|
188 | 184 | } |
|
189 | 185 | return debug.space(); |
|
190 | 186 | } |
|
191 | 187 | |
|
192 | 188 | |
|
193 | 189 | #include "moc_qlineseries.cpp" |
|
194 | 190 | |
|
195 | 191 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now