28 |
28 |
from AppDocData import AppDocData
|
29 |
29 |
from Drawing import Drawing
|
30 |
30 |
|
|
31 |
class CustomTreeWidgetItem(QTreeWidgetItem):
|
|
32 |
def __init__(self, *args, **kwargs):
|
|
33 |
super(CustomTreeWidgetItem, self).__init__(*args, **kwargs)
|
|
34 |
|
|
35 |
def setData(self, column, role, value):
|
|
36 |
if role == Qt.EditRole:
|
|
37 |
pass
|
|
38 |
elif role == Qt.CheckStateRole:
|
|
39 |
if self.treeWidget() is not None:
|
|
40 |
state = Qt.CheckState.Unchecked if value is 0 else Qt.CheckState.Checked
|
|
41 |
self.treeWidget().checkBoxToggled.emit(self, state)
|
|
42 |
|
|
43 |
super(CustomTreeWidgetItem, self).setData(column, role, value)
|
|
44 |
|
31 |
45 |
class QItemTreeWidget(QTreeWidget):
|
32 |
46 |
TREE_DATA_ROLE = Qt.UserRole
|
33 |
47 |
|
... | ... | |
36 |
50 |
noteNoSingleClicked = pyqtSignal(str, dict)
|
37 |
51 |
lineNoSingleClicked = pyqtSignal(QEngineeringAbstractItem)
|
38 |
52 |
drawingClicked = pyqtSignal(Drawing)
|
|
53 |
checkBoxToggled = pyqtSignal(QTreeWidgetItem, Qt.CheckState)
|
39 |
54 |
|
40 |
55 |
'''
|
41 |
56 |
@history 2018.05.11 Jeongwoo Add Context Menu settings
|
42 |
57 |
'''
|
43 |
58 |
def __init__(self, imageViewer):
|
44 |
59 |
QTreeWidget.__init__(self)
|
|
60 |
|
|
61 |
self.checkBoxToggled.connect(self.itemCheckBoxToggled)
|
|
62 |
|
45 |
63 |
self.itemClicked.connect(self.itemClickEvent)
|
46 |
64 |
self.imageViewer = imageViewer
|
47 |
65 |
self.scene = imageViewer.scene
|
... | ... | |
265 |
283 |
item = QTreeWidgetItem(self.SymbolsTreeItem, [child.name])
|
266 |
284 |
|
267 |
285 |
if item is not None:
|
268 |
|
#if type(child) is QEngineeringErrorItem:
|
269 |
|
# iconPath = appDocData.getErrorItemSvgPath()
|
270 |
|
#else:
|
271 |
|
#iconPath = os.path.join(AppDocData.instance().getCurrentProject().getSvgFilePath(), child.type , child.name + ".svg")
|
272 |
286 |
iconPath = os.path.join(AppDocData.instance().getCurrentProject().getSvgFilePath(), child.type , child.name + ".svg")
|
273 |
287 |
item.setIcon(0, QIcon(iconPath))
|
274 |
288 |
item.setData(0, self.TREE_DATA_ROLE, child)
|
... | ... | |
280 |
294 |
self.SymbolsTreeItem.addChild(item)
|
281 |
295 |
self.SymbolsTreeItem.sortChildren(0, Qt.AscendingOrder) # sort childrens
|
282 |
296 |
elif type(child) is QEngineeringLineNoTextItem:
|
283 |
|
item = QTreeWidgetItem([child.text()])
|
|
297 |
item = CustomTreeWidgetItem([child.text()])
|
284 |
298 |
item.setFlags(item.flags() | Qt.ItemIsUserCheckable)
|
285 |
299 |
item.setData(0, self.TREE_DATA_ROLE, child)
|
286 |
|
item.setCheckState(0, Qt.Unchecked)
|
|
300 |
item.setCheckState(0, Qt.Checked if child.isVisible() else Qt.Unchecked)
|
287 |
301 |
brush = QBrush()
|
288 |
302 |
brush.setColor(QColor(child.getColor()))
|
289 |
303 |
item.setForeground(0, brush)
|
... | ... | |
291 |
305 |
child.treeItem = item
|
292 |
306 |
self.LineNoTreeItem.addChild(item)
|
293 |
307 |
elif type(child) is QEngineeringTrimLineNoTextItem:
|
294 |
|
item = QTreeWidgetItem(['Trim Line'])
|
|
308 |
item = CustomTreeWidgetItem(['Trim Line'])
|
295 |
309 |
item.setFlags(item.flags() | Qt.ItemIsUserCheckable)
|
296 |
310 |
item.setData(0, self.TREE_DATA_ROLE, child)
|
297 |
|
item.setCheckState(0, Qt.Unchecked)
|
|
311 |
item.setCheckState(0, Qt.Checked if child.isVisible() else Qt.Unchecked)
|
298 |
312 |
brush = QBrush()
|
299 |
313 |
brush.setColor(QColor(child.getColor()))
|
300 |
314 |
item.setForeground(0, brush)
|
... | ... | |
409 |
423 |
|
410 |
424 |
self.expandAll()
|
411 |
425 |
|
|
426 |
def itemCheckBoxToggled(self, item, checkState):
|
|
427 |
"""
|
|
428 |
set visible of invisible of item
|
|
429 |
"""
|
|
430 |
try:
|
|
431 |
itemData = item.data(0, self.TREE_DATA_ROLE)
|
|
432 |
if (type(itemData) is QEngineeringLineNoTextItem) or (type(itemData) is QEngineeringTrimLineNoTextItem):
|
|
433 |
itemData.setVisible(checkState == Qt.CheckState.Checked)
|
|
434 |
except Exception as ex:
|
|
435 |
from App import App
|
|
436 |
from AppDocData import MessageType
|
|
437 |
|
|
438 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
|
|
439 |
App.mainWnd().addMessage.emit(MessageType.Error, message)
|
|
440 |
finally:
|
|
441 |
pass
|
|
442 |
|
412 |
443 |
'''
|
413 |
444 |
@brief TreeWidget Item click listener
|
414 |
445 |
@author Jeongwoo
|
... | ... | |
445 |
476 |
self.singleClicked.emit(itemData)
|
446 |
477 |
elif (type(itemData) is QEngineeringLineNoTextItem) or (type(itemData) is QEngineeringRunItem):
|
447 |
478 |
HighlightCommand(self.imageViewer).execute(itemData)
|
448 |
|
'''
|
449 |
|
if type(itemData) is QEngineeringLineNoTextItem:
|
450 |
|
rect = itemData.sceneBoundingRect()
|
451 |
|
if isSvgClick == False:
|
452 |
|
self.imageViewer.centerOn(rect.center())
|
453 |
|
## Send new event to imageViewer's zoomImage Method
|
454 |
|
self.imageViewer.zoomImage(True, QMouseEvent(QEvent.MouseButtonPress, self.imageViewer.mapFromScene(QPointF(rect.left(), rect.top())), Qt.LeftButton, Qt.LeftButton, Qt.NoModifier), 3)
|
455 |
|
else:
|
456 |
|
pass
|
457 |
|
'''
|
458 |
|
|
459 |
479 |
self.lineNoSingleClicked.emit(itemData)
|
460 |
480 |
item.setSelected(True)
|
461 |
481 |
elif type(itemData) is list and type(itemData[0]) is QEngineeringNoteItem:
|
... | ... | |
472 |
492 |
self.noteNoSingleClicked.emit(itemData[0].text(), noteContentsList)
|
473 |
493 |
elif type(itemData) is QEngineeringUnknownItem:
|
474 |
494 |
HighlightCommand(self.imageViewer).execute(itemData)
|
475 |
|
'''
|
476 |
|
rect = itemData.sceneBoundingRect()
|
477 |
|
self.imageViewer.centerOn(rect.center())
|
478 |
|
self.imageViewer.zoomImage(True, QMouseEvent(QEvent.MouseButtonPress, self.imageViewer.mapFromScene(QPointF(rect.left(), rect.top())), Qt.LeftButton, Qt.LeftButton, Qt.NoModifier), 3)
|
479 |
|
'''
|
480 |
495 |
elif type(itemData) is Drawing:
|
481 |
496 |
self.drawingClicked.emit(itemData)
|
482 |
497 |
|