fix: polylineroi segment draws to wrong handle after click
This commit is contained in:
parent
9b9a72e6bf
commit
c6839b4708
@ -571,7 +571,6 @@ class ROI(GraphicsObject):
|
|||||||
## Note: by default, handles are not user-removable even if this method returns True.
|
## Note: by default, handles are not user-removable even if this method returns True.
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def getLocalHandlePositions(self, index=None):
|
def getLocalHandlePositions(self, index=None):
|
||||||
"""Returns the position of handles in the ROI's coordinate system.
|
"""Returns the position of handles in the ROI's coordinate system.
|
||||||
|
|
||||||
@ -1969,9 +1968,13 @@ class LineSegmentROI(ROI):
|
|||||||
if len(positions) > 2:
|
if len(positions) > 2:
|
||||||
raise Exception("LineSegmentROI must be defined by exactly 2 positions. For more points, use PolyLineROI.")
|
raise Exception("LineSegmentROI must be defined by exactly 2 positions. For more points, use PolyLineROI.")
|
||||||
|
|
||||||
self.endpoints = []
|
|
||||||
for i, p in enumerate(positions):
|
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):
|
def listPoints(self):
|
||||||
return [p['item'].pos() for p in self.handles]
|
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.
|
See ROI.getArrayRegion() for a description of the arguments.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
imgPts = [self.mapToItem(img, h.pos()) for h in self.endpoints]
|
imgPts = [self.mapToItem(img, h.pos()) for h in self.endpoints]
|
||||||
rgns = []
|
rgns = []
|
||||||
coords = []
|
coords = []
|
||||||
|
@ -208,15 +208,23 @@ def test_PolyLineROI():
|
|||||||
# click segment
|
# click segment
|
||||||
mouseClick(plt, pt, QtCore.Qt.LeftButton)
|
mouseClick(plt, pt, QtCore.Qt.LeftButton)
|
||||||
assertImageApproved(plt, 'roi/polylineroi/'+name+'_click_segment', 'Click mouse over segment.')
|
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()
|
r.clearPoints()
|
||||||
assertImageApproved(plt, 'roi/polylineroi/'+name+'_clear', 'All points cleared.')
|
assertImageApproved(plt, 'roi/polylineroi/'+name+'_clear', 'All points cleared.')
|
||||||
assert len(r.getState()['points']) == 0
|
assert len(r.getState()['points']) == 0
|
||||||
|
|
||||||
|
# call setPoints
|
||||||
r.setPoints(initState['points'])
|
r.setPoints(initState['points'])
|
||||||
assertImageApproved(plt, 'roi/polylineroi/'+name+'_setpoints', 'Reset points to initial state.')
|
assertImageApproved(plt, 'roi/polylineroi/'+name+'_setpoints', 'Reset points to initial state.')
|
||||||
assert len(r.getState()['points']) == 3
|
assert len(r.getState()['points']) == 3
|
||||||
|
|
||||||
|
# call setState
|
||||||
r.setState(initState)
|
r.setState(initState)
|
||||||
assertImageApproved(plt, 'roi/polylineroi/'+name+'_setstate', 'Reset ROI to initial state.')
|
assertImageApproved(plt, 'roi/polylineroi/'+name+'_setstate', 'Reset ROI to initial state.')
|
||||||
assert len(r.getState()['points']) == 3
|
assert len(r.getState()['points']) == 3
|
||||||
|
@ -44,7 +44,7 @@ Procedure for unit-testing with images:
|
|||||||
# pyqtgraph should be tested against. When adding or changing test 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
|
# create and push a new tag and update this variable. To test locally, begin
|
||||||
# by creating the tag in your ~/.pyqtgraph/test-data repository.
|
# by creating the tag in your ~/.pyqtgraph/test-data repository.
|
||||||
testDataTag = 'test-data-6'
|
testDataTag = 'test-data-7'
|
||||||
|
|
||||||
|
|
||||||
import time
|
import time
|
||||||
|
Loading…
Reference in New Issue
Block a user