Skip to content

Commit

Permalink
Merge pull request #235 from zhujun98/fix_bug_in_data_source_tree
Browse files Browse the repository at this point in the history
Fix bug in data source tree
  • Loading branch information
zhujun98 authored Jun 22, 2020
2 parents 1598f3b + 166b7fd commit 03b4981
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 14 deletions.
Binary file modified docs/images/data_source_tree.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 6 additions & 2 deletions extra_foam/gui/ctrl_widgets/data_source_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,13 +281,17 @@ def setData(self, index, value, role=None) -> bool:
self.dataChanged.emit(index.sibling(i, 0),
index.siblingAtRow(i))
self.source_item_toggled_sgn.emit(
False,
f'{item_sb.name()} {item_sb.ppt()}')
False, f'{item_sb.name()} {item_sb.ppt()}')
break

item.setChecked(value)
else: # role == Qt.EditRole
old_src_name = item.name()
old_ppt = item.ppt()
item.setData(value, index.column())
# remove registered item with the old device ID and property
self.source_item_toggled_sgn.emit(
False, f'{old_src_name} {old_ppt}')

main_det = config["DETECTOR"]
ctg = item.parent().name()
Expand Down
40 changes: 28 additions & 12 deletions extra_foam/gui/ctrl_widgets/tests/test_data_source_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,23 +212,35 @@ def testDataSourceTreeModelPs(self, control_sources, pipeline_sources):
spy = QtTest.QSignalSpy(model.source_item_toggled_sgn)
# change device ID
model.setData(model.index(0, 2, dssc_ctg), 'A+', Qt.EditRole)
self.assertEqual(1, len(spy))
self.assertTrue(spy[0][0])
self.assertTupleEqual(('DSSC', 'A+', '[]', 'a', '[None, None]', '', 1), spy[0][1])
self.assertEqual(2, len(spy))
# check signal for deleting old source
self.assertFalse(spy[0][0])
self.assertEqual('A a', spy[0][1])
# check signal for adding new source
self.assertTrue(spy[1][0])
self.assertTupleEqual(('DSSC', 'A+', '[]', 'a', '[None, None]', '', 1), spy[1][1])

spy = QtTest.QSignalSpy(model.source_item_toggled_sgn)
# change property
model.setData(model.index(0, 3, dssc_ctg), 'a-', Qt.EditRole)
self.assertEqual(1, len(spy))
self.assertTrue(spy[0][0])
self.assertTupleEqual(('DSSC', 'A+', '[]', 'a-', '[None, None]', '', 1), spy[0][1])
self.assertEqual(2, len(spy))
# check signal for deleting old source
self.assertFalse(spy[0][0])
self.assertEqual('A+ a', spy[0][1])
# check signal for adding new source
self.assertTrue(spy[1][0])
self.assertTupleEqual(('DSSC', 'A+', '[]', 'a-', '[None, None]', '', 1), spy[1][1])

spy = QtTest.QSignalSpy(model.source_item_toggled_sgn)
# change slicer
model.setData(model.index(0, 4, dssc_ctg), '::2', Qt.EditRole)
self.assertEqual(1, len(spy))
self.assertTrue(spy[0][0])
self.assertTupleEqual(('DSSC', 'A+', '[]', 'a-', '[None, None, 2]', '', 1), spy[0][1])
self.assertEqual(2, len(spy))
# check signal for deleting old source
self.assertFalse(spy[0][0])
# deleting does not check slicer
# check signal for adding new source
self.assertTrue(spy[1][0])
self.assertTupleEqual(('DSSC', 'A+', '[]', 'a-', '[None, None, 2]', '', 1), spy[1][1])

spy = QtTest.QSignalSpy(model.source_item_toggled_sgn)
# change a DSSC source
Expand Down Expand Up @@ -313,9 +325,13 @@ def testDataSourceTreeModelPs(self, control_sources, pipeline_sources):
spy = QtTest.QSignalSpy(model.source_item_toggled_sgn)
# change slicer
model.setData(model.index(1, 5, xgm_ctg), '-1, 1', Qt.EditRole)
self.assertEqual(1, len(spy))
self.assertTrue(spy[0][0])
self.assertTupleEqual(('XGM', 'XA', '[]', 'flux', '', '(-1.0, 1.0)', 0), spy[0][1])
self.assertEqual(2, len(spy))
# delete old source
self.assertFalse(spy[0][0])
# deleting does not check range
# add new source
self.assertTrue(spy[1][0])
self.assertTupleEqual(('XGM', 'XA', '[]', 'flux', '', '(-1.0, 1.0)', 0), spy[1][1])

@patch.dict(config._data, {"PULSE_RESOLVED": False})
@patch.object(ConfigWrapper, "pipeline_sources", new_callable=PropertyMock)
Expand Down

0 comments on commit 03b4981

Please sign in to comment.