[Uml-devel] [Bug 58809] Image export via command line

Oliver Kellogg okellogg at users.sourceforge.net
Fri Aug 5 03:17:18 UTC 2005


------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
         
http://bugs.kde.org/show_bug.cgi?id=58809         




------- Additional Comments From okellogg users sourceforge net  2005-08-05 12:15 -------
SVN commit 443195 by okellogg:

Patch from Alan Ezust adds image export via command line.
I have not yet tested this stuff; can we close the PR?
CCBUG:58809


 M  +2 -1      ChangeLog  
 M  +2 -0      THANKS  
 M  +1 -0      umbrello/Makefile.am  
 M  +15 -2     umbrello/main.cpp  
 M  +48 -0     umbrello/umlview.cpp  
 M  +11 -0     umbrello/umlview.h  


--- branches/KDE/3.5/kdesdk/umbrello/ChangeLog #443194:443195
 @ -5,10 +5,11  @
 * Code generator for Tcl
 * Externalization of folders (i.e. submodel files)
 * Change interface into class and vice versa (if abstract and no attributes)
+* Image export via command line
 * Automatic Diagram Layout (67059, not yet closed)
 
 * Bugs fixed / wishes implemented (see http://bugs.kde.org)
-57588 67719 72016 79433 87252 88117 97162 105564 108223 109591 109636
+57588 58809 67719 72016 79433 87252 88117 97162 105564 108223 109591 109636
 
 Version 1.4.2 (maintenance release)
 
--- branches/KDE/3.5/kdesdk/umbrello/THANKS #443194:443195
 @ -25,6 +25,7  @
 Albert Astals Cid <tsdgeos  terra es>
 Richard Dale <duke  tipitina demon co uk>
 Vincent Decorges <vincent.decorges  eivd ch>
+Alan Ezust <alan.ezust  gmail com>
 Jean-Remy Falleri <jr.falleri  gmail com>
 Andi Fischer <andi.fischer  hispeed ch>
 Pascal Fleury <fleury  users sourceforge net>
 @ -47,6 +48,7  @
 Laurent Montel <montel  kde org>
 Lutz Mueller <lutz.mueller  gmx de>
 Heiko Nardmann <heiko.nardmann  onlinehome de>
+Dimitri Ognibene <ognibened  yahoo it>
 Carsten Pfeiffer <pfeiffer  kde org>
 Ivan Porres <iporres  abo fi>
 Ruediger Ranft <kdebugs  rranft1 mail htwm de>
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/Makefile.am #443194:443195
 @ -43,6 +43,7  @
 enum.cpp \
 enumliteral.cpp \
 enumwidget.cpp \
+exportviewaction.cpp \
 floatingtext.cpp \
 kplayerslideraction.cpp \
 hierarchicalcodeblock.cpp \
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/main.cpp #443194:443195
 @ -14,7 +14,8  @
 
 #include "uml.h"
 #include "version.h"
-
+#include "umlview.h"
+#include "exportviewaction.h"
 #include "kstartuplogo.h"
 
 #include <kaboutdata.h>
 @ -36,6 +37,7  @
 static KCmdLineOptions options[] =
     {
         { "+[File]", I18N_NOOP("File to open"), 0 },
+        { "export <extension>", I18N_NOOP("export diagrams to extension and exit"), 0},
         // INSERT YOUR COMMANDLINE OPTIONS HERE
         KCmdLineLastOption
     };
 @ -82,7 +84,7  @
         KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
         if ( args -> count() ) {
             uml -> openDocumentFile( args -> url( 0 ) );
-            args -> clear();
+            // args -> clear();  // Why is this necessary?
         } else {
             cfg -> setGroup( "General Options" );
             bool last = cfg -> readBoolEntry( "loadlast", false );
 @ -93,6 +95,17  @
                 uml->newDocument();
             }
         }
+        QCStringList exportOpt = args->getOptionList("export");
+        if (exportOpt.size() > 0) {
+        for (QCStringList::iterator itr = exportOpt.begin();
+            itr != exportOpt.end(); ++itr) {
+                QString extension = QString(*itr);
+                kdDebug() << "extension: " << extension << endl;
+                ExportViewAction eva(extension);
+                eva.exportAllViews();
+            }
+            return 0;
+        }
         if ( showLogo && !start_logo->isHidden() ) {
             start_logo->raise();
         }
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/umlview.cpp #443194:443195
 @ -1444,6 +1444,54  @
 
 }
 
+void UMLView::exportImageTo(QString imageMimetype) {
+    KTempFile tmpfile;
+    QString extDef = mimeTypeToImageType(imageMimetype).lower();
+    QString file = getName() + "." + extDef;
+    kdDebug() << "m_ImageURL: " << m_ImageURL.fileName() << endl;
+    if (!m_ImageURL.isEmpty()) {
+      file = tmpfile.name();
+    }
+    
+    QFileInfo info(file);
+    QString ext = info.extension(false);
+
+    QRect rect = getDiagramRect();
+    if (rect.isEmpty()) {
+        kdDebug() << "Can not save an empty diagram" << endl;
+        return;
+    }
+    kdDebug() << "ExportImageTo: " << file << endl;
+    if (imageMimetype == "image/x-eps") {
+        printToFile(file,true);
+    } else if (imageMimetype == "image/svg+xml") {
+        QPicture* diagram = new QPicture();
+        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(file, 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);
+        diagram.save(file, mimeTypeToImageType(imageMimetype).ascii());
+    }
+}
+
 void UMLView::exportImage() {
     UMLApp *app = UMLApp::app();
     QStringList fmt = QImage::outputFormatList();
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/umlview.h #443194:443195
 @ -669,6 +669,17  @
     void copyAsImage(QPixmap*& pix);
 
     /**
+     * Does not pop up any dialogs, but tries to save this
+     * image to the last-saved name. can be called from
+     * command line.
+     *  param mimetype - an alternate mimetype to save as
+     *  todo test further, and later refactor the redundant
+     *     code from exportImage() -- SAE left
+     *     exportImage alone for this exercise
+     */
+    void exportImageTo(QString mimetype);
+
+    /**
      * Saves a png file to the given url.
      */
     void exportImage();




More information about the umbrello-devel mailing list