fix: polylineroi segment draws to wrong handle after click

This commit is contained in:
Luke Campagnola 2017-10-17 21:22:55 -07:00
parent 9b9a72e6bf
commit c6839b4708
3 changed files with 15 additions and 5 deletions

View File

@ -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 = []

View File

@ -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

View File

@ -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