changeset 20120:c58cf3a65519

improve copy to clipboard code for Qt plotting * Figure.cc (Figure::copy_figure_callback): Append format to temporary file name. Check that QImage is valid before copying to clipboard.
author John W. Eaton <jwe@octave.org>
date Fri, 17 Apr 2015 14:07:00 -0400
parents 4d0c7fec0a31
children 23fb65b45d8c
files libgui/graphics/Figure.cc
diffstat 1 files changed, 12 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/graphics/Figure.cc	Fri Apr 17 09:09:52 2015 -0700
+++ b/libgui/graphics/Figure.cc	Fri Apr 17 14:07:00 2015 -0400
@@ -51,6 +51,7 @@
 
 #include "file-ops.h"
 #include "unwind-prot.h"
+#include "utils.h"
 
 #include "octave-qt-link.h"
 
@@ -828,11 +829,11 @@
 
   unwind_protect frame;
 
-  std::string file = octave_tempnam ("", "oct-", msg);
+  std::string file = octave_tempnam ("", "oct-", msg) + "." + format;
 
   if (file.empty ())
     {
-      // FIXME: report error contained in message.
+      // Report error?
       return;
     }
 
@@ -844,7 +845,15 @@
 
   QClipboard *clipboard = QApplication::clipboard ();
 
-  clipboard->setImage (QImage (file.c_str ()));
+  QImage img (file.c_str (), format.c_str ());
+
+  if (img.isNull ())
+    {
+      // Report error?
+      return;
+    }
+
+  clipboard->setImage (img);
 }
   
 void