37 |
37 |
38 def __init__(self, scene, parent=None): |
38 def __init__(self, scene, parent=None): |
39 """ |
39 """ |
40 Constructor |
40 Constructor |
41 |
41 |
42 @param scene reference to the scene object (QGraphicsScene) |
42 @param scene reference to the scene object |
43 @param parent parent widget of the view (QWidget) |
43 @type QGraphicsScene |
|
44 @param parent parent widget of the view |
|
45 @type QWidget |
44 """ |
46 """ |
45 E5GraphicsView.__init__(self, scene, parent) |
47 E5GraphicsView.__init__(self, scene, parent) |
46 self.setObjectName("UMLGraphicsView") |
48 self.setObjectName("UMLGraphicsView") |
47 self.setViewportUpdateMode( |
49 self.setViewportUpdateMode( |
48 QGraphicsView.ViewportUpdateMode.FullViewportUpdate) |
50 QGraphicsView.ViewportUpdateMode.FullViewportUpdate) |
187 |
189 |
188 def __sceneChanged(self, areas): |
190 def __sceneChanged(self, areas): |
189 """ |
191 """ |
190 Private slot called when the scene changes. |
192 Private slot called when the scene changes. |
191 |
193 |
192 @param areas list of rectangles that contain changes (list of QRectF) |
194 @param areas list of rectangles that contain changes |
|
195 @type list of QRectF |
193 """ |
196 """ |
194 if len(self.scene().selectedItems()) > 0: |
197 if len(self.scene().selectedItems()) > 0: |
195 self.deleteShapeAct.setEnabled(True) |
198 self.deleteShapeAct.setEnabled(True) |
196 else: |
199 else: |
197 self.deleteShapeAct.setEnabled(False) |
200 self.deleteShapeAct.setEnabled(False) |
212 |
215 |
213 def initToolBar(self): |
216 def initToolBar(self): |
214 """ |
217 """ |
215 Public method to populate a toolbar with our actions. |
218 Public method to populate a toolbar with our actions. |
216 |
219 |
217 @return the populated toolBar (QToolBar) |
220 @return the populated toolBar |
|
221 @rtype QToolBar |
218 """ |
222 """ |
219 toolBar = QToolBar(self.tr("Graphics"), self) |
223 toolBar = QToolBar(self.tr("Graphics"), self) |
220 toolBar.setIconSize(UI.Config.ToolBarIconSize) |
224 toolBar.setIconSize(UI.Config.ToolBarIconSize) |
221 toolBar.addAction(self.deleteShapeAct) |
225 toolBar.addAction(self.deleteShapeAct) |
222 toolBar.addSeparator() |
226 toolBar.addSeparator() |
241 def filteredItems(self, items, itemType=UMLItem): |
245 def filteredItems(self, items, itemType=UMLItem): |
242 """ |
246 """ |
243 Public method to filter a list of items. |
247 Public method to filter a list of items. |
244 |
248 |
245 @param items list of items as returned by the scene object |
249 @param items list of items as returned by the scene object |
246 (QGraphicsItem) |
250 @type QGraphicsItem |
247 @param itemType type to be filtered (class) |
251 @param itemType type to be filtered |
248 @return list of interesting collision items (QGraphicsItem) |
252 @type class |
|
253 @return list of interesting collision items |
|
254 @rtype QGraphicsItem |
249 """ |
255 """ |
250 return [itm for itm in items if isinstance(itm, itemType)] |
256 return [itm for itm in items if isinstance(itm, itemType)] |
251 |
257 |
252 def selectItems(self, items): |
258 def selectItems(self, items): |
253 """ |
259 """ |
254 Public method to select the given items. |
260 Public method to select the given items. |
255 |
261 |
256 @param items list of items to be selected (list of QGraphicsItemItem) |
262 @param items list of items to be selected |
|
263 @type list of QGraphicsItemItem |
257 """ |
264 """ |
258 # step 1: deselect all items |
265 # step 1: deselect all items |
259 self.unselectItems() |
266 self.unselectItems() |
260 |
267 |
261 # step 2: select all given items |
268 # step 2: select all given items |
265 |
272 |
266 def selectItem(self, item): |
273 def selectItem(self, item): |
267 """ |
274 """ |
268 Public method to select an item. |
275 Public method to select an item. |
269 |
276 |
270 @param item item to be selected (QGraphicsItemItem) |
277 @param item item to be selected |
|
278 @type QGraphicsItemItem |
271 """ |
279 """ |
272 if isinstance(item, UMLItem): |
280 if isinstance(item, UMLItem): |
273 item.setSelected(not item.isSelected()) |
281 item.setSelected(not item.isSelected()) |
274 |
282 |
275 def __deleteShape(self): |
283 def __deleteShape(self): |
327 def autoAdjustSceneSize(self, limit=False): |
335 def autoAdjustSceneSize(self, limit=False): |
328 """ |
336 """ |
329 Public method to adjust the scene size to the diagram size. |
337 Public method to adjust the scene size to the diagram size. |
330 |
338 |
331 @param limit flag indicating to limit the scene to the |
339 @param limit flag indicating to limit the scene to the |
332 initial size (boolean) |
340 initial size |
|
341 @type bool |
333 """ |
342 """ |
334 super().autoAdjustSceneSize(limit=limit) |
343 super().autoAdjustSceneSize(limit=limit) |
335 self.__checkSizeActions() |
344 self.__checkSizeActions() |
336 |
345 |
337 def saveImage(self): |
346 def saveImage(self): |
470 |
479 |
471 def __printPreviewPrint(self, printer): |
480 def __printPreviewPrint(self, printer): |
472 """ |
481 """ |
473 Private slot to generate a print preview. |
482 Private slot to generate a print preview. |
474 |
483 |
475 @param printer reference to the printer object (QPrinter) |
484 @param printer reference to the printer object |
|
485 @type QPrinter |
476 """ |
486 """ |
477 super().printDiagram(printer, self.diagramName) |
487 super().printDiagram(printer, self.diagramName) |
478 |
488 |
479 def setDiagramName(self, name): |
489 def setDiagramName(self, name): |
480 """ |
490 """ |
481 Public slot to set the diagram name. |
491 Public slot to set the diagram name. |
482 |
492 |
483 @param name diagram name (string) |
493 @param name diagram name |
|
494 @type str |
484 """ |
495 """ |
485 self.diagramName = name |
496 self.diagramName = name |
486 |
497 |
487 def __alignShapes(self, alignment): |
498 def __alignShapes(self, alignment): |
488 """ |
499 """ |
489 Private slot to align the selected shapes. |
500 Private slot to align the selected shapes. |
490 |
501 |
491 @param alignment alignment type (Qt.AlignmentFlag) |
502 @param alignment alignment type |
|
503 @type Qt.AlignmentFlag |
492 """ |
504 """ |
493 # step 1: get all selected items |
505 # step 1: get all selected items |
494 items = self.scene().selectedItems() |
506 items = self.scene().selectedItems() |
495 if len(items) <= 1: |
507 if len(items) <= 1: |
496 return |
508 return |
562 |
574 |
563 def __itemsBoundingRect(self, items): |
575 def __itemsBoundingRect(self, items): |
564 """ |
576 """ |
565 Private method to calculate the bounding rectangle of the given items. |
577 Private method to calculate the bounding rectangle of the given items. |
566 |
578 |
567 @param items list of items to operate on (list of UMLItem) |
579 @param items list of items to operate on |
568 @return bounding rectangle (QRectF) |
580 @type list of UMLItem |
|
581 @return bounding rectangle |
|
582 @rtype QRectF |
569 """ |
583 """ |
570 rect = self.scene().sceneRect() |
584 rect = self.scene().sceneRect() |
571 right = rect.left() |
585 right = rect.left() |
572 bottom = rect.top() |
586 bottom = rect.top() |
573 left = rect.right() |
587 left = rect.right() |
582 |
596 |
583 def keyPressEvent(self, evt): |
597 def keyPressEvent(self, evt): |
584 """ |
598 """ |
585 Protected method handling key press events. |
599 Protected method handling key press events. |
586 |
600 |
587 @param evt reference to the key event (QKeyEvent) |
601 @param evt reference to the key event |
|
602 @type QKeyEvent |
588 """ |
603 """ |
589 key = evt.key() |
604 key = evt.key() |
590 if key in [Qt.Key.Key_Up, Qt.Key.Key_Down, Qt.Key.Key_Left, |
605 if key in [Qt.Key.Key_Up, Qt.Key.Key_Down, Qt.Key.Key_Left, |
591 Qt.Key.Key_Right]: |
606 Qt.Key.Key_Right]: |
592 items = self.filteredItems(self.scene().selectedItems()) |
607 items = self.filteredItems(self.scene().selectedItems()) |
616 |
631 |
617 def wheelEvent(self, evt): |
632 def wheelEvent(self, evt): |
618 """ |
633 """ |
619 Protected method to handle wheel events. |
634 Protected method to handle wheel events. |
620 |
635 |
621 @param evt reference to the wheel event (QWheelEvent) |
636 @param evt reference to the wheel event |
|
637 @type QWheelEvent |
622 """ |
638 """ |
623 if evt.modifiers() & Qt.KeyboardModifier.ControlModifier: |
639 if evt.modifiers() & Qt.KeyboardModifier.ControlModifier: |
624 delta = evt.angleDelta().y() |
640 delta = evt.angleDelta().y() |
625 if delta < 0: |
641 if delta < 0: |
626 self.zoomOut() |
642 self.zoomOut() |
633 |
649 |
634 def event(self, evt): |
650 def event(self, evt): |
635 """ |
651 """ |
636 Public method handling events. |
652 Public method handling events. |
637 |
653 |
638 @param evt reference to the event (QEvent) |
654 @param evt reference to the event |
639 @return flag indicating, if the event was handled (boolean) |
655 @type QEvent |
|
656 @return flag indicating, if the event was handled |
|
657 @rtype bool |
640 """ |
658 """ |
641 if evt.type() == QEvent.Type.Gesture: |
659 if evt.type() == QEvent.Type.Gesture: |
642 self.gestureEvent(evt) |
660 self.gestureEvent(evt) |
643 return True |
661 return True |
644 |
662 |
646 |
664 |
647 def gestureEvent(self, evt): |
665 def gestureEvent(self, evt): |
648 """ |
666 """ |
649 Protected method handling gesture events. |
667 Protected method handling gesture events. |
650 |
668 |
651 @param evt reference to the gesture event (QGestureEvent |
669 @param evt reference to the gesture event |
|
670 @type QGestureEvent |
652 """ |
671 """ |
653 pinch = evt.gesture(Qt.GestureType.PinchGesture) |
672 pinch = evt.gesture(Qt.GestureType.PinchGesture) |
654 if pinch: |
673 if pinch: |
655 if pinch.state() == Qt.GestureState.GestureStarted: |
674 if pinch.state() == Qt.GestureState.GestureStarted: |
656 pinch.setTotalScaleFactor(self.zoom() / 100.0) |
675 pinch.setTotalScaleFactor(self.zoom() / 100.0) |
660 |
679 |
661 def getItemId(self): |
680 def getItemId(self): |
662 """ |
681 """ |
663 Public method to get the ID to be assigned to an item. |
682 Public method to get the ID to be assigned to an item. |
664 |
683 |
665 @return item ID (integer) |
684 @return item ID |
|
685 @rtype int |
666 """ |
686 """ |
667 self.__itemId += 1 |
687 self.__itemId += 1 |
668 return self.__itemId |
688 return self.__itemId |
669 |
689 |
670 def findItem(self, itemId): |
690 def findItem(self, itemId): |
671 """ |
691 """ |
672 Public method to find an UML item based on the ID. |
692 Public method to find an UML item based on the ID. |
673 |
693 |
674 @param itemId of the item to search for (integer) |
694 @param itemId of the item to search for |
675 @return item found (UMLItem) or None |
695 @type int |
|
696 @return item found or None |
|
697 @rtype UMLItem |
676 """ |
698 """ |
677 for item in self.scene().items(): |
699 for item in self.scene().items(): |
678 try: |
700 try: |
679 if item.getId() == itemId: |
701 if item.getId() == itemId: |
680 return item |
702 return item |
685 |
707 |
686 def findItemByName(self, name): |
708 def findItemByName(self, name): |
687 """ |
709 """ |
688 Public method to find an UML item based on its name. |
710 Public method to find an UML item based on its name. |
689 |
711 |
690 @param name name to look for (string) |
712 @param name name to look for |
691 @return item found (UMLItem) or None |
713 @type str |
|
714 @return item found or None |
|
715 @rtype UMLItem |
692 """ |
716 """ |
693 for item in self.scene().items(): |
717 for item in self.scene().items(): |
694 try: |
718 try: |
695 if item.getName() == name: |
719 if item.getName() == name: |
696 return item |
720 return item |
723 |
748 |
724 def parsePersistenceData(self, version, data): |
749 def parsePersistenceData(self, version, data): |
725 """ |
750 """ |
726 Public method to parse persisted data. |
751 Public method to parse persisted data. |
727 |
752 |
728 @param version version of the data (string) |
753 @param version version of the data |
729 @param data persisted data to be parsed (list of string) |
754 @type str |
|
755 @param data persisted data to be parsed |
|
756 @type list of str |
730 @return tuple of flag indicating success (boolean) and faulty line |
757 @return tuple of flag indicating success (boolean) and faulty line |
731 number (integer) |
758 number |
|
759 @rtype int |
732 """ |
760 """ |
733 umlItems = {} |
761 umlItems = {} |
734 |
762 |
735 if not data[0].startswith("diagram_name:"): |
763 if not data[0].startswith("diagram_name:"): |
736 return False, 0 |
764 return False, 0 |