Skip to content

Commit

Permalink
Table ROI color change: backport to 2.7 (#2068)
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeSullivan7 authored Feb 26, 2024
2 parents 7669e7d + 7444f1f commit e23da78
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions docs/release_notes/2.7.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ New Features
- #2026: Time of flight graph in the Spectrum Viewer is now resizable
- #2027: The Spectrum ROI details display in an adjustable table via spinboxes
- #2048: Update spectrum documentation to reflect changes made to the Spectrum Viewer.
- #2046 : Enhancement: Implement Click Dialog for Changing ROI Colors in Table

Fixes
-----
Expand Down
3 changes: 2 additions & 1 deletion mantidimaging/gui/windows/spectrum_viewer/presenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ def change_roi_colour(self, roi_name: str, new_colour: tuple) -> None:
"""
if roi_name in self.view.spectrum_widget.roi_dict:
self.view.spectrum_widget.roi_dict[roi_name].colour = new_colour
self.view.update_roi_color_in_table(roi_name, new_colour)
self.view.update_roi_color(roi_name, new_colour)
self.view.on_visibility_change()

def add_rits_roi(self) -> None:
roi_name = ROI_RITS
Expand Down
6 changes: 3 additions & 3 deletions mantidimaging/gui/windows/spectrum_viewer/spectrum_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ def __init__(self, name: str, sensible_roi: SensibleROI, *args, **kwargs):
self.roi.setAcceptedMouseButtons(Qt.MouseButton.LeftButton)

self.menu = QMenu()
change_color_action = QAction("Change ROI Colour", self)
change_color_action.triggered.connect(self.onChangeColor)
self.menu.addAction(change_color_action)
self.change_color_action = QAction("Change ROI Colour", self)
self.change_color_action.triggered.connect(self.onChangeColor)
self.menu.addAction(self.change_color_action)

def onChangeColor(self):
current_color = QColor(*self._colour)
Expand Down
14 changes: 11 additions & 3 deletions mantidimaging/gui/windows/spectrum_viewer/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def __init__(self, main_window: 'MainWindowView'):
self.tableView.setSelectionBehavior(QAbstractItemView.SelectRows)
self.tableView.setSelectionMode(QAbstractItemView.SingleSelection)
self.tableView.setAlternatingRowColors(True)
self.tableView.clicked.connect(self.handle_table_click)

# Roi Prop table
self.roi_table_properties = ["Top", "Bottom", "Left", "Right"]
Expand Down Expand Up @@ -351,10 +352,18 @@ def set_new_roi(self) -> None:
spinbox.setEnabled(True)
self.set_roi_properties()

def update_roi_color_in_table(self, roi_name: str, new_color: tuple):
def handle_table_click(self, index):
if index.isValid() and index.column() == 1:
roi_name = self.roi_table_model.index(index.row(), 0).data()
self.set_spectum_roi_color(roi_name)

def set_spectum_roi_color(self, roi_name: str) -> None:
spectrum_roi = self.spectrum_widget.roi_dict[roi_name]
spectrum_roi.change_color_action.trigger()

def update_roi_color(self, roi_name: str, new_color: tuple) -> None:
"""
Finds ROI by name in table and updates colour.
@param roi_name: Name of the ROI to update.
@param new_color: The new color for the ROI in (R, G, B) format.
"""
Expand All @@ -365,7 +374,6 @@ def update_roi_color_in_table(self, roi_name: str, new_color: tuple):
def find_row_for_roi(self, roi_name: str) -> Optional[int]:
"""
Returns row index for ROI name, or None if not found.
@param roi_name: Name ROI find.
@return: Row index ROI or None.
"""
Expand Down

0 comments on commit e23da78

Please sign in to comment.