Bugfix: ScatterPlotItem not updating correctly when view is resized

Documentation updates (linked GLImageItem and Legend item to indexes)
This commit is contained in:
Luke Campagnola 2012-10-22 13:34:03 -04:00
parent 65ed889a77
commit 16434272c2
6 changed files with 18 additions and 34 deletions

View File

@ -18,6 +18,7 @@ Contents:
glgriditem
glmeshitem
glvolumeitem
glimageitem
glaxisitem
glgraphicsitem
meshdata

View File

@ -29,6 +29,7 @@ Contents:
scalebar
labelitem
vtickgroup
legenditem
gradienteditoritem
histogramlutitem
gradientlegend

View File

@ -394,14 +394,17 @@ class GraphicsItem(object):
if oldView is not None:
#print "disconnect:", self, oldView
oldView.sigRangeChanged.disconnect(self.viewRangeChanged)
oldView.sigTransformChanged.disconnect(self.viewTransformChanged)
self._connectedView = None
## connect to new view
if view is not None:
#print "connect:", self, view
view.sigRangeChanged.connect(self.viewRangeChanged)
view.sigTransformChanged.connect(self.viewTransformChanged)
self._connectedView = weakref.ref(view)
self.viewRangeChanged()
self.viewTransformChanged()
## inform children that their view might have changed
self._replaceView(oldView)
@ -425,3 +428,9 @@ class GraphicsItem(object):
Called whenever the view coordinates of the ViewBox containing this item have changed.
"""
pass
def viewTransformChanged(self):
"""
Called whenever the transformation matrix of the view has changed.
"""
pass

View File

@ -642,9 +642,9 @@ class ScatterPlotItem(GraphicsObject):
ymx = 0
return QtCore.QRectF(xmn, ymn, xmx-xmn, ymx-ymn)
def viewRangeChanged(self):
def viewTransformChanged(self):
self.prepareGeometryChange()
GraphicsObject.viewRangeChanged(self)
GraphicsObject.viewTransformChanged(self)
self.bounds = [None, None]
self.fragments = None

View File

@ -48,6 +48,7 @@ class ViewBox(GraphicsWidget):
sigRangeChanged = QtCore.Signal(object, object)
#sigActionPositionChanged = QtCore.Signal(object)
sigStateChanged = QtCore.Signal(object)
sigTransformChanged = QtCore.Signal(object)
## mouse modes
PanMode = 3
@ -307,10 +308,6 @@ class ViewBox(GraphicsWidget):
print("make qrectf failed:", self.state['viewRange'])
raise
#def viewportTransform(self):
##return self.itemTransform(self.childGroup)[0]
#return self.childGroup.itemTransform(self)[0]
def targetRange(self):
return [x[:] for x in self.state['targetRange']] ## return copy
@ -1121,29 +1118,15 @@ class ViewBox(GraphicsWidget):
m = QtGui.QTransform()
## First center the viewport at 0
#self.childGroup.resetTransform()
#self.resetTransform()
#center = self.transform().inverted()[0].map(bounds.center())
center = bounds.center()
#print " transform to center:", center
#if self.state['yInverted']:
#m.translate(center.x(), -center.y())
#print " inverted; translate", center.x(), center.y()
#else:
m.translate(center.x(), center.y())
#print " not inverted; translate", center.x(), -center.y()
## Now scale and translate properly
m.scale(scale[0], scale[1])
st = Point(vr.center())
#st = translate
m.translate(-st[0], -st[1])
self.childGroup.setTransform(m)
#self.setTransform(m)
#self.prepareGeometryChange()
#self.currentScale = scale
if changed[0]:
self.sigXRangeChanged.emit(self, tuple(self.state['viewRange'][0]))
@ -1151,6 +1134,8 @@ class ViewBox(GraphicsWidget):
self.sigYRangeChanged.emit(self, tuple(self.state['viewRange'][1]))
if any(changed):
self.sigRangeChanged.emit(self, self.state['viewRange'])
self.sigTransformChanged.emit(self)
def paint(self, p, opt, widget):
if self.border is not None:
@ -1159,20 +1144,6 @@ class ViewBox(GraphicsWidget):
#p.fillRect(bounds, QtGui.QColor(0, 0, 0))
p.drawPath(bounds)
#def saveSvg(self):
#pass
#def saveImage(self):
#pass
#def savePrint(self):
#printer = QtGui.QPrinter()
#if QtGui.QPrintDialog(printer).exec_() == QtGui.QDialog.Accepted:
#p = QtGui.QPainter(printer)
#p.setRenderHint(p.Antialiasing)
#self.scene().render(p)
#p.end()
def updateBackground(self):
bg = self.state['background']
if bg is None:

View File

@ -42,6 +42,7 @@ class GraphicsView(QtGui.QGraphicsView):
enabled via enableMouse() (but ordinarily, we use ViewBox for this functionality)."""
sigRangeChanged = QtCore.Signal(object, object)
sigTransformChanged = QtCore.Signal(object)
sigMouseReleased = QtCore.Signal(object)
sigSceneMouseMoved = QtCore.Signal(object)
#sigRegionChanged = QtCore.Signal(object)
@ -212,6 +213,7 @@ class GraphicsView(QtGui.QGraphicsView):
self.fitInView(self.range, QtCore.Qt.IgnoreAspectRatio)
self.sigRangeChanged.emit(self, self.range)
self.sigTransformChanged.emit(self)
if propagate:
for v in self.lockedViewports: