@@ -1,571 +1,570 | |||
|
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 <QtTest/QtTest> |
|
22 | 22 | #include <qhorizontalbarseries.h> |
|
23 | 23 | #include <qbarset.h> |
|
24 | 24 | #include <qchartview.h> |
|
25 | 25 | #include <qchart.h> |
|
26 | 26 | #include "tst_definitions.h" |
|
27 | 27 | |
|
28 | 28 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
29 | 29 | |
|
30 | 30 | Q_DECLARE_METATYPE(QBarSet*) |
|
31 | 31 | |
|
32 | 32 | class tst_QHorizontalBarSeries : public QObject |
|
33 | 33 | { |
|
34 | 34 | Q_OBJECT |
|
35 | 35 | |
|
36 | 36 | public slots: |
|
37 | 37 | void initTestCase(); |
|
38 | 38 | void cleanupTestCase(); |
|
39 | 39 | void init(); |
|
40 | 40 | void cleanup(); |
|
41 | 41 | |
|
42 | 42 | private slots: |
|
43 | 43 | void qhorizontalbarseries_data(); |
|
44 | 44 | void qhorizontalbarseries(); |
|
45 | 45 | void type_data(); |
|
46 | 46 | void type(); |
|
47 | 47 | void append_data(); |
|
48 | 48 | void append(); |
|
49 | 49 | void remove_data(); |
|
50 | 50 | void remove(); |
|
51 | 51 | void appendList_data(); |
|
52 | 52 | void appendList(); |
|
53 | 53 | void count_data(); |
|
54 | 54 | void count(); |
|
55 | 55 | void barSets_data(); |
|
56 | 56 | void barSets(); |
|
57 | 57 | void setLabelsVisible_data(); |
|
58 | 58 | void setLabelsVisible(); |
|
59 | 59 | void mouseclicked_data(); |
|
60 | 60 | void mouseclicked(); |
|
61 | 61 | void mousehovered_data(); |
|
62 | 62 | void mousehovered(); |
|
63 | 63 | void clearWithAnimations(); |
|
64 | 64 | |
|
65 | 65 | private: |
|
66 | 66 | QHorizontalBarSeries* m_barseries; |
|
67 | 67 | QHorizontalBarSeries* m_barseries_with_sets; |
|
68 | 68 | |
|
69 | 69 | QList<QBarSet*> m_testSets; |
|
70 | 70 | |
|
71 | 71 | }; |
|
72 | 72 | |
|
73 | 73 | void tst_QHorizontalBarSeries::initTestCase() |
|
74 | 74 | { |
|
75 | 75 | qRegisterMetaType<QBarSet*>("QBarSet*"); |
|
76 | 76 | } |
|
77 | 77 | |
|
78 | 78 | void tst_QHorizontalBarSeries::cleanupTestCase() |
|
79 | 79 | { |
|
80 | 80 | } |
|
81 | 81 | |
|
82 | 82 | void tst_QHorizontalBarSeries::init() |
|
83 | 83 | { |
|
84 | 84 | m_barseries = new QHorizontalBarSeries(); |
|
85 | 85 | m_barseries_with_sets = new QHorizontalBarSeries(); |
|
86 | 86 | |
|
87 | 87 | for (int i=0; i<5; i++) { |
|
88 | 88 | m_testSets.append(new QBarSet("testset")); |
|
89 | 89 | m_barseries_with_sets->append(m_testSets.at(i)); |
|
90 | 90 | } |
|
91 | 91 | } |
|
92 | 92 | |
|
93 | 93 | void tst_QHorizontalBarSeries::cleanup() |
|
94 | 94 | { |
|
95 | 95 | foreach(QBarSet* s, m_testSets) { |
|
96 | 96 | m_barseries_with_sets->remove(s); |
|
97 | delete s; | |
|
98 | 97 | } |
|
99 | 98 | m_testSets.clear(); |
|
100 | 99 | |
|
101 | 100 | delete m_barseries; |
|
102 | 101 | m_barseries = 0; |
|
103 | 102 | delete m_barseries_with_sets; |
|
104 | 103 | m_barseries_with_sets = 0; |
|
105 | 104 | } |
|
106 | 105 | |
|
107 | 106 | void tst_QHorizontalBarSeries::qhorizontalbarseries_data() |
|
108 | 107 | { |
|
109 | 108 | } |
|
110 | 109 | |
|
111 | 110 | void tst_QHorizontalBarSeries::qhorizontalbarseries() |
|
112 | 111 | { |
|
113 | 112 | QHorizontalBarSeries *barseries = new QHorizontalBarSeries(); |
|
114 | 113 | QVERIFY(barseries != 0); |
|
115 | 114 | } |
|
116 | 115 | |
|
117 | 116 | void tst_QHorizontalBarSeries::type_data() |
|
118 | 117 | { |
|
119 | 118 | |
|
120 | 119 | } |
|
121 | 120 | |
|
122 | 121 | void tst_QHorizontalBarSeries::type() |
|
123 | 122 | { |
|
124 | 123 | QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeHorizontalBar); |
|
125 | 124 | } |
|
126 | 125 | |
|
127 | 126 | void tst_QHorizontalBarSeries::append_data() |
|
128 | 127 | { |
|
129 | 128 | } |
|
130 | 129 | |
|
131 | 130 | void tst_QHorizontalBarSeries::append() |
|
132 | 131 | { |
|
133 | 132 | QVERIFY(m_barseries->count() == 0); |
|
134 | 133 | |
|
135 | 134 | bool ret = false; |
|
136 | 135 | |
|
137 | 136 | // Try adding barset |
|
138 | 137 | QBarSet *barset = new QBarSet("testset"); |
|
139 | 138 | ret = m_barseries->append(barset); |
|
140 | 139 | |
|
141 | 140 | QVERIFY(ret == true); |
|
142 | 141 | QVERIFY(m_barseries->count() == 1); |
|
143 | 142 | |
|
144 | 143 | // Try adding another set |
|
145 | 144 | QBarSet *barset2 = new QBarSet("testset2"); |
|
146 | 145 | ret = m_barseries->append(barset2); |
|
147 | 146 | |
|
148 | 147 | QVERIFY(ret == true); |
|
149 | 148 | QVERIFY(m_barseries->count() == 2); |
|
150 | 149 | |
|
151 | 150 | // Try adding same set again |
|
152 | 151 | ret = m_barseries->append(barset2); |
|
153 | 152 | QVERIFY(ret == false); |
|
154 | 153 | QVERIFY(m_barseries->count() == 2); |
|
155 | 154 | |
|
156 | 155 | // Try adding null set |
|
157 | 156 | ret = m_barseries->append(0); |
|
158 | 157 | QVERIFY(ret == false); |
|
159 | 158 | QVERIFY(m_barseries->count() == 2); |
|
160 | 159 | |
|
161 | 160 | } |
|
162 | 161 | |
|
163 | 162 | void tst_QHorizontalBarSeries::remove_data() |
|
164 | 163 | { |
|
165 | 164 | } |
|
166 | 165 | |
|
167 | 166 | void tst_QHorizontalBarSeries::remove() |
|
168 | 167 | { |
|
169 | 168 | int count = m_testSets.count(); |
|
170 | 169 | QVERIFY(m_barseries_with_sets->count() == count); |
|
171 | 170 | |
|
172 | 171 | // Try to remove null pointer (should not remove, should not crash) |
|
173 | 172 | bool ret = false; |
|
174 | 173 | ret = m_barseries_with_sets->remove(0); |
|
175 | 174 | QVERIFY(ret == false); |
|
176 | 175 | QVERIFY(m_barseries_with_sets->count() == count); |
|
177 | 176 | |
|
178 | 177 | // Try to remove invalid pointer (should not remove, should not crash) |
|
179 | 178 | ret = m_barseries_with_sets->remove((QBarSet*) (m_testSets.at(0) + 1) ); |
|
180 | 179 | QVERIFY(ret == false); |
|
181 | 180 | QVERIFY(m_barseries_with_sets->count() == count); |
|
182 | 181 | |
|
183 | 182 | // remove some sets |
|
184 | 183 | ret = m_barseries_with_sets->remove(m_testSets.at(2)); |
|
185 | 184 | QVERIFY(ret == true); |
|
186 | 185 | ret = m_barseries_with_sets->remove(m_testSets.at(3)); |
|
187 | 186 | QVERIFY(ret == true); |
|
188 | 187 | ret = m_barseries_with_sets->remove(m_testSets.at(4)); |
|
189 | 188 | QVERIFY(ret == true); |
|
190 | 189 | |
|
191 | 190 | QVERIFY(m_barseries_with_sets->count() == 2); |
|
192 | 191 | |
|
193 | 192 | QList<QBarSet*> verifysets = m_barseries_with_sets->barSets(); |
|
194 | 193 | |
|
195 | 194 | QVERIFY(verifysets.at(0) == m_testSets.at(0)); |
|
196 | 195 | QVERIFY(verifysets.at(1) == m_testSets.at(1)); |
|
197 | 196 | |
|
198 | 197 | // Try removing all sets again (should be ok, even if some sets have already been removed) |
|
199 | 198 | ret = false; |
|
200 | 199 | for (int i=0; i<count; i++) { |
|
201 | 200 | ret |= m_barseries_with_sets->remove(m_testSets.at(i)); |
|
202 | 201 | } |
|
203 | 202 | |
|
204 | 203 | QVERIFY(ret == true); |
|
205 | 204 | QVERIFY(m_barseries_with_sets->count() == 0); |
|
206 | 205 | } |
|
207 | 206 | |
|
208 | 207 | void tst_QHorizontalBarSeries::appendList_data() |
|
209 | 208 | { |
|
210 | 209 | |
|
211 | 210 | } |
|
212 | 211 | |
|
213 | 212 | void tst_QHorizontalBarSeries::appendList() |
|
214 | 213 | { |
|
215 | 214 | int count = 5; |
|
216 | 215 | QVERIFY(m_barseries->count() == 0); |
|
217 | 216 | |
|
218 | 217 | QList<QBarSet*> sets; |
|
219 | 218 | for (int i=0; i<count; i++) { |
|
220 | 219 | sets.append(new QBarSet("testset")); |
|
221 | 220 | } |
|
222 | 221 | |
|
223 | 222 | // Append new sets (should succeed, count should match the count of sets) |
|
224 | 223 | bool ret = false; |
|
225 | 224 | ret = m_barseries->append(sets); |
|
226 | 225 | QVERIFY(ret == true); |
|
227 | 226 | QVERIFY(m_barseries->count() == count); |
|
228 | 227 | |
|
229 | 228 | // Append same sets again (should fail, count should remain same) |
|
230 | 229 | ret = m_barseries->append(sets); |
|
231 | 230 | QVERIFY(ret == false); |
|
232 | 231 | QVERIFY(m_barseries->count() == count); |
|
233 | 232 | |
|
234 | 233 | // Try append empty list (should succeed, but count should remain same) |
|
235 | 234 | QList<QBarSet*> invalidList; |
|
236 | 235 | ret = m_barseries->append(invalidList); |
|
237 | 236 | QVERIFY(ret == true); |
|
238 | 237 | QVERIFY(m_barseries->count() == count); |
|
239 | 238 | |
|
240 | 239 | // Try append list with one new and one existing set (should fail, count remains same) |
|
241 | 240 | invalidList.append(new QBarSet("ok set")); |
|
242 | 241 | invalidList.append(sets.at(0)); |
|
243 | 242 | ret = m_barseries->append(invalidList); |
|
244 | 243 | QVERIFY(ret == false); |
|
245 | 244 | QVERIFY(m_barseries->count() == count); |
|
246 | 245 | |
|
247 | 246 | // Try append list with null pointers (should fail, count remains same) |
|
248 | 247 | QList<QBarSet*> invalidList2; |
|
249 | 248 | invalidList2.append(0); |
|
250 | 249 | invalidList2.append(0); |
|
251 | 250 | invalidList2.append(0); |
|
252 | 251 | ret = m_barseries->append(invalidList2); |
|
253 | 252 | QVERIFY(ret == false); |
|
254 | 253 | QVERIFY(m_barseries->count() == count); |
|
255 | 254 | } |
|
256 | 255 | |
|
257 | 256 | void tst_QHorizontalBarSeries::count_data() |
|
258 | 257 | { |
|
259 | 258 | |
|
260 | 259 | } |
|
261 | 260 | |
|
262 | 261 | void tst_QHorizontalBarSeries::count() |
|
263 | 262 | { |
|
264 | 263 | QVERIFY(m_barseries->count() == 0); |
|
265 | 264 | QVERIFY(m_barseries_with_sets->count() == m_testSets.count()); |
|
266 | 265 | } |
|
267 | 266 | |
|
268 | 267 | void tst_QHorizontalBarSeries::barSets_data() |
|
269 | 268 | { |
|
270 | 269 | |
|
271 | 270 | } |
|
272 | 271 | |
|
273 | 272 | void tst_QHorizontalBarSeries::barSets() |
|
274 | 273 | { |
|
275 | 274 | QVERIFY(m_barseries->barSets().count() == 0); |
|
276 | 275 | |
|
277 | 276 | QList<QBarSet*> sets = m_barseries_with_sets->barSets(); |
|
278 | 277 | QVERIFY(sets.count() == m_testSets.count()); |
|
279 | 278 | |
|
280 | 279 | for (int i=0; i<m_testSets.count(); i++) { |
|
281 | 280 | QVERIFY(sets.at(i) == m_testSets.at(i)); |
|
282 | 281 | } |
|
283 | 282 | } |
|
284 | 283 | |
|
285 | 284 | void tst_QHorizontalBarSeries::setLabelsVisible_data() |
|
286 | 285 | { |
|
287 | 286 | |
|
288 | 287 | } |
|
289 | 288 | |
|
290 | 289 | void tst_QHorizontalBarSeries::setLabelsVisible() |
|
291 | 290 | { |
|
292 | 291 | // labels should be invisible by default |
|
293 | 292 | QVERIFY(m_barseries->isLabelsVisible() == false); |
|
294 | 293 | QVERIFY(m_barseries_with_sets->isLabelsVisible() == false); |
|
295 | 294 | |
|
296 | 295 | // turn labels to visible |
|
297 | 296 | m_barseries_with_sets->setLabelsVisible(true); |
|
298 | 297 | // TODO: test the signal |
|
299 | 298 | QVERIFY(m_barseries_with_sets->isLabelsVisible() == true); |
|
300 | 299 | |
|
301 | 300 | // turn labels to invisible |
|
302 | 301 | m_barseries_with_sets->setLabelsVisible(false); |
|
303 | 302 | // TODO: test the signal |
|
304 | 303 | QVERIFY(m_barseries_with_sets->isLabelsVisible() == false); |
|
305 | 304 | |
|
306 | 305 | // without parameter, should turn labels to visible |
|
307 | 306 | m_barseries_with_sets->setLabelsVisible(); |
|
308 | 307 | // TODO: test the signal |
|
309 | 308 | QVERIFY(m_barseries_with_sets->isLabelsVisible() == true); |
|
310 | 309 | } |
|
311 | 310 | |
|
312 | 311 | void tst_QHorizontalBarSeries::mouseclicked_data() |
|
313 | 312 | { |
|
314 | 313 | |
|
315 | 314 | } |
|
316 | 315 | |
|
317 | 316 | void tst_QHorizontalBarSeries::mouseclicked() |
|
318 | 317 | { |
|
319 | 318 | QHorizontalBarSeries* series = new QHorizontalBarSeries(); |
|
320 | 319 | |
|
321 | 320 | QBarSet* set1 = new QBarSet(QString("set 1")); |
|
322 | 321 | *set1 << 10 << 10 << 10; |
|
323 | 322 | series->append(set1); |
|
324 | 323 | |
|
325 | 324 | QBarSet* set2 = new QBarSet(QString("set 2")); |
|
326 | 325 | *set2 << 10 << 10 << 10; |
|
327 | 326 | series->append(set2); |
|
328 | 327 | |
|
329 | 328 | QSignalSpy seriesSpy(series,SIGNAL(clicked(int,QBarSet*))); |
|
330 | 329 | QSignalSpy setSpy1(set1, SIGNAL(clicked(int))); |
|
331 | 330 | QSignalSpy setSpy2(set2, SIGNAL(clicked(int))); |
|
332 | 331 | |
|
333 | 332 | QChartView view(new QChart()); |
|
334 | 333 | view.resize(400,300); |
|
335 | 334 | view.chart()->addSeries(series); |
|
336 | 335 | view.show(); |
|
337 | 336 | QTest::qWaitForWindowShown(&view); |
|
338 | 337 | |
|
339 | 338 | //==================================================================================== |
|
340 | 339 | // barset 1, bar 0 |
|
341 | 340 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(200,218)); |
|
342 | 341 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
343 | 342 | |
|
344 | 343 | QCOMPARE(seriesSpy.count(), 1); |
|
345 | 344 | QCOMPARE(setSpy1.count(), 1); |
|
346 | 345 | QCOMPARE(setSpy2.count(), 0); |
|
347 | 346 | |
|
348 | 347 | QList<QVariant> seriesSpyArg = seriesSpy.takeFirst(); |
|
349 | 348 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); |
|
350 | 349 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); |
|
351 | 350 | QVERIFY(seriesSpyArg.at(0).toInt() == 0); |
|
352 | 351 | |
|
353 | 352 | QList<QVariant> setSpyArg = setSpy1.takeFirst(); |
|
354 | 353 | QVERIFY(setSpyArg.at(0).type() == QVariant::Int); |
|
355 | 354 | QVERIFY(setSpyArg.at(0).toInt() == 0); |
|
356 | 355 | |
|
357 | 356 | //==================================================================================== |
|
358 | 357 | // barset 1, bar 1 |
|
359 | 358 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(200,161)); |
|
360 | 359 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
361 | 360 | |
|
362 | 361 | QCOMPARE(seriesSpy.count(), 1); |
|
363 | 362 | QCOMPARE(setSpy1.count(), 1); |
|
364 | 363 | QCOMPARE(setSpy2.count(), 0); |
|
365 | 364 | |
|
366 | 365 | seriesSpyArg = seriesSpy.takeFirst(); |
|
367 | 366 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); |
|
368 | 367 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); |
|
369 | 368 | QVERIFY(seriesSpyArg.at(0).toInt() == 1); |
|
370 | 369 | |
|
371 | 370 | setSpyArg = setSpy1.takeFirst(); |
|
372 | 371 | QVERIFY(setSpyArg.at(0).type() == QVariant::Int); |
|
373 | 372 | QVERIFY(setSpyArg.at(0).toInt() == 1); |
|
374 | 373 | |
|
375 | 374 | //==================================================================================== |
|
376 | 375 | // barset 1, bar 2 |
|
377 | 376 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(200,104)); |
|
378 | 377 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
379 | 378 | |
|
380 | 379 | QCOMPARE(seriesSpy.count(), 1); |
|
381 | 380 | QCOMPARE(setSpy1.count(), 1); |
|
382 | 381 | QCOMPARE(setSpy2.count(), 0); |
|
383 | 382 | |
|
384 | 383 | seriesSpyArg = seriesSpy.takeFirst(); |
|
385 | 384 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); |
|
386 | 385 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); |
|
387 | 386 | QVERIFY(seriesSpyArg.at(0).toInt() == 2); |
|
388 | 387 | |
|
389 | 388 | setSpyArg = setSpy1.takeFirst(); |
|
390 | 389 | QVERIFY(setSpyArg.at(0).type() == QVariant::Int); |
|
391 | 390 | QVERIFY(setSpyArg.at(0).toInt() == 2); |
|
392 | 391 | |
|
393 | 392 | //==================================================================================== |
|
394 | 393 | // barset 2, bar 0 |
|
395 | 394 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(200,203)); |
|
396 | 395 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
397 | 396 | |
|
398 | 397 | QCOMPARE(seriesSpy.count(), 1); |
|
399 | 398 | QCOMPARE(setSpy1.count(), 0); |
|
400 | 399 | QCOMPARE(setSpy2.count(), 1); |
|
401 | 400 | |
|
402 | 401 | seriesSpyArg = seriesSpy.takeFirst(); |
|
403 | 402 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); |
|
404 | 403 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); |
|
405 | 404 | QVERIFY(seriesSpyArg.at(0).toInt() == 0); |
|
406 | 405 | |
|
407 | 406 | setSpyArg = setSpy2.takeFirst(); |
|
408 | 407 | QVERIFY(setSpyArg.at(0).type() == QVariant::Int); |
|
409 | 408 | QVERIFY(setSpyArg.at(0).toInt() == 0); |
|
410 | 409 | |
|
411 | 410 | //==================================================================================== |
|
412 | 411 | // barset 2, bar 1 |
|
413 | 412 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(200,146)); |
|
414 | 413 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
415 | 414 | |
|
416 | 415 | QCOMPARE(seriesSpy.count(), 1); |
|
417 | 416 | QCOMPARE(setSpy1.count(), 0); |
|
418 | 417 | QCOMPARE(setSpy2.count(), 1); |
|
419 | 418 | |
|
420 | 419 | seriesSpyArg = seriesSpy.takeFirst(); |
|
421 | 420 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); |
|
422 | 421 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); |
|
423 | 422 | QVERIFY(seriesSpyArg.at(0).toInt() == 1); |
|
424 | 423 | |
|
425 | 424 | setSpyArg = setSpy2.takeFirst(); |
|
426 | 425 | QVERIFY(setSpyArg.at(0).type() == QVariant::Int); |
|
427 | 426 | QVERIFY(setSpyArg.at(0).toInt() == 1); |
|
428 | 427 | |
|
429 | 428 | //==================================================================================== |
|
430 | 429 | // barset 2, bar 2 |
|
431 | 430 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(200,89)); |
|
432 | 431 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
433 | 432 | |
|
434 | 433 | QCOMPARE(seriesSpy.count(), 1); |
|
435 | 434 | QCOMPARE(setSpy1.count(), 0); |
|
436 | 435 | QCOMPARE(setSpy2.count(), 1); |
|
437 | 436 | |
|
438 | 437 | seriesSpyArg = seriesSpy.takeFirst(); |
|
439 | 438 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); |
|
440 | 439 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); |
|
441 | 440 | QVERIFY(seriesSpyArg.at(0).toInt() == 2); |
|
442 | 441 | |
|
443 | 442 | setSpyArg = setSpy2.takeFirst(); |
|
444 | 443 | QVERIFY(setSpyArg.at(0).type() == QVariant::Int); |
|
445 | 444 | QVERIFY(setSpyArg.at(0).toInt() == 2); |
|
446 | 445 | } |
|
447 | 446 | |
|
448 | 447 | void tst_QHorizontalBarSeries::mousehovered_data() |
|
449 | 448 | { |
|
450 | 449 | |
|
451 | 450 | } |
|
452 | 451 | |
|
453 | 452 | void tst_QHorizontalBarSeries::mousehovered() |
|
454 | 453 | { |
|
455 | 454 | QHorizontalBarSeries* series = new QHorizontalBarSeries(); |
|
456 | 455 | |
|
457 | 456 | QBarSet* set1 = new QBarSet(QString("set 1")); |
|
458 | 457 | *set1 << 10 << 10 << 10; |
|
459 | 458 | series->append(set1); |
|
460 | 459 | |
|
461 | 460 | QBarSet* set2 = new QBarSet(QString("set 2")); |
|
462 | 461 | *set2 << 10 << 10 << 10; |
|
463 | 462 | series->append(set2); |
|
464 | 463 | |
|
465 | 464 | QSignalSpy seriesSpy(series,SIGNAL(hovered(bool,QBarSet*))); |
|
466 | 465 | QSignalSpy setSpy1(set1, SIGNAL(hovered(bool))); |
|
467 | 466 | QSignalSpy setSpy2(set2, SIGNAL(hovered(bool))); |
|
468 | 467 | |
|
469 | 468 | QChartView view(new QChart()); |
|
470 | 469 | view.resize(400,300); |
|
471 | 470 | view.chart()->addSeries(series); |
|
472 | 471 | view.show(); |
|
473 | 472 | QTest::qWaitForWindowShown(&view); |
|
474 | 473 | |
|
475 | 474 | //this is hack since view does not get events otherwise |
|
476 | 475 | view.setMouseTracking(true); |
|
477 | 476 | |
|
478 | 477 | //======================================================================= |
|
479 | 478 | // move mouse to bottom border |
|
480 | 479 | QTest::mouseMove(view.viewport(), QPoint(200, 300)); |
|
481 | 480 | QCoreApplication::processEvents(QEventLoop::AllEvents, 10000); |
|
482 | 481 | TRY_COMPARE(seriesSpy.count(), 0); |
|
483 | 482 | TRY_COMPARE(setSpy1.count(), 0); |
|
484 | 483 | TRY_COMPARE(setSpy2.count(), 0); |
|
485 | 484 | |
|
486 | 485 | //======================================================================= |
|
487 | 486 | // move mouse on top of set1 |
|
488 | 487 | QTest::mouseMove(view.viewport(), QPoint(200,218)); |
|
489 | 488 | TRY_COMPARE(seriesSpy.count(), 1); |
|
490 | 489 | TRY_COMPARE(setSpy1.count(), 1); |
|
491 | 490 | TRY_COMPARE(setSpy2.count(), 0); |
|
492 | 491 | |
|
493 | 492 | QList<QVariant> seriesSpyArg = seriesSpy.takeFirst(); |
|
494 | 493 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); |
|
495 | 494 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); |
|
496 | 495 | QVERIFY(seriesSpyArg.at(0).toBool() == true); |
|
497 | 496 | |
|
498 | 497 | QList<QVariant> setSpyArg = setSpy1.takeFirst(); |
|
499 | 498 | QVERIFY(setSpyArg.at(0).type() == QVariant::Bool); |
|
500 | 499 | QVERIFY(setSpyArg.at(0).toBool() == true); |
|
501 | 500 | |
|
502 | 501 | //======================================================================= |
|
503 | 502 | // move mouse from top of set1 to top of set2 |
|
504 | 503 | QTest::mouseMove(view.viewport(), QPoint(200,203)); |
|
505 | 504 | TRY_COMPARE(seriesSpy.count(), 2); |
|
506 | 505 | TRY_COMPARE(setSpy1.count(), 1); |
|
507 | 506 | TRY_COMPARE(setSpy2.count(), 1); |
|
508 | 507 | |
|
509 | 508 | // should leave set1 |
|
510 | 509 | seriesSpyArg = seriesSpy.takeFirst(); |
|
511 | 510 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); |
|
512 | 511 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); |
|
513 | 512 | QVERIFY(seriesSpyArg.at(0).toBool() == false); |
|
514 | 513 | |
|
515 | 514 | setSpyArg = setSpy1.takeFirst(); |
|
516 | 515 | QVERIFY(setSpyArg.at(0).type() == QVariant::Bool); |
|
517 | 516 | QVERIFY(setSpyArg.at(0).toBool() == false); |
|
518 | 517 | |
|
519 | 518 | // should enter set2 |
|
520 | 519 | seriesSpyArg = seriesSpy.takeFirst(); |
|
521 | 520 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); |
|
522 | 521 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); |
|
523 | 522 | QVERIFY(seriesSpyArg.at(0).toBool() == true); |
|
524 | 523 | |
|
525 | 524 | setSpyArg = setSpy2.takeFirst(); |
|
526 | 525 | QVERIFY(setSpyArg.at(0).type() == QVariant::Bool); |
|
527 | 526 | QVERIFY(setSpyArg.at(0).toBool() == true); |
|
528 | 527 | |
|
529 | 528 | //======================================================================= |
|
530 | 529 | // move mouse from top of set2 to background |
|
531 | 530 | QTest::mouseMove(view.viewport(), QPoint(0,203)); |
|
532 | 531 | TRY_COMPARE(seriesSpy.count(), 1); |
|
533 | 532 | TRY_COMPARE(setSpy1.count(), 0); |
|
534 | 533 | TRY_COMPARE(setSpy2.count(), 1); |
|
535 | 534 | |
|
536 | 535 | // should leave set2 |
|
537 | 536 | seriesSpyArg = seriesSpy.takeFirst(); |
|
538 | 537 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); |
|
539 | 538 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); |
|
540 | 539 | QVERIFY(seriesSpyArg.at(0).toBool() == false); |
|
541 | 540 | |
|
542 | 541 | setSpyArg = setSpy2.takeFirst(); |
|
543 | 542 | QVERIFY(setSpyArg.at(0).type() == QVariant::Bool); |
|
544 | 543 | QVERIFY(setSpyArg.at(0).toBool() == false); |
|
545 | 544 | } |
|
546 | 545 | |
|
547 | 546 | void tst_QHorizontalBarSeries::clearWithAnimations() |
|
548 | 547 | { |
|
549 | 548 | QHorizontalBarSeries* series = new QHorizontalBarSeries(); |
|
550 | 549 | |
|
551 | 550 | QBarSet* set1 = new QBarSet(QString("set 1")); |
|
552 | 551 | *set1 << 10 << 10 << 10; |
|
553 | 552 | series->append(set1); |
|
554 | 553 | |
|
555 | 554 | QBarSet* set2 = new QBarSet(QString("set 2")); |
|
556 | 555 | *set2 << 10 << 10 << 10; |
|
557 | 556 | series->append(set2); |
|
558 | 557 | |
|
559 | 558 | QChartView view(new QChart()); |
|
560 | 559 | view.resize(400,300); |
|
561 | 560 | view.chart()->setAnimationOptions(QChart::SeriesAnimations); |
|
562 | 561 | view.chart()->addSeries(series); |
|
563 | 562 | view.show(); |
|
564 | 563 | |
|
565 | 564 | series->clear(); |
|
566 | 565 | } |
|
567 | 566 | |
|
568 | 567 | QTEST_MAIN(tst_QHorizontalBarSeries) |
|
569 | 568 | |
|
570 | 569 | #include "tst_qhorizontalbarseries.moc" |
|
571 | 570 |
General Comments 0
You need to be logged in to leave comments.
Login now