mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-13 19:21:50 +02:00
refactor(curve settings): move signal logic to SignalCombobox
This commit is contained in:
@ -90,6 +90,36 @@ class SignalComboBox(DeviceSignalInputBase, QComboBox):
|
||||
self.insertItem(0, "Hinted Signals")
|
||||
self.model().item(0).setEnabled(False)
|
||||
|
||||
def set_to_obj_name(self, obj_name: str) -> bool:
|
||||
"""
|
||||
Set the combobox to the object name of the signal.
|
||||
|
||||
Args:
|
||||
obj_name (str): Object name of the signal.
|
||||
|
||||
Returns:
|
||||
bool: True if the object name was found and set, False otherwise.
|
||||
"""
|
||||
for i in range(self.count()):
|
||||
signal_data = self.itemData(i)
|
||||
if signal_data and signal_data.get("obj_name") == obj_name:
|
||||
self.setCurrentIndex(i)
|
||||
return True
|
||||
return False
|
||||
|
||||
def set_to_first_enabled(self) -> bool:
|
||||
"""
|
||||
Set the combobox to the first enabled item.
|
||||
|
||||
Returns:
|
||||
bool: True if an enabled item was found and set, False otherwise.
|
||||
"""
|
||||
for i in range(self.count()):
|
||||
if self.model().item(i).isEnabled():
|
||||
self.setCurrentIndex(i)
|
||||
return True
|
||||
return False
|
||||
|
||||
@SafeSlot()
|
||||
def reset_selection(self):
|
||||
"""Reset the selection of the combobox."""
|
||||
|
@ -102,19 +102,10 @@ class CurveSetting(SettingWidget):
|
||||
self.device_x.setCurrentIndex(item if item != -1 else 0)
|
||||
signal_x = self.target_widget.x_axis_mode.get("entry", "")
|
||||
if signal_x:
|
||||
for i in range(self.signal_x.count()):
|
||||
signal_data = self.signal_x.itemData(i)
|
||||
if signal_data and signal_data.get("obj_name") == signal_x:
|
||||
self.signal_x.setCurrentIndex(i)
|
||||
break
|
||||
self.signal_x.set_to_obj_name(signal_x)
|
||||
else:
|
||||
# If no match is found, set to the first enabled item
|
||||
for i in range(self.signal_x.count()):
|
||||
model = self.signal_x.model()
|
||||
if model.flags(model.index(i, 0)) & Qt.ItemIsEnabled:
|
||||
self.signal_x.setCurrentIndex(i)
|
||||
break
|
||||
else:
|
||||
if not self.signal_x.set_to_first_enabled():
|
||||
# If no enabled item is found, set to the first item
|
||||
self.signal_x.setCurrentIndex(0)
|
||||
else:
|
||||
|
@ -142,20 +142,10 @@ class CurveRow(QTreeWidgetItem):
|
||||
# If the device name is not found, set the first enabled item
|
||||
self.device_edit.setCurrentIndex(0)
|
||||
|
||||
for i in range(self.entry_edit.count()):
|
||||
entry_data = self.entry_edit.itemData(i)
|
||||
if entry_data and entry_data.get("obj_name") == self.config.signal.entry:
|
||||
# If the device name matches an object name, set it
|
||||
self.entry_edit.setCurrentIndex(i)
|
||||
break
|
||||
else:
|
||||
# If no match found, set the first enabled item
|
||||
for i in range(self.entry_edit.count()):
|
||||
model = self.entry_edit.model()
|
||||
if model.flags(model.index(i, 0)) & Qt.ItemIsEnabled:
|
||||
self.entry_edit.setCurrentIndex(i)
|
||||
break
|
||||
else:
|
||||
if not self.entry_edit.set_to_obj_name(self.config.signal.entry):
|
||||
# If the entry is not found, try to set it to the first enabled item
|
||||
if not self.entry_edit.set_to_first_enabled():
|
||||
# If no enabled item is found, set to the first item
|
||||
self.entry_edit.setCurrentIndex(0)
|
||||
|
||||
self.tree.setItemWidget(self, 1, self.device_edit)
|
||||
|
Reference in New Issue
Block a user