aboutsummaryrefslogtreecommitdiff
path: root/src/gui/actions.py
diff options
context:
space:
mode:
authortassaron2017-08-17 10:42:15 -0400
committertassaron2017-08-17 10:42:15 -0400
commitc06ca5cdcb603f1855cb0122fc2ab6d2473f3c24 (patch)
tree383cabd30bc1dcfc95839b31818b5878eb676e35 /src/gui/actions.py
parentf66ec40ba6e9c4062d1e41894e0a88f713add96d (diff)
undoable add-comp & clear-preset actions
Diffstat (limited to 'src/gui/actions.py')
-rw-r--r--src/gui/actions.py45
1 files changed, 36 insertions, 9 deletions
diff --git a/src/gui/actions.py b/src/gui/actions.py
index 5a0869d..cdd3dfa 100644
--- a/src/gui/actions.py
+++ b/src/gui/actions.py
@@ -4,6 +4,23 @@
from PyQt5.QtWidgets import QUndoCommand
+class AddComponent(QUndoCommand):
+ def __init__(self, parent, compI, moduleI):
+ super().__init__(
+ "New %s component" %
+ parent.core.modules[moduleI].Component.name
+ )
+ self.parent = parent
+ self.moduleI = moduleI
+ self.compI = compI
+
+ def redo(self):
+ self.parent.core.insertComponent(self.compI, self.moduleI, self.parent)
+
+ def undo(self):
+ self.parent._removeComponent(self.compI)
+
+
class RemoveComponent(QUndoCommand):
def __init__(self, parent, selectedRows):
super().__init__('Remove component')
@@ -17,15 +34,7 @@ class RemoveComponent(QUndoCommand):
]
def redo(self):
- stackedWidget = self.parent.window.stackedWidget
- componentList = self.parent.window.listWidget_componentList
- for index in self.selectedRows:
- stackedWidget.removeWidget(self.parent.pages[index])
- componentList.takeItem(index)
- self.parent.core.removeComponent(index)
- self.parent.pages.pop(index)
- self.parent.changeComponentWidget()
- self.parent.drawPreview()
+ self.parent._removeComponent(self.selectedRows[0])
def undo(self):
componentList = self.parent.window.listWidget_componentList
@@ -74,3 +83,21 @@ class MoveComponent(QUndoCommand):
def undo(self):
self.do(self.newRow, self.row)
+
+
+class ClearPreset(QUndoCommand):
+ def __init__(self, parent, compI):
+ super().__init__("Clear preset")
+ self.parent = parent
+ self.compI = compI
+ self.component = self.parent.core.selectedComponents[compI]
+ self.store = self.component.savePreset()
+ self.store['preset'] = self.component.currentPreset
+
+ def redo(self):
+ self.parent.core.clearPreset(self.compI)
+ self.parent.updateComponentTitle(self.compI, False)
+
+ def undo(self):
+ self.parent.core.selectedComponents[self.compI].loadPreset(self.store)
+ self.parent.updateComponentTitle(self.compI, self.store)