tst_qstackedbarseries.cpp
272 lines
| 8.1 KiB
| text/x-c
|
CppLexer
|
r1116 | /**************************************************************************** | ||
** | ||||
** 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$ | ||||
** | ||||
****************************************************************************/ | ||||
#include <QtTest/QtTest> | ||||
#include <qstackedbarseries.h> | ||||
#include <qbarset.h> | ||||
|
r1145 | #include <qchartview.h> | ||
#include <qchart.h> | ||||
|
r1116 | |||
QTCOMMERCIALCHART_USE_NAMESPACE | ||||
|
r1145 | Q_DECLARE_METATYPE(QBarSet*) | ||
|
r1116 | class tst_QStackedBarSeries : public QObject | ||
{ | ||||
Q_OBJECT | ||||
public slots: | ||||
void initTestCase(); | ||||
void cleanupTestCase(); | ||||
void init(); | ||||
void cleanup(); | ||||
private slots: | ||||
void qstackedbarseries_data(); | ||||
void qstackedbarseries(); | ||||
void type_data(); | ||||
void type(); | ||||
|
r1146 | void mouseclicked_data(); | ||
void mouseclicked(); | ||||
void mousehovered_data(); | ||||
void mousehovered(); | ||||
|
r1116 | |||
private: | ||||
QStackedBarSeries* m_barseries; | ||||
}; | ||||
void tst_QStackedBarSeries::initTestCase() | ||||
{ | ||||
|
r1145 | qRegisterMetaType<QBarSet*>("QBarSet*"); | ||
|
r1116 | } | ||
void tst_QStackedBarSeries::cleanupTestCase() | ||||
{ | ||||
} | ||||
void tst_QStackedBarSeries::init() | ||||
{ | ||||
m_barseries = new QStackedBarSeries(); | ||||
} | ||||
void tst_QStackedBarSeries::cleanup() | ||||
{ | ||||
delete m_barseries; | ||||
m_barseries = 0; | ||||
} | ||||
void tst_QStackedBarSeries::qstackedbarseries_data() | ||||
{ | ||||
} | ||||
void tst_QStackedBarSeries::qstackedbarseries() | ||||
{ | ||||
QStackedBarSeries *barseries = new QStackedBarSeries(); | ||||
QVERIFY(barseries != 0); | ||||
} | ||||
void tst_QStackedBarSeries::type_data() | ||||
{ | ||||
} | ||||
void tst_QStackedBarSeries::type() | ||||
{ | ||||
QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeStackedBar); | ||||
} | ||||
|
r1146 | void tst_QStackedBarSeries::mouseclicked_data() | ||
|
r1145 | { | ||
} | ||||
|
r1146 | void tst_QStackedBarSeries::mouseclicked() | ||
|
r1145 | { | ||
QStackedBarSeries* series = new QStackedBarSeries(); | ||||
QBarSet* set1 = new QBarSet(QString("set 1")); | ||||
*set1 << 10 << 10 << 10; | ||||
|
r1194 | series->append(set1); | ||
|
r1145 | |||
QBarSet* set2 = new QBarSet(QString("set 2")); | ||||
*set2 << 10 << 10 << 10; | ||||
|
r1194 | series->append(set2); | ||
|
r1145 | |||
|
r1321 | QSignalSpy seriesSpy(series,SIGNAL(clicked(QBarSet*,int))); | ||
|
r1145 | |||
QChartView view(new QChart()); | ||||
view.resize(400,300); | ||||
view.chart()->addSeries(series); | ||||
view.show(); | ||||
QTest::qWaitForWindowShown(&view); | ||||
//==================================================================================== | ||||
// barset 1, category test1 | ||||
|
r1287 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(106,190)); | ||
|
r1145 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | ||
QCOMPARE(seriesSpy.count(), 1); | ||||
QList<QVariant> seriesSpyArg = seriesSpy.takeFirst(); | ||||
QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); | ||||
|
r1321 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int); | ||
QVERIFY(seriesSpyArg.at(1).toInt() == 0); | ||||
|
r1145 | |||
//==================================================================================== | ||||
// barset 1, category test2 | ||||
|
r1287 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(199,190)); | ||
|
r1145 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | ||
QCOMPARE(seriesSpy.count(), 1); | ||||
seriesSpyArg = seriesSpy.takeFirst(); | ||||
QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); | ||||
|
r1321 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int); | ||
QVERIFY(seriesSpyArg.at(1).toInt() == 1); | ||||
|
r1145 | |||
//==================================================================================== | ||||
// barset 1, category test3 | ||||
|
r1287 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(292,190)); | ||
|
r1145 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | ||
QCOMPARE(seriesSpy.count(), 1); | ||||
seriesSpyArg = seriesSpy.takeFirst(); | ||||
QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); | ||||
|
r1321 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int); | ||
QVERIFY(seriesSpyArg.at(1).toInt() == 2); | ||||
|
r1145 | |||
//==================================================================================== | ||||
// barset 2, category test1 | ||||
|
r1287 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(106,95)); | ||
|
r1145 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | ||
QCOMPARE(seriesSpy.count(), 1); | ||||
seriesSpyArg = seriesSpy.takeFirst(); | ||||
QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); | ||||
|
r1321 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int); | ||
QVERIFY(seriesSpyArg.at(1).toInt() == 0); | ||||
|
r1145 | |||
//==================================================================================== | ||||
// barset 2, category test2 | ||||
|
r1287 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(199,95)); | ||
|
r1145 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | ||
QCOMPARE(seriesSpy.count(), 1); | ||||
seriesSpyArg = seriesSpy.takeFirst(); | ||||
QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); | ||||
|
r1321 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int); | ||
QVERIFY(seriesSpyArg.at(1).toInt() == 1); | ||||
|
r1145 | |||
//==================================================================================== | ||||
// barset 2, category test3 | ||||
|
r1287 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(292,95)); | ||
|
r1145 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | ||
QCOMPARE(seriesSpy.count(), 1); | ||||
seriesSpyArg = seriesSpy.takeFirst(); | ||||
QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); | ||||
|
r1321 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int); | ||
QVERIFY(seriesSpyArg.at(1).toInt() == 2); | ||||
|
r1145 | } | ||
|
r1146 | void tst_QStackedBarSeries::mousehovered_data() | ||
{ | ||||
} | ||||
void tst_QStackedBarSeries::mousehovered() | ||||
{ | ||||
QStackedBarSeries* series = new QStackedBarSeries(); | ||||
QBarSet* set1 = new QBarSet(QString("set 1")); | ||||
*set1 << 10 << 10 << 10; | ||||
|
r1194 | series->append(set1); | ||
|
r1146 | |||
QBarSet* set2 = new QBarSet(QString("set 2")); | ||||
*set2 << 10 << 10 << 10; | ||||
|
r1194 | series->append(set2); | ||
|
r1146 | |||
QSignalSpy seriesSpy(series,SIGNAL(hovered(QBarSet*,bool))); | ||||
QChartView view(new QChart()); | ||||
view.resize(400,300); | ||||
view.chart()->addSeries(series); | ||||
view.show(); | ||||
QTest::qWaitForWindowShown(&view); | ||||
|
r1287 | //this is hack since view does not get events otherwise | ||
view.setMouseTracking(true); | ||||
|
r1146 | //======================================================================= | ||
// move mouse to left border | ||||
|
r1287 | QTest::mouseMove(view.viewport(), QPoint(0, 190)); | ||
|
r1146 | |||
QVERIFY(seriesSpy.count() == 0); | ||||
//======================================================================= | ||||
// move mouse on top of set1 | ||||
|
r1287 | QTest::mouseMove(view.viewport(), QPoint(106,190)); | ||
|
r1146 | |||
QVERIFY(seriesSpy.count() == 1); | ||||
QList<QVariant> seriesSpyArg = seriesSpy.takeFirst(); | ||||
QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); | ||||
|
r1287 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool); | ||
QVERIFY(seriesSpyArg.at(1).toBool() == true); | ||||
|
r1146 | |||
//======================================================================= | ||||
// move mouse from top of set1 to top of set2 | ||||
|
r1287 | QTest::mouseMove(view.viewport(), QPoint(106,95)); | ||
|
r1146 | |||
QVERIFY(seriesSpy.count() == 2); | ||||
// should leave set1 | ||||
seriesSpyArg = seriesSpy.takeFirst(); | ||||
QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); | ||||
QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool); | ||||
QVERIFY(seriesSpyArg.at(1).toBool() == false); | ||||
// should enter set2 | ||||
seriesSpyArg = seriesSpy.takeFirst(); | ||||
QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); | ||||
QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool); | ||||
QVERIFY(seriesSpyArg.at(1).toBool() == true); | ||||
//======================================================================= | ||||
// move mouse from top of set2 to background | ||||
|
r1287 | QTest::mouseMove(view.viewport(), QPoint(106,0)); | ||
|
r1146 | |||
QVERIFY(seriesSpy.count() == 1); | ||||
|
r1287 | // should leave set2 | ||
|
r1146 | seriesSpyArg = seriesSpy.takeFirst(); | ||
QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); | ||||
QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool); | ||||
QVERIFY(seriesSpyArg.at(1).toBool() == false); | ||||
} | ||||
|
r1116 | QTEST_MAIN(tst_QStackedBarSeries) | ||
#include "tst_qstackedbarseries.moc" | ||||