MCPcopy Create free account
hub / github.com/KDE/labplot / customTextLabels

Method customTextLabels

tests/backend/Axis/AxisTest2.cpp:496–553  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

494}
495
496void AxisTest2::customTextLabels() {
497 QLocale::setDefault(QLocale::C); // . as decimal separator
498 Project project;
499 auto* ws = new Worksheet(QStringLiteral("worksheet"));
500 QVERIFY(ws != nullptr);
501 project.addChild(ws);
502
503 Spreadsheet* spreadsheetData = new Spreadsheet(QStringLiteral("data"), false);
504 spreadsheetData->setColumnCount(2);
505 spreadsheetData->setRowCount(3);
506 project.addChild(spreadsheetData);
507
508 auto* xCol = spreadsheetData->column(0);
509 xCol->replaceValues(0, QVector<double>({1, 2, 3}));
510
511 auto* yCol = spreadsheetData->column(1);
512 yCol->replaceValues(0, QVector<double>({2, 3, 4}));
513
514 QCOMPARE(spreadsheetData->rowCount(), 3);
515 QCOMPARE(spreadsheetData->columnCount(), 2);
516
517 Spreadsheet* spreadsheetLabels = new Spreadsheet(QStringLiteral("data"), false);
518 spreadsheetLabels->setColumnCount(1);
519 spreadsheetLabels->setRowCount(3);
520 project.addChild(spreadsheetLabels);
521 auto* labelsCol = spreadsheetLabels->column(0);
522 labelsCol->setColumnMode(AbstractColumn::ColumnMode::Text);
523 labelsCol->replaceTexts(-1, QVector<QString>({QStringLiteral("A"), QStringLiteral("B"), QStringLiteral("C")}));
524
525 auto* p = new CartesianPlot(QStringLiteral("plot"));
526 p->setType(CartesianPlot::Type::TwoAxes); // Otherwise no axis are created
527 QVERIFY(p != nullptr);
528 ws->addChild(p);
529
530 auto* curve = new XYCurve(QStringLiteral("xy-curve"));
531 curve->setXColumn(xCol);
532 curve->setYColumn(yCol);
533 p->addChild(curve);
534
535 auto axes = p->children<Axis>();
536 QCOMPARE(axes.count(), 2);
537 QCOMPARE(axes.at(0)->name(), QStringLiteral("x"));
538 QCOMPARE(axes.at(1)->name(), QStringLiteral("y"));
539
540 auto* xAxis = static_cast<Axis*>(axes.at(0));
541 xAxis->setMajorTicksNumber(3, false);
542 xAxis->setLabelsTextType(Axis::LabelsTextType::CustomValues);
543 xAxis->setLabelsTextColumn(labelsCol);
544
545 {
546 QStringList expectedStrings{
547 QStringLiteral("A"),
548 QStringLiteral("B"),
549 QStringLiteral("C"),
550 };
551 COMPARE_STRING_VECTORS(xAxis->tickLabelStrings(), expectedStrings);
552 }
553}

Callers

nothing calls this directly

Calls 15

setYColumnMethod · 0.80
setMajorTicksNumberMethod · 0.80
setLabelsTextTypeMethod · 0.80
setLabelsTextColumnMethod · 0.80
tickLabelStringsMethod · 0.80
addChildMethod · 0.45
setColumnCountMethod · 0.45
setRowCountMethod · 0.45
columnMethod · 0.45
replaceValuesMethod · 0.45
rowCountMethod · 0.45
columnCountMethod · 0.45

Tested by

no test coverage detected