Skip to content
Snippets Groups Projects
Commit e5f58a83 authored by Lan Dam's avatar Lan Dam
Browse files

change names of function, variable to be more descriptive' spelling, change...

change names of function, variable to be more descriptive' spelling, change witget for conversion to spinbox
parent a0dd4112
No related branches found
No related tags found
1 merge request!211Implement dialog to add/edit a single channel in database
This commit is part of merge request !211. Comments created here will be created in the context of that merge request.
......@@ -13,7 +13,7 @@ from sohstationviewer.view.db_config.add_edit_single_channel_helper import (
from sohstationviewer.database.process_db import execute_db
def get_db_str_with_null(col, val):
def create_assign_string_for_db_query(col, val):
"""
Create assign db string that assign to NULL if val is empty str
:param col: column in the db table
......@@ -35,12 +35,12 @@ def add_separation_line(layout):
class AddEditSingleChannelDialog(QDialog):
"""
Dialog to add info for channel not in database or edit the existing channel
"""
def __init__(self, parent: Optional[QWidget],
chan_id: str, data_type: str):
"""
Dialog to add info for channel not in database or edit the existing
channel
:param parent: the parent widget
:param chan_id: name of channel to be added/edited
:param data_type: type of the data being processed
......@@ -51,7 +51,7 @@ class AddEditSingleChannelDialog(QDialog):
# data_type of the channel
self.data_type = data_type
# True if this channel isn't in DB yet
self.new = False
self.is_new_db_channel = False
# To skip on_param_chkbox_changed() when param is changed by the
# program at the beginning
self.param_changed_by_signal = False
......@@ -70,14 +70,13 @@ class AddEditSingleChannelDialog(QDialog):
"added to channel name to be displayed")
# convert factor to change from count to actual value
self.convesion_lnedit = QtWidgets.QLineEdit(self)
self.convesion_lnedit.setPlaceholderText(
self.conversion_lnedit = QtWidgets.QSpinBox()
self.conversion_lnedit.setMinimum(0)
self.conversion_lnedit.setMaximum(5)
self.conversion_lnedit.setToolTip(
"to convert from count to actual value"
)
validator = QtGui.QDoubleValidator(0.0, 5.0, 6)
validator.setNotation(QtGui.QDoubleValidator.StandardNotation)
self.convesion_lnedit.setValidator(validator)
self.convesion_lnedit.setText('1')
self.conversion_lnedit.setValue(1)
# channel's unit
self.unit_lnedit = QtWidgets.QLineEdit(self)
......@@ -150,7 +149,7 @@ class AddEditSingleChannelDialog(QDialog):
channel_layout.addWidget(self.label_lnedit, 1, 1, 1, 1)
channel_layout.addWidget(QtWidgets.QLabel('Conversion'), 2, 0, 1, 1)
channel_layout.addWidget(self.convesion_lnedit, 2, 1, 1, 1)
channel_layout.addWidget(self.conversion_lnedit, 2, 1, 1, 1)
channel_layout.addWidget(QtWidgets.QLabel('Unit'), 3, 0, 1, 1)
channel_layout.addWidget(self.unit_lnedit, 3, 1, 1, 1)
......@@ -215,14 +214,14 @@ class AddEditSingleChannelDialog(QDialog):
try:
self.channel_info = get_channel_info(self.chan_id, self.data_type)
except IndexError:
self.new = True
self.is_new_db_channel = True
self.channel_info = get_channel_info('DEFAULT', 'Default')
self.name_lnedit.setText(self.chan_id)
self.label_lnedit.setText(self.channel_info['label'])
self.convesion_lnedit.setText(
self.conversion_lnedit.setText(
str(float(self.channel_info['convertFactor'])))
self.unit_lnedit.setText(self.channel_info['unit'])
......@@ -247,7 +246,7 @@ class AddEditSingleChannelDialog(QDialog):
if self.param_changed_by_signal:
self.param_changed_by_signal = False
return
if not self.new:
if not self.is_new_db_channel:
msg = ("ARE YOU SURE YOU WANT TO CHANGE PARAMETER FOR CHANNEL "
f"'{self.chan_id}'?")
result = QtWidgets.QMessageBox.question(
......@@ -299,7 +298,7 @@ class AddEditSingleChannelDialog(QDialog):
return
param = f"param='{self.param_cbobox.currentText()}'"
self.update_para_info(param)
if self.new:
if self.is_new_db_channel:
self.insert_channel_info()
else:
self.update_channel_info()
......@@ -310,11 +309,11 @@ class AddEditSingleChannelDialog(QDialog):
Save parameter related info to Parameters table
:param param: param condition string
"""
plot_type = get_db_str_with_null(
plot_type = create_assign_string_for_db_query(
'plotType', self.plot_type_cbo_box.currentText())
value_colorb = get_db_str_with_null(
value_colorb = create_assign_string_for_db_query(
'valueColorsB', self.value_colorb_widget.text())
value_colorw = get_db_str_with_null(
value_colorw = create_assign_string_for_db_query(
'valueColorsW', self.value_colorw_widget.text())
height = f"height={self.height_spnbox.value()}"
sql = (f"UPDATE Parameters SET {plot_type}, {value_colorb}, "
......@@ -327,7 +326,7 @@ class AddEditSingleChannelDialog(QDialog):
f"'{self.label_lnedit.text()}', "
f"'{self.param_cbobox.currentText()}', "
f"NULL, " # linkedChan for RT130 only and won't be changed
f"{self.convesion_lnedit.text()}, "
f"{self.conversion_lnedit.text()}, "
f"'{self.unit_lnedit.text()}', "
f"{self.fix_point_spnbox.value()}, "
f"'{self.data_type_lnedit.text()}')")
......@@ -338,7 +337,7 @@ class AddEditSingleChannelDialog(QDialog):
label = f"label='{self.label_lnedit.text()}'"
param = f"param='{self.param_cbobox.currentText()}'"
linked_chan = "linkedChan=NULL"
convert_factor = f"convertFactor={self.convesion_lnedit.text()}"
convert_factor = f"convertFactor={self.conversion_lnedit.text()}"
unit = f"unit='{self.unit_lnedit.text()}'"
fix_point = f"fixPoint={self.fix_point_spnbox.value()}"
data_type = f"dataType='{self.data_type_lnedit.text()}'"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment