! * restores the column pointers from the column paths after the project was loaded and all objects instantiated. * TODO: why do we need this extra logic here and why Project::restorePointers() is not enough which is already called in ProjectParser::importTo() at the end * of the import anyway? */
| 310 | * of the import anyway? |
| 311 | */ |
| 312 | void OriginProjectParser::restorePointers(Project* project) { |
| 313 | // 1. extend the paths to contain the parent structures first |
| 314 | // 2. restore the pointers from the paths |
| 315 | const auto& columns = project->children<Column>(AbstractAspect::ChildIndexFlag::Recursive); |
| 316 | const auto& spreadsheets = project->children<Spreadsheet>(AbstractAspect::ChildIndexFlag::Recursive); |
| 317 | DEBUG(Q_FUNC_INFO << ", NUMBER of spreadsheets/columns = " << spreadsheets.count() << "/" << columns.count()) |
| 318 | |
| 319 | // xy-curves |
| 320 | const auto& curves = project->children<XYCurve>(AbstractAspect::ChildIndexFlag::Recursive); |
| 321 | for (auto* curve : curves) { |
| 322 | DEBUG(Q_FUNC_INFO << ", RESTORE CURVE with x/y column path " << STDSTRING(curve->xColumnPath()) << " " << STDSTRING(curve->yColumnPath())) |
| 323 | curve->setSuppressRetransform(true); |
| 324 | |
| 325 | // x-column |
| 326 | auto spreadsheetName = curve->xColumnPath(); |
| 327 | spreadsheetName.truncate(curve->xColumnPath().lastIndexOf(QLatin1Char('/'))); |
| 328 | // DEBUG(Q_FUNC_INFO << ", SPREADSHEET name from column: " << STDSTRING(spreadsheetName)) |
| 329 | for (const auto* spreadsheet : spreadsheets) { |
| 330 | QString container, containerPath = spreadsheet->parentAspect()->path(); |
| 331 | if (spreadsheetName.contains(QLatin1Char('/'))) { // part of a workbook |
| 332 | container = containerPath.mid(containerPath.lastIndexOf(QLatin1Char('/')) + 1) + QLatin1Char('/'); |
| 333 | containerPath = containerPath.left(containerPath.lastIndexOf(QLatin1Char('/'))); |
| 334 | } |
| 335 | // DEBUG("CONTAINER = " << STDSTRING(container)) |
| 336 | // DEBUG("CONTAINER PATH = " << STDSTRING(containerPath)) |
| 337 | // DEBUG(Q_FUNC_INFO << ", LOOP spreadsheet names = \"" << STDSTRING(container) + |
| 338 | // STDSTRING(spreadsheet->name()) << "\", path = " << STDSTRING(spreadsheetName)) |
| 339 | // DEBUG("SPREADSHEET parent path = " << STDSTRING(spreadsheet->parentAspect()->path())) |
| 340 | if (container + spreadsheet->name() == spreadsheetName) { |
| 341 | const QString& newPath = containerPath + QLatin1Char('/') + curve->xColumnPath(); |
| 342 | // DEBUG(Q_FUNC_INFO << ", SET COLUMN PATH to \"" << STDSTRING(newPath) << "\"") |
| 343 | curve->setXColumnPath(newPath); |
| 344 | |
| 345 | RESTORE_COLUMN_POINTER(curve, xColumn, XColumn); |
| 346 | break; |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | // y-column |
| 351 | spreadsheetName = curve->yColumnPath(); |
| 352 | spreadsheetName.truncate(curve->yColumnPath().lastIndexOf(QLatin1Char('/'))); |
| 353 | for (const auto* spreadsheet : spreadsheets) { |
| 354 | QString container, containerPath = spreadsheet->parentAspect()->path(); |
| 355 | if (spreadsheetName.contains(QLatin1Char('/'))) { // part of a workbook |
| 356 | container = containerPath.mid(containerPath.lastIndexOf(QLatin1Char('/')) + 1) + QLatin1Char('/'); |
| 357 | containerPath = containerPath.left(containerPath.lastIndexOf(QLatin1Char('/'))); |
| 358 | } |
| 359 | if (container + spreadsheet->name() == spreadsheetName) { |
| 360 | const QString& newPath = containerPath + QLatin1Char('/') + curve->yColumnPath(); |
| 361 | curve->setYColumnPath(newPath); |
| 362 | |
| 363 | RESTORE_COLUMN_POINTER(curve, yColumn, YColumn); |
| 364 | break; |
| 365 | } |
| 366 | } |
| 367 | DEBUG(Q_FUNC_INFO << ", curve x/y COLUMNS = " << curve->xColumn() << "/" << curve->yColumn()) |
| 368 | |
| 369 | // error columns |
nothing calls this directly
no test coverage detected