| 642 | } |
| 643 | |
| 644 | void RetransformTest::TestAddCurve() { |
| 645 | Project project; |
| 646 | auto* ws = new Worksheet(QStringLiteral("Worksheet")); |
| 647 | QVERIFY(ws != nullptr); |
| 648 | project.addChild(ws); |
| 649 | |
| 650 | auto* p = new CartesianPlot(QStringLiteral("plot")); |
| 651 | p->setType(CartesianPlot::Type::TwoAxes); // Otherwise no axis are created |
| 652 | QVERIFY(p != nullptr); |
| 653 | ws->addChild(p); |
| 654 | |
| 655 | RetransformCallCounter c; |
| 656 | |
| 657 | p->addChild(new XYEquationCurve(QLatin1String("curve"))); |
| 658 | |
| 659 | // check that plot will be recalculated if a curve will be added |
| 660 | QCOMPARE(c.callCount(p), 1); |
| 661 | |
| 662 | auto children = project.children(AspectType::AbstractAspect, AbstractAspect::ChildIndexFlag::Recursive); |
| 663 | |
| 664 | // Project/Worksheet |
| 665 | // Project/Worksheet/plot |
| 666 | // Project/Worksheet/plot/x |
| 667 | // Project/Worksheet/plot/y |
| 668 | // Project/Worksheet/plot/f(x) // equation curve |
| 669 | QCOMPARE(children.length(), 5); |
| 670 | for (const auto& child : children) |
| 671 | connect(child, &AbstractAspect::retransformCalledSignal, &c, &RetransformCallCounter::aspectRetransformed); |
| 672 | |
| 673 | for (const auto& plot : project.children(AspectType::CartesianPlot, AbstractAspect::ChildIndexFlag::Recursive)) |
| 674 | connect(static_cast<CartesianPlot*>(plot), &CartesianPlot::scaleRetransformed, &c, &RetransformCallCounter::retransformScaleCalled); |
| 675 | |
| 676 | c.resetRetransformCount(); |
| 677 | |
| 678 | auto equationCurves = p->children(AspectType::XYEquationCurve); |
| 679 | QCOMPARE(equationCurves.count(), 1); |
| 680 | auto* equationCurve = static_cast<XYEquationCurve*>(equationCurves.at(0)); |
| 681 | XYEquationCurve::EquationData data; |
| 682 | data.count = 100; |
| 683 | data.expression1 = QStringLiteral("x"); |
| 684 | data.expression2 = QString(); |
| 685 | data.min = QStringLiteral("0"); |
| 686 | data.max = QStringLiteral("10"); |
| 687 | data.type = XYEquationCurve::EquationType::Cartesian; |
| 688 | equationCurve->setEquationData(data); |
| 689 | |
| 690 | auto list = QStringList({i18n("Project") + QStringLiteral("/Worksheet/plot/x"), |
| 691 | i18n("Project") + QStringLiteral("/Worksheet/plot/y"), |
| 692 | i18n("Project") + QStringLiteral("/Worksheet/plot/f(x)")}); |
| 693 | QCOMPARE(c.elementLogCount(false), list.count()); |
| 694 | QCOMPARE(c.callCount(list.at(0)), 1); |
| 695 | QCOMPARE(c.callCount(list.at(1)), 1); |
| 696 | QCOMPARE(c.callCount(list.at(2)), 0); |
| 697 | |
| 698 | // x and y are called only once |
| 699 | QCOMPARE(c.logsXScaleRetransformed.count(), 1); |
| 700 | QCOMPARE(c.logsXScaleRetransformed.at(0).plot, p); |
| 701 | QCOMPARE(c.logsXScaleRetransformed.at(0).index, 0); |
nothing calls this directly
no test coverage detected