* @brief Deserialises a project from an in-memory QJsonDocument; older-schema * loads deliberately drop customizeWorkspaces and clear m_workspaces because * migrated projects can carry stale refs that would blank the dashboard, so * forcing the auto layout is preferred over honouring those refs. */
| 2399 | * forcing the auto layout is preferred over honouring those refs. |
| 2400 | */ |
| 2401 | bool DataModel::ProjectModel::loadFromJsonDocument(const QJsonDocument& document, |
| 2402 | const QString& sourcePath) |
| 2403 | { |
| 2404 | if (document.isEmpty()) |
| 2405 | return false; |
| 2406 | |
| 2407 | m_autoSaveSuspended = true; |
| 2408 | if (m_autoSaveTimer) |
| 2409 | m_autoSaveTimer->stop(); |
| 2410 | |
| 2411 | m_groups.clear(); |
| 2412 | m_actions.clear(); |
| 2413 | m_sources.clear(); |
| 2414 | m_workspaces.clear(); |
| 2415 | m_widgetSettings = QJsonObject(); |
| 2416 | m_treeExpansion = QJsonObject(); |
| 2417 | m_diagramCollapse = QJsonObject(); |
| 2418 | |
| 2419 | m_filePath = sourcePath; |
| 2420 | |
| 2421 | const auto json = document.object(); |
| 2422 | const QString legacyParserCode = json.value(QLatin1StringView("frameParser")).toString(); |
| 2423 | const bool legacyUniqueIds = !json.contains(Keys::NextUniqueId); |
| 2424 | |
| 2425 | const int loadedSchema = ss_jsr(json, Keys::SchemaVersion, 0).toInt(); |
| 2426 | const bool olderSchema = loadedSchema < DataModel::kSchemaVersion; |
| 2427 | |
| 2428 | m_apiCallAllowFullSurface = ss_jsr(json, Keys::ApiCallAllowFullSurface, false).toBool(); |
| 2429 | DataModel::ScriptApiCall::setAllowFullSurface(m_apiCallAllowFullSurface); |
| 2430 | |
| 2431 | m_controlScriptCode = ss_jsr(json, Keys::ControlScriptCode, "").toString(); |
| 2432 | DataModel::ControlScript::instance().setCode(m_controlScriptCode); |
| 2433 | |
| 2434 | loadProjectRootScalars(json); |
| 2435 | loadProjectArrays(json, legacyParserCode); |
| 2436 | enforceGplSingleSource(); |
| 2437 | resolveDatasetTransformLanguages(); |
| 2438 | resolveDatasetVirtualFlags(); |
| 2439 | |
| 2440 | seedNextUniqueIdFromGroups(); |
| 2441 | loadWidgetSettingsAndWorkspaces(json); |
| 2442 | |
| 2443 | if (olderSchema) { |
| 2444 | m_customizeWorkspaces = false; |
| 2445 | m_workspaces.clear(); |
| 2446 | } |
| 2447 | |
| 2448 | if (legacyUniqueIds) { |
| 2449 | migrateLegacyWorkspaceRefs(); |
| 2450 | migrateLegacyXAxisIds(); |
| 2451 | } |
| 2452 | |
| 2453 | migrateLegacyWaterfallYAxisIds(); |
| 2454 | |
| 2455 | loadPointCount(json); |
| 2456 | loadPlotTimeRange(json); |
| 2457 | loadChangeDrivenTransforms(json); |
| 2458 | migrateLegacyLayoutKeys(); |
no test coverage detected