프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / DTI_PID / ItemPropertyTableWidget.py @ c5e51d41

이력 | 보기 | 이력해설 | 다운로드 (41.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('')
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
                    self.setItem(row - 1, 3, QTableWidgetItem('Open'))
609

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

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

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

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

    
638
                self.show_item_properties(self._item)
639

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
782
                row = row + 1
783

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

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

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

    
810
    '''
811
        @brief      Key Press Event
812
        @author     kyouho
813
        @date       2018.07.19
814
    '''
815
    def keyPressEvent(self, event):
816
        from SymbolAttr import SymbolAttr
817

    
818
        if event.key() == Qt.Key_Delete:
819
            items = self.mainWindow.graphicsView.scene.selectedItems()
820
            selectedIndexes = self.selectedIndexes()
821
            if selectedIndexes[0].column() == 3 and self.item(selectedIndexes[0].row(), 1).text() == 'OWNER':
822
                items[0].owner = None
823
                self.show_item_property(items[0])
824
            #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:
825
            #    if selectedIndexes[0].column() == 3:
826
            #        attributeStr = self.item(selectedIndexes[0].row(), 1).text()
827
            #        items[0].removeSelfAttr(attributeStr)
828
            #        self.mainWindow.refreshResultPropertyTableWidget()
829
            elif len(items) == 1 and len(selectedIndexes) == 1 and (type(items[0]) is QEngineeringLineItem or issubclass(type(items[0]), SymbolSvgItem)):
830
                key_cell = self.item(selectedIndexes[0].row(), 1)
831
                data = key_cell.data(Qt.UserRole)
832
                if selectedIndexes[0].column() == 3 and key_cell.text().find('CONN') is 0:
833
                    selectedUID = self.item(selectedIndexes[0].row(), 1).text()
834
                    connNum = int(key_cell.text().replace('CONN', ''))
835
                    items[0].connectors[connNum - 1].connectedItem = None
836
                    self.show_item_property(items[0])
837

    
838
                    for sceneItem in self.mainWindow.graphicsView.scene.items():
839
                        if hasattr(sceneItem, 'uid') and str(sceneItem.uid) == selectedUID and hasattr(sceneItem, 'connectors'):
840
                            for sceneConnector in sceneItem.connectors:
841
                                if sceneConnector.connectedItem is not None and items[0].uid == sceneConnector.connectedItem.uid:
842
                                    sceneConnector.connectedItem = None
843
                elif selectedIndexes[0].column() == 3 and data and type(data) is SymbolAttr:
844
                    assocItem = None
845
                    for _attr,_value in items[0].attrs.items():
846
                        if str(_attr.UID) == str(data.UID):
847
                            assocItem = _attr.AssocItem
848
                            items[0].remove_assoc_item(_attr.AssocItem)
849
                            if issubclass(type(_attr.AssocItem), QEngineeringTextItem):
850
                                _attr.AssocItem.owner = None
851
                            _attr.AssocItem = None
852
                            items[0].attrs[_attr] = ''
853
                            break
854
                    for _attr,_value in items[0].attrs.items():
855
                        if _attr.AssocItem is assocItem:
856
                            _attr.AssocItem = None
857
                            items[0].attrs[_attr] = ''
858
                    self.show_item_property(items[0])
859
            elif len(items) == 1 and len(selectedIndexes) == 1 and type(items[0]) is QEngineeringSpecBreakItem:
860
                keyCell = self.item(selectedIndexes[0].row(), 1)
861
                if selectedIndexes[0].column() == 3 and (keyCell.text() == 'UpStream' or keyCell.text() == 'DownStream'):
862
                    for attr in items[0].attrs.keys():
863
                        if attr.Attribute == keyCell.text():
864
                            items[0].attrs[attr] = None
865
                    self.show_item_property(items[0])
866
        elif (event.key() == Qt.Key_C) and (event.modifiers() & Qt.ControlModifier):
867
            self.copy_cells_to_clipboard()
868
            event.accept()
869

    
870
    def copy_cells_to_clipboard(self):
871
        """ copy selected text to clipboard """
872

    
873
        selection = self.selectedIndexes()
874
        if selection:
875
            rows = sorted(index.row() for index in selection)
876
            columns = sorted(index.column() for index in selection)
877
            text = self.item(rows[-1], columns[-1]).text()
878
            QApplication.clipboard().setText(text)
879

    
880
    '''
881
        @brief      int cell check
882
        @author     kyouho
883
        @date       2018.08.20
884
    '''
885
    def cellChangedEvent(self, row, column):
886
        from SymbolAttr import SymbolProp
887
        from SymbolAttr import SymbolAttr
888

    
889
        try:
890
            if column == 3:
891
                item = self.item(row, 1)
892
                data = item.data(Qt.UserRole) if item is not None else None
893
                if data is not None:
894
                    if self._item:
895
                        if type(data) is SymbolProp:
896
                            if data.AttributeType != 'Boolean':
897
                                self._item.set_property(data.Attribute, self.item(row, column).text())
898
                            else:
899
                                self._item.set_property(data.Attribute, self.cellWidget(row, column).isChecked())
900
                        elif type(data) is SymbolAttr:
901
                            if data.AttributeType != 'Boolean':
902
                                self._item.set_attrib(data, self.item(row, column).text())
903
                            else:
904
                                self._item.set_attrib(data, self.cellWidget(row, column).isChecked())
905
        except Exception as ex:
906
            from App import App
907
            from AppDocData import MessageType
908

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

    
912
    '''
913
        @brief      resultPropertyTableWidget Cell Double Click Event
914
        @author     kyouho
915
        @date       2018.07.19
916
        @history    euisung  2019.01.15  edit specbreak
917
    '''
918
    def cellDoubleClickedEvent(self, row, column):
919
        from SymbolAttr import SymbolProp
920

    
921
        if column == 2:
922
            items = self.mainWindow.graphicsView.scene.selectedItems()
923
            keyCell = self.item(row, 1)
924
            attr = keyCell.data(Qt.UserRole)
925
            if hasattr(keyCell, 'tag') and type(items[0]) is not QEngineeringSpecBreakItem:
926
                attr = keyCell.tag
927
                if attr.is_selectable:
928
                    cmd = SelectAttributeCommand.SelectAttributeCommand(items[0], attr, self.mainWindow.graphicsView)
929
                    cmd.onSuccess.connect(self.onSuccessSelectAttribute)
930
                    self.mainWindow.graphicsView.command = cmd
931
                elif self.item(row, column).flags() != Qt.ItemIsEnabled: 
932
                    self.editItem(self.item(row, column))
933
            elif keyCell.text() == 'CONN' and type(items[0]) is QEngineeringLineNoTextItem:
934
                from SymbolAttr import SymbolAttr
935
                attr = SymbolAttr()
936
                attr.AttributeType = "Line Item"
937
                cmd = SelectAttributeCommand.SelectAttributeCommand(items[0], attr, self.mainWindow.graphicsView)
938
                cmd.onSuccess.connect(self.onSuccessSelectAttribute)
939
                self.mainWindow.graphicsView.command = cmd
940
            elif keyCell.text() == 'OWNER' and ((type(items[0]) is QEngineeringLineItem) or (issubclass(type(items[0]), SymbolSvgItem)) or (issubclass(type(items[0]), QEngineeringTextItem))):
941
                attr = keyCell.data(Qt.UserRole)
942
                cmd = SelectAttributeCommand.SelectAttributeCommand(items[0], attr, self.mainWindow.graphicsView)
943
                cmd.onSuccess.connect(self.onSuccessSelectAttribute)
944
                self.mainWindow.graphicsView.command = cmd
945
            elif type(items[0]) is QEngineeringSpecBreakItem:
946
                if keyCell.text() == 'UpStream' or keyCell.text() == 'DownStream':
947
                    attr = keyCell.data(Qt.UserRole)
948
                    cmd = SelectAttributeCommand.SelectAttributeCommand(items[0], attr, self.mainWindow.graphicsView)
949
                    cmd.onSuccess.connect(self.onSuccessSelectAttribute)
950
                    self.mainWindow.graphicsView.command = cmd
951

    
952
                elif keyCell.text() == 'Set Specs':
953
                    from SpecBreakDialog import QSpecBreakDialog
954

    
955
                    try:
956
                        dialog = QSpecBreakDialog(self, items[0])
957
                        dialog.exec_()
958
                        self.show_item_property(items[0])
959
                    except Exception as ex:
960
                        print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
961
            elif issubclass(type(attr), SymbolProp):
962
                attr = keyCell.data(Qt.UserRole)
963
                cmd = SelectAttributeCommand.SelectAttributeCommand(items[0], attr, self.mainWindow.graphicsView)
964
                cmd.onSuccess.connect(self.onSuccessSelectAttribute)
965
                self.mainWindow.graphicsView.command = cmd
966

    
967
    '''
968
        @brief      success select attribute 
969
        @author     kyouho
970
        @date       2018.10.23
971
    '''
972
    def onSuccessSelectAttribute(self, connItem = None):
973
        """ update item's properties after selecting """
974
        self.show_item_property(self._item)
클립보드 이미지 추가 (최대 크기: 500 MB)