# HG changeset patch # User John W. Eaton # Date 1429294020 14400 # Node ID c58cf3a6551934a8f4fb90b4fc977f915e6f602d # Parent 4d0c7fec0a315c2c551488acff2d7a3ff61a42db 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. diff -r 4d0c7fec0a31 -r c58cf3a65519 libgui/graphics/Figure.cc --- 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