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