tst_qpercentbarseries.cpp
605 lines
| 22.8 KiB
| text/x-c
|
CppLexer
|
r1116 | /**************************************************************************** | ||
** | ||||
|
r2433 | ** Copyright (C) 2013 Digia Plc | ||
|
r1116 | ** All rights reserved. | ||
** For any questions to Digia, please use contact form at http://qt.digia.com | ||||
** | ||||
|
r2574 | ** This file is part of the Qt Enterprise Charts Add-on. | ||
|
r1116 | ** | ||
** $QT_BEGIN_LICENSE$ | ||||
|
r2574 | ** Licensees holding valid Qt Enterprise licenses may use this file in | ||
** accordance with the Qt Enterprise License Agreement provided with the | ||||
|
r1116 | ** 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 <qpercentbarseries.h> | ||||
#include <qbarset.h> | ||||
|
r1145 | #include <qchartview.h> | ||
#include <qchart.h> | ||||
|
r1466 | #include "tst_definitions.h" | ||
|
r1116 | |||
QTCOMMERCIALCHART_USE_NAMESPACE | ||||
|
r1145 | Q_DECLARE_METATYPE(QBarSet*) | ||
|
r1116 | class tst_QPercentBarSeries : public QObject | ||
{ | ||||
Q_OBJECT | ||||
public slots: | ||||
void initTestCase(); | ||||
void cleanupTestCase(); | ||||
void init(); | ||||
void cleanup(); | ||||
private slots: | ||||
void qpercentbarseries_data(); | ||||
void qpercentbarseries(); | ||||
void type_data(); | ||||
void type(); | ||||
|
r1146 | void mouseclicked_data(); | ||
void mouseclicked(); | ||||
void mousehovered_data(); | ||||
void mousehovered(); | ||||
|
r1116 | |||
private: | ||||
QPercentBarSeries* m_barseries; | ||||
}; | ||||
void tst_QPercentBarSeries::initTestCase() | ||||
{ | ||||
|
r1145 | qRegisterMetaType<QBarSet*>("QBarSet*"); | ||
|
r1116 | } | ||
void tst_QPercentBarSeries::cleanupTestCase() | ||||
{ | ||||
} | ||||
void tst_QPercentBarSeries::init() | ||||
{ | ||||
m_barseries = new QPercentBarSeries(); | ||||
} | ||||
void tst_QPercentBarSeries::cleanup() | ||||
{ | ||||
delete m_barseries; | ||||
m_barseries = 0; | ||||
} | ||||
void tst_QPercentBarSeries::qpercentbarseries_data() | ||||
{ | ||||
} | ||||
void tst_QPercentBarSeries::qpercentbarseries() | ||||
{ | ||||
QPercentBarSeries *barseries = new QPercentBarSeries(); | ||||
QVERIFY(barseries != 0); | ||||
} | ||||
void tst_QPercentBarSeries::type_data() | ||||
{ | ||||
} | ||||
void tst_QPercentBarSeries::type() | ||||
{ | ||||
QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypePercentBar); | ||||
} | ||||
|
r1146 | void tst_QPercentBarSeries::mouseclicked_data() | ||
|
r1145 | { | ||
} | ||||
|
r1146 | void tst_QPercentBarSeries::mouseclicked() | ||
|
r1145 | { | ||
|
r2066 | SKIP_IF_CANNOT_TEST_MOUSE_EVENTS(); | ||
|
r1145 | QPercentBarSeries* series = new QPercentBarSeries(); | ||
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 | |||
|
r2073 | QList<QBarSet*> barSets = series->barSets(); | ||
|
r2110 | QSignalSpy seriesSpy(series,SIGNAL(clicked(int,QBarSet*))); | ||
|
r1145 | |||
QChartView view(new QChart()); | ||||
view.resize(400,300); | ||||
view.chart()->addSeries(series); | ||||
view.show(); | ||||
QTest::qWaitForWindowShown(&view); | ||||
|
r2073 | // Calculate expected layout for bars | ||
QRectF plotArea = view.chart()->plotArea(); | ||||
qreal width = plotArea.width(); | ||||
qreal height = plotArea.height(); | ||||
qreal rangeY = 100; // From 0 to 100 because range is scaled to 100% | ||||
qreal rangeX = 3; // 3 values per set | ||||
qreal scaleY = (height / rangeY); | ||||
qreal scaleX = (width / rangeX); | ||||
qreal setCount = series->count(); | ||||
qreal domainMinY = 0; // These come from internal domain used by barseries. | ||||
qreal domainMinX = -0.5; // No access to domain from outside, so use hard coded values. | ||||
qreal rectWidth = scaleX * series->barWidth(); | ||||
QVector<QRectF> layout; | ||||
// 3 = count of values in set | ||||
// Note that rects in this vector will be interleaved (set1 bar0, set2 bar0, set1 bar1, set2 bar1, etc.) | ||||
for (int i = 0; i < 3; i++) { | ||||
qreal colSum = 20; // Sum of values in column (10 + 10 in our test case) | ||||
qreal percentage = (100 / colSum); | ||||
qreal yPos = height + scaleY * domainMinY + plotArea.top(); | ||||
for (int set = 0; set < setCount; set++) { | ||||
qreal xPos = (i - domainMinX) * scaleX + plotArea.left() - rectWidth/2; | ||||
qreal rectHeigth = barSets.at(set)->at(i) * percentage * scaleY; | ||||
QRectF rect(xPos, yPos-rectHeigth, rectWidth, rectHeigth); | ||||
layout.append(rect); | ||||
yPos -= rectHeigth; | ||||
} | ||||
} | ||||
|
r1145 | //==================================================================================== | ||
|
r2073 | // barset 1, bar 0 | ||
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(0).center().toPoint()); | ||||
|
r1145 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | ||
QCOMPARE(seriesSpy.count(), 1); | ||||
QList<QVariant> seriesSpyArg = seriesSpy.takeFirst(); | ||||
|
r1563 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); | ||
QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); | ||||
QVERIFY(seriesSpyArg.at(0).toInt() == 0); | ||||
|
r1145 | |||
//==================================================================================== | ||||
|
r2073 | // barset 1, bar 1 | ||
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(2).center().toPoint()); | ||||
|
r1145 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | ||
QCOMPARE(seriesSpy.count(), 1); | ||||
seriesSpyArg = seriesSpy.takeFirst(); | ||||
|
r1563 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); | ||
QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); | ||||
QVERIFY(seriesSpyArg.at(0).toInt() == 1); | ||||
|
r1145 | |||
//==================================================================================== | ||||
|
r2073 | // barset 1, bar 2 | ||
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(4).center().toPoint()); | ||||
|
r1145 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | ||
QCOMPARE(seriesSpy.count(), 1); | ||||
seriesSpyArg = seriesSpy.takeFirst(); | ||||
|
r1563 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); | ||
QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); | ||||
QVERIFY(seriesSpyArg.at(0).toInt() == 2); | ||||
|
r1145 | |||
//==================================================================================== | ||||
|
r2073 | // barset 2, bar 0 | ||
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(1).center().toPoint()); | ||||
|
r1145 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | ||
QCOMPARE(seriesSpy.count(), 1); | ||||
seriesSpyArg = seriesSpy.takeFirst(); | ||||
|
r1563 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); | ||
QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); | ||||
QVERIFY(seriesSpyArg.at(0).toInt() == 0); | ||||
|
r1145 | |||
//==================================================================================== | ||||
|
r2073 | // barset 2, bar 1 | ||
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(3).center().toPoint()); | ||||
|
r1145 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | ||
QCOMPARE(seriesSpy.count(), 1); | ||||
seriesSpyArg = seriesSpy.takeFirst(); | ||||
|
r1563 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); | ||
QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); | ||||
QVERIFY(seriesSpyArg.at(0).toInt() == 1); | ||||
|
r1145 | |||
//==================================================================================== | ||||
|
r2073 | // barset 2, bar 2 | ||
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(5).center().toPoint()); | ||||
|
r1145 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | ||
QCOMPARE(seriesSpy.count(), 1); | ||||
seriesSpyArg = seriesSpy.takeFirst(); | ||||
|
r1563 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); | ||
QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); | ||||
QVERIFY(seriesSpyArg.at(0).toInt() == 2); | ||||
|
r1145 | } | ||
|
r1116 | |||
|
r1146 | void tst_QPercentBarSeries::mousehovered_data() | ||
{ | ||||
} | ||||
void tst_QPercentBarSeries::mousehovered() | ||||
{ | ||||
|
r2066 | SKIP_IF_CANNOT_TEST_MOUSE_EVENTS(); | ||
|
r1146 | QPercentBarSeries* series = new QPercentBarSeries(); | ||
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 | |||
|
r2073 | QList<QBarSet*> barSets = series->barSets(); | ||
|
r2110 | QSignalSpy seriesSpy(series,SIGNAL(hovered(bool,QBarSet*))); | ||
|
r2600 | QSignalSpy seriesIndexSpy(series, SIGNAL(hovered(bool, int, QBarSet*))); | ||
QSignalSpy setIndexSpy1(set1, SIGNAL(hovered(bool, int))); | ||||
QSignalSpy setIndexSpy2(set2, SIGNAL(hovered(bool, int))); | ||||
|
r1146 | |||
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); | ||||
|
r2073 | // Calculate expected layout for bars | ||
QRectF plotArea = view.chart()->plotArea(); | ||||
qreal width = plotArea.width(); | ||||
qreal height = plotArea.height(); | ||||
qreal rangeY = 100; // From 0 to 100 because range is scaled to 100% | ||||
qreal rangeX = 3; // 3 values per set | ||||
qreal scaleY = (height / rangeY); | ||||
qreal scaleX = (width / rangeX); | ||||
qreal setCount = series->count(); | ||||
qreal domainMinY = 0; // These come from internal domain used by barseries. | ||||
qreal domainMinX = -0.5; // No access to domain from outside, so use hard coded values. | ||||
qreal rectWidth = scaleX * series->barWidth(); | ||||
QVector<QRectF> layout; | ||||
// 3 = count of values in set | ||||
// Note that rects in this vector will be interleaved (set1 bar0, set2 bar0, set1 bar1, set2 bar1, etc.) | ||||
for (int i = 0; i < 3; i++) { | ||||
qreal colSum = 20; // Sum of values in column (10 + 10 in our test case) | ||||
qreal percentage = (100 / colSum); | ||||
qreal yPos = height + scaleY * domainMinY + plotArea.top(); | ||||
for (int set = 0; set < setCount; set++) { | ||||
qreal xPos = (i - domainMinX) * scaleX + plotArea.left() - rectWidth/2; | ||||
qreal rectHeight = barSets.at(set)->at(i) * percentage * scaleY; | ||||
QRectF rect(xPos, yPos-rectHeight, rectWidth, rectHeight); | ||||
layout.append(rect); | ||||
yPos -= rectHeight; | ||||
} | ||||
} | ||||
|
r1146 | //======================================================================= | ||
// move mouse to left border | ||||
|
r2073 | QTest::mouseMove(view.viewport(), QPoint(0, layout.at(0).center().y())); | ||
|
r1466 | QCoreApplication::processEvents(QEventLoop::AllEvents, 10000); | ||
TRY_COMPARE(seriesSpy.count(), 0); | ||||
|
r2600 | TRY_COMPARE(seriesIndexSpy.count(), 0); | ||
|
r1146 | |||
//======================================================================= | ||||
// move mouse on top of set1 | ||||
|
r2073 | QTest::mouseMove(view.viewport(), layout.at(0).center().toPoint()); | ||
|
r1466 | TRY_COMPARE(seriesSpy.count(), 1); | ||
|
r2600 | TRY_COMPARE(seriesIndexSpy.count(), 1); | ||
TRY_COMPARE(setIndexSpy1.count(), 1); | ||||
TRY_COMPARE(setIndexSpy2.count(), 0); | ||||
|
r1146 | |||
QList<QVariant> seriesSpyArg = seriesSpy.takeFirst(); | ||||
|
r1563 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); | ||
QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); | ||||
QVERIFY(seriesSpyArg.at(0).toBool() == true); | ||||
|
r1146 | |||
|
r2600 | QList<QVariant> seriesIndexSpyArg = seriesIndexSpy.takeFirst(); | ||
QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1); | ||||
QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool); | ||||
QVERIFY(seriesIndexSpyArg.at(0).toBool() == true); | ||||
QList<QVariant> setIndexSpyArg = setIndexSpy1.takeFirst(); | ||||
QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool); | ||||
QVERIFY(setIndexSpyArg.at(0).toBool() == true); | ||||
|
r1146 | //======================================================================= | ||
// move mouse from top of set1 to top of set2 | ||||
|
r2073 | QTest::mouseMove(view.viewport(), layout.at(1).center().toPoint()); | ||
|
r1466 | TRY_COMPARE(seriesSpy.count(), 2); | ||
|
r2600 | TRY_COMPARE(seriesIndexSpy.count(), 2); | ||
TRY_COMPARE(setIndexSpy1.count(), 1); | ||||
TRY_COMPARE(setIndexSpy2.count(), 1); | ||||
|
r1146 | |||
// should leave set1 | ||||
seriesSpyArg = seriesSpy.takeFirst(); | ||||
|
r1563 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); | ||
QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); | ||||
QVERIFY(seriesSpyArg.at(0).toBool() == false); | ||||
|
r1146 | |||
|
r2600 | seriesIndexSpyArg = seriesIndexSpy.takeFirst(); | ||
QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1); | ||||
QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool); | ||||
QVERIFY(seriesIndexSpyArg.at(0).toBool() == false); | ||||
setIndexSpyArg = setIndexSpy1.takeFirst(); | ||||
QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool); | ||||
QVERIFY(setIndexSpyArg.at(0).toBool() == false); | ||||
|
r1146 | // should enter set2 | ||
seriesSpyArg = seriesSpy.takeFirst(); | ||||
|
r1563 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); | ||
QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); | ||||
QVERIFY(seriesSpyArg.at(0).toBool() == true); | ||||
|
r1146 | |||
|
r2600 | seriesIndexSpyArg = seriesIndexSpy.takeFirst(); | ||
QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2); | ||||
QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool); | ||||
QVERIFY(seriesIndexSpyArg.at(0).toBool() == true); | ||||
setIndexSpyArg = setIndexSpy2.takeFirst(); | ||||
QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool); | ||||
QVERIFY(setIndexSpyArg.at(0).toBool() == true); | ||||
|
r1146 | //======================================================================= | ||
// move mouse from top of set2 to background | ||||
|
r2073 | QTest::mouseMove(view.viewport(), QPoint(layout.at(1).center().x(), 0)); | ||
|
r1466 | TRY_COMPARE(seriesSpy.count(), 1); | ||
|
r2600 | TRY_COMPARE(seriesIndexSpy.count(), 1); | ||
TRY_COMPARE(setIndexSpy1.count(), 0); | ||||
TRY_COMPARE(setIndexSpy2.count(), 1); | ||||
|
r1146 | |||
|
r1287 | // should leave set2 | ||
|
r1146 | seriesSpyArg = seriesSpy.takeFirst(); | ||
|
r1563 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); | ||
QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); | ||||
QVERIFY(seriesSpyArg.at(0).toBool() == false); | ||||
|
r2600 | |||
seriesIndexSpyArg = seriesIndexSpy.takeFirst(); | ||||
QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2); | ||||
QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool); | ||||
QVERIFY(seriesIndexSpyArg.at(0).toBool() == false); | ||||
setIndexSpyArg = setIndexSpy2.takeFirst(); | ||||
QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool); | ||||
QVERIFY(setIndexSpyArg.at(0).toBool() == false); | ||||
//======================================================================= | ||||
// move mouse on top of set1, bar0 to check the index (hover into set1) | ||||
QTest::mouseMove(view.viewport(), layout.at(0).center().toPoint()); | ||||
TRY_COMPARE(seriesSpy.count(), 1); | ||||
TRY_COMPARE(seriesIndexSpy.count(), 1); | ||||
TRY_COMPARE(setIndexSpy1.count(), 1); | ||||
TRY_COMPARE(setIndexSpy2.count(), 0); | ||||
//should enter set1, bar0 | ||||
seriesSpyArg = seriesSpy.takeFirst(); | ||||
QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); | ||||
QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); | ||||
QVERIFY(seriesSpyArg.at(0).toBool() == true); | ||||
seriesIndexSpyArg = seriesIndexSpy.takeFirst(); | ||||
QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1); | ||||
QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool); | ||||
QVERIFY(seriesIndexSpyArg.at(0).toBool() == true); | ||||
QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int); | ||||
QVERIFY(seriesIndexSpyArg.at(1).toInt() == 0); | ||||
setIndexSpyArg = setIndexSpy1.takeFirst(); | ||||
QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool); | ||||
QVERIFY(setIndexSpyArg.at(0).toBool() == true); | ||||
QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int); | ||||
QVERIFY(setIndexSpyArg.at(1).toInt() == 0); | ||||
//======================================================================= | ||||
// move mouse on top of set2, bar0 to check the index (hover out set1, | ||||
// hover in set2) | ||||
QTest::mouseMove(view.viewport(), layout.at(1).center().toPoint()); | ||||
TRY_COMPARE(seriesSpy.count(), 2); | ||||
TRY_COMPARE(seriesIndexSpy.count(), 2); | ||||
TRY_COMPARE(setIndexSpy1.count(), 1); | ||||
TRY_COMPARE(setIndexSpy2.count(), 1); | ||||
//should leave set1, bar0 | ||||
seriesSpyArg = seriesSpy.takeFirst(); | ||||
QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); | ||||
QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); | ||||
QVERIFY(seriesSpyArg.at(0).toBool() == false); | ||||
seriesIndexSpyArg = seriesIndexSpy.takeFirst(); | ||||
QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1); | ||||
QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool); | ||||
QVERIFY(seriesIndexSpyArg.at(0).toBool() == false); | ||||
QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int); | ||||
QVERIFY(seriesIndexSpyArg.at(1).toInt() == 0); | ||||
setIndexSpyArg = setIndexSpy1.takeFirst(); | ||||
QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool); | ||||
QVERIFY(setIndexSpyArg.at(0).toBool() == false); | ||||
QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int); | ||||
QVERIFY(setIndexSpyArg.at(1).toInt() == 0); | ||||
//should enter set2, bar0 | ||||
seriesSpyArg = seriesSpy.takeFirst(); | ||||
QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); | ||||
QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); | ||||
QVERIFY(seriesSpyArg.at(0).toBool() == true); | ||||
seriesIndexSpyArg = seriesIndexSpy.takeFirst(); | ||||
QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2); | ||||
QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool); | ||||
QVERIFY(seriesIndexSpyArg.at(0).toBool() == true); | ||||
QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int); | ||||
QVERIFY(seriesIndexSpyArg.at(1).toInt() == 0); | ||||
setIndexSpyArg = setIndexSpy2.takeFirst(); | ||||
QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool); | ||||
QVERIFY(setIndexSpyArg.at(0).toBool() == true); | ||||
QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int); | ||||
QVERIFY(setIndexSpyArg.at(1).toInt() == 0); | ||||
//======================================================================= | ||||
// move mouse on top of set1, bar1 to check the index (hover out set2, | ||||
// hover in set1) | ||||
QTest::mouseMove(view.viewport(), layout.at(2).center().toPoint()); | ||||
TRY_COMPARE(seriesSpy.count(), 2); | ||||
TRY_COMPARE(seriesIndexSpy.count(), 2); | ||||
TRY_COMPARE(setIndexSpy1.count(), 1); | ||||
TRY_COMPARE(setIndexSpy2.count(), 1); | ||||
//should leave set2, bar0 | ||||
seriesSpyArg = seriesSpy.takeFirst(); | ||||
QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); | ||||
QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); | ||||
QVERIFY(seriesSpyArg.at(0).toBool() == false); | ||||
seriesIndexSpyArg = seriesIndexSpy.takeFirst(); | ||||
QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2); | ||||
QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool); | ||||
QVERIFY(seriesIndexSpyArg.at(0).toBool() == false); | ||||
QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int); | ||||
QVERIFY(seriesIndexSpyArg.at(1).toInt() == 0); | ||||
setIndexSpyArg = setIndexSpy2.takeFirst(); | ||||
QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool); | ||||
QVERIFY(setIndexSpyArg.at(0).toBool() == false); | ||||
QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int); | ||||
QVERIFY(setIndexSpyArg.at(1).toInt() == 0); | ||||
//should enter set1, bar1 | ||||
seriesSpyArg = seriesSpy.takeFirst(); | ||||
QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); | ||||
QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); | ||||
QVERIFY(seriesSpyArg.at(0).toBool() == true); | ||||
seriesIndexSpyArg = seriesIndexSpy.takeFirst(); | ||||
QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1); | ||||
QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool); | ||||
QVERIFY(seriesIndexSpyArg.at(0).toBool() == true); | ||||
QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int); | ||||
QVERIFY(seriesIndexSpyArg.at(1).toInt() == 1); | ||||
setIndexSpyArg = setIndexSpy1.takeFirst(); | ||||
QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool); | ||||
QVERIFY(setIndexSpyArg.at(0).toBool() == true); | ||||
QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int); | ||||
QVERIFY(setIndexSpyArg.at(1).toInt() == 1); | ||||
//======================================================================= | ||||
// move mouse between set1 and set2 (hover out set1) | ||||
QTest::mouseMove(view.viewport(), QPoint((layout.at(3).right() + layout.at(4).left()) /2, | ||||
layout.at(2).top())); | ||||
QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | ||||
TRY_COMPARE(seriesSpy.count(), 1); | ||||
TRY_COMPARE(seriesIndexSpy.count(), 1); | ||||
TRY_COMPARE(setIndexSpy1.count(), 1); | ||||
TRY_COMPARE(setIndexSpy2.count(), 0); | ||||
//should leave set1, bar1 | ||||
seriesSpyArg = seriesSpy.takeFirst(); | ||||
QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); | ||||
QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); | ||||
QVERIFY(seriesSpyArg.at(0).toBool() == false); | ||||
seriesIndexSpyArg = seriesIndexSpy.takeFirst(); | ||||
QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set1); | ||||
QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool); | ||||
QVERIFY(seriesIndexSpyArg.at(0).toBool() == false); | ||||
QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int); | ||||
QVERIFY(seriesIndexSpyArg.at(1).toInt() == 1); | ||||
setIndexSpyArg = setIndexSpy1.takeFirst(); | ||||
QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool); | ||||
QVERIFY(setIndexSpyArg.at(0).toBool() == false); | ||||
QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int); | ||||
QVERIFY(setIndexSpyArg.at(1).toInt() == 1); | ||||
//======================================================================= | ||||
// move mouse on top of set2, bar1 to check the index (hover in set2) | ||||
QTest::mouseMove(view.viewport(), layout.at(3).center().toPoint()); | ||||
TRY_COMPARE(seriesSpy.count(), 1); | ||||
TRY_COMPARE(seriesIndexSpy.count(), 1); | ||||
TRY_COMPARE(setIndexSpy1.count(), 0); | ||||
TRY_COMPARE(setIndexSpy2.count(), 1); | ||||
//should enter set2, bar1 | ||||
seriesSpyArg = seriesSpy.takeFirst(); | ||||
QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); | ||||
QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); | ||||
QVERIFY(seriesSpyArg.at(0).toBool() == true); | ||||
seriesIndexSpyArg = seriesIndexSpy.takeFirst(); | ||||
QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2); | ||||
QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool); | ||||
QVERIFY(seriesIndexSpyArg.at(0).toBool() == true); | ||||
QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int); | ||||
QVERIFY(seriesIndexSpyArg.at(1).toInt() == 1); | ||||
setIndexSpyArg = setIndexSpy2.takeFirst(); | ||||
QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool); | ||||
QVERIFY(setIndexSpyArg.at(0).toBool() == true); | ||||
QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int); | ||||
QVERIFY(setIndexSpyArg.at(1).toInt() == 1); | ||||
//======================================================================= | ||||
// move mouse between set1 and set2 (hover out set2) | ||||
QTest::mouseMove(view.viewport(), QPoint((layout.at(3).right() + layout.at(4).left()) /2, | ||||
layout.at(2).top())); | ||||
QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | ||||
TRY_COMPARE(seriesSpy.count(), 1); | ||||
TRY_COMPARE(seriesIndexSpy.count(), 1); | ||||
TRY_COMPARE(setIndexSpy1.count(), 0); | ||||
TRY_COMPARE(setIndexSpy2.count(), 1); | ||||
//should leave set1, bar1 | ||||
seriesSpyArg = seriesSpy.takeFirst(); | ||||
QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); | ||||
QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); | ||||
QVERIFY(seriesSpyArg.at(0).toBool() == false); | ||||
seriesIndexSpyArg = seriesIndexSpy.takeFirst(); | ||||
QCOMPARE(qvariant_cast<QBarSet*>(seriesIndexSpyArg.at(2)), set2); | ||||
QVERIFY(seriesIndexSpyArg.at(0).type() == QVariant::Bool); | ||||
QVERIFY(seriesIndexSpyArg.at(0).toBool() == false); | ||||
QVERIFY(seriesIndexSpyArg.at(1).type() == QVariant::Int); | ||||
QVERIFY(seriesIndexSpyArg.at(1).toInt() == 1); | ||||
setIndexSpyArg = setIndexSpy2.takeFirst(); | ||||
QVERIFY(setIndexSpyArg.at(0).type() == QVariant::Bool); | ||||
QVERIFY(setIndexSpyArg.at(0).toBool() == false); | ||||
QVERIFY(setIndexSpyArg.at(1).type() == QVariant::Int); | ||||
QVERIFY(setIndexSpyArg.at(1).toInt() == 1); | ||||
|
r1146 | } | ||
|
r1116 | QTEST_MAIN(tst_QPercentBarSeries) | ||
#include "tst_qpercentbarseries.moc" | ||||