##// END OF EJS Templates
More model related tests for Pie
Marek Rosa -
r1182:b3b206fa2a47
parent child
Show More
@@ -51,6 +51,7 private slots:
51 void hoverSignal();
51 void hoverSignal();
52 void model();
52 void model();
53 void modelCustomMap();
53 void modelCustomMap();
54 void modelUpdate();
54
55
55 private:
56 private:
56 void verifyCalculatedData(const QPieSeries &series, bool *ok);
57 void verifyCalculatedData(const QPieSeries &series, bool *ok);
@@ -327,6 +328,11 void tst_qpieseries::hoverSignal()
327 void tst_qpieseries::model()
328 void tst_qpieseries::model()
328 {
329 {
329 QPieSeries *series = new QPieSeries;
330 QPieSeries *series = new QPieSeries;
331 QChart *chart = new QChart;
332 chart->addSeries(series);
333 QChartView *chartView = new QChartView(chart);
334 chartView->show();
335
330 QStandardItemModel *stdModel = new QStandardItemModel(0, 2);
336 QStandardItemModel *stdModel = new QStandardItemModel(0, 2);
331 series->setModel(stdModel);
337 series->setModel(stdModel);
332 QVERIFY2((series->model()) == stdModel, "Model should be stdModel");
338 QVERIFY2((series->model()) == stdModel, "Model should be stdModel");
@@ -349,6 +355,16 void tst_qpieseries::model()
349 series->setModelMapper(mapper); // this should cause the Pie to get initialized from the model, since there is now both the model and the mapper defined
355 series->setModelMapper(mapper); // this should cause the Pie to get initialized from the model, since there is now both the model and the mapper defined
350 QCOMPARE(series->slices().count(), rowCount);
356 QCOMPARE(series->slices().count(), rowCount);
351
357
358 // set the mappings to be outside of the model
359 mapper->setMapLabels(5);
360 mapper->setMapValues(4);
361 QCOMPARE(series->slices().count(), 0); // Mappings are invalid, so the number of slices should be 0
362
363 // set back to correct ones
364 mapper->setMapValues(0);
365 mapper->setMapLabels(0);
366 QCOMPARE(series->slices().count(), rowCount);
367
352 // reset the mappings
368 // reset the mappings
353 mapper->reset();
369 mapper->reset();
354 QCOMPARE(series->slices().count(), 0); // Mappings have been reset and are invalid, so the number of slices should be 0
370 QCOMPARE(series->slices().count(), 0); // Mappings have been reset and are invalid, so the number of slices should be 0
@@ -363,7 +379,8 void tst_qpieseries::model()
363 void tst_qpieseries::modelCustomMap()
379 void tst_qpieseries::modelCustomMap()
364 {
380 {
365 int rowCount = 12;
381 int rowCount = 12;
366 QStandardItemModel *stdModel = new QStandardItemModel(0, 2);
382 int columnCount = 3;
383 QStandardItemModel *stdModel = new QStandardItemModel(0, 3);
367 for (int row = 0; row < rowCount; ++row) {
384 for (int row = 0; row < rowCount; ++row) {
368 for (int column = 0; column < 2; column++) {
385 for (int column = 0; column < 2; column++) {
369 QStandardItem *item = new QStandardItem(row * column);
386 QStandardItem *item = new QStandardItem(row * column);
@@ -372,6 +389,10 void tst_qpieseries::modelCustomMap()
372 }
389 }
373
390
374 QPieSeries *series = new QPieSeries;
391 QPieSeries *series = new QPieSeries;
392 QChart *chart = new QChart;
393 chart->addSeries(series);
394 QChartView *chartView = new QChartView(chart);
395 chartView->show();
375 series->setModel(stdModel);
396 series->setModel(stdModel);
376
397
377 QPieModelMapper *mapper = new QPieModelMapper;
398 QPieModelMapper *mapper = new QPieModelMapper;
@@ -380,6 +401,14 void tst_qpieseries::modelCustomMap()
380 series->setModelMapper(mapper);
401 series->setModelMapper(mapper);
381 QCOMPARE(series->slices().count(), rowCount);
402 QCOMPARE(series->slices().count(), rowCount);
382
403
404 // lets change the orientation to horizontal
405 mapper->setOrientation(Qt::Horizontal);
406 QCOMPARE(series->slices().count(), columnCount);
407
408 // change it back to vertical
409 mapper->setOrientation(Qt::Vertical);
410 QCOMPARE(series->slices().count(), rowCount);
411
383 // lets customize the mapping
412 // lets customize the mapping
384 int first = 3;
413 int first = 3;
385 mapper->setFirst(first);
414 mapper->setFirst(first);
@@ -392,6 +421,56 void tst_qpieseries::modelCustomMap()
392 QCOMPARE(series->slices().count(), qMin(count, rowCount - first));
421 QCOMPARE(series->slices().count(), qMin(count, rowCount - first));
393 }
422 }
394
423
424 void tst_qpieseries::modelUpdate()
425 {
426 int rowCount = 12;
427 int columnCount = 7;
428 QStandardItemModel *stdModel = new QStandardItemModel(0, 3);
429 for (int row = 0; row < rowCount; ++row) {
430 for (int column = 0; column < 2; column++) {
431 QStandardItem *item = new QStandardItem(row * column);
432 stdModel->setItem(row, column, item);
433 }
434 }
435
436 QPieSeries *series = new QPieSeries;
437 QChart *chart = new QChart;
438 chart->addSeries(series);
439 QChartView *chartView = new QChartView(chart);
440 chartView->show();
441 series->setModel(stdModel);
442
443 QPieModelMapper *mapper = new QPieModelMapper;
444 mapper->setMapValues(0);
445 mapper->setMapLabels(0);
446 series->setModelMapper(mapper);
447
448 stdModel->insertRows(3, 5);
449 QCOMPARE(series->slices().count(), rowCount + 5);
450
451 stdModel->removeRows(10, 5);
452 QCOMPARE(series->slices().count(), rowCount);
453
454 // limit the number of slices taken from the model to 12
455 mapper->setCount(rowCount);
456 stdModel->insertRows(3, 5);
457 QCOMPARE(series->slices().count(), rowCount);
458
459 stdModel->removeRows(0, 10);
460 QCOMPARE(series->slices().count(), rowCount - 5);
461
462 // change the orientation to horizontal
463 mapper->setOrientation(Qt::Horizontal);
464 QCOMPARE(series->slices().count(), columnCount);
465
466 stdModel->insertColumns(3, 10);
467 QCOMPARE(series->slices().count(), rowCount); // count is limited to rowCount (12)
468
469 stdModel->removeColumns(5, 10);
470 QCOMPARE(series->slices().count(), columnCount);
471
472 }
473
395 QTEST_MAIN(tst_qpieseries)
474 QTEST_MAIN(tst_qpieseries)
396
475
397 #include "tst_qpieseries.moc"
476 #include "tst_qpieseries.moc"
@@ -343,8 +343,8 void TableWidget::updateChartType(bool toggle)
343 pieSeries->setModel(m_model);
343 pieSeries->setModel(m_model);
344
344
345 QPieModelMapper *mapper = new QPieModelMapper;
345 QPieModelMapper *mapper = new QPieModelMapper;
346 mapper->setMapValues(1);
346 mapper->setMapValues(-1);
347 mapper->setMapLabels(1);
347 mapper->setMapLabels(-1);
348 mapper->setFirst(2);
348 mapper->setFirst(2);
349 mapper->setCount(5);
349 mapper->setCount(5);
350 pieSeries->setModelMapper(mapper);
350 pieSeries->setModelMapper(mapper);
@@ -355,7 +355,7 void TableWidget::updateChartType(bool toggle)
355 // pieSeries->setVerticalPosition(0.3);
355 // pieSeries->setVerticalPosition(0.3);
356
356
357 m_chart->addSeries(pieSeries);
357 m_chart->addSeries(pieSeries);
358 seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper();
358 // seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper();
359 m_model->addMapping(seriesColorHex, QRect(0, 2, 2, 5));
359 m_model->addMapping(seriesColorHex, QRect(0, 2, 2, 5));
360
360
361 // // pie 2
361 // // pie 2
General Comments 0
You need to be logged in to leave comments. Login now