From c6839b4708f331fdc1a16f859f658846f38b3827 Mon Sep 17 00:00:00 2001 From: Luke Campagnola Date: Tue, 17 Oct 2017 21:22:55 -0700 Subject: [PATCH] fix: polylineroi segment draws to wrong handle after click --- pyqtgraph/graphicsItems/ROI.py | 10 ++++++---- pyqtgraph/graphicsItems/tests/test_ROI.py | 8 ++++++++ pyqtgraph/tests/image_testing.py | 2 +- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/pyqtgraph/graphicsItems/ROI.py b/pyqtgraph/graphicsItems/ROI.py index 319524e9..9682b6b3 100644 --- a/pyqtgraph/graphicsItems/ROI.py +++ b/pyqtgraph/graphicsItems/ROI.py @@ -571,7 +571,6 @@ class ROI(GraphicsObject): ## Note: by default, handles are not user-removable even if this method returns True. return True - def getLocalHandlePositions(self, index=None): """Returns the position of handles in the ROI's coordinate system. @@ -1969,9 +1968,13 @@ class LineSegmentROI(ROI): if len(positions) > 2: raise Exception("LineSegmentROI must be defined by exactly 2 positions. For more points, use PolyLineROI.") - self.endpoints = [] for i, p in enumerate(positions): - self.endpoints.append(self.addFreeHandle(p, item=handles[i])) + self.addFreeHandle(p, item=handles[i]) + + @property + def endpoints(self): + # must not be cached because self.handles may change. + return [h['item'] for h in self.handles] def listPoints(self): return [p['item'].pos() for p in self.handles] @@ -2018,7 +2021,6 @@ class LineSegmentROI(ROI): See ROI.getArrayRegion() for a description of the arguments. """ - imgPts = [self.mapToItem(img, h.pos()) for h in self.endpoints] rgns = [] coords = [] diff --git a/pyqtgraph/graphicsItems/tests/test_ROI.py b/pyqtgraph/graphicsItems/tests/test_ROI.py index ddc7f173..8cc2efd5 100644 --- a/pyqtgraph/graphicsItems/tests/test_ROI.py +++ b/pyqtgraph/graphicsItems/tests/test_ROI.py @@ -208,15 +208,23 @@ def test_PolyLineROI(): # click segment mouseClick(plt, pt, QtCore.Qt.LeftButton) assertImageApproved(plt, 'roi/polylineroi/'+name+'_click_segment', 'Click mouse over segment.') + + # drag new handle + mouseMove(plt, pt+pg.Point(10, -10)) # pg bug: have to move the mouse off/on again to register hover + mouseDrag(plt, pt, pt + pg.Point(10, -10), QtCore.Qt.LeftButton) + assertImageApproved(plt, 'roi/polylineroi/'+name+'_drag_new_handle', 'Drag mouse over created handle.') + # clear all points r.clearPoints() assertImageApproved(plt, 'roi/polylineroi/'+name+'_clear', 'All points cleared.') assert len(r.getState()['points']) == 0 + # call setPoints r.setPoints(initState['points']) assertImageApproved(plt, 'roi/polylineroi/'+name+'_setpoints', 'Reset points to initial state.') assert len(r.getState()['points']) == 3 + # call setState r.setState(initState) assertImageApproved(plt, 'roi/polylineroi/'+name+'_setstate', 'Reset ROI to initial state.') assert len(r.getState()['points']) == 3 diff --git a/pyqtgraph/tests/image_testing.py b/pyqtgraph/tests/image_testing.py index 2bd6e8d3..a7552631 100644 --- a/pyqtgraph/tests/image_testing.py +++ b/pyqtgraph/tests/image_testing.py @@ -44,7 +44,7 @@ Procedure for unit-testing with images: # pyqtgraph should be tested against. When adding or changing test images, # create and push a new tag and update this variable. To test locally, begin # by creating the tag in your ~/.pyqtgraph/test-data repository. -testDataTag = 'test-data-6' +testDataTag = 'test-data-7' import time