diff --git a/sohstationviewer/view/db_config/value_color_helper/edit_value_color_dialog/multi_color_dot_dialog.py b/sohstationviewer/view/db_config/value_color_helper/edit_value_color_dialog/multi_color_dot_dialog.py index bb064752ca5eff9fde8259ff3ce53579df2030c9..bf9f0f0af78008f39b1ccdd9b90a9435a6c947fa 100644 --- a/sohstationviewer/view/db_config/value_color_helper/edit_value_color_dialog/multi_color_dot_dialog.py +++ b/sohstationviewer/view/db_config/value_color_helper/edit_value_color_dialog/multi_color_dot_dialog.py @@ -130,6 +130,61 @@ class MultiColorDotDialog(EditValueColorDialog): def add_row(self, rowid): pass + def handle_clear_higher_bound(self, rowid): + if rowid < len(self.rowid_value_dict) - 1: + # If the cleared one isn't the last one, it shouldn't be + # allowed. A warning should be given. + msg = "Higher bound must be a number" + QtWidgets.QMessageBox.information(self, "Error", msg) + self.higher_bound_lnedits[rowid].setText( + str(self.rowid_value_dict[rowid])) + else: + # If the cleared one is the last one, the lower_bound_lnedit + # of the next row will be cleared too. + if rowid == 0: + # If the cleared one is the only one, this shouldn't be + # allowed. A warning should be given. + msg = ("There should be at least one value" + " for this plot type.") + QtWidgets.QMessageBox.information(self, "Error", msg) + return + self.set_color_enabled(rowid, False) + self.lower_bound_lnedits[rowid + 1].setText('') + self.set_value_rowid_dict() + + def handle_skipping_editing_row(self, rowid): + if self.higher_bound_lnedits[rowid].text() == '': + # called by clearing text in this section + return + self.changed_rowid = None + # When user edit the row that skips some row from the last row + # the current higher_bound_lnedit will be cleared + msg = ("You have to edit rows in order.\n" + "Skipping rows isn't allowed.") + QtWidgets.QMessageBox.information(self, "Error", msg) + self.higher_bound_lnedits[rowid].setText('') + + def handle_edited_value_not_ascending( + 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 + # widget will be set to the original value. + cond = (f"{prev_higher_bound} < " + if prev_higher_bound != -20 else '') + cond += (f"d < {next_higher_bound}" + if next_higher_bound != 20 else 'd') + msg = f"Value entered must be: {cond}" + QtWidgets.QMessageBox.information(self, "Error", msg) + try: + self.higher_bound_lnedits[rowid].setText( + str(self.rowid_value_dict[rowid])) + except KeyError: + # If the current row is the last one, there's no original value + # So the widget will be cleared. + self.higher_bound_lnedits[rowid].setText('') + self.select_color_btn_clicked = False + self.save_colors_btn_clicked = False + def on_higher_bound_editing_finished(self, rowid: int): """ Check value entered for higher bound: @@ -150,16 +205,7 @@ class MultiColorDotDialog(EditValueColorDialog): return if len(self.rowid_value_dict) < self.changed_rowid < ROW_TOTAL - 1: - if self.higher_bound_lnedits[rowid].text() == '': - # called by clearing text in this section - return - self.changed_rowid = None - # When user edit the row that skips some row from the last row - # the current higher_bound_lnedit will be cleared - msg = ("You have to edit rows in order.\n" - "Skipping rows isn't allowed.") - QtWidgets.QMessageBox.information(self, "Error", msg) - self.higher_bound_lnedits[rowid].setText('') + self.handle_skipping_editing_row(rowid) return self.changed_rowid = None @@ -168,33 +214,12 @@ class MultiColorDotDialog(EditValueColorDialog): float(self.higher_bound_lnedits[rowid - 1].text()) if rowid > 0 else -20) - try: - curr_higher_bound = float(self.higher_bound_lnedits[rowid].text()) - except ValueError: - # When the current higher_bound_lnedit is cleared. - if rowid < len(self.rowid_value_dict) - 1: - # If the cleared one isn't the last one, it shouldn't be - # allowed. A warning should be given. - msg = "Higher bound must be a number" - QtWidgets.QMessageBox.information(self, "Error", msg) - self.higher_bound_lnedits[rowid].setText( - str(self.rowid_value_dict[rowid])) - else: - # If the cleared one is the last one, the lower_bound_lnedit - # of the next row will be cleared too. - if rowid == 0: - # If the cleared one is the only one, this shouldn't be - # allowed. A warning should be given. - msg = ("There should be at least one value" - " for this plot type.") - QtWidgets.QMessageBox.information(self, "Error", msg) - return - self.set_color_enabled(rowid, False) - self.lower_bound_lnedits[rowid + 1].setText('') - self.set_value_rowid_dict() + if self.higher_bound_lnedits[rowid].text().strip() == '': + self.handle_clear_higher_bound(rowid) self.select_color_btn_clicked = False self.save_colors_btn_clicked = False return + if rowid >= len(self.rowid_value_dict) - 1: # When the current higher_bound_lnedits is on the last row # set the limit 20 to be the next_higher_bound @@ -203,26 +228,12 @@ class MultiColorDotDialog(EditValueColorDialog): next_higher_bound = float( self.higher_bound_lnedits[rowid + 1].text()) + curr_higher_bound = float(self.higher_bound_lnedits[rowid].text()) if (curr_higher_bound <= prev_higher_bound or curr_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 - # widget will be set to the original value. - cond = (f"{prev_higher_bound} < " - if prev_higher_bound != -20 else '') - cond += (f"d < {next_higher_bound}" - if next_higher_bound != 20 else 'd') - msg = f"Value entered must be: {cond}" - QtWidgets.QMessageBox.information(self, "Error", msg) - try: - self.higher_bound_lnedits[rowid].setText( - str(self.rowid_value_dict[rowid])) - except KeyError: - # If the current row is the last one, there's no original value - # So the widget will be cleared. - self.higher_bound_lnedits[rowid].setText('') - self.select_color_btn_clicked = False - self.save_colors_btn_clicked = False + self.handle_edited_value_not_ascending(rowid, + prev_higher_bound, + next_higher_bound) return if ((rowid == 0 and self.include_less_than_chkbox.isChecked()) or rowid != 0): @@ -277,13 +288,10 @@ class MultiColorDotDialog(EditValueColorDialog): def on_include(self, rowid: int, chkbox: QtWidgets.QCheckBox): """ - When include_less_than_chkbox/include_greater_than_chkbox is clicked - decide to allow user select color based on the status of the - check box. + Enable/Disable Select Color button when include_less_than_chkbox/ + include_greater_than_chkbox is checked/unchecked. """ self.set_color_enabled(rowid, chkbox.isChecked()) - # to be able to click on buttons after include checkbox is checked - self.changed_rowid = None def set_row(self, vc_idx: int, value: float, color: str): """