Add CanvasItem.saveState/restoreState
This commit is contained in:
parent
ee117fd957
commit
65b5b6a7bc
@ -19,9 +19,11 @@ elif QT_LIB == 'PyQt5':
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
from .. import debug
|
from .. import debug
|
||||||
import weakref
|
import weakref
|
||||||
|
import gc
|
||||||
from .CanvasManager import CanvasManager
|
from .CanvasManager import CanvasManager
|
||||||
from .CanvasItem import CanvasItem, GroupCanvasItem
|
from .CanvasItem import CanvasItem, GroupCanvasItem
|
||||||
|
|
||||||
|
|
||||||
class Canvas(QtGui.QWidget):
|
class Canvas(QtGui.QWidget):
|
||||||
|
|
||||||
sigSelectionChanged = QtCore.Signal(object, object)
|
sigSelectionChanged = QtCore.Signal(object, object)
|
||||||
@ -417,25 +419,24 @@ class Canvas(QtGui.QWidget):
|
|||||||
ctrl = item.ctrlWidget()
|
ctrl = item.ctrlWidget()
|
||||||
ctrl.hide()
|
ctrl.hide()
|
||||||
self.ui.ctrlLayout.removeWidget(ctrl)
|
self.ui.ctrlLayout.removeWidget(ctrl)
|
||||||
|
ctrl.setParent(None)
|
||||||
else:
|
else:
|
||||||
if hasattr(item, '_canvasItem'):
|
if hasattr(item, '_canvasItem'):
|
||||||
self.removeItem(item._canvasItem)
|
self.removeItem(item._canvasItem)
|
||||||
else:
|
else:
|
||||||
self.view.removeItem(item)
|
self.view.removeItem(item)
|
||||||
|
|
||||||
## disconnect signals, remove from list, etc..
|
gc.collect()
|
||||||
|
|
||||||
def clear(self):
|
def clear(self):
|
||||||
while len(self.items) > 0:
|
while len(self.items) > 0:
|
||||||
self.removeItem(self.items[0])
|
self.removeItem(self.items[0])
|
||||||
|
|
||||||
|
|
||||||
def addToScene(self, item):
|
def addToScene(self, item):
|
||||||
self.view.addItem(item)
|
self.view.addItem(item)
|
||||||
|
|
||||||
def removeFromScene(self, item):
|
def removeFromScene(self, item):
|
||||||
self.view.removeItem(item)
|
self.view.removeItem(item)
|
||||||
|
|
||||||
|
|
||||||
def listItems(self):
|
def listItems(self):
|
||||||
"""Return a dictionary of name:item pairs"""
|
"""Return a dictionary of name:item pairs"""
|
||||||
|
@ -453,6 +453,25 @@ class CanvasItem(QtCore.QObject):
|
|||||||
def isVisible(self):
|
def isVisible(self):
|
||||||
return self.opts['visible']
|
return self.opts['visible']
|
||||||
|
|
||||||
|
def saveState(self):
|
||||||
|
return {
|
||||||
|
'type': self.__class__.__name__,
|
||||||
|
'name': self.name,
|
||||||
|
'visible': self.isVisible(),
|
||||||
|
'alpha': self.alpha(),
|
||||||
|
'userTransform': self.saveTransform(),
|
||||||
|
'z': self.zValue(),
|
||||||
|
'scalable': self.opts['scalable'],
|
||||||
|
'rotatable': self.opts['rotatable'],
|
||||||
|
'movable': self.opts['movable'],
|
||||||
|
}
|
||||||
|
|
||||||
|
def restoreState(self, state):
|
||||||
|
self.setVisible(state['visible'])
|
||||||
|
self.setAlpha(state['alpha'])
|
||||||
|
self.restoreTransform(state['userTransform'])
|
||||||
|
self.setZValue(state['z'])
|
||||||
|
|
||||||
|
|
||||||
class GroupCanvasItem(CanvasItem):
|
class GroupCanvasItem(CanvasItem):
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user