mirror of
https://github.com/alicevision/Meshroom.git
synced 2025-05-19 20:16:30 +02:00
[commands] add ListAttributeAppend/Remove commands
This commit is contained in:
parent
61ade5bfa7
commit
c30b92b695
2 changed files with 49 additions and 0 deletions
|
@ -164,3 +164,44 @@ class RemoveEdgeCommand(GraphCommand):
|
||||||
def undoImpl(self):
|
def undoImpl(self):
|
||||||
self.graph.addEdge(self.graph.attribute(self.srcAttr),
|
self.graph.addEdge(self.graph.attribute(self.srcAttr),
|
||||||
self.graph.attribute(self.dstAttr))
|
self.graph.attribute(self.dstAttr))
|
||||||
|
|
||||||
|
|
||||||
|
class ListAttributeAppendCommand(GraphCommand):
|
||||||
|
def __init__(self, graph, listAttribute, value, parent=None):
|
||||||
|
super(ListAttributeAppendCommand, self).__init__(graph, parent)
|
||||||
|
assert isinstance(listAttribute, ListAttribute)
|
||||||
|
self.attrName = listAttribute.fullName()
|
||||||
|
self.index = None
|
||||||
|
self.value = value
|
||||||
|
self.setText("Append to {}".format(self.attrName))
|
||||||
|
|
||||||
|
def redoImpl(self):
|
||||||
|
listAttribute = self.graph.attribute(self.attrName)
|
||||||
|
listAttribute.append(self.value)
|
||||||
|
self.index = len(listAttribute) - 1
|
||||||
|
return True
|
||||||
|
|
||||||
|
def undoImpl(self):
|
||||||
|
listAttribute = self.graph.attribute(self.attrName)
|
||||||
|
listAttribute.remove(self.index)
|
||||||
|
|
||||||
|
|
||||||
|
class ListAttributeRemoveCommand(GraphCommand):
|
||||||
|
def __init__(self, graph, attribute, parent=None):
|
||||||
|
super(ListAttributeRemoveCommand, self).__init__(graph, parent)
|
||||||
|
listAttribute = attribute.parent()
|
||||||
|
assert isinstance(listAttribute, ListAttribute)
|
||||||
|
self.listAttrName = listAttribute.fullName()
|
||||||
|
self.index = listAttribute.index(attribute)
|
||||||
|
self.value = attribute.getExportValue()
|
||||||
|
self.setText("Remove {}".format(attribute.fullName()))
|
||||||
|
|
||||||
|
def redoImpl(self):
|
||||||
|
listAttribute = self.graph.attribute(self.listAttrName)
|
||||||
|
listAttribute.remove(self.index)
|
||||||
|
return True
|
||||||
|
|
||||||
|
def undoImpl(self):
|
||||||
|
listAttribute = self.graph.attribute(self.listAttrName)
|
||||||
|
listAttribute.insert(self.value, self.index)
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,14 @@ class Reconstruction(QObject):
|
||||||
def setAttribute(self, attribute, value):
|
def setAttribute(self, attribute, value):
|
||||||
self._undoStack.tryAndPush(commands.SetAttributeCommand(self._graph, attribute, value))
|
self._undoStack.tryAndPush(commands.SetAttributeCommand(self._graph, attribute, value))
|
||||||
|
|
||||||
|
@Slot(graph.Attribute, QJsonValue)
|
||||||
|
def appendAttribute(self, attribute, value):
|
||||||
|
self._undoStack.tryAndPush(commands.ListAttributeAppendCommand(self._graph, attribute, value.toObject()))
|
||||||
|
|
||||||
|
@Slot(graph.Attribute)
|
||||||
|
def removeAttribute(self, attribute):
|
||||||
|
self._undoStack.tryAndPush(commands.ListAttributeRemoveCommand(self._graph, attribute))
|
||||||
|
|
||||||
@Slot(str)
|
@Slot(str)
|
||||||
def load(self, filepath):
|
def load(self, filepath):
|
||||||
self._graph.load(filepath)
|
self._graph.load(filepath)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue