summaryrefslogtreecommitdiffstats
path: root/tests/auto/qpercentbarseries/tst_qpercentbarseries.cpp
diff options
context:
space:
mode:
authorsauimone <samu.uimonen@digia.com>2012-09-17 17:28:54 +0300
committersauimone <samu.uimonen@digia.com>2012-09-17 17:29:22 +0300
commit9c07511ab7b23b737d7f8aeb1dea80d3d1220020 (patch)
treeca79902e359b49edcbef42bb01f6cb21181bd616 /tests/auto/qpercentbarseries/tst_qpercentbarseries.cpp
parent4d4cbd83148b74c8d7d2e010d475d89367128c23 (diff)
bar test update. Tests now calculate expected layout from charts plot area and use that instead of precalculated QPointF magic numbers
Diffstat (limited to 'tests/auto/qpercentbarseries/tst_qpercentbarseries.cpp')
-rw-r--r--tests/auto/qpercentbarseries/tst_qpercentbarseries.cpp102
1 files changed, 86 insertions, 16 deletions
diff --git a/tests/auto/qpercentbarseries/tst_qpercentbarseries.cpp b/tests/auto/qpercentbarseries/tst_qpercentbarseries.cpp
index 792e3d3a..3bc1fc63 100644
--- a/tests/auto/qpercentbarseries/tst_qpercentbarseries.cpp
+++ b/tests/auto/qpercentbarseries/tst_qpercentbarseries.cpp
@@ -112,6 +112,8 @@ void tst_QPercentBarSeries::mouseclicked()
*set2 << 10 << 10 << 10;
series->append(set2);
+ QList<QBarSet*> barSets = series->barSets();
+
QSignalSpy seriesSpy(series,SIGNAL(clicked(int, QBarSet*)));
QChartView view(new QChart());
@@ -120,9 +122,42 @@ void tst_QPercentBarSeries::mouseclicked()
view.show();
QTest::qWaitForWindowShown(&view);
+ // 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;
+ }
+ }
+
//====================================================================================
-// barset 1, category test1
- QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(86,211));
+// barset 1, bar 0
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(0).center().toPoint());
QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
QCOMPARE(seriesSpy.count(), 1);
@@ -133,8 +168,8 @@ void tst_QPercentBarSeries::mouseclicked()
QVERIFY(seriesSpyArg.at(0).toInt() == 0);
//====================================================================================
-// barset 1, category test2
- QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(200,211));
+// barset 1, bar 1
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(2).center().toPoint());
QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
QCOMPARE(seriesSpy.count(), 1);
@@ -145,8 +180,8 @@ void tst_QPercentBarSeries::mouseclicked()
QVERIFY(seriesSpyArg.at(0).toInt() == 1);
//====================================================================================
-// barset 1, category test3
- QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(314,211));
+// barset 1, bar 2
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(4).center().toPoint());
QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
QCOMPARE(seriesSpy.count(), 1);
@@ -157,8 +192,8 @@ void tst_QPercentBarSeries::mouseclicked()
QVERIFY(seriesSpyArg.at(0).toInt() == 2);
//====================================================================================
-// barset 2, category test1
- QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(86,90));
+// barset 2, bar 0
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(1).center().toPoint());
QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
QCOMPARE(seriesSpy.count(), 1);
@@ -169,8 +204,8 @@ void tst_QPercentBarSeries::mouseclicked()
QVERIFY(seriesSpyArg.at(0).toInt() == 0);
//====================================================================================
-// barset 2, category test2
- QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(200,90));
+// barset 2, bar 1
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(3).center().toPoint());
QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
QCOMPARE(seriesSpy.count(), 1);
@@ -181,8 +216,8 @@ void tst_QPercentBarSeries::mouseclicked()
QVERIFY(seriesSpyArg.at(0).toInt() == 1);
//====================================================================================
-// barset 2, category test3
- QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(314,90));
+// barset 2, bar 2
+ QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, layout.at(5).center().toPoint());
QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
QCOMPARE(seriesSpy.count(), 1);
@@ -212,6 +247,8 @@ void tst_QPercentBarSeries::mousehovered()
*set2 << 10 << 10 << 10;
series->append(set2);
+ QList<QBarSet*> barSets = series->barSets();
+
QSignalSpy seriesSpy(series,SIGNAL(hovered(bool, QBarSet*)));
QChartView view(new QChart());
@@ -223,15 +260,48 @@ void tst_QPercentBarSeries::mousehovered()
//this is hack since view does not get events otherwise
view.setMouseTracking(true);
+ // 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;
+ }
+ }
+
//=======================================================================
// move mouse to left border
- QTest::mouseMove(view.viewport(), QPoint(0, 211));
+ QTest::mouseMove(view.viewport(), QPoint(0, layout.at(0).center().y()));
QCoreApplication::processEvents(QEventLoop::AllEvents, 10000);
TRY_COMPARE(seriesSpy.count(), 0);
//=======================================================================
// move mouse on top of set1
- QTest::mouseMove(view.viewport(), QPoint(86,211));
+ QTest::mouseMove(view.viewport(), layout.at(0).center().toPoint());
TRY_COMPARE(seriesSpy.count(), 1);
QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
@@ -241,7 +311,7 @@ void tst_QPercentBarSeries::mousehovered()
//=======================================================================
// move mouse from top of set1 to top of set2
- QTest::mouseMove(view.viewport(), QPoint(86,90));
+ QTest::mouseMove(view.viewport(), layout.at(1).center().toPoint());
TRY_COMPARE(seriesSpy.count(), 2);
// should leave set1
@@ -258,7 +328,7 @@ void tst_QPercentBarSeries::mousehovered()
//=======================================================================
// move mouse from top of set2 to background
- QTest::mouseMove(view.viewport(), QPoint(86,0));
+ QTest::mouseMove(view.viewport(), QPoint(layout.at(1).center().x(), 0));
TRY_COMPARE(seriesSpy.count(), 1);
// should leave set2