From 761cc38fc412d20fee20c38293e0b87fd2ba2b00 Mon Sep 17 00:00:00 2001
From: ldam <ldam@passcal.nmt.edu>
Date: Fri, 8 Dec 2023 12:13:55 -0700
Subject: [PATCH] docstring, move common codes in the subclasses to superclass

---
 .../multi_color_dot_dialog.py                 | 160 +++++++++---------
 1 file changed, 84 insertions(+), 76 deletions(-)

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 bf9f0f0af..842200588 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
@@ -127,13 +127,64 @@ class MultiColorDotDialog(EditValueColorDialog):
 
         super().connect_signals()
 
-    def add_row(self, rowid):
+    def get_comparing_text(self, rowid):
         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):
+        """
+        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 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"
             QtWidgets.QMessageBox.information(self, "Error", msg)
             self.higher_bound_lnedits[rowid].setText(
@@ -153,6 +204,12 @@ class MultiColorDotDialog(EditValueColorDialog):
             self.set_value_rowid_dict()
 
     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() == '':
             # called by clearing text in this section
             return
@@ -166,9 +223,15 @@ class MultiColorDotDialog(EditValueColorDialog):
 
     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.
+        """
+        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.
+        :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} < "
                 if prev_higher_bound != -20 else '')
         cond += (f"d < {next_higher_bound}"
@@ -370,47 +433,19 @@ class MultiColorDotLowerEqualDialog(MultiColorDotDialog):
         super(MultiColorDotLowerEqualDialog, self).__init__(
             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,
-            higher bound line edit, select color button, display color label
+        Create text that show relationship between lower_bound and higher_bound
+        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:
-            lower_bound_lnedit.setHidden(True)
-            comp_text = "      d <"
+            comparing_text = "      d <"
         elif rowid < ROW_TOTAL - 1:
-            lower_bound_lnedit.setEnabled(False)
-            comp_text = "<= d <"
+            comparing_text = "<= d <"
         else:
-            lower_bound_lnedit.setHidden(True)
-            comp_text = "      d ="
-        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)
+            comparing_text = "      d ="
+        return comparing_text
 
     def set_value(self):
         """
@@ -442,46 +477,19 @@ class MultiColorDotUpperEqualDialog(MultiColorDotDialog):
         super(MultiColorDotUpperEqualDialog, self).__init__(
             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,
-            higher bound line edit, select color button, display color label
+        Create text that show relationship between lower_bound and higher_bound
+        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:
-            lower_bound_lnedit.setHidden(True)
-            comp_text = "   d <="
+            comparing_text = "   d <="
         elif rowid < ROW_TOTAL - 1:
-            lower_bound_lnedit.setEnabled(False)
-            comp_text = "< d <="
+            comparing_text = "< d <="
         else:
-            lower_bound_lnedit.setReadOnly(True)
-            comp_text = "< d   "
-        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)
+            comparing_text = "< d   "
+        return comparing_text
 
     def set_value(self):
         """
-- 
GitLab