fix: 终极状态回滚 + 三个 panel 短路径导包修复

- water_quality_gui_v2.py:回滚机制由 panel_registry.get_tab_index 改为基于 PANEL_REGISTRY[current_tab_idx]['step_id'] 的索引反查,消除不存在的 get_tab_index 导致回滚期间二次崩溃并被静默吞噬的幽灵跳步根因
This commit is contained in:
DXC
2026-06-18 14:55:14 +08:00
parent e5bb9c5cd9
commit b2435d66c3
4 changed files with 11 additions and 13 deletions

View File

@ -482,22 +482,20 @@ class WaterQualityGUI(QMainWindow):
QMessageBox.critical(self, "面板加载失败",
f"加载页面时发生严重错误:\n{e}\n\n详见终端日志。")
# ====== 新增:状态回滚(解决幽灵跳转/假死) ======
# 既然右侧未能成功切换,必须强制将左侧导航栏的选中项退回到与右侧一致
# ====== 终极状态回滚机制 ======
self._step_list.blockSignals(True)
try:
current_tab_idx = self._tab_widget.currentIndex()
from src.gui.core.panel_registry import get_tab_index
# 遍历左侧列表,找到属于当前显示的 tab_index 的那个 step
for i in range(self._step_list.count()):
item_node = self._step_list.item(i)
if item_node:
node_data = item_node.data(Qt.UserRole)
if node_data and node_data != "stage_header" and get_tab_index(node_data) == current_tab_idx:
from src.gui.core.panel_registry import PANEL_REGISTRY
if 0 <= current_tab_idx < len(PANEL_REGISTRY):
correct_step_id = PANEL_REGISTRY[current_tab_idx]['step_id']
for i in range(self._step_list.count()):
item_node = self._step_list.item(i)
if item_node and item_node.data(Qt.UserRole) == correct_step_id:
self._step_list.setCurrentRow(i)
break
except Exception:
pass # 回滚期间如果发生异常,默默忽略,防止二次崩溃
pass
finally:
self._step_list.blockSignals(False)