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

Method dateTime

tests/backend/Axis/AxisTest3.cpp:28–87  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26#include <QUndoStack>
27
28void 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);

Callers 7

testParserPython06Method · 0.45
testParserPython07Method · 0.45
testParserPython08Method · 0.45
testParserPython09Method · 0.45
testParserPython10Method · 0.45
helperMacros.hFile · 0.45

Calls 15

setNiceExtendMethod · 0.80
setYColumnMethod · 0.80
setMajorTicksNumberMethod · 0.80
rangeMethod · 0.80
tickLabelStringsMethod · 0.80
addChildMethod · 0.45
setColumnCountMethod · 0.45
setRowCountMethod · 0.45
columnMethod · 0.45
setColumnModeMethod · 0.45
replaceDateTimesMethod · 0.45

Tested by

no test coverage detected