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

Method customColumnDateTime

tests/backend/Axis/AxisTest3.cpp:1047–1143  ·  view source on GitHub ↗

! * \brief AxisTest3::customColumnDateTime * Test setting a custom column as major tick once with the custom column values and * once with another column as ticks label */

Source from the content-addressed store, hash-verified

1045 * once with another column as ticks label
1046 */
1047void AxisTest3::customColumnDateTime() {
1048 Project project;
1049 auto* ws = new Worksheet(QStringLiteral("worksheet"));
1050 QVERIFY(ws != nullptr);
1051 project.addChild(ws);
1052 ws->setPageRect(QRectF(0, 0, 300, 300));
1053 ws->setLayoutBottomMargin(0);
1054 ws->setLayoutTopMargin(0);
1055 ws->setLayoutRightMargin(0);
1056 ws->setLayoutLeftMargin(0);
1057
1058 Spreadsheet* spreadsheetData = new Spreadsheet(QStringLiteral("data"), false);
1059 spreadsheetData->setColumnCount(2);
1060 spreadsheetData->setRowCount(3);
1061 project.addChild(spreadsheetData);
1062 auto* xCol = spreadsheetData->column(0);
1063 xCol->setColumnMode(AbstractColumn::ColumnMode::DateTime);
1064 QDateTime dt1 = QDateTime::fromString(QStringLiteral("2017-07-24T00:00:00Z"), Qt::ISODate);
1065 QDateTime dt2 = QDateTime::fromString(QStringLiteral("2017-07-25T00:00:00Z"), Qt::ISODate);
1066 QDateTime dt3 = QDateTime::fromString(QStringLiteral("2019-07-26T00:00:00Z"), Qt::ISODate);
1067 xCol->replaceDateTimes(-1, QVector<QDateTime>({dt1, dt2, dt3}));
1068 auto* yCol = spreadsheetData->column(1);
1069 yCol->replaceValues(-1, QVector<double>({2., 3., 4.}));
1070
1071 Spreadsheet* spreadsheetLabels = new Spreadsheet(QStringLiteral("labels"), false);
1072 spreadsheetLabels->setColumnCount(2);
1073 spreadsheetLabels->setRowCount(3);
1074 project.addChild(spreadsheetLabels);
1075 auto* posCol = spreadsheetLabels->column(0);
1076 posCol->setColumnMode(AbstractColumn::ColumnMode::DateTime);
1077 QDateTime dt1Label = QDateTime::fromString(QStringLiteral("2017-07-24T11:03:02Z"), Qt::ISODate);
1078 QDateTime dt2Label = QDateTime::fromString(QStringLiteral("2017-07-24T15:30:00Z"), Qt::ISODate);
1079 QDateTime dt3Label = QDateTime::fromString(QStringLiteral("2019-07-25T13:25:00Z"), Qt::ISODate);
1080 posCol->replaceDateTimes(-1, QVector<QDateTime>({dt1Label, dt2Label, dt3Label}));
1081 auto* labelsCol = spreadsheetLabels->column(1);
1082 labelsCol->setColumnMode(AbstractColumn::ColumnMode::Text);
1083 labelsCol->replaceTexts(-1, QVector<QString>({QStringLiteral("first"), QStringLiteral("second"), QStringLiteral("third")}));
1084
1085 auto* p = new CartesianPlot(QStringLiteral("plot"));
1086 p->setType(CartesianPlot::Type::TwoAxes); // Otherwise no axes are created
1087 p->setNiceExtend(false);
1088 QVERIFY(p != nullptr);
1089 p->setBottomPadding(0);
1090 p->setHorizontalPadding(0);
1091 p->setRightPadding(0);
1092 p->setVerticalPadding(0);
1093 ws->addChild(p);
1094
1095 auto* curve = new XYCurve(QStringLiteral("xy-curve"));
1096 curve->setXColumn(xCol);
1097 curve->setYColumn(yCol);
1098 p->addChild(curve);
1099
1100 auto axes = p->children<Axis>();
1101 QCOMPARE(axes.count(), 2);
1102 QCOMPARE(axes.at(0)->name(), QStringLiteral("x"));
1103 QCOMPARE(axes.at(1)->name(), QStringLiteral("y"));
1104

Callers

nothing calls this directly

Calls 15

QRectFClass · 0.85
setPageRectMethod · 0.80
setNiceExtendMethod · 0.80
setBottomPaddingMethod · 0.80
setHorizontalPaddingMethod · 0.80
setRightPaddingMethod · 0.80
setVerticalPaddingMethod · 0.80
setYColumnMethod · 0.80
rangeMethod · 0.80
setMajorTicksTypeMethod · 0.80
setMajorTicksColumnMethod · 0.80
tickLabelStringsMethod · 0.80

Tested by

no test coverage detected