237 endx += border |
237 endx += border |
238 endy += border |
238 endy += border |
239 |
239 |
240 return QSizeF(endx + 1, endy + 1) |
240 return QSizeF(endx + 1, endy + 1) |
241 |
241 |
242 def __getDiagram(self, rect, format="PNG", filename=None): |
242 def __getDiagram(self, rect, imageFormat="PNG", filename=None): |
243 """ |
243 """ |
244 Private method to retrieve the diagram from the scene fitting it |
244 Private method to retrieve the diagram from the scene fitting it |
245 in the minimum rectangle. |
245 in the minimum rectangle. |
246 |
246 |
247 @param rect minimum rectangle fitting the diagram (QRectF) |
247 @param rect minimum rectangle fitting the diagram (QRectF) |
248 @param format format for the image file (string) |
248 @param imageFormat format for the image file (string) |
249 @param filename name of the file for non pixmaps (string) |
249 @param filename name of the file for non pixmaps (string) |
250 @return diagram pixmap to receive the diagram (QPixmap) |
250 @return diagram pixmap to receive the diagram (QPixmap) |
251 """ |
251 """ |
252 selectedItems = self.scene().selectedItems() |
252 selectedItems = self.scene().selectedItems() |
253 |
253 |
255 if selectedItems: |
255 if selectedItems: |
256 for item in selectedItems: |
256 for item in selectedItems: |
257 item.setSelected(False) |
257 item.setSelected(False) |
258 |
258 |
259 # step 2: grab the diagram |
259 # step 2: grab the diagram |
260 if format == "PNG": |
260 if imageFormat == "PNG": |
261 paintDevice = QPixmap(int(rect.width()), int(rect.height())) |
261 paintDevice = QPixmap(int(rect.width()), int(rect.height())) |
262 paintDevice.fill(self.backgroundBrush().color()) |
262 paintDevice.fill(self.backgroundBrush().color()) |
263 else: |
263 else: |
264 from PyQt5.QtSvg import QSvgGenerator |
264 from PyQt5.QtSvg import QSvgGenerator |
265 paintDevice = QSvgGenerator() |
265 paintDevice = QSvgGenerator() |
276 for item in selectedItems: |
276 for item in selectedItems: |
277 item.setSelected(True) |
277 item.setSelected(True) |
278 |
278 |
279 return paintDevice |
279 return paintDevice |
280 |
280 |
281 def saveImage(self, filename, format="PNG"): |
281 def saveImage(self, filename, imageFormat="PNG"): |
282 """ |
282 """ |
283 Public method to save the scene to a file. |
283 Public method to save the scene to a file. |
284 |
284 |
285 @param filename name of the file to write the image to (string) |
285 @param filename name of the file to write the image to (string) |
286 @param format format for the image file (string) |
286 @param imageFormat format for the image file (string) |
287 @return flag indicating success (boolean) |
287 @return flag indicating success (boolean) |
288 """ |
288 """ |
289 rect = self._getDiagramRect(self.border) |
289 rect = self._getDiagramRect(self.border) |
290 if format == "SVG": |
290 if imageFormat == "SVG": |
291 self.__getDiagram(rect, format=format, filename=filename) |
291 self.__getDiagram(rect, imageFormat=imageFormat, filename=filename) |
292 return True |
292 return True |
293 else: |
293 else: |
294 pixmap = self.__getDiagram(rect) |
294 pixmap = self.__getDiagram(rect) |
295 return pixmap.save(filename, format) |
295 return pixmap.save(filename, imageFormat) |
296 |
296 |
297 def printDiagram(self, printer, diagramName=""): |
297 def printDiagram(self, printer, diagramName=""): |
298 """ |
298 """ |
299 Public method to print the diagram. |
299 Public method to print the diagram. |
300 |
300 |