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

Method dateTimeSpacingOffsetNonZero

tests/backend/Axis/AxisTest3.cpp:160–235  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

158}
159
160void AxisTest3::dateTimeSpacingOffsetNonZero() {
161 QLocale::setDefault(QLocale::C); // use . as decimal separator
162 Project project;
163 auto* ws = new Worksheet(QStringLiteral("worksheet"));
164 QVERIFY(ws != nullptr);
165 project.addChild(ws);
166
167 Spreadsheet* spreadsheetData = new Spreadsheet(QStringLiteral("data"), false);
168 spreadsheetData->setColumnCount(2);
169 spreadsheetData->setRowCount(3);
170 project.addChild(spreadsheetData);
171
172 auto* xCol = spreadsheetData->column(0);
173 xCol->setColumnMode(AbstractColumn::ColumnMode::DateTime);
174 QDateTime dt1 = QDateTime::fromString(QStringLiteral("2017-07-24T00:00:00Z"), Qt::ISODate);
175 QDateTime dt2 = QDateTime::fromString(QStringLiteral("2017-11-24T12:03:00Z"), Qt::ISODate);
176 QDateTime dt3 = QDateTime::fromString(QStringLiteral("2019-12-24T00:05:03Z"), Qt::ISODate);
177 xCol->replaceDateTimes(-1, QVector<QDateTime>({dt1, dt2, dt3}));
178
179 auto* yCol = spreadsheetData->column(1);
180 yCol->replaceValues(-1, QVector<double>({2., 3., 4.}));
181
182 QCOMPARE(spreadsheetData->rowCount(), 3);
183 QCOMPARE(spreadsheetData->columnCount(), 2);
184
185 auto* p = new CartesianPlot(QStringLiteral("plot"));
186 p->setType(CartesianPlot::Type::TwoAxes); // Otherwise no axes are created
187 p->setNiceExtend(false);
188 QVERIFY(p != nullptr);
189 ws->addChild(p);
190
191 auto* curve = new XYCurve(QStringLiteral("xy-curve"));
192 curve->setXColumn(xCol);
193 curve->setYColumn(yCol);
194 p->addChild(curve);
195
196 auto axes = p->children<Axis>();
197 QCOMPARE(axes.count(), 2);
198 QCOMPARE(axes.at(0)->name(), QStringLiteral("x"));
199 QCOMPARE(axes.at(1)->name(), QStringLiteral("y"));
200
201 auto* xAxis = static_cast<Axis*>(axes.at(0));
202 xAxis->setMajorTicksSpacing(DateTime::createValue(0, 1, 0, 0, 0, 0, 0)); // 1 month
203 QCOMPARE(xAxis->range().start(), dt1.toMSecsSinceEpoch());
204 QCOMPARE(xAxis->range().end(), dt3.toMSecsSinceEpoch());
205 xAxis->setMajorTicksType(Axis::TicksType::Spacing);
206 // QCOMPARE(xAxis->majorTicksNumber(), 3);
207 xAxis->setLabelsDateTimeFormat(QStringLiteral("yyyy-MM-dd hh:mm:ss"));
208 QCOMPARE(xAxis->labelsTextType(), Axis::LabelsTextType::PositionValues);
209 QCOMPARE(xAxis->majorTicksStartType(), Axis::TicksStartType::Offset);
210 xAxis->setMajorTickStartOffset(DateTime::createValue(1, 2, 3, 4, 5, 6, 7));
211 QVERIFY(xAxis->majorTickStartOffset() > 0);
212 QCOMPARE(xAxis->majorTickStartValue(), 0);
213
214 {
215 const auto v = xAxis->tickLabelStrings();
216 QStringList expectedStrings{
217 QStringLiteral("2018-09-27 04:05:06"),

Callers

nothing calls this directly

Calls 15

createValueFunction · 0.85
setNiceExtendMethod · 0.80
setYColumnMethod · 0.80
setMajorTicksSpacingMethod · 0.80
rangeMethod · 0.80
setMajorTicksTypeMethod · 0.80
tickLabelStringsMethod · 0.80
addChildMethod · 0.45
setColumnCountMethod · 0.45
setRowCountMethod · 0.45

Tested by

no test coverage detected