| 822 | } |
| 823 | |
| 824 | void RetransformTest::TestImportCSV() { |
| 825 | Project project; |
| 826 | auto* ws = new Worksheet(QStringLiteral("Worksheet")); |
| 827 | QVERIFY(ws != nullptr); |
| 828 | project.addChild(ws); |
| 829 | |
| 830 | Spreadsheet* spreadsheet = new Spreadsheet(QStringLiteral("test"), false); |
| 831 | spreadsheet->setColumnCount(2); |
| 832 | spreadsheet->setRowCount(3); |
| 833 | |
| 834 | auto* xCol = spreadsheet->column(0); |
| 835 | xCol->replaceValues(0, QVector<double>({1, 2, 3})); |
| 836 | |
| 837 | auto* yCol = spreadsheet->column(1); |
| 838 | yCol->replaceValues(0, QVector<double>({2, 3, 4})); |
| 839 | |
| 840 | QCOMPARE(spreadsheet->rowCount(), 3); |
| 841 | QCOMPARE(spreadsheet->columnCount(), 2); |
| 842 | |
| 843 | project.addChild(spreadsheet); |
| 844 | auto* p = new CartesianPlot(QStringLiteral("plot")); |
| 845 | p->setType(CartesianPlot::Type::TwoAxes); // Otherwise no axis are created |
| 846 | QVERIFY(p != nullptr); |
| 847 | ws->addChild(p); |
| 848 | |
| 849 | auto* curve = new XYCurve(QStringLiteral("xy-curve")); |
| 850 | curve->setXColumn(xCol); |
| 851 | curve->setYColumn(yCol); |
| 852 | p->addChild(curve); |
| 853 | |
| 854 | auto children = project.children(AspectType::AbstractAspect, AbstractAspect::ChildIndexFlag::Recursive); |
| 855 | |
| 856 | RetransformCallCounter c; |
| 857 | // Worksheet "Worksheet" |
| 858 | // CartesianPlot "plot" |
| 859 | // Axis "x" |
| 860 | // Axis "y" |
| 861 | // XYCurve "xy-curve" |
| 862 | // Spreadsheet "test" |
| 863 | // Column "1" |
| 864 | // Column "2" |
| 865 | QCOMPARE(children.length(), 8); |
| 866 | for (const auto& child : children) { |
| 867 | qDebug() << child->name(); |
| 868 | connect(child, &AbstractAspect::retransformCalledSignal, &c, &RetransformCallCounter::aspectRetransformed); |
| 869 | } |
| 870 | |
| 871 | for (const auto& plot : project.children(AspectType::CartesianPlot, AbstractAspect::ChildIndexFlag::Recursive)) |
| 872 | connect(static_cast<CartesianPlot*>(plot), &CartesianPlot::scaleRetransformed, &c, &RetransformCallCounter::retransformScaleCalled); |
| 873 | |
| 874 | // check axis ranges |
| 875 | auto axes = p->children(AspectType::Axis, AbstractAspect::ChildIndexFlag::Recursive); |
| 876 | QCOMPARE(axes.length(), 2); |
| 877 | auto* xAxis = axes.at(0); |
| 878 | QVector<double> ref = {1, 1.5, 2, 2.5, 3}; |
| 879 | COMPARE_DOUBLE_VECTORS(static_cast<Axis*>(xAxis)->tickLabelValues(), ref); |
| 880 | auto* yAxis = axes.at(1); |
| 881 | ref = {2, 2.5, 3, 3.5, 4}; |
nothing calls this directly
no test coverage detected