| 26 | #include <QUndoStack> |
| 27 | |
| 28 | void AxisTest3::dateTime() { |
| 29 | QLocale::setDefault(QLocale::C); // use . as decimal separator |
| 30 | Project project; |
| 31 | auto* ws = new Worksheet(QStringLiteral("worksheet")); |
| 32 | QVERIFY(ws != nullptr); |
| 33 | project.addChild(ws); |
| 34 | |
| 35 | Spreadsheet* spreadsheetData = new Spreadsheet(QStringLiteral("data"), false); |
| 36 | spreadsheetData->setColumnCount(2); |
| 37 | spreadsheetData->setRowCount(3); |
| 38 | project.addChild(spreadsheetData); |
| 39 | |
| 40 | auto* xCol = spreadsheetData->column(0); |
| 41 | xCol->setColumnMode(AbstractColumn::ColumnMode::DateTime); |
| 42 | QDateTime dt1 = QDateTime::fromString(QStringLiteral("2017-07-24T00:00:00Z"), Qt::ISODate); |
| 43 | QDateTime dt2 = QDateTime::fromString(QStringLiteral("2017-08-24T00:00:00Z"), Qt::ISODate); |
| 44 | QDateTime dt3 = QDateTime::fromString(QStringLiteral("2017-09-24T00:00:00Z"), Qt::ISODate); |
| 45 | xCol->replaceDateTimes(-1, QVector<QDateTime>({dt1, dt2, dt3})); |
| 46 | |
| 47 | auto* yCol = spreadsheetData->column(1); |
| 48 | yCol->replaceValues(-1, QVector<double>({2., 3., 4.})); |
| 49 | |
| 50 | QCOMPARE(spreadsheetData->rowCount(), 3); |
| 51 | QCOMPARE(spreadsheetData->columnCount(), 2); |
| 52 | |
| 53 | auto* p = new CartesianPlot(QStringLiteral("plot")); |
| 54 | p->setType(CartesianPlot::Type::TwoAxes); // Otherwise no axes are created |
| 55 | p->setNiceExtend(false); |
| 56 | QVERIFY(p != nullptr); |
| 57 | ws->addChild(p); |
| 58 | |
| 59 | auto* curve = new XYCurve(QStringLiteral("xy-curve")); |
| 60 | curve->setXColumn(xCol); |
| 61 | curve->setYColumn(yCol); |
| 62 | p->addChild(curve); |
| 63 | |
| 64 | auto axes = p->children<Axis>(); |
| 65 | QCOMPARE(axes.count(), 2); |
| 66 | QCOMPARE(axes.at(0)->name(), QStringLiteral("x")); |
| 67 | QCOMPARE(axes.at(1)->name(), QStringLiteral("y")); |
| 68 | |
| 69 | auto* xAxis = static_cast<Axis*>(axes.at(0)); |
| 70 | xAxis->setMajorTicksNumber(3, false); |
| 71 | QCOMPARE(xAxis->range().start(), dt1.toMSecsSinceEpoch()); |
| 72 | QCOMPARE(xAxis->range().end(), dt3.toMSecsSinceEpoch()); |
| 73 | QCOMPARE(xAxis->majorTicksType(), Axis::TicksType::TotalNumber); |
| 74 | QCOMPARE(xAxis->majorTicksNumber(), 3); |
| 75 | xAxis->setLabelsDateTimeFormat(QStringLiteral("yyyy-MM-dd hh:mm:ss")); |
| 76 | QCOMPARE(xAxis->labelsTextType(), Axis::LabelsTextType::PositionValues); |
| 77 | |
| 78 | { |
| 79 | const auto v = xAxis->tickLabelStrings(); |
| 80 | QStringList expectedStrings{ |
| 81 | QStringLiteral("2017-07-24 00:00:00"), |
| 82 | QStringLiteral("2017-08-24 00:00:00"), |
| 83 | QStringLiteral("2017-09-24 00:00:00"), |
| 84 | }; |
| 85 | COMPARE_STRING_VECTORS(xAxis->tickLabelStrings(), expectedStrings); |
no test coverage detected