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

docstring, move common codes in the subclasses to superclass

parent 7e6ff0d0
No related branches found
No related tags found
1 merge request!217Implement dialogs to edit valueColors for 2 multiColorDots plot types
Pipeline #3333 passed with stage
in 6 minutes and 19 seconds
...@@ -127,13 +127,64 @@ class MultiColorDotDialog(EditValueColorDialog): ...@@ -127,13 +127,64 @@ class MultiColorDotDialog(EditValueColorDialog):
super().connect_signals() super().connect_signals()
def add_row(self, rowid): def get_comparing_text(self, rowid):
pass pass
def add_row(self, rowid):
"""
Adding a row including Lower bound line dit, comparing operator label,
higher bound line edit, select color button, display color label
:param rowid: id of current row
"""
lower_bound_lnedit = QtWidgets.QLineEdit()
self.main_layout.addWidget(lower_bound_lnedit, rowid, 1, 1, 1)
lower_bound_lnedit.setReadOnly(True)
if rowid == 0:
lower_bound_lnedit.setHidden(True)
elif rowid < ROW_TOTAL - 1:
lower_bound_lnedit.setEnabled(False)
else:
lower_bound_lnedit.setHidden(True)
comparing_text = self.get_comparing_text(rowid)
self.main_layout.addWidget(QtWidgets.QLabel(
comparing_text), rowid, 2, 1, 1)
higher_bound_lnedit = QtWidgets.QLineEdit()
validator = BoundValidator()
higher_bound_lnedit.setValidator(validator)
self.main_layout.addWidget(higher_bound_lnedit, rowid, 3, 1, 1)
if rowid == ROW_TOTAL - 1:
higher_bound_lnedit.setEnabled(False)
select_color_btn = QtWidgets.QPushButton("Select Color")
# set focus policy to not be clicked by hitting enter in higher bound
select_color_btn.setFocusPolicy(QtCore.Qt.NoFocus)
self.main_layout.addWidget(select_color_btn, rowid, 4, 1, 1)
color_label = QtWidgets.QLabel()
color_label.setFixedWidth(30)
color_label.setAutoFillBackground(True)
self.main_layout.addWidget(color_label, rowid, 5, 1, 1)
select_color_btn.clicked.connect(
lambda: self.on_select_color(rowid))
return (lower_bound_lnedit, higher_bound_lnedit,
select_color_btn, color_label)
def handle_clear_higher_bound(self, rowid): def handle_clear_higher_bound(self, rowid):
"""
If user clear higher_bound
+ in the middle, not allow.
+ of the only row, not allow.
+ in the last edited row, the lower_bound for the next row need to be
cleared, and the very end row's value will be set to the higher_bound
of the previous row.
"""
if rowid < len(self.rowid_value_dict) - 1: if rowid < len(self.rowid_value_dict) - 1:
# If the cleared one isn't the last one, it shouldn't be # If the cleared one isn't the last one, it shouldn't be
# allowed. A warning should be given. # allowed. An Error message should be given.
msg = "Higher bound must be a number" msg = "Higher bound must be a number"
QtWidgets.QMessageBox.information(self, "Error", msg) QtWidgets.QMessageBox.information(self, "Error", msg)
self.higher_bound_lnedits[rowid].setText( self.higher_bound_lnedits[rowid].setText(
...@@ -153,6 +204,12 @@ class MultiColorDotDialog(EditValueColorDialog): ...@@ -153,6 +204,12 @@ class MultiColorDotDialog(EditValueColorDialog):
self.set_value_rowid_dict() self.set_value_rowid_dict()
def handle_skipping_editing_row(self, rowid): def handle_skipping_editing_row(self, rowid):
"""
If user add value in a row that skipping from the last edited row,
it shouldn't be allowed, an Error message should be given before the
higher_bound is cleared, the actions will ignite the call to this
function one more time which should be ignored.
"""
if self.higher_bound_lnedits[rowid].text() == '': if self.higher_bound_lnedits[rowid].text() == '':
# called by clearing text in this section # called by clearing text in this section
return return
...@@ -166,9 +223,15 @@ class MultiColorDotDialog(EditValueColorDialog): ...@@ -166,9 +223,15 @@ class MultiColorDotDialog(EditValueColorDialog):
def handle_edited_value_not_ascending( def handle_edited_value_not_ascending(
self, rowid, prev_higher_bound, next_higher_bound): self, rowid, prev_higher_bound, next_higher_bound):
# If value enter to the current higher_bound_lnedit make it out """
# of increasing sorting, a warning will be given, and the If value enter to the current higher_bound_lnedit make it out of
# widget will be set to the original value. increasing sorting, a warning will be given, and the widget will be
set to the original value.
:param rowid: id of current row
:param prev_higher_bound: higher_bound value of the previous row
:param next_higher_bound: higher_bound value of the next row
"""
cond = (f"{prev_higher_bound} < " cond = (f"{prev_higher_bound} < "
if prev_higher_bound != -20 else '') if prev_higher_bound != -20 else '')
cond += (f"d < {next_higher_bound}" cond += (f"d < {next_higher_bound}"
...@@ -370,47 +433,19 @@ class MultiColorDotLowerEqualDialog(MultiColorDotDialog): ...@@ -370,47 +433,19 @@ class MultiColorDotLowerEqualDialog(MultiColorDotDialog):
super(MultiColorDotLowerEqualDialog, self).__init__( super(MultiColorDotLowerEqualDialog, self).__init__(
parent, value_color_str, upper_equal=False) parent, value_color_str, upper_equal=False)
def add_row(self, rowid): def get_comparing_text(self, rowid: int):
""" """
Adding a row including Lower bound line dit, comparing operator label, Create text that show relationship between lower_bound and higher_bound
higher bound line edit, select color button, display color label to data for the selected color.
:param rowid: id of current row
""" """
lower_bound_lnedit = QtWidgets.QLineEdit()
self.main_layout.addWidget(lower_bound_lnedit, rowid, 1, 1, 1)
lower_bound_lnedit.setReadOnly(True)
if rowid == 0: if rowid == 0:
lower_bound_lnedit.setHidden(True) comparing_text = " d <"
comp_text = " d <"
elif rowid < ROW_TOTAL - 1: elif rowid < ROW_TOTAL - 1:
lower_bound_lnedit.setEnabled(False) comparing_text = "<= d <"
comp_text = "<= d <"
else: else:
lower_bound_lnedit.setHidden(True) comparing_text = " d ="
comp_text = " d =" return comparing_text
self.main_layout.addWidget(QtWidgets.QLabel(comp_text), rowid, 2, 1, 1)
higher_bound_lnedit = QtWidgets.QLineEdit()
validator = BoundValidator()
higher_bound_lnedit.setValidator(validator)
self.main_layout.addWidget(higher_bound_lnedit, rowid, 3, 1, 1)
if rowid == ROW_TOTAL - 1:
higher_bound_lnedit.setEnabled(False)
select_color_btn = QtWidgets.QPushButton("Select Color")
# set focus policy to not be clicked by hitting enter in higher bound
select_color_btn.setFocusPolicy(QtCore.Qt.NoFocus)
self.main_layout.addWidget(select_color_btn, rowid, 4, 1, 1)
color_label = QtWidgets.QLabel()
color_label.setFixedWidth(30)
color_label.setAutoFillBackground(True)
self.main_layout.addWidget(color_label, rowid, 5, 1, 1)
select_color_btn.clicked.connect(
lambda: self.on_select_color(rowid))
return (lower_bound_lnedit, higher_bound_lnedit,
select_color_btn, color_label)
def set_value(self): def set_value(self):
""" """
...@@ -442,46 +477,19 @@ class MultiColorDotUpperEqualDialog(MultiColorDotDialog): ...@@ -442,46 +477,19 @@ class MultiColorDotUpperEqualDialog(MultiColorDotDialog):
super(MultiColorDotUpperEqualDialog, self).__init__( super(MultiColorDotUpperEqualDialog, self).__init__(
parent, value_color_str, upper_equal=True) parent, value_color_str, upper_equal=True)
def add_row(self, rowid): def get_comparing_text(self, rowid):
""" """
Adding a row including Lower bound line dit, comparing operator label, Create text that show relationship between lower_bound and higher_bound
higher bound line edit, select color button, display color label to data for the selected color.
:param rowid: id of current row
""" """
lower_bound_lnedit = QtWidgets.QLineEdit()
self.main_layout.addWidget(lower_bound_lnedit, rowid, 1, 1, 1)
lower_bound_lnedit.setReadOnly(True)
if rowid == 0: if rowid == 0:
lower_bound_lnedit.setHidden(True) comparing_text = " d <="
comp_text = " d <="
elif rowid < ROW_TOTAL - 1: elif rowid < ROW_TOTAL - 1:
lower_bound_lnedit.setEnabled(False) comparing_text = "< d <="
comp_text = "< d <="
else: else:
lower_bound_lnedit.setReadOnly(True) comparing_text = "< d "
comp_text = "< d " return comparing_text
self.main_layout.addWidget(QtWidgets.QLabel(comp_text), rowid, 2, 1, 1)
higher_bound_lnedit = QtWidgets.QLineEdit()
validator = BoundValidator()
higher_bound_lnedit.setValidator(validator)
self.main_layout.addWidget(higher_bound_lnedit, rowid, 3, 1, 1)
if rowid == ROW_TOTAL - 1:
higher_bound_lnedit.setHidden(True)
select_color_btn = QtWidgets.QPushButton("Select Color")
# set focus policy to not be clicked by hitting enter in higher bound
select_color_btn.setFocusPolicy(QtCore.Qt.NoFocus)
self.main_layout.addWidget(select_color_btn, rowid, 4, 1, 1)
color_label = QtWidgets.QLabel()
color_label.setFixedWidth(30)
color_label.setAutoFillBackground(True)
self.main_layout.addWidget(color_label, rowid, 5, 1, 1)
select_color_btn.clicked.connect(
lambda: self.on_select_color(rowid))
return (lower_bound_lnedit, higher_bound_lnedit,
select_color_btn, color_label)
def set_value(self): def set_value(self):
""" """
......
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