프로젝트

일반

사용자정보

개정판 90070007

ID900700071d998f2003eb2583ed0228d744445428
상위 2f394152
하위 cf60792a

김연진이(가) 5년 이상 전에 추가함

issue #000: 불필요한 UI 제거

Change-Id: Ieb027cb9ecf454afdbe844f8c24d55d7c7756529

차이점 보기:

HYTOS/HYTOS/DrawingUnitTableWidget.py
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
class QDrawingUnitTableWidget(QTableWidget):
37
    def __init__(self, mainWindow):
38
        QTableWidget.__init__(self)
39
        self._item = None
40
        self.initDrawingUnitTableWidget()
41
        self.mainWindow = mainWindow
42

  
43
        self.cellChanged.connect(self.cellChangedEvent)
44
        self.cellDoubleClicked.connect(self.cellDoubleClickedEvent)
45

  
46
    '''
47
        @brief  show item's property
48
        @author humkyung
49
        @date   2018.07.03
50
        @history    euisung  2019.01.15     add icon image to line item
51
    '''
52
    def show_item_property(self, item):
53
        try:
54
            from PyQt5 import QtGui
55
            from SymbolAttr import SymbolAttr
56

  
57
            self._item = item
58

  
59
            self.blockSignals(True)
60

  
61
            if type(item) is QEngineeringLineItem:
62
                self.initTitleCell(item)
63
                self.initContentsCell()
64
            elif issubclass(type(item), SymbolSvgItem):
65
                self.onSymbolClicked(item)
66
            elif type(item) is QEngineeringLineNoTextItem:
67
                self.onLineNoClicked(item)
68
            elif type(item) is QEngineeringNoteItem:
69
                noteContentsList = item.findNoteContents(item.text())
70
                self.onNoteClicked(item.text(), noteContentsList)
71
            elif issubclass(type(item), QEngineeringTextItem):
72
                self.onTextClicked(item)
73
            elif type(item) is QEngineeringVendorItem:
74
                self.onVendorClicked(item)
75
            elif item is None:
76
                self.setRowCount(0)
77
        except Exception as ex:
78
            from App import App 
79

  
80
            message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
81
            App.mainWnd().addMessage.emit(MessageType.Error, message)
82
        finally:
83
            self.blockSignals(False)
84

  
85
    '''
86
        @brief      Initialize TableWidget
87
        @author     Jeongwoo
88
        @date       18.04.13
89
        @history    humkyung 2018.07.08 show column header
90
    '''
91
    def initDrawingUnitTableWidget(self):
92
        self.setColumnCount(2)
93
        self.setHorizontalHeaderLabels([self.tr('Name'), self.tr('Unit')])
94
        self.setColumnWidth(0, 130)        
95
        self.verticalHeader().hide()
96
        self.horizontalHeader().setStretchLastSection(True)
97

  
98
    def clear_units(self):
99
        self.clearContents()
100
        self.setRowCount(0)
101

  
102
    def load_units(self, drawingName):
103
        from AppDocData import AppDocData
104

  
105
        self.clear_units()
106

  
107
        unitsList = AppDocData.instance().getUnitsByDrawingName(drawingName)
108

  
109
        count = len(unitsList)
110

  
111
        if count > 0:
112
            self.setRowCount(count)
113
            rowIndex = 0
114
            for units in unitsList:
115
                #uid = QTableWidgetItem(str(hmb.uid))
116
                #uid.setTextAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
117

  
118
                self.setItem(rowIndex, 0, QTableWidgetItem(str(units[0])))
119
                self.setItem(rowIndex, 1, QTableWidgetItem(str(units[1])))
120

  
121
                rowIndex += 1
122

  
123

  
124
    '''
125
        @brief      Slot to accept item click event
126
        @author     Jeongwoo
127
        @date       18.04.13
128
        @history    humkyung 2018.04.17 check if given symbol type is SymbolSvgItem
129
    '''
130
    @pyqtSlot(SymbolSvgItem)
131
    def onSymbolClicked(self, symbol):
132
        try:
133
            self.blockSignals(True)
134
            if issubclass(type(symbol), SymbolSvgItem):
135
                self._item = symbol
136
                self.symbolChanged(symbol)
137
            elif type(symbol) is QEngineeringLineNoTextItem:
138
                self.lineNoChanged(symbol)
139
        finally:
140
            self.blockSignals(True)
141

  
142
    '''
143
        @brief      show drawing' attributes
144
        @author     humkyung 
145
        @date       2018.07.07
146
    '''
147
    @pyqtSlot(Drawing)
148
    def onDrawingClicked(self, drawing):
149
        try:
150
            self.blockSignals(True)
151
            self.setRowCount(len(drawing.attrs))
152

  
153
            row = 0
154
            for attr in drawing.attrs:
155
                name = attr[0]
156
                item = QTableWidgetItem(name)
157
                item.setFlags(Qt.ItemIsEnabled)
158
                item.setBackground(Qt.lightGray)
159
                self.setItem(row, 0, item)
160

  
161
                value = attr[1]
162
                item = QTableWidgetItem(value)
163
                item.setFlags(Qt.ItemIsEnabled)
164
                self.setItem(row, 1, item)
165

  
166
                row = row + 1
167
        finally:
168
            self.blockSignals(False)
169

  
170
    def onVendorClicked(self, item):
171
        from SymbolAttr import SymbolAttr
172

  
173
        try:
174
            self.blockSignals(True)
175
            self.initTitleCell(item)
176

  
177
            self.setItem(0, 3, QTableWidgetItem(str(self._item.uid)))
178

  
179
            self.show_item_properties(item)
180
        finally:
181
            self.blockSignals(False)
182

  
183
    def onTextClicked(self, item):
184
        from SymbolAttr import SymbolAttr
185

  
186
        try:
187
            self.blockSignals(True)
188
            self.initTitleCell(item)
189

  
190
            self.setItem(0, 3, QTableWidgetItem(str(self._item.uid)))
191

  
192
            owner_item = QTableWidgetItem('{}'.format('None' if self._item.owner is None else str(self._item.owner)))
193
            owner_item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable)
194
            self.setItem(1, 3, owner_item)
195

  
196
            """ show icon item """
197
            attr = SymbolAttr()
198
            attr.AttributeType = "OWNER"
199
            self.show_icon_item(1, 2, attr)
200
            self.item(1, 1).setData(Qt.UserRole, attr)
201

  
202
            self.setItem(2, 3, QTableWidgetItem(self._item.type))
203
            self.setItem(3, 3, QTableWidgetItem(self._item.text()))
204
        finally:
205
            self.blockSignals(False)
206

  
207
    '''
208
        @brief      Slot to accept Note item click event
209
        @author     Jeongwoo
210
        @date       18.04.27
211
        @history    humkyung 2018.07.08 change method name to onNoteClicked
212
    '''
213
    @pyqtSlot(str, dict)
214
    def onNoteClicked(self, noteNoStr, noteContentsList):
215
        try:
216
            self.blockSignals(True)
217
            self.noteChanged(noteNoStr, noteContentsList)
218
        finally:
219
            self.blockSignals(False)
220

  
221
    '''
222
        @brief      Slot to accept Line No Item Click event
223
        @author     Jeongwoo
224
        @date       18.05.10
225
        @hisotry    humkyung 2018.07.08 change method name to onLineNoClicked
226
    '''
227
    @pyqtSlot(QEngineeringAbstractItem)
228
    def onLineNoClicked(self, item):
229
        try:
230
            self.blockSignals(True)
231
            self.lineNoChanged(item)
232
        finally:
233
            self.blockSignals(False)
234
        
235
    '''
236
        @brief      Reset table with new SymbolSvgItem
237
        @author     Jeongwoo
238
        @date       18.04.13
239
        @history    .
240
    '''
241
    def symbolChanged(self, item):
242
        self.initTitleCell(item)
243
        self.initContentsCell()
244

  
245
    '''
246
        @brief      Reset table with note info
247
        @author     Jeongwoo
248
        @date       18.04.27
249
    '''
250
    def noteChanged(self, noteNoStr, noteContentsList):
251
        self.initNoteCell(noteNoStr, noteContentsList)
252

  
253
    '''
254
        @brief      Reset table with line no item
255
        @author     Jeongwoo
256
        @date       18.05.10
257
    '''
258
    def lineNoChanged(self, item):
259
        from EngineeringRunItem import QEngineeringRunItem
260

  
261
        if type(item) is QEngineeringLineNoTextItem:
262
            self.initTitleCell(item)
263
            self.initLineNoCell(item)
264
        elif type(item) is QEngineeringRunItem:
265
            self.initLineRunCell(item)
266

  
267
        """ show tooltip """
268
        for index in range(self.rowCount()):
269
            item = self.item(index, 1)
270
            if item is not None:
271
                item.setToolTip(item.text())
272

  
273
    '''
274
        @brief      Initialize Title Cell
275
        @author     Jeongwoos
276
        @date       18.04.13
277
        @history    Jeongwoo 2018.04.27 Add if-statement by ItemType
278
                    Jeongwoo 2018.05.10 Add if-statement LINE_NO ItemType
279
                    humkyung 2018.08.15 add combobox for line type
280
    '''
281
    def initTitleCell(self, item):
282
        from LineTypeConditions import LineTypeConditions
283

  
284
        try:
285
            self.clear()
286
            self.setHorizontalHeaderLabels(['', self.tr('Name'), '', self.tr('Value')])
287
            self.setColumnWidth(0, 20)
288
            self.setColumnWidth(1, 80)
289
            self.setColumnWidth(2, 20)
290
            if type(item) is QEngineeringSpecBreakItem:
291
                self.setRowCount(7)
292
                self.setItem(0, 1, QTableWidgetItem(self.tr("UID")))
293
                self.setItem(1, 1, QTableWidgetItem(self.tr("Name")))
294
                self.setItem(2, 1, QTableWidgetItem(self.tr("Type")))
295
                self.setItem(3, 1, QTableWidgetItem(self.tr("Angle")))
296
                self.setItem(4, 1, QTableWidgetItem(self.tr("Origin")))
297
                self.setItem(5, 1, QTableWidgetItem(self.tr("OWNER")))
298
                self.setItem(6, 1, QTableWidgetItem(self.tr("Set Specs")))
299
            elif type(item) is QEngineeringErrorItem:
300
                self.setRowCount(7)
301
                self.setItem(0, 1, QTableWidgetItem(self.tr("UID")))
302
                self.setItem(1, 1, QTableWidgetItem(self.tr("Name")))
303
                self.setItem(2, 1, QTableWidgetItem(self.tr("Type")))
304
                self.setItem(3, 1, QTableWidgetItem(self.tr("Angle")))
305
                self.setItem(4, 1, QTableWidgetItem(self.tr("Origin")))
306
                self.setItem(5, 1, QTableWidgetItem(self.tr("OWNER")))
307
                self.setItem(6, 1, QTableWidgetItem(self.tr("Message")))
308
            elif issubclass(type(item), SymbolSvgItem):
309
                self.setRowCount(6)
310
                self.setItem(0, 1, QTableWidgetItem(self.tr("UID")))
311
                self.setItem(1, 1, QTableWidgetItem(self.tr("Name")))
312
                self.setItem(2, 1, QTableWidgetItem(self.tr("Type")))
313
                self.setItem(3, 1, QTableWidgetItem(self.tr("Angle")))
314
                self.setItem(4, 1, QTableWidgetItem(self.tr("Origin")))
315
                self.setItem(5, 1, QTableWidgetItem(self.tr("OWNER")))
316
            elif type(item) is QEngineeringNoteItem:
317
                self.setRowCount(2)
318
                self.setItem(0, 1, QTableWidgetItem(self.tr("Note No")))
319
                self.setItem(1, 1, QTableWidgetItem(self.tr("Desc.")))
320
            elif type(item) is QEngineeringLineNoTextItem:
321
                self.setRowCount(1)
322
                self.setItem(0, 1, QTableWidgetItem(self.tr("UID")))
323
            elif type(item) is QEngineeringLineItem:
324
                self.setRowCount(5)
325
                self.setItem(0, 1, QTableWidgetItem(self.tr('UID')))
326
                self.setItem(1, 1, QTableWidgetItem(self.tr('OWNER')))
327
                widgetItem = QTableWidgetItem(self.tr("Type"))
328
                widgetItem.setData(Qt.UserRole, item)
329
                self.setItem(2, 1, widgetItem)
330
                self._lineTypeComboBox = QComboBox(self)
331
                self._lineTypeComboBox.tag = widgetItem
332
                for lineType in LineTypeConditions.items():
333
                    self._lineTypeComboBox.addItem(lineType.name)
334
                self.setCellWidget(2, 3, self._lineTypeComboBox)
335
                self._lineTypeComboBox.setCurrentText(item.lineType)
336
                self._lineTypeComboBox.currentIndexChanged.connect(self.onLineTypeChanged)
337
            elif type(item) is QEngineeringVendorItem:
338
                self.setRowCount(1)
339
                self.setItem(0, 1, QTableWidgetItem(self.tr("UID")))
340
            else:
341
                self.setRowCount(4)
342
                self.setItem(0, 1, QTableWidgetItem(self.tr("UID")))
343
                self.setItem(1, 1, QTableWidgetItem(self.tr("OWNER")))
344
                self.setItem(2, 1, QTableWidgetItem(self.tr("Type")))
345
                self.setItem(3, 1, QTableWidgetItem(self.tr("Text")))
346

  
347
            for index in range(self.rowCount()):
348
                item = self.item(index, 1)
349
                if item is not None:
350
                    item.setFlags(Qt.ItemIsEnabled)
351
                    item.setBackground(Qt.lightGray)
352
        except Exception as ex:
353
            from App import App 
354

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

  
358
    '''
359
        @brief  change selected lines' type by selected line type
360
        @author humkyung
361
        @date   2018.08.15
362
    '''
363
    def onLineTypeChanged(self, param):
364
        lineType = self._lineTypeComboBox.itemText(param)
365
        data = self._lineTypeComboBox.tag.data(Qt.UserRole)
366
        if type(data) is QEngineeringLineItem:
367
            self.changeConnectedLineType(data, lineType)
368

  
369
    def changeConnectedLineType(self, line, lineType):
370
        line.lineType = lineType
371
        if type(line.connectors[0].connectedItem) is QEngineeringLineItem and \
372
                (line.connectors[0].connectedItem.connectors[0].connectedItem is line or line.connectors[0].connectedItem.connectors[1].connectedItem is line) and \
373
                line.connectors[0].connectedItem.lineType is not lineType:
374
            self.changeConnectedLineType(line.connectors[0].connectedItem, lineType)
375
        if type(line.connectors[1].connectedItem) is QEngineeringLineItem and \
376
                (line.connectors[1].connectedItem.connectors[0].connectedItem is line or line.connectors[1].connectedItem.connectors[1].connectedItem is line) and \
377
                line.connectors[1].connectedItem.lineType is not lineType:
378
            self.changeConnectedLineType(line.connectors[1].connectedItem, lineType)
379

  
380
    def show_icon_item(self, row, col, prop):
381
        """ show icon item on grid """
382
        from PyQt5 import QtGui
383

  
384
        if prop.is_selectable or prop.AttributeType == 'OWNER' or prop.AttributeType == 'CONN':
385
            icon = QtGui.QIcon()
386
            icon.addPixmap(QtGui.QPixmap(":/newPrefix/doubleclick.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
387
            icon_item = QTableWidgetItem('')
388
            icon_item.setFlags(Qt.ItemIsEnabled)
389
            icon_item.setIcon(icon)
390
            self.setItem(row, col, icon_item)
391
        elif prop.AttributeType == "String":
392
            icon = QtGui.QIcon()
393
            icon.addPixmap(QtGui.QPixmap(":/newPrefix/type.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
394
            icon_item = QTableWidgetItem()
395
            icon_item.setIcon(icon)
396
            self.setItem(row, col, icon_item)
397
        else:
398
            item = QTableWidgetItem()
399
            item.setFlags(Qt.ItemIsEditable)
400
            self.setItem(row, col, item)
401

  
402
    def show_item_properties(self, item):
403
        """ show item properties on grid """
404
        from PyQt5 import QtGui
405

  
406
        row = self.rowCount()
407
        if hasattr(item, '_properties'):
408
            self.setRowCount(row + len(item.properties))
409

  
410
            for prop,value in item.properties.items():
411
                try:
412
                    """ show freeze state """
413
                    checkbox = QCustomCheckBox(self, row, 0)
414
                    checkbox.setChecked(prop.Freeze)
415
                    checkbox.stateChanged.connect(checkbox.state_changed)
416
                    self.setCellWidget(row, 0, checkbox)
417

  
418
                    """ show property name """
419
                    key_item = QTableWidgetItem(prop.DisplayAttribute if prop.DisplayAttribute else prop.Attribute)
420
                    key_item.setFlags(Qt.ItemIsEnabled)
421
                    key_item.setBackground(Qt.lightGray)
422
                    key_item.setData(Qt.UserRole, prop)
423
                    self.setItem(row, 1, key_item)
424

  
425
                    """ show icon item """
426
                    self.show_icon_item(row, 2, prop)
427

  
428
                    """ show property value """
429
                    if prop.is_selectable:
430
                        value_item = QTableWidgetItem(str(value.uid) if hasattr(value, 'uid') else value)
431
                        value_item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable)
432
                        self.setItem(row, 3, value_item)
433
                    else:
434
                        if prop.AttributeType == 'Boolean':
435
                            self.checkbox_cell = QCustomCheckBox(self, row, 3)
436
                            self.checkbox_cell.setChecked(True if value and str(value) == 'True' else False)
437
                            self.checkbox_cell.stateChanged.connect(self.checkbox_cell.state_changed)
438
                            #if prop.Attribute == 'Freeze': self.checkbox_cell.stateChanged.connect(item.freeze_item.update_freeze)
439
                            self.setCellWidget(row, 3, self.checkbox_cell)
440
                        else:
441
                            value_item = QTableWidgetItem(value if value else '')
442
                            value_item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable|Qt.ItemIsEditable)
443
                            self.setItem(row, 3, value_item)
444

  
445
                    checkbox.state_changed(checkbox.isChecked())
446
                    
447
                    row = row + 1
448
                except Exception as ex:
449
                    from App import App 
450

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

  
454
    def show_item_attributes(self, item):
455
        """ show item's attributes on grid """
456
        from PyQt5 import QtGui
457

  
458
        row = self.rowCount()
459
        attrs = item.getAttributes()
460

  
461
        # display attributes of symbol
462
        if attrs is not None:
463
            self.setRowCount(row + len(attrs))
464

  
465
            for key,value in attrs.items():
466
                try:
467
                    """ show freeze state """
468
                    checkbox = QCustomCheckBox(self, row, 0)
469
                    checkbox.setChecked(key.Freeze)
470
                    checkbox.stateChanged.connect(checkbox.state_changed)
471
                    self.setCellWidget(row, 0, checkbox)
472

  
473
                    """ show property name """
474
                    key_item = QTableWidgetItem(key.DisplayAttribute if key.DisplayAttribute else key.Attribute)
475
                    key_item.setBackground(Qt.lightGray)
476
                    key_item.setData(Qt.UserRole, key)
477
                    self.setItem(row, 1, key_item)
478

  
479
                    """ show icon item """
480
                    self.show_icon_item(row, 2, key)
481

  
482
                    value_item = QTableWidgetItem(str(value))
483
                    value_item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable|Qt.ItemIsEditable)
484

  
485
                    if type(item) is QEngineeringSpecBreakItem:
486
                        if key.Attribute == 'UpStream' or key.Attribute == 'DownStream':
487
                            UpDownItem = QTableWidgetItem('{}'.format('None' if value is None else value))
488
                            self.setItem(row, 3, UpDownItem)
489
                        elif key.AttributeType == 'Spec':
490
                            self.setItem(row, 3, QTableWidgetItem(key.Attribute))
491
                    else:
492
                        self.setItem(row, 3, value_item)
493

  
494
                    checkbox.state_changed(checkbox.isChecked())
495

  
496
                    row = row + 1
497
                except Exception as ex:
498
                        from App import App 
499

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

  
503
    def show_item_connectors(self, item):
504
        """ show items' connectors on grid """
505
        from PyQt5 import QtGui
506
        from SymbolAttr import SymbolAttr
507

  
508
        row = self.rowCount()
509
        self.setRowCount(row + len(item.connectors))
510

  
511
        count = 1
512
        for connector in item.connectors:
513
            connector_item = QTableWidgetItem('CONN{}'.format(count))
514
            connector_item.setFlags(Qt.ItemIsEnabled)
515
            connector_item.setBackground(Qt.lightGray)
516
            self.setItem(row, 1, connector_item)
517

  
518
            attr = SymbolAttr()
519
            attr.AttributeType = "CONN"
520
            attr.AttrAt = count
521
            connector_item.setData(Qt.UserRole, attr)
522

  
523
            """ show icon item """
524
            self.show_icon_item(row, 2, attr)
525

  
526
            connector_item = QTableWidgetItem('{}'.format('None' if connector.connectedItem is None else str(connector.connectedItem)))
527
            connector_item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable)
528
            self.setItem(row, 3, connector_item)
529
            
530
            row = row + 1
531
            count = count + 1
532

  
533
    '''
534
        @brief      Initialize Contents Cell
535
        @author     Jeongwoo
536
        @date       18.04.13
537
        @history    humkyung 2018.06.14 display symbol attributes 
538
                    humkyung 2018.07.05 display connectivity
539
                    euisung  2019.01.15 edit specbreak
540
    '''
541
    def initContentsCell(self):
542
        from PyQt5 import QtGui
543
        from SymbolAttr import SymbolAttr
544

  
545
        try:
546
            if self._item is not None and issubclass(type(self._item), SymbolSvgItem):
547
                docData = AppDocData.instance()
548

  
549
                self.setItem(0, 3, QTableWidgetItem(str(self._item.uid)))
550
                self.setItem(1, 3, QTableWidgetItem(self._item.name))
551
                self.setItem(2, 3, QTableWidgetItem(self._item.type))
552
                self.setItem(3, 3, QTableWidgetItem(str(round(math.degrees(self._item.angle)))))
553
                self.setItem(4, 3, QTableWidgetItem(str(self._item.origin)))
554
                owner_item = QTableWidgetItem('{}'.format('None' if self._item.owner is None else str(self._item.owner)))
555
                self.setItem(5, 3, owner_item)
556

  
557
                for index in range(self.rowCount()):
558
                    item = self.item(index, 3)
559
                    if item is not None:
560
                        item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable)
561

  
562
                """ show icon item """
563
                attr = SymbolAttr()
564
                attr.AttributeType = "OWNER"
565
                self.show_icon_item(5, 2, attr)
566
                self.item(5, 1).setData(Qt.UserRole, attr)
567

  
568
                if type(self._item) is not QEngineeringSpecBreakItem and type(self._item) is not QEngineeringErrorItem:
569
                    self.show_item_properties(self._item)
570

  
571
                if type(self._item) is QEngineeringSpecBreakItem:
572
                    row = self.rowCount()
573
                    setSpecsItem = QTableWidgetItem('Open')
574
                    icon = QtGui.QIcon()
575
                    icon.addPixmap(QtGui.QPixmap(":/newPrefix/doubleclick.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
576
                    setSpecsItem.setIcon(icon)
577
                    self.setItem(row - 1, 2, setSpecsItem)
578

  
579
                if type(self._item) is QEngineeringErrorItem:
580
                    errType = 'None'
581
                    if type(self._item.parent) is QEngineeringLineItem:
582
                        errType = 'line'
583
                    elif issubclass(type(self._item.parent), SymbolSvgItem):
584
                        errType = 'symbol'
585
                    self.setItem(2, 3, QTableWidgetItem(errType))
586
                    self.setItem(5, 3, QTableWidgetItem(str(self._item.parent.uid)))
587
                    self.setItem(6, 3, QTableWidgetItem(self._item.msg))
588

  
589
                self.show_item_attributes(self._item)
590
                self.show_item_connectors(self._item)
591
                
592
                for index in range(self.rowCount()):
593
                    item = self.item(index, 3)
594
                    if item is not None: item.setToolTip(item.text())
595
            elif self._item is not None and type(self._item) is QEngineeringLineItem:
596
                self.setItem(0, 3, QTableWidgetItem(str(self._item.uid)))
597

  
598
                """ show icon item """
599
                attr = SymbolAttr()
600
                attr.AttributeType = "OWNER"
601
                self.show_icon_item(1, 2, attr)
602
                self.item(1, 1).setData(Qt.UserRole, attr)
603

  
604
                owner_item = QTableWidgetItem('{}'.format('None' if self._item.owner is None else str(self._item.owner)))
605
                self.setItem(1, 3, owner_item)
606

  
607
                self.show_item_properties(self._item)
608

  
609
                pt = self._item.startPoint()
610
                key_item = QTableWidgetItem(self.tr("Start"))
611
                key_item.setFlags(Qt.ItemIsEnabled)
612
                key_item.setBackground(Qt.lightGray)
613
                self.setItem(3, 1, key_item)
614
                self.setItem(3, 3, QTableWidgetItem('({},{})'.format(pt[0], pt[1])))
615
                pt = self._item.endPoint()
616
                key_item = QTableWidgetItem(self.tr("End"))
617
                key_item.setFlags(Qt.ItemIsEnabled)
618
                key_item.setBackground(Qt.lightGray)
619
                self.setItem(4, 1, key_item)
620
                self.setItem(4, 3, QTableWidgetItem('({},{})'.format(pt[0], pt[1])))
621

  
622
                self.show_item_attributes(self._item)
623
                self.show_item_connectors(self._item)
624
            else:
625
                self.setRowCount(0)
626
            
627
        except Exception as ex:
628
            from App import App 
629

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

  
633
    '''
634
        @brief      combobox change event
635
        @author     kyouho
636
        @date       2018.08.28
637
    '''
638
    def upStreamChanged(self, text):
639
        if self._item is not None:
640
            find = False
641
            for index in range(len(self._item.attrs)):
642
                if type(self._item.attrs[index]) is tuple and self._item.attrs[index][0] == 'Up Stream':
643
                    self._item.attrs[index] = (self._item.attrs[index][0], text)
644
                    find = True
645
                    break
646
            
647
            if not find:
648
                self._item.attrs.append(('Up Stream', text))
649

  
650
    '''
651
        @brief      combobox change event
652
        @author     kyouho
653
        @date       2018.08.28
654
    '''
655
    def downStreamChanged(self, text):
656
        if self._item is not None:
657
            find = False
658
            for index in range(len(self._item.attrs)):
659
                if type(self._item.attrs[index]) is tuple and self._item.attrs[index][0] == 'Down Stream':
660
                    self._item.attrs[index] = (self._item.attrs[index][0], text)
661
                    find = True
662
                    break
663
            
664
            if not find:
665
                self._item.attrs.append(('Down Stream', text))
666

  
667
    '''
668
        @brief      Initialize Note Contents Cell
669
        @author     Jeongwoo
670
        @date       18.04.27
671
    '''
672
    def initNoteCell(self, noteNoStr, noteContentsList):
673
        self.setRowCount(0)
674

  
675
        for key in noteContentsList:
676
            row = self.rowCount()
677
            self.setRowCount(row + len(noteContentsList[key]))
678
            item = QTableWidgetItem(key)
679
            self.setItem(row, 1, item)
680

  
681
            for index in range(len(noteContentsList[key])):
682
                self.setItem(row, 3, QTableWidgetItem(noteContentsList[key][index]))
683
                row = row + 1
684

  
685
        for index in range(self.rowCount()):
686
            item = self.item(index, 1)
687
            if item is not None:
688
                item.setFlags(Qt.ItemIsEnabled)
689
                item.setBackground(Qt.lightGray)
690

  
691
    '''
692
        @brief      Initialize Line No Contents Cell
693
        @author     Jeongwoo
694
        @date       18.05.10
695
        @history    humkyung 2018.07.20 display combobox when key is 'Stream No'
696
    '''
697
    def initLineNoCell(self, lineNoItem):
698
        appDocData = AppDocData.instance()
699
        configs = appDocData.getConfigs('Line No', 'Configuration')
700
        configs = configs[0].value.split('"-"')
701

  
702
        item = QTableWidgetItem(str(lineNoItem.uid))
703
        item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable)
704
        self.setItem(0, 3, item)
705

  
706
        self.show_item_properties(lineNoItem)
707
        
708
        row = self.rowCount()
709
        attrs = lineNoItem.getAttributes()
710
        self.setRowCount(row + len(attrs))
711
        if attrs is not None:
712
            for key in attrs.keys():
713
                item = QTableWidgetItem(key.DisplayAttribute if key.DisplayAttribute else key.Attribute)
714
                item.setFlags(Qt.ItemIsEnabled)
715
                item.setBackground(Qt.lightGray)
716
                item.tag = key
717
                self.setItem(row, 1, item)
718

  
719
                """ show icon item """
720
                self.show_icon_item(row, 2, key)
721

  
722
                # value cell
723
                value = attrs[key]
724
                valueCell = QTableWidgetItem(value)
725

  
726
                # UID로 확인
727
                keyStr = appDocData.getLinePropertiesByUID(key.UID)
728
                if keyStr:
729
                    # editable value cell
730
                    if keyStr[0].AttributeType == 'String':
731
                        pass
732
                        #self.attrValueList.append((valueCell, key.Attribute))
733
                        #self.stringCell.append(valueCell)
734
                    if keyStr[0].UID in configs: valueCell.setFlags(Qt.ItemIsEnabled)
735
                else:
736
                    valueCell.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable)
737
                 
738
                if key.Attribute.upper() == 'STREAM_NO':
739
                    self.streamNoComboBox = QComboBox()
740
                    self.streamNoComboBox.tag = key
741
                    self.streamNoComboBox.currentIndexChanged.connect(self.onStreamNoChanged)
742
                    
743
                    streamNos = sorted(list(appDocData.hmbTable.streamNos()))
744
                    for streamNo in streamNos:
745
                        self.streamNoComboBox.addItem(streamNo)
746
                    self.setCellWidget(row, 3, self.streamNoComboBox)
747
                    self.streamNoComboBox.setCurrentText(value)
748
                    
749
                self.setItem(row, 3, valueCell)
750

  
751
                row = row + 1
752

  
753
    '''
754
        @brief  change selected lines' stream no by selected stream no
755
        @author humkyung
756
        @date   2018.07.20
757
    '''
758
    def onStreamNoChanged(self, param):
759
        items = self.mainWindow.graphicsView.scene.selectedItems()
760
        if items is not None and len(items) == 1:
761
            if type(items[0]) is QEngineeringLineNoTextItem:
762
                stream_no = self.streamNoComboBox.itemText(param)
763
                items[0].set_attrib(self.streamNoComboBox.tag, stream_no)
764
                return
765

  
766
    '''
767
        @brief      Initialize Run Contents Cell
768
        @author     humkyung 
769
        @date       2018.05.27
770
    '''
771
    def initLineRunCell(self, item):
772
        self.setRowCount(1)
773

  
774
        lineTypeItem = QTableWidgetItem(self.tr("Line Type"))
775
        lineTypeItem.setBackground(Qt.lightGray)
776
        lineTypeItem.setFlags(Qt.ItemIsEnabled)
777
        self.setItem(0, 1, lineTypeItem)
778

  
779
    '''
780
        @brief      Key Press Event
781
        @author     kyouho
782
        @date       2018.07.19
783
    '''
784
    def keyPressEvent(self, event):
785
        from SymbolAttr import SymbolAttr
786

  
787
        if event.key() == Qt.Key_Delete:
788
            items = self.mainWindow.graphicsView.scene.selectedItems()
789
            selectedIndexes = self.selectedIndexes()
790
            if selectedIndexes[0].column() == 3 and self.item(selectedIndexes[0].row(), 1).text() == 'OWNER':
791
                items[0].owner = None
792
                self.show_item_property(items[0])
793
            #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:
794
            #    if selectedIndexes[0].column() == 3:
795
            #        attributeStr = self.item(selectedIndexes[0].row(), 1).text()
796
            #        items[0].removeSelfAttr(attributeStr)
797
            #        self.mainWindow.refreshResultPropertyTableWidget()
798
            elif len(items) == 1 and len(selectedIndexes) == 1 and (type(items[0]) is QEngineeringLineItem or issubclass(type(items[0]), SymbolSvgItem)):
799
                key_cell = self.item(selectedIndexes[0].row(), 1)
800
                data = key_cell.data(Qt.UserRole)
801
                if selectedIndexes[0].column() == 3 and key_cell.text().find('CONN') is 0:
802
                    selectedUID = self.item(selectedIndexes[0].row(), 1).text()
803
                    connNum = int(key_cell.text().replace('CONN', ''))
804
                    items[0].connectors[connNum - 1].connectedItem = None
805
                    self.show_item_property(items[0])
806

  
807
                    for sceneItem in self.mainWindow.graphicsView.scene.items():
808
                        if hasattr(sceneItem, 'uid') and str(sceneItem.uid) == selectedUID and hasattr(sceneItem, 'connectors'):
809
                            for sceneConnector in sceneItem.connectors:
810
                                if sceneConnector.connectedItem is not None and items[0].uid == sceneConnector.connectedItem.uid:
811
                                    sceneConnector.connectedItem = None
812
                elif selectedIndexes[0].column() == 3 and data and type(data) is SymbolAttr:
813
                    for _attr,_value in items[0].attrs.items():
814
                        if str(_attr.UID) == str(data.UID):
815
                            items[0].remove_assoc_item(_attr.AssocItem)
816
                            if type(_attr.AssocItem) is QEngineeringTextItem:
817
                                _attr.AssocItem.owner = None
818
                            _attr.AssocItem = None
819
                            items[0].attrs[_attr] = ''
820
                            self.show_item_property(items[0])
821
                            break
822
            elif len(items) == 1 and len(selectedIndexes) == 1 and type(items[0]) is QEngineeringSpecBreakItem:
823
                keyCell = self.item(selectedIndexes[0].row(), 1)
824
                if selectedIndexes[0].column() == 3 and (keyCell.text() == 'UpStream' or keyCell.text() == 'DownStream'):
825
                    for attr in items[0].attrs.keys():
826
                        if attr.Attribute == keyCell.text():
827
                            items[0].attrs[attr] = None
828
                    self.show_item_property(items[0])
829
        elif (event.key() == Qt.Key_C) and (event.modifiers() & Qt.ControlModifier):
830
            self.copy_cells_to_clipboard()
831
            event.accept()
832

  
833
    def copy_cells_to_clipboard(self):
834
        """ copy selected text to clipboard """
835

  
836
        selection = self.selectedIndexes()
837
        if selection:
838
            rows = sorted(index.row() for index in selection)
839
            columns = sorted(index.column() for index in selection)
840
            text = self.item(rows[-1], columns[-1]).text()
841
            QApplication.clipboard().setText(text)
842

  
843
    '''
844
        @brief      int cell check
845
        @author     kyouho
846
        @date       2018.08.20
847
    '''
848
    def cellChangedEvent(self, row, column):
849
        from SymbolAttr import SymbolProp
850
        from SymbolAttr import SymbolAttr
851

  
852
        try:
853
            if column == 3:
854
                item = self.item(row, 1)
855
                data = item.data(Qt.UserRole) if item is not None else None
856
                if data is not None:
857
                    if self._item:
858
                        if type(data) is SymbolProp:
859
                            if data.AttributeType != 'Boolean':
860
                                self._item.set_property(data.Attribute, self.item(row, column).text())
861
                            else:
862
                                self._item.set_property(data.Attribute, self.cellWidget(row, column).isChecked())
863
                        elif type(data) is SymbolAttr:
864
                            if data.AttributeType != 'Boolean':
865
                                self._item.set_attrib(data, self.item(row, column).text())
866
                            else:
867
                                self._item.set_attrib(data, self.cellWidget(row, column).isChecked())
868
        except Exception as ex:
869
            from App import App
870
            from AppDocData import MessageType
871

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

  
875
    '''
876
        @brief      resultPropertyTableWidget Cell Double Click Event
877
        @author     kyouho
878
        @date       2018.07.19
879
        @history    euisung  2019.01.15  edit specbreak
880
    '''
881
    def cellDoubleClickedEvent(self, row, column):
882
        from SymbolAttr import SymbolProp
883

  
884
        if column == 2:
885
            items = self.mainWindow.graphicsView.scene.selectedItems()
886
            keyCell = self.item(row, 1)
887
            attr = keyCell.data(Qt.UserRole)
888
            if hasattr(keyCell, 'tag') and type(items[0]) is not QEngineeringSpecBreakItem:
889
                attr = keyCell.tag
890
                if attr.is_selectable:
891
                    cmd = SelectAttributeCommand.SelectAttributeCommand(items[0], attr, self.mainWindow.graphicsView)
892
                    cmd.onSuccess.connect(self.onSuccessSelectAttribute)
893
                    self.mainWindow.graphicsView.command = cmd
894
                elif self.item(row, column).flags() != Qt.ItemIsEnabled: 
895
                    self.editItem(self.item(row, column))
896
            elif keyCell.text() == 'CONN' and type(items[0]) is QEngineeringLineNoTextItem:
897
                from SymbolAttr import SymbolAttr
898
                attr = SymbolAttr()
899
                attr.AttributeType = "Line Item"
900
                cmd = SelectAttributeCommand.SelectAttributeCommand(items[0], attr, self.mainWindow.graphicsView)
901
                cmd.onSuccess.connect(self.onSuccessSelectAttribute)
902
                self.mainWindow.graphicsView.command = cmd
903
            elif keyCell.text() == 'OWNER' and ((type(items[0]) is QEngineeringLineItem) or (issubclass(type(items[0]), SymbolSvgItem)) or (issubclass(type(items[0]), QEngineeringTextItem))):
904
                attr = keyCell.data(Qt.UserRole)
905
                cmd = SelectAttributeCommand.SelectAttributeCommand(items[0], attr, self.mainWindow.graphicsView)
906
                cmd.onSuccess.connect(self.onSuccessSelectAttribute)
907
                self.mainWindow.graphicsView.command = cmd
908
            elif type(items[0]) is QEngineeringSpecBreakItem:
909
                if keyCell.text() == 'UpStream' or keyCell.text() == 'DownStream':
910
                    attr = keyCell.data(Qt.UserRole)
911
                    cmd = SelectAttributeCommand.SelectAttributeCommand(items[0], attr, self.mainWindow.graphicsView)
912
                    cmd.onSuccess.connect(self.onSuccessSelectAttribute)
913
                    self.mainWindow.graphicsView.command = cmd
914

  
915
                elif keyCell.text() == 'Set Specs':
916
                    from SpecBreakDialog import QSpecBreakDialog
917

  
918
                    try:
919
                        dialog = QSpecBreakDialog(self, items[0])
920
                        dialog.exec_()
921
                        self.show_item_property(items[0])
922
                    except Exception as ex:
923
                        print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno))
924
            elif issubclass(type(attr), SymbolProp):
925
                attr = keyCell.data(Qt.UserRole)
926
                cmd = SelectAttributeCommand.SelectAttributeCommand(items[0], attr, self.mainWindow.graphicsView)
927
                cmd.onSuccess.connect(self.onSuccessSelectAttribute)
928
                self.mainWindow.graphicsView.command = cmd
929

  
930
    '''
931
        @brief      success select attribute 
932
        @author     kyouho
933
        @date       2018.10.23
934
    '''
935
    def onSuccessSelectAttribute(self, connItem = None):
936
        """ update item's properties after selecting """
937
        self.show_item_property(self._item)
HYTOS/HYTOS/UI/MainWindow.ui
224 224
   <addaction name="actionZoom"/>
225 225
   <addaction name="actionFitWindow"/>
226 226
  </widget>
227
  <widget class="QDockWidget" name="dockWidgetPropertyExplorer">
228
   <property name="windowTitle">
229
    <string>Property Explorer</string>
230
   </property>
231
   <attribute name="dockWidgetArea">
232
    <number>1</number>
233
   </attribute>
234
   <widget class="QWidget" name="dockWidgetContents_4">
235
    <layout class="QGridLayout" name="gridLayout_3" rowstretch="20,80">
236
     <item row="1" column="0">
237
      <layout class="QVBoxLayout" name="verticalLayoutProperty"/>
238
     </item>
239
     <item row="0" column="0">
240
      <layout class="QHBoxLayout" name="horizontalLayout_2">
241
       <item>
242
        <widget class="QLabel" name="label">
243
         <property name="font">
244
          <font>
245
           <weight>50</weight>
246
           <bold>false</bold>
247
          </font>
248
         </property>
249
         <property name="text">
250
          <string>Tag No. </string>
251
         </property>
252
        </widget>
253
       </item>
254
       <item>
255
        <widget class="QLineEdit" name="lineEdit">
256
         <property name="font">
257
          <font>
258
           <weight>50</weight>
259
           <bold>false</bold>
260
          </font>
261
         </property>
262
         <property name="text">
263
          <string/>
264
         </property>
265
         <property name="alignment">
266
          <set>Qt::AlignCenter</set>
267
         </property>
268
        </widget>
269
       </item>
270
      </layout>
271
     </item>
272
    </layout>
273
   </widget>
274
  </widget>
275 227
  <action name="actionOpen">
276 228
   <property name="icon">
277 229
    <iconset resource="../res/MainWindow.qrc">

내보내기 Unified diff

클립보드 이미지 추가 (최대 크기: 500 MB)