Graphics/UMLGraphicsView.py

changeset 2992
dbdf27746da5
parent 2953
703452a2876f
child 3020
542e97d4ecb3
child 3057
10516539f238
equal deleted inserted replaced
2991:226481ff40d1 2992:dbdf27746da5
5 5
6 """ 6 """
7 Module implementing a subclass of E5GraphicsView for our diagrams. 7 Module implementing a subclass of E5GraphicsView for our diagrams.
8 """ 8 """
9 9
10 from PyQt4.QtCore import pyqtSignal, Qt, QSignalMapper, QFileInfo, QEvent, QRectF 10 from PyQt4.QtCore import pyqtSignal, Qt, QSignalMapper, QFileInfo, QEvent, \
11 from PyQt4.QtGui import QGraphicsView, QAction, QToolBar, QDialog, QPrinter, QPrintDialog 11 QRectF
12 from PyQt4.QtGui import QGraphicsView, QAction, QToolBar, QDialog, QPrinter, \
13 QPrintDialog
12 14
13 from E5Graphics.E5GraphicsView import E5GraphicsView 15 from E5Graphics.E5GraphicsView import E5GraphicsView
14 16
15 from E5Gui import E5MessageBox, E5FileDialog 17 from E5Gui import E5MessageBox, E5FileDialog
16 from E5Gui.E5ZoomWidget import E5ZoomWidget 18 from E5Gui.E5ZoomWidget import E5ZoomWidget
47 self.__itemId = -1 49 self.__itemId = -1
48 50
49 self.border = 10 51 self.border = 10
50 self.deltaSize = 100.0 52 self.deltaSize = 100.0
51 53
52 self.__zoomWidget = E5ZoomWidget(UI.PixmapCache.getPixmap("zoomOut.png"), 54 self.__zoomWidget = E5ZoomWidget(
55 UI.PixmapCache.getPixmap("zoomOut.png"),
53 UI.PixmapCache.getPixmap("zoomIn.png"), 56 UI.PixmapCache.getPixmap("zoomIn.png"),
54 UI.PixmapCache.getPixmap("zoomReset.png"), self) 57 UI.PixmapCache.getPixmap("zoomReset.png"), self)
55 parent.statusBar().addPermanentWidget(self.__zoomWidget) 58 parent.statusBar().addPermanentWidget(self.__zoomWidget)
56 self.__zoomWidget.setMapping( 59 self.__zoomWidget.setMapping(
57 E5GraphicsView.ZoomLevels, E5GraphicsView.ZoomLevelDefault) 60 E5GraphicsView.ZoomLevels, E5GraphicsView.ZoomLevelDefault)
76 self.trUtf8("Delete shapes"), self) 79 self.trUtf8("Delete shapes"), self)
77 self.deleteShapeAct.triggered[()].connect(self.__deleteShape) 80 self.deleteShapeAct.triggered[()].connect(self.__deleteShape)
78 81
79 self.incWidthAct = \ 82 self.incWidthAct = \
80 QAction(UI.PixmapCache.getIcon("sceneWidthInc.png"), 83 QAction(UI.PixmapCache.getIcon("sceneWidthInc.png"),
81 self.trUtf8("Increase width by {0} points").format(self.deltaSize), 84 self.trUtf8("Increase width by {0} points").format(
85 self.deltaSize),
82 self) 86 self)
83 self.incWidthAct.triggered[()].connect(self.__incWidth) 87 self.incWidthAct.triggered[()].connect(self.__incWidth)
84 88
85 self.incHeightAct = \ 89 self.incHeightAct = \
86 QAction(UI.PixmapCache.getIcon("sceneHeightInc.png"), 90 QAction(UI.PixmapCache.getIcon("sceneHeightInc.png"),
87 self.trUtf8("Increase height by {0} points").format(self.deltaSize), 91 self.trUtf8("Increase height by {0} points").format(
92 self.deltaSize),
88 self) 93 self)
89 self.incHeightAct.triggered[()].connect(self.__incHeight) 94 self.incHeightAct.triggered[()].connect(self.__incHeight)
90 95
91 self.decWidthAct = \ 96 self.decWidthAct = \
92 QAction(UI.PixmapCache.getIcon("sceneWidthDec.png"), 97 QAction(UI.PixmapCache.getIcon("sceneWidthDec.png"),
93 self.trUtf8("Decrease width by {0} points").format(self.deltaSize), 98 self.trUtf8("Decrease width by {0} points").format(
99 self.deltaSize),
94 self) 100 self)
95 self.decWidthAct.triggered[()].connect(self.__decWidth) 101 self.decWidthAct.triggered[()].connect(self.__decWidth)
96 102
97 self.decHeightAct = \ 103 self.decHeightAct = \
98 QAction(UI.PixmapCache.getIcon("sceneHeightDec.png"), 104 QAction(UI.PixmapCache.getIcon("sceneHeightDec.png"),
99 self.trUtf8("Decrease height by {0} points").format(self.deltaSize), 105 self.trUtf8("Decrease height by {0} points").format(
106 self.deltaSize),
100 self) 107 self)
101 self.decHeightAct.triggered[()].connect(self.__decHeight) 108 self.decHeightAct.triggered[()].connect(self.__decHeight)
102 109
103 self.setSizeAct = \ 110 self.setSizeAct = \
104 QAction(UI.PixmapCache.getIcon("sceneSize.png"), 111 QAction(UI.PixmapCache.getIcon("sceneSize.png"),
340 " Overwrite it?</p>").format(fname), 347 " Overwrite it?</p>").format(fname),
341 icon=E5MessageBox.Warning) 348 icon=E5MessageBox.Warning)
342 if not res: 349 if not res:
343 return 350 return
344 351
345 success = super().saveImage(fname, QFileInfo(fname).suffix().upper()) 352 success = super().saveImage(
353 fname, QFileInfo(fname).suffix().upper())
346 if not success: 354 if not success:
347 E5MessageBox.critical(self, 355 E5MessageBox.critical(self,
348 self.trUtf8("Save Diagram"), 356 self.trUtf8("Save Diagram"),
349 self.trUtf8("""<p>The file <b>{0}</b> could not be saved.</p>""") 357 self.trUtf8(
358 """<p>The file <b>{0}</b> could not be saved.</p>""")
350 .format(fname)) 359 .format(fname))
351 360
352 def __relayout(self): 361 def __relayout(self):
353 """ 362 """
354 Private slot to handle the re-layout context menu entry. 363 Private slot to handle the re-layout context menu entry.
675 item.getId(), item.x(), item.y(), item.getItemType(), 684 item.getId(), item.x(), item.y(), item.getItemType(),
676 item.buildItemDataString())) 685 item.buildItemDataString()))
677 686
678 from .AssociationItem import AssociationItem 687 from .AssociationItem import AssociationItem
679 for item in self.filteredItems(self.scene().items(), AssociationItem): 688 for item in self.filteredItems(self.scene().items(), AssociationItem):
680 lines.append("association: {0}".format(item.buildAssociationItemDataString())) 689 lines.append("association: {0}".format(
690 item.buildAssociationItemDataString()))
681 691
682 return lines 692 return lines
683 693
684 def parsePersistenceData(self, version, data): 694 def parsePersistenceData(self, version, data):
685 """ 695 """
727 return False, linenum 737 return False, linenum
728 except ValueError: 738 except ValueError:
729 return False, linenum 739 return False, linenum
730 elif key == "association": 740 elif key == "association":
731 srcId, dstId, assocType, topToBottom = \ 741 srcId, dstId, assocType, topToBottom = \
732 AssociationItem.parseAssociationItemDataString(value.strip()) 742 AssociationItem.parseAssociationItemDataString(
743 value.strip())
733 assoc = AssociationItem(umlItems[srcId], umlItems[dstId], 744 assoc = AssociationItem(umlItems[srcId], umlItems[dstId],
734 assocType, topToBottom) 745 assocType, topToBottom)
735 self.scene().addItem(assoc) 746 self.scene().addItem(assoc)
736 747
737 return True, -1 748 return True, -1

eric ide

mercurial