hytos / DTI_PID / DTI_PID / ItemPropertyTableWidget.py @ 9689cb6b
이력 | 보기 | 이력해설 | 다운로드 (36.9 KB)
1 |
# coding: utf-8
|
---|---|
2 |
|
3 |
try:
|
4 |
from PyQt5.QtCore import * |
5 |
from PyQt5.QtGui import * |
6 |
from PyQt5.QtWidgets import * |
7 |
except ImportError: |
8 |
try:
|
9 |
from PyQt4.QtCore import * |
10 |
from PyQt4.QtGui import * |
11 |
except ImportError: |
12 |
raise ImportError("ImageViewerQt: Requires PyQt5 or PyQt4.") |
13 |
|
14 |
import os |
15 |
import sys |
16 |
import math |
17 |
import re |
18 |
import SelectAttributeCommand |
19 |
|
20 |
from EngineeringAbstractItem import QEngineeringAbstractItem |
21 |
from SymbolSvgItem import SymbolSvgItem |
22 |
from EngineeringLineNoTextItem import QEngineeringLineNoTextItem |
23 |
from EngineeringLineItem import QEngineeringLineItem |
24 |
from EngineeringNoteItem import QEngineeringNoteItem |
25 |
from EngineeringTextItem import QEngineeringTextItem |
26 |
from UserInputAttribute import UserInputAttribute |
27 |
from EngineeringSpecBreakItem import QEngineeringSpecBreakItem |
28 |
from EngineeringErrorItem import QEngineeringErrorItem |
29 |
from AppDocData import * |
30 |
from Drawing import Drawing |
31 |
from enum import Enum |
32 |
|
33 |
'''
|
34 |
@brief ItemType
|
35 |
@author Jeongwoo
|
36 |
@date 2018.04.27
|
37 |
@history 2018.05.10 Jeongwoo Add LINE_NO
|
38 |
'''
|
39 |
class ItemType(Enum): |
40 |
SYMBOL = 1
|
41 |
NOTE = 2
|
42 |
LINE_NO = 3
|
43 |
|
44 |
class QCustomCheckBox(QCheckBox): |
45 |
def __init__(self, table, row, col): |
46 |
QCheckBox.__init__(self)
|
47 |
self.table = table
|
48 |
self.row = row
|
49 |
self.col = col
|
50 |
|
51 |
def state_changed(self, state): |
52 |
""" check box state is changed """
|
53 |
if self.col == 0: |
54 |
widget = self.table.cellWidget(self.row, 3) |
55 |
if widget:
|
56 |
widget.setEnabled(False) if state else widget.setEnabled(True) |
57 |
|
58 |
data = self.table.item(self.row, 1).data(Qt.UserRole) |
59 |
if data: data.Freeze = self.isChecked() |
60 |
|
61 |
item = self.table.item(self.row, 3) |
62 |
if item:
|
63 |
item.setFlags(Qt.ItemIsEnabled) if state else item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsEditable|Qt.ItemIsSelectable) |
64 |
item.setBackground(Qt.lightGray) if state else item.setBackground(Qt.white) |
65 |
elif self.col == 3: |
66 |
cell = self.table.item(self.row, 1) |
67 |
if cell:
|
68 |
data = cell.data(Qt.UserRole) |
69 |
if data is not None: |
70 |
if self.table._item: self.table._item.set_property(data.Attribute, self.isChecked()) |
71 |
|
72 |
class QItemPropertyTableWidget(QTableWidget): |
73 |
def __init__(self, mainWindow): |
74 |
QTableWidget.__init__(self)
|
75 |
self._item = None |
76 |
self.initResultPropertyTableWidget()
|
77 |
self.mainWindow = mainWindow
|
78 |
|
79 |
self.cellChanged.connect(self.cellChangedEvent) |
80 |
self.cellDoubleClicked.connect(self.cellDoubleClickedEvent) |
81 |
|
82 |
'''
|
83 |
@brief show item's property
|
84 |
@author humkyung
|
85 |
@date 2018.07.03
|
86 |
@history euisung 2019.01.15 add icon image to line item
|
87 |
'''
|
88 |
def show_item_property(self, item): |
89 |
try:
|
90 |
from PyQt5 import QtGui |
91 |
from SymbolAttr import SymbolAttr |
92 |
|
93 |
self._item = item
|
94 |
|
95 |
self.blockSignals(True) |
96 |
|
97 |
if type(item) is QEngineeringLineItem: |
98 |
self.initTitleCell(item)
|
99 |
self.initContentsCell()
|
100 |
elif issubclass(type(item), SymbolSvgItem): |
101 |
self.onSymbolClicked(item)
|
102 |
elif type(item) is QEngineeringLineNoTextItem: |
103 |
self.onLineNoClicked(item)
|
104 |
elif type(item) is QEngineeringNoteItem: |
105 |
noteContentsList = item.findNoteContents(item.text()) |
106 |
self.onNoteClicked(item.text(), noteContentsList)
|
107 |
elif item is None: |
108 |
self.setRowCount(0) |
109 |
except Exception as ex: |
110 |
from App import App |
111 |
|
112 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
113 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
114 |
finally:
|
115 |
self.blockSignals(False) |
116 |
|
117 |
'''
|
118 |
@brief Initialize TableWidget
|
119 |
@author Jeongwoo
|
120 |
@date 18.04.13
|
121 |
@history humkyung 2018.07.08 show column header
|
122 |
'''
|
123 |
def initResultPropertyTableWidget(self): |
124 |
self.setColumnCount(4) |
125 |
self.setHorizontalHeaderLabels(['', 'Name', '', 'Value']) |
126 |
self.setColumnWidth(0, 10) |
127 |
self.setColumnWidth(1, 20) |
128 |
self.setColumnWidth(2, 10) |
129 |
self.setRowCount(13) |
130 |
self.verticalHeader().hide()
|
131 |
self.horizontalHeader().setStretchLastSection(True) |
132 |
|
133 |
'''
|
134 |
@brief Slot to accept item click event
|
135 |
@author Jeongwoo
|
136 |
@date 18.04.13
|
137 |
@history humkyung 2018.04.17 check if given symbol type is SymbolSvgItem
|
138 |
'''
|
139 |
@pyqtSlot(SymbolSvgItem)
|
140 |
def onSymbolClicked(self, symbol): |
141 |
try:
|
142 |
self.blockSignals(True) |
143 |
if issubclass(type(symbol), SymbolSvgItem): |
144 |
self._item = symbol
|
145 |
self.symbolChanged(symbol)
|
146 |
elif type(symbol) is QEngineeringLineNoTextItem: |
147 |
self.lineNoChanged(symbol)
|
148 |
finally:
|
149 |
self.blockSignals(True) |
150 |
|
151 |
'''
|
152 |
@brief show drawing' attributes
|
153 |
@author humkyung
|
154 |
@date 2018.07.07
|
155 |
'''
|
156 |
@pyqtSlot(Drawing)
|
157 |
def onDrawingClicked(self, drawing): |
158 |
try:
|
159 |
self.blockSignals(True) |
160 |
self.setRowCount(len(drawing.attrs)) |
161 |
|
162 |
row = 0
|
163 |
for attr in drawing.attrs: |
164 |
name = attr[0]
|
165 |
item = QTableWidgetItem(name) |
166 |
item.setFlags(Qt.ItemIsEnabled) |
167 |
item.setBackground(Qt.lightGray) |
168 |
self.setItem(row, 0, item) |
169 |
|
170 |
value = attr[1]
|
171 |
item = QTableWidgetItem(value) |
172 |
item.setFlags(Qt.ItemIsEnabled) |
173 |
self.setItem(row, 1, item) |
174 |
|
175 |
row = row + 1
|
176 |
finally:
|
177 |
self.blockSignals(False) |
178 |
|
179 |
'''
|
180 |
@brief Slot to accept Note item click event
|
181 |
@author Jeongwoo
|
182 |
@date 18.04.27
|
183 |
@history humkyung 2018.07.08 change method name to onNoteClicked
|
184 |
'''
|
185 |
@pyqtSlot(str, dict) |
186 |
def onNoteClicked(self, noteNoStr, noteContentsList): |
187 |
try:
|
188 |
self.blockSignals(True) |
189 |
self.noteChanged(noteNoStr, noteContentsList)
|
190 |
finally:
|
191 |
self.blockSignals(False) |
192 |
|
193 |
'''
|
194 |
@brief Slot to accept Line No Item Click event
|
195 |
@author Jeongwoo
|
196 |
@date 18.05.10
|
197 |
@hisotry humkyung 2018.07.08 change method name to onLineNoClicked
|
198 |
'''
|
199 |
@pyqtSlot(QEngineeringAbstractItem)
|
200 |
def onLineNoClicked(self, item): |
201 |
try:
|
202 |
self.blockSignals(True) |
203 |
self.lineNoChanged(item)
|
204 |
finally:
|
205 |
self.blockSignals(False) |
206 |
|
207 |
'''
|
208 |
@brief Reset table with new SymbolSvgItem
|
209 |
@author Jeongwoo
|
210 |
@date 18.04.13
|
211 |
@history .
|
212 |
'''
|
213 |
def symbolChanged(self, item): |
214 |
self.initTitleCell(item)
|
215 |
self.initContentsCell()
|
216 |
|
217 |
'''
|
218 |
@brief Reset table with note info
|
219 |
@author Jeongwoo
|
220 |
@date 18.04.27
|
221 |
'''
|
222 |
def noteChanged(self, noteNoStr, noteContentsList): |
223 |
self.initNoteCell(noteNoStr, noteContentsList)
|
224 |
|
225 |
'''
|
226 |
@brief Reset table with line no item
|
227 |
@author Jeongwoo
|
228 |
@date 18.05.10
|
229 |
'''
|
230 |
def lineNoChanged(self, item): |
231 |
from EngineeringRunItem import QEngineeringRunItem |
232 |
|
233 |
if type(item) is QEngineeringLineNoTextItem: |
234 |
self.initTitleCell(item)
|
235 |
self.initLineNoCell(item)
|
236 |
elif type(item) is QEngineeringRunItem: |
237 |
self.initLineRunCell(item)
|
238 |
|
239 |
""" show tooltip """
|
240 |
for index in range(self.rowCount()): |
241 |
item = self.item(index, 1) |
242 |
if item is not None: |
243 |
item.setToolTip(item.text()) |
244 |
|
245 |
'''
|
246 |
@brief Initialize Title Cell
|
247 |
@author Jeongwoos
|
248 |
@date 18.04.13
|
249 |
@history Jeongwoo 2018.04.27 Add if-statement by ItemType
|
250 |
Jeongwoo 2018.05.10 Add if-statement LINE_NO ItemType
|
251 |
humkyung 2018.08.15 add combobox for line type
|
252 |
'''
|
253 |
def initTitleCell(self, item): |
254 |
from LineTypeConditions import LineTypeConditions |
255 |
|
256 |
try:
|
257 |
self.clear()
|
258 |
self.setHorizontalHeaderLabels(['', 'Name', '', 'Value']) |
259 |
self.setColumnWidth(0, 20) |
260 |
self.setColumnWidth(1, 80) |
261 |
self.setColumnWidth(2, 20) |
262 |
if type(item) is QEngineeringSpecBreakItem: |
263 |
self.setRowCount(7) |
264 |
self.setItem(0, 1, QTableWidgetItem("UID")) |
265 |
self.setItem(1, 1, QTableWidgetItem("심볼명")) |
266 |
self.setItem(2, 1, QTableWidgetItem("타입")) |
267 |
self.setItem(3, 1, QTableWidgetItem("각도")) |
268 |
self.setItem(4, 1, QTableWidgetItem("원점")) |
269 |
self.setItem(5, 1, QTableWidgetItem("OWNER")) |
270 |
self.setItem(6, 1, QTableWidgetItem("Set Specs")) |
271 |
elif type(item) is QEngineeringErrorItem: |
272 |
self.setRowCount(7) |
273 |
self.setItem(0, 1, QTableWidgetItem("UID")) |
274 |
self.setItem(1, 1, QTableWidgetItem("심볼명")) |
275 |
self.setItem(2, 1, QTableWidgetItem("타입")) |
276 |
self.setItem(3, 1, QTableWidgetItem("각도")) |
277 |
self.setItem(4, 1, QTableWidgetItem("원점")) |
278 |
self.setItem(5, 1, QTableWidgetItem("OWNER")) |
279 |
self.setItem(6, 1, QTableWidgetItem("Message")) |
280 |
elif issubclass(type(item), SymbolSvgItem): |
281 |
self.setRowCount(6) |
282 |
self.setItem(0, 1, QTableWidgetItem("UID")) |
283 |
self.setItem(1, 1, QTableWidgetItem("심볼명")) |
284 |
self.setItem(2, 1, QTableWidgetItem("타입")) |
285 |
self.setItem(3, 1, QTableWidgetItem("각도")) |
286 |
self.setItem(4, 1, QTableWidgetItem("원점")) |
287 |
self.setItem(5, 1, QTableWidgetItem("OWNER")) |
288 |
elif type(item) is QEngineeringNoteItem: |
289 |
self.setRowCount(2) |
290 |
self.setItem(0, 1, QTableWidgetItem("노트번호")) |
291 |
self.setItem(1, 1, QTableWidgetItem("설명")) |
292 |
elif type(item) is QEngineeringLineNoTextItem: |
293 |
self.setRowCount(1) |
294 |
self.setItem(0, 1, QTableWidgetItem("UID")) |
295 |
elif type(item) is QEngineeringLineItem: |
296 |
self.setRowCount(5) |
297 |
self.setItem(0, 1, QTableWidgetItem('UID')) |
298 |
self.setItem(1, 1, QTableWidgetItem('OWNER')) |
299 |
widgetItem = QTableWidgetItem("타입")
|
300 |
widgetItem.setData(Qt.UserRole, item) |
301 |
self.setItem(2, 1, widgetItem) |
302 |
self._lineTypeComboBox = QComboBox(self) |
303 |
self._lineTypeComboBox.tag = widgetItem
|
304 |
appDocData = AppDocData.instance() |
305 |
for lineType in LineTypeConditions.items(): |
306 |
self._lineTypeComboBox.addItem(lineType.name)
|
307 |
self.setCellWidget(2, 3, self._lineTypeComboBox) |
308 |
self._lineTypeComboBox.setCurrentText(item.lineType)
|
309 |
self._lineTypeComboBox.currentIndexChanged.connect(self.onLineTypeChanged) |
310 |
|
311 |
for index in range(self.rowCount()): |
312 |
item = self.item(index, 1) |
313 |
if item is not None: |
314 |
item.setFlags(Qt.ItemIsEnabled) |
315 |
item.setBackground(Qt.lightGray) |
316 |
except Exception as ex: |
317 |
from App import App |
318 |
|
319 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
320 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
321 |
|
322 |
'''
|
323 |
@brief change selected lines' type by selected line type
|
324 |
@author humkyung
|
325 |
@date 2018.08.15
|
326 |
'''
|
327 |
def onLineTypeChanged(self, param): |
328 |
lineType = self._lineTypeComboBox.itemText(param)
|
329 |
data = self._lineTypeComboBox.tag.data(Qt.UserRole)
|
330 |
if type(data) is QEngineeringLineItem: |
331 |
data.lineType = lineType |
332 |
|
333 |
def show_icon_item(self, row, col, prop): |
334 |
""" show icon item on grid """
|
335 |
from PyQt5 import QtGui |
336 |
|
337 |
if prop.is_selectable or prop.AttributeType == 'OWNER' or prop.AttributeType == 'CONN': |
338 |
icon = QtGui.QIcon() |
339 |
icon.addPixmap(QtGui.QPixmap(":/newPrefix/doubleclick.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
340 |
icon_item = QTableWidgetItem('')
|
341 |
icon_item.setFlags(Qt.ItemIsEnabled) |
342 |
icon_item.setIcon(icon) |
343 |
self.setItem(row, col, icon_item)
|
344 |
elif prop.AttributeType == "String": |
345 |
icon = QtGui.QIcon() |
346 |
icon.addPixmap(QtGui.QPixmap(":/newPrefix/type.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
347 |
icon_item = QTableWidgetItem() |
348 |
icon_item.setIcon(icon) |
349 |
self.setItem(row, col, icon_item)
|
350 |
else:
|
351 |
item = QTableWidgetItem() |
352 |
item.setFlags(Qt.ItemIsEditable) |
353 |
self.setItem(row, col, item)
|
354 |
|
355 |
def show_item_properties(self, item): |
356 |
""" show item properties on grid """
|
357 |
from PyQt5 import QtGui |
358 |
|
359 |
row = self.rowCount()
|
360 |
if hasattr(item, '_properties'): |
361 |
self.setRowCount(row + len(item.properties)) |
362 |
|
363 |
for prop,value in item.properties.items(): |
364 |
try:
|
365 |
""" show freeze state """
|
366 |
checkbox = QCustomCheckBox(self, row, 0) |
367 |
checkbox.setChecked(prop.Freeze) |
368 |
checkbox.stateChanged.connect(checkbox.state_changed) |
369 |
self.setCellWidget(row, 0, checkbox) |
370 |
|
371 |
""" show property name """
|
372 |
key_item = QTableWidgetItem(prop.DisplayAttribute if prop.DisplayAttribute else prop.Attribute) |
373 |
key_item.setFlags(Qt.ItemIsEnabled) |
374 |
key_item.setBackground(Qt.lightGray) |
375 |
key_item.setData(Qt.UserRole, prop) |
376 |
self.setItem(row, 1, key_item) |
377 |
|
378 |
""" show icon item """
|
379 |
self.show_icon_item(row, 2, prop) |
380 |
|
381 |
""" show property value """
|
382 |
if prop.is_selectable:
|
383 |
value_item = QTableWidgetItem(str(value.uid) if hasattr(value, 'uid') else value) |
384 |
value_item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable) |
385 |
self.setItem(row, 3, value_item) |
386 |
else:
|
387 |
if prop.AttributeType == 'Boolean': |
388 |
self.checkbox_cell = QCustomCheckBox(self, row, 3) |
389 |
self.checkbox_cell.setChecked(True if value and str(value) == 'True' else False) |
390 |
self.checkbox_cell.stateChanged.connect(self.checkbox_cell.state_changed) |
391 |
if prop.Attribute == 'Freeze': self.checkbox_cell.stateChanged.connect(item.freeze_item.update_freeze) |
392 |
self.setCellWidget(row, 3, self.checkbox_cell) |
393 |
else:
|
394 |
value_item = QTableWidgetItem(value if value else '') |
395 |
value_item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable|Qt.ItemIsEditable) |
396 |
self.setItem(row, 3, value_item) |
397 |
|
398 |
checkbox.state_changed(checkbox.isChecked()) |
399 |
|
400 |
row = row + 1
|
401 |
except Exception as ex: |
402 |
from App import App |
403 |
|
404 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
405 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
406 |
|
407 |
def show_item_attributes(self, item): |
408 |
""" show item's attributes on grid """
|
409 |
from PyQt5 import QtGui |
410 |
|
411 |
row = self.rowCount()
|
412 |
attrs = item.getAttributes() |
413 |
|
414 |
# display attributes of symbol
|
415 |
if attrs is not None: |
416 |
self.setRowCount(row + len(attrs)) |
417 |
|
418 |
for key,value in attrs.items(): |
419 |
try:
|
420 |
""" show freeze state """
|
421 |
checkbox = QCustomCheckBox(self, row, 0) |
422 |
checkbox.setChecked(key.Freeze) |
423 |
checkbox.stateChanged.connect(checkbox.state_changed) |
424 |
self.setCellWidget(row, 0, checkbox) |
425 |
|
426 |
""" show property name """
|
427 |
key_item = QTableWidgetItem(key.DisplayAttribute if key.DisplayAttribute else key.Attribute) |
428 |
key_item.setBackground(Qt.lightGray) |
429 |
key_item.setData(Qt.UserRole, key) |
430 |
self.setItem(row, 1, key_item) |
431 |
|
432 |
""" show icon item """
|
433 |
self.show_icon_item(row, 2, key) |
434 |
|
435 |
value_item = QTableWidgetItem(str(value))
|
436 |
value_item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable|Qt.ItemIsEditable) |
437 |
|
438 |
if type(item) is QEngineeringSpecBreakItem: |
439 |
if key.Attribute == 'UpStream' or key.Attribute == 'DownStream': |
440 |
UpDownItem = QTableWidgetItem('{}'.format('None' if value is None else value)) |
441 |
icon = QtGui.QIcon() |
442 |
icon.addPixmap(QtGui.QPixmap(":/newPrefix/doubleclick.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
443 |
UpDownItem.setIcon(icon) |
444 |
self.setItem(row, 3, UpDownItem) |
445 |
elif key.AttributeType == 'Spec': |
446 |
self.setItem(row, 3, QTableWidgetItem(key.Attribute)) |
447 |
else:
|
448 |
self.setItem(row, 3, value_item) |
449 |
|
450 |
checkbox.state_changed(checkbox.isChecked()) |
451 |
|
452 |
row = row + 1
|
453 |
except Exception as ex: |
454 |
from App import App |
455 |
|
456 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
457 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
458 |
|
459 |
def show_item_connectors(self, item): |
460 |
""" show items' connectors on grid """
|
461 |
from PyQt5 import QtGui |
462 |
from SymbolAttr import SymbolAttr |
463 |
|
464 |
row = self.rowCount()
|
465 |
self.setRowCount(row + len(item.connectors)) |
466 |
|
467 |
count = 1
|
468 |
for connector in item.connectors: |
469 |
connector_item = QTableWidgetItem('CONN{}'.format(count))
|
470 |
connector_item.setFlags(Qt.ItemIsEnabled) |
471 |
connector_item.setBackground(Qt.lightGray) |
472 |
self.setItem(row, 1, connector_item) |
473 |
|
474 |
attr = SymbolAttr() |
475 |
attr.AttributeType = "CONN"
|
476 |
attr.AttrAt = count |
477 |
connector_item.setData(Qt.UserRole, attr) |
478 |
|
479 |
""" show icon item """
|
480 |
self.show_icon_item(row, 2, attr) |
481 |
|
482 |
connector_item = QTableWidgetItem('{}'.format('None' if connector.connectedItem is None else str(connector.connectedItem))) |
483 |
connector_item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable) |
484 |
self.setItem(row, 3, connector_item) |
485 |
|
486 |
row = row + 1
|
487 |
count = count + 1
|
488 |
|
489 |
'''
|
490 |
@brief Initialize Contents Cell
|
491 |
@author Jeongwoo
|
492 |
@date 18.04.13
|
493 |
@history humkyung 2018.06.14 display symbol attributes
|
494 |
humkyung 2018.07.05 display connectivity
|
495 |
euisung 2019.01.15 edit specbreak
|
496 |
'''
|
497 |
def initContentsCell(self): |
498 |
from PyQt5 import QtGui |
499 |
from SymbolAttr import SymbolAttr |
500 |
|
501 |
try:
|
502 |
if self._item is not None and issubclass(type(self._item), SymbolSvgItem): |
503 |
docData = AppDocData.instance() |
504 |
|
505 |
self.setItem(0, 3, QTableWidgetItem(str(self._item.uid))) |
506 |
self.setItem(1, 3, QTableWidgetItem(self._item.name)) |
507 |
self.setItem(2, 3, QTableWidgetItem(self._item.type)) |
508 |
self.setItem(3, 3, QTableWidgetItem(str(round(math.degrees(self._item.angle))))) |
509 |
self.setItem(4, 3, QTableWidgetItem(str(self._item.origin))) |
510 |
owner_item = QTableWidgetItem('{}'.format('None' if self._item.owner is None else str(self._item.owner))) |
511 |
owner_item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable) |
512 |
self.setItem(5, 3, owner_item) |
513 |
|
514 |
""" show icon item """
|
515 |
attr = SymbolAttr() |
516 |
attr.AttributeType = "OWNER"
|
517 |
self.show_icon_item(5, 2, attr) |
518 |
self.item(5, 1).setData(Qt.UserRole, attr) |
519 |
|
520 |
if type(self._item) is not QEngineeringSpecBreakItem and type(self._item) is not QEngineeringErrorItem: |
521 |
self.show_item_properties(self._item) |
522 |
|
523 |
if type(self._item) is QEngineeringSpecBreakItem: |
524 |
row = self.rowCount()
|
525 |
setSpecsItem = QTableWidgetItem('Open')
|
526 |
icon = QtGui.QIcon() |
527 |
icon.addPixmap(QtGui.QPixmap(":/newPrefix/doubleclick.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
528 |
setSpecsItem.setIcon(icon) |
529 |
self.setItem(row - 1, 3, setSpecsItem) |
530 |
|
531 |
if type(self._item) is QEngineeringErrorItem: |
532 |
errType = 'None'
|
533 |
if type(self._item.parent) is QEngineeringLineItem: |
534 |
errType = 'line'
|
535 |
elif issubclass(type(self._item.parent), SymbolSvgItem): |
536 |
errType = 'symbol'
|
537 |
self.setItem(2, 3, QTableWidgetItem(errType)) |
538 |
self.setItem(5, 3, QTableWidgetItem(str(self._item.parent.uid))) |
539 |
self.setItem(6, 3, QTableWidgetItem(self._item.msg)) |
540 |
|
541 |
self.show_item_attributes(self._item) |
542 |
self.show_item_connectors(self._item) |
543 |
|
544 |
for index in range(self.rowCount()): |
545 |
item = self.item(index, 3) |
546 |
if item is not None: item.setToolTip(item.text()) |
547 |
elif self._item is not None and type(self._item) is QEngineeringLineItem: |
548 |
self.setItem(0, 3, QTableWidgetItem(str(self._item.uid))) |
549 |
|
550 |
""" show icon item """
|
551 |
attr = SymbolAttr() |
552 |
attr.AttributeType = "OWNER"
|
553 |
self.show_icon_item(1, 2, attr) |
554 |
self.item(1, 1).setData(Qt.UserRole, attr) |
555 |
|
556 |
owner_item = QTableWidgetItem('{}'.format('None' if self._item.owner is None else str(self._item.owner))) |
557 |
self.setItem(1, 3, owner_item) |
558 |
|
559 |
self.show_item_properties(self._item) |
560 |
|
561 |
pt = self._item.startPoint()
|
562 |
key_item = QTableWidgetItem(self.tr("시작점")) |
563 |
key_item.setFlags(Qt.ItemIsEnabled) |
564 |
key_item.setBackground(Qt.lightGray) |
565 |
self.setItem(3, 1, key_item) |
566 |
self.setItem(3, 3, QTableWidgetItem('({},{})'.format(pt[0], pt[1]))) |
567 |
pt = self._item.endPoint()
|
568 |
key_item = QTableWidgetItem(self.tr("끝점")) |
569 |
key_item.setFlags(Qt.ItemIsEnabled) |
570 |
key_item.setBackground(Qt.lightGray) |
571 |
self.setItem(4, 1, key_item) |
572 |
self.setItem(4, 3, QTableWidgetItem('({},{})'.format(pt[0], pt[1]))) |
573 |
|
574 |
self.show_item_connectors(self._item) |
575 |
else:
|
576 |
self.setRowCount(0) |
577 |
except Exception as ex: |
578 |
from App import App |
579 |
|
580 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
581 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
582 |
|
583 |
'''
|
584 |
@brief combobox change event
|
585 |
@author kyouho
|
586 |
@date 2018.08.28
|
587 |
'''
|
588 |
def upStreamChanged(self, text): |
589 |
if self._item is not None: |
590 |
find = False
|
591 |
for index in range(len(self._item.attrs)): |
592 |
if type(self._item.attrs[index]) is tuple and self._item.attrs[index][0] == 'Up Stream': |
593 |
self._item.attrs[index] = (self._item.attrs[index][0], text) |
594 |
find = True
|
595 |
break
|
596 |
|
597 |
if not find: |
598 |
self._item.attrs.append(('Up Stream', text)) |
599 |
|
600 |
'''
|
601 |
@brief combobox change event
|
602 |
@author kyouho
|
603 |
@date 2018.08.28
|
604 |
'''
|
605 |
def downStreamChanged(self, text): |
606 |
if self._item is not None: |
607 |
find = False
|
608 |
for index in range(len(self._item.attrs)): |
609 |
if type(self._item.attrs[index]) is tuple and self._item.attrs[index][0] == 'Down Stream': |
610 |
self._item.attrs[index] = (self._item.attrs[index][0], text) |
611 |
find = True
|
612 |
break
|
613 |
|
614 |
if not find: |
615 |
self._item.attrs.append(('Down Stream', text)) |
616 |
|
617 |
'''
|
618 |
@brief Initialize Note Contents Cell
|
619 |
@author Jeongwoo
|
620 |
@date 18.04.27
|
621 |
'''
|
622 |
def initNoteCell(self, noteNoStr, noteContentsList): |
623 |
self.setRowCount(0) |
624 |
|
625 |
for key in noteContentsList: |
626 |
row = self.rowCount()
|
627 |
self.setRowCount(row + len(noteContentsList[key])) |
628 |
item = QTableWidgetItem(key) |
629 |
self.setItem(row, 1, item) |
630 |
|
631 |
for index in range(len(noteContentsList[key])): |
632 |
self.setItem(row, 3, QTableWidgetItem(noteContentsList[key][index])) |
633 |
row = row + 1
|
634 |
|
635 |
for index in range(self.rowCount()): |
636 |
item = self.item(index, 1) |
637 |
if item is not None: |
638 |
item.setFlags(Qt.ItemIsEnabled) |
639 |
item.setBackground(Qt.lightGray) |
640 |
|
641 |
'''
|
642 |
@brief Initialize Line No Contents Cell
|
643 |
@author Jeongwoo
|
644 |
@date 18.05.10
|
645 |
@history humkyung 2018.07.20 display combobox when key is 'Stream No'
|
646 |
'''
|
647 |
def initLineNoCell(self, lineNoItem): |
648 |
appDocData = AppDocData.instance() |
649 |
configs = appDocData.getConfigs('Line No', 'Configuration') |
650 |
configs = configs[0].value.split('"-"') |
651 |
|
652 |
item = QTableWidgetItem(str(lineNoItem.uid))
|
653 |
item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable) |
654 |
self.setItem(0, 3, item) |
655 |
|
656 |
self.show_item_properties(lineNoItem)
|
657 |
|
658 |
row = self.rowCount()
|
659 |
attrs = lineNoItem.getAttributes() |
660 |
self.setRowCount(row + len(attrs)) |
661 |
if attrs is not None: |
662 |
for key in attrs.keys(): |
663 |
item = QTableWidgetItem(key.DisplayAttribute if key.DisplayAttribute else key.Attribute) |
664 |
item.setFlags(Qt.ItemIsEnabled) |
665 |
item.setBackground(Qt.lightGray) |
666 |
item.tag = key |
667 |
self.setItem(row, 1, item) |
668 |
|
669 |
""" show icon item """
|
670 |
self.show_icon_item(row, 2, key) |
671 |
|
672 |
# value cell
|
673 |
value = attrs[key] |
674 |
valueCell = QTableWidgetItem(value) |
675 |
|
676 |
# UID로 확인
|
677 |
keyStr = appDocData.getLinePropertiesByUID(key.UID) |
678 |
if keyStr:
|
679 |
# editable value cell
|
680 |
if keyStr[0].AttributeType == 'String': |
681 |
pass
|
682 |
#self.attrValueList.append((valueCell, key.Attribute))
|
683 |
#self.stringCell.append(valueCell)
|
684 |
if keyStr[0].UID in configs: valueCell.setFlags(Qt.ItemIsEnabled) |
685 |
else:
|
686 |
valueCell.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable) |
687 |
|
688 |
if key.Attribute.upper() == 'STREAM_NO': |
689 |
self.streamNoComboBox = QComboBox()
|
690 |
self.streamNoComboBox.tag = key
|
691 |
self.streamNoComboBox.currentIndexChanged.connect(self.onStreamNoChanged) |
692 |
|
693 |
streamNos = sorted(list(appDocData.hmbTable.streamNos())) |
694 |
for streamNo in streamNos: |
695 |
self.streamNoComboBox.addItem(streamNo)
|
696 |
self.setCellWidget(row, 3, self.streamNoComboBox) |
697 |
self.streamNoComboBox.setCurrentText(value)
|
698 |
|
699 |
self.setItem(row, 3, valueCell) |
700 |
|
701 |
row = row + 1
|
702 |
|
703 |
'''
|
704 |
@brief change selected lines' stream no by selected stream no
|
705 |
@author humkyung
|
706 |
@date 2018.07.20
|
707 |
'''
|
708 |
def onStreamNoChanged(self, param): |
709 |
items = self.mainWindow.graphicsView.scene.selectedItems()
|
710 |
if items is not None and len(items) == 1: |
711 |
if type(items[0]) is QEngineeringLineNoTextItem: |
712 |
stream_no = self.streamNoComboBox.itemText(param)
|
713 |
items[0].set_attrib(self.streamNoComboBox.tag, stream_no) |
714 |
return
|
715 |
|
716 |
'''
|
717 |
@brief Initialize Run Contents Cell
|
718 |
@author humkyung
|
719 |
@date 2018.05.27
|
720 |
'''
|
721 |
def initLineRunCell(self, item): |
722 |
self.setRowCount(1) |
723 |
|
724 |
lineTypeItem = QTableWidgetItem(self.tr("라인 타입")) |
725 |
lineTypeItem.setBackground(Qt.lightGray) |
726 |
lineTypeItem.setFlags(Qt.ItemIsEnabled) |
727 |
self.setItem(0, 1, lineTypeItem) |
728 |
|
729 |
'''
|
730 |
@brief Key Press Event
|
731 |
@author kyouho
|
732 |
@date 2018.07.19
|
733 |
'''
|
734 |
def keyPressEvent(self, event): |
735 |
if event.key() == Qt.Key_Delete:
|
736 |
items = self.mainWindow.graphicsView.scene.selectedItems()
|
737 |
selectedIndexes = self.selectedIndexes()
|
738 |
if selectedIndexes[0].column() == 3 and self.item(selectedIndexes[0].row(), 1).text() == 'OWNER': |
739 |
items[0].owner = None |
740 |
self.show_item_property(items[0]) |
741 |
elif len(items) == 1 and len(selectedIndexes) == 1 and type(items[0]) is not QEngineeringLineItem and type(items[0]) is not QEngineeringSpecBreakItem and self.item(selectedIndexes[0].row(), 1).text().find('CONN') is not 0: |
742 |
if selectedIndexes[0].column() == 3: |
743 |
attributeStr = self.item(selectedIndexes[0].row(), 1).text() |
744 |
items[0].removeSelfAttr(attributeStr)
|
745 |
self.mainWindow.refreshResultPropertyTableWidget()
|
746 |
elif len(items) == 1 and len(selectedIndexes) == 1 and (type(items[0]) is QEngineeringLineItem or issubclass(type(items[0]), SymbolSvgItem)): |
747 |
key_cell = self.item(selectedIndexes[0].row(), 1) |
748 |
if selectedIndexes[0].column() == 3 and key_cell.text().find('CONN') is 0: |
749 |
selectedUID = self.item(selectedIndexes[0].row(), 1).text() |
750 |
connNum = int(key_cell.text().replace('CONN', '')) |
751 |
items[0].connectors[connNum - 1].connectedItem = None |
752 |
self.show_item_property(items[0]) |
753 |
|
754 |
for sceneItem in self.mainWindow.graphicsView.scene.items(): |
755 |
if hasattr(sceneItem, 'uid') and str(sceneItem.uid) == selectedUID and hasattr(sceneItem, 'connectors'): |
756 |
for sceneConnector in sceneItem.connectors: |
757 |
if sceneConnector.connectedItem is not None and items[0].uid == sceneConnector.connectedItem.uid: |
758 |
sceneConnector.connectedItem = None
|
759 |
elif len(items) == 1 and len(selectedIndexes) == 1 and type(items[0]) is QEngineeringSpecBreakItem: |
760 |
keyCell = self.item(selectedIndexes[0].row(), 1) |
761 |
if selectedIndexes[0].column() == 3 and (keyCell.text() == 'UpStream' or keyCell.text() == 'DownStream'): |
762 |
for attr in items[0].attrs.keys(): |
763 |
if attr.Attribute == keyCell.text():
|
764 |
items[0].attrs[attr] = None |
765 |
self.show_item_property(items[0]) |
766 |
elif (event.key() == Qt.Key_C) and (event.modifiers() & Qt.ControlModifier): |
767 |
self.copy_cells_to_clipboard()
|
768 |
event.accept() |
769 |
|
770 |
def copy_cells_to_clipboard(self): |
771 |
""" copy selected text to clipboard """
|
772 |
|
773 |
selection = self.selectedIndexes()
|
774 |
if selection:
|
775 |
rows = sorted(index.row() for index in selection) |
776 |
columns = sorted(index.column() for index in selection) |
777 |
text = self.item(rows[-1], columns[-1]).text() |
778 |
QApplication.clipboard().setText(text) |
779 |
|
780 |
'''
|
781 |
@brief int cell check
|
782 |
@author kyouho
|
783 |
@date 2018.08.20
|
784 |
'''
|
785 |
def cellChangedEvent(self, row, column): |
786 |
from SymbolAttr import SymbolProp |
787 |
from SymbolAttr import SymbolAttr |
788 |
|
789 |
try:
|
790 |
if column == 3: |
791 |
item = self.item(row, 1) |
792 |
data = item.data(Qt.UserRole) if item is not None else None |
793 |
if data is not None: |
794 |
if self._item: |
795 |
if type(data) is SymbolProp: |
796 |
if data.AttributeType != 'Boolean': |
797 |
self._item.set_property(data.Attribute, self.item(row, column).text()) |
798 |
else:
|
799 |
self._item.set_property(data.Attribute, self.cellWidget(row, column).isChecked()) |
800 |
elif type(data) is SymbolAttr: |
801 |
if data.AttributeType != 'Boolean': |
802 |
self._item.set_attrib(data, self.item(row, column).text()) |
803 |
else:
|
804 |
self._item.set_attrib(data, self.cellWidget(row, column).isChecked()) |
805 |
except Exception as ex: |
806 |
from App import App |
807 |
from AppDocData import MessageType |
808 |
|
809 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
810 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
811 |
|
812 |
'''
|
813 |
@brief resultPropertyTableWidget Cell Double Click Event
|
814 |
@author kyouho
|
815 |
@date 2018.07.19
|
816 |
@history euisung 2019.01.15 edit specbreak
|
817 |
'''
|
818 |
def cellDoubleClickedEvent(self, row, column): |
819 |
from SymbolAttr import SymbolProp |
820 |
|
821 |
if column == 2: |
822 |
items = self.mainWindow.graphicsView.scene.selectedItems()
|
823 |
keyCell = self.item(row, 1) |
824 |
attr = keyCell.data(Qt.UserRole) |
825 |
if hasattr(keyCell, 'tag') and type(items[0]) is not QEngineeringSpecBreakItem: |
826 |
attr = keyCell.tag |
827 |
if attr.is_selectable:
|
828 |
cmd = SelectAttributeCommand.SelectAttributeCommand(items[0], attr, self.mainWindow.graphicsView) |
829 |
cmd.onSuccess.connect(self.onSuccessSelectAttribute)
|
830 |
self.mainWindow.graphicsView.command = cmd
|
831 |
elif self.item(row, column).flags() != Qt.ItemIsEnabled: |
832 |
self.editItem(self.item(row, column)) |
833 |
elif keyCell.text() == 'CONN' and type(items[0]) is QEngineeringLineNoTextItem: |
834 |
from SymbolAttr import SymbolAttr |
835 |
attr = SymbolAttr() |
836 |
attr.AttributeType = "Line Item"
|
837 |
cmd = SelectAttributeCommand.SelectAttributeCommand(items[0], attr, self.mainWindow.graphicsView) |
838 |
cmd.onSuccess.connect(self.onSuccessSelectAttribute)
|
839 |
self.mainWindow.graphicsView.command = cmd
|
840 |
elif keyCell.text() == 'OWNER' and ((type(items[0]) is QEngineeringLineItem) or (issubclass(type(items[0]), SymbolSvgItem))): |
841 |
attr = keyCell.data(Qt.UserRole) |
842 |
cmd = SelectAttributeCommand.SelectAttributeCommand(items[0], attr, self.mainWindow.graphicsView) |
843 |
cmd.onSuccess.connect(self.onSuccessSelectAttribute)
|
844 |
self.mainWindow.graphicsView.command = cmd
|
845 |
elif type(items[0]) is QEngineeringSpecBreakItem: |
846 |
if keyCell.text() == 'UpStream' or keyCell.text() == 'DownStream': |
847 |
attr = keyCell.data(Qt.UserRole) |
848 |
cmd = SelectAttributeCommand.SelectAttributeCommand(items[0], attr, self.mainWindow.graphicsView) |
849 |
cmd.onSuccess.connect(self.onSuccessSelectAttribute)
|
850 |
self.mainWindow.graphicsView.command = cmd
|
851 |
|
852 |
elif keyCell.text() == 'Set Specs': |
853 |
from SpecBreakDialog import QSpecBreakDialog |
854 |
|
855 |
try:
|
856 |
dialog = QSpecBreakDialog(self, items[0]) |
857 |
dialog.exec_() |
858 |
self.show_item_property(items[0]) |
859 |
except Exception as ex: |
860 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
861 |
elif issubclass(type(attr), SymbolProp): |
862 |
attr = keyCell.data(Qt.UserRole) |
863 |
cmd = SelectAttributeCommand.SelectAttributeCommand(items[0], attr, self.mainWindow.graphicsView) |
864 |
cmd.onSuccess.connect(self.onSuccessSelectAttribute)
|
865 |
self.mainWindow.graphicsView.command = cmd
|
866 |
|
867 |
'''
|
868 |
@brief success select attribute
|
869 |
@author kyouho
|
870 |
@date 2018.10.23
|
871 |
'''
|
872 |
def onSuccessSelectAttribute(self, connItem = None): |
873 |
""" update item's properties after selecting """
|
874 |
self.show_item_property(self._item) |