[Uml-devel] kdesdk/umbrello/umbrello

Jonathan Riddell jri at jriddell.org
Tue Jun 15 14:11:06 UTC 2004


CVS commit by jriddell: 

Nifty patch by Achim Spangler <Achim.Spangler_AT_mnet-online.de>
Add SVG diagram export


  M +38 -10    umlview.cpp   1.143


--- kdesdk/umbrello/umbrello/umlview.cpp  #1.142:1.143
@@ -12,4 +12,5 @@
 // include files for Qt
 #include <qpixmap.h>
+#include <qpicture.h>
 #include <qprinter.h>
 #include <qpainter.h>
@@ -1239,4 +1240,5 @@ QString imageTypeToMimeType(QString imag
         if (QString("XPM") == imagetype) return "image/x-xpm";
         if (QString("EPS") == imagetype) return "image/x-eps";
+        if (QString("SVG") == imagetype) return "image/svg+xml";
         return QString::null;
 }
@@ -1252,4 +1254,5 @@ QString mimeTypeToImageType(QString mime
         if (QString("image/x-xpm") == mimetype) return "XPM";
         if (QString("image/x-eps") == mimetype) return "EPS";
+        if (QString("image/svg+xml") == mimetype) return "SVG";
         return QString::null;
 }
@@ -1326,4 +1329,5 @@ void UMLView::exportImage() {
         // special image types that are handled separately
         mimetypes.append("image/x-eps");
+        mimetypes.append("image/svg+xml");
         // "normal" image types that are present
         QString m;
@@ -1393,5 +1397,29 @@ void UMLView::exportImage() {
                 if (imageMimetype == "image/x-eps") {
                         printToFile(s,true);
-                }else{
+                } else if (imageMimetype == "image/svg+xml") {
+                        QPicture* diagram = new QPicture();
+
+                        // do not call printer.setup(); because we want no user
+                        // interaction here
+                        QPainter* painter = new QPainter();
+                        painter->begin( diagram );
+
+                        // make sure the widget sizes will be according to the
+                        // actually used printer font, important for getDiagramRect()
+                        // and the actual painting
+                        forceUpdateWidgetFontMetrics(painter);
+
+                        QRect rect = getDiagramRect();
+                        painter->translate(-rect.x(),-rect.y());
+                        getDiagram(rect,*painter);
+                        painter->end();
+                        diagram->save(s, mimeTypeToImageType(imageMimetype).ascii());
+
+                        // delete painter and printer before we try to open and fix the file
+                        delete painter;
+                        delete diagram;
+                        // next painting will most probably be to a different device (i.e. the screen)
+                        forceUpdateWidgetFontMetrics(0);
+                } else {
                         QPixmap diagram(rect.width(), rect.height());
                         getDiagram(rect, diagram);






More information about the umbrello-devel mailing list