| 235 | } |
| 236 | |
| 237 | void AxisTest3::dateTimeSpacingStartValueNonZero() { |
| 238 | QLocale::setDefault(QLocale::C); // use . as decimal separator |
| 239 | Project project; |
| 240 | auto* ws = new Worksheet(QStringLiteral("worksheet")); |
| 241 | QVERIFY(ws != nullptr); |
| 242 | project.addChild(ws); |
| 243 | |
| 244 | Spreadsheet* spreadsheetData = new Spreadsheet(QStringLiteral("data"), false); |
| 245 | spreadsheetData->setColumnCount(2); |
| 246 | spreadsheetData->setRowCount(3); |
| 247 | project.addChild(spreadsheetData); |
| 248 | |
| 249 | auto* xCol = spreadsheetData->column(0); |
| 250 | xCol->setColumnMode(AbstractColumn::ColumnMode::DateTime); |
| 251 | QDateTime dt1 = QDateTime::fromString(QStringLiteral("2017-07-24T00:00:00Z"), Qt::ISODate); |
| 252 | QDateTime dt2 = QDateTime::fromString(QStringLiteral("2017-11-24T12:03:00Z"), Qt::ISODate); |
| 253 | QDateTime dt3 = QDateTime::fromString(QStringLiteral("2019-03-01T00:00:00Z"), Qt::ISODate); |
| 254 | xCol->replaceDateTimes(-1, QVector<QDateTime>({dt1, dt2, dt3})); |
| 255 | |
| 256 | auto* yCol = spreadsheetData->column(1); |
| 257 | yCol->replaceValues(-1, QVector<double>({2., 3., 4.})); |
| 258 | |
| 259 | QCOMPARE(spreadsheetData->rowCount(), 3); |
| 260 | QCOMPARE(spreadsheetData->columnCount(), 2); |
| 261 | |
| 262 | auto* p = new CartesianPlot(QStringLiteral("plot")); |
| 263 | p->setType(CartesianPlot::Type::TwoAxes); // Otherwise no axes are created |
| 264 | p->setNiceExtend(false); |
| 265 | QVERIFY(p != nullptr); |
| 266 | ws->addChild(p); |
| 267 | |
| 268 | auto* curve = new XYCurve(QStringLiteral("xy-curve")); |
| 269 | curve->setXColumn(xCol); |
| 270 | curve->setYColumn(yCol); |
| 271 | p->addChild(curve); |
| 272 | |
| 273 | auto axes = p->children<Axis>(); |
| 274 | QCOMPARE(axes.count(), 2); |
| 275 | QCOMPARE(axes.at(0)->name(), QStringLiteral("x")); |
| 276 | QCOMPARE(axes.at(1)->name(), QStringLiteral("y")); |
| 277 | |
| 278 | auto* xAxis = static_cast<Axis*>(axes.at(0)); |
| 279 | xAxis->setMajorTicksSpacing(DateTime::createValue(0, 1, 0, 0, 0, 0, 0)); // 1 month |
| 280 | QCOMPARE(xAxis->range().start(), dt1.toMSecsSinceEpoch()); |
| 281 | QCOMPARE(xAxis->range().end(), dt3.toMSecsSinceEpoch()); |
| 282 | xAxis->setMajorTicksType(Axis::TicksType::Spacing); |
| 283 | // QCOMPARE(xAxis->majorTicksNumber(), 3); |
| 284 | xAxis->setLabelsDateTimeFormat(QStringLiteral("yyyy-MM-dd hh:mm:ss")); |
| 285 | QCOMPARE(xAxis->labelsTextType(), Axis::LabelsTextType::PositionValues); |
| 286 | xAxis->setMajorTicksStartType(Axis::TicksStartType::Absolute); |
| 287 | xAxis->setMajorTickStartValue(QDateTime::fromString(QStringLiteral("2018-09-27T16:05:06Z"), Qt::ISODate).toMSecsSinceEpoch()); |
| 288 | QVERIFY(xAxis->majorTickStartValue() > 0); |
| 289 | { |
| 290 | const auto v = xAxis->tickLabelStrings(); |
| 291 | QStringList expectedStrings{ |
| 292 | QStringLiteral("2018-09-27 16:05:06"), |
| 293 | QStringLiteral("2018-10-27 16:05:06"), |
| 294 | QStringLiteral("2018-11-27 16:05:06"), |
nothing calls this directly
no test coverage detected