프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

hytos / HYTOS / HYTOS / ItemPropertyTableWidget.py @ 29485992

이력 | 보기 | 이력해설 | 다운로드 (40.8 KB)

1
# coding: utf-8
2

    
3
try:
4
    from PyQt5.QtCore import *
5
    from PyQt5.QtGui import *
6
    from PyQt5.QtWidgets import *
7
except ImportError:
8
    try:
9
        from PyQt4.QtCore import *
10
        from PyQt4.QtGui import *
11
    except ImportError:
12
        raise ImportError("ImageViewerQt: Requires PyQt5 or PyQt4.")
13

    
14
import os
15
import sys
16
import math
17
import re
18
import SelectAttributeCommand
19

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

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

    
46
class QCustomCheckBox(QCheckBox):
47
    def __init__(self, table, row, col):
48
        QCheckBox.__init__(self)
49
        self.table = table
50
        self.row = row
51
        self.col = col
52

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

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

    
71
            widget = self.table.cellWidget(self.row, 3)
72
            if widget:
73
                widget.setEnabled(False) if state else widget.setEnabled(True)
74

    
75
            data = self.table.item(self.row, 1).data(Qt.UserRole)
76
            if data: data.Freeze = self.isChecked()
77

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

    
89
class QItemPropertyTableWidget(QTableWidget):
90
    def __init__(self, mainWindow):
91
        QTableWidget.__init__(self)
92
        self._item = None
93
        self.initResultPropertyTableWidget()
94
        self.mainWindow = mainWindow
95

    
96
        self.cellChanged.connect(self.cellChangedEvent)
97
        self.cellDoubleClicked.connect(self.cellDoubleClickedEvent)
98

    
99
    '''
100
        @brief  show item's property
101
        @author humkyung
102
        @date   2018.07.03
103
        @history    euisung  2019.01.15     add icon image to line item
104
    '''
105
    def show_item_property(self, item):
106
        try:
107
            from PyQt5 import QtGui
108
            from SymbolAttr import SymbolAttr
109

    
110
            self._item = item
111

    
112
            self.blockSignals(True)
113

    
114
            if type(item) is QEngineeringLineItem:
115
                self.initTitleCell(item)
116
                self.initContentsCell()
117
            elif issubclass(type(item), SymbolSvgItem):
118
                self.onSymbolClicked(item)
119
            elif type(item) is QEngineeringLineNoTextItem:
120
                self.onLineNoClicked(item)
121
            elif type(item) is QEngineeringNoteItem:
122
                noteContentsList = item.findNoteContents(item.text())
123
                self.onNoteClicked(item.text(), noteContentsList)
124
            elif issubclass(type(item), QEngineeringTextItem):
125
                self.onTextClicked(item)
126
            elif type(item) is QEngineeringVendorItem:
127
                self.onVendorClicked(item)
128
            elif item is None:
129
                self.setRowCount(0)
130
        except Exception as ex:
131
            from App import App 
132

    
133
            message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
134
            App.mainWnd().addMessage.emit(MessageType.Error, message)
135
        finally:
136
            self.blockSignals(False)
137

    
138
    '''
139
        @brief      Initialize TableWidget
140
        @author     Jeongwoo
141
        @date       18.04.13
142
        @history    humkyung 2018.07.08 show column header
143
    '''
144
    def initResultPropertyTableWidget(self):
145
        self.setColumnCount(4)
146
        self.setHorizontalHeaderLabels(['', self.tr('Name'), '', self.tr('Value')])
147
        self.setColumnWidth(0, 10)
148
        self.setColumnWidth(1, 20)
149
        self.setColumnWidth(2, 10)
150
        self.setRowCount(13)
151
        self.verticalHeader().hide()
152
        self.horizontalHeader().setStretchLastSection(True)
153
        
154
    '''
155
        @brief      Slot to accept item click event
156
        @author     Jeongwoo
157
        @date       18.04.13
158
        @history    humkyung 2018.04.17 check if given symbol type is SymbolSvgItem
159
    '''
160
    @pyqtSlot(SymbolSvgItem)
161
    def onSymbolClicked(self, symbol):
162
        try:
163
            self.blockSignals(True)
164
            if issubclass(type(symbol), SymbolSvgItem):
165
                self._item = symbol
166
                self.symbolChanged(symbol)
167
            elif type(symbol) is QEngineeringLineNoTextItem:
168
                self.lineNoChanged(symbol)
169
        finally:
170
            self.blockSignals(True)
171

    
172
    '''
173
        @brief      show drawing' attributes
174
        @author     humkyung 
175
        @date       2018.07.07
176
    '''
177
    @pyqtSlot(Drawing)
178
    def onDrawingClicked(self, drawing):
179
        try:
180
            self.blockSignals(True)
181
            self.setRowCount(len(drawing.attrs))
182

    
183
            row = 0
184
            for attr in drawing.attrs:
185
                name = attr[0]
186
                item = QTableWidgetItem(name)
187
                item.setFlags(Qt.ItemIsEnabled)
188
                item.setBackground(Qt.lightGray)
189
                self.setItem(row, 0, item)
190

    
191
                value = attr[1]
192
                item = QTableWidgetItem(value)
193
                item.setFlags(Qt.ItemIsEnabled)
194
                self.setItem(row, 1, item)
195

    
196
                row = row + 1
197
        finally:
198
            self.blockSignals(False)
199

    
200
    def onVendorClicked(self, item):
201
        from SymbolAttr import SymbolAttr
202

    
203
        try:
204
            self.blockSignals(True)
205
            self.initTitleCell(item)
206

    
207
            self.setItem(0, 3, QTableWidgetItem(str(self._item.uid)))
208

    
209
            self.show_item_properties(item)
210
        finally:
211
            self.blockSignals(False)
212

    
213
    def onTextClicked(self, item):
214
        from SymbolAttr import SymbolAttr
215

    
216
        try:
217
            self.blockSignals(True)
218
            self.initTitleCell(item)
219

    
220
            self.setItem(0, 3, QTableWidgetItem(str(self._item.uid)))
221

    
222
            owner_item = QTableWidgetItem('{}'.format('None' if self._item.owner is None else str(self._item.owner)))
223
            owner_item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable)
224
            self.setItem(1, 3, owner_item)
225

    
226
            """ show icon item """
227
            attr = SymbolAttr()
228
            attr.AttributeType = "OWNER"
229
            self.show_icon_item(1, 2, attr)
230
            self.item(1, 1).setData(Qt.UserRole, attr)
231

    
232
            self.setItem(2, 3, QTableWidgetItem(self._item.type))
233
            self.setItem(3, 3, QTableWidgetItem(self._item.text()))
234
        finally:
235
            self.blockSignals(False)
236

    
237
    '''
238
        @brief      Slot to accept Note item click event
239
        @author     Jeongwoo
240
        @date       18.04.27
241
        @history    humkyung 2018.07.08 change method name to onNoteClicked
242
    '''
243
    @pyqtSlot(str, dict)
244
    def onNoteClicked(self, noteNoStr, noteContentsList):
245
        try:
246
            self.blockSignals(True)
247
            self.noteChanged(noteNoStr, noteContentsList)
248
        finally:
249
            self.blockSignals(False)
250

    
251
    '''
252
        @brief      Slot to accept Line No Item Click event
253
        @author     Jeongwoo
254
        @date       18.05.10
255
        @hisotry    humkyung 2018.07.08 change method name to onLineNoClicked
256
    '''
257
    @pyqtSlot(QEngineeringAbstractItem)
258
    def onLineNoClicked(self, item):
259
        try:
260
            self.blockSignals(True)
261
            self.lineNoChanged(item)
262
        finally:
263
            self.blockSignals(False)
264
        
265
    '''
266
        @brief      Reset table with new SymbolSvgItem
267
        @author     Jeongwoo
268
        @date       18.04.13
269
        @history    .
270
    '''
271
    def symbolChanged(self, item):
272
        self.initTitleCell(item)
273
        self.initContentsCell()
274

    
275
    '''
276
        @brief      Reset table with note info
277
        @author     Jeongwoo
278
        @date       18.04.27
279
    '''
280
    def noteChanged(self, noteNoStr, noteContentsList):
281
        self.initNoteCell(noteNoStr, noteContentsList)
282

    
283
    '''
284
        @brief      Reset table with line no item
285
        @author     Jeongwoo
286
        @date       18.05.10
287
    '''
288
    def lineNoChanged(self, item):
289
        from EngineeringRunItem import QEngineeringRunItem
290

    
291
        if type(item) is QEngineeringLineNoTextItem:
292
            self.initTitleCell(item)
293
            self.initLineNoCell(item)
294
        elif type(item) is QEngineeringRunItem:
295
            self.initLineRunCell(item)
296

    
297
        """ show tooltip """
298
        for index in range(self.rowCount()):
299
            item = self.item(index, 1)
300
            if item is not None:
301
                item.setToolTip(item.text())
302

    
303
    '''
304
        @brief      Initialize Title Cell
305
        @author     Jeongwoos
306
        @date       18.04.13
307
        @history    Jeongwoo 2018.04.27 Add if-statement by ItemType
308
                    Jeongwoo 2018.05.10 Add if-statement LINE_NO ItemType
309
                    humkyung 2018.08.15 add combobox for line type
310
    '''
311
    def initTitleCell(self, item):
312
        from LineTypeConditions import LineTypeConditions
313

    
314
        try:
315
            self.clear()
316
            self.setHorizontalHeaderLabels(['', self.tr('Name'), '', self.tr('Value')])
317
            self.setColumnWidth(0, 20)
318
            self.setColumnWidth(1, 80)
319
            self.setColumnWidth(2, 20)
320
            if type(item) is QEngineeringSpecBreakItem:
321
                self.setRowCount(7)
322
                self.setItem(0, 1, QTableWidgetItem(self.tr("UID")))
323
                self.setItem(1, 1, QTableWidgetItem(self.tr("Name")))
324
                self.setItem(2, 1, QTableWidgetItem(self.tr("Type")))
325
                self.setItem(3, 1, QTableWidgetItem(self.tr("Angle")))
326
                self.setItem(4, 1, QTableWidgetItem(self.tr("Origin")))
327
                self.setItem(5, 1, QTableWidgetItem(self.tr("OWNER")))
328
                self.setItem(6, 1, QTableWidgetItem(self.tr("Set Specs")))
329
            elif type(item) is QEngineeringErrorItem:
330
                self.setRowCount(7)
331
                self.setItem(0, 1, QTableWidgetItem(self.tr("UID")))
332
                self.setItem(1, 1, QTableWidgetItem(self.tr("Name")))
333
                self.setItem(2, 1, QTableWidgetItem(self.tr("Type")))
334
                self.setItem(3, 1, QTableWidgetItem(self.tr("Angle")))
335
                self.setItem(4, 1, QTableWidgetItem(self.tr("Origin")))
336
                self.setItem(5, 1, QTableWidgetItem(self.tr("OWNER")))
337
                self.setItem(6, 1, QTableWidgetItem(self.tr("Message")))
338
            elif issubclass(type(item), SymbolSvgItem):
339
                self.setRowCount(6)
340
                self.setItem(0, 1, QTableWidgetItem(self.tr("UID")))
341
                self.setItem(1, 1, QTableWidgetItem(self.tr("Name")))
342
                self.setItem(2, 1, QTableWidgetItem(self.tr("Type")))
343
                self.setItem(3, 1, QTableWidgetItem(self.tr("Angle")))
344
                self.setItem(4, 1, QTableWidgetItem(self.tr("Origin")))
345
                self.setItem(5, 1, QTableWidgetItem(self.tr("OWNER")))
346
            elif type(item) is QEngineeringNoteItem:
347
                self.setRowCount(2)
348
                self.setItem(0, 1, QTableWidgetItem(self.tr("Note No")))
349
                self.setItem(1, 1, QTableWidgetItem(self.tr("Desc.")))
350
            elif type(item) is QEngineeringLineNoTextItem:
351
                self.setRowCount(1)
352
                self.setItem(0, 1, QTableWidgetItem(self.tr("UID")))
353
            elif type(item) is QEngineeringLineItem:
354
                self.setRowCount(5)
355
                self.setItem(0, 1, QTableWidgetItem(self.tr('UID')))
356
                self.setItem(1, 1, QTableWidgetItem(self.tr('OWNER')))
357
                widgetItem = QTableWidgetItem(self.tr("Type"))
358
                widgetItem.setData(Qt.UserRole, item)
359
                self.setItem(2, 1, widgetItem)
360
                self._lineTypeComboBox = QComboBox(self)
361
                self._lineTypeComboBox.tag = widgetItem
362
                for lineType in LineTypeConditions.items():
363
                    self._lineTypeComboBox.addItem(lineType.name)
364
                self.setCellWidget(2, 3, self._lineTypeComboBox)
365
                self._lineTypeComboBox.setCurrentText(item.lineType)
366
                self._lineTypeComboBox.currentIndexChanged.connect(self.onLineTypeChanged)
367
            elif type(item) is QEngineeringVendorItem:
368
                self.setRowCount(1)
369
                self.setItem(0, 1, QTableWidgetItem(self.tr("UID")))
370
            else:
371
                self.setRowCount(4)
372
                self.setItem(0, 1, QTableWidgetItem(self.tr("UID")))
373
                self.setItem(1, 1, QTableWidgetItem(self.tr("OWNER")))
374
                self.setItem(2, 1, QTableWidgetItem(self.tr("Type")))
375
                self.setItem(3, 1, QTableWidgetItem(self.tr("Text")))
376

    
377
            for index in range(self.rowCount()):
378
                item = self.item(index, 1)
379
                if item is not None:
380
                    item.setFlags(Qt.ItemIsEnabled)
381
                    item.setBackground(Qt.lightGray)
382
        except Exception as ex:
383
            from App import App 
384

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

    
388
    '''
389
        @brief  change selected lines' type by selected line type
390
        @author humkyung
391
        @date   2018.08.15
392
    '''
393
    def onLineTypeChanged(self, param):
394
        lineType = self._lineTypeComboBox.itemText(param)
395
        data = self._lineTypeComboBox.tag.data(Qt.UserRole)
396
        if type(data) is QEngineeringLineItem:
397
            self.changeConnectedLineType(data, lineType)
398

    
399
    def changeConnectedLineType(self, line, lineType):
400
        line.lineType = lineType
401
        if type(line.connectors[0].connectedItem) is QEngineeringLineItem and \
402
                (line.connectors[0].connectedItem.connectors[0].connectedItem is line or line.connectors[0].connectedItem.connectors[1].connectedItem is line) and \
403
                line.connectors[0].connectedItem.lineType is not lineType:
404
            self.changeConnectedLineType(line.connectors[0].connectedItem, lineType)
405
        if type(line.connectors[1].connectedItem) is QEngineeringLineItem and \
406
                (line.connectors[1].connectedItem.connectors[0].connectedItem is line or line.connectors[1].connectedItem.connectors[1].connectedItem is line) and \
407
                line.connectors[1].connectedItem.lineType is not lineType:
408
            self.changeConnectedLineType(line.connectors[1].connectedItem, lineType)
409

    
410
    def show_icon_item(self, row, col, prop):
411
        """ show icon item on grid """
412
        from PyQt5 import QtGui
413

    
414
        if prop.is_selectable or prop.AttributeType == 'OWNER' or prop.AttributeType == 'CONN':
415
            icon = QtGui.QIcon()
416
            icon.addPixmap(QtGui.QPixmap(":/newPrefix/doubleclick.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
417
            icon_item = QTableWidgetItem('')
418
            icon_item.setFlags(Qt.ItemIsEnabled)
419
            icon_item.setIcon(icon)
420
            self.setItem(row, col, icon_item)
421
        elif prop.AttributeType == "String":
422
            icon = QtGui.QIcon()
423
            icon.addPixmap(QtGui.QPixmap(":/newPrefix/type.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
424
            icon_item = QTableWidgetItem()
425
            icon_item.setIcon(icon)
426
            self.setItem(row, col, icon_item)
427
        else:
428
            item = QTableWidgetItem()
429
            item.setFlags(Qt.ItemIsEditable)
430
            self.setItem(row, col, item)
431

    
432
    def show_item_properties(self, item):
433
        """ show item properties on grid """
434
        from PyQt5 import QtGui
435

    
436
        row = self.rowCount()
437
        if hasattr(item, '_properties'):
438
            self.setRowCount(row + len(item.properties))
439

    
440
            for prop,value in item.properties.items():
441
                try:
442
                    """ show freeze state """
443
                    checkbox = QCustomCheckBox(self, row, 0)
444
                    checkbox.setChecked(prop.Freeze)
445
                    checkbox.stateChanged.connect(checkbox.state_changed)
446
                    self.setCellWidget(row, 0, checkbox)
447

    
448
                    """ show property name """
449
                    key_item = QTableWidgetItem(prop.DisplayAttribute if prop.DisplayAttribute else prop.Attribute)
450
                    key_item.setFlags(Qt.ItemIsEnabled)
451
                    key_item.setBackground(Qt.lightGray)
452
                    key_item.setData(Qt.UserRole, prop)
453
                    self.setItem(row, 1, key_item)
454

    
455
                    """ show icon item """
456
                    self.show_icon_item(row, 2, prop)
457

    
458
                    """ show property value """
459
                    if prop.is_selectable:
460
                        value_item = QTableWidgetItem(str(value.uid) if hasattr(value, 'uid') else value)
461
                        value_item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable)
462
                        self.setItem(row, 3, value_item)
463
                    else:
464
                        if prop.AttributeType == 'Boolean':
465
                            self.checkbox_cell = QCustomCheckBox(self, row, 3)
466
                            self.checkbox_cell.setChecked(True if value and str(value) == 'True' else False)
467
                            self.checkbox_cell.stateChanged.connect(self.checkbox_cell.state_changed)
468
                            #if prop.Attribute == 'Freeze': self.checkbox_cell.stateChanged.connect(item.freeze_item.update_freeze)
469
                            self.setCellWidget(row, 3, self.checkbox_cell)
470
                        else:
471
                            value_item = QTableWidgetItem(value if value else '')
472
                            value_item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable|Qt.ItemIsEditable)
473
                            self.setItem(row, 3, value_item)
474

    
475
                    checkbox.state_changed(checkbox.isChecked())
476
                    
477
                    row = row + 1
478
                except Exception as ex:
479
                    from App import App 
480

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

    
484
    def show_item_attributes(self, item):
485
        """ show item's attributes on grid """
486
        from PyQt5 import QtGui
487

    
488
        row = self.rowCount()
489
        attrs = item.getAttributes()
490

    
491
        # display attributes of symbol
492
        if attrs is not None:
493
            self.setRowCount(row + len(attrs))
494

    
495
            for key,value in attrs.items():
496
                try:
497
                    """ show freeze state """
498
                    checkbox = QCustomCheckBox(self, row, 0)
499
                    checkbox.setChecked(key.Freeze)
500
                    checkbox.stateChanged.connect(checkbox.state_changed)
501
                    self.setCellWidget(row, 0, checkbox)
502

    
503
                    """ show property name """
504
                    key_item = QTableWidgetItem(key.DisplayAttribute if key.DisplayAttribute else key.Attribute)
505
                    key_item.setBackground(Qt.lightGray)
506
                    key_item.setData(Qt.UserRole, key)
507
                    self.setItem(row, 1, key_item)
508

    
509
                    """ show icon item """
510
                    self.show_icon_item(row, 2, key)
511

    
512
                    value_item = QTableWidgetItem(str(value))
513
                    value_item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable|Qt.ItemIsEditable)
514

    
515
                    if type(item) is QEngineeringSpecBreakItem:
516
                        if key.Attribute == 'UpStream' or key.Attribute == 'DownStream':
517
                            UpDownItem = QTableWidgetItem('{}'.format('None' if value is None else value))
518
                            self.setItem(row, 3, UpDownItem)
519
                        elif key.AttributeType == 'Spec':
520
                            self.setItem(row, 3, QTableWidgetItem(key.Attribute))
521
                    else:
522
                        self.setItem(row, 3, value_item)
523

    
524
                    checkbox.state_changed(checkbox.isChecked())
525

    
526
                    row = row + 1
527
                except Exception as ex:
528
                        from App import App 
529

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

    
533
    def show_item_connectors(self, item):
534
        """ show items' connectors on grid """
535
        from PyQt5 import QtGui
536
        from SymbolAttr import SymbolAttr
537

    
538
        row = self.rowCount()
539
        self.setRowCount(row + len(item.connectors))
540

    
541
        count = 1
542
        for connector in item.connectors:
543
            connector_item = QTableWidgetItem('CONN{}'.format(count))
544
            connector_item.setFlags(Qt.ItemIsEnabled)
545
            connector_item.setBackground(Qt.lightGray)
546
            self.setItem(row, 1, connector_item)
547

    
548
            attr = SymbolAttr()
549
            attr.AttributeType = "CONN"
550
            attr.AttrAt = count
551
            connector_item.setData(Qt.UserRole, attr)
552

    
553
            """ show icon item """
554
            self.show_icon_item(row, 2, attr)
555

    
556
            connector_item = QTableWidgetItem('{}'.format('None' if connector.connectedItem is None else str(connector.connectedItem)))
557
            connector_item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable)
558
            self.setItem(row, 3, connector_item)
559
            
560
            row = row + 1
561
            count = count + 1
562

    
563
    '''
564
        @brief      Initialize Contents Cell
565
        @author     Jeongwoo
566
        @date       18.04.13
567
        @history    humkyung 2018.06.14 display symbol attributes 
568
                    humkyung 2018.07.05 display connectivity
569
                    euisung  2019.01.15 edit specbreak
570
    '''
571
    def initContentsCell(self):
572
        from PyQt5 import QtGui
573
        from SymbolAttr import SymbolAttr
574

    
575
        try:
576
            if self._item is not None and issubclass(type(self._item), SymbolSvgItem):
577
                docData = AppDocData.instance()
578

    
579
                self.setItem(0, 3, QTableWidgetItem(str(self._item.uid)))
580
                self.setItem(1, 3, QTableWidgetItem(self._item.name))
581
                self.setItem(2, 3, QTableWidgetItem(self._item.type))
582
                self.setItem(3, 3, QTableWidgetItem(str(round(math.degrees(self._item.angle)))))
583
                self.setItem(4, 3, QTableWidgetItem(str(self._item.origin)))
584
                owner_item = QTableWidgetItem('{}'.format('None' if self._item.owner is None else str(self._item.owner)))
585
                self.setItem(5, 3, owner_item)
586

    
587
                for index in range(self.rowCount()):
588
                    item = self.item(index, 3)
589
                    if item is not None:
590
                        item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable)
591

    
592
                """ show icon item """
593
                attr = SymbolAttr()
594
                attr.AttributeType = "OWNER"
595
                self.show_icon_item(5, 2, attr)
596
                self.item(5, 1).setData(Qt.UserRole, attr)
597

    
598
                if type(self._item) is not QEngineeringSpecBreakItem and type(self._item) is not QEngineeringErrorItem:
599
                    self.show_item_properties(self._item)
600

    
601
                if type(self._item) is QEngineeringSpecBreakItem:
602
                    row = self.rowCount()
603
                    setSpecsItem = QTableWidgetItem('Open')
604
                    icon = QtGui.QIcon()
605
                    icon.addPixmap(QtGui.QPixmap(":/newPrefix/doubleclick.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
606
                    setSpecsItem.setIcon(icon)
607
                    self.setItem(row - 1, 2, setSpecsItem)
608

    
609
                if type(self._item) is QEngineeringErrorItem:
610
                    errType = 'None'
611
                    if type(self._item.parent) is QEngineeringLineItem:
612
                        errType = 'line'
613
                    elif issubclass(type(self._item.parent), SymbolSvgItem):
614
                        errType = 'symbol'
615
                    self.setItem(2, 3, QTableWidgetItem(errType))
616
                    self.setItem(5, 3, QTableWidgetItem(str(self._item.parent.uid)))
617
                    self.setItem(6, 3, QTableWidgetItem(self._item.msg))
618

    
619
                self.show_item_attributes(self._item)
620
                self.show_item_connectors(self._item)
621
                
622
                for index in range(self.rowCount()):
623
                    item = self.item(index, 3)
624
                    if item is not None: item.setToolTip(item.text())
625
            elif self._item is not None and type(self._item) is QEngineeringLineItem:
626
                self.setItem(0, 3, QTableWidgetItem(str(self._item.uid)))
627

    
628
                """ show icon item """
629
                attr = SymbolAttr()
630
                attr.AttributeType = "OWNER"
631
                self.show_icon_item(1, 2, attr)
632
                self.item(1, 1).setData(Qt.UserRole, attr)
633

    
634
                owner_item = QTableWidgetItem('{}'.format('None' if self._item.owner is None else str(self._item.owner)))
635
                self.setItem(1, 3, owner_item)
636

    
637
                self.show_item_properties(self._item)
638

    
639
                pt = self._item.startPoint()
640
                key_item = QTableWidgetItem(self.tr("Start"))
641
                key_item.setFlags(Qt.ItemIsEnabled)
642
                key_item.setBackground(Qt.lightGray)
643
                self.setItem(3, 1, key_item)
644
                self.setItem(3, 3, QTableWidgetItem('({},{})'.format(pt[0], pt[1])))
645
                pt = self._item.endPoint()
646
                key_item = QTableWidgetItem(self.tr("End"))
647
                key_item.setFlags(Qt.ItemIsEnabled)
648
                key_item.setBackground(Qt.lightGray)
649
                self.setItem(4, 1, key_item)
650
                self.setItem(4, 3, QTableWidgetItem('({},{})'.format(pt[0], pt[1])))
651

    
652
                self.show_item_attributes(self._item)
653
                self.show_item_connectors(self._item)
654
            else:
655
                self.setRowCount(0)
656
            
657
        except Exception as ex:
658
            from App import App 
659

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

    
663
    '''
664
        @brief      combobox change event
665
        @author     kyouho
666
        @date       2018.08.28
667
    '''
668
    def upStreamChanged(self, text):
669
        if self._item is not None:
670
            find = False
671
            for index in range(len(self._item.attrs)):
672
                if type(self._item.attrs[index]) is tuple and self._item.attrs[index][0] == 'Up Stream':
673
                    self._item.attrs[index] = (self._item.attrs[index][0], text)
674
                    find = True
675
                    break
676
            
677
            if not find:
678
                self._item.attrs.append(('Up Stream', text))
679

    
680
    '''
681
        @brief      combobox change event
682
        @author     kyouho
683
        @date       2018.08.28
684
    '''
685
    def downStreamChanged(self, text):
686
        if self._item is not None:
687
            find = False
688
            for index in range(len(self._item.attrs)):
689
                if type(self._item.attrs[index]) is tuple and self._item.attrs[index][0] == 'Down Stream':
690
                    self._item.attrs[index] = (self._item.attrs[index][0], text)
691
                    find = True
692
                    break
693
            
694
            if not find:
695
                self._item.attrs.append(('Down Stream', text))
696

    
697
    '''
698
        @brief      Initialize Note Contents Cell
699
        @author     Jeongwoo
700
        @date       18.04.27
701
    '''
702
    def initNoteCell(self, noteNoStr, noteContentsList):
703
        self.setRowCount(0)
704

    
705
        for key in noteContentsList:
706
            row = self.rowCount()
707
            self.setRowCount(row + len(noteContentsList[key]))
708
            item = QTableWidgetItem(key)
709
            self.setItem(row, 1, item)
710

    
711
            for index in range(len(noteContentsList[key])):
712
                self.setItem(row, 3, QTableWidgetItem(noteContentsList[key][index]))
713
                row = row + 1
714

    
715
        for index in range(self.rowCount()):
716
            item = self.item(index, 1)
717
            if item is not None:
718
                item.setFlags(Qt.ItemIsEnabled)
719
                item.setBackground(Qt.lightGray)
720

    
721
    '''
722
        @brief      Initialize Line No Contents Cell
723
        @author     Jeongwoo
724
        @date       18.05.10
725
        @history    humkyung 2018.07.20 display combobox when key is 'Stream No'
726
    '''
727
    def initLineNoCell(self, lineNoItem):
728
        appDocData = AppDocData.instance()
729
        configs = appDocData.getConfigs('Line No', 'Configuration')
730
        configs = configs[0].value.split('"-"')
731

    
732
        item = QTableWidgetItem(str(lineNoItem.uid))
733
        item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable)
734
        self.setItem(0, 3, item)
735

    
736
        self.show_item_properties(lineNoItem)
737
        
738
        row = self.rowCount()
739
        attrs = lineNoItem.getAttributes()
740
        self.setRowCount(row + len(attrs))
741
        if attrs is not None:
742
            for key in attrs.keys():
743
                item = QTableWidgetItem(key.DisplayAttribute if key.DisplayAttribute else key.Attribute)
744
                item.setFlags(Qt.ItemIsEnabled)
745
                item.setBackground(Qt.lightGray)
746
                item.tag = key
747
                self.setItem(row, 1, item)
748

    
749
                """ show icon item """
750
                self.show_icon_item(row, 2, key)
751

    
752
                # value cell
753
                value = attrs[key]
754
                valueCell = QTableWidgetItem(value)
755

    
756
                # UID로 확인
757
                keyStr = appDocData.getLinePropertiesByUID(key.UID)
758
                if keyStr:
759
                    # editable value cell
760
                    if keyStr[0].AttributeType == 'String':
761
                        pass
762
                        #self.attrValueList.append((valueCell, key.Attribute))
763
                        #self.stringCell.append(valueCell)
764
                    if keyStr[0].UID in configs: valueCell.setFlags(Qt.ItemIsEnabled)
765
                else:
766
                    valueCell.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable)
767
                 
768
                if key.Attribute.upper() == 'STREAM_NO':
769
                    self.streamNoComboBox = QComboBox()
770
                    self.streamNoComboBox.tag = key
771
                    self.streamNoComboBox.currentIndexChanged.connect(self.onStreamNoChanged)
772
                    
773
                    streamNos = sorted(list(appDocData.hmbTable.streamNos()))
774
                    for streamNo in streamNos:
775
                        self.streamNoComboBox.addItem(streamNo)
776
                    self.setCellWidget(row, 3, self.streamNoComboBox)
777
                    self.streamNoComboBox.setCurrentText(value)
778
                    
779
                self.setItem(row, 3, valueCell)
780

    
781
                row = row + 1
782

    
783
    '''
784
        @brief  change selected lines' stream no by selected stream no
785
        @author humkyung
786
        @date   2018.07.20
787
    '''
788
    def onStreamNoChanged(self, param):
789
        items = self.mainWindow.graphicsView.scene.selectedItems()
790
        if items is not None and len(items) == 1:
791
            if type(items[0]) is QEngineeringLineNoTextItem:
792
                stream_no = self.streamNoComboBox.itemText(param)
793
                items[0].set_attrib(self.streamNoComboBox.tag, stream_no)
794
                return
795

    
796
    '''
797
        @brief      Initialize Run Contents Cell
798
        @author     humkyung 
799
        @date       2018.05.27
800
    '''
801
    def initLineRunCell(self, item):
802
        self.setRowCount(1)
803

    
804
        lineTypeItem = QTableWidgetItem(self.tr("Line Type"))
805
        lineTypeItem.setBackground(Qt.lightGray)
806
        lineTypeItem.setFlags(Qt.ItemIsEnabled)
807
        self.setItem(0, 1, lineTypeItem)
808

    
809
    '''
810
        @brief      Key Press Event
811
        @author     kyouho
812
        @date       2018.07.19
813
    '''
814
    def keyPressEvent(self, event):
815
        if event.key() == Qt.Key_Delete:
816
            items = self.mainWindow.graphicsView.scene.selectedItems()
817
            selectedIndexes = self.selectedIndexes()
818
            if selectedIndexes[0].column() == 3 and self.item(selectedIndexes[0].row(), 1).text() == 'OWNER':
819
                items[0].owner = None
820
                self.show_item_property(items[0])
821
            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:
822
                if selectedIndexes[0].column() == 3:
823
                    attributeStr = self.item(selectedIndexes[0].row(), 1).text()
824
                    items[0].removeSelfAttr(attributeStr)
825
                    self.mainWindow.refreshResultPropertyTableWidget()
826
            elif len(items) == 1 and len(selectedIndexes) == 1 and (type(items[0]) is QEngineeringLineItem or issubclass(type(items[0]), SymbolSvgItem)):
827
                key_cell = self.item(selectedIndexes[0].row(), 1)
828
                if selectedIndexes[0].column() == 3 and key_cell.text().find('CONN') is 0:
829
                    selectedUID = self.item(selectedIndexes[0].row(), 1).text()
830
                    connNum = int(key_cell.text().replace('CONN', ''))
831
                    items[0].connectors[connNum - 1].connectedItem = None
832
                    self.show_item_property(items[0])
833

    
834
                    for sceneItem in self.mainWindow.graphicsView.scene.items():
835
                        if hasattr(sceneItem, 'uid') and str(sceneItem.uid) == selectedUID and hasattr(sceneItem, 'connectors'):
836
                            for sceneConnector in sceneItem.connectors:
837
                                if sceneConnector.connectedItem is not None and items[0].uid == sceneConnector.connectedItem.uid:
838
                                    sceneConnector.connectedItem = None
839
            elif len(items) == 1 and len(selectedIndexes) == 1 and type(items[0]) is QEngineeringSpecBreakItem:
840
                keyCell = self.item(selectedIndexes[0].row(), 1)
841
                if selectedIndexes[0].column() == 3 and (keyCell.text() == 'UpStream' or keyCell.text() == 'DownStream'):
842
                    for attr in items[0].attrs.keys():
843
                        if attr.Attribute == keyCell.text():
844
                            items[0].attrs[attr] = None
845
                    self.show_item_property(items[0])
846
        elif (event.key() == Qt.Key_C) and (event.modifiers() & Qt.ControlModifier):
847
            self.copy_cells_to_clipboard()
848
            event.accept()
849

    
850
    def copy_cells_to_clipboard(self):
851
        """ copy selected text to clipboard """
852

    
853
        selection = self.selectedIndexes()
854
        if selection:
855
            rows = sorted(index.row() for index in selection)
856
            columns = sorted(index.column() for index in selection)
857
            text = self.item(rows[-1], columns[-1]).text()
858
            QApplication.clipboard().setText(text)
859

    
860
    '''
861
        @brief      int cell check
862
        @author     kyouho
863
        @date       2018.08.20
864
    '''
865
    def cellChangedEvent(self, row, column):
866
        from SymbolAttr import SymbolProp
867
        from SymbolAttr import SymbolAttr
868

    
869
        try:
870
            if column == 3:
871
                item = self.item(row, 1)
872
                data = item.data(Qt.UserRole) if item is not None else None
873
                if data is not None:
874
                    if self._item:
875
                        if type(data) is SymbolProp:
876
                            if data.AttributeType != 'Boolean':
877
                                self._item.set_property(data.Attribute, self.item(row, column).text())
878
                            else:
879
                                self._item.set_property(data.Attribute, self.cellWidget(row, column).isChecked())
880
                        elif type(data) is SymbolAttr:
881
                            if data.AttributeType != 'Boolean':
882
                                self._item.set_attrib(data, self.item(row, column).text())
883
                            else:
884
                                self._item.set_attrib(data, self.cellWidget(row, column).isChecked())
885
        except Exception as ex:
886
            from App import App
887
            from AppDocData import MessageType
888

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

    
892
    '''
893
        @brief      resultPropertyTableWidget Cell Double Click Event
894
        @author     kyouho
895
        @date       2018.07.19
896
        @history    euisung  2019.01.15  edit specbreak
897
    '''
898
    def cellDoubleClickedEvent(self, row, column):
899
        from SymbolAttr import SymbolProp
900

    
901
        if column == 2:
902
            items = self.mainWindow.graphicsView.scene.selectedItems()
903
            keyCell = self.item(row, 1)
904
            attr = keyCell.data(Qt.UserRole)
905
            if hasattr(keyCell, 'tag') and type(items[0]) is not QEngineeringSpecBreakItem:
906
                attr = keyCell.tag
907
                if attr.is_selectable:
908
                    cmd = SelectAttributeCommand.SelectAttributeCommand(items[0], attr, self.mainWindow.graphicsView)
909
                    cmd.onSuccess.connect(self.onSuccessSelectAttribute)
910
                    self.mainWindow.graphicsView.command = cmd
911
                elif self.item(row, column).flags() != Qt.ItemIsEnabled: 
912
                    self.editItem(self.item(row, column))
913
            elif keyCell.text() == 'CONN' and type(items[0]) is QEngineeringLineNoTextItem:
914
                from SymbolAttr import SymbolAttr
915
                attr = SymbolAttr()
916
                attr.AttributeType = "Line Item"
917
                cmd = SelectAttributeCommand.SelectAttributeCommand(items[0], attr, self.mainWindow.graphicsView)
918
                cmd.onSuccess.connect(self.onSuccessSelectAttribute)
919
                self.mainWindow.graphicsView.command = cmd
920
            elif keyCell.text() == 'OWNER' and ((type(items[0]) is QEngineeringLineItem) or (issubclass(type(items[0]), SymbolSvgItem)) or (issubclass(type(items[0]), QEngineeringTextItem))):
921
                attr = keyCell.data(Qt.UserRole)
922
                cmd = SelectAttributeCommand.SelectAttributeCommand(items[0], attr, self.mainWindow.graphicsView)
923
                cmd.onSuccess.connect(self.onSuccessSelectAttribute)
924
                self.mainWindow.graphicsView.command = cmd
925
            elif type(items[0]) is QEngineeringSpecBreakItem:
926
                if keyCell.text() == 'UpStream' or keyCell.text() == 'DownStream':
927
                    attr = keyCell.data(Qt.UserRole)
928
                    cmd = SelectAttributeCommand.SelectAttributeCommand(items[0], attr, self.mainWindow.graphicsView)
929
                    cmd.onSuccess.connect(self.onSuccessSelectAttribute)
930
                    self.mainWindow.graphicsView.command = cmd
931

    
932
                elif keyCell.text() == 'Set Specs':
933
                    from SpecBreakDialog import QSpecBreakDialog
934

    
935
                    try:
936
                        dialog = QSpecBreakDialog(self, items[0])
937
                        dialog.exec_()
938
                        self.show_item_property(items[0])
939
                    except Exception as ex:
940
                        print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
941
            elif issubclass(type(attr), SymbolProp):
942
                attr = keyCell.data(Qt.UserRole)
943
                cmd = SelectAttributeCommand.SelectAttributeCommand(items[0], attr, self.mainWindow.graphicsView)
944
                cmd.onSuccess.connect(self.onSuccessSelectAttribute)
945
                self.mainWindow.graphicsView.command = cmd
946

    
947
    '''
948
        @brief      success select attribute 
949
        @author     kyouho
950
        @date       2018.10.23
951
    '''
952
    def onSuccessSelectAttribute(self, connItem = None):
953
        """ update item's properties after selecting """
954
        self.show_item_property(self._item)
클립보드 이미지 추가 (최대 크기: 500 MB)