hytos / DTI_PID / DTI_PID / ItemDataFormatDialog.py @ 7e003f07
이력 | 보기 | 이력해설 | 다운로드 (30.9 KB)
1 |
# coding: utf-8
|
---|---|
2 |
""" This is ItemDataFormatDialog module """
|
3 |
|
4 |
import os |
5 |
import sys |
6 |
from PyQt5.QtCore import * |
7 |
from PyQt5.QtGui import * |
8 |
from PyQt5.QtWidgets import * |
9 |
from AppDocData import AppDocData, Config |
10 |
import ItemDataFormat_UI |
11 |
|
12 |
dbListOrderName = ['LINE_DATA_LIST_EXPORT_ORDER', 'EQUIPMENT_DATA_LIST_EXPORT_ORDER', 'VALVE_DATA_LIST_EXPORT_ORDER', |
13 |
'INSTRUMENT_DATA_LIST_EXPORT_ORDER', 'NOTE_DATA_LIST_EXPORT_ORDER'] |
14 |
dbListName = ['LINE_DATA_LIST', 'EQUIPMENT_DATA_LIST', 'VALVE_DATA_LIST', 'INSTRUMENT_DATA_LIST', 'NOTE_DATA_LIST'] |
15 |
|
16 |
|
17 |
class QItemDataFormatDialog(QDialog): |
18 |
""" This is QItemDataFormatDialog class """
|
19 |
|
20 |
DATA_LIST = ['LINE_DATA_LIST', 'EQUIPMENT_DATA_LIST', 'VALVE_DATA_LIST', 'INSTRUMENT_DATA_LIST', 'NOTE_DATA_LIST'] |
21 |
|
22 |
def __init__(self, parent, columnListAll, columnOrder): |
23 |
QDialog.__init__(self, parent)
|
24 |
self.setWindowFlag(Qt.WindowMinMaxButtonsHint)
|
25 |
|
26 |
self.parent = parent
|
27 |
self.ui = ItemDataFormat_UI.Ui_ItemDataFormatDialog()
|
28 |
self.ui.setupUi(self) |
29 |
|
30 |
self.columnListAll = columnListAll
|
31 |
self.columnOrder = columnOrder
|
32 |
|
33 |
self.delimiter = '!-!' |
34 |
self.delimiterCombine = '!@!' |
35 |
self.emptyCol = 'Empty Column' |
36 |
self.selectedCol = None |
37 |
|
38 |
self.lineHistory = []
|
39 |
self.equipmentHistory = []
|
40 |
self.valveHistory = []
|
41 |
self.instrumentHistory = []
|
42 |
self.noteHistory = []
|
43 |
self.colHistory = \
|
44 |
{ |
45 |
QItemDataFormatDialog.DATA_LIST[0]: self.lineHistory, |
46 |
QItemDataFormatDialog.DATA_LIST[1]: self.equipmentHistory, |
47 |
QItemDataFormatDialog.DATA_LIST[2]: self.valveHistory, |
48 |
QItemDataFormatDialog.DATA_LIST[3]: self.instrumentHistory, |
49 |
QItemDataFormatDialog.DATA_LIST[4]: self.noteHistory |
50 |
} |
51 |
|
52 |
self.listWidgets = \
|
53 |
{ |
54 |
QItemDataFormatDialog.DATA_LIST[0]: self.ui.listWidgetLine, |
55 |
QItemDataFormatDialog.DATA_LIST[1]: self.ui.listWidgetEquipment, |
56 |
QItemDataFormatDialog.DATA_LIST[2]: self.ui.listWidgetValve, |
57 |
QItemDataFormatDialog.DATA_LIST[3]: self.ui.listWidgetInstrument, |
58 |
QItemDataFormatDialog.DATA_LIST[4]: self.ui.listWidgetNote |
59 |
} |
60 |
|
61 |
self.tableWidgets = \
|
62 |
{ |
63 |
QItemDataFormatDialog.DATA_LIST[0]: self.ui.tableWidgetLine, |
64 |
QItemDataFormatDialog.DATA_LIST[1]: self.ui.tableWidgetEquipment, |
65 |
QItemDataFormatDialog.DATA_LIST[2]: self.ui.tableWidgetValve, |
66 |
QItemDataFormatDialog.DATA_LIST[3]: self.ui.tableWidgetInstrument, |
67 |
QItemDataFormatDialog.DATA_LIST[4]: self.ui.tableWidgetNote |
68 |
} |
69 |
|
70 |
self.sections = \
|
71 |
{ |
72 |
QItemDataFormatDialog.DATA_LIST[0]: self.lineSectionClicked, |
73 |
QItemDataFormatDialog.DATA_LIST[1]: self.equipmentSectionClicked, |
74 |
QItemDataFormatDialog.DATA_LIST[2]: self.valveSectionClicked, |
75 |
QItemDataFormatDialog.DATA_LIST[3]: self.instrumentSectionClicked, |
76 |
QItemDataFormatDialog.DATA_LIST[4]: self.noteSectionClicked |
77 |
} |
78 |
|
79 |
self.items = \
|
80 |
{ |
81 |
QItemDataFormatDialog.DATA_LIST[0]: self.lineItemDoubleCliked, |
82 |
QItemDataFormatDialog.DATA_LIST[1]: self.equipmentItemDoubleCliked, |
83 |
QItemDataFormatDialog.DATA_LIST[2]: self.valveItemDoubleCliked, |
84 |
QItemDataFormatDialog.DATA_LIST[3]: self.instrumentItemDoubleCliked, |
85 |
QItemDataFormatDialog.DATA_LIST[4]: self.noteItemDoubleCliked |
86 |
} |
87 |
|
88 |
self.drops = \
|
89 |
{ |
90 |
QItemDataFormatDialog.DATA_LIST[0]: self.lineDropEvent, |
91 |
QItemDataFormatDialog.DATA_LIST[1]: self.equipmentDropEvent, |
92 |
QItemDataFormatDialog.DATA_LIST[2]: self.valveDropEvent, |
93 |
QItemDataFormatDialog.DATA_LIST[3]: self.instrumentDropEvent, |
94 |
QItemDataFormatDialog.DATA_LIST[4]: self.noteDropEvent |
95 |
} |
96 |
|
97 |
self.deleteButtons = \
|
98 |
{ |
99 |
QItemDataFormatDialog.DATA_LIST[0]: self.ui.pushButtonLineDelete, |
100 |
QItemDataFormatDialog.DATA_LIST[1]: self.ui.pushButtonEquipmentDelete, |
101 |
QItemDataFormatDialog.DATA_LIST[2]: self.ui.pushButtonValveDelete, |
102 |
QItemDataFormatDialog.DATA_LIST[3]: self.ui.pushButtonInstrumentDelete, |
103 |
QItemDataFormatDialog.DATA_LIST[4]: self.ui.pushButtonNoteDelete |
104 |
} |
105 |
|
106 |
self.deletes = \
|
107 |
{ |
108 |
QItemDataFormatDialog.DATA_LIST[0]: self.lineDeleteClicked, |
109 |
QItemDataFormatDialog.DATA_LIST[1]: self.equipmentDeleteClicked, |
110 |
QItemDataFormatDialog.DATA_LIST[2]: self.valveDeleteClicked, |
111 |
QItemDataFormatDialog.DATA_LIST[3]: self.instrumentDeleteClicked, |
112 |
QItemDataFormatDialog.DATA_LIST[4]: self.noteDeleteClicked |
113 |
} |
114 |
|
115 |
self.addButtons = \
|
116 |
{ |
117 |
QItemDataFormatDialog.DATA_LIST[0]: self.ui.pushButtonLineAdd, |
118 |
QItemDataFormatDialog.DATA_LIST[1]: self.ui.pushButtonEquipmentAdd, |
119 |
QItemDataFormatDialog.DATA_LIST[2]: self.ui.pushButtonValveAdd, |
120 |
QItemDataFormatDialog.DATA_LIST[3]: self.ui.pushButtonInstrumentAdd, |
121 |
QItemDataFormatDialog.DATA_LIST[4]: self.ui.pushButtonNoteAdd |
122 |
} |
123 |
|
124 |
self.adds = \
|
125 |
{ |
126 |
QItemDataFormatDialog.DATA_LIST[0]: self.lineAddClicked, |
127 |
QItemDataFormatDialog.DATA_LIST[1]: self.equipmentAddClicked, |
128 |
QItemDataFormatDialog.DATA_LIST[2]: self.valveAddClicked, |
129 |
QItemDataFormatDialog.DATA_LIST[3]: self.instrumentAddClicked, |
130 |
QItemDataFormatDialog.DATA_LIST[4]: self.noteAddClicked |
131 |
} |
132 |
|
133 |
self.emptyButtons = \
|
134 |
{ |
135 |
QItemDataFormatDialog.DATA_LIST[0]: self.ui.pushButtonLineEmptyColumn, |
136 |
QItemDataFormatDialog.DATA_LIST[1]: self.ui.pushButtonEquipmentEmptyColumn, |
137 |
QItemDataFormatDialog.DATA_LIST[2]: self.ui.pushButtonValveEmptyColumn, |
138 |
QItemDataFormatDialog.DATA_LIST[3]: self.ui.pushButtonInstrumentEmptyColumn, |
139 |
QItemDataFormatDialog.DATA_LIST[4]: self.ui.pushButtonNoteEmptyColumn |
140 |
} |
141 |
|
142 |
self.emptys = \
|
143 |
{ |
144 |
QItemDataFormatDialog.DATA_LIST[0]: self.lineEmptyClicked, |
145 |
QItemDataFormatDialog.DATA_LIST[1]: self.equipmentEmptyClicked, |
146 |
QItemDataFormatDialog.DATA_LIST[2]: self.valveEmptyClicked, |
147 |
QItemDataFormatDialog.DATA_LIST[3]: self.instrumentEmptyClicked, |
148 |
QItemDataFormatDialog.DATA_LIST[4]: self.noteEmptyClicked |
149 |
} |
150 |
|
151 |
self.colAddButtons = \
|
152 |
{ |
153 |
QItemDataFormatDialog.DATA_LIST[0]: self.ui.pushButtonLineColAdd, |
154 |
QItemDataFormatDialog.DATA_LIST[1]: self.ui.pushButtonEqpColAdd, |
155 |
QItemDataFormatDialog.DATA_LIST[2]: self.ui.pushButtonValveColAdd, |
156 |
QItemDataFormatDialog.DATA_LIST[3]: self.ui.pushButtonInstColAdd, |
157 |
QItemDataFormatDialog.DATA_LIST[4]: self.ui.pushButtonNoteColAdd |
158 |
} |
159 |
|
160 |
self.colAdds = \
|
161 |
{ |
162 |
QItemDataFormatDialog.DATA_LIST[0]: self.line_add_clicked, |
163 |
QItemDataFormatDialog.DATA_LIST[1]: self.equipment_add_clicked, |
164 |
QItemDataFormatDialog.DATA_LIST[2]: self.valve_add_clicked, |
165 |
QItemDataFormatDialog.DATA_LIST[3]: self.instrument_add_clicked, |
166 |
QItemDataFormatDialog.DATA_LIST[4]: self.note_add_clicked |
167 |
} |
168 |
|
169 |
self.colEditButtons = \
|
170 |
{ |
171 |
QItemDataFormatDialog.DATA_LIST[0]: self.ui.pushButtonLineColEdit, |
172 |
QItemDataFormatDialog.DATA_LIST[1]: self.ui.pushButtonEqpColEdit, |
173 |
QItemDataFormatDialog.DATA_LIST[2]: self.ui.pushButtonValveColEdit, |
174 |
QItemDataFormatDialog.DATA_LIST[3]: self.ui.pushButtonInstColEdit, |
175 |
QItemDataFormatDialog.DATA_LIST[4]: self.ui.pushButtonNoteColEdit |
176 |
} |
177 |
|
178 |
self.colEdits = \
|
179 |
{ |
180 |
QItemDataFormatDialog.DATA_LIST[0]: self.line_edit_clicked, |
181 |
QItemDataFormatDialog.DATA_LIST[1]: self.equipment_edit_clicked, |
182 |
QItemDataFormatDialog.DATA_LIST[2]: self.valve_edit_clicked, |
183 |
QItemDataFormatDialog.DATA_LIST[3]: self.instrument_edit_clicked, |
184 |
QItemDataFormatDialog.DATA_LIST[4]: self.note_edit_clicked |
185 |
} |
186 |
|
187 |
# button en/disable setting
|
188 |
self.ui.pushButtonLineColAdd.setDisabled(True) |
189 |
self.ui.pushButtonLineColDelete.setDisabled(True) |
190 |
self.ui.pushButtonLineColEdit.setDisabled(True) |
191 |
self.ui.pushButtonEqpColDelete.setDisabled(True) |
192 |
self.ui.pushButtonValveColDelete.setDisabled(True) |
193 |
self.ui.pushButtonInstColDelete.setDisabled(True) |
194 |
self.ui.pushButtonNoteColAdd.setDisabled(True) |
195 |
self.ui.pushButtonNoteColDelete.setDisabled(True) |
196 |
self.ui.pushButtonNoteColEdit.setDisabled(True) |
197 |
|
198 |
self.dragItem = None |
199 |
|
200 |
# tableWidget setting
|
201 |
for key in self.tableWidgets.keys(): |
202 |
self.tableWidgets[key].horizontalHeader().setSectionsMovable(True) |
203 |
self.tableWidgets[key].setSelectionMode(QAbstractItemView.SingleSelection)
|
204 |
self.tableWidgets[key].horizontalHeader().setSectionsClickable(True) |
205 |
self.tableWidgets[key].horizontalHeader().setHighlightSections(True) |
206 |
|
207 |
headers = [] |
208 |
tokens = self.columnOrder[key][0].value.split(self.delimiter) |
209 |
for token in tokens: |
210 |
header = token.split(self.delimiterCombine)
|
211 |
headers.append([header[0] if len(header) > 0 else '', header[-1] if len(header) > 1 else '']) |
212 |
|
213 |
self.tableWidgets[key].setColumnCount(len(headers)) |
214 |
self.tableWidgets[key].setHorizontalHeaderLabels([header[0] for header in headers]) |
215 |
for col in range(len(headers)): |
216 |
self.tableWidgets[key].setItem(0, col, QTableWidgetItem(headers[col][1])) |
217 |
self.tableWidgets[key].horizontalHeaderItem(col).setSizeHint(QSize(25, 25)) |
218 |
# self.tableWidgets[key].setColumnWidth(col, len(headers[col]) * 8 + 10)
|
219 |
|
220 |
self.tableWidgets[key].horizontalHeader().sectionClicked.connect(self.sections[key]) |
221 |
self.tableWidgets[key].cellClicked.connect(self.sections[key]) |
222 |
self.deleteButtons[key].clicked.connect(self.deletes[key]) |
223 |
self.addButtons[key].clicked.connect(self.adds[key]) |
224 |
self.emptyButtons[key].clicked.connect(self.emptys[key]) |
225 |
|
226 |
self.tableWidgets[key].setDragDropMode(QAbstractItemView.DropOnly)
|
227 |
self.tableWidgets[key].setAcceptDrops(True) |
228 |
self.tableWidgets[key].dropEvent = self.drops[key] |
229 |
|
230 |
# attribute list setting
|
231 |
for key in self.listWidgets.keys(): |
232 |
self.listWidgets[key].itemDoubleClicked.connect(self.items[key]) |
233 |
self.colAddButtons[key].clicked.connect(self.colAdds[key]) |
234 |
self.colEditButtons[key].clicked.connect(self.colEdits[key]) |
235 |
for header in range(1, len(columnListAll[key])): |
236 |
item = QListWidgetItem(columnListAll[key][header]) |
237 |
item.setSizeHint(QSize(25, 25)) |
238 |
self.listWidgets[key].addItem(item)
|
239 |
for logical in range(self.tableWidgets[key].columnCount()): |
240 |
if item.text() == self.tableWidgets[key].horizontalHeaderItem(logical).text(): |
241 |
# item.setBackground(self.selectionBackground)
|
242 |
self.listWidgets[key].takeItem(self.listWidgets[key].count() - 1) |
243 |
break
|
244 |
|
245 |
self.listWidgets[key].setDragDropMode(QAbstractItemView.DragDrop)
|
246 |
self.listWidgets[key].dragEnterEvent = self.dragEnterEvent |
247 |
|
248 |
self.ui.pushButtonApply.clicked.connect(self.pushButtonApplyClicked) |
249 |
self.ui.pushButtonClose.clicked.connect(self.pushButtonCloseClicked) |
250 |
self.ui.tabWidget.currentChanged.connect(self.tabchanged) |
251 |
|
252 |
'''
|
253 |
@brief clear selected colunm when tab changed
|
254 |
@author euisung
|
255 |
@date 2018.10.31
|
256 |
'''
|
257 |
|
258 |
def tabchanged(self, event): |
259 |
if self.selectedCol is not None: |
260 |
self.selectedCol[0].setCurrentCell(0, 0) |
261 |
self.selectedCol = None |
262 |
|
263 |
'''
|
264 |
@brief add column by drag and drop
|
265 |
@author euisung
|
266 |
@date 2018.10.30
|
267 |
'''
|
268 |
|
269 |
def dragEnterEvent(self, event): |
270 |
try:
|
271 |
self.dragItem = self.focusWidget().item(self.focusWidget().indexAt(event.pos()).row()).text() |
272 |
except:
|
273 |
self.dragItem = None |
274 |
# self.clearFocus()
|
275 |
|
276 |
def dropEvent(self, event, table, alist): |
277 |
if self.dragItem is None: |
278 |
return
|
279 |
visualIndex = table.horizontalHeader().visualIndex(table.indexAt(event.pos()).column()) |
280 |
item = QTableWidgetItem(self.dragItem)
|
281 |
self.listItemDoubleClicked(table, item, alist, visualIndex)
|
282 |
logicalIndex = table.horizontalHeader().logicalIndex(visualIndex) |
283 |
table.setCurrentCell(0, logicalIndex)
|
284 |
self.selectedCol = [table, logicalIndex, alist]
|
285 |
# self.update()
|
286 |
|
287 |
def lineDropEvent(self, event): |
288 |
self.dropEvent(event, self.tableWidgets[QItemDataFormatDialog.DATA_LIST[0]], |
289 |
self.listWidgets[QItemDataFormatDialog.DATA_LIST[0]]) |
290 |
|
291 |
def equipmentDropEvent(self, event): |
292 |
self.dropEvent(event, self.tableWidgets[QItemDataFormatDialog.DATA_LIST[1]], |
293 |
self.listWidgets[QItemDataFormatDialog.DATA_LIST[1]]) |
294 |
|
295 |
def valveDropEvent(self, event): |
296 |
self.dropEvent(event, self.tableWidgets[QItemDataFormatDialog.DATA_LIST[2]], |
297 |
self.listWidgets[QItemDataFormatDialog.DATA_LIST[2]]) |
298 |
|
299 |
def instrumentDropEvent(self, event): |
300 |
self.dropEvent(event, self.tableWidgets[QItemDataFormatDialog.DATA_LIST[3]], |
301 |
self.listWidgets[QItemDataFormatDialog.DATA_LIST[3]]) |
302 |
|
303 |
def noteDropEvent(self, event): |
304 |
self.dropEvent(event, self.tableWidgets[QItemDataFormatDialog.DATA_LIST[4]], |
305 |
self.listWidgets[QItemDataFormatDialog.DATA_LIST[4]]) |
306 |
|
307 |
def edit_column_clicked(self, tableName, alist, colList, history): |
308 |
'''
|
309 |
@brief edit column
|
310 |
@author euisung
|
311 |
@date 2019.03.13
|
312 |
'''
|
313 |
from ItemDataAddEditDialog import QItemDataAddEditDialog |
314 |
|
315 |
oldItem = alist.currentItem() |
316 |
if oldItem is None: |
317 |
return
|
318 |
item_data_format_dialog = QItemDataAddEditDialog(self, False, tableName, colList, history, oldItem.text()) |
319 |
isAccepted, newHistory = item_data_format_dialog.showDialog() |
320 |
if isAccepted:
|
321 |
history.append(newHistory) |
322 |
item = QListWidgetItem(newHistory[1])
|
323 |
item.setSizeHint(QSize(25, 25)) |
324 |
alist.addItem(item) |
325 |
for logical in range(alist.count()): |
326 |
if oldItem.text() == alist.item(logical).text():
|
327 |
alist.takeItem(logical) |
328 |
break
|
329 |
|
330 |
def line_edit_clicked(self): |
331 |
data_list = QItemDataFormatDialog.DATA_LIST[0]
|
332 |
self.edit_column_clicked(data_list, self.listWidgets[data_list], self.columnListAll[data_list], |
333 |
self.colHistory[data_list])
|
334 |
|
335 |
def equipment_edit_clicked(self): |
336 |
data_list = QItemDataFormatDialog.DATA_LIST[1]
|
337 |
self.edit_column_clicked(data_list, self.listWidgets[data_list], self.columnListAll[data_list], |
338 |
self.colHistory[data_list])
|
339 |
|
340 |
def valve_edit_clicked(self): |
341 |
data_list = QItemDataFormatDialog.DATA_LIST[2]
|
342 |
self.edit_column_clicked(data_list, self.listWidgets[data_list], self.columnListAll[data_list], |
343 |
self.colHistory[data_list])
|
344 |
|
345 |
def instrument_edit_clicked(self): |
346 |
data_list = QItemDataFormatDialog.DATA_LIST[3]
|
347 |
self.edit_column_clicked(data_list, self.listWidgets[data_list], self.columnListAll[data_list], |
348 |
self.colHistory[data_list])
|
349 |
|
350 |
def note_edit_clicked(self): |
351 |
data_list = QItemDataFormatDialog.DATA_LIST[4]
|
352 |
self.edit_column_clicked(data_list, self.listWidgets[data_list], self.columnListAll[data_list], |
353 |
self.colHistory[data_list])
|
354 |
|
355 |
def add_column_clicked(self, tableName, alist, colList, history): |
356 |
'''
|
357 |
@brief add column
|
358 |
@author euisung
|
359 |
@date 2019.03.13
|
360 |
'''
|
361 |
from ItemDataAddEditDialog import QItemDataAddEditDialog |
362 |
|
363 |
item_data_format_dialog = QItemDataAddEditDialog(self, True, tableName, colList, history) |
364 |
isAccepted, newHistory = item_data_format_dialog.showDialog() |
365 |
if isAccepted:
|
366 |
# print('added')
|
367 |
history.append(newHistory) |
368 |
item = QListWidgetItem(newHistory[1])
|
369 |
item.setSizeHint(QSize(25, 25)) |
370 |
alist.addItem(item) |
371 |
|
372 |
def line_add_clicked(self): |
373 |
data_list = QItemDataFormatDialog.DATA_LIST[0]
|
374 |
self.add_column_clicked(data_list, self.listWidgets[data_list], self.columnListAll[data_list], |
375 |
self.colHistory[data_list])
|
376 |
|
377 |
def equipment_add_clicked(self): |
378 |
data_list = QItemDataFormatDialog.DATA_LIST[1]
|
379 |
self.add_column_clicked(data_list, self.listWidgets[data_list], self.columnListAll[data_list], |
380 |
self.colHistory[data_list])
|
381 |
|
382 |
def valve_add_clicked(self): |
383 |
data_list = QItemDataFormatDialog.DATA_LIST[2]
|
384 |
self.add_column_clicked(data_list, self.listWidgets[data_list], self.columnListAll[data_list], |
385 |
self.colHistory[data_list])
|
386 |
|
387 |
def instrument_add_clicked(self): |
388 |
data_list = QItemDataFormatDialog.DATA_LIST[3]
|
389 |
self.add_column_clicked(data_list, self.listWidgets[data_list], self.columnListAll[data_list], |
390 |
self.colHistory[data_list])
|
391 |
|
392 |
def note_add_clicked(self): |
393 |
data_list = QItemDataFormatDialog.DATA_LIST[4]
|
394 |
self.add_column_clicked(data_list, self.listWidgets[data_list], self.columnListAll[data_list], |
395 |
self.colHistory[data_list])
|
396 |
|
397 |
'''
|
398 |
@brief add empty column
|
399 |
@author euisung
|
400 |
@date 2018.10.29
|
401 |
'''
|
402 |
|
403 |
def emptyColumnClicked(self, table, alist): |
404 |
table.setColumnCount(table.columnCount() + 1)
|
405 |
table.setHorizontalHeaderItem(table.columnCount() - 1, QTableWidgetItem(self.emptyCol)) |
406 |
table.setItem(0, table.columnCount() - 1, QTableWidgetItem('add header')) |
407 |
if self.selectedCol is not None: |
408 |
table.horizontalHeader().moveSection(table.columnCount() - 1, table.horizontalHeader().visualIndex(
|
409 |
self.selectedCol[0].currentColumn()) + 1) |
410 |
else:
|
411 |
table.horizontalHeader().moveSection(table.columnCount() - 1, 1) |
412 |
table.setCurrentCell(0, table.columnCount() - 1) |
413 |
self.selectedCol = [table, None, alist] |
414 |
|
415 |
def lineEmptyClicked(self): |
416 |
data_list = QItemDataFormatDialog.DATA_LIST[0]
|
417 |
self.emptyColumnClicked(self.tableWidgets[data_list], self.listWidgets[data_list]) |
418 |
|
419 |
def equipmentEmptyClicked(self): |
420 |
data_list = QItemDataFormatDialog.DATA_LIST[1]
|
421 |
self.emptyColumnClicked(self.tableWidgets[data_list], self.listWidgets[data_list]) |
422 |
|
423 |
def valveEmptyClicked(self): |
424 |
data_list = QItemDataFormatDialog.DATA_LIST[2]
|
425 |
self.emptyColumnClicked(self.tableWidgets[data_list], self.listWidgets[data_list]) |
426 |
|
427 |
def instrumentEmptyClicked(self): |
428 |
data_list = QItemDataFormatDialog.DATA_LIST[3]
|
429 |
self.emptyColumnClicked(self.tableWidgets[data_list], self.listWidgets[data_list]) |
430 |
|
431 |
def noteEmptyClicked(self): |
432 |
data_list = QItemDataFormatDialog.DATA_LIST[4]
|
433 |
self.emptyColumnClicked(self.tableWidgets[data_list], self.listWidgets[data_list]) |
434 |
|
435 |
'''
|
436 |
@brief save and apply all change
|
437 |
@author euisung
|
438 |
@date 2018.10.25
|
439 |
'''
|
440 |
|
441 |
def pushButtonApplyClicked(self): |
442 |
docData = AppDocData.instance() |
443 |
configs = [] |
444 |
for key in self.tableWidgets.keys(): |
445 |
# table column apply
|
446 |
addedCol = [] |
447 |
editedCol = [] |
448 |
for history in self.colHistory[key]: |
449 |
if history[0] is not None: # edit |
450 |
isNewAddedCol = False
|
451 |
for index in range(len(addedCol)): |
452 |
if addedCol[index] == history[0]: |
453 |
isNewAddedCol = True
|
454 |
addedCol[index] = history[1]
|
455 |
break
|
456 |
if not isNewAddedCol: |
457 |
editedCol.append(history) |
458 |
else: # add |
459 |
addedCol.append(history[1])
|
460 |
|
461 |
# save column order
|
462 |
value = ''
|
463 |
for col in range(self.tableWidgets[key].columnCount()): |
464 |
order = self.tableWidgets[key].horizontalHeader().logicalIndex(col)
|
465 |
if order is -1: continue |
466 |
|
467 |
col_name = self.tableWidgets[key].horizontalHeaderItem(order).text()
|
468 |
display_name = self.tableWidgets[key].item(0, order).text() |
469 |
value += col_name + self.delimiterCombine + display_name + self.delimiter |
470 |
|
471 |
value = value[:-len(self.delimiter)] |
472 |
configs.append(Config('Order', key, value))
|
473 |
|
474 |
docData.saveConfigs(configs) |
475 |
|
476 |
reply = QMessageBox.information(self, self.tr('Information'), self.tr('Save Success!'), QMessageBox.Ok, |
477 |
QMessageBox.Cancel) |
478 |
if reply == QMessageBox.Ok:
|
479 |
QDialog.accept(self)
|
480 |
|
481 |
'''
|
482 |
@brief attribure list double clicked event, add to table
|
483 |
@author euisung
|
484 |
@date 2018.10.25
|
485 |
'''
|
486 |
|
487 |
def listItemDoubleClicked(self, table, item, alist, loc=None): |
488 |
if item == None: |
489 |
return
|
490 |
for index in range(table.columnCount()): |
491 |
if item.text() == table.horizontalHeaderItem(index).text():
|
492 |
# QMessageBox.about(self, "알림", '이미 추가된 항목입니다.')
|
493 |
return
|
494 |
table.setColumnCount(table.columnCount() + 1)
|
495 |
table.setHorizontalHeaderItem(table.columnCount() - 1, QTableWidgetItem(item.text()))
|
496 |
table.setItem(0, table.columnCount() - 1, QTableWidgetItem(item.text())) |
497 |
table.horizontalHeaderItem(table.columnCount() - 1).setSizeHint(QSize(25, 25)) |
498 |
table.setColumnWidth(table.columnCount() - 1, len(item.text()) * 8 + 10) |
499 |
if loc is None: |
500 |
if self.selectedCol is None: |
501 |
table.horizontalHeader().moveSection(table.columnCount() - 1, 1) |
502 |
else:
|
503 |
table.horizontalHeader().moveSection(table.columnCount() - 1, table.horizontalHeader().visualIndex(
|
504 |
self.selectedCol[0].currentColumn()) + 1) |
505 |
else:
|
506 |
table.horizontalHeader().moveSection(table.columnCount() - 1, loc)
|
507 |
table.setCurrentCell(0, table.columnCount() - 1) |
508 |
for logical in range(alist.count()): |
509 |
if item.text() == alist.item(logical).text():
|
510 |
alist.takeItem(logical) |
511 |
break
|
512 |
|
513 |
def lineItemDoubleCliked(self, item): |
514 |
data_list = QItemDataFormatDialog.DATA_LIST[0]
|
515 |
self.listItemDoubleClicked(self.tableWidgets[data_list], item, self.listWidgets[data_list]) |
516 |
|
517 |
def equipmentItemDoubleCliked(self, item): |
518 |
data_list = QItemDataFormatDialog.DATA_LIST[1]
|
519 |
self.listItemDoubleClicked(self.tableWidgets[data_list], item, self.listWidgets[data_list]) |
520 |
|
521 |
def valveItemDoubleCliked(self, item): |
522 |
data_list = QItemDataFormatDialog.DATA_LIST[2]
|
523 |
self.listItemDoubleClicked(self.tableWidgets[data_list], item, self.listWidgets[data_list]) |
524 |
|
525 |
def instrumentItemDoubleCliked(self, item): |
526 |
data_list = QItemDataFormatDialog.DATA_LIST[3]
|
527 |
self.listItemDoubleClicked(self.tableWidgets[data_list], item, self.listWidgets[data_list]) |
528 |
|
529 |
def noteItemDoubleCliked(self, item): |
530 |
data_list = QItemDataFormatDialog.DATA_LIST[4]
|
531 |
self.listItemDoubleClicked(self.tableWidgets[data_list], item, self.listWidgets[data_list]) |
532 |
|
533 |
'''
|
534 |
@brief close without save
|
535 |
@author euisung
|
536 |
@date 2018.10.25
|
537 |
'''
|
538 |
|
539 |
def pushButtonCloseClicked(self): |
540 |
QDialog.reject(self)
|
541 |
|
542 |
'''
|
543 |
@brief key pressed event
|
544 |
@author euisung
|
545 |
@date 2018.10.25
|
546 |
'''
|
547 |
|
548 |
def keyPressEvent(self, event): |
549 |
try:
|
550 |
if event.key() == Qt.Key_Delete and self.selectedCol is not None and self.selectedCol[ |
551 |
0].columnCount() is not 1 and self.selectedCol[0].currentColumn() is not 0: |
552 |
visualIndex = self.selectedCol[0].horizontalHeader().visualIndex(self.selectedCol[0].currentColumn()) |
553 |
if self.selectedCol[0].horizontalHeaderItem( |
554 |
self.selectedCol[0].currentColumn()).text() != self.emptyCol: |
555 |
item = QListWidgetItem( |
556 |
self.selectedCol[0].horizontalHeaderItem(self.selectedCol[0].currentColumn()).text()) |
557 |
item.setSizeHint(QSize(25, 25)) |
558 |
self.selectedCol[2].addItem(item) |
559 |
# for logical in range(self.selectedCol[2].count()):
|
560 |
# if self.selectedCol[0].horizontalHeaderItem(self.selectedCol[1]).text() == self.selectedCol[2].item(logical).text():
|
561 |
# self.selectedCol[2].item(logical).setBackground(self.originBackground)
|
562 |
# break
|
563 |
self.selectedCol[0].removeColumn(self.selectedCol[0].currentColumn()) |
564 |
if visualIndex is self.selectedCol[0].columnCount(): |
565 |
logicalIndex = self.selectedCol[0].horizontalHeader().logicalIndex(visualIndex - 1) |
566 |
self.selectedCol[0].setCurrentCell(0, logicalIndex) |
567 |
self.selectedCol[1] = logicalIndex |
568 |
if self.selectedCol[0].columnCount() is 1: |
569 |
self.selectedCol = None |
570 |
else:
|
571 |
logicalIndex = self.selectedCol[0].horizontalHeader().logicalIndex(visualIndex) |
572 |
self.selectedCol[1] = logicalIndex |
573 |
self.selectedCol[0].setCurrentCell(0, logicalIndex) |
574 |
|
575 |
QDialog.keyPressEvent(self, event)
|
576 |
except Exception as ex: |
577 |
print('error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
578 |
sys.exc_info()[-1].tb_lineno))
|
579 |
from App import App |
580 |
from AppDocData import MessageType |
581 |
|
582 |
message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, |
583 |
sys.exc_info()[-1].tb_lineno)
|
584 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
585 |
return None |
586 |
|
587 |
'''
|
588 |
@brief add column by button clicked
|
589 |
@author euisung
|
590 |
@date 2018.10.25
|
591 |
'''
|
592 |
|
593 |
def addClicked(self, table, alist): |
594 |
item = alist.currentItem() |
595 |
self.listItemDoubleClicked(table, item, alist)
|
596 |
|
597 |
def lineAddClicked(self): |
598 |
data_list = QItemDataFormatDialog.DATA_LIST[0]
|
599 |
self.addClicked(self.tableWidgets[data_list], self.listWidgets[data_list]) |
600 |
|
601 |
def equipmentAddClicked(self): |
602 |
data_list = QItemDataFormatDialog.DATA_LIST[1]
|
603 |
self.addClicked(self.tableWidgets[data_list], self.listWidgets[data_list]) |
604 |
|
605 |
def valveAddClicked(self): |
606 |
data_list = QItemDataFormatDialog.DATA_LIST[2]
|
607 |
self.addClicked(self.tableWidgets[data_list], self.listWidgets[data_list]) |
608 |
|
609 |
def instrumentAddClicked(self): |
610 |
data_list = QItemDataFormatDialog.DATA_LIST[3]
|
611 |
self.addClicked(self.tableWidgets[data_list], self.listWidgets[data_list]) |
612 |
|
613 |
def noteAddClicked(self): |
614 |
data_list = QItemDataFormatDialog.DATA_LIST[4]
|
615 |
self.addClicked(self.tableWidgets[data_list], self.listWidgets[data_list]) |
616 |
|
617 |
'''
|
618 |
@brief delete column by button clicked
|
619 |
@author euisung
|
620 |
@date 2018.10.25
|
621 |
'''
|
622 |
|
623 |
def deleteClicked(self, table, alist): |
624 |
if self.selectedCol is None: |
625 |
return
|
626 |
if table.horizontalHeaderItem(table.currentColumn()).text() != self.emptyCol: |
627 |
item = QListWidgetItem(table.horizontalHeaderItem(table.currentColumn()).text()) |
628 |
item.setSizeHint(QSize(25, 25)) |
629 |
alist.addItem(item) |
630 |
# for logical in range(self.selectedCol[2].count()):
|
631 |
# if self.selectedCol[0].horizontalHeaderItem(self.selectedCol[1]).text() == self.selectedCol[2].item(logical).text():
|
632 |
# self.selectedCol[2].item(logical).setBackground(self.originBackground)
|
633 |
# break
|
634 |
table.removeColumn(table.currentColumn()) |
635 |
self.selectedCol = None |
636 |
|
637 |
def lineDeleteClicked(self): |
638 |
data_list = QItemDataFormatDialog.DATA_LIST[0]
|
639 |
self.deleteClicked(self.tableWidgets[data_list], self.listWidgets[data_list]) |
640 |
|
641 |
def equipmentDeleteClicked(self): |
642 |
data_list = QItemDataFormatDialog.DATA_LIST[1]
|
643 |
self.deleteClicked(self.tableWidgets[data_list], self.listWidgets[data_list]) |
644 |
|
645 |
def valveDeleteClicked(self): |
646 |
data_list = QItemDataFormatDialog.DATA_LIST[2]
|
647 |
self.deleteClicked(self.tableWidgets[data_list], self.listWidgets[data_list]) |
648 |
|
649 |
def instrumentDeleteClicked(self): |
650 |
data_list = QItemDataFormatDialog.DATA_LIST[3]
|
651 |
self.deleteClicked(self.tableWidgets[data_list], self.listWidgets[data_list]) |
652 |
|
653 |
def noteDeleteClicked(self): |
654 |
data_list = QItemDataFormatDialog.DATA_LIST[4]
|
655 |
self.deleteClicked(self.tableWidgets[data_list], self.listWidgets[data_list]) |
656 |
|
657 |
'''
|
658 |
@brief table section clicked event, set selected column
|
659 |
@author euisung
|
660 |
@date 2018.10.25
|
661 |
'''
|
662 |
|
663 |
def sectionClicked(self, table, logicalIndex, alist): |
664 |
if logicalIndex is not 0: |
665 |
table.setCurrentCell(0, logicalIndex)
|
666 |
|
667 |
self.selectedCol = [table, None, alist] |
668 |
|
669 |
def lineSectionClicked(self, logicalIndex): |
670 |
data_list = QItemDataFormatDialog.DATA_LIST[0]
|
671 |
self.sectionClicked(self.tableWidgets[data_list], logicalIndex, self.listWidgets[data_list]) |
672 |
|
673 |
def equipmentSectionClicked(self, logicalIndex): |
674 |
data_list = QItemDataFormatDialog.DATA_LIST[1]
|
675 |
self.sectionClicked(self.tableWidgets[data_list], logicalIndex, self.listWidgets[data_list]) |
676 |
|
677 |
def valveSectionClicked(self, logicalIndex): |
678 |
data_list = QItemDataFormatDialog.DATA_LIST[2]
|
679 |
self.sectionClicked(self.tableWidgets[data_list], logicalIndex, self.listWidgets[data_list]) |
680 |
|
681 |
def instrumentSectionClicked(self, logicalIndex): |
682 |
data_list = QItemDataFormatDialog.DATA_LIST[3]
|
683 |
self.sectionClicked(self.tableWidgets[data_list], logicalIndex, self.listWidgets[data_list]) |
684 |
|
685 |
def noteSectionClicked(self, logicalIndex): |
686 |
data_list = QItemDataFormatDialog.DATA_LIST[4]
|
687 |
self.sectionClicked(self.tableWidgets[data_list], logicalIndex, self.listWidgets[data_list]) |