##// END OF EJS Templates
Added two model related tests to pieseries
Marek Rosa -
r1180:1a2d53d6021f
parent child
Show More
@@ -74,6 +74,7 void QPieModelMapper::reset()
74 m_orientation = Qt::Vertical;
74 m_orientation = Qt::Vertical;
75 m_mapValues = -1;
75 m_mapValues = -1;
76 m_mapLabels = -1;
76 m_mapLabels = -1;
77 emit updated();
77 }
78 }
78
79
79 #include "moc_qpiemodelmapper.cpp"
80 #include "moc_qpiemodelmapper.cpp"
@@ -722,6 +722,10 void QPieSeriesPrivate::initializePieFromModel()
722 // clear current content
722 // clear current content
723 q->clear();
723 q->clear();
724
724
725 // check if mappings are set
726 if (m_mapper->mapValues() == -1 || m_mapper->mapLabels() == -1)
727 return;
728
725 // create the initial slices set
729 // create the initial slices set
726 if (m_mapper->orientation() == Qt::Vertical) {
730 if (m_mapper->orientation() == Qt::Vertical) {
727 if (m_mapper->mapValues() >= m_model->columnCount() || m_mapper->mapLabels() >= m_model->columnCount())
731 if (m_mapper->mapValues() >= m_model->columnCount() || m_mapper->mapLabels() >= m_model->columnCount())
@@ -23,6 +23,8
23 #include <qchart.h>
23 #include <qchart.h>
24 #include <qpieseries.h>
24 #include <qpieseries.h>
25 #include <qpieslice.h>
25 #include <qpieslice.h>
26 #include <qpiemodelmapper.h>
27 #include <QStandardItemModel>
26 #include <tst_definitions.h>
28 #include <tst_definitions.h>
27
29
28 QTCOMMERCIALCHART_USE_NAMESPACE
30 QTCOMMERCIALCHART_USE_NAMESPACE
@@ -47,6 +49,8 private slots:
47 void calculatedValues();
49 void calculatedValues();
48 void clickedSignal();
50 void clickedSignal();
49 void hoverSignal();
51 void hoverSignal();
52 void model();
53 void modelCustomMap();
50
54
51 private:
55 private:
52 void verifyCalculatedData(const QPieSeries &series, bool *ok);
56 void verifyCalculatedData(const QPieSeries &series, bool *ok);
@@ -320,6 +324,74 void tst_qpieseries::hoverSignal()
320 QCOMPARE(qvariant_cast<bool>(hoverSpy.at(1).at(1)), false);
324 QCOMPARE(qvariant_cast<bool>(hoverSpy.at(1).at(1)), false);
321 }
325 }
322
326
327 void tst_qpieseries::model()
328 {
329 QPieSeries *series = new QPieSeries;
330 QStandardItemModel *stdModel = new QStandardItemModel(0, 2);
331 series->setModel(stdModel);
332 QVERIFY2((series->model()) == stdModel, "Model should be stdModel");
333
334 int rowCount = 3;
335 for (int row = 0; row < rowCount; ++row) {
336 for (int column = 0; column < 2; column++) {
337 QStandardItem *item = new QStandardItem(row * column);
338 stdModel->setItem(row, column, item);
339 }
340 }
341
342 // data has been added to the model, but mapper is not set the number of slices should still be 0
343 QVERIFY2(series->slices().count() == 0, "Mapper has not been set, so the number of slices should be 0");
344
345 // set the mapper
346 QPieModelMapper *mapper = new QPieModelMapper;
347 mapper->setMapValues(0);
348 mapper->setMapLabels(0);
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
350 QCOMPARE(series->slices().count(), rowCount);
351
352 // reset the mappings
353 mapper->reset();
354 QCOMPARE(series->slices().count(), 0); // Mappings have been reset and are invalid, so the number of slices should be 0
355
356 // unset the model and the mapper
357 series->setModel(0);
358 series->setModelMapper(0);
359 QVERIFY(series->model() == 0); // Model should be unset
360 QVERIFY(series->modelMapper() == 0); // Model mapper should be unset
361 }
362
363 void tst_qpieseries::modelCustomMap()
364 {
365 int rowCount = 12;
366 QStandardItemModel *stdModel = new QStandardItemModel(0, 2);
367 for (int row = 0; row < rowCount; ++row) {
368 for (int column = 0; column < 2; column++) {
369 QStandardItem *item = new QStandardItem(row * column);
370 stdModel->setItem(row, column, item);
371 }
372 }
373
374 QPieSeries *series = new QPieSeries;
375 series->setModel(stdModel);
376
377 QPieModelMapper *mapper = new QPieModelMapper;
378 mapper->setMapValues(0);
379 mapper->setMapLabels(0);
380 series->setModelMapper(mapper);
381 QCOMPARE(series->slices().count(), rowCount);
382
383 // lets customize the mapping
384 int first = 3;
385 mapper->setFirst(first);
386 QCOMPARE(series->slices().count(), rowCount - first);
387 int count = 7;
388 mapper->setCount(count);
389 QCOMPARE(series->slices().count(), count);
390 first = 9;
391 mapper->setFirst(first);
392 QCOMPARE(series->slices().count(), qMin(count, rowCount - first));
393 }
394
323 QTEST_MAIN(tst_qpieseries)
395 QTEST_MAIN(tst_qpieseries)
324
396
325 #include "tst_qpieseries.moc"
397 #include "tst_qpieseries.moc"
General Comments 0
You need to be logged in to leave comments. Login now