@@ -1,406 +1,393 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2014 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 Enterprise Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Enterprise licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Enterprise 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 | #ifndef BUILD_PRIVATE_UNIT_TESTS |
|
21 | 21 | #include <QtTest/QtTest> |
|
22 | 22 | |
|
23 | 23 | class tst_ChartDataSet: public QObject { |
|
24 | 24 | |
|
25 | 25 | Q_OBJECT |
|
26 | 26 | |
|
27 | 27 | private Q_SLOTS: |
|
28 | 28 | void skip(); |
|
29 | 29 | |
|
30 | 30 | }; |
|
31 | 31 | |
|
32 | 32 | void tst_ChartDataSet::skip() |
|
33 | 33 | { |
|
34 | 34 | QSKIP("This test requires the debug version of library"); |
|
35 | 35 | } |
|
36 | 36 | |
|
37 | 37 | QTEST_MAIN(tst_ChartDataSet) |
|
38 | 38 | #include "tst_chartdataset.moc" |
|
39 | 39 | |
|
40 | 40 | #else |
|
41 | 41 | |
|
42 | 42 | #include <QtTest/QtTest> |
|
43 | 43 | #include <QtCharts/QAbstractAxis> |
|
44 | 44 | #include <QtCharts/QValueAxis> |
|
45 | 45 | #include <QtCharts/QBarCategoryAxis> |
|
46 | 46 | #include <QtCharts/QCategoryAxis> |
|
47 | 47 | #ifndef QT_ON_ARM |
|
48 | 48 | #include <QtCharts/QDateTimeAxis> |
|
49 | 49 | #endif |
|
50 | 50 | #include <QtCharts/QLineSeries> |
|
51 | 51 | #include <QtCharts/QAreaSeries> |
|
52 | 52 | #include <QtCharts/QScatterSeries> |
|
53 | 53 | #include <QtCharts/QSplineSeries> |
|
54 | 54 | #include <QtCharts/QPieSeries> |
|
55 | 55 | #include <QtCharts/QBarSeries> |
|
56 | 56 | #include <QtCharts/QPercentBarSeries> |
|
57 | 57 | #include <QtCharts/QStackedBarSeries> |
|
58 | 58 | #include <private/chartdataset_p.h> |
|
59 | 59 | #include <private/abstractdomain_p.h> |
|
60 | 60 | #include <tst_definitions.h> |
|
61 | 61 | |
|
62 | 62 | QT_CHARTS_USE_NAMESPACE |
|
63 | 63 | |
|
64 | 64 | Q_DECLARE_METATYPE(AbstractDomain *) |
|
65 | 65 | Q_DECLARE_METATYPE(QAbstractAxis *) |
|
66 | 66 | Q_DECLARE_METATYPE(QAbstractSeries *) |
|
67 | 67 | Q_DECLARE_METATYPE(QList<QAbstractSeries *>) |
|
68 | 68 | Q_DECLARE_METATYPE(QList<QAbstractAxis *>) |
|
69 | 69 | Q_DECLARE_METATYPE(Qt::Alignment) |
|
70 | 70 | Q_DECLARE_METATYPE(QList<Qt::Alignment>) |
|
71 | 71 | Q_DECLARE_METATYPE(QLineSeries *) |
|
72 | 72 | |
|
73 | 73 | class tst_ChartDataSet: public QObject { |
|
74 | 74 | |
|
75 | 75 | Q_OBJECT |
|
76 | 76 | public: |
|
77 | 77 | tst_ChartDataSet():m_dataset(0){}; |
|
78 | 78 | |
|
79 | 79 | public Q_SLOTS: |
|
80 | 80 | void initTestCase(); |
|
81 | 81 | void cleanupTestCase(); |
|
82 | 82 | void init(); |
|
83 | 83 | void cleanup(); |
|
84 | 84 | |
|
85 | 85 | private Q_SLOTS: |
|
86 | 86 | void chartdataset_data(); |
|
87 | 87 | void chartdataset(); |
|
88 | 88 | void addSeries_data(); |
|
89 | 89 | void addSeries(); |
|
90 | 90 | void removeSeries_data(); |
|
91 | 91 | void removeSeries(); |
|
92 | 92 | void addAxis_data(); |
|
93 | 93 | void addAxis(); |
|
94 | 94 | void removeAxis_data(); |
|
95 | 95 | void removeAxis(); |
|
96 | 96 | void attachAxis_data(); |
|
97 | 97 | void attachAxis(); |
|
98 | 98 | void detachAxis_data(); |
|
99 | 99 | void detachAxis(); |
|
100 | 100 | |
|
101 | 101 | private: |
|
102 | 102 | ChartDataSet* m_dataset; |
|
103 | 103 | }; |
|
104 | 104 | |
|
105 | 105 | void tst_ChartDataSet::initTestCase() |
|
106 | 106 | { |
|
107 | 107 | qRegisterMetaType<AbstractDomain*>(); |
|
108 | 108 | qRegisterMetaType<QAbstractAxis*>(); |
|
109 | 109 | qRegisterMetaType<QAbstractSeries*>(); |
|
110 | 110 | } |
|
111 | 111 | |
|
112 | 112 | void tst_ChartDataSet::cleanupTestCase() |
|
113 | 113 | { |
|
114 | 114 | } |
|
115 | 115 | |
|
116 | 116 | void tst_ChartDataSet::init() |
|
117 | 117 | { |
|
118 | 118 | Q_ASSERT(!m_dataset); |
|
119 | 119 | m_dataset = new ChartDataSet(0); |
|
120 | 120 | } |
|
121 | 121 | |
|
122 | 122 | |
|
123 | 123 | void tst_ChartDataSet::cleanup() |
|
124 | 124 | { |
|
125 | 125 | delete m_dataset; |
|
126 | 126 | m_dataset=0; |
|
127 | 127 | } |
|
128 | 128 | |
|
129 | 129 | void tst_ChartDataSet::chartdataset_data() |
|
130 | 130 | { |
|
131 | 131 | } |
|
132 | 132 | |
|
133 | 133 | void tst_ChartDataSet::chartdataset() |
|
134 | 134 | { |
|
135 | 135 | QVERIFY(m_dataset->axes().isEmpty()); |
|
136 | 136 | QVERIFY(m_dataset->series().isEmpty()); |
|
137 | 137 | m_dataset->createDefaultAxes(); |
|
138 | 138 | } |
|
139 | 139 | |
|
140 | 140 | |
|
141 | 141 | void tst_ChartDataSet::addSeries_data() |
|
142 | 142 | { |
|
143 | 143 | QTest::addColumn<QAbstractSeries*>("series"); |
|
144 | 144 | |
|
145 | 145 | QAbstractSeries* line = new QLineSeries(this); |
|
146 | 146 | QTest::newRow("line") << line; |
|
147 | 147 | |
|
148 | 148 | QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(new QLineSeries(this))); |
|
149 | 149 | QTest::newRow("area") << area; |
|
150 | 150 | |
|
151 | 151 | QAbstractSeries* scatter = new QScatterSeries(this); |
|
152 | 152 | QTest::newRow("scatter") << scatter; |
|
153 | 153 | |
|
154 | 154 | QAbstractSeries* spline = new QSplineSeries(this); |
|
155 | 155 | QTest::newRow("spline") << spline; |
|
156 | 156 | |
|
157 | 157 | QAbstractSeries* pie = new QPieSeries(this); |
|
158 | 158 | QTest::newRow("pie") << pie; |
|
159 | 159 | |
|
160 | 160 | QAbstractSeries* bar = new QBarSeries(this); |
|
161 | 161 | QTest::newRow("bar") << bar; |
|
162 | 162 | |
|
163 | 163 | QAbstractSeries* percent = new QPercentBarSeries(this); |
|
164 | 164 | QTest::newRow("percent") << percent; |
|
165 | 165 | |
|
166 | 166 | QAbstractSeries* stacked = new QStackedBarSeries(this); |
|
167 | 167 | QTest::newRow("stacked") << stacked; |
|
168 | 168 | } |
|
169 | 169 | |
|
170 | 170 | void tst_ChartDataSet::addSeries() |
|
171 | 171 | { |
|
172 | 172 | QFETCH(QAbstractSeries*, series); |
|
173 | 173 | QVERIFY(m_dataset->series().isEmpty()); |
|
174 | 174 | |
|
175 | 175 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); |
|
176 | 176 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
177 | 177 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); |
|
178 | 178 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
179 | 179 | |
|
180 | 180 | m_dataset->addSeries(series); |
|
181 | 181 | |
|
182 | 182 | QCOMPARE(m_dataset->series().count(),1); |
|
183 | 183 | TRY_COMPARE(spy0.count(), 0); |
|
184 | 184 | TRY_COMPARE(spy1.count(), 0); |
|
185 | 185 | TRY_COMPARE(spy2.count(), 1); |
|
186 | 186 | TRY_COMPARE(spy3.count(), 0); |
|
187 | 187 | } |
|
188 | 188 | |
|
189 | 189 | void tst_ChartDataSet::removeSeries_data() |
|
190 | 190 | { |
|
191 | 191 | addSeries_data(); |
|
192 | 192 | } |
|
193 | 193 | |
|
194 | 194 | void tst_ChartDataSet::removeSeries() |
|
195 | 195 | { |
|
196 | 196 | QFETCH(QAbstractSeries*, series); |
|
197 | 197 | QVERIFY(m_dataset->series().isEmpty()); |
|
198 | 198 | m_dataset->addSeries(series); |
|
199 | 199 | |
|
200 | 200 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); |
|
201 | 201 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
202 | 202 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); |
|
203 | 203 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
204 | 204 | |
|
205 | 205 | m_dataset->removeSeries(series); |
|
206 | 206 | |
|
207 | 207 | QCOMPARE(m_dataset->series().count(),0); |
|
208 | 208 | TRY_COMPARE(spy0.count(), 0); |
|
209 | 209 | TRY_COMPARE(spy1.count(), 0); |
|
210 | 210 | TRY_COMPARE(spy2.count(), 0); |
|
211 | 211 | TRY_COMPARE(spy3.count(), 1); |
|
212 | 212 | } |
|
213 | 213 | |
|
214 | 214 | void tst_ChartDataSet::addAxis_data() |
|
215 | 215 | { |
|
216 | 216 | QTest::addColumn<QAbstractAxis*>("axis"); |
|
217 | 217 | QAbstractAxis* value = new QValueAxis(this); |
|
218 | 218 | QAbstractAxis* category = new QCategoryAxis(this); |
|
219 | 219 | QAbstractAxis* barcategory = new QBarCategoryAxis(this); |
|
220 | 220 | #ifndef Q_WS_QWS |
|
221 | 221 | QAbstractAxis* datetime = new QDateTimeAxis(this); |
|
222 | 222 | #endif |
|
223 | 223 | |
|
224 | 224 | QTest::newRow("value") << value; |
|
225 | 225 | QTest::newRow("category") << category; |
|
226 | 226 | QTest::newRow("barcategory") << barcategory; |
|
227 | 227 | #ifndef Q_WS_QWS |
|
228 | 228 | QTest::newRow("datetime") << datetime; |
|
229 | 229 | #endif |
|
230 | 230 | } |
|
231 | 231 | |
|
232 | 232 | void tst_ChartDataSet::addAxis() |
|
233 | 233 | { |
|
234 | 234 | QFETCH(QAbstractAxis*, axis); |
|
235 | 235 | QVERIFY(m_dataset->axes().isEmpty()); |
|
236 | 236 | |
|
237 | 237 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); |
|
238 | 238 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
239 | 239 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); |
|
240 | 240 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
241 | 241 | |
|
242 | 242 | m_dataset->addAxis(axis,Qt::AlignBottom); |
|
243 | 243 | |
|
244 | 244 | QCOMPARE(m_dataset->axes().count(),1); |
|
245 | 245 | TRY_COMPARE(spy0.count(), 1); |
|
246 | 246 | TRY_COMPARE(spy1.count(), 0); |
|
247 | 247 | TRY_COMPARE(spy2.count(), 0); |
|
248 | 248 | TRY_COMPARE(spy3.count(), 0); |
|
249 | 249 | } |
|
250 | 250 | |
|
251 | 251 | void tst_ChartDataSet::removeAxis_data() |
|
252 | 252 | { |
|
253 | 253 | addAxis_data(); |
|
254 | 254 | } |
|
255 | 255 | |
|
256 | 256 | void tst_ChartDataSet::removeAxis() |
|
257 | 257 | { |
|
258 | 258 | QFETCH(QAbstractAxis*, axis); |
|
259 | 259 | QVERIFY(m_dataset->series().isEmpty()); |
|
260 | 260 | m_dataset->addAxis(axis,Qt::AlignBottom); |
|
261 | 261 | |
|
262 | 262 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); |
|
263 | 263 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
264 | 264 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); |
|
265 | 265 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
266 | 266 | |
|
267 | 267 | m_dataset->removeAxis(axis); |
|
268 | 268 | |
|
269 | 269 | QCOMPARE(m_dataset->axes().count(),0); |
|
270 | 270 | QCOMPARE(m_dataset->series().count(),0); |
|
271 | 271 | TRY_COMPARE(spy0.count(), 0); |
|
272 | 272 | TRY_COMPARE(spy1.count(), 1); |
|
273 | 273 | TRY_COMPARE(spy2.count(), 0); |
|
274 | 274 | TRY_COMPARE(spy3.count(), 0); |
|
275 | 275 | } |
|
276 | 276 | |
|
277 | 277 | void tst_ChartDataSet::attachAxis_data() |
|
278 | 278 | { |
|
279 | 279 | |
|
280 | 280 | QTest::addColumn<QList<QAbstractSeries*> >("series"); |
|
281 | 281 | QTest::addColumn<QList<QAbstractAxis*> >("axis"); |
|
282 | 282 | QTest::addColumn<QList<Qt::Alignment> >("alignment"); |
|
283 | 283 | QTest::addColumn<QAbstractSeries*>("attachSeries"); |
|
284 | 284 | QTest::addColumn<QAbstractAxis*>("attachAxis"); |
|
285 | 285 | QTest::addColumn<bool>("success"); |
|
286 | 286 | |
|
287 | //QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line)); | |
|
288 | QAbstractSeries* scatter = new QScatterSeries(this); | |
|
289 | QAbstractSeries* spline = new QSplineSeries(this); | |
|
290 | QAbstractSeries* pie = new QPieSeries(this); | |
|
291 | QAbstractSeries* bar = new QBarSeries(this); | |
|
292 | QAbstractSeries* percent = new QPercentBarSeries(this); | |
|
293 | QAbstractSeries* stacked = new QStackedBarSeries(this); | |
|
294 | ||
|
295 | QAbstractAxis* category = new QCategoryAxis(this); | |
|
296 | QAbstractAxis* barcategory = new QBarCategoryAxis(this); | |
|
297 | #ifndef Q_WS_QWS | |
|
298 | QAbstractAxis* datetime = new QDateTimeAxis(this); | |
|
299 | #endif | |
|
300 | 287 | { |
|
301 | 288 | QList<QAbstractSeries*> series; |
|
302 | 289 | QList<QAbstractAxis*> axes; |
|
303 | 290 | QList<Qt::Alignment> alignment; |
|
304 | 291 | QAbstractSeries* line = new QLineSeries(this); |
|
305 | 292 | QAbstractAxis* value1 = new QValueAxis(this); |
|
306 | 293 | QAbstractAxis* value2 = new QValueAxis(this); |
|
307 | 294 | series << line << 0; |
|
308 | 295 | axes << value1 << value2; |
|
309 | 296 | alignment << Qt::AlignBottom << Qt::AlignLeft; |
|
310 | 297 | QTest::newRow("first") << series << axes << alignment << line << value2 << true ; |
|
311 | 298 | } |
|
312 | 299 | |
|
313 | 300 | { |
|
314 | 301 | QList<QAbstractSeries*> series; |
|
315 | 302 | QList<QAbstractAxis*> axes; |
|
316 | 303 | QList<Qt::Alignment> alignment; |
|
317 | 304 | QAbstractSeries* line = new QLineSeries(this); |
|
318 | 305 | QAbstractAxis* value1 = new QValueAxis(this); |
|
319 | 306 | QAbstractAxis* value2 = new QValueAxis(this); |
|
320 | 307 | series << 0 << line; |
|
321 | 308 | axes << value1 << value2; |
|
322 | 309 | alignment << Qt::AlignBottom << Qt::AlignLeft; |
|
323 | 310 | QTest::newRow("second") << series << axes << alignment << line << value1 << true; |
|
324 | 311 | } |
|
325 | 312 | |
|
326 | 313 | } |
|
327 | 314 | |
|
328 | 315 | void tst_ChartDataSet::attachAxis() |
|
329 | 316 | { |
|
330 | 317 | QFETCH(QList<QAbstractSeries*>, series); |
|
331 | 318 | QFETCH(QList<QAbstractAxis*>, axis); |
|
332 | 319 | QFETCH(QList<Qt::Alignment>, alignment); |
|
333 | 320 | QFETCH(QAbstractSeries*, attachSeries); |
|
334 | 321 | QFETCH(QAbstractAxis*, attachAxis); |
|
335 | 322 | QFETCH(bool, success); |
|
336 | 323 | |
|
337 | 324 | Q_ASSERT(series.count() == axis.count()); |
|
338 | 325 | Q_ASSERT(series.count() == alignment.count()); |
|
339 | 326 | |
|
340 | 327 | QVERIFY(m_dataset->series().isEmpty()); |
|
341 | 328 | QVERIFY(m_dataset->axes().isEmpty()); |
|
342 | 329 | |
|
343 | 330 | for(int i = 0 ; i < series.count() ; i++){ |
|
344 | 331 | if(series[i]) m_dataset->addSeries(series[i]); |
|
345 | 332 | if(axis[i]) m_dataset->addAxis(axis[i],alignment[i]); |
|
346 | 333 | if(series[i] && axis[i]) m_dataset->attachAxis(series[i],axis[i]); |
|
347 | 334 | } |
|
348 | 335 | |
|
349 | 336 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); |
|
350 | 337 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
351 | 338 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); |
|
352 | 339 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
353 | 340 | |
|
354 | 341 | QCOMPARE(m_dataset->attachAxis(attachSeries,attachAxis),success); |
|
355 | 342 | |
|
356 | 343 | } |
|
357 | 344 | |
|
358 | 345 | void tst_ChartDataSet::detachAxis_data() |
|
359 | 346 | { |
|
360 | 347 | QTest::addColumn<QList<QAbstractSeries*> >("series"); |
|
361 | 348 | QTest::addColumn<QList<QAbstractAxis*> >("axis"); |
|
362 | 349 | QTest::addColumn<QAbstractSeries*>("detachSeries"); |
|
363 | 350 | QTest::addColumn<QAbstractAxis*>("detachAxis"); |
|
364 | 351 | QTest::addColumn<bool>("success"); |
|
365 | 352 | |
|
366 | 353 | { |
|
367 | 354 | QList<QAbstractSeries*> series; |
|
368 | 355 | QList<QAbstractAxis*> axes; |
|
369 | 356 | QAbstractSeries* line = new QLineSeries(this); |
|
370 | 357 | QAbstractAxis* value = new QValueAxis(this); |
|
371 | 358 | series << line; |
|
372 | 359 | axes << value; |
|
373 | 360 | QTest::newRow("first") << series << axes << line << value << true; |
|
374 | 361 | } |
|
375 | 362 | } |
|
376 | 363 | |
|
377 | 364 | void tst_ChartDataSet::detachAxis() |
|
378 | 365 | { |
|
379 | 366 | QFETCH(QList<QAbstractSeries*>, series); |
|
380 | 367 | QFETCH(QList<QAbstractAxis*>, axis); |
|
381 | 368 | QFETCH(QAbstractSeries*, detachSeries); |
|
382 | 369 | QFETCH(QAbstractAxis*, detachAxis); |
|
383 | 370 | QFETCH(bool, success); |
|
384 | 371 | |
|
385 | 372 | Q_ASSERT(series.count() == axis.count()); |
|
386 | 373 | |
|
387 | 374 | QVERIFY(m_dataset->series().isEmpty()); |
|
388 | 375 | QVERIFY(m_dataset->axes().isEmpty()); |
|
389 | 376 | |
|
390 | 377 | for(int i = 0; i < series.count(); i++) { |
|
391 | 378 | if(series[i]) m_dataset->addSeries(series[i]); |
|
392 | 379 | if(axis[i]) m_dataset->addAxis(axis[i],Qt::AlignBottom); |
|
393 | 380 | if(series[i] && axis[i]) m_dataset->attachAxis(series[i],axis[i]); |
|
394 | 381 | } |
|
395 | 382 | |
|
396 | 383 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*))); |
|
397 | 384 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
398 | 385 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*))); |
|
399 | 386 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
400 | 387 | |
|
401 | 388 | QCOMPARE(m_dataset->detachAxis(detachSeries,detachAxis),success); |
|
402 | 389 | } |
|
403 | 390 | |
|
404 | 391 | QTEST_MAIN(tst_ChartDataSet) |
|
405 | 392 | #include "tst_chartdataset.moc" |
|
406 | 393 | #endif |
@@ -1,89 +1,90 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2014 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 Enterprise Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Enterprise licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Enterprise 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 | |
|
22 | 22 | #ifndef CHARTS_H |
|
23 | 23 | #define CHARTS_H |
|
24 | 24 | #include "model.h" |
|
25 | 25 | #include <QtCore/QList> |
|
26 | 26 | #include <QtCore/QString> |
|
27 | #include <QtCore/QSharedPointer> | |
|
27 | 28 | #include <QtCharts/QChartGlobal> |
|
28 | 29 | |
|
29 | 30 | QT_CHARTS_BEGIN_NAMESPACE |
|
30 | 31 | class QChart; |
|
31 | 32 | QT_CHARTS_END_NAMESPACE |
|
32 | 33 | |
|
33 | 34 | QT_CHARTS_USE_NAMESPACE |
|
34 | 35 | |
|
35 | 36 | class Chart |
|
36 | 37 | { |
|
37 | 38 | public: |
|
38 | 39 | virtual ~Chart() {}; |
|
39 | 40 | virtual QChart *createChart(const DataTable &table) = 0; |
|
40 | 41 | virtual QString name() = 0; |
|
41 | 42 | virtual QString category() = 0; |
|
42 | 43 | virtual QString subCategory() = 0; |
|
43 | 44 | |
|
44 | 45 | }; |
|
45 | 46 | |
|
46 | 47 | namespace Charts |
|
47 | 48 | { |
|
48 | 49 | |
|
49 | 50 | typedef QList<Chart *> ChartList; |
|
50 | 51 | |
|
51 | 52 | inline ChartList &chartList() |
|
52 | 53 | { |
|
53 | 54 | static ChartList list; |
|
54 | 55 | return list; |
|
55 | 56 | } |
|
56 | 57 | |
|
57 | 58 | inline bool findChart(Chart *chart) |
|
58 | 59 | { |
|
59 | 60 | ChartList &list = chartList(); |
|
60 | 61 | if (list.contains(chart)) |
|
61 | 62 | return true; |
|
62 | 63 | |
|
63 | 64 | foreach (Chart *item, list) { |
|
64 | 65 | if (item->name() == chart->name() && item->category() == chart->category() && item->subCategory() == chart->subCategory()) |
|
65 | 66 | return true; |
|
66 | 67 | } |
|
67 | 68 | return false; |
|
68 | 69 | } |
|
69 | 70 | |
|
70 | 71 | inline void addChart(Chart *chart) |
|
71 | 72 | { |
|
72 | 73 | ChartList &list = chartList(); |
|
73 | 74 | if (!findChart(chart)) |
|
74 | 75 | list.append(chart); |
|
75 | 76 | } |
|
76 | 77 | } |
|
77 | 78 | |
|
78 | 79 | template <class T> |
|
79 | 80 | class ChartWrapper |
|
80 | 81 | { |
|
81 | 82 | public: |
|
82 | 83 | QSharedPointer<T> chart; |
|
83 | 84 | ChartWrapper() : chart(new T) { Charts::addChart(chart.data()); } |
|
84 | 85 | }; |
|
85 | 86 | |
|
86 | 87 | #define DECLARE_CHART(chartType) static ChartWrapper<chartType> chartType; |
|
87 | 88 | #define DECLARE_CHART_TEMPLATE(chartType,chartName) static ChartWrapper<chartType> chartName; |
|
88 | 89 | |
|
89 | 90 | #endif |
General Comments 0
You need to be logged in to leave comments.
Login now