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

Method removeCurves

tests/backend/XYCurve/XYFunctionCurveTest.cpp:108–166  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

106}
107
108void XYFunctionCurveTest::removeCurves() {
109 Project project;
110 auto* ws = new Worksheet(QStringLiteral("Worksheet"));
111 QVERIFY(ws != nullptr);
112 project.addChild(ws);
113
114 auto* p = new CartesianPlot(QStringLiteral("plot"));
115 p->setType(CartesianPlot::Type::TwoAxes); // Otherwise no axis are created
116 QVERIFY(p != nullptr);
117 ws->addChild(p);
118
119 // Generate data and
120 Spreadsheet* sheet = new Spreadsheet(QStringLiteral("Spreadsheet"), false);
121 project.addChild(sheet);
122 sheet->setColumnCount(2);
123 sheet->setRowCount(11);
124 sheet->column(0)->setColumnMode(AbstractColumn::ColumnMode::Double);
125 sheet->column(1)->setColumnMode(AbstractColumn::ColumnMode::Double);
126
127 for (int i = 0; i < sheet->rowCount(); i++) {
128 sheet->column(0)->setValueAt(i, i);
129 sheet->column(1)->setValueAt(i, 2 * i + 1);
130 }
131
132 auto* curve = new XYCurve(QStringLiteral("curve1"));
133 p->addChild(curve);
134 curve->setCoordinateSystemIndex(0);
135 curve->setXColumn(sheet->column(0));
136 curve->setYColumn(sheet->column(1));
137
138 p->addChild(new XYFunctionCurve(QLatin1String("eq2")));
139 auto functionCurves = p->children(AspectType::XYFunctionCurve);
140 QCOMPARE(functionCurves.count(), 1);
141 auto* functionCurve = static_cast<XYFunctionCurve*>(functionCurves.at(0));
142
143 auto dock = XYFunctionCurveDock(nullptr);
144 dock.setupGeneral();
145 dock.setCurves({functionCurve});
146
147 functionCurve->setFunction(QStringLiteral("2*x"), {QStringLiteral("x")}, {curve});
148
149 {
150 const auto* xColumn = functionCurve->xColumn();
151 const auto* yColumn = functionCurve->yColumn();
152 QCOMPARE(xColumn->rowCount(), 11);
153 QCOMPARE(yColumn->rowCount(), 11);
154 for (int i = 0; i < xColumn->rowCount(); i++) {
155 VALUES_EQUAL(xColumn->valueAt(i), (double)i);
156 VALUES_EQUAL(yColumn->valueAt(i), 2 * (2 * i + 1.));
157 }
158 }
159
160 curve->remove();
161
162 QCOMPARE(functionCurve->xColumn()->rowCount(), 0);
163 QCOMPARE(functionCurve->functionData().count(), 1);
164 QCOMPARE(functionCurve->functionData().at(0).curve(), nullptr);
165 QCOMPARE(functionCurve->functionData().at(0).curvePath(), i18n("Project") + QStringLiteral("/Worksheet/plot/curve1"));

Callers

nothing calls this directly

Calls 15

setYColumnMethod · 0.80
setFunctionMethod · 0.80
curveMethod · 0.80
curvePathMethod · 0.80
XYFunctionCurveDockClass · 0.50
addChildMethod · 0.45
setTypeMethod · 0.45
setColumnCountMethod · 0.45
setRowCountMethod · 0.45
setColumnModeMethod · 0.45
columnMethod · 0.45

Tested by

no test coverage detected