tst_qpiemodelmapper.cpp
587 lines
| 19.0 KiB
| text/x-c
|
CppLexer
|
r1365 | /**************************************************************************** | ||
** | ||||
|
r2688 | ** Copyright (C) 2014 Digia Plc | ||
|
r1365 | ** All rights reserved. | ||
** For any questions to Digia, please use contact form at http://qt.digia.com | ||||
** | ||||
|
r2574 | ** This file is part of the Qt Enterprise Charts Add-on. | ||
|
r1365 | ** | ||
** $QT_BEGIN_LICENSE$ | ||||
|
r2574 | ** Licensees holding valid Qt Enterprise licenses may use this file in | ||
** accordance with the Qt Enterprise License Agreement provided with the | ||||
|
r1365 | ** Software or, alternatively, in accordance with the terms contained in | ||
** a written agreement between you and Digia. | ||||
** | ||||
** If you have questions regarding the use of this file, please use | ||||
** contact form at http://qt.digia.com | ||||
** $QT_END_LICENSE$ | ||||
** | ||||
****************************************************************************/ | ||||
|
r1239 | #include <QtCore/QString> | ||
#include <QtTest/QtTest> | ||||
|
r2714 | #include <QtCharts/QChart> | ||
#include <QtCharts/QChartView> | ||||
#include <QtCharts/QPieSeries> | ||||
#include <QtCharts/QPieSlice> | ||||
#include <QtCharts/QVPieModelMapper> | ||||
#include <QtCharts/QHPieModelMapper> | ||||
#include <QtGui/QStandardItemModel> | ||||
|
r1239 | |||
|
r2712 | QT_CHARTS_USE_NAMESPACE | ||
|
r1239 | |||
|
r1352 | class tst_qpiemodelmapper : public QObject | ||
|
r1239 | { | ||
Q_OBJECT | ||||
public: | ||||
|
r1352 | tst_qpiemodelmapper(); | ||
|
r1427 | void createVerticalMapper(); | ||
void createHorizontalMapper(); | ||||
|
r1239 | |||
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(); | ||||
|
r1251 | void seriesUpdated(); | ||
|
r1427 | void verticalModelInsertRows(); | ||
void verticalModelRemoveRows(); | ||||
void verticalModelInsertColumns(); | ||||
void verticalModelRemoveColumns(); | ||||
void horizontalModelInsertRows(); | ||||
void horizontalModelRemoveRows(); | ||||
void horizontalModelInsertColumns(); | ||||
void horizontalModelRemoveColumns(); | ||||
void modelUpdateCell(); | ||||
|
r1924 | void verticalMapperSignals(); | ||
void horizontalMapperSignals(); | ||||
|
r1239 | |||
private: | ||||
QStandardItemModel *m_model; | ||||
int m_modelRowCount; | ||||
int m_modelColumnCount; | ||||
|
r1427 | QVPieModelMapper *m_vMapper; | ||
QHPieModelMapper *m_hMapper; | ||||
|
r1239 | |||
QPieSeries *m_series; | ||||
QChart *m_chart; | ||||
|
r2733 | QChartView *m_chartView; | ||
|
r1239 | }; | ||
|
r1352 | tst_qpiemodelmapper::tst_qpiemodelmapper(): | ||
|
r1239 | m_model(0), | ||
m_modelRowCount(10), | ||||
|
r1427 | m_modelColumnCount(8), | ||
m_vMapper(0), | ||||
m_hMapper(0), | ||||
m_series(0), | ||||
|
r2733 | m_chart(0), | ||
m_chartView(0) | ||||
|
r1427 | { | ||
} | ||||
void tst_qpiemodelmapper::createVerticalMapper() | ||||
{ | ||||
m_vMapper = new QVPieModelMapper; | ||||
QVERIFY(m_vMapper->model() == 0); | ||||
m_vMapper->setValuesColumn(0); | ||||
m_vMapper->setLabelsColumn(1); | ||||
m_vMapper->setModel(m_model); | ||||
m_vMapper->setSeries(m_series); | ||||
} | ||||
void tst_qpiemodelmapper::createHorizontalMapper() | ||||
|
r1239 | { | ||
|
r1427 | m_hMapper = new QHPieModelMapper; | ||
QVERIFY(m_hMapper->model() == 0); | ||||
m_hMapper->setValuesRow(0); | ||||
m_hMapper->setLabelsRow(1); | ||||
m_hMapper->setModel(m_model); | ||||
m_hMapper->setSeries(m_series); | ||||
|
r1239 | } | ||
|
r1352 | void tst_qpiemodelmapper::init() | ||
|
r1239 | { | ||
m_series = new QPieSeries; | ||||
m_chart->addSeries(m_series); | ||||
|
r1427 | |||
m_model = new QStandardItemModel(m_modelRowCount, m_modelColumnCount, this); | ||||
for (int row = 0; row < m_modelRowCount; ++row) { | ||||
for (int column = 0; column < m_modelColumnCount; column++) { | ||||
m_model->setData(m_model->index(row, column), row * column); | ||||
} | ||||
} | ||||
|
r1239 | } | ||
|
r1352 | void tst_qpiemodelmapper::cleanup() | ||
|
r1239 | { | ||
m_chart->removeSeries(m_series); | ||||
|
r1427 | m_series->deleteLater(); | ||
|
r1239 | m_series = 0; | ||
|
r1427 | |||
m_model->clear(); | ||||
m_model->deleteLater(); | ||||
m_model = 0; | ||||
if (m_vMapper) { | ||||
m_vMapper->deleteLater(); | ||||
m_vMapper = 0; | ||||
} | ||||
if (m_hMapper) { | ||||
m_hMapper->deleteLater(); | ||||
m_hMapper = 0; | ||||
} | ||||
|
r1239 | } | ||
|
r1352 | void tst_qpiemodelmapper::initTestCase() | ||
|
r1239 | { | ||
m_chart = new QChart; | ||||
|
r2733 | m_chartView = new QChartView(m_chart); | ||
m_chartView->show(); | ||||
|
r1239 | } | ||
|
r1352 | void tst_qpiemodelmapper::cleanupTestCase() | ||
|
r1239 | { | ||
|
r2733 | delete m_chartView; | ||
QTest::qWait(1); // Allow final deleteLaters to run | ||||
|
r1239 | } | ||
|
r1352 | void tst_qpiemodelmapper::verticalMapper_data() | ||
|
r1239 | { | ||
QTest::addColumn<int>("valuesColumn"); | ||||
QTest::addColumn<int>("labelsColumn"); | ||||
QTest::addColumn<int>("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; | ||||
|
r1352 | QTest::newRow("values column beyond the size of model and invalid labels column") << m_modelColumnCount << -1 << 0; | ||
|
r1239 | } | ||
|
r1352 | void tst_qpiemodelmapper::verticalMapper() | ||
|
r1239 | { | ||
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; | ||||
} | ||||
|
r1352 | void tst_qpiemodelmapper::verticalMapperCustomMapping_data() | ||
|
r1239 | { | ||
QTest::addColumn<int>("first"); | ||||
QTest::addColumn<int>("countLimit"); | ||||
QTest::addColumn<int>("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; | ||||
} | ||||
|
r1352 | void tst_qpiemodelmapper::verticalMapperCustomMapping() | ||
|
r1239 | { | ||
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); | ||||
|
r1499 | mapper->setFirstRow(first); | ||
mapper->setRowCount(countLimit); | ||||
|
r1239 | |||
QCOMPARE(m_series->count(), expectedCount); | ||||
|
r1251 | // change values column mapping to invalid | ||
|
r1239 | mapper->setValuesColumn(-1); | ||
mapper->setLabelsColumn(1); | ||||
QCOMPARE(m_series->count(), 0); | ||||
delete mapper; | ||||
mapper = 0; | ||||
} | ||||
|
r1352 | void tst_qpiemodelmapper::horizontalMapper_data() | ||
|
r1239 | { | ||
QTest::addColumn<int>("valuesRow"); | ||||
QTest::addColumn<int>("labelsRow"); | ||||
QTest::addColumn<int>("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; | ||||
} | ||||
|
r1352 | void tst_qpiemodelmapper::horizontalMapper() | ||
|
r1239 | { | ||
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; | ||||
} | ||||
|
r1352 | void tst_qpiemodelmapper::horizontalMapperCustomMapping_data() | ||
|
r1239 | { | ||
QTest::addColumn<int>("first"); | ||||
QTest::addColumn<int>("countLimit"); | ||||
QTest::addColumn<int>("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; | ||||
} | ||||
|
r1352 | void tst_qpiemodelmapper::horizontalMapperCustomMapping() | ||
|
r1239 | { | ||
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); | ||||
|
r1499 | mapper->setFirstColumn(first); | ||
mapper->setColumnCount(countLimit); | ||||
|
r1239 | |||
QCOMPARE(m_series->count(), expectedCount); | ||||
|
r1251 | // change values row mapping to invalid | ||
|
r1239 | mapper->setValuesRow(-1); | ||
mapper->setLabelsRow(1); | ||||
QCOMPARE(m_series->count(), 0); | ||||
delete mapper; | ||||
mapper = 0; | ||||
} | ||||
|
r1352 | void tst_qpiemodelmapper::seriesUpdated() | ||
|
r1251 | { | ||
|
r1427 | // setup the mapper | ||
createVerticalMapper(); | ||||
|
r1251 | QCOMPARE(m_series->count(), m_modelRowCount); | ||
|
r1499 | QCOMPARE(m_vMapper->rowCount(), -1); | ||
|
r1251 | |||
m_series->append("1000", 1000); | ||||
QCOMPARE(m_series->count(), m_modelRowCount + 1); | ||||
|
r1499 | QCOMPARE(m_vMapper->rowCount(), -1); // the value should not change as it indicates 'all' items there are in the model | ||
|
r1251 | |||
m_series->remove(m_series->slices().last()); | ||||
QCOMPARE(m_series->count(), m_modelRowCount); | ||||
|
r1499 | QCOMPARE(m_vMapper->rowCount(), -1); // the value should not change as it indicates 'all' items there are in the model | ||
|
r1427 | |||
QPieSlice *slice = m_series->slices().first(); | ||||
slice->setValue(25.0); | ||||
slice->setLabel(QString("25.0")); | ||||
QCOMPARE(m_model->data(m_model->index(0, 0)).toReal(), 25.0); | ||||
QCOMPARE(m_model->data(m_model->index(0, 1)).toString(), QString("25.0")); | ||||
} | ||||
void tst_qpiemodelmapper::verticalModelInsertRows() | ||||
{ | ||||
// setup the mapper | ||||
createVerticalMapper(); | ||||
QCOMPARE(m_series->count(), m_modelRowCount); | ||||
QVERIFY(m_vMapper->model() != 0); | ||||
int insertCount = 4; | ||||
m_model->insertRows(3, insertCount); | ||||
QCOMPARE(m_series->count(), m_modelRowCount + insertCount); | ||||
int first = 3; | ||||
|
r1499 | m_vMapper->setFirstRow(3); | ||
|
r1427 | QCOMPARE(m_series->count(), m_modelRowCount + insertCount - first); | ||
m_model->insertRows(3, insertCount); | ||||
QCOMPARE(m_series->count(), m_modelRowCount + 2 * insertCount - first); | ||||
int countLimit = 6; | ||||
|
r1499 | m_vMapper->setRowCount(countLimit); | ||
|
r1427 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelRowCount + 2 * insertCount - first)); | ||
m_model->insertRows(3, insertCount); | ||||
QCOMPARE(m_series->count(), qMin(countLimit, m_modelRowCount + 3 * insertCount - first)); | ||||
|
r1499 | m_vMapper->setFirstRow(0); | ||
|
r1427 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelRowCount + 3 * insertCount)); | ||
|
r1499 | m_vMapper->setRowCount(-1); | ||
|
r1427 | QCOMPARE(m_series->count(), m_modelRowCount + 3 * insertCount); | ||
} | ||||
void tst_qpiemodelmapper::verticalModelRemoveRows() | ||||
{ | ||||
// setup the mapper | ||||
createVerticalMapper(); | ||||
QCOMPARE(m_series->count(), m_modelRowCount); | ||||
QVERIFY(m_vMapper->model() != 0); | ||||
int removeCount = 2; | ||||
m_model->removeRows(1, removeCount); | ||||
QCOMPARE(m_series->count(), m_modelRowCount - removeCount); | ||||
int first = 1; | ||||
|
r1499 | m_vMapper->setFirstRow(first); | ||
|
r1427 | QCOMPARE(m_series->count(), m_modelRowCount - removeCount - first); | ||
m_model->removeRows(1, removeCount); | ||||
QCOMPARE(m_series->count(), m_modelRowCount - 2 * removeCount - first); | ||||
int countLimit = 3; | ||||
|
r1499 | m_vMapper->setRowCount(countLimit); | ||
|
r1427 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelRowCount - 2 * removeCount - first)); | ||
m_model->removeRows(1, removeCount); | ||||
QCOMPARE(m_series->count(), qMin(countLimit, m_modelRowCount - 3 * removeCount - first)); | ||||
|
r1499 | m_vMapper->setFirstRow(0); | ||
|
r1427 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelRowCount - 3 * removeCount)); | ||
|
r1499 | m_vMapper->setRowCount(-1); | ||
|
r1427 | QCOMPARE(m_series->count(), m_modelRowCount - 3 * removeCount); | ||
} | ||||
void tst_qpiemodelmapper::verticalModelInsertColumns() | ||||
{ | ||||
// setup the mapper | ||||
createVerticalMapper(); | ||||
QCOMPARE(m_series->count(), m_modelRowCount); | ||||
QVERIFY(m_vMapper->model() != 0); | ||||
int insertCount = 4; | ||||
m_model->insertColumns(3, insertCount); | ||||
QCOMPARE(m_series->count(), m_modelRowCount); | ||||
} | ||||
void tst_qpiemodelmapper::verticalModelRemoveColumns() | ||||
{ | ||||
// setup the mapper | ||||
createVerticalMapper(); | ||||
QCOMPARE(m_series->count(), m_modelRowCount); | ||||
QVERIFY(m_vMapper->model() != 0); | ||||
int removeCount = m_modelColumnCount - 2; | ||||
m_model->removeColumns(0, removeCount); | ||||
QCOMPARE(m_series->count(), m_modelRowCount); | ||||
// leave only one column | ||||
m_model->removeColumns(0, m_modelColumnCount - removeCount - 1); | ||||
QCOMPARE(m_series->count(), 0); | ||||
} | ||||
void tst_qpiemodelmapper::horizontalModelInsertRows() | ||||
{ | ||||
// setup the mapper | ||||
createHorizontalMapper(); | ||||
QCOMPARE(m_series->count(), m_modelColumnCount); | ||||
QVERIFY(m_hMapper->model() != 0); | ||||
int insertCount = 4; | ||||
m_model->insertRows(3, insertCount); | ||||
QCOMPARE(m_series->count(), m_modelColumnCount); | ||||
} | ||||
void tst_qpiemodelmapper::horizontalModelRemoveRows() | ||||
{ | ||||
// setup the mapper | ||||
createHorizontalMapper(); | ||||
QCOMPARE(m_series->count(), m_modelColumnCount); | ||||
QVERIFY(m_hMapper->model() != 0); | ||||
int removeCount = m_modelRowCount - 2; | ||||
m_model->removeRows(0, removeCount); | ||||
QCOMPARE(m_series->count(), m_modelColumnCount); | ||||
// leave only one column | ||||
m_model->removeRows(0, m_modelRowCount - removeCount - 1); | ||||
QCOMPARE(m_series->count(), 0); | ||||
} | ||||
void tst_qpiemodelmapper::horizontalModelInsertColumns() | ||||
{ | ||||
// setup the mapper | ||||
createHorizontalMapper(); | ||||
QCOMPARE(m_series->count(), m_modelColumnCount); | ||||
QVERIFY(m_hMapper->model() != 0); | ||||
int insertCount = 4; | ||||
m_model->insertColumns(3, insertCount); | ||||
QCOMPARE(m_series->count(), m_modelColumnCount + insertCount); | ||||
int first = 3; | ||||
|
r1499 | m_hMapper->setFirstColumn(3); | ||
|
r1427 | QCOMPARE(m_series->count(), m_modelColumnCount + insertCount - first); | ||
m_model->insertColumns(3, insertCount); | ||||
QCOMPARE(m_series->count(), m_modelColumnCount + 2 * insertCount - first); | ||||
int countLimit = 6; | ||||
|
r1499 | m_hMapper->setColumnCount(countLimit); | ||
|
r1427 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelColumnCount + 2 * insertCount - first)); | ||
m_model->insertColumns(3, insertCount); | ||||
QCOMPARE(m_series->count(), qMin(countLimit, m_modelColumnCount + 3 * insertCount - first)); | ||||
|
r1499 | m_hMapper->setFirstColumn(0); | ||
|
r1427 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelColumnCount + 3 * insertCount)); | ||
|
r1499 | m_hMapper->setColumnCount(-1); | ||
|
r1427 | QCOMPARE(m_series->count(), m_modelColumnCount + 3 * insertCount); | ||
} | ||||
void tst_qpiemodelmapper::horizontalModelRemoveColumns() | ||||
{ | ||||
// setup the mapper | ||||
createHorizontalMapper(); | ||||
QCOMPARE(m_series->count(), m_modelColumnCount); | ||||
QVERIFY(m_hMapper->model() != 0); | ||||
int removeCount = 2; | ||||
m_model->removeColumns(1, removeCount); | ||||
QCOMPARE(m_series->count(), m_modelColumnCount - removeCount); | ||||
int first = 1; | ||||
|
r1499 | m_hMapper->setFirstColumn(first); | ||
|
r1427 | QCOMPARE(m_series->count(), m_modelColumnCount - removeCount - first); | ||
m_model->removeColumns(1, removeCount); | ||||
QCOMPARE(m_series->count(), m_modelColumnCount - 2 * removeCount - first); | ||||
int countLimit = 3; | ||||
|
r1499 | m_hMapper->setColumnCount(countLimit); | ||
|
r1427 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelColumnCount - 2 * removeCount - first)); | ||
m_model->removeColumns(1, removeCount); | ||||
QCOMPARE(m_series->count(), qMin(countLimit, m_modelColumnCount - 3 * removeCount - first)); | ||||
|
r1499 | m_hMapper->setFirstColumn(0); | ||
|
r1427 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelColumnCount - 3 * removeCount)); | ||
|
r1499 | m_hMapper->setColumnCount(-1); | ||
|
r1427 | QCOMPARE(m_series->count(), m_modelColumnCount - 3 * removeCount); | ||
} | ||||
void tst_qpiemodelmapper::modelUpdateCell() | ||||
{ | ||||
// setup the mapper | ||||
createVerticalMapper(); | ||||
|
r1251 | |||
|
r1427 | QVERIFY(m_model->setData(m_model->index(1, 0), 44)); | ||
QCOMPARE(m_series->slices().at(1)->value(), 44.0); | ||||
QCOMPARE(m_model->data(m_model->index(1, 0)).toReal(), 44.0); | ||||
|
r1251 | } | ||
|
r1924 | void tst_qpiemodelmapper::verticalMapperSignals() | ||
{ | ||||
QVPieModelMapper *mapper = new QVPieModelMapper; | ||||
QSignalSpy spy0(mapper, SIGNAL(firstRowChanged())); | ||||
QSignalSpy spy1(mapper, SIGNAL(rowCountChanged())); | ||||
QSignalSpy spy2(mapper, SIGNAL(valuesColumnChanged())); | ||||
QSignalSpy spy3(mapper, SIGNAL(labelsColumnChanged())); | ||||
QSignalSpy spy4(mapper, SIGNAL(modelReplaced())); | ||||
QSignalSpy spy5(mapper, SIGNAL(seriesReplaced())); | ||||
mapper->setValuesColumn(0); | ||||
mapper->setLabelsColumn(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); | ||||
|
r2733 | delete mapper; | ||
|
r1924 | } | ||
void tst_qpiemodelmapper::horizontalMapperSignals() | ||||
{ | ||||
QHPieModelMapper *mapper = new QHPieModelMapper; | ||||
QSignalSpy spy0(mapper, SIGNAL(firstColumnChanged())); | ||||
QSignalSpy spy1(mapper, SIGNAL(columnCountChanged())); | ||||
QSignalSpy spy2(mapper, SIGNAL(valuesRowChanged())); | ||||
QSignalSpy spy3(mapper, SIGNAL(labelsRowChanged())); | ||||
QSignalSpy spy4(mapper, SIGNAL(modelReplaced())); | ||||
QSignalSpy spy5(mapper, SIGNAL(seriesReplaced())); | ||||
mapper->setValuesRow(0); | ||||
mapper->setLabelsRow(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); | ||||
} | ||||
|
r1352 | QTEST_MAIN(tst_qpiemodelmapper) | ||
|
r1239 | |||
#include "tst_qpiemodelmapper.moc" | ||||