tst_qlineseries.cpp
636 lines
| 16.1 KiB
| text/x-c
|
CppLexer
Michal Klocek
|
r1064 | /**************************************************************************** | ||
** | ||||
** Copyright (C) 2012 Digia Plc | ||||
** All rights reserved. | ||||
** For any questions to Digia, please use contact form at http://qt.digia.com | ||||
** | ||||
** This file is part of the Qt Commercial Charts Add-on. | ||||
** | ||||
** $QT_BEGIN_LICENSE$ | ||||
** Licensees holding valid Qt Commercial licenses may use this file in | ||||
** accordance with the Qt Commercial License Agreement provided with the | ||||
** 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$ | ||||
** | ||||
****************************************************************************/ | ||||
Michal Klocek
|
r1058 | #include <QtTest/QtTest> | ||
#include <qlineseries.h> | ||||
Michal Klocek
|
r1064 | #include <qchartview.h> | ||
Marek Rosa
|
r1071 | #include <QStandardItemModel> | ||
Michal Klocek
|
r1064 | |||
Q_DECLARE_METATYPE(QList<QPointF>) | ||||
Michal Klocek
|
r1058 | |||
QTCOMMERCIALCHART_USE_NAMESPACE | ||||
class tst_QLineSeries : public QObject | ||||
{ | ||||
Q_OBJECT | ||||
Marek Rosa
|
r1072 | public slots: | ||
Michal Klocek
|
r1058 | void initTestCase(); | ||
void cleanupTestCase(); | ||||
void init(); | ||||
void cleanup(); | ||||
Marek Rosa
|
r1072 | private slots: | ||
Michal Klocek
|
r1064 | void qlineseries_data(); | ||
void qlineseries(); | ||||
Michal Klocek
|
r1070 | void append_raw_data(); | ||
void append_raw(); | ||||
void append_chart_data(); | ||||
void append_chart(); | ||||
void append_chart_animation_data(); | ||||
void append_chart_animation(); | ||||
void chart_append_data(); | ||||
void chart_append(); | ||||
void count_raw_data(); | ||||
void count_raw(); | ||||
Michal Klocek
|
r1058 | void oper_data(); | ||
void oper(); | ||||
void pen_data(); | ||||
void pen(); | ||||
Michal Klocek
|
r1070 | void pointsVisible_raw_data(); | ||
void pointsVisible_raw(); | ||||
void remove_raw_data(); | ||||
void remove_raw(); | ||||
void remove_chart_data(); | ||||
void remove_chart(); | ||||
void remove_chart_animation_data(); | ||||
void remove_chart_animation(); | ||||
Michal Klocek
|
r1099 | void removeAll_raw_data(); | ||
void removeAll_raw(); | ||||
void removeAll_chart_data(); | ||||
void removeAll_chart(); | ||||
void removeAll_chart_animation_data(); | ||||
void removeAll_chart_animation(); | ||||
void replace_raw_data(); | ||||
void replace_raw(); | ||||
void replace_chart_data(); | ||||
void replace_chart(); | ||||
void replace_chart_animation_data(); | ||||
void replace_chart_animation(); | ||||
Michal Klocek
|
r1058 | void setModel_data(); | ||
void setModel(); | ||||
void setModelMapping_data(); | ||||
void setModelMapping(); | ||||
Marek Rosa
|
r1077 | void setModelMappingRange_data(); | ||
void setModelMappingRange(); | ||||
Marek Rosa
|
r1081 | void modelUpdated(); | ||
void modelUpdatedCustomMapping(); | ||||
Marek Rosa
|
r1072 | private: | ||
Michal Klocek
|
r1070 | void append_data(); | ||
void count_data(); | ||||
void pointsVisible_data(); | ||||
Michal Klocek
|
r1058 | |||
Marek Rosa
|
r1072 | private: | ||
Michal Klocek
|
r1064 | QChartView* m_view; | ||
QChart* m_chart; | ||||
Michal Klocek
|
r1070 | QLineSeries* m_series; | ||
Michal Klocek
|
r1058 | }; | ||
void tst_QLineSeries::initTestCase() | ||||
{ | ||||
} | ||||
void tst_QLineSeries::cleanupTestCase() | ||||
{ | ||||
} | ||||
void tst_QLineSeries::init() | ||||
{ | ||||
Marek Rosa
|
r1072 | m_view = new QChartView(new QChart()); | ||
m_chart = m_view->chart(); | ||||
m_series = new QLineSeries(); | ||||
Michal Klocek
|
r1058 | } | ||
void tst_QLineSeries::cleanup() | ||||
{ | ||||
Michal Klocek
|
r1070 | delete m_series; | ||
Michal Klocek
|
r1064 | delete m_view; | ||
m_view = 0; | ||||
m_chart = 0; | ||||
Michal Klocek
|
r1070 | m_series = 0; | ||
Michal Klocek
|
r1058 | } | ||
Michal Klocek
|
r1064 | void tst_QLineSeries::qlineseries_data() | ||
Michal Klocek
|
r1058 | { | ||
Michal Klocek
|
r1070 | |||
Michal Klocek
|
r1058 | } | ||
Michal Klocek
|
r1064 | void tst_QLineSeries::qlineseries() | ||
Michal Klocek
|
r1058 | { | ||
Michal Klocek
|
r1064 | QLineSeries series; | ||
QCOMPARE(series.count(),0); | ||||
QCOMPARE(series.brush(), QBrush()); | ||||
QCOMPARE(series.points(), QList<QPointF>()); | ||||
QCOMPARE(series.pen(), QPen()); | ||||
Michal Klocek
|
r1058 | QCOMPARE(series.pointsVisible(), false); | ||
Michal Klocek
|
r1064 | |||
series.append(QList<QPointF>()); | ||||
series.append(0.0,0.0); | ||||
series.append(QPointF()); | ||||
series.remove(0.0,0.0); | ||||
Michal Klocek
|
r1058 | series.remove(QPointF()); | ||
series.removeAll(); | ||||
Michal Klocek
|
r1064 | |||
series.replace(QPointF(),QPointF()); | ||||
series.replace(0,0,0,0); | ||||
Michal Klocek
|
r1058 | series.setBrush(QBrush()); | ||
Michal Klocek
|
r1064 | |||
Michal Klocek
|
r1058 | QCOMPARE(series.setModel((QAbstractItemModel*)0), false); | ||
Michal Klocek
|
r1064 | |||
series.setModelMapping(-1, -1, Qt::Orientation(0)); | ||||
Michal Klocek
|
r1058 | series.setPen(QPen()); | ||
series.setPointsVisible(false); | ||||
Michal Klocek
|
r1070 | |||
m_chart->addSeries(&series); | ||||
m_view->show(); | ||||
QTest::qWaitForWindowShown(m_view); | ||||
Michal Klocek
|
r1058 | } | ||
void tst_QLineSeries::append_data() | ||||
{ | ||||
Michal Klocek
|
r1070 | QTest::addColumn< QList<QPointF> >("points"); | ||
QTest::newRow("0,0 1,1 2,2 3,3") << (QList<QPointF>() << QPointF(0,0) << QPointF(1,1) << QPointF(2,2) << QPointF(3,3)); | ||||
QTest::newRow("0,0 -1,-1 -2,-2 -3,-3") << (QList<QPointF>() << QPointF(0,0) << QPointF(-1,-1) << QPointF(-2,-2) << QPointF(-3,-3)); | ||||
Michal Klocek
|
r1058 | } | ||
Michal Klocek
|
r1070 | void tst_QLineSeries::append_raw_data() | ||
{ | ||||
append_data(); | ||||
} | ||||
Michal Klocek
|
r1058 | |||
Michal Klocek
|
r1070 | void tst_QLineSeries::append_raw() | ||
{ | ||||
QFETCH(QList<QPointF>, points); | ||||
QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); | ||||
QTest::qWait(200); | ||||
m_series->append(points); | ||||
QTest::qWait(200); | ||||
Michal Klocek
|
r1058 | QCOMPARE(spy0.count(), 0); | ||
Michal Klocek
|
r1070 | QCOMPARE(m_series->points(), points); | ||
Michal Klocek
|
r1058 | } | ||
Michal Klocek
|
r1070 | void tst_QLineSeries::chart_append_data() | ||
Michal Klocek
|
r1058 | { | ||
Michal Klocek
|
r1070 | append_data(); | ||
Michal Klocek
|
r1058 | } | ||
Michal Klocek
|
r1070 | void tst_QLineSeries::chart_append() | ||
Michal Klocek
|
r1058 | { | ||
Michal Klocek
|
r1070 | append_raw(); | ||
m_chart->addSeries(m_series); | ||||
m_view->show(); | ||||
QTest::qWaitForWindowShown(m_view); | ||||
} | ||||
Michal Klocek
|
r1058 | |||
Michal Klocek
|
r1070 | void tst_QLineSeries::append_chart_data() | ||
{ | ||||
append_data(); | ||||
} | ||||
Michal Klocek
|
r1058 | |||
Michal Klocek
|
r1070 | void tst_QLineSeries::append_chart() | ||
{ | ||||
m_view->show(); | ||||
m_chart->addSeries(m_series); | ||||
QTest::qWaitForWindowShown(m_view); | ||||
Michal Klocek
|
r1099 | append_raw(); | ||
Michal Klocek
|
r1070 | } | ||
Michal Klocek
|
r1058 | |||
Michal Klocek
|
r1070 | void tst_QLineSeries::append_chart_animation_data() | ||
{ | ||||
append_data(); | ||||
} | ||||
Michal Klocek
|
r1058 | |||
Michal Klocek
|
r1070 | void tst_QLineSeries::append_chart_animation() | ||
{ | ||||
m_chart->setAnimationOptions(QChart::AllAnimations); | ||||
append_chart(); | ||||
Michal Klocek
|
r1058 | } | ||
void tst_QLineSeries::count_data() | ||||
{ | ||||
QTest::addColumn<int>("count"); | ||||
QTest::newRow("0") << 0; | ||||
Michal Klocek
|
r1070 | QTest::newRow("5") << 5; | ||
QTest::newRow("10") << 5; | ||||
Michal Klocek
|
r1058 | } | ||
Michal Klocek
|
r1070 | void tst_QLineSeries::count_raw_data() | ||
Michal Klocek
|
r1058 | { | ||
Michal Klocek
|
r1070 | count_data(); | ||
Michal Klocek
|
r1058 | } | ||
Michal Klocek
|
r1070 | void tst_QLineSeries::count_raw() | ||
Michal Klocek
|
r1058 | { | ||
Michal Klocek
|
r1070 | QFETCH(int, count); | ||
Michal Klocek
|
r1058 | |||
Michal Klocek
|
r1070 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); | ||
Michal Klocek
|
r1058 | |||
Michal Klocek
|
r1070 | for(int i=0 ; i< count; ++i) | ||
m_series->append(i,i); | ||||
Michal Klocek
|
r1058 | |||
QCOMPARE(spy0.count(), 0); | ||||
Michal Klocek
|
r1070 | QCOMPARE(m_series->count(), count); | ||
Michal Klocek
|
r1058 | } | ||
void tst_QLineSeries::oper_data() | ||||
{ | ||||
Michal Klocek
|
r1070 | append_data(); | ||
Michal Klocek
|
r1058 | } | ||
void tst_QLineSeries::oper() | ||||
{ | ||||
QFETCH(QList<QPointF>, points); | ||||
Michal Klocek
|
r1070 | QLineSeries series; | ||
Michal Klocek
|
r1058 | |||
QSignalSpy spy0(&series, SIGNAL(clicked(QPointF const&))); | ||||
Michal Klocek
|
r1070 | foreach(const QPointF& point,points) | ||
{ | ||||
series<<point; | ||||
} | ||||
Michal Klocek
|
r1058 | |||
Michal Klocek
|
r1070 | QCOMPARE(series.points(), points); | ||
Michal Klocek
|
r1058 | QCOMPARE(spy0.count(), 0); | ||
} | ||||
Michal Klocek
|
r1070 | |||
Michal Klocek
|
r1058 | void tst_QLineSeries::pen_data() | ||
{ | ||||
QTest::addColumn<QPen>("pen"); | ||||
QTest::newRow("null") << QPen(); | ||||
Michal Klocek
|
r1070 | QTest::newRow("blue") << QPen(Qt::blue); | ||
QTest::newRow("black") << QPen(Qt::black); | ||||
QTest::newRow("red") << QPen(Qt::red); | ||||
Michal Klocek
|
r1058 | } | ||
void tst_QLineSeries::pen() | ||||
{ | ||||
QFETCH(QPen, pen); | ||||
Michal Klocek
|
r1070 | QLineSeries series; | ||
Michal Klocek
|
r1058 | |||
QSignalSpy spy0(&series, SIGNAL(clicked(QPointF const&))); | ||||
Michal Klocek
|
r1070 | series.setPen(pen); | ||
Michal Klocek
|
r1058 | |||
Michal Klocek
|
r1070 | QCOMPARE(spy0.count(), 0); | ||
Michal Klocek
|
r1058 | QCOMPARE(series.pen(), pen); | ||
Michal Klocek
|
r1070 | m_chart->addSeries(&series); | ||
if(pen!=QPen()) QCOMPARE(series.pen(), pen); | ||||
Michal Klocek
|
r1110 | |||
m_chart->setTheme(QChart::ChartThemeDark); | ||||
if(pen!=QPen()) QCOMPARE(series.pen(), pen); | ||||
Michal Klocek
|
r1058 | } | ||
void tst_QLineSeries::pointsVisible_data() | ||||
{ | ||||
QTest::addColumn<bool>("pointsVisible"); | ||||
QTest::newRow("true") << true; | ||||
QTest::newRow("false") << false; | ||||
} | ||||
Michal Klocek
|
r1070 | void tst_QLineSeries::pointsVisible_raw_data() | ||
{ | ||||
pointsVisible_data(); | ||||
} | ||||
void tst_QLineSeries::pointsVisible_raw() | ||||
Michal Klocek
|
r1058 | { | ||
QFETCH(bool, pointsVisible); | ||||
Michal Klocek
|
r1070 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); | ||
m_series->setPointsVisible(pointsVisible); | ||||
QCOMPARE(spy0.count(), 0); | ||||
QCOMPARE(m_series->pointsVisible(), pointsVisible); | ||||
} | ||||
Michal Klocek
|
r1058 | |||
Michal Klocek
|
r1070 | void tst_QLineSeries::remove_raw_data() | ||
{ | ||||
append_data(); | ||||
} | ||||
Michal Klocek
|
r1058 | |||
Michal Klocek
|
r1070 | void tst_QLineSeries::remove_raw() | ||
{ | ||||
QFETCH(QList<QPointF>, points); | ||||
QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); | ||||
m_series->append(points); | ||||
QTest::qWait(200); | ||||
QCOMPARE(spy0.count(), 0); | ||||
QCOMPARE(m_series->points(), points); | ||||
Michal Klocek
|
r1058 | |||
Michal Klocek
|
r1070 | foreach(const QPointF& point,points) | ||
{ | ||||
m_series->remove(point); | ||||
QTest::qWait(200); | ||||
} | ||||
Michal Klocek
|
r1058 | |||
QCOMPARE(spy0.count(), 0); | ||||
Michal Klocek
|
r1070 | QCOMPARE(m_series->points().count(), 0); | ||
Michal Klocek
|
r1058 | } | ||
Michal Klocek
|
r1070 | void tst_QLineSeries::remove_chart_data() | ||
Michal Klocek
|
r1058 | { | ||
Michal Klocek
|
r1070 | append_data(); | ||
Michal Klocek
|
r1058 | } | ||
Michal Klocek
|
r1070 | void tst_QLineSeries::remove_chart() | ||
Michal Klocek
|
r1058 | { | ||
Michal Klocek
|
r1070 | m_view->show(); | ||
m_chart->addSeries(m_series); | ||||
QTest::qWaitForWindowShown(m_view); | ||||
Michal Klocek
|
r1099 | remove_raw(); | ||
Michal Klocek
|
r1070 | } | ||
Michal Klocek
|
r1058 | |||
Michal Klocek
|
r1070 | void tst_QLineSeries::remove_chart_animation_data() | ||
{ | ||||
append_data(); | ||||
} | ||||
Michal Klocek
|
r1058 | |||
Michal Klocek
|
r1070 | void tst_QLineSeries::remove_chart_animation() | ||
{ | ||||
m_chart->setAnimationOptions(QChart::AllAnimations); | ||||
remove_chart(); | ||||
Michal Klocek
|
r1058 | } | ||
Michal Klocek
|
r1070 | |||
Michal Klocek
|
r1099 | void tst_QLineSeries::removeAll_raw_data() | ||
Michal Klocek
|
r1058 | { | ||
Michal Klocek
|
r1070 | append_data(); | ||
Michal Klocek
|
r1058 | } | ||
Michal Klocek
|
r1099 | void tst_QLineSeries::removeAll_raw() | ||
Michal Klocek
|
r1058 | { | ||
Michal Klocek
|
r1099 | QFETCH(QList<QPointF>, points); | ||
QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); | ||||
m_series->append(points); | ||||
QCOMPARE(spy0.count(), 0); | ||||
QCOMPARE(m_series->points(), points); | ||||
QTest::qWait(200); | ||||
m_series->removeAll(); | ||||
QTest::qWait(200); | ||||
QCOMPARE(spy0.count(), 0); | ||||
QCOMPARE(m_series->points().count(), 0); | ||||
} | ||||
Michal Klocek
|
r1058 | |||
Michal Klocek
|
r1099 | void tst_QLineSeries::removeAll_chart_data() | ||
{ | ||||
append_data(); | ||||
} | ||||
Michal Klocek
|
r1058 | |||
Michal Klocek
|
r1099 | void tst_QLineSeries::removeAll_chart() | ||
{ | ||||
m_view->show(); | ||||
m_chart->addSeries(m_series); | ||||
QTest::qWaitForWindowShown(m_view); | ||||
removeAll_raw(); | ||||
} | ||||
Michal Klocek
|
r1058 | |||
Michal Klocek
|
r1099 | void tst_QLineSeries::removeAll_chart_animation_data() | ||
{ | ||||
append_data(); | ||||
} | ||||
Michal Klocek
|
r1058 | |||
Michal Klocek
|
r1099 | void tst_QLineSeries::removeAll_chart_animation() | ||
{ | ||||
m_chart->setAnimationOptions(QChart::AllAnimations); | ||||
removeAll_chart(); | ||||
Michal Klocek
|
r1058 | } | ||
Michal Klocek
|
r1099 | void tst_QLineSeries::replace_raw_data() | ||
Michal Klocek
|
r1058 | { | ||
Michal Klocek
|
r1099 | append_data(); | ||
Michal Klocek
|
r1058 | } | ||
Michal Klocek
|
r1099 | void tst_QLineSeries::replace_raw() | ||
Michal Klocek
|
r1058 | { | ||
Michal Klocek
|
r1099 | QFETCH(QList<QPointF>, points); | ||
QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); | ||||
m_series->append(points); | ||||
QCOMPARE(spy0.count(), 0); | ||||
QCOMPARE(m_series->points(), points); | ||||
QTest::qWait(200); | ||||
foreach(const QPointF& point,points) | ||||
{ | ||||
m_series->replace(point.x(),point.y(),point.x(),0); | ||||
QTest::qWait(200); | ||||
} | ||||
Michal Klocek
|
r1058 | |||
Michal Klocek
|
r1099 | QList<QPointF> newPoints = m_series->points(); | ||
Michal Klocek
|
r1058 | |||
Michal Klocek
|
r1099 | QCOMPARE(newPoints.count(), points.count()); | ||
for(int i =0 ; i<points.count() ; ++i) { | ||||
QCOMPARE(points[i].x(), newPoints[i].x()); | ||||
QCOMPARE(newPoints[i].y(), 0.0); | ||||
} | ||||
} | ||||
Michal Klocek
|
r1058 | |||
Michal Klocek
|
r1099 | void tst_QLineSeries::replace_chart_data() | ||
{ | ||||
append_data(); | ||||
} | ||||
void tst_QLineSeries::replace_chart() | ||||
{ | ||||
m_view->show(); | ||||
m_chart->addSeries(m_series); | ||||
QTest::qWaitForWindowShown(m_view); | ||||
replace_raw(); | ||||
} | ||||
void tst_QLineSeries::replace_chart_animation_data() | ||||
{ | ||||
append_data(); | ||||
} | ||||
void tst_QLineSeries::replace_chart_animation() | ||||
{ | ||||
m_chart->setAnimationOptions(QChart::AllAnimations); | ||||
replace_chart(); | ||||
Michal Klocek
|
r1058 | } | ||
void tst_QLineSeries::setModel_data() | ||||
{ | ||||
Marek Rosa
|
r1072 | |||
Michal Klocek
|
r1058 | } | ||
void tst_QLineSeries::setModel() | ||||
{ | ||||
Marek Rosa
|
r1077 | QLineSeries series; | ||
series.setModel(0); | ||||
QVERIFY2(series.model() == 0, "Model should be unset"); | ||||
Michal Klocek
|
r1058 | |||
Marek Rosa
|
r1077 | QStandardItemModel *stdModel = new QStandardItemModel(); | ||
series.setModel(stdModel); | ||||
QVERIFY2((series.model()) == stdModel, "Model should be stdModel"); | ||||
Michal Klocek
|
r1058 | |||
Marek Rosa
|
r1077 | // unset the model | ||
series.setModel(0); | ||||
QVERIFY2(series.model() == 0, "Model should be unset"); | ||||
Michal Klocek
|
r1058 | |||
} | ||||
Q_DECLARE_METATYPE(Qt::Orientation) | ||||
void tst_QLineSeries::setModelMapping_data() | ||||
{ | ||||
QTest::addColumn<int>("modelX"); | ||||
QTest::addColumn<int>("modelY"); | ||||
QTest::addColumn<Qt::Orientation>("orientation"); | ||||
Marek Rosa
|
r1071 | QTest::newRow("different x and y, vertical") << 0 << 1 << Qt::Vertical; | ||
QTest::newRow("same x and y, vertical") << 0 << 0 << Qt::Vertical; | ||||
QTest::newRow("invalid x, corrent y, vertical") << -1 << 1 << Qt::Vertical; | ||||
QTest::newRow("different x and y, horizontal") << 0 << 1 << Qt::Horizontal; | ||||
QTest::newRow("same x and y, horizontal") << 0 << 0 << Qt::Horizontal; | ||||
QTest::newRow("invalid x, corrent y, horizontal") << -1 << 1 << Qt::Horizontal; | ||||
Michal Klocek
|
r1058 | } | ||
void tst_QLineSeries::setModelMapping() | ||||
{ | ||||
QFETCH(int, modelX); | ||||
QFETCH(int, modelY); | ||||
QFETCH(Qt::Orientation, orientation); | ||||
Marek Rosa
|
r1071 | QLineSeries series; | ||
Michal Klocek
|
r1058 | |||
Marek Rosa
|
r1071 | // model has not been set so setting mapping should do nothing | ||
Michal Klocek
|
r1058 | series.setModelMapping(modelX, modelY, orientation); | ||
Marek Rosa
|
r1071 | QCOMPARE(series.mapX(), -1); | ||
QCOMPARE(series.mapY(), -1); | ||||
QVERIFY2(series.mapOrientation() == Qt::Vertical, "The orientation by default should be Qt::Vertical"); | ||||
Michal Klocek
|
r1058 | |||
Marek Rosa
|
r1071 | // now let us set the model | ||
series.setModel(new QStandardItemModel()); | ||||
series.setModelMapping(modelX, modelY, orientation); | ||||
QCOMPARE(series.mapX(), modelX); | ||||
QCOMPARE(series.mapY(), modelY); | ||||
QVERIFY2(series.mapOrientation() == orientation, "not good"); | ||||
// now let us remove the model, the values should go back to default ones. | ||||
series.setModel(0); | ||||
QCOMPARE(series.mapX(), -1); | ||||
QCOMPARE(series.mapY(), -1); | ||||
QVERIFY2(series.mapOrientation() == Qt::Vertical, "The orientation by default should be Qt::Vertical"); | ||||
Michal Klocek
|
r1058 | } | ||
Marek Rosa
|
r1077 | void tst_QLineSeries::setModelMappingRange_data() | ||
{ | ||||
QTest::addColumn<int>("first"); | ||||
QTest::addColumn<int>("count"); | ||||
QTest::newRow("first: 0, count: unlimited") << 0 << -1; | ||||
QTest::newRow("first: 0, count: 5") << 0 << 5; | ||||
QTest::newRow("first: 3, count: unlimited") << 3 << -1; | ||||
QTest::newRow("first: 3, count: 5") << 3 << 5; | ||||
QTest::newRow("first: -3, count: 5") << -3 << 5; | ||||
QTest::newRow("first: 3, count: -5") << 3 << -5; | ||||
QTest::newRow("first: -3, count: -5") << 3 << -5; | ||||
QTest::newRow("first: -3, count: 0") << -3 << 0; | ||||
QTest::newRow("first: 0, count: -5") << 0 << -5; | ||||
QTest::newRow("first: 0, count: 0") << 0 << 0; | ||||
} | ||||
void tst_QLineSeries::setModelMappingRange() | ||||
{ | ||||
QFETCH(int, first); | ||||
QFETCH(int, count); | ||||
QLineSeries series; | ||||
Marek Rosa
|
r1081 | QStandardItemModel *model = new QStandardItemModel(0, 2); | ||
Marek Rosa
|
r1077 | series.setModel(model); | ||
series.setModelMapping(0, 1); | ||||
series.setModelMappingRange(first, count); | ||||
QCOMPARE(series.mapFirst(), qMax(first, 0)); // regardles of what value was used to set the range, first should not be less than 0 | ||||
QCOMPARE(series.mapCount(), qMax(count, -1)); // regardles of what value was used to set the range, first should not be less than 0 | ||||
QVERIFY2(series.count() == 0, "No rows in the model, count should be 0"); | ||||
for (int row = 0; row < 3; ++row) { | ||||
Marek Rosa
|
r1081 | for (int column = 0; column < 2; column++) { | ||
Marek Rosa
|
r1077 | QStandardItem *item = new QStandardItem(row * column); | ||
model->setItem(row, column, item); | ||||
} | ||||
} | ||||
if (qMax(count, -1) != -1) | ||||
QVERIFY2(series.count() == qMin(model->rowCount() - qMax(first, 0), qMax(count, -1)), "Count should be the number of items in a model after first item, but not more than count and not less than 0"); | ||||
else | ||||
QVERIFY2(series.count() == model->rowCount() - qMax(first, 0), "Count should be the number of items in a model after first item, but not less then 0"); | ||||
// let's add few more rows to the model | ||||
for (int row = 0; row < 10; ++row) { | ||||
QList<QStandardItem *> newRow; | ||||
Marek Rosa
|
r1081 | for (int column = 0; column < 2; column++) { | ||
Marek Rosa
|
r1077 | newRow.append(new QStandardItem(row * column)); | ||
} | ||||
model->appendRow(newRow); | ||||
} | ||||
if (qMax(count, -1) != -1) | ||||
QVERIFY2(series.count() == qMin(model->rowCount() - qMax(first, 0), qMax(count, -1)), "Count should be the number of items in a model after first item, but not more than count, but not more than count and not less than 0"); | ||||
else | ||||
QVERIFY2(series.count() == model->rowCount() - qMax(first, 0), "Count should be the number of items in a model after first item, but not less then 0"); | ||||
Marek Rosa
|
r1081 | // unset the model, values should be default | ||
series.setModel(0); | ||||
QCOMPARE(series.mapFirst(), 0); | ||||
QCOMPARE(series.mapCount(), -1); | ||||
QVERIFY2(series.count() == 0, "No rows in the model, count should be 0"); | ||||
} | ||||
void tst_QLineSeries::modelUpdated() | ||||
{ | ||||
QStandardItemModel *model = new QStandardItemModel; | ||||
for (int row = 0; row < 10; ++row) { | ||||
QList<QStandardItem *> newRow; | ||||
for (int column = 0; column < 2; column++) { | ||||
newRow.append(new QStandardItem(row * column)); | ||||
} | ||||
model->appendRow(newRow); | ||||
} | ||||
QLineSeries series; | ||||
series.setModel(model); | ||||
series.setModelMapping(0, 1); | ||||
Marek Rosa
|
r1077 | |||
Marek Rosa
|
r1081 | model->setData(model->index(3, 1), 34); | ||
// check that the update data is correctly taken from the model | ||||
QVERIFY(qFuzzyCompare(series.points().at(3).y(), 34)); | ||||
} | ||||
void tst_QLineSeries::modelUpdatedCustomMapping() | ||||
{ | ||||
QStandardItemModel *model = new QStandardItemModel; | ||||
for (int row = 0; row < 10; ++row) { | ||||
QList<QStandardItem *> newRow; | ||||
for (int column = 0; column < 2; column++) { | ||||
newRow.append(new QStandardItem(row * column)); | ||||
} | ||||
model->appendRow(newRow); | ||||
} | ||||
QLineSeries series; | ||||
series.setModel(model); | ||||
series.setModelMapping(0, 1); | ||||
series.setModelMappingRange(3, 4); | ||||
Marek Rosa
|
r1077 | |||
Marek Rosa
|
r1081 | model->setData(model->index(3, 1), 34); | ||
QVERIFY(qFuzzyCompare(series.points().at(0).y(), 34)); | ||||
Marek Rosa
|
r1077 | } | ||
Michal Klocek
|
r1058 | QTEST_MAIN(tst_QLineSeries) | ||
#include "tst_qlineseries.moc" | ||||