개정판 9d0a18b6
dev issue #579: Develop FluidCode Form
DTI_PID/DTI_PID/AppDocData.py | ||
---|---|---|
1177 | 1177 |
for data in addDataList: |
1178 | 1178 |
uid = data.uid |
1179 | 1179 |
if not uid: |
1180 |
print(uid) |
|
1181 | 1180 |
sql = "insert or replace into FluidCode(UID, CODE, DESCRIPTION) values(lower(hex(randomblob(16))), '{}', '{}')".format(data.code, data.description) |
1182 | 1181 |
else: |
1183 | 1182 |
sql = "update FluidCode SET CODE='{}', DESCRIPTION='{}' WHERE UID = '{}'".format(data.code, data.description, data.uid) |
... | ... | |
1186 | 1185 |
for data in removeDataList: |
1187 | 1186 |
uid = data.uid |
1188 | 1187 |
if uid: |
1189 |
print('remove UID : ' + uid) |
|
1190 | 1188 |
sql = "delete from FluidCode where UID = '{}'".format(uid) |
1191 | 1189 |
cursor.execute(sql) |
1192 | 1190 |
|
DTI_PID/DTI_PID/FluidCodeDialog.py | ||
---|---|---|
22 | 22 |
self.ui = FluidCode_UI.Ui_DialogFluidCode() |
23 | 23 |
self.ui.setupUi(self) |
24 | 24 |
|
25 |
self.removeFluidCode = [] |
|
26 |
self.currentCode = {} |
|
27 |
|
|
25 | 28 |
docData = AppDocData.instance() |
26 | 29 |
fluidCodes = docData.getFluidCodeData() |
27 | 30 |
|
28 |
self.ui.tableWidgetFluidCode.setColumnCount(3) |
|
29 |
self.ui.tableWidgetFluidCode.setHorizontalHeaderLabels(['uid', 'Code', 'Desc.']) |
|
31 |
table = self.ui.tableWidgetFluidCode |
|
32 |
|
|
33 |
table.setColumnCount(3) |
|
34 |
table.setHorizontalHeaderLabels(['uid', 'Code', 'Desc.']) |
|
30 | 35 |
|
31 |
self.ui.tableWidgetFluidCode.setRowCount(len(fluidCodes))
|
|
32 |
self.ui.tableWidgetFluidCode.horizontalHeaderItem(0).setSizeHint(QSize(30, 30))
|
|
36 |
table.setRowCount(len(fluidCodes))
|
|
37 |
table.horizontalHeaderItem(0).setSizeHint(QSize(30, 30))
|
|
33 | 38 |
|
34 | 39 |
row = 0 |
35 | 40 |
for fluidCode in fluidCodes: |
36 |
self.ui.tableWidgetFluidCode.setItem(row, 0, QTableWidgetItem(fluidCode.uid))
|
|
37 |
self.ui.tableWidgetFluidCode.setItem(row, 1, QTableWidgetItem(fluidCode.code))
|
|
38 |
self.ui.tableWidgetFluidCode.setItem(row, 2, QTableWidgetItem(fluidCode.description))
|
|
41 |
table.setItem(row, 0, QTableWidgetItem(fluidCode.uid))
|
|
42 |
table.setItem(row, 1, QTableWidgetItem(fluidCode.code))
|
|
43 |
table.setItem(row, 2, QTableWidgetItem(fluidCode.description))
|
|
39 | 44 |
row += 1 |
45 |
|
|
46 |
table.horizontalHeaderItem(1).setSizeHint(QSize(30, 30)) |
|
47 |
table.resizeColumnToContents(2) |
|
48 |
table.hideColumn(0) |
|
49 |
table.cellChanged.connect(self.cellValueChanged) |
|
50 |
self.checkRowAndAddRow() |
|
51 |
self.setCurrentCode() |
|
52 |
|
|
40 | 53 |
''' |
41 | 54 |
@brief save fluid codes to sqlite |
42 | 55 |
@author humkyungS |
... | ... | |
44 | 57 |
@history 2018.07.03 kyouho |
45 | 58 |
''' |
46 | 59 |
def accept(self): |
47 |
from FluidCodeData import FluidCodeData |
|
48 | 60 |
table = self.ui.tableWidgetFluidCode |
49 |
removeFluidCode = [] |
|
50 | 61 |
fluidCodes = [] |
51 | 62 |
|
52 | 63 |
try: |
53 | 64 |
rowCount = table.rowCount() |
54 | 65 |
for row in range(rowCount): |
66 |
data = self.getFluidCodeDataInRow(row) |
|
67 |
if data.code: |
|
68 |
fluidCodes.append(data) |
|
69 |
|
|
70 |
docData = AppDocData.instance() |
|
71 |
docData.setFluidCodeData(fluidCodes, self.removeFluidCode) |
|
72 |
|
|
73 |
except Exception as ex: |
|
74 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
|
75 |
|
|
76 |
QDialog.accept(self) |
|
77 |
|
|
78 |
''' |
|
79 |
@brief key press event |
|
80 |
@author kyouho |
|
81 |
@date 2018.07.03 |
|
82 |
''' |
|
83 |
def keyPressEvent(self, e): |
|
84 |
try: |
|
85 |
if e.key() == Qt.Key_Delete: |
|
86 |
table = self.ui.tableWidgetFluidCode |
|
87 |
|
|
88 |
selectedIndexes = table.selectedIndexes() |
|
89 |
selectedRows = [item.row() for item in selectedIndexes] |
|
90 |
model = table.model() |
|
91 |
|
|
92 |
rowsIndex = [] |
|
93 |
for row in selectedRows: |
|
94 |
rowsIndex.append(row) |
|
95 |
|
|
96 |
#중복 제거 |
|
97 |
rowsIndex = list(set(rowsIndex)) |
|
98 |
rowsIndex.reverse() |
|
55 | 99 |
|
56 |
isHide = table.isRowHidden(row) |
|
57 |
|
|
58 |
uid = table.item(row, 0) |
|
59 |
codeItem = table.item(row, 1) |
|
60 |
descriptionItem = table.item(row, 2) |
|
61 |
data = FluidCodeData(uid.text() ,codeItem.text(), descriptionItem.text()) |
|
100 |
for row in rowsIndex: |
|
101 |
data = self.getFluidCodeDataInRow(row) |
|
102 |
self.removeFluidCode.append(data) |
|
103 |
model.removeRow(row) |
|
104 |
|
|
105 |
self.checkRowAndAddRow() |
|
106 |
|
|
107 |
except Exception as ex: |
|
108 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
|
109 |
|
|
62 | 110 |
|
63 |
if isHide: |
|
64 |
removeFluidCode.append(data) |
|
111 |
''' |
|
112 |
@brief get FluidCodeData in QtTable |
|
113 |
@author kyouho |
|
114 |
@date 2018.07.03 |
|
115 |
''' |
|
116 |
def getFluidCodeDataInRow(self, rowIndex): |
|
117 |
try: |
|
118 |
from FluidCodeData import FluidCodeData |
|
119 |
table = self.ui.tableWidgetFluidCode |
|
120 |
|
|
121 |
uid = table.item(rowIndex, 0) |
|
122 |
codeItem = table.item(rowIndex, 1) |
|
123 |
descriptionItem = table.item(rowIndex, 2) |
|
124 |
|
|
125 |
data = FluidCodeData(uid.text() ,codeItem.text(), descriptionItem.text()) |
|
126 |
|
|
127 |
except Exception as ex: |
|
128 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
|
129 |
|
|
130 |
return data |
|
131 |
|
|
132 |
''' |
|
133 |
@brief cellValueChange event |
|
134 |
@author kyouho |
|
135 |
@date 2018.07.03 |
|
136 |
''' |
|
137 |
def cellValueChanged(self, row, column): |
|
138 |
try: |
|
139 |
table = self.ui.tableWidgetFluidCode |
|
140 |
item = table.item(row, 1) |
|
141 |
code = item.text() |
|
142 |
if column == 1: |
|
143 |
result = self.isExistCode(code) |
|
144 |
if result: |
|
145 |
self.checkRowAndAddRow() |
|
146 |
self.setCurrentCode() |
|
65 | 147 |
else: |
66 |
fluidCodes.append(data)
|
|
148 |
item.setText(self.currentCode[row])
|
|
67 | 149 |
|
68 |
docData = AppDocData.instance()
|
|
69 |
docData.setFluidCodeData(fluidCodes, removeFluidCode)
|
|
150 |
except Exception as ex:
|
|
151 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
|
|
70 | 152 |
|
153 |
|
|
154 |
''' |
|
155 |
@brief Check Duplicate Code |
|
156 |
@author kyouho |
|
157 |
@date 2018.07.03 |
|
158 |
''' |
|
159 |
def isExistCode(self, editCode): |
|
160 |
try: |
|
161 |
if not editCode: |
|
162 |
return False |
|
163 |
|
|
164 |
table = self.ui.tableWidgetFluidCode |
|
165 |
rowCount = table.rowCount() |
|
166 |
codes = [] |
|
167 |
for row in range(rowCount): |
|
168 |
code = table.item(row, 1).text() |
|
169 |
codes.append(code) |
|
170 |
|
|
171 |
count = codes.count(editCode) |
|
172 |
|
|
173 |
if count >=2: |
|
174 |
return False |
|
175 |
else: |
|
176 |
return True |
|
177 |
|
|
71 | 178 |
except Exception as ex: |
72 | 179 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
180 |
|
|
181 |
''' |
|
182 |
@brief save current Code (self.currentCode) |
|
183 |
@author kyouho |
|
184 |
@date 2018.07.03 |
|
185 |
''' |
|
186 |
def setCurrentCode(self): |
|
187 |
try: |
|
188 |
self.currentCode.clear() |
|
189 |
|
|
190 |
table = self.ui.tableWidgetFluidCode |
|
191 |
rowCount = table.rowCount() |
|
192 |
|
|
193 |
for row in range(rowCount): |
|
194 |
code = table.item(row, 1).text() |
|
195 |
self.currentCode[row] = code |
|
196 |
|
|
197 |
except Exception as ex: |
|
198 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
|
199 |
|
|
200 |
''' |
|
201 |
@brief Add new row |
|
202 |
@author kyouho |
|
203 |
@date 2018.07.04 |
|
204 |
''' |
|
205 |
def checkRowAndAddRow(self): |
|
206 |
try: |
|
207 |
table = self.ui.tableWidgetFluidCode |
|
208 |
rowCount = table.rowCount() |
|
209 |
result = True |
|
210 |
for row in range(rowCount): |
|
211 |
code = table.item(row, 1).text() |
|
212 |
if not code: |
|
213 |
result = False |
|
214 |
|
|
215 |
if result: |
|
216 |
table.cellChanged.disconnect(self.cellValueChanged) |
|
217 |
table.setRowCount(rowCount + 1) |
|
218 |
table.setItem(rowCount, 0, QTableWidgetItem('')) |
|
219 |
table.setItem(rowCount, 1, QTableWidgetItem('')) |
|
220 |
table.setItem(rowCount, 2, QTableWidgetItem('')) |
|
221 |
table.cellChanged.connect(self.cellValueChanged) |
|
73 | 222 |
|
74 |
|
|
75 |
QDialog.accept(self) |
|
223 |
except Exception as ex: |
|
224 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
|
225 |
|
|
226 |
|
|
227 |
|
내보내기 Unified diff