프로젝트

일반

사용자정보

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

hytos / DTI_PID / DTI_PID / ItemPropertyTableWidget.py @ 7b02722f

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

1
# coding: utf-8
2

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

    
14
import os
15
import sys
16
import math
17
import re
18
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
                owner_item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable)
586
                self.setItem(5, 3, owner_item)
587

    
588
                """ show icon item """
589
                attr = SymbolAttr()
590
                attr.AttributeType = "OWNER"
591
                self.show_icon_item(5, 2, attr)
592
                self.item(5, 1).setData(Qt.UserRole, attr)
593

    
594
                if type(self._item) is not QEngineeringSpecBreakItem and type(self._item) is not QEngineeringErrorItem:
595
                    self.show_item_properties(self._item)
596

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

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

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

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

    
630
                owner_item = QTableWidgetItem('{}'.format('None' if self._item.owner is None else str(self._item.owner)))
631
                self.setItem(1, 3, owner_item)
632

    
633
                self.show_item_properties(self._item)
634

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

    
648
                self.show_item_attributes(self._item)
649
                self.show_item_connectors(self._item)
650
            else:
651
                self.setRowCount(0)
652
        except Exception as ex:
653
            from App import App 
654

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

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

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

    
692
    '''
693
        @brief      Initialize Note Contents Cell
694
        @author     Jeongwoo
695
        @date       18.04.27
696
    '''
697
    def initNoteCell(self, noteNoStr, noteContentsList):
698
        self.setRowCount(0)
699

    
700
        for key in noteContentsList:
701
            row = self.rowCount()
702
            self.setRowCount(row + len(noteContentsList[key]))
703
            item = QTableWidgetItem(key)
704
            self.setItem(row, 1, item)
705

    
706
            for index in range(len(noteContentsList[key])):
707
                self.setItem(row, 3, QTableWidgetItem(noteContentsList[key][index]))
708
                row = row + 1
709

    
710
        for index in range(self.rowCount()):
711
            item = self.item(index, 1)
712
            if item is not None:
713
                item.setFlags(Qt.ItemIsEnabled)
714
                item.setBackground(Qt.lightGray)
715

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

    
727
        item = QTableWidgetItem(str(lineNoItem.uid))
728
        item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable)
729
        self.setItem(0, 3, item)
730

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

    
744
                """ show icon item """
745
                self.show_icon_item(row, 2, key)
746

    
747
                # value cell
748
                value = attrs[key]
749
                valueCell = QTableWidgetItem(value)
750

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

    
776
                row = row + 1
777

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

    
791
    '''
792
        @brief      Initialize Run Contents Cell
793
        @author     humkyung 
794
        @date       2018.05.27
795
    '''
796
    def initLineRunCell(self, item):
797
        self.setRowCount(1)
798

    
799
        lineTypeItem = QTableWidgetItem(self.tr("Line Type"))
800
        lineTypeItem.setBackground(Qt.lightGray)
801
        lineTypeItem.setFlags(Qt.ItemIsEnabled)
802
        self.setItem(0, 1, lineTypeItem)
803

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

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

    
845
    def copy_cells_to_clipboard(self):
846
        """ copy selected text to clipboard """
847

    
848
        selection = self.selectedIndexes()
849
        if selection:
850
            rows = sorted(index.row() for index in selection)
851
            columns = sorted(index.column() for index in selection)
852
            text = self.item(rows[-1], columns[-1]).text()
853
            QApplication.clipboard().setText(text)
854

    
855
    '''
856
        @brief      int cell check
857
        @author     kyouho
858
        @date       2018.08.20
859
    '''
860
    def cellChangedEvent(self, row, column):
861
        from SymbolAttr import SymbolProp
862
        from SymbolAttr import SymbolAttr
863

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

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

    
887
    '''
888
        @brief      resultPropertyTableWidget Cell Double Click Event
889
        @author     kyouho
890
        @date       2018.07.19
891
        @history    euisung  2019.01.15  edit specbreak
892
    '''
893
    def cellDoubleClickedEvent(self, row, column):
894
        from SymbolAttr import SymbolProp
895

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

    
927
                elif keyCell.text() == 'Set Specs':
928
                    from SpecBreakDialog import QSpecBreakDialog
929

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

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