프로젝트

일반

사용자정보

통계
| 개정판:

hytos / HYTOS / HYTOS / ItemPropertyTableWidget.py @ 2281dace

이력 | 보기 | 이력해설 | 다운로드 (42.6 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

    
19
from EngineeringAbstractItem import QEngineeringAbstractItem
20
from SymbolSvgItem import SymbolSvgItem
21
from EngineeringLineNoTextItem import QEngineeringLineNoTextItem
22
from EngineeringNoteItem import QEngineeringNoteItem
23
from EngineeringTextItem import QEngineeringTextItem
24
from UserInputAttribute import UserInputAttribute
25
from EngineeringSpecBreakItem import QEngineeringSpecBreakItem
26
from EngineeringErrorItem import QEngineeringErrorItem
27
from SymbolAttr import SymbolAttr
28
from AppDocData import *
29
from Drawing import Drawing
30
from enum import Enum
31

    
32
'''
33
    @brief      ItemType
34
    @author     Jeongwoo
35
    @date       2018.04.27
36
    @history    2018.05.10  Jeongwoo    Add LINE_NO
37
'''
38
class ItemType(Enum):
39
    SYMBOL = 1
40
    NOTE = 2
41
    LINE_NO = 3
42

    
43
class QCustomCheckBox(QCheckBox):
44
    def __init__(self, table, row, col):
45
        QCheckBox.__init__(self)
46
        self.table = table
47
        self.row = row
48
        self.col = col
49

    
50
    def state_changed(self, state):
51
        """ check box state is changed """
52
        if self.col == 0:
53
            '''
54
            for index in range(self.table.rowCount()):
55
                data = self.table.item(index, 1).data(Qt.UserRole) if self.table.item(index, 1) is not None else None
56
                if data and type(data) is SymbolAttr:
57
                    widget = self.table.cellWidget(index, 3)
58
                    if widget:
59
                        widget.setEnabled(False) if state else widget.setEnabled(True)
60
                    data.Freeze = self.isChecked()
61

62
                    item = self.table.item(index, 3)
63
                    if item:
64
                        item.setFlags(Qt.ItemIsEnabled) if state else item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsEditable|Qt.ItemIsSelectable)
65
                        item.setBackground(Qt.lightGray) if state else item.setBackground(Qt.white)
66
            '''
67

    
68
            widget = self.table.cellWidget(self.row, 3)
69
            if widget:
70
                widget.setEnabled(False) if state else widget.setEnabled(True)
71

    
72
            data = self.table.item(self.row, 1).data(Qt.UserRole)
73
            if data: data.Freeze = self.isChecked()
74

    
75
            item = self.table.item(self.row, 3)
76
            if item:
77
                item.setFlags(Qt.ItemIsEnabled) if state else item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsEditable|Qt.ItemIsSelectable)
78
                item.setBackground(Qt.lightGray) if state else item.setBackground(Qt.white)
79
        elif self.col == 3:
80
            cell = self.table.item(self.row, 1)
81
            if cell:
82
                data = cell.data(Qt.UserRole)
83
                if data is not None:
84
                    if self.table._item: self.table._item.set_property(data.Attribute, self.isChecked())
85

    
86
class QItemPropertyTableWidget(QTableWidget):
87
    def __init__(self, mainWindow):
88
        QTableWidget.__init__(self)
89
        self._item = None
90
        self.mainWindow = mainWindow
91

    
92
        self.cellChanged.connect(self.cellChangedEvent)
93
        self.cellDoubleClicked.connect(self.cellDoubleClickedEvent)
94

    
95
    '''
96
        @brief      Initialize TableWidget
97
        @author     Jeongwoo
98
        @date       18.04.13
99
        @history    humkyung 2018.07.08 show column header
100
    '''
101
    def initItemPropertyTableWidget(self, item=None):
102

    
103
        if item is None:
104
            self.horizontalHeader().hide()
105
            return
106

    
107
        self.horizontalHeader().show()
108

    
109
        category = item.category
110

    
111
        if category == 'Equipment - [ Pressure Drop ]':
112
            self.setColumnCount(2)
113
            self.setHorizontalHeaderLabels(['P. Drop', 'Elevation'])
114
            self.setColumnWidth(0, 80)
115
            self.setColumnWidth(1, 80)
116
        elif category == 'Equipment - [ Pressurized ]':
117
            self.setColumnCount(3)
118
            self.setHorizontalHeaderLabels(['Index', 'P. Drop', 'Elevation'])
119
            self.setColumnWidth(0, 70)
120
            self.setColumnWidth(1, 70)
121
            self.setColumnWidth(2, 10)
122
        elif category == 'Equipment - [ Rotating ]':
123
            self.setColumnCount(2)
124
            self.setHorizontalHeaderLabels(['P. Drop', 'Elevation'])
125
            self.setColumnWidth(0, 80)
126
            self.setColumnWidth(1, 80)
127
        elif category == 'Instrument':
128
            self.setColumnCount(2)
129
            self.setHorizontalHeaderLabels(['P. Drop', 'Elevation'])
130
            self.setColumnWidth(0, 80)
131
            self.setColumnWidth(1, 80)
132

    
133
        self.verticalHeader().hide()
134
        self.horizontalHeader().setStretchLastSection(True)
135
        #self.verticallHeader().setDefaultSectionSize(50)
136

    
137
    '''
138
        @brief  show item's property
139
        @author humkyung
140
        @date   2018.07.03
141
        @history    euisung  2019.01.15     add icon image to line item
142
    '''
143
    def show_item_property(self, item):
144
        try:
145
            from PyQt5 import QtGui
146
            from SymbolAttr import SymbolAttr
147
            from EngineeringStreamlineItem import QEngineeringStreamlineItem
148

    
149
            self._item = item
150

    
151
            self.blockSignals(True)
152

    
153
            if type(item) is QEngineeringStreamlineItem:
154
                self.initItemPropertyTableWidget()
155
                self.initTitleCell(item)
156
                self.initContentsCell()
157
            elif issubclass(type(item), SymbolSvgItem):                
158
                self.onSymbolClicked(item)
159
            elif type(item) is QEngineeringLineNoTextItem:
160
                self.onLineNoClicked(item)
161
            elif type(item) is QEngineeringNoteItem:
162
                noteContentsList = item.findNoteContents(item.text())
163
                self.onNoteClicked(item.text(), noteContentsList)
164
            elif issubclass(type(item), QEngineeringTextItem):
165
                self.onTextClicked(item)
166
            elif type(item) is QEngineeringVendorItem:
167
                self.onVendorClicked(item)
168
            elif item is None:
169
                self.setRowCount(0)
170
        except Exception as ex:
171
            from App import App 
172

    
173
            message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
174
            App.mainWnd().addMessage.emit(MessageType.Error, message)
175
        finally:
176
            self.blockSignals(False)
177

    
178
    
179
        
180
    '''
181
        @brief      Slot to accept item click event
182
        @author     Jeongwoo
183
        @date       18.04.13
184
        @history    humkyung 2018.04.17 check if given symbol type is SymbolSvgItem
185
    '''
186
    @pyqtSlot(SymbolSvgItem)
187
    def onSymbolClicked(self, symbol):
188
        try:
189
            self.blockSignals(True)
190
            if issubclass(type(symbol), SymbolSvgItem):
191
                self._item = symbol
192
                self.symbolChanged(symbol)
193
            elif type(symbol) is QEngineeringLineNoTextItem:
194
                self.lineNoChanged(symbol)
195
        finally:
196
            self.blockSignals(True)
197

    
198
    '''
199
        @brief      show drawing' attributes
200
        @author     humkyung 
201
        @date       2018.07.07
202
    '''
203
    @pyqtSlot(Drawing)
204
    def onDrawingClicked(self, drawing):
205
        try:
206
            self.blockSignals(True)
207
            self.setRowCount(len(drawing.attrs))
208

    
209
            row = 0
210
            for attr in drawing.attrs:
211
                name = attr[0]
212
                item = QTableWidgetItem(name)
213
                item.setFlags(Qt.ItemIsEnabled)
214
                item.setBackground(Qt.lightGray)
215
                self.setItem(row, 0, item)
216

    
217
                value = attr[1]
218
                item = QTableWidgetItem(value)
219
                item.setFlags(Qt.ItemIsEnabled)
220
                self.setItem(row, 1, item)
221

    
222
                row = row + 1
223
        finally:
224
            self.blockSignals(False)
225

    
226
    def onVendorClicked(self, item):
227
        from SymbolAttr import SymbolAttr
228

    
229
        try:
230
            self.blockSignals(True)
231
            self.initTitleCell(item)
232

    
233
            self.setItem(0, 3, QTableWidgetItem(str(self._item.uid)))
234

    
235
            self.show_item_properties(item)
236
        finally:
237
            self.blockSignals(False)
238

    
239
    def onTextClicked(self, item):
240
        from SymbolAttr import SymbolAttr
241

    
242
        try:
243
            self.blockSignals(True)
244
            self.initTitleCell(item)
245

    
246
            self.setItem(0, 3, QTableWidgetItem(str(self._item.uid)))
247

    
248
            owner_item = QTableWidgetItem('{}'.format('None' if self._item.owner is None else str(self._item.owner)))
249
            owner_item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable)
250
            self.setItem(1, 3, owner_item)
251

    
252
            """ show icon item """
253
            attr = SymbolAttr()
254
            attr.AttributeType = "OWNER"
255
            self.show_icon_item(1, 2, attr)
256
            self.item(1, 1).setData(Qt.UserRole, attr)
257

    
258
            self.setItem(2, 3, QTableWidgetItem(self._item.type))
259
            self.setItem(3, 3, QTableWidgetItem(self._item.text()))
260
        finally:
261
            self.blockSignals(False)
262

    
263
    '''
264
        @brief      Slot to accept Note item click event
265
        @author     Jeongwoo
266
        @date       18.04.27
267
        @history    humkyung 2018.07.08 change method name to onNoteClicked
268
    '''
269
    @pyqtSlot(str, dict)
270
    def onNoteClicked(self, noteNoStr, noteContentsList):
271
        try:
272
            self.blockSignals(True)
273
            self.noteChanged(noteNoStr, noteContentsList)
274
        finally:
275
            self.blockSignals(False)
276

    
277
    '''
278
        @brief      Slot to accept Line No Item Click event
279
        @author     Jeongwoo
280
        @date       18.05.10
281
        @hisotry    humkyung 2018.07.08 change method name to onLineNoClicked
282
    '''
283
    @pyqtSlot(QEngineeringAbstractItem)
284
    def onLineNoClicked(self, item):
285
        try:
286
            self.blockSignals(True)
287
            self.lineNoChanged(item)
288
        finally:
289
            self.blockSignals(False)
290
        
291
    '''
292
        @brief      Reset table with new SymbolSvgItem
293
        @author     Jeongwoo
294
        @date       18.04.13
295
        @history    .
296
    '''
297
    def symbolChanged(self, item):
298
        self.initItemPropertyTableWidget(item)
299
        #self.initTitleCell(item)
300
        self.initContentsCell()
301

    
302
    '''
303
        @brief      Reset table with note info
304
        @author     Jeongwoo
305
        @date       18.04.27
306
    '''
307
    def noteChanged(self, noteNoStr, noteContentsList):
308
        self.initNoteCell(noteNoStr, noteContentsList)
309

    
310
    '''
311
        @brief      Reset table with line no item
312
        @author     Jeongwoo
313
        @date       18.05.10
314
    '''
315
    def lineNoChanged(self, item):
316
        from EngineeringRunItem import QEngineeringRunItem
317

    
318
        if type(item) is QEngineeringLineNoTextItem:
319
            self.initTitleCell(item)
320
            self.initLineNoCell(item)
321
        elif type(item) is QEngineeringRunItem:
322
            self.initLineRunCell(item)
323

    
324
        """ show tooltip """
325
        for index in range(self.rowCount()):
326
            item = self.item(index, 1)
327
            if item is not None:
328
                item.setToolTip(item.text())
329

    
330
    '''
331
        @brief      Initialize Title Cell
332
        @author     Jeongwoos
333
        @date       18.04.13
334
        @history    Jeongwoo 2018.04.27 Add if-statement by ItemType
335
                    Jeongwoo 2018.05.10 Add if-statement LINE_NO ItemType
336
                    humkyung 2018.08.15 add combobox for line type
337
    '''
338
    def initTitleCell(self, item):
339
        from LineTypeConditions import LineTypeConditions
340
        from EngineeringStreamlineItem import QEngineeringStreamlineItem
341

    
342
        try:
343

    
344
            #self.clear()
345
            #self.setHorizontalHeaderLabels(['', self.tr('Name'), '', self.tr('Value')])
346
            #self.setColumnWidth(0, 20)
347
            #self.setColumnWidth(1, 80)
348
            #self.setColumnWidth(2, 20)
349
            if type(item) is QEngineeringStreamlineItem:
350
                self.setRowCount(7)
351
                self.setItem(0, 1, QTableWidgetItem(self.tr("UID")))
352
                self.setItem(1, 1, QTableWidgetItem(self.tr("Name")))
353
                self.setItem(2, 1, QTableWidgetItem(self.tr("Type")))
354
                self.setItem(3, 1, QTableWidgetItem(self.tr("Angle")))
355
                self.setItem(4, 1, QTableWidgetItem(self.tr("Origin")))
356
                self.setItem(5, 1, QTableWidgetItem(self.tr("OWNER")))
357
                self.setItem(6, 1, QTableWidgetItem(self.tr("Set Specs")))
358
            elif type(item) is QEngineeringErrorItem:
359
                self.setRowCount(7)
360
                self.setItem(0, 1, QTableWidgetItem(self.tr("UID")))
361
                self.setItem(1, 1, QTableWidgetItem(self.tr("Name")))
362
                self.setItem(2, 1, QTableWidgetItem(self.tr("Type")))
363
                self.setItem(3, 1, QTableWidgetItem(self.tr("Angle")))
364
                self.setItem(4, 1, QTableWidgetItem(self.tr("Origin")))
365
                self.setItem(5, 1, QTableWidgetItem(self.tr("OWNER")))
366
                self.setItem(6, 1, QTableWidgetItem(self.tr("Message")))
367
            elif issubclass(type(item), SymbolSvgItem):
368
                self.setRowCount(6)
369
                self.setItem(0, 1, QTableWidgetItem(self.tr("UID")))
370
                self.setItem(1, 1, QTableWidgetItem(self.tr("Name")))
371
                self.setItem(2, 1, QTableWidgetItem(self.tr("Type")))
372
                self.setItem(3, 1, QTableWidgetItem(self.tr("Angle")))
373
                self.setItem(4, 1, QTableWidgetItem(self.tr("Origin")))
374
                self.setItem(5, 1, QTableWidgetItem(self.tr("OWNER")))
375
            elif type(item) is QEngineeringNoteItem:
376
                self.setRowCount(2)
377
                self.setItem(0, 1, QTableWidgetItem(self.tr("Note No")))
378
                self.setItem(1, 1, QTableWidgetItem(self.tr("Desc.")))
379
            elif type(item) is QEngineeringLineNoTextItem:
380
                self.setRowCount(1)
381
                self.setItem(0, 1, QTableWidgetItem(self.tr("UID")))
382
            elif type(item) is QEngineeringLineItem:
383
                self.setRowCount(5)
384
                self.setItem(0, 1, QTableWidgetItem(self.tr('UID')))
385
                self.setItem(1, 1, QTableWidgetItem(self.tr('OWNER')))
386
                widgetItem = QTableWidgetItem(self.tr("Type"))
387
                widgetItem.setData(Qt.UserRole, item)
388
                self.setItem(2, 1, widgetItem)
389
                self._lineTypeComboBox = QComboBox(self)
390
                self._lineTypeComboBox.tag = widgetItem
391
                for lineType in LineTypeConditions.items():
392
                    self._lineTypeComboBox.addItem(lineType.name)
393
                self.setCellWidget(2, 3, self._lineTypeComboBox)
394
                self._lineTypeComboBox.setCurrentText(item.lineType)
395
                self._lineTypeComboBox.currentIndexChanged.connect(self.onLineTypeChanged)
396
            elif type(item) is QEngineeringVendorItem:
397
                self.setRowCount(1)
398
                self.setItem(0, 1, QTableWidgetItem(self.tr("UID")))
399
            #else:
400
            #    self.setRowCount(4)
401
            #    self.setItem(0, 1, QTableWidgetItem(self.tr("UID")))
402
            #    self.setItem(1, 1, QTableWidgetItem(self.tr("OWNER")))
403
            #    self.setItem(2, 1, QTableWidgetItem(self.tr("Type")))
404
            #    self.setItem(3, 1, QTableWidgetItem(self.tr("Text")))
405

    
406
            for index in range(self.rowCount()):
407
                item = self.item(index, 1)
408
                if item is not None:
409
                    item.setFlags(Qt.ItemIsEnabled)
410
                    item.setBackground(Qt.lightGray)
411
        except Exception as ex:
412
            from App import App 
413

    
414
            message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
415
            App.mainWnd().addMessage.emit(MessageType.Error, message)
416

    
417
    '''
418
        @brief  change selected lines' type by selected line type
419
        @author humkyung
420
        @date   2018.08.15
421
    '''
422
    def onLineTypeChanged(self, param):
423
        lineType = self._lineTypeComboBox.itemText(param)
424
        data = self._lineTypeComboBox.tag.data(Qt.UserRole)
425
        if type(data) is QEngineeringLineItem:
426
            self.changeConnectedLineType(data, lineType)
427

    
428
    def changeConnectedLineType(self, line, lineType):
429
        line.lineType = lineType
430
        if type(line.connectors[0].connectedItem) is QEngineeringLineItem and \
431
                (line.connectors[0].connectedItem.connectors[0].connectedItem is line or line.connectors[0].connectedItem.connectors[1].connectedItem is line) and \
432
                line.connectors[0].connectedItem.lineType is not lineType:
433
            self.changeConnectedLineType(line.connectors[0].connectedItem, lineType)
434
        if type(line.connectors[1].connectedItem) is QEngineeringLineItem and \
435
                (line.connectors[1].connectedItem.connectors[0].connectedItem is line or line.connectors[1].connectedItem.connectors[1].connectedItem is line) and \
436
                line.connectors[1].connectedItem.lineType is not lineType:
437
            self.changeConnectedLineType(line.connectors[1].connectedItem, lineType)
438

    
439
    def show_icon_item(self, row, col, prop):
440
        """ show icon item on grid """
441
        from PyQt5 import QtGui
442

    
443
        if prop.is_selectable or prop.AttributeType == 'OWNER' or prop.AttributeType == 'CONN':
444
            icon = QtGui.QIcon()
445
            icon.addPixmap(QtGui.QPixmap(":/newPrefix/doubleclick.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
446
            icon_item = QTableWidgetItem('')
447
            icon_item.setFlags(Qt.ItemIsEnabled)
448
            icon_item.setIcon(icon)
449
            self.setItem(row, col, icon_item)
450
        elif prop.AttributeType == "String":
451
            icon = QtGui.QIcon()
452
            icon.addPixmap(QtGui.QPixmap(":/newPrefix/type.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
453
            icon_item = QTableWidgetItem()
454
            icon_item.setIcon(icon)
455
            self.setItem(row, col, icon_item)
456
        else:
457
            item = QTableWidgetItem()
458
            item.setFlags(Qt.ItemIsEditable)
459
            self.setItem(row, col, item)
460

    
461
    def show_item_properties(self, item):
462
        """ show item properties on grid """
463
        from PyQt5 import QtGui
464

    
465
        row = self.rowCount()
466
        if hasattr(item, '_properties'):
467
            self.setRowCount(row + len(item.properties))
468

    
469
            for prop,value in item.properties.items():
470
                try:
471
                    """ show freeze state """
472
                    checkbox = QCustomCheckBox(self, row, 0)
473
                    checkbox.setChecked(prop.Freeze)
474
                    checkbox.stateChanged.connect(checkbox.state_changed)
475
                    self.setCellWidget(row, 0, checkbox)
476

    
477
                    """ show property name """
478
                    key_item = QTableWidgetItem(prop.DisplayAttribute if prop.DisplayAttribute else prop.Attribute)
479
                    key_item.setFlags(Qt.ItemIsEnabled)
480
                    key_item.setBackground(Qt.lightGray)
481
                    key_item.setData(Qt.UserRole, prop)
482
                    self.setItem(row, 1, key_item)
483

    
484
                    """ show icon item """
485
                    self.show_icon_item(row, 2, prop)
486

    
487
                    """ show property value """
488
                    if prop.is_selectable:
489
                        value_item = QTableWidgetItem(str(value.uid) if hasattr(value, 'uid') else value)
490
                        value_item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable)
491
                        self.setItem(row, 3, value_item)
492
                    else:
493
                        if prop.AttributeType == 'Boolean':
494
                            self.checkbox_cell = QCustomCheckBox(self, row, 3)
495
                            self.checkbox_cell.setChecked(True if value and str(value) == 'True' else False)
496
                            self.checkbox_cell.stateChanged.connect(self.checkbox_cell.state_changed)
497
                            #if prop.Attribute == 'Freeze': self.checkbox_cell.stateChanged.connect(item.freeze_item.update_freeze)
498
                            self.setCellWidget(row, 3, self.checkbox_cell)
499
                        else:
500
                            value_item = QTableWidgetItem(value if value else '')
501
                            value_item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable|Qt.ItemIsEditable)
502
                            self.setItem(row, 3, value_item)
503

    
504
                    checkbox.state_changed(checkbox.isChecked())
505
                    
506
                    row = row + 1
507
                except Exception as ex:
508
                    from App import App 
509

    
510
                    message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
511
                    App.mainWnd().addMessage.emit(MessageType.Error, message)
512

    
513
    def show_item_attributes(self, item):
514
        """ show item's attributes on grid """
515
        from PyQt5 import QtGui
516

    
517
        row = self.rowCount()
518
        attrs = item.getAttributes()
519

    
520
        # display attributes of symbol
521
        if attrs is not None:
522
            self.setRowCount(row + len(attrs))
523

    
524
            for key,value in attrs.items():
525
                try:
526
                    """ show freeze state """
527
                    checkbox = QCustomCheckBox(self, row, 0)
528
                    checkbox.setChecked(key.Freeze)
529
                    checkbox.stateChanged.connect(checkbox.state_changed)
530
                    self.setCellWidget(row, 0, checkbox)
531

    
532
                    """ show property name """
533
                    key_item = QTableWidgetItem(key.DisplayAttribute if key.DisplayAttribute else key.Attribute)
534
                    key_item.setBackground(Qt.lightGray)
535
                    key_item.setData(Qt.UserRole, key)
536
                    self.setItem(row, 1, key_item)
537

    
538
                    """ show icon item """
539
                    self.show_icon_item(row, 2, key)
540

    
541
                    value_item = QTableWidgetItem(str(value))
542
                    value_item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable|Qt.ItemIsEditable)
543

    
544
                    if type(item) is QEngineeringSpecBreakItem:
545
                        if key.Attribute == 'UpStream' or key.Attribute == 'DownStream':
546
                            UpDownItem = QTableWidgetItem('{}'.format('None' if value is None else value))
547
                            self.setItem(row, 3, UpDownItem)
548
                        elif key.AttributeType == 'Spec':
549
                            self.setItem(row, 3, QTableWidgetItem(key.Attribute))
550
                    else:
551
                        self.setItem(row, 3, value_item)
552

    
553
                    checkbox.state_changed(checkbox.isChecked())
554

    
555
                    row = row + 1
556
                except Exception as ex:
557
                        from App import App 
558

    
559
                        message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
560
                        App.mainWnd().addMessage.emit(MessageType.Error, message)
561

    
562
    def show_item_connectors(self, item):
563
        """ show items' connectors on grid """
564
        from PyQt5 import QtGui
565
        from SymbolAttr import SymbolAttr
566

    
567
        row = 0 #self.rowCount()
568
        self.setRowCount(row + len(item.connectors))
569
        
570
        count = 1
571
        for connector in item.connectors:
572
            connector_item = QTableWidgetItem('{}'.format(count))
573
            connector_item.setFlags(Qt.ItemIsEnabled)
574
            connector_item.setBackground(Qt.lightGray)
575
            connector_item.setTextAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
576
            self.setItem(row, 0, connector_item)
577

    
578
            #attr = SymbolAttr()
579
            #attr.AttributeType = "CONN"
580
            #attr.AttrAt = count
581
            #connector_item.setData(Qt.UserRole, attr)
582

    
583
            """ show icon item """
584
            #self.show_icon_item(row, 2, attr)
585

    
586
            #connector_item = QTableWidgetItem('{}'.format('None' if connector.connectedItem is None else str(connector.connectedItem)))
587
            #connector_item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable)
588
            #self.setItem(row, 3, connector_item)
589
            
590
            row = row + 1
591
            count = count + 1
592

    
593
    '''
594
        @brief      Initialize Contents Cell
595
        @author     Jeongwoo
596
        @date       18.04.13
597
        @history    humkyung 2018.06.14 display symbol attributes 
598
                    humkyung 2018.07.05 display connectivity
599
                    euisung  2019.01.15 edit specbreak
600
    '''
601
    def initContentsCell(self):
602
        from PyQt5 import QtGui
603
        from SymbolAttr import SymbolAttr
604

    
605
        try:
606
            if self._item is not None and issubclass(type(self._item), SymbolSvgItem):
607
                docData = AppDocData.instance()
608

    
609
                '''
610
                self.setItem(0, 3, QTableWidgetItem(str(self._item.uid)))
611
                self.setItem(1, 3, QTableWidgetItem(self._item.name))
612
                self.setItem(2, 3, QTableWidgetItem(self._item.type))
613
                self.setItem(3, 3, QTableWidgetItem(str(round(math.degrees(self._item.angle)))))
614
                self.setItem(4, 3, QTableWidgetItem(str(self._item.origin)))
615
                owner_item = QTableWidgetItem('{}'.format('None' if self._item.owner is None else str(self._item.owner)))
616
                self.setItem(5, 3, owner_item)
617

618
                for index in range(self.rowCount()):
619
                    item = self.item(index, 3)
620
                    if item is not None:
621
                        item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable)
622

623
                """ show icon item """
624
                attr = SymbolAttr()
625
                attr.AttributeType = "OWNER"
626
                self.show_icon_item(5, 2, attr)
627
                self.item(5, 1).setData(Qt.UserRole, attr)
628

629
                #if type(self._item) is not QEngineeringSpecBreakItem and type(self._item) is not QEngineeringErrorItem:
630
                    #self.show_item_properties(self._item)
631

632
                if type(self._item) is QEngineeringSpecBreakItem:
633
                    row = self.rowCount()
634
                    setSpecsItem = QTableWidgetItem('Open')
635
                    icon = QtGui.QIcon()
636
                    icon.addPixmap(QtGui.QPixmap(":/newPrefix/doubleclick.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
637
                    setSpecsItem.setIcon(icon)
638
                    self.setItem(row - 1, 2, setSpecsItem)
639

640
                if type(self._item) is QEngineeringErrorItem:
641
                    errType = 'None'
642
                    if type(self._item.parent) is QEngineeringLineItem:
643
                        errType = 'line'
644
                    elif issubclass(type(self._item.parent), SymbolSvgItem):
645
                        errType = 'symbol'
646
                    self.setItem(2, 3, QTableWidgetItem(errType))
647
                    self.setItem(5, 3, QTableWidgetItem(str(self._item.parent.uid)))
648
                    self.setItem(6, 3, QTableWidgetItem(self._item.msg))
649

650
                self.show_item_attributes(self._item)
651
                '''
652
                self.show_item_connectors(self._item)
653
                
654
                for index in range(self.rowCount()):
655
                    item = self.item(index, 3)
656
                    if item is not None: item.setToolTip(item.text())
657
            elif self._item is not None and type(self._item) is QEngineeringLineItem:
658
                self.setItem(0, 3, QTableWidgetItem(str(self._item.uid)))
659

    
660
                """ show icon item """
661
                attr = SymbolAttr()
662
                attr.AttributeType = "OWNER"
663
                self.show_icon_item(1, 2, attr)
664
                self.item(1, 1).setData(Qt.UserRole, attr)
665

    
666
                owner_item = QTableWidgetItem('{}'.format('None' if self._item.owner is None else str(self._item.owner)))
667
                self.setItem(1, 3, owner_item)
668

    
669
                self.show_item_properties(self._item)
670

    
671
                pt = self._item.startPoint()
672
                key_item = QTableWidgetItem(self.tr("Start"))
673
                key_item.setFlags(Qt.ItemIsEnabled)
674
                key_item.setBackground(Qt.lightGray)
675
                self.setItem(3, 1, key_item)
676
                self.setItem(3, 3, QTableWidgetItem('({},{})'.format(pt[0], pt[1])))
677
                pt = self._item.endPoint()
678
                key_item = QTableWidgetItem(self.tr("End"))
679
                key_item.setFlags(Qt.ItemIsEnabled)
680
                key_item.setBackground(Qt.lightGray)
681
                self.setItem(4, 1, key_item)
682
                self.setItem(4, 3, QTableWidgetItem('({},{})'.format(pt[0], pt[1])))
683

    
684
                self.show_item_attributes(self._item)
685
                self.show_item_connectors(self._item)
686
            else:
687
                self.setRowCount(0)
688
            
689
        except Exception as ex:
690
            from App import App 
691

    
692
            message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
693
            App.mainWnd().addMessage.emit(MessageType.Error, message)
694

    
695
    '''
696
        @brief      combobox change event
697
        @author     kyouho
698
        @date       2018.08.28
699
    '''
700
    def upStreamChanged(self, text):
701
        if self._item is not None:
702
            find = False
703
            for index in range(len(self._item.attrs)):
704
                if type(self._item.attrs[index]) is tuple and self._item.attrs[index][0] == 'Up Stream':
705
                    self._item.attrs[index] = (self._item.attrs[index][0], text)
706
                    find = True
707
                    break
708
            
709
            if not find:
710
                self._item.attrs.append(('Up Stream', text))
711

    
712
    '''
713
        @brief      combobox change event
714
        @author     kyouho
715
        @date       2018.08.28
716
    '''
717
    def downStreamChanged(self, text):
718
        if self._item is not None:
719
            find = False
720
            for index in range(len(self._item.attrs)):
721
                if type(self._item.attrs[index]) is tuple and self._item.attrs[index][0] == 'Down Stream':
722
                    self._item.attrs[index] = (self._item.attrs[index][0], text)
723
                    find = True
724
                    break
725
            
726
            if not find:
727
                self._item.attrs.append(('Down Stream', text))
728

    
729
    '''
730
        @brief      Initialize Note Contents Cell
731
        @author     Jeongwoo
732
        @date       18.04.27
733
    '''
734
    def initNoteCell(self, noteNoStr, noteContentsList):
735
        self.setRowCount(0)
736

    
737
        for key in noteContentsList:
738
            row = self.rowCount()
739
            self.setRowCount(row + len(noteContentsList[key]))
740
            item = QTableWidgetItem(key)
741
            self.setItem(row, 1, item)
742

    
743
            for index in range(len(noteContentsList[key])):
744
                self.setItem(row, 3, QTableWidgetItem(noteContentsList[key][index]))
745
                row = row + 1
746

    
747
        for index in range(self.rowCount()):
748
            item = self.item(index, 1)
749
            if item is not None:
750
                item.setFlags(Qt.ItemIsEnabled)
751
                item.setBackground(Qt.lightGray)
752

    
753
    '''
754
        @brief      Initialize Line No Contents Cell
755
        @author     Jeongwoo
756
        @date       18.05.10
757
        @history    humkyung 2018.07.20 display combobox when key is 'Stream No'
758
    '''
759
    def initLineNoCell(self, lineNoItem):
760
        appDocData = AppDocData.instance()
761
        configs = appDocData.getConfigs('Line No', 'Configuration')
762
        configs = configs[0].value.split('"-"')
763

    
764
        item = QTableWidgetItem(str(lineNoItem.uid))
765
        item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable)
766
        self.setItem(0, 3, item)
767

    
768
        self.show_item_properties(lineNoItem)
769
        
770
        row = self.rowCount()
771
        attrs = lineNoItem.getAttributes()
772
        self.setRowCount(row + len(attrs))
773
        if attrs is not None:
774
            for key in attrs.keys():
775
                item = QTableWidgetItem(key.DisplayAttribute if key.DisplayAttribute else key.Attribute)
776
                item.setFlags(Qt.ItemIsEnabled)
777
                item.setBackground(Qt.lightGray)
778
                item.tag = key
779
                self.setItem(row, 1, item)
780

    
781
                """ show icon item """
782
                self.show_icon_item(row, 2, key)
783

    
784
                # value cell
785
                value = attrs[key]
786
                valueCell = QTableWidgetItem(value)
787

    
788
                # UID로 확인
789
                keyStr = appDocData.getLinePropertiesByUID(key.UID)
790
                if keyStr:
791
                    # editable value cell
792
                    if keyStr[0].AttributeType == 'String':
793
                        pass
794
                        #self.attrValueList.append((valueCell, key.Attribute))
795
                        #self.stringCell.append(valueCell)
796
                    if keyStr[0].UID in configs: valueCell.setFlags(Qt.ItemIsEnabled)
797
                else:
798
                    valueCell.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable)
799
                 
800
                if key.Attribute.upper() == 'STREAM_NO':
801
                    self.streamNoComboBox = QComboBox()
802
                    self.streamNoComboBox.tag = key
803
                    self.streamNoComboBox.currentIndexChanged.connect(self.onStreamNoChanged)
804
                    
805
                    streamNos = sorted(list(appDocData.hmbTable.streamNos()))
806
                    for streamNo in streamNos:
807
                        self.streamNoComboBox.addItem(streamNo)
808
                    self.setCellWidget(row, 3, self.streamNoComboBox)
809
                    self.streamNoComboBox.setCurrentText(value)
810
                    
811
                self.setItem(row, 3, valueCell)
812

    
813
                row = row + 1
814

    
815
    '''
816
        @brief  change selected lines' stream no by selected stream no
817
        @author humkyung
818
        @date   2018.07.20
819
    '''
820
    def onStreamNoChanged(self, param):
821
        items = self.mainWindow.graphicsView.scene.selectedItems()
822
        if items is not None and len(items) == 1:
823
            if type(items[0]) is QEngineeringLineNoTextItem:
824
                stream_no = self.streamNoComboBox.itemText(param)
825
                items[0].set_attrib(self.streamNoComboBox.tag, stream_no)
826
                return
827

    
828
    '''
829
        @brief      Initialize Run Contents Cell
830
        @author     humkyung 
831
        @date       2018.05.27
832
    '''
833
    def initLineRunCell(self, item):
834
        self.setRowCount(1)
835

    
836
        lineTypeItem = QTableWidgetItem(self.tr("Line Type"))
837
        lineTypeItem.setBackground(Qt.lightGray)
838
        lineTypeItem.setFlags(Qt.ItemIsEnabled)
839
        self.setItem(0, 1, lineTypeItem)
840

    
841
    '''
842
        @brief      Key Press Event
843
        @author     kyouho
844
        @date       2018.07.19
845
    '''
846
    def keyPressEvent(self, event):
847
        from SymbolAttr import SymbolAttr
848

    
849
        if event.key() == Qt.Key_Delete:
850
            items = self.mainWindow.graphicsView.scene.selectedItems()
851
            selectedIndexes = self.selectedIndexes()
852
            if selectedIndexes[0].column() == 3 and self.item(selectedIndexes[0].row(), 1).text() == 'OWNER':
853
                items[0].owner = None
854
                self.show_item_property(items[0])
855
            #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:
856
            #    if selectedIndexes[0].column() == 3:
857
            #        attributeStr = self.item(selectedIndexes[0].row(), 1).text()
858
            #        items[0].removeSelfAttr(attributeStr)
859
            #        self.mainWindow.refreshResultPropertyTableWidget()
860
            elif len(items) == 1 and len(selectedIndexes) == 1 and (type(items[0]) is QEngineeringLineItem or issubclass(type(items[0]), SymbolSvgItem)):
861
                key_cell = self.item(selectedIndexes[0].row(), 1)
862
                data = key_cell.data(Qt.UserRole)
863
                if selectedIndexes[0].column() == 3 and key_cell.text().find('CONN') is 0:
864
                    selectedUID = self.item(selectedIndexes[0].row(), 1).text()
865
                    connNum = int(key_cell.text().replace('CONN', ''))
866
                    items[0].connectors[connNum - 1].connectedItem = None
867
                    self.show_item_property(items[0])
868

    
869
                    for sceneItem in self.mainWindow.graphicsView.scene.items():
870
                        if hasattr(sceneItem, 'uid') and str(sceneItem.uid) == selectedUID and hasattr(sceneItem, 'connectors'):
871
                            for sceneConnector in sceneItem.connectors:
872
                                if sceneConnector.connectedItem is not None and items[0].uid == sceneConnector.connectedItem.uid:
873
                                    sceneConnector.connectedItem = None
874
                elif selectedIndexes[0].column() == 3 and data and type(data) is SymbolAttr:
875
                    for _attr,_value in items[0].attrs.items():
876
                        if str(_attr.UID) == str(data.UID):
877
                            items[0].remove_assoc_item(_attr.AssocItem)
878
                            if type(_attr.AssocItem) is QEngineeringTextItem:
879
                                _attr.AssocItem.owner = None
880
                            _attr.AssocItem = None
881
                            items[0].attrs[_attr] = ''
882
                            self.show_item_property(items[0])
883
                            break
884
            elif len(items) == 1 and len(selectedIndexes) == 1 and type(items[0]) is QEngineeringSpecBreakItem:
885
                keyCell = self.item(selectedIndexes[0].row(), 1)
886
                if selectedIndexes[0].column() == 3 and (keyCell.text() == 'UpStream' or keyCell.text() == 'DownStream'):
887
                    for attr in items[0].attrs.keys():
888
                        if attr.Attribute == keyCell.text():
889
                            items[0].attrs[attr] = None
890
                    self.show_item_property(items[0])
891
        elif (event.key() == Qt.Key_C) and (event.modifiers() & Qt.ControlModifier):
892
            self.copy_cells_to_clipboard()
893
            event.accept()
894

    
895
    def copy_cells_to_clipboard(self):
896
        """ copy selected text to clipboard """
897

    
898
        selection = self.selectedIndexes()
899
        if selection:
900
            rows = sorted(index.row() for index in selection)
901
            columns = sorted(index.column() for index in selection)
902
            text = self.item(rows[-1], columns[-1]).text()
903
            QApplication.clipboard().setText(text)
904

    
905
    '''
906
        @brief      int cell check
907
        @author     kyouho
908
        @date       2018.08.20
909
    '''
910
    def cellChangedEvent(self, row, column):
911
        from SymbolAttr import SymbolProp
912
        from SymbolAttr import SymbolAttr
913

    
914
        try:
915
            if column == 3:
916
                item = self.item(row, 1)
917
                data = item.data(Qt.UserRole) if item is not None else None
918
                if data is not None:
919
                    if self._item:
920
                        if type(data) is SymbolProp:
921
                            if data.AttributeType != 'Boolean':
922
                                self._item.set_property(data.Attribute, self.item(row, column).text())
923
                            else:
924
                                self._item.set_property(data.Attribute, self.cellWidget(row, column).isChecked())
925
                        elif type(data) is SymbolAttr:
926
                            if data.AttributeType != 'Boolean':
927
                                self._item.set_attrib(data, self.item(row, column).text())
928
                            else:
929
                                self._item.set_attrib(data, self.cellWidget(row, column).isChecked())
930
        except Exception as ex:
931
            from App import App
932
            from AppDocData import MessageType
933

    
934
            message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
935
            App.mainWnd().addMessage.emit(MessageType.Error, message)
936

    
937
    '''
938
        @brief      resultPropertyTableWidget Cell Double Click Event
939
        @author     kyouho
940
        @date       2018.07.19
941
        @history    euisung  2019.01.15  edit specbreak
942
    '''
943
    def cellDoubleClickedEvent(self, row, column):
944
        from SymbolAttr import SymbolProp
945

    
946
        if column == 2:
947
            items = self.mainWindow.graphicsView.scene.selectedItems()
948
            keyCell = self.item(row, 1)
949
            attr = keyCell.data(Qt.UserRole)
950
            if hasattr(keyCell, 'tag') and type(items[0]) is not QEngineeringSpecBreakItem:
951
                attr = keyCell.tag
952
                if attr.is_selectable:
953
                    cmd = SelectAttributeCommand.SelectAttributeCommand(items[0], attr, self.mainWindow.graphicsView)
954
                    cmd.onSuccess.connect(self.onSuccessSelectAttribute)
955
                    self.mainWindow.graphicsView.command = cmd
956
                elif self.item(row, column).flags() != Qt.ItemIsEnabled: 
957
                    self.editItem(self.item(row, column))
958
            elif keyCell.text() == 'CONN' and type(items[0]) is QEngineeringLineNoTextItem:
959
                from SymbolAttr import SymbolAttr
960
                attr = SymbolAttr()
961
                attr.AttributeType = "Line Item"
962
                cmd = SelectAttributeCommand.SelectAttributeCommand(items[0], attr, self.mainWindow.graphicsView)
963
                cmd.onSuccess.connect(self.onSuccessSelectAttribute)
964
                self.mainWindow.graphicsView.command = cmd
965
            elif keyCell.text() == 'OWNER' and ((type(items[0]) is QEngineeringLineItem) or (issubclass(type(items[0]), SymbolSvgItem)) or (issubclass(type(items[0]), QEngineeringTextItem))):
966
                attr = keyCell.data(Qt.UserRole)
967
                cmd = SelectAttributeCommand.SelectAttributeCommand(items[0], attr, self.mainWindow.graphicsView)
968
                cmd.onSuccess.connect(self.onSuccessSelectAttribute)
969
                self.mainWindow.graphicsView.command = cmd
970
            elif type(items[0]) is QEngineeringSpecBreakItem:
971
                if keyCell.text() == 'UpStream' or keyCell.text() == 'DownStream':
972
                    attr = keyCell.data(Qt.UserRole)
973
                    cmd = SelectAttributeCommand.SelectAttributeCommand(items[0], attr, self.mainWindow.graphicsView)
974
                    cmd.onSuccess.connect(self.onSuccessSelectAttribute)
975
                    self.mainWindow.graphicsView.command = cmd
976

    
977
                elif keyCell.text() == 'Set Specs':
978
                    from SpecBreakDialog import QSpecBreakDialog
979

    
980
                    try:
981
                        dialog = QSpecBreakDialog(self, items[0])
982
                        dialog.exec_()
983
                        self.show_item_property(items[0])
984
                    except Exception as ex:
985
                        print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
986
            elif issubclass(type(attr), SymbolProp):
987
                attr = keyCell.data(Qt.UserRole)
988
                cmd = SelectAttributeCommand.SelectAttributeCommand(items[0], attr, self.mainWindow.graphicsView)
989
                cmd.onSuccess.connect(self.onSuccessSelectAttribute)
990
                self.mainWindow.graphicsView.command = cmd
991

    
992
    '''
993
        @brief      success select attribute 
994
        @author     kyouho
995
        @date       2018.10.23
996
    '''
997
    def onSuccessSelectAttribute(self, connItem = None):
998
        """ update item's properties after selecting """
999
        self.show_item_property(self._item)
클립보드 이미지 추가 (최대 크기: 500 MB)