From c54b94e53f204db545505094408f7a2ef839e02c 2012-08-30 12:48:58 From: Marek Rosa Date: 2012-08-30 12:48:58 Subject: [PATCH] Added signals test cases to xymodelmapper plus fix to xymodelmapper --- diff --git a/src/xychart/qhxymodelmapper.cpp b/src/xychart/qhxymodelmapper.cpp index d6f0484..8b47db6 100644 --- a/src/xychart/qhxymodelmapper.cpp +++ b/src/xychart/qhxymodelmapper.cpp @@ -223,7 +223,7 @@ void QHXYModelMapper::setColumnCount(int columnCount) { if (columnCount != count()) { setCount(columnCount); - emit firstColumnChanged(); + emit columnCountChanged(); } } diff --git a/src/xychart/qvxymodelmapper.cpp b/src/xychart/qvxymodelmapper.cpp index 94ca74f..c00abea 100644 --- a/src/xychart/qvxymodelmapper.cpp +++ b/src/xychart/qvxymodelmapper.cpp @@ -223,7 +223,7 @@ void QVXYModelMapper::setRowCount(int rowCount) { if (rowCount != count()) { setCount(rowCount); - emit firstRowChanged(); + emit rowCountChanged(); } } diff --git a/tests/auto/qxymodelmapper/tst_qxymodelmapper.cpp b/tests/auto/qxymodelmapper/tst_qxymodelmapper.cpp index 4aa033c..e650577 100644 --- a/tests/auto/qxymodelmapper/tst_qxymodelmapper.cpp +++ b/tests/auto/qxymodelmapper/tst_qxymodelmapper.cpp @@ -63,6 +63,8 @@ class tst_qxymodelmapper : public QObject void horizontalModelInsertColumns(); void horizontalModelRemoveColumns(); void modelUpdateCell(); + void verticalMapperSignals(); + void horizontalMapperSignals(); private: QStandardItemModel *m_model; @@ -524,6 +526,59 @@ void tst_qxymodelmapper::modelUpdateCell() QCOMPARE(m_model->data(m_model->index(1, 0)).toReal(), 44.0); } +void tst_qxymodelmapper::verticalMapperSignals() +{ + QVXYModelMapper *mapper = new QVXYModelMapper; + + QSignalSpy spy0(mapper, SIGNAL(firstRowChanged())); + QSignalSpy spy1(mapper, SIGNAL(rowCountChanged())); + QSignalSpy spy2(mapper, SIGNAL(xColumnChanged())); + QSignalSpy spy3(mapper, SIGNAL(yColumnChanged())); + QSignalSpy spy4(mapper, SIGNAL(modelReplaced())); + QSignalSpy spy5(mapper, SIGNAL(seriesReplaced())); + + mapper->setXColumn(0); + mapper->setYColumn(1); + mapper->setModel(m_model); + mapper->setSeries(m_series); + mapper->setFirstRow(1); + mapper->setRowCount(5); + + QCOMPARE(spy0.count(), 1); + QCOMPARE(spy1.count(), 1); + QCOMPARE(spy2.count(), 1); + QCOMPARE(spy3.count(), 1); + QCOMPARE(spy4.count(), 1); + QCOMPARE(spy5.count(), 1); + +} + +void tst_qxymodelmapper::horizontalMapperSignals() +{ + QHXYModelMapper *mapper = new QHXYModelMapper; + + QSignalSpy spy0(mapper, SIGNAL(firstColumnChanged())); + QSignalSpy spy1(mapper, SIGNAL(columnCountChanged())); + QSignalSpy spy2(mapper, SIGNAL(xRowChanged())); + QSignalSpy spy3(mapper, SIGNAL(yRowChanged())); + QSignalSpy spy4(mapper, SIGNAL(modelReplaced())); + QSignalSpy spy5(mapper, SIGNAL(seriesReplaced())); + + mapper->setXRow(0); + mapper->setYRow(1); + mapper->setModel(m_model); + mapper->setSeries(m_series); + mapper->setFirstColumn(1); + mapper->setColumnCount(5); + + QCOMPARE(spy0.count(), 1); + QCOMPARE(spy1.count(), 1); + QCOMPARE(spy2.count(), 1); + QCOMPARE(spy3.count(), 1); + QCOMPARE(spy4.count(), 1); + QCOMPARE(spy5.count(), 1); +} + QTEST_MAIN(tst_qxymodelmapper) #include "tst_qxymodelmapper.moc"