| 311 | } |
| 312 | |
| 313 | void restoreNode( |
| 314 | const LayoutNode& node, DockWidget* widget, RestorePlotPool& pool, |
| 315 | const PlotDocker::ObjectWidgetFactory& object_factory) { |
| 316 | if (widget == nullptr) { |
| 317 | return; |
| 318 | } |
| 319 | |
| 320 | if (node.type == LayoutNode::Type::kArea) { |
| 321 | widget->setStateId(node.area_id); |
| 322 | widget->setName(node.area_name.isEmpty() ? QStringLiteral("...") : node.area_name); |
| 323 | |
| 324 | const QDomElement dock_element = node.plots.isEmpty() ? QDomElement{} : node.plots.front(); |
| 325 | |
| 326 | if (isObjectWidgetElement(dock_element)) { |
| 327 | // Object-widget path: build an empty dock by kind (the XML tag), then ask |
| 328 | // it to load its own payload. Unknown kind (no factory / null result) → |
| 329 | // leave the dock as-is rather than mis-parsing a scene element as a plot. |
| 330 | IDataWidget* obj = object_factory ? object_factory(dock_element.tagName(), nullptr, widget) : nullptr; |
| 331 | if (obj != nullptr) { |
| 332 | widget->setObjectWidget(obj); |
| 333 | obj->xmlLoadState(dock_element); |
| 334 | } |
| 335 | return; |
| 336 | } |
| 337 | |
| 338 | // Plot path |
| 339 | PlotWidget* plot = widget->plotWidget(); |
| 340 | if (plot == nullptr) { |
| 341 | plot = pool.takeForArea(node); |
| 342 | widget->setPlotWidget(plot); |
| 343 | } |
| 344 | if (!dock_element.isNull()) { |
| 345 | plot->xmlLoadState(dock_element); |
| 346 | } else { |
| 347 | plot->removeAllCurves(); |
| 348 | } |
| 349 | return; |
| 350 | } |
| 351 | |
| 352 | if (node.children.isEmpty()) { |
| 353 | return; |
| 354 | } |
| 355 | |
| 356 | QVector<DockWidget*> widgets; |
| 357 | widgets.push_back(widget); |
| 358 | DockWidget* split_anchor = widget; |
| 359 | for (qsizetype index = 1; index < node.children.size(); ++index) { |
| 360 | const LayoutNode& child = node.children.at(index); |
| 361 | const bool child_is_object = isObjectWidgetElement(firstLeafElement(child)); |
| 362 | if (child_is_object) { |
| 363 | // No plot needed — the leaf will install an object widget itself. |
| 364 | split_anchor = |
| 365 | node.orientation == Qt::Horizontal ? split_anchor->splitHorizontal() : split_anchor->splitVertical(); |
| 366 | } else { |
| 367 | PlotWidget* child_plot = pool.takeFirstForNode(child); |
| 368 | split_anchor = node.orientation == Qt::Horizontal ? split_anchor->splitHorizontal(child_plot) |
| 369 | : split_anchor->splitVertical(child_plot); |
| 370 | } |
no test coverage detected