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

Method tickLabelRepresentationAutomatic

tests/backend/Axis/AxisTest.cpp:501–563  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

499}
500
501void AxisTest::tickLabelRepresentationAutomatic() {
502 QLocale::setDefault(QLocale::C); // . as decimal separator
503 Project project;
504 auto* ws = new Worksheet(QStringLiteral("worksheet"));
505 QVERIFY(ws != nullptr);
506 project.addChild(ws);
507
508 auto* p = new CartesianPlot(QStringLiteral("plot"));
509 QVERIFY(p != nullptr);
510 p->setType(CartesianPlot::Type::TwoAxes); // Otherwise no axis are created
511 ws->addChild(p);
512
513 auto axes = p->children<Axis>();
514 QCOMPARE(axes.count(), 2);
515 QCOMPARE(axes.at(0)->name(), QStringLiteral("x"));
516 QCOMPARE(axes.at(1)->name(), QStringLiteral("y"));
517 auto* yAxis = static_cast<Axis*>(axes.at(1));
518
519 AxisDock dock(nullptr);
520 dock.setAxes({yAxis});
521
522 QCOMPARE(dock.ui.chkLabelsFormatAuto->isChecked(), true);
523 QCOMPARE(dock.ui.cbLabelsFormat->isEnabled(), false);
524
525 {
526 QCOMPARE(yAxis->labelsFormat(), Axis::LabelsFormat::Decimal);
527 QStringList expectedStrings{QStringLiteral("0.0"),
528 QStringLiteral("0.2"),
529 QStringLiteral("0.4"),
530 QStringLiteral("0.6"),
531 QStringLiteral("0.8"),
532 QStringLiteral("1.0")};
533 COMPARE_STRING_VECTORS(yAxis->tickLabelStrings(), expectedStrings);
534 }
535
536 p->setRangeDefault(Dimension::Y, Range<double>(0, 1e6));
537
538 {
539 QCOMPARE(yAxis->labelsFormat(), Axis::LabelsFormat::Scientific);
540 QStringList expectedStrings{
541 QStringLiteral("0"),
542 AxisPrivate::createScientificRepresentation(QStringLiteral("2"), QStringLiteral("5")),
543 AxisPrivate::createScientificRepresentation(QStringLiteral("4"), QStringLiteral("5")),
544 AxisPrivate::createScientificRepresentation(QStringLiteral("6"), QStringLiteral("5")),
545 AxisPrivate::createScientificRepresentation(QStringLiteral("8"), QStringLiteral("5")),
546 AxisPrivate::createScientificRepresentation(QStringLiteral("1"), QStringLiteral("6")),
547 };
548 COMPARE_STRING_VECTORS(yAxis->tickLabelStrings(), expectedStrings);
549 }
550
551 p->setRangeDefault(Dimension::Y, Range<double>(0, 1));
552
553 {
554 QCOMPARE(yAxis->labelsFormat(), Axis::LabelsFormat::Decimal);
555 QStringList expectedStrings{QStringLiteral("0.0"),
556 QStringLiteral("0.2"),
557 QStringLiteral("0.4"),
558 QStringLiteral("0.6"),

Callers

nothing calls this directly

Calls 7

tickLabelStringsMethod · 0.80
setRangeDefaultMethod · 0.80
addChildMethod · 0.45
setTypeMethod · 0.45
countMethod · 0.45
nameMethod · 0.45
setAxesMethod · 0.45

Tested by

no test coverage detected