diff --git a/app/src/ui/runtime_monitor_widget.cpp b/app/src/ui/runtime_monitor_widget.cpp index af1629e..6aad488 100644 --- a/app/src/ui/runtime_monitor_widget.cpp +++ b/app/src/ui/runtime_monitor_widget.cpp @@ -43,7 +43,11 @@ void RuntimeMonitorWidget::setProjectObjects( const std::string &page_id, const std::string &logic_id) { hmi_view_->setPageId(page_id); + // 运行视图是独立投影,同一页面的控件也可能已在编辑视图中发生变化 + hmi_view_->reloadPage(); logic_view_->setLogicId(logic_id); + // 同一逻辑 ID 下的网络结构变化同样需要在首次扫描前立即可见 + logic_view_->reloadLogic(); } void RuntimeMonitorWidget::setMode( diff --git a/app/tests/main_window_tests.cpp b/app/tests/main_window_tests.cpp index 17abd76..abeec82 100644 --- a/app/tests/main_window_tests.cpp +++ b/app/tests/main_window_tests.cpp @@ -212,6 +212,7 @@ void testModeActionsControlEditingAvailability() QAction *offline_action = requiredChild(window, "offlineModeAction"); QAction *online_action = requiredChild(window, "onlineModeAction"); QAction *add_button_action = requiredChild(window, "addButtonAction"); + QAction *add_indicator_action = requiredChild(window, "addIndicatorAction"); QAction *delete_control_action = requiredChild(window, "deleteControlAction"); QAction *add_normally_open_action = requiredChild( window, "addNormallyOpenAction"); @@ -269,6 +270,14 @@ void testModeActionsControlEditingAvailability() require(editor_service.findPage(page_id)->controls.empty(), "deleting a selected control must update the HMI page model"); + add_indicator_action->trigger(); + HmiControl runtime_indicator = *editor_service.findControl(page_id, "indicator-1"); + runtime_indicator.binding = RegisterAddress{RegisterArea::M, 3}; + require(editor_service.updateControl( + page_id, runtime_indicator.id, runtime_indicator).succeeded, + "a configured HMI control must be available for the runtime projection"); + hmi_editor->reloadPage(); + add_normally_open_action->trigger(); parallel_insert_action->trigger(); add_normal_coil_action->trigger(); @@ -326,6 +335,10 @@ void testModeActionsControlEditingAvailability() require(runtime_tab->isVisible() && runtime_hmi->isVisible() && runtime_logic->isVisible() && free_monitor->isVisible(), "offline running must show HMI, ladder trace and free monitor together"); + auto *runtime_hmi_view = qobject_cast(runtime_hmi); + require(runtime_hmi_view != nullptr + && runtime_hmi_view->scene()->items().size() == 2, + "offline runtime HMI must project the configured page control"); QLineEdit *monitor_address = requiredChild(window, "addressEdit"); QPushButton *monitor_add = requiredChild(window, "addButton"); QTableWidget *monitor_table = requiredChild(window, "monitorTable");