! * \brief AxisTest3::customColumnNumeric * Test setting a custom column as major tick once with the custom column values and * once with another column as ticks label */
| 553 | * once with another column as ticks label |
| 554 | */ |
| 555 | void AxisTest3::customColumnNumeric() { |
| 556 | Project project; |
| 557 | auto* ws = new Worksheet(QStringLiteral("worksheet")); |
| 558 | QVERIFY(ws != nullptr); |
| 559 | project.addChild(ws); |
| 560 | ws->setPageRect(QRectF(0, 0, 300, 300)); |
| 561 | ws->setLayoutBottomMargin(0); |
| 562 | ws->setLayoutTopMargin(0); |
| 563 | ws->setLayoutRightMargin(0); |
| 564 | ws->setLayoutLeftMargin(0); |
| 565 | |
| 566 | Spreadsheet* spreadsheetData = new Spreadsheet(QStringLiteral("data"), false); |
| 567 | spreadsheetData->setColumnCount(2); |
| 568 | spreadsheetData->setRowCount(3); |
| 569 | project.addChild(spreadsheetData); |
| 570 | auto* xCol = spreadsheetData->column(0); |
| 571 | xCol->setColumnMode(AbstractColumn::ColumnMode::Double); |
| 572 | xCol->replaceValues(-1, QVector<double>({1., 2., 5.})); |
| 573 | auto* yCol = spreadsheetData->column(1); |
| 574 | yCol->replaceValues(-1, QVector<double>({2., 3., 4.})); |
| 575 | |
| 576 | Spreadsheet* spreadsheetLabels = new Spreadsheet(QStringLiteral("labels"), false); |
| 577 | spreadsheetLabels->setColumnCount(2); |
| 578 | spreadsheetLabels->setRowCount(3); |
| 579 | project.addChild(spreadsheetLabels); |
| 580 | auto* posCol = spreadsheetLabels->column(0); |
| 581 | posCol->setColumnMode(AbstractColumn::ColumnMode::Double); |
| 582 | posCol->replaceValues(-1, QVector<double>({1.7, 2.2, 2.5})); |
| 583 | auto* labelsCol = spreadsheetLabels->column(1); |
| 584 | labelsCol->setColumnMode(AbstractColumn::ColumnMode::Text); |
| 585 | labelsCol->replaceTexts(-1, QVector<QString>({QStringLiteral("first"), QStringLiteral("second"), QStringLiteral("third")})); |
| 586 | |
| 587 | auto* p = new CartesianPlot(QStringLiteral("plot")); |
| 588 | p->setType(CartesianPlot::Type::TwoAxes); // Otherwise no axes are created |
| 589 | p->setNiceExtend(false); |
| 590 | QVERIFY(p != nullptr); |
| 591 | p->setBottomPadding(0); |
| 592 | p->setHorizontalPadding(0); |
| 593 | p->setRightPadding(0); |
| 594 | p->setVerticalPadding(0); |
| 595 | ws->addChild(p); |
| 596 | |
| 597 | auto* curve = new XYCurve(QStringLiteral("xy-curve")); |
| 598 | curve->setXColumn(xCol); |
| 599 | curve->setYColumn(yCol); |
| 600 | p->addChild(curve); |
| 601 | |
| 602 | auto axes = p->children<Axis>(); |
| 603 | QCOMPARE(axes.count(), 2); |
| 604 | QCOMPARE(axes.at(0)->name(), QStringLiteral("x")); |
| 605 | QCOMPARE(axes.at(1)->name(), QStringLiteral("y")); |
| 606 | |
| 607 | auto* xAxis = static_cast<Axis*>(axes.at(0)); |
| 608 | QCOMPARE(xAxis->range().start(), 1.); |
| 609 | QCOMPARE(xAxis->range().end(), 5.); |
| 610 | xAxis->setMajorTicksType(Axis::TicksType::CustomColumn); |
| 611 | xAxis->setMajorTicksColumn(posCol); |
| 612 | QCOMPARE(xAxis->labelsTextType(), Axis::LabelsTextType::PositionValues); |
nothing calls this directly
no test coverage detected