Skip to content
Snippets Groups Projects

Change how users delete entries from the database

Merged Kien Le requested to merge feature-new_way_to_delete_database_entry into master
Files
6
@@ -2,6 +2,7 @@
@@ -2,6 +2,7 @@
channel_dialog.py
channel_dialog.py
GUI to add/edit/remove channels
GUI to add/edit/remove channels
"""
"""
 
from PySide2.QtWidgets import QMessageBox
from sohstationviewer.view.db_config.db_config_dialog import UiDBInfoDialog
from sohstationviewer.view.db_config.db_config_dialog import UiDBInfoDialog
from sohstationviewer.database.process_db import execute_db
from sohstationviewer.database.process_db import execute_db
@@ -23,6 +24,7 @@ class ChannelDialog(UiDBInfoDialog):
@@ -23,6 +24,7 @@ class ChannelDialog(UiDBInfoDialog):
'channel', 'channels', resize_content_columns=[0, 4, 5, 6],
'channel', 'channels', resize_content_columns=[0, 4, 5, 6],
need_data_type_choice=True, required_columns={3: 'Param'},
need_data_type_choice=True, required_columns={3: 'Param'},
check_fk=False)
check_fk=False)
 
self.delete_sql_supplement = f" AND dataType='{self.data_type}'"
self.setWindowTitle("Edit/Add/Delete Channels")
self.setWindowTitle("Edit/Add/Delete Channels")
def update_data_table_widget_items(self):
def update_data_table_widget_items(self):
@@ -46,9 +48,9 @@ class ChannelDialog(UiDBInfoDialog):
@@ -46,9 +48,9 @@ class ChannelDialog(UiDBInfoDialog):
self.data_table_widget.cellWidget(0, 5).setText('')
self.data_table_widget.cellWidget(0, 5).setText('')
self.data_table_widget.cellWidget(0, 6).setValue(0)
self.data_table_widget.cellWidget(0, 6).setValue(0)
def add_row(self, row_idx, fk=False):
def set_row_widgets(self, row_idx, fk=False):
"""
"""
Add a row of widgets to self.data_table_widgets.
Set the widgets in a row in self.data_table_widgets.
:param row_idx: index of row to add
:param row_idx: index of row to add
:param fk: bool: True if there is a foreign constrain that prevents the
:param fk: bool: True if there is a foreign constrain that prevents the
@@ -63,14 +65,51 @@ class ChannelDialog(UiDBInfoDialog):
@@ -63,14 +65,51 @@ class ChannelDialog(UiDBInfoDialog):
self.add_widget(self.data_list, row_idx, 5) # unit
self.add_widget(self.data_list, row_idx, 5) # unit
self.add_widget(self.data_list, row_idx, 6,
self.add_widget(self.data_list, row_idx, 6,
range_values=[0, 5]) # fixPoint
range_values=[0, 5]) # fixPoint
 
self.add_delete_button_to_row(row_idx, fk)
def data_type_changed(self):
def data_type_changed(self):
"""
"""
Load new self.data_list when self.data_type_combo_box's value is
Method called when the data type of the data table is changed.
changed
"""
If there are unsaved changes, ask the user what to do. If the user
self.data_type = self.data_type_combo_box.currentText()
proceeds with the change, load channels of the new data type from the
self.update_data_table_widget_items()
database and populate the data table with these new channels. The user
 
can choose to save or not save the changes to the database with this
 
option. Otherwise, change the data type back and do nothing.
 
"""
 
# If the user cancel changing the data type when there are unsaved
 
# changes, the data type is changed back, which causes another
 
# execution of this method and thus, the prompt dialog shows up
 
# twice. This if statement fixes that problem.
 
if self.data_type == self.data_type_combo_box.currentText():
 
return
 
 
if not self.has_changes():
 
self.data_type = self.data_type_combo_box.currentText()
 
self.update_data_table_widget_items()
 
self.delete_sql_supplement = f" AND dataType='{self.data_type}'"
 
return
 
 
unsaved_changes_prompt = (
 
'<h3>Unsaved Changes</h3>'
 
'Are you sure you want to change the data type? '
 
'Any changes you made will not be saved?'
 
)
 
options = QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel
 
user_choice = QMessageBox.warning(self, 'Unsaved Changes',
 
unsaved_changes_prompt, options)
 
if user_choice != QMessageBox.Cancel:
 
if user_choice == QMessageBox.Save:
 
self.save_changes(need_confirmation=False)
 
elif user_choice == QMessageBox.Discard:
 
self.undo_all_deletes()
 
self.data_type = self.data_type_combo_box.currentText()
 
self.update_data_table_widget_items()
 
self.delete_sql_supplement = f" AND dataType='{self.data_type}'"
 
else:
 
# Cover both the case where the cancel button is pressed and the
 
# case where the exit button is pressed.
 
self.data_type_combo_box.setCurrentText(self.data_type)
def get_data_list(self):
def get_data_list(self):
"""
"""
Loading