@@ -1,77 +1,79 | |||
|
1 | 1 | /*! |
|
2 | 2 | \page qml.html |
|
3 | 3 | \title QtCommercial Charts QML API |
|
4 | 4 | \keyword Charts QML API |
|
5 | 5 | |
|
6 | 6 | QtCommercial Charts QML API is an intuitive and simple way to show charts in your QML |
|
7 | 7 | applications. The following QML shows you to create a simple pie chart: |
|
8 | 8 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 1 |
|
9 | 9 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2 |
|
10 | 10 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 3 |
|
11 | 11 | |
|
12 | 12 | \raw HTML |
|
13 | 13 | <table cellpadding="2" cellspacing="1" border="0" width="95%" class="indextable"> |
|
14 | 14 | <tr> |
|
15 | 15 | <th class="titleheader" width="25%"> ChartView and it's properties </th> |
|
16 | 16 | </tr> |
|
17 | 17 | <tr> |
|
18 | 18 | <td valign="top"> |
|
19 | 19 | <ul> |
|
20 | 20 | <li><a href="qml-chartview.html">ChartView</a></li> |
|
21 | 21 | <li><a href="qml-axis.html">Axis</a></li> |
|
22 | 22 | <li><a href="qml-legend.html">Legend</a></li> |
|
23 | <li><a href="qml-abstractseries.html">AbstractSeries</a></li> | |
|
23 | 24 | </ul> |
|
24 | 25 | </td> |
|
25 | 26 | </tr> |
|
26 | 27 | </table> |
|
27 | 28 | <table cellpadding="2" cellspacing="1" border="0" width="95%" class="indextable"> |
|
28 | 29 | <tr> |
|
29 | 30 | <th class="titleheader" width="25%"> XY chart </th> |
|
30 | 31 | </tr> |
|
31 | 32 | <tr> |
|
32 | 33 | <td valign="top"> |
|
33 | 34 | <ul> |
|
35 | <li><a href="qml-xyseries.html">XYSeries</a></li> | |
|
34 | 36 | <li><a href="qml-lineseries.html">LineSeries</a></li> |
|
35 | 37 | <li><a href="qml-areaseries.html">AreaSeries</a></li> |
|
36 | 38 | <li><a href="qml-scatterseries.html">ScatterSeries</a></li> |
|
37 | 39 | <li><a href="qml-splineseries.html">SplineSeries</a></li> |
|
38 | 40 | <li><a href="qml-xypoint.html">XyPoint</a></li> |
|
39 | 41 | <li><a href="qml-hxymodelmapper.html">HXYModelMapper</a></li> |
|
40 | 42 | <li><a href="qml-vxymodelmapper.html">VXYModelMapper</a></li> |
|
41 | 43 | </ul> |
|
42 | 44 | </td> |
|
43 | 45 | </tr> |
|
44 | 46 | </table> |
|
45 | 47 | <table cellpadding="2" cellspacing="1" border="0" width="95%" class="indextable"> |
|
46 | 48 | <tr> |
|
47 | 49 | <th class="titleheader" width="25%"> Pie chart </th> |
|
48 | 50 | <tr> |
|
49 | 51 | <td valign="top"> |
|
50 | 52 | <ul> |
|
51 | 53 | <li><a href="qml-pieseries.html">PieSeries</a></li> |
|
52 | 54 | <li><a href="qml-pieslice.html">PieSlice</a></li> |
|
53 | 55 | <li><a href="qml-hpiemodelmapper.html">HPieModelMapper</a></li> |
|
54 | 56 | <li><a href="qml-vpiemodelmapper.html">VPieModelMapper</a></li> |
|
55 | 57 | </ul> |
|
56 | 58 | </td> |
|
57 | 59 | </tr> |
|
58 | 60 | </table> |
|
59 | 61 | <table cellpadding="2" cellspacing="1" border="0" width="95%" class="indextable"> |
|
60 | 62 | <tr> |
|
61 | 63 | <th class="titleheader" width="25%"> Bar chart </th> |
|
62 | 64 | <tr> |
|
63 | 65 | <td valign="top"> |
|
64 | 66 | <ul> |
|
65 | 67 | <li><a href="qml-barseries.html">BarSeries</a></li> |
|
66 | 68 | <li><a href="qml-groupedbarseries.html">GroupedBarSeries</a></li> |
|
67 | 69 | <li><a href="qml-stackedbarseries.html">StackedBarSeries</a></li> |
|
68 | 70 | <li><a href="qml-percentbarseries.html">PercentBarSeries</a></li> |
|
69 | 71 | <li><a href="qml-barset.html">BarSet</a></li> |
|
70 | 72 | <li><a href="qml-hbarmodelmapper.html">HBarModelMapper</a></li> |
|
71 | 73 | <li><a href="qml-vbarmodelmapper.html">VBarModelMapper</a></li> |
|
72 | 74 | </ul> |
|
73 | 75 | </td> |
|
74 | 76 | </tr> |
|
75 | 77 | </table> |
|
76 | 78 | \endraw |
|
77 | 79 | */ |
@@ -1,308 +1,314 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "declarativebarseries.h" |
|
22 | 22 | #include "declarativechart.h" |
|
23 | 23 | #include <QBarSet> |
|
24 | 24 | #include <QVBarModelMapper> |
|
25 | 25 | #include <QHBarModelMapper> |
|
26 | 26 | |
|
27 | 27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | 28 | |
|
29 | 29 | DeclarativeBarSet::DeclarativeBarSet(QObject *parent) : |
|
30 | 30 | QBarSet("", parent) |
|
31 | 31 | { |
|
32 | 32 | connect(this, SIGNAL(valuesAdded(int,int)), this, SLOT(handleCountChanged(int, int))); |
|
33 | 33 | connect(this, SIGNAL(valuesRemoved(int,int)), this, SLOT(handleCountChanged(int, int))); |
|
34 | 34 | } |
|
35 | 35 | |
|
36 | 36 | void DeclarativeBarSet::handleCountChanged(int index, int count) |
|
37 | 37 | { |
|
38 | 38 | Q_UNUSED(index) |
|
39 | 39 | Q_UNUSED(count) |
|
40 | 40 | emit countChanged(QBarSet::count()); |
|
41 | 41 | } |
|
42 | 42 | |
|
43 | 43 | QVariantList DeclarativeBarSet::values() |
|
44 | 44 | { |
|
45 | 45 | QVariantList values; |
|
46 | 46 | for (int i(0); i < count(); i++) |
|
47 | 47 | values.append(QVariant(QBarSet::at(i))); |
|
48 | 48 | return values; |
|
49 | 49 | } |
|
50 | 50 | |
|
51 | 51 | void DeclarativeBarSet::setValues(QVariantList values) |
|
52 | 52 | { |
|
53 | 53 | while (count()) |
|
54 | 54 | remove(count() - 1); |
|
55 | 55 | |
|
56 | 56 | for (int i(0); i < values.count(); i++) { |
|
57 | 57 | if (values.at(i).canConvert(QVariant::Double)) |
|
58 | 58 | QBarSet::append(values[i].toDouble()); |
|
59 | 59 | else if (values.at(i).canConvert(QVariant::PointF)) |
|
60 | 60 | QBarSet::append(values[i].toPointF()); |
|
61 | 61 | } |
|
62 | 62 | } |
|
63 | 63 | |
|
64 | 64 | DeclarativeBarSeries::DeclarativeBarSeries(QDeclarativeItem *parent) : |
|
65 | 65 | QBarSeries(parent) |
|
66 | 66 | { |
|
67 | 67 | connect(this, SIGNAL(barsetsAdded(QList<QBarSet*>)), this, SLOT(handleAdded(QList<QBarSet*>))); |
|
68 | 68 | connect(this, SIGNAL(barsetsRemoved(QList<QBarSet*>)), this, SLOT(handleRemoved(QList<QBarSet*>))); |
|
69 | 69 | } |
|
70 | 70 | |
|
71 | 71 | void DeclarativeBarSeries::handleAdded(QList<QBarSet* > barsets) |
|
72 | 72 | { |
|
73 | 73 | foreach(QBarSet *b, barsets) { |
|
74 | 74 | DeclarativeBarSet *barset = qobject_cast<DeclarativeBarSet *>(b); |
|
75 | 75 | emit added(barset); |
|
76 | 76 | } |
|
77 | 77 | } |
|
78 | 78 | |
|
79 | 79 | void DeclarativeBarSeries::handleRemoved(QList<QBarSet* > barsets) |
|
80 | 80 | { |
|
81 | 81 | foreach(QBarSet *b, barsets) { |
|
82 | 82 | DeclarativeBarSet *barset = qobject_cast<DeclarativeBarSet *>(b); |
|
83 | 83 | emit removed(barset); |
|
84 | 84 | } |
|
85 | 85 | } |
|
86 | 86 | |
|
87 | 87 | void DeclarativeBarSeries::classBegin() |
|
88 | 88 | { |
|
89 | 89 | } |
|
90 | 90 | |
|
91 | 91 | void DeclarativeBarSeries::componentComplete() |
|
92 | 92 | { |
|
93 | 93 | foreach(QObject *child, children()) { |
|
94 | 94 | if (qobject_cast<DeclarativeBarSet *>(child)) { |
|
95 | 95 | QBarSeries::append(qobject_cast<DeclarativeBarSet *>(child)); |
|
96 | 96 | } else if(qobject_cast<QVBarModelMapper *>(child)) { |
|
97 | 97 | QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child); |
|
98 | 98 | mapper->setSeries(this); |
|
99 | 99 | } else if(qobject_cast<QHBarModelMapper *>(child)) { |
|
100 | 100 | QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child); |
|
101 | 101 | mapper->setSeries(this); |
|
102 | 102 | } |
|
103 | 103 | } |
|
104 | 104 | } |
|
105 | 105 | |
|
106 | 106 | QDeclarativeListProperty<QObject> DeclarativeBarSeries::seriesChildren() |
|
107 | 107 | { |
|
108 | 108 | return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren); |
|
109 | 109 | } |
|
110 | 110 | |
|
111 | 111 | void DeclarativeBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element) |
|
112 | 112 | { |
|
113 | 113 | // Empty implementation; the children are parsed in componentComplete instead |
|
114 | 114 | Q_UNUSED(list); |
|
115 | 115 | Q_UNUSED(element); |
|
116 | 116 | } |
|
117 | 117 | |
|
118 | 118 | DeclarativeBarSet *DeclarativeBarSeries::at(int index) |
|
119 | 119 | { |
|
120 | 120 | QList<QBarSet*> setList = barSets(); |
|
121 | 121 | if (index >= 0 && index < setList.count()) |
|
122 | 122 | return qobject_cast<DeclarativeBarSet *>(setList[index]); |
|
123 | 123 | |
|
124 | 124 | return 0; |
|
125 | 125 | } |
|
126 | 126 | |
|
127 | 127 | DeclarativeBarSet *DeclarativeBarSeries::insert(int index, QString label, QVariantList values) |
|
128 | 128 | { |
|
129 | int insertIndex = index; | |
|
130 | if (insertIndex < 0) | |
|
131 | insertIndex = 0; | |
|
132 | else if (insertIndex > count()) | |
|
133 | insertIndex = count(); | |
|
134 | ||
|
129 | 135 | DeclarativeBarSet *barset = new DeclarativeBarSet(this); |
|
130 | 136 | barset->setLabel(label); |
|
131 | 137 | barset->setValues(values); |
|
132 | if (QBarSeries::insert(index, barset)) | |
|
138 | if (QBarSeries::insert(insertIndex, barset)) | |
|
133 | 139 | return barset; |
|
134 | 140 | delete barset; |
|
135 | 141 | return 0; |
|
136 | 142 | } |
|
137 | 143 | |
|
138 | 144 | DeclarativeGroupedBarSeries::DeclarativeGroupedBarSeries(QDeclarativeItem *parent) : |
|
139 | 145 | QGroupedBarSeries(parent) |
|
140 | 146 | { |
|
141 | 147 | } |
|
142 | 148 | |
|
143 | 149 | void DeclarativeGroupedBarSeries::classBegin() |
|
144 | 150 | { |
|
145 | 151 | } |
|
146 | 152 | |
|
147 | 153 | void DeclarativeGroupedBarSeries::componentComplete() |
|
148 | 154 | { |
|
149 | 155 | foreach(QObject *child, children()) { |
|
150 | 156 | if (qobject_cast<DeclarativeBarSet *>(child)) { |
|
151 | 157 | QBarSeries::append(qobject_cast<DeclarativeBarSet *>(child)); |
|
152 | 158 | } else if(qobject_cast<QVBarModelMapper *>(child)) { |
|
153 | 159 | QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child); |
|
154 | 160 | mapper->setSeries(this); |
|
155 | 161 | } else if(qobject_cast<QHBarModelMapper *>(child)) { |
|
156 | 162 | QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child); |
|
157 | 163 | mapper->setSeries(this); |
|
158 | 164 | } |
|
159 | 165 | } |
|
160 | 166 | } |
|
161 | 167 | |
|
162 | 168 | QDeclarativeListProperty<QObject> DeclarativeGroupedBarSeries::seriesChildren() |
|
163 | 169 | { |
|
164 | 170 | return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren); |
|
165 | 171 | } |
|
166 | 172 | |
|
167 | 173 | void DeclarativeGroupedBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element) |
|
168 | 174 | { |
|
169 | 175 | // Empty implementation; the children are parsed in componentComplete instead |
|
170 | 176 | Q_UNUSED(list); |
|
171 | 177 | Q_UNUSED(element); |
|
172 | 178 | } |
|
173 | 179 | |
|
174 | 180 | DeclarativeBarSet *DeclarativeGroupedBarSeries::at(int index) |
|
175 | 181 | { |
|
176 | 182 | QList<QBarSet*> setList = barSets(); |
|
177 | 183 | if (index >= 0 && index < setList.count()) |
|
178 | 184 | return qobject_cast<DeclarativeBarSet *>(setList[index]); |
|
179 | 185 | |
|
180 | 186 | return 0; |
|
181 | 187 | } |
|
182 | 188 | |
|
183 | 189 | DeclarativeBarSet *DeclarativeGroupedBarSeries::insert(int index, QString label, QVariantList values) |
|
184 | 190 | { |
|
185 | 191 | DeclarativeBarSet *barset = new DeclarativeBarSet(this); |
|
186 | 192 | barset->setLabel(label); |
|
187 | 193 | barset->setValues(values); |
|
188 | 194 | if (QGroupedBarSeries::insert(index, barset)) |
|
189 | 195 | return barset; |
|
190 | 196 | delete barset; |
|
191 | 197 | return 0; |
|
192 | 198 | } |
|
193 | 199 | |
|
194 | 200 | DeclarativeStackedBarSeries::DeclarativeStackedBarSeries(QDeclarativeItem *parent) : |
|
195 | 201 | QStackedBarSeries(parent) |
|
196 | 202 | { |
|
197 | 203 | } |
|
198 | 204 | |
|
199 | 205 | void DeclarativeStackedBarSeries::classBegin() |
|
200 | 206 | { |
|
201 | 207 | } |
|
202 | 208 | |
|
203 | 209 | void DeclarativeStackedBarSeries::componentComplete() |
|
204 | 210 | { |
|
205 | 211 | foreach(QObject *child, children()) { |
|
206 | 212 | if (qobject_cast<DeclarativeBarSet *>(child)) { |
|
207 | 213 | QBarSeries::append(qobject_cast<DeclarativeBarSet *>(child)); |
|
208 | 214 | } else if(qobject_cast<QVBarModelMapper *>(child)) { |
|
209 | 215 | QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child); |
|
210 | 216 | mapper->setSeries(this); |
|
211 | 217 | } else if(qobject_cast<QHBarModelMapper *>(child)) { |
|
212 | 218 | QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child); |
|
213 | 219 | mapper->setSeries(this); |
|
214 | 220 | } |
|
215 | 221 | } |
|
216 | 222 | } |
|
217 | 223 | |
|
218 | 224 | QDeclarativeListProperty<QObject> DeclarativeStackedBarSeries::seriesChildren() |
|
219 | 225 | { |
|
220 | 226 | return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren); |
|
221 | 227 | } |
|
222 | 228 | |
|
223 | 229 | void DeclarativeStackedBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element) |
|
224 | 230 | { |
|
225 | 231 | // Empty implementation; the children are parsed in componentComplete instead |
|
226 | 232 | Q_UNUSED(list); |
|
227 | 233 | Q_UNUSED(element); |
|
228 | 234 | } |
|
229 | 235 | |
|
230 | 236 | DeclarativeBarSet *DeclarativeStackedBarSeries::at(int index) |
|
231 | 237 | { |
|
232 | 238 | QList<QBarSet*> setList = barSets(); |
|
233 | 239 | if (index >= 0 && index < setList.count()) |
|
234 | 240 | return qobject_cast<DeclarativeBarSet *>(setList[index]); |
|
235 | 241 | |
|
236 | 242 | return 0; |
|
237 | 243 | } |
|
238 | 244 | |
|
239 | 245 | DeclarativeBarSet *DeclarativeStackedBarSeries::insert(int index, QString label, QVariantList values) |
|
240 | 246 | { |
|
241 | 247 | DeclarativeBarSet *barset = new DeclarativeBarSet(this); |
|
242 | 248 | barset->setLabel(label); |
|
243 | 249 | barset->setValues(values); |
|
244 | 250 | if (QStackedBarSeries::insert(index, barset)) |
|
245 | 251 | return barset; |
|
246 | 252 | delete barset; |
|
247 | 253 | return 0; |
|
248 | 254 | } |
|
249 | 255 | |
|
250 | 256 | DeclarativePercentBarSeries::DeclarativePercentBarSeries(QDeclarativeItem *parent) : |
|
251 | 257 | QPercentBarSeries(parent) |
|
252 | 258 | { |
|
253 | 259 | } |
|
254 | 260 | |
|
255 | 261 | void DeclarativePercentBarSeries::classBegin() |
|
256 | 262 | { |
|
257 | 263 | } |
|
258 | 264 | |
|
259 | 265 | void DeclarativePercentBarSeries::componentComplete() |
|
260 | 266 | { |
|
261 | 267 | foreach(QObject *child, children()) { |
|
262 | 268 | if (qobject_cast<DeclarativeBarSet *>(child)) { |
|
263 | 269 | QBarSeries::append(qobject_cast<DeclarativeBarSet *>(child)); |
|
264 | 270 | } else if(qobject_cast<QVBarModelMapper *>(child)) { |
|
265 | 271 | QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child); |
|
266 | 272 | mapper->setSeries(this); |
|
267 | 273 | } else if(qobject_cast<QHBarModelMapper *>(child)) { |
|
268 | 274 | QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child); |
|
269 | 275 | mapper->setSeries(this); |
|
270 | 276 | } |
|
271 | 277 | } |
|
272 | 278 | } |
|
273 | 279 | |
|
274 | 280 | QDeclarativeListProperty<QObject> DeclarativePercentBarSeries::seriesChildren() |
|
275 | 281 | { |
|
276 | 282 | return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren); |
|
277 | 283 | } |
|
278 | 284 | |
|
279 | 285 | void DeclarativePercentBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element) |
|
280 | 286 | { |
|
281 | 287 | // Empty implementation; the children are parsed in componentComplete instead |
|
282 | 288 | Q_UNUSED(list); |
|
283 | 289 | Q_UNUSED(element); |
|
284 | 290 | } |
|
285 | 291 | |
|
286 | 292 | DeclarativeBarSet *DeclarativePercentBarSeries::at(int index) |
|
287 | 293 | { |
|
288 | 294 | QList<QBarSet*> setList = barSets(); |
|
289 | 295 | if (index >= 0 && index < setList.count()) |
|
290 | 296 | return qobject_cast<DeclarativeBarSet *>(setList[index]); |
|
291 | 297 | |
|
292 | 298 | return 0; |
|
293 | 299 | } |
|
294 | 300 | |
|
295 | 301 | DeclarativeBarSet *DeclarativePercentBarSeries::insert(int index, QString label, QVariantList values) |
|
296 | 302 | { |
|
297 | 303 | DeclarativeBarSet *barset = new DeclarativeBarSet(this); |
|
298 | 304 | barset->setLabel(label); |
|
299 | 305 | barset->setValues(values); |
|
300 | 306 | if (QPercentBarSeries::insert(index, barset)) |
|
301 | 307 | return barset; |
|
302 | 308 | delete barset; |
|
303 | 309 | return 0; |
|
304 | 310 | } |
|
305 | 311 | |
|
306 | 312 | #include "moc_declarativebarseries.cpp" |
|
307 | 313 | |
|
308 | 314 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,392 +1,441 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "declarativechart.h" |
|
22 | 22 | #include <QPainter> |
|
23 | 23 | #include "declarativelineseries.h" |
|
24 | 24 | #include "declarativeareaseries.h" |
|
25 | 25 | #include "declarativebarseries.h" |
|
26 | 26 | #include "declarativepieseries.h" |
|
27 | 27 | #include "declarativesplineseries.h" |
|
28 | 28 | #include "declarativescatterseries.h" |
|
29 | 29 | |
|
30 | 30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | 31 | |
|
32 | 32 | /*! |
|
33 | 33 | \qmlclass ChartView DeclarativeChart |
|
34 | 34 | |
|
35 | 35 | ChartView element is the parent that is responsible for showing different chart series types. |
|
36 | 36 | |
|
37 | 37 | The following QML shows how to create a simple chart with one pie series: |
|
38 | 38 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 1 |
|
39 | 39 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2 |
|
40 | 40 | \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 3 |
|
41 | 41 | |
|
42 | 42 | \beginfloatleft |
|
43 | 43 | \image examples_qmlpiechart.png |
|
44 | 44 | \endfloat |
|
45 | 45 | \clearfloat |
|
46 | 46 | */ |
|
47 | 47 | |
|
48 | 48 | /*! |
|
49 | 49 | \qmlproperty Theme ChartView::theme |
|
50 | 50 | Theme defines the visual appearance of the chart, including for example colors, fonts, line |
|
51 | 51 | widths and chart background. |
|
52 | 52 | */ |
|
53 | 53 | |
|
54 | 54 | /*! |
|
55 | 55 | \qmlproperty Animation ChartView::animation |
|
56 | 56 | Animation configuration of the chart. One of ChartView.NoAnimation, ChartView.GridAxisAnimations, |
|
57 | 57 | ChartView.SeriesAnimations or ChartView.AllAnimations. |
|
58 | 58 | */ |
|
59 | 59 | |
|
60 | 60 | /*! |
|
61 | 61 | \qmlproperty Font ChartView::titleFont |
|
62 | 62 | The title font of the chart |
|
63 | 63 | |
|
64 | 64 | See the \l {Font} {QML Font Element} for detailed documentation. |
|
65 | 65 | */ |
|
66 | 66 | |
|
67 | 67 | /*! |
|
68 | 68 | \qmlproperty string ChartView::title |
|
69 | 69 | The title of the chart, shown on top of the chart. |
|
70 | 70 | \sa ChartView::titleColor |
|
71 | 71 | */ |
|
72 | 72 | |
|
73 | 73 | /*! |
|
74 | 74 | \qmlproperty string ChartView::titleColor |
|
75 | 75 | The color of the title text. |
|
76 | 76 | */ |
|
77 | 77 | |
|
78 | 78 | /*! |
|
79 | 79 | \qmlproperty Axis ChartView::axisX |
|
80 | 80 | The x-axis of the chart. |
|
81 | 81 | */ |
|
82 | 82 | |
|
83 | 83 | /*! |
|
84 | 84 | \qmlproperty Axis ChartView::axisY |
|
85 | 85 | The default y-axis of the chart. |
|
86 | 86 | */ |
|
87 | 87 | |
|
88 | 88 | /*! |
|
89 | 89 | \qmlproperty Legend ChartView::legend |
|
90 | 90 | The legend of the chart. Legend lists all the series, pie slices and bar sets added on the chart. |
|
91 | 91 | */ |
|
92 | 92 | |
|
93 | 93 | /*! |
|
94 | 94 | \qmlproperty int ChartView::count |
|
95 | 95 | The count of series added to the chart. |
|
96 | 96 | */ |
|
97 | 97 | |
|
98 | 98 | /*! |
|
99 | 99 | \qmlproperty color ChartView::backgroundColor |
|
100 | 100 | The color of the chart's background. By default background color is defined by chart theme. |
|
101 | 101 | \sa ChartView::theme |
|
102 | 102 | */ |
|
103 | 103 | |
|
104 | 104 | /*! |
|
105 | 105 | \qmlproperty bool ChartView::dropShadowEnabled |
|
106 | 106 | The chart's border drop shadow. Set to true to enable drop shadow. |
|
107 | 107 | */ |
|
108 | 108 | |
|
109 | 109 | /*! |
|
110 | \qmlmethod AbstractSeries ChartView::series(int index) | |
|
111 | Returns the series with \a index on the chart. This allows you to loop through the series of a chart together with | |
|
112 | the count property of the chart. | |
|
113 | */ | |
|
114 | ||
|
115 | /*! | |
|
116 | \qmlmethod AbstractSeries ChartView::series(string name) | |
|
117 | Returns the first series on the chart with \a name. If there is no series with that name, returns null. | |
|
118 | */ | |
|
119 | ||
|
120 | /*! | |
|
121 | \qmlmethod AbstractSeries ChartView::createSeries(SeriesType type, string name) | |
|
122 | Creates a series object of \a type to the chart. For example: | |
|
123 | \code | |
|
124 | var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter series"); | |
|
125 | scatter.markerSize = 22; | |
|
126 | scatter.append(1.1, 2.0); | |
|
127 | \endcode | |
|
128 | */ | |
|
129 | ||
|
130 | /*! | |
|
110 | 131 | \qmlmethod Axis ChartView::axisY(QAbstractSeries *series) |
|
111 |
The y-axis of the series. This is the same as the default y-axis of the chart |
|
|
112 | explicitly defined the series to have a non-default y-axis. | |
|
132 | The y-axis of the series. This is the same as the default y-axis of the chart as multiple y-axes are not yet supported. | |
|
133 | */ | |
|
134 | ||
|
135 | /*! | |
|
136 | \qmlmethod ChartView::zoomY(real factor) | |
|
137 | Zooms in by \a factor on the center of the chart. | |
|
138 | */ | |
|
139 | ||
|
140 | /*! | |
|
141 | \qmlmethod ChartView::scrollLeft(real pixels) | |
|
142 | Scrolls to left by \a pixels. This is a convenience function that suits for example for key navigation. | |
|
143 | \sa Axis::min, Axis::max | |
|
144 | */ | |
|
145 | ||
|
146 | /*! | |
|
147 | \qmlmethod ChartView::scrollRight(real pixels) | |
|
148 | Scrolls to right by \a pixels. This is a convenience function that suits for example for key navigation. | |
|
149 | \sa Axis::min, Axis::max | |
|
150 | */ | |
|
151 | ||
|
152 | /*! | |
|
153 | \qmlmethod ChartView::scrollUp(real pixels) | |
|
154 | Scrolls up by \a pixels. This is a convenience function that suits for example for key navigation. | |
|
155 | \sa Axis::min, Axis::max | |
|
156 | */ | |
|
157 | ||
|
158 | /*! | |
|
159 | \qmlmethod ChartView::scrollDown(real pixels) | |
|
160 | Scrolls down by \a pixels. This is a convenience function that suits for example for key navigation. | |
|
161 | \sa Axis::min, Axis::max | |
|
113 | 162 | */ |
|
114 | 163 | |
|
115 | 164 | DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent) |
|
116 | 165 | : QDeclarativeItem(parent), |
|
117 | 166 | m_chart(new QChart(this)) |
|
118 | 167 | { |
|
119 | 168 | setFlag(QGraphicsItem::ItemHasNoContents, false); |
|
120 | 169 | // m_chart->axisX()->setNiceNumbersEnabled(false); |
|
121 | 170 | } |
|
122 | 171 | |
|
123 | 172 | DeclarativeChart::~DeclarativeChart() |
|
124 | 173 | { |
|
125 | 174 | delete m_chart; |
|
126 | 175 | } |
|
127 | 176 | |
|
128 | 177 | void DeclarativeChart::childEvent(QChildEvent *event) |
|
129 | 178 | { |
|
130 | 179 | if (event->type() == QEvent::ChildAdded) { |
|
131 | 180 | if (qobject_cast<QAbstractSeries *>(event->child())) { |
|
132 | 181 | m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child())); |
|
133 | 182 | } |
|
134 | 183 | } |
|
135 | 184 | } |
|
136 | 185 | |
|
137 | 186 | void DeclarativeChart::componentComplete() |
|
138 | 187 | { |
|
139 | 188 | foreach(QObject *child, children()) { |
|
140 | 189 | if (qobject_cast<QAbstractSeries *>(child)) { |
|
141 | 190 | // qDebug() << "DeclarativeChart::componentComplete(), add: " << child; |
|
142 | 191 | // TODO: how about optional y-axis? |
|
143 | 192 | m_chart->addSeries(qobject_cast<QAbstractSeries *>(child)); |
|
144 | 193 | } |
|
145 | 194 | } |
|
146 | 195 | QDeclarativeItem::componentComplete(); |
|
147 | 196 | } |
|
148 | 197 | |
|
149 | 198 | void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) |
|
150 | 199 | { |
|
151 | 200 | // qDebug() << "DeclarativeChart::geometryChanged" << newGeometry.width() << newGeometry.height(); |
|
152 | 201 | if (newGeometry.isValid()) { |
|
153 | 202 | if (newGeometry.width() > 0 && newGeometry.height() > 0) { |
|
154 | 203 | m_chart->resize(newGeometry.width(), newGeometry.height()); |
|
155 | 204 | } |
|
156 | 205 | } |
|
157 | 206 | QDeclarativeItem::geometryChanged(newGeometry, oldGeometry); |
|
158 | 207 | } |
|
159 | 208 | |
|
160 | 209 | void DeclarativeChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
161 | 210 | { |
|
162 | 211 | Q_UNUSED(option) |
|
163 | 212 | Q_UNUSED(widget) |
|
164 | 213 | |
|
165 | 214 | // TODO: optimized? |
|
166 | 215 | painter->setRenderHint(QPainter::Antialiasing, true); |
|
167 | 216 | } |
|
168 | 217 | |
|
169 | 218 | void DeclarativeChart::setTheme(DeclarativeChart::Theme theme) |
|
170 | 219 | { |
|
171 | 220 | QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme; |
|
172 | 221 | if (chartTheme != m_chart->theme()) |
|
173 | 222 | m_chart->setTheme(chartTheme); |
|
174 | 223 | } |
|
175 | 224 | |
|
176 | 225 | DeclarativeChart::Theme DeclarativeChart::theme() |
|
177 | 226 | { |
|
178 | 227 | return (DeclarativeChart::Theme) m_chart->theme(); |
|
179 | 228 | } |
|
180 | 229 | |
|
181 | 230 | void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations) |
|
182 | 231 | { |
|
183 | 232 | QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations; |
|
184 | 233 | if (animationOptions != m_chart->animationOptions()) |
|
185 | 234 | m_chart->setAnimationOptions(animationOptions); |
|
186 | 235 | } |
|
187 | 236 | |
|
188 | 237 | DeclarativeChart::Animation DeclarativeChart::animationOptions() |
|
189 | 238 | { |
|
190 | 239 | if (m_chart->animationOptions().testFlag(QChart::AllAnimations)) |
|
191 | 240 | return DeclarativeChart::AllAnimations; |
|
192 | 241 | else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations)) |
|
193 | 242 | return DeclarativeChart::GridAxisAnimations; |
|
194 | 243 | else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations)) |
|
195 | 244 | return DeclarativeChart::SeriesAnimations; |
|
196 | 245 | else |
|
197 | 246 | return DeclarativeChart::NoAnimation; |
|
198 | 247 | } |
|
199 | 248 | |
|
200 | 249 | void DeclarativeChart::setTitle(QString title) |
|
201 | 250 | { |
|
202 | 251 | if (title != m_chart->title()) |
|
203 | 252 | m_chart->setTitle(title); |
|
204 | 253 | } |
|
205 | 254 | QString DeclarativeChart::title() |
|
206 | 255 | { |
|
207 | 256 | return m_chart->title(); |
|
208 | 257 | } |
|
209 | 258 | |
|
210 | 259 | QAxis *DeclarativeChart::axisX() |
|
211 | 260 | { |
|
212 | 261 | return m_chart->axisX(); |
|
213 | 262 | } |
|
214 | 263 | |
|
215 | 264 | QAxis *DeclarativeChart::axisY(QAbstractSeries *series) |
|
216 | 265 | { |
|
217 | 266 | return m_chart->axisY(series); |
|
218 | 267 | } |
|
219 | 268 | |
|
220 | 269 | QLegend *DeclarativeChart::legend() |
|
221 | 270 | { |
|
222 | 271 | return m_chart->legend(); |
|
223 | 272 | } |
|
224 | 273 | |
|
225 | 274 | QVariantList DeclarativeChart::axisXLabels() |
|
226 | 275 | { |
|
227 | 276 | QVariantList labels; |
|
228 | 277 | foreach (qreal value, m_chart->axisX()->categories()->values()) { |
|
229 | 278 | labels.append(value); |
|
230 | 279 | labels.append(m_chart->axisX()->categories()->label(value)); |
|
231 | 280 | } |
|
232 | 281 | return labels; |
|
233 | 282 | } |
|
234 | 283 | |
|
235 | 284 | void DeclarativeChart::setAxisXLabels(QVariantList list) |
|
236 | 285 | { |
|
237 | 286 | QVariant value(QVariant::Invalid); |
|
238 | 287 | foreach (QVariant element, list) { |
|
239 | 288 | if (value.isValid() && element.type() == QVariant::String) { |
|
240 | 289 | m_chart->axisX()->categories()->insert(value.toDouble(), element.toString()); |
|
241 | 290 | value = QVariant(QVariant::Invalid); |
|
242 | 291 | } else { |
|
243 | 292 | if (element.canConvert(QVariant::Double)) |
|
244 | 293 | value = element; |
|
245 | 294 | } |
|
246 | 295 | } |
|
247 | 296 | emit axisLabelsChanged(); |
|
248 | 297 | } |
|
249 | 298 | |
|
250 | 299 | void DeclarativeChart::setTitleColor(QColor color) |
|
251 | 300 | { |
|
252 | 301 | QBrush b = m_chart->titleBrush(); |
|
253 | 302 | if (color != b.color()) { |
|
254 | 303 | b.setColor(color); |
|
255 | 304 | m_chart->setTitleBrush(b); |
|
256 | 305 | emit titleColorChanged(); |
|
257 | 306 | } |
|
258 | 307 | } |
|
259 | 308 | |
|
260 | 309 | QFont DeclarativeChart::titleFont() const |
|
261 | 310 | { |
|
262 | 311 | return m_chart->titleFont(); |
|
263 | 312 | } |
|
264 | 313 | |
|
265 | 314 | void DeclarativeChart::setTitleFont(const QFont& font) |
|
266 | 315 | { |
|
267 | 316 | m_chart->setTitleFont(font); |
|
268 | 317 | } |
|
269 | 318 | |
|
270 | 319 | QColor DeclarativeChart::titleColor() |
|
271 | 320 | { |
|
272 | 321 | return m_chart->titleBrush().color(); |
|
273 | 322 | } |
|
274 | 323 | |
|
275 | 324 | void DeclarativeChart::setBackgroundColor(QColor color) |
|
276 | 325 | { |
|
277 | 326 | QBrush b = m_chart->backgroundBrush(); |
|
278 | 327 | if (b.style() != Qt::SolidPattern || color != b.color()) { |
|
279 | 328 | b.setStyle(Qt::SolidPattern); |
|
280 | 329 | b.setColor(color); |
|
281 | 330 | m_chart->setBackgroundBrush(b); |
|
282 | 331 | emit backgroundColorChanged(); |
|
283 | 332 | } |
|
284 | 333 | } |
|
285 | 334 | |
|
286 | 335 | QColor DeclarativeChart::backgroundColor() |
|
287 | 336 | { |
|
288 | 337 | return m_chart->backgroundBrush().color(); |
|
289 | 338 | } |
|
290 | 339 | |
|
291 | 340 | int DeclarativeChart::count() |
|
292 | 341 | { |
|
293 | 342 | return m_chart->series().count(); |
|
294 | 343 | } |
|
295 | 344 | |
|
296 | 345 | void DeclarativeChart::setDropShadowEnabled(bool enabled) |
|
297 | 346 | { |
|
298 | 347 | if (enabled != m_chart->isDropShadowEnabled()) { |
|
299 | 348 | m_chart->setDropShadowEnabled(enabled); |
|
300 | 349 | dropShadowEnabledChanged(enabled); |
|
301 | 350 | } |
|
302 | 351 | } |
|
303 | 352 | |
|
304 | 353 | bool DeclarativeChart::dropShadowEnabled() |
|
305 | 354 | { |
|
306 | 355 | return m_chart->isDropShadowEnabled(); |
|
307 | 356 | } |
|
308 | 357 | |
|
309 | 358 | void DeclarativeChart::zoom(qreal factor) |
|
310 | 359 | { |
|
311 | 360 | m_chart->zoom(factor); |
|
312 | 361 | } |
|
313 | 362 | |
|
314 | 363 | void DeclarativeChart::scrollLeft(qreal pixels) |
|
315 | 364 | { |
|
316 | 365 | m_chart->scroll(QPointF(pixels, 0)); |
|
317 | 366 | } |
|
318 | 367 | |
|
319 | 368 | void DeclarativeChart::scrollRight(qreal pixels) |
|
320 | 369 | { |
|
321 | 370 | m_chart->scroll(QPointF(-pixels, 0)); |
|
322 | 371 | } |
|
323 | 372 | |
|
324 | 373 | void DeclarativeChart::scrollUp(qreal pixels) |
|
325 | 374 | { |
|
326 | 375 | m_chart->scroll(QPointF(0, pixels)); |
|
327 | 376 | } |
|
328 | 377 | |
|
329 | 378 | void DeclarativeChart::scrollDown(qreal pixels) |
|
330 | 379 | { |
|
331 | 380 | m_chart->scroll(QPointF(0, -pixels)); |
|
332 | 381 | } |
|
333 | 382 | |
|
334 | 383 | QAbstractSeries *DeclarativeChart::series(int index) |
|
335 | 384 | { |
|
336 | 385 | if (index < m_chart->series().count()) { |
|
337 | 386 | return m_chart->series().at(index); |
|
338 | 387 | } |
|
339 | 388 | return 0; |
|
340 | 389 | } |
|
341 | 390 | |
|
342 | 391 | QAbstractSeries *DeclarativeChart::series(QString seriesName) |
|
343 | 392 | { |
|
344 | 393 | foreach(QAbstractSeries *series, m_chart->series()) { |
|
345 | 394 | if (series->name() == seriesName) |
|
346 | 395 | return series; |
|
347 | 396 | } |
|
348 | 397 | return 0; |
|
349 | 398 | } |
|
350 | 399 | |
|
351 | 400 | QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name) |
|
352 | 401 | { |
|
353 | 402 | QAbstractSeries *series = 0; |
|
354 | 403 | switch (type) { |
|
355 | 404 | case DeclarativeChart::SeriesTypeLine: |
|
356 | 405 | series = new DeclarativeLineSeries(); |
|
357 | 406 | break; |
|
358 | 407 | case DeclarativeChart::SeriesTypeArea: |
|
359 | 408 | series = new DeclarativeAreaSeries(); |
|
360 | 409 | break; |
|
361 | 410 | case DeclarativeChart::SeriesTypeBar: |
|
362 | 411 | series = new DeclarativeBarSeries(); |
|
363 | 412 | break; |
|
364 | 413 | case DeclarativeChart::SeriesTypeStackedBar: |
|
365 | 414 | // TODO |
|
366 | 415 | break; |
|
367 | 416 | case DeclarativeChart::SeriesTypePercentBar: |
|
368 | 417 | // TODO |
|
369 | 418 | break; |
|
370 | 419 | case DeclarativeChart::SeriesTypeGroupedBar: |
|
371 | 420 | series = new DeclarativeGroupedBarSeries(); |
|
372 | 421 | break; |
|
373 | 422 | case DeclarativeChart::SeriesTypePie: |
|
374 | 423 | series = new DeclarativePieSeries(); |
|
375 | 424 | break; |
|
376 | 425 | case DeclarativeChart::SeriesTypeScatter: |
|
377 | 426 | series = new DeclarativeScatterSeries(); |
|
378 | 427 | break; |
|
379 | 428 | case DeclarativeChart::SeriesTypeSpline: |
|
380 | 429 | series = new DeclarativeSplineSeries(); |
|
381 | 430 | break; |
|
382 | 431 | default: |
|
383 | 432 | qWarning() << "Illegal series type"; |
|
384 | 433 | } |
|
385 | 434 | series->setName(name); |
|
386 | 435 | m_chart->addSeries(series); |
|
387 | 436 | return series; |
|
388 | 437 | } |
|
389 | 438 | |
|
390 | 439 | #include "moc_declarativechart.cpp" |
|
391 | 440 | |
|
392 | 441 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,139 +1,141 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #ifndef DECLARATIVECHART_H |
|
22 | 22 | #define DECLARATIVECHART_H |
|
23 | 23 | |
|
24 | 24 | #include <QtCore/QtGlobal> |
|
25 | 25 | #include <QDeclarativeItem> |
|
26 | 26 | #include <qchart.h> |
|
27 | 27 | #include <QAxis> |
|
28 | 28 | |
|
29 | 29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | 30 | |
|
31 | 31 | // TODO: Derive from QChart for easier definition of properties? |
|
32 | 32 | class DeclarativeChart : public QDeclarativeItem |
|
33 | 33 | // TODO: for QTQUICK2: extend QQuickPainterItem instead |
|
34 | 34 | //class DeclarativeChart : public QQuickPaintedItem, public Chart |
|
35 | 35 | { |
|
36 | 36 | Q_OBJECT |
|
37 | 37 | Q_PROPERTY(Theme theme READ theme WRITE setTheme) |
|
38 | 38 | Q_PROPERTY(Animation animationOptions READ animationOptions WRITE setAnimationOptions) |
|
39 | 39 | Q_PROPERTY(QString title READ title WRITE setTitle) |
|
40 | 40 | Q_PROPERTY(QFont titleFont READ titleFont WRITE setTitleFont) |
|
41 | 41 | Q_PROPERTY(QColor titleColor READ titleColor WRITE setTitleColor NOTIFY titleColorChanged) |
|
42 | 42 | Q_PROPERTY(QAxis *axisX READ axisX) |
|
43 | 43 | Q_PROPERTY(QAxis *axisY READ axisY) |
|
44 | 44 | Q_PROPERTY(QLegend *legend READ legend) |
|
45 | 45 | // TODO: how to define axis labels? This is not very convenient |
|
46 | 46 | Q_PROPERTY(QVariantList axisXLabels READ axisXLabels WRITE setAxisXLabels NOTIFY axisLabelsChanged) |
|
47 | 47 | Q_PROPERTY(int count READ count) |
|
48 | 48 | Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged) |
|
49 | 49 | Q_PROPERTY(bool dropShadowEnabled READ dropShadowEnabled WRITE setDropShadowEnabled NOTIFY dropShadowEnabledChanged) |
|
50 | 50 | Q_ENUMS(Animation) |
|
51 | 51 | Q_ENUMS(Theme) |
|
52 | 52 | Q_ENUMS(SeriesType) |
|
53 | 53 | |
|
54 | 54 | public: |
|
55 | 55 | // duplicating enums from QChart to make the QML api namings 1-to-1 with the C++ api |
|
56 | 56 | enum Theme { |
|
57 | 57 | ChartThemeLight = 0, |
|
58 | 58 | ChartThemeBlueCerulean, |
|
59 | 59 | ChartThemeDark, |
|
60 | 60 | ChartThemeBrownSand, |
|
61 | 61 | ChartThemeBlueNcs, |
|
62 | 62 | ChartThemeHighContrast, |
|
63 | 63 | ChartThemeBlueIcy |
|
64 | 64 | }; |
|
65 | 65 | |
|
66 | 66 | enum Animation { |
|
67 | 67 | NoAnimation = 0x0, |
|
68 | 68 | GridAxisAnimations = 0x1, |
|
69 | 69 | SeriesAnimations =0x2, |
|
70 | 70 | AllAnimations = 0x3 |
|
71 | 71 | }; |
|
72 | 72 | |
|
73 | 73 | enum SeriesType { |
|
74 | 74 | SeriesTypeLine, |
|
75 | 75 | SeriesTypeArea, |
|
76 | 76 | SeriesTypeBar, |
|
77 | 77 | SeriesTypeStackedBar, |
|
78 | 78 | SeriesTypePercentBar, |
|
79 | 79 | SeriesTypeGroupedBar, |
|
80 | 80 | SeriesTypePie, |
|
81 | 81 | SeriesTypeScatter, |
|
82 | 82 | SeriesTypeSpline |
|
83 | 83 | }; |
|
84 | 84 | |
|
85 | 85 | public: |
|
86 | 86 | DeclarativeChart(QDeclarativeItem *parent = 0); |
|
87 | 87 | ~DeclarativeChart(); |
|
88 | 88 | |
|
89 | 89 | public: // From QDeclarativeItem/QGraphicsItem |
|
90 | 90 | void childEvent(QChildEvent *event); |
|
91 | 91 | void componentComplete(); |
|
92 | 92 | void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); |
|
93 | 93 | void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); |
|
94 | 94 | |
|
95 | 95 | public: |
|
96 | 96 | void setTheme(DeclarativeChart::Theme theme); |
|
97 | 97 | DeclarativeChart::Theme theme(); |
|
98 | 98 | void setAnimationOptions(DeclarativeChart::Animation animations); |
|
99 | 99 | DeclarativeChart::Animation animationOptions(); |
|
100 | 100 | void setTitle(QString title); |
|
101 | 101 | QString title(); |
|
102 | 102 | QAxis *axisX(); |
|
103 | Q_INVOKABLE QAxis *axisY(QAbstractSeries *series = 0); | |
|
104 | 103 | QLegend *legend(); |
|
105 | 104 | QVariantList axisXLabels(); |
|
106 | 105 | void setAxisXLabels(QVariantList list); |
|
107 | 106 | QFont titleFont() const; |
|
108 | 107 | void setTitleFont(const QFont& font); |
|
109 | 108 | void setTitleColor(QColor color); |
|
110 | 109 | QColor titleColor(); |
|
111 | 110 | void setBackgroundColor(QColor color); |
|
112 | 111 | QColor backgroundColor(); |
|
113 | 112 | int count(); |
|
114 | 113 | void setDropShadowEnabled(bool enabled); |
|
115 | 114 | bool dropShadowEnabled(); |
|
115 | ||
|
116 | public: | |
|
117 | Q_INVOKABLE QAbstractSeries *series(int index); | |
|
118 | Q_INVOKABLE QAbstractSeries *series(QString seriesName); | |
|
119 | Q_INVOKABLE QAbstractSeries *createSeries(DeclarativeChart::SeriesType type, QString name = ""); | |
|
120 | Q_INVOKABLE QAxis *axisY(QAbstractSeries *series = 0); | |
|
116 | 121 | Q_INVOKABLE void zoom(qreal factor); |
|
117 | 122 | Q_INVOKABLE void scrollLeft(qreal pixels); |
|
118 | 123 | Q_INVOKABLE void scrollRight(qreal pixels); |
|
119 | 124 | Q_INVOKABLE void scrollUp(qreal pixels); |
|
120 | 125 | Q_INVOKABLE void scrollDown(qreal pixels); |
|
121 | Q_INVOKABLE QAbstractSeries *series(int index); | |
|
122 | Q_INVOKABLE QAbstractSeries *series(QString seriesName); | |
|
123 | Q_INVOKABLE QAbstractSeries *createSeries(DeclarativeChart::SeriesType type, QString name = ""); | |
|
124 | 126 | |
|
125 | 127 | Q_SIGNALS: |
|
126 | 128 | void axisLabelsChanged(); |
|
127 | 129 | void titleColorChanged(); |
|
128 | 130 | void backgroundColorChanged(); |
|
129 | 131 | void dropShadowEnabledChanged(bool enabled); |
|
130 | 132 | |
|
131 | 133 | public: |
|
132 | 134 | // Extending QChart with DeclarativeChart is not possible because QObject does not support |
|
133 | 135 | // multi inheritance, so we now have a QChart as a member instead |
|
134 | 136 | QChart *m_chart; |
|
135 | 137 | }; |
|
136 | 138 | |
|
137 | 139 | QTCOMMERCIALCHART_END_NAMESPACE |
|
138 | 140 | |
|
139 | 141 | #endif // DECLARATIVECHART_H |
@@ -1,68 +1,68 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #ifndef DECLARATIVELINESERIES_H |
|
22 | 22 | #define DECLARATIVELINESERIES_H |
|
23 | 23 | |
|
24 | 24 | #include "qchartglobal.h" |
|
25 | 25 | #include "qlineseries.h" |
|
26 | 26 | #include "declarativexyseries.h" |
|
27 | 27 | #include <QDeclarativeParserStatus> |
|
28 | 28 | #include <QDeclarativeListProperty> |
|
29 | 29 | #include <QDeclarativeParserStatus> |
|
30 | 30 | |
|
31 | 31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | 32 | |
|
33 | 33 | class DeclarativeLineSeries : public QLineSeries, public DeclarativeXySeries, public QDeclarativeParserStatus |
|
34 | 34 | { |
|
35 | 35 | Q_OBJECT |
|
36 | 36 | Q_INTERFACES(QDeclarativeParserStatus) |
|
37 | 37 | Q_PROPERTY(int count READ count NOTIFY countChanged) |
|
38 | 38 | Q_PROPERTY(QDeclarativeListProperty<QObject> declarativeChildren READ declarativeChildren) |
|
39 | 39 | Q_CLASSINFO("DefaultProperty", "declarativeChildren") |
|
40 | 40 | |
|
41 | 41 | public: |
|
42 | 42 | explicit DeclarativeLineSeries(QObject *parent = 0); |
|
43 | 43 | QXYSeries *xySeries(); |
|
44 | 44 | QDeclarativeListProperty<QObject> declarativeChildren(); |
|
45 | 45 | |
|
46 | 46 | public: // from QDeclarativeParserStatus |
|
47 | 47 | void classBegin() { DeclarativeXySeries::classBegin(); } |
|
48 | 48 | void componentComplete() { DeclarativeXySeries::componentComplete(); } |
|
49 | 49 | |
|
50 | public: // from QLineSeries | |
|
51 |
Q_INVOKABLE void append(qreal x, qreal y) { |
|
|
52 |
Q_INVOKABLE void replace(qreal oldX, qreal oldY, qreal newX, qreal newY) { |
|
|
53 |
Q_INVOKABLE void remove(qreal x, qreal y) { |
|
|
54 |
Q_INVOKABLE void insert(int index, qreal x, qreal y) { |
|
|
55 |
Q_INVOKABLE void clear() { |
|
|
56 |
Q_INVOKABLE |
|
|
50 | public: | |
|
51 | Q_INVOKABLE void append(qreal x, qreal y) { DeclarativeXySeries::append(x, y); } | |
|
52 | Q_INVOKABLE void replace(qreal oldX, qreal oldY, qreal newX, qreal newY) { DeclarativeXySeries::replace(oldX, oldY, newX, newY); } | |
|
53 | Q_INVOKABLE void remove(qreal x, qreal y) { DeclarativeXySeries::remove(x, y); } | |
|
54 | Q_INVOKABLE void insert(int index, qreal x, qreal y) { DeclarativeXySeries::insert(index, x, y); } | |
|
55 | Q_INVOKABLE void clear() { DeclarativeXySeries::clear(); } | |
|
56 | Q_INVOKABLE QPointF at(int index) { return DeclarativeXySeries::at(index); } | |
|
57 | 57 | |
|
58 | 58 | Q_SIGNALS: |
|
59 | 59 | void countChanged(int count); |
|
60 | 60 | |
|
61 | 61 | public Q_SLOTS: |
|
62 | 62 | static void appendDeclarativeChildren(QDeclarativeListProperty<QObject> *list, QObject *element); |
|
63 | 63 | void handleCountChanged(int index); |
|
64 | 64 | }; |
|
65 | 65 | |
|
66 | 66 | QTCOMMERCIALCHART_END_NAMESPACE |
|
67 | 67 | |
|
68 | 68 | #endif // DECLARATIVELINESERIES_H |
@@ -1,67 +1,67 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #ifndef DECLARATIVESCATTERSERIES_H |
|
22 | 22 | #define DECLARATIVESCATTERSERIES_H |
|
23 | 23 | |
|
24 | 24 | #include "qchartglobal.h" |
|
25 | 25 | #include "qscatterseries.h" |
|
26 | 26 | #include "declarativexyseries.h" |
|
27 | 27 | #include <QDeclarativeListProperty> |
|
28 | 28 | #include <QDeclarativeParserStatus> |
|
29 | 29 | |
|
30 | 30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | 31 | |
|
32 | 32 | class DeclarativeScatterSeries : public QScatterSeries, public DeclarativeXySeries, public QDeclarativeParserStatus |
|
33 | 33 | { |
|
34 | 34 | Q_OBJECT |
|
35 | 35 | Q_INTERFACES(QDeclarativeParserStatus) |
|
36 | 36 | Q_PROPERTY(int count READ count NOTIFY countChanged) |
|
37 | 37 | Q_PROPERTY(QDeclarativeListProperty<QObject> declarativeChildren READ declarativeChildren) |
|
38 | 38 | Q_CLASSINFO("DefaultProperty", "declarativeChildren") |
|
39 | 39 | |
|
40 | 40 | public: |
|
41 | 41 | explicit DeclarativeScatterSeries(QObject *parent = 0); |
|
42 | 42 | QXYSeries *xySeries(); |
|
43 | 43 | QDeclarativeListProperty<QObject> declarativeChildren(); |
|
44 | 44 | |
|
45 | 45 | public: // from QDeclarativeParserStatus |
|
46 | 46 | void classBegin() { DeclarativeXySeries::classBegin(); } |
|
47 | 47 | void componentComplete() { DeclarativeXySeries::componentComplete(); } |
|
48 | 48 | |
|
49 | public: // from QScatterSeries | |
|
50 |
Q_INVOKABLE void append(qreal x, qreal y) { |
|
|
51 |
Q_INVOKABLE void replace(qreal oldX, qreal oldY, qreal newX, qreal newY) { |
|
|
52 |
Q_INVOKABLE void remove(qreal x, qreal y) { |
|
|
53 | Q_INVOKABLE void clear() { QScatterSeries::clear(); } | |
|
54 | Q_INVOKABLE void insert(int index, qreal x, qreal y) { QScatterSeries::insert(index, QPointF(x, y)); } | |
|
55 |
Q_INVOKABLE |
|
|
49 | public: | |
|
50 | Q_INVOKABLE void append(qreal x, qreal y) { DeclarativeXySeries::append(x, y); } | |
|
51 | Q_INVOKABLE void replace(qreal oldX, qreal oldY, qreal newX, qreal newY) { DeclarativeXySeries::replace(oldX, oldY, newX, newY); } | |
|
52 | Q_INVOKABLE void remove(qreal x, qreal y) { DeclarativeXySeries::remove(x, y); } | |
|
53 | Q_INVOKABLE void insert(int index, qreal x, qreal y) { DeclarativeXySeries::insert(index, x, y); } | |
|
54 | Q_INVOKABLE void clear() { DeclarativeXySeries::clear(); } | |
|
55 | Q_INVOKABLE QPointF at(int index) { return DeclarativeXySeries::at(index); } | |
|
56 | 56 | |
|
57 | 57 | Q_SIGNALS: |
|
58 | 58 | void countChanged(int count); |
|
59 | 59 | |
|
60 | 60 | public Q_SLOTS: |
|
61 | 61 | static void appendDeclarativeChildren(QDeclarativeListProperty<QObject> *list, QObject *element); |
|
62 | 62 | void handleCountChanged(int index); |
|
63 | 63 | }; |
|
64 | 64 | |
|
65 | 65 | QTCOMMERCIALCHART_END_NAMESPACE |
|
66 | 66 | |
|
67 | 67 | #endif // DECLARATIVESCATTERSERIES_H |
@@ -1,68 +1,68 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #ifndef DECLARATIVESPLINESERIES_H |
|
22 | 22 | #define DECLARATIVESPLINESERIES_H |
|
23 | 23 | |
|
24 | 24 | #include "qchartglobal.h" |
|
25 | 25 | #include "qsplineseries.h" |
|
26 | 26 | #include "declarativexyseries.h" |
|
27 | 27 | #include <QDeclarativeParserStatus> |
|
28 | 28 | #include <QDeclarativeListProperty> |
|
29 | 29 | #include <QDeclarativeParserStatus> |
|
30 | 30 | |
|
31 | 31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | 32 | |
|
33 | 33 | class DeclarativeSplineSeries : public QSplineSeries, public DeclarativeXySeries, public QDeclarativeParserStatus |
|
34 | 34 | { |
|
35 | 35 | Q_OBJECT |
|
36 | 36 | Q_INTERFACES(QDeclarativeParserStatus) |
|
37 | 37 | Q_PROPERTY(int count READ count NOTIFY countChanged) |
|
38 | 38 | Q_PROPERTY(QDeclarativeListProperty<QObject> declarativeChildren READ declarativeChildren) |
|
39 | 39 | Q_CLASSINFO("DefaultProperty", "declarativeChildren") |
|
40 | 40 | |
|
41 | 41 | public: |
|
42 | 42 | explicit DeclarativeSplineSeries(QObject *parent = 0); |
|
43 | 43 | QXYSeries *xySeries(); |
|
44 | 44 | QDeclarativeListProperty<QObject> declarativeChildren(); |
|
45 | 45 | |
|
46 | 46 | public: // from QDeclarativeParserStatus |
|
47 | 47 | void classBegin() { DeclarativeXySeries::classBegin(); } |
|
48 | 48 | void componentComplete() { DeclarativeXySeries::componentComplete(); } |
|
49 | 49 | |
|
50 | public: // from QSplineSeries | |
|
51 |
Q_INVOKABLE void append(qreal x, qreal y) { |
|
|
52 |
Q_INVOKABLE void replace(qreal oldX, qreal oldY, qreal newX, qreal newY) { |
|
|
53 |
Q_INVOKABLE void remove(qreal x, qreal y) { |
|
|
54 | Q_INVOKABLE void clear() { QSplineSeries::clear(); } | |
|
55 | Q_INVOKABLE void insert(int index, qreal x, qreal y) { QSplineSeries::insert(index, QPointF(x, y)); } | |
|
56 |
Q_INVOKABLE |
|
|
50 | public: | |
|
51 | Q_INVOKABLE void append(qreal x, qreal y) { DeclarativeXySeries::append(x, y); } | |
|
52 | Q_INVOKABLE void replace(qreal oldX, qreal oldY, qreal newX, qreal newY) { DeclarativeXySeries::replace(oldX, oldY, newX, newY); } | |
|
53 | Q_INVOKABLE void remove(qreal x, qreal y) { DeclarativeXySeries::remove(x, y); } | |
|
54 | Q_INVOKABLE void insert(int index, qreal x, qreal y) { DeclarativeXySeries::insert(index, x, y); } | |
|
55 | Q_INVOKABLE void clear() { DeclarativeXySeries::clear(); } | |
|
56 | Q_INVOKABLE QPointF at(int index) { return DeclarativeXySeries::at(index); } | |
|
57 | 57 | |
|
58 | 58 | Q_SIGNALS: |
|
59 | 59 | void countChanged(int count); |
|
60 | 60 | |
|
61 | 61 | public Q_SLOTS: |
|
62 | 62 | static void appendDeclarativeChildren(QDeclarativeListProperty<QObject> *list, QObject *element); |
|
63 | 63 | void handleCountChanged(int index); |
|
64 | 64 | }; |
|
65 | 65 | |
|
66 | 66 | QTCOMMERCIALCHART_END_NAMESPACE |
|
67 | 67 | |
|
68 | 68 | #endif // DECLARATIVESPLINESERIES_H |
@@ -1,77 +1,106 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | //#include "DeclarativeXySeries.h" |
|
22 | 22 | #include "declarativexyseries.h" |
|
23 | 23 | #include "declarativechart.h" |
|
24 | 24 | #include <QXYSeries> |
|
25 | 25 | #include <QVXYModelMapper> |
|
26 | 26 | #include <QHXYModelMapper> |
|
27 | 27 | #include <QDeclarativeListProperty> |
|
28 | 28 | |
|
29 | 29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | 30 | |
|
31 | 31 | DeclarativeXySeries::DeclarativeXySeries() |
|
32 | 32 | { |
|
33 | 33 | } |
|
34 | 34 | |
|
35 | 35 | DeclarativeXySeries::~DeclarativeXySeries() |
|
36 | 36 | { |
|
37 | 37 | } |
|
38 | 38 | |
|
39 | 39 | void DeclarativeXySeries::classBegin() |
|
40 | 40 | { |
|
41 | 41 | } |
|
42 | 42 | |
|
43 | 43 | void DeclarativeXySeries::componentComplete() |
|
44 | 44 | { |
|
45 | 45 | QXYSeries *series = qobject_cast<QXYSeries *>(xySeries()); |
|
46 | 46 | Q_ASSERT(series); |
|
47 | 47 | |
|
48 | 48 | foreach(QObject *child, series->children()) { |
|
49 | 49 | if (qobject_cast<DeclarativeXyPoint *>(child)) { |
|
50 | 50 | DeclarativeXyPoint *point = qobject_cast<DeclarativeXyPoint *>(child); |
|
51 | 51 | series->append(point->x(), point->y()); |
|
52 | 52 | } else if(qobject_cast<QVXYModelMapper *>(child)) { |
|
53 | 53 | QVXYModelMapper *mapper = qobject_cast<QVXYModelMapper *>(child); |
|
54 | 54 | mapper->setSeries(series); |
|
55 | 55 | } else if(qobject_cast<QHXYModelMapper *>(child)) { |
|
56 | 56 | QHXYModelMapper *mapper = qobject_cast<QHXYModelMapper *>(child); |
|
57 | 57 | mapper->setSeries(series); |
|
58 | 58 | } |
|
59 | 59 | } |
|
60 | 60 | } |
|
61 | 61 | |
|
62 | DeclarativeXyPoint *DeclarativeXySeries::at(int index) | |
|
62 | void DeclarativeXySeries::append(qreal x, qreal y) | |
|
63 | 63 | { |
|
64 | 64 | QXYSeries *series = qobject_cast<QXYSeries *>(xySeries()); |
|
65 | 65 | Q_ASSERT(series); |
|
66 | if (index < series->count()) { | |
|
67 | QPointF point = series->points().at(index); | |
|
68 | DeclarativeXyPoint *xyPoint = new DeclarativeXyPoint(series); | |
|
69 | xyPoint->setX(point.x()); | |
|
70 | xyPoint->setY(point.y()); | |
|
71 | return xyPoint; | |
|
72 | } | |
|
73 | return 0; | |
|
66 | series->append(x, y); | |
|
74 | 67 | } |
|
75 | 68 | |
|
69 | void DeclarativeXySeries::replace(qreal oldX, qreal oldY, qreal newX, qreal newY) | |
|
70 | { | |
|
71 | QXYSeries *series = qobject_cast<QXYSeries *>(xySeries()); | |
|
72 | Q_ASSERT(series); | |
|
73 | series->replace(oldX, oldY, newX, newY); | |
|
74 | } | |
|
75 | ||
|
76 | void DeclarativeXySeries::remove(qreal x, qreal y) | |
|
77 | { | |
|
78 | QXYSeries *series = qobject_cast<QXYSeries *>(xySeries()); | |
|
79 | Q_ASSERT(series); | |
|
80 | series->remove(x, y); | |
|
81 | } | |
|
82 | ||
|
83 | void DeclarativeXySeries::insert(int index, qreal x, qreal y) | |
|
84 | { | |
|
85 | QXYSeries *series = qobject_cast<QXYSeries *>(xySeries()); | |
|
86 | Q_ASSERT(series); | |
|
87 | series->insert(index, QPointF(x, y)); | |
|
88 | } | |
|
89 | ||
|
90 | void DeclarativeXySeries::clear() | |
|
91 | { | |
|
92 | QXYSeries *series = qobject_cast<QXYSeries *>(xySeries()); | |
|
93 | Q_ASSERT(series); | |
|
94 | series->clear(); | |
|
95 | } | |
|
96 | ||
|
97 | QPointF DeclarativeXySeries::at(int index) | |
|
98 | { | |
|
99 | QXYSeries *series = qobject_cast<QXYSeries *>(xySeries()); | |
|
100 | Q_ASSERT(series); | |
|
101 | if (index >= 0 || index < series->count()) | |
|
102 | return series->points().at(index); | |
|
103 | return QPointF(0, 0); | |
|
104 | } | |
|
76 | 105 | |
|
77 | 106 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,49 +1,55 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #ifndef DECLARATIVE_XY_SERIES_H |
|
22 | 22 | #define DECLARATIVE_XY_SERIES_H |
|
23 | 23 | |
|
24 | 24 | #include "qchartglobal.h" |
|
25 | 25 | #include "declarativexypoint.h" |
|
26 | 26 | #include <QColor> |
|
27 | 27 | #include <QXYSeries> |
|
28 | 28 | |
|
29 | 29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | 30 | |
|
31 | 31 | class QChart; |
|
32 | 32 | class QAbstractSeries; |
|
33 | 33 | |
|
34 | 34 | class DeclarativeXySeries |
|
35 | 35 | { |
|
36 | 36 | public: |
|
37 | 37 | explicit DeclarativeXySeries(); |
|
38 | 38 | ~DeclarativeXySeries(); |
|
39 | 39 | |
|
40 | 40 | public: |
|
41 | 41 | void classBegin(); |
|
42 | 42 | void componentComplete(); |
|
43 | 43 | virtual QXYSeries *xySeries() = 0; |
|
44 | DeclarativeXyPoint *at(int index); | |
|
44 | ||
|
45 | void append(qreal x, qreal y); | |
|
46 | void replace(qreal oldX, qreal oldY, qreal newX, qreal newY); | |
|
47 | void remove(qreal x, qreal y); | |
|
48 | void insert(int index, qreal x, qreal y); | |
|
49 | void clear(); | |
|
50 | QPointF at(int index); | |
|
45 | 51 | }; |
|
46 | 52 | |
|
47 | 53 | QTCOMMERCIALCHART_END_NAMESPACE |
|
48 | 54 | |
|
49 | 55 | #endif // DECLARATIVE_XY_SERIES_H |
@@ -1,688 +1,722 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qbarseries.h" |
|
22 | 22 | #include "qbarseries_p.h" |
|
23 | 23 | #include "qbarset.h" |
|
24 | 24 | #include "qbarset_p.h" |
|
25 | 25 | #include "domain_p.h" |
|
26 | 26 | #include "legendmarker_p.h" |
|
27 | 27 | #include "chartdataset_p.h" |
|
28 | 28 | #include "charttheme_p.h" |
|
29 | 29 | #include "chartanimator_p.h" |
|
30 | 30 | |
|
31 | 31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | 32 | |
|
33 | 33 | /*! |
|
34 | 34 | \class QBarSeries |
|
35 | 35 | \brief Series for creating a bar chart |
|
36 | 36 | \mainclass |
|
37 | 37 | |
|
38 | 38 | QBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to |
|
39 | 39 | the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar |
|
40 | 40 | and y-value is the height of the bar. The category names are ignored with this series and x-axis |
|
41 | 41 | shows the x-values. |
|
42 | 42 | |
|
43 | 43 | See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart. |
|
44 | 44 | \image examples_barchart.png |
|
45 | 45 | |
|
46 | 46 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries |
|
47 | 47 | */ |
|
48 | 48 | /*! |
|
49 | 49 | \qmlclass BarSeries QBarSeries |
|
50 | \inherits AbstractSeries | |
|
51 | ||
|
52 | The following QML shows how to create a simple bar chart: | |
|
53 | \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1 | |
|
50 | 54 | |
|
51 | 55 | \beginfloatleft |
|
52 | 56 | \image demos_qmlchart6.png |
|
53 | 57 | \endfloat |
|
54 | 58 | \clearfloat |
|
55 | ||
|
56 | The following QML shows how to create a simple bar chart: | |
|
57 | \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1 | |
|
58 | 59 | */ |
|
59 | 60 | |
|
60 | 61 | /*! |
|
61 | 62 | \property QBarSeries::barWidth |
|
62 | 63 | The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars |
|
63 | 64 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
64 | 65 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
65 | 66 | Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar. |
|
66 | 67 | \sa QGroupedBarSeries |
|
67 | 68 | */ |
|
68 | 69 | /*! |
|
69 | 70 | \qmlproperty real BarSeries::barWidth |
|
70 | 71 | The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars |
|
71 | 72 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
72 | 73 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
73 | 74 | Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar. |
|
74 | 75 | */ |
|
75 | 76 | |
|
76 | 77 | /*! |
|
77 | 78 | \property QBarSeries::count |
|
78 | 79 | Holds the number of sets in series. |
|
79 | 80 | */ |
|
80 | 81 | /*! |
|
81 | 82 | \qmlproperty int BarSeries::count |
|
82 | 83 | Holds the number of sets in series. |
|
83 | 84 | */ |
|
84 | 85 | |
|
85 | 86 | /*! |
|
86 | 87 | \property QBarSeries::labelsVisible |
|
87 | 88 | Defines the visibility of the labels in series |
|
88 | 89 | */ |
|
89 | 90 | /*! |
|
90 | 91 | \qmlproperty bool BarSeries::labelsVisible |
|
91 | 92 | Defines the visibility of the labels in series |
|
92 | 93 | */ |
|
93 | 94 | |
|
94 | 95 | /*! |
|
95 | 96 | \fn void QBarSeries::clicked(QBarSet *barset, int index) |
|
96 | 97 | |
|
97 | 98 | The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset. |
|
98 | 99 | Clicked bar inside set is indexed by \a index |
|
99 | 100 | */ |
|
100 | 101 | /*! |
|
101 | 102 | \qmlsignal BarSeries::onClicked(BarSet barset, int index) |
|
102 | 103 | |
|
103 | 104 | The signal is emitted if the user clicks with a mouse on top of BarSet. |
|
104 | 105 | Clicked bar inside set is indexed by \a index |
|
105 | 106 | */ |
|
106 | 107 | |
|
107 | 108 | /*! |
|
108 | 109 | \fn void QBarSeries::hovered(QBarSet* barset, bool status) |
|
109 | 110 | |
|
110 | 111 | The signal is emitted if mouse is hovered on top of series. |
|
111 | 112 | Parameter \a barset is the pointer of barset, where hover happened. |
|
112 | 113 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
113 | 114 | */ |
|
114 | 115 | /*! |
|
115 | 116 | \qmlsignal BarSeries::onHovered(BarSet barset, bool status) |
|
116 | 117 | |
|
117 | 118 | The signal is emitted if mouse is hovered on top of series. |
|
118 | 119 | Parameter \a barset is the pointer of barset, where hover happened. |
|
119 | 120 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
120 | 121 | */ |
|
121 | 122 | |
|
122 | 123 | /*! |
|
123 | 124 | \fn void QBarSeries::countChanged() |
|
124 | 125 | This signal is emitted when barset count has been changed, for example by append or remove. |
|
125 | 126 | */ |
|
126 | 127 | /*! |
|
127 | 128 | \qmlsignal BarSeries::countChanged() |
|
128 | 129 | This signal is emitted when barset count has been changed, for example by append or remove. |
|
129 | 130 | */ |
|
130 | 131 | |
|
131 | 132 | /*! |
|
132 | 133 | \fn void QBarSeries::labelsVisibleChanged() |
|
133 | 134 | This signal is emitted when labels visibility have changed. |
|
134 | 135 | \sa isLabelsVisible(), setLabelsVisible() |
|
135 | 136 | */ |
|
136 | 137 | |
|
137 | 138 | /*! |
|
138 | 139 | \fn void QBarSeries::barsetsAdded(QList<QBarSet*> sets) |
|
139 | 140 | This signal is emitted when \a sets have been added to the series. |
|
140 | 141 | \sa append(), insert() |
|
141 | 142 | */ |
|
142 | 143 | /*! |
|
143 | 144 | \qmlsignal BarSeries::added(BarSet barset) |
|
144 | 145 | Emitted when \a barset has been added to the series. |
|
145 | 146 | */ |
|
146 | 147 | |
|
147 | 148 | /*! |
|
148 | 149 | \fn void QBarSeries::barsetsRemoved(QList<QBarSet*> sets) |
|
149 | 150 | This signal is emitted when \a sets have been removed from the series. |
|
150 | 151 | \sa remove() |
|
151 | 152 | */ |
|
152 | 153 | /*! |
|
153 | 154 | \qmlsignal BarSeries::removed(BarSet barset) |
|
154 | 155 | Emitted when \a barset has been removed from the series. |
|
155 | 156 | */ |
|
156 | 157 | |
|
157 | 158 | /*! |
|
159 | \qmlmethod BarSet BarSeries::at(int index) | |
|
160 | Returns bar set at \a index. Returns null if the index is not valid. | |
|
161 | */ | |
|
162 | ||
|
163 | /*! | |
|
164 | \qmlmethod BarSet BarSeries::append(string label, VariantList values) | |
|
165 | Adds a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XyPoints. | |
|
166 | For example: | |
|
167 | \code | |
|
168 | myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]); | |
|
169 | myBarSeries.append("set 2", [Qt.point(0, 1), Qt.point(2, 2.5), Qt.point(3.5, 2.2)]); | |
|
170 | \endcode | |
|
171 | */ | |
|
172 | ||
|
173 | /*! | |
|
174 | \qmlmethod BarSet BarSeries::insert(int index, string label, VariantList values) | |
|
175 | Inserts a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XyPoints. | |
|
176 | If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is | |
|
177 | appended. | |
|
178 | \sa BarSeries::append() | |
|
179 | */ | |
|
180 | ||
|
181 | /*! | |
|
182 | \qmlmethod bool BarSeries::remove(BarSet barset) | |
|
183 | Removes the barset from the series. Returns true if successfull, false otherwise. | |
|
184 | */ | |
|
185 | ||
|
186 | /*! | |
|
187 | \qmlmethod BarSeries::clear() | |
|
188 | Removes all barsets from the series. | |
|
189 | */ | |
|
190 | ||
|
191 | /*! | |
|
158 | 192 | Constructs empty QBarSeries. |
|
159 | 193 | QBarSeries is QObject which is a child of a \a parent. |
|
160 | 194 | */ |
|
161 | 195 | QBarSeries::QBarSeries(QObject *parent) : |
|
162 | 196 | QAbstractSeries(*new QBarSeriesPrivate(this),parent) |
|
163 | 197 | { |
|
164 | 198 | } |
|
165 | 199 | |
|
166 | 200 | /*! |
|
167 | 201 | Destructs barseries and owned barsets. |
|
168 | 202 | */ |
|
169 | 203 | QBarSeries::~QBarSeries() |
|
170 | 204 | { |
|
171 | 205 | Q_D(QBarSeries); |
|
172 | 206 | if(d->m_dataset){ |
|
173 | 207 | d->m_dataset->removeSeries(this); |
|
174 | 208 | } |
|
175 | 209 | } |
|
176 | 210 | |
|
177 | 211 | /*! |
|
178 | 212 | \internal |
|
179 | 213 | */ |
|
180 | 214 | QBarSeries::QBarSeries(QBarSeriesPrivate &d, QObject *parent) : |
|
181 | 215 | QAbstractSeries(d,parent) |
|
182 | 216 | { |
|
183 | 217 | } |
|
184 | 218 | |
|
185 | 219 | /*! |
|
186 | 220 | Returns the type of series. Derived classes override this. |
|
187 | 221 | */ |
|
188 | 222 | QAbstractSeries::SeriesType QBarSeries::type() const |
|
189 | 223 | { |
|
190 | 224 | return QAbstractSeries::SeriesTypeBar; |
|
191 | 225 | } |
|
192 | 226 | |
|
193 | 227 | /*! |
|
194 | 228 | Sets the width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars |
|
195 | 229 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
196 | 230 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
197 | 231 | Note that with \link QGroupedBarSeries \endlink this value means the width of one group of bars instead of just one bar. |
|
198 | 232 | */ |
|
199 | 233 | void QBarSeries::setBarWidth(qreal width) |
|
200 | 234 | { |
|
201 | 235 | Q_D(QBarSeries); |
|
202 | 236 | d->setBarWidth(width); |
|
203 | 237 | } |
|
204 | 238 | |
|
205 | 239 | /*! |
|
206 | 240 | Returns the width of the bars of the series. |
|
207 | 241 | \sa setBarWidth() |
|
208 | 242 | */ |
|
209 | 243 | qreal QBarSeries::barWidth() const |
|
210 | 244 | { |
|
211 | 245 | Q_D(const QBarSeries); |
|
212 | 246 | return d->barWidth(); |
|
213 | 247 | } |
|
214 | 248 | |
|
215 | 249 | /*! |
|
216 | 250 | Adds a set of bars to series. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. |
|
217 | 251 | Returns true, if appending succeeded. |
|
218 | 252 | */ |
|
219 | 253 | bool QBarSeries::append(QBarSet *set) |
|
220 | 254 | { |
|
221 | 255 | Q_D(QBarSeries); |
|
222 | 256 | bool success = d->append(set); |
|
223 | 257 | if (success) { |
|
224 | 258 | QList<QBarSet*> sets; |
|
225 | 259 | sets.append(set); |
|
226 | 260 | emit barsetsAdded(sets); |
|
227 | 261 | emit countChanged(); |
|
228 | 262 | } |
|
229 | 263 | return success; |
|
230 | 264 | } |
|
231 | 265 | |
|
232 | 266 | /*! |
|
233 | 267 | Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set. |
|
234 | 268 | Returns true, if set was removed. |
|
235 | 269 | */ |
|
236 | 270 | bool QBarSeries::remove(QBarSet *set) |
|
237 | 271 | { |
|
238 | 272 | Q_D(QBarSeries); |
|
239 | 273 | bool success = d->remove(set); |
|
240 | 274 | if (success) { |
|
241 | 275 | QList<QBarSet*> sets; |
|
242 | 276 | sets.append(set); |
|
243 | 277 | emit barsetsRemoved(sets); |
|
244 | 278 | emit countChanged(); |
|
245 | 279 | } |
|
246 | 280 | return success; |
|
247 | 281 | } |
|
248 | 282 | |
|
249 | 283 | /*! |
|
250 | 284 | Adds a list of barsets to series. Takes ownership of \a sets. |
|
251 | 285 | Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series, |
|
252 | 286 | nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended |
|
253 | 287 | and function returns false. |
|
254 | 288 | */ |
|
255 | 289 | bool QBarSeries::append(QList<QBarSet* > sets) |
|
256 | 290 | { |
|
257 | 291 | Q_D(QBarSeries); |
|
258 | 292 | bool success = d->append(sets); |
|
259 | 293 | if (success) { |
|
260 | 294 | emit barsetsAdded(sets); |
|
261 | 295 | emit countChanged(); |
|
262 | 296 | } |
|
263 | 297 | return success; |
|
264 | 298 | } |
|
265 | 299 | |
|
266 | 300 | /*! |
|
267 | 301 | Insert a set of bars to series at \a index postion. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. |
|
268 | 302 | Returns true, if inserting succeeded. |
|
269 | 303 | |
|
270 | 304 | */ |
|
271 | 305 | bool QBarSeries::insert(int index, QBarSet *set) |
|
272 | 306 | { |
|
273 | 307 | Q_D(QBarSeries); |
|
274 | 308 | bool success = d->insert(index, set); |
|
275 | 309 | if (success) { |
|
276 | 310 | QList<QBarSet*> sets; |
|
277 | 311 | sets.append(set); |
|
278 | 312 | emit barsetsAdded(sets); |
|
279 | 313 | emit countChanged(); |
|
280 | 314 | } |
|
281 | 315 | return success; |
|
282 | 316 | } |
|
283 | 317 | |
|
284 | 318 | /*! |
|
285 | 319 | Removes all of the bar sets from the series |
|
286 | 320 | */ |
|
287 | 321 | void QBarSeries::clear() |
|
288 | 322 | { |
|
289 | 323 | Q_D(QBarSeries); |
|
290 | 324 | QList<QBarSet *> sets = barSets(); |
|
291 | 325 | bool success = d->remove(sets); |
|
292 | 326 | if (success) { |
|
293 | 327 | emit barsetsRemoved(sets); |
|
294 | 328 | emit countChanged(); |
|
295 | 329 | } |
|
296 | 330 | } |
|
297 | 331 | |
|
298 | 332 | /*! |
|
299 | 333 | Returns number of sets in series. |
|
300 | 334 | */ |
|
301 | 335 | int QBarSeries::count() const |
|
302 | 336 | { |
|
303 | 337 | Q_D(const QBarSeries); |
|
304 | 338 | return d->m_barSets.count(); |
|
305 | 339 | } |
|
306 | 340 | |
|
307 | 341 | /*! |
|
308 | 342 | Returns a list of sets in series. Keeps ownership of sets. |
|
309 | 343 | */ |
|
310 | 344 | QList<QBarSet*> QBarSeries::barSets() const |
|
311 | 345 | { |
|
312 | 346 | Q_D(const QBarSeries); |
|
313 | 347 | return d->m_barSets; |
|
314 | 348 | } |
|
315 | 349 | |
|
316 | 350 | /*! |
|
317 | 351 | Sets the visibility of labels in series to \a visible |
|
318 | 352 | */ |
|
319 | 353 | void QBarSeries::setLabelsVisible(bool visible) |
|
320 | 354 | { |
|
321 | 355 | Q_D(QBarSeries); |
|
322 | 356 | if (d->m_labelsVisible != visible) { |
|
323 | 357 | d->setLabelsVisible(visible); |
|
324 | 358 | emit labelsVisibleChanged(); |
|
325 | 359 | } |
|
326 | 360 | } |
|
327 | 361 | |
|
328 | 362 | /*! |
|
329 | 363 | Returns the visibility of labels |
|
330 | 364 | */ |
|
331 | 365 | bool QBarSeries::isLabelsVisible() const |
|
332 | 366 | { |
|
333 | 367 | Q_D(const QBarSeries); |
|
334 | 368 | return d->m_labelsVisible; |
|
335 | 369 | } |
|
336 | 370 | |
|
337 | 371 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
338 | 372 | |
|
339 | 373 | QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) : |
|
340 | 374 | QAbstractSeriesPrivate(q), |
|
341 | 375 | m_barWidth(0.5), // Default value is 50% of category width |
|
342 | 376 | m_labelsVisible(false), |
|
343 | 377 | m_visible(true) |
|
344 | 378 | { |
|
345 | 379 | } |
|
346 | 380 | |
|
347 | 381 | int QBarSeriesPrivate::categoryCount() const |
|
348 | 382 | { |
|
349 | 383 | // No categories defined. return count of longest set. |
|
350 | 384 | int count = 0; |
|
351 | 385 | for (int i=0; i<m_barSets.count(); i++) { |
|
352 | 386 | if (m_barSets.at(i)->count() > count) { |
|
353 | 387 | count = m_barSets.at(i)->count(); |
|
354 | 388 | } |
|
355 | 389 | } |
|
356 | 390 | |
|
357 | 391 | return count; |
|
358 | 392 | } |
|
359 | 393 | |
|
360 | 394 | void QBarSeriesPrivate::setBarWidth(qreal width) |
|
361 | 395 | { |
|
362 | 396 | if (width < 0.0) { |
|
363 | 397 | width = 0.0; |
|
364 | 398 | } |
|
365 | 399 | m_barWidth = width; |
|
366 | 400 | emit updatedBars(); |
|
367 | 401 | } |
|
368 | 402 | |
|
369 | 403 | qreal QBarSeriesPrivate::barWidth() const |
|
370 | 404 | { |
|
371 | 405 | return m_barWidth; |
|
372 | 406 | } |
|
373 | 407 | |
|
374 | 408 | QBarSet* QBarSeriesPrivate::barsetAt(int index) |
|
375 | 409 | { |
|
376 | 410 | return m_barSets.at(index); |
|
377 | 411 | } |
|
378 | 412 | |
|
379 | 413 | void QBarSeriesPrivate::setVisible(bool visible) |
|
380 | 414 | { |
|
381 | 415 | m_visible = visible; |
|
382 | 416 | emit updatedBars(); |
|
383 | 417 | } |
|
384 | 418 | |
|
385 | 419 | void QBarSeriesPrivate::setLabelsVisible(bool visible) |
|
386 | 420 | { |
|
387 | 421 | m_labelsVisible = visible; |
|
388 | 422 | emit labelsVisibleChanged(visible); |
|
389 | 423 | } |
|
390 | 424 | |
|
391 | 425 | qreal QBarSeriesPrivate::min() |
|
392 | 426 | { |
|
393 | 427 | if (m_barSets.count() <= 0) { |
|
394 | 428 | return 0; |
|
395 | 429 | } |
|
396 | 430 | qreal min = INT_MAX; |
|
397 | 431 | |
|
398 | 432 | for (int i = 0; i < m_barSets.count(); i++) { |
|
399 | 433 | int categoryCount = m_barSets.at(i)->count(); |
|
400 | 434 | for (int j = 0; j < categoryCount; j++) { |
|
401 | 435 | qreal temp = m_barSets.at(i)->at(j).y(); |
|
402 | 436 | if (temp < min) |
|
403 | 437 | min = temp; |
|
404 | 438 | } |
|
405 | 439 | } |
|
406 | 440 | return min; |
|
407 | 441 | } |
|
408 | 442 | |
|
409 | 443 | qreal QBarSeriesPrivate::max() |
|
410 | 444 | { |
|
411 | 445 | if (m_barSets.count() <= 0) { |
|
412 | 446 | return 0; |
|
413 | 447 | } |
|
414 | 448 | qreal max = INT_MIN; |
|
415 | 449 | |
|
416 | 450 | for (int i = 0; i < m_barSets.count(); i++) { |
|
417 | 451 | int categoryCount = m_barSets.at(i)->count(); |
|
418 | 452 | for (int j = 0; j < categoryCount; j++) { |
|
419 | 453 | qreal temp = m_barSets.at(i)->at(j).y(); |
|
420 | 454 | if (temp > max) |
|
421 | 455 | max = temp; |
|
422 | 456 | } |
|
423 | 457 | } |
|
424 | 458 | |
|
425 | 459 | return max; |
|
426 | 460 | } |
|
427 | 461 | |
|
428 | 462 | qreal QBarSeriesPrivate::valueAt(int set, int category) |
|
429 | 463 | { |
|
430 | 464 | if ((set < 0) || (set >= m_barSets.count())) { |
|
431 | 465 | // No set, no value. |
|
432 | 466 | return 0; |
|
433 | 467 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
434 | 468 | // No category, no value. |
|
435 | 469 | return 0; |
|
436 | 470 | } |
|
437 | 471 | |
|
438 | 472 | return m_barSets.at(set)->at(category).y(); |
|
439 | 473 | } |
|
440 | 474 | |
|
441 | 475 | qreal QBarSeriesPrivate::percentageAt(int set, int category) |
|
442 | 476 | { |
|
443 | 477 | if ((set < 0) || (set >= m_barSets.count())) { |
|
444 | 478 | // No set, no value. |
|
445 | 479 | return 0; |
|
446 | 480 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
447 | 481 | // No category, no value. |
|
448 | 482 | return 0; |
|
449 | 483 | } |
|
450 | 484 | |
|
451 | 485 | qreal value = m_barSets.at(set)->at(category).y(); |
|
452 | 486 | qreal sum = categorySum(category); |
|
453 | 487 | if ( qFuzzyIsNull(sum) ) { |
|
454 | 488 | return 0; |
|
455 | 489 | } |
|
456 | 490 | |
|
457 | 491 | return value / sum; |
|
458 | 492 | } |
|
459 | 493 | |
|
460 | 494 | qreal QBarSeriesPrivate::categorySum(int category) |
|
461 | 495 | { |
|
462 | 496 | qreal sum(0); |
|
463 | 497 | int count = m_barSets.count(); // Count sets |
|
464 | 498 | for (int set = 0; set < count; set++) { |
|
465 | 499 | if (category < m_barSets.at(set)->count()) |
|
466 | 500 | sum += m_barSets.at(set)->at(category).y(); |
|
467 | 501 | } |
|
468 | 502 | return sum; |
|
469 | 503 | } |
|
470 | 504 | |
|
471 | 505 | qreal QBarSeriesPrivate::absoluteCategorySum(int category) |
|
472 | 506 | { |
|
473 | 507 | qreal sum(0); |
|
474 | 508 | int count = m_barSets.count(); // Count sets |
|
475 | 509 | for (int set = 0; set < count; set++) { |
|
476 | 510 | if (category < m_barSets.at(set)->count()) |
|
477 | 511 | sum += qAbs(m_barSets.at(set)->at(category).y()); |
|
478 | 512 | } |
|
479 | 513 | return sum; |
|
480 | 514 | } |
|
481 | 515 | |
|
482 | 516 | qreal QBarSeriesPrivate::maxCategorySum() |
|
483 | 517 | { |
|
484 | 518 | qreal max = INT_MIN; |
|
485 | 519 | int count = categoryCount(); |
|
486 | 520 | for (int i = 0; i < count; i++) { |
|
487 | 521 | qreal sum = categorySum(i); |
|
488 | 522 | if (sum > max) |
|
489 | 523 | max = sum; |
|
490 | 524 | } |
|
491 | 525 | return max; |
|
492 | 526 | } |
|
493 | 527 | |
|
494 | 528 | qreal QBarSeriesPrivate::minX() |
|
495 | 529 | { |
|
496 | 530 | if (m_barSets.count() <= 0) { |
|
497 | 531 | return 0; |
|
498 | 532 | } |
|
499 | 533 | qreal min = INT_MAX; |
|
500 | 534 | |
|
501 | 535 | for (int i = 0; i < m_barSets.count(); i++) { |
|
502 | 536 | int categoryCount = m_barSets.at(i)->count(); |
|
503 | 537 | for (int j = 0; j < categoryCount; j++) { |
|
504 | 538 | qreal temp = m_barSets.at(i)->at(j).x(); |
|
505 | 539 | if (temp < min) |
|
506 | 540 | min = temp; |
|
507 | 541 | } |
|
508 | 542 | } |
|
509 | 543 | return min; |
|
510 | 544 | } |
|
511 | 545 | |
|
512 | 546 | qreal QBarSeriesPrivate::maxX() |
|
513 | 547 | { |
|
514 | 548 | if (m_barSets.count() <= 0) { |
|
515 | 549 | return 0; |
|
516 | 550 | } |
|
517 | 551 | qreal max = INT_MIN; |
|
518 | 552 | |
|
519 | 553 | for (int i = 0; i < m_barSets.count(); i++) { |
|
520 | 554 | int categoryCount = m_barSets.at(i)->count(); |
|
521 | 555 | for (int j = 0; j < categoryCount; j++) { |
|
522 | 556 | qreal temp = m_barSets.at(i)->at(j).x(); |
|
523 | 557 | if (temp > max) |
|
524 | 558 | max = temp; |
|
525 | 559 | } |
|
526 | 560 | } |
|
527 | 561 | |
|
528 | 562 | return max; |
|
529 | 563 | } |
|
530 | 564 | |
|
531 | 565 | |
|
532 | 566 | void QBarSeriesPrivate::scaleDomain(Domain& domain) |
|
533 | 567 | { |
|
534 | 568 | qreal minX(domain.minX()); |
|
535 | 569 | qreal minY(domain.minY()); |
|
536 | 570 | qreal maxX(domain.maxX()); |
|
537 | 571 | qreal maxY(domain.maxY()); |
|
538 | 572 | int tickXCount(domain.tickXCount()); |
|
539 | 573 | int tickYCount(domain.tickYCount()); |
|
540 | 574 | |
|
541 | 575 | qreal seriesMinX = this->minX(); |
|
542 | 576 | qreal seriesMaxX = this->maxX(); |
|
543 | 577 | qreal y = max(); |
|
544 | 578 | minX = qMin(minX, seriesMinX - 0.5); |
|
545 | 579 | minY = qMin(minY, y); |
|
546 | 580 | maxX = qMax(maxX, seriesMaxX + 0.5); |
|
547 | 581 | maxY = qMax(maxY, y); |
|
548 | 582 | tickXCount = categoryCount()+1; |
|
549 | 583 | |
|
550 | 584 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
551 | 585 | } |
|
552 | 586 | |
|
553 | 587 | Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
554 | 588 | { |
|
555 | 589 | Q_Q(QBarSeries); |
|
556 | 590 | |
|
557 | 591 | BarChartItem* bar = new BarChartItem(q,presenter); |
|
558 | 592 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
559 | 593 | presenter->animator()->addAnimation(bar); |
|
560 | 594 | } |
|
561 | 595 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
562 | 596 | return bar; |
|
563 | 597 | |
|
564 | 598 | } |
|
565 | 599 | |
|
566 | 600 | QList<LegendMarker*> QBarSeriesPrivate::createLegendMarker(QLegend* legend) |
|
567 | 601 | { |
|
568 | 602 | Q_Q(QBarSeries); |
|
569 | 603 | QList<LegendMarker*> markers; |
|
570 | 604 | foreach(QBarSet* set, q->barSets()) { |
|
571 | 605 | BarLegendMarker* marker = new BarLegendMarker(q,set,legend); |
|
572 | 606 | markers << marker; |
|
573 | 607 | } |
|
574 | 608 | |
|
575 | 609 | return markers; |
|
576 | 610 | } |
|
577 | 611 | |
|
578 | 612 | bool QBarSeriesPrivate::append(QBarSet *set) |
|
579 | 613 | { |
|
580 | 614 | Q_Q(QBarSeries); |
|
581 | 615 | if ((m_barSets.contains(set)) || (set == 0)) { |
|
582 | 616 | // Fail if set is already in list or set is null. |
|
583 | 617 | return false; |
|
584 | 618 | } |
|
585 | 619 | m_barSets.append(set); |
|
586 | 620 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
587 | 621 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
588 | 622 | emit restructuredBars(); // this notifies barchartitem |
|
589 | 623 | if (m_dataset) { |
|
590 | 624 | m_dataset->updateSeries(q); // this notifies legend |
|
591 | 625 | } |
|
592 | 626 | return true; |
|
593 | 627 | } |
|
594 | 628 | |
|
595 | 629 | bool QBarSeriesPrivate::remove(QBarSet *set) |
|
596 | 630 | { |
|
597 | 631 | Q_Q(QBarSeries); |
|
598 | 632 | if (!m_barSets.contains(set)) { |
|
599 | 633 | // Fail if set is not in list |
|
600 | 634 | return false; |
|
601 | 635 | } |
|
602 | 636 | m_barSets.removeOne(set); |
|
603 | 637 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
604 | 638 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
605 | 639 | emit restructuredBars(); // this notifies barchartitem |
|
606 | 640 | if (m_dataset) { |
|
607 | 641 | m_dataset->updateSeries(q); // this notifies legend |
|
608 | 642 | } |
|
609 | 643 | return true; |
|
610 | 644 | } |
|
611 | 645 | |
|
612 | 646 | bool QBarSeriesPrivate::append(QList<QBarSet* > sets) |
|
613 | 647 | { |
|
614 | 648 | Q_Q(QBarSeries); |
|
615 | 649 | foreach (QBarSet* set, sets) { |
|
616 | 650 | if ((set == 0) || (m_barSets.contains(set))) { |
|
617 | 651 | // Fail if any of the sets is null or is already appended. |
|
618 | 652 | return false; |
|
619 | 653 | } |
|
620 | 654 | if (sets.count(set) != 1) { |
|
621 | 655 | // Also fail if same set is more than once in given list. |
|
622 | 656 | return false; |
|
623 | 657 | } |
|
624 | 658 | } |
|
625 | 659 | |
|
626 | 660 | foreach (QBarSet* set, sets) { |
|
627 | 661 | m_barSets.append(set); |
|
628 | 662 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
629 | 663 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
630 | 664 | } |
|
631 | 665 | emit restructuredBars(); // this notifies barchartitem |
|
632 | 666 | if (m_dataset) { |
|
633 | 667 | m_dataset->updateSeries(q); // this notifies legend |
|
634 | 668 | } |
|
635 | 669 | return true; |
|
636 | 670 | } |
|
637 | 671 | |
|
638 | 672 | bool QBarSeriesPrivate::remove(QList<QBarSet* > sets) |
|
639 | 673 | { |
|
640 | 674 | Q_Q(QBarSeries); |
|
641 | 675 | if (sets.count() == 0) { |
|
642 | 676 | return false; |
|
643 | 677 | } |
|
644 | 678 | foreach (QBarSet* set, sets) { |
|
645 | 679 | if ((set == 0) || (!m_barSets.contains(set))) { |
|
646 | 680 | // Fail if any of the sets is null or is not in series |
|
647 | 681 | return false; |
|
648 | 682 | } |
|
649 | 683 | if (sets.count(set) != 1) { |
|
650 | 684 | // Also fail if same set is more than once in given list. |
|
651 | 685 | return false; |
|
652 | 686 | } |
|
653 | 687 | } |
|
654 | 688 | |
|
655 | 689 | foreach (QBarSet* set, sets) { |
|
656 | 690 | m_barSets.removeOne(set); |
|
657 | 691 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
658 | 692 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
659 | 693 | } |
|
660 | 694 | |
|
661 | 695 | emit restructuredBars(); // this notifies barchartitem |
|
662 | 696 | if (m_dataset) { |
|
663 | 697 | m_dataset->updateSeries(q); // this notifies legend |
|
664 | 698 | } |
|
665 | 699 | return true; |
|
666 | 700 | } |
|
667 | 701 | |
|
668 | 702 | bool QBarSeriesPrivate::insert(int index, QBarSet *set) |
|
669 | 703 | { |
|
670 | 704 | Q_Q(QBarSeries); |
|
671 | 705 | if ((m_barSets.contains(set)) || (set == 0)) { |
|
672 | 706 | // Fail if set is already in list or set is null. |
|
673 | 707 | return false; |
|
674 | 708 | } |
|
675 | 709 | m_barSets.insert(index, set); |
|
676 | 710 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
677 | 711 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
678 | 712 | emit restructuredBars(); // this notifies barchartitem |
|
679 | 713 | if (m_dataset) { |
|
680 | 714 | m_dataset->updateSeries(q); // this notifies legend |
|
681 | 715 | } |
|
682 | 716 | return true; |
|
683 | 717 | } |
|
684 | 718 | |
|
685 | 719 | #include "moc_qbarseries.cpp" |
|
686 | 720 | #include "moc_qbarseries_p.cpp" |
|
687 | 721 | |
|
688 | 722 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,725 +1,751 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qpieseries.h" |
|
22 | 22 | #include "qpieseries_p.h" |
|
23 | 23 | #include "qpieslice.h" |
|
24 | 24 | #include "qpieslice_p.h" |
|
25 | 25 | #include "pieslicedata_p.h" |
|
26 | 26 | #include "chartdataset_p.h" |
|
27 | 27 | #include "charttheme_p.h" |
|
28 | 28 | #include "chartanimator_p.h" |
|
29 | 29 | #include "legendmarker_p.h" |
|
30 | 30 | |
|
31 | 31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | 32 | |
|
33 | 33 | /*! |
|
34 | 34 | \class QPieSeries |
|
35 | 35 | \brief Pie series API for QtCommercial Charts |
|
36 | 36 | |
|
37 | 37 | The pie series defines a pie chart which consists of pie slices which are defined as QPieSlice objects. |
|
38 | 38 | The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices. |
|
39 | 39 | The actual slice size is determined by that relative value. |
|
40 | 40 | |
|
41 | 41 | Pie size and position on the chart is controlled by using relative values which range from 0.0 to 1.0 |
|
42 | 42 | These relate to the actual chart rectangle. |
|
43 | 43 | |
|
44 | 44 | By default the pie is defined as a full pie but it can also be a partial pie. |
|
45 | 45 | This can be done by setting a starting angle and angle span to the series. |
|
46 | 46 | Full pie is 360 degrees where 0 is at 12 a'clock. |
|
47 | 47 | |
|
48 | 48 | See the \l {PieChart Example} {pie chart example} to learn how to create a simple pie chart. |
|
49 | 49 | \image examples_piechart.png |
|
50 | 50 | */ |
|
51 | 51 | /*! |
|
52 | 52 | \qmlclass PieSeries QPieSeries |
|
53 | \inherits AbstractSeries | |
|
53 | 54 | |
|
54 | 55 | The following QML shows how to create a simple pie chart. |
|
55 | 56 | |
|
56 | 57 | \snippet ../demos/qmlchart/qml/qmlchart/View1.qml 1 |
|
57 | 58 | |
|
58 | 59 | \beginfloatleft |
|
59 | 60 | \image demos_qmlchart1.png |
|
60 | 61 | \endfloat |
|
61 | 62 | \clearfloat |
|
62 | 63 | */ |
|
63 | 64 | |
|
64 | 65 | /*! |
|
65 | 66 | \property QPieSeries::horizontalPosition |
|
66 | 67 | \brief Defines the horizontal position of the pie. |
|
67 | 68 | |
|
68 | 69 | The value is a relative value to the chart rectangle where: |
|
69 | 70 | |
|
70 | 71 | \list |
|
71 | 72 | \o 0.0 is the absolute left. |
|
72 | 73 | \o 1.0 is the absolute right. |
|
73 | 74 | \endlist |
|
74 | 75 | Default value is 0.5 (center). |
|
75 | 76 | \sa verticalPosition |
|
76 | 77 | */ |
|
77 | 78 | |
|
78 | 79 | /*! |
|
79 | 80 | \qmlproperty real PieSeries::horizontalPosition |
|
80 | 81 | |
|
81 | 82 | Defines the horizontal position of the pie. |
|
82 | 83 | |
|
83 | 84 | The value is a relative value to the chart rectangle where: |
|
84 | 85 | |
|
85 | 86 | \list |
|
86 | 87 | \o 0.0 is the absolute left. |
|
87 | 88 | \o 1.0 is the absolute right. |
|
88 | 89 | \endlist |
|
89 | 90 | Default value is 0.5 (center). |
|
90 | 91 | \sa verticalPosition |
|
91 | 92 | */ |
|
92 | 93 | |
|
93 | 94 | /*! |
|
94 | 95 | \property QPieSeries::verticalPosition |
|
95 | 96 | \brief Defines the vertical position of the pie. |
|
96 | 97 | |
|
97 | 98 | The value is a relative value to the chart rectangle where: |
|
98 | 99 | |
|
99 | 100 | \list |
|
100 | 101 | \o 0.0 is the absolute top. |
|
101 | 102 | \o 1.0 is the absolute bottom. |
|
102 | 103 | \endlist |
|
103 | 104 | Default value is 0.5 (center). |
|
104 | 105 | \sa horizontalPosition |
|
105 | 106 | */ |
|
106 | 107 | |
|
107 | 108 | /*! |
|
108 | 109 | \qmlproperty real PieSeries::verticalPosition |
|
109 | 110 | |
|
110 | 111 | Defines the vertical position of the pie. |
|
111 | 112 | |
|
112 | 113 | The value is a relative value to the chart rectangle where: |
|
113 | 114 | |
|
114 | 115 | \list |
|
115 | 116 | \o 0.0 is the absolute top. |
|
116 | 117 | \o 1.0 is the absolute bottom. |
|
117 | 118 | \endlist |
|
118 | 119 | Default value is 0.5 (center). |
|
119 | 120 | \sa horizontalPosition |
|
120 | 121 | */ |
|
121 | 122 | |
|
122 | 123 | /*! |
|
123 | 124 | \property QPieSeries::size |
|
124 | 125 | \brief Defines the pie size. |
|
125 | 126 | |
|
126 | 127 | The value is a relative value to the chart rectangle where: |
|
127 | 128 | |
|
128 | 129 | \list |
|
129 | 130 | \o 0.0 is the minimum size (pie not drawn). |
|
130 | 131 | \o 1.0 is the maximum size that can fit the chart. |
|
131 | 132 | \endlist |
|
132 | 133 | |
|
133 | 134 | Default value is 0.7. |
|
134 | 135 | */ |
|
135 | 136 | |
|
136 | 137 | /*! |
|
137 | 138 | \qmlproperty real PieSeries::size |
|
138 | 139 | |
|
139 | 140 | Defines the pie size. |
|
140 | 141 | |
|
141 | 142 | The value is a relative value to the chart rectangle where: |
|
142 | 143 | |
|
143 | 144 | \list |
|
144 | 145 | \o 0.0 is the minimum size (pie not drawn). |
|
145 | 146 | \o 1.0 is the maximum size that can fit the chart. |
|
146 | 147 | \endlist |
|
147 | 148 | |
|
148 | 149 | Default value is 0.7. |
|
149 | 150 | */ |
|
150 | 151 | |
|
151 | 152 | /*! |
|
152 | 153 | \property QPieSeries::startAngle |
|
153 | 154 | \brief Defines the starting angle of the pie. |
|
154 | 155 | |
|
155 | 156 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
156 | 157 | |
|
157 | 158 | Default is value is 0. |
|
158 | 159 | */ |
|
159 | 160 | |
|
160 | 161 | /*! |
|
161 | 162 | \qmlproperty real PieSeries::startAngle |
|
162 | 163 | |
|
163 | 164 | Defines the starting angle of the pie. |
|
164 | 165 | |
|
165 | 166 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
166 | 167 | |
|
167 | 168 | Default is value is 0. |
|
168 | 169 | */ |
|
169 | 170 | |
|
170 | 171 | /*! |
|
171 | 172 | \property QPieSeries::endAngle |
|
172 | 173 | \brief Defines the ending angle of the pie. |
|
173 | 174 | |
|
174 | 175 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
175 | 176 | |
|
176 | 177 | Default is value is 360. |
|
177 | 178 | */ |
|
178 | 179 | |
|
179 | 180 | /*! |
|
180 | 181 | \qmlproperty real PieSeries::endAngle |
|
181 | 182 | |
|
182 | 183 | Defines the ending angle of the pie. |
|
183 | 184 | |
|
184 | 185 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
185 | 186 | |
|
186 | 187 | Default is value is 360. |
|
187 | 188 | */ |
|
188 | 189 | |
|
189 | 190 | /*! |
|
190 | 191 | \property QPieSeries::count |
|
191 | 192 | |
|
192 | 193 | Number of slices in the series. |
|
193 | 194 | */ |
|
194 | 195 | |
|
195 | 196 | /*! |
|
196 | 197 | \qmlproperty int PieSeries::count |
|
197 | 198 | |
|
198 | 199 | Number of slices in the series. |
|
199 | 200 | */ |
|
200 | 201 | |
|
201 | 202 | /*! |
|
202 | 203 | \fn void QPieSeries::countChanged() |
|
203 | 204 | |
|
204 | 205 | Emitted when the slice count has changed. |
|
205 | 206 | |
|
206 | 207 | \sa count |
|
207 | 208 | */ |
|
208 | 209 | |
|
209 | 210 | /*! |
|
210 | 211 | \property QPieSeries::sum |
|
211 | 212 | |
|
212 | 213 | Sum of all slices. |
|
213 | 214 | |
|
214 | 215 | The series keeps track of the sum of all slices it holds. |
|
215 | 216 | */ |
|
216 | 217 | |
|
217 | 218 | /*! |
|
218 | 219 | \qmlproperty real PieSeries::sum |
|
219 | 220 | |
|
220 | 221 | Sum of all slices. |
|
221 | 222 | |
|
222 | 223 | The series keeps track of the sum of all slices it holds. |
|
223 | 224 | */ |
|
224 | 225 | |
|
225 | 226 | /*! |
|
226 | 227 | \fn void QPieSeries::sumChanged() |
|
227 | 228 | |
|
228 | 229 | Emitted when the sum of all slices has changed. |
|
229 | 230 | |
|
230 | 231 | \sa sum |
|
231 | 232 | */ |
|
232 | 233 | |
|
233 | 234 | /*! |
|
234 | 235 | \fn void QPieSeries::added(QList<QPieSlice*> slices) |
|
235 | 236 | |
|
236 | 237 | This signal is emitted when \a slices have been added to the series. |
|
237 | 238 | |
|
238 | 239 | \sa append(), insert() |
|
239 | 240 | */ |
|
240 | 241 | /*! |
|
241 | 242 | \qmlsignal PieSeries::added(PieSlice slice) |
|
242 | 243 | Emitted when \a slice has been added to the series. |
|
243 | 244 | */ |
|
244 | 245 | |
|
245 | 246 | /*! |
|
246 | 247 | \fn void QPieSeries::removed(QList<QPieSlice*> slices) |
|
247 | 248 | This signal is emitted when \a slices have been removed from the series. |
|
248 | 249 | \sa remove() |
|
249 | 250 | */ |
|
250 | 251 | /*! |
|
251 | 252 | \qmlsignal PieSeries::removed(PieSlice slice) |
|
252 | 253 | Emitted when \a slice has been removed from the series. |
|
253 | 254 | */ |
|
254 | 255 | |
|
255 | 256 | /*! |
|
256 | 257 | \fn void QPieSeries::clicked(QPieSlice* slice) |
|
257 | 258 | |
|
258 | 259 | This signal is emitted when a \a slice has been clicked. |
|
259 | 260 | |
|
260 | 261 | \sa QPieSlice::clicked() |
|
261 | 262 | */ |
|
262 | 263 | |
|
263 | 264 | /*! |
|
264 | 265 | \fn void QPieSeries::hovered(QPieSlice* slice, bool state) |
|
265 | 266 | |
|
266 | 267 | This signal is emitted when user has hovered over or away from the \a slice. |
|
267 | 268 | |
|
268 | 269 | \a state is true when user has hovered over the slice and false when hover has moved away from the slice. |
|
269 | 270 | |
|
270 | 271 | \sa QPieSlice::hovered() |
|
271 | 272 | */ |
|
272 | 273 | |
|
273 | 274 | /*! |
|
275 | \qmlmethod PieSlice PieSeries::at(int index) | |
|
276 | Returns slice at \a index. Returns null if the index is not valid. | |
|
277 | */ | |
|
278 | ||
|
279 | /*! | |
|
280 | \qmlmethod PieSlice PieSeries::find(string label) | |
|
281 | Returns the first slice with \a label. Returns null if the index is not valid. | |
|
282 | */ | |
|
283 | ||
|
284 | /*! | |
|
285 | \qmlmethod PieSlice PieSeries::append(string label, real value) | |
|
286 | Adds a new slice with \a label and \a value to the pie. | |
|
287 | */ | |
|
288 | ||
|
289 | /*! | |
|
290 | \qmlmethod bool PieSeries::remove(PieSlice slice) | |
|
291 | Removes the \a slice from the pie. Returns true if the removal was successfull, false otherwise. | |
|
292 | */ | |
|
293 | ||
|
294 | /*! | |
|
295 | \qmlmethod PieSeries::clear() | |
|
296 | Removes all slices from the pie. | |
|
297 | */ | |
|
298 | ||
|
299 | /*! | |
|
274 | 300 | Constructs a series object which is a child of \a parent. |
|
275 | 301 | */ |
|
276 | 302 | QPieSeries::QPieSeries(QObject *parent) : |
|
277 | 303 | QAbstractSeries(*new QPieSeriesPrivate(this),parent) |
|
278 | 304 | { |
|
279 | 305 | |
|
280 | 306 | } |
|
281 | 307 | |
|
282 | 308 | /*! |
|
283 | 309 | Destroys the series and its slices. |
|
284 | 310 | */ |
|
285 | 311 | QPieSeries::~QPieSeries() |
|
286 | 312 | { |
|
287 | 313 | // NOTE: d_prt destroyed by QObject |
|
288 | 314 | } |
|
289 | 315 | |
|
290 | 316 | /*! |
|
291 | 317 | Returns QChartSeries::SeriesTypePie. |
|
292 | 318 | */ |
|
293 | 319 | QAbstractSeries::SeriesType QPieSeries::type() const |
|
294 | 320 | { |
|
295 | 321 | return QAbstractSeries::SeriesTypePie; |
|
296 | 322 | } |
|
297 | 323 | |
|
298 | 324 | /*! |
|
299 | 325 | Appends a single \a slice to the series. |
|
300 | 326 | Slice ownership is passed to the series. |
|
301 | 327 | |
|
302 | 328 | Returns true if append was succesfull. |
|
303 | 329 | */ |
|
304 | 330 | bool QPieSeries::append(QPieSlice* slice) |
|
305 | 331 | { |
|
306 | 332 | return append(QList<QPieSlice*>() << slice); |
|
307 | 333 | } |
|
308 | 334 | |
|
309 | 335 | /*! |
|
310 | 336 | Appends an array of \a slices to the series. |
|
311 | 337 | Slice ownership is passed to the series. |
|
312 | 338 | |
|
313 | 339 | Returns true if append was successfull. |
|
314 | 340 | */ |
|
315 | 341 | bool QPieSeries::append(QList<QPieSlice*> slices) |
|
316 | 342 | { |
|
317 | 343 | Q_D(QPieSeries); |
|
318 | 344 | |
|
319 | 345 | if (slices.count() == 0) |
|
320 | 346 | return false; |
|
321 | 347 | |
|
322 | 348 | foreach (QPieSlice* s, slices) { |
|
323 | 349 | if (!s || d->m_slices.contains(s)) |
|
324 | 350 | return false; |
|
325 | 351 | if (s->series()) // already added to some series |
|
326 | 352 | return false; |
|
327 | 353 | } |
|
328 | 354 | |
|
329 | 355 | foreach (QPieSlice* s, slices) { |
|
330 | 356 | s->setParent(this); |
|
331 | 357 | QPieSlicePrivate::fromSlice(s)->m_series = this; |
|
332 | 358 | d->m_slices << s; |
|
333 | 359 | } |
|
334 | 360 | |
|
335 | 361 | d->updateDerivativeData(); |
|
336 | 362 | |
|
337 | 363 | foreach (QPieSlice* s, slices) { |
|
338 | 364 | connect(s, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged())); |
|
339 | 365 | connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked())); |
|
340 | 366 | connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool))); |
|
341 | 367 | } |
|
342 | 368 | |
|
343 | 369 | emit added(slices); |
|
344 | 370 | emit countChanged(); |
|
345 | 371 | |
|
346 | 372 | return true; |
|
347 | 373 | } |
|
348 | 374 | |
|
349 | 375 | /*! |
|
350 | 376 | Appends a single \a slice to the series and returns a reference to the series. |
|
351 | 377 | Slice ownership is passed to the series. |
|
352 | 378 | */ |
|
353 | 379 | QPieSeries& QPieSeries::operator << (QPieSlice* slice) |
|
354 | 380 | { |
|
355 | 381 | append(slice); |
|
356 | 382 | return *this; |
|
357 | 383 | } |
|
358 | 384 | |
|
359 | 385 | |
|
360 | 386 | /*! |
|
361 | 387 | Appends a single slice to the series with give \a value and \a label. |
|
362 | 388 | Slice ownership is passed to the series. |
|
363 | 389 | */ |
|
364 | 390 | QPieSlice* QPieSeries::append(QString label, qreal value) |
|
365 | 391 | { |
|
366 | 392 | QPieSlice* slice = new QPieSlice(label, value); |
|
367 | 393 | append(slice); |
|
368 | 394 | return slice; |
|
369 | 395 | } |
|
370 | 396 | |
|
371 | 397 | /*! |
|
372 | 398 | Inserts a single \a slice to the series before the slice at \a index position. |
|
373 | 399 | Slice ownership is passed to the series. |
|
374 | 400 | |
|
375 | 401 | Returns true if insert was successfull. |
|
376 | 402 | */ |
|
377 | 403 | bool QPieSeries::insert(int index, QPieSlice* slice) |
|
378 | 404 | { |
|
379 | 405 | Q_D(QPieSeries); |
|
380 | 406 | |
|
381 | 407 | if (index < 0 || index > d->m_slices.count()) |
|
382 | 408 | return false; |
|
383 | 409 | |
|
384 | 410 | if (!slice || d->m_slices.contains(slice)) |
|
385 | 411 | return false; |
|
386 | 412 | |
|
387 | 413 | if (slice->series()) // already added to some series |
|
388 | 414 | return false; |
|
389 | 415 | |
|
390 | 416 | slice->setParent(this); |
|
391 | 417 | QPieSlicePrivate::fromSlice(slice)->m_series = this; |
|
392 | 418 | d->m_slices.insert(index, slice); |
|
393 | 419 | |
|
394 | 420 | d->updateDerivativeData(); |
|
395 | 421 | |
|
396 | 422 | connect(slice, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged())); |
|
397 | 423 | connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked())); |
|
398 | 424 | connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool))); |
|
399 | 425 | |
|
400 | 426 | emit added(QList<QPieSlice*>() << slice); |
|
401 | 427 | emit countChanged(); |
|
402 | 428 | |
|
403 | 429 | return true; |
|
404 | 430 | } |
|
405 | 431 | |
|
406 | 432 | /*! |
|
407 | 433 | Removes a single \a slice from the series and deletes the slice. |
|
408 | 434 | |
|
409 | 435 | Do not reference the pointer after this call. |
|
410 | 436 | |
|
411 | 437 | Returns true if remove was successfull. |
|
412 | 438 | */ |
|
413 | 439 | bool QPieSeries::remove(QPieSlice* slice) |
|
414 | 440 | { |
|
415 | 441 | Q_D(QPieSeries); |
|
416 | 442 | |
|
417 | 443 | if (!d->m_slices.removeOne(slice)) |
|
418 | 444 | return false; |
|
419 | 445 | |
|
420 | 446 | d->updateDerivativeData(); |
|
421 | 447 | |
|
422 | 448 | emit removed(QList<QPieSlice*>() << slice); |
|
423 | 449 | emit countChanged(); |
|
424 | 450 | |
|
425 | 451 | delete slice; |
|
426 | 452 | slice = 0; |
|
427 | 453 | |
|
428 | 454 | return true; |
|
429 | 455 | } |
|
430 | 456 | |
|
431 | 457 | /*! |
|
432 | 458 | Clears all slices from the series. |
|
433 | 459 | */ |
|
434 | 460 | void QPieSeries::clear() |
|
435 | 461 | { |
|
436 | 462 | Q_D(QPieSeries); |
|
437 | 463 | if (d->m_slices.count() == 0) |
|
438 | 464 | return; |
|
439 | 465 | |
|
440 | 466 | QList<QPieSlice*> slices = d->m_slices; |
|
441 | 467 | foreach (QPieSlice* s, d->m_slices) { |
|
442 | 468 | d->m_slices.removeOne(s); |
|
443 | 469 | delete s; |
|
444 | 470 | } |
|
445 | 471 | |
|
446 | 472 | d->updateDerivativeData(); |
|
447 | 473 | |
|
448 | 474 | emit removed(slices); |
|
449 | 475 | emit countChanged(); |
|
450 | 476 | } |
|
451 | 477 | |
|
452 | 478 | /*! |
|
453 | 479 | Returns a list of slices that belong to this series. |
|
454 | 480 | */ |
|
455 | 481 | QList<QPieSlice*> QPieSeries::slices() const |
|
456 | 482 | { |
|
457 | 483 | Q_D(const QPieSeries); |
|
458 | 484 | return d->m_slices; |
|
459 | 485 | } |
|
460 | 486 | |
|
461 | 487 | /*! |
|
462 | 488 | returns the number of the slices in this series. |
|
463 | 489 | */ |
|
464 | 490 | int QPieSeries::count() const |
|
465 | 491 | { |
|
466 | 492 | Q_D(const QPieSeries); |
|
467 | 493 | return d->m_slices.count(); |
|
468 | 494 | } |
|
469 | 495 | |
|
470 | 496 | /*! |
|
471 | 497 | Returns true is the series is empty. |
|
472 | 498 | */ |
|
473 | 499 | bool QPieSeries::isEmpty() const |
|
474 | 500 | { |
|
475 | 501 | Q_D(const QPieSeries); |
|
476 | 502 | return d->m_slices.isEmpty(); |
|
477 | 503 | } |
|
478 | 504 | |
|
479 | 505 | /*! |
|
480 | 506 | Returns the sum of all slice values in this series. |
|
481 | 507 | |
|
482 | 508 | \sa QPieSlice::value(), QPieSlice::setValue(), QPieSlice::percentage() |
|
483 | 509 | */ |
|
484 | 510 | qreal QPieSeries::sum() const |
|
485 | 511 | { |
|
486 | 512 | Q_D(const QPieSeries); |
|
487 | 513 | return d->m_sum; |
|
488 | 514 | } |
|
489 | 515 | |
|
490 | 516 | void QPieSeries::setHorizontalPosition(qreal relativePosition) |
|
491 | 517 | { |
|
492 | 518 | Q_D(QPieSeries); |
|
493 | 519 | |
|
494 | 520 | if (relativePosition < 0.0) |
|
495 | 521 | relativePosition = 0.0; |
|
496 | 522 | if (relativePosition > 1.0) |
|
497 | 523 | relativePosition = 1.0; |
|
498 | 524 | |
|
499 | 525 | if (!qFuzzyIsNull(d->m_pieRelativeHorPos - relativePosition)) { |
|
500 | 526 | d->m_pieRelativeHorPos = relativePosition; |
|
501 | 527 | emit d->horizontalPositionChanged(); |
|
502 | 528 | } |
|
503 | 529 | } |
|
504 | 530 | |
|
505 | 531 | qreal QPieSeries::horizontalPosition() const |
|
506 | 532 | { |
|
507 | 533 | Q_D(const QPieSeries); |
|
508 | 534 | return d->m_pieRelativeHorPos; |
|
509 | 535 | } |
|
510 | 536 | |
|
511 | 537 | void QPieSeries::setVerticalPosition(qreal relativePosition) |
|
512 | 538 | { |
|
513 | 539 | Q_D(QPieSeries); |
|
514 | 540 | |
|
515 | 541 | if (relativePosition < 0.0) |
|
516 | 542 | relativePosition = 0.0; |
|
517 | 543 | if (relativePosition > 1.0) |
|
518 | 544 | relativePosition = 1.0; |
|
519 | 545 | |
|
520 | 546 | if (!qFuzzyIsNull(d->m_pieRelativeVerPos - relativePosition)) { |
|
521 | 547 | d->m_pieRelativeVerPos = relativePosition; |
|
522 | 548 | emit d->verticalPositionChanged(); |
|
523 | 549 | } |
|
524 | 550 | } |
|
525 | 551 | |
|
526 | 552 | qreal QPieSeries::verticalPosition() const |
|
527 | 553 | { |
|
528 | 554 | Q_D(const QPieSeries); |
|
529 | 555 | return d->m_pieRelativeVerPos; |
|
530 | 556 | } |
|
531 | 557 | |
|
532 | 558 | void QPieSeries::setPieSize(qreal relativeSize) |
|
533 | 559 | { |
|
534 | 560 | Q_D(QPieSeries); |
|
535 | 561 | |
|
536 | 562 | if (relativeSize < 0.0) |
|
537 | 563 | relativeSize = 0.0; |
|
538 | 564 | if (relativeSize > 1.0) |
|
539 | 565 | relativeSize = 1.0; |
|
540 | 566 | |
|
541 | 567 | if (!qFuzzyIsNull(d->m_pieRelativeSize - relativeSize)) { |
|
542 | 568 | d->m_pieRelativeSize = relativeSize; |
|
543 | 569 | emit d->pieSizeChanged(); |
|
544 | 570 | } |
|
545 | 571 | } |
|
546 | 572 | |
|
547 | 573 | qreal QPieSeries::pieSize() const |
|
548 | 574 | { |
|
549 | 575 | Q_D(const QPieSeries); |
|
550 | 576 | return d->m_pieRelativeSize; |
|
551 | 577 | } |
|
552 | 578 | |
|
553 | 579 | |
|
554 | 580 | void QPieSeries::setPieStartAngle(qreal angle) |
|
555 | 581 | { |
|
556 | 582 | Q_D(QPieSeries); |
|
557 | 583 | if (qFuzzyIsNull(d->m_pieStartAngle - angle)) |
|
558 | 584 | return; |
|
559 | 585 | d->m_pieStartAngle = angle; |
|
560 | 586 | d->updateDerivativeData(); |
|
561 | 587 | emit d->pieStartAngleChanged(); |
|
562 | 588 | } |
|
563 | 589 | |
|
564 | 590 | qreal QPieSeries::pieStartAngle() const |
|
565 | 591 | { |
|
566 | 592 | Q_D(const QPieSeries); |
|
567 | 593 | return d->m_pieStartAngle; |
|
568 | 594 | } |
|
569 | 595 | |
|
570 | 596 | /*! |
|
571 | 597 | Sets the end angle of the pie. |
|
572 | 598 | |
|
573 | 599 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
574 | 600 | |
|
575 | 601 | \a angle must be greater than start angle. |
|
576 | 602 | |
|
577 | 603 | \sa pieEndAngle(), pieStartAngle(), setPieStartAngle() |
|
578 | 604 | */ |
|
579 | 605 | void QPieSeries::setPieEndAngle(qreal angle) |
|
580 | 606 | { |
|
581 | 607 | Q_D(QPieSeries); |
|
582 | 608 | if (qFuzzyIsNull(d->m_pieEndAngle - angle)) |
|
583 | 609 | return; |
|
584 | 610 | d->m_pieEndAngle = angle; |
|
585 | 611 | d->updateDerivativeData(); |
|
586 | 612 | emit d->pieEndAngleChanged(); |
|
587 | 613 | } |
|
588 | 614 | |
|
589 | 615 | /*! |
|
590 | 616 | Returns the end angle of the pie. |
|
591 | 617 | |
|
592 | 618 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
593 | 619 | |
|
594 | 620 | \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle() |
|
595 | 621 | */ |
|
596 | 622 | qreal QPieSeries::pieEndAngle() const |
|
597 | 623 | { |
|
598 | 624 | Q_D(const QPieSeries); |
|
599 | 625 | return d->m_pieEndAngle; |
|
600 | 626 | } |
|
601 | 627 | |
|
602 | 628 | /*! |
|
603 | 629 | Sets the all the slice labels \a visible or invisible. |
|
604 | 630 | |
|
605 | 631 | Note that this affects only the current slices in the series. |
|
606 | 632 | If user adds a new slice the default label visibility is false. |
|
607 | 633 | |
|
608 | 634 | \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible() |
|
609 | 635 | */ |
|
610 | 636 | void QPieSeries::setLabelsVisible(bool visible) |
|
611 | 637 | { |
|
612 | 638 | Q_D(QPieSeries); |
|
613 | 639 | foreach (QPieSlice* s, d->m_slices) |
|
614 | 640 | s->setLabelVisible(visible); |
|
615 | 641 | } |
|
616 | 642 | |
|
617 | 643 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
618 | 644 | |
|
619 | 645 | |
|
620 | 646 | QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) : |
|
621 | 647 | QAbstractSeriesPrivate(parent), |
|
622 | 648 | m_pieRelativeHorPos(0.5), |
|
623 | 649 | m_pieRelativeVerPos(0.5), |
|
624 | 650 | m_pieRelativeSize(0.7), |
|
625 | 651 | m_pieStartAngle(0), |
|
626 | 652 | m_pieEndAngle(360), |
|
627 | 653 | m_sum(0) |
|
628 | 654 | { |
|
629 | 655 | } |
|
630 | 656 | |
|
631 | 657 | QPieSeriesPrivate::~QPieSeriesPrivate() |
|
632 | 658 | { |
|
633 | 659 | } |
|
634 | 660 | |
|
635 | 661 | void QPieSeriesPrivate::updateDerivativeData() |
|
636 | 662 | { |
|
637 | 663 | // calculate sum of all slices |
|
638 | 664 | qreal sum = 0; |
|
639 | 665 | foreach (QPieSlice* s, m_slices) |
|
640 | 666 | sum += s->value(); |
|
641 | 667 | |
|
642 | 668 | if (!qFuzzyIsNull(m_sum - sum)) { |
|
643 | 669 | m_sum = sum; |
|
644 | 670 | emit q_func()->sumChanged(); |
|
645 | 671 | } |
|
646 | 672 | |
|
647 | 673 | // nothing to show.. |
|
648 | 674 | if (qFuzzyIsNull(m_sum)) |
|
649 | 675 | return; |
|
650 | 676 | |
|
651 | 677 | // update slice attributes |
|
652 | 678 | qreal sliceAngle = m_pieStartAngle; |
|
653 | 679 | qreal pieSpan = m_pieEndAngle - m_pieStartAngle; |
|
654 | 680 | QVector<QPieSlice*> changed; |
|
655 | 681 | foreach (QPieSlice* s, m_slices) { |
|
656 | 682 | QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s); |
|
657 | 683 | d->setPercentage(s->value() / m_sum); |
|
658 | 684 | d->setStartAngle(sliceAngle); |
|
659 | 685 | d->setAngleSpan(pieSpan * s->percentage()); |
|
660 | 686 | sliceAngle += s->angleSpan(); |
|
661 | 687 | } |
|
662 | 688 | |
|
663 | 689 | |
|
664 | 690 | emit calculatedDataChanged(); |
|
665 | 691 | } |
|
666 | 692 | |
|
667 | 693 | QPieSeriesPrivate* QPieSeriesPrivate::fromSeries(QPieSeries *series) |
|
668 | 694 | { |
|
669 | 695 | return series->d_func(); |
|
670 | 696 | } |
|
671 | 697 | |
|
672 | 698 | void QPieSeriesPrivate::sliceValueChanged() |
|
673 | 699 | { |
|
674 | 700 | Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender()))); |
|
675 | 701 | updateDerivativeData(); |
|
676 | 702 | } |
|
677 | 703 | |
|
678 | 704 | void QPieSeriesPrivate::sliceClicked() |
|
679 | 705 | { |
|
680 | 706 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); |
|
681 | 707 | Q_ASSERT(m_slices.contains(slice)); |
|
682 | 708 | Q_Q(QPieSeries); |
|
683 | 709 | emit q->clicked(slice); |
|
684 | 710 | } |
|
685 | 711 | |
|
686 | 712 | void QPieSeriesPrivate::sliceHovered(bool state) |
|
687 | 713 | { |
|
688 | 714 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); |
|
689 | 715 | Q_ASSERT(m_slices.contains(slice)); |
|
690 | 716 | Q_Q(QPieSeries); |
|
691 | 717 | emit q->hovered(slice, state); |
|
692 | 718 | } |
|
693 | 719 | |
|
694 | 720 | void QPieSeriesPrivate::scaleDomain(Domain& domain) |
|
695 | 721 | { |
|
696 | 722 | Q_UNUSED(domain); |
|
697 | 723 | // does not apply to pie |
|
698 | 724 | } |
|
699 | 725 | |
|
700 | 726 | Chart* QPieSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
701 | 727 | { |
|
702 | 728 | Q_Q(QPieSeries); |
|
703 | 729 | PieChartItem* pie = new PieChartItem(q,presenter); |
|
704 | 730 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
705 | 731 | presenter->animator()->addAnimation(pie); |
|
706 | 732 | } |
|
707 | 733 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
708 | 734 | return pie; |
|
709 | 735 | } |
|
710 | 736 | |
|
711 | 737 | QList<LegendMarker*> QPieSeriesPrivate::createLegendMarker(QLegend* legend) |
|
712 | 738 | { |
|
713 | 739 | Q_Q(QPieSeries); |
|
714 | 740 | QList<LegendMarker*> markers; |
|
715 | 741 | foreach(QPieSlice* slice, q->slices()) { |
|
716 | 742 | PieLegendMarker* marker = new PieLegendMarker(q,slice,legend); |
|
717 | 743 | markers << marker; |
|
718 | 744 | } |
|
719 | 745 | return markers; |
|
720 | 746 | } |
|
721 | 747 | |
|
722 | 748 | #include "moc_qpieseries.cpp" |
|
723 | 749 | #include "moc_qpieseries_p.cpp" |
|
724 | 750 | |
|
725 | 751 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,173 +1,175 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qabstractseries.h" |
|
22 | 22 | #include "qabstractseries_p.h" |
|
23 | 23 | #include "chartdataset_p.h" |
|
24 | 24 | |
|
25 | 25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | 26 | |
|
27 | 27 | /*! |
|
28 | 28 | \class QAbstractSeries |
|
29 | 29 | \brief Base class for all QtCommercial Chart series. |
|
30 | 30 | \mainclass |
|
31 | 31 | |
|
32 | 32 | Usually you use the series type specific inherited classes instead of the base class. |
|
33 | 33 | \sa QXYSeries, QLineSeries, QSplineSeries, QScatterSeries, QAreaSeries, QBarSeries, QStackedBarSeries, |
|
34 | 34 | QPercentBarSeries, QPieSeries |
|
35 | 35 | */ |
|
36 | /*! | |
|
37 | \qmlclass AbstractSeries | |
|
38 | AbstractSeries is the base class for all series. | |
|
39 | The class cannot be instantiated by the user. | |
|
40 | */ | |
|
36 | 41 | |
|
37 | 42 | /*! |
|
38 | 43 | \enum QAbstractSeries::SeriesType |
|
39 | 44 | |
|
40 | 45 | The type of the series object. |
|
41 | 46 | |
|
42 | 47 | \value SeriesTypeLine |
|
43 | 48 | \value SeriesTypeArea |
|
44 | 49 | \value SeriesTypeBar |
|
45 | 50 | \value SeriesTypeStackedBar |
|
46 | 51 | \value SeriesTypePercentBar |
|
47 | 52 | \value SeriesTypeGroupedBar |
|
48 | 53 | \value SeriesTypePie |
|
49 | 54 | \value SeriesTypeScatter |
|
50 | 55 | \value SeriesTypeSpline |
|
51 | 56 | */ |
|
52 | 57 | |
|
53 | 58 | /*! |
|
54 | 59 | \property QAbstractSeries::type |
|
55 | 60 | The type of the series. |
|
56 | 61 | */ |
|
62 | /*! | |
|
63 | \qmlproperty ChartView.SeriesType AbstractSeries::type | |
|
64 | The type of the series. | |
|
65 | */ | |
|
57 | 66 | |
|
58 | 67 | /*! |
|
59 | 68 | \property QAbstractSeries::name |
|
60 | \brief name of the series property | |
|
69 | \brief name of the series property. The name is shown in legend for QXYSeries. | |
|
70 | */ | |
|
71 | /*! | |
|
72 | \qmlproperty string AbstractSeries::name | |
|
73 | Name of the series. The name is shown in legend for QXYSeries. | |
|
61 | 74 | */ |
|
62 | 75 | |
|
63 | 76 | /*! |
|
64 | 77 | \fn void QAbstractSeries::nameChanged() |
|
65 | ||
|
66 | 78 | This signal is emitted when the series name changes. |
|
67 | ||
|
68 | \sa name | |
|
79 | */ | |
|
80 | /*! | |
|
81 | \qmlsignal AbstractSeries::nameChanged() | |
|
82 | This signal is emitted when the series name changes. | |
|
69 | 83 | */ |
|
70 | 84 | |
|
71 | 85 | /*! |
|
72 | 86 | \property QAbstractSeries::visible |
|
73 | 87 | \brief whether the series is visible or not; true by default. |
|
74 | 88 | */ |
|
75 | 89 | |
|
76 | 90 | /*! |
|
77 | 91 | \fn void QAbstractSeries::visibleChanged() |
|
78 | 92 | Emitted when the series visibility changes. |
|
79 | 93 | */ |
|
80 | 94 | |
|
81 | 95 | /*! |
|
82 | 96 | \internal |
|
83 | 97 | \brief Constructs ChartSeries object with \a parent. |
|
84 | 98 | */ |
|
85 | 99 | QAbstractSeries::QAbstractSeries(QAbstractSeriesPrivate &d, QObject *parent) : |
|
86 | 100 | QObject(parent), |
|
87 | 101 | d_ptr(&d) |
|
88 | 102 | { |
|
89 | 103 | } |
|
90 | 104 | |
|
91 | 105 | /*! |
|
92 | 106 | \brief Virtual destructor for the chart series. |
|
93 | 107 | */ |
|
94 | 108 | QAbstractSeries::~QAbstractSeries() |
|
95 | 109 | { |
|
96 | 110 | if(d_ptr->m_dataset) qFatal("Still binded series detected !"); |
|
97 | 111 | } |
|
98 | 112 | |
|
99 | /*! | |
|
100 | \brief Sets a \a name for the series. | |
|
101 | ||
|
102 | The name of a series is shown in the legend for QXYSeries. | |
|
103 | \sa QChart::setTitle() | |
|
104 | \sa QPieSlice::setLabel() | |
|
105 | \sa QBarSet::setName() | |
|
106 | */ | |
|
107 | 113 | void QAbstractSeries::setName(const QString& name) |
|
108 | 114 | { |
|
109 | 115 | if (name != d_ptr->m_name) { |
|
110 | 116 | d_ptr->m_name = name; |
|
111 | 117 | emit nameChanged(); |
|
112 | 118 | } |
|
113 | 119 | } |
|
114 | 120 | |
|
115 | /*! | |
|
116 | \brief Returns the name of the series. | |
|
117 | \sa setName() | |
|
118 | */ | |
|
119 | 121 | QString QAbstractSeries::name() const |
|
120 | 122 | { |
|
121 | 123 | return d_ptr->m_name; |
|
122 | 124 | } |
|
123 | 125 | |
|
124 | 126 | /*! |
|
125 | 127 | Sets the visibility of series to \a visible |
|
126 | 128 | */ |
|
127 | 129 | void QAbstractSeries::setVisible(bool visible) |
|
128 | 130 | { |
|
129 | 131 | if (visible != d_ptr->m_visible) { |
|
130 | 132 | d_ptr->m_visible = visible; |
|
131 | 133 | emit visibleChanged(); |
|
132 | 134 | } |
|
133 | 135 | } |
|
134 | 136 | |
|
135 | 137 | /*! |
|
136 | 138 | Returns the visibility of series |
|
137 | 139 | */ |
|
138 | 140 | bool QAbstractSeries::isVisible() const |
|
139 | 141 | { |
|
140 | 142 | return d_ptr->m_visible; |
|
141 | 143 | } |
|
142 | 144 | |
|
143 | 145 | /*! |
|
144 | 146 | \brief Returns the chart where series belongs to. |
|
145 | 147 | |
|
146 | 148 | Set automatically when the series is added to the chart |
|
147 | 149 | and unset when the series is removed from the chart. |
|
148 | 150 | */ |
|
149 | 151 | QChart* QAbstractSeries::chart() const |
|
150 | 152 | { |
|
151 | 153 | return d_ptr->m_chart; |
|
152 | 154 | } |
|
153 | 155 | |
|
154 | 156 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
|
155 | 157 | |
|
156 | 158 | QAbstractSeriesPrivate::QAbstractSeriesPrivate(QAbstractSeries* q): |
|
157 | 159 | q_ptr(q), |
|
158 | 160 | m_chart(0), |
|
159 | 161 | m_dataset(0), |
|
160 | 162 | m_visible(true) |
|
161 | 163 | { |
|
162 | 164 | } |
|
163 | 165 | |
|
164 | 166 | QAbstractSeriesPrivate::~QAbstractSeriesPrivate() |
|
165 | 167 | { |
|
166 | 168 | } |
|
167 | 169 | |
|
168 | 170 | #include "moc_qabstractseries.cpp" |
|
169 | 171 | #include "moc_qabstractseries_p.cpp" |
|
170 | 172 | |
|
171 | 173 | QTCOMMERCIALCHART_END_NAMESPACE |
|
172 | 174 | |
|
173 | 175 |
@@ -1,415 +1,439 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qxyseries.h" |
|
22 | 22 | #include "qxyseries_p.h" |
|
23 | 23 | #include "domain_p.h" |
|
24 | 24 | #include "legendmarker_p.h" |
|
25 | 25 | |
|
26 | 26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | 27 | |
|
28 | 28 | /*! |
|
29 | 29 | \class QXYSeries |
|
30 | 30 | \brief The QXYSeries class is a base class for line, spline and scatter series. |
|
31 | 31 | */ |
|
32 | 32 | /*! |
|
33 | 33 | \qmlclass XYSeries |
|
34 | \brief The XYSeries class is a base class for line, spline and scatter series. | |
|
34 | \inherits AbstractSeries | |
|
35 | The XYSeries class is a base class for line, spline and scatter series. | |
|
35 | 36 | |
|
36 | 37 | The class cannot be instantiated directly. |
|
37 | 38 | */ |
|
38 | 39 | |
|
39 | 40 | /*! |
|
40 | 41 | \property QXYSeries::pointsVisible |
|
41 | 42 | Controls if the data points are visible and should be drawn. |
|
42 | 43 | */ |
|
43 | 44 | /*! |
|
44 | 45 | \qmlproperty bool XYSeries::pointsVisible |
|
45 | 46 | Controls if the data points are visible and should be drawn. |
|
46 | 47 | */ |
|
47 | 48 | |
|
48 | 49 | /*! |
|
49 | 50 | \fn QPen QXYSeries::pen() const |
|
50 | 51 | \brief Returns pen used to draw points for series. |
|
51 | 52 | \sa setPen() |
|
52 | 53 | */ |
|
53 | 54 | |
|
54 | 55 | /*! |
|
55 | 56 | \fn QBrush QXYSeries::brush() const |
|
56 | 57 | \brief Returns brush used to draw points for series. |
|
57 | 58 | \sa setBrush() |
|
58 | 59 | */ |
|
59 | 60 | |
|
60 | 61 | /*! |
|
61 | 62 | \property QXYSeries::color |
|
62 | 63 | The color of the series. This is line (pen) color in case of QLineSeries or QSplineSeries and |
|
63 | 64 | fill (brush) color in case of QScatterSeries or QAreaSeries. |
|
64 | 65 | \sa QXYSeries::pen(), QXYSeries::brush() |
|
65 | 66 | */ |
|
66 | 67 | /*! |
|
67 | 68 | \qmlproperty color XYSeries::color |
|
68 | 69 | The color of the series. This is line (pen) color in case of LineSeries or SplineSeries and |
|
69 | 70 | fill (brush) color in case of ScatterSeries or AreaSeries. |
|
70 | 71 | */ |
|
71 | 72 | |
|
72 | 73 | /*! |
|
73 | 74 | \fn void QXYSeries::clicked(const QPointF& point) |
|
74 | 75 | \brief Signal is emitted when user clicks the \a point on chart. |
|
75 | 76 | */ |
|
76 | 77 | /*! |
|
77 | 78 | \qmlsignal XYSeries::onClicked(QPointF point) |
|
78 | 79 | Signal is emitted when user clicks the \a point on chart. For example: |
|
79 | 80 | \code |
|
80 | 81 | LineSeries { |
|
81 | 82 | XyPoint { x: 0; y: 0 } |
|
82 | 83 | XyPoint { x: 1.1; y: 2.1 } |
|
83 | 84 | onClicked: console.log("onClicked: " + point.x + ", " + point.y); |
|
84 | 85 | } |
|
85 | 86 | \endcode |
|
86 | 87 | */ |
|
87 | 88 | |
|
88 | 89 | /*! |
|
89 | 90 | \fn void QXYSeries::pointReplaced(int index) |
|
90 | 91 | Signal is emitted when a point has been replaced at \a index. |
|
91 | 92 | \sa replace() |
|
92 | 93 | */ |
|
93 | 94 | /*! |
|
94 | 95 | \qmlsignal XYSeries::pointReplaced(int index) |
|
95 | 96 | Signal is emitted when a point has been replaced at \a index. |
|
96 | 97 | */ |
|
97 | 98 | |
|
98 | 99 | /*! |
|
99 | 100 | \fn void QXYSeries::pointAdded(int index) |
|
100 | 101 | Signal is emitted when a point has been added at \a index. |
|
101 | 102 | \sa append(), insert() |
|
102 | 103 | */ |
|
103 | 104 | /*! |
|
104 | 105 | \qmlsignal XYSeries::pointAdded(int index) |
|
105 | 106 | Signal is emitted when a point has been added at \a index. |
|
106 | 107 | */ |
|
107 | 108 | |
|
108 | 109 | /*! |
|
109 | 110 | \fn void QXYSeries::pointRemoved(int index) |
|
110 | 111 | Signal is emitted when a point has been removed from \a index. |
|
111 | 112 | \sa remove() |
|
112 | 113 | */ |
|
113 | 114 | /*! |
|
114 | 115 | \qmlsignal XYSeries::pointRemoved(int index) |
|
115 | 116 | Signal is emitted when a point has been removed from \a index. |
|
116 | 117 | */ |
|
117 | 118 | |
|
118 | 119 | /*! |
|
119 | 120 | \fn void QXYSeries::colorChanged(QColor color) |
|
120 | 121 | \brief Signal is emitted when the line (pen) color has changed to \a color. |
|
121 | 122 | */ |
|
122 | 123 | /*! |
|
123 | 124 | \qmlsignal XYSeries::colorChanged(QColor color) |
|
124 | 125 | Signal is emitted when the line (pen) color has changed to \a color. |
|
125 | 126 | */ |
|
126 | 127 | |
|
127 | 128 | /*! |
|
128 | 129 | \fn void QXYSeriesPrivate::updated() |
|
129 | 130 | \brief \internal |
|
130 | 131 | */ |
|
131 | 132 | |
|
132 | 133 | /*! |
|
133 |
\qmlmethod X |
|
|
134 | \qmlmethod XYSeries::append(real x, real y) | |
|
135 | Append point (\a x, \a y) to the series | |
|
136 | */ | |
|
137 | ||
|
138 | /*! | |
|
139 | \qmlmethod XYSeries::replace(real oldX, real oldY, real newX, real newY) | |
|
140 | Replaces point (\a oldX, \a oldY) with point (\a newX, \a newY). Does nothing, if point (oldX, oldY) does not | |
|
141 | exist. | |
|
142 | */ | |
|
143 | ||
|
144 | /*! | |
|
145 | \qmlmethod XYSeries::remove(real x, real y) | |
|
146 | Removes point (\a x, \a y) from the series. Does nothing, if point (x, y) does not exist. | |
|
147 | */ | |
|
148 | ||
|
149 | /*! | |
|
150 | \qmlmethod XYSeries::insert(int index, real x, real y) | |
|
151 | Inserts point (\a x, \a y) to the \a index. If index is 0 or smaller than 0 the point is prepended to the list of | |
|
152 | points. If index is the same as or bigger than count, the point is appended to the list of points. | |
|
153 | */ | |
|
154 | ||
|
155 | /*! | |
|
156 | \qmlmethod QPointF XYSeries::at(int index) | |
|
157 | Returns point at \a index. Returns (0, 0) if the index is not valid. | |
|
134 | 158 | */ |
|
135 | 159 | |
|
136 | 160 | /*! |
|
137 | 161 | \internal |
|
138 | 162 | |
|
139 | 163 | Constructs empty series object which is a child of \a parent. |
|
140 | 164 | When series object is added to QChartView or QChart instance ownerships is transferred. |
|
141 | 165 | */ |
|
142 | 166 | QXYSeries::QXYSeries(QXYSeriesPrivate &d,QObject *parent) : QAbstractSeries(d, parent) |
|
143 | 167 | { |
|
144 | 168 | } |
|
145 | 169 | |
|
146 | 170 | /*! |
|
147 | 171 | Destroys the object. Series added to QChartView or QChart instances are owned by those, |
|
148 | 172 | and are deleted when mentioned object are destroyed. |
|
149 | 173 | */ |
|
150 | 174 | QXYSeries::~QXYSeries() |
|
151 | 175 | { |
|
152 | 176 | } |
|
153 | 177 | |
|
154 | 178 | /*! |
|
155 | 179 | Adds data point \a x \a y to the series. Points are connected with lines on the chart. |
|
156 | 180 | */ |
|
157 | 181 | void QXYSeries::append(qreal x,qreal y) |
|
158 | 182 | { |
|
159 | 183 | append(QPointF(x,y)); |
|
160 | 184 | } |
|
161 | 185 | |
|
162 | 186 | /*! |
|
163 | 187 | This is an overloaded function. |
|
164 | 188 | Adds data \a point to the series. Points are connected with lines on the chart. |
|
165 | 189 | */ |
|
166 | 190 | void QXYSeries::append(const QPointF &point) |
|
167 | 191 | { |
|
168 | 192 | Q_D(QXYSeries); |
|
169 | 193 | d->m_points<<point; |
|
170 | 194 | // emit d->pointAdded(d->m_points.count()-1); |
|
171 | 195 | emit pointAdded(d->m_points.count()-1); |
|
172 | 196 | } |
|
173 | 197 | |
|
174 | 198 | /*! |
|
175 | 199 | This is an overloaded function. |
|
176 | 200 | Adds list of data \a points to the series. Points are connected with lines on the chart. |
|
177 | 201 | */ |
|
178 | 202 | void QXYSeries::append(const QList<QPointF> &points) |
|
179 | 203 | { |
|
180 | 204 | foreach(const QPointF& point , points) { |
|
181 | 205 | append(point); |
|
182 | 206 | } |
|
183 | 207 | } |
|
184 | 208 | |
|
185 | 209 | /*! |
|
186 | 210 | Replaces data point \a oldX \a oldY with data point \a newX \a newY. |
|
187 | 211 | */ |
|
188 | 212 | void QXYSeries::replace(qreal oldX,qreal oldY,qreal newX,qreal newY) |
|
189 | 213 | { |
|
190 | 214 | replace(QPointF(oldX,oldY),QPointF(newX,newY)); |
|
191 | 215 | } |
|
192 | 216 | |
|
193 | 217 | /*! |
|
194 | 218 | Replaces \a oldPoint with \a newPoint. |
|
195 | 219 | */ |
|
196 | 220 | void QXYSeries::replace(const QPointF &oldPoint,const QPointF &newPoint) |
|
197 | 221 | { |
|
198 | 222 | Q_D(QXYSeries); |
|
199 | 223 | int index = d->m_points.indexOf(oldPoint); |
|
200 | 224 | if(index==-1) return; |
|
201 | 225 | d->m_points[index] = newPoint; |
|
202 | 226 | // emit d->pointReplaced(index); |
|
203 | 227 | emit pointReplaced(index); |
|
204 | 228 | } |
|
205 | 229 | |
|
206 | 230 | /*! |
|
207 | 231 | Removes current \a x and \a y value. |
|
208 | 232 | */ |
|
209 | 233 | void QXYSeries::remove(qreal x,qreal y) |
|
210 | 234 | { |
|
211 | 235 | remove(QPointF(x,y)); |
|
212 | 236 | } |
|
213 | 237 | |
|
214 | 238 | /*! |
|
215 | 239 | Removes current \a point x value. |
|
216 | 240 | |
|
217 | 241 | Note: point y value is ignored. |
|
218 | 242 | */ |
|
219 | 243 | void QXYSeries::remove(const QPointF &point) |
|
220 | 244 | { |
|
221 | 245 | Q_D(QXYSeries); |
|
222 | 246 | int index = d->m_points.indexOf(point); |
|
223 | 247 | if(index==-1) return; |
|
224 | 248 | d->m_points.remove(index); |
|
225 | 249 | // emit d->pointRemoved(index); |
|
226 | 250 | emit pointRemoved(index); |
|
227 | 251 | } |
|
228 | 252 | |
|
229 | 253 | /*! |
|
230 | 254 | Inserts a \a point in the series at \a index position. |
|
231 | 255 | */ |
|
232 | 256 | void QXYSeries::insert(int index, const QPointF &point) |
|
233 | 257 | { |
|
234 | 258 | Q_D(QXYSeries); |
|
235 | 259 | d->m_points.insert(index, point); |
|
236 | 260 | // emit d->pointAdded(index); |
|
237 | 261 | emit pointAdded(index); |
|
238 | 262 | } |
|
239 | 263 | |
|
240 | 264 | /*! |
|
241 | 265 | Removes all points from the series. |
|
242 | 266 | */ |
|
243 | 267 | void QXYSeries::clear() |
|
244 | 268 | { |
|
245 | 269 | Q_D(QXYSeries); |
|
246 | 270 | for (int i = d->m_points.size() - 1; i >= 0; i--) |
|
247 | 271 | remove(d->m_points.at(i)); |
|
248 | 272 | } |
|
249 | 273 | |
|
250 | 274 | /*! |
|
251 | 275 | \internal \a pos |
|
252 | 276 | */ |
|
253 | 277 | QList<QPointF> QXYSeries::points() const |
|
254 | 278 | { |
|
255 | 279 | Q_D(const QXYSeries); |
|
256 | 280 | return d->m_points.toList(); |
|
257 | 281 | } |
|
258 | 282 | |
|
259 | 283 | /*! |
|
260 | 284 | Returns number of data points within series. |
|
261 | 285 | */ |
|
262 | 286 | int QXYSeries::count() const |
|
263 | 287 | { |
|
264 | 288 | Q_D(const QXYSeries); |
|
265 | 289 | return d->m_points.count(); |
|
266 | 290 | } |
|
267 | 291 | |
|
268 | 292 | |
|
269 | 293 | /*! |
|
270 | 294 | Sets \a pen used for drawing points on the chart. If the pen is not defined, the |
|
271 | 295 | pen from chart theme is used. |
|
272 | 296 | \sa QChart::setTheme() |
|
273 | 297 | */ |
|
274 | 298 | void QXYSeries::setPen(const QPen &pen) |
|
275 | 299 | { |
|
276 | 300 | Q_D(QXYSeries); |
|
277 | 301 | if (d->m_pen!=pen) { |
|
278 | 302 | d->m_pen = pen; |
|
279 | 303 | emit d->updated(); |
|
280 | 304 | } |
|
281 | 305 | } |
|
282 | 306 | |
|
283 | 307 | QPen QXYSeries::pen() const |
|
284 | 308 | { |
|
285 | 309 | Q_D(const QXYSeries); |
|
286 | 310 | return d->m_pen; |
|
287 | 311 | } |
|
288 | 312 | |
|
289 | 313 | /*! |
|
290 | 314 | Sets \a brush used for drawing points on the chart. If the brush is not defined, brush |
|
291 | 315 | from chart theme setting is used. |
|
292 | 316 | \sa QChart::setTheme() |
|
293 | 317 | */ |
|
294 | 318 | void QXYSeries::setBrush(const QBrush &brush) |
|
295 | 319 | { |
|
296 | 320 | Q_D(QXYSeries); |
|
297 | 321 | if (d->m_brush!=brush) { |
|
298 | 322 | d->m_brush = brush; |
|
299 | 323 | emit d->updated(); |
|
300 | 324 | } |
|
301 | 325 | } |
|
302 | 326 | |
|
303 | 327 | QBrush QXYSeries::brush() const |
|
304 | 328 | { |
|
305 | 329 | Q_D(const QXYSeries); |
|
306 | 330 | return d->m_brush; |
|
307 | 331 | } |
|
308 | 332 | |
|
309 | 333 | void QXYSeries::setColor(const QColor &color) |
|
310 | 334 | { |
|
311 | 335 | QPen p = pen(); |
|
312 | 336 | if (p.color() != color) { |
|
313 | 337 | p.setColor(color); |
|
314 | 338 | setPen(p); |
|
315 | 339 | emit colorChanged(color); |
|
316 | 340 | } |
|
317 | 341 | } |
|
318 | 342 | |
|
319 | 343 | QColor QXYSeries::color() const |
|
320 | 344 | { |
|
321 | 345 | return pen().color(); |
|
322 | 346 | } |
|
323 | 347 | |
|
324 | 348 | void QXYSeries::setPointsVisible(bool visible) |
|
325 | 349 | { |
|
326 | 350 | Q_D(QXYSeries); |
|
327 | 351 | if (d->m_pointsVisible != visible){ |
|
328 | 352 | d->m_pointsVisible = visible; |
|
329 | 353 | emit d->updated(); |
|
330 | 354 | } |
|
331 | 355 | } |
|
332 | 356 | |
|
333 | 357 | bool QXYSeries::pointsVisible() const |
|
334 | 358 | { |
|
335 | 359 | Q_D(const QXYSeries); |
|
336 | 360 | return d->m_pointsVisible; |
|
337 | 361 | } |
|
338 | 362 | |
|
339 | 363 | |
|
340 | 364 | /*! |
|
341 | 365 | Stream operator for adding a data \a point to the series. |
|
342 | 366 | \sa append() |
|
343 | 367 | */ |
|
344 | 368 | QXYSeries& QXYSeries::operator<< (const QPointF &point) |
|
345 | 369 | { |
|
346 | 370 | append(point); |
|
347 | 371 | return *this; |
|
348 | 372 | } |
|
349 | 373 | |
|
350 | 374 | |
|
351 | 375 | /*! |
|
352 | 376 | Stream operator for adding a list of \a points to the series. |
|
353 | 377 | \sa append() |
|
354 | 378 | */ |
|
355 | 379 | |
|
356 | 380 | QXYSeries& QXYSeries::operator<< (const QList<QPointF>& points) |
|
357 | 381 | { |
|
358 | 382 | append(points); |
|
359 | 383 | return *this; |
|
360 | 384 | } |
|
361 | 385 | |
|
362 | 386 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
363 | 387 | |
|
364 | 388 | |
|
365 | 389 | QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q) : |
|
366 | 390 | QAbstractSeriesPrivate(q), |
|
367 | 391 | m_pointsVisible(false) |
|
368 | 392 | { |
|
369 | 393 | } |
|
370 | 394 | |
|
371 | 395 | void QXYSeriesPrivate::scaleDomain(Domain& domain) |
|
372 | 396 | { |
|
373 | 397 | qreal minX(domain.minX()); |
|
374 | 398 | qreal minY(domain.minY()); |
|
375 | 399 | qreal maxX(domain.maxX()); |
|
376 | 400 | qreal maxY(domain.maxY()); |
|
377 | 401 | int tickXCount(domain.tickXCount()); |
|
378 | 402 | int tickYCount(domain.tickYCount()); |
|
379 | 403 | |
|
380 | 404 | Q_Q(QXYSeries); |
|
381 | 405 | |
|
382 | 406 | const QList<QPointF>& points = q->points(); |
|
383 | 407 | |
|
384 | 408 | |
|
385 | 409 | if(points.isEmpty()){ |
|
386 | 410 | minX=0.0; |
|
387 | 411 | minY=0.0; |
|
388 | 412 | maxX=1.0; |
|
389 | 413 | maxY=1.0; |
|
390 | 414 | } |
|
391 | 415 | |
|
392 | 416 | for (int i = 0; i < points.count(); i++) |
|
393 | 417 | { |
|
394 | 418 | qreal x = points[i].x(); |
|
395 | 419 | qreal y = points[i].y(); |
|
396 | 420 | minX = qMin(minX, x); |
|
397 | 421 | minY = qMin(minY, y); |
|
398 | 422 | maxX = qMax(maxX, x); |
|
399 | 423 | maxY = qMax(maxY, y); |
|
400 | 424 | } |
|
401 | 425 | |
|
402 | 426 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
403 | 427 | } |
|
404 | 428 | |
|
405 | 429 | QList<LegendMarker*> QXYSeriesPrivate::createLegendMarker(QLegend* legend) |
|
406 | 430 | { |
|
407 | 431 | Q_Q(QXYSeries); |
|
408 | 432 | QList<LegendMarker*> list; |
|
409 | 433 | return list << new XYLegendMarker(q,legend); |
|
410 | 434 | } |
|
411 | 435 | |
|
412 | 436 | #include "moc_qxyseries.cpp" |
|
413 | 437 | #include "moc_qxyseries_p.cpp" |
|
414 | 438 | |
|
415 | 439 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,362 +1,409 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "tst_qxyseries.h" |
|
22 | 22 | |
|
23 | 23 | Q_DECLARE_METATYPE(QList<QPointF>) |
|
24 | 24 | |
|
25 | 25 | void tst_QXYSeries::initTestCase() |
|
26 | 26 | { |
|
27 | 27 | } |
|
28 | 28 | |
|
29 | 29 | void tst_QXYSeries::cleanupTestCase() |
|
30 | 30 | { |
|
31 | 31 | } |
|
32 | 32 | |
|
33 | 33 | void tst_QXYSeries::init() |
|
34 | 34 | { |
|
35 | 35 | m_view = new QChartView(new QChart()); |
|
36 | 36 | m_chart = m_view->chart(); |
|
37 | 37 | } |
|
38 | 38 | |
|
39 | 39 | void tst_QXYSeries::cleanup() |
|
40 | 40 | { |
|
41 | 41 | delete m_view; |
|
42 | 42 | m_view = 0; |
|
43 | 43 | m_chart = 0; |
|
44 | 44 | m_series = 0; |
|
45 | 45 | } |
|
46 | 46 | |
|
47 | void tst_QXYSeries::seriesName() | |
|
48 | { | |
|
49 | QSignalSpy nameSpy(m_series, SIGNAL(nameChanged())); | |
|
50 | QCOMPARE(m_series->name(), QString()); | |
|
51 | m_series->setName("seriesname"); | |
|
52 | QCOMPARE(m_series->name(), QString("seriesname")); | |
|
53 | TRY_COMPARE(nameSpy.count(), 1); | |
|
54 | } | |
|
55 | ||
|
56 | void tst_QXYSeries::seriesVisible() | |
|
57 | { | |
|
58 | QSignalSpy visibleSpy(m_series, SIGNAL(visibleChanged())); | |
|
59 | QCOMPARE(m_series->isVisible(), true); | |
|
60 | m_series->setVisible(false); | |
|
61 | QCOMPARE(m_series->isVisible(), false); | |
|
62 | m_series->setVisible(true); | |
|
63 | TRY_COMPARE(visibleSpy.count(), 2); | |
|
64 | } | |
|
65 | ||
|
47 | 66 | void tst_QXYSeries::append_data() |
|
48 | 67 | { |
|
49 | 68 | QTest::addColumn< QList<QPointF> >("points"); |
|
50 | 69 | QTest::newRow("0,0 1,1 2,2 3,3") << (QList<QPointF>() << QPointF(0,0) << QPointF(1,1) << QPointF(2,2) << QPointF(3,3)); |
|
51 | 70 | QTest::newRow("0,0 -1,-1 -2,-2 -3,-3") << (QList<QPointF>() << QPointF(0,0) << QPointF(-1,-1) << QPointF(-2,-2) << QPointF(-3,-3)); |
|
52 | 71 | } |
|
53 | 72 | |
|
54 | 73 | |
|
55 | 74 | void tst_QXYSeries::append_raw_data() |
|
56 | 75 | { |
|
57 | 76 | append_data(); |
|
58 | 77 | } |
|
59 | 78 | |
|
60 | 79 | void tst_QXYSeries::append_raw() |
|
61 | 80 | { |
|
62 | 81 | QFETCH(QList<QPointF>, points); |
|
63 | 82 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); |
|
83 | QSignalSpy addedSpy(m_series, SIGNAL(pointAdded(int))); | |
|
64 | 84 | m_series->append(points); |
|
65 | 85 | TRY_COMPARE(spy0.count(), 0); |
|
86 | TRY_COMPARE(addedSpy.count(), points.count()); | |
|
66 | 87 | QCOMPARE(m_series->points(), points); |
|
67 | 88 | } |
|
68 | 89 | |
|
69 | 90 | void tst_QXYSeries::chart_append_data() |
|
70 | 91 | { |
|
71 | 92 | append_data(); |
|
72 | 93 | } |
|
73 | 94 | |
|
74 | 95 | void tst_QXYSeries::chart_append() |
|
75 | 96 | { |
|
76 | 97 | append_raw(); |
|
77 | 98 | m_chart->addSeries(m_series); |
|
78 | 99 | m_view->show(); |
|
79 | 100 | QTest::qWaitForWindowShown(m_view); |
|
80 | 101 | } |
|
81 | 102 | |
|
82 | 103 | void tst_QXYSeries::append_chart_data() |
|
83 | 104 | { |
|
84 | 105 | append_data(); |
|
85 | 106 | } |
|
86 | 107 | |
|
87 | 108 | void tst_QXYSeries::append_chart() |
|
88 | 109 | { |
|
89 | 110 | m_view->show(); |
|
90 | 111 | m_chart->addSeries(m_series); |
|
91 | 112 | QTest::qWaitForWindowShown(m_view); |
|
92 | 113 | append_raw(); |
|
93 | 114 | |
|
94 | 115 | } |
|
95 | 116 | |
|
96 | 117 | void tst_QXYSeries::append_chart_animation_data() |
|
97 | 118 | { |
|
98 | 119 | append_data(); |
|
99 | 120 | } |
|
100 | 121 | |
|
101 | 122 | void tst_QXYSeries::append_chart_animation() |
|
102 | 123 | { |
|
103 | 124 | m_chart->setAnimationOptions(QChart::AllAnimations); |
|
104 | 125 | append_chart(); |
|
105 | 126 | } |
|
106 | 127 | |
|
107 | 128 | void tst_QXYSeries::count_data() |
|
108 | 129 | { |
|
109 | 130 | QTest::addColumn<int>("count"); |
|
110 | 131 | QTest::newRow("0") << 0; |
|
111 | 132 | QTest::newRow("5") << 5; |
|
112 | 133 | QTest::newRow("10") << 5; |
|
113 | 134 | } |
|
114 | 135 | |
|
115 | 136 | void tst_QXYSeries::count_raw_data() |
|
116 | 137 | { |
|
117 | 138 | count_data(); |
|
118 | 139 | } |
|
119 | 140 | |
|
120 | 141 | void tst_QXYSeries::count_raw() |
|
121 | 142 | { |
|
122 | 143 | QFETCH(int, count); |
|
123 | 144 | |
|
124 | 145 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); |
|
125 | 146 | |
|
126 | 147 | for(int i=0 ; i< count; ++i) |
|
127 | 148 | m_series->append(i,i); |
|
128 | 149 | |
|
129 | 150 | TRY_COMPARE(spy0.count(), 0); |
|
130 | 151 | QCOMPARE(m_series->count(), count); |
|
131 | 152 | } |
|
132 | 153 | |
|
133 | 154 | void tst_QXYSeries::remove_raw_data() |
|
134 | 155 | { |
|
135 | 156 | append_data(); |
|
136 | 157 | } |
|
137 | 158 | |
|
138 | 159 | void tst_QXYSeries::remove_raw() |
|
139 | 160 | { |
|
140 | 161 | QFETCH(QList<QPointF>, points); |
|
141 | 162 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); |
|
142 | 163 | m_series->append(points); |
|
143 | 164 | TRY_COMPARE(spy0.count(), 0); |
|
144 | 165 | QCOMPARE(m_series->points(), points); |
|
145 | 166 | |
|
146 | 167 | foreach(const QPointF& point,points) |
|
147 | 168 | m_series->remove(point); |
|
148 | 169 | |
|
149 | 170 | QCOMPARE(m_series->points().count(), 0); |
|
150 | 171 | TRY_COMPARE(spy0.count(), 0); |
|
151 | 172 | |
|
152 | 173 | m_series->append(points); |
|
153 | 174 | QCOMPARE(m_series->points(), points); |
|
154 | 175 | |
|
155 | 176 | //reverse order |
|
156 | 177 | for(int i = points.count()-1 ; i>=0; i--){ |
|
157 | 178 | m_series->remove(points[i]); |
|
158 | 179 | } |
|
159 | 180 | QCOMPARE(m_series->points().count(), 0); |
|
160 | 181 | } |
|
161 | 182 | |
|
162 | 183 | void tst_QXYSeries::remove_chart_data() |
|
163 | 184 | { |
|
164 | 185 | append_data(); |
|
165 | 186 | } |
|
166 | 187 | |
|
167 | 188 | void tst_QXYSeries::remove_chart() |
|
168 | 189 | { |
|
169 | 190 | m_view->show(); |
|
170 | 191 | m_chart->addSeries(m_series); |
|
171 | 192 | QTest::qWaitForWindowShown(m_view); |
|
172 | 193 | remove_raw(); |
|
173 | 194 | } |
|
174 | 195 | |
|
175 | 196 | void tst_QXYSeries::remove_chart_animation_data() |
|
176 | 197 | { |
|
177 | 198 | append_data(); |
|
178 | 199 | } |
|
179 | 200 | |
|
180 | 201 | void tst_QXYSeries::remove_chart_animation() |
|
181 | 202 | { |
|
182 | 203 | m_chart->setAnimationOptions(QChart::AllAnimations); |
|
183 | 204 | remove_chart(); |
|
184 | 205 | } |
|
185 | 206 | |
|
186 | 207 | |
|
187 | 208 | void tst_QXYSeries::clear_raw_data() |
|
188 | 209 | { |
|
189 | 210 | append_data(); |
|
190 | 211 | } |
|
191 | 212 | |
|
192 | 213 | void tst_QXYSeries::clear_raw() |
|
193 | 214 | { |
|
194 | 215 | QFETCH(QList<QPointF>, points); |
|
195 | 216 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); |
|
196 | 217 | m_series->append(points); |
|
197 | 218 | TRY_COMPARE(spy0.count(), 0); |
|
198 | 219 | QCOMPARE(m_series->points(), points); |
|
199 | 220 | m_series->clear(); |
|
200 | 221 | TRY_COMPARE(spy0.count(), 0); |
|
201 | 222 | QCOMPARE(m_series->points().count(), 0); |
|
202 | 223 | } |
|
203 | 224 | |
|
204 | 225 | void tst_QXYSeries::clear_chart_data() |
|
205 | 226 | { |
|
206 | 227 | append_data(); |
|
207 | 228 | } |
|
208 | 229 | |
|
209 | 230 | void tst_QXYSeries::clear_chart() |
|
210 | 231 | { |
|
211 | 232 | m_view->show(); |
|
212 | 233 | m_chart->addSeries(m_series); |
|
213 | 234 | QTest::qWaitForWindowShown(m_view); |
|
214 | 235 | clear_raw(); |
|
215 | 236 | } |
|
216 | 237 | |
|
217 | 238 | void tst_QXYSeries::clear_chart_animation_data() |
|
218 | 239 | { |
|
219 | 240 | append_data(); |
|
220 | 241 | } |
|
221 | 242 | |
|
222 | 243 | void tst_QXYSeries::clear_chart_animation() |
|
223 | 244 | { |
|
224 | 245 | m_chart->setAnimationOptions(QChart::AllAnimations); |
|
225 | 246 | clear_chart(); |
|
226 | 247 | } |
|
227 | 248 | |
|
228 | 249 | void tst_QXYSeries::replace_raw_data() |
|
229 | 250 | { |
|
230 | 251 | append_data(); |
|
231 | 252 | } |
|
232 | 253 | |
|
233 | 254 | void tst_QXYSeries::replace_raw() |
|
234 | 255 | { |
|
235 | 256 | QFETCH(QList<QPointF>, points); |
|
236 |
QSignalSpy |
|
|
257 | QSignalSpy replacedSpy(m_series, SIGNAL(pointReplaced(int))); | |
|
237 | 258 | m_series->append(points); |
|
238 |
TRY_COMPARE( |
|
|
259 | TRY_COMPARE(replacedSpy.count(), 0); | |
|
239 | 260 | QCOMPARE(m_series->points(), points); |
|
240 | 261 | |
|
241 | foreach(const QPointF& point,points) | |
|
262 | foreach(const QPointF& point, points) | |
|
242 | 263 | m_series->replace(point.x(),point.y(),point.x(),0); |
|
264 | TRY_COMPARE(replacedSpy.count(), points.count()); | |
|
265 | ||
|
266 | // Replace a point that does not exist | |
|
267 | m_series->replace(-123, 999, 0, 0); | |
|
268 | TRY_COMPARE(replacedSpy.count(), points.count()); | |
|
243 | 269 | |
|
244 | 270 | QList<QPointF> newPoints = m_series->points(); |
|
245 | 271 | |
|
246 | 272 | QCOMPARE(newPoints.count(), points.count()); |
|
247 | 273 | |
|
248 | 274 | for(int i =0 ; i<points.count() ; ++i) { |
|
249 | 275 | QCOMPARE(points[i].x(), newPoints[i].x()); |
|
250 | 276 | QCOMPARE(newPoints[i].y(), 0.0); |
|
251 | 277 | } |
|
252 | 278 | } |
|
253 | 279 | |
|
254 | 280 | |
|
255 | 281 | void tst_QXYSeries::replace_chart_data() |
|
256 | 282 | { |
|
257 | 283 | append_data(); |
|
258 | 284 | } |
|
259 | 285 | |
|
260 | 286 | void tst_QXYSeries::replace_chart() |
|
261 | 287 | { |
|
262 | 288 | m_view->show(); |
|
263 | 289 | m_chart->addSeries(m_series); |
|
264 | 290 | QTest::qWaitForWindowShown(m_view); |
|
265 | 291 | replace_raw(); |
|
266 | 292 | } |
|
267 | 293 | |
|
268 | 294 | void tst_QXYSeries::replace_chart_animation_data() |
|
269 | 295 | { |
|
270 | 296 | append_data(); |
|
271 | 297 | } |
|
272 | 298 | |
|
273 | 299 | void tst_QXYSeries::replace_chart_animation() |
|
274 | 300 | { |
|
275 | 301 | m_chart->setAnimationOptions(QChart::AllAnimations); |
|
276 | 302 | replace_chart(); |
|
277 | 303 | } |
|
278 | 304 | |
|
305 | void tst_QXYSeries::insert_data() | |
|
306 | { | |
|
307 | append_data(); | |
|
308 | } | |
|
309 | ||
|
310 | void tst_QXYSeries::insert() | |
|
311 | { | |
|
312 | QFETCH(QList<QPointF>, points); | |
|
313 | m_series->append(points); | |
|
314 | ||
|
315 | QSignalSpy addedSpy(m_series, SIGNAL(pointAdded(int))); | |
|
316 | ||
|
317 | m_series->insert(0, QPointF(5, 5)); | |
|
318 | TRY_COMPARE(addedSpy.count(), 1); | |
|
319 | QCOMPARE(m_series->points().count(), points.count() + 1); | |
|
320 | ||
|
321 | m_series->insert(m_series->count(), QPointF(6, 6)); | |
|
322 | TRY_COMPARE(addedSpy.count(), 2); | |
|
323 | QCOMPARE(m_series->points().count(), points.count() + 2); | |
|
324 | } | |
|
325 | ||
|
279 | 326 | void tst_QXYSeries::oper_data() |
|
280 | 327 | { |
|
281 | 328 | append_data(); |
|
282 | 329 | } |
|
283 | 330 | |
|
284 | 331 | void tst_QXYSeries::oper() |
|
285 | 332 | { |
|
286 | 333 | QFETCH(QList<QPointF>, points); |
|
287 | 334 | |
|
288 | 335 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); |
|
289 | 336 | |
|
290 | 337 | foreach(const QPointF& point,points) |
|
291 | 338 | { |
|
292 | 339 | *m_series<<point; |
|
293 | 340 | } |
|
294 | 341 | |
|
295 | 342 | QCOMPARE(m_series->points(), points); |
|
296 | 343 | TRY_COMPARE(spy0.count(), 0); |
|
297 | 344 | } |
|
298 | 345 | |
|
299 | 346 | |
|
300 | 347 | void tst_QXYSeries::pen_data() |
|
301 | 348 | { |
|
302 | 349 | QTest::addColumn<QPen>("pen"); |
|
303 | 350 | QTest::newRow("null") << QPen(); |
|
304 | 351 | QTest::newRow("blue") << QPen(Qt::blue); |
|
305 | 352 | QTest::newRow("black") << QPen(Qt::black); |
|
306 | 353 | QTest::newRow("red") << QPen(Qt::red); |
|
307 | 354 | } |
|
308 | 355 | |
|
309 | 356 | void tst_QXYSeries::pen() |
|
310 | 357 | { |
|
311 | 358 | QFETCH(QPen, pen); |
|
312 | 359 | |
|
313 | 360 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); |
|
314 | 361 | m_series->setPen(pen); |
|
315 | 362 | |
|
316 | 363 | TRY_COMPARE(spy0.count(), 0); |
|
317 | 364 | QCOMPARE(m_series->pen(), pen); |
|
318 | 365 | |
|
319 | 366 | m_chart->addSeries(m_series); |
|
320 | 367 | |
|
321 | 368 | if (pen != QPen()) |
|
322 | 369 | QCOMPARE(m_series->pen(), pen); |
|
323 | 370 | |
|
324 | 371 | m_chart->setTheme(QChart::ChartThemeDark); |
|
325 | 372 | |
|
326 | 373 | // setting a theme will overwrite all customizations |
|
327 | 374 | if (pen != QPen()) |
|
328 | 375 | QVERIFY(m_series->pen() != pen); |
|
329 | 376 | } |
|
330 | 377 | |
|
331 | 378 | void tst_QXYSeries::pointsVisible_data() |
|
332 | 379 | { |
|
333 | 380 | QTest::addColumn<bool>("pointsVisible"); |
|
334 | 381 | QTest::newRow("true") << true; |
|
335 | 382 | QTest::newRow("false") << false; |
|
336 | 383 | } |
|
337 | 384 | |
|
338 | 385 | void tst_QXYSeries::pointsVisible_raw_data() |
|
339 | 386 | { |
|
340 | 387 | pointsVisible_data(); |
|
341 | 388 | } |
|
342 | 389 | |
|
343 | 390 | void tst_QXYSeries::pointsVisible_raw() |
|
344 | 391 | { |
|
345 | 392 | QFETCH(bool, pointsVisible); |
|
346 | 393 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); |
|
347 | 394 | m_series->setPointsVisible(pointsVisible); |
|
348 | 395 | TRY_COMPARE(spy0.count(), 0); |
|
349 | 396 | QCOMPARE(m_series->pointsVisible(), pointsVisible); |
|
350 | 397 | } |
|
351 | 398 | |
|
352 | 399 | void tst_QXYSeries::changedSignals() |
|
353 | 400 | { |
|
354 | 401 | QSignalSpy visibleSpy(m_series, SIGNAL(visibleChanged())); |
|
355 | 402 | |
|
356 | 403 | m_series->setVisible(false); |
|
357 | 404 | m_series->setVisible(false); |
|
358 | 405 | TRY_COMPARE(visibleSpy.count(), 1); |
|
359 | 406 | m_series->setVisible(true); |
|
360 | 407 | TRY_COMPARE(visibleSpy.count(), 2); |
|
361 | 408 | } |
|
362 | 409 |
@@ -1,89 +1,93 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #ifndef TST_QXYSERIES_H |
|
22 | 22 | #define TST_QXYSERIES_H |
|
23 | 23 | |
|
24 | 24 | #include <QtTest/QtTest> |
|
25 | 25 | #include <qxyseries.h> |
|
26 | 26 | #include <qchartview.h> |
|
27 | 27 | #include <QStandardItemModel> |
|
28 | 28 | #include <tst_definitions.h> |
|
29 | 29 | |
|
30 | 30 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
31 | 31 | |
|
32 | 32 | class tst_QXYSeries : public QObject |
|
33 | 33 | { |
|
34 | 34 | Q_OBJECT |
|
35 | 35 | |
|
36 | 36 | public slots: |
|
37 | 37 | virtual void initTestCase(); |
|
38 | 38 | virtual void cleanupTestCase(); |
|
39 | 39 | virtual void init(); |
|
40 | 40 | virtual void cleanup(); |
|
41 | 41 | |
|
42 | 42 | private slots: |
|
43 | void seriesName(); | |
|
44 | void seriesVisible(); | |
|
43 | 45 | void oper_data(); |
|
44 | 46 | void oper(); |
|
45 | 47 | void pen_data(); |
|
46 | 48 | void pen(); |
|
47 | 49 | void pointsVisible_raw_data(); |
|
48 | 50 | void pointsVisible_raw(); |
|
49 | 51 | void append_raw_data(); |
|
50 | 52 | void append_raw(); |
|
51 | 53 | void append_chart_data(); |
|
52 | 54 | void append_chart(); |
|
53 | 55 | void append_chart_animation_data(); |
|
54 | 56 | void append_chart_animation(); |
|
55 | 57 | void chart_append_data(); |
|
56 | 58 | void chart_append(); |
|
57 | 59 | void count_raw_data(); |
|
58 | 60 | void count_raw(); |
|
59 | 61 | void remove_raw_data(); |
|
60 | 62 | void remove_raw(); |
|
61 | 63 | void remove_chart_data(); |
|
62 | 64 | void remove_chart(); |
|
63 | 65 | void remove_chart_animation_data(); |
|
64 | 66 | void remove_chart_animation(); |
|
65 | 67 | void clear_raw_data(); |
|
66 | 68 | void clear_raw(); |
|
67 | 69 | void clear_chart_data(); |
|
68 | 70 | void clear_chart(); |
|
69 | 71 | void clear_chart_animation_data(); |
|
70 | 72 | void clear_chart_animation(); |
|
71 | 73 | void replace_raw_data(); |
|
72 | 74 | void replace_raw(); |
|
73 | 75 | void replace_chart_data(); |
|
74 | 76 | void replace_chart(); |
|
75 | 77 | void replace_chart_animation_data(); |
|
76 | 78 | void replace_chart_animation(); |
|
79 | void insert_data(); | |
|
80 | void insert(); | |
|
77 | 81 | void changedSignals(); |
|
78 | 82 | protected: |
|
79 | 83 | void append_data(); |
|
80 | 84 | void count_data(); |
|
81 | 85 | void pointsVisible_data(); |
|
82 | 86 | |
|
83 | 87 | protected: |
|
84 | 88 | QChartView* m_view; |
|
85 | 89 | QChart* m_chart; |
|
86 | 90 | QXYSeries* m_series; |
|
87 | 91 | }; |
|
88 | 92 | |
|
89 | 93 | #endif |
@@ -1,66 +1,66 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | import QtQuick 1.0 |
|
22 | 22 | import QtCommercial.Chart 1.0 |
|
23 | 23 | |
|
24 | 24 | |
|
25 | 25 | Flow { |
|
26 | 26 | id: flow |
|
27 | 27 | spacing: 5 |
|
28 | 28 | flow: Flow.TopToBottom |
|
29 | 29 | property variant series |
|
30 | 30 | |
|
31 | 31 | Button { |
|
32 | 32 | text: "visible" |
|
33 | 33 | onClicked: series.visible = !series.visible; |
|
34 | 34 | } |
|
35 | 35 | Button { |
|
36 | 36 | text: "color" |
|
37 | 37 | onClicked: series.color = main.nextColor(); |
|
38 | 38 | } |
|
39 | 39 | Button { |
|
40 | 40 | text: "points visible" |
|
41 | 41 | onClicked: series.pointsVisible = !series.pointsVisible; |
|
42 | 42 | } |
|
43 | 43 | Button { |
|
44 | 44 | text: "append point" |
|
45 | 45 | onClicked: series.append(series.count - 1, series.count - 1); |
|
46 | 46 | } |
|
47 | 47 | Button { |
|
48 | 48 | text: "replace point" |
|
49 | 49 | onClicked: { |
|
50 | 50 | var xyPoint = series.at(series.count - 1); |
|
51 | 51 | series.replace(xyPoint.x, xyPoint.y, xyPoint.x, xyPoint.y + 0.1); |
|
52 | 52 | } |
|
53 | 53 | } |
|
54 | 54 | Button { |
|
55 | 55 | text: "remove point" |
|
56 | 56 | onClicked: series.remove(series.at(series.count - 1).x, series.at(series.count - 1).y); |
|
57 | 57 | } |
|
58 | 58 | Button { |
|
59 | 59 | text: "insert point" |
|
60 |
onClicked: series.insert( |
|
|
60 | onClicked: series.insert(series.count - 2, series.count - 2, series.count - 2); | |
|
61 | 61 | } |
|
62 | 62 | Button { |
|
63 | 63 | text: "clear" |
|
64 | 64 | onClicked: series.clear(); |
|
65 | 65 | } |
|
66 | 66 | } |
@@ -1,78 +1,78 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | import QtQuick 1.0 |
|
22 | 22 | import QtCommercial.Chart 1.0 |
|
23 | 23 | |
|
24 | 24 | |
|
25 | 25 | Flow { |
|
26 | 26 | id: flow |
|
27 | 27 | spacing: 5 |
|
28 | 28 | flow: Flow.TopToBottom |
|
29 | 29 | property variant series |
|
30 | 30 | |
|
31 | 31 | Button { |
|
32 | 32 | text: "visible" |
|
33 | 33 | onClicked: series.visible = !series.visible; |
|
34 | 34 | } |
|
35 | 35 | Button { |
|
36 | 36 | text: "color" |
|
37 | 37 | onClicked: series.color = main.nextColor(); |
|
38 | 38 | } |
|
39 | 39 | Button { |
|
40 | 40 | text: "borderColor" |
|
41 | 41 | onClicked: series.borderColor = main.nextColor(); |
|
42 | 42 | } |
|
43 | 43 | Button { |
|
44 | 44 | text: "markerSize +" |
|
45 | 45 | onClicked: series.markerSize += 1.0; |
|
46 | 46 | } |
|
47 | 47 | Button { |
|
48 | 48 | text: "markerSize -" |
|
49 | 49 | onClicked: series.markerSize -= 1.0; |
|
50 | 50 | } |
|
51 | 51 | Button { |
|
52 | 52 | text: "markerShape" |
|
53 | 53 | onClicked: series.markerShape = ((series.markerShape + 1) % 2); |
|
54 | 54 | } |
|
55 | 55 | Button { |
|
56 | 56 | text: "append point" |
|
57 | 57 | onClicked: series.append(series.count - 1, series.count - 1); |
|
58 | 58 | } |
|
59 | 59 | Button { |
|
60 | 60 | text: "replace point" |
|
61 | 61 | onClicked: { |
|
62 | 62 | var xyPoint = series.at(series.count - 1); |
|
63 | 63 | series.replace(xyPoint.x, xyPoint.y, xyPoint.x, xyPoint.y + 0.1); |
|
64 | 64 | } |
|
65 | 65 | } |
|
66 | 66 | Button { |
|
67 | 67 | text: "remove point" |
|
68 | 68 | onClicked: series.remove(series.at(series.count - 1).x, series.at(series.count - 1).y); |
|
69 | 69 | } |
|
70 | 70 | Button { |
|
71 | 71 | text: "insert point" |
|
72 |
onClicked: series.insert( |
|
|
72 | onClicked: series.insert(series.count - 2, series.count - 2, series.count - 2); | |
|
73 | 73 | } |
|
74 | 74 | Button { |
|
75 | 75 | text: "clear" |
|
76 | 76 | onClicked: series.clear(); |
|
77 | 77 | } |
|
78 | 78 | } |
General Comments 0
You need to be logged in to leave comments.
Login now