Graphics/UMLGraphicsView.py

branch
Py2 comp.
changeset 3057
10516539f238
parent 2791
a9577f248f04
parent 2992
dbdf27746da5
child 3058
0a02c433f52d
equal deleted inserted replaced
3056:9986ec0e559a 3057:10516539f238
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 __future__ import unicode_literals # __IGNORE_WARNING__ 10 from __future__ import unicode_literals # __IGNORE_WARNING__
11 11
12 from PyQt4.QtCore import pyqtSignal, Qt, QSignalMapper, QFileInfo, QEvent, QRectF 12 from PyQt4.QtCore import pyqtSignal, Qt, QSignalMapper, QFileInfo, QEvent, \
13 from PyQt4.QtGui import QGraphicsView, QAction, QToolBar, QDialog, QPrinter, QPrintDialog 13 QRectF
14 from PyQt4.QtGui import QGraphicsView, QAction, QToolBar, QDialog, QPrinter, \
15 QPrintDialog
14 16
15 from E5Graphics.E5GraphicsView import E5GraphicsView 17 from E5Graphics.E5GraphicsView import E5GraphicsView
16 18
17 from E5Gui import E5MessageBox, E5FileDialog 19 from E5Gui import E5MessageBox, E5FileDialog
18 from E5Gui.E5ZoomWidget import E5ZoomWidget 20 from E5Gui.E5ZoomWidget import E5ZoomWidget
49 self.__itemId = -1 51 self.__itemId = -1
50 52
51 self.border = 10 53 self.border = 10
52 self.deltaSize = 100.0 54 self.deltaSize = 100.0
53 55
54 self.__zoomWidget = E5ZoomWidget(UI.PixmapCache.getPixmap("zoomOut.png"), 56 self.__zoomWidget = E5ZoomWidget(
57 UI.PixmapCache.getPixmap("zoomOut.png"),
55 UI.PixmapCache.getPixmap("zoomIn.png"), 58 UI.PixmapCache.getPixmap("zoomIn.png"),
56 UI.PixmapCache.getPixmap("zoomReset.png"), self) 59 UI.PixmapCache.getPixmap("zoomReset.png"), self)
57 parent.statusBar().addPermanentWidget(self.__zoomWidget) 60 parent.statusBar().addPermanentWidget(self.__zoomWidget)
58 self.__zoomWidget.setMapping( 61 self.__zoomWidget.setMapping(
59 E5GraphicsView.ZoomLevels, E5GraphicsView.ZoomLevelDefault) 62 E5GraphicsView.ZoomLevels, E5GraphicsView.ZoomLevelDefault)
78 self.trUtf8("Delete shapes"), self) 81 self.trUtf8("Delete shapes"), self)
79 self.deleteShapeAct.triggered[()].connect(self.__deleteShape) 82 self.deleteShapeAct.triggered[()].connect(self.__deleteShape)
80 83
81 self.incWidthAct = \ 84 self.incWidthAct = \
82 QAction(UI.PixmapCache.getIcon("sceneWidthInc.png"), 85 QAction(UI.PixmapCache.getIcon("sceneWidthInc.png"),
83 self.trUtf8("Increase width by {0} points").format(self.deltaSize), 86 self.trUtf8("Increase width by {0} points").format(
87 self.deltaSize),
84 self) 88 self)
85 self.incWidthAct.triggered[()].connect(self.__incWidth) 89 self.incWidthAct.triggered[()].connect(self.__incWidth)
86 90
87 self.incHeightAct = \ 91 self.incHeightAct = \
88 QAction(UI.PixmapCache.getIcon("sceneHeightInc.png"), 92 QAction(UI.PixmapCache.getIcon("sceneHeightInc.png"),
89 self.trUtf8("Increase height by {0} points").format(self.deltaSize), 93 self.trUtf8("Increase height by {0} points").format(
94 self.deltaSize),
90 self) 95 self)
91 self.incHeightAct.triggered[()].connect(self.__incHeight) 96 self.incHeightAct.triggered[()].connect(self.__incHeight)
92 97
93 self.decWidthAct = \ 98 self.decWidthAct = \
94 QAction(UI.PixmapCache.getIcon("sceneWidthDec.png"), 99 QAction(UI.PixmapCache.getIcon("sceneWidthDec.png"),
95 self.trUtf8("Decrease width by {0} points").format(self.deltaSize), 100 self.trUtf8("Decrease width by {0} points").format(
101 self.deltaSize),
96 self) 102 self)
97 self.decWidthAct.triggered[()].connect(self.__decWidth) 103 self.decWidthAct.triggered[()].connect(self.__decWidth)
98 104
99 self.decHeightAct = \ 105 self.decHeightAct = \
100 QAction(UI.PixmapCache.getIcon("sceneHeightDec.png"), 106 QAction(UI.PixmapCache.getIcon("sceneHeightDec.png"),
101 self.trUtf8("Decrease height by {0} points").format(self.deltaSize), 107 self.trUtf8("Decrease height by {0} points").format(
108 self.deltaSize),
102 self) 109 self)
103 self.decHeightAct.triggered[()].connect(self.__decHeight) 110 self.decHeightAct.triggered[()].connect(self.__decHeight)
104 111
105 self.setSizeAct = \ 112 self.setSizeAct = \
106 QAction(UI.PixmapCache.getIcon("sceneSize.png"), 113 QAction(UI.PixmapCache.getIcon("sceneSize.png"),
342 " Overwrite it?</p>").format(fname), 349 " Overwrite it?</p>").format(fname),
343 icon=E5MessageBox.Warning) 350 icon=E5MessageBox.Warning)
344 if not res: 351 if not res:
345 return 352 return
346 353
347 success = super(UMLGraphicsView, self).saveImage(fname, QFileInfo(fname).suffix().upper()) 354 success = super(UMLGraphicsView, self).saveImage(
355 fname, QFileInfo(fname).suffix().upper())
348 if not success: 356 if not success:
349 E5MessageBox.critical(self, 357 E5MessageBox.critical(self,
350 self.trUtf8("Save Diagram"), 358 self.trUtf8("Save Diagram"),
351 self.trUtf8("""<p>The file <b>{0}</b> could not be saved.</p>""") 359 self.trUtf8(
360 """<p>The file <b>{0}</b> could not be saved.</p>""")
352 .format(fname)) 361 .format(fname))
353 362
354 def __relayout(self): 363 def __relayout(self):
355 """ 364 """
356 Private slot to handle the re-layout context menu entry. 365 Private slot to handle the re-layout context menu entry.
443 preview.exec_() 452 preview.exec_()
444 453
445 def __printPreviewPrint(self, printer): 454 def __printPreviewPrint(self, printer):
446 """ 455 """
447 Private slot to generate a print preview. 456 Private slot to generate a print preview.
457
458 @param printer reference to the printer object (QPrinter)
448 """ 459 """
449 super(UMLGraphicsView, self).printDiagram(printer, self.diagramName) 460 super(UMLGraphicsView, self).printDiagram(printer, self.diagramName)
450 461
451 def setDiagramName(self, name): 462 def setDiagramName(self, name):
452 """ 463 """
675 item.getId(), item.x(), item.y(), item.getItemType(), 686 item.getId(), item.x(), item.y(), item.getItemType(),
676 item.buildItemDataString())) 687 item.buildItemDataString()))
677 688
678 from .AssociationItem import AssociationItem 689 from .AssociationItem import AssociationItem
679 for item in self.filteredItems(self.scene().items(), AssociationItem): 690 for item in self.filteredItems(self.scene().items(), AssociationItem):
680 lines.append("association: {0}".format(item.buildAssociationItemDataString())) 691 lines.append("association: {0}".format(
692 item.buildAssociationItemDataString()))
681 693
682 return lines 694 return lines
683 695
684 def parsePersistenceData(self, version, data): 696 def parsePersistenceData(self, version, data):
685 """ 697 """
727 return False, linenum 739 return False, linenum
728 except ValueError: 740 except ValueError:
729 return False, linenum 741 return False, linenum
730 elif key == "association": 742 elif key == "association":
731 srcId, dstId, assocType, topToBottom = \ 743 srcId, dstId, assocType, topToBottom = \
732 AssociationItem.parseAssociationItemDataString(value.strip()) 744 AssociationItem.parseAssociationItemDataString(
745 value.strip())
733 assoc = AssociationItem(umlItems[srcId], umlItems[dstId], 746 assoc = AssociationItem(umlItems[srcId], umlItems[dstId],
734 assocType, topToBottom) 747 assocType, topToBottom)
735 self.scene().addItem(assoc) 748 self.scene().addItem(assoc)
736 749
737 return True, -1 750 return True, -1

eric ide

mercurial