프로젝트

일반

사용자정보

개정판 f93e6d5e

IDf93e6d5eaa847f890b4b54aa215105c9b914b269
상위 7bd122a8
하위 f730f5c4

백흠경이(가) 약 5년 전에 추가함

issue #1436: Undo/Redo 기능

Change-Id: I71577986ad523b3973454c7976f250f6c9418687

차이점 보기:

HYTOS/HYTOS/QtImageViewerScene.py
24 24

  
25 25
    def __init__(self, viewer):
26 26
        QGraphicsScene.__init__(self, viewer)
27
        self._undo_stack = QUndoStack(self)
28
        self._pressed_position = None
29

  
30
    @property
31
    def undo_stack(self):
32
        return self._undo_stack
27 33

  
28 34
    def addItem(self, item):
29 35
        """ add given item to scene """
......
40 46
        """delete selected items when press delete key"""
41 47
        from SymbolSvgItem import SymbolSvgItem
42 48
        from EngineeringCloudItem import QEngineeringCloudItem
49
        from DeleteCommand import DeleteCommand
43 50

  
44 51
        if event.key() == Qt.Key_Delete:
45
            selected = self.selectedItems()
46
            while selected:
47
                item = selected.pop()
48
                if issubclass(type(item), QGraphicsTextItem) and not item.hasFocus():
49
                    self.removeItem(item)
50
                elif type(item) is QEngineeringCloudItem:
51
                    self.removeItem(item)
52
                elif issubclass(type(item), SymbolSvgItem) or issubclass(type(item), QGraphicsPathItem):
53
                    item.transfer.onRemoved.emit(item)
52
            selected = [item for item in self.selectedItems()
53
                        if (issubclass(type(item), QGraphicsTextItem) and not item.hasFocus()) or
54
                        (type(item) is QEngineeringCloudItem) or
55
                        (issubclass(type(item), SymbolSvgItem)) or
56
                        (issubclass(type(item), QGraphicsPathItem))]
57

  
58
            self._undo_stack.push(DeleteCommand(self, selected))
59
        elif event.key() == Qt.Key_Z and event.modifiers() & Qt.ControlModifier:
60
            self._undo_stack.undo()
61
        elif event.key() == Qt.Key_R and event.modifiers() & Qt.ControlModifier:
62
            self._undo_stack.redo()
54 63

  
55 64
        QGraphicsScene.keyPressEvent(self, event)
56 65

  
66
    def mousePressEvent(self, event: 'QGraphicsSceneMouseEvent') -> None:
67
        from SymbolSvgItem import SymbolSvgItem
68

  
69
        if self.selectedItems() and not (type(self.selectedItems()[0]) is SymbolSvgItem and
70
                                         self.selectedItems()[0].get_selected_corner(event.scenePos())):
71
            self._pressed_position = event.scenePos()
72
        elif not self.selectedItems() and self.items(event.scenePos()):
73
            self._pressed_position = event.scenePos()
74

  
75
        super(QtImageViewerScene, self).mousePressEvent(event)
76

  
77
    def mouseReleaseEvent(self, event: 'QGraphicsSceneMouseEvent') -> None:
78
        from MoveCommand import MoveCommand
79

  
80
        if self._pressed_position and self._pressed_position != event.scenePos() and self.selectedItems():
81
            self._undo_stack.push(MoveCommand(self, event.scenePos() - self._pressed_position))
82
        self._pressed_position = None
83
        super(QtImageViewerScene, self).mouseReleaseEvent(event)
84

  
57 85
    """
58 86
    def rectForTile(self, x, y):
59 87
        # Return the rectangle for the tile at position (x, y).

내보내기 Unified diff

클립보드 이미지 추가 (최대 크기: 500 MB)