aboutsummaryrefslogtreecommitdiff
path: root/src/gui/actions.py
blob: 5cf64e118822b9f62e19c54f77b73610630e2278 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
'''
    QCommand classes for every undoable user action performed in the MainWindow
'''
from PyQt5.QtWidgets import QUndoCommand


class RemoveComponent(QUndoCommand):
    def __init__(self, parent, selectedRows):
        super().__init__('Remove component')
        self.parent = parent
        componentList = self.parent.window.listWidget_componentList
        self.selectedRows = [
            componentList.row(selected) for selected in selectedRows
        ]
        self.components = [
            parent.core.selectedComponents[i] for i in self.selectedRows
        ]

    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()

    def undo(self):
        componentList = self.parent.window.listWidget_componentList
        for index, comp in zip(self.selectedRows, self.components):
            self.parent.core.insertComponent(
                index, comp, self.parent
            )
        self.parent.drawPreview()