! * test save and restore of the project with the activated option "save calculations", * the results of calculations are saved into and read from project's XML.' */
| 174 | * the results of calculations are saved into and read from project's XML.' |
| 175 | */ |
| 176 | void CommonAnalysisTest::saveRestoreWithCalculations() { |
| 177 | QString savePath; |
| 178 | |
| 179 | // save |
| 180 | { |
| 181 | Project project; |
| 182 | project.setSaveCalculations(true); |
| 183 | auto* ws = new Worksheet(QStringLiteral("Worksheet")); |
| 184 | project.addChild(ws); |
| 185 | |
| 186 | auto* plot = new CartesianPlot(QStringLiteral("plot")); |
| 187 | ws->addChild(plot); |
| 188 | |
| 189 | auto* sheet = new Spreadsheet(QStringLiteral("sheet")); |
| 190 | project.addChild(sheet); |
| 191 | sheet->setColumnCount(2); |
| 192 | sheet->setRowCount(2); |
| 193 | sheet->column(0)->setValueAt(0, 1); |
| 194 | sheet->column(0)->setValueAt(1, 2); |
| 195 | sheet->column(1)->setValueAt(0, 1); |
| 196 | sheet->column(1)->setValueAt(1, 2); |
| 197 | |
| 198 | auto* fitCurve = new XYFitCurve(QStringLiteral("fit")); |
| 199 | plot->addChild(fitCurve); |
| 200 | fitCurve->setDataSourceType(XYAnalysisCurve::DataSourceType::Spreadsheet); |
| 201 | fitCurve->setXDataColumn(sheet->column(0)); |
| 202 | fitCurve->setYDataColumn(sheet->column(1)); |
| 203 | |
| 204 | // perform the fit |
| 205 | XYFitCurve::FitData fitData = fitCurve->fitData(); |
| 206 | fitData.modelCategory = nsl_fit_model_basic; |
| 207 | fitData.modelType = nsl_fit_model_polynomial; |
| 208 | fitData.degree = 1; |
| 209 | XYFitCurve::initFitData(fitData); |
| 210 | fitCurve->setFitData(fitData); |
| 211 | fitCurve->recalculate(); |
| 212 | |
| 213 | SAVE_PROJECT("saveRestoreWithCalculations"); |
| 214 | } |
| 215 | |
| 216 | // load the project and verify the columns in the analysis curve have valid data |
| 217 | { |
| 218 | Project project; |
| 219 | QCOMPARE(project.load(savePath), true); |
| 220 | |
| 221 | const auto* ws = project.child<Worksheet>(0); |
| 222 | QVERIFY(ws); |
| 223 | const auto* plot = ws->child<CartesianPlot>(0); |
| 224 | QVERIFY(plot); |
| 225 | const auto* curve = plot->child<XYCurve>(0); |
| 226 | QVERIFY(curve); |
| 227 | const auto* fitCurve = plot->child<XYFitCurve>(0); |
| 228 | QVERIFY(fitCurve); |
| 229 | |
| 230 | // TODO: check to make sure no recalculate() was called. |
| 231 | |
| 232 | // the number of valid (non-empty) values should be greater than 0 |
| 233 | QVERIFY(fitCurve->xColumn()); |
nothing calls this directly
no test coverage detected