diff --git a/src/piechart/qpiemodelmapper.cpp b/src/piechart/qpiemodelmapper.cpp index 775d402..553ab27 100644 --- a/src/piechart/qpiemodelmapper.cpp +++ b/src/piechart/qpiemodelmapper.cpp @@ -73,7 +73,6 @@ void QPieModelMapper::setFirst(int first) Q_D(QPieModelMapper); d->m_first = qMax(first, 0); d->initializePieFromModel(); - // emit updated(); } int QPieModelMapper::count() const @@ -87,7 +86,6 @@ void QPieModelMapper::setCount(int count) Q_D(QPieModelMapper); d->m_count = qMax(count, -1); d->initializePieFromModel(); - // emit updated(); } Qt::Orientation QPieModelMapper::orientation() const @@ -101,7 +99,6 @@ void QPieModelMapper::setOrientation(Qt::Orientation orientation) Q_D(QPieModelMapper); d->m_orientation = orientation; d->initializePieFromModel(); - // emit updated(); } int QPieModelMapper::valuesIndex() const @@ -110,12 +107,11 @@ int QPieModelMapper::valuesIndex() const return d->m_valuesIndex; } -void QPieModelMapper::setValuesIndex(int mapValues) +void QPieModelMapper::setValuesIndex(int valuesIndex) { Q_D(QPieModelMapper); - d->m_valuesIndex = mapValues; + d->m_valuesIndex = qMax(-1, valuesIndex); d->initializePieFromModel(); - // emit updated(); } int QPieModelMapper::labelsIndex() const @@ -124,12 +120,11 @@ int QPieModelMapper::labelsIndex() const return d->m_labelsIndex; } -void QPieModelMapper::setLabelsIndex(int mapLabels) +void QPieModelMapper::setLabelsIndex(int labelsIndex) { Q_D(QPieModelMapper); - d->m_labelsIndex = mapLabels; + d->m_labelsIndex = qMax(-1, labelsIndex); d->initializePieFromModel(); - // emit updated(); } void QPieModelMapper::reset() @@ -140,7 +135,6 @@ void QPieModelMapper::reset() d->m_orientation = Qt::Vertical; d->m_valuesIndex = -1; d->m_labelsIndex = -1; - // emit updated(); } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -439,10 +433,6 @@ void QPieModelMapperPrivate::initializePieFromModel() if (m_model == 0 || m_series == 0) return; - // check if mappings are set - if (m_valuesIndex == -1 || m_labelsIndex == -1) - return; - blockSeriesSignals(); // clear current content m_series->clear(); diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index d834162..09f0e45 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -3,7 +3,7 @@ } TEMPLATE = subdirs -SUBDIRS += qchartview qchart qlineseries qbarset qbarseries qstackedbarseries qpercentbarseries qgroupedbarseries qpieslice qpieseries +SUBDIRS += qchartview qchart qlineseries qbarset qbarseries qstackedbarseries qpercentbarseries qgroupedbarseries qpieslice qpieseries qpiemodelmapper test_private:{ SUBDIRS += chartdataset domain diff --git a/tests/auto/qpiemodelmapper/qpiemodelmapper.pro b/tests/auto/qpiemodelmapper/qpiemodelmapper.pro new file mode 100644 index 0000000..3a3995e --- /dev/null +++ b/tests/auto/qpiemodelmapper/qpiemodelmapper.pro @@ -0,0 +1,8 @@ +!include( ../auto.pri ) { + error( "Couldn't find the auto.pri file!" ) +} + +SOURCES += \ + tst_qpiemodelmapper.cpp + +!system_build:mac: QMAKE_POST_LINK += "$$MAC_POST_LINK_PREFIX $$MAC_AUTOTESTS_BIN_DIR" diff --git a/tests/auto/qpiemodelmapper/tst_qpiemodelmapper.cpp b/tests/auto/qpiemodelmapper/tst_qpiemodelmapper.cpp new file mode 100644 index 0000000..87d0988 --- /dev/null +++ b/tests/auto/qpiemodelmapper/tst_qpiemodelmapper.cpp @@ -0,0 +1,241 @@ +#include +#include + +#include +#include +#include +#include +#include +#include + +QTCOMMERCIALCHART_USE_NAMESPACE + +class tst_piemodelmapper : public QObject +{ + Q_OBJECT + + public: + tst_piemodelmapper(); + + private Q_SLOTS: + void initTestCase(); + void cleanupTestCase(); + void init(); + void cleanup(); + void verticalMapper_data(); + void verticalMapper(); + void verticalMapperCustomMapping_data(); + void verticalMapperCustomMapping(); + void horizontalMapper_data(); + void horizontalMapper(); + void horizontalMapperCustomMapping_data(); + void horizontalMapperCustomMapping(); + + + private: + QStandardItemModel *m_model; + int m_modelRowCount; + int m_modelColumnCount; + + QPieSeries *m_series; + QChart *m_chart; +}; + +tst_piemodelmapper::tst_piemodelmapper(): + m_model(0), + m_modelRowCount(10), + m_modelColumnCount(8) +{ +} + +void tst_piemodelmapper::init() +{ + m_series = new QPieSeries; + m_chart->addSeries(m_series); +} + +void tst_piemodelmapper::cleanup() +{ + m_chart->removeSeries(m_series); + delete m_series; + m_series = 0; +} + +void tst_piemodelmapper::initTestCase() +{ + m_chart = new QChart; + QChartView *chartView = new QChartView(m_chart); + chartView->show(); + + m_model = new QStandardItemModel(this); + for (int row = 0; row < m_modelRowCount; ++row) { + for (int column = 0; column < m_modelColumnCount; column++) { + QStandardItem *item = new QStandardItem(row * column); + m_model->setItem(row, column, item); + } + } +} + +void tst_piemodelmapper::cleanupTestCase() +{ + m_model->clear(); +} + +void tst_piemodelmapper::verticalMapper_data() +{ + QTest::addColumn("valuesColumn"); + QTest::addColumn("labelsColumn"); + QTest::addColumn("expectedCount"); + QTest::newRow("different values and labels columns") << 0 << 1 << m_modelRowCount; + QTest::newRow("same values and labels columns") << 1 << 1 << m_modelRowCount; + QTest::newRow("invalid values column and correct labels column") << -3 << 1 << 0; + QTest::newRow("values column beyond the size of model and correct labels column") << m_modelColumnCount << 1 << 0; + QTest::newRow("values column beyond the size of model and correct labels column") << m_modelColumnCount << -1 << 0; +} + +void tst_piemodelmapper::verticalMapper() +{ + QFETCH(int, valuesColumn); + QFETCH(int, labelsColumn); + QFETCH(int, expectedCount); + + QVPieModelMapper *mapper = new QVPieModelMapper; + mapper->setValuesColumn(valuesColumn); + mapper->setLabelsColumn(labelsColumn); + mapper->setModel(m_model); + mapper->setSeries(m_series); + + QCOMPARE(m_series->count(), expectedCount); + QCOMPARE(mapper->valuesColumn(), qMax(-1, valuesColumn)); + QCOMPARE(mapper->labelsColumn(), qMax(-1, labelsColumn)); + + delete mapper; + mapper = 0; +} + +void tst_piemodelmapper::verticalMapperCustomMapping_data() +{ + QTest::addColumn("first"); + QTest::addColumn("countLimit"); + QTest::addColumn("expectedCount"); + QTest::newRow("first: 0, unlimited count") << 0 << -1 << m_modelRowCount; + QTest::newRow("first: 3, unlimited count") << 3 << -1 << m_modelRowCount - 3; + QTest::newRow("first: 0, count: 5") << 0 << 5 << qMin(5, m_modelRowCount); + QTest::newRow("first: 3, count: 5") << 3 << 5 << qMin(5, m_modelRowCount - 3); + QTest::newRow("first: +1 greater then the number of rows in the model, unlimited count") << m_modelRowCount + 1 << -1 << 0; + QTest::newRow("first: +1 greater then the number of rows in the model, count: 5") << m_modelRowCount + 1 << 5 << 0; + QTest::newRow("first: 0, count: +3 greater than the number of rows in the model (should limit to the size of model)") << 0 << m_modelRowCount + 3 << m_modelRowCount; + QTest::newRow("first: -3(invalid - should default to 0), unlimited count") << -3 << -1 << m_modelRowCount; + QTest::newRow("first: 0, count: -3 (invalid - shlould default to -1)") << 0 << -3 << m_modelRowCount; + QTest::newRow("first: -3(invalid - should default to 0), count: -3 (invalid - shlould default to -1)") << -3 << -3 << m_modelRowCount; + +} + +void tst_piemodelmapper::verticalMapperCustomMapping() +{ + QFETCH(int, first); + QFETCH(int, countLimit); + QFETCH(int, expectedCount); + + QCOMPARE(m_series->count(), 0); + + QVPieModelMapper *mapper = new QVPieModelMapper; + mapper->setValuesColumn(0); + mapper->setLabelsColumn(1); + mapper->setModel(m_model); + mapper->setSeries(m_series); + mapper->setFirst(first); + mapper->setCount(countLimit); + + QCOMPARE(m_series->count(), expectedCount); + + // change values column mappings to invalid + mapper->setValuesColumn(-1); + mapper->setLabelsColumn(1); + + QCOMPARE(m_series->count(), 0); + + delete mapper; + mapper = 0; +} + +void tst_piemodelmapper::horizontalMapper_data() +{ + QTest::addColumn("valuesRow"); + QTest::addColumn("labelsRow"); + QTest::addColumn("expectedCount"); + QTest::newRow("different values and labels rows") << 0 << 1 << m_modelColumnCount; + QTest::newRow("same values and labels rows") << 1 << 1 << m_modelColumnCount; + QTest::newRow("invalid values row and correct labels row") << -3 << 1 << 0; + QTest::newRow("values row beyond the size of model and correct labels row") << m_modelRowCount << 1 << 0; + QTest::newRow("values row beyond the size of model and invalid labels row") << m_modelRowCount << -1 << 0; +} + +void tst_piemodelmapper::horizontalMapper() +{ + QFETCH(int, valuesRow); + QFETCH(int, labelsRow); + QFETCH(int, expectedCount); + + QHPieModelMapper *mapper = new QHPieModelMapper; + mapper->setValuesRow(valuesRow); + mapper->setLabelsRow(labelsRow); + mapper->setModel(m_model); + mapper->setSeries(m_series); + + QCOMPARE(m_series->count(), expectedCount); + QCOMPARE(mapper->valuesRow(), qMax(-1, valuesRow)); + QCOMPARE(mapper->labelsRow(), qMax(-1, labelsRow)); + + delete mapper; + mapper = 0; +} + +void tst_piemodelmapper::horizontalMapperCustomMapping_data() +{ + QTest::addColumn("first"); + QTest::addColumn("countLimit"); + QTest::addColumn("expectedCount"); + QTest::newRow("first: 0, unlimited count") << 0 << -1 << m_modelColumnCount; + QTest::newRow("first: 3, unlimited count") << 3 << -1 << m_modelColumnCount - 3; + QTest::newRow("first: 0, count: 5") << 0 << 5 << qMin(5, m_modelColumnCount); + QTest::newRow("first: 3, count: 5") << 3 << 5 << qMin(5, m_modelColumnCount - 3); + QTest::newRow("first: +1 greater then the number of columns in the model, unlimited count") << m_modelColumnCount + 1 << -1 << 0; + QTest::newRow("first: +1 greater then the number of columns in the model, count: 5") << m_modelColumnCount + 1 << 5 << 0; + QTest::newRow("first: 0, count: +3 greater than the number of columns in the model (should limit to the size of model)") << 0 << m_modelColumnCount + 3 << m_modelColumnCount; + QTest::newRow("first: -3(invalid - should default to 0), unlimited count") << -3 << -1 << m_modelColumnCount; + QTest::newRow("first: 0, count: -3 (invalid - shlould default to -1)") << 0 << -3 << m_modelColumnCount; + QTest::newRow("first: -3(invalid - should default to 0), count: -3 (invalid - shlould default to -1)") << -3 << -3 << m_modelColumnCount; +} + +void tst_piemodelmapper::horizontalMapperCustomMapping() +{ + QFETCH(int, first); + QFETCH(int, countLimit); + QFETCH(int, expectedCount); + + QCOMPARE(m_series->count(), 0); + + QHPieModelMapper *mapper = new QHPieModelMapper; + mapper->setValuesRow(0); + mapper->setLabelsRow(1); + mapper->setModel(m_model); + mapper->setSeries(m_series); + mapper->setFirst(first); + mapper->setCount(countLimit); + + QCOMPARE(m_series->count(), expectedCount); + + // change values column mappings to invalid + mapper->setValuesRow(-1); + mapper->setLabelsRow(1); + + QCOMPARE(m_series->count(), 0); + + delete mapper; + mapper = 0; +} + +QTEST_MAIN(tst_piemodelmapper) + +#include "tst_qpiemodelmapper.moc" diff --git a/tests/tablemodelchart/tablewidget.cpp b/tests/tablemodelchart/tablewidget.cpp index 3fa3420..64e123d 100644 --- a/tests/tablemodelchart/tablewidget.cpp +++ b/tests/tablemodelchart/tablewidget.cpp @@ -355,7 +355,7 @@ void TableWidget::updateChartType(bool toggle) m_pieMapper->setSeries(m_pieSeries); m_pieMapper->setModel(m_model); m_pieMapper->setFirst(2); - m_pieMapper->setCount(5); +// m_pieMapper->setCount(5); // pieSeries->setModelMapper(mapper); m_pieSeries->setLabelsVisible(true);