Skip to content
Snippets Groups Projects

Fix channel prefer dialog not save

Merged Lan Dam requested to merge i222_channel_prefer_dialog_not_save into develop
1 file
+ 50
15
Compare changes
  • Side-by-side
  • Inline
@@ -83,6 +83,12 @@ class ChannelPreferDialog(OneWindowAtATimeDialog):
"""
self.avail_data_types: List[str] = []
"""
working_data_types: list of available data types that aren't default
one
"""
self.working_data_types: List[str] = self.get_data_types(
include_default=False)
"""
curr_row: current row
"""
self.curr_row: int = -1
@@ -550,6 +556,23 @@ class ChannelPreferDialog(OneWindowAtATimeDialog):
"""
if not self.validate_row():
return
self.save_btn.setFocus()
sql_list = []
has_error = False
for row_idx in range(TOTAL_ROW):
sql = self.create_save_row_sql(row_idx)
if sql is None:
has_error = True
elif sql != '':
sql_list.append(sql)
if has_error:
return False
if len(sql_list) == 0:
self.parent.pref_soh_list = []
self.parent.pref_soh_list_name = ''
self.parent.pref_soh_list_data_type = 'Unknown'
if self.changed:
msg = ("All IDs in the database will be overwritten with "
"current IDs in the dialog.\nClick Cancel to stop updating "
@@ -560,16 +583,6 @@ class ChannelPreferDialog(OneWindowAtATimeDialog):
QtWidgets.QMessageBox.StandardButton.Cancel)
if result == QtWidgets.QMessageBox.StandardButton.Cancel:
return False
sql_list = []
for row_idx in range(TOTAL_ROW):
sql = self.create_save_row_sql(row_idx)
if sql is not None:
sql_list.append(sql)
if len(sql_list) == 0:
self.parent.pref_soh_list = []
self.parent.pref_soh_list_name = ''
self.parent.pref_soh_list_data_type = 'Unknown'
ret = trunc_add_db('ChannelPrefer', sql_list)
if ret is not True:
display_tracking_info(self.parent, ret, LogType.ERROR)
@@ -581,12 +594,15 @@ class ChannelPreferDialog(OneWindowAtATimeDialog):
self.changed = False
return True
def create_save_row_sql(self, row_idx):
def create_save_row_sql(self, row_idx: int) -> Union[bool, str]:
"""
Read info from the row with index row_idx to create insert sql.
:param row_idx: int - index of a row
:return: str - insert sql with the row's info
:return:
None: has error
str!='' - insert sql with the row's info
str=='' - no sql to add
"""
current = 1 if self.soh_list_table_widget.cellWidget(
row_idx, COL['sel']).isChecked() else 0
name = self.soh_list_table_widget.item(
@@ -596,1+612,1 @@
row_idx, COL['dataType']).currentText()
idx = self.soh_list_table_widget.item(
row_idx, COL['IDs']).text()
if idx.strip() == '':
if idx.strip() == '' and name.strip() == '':
return ''
if data_type not in self.working_data_types:
msg = (f"Please add a data type that isn't Default for row"
f" {row_idx}.")
QtWidgets.QMessageBox.information(self, "Missing info", msg)
return
if idx.strip() == '' and name.strip() != '':
msg = f"Please add Preferred SOH list for row {row_idx}."
QtWidgets.QMessageBox.information(self, "Missing info", msg)
return
if name.strip() == '' and idx.strip() != '':
msg = f"Please add Name for row {row_idx}."
@@ -613,21 +638,31 @@ class ChannelPreferDialog(OneWindowAtATimeDialog):
"""
if not self.save():
return
if self.parent.pref_soh_list_name == '':
msg = "Please select a row to add to Main Window."
QtWidgets.QMessageBox.information(self, "Missing info", msg)
return
self.parent.curr_pref_soh_list_name_txtbox.setText(
self.parent.pref_soh_list_name)
self.parent.all_soh_chans_check_box.setChecked(False)
self.close()
@staticmethod
def get_data_types():
def get_data_types(include_default: bool = True):
"""
Get list of data types from DB.
:param include_default: flag indicate if Default data type should be
included or not
:return: [str, ] - list of data types
"""
data_type_rows = execute_db(
'SELECT * FROM DataTypes ORDER BY dataType ASC')
return [d[0] for d in data_type_rows]
if include_default:
return [d[0] for d in data_type_rows]
else:
return [d[0] for d in data_type_rows
if d[0] != 'Default']
@staticmethod
def get_db_channels(data_type) -> List[str]:
Loading