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
|
||||
from .. import debug
|
||||
import weakref
|
||||
import gc
|
||||
from .CanvasManager import CanvasManager
|
||||
from .CanvasItem import CanvasItem, GroupCanvasItem
|
||||
|
||||
|
||||
class Canvas(QtGui.QWidget):
|
||||
|
||||
sigSelectionChanged = QtCore.Signal(object, object)
|
||||
@ -417,25 +419,24 @@ class Canvas(QtGui.QWidget):
|
||||
ctrl = item.ctrlWidget()
|
||||
ctrl.hide()
|
||||
self.ui.ctrlLayout.removeWidget(ctrl)
|
||||
ctrl.setParent(None)
|
||||
else:
|
||||
if hasattr(item, '_canvasItem'):
|
||||
self.removeItem(item._canvasItem)
|
||||
else:
|
||||
self.view.removeItem(item)
|
||||
|
||||
## disconnect signals, remove from list, etc..
|
||||
|
||||
gc.collect()
|
||||
|
||||
def clear(self):
|
||||
while len(self.items) > 0:
|
||||
self.removeItem(self.items[0])
|
||||
|
||||
|
||||
def addToScene(self, item):
|
||||
self.view.addItem(item)
|
||||
|
||||
def removeFromScene(self, item):
|
||||
self.view.removeItem(item)
|
||||
|
||||
|
||||
def listItems(self):
|
||||
"""Return a dictionary of name:item pairs"""
|
||||
|
@ -453,6 +453,25 @@ class CanvasItem(QtCore.QObject):
|
||||
def isVisible(self):
|
||||
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):
|
||||
"""
|
||||
|
Loading…
x
Reference in New Issue
Block a user