개정판 67cd9ddb
issue #366: Undo/Redo for flip
Change-Id: Icea5203d65651f46a832ddff1a821c9b7c4c64a6
DTI_PID/DTI_PID/Commands/FlipCommand.py | ||
---|---|---|
1 |
# coding: utf-8 |
|
2 |
""" This is flip command module """ |
|
3 |
import os.path |
|
4 |
import sys |
|
5 |
from SymbolSvgItem import SymbolSvgItem |
|
6 |
from EngineeringErrorItem import QEngineeringErrorItem |
|
7 |
from PyQt5.QtCore import * |
|
8 |
from PyQt5.QtGui import * |
|
9 |
from PyQt5.QtWidgets import * |
|
10 |
|
|
11 |
|
|
12 |
class FlipCommand(QUndoCommand): |
|
13 |
def __init__(self, scene, items, parent=None): |
|
14 |
from SymbolSvgItem import SymbolSvgItem |
|
15 |
|
|
16 |
super(FlipCommand, self).__init__(parent) |
|
17 |
self._scene = scene |
|
18 |
self._items = [item for item in items if issubclass(type(item), SymbolSvgItem) and |
|
19 |
type(self) is not QEngineeringErrorItem] |
|
20 |
self._params = None |
|
21 |
self._flipped = False |
|
22 |
|
|
23 |
def undo(self): |
|
24 |
"""undo""" |
|
25 |
for idx, item in enumerate(self._items): |
|
26 |
item.flip = self._params[idx] |
|
27 |
item.flip_symbol() |
|
28 |
|
|
29 |
self._scene.update() |
|
30 |
|
|
31 |
self._flipped = False |
|
32 |
|
|
33 |
def redo(self): |
|
34 |
"""redo""" |
|
35 |
if not self._flipped: |
|
36 |
_params = [] |
|
37 |
for idx, item in enumerate(self._items): |
|
38 |
_params.append(item.flip) |
|
39 |
item.flip = 0 if item.flip else 1 |
|
40 |
item.flip_symbol() |
|
41 |
|
|
42 |
self._params = _params |
|
43 |
self._scene.update() |
DTI_PID/DTI_PID/QtImageViewerScene.py | ||
---|---|---|
61 | 61 |
from EngineeringTextItem import QEngineeringTextItem |
62 | 62 |
from DeleteCommand import DeleteCommand |
63 | 63 |
from RotateCommand import RotateCommand |
64 |
from FlipCommand import FlipCommand |
|
64 | 65 |
|
65 | 66 |
try: |
66 | 67 |
if event.key() == Qt.Key_Delete: |
... | ... | |
94 | 95 |
self._undo_stack.redo() |
95 | 96 |
elif self.selectedItems() and event.key() == Qt.Key_R and not(event.modifiers() & Qt.ControlModifier): |
96 | 97 |
self._undo_stack.push(RotateCommand(self, self.selectedItems())) |
98 |
elif self.selectedItems() and event.key() == Qt.Key_F and not(event.modifiers() & Qt.ControlModifier): |
|
99 |
self._undo_stack.push(FlipCommand(self, self.selectedItems())) |
|
97 | 100 |
|
98 | 101 |
super(QtImageViewerScene, self).keyPressEvent(event) |
99 | 102 |
except Exception as ex: |
DTI_PID/DTI_PID/Shapes/SymbolSvgItem.py | ||
---|---|---|
1036 | 1036 |
|
1037 | 1037 |
if not self.isSelected(): |
1038 | 1038 |
return |
1039 |
if event.key() == Qt.Key_B: |
|
1039 |
elif event.key() == Qt.Key_B:
|
|
1040 | 1040 |
self.bind_close_items() |
1041 |
""" |
|
1042 |
elif event.key() == Qt.Key_R and QApplication.keyboardModifiers() != Qt.ControlModifier and \ |
|
1043 |
type(self) is not QEngineeringErrorItem: |
|
1044 |
self.rotateSymbol() |
|
1045 |
""" |
|
1046 |
if event.key() == Qt.Key_O and type(self) is not QEngineeringErrorItem: |
|
1041 |
elif event.key() == Qt.Key_O and type(self) is not QEngineeringErrorItem: |
|
1047 | 1042 |
pass |
1048 | 1043 |
elif event.key() == Qt.Key_C and type(self) is not QEngineeringErrorItem: |
1049 | 1044 |
self.changeConnPoint() |
1050 |
elif event.key() == Qt.Key_F and type(self) is not QEngineeringErrorItem: |
|
1051 |
self.flip = 1 if self.flip is 0 else 0 |
|
1052 |
self.flip_symbol() |
|
1053 | 1045 |
elif event.key() == Qt.Key_Return: |
1054 | 1046 |
return |
1055 | 1047 |
# disable |
내보내기 Unified diff