hytos / DTI_PID / DTI_PID / ItemPropertyTableWidget.py @ 1447ed3e
이력 | 보기 | 이력해설 | 다운로드 (51.4 KB)
1 |
# coding: utf-8
|
---|---|
2 |
""" This is ItemPropertyTableWidget module """
|
3 |
|
4 |
try:
|
5 |
from PyQt5.QtCore import * |
6 |
from PyQt5.QtGui import * |
7 |
from PyQt5.QtWidgets import * |
8 |
except ImportError: |
9 |
try:
|
10 |
from PyQt4.QtCore import * |
11 |
from PyQt4.QtGui import * |
12 |
except ImportError: |
13 |
raise ImportError("ImageViewerQt: Requires PyQt5 or PyQt4.") |
14 |
|
15 |
import os |
16 |
import sys |
17 |
import math |
18 |
import re |
19 |
from functools import partial |
20 |
import SelectAttributeCommand, SelectAttributeBatchCommand |
21 |
|
22 |
from EngineeringAbstractItem import QEngineeringAbstractItem |
23 |
from SymbolSvgItem import SymbolSvgItem |
24 |
from EngineeringLineNoTextItem import QEngineeringLineNoTextItem |
25 |
from QEngineeringTrimLineNoTextItem import QEngineeringTrimLineNoTextItem |
26 |
from QEngineeringTagNoTextItem import QEngineeringTagNoTextItem |
27 |
from EngineeringLineItem import QEngineeringLineItem |
28 |
from EngineeringNoteItem import QEngineeringNoteItem |
29 |
from EngineeringTextItem import QEngineeringTextItem |
30 |
from UserInputAttribute import UserInputAttribute |
31 |
from EngineeringSpecBreakItem import QEngineeringSpecBreakItem |
32 |
from EngineeringErrorItem import QEngineeringErrorItem |
33 |
from EngineeringVendorItem import QEngineeringVendorItem |
34 |
from SymbolAttr import SymbolAttr |
35 |
from AppDocData import * |
36 |
from Drawing import Drawing |
37 |
from enum import Enum |
38 |
|
39 |
'''
|
40 |
@brief ItemType
|
41 |
@author Jeongwoo
|
42 |
@date 2018.04.27
|
43 |
@history 2018.05.10 Jeongwoo Add LINE_NO
|
44 |
'''
|
45 |
|
46 |
|
47 |
class ItemType(Enum): |
48 |
SYMBOL = 1
|
49 |
NOTE = 2
|
50 |
LINE_NO = 3
|
51 |
|
52 |
|
53 |
class QCustomCheckBox(QCheckBox): |
54 |
def __init__(self, table, row, col): |
55 |
QCheckBox.__init__(self)
|
56 |
self.table = table
|
57 |
self.row = row
|
58 |
self.col = col
|
59 |
|
60 |
def state_changed(self, state): |
61 |
""" check box state is changed """
|
62 |
if self.col == 0: |
63 |
'''
|
64 |
for index in range(self.table.rowCount()):
|
65 |
data = self.table.item(index, 1).data(Qt.UserRole) if self.table.item(index, 1) is not None else None
|
66 |
if data and type(data) is SymbolAttr:
|
67 |
widget = self.table.cellWidget(index, 3)
|
68 |
if widget:
|
69 |
widget.setEnabled(False) if state else widget.setEnabled(True)
|
70 |
data.Freeze = self.isChecked()
|
71 |
|
72 |
item = self.table.item(index, 3)
|
73 |
if item:
|
74 |
item.setFlags(Qt.ItemIsEnabled) if state else item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsEditable|Qt.ItemIsSelectable)
|
75 |
item.setBackground(Qt.lightGray) if state else item.setBackground(Qt.white)
|
76 |
'''
|
77 |
|
78 |
widget = self.table.cellWidget(self.row, 3) |
79 |
if widget:
|
80 |
widget.setEnabled(False) if state else widget.setEnabled(True) |
81 |
|
82 |
data = self.table.item(self.row, 1).data(Qt.UserRole) |
83 |
if data: data.Freeze = self.isChecked() |
84 |
|
85 |
item = self.table.item(self.row, 3) |
86 |
if item:
|
87 |
item.setFlags(Qt.ItemIsEnabled) if state else item.setFlags( |
88 |
Qt.ItemIsEnabled | Qt.ItemIsEditable | Qt.ItemIsSelectable) |
89 |
# item.setBackground(Qt.lightGray) if state else item.setBackground(Qt.white)
|
90 |
elif self.col == 3: |
91 |
cell = self.table.item(self.row, 1) |
92 |
if cell:
|
93 |
data = cell.data(Qt.UserRole) |
94 |
if data is not None: |
95 |
if self.table._item: self.table._item.set_property(data.Attribute, self.isChecked()) |
96 |
|
97 |
|
98 |
class QItemPropertyTableWidget(QTableWidget): |
99 |
def __init__(self, mainWindow): |
100 |
QTableWidget.__init__(self)
|
101 |
self._item = None |
102 |
self.initResultPropertyTableWidget()
|
103 |
self.mainWindow = mainWindow
|
104 |
|
105 |
self.cellChanged.connect(self.cellChangedEvent) |
106 |
self.cellDoubleClicked.connect(self.cellDoubleClickedEvent) |
107 |
|
108 |
'''
|
109 |
@brief show item's property
|
110 |
@author humkyung
|
111 |
@date 2018.07.03
|
112 |
@history euisung 2019.01.15 add icon image to line item
|
113 |
'''
|
114 |
|
115 |
def show_item_property(self, item): |
116 |
try:
|
117 |
from PyQt5 import QtGui |
118 |
from SymbolAttr import SymbolAttr |
119 |
from EngineeringRunItem import QEngineeringRunItem |
120 |
|
121 |
self._item = item
|
122 |
|
123 |
self.blockSignals(True) |
124 |
|
125 |
if type(item) is QEngineeringLineItem: |
126 |
self.initTitleCell(item)
|
127 |
self.initContentsCell()
|
128 |
elif issubclass(type(item), SymbolSvgItem): |
129 |
self.onSymbolClicked(item)
|
130 |
elif type(item) is QEngineeringLineNoTextItem or type(item) is QEngineeringRunItem: |
131 |
self.onLineNoClicked(item)
|
132 |
elif type(item) is QEngineeringTagNoTextItem: |
133 |
self.onTagNoClicked(item)
|
134 |
elif type(item) is QEngineeringNoteItem: |
135 |
noteContentsList = item.findNoteContents(item.text()) |
136 |
self.onNoteClicked(item.text(), noteContentsList)
|
137 |
elif issubclass(type(item), QEngineeringTextItem): |
138 |
self.onTextClicked(item)
|
139 |
elif type(item) is QEngineeringVendorItem: |
140 |
self.onVendorClicked(item)
|
141 |
elif item is None: |
142 |
self.setRowCount(0) |
143 |
except Exception as ex: |
144 |
from App import App |
145 |
|
146 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
147 |
sys.exc_info()[-1].tb_lineno)
|
148 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
149 |
finally:
|
150 |
self.blockSignals(False) |
151 |
|
152 |
'''
|
153 |
@brief Initialize TableWidget
|
154 |
@author Jeongwoo
|
155 |
@date 18.04.13
|
156 |
@history humkyung 2018.07.08 show column header
|
157 |
'''
|
158 |
|
159 |
def initResultPropertyTableWidget(self): |
160 |
self.setColumnCount(4) |
161 |
self.setHorizontalHeaderLabels(['', self.tr('Name'), '', self.tr('Value')]) |
162 |
self.setColumnWidth(0, 10) |
163 |
self.setColumnWidth(1, 20) |
164 |
self.setColumnWidth(2, 10) |
165 |
self.setRowCount(13) |
166 |
self.verticalHeader().hide()
|
167 |
self.horizontalHeader().setStretchLastSection(True) |
168 |
|
169 |
'''
|
170 |
@brief Slot to accept item click event
|
171 |
@author Jeongwoo
|
172 |
@date 18.04.13
|
173 |
@history humkyung 2018.04.17 check if given symbol type is SymbolSvgItem
|
174 |
'''
|
175 |
|
176 |
@pyqtSlot(SymbolSvgItem)
|
177 |
def onSymbolClicked(self, symbol): |
178 |
try:
|
179 |
self.blockSignals(True) |
180 |
if issubclass(type(symbol), SymbolSvgItem): |
181 |
self._item = symbol
|
182 |
self.symbolChanged(symbol)
|
183 |
elif type(symbol) is QEngineeringLineNoTextItem: |
184 |
self.lineNoChanged(symbol)
|
185 |
finally:
|
186 |
self.blockSignals(False) |
187 |
|
188 |
'''
|
189 |
@brief show drawing' attributes
|
190 |
@author humkyung
|
191 |
@date 2018.07.07
|
192 |
'''
|
193 |
|
194 |
@pyqtSlot(Drawing)
|
195 |
def onDrawingClicked(self, drawing): |
196 |
try:
|
197 |
self.blockSignals(True) |
198 |
self.setRowCount(len(drawing.attrs)) |
199 |
|
200 |
row = 0
|
201 |
for attr in drawing.attrs: |
202 |
name = attr[0]
|
203 |
item = QTableWidgetItem(name) |
204 |
item.setFlags(Qt.ItemIsEnabled) |
205 |
# item.setBackground(Qt.lightGray)
|
206 |
self.setItem(row, 0, item) |
207 |
|
208 |
value = attr[1]
|
209 |
item = QTableWidgetItem(value) |
210 |
item.setFlags(Qt.ItemIsEnabled) |
211 |
self.setItem(row, 1, item) |
212 |
|
213 |
row = row + 1
|
214 |
finally:
|
215 |
self.blockSignals(False) |
216 |
|
217 |
def onVendorClicked(self, item): |
218 |
from SymbolAttr import SymbolAttr |
219 |
|
220 |
try:
|
221 |
self.blockSignals(True) |
222 |
self.initTitleCell(item)
|
223 |
|
224 |
self.setItem(0, 3, QTableWidgetItem(str(self._item.uid))) |
225 |
|
226 |
self.show_item_properties(item)
|
227 |
self.show_item_attributes(item)
|
228 |
finally:
|
229 |
self.blockSignals(False) |
230 |
|
231 |
def onTextClicked(self, item): |
232 |
from SymbolAttr import SymbolAttr |
233 |
|
234 |
try:
|
235 |
self.blockSignals(True) |
236 |
self.textChanged(item)
|
237 |
finally:
|
238 |
self.blockSignals(False) |
239 |
|
240 |
def textChanged(self, item): |
241 |
self.initTitleCell(item)
|
242 |
|
243 |
self.setItem(0, 3, QTableWidgetItem(str(self._item.uid))) |
244 |
|
245 |
owner_item = QTableWidgetItem('{}'.format('None' if self._item.owner is None else str(self._item.owner))) |
246 |
owner_item.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable) |
247 |
self.setItem(1, 3, owner_item) |
248 |
|
249 |
""" show icon item """
|
250 |
attr = SymbolAttr() |
251 |
attr.AttributeType = "OWNER"
|
252 |
self.show_icon_item(1, 2, attr) |
253 |
self.item(1, 1).setData(Qt.UserRole, attr) |
254 |
|
255 |
self.setItem(2, 3, QTableWidgetItem(self._item.type)) |
256 |
self.setItem(3, 3, QTableWidgetItem(self._item.text())) |
257 |
self.setItem(4, 3, QTableWidgetItem(self._item.area)) |
258 |
|
259 |
'''
|
260 |
@brief Slot to accept Note item click event
|
261 |
@author Jeongwoo
|
262 |
@date 18.04.27
|
263 |
@history humkyung 2018.07.08 change method name to onNoteClicked
|
264 |
'''
|
265 |
|
266 |
@pyqtSlot(str, dict) |
267 |
def onNoteClicked(self, noteNoStr, noteContentsList): |
268 |
try:
|
269 |
self.blockSignals(True) |
270 |
self.noteChanged(noteNoStr, noteContentsList)
|
271 |
finally:
|
272 |
self.blockSignals(False) |
273 |
|
274 |
'''
|
275 |
@brief Slot to accept Line No Item Click event
|
276 |
@author Jeongwoo
|
277 |
@date 18.05.10
|
278 |
@hisotry humkyung 2018.07.08 change method name to onLineNoClicked
|
279 |
'''
|
280 |
@pyqtSlot(QEngineeringAbstractItem)
|
281 |
def onLineNoClicked(self, item): |
282 |
try:
|
283 |
self.blockSignals(True) |
284 |
self.lineNoChanged(item)
|
285 |
finally:
|
286 |
self.blockSignals(False) |
287 |
|
288 |
@pyqtSlot(QEngineeringAbstractItem)
|
289 |
def onTagNoClicked(self, item): |
290 |
try:
|
291 |
self.blockSignals(True) |
292 |
self.textChanged(item)
|
293 |
self.initTagNoCell(item)
|
294 |
|
295 |
""" show tooltip """
|
296 |
for index in range(self.rowCount()): |
297 |
item = self.item(index, 1) |
298 |
if item is not None: |
299 |
item.setToolTip(item.text()) |
300 |
finally:
|
301 |
self.blockSignals(False) |
302 |
|
303 |
def symbolChanged(self, item): |
304 |
"""fill symbol properties"""
|
305 |
self.initTitleCell(item)
|
306 |
self.initContentsCell()
|
307 |
|
308 |
'''
|
309 |
@brief Reset table with note info
|
310 |
@author Jeongwoo
|
311 |
@date 18.04.27
|
312 |
'''
|
313 |
|
314 |
def noteChanged(self, noteNoStr, noteContentsList): |
315 |
self.initNoteCell(noteNoStr, noteContentsList)
|
316 |
|
317 |
'''
|
318 |
@brief Reset table with line no item
|
319 |
@author Jeongwoo
|
320 |
@date 18.05.10
|
321 |
'''
|
322 |
|
323 |
def lineNoChanged(self, item): |
324 |
from EngineeringRunItem import QEngineeringRunItem |
325 |
|
326 |
if type(item) is QEngineeringLineNoTextItem: |
327 |
self.initTitleCell(item)
|
328 |
self.initLineNoCell(item)
|
329 |
elif type(item) is QEngineeringRunItem: |
330 |
self.initLineRunCell(item)
|
331 |
|
332 |
""" show tooltip """
|
333 |
for index in range(self.rowCount()): |
334 |
item = self.item(index, 1) |
335 |
if item is not None: |
336 |
item.setToolTip(item.text()) |
337 |
|
338 |
'''
|
339 |
@brief Initialize Title Cell
|
340 |
@author Jeongwoos
|
341 |
@date 18.04.13
|
342 |
@history Jeongwoo 2018.04.27 Add if-statement by ItemType
|
343 |
Jeongwoo 2018.05.10 Add if-statement LINE_NO ItemType
|
344 |
humkyung 2018.08.15 add combobox for line type
|
345 |
'''
|
346 |
|
347 |
def initTitleCell(self, item): |
348 |
from LineTypeConditions import LineTypeConditions |
349 |
|
350 |
try:
|
351 |
self.clear()
|
352 |
self.setHorizontalHeaderLabels(['', self.tr('Name'), '', self.tr('Value')]) |
353 |
self.setColumnWidth(0, 20) |
354 |
self.setColumnWidth(1, 80) |
355 |
self.setColumnWidth(2, 20) |
356 |
if type(item) is QEngineeringSpecBreakItem: |
357 |
self.setRowCount(7) |
358 |
self.setItem(0, 1, QTableWidgetItem(self.tr("UID"))) |
359 |
self.setItem(1, 1, QTableWidgetItem(self.tr("Name"))) |
360 |
self.setItem(2, 1, QTableWidgetItem(self.tr("Type"))) |
361 |
self.setItem(3, 1, QTableWidgetItem(self.tr("Angle"))) |
362 |
self.setItem(4, 1, QTableWidgetItem(self.tr("Origin"))) |
363 |
self.setItem(5, 1, QTableWidgetItem(self.tr("Set Batch"))) |
364 |
self.setItem(6, 1, QTableWidgetItem(self.tr("Set Specs"))) |
365 |
elif type(item) is QEngineeringErrorItem: |
366 |
self.setRowCount(7) |
367 |
self.setItem(0, 1, QTableWidgetItem(self.tr("UID"))) |
368 |
self.setItem(1, 1, QTableWidgetItem(self.tr("Name"))) |
369 |
self.setItem(2, 1, QTableWidgetItem(self.tr("Type"))) |
370 |
self.setItem(3, 1, QTableWidgetItem(self.tr("Angle"))) |
371 |
self.setItem(4, 1, QTableWidgetItem(self.tr("Origin"))) |
372 |
self.setItem(5, 1, QTableWidgetItem(self.tr("OWNER"))) |
373 |
self.setItem(6, 1, QTableWidgetItem(self.tr("Message"))) |
374 |
elif issubclass(type(item), SymbolSvgItem): |
375 |
self.setRowCount(6) |
376 |
self.setItem(0, 1, QTableWidgetItem(self.tr("UID"))) |
377 |
self.setItem(1, 1, QTableWidgetItem(self.tr("Name"))) |
378 |
self.setItem(2, 1, QTableWidgetItem(self.tr("Type"))) |
379 |
self.setItem(3, 1, QTableWidgetItem(self.tr("Angle"))) |
380 |
self.setItem(4, 1, QTableWidgetItem(self.tr("Origin"))) |
381 |
self.setItem(5, 1, QTableWidgetItem(self.tr("OWNER"))) |
382 |
elif type(item) is QEngineeringNoteItem: |
383 |
self.setRowCount(2) |
384 |
self.setItem(0, 1, QTableWidgetItem(self.tr("Note No"))) |
385 |
self.setItem(1, 1, QTableWidgetItem(self.tr("Desc."))) |
386 |
elif type(item) is QEngineeringLineNoTextItem: |
387 |
#configs = AppDocData.instance().getConfigs('Project', 'Operation')
|
388 |
_desc = AppDocData.instance().getCurrentProject().desc.split('!-!')
|
389 |
if len(_desc) == 2 and _desc[0] == 'Instrument': |
390 |
self.setRowCount(2) |
391 |
self.setItem(1, 1, QTableWidgetItem(self.tr("Set Batch"))) |
392 |
else:
|
393 |
self.setRowCount(1) |
394 |
self.setItem(0, 1, QTableWidgetItem(self.tr("UID"))) |
395 |
elif type(item) is QEngineeringLineItem: |
396 |
self.setRowCount(5) |
397 |
self.setItem(0, 1, QTableWidgetItem(self.tr('UID'))) |
398 |
self.setItem(1, 1, QTableWidgetItem(self.tr('OWNER'))) |
399 |
widgetItem = QTableWidgetItem(self.tr("Type")) |
400 |
widgetItem.setData(Qt.UserRole, item) |
401 |
self.setItem(2, 1, widgetItem) |
402 |
line_type_combo = QComboBox(self)
|
403 |
line_type_combo.tag = widgetItem |
404 |
for lineType in LineTypeConditions.items(): |
405 |
line_type_combo.addItem(lineType.name) |
406 |
self.setCellWidget(2, 3, line_type_combo) |
407 |
line_type_combo.setCurrentText(item.lineType) |
408 |
line_type_combo.currentIndexChanged.connect(partial(self.on_line_type_changed, item, line_type_combo))
|
409 |
elif type(item) is QEngineeringVendorItem: |
410 |
self.setRowCount(1) |
411 |
self.setItem(0, 1, QTableWidgetItem(self.tr("UID"))) |
412 |
else:
|
413 |
from Area import Area |
414 |
app_doc_data = AppDocData.instance() |
415 |
area_list = app_doc_data.getAreaList() |
416 |
title_area_list = app_doc_data.getTitleBlockProperties() |
417 |
self.setRowCount(5) |
418 |
self.setItem(0, 1, QTableWidgetItem(self.tr("UID"))) |
419 |
self.setItem(1, 1, QTableWidgetItem(self.tr("OWNER"))) |
420 |
self.setItem(2, 1, QTableWidgetItem(self.tr("Type"))) |
421 |
self.setItem(3, 1, QTableWidgetItem(self.tr("Text"))) |
422 |
widgetItem = QTableWidgetItem(self.tr("Area")) |
423 |
widgetItem.setData(Qt.UserRole, item) |
424 |
self.setItem(4, 1, widgetItem) |
425 |
self._areaComboBox = QComboBox(self) |
426 |
self._areaComboBox.tag = widgetItem
|
427 |
self._areaComboBox.addItem('None') |
428 |
title_list = [] |
429 |
if title_area_list:
|
430 |
for title_area in title_area_list: |
431 |
area = Area(title_area[1], title_area[0]) |
432 |
title_list.append(area) |
433 |
for area in area_list + title_list: |
434 |
self._areaComboBox.addItem(area.name)
|
435 |
self.setCellWidget(4, 3, self._areaComboBox) |
436 |
name = [area.name for area in area_list + title_list if item.area == area.uid] |
437 |
self._areaComboBox.setCurrentText(name[0] if name else 'None') |
438 |
self._areaComboBox.currentIndexChanged.connect(self.onAreaChanged) |
439 |
|
440 |
for index in range(self.rowCount()): |
441 |
item = self.item(index, 1) |
442 |
if item is not None: |
443 |
item.setFlags(Qt.ItemIsEnabled) |
444 |
# item.setBackground(Qt.lightGray)
|
445 |
except Exception as ex: |
446 |
from App import App |
447 |
|
448 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
449 |
sys.exc_info()[-1].tb_lineno)
|
450 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
451 |
|
452 |
def on_line_type_changed(self, item, combo_box, index): |
453 |
"""change connected lines' type by selected line type"""
|
454 |
line_type = combo_box.itemText(index) |
455 |
if type(item) is QEngineeringLineItem: |
456 |
self.change_connected_line_type(item, line_type)
|
457 |
|
458 |
def onAreaChanged(self, param): |
459 |
from Area import Area |
460 |
app_doc_data = AppDocData.instance() |
461 |
area_list = app_doc_data.getAreaList() |
462 |
title_area_list = app_doc_data.getTitleBlockProperties() |
463 |
title_list = [] |
464 |
for title_area in title_area_list: |
465 |
area = Area(title_area[1], title_area[0]) |
466 |
title_list.append(area) |
467 |
|
468 |
name = self._areaComboBox.itemText(param)
|
469 |
name = [area.uid for area in area_list + title_list if name == area.name] |
470 |
data = self._areaComboBox.tag.data(Qt.UserRole)
|
471 |
if type(data) is QEngineeringTextItem: |
472 |
data.area = name[0] if name else 'None' |
473 |
|
474 |
def change_connected_line_type(self, line, line_type): |
475 |
"""change line type recursively"""
|
476 |
pool, visited = [line], [] |
477 |
while pool:
|
478 |
_item = pool.pop() |
479 |
visited.append(_item) |
480 |
_item.lineType = line_type |
481 |
|
482 |
if type(_item.connectors[0].connectedItem) is QEngineeringLineItem and \ |
483 |
_item.connectors[0].connectedItem.is_connected(_item) and \ |
484 |
_item.connectors[0].connectedItem not in visited: |
485 |
pool.append(_item.connectors[0].connectedItem)
|
486 |
if type(_item.connectors[1].connectedItem) is QEngineeringLineItem and \ |
487 |
_item.connectors[1].connectedItem.is_connected(_item) and \ |
488 |
_item.connectors[1].connectedItem not in visited: |
489 |
pool.append(_item.connectors[1].connectedItem)
|
490 |
"""up to here"""
|
491 |
|
492 |
def show_icon_item(self, row, col, prop): |
493 |
""" show icon item on grid """
|
494 |
from PyQt5 import QtGui |
495 |
|
496 |
if prop.is_selectable or prop.AttributeType == 'OWNER' or prop.AttributeType == 'CONN': |
497 |
icon = QtGui.QIcon() |
498 |
icon.addPixmap(QtGui.QPixmap(":/newPrefix/doubleclick.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
499 |
icon_item = QTableWidgetItem('')
|
500 |
icon_item.setFlags(Qt.ItemIsEnabled) |
501 |
icon_item.setIcon(icon) |
502 |
self.setItem(row, col, icon_item)
|
503 |
elif prop.AttributeType == "String": |
504 |
icon = QtGui.QIcon() |
505 |
icon.addPixmap(QtGui.QPixmap(":/newPrefix/type.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
506 |
icon_item = QTableWidgetItem() |
507 |
icon_item.setIcon(icon) |
508 |
self.setItem(row, col, icon_item)
|
509 |
else:
|
510 |
item = QTableWidgetItem() |
511 |
item.setFlags(Qt.ItemIsEditable) |
512 |
self.setItem(row, col, item)
|
513 |
|
514 |
def show_item_properties(self, item): |
515 |
""" show item properties on grid """
|
516 |
from PyQt5 import QtGui |
517 |
|
518 |
row = self.rowCount()
|
519 |
_row = row |
520 |
if hasattr(item, '_properties'): |
521 |
self.setRowCount(row + len(item.properties)) |
522 |
|
523 |
for prop, value in item.properties.items(): |
524 |
if prop.Attribute == 'Config': |
525 |
self.setRowCount(_row + len(item.properties) - 1) |
526 |
continue
|
527 |
try:
|
528 |
""" show freeze state """
|
529 |
checkbox = QCustomCheckBox(self, row, 0) |
530 |
checkbox.setChecked(prop.Freeze) |
531 |
checkbox.stateChanged.connect(checkbox.state_changed) |
532 |
self.setCellWidget(row, 0, checkbox) |
533 |
|
534 |
""" show property name """
|
535 |
key_item = QTableWidgetItem(prop.DisplayAttribute if prop.DisplayAttribute else prop.Attribute) |
536 |
key_item.setFlags(Qt.ItemIsEnabled) |
537 |
# key_item.setBackground(Qt.lightGray)
|
538 |
key_item.setData(Qt.UserRole, prop) |
539 |
self.setItem(row, 1, key_item) |
540 |
|
541 |
""" show icon item """
|
542 |
self.show_icon_item(row, 2, prop) |
543 |
|
544 |
""" show property value """
|
545 |
if prop.is_selectable:
|
546 |
value_item = QTableWidgetItem(str(value.uid) if hasattr(value, 'uid') else value) |
547 |
value_item.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable) |
548 |
self.setItem(row, 3, value_item) |
549 |
else:
|
550 |
if prop.AttributeType == 'Boolean': |
551 |
self.checkbox_cell = QCustomCheckBox(self, row, 3) |
552 |
self.checkbox_cell.setChecked(True if value and str(value) == 'True' else False) |
553 |
self.checkbox_cell.stateChanged.connect(self.checkbox_cell.state_changed) |
554 |
# if prop.Attribute == 'Freeze': self.checkbox_cell.stateChanged.connect(item.freeze_item.update_freeze)
|
555 |
self.setCellWidget(row, 3, self.checkbox_cell) |
556 |
else:
|
557 |
value_item = QTableWidgetItem(value if value else '') |
558 |
value_item.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable | Qt.ItemIsEditable) |
559 |
self.setItem(row, 3, value_item) |
560 |
|
561 |
checkbox.state_changed(checkbox.isChecked()) |
562 |
|
563 |
row = row + 1
|
564 |
except Exception as ex: |
565 |
from App import App |
566 |
|
567 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
568 |
sys.exc_info()[-1].tb_lineno)
|
569 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
570 |
|
571 |
def show_item_attributes(self, item): |
572 |
""" show item's attributes on grid """
|
573 |
from PyQt5 import QtGui |
574 |
from functools import partial |
575 |
|
576 |
row = self.rowCount()
|
577 |
attrs = item.getAttributes() |
578 |
|
579 |
# display attributes of symbol
|
580 |
if attrs is not None: |
581 |
self.setRowCount(row + len(attrs)) |
582 |
|
583 |
for key, value in sorted(attrs.items(), key=lambda param:int(param[0].Index)): |
584 |
try:
|
585 |
""" show freeze state """
|
586 |
checkbox = QCustomCheckBox(self, row, 0) |
587 |
checkbox.setChecked(key.Freeze) |
588 |
checkbox.stateChanged.connect(checkbox.state_changed) |
589 |
self.setCellWidget(row, 0, checkbox) |
590 |
|
591 |
""" show attribute name """
|
592 |
key_item = QTableWidgetItem(key.DisplayAttribute if key.DisplayAttribute else key.Attribute) |
593 |
# key_item.setBackground(Qt.lightGray)
|
594 |
key_item.setData(Qt.UserRole, key) |
595 |
self.setItem(row, 1, key_item) |
596 |
key_item.setFlags(Qt.ItemIsEnabled) |
597 |
|
598 |
""" show icon item """
|
599 |
self.show_icon_item(row, 2, key) |
600 |
|
601 |
value_item = QTableWidgetItem(str(value))
|
602 |
value_item.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable | Qt.ItemIsEditable) |
603 |
|
604 |
if type(item) is QEngineeringSpecBreakItem: |
605 |
if key.Attribute == 'UpStream' or key.Attribute == 'DownStream': |
606 |
UpDownItem = QTableWidgetItem('{}'.format('None' if value is None else value)) |
607 |
self.setItem(row, 3, UpDownItem) |
608 |
else: # elif key.AttributeType == 'Spec': |
609 |
self.setItem(row, 3, QTableWidgetItem(str(value)[1:-1])) |
610 |
else:
|
611 |
self.setItem(row, 3, value_item) |
612 |
'''
|
613 |
if key.Attribute.upper() == 'STREAM NO':
|
614 |
stream_no_combo = QComboBox()
|
615 |
stream_no_combo.tag = key
|
616 |
|
617 |
app_doc_data = AppDocData.instance()
|
618 |
stream_nos = sorted(list(app_doc_data.hmbTable.streamNos()))
|
619 |
for streamNo in stream_nos:
|
620 |
stream_no_combo.addItem(streamNo)
|
621 |
self.setCellWidget(row, 3, stream_no_combo)
|
622 |
stream_no_combo.setCurrentText(value)
|
623 |
|
624 |
stream_no_combo.currentIndexChanged.connect(
|
625 |
partial(self.on_stream_no_changed, item, stream_no_combo))
|
626 |
'''
|
627 |
|
628 |
checkbox.state_changed(checkbox.isChecked()) |
629 |
|
630 |
row = row + 1
|
631 |
except Exception as ex: |
632 |
from App import App |
633 |
|
634 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
635 |
sys.exc_info()[-1].tb_lineno)
|
636 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
637 |
|
638 |
def show_item_connectors(self, item): |
639 |
""" show items' connectors on grid """
|
640 |
from PyQt5 import QtGui |
641 |
from SymbolAttr import SymbolAttr |
642 |
|
643 |
row = self.rowCount()
|
644 |
self.setRowCount(row + len(item.connectors)) |
645 |
|
646 |
count = 1
|
647 |
for connector in item.connectors: |
648 |
connector_item = QTableWidgetItem('CONN{}'.format(count))
|
649 |
connector_item.setFlags(Qt.ItemIsEnabled) |
650 |
# connector_item.setBackground(Qt.lightGray)
|
651 |
self.setItem(row, 1, connector_item) |
652 |
|
653 |
attr = SymbolAttr() |
654 |
attr.AttributeType = "CONN"
|
655 |
attr.AttrAt = count |
656 |
connector_item.setData(Qt.UserRole, attr) |
657 |
|
658 |
""" show icon item """
|
659 |
self.show_icon_item(row, 2, attr) |
660 |
|
661 |
connector_item = QTableWidgetItem( |
662 |
'{}'.format('None' if connector.connectedItem is None else str(connector.connectedItem))) |
663 |
connector_item.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable) |
664 |
self.setItem(row, 3, connector_item) |
665 |
|
666 |
row = row + 1
|
667 |
count = count + 1
|
668 |
|
669 |
'''
|
670 |
@brief Initialize Contents Cell
|
671 |
@author Jeongwoo
|
672 |
@date 18.04.13
|
673 |
@history humkyung 2018.06.14 display symbol attributes
|
674 |
humkyung 2018.07.05 display connectivity
|
675 |
euisung 2019.01.15 edit specbreak
|
676 |
'''
|
677 |
|
678 |
def initContentsCell(self): |
679 |
from PyQt5 import QtGui |
680 |
from SymbolAttr import SymbolAttr |
681 |
|
682 |
try:
|
683 |
if self._item is not None and issubclass(type(self._item), SymbolSvgItem): |
684 |
self.setItem(0, 3, QTableWidgetItem(str(self._item.uid))) |
685 |
self.setItem(1, 3, QTableWidgetItem(self._item.name)) |
686 |
self.setItem(2, 3, QTableWidgetItem(self._item.type)) |
687 |
self.setItem(3, 3, QTableWidgetItem(str(round(self._item.rotation())))) |
688 |
self.setItem(4, 3, QTableWidgetItem(str(self._item.origin))) |
689 |
owner_item = QTableWidgetItem( |
690 |
'{}'.format('None' if self._item.owner is None else str(self._item.owner))) |
691 |
self.setItem(5, 3, owner_item) |
692 |
|
693 |
for index in range(self.rowCount()): |
694 |
item = self.item(index, 3) |
695 |
if item is not None: |
696 |
item.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable) |
697 |
|
698 |
""" show icon item """
|
699 |
attr = SymbolAttr() |
700 |
attr.AttributeType = "OWNER"
|
701 |
self.show_icon_item(5, 2, attr) |
702 |
self.item(5, 1).setData(Qt.UserRole, attr) |
703 |
|
704 |
if type(self._item) is not QEngineeringSpecBreakItem and type(self._item) is not QEngineeringErrorItem: |
705 |
self.show_item_properties(self._item) |
706 |
|
707 |
if type(self._item) is QEngineeringSpecBreakItem: |
708 |
row = self.rowCount()
|
709 |
setSpecsItem = QTableWidgetItem('')
|
710 |
icon = QtGui.QIcon() |
711 |
icon.addPixmap(QtGui.QPixmap(":/newPrefix/doubleclick.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
712 |
setSpecsItem.setIcon(icon) |
713 |
self.setItem(row - 1, 2, setSpecsItem) |
714 |
self.setItem(row - 1, 3, QTableWidgetItem('Open')) |
715 |
|
716 |
if type(self._item) is QEngineeringErrorItem: |
717 |
errType = 'None'
|
718 |
if type(self._item.parent) is QEngineeringLineItem: |
719 |
errType = 'line'
|
720 |
elif issubclass(type(self._item.parent), SymbolSvgItem): |
721 |
errType = 'symbol'
|
722 |
self.setItem(2, 3, QTableWidgetItem(errType)) |
723 |
self.setItem(5, 3, QTableWidgetItem(str(self._item.parent.uid))) |
724 |
self.setItem(6, 3, QTableWidgetItem(self._item.msg)) |
725 |
|
726 |
self.show_item_attributes(self._item) |
727 |
self.show_item_connectors(self._item) |
728 |
|
729 |
if type(self._item) is QEngineeringSpecBreakItem: |
730 |
self.show_item_properties(self._item) |
731 |
|
732 |
for index in range(self.rowCount()): |
733 |
item = self.item(index, 3) |
734 |
if item is not None: item.setToolTip(item.text()) |
735 |
elif self._item is not None and type(self._item) is QEngineeringLineItem: |
736 |
self.setItem(0, 3, QTableWidgetItem(str(self._item.uid))) |
737 |
|
738 |
""" show icon item """
|
739 |
attr = SymbolAttr() |
740 |
attr.AttributeType = "OWNER"
|
741 |
self.show_icon_item(1, 2, attr) |
742 |
self.item(1, 1).setData(Qt.UserRole, attr) |
743 |
|
744 |
owner_item = QTableWidgetItem(f"{'None' if self._item.owner is None else str(self._item.owner)}")
|
745 |
self.setItem(1, 3, owner_item) |
746 |
|
747 |
pt = self._item.start_point()
|
748 |
key_item = QTableWidgetItem(self.tr("Start")) |
749 |
key_item.setFlags(Qt.ItemIsEnabled) |
750 |
# key_item.setBackground(Qt.lightGray)
|
751 |
self.setItem(3, 1, key_item) |
752 |
self.setItem(3, 3, QTableWidgetItem('({},{})'.format(pt[0], pt[1]))) |
753 |
pt = self._item.end_point()
|
754 |
key_item = QTableWidgetItem(self.tr("End")) |
755 |
key_item.setFlags(Qt.ItemIsEnabled) |
756 |
# key_item.setBackground(Qt.lightGray)
|
757 |
self.setItem(4, 1, key_item) |
758 |
self.setItem(4, 3, QTableWidgetItem('({},{})'.format(pt[0], pt[1]))) |
759 |
|
760 |
self.show_item_attributes(self._item) |
761 |
self.show_item_connectors(self._item) |
762 |
self.show_item_properties(self._item) |
763 |
else:
|
764 |
self.setRowCount(0) |
765 |
|
766 |
except Exception as ex: |
767 |
from App import App |
768 |
|
769 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
770 |
sys.exc_info()[-1].tb_lineno)
|
771 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
772 |
|
773 |
'''
|
774 |
@brief combobox change event
|
775 |
@author kyouho
|
776 |
@date 2018.08.28
|
777 |
'''
|
778 |
|
779 |
def upStreamChanged(self, text): |
780 |
if self._item is not None: |
781 |
find = False
|
782 |
for index in range(len(self._item.attrs)): |
783 |
if type(self._item.attrs[index]) is tuple and self._item.attrs[index][0] == 'Up Stream': |
784 |
self._item.attrs[index] = (self._item.attrs[index][0], text) |
785 |
find = True
|
786 |
break
|
787 |
|
788 |
if not find: |
789 |
self._item.attrs.append(('Up Stream', text)) |
790 |
|
791 |
'''
|
792 |
@brief combobox change event
|
793 |
@author kyouho
|
794 |
@date 2018.08.28
|
795 |
'''
|
796 |
|
797 |
def downStreamChanged(self, text): |
798 |
if self._item is not None: |
799 |
find = False
|
800 |
for index in range(len(self._item.attrs)): |
801 |
if type(self._item.attrs[index]) is tuple and self._item.attrs[index][0] == 'Down Stream': |
802 |
self._item.attrs[index] = (self._item.attrs[index][0], text) |
803 |
find = True
|
804 |
break
|
805 |
|
806 |
if not find: |
807 |
self._item.attrs.append(('Down Stream', text)) |
808 |
|
809 |
'''
|
810 |
@brief Initialize Note Contents Cell
|
811 |
@author Jeongwoo
|
812 |
@date 18.04.27
|
813 |
'''
|
814 |
|
815 |
def initNoteCell(self, noteNoStr, noteContentsList): |
816 |
self.setRowCount(0) |
817 |
|
818 |
for key in noteContentsList: |
819 |
row = self.rowCount()
|
820 |
self.setRowCount(row + len(noteContentsList[key])) |
821 |
item = QTableWidgetItem(key) |
822 |
self.setItem(row, 1, item) |
823 |
|
824 |
for index in range(len(noteContentsList[key])): |
825 |
self.setItem(row, 3, QTableWidgetItem(noteContentsList[key][index])) |
826 |
row = row + 1
|
827 |
|
828 |
for index in range(self.rowCount()): |
829 |
item = self.item(index, 1) |
830 |
if item is not None: |
831 |
item.setFlags(Qt.ItemIsEnabled) |
832 |
# item.setBackground(Qt.lightGray)
|
833 |
|
834 |
'''
|
835 |
@brief Initialize Line No Contents Cell
|
836 |
@author Jeongwoo
|
837 |
@date 18.05.10
|
838 |
@history humkyung 2018.07.20 display combobox when key is 'Stream No'
|
839 |
'''
|
840 |
def initLineNoCell(self, lineNoItem): |
841 |
appDocData = AppDocData.instance() |
842 |
configs = appDocData.getConfigs('Line No', 'Configuration') |
843 |
configs = configs[0].value.split('"-"') |
844 |
|
845 |
item = QTableWidgetItem(str(lineNoItem.uid))
|
846 |
item.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable) |
847 |
self.setItem(0, 3, item) |
848 |
|
849 |
# for set batch
|
850 |
#configs = appDocData.getConfigs('Project', 'Operation')
|
851 |
_desc = appDocData.getCurrentProject().desc.split('!-!')
|
852 |
if len(_desc) == 2 and _desc[0] == 'Instrument': |
853 |
owner_item = QTableWidgetItem('None')
|
854 |
self.setItem(1, 3, owner_item) |
855 |
attr = SymbolAttr() |
856 |
attr.AttributeType = "OWNER"
|
857 |
self.show_icon_item(1, 2, attr) |
858 |
self.item(1, 1).setData(Qt.UserRole, attr) |
859 |
|
860 |
self.show_item_properties(lineNoItem)
|
861 |
|
862 |
row = self.rowCount()
|
863 |
attrs = lineNoItem.getAttributes() |
864 |
self.setRowCount(row + len(attrs)) |
865 |
if attrs is not None: |
866 |
for key in attrs.keys(): |
867 |
item = QTableWidgetItem(key.DisplayAttribute if key.DisplayAttribute else key.Attribute) |
868 |
item.setFlags(Qt.ItemIsEnabled) |
869 |
# item.setBackground(Qt.lightGray)
|
870 |
item.setData(Qt.UserRole, key) |
871 |
self.setItem(row, 1, item) |
872 |
|
873 |
""" show icon item """
|
874 |
self.show_icon_item(row, 2, key) |
875 |
|
876 |
""" show freeze state """
|
877 |
if key.IsProp != 5: |
878 |
checkbox = QCustomCheckBox(self, row, 0) |
879 |
checkbox.setChecked(key.Freeze) |
880 |
checkbox.stateChanged.connect(checkbox.state_changed) |
881 |
self.setCellWidget(row, 0, checkbox) |
882 |
|
883 |
# value cell
|
884 |
value = attrs[key] |
885 |
valueCell = QTableWidgetItem(value) |
886 |
|
887 |
# UID로 확인
|
888 |
keyStr = appDocData.getLinePropertiesByUID(key.UID) |
889 |
if keyStr:
|
890 |
# editable value cell
|
891 |
if keyStr[0].AttributeType == 'String': |
892 |
pass
|
893 |
# self.attrValueList.append((valueCell, key.Attribute))
|
894 |
# self.stringCell.append(valueCell)
|
895 |
if keyStr[0].UID in configs: valueCell.setFlags(Qt.ItemIsEnabled) |
896 |
else:
|
897 |
valueCell.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable) |
898 |
|
899 |
self.setItem(row, 3, valueCell) |
900 |
|
901 |
row = row + 1
|
902 |
|
903 |
def initTagNoCell(self, tagNoItem): |
904 |
appDocData = AppDocData.instance() |
905 |
configs = appDocData.getConfigs('Tag No', 'Configuration') |
906 |
configs = configs[0].value.split('"-"') |
907 |
|
908 |
row = self.rowCount()
|
909 |
attrs = tagNoItem.getAttributes() |
910 |
self.setRowCount(row + len(attrs)) |
911 |
if attrs is not None: |
912 |
for key in attrs.keys(): |
913 |
item = QTableWidgetItem(key.DisplayAttribute if key.DisplayAttribute else key.Attribute) |
914 |
item.setFlags(Qt.ItemIsEnabled) |
915 |
# item.setBackground(Qt.lightGray)
|
916 |
item.setData(Qt.UserRole, key) |
917 |
self.setItem(row, 1, item) |
918 |
|
919 |
""" show icon item """
|
920 |
self.show_icon_item(row, 2, key) |
921 |
|
922 |
""" show freeze state """
|
923 |
if key.IsProp != 5: |
924 |
checkbox = QCustomCheckBox(self, row, 0) |
925 |
checkbox.setChecked(key.Freeze) |
926 |
checkbox.stateChanged.connect(checkbox.state_changed) |
927 |
self.setCellWidget(row, 0, checkbox) |
928 |
|
929 |
# value cell
|
930 |
value = attrs[key] |
931 |
valueCell = QTableWidgetItem(value) |
932 |
|
933 |
# UID로 확인
|
934 |
keyStr = appDocData.getLinePropertiesByUID(key.UID) |
935 |
if keyStr:
|
936 |
# editable value cell
|
937 |
if keyStr[0].AttributeType == 'String': |
938 |
pass
|
939 |
# self.attrValueList.append((valueCell, key.Attribute))
|
940 |
# self.stringCell.append(valueCell)
|
941 |
if keyStr[0].UID in configs: valueCell.setFlags(Qt.ItemIsEnabled) |
942 |
else:
|
943 |
valueCell.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable) |
944 |
|
945 |
self.setItem(row, 3, valueCell) |
946 |
|
947 |
row = row + 1
|
948 |
|
949 |
'''
|
950 |
def on_stream_no_changed(self, item, combobox, index):
|
951 |
"""change connected lines' stream no by selected stream no"""
|
952 |
try:
|
953 |
stream_no = combobox.itemText(index)
|
954 |
item.stream_no = stream_no
|
955 |
|
956 |
"""change connected line's stream no"""
|
957 |
if type(item) is QEngineeringLineItem:
|
958 |
pool, visited = [item], []
|
959 |
while pool:
|
960 |
_item = pool.pop()
|
961 |
visited.append(_item)
|
962 |
_item.stream_no = stream_no
|
963 |
|
964 |
if type(_item.connectors[0].connectedItem) is QEngineeringLineItem and \
|
965 |
_item.connectors[0].connectedItem.is_connected(_item) and \
|
966 |
_item.connectors[0].connectedItem not in visited:
|
967 |
pool.append(_item.connectors[0].connectedItem)
|
968 |
if type(_item.connectors[1].connectedItem) is QEngineeringLineItem and \
|
969 |
_item.connectors[1].connectedItem.is_connected(_item) and \
|
970 |
_item.connectors[1].connectedItem not in visited:
|
971 |
pool.append(_item.connectors[1].connectedItem)
|
972 |
"""up to here"""
|
973 |
|
974 |
for row in range(self.rowCount()):
|
975 |
data = self.item(row, 1).data(Qt.UserRole)
|
976 |
if data and type(data) is SymbolAttr and data.AttributeType == 'HMB':
|
977 |
value = item.attrib(data.Attribute)
|
978 |
self.item(row, 3).setText(value)
|
979 |
except Exception as ex:
|
980 |
from App import App
|
981 |
from AppDocData import MessageType
|
982 |
|
983 |
message = f"error occurred({repr(ex)}) in {sys.exc_info()[-1].tb_frame.f_code.co_filename}:" \
|
984 |
f"{sys.exc_info()[-1].tb_lineno}"
|
985 |
App.mainWnd().addMessage.emit(MessageType.Error, message)
|
986 |
'''
|
987 |
|
988 |
'''
|
989 |
@brief Initialize Run Contents Cell
|
990 |
@author humkyung
|
991 |
@date 2018.05.27
|
992 |
'''
|
993 |
|
994 |
def initLineRunCell(self, item): |
995 |
self.setRowCount(1) |
996 |
|
997 |
lineTypeItem = QTableWidgetItem(self.tr("Line Type")) |
998 |
# lineTypeItem.setBackground(Qt.lightGray)
|
999 |
lineTypeItem.setFlags(Qt.ItemIsEnabled) |
1000 |
self.setItem(0, 1, lineTypeItem) |
1001 |
|
1002 |
'''
|
1003 |
@brief Key Press Event
|
1004 |
@author kyouho
|
1005 |
@date 2018.07.19
|
1006 |
'''
|
1007 |
|
1008 |
def keyPressEvent(self, event): |
1009 |
from SymbolAttr import SymbolAttr |
1010 |
|
1011 |
app_doc_data = AppDocData.instance() |
1012 |
|
1013 |
if event.key() == Qt.Key_Delete:
|
1014 |
items = self.mainWindow.graphicsView.scene().selectedItems()
|
1015 |
selectedIndexes = self.selectedIndexes()
|
1016 |
if selectedIndexes and selectedIndexes[0].column() == 3 and self.item(selectedIndexes[0].row(), |
1017 |
1).text() == 'OWNER': |
1018 |
item = items[0]
|
1019 |
item.owner = None
|
1020 |
|
1021 |
matches = [_item for _item in self.mainWindow.graphicsView.scene().items() if |
1022 |
type(_item) is QEngineeringLineNoTextItem] |
1023 |
matches.extend([lineNo for lineNo in app_doc_data.tracerLineNos if |
1024 |
type(lineNo) is QEngineeringTrimLineNoTextItem]) |
1025 |
for match in matches: |
1026 |
if item is match.prop('From'): |
1027 |
match.set_property('From', None) |
1028 |
if item is match.prop('To'): |
1029 |
match.set_property('To', None) |
1030 |
|
1031 |
for run_index in reversed(range(len(match.runs))): |
1032 |
run = match.runs[run_index] |
1033 |
if item in run.items: |
1034 |
index = run.items.index(item) |
1035 |
run.items.pop(index) |
1036 |
if not run.items: |
1037 |
run.explode() |
1038 |
if type(match) is QEngineeringTrimLineNoTextItem and not match.runs: |
1039 |
app_doc_data.tracerLineNos.pop(app_doc_data.tracerLineNos.index(match)) |
1040 |
|
1041 |
self.show_item_property(item)
|
1042 |
elif len(items) == 1 and len(selectedIndexes) == 1 and ( |
1043 |
type(items[0]) is QEngineeringLineItem or issubclass(type(items[0]), SymbolSvgItem) or \ |
1044 |
type(items[0]) is QEngineeringLineNoTextItem or type(items[0]) is QEngineeringVendorItem): |
1045 |
key_cell = self.item(selectedIndexes[0].row(), 1) |
1046 |
data = key_cell.data(Qt.UserRole) |
1047 |
if selectedIndexes[0].column() == 3 and key_cell.text().find('CONN') is 0: |
1048 |
selectedUID = self.item(selectedIndexes[0].row(), 1).text() |
1049 |
connNum = int(key_cell.text().replace('CONN', '')) |
1050 |
items[0].connectors[connNum - 1].connectedItem = None |
1051 |
self.show_item_property(items[0]) |
1052 |
|
1053 |
for sceneItem in self.mainWindow.graphicsView.scene().items(): |
1054 |
if hasattr(sceneItem, 'uid') and str(sceneItem.uid) == selectedUID and hasattr(sceneItem, |
1055 |
'connectors'):
|
1056 |
for sceneConnector in sceneItem.connectors: |
1057 |
if sceneConnector.connectedItem is not None and items[ |
1058 |
0].uid == sceneConnector.connectedItem.uid:
|
1059 |
sceneConnector.connectedItem = None
|
1060 |
elif selectedIndexes[0].column() == 3 and data and type(data) is SymbolAttr: |
1061 |
assocItem = None
|
1062 |
for _attr, _value in items[0].attrs.items(): |
1063 |
if str(_attr.UID) == str(data.UID): |
1064 |
assocItem = _attr.AssocItem |
1065 |
items[0].remove_assoc_item(_attr.AssocItem)
|
1066 |
if issubclass(type(_attr.AssocItem), QEngineeringTextItem): |
1067 |
_attr.AssocItem.owner = None
|
1068 |
_attr.AssocItem = None
|
1069 |
items[0].attrs[_attr] = '' |
1070 |
break
|
1071 |
for _attr, _value in items[0].attrs.items(): |
1072 |
if _attr.AssocItem is assocItem: |
1073 |
_attr.AssocItem = None
|
1074 |
items[0].attrs[_attr] = '' |
1075 |
self.show_item_property(items[0]) |
1076 |
elif len(items) == 1 and len(selectedIndexes) == 1 and type(items[0]) is QEngineeringSpecBreakItem: |
1077 |
keyCell = self.item(selectedIndexes[0].row(), 1) |
1078 |
if selectedIndexes[0].column() == 3 and ( |
1079 |
keyCell.text() == 'UpStream' or keyCell.text() == 'DownStream'): |
1080 |
for attr in items[0].attrs.keys(): |
1081 |
if attr.Attribute == keyCell.text():
|
1082 |
items[0].attrs[attr] = None |
1083 |
self.show_item_property(items[0]) |
1084 |
elif (event.key() == Qt.Key_C) and (event.modifiers() & Qt.ControlModifier): |
1085 |
self.copy_cells_to_clipboard()
|
1086 |
event.accept() |
1087 |
|
1088 |
super(QItemPropertyTableWidget, self).keyPressEvent(event) |
1089 |
|
1090 |
def copy_cells_to_clipboard(self): |
1091 |
""" copy selected text to clipboard """
|
1092 |
|
1093 |
selection = self.selectedIndexes()
|
1094 |
if selection:
|
1095 |
rows = sorted(index.row() for index in selection) |
1096 |
columns = sorted(index.column() for index in selection) |
1097 |
text = self.item(rows[-1], columns[-1]).text() |
1098 |
QApplication.clipboard().setText(text) |
1099 |
|
1100 |
'''
|
1101 |
@brief int cell check
|
1102 |
@author kyouho
|
1103 |
@date 2018.08.20
|
1104 |
'''
|
1105 |
|
1106 |
def cellChangedEvent(self, row, column): |
1107 |
from SymbolAttr import SymbolProp |
1108 |
from SymbolAttr import SymbolAttr |
1109 |
|
1110 |
try:
|
1111 |
if column == 3: |
1112 |
item = self.item(row, 1) |
1113 |
data = item.data(Qt.UserRole) if item is not None else None |
1114 |
if data is not None: |
1115 |
if self._item: |
1116 |
if type(data) is SymbolProp: |
1117 |
if data.AttributeType != 'Boolean': |
1118 |
self._item.set_property(data.Attribute, self.item(row, column).text()) |
1119 |
else:
|
1120 |
self._item.set_property(data.Attribute, self.cellWidget(row, column).isChecked()) |
1121 |
elif type(data) is SymbolAttr: |
1122 |
if data.AttributeType != 'Boolean': |
1123 |
self._item.set_attrib(data, self.item(row, column).text()) |
1124 |
else:
|
1125 |
self._item.set_attrib(data, self.cellWidget(row, column).isChecked()) |
1126 |
except Exception as ex: |
1127 |
from App import App |
1128 |
from AppDocData import MessageType |
1129 |
|
1130 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
1131 |
sys.exc_info()[-1].tb_lineno)
|
1132 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
1133 |
|
1134 |
'''
|
1135 |
@brief resultPropertyTableWidget Cell Double Click Event
|
1136 |
@author kyouho
|
1137 |
@date 2018.07.19
|
1138 |
@history euisung 2019.01.15 edit specbreak
|
1139 |
'''
|
1140 |
|
1141 |
def cellDoubleClickedEvent(self, row, column): |
1142 |
from SymbolAttr import SymbolProp |
1143 |
|
1144 |
if column == 2: |
1145 |
items = self.mainWindow.graphicsView.scene().selectedItems()
|
1146 |
keyCell = self.item(row, 1) |
1147 |
attr = keyCell.data(Qt.UserRole) |
1148 |
if hasattr(keyCell, 'tag') and type(items[0]) is not QEngineeringSpecBreakItem: |
1149 |
attr = keyCell.tag |
1150 |
if attr.is_selectable:
|
1151 |
cmd = SelectAttributeCommand.SelectAttributeCommand(items[0], attr, self.mainWindow.graphicsView) |
1152 |
cmd.onSuccess.connect(self.onSuccessSelectAttribute)
|
1153 |
self.mainWindow.graphicsView.command = cmd
|
1154 |
elif self.item(row, column).flags() != Qt.ItemIsEnabled: |
1155 |
self.editItem(self.item(row, column)) |
1156 |
elif keyCell.text() == 'CONN' and type(items[0]) is QEngineeringLineNoTextItem: |
1157 |
# unused code
|
1158 |
from SymbolAttr import SymbolAttr |
1159 |
attr = SymbolAttr() |
1160 |
attr.AttributeType = "Line Item"
|
1161 |
cmd = SelectAttributeCommand.SelectAttributeCommand(items[0], attr, self.mainWindow.graphicsView) |
1162 |
cmd.onSuccess.connect(self.onSuccessSelectAttribute)
|
1163 |
self.mainWindow.graphicsView.command = cmd
|
1164 |
elif keyCell.text() == 'OWNER' and ( |
1165 |
(type(items[0]) is QEngineeringLineItem) or (issubclass(type(items[0]), SymbolSvgItem)) or ( |
1166 |
issubclass(type(items[0]), QEngineeringTextItem))): |
1167 |
attr = keyCell.data(Qt.UserRole) |
1168 |
cmd = SelectAttributeCommand.SelectAttributeCommand(items[0], attr, self.mainWindow.graphicsView) |
1169 |
cmd.onSuccess.connect(self.onSuccessSelectAttribute)
|
1170 |
self.mainWindow.graphicsView.command = cmd
|
1171 |
|
1172 |
elif keyCell.text() == 'Set Batch': |
1173 |
cmd = SelectAttributeBatchCommand.SelectAttributeBatchCommand(items[0], self.mainWindow.graphicsView, True if type(items[0]) is QEngineeringLineNoTextItem else False) |
1174 |
cmd.onSuccess.connect(self.onSuccessSelectAttribute)
|
1175 |
self.mainWindow.graphicsView.command = cmd
|
1176 |
elif type(items[0]) is QEngineeringSpecBreakItem: |
1177 |
if keyCell.text() == 'UpStream' or keyCell.text() == 'DownStream': |
1178 |
attr = keyCell.data(Qt.UserRole) |
1179 |
cmd = SelectAttributeCommand.SelectAttributeCommand(items[0], attr, self.mainWindow.graphicsView) |
1180 |
cmd.onSuccess.connect(self.onSuccessSelectAttribute)
|
1181 |
self.mainWindow.graphicsView.command = cmd
|
1182 |
elif keyCell.text() == 'Set Specs': |
1183 |
from SpecBreakDialog import QSpecBreakDialog |
1184 |
|
1185 |
try:
|
1186 |
dialog = QSpecBreakDialog(self, items[0]) |
1187 |
dialog.exec_() |
1188 |
self.show_item_property(items[0]) |
1189 |
except Exception as ex: |
1190 |
print('error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
1191 |
sys.exc_info()[-1].tb_lineno))
|
1192 |
|
1193 |
elif issubclass(type(attr), SymbolProp): |
1194 |
attr = keyCell.data(Qt.UserRole) |
1195 |
cmd = SelectAttributeCommand.SelectAttributeCommand(items[0], attr, self.mainWindow.graphicsView) |
1196 |
cmd.onSuccess.connect(self.onSuccessSelectAttribute)
|
1197 |
self.mainWindow.graphicsView.command = cmd
|
1198 |
|
1199 |
'''
|
1200 |
@brief success select attribute
|
1201 |
@author kyouho
|
1202 |
@date 2018.10.23
|
1203 |
'''
|
1204 |
def onSuccessSelectAttribute(self, connItem=None): |
1205 |
""" update item's properties after selecting """
|
1206 |
if connItem:
|
1207 |
self._item = connItem
|
1208 |
self.show_item_property(self._item) |