tst_qlineseries.cpp
240 lines
| 7.6 KiB
| text/x-c
|
CppLexer
|
r2854 | /**************************************************************************** | ||
|
r1064 | ** | ||
|
r2854 | ** Copyright (C) 2016 The Qt Company Ltd. | ||
** Contact: https://www.qt.io/licensing/ | ||||
|
r1064 | ** | ||
|
r2854 | ** This file is part of the Qt Charts module of the Qt Toolkit. | ||
|
r1064 | ** | ||
|
r2854 | ** $QT_BEGIN_LICENSE:GPL$ | ||
|
r2845 | ** Commercial License Usage | ||
** Licensees holding valid commercial Qt licenses may use this file in | ||||
** accordance with the commercial license agreement provided with the | ||||
** Software or, alternatively, in accordance with the terms contained in | ||||
** a written agreement between you and The Qt Company. For licensing terms | ||||
|
r2854 | ** and conditions see https://www.qt.io/terms-conditions. For further | ||
** information use the contact form at https://www.qt.io/contact-us. | ||||
** | ||||
** GNU General Public License Usage | ||||
** Alternatively, this file may be used under the terms of the GNU | ||||
** General Public License version 3 or (at your option) any later version | ||||
** approved by the KDE Free Qt Foundation. The licenses are as published by | ||||
** the Free Software Foundation and appearing in the file LICENSE.GPL3 | ||||
** included in the packaging of this file. Please review the following | ||||
** information to ensure the GNU General Public License requirements will | ||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html. | ||||
|
r1064 | ** | ||
|
r2845 | ** $QT_END_LICENSE$ | ||
** | ||||
|
r2854 | ****************************************************************************/ | ||
|
r1064 | |||
|
r1266 | #include "../qxyseries/tst_qxyseries.h" | ||
|
r2714 | #include <QtCharts/QLineSeries> | ||
|
r1064 | |||
|
r1266 | Q_DECLARE_METATYPE(QList<QPointF>) | ||
|
r2820 | Q_DECLARE_METATYPE(QVector<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(); | ||||
|
r2772 | void insert(); | ||
|
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>()); | ||||
|
r2820 | QCOMPARE(series.pointsVector(), QVector<QPointF>()); | ||
|
r1178 | QCOMPARE(series.pen(), QPen()); | ||
QCOMPARE(series.pointsVisible(), false); | ||||
|
r2689 | QCOMPARE(series.pointLabelsVisible(), false); | ||
QCOMPARE(series.pointLabelsFormat(), QLatin1String("@xPoint, @yPoint")); | ||||
|
r2815 | QCOMPARE(series.pointLabelsClipping(), true); | ||
|
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())); | ||||
} | ||||
|
r2772 | void tst_QLineSeries::insert() | ||
{ | ||||
QLineSeries lineSeries; | ||||
QSignalSpy insertSpy(&lineSeries, &QXYSeries::pointAdded); | ||||
lineSeries.insert(0, QPoint(3, 3)); | ||||
QCOMPARE(insertSpy.count(), 1); | ||||
QVariantList arguments = insertSpy.takeFirst(); | ||||
QCOMPARE(arguments.first().toInt(), 0); | ||||
lineSeries.insert(0, QPoint(1, 1)); | ||||
arguments = insertSpy.takeFirst(); | ||||
QCOMPARE(arguments.first().toInt(), 0); | ||||
lineSeries.insert(1, QPoint(2, 2)); | ||||
arguments = insertSpy.takeFirst(); | ||||
QCOMPARE(arguments.first().toInt(), 1); | ||||
lineSeries.insert(42, QPoint(0, 0)); | ||||
arguments = insertSpy.takeFirst(); | ||||
QCOMPARE(arguments.first().toInt(), 3); | ||||
lineSeries.insert(-42, QPoint(0, 0)); | ||||
arguments = insertSpy.takeFirst(); | ||||
QCOMPARE(arguments.first().toInt(), 0); | ||||
} | ||||
|
r2739 | 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); | ||||
|
r2746 | // mouseClick needed first to save the position | ||
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, checkPoint.toPoint()); | ||||
|
r2739 | 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" | ||||