diff --git a/src/xychart/qxyseries.cpp b/src/xychart/qxyseries.cpp index 9aebd72..fb96959 100644 --- a/src/xychart/qxyseries.cpp +++ b/src/xychart/qxyseries.cpp @@ -393,6 +393,15 @@ void QXYSeriesPrivate::scaleDomain(Domain& domain) Q_Q(QXYSeries); const QList& points = q->points(); + + if(points.isEmpty()){ + minX=0.0; + minY=0.0; + maxX=1.0; + maxY=1.0; + } + + for (int i = 0; i < points.count(); i++) { qreal x = points[i].x(); diff --git a/test/auto/qlineseries/tst_qlineseries.cpp b/test/auto/qlineseries/tst_qlineseries.cpp index 67e580f..ad320af 100644 --- a/test/auto/qlineseries/tst_qlineseries.cpp +++ b/test/auto/qlineseries/tst_qlineseries.cpp @@ -39,55 +39,49 @@ public slots: private slots: void qlineseries_data(); void qlineseries(); - - void append_data(); - void append(); - void brush_data(); - void brush(); - void count_data(); - void count(); - void data_data(); - void data(); + 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(); void oper_data(); void oper(); void pen_data(); void pen(); - void pointsVisible_data(); - void pointsVisible(); - void remove_data(); - void remove(); + 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(); void removeAll_data(); void removeAll(); void replace_data(); void replace(); - void setBrush_data(); - void setBrush(); void setModel_data(); void setModel(); void setModelMapping_data(); void setModelMapping(); - void setPen_data(); - void setPen(); - void setPointsVisible_data(); - void setPointsVisible(); - void x_data(); - void x(); - void y_data(); - void y(); - void clicked_data(); - void clicked(); - void selected_data(); - void selected(); +private: + void append_data(); + void count_data(); + void pointsVisible_data(); private: QChartView* m_view; QChart* m_chart; + QLineSeries* m_series; }; void tst_QLineSeries::initTestCase() { - m_view = new QChartView(new QChart()); - m_chart = m_view->chart(); } void tst_QLineSeries::cleanupTestCase() @@ -96,17 +90,23 @@ void tst_QLineSeries::cleanupTestCase() void tst_QLineSeries::init() { + m_view = new QChartView(new QChart()); + m_chart = m_view->chart(); + m_series = new QLineSeries(); } void tst_QLineSeries::cleanup() { + delete m_series; delete m_view; m_view = 0; m_chart = 0; + m_series = 0; } void tst_QLineSeries::qlineseries_data() { + } void tst_QLineSeries::qlineseries() @@ -137,171 +137,144 @@ void tst_QLineSeries::qlineseries() series.setPen(QPen()); series.setPointsVisible(false); + + m_chart->addSeries(&series); + m_view->show(); + QTest::qWaitForWindowShown(m_view); } void tst_QLineSeries::append_data() { -#if 0 - QTest::addColumn>("points"); - QTest::newRow("null") << QList(); -#endif + QTest::addColumn< QList >("points"); + QTest::newRow("0,0 1,1 2,2 3,3") << (QList() << QPointF(0,0) << QPointF(1,1) << QPointF(2,2) << QPointF(3,3)); + QTest::newRow("0,0 -1,-1 -2,-2 -3,-3") << (QList() << QPointF(0,0) << QPointF(-1,-1) << QPointF(-2,-2) << QPointF(-3,-3)); } -// public void append(QList const points) -void tst_QLineSeries::append() -{ -#if 0 - QFETCH(QList, points); - - SubQXYSeries series; - - QSignalSpy spy0(&series, SIGNAL(clicked(QPointF const&))); - QSignalSpy spy1(&series, SIGNAL(selected())); - series.append(points); +void tst_QLineSeries::append_raw_data() +{ + append_data(); +} +void tst_QLineSeries::append_raw() +{ + QFETCH(QList, points); + QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); + QTest::qWait(200); + m_series->append(points); + QTest::qWait(200); QCOMPARE(spy0.count(), 0); - QCOMPARE(spy1.count(), 0); -#endif - QSKIP("Test is not implemented.", SkipAll); + QCOMPARE(m_series->points(), points); } -Q_DECLARE_METATYPE(QBrush) -void tst_QLineSeries::brush_data() +void tst_QLineSeries::chart_append_data() { -#if 0 - QTest::addColumn("brush"); - QTest::newRow("null") << QBrush(); -#endif + append_data(); } -// public QBrush brush() const -void tst_QLineSeries::brush() +void tst_QLineSeries::chart_append() { -#if 0 - QFETCH(QBrush, brush); + append_raw(); + m_chart->addSeries(m_series); + m_view->show(); + QTest::qWaitForWindowShown(m_view); +} - SubQXYSeries series; +void tst_QLineSeries::append_chart_data() +{ + append_data(); +} - QSignalSpy spy0(&series, SIGNAL(clicked(QPointF const&))); - QSignalSpy spy1(&series, SIGNAL(selected())); +void tst_QLineSeries::append_chart() +{ + m_view->show(); + m_chart->addSeries(m_series); + append_raw(); + QTest::qWaitForWindowShown(m_view); +} - QCOMPARE(series.brush(), brush); +void tst_QLineSeries::append_chart_animation_data() +{ + append_data(); +} - QCOMPARE(spy0.count(), 0); - QCOMPARE(spy1.count(), 0); -#endif - QSKIP("Test is not implemented.", SkipAll); +void tst_QLineSeries::append_chart_animation() +{ + m_chart->setAnimationOptions(QChart::AllAnimations); + append_chart(); } void tst_QLineSeries::count_data() { QTest::addColumn("count"); QTest::newRow("0") << 0; - QTest::newRow("-1") << -1; -} - -// public int count() const -void tst_QLineSeries::count() -{ -#if 0 - QFETCH(int, count); - - SubQXYSeries series; - - QSignalSpy spy0(&series, SIGNAL(clicked(QPointF const&))); - QSignalSpy spy1(&series, SIGNAL(selected())); - - QCOMPARE(series.count(), count); - - QCOMPARE(spy0.count(), 0); - QCOMPARE(spy1.count(), 0); -#endif - QSKIP("Test is not implemented.", SkipAll); + QTest::newRow("5") << 5; + QTest::newRow("10") << 5; } -void tst_QLineSeries::data_data() +void tst_QLineSeries::count_raw_data() { -#if 0 - QTest::addColumn>("data"); - QTest::newRow("null") << QList(); -#endif + count_data(); } -// public QList data() -void tst_QLineSeries::data() +void tst_QLineSeries::count_raw() { -#if 0 - QFETCH(QList, data); - - SubQXYSeries series; + QFETCH(int, count); - QSignalSpy spy0(&series, SIGNAL(clicked(QPointF const&))); - QSignalSpy spy1(&series, SIGNAL(selected())); + QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); - QCOMPARE(series.data(), data); + for(int i=0 ; i< count; ++i) + m_series->append(i,i); QCOMPARE(spy0.count(), 0); - QCOMPARE(spy1.count(), 0); -#endif - QSKIP("Test is not implemented.", SkipAll); + QCOMPARE(m_series->count(), count); } void tst_QLineSeries::oper_data() { -#if 0 - QTest::addColumn>("points"); - QTest::addColumn("operator<<"); - QTest::newRow("null") << QList() << QXYSeries&(); -#endif + append_data(); } -// public QXYSeries& operator<<(QList const points) void tst_QLineSeries::oper() { -#if 0 QFETCH(QList, points); - QFETCH(QXYSeries&, operator<<); - - SubQXYSeries series; + QLineSeries series; QSignalSpy spy0(&series, SIGNAL(clicked(QPointF const&))); - QSignalSpy spy1(&series, SIGNAL(selected())); - QCOMPARE(series.operator<<(points), operator<<); + foreach(const QPointF& point,points) + { + series<("pen"); QTest::newRow("null") << QPen(); -#endif + QTest::newRow("blue") << QPen(Qt::blue); + QTest::newRow("black") << QPen(Qt::black); + QTest::newRow("red") << QPen(Qt::red); } -// public QPen pen() const void tst_QLineSeries::pen() { -#if 0 QFETCH(QPen, pen); - - SubQXYSeries series; + QLineSeries series; QSignalSpy spy0(&series, SIGNAL(clicked(QPointF const&))); - QSignalSpy spy1(&series, SIGNAL(selected())); + series.setPen(pen); + QCOMPARE(spy0.count(), 0); QCOMPARE(series.pen(), pen); - QCOMPARE(spy0.count(), 0); - QCOMPARE(spy1.count(), 0); -#endif - QSKIP("Test is not implemented.", SkipAll); + m_chart->addSeries(&series); + + if(pen!=QPen()) QCOMPARE(series.pen(), pen); } void tst_QLineSeries::pointsVisible_data() @@ -311,60 +284,74 @@ void tst_QLineSeries::pointsVisible_data() QTest::newRow("false") << false; } -// public bool pointsVisible() const -void tst_QLineSeries::pointsVisible() +void tst_QLineSeries::pointsVisible_raw_data() +{ + pointsVisible_data(); +} + +void tst_QLineSeries::pointsVisible_raw() { -#if 0 QFETCH(bool, pointsVisible); + QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); + m_series->setPointsVisible(pointsVisible); + QCOMPARE(spy0.count(), 0); + QCOMPARE(m_series->pointsVisible(), pointsVisible); +} - SubQXYSeries series; +void tst_QLineSeries::remove_raw_data() +{ + append_data(); +} - QSignalSpy spy0(&series, SIGNAL(clicked(QPointF const&))); - QSignalSpy spy1(&series, SIGNAL(selected())); +void tst_QLineSeries::remove_raw() +{ + QFETCH(QList, 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); - QCOMPARE(series.pointsVisible(), pointsVisible); + foreach(const QPointF& point,points) + { + m_series->remove(point); + QTest::qWait(200); + } QCOMPARE(spy0.count(), 0); - QCOMPARE(spy1.count(), 0); -#endif - QSKIP("Test is not implemented.", SkipAll); + QCOMPARE(m_series->points().count(), 0); } -void tst_QLineSeries::remove_data() +void tst_QLineSeries::remove_chart_data() { - QTest::addColumn("x"); - QTest::addColumn("y"); - QTest::newRow("null") << 0.0 << 0.0; + append_data(); } -// public void remove(qreal x, qreal y) -void tst_QLineSeries::remove() +void tst_QLineSeries::remove_chart() { -#if 0 - QFETCH(qreal, x); - QFETCH(qreal, y); - - SubQXYSeries series; - - QSignalSpy spy0(&series, SIGNAL(clicked(QPointF const&))); - QSignalSpy spy1(&series, SIGNAL(selected())); + m_view->show(); + m_chart->addSeries(m_series); + remove_raw(); + QTest::qWaitForWindowShown(m_view); +} - series.remove(x, y); +void tst_QLineSeries::remove_chart_animation_data() +{ + append_data(); +} - QCOMPARE(spy0.count(), 0); - QCOMPARE(spy1.count(), 0); -#endif - QSKIP("Test is not implemented.", SkipAll); +void tst_QLineSeries::remove_chart_animation() +{ + m_chart->setAnimationOptions(QChart::AllAnimations); + remove_chart(); } + void tst_QLineSeries::removeAll_data() { - QTest::addColumn("foo"); - QTest::newRow("0") << 0; - QTest::newRow("-1") << -1; + append_data(); } -// public void removeAll() void tst_QLineSeries::removeAll() { #if 0 @@ -389,7 +376,6 @@ void tst_QLineSeries::replace_data() QTest::newRow("null") << QPointF(); } -// public void replace(QPointF const& point) void tst_QLineSeries::replace() { #if 0 @@ -408,33 +394,6 @@ void tst_QLineSeries::replace() QSKIP("Test is not implemented.", SkipAll); } -void tst_QLineSeries::setBrush_data() -{ -#if 0 - QTest::addColumn("brush"); - QTest::newRow("null") << QBrush(); -#endif -} - -// public void setBrush(QBrush const& brush) -void tst_QLineSeries::setBrush() -{ -#if 0 - QFETCH(QBrush, brush); - - SubQXYSeries series; - - QSignalSpy spy0(&series, SIGNAL(clicked(QPointF const&))); - QSignalSpy spy1(&series, SIGNAL(selected())); - - series.setBrush(brush); - - QCOMPARE(spy0.count(), 0); - QCOMPARE(spy1.count(), 0); -#endif - QSKIP("Test is not implemented.", SkipAll); -} - void tst_QLineSeries::setModel_data() { QTest::addColumn("modelCount"); @@ -442,7 +401,6 @@ void tst_QLineSeries::setModel_data() QTest::newRow("null") << 0 << false; } -// public bool setModel(QAbstractItemModel* model) void tst_QLineSeries::setModel() { #if 0 @@ -473,7 +431,6 @@ void tst_QLineSeries::setModelMapping_data() #endif } -// public void setModelMapping(int modelX, int modelY, Qt::Orientation orientation = Qt::Vertical) void tst_QLineSeries::setModelMapping() { #if 0 @@ -494,164 +451,6 @@ void tst_QLineSeries::setModelMapping() QSKIP("Test is not implemented.", SkipAll); } -void tst_QLineSeries::setPen_data() -{ -#if 0 - QTest::addColumn("pen"); - QTest::newRow("null") << QPen(); -#endif -} - -// public void setPen(QPen const& pen) -void tst_QLineSeries::setPen() -{ -#if 0 - QFETCH(QPen, pen); - - SubQXYSeries series; - - QSignalSpy spy0(&series, SIGNAL(clicked(QPointF const&))); - QSignalSpy spy1(&series, SIGNAL(selected())); - - series.setPen(pen); - - QCOMPARE(spy0.count(), 0); - QCOMPARE(spy1.count(), 0); -#endif - QSKIP("Test is not implemented.", SkipAll); -} - -void tst_QLineSeries::setPointsVisible_data() -{ - QTest::addColumn("visible"); - QTest::newRow("true") << true; - QTest::newRow("false") << false; -} - -// public void setPointsVisible(bool visible = true) -void tst_QLineSeries::setPointsVisible() -{ -#if 0 - QFETCH(bool, visible); - - SubQXYSeries series; - - QSignalSpy spy0(&series, SIGNAL(clicked(QPointF const&))); - QSignalSpy spy1(&series, SIGNAL(selected())); - - series.setPointsVisible(visible); - - QCOMPARE(spy0.count(), 0); - QCOMPARE(spy1.count(), 0); -#endif - QSKIP("Test is not implemented.", SkipAll); -} - -void tst_QLineSeries::x_data() -{ - QTest::addColumn("pos"); - QTest::addColumn("x"); - QTest::newRow("null") << 0 << 0.0; -} - -// public qreal x(int pos) const -void tst_QLineSeries::x() -{ -#if 0 - QFETCH(int, pos); - QFETCH(qreal, x); - - SubQXYSeries series; - - QSignalSpy spy0(&series, SIGNAL(clicked(QPointF const&))); - QSignalSpy spy1(&series, SIGNAL(selected())); - - QCOMPARE(series.x(pos), x); - - QCOMPARE(spy0.count(), 0); - QCOMPARE(spy1.count(), 0); -#endif - QSKIP("Test is not implemented.", SkipAll); -} - -void tst_QLineSeries::y_data() -{ - QTest::addColumn("pos"); - QTest::addColumn("y"); - QTest::newRow("null") << 0 << 0.0; -} - -// public qreal y(int pos) const -void tst_QLineSeries::y() -{ -#if 0 - QFETCH(int, pos); - QFETCH(qreal, y); - - SubQXYSeries series; - - QSignalSpy spy0(&series, SIGNAL(clicked(QPointF const&))); - QSignalSpy spy1(&series, SIGNAL(selected())); - - QCOMPARE(series.y(pos), y); - - QCOMPARE(spy0.count(), 0); - QCOMPARE(spy1.count(), 0); -#endif - QSKIP("Test is not implemented.", SkipAll); -} - -void tst_QLineSeries::clicked_data() -{ - QTest::addColumn("point"); - QTest::newRow("null") << QPointF(); -} - -// protected void clicked(QPointF const& point) -void tst_QLineSeries::clicked() -{ -#if 0 - QFETCH(QPointF, point); - - SubQXYSeries series; - - QSignalSpy spy0(&series, SIGNAL(clicked(QPointF const&))); - QSignalSpy spy1(&series, SIGNAL(selected())); - - series.call_clicked(point); - - QCOMPARE(spy0.count(), 0); - QCOMPARE(spy1.count(), 0); -#endif - QSKIP("Test is not implemented.", SkipAll); -} - -void tst_QLineSeries::selected_data() -{ - QTest::addColumn("foo"); - QTest::newRow("0") << 0; - QTest::newRow("-1") << -1; -} - -// protected void selected() -void tst_QLineSeries::selected() -{ -#if 0 - QFETCH(int, foo); - - SubQXYSeries series; - - QSignalSpy spy0(&series, SIGNAL(clicked(QPointF const&))); - QSignalSpy spy1(&series, SIGNAL(selected())); - - series.call_selected(); - - QCOMPARE(spy0.count(), 0); - QCOMPARE(spy1.count(), 0); -#endif - QSKIP("Test is not implemented.", SkipAll); -} - QTEST_MAIN(tst_QLineSeries) #include "tst_qlineseries.moc"