프로젝트

일반

사용자정보

개정판 24cc2e1e

ID24cc2e1e862112c0581791ffe6c9236e83ad0c06
상위 13ce32a8
하위 5ecf2996

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

issue #000 SymbolTreeWidget.py 수정

1. Category가 'Stream Line' 은 TreeWidget에서 제외
2. Symbol 수정, 삭제 기능 제거

Change-Id: I16edd727c6eae9aa36cd7963a23b1f1d586b44c6

차이점 보기:

HYTOS/HYTOS/SymbolTreeWidget.py
25 25
        QTreeWidget.__init__(self)
26 26
        self.setDragEnabled(True)   # enable drag
27 27
        self.initSymbolTreeWidget()
28
        self.isDoubleClicked = False
29
        self.itemDoubleClicked.connect(self.itemDoubleClickEvent)
30
        self.setContextMenuPolicy(Qt.CustomContextMenu)
31
        self.customContextMenuRequested.connect(self.openContextMenu)
32
        self.currentItemChanged.connect(self.onCurrentItemChanged)
33
            
34
    '''
35
        @brief      Show Context Menu
36
        @author     Jeongwoo
37
        @date       18.04.??
38
        @history    Jeongwoo 2018.04.23 Symbol object Null Check when show context menu
39
                    humkyung 2018.08.14 add menu for symbol type
40
    '''
41
    def openContextMenu(self, position):
42
        indexes = self.selectedIndexes()
43
        itemPosition = self.mapTo(self, position)
44
        item = self.itemAt(itemPosition)
45
        data = item.data(0, self.TREE_DATA_ROLE)
46
        if data is not None and type(data) is symbol.SymbolBase:
47
            sym = self.getSymbolByItemName(item, 0)
48
            text = item.text(0)
49
            if len(indexes) > 0:
50
                level = 0
51
                index = indexes[0]
52
                while index.parent().isValid():
53
                    index = index.parent()
54
                    level += 1
55
            if sym is not None:
56
                menu = QMenu()
57
                editSymbolAction = QAction(self.tr("Edit Symbol"))
58
                editSymbolAction.triggered.connect(lambda: self.editSymbolActionClickEvent(item, 0))
59
                menu.addAction(editSymbolAction)
60
                displaySymbolAction = QAction(self.tr("Display Symbol"))
61
                displaySymbolAction.triggered.connect(lambda: self.displaySymbolActionClickEvent(sym.getType(), text))
62
                menu.addAction(displaySymbolAction)
63
                deleteSymbolAction = QAction(self.tr("Delete Symbol"))
64
                deleteSymbolAction.triggered.connect(lambda: self.deleteSymbolActionClickEvent(sym.getType(), text))
65
                menu.addAction(deleteSymbolAction)
66
                menu.exec_(self.viewport().mapToGlobal(position))
67
        else:
68
            menu = QMenu()
69
            editAttrAction = QAction(self.tr("Edit Attribute"))
70
            editAttrAction.triggered.connect(lambda: self.onEditAttrClicked(item, 0))
71
            menu.addAction(editAttrAction)
72
            menu.exec_(self.viewport().mapToGlobal(position))
73

  
74
    def editSymbolActionClickEvent(self, item, columNo):
75
        self.showSymbolEditorDialog(item, columNo)
76

  
77
    '''
78
        @brief      popup attribute editor dialog
79
        @author     humkyung
80
        @date       2018.08.13
81
    '''
82
    def onEditAttrClicked(self, item, columnNo):
83
        from SymbolAttrEditorDialog import QSymbolAttrEditorDialog
84

  
85
        try:
86
                data = item.data(0, self.TREE_DATA_ROLE)
87

  
88
                dlg = QSymbolAttrEditorDialog(self, data)
89
                dlg.exec_()
90
        except Exception as ex:
91
            from App import App
92

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

  
96
    def displaySymbolActionClickEvent(self, itemType, itemName):
97
        project = AppDocData.instance().getCurrentProject()
98
        image = QImage(os.path.join(project.getImageFilePath(), itemType, itemName, "PNG")) #itemName includes ".png"
99
        dialog = QSymbolDisplayDialog.QSymbolDisplayDialog(image)
100
        dialog.showDialog()
101

  
102
    def deleteSymbolActionClickEvent(self, itemType, itemName):
103
        msg = QMessageBox()
104
        msg.setIcon(QMessageBox.Critical)
105
        msg.setText(self.tr('Are you sure you want to delete selected symbol?\nData can not be restored!'))
106
        msg.setWindowTitle(self.tr('Delete symbol'))
107
        msg.setStandardButtons(QMessageBox.Ok|QMessageBox.Cancel)
108
        result = msg.exec_()
109
        self.handleDeleteSymbolAction(result, itemType, itemName)
110

  
111
    '''
112
        @history    2018.05.03  Jeongwoo    Modify file path with ".png" and ".svg"
113
                                            Use project object when making svgPath
114
    '''
115
    def handleDeleteSymbolAction(self, result, itemType, itemName):
116
        if result == QMessageBox.Ok:
117
            project = AppDocData.instance().getCurrentProject()
118
            imagePath = os.path.join(project.getImageFilePath(), itemType, itemName  + '.png') # itemName DOESN'T includes ".png"
119
            if os.path.exists(imagePath):
120
                os.remove(imagePath)
121

  
122
            svgPath = os.path.join(project.getSvgFilePath(), itemType, itemName + '.svg')
123
            if os.path.exists(svgPath):
124
                os.remove(svgPath)
125

  
126
            AppDocData.instance().deleteSymbol(itemName)
127
            self.initSymbolTreeWidget()
128
        else:
129
            pass
130

  
28
        
131 29
    '''
132 30
        @history    2018.05.02  Jeongwoo    Change return value of QSymbolEditorDialog (Single variable → Tuple)
133 31
    '''
......
135 33
        project = AppDocData.instance().getCurrentProject()
136 34
        if project is not None:
137 35
            self.clear()
138
            projectPath = project.getPath().replace("\\", "/")
139 36
            self.makeChildDir()
140 37
            self.loadSymbolInfo()
141 38
            self.expandAll()
......
147 44
        @history    Jeongwoo 2018.05.03 Get Svg File Path by SymbolBase.getSvgFileFullPath()
148 45
                    humkyung 2018.07.30 sort child items
149 46
    '''
150
    def loadSymbolInfo(self):
151
        
47
    def loadSymbolInfo(self):        
152 48
        try:
153 49
            symbolCategoryList = AppDocData.instance().getSymbolCategoryList()
154 50
            for symbolCategory in symbolCategoryList:
51
                if symbolCategory == 'Stream Line':
52
                    continue
155 53
                parent = QTreeWidgetItem(self, [symbolCategory])
156 54
                parent.setData(0, self.TREE_DATA_ROLE, symbolCategory)
157 55

  
158

  
159

  
160 56
                symbolTypeList = AppDocData.instance().getSymbolTypeListByCategory(symbolCategory)
161 57
                for symbolType in symbolTypeList:
162 58
                    category = QTreeWidgetItem(parent, [symbolType[1]])
......
202 98
            os.makedirs(tempDir)
203 99

  
204 100
    '''
205
        @history    2019.07.11  yeonjin    심벌 편집 시 png 파일이 아닌 svg 파일을 불러 오도록 수정
206
                                            
207
    '''
208
    def showSymbolEditorDialog(self, item, columnNo):
209
        try:
210
            sym = self.getSymbolByItemName(item, columnNo)
211
            if sym is not None:
212
                #path = sym.getPath()
213
                #image = QImage(path, "PNG")
214
                path = sym.getSvgFileFullPath()
215
                image = QImage(path, "SVG")
216
                symbolEditorDialog = SymbolEditorDialog.QSymbolEditorDialog(self, image, AppDocData.instance().getCurrentProject(), sym)
217
                (isAccepted, isImmediateInsert, offsetX, offsetY, newSym) = symbolEditorDialog.showDialog()
218
                self.initSymbolTreeWidget()
219
            else:
220
                QMessageBox.about(self, self.tr('Error'), self.tr('Error occurs during loading symbol data.'))
221
        except Exception as ex:
222
            from App import App
223

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

  
227
    def itemDoubleClickEvent(self, item, columnNo):
228
        self.isDoubleClicked = True
229
        sym = self.getSymbolByItemName(item, columnNo)
230
        itemName = item.text(columnNo)
231
        if sym is not None:
232
            self.showSymbolEditorDialog(item, columnNo)
233
        self.isDoubleClicked = False
234

  
235
    '''
236
        @brief      Get Symbol data by symbol name
237
        @author     Jeongwoo
238
        @date       18.04.20
239
    '''
240
    def getSymbolByItemName(self, item, columnNo):
241
        itemName = item.text(columnNo)
242

  
243
        name = itemName
244
        sym = AppDocData.instance().getSymbolByQuery("name", name)
245
        return sym
246

  
247
    '''
248
        @breif      show symbol's property when selection changed
249
        @author     humkyung
250
        @date       2018.07.30
251
    '''
252
    def onCurrentItemChanged(self, current, previous):
253
        item = self.currentItem()
254
        if item is not None:
255
            data = item.data(0, self.TREE_DATA_ROLE)
256
            if data is not None and type(data) is symbol.SymbolBase:
257
                self.singleClicked.emit(data)
258

  
259
    '''
260 101
        @brief  start drag
261 102
        @author humkyung
262 103
        @date   2018.04.17

내보내기 Unified diff

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