File indexing completed on 2024-11-03 09:47:02

0001 /*
0002     File                 : AxisTest.cpp
0003     Project              : LabPlot
0004     Description          : Tests for Axis
0005     --------------------------------------------------------------------
0006     SPDX-FileCopyrightText: 2022 Martin Marmsoler <martin.marmsoler@gmail.com>
0007 
0008     SPDX-License-Identifier: GPL-2.0-or-later
0009 */
0010 
0011 #include "AxisTest.h"
0012 #include "backend/core/Project.h"
0013 #include "backend/spreadsheet/Spreadsheet.h"
0014 #include "backend/worksheet/Worksheet.h"
0015 #include "backend/worksheet/plots/cartesian/CartesianPlot.h"
0016 #include "src/backend/core/Time.h"
0017 #include "src/backend/worksheet/Line.h"
0018 #include "src/backend/worksheet/TextLabel.h"
0019 #include "src/backend/worksheet/WorksheetElement.h"
0020 #include "src/backend/worksheet/plots/cartesian/Axis.h" // already included in CartesianPlot
0021 #include "src/backend/worksheet/plots/cartesian/AxisPrivate.h"
0022 #include "src/kdefrontend/dockwidgets/AxisDock.h" // access ui elements
0023 #include "src/kdefrontend/widgets/LabelWidget.h"
0024 #include "src/kdefrontend/widgets/LineWidget.h"
0025 
0026 #include <QUndoStack>
0027 
0028 #define CHECK_AXIS_LABELS(currentTickValues, expectedTickValues)                                                                                               \
0029     {                                                                                                                                                          \
0030         /* To check if retransform ticks was called at the correct time */                                                                                     \
0031         QCOMPARE(currentTickValues.length(), expectedTickValues.length());                                                                                     \
0032         for (int i = 0; i < expectedTickValues.length(); i++)                                                                                                  \
0033             QCOMPARE(currentTickValues.at(i), expectedTickValues.at(i));                                                                                       \
0034     }
0035 
0036 void AxisTest::axisLine() {
0037     Project project;
0038     auto* ws = new Worksheet(QStringLiteral("worksheet"));
0039     QVERIFY(ws != nullptr);
0040     project.addChild(ws);
0041 
0042     auto* p = new CartesianPlot(QStringLiteral("plot"));
0043     p->setType(CartesianPlot::Type::TwoAxes); // Otherwise no axis are created
0044     QVERIFY(p != nullptr);
0045     ws->addChild(p);
0046 
0047     auto axes = p->children<Axis>();
0048     QCOMPARE(axes.count(), 2);
0049     QCOMPARE(axes.at(0)->name(), QStringLiteral("x"));
0050     QCOMPARE(axes.at(1)->name(), QStringLiteral("y"));
0051 
0052     auto* xAxis = axes.at(0);
0053     auto* yAxis1 = axes.at(1);
0054 
0055     const auto dataRect = p->dataRect();
0056     const auto bottomLeft = dataRect.bottomLeft();
0057     const auto topLeft = dataRect.topLeft();
0058     const auto bottomRight = dataRect.bottomRight();
0059 
0060     {
0061         auto* axis = yAxis1;
0062 
0063         QCOMPARE(axis->offset(), 0);
0064         QCOMPARE(axis->position(), Axis::Position::Left);
0065 
0066         const auto& linePath = axis->d_func()->linePath;
0067         QCOMPARE(linePath.isEmpty(), false);
0068         QCOMPARE(linePath.elementCount(), 2);
0069 
0070         auto element = linePath.elementAt(0);
0071         QCOMPARE(element.type, QPainterPath::MoveToElement);
0072         QCOMPARE(element.x, bottomLeft.x());
0073         QCOMPARE(element.y, bottomLeft.y());
0074         element = linePath.elementAt(1);
0075         QCOMPARE(element.type, QPainterPath::LineToElement);
0076         QCOMPARE(element.x, topLeft.x());
0077         QCOMPARE(element.y, topLeft.y());
0078     }
0079 
0080     {
0081         auto* axis = xAxis;
0082 
0083         QCOMPARE(axis->offset(), 0);
0084         QCOMPARE(axis->position(), Axis::Position::Bottom);
0085 
0086         const auto& linePath = axis->d_func()->linePath;
0087         QCOMPARE(linePath.isEmpty(), false);
0088         QCOMPARE(linePath.elementCount(), 2);
0089 
0090         auto element = linePath.elementAt(0);
0091         QCOMPARE(element.type, QPainterPath::MoveToElement);
0092         QCOMPARE(element.x, bottomLeft.x());
0093         QCOMPARE(element.y, bottomLeft.y());
0094         element = linePath.elementAt(1);
0095         QCOMPARE(element.type, QPainterPath::LineToElement);
0096         QCOMPARE(element.x, bottomRight.x());
0097         QCOMPARE(element.y, bottomRight.y());
0098     }
0099 
0100     yAxis1->copy();
0101     p->paste();
0102 
0103     axes = p->children<Axis>();
0104     QCOMPARE(axes.count(), 3);
0105     QCOMPARE(axes.at(0)->name(), QStringLiteral("x"));
0106     QCOMPARE(axes.at(1)->name(), QStringLiteral("y"));
0107     QCOMPARE(axes.at(1), yAxis1);
0108     QVERIFY(axes.at(2)->name().startsWith(QLatin1Char('y')));
0109 
0110     auto yAxis2 = axes.at(2);
0111 
0112     {
0113         auto* axis = yAxis2;
0114 
0115         QCOMPARE(axis->offset(), 0);
0116         QCOMPARE(axis->position(), Axis::Position::Left);
0117 
0118         const auto& linePath = axis->d_func()->linePath;
0119         QCOMPARE(linePath.isEmpty(), false);
0120         QCOMPARE(linePath.elementCount(), 2);
0121 
0122         auto element = linePath.elementAt(0);
0123         QCOMPARE(element.type, QPainterPath::MoveToElement);
0124         QCOMPARE(element.x, bottomLeft.x());
0125         QCOMPARE(element.y, bottomLeft.y());
0126         element = linePath.elementAt(1);
0127         QCOMPARE(element.type, QPainterPath::LineToElement);
0128         QCOMPARE(element.x, topLeft.x());
0129         QCOMPARE(element.y, topLeft.y());
0130     }
0131 }
0132 
0133 void AxisTest::majorTicksAutoNumberEnableDisable() {
0134     Project project;
0135     auto* ws = new Worksheet(QStringLiteral("worksheet"));
0136     QVERIFY(ws != nullptr);
0137     project.addChild(ws);
0138 
0139     auto* p = new CartesianPlot(QStringLiteral("plot"));
0140     p->setType(CartesianPlot::Type::TwoAxes); // Otherwise no axis are created
0141     QVERIFY(p != nullptr);
0142     ws->addChild(p);
0143 
0144     auto axes = p->children<Axis>();
0145     QCOMPARE(axes.count(), 2);
0146     QCOMPARE(axes.at(0)->name(), QStringLiteral("x"));
0147     QCOMPARE(axes.at(1)->name(), QStringLiteral("y"));
0148 
0149     AxisDock axisDock(nullptr);
0150 
0151     auto* xAxis = axes.at(0);
0152     QCOMPARE(xAxis->majorTicksNumber(), 6); // Default number created by autonumbering
0153     QCOMPARE(xAxis->majorTicksAutoNumber(), true);
0154 
0155     {
0156         QVector<double> expectedTickValues = {0, 0.2, 0.4, 0.6, 0.8, 1.0};
0157         CHECK_AXIS_LABELS(xAxis->tickLabelValues(), expectedTickValues);
0158     }
0159 
0160     // To check also if the dock shows the correct values
0161     axisDock.setAxes({xAxis});
0162 
0163     QCOMPARE(axisDock.ui.cbMajorTicksAutoNumber->isChecked(), true);
0164     QCOMPARE(axisDock.ui.sbMajorTicksNumber->isEnabled(), false);
0165 
0166     // Not possible, because sbMajorTicksNumber is disabled
0167     // test it nevertless
0168     xAxis->setMajorTicksNumber(5);
0169     QCOMPARE(xAxis->majorTicksNumber(), 5);
0170     QCOMPARE(xAxis->majorTicksAutoNumber(), false);
0171 
0172     {
0173         QVector<double> expectedTickValues = {0, 0.25, 0.5, 0.75, 1};
0174         CHECK_AXIS_LABELS(xAxis->tickLabelValues(), expectedTickValues);
0175     }
0176 
0177     QCOMPARE(axisDock.ui.cbMajorTicksAutoNumber->isChecked(), false);
0178     QCOMPARE(axisDock.ui.sbMajorTicksNumber->isEnabled(), true);
0179     QCOMPARE(axisDock.ui.sbMajorTicksNumber->value(), 5);
0180 
0181     // Check that undo/redo works for setting manual ticknumber
0182     project.undoStack()->undo();
0183     QCOMPARE(xAxis->majorTicksNumber(), 6);
0184     QCOMPARE(xAxis->majorTicksAutoNumber(), true);
0185 
0186     {
0187         QVector<double> expectedTickValues = {0, 0.2, 0.4, 0.6, 0.8, 1.0};
0188         CHECK_AXIS_LABELS(xAxis->tickLabelValues(), expectedTickValues);
0189     }
0190 
0191     QCOMPARE(axisDock.ui.cbMajorTicksAutoNumber->isChecked(), true);
0192     QCOMPARE(axisDock.ui.sbMajorTicksNumber->isEnabled(), false);
0193     QCOMPARE(axisDock.ui.sbMajorTicksNumber->value(), 6);
0194 
0195     project.undoStack()->redo();
0196     QCOMPARE(xAxis->majorTicksNumber(), 5);
0197     QCOMPARE(xAxis->majorTicksAutoNumber(), false);
0198 
0199     {
0200         QVector<double> expectedTickValues = {0, 0.25, 0.5, 0.75, 1};
0201         CHECK_AXIS_LABELS(xAxis->tickLabelValues(), expectedTickValues);
0202     }
0203 
0204     xAxis->setMajorTicksAutoNumber(true);
0205     QCOMPARE(xAxis->majorTicksNumber(), 6);
0206     QCOMPARE(xAxis->majorTicksAutoNumber(), true);
0207 
0208     {
0209         QVector<double> expectedTickValues = {0, 0.2, 0.4, 0.6, 0.8, 1.0};
0210         CHECK_AXIS_LABELS(xAxis->tickLabelValues(), expectedTickValues);
0211     }
0212 
0213     // Check that undo/redo works for setting autonumber enable/disable
0214     project.undoStack()->undo();
0215     QCOMPARE(xAxis->majorTicksNumber(), 5);
0216     QCOMPARE(xAxis->majorTicksAutoNumber(), false);
0217 
0218     {
0219         QVector<double> expectedTickValues = {0, 0.25, 0.5, 0.75, 1};
0220         CHECK_AXIS_LABELS(xAxis->tickLabelValues(), expectedTickValues);
0221     }
0222 
0223     project.undoStack()->redo();
0224     QCOMPARE(xAxis->majorTicksNumber(), 6);
0225     QCOMPARE(xAxis->majorTicksAutoNumber(), true);
0226 
0227     {
0228         QVector<double> expectedTickValues = {0, 0.2, 0.4, 0.6, 0.8, 1.0};
0229         CHECK_AXIS_LABELS(xAxis->tickLabelValues(), expectedTickValues);
0230     }
0231 }
0232 
0233 void AxisTest::minorTicksAutoNumberEnableDisable() {
0234     Project project;
0235     auto* ws = new Worksheet(QStringLiteral("worksheet"));
0236     QVERIFY(ws != nullptr);
0237     project.addChild(ws);
0238 
0239     auto* p = new CartesianPlot(QStringLiteral("plot"));
0240     p->setType(CartesianPlot::Type::TwoAxes); // Otherwise no axis are created
0241     QVERIFY(p != nullptr);
0242     ws->addChild(p);
0243 
0244     auto axes = p->children<Axis>();
0245     QCOMPARE(axes.count(), 2);
0246     QCOMPARE(axes.at(0)->name(), QStringLiteral("x"));
0247     QCOMPARE(axes.at(1)->name(), QStringLiteral("y"));
0248 
0249     AxisDock axisDock(nullptr);
0250 
0251     auto* xAxis = axes.at(0);
0252     QCOMPARE(xAxis->minorTicksNumber(), 1); // Default number created by autonumbering
0253     QCOMPARE(xAxis->minorTicksAutoNumber(), true);
0254 
0255     // To check also if the dock shows the correct values
0256     axisDock.setAxes({xAxis});
0257 
0258     QCOMPARE(axisDock.ui.cbMinorTicksAutoNumber->isChecked(), true);
0259     QCOMPARE(axisDock.ui.sbMinorTicksNumber->isEnabled(), false);
0260 
0261     // Not possible, because sbminorTicksNumber is disabled
0262     // test it nevertless
0263     xAxis->setMinorTicksNumber(5);
0264     QCOMPARE(xAxis->minorTicksNumber(), 5);
0265     QCOMPARE(xAxis->minorTicksAutoNumber(), false);
0266 
0267     QCOMPARE(axisDock.ui.cbMinorTicksAutoNumber->isChecked(), false);
0268     QCOMPARE(axisDock.ui.sbMinorTicksNumber->isEnabled(), true);
0269     QCOMPARE(axisDock.ui.sbMinorTicksNumber->value(), 5);
0270 
0271     // Check that undo/redo works for setting manual ticknumber
0272     project.undoStack()->undo();
0273     QCOMPARE(xAxis->minorTicksNumber(), 1);
0274     QCOMPARE(xAxis->minorTicksAutoNumber(), true);
0275 
0276     QCOMPARE(axisDock.ui.cbMinorTicksAutoNumber->isChecked(), true);
0277     QCOMPARE(axisDock.ui.sbMinorTicksNumber->isEnabled(), false);
0278     QCOMPARE(axisDock.ui.sbMinorTicksNumber->value(), 1);
0279 
0280     project.undoStack()->redo();
0281     QCOMPARE(xAxis->minorTicksNumber(), 5);
0282     QCOMPARE(xAxis->minorTicksAutoNumber(), false);
0283 
0284     xAxis->setMinorTicksAutoNumber(true);
0285     QCOMPARE(xAxis->minorTicksNumber(), 1);
0286     QCOMPARE(xAxis->minorTicksAutoNumber(), true);
0287 
0288     // Check that undo/redo works for setting autonumber enable/disable
0289     project.undoStack()->undo();
0290     QCOMPARE(xAxis->minorTicksNumber(), 5);
0291     QCOMPARE(xAxis->minorTicksAutoNumber(), false);
0292 
0293     project.undoStack()->redo();
0294     QCOMPARE(xAxis->minorTicksNumber(), 1);
0295     QCOMPARE(xAxis->minorTicksAutoNumber(), true);
0296 }
0297 
0298 void AxisTest::majorTicksStartValue() {
0299     Project project;
0300     auto* ws = new Worksheet(QStringLiteral("worksheet"));
0301     QVERIFY(ws != nullptr);
0302     project.addChild(ws);
0303 
0304     auto* p = new CartesianPlot(QStringLiteral("plot"));
0305     p->setType(CartesianPlot::Type::TwoAxes); // Otherwise no axis are created
0306     QVERIFY(p != nullptr);
0307     ws->addChild(p);
0308 
0309     auto axes = p->children<Axis>();
0310     QCOMPARE(axes.count(), 2);
0311     QCOMPARE(axes.at(0)->name(), QStringLiteral("x"));
0312     QCOMPARE(axes.at(1)->name(), QStringLiteral("y"));
0313 
0314     AxisDock axisDock(nullptr);
0315 
0316     auto* xAxis = axes.at(0);
0317 
0318     {
0319         QVector<double> expectedTickValues = {0, 0.2, 0.4, 0.6, 0.8, 1.0};
0320         CHECK_AXIS_LABELS(xAxis->tickLabelValues(), expectedTickValues);
0321     }
0322 
0323     // To check also if the dock shows the correct values
0324     axisDock.setAxes({xAxis});
0325 
0326     QCOMPARE(axisDock.ui.cbMajorTicksStartType->currentIndex(), 1); // by default offset is used
0327 
0328     QCOMPARE(xAxis->majorTicksStartType(), Axis::TicksStartType::Offset);
0329 
0330     xAxis->setMajorTickStartValue(0.1); // does not affect anything, but just that the ticklabels are different to the offset when setting
0331 
0332     xAxis->setMajorTicksStartType(Axis::TicksStartType::Absolute);
0333 
0334     QCOMPARE(axisDock.ui.cbMajorTicksStartType->currentIndex(), 0);
0335 
0336     QCOMPARE(xAxis->majorTicksStartType(), Axis::TicksStartType::Absolute);
0337     {
0338         QVector<double> expectedTickValues = {0.1, 0.4, 0.7, 1.0}; // starting now from 0.1
0339         CHECK_AXIS_LABELS(xAxis->tickLabelValues(), expectedTickValues);
0340     }
0341 
0342     xAxis->setMajorTickStartValue(0.2);
0343     QCOMPARE(axisDock.ui.sbMajorTickStartValue->value(), 0.2);
0344 
0345     {
0346         QVector<double> expectedTickValues = {0.2, 0.4, 0.6, 0.8, 1.0}; // starting now from 0.2
0347         CHECK_AXIS_LABELS(xAxis->tickLabelValues(), expectedTickValues);
0348     }
0349 
0350     project.undoStack()->undo();
0351 
0352     QCOMPARE(xAxis->majorTicksStartType(), Axis::TicksStartType::Absolute);
0353 
0354     {
0355         QVector<double> expectedTickValues = {0.1, 0.4, 0.7, 1.0}; // starting now from 0.1
0356         CHECK_AXIS_LABELS(xAxis->tickLabelValues(), expectedTickValues);
0357     }
0358 
0359     project.undoStack()->undo();
0360 
0361     QCOMPARE(xAxis->majorTicksStartType(), Axis::TicksStartType::Offset);
0362 
0363     // by default the offset is zero, so we are starting again from the begining
0364     {
0365         QVector<double> expectedTickValues = {0, 0.2, 0.4, 0.6, 0.8, 1.0};
0366         CHECK_AXIS_LABELS(xAxis->tickLabelValues(), expectedTickValues);
0367     }
0368 }
0369 
0370 void AxisTest::TestSetCoordinateSystem() {
0371     // Test if the range stored in the Axis gets updated when a new coordinatesystemindex is set
0372     Project project;
0373     auto* ws = new Worksheet(QStringLiteral("worksheet"));
0374     QVERIFY(ws != nullptr);
0375     project.addChild(ws);
0376 
0377     auto* p = new CartesianPlot(QStringLiteral("plot"));
0378     p->setType(CartesianPlot::Type::TwoAxes); // Otherwise no axes are created
0379     QVERIFY(p != nullptr);
0380 
0381     ws->addChild(p);
0382 
0383     auto axes = p->children<Axis>();
0384     QCOMPARE(axes.count(), 2);
0385     auto yAxis = axes.at(1);
0386     QCOMPARE(yAxis->name(), QStringLiteral("y"));
0387     {
0388         auto range = yAxis->range();
0389         QCOMPARE(range.start(), 0);
0390         QCOMPARE(range.end(), 1);
0391     }
0392 
0393     // Add new coordinatesystem to the plot
0394     p->addYRange(Range<double>(5, 100));
0395     QCOMPARE(p->rangeCount(Dimension::X), 1);
0396     QCOMPARE(p->rangeCount(Dimension::Y), 2);
0397     p->addCoordinateSystem();
0398     QCOMPARE(p->coordinateSystemCount(), 2);
0399     auto cSystem = p->coordinateSystem(1);
0400     cSystem->setIndex(Dimension::X, 0);
0401     cSystem->setIndex(Dimension::Y, 1);
0402 
0403     // Change CoordinatesystemIndex of the axis
0404     yAxis->setCoordinateSystemIndex(1);
0405 
0406     {
0407         auto range = yAxis->range();
0408         QCOMPARE(range.start(), 5);
0409         QCOMPARE(range.end(), 100);
0410     }
0411 }
0412 
0413 void AxisTest::TestSetRange() {
0414     Project project;
0415     auto* ws = new Worksheet(QStringLiteral("worksheet"));
0416     QVERIFY(ws != nullptr);
0417     project.addChild(ws);
0418     auto* p = new CartesianPlot(QStringLiteral("plot"));
0419     p->setType(CartesianPlot::Type::TwoAxes); // Otherwise no axes are created
0420     QVERIFY(p != nullptr);
0421     ws->addChild(p);
0422     auto axes = p->children<Axis>();
0423     QCOMPARE(axes.count(), 2);
0424     auto xAxis = axes.at(0);
0425     QCOMPARE(xAxis->name(), QStringLiteral("x"));
0426 
0427     // This does not work anymore, because isNumeric() is depending on the
0428     // CoordinateSystem which is not available when using creating the object
0429     // TODO: find a way to sync AxisPrivate::Range with the CartesianPlotRange
0430     // (Not only the start/end, but also the format and the scale!)
0431     // Then this can be used again
0432     // Axis xAxis(QStringLiteral("x"), Axis::Orientation::Horizontal);
0433 
0434     auto arange = xAxis->range();
0435     // different to default values!
0436     Range<double> r(5, 11, RangeT::Format::DateTime, RangeT::Scale::Log10);
0437     QVERIFY(arange.start() != r.start());
0438     QVERIFY(arange.end() != r.end());
0439     QVERIFY(arange.format() != r.format());
0440     QVERIFY(arange.scale() != r.scale());
0441 
0442     xAxis->setRange(r);
0443     arange = xAxis->range();
0444     QCOMPARE(arange.start(), 5);
0445     QCOMPARE(arange.end(), 11);
0446     QCOMPARE(arange.format(), RangeT::Format::DateTime);
0447     QCOMPARE(arange.scale(), RangeT::Scale::Log10);
0448 
0449     xAxis->setStart(1);
0450     arange = xAxis->range();
0451     QCOMPARE(arange.start(), 1);
0452     QCOMPARE(arange.end(), 11);
0453     QCOMPARE(arange.format(), RangeT::Format::DateTime);
0454     QCOMPARE(arange.scale(), RangeT::Scale::Log10);
0455 
0456     xAxis->setEnd(23);
0457     arange = xAxis->range();
0458     QCOMPARE(arange.start(), 1);
0459     QCOMPARE(arange.end(), 23);
0460     QCOMPARE(arange.format(), RangeT::Format::DateTime);
0461     QCOMPARE(arange.scale(), RangeT::Scale::Log10);
0462 
0463     xAxis->setRange(-10, 10);
0464     arange = xAxis->range();
0465     QCOMPARE(arange.start(), -10);
0466     QCOMPARE(arange.end(), 10);
0467     QCOMPARE(arange.format(), RangeT::Format::DateTime);
0468     QCOMPARE(arange.scale(), RangeT::Scale::Log10);
0469 }
0470 
0471 void AxisTest::TestAddingHorizontalAxis() {
0472     Project project;
0473     auto* ws = new Worksheet(QStringLiteral("worksheet"));
0474     QVERIFY(ws != nullptr);
0475     project.addChild(ws);
0476 
0477     auto* p = new CartesianPlot(QStringLiteral("plot"));
0478     p->setType(CartesianPlot::Type::TwoAxes); // Otherwise no axes are created
0479     QVERIFY(p != nullptr);
0480 
0481     ws->addChild(p);
0482 
0483     p->addHorizontalAxis(); // should not crash
0484 }
0485 
0486 void AxisTest::TestAddingVerticalAxis() {
0487     Project project;
0488     auto* ws = new Worksheet(QStringLiteral("worksheet"));
0489     QVERIFY(ws != nullptr);
0490     project.addChild(ws);
0491 
0492     auto* p = new CartesianPlot(QStringLiteral("plot"));
0493     p->setType(CartesianPlot::Type::TwoAxes); // Otherwise no axes are created
0494     QVERIFY(p != nullptr);
0495 
0496     ws->addChild(p);
0497 
0498     p->addVerticalAxis(); // should not crash
0499 }
0500 
0501 void AxisTest::tickLabelRepresentationAutomatic() {
0502     QLocale::setDefault(QLocale::C); // . as decimal separator
0503     Project project;
0504     auto* ws = new Worksheet(QStringLiteral("worksheet"));
0505     QVERIFY(ws != nullptr);
0506     project.addChild(ws);
0507 
0508     auto* p = new CartesianPlot(QStringLiteral("plot"));
0509     p->setType(CartesianPlot::Type::TwoAxes); // Otherwise no axis are created
0510     QVERIFY(p != nullptr);
0511     ws->addChild(p);
0512 
0513     auto axes = p->children<Axis>();
0514     QCOMPARE(axes.count(), 2);
0515     QCOMPARE(axes.at(0)->name(), QStringLiteral("x"));
0516     QCOMPARE(axes.at(1)->name(), QStringLiteral("y"));
0517     auto* yAxis = static_cast<Axis*>(axes.at(1));
0518 
0519     AxisDock dock(nullptr);
0520     dock.setAxes({yAxis});
0521 
0522     QCOMPARE(dock.ui.chkLabelsFormatAuto->isChecked(), true);
0523     QCOMPARE(dock.ui.cbLabelsFormat->isEnabled(), false);
0524 
0525     {
0526         QCOMPARE(yAxis->labelsFormat(), Axis::LabelsFormat::Decimal);
0527         QStringList expectedStrings{QStringLiteral("0.0"),
0528                                     QStringLiteral("0.2"),
0529                                     QStringLiteral("0.4"),
0530                                     QStringLiteral("0.6"),
0531                                     QStringLiteral("0.8"),
0532                                     QStringLiteral("1.0")};
0533         COMPARE_STRING_VECTORS(yAxis->tickLabelStrings(), expectedStrings);
0534     }
0535 
0536     p->setRangeDefault(Dimension::Y, Range<double>(0, 1e6));
0537 
0538     {
0539         QCOMPARE(yAxis->labelsFormat(), Axis::LabelsFormat::Scientific);
0540         QStringList expectedStrings{
0541             QStringLiteral("0"),
0542             AxisPrivate::createScientificRepresentation(QStringLiteral("2"), QStringLiteral("5")),
0543             AxisPrivate::createScientificRepresentation(QStringLiteral("4"), QStringLiteral("5")),
0544             AxisPrivate::createScientificRepresentation(QStringLiteral("6"), QStringLiteral("5")),
0545             AxisPrivate::createScientificRepresentation(QStringLiteral("8"), QStringLiteral("5")),
0546             AxisPrivate::createScientificRepresentation(QStringLiteral("1"), QStringLiteral("6")),
0547         };
0548         COMPARE_STRING_VECTORS(yAxis->tickLabelStrings(), expectedStrings);
0549     }
0550 
0551     p->setRangeDefault(Dimension::Y, Range<double>(0, 1));
0552 
0553     {
0554         QCOMPARE(yAxis->labelsFormat(), Axis::LabelsFormat::Decimal);
0555         QStringList expectedStrings{QStringLiteral("0.0"),
0556                                     QStringLiteral("0.2"),
0557                                     QStringLiteral("0.4"),
0558                                     QStringLiteral("0.6"),
0559                                     QStringLiteral("0.8"),
0560                                     QStringLiteral("1.0")};
0561         COMPARE_STRING_VECTORS(yAxis->tickLabelStrings(), expectedStrings);
0562     }
0563 }
0564 
0565 void AxisTest::tickLabelRepresentationManual() {
0566     QLocale::setDefault(QLocale::English); // . as decimal separator
0567     Project project;
0568     auto* ws = new Worksheet(QStringLiteral("worksheet"));
0569     QVERIFY(ws != nullptr);
0570     project.addChild(ws);
0571 
0572     auto* p = new CartesianPlot(QStringLiteral("plot"));
0573     p->setType(CartesianPlot::Type::TwoAxes); // Otherwise no axis are created
0574     QVERIFY(p != nullptr);
0575     ws->addChild(p);
0576 
0577     auto axes = p->children<Axis>();
0578     QCOMPARE(axes.count(), 2);
0579     QCOMPARE(axes.at(0)->name(), QStringLiteral("x"));
0580     QCOMPARE(axes.at(1)->name(), QStringLiteral("y"));
0581     auto* yAxis = static_cast<Axis*>(axes.at(1));
0582 
0583     AxisDock dock(nullptr);
0584     dock.setAxes({yAxis});
0585 
0586     QCOMPARE(dock.ui.chkLabelsFormatAuto->isChecked(), true);
0587     QCOMPARE(dock.ui.cbLabelsFormat->isEnabled(), false);
0588 
0589     yAxis->setLabelsFormatAuto(false);
0590 
0591     QCOMPARE(dock.ui.chkLabelsFormatAuto->isChecked(), false);
0592     QCOMPARE(dock.ui.cbLabelsFormat->isEnabled(), true);
0593 
0594     {
0595         // Check if applied also when settings
0596         AxisDock dock2(nullptr);
0597         dock2.setAxes({yAxis});
0598         QCOMPARE(dock2.ui.chkLabelsFormatAuto->isChecked(), false);
0599         QCOMPARE(dock2.ui.cbLabelsFormat->isEnabled(), true);
0600     }
0601 
0602     {
0603         QCOMPARE(yAxis->labelsFormat(), Axis::LabelsFormat::Decimal);
0604         QStringList expectedStrings{QStringLiteral("0.0"),
0605                                     QStringLiteral("0.2"),
0606                                     QStringLiteral("0.4"),
0607                                     QStringLiteral("0.6"),
0608                                     QStringLiteral("0.8"),
0609                                     QStringLiteral("1.0")};
0610         COMPARE_STRING_VECTORS(yAxis->tickLabelStrings(), expectedStrings);
0611     }
0612 
0613     p->setRangeDefault(Dimension::Y, Range<double>(0, 1e6));
0614 
0615     {
0616         QCOMPARE(yAxis->labelsFormat(), Axis::LabelsFormat::Decimal);
0617         QStringList expectedStrings{QStringLiteral("0"),
0618                                     QStringLiteral("200,000"),
0619                                     QStringLiteral("400,000"),
0620                                     QStringLiteral("600,000"),
0621                                     QStringLiteral("800,000"),
0622                                     QStringLiteral("1,000,000")};
0623         COMPARE_STRING_VECTORS(yAxis->tickLabelStrings(), expectedStrings);
0624     }
0625 
0626     p->setRangeDefault(Dimension::Y, Range<double>(0, 1));
0627 
0628     {
0629         QCOMPARE(yAxis->labelsFormat(), Axis::LabelsFormat::Decimal);
0630         QStringList expectedStrings{QStringLiteral("0.0"),
0631                                     QStringLiteral("0.2"),
0632                                     QStringLiteral("0.4"),
0633                                     QStringLiteral("0.6"),
0634                                     QStringLiteral("0.8"),
0635                                     QStringLiteral("1.0")};
0636         COMPARE_STRING_VECTORS(yAxis->tickLabelStrings(), expectedStrings);
0637     }
0638 }
0639 
0640 // TODO: write test switching between numeric and datetime
0641 
0642 #define CHECK_TITLE_COLOR(color_)                                                                                                                              \
0643     QCOMPARE(a->title()->fontColor(), color_);                                                                                                                 \
0644     QCOMPARE(dock.labelWidget->ui.kcbFontColor->color(), color_);
0645 
0646 #define CHECK_MAJOR_TICKS_LINE_COLOR(color_)                                                                                                                   \
0647     QCOMPARE(a->majorTicksLine()->color(), color_);                                                                                                            \
0648     QCOMPARE(dock.majorTicksLineWidget->ui.kcbColor->color(), color_);
0649 
0650 #define CHECK_MINOR_TICKS_LINE_COLOR(color_)                                                                                                                   \
0651     QCOMPARE(a->minorTicksLine()->color(), color_);                                                                                                            \
0652     QCOMPARE(dock.minorTicksLineWidget->ui.kcbColor->color(), color_);
0653 
0654 #define CHECK_LINE_COLOR(color_)                                                                                                                               \
0655     QCOMPARE(a->line()->color(), color_);                                                                                                                      \
0656     QCOMPARE(dock.lineWidget->ui.kcbColor->color(), color_);
0657 
0658 #define CHECK_TICK_LABLES_COLOR(color_)                                                                                                                        \
0659     QCOMPARE(a->labelsColor(), color_);                                                                                                                        \
0660     QCOMPARE(dock.ui.kcbLabelsFontColor->color(), color_);
0661 
0662 #define CHECK_COMMON_COLOR(color_)                                                                                                                             \
0663     CHECK_TITLE_COLOR(color_);                                                                                                                                 \
0664     CHECK_MAJOR_TICKS_LINE_COLOR(color_);                                                                                                                      \
0665     CHECK_MINOR_TICKS_LINE_COLOR(color_);                                                                                                                      \
0666     CHECK_LINE_COLOR(color_);                                                                                                                                  \
0667     CHECK_TICK_LABLES_COLOR(color_);                                                                                                                           \
0668     QCOMPARE(dock.ui.kcbAxisColor->color(), color_);
0669 
0670 #define CREATE_PROJECT                                                                                                                                         \
0671     Project project;                                                                                                                                           \
0672     auto* ws = new Worksheet(QStringLiteral("worksheet"));                                                                                                     \
0673     QVERIFY(ws != nullptr);                                                                                                                                    \
0674     project.addChild(ws);                                                                                                                                      \
0675                                                                                                                                                                \
0676     auto* p = new CartesianPlot(QStringLiteral("plot"));                                                                                                       \
0677     p->setType(CartesianPlot::Type::TwoAxes); /* Otherwise no axis are created */                                                                              \
0678     QVERIFY(p != nullptr);                                                                                                                                     \
0679     ws->addChild(p);                                                                                                                                           \
0680                                                                                                                                                                \
0681     auto axes = p->children<Axis>();                                                                                                                           \
0682     QCOMPARE(axes.count(), 2);                                                                                                                                 \
0683     QCOMPARE(axes.at(0)->name(), QStringLiteral("x"));                                                                                                         \
0684     QCOMPARE(axes.at(1)->name(), QStringLiteral("y"));                                                                                                         \
0685     auto a = axes.at(0);                                                                                                                                       \
0686     AxisDock dock(nullptr);                                                                                                                                    \
0687     dock.setAxes({a});                                                                                                                                         \
0688     CHECK_COMMON_COLOR(Qt::black);
0689 
0690 void AxisTest::setAxisColor() {
0691     CREATE_PROJECT
0692 
0693     // set axis color
0694     dock.ui.kcbAxisColor->setColor(Qt::red);
0695     CHECK_COMMON_COLOR(Qt::red);
0696 
0697     // undo/redo
0698     a->undoStack()->undo();
0699     CHECK_COMMON_COLOR(Qt::black);
0700     a->undoStack()->redo();
0701     CHECK_COMMON_COLOR(Qt::red);
0702 }
0703 
0704 void AxisTest::setTitleColor() {
0705     CREATE_PROJECT
0706 
0707     // change title color
0708     dock.labelWidget->ui.kcbFontColor->setColor(Qt::green);
0709     CHECK_TITLE_COLOR(Qt::green);
0710     QCOMPARE(dock.ui.kcbAxisColor->color(), Qt::transparent);
0711     CHECK_MAJOR_TICKS_LINE_COLOR(Qt::black);
0712     CHECK_MINOR_TICKS_LINE_COLOR(Qt::black);
0713     CHECK_LINE_COLOR(Qt::black);
0714     CHECK_TICK_LABLES_COLOR(Qt::black);
0715 
0716     a->undoStack()->undo();
0717     CHECK_COMMON_COLOR(Qt::black);
0718 
0719     a->undoStack()->redo();
0720     CHECK_TITLE_COLOR(Qt::green);
0721     QCOMPARE(dock.ui.kcbAxisColor->color(), Qt::transparent);
0722     CHECK_MAJOR_TICKS_LINE_COLOR(Qt::black);
0723     CHECK_MINOR_TICKS_LINE_COLOR(Qt::black);
0724     CHECK_LINE_COLOR(Qt::black);
0725     CHECK_TICK_LABLES_COLOR(Qt::black);
0726 }
0727 
0728 void AxisTest::setMajorTickColor() {
0729     CREATE_PROJECT
0730 
0731     // change title color
0732     dock.majorTicksLineWidget->setColor(Qt::green);
0733     CHECK_MAJOR_TICKS_LINE_COLOR(Qt::green);
0734     QCOMPARE(dock.ui.kcbAxisColor->color(), Qt::transparent);
0735     CHECK_TITLE_COLOR(Qt::black);
0736     CHECK_MINOR_TICKS_LINE_COLOR(Qt::black);
0737     CHECK_LINE_COLOR(Qt::black);
0738     CHECK_TICK_LABLES_COLOR(Qt::black);
0739 
0740     a->undoStack()->undo();
0741     CHECK_COMMON_COLOR(Qt::black);
0742 
0743     a->undoStack()->redo();
0744     CHECK_MAJOR_TICKS_LINE_COLOR(Qt::green);
0745     QCOMPARE(dock.ui.kcbAxisColor->color(), Qt::transparent);
0746     CHECK_TITLE_COLOR(Qt::black);
0747     CHECK_MINOR_TICKS_LINE_COLOR(Qt::black);
0748     CHECK_LINE_COLOR(Qt::black);
0749     CHECK_TICK_LABLES_COLOR(Qt::black);
0750 }
0751 
0752 void AxisTest::setMinorTickColor() {
0753     CREATE_PROJECT
0754 
0755     // change title color
0756     dock.minorTicksLineWidget->setColor(Qt::green);
0757     CHECK_MINOR_TICKS_LINE_COLOR(Qt::green);
0758     QCOMPARE(dock.ui.kcbAxisColor->color(), Qt::transparent);
0759     CHECK_TITLE_COLOR(Qt::black);
0760     CHECK_MAJOR_TICKS_LINE_COLOR(Qt::black);
0761     CHECK_LINE_COLOR(Qt::black);
0762     CHECK_TICK_LABLES_COLOR(Qt::black);
0763 
0764     a->undoStack()->undo();
0765     CHECK_COMMON_COLOR(Qt::black);
0766 
0767     a->undoStack()->redo();
0768     CHECK_MINOR_TICKS_LINE_COLOR(Qt::green);
0769     QCOMPARE(dock.ui.kcbAxisColor->color(), Qt::transparent);
0770     CHECK_TITLE_COLOR(Qt::black);
0771     CHECK_MAJOR_TICKS_LINE_COLOR(Qt::black);
0772     CHECK_LINE_COLOR(Qt::black);
0773     CHECK_TICK_LABLES_COLOR(Qt::black);
0774 }
0775 
0776 void AxisTest::setLineColor() {
0777     CREATE_PROJECT
0778 
0779     // change title color
0780     dock.lineWidget->setColor(Qt::green);
0781     CHECK_LINE_COLOR(Qt::green);
0782     QCOMPARE(dock.ui.kcbAxisColor->color(), Qt::transparent);
0783     CHECK_TITLE_COLOR(Qt::black);
0784     CHECK_MAJOR_TICKS_LINE_COLOR(Qt::black);
0785     CHECK_MINOR_TICKS_LINE_COLOR(Qt::black);
0786     CHECK_TICK_LABLES_COLOR(Qt::black);
0787 
0788     a->undoStack()->undo();
0789     CHECK_COMMON_COLOR(Qt::black);
0790 
0791     a->undoStack()->redo();
0792     CHECK_LINE_COLOR(Qt::green);
0793     QCOMPARE(dock.ui.kcbAxisColor->color(), Qt::transparent);
0794     CHECK_TITLE_COLOR(Qt::black);
0795     CHECK_MAJOR_TICKS_LINE_COLOR(Qt::black);
0796     CHECK_MINOR_TICKS_LINE_COLOR(Qt::black);
0797     CHECK_TICK_LABLES_COLOR(Qt::black);
0798 }
0799 
0800 void AxisTest::setTickLabelColor() {
0801     CREATE_PROJECT
0802 
0803     // change title color
0804     dock.ui.kcbLabelsFontColor->setColor(Qt::green);
0805     CHECK_TICK_LABLES_COLOR(Qt::green);
0806     QCOMPARE(dock.ui.kcbAxisColor->color(), Qt::transparent);
0807     CHECK_TITLE_COLOR(Qt::black);
0808     CHECK_MAJOR_TICKS_LINE_COLOR(Qt::black);
0809     CHECK_MINOR_TICKS_LINE_COLOR(Qt::black);
0810     CHECK_LINE_COLOR(Qt::black);
0811 
0812     a->undoStack()->undo();
0813     CHECK_COMMON_COLOR(Qt::black);
0814 
0815     a->undoStack()->redo();
0816     CHECK_TICK_LABLES_COLOR(Qt::green);
0817     QCOMPARE(dock.ui.kcbAxisColor->color(), Qt::transparent);
0818     CHECK_TITLE_COLOR(Qt::black);
0819     CHECK_MAJOR_TICKS_LINE_COLOR(Qt::black);
0820     CHECK_MINOR_TICKS_LINE_COLOR(Qt::black);
0821     CHECK_LINE_COLOR(Qt::black);
0822 }
0823 
0824 void AxisTest::automaticTicNumberUpdateDockMajorTicks() {
0825     Project project;
0826     auto* ws = new Worksheet(QStringLiteral("worksheet"));
0827     QVERIFY(ws != nullptr);
0828     project.addChild(ws);
0829 
0830     auto* p = new CartesianPlot(QStringLiteral("plot"));
0831     p->setType(CartesianPlot::Type::TwoAxes); // Otherwise no axis are created
0832     QVERIFY(p != nullptr);
0833     ws->addChild(p);
0834 
0835     auto axes = p->children<Axis>();
0836     QCOMPARE(axes.count(), 2);
0837     QCOMPARE(axes.at(0)->name(), QStringLiteral("x"));
0838     QCOMPARE(axes.at(1)->name(), QStringLiteral("y"));
0839     auto* yAxis = static_cast<Axis*>(axes.at(1));
0840     auto* xAxis = static_cast<Axis*>(axes.at(0));
0841 
0842     AxisDock dock(nullptr);
0843 
0844     dock.setAxes({xAxis, yAxis});
0845     dock.ui.cbMajorTicksAutoNumber->setChecked(false);
0846     dock.ui.sbMajorTicksNumber->setValue(10);
0847 
0848     // Check majorticks numbers of the axes
0849     QCOMPARE(xAxis->majorTicksNumber(), 10);
0850     QCOMPARE(xAxis->majorTicksAutoNumber(), false);
0851     QCOMPARE(yAxis->majorTicksNumber(), 10);
0852     QCOMPARE(xAxis->majorTicksAutoNumber(), false);
0853     QCOMPARE(dock.ui.cbMajorTicksAutoNumber->isChecked(), false);
0854 
0855     dock.setAxes({xAxis, yAxis}); // Another time
0856     dock.ui.cbMajorTicksAutoNumber->setChecked(true);
0857 
0858     QCOMPARE(xAxis->majorTicksNumber(), 6);
0859     QCOMPARE(xAxis->majorTicksAutoNumber(), true);
0860     QCOMPARE(yAxis->majorTicksNumber(), 6);
0861     QCOMPARE(xAxis->majorTicksAutoNumber(), true);
0862     QCOMPARE(dock.ui.sbMajorTicksNumber->value(), 6);
0863 }
0864 
0865 void AxisTest::automaticTicNumberUpdateDockMinorTicks() {
0866     Project project;
0867     auto* ws = new Worksheet(QStringLiteral("worksheet"));
0868     QVERIFY(ws != nullptr);
0869     project.addChild(ws);
0870 
0871     auto* p = new CartesianPlot(QStringLiteral("plot"));
0872     p->setType(CartesianPlot::Type::TwoAxes); // Otherwise no axis are created
0873     QVERIFY(p != nullptr);
0874     ws->addChild(p);
0875 
0876     auto axes = p->children<Axis>();
0877     QCOMPARE(axes.count(), 2);
0878     QCOMPARE(axes.at(0)->name(), QStringLiteral("x"));
0879     QCOMPARE(axes.at(1)->name(), QStringLiteral("y"));
0880     auto* yAxis = static_cast<Axis*>(axes.at(1));
0881     auto* xAxis = static_cast<Axis*>(axes.at(0));
0882 
0883     AxisDock dock(nullptr);
0884     dock.setAxes({xAxis, yAxis});
0885     dock.ui.cbMinorTicksAutoNumber->setChecked(false);
0886     dock.ui.sbMinorTicksNumber->setValue(10);
0887 
0888     // Check minorticks numbers of the axes
0889     QCOMPARE(xAxis->minorTicksNumber(), 10);
0890     QCOMPARE(xAxis->minorTicksAutoNumber(), false);
0891     QCOMPARE(yAxis->minorTicksNumber(), 10);
0892     QCOMPARE(xAxis->minorTicksAutoNumber(), false);
0893     QCOMPARE(dock.ui.cbMinorTicksAutoNumber->isChecked(), false);
0894 
0895     dock.setAxes({xAxis, yAxis}); // Another time
0896     QCOMPARE(dock.ui.cbMinorTicksAutoNumber->isChecked(), false);
0897     dock.ui.cbMinorTicksAutoNumber->setChecked(true);
0898 
0899     // 1 is the default value for automatic
0900     QCOMPARE(xAxis->minorTicksNumber(), 1);
0901     QCOMPARE(xAxis->minorTicksAutoNumber(), true);
0902     QCOMPARE(yAxis->minorTicksNumber(), 1);
0903     QCOMPARE(xAxis->minorTicksAutoNumber(), true);
0904     QCOMPARE(dock.ui.sbMinorTicksNumber->value(), 1);
0905 }
0906 
0907 void AxisTest::columnLabelValues() {
0908     QLocale::setDefault(QLocale::C); // . as decimal separator
0909     Project project;
0910     auto* ws = new Worksheet(QStringLiteral("worksheet"));
0911     QVERIFY(ws != nullptr);
0912     project.addChild(ws);
0913 
0914     Spreadsheet* spreadsheet = new Spreadsheet(QStringLiteral("test"), false);
0915     spreadsheet->setColumnCount(2);
0916     spreadsheet->setRowCount(3);
0917     project.addChild(spreadsheet);
0918 
0919     auto* xCol = spreadsheet->column(0);
0920     xCol->replaceValues(0, QVector<double>({1, 2, 3}));
0921 
0922     auto* yCol = spreadsheet->column(1);
0923     yCol->replaceValues(0, QVector<double>({2, 3, 4}));
0924 
0925     QCOMPARE(spreadsheet->rowCount(), 3);
0926     QCOMPARE(spreadsheet->columnCount(), 2);
0927 
0928     yCol->addValueLabel(2, QStringLiteral("Status 1"));
0929     yCol->addValueLabel(3, QStringLiteral("Status 2"));
0930     yCol->addValueLabel(4, QStringLiteral("Status 3"));
0931 
0932     auto* p = new CartesianPlot(QStringLiteral("plot"));
0933     p->setType(CartesianPlot::Type::TwoAxes); // Otherwise no axis are created
0934     QVERIFY(p != nullptr);
0935     ws->addChild(p);
0936 
0937     auto* curve = new XYCurve(QStringLiteral("xy-curve"));
0938     curve->setXColumn(xCol);
0939     curve->setYColumn(yCol);
0940     p->addChild(curve);
0941 
0942     auto axes = p->children<Axis>();
0943     QCOMPARE(axes.count(), 2);
0944     QCOMPARE(axes.at(0)->name(), QStringLiteral("x"));
0945     QCOMPARE(axes.at(1)->name(), QStringLiteral("y"));
0946     auto* yAxis = static_cast<Axis*>(axes.at(1));
0947     // auto* xAxis = static_cast<Axis*>(axes.at(0));
0948 
0949     {
0950         QCOMPARE(yAxis->labelsFormat(), Axis::LabelsFormat::Decimal);
0951         const auto v = yAxis->tickLabelStrings();
0952         QStringList expectedStrings{
0953             QStringLiteral("2.0"),
0954             QStringLiteral("2.5"),
0955             QStringLiteral("3.0"),
0956             QStringLiteral("3.5"),
0957             QStringLiteral("4.0"),
0958         };
0959         COMPARE_STRING_VECTORS(yAxis->tickLabelStrings(), expectedStrings);
0960     }
0961 
0962     {
0963         yAxis->setMajorTicksType(Axis::TicksType::ColumnLabels);
0964         yAxis->setMajorTicksColumn(yCol);
0965 
0966         QStringList expectedStrings{
0967             QStringLiteral("Status 1"),
0968             QStringLiteral("Status 2"),
0969             QStringLiteral("Status 3"),
0970         };
0971         COMPARE_STRING_VECTORS(yAxis->tickLabelStrings(), expectedStrings);
0972     }
0973 }
0974 
0975 /*!
0976  * \brief AxisTest::columnLabelValuesMaxValues
0977  * Same as columnLabelValuesMaxValues() with the difference
0978  * that more columnLabels are available than the maximum number of ticks allowed
0979  * in the axis. This leads to a limited representation of ticks/labels
0980  */
0981 void AxisTest::columnLabelValuesMaxValues() {
0982     constexpr int valueLabelsCount = 1000;
0983     QLocale::setDefault(QLocale::C); // . as decimal separator
0984     Project project;
0985     auto* ws = new Worksheet(QStringLiteral("worksheet"));
0986     QVERIFY(ws != nullptr);
0987     project.addChild(ws);
0988 
0989     Spreadsheet* spreadsheet = new Spreadsheet(QStringLiteral("test"), false);
0990     spreadsheet->setColumnCount(2);
0991     spreadsheet->setRowCount(3);
0992     project.addChild(spreadsheet);
0993 
0994     auto* xCol = spreadsheet->column(0);
0995     xCol->replaceValues(-1, QVector<double>({1., 100.}));
0996 
0997     auto* yCol = spreadsheet->column(1);
0998     yCol->replaceValues(-1, QVector<double>({1., 1000.}));
0999 
1000     QCOMPARE(spreadsheet->rowCount(), 2);
1001     QCOMPARE(spreadsheet->columnCount(), 2);
1002 
1003     for (int i = 0; i <= valueLabelsCount; i++) {
1004         yCol->addValueLabel(i, QStringLiteral("Status ") + QString::number(i));
1005     }
1006 
1007     auto* p = new CartesianPlot(QStringLiteral("plot"));
1008     p->setType(CartesianPlot::Type::TwoAxes); // Otherwise no axis are created
1009     QVERIFY(p != nullptr);
1010     ws->addChild(p);
1011 
1012     auto* curve = new XYCurve(QStringLiteral("xy-curve"));
1013     curve->setXColumn(xCol);
1014     curve->setYColumn(yCol);
1015     p->addChild(curve);
1016 
1017     auto axes = p->children<Axis>();
1018     QCOMPARE(axes.count(), 2);
1019     QCOMPARE(axes.at(0)->name(), QStringLiteral("x"));
1020     QCOMPARE(axes.at(1)->name(), QStringLiteral("y"));
1021     auto* yAxis = static_cast<Axis*>(axes.at(1));
1022     // auto* xAxis = static_cast<Axis*>(axes.at(0));
1023 
1024     {
1025         yAxis->setMajorTicksType(Axis::TicksType::ColumnLabels);
1026         yAxis->setMajorTicksColumn(yCol);
1027 
1028         const auto v = yAxis->tickLabelStrings();
1029         QStringList expectedStrings;
1030         for (int i = 0; i <= valueLabelsCount; i += valueLabelsCount / (Axis::maxNumberMajorTicksCustomColumn() - 1))
1031             expectedStrings.push_back(QStringLiteral("Status ") + QString::number(i));
1032 
1033         COMPARE_STRING_VECTORS(yAxis->tickLabelStrings(), expectedStrings);
1034     }
1035 }
1036 
1037 void AxisTest::customTextLabels() {
1038     QLocale::setDefault(QLocale::C); // . as decimal separator
1039     Project project;
1040     auto* ws = new Worksheet(QStringLiteral("worksheet"));
1041     QVERIFY(ws != nullptr);
1042     project.addChild(ws);
1043 
1044     Spreadsheet* spreadsheetData = new Spreadsheet(QStringLiteral("data"), false);
1045     spreadsheetData->setColumnCount(2);
1046     spreadsheetData->setRowCount(3);
1047     project.addChild(spreadsheetData);
1048 
1049     auto* xCol = spreadsheetData->column(0);
1050     xCol->replaceValues(0, QVector<double>({1, 2, 3}));
1051 
1052     auto* yCol = spreadsheetData->column(1);
1053     yCol->replaceValues(0, QVector<double>({2, 3, 4}));
1054 
1055     QCOMPARE(spreadsheetData->rowCount(), 3);
1056     QCOMPARE(spreadsheetData->columnCount(), 2);
1057 
1058     Spreadsheet* spreadsheetLabels = new Spreadsheet(QStringLiteral("data"), false);
1059     spreadsheetLabels->setColumnCount(1);
1060     spreadsheetLabels->setRowCount(3);
1061     project.addChild(spreadsheetLabels);
1062     auto* labelsCol = spreadsheetLabels->column(0);
1063     labelsCol->setColumnMode(AbstractColumn::ColumnMode::Text);
1064     labelsCol->replaceTexts(-1, QVector<QString>({QStringLiteral("A"), QStringLiteral("B"), QStringLiteral("C")}));
1065 
1066     auto* p = new CartesianPlot(QStringLiteral("plot"));
1067     p->setType(CartesianPlot::Type::TwoAxes); // Otherwise no axis are created
1068     QVERIFY(p != nullptr);
1069     ws->addChild(p);
1070 
1071     auto* curve = new XYCurve(QStringLiteral("xy-curve"));
1072     curve->setXColumn(xCol);
1073     curve->setYColumn(yCol);
1074     p->addChild(curve);
1075 
1076     auto axes = p->children<Axis>();
1077     QCOMPARE(axes.count(), 2);
1078     QCOMPARE(axes.at(0)->name(), QStringLiteral("x"));
1079     QCOMPARE(axes.at(1)->name(), QStringLiteral("y"));
1080 
1081     auto* xAxis = static_cast<Axis*>(axes.at(0));
1082     xAxis->setMajorTicksNumber(3, false);
1083     xAxis->setLabelsTextType(Axis::LabelsTextType::CustomValues);
1084     xAxis->setLabelsTextColumn(labelsCol);
1085 
1086     {
1087         const auto v = xAxis->tickLabelStrings();
1088         QStringList expectedStrings{
1089             QStringLiteral("A"),
1090             QStringLiteral("B"),
1091             QStringLiteral("C"),
1092         };
1093         COMPARE_STRING_VECTORS(xAxis->tickLabelStrings(), expectedStrings);
1094     }
1095 }
1096 
1097 QTEST_MAIN(AxisTest)