tst_qlineseries.cpp
202 lines
| 5.9 KiB
| text/x-c
|
CppLexer
|
r1064 | /**************************************************************************** | ||
** | ||||
|
r2688 | ** Copyright (C) 2014 Digia Plc | ||
|
r1064 | ** All rights reserved. | ||
|
r2740 | ** For any questions to Digia, please use contact form at http://qt.io | ||
|
r1064 | ** | ||
|
r2740 | ** This file is part of the Qt Charts module. | ||
|
r1064 | ** | ||
|
r2740 | ** Licensees holding valid commercial license for Qt may use this file in | ||
** accordance with the Qt License Agreement provided with the Software | ||||
** or, alternatively, in accordance with the terms contained in a written | ||||
** agreement between you and Digia. | ||||
|
r1064 | ** | ||
** If you have questions regarding the use of this file, please use | ||||
|
r2740 | ** contact form at http://qt.io | ||
|
r1064 | ** | ||
****************************************************************************/ | ||||
|
r1266 | #include "../qxyseries/tst_qxyseries.h" | ||
|
r2714 | #include <QtCharts/QLineSeries> | ||
|
r1064 | |||
|
r1058 | |||
|
r1266 | Q_DECLARE_METATYPE(QList<QPointF>) | ||
|
r1058 | |||
|
r1266 | class tst_QLineSeries : public tst_QXYSeries | ||
|
r1058 | { | ||
Q_OBJECT | ||||
|
r1266 | public slots: | ||
|
r1058 | void initTestCase(); | ||
void cleanupTestCase(); | ||||
void init(); | ||||
void cleanup(); | ||||
|
r1266 | private slots: | ||
|
r1064 | void qlineseries_data(); | ||
void qlineseries(); | ||||
|
r2739 | void pressedSignal(); | ||
void releasedSignal(); | ||||
void doubleClickedSignal(); | ||||
|
r1266 | protected: | ||
|
r1070 | void pointsVisible_data(); | ||
|
r1058 | }; | ||
void tst_QLineSeries::initTestCase() | ||||
{ | ||||
} | ||||
void tst_QLineSeries::cleanupTestCase() | ||||
{ | ||||
|
r2733 | QTest::qWait(1); // Allow final deleteLaters to run | ||
|
r1058 | } | ||
void tst_QLineSeries::init() | ||||
{ | ||||
|
r1266 | tst_QXYSeries::init(); | ||
|
r1072 | m_series = new QLineSeries(); | ||
|
r1058 | } | ||
void tst_QLineSeries::cleanup() | ||||
{ | ||||
|
r1070 | delete m_series; | ||
|
r1699 | m_series=0; | ||
|
r1266 | tst_QXYSeries::cleanup(); | ||
|
r1058 | } | ||
|
r1064 | void tst_QLineSeries::qlineseries_data() | ||
|
r1058 | { | ||
|
r1070 | |||
|
r1058 | } | ||
|
r1064 | void tst_QLineSeries::qlineseries() | ||
|
r1058 | { | ||
|
r1178 | QLineSeries series; | ||
|
r1064 | |||
|
r1178 | QCOMPARE(series.count(),0); | ||
QCOMPARE(series.brush(), QBrush()); | ||||
QCOMPARE(series.points(), QList<QPointF>()); | ||||
QCOMPARE(series.pen(), QPen()); | ||||
QCOMPARE(series.pointsVisible(), false); | ||||
|
r2689 | QCOMPARE(series.pointLabelsVisible(), false); | ||
QCOMPARE(series.pointLabelsFormat(), QLatin1String("@xPoint, @yPoint")); | ||||
|
r1064 | |||
|
r1178 | series.append(QList<QPointF>()); | ||
series.append(0.0,0.0); | ||||
series.append(QPointF()); | ||||
|
r1064 | |||
|
r1178 | series.remove(0.0,0.0); | ||
series.remove(QPointF()); | ||||
|
r1374 | series.clear(); | ||
|
r1064 | |||
|
r1178 | series.replace(QPointF(),QPointF()); | ||
series.replace(0,0,0,0); | ||||
series.setBrush(QBrush()); | ||||
|
r1064 | |||
|
r1178 | series.setPen(QPen()); | ||
series.setPointsVisible(false); | ||||
|
r1070 | |||
|
r2689 | series.setPointLabelsVisible(false); | ||
series.setPointLabelsFormat(QString()); | ||||
|
r1178 | m_chart->addSeries(&series); | ||
m_view->show(); | ||||
QTest::qWaitForWindowShown(m_view); | ||||
|
r1058 | } | ||
|
r2739 | void tst_QLineSeries::pressedSignal() | ||
{ | ||||
SKIP_IF_CANNOT_TEST_MOUSE_EVENTS(); | ||||
QPointF linePoint(4, 12); | ||||
QLineSeries *lineSeries = new QLineSeries(); | ||||
lineSeries->append(QPointF(2, 1)); | ||||
lineSeries->append(linePoint); | ||||
lineSeries->append(QPointF(6, 12)); | ||||
QChartView view; | ||||
view.chart()->legend()->setVisible(false); | ||||
view.chart()->addSeries(lineSeries); | ||||
view.show(); | ||||
QTest::qWaitForWindowShown(&view); | ||||
QSignalSpy seriesSpy(lineSeries, SIGNAL(pressed(QPointF))); | ||||
QPointF checkPoint = view.chart()->mapToPosition(linePoint); | ||||
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, checkPoint.toPoint()); | ||||
QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | ||||
QCOMPARE(seriesSpy.count(), 1); | ||||
QList<QVariant> seriesSpyArg = seriesSpy.takeFirst(); | ||||
// checkPoint is QPointF and for the mouseClick it it's changed to QPoint | ||||
// this causes small distinction in decimals so we round it before comparing | ||||
QPointF signalPoint = qvariant_cast<QPointF>(seriesSpyArg.at(0)); | ||||
QCOMPARE(qRound(signalPoint.x()), qRound(linePoint.x())); | ||||
QCOMPARE(qRound(signalPoint.y()), qRound(linePoint.y())); | ||||
} | ||||
void tst_QLineSeries::releasedSignal() | ||||
{ | ||||
SKIP_IF_CANNOT_TEST_MOUSE_EVENTS(); | ||||
QPointF linePoint(4, 12); | ||||
QLineSeries *lineSeries = new QLineSeries(); | ||||
lineSeries->append(QPointF(2, 20)); | ||||
lineSeries->append(linePoint); | ||||
lineSeries->append(QPointF(6, 12)); | ||||
QChartView view; | ||||
view.chart()->legend()->setVisible(false); | ||||
view.chart()->addSeries(lineSeries); | ||||
view.show(); | ||||
QTest::qWaitForWindowShown(&view); | ||||
QSignalSpy seriesSpy(lineSeries, SIGNAL(released(QPointF))); | ||||
QPointF checkPoint = view.chart()->mapToPosition(linePoint); | ||||
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, checkPoint.toPoint()); | ||||
QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | ||||
QCOMPARE(seriesSpy.count(), 1); | ||||
QList<QVariant> seriesSpyArg = seriesSpy.takeFirst(); | ||||
// checkPoint is QPointF and for the mouseClick it it's changed to QPoint | ||||
// this causes small distinction in decimals so we round it before comparing | ||||
QPointF signalPoint = qvariant_cast<QPointF>(seriesSpyArg.at(0)); | ||||
QCOMPARE(qRound(signalPoint.x()), qRound(linePoint.x())); | ||||
QCOMPARE(qRound(signalPoint.y()), qRound(linePoint.y())); | ||||
} | ||||
void tst_QLineSeries::doubleClickedSignal() | ||||
{ | ||||
SKIP_IF_CANNOT_TEST_MOUSE_EVENTS(); | ||||
QPointF linePoint(4, 12); | ||||
QLineSeries *lineSeries = new QLineSeries(); | ||||
lineSeries->append(QPointF(2, 20)); | ||||
lineSeries->append(linePoint); | ||||
lineSeries->append(QPointF(6, 12)); | ||||
QChartView view; | ||||
view.chart()->legend()->setVisible(false); | ||||
view.chart()->addSeries(lineSeries); | ||||
view.show(); | ||||
QTest::qWaitForWindowShown(&view); | ||||
QSignalSpy seriesSpy(lineSeries, SIGNAL(doubleClicked(QPointF))); | ||||
QPointF checkPoint = view.chart()->mapToPosition(linePoint); | ||||
QTest::mouseDClick(view.viewport(), Qt::LeftButton, 0, checkPoint.toPoint()); | ||||
QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | ||||
QCOMPARE(seriesSpy.count(), 1); | ||||
QList<QVariant> seriesSpyArg = seriesSpy.takeFirst(); | ||||
// checkPoint is QPointF and for the mouseClick it it's changed to QPoint | ||||
// this causes small distinction in decimals so we round it before comparing | ||||
QPointF signalPoint = qvariant_cast<QPointF>(seriesSpyArg.at(0)); | ||||
QCOMPARE(qRound(signalPoint.x()), qRound(linePoint.x())); | ||||
QCOMPARE(qRound(signalPoint.y()), qRound(linePoint.y())); | ||||
} | ||||
|
r1058 | QTEST_MAIN(tst_QLineSeries) | ||
#include "tst_qlineseries.moc" | ||||