Commit 16434272 authored by Luke Campagnola's avatar Luke Campagnola
Browse files

Bugfix: ScatterPlotItem not updating correctly when view is resized

Documentation updates (linked GLImageItem and Legend item to indexes)
parent 65ed889a
......@@ -18,6 +18,7 @@ Contents:
glgriditem
glmeshitem
glvolumeitem
glimageitem
glaxisitem
glgraphicsitem
meshdata
......
......@@ -29,6 +29,7 @@ Contents:
scalebar
labelitem
vtickgroup
legenditem
gradienteditoritem
histogramlutitem
gradientlegend
......
......@@ -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
\ No newline at end of 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
......
......@@ -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:
......
......@@ -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:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment