##// END OF EJS Templates
Fix animation artifact with boxplots....
Fix animation artifact with boxplots. Also rename m_moveMedianLine to m_changeAnimation to clarify things. Change-Id: I342434c479a9a8cac3a2eed3dafa5692b3c30f72 Reviewed-by: Mika Salmela <mika.salmela@digia.com>

File last commit:

r2433:4d17a12f375e
r2564:b874ab753024
Show More
tst_qstackedbarseries.cpp
351 lines | 11.6 KiB | text/x-c | CppLexer
/ tests / auto / qstackedbarseries / tst_qstackedbarseries.cpp
sauimone
stacked and percent bar unit tests
r1116 /****************************************************************************
**
Miikka Heikkinen
More copyright year changes
r2433 ** Copyright (C) 2013 Digia Plc
sauimone
stacked and percent bar unit tests
r1116 ** 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>
sauimone
mouse click test cases for barcharts. Fixed found error
r1145 #include <qchartview.h>
#include <qchart.h>
Jani Honkonen
autotests: try to fix bar hover failures in bamboo
r1466 #include "tst_definitions.h"
sauimone
stacked and percent bar unit tests
r1116
QTCOMMERCIALCHART_USE_NAMESPACE
sauimone
mouse click test cases for barcharts. Fixed found error
r1145 Q_DECLARE_METATYPE(QBarSet*)
sauimone
stacked and percent bar unit tests
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();
sauimone
mouse hover test cases for barcharts
r1146 void mouseclicked_data();
void mouseclicked();
void mousehovered_data();
void mousehovered();
sauimone
stacked and percent bar unit tests
r1116
private:
QStackedBarSeries* m_barseries;
};
void tst_QStackedBarSeries::initTestCase()
{
sauimone
mouse click test cases for barcharts. Fixed found error
r1145 qRegisterMetaType<QBarSet*>("QBarSet*");
sauimone
stacked and percent bar unit tests
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);
}
sauimone
mouse hover test cases for barcharts
r1146 void tst_QStackedBarSeries::mouseclicked_data()
sauimone
mouse click test cases for barcharts. Fixed found error
r1145 {
}
sauimone
mouse hover test cases for barcharts
r1146 void tst_QStackedBarSeries::mouseclicked()
sauimone
mouse click test cases for barcharts. Fixed found error
r1145 {
sauimone
added SKIP_IF_CANNOT_TEST_MOUSE_EVENTS macro to barseries tests
r2066 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
sauimone
mouse click test cases for barcharts. Fixed found error
r1145 QStackedBarSeries* series = new QStackedBarSeries();
QBarSet* set1 = new QBarSet(QString("set 1"));
*set1 << 10 << 10 << 10;
sauimone
Renamed appendBarSet to append, removeBarSet to remove
r1194 series->append(set1);
sauimone
mouse click test cases for barcharts. Fixed found error
r1145
QBarSet* set2 = new QBarSet(QString("set 2"));
*set2 << 10 << 10 << 10;
sauimone
Renamed appendBarSet to append, removeBarSet to remove
r1194 series->append(set2);
sauimone
mouse click test cases for barcharts. Fixed found error
r1145
sauimone
bar test update. Tests now calculate expected layout from charts plot area and use that instead of precalculated QPointF magic numbers
r2073 QList<QBarSet*> barSets = series->barSets();
Jani Honkonen
normalize signal/slot signatures
r2110 QSignalSpy seriesSpy(series,SIGNAL(clicked(int,QBarSet*)));
sauimone
mouse click test cases for barcharts. Fixed found error
r1145
QChartView view(new QChart());
view.resize(400,300);
view.chart()->addSeries(series);
view.show();
QTest::qWaitForWindowShown(&view);
sauimone
bar test update. Tests now calculate expected layout from charts plot area and use that instead of precalculated QPointF magic numbers
r2073 // Calculate expected layout for bars
QRectF plotArea = view.chart()->plotArea();
qreal width = plotArea.width();
qreal height = plotArea.height();
qreal rangeY = 20; // From 0 to 20 because sets are stacked (this should be height of highest stack)
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 yMax = height + scaleY * domainMinY + plotArea.top();
qreal yMin = 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) * scaleY;
if (rectHeight < 0) {
QRectF rect(xPos, yMax-rectHeight, rectWidth, rectHeight);
layout.append(rect);
yMax -= rectHeight;
} else {
QRectF rect(xPos, yMin-rectHeight, rectWidth, rectHeight);
layout.append(rect);
yMin -= rectHeight;
}
}
}
sauimone
mouse click test cases for barcharts. Fixed found error
r1145 //====================================================================================
sauimone
bar test update. Tests now calculate expected layout from charts plot area and use that instead of precalculated QPointF magic numbers
r2073 // barset 1, bar 0
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(0).center().toPoint());
sauimone
mouse click test cases for barcharts. Fixed found error
r1145 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
QCOMPARE(seriesSpy.count(), 1);
QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
sauimone
removed double signal emitting from barseries/set
r1563 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
QVERIFY(seriesSpyArg.at(0).toInt() == 0);
sauimone
mouse click test cases for barcharts. Fixed found error
r1145
//====================================================================================
sauimone
bar test update. Tests now calculate expected layout from charts plot area and use that instead of precalculated QPointF magic numbers
r2073 // barset 1, bar 1
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(2).center().toPoint());
sauimone
mouse click test cases for barcharts. Fixed found error
r1145 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
QCOMPARE(seriesSpy.count(), 1);
seriesSpyArg = seriesSpy.takeFirst();
sauimone
removed double signal emitting from barseries/set
r1563 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
QVERIFY(seriesSpyArg.at(0).toInt() == 1);
sauimone
mouse click test cases for barcharts. Fixed found error
r1145
//====================================================================================
sauimone
bar test update. Tests now calculate expected layout from charts plot area and use that instead of precalculated QPointF magic numbers
r2073 // barset 1, bar 2
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(4).center().toPoint());
sauimone
mouse click test cases for barcharts. Fixed found error
r1145 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
QCOMPARE(seriesSpy.count(), 1);
seriesSpyArg = seriesSpy.takeFirst();
sauimone
removed double signal emitting from barseries/set
r1563 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
QVERIFY(seriesSpyArg.at(0).toInt() == 2);
sauimone
mouse click test cases for barcharts. Fixed found error
r1145
//====================================================================================
sauimone
bar test update. Tests now calculate expected layout from charts plot area and use that instead of precalculated QPointF magic numbers
r2073 // barset 2, bar 0
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(1).center().toPoint());
sauimone
mouse click test cases for barcharts. Fixed found error
r1145 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
QCOMPARE(seriesSpy.count(), 1);
seriesSpyArg = seriesSpy.takeFirst();
sauimone
removed double signal emitting from barseries/set
r1563 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
QVERIFY(seriesSpyArg.at(0).toInt() == 0);
sauimone
mouse click test cases for barcharts. Fixed found error
r1145
//====================================================================================
sauimone
bar test update. Tests now calculate expected layout from charts plot area and use that instead of precalculated QPointF magic numbers
r2073 // barset 2, bar 1
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(3).center().toPoint());
sauimone
mouse click test cases for barcharts. Fixed found error
r1145 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
QCOMPARE(seriesSpy.count(), 1);
seriesSpyArg = seriesSpy.takeFirst();
sauimone
removed double signal emitting from barseries/set
r1563 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
QVERIFY(seriesSpyArg.at(0).toInt() == 1);
sauimone
mouse click test cases for barcharts. Fixed found error
r1145
//====================================================================================
sauimone
bar test update. Tests now calculate expected layout from charts plot area and use that instead of precalculated QPointF magic numbers
r2073 // barset 2, bar 2
QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(5).center().toPoint());
sauimone
mouse click test cases for barcharts. Fixed found error
r1145 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
QCOMPARE(seriesSpy.count(), 1);
seriesSpyArg = seriesSpy.takeFirst();
sauimone
removed double signal emitting from barseries/set
r1563 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
QVERIFY(seriesSpyArg.at(0).toInt() == 2);
sauimone
mouse click test cases for barcharts. Fixed found error
r1145 }
sauimone
mouse hover test cases for barcharts
r1146 void tst_QStackedBarSeries::mousehovered_data()
{
}
void tst_QStackedBarSeries::mousehovered()
{
sauimone
added SKIP_IF_CANNOT_TEST_MOUSE_EVENTS macro to barseries tests
r2066 SKIP_IF_CANNOT_TEST_MOUSE_EVENTS();
sauimone
mouse hover test cases for barcharts
r1146 QStackedBarSeries* series = new QStackedBarSeries();
QBarSet* set1 = new QBarSet(QString("set 1"));
*set1 << 10 << 10 << 10;
sauimone
Renamed appendBarSet to append, removeBarSet to remove
r1194 series->append(set1);
sauimone
mouse hover test cases for barcharts
r1146
QBarSet* set2 = new QBarSet(QString("set 2"));
*set2 << 10 << 10 << 10;
sauimone
Renamed appendBarSet to append, removeBarSet to remove
r1194 series->append(set2);
sauimone
mouse hover test cases for barcharts
r1146
sauimone
bar test update. Tests now calculate expected layout from charts plot area and use that instead of precalculated QPointF magic numbers
r2073 QList<QBarSet*> barSets = series->barSets();
Jani Honkonen
normalize signal/slot signatures
r2110 QSignalSpy seriesSpy(series,SIGNAL(hovered(bool,QBarSet*)));
sauimone
mouse hover test cases for barcharts
r1146
QChartView view(new QChart());
view.resize(400,300);
view.chart()->addSeries(series);
view.show();
QTest::qWaitForWindowShown(&view);
sauimone
barseries autotest update
r1287 //this is hack since view does not get events otherwise
view.setMouseTracking(true);
sauimone
bar test update. Tests now calculate expected layout from charts plot area and use that instead of precalculated QPointF magic numbers
r2073 // Calculate expected layout for bars
QRectF plotArea = view.chart()->plotArea();
qreal width = plotArea.width();
qreal height = plotArea.height();
qreal rangeY = 20; // From 0 to 20 because sets are stacked (this should be height of highest stack)
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 yMax = height + scaleY * domainMinY + plotArea.top();
qreal yMin = 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) * scaleY;
if (rectHeight < 0) {
QRectF rect(xPos, yMax-rectHeight, rectWidth, rectHeight);
layout.append(rect);
yMax -= rectHeight;
} else {
QRectF rect(xPos, yMin-rectHeight, rectWidth, rectHeight);
layout.append(rect);
yMin -= rectHeight;
}
}
}
sauimone
mouse hover test cases for barcharts
r1146 //=======================================================================
// move mouse to left border
sauimone
bar test update. Tests now calculate expected layout from charts plot area and use that instead of precalculated QPointF magic numbers
r2073 QTest::mouseMove(view.viewport(), QPoint(0, layout.at(0).center().y()));
Jani Honkonen
autotests: try to fix bar hover failures in bamboo
r1466 QCoreApplication::processEvents(QEventLoop::AllEvents, 10000);
TRY_COMPARE(seriesSpy.count(), 0);
sauimone
mouse hover test cases for barcharts
r1146
//=======================================================================
// move mouse on top of set1
sauimone
bar test update. Tests now calculate expected layout from charts plot area and use that instead of precalculated QPointF magic numbers
r2073 QTest::mouseMove(view.viewport(), layout.at(0).center().toPoint());
Jani Honkonen
autotests: try to fix bar hover failures in bamboo
r1466 TRY_COMPARE(seriesSpy.count(), 1);
sauimone
mouse hover test cases for barcharts
r1146
QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
sauimone
removed double signal emitting from barseries/set
r1563 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
QVERIFY(seriesSpyArg.at(0).toBool() == true);
sauimone
mouse hover test cases for barcharts
r1146
//=======================================================================
// move mouse from top of set1 to top of set2
sauimone
bar test update. Tests now calculate expected layout from charts plot area and use that instead of precalculated QPointF magic numbers
r2073 QTest::mouseMove(view.viewport(), layout.at(1).center().toPoint());
Jani Honkonen
autotests: try to fix bar hover failures in bamboo
r1466 TRY_COMPARE(seriesSpy.count(), 2);
sauimone
mouse hover test cases for barcharts
r1146
// should leave set1
seriesSpyArg = seriesSpy.takeFirst();
sauimone
removed double signal emitting from barseries/set
r1563 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
QVERIFY(seriesSpyArg.at(0).toBool() == false);
sauimone
mouse hover test cases for barcharts
r1146
// should enter set2
seriesSpyArg = seriesSpy.takeFirst();
sauimone
removed double signal emitting from barseries/set
r1563 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
QVERIFY(seriesSpyArg.at(0).toBool() == true);
sauimone
mouse hover test cases for barcharts
r1146
//=======================================================================
// move mouse from top of set2 to background
sauimone
bar test update. Tests now calculate expected layout from charts plot area and use that instead of precalculated QPointF magic numbers
r2073 QTest::mouseMove(view.viewport(), QPoint(layout.at(1).center().x(), 0));
Jani Honkonen
autotests: try to fix bar hover failures in bamboo
r1466 TRY_COMPARE(seriesSpy.count(), 1);
sauimone
mouse hover test cases for barcharts
r1146
sauimone
barseries autotest update
r1287 // should leave set2
sauimone
mouse hover test cases for barcharts
r1146 seriesSpyArg = seriesSpy.takeFirst();
sauimone
removed double signal emitting from barseries/set
r1563 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
QVERIFY(seriesSpyArg.at(0).toBool() == false);
sauimone
mouse hover test cases for barcharts
r1146 }
sauimone
stacked and percent bar unit tests
r1116 QTEST_MAIN(tst_QStackedBarSeries)
#include "tst_qstackedbarseries.moc"