개정판 776e52d3
issue #1047: 객체 삭제
Change-Id: Iafd94789cfd17758802dc2fcb96793d80ca9331f
HYTOS/HYTOS/MainWindow.py | ||
---|---|---|
1580 | 1580 |
try: |
1581 | 1581 |
self.itemTreeWidget.itemRemoved(item) |
1582 | 1582 |
|
1583 |
matches = [_item for _item in self.graphicsView.scene.items() if hasattr(_item, 'connectors') and [connector for connector in _item.connectors if connector.connectedItem is item]] |
|
1583 |
matches = [_item for _item in self.graphicsView.scene.items() if hasattr(_item, 'connectors') and \ |
|
1584 |
[connector for connector in _item.connectors if connector.connectedItem is not None and connector.connectedItem.parentItem() is item]] |
|
1584 | 1585 |
for match in matches: |
1585 | 1586 |
for connector in match.connectors: |
1586 |
if connector.connectedItem is item: connector.connectedItem = None |
|
1587 |
|
|
1588 |
#matches = [_item for _item in self.graphicsView.scene.items() if hasattr(_item, 'remove_assoc_item')] |
|
1589 |
#for _item in matches: |
|
1590 |
# _item.remove_assoc_item(item) |
|
1587 |
if connector.connectedItem.parentItem() is item: connector.connect(None) |
|
1591 | 1588 |
|
1592 | 1589 |
matches = [_item for _item in self.graphicsView.scene.items() if type(_item) is QEngineeringLineNoTextItem] |
1593 | 1590 |
for match in matches: |
... | ... | |
1621 | 1618 |
break |
1622 | 1619 |
if done: break |
1623 | 1620 |
|
1624 |
if type(item) is QEngineeringFlowMarkItem and item.parentItem(): |
|
1625 |
if item in item.parentItem()._flowMark: |
|
1626 |
item.parentItem()._flowMark.pop(item.parentItem()._flowMark.index(item)) |
|
1627 |
|
|
1628 |
if item.scene() is not None: item.scene().removeItem(item) |
|
1621 |
if item.scene() is not None: |
|
1622 |
item.scene().removeItem(item) |
|
1623 |
del item |
|
1629 | 1624 |
except Exception as ex: |
1630 | 1625 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
1631 | 1626 |
self.addMessage.emit(MessageType.Error, message) |
HYTOS/HYTOS/Shapes/EngineeringConnectorItem.py | ||
---|---|---|
63 | 63 |
|
64 | 64 |
if type(parent) is SymbolSvgItem: |
65 | 65 |
""" setup label for connector index """ |
66 |
self._label = QGraphicsTextItem('{}'.format(index), self) |
|
67 |
self._label.setAcceptedMouseButtons(Qt.NoButton) |
|
68 |
self._label.setZValue(0) |
|
69 |
font = QFont('Arial', QEngineeringConnectorItem.SMALL_SIZE) |
|
70 |
font.setPointSizeF(5) |
|
71 |
self._label.setFont(font) |
|
66 |
self._font = QFont('Arial', QEngineeringConnectorItem.SMALL_SIZE) |
|
67 |
self._font.setPointSizeF(5) |
|
68 |
self._conn_index = index |
|
72 | 69 |
|
73 | 70 |
@property |
74 | 71 |
def connectedItem(self): |
... | ... | |
410 | 407 |
@date 2018.04.21 |
411 | 408 |
''' |
412 | 409 |
def paint(self, painter, options=None, widget=None): |
413 |
QGraphicsEllipseItem.paint(self, painter, options, widget)
|
|
410 |
from SymbolSvgItem import SymbolSvgItem
|
|
414 | 411 |
|
415 |
if self.parentItem() is not None and hasattr(self, '_label'): |
|
416 |
self._label.setDefaultTextColor(Qt.red) if self.parentItem().hover else self._label.setDefaultTextColor(Qt.black) |
|
412 |
QGraphicsEllipseItem.paint(self, painter, options, widget) |
|
413 |
if type(self.parentItem()) is SymbolSvgItem: |
|
414 |
painter.setFont(self._font) |
|
415 |
painter.drawText(self.boundingRect(), str(self._conn_index), QTextOption(Qt.AlignCenter)) |
|
417 | 416 |
|
418 | 417 |
''' |
419 | 418 |
@brief check Overlap |
HYTOS/HYTOS/Shapes/EngineeringStreamlineItem.py | ||
---|---|---|
37 | 37 |
QGraphicsPathItem.__init__(self, parent) |
38 | 38 |
QEngineeringAbstractItem.__init__(self) |
39 | 39 |
self.setFlags(QGraphicsItem.ItemIsSelectable|QGraphicsItem.ItemIsFocusable) |
40 |
self.setAcceptHoverEvents(True) |
|
41 |
self.setAcceptTouchEvents(True) |
|
40 | 42 |
|
41 | 43 |
self.uid = uuid.uuid4() if uid is None else uid |
42 | 44 |
self._vertices = [] |
... | ... | |
45 | 47 |
self.setPen(QPen(Qt.blue, 1, Qt.SolidLine)) # set default pen |
46 | 48 |
|
47 | 49 |
self.transfer = Transfer() |
50 |
self.transfer.onRemoved.connect(self.on_item_removed) |
|
48 | 51 |
self.setZValue(QEngineeringStreamlineItem.ZVALUE) |
49 | 52 |
except Exception as ex: |
50 | 53 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
... | ... | |
227 | 230 |
self.__buildItem() |
228 | 231 |
self.update() |
229 | 232 |
|
233 |
def hoverEnterEvent(self, event): |
|
234 |
""" hilight item and it's children """ |
|
235 |
self.highlight(True) |
|
236 |
|
|
237 |
def hoverLeaveEvent(self, event): |
|
238 |
""" unhighlight item """ |
|
239 |
self.highlight(False) |
|
240 |
|
|
241 |
def highlight(self, flag): |
|
242 |
self.hover = flag |
|
243 |
self.setZValue(QEngineeringAbstractItem.HOVER_ZVALUE) if flag else self.setZValue(QEngineeringStreamlineItem.ZVALUE) |
|
244 |
self.update() |
|
245 |
|
|
246 |
''' |
|
247 |
@brief override paint method |
|
248 |
@history humkyung 2018.08.30 draw flowmark only for Primary or Secondary |
|
249 |
''' |
|
250 |
def paint(self, painter, option, widget): |
|
251 |
if self.isSelected(): |
|
252 |
hilightColor = QColor(255, 0, 0, 127) |
|
253 |
focuspen = QPen(Qt.DotLine) |
|
254 |
focuspen.setColor(hilightColor) |
|
255 |
focuspen.setWidthF(10) |
|
256 |
brush = QBrush(hilightColor, Qt.Dense7Pattern) |
|
257 |
painter.setBrush(brush) |
|
258 |
painter.setPen(focuspen) |
|
259 |
else: |
|
260 |
color = self.getColor() |
|
261 |
self.setColor(color) |
|
262 |
|
|
263 |
QGraphicsPathItem.paint(self, painter, option, widget) |
|
264 |
|
|
265 |
def on_item_removed(self, item): |
|
266 |
""" remove item from scene and then delete it """ |
|
267 |
if item is self: |
|
268 |
for conn in item.connectors: |
|
269 |
if conn.connectedItem is not None: conn.connectedItem.connect(None) |
|
270 |
|
|
271 |
self.scene().removeItem(item) |
|
272 |
del item |
|
273 |
|
|
230 | 274 |
''' |
231 | 275 |
@brief Return real item position |
232 | 276 |
@authro Jeongwoo |
... | ... | |
255 | 299 |
|
256 | 300 |
def on_symbol_pos_changed(self, symbol): |
257 | 301 |
""" rebuild stream line because symbol position is changed """ |
258 |
self.connectors[0].setPos(self.connectors[0].connectedItem.center()) |
|
259 |
self.connectors[-1].setPos(self.connectors[-1].connectedItem.center()) |
|
302 |
if self.connectors[0].connectedItem is not None : self.connectors[0].setPos(self.connectors[0].connectedItem.center())
|
|
303 |
if self.connectors[-1].connectedItem is not None : self.connectors[-1].setPos(self.connectors[-1].connectedItem.center())
|
|
260 | 304 |
self.on_connector_pos_changed(None) |
261 | 305 |
|
262 | 306 |
def on_connector_pos_changed(self, connector): |
HYTOS/HYTOS/Shapes/SymbolSvgItem.py | ||
---|---|---|
710 | 710 |
2018.05.25 Jeongwoo Seperate delete item method |
711 | 711 |
''' |
712 | 712 |
def keyPressEvent(self, event): |
713 |
if not self.isSelected(): |
|
714 |
return |
|
713 |
if not self.isSelected(): return
|
|
714 |
|
|
715 | 715 |
if event.key() == Qt.Key_Delete: |
716 | 716 |
self.deleteSvgItemFromScene() |
717 | 717 |
elif event.key() == Qt.Key_R: |
... | ... | |
722 | 722 |
self.changeConnPoint() |
723 | 723 |
elif event.key() == Qt.Key_F: |
724 | 724 |
self.flipSymbol() |
725 |
elif event.key() == Qt.Key_Up: ### translate symbol |
|
726 |
transform = QTransform() |
|
727 |
transform.translate(0, -1) |
|
728 |
self.setTransform(transform) |
|
729 |
elif event.key() == Qt.Key_Down: |
|
730 |
pass |
|
731 |
elif event.key() == Qt.Key_Left: |
|
732 |
pass |
|
733 |
elif event.key() == Qt.Key_Right: |
|
734 |
pass |
|
725 | 735 |
|
726 | 736 |
''' |
727 | 737 |
@brief connect attribute |
... | ... | |
1302 | 1312 |
for connector in self.connectors: |
1303 | 1313 |
connector.buildItem() |
1304 | 1314 |
|
1305 |
''' |
|
1306 |
@brief Delete svg item |
|
1307 |
@author Jeongwoo |
|
1308 |
@date 2018.05.25 |
|
1309 |
''' |
|
1310 | 1315 |
def deleteSvgItemFromScene(self): |
1311 |
for connector in self.connectors:
|
|
1312 |
if connector.connectedItem is not None:
|
|
1313 |
try:
|
|
1314 |
connector.connectedItem.removeSymbol(self)
|
|
1315 |
except Exception as ex:
|
|
1316 |
from App import App
|
|
1317 |
from AppDocData import MessageType
|
|
1318 |
|
|
1319 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
|
1320 |
App.mainWnd().addMessage.emit(MessageType.Error, message)
|
|
1321 |
break
|
|
1316 |
""" remove self from scene """
|
|
1317 |
try:
|
|
1318 |
for conn in self.connectors:
|
|
1319 |
if conn.connectedItem is not None:
|
|
1320 |
conn.connectedItem.connect(None)
|
|
1321 |
except Exception as ex:
|
|
1322 |
from App import App
|
|
1323 |
from AppDocData import MessageType |
|
1324 |
|
|
1325 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
|
|
1326 |
App.mainWnd().addMessage.emit(MessageType.Error, message)
|
|
1322 | 1327 |
|
1323 | 1328 |
self.transfer.onRemoved.emit(self) |
1324 | 1329 |
|
내보내기 Unified diff