| 87 | } |
| 88 | |
| 89 | void AxisTest3::dateTimeSpacing() { |
| 90 | QLocale::setDefault(QLocale::C); // use . as decimal separator |
| 91 | Project project; |
| 92 | auto* ws = new Worksheet(QStringLiteral("worksheet")); |
| 93 | QVERIFY(ws != nullptr); |
| 94 | project.addChild(ws); |
| 95 | |
| 96 | Spreadsheet* spreadsheetData = new Spreadsheet(QStringLiteral("data"), false); |
| 97 | spreadsheetData->setColumnCount(2); |
| 98 | spreadsheetData->setRowCount(3); |
| 99 | project.addChild(spreadsheetData); |
| 100 | |
| 101 | auto* xCol = spreadsheetData->column(0); |
| 102 | xCol->setColumnMode(AbstractColumn::ColumnMode::DateTime); |
| 103 | QDateTime dt1 = QDateTime::fromString(QStringLiteral("2017-07-24T00:00:00Z"), Qt::ISODate); |
| 104 | QDateTime dt2 = QDateTime::fromString(QStringLiteral("2017-11-24T12:03:00Z"), Qt::ISODate); |
| 105 | QDateTime dt3 = QDateTime::fromString(QStringLiteral("2017-12-24T00:05:03Z"), Qt::ISODate); |
| 106 | xCol->replaceDateTimes(-1, QVector<QDateTime>({dt1, dt2, dt3})); |
| 107 | |
| 108 | auto* yCol = spreadsheetData->column(1); |
| 109 | yCol->replaceValues(-1, QVector<double>({2., 3., 4.})); |
| 110 | |
| 111 | QCOMPARE(spreadsheetData->rowCount(), 3); |
| 112 | QCOMPARE(spreadsheetData->columnCount(), 2); |
| 113 | |
| 114 | auto* p = new CartesianPlot(QStringLiteral("plot")); |
| 115 | p->setType(CartesianPlot::Type::TwoAxes); // Otherwise no axes are created |
| 116 | p->setNiceExtend(false); |
| 117 | QVERIFY(p != nullptr); |
| 118 | ws->addChild(p); |
| 119 | |
| 120 | auto* curve = new XYCurve(QStringLiteral("xy-curve")); |
| 121 | curve->setXColumn(xCol); |
| 122 | curve->setYColumn(yCol); |
| 123 | p->addChild(curve); |
| 124 | |
| 125 | auto axes = p->children<Axis>(); |
| 126 | QCOMPARE(axes.count(), 2); |
| 127 | QCOMPARE(axes.at(0)->name(), QStringLiteral("x")); |
| 128 | QCOMPARE(axes.at(1)->name(), QStringLiteral("y")); |
| 129 | |
| 130 | auto* xAxis = static_cast<Axis*>(axes.at(0)); |
| 131 | xAxis->setMajorTicksSpacing(DateTime::createValue(0, 1, 0, 0, 0, 0, 0)); // 1 month |
| 132 | QCOMPARE(xAxis->range().start(), dt1.toMSecsSinceEpoch()); |
| 133 | QCOMPARE(xAxis->range().end(), dt3.toMSecsSinceEpoch()); |
| 134 | xAxis->setMajorTicksType(Axis::TicksType::Spacing); |
| 135 | // QCOMPARE(xAxis->majorTicksNumber(), 3); |
| 136 | xAxis->setLabelsDateTimeFormat(QStringLiteral("yyyy-MM-dd hh:mm:ss")); |
| 137 | QCOMPARE(xAxis->labelsTextType(), Axis::LabelsTextType::PositionValues); |
| 138 | QCOMPARE(xAxis->majorTicksStartType(), Axis::TicksStartType::Offset); |
| 139 | QCOMPARE(xAxis->majorTickStartOffset(), 0); |
| 140 | QCOMPARE(xAxis->majorTickStartValue(), 0); |
| 141 | |
| 142 | { |
| 143 | const auto v = xAxis->tickLabelStrings(); |
| 144 | QStringList expectedStrings{ |
| 145 | QStringLiteral("2017-07-24 00:00:00"), |
| 146 | QStringLiteral("2017-08-24 00:00:00"), |
nothing calls this directly
no test coverage detected