hytos / DTI_PID / DTI_PID / QResultPropertyTableWidget.py @ 18f21a9a
이력 | 보기 | 이력해설 | 다운로드 (6.64 KB)
1 |
try:
|
---|---|
2 |
from PyQt5.QtCore import * |
3 |
from PyQt5.QtGui import * |
4 |
from PyQt5.QtWidgets import * |
5 |
except ImportError: |
6 |
try:
|
7 |
from PyQt4.QtCore import * |
8 |
from PyQt4.QtGui import * |
9 |
except ImportError: |
10 |
raise ImportError("ImageViewerQt: Requires PyQt5 or PyQt4.") |
11 |
from AppDocData import AppDocData |
12 |
import os |
13 |
import sys |
14 |
import math |
15 |
from SymbolSvgItem import SymbolSvgItem |
16 |
from QEngineeringLineNoTextItem import QEngineeringLineNoTextItem |
17 |
from enum import Enum |
18 |
|
19 |
'''
|
20 |
@brief ItemType
|
21 |
@author Jeongwoo
|
22 |
@date 2018.04.27
|
23 |
@history 2018.05.10 Jeongwoo Add LINE_NO
|
24 |
'''
|
25 |
class ItemType(Enum): |
26 |
SYMBOL = 1
|
27 |
NOTE = 2
|
28 |
LINE_NO = 3
|
29 |
|
30 |
class QResultPropertyTableWidget(QTableWidget): |
31 |
def __init__(self): |
32 |
QTableWidget.__init__(self)
|
33 |
self.symData = None |
34 |
self.initResultPropertyTableWidget()
|
35 |
|
36 |
'''
|
37 |
@brief Initialize TableWidget
|
38 |
@author Jeongwoo
|
39 |
@date 18.04.13
|
40 |
@history .
|
41 |
'''
|
42 |
def initResultPropertyTableWidget(self): |
43 |
self.setColumnCount(2) |
44 |
self.setRowCount(13) |
45 |
self.horizontalHeader().hide()
|
46 |
self.verticalHeader().hide()
|
47 |
self.horizontalHeader().setStretchLastSection(True) |
48 |
self.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
|
49 |
self.setEditTriggers(QAbstractItemView.NoEditTriggers)
|
50 |
|
51 |
'''
|
52 |
@brief Slot to accept item click event
|
53 |
@author Jeongwoo
|
54 |
@date 18.04.13
|
55 |
@history humkyung 2018.04.17 check if given symbol type is SymbolSvgItem
|
56 |
'''
|
57 |
@pyqtSlot(SymbolSvgItem)
|
58 |
def getClickedSymbol(self, symbol): |
59 |
if issubclass(type(symbol), SymbolSvgItem): |
60 |
self.symData = symbol
|
61 |
self.symbolChanged()
|
62 |
|
63 |
'''
|
64 |
@brief Slot to accept Note item click event
|
65 |
@author Jeongwoo
|
66 |
@date 18.04.27
|
67 |
'''
|
68 |
@pyqtSlot(str, list) |
69 |
def getClickedNote(self, noteNoStr, noteContentsList): |
70 |
self.noteChanged(noteNoStr, noteContentsList)
|
71 |
|
72 |
'''
|
73 |
@brief Slot to accept Line No Item Click event
|
74 |
@author Jeongwoo
|
75 |
@date 18.05.10
|
76 |
'''
|
77 |
@pyqtSlot(QEngineeringLineNoTextItem)
|
78 |
def getClickedLineNo(self, lineNoItem): |
79 |
self.lineNoChanged(lineNoItem)
|
80 |
|
81 |
'''
|
82 |
@brief Reset table with new SymbolSvgItem
|
83 |
@author Jeongwoo
|
84 |
@date 18.04.13
|
85 |
@history .
|
86 |
'''
|
87 |
def symbolChanged(self): |
88 |
self.initTitleCell(ItemType.SYMBOL)
|
89 |
self.initContentsCell()
|
90 |
|
91 |
'''
|
92 |
@brief Reset table with note info
|
93 |
@author Jeongwoo
|
94 |
@date 18.04.27
|
95 |
'''
|
96 |
def noteChanged(self, noteNoStr, noteContentsList): |
97 |
self.initTitleCell(ItemType.NOTE)
|
98 |
self.initNoteCell(noteNoStr, noteContentsList)
|
99 |
|
100 |
'''
|
101 |
@brief Reset table with line no item
|
102 |
@author Jeongwoo
|
103 |
@date 18.05.10
|
104 |
'''
|
105 |
def lineNoChanged(self, lineNoItem): |
106 |
self.initTitleCell(ItemType.LINE_NO)
|
107 |
self.initLineNoCell(lineNoItem)
|
108 |
|
109 |
'''
|
110 |
@brief Initialize Title Cell
|
111 |
@author Jeongwoo
|
112 |
@date 18.04.13
|
113 |
@history 2018.04.27 Jeongwoo Add if-statement by ItemType
|
114 |
2018.05.10 Jeongwoo Add if-statement LINE_NO ItemType
|
115 |
'''
|
116 |
def initTitleCell(self, type): |
117 |
self.clear()
|
118 |
|
119 |
if type == ItemType.SYMBOL:
|
120 |
self.setItem(0, 0, QTableWidgetItem("심볼명")) |
121 |
self.setItem(1, 0, QTableWidgetItem("타입")) |
122 |
self.setItem(2, 0, QTableWidgetItem("각도")) |
123 |
elif type == ItemType.NOTE:
|
124 |
self.setItem(0, 0, QTableWidgetItem("노트번호")) |
125 |
self.setItem(1, 0, QTableWidgetItem("노트내용")) |
126 |
elif type == ItemType.LINE_NO:
|
127 |
'''
|
128 |
DO NOTHING / initLineNoCell
|
129 |
'''
|
130 |
|
131 |
for index in range(self.rowCount()): |
132 |
item = self.item(index, 0) |
133 |
if item is not None: |
134 |
item.setBackground(QColor(220, 220, 220)) |
135 |
|
136 |
'''
|
137 |
@brief Initialize Contents Cell
|
138 |
@author Jeongwoo
|
139 |
@date 18.04.13
|
140 |
@history humkyung 2018.06.14 display symbol attributes
|
141 |
'''
|
142 |
def initContentsCell(self): |
143 |
from QEngineeringInstrumentItem import QEngineeringInstrumentItem |
144 |
|
145 |
if self.symData is not None: |
146 |
self.setItem(0, 1, QTableWidgetItem(self.symData.name)) |
147 |
self.setItem(1, 1, QTableWidgetItem(self.symData.type)) |
148 |
self.setItem(2, 1, QTableWidgetItem(str(round(math.degrees(self.symData.angle))))) |
149 |
|
150 |
# display attributes of symbol
|
151 |
attrs = self.symData.getAttributes()
|
152 |
if attrs is not None: |
153 |
attrItems = list(attrs.items())
|
154 |
for index in range(len(attrItems)): |
155 |
key = attrItems[index][0]
|
156 |
value = attrItems[index][1]
|
157 |
keyItem = QTableWidgetItem(key) |
158 |
keyItem.setBackground(QColor(220, 220, 220)) |
159 |
self.setItem(1 + index, 0, keyItem) |
160 |
self.setItem(1 + index, 1, QTableWidgetItem(value)) |
161 |
# up to here
|
162 |
else:
|
163 |
for index in range(self.rowCount()): |
164 |
item = self.item(index, 1) |
165 |
if item is not None: |
166 |
item.setText("")
|
167 |
|
168 |
'''
|
169 |
@brief Initialize Note Contents Cell
|
170 |
@author Jeongwoo
|
171 |
@date 18.04.27
|
172 |
'''
|
173 |
def initNoteCell(self, noteNoStr, noteContentsList): |
174 |
self.setItem(0, 1, QTableWidgetItem(noteNoStr)) |
175 |
for index in range(len(noteContentsList)): |
176 |
self.setItem(1+index, 1, QTableWidgetItem(noteContentsList[index])) |
177 |
|
178 |
'''
|
179 |
@brief Initialize Line No Contents Cell
|
180 |
@author Jeongwoo
|
181 |
@date 18.05.10
|
182 |
'''
|
183 |
def initLineNoCell(self, lineNoItem): |
184 |
lineNoTitleItem = QTableWidgetItem("Line No.")
|
185 |
lineNoTitleItem.setBackground(QColor(220, 220, 220)) |
186 |
self.setItem(0, 0, lineNoTitleItem) |
187 |
self.setItem(0, 1, QTableWidgetItem(lineNoItem.text())) |
188 |
attrs = lineNoItem.getLineNoAttributes() |
189 |
if attrs is not None: |
190 |
attrItems = list(attrs.items())
|
191 |
for index in range(len(attrItems)): |
192 |
key = attrItems[index][0]
|
193 |
value = attrItems[index][1]
|
194 |
keyItem = QTableWidgetItem(key) |
195 |
keyItem.setBackground(QColor(220, 220, 220)) |
196 |
self.setItem(1 + index, 0, keyItem) |
197 |
self.setItem(1 + index, 1, QTableWidgetItem(value)) |