refactor(iomodbus): rebase PicklistDelegate onto the kit InstrumentDelegate (BL-DS-P3 carry-over)

This commit is contained in:
2026-06-11 13:53:23 -04:00
parent 20ca6d1105
commit 8e79964a8c
3 changed files with 24 additions and 3 deletions

View File

@@ -6,6 +6,10 @@ labels (an off-catalog device value), it's inserted at the top so it stays visib
isn't silently lost. The chosen *label* is written back through the model, so the
existing ``on_edit -> write_cell -> codecs.selection`` path maps it to the numeric value
unchanged. Non-pick-list cells fall through to the default editor.
Rebased onto ``InstrumentDelegate`` (kit §5.4/§5.6): hover affordance, edge bars,
alarm tint, the styled in-place editor, and write feedback (``mark_pending``/``resolve``)
now apply to all register-grid cells without any extra wiring.
"""
from __future__ import annotations
@@ -13,7 +17,9 @@ from __future__ import annotations
from typing import TYPE_CHECKING
from PySide6.QtCore import Qt
from PySide6.QtWidgets import QComboBox, QStyledItemDelegate
from PySide6.QtWidgets import QComboBox
from cim_suite.core.ui.kit import InstrumentDelegate
from ..protocol.codecs import parse_picklist
@@ -21,7 +27,7 @@ if TYPE_CHECKING:
from .register_grid import RegisterGrid
class PicklistDelegate(QStyledItemDelegate):
class PicklistDelegate(InstrumentDelegate):
def __init__(self, grid: RegisterGrid) -> None:
super().__init__(grid.table)
self._grid = grid

View File

@@ -29,7 +29,9 @@ class RegisterGrid(TableTab):
self._row_cells: list[list[RegisterCell | None]] = []
controller.deviceSelected.connect(self.rebuild)
controller.cellUpdated.connect(self._on_cell)
self.table.setItemDelegate(PicklistDelegate(self))
delegate = PicklistDelegate(self)
self.table.setItemDelegate(delegate)
self.delegate = delegate # keep TableTab.delegate pointing at the installed one
# subclasses build (rows, row_cells) and may set headers
def _collect(self) -> tuple[list[list[str]], list[list[RegisterCell | None]]]:

View File

@@ -125,3 +125,16 @@ def test_setModelData_routes_label_to_model(qtbot):
combo.setCurrentIndex(1) # "Reversed"
delegate.setModelData(combo, grid.table.model(), index)
assert grid.table.item(0, 1).text() == "Reversed"
def test_picklist_delegate_is_an_instrument_delegate(qtbot, catalog):
from cim_suite.core.ui.kit import InstrumentDelegate
from cim_suite.modules.iomodbus.domain.controller import ModbusController
from cim_suite.modules.iomodbus.ui.channels_tab import ChannelsTab
ctrl = ModbusController(catalog)
tab = ChannelsTab(ctrl)
qtbot.addWidget(tab)
assert isinstance(tab.table.itemDelegate(), InstrumentDelegate)
# TableTab.delegate must reference the INSTALLED delegate (write feedback uses it)
assert tab.delegate is tab.table.itemDelegate()