|
6 | 6 |
|
7 | 7 | from PyQt5.QtCore import Qt
|
8 | 8 | from PyQt5.QtTest import QTest
|
| 9 | +from PyQt5.QtGui import QColor |
9 | 10 |
|
10 | 11 | from mantidimaging.gui.test.gui_system_base import GuiSystemBase, SHOW_DELAY, SHORT_DELAY
|
| 12 | +from mantidimaging.gui.windows.spectrum_viewer.model import SpecType, SensibleROI |
11 | 13 | from mantidimaging.test_helpers.qt_test_helpers import wait_until
|
12 | 14 |
|
13 | 15 |
|
@@ -56,3 +58,77 @@ def test_add_roi(self) -> None:
|
56 | 58 | self.assertEqual(final_roi_count, initial_roi_count + 1)
|
57 | 59 | self.assertIn(f'roi_{i}', self.spectrum_window.roi_table_model.roi_names())
|
58 | 60 | self.assertIn(f'roi_{i}', self.spectrum_window.spectrum_widget.roi_dict)
|
| 61 | + |
| 62 | + def test_remove_roi(self) -> None: |
| 63 | + QTest.mouseClick(self.spectrum_window.addBtn, Qt.MouseButton.LeftButton) |
| 64 | + QTest.qWait(SHORT_DELAY) |
| 65 | + initial_roi_count = self.spectrum_window.roi_table_model.rowCount() |
| 66 | + |
| 67 | + QTest.mouseClick(self.spectrum_window.removeBtn, Qt.MouseButton.LeftButton) |
| 68 | + QTest.qWait(SHORT_DELAY) |
| 69 | + final_roi_count = self.spectrum_window.roi_table_model.rowCount() |
| 70 | + |
| 71 | + self.assertEqual(final_roi_count, initial_roi_count - 1) |
| 72 | + self.assertNotIn(f'roi_{initial_roi_count - 1}', self.spectrum_window.roi_table_model.roi_names()) |
| 73 | + self.assertNotIn(f'roi_{initial_roi_count - 1}', self.spectrum_window.spectrum_widget.roi_dict) |
| 74 | + |
| 75 | + def test_change_roi_color(self): |
| 76 | + QTest.mouseClick(self.spectrum_window.addBtn, Qt.MouseButton.LeftButton) |
| 77 | + QTest.qWait(SHORT_DELAY) |
| 78 | + |
| 79 | + roi_name = 'roi_1' |
| 80 | + new_color = (255, 0, 0, 255) |
| 81 | + |
| 82 | + sensible_roi = SensibleROI(left=0, top=0, right=10, bottom=10) |
| 83 | + self.spectrum_window.spectrum_widget.add_roi(sensible_roi, roi_name) |
| 84 | + |
| 85 | + spec_roi = self.spectrum_window.spectrum_widget.roi_dict[roi_name] |
| 86 | + |
| 87 | + with mock.patch.object(spec_roi, 'openColorDialog', return_value=QColor(*new_color)): |
| 88 | + spec_roi.onChangeColor() |
| 89 | + |
| 90 | + self.assertEqual(self.spectrum_window.spectrum_widget.roi_dict[roi_name].colour, new_color) |
| 91 | + |
| 92 | + def test_rename_roi(self): |
| 93 | + QTest.mouseClick(self.spectrum_window.addBtn, Qt.MouseButton.LeftButton) |
| 94 | + QTest.qWait(SHORT_DELAY) |
| 95 | + |
| 96 | + old_name = 'roi_1' |
| 97 | + new_name = 'roi_renamed' |
| 98 | + |
| 99 | + table_model = self.spectrum_window.roi_table_model |
| 100 | + row = table_model.roi_names().index(old_name) |
| 101 | + |
| 102 | + table_model.set_element(row, 0, new_name) |
| 103 | + table_model.dataChanged.emit(table_model.index(row, 0), table_model.index(row, 0)) |
| 104 | + |
| 105 | + self.assertNotIn(old_name, self.spectrum_window.spectrum_widget.roi_dict) |
| 106 | + self.assertIn(new_name, self.spectrum_window.spectrum_widget.roi_dict) |
| 107 | + |
| 108 | + def test_adjust_roi(self): |
| 109 | + QTest.mouseClick(self.spectrum_window.addBtn, Qt.MouseButton.LeftButton) |
| 110 | + QTest.qWait(SHORT_DELAY) |
| 111 | + |
| 112 | + roi_names = self.spectrum_window.presenter.get_roi_names() |
| 113 | + roi_name = next(name for name in roi_names if name != 'all') |
| 114 | + roi_widget = self.spectrum_window.spectrum_widget.roi_dict[roi_name] |
| 115 | + handle_index = 0 |
| 116 | + new_position = (10, 20) |
| 117 | + |
| 118 | + roi_widget.movePoint(handle_index, new_position) |
| 119 | + QTest.qWait(SHORT_DELAY) |
| 120 | + |
| 121 | + updated_roi = self.spectrum_window.presenter.model.get_roi(roi_name) |
| 122 | + self.assertEqual(updated_roi.right, new_position[0]) |
| 123 | + self.assertEqual(updated_roi.bottom, new_position[1]) |
| 124 | + self.assertEqual(updated_roi.top, 0) |
| 125 | + self.assertEqual(updated_roi.left, 0) |
| 126 | + |
| 127 | + def test_normalisation_toggle(self): |
| 128 | + self.spectrum_window.normaliseCheckBox.setCheckState(Qt.CheckState.Checked) |
| 129 | + QTest.qWait(SHORT_DELAY) |
| 130 | + assert self.spectrum_window.presenter.spectrum_mode == SpecType.SAMPLE_NORMED |
| 131 | + |
| 132 | + self.spectrum_window.normaliseCheckBox.setCheckState(Qt.CheckState.Unchecked) |
| 133 | + QTest.qWait(SHORT_DELAY) |
| 134 | + assert self.spectrum_window.presenter.spectrum_mode == SpecType.SAMPLE |
0 commit comments