프로젝트

일반

사용자정보

개정판 3da613fe

ID3da613fe1c4dae7e875d7c12b85e8e76c8264c75
상위 e2573363
하위 20018a10

백흠경이(가) 약 5년 전에 추가함

issue #640: 'Combined' 속성 타입 추가
- 속성 이름, Attr At에 Validator 설정

Change-Id: I294c240ee77d269c91fb181121209714d934281e

차이점 보기:

DTI_PID/DTI_PID/Shapes/EngineeringAbstractItem.py
225 225
        return res
226 226
    
227 227
    def getAttributes(self):
228
        """calculate all attributes of item"""
229
        import re
230

  
228 231
        _attrs = {}
229 232
        try:
230 233
            from AppDocData import AppDocData
......
236 239
            from EngineeringLineNoTextItem import QEngineeringLineNoTextItem
237 240

  
238 241
            """ get attributes of item from database """
239
            docData = AppDocData.instance()
242
            app_doc_data = AppDocData.instance()
240 243
            if type(self) is QEngineeringLineItem:
241
                symbolAttrs =  docData.getSymbolAttribute('Line')
244
                symbolAttrs = app_doc_data.getSymbolAttribute('Line')
242 245
            elif type(self) is QEngineeringVendorItem:
243
                symbolAttrs =  docData.getSymbolAttribute('Package')
246
                symbolAttrs = app_doc_data.getSymbolAttribute('Package')
244 247
            elif type(self) is QEngineeringLineNoTextItem:
245
                symbolAttrs =  docData.getSymbolAttribute('Line No')
248
                symbolAttrs = app_doc_data.getSymbolAttribute('Line No')
246 249
                self.getLineNoAttributes(_attrs)
247 250
            else:
248
                symbolAttrs = docData.getSymbolAttribute(self.type)
251
                symbolAttrs = app_doc_data.getSymbolAttribute(self.type)
252

  
249 253
            targetAttrs = []
250
            if not (type(self) is QEngineeringLineItem or type(self) is QEngineeringVendorItem or type(self) is QEngineeringLineNoTextItem):
254
            if not (type(self) is QEngineeringLineItem or type(self) is QEngineeringVendorItem or
255
                    type(self) is QEngineeringLineNoTextItem):
251 256
                for attr in symbolAttrs:
252
                    if attr.Target is None or attr.Target == 'ALL' or [target for target in attr.Target.split(',') if self.dbUid is int(target)]:
257
                    if attr.Target is None or attr.Target == 'ALL' or \
258
                            [target for target in attr.Target.split(',') if self.dbUid is int(target)]:
253 259
                        targetAttrs.append(attr)
254 260
            else:
255 261
                targetAttrs = symbolAttrs
256 262

  
257 263
            _texts = self.texts()
258 264
            _symbols = self.symbols()
259
            for attr in targetAttrs:
260
                matches = [_attr for _attr,_ in self.attrs.items() if _attr.UID == attr.UID]
265
            for attr in [_attr for _attr in targetAttrs if _attr.AttributeType != 'Combined']:
266
                matches = [_attr for _attr, _ in self.attrs.items() if _attr.UID == attr.UID]
261 267
                if matches:
262 268
                    attr.Freeze = matches[0].Freeze         # update freeze value
263 269
                    attr.AssocItem = matches[0].AssocItem
......
294 300
                    else:
295 301
                        item = attr.AssocItem = self.get_assoc_item(attr.AssocItem)
296 302
                        _attrs[attr] = eval(attr.Expression) if attr.Expression and ((item and 'item' in attr.Expression) or 'self' in attr.Expression) else ''
297
                elif attr.AttributeType == 'Symbol Item' or attr.AttributeType == 'Line Item' or attr.AttributeType == 'Comp Item' or attr.AttributeType == 'EQ Item':
303
                elif attr.AttributeType == 'Symbol Item' or attr.AttributeType == 'Line Item' or \
304
                        attr.AttributeType == 'Comp Item' or attr.AttributeType == 'EQ Item':
298 305
                    at = int(attr.AttrAt)
299 306
                    if not attr.AssocItem and len(_symbols) > at:
300 307
                        attr.AssocItem = _symbols[at]
......
305 312
                        _attrs[attr] = eval(attr.Expression) if attr.Expression else ''
306 313
                    else:
307 314
                        _attrs[attr] = ''
308
                #elif attr.AttributeType == 'Tag No':
309
                #    _attrs[attr] = eval(attr.Expression) if attr.Expression and not _attrs[attr] else _attrs[attr]
310 315
                elif attr.AttributeType == 'String':
311 316
                    _attrs[attr] = attr.Expression if attr.Expression and not _attrs[attr] else _attrs[attr]
312 317

  
313
            for _attr,_value in _attrs.items():
318
            """calculate attribute value for combined type"""
319
            p = re.compile('{[A-Za-z0-9]+}')
320
            for attr in [_attr for _attr in targetAttrs if _attr.AttributeType == 'Combined']:
321
                value, pos = '', 0
322

  
323
                matches = p.finditer(attr.Expression)
324
                for match in matches:
325
                    attr_name = attr.Expression[(match.start() + 1):(match.end() - 1)]
326
                    values = [value for key, value in _attrs.items() if key.Attribute == attr_name]
327
                    value += attr.Expression[pos:match.start()] + values[0] if values else ''
328
                    pos = match.end()
329

  
330
                value += attr.Expression[pos:len(attr.Expression)]
331
                _attrs[attr] = value
332
            """up to here"""
333

  
334
            for _attr, _value in _attrs.items():
314 335
                if _value is None or _value == '':
315 336
                    _attr.AssocItem = None
316 337

  
......
326 347

  
327 348
    def attrib(self, name):
328 349
        """ return the value of given attribute with name """
329
        matches = [(attr,value) for attr,value in self.getAttributes().items() if attr.Attribute == name]
350
        matches = [(attr, value) for attr, value in self.getAttributes().items() if attr.Attribute == name]
330 351
        if matches: return matches[0][1]
331 352

  
332 353
        return None
333 354

  
334 355
    def set_attrib(self, attrib, value):
335 356
        """ set attribute with given value """
336
        matches = [attr for attr,_ in self.attrs.items() if attr.UID == attrib.UID]
357
        matches = [attr for attr, _ in self.attrs.items() if attr.UID == attrib.UID]
337 358
        if len(matches) == 1: self.attrs[matches[0]] = value
338 359

  
339 360
    @staticmethod
......
546 567

  
547 568
    def center(self):
548 569
        return self.sceneBoundingRect().center()
570

  
571

  
572
if __name__ == '__main__':
573
    import re
574

  
575
    p = re.compile('{[A-Za-z0-9]+}')
576
    value, pos = '', 0
577

  
578
    _attrs = {'a': '~', 'b': '!', 'C': '+'}
579
    expression = 'XXXXXXX{a}-{b}-{C}----'
580
    matches = p.finditer(expression)
581
    for match in matches:
582
        attr_name = expression[(match.start() + 1):(match.end() - 1)]
583
        value += expression[pos:match.start()] + _attrs[attr_name]
584
        pos = match.end()
585

  
586
    value += expression[pos:len(expression)]
587
    print(value)
DTI_PID/DTI_PID/Shapes/SymbolSvgItem.py
1153 1153
            self.grabMouse()
1154 1154

  
1155 1155
    '''
1156
        @brief      get attribute
1157
        @author     humkyung
1158
        @date       2018.06.14
1159
        @history    kyouho  2018.07.18  Add only attr QEngineeringTextItem
1160
    '''
1161
    '''
1162
    def getAttributes(self):
1163
        _attrs = {}
1164
        try:
1165
            from AppDocData import AppDocData
1166
            from EngineeringAbstractItem import QEngineeringAbstractItem
1167
            from EngineeringTextItem import QEngineeringTextItem
1168
            from EngineeringValveOperCodeTextItem import QEngineeringValveOperCodeTextItem
1169

  
1170
            """ get attributes of item from database """
1171
            docData = AppDocData.instance()
1172
            symbolAttrs = docData.getSymbolAttribute(self.type)
1173

  
1174
            _texts = self.texts()
1175
            _symbols = self.symbols()
1176
            for attr in symbolAttrs:
1177
                matches = [_attr for _attr,_ in self.attrs.items() if _attr.UID == attr.UID]
1178
                if matches:
1179
                    attr.Freeze = matches[0].Freeze         ### update freeze value
1180
                    attr.AssocItem = matches[0].AssocItem
1181
                    _attrs[attr] = self.attrs[matches[0]]   ### copy attribute value
1182
                else:
1183
                    _attrs[attr] = ''
1184
 
1185
                if attr.Freeze: continue    ### do not evalulate value if attribute is frozen
1186
                if attr.AttributeType == 'Size Text Item' or attr.AttributeType == 'Text Item' or attr.AttributeType == 'Valve Oper Code':
1187
                    at = int(attr.AttrAt)
1188
                    items = [text for text in _texts if QEngineeringAbstractItem.assoc_type(text) == attr.AttributeType]
1189
                    if not attr.AssocItem and len(items) > at:
1190
                        attr.AssocItem = items[at]
1191
                        item = attr.AssocItem
1192
                        _attrs[attr] = eval(attr.Expression) if attr.Expression else ''
1193
                    elif attr.AssocItem:
1194
                        item = attr.AssocItem
1195
                        _attrs[attr] = eval(attr.Expression) if attr.Expression else ''
1196
                    else:
1197
                        _attrs[attr] = ''
1198
                elif attr.AttributeType == 'Symbol Item':
1199
                    at = int(attr.AttrAt)
1200
                    if not attr.AssocItem and len(_symbols) > at:
1201
                        attr.AssocItem = _symbols[at]
1202
                        item = attr.AssocItem
1203
                        _attrs[attr] = eval(attr.Expression) if attr.Expression else ''
1204
                    elif attr.AssocItem:
1205
                        item = attr.AssocItem
1206
                        _attrs[attr] = eval(attr.Expression) if attr.Expression else ''
1207
                    else:
1208
                        _attrs[attr] = ''
1209
            
1210
            self.attrs = _attrs ### assign self.attrs
1211
        except Exception as ex:
1212
            from App import App 
1213
            from AppDocData import MessageType
1214

  
1215
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)
1216
            App.mainWnd().addMessage.emit(MessageType.Error, message)
1217
        
1218
        return self.attrs
1219
    '''
1220

  
1221
    '''
1222 1156
        @brief      generate xml code
1223 1157
        @author     humkyung
1224 1158
        @date       2018.04.23
DTI_PID/DTI_PID/SymbolAttr.py
1 1
# coding: utf-8
2 2
""" This is Symbol Attribute module """
3 3

  
4

  
4 5
class SymbolProp:
5 6
    """ This is symbol property class """
6 7

  
......
12 13
        self.Attribute = Attribute
13 14
        self.AttributeType = AttributType
14 15
        self.DisplayAttribute = DisplayAttribute if DisplayAttribute else Attribute
15
        self.Length = Length 
16
        self.Expression = Expression 
16
        self.Length = Length
17
        self.Expression = Expression
17 18

  
18 19
    @property
19 20
    def is_selectable(self):
20 21
        """ return if attribute is selectable """
21 22
        from SymbolAttrEditorDialog import QSymbolAttrEditorDialog
22 23

  
23
        return (self.AttributeType in [key for key,value in QSymbolAttrEditorDialog.SYMBOL_ATTR_DATA_TYPES.items() if value == -1])
24
        return (self.AttributeType in [key for key, value in QSymbolAttrEditorDialog.SYMBOL_ATTR_DATA_TYPES.items() if
25
                                       value == -1])
24 26

  
25 27
    def match_type(self, item):
26 28
        """ check if given item's attribute type matches """
......
43 45
    def parse_record(self, record):
44 46
        """ parse record for property """
45 47
        import uuid
46
        
48

  
47 49
        self.UID = uuid.UUID(record['UID'])
48 50
        self.Freeze = record['Freeze'] == 'True' if record['Freeze'] else False
49 51
        self.Attribute = record['Attribute']
......
55 57
    def parse_xml(self, node):
56 58
        """ parse xml node for property """
57 59
        import uuid
58
        
60

  
59 61
        self.UID = uuid.UUID(node.attrib['UID'])
60 62
        self.Freeze = node.attrib['Freeze'] == 'True' if 'Freeze' in node.attrib else False
61 63
        self.Attribute = node.attrib['Attribute']
......
87 89
        False
88 90
        """
89 91
        try:
90
            uuid_obj = uuid.UUID(value)#, version=version)
92
            uuid_obj = uuid.UUID(value)  # , version=version)
91 93
        except:
92 94
            return False
93 95

  
94
        return str(uuid_obj) == value 
96
        return str(uuid_obj) == value
95 97

  
96 98
    def parse_value(self, text):
97 99
        """ parse value of property """
......
117 119

  
118 120
        return node
119 121

  
122

  
120 123
class SymbolAttr(SymbolProp):
121 124
    """ This is symbol attribute class """
125

  
122 126
    def __init__(self):
123 127
        import uuid
124 128
        SymbolProp.__init__(self, None, None, None)
......
140 144
    def from_record(record):
141 145
        """ parse record for property """
142 146
        import uuid
143
        
147

  
144 148
        attr = SymbolAttr()
145 149
        attr.UID = uuid.UUID(record['UID'])
146 150
        attr.Freeze = record['Freeze'] == 'True' if record['Freeze'] else False
......
151 155
        attr.Expression = record['Expression']
152 156
        attr.Length = record['Length'] if 'Length' in record else 0
153 157
        attr.IsProp = int(record['Property']) if record['Property'] else 0
154
        attr.AssocItem = uuid.UUID(record['Association_UID']) if record['Association_UID'] and record['Association_UID'] != 'None' else None
158
        attr.AssocItem = uuid.UUID(record['Association_UID']) if record['Association_UID'] and record[
159
            'Association_UID'] != 'None' else None
155 160

  
156 161
        return attr
157 162

  
......
169 174
        attr.AttrAt = node.attrib['AttrAt']
170 175
        attr.Expression = node.attrib['Expression']
171 176
        attr.Length = node.attrib['Length']
172
        attr.AssocItem = uuid.UUID(node.attrib['AssocItem']) if 'AssocItem' in node.attrib and node.attrib['AssocItem'] != '' else None
177
        attr.AssocItem = uuid.UUID(node.attrib['AssocItem']) if 'AssocItem' in node.attrib and node.attrib[
178
            'AssocItem'] != '' else None
173 179

  
174 180
        return attr
175 181

  
......
188 194
        node.attrib['Length'] = str(self.Length) if self.Length is not None else ''
189 195
        node.attrib['AssocItem'] = str(self.AssocItem) if self.AssocItem is not None else ''
190 196

  
191
        return node
197
        return node
DTI_PID/DTI_PID/SymbolAttrEditorDialog.py
17 17
import SymbolAttrEditor_UI
18 18

  
19 19

  
20
class AttributeDelegate(QStyledItemDelegate):
21
    def createEditor(self, parent, option, index):
22
        editor = super(AttributeDelegate, self).createEditor(parent, option, index)
23
        if index.column() == 1:
24
            editor = QLineEdit(parent)
25
            validator = QRegExpValidator(QRegExp('^[A-Za-z0-9]+$'), parent)
26
            editor.setValidator(validator)
27
        elif index.column() == 4:
28
            editor = QLineEdit(parent)
29
            validator = QRegExpValidator(QRegExp('^(\\d+|)$'), parent)
30
            editor.setValidator(validator)
31

  
32
        return editor
33

  
34
    """
35
    def setEditorData(self, editor, index):
36
        if index.column() == 4:
37
            m = 0 if index.column() == 1 else index.sibling(index.row(), 1).data()
38
            M = index.sibling(index.row(), 2).data() if index.column() == 1 else 360
39
            if hasattr(m, 'toPyObject'):
40
                m = m.toPyObject()
41
            if hasattr(M, 'toPyObject'):
42
                M = M.toPyObject()
43
            editor.setMinimum(m)
44
            editor.setMaximum(M)
45
        super(LimistDelegate, self).setEditorData(editor, index)
46
    """
47

  
48

  
20 49
class QSymbolAttrEditorDialog(QDialog):
21 50
    """ This is symbol attribute editor dialog class """
22 51

  
23 52
    SYMBOL_ATTR_DATA_TYPES = {'Symbol Item': -1, 'Size Text Item': -1, 'Text Item': -1, 'Tag No': -1,
24 53
                              'Valve Oper Code': -1, 'Line Item': -1, 'Comp Item': -1, 'EQ Item': -1, 'Int': 1,
25
                              'String': 1}
54
                              'String': 1, 'Combined': 1}
26 55
    LINE_NO_ATTR_TYPES = ['Code Table', 'Int', 'String', 'Symbol']
27 56

  
28
    def __init__(self, parent, symbolType=None):
57
    def __init__(self, parent, symbolType = None):
29 58
        QDialog.__init__(self, parent)
30 59

  
31 60
        self.ui = SymbolAttrEditor_UI.Ui_SymbolAttrEditorDialog()
......
42 71
            self.ui.tableWidgetAttr.setRowCount(0)
43 72
            self.ui.tableWidgetAttr.verticalHeader().setVisible(False)
44 73
            self.ui.horizontalLayout_2.addWidget(self.ui.tableWidgetAttr)
74
            delegate = AttributeDelegate(self.ui.tableWidgetAttr)
75
            self.ui.tableWidgetAttr.setItemDelegate(delegate)
45 76
            # up to here
46 77
            # combobox logic
47 78
            self.settingComboBoxSymbolType(symbolType[2])
......
79 110

  
80 111
    def cell_double_clicked(self, row, column):
81 112
        if self._symbolType is None or not (column is 6 or column is 7): return
82
        if hasattr(self.ui.tableWidgetAttr.item(row, 0), 'tag') and self.ui.tableWidgetAttr.item(row,
83
                                                                                                 0).tag.IsProp == 2: return
113
        if hasattr(self.ui.tableWidgetAttr.item(row, 0), 'tag') and \
114
                self.ui.tableWidgetAttr.item(row, 0).data(Qt.UserRole).IsProp == 2: return
84 115

  
85 116
        from SymbolAttrTargetDialog import SymbolAttrTargetDialog
86 117
        from SymbolAttrCodeTableDialog import SymbolAttrCodeTableDialog
......
89 120
        try:
90 121
            # code table setting
91 122
            if column == 7:
92
                dialog = SymbolAttrCodeTableDialog(self, str(self.ui.tableWidgetAttr.item(row, 0).tag.UID),
93
                                                   tableDatas=self.ui.tableWidgetAttr.item(row, 7).tag)
123
                dialog = SymbolAttrCodeTableDialog(self, str(self.ui.tableWidgetAttr.item(row, 0).data(Qt.UserRole).UID),
124
                                                   tableDatas=self.ui.tableWidgetAttr.item(row, 7).data(Qt.UserRole))
94 125
                (isAccept, code_data) = dialog.showDialog()
95 126

  
96 127
                if isAccept:
97
                    self.ui.tableWidgetAttr.item(row, 7).tag = code_data
128
                    self.ui.tableWidgetAttr.item(row, 7).setData(Qt.UserRole, code_data)
98 129

  
99 130
                graphicsView = App.mainWnd().graphicsView
100 131
                if dialog.code_area:
......
108 139
            elif column == 6:
109 140
                symbolType = self.ui.comboBoxSymbolType.currentText()
110 141

  
111
                dialog = SymbolAttrTargetDialog(self, symbolType, self.ui.tableWidgetAttr.item(row, 6).tag)
142
                dialog = SymbolAttrTargetDialog(self, symbolType, self.ui.tableWidgetAttr.item(row, 6).data(Qt.UserRole))
112 143
                (isAccept, target) = dialog.showDialog()
113 144

  
114 145
                if isAccept:
115
                    self.ui.tableWidgetAttr.item(row, 6).tag = target
146
                    self.ui.tableWidgetAttr.item(row, 6).setData(Qt.UserRole, target)
116 147
                    if target == 'ALL':
117 148
                        self.ui.tableWidgetAttr.item(row, 6).setText('ALL')
118 149
                    else:
......
158 189
        self.loadData(self._symbolType)
159 190

  
160 191
    def loadData(self, symbolType):
161
        """
162
        @brief      load data
163
        @author     humkyung
164
        @date       2018.08.14
165
        @history    humkyung 2018.10.13 add expression
166
        """
192
        """load data from database"""
167 193

  
168
        appDocData = AppDocData.instance()
194
        app_doc_data = AppDocData.instance()
169 195

  
170
        self.currentTypeId = appDocData.getSymbolTypeId(symbolType)
196
        self.currentTypeId = app_doc_data.getSymbolTypeId(symbolType)
171 197

  
172
        attrs = appDocData.getSymbolAttribute(symbolType)
198
        attrs = app_doc_data.getSymbolAttribute(symbolType)
173 199
        self.ui.tableWidgetAttr.setRowCount(len(attrs))
174 200

  
175 201
        row = 0
176 202
        for attr in attrs:
177 203
            item = QTableWidgetItem(str(attr.UID))  # UID
178
            item.tag = attr
204
            item.setData(Qt.UserRole, attr)
205
            #item.tag = attr
179 206
            self.ui.tableWidgetAttr.setItem(row, 0, item)
180 207
            item = QTableWidgetItem(attr.Attribute)  # Name
181 208
            if attr.IsProp >= 2:
......
212 239
            self.ui.tableWidgetAttr.setItem(row, 5, item)
213 240

  
214 241
            item = QTableWidgetItem('ALL') if attr.Target == 'ALL' or attr.Target is None else QTableWidgetItem('...')
215
            item.tag = attr.Target
242
            item.setData(Qt.UserRole, attr.Target)
243
            #item.tag = attr.Target
216 244
            item.setTextAlignment(Qt.AlignHCenter)
217 245
            item.setFlags(Qt.ItemIsEnabled)
218 246
            self.ui.tableWidgetAttr.setItem(row, 6, item)
219 247

  
220 248
            item = QTableWidgetItem('...')
221
            item.tag = attr.Codes.values
249
            item.setData(Qt.UserRole, attr.Codes.values)
250
            #item.tag = attr.Codes.values
222 251
            item.setTextAlignment(Qt.AlignHCenter)
223 252
            item.setFlags(Qt.ItemIsEnabled)
224 253
            self.ui.tableWidgetAttr.setItem(row, 7, item)
225 254

  
226 255
            row = row + 1
227 256

  
228
    def saveData(self):
257
    def save_data(self):
229 258
        """save symbol attributes"""
230 259

  
231
        app_doc_data = AppDocData.instance()
232

  
233
        attrs = []
234
        table = self.ui.tableWidgetAttr
235

  
236
        for index in range(table.rowCount()):
237
            attr = []
238
            attr.append(table.item(index, 0).text() if table.item(index, 0) is not None else '')
239
            attr.append(table.item(index, 1).text() if table.item(index, 1) is not None else '')
240
            attr.append(table.item(index, 2).text() if table.item(index, 2) is not None else '')
241

  
242
            attr_data_type = table.cellWidget(index, 3).currentText() if table.cellWidget(index, 3) else \
243
                table.item(index, 3).text()
244
            attr.append(attr_data_type)
245

  
246
            attr_at = table.item(index, 4).text() if table.item(index, 4) is not None else ''
247
            if attr_data_type in ['Text Item', 'Symbol Item'] and not attr_at:
248
                QMessageBox.information(self, 'Information', f"'Attr At' must be set for {attr_data_type}")
249
                return False
250

  
251
            attr.append(attr_at)  # Attribute At
260
        try:
261
            app_doc_data = AppDocData.instance()
262

  
263
            attrs = []
264
            table = self.ui.tableWidgetAttr
265

  
266
            for index in range(table.rowCount()):
267
                attr = []
268
                attr.append(table.item(index, 0).text() if table.item(index, 0) is not None else '')
269
                attr.append(table.item(index, 1).text() if table.item(index, 1) is not None else '')
270
                attr.append(table.item(index, 2).text() if table.item(index, 2) is not None else '')
271

  
272
                attr_data_type = table.cellWidget(index, 3).currentText() if table.cellWidget(index, 3) else \
273
                    table.item(index, 3).text()
274
                attr.append(attr_data_type)
275

  
276
                attr_at = table.item(index, 4).text() if table.item(index, 4) is not None else ''
277
                if attr_data_type in ['Text Item', 'Symbol Item'] and not attr_at:
278
                    QMessageBox.information(self, 'Information', f"'Attr At' must be set for {attr_data_type}")
279
                    return False
280

  
281
                attr.append(attr_at)  # Attribute At
282

  
283
                attr.append(table.item(index, 5).text() if table.item(index, 5) is not None else '')  # Expression
284
                attr.append(table.item(index, 6).data(Qt.UserRole) if table.item(index, 6).data(Qt.UserRole) is not None
285
                            else 'ALL')  # Target
286
                attr.append(index)
287
                attr.append(table.item(index, 0).data(Qt.UserRole).IsProp) if table.item(index, 0).data(Qt.UserRole) else \
288
                    attr.append(0)
289
                attr.append(table.item(index, 7).data(Qt.UserRole))   # code table
290
                attrs.append(attr)
291

  
292
            app_doc_data.saveSymbolAttributes(self.currentTypeId, attrs, self._symbolType)
293
            return True
294
        except Exception as ex:
295
            from App import App
296
            from AppDocData import MessageType
252 297

  
253
            attr.append(table.item(index, 5).text() if table.item(index, 5) is not None else '')  # Expression
254
            attr.append(table.item(index, 6).tag if table.item(index, 6).tag is not None else 'ALL')  # Target
255
            attr.append(index)
256
            attr.append(table.item(index, 0).tag.IsProp) if hasattr(table.item(index, 0), 'tag') else attr.append(0)
257
            attr.append(table.item(index, 7).tag)   # code table
258
            attrs.append(attr)
298
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
299
                                                           sys.exc_info()[-1].tb_lineno)
300
            App.mainWnd().addMessage.emit(MessageType.Error, message)
259 301

  
260
        app_doc_data.saveSymbolAttributes(self.currentTypeId, attrs, self._symbolType)
261
        return True
302
        return False
262 303

  
263 304
    '''
264 305
        @brief  add a attribute
......
280 321
        self.ui.tableWidgetAttr.setCellWidget(rows, 3, attrTypeComboBox)
281 322

  
282 323
        item = QTableWidgetItem('ALL')
283
        item.tag = 'ALL'
324
        item.setData(Qt.UserRole, 'ALL')
284 325
        item.setTextAlignment(Qt.AlignHCenter)
285 326
        item.setFlags(Qt.ItemIsEnabled)
286 327
        self.ui.tableWidgetAttr.setItem(rows, 6, item)
287 328

  
288 329
        item = QTableWidgetItem('...')
289
        item.tag = []
330
        item.setData(Qt.UserRole, [])
290 331
        item.setTextAlignment(Qt.AlignHCenter)
291 332
        item.setFlags(Qt.ItemIsEnabled)
292 333
        self.ui.tableWidgetAttr.setItem(rows, 7, item)
293 334

  
294 335
        attr = SymbolAttr()
295 336
        item = QTableWidgetItem(str(attr.UID))
296
        item.tag = attr
337
        item.setData(Qt.UserRole, attr)
338
        #item.tag = attr
297 339
        self.ui.tableWidgetAttr.setItem(rows, 0, item)
298 340

  
299 341
    '''
......
306 348
        model = self.ui.tableWidgetAttr.model()
307 349
        row = self.ui.tableWidgetAttr.currentRow()
308 350

  
309
        if row != -1 and not (hasattr(self.ui.tableWidgetAttr.item(row, 0), 'tag') and self.ui.tableWidgetAttr.item(row,
310
                                                                                                                    0).tag.IsProp == 2):
351
        if row != -1 and not (hasattr(self.ui.tableWidgetAttr.item(row, 0), 'tag') and
352
                              self.ui.tableWidgetAttr.item(row, 0).data(Qt.UserRole).IsProp == 2):
311 353
            model.removeRow(row)
312 354

  
313 355
    '''
......
318 360

  
319 361
    def accept(self):
320 362
        if self._symbolType is not None:
321
            if not self.saveData():
363
            if not self.save_data():
322 364
                return
323 365
        else:
324 366
            self.saveLineAttrData()

내보내기 Unified diff

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