프로젝트

일반

사용자정보

개정판 a3228af3

IDa3228af31b68999a8325ff37ff52d32a9747e1b6
상위 01547c4a
하위 b76eae7a, 173e6080

함의성이(가) 약 5년 전에 추가함

issue #563: unify item properties like attribute

Change-Id: If05bd82eea7a37eb23a9e4db3f7f4635c79d59e3

차이점 보기:

DTI_PID/DTI_PID/Shapes/EngineeringAbstractItem.py
418 418
            if _type in self._associations and item in self._associations[_type]:
419 419
                index = self._associations[_type].index(item)
420 420
                self._associations[_type].pop(index)
421

  
422
    @property
423
    def properties(self):
424
        """ getter of properties """
425
        import uuid
426
        from SymbolSvgItem import SymbolSvgItem
427
        from EngineeringLineItem import QEngineeringLineItem
428
        from EngineeringLineNoTextItem import QEngineeringLineNoTextItem
429
        from EngineeringVendorItem import QEngineeringVendorItem
430

  
431
        if type(self) is QEngineeringLineNoTextItem:
432
            for prop,value in self._properties.items():
433
                if prop.is_selectable and type(value) is uuid.UUID and self.scene():
434
                    matches = [x for x in self.scene().items() if hasattr(x, 'uid') and str(x.uid) == str(value)]
435
                    if matches: self._properties[prop] = matches[0]
436

  
437
        elif type(self) is QEngineeringLineItem:
438
            for prop, value in self._properties.items():
439
                if prop.is_selectable and type(value) is uuid.UUID and self.scene():
440
                    matches = [x for x in self.scene().items() if hasattr(x, 'uid') and str(x.uid) == str(value)]
441
                    if matches: self._properties[prop] = matches[0]
442

  
443
                if prop.Expression: self._properties[prop] = eval(prop.Expression)
444

  
445
        elif issubclass(type(self), SymbolSvgItem):
446
            for prop, value in self._properties.items():
447
                try:
448
                    if prop.is_selectable and type(value) is uuid.UUID and self.scene():
449
                        matches = [x for x in self.scene().items() if hasattr(x, 'uid') and str(x.uid) == str(value)]
450
                        if matches: self._properties[prop] = matches[0]
451

  
452
                    if prop.Expression:
453
                        item = self._properties[prop]  # assign item
454
                        self._properties[prop] = eval(prop.Expression)
455
                except Exception as ex:
456
                    from App import App
457
                    message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
458
                                                                  sys.exc_info()[-1].tb_lineno)
459
                    App.mainWnd().addMessage.emit(MessageType.Error, message)
460

  
461
        elif type(self) is QEngineeringVendorItem:
462
            for prop, value in self._properties.items():
463
                try:
464
                    if prop.is_selectable and type(value) is uuid.UUID and self.scene():
465
                        matches = [x for x in self.scene().items() if hasattr(x, 'uid') and str(x.uid) == str(value)]
466
                        if matches: self._properties[prop] = matches[0]
467

  
468
                    if prop.Expression:
469
                        item = self._properties[prop]  # assign item
470
                        self._properties[prop] = eval(prop.Expression)
471
                except Exception as ex:
472
                    from App import App
473
                    message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,
474
                                                                  sys.exc_info()[-1].tb_lineno)
475
                    App.mainWnd().addMessage.emit(MessageType.Error, message)
476
                        
477
        return self._properties
478

  
479
    @properties.setter
480
    def properties(self, value):
481
        """ setter of properties """
482
        self._properties = value
483

  
484
    def prop(self, property):
485
        """ return property with given value """
486
        from SymbolSvgItem import SymbolSvgItem
487
        from EngineeringLineItem import QEngineeringLineItem
488
        from EngineeringLineNoTextItem import QEngineeringLineNoTextItem
489
        from EngineeringVendorItem import QEngineeringVendorItem
490

  
491
        if type(self) is QEngineeringLineNoTextItem:
492
            matches = [prop for prop,_ in self.properties.items() if prop.Attribute == property]
493
            return self.properties[matches[0]] if matches else None
494

  
495
        elif type(self) is QEngineeringLineItem:
496
            matches = [(prop, value) for prop, value in self.properties.items() if prop.Attribute == name]
497
            if matches: return matches[0][1]
498

  
499
            return None
500

  
501
        elif issubclass(type(self), SymbolSvgItem):
502
            matches = [(prop, value) for prop, value in self.properties.items() if prop.Attribute == name]
503
            if matches: return matches[0][1]
504

  
505
            return None
506

  
507
        elif type(self) is QEngineeringVendorItem:
508
            matches = [(prop, value) for prop, value in self.properties.items() if prop.Attribute == name]
509
            if matches: return matches[0][1]
510

  
511
    def set_property(self, property, value):
512
        """ set property with given value """
513
        from SymbolSvgItem import SymbolSvgItem
514
        from EngineeringLineItem import QEngineeringLineItem
515
        from EngineeringLineNoTextItem import QEngineeringLineNoTextItem
516
        from EngineeringVendorItem import QEngineeringVendorItem
517

  
518
        if type(self) is QEngineeringLineNoTextItem:
519
            matches = [prop for prop,_ in self._properties.items() if prop.Attribute == property]
520
            if matches: self._properties[matches[0]] = value
521

  
522
        elif type(self) is QEngineeringLineItem:
523
            if issubclass(type(value), QEngineeringAbstractItem): self.add_assoc_item(value, 0)
524
            matches = [prop for prop, _ in self._properties.items() if prop.Attribute == property]
525
            if matches: self._properties[matches[0]] = value
526

  
527
        elif issubclass(type(self), SymbolSvgItem):
528
            if issubclass(type(value), QEngineeringAbstractItem): self.add_assoc_item(value, 0)
529
            matches = [prop for prop, _ in self._properties.items() if prop.Attribute == property]
530
            if matches: self._properties[matches[0]] = value
531

  
532
        elif type(self) is QEngineeringVendorItem:
533
            if issubclass(type(value), QEngineeringAbstractItem):
534
                self.add_assoc_item(value, 0)
535
            matches = [prop for prop, _ in self._properties.items() if prop.Attribute == property]
536
            if matches: self._properties[matches[0]] = value
DTI_PID/DTI_PID/Shapes/EngineeringLineItem.py
115 115

  
116 116
        return tooltip
117 117

  
118
    '''
118 119
    @property
119 120
    def properties(self):
120 121
        """ getter of flow mark """
......
141 142
        if matches: return matches[0][1]
142 143

  
143 144
        return None
145
    '''
144 146

  
145 147
    @property
146 148
    def Size(self):
DTI_PID/DTI_PID/Shapes/EngineeringLineNoTextItem.py
47 47
        #self.freeze_item.setPen(Qt.black)
48 48

  
49 49
    @property
50
    def properties(self):
51
        """ getter of properties """
52
        import uuid
53

  
54
        for prop,value in self._properties.items():
55
            if prop.is_selectable and type(value) is uuid.UUID and self.scene():
56
                matches = [x for x in self.scene().items() if hasattr(x, 'uid') and str(x.uid) == str(value)]
57
                if matches: self._properties[prop] = matches[0]
58
            
59
        return self._properties
60

  
61
    @properties.setter
62
    def properties(self, value):
63
        """ setter of properties """
64
        self._properties = value
65

  
66
    def prop(self, property):
67
        """ return property with given value """
68
        matches = [prop for prop,_ in self.properties.items() if prop.Attribute == property]
69
        return self.properties[matches[0]] if matches else None
70

  
71
    def set_property(self, property, value):
72
        """ set property with given value """
73
        matches = [prop for prop,_ in self._properties.items() if prop.Attribute == property]
74
        if matches: self._properties[matches[0]] = value
75

  
76
    @property
77 50
    def Size(self):
78 51
        """ return line no's size """
79 52
        attrs = self.getAttributes()
DTI_PID/DTI_PID/Shapes/EngineeringVendorItem.py
79 79
        from EngineeringTextItem import QEngineeringTextItem
80 80

  
81 81
        if self.associations():
82
            matches = [assoc for assoc in self.associations() if type(assoc) is QEngineeringTextItem]
82
            matches = [assoc for assoc in self.associations() if issubclass(type(assoc), QEngineeringTextItem)]
83 83
            if matches:
84 84
                return matches[0].text()
85 85
        else:
......
361 361
        polygon = QPolygonF(points)
362 362
        self.setPolygon(polygon)
363 363

  
364
    '''
364 365
    @property
365 366
    def properties(self):
366 367
        """ getter of properties """
......
384 385

  
385 386
        return self._properties
386 387

  
387
    @properties.setter
388
    def properties(self, value):
389
        """ setter of properties """
390
        self._properties = value
391

  
392 388
    def set_property(self, property, value):
393 389
        """ set property with given value """
394 390
        if issubclass(type(value), QEngineeringAbstractItem):
......
400 396
        """ return the value of given property with name """
401 397
        matches = [(prop, value) for prop, value in self.properties.items() if prop.Attribute == name]
402 398
        if matches: return matches[0][1]
399
    '''
403 400

  
404 401
    def __str__(self):
405 402
        return str(self.uid)
DTI_PID/DTI_PID/Shapes/SymbolSvgItem.py
160 160
            self._color = self.DEFAULT_COLOR
161 161
        self.setColor(self._color)
162 162

  
163
    '''
163 164
    @property
164 165
    def properties(self):
165 166
        """ getter of properties """
......
183 184

  
184 185
        return self._properties
185 186

  
186
    @properties.setter
187
    def properties(self, value):
188
        """ setter of properties """
189
        self._properties = value
190

  
191 187
    def set_property(self, property, value):
192 188
        """ set property with given value """
193 189
        if issubclass(type(value), QEngineeringAbstractItem): self.add_assoc_item(value, 0)
......
200 196
        if matches: return matches[0][1]
201 197

  
202 198
        return None
199
    '''
203 200

  
204 201
    @property
205 202
    def Size(self):

내보내기 Unified diff

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