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.insertItem(0, "Hinted Signals")
|
||||||
self.model().item(0).setEnabled(False)
|
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()
|
@SafeSlot()
|
||||||
def reset_selection(self):
|
def reset_selection(self):
|
||||||
"""Reset the selection of the combobox."""
|
"""Reset the selection of the combobox."""
|
||||||
|
@ -102,19 +102,10 @@ class CurveSetting(SettingWidget):
|
|||||||
self.device_x.setCurrentIndex(item if item != -1 else 0)
|
self.device_x.setCurrentIndex(item if item != -1 else 0)
|
||||||
signal_x = self.target_widget.x_axis_mode.get("entry", "")
|
signal_x = self.target_widget.x_axis_mode.get("entry", "")
|
||||||
if signal_x:
|
if signal_x:
|
||||||
for i in range(self.signal_x.count()):
|
self.signal_x.set_to_obj_name(signal_x)
|
||||||
signal_data = self.signal_x.itemData(i)
|
|
||||||
if signal_data and signal_data.get("obj_name") == signal_x:
|
|
||||||
self.signal_x.setCurrentIndex(i)
|
|
||||||
break
|
|
||||||
else:
|
else:
|
||||||
# If no match is found, set to the first enabled item
|
# If no match is found, set to the first enabled item
|
||||||
for i in range(self.signal_x.count()):
|
if not self.signal_x.set_to_first_enabled():
|
||||||
model = self.signal_x.model()
|
|
||||||
if model.flags(model.index(i, 0)) & Qt.ItemIsEnabled:
|
|
||||||
self.signal_x.setCurrentIndex(i)
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
# If no enabled item is found, set to the first item
|
# If no enabled item is found, set to the first item
|
||||||
self.signal_x.setCurrentIndex(0)
|
self.signal_x.setCurrentIndex(0)
|
||||||
else:
|
else:
|
||||||
|
@ -142,20 +142,10 @@ class CurveRow(QTreeWidgetItem):
|
|||||||
# If the device name is not found, set the first enabled item
|
# If the device name is not found, set the first enabled item
|
||||||
self.device_edit.setCurrentIndex(0)
|
self.device_edit.setCurrentIndex(0)
|
||||||
|
|
||||||
for i in range(self.entry_edit.count()):
|
if not self.entry_edit.set_to_obj_name(self.config.signal.entry):
|
||||||
entry_data = self.entry_edit.itemData(i)
|
# If the entry is not found, try to set it to the first enabled item
|
||||||
if entry_data and entry_data.get("obj_name") == self.config.signal.entry:
|
if not self.entry_edit.set_to_first_enabled():
|
||||||
# If the device name matches an object name, set it
|
# If no enabled item is found, set to the first item
|
||||||
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:
|
|
||||||
self.entry_edit.setCurrentIndex(0)
|
self.entry_edit.setCurrentIndex(0)
|
||||||
|
|
||||||
self.tree.setItemWidget(self, 1, self.device_edit)
|
self.tree.setItemWidget(self, 1, self.device_edit)
|
||||||
|
Reference in New Issue
Block a user